Skip to content

Instantly share code, notes, and snippets.

@godismyjudge95
Created March 2, 2019 08:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save godismyjudge95/a4ea43263db53b90b05511c911cd0034 to your computer and use it in GitHub Desktop.
Save godismyjudge95/a4ea43263db53b90b05511c911cd0034 to your computer and use it in GitHub Desktop.
Mapbox GL Draw Click Propagation Fixed Build
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.MapboxDraw = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
"use strict";
var runSetup = require('./src/setup');
var setupOptions = require('./src/options');
var setupAPI = require('./src/api');
var Constants = require('./src/constants');
var setupDraw = function setupDraw(options, api) {
options = setupOptions(options);
var ctx = {
options: options
};
api = setupAPI(ctx, api);
ctx.api = api;
var setup = runSetup(ctx);
api.onAdd = setup.onAdd;
api.onRemove = setup.onRemove;
api.types = Constants.types;
api.options = options;
return api;
};
module.exports = function (options) {
setupDraw(options, this);
};
module.exports.modes = require('./src/modes');
},{"./src/api":22,"./src/constants":23,"./src/modes":56,"./src/options":61,"./src/setup":63}],2:[function(require,module,exports){
module.exports = Extent;
function Extent(bbox) {
if (!(this instanceof Extent)) {
return new Extent(bbox);
}
this._bbox = bbox || [Infinity, Infinity, -Infinity, -Infinity];
this._valid = !!bbox;
}
Extent.prototype.include = function(ll) {
this._valid = true;
this._bbox[0] = Math.min(this._bbox[0], ll[0]);
this._bbox[1] = Math.min(this._bbox[1], ll[1]);
this._bbox[2] = Math.max(this._bbox[2], ll[0]);
this._bbox[3] = Math.max(this._bbox[3], ll[1]);
return this;
};
Extent.prototype.equals = function(_) {
var other;
if (_ instanceof Extent) { other = _.bbox(); } else { other = _; }
return this._bbox[0] == other[0] &&
this._bbox[1] == other[1] &&
this._bbox[2] == other[2] &&
this._bbox[3] == other[3];
};
Extent.prototype.center = function(_) {
if (!this._valid) return null;
return [
(this._bbox[0] + this._bbox[2]) / 2,
(this._bbox[1] + this._bbox[3]) / 2]
};
Extent.prototype.union = function(_) {
this._valid = true;
var other;
if (_ instanceof Extent) { other = _.bbox(); } else { other = _; }
this._bbox[0] = Math.min(this._bbox[0], other[0]);
this._bbox[1] = Math.min(this._bbox[1], other[1]);
this._bbox[2] = Math.max(this._bbox[2], other[2]);
this._bbox[3] = Math.max(this._bbox[3], other[3]);
return this;
};
Extent.prototype.bbox = function() {
if (!this._valid) return null;
return this._bbox;
};
Extent.prototype.contains = function(ll) {
if (!ll) return this._fastContains();
if (!this._valid) return null;
var lon = ll[0], lat = ll[1];
return this._bbox[0] <= lon &&
this._bbox[1] <= lat &&
this._bbox[2] >= lon &&
this._bbox[3] >= lat;
};
Extent.prototype.intersect = function(_) {
if (!this._valid) return null;
var other;
if (_ instanceof Extent) { other = _.bbox(); } else { other = _; }
return !(
this._bbox[0] > other[2] ||
this._bbox[2] < other[0] ||
this._bbox[3] < other[1] ||
this._bbox[1] > other[3]
);
};
Extent.prototype._fastContains = function() {
if (!this._valid) return new Function('return null;');
var body = 'return ' +
this._bbox[0] + '<= ll[0] &&' +
this._bbox[1] + '<= ll[1] &&' +
this._bbox[2] + '>= ll[0] &&' +
this._bbox[3] + '>= ll[1]';
return new Function('ll', body);
};
Extent.prototype.polygon = function() {
if (!this._valid) return null;
return {
type: 'Polygon',
coordinates: [
[
// W, S
[this._bbox[0], this._bbox[1]],
// E, S
[this._bbox[2], this._bbox[1]],
// E, N
[this._bbox[2], this._bbox[3]],
// W, N
[this._bbox[0], this._bbox[3]],
// W, S
[this._bbox[0], this._bbox[1]]
]
]
};
};
},{}],3:[function(require,module,exports){
var wgs84 = require('wgs84');
module.exports.geometry = geometry;
module.exports.ring = ringArea;
function geometry(_) {
var area = 0, i;
switch (_.type) {
case 'Polygon':
return polygonArea(_.coordinates);
case 'MultiPolygon':
for (i = 0; i < _.coordinates.length; i++) {
area += polygonArea(_.coordinates[i]);
}
return area;
case 'Point':
case 'MultiPoint':
case 'LineString':
case 'MultiLineString':
return 0;
case 'GeometryCollection':
for (i = 0; i < _.geometries.length; i++) {
area += geometry(_.geometries[i]);
}
return area;
}
}
function polygonArea(coords) {
var area = 0;
if (coords && coords.length > 0) {
area += Math.abs(ringArea(coords[0]));
for (var i = 1; i < coords.length; i++) {
area -= Math.abs(ringArea(coords[i]));
}
}
return area;
}
/**
* 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 http://trs-new.jpl.nasa.gov/dspace/handle/2014/40409
*
* Returns:
* {float} The approximate signed geodesic area of the polygon in square
* meters.
*/
function ringArea(coords) {
var p1, p2, p3, lowerIndex, middleIndex, upperIndex, i,
area = 0,
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];
area += ( rad(p3[0]) - rad(p1[0]) ) * Math.sin( rad(p2[1]));
}
area = area * wgs84.RADIUS * wgs84.RADIUS / 2;
}
return area;
}
function rad(_) {
return _ * Math.PI / 180;
}
},{"wgs84":20}],4:[function(require,module,exports){
module.exports = function flatten(list) {
return _flatten(list);
function _flatten(list) {
if (Array.isArray(list) && list.length &&
typeof list[0] === 'number') {
return [list];
}
return list.reduce(function (acc, item) {
if (Array.isArray(item) && Array.isArray(item[0])) {
return acc.concat(_flatten(item));
} else {
acc.push(item);
return acc;
}
}, []);
}
};
},{}],5:[function(require,module,exports){
var geojsonNormalize = require('@mapbox/geojson-normalize'),
geojsonFlatten = require('geojson-flatten'),
flatten = require('./flatten');
module.exports = function(_) {
if (!_) return [];
var normalized = geojsonFlatten(geojsonNormalize(_)),
coordinates = [];
normalized.features.forEach(function(feature) {
if (!feature.geometry) return;
coordinates = coordinates.concat(flatten(feature.geometry.coordinates));
});
return coordinates;
};
},{"./flatten":4,"@mapbox/geojson-normalize":7,"geojson-flatten":13}],6:[function(require,module,exports){
var geojsonCoords = require('@mapbox/geojson-coords'),
traverse = require('traverse'),
extent = require('@mapbox/extent');
var geojsonTypesByDataAttributes = {
features: ['FeatureCollection'],
coordinates: ['Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon'],
geometry: ['Feature'],
geometries: ['GeometryCollection']
}
var dataAttributes = Object.keys(geojsonTypesByDataAttributes);
module.exports = function(_) {
return getExtent(_).bbox();
};
module.exports.polygon = function(_) {
return getExtent(_).polygon();
};
module.exports.bboxify = function(_) {
return traverse(_).map(function(value) {
if (!value) return ;
var isValid = dataAttributes.some(function(attribute){
if(value[attribute]) {
return geojsonTypesByDataAttributes[attribute].indexOf(value.type) !== -1;
}
return false;
});
if(isValid){
value.bbox = getExtent(value).bbox();
this.update(value);
}
});
};
function getExtent(_) {
var bbox = [Infinity, Infinity, -Infinity, -Infinity],
ext = extent(),
coords = geojsonCoords(_);
for (var i = 0; i < coords.length; i++) ext.include(coords[i]);
return ext;
}
},{"@mapbox/extent":2,"@mapbox/geojson-coords":5,"traverse":19}],7:[function(require,module,exports){
module.exports = normalize;
var types = {
Point: 'geometry',
MultiPoint: 'geometry',
LineString: 'geometry',
MultiLineString: 'geometry',
Polygon: 'geometry',
MultiPolygon: 'geometry',
GeometryCollection: 'geometry',
Feature: 'feature',
FeatureCollection: 'featurecollection'
};
/**
* Normalize a GeoJSON feature into a FeatureCollection.
*
* @param {object} gj geojson data
* @returns {object} normalized geojson data
*/
function normalize(gj) {
if (!gj || !gj.type) return null;
var type = types[gj.type];
if (!type) return null;
if (type === 'geometry') {
return {
type: 'FeatureCollection',
features: [{
type: 'Feature',
properties: {},
geometry: gj
}]
};
} else if (type === 'feature') {
return {
type: 'FeatureCollection',
features: [gj]
};
} else if (type === 'featurecollection') {
return gj;
}
}
},{}],8:[function(require,module,exports){
var jsonlint = require('jsonlint-lines'),
geojsonHintObject = require('./object');
/**
* @alias geojsonhint
* @param {(string|object)} GeoJSON given as a string or as an object
* @param {Object} options
* @param {boolean} [options.noDuplicateMembers=true] forbid repeated
* properties. This is only available for string input, becaused parsed
* Objects cannot have duplicate properties.
* @param {boolean} [options.precisionWarning=true] warn if GeoJSON contains
* unnecessary coordinate precision.
* @returns {Array<Object>} an array of errors
*/
function hint(str, options) {
var gj, errors = [];
if (typeof str === 'object') {
gj = str;
} else if (typeof str === 'string') {
try {
gj = jsonlint.parse(str);
} catch(e) {
var match = e.message.match(/line (\d+)/);
var lineNumber = parseInt(match[1], 10);
return [{
line: lineNumber - 1,
message: e.message,
error: e
}];
}
} else {
return [{
message: 'Expected string or object as input',
line: 0
}];
}
errors = errors.concat(geojsonHintObject.hint(gj, options));
return errors;
}
module.exports.hint = hint;
},{"./object":9,"jsonlint-lines":15}],9:[function(require,module,exports){
var rightHandRule = require('./rhr');
/**
* @alias geojsonhint
* @param {(string|object)} GeoJSON given as a string or as an object
* @param {Object} options
* @param {boolean} [options.noDuplicateMembers=true] forbid repeated
* properties. This is only available for string input, becaused parsed
* Objects cannot have duplicate properties.
* @param {boolean} [options.precisionWarning=true] warn if GeoJSON contains
* unnecessary coordinate precision.
* @returns {Array<Object>} an array of errors
*/
function hint(gj, options) {
var errors = [];
var precisionWarningCount = 0;
var maxPrecisionWarnings = 10;
var maxPrecision = 6;
function root(_) {
if ((!options || options.noDuplicateMembers !== false) &&
_.__duplicateProperties__) {
errors.push({
message: 'An object contained duplicate members, making parsing ambigous: ' + _.__duplicateProperties__.join(', '),
line: _.__line__
});
}
if (requiredProperty(_, 'type', 'string')) {
return;
}
if (!types[_.type]) {
var expectedType = typesLower[_.type.toLowerCase()];
if (expectedType !== undefined) {
errors.push({
message: 'Expected ' + expectedType + ' but got ' + _.type + ' (case sensitive)',
line: _.__line__
});
} else {
errors.push({
message: 'The type ' + _.type + ' is unknown',
line: _.__line__
});
}
} else if (_) {
types[_.type](_);
}
}
function everyIs(_, type) {
// make a single exception because typeof null === 'object'
return _.every(function(x) {
return x !== null && typeof x === type;
});
}
function requiredProperty(_, name, type) {
if (typeof _[name] === 'undefined') {
return errors.push({
message: '"' + name + '" member required',
line: _.__line__
});
} else if (type === 'array') {
if (!Array.isArray(_[name])) {
return errors.push({
message: '"' + name +
'" member should be an array, but is an ' +
(typeof _[name]) + ' instead',
line: _.__line__
});
}
} else if (type === 'object' && _[name] && _[name].constructor.name !== 'Object') {
return errors.push({
message: '"' + name +
'" member should be ' + (type) +
', but is an ' + (_[name].constructor.name) + ' instead',
line: _.__line__
});
} else if (type && typeof _[name] !== type) {
return errors.push({
message: '"' + name +
'" member should be ' + (type) +
', but is an ' + (typeof _[name]) + ' instead',
line: _.__line__
});
}
}
// https://tools.ietf.org/html/rfc7946#section-3.3
function FeatureCollection(featureCollection) {
crs(featureCollection);
bbox(featureCollection);
if (featureCollection.properties !== undefined) {
errors.push({
message: 'FeatureCollection object cannot contain a "properties" member',
line: featureCollection.__line__
});
}
if (featureCollection.coordinates !== undefined) {
errors.push({
message: 'FeatureCollection object cannot contain a "coordinates" member',
line: featureCollection.__line__
});
}
if (!requiredProperty(featureCollection, 'features', 'array')) {
if (!everyIs(featureCollection.features, 'object')) {
return errors.push({
message: 'Every feature must be an object',
line: featureCollection.__line__
});
}
featureCollection.features.forEach(Feature);
}
}
// https://tools.ietf.org/html/rfc7946#section-3.1.1
function position(_, line) {
if (!Array.isArray(_)) {
return errors.push({
message: 'position should be an array, is a ' + (typeof _) +
' instead',
line: _.__line__ || line
});
}
if (_.length < 2) {
return errors.push({
message: 'position must have 2 or more elements',
line: _.__line__ || line
});
}
if (_.length > 3) {
return errors.push({
message: 'position should not have more than 3 elements',
level: 'message',
line: _.__line__ || line
});
}
if (!everyIs(_, 'number')) {
return errors.push({
message: 'each element in a position must be a number',
line: _.__line__ || line
});
}
if (options && options.precisionWarning) {
if (precisionWarningCount === maxPrecisionWarnings) {
precisionWarningCount += 1;
return errors.push({
message: 'truncated warnings: we\'ve encountered coordinate precision warning ' + maxPrecisionWarnings + ' times, no more warnings will be reported',
level: 'message',
line: _.__line__ || line
});
} else if (precisionWarningCount < maxPrecisionWarnings) {
_.forEach(function(num) {
var precision = 0;
var decimalStr = String(num).split('.')[1];
if (decimalStr !== undefined)
precision = decimalStr.length;
if (precision > maxPrecision) {
precisionWarningCount += 1;
return errors.push({
message: 'precision of coordinates should be reduced',
level: 'message',
line: _.__line__ || line
});
}
});
}
}
}
function positionArray(coords, type, depth, line) {
if (line === undefined && coords.__line__ !== undefined) {
line = coords.__line__;
}
if (depth === 0) {
return position(coords, line);
}
if (depth === 1 && type) {
if (type === 'LinearRing') {
if (!Array.isArray(coords[coords.length - 1])) {
errors.push({
message: 'a number was found where a coordinate array should have been found: this needs to be nested more deeply',
line: line
});
return true;
}
if (coords.length < 4) {
errors.push({
message: 'a LinearRing of coordinates needs to have four or more positions',
line: line
});
}
if (coords.length &&
(coords[coords.length - 1].length !== coords[0].length ||
!coords[coords.length - 1].every(function(pos, index) {
return coords[0][index] === pos;
}))) {
errors.push({
message: 'the first and last positions in a LinearRing of coordinates must be the same',
line: line
});
return true;
}
} else if (type === 'Line' && coords.length < 2) {
return errors.push({
message: 'a line needs to have two or more coordinates to be valid',
line: line
});
}
}
if (!Array.isArray(coords)) {
errors.push({
message: 'a number was found where a coordinate array should have been found: this needs to be nested more deeply',
line: line
});
} else {
var results = coords.map(function(c) {
return positionArray(c, type, depth - 1, c.__line__ || line);
});
return results.some(function(r) {
return r;
});
}
}
function crs(_) {
if (!_.crs) return;
var defaultCRSName = 'urn:ogc:def:crs:OGC:1.3:CRS84';
if (typeof _.crs === 'object' && _.crs.properties && _.crs.properties.name === defaultCRSName) {
errors.push({
message: 'old-style crs member is not recommended, this object is equivalent to the default and should be removed',
line: _.__line__
});
} else {
errors.push({
message: 'old-style crs member is not recommended',
line: _.__line__
});
}
}
function bbox(_) {
if (!_.bbox) {
return;
}
if (Array.isArray(_.bbox)) {
if (!everyIs(_.bbox, 'number')) {
errors.push({
message: 'each element in a bbox member must be a number',
line: _.bbox.__line__
});
}
if (!(_.bbox.length === 4 || _.bbox.length === 6)) {
errors.push({
message: 'bbox must contain 4 elements (for 2D) or 6 elements (for 3D)',
line: _.bbox.__line__
});
}
return errors.length;
}
errors.push({
message: 'bbox member must be an array of numbers, but is a ' + (typeof _.bbox),
line: _.__line__
});
}
function geometrySemantics(geom) {
if (geom.properties !== undefined) {
errors.push({
message: 'geometry object cannot contain a "properties" member',
line: geom.__line__
});
}
if (geom.geometry !== undefined) {
errors.push({
message: 'geometry object cannot contain a "geometry" member',
line: geom.__line__
});
}
if (geom.features !== undefined) {
errors.push({
message: 'geometry object cannot contain a "features" member',
line: geom.__line__
});
}
}
// https://tools.ietf.org/html/rfc7946#section-3.1.2
function Point(point) {
crs(point);
bbox(point);
geometrySemantics(point);
if (!requiredProperty(point, 'coordinates', 'array')) {
position(point.coordinates);
}
}
// https://tools.ietf.org/html/rfc7946#section-3.1.6
function Polygon(polygon) {
crs(polygon);
bbox(polygon);
if (!requiredProperty(polygon, 'coordinates', 'array')) {
if (!positionArray(polygon.coordinates, 'LinearRing', 2)) {
rightHandRule(polygon, errors);
}
}
}
// https://tools.ietf.org/html/rfc7946#section-3.1.7
function MultiPolygon(multiPolygon) {
crs(multiPolygon);
bbox(multiPolygon);
if (!requiredProperty(multiPolygon, 'coordinates', 'array')) {
if (!positionArray(multiPolygon.coordinates, 'LinearRing', 3)) {
rightHandRule(multiPolygon, errors);
}
}
}
// https://tools.ietf.org/html/rfc7946#section-3.1.4
function LineString(lineString) {
crs(lineString);
bbox(lineString);
if (!requiredProperty(lineString, 'coordinates', 'array')) {
positionArray(lineString.coordinates, 'Line', 1);
}
}
// https://tools.ietf.org/html/rfc7946#section-3.1.5
function MultiLineString(multiLineString) {
crs(multiLineString);
bbox(multiLineString);
if (!requiredProperty(multiLineString, 'coordinates', 'array')) {
positionArray(multiLineString.coordinates, 'Line', 2);
}
}
// https://tools.ietf.org/html/rfc7946#section-3.1.3
function MultiPoint(multiPoint) {
crs(multiPoint);
bbox(multiPoint);
if (!requiredProperty(multiPoint, 'coordinates', 'array')) {
positionArray(multiPoint.coordinates, '', 1);
}
}
// https://tools.ietf.org/html/rfc7946#section-3.1.8
function GeometryCollection(geometryCollection) {
crs(geometryCollection);
bbox(geometryCollection);
if (!requiredProperty(geometryCollection, 'geometries', 'array')) {
if (!everyIs(geometryCollection.geometries, 'object')) {
errors.push({
message: 'The geometries array in a GeometryCollection must contain only geometry objects',
line: geometryCollection.__line__
});
}
if (geometryCollection.geometries.length === 1) {
errors.push({
message: 'GeometryCollection with a single geometry should be avoided in favor of single part or a single object of multi-part type',
line: geometryCollection.geometries.__line__
});
}
geometryCollection.geometries.forEach(function(geometry) {
if (geometry) {
if (geometry.type === 'GeometryCollection') {
errors.push({
message: 'GeometryCollection should avoid nested geometry collections',
line: geometryCollection.geometries.__line__
});
}
root(geometry);
}
});
}
}
// https://tools.ietf.org/html/rfc7946#section-3.2
function Feature(feature) {
crs(feature);
bbox(feature);
// https://github.com/geojson/draft-geojson/blob/master/middle.mkd#feature-object
if (feature.id !== undefined &&
typeof feature.id !== 'string' &&
typeof feature.id !== 'number') {
errors.push({
message: 'Feature "id" member must have a string or number value',
line: feature.__line__
});
}
if (feature.features !== undefined) {
errors.push({
message: 'Feature object cannot contain a "features" member',
line: feature.__line__
});
}
if (feature.coordinates !== undefined) {
errors.push({
message: 'Feature object cannot contain a "coordinates" member',
line: feature.__line__
});
}
if (feature.type !== 'Feature') {
errors.push({
message: 'GeoJSON features must have a type=feature member',
line: feature.__line__
});
}
requiredProperty(feature, 'properties', 'object');
if (!requiredProperty(feature, 'geometry', 'object')) {
// https://tools.ietf.org/html/rfc7946#section-3.2
// tolerate null geometry
if (feature.geometry) root(feature.geometry);
}
}
var types = {
Point: Point,
Feature: Feature,
MultiPoint: MultiPoint,
LineString: LineString,
MultiLineString: MultiLineString,
FeatureCollection: FeatureCollection,
GeometryCollection: GeometryCollection,
Polygon: Polygon,
MultiPolygon: MultiPolygon
};
var typesLower = Object.keys(types).reduce(function(prev, curr) {
prev[curr.toLowerCase()] = curr;
return prev;
}, {});
if (typeof gj !== 'object' ||
gj === null ||
gj === undefined) {
errors.push({
message: 'The root of a GeoJSON object must be an object.',
line: 0
});
return errors;
}
root(gj);
errors.forEach(function(err) {
if ({}.hasOwnProperty.call(err, 'line') && err.line === undefined) {
delete err.line;
}
});
return errors;
}
module.exports.hint = hint;
},{"./rhr":10}],10:[function(require,module,exports){
function rad(x) {
return x * Math.PI / 180;
}
function isRingClockwise (coords) {
var area = 0;
if (coords.length > 2) {
var p1, p2;
for (var i = 0; i < coords.length - 1; i++) {
p1 = coords[i];
p2 = coords[i + 1];
area += rad(p2[0] - p1[0]) * (2 + Math.sin(rad(p1[1])) + Math.sin(rad(p2[1])));
}
}
return area >= 0;
}
function isPolyRHR (coords) {
if (coords && coords.length > 0) {
if (isRingClockwise(coords[0]))
return false;
var interiorCoords = coords.slice(1, coords.length);
if (!interiorCoords.every(isRingClockwise))
return false;
}
return true;
}
function rightHandRule (geometry) {
if (geometry.type === 'Polygon') {
return isPolyRHR(geometry.coordinates);
} else if (geometry.type === 'MultiPolygon') {
return geometry.coordinates.every(isPolyRHR);
}
}
module.exports = function validateRightHandRule(geometry, errors) {
if (!rightHandRule(geometry)) {
errors.push({
message: 'Polygons and MultiPolygons should follow the right-hand rule',
level: 'message',
line: geometry.__line__
});
}
};
},{}],11:[function(require,module,exports){
'use strict';
module.exports = Point;
/**
* A standalone point geometry with useful accessor, comparison, and
* modification methods.
*
* @class Point
* @param {Number} x the x-coordinate. this could be longitude or screen
* pixels, or any other sort of unit.
* @param {Number} y the y-coordinate. this could be latitude or screen
* pixels, or any other sort of unit.
* @example
* var point = new Point(-77, 38);
*/
function Point(x, y) {
this.x = x;
this.y = y;
}
Point.prototype = {
/**
* Clone this point, returning a new point that can be modified
* without affecting the old one.
* @return {Point} the clone
*/
clone: function() { return new Point(this.x, this.y); },
/**
* Add this point's x & y coordinates to another point,
* yielding a new point.
* @param {Point} p the other point
* @return {Point} output point
*/
add: function(p) { return this.clone()._add(p); },
/**
* Subtract this point's x & y coordinates to from point,
* yielding a new point.
* @param {Point} p the other point
* @return {Point} output point
*/
sub: function(p) { return this.clone()._sub(p); },
/**
* Multiply this point's x & y coordinates by point,
* yielding a new point.
* @param {Point} p the other point
* @return {Point} output point
*/
multByPoint: function(p) { return this.clone()._multByPoint(p); },
/**
* Divide this point's x & y coordinates by point,
* yielding a new point.
* @param {Point} p the other point
* @return {Point} output point
*/
divByPoint: function(p) { return this.clone()._divByPoint(p); },
/**
* Multiply this point's x & y coordinates by a factor,
* yielding a new point.
* @param {Point} k factor
* @return {Point} output point
*/
mult: function(k) { return this.clone()._mult(k); },
/**
* Divide this point's x & y coordinates by a factor,
* yielding a new point.
* @param {Point} k factor
* @return {Point} output point
*/
div: function(k) { return this.clone()._div(k); },
/**
* Rotate this point around the 0, 0 origin by an angle a,
* given in radians
* @param {Number} a angle to rotate around, in radians
* @return {Point} output point
*/
rotate: function(a) { return this.clone()._rotate(a); },
/**
* Rotate this point around p point by an angle a,
* given in radians
* @param {Number} a angle to rotate around, in radians
* @param {Point} p Point to rotate around
* @return {Point} output point
*/
rotateAround: function(a,p) { return this.clone()._rotateAround(a,p); },
/**
* Multiply this point by a 4x1 transformation matrix
* @param {Array<Number>} m transformation matrix
* @return {Point} output point
*/
matMult: function(m) { return this.clone()._matMult(m); },
/**
* Calculate this point but as a unit vector from 0, 0, meaning
* that the distance from the resulting point to the 0, 0
* coordinate will be equal to 1 and the angle from the resulting
* point to the 0, 0 coordinate will be the same as before.
* @return {Point} unit vector point
*/
unit: function() { return this.clone()._unit(); },
/**
* Compute a perpendicular point, where the new y coordinate
* is the old x coordinate and the new x coordinate is the old y
* coordinate multiplied by -1
* @return {Point} perpendicular point
*/
perp: function() { return this.clone()._perp(); },
/**
* Return a version of this point with the x & y coordinates
* rounded to integers.
* @return {Point} rounded point
*/
round: function() { return this.clone()._round(); },
/**
* Return the magitude of this point: this is the Euclidean
* distance from the 0, 0 coordinate to this point's x and y
* coordinates.
* @return {Number} magnitude
*/
mag: function() {
return Math.sqrt(this.x * this.x + this.y * this.y);
},
/**
* Judge whether this point is equal to another point, returning
* true or false.
* @param {Point} other the other point
* @return {boolean} whether the points are equal
*/
equals: function(other) {
return this.x === other.x &&
this.y === other.y;
},
/**
* Calculate the distance from this point to another point
* @param {Point} p the other point
* @return {Number} distance
*/
dist: function(p) {
return Math.sqrt(this.distSqr(p));
},
/**
* Calculate the distance from this point to another point,
* without the square root step. Useful if you're comparing
* relative distances.
* @param {Point} p the other point
* @return {Number} distance
*/
distSqr: function(p) {
var dx = p.x - this.x,
dy = p.y - this.y;
return dx * dx + dy * dy;
},
/**
* Get the angle from the 0, 0 coordinate to this point, in radians
* coordinates.
* @return {Number} angle
*/
angle: function() {
return Math.atan2(this.y, this.x);
},
/**
* Get the angle from this point to another point, in radians
* @param {Point} b the other point
* @return {Number} angle
*/
angleTo: function(b) {
return Math.atan2(this.y - b.y, this.x - b.x);
},
/**
* Get the angle between this point and another point, in radians
* @param {Point} b the other point
* @return {Number} angle
*/
angleWith: function(b) {
return this.angleWithSep(b.x, b.y);
},
/*
* Find the angle of the two vectors, solving the formula for
* the cross product a x b = |a||b|sin(θ) for θ.
* @param {Number} x the x-coordinate
* @param {Number} y the y-coordinate
* @return {Number} the angle in radians
*/
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;
}
};
/**
* Construct a point from an array if necessary, otherwise if the input
* is already a Point, or an unknown type, return it unchanged
* @param {Array<Number>|Point|*} a any kind of input value
* @return {Point} constructed point, or passed-through value.
* @example
* // this
* var point = Point.convert([0, 1]);
* // is equivalent to
* var point = new Point(0, 1);
*/
Point.convert = function (a) {
if (a instanceof Point) {
return a;
}
if (Array.isArray(a)) {
return new Point(a[0], a[1]);
}
return a;
};
},{}],12:[function(require,module,exports){
},{}],13:[function(require,module,exports){
module.exports=function e(t){switch(t&&t.type||null){case"FeatureCollection":return t.features=t.features.reduce(function(t,r){return t.concat(e(r))},[]),t;case"Feature":return t.geometry?e(t.geometry).map(function(e){var r={type:"Feature",properties:JSON.parse(JSON.stringify(t.properties)),geometry:e};return void 0!==t.id&&(r.id=t.id),r}):t;case"MultiPoint":return t.coordinates.map(function(e){return{type:"Point",coordinates:e}});case"MultiPolygon":return t.coordinates.map(function(e){return{type:"Polygon",coordinates:e}});case"MultiLineString":return t.coordinates.map(function(e){return{type:"LineString",coordinates:e}});case"GeometryCollection":return t.geometries.map(e).reduce(function(e,t){return e.concat(t)},[]);case"Point":case"Polygon":case"LineString":return[t]}};
},{}],14:[function(require,module,exports){
var hat = module.exports = function (bits, base) {
if (!base) base = 16;
if (bits === undefined) bits = 128;
if (bits <= 0) return '0';
var digits = Math.log(Math.pow(2, bits)) / Math.log(base);
for (var i = 2; digits === Infinity; i *= 2) {
digits = Math.log(Math.pow(2, bits / i)) / Math.log(base) * i;
}
var rem = digits - Math.floor(digits);
var res = '';
for (var i = 0; i < Math.floor(digits); i++) {
var x = Math.floor(Math.random() * base).toString(base);
res = x + res;
}
if (rem) {
var b = Math.pow(base, rem);
var x = Math.floor(Math.random() * b).toString(base);
res = x + res;
}
var parsed = parseInt(res, base);
if (parsed !== Infinity && parsed >= Math.pow(2, bits)) {
return hat(bits, base)
}
else return res;
};
hat.rack = function (bits, base, expandBy) {
var fn = function (data) {
var iters = 0;
do {
if (iters ++ > 10) {
if (expandBy) bits += expandBy;
else throw new Error('too many ID collisions, use more bits')
}
var id = hat(bits, base);
} while (Object.hasOwnProperty.call(hats, id));
hats[id] = data;
return id;
};
var hats = fn.hats = {};
fn.get = function (id) {
return fn.hats[id];
};
fn.set = function (id, value) {
fn.hats[id] = value;
return fn;
};
fn.bits = bits || 128;
fn.base = base || 16;
return fn;
};
},{}],15:[function(require,module,exports){
(function (process){
/* parser generated by jison 0.4.17 */
/*
Returns a Parser object of the following structure:
Parser: {
yy: {}
}
Parser.prototype: {
yy: {},
trace: function(),
symbols_: {associative list: name ==> number},
terminals_: {associative list: number ==> name},
productions_: [...],
performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
table: [...],
defaultActions: {...},
parseError: function(str, hash),
parse: function(input),
lexer: {
EOF: 1,
parseError: function(str, hash),
setInput: function(input),
input: function(),
unput: function(str),
more: function(),
less: function(n),
pastInput: function(),
upcomingInput: function(),
showPosition: function(),
test_match: function(regex_match_array, rule_index),
next: function(),
lex: function(),
begin: function(condition),
popState: function(),
_currentRules: function(),
topState: function(),
pushState: function(condition),
options: {
ranges: boolean (optional: true ==> token location info will include a .range[] member)
flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
backtrack_lexer: boolean (optional: true ==> lexer regexes are tested in order and for each matching regex the action code is invoked; the lexer terminates the scan when a token is returned by the action code)
},
performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
rules: [...],
conditions: {associative list: name ==> set},
}
}
token location info (@$, _$, etc.): {
first_line: n,
last_line: n,
first_column: n,
last_column: n,
range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
}
the parseError function receives a 'hash' object with these members for lexer and parser errors: {
text: (matched text)
token: (the produced terminal token, if any)
line: (yylineno)
}
while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
loc: (yylloc)
expected: (string describing the set of expected tokens)
recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
}
*/
var jsonlint = (function(){
var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[1,12],$V1=[1,13],$V2=[1,9],$V3=[1,10],$V4=[1,11],$V5=[1,14],$V6=[1,15],$V7=[14,18,22,24],$V8=[18,22],$V9=[22,24];
var parser = {trace: function trace() { },
yy: {},
symbols_: {"error":2,"JSONString":3,"STRING":4,"JSONNumber":5,"NUMBER":6,"JSONNullLiteral":7,"NULL":8,"JSONBooleanLiteral":9,"TRUE":10,"FALSE":11,"JSONText":12,"JSONValue":13,"EOF":14,"JSONObject":15,"JSONArray":16,"{":17,"}":18,"JSONMemberList":19,"JSONMember":20,":":21,",":22,"[":23,"]":24,"JSONElementList":25,"$accept":0,"$end":1},
terminals_: {2:"error",4:"STRING",6:"NUMBER",8:"NULL",10:"TRUE",11:"FALSE",14:"EOF",17:"{",18:"}",21:":",22:",",23:"[",24:"]"},
productions_: [0,[3,1],[5,1],[7,1],[9,1],[9,1],[12,2],[13,1],[13,1],[13,1],[13,1],[13,1],[13,1],[15,2],[15,3],[20,3],[19,1],[19,3],[16,2],[16,3],[25,1],[25,3]],
performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
/* this == yyval */
var $0 = $$.length - 1;
switch (yystate) {
case 1:
// replace escaped characters with actual character
this.$ = yytext.replace(/\\(\\|")/g, "$"+"1")
.replace(/\\n/g,'\n')
.replace(/\\r/g,'\r')
.replace(/\\t/g,'\t')
.replace(/\\v/g,'\v')
.replace(/\\f/g,'\f')
.replace(/\\b/g,'\b');
break;
case 2:
this.$ = Number(yytext);
break;
case 3:
this.$ = null;
break;
case 4:
this.$ = true;
break;
case 5:
this.$ = false;
break;
case 6:
return this.$ = $$[$0-1];
break;
case 13:
this.$ = {}; Object.defineProperty(this.$, '__line__', {
value: this._$.first_line,
enumerable: false
})
break;
case 14: case 19:
this.$ = $$[$0-1]; Object.defineProperty(this.$, '__line__', {
value: this._$.first_line,
enumerable: false
})
break;
case 15:
this.$ = [$$[$0-2], $$[$0]];
break;
case 16:
this.$ = {}; this.$[$$[$0][0]] = $$[$0][1];
break;
case 17:
this.$ = $$[$0-2];
if ($$[$0-2][$$[$0][0]] !== undefined) {
if (!this.$.__duplicateProperties__) {
Object.defineProperty(this.$, '__duplicateProperties__', {
value: [],
enumerable: false
});
}
this.$.__duplicateProperties__.push($$[$0][0]);
}
$$[$0-2][$$[$0][0]] = $$[$0][1];
break;
case 18:
this.$ = []; Object.defineProperty(this.$, '__line__', {
value: this._$.first_line,
enumerable: false
})
break;
case 20:
this.$ = [$$[$0]];
break;
case 21:
this.$ = $$[$0-2]; $$[$0-2].push($$[$0]);
break;
}
},
table: [{3:5,4:$V0,5:6,6:$V1,7:3,8:$V2,9:4,10:$V3,11:$V4,12:1,13:2,15:7,16:8,17:$V5,23:$V6},{1:[3]},{14:[1,16]},o($V7,[2,7]),o($V7,[2,8]),o($V7,[2,9]),o($V7,[2,10]),o($V7,[2,11]),o($V7,[2,12]),o($V7,[2,3]),o($V7,[2,4]),o($V7,[2,5]),o([14,18,21,22,24],[2,1]),o($V7,[2,2]),{3:20,4:$V0,18:[1,17],19:18,20:19},{3:5,4:$V0,5:6,6:$V1,7:3,8:$V2,9:4,10:$V3,11:$V4,13:23,15:7,16:8,17:$V5,23:$V6,24:[1,21],25:22},{1:[2,6]},o($V7,[2,13]),{18:[1,24],22:[1,25]},o($V8,[2,16]),{21:[1,26]},o($V7,[2,18]),{22:[1,28],24:[1,27]},o($V9,[2,20]),o($V7,[2,14]),{3:20,4:$V0,20:29},{3:5,4:$V0,5:6,6:$V1,7:3,8:$V2,9:4,10:$V3,11:$V4,13:30,15:7,16:8,17:$V5,23:$V6},o($V7,[2,19]),{3:5,4:$V0,5:6,6:$V1,7:3,8:$V2,9:4,10:$V3,11:$V4,13:31,15:7,16:8,17:$V5,23:$V6},o($V8,[2,17]),o($V8,[2,15]),o($V9,[2,21])],
defaultActions: {16:[2,6]},
parseError: function parseError(str, hash) {
if (hash.recoverable) {
this.trace(str);
} else {
function _parseError (msg, hash) {
this.message = msg;
this.hash = hash;
}
_parseError.prototype = Error;
throw new _parseError(str, hash);
}
},
parse: function parse(input) {
var self = this, stack = [0], tstack = [], vstack = [null], lstack = [], table = this.table, yytext = '', yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1;
var args = lstack.slice.call(arguments, 1);
var lexer = Object.create(this.lexer);
var sharedState = { yy: {} };
for (var k in this.yy) {
if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
sharedState.yy[k] = this.yy[k];
}
}
lexer.setInput(input, sharedState.yy);
sharedState.yy.lexer = lexer;
sharedState.yy.parser = this;
if (typeof lexer.yylloc == 'undefined') {
lexer.yylloc = {};
}
var yyloc = lexer.yylloc;
lstack.push(yyloc);
var ranges = lexer.options && lexer.options.ranges;
if (typeof sharedState.yy.parseError === 'function') {
this.parseError = sharedState.yy.parseError;
} else {
this.parseError = Object.getPrototypeOf(this).parseError;
}
function popStack(n) {
stack.length = stack.length - 2 * n;
vstack.length = vstack.length - n;
lstack.length = lstack.length - n;
}
_token_stack:
var lex = function () {
var token;
token = lexer.lex() || EOF;
if (typeof token !== 'number') {
token = self.symbols_[token] || token;
}
return token;
};
var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected;
while (true) {
state = stack[stack.length - 1];
if (this.defaultActions[state]) {
action = this.defaultActions[state];
} else {
if (symbol === null || typeof symbol == 'undefined') {
symbol = lex();
}
action = table[state] && table[state][symbol];
}
if (typeof action === 'undefined' || !action.length || !action[0]) {
var errStr = '';
expected = [];
for (p in table[state]) {
if (this.terminals_[p] && p > TERROR) {
expected.push('\'' + this.terminals_[p] + '\'');
}
}
if (lexer.showPosition) {
errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
} else {
errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
}
this.parseError(errStr, {
text: lexer.match,
token: this.terminals_[symbol] || symbol,
line: lexer.yylineno,
loc: yyloc,
expected: expected
});
}
if (action[0] instanceof Array && action.length > 1) {
throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
}
switch (action[0]) {
case 1:
stack.push(symbol);
vstack.push(lexer.yytext);
lstack.push(lexer.yylloc);
stack.push(action[1]);
symbol = null;
if (!preErrorSymbol) {
yyleng = lexer.yyleng;
yytext = lexer.yytext;
yylineno = lexer.yylineno;
yyloc = lexer.yylloc;
if (recovering > 0) {
recovering--;
}
} else {
symbol = preErrorSymbol;
preErrorSymbol = null;
}
break;
case 2:
len = this.productions_[action[1]][1];
yyval.$ = vstack[vstack.length - len];
yyval._$ = {
first_line: lstack[lstack.length - (len || 1)].first_line,
last_line: lstack[lstack.length - 1].last_line,
first_column: lstack[lstack.length - (len || 1)].first_column,
last_column: lstack[lstack.length - 1].last_column
};
if (ranges) {
yyval._$.range = [
lstack[lstack.length - (len || 1)].range[0],
lstack[lstack.length - 1].range[1]
];
}
r = this.performAction.apply(yyval, [
yytext,
yyleng,
yylineno,
sharedState.yy,
action[1],
vstack,
lstack
].concat(args));
if (typeof r !== 'undefined') {
return r;
}
if (len) {
stack = stack.slice(0, -1 * len * 2);
vstack = vstack.slice(0, -1 * len);
lstack = lstack.slice(0, -1 * len);
}
stack.push(this.productions_[action[1]][0]);
vstack.push(yyval.$);
lstack.push(yyval._$);
newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
stack.push(newState);
break;
case 3:
return true;
}
}
return true;
}};
/* generated by jison-lex 0.3.4 */
var lexer = (function(){
var lexer = ({
EOF:1,
parseError:function parseError(str, hash) {
if (this.yy.parser) {
this.yy.parser.parseError(str, hash);
} else {
throw new Error(str);
}
},
// resets the lexer, sets new input
setInput:function (input, yy) {
this.yy = yy || this.yy || {};
this._input = input;
this._more = this._backtrack = this.done = false;
this.yylineno = this.yyleng = 0;
this.yytext = this.matched = this.match = '';
this.conditionStack = ['INITIAL'];
this.yylloc = {
first_line: 1,
first_column: 0,
last_line: 1,
last_column: 0
};
if (this.options.ranges) {
this.yylloc.range = [0,0];
}
this.offset = 0;
return this;
},
// consumes and returns one char from the input
input:function () {
var ch = this._input[0];
this.yytext += ch;
this.yyleng++;
this.offset++;
this.match += ch;
this.matched += ch;
var lines = ch.match(/(?:\r\n?|\n).*/g);
if (lines) {
this.yylineno++;
this.yylloc.last_line++;
} else {
this.yylloc.last_column++;
}
if (this.options.ranges) {
this.yylloc.range[1]++;
}
this._input = this._input.slice(1);
return ch;
},
// unshifts one char (or a string) into the input
unput:function (ch) {
var len = ch.length;
var lines = ch.split(/(?:\r\n?|\n)/g);
this._input = ch + this._input;
this.yytext = this.yytext.substr(0, this.yytext.length - len);
//this.yyleng -= len;
this.offset -= len;
var oldLines = this.match.split(/(?:\r\n?|\n)/g);
this.match = this.match.substr(0, this.match.length - 1);
this.matched = this.matched.substr(0, this.matched.length - 1);
if (lines.length - 1) {
this.yylineno -= lines.length - 1;
}
var r = this.yylloc.range;
this.yylloc = {
first_line: this.yylloc.first_line,
last_line: this.yylineno + 1,
first_column: this.yylloc.first_column,
last_column: lines ?
(lines.length === oldLines.length ? this.yylloc.first_column : 0)
+ oldLines[oldLines.length - lines.length].length - lines[0].length :
this.yylloc.first_column - len
};
if (this.options.ranges) {
this.yylloc.range = [r[0], r[0] + this.yyleng - len];
}
this.yyleng = this.yytext.length;
return this;
},
// When called from action, caches matched text and appends it on next action
more:function () {
this._more = true;
return this;
},
// When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
reject:function () {
if (this.options.backtrack_lexer) {
this._backtrack = true;
} else {
return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n' + this.showPosition(), {
text: "",
token: null,
line: this.yylineno
});
}
return this;
},
// retain first n characters of the match
less:function (n) {
this.unput(this.match.slice(n));
},
// displays already matched input, i.e. for error messages
pastInput:function () {
var past = this.matched.substr(0, this.matched.length - this.match.length);
return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
},
// displays upcoming input, i.e. for error messages
upcomingInput:function () {
var next = this.match;
if (next.length < 20) {
next += this._input.substr(0, 20-next.length);
}
return (next.substr(0,20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
},
// displays the character position where the lexing error occurred, i.e. for error messages
showPosition:function () {
var pre = this.pastInput();
var c = new Array(pre.length + 1).join("-");
return pre + this.upcomingInput() + "\n" + c + "^";
},
// test the lexed token: return FALSE when not a match, otherwise return token
test_match:function (match, indexed_rule) {
var token,
lines,
backup;
if (this.options.backtrack_lexer) {
// save context
backup = {
yylineno: this.yylineno,
yylloc: {
first_line: this.yylloc.first_line,
last_line: this.last_line,
first_column: this.yylloc.first_column,
last_column: this.yylloc.last_column
},
yytext: this.yytext,
match: this.match,
matches: this.matches,
matched: this.matched,
yyleng: this.yyleng,
offset: this.offset,
_more: this._more,
_input: this._input,
yy: this.yy,
conditionStack: this.conditionStack.slice(0),
done: this.done
};
if (this.options.ranges) {
backup.yylloc.range = this.yylloc.range.slice(0);
}
}
lines = match[0].match(/(?:\r\n?|\n).*/g);
if (lines) {
this.yylineno += lines.length;
}
this.yylloc = {
first_line: this.yylloc.last_line,
last_line: this.yylineno + 1,
first_column: this.yylloc.last_column,
last_column: lines ?
lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length :
this.yylloc.last_column + match[0].length
};
this.yytext += match[0];
this.match += match[0];
this.matches = match;
this.yyleng = this.yytext.length;
if (this.options.ranges) {
this.yylloc.range = [this.offset, this.offset += this.yyleng];
}
this._more = false;
this._backtrack = false;
this._input = this._input.slice(match[0].length);
this.matched += match[0];
token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
if (this.done && this._input) {
this.done = false;
}
if (token) {
return token;
} else if (this._backtrack) {
// recover context
for (var k in backup) {
this[k] = backup[k];
}
return false; // rule action called reject() implying the next rule should be tested instead.
}
return false;
},
// return next match in input
next:function () {
if (this.done) {
return this.EOF;
}
if (!this._input) {
this.done = true;
}
var token,
match,
tempMatch,
index;
if (!this._more) {
this.yytext = '';
this.match = '';
}
var rules = this._currentRules();
for (var i = 0; i < rules.length; i++) {
tempMatch = this._input.match(this.rules[rules[i]]);
if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
match = tempMatch;
index = i;
if (this.options.backtrack_lexer) {
token = this.test_match(tempMatch, rules[i]);
if (token !== false) {
return token;
} else if (this._backtrack) {
match = false;
continue; // rule action called reject() implying a rule MISmatch.
} else {
// else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
return false;
}
} else if (!this.options.flex) {
break;
}
}
}
if (match) {
token = this.test_match(match, rules[index]);
if (token !== false) {
return token;
}
// else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
return false;
}
if (this._input === "") {
return this.EOF;
} else {
return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
text: "",
token: null,
line: this.yylineno
});
}
},
// return next match that has a token
lex:function lex() {
var r = this.next();
if (r) {
return r;
} else {
return this.lex();
}
},
// activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
begin:function begin(condition) {
this.conditionStack.push(condition);
},
// pop the previously active lexer condition state off the condition stack
popState:function popState() {
var n = this.conditionStack.length - 1;
if (n > 0) {
return this.conditionStack.pop();
} else {
return this.conditionStack[0];
}
},
// produce the lexer rule set which is active for the currently active lexer condition state
_currentRules:function _currentRules() {
if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
} else {
return this.conditions["INITIAL"].rules;
}
},
// return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
topState:function topState(n) {
n = this.conditionStack.length - 1 - Math.abs(n || 0);
if (n >= 0) {
return this.conditionStack[n];
} else {
return "INITIAL";
}
},
// alias for begin(condition)
pushState:function pushState(condition) {
this.begin(condition);
},
// return the number of states currently on the stack
stateStackSize:function stateStackSize() {
return this.conditionStack.length;
},
options: {},
performAction: function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
var YYSTATE=YY_START;
switch($avoiding_name_collisions) {
case 0:/* skip whitespace */
break;
case 1:return 6
break;
case 2:yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2); return 4
break;
case 3:return 17
break;
case 4:return 18
break;
case 5:return 23
break;
case 6:return 24
break;
case 7:return 22
break;
case 8:return 21
break;
case 9:return 10
break;
case 10:return 11
break;
case 11:return 8
break;
case 12:return 14
break;
case 13:return 'INVALID'
break;
}
},
rules: [/^(?:\s+)/,/^(?:(-?([0-9]|[1-9][0-9]+))(\.[0-9]+)?([eE][-+]?[0-9]+)?\b)/,/^(?:"(?:\\[\\"bfnrt\/]|\\u[a-fA-F0-9]{4}|[^\\\0-\x09\x0a-\x1f"])*")/,/^(?:\{)/,/^(?:\})/,/^(?:\[)/,/^(?:\])/,/^(?:,)/,/^(?::)/,/^(?:true\b)/,/^(?:false\b)/,/^(?:null\b)/,/^(?:$)/,/^(?:.)/],
conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13],"inclusive":true}}
});
return lexer;
})();
parser.lexer = lexer;
function Parser () {
this.yy = {};
}
Parser.prototype = parser;parser.Parser = Parser;
return new Parser;
})();
if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
exports.parser = jsonlint;
exports.Parser = jsonlint.Parser;
exports.parse = function () { return jsonlint.parse.apply(jsonlint, arguments); };
exports.main = function commonjsMain(args) {
if (!args[1]) {
console.log('Usage: '+args[0]+' FILE');
process.exit(1);
}
var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8");
return exports.parser.parse(source);
};
if (typeof module !== 'undefined' && require.main === module) {
exports.main(process.argv.slice(1));
}
}
}).call(this,require('_process'))
},{"_process":18,"fs":12,"path":17}],16:[function(require,module,exports){
(function (global){
/**
* Lodash (Custom Build) <https://lodash.com/>
* Build: `lodash modularize exports="npm" -o ./`
* Copyright JS Foundation and other contributors <https://js.foundation/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*/
/** Used as the size to enable large array optimizations. */
var LARGE_ARRAY_SIZE = 200;
/** Used to stand-in for `undefined` hash values. */
var HASH_UNDEFINED = '__lodash_hash_undefined__';
/** Used to compose bitmasks for value comparisons. */
var COMPARE_PARTIAL_FLAG = 1,
COMPARE_UNORDERED_FLAG = 2;
/** Used as references for various `Number` constants. */
var MAX_SAFE_INTEGER = 9007199254740991;
/** `Object#toString` result references. */
var argsTag = '[object Arguments]',
arrayTag = '[object Array]',
asyncTag = '[object AsyncFunction]',
boolTag = '[object Boolean]',
dateTag = '[object Date]',
errorTag = '[object Error]',
funcTag = '[object Function]',
genTag = '[object GeneratorFunction]',
mapTag = '[object Map]',
numberTag = '[object Number]',
nullTag = '[object Null]',
objectTag = '[object Object]',
promiseTag = '[object Promise]',
proxyTag = '[object Proxy]',
regexpTag = '[object RegExp]',
setTag = '[object Set]',
stringTag = '[object String]',
symbolTag = '[object Symbol]',
undefinedTag = '[object Undefined]',
weakMapTag = '[object WeakMap]';
var arrayBufferTag = '[object ArrayBuffer]',
dataViewTag = '[object DataView]',
float32Tag = '[object Float32Array]',
float64Tag = '[object Float64Array]',
int8Tag = '[object Int8Array]',
int16Tag = '[object Int16Array]',
int32Tag = '[object Int32Array]',
uint8Tag = '[object Uint8Array]',
uint8ClampedTag = '[object Uint8ClampedArray]',
uint16Tag = '[object Uint16Array]',
uint32Tag = '[object Uint32Array]';
/**
* Used to match `RegExp`
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
*/
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
/** Used to detect host constructors (Safari). */
var reIsHostCtor = /^\[object .+?Constructor\]$/;
/** Used to detect unsigned integer values. */
var reIsUint = /^(?:0|[1-9]\d*)$/;
/** Used to identify `toStringTag` values of typed arrays. */
var typedArrayTags = {};
typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
typedArrayTags[uint32Tag] = true;
typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
typedArrayTags[errorTag] = typedArrayTags[funcTag] =
typedArrayTags[mapTag] = typedArrayTags[numberTag] =
typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
typedArrayTags[setTag] = typedArrayTags[stringTag] =
typedArrayTags[weakMapTag] = false;
/** Detect free variable `global` from Node.js. */
var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
/** Detect free variable `self`. */
var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
/** Used as a reference to the global object. */
var root = freeGlobal || freeSelf || Function('return this')();
/** Detect free variable `exports`. */
var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
/** Detect free variable `module`. */
var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
/** Detect the popular CommonJS extension `module.exports`. */
var moduleExports = freeModule && freeModule.exports === freeExports;
/** Detect free variable `process` from Node.js. */
var freeProcess = moduleExports && freeGlobal.process;
/** Used to access faster Node.js helpers. */
var nodeUtil = (function() {
try {
return freeProcess && freeProcess.binding && freeProcess.binding('util');
} catch (e) {}
}());
/* Node.js helper references. */
var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
/**
* A specialized version of `_.filter` for arrays without support for
* iteratee shorthands.
*
* @private
* @param {Array} [array] The array to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {Array} Returns the new filtered array.
*/
function arrayFilter(array, predicate) {
var index = -1,
length = array == null ? 0 : array.length,
resIndex = 0,
result = [];
while (++index < length) {
var value = array[index];
if (predicate(value, index, array)) {
result[resIndex++] = value;
}
}
return result;
}
/**
* Appends the elements of `values` to `array`.
*
* @private
* @param {Array} array The array to modify.
* @param {Array} values The values to append.
* @returns {Array} Returns `array`.
*/
function arrayPush(array, values) {
var index = -1,
length = values.length,
offset = array.length;
while (++index < length) {
array[offset + index] = values[index];
}
return array;
}
/**
* A specialized version of `_.some` for arrays without support for iteratee
* shorthands.
*
* @private
* @param {Array} [array] The array to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {boolean} Returns `true` if any element passes the predicate check,
* else `false`.
*/
function arraySome(array, predicate) {
var index = -1,
length = array == null ? 0 : array.length;
while (++index < length) {
if (predicate(array[index], index, array)) {
return true;
}
}
return false;
}
/**
* The base implementation of `_.times` without support for iteratee shorthands
* or max array length checks.
*
* @private
* @param {number} n The number of times to invoke `iteratee`.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns the array of results.
*/
function baseTimes(n, iteratee) {
var index = -1,
result = Array(n);
while (++index < n) {
result[index] = iteratee(index);
}
return result;
}
/**
* The base implementation of `_.unary` without support for storing metadata.
*
* @private
* @param {Function} func The function to cap arguments for.
* @returns {Function} Returns the new capped function.
*/
function baseUnary(func) {
return function(value) {
return func(value);
};
}
/**
* Checks if a `cache` value for `key` exists.
*
* @private
* @param {Object} cache The cache to query.
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
*/
function cacheHas(cache, key) {
return cache.has(key);
}
/**
* Gets the value at `key` of `object`.
*
* @private
* @param {Object} [object] The object to query.
* @param {string} key The key of the property to get.
* @returns {*} Returns the property value.
*/
function getValue(object, key) {
return object == null ? undefined : object[key];
}
/**
* Converts `map` to its key-value pairs.
*
* @private
* @param {Object} map The map to convert.
* @returns {Array} Returns the key-value pairs.
*/
function mapToArray(map) {
var index = -1,
result = Array(map.size);
map.forEach(function(value, key) {
result[++index] = [key, value];
});
return result;
}
/**
* Creates a unary function that invokes `func` with its argument transformed.
*
* @private
* @param {Function} func The function to wrap.
* @param {Function} transform The argument transform.
* @returns {Function} Returns the new function.
*/
function overArg(func, transform) {
return function(arg) {
return func(transform(arg));
};
}
/**
* Converts `set` to an array of its values.
*
* @private
* @param {Object} set The set to convert.
* @returns {Array} Returns the values.
*/
function setToArray(set) {
var index = -1,
result = Array(set.size);
set.forEach(function(value) {
result[++index] = value;
});
return result;
}
/** Used for built-in method references. */
var arrayProto = Array.prototype,
funcProto = Function.prototype,
objectProto = Object.prototype;
/** Used to detect overreaching core-js shims. */
var coreJsData = root['__core-js_shared__'];
/** Used to resolve the decompiled source of functions. */
var funcToString = funcProto.toString;
/** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;
/** Used to detect methods masquerading as native. */
var maskSrcKey = (function() {
var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
return uid ? ('Symbol(src)_1.' + uid) : '';
}());
/**
* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
* of values.
*/
var nativeObjectToString = objectProto.toString;
/** Used to detect if a method is native. */
var reIsNative = RegExp('^' +
funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
);
/** Built-in value references. */
var Buffer = moduleExports ? root.Buffer : undefined,
Symbol = root.Symbol,
Uint8Array = root.Uint8Array,
propertyIsEnumerable = objectProto.propertyIsEnumerable,
splice = arrayProto.splice,
symToStringTag = Symbol ? Symbol.toStringTag : undefined;
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeGetSymbols = Object.getOwnPropertySymbols,
nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
nativeKeys = overArg(Object.keys, Object);
/* Built-in method references that are verified to be native. */
var DataView = getNative(root, 'DataView'),
Map = getNative(root, 'Map'),
Promise = getNative(root, 'Promise'),
Set = getNative(root, 'Set'),
WeakMap = getNative(root, 'WeakMap'),
nativeCreate = getNative(Object, 'create');
/** Used to detect maps, sets, and weakmaps. */
var dataViewCtorString = toSource(DataView),
mapCtorString = toSource(Map),
promiseCtorString = toSource(Promise),
setCtorString = toSource(Set),
weakMapCtorString = toSource(WeakMap);
/** Used to convert symbols to primitives and strings. */
var symbolProto = Symbol ? Symbol.prototype : undefined,
symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
/**
* Creates a hash object.
*
* @private
* @constructor
* @param {Array} [entries] The key-value pairs to cache.
*/
function Hash(entries) {
var index = -1,
length = entries == null ? 0 : entries.length;
this.clear();
while (++index < length) {
var entry = entries[index];
this.set(entry[0], entry[1]);
}
}
/**
* Removes all key-value entries from the hash.
*
* @private
* @name clear
* @memberOf Hash
*/
function hashClear() {
this.__data__ = nativeCreate ? nativeCreate(null) : {};
this.size = 0;
}
/**
* Removes `key` and its value from the hash.
*
* @private
* @name delete
* @memberOf Hash
* @param {Object} hash The hash to modify.
* @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
*/
function hashDelete(key) {
var result = this.has(key) && delete this.__data__[key];
this.size -= result ? 1 : 0;
return result;
}
/**
* Gets the hash value for `key`.
*
* @private
* @name get
* @memberOf Hash
* @param {string} key The key of the value to get.
* @returns {*} Returns the entry value.
*/
function hashGet(key) {
var data = this.__data__;
if (nativeCreate) {
var result = data[key];
return result === HASH_UNDEFINED ? undefined : result;
}
return hasOwnProperty.call(data, key) ? data[key] : undefined;
}
/**
* Checks if a hash value for `key` exists.
*
* @private
* @name has
* @memberOf Hash
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
*/
function hashHas(key) {
var data = this.__data__;
return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
}
/**
* Sets the hash `key` to `value`.
*
* @private
* @name set
* @memberOf Hash
* @param {string} key The key of the value to set.
* @param {*} value The value to set.
* @returns {Object} Returns the hash instance.
*/
function hashSet(key, value) {
var data = this.__data__;
this.size += this.has(key) ? 0 : 1;
data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
return this;
}
// Add methods to `Hash`.
Hash.prototype.clear = hashClear;
Hash.prototype['delete'] = hashDelete;
Hash.prototype.get = hashGet;
Hash.prototype.has = hashHas;
Hash.prototype.set = hashSet;
/**
* Creates an list cache object.
*
* @private
* @constructor
* @param {Array} [entries] The key-value pairs to cache.
*/
function ListCache(entries) {
var index = -1,
length = entries == null ? 0 : entries.length;
this.clear();
while (++index < length) {
var entry = entries[index];
this.set(entry[0], entry[1]);
}
}
/**
* Removes all key-value entries from the list cache.
*
* @private
* @name clear
* @memberOf ListCache
*/
function listCacheClear() {
this.__data__ = [];
this.size = 0;
}
/**
* Removes `key` and its value from the list cache.
*
* @private
* @name delete
* @memberOf ListCache
* @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
*/
function listCacheDelete(key) {
var data = this.__data__,
index = assocIndexOf(data, key);
if (index < 0) {
return false;
}
var lastIndex = data.length - 1;
if (index == lastIndex) {
data.pop();
} else {
splice.call(data, index, 1);
}
--this.size;
return true;
}
/**
* Gets the list cache value for `key`.
*
* @private
* @name get
* @memberOf ListCache
* @param {string} key The key of the value to get.
* @returns {*} Returns the entry value.
*/
function listCacheGet(key) {
var data = this.__data__,
index = assocIndexOf(data, key);
return index < 0 ? undefined : data[index][1];
}
/**
* Checks if a list cache value for `key` exists.
*
* @private
* @name has
* @memberOf ListCache
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
*/
function listCacheHas(key) {
return assocIndexOf(this.__data__, key) > -1;
}
/**
* Sets the list cache `key` to `value`.
*
* @private
* @name set
* @memberOf ListCache
* @param {string} key The key of the value to set.
* @param {*} value The value to set.
* @returns {Object} Returns the list cache instance.
*/
function listCacheSet(key, value) {
var data = this.__data__,
index = assocIndexOf(data, key);
if (index < 0) {
++this.size;
data.push([key, value]);
} else {
data[index][1] = value;
}
return this;
}
// Add methods to `ListCache`.
ListCache.prototype.clear = listCacheClear;
ListCache.prototype['delete'] = listCacheDelete;
ListCache.prototype.get = listCacheGet;
ListCache.prototype.has = listCacheHas;
ListCache.prototype.set = listCacheSet;
/**
* Creates a map cache object to store key-value pairs.
*
* @private
* @constructor
* @param {Array} [entries] The key-value pairs to cache.
*/
function MapCache(entries) {
var index = -1,
length = entries == null ? 0 : entries.length;
this.clear();
while (++index < length) {
var entry = entries[index];
this.set(entry[0], entry[1]);
}
}
/**
* Removes all key-value entries from the map.
*
* @private
* @name clear
* @memberOf MapCache
*/
function mapCacheClear() {
this.size = 0;
this.__data__ = {
'hash': new Hash,
'map': new (Map || ListCache),
'string': new Hash
};
}
/**
* Removes `key` and its value from the map.
*
* @private
* @name delete
* @memberOf MapCache
* @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
*/
function mapCacheDelete(key) {
var result = getMapData(this, key)['delete'](key);
this.size -= result ? 1 : 0;
return result;
}
/**
* Gets the map value for `key`.
*
* @private
* @name get
* @memberOf MapCache
* @param {string} key The key of the value to get.
* @returns {*} Returns the entry value.
*/
function mapCacheGet(key) {
return getMapData(this, key).get(key);
}
/**
* Checks if a map value for `key` exists.
*
* @private
* @name has
* @memberOf MapCache
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
*/
function mapCacheHas(key) {
return getMapData(this, key).has(key);
}
/**
* Sets the map `key` to `value`.
*
* @private
* @name set
* @memberOf MapCache
* @param {string} key The key of the value to set.
* @param {*} value The value to set.
* @returns {Object} Returns the map cache instance.
*/
function mapCacheSet(key, value) {
var data = getMapData(this, key),
size = data.size;
data.set(key, value);
this.size += data.size == size ? 0 : 1;
return this;
}
// Add methods to `MapCache`.
MapCache.prototype.clear = mapCacheClear;
MapCache.prototype['delete'] = mapCacheDelete;
MapCache.prototype.get = mapCacheGet;
MapCache.prototype.has = mapCacheHas;
MapCache.prototype.set = mapCacheSet;
/**
*
* Creates an array cache object to store unique values.
*
* @private
* @constructor
* @param {Array} [values] The values to cache.
*/
function SetCache(values) {
var index = -1,
length = values == null ? 0 : values.length;
this.__data__ = new MapCache;
while (++index < length) {
this.add(values[index]);
}
}
/**
* Adds `value` to the array cache.
*
* @private
* @name add
* @memberOf SetCache
* @alias push
* @param {*} value The value to cache.
* @returns {Object} Returns the cache instance.
*/
function setCacheAdd(value) {
this.__data__.set(value, HASH_UNDEFINED);
return this;
}
/**
* Checks if `value` is in the array cache.
*
* @private
* @name has
* @memberOf SetCache
* @param {*} value The value to search for.
* @returns {number} Returns `true` if `value` is found, else `false`.
*/
function setCacheHas(value) {
return this.__data__.has(value);
}
// Add methods to `SetCache`.
SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
SetCache.prototype.has = setCacheHas;
/**
* Creates a stack cache object to store key-value pairs.
*
* @private
* @constructor
* @param {Array} [entries] The key-value pairs to cache.
*/
function Stack(entries) {
var data = this.__data__ = new ListCache(entries);
this.size = data.size;
}
/**
* Removes all key-value entries from the stack.
*
* @private
* @name clear
* @memberOf Stack
*/
function stackClear() {
this.__data__ = new ListCache;
this.size = 0;
}
/**
* Removes `key` and its value from the stack.
*
* @private
* @name delete
* @memberOf Stack
* @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
*/
function stackDelete(key) {
var data = this.__data__,
result = data['delete'](key);
this.size = data.size;
return result;
}
/**
* Gets the stack value for `key`.
*
* @private
* @name get
* @memberOf Stack
* @param {string} key The key of the value to get.
* @returns {*} Returns the entry value.
*/
function stackGet(key) {
return this.__data__.get(key);
}
/**
* Checks if a stack value for `key` exists.
*
* @private
* @name has
* @memberOf Stack
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
*/
function stackHas(key) {
return this.__data__.has(key);
}
/**
* Sets the stack `key` to `value`.
*
* @private
* @name set
* @memberOf Stack
* @param {string} key The key of the value to set.
* @param {*} value The value to set.
* @returns {Object} Returns the stack cache instance.
*/
function stackSet(key, value) {
var data = this.__data__;
if (data instanceof ListCache) {
var pairs = data.__data__;
if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
pairs.push([key, value]);
this.size = ++data.size;
return this;
}
data = this.__data__ = new MapCache(pairs);
}
data.set(key, value);
this.size = data.size;
return this;
}
// Add methods to `Stack`.
Stack.prototype.clear = stackClear;
Stack.prototype['delete'] = stackDelete;
Stack.prototype.get = stackGet;
Stack.prototype.has = stackHas;
Stack.prototype.set = stackSet;
/**
* Creates an array of the enumerable property names of the array-like `value`.
*
* @private
* @param {*} value The value to query.
* @param {boolean} inherited Specify returning inherited property names.
* @returns {Array} Returns the array of property names.
*/
function arrayLikeKeys(value, inherited) {
var isArr = isArray(value),
isArg = !isArr && isArguments(value),
isBuff = !isArr && !isArg && isBuffer(value),
isType = !isArr && !isArg && !isBuff && isTypedArray(value),
skipIndexes = isArr || isArg || isBuff || isType,
result = skipIndexes ? baseTimes(value.length, String) : [],
length = result.length;
for (var key in value) {
if ((inherited || hasOwnProperty.call(value, key)) &&
!(skipIndexes && (
// Safari 9 has enumerable `arguments.length` in strict mode.
key == 'length' ||
// Node.js 0.10 has enumerable non-index properties on buffers.
(isBuff && (key == 'offset' || key == 'parent')) ||
// PhantomJS 2 has enumerable non-index properties on typed arrays.
(isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
// Skip index properties.
isIndex(key, length)
))) {
result.push(key);
}
}
return result;
}
/**
* Gets the index at which the `key` is found in `array` of key-value pairs.
*
* @private
* @param {Array} array The array to inspect.
* @param {*} key The key to search for.
* @returns {number} Returns the index of the matched value, else `-1`.
*/
function assocIndexOf(array, key) {
var length = array.length;
while (length--) {
if (eq(array[length][0], key)) {
return length;
}
}
return -1;
}
/**
* The base implementation of `getAllKeys` and `getAllKeysIn` which uses
* `keysFunc` and `symbolsFunc` to get the enumerable property names and
* symbols of `object`.
*
* @private
* @param {Object} object The object to query.
* @param {Function} keysFunc The function to get the keys of `object`.
* @param {Function} symbolsFunc The function to get the symbols of `object`.
* @returns {Array} Returns the array of property names and symbols.
*/
function baseGetAllKeys(object, keysFunc, symbolsFunc) {
var result = keysFunc(object);
return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
}
/**
* The base implementation of `getTag` without fallbacks for buggy environments.
*
* @private
* @param {*} value The value to query.
* @returns {string} Returns the `toStringTag`.
*/
function baseGetTag(value) {
if (value == null) {
return value === undefined ? undefinedTag : nullTag;
}
return (symToStringTag && symToStringTag in Object(value))
? getRawTag(value)
: objectToString(value);
}
/**
* The base implementation of `_.isArguments`.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an `arguments` object,
*/
function baseIsArguments(value) {
return isObjectLike(value) && baseGetTag(value) == argsTag;
}
/**
* The base implementation of `_.isEqual` which supports partial comparisons
* and tracks traversed objects.
*
* @private
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @param {boolean} bitmask The bitmask flags.
* 1 - Unordered comparison
* 2 - Partial comparison
* @param {Function} [customizer] The function to customize comparisons.
* @param {Object} [stack] Tracks traversed `value` and `other` objects.
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
*/
function baseIsEqual(value, other, bitmask, customizer, stack) {
if (value === other) {
return true;
}
if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
return value !== value && other !== other;
}
return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
}
/**
* A specialized version of `baseIsEqual` for arrays and objects which performs
* deep comparisons and tracks traversed objects enabling objects with circular
* references to be compared.
*
* @private
* @param {Object} object The object to compare.
* @param {Object} other The other object to compare.
* @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
* @param {Function} customizer The function to customize comparisons.
* @param {Function} equalFunc The function to determine equivalents of values.
* @param {Object} [stack] Tracks traversed `object` and `other` objects.
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
*/
function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
var objIsArr = isArray(object),
othIsArr = isArray(other),
objTag = objIsArr ? arrayTag : getTag(object),
othTag = othIsArr ? arrayTag : getTag(other);
objTag = objTag == argsTag ? objectTag : objTag;
othTag = othTag == argsTag ? objectTag : othTag;
var objIsObj = objTag == objectTag,
othIsObj = othTag == objectTag,
isSameTag = objTag == othTag;
if (isSameTag && isBuffer(object)) {
if (!isBuffer(other)) {
return false;
}
objIsArr = true;
objIsObj = false;
}
if (isSameTag && !objIsObj) {
stack || (stack = new Stack);
return (objIsArr || isTypedArray(object))
? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
: equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
}
if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
if (objIsWrapped || othIsWrapped) {
var objUnwrapped = objIsWrapped ? object.value() : object,
othUnwrapped = othIsWrapped ? other.value() : other;
stack || (stack = new Stack);
return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
}
}
if (!isSameTag) {
return false;
}
stack || (stack = new Stack);
return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
}
/**
* The base implementation of `_.isNative` without bad shim checks.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a native function,
* else `false`.
*/
function baseIsNative(value) {
if (!isObject(value) || isMasked(value)) {
return false;
}
var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
return pattern.test(toSource(value));
}
/**
* The base implementation of `_.isTypedArray` without Node.js optimizations.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
*/
function baseIsTypedArray(value) {
return isObjectLike(value) &&
isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
}
/**
* The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
*/
function baseKeys(object) {
if (!isPrototype(object)) {
return nativeKeys(object);
}
var result = [];
for (var key in Object(object)) {
if (hasOwnProperty.call(object, key) && key != 'constructor') {
result.push(key);
}
}
return result;
}
/**
* A specialized version of `baseIsEqualDeep` for arrays with support for
* partial deep comparisons.
*
* @private
* @param {Array} array The array to compare.
* @param {Array} other The other array to compare.
* @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
* @param {Function} customizer The function to customize comparisons.
* @param {Function} equalFunc The function to determine equivalents of values.
* @param {Object} stack Tracks traversed `array` and `other` objects.
* @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
*/
function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
arrLength = array.length,
othLength = other.length;
if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
return false;
}
// Assume cyclic values are equal.
var stacked = stack.get(array);
if (stacked && stack.get(other)) {
return stacked == other;
}
var index = -1,
result = true,
seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
stack.set(array, other);
stack.set(other, array);
// Ignore non-index properties.
while (++index < arrLength) {
var arrValue = array[index],
othValue = other[index];
if (customizer) {
var compared = isPartial
? customizer(othValue, arrValue, index, other, array, stack)
: customizer(arrValue, othValue, index, array, other, stack);
}
if (compared !== undefined) {
if (compared) {
continue;
}
result = false;
break;
}
// Recursively compare arrays (susceptible to call stack limits).
if (seen) {
if (!arraySome(other, function(othValue, othIndex) {
if (!cacheHas(seen, othIndex) &&
(arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
return seen.push(othIndex);
}
})) {
result = false;
break;
}
} else if (!(
arrValue === othValue ||
equalFunc(arrValue, othValue, bitmask, customizer, stack)
)) {
result = false;
break;
}
}
stack['delete'](array);
stack['delete'](other);
return result;
}
/**
* A specialized version of `baseIsEqualDeep` for comparing objects of
* the same `toStringTag`.
*
* **Note:** This function only supports comparing values with tags of
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
*
* @private
* @param {Object} object The object to compare.
* @param {Object} other The other object to compare.
* @param {string} tag The `toStringTag` of the objects to compare.
* @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
* @param {Function} customizer The function to customize comparisons.
* @param {Function} equalFunc The function to determine equivalents of values.
* @param {Object} stack Tracks traversed `object` and `other` objects.
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
*/
function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
switch (tag) {
case dataViewTag:
if ((object.byteLength != other.byteLength) ||
(object.byteOffset != other.byteOffset)) {
return false;
}
object = object.buffer;
other = other.buffer;
case arrayBufferTag:
if ((object.byteLength != other.byteLength) ||
!equalFunc(new Uint8Array(object), new Uint8Array(other))) {
return false;
}
return true;
case boolTag:
case dateTag:
case numberTag:
// Coerce booleans to `1` or `0` and dates to milliseconds.
// Invalid dates are coerced to `NaN`.
return eq(+object, +other);
case errorTag:
return object.name == other.name && object.message == other.message;
case regexpTag:
case stringTag:
// Coerce regexes to strings and treat strings, primitives and objects,
// as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
// for more details.
return object == (other + '');
case mapTag:
var convert = mapToArray;
case setTag:
var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
convert || (convert = setToArray);
if (object.size != other.size && !isPartial) {
return false;
}
// Assume cyclic values are equal.
var stacked = stack.get(object);
if (stacked) {
return stacked == other;
}
bitmask |= COMPARE_UNORDERED_FLAG;
// Recursively compare objects (susceptible to call stack limits).
stack.set(object, other);
var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
stack['delete'](object);
return result;
case symbolTag:
if (symbolValueOf) {
return symbolValueOf.call(object) == symbolValueOf.call(other);
}
}
return false;
}
/**
* A specialized version of `baseIsEqualDeep` for objects with support for
* partial deep comparisons.
*
* @private
* @param {Object} object The object to compare.
* @param {Object} other The other object to compare.
* @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
* @param {Function} customizer The function to customize comparisons.
* @param {Function} equalFunc The function to determine equivalents of values.
* @param {Object} stack Tracks traversed `object` and `other` objects.
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
*/
function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
objProps = getAllKeys(object),
objLength = objProps.length,
othProps = getAllKeys(other),
othLength = othProps.length;
if (objLength != othLength && !isPartial) {
return false;
}
var index = objLength;
while (index--) {
var key = objProps[index];
if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
return false;
}
}
// Assume cyclic values are equal.
var stacked = stack.get(object);
if (stacked && stack.get(other)) {
return stacked == other;
}
var result = true;
stack.set(object, other);
stack.set(other, object);
var skipCtor = isPartial;
while (++index < objLength) {
key = objProps[index];
var objValue = object[key],
othValue = other[key];
if (customizer) {
var compared = isPartial
? customizer(othValue, objValue, key, other, object, stack)
: customizer(objValue, othValue, key, object, other, stack);
}
// Recursively compare objects (susceptible to call stack limits).
if (!(compared === undefined
? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
: compared
)) {
result = false;
break;
}
skipCtor || (skipCtor = key == 'constructor');
}
if (result && !skipCtor) {
var objCtor = object.constructor,
othCtor = other.constructor;
// Non `Object` object instances with different constructors are not equal.
if (objCtor != othCtor &&
('constructor' in object && 'constructor' in other) &&
!(typeof objCtor == 'function' && objCtor instanceof objCtor &&
typeof othCtor == 'function' && othCtor instanceof othCtor)) {
result = false;
}
}
stack['delete'](object);
stack['delete'](other);
return result;
}
/**
* Creates an array of own enumerable property names and symbols of `object`.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names and symbols.
*/
function getAllKeys(object) {
return baseGetAllKeys(object, keys, getSymbols);
}
/**
* Gets the data for `map`.
*
* @private
* @param {Object} map The map to query.
* @param {string} key The reference key.
* @returns {*} Returns the map data.
*/
function getMapData(map, key) {
var data = map.__data__;
return isKeyable(key)
? data[typeof key == 'string' ? 'string' : 'hash']
: data.map;
}
/**
* Gets the native function at `key` of `object`.
*
* @private
* @param {Object} object The object to query.
* @param {string} key The key of the method to get.
* @returns {*} Returns the function if it's native, else `undefined`.
*/
function getNative(object, key) {
var value = getValue(object, key);
return baseIsNative(value) ? value : undefined;
}
/**
* A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
*
* @private
* @param {*} value The value to query.
* @returns {string} Returns the raw `toStringTag`.
*/
function getRawTag(value) {
var isOwn = hasOwnProperty.call(value, symToStringTag),
tag = value[symToStringTag];
try {
value[symToStringTag] = undefined;
var unmasked = true;
} catch (e) {}
var result = nativeObjectToString.call(value);
if (unmasked) {
if (isOwn) {
value[symToStringTag] = tag;
} else {
delete value[symToStringTag];
}
}
return result;
}
/**
* Creates an array of the own enumerable symbols of `object`.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the array of symbols.
*/
var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
if (object == null) {
return [];
}
object = Object(object);
return arrayFilter(nativeGetSymbols(object), function(symbol) {
return propertyIsEnumerable.call(object, symbol);
});
};
/**
* Gets the `toStringTag` of `value`.
*
* @private
* @param {*} value The value to query.
* @returns {string} Returns the `toStringTag`.
*/
var getTag = baseGetTag;
// Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
(Map && getTag(new Map) != mapTag) ||
(Promise && getTag(Promise.resolve()) != promiseTag) ||
(Set && getTag(new Set) != setTag) ||
(WeakMap && getTag(new WeakMap) != weakMapTag)) {
getTag = function(value) {
var result = baseGetTag(value),
Ctor = result == objectTag ? value.constructor : undefined,
ctorString = Ctor ? toSource(Ctor) : '';
if (ctorString) {
switch (ctorString) {
case dataViewCtorString: return dataViewTag;
case mapCtorString: return mapTag;
case promiseCtorString: return promiseTag;
case setCtorString: return setTag;
case weakMapCtorString: return weakMapTag;
}
}
return result;
};
}
/**
* Checks if `value` is a valid array-like index.
*
* @private
* @param {*} value The value to check.
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
*/
function isIndex(value, length) {
length = length == null ? MAX_SAFE_INTEGER : length;
return !!length &&
(typeof value == 'number' || reIsUint.test(value)) &&
(value > -1 && value % 1 == 0 && value < length);
}
/**
* Checks if `value` is suitable for use as unique object key.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is suitable, else `false`.
*/
function isKeyable(value) {
var type = typeof value;
return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
? (value !== '__proto__')
: (value === null);
}
/**
* Checks if `func` has its source masked.
*
* @private
* @param {Function} func The function to check.
* @returns {boolean} Returns `true` if `func` is masked, else `false`.
*/
function isMasked(func) {
return !!maskSrcKey && (maskSrcKey in func);
}
/**
* Checks if `value` is likely a prototype object.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
*/
function isPrototype(value) {
var Ctor = value && value.constructor,
proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
return value === proto;
}
/**
* Converts `value` to a string using `Object.prototype.toString`.
*
* @private
* @param {*} value The value to convert.
* @returns {string} Returns the converted string.
*/
function objectToString(value) {
return nativeObjectToString.call(value);
}
/**
* Converts `func` to its source code.
*
* @private
* @param {Function} func The function to convert.
* @returns {string} Returns the source code.
*/
function toSource(func) {
if (func != null) {
try {
return funcToString.call(func);
} catch (e) {}
try {
return (func + '');
} catch (e) {}
}
return '';
}
/**
* Performs a
* [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
* comparison between two values to determine if they are equivalent.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
* @example
*
* var object = { 'a': 1 };
* var other = { 'a': 1 };
*
* _.eq(object, object);
* // => true
*
* _.eq(object, other);
* // => false
*
* _.eq('a', 'a');
* // => true
*
* _.eq('a', Object('a'));
* // => false
*
* _.eq(NaN, NaN);
* // => true
*/
function eq(value, other) {
return value === other || (value !== value && other !== other);
}
/**
* Checks if `value` is likely an `arguments` object.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an `arguments` object,
* else `false`.
* @example
*
* _.isArguments(function() { return arguments; }());
* // => true
*
* _.isArguments([1, 2, 3]);
* // => false
*/
var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
!propertyIsEnumerable.call(value, 'callee');
};
/**
* Checks if `value` is classified as an `Array` object.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an array, else `false`.
* @example
*
* _.isArray([1, 2, 3]);
* // => true
*
* _.isArray(document.body.children);
* // => false
*
* _.isArray('abc');
* // => false
*
* _.isArray(_.noop);
* // => false
*/
var isArray = Array.isArray;
/**
* Checks if `value` is array-like. A value is considered array-like if it's
* not a function and has a `value.length` that's an integer greater than or
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
* @example
*
* _.isArrayLike([1, 2, 3]);
* // => true
*
* _.isArrayLike(document.body.children);
* // => true
*
* _.isArrayLike('abc');
* // => true
*
* _.isArrayLike(_.noop);
* // => false
*/
function isArrayLike(value) {
return value != null && isLength(value.length) && !isFunction(value);
}
/**
* Checks if `value` is a buffer.
*
* @static
* @memberOf _
* @since 4.3.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
* @example
*
* _.isBuffer(new Buffer(2));
* // => true
*
* _.isBuffer(new Uint8Array(2));
* // => false
*/
var isBuffer = nativeIsBuffer || stubFalse;
/**
* Performs a deep comparison between two values to determine if they are
* equivalent.
*
* **Note:** This method supports comparing arrays, array buffers, booleans,
* date objects, error objects, maps, numbers, `Object` objects, regexes,
* sets, strings, symbols, and typed arrays. `Object` objects are compared
* by their own, not inherited, enumerable properties. Functions and DOM
* nodes are compared by strict equality, i.e. `===`.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
* @example
*
* var object = { 'a': 1 };
* var other = { 'a': 1 };
*
* _.isEqual(object, other);
* // => true
*
* object === other;
* // => false
*/
function isEqual(value, other) {
return baseIsEqual(value, other);
}
/**
* Checks if `value` is classified as a `Function` object.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a function, else `false`.
* @example
*
* _.isFunction(_);
* // => true
*
* _.isFunction(/abc/);
* // => false
*/
function isFunction(value) {
if (!isObject(value)) {
return false;
}
// The use of `Object#toString` avoids issues with the `typeof` operator
// in Safari 9 which returns 'object' for typed arrays and other constructors.
var tag = baseGetTag(value);
return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
}
/**
* Checks if `value` is a valid array-like length.
*
* **Note:** This method is loosely based on
* [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
* @example
*
* _.isLength(3);
* // => true
*
* _.isLength(Number.MIN_VALUE);
* // => false
*
* _.isLength(Infinity);
* // => false
*
* _.isLength('3');
* // => false
*/
function isLength(value) {
return typeof value == 'number' &&
value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
}
/**
* Checks if `value` is the
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
* @example
*
* _.isObject({});
* // => true
*
* _.isObject([1, 2, 3]);
* // => true
*
* _.isObject(_.noop);
* // => true
*
* _.isObject(null);
* // => false
*/
function isObject(value) {
var type = typeof value;
return value != null && (type == 'object' || type == 'function');
}
/**
* Checks if `value` is object-like. A value is object-like if it's not `null`
* and has a `typeof` result of "object".
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
* @example
*
* _.isObjectLike({});
* // => true
*
* _.isObjectLike([1, 2, 3]);
* // => true
*
* _.isObjectLike(_.noop);
* // => false
*
* _.isObjectLike(null);
* // => false
*/
function isObjectLike(value) {
return value != null && typeof value == 'object';
}
/**
* Checks if `value` is classified as a typed array.
*
* @static
* @memberOf _
* @since 3.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
* @example
*
* _.isTypedArray(new Uint8Array);
* // => true
*
* _.isTypedArray([]);
* // => false
*/
var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
/**
* Creates an array of the own enumerable property names of `object`.
*
* **Note:** Non-object values are coerced to objects. See the
* [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
* for more details.
*
* @static
* @since 0.1.0
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
* @example
*
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* _.keys(new Foo);
* // => ['a', 'b'] (iteration order is not guaranteed)
*
* _.keys('hi');
* // => ['0', '1']
*/
function keys(object) {
return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
}
/**
* This method returns a new empty array.
*
* @static
* @memberOf _
* @since 4.13.0
* @category Util
* @returns {Array} Returns the new empty array.
* @example
*
* var arrays = _.times(2, _.stubArray);
*
* console.log(arrays);
* // => [[], []]
*
* console.log(arrays[0] === arrays[1]);
* // => false
*/
function stubArray() {
return [];
}
/**
* This method returns `false`.
*
* @static
* @memberOf _
* @since 4.13.0
* @category Util
* @returns {boolean} Returns `false`.
* @example
*
* _.times(2, _.stubFalse);
* // => [false, false]
*/
function stubFalse() {
return false;
}
module.exports = isEqual;
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],17:[function(require,module,exports){
(function (process){
// .dirname, .basename, and .extname methods are extracted from Node.js v8.11.1,
// backported and transplited with Babel, with backwards-compat fixes
// 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.
// resolves . and .. elements in a path array with directory names there
// must be no slashes, empty elements, or device names (c:\) in the array
// (so also no leading and trailing slashes - it does not distinguish
// relative and absolute paths)
function normalizeArray(parts, allowAboveRoot) {
// if the path tries to go above the root, `up` ends up > 0
var up = 0;
for (var i = parts.length - 1; i >= 0; i--) {
var last = parts[i];
if (last === '.') {
parts.splice(i, 1);
} else if (last === '..') {
parts.splice(i, 1);
up++;
} else if (up) {
parts.splice(i, 1);
up--;
}
}
// if the path is allowed to go above the root, restore leading ..s
if (allowAboveRoot) {
for (; up--; up) {
parts.unshift('..');
}
}
return parts;
}
// path.resolve([from ...], to)
// posix version
exports.resolve = function() {
var resolvedPath = '',
resolvedAbsolute = false;
for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
var path = (i >= 0) ? arguments[i] : process.cwd();
// Skip empty and invalid entries
if (typeof path !== 'string') {
throw new TypeError('Arguments to path.resolve must be strings');
} else if (!path) {
continue;
}
resolvedPath = path + '/' + resolvedPath;
resolvedAbsolute = path.charAt(0) === '/';
}
// At this point the path should be resolved to a full absolute path, but
// handle relative paths to be safe (might happen when process.cwd() fails)
// Normalize the path
resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
return !!p;
}), !resolvedAbsolute).join('/');
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
};
// path.normalize(path)
// posix version
exports.normalize = function(path) {
var isAbsolute = exports.isAbsolute(path),
trailingSlash = substr(path, -1) === '/';
// Normalize the path
path = normalizeArray(filter(path.split('/'), function(p) {
return !!p;
}), !isAbsolute).join('/');
if (!path && !isAbsolute) {
path = '.';
}
if (path && trailingSlash) {
path += '/';
}
return (isAbsolute ? '/' : '') + path;
};
// posix version
exports.isAbsolute = function(path) {
return path.charAt(0) === '/';
};
// posix version
exports.join = function() {
var paths = Array.prototype.slice.call(arguments, 0);
return exports.normalize(filter(paths, function(p, index) {
if (typeof p !== 'string') {
throw new TypeError('Arguments to path.join must be strings');
}
return p;
}).join('/'));
};
// path.relative(from, to)
// posix version
exports.relative = function(from, to) {
from = exports.resolve(from).substr(1);
to = exports.resolve(to).substr(1);
function trim(arr) {
var start = 0;
for (; start < arr.length; start++) {
if (arr[start] !== '') break;
}
var end = arr.length - 1;
for (; end >= 0; end--) {
if (arr[end] !== '') break;
}
if (start > end) return [];
return arr.slice(start, end - start + 1);
}
var fromParts = trim(from.split('/'));
var toParts = trim(to.split('/'));
var length = Math.min(fromParts.length, toParts.length);
var samePartsLength = length;
for (var i = 0; i < length; i++) {
if (fromParts[i] !== toParts[i]) {
samePartsLength = i;
break;
}
}
var outputParts = [];
for (var i = samePartsLength; i < fromParts.length; i++) {
outputParts.push('..');
}
outputParts = outputParts.concat(toParts.slice(samePartsLength));
return outputParts.join('/');
};
exports.sep = '/';
exports.delimiter = ':';
exports.dirname = function (path) {
if (typeof path !== 'string') path = path + '';
if (path.length === 0) return '.';
var code = path.charCodeAt(0);
var hasRoot = code === 47 /*/*/;
var end = -1;
var matchedSlash = true;
for (var i = path.length - 1; i >= 1; --i) {
code = path.charCodeAt(i);
if (code === 47 /*/*/) {
if (!matchedSlash) {
end = i;
break;
}
} else {
// We saw the first non-path separator
matchedSlash = false;
}
}
if (end === -1) return hasRoot ? '/' : '.';
if (hasRoot && end === 1) {
// return '//';
// Backwards-compat fix:
return '/';
}
return path.slice(0, end);
};
function basename(path) {
if (typeof path !== 'string') path = path + '';
var start = 0;
var end = -1;
var matchedSlash = true;
var i;
for (i = path.length - 1; i >= 0; --i) {
if (path.charCodeAt(i) === 47 /*/*/) {
// If we reached a path separator that was not part of a set of path
// separators at the end of the string, stop now
if (!matchedSlash) {
start = i + 1;
break;
}
} else if (end === -1) {
// We saw the first non-path separator, mark this as the end of our
// path component
matchedSlash = false;
end = i + 1;
}
}
if (end === -1) return '';
return path.slice(start, end);
}
// Uses a mixed approach for backwards-compatibility, as ext behavior changed
// in new Node.js versions, so only basename() above is backported here
exports.basename = function (path, ext) {
var f = basename(path);
if (ext && f.substr(-1 * ext.length) === ext) {
f = f.substr(0, f.length - ext.length);
}
return f;
};
exports.extname = function (path) {
if (typeof path !== 'string') path = path + '';
var startDot = -1;
var startPart = 0;
var end = -1;
var matchedSlash = true;
// Track the state of characters (if any) we see before our first dot and
// after any path separator we find
var preDotState = 0;
for (var i = path.length - 1; i >= 0; --i) {
var code = path.charCodeAt(i);
if (code === 47 /*/*/) {
// If we reached a path separator that was not part of a set of path
// separators at the end of the string, stop now
if (!matchedSlash) {
startPart = i + 1;
break;
}
continue;
}
if (end === -1) {
// We saw the first non-path separator, mark this as the end of our
// extension
matchedSlash = false;
end = i + 1;
}
if (code === 46 /*.*/) {
// If this is our first dot, mark it as the start of our extension
if (startDot === -1)
startDot = i;
else if (preDotState !== 1)
preDotState = 1;
} else if (startDot !== -1) {
// We saw a non-dot and non-path separator before our dot, so we should
// have a good chance at having a non-empty extension
preDotState = -1;
}
}
if (startDot === -1 || end === -1 ||
// We saw a non-dot character immediately before the dot
preDotState === 0 ||
// The (right-most) trimmed path component is exactly '..'
preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
return '';
}
return path.slice(startDot, end);
};
function filter (xs, f) {
if (xs.filter) return xs.filter(f);
var res = [];
for (var i = 0; i < xs.length; i++) {
if (f(xs[i], i, xs)) res.push(xs[i]);
}
return res;
}
// String.prototype.substr - negative index don't work in IE8
var substr = 'ab'.substr(-1) === 'b'
? function (str, start, len) { return str.substr(start, len) }
: function (str, start, len) {
if (start < 0) start = str.length + start;
return str.substr(start, len);
}
;
}).call(this,require('_process'))
},{"_process":18}],18:[function(require,module,exports){
// shim for using process in browser
var process = module.exports = {};
// cached from whatever global is present so that test runners that stub it
// don't break things. But we need to wrap it in a try catch in case it is
// wrapped in strict mode code which doesn't define any globals. It's inside a
// function because try/catches deoptimize in certain engines.
var cachedSetTimeout;
var cachedClearTimeout;
function defaultSetTimout() {
throw new Error('setTimeout has not been defined');
}
function defaultClearTimeout () {
throw new Error('clearTimeout has not been defined');
}
(function () {
try {
if (typeof setTimeout === 'function') {
cachedSetTimeout = setTimeout;
} else {
cachedSetTimeout = defaultSetTimout;
}
} catch (e) {
cachedSetTimeout = defaultSetTimout;
}
try {
if (typeof clearTimeout === 'function') {
cachedClearTimeout = clearTimeout;
} else {
cachedClearTimeout = defaultClearTimeout;
}
} catch (e) {
cachedClearTimeout = defaultClearTimeout;
}
} ())
function runTimeout(fun) {
if (cachedSetTimeout === setTimeout) {
//normal enviroments in sane situations
return setTimeout(fun, 0);
}
// if setTimeout wasn't available but was latter defined
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
cachedSetTimeout = setTimeout;
return setTimeout(fun, 0);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedSetTimeout(fun, 0);
} catch(e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedSetTimeout.call(null, fun, 0);
} catch(e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
return cachedSetTimeout.call(this, fun, 0);
}
}
}
function runClearTimeout(marker) {
if (cachedClearTimeout === clearTimeout) {
//normal enviroments in sane situations
return clearTimeout(marker);
}
// if clearTimeout wasn't available but was latter defined
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
cachedClearTimeout = clearTimeout;
return clearTimeout(marker);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedClearTimeout(marker);
} catch (e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedClearTimeout.call(null, marker);
} catch (e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
return cachedClearTimeout.call(this, marker);
}
}
}
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue) {
return;
}
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = runTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
runClearTimeout(timeout);
}
process.nextTick = function (fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
runTimeout(drainQueue);
}
};
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
function noop() {}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.prependListener = noop;
process.prependOnceListener = noop;
process.listeners = function (name) { return [] }
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };
},{}],19:[function(require,module,exports){
var traverse = module.exports = function (obj) {
return new Traverse(obj);
};
function Traverse (obj) {
this.value = obj;
}
Traverse.prototype.get = function (ps) {
var node = this.value;
for (var i = 0; i < ps.length; i ++) {
var key = ps[i];
if (!node || !hasOwnProperty.call(node, key)) {
node = undefined;
break;
}
node = node[key];
}
return node;
};
Traverse.prototype.has = function (ps) {
var node = this.value;
for (var i = 0; i < ps.length; i ++) {
var key = ps[i];
if (!node || !hasOwnProperty.call(node, key)) {
return false;
}
node = node[key];
}
return true;
};
Traverse.prototype.set = function (ps, value) {
var node = this.value;
for (var i = 0; i < ps.length - 1; i ++) {
var key = ps[i];
if (!hasOwnProperty.call(node, key)) node[key] = {};
node = node[key];
}
node[ps[i]] = value;
return value;
};
Traverse.prototype.map = function (cb) {
return walk(this.value, cb, true);
};
Traverse.prototype.forEach = function (cb) {
this.value = walk(this.value, cb, false);
return this.value;
};
Traverse.prototype.reduce = function (cb, init) {
var skip = arguments.length === 1;
var acc = skip ? this.value : init;
this.forEach(function (x) {
if (!this.isRoot || !skip) {
acc = cb.call(this, acc, x);
}
});
return acc;
};
Traverse.prototype.paths = function () {
var acc = [];
this.forEach(function (x) {
acc.push(this.path);
});
return acc;
};
Traverse.prototype.nodes = function () {
var acc = [];
this.forEach(function (x) {
acc.push(this.node);
});
return acc;
};
Traverse.prototype.clone = function () {
var parents = [], nodes = [];
return (function clone (src) {
for (var i = 0; i < parents.length; i++) {
if (parents[i] === src) {
return nodes[i];
}
}
if (typeof src === 'object' && src !== null) {
var dst = copy(src);
parents.push(src);
nodes.push(dst);
forEach(objectKeys(src), function (key) {
dst[key] = clone(src[key]);
});
parents.pop();
nodes.pop();
return dst;
}
else {
return src;
}
})(this.value);
};
function walk (root, cb, immutable) {
var path = [];
var parents = [];
var alive = true;
return (function walker (node_) {
var node = immutable ? copy(node_) : node_;
var modifiers = {};
var keepGoing = true;
var state = {
node : node,
node_ : node_,
path : [].concat(path),
parent : parents[parents.length - 1],
parents : parents,
key : path.slice(-1)[0],
isRoot : path.length === 0,
level : path.length,
circular : null,
update : function (x, stopHere) {
if (!state.isRoot) {
state.parent.node[state.key] = x;
}
state.node = x;
if (stopHere) keepGoing = false;
},
'delete' : function (stopHere) {
delete state.parent.node[state.key];
if (stopHere) keepGoing = false;
},
remove : function (stopHere) {
if (isArray(state.parent.node)) {
state.parent.node.splice(state.key, 1);
}
else {
delete state.parent.node[state.key];
}
if (stopHere) keepGoing = false;
},
keys : null,
before : function (f) { modifiers.before = f },
after : function (f) { modifiers.after = f },
pre : function (f) { modifiers.pre = f },
post : function (f) { modifiers.post = f },
stop : function () { alive = false },
block : function () { keepGoing = false }
};
if (!alive) return state;
function updateState() {
if (typeof state.node === 'object' && state.node !== null) {
if (!state.keys || state.node_ !== state.node) {
state.keys = objectKeys(state.node)
}
state.isLeaf = state.keys.length == 0;
for (var i = 0; i < parents.length; i++) {
if (parents[i].node_ === node_) {
state.circular = parents[i];
break;
}
}
}
else {
state.isLeaf = true;
state.keys = null;
}
state.notLeaf = !state.isLeaf;
state.notRoot = !state.isRoot;
}
updateState();
// use return values to update if defined
var ret = cb.call(state, state.node);
if (ret !== undefined && state.update) state.update(ret);
if (modifiers.before) modifiers.before.call(state, state.node);
if (!keepGoing) return state;
if (typeof state.node == 'object'
&& state.node !== null && !state.circular) {
parents.push(state);
updateState();
forEach(state.keys, function (key, i) {
path.push(key);
if (modifiers.pre) modifiers.pre.call(state, state.node[key], key);
var child = walker(state.node[key]);
if (immutable && hasOwnProperty.call(state.node, key)) {
state.node[key] = child.node;
}
child.isLast = i == state.keys.length - 1;
child.isFirst = i == 0;
if (modifiers.post) modifiers.post.call(state, child);
path.pop();
});
parents.pop();
}
if (modifiers.after) modifiers.after.call(state, state.node);
return state;
})(root).node;
}
function copy (src) {
if (typeof src === 'object' && src !== null) {
var dst;
if (isArray(src)) {
dst = [];
}
else if (isDate(src)) {
dst = new Date(src.getTime ? src.getTime() : src);
}
else if (isRegExp(src)) {
dst = new RegExp(src);
}
else if (isError(src)) {
dst = { message: src.message };
}
else if (isBoolean(src)) {
dst = new Boolean(src);
}
else if (isNumber(src)) {
dst = new Number(src);
}
else if (isString(src)) {
dst = new String(src);
}
else if (Object.create && Object.getPrototypeOf) {
dst = Object.create(Object.getPrototypeOf(src));
}
else if (src.constructor === Object) {
dst = {};
}
else {
var proto =
(src.constructor && src.constructor.prototype)
|| src.__proto__
|| {}
;
var T = function () {};
T.prototype = proto;
dst = new T;
}
forEach(objectKeys(src), function (key) {
dst[key] = src[key];
});
return dst;
}
else return src;
}
var objectKeys = Object.keys || function keys (obj) {
var res = [];
for (var key in obj) res.push(key)
return res;
};
function toS (obj) { return Object.prototype.toString.call(obj) }
function isDate (obj) { return toS(obj) === '[object Date]' }
function isRegExp (obj) { return toS(obj) === '[object RegExp]' }
function isError (obj) { return toS(obj) === '[object Error]' }
function isBoolean (obj) { return toS(obj) === '[object Boolean]' }
function isNumber (obj) { return toS(obj) === '[object Number]' }
function isString (obj) { return toS(obj) === '[object String]' }
var isArray = Array.isArray || function isArray (xs) {
return Object.prototype.toString.call(xs) === '[object Array]';
};
var forEach = function (xs, fn) {
if (xs.forEach) return xs.forEach(fn)
else for (var i = 0; i < xs.length; i++) {
fn(xs[i], i, xs);
}
};
forEach(objectKeys(Traverse.prototype), function (key) {
traverse[key] = function (obj) {
var args = [].slice.call(arguments, 1);
var t = new Traverse(obj);
return t[key].apply(t, args);
};
});
var hasOwnProperty = Object.hasOwnProperty || function (obj, key) {
return key in obj;
};
},{}],20:[function(require,module,exports){
module.exports.RADIUS = 6378137;
module.exports.FLATTENING = 1/298.257223563;
module.exports.POLAR_RADIUS = 6356752.3142;
},{}],21:[function(require,module,exports){
module.exports = extend
var hasOwnProperty = Object.prototype.hasOwnProperty;
function extend() {
var target = {}
for (var i = 0; i < arguments.length; i++) {
var source = arguments[i]
for (var key in source) {
if (hasOwnProperty.call(source, key)) {
target[key] = source[key]
}
}
}
return target
}
},{}],22:[function(require,module,exports){
"use strict";
var isEqual = require('lodash.isequal');
var normalize = require('@mapbox/geojson-normalize');
var hat = require('hat');
var featuresAt = require('./lib/features_at');
var stringSetsAreEqual = require('./lib/string_sets_are_equal');
var geojsonhint = require('@mapbox/geojsonhint');
var Constants = require('./constants');
var StringSet = require('./lib/string_set');
var featureTypes = {
Polygon: require('./feature_types/polygon'),
LineString: require('./feature_types/line_string'),
Point: require('./feature_types/point'),
MultiPolygon: require('./feature_types/multi_feature'),
MultiLineString: require('./feature_types/multi_feature'),
MultiPoint: require('./feature_types/multi_feature')
};
module.exports = function (ctx, api) {
api.modes = Constants.modes;
api.getFeatureIdsAt = function (point) {
var features = featuresAt.click({
point: point
}, null, ctx);
return features.map(function (feature) {
return feature.properties.id;
});
};
api.getSelectedIds = function () {
return ctx.store.getSelectedIds();
};
api.getSelected = function () {
return {
type: Constants.geojsonTypes.FEATURE_COLLECTION,
features: ctx.store.getSelectedIds().map(function (id) {
return ctx.store.get(id);
}).map(function (feature) {
return feature.toGeoJSON();
})
};
};
api.getSelectedPoints = function () {
return {
type: Constants.geojsonTypes.FEATURE_COLLECTION,
features: ctx.store.getSelectedCoordinates().map(function (coordinate) {
return {
type: Constants.geojsonTypes.FEATURE,
properties: {},
geometry: {
type: Constants.geojsonTypes.POINT,
coordinates: coordinate.coordinates
}
};
})
};
};
api.set = function (featureCollection) {
if (featureCollection.type === undefined || featureCollection.type !== Constants.geojsonTypes.FEATURE_COLLECTION || !Array.isArray(featureCollection.features)) {
throw new Error('Invalid FeatureCollection');
}
var renderBatch = ctx.store.createRenderBatch();
var toDelete = ctx.store.getAllIds().slice();
var newIds = api.add(featureCollection);
var newIdsLookup = new StringSet(newIds);
toDelete = toDelete.filter(function (id) {
return !newIdsLookup.has(id);
});
if (toDelete.length) {
api.delete(toDelete);
}
renderBatch();
return newIds;
};
api.add = function (geojson) {
var errors = geojsonhint.hint(geojson, {
precisionWarning: false
}).filter(function (e) {
return e.level !== 'message';
});
if (errors.length) {
throw new Error(errors[0].message);
}
var featureCollection = JSON.parse(JSON.stringify(normalize(geojson)));
var ids = featureCollection.features.map(function (feature) {
feature.id = feature.id || hat();
if (feature.geometry === null) {
throw new Error('Invalid geometry: null');
}
if (ctx.store.get(feature.id) === undefined || ctx.store.get(feature.id).type !== feature.geometry.type) {
// If the feature has not yet been created ...
var Model = featureTypes[feature.geometry.type];
if (Model === undefined) {
throw new Error("Invalid geometry type: ".concat(feature.geometry.type, "."));
}
var internalFeature = new Model(ctx, feature);
ctx.store.add(internalFeature);
} else {
// If a feature of that id has already been created, and we are swapping it out ...
var _internalFeature = ctx.store.get(feature.id);
_internalFeature.properties = feature.properties;
if (!isEqual(_internalFeature.getCoordinates(), feature.geometry.coordinates)) {
_internalFeature.incomingCoords(feature.geometry.coordinates);
}
}
return feature.id;
});
ctx.store.render();
return ids;
};
api.get = function (id) {
var feature = ctx.store.get(id);
if (feature) {
return feature.toGeoJSON();
}
};
api.getAll = function () {
return {
type: Constants.geojsonTypes.FEATURE_COLLECTION,
features: ctx.store.getAll().map(function (feature) {
return feature.toGeoJSON();
})
};
};
api.delete = function (featureIds) {
ctx.store.delete(featureIds, {
silent: true
}); // If we were in direct select mode and our selected feature no longer exists
// (because it was deleted), we need to get out of that mode.
if (api.getMode() === Constants.modes.DIRECT_SELECT && !ctx.store.getSelectedIds().length) {
ctx.events.changeMode(Constants.modes.SIMPLE_SELECT, undefined, {
silent: true
});
} else {
ctx.store.render();
}
return api;
};
api.deleteAll = function () {
ctx.store.delete(ctx.store.getAllIds(), {
silent: true
}); // If we were in direct select mode, now our selected feature no longer exists,
// so escape that mode.
if (api.getMode() === Constants.modes.DIRECT_SELECT) {
ctx.events.changeMode(Constants.modes.SIMPLE_SELECT, undefined, {
silent: true
});
} else {
ctx.store.render();
}
return api;
};
api.changeMode = function (mode) {
var modeOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
// Avoid changing modes just to re-select what's already selected
if (mode === Constants.modes.SIMPLE_SELECT && api.getMode() === Constants.modes.SIMPLE_SELECT) {
if (stringSetsAreEqual(modeOptions.featureIds || [], ctx.store.getSelectedIds())) return api; // And if we are changing the selection within simple_select mode, just change the selection,
// instead of stopping and re-starting the mode
ctx.store.setSelected(modeOptions.featureIds, {
silent: true
});
ctx.store.render();
return api;
}
if (mode === Constants.modes.DIRECT_SELECT && api.getMode() === Constants.modes.DIRECT_SELECT && modeOptions.featureId === ctx.store.getSelectedIds()[0]) {
return api;
}
ctx.events.changeMode(mode, modeOptions, {
silent: true
});
return api;
};
api.getMode = function () {
return ctx.events.getMode();
};
api.trash = function () {
ctx.events.trash({
silent: true
});
return api;
};
api.combineFeatures = function () {
ctx.events.combineFeatures({
silent: true
});
return api;
};
api.uncombineFeatures = function () {
ctx.events.uncombineFeatures({
silent: true
});
return api;
};
api.setFeatureProperty = function (featureId, property, value) {
ctx.store.setFeatureProperty(featureId, property, value);
return api;
};
return api;
};
},{"./constants":23,"./feature_types/line_string":26,"./feature_types/multi_feature":27,"./feature_types/point":28,"./feature_types/polygon":29,"./lib/features_at":37,"./lib/string_set":47,"./lib/string_sets_are_equal":48,"@mapbox/geojson-normalize":7,"@mapbox/geojsonhint":8,"hat":14,"lodash.isequal":16}],23:[function(require,module,exports){
"use strict";
module.exports = {
classes: {
CONTROL_BASE: 'mapboxgl-ctrl',
CONTROL_PREFIX: 'mapboxgl-ctrl-',
CONTROL_BUTTON: 'mapbox-gl-draw_ctrl-draw-btn',
CONTROL_BUTTON_LINE: 'mapbox-gl-draw_line',
CONTROL_BUTTON_POLYGON: 'mapbox-gl-draw_polygon',
CONTROL_BUTTON_POINT: 'mapbox-gl-draw_point',
CONTROL_BUTTON_TRASH: 'mapbox-gl-draw_trash',
CONTROL_BUTTON_COMBINE_FEATURES: 'mapbox-gl-draw_combine',
CONTROL_BUTTON_UNCOMBINE_FEATURES: 'mapbox-gl-draw_uncombine',
CONTROL_GROUP: 'mapboxgl-ctrl-group',
ATTRIBUTION: 'mapboxgl-ctrl-attrib',
ACTIVE_BUTTON: 'active',
BOX_SELECT: 'mapbox-gl-draw_boxselect'
},
sources: {
HOT: 'mapbox-gl-draw-hot',
COLD: 'mapbox-gl-draw-cold'
},
cursors: {
ADD: 'add',
MOVE: 'move',
DRAG: 'drag',
POINTER: 'pointer',
NONE: 'none'
},
types: {
POLYGON: 'polygon',
LINE: 'line_string',
POINT: 'point'
},
geojsonTypes: {
FEATURE: 'Feature',
POLYGON: 'Polygon',
LINE_STRING: 'LineString',
POINT: 'Point',
FEATURE_COLLECTION: 'FeatureCollection',
MULTI_PREFIX: 'Multi',
MULTI_POINT: 'MultiPoint',
MULTI_LINE_STRING: 'MultiLineString',
MULTI_POLYGON: 'MultiPolygon'
},
modes: {
DRAW_LINE_STRING: 'draw_line_string',
DRAW_POLYGON: 'draw_polygon',
DRAW_POINT: 'draw_point',
SIMPLE_SELECT: 'simple_select',
DIRECT_SELECT: 'direct_select',
STATIC: 'static'
},
events: {
CREATE: 'draw.create',
DELETE: 'draw.delete',
UPDATE: 'draw.update',
SELECTION_CHANGE: 'draw.selectionchange',
MODE_CHANGE: 'draw.modechange',
ACTIONABLE: 'draw.actionable',
RENDER: 'draw.render',
COMBINE_FEATURES: 'draw.combine',
UNCOMBINE_FEATURES: 'draw.uncombine'
},
updateActions: {
MOVE: 'move',
CHANGE_COORDINATES: 'change_coordinates'
},
meta: {
FEATURE: 'feature',
MIDPOINT: 'midpoint',
VERTEX: 'vertex'
},
activeStates: {
ACTIVE: 'true',
INACTIVE: 'false'
},
interactions: ['scrollZoom', 'boxZoom', 'dragRotate', 'dragPan', 'keyboard', 'doubleClickZoom', 'touchZoomRotate'],
LAT_MIN: -90,
LAT_RENDERED_MIN: -85,
LAT_MAX: 90,
LAT_RENDERED_MAX: 85,
LNG_MIN: -270,
LNG_MAX: 270
};
},{}],24:[function(require,module,exports){
"use strict";
var setupModeHandler = require('./lib/mode_handler');
var getFeaturesAndSetCursor = require('./lib/get_features_and_set_cursor');
var featuresAt = require('./lib/features_at');
var isClick = require('./lib/is_click');
var isTap = require('./lib/is_tap');
var Constants = require('./constants');
var objectToMode = require('./modes/object_to_mode');
module.exports = function (ctx) {
var modes = Object.keys(ctx.options.modes).reduce(function (m, k) {
m[k] = objectToMode(ctx.options.modes[k]);
return m;
}, {});
var mouseDownInfo = {};
var touchStartInfo = {};
var events = {};
var _currentModeName = null;
var currentMode = null;
events.drag = function (event, isDrag) {
if (isDrag({
point: event.point,
time: new Date().getTime()
})) {
ctx.ui.queueMapClasses({
mouse: Constants.cursors.DRAG
});
currentMode.drag(event);
} else {
event.originalEvent.stopPropagation();
}
};
events.mousedrag = function (event) {
events.drag(event, function (endInfo) {
return !isClick(mouseDownInfo, endInfo);
});
};
events.touchdrag = function (event) {
events.drag(event, function (endInfo) {
return !isTap(touchStartInfo, endInfo);
});
};
events.mousemove = function (event) {
var button = event.originalEvent.buttons !== undefined ? event.originalEvent.buttons : event.originalEvent.which;
if (button === 1) {
return events.mousedrag(event);
}
var target = getFeaturesAndSetCursor(event, ctx);
event.featureTarget = target;
currentMode.mousemove(event);
};
events.mousedown = function (event) {
mouseDownInfo = {
time: new Date().getTime(),
point: event.point
};
var target = getFeaturesAndSetCursor(event, ctx);
event.featureTarget = target;
currentMode.mousedown(event);
};
events.mouseup = function (event) {
var target = getFeaturesAndSetCursor(event, ctx);
event.featureTarget = target;
if (isClick(mouseDownInfo, {
point: event.point,
time: new Date().getTime()
})) {
currentMode.click(event);
} else {
currentMode.mouseup(event);
}
};
events.mouseout = function (event) {
currentMode.mouseout(event);
};
events.touchstart = function (event) {
if (!ctx.options.touchEnabled) {
return;
}
touchStartInfo = {
time: new Date().getTime(),
point: event.point
};
var target = featuresAt.touch(event, null, ctx)[0]; // If there are no mapbox targets nearby, let the event propagate through
if (!target) {
return;
} // Prevent emulated mouse events because we will fully handle the touch here.
// This does not stop the touch events from propogating to mapbox though. (because of the lines above)
event.originalEvent.preventDefault();
event.featureTarget = target;
currentMode.touchstart(event);
};
events.touchmove = function (event) {
event.originalEvent.preventDefault();
if (!ctx.options.touchEnabled) {
return;
}
currentMode.touchmove(event);
return events.touchdrag(event);
};
events.touchend = function (event) {
if (!ctx.options.touchEnabled) {
return;
}
var target = featuresAt.touch(event, null, ctx)[0]; // If there are no mapbox targets nearby, let the event propagate through
if (!target) {
return;
}
event.originalEvent.preventDefault();
event.featureTarget = target;
if (isTap(touchStartInfo, {
time: new Date().getTime(),
point: event.point
})) {
currentMode.tap(event);
} else {
currentMode.touchend(event);
}
}; // 8 - Backspace
// 46 - Delete
var isKeyModeValid = function isKeyModeValid(code) {
return !(code === 8 || code === 46 || code >= 48 && code <= 57);
};
events.keydown = function (event) {
if ((event.srcElement || event.target).classList[0] !== 'mapboxgl-canvas') return; // we only handle events on the map
if ((event.keyCode === 8 || event.keyCode === 46) && ctx.options.controls.trash) {
event.preventDefault();
currentMode.trash();
} else if (isKeyModeValid(event.keyCode)) {
currentMode.keydown(event);
} else if (event.keyCode === 49 && ctx.options.controls.point) {
changeMode(Constants.modes.DRAW_POINT);
} else if (event.keyCode === 50 && ctx.options.controls.line_string) {
changeMode(Constants.modes.DRAW_LINE_STRING);
} else if (event.keyCode === 51 && ctx.options.controls.polygon) {
changeMode(Constants.modes.DRAW_POLYGON);
}
};
events.keyup = function (event) {
if (isKeyModeValid(event.keyCode)) {
currentMode.keyup(event);
}
};
events.zoomend = function () {
ctx.store.changeZoom();
};
events.data = function (event) {
if (event.dataType === 'style') {
var setup = ctx.setup,
map = ctx.map,
options = ctx.options,
store = ctx.store;
var hasLayers = options.styles.some(function (style) {
return map.getLayer(style.id);
});
if (!hasLayers) {
setup.addLayers();
store.setDirty();
store.render();
}
}
};
function changeMode(modename, nextModeOptions) {
var eventOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
currentMode.stop();
var modebuilder = modes[modename];
if (modebuilder === undefined) {
throw new Error("".concat(modename, " is not valid"));
}
_currentModeName = modename;
var mode = modebuilder(ctx, nextModeOptions);
currentMode = setupModeHandler(mode, ctx);
if (!eventOptions.silent) {
ctx.map.fire(Constants.events.MODE_CHANGE, {
mode: modename
});
}
ctx.store.setDirty();
ctx.store.render();
}
var actionState = {
trash: false,
combineFeatures: false,
uncombineFeatures: false
};
function actionable(actions) {
var changed = false;
Object.keys(actions).forEach(function (action) {
if (actionState[action] === undefined) throw new Error('Invalid action type');
if (actionState[action] !== actions[action]) changed = true;
actionState[action] = actions[action];
});
if (changed) ctx.map.fire(Constants.events.ACTIONABLE, {
actions: actionState
});
}
var api = {
start: function start() {
_currentModeName = ctx.options.defaultMode;
currentMode = setupModeHandler(modes[_currentModeName](ctx), ctx);
},
changeMode: changeMode,
actionable: actionable,
currentModeName: function currentModeName() {
return _currentModeName;
},
currentModeRender: function currentModeRender(geojson, push) {
return currentMode.render(geojson, push);
},
fire: function fire(name, event) {
if (events[name]) {
events[name](event);
}
},
addEventListeners: function addEventListeners() {
ctx.map.on('mousemove', events.mousemove);
ctx.map.on('mousedown', events.mousedown);
ctx.map.on('mouseup', events.mouseup);
ctx.map.on('data', events.data);
ctx.map.on('touchmove', events.touchmove);
ctx.map.on('touchstart', events.touchstart);
ctx.map.on('touchend', events.touchend);
ctx.container.addEventListener('mouseout', events.mouseout);
if (ctx.options.keybindings) {
ctx.container.addEventListener('keydown', events.keydown);
ctx.container.addEventListener('keyup', events.keyup);
}
},
removeEventListeners: function removeEventListeners() {
ctx.map.off('mousemove', events.mousemove);
ctx.map.off('mousedown', events.mousedown);
ctx.map.off('mouseup', events.mouseup);
ctx.map.off('data', events.data);
ctx.map.off('touchmove', events.touchmove);
ctx.map.off('touchstart', events.touchstart);
ctx.map.off('touchend', events.touchend);
ctx.container.removeEventListener('mouseout', events.mouseout);
if (ctx.options.keybindings) {
ctx.container.removeEventListener('keydown', events.keydown);
ctx.container.removeEventListener('keyup', events.keyup);
}
},
trash: function trash(options) {
currentMode.trash(options);
},
combineFeatures: function combineFeatures() {
currentMode.combineFeatures();
},
uncombineFeatures: function uncombineFeatures() {
currentMode.uncombineFeatures();
},
getMode: function getMode() {
return _currentModeName;
}
};
return api;
};
},{"./constants":23,"./lib/features_at":37,"./lib/get_features_and_set_cursor":38,"./lib/is_click":39,"./lib/is_tap":41,"./lib/mode_handler":43,"./modes/object_to_mode":59}],25:[function(require,module,exports){
"use strict";
var hat = require('hat');
var Constants = require('../constants');
var Feature = function Feature(ctx, geojson) {
this.ctx = ctx;
this.properties = geojson.properties || {};
this.coordinates = geojson.geometry.coordinates;
this.id = geojson.id || hat();
this.type = geojson.geometry.type;
};
Feature.prototype.changed = function () {
this.ctx.store.featureChanged(this.id);
};
Feature.prototype.incomingCoords = function (coords) {
this.setCoordinates(coords);
};
Feature.prototype.setCoordinates = function (coords) {
this.coordinates = coords;
this.changed();
};
Feature.prototype.getCoordinates = function () {
return JSON.parse(JSON.stringify(this.coordinates));
};
Feature.prototype.setProperty = function (property, value) {
this.properties[property] = value;
};
Feature.prototype.toGeoJSON = function () {
return JSON.parse(JSON.stringify({
id: this.id,
type: Constants.geojsonTypes.FEATURE,
properties: this.properties,
geometry: {
coordinates: this.getCoordinates(),
type: this.type
}
}));
};
Feature.prototype.internal = function (mode) {
var properties = {
id: this.id,
meta: Constants.meta.FEATURE,
'meta:type': this.type,
active: Constants.activeStates.INACTIVE,
mode: mode
};
if (this.ctx.options.userProperties) {
for (var name in this.properties) {
properties["user_".concat(name)] = this.properties[name];
}
}
return {
type: Constants.geojsonTypes.FEATURE,
properties: properties,
geometry: {
coordinates: this.getCoordinates(),
type: this.type
}
};
};
module.exports = Feature;
},{"../constants":23,"hat":14}],26:[function(require,module,exports){
"use strict";
var Feature = require('./feature');
var LineString = function LineString(ctx, geojson) {
Feature.call(this, ctx, geojson);
};
LineString.prototype = Object.create(Feature.prototype);
LineString.prototype.isValid = function () {
return this.coordinates.length > 1;
};
LineString.prototype.addCoordinate = function (path, lng, lat) {
this.changed();
var id = parseInt(path, 10);
this.coordinates.splice(id, 0, [lng, lat]);
};
LineString.prototype.getCoordinate = function (path) {
var id = parseInt(path, 10);
return JSON.parse(JSON.stringify(this.coordinates[id]));
};
LineString.prototype.removeCoordinate = function (path) {
this.changed();
this.coordinates.splice(parseInt(path, 10), 1);
};
LineString.prototype.updateCoordinate = function (path, lng, lat) {
var id = parseInt(path, 10);
this.coordinates[id] = [lng, lat];
this.changed();
};
module.exports = LineString;
},{"./feature":25}],27:[function(require,module,exports){
"use strict";
var Feature = require('./feature');
var Constants = require('../constants');
var hat = require('hat');
var models = {
MultiPoint: require('./point'),
MultiLineString: require('./line_string'),
MultiPolygon: require('./polygon')
};
var takeAction = function takeAction(features, action, path, lng, lat) {
var parts = path.split('.');
var idx = parseInt(parts[0], 10);
var tail = !parts[1] ? null : parts.slice(1).join('.');
return features[idx][action](tail, lng, lat);
};
var MultiFeature = function MultiFeature(ctx, geojson) {
Feature.call(this, ctx, geojson);
delete this.coordinates;
this.model = models[geojson.geometry.type];
if (this.model === undefined) throw new TypeError("".concat(geojson.geometry.type, " is not a valid type"));
this.features = this._coordinatesToFeatures(geojson.geometry.coordinates);
};
MultiFeature.prototype = Object.create(Feature.prototype);
MultiFeature.prototype._coordinatesToFeatures = function (coordinates) {
var _this = this;
var Model = this.model.bind(this);
return coordinates.map(function (coords) {
return new Model(_this.ctx, {
id: hat(),
type: Constants.geojsonTypes.FEATURE,
properties: {},
geometry: {
coordinates: coords,
type: _this.type.replace('Multi', '')
}
});
});
};
MultiFeature.prototype.isValid = function () {
return this.features.every(function (f) {
return f.isValid();
});
};
MultiFeature.prototype.setCoordinates = function (coords) {
this.features = this._coordinatesToFeatures(coords);
this.changed();
};
MultiFeature.prototype.getCoordinate = function (path) {
return takeAction(this.features, 'getCoordinate', path);
};
MultiFeature.prototype.getCoordinates = function () {
return JSON.parse(JSON.stringify(this.features.map(function (f) {
if (f.type === Constants.geojsonTypes.POLYGON) return f.getCoordinates();
return f.coordinates;
})));
};
MultiFeature.prototype.updateCoordinate = function (path, lng, lat) {
takeAction(this.features, 'updateCoordinate', path, lng, lat);
this.changed();
};
MultiFeature.prototype.addCoordinate = function (path, lng, lat) {
takeAction(this.features, 'addCoordinate', path, lng, lat);
this.changed();
};
MultiFeature.prototype.removeCoordinate = function (path) {
takeAction(this.features, 'removeCoordinate', path);
this.changed();
};
MultiFeature.prototype.getFeatures = function () {
return this.features;
};
module.exports = MultiFeature;
},{"../constants":23,"./feature":25,"./line_string":26,"./point":28,"./polygon":29,"hat":14}],28:[function(require,module,exports){
"use strict";
var Feature = require('./feature');
var Point = function Point(ctx, geojson) {
Feature.call(this, ctx, geojson);
};
Point.prototype = Object.create(Feature.prototype);
Point.prototype.isValid = function () {
return typeof this.coordinates[0] === 'number' && typeof this.coordinates[1] === 'number';
};
Point.prototype.updateCoordinate = function (pathOrLng, lngOrLat, lat) {
if (arguments.length === 3) {
this.coordinates = [lngOrLat, lat];
} else {
this.coordinates = [pathOrLng, lngOrLat];
}
this.changed();
};
Point.prototype.getCoordinate = function () {
return this.getCoordinates();
};
module.exports = Point;
},{"./feature":25}],29:[function(require,module,exports){
"use strict";
var Feature = require('./feature');
var Polygon = function Polygon(ctx, geojson) {
Feature.call(this, ctx, geojson);
this.coordinates = this.coordinates.map(function (ring) {
return ring.slice(0, -1);
});
};
Polygon.prototype = Object.create(Feature.prototype);
Polygon.prototype.isValid = function () {
if (this.coordinates.length === 0) return false;
return this.coordinates.every(function (ring) {
return ring.length > 2;
});
}; // Expects valid geoJSON polygon geometry: first and last positions must be equivalent.
Polygon.prototype.incomingCoords = function (coords) {
this.coordinates = coords.map(function (ring) {
return ring.slice(0, -1);
});
this.changed();
}; // Does NOT expect valid geoJSON polygon geometry: first and last positions should not be equivalent.
Polygon.prototype.setCoordinates = function (coords) {
this.coordinates = coords;
this.changed();
};
Polygon.prototype.addCoordinate = function (path, lng, lat) {
this.changed();
var ids = path.split('.').map(function (x) {
return parseInt(x, 10);
});
var ring = this.coordinates[ids[0]];
ring.splice(ids[1], 0, [lng, lat]);
};
Polygon.prototype.removeCoordinate = function (path) {
this.changed();
var ids = path.split('.').map(function (x) {
return parseInt(x, 10);
});
var ring = this.coordinates[ids[0]];
if (ring) {
ring.splice(ids[1], 1);
if (ring.length < 3) {
this.coordinates.splice(ids[0], 1);
}
}
};
Polygon.prototype.getCoordinate = function (path) {
var ids = path.split('.').map(function (x) {
return parseInt(x, 10);
});
var ring = this.coordinates[ids[0]];
return JSON.parse(JSON.stringify(ring[ids[1]]));
};
Polygon.prototype.getCoordinates = function () {
return this.coordinates.map(function (coords) {
return coords.concat([coords[0]]);
});
};
Polygon.prototype.updateCoordinate = function (path, lng, lat) {
this.changed();
var parts = path.split('.');
var ringId = parseInt(parts[0], 10);
var coordId = parseInt(parts[1], 10);
if (this.coordinates[ringId] === undefined) {
this.coordinates[ringId] = [];
}
this.coordinates[ringId][coordId] = [lng, lat];
};
module.exports = Polygon;
},{"./feature":25}],30:[function(require,module,exports){
"use strict";
var Constants = require('../constants');
module.exports = {
isOfMetaType: function isOfMetaType(type) {
return function (e) {
var featureTarget = e.featureTarget;
if (!featureTarget) return false;
if (!featureTarget.properties) return false;
return featureTarget.properties.meta === type;
};
},
isShiftMousedown: function isShiftMousedown(e) {
if (!e.originalEvent) return false;
if (!e.originalEvent.shiftKey) return false;
return e.originalEvent.button === 0;
},
isActiveFeature: function isActiveFeature(e) {
if (!e.featureTarget) return false;
if (!e.featureTarget.properties) return false;
return e.featureTarget.properties.active === Constants.activeStates.ACTIVE && e.featureTarget.properties.meta === Constants.meta.FEATURE;
},
isInactiveFeature: function isInactiveFeature(e) {
if (!e.featureTarget) return false;
if (!e.featureTarget.properties) return false;
return e.featureTarget.properties.active === Constants.activeStates.INACTIVE && e.featureTarget.properties.meta === Constants.meta.FEATURE;
},
noTarget: function noTarget(e) {
return e.featureTarget === undefined;
},
isFeature: function isFeature(e) {
if (!e.featureTarget) return false;
if (!e.featureTarget.properties) return false;
return e.featureTarget.properties.meta === Constants.meta.FEATURE;
},
isVertex: function isVertex(e) {
var featureTarget = e.featureTarget;
if (!featureTarget) return false;
if (!featureTarget.properties) return false;
return featureTarget.properties.meta === Constants.meta.VERTEX;
},
isShiftDown: function isShiftDown(e) {
if (!e.originalEvent) return false;
return e.originalEvent.shiftKey === true;
},
isEscapeKey: function isEscapeKey(e) {
return e.keyCode === 27;
},
isEnterKey: function isEnterKey(e) {
return e.keyCode === 13;
},
true: function _true() {
return true;
}
};
},{"../constants":23}],31:[function(require,module,exports){
"use strict";
var extent = require('@mapbox/geojson-extent');
var Constants = require('../constants');
var LAT_MIN = Constants.LAT_MIN,
LAT_MAX = Constants.LAT_MAX,
LAT_RENDERED_MIN = Constants.LAT_RENDERED_MIN,
LAT_RENDERED_MAX = Constants.LAT_RENDERED_MAX,
LNG_MIN = Constants.LNG_MIN,
LNG_MAX = Constants.LNG_MAX; // Ensure that we do not drag north-south far enough for
// - any part of any feature to exceed the poles
// - any feature to be completely lost in the space between the projection's
// edge and the poles, such that it couldn't be re-selected and moved back
module.exports = function (geojsonFeatures, delta) {
// "inner edge" = a feature's latitude closest to the equator
var northInnerEdge = LAT_MIN;
var southInnerEdge = LAT_MAX; // "outer edge" = a feature's latitude furthest from the equator
var northOuterEdge = LAT_MIN;
var southOuterEdge = LAT_MAX;
var westEdge = LNG_MAX;
var eastEdge = LNG_MIN;
geojsonFeatures.forEach(function (feature) {
var bounds = extent(feature);
var featureSouthEdge = bounds[1];
var featureNorthEdge = bounds[3];
var featureWestEdge = bounds[0];
var featureEastEdge = bounds[2];
if (featureSouthEdge > northInnerEdge) northInnerEdge = featureSouthEdge;
if (featureNorthEdge < southInnerEdge) southInnerEdge = featureNorthEdge;
if (featureNorthEdge > northOuterEdge) northOuterEdge = featureNorthEdge;
if (featureSouthEdge < southOuterEdge) southOuterEdge = featureSouthEdge;
if (featureWestEdge < westEdge) westEdge = featureWestEdge;
if (featureEastEdge > eastEdge) eastEdge = featureEastEdge;
}); // These changes are not mutually exclusive: we might hit the inner
// edge but also have hit the outer edge and therefore need
// another readjustment
var constrainedDelta = delta;
if (northInnerEdge + constrainedDelta.lat > LAT_RENDERED_MAX) {
constrainedDelta.lat = LAT_RENDERED_MAX - northInnerEdge;
}
if (northOuterEdge + constrainedDelta.lat > LAT_MAX) {
constrainedDelta.lat = LAT_MAX - northOuterEdge;
}
if (southInnerEdge + constrainedDelta.lat < LAT_RENDERED_MIN) {
constrainedDelta.lat = LAT_RENDERED_MIN - southInnerEdge;
}
if (southOuterEdge + constrainedDelta.lat < LAT_MIN) {
constrainedDelta.lat = LAT_MIN - southOuterEdge;
}
if (westEdge + constrainedDelta.lng <= LNG_MIN) {
constrainedDelta.lng += Math.ceil(Math.abs(constrainedDelta.lng) / 360) * 360;
}
if (eastEdge + constrainedDelta.lng >= LNG_MAX) {
constrainedDelta.lng -= Math.ceil(Math.abs(constrainedDelta.lng) / 360) * 360;
}
return constrainedDelta;
};
},{"../constants":23,"@mapbox/geojson-extent":6}],32:[function(require,module,exports){
"use strict";
var Constants = require('../constants');
module.exports = function (parent, startVertex, endVertex, map) {
var startCoord = startVertex.geometry.coordinates;
var endCoord = endVertex.geometry.coordinates; // If a coordinate exceeds the projection, we can't calculate a midpoint,
// so run away
if (startCoord[1] > Constants.LAT_RENDERED_MAX || startCoord[1] < Constants.LAT_RENDERED_MIN || endCoord[1] > Constants.LAT_RENDERED_MAX || endCoord[1] < Constants.LAT_RENDERED_MIN) {
return null;
}
var ptA = map.project([startCoord[0], startCoord[1]]);
var ptB = map.project([endCoord[0], endCoord[1]]);
var mid = map.unproject([(ptA.x + ptB.x) / 2, (ptA.y + ptB.y) / 2]);
return {
type: Constants.geojsonTypes.FEATURE,
properties: {
meta: Constants.meta.MIDPOINT,
parent: parent,
lng: mid.lng,
lat: mid.lat,
coord_path: endVertex.properties.coord_path
},
geometry: {
type: Constants.geojsonTypes.POINT,
coordinates: [mid.lng, mid.lat]
}
};
};
},{"../constants":23}],33:[function(require,module,exports){
"use strict";
var createVertex = require('./create_vertex');
var createMidpoint = require('./create_midpoint');
var Constants = require('../constants');
function createSupplementaryPoints(geojson) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var basePath = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var _geojson$geometry = geojson.geometry,
type = _geojson$geometry.type,
coordinates = _geojson$geometry.coordinates;
var featureId = geojson.properties && geojson.properties.id;
var supplementaryPoints = [];
if (type === Constants.geojsonTypes.POINT) {
// For points, just create a vertex
supplementaryPoints.push(createVertex(featureId, coordinates, basePath, isSelectedPath(basePath)));
} else if (type === Constants.geojsonTypes.POLYGON) {
// Cycle through a Polygon's rings and
// process each line
coordinates.forEach(function (line, lineIndex) {
processLine(line, basePath !== null ? "".concat(basePath, ".").concat(lineIndex) : String(lineIndex));
});
} else if (type === Constants.geojsonTypes.LINE_STRING) {
processLine(coordinates, basePath);
} else if (type.indexOf(Constants.geojsonTypes.MULTI_PREFIX) === 0) {
processMultiGeometry();
}
function processLine(line, lineBasePath) {
var firstPointString = '';
var lastVertex = null;
line.forEach(function (point, pointIndex) {
var pointPath = lineBasePath !== undefined && lineBasePath !== null ? "".concat(lineBasePath, ".").concat(pointIndex) : String(pointIndex);
var vertex = createVertex(featureId, point, pointPath, isSelectedPath(pointPath)); // If we're creating midpoints, check if there was a
// vertex before this one. If so, add a midpoint
// between that vertex and this one.
if (options.midpoints && lastVertex) {
var midpoint = createMidpoint(featureId, lastVertex, vertex, options.map);
if (midpoint) {
supplementaryPoints.push(midpoint);
}
}
lastVertex = vertex; // A Polygon line's last point is the same as the first point. If we're on the last
// point, we want to draw a midpoint before it but not another vertex on it
// (since we already a vertex there, from the first point).
var stringifiedPoint = JSON.stringify(point);
if (firstPointString !== stringifiedPoint) {
supplementaryPoints.push(vertex);
}
if (pointIndex === 0) {
firstPointString = stringifiedPoint;
}
});
}
function isSelectedPath(path) {
if (!options.selectedPaths) return false;
return options.selectedPaths.indexOf(path) !== -1;
} // Split a multi-geometry into constituent
// geometries, and accumulate the supplementary points
// for each of those constituents
function processMultiGeometry() {
var subType = type.replace(Constants.geojsonTypes.MULTI_PREFIX, '');
coordinates.forEach(function (subCoordinates, index) {
var subFeature = {
type: Constants.geojsonTypes.FEATURE,
properties: geojson.properties,
geometry: {
type: subType,
coordinates: subCoordinates
}
};
supplementaryPoints = supplementaryPoints.concat(createSupplementaryPoints(subFeature, options, index));
});
}
return supplementaryPoints;
}
module.exports = createSupplementaryPoints;
},{"../constants":23,"./create_midpoint":32,"./create_vertex":34}],34:[function(require,module,exports){
"use strict";
var Constants = require('../constants');
/**
* Returns GeoJSON for a Point representing the
* vertex of another feature.
*
* @param {string} parentId
* @param {Array<number>} coordinates
* @param {string} path - Dot-separated numbers indicating exactly
* where the point exists within its parent feature's coordinates.
* @param {boolean} selected
* @return {GeoJSON} Point
*/
module.exports = function (parentId, coordinates, path, selected) {
return {
type: Constants.geojsonTypes.FEATURE,
properties: {
meta: Constants.meta.VERTEX,
parent: parentId,
coord_path: path,
active: selected ? Constants.activeStates.ACTIVE : Constants.activeStates.INACTIVE
},
geometry: {
type: Constants.geojsonTypes.POINT,
coordinates: coordinates
}
};
};
},{"../constants":23}],35:[function(require,module,exports){
"use strict";
module.exports = {
enable: function enable(ctx) {
setTimeout(function () {
// First check we've got a map and some context.
if (!ctx.map || !ctx.map.doubleClickZoom || !ctx._ctx || !ctx._ctx.store || !ctx._ctx.store.getInitialConfigValue) return; // Now check initial state wasn't false (we leave it disabled if so)
if (!ctx._ctx.store.getInitialConfigValue('doubleClickZoom')) return;
ctx.map.doubleClickZoom.enable();
}, 0);
},
disable: function disable(ctx) {
setTimeout(function () {
if (!ctx.map || !ctx.map.doubleClickZoom) return; // Always disable here, as it's necessary in some cases.
ctx.map.doubleClickZoom.disable();
}, 0);
}
};
},{}],36:[function(require,module,exports){
"use strict";
module.exports = function (a, b) {
var x = a.x - b.x;
var y = a.y - b.y;
return Math.sqrt(x * x + y * y);
};
},{}],37:[function(require,module,exports){
"use strict";
var sortFeatures = require('./sort_features');
var mapEventToBoundingBox = require('./map_event_to_bounding_box');
var Constants = require('../constants');
var StringSet = require('./string_set');
var META_TYPES = [Constants.meta.FEATURE, Constants.meta.MIDPOINT, Constants.meta.VERTEX]; // Requires either event or bbox
module.exports = {
click: featuresAtClick,
touch: featuresAtTouch
};
function featuresAtClick(event, bbox, ctx) {
return featuresAt(event, bbox, ctx, ctx.options.clickBuffer);
}
function featuresAtTouch(event, bbox, ctx) {
return featuresAt(event, bbox, ctx, ctx.options.touchBuffer);
}
function featuresAt(event, bbox, ctx, buffer) {
if (ctx.map === null) return [];
var box = event ? mapEventToBoundingBox(event, buffer) : bbox;
var queryParams = {};
if (ctx.options.styles) queryParams.layers = ctx.options.styles.map(function (s) {
return s.id;
});
var features = ctx.map.queryRenderedFeatures(box, queryParams).filter(function (feature) {
return META_TYPES.indexOf(feature.properties.meta) !== -1;
});
var featureIds = new StringSet();
var uniqueFeatures = [];
features.forEach(function (feature) {
var featureId = feature.properties.id;
if (featureIds.has(featureId)) return;
featureIds.add(featureId);
uniqueFeatures.push(feature);
});
return sortFeatures(uniqueFeatures);
}
},{"../constants":23,"./map_event_to_bounding_box":42,"./sort_features":46,"./string_set":47}],38:[function(require,module,exports){
"use strict";
var featuresAt = require('./features_at');
var Constants = require('../constants');
module.exports = function getFeatureAtAndSetCursors(event, ctx) {
var features = featuresAt.click(event, null, ctx);
var classes = {
mouse: Constants.cursors.NONE
};
if (features[0]) {
classes.mouse = features[0].properties.active === Constants.activeStates.ACTIVE ? Constants.cursors.MOVE : Constants.cursors.POINTER;
classes.feature = features[0].properties.meta;
}
if (ctx.events.currentModeName().indexOf('draw') !== -1) {
classes.mouse = Constants.cursors.ADD;
}
ctx.ui.queueMapClasses(classes);
ctx.ui.updateMapClasses();
return features[0];
};
},{"../constants":23,"./features_at":37}],39:[function(require,module,exports){
"use strict";
var euclideanDistance = require('./euclidean_distance');
var FINE_TOLERANCE = 4;
var GROSS_TOLERANCE = 12;
var INTERVAL = 500;
module.exports = function isClick(start, end) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var fineTolerance = options.fineTolerance != null ? options.fineTolerance : FINE_TOLERANCE;
var grossTolerance = options.grossTolerance != null ? options.grossTolerance : GROSS_TOLERANCE;
var interval = options.interval != null ? options.interval : INTERVAL;
start.point = start.point || end.point;
start.time = start.time || end.time;
var moveDistance = euclideanDistance(start.point, end.point);
return moveDistance < fineTolerance || moveDistance < grossTolerance && end.time - start.time < interval;
};
},{"./euclidean_distance":36}],40:[function(require,module,exports){
"use strict";
function isEventAtCoordinates(event, coordinates) {
if (!event.lngLat) return false;
return event.lngLat.lng === coordinates[0] && event.lngLat.lat === coordinates[1];
}
module.exports = isEventAtCoordinates;
},{}],41:[function(require,module,exports){
"use strict";
var euclideanDistance = require('./euclidean_distance');
var TOLERANCE = 25;
var INTERVAL = 250;
module.exports = function isTap(start, end) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var tolerance = options.tolerance != null ? options.tolerance : TOLERANCE;
var interval = options.interval != null ? options.interval : INTERVAL;
start.point = start.point || end.point;
start.time = start.time || end.time;
var moveDistance = euclideanDistance(start.point, end.point);
return moveDistance < tolerance && end.time - start.time < interval;
};
},{"./euclidean_distance":36}],42:[function(require,module,exports){
"use strict";
/**
* Returns a bounding box representing the event's location.
*
* @param {Event} mapEvent - Mapbox GL JS map event, with a point properties.
* @return {Array<Array<number>>} Bounding box.
*/
function mapEventToBoundingBox(mapEvent) {
var buffer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
return [[mapEvent.point.x - buffer, mapEvent.point.y - buffer], [mapEvent.point.x + buffer, mapEvent.point.y + buffer]];
}
module.exports = mapEventToBoundingBox;
},{}],43:[function(require,module,exports){
"use strict";
var ModeHandler = function ModeHandler(mode, DrawContext) {
var handlers = {
drag: [],
click: [],
mousemove: [],
mousedown: [],
mouseup: [],
mouseout: [],
keydown: [],
keyup: [],
touchstart: [],
touchmove: [],
touchend: [],
tap: []
};
var ctx = {
on: function on(event, selector, fn) {
if (handlers[event] === undefined) {
throw new Error("Invalid event type: ".concat(event));
}
handlers[event].push({
selector: selector,
fn: fn
});
},
render: function render(id) {
DrawContext.store.featureChanged(id);
}
};
var delegate = function delegate(eventName, event) {
var handles = handlers[eventName];
var iHandle = handles.length;
while (iHandle--) {
var handle = handles[iHandle];
if (handle.selector(event)) {
handle.fn.call(ctx, event);
DrawContext.store.render();
DrawContext.ui.updateMapClasses(); // ensure an event is only handled once
// we do this to let modes have multiple overlapping selectors
// and relay on order of oppertations to filter
break;
}
}
};
mode.start.call(ctx);
return {
render: mode.render,
stop: function stop() {
if (mode.stop) mode.stop();
},
trash: function trash() {
if (mode.trash) {
mode.trash();
DrawContext.store.render();
}
},
combineFeatures: function combineFeatures() {
if (mode.combineFeatures) {
mode.combineFeatures();
}
},
uncombineFeatures: function uncombineFeatures() {
if (mode.uncombineFeatures) {
mode.uncombineFeatures();
}
},
drag: function drag(event) {
delegate('drag', event);
},
click: function click(event) {
delegate('click', event);
},
mousemove: function mousemove(event) {
delegate('mousemove', event);
},
mousedown: function mousedown(event) {
delegate('mousedown', event);
},
mouseup: function mouseup(event) {
delegate('mouseup', event);
},
mouseout: function mouseout(event) {
delegate('mouseout', event);
},
keydown: function keydown(event) {
delegate('keydown', event);
},
keyup: function keyup(event) {
delegate('keyup', event);
},
touchstart: function touchstart(event) {
delegate('touchstart', event);
},
touchmove: function touchmove(event) {
delegate('touchmove', event);
},
touchend: function touchend(event) {
delegate('touchend', event);
},
tap: function tap(event) {
delegate('tap', event);
}
};
};
module.exports = ModeHandler;
},{}],44:[function(require,module,exports){
"use strict";
var Point = require('@mapbox/point-geometry');
/**
* Returns a Point representing a mouse event's position
* relative to a containing element.
*
* @param {MouseEvent} mouseEvent
* @param {Node} container
* @returns {Point}
*/
function mouseEventPoint(mouseEvent, container) {
var rect = container.getBoundingClientRect();
return new Point(mouseEvent.clientX - rect.left - (container.clientLeft || 0), mouseEvent.clientY - rect.top - (container.clientTop || 0));
}
module.exports = mouseEventPoint;
},{"@mapbox/point-geometry":11}],45:[function(require,module,exports){
"use strict";
var constrainFeatureMovement = require('./constrain_feature_movement');
var Constants = require('../constants');
module.exports = function (features, delta) {
var constrainedDelta = constrainFeatureMovement(features.map(function (feature) {
return feature.toGeoJSON();
}), delta);
features.forEach(function (feature) {
var currentCoordinates = feature.getCoordinates();
var moveCoordinate = function moveCoordinate(coord) {
var point = {
lng: coord[0] + constrainedDelta.lng,
lat: coord[1] + constrainedDelta.lat
};
return [point.lng, point.lat];
};
var moveRing = function moveRing(ring) {
return ring.map(function (coord) {
return moveCoordinate(coord);
});
};
var moveMultiPolygon = function moveMultiPolygon(multi) {
return multi.map(function (ring) {
return moveRing(ring);
});
};
var nextCoordinates;
if (feature.type === Constants.geojsonTypes.POINT) {
nextCoordinates = moveCoordinate(currentCoordinates);
} else if (feature.type === Constants.geojsonTypes.LINE_STRING || feature.type === Constants.geojsonTypes.MULTI_POINT) {
nextCoordinates = currentCoordinates.map(moveCoordinate);
} else if (feature.type === Constants.geojsonTypes.POLYGON || feature.type === Constants.geojsonTypes.MULTI_LINE_STRING) {
nextCoordinates = currentCoordinates.map(moveRing);
} else if (feature.type === Constants.geojsonTypes.MULTI_POLYGON) {
nextCoordinates = currentCoordinates.map(moveMultiPolygon);
}
feature.incomingCoords(nextCoordinates);
});
};
},{"../constants":23,"./constrain_feature_movement":31}],46:[function(require,module,exports){
"use strict";
var area = require('@mapbox/geojson-area');
var Constants = require('../constants');
var FEATURE_SORT_RANKS = {
Point: 0,
LineString: 1,
Polygon: 2
};
function comparator(a, b) {
var score = FEATURE_SORT_RANKS[a.geometry.type] - FEATURE_SORT_RANKS[b.geometry.type];
if (score === 0 && a.geometry.type === Constants.geojsonTypes.POLYGON) {
return a.area - b.area;
}
return score;
} // Sort in the order above, then sort polygons by area ascending.
function sortFeatures(features) {
return features.map(function (feature) {
if (feature.geometry.type === Constants.geojsonTypes.POLYGON) {
feature.area = area.geometry({
type: Constants.geojsonTypes.FEATURE,
property: {},
geometry: feature.geometry
});
}
return feature;
}).sort(comparator).map(function (feature) {
delete feature.area;
return feature;
});
}
module.exports = sortFeatures;
},{"../constants":23,"@mapbox/geojson-area":3}],47:[function(require,module,exports){
"use strict";
function StringSet(items) {
this._items = {};
this._nums = {};
this._length = items ? items.length : 0;
if (!items) return;
for (var i = 0, l = items.length; i < l; i++) {
this.add(items[i]);
if (items[i] === undefined) continue;
if (typeof items[i] === 'string') this._items[items[i]] = i;else this._nums[items[i]] = i;
}
}
StringSet.prototype.add = function (x) {
if (this.has(x)) return this;
this._length++;
if (typeof x === 'string') this._items[x] = this._length;else this._nums[x] = this._length;
return this;
};
StringSet.prototype.delete = function (x) {
if (this.has(x) === false) return this;
this._length--;
delete this._items[x];
delete this._nums[x];
return this;
};
StringSet.prototype.has = function (x) {
if (typeof x !== 'string' && typeof x !== 'number') return false;
return this._items[x] !== undefined || this._nums[x] !== undefined;
};
StringSet.prototype.values = function () {
var _this = this;
var values = [];
Object.keys(this._items).forEach(function (k) {
values.push({
k: k,
v: _this._items[k]
});
});
Object.keys(this._nums).forEach(function (k) {
values.push({
k: JSON.parse(k),
v: _this._nums[k]
});
});
return values.sort(function (a, b) {
return a.v - b.v;
}).map(function (a) {
return a.k;
});
};
StringSet.prototype.clear = function () {
this._length = 0;
this._items = {};
this._nums = {};
return this;
};
module.exports = StringSet;
},{}],48:[function(require,module,exports){
"use strict";
module.exports = function (a, b) {
if (a.length !== b.length) return false;
return JSON.stringify(a.map(function (id) {
return id;
}).sort()) === JSON.stringify(b.map(function (id) {
return id;
}).sort());
};
},{}],49:[function(require,module,exports){
"use strict";
module.exports = [{
'id': 'gl-draw-polygon-fill-inactive',
'type': 'fill',
'filter': ['all', ['==', 'active', 'false'], ['==', '$type', 'Polygon'], ['!=', 'mode', 'static']],
'paint': {
'fill-color': '#3bb2d0',
'fill-outline-color': '#3bb2d0',
'fill-opacity': 0.1
}
}, {
'id': 'gl-draw-polygon-fill-active',
'type': 'fill',
'filter': ['all', ['==', 'active', 'true'], ['==', '$type', 'Polygon']],
'paint': {
'fill-color': '#fbb03b',
'fill-outline-color': '#fbb03b',
'fill-opacity': 0.1
}
}, {
'id': 'gl-draw-polygon-midpoint',
'type': 'circle',
'filter': ['all', ['==', '$type', 'Point'], ['==', 'meta', 'midpoint']],
'paint': {
'circle-radius': 3,
'circle-color': '#fbb03b'
}
}, {
'id': 'gl-draw-polygon-stroke-inactive',
'type': 'line',
'filter': ['all', ['==', 'active', 'false'], ['==', '$type', 'Polygon'], ['!=', 'mode', 'static']],
'layout': {
'line-cap': 'round',
'line-join': 'round'
},
'paint': {
'line-color': '#3bb2d0',
'line-width': 2
}
}, {
'id': 'gl-draw-polygon-stroke-active',
'type': 'line',
'filter': ['all', ['==', 'active', 'true'], ['==', '$type', 'Polygon']],
'layout': {
'line-cap': 'round',
'line-join': 'round'
},
'paint': {
'line-color': '#fbb03b',
'line-dasharray': [0.2, 2],
'line-width': 2
}
}, {
'id': 'gl-draw-line-inactive',
'type': 'line',
'filter': ['all', ['==', 'active', 'false'], ['==', '$type', 'LineString'], ['!=', 'mode', 'static']],
'layout': {
'line-cap': 'round',
'line-join': 'round'
},
'paint': {
'line-color': '#3bb2d0',
'line-width': 2
}
}, {
'id': 'gl-draw-line-active',
'type': 'line',
'filter': ['all', ['==', '$type', 'LineString'], ['==', 'active', 'true']],
'layout': {
'line-cap': 'round',
'line-join': 'round'
},
'paint': {
'line-color': '#fbb03b',
'line-dasharray': [0.2, 2],
'line-width': 2
}
}, {
'id': 'gl-draw-polygon-and-line-vertex-stroke-inactive',
'type': 'circle',
'filter': ['all', ['==', 'meta', 'vertex'], ['==', '$type', 'Point'], ['!=', 'mode', 'static']],
'paint': {
'circle-radius': 5,
'circle-color': '#fff'
}
}, {
'id': 'gl-draw-polygon-and-line-vertex-inactive',
'type': 'circle',
'filter': ['all', ['==', 'meta', 'vertex'], ['==', '$type', 'Point'], ['!=', 'mode', 'static']],
'paint': {
'circle-radius': 3,
'circle-color': '#fbb03b'
}
}, {
'id': 'gl-draw-point-point-stroke-inactive',
'type': 'circle',
'filter': ['all', ['==', 'active', 'false'], ['==', '$type', 'Point'], ['==', 'meta', 'feature'], ['!=', 'mode', 'static']],
'paint': {
'circle-radius': 5,
'circle-opacity': 1,
'circle-color': '#fff'
}
}, {
'id': 'gl-draw-point-inactive',
'type': 'circle',
'filter': ['all', ['==', 'active', 'false'], ['==', '$type', 'Point'], ['==', 'meta', 'feature'], ['!=', 'mode', 'static']],
'paint': {
'circle-radius': 3,
'circle-color': '#3bb2d0'
}
}, {
'id': 'gl-draw-point-stroke-active',
'type': 'circle',
'filter': ['all', ['==', '$type', 'Point'], ['==', 'active', 'true'], ['!=', 'meta', 'midpoint']],
'paint': {
'circle-radius': 7,
'circle-color': '#fff'
}
}, {
'id': 'gl-draw-point-active',
'type': 'circle',
'filter': ['all', ['==', '$type', 'Point'], ['!=', 'meta', 'midpoint'], ['==', 'active', 'true']],
'paint': {
'circle-radius': 5,
'circle-color': '#fbb03b'
}
}, {
'id': 'gl-draw-polygon-fill-static',
'type': 'fill',
'filter': ['all', ['==', 'mode', 'static'], ['==', '$type', 'Polygon']],
'paint': {
'fill-color': '#404040',
'fill-outline-color': '#404040',
'fill-opacity': 0.1
}
}, {
'id': 'gl-draw-polygon-stroke-static',
'type': 'line',
'filter': ['all', ['==', 'mode', 'static'], ['==', '$type', 'Polygon']],
'layout': {
'line-cap': 'round',
'line-join': 'round'
},
'paint': {
'line-color': '#404040',
'line-width': 2
}
}, {
'id': 'gl-draw-line-static',
'type': 'line',
'filter': ['all', ['==', 'mode', 'static'], ['==', '$type', 'LineString']],
'layout': {
'line-cap': 'round',
'line-join': 'round'
},
'paint': {
'line-color': '#404040',
'line-width': 2
}
}, {
'id': 'gl-draw-point-static',
'type': 'circle',
'filter': ['all', ['==', 'mode', 'static'], ['==', '$type', 'Point']],
'paint': {
'circle-radius': 5,
'circle-color': '#404040'
}
}];
},{}],50:[function(require,module,exports){
"use strict";
function throttle(fn, time, context) {
var lock, args;
function later() {
// reset lock and call if queued
lock = false;
if (args) {
wrapperFn.apply(context, args);
args = false;
}
}
function wrapperFn() {
if (lock) {
// called too soon, queue to call later
args = arguments;
} else {
// lock until later then call
lock = true;
fn.apply(context, arguments);
setTimeout(later, time);
}
}
return wrapperFn;
}
module.exports = throttle;
},{}],51:[function(require,module,exports){
"use strict";
/**
* Derive a dense array (no `undefined`s) from a single value or array.
*
* @param {any} x
* @return {Array<any>}
*/
function toDenseArray(x) {
return [].concat(x).filter(function (y) {
return y !== undefined;
});
}
module.exports = toDenseArray;
},{}],52:[function(require,module,exports){
"use strict";
var _require = require('../lib/common_selectors'),
noTarget = _require.noTarget,
isOfMetaType = _require.isOfMetaType,
isInactiveFeature = _require.isInactiveFeature,
isShiftDown = _require.isShiftDown;
var createSupplementaryPoints = require('../lib/create_supplementary_points');
var constrainFeatureMovement = require('../lib/constrain_feature_movement');
var doubleClickZoom = require('../lib/double_click_zoom');
var Constants = require('../constants');
var CommonSelectors = require('../lib/common_selectors');
var moveFeatures = require('../lib/move_features');
var isVertex = isOfMetaType(Constants.meta.VERTEX);
var isMidpoint = isOfMetaType(Constants.meta.MIDPOINT);
var DirectSelect = {}; // INTERNAL FUCNTIONS
DirectSelect.fireUpdate = function () {
this.map.fire(Constants.events.UPDATE, {
action: Constants.updateActions.CHANGE_COORDINATES,
features: this.getSelected().map(function (f) {
return f.toGeoJSON();
})
});
};
DirectSelect.fireActionable = function (state) {
this.setActionableState({
combineFeatures: false,
uncombineFeatures: false,
trash: state.selectedCoordPaths.length > 0
});
};
DirectSelect.startDragging = function (state, e) {
this.map.dragPan.disable();
state.canDragMove = true;
state.dragMoveLocation = e.lngLat;
};
DirectSelect.stopDragging = function (state) {
this.map.dragPan.enable();
state.dragMoving = false;
state.canDragMove = false;
state.dragMoveLocation = null;
};
DirectSelect.onVertex = function (state, e) {
this.startDragging(state, e);
var about = e.featureTarget.properties;
var selectedIndex = state.selectedCoordPaths.indexOf(about.coord_path);
if (!isShiftDown(e) && selectedIndex === -1) {
state.selectedCoordPaths = [about.coord_path];
} else if (isShiftDown(e) && selectedIndex === -1) {
state.selectedCoordPaths.push(about.coord_path);
}
var selectedCoordinates = this.pathsToCoordinates(state.featureId, state.selectedCoordPaths);
this.setSelectedCoordinates(selectedCoordinates);
};
DirectSelect.onMidpoint = function (state, e) {
this.startDragging(state, e);
var about = e.featureTarget.properties;
state.feature.addCoordinate(about.coord_path, about.lng, about.lat);
this.fireUpdate();
state.selectedCoordPaths = [about.coord_path];
};
DirectSelect.pathsToCoordinates = function (featureId, paths) {
return paths.map(function (coord_path) {
return {
feature_id: featureId,
coord_path: coord_path
};
});
};
DirectSelect.onFeature = function (state, e) {
if (state.selectedCoordPaths.length === 0) this.startDragging(state, e);else this.stopDragging(state);
};
DirectSelect.dragFeature = function (state, e, delta) {
moveFeatures(this.getSelected(), delta);
state.dragMoveLocation = e.lngLat;
};
DirectSelect.dragVertex = function (state, e, delta) {
var selectedCoords = state.selectedCoordPaths.map(function (coord_path) {
return state.feature.getCoordinate(coord_path);
});
var selectedCoordPoints = selectedCoords.map(function (coords) {
return {
type: Constants.geojsonTypes.FEATURE,
properties: {},
geometry: {
type: Constants.geojsonTypes.POINT,
coordinates: coords
}
};
});
var constrainedDelta = constrainFeatureMovement(selectedCoordPoints, delta);
for (var i = 0; i < selectedCoords.length; i++) {
var coord = selectedCoords[i];
state.feature.updateCoordinate(state.selectedCoordPaths[i], coord[0] + constrainedDelta.lng, coord[1] + constrainedDelta.lat);
}
};
DirectSelect.clickNoTarget = function () {
this.changeMode(Constants.modes.SIMPLE_SELECT);
};
DirectSelect.clickInactive = function () {
this.changeMode(Constants.modes.SIMPLE_SELECT);
};
DirectSelect.clickActiveFeature = function (state) {
state.selectedCoordPaths = [];
this.clearSelectedCoordinates();
state.feature.changed();
}; // EXTERNAL FUNCTIONS
DirectSelect.onSetup = function (opts) {
var featureId = opts.featureId;
var feature = this.getFeature(featureId);
if (!feature) {
throw new Error('You must provide a featureId to enter direct_select mode');
}
if (feature.type === Constants.geojsonTypes.POINT) {
throw new TypeError('direct_select mode doesn\'t handle point features');
}
var state = {
featureId: featureId,
feature: feature,
dragMoveLocation: opts.startPos || null,
dragMoving: false,
canDragMove: false,
selectedCoordPaths: opts.coordPath ? [opts.coordPath] : []
};
this.setSelectedCoordinates(this.pathsToCoordinates(featureId, state.selectedCoordPaths));
this.setSelected(featureId);
doubleClickZoom.disable(this);
this.setActionableState({
trash: true
});
return state;
};
DirectSelect.onStop = function () {
doubleClickZoom.enable(this);
this.clearSelectedCoordinates();
};
DirectSelect.toDisplayFeatures = function (state, geojson, push) {
if (state.featureId === geojson.properties.id) {
geojson.properties.active = Constants.activeStates.ACTIVE;
push(geojson);
createSupplementaryPoints(geojson, {
map: this.map,
midpoints: true,
selectedPaths: state.selectedCoordPaths
}).forEach(push);
} else {
geojson.properties.active = Constants.activeStates.INACTIVE;
push(geojson);
}
this.fireActionable(state);
};
DirectSelect.onTrash = function (state) {
state.selectedCoordPaths.sort().reverse().forEach(function (id) {
return state.feature.removeCoordinate(id);
});
this.fireUpdate();
state.selectedCoordPaths = [];
this.clearSelectedCoordinates();
this.fireActionable(state);
if (state.feature.isValid() === false) {
this.deleteFeature([state.featureId]);
this.changeMode(Constants.modes.SIMPLE_SELECT, {});
}
};
DirectSelect.onMouseMove = function (state, e) {
// On mousemove that is not a drag, stop vertex movement.
var isFeature = CommonSelectors.isActiveFeature(e);
var onVertex = isVertex(e);
var noCoords = state.selectedCoordPaths.length === 0;
if (isFeature && noCoords) this.updateUIClasses({
mouse: Constants.cursors.MOVE
});else if (onVertex && !noCoords) this.updateUIClasses({
mouse: Constants.cursors.MOVE
});else this.updateUIClasses({
mouse: Constants.cursors.NONE
});
this.stopDragging(state);
};
DirectSelect.onMouseOut = function (state) {
// As soon as you mouse leaves the canvas, update the feature
if (state.dragMoving) this.fireUpdate();
};
DirectSelect.onTouchStart = DirectSelect.onMouseDown = function (state, e) {
if (isVertex(e)) return this.onVertex(state, e);
if (CommonSelectors.isActiveFeature(e)) return this.onFeature(state, e);
if (isMidpoint(e)) return this.onMidpoint(state, e);
};
DirectSelect.onDrag = function (state, e) {
if (state.canDragMove !== true) return;
state.dragMoving = true;
e.originalEvent.stopPropagation();
var delta = {
lng: e.lngLat.lng - state.dragMoveLocation.lng,
lat: e.lngLat.lat - state.dragMoveLocation.lat
};
if (state.selectedCoordPaths.length > 0) this.dragVertex(state, e, delta);else this.dragFeature(state, e, delta);
state.dragMoveLocation = e.lngLat;
};
DirectSelect.onClick = function (state, e) {
if (noTarget(e)) return this.clickNoTarget(state, e);
if (CommonSelectors.isActiveFeature(e)) return this.clickActiveFeature(state, e);
if (isInactiveFeature(e)) return this.clickInactive(state, e);
this.stopDragging(state);
};
DirectSelect.onTap = function (state, e) {
if (noTarget(e)) return this.clickNoTarget(state, e);
if (CommonSelectors.isActiveFeature(e)) return this.clickActiveFeature(state, e);
if (isInactiveFeature(e)) return this.clickInactive(state, e);
};
DirectSelect.onTouchEnd = DirectSelect.onMouseUp = function (state) {
if (state.dragMoving) {
this.fireUpdate();
}
this.stopDragging(state);
};
module.exports = DirectSelect;
},{"../constants":23,"../lib/common_selectors":30,"../lib/constrain_feature_movement":31,"../lib/create_supplementary_points":33,"../lib/double_click_zoom":35,"../lib/move_features":45}],53:[function(require,module,exports){
"use strict";
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
var CommonSelectors = require('../lib/common_selectors');
var isEventAtCoordinates = require('../lib/is_event_at_coordinates');
var doubleClickZoom = require('../lib/double_click_zoom');
var Constants = require('../constants');
var createVertex = require('../lib/create_vertex');
var DrawLineString = {};
DrawLineString.onSetup = function (opts) {
opts = opts || {};
var featureId = opts.featureId;
var line, currentVertexPosition;
var direction = 'forward';
if (featureId) {
line = this.getFeature(featureId);
if (!line) {
throw new Error('Could not find a feature with the provided featureId');
}
var from = opts.from;
if (from && from.type === 'Feature' && from.geometry && from.geometry.type === 'Point') {
from = from.geometry;
}
if (from && from.type === 'Point' && from.coordinates && from.coordinates.length === 2) {
from = from.coordinates;
}
if (!from || !Array.isArray(from)) {
throw new Error('Please use the `from` property to indicate which point to continue the line from');
}
var lastCoord = line.coordinates.length - 1;
if (line.coordinates[lastCoord][0] === from[0] && line.coordinates[lastCoord][1] === from[1]) {
var _line;
currentVertexPosition = lastCoord + 1; // add one new coordinate to continue from
(_line = line).addCoordinate.apply(_line, [currentVertexPosition].concat(_toConsumableArray(line.coordinates[lastCoord])));
} else if (line.coordinates[0][0] === from[0] && line.coordinates[0][1] === from[1]) {
var _line2;
direction = 'backwards';
currentVertexPosition = 0; // add one new coordinate to continue from
(_line2 = line).addCoordinate.apply(_line2, [currentVertexPosition].concat(_toConsumableArray(line.coordinates[0])));
} else {
throw new Error('`from` should match the point at either the start or the end of the provided LineString');
}
} else {
line = this.newFeature({
type: Constants.geojsonTypes.FEATURE,
properties: {},
geometry: {
type: Constants.geojsonTypes.LINE_STRING,
coordinates: []
}
});
currentVertexPosition = 0;
this.addFeature(line);
}
this.clearSelectedFeatures();
doubleClickZoom.disable(this);
this.updateUIClasses({
mouse: Constants.cursors.ADD
});
this.activateUIButton(Constants.types.LINE);
this.setActionableState({
trash: true
});
return {
line: line,
currentVertexPosition: currentVertexPosition,
direction: direction
};
};
DrawLineString.clickAnywhere = function (state, e) {
if (state.currentVertexPosition > 0 && isEventAtCoordinates(e, state.line.coordinates[state.currentVertexPosition - 1]) || state.direction === 'backwards' && isEventAtCoordinates(e, state.line.coordinates[state.currentVertexPosition + 1])) {
return this.changeMode(Constants.modes.SIMPLE_SELECT, {
featureIds: [state.line.id]
});
}
this.updateUIClasses({
mouse: Constants.cursors.ADD
});
state.line.updateCoordinate(state.currentVertexPosition, e.lngLat.lng, e.lngLat.lat);
if (state.direction === 'forward') {
state.currentVertexPosition++;
state.line.updateCoordinate(state.currentVertexPosition, e.lngLat.lng, e.lngLat.lat);
} else {
state.line.addCoordinate(0, e.lngLat.lng, e.lngLat.lat);
}
};
DrawLineString.clickOnVertex = function (state) {
return this.changeMode(Constants.modes.SIMPLE_SELECT, {
featureIds: [state.line.id]
});
};
DrawLineString.onMouseMove = function (state, e) {
state.line.updateCoordinate(state.currentVertexPosition, e.lngLat.lng, e.lngLat.lat);
if (CommonSelectors.isVertex(e)) {
this.updateUIClasses({
mouse: Constants.cursors.POINTER
});
}
};
DrawLineString.onTap = DrawLineString.onClick = function (state, e) {
if (CommonSelectors.isVertex(e)) return this.clickOnVertex(state, e);
this.clickAnywhere(state, e);
};
DrawLineString.onKeyUp = function (state, e) {
if (CommonSelectors.isEnterKey(e)) {
this.changeMode(Constants.modes.SIMPLE_SELECT, {
featureIds: [state.line.id]
});
} else if (CommonSelectors.isEscapeKey(e)) {
this.deleteFeature([state.line.id], {
silent: true
});
this.changeMode(Constants.modes.SIMPLE_SELECT);
}
};
DrawLineString.onStop = function (state) {
doubleClickZoom.enable(this);
this.activateUIButton(); // check to see if we've deleted this feature
if (this.getFeature(state.line.id) === undefined) return; //remove last added coordinate
state.line.removeCoordinate("".concat(state.currentVertexPosition));
if (state.line.isValid()) {
this.map.fire(Constants.events.CREATE, {
features: [state.line.toGeoJSON()]
});
} else {
this.deleteFeature([state.line.id], {
silent: true
});
this.changeMode(Constants.modes.SIMPLE_SELECT, {}, {
silent: true
});
}
};
DrawLineString.onTrash = function (state) {
this.deleteFeature([state.line.id], {
silent: true
});
this.changeMode(Constants.modes.SIMPLE_SELECT);
};
DrawLineString.toDisplayFeatures = function (state, geojson, display) {
var isActiveLine = geojson.properties.id === state.line.id;
geojson.properties.active = isActiveLine ? Constants.activeStates.ACTIVE : Constants.activeStates.INACTIVE;
if (!isActiveLine) return display(geojson); // Only render the line if it has at least one real coordinate
if (geojson.geometry.coordinates.length < 2) return;
geojson.properties.meta = Constants.meta.FEATURE;
display(createVertex(state.line.id, geojson.geometry.coordinates[state.direction === 'forward' ? geojson.geometry.coordinates.length - 2 : 1], "".concat(state.direction === 'forward' ? geojson.geometry.coordinates.length - 2 : 1), false));
display(geojson);
};
module.exports = DrawLineString;
},{"../constants":23,"../lib/common_selectors":30,"../lib/create_vertex":34,"../lib/double_click_zoom":35,"../lib/is_event_at_coordinates":40}],54:[function(require,module,exports){
"use strict";
var CommonSelectors = require('../lib/common_selectors');
var Constants = require('../constants');
var DrawPoint = {};
DrawPoint.onSetup = function () {
var point = this.newFeature({
type: Constants.geojsonTypes.FEATURE,
properties: {},
geometry: {
type: Constants.geojsonTypes.POINT,
coordinates: []
}
});
this.addFeature(point);
this.clearSelectedFeatures();
this.updateUIClasses({
mouse: Constants.cursors.ADD
});
this.activateUIButton(Constants.types.POINT);
this.setActionableState({
trash: true
});
return {
point: point
};
};
DrawPoint.stopDrawingAndRemove = function (state) {
this.deleteFeature([state.point.id], {
silent: true
});
this.changeMode(Constants.modes.SIMPLE_SELECT);
};
DrawPoint.onTap = DrawPoint.onClick = function (state, e) {
this.updateUIClasses({
mouse: Constants.cursors.MOVE
});
state.point.updateCoordinate('', e.lngLat.lng, e.lngLat.lat);
this.map.fire(Constants.events.CREATE, {
features: [state.point.toGeoJSON()]
});
this.changeMode(Constants.modes.SIMPLE_SELECT, {
featureIds: [state.point.id]
});
};
DrawPoint.onStop = function (state) {
this.activateUIButton();
if (!state.point.getCoordinate().length) {
this.deleteFeature([state.point.id], {
silent: true
});
}
};
DrawPoint.toDisplayFeatures = function (state, geojson, display) {
// Never render the point we're drawing
var isActivePoint = geojson.properties.id === state.point.id;
geojson.properties.active = isActivePoint ? Constants.activeStates.ACTIVE : Constants.activeStates.INACTIVE;
if (!isActivePoint) return display(geojson);
};
DrawPoint.onTrash = DrawPoint.stopDrawingAndRemove;
DrawPoint.onKeyUp = function (state, e) {
if (CommonSelectors.isEscapeKey(e) || CommonSelectors.isEnterKey(e)) {
return this.stopDrawingAndRemove(state, e);
}
};
module.exports = DrawPoint;
},{"../constants":23,"../lib/common_selectors":30}],55:[function(require,module,exports){
"use strict";
var CommonSelectors = require('../lib/common_selectors');
var doubleClickZoom = require('../lib/double_click_zoom');
var Constants = require('../constants');
var isEventAtCoordinates = require('../lib/is_event_at_coordinates');
var createVertex = require('../lib/create_vertex');
var DrawPolygon = {};
DrawPolygon.onSetup = function () {
var polygon = this.newFeature({
type: Constants.geojsonTypes.FEATURE,
properties: {},
geometry: {
type: Constants.geojsonTypes.POLYGON,
coordinates: [[]]
}
});
this.addFeature(polygon);
this.clearSelectedFeatures();
doubleClickZoom.disable(this);
this.updateUIClasses({
mouse: Constants.cursors.ADD
});
this.activateUIButton(Constants.types.POLYGON);
this.setActionableState({
trash: true
});
return {
polygon: polygon,
currentVertexPosition: 0
};
};
DrawPolygon.clickAnywhere = function (state, e) {
if (state.currentVertexPosition > 0 && isEventAtCoordinates(e, state.polygon.coordinates[0][state.currentVertexPosition - 1])) {
return this.changeMode(Constants.modes.SIMPLE_SELECT, {
featureIds: [state.polygon.id]
});
}
this.updateUIClasses({
mouse: Constants.cursors.ADD
});
state.polygon.updateCoordinate("0.".concat(state.currentVertexPosition), e.lngLat.lng, e.lngLat.lat);
state.currentVertexPosition++;
state.polygon.updateCoordinate("0.".concat(state.currentVertexPosition), e.lngLat.lng, e.lngLat.lat);
};
DrawPolygon.clickOnVertex = function (state) {
return this.changeMode(Constants.modes.SIMPLE_SELECT, {
featureIds: [state.polygon.id]
});
};
DrawPolygon.onMouseMove = function (state, e) {
state.polygon.updateCoordinate("0.".concat(state.currentVertexPosition), e.lngLat.lng, e.lngLat.lat);
if (CommonSelectors.isVertex(e)) {
this.updateUIClasses({
mouse: Constants.cursors.POINTER
});
}
};
DrawPolygon.onTap = DrawPolygon.onClick = function (state, e) {
if (CommonSelectors.isVertex(e)) return this.clickOnVertex(state, e);
return this.clickAnywhere(state, e);
};
DrawPolygon.onKeyUp = function (state, e) {
if (CommonSelectors.isEscapeKey(e)) {
this.deleteFeature([state.polygon.id], {
silent: true
});
this.changeMode(Constants.modes.SIMPLE_SELECT);
} else if (CommonSelectors.isEnterKey(e)) {
this.changeMode(Constants.modes.SIMPLE_SELECT, {
featureIds: [state.polygon.id]
});
}
};
DrawPolygon.onStop = function (state) {
this.updateUIClasses({
mouse: Constants.cursors.NONE
});
doubleClickZoom.enable(this);
this.activateUIButton(); // check to see if we've deleted this feature
if (this.getFeature(state.polygon.id) === undefined) return; //remove last added coordinate
state.polygon.removeCoordinate("0.".concat(state.currentVertexPosition));
if (state.polygon.isValid()) {
this.map.fire(Constants.events.CREATE, {
features: [state.polygon.toGeoJSON()]
});
} else {
this.deleteFeature([state.polygon.id], {
silent: true
});
this.changeMode(Constants.modes.SIMPLE_SELECT, {}, {
silent: true
});
}
};
DrawPolygon.toDisplayFeatures = function (state, geojson, display) {
var isActivePolygon = geojson.properties.id === state.polygon.id;
geojson.properties.active = isActivePolygon ? Constants.activeStates.ACTIVE : Constants.activeStates.INACTIVE;
if (!isActivePolygon) return display(geojson); // Don't render a polygon until it has two positions
// (and a 3rd which is just the first repeated)
if (geojson.geometry.coordinates.length === 0) return;
var coordinateCount = geojson.geometry.coordinates[0].length; // 2 coordinates after selecting a draw type
// 3 after creating the first point
if (coordinateCount < 3) {
return;
}
geojson.properties.meta = Constants.meta.FEATURE;
display(createVertex(state.polygon.id, geojson.geometry.coordinates[0][0], '0.0', false));
if (coordinateCount > 3) {
// Add a start position marker to the map, clicking on this will finish the feature
// This should only be shown when we're in a valid spot
var endPos = geojson.geometry.coordinates[0].length - 3;
display(createVertex(state.polygon.id, geojson.geometry.coordinates[0][endPos], "0.".concat(endPos), false));
}
if (coordinateCount <= 4) {
// If we've only drawn two positions (plus the closer),
// make a LineString instead of a Polygon
var lineCoordinates = [[geojson.geometry.coordinates[0][0][0], geojson.geometry.coordinates[0][0][1]], [geojson.geometry.coordinates[0][1][0], geojson.geometry.coordinates[0][1][1]]]; // create an initial vertex so that we can track the first point on mobile devices
display({
type: Constants.geojsonTypes.FEATURE,
properties: geojson.properties,
geometry: {
coordinates: lineCoordinates,
type: Constants.geojsonTypes.LINE_STRING
}
});
if (coordinateCount === 3) {
return;
}
} // render the Polygon
return display(geojson);
};
DrawPolygon.onTrash = function (state) {
this.deleteFeature([state.polygon.id], {
silent: true
});
this.changeMode(Constants.modes.SIMPLE_SELECT);
};
module.exports = DrawPolygon;
},{"../constants":23,"../lib/common_selectors":30,"../lib/create_vertex":34,"../lib/double_click_zoom":35,"../lib/is_event_at_coordinates":40}],56:[function(require,module,exports){
"use strict";
module.exports = {
simple_select: require('./simple_select'),
direct_select: require('./direct_select'),
draw_point: require('./draw_point'),
draw_polygon: require('./draw_polygon'),
draw_line_string: require('./draw_line_string')
};
},{"./direct_select":52,"./draw_line_string":53,"./draw_point":54,"./draw_polygon":55,"./simple_select":60}],57:[function(require,module,exports){
"use strict";
var ModeInterface = module.exports = require('./mode_interface_accessors');
/**
* Triggered while a mode is being transitioned into.
* @param opts {Object} - this is the object passed via `draw.changeMode('mode', opts)`;
* @name MODE.onSetup
* @returns {Object} - this object will be passed to all other life cycle functions
*/
ModeInterface.prototype.onSetup = function () {};
/**
* Triggered when a drag event is detected on the map
* @name MODE.onDrag
* @param state {Object} - a mutible state object created by onSetup
* @param e {Object} - the captured event that is triggering this life cycle event
*/
ModeInterface.prototype.onDrag = function () {};
/**
* Triggered when the mouse is clicked
* @name MODE.onClick
* @param state {Object} - a mutible state object created by onSetup
* @param e {Object} - the captured event that is triggering this life cycle event
*/
ModeInterface.prototype.onClick = function () {};
/**
* Triggered with the mouse is moved
* @name MODE.onMouseMove
* @param state {Object} - a mutible state object created by onSetup
* @param e {Object} - the captured event that is triggering this life cycle event
*/
ModeInterface.prototype.onMouseMove = function () {};
/**
* Triggered when the mouse button is pressed down
* @name MODE.onMouseDown
* @param state {Object} - a mutible state object created by onSetup
* @param e {Object} - the captured event that is triggering this life cycle event
*/
ModeInterface.prototype.onMouseDown = function () {};
/**
* Triggered when the mouse button is released
* @name MODE.onMouseUp
* @param state {Object} - a mutible state object created by onSetup
* @param e {Object} - the captured event that is triggering this life cycle event
*/
ModeInterface.prototype.onMouseUp = function () {};
/**
* Triggered when the mouse leaves the map's container
* @name MODE.onMouseOut
* @param state {Object} - a mutible state object created by onSetup
* @param e {Object} - the captured event that is triggering this life cycle event
*/
ModeInterface.prototype.onMouseOut = function () {};
/**
* Triggered when a key up event is detected
* @name MODE.onKeyUp
* @param state {Object} - a mutible state object created by onSetup
* @param e {Object} - the captured event that is triggering this life cycle event
*/
ModeInterface.prototype.onKeyUp = function () {};
/**
* Triggered when a key down event is detected
* @name MODE.onKeyDown
* @param state {Object} - a mutible state object created by onSetup
* @param e {Object} - the captured event that is triggering this life cycle event
*/
ModeInterface.prototype.onKeyDown = function () {};
/**
* Triggered when a touch event is started
* @name MODE.onTouchStart
* @param state {Object} - a mutible state object created by onSetup
* @param e {Object} - the captured event that is triggering this life cycle event
*/
ModeInterface.prototype.onTouchStart = function () {};
/**
* Triggered when one drags thier finger on a mobile device
* @name MODE.onTouchMove
* @param state {Object} - a mutible state object created by onSetup
* @param e {Object} - the captured event that is triggering this life cycle event
*/
ModeInterface.prototype.onTouchMove = function () {};
/**
* Triggered when one removes their finger from the map
* @name MODE.onTouchEnd
* @param state {Object} - a mutible state object created by onSetup
* @param e {Object} - the captured event that is triggering this life cycle event
*/
ModeInterface.prototype.onTouchEnd = function () {};
/**
* Triggered when one quicly taps the map
* @name MODE.onTap
* @param state {Object} - a mutible state object created by onSetup
* @param e {Object} - the captured event that is triggering this life cycle event
*/
ModeInterface.prototype.onTap = function () {};
/**
* Triggered when the mode is being exited, to be used for cleaning up artifacts such as invalid features
* @name MODE.onStop
* @param state {Object} - a mutible state object created by onSetup
*/
ModeInterface.prototype.onStop = function () {};
/**
* Triggered when [draw.trash()](https://github.com/mapbox/mapbox-gl-draw/blob/master/API.md#trash-draw) is called.
* @name MODE.onTrash
* @param state {Object} - a mutible state object created by onSetup
*/
ModeInterface.prototype.onTrash = function () {};
/**
* Triggered when [draw.combineFeatures()](https://github.com/mapbox/mapbox-gl-draw/blob/master/API.md#combinefeatures-draw) is called.
* @name MODE.onCombineFeature
* @param state {Object} - a mutible state object created by onSetup
*/
ModeInterface.prototype.onCombineFeature = function () {};
/**
* Triggered when [draw.uncombineFeatures()](https://github.com/mapbox/mapbox-gl-draw/blob/master/API.md#uncombinefeatures-draw) is called.
* @name MODE.onUncombineFeature
* @param state {Object} - a mutible state object created by onSetup
*/
ModeInterface.prototype.onUncombineFeature = function () {};
/**
* Triggered per feature on render to convert raw features into set of features for display on the map
* See [styling draw](https://github.com/mapbox/mapbox-gl-draw/blob/master/API.md#styling-draw) for information about what geojson properties Draw uses as part of rendering.
* @name MODE.toDisplayFeatures
* @param state {Object} - a mutible state object created by onSetup
* @param geojson {Object} - a geojson being evaulated. To render, pass to `display`.
* @param display {Function} - all geojson objects passed to this be rendered onto the map
*/
ModeInterface.prototype.toDisplayFeatures = function () {
throw new Error('You must overwrite toDisplayFeatures');
};
},{"./mode_interface_accessors":58}],58:[function(require,module,exports){
"use strict";
var Constants = require('../constants');
var featuresAt = require('../lib/features_at');
var Point = require('../feature_types/point');
var LineString = require('../feature_types/line_string');
var Polygon = require('../feature_types/polygon');
var MultiFeature = require('../feature_types/multi_feature');
var ModeInterface = module.exports = function (ctx) {
this.map = ctx.map;
this.drawConfig = JSON.parse(JSON.stringify(ctx.options || {}));
this._ctx = ctx;
};
/**
* Sets Draw's interal selected state
* @name this.setSelected
* @param {DrawFeature[]} - whats selected as a [DrawFeature](https://github.com/mapbox/mapbox-gl-draw/blob/master/src/feature_types/feature.js)
*/
ModeInterface.prototype.setSelected = function (features) {
return this._ctx.store.setSelected(features);
};
/**
* Sets Draw's internal selected coordinate state
* @name this.setSelectedCoordinates
* @param {Object[]} coords - a array of {coord_path: 'string', featureId: 'string'}
*/
ModeInterface.prototype.setSelectedCoordinates = function (coords) {
var _this = this;
this._ctx.store.setSelectedCoordinates(coords);
coords.reduce(function (m, c) {
if (m[c.feature_id] === undefined) {
m[c.feature_id] = true;
_this._ctx.store.get(c.feature_id).changed();
}
return m;
}, {});
};
/**
* Get all selected features as a [DrawFeature](https://github.com/mapbox/mapbox-gl-draw/blob/master/src/feature_types/feature.js)
* @name this.getSelected
* @returns {DrawFeature[]}
*/
ModeInterface.prototype.getSelected = function () {
return this._ctx.store.getSelected();
};
/**
* Get the ids of all currently selected features
* @name this.getSelectedIds
* @returns {String[]}
*/
ModeInterface.prototype.getSelectedIds = function () {
return this._ctx.store.getSelectedIds();
};
/**
* Check if a feature is selected
* @name this.isSelected
* @param {String} id - a feature id
* @returns {Boolean}
*/
ModeInterface.prototype.isSelected = function (id) {
return this._ctx.store.isSelected(id);
};
/**
* Get a [DrawFeature](https://github.com/mapbox/mapbox-gl-draw/blob/master/src/feature_types/feature.js) by its id
* @name this.getFeature
* @param {String} id - a feature id
* @returns {DrawFeature}
*/
ModeInterface.prototype.getFeature = function (id) {
return this._ctx.store.get(id);
};
/**
* Add a feature to draw's internal selected state
* @name this.select
* @param {String} id
*/
ModeInterface.prototype.select = function (id) {
return this._ctx.store.select(id);
};
/**
* Remove a feature from draw's internal selected state
* @name this.delete
* @param {String} id
*/
ModeInterface.prototype.deselect = function (id) {
return this._ctx.store.deselect(id);
};
/**
* Delete a feature from draw
* @name this.deleteFeature
* @param {String} id - a feature id
*/
ModeInterface.prototype.deleteFeature = function (id) {
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return this._ctx.store.delete(id, opts);
};
/**
* Add a [DrawFeature](https://github.com/mapbox/mapbox-gl-draw/blob/master/src/feature_types/feature.js) to draw.
* See `this.newFeature` for converting geojson into a DrawFeature
* @name this.addFeature
* @param {DrawFeature} feature - the feature to add
*/
ModeInterface.prototype.addFeature = function (feature) {
return this._ctx.store.add(feature);
};
/**
* Clear all selected features
*/
ModeInterface.prototype.clearSelectedFeatures = function () {
return this._ctx.store.clearSelected();
};
/**
* Clear all selected coordinates
*/
ModeInterface.prototype.clearSelectedCoordinates = function () {
return this._ctx.store.clearSelectedCoordinates();
};
/**
* Indicate if the different action are currently possible with your mode
* See [draw.actionalbe](https://github.com/mapbox/mapbox-gl-draw/blob/master/API.md#drawactionable) for a list of possible actions. All undefined actions are set to **false** by default
* @name this.setActionableState
* @param {Object} actions
*/
ModeInterface.prototype.setActionableState = function () {
var actions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var newSet = {
trash: actions.trash || false,
combineFeatures: actions.combineFeatures || false,
uncombineFeatures: actions.uncombineFeatures || false
};
return this._ctx.events.actionable(newSet);
};
/**
* Trigger a mode change
* @name this.changeMode
* @param {String} mode - the mode to transition into
* @param {Object} opts - the options object to pass to the new mode
* @param {Object} eventOpts - used to control what kind of events are emitted.
*/
ModeInterface.prototype.changeMode = function (mode) {
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var eventOpts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
return this._ctx.events.changeMode(mode, opts, eventOpts);
};
/**
* Update the state of draw map classes
* @name this.updateUIClasses
* @param {Object} opts
*/
ModeInterface.prototype.updateUIClasses = function (opts) {
return this._ctx.ui.queueMapClasses(opts);
};
/**
* If a name is provided it makes that button active, else if makes all buttons inactive
* @name this.activateUIButton
* @param {String?} name - name of the button to make active, leave as undefined to set buttons to be inactive
*/
ModeInterface.prototype.activateUIButton = function (name) {
return this._ctx.ui.setActiveButton(name);
};
/**
* Get the features at the location of an event object or in a bbox
* @name this.featuresAt
* @param {Event||NULL} event - a mapbox-gl event object
* @param {BBOX||NULL} bbox - the area to get features from
* @param {String} bufferType - is this `click` or `tap` event, defaults to click
*/
ModeInterface.prototype.featuresAt = function (event, bbox) {
var bufferType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'click';
if (bufferType !== 'click' && bufferType !== 'touch') throw new Error('invalid buffer type');
return featuresAt[bufferType](event, bbox, this._ctx);
};
/**
* Create a new [DrawFeature](https://github.com/mapbox/mapbox-gl-draw/blob/master/src/feature_types/feature.js) from geojson
* @name this.newFeature
* @param {GeoJSONFeature} geojson
* @returns {DrawFeature}
*/
ModeInterface.prototype.newFeature = function (geojson) {
var type = geojson.geometry.type;
if (type === Constants.geojsonTypes.POINT) return new Point(this._ctx, geojson);
if (type === Constants.geojsonTypes.LINE_STRING) return new LineString(this._ctx, geojson);
if (type === Constants.geojsonTypes.POLYGON) return new Polygon(this._ctx, geojson);
return new MultiFeature(this._ctx, geojson);
};
/**
* Check is an object is an instance of a [DrawFeature](https://github.com/mapbox/mapbox-gl-draw/blob/master/src/feature_types/feature.js)
* @name this.isInstanceOf
* @param {String} type - `Point`, `LineString`, `Polygon`, `MultiFeature`
* @param {Object} feature - the object that needs to be checked
* @returns {Boolean}
*/
ModeInterface.prototype.isInstanceOf = function (type, feature) {
if (type === Constants.geojsonTypes.POINT) return feature instanceof Point;
if (type === Constants.geojsonTypes.LINE_STRING) return feature instanceof LineString;
if (type === Constants.geojsonTypes.POLYGON) return feature instanceof Polygon;
if (type === 'MultiFeature') return feature instanceof MultiFeature;
throw new Error("Unknown feature class: ".concat(type));
};
/**
* Force draw to rerender the feature of the provided id
* @name this.doRender
* @param {String} id - a feature id
*/
ModeInterface.prototype.doRender = function (id) {
return this._ctx.store.featureChanged(id);
};
},{"../constants":23,"../feature_types/line_string":26,"../feature_types/multi_feature":27,"../feature_types/point":28,"../feature_types/polygon":29,"../lib/features_at":37}],59:[function(require,module,exports){
"use strict";
var ModeInterface = require('./mode_interface');
var eventMapper = {
drag: 'onDrag',
click: 'onClick',
mousemove: 'onMouseMove',
mousedown: 'onMouseDown',
mouseup: 'onMouseUp',
mouseout: 'onMouseOut',
keyup: 'onKeyUp',
keydown: 'onKeyDown',
touchstart: 'onTouchStart',
touchmove: 'onTouchMove',
touchend: 'onTouchEnd',
tap: 'onTap'
};
var eventKeys = Object.keys(eventMapper);
module.exports = function (modeObject) {
var modeObjectKeys = Object.keys(modeObject);
return function (ctx) {
var startOpts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var state = {};
var mode = modeObjectKeys.reduce(function (m, k) {
m[k] = modeObject[k];
return m;
}, new ModeInterface(ctx));
function wrapper(eh) {
return function (e) {
mode[eh](state, e);
};
}
return {
start: function start() {
var _this = this;
state = mode.onSetup(startOpts); // this should set ui buttons
// Adds event handlers for all event options
// add sets the selector to false for all
// handlers that are not present in the mode
// to reduce on render calls for functions that
// have no logic
eventKeys.forEach(function (key) {
var modeHandler = eventMapper[key];
var selector = function selector() {
return false;
};
if (modeObject[modeHandler]) {
selector = function selector() {
return true;
};
}
_this.on(key, selector, wrapper(modeHandler));
});
},
stop: function stop() {
mode.onStop(state);
},
trash: function trash() {
mode.onTrash(state);
},
combineFeatures: function combineFeatures() {
mode.onCombineFeatures(state);
},
uncombineFeatures: function uncombineFeatures() {
mode.onUncombineFeatures(state);
},
render: function render(geojson, push) {
mode.toDisplayFeatures(state, geojson, push);
}
};
};
};
},{"./mode_interface":57}],60:[function(require,module,exports){
"use strict";
var CommonSelectors = require('../lib/common_selectors');
var mouseEventPoint = require('../lib/mouse_event_point');
var createSupplementaryPoints = require('../lib/create_supplementary_points');
var StringSet = require('../lib/string_set');
var doubleClickZoom = require('../lib/double_click_zoom');
var moveFeatures = require('../lib/move_features');
var Constants = require('../constants');
var SimpleSelect = {};
SimpleSelect.onSetup = function (opts) {
var _this = this;
// turn the opts into state.
var state = {
dragMoveLocation: null,
boxSelectStartLocation: null,
boxSelectElement: undefined,
boxSelecting: false,
canBoxSelect: false,
dragMoveing: false,
canDragMove: false,
initiallySelectedFeatureIds: opts.featureIds || []
};
this.setSelected(state.initiallySelectedFeatureIds.filter(function (id) {
return _this.getFeature(id) !== undefined;
}));
this.fireActionable();
this.setActionableState({
combineFeatures: true,
uncombineFeatures: true,
trash: true
});
return state;
};
SimpleSelect.fireUpdate = function () {
this.map.fire(Constants.events.UPDATE, {
action: Constants.updateActions.MOVE,
features: this.getSelected().map(function (f) {
return f.toGeoJSON();
})
});
};
SimpleSelect.fireActionable = function () {
var _this2 = this;
var selectedFeatures = this.getSelected();
var multiFeatures = selectedFeatures.filter(function (feature) {
return _this2.isInstanceOf('MultiFeature', feature);
});
var combineFeatures = false;
if (selectedFeatures.length > 1) {
combineFeatures = true;
var featureType = selectedFeatures[0].type.replace('Multi', '');
selectedFeatures.forEach(function (feature) {
if (feature.type.replace('Multi', '') !== featureType) {
combineFeatures = false;
}
});
}
var uncombineFeatures = multiFeatures.length > 0;
var trash = selectedFeatures.length > 0;
this.setActionableState({
combineFeatures: combineFeatures,
uncombineFeatures: uncombineFeatures,
trash: trash
});
};
SimpleSelect.getUniqueIds = function (allFeatures) {
if (!allFeatures.length) return [];
var ids = allFeatures.map(function (s) {
return s.properties.id;
}).filter(function (id) {
return id !== undefined;
}).reduce(function (memo, id) {
memo.add(id);
return memo;
}, new StringSet());
return ids.values();
};
SimpleSelect.stopExtendedInteractions = function (state) {
if (state.boxSelectElement) {
if (state.boxSelectElement.parentNode) state.boxSelectElement.parentNode.removeChild(state.boxSelectElement);
state.boxSelectElement = null;
}
this.map.dragPan.enable();
state.boxSelecting = false;
state.canBoxSelect = false;
state.dragMoving = false;
state.canDragMove = false;
};
SimpleSelect.onStop = function () {
doubleClickZoom.enable(this);
};
SimpleSelect.onMouseMove = function (state) {
// On mousemove that is not a drag, stop extended interactions.
// This is useful if you drag off the canvas, release the button,
// then move the mouse back over the canvas --- we don't allow the
// interaction to continue then, but we do let it continue if you held
// the mouse button that whole time
return this.stopExtendedInteractions(state);
};
SimpleSelect.onMouseOut = function (state) {
// As soon as you mouse leaves the canvas, update the feature
if (state.dragMoving) return this.fireUpdate();
};
SimpleSelect.onTap = SimpleSelect.onClick = function (state, e) {
// Click (with or without shift) on no feature
if (CommonSelectors.noTarget(e)) return this.clickAnywhere(state, e); // also tap
if (CommonSelectors.isOfMetaType(Constants.meta.VERTEX)(e)) return this.clickOnVertex(state, e); //tap
if (CommonSelectors.isFeature(e)) return this.clickOnFeature(state, e);
};
SimpleSelect.clickAnywhere = function (state) {
var _this3 = this;
// Clear the re-render selection
var wasSelected = this.getSelectedIds();
if (wasSelected.length) {
this.clearSelectedFeatures();
wasSelected.forEach(function (id) {
return _this3.doRender(id);
});
}
doubleClickZoom.enable(this);
this.stopExtendedInteractions(state);
};
SimpleSelect.clickOnVertex = function (state, e) {
// Enter direct select mode
this.changeMode(Constants.modes.DIRECT_SELECT, {
featureId: e.featureTarget.properties.parent,
coordPath: e.featureTarget.properties.coord_path,
startPos: e.lngLat
});
this.updateUIClasses({
mouse: Constants.cursors.MOVE
});
};
SimpleSelect.startOnActiveFeature = function (state, e) {
// Stop any already-underway extended interactions
this.stopExtendedInteractions(state); // Disable map.dragPan immediately so it can't start
this.map.dragPan.disable(); // Re-render it and enable drag move
this.doRender(e.featureTarget.properties.id); // Set up the state for drag moving
state.canDragMove = true;
state.dragMoveLocation = e.lngLat;
};
SimpleSelect.clickOnFeature = function (state, e) {
var _this4 = this;
// Stop everything
doubleClickZoom.disable(this);
this.stopExtendedInteractions(state);
var isShiftClick = CommonSelectors.isShiftDown(e);
var selectedFeatureIds = this.getSelectedIds();
var featureId = e.featureTarget.properties.id;
var isFeatureSelected = this.isSelected(featureId); // Click (without shift) on any selected feature but a point
if (!isShiftClick && isFeatureSelected && this.getFeature(featureId).type !== Constants.geojsonTypes.POINT) {
// Enter direct select mode
return this.changeMode(Constants.modes.DIRECT_SELECT, {
featureId: featureId
});
} // Shift-click on a selected feature
if (isFeatureSelected && isShiftClick) {
// Deselect it
this.deselect(featureId);
this.updateUIClasses({
mouse: Constants.cursors.POINTER
});
if (selectedFeatureIds.length === 1) {
doubleClickZoom.enable(this);
} // Shift-click on an unselected feature
} else if (!isFeatureSelected && isShiftClick) {
// Add it to the selection
this.select(featureId);
this.updateUIClasses({
mouse: Constants.cursors.MOVE
}); // Click (without shift) on an unselected feature
} else if (!isFeatureSelected && !isShiftClick) {
// Make it the only selected feature
selectedFeatureIds.forEach(function (id) {
return _this4.doRender(id);
});
this.setSelected(featureId);
this.updateUIClasses({
mouse: Constants.cursors.MOVE
});
} // No matter what, re-render the clicked feature
this.doRender(featureId);
};
SimpleSelect.onMouseDown = function (state, e) {
if (CommonSelectors.isActiveFeature(e)) return this.startOnActiveFeature(state, e);
if (this.drawConfig.boxSelect && CommonSelectors.isShiftMousedown(e)) return this.startBoxSelect(state, e);
};
SimpleSelect.startBoxSelect = function (state, e) {
this.stopExtendedInteractions(state);
this.map.dragPan.disable(); // Enable box select
state.boxSelectStartLocation = mouseEventPoint(e.originalEvent, this.map.getContainer());
state.canBoxSelect = true;
};
SimpleSelect.onTouchStart = function (state, e) {
if (CommonSelectors.isActiveFeature(e)) return this.startOnActiveFeature(state, e);
};
SimpleSelect.onDrag = function (state, e) {
if (state.canDragMove) return this.dragMove(state, e);
if (this.drawConfig.boxSelect && state.canBoxSelect) return this.whileBoxSelect(state, e);
};
SimpleSelect.whileBoxSelect = function (state, e) {
state.boxSelecting = true;
this.updateUIClasses({
mouse: Constants.cursors.ADD
}); // Create the box node if it doesn't exist
if (!state.boxSelectElement) {
state.boxSelectElement = document.createElement('div');
state.boxSelectElement.classList.add(Constants.classes.BOX_SELECT);
this.map.getContainer().appendChild(state.boxSelectElement);
} // Adjust the box node's width and xy position
var current = mouseEventPoint(e.originalEvent, this.map.getContainer());
var minX = Math.min(state.boxSelectStartLocation.x, current.x);
var maxX = Math.max(state.boxSelectStartLocation.x, current.x);
var minY = Math.min(state.boxSelectStartLocation.y, current.y);
var maxY = Math.max(state.boxSelectStartLocation.y, current.y);
var translateValue = "translate(".concat(minX, "px, ").concat(minY, "px)");
state.boxSelectElement.style.transform = translateValue;
state.boxSelectElement.style.WebkitTransform = translateValue;
state.boxSelectElement.style.width = "".concat(maxX - minX, "px");
state.boxSelectElement.style.height = "".concat(maxY - minY, "px");
};
SimpleSelect.dragMove = function (state, e) {
// Dragging when drag move is enabled
state.dragMoving = true;
e.originalEvent.stopPropagation();
var delta = {
lng: e.lngLat.lng - state.dragMoveLocation.lng,
lat: e.lngLat.lat - state.dragMoveLocation.lat
};
moveFeatures(this.getSelected(), delta);
state.dragMoveLocation = e.lngLat;
};
SimpleSelect.onMouseUp = function (state, e) {
var _this5 = this;
// End any extended interactions
if (state.dragMoving) {
this.fireUpdate();
} else if (state.boxSelecting) {
var bbox = [state.boxSelectStartLocation, mouseEventPoint(e.originalEvent, this.map.getContainer())];
var featuresInBox = this.featuresAt(null, bbox, 'click');
var idsToSelect = this.getUniqueIds(featuresInBox).filter(function (id) {
return !_this5.isSelected(id);
});
if (idsToSelect.length) {
this.select(idsToSelect);
idsToSelect.forEach(function (id) {
return _this5.doRender(id);
});
this.updateUIClasses({
mouse: Constants.cursors.MOVE
});
}
}
this.stopExtendedInteractions(state);
};
SimpleSelect.toDisplayFeatures = function (state, geojson, display) {
geojson.properties.active = this.isSelected(geojson.properties.id) ? Constants.activeStates.ACTIVE : Constants.activeStates.INACTIVE;
display(geojson);
this.fireActionable();
if (geojson.properties.active !== Constants.activeStates.ACTIVE || geojson.geometry.type === Constants.geojsonTypes.POINT) return;
createSupplementaryPoints(geojson).forEach(display);
};
SimpleSelect.onTrash = function () {
this.deleteFeature(this.getSelectedIds());
this.fireActionable();
};
SimpleSelect.onCombineFeatures = function () {
var selectedFeatures = this.getSelected();
if (selectedFeatures.length === 0 || selectedFeatures.length < 2) return;
var coordinates = [],
featuresCombined = [];
var featureType = selectedFeatures[0].type.replace('Multi', '');
for (var i = 0; i < selectedFeatures.length; i++) {
var feature = selectedFeatures[i];
if (feature.type.replace('Multi', '') !== featureType) {
return;
}
if (feature.type.includes('Multi')) {
feature.getCoordinates().forEach(function (subcoords) {
coordinates.push(subcoords);
});
} else {
coordinates.push(feature.getCoordinates());
}
featuresCombined.push(feature.toGeoJSON());
}
if (featuresCombined.length > 1) {
var multiFeature = this.newFeature({
type: Constants.geojsonTypes.FEATURE,
properties: featuresCombined[0].properties,
geometry: {
type: "Multi".concat(featureType),
coordinates: coordinates
}
});
this.addFeature(multiFeature);
this.deleteFeature(this.getSelectedIds(), {
silent: true
});
this.setSelected([multiFeature.id]);
this.map.fire(Constants.events.COMBINE_FEATURES, {
createdFeatures: [multiFeature.toGeoJSON()],
deletedFeatures: featuresCombined
});
}
this.fireActionable();
};
SimpleSelect.onUncombineFeatures = function () {
var _this6 = this;
var selectedFeatures = this.getSelected();
if (selectedFeatures.length === 0) return;
var createdFeatures = [];
var featuresUncombined = [];
var _loop = function _loop(i) {
var feature = selectedFeatures[i];
if (_this6.isInstanceOf('MultiFeature', feature)) {
feature.getFeatures().forEach(function (subFeature) {
_this6.addFeature(subFeature);
subFeature.properties = feature.properties;
createdFeatures.push(subFeature.toGeoJSON());
_this6.select([subFeature.id]);
});
_this6.deleteFeature(feature.id, {
silent: true
});
featuresUncombined.push(feature.toGeoJSON());
}
};
for (var i = 0; i < selectedFeatures.length; i++) {
_loop(i);
}
if (createdFeatures.length > 1) {
this.map.fire(Constants.events.UNCOMBINE_FEATURES, {
createdFeatures: createdFeatures,
deletedFeatures: featuresUncombined
});
}
this.fireActionable();
};
module.exports = SimpleSelect;
},{"../constants":23,"../lib/common_selectors":30,"../lib/create_supplementary_points":33,"../lib/double_click_zoom":35,"../lib/mouse_event_point":44,"../lib/move_features":45,"../lib/string_set":47}],61:[function(require,module,exports){
"use strict";
var xtend = require('xtend');
var Constants = require('./constants');
var defaultOptions = {
defaultMode: Constants.modes.SIMPLE_SELECT,
keybindings: true,
touchEnabled: true,
clickBuffer: 2,
touchBuffer: 25,
boxSelect: true,
displayControlsDefault: true,
styles: require('./lib/theme'),
modes: require('./modes'),
controls: {},
userProperties: false
};
var showControls = {
point: true,
line_string: true,
polygon: true,
trash: true,
combine_features: true,
uncombine_features: true
};
var hideControls = {
point: false,
line_string: false,
polygon: false,
trash: false,
combine_features: false,
uncombine_features: false
};
function addSources(styles, sourceBucket) {
return styles.map(function (style) {
if (style.source) return style;
return xtend(style, {
id: "".concat(style.id, ".").concat(sourceBucket),
source: sourceBucket === 'hot' ? Constants.sources.HOT : Constants.sources.COLD
});
});
}
module.exports = function () {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var withDefaults = xtend(options);
if (!options.controls) {
withDefaults.controls = {};
}
if (options.displayControlsDefault === false) {
withDefaults.controls = xtend(hideControls, options.controls);
} else {
withDefaults.controls = xtend(showControls, options.controls);
}
withDefaults = xtend(defaultOptions, withDefaults); // Layers with a shared source should be adjacent for performance reasons
withDefaults.styles = addSources(withDefaults.styles, 'cold').concat(addSources(withDefaults.styles, 'hot'));
return withDefaults;
};
},{"./constants":23,"./lib/theme":49,"./modes":56,"xtend":21}],62:[function(require,module,exports){
"use strict";
var Constants = require('./constants');
module.exports = function render() {
var store = this;
var mapExists = store.ctx.map && store.ctx.map.getSource(Constants.sources.HOT) !== undefined;
if (!mapExists) return cleanup();
var mode = store.ctx.events.currentModeName();
store.ctx.ui.queueMapClasses({
mode: mode
});
var newHotIds = [];
var newColdIds = [];
if (store.isDirty) {
newColdIds = store.getAllIds();
} else {
newHotIds = store.getChangedIds().filter(function (id) {
return store.get(id) !== undefined;
});
newColdIds = store.sources.hot.filter(function (geojson) {
return geojson.properties.id && newHotIds.indexOf(geojson.properties.id) === -1 && store.get(geojson.properties.id) !== undefined;
}).map(function (geojson) {
return geojson.properties.id;
});
}
store.sources.hot = [];
var lastColdCount = store.sources.cold.length;
store.sources.cold = store.isDirty ? [] : store.sources.cold.filter(function (geojson) {
var id = geojson.properties.id || geojson.properties.parent;
return newHotIds.indexOf(id) === -1;
});
var coldChanged = lastColdCount !== store.sources.cold.length || newColdIds.length > 0;
newHotIds.forEach(function (id) {
return renderFeature(id, 'hot');
});
newColdIds.forEach(function (id) {
return renderFeature(id, 'cold');
});
function renderFeature(id, source) {
var feature = store.get(id);
var featureInternal = feature.internal(mode);
store.ctx.events.currentModeRender(featureInternal, function (geojson) {
store.sources[source].push(geojson);
});
}
if (coldChanged) {
store.ctx.map.getSource(Constants.sources.COLD).setData({
type: Constants.geojsonTypes.FEATURE_COLLECTION,
features: store.sources.cold
});
}
store.ctx.map.getSource(Constants.sources.HOT).setData({
type: Constants.geojsonTypes.FEATURE_COLLECTION,
features: store.sources.hot
});
if (store._emitSelectionChange) {
store.ctx.map.fire(Constants.events.SELECTION_CHANGE, {
features: store.getSelected().map(function (feature) {
return feature.toGeoJSON();
}),
points: store.getSelectedCoordinates().map(function (coordinate) {
return {
type: Constants.geojsonTypes.FEATURE,
properties: {},
geometry: {
type: Constants.geojsonTypes.POINT,
coordinates: coordinate.coordinates
}
};
})
});
store._emitSelectionChange = false;
}
if (store._deletedFeaturesToEmit.length) {
var geojsonToEmit = store._deletedFeaturesToEmit.map(function (feature) {
return feature.toGeoJSON();
});
store._deletedFeaturesToEmit = [];
store.ctx.map.fire(Constants.events.DELETE, {
features: geojsonToEmit
});
}
cleanup();
store.ctx.map.fire(Constants.events.RENDER, {});
function cleanup() {
store.isDirty = false;
store.clearChangedIds();
}
};
},{"./constants":23}],63:[function(require,module,exports){
"use strict";
var events = require('./events');
var Store = require('./store');
var ui = require('./ui');
var Constants = require('./constants');
var xtend = require('xtend');
module.exports = function (ctx) {
var controlContainer = null;
var mapLoadedInterval = null;
var setup = {
onRemove: function onRemove() {
// Stop connect attempt in the event that control is removed before map is loaded
ctx.map.off('load', setup.connect);
clearInterval(mapLoadedInterval);
setup.removeLayers();
ctx.store.restoreMapConfig();
ctx.ui.removeButtons();
ctx.events.removeEventListeners();
ctx.ui.clearMapClasses();
ctx.map = null;
ctx.container = null;
ctx.store = null;
if (controlContainer && controlContainer.parentNode) controlContainer.parentNode.removeChild(controlContainer);
controlContainer = null;
return this;
},
connect: function connect() {
ctx.map.off('load', setup.connect);
clearInterval(mapLoadedInterval);
setup.addLayers();
ctx.store.storeMapConfig();
ctx.events.addEventListeners();
},
onAdd: function onAdd(map) {
if ("production" !== 'test') {
// Monkey patch to resolve breaking change to `fire` introduced by
// mapbox-gl-js. See mapbox/mapbox-gl-draw/issues/766.
var _fire = map.fire;
map.fire = function (type, event) {
var args = arguments;
if (_fire.length === 1 && arguments.length !== 1) {
args = [xtend({}, {
type: type
}, event)];
}
return _fire.apply(map, args);
};
}
ctx.map = map;
ctx.events = events(ctx);
ctx.ui = ui(ctx);
ctx.container = map.getContainer();
ctx.store = new Store(ctx);
controlContainer = ctx.ui.addButtons();
if (ctx.options.boxSelect) {
map.boxZoom.disable(); // Need to toggle dragPan on and off or else first
// dragPan disable attempt in simple_select doesn't work
map.dragPan.disable();
map.dragPan.enable();
}
if (map.loaded()) {
setup.connect();
} else {
map.on('load', setup.connect);
mapLoadedInterval = setInterval(function () {
if (map.loaded()) setup.connect();
}, 16);
}
ctx.events.start();
return controlContainer;
},
addLayers: function addLayers() {
// drawn features style
ctx.map.addSource(Constants.sources.COLD, {
data: {
type: Constants.geojsonTypes.FEATURE_COLLECTION,
features: []
},
type: 'geojson'
}); // hot features style
ctx.map.addSource(Constants.sources.HOT, {
data: {
type: Constants.geojsonTypes.FEATURE_COLLECTION,
features: []
},
type: 'geojson'
});
ctx.options.styles.forEach(function (style) {
ctx.map.addLayer(style);
});
ctx.store.setDirty(true);
ctx.store.render();
},
// Check for layers and sources before attempting to remove
// If user adds draw control and removes it before the map is loaded, layers and sources will be missing
removeLayers: function removeLayers() {
ctx.options.styles.forEach(function (style) {
if (ctx.map.getLayer(style.id)) {
ctx.map.removeLayer(style.id);
}
});
if (ctx.map.getSource(Constants.sources.COLD)) {
ctx.map.removeSource(Constants.sources.COLD);
}
if (ctx.map.getSource(Constants.sources.HOT)) {
ctx.map.removeSource(Constants.sources.HOT);
}
}
};
ctx.setup = setup;
return setup;
};
},{"./constants":23,"./events":24,"./store":64,"./ui":65,"xtend":21}],64:[function(require,module,exports){
"use strict";
var throttle = require('./lib/throttle');
var toDenseArray = require('./lib/to_dense_array');
var StringSet = require('./lib/string_set');
var render = require('./render');
var interactions = require('./constants').interactions;
var Store = module.exports = function (ctx) {
this._features = {};
this._featureIds = new StringSet();
this._selectedFeatureIds = new StringSet();
this._selectedCoordinates = [];
this._changedFeatureIds = new StringSet();
this._deletedFeaturesToEmit = [];
this._emitSelectionChange = false;
this._mapInitialConfig = {};
this.ctx = ctx;
this.sources = {
hot: [],
cold: []
};
this.render = throttle(render, 16, this);
this.isDirty = false;
};
/**
* Delays all rendering until the returned function is invoked
* @return {Function} renderBatch
*/
Store.prototype.createRenderBatch = function () {
var _this = this;
var holdRender = this.render;
var numRenders = 0;
this.render = function () {
numRenders++;
};
return function () {
_this.render = holdRender;
if (numRenders > 0) {
_this.render();
}
};
};
/**
* Sets the store's state to dirty.
* @return {Store} this
*/
Store.prototype.setDirty = function () {
this.isDirty = true;
return this;
};
/**
* Sets a feature's state to changed.
* @param {string} featureId
* @return {Store} this
*/
Store.prototype.featureChanged = function (featureId) {
this._changedFeatureIds.add(featureId);
return this;
};
/**
* Gets the ids of all features currently in changed state.
* @return {Store} this
*/
Store.prototype.getChangedIds = function () {
return this._changedFeatureIds.values();
};
/**
* Sets all features to unchanged state.
* @return {Store} this
*/
Store.prototype.clearChangedIds = function () {
this._changedFeatureIds.clear();
return this;
};
/**
* Gets the ids of all features in the store.
* @return {Store} this
*/
Store.prototype.getAllIds = function () {
return this._featureIds.values();
};
/**
* Adds a feature to the store.
* @param {Object} feature
*
* @return {Store} this
*/
Store.prototype.add = function (feature) {
this.featureChanged(feature.id);
this._features[feature.id] = feature;
this._featureIds.add(feature.id);
return this;
};
/**
* Deletes a feature or array of features from the store.
* Cleans up after the deletion by deselecting the features.
* If changes were made, sets the state to the dirty
* and fires an event.
* @param {string | Array<string>} featureIds
* @param {Object} [options]
* @param {Object} [options.silent] - If `true`, this invocation will not fire an event.
* @return {Store} this
*/
Store.prototype.delete = function (featureIds) {
var _this2 = this;
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
toDenseArray(featureIds).forEach(function (id) {
if (!_this2._featureIds.has(id)) return;
_this2._featureIds.delete(id);
_this2._selectedFeatureIds.delete(id);
if (!options.silent) {
if (_this2._deletedFeaturesToEmit.indexOf(_this2._features[id]) === -1) {
_this2._deletedFeaturesToEmit.push(_this2._features[id]);
}
}
delete _this2._features[id];
_this2.isDirty = true;
});
refreshSelectedCoordinates.call(this, options);
return this;
};
/**
* Returns a feature in the store matching the specified value.
* @return {Object | undefined} feature
*/
Store.prototype.get = function (id) {
return this._features[id];
};
/**
* Returns all features in the store.
* @return {Array<Object>}
*/
Store.prototype.getAll = function () {
var _this3 = this;
return Object.keys(this._features).map(function (id) {
return _this3._features[id];
});
};
/**
* Adds features to the current selection.
* @param {string | Array<string>} featureIds
* @param {Object} [options]
* @param {Object} [options.silent] - If `true`, this invocation will not fire an event.
* @return {Store} this
*/
Store.prototype.select = function (featureIds) {
var _this4 = this;
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
toDenseArray(featureIds).forEach(function (id) {
if (_this4._selectedFeatureIds.has(id)) return;
_this4._selectedFeatureIds.add(id);
_this4._changedFeatureIds.add(id);
if (!options.silent) {
_this4._emitSelectionChange = true;
}
});
return this;
};
/**
* Deletes features from the current selection.
* @param {string | Array<string>} featureIds
* @param {Object} [options]
* @param {Object} [options.silent] - If `true`, this invocation will not fire an event.
* @return {Store} this
*/
Store.prototype.deselect = function (featureIds) {
var _this5 = this;
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
toDenseArray(featureIds).forEach(function (id) {
if (!_this5._selectedFeatureIds.has(id)) return;
_this5._selectedFeatureIds.delete(id);
_this5._changedFeatureIds.add(id);
if (!options.silent) {
_this5._emitSelectionChange = true;
}
});
refreshSelectedCoordinates.call(this, options);
return this;
};
/**
* Clears the current selection.
* @param {Object} [options]
* @param {Object} [options.silent] - If `true`, this invocation will not fire an event.
* @return {Store} this
*/
Store.prototype.clearSelected = function () {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
this.deselect(this._selectedFeatureIds.values(), {
silent: options.silent
});
return this;
};
/**
* Sets the store's selection, clearing any prior values.
* If no feature ids are passed, the store is just cleared.
* @param {string | Array<string> | undefined} featureIds
* @param {Object} [options]
* @param {Object} [options.silent] - If `true`, this invocation will not fire an event.
* @return {Store} this
*/
Store.prototype.setSelected = function (featureIds) {
var _this6 = this;
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
featureIds = toDenseArray(featureIds); // Deselect any features not in the new selection
this.deselect(this._selectedFeatureIds.values().filter(function (id) {
return featureIds.indexOf(id) === -1;
}), {
silent: options.silent
}); // Select any features in the new selection that were not already selected
this.select(featureIds.filter(function (id) {
return !_this6._selectedFeatureIds.has(id);
}), {
silent: options.silent
});
return this;
};
/**
* Sets the store's coordinates selection, clearing any prior values.
* @param {Array<Array<string>>} coordinates
* @return {Store} this
*/
Store.prototype.setSelectedCoordinates = function (coordinates) {
this._selectedCoordinates = coordinates;
this._emitSelectionChange = true;
return this;
};
/**
* Clears the current coordinates selection.
* @param {Object} [options]
* @return {Store} this
*/
Store.prototype.clearSelectedCoordinates = function () {
this._selectedCoordinates = [];
this._emitSelectionChange = true;
return this;
};
/**
* Returns the ids of features in the current selection.
* @return {Array<string>} Selected feature ids.
*/
Store.prototype.getSelectedIds = function () {
return this._selectedFeatureIds.values();
};
/**
* Returns features in the current selection.
* @return {Array<Object>} Selected features.
*/
Store.prototype.getSelected = function () {
var _this7 = this;
return this._selectedFeatureIds.values().map(function (id) {
return _this7.get(id);
});
};
/**
* Returns selected coordinates in the currently selected feature.
* @return {Array<Object>} Selected coordinates.
*/
Store.prototype.getSelectedCoordinates = function () {
var _this8 = this;
var selected = this._selectedCoordinates.map(function (coordinate) {
var feature = _this8.get(coordinate.feature_id);
return {
coordinates: feature.getCoordinate(coordinate.coord_path)
};
});
return selected;
};
/**
* Indicates whether a feature is selected.
* @param {string} featureId
* @return {boolean} `true` if the feature is selected, `false` if not.
*/
Store.prototype.isSelected = function (featureId) {
return this._selectedFeatureIds.has(featureId);
};
/**
* Sets a property on the given feature
* @param {string} featureId
* @param {string} property property
* @param {string} property value
*/
Store.prototype.setFeatureProperty = function (featureId, property, value) {
this.get(featureId).setProperty(property, value);
this.featureChanged(featureId);
};
function refreshSelectedCoordinates(options) {
var _this9 = this;
var newSelectedCoordinates = this._selectedCoordinates.filter(function (point) {
return _this9._selectedFeatureIds.has(point.feature_id);
});
if (this._selectedCoordinates.length !== newSelectedCoordinates.length && !options.silent) {
this._emitSelectionChange = true;
}
this._selectedCoordinates = newSelectedCoordinates;
}
/**
* Stores the initial config for a map, so that we can set it again after we're done.
*/
Store.prototype.storeMapConfig = function () {
var _this10 = this;
interactions.forEach(function (interaction) {
var interactionSet = _this10.ctx.map[interaction];
if (interactionSet) {
_this10._mapInitialConfig[interaction] = _this10.ctx.map[interaction].isEnabled();
}
});
};
/**
* Restores the initial config for a map, ensuring all is well.
*/
Store.prototype.restoreMapConfig = function () {
var _this11 = this;
Object.keys(this._mapInitialConfig).forEach(function (key) {
var value = _this11._mapInitialConfig[key];
if (value) {
_this11.ctx.map[key].enable();
} else {
_this11.ctx.map[key].disable();
}
});
};
/**
* Returns the initial state of an interaction setting.
* @param {string} interaction
* @return {boolean} `true` if the interaction is enabled, `false` if not.
* Defaults to `true`. (Todo: include defaults.)
*/
Store.prototype.getInitialConfigValue = function (interaction) {
if (this._mapInitialConfig[interaction] !== undefined) {
return this._mapInitialConfig[interaction];
} else {
// This needs to be set to whatever the default is for that interaction
// It seems to be true for all cases currently, so let's send back `true`.
return true;
}
};
},{"./constants":23,"./lib/string_set":47,"./lib/throttle":50,"./lib/to_dense_array":51,"./render":62}],65:[function(require,module,exports){
"use strict";
var xtend = require('xtend');
var Constants = require('./constants');
var classTypes = ['mode', 'feature', 'mouse'];
module.exports = function (ctx) {
var buttonElements = {};
var activeButton = null;
var currentMapClasses = {
mode: null,
// e.g. mode-direct_select
feature: null,
// e.g. feature-vertex
mouse: null // e.g. mouse-move
};
var nextMapClasses = {
mode: null,
feature: null,
mouse: null
};
function clearMapClasses() {
queueMapClasses({
mode: null,
feature: null,
mouse: null
});
updateMapClasses();
}
function queueMapClasses(options) {
nextMapClasses = xtend(nextMapClasses, options);
}
function updateMapClasses() {
if (!ctx.container) return;
var classesToRemove = [];
var classesToAdd = [];
classTypes.forEach(function (type) {
if (nextMapClasses[type] === currentMapClasses[type]) return;
classesToRemove.push("".concat(type, "-").concat(currentMapClasses[type]));
if (nextMapClasses[type] !== null) {
classesToAdd.push("".concat(type, "-").concat(nextMapClasses[type]));
}
});
if (classesToRemove.length > 0) {
ctx.container.classList.remove.apply(ctx.container.classList, classesToRemove);
}
if (classesToAdd.length > 0) {
ctx.container.classList.add.apply(ctx.container.classList, classesToAdd);
}
currentMapClasses = xtend(currentMapClasses, nextMapClasses);
}
function createControlButton(id) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var button = document.createElement('button');
button.className = "".concat(Constants.classes.CONTROL_BUTTON, " ").concat(options.className);
button.setAttribute('title', options.title);
options.container.appendChild(button);
button.addEventListener('click', function (e) {
e.preventDefault();
e.stopPropagation();
var clickedButton = e.target;
if (clickedButton === activeButton) {
deactivateButtons();
return;
}
setActiveButton(id);
options.onActivate();
}, true);
return button;
}
function deactivateButtons() {
if (!activeButton) return;
activeButton.classList.remove(Constants.classes.ACTIVE_BUTTON);
activeButton = null;
}
function setActiveButton(id) {
deactivateButtons();
var button = buttonElements[id];
if (!button) return;
if (button && id !== 'trash') {
button.classList.add(Constants.classes.ACTIVE_BUTTON);
activeButton = button;
}
}
function addButtons() {
var controls = ctx.options.controls;
var controlGroup = document.createElement('div');
controlGroup.className = "".concat(Constants.classes.CONTROL_GROUP, " ").concat(Constants.classes.CONTROL_BASE);
if (!controls) return controlGroup;
if (controls[Constants.types.LINE]) {
buttonElements[Constants.types.LINE] = createControlButton(Constants.types.LINE, {
container: controlGroup,
className: Constants.classes.CONTROL_BUTTON_LINE,
title: "LineString tool ".concat(ctx.options.keybindings ? '(l)' : ''),
onActivate: function onActivate() {
return ctx.events.changeMode(Constants.modes.DRAW_LINE_STRING);
}
});
}
if (controls[Constants.types.POLYGON]) {
buttonElements[Constants.types.POLYGON] = createControlButton(Constants.types.POLYGON, {
container: controlGroup,
className: Constants.classes.CONTROL_BUTTON_POLYGON,
title: "Polygon tool ".concat(ctx.options.keybindings ? '(p)' : ''),
onActivate: function onActivate() {
return ctx.events.changeMode(Constants.modes.DRAW_POLYGON);
}
});
}
if (controls[Constants.types.POINT]) {
buttonElements[Constants.types.POINT] = createControlButton(Constants.types.POINT, {
container: controlGroup,
className: Constants.classes.CONTROL_BUTTON_POINT,
title: "Marker tool ".concat(ctx.options.keybindings ? '(m)' : ''),
onActivate: function onActivate() {
return ctx.events.changeMode(Constants.modes.DRAW_POINT);
}
});
}
if (controls.trash) {
buttonElements.trash = createControlButton('trash', {
container: controlGroup,
className: Constants.classes.CONTROL_BUTTON_TRASH,
title: 'Delete',
onActivate: function onActivate() {
ctx.events.trash();
}
});
}
if (controls.combine_features) {
buttonElements.combine_features = createControlButton('combineFeatures', {
container: controlGroup,
className: Constants.classes.CONTROL_BUTTON_COMBINE_FEATURES,
title: 'Combine',
onActivate: function onActivate() {
ctx.events.combineFeatures();
}
});
}
if (controls.uncombine_features) {
buttonElements.uncombine_features = createControlButton('uncombineFeatures', {
container: controlGroup,
className: Constants.classes.CONTROL_BUTTON_UNCOMBINE_FEATURES,
title: 'Uncombine',
onActivate: function onActivate() {
ctx.events.uncombineFeatures();
}
});
}
return controlGroup;
}
function removeButtons() {
Object.keys(buttonElements).forEach(function (buttonId) {
var button = buttonElements[buttonId];
if (button.parentNode) {
button.parentNode.removeChild(button);
}
delete buttonElements[buttonId];
});
}
return {
setActiveButton: setActiveButton,
queueMapClasses: queueMapClasses,
updateMapClasses: updateMapClasses,
clearMapClasses: clearMapClasses,
addButtons: addButtons,
removeButtons: removeButtons
};
};
},{"./constants":23,"xtend":21}]},{},[1])(1)
});
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).MapboxDraw=e()}}(function(){return function i(s,a,c){function u(t,e){if(!a[t]){if(!s[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(l)return l(t,!0);var o=new Error("Cannot find module '"+t+"'");throw o.code="MODULE_NOT_FOUND",o}var r=a[t]={exports:{}};s[t][0].call(r.exports,function(e){return u(s[t][1][e]||e)},r,r.exports,i,s,a,c)}return a[t].exports}for(var l="function"==typeof require&&require,e=0;e<c.length;e++)u(c[e]);return u}({1:[function(e,t,n){"use strict";var r=e("./src/setup"),i=e("./src/options"),s=e("./src/api"),a=e("./src/constants");t.exports=function(e){!function(e,t){var n={options:e=i(e)};t=s(n,t),n.api=t;var o=r(n);t.onAdd=o.onAdd,t.onRemove=o.onRemove,t.types=a.types,t.options=e}(e,this)},t.exports.modes=e("./src/modes")},{"./src/api":22,"./src/constants":23,"./src/modes":56,"./src/options":61,"./src/setup":63}],2:[function(e,t,n){function o(e){if(!(this instanceof o))return new o(e);this._bbox=e||[1/0,1/0,-1/0,-1/0],this._valid=!!e}(t.exports=o).prototype.include=function(e){return this._valid=!0,this._bbox[0]=Math.min(this._bbox[0],e[0]),this._bbox[1]=Math.min(this._bbox[1],e[1]),this._bbox[2]=Math.max(this._bbox[2],e[0]),this._bbox[3]=Math.max(this._bbox[3],e[1]),this},o.prototype.equals=function(e){var t;return t=e instanceof o?e.bbox():e,this._bbox[0]==t[0]&&this._bbox[1]==t[1]&&this._bbox[2]==t[2]&&this._bbox[3]==t[3]},o.prototype.center=function(e){return this._valid?[(this._bbox[0]+this._bbox[2])/2,(this._bbox[1]+this._bbox[3])/2]:null},o.prototype.union=function(e){var t;return this._valid=!0,t=e instanceof o?e.bbox():e,this._bbox[0]=Math.min(this._bbox[0],t[0]),this._bbox[1]=Math.min(this._bbox[1],t[1]),this._bbox[2]=Math.max(this._bbox[2],t[2]),this._bbox[3]=Math.max(this._bbox[3],t[3]),this},o.prototype.bbox=function(){return this._valid?this._bbox:null},o.prototype.contains=function(e){if(!e)return this._fastContains();if(!this._valid)return null;var t=e[0],n=e[1];return this._bbox[0]<=t&&this._bbox[1]<=n&&this._bbox[2]>=t&&this._bbox[3]>=n},o.prototype.intersect=function(e){return this._valid?(t=e instanceof o?e.bbox():e,!(this._bbox[0]>t[2]||this._bbox[2]<t[0]||this._bbox[3]<t[1]||this._bbox[1]>t[3])):null;var t},o.prototype._fastContains=function(){if(!this._valid)return new Function("return null;");var e="return "+this._bbox[0]+"<= ll[0] &&"+this._bbox[1]+"<= ll[1] &&"+this._bbox[2]+">= ll[0] &&"+this._bbox[3]+">= ll[1]";return new Function("ll",e)},o.prototype.polygon=function(){return this._valid?{type:"Polygon",coordinates:[[[this._bbox[0],this._bbox[1]],[this._bbox[2],this._bbox[1]],[this._bbox[2],this._bbox[3]],[this._bbox[0],this._bbox[3]],[this._bbox[0],this._bbox[1]]]]}:null}},{}],3:[function(e,t,n){var u=e("wgs84");function r(e){var t=0;if(e&&0<e.length){t+=Math.abs(o(e[0]));for(var n=1;n<e.length;n++)t-=Math.abs(o(e[n]))}return t}function o(e){var t,n,o,r,i,s,a=0,c=e.length;if(2<c){for(s=0;s<c;s++)i=s===c-2?(o=c-2,r=c-1,0):s===c-1?(o=c-1,r=0,1):(r=(o=s)+1,s+2),t=e[o],n=e[r],a+=(l(e[i][0])-l(t[0]))*Math.sin(l(n[1]));a=a*u.RADIUS*u.RADIUS/2}return a}function l(e){return e*Math.PI/180}t.exports.geometry=function e(t){var n,o=0;switch(t.type){case"Polygon":return r(t.coordinates);case"MultiPolygon":for(n=0;n<t.coordinates.length;n++)o+=r(t.coordinates[n]);return o;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0;case"GeometryCollection":for(n=0;n<t.geometries.length;n++)o+=e(t.geometries[n]);return o}},t.exports.ring=o},{wgs84:20}],4:[function(e,t,n){t.exports=function(e){return function n(e){if(Array.isArray(e)&&e.length&&"number"==typeof e[0])return[e];return e.reduce(function(e,t){return Array.isArray(t)&&Array.isArray(t[0])?e.concat(n(t)):(e.push(t),e)},[])}(e)}},{}],5:[function(e,t,n){var o=e("@mapbox/geojson-normalize"),r=e("geojson-flatten"),i=e("./flatten");t.exports=function(e){if(!e)return[];var t=r(o(e)),n=[];return t.features.forEach(function(e){e.geometry&&(n=n.concat(i(e.geometry.coordinates)))}),n}},{"./flatten":4,"@mapbox/geojson-normalize":7,"geojson-flatten":13}],6:[function(e,t,n){var r=e("@mapbox/geojson-coords"),o=e("traverse"),i=e("@mapbox/extent"),s={features:["FeatureCollection"],coordinates:["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon"],geometry:["Feature"],geometries:["GeometryCollection"]},a=Object.keys(s);function c(e){for(var t=i(),n=r(e),o=0;o<n.length;o++)t.include(n[o]);return t}t.exports=function(e){return c(e).bbox()},t.exports.polygon=function(e){return c(e).polygon()},t.exports.bboxify=function(e){return o(e).map(function(t){t&&(a.some(function(e){return!!t[e]&&-1!==s[e].indexOf(t.type)})&&(t.bbox=c(t).bbox(),this.update(t)))})}},{"@mapbox/extent":2,"@mapbox/geojson-coords":5,traverse:19}],7:[function(e,t,n){t.exports=function(e){if(!e||!e.type)return null;var t=o[e.type];if(!t)return null;{if("geometry"===t)return{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:e}]};if("feature"===t)return{type:"FeatureCollection",features:[e]};if("featurecollection"===t)return e}};var o={Point:"geometry",MultiPoint:"geometry",LineString:"geometry",MultiLineString:"geometry",Polygon:"geometry",MultiPolygon:"geometry",GeometryCollection:"geometry",Feature:"feature",FeatureCollection:"featurecollection"}},{}],8:[function(e,t,n){var i=e("jsonlint-lines"),s=e("./object");t.exports.hint=function(e,t){var n,o=[];if("object"==typeof e)n=e;else{if("string"!=typeof e)return[{message:"Expected string or object as input",line:0}];try{n=i.parse(e)}catch(e){var r=e.message.match(/line (\d+)/);return[{line:parseInt(r[1],10)-1,message:e.message,error:e}]}}return o=o.concat(s.hint(n,t))}},{"./object":9,"jsonlint-lines":15}],9:[function(e,t,n){var y=e("./rhr");t.exports.hint=function(e,n){var i=[],s=0,t=10,a=6;function o(e){if(n&&!1===n.noDuplicateMembers||!e.__duplicateProperties__||i.push({message:"An object contained duplicate members, making parsing ambigous: "+e.__duplicateProperties__.join(", "),line:e.__line__}),!r(e,"type","string"))if(d[e.type])e&&d[e.type](e);else{var t=g[e.type.toLowerCase()];void 0!==t?i.push({message:"Expected "+t+" but got "+e.type+" (case sensitive)",line:e.__line__}):i.push({message:"The type "+e.type+" is unknown",line:e.__line__})}}function c(e,t){return e.every(function(e){return null!==e&&typeof e===t})}function r(e,t,n){if(void 0===e[t])return i.push({message:'"'+t+'" member required',line:e.__line__});if("array"===n){if(!Array.isArray(e[t]))return i.push({message:'"'+t+'" member should be an array, but is an '+typeof e[t]+" instead",line:e.__line__})}else{if("object"===n&&e[t]&&"Object"!==e[t].constructor.name)return i.push({message:'"'+t+'" member should be '+n+", but is an "+e[t].constructor.name+" instead",line:e.__line__});if(n&&typeof e[t]!==n)return i.push({message:'"'+t+'" member should be '+n+", but is an "+typeof e[t]+" instead",line:e.__line__})}}function u(o,r){if(!Array.isArray(o))return i.push({message:"position should be an array, is a "+typeof o+" instead",line:o.__line__||r});if(o.length<2)return i.push({message:"position must have 2 or more elements",line:o.__line__||r});if(3<o.length)return i.push({message:"position should not have more than 3 elements",level:"message",line:o.__line__||r});if(!c(o,"number"))return i.push({message:"each element in a position must be a number",line:o.__line__||r});if(n&&n.precisionWarning){if(s===t)return s+=1,i.push({message:"truncated warnings: we've encountered coordinate precision warning "+t+" times, no more warnings will be reported",level:"message",line:o.__line__||r});s<t&&o.forEach(function(e){var t=0,n=String(e).split(".")[1];if(void 0!==n&&(t=n.length),a<t)return s+=1,i.push({message:"precision of coordinates should be reduced",level:"message",line:o.__line__||r})})}}function l(n,t,o,r){if(void 0===r&&void 0!==n.__line__&&(r=n.__line__),0===o)return u(n,r);if(1===o&&t)if("LinearRing"===t){if(!Array.isArray(n[n.length-1]))return i.push({message:"a number was found where a coordinate array should have been found: this needs to be nested more deeply",line:r}),!0;if(n.length<4&&i.push({message:"a LinearRing of coordinates needs to have four or more positions",line:r}),n.length&&(n[n.length-1].length!==n[0].length||!n[n.length-1].every(function(e,t){return n[0][t]===e})))return i.push({message:"the first and last positions in a LinearRing of coordinates must be the same",line:r}),!0}else if("Line"===t&&n.length<2)return i.push({message:"a line needs to have two or more coordinates to be valid",line:r});if(Array.isArray(n))return n.map(function(e){return l(e,t,o-1,e.__line__||r)}).some(function(e){return e});i.push({message:"a number was found where a coordinate array should have been found: this needs to be nested more deeply",line:r})}function p(e){e.crs&&("object"==typeof e.crs&&e.crs.properties&&"urn:ogc:def:crs:OGC:1.3:CRS84"===e.crs.properties.name?i.push({message:"old-style crs member is not recommended, this object is equivalent to the default and should be removed",line:e.__line__}):i.push({message:"old-style crs member is not recommended",line:e.__line__}))}function f(e){if(e.bbox)return Array.isArray(e.bbox)?(c(e.bbox,"number")||i.push({message:"each element in a bbox member must be a number",line:e.bbox.__line__}),4!==e.bbox.length&&6!==e.bbox.length&&i.push({message:"bbox must contain 4 elements (for 2D) or 6 elements (for 3D)",line:e.bbox.__line__}),i.length):void i.push({message:"bbox member must be an array of numbers, but is a "+typeof e.bbox,line:e.__line__})}function h(e){p(e),f(e),void 0!==e.id&&"string"!=typeof e.id&&"number"!=typeof e.id&&i.push({message:'Feature "id" member must have a string or number value',line:e.__line__}),void 0!==e.features&&i.push({message:'Feature object cannot contain a "features" member',line:e.__line__}),void 0!==e.coordinates&&i.push({message:'Feature object cannot contain a "coordinates" member',line:e.__line__}),"Feature"!==e.type&&i.push({message:"GeoJSON features must have a type=feature member",line:e.__line__}),r(e,"properties","object"),r(e,"geometry","object")||e.geometry&&o(e.geometry)}var d={Point:function(e){var t;p(e),f(e),void 0!==(t=e).properties&&i.push({message:'geometry object cannot contain a "properties" member',line:t.__line__}),void 0!==t.geometry&&i.push({message:'geometry object cannot contain a "geometry" member',line:t.__line__}),void 0!==t.features&&i.push({message:'geometry object cannot contain a "features" member',line:t.__line__}),r(e,"coordinates","array")||u(e.coordinates)},Feature:h,MultiPoint:function(e){p(e),f(e),r(e,"coordinates","array")||l(e.coordinates,"",1)},LineString:function(e){p(e),f(e),r(e,"coordinates","array")||l(e.coordinates,"Line",1)},MultiLineString:function(e){p(e),f(e),r(e,"coordinates","array")||l(e.coordinates,"Line",2)},FeatureCollection:function(e){if(p(e),f(e),void 0!==e.properties&&i.push({message:'FeatureCollection object cannot contain a "properties" member',line:e.__line__}),void 0!==e.coordinates&&i.push({message:'FeatureCollection object cannot contain a "coordinates" member',line:e.__line__}),!r(e,"features","array")){if(!c(e.features,"object"))return i.push({message:"Every feature must be an object",line:e.__line__});e.features.forEach(h)}},GeometryCollection:function(t){p(t),f(t),r(t,"geometries","array")||(c(t.geometries,"object")||i.push({message:"The geometries array in a GeometryCollection must contain only geometry objects",line:t.__line__}),1===t.geometries.length&&i.push({message:"GeometryCollection with a single geometry should be avoided in favor of single part or a single object of multi-part type",line:t.geometries.__line__}),t.geometries.forEach(function(e){e&&("GeometryCollection"===e.type&&i.push({message:"GeometryCollection should avoid nested geometry collections",line:t.geometries.__line__}),o(e))}))},Polygon:function(e){p(e),f(e),r(e,"coordinates","array")||l(e.coordinates,"LinearRing",2)||y(e,i)},MultiPolygon:function(e){p(e),f(e),r(e,"coordinates","array")||l(e.coordinates,"LinearRing",3)||y(e,i)}},g=Object.keys(d).reduce(function(e,t){return e[t.toLowerCase()]=t,e},{});return"object"!=typeof e||null==e?i.push({message:"The root of a GeoJSON object must be an object.",line:0}):(o(e),i.forEach(function(e){({}).hasOwnProperty.call(e,"line")&&void 0===e.line&&delete e.line})),i}},{"./rhr":10}],10:[function(e,t,n){function i(e){return e*Math.PI/180}function o(e){var t=0;if(2<e.length)for(var n,o,r=0;r<e.length-1;r++)n=e[r],t+=i((o=e[r+1])[0]-n[0])*(2+Math.sin(i(n[1]))+Math.sin(i(o[1])));return 0<=t}function r(e){if(e&&0<e.length){if(o(e[0]))return!1;if(!e.slice(1,e.length).every(o))return!1}return!0}t.exports=function(e,t){var n;("Polygon"===(n=e).type?r(n.coordinates):"MultiPolygon"===n.type?n.coordinates.every(r):void 0)||t.push({message:"Polygons and MultiPolygons should follow the right-hand rule",level:"message",line:e.__line__})}},{}],11:[function(e,t,n){"use strict";function o(e,t){this.x=e,this.y=t}(t.exports=o).prototype={clone:function(){return new o(this.x,this.y)},add:function(e){return this.clone()._add(e)},sub:function(e){return this.clone()._sub(e)},multByPoint:function(e){return this.clone()._multByPoint(e)},divByPoint:function(e){return this.clone()._divByPoint(e)},mult:function(e){return this.clone()._mult(e)},div:function(e){return this.clone()._div(e)},rotate:function(e){return this.clone()._rotate(e)},rotateAround:function(e,t){return this.clone()._rotateAround(e,t)},matMult:function(e){return this.clone()._matMult(e)},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(e){return this.x===e.x&&this.y===e.y},dist:function(e){return Math.sqrt(this.distSqr(e))},distSqr:function(e){var t=e.x-this.x,n=e.y-this.y;return t*t+n*n},angle:function(){return Math.atan2(this.y,this.x)},angleTo:function(e){return Math.atan2(this.y-e.y,this.x-e.x)},angleWith:function(e){return this.angleWithSep(e.x,e.y)},angleWithSep:function(e,t){return Math.atan2(this.x*t-this.y*e,this.x*e+this.y*t)},_matMult:function(e){var t=e[0]*this.x+e[1]*this.y,n=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=n,this},_add:function(e){return this.x+=e.x,this.y+=e.y,this},_sub:function(e){return this.x-=e.x,this.y-=e.y,this},_mult:function(e){return this.x*=e,this.y*=e,this},_div:function(e){return this.x/=e,this.y/=e,this},_multByPoint:function(e){return this.x*=e.x,this.y*=e.y,this},_divByPoint:function(e){return this.x/=e.x,this.y/=e.y,this},_unit:function(){return this._div(this.mag()),this},_perp:function(){var e=this.y;return this.y=this.x,this.x=-e,this},_rotate:function(e){var t=Math.cos(e),n=Math.sin(e),o=t*this.x-n*this.y,r=n*this.x+t*this.y;return this.x=o,this.y=r,this},_rotateAround:function(e,t){var n=Math.cos(e),o=Math.sin(e),r=t.x+n*(this.x-t.x)-o*(this.y-t.y),i=t.y+o*(this.x-t.x)+n*(this.y-t.y);return this.x=r,this.y=i,this},_round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}},o.convert=function(e){return e instanceof o?e:Array.isArray(e)?new o(e[0],e[1]):e}},{}],12:[function(e,t,n){},{}],13:[function(e,t,n){t.exports=function n(o){switch(o&&o.type||null){case"FeatureCollection":return o.features=o.features.reduce(function(e,t){return e.concat(n(t))},[]),o;case"Feature":return o.geometry?n(o.geometry).map(function(e){var t={type:"Feature",properties:JSON.parse(JSON.stringify(o.properties)),geometry:e};return void 0!==o.id&&(t.id=o.id),t}):o;case"MultiPoint":return o.coordinates.map(function(e){return{type:"Point",coordinates:e}});case"MultiPolygon":return o.coordinates.map(function(e){return{type:"Polygon",coordinates:e}});case"MultiLineString":return o.coordinates.map(function(e){return{type:"LineString",coordinates:e}});case"GeometryCollection":return o.geometries.map(n).reduce(function(e,t){return e.concat(t)},[]);case"Point":case"Polygon":case"LineString":return[o]}}},{}],14:[function(e,t,n){var c=t.exports=function(e,t){if(t||(t=16),void 0===e&&(e=128),e<=0)return"0";for(var n=Math.log(Math.pow(2,e))/Math.log(t),o=2;n===1/0;o*=2)n=Math.log(Math.pow(2,e/o))/Math.log(t)*o;var r=n-Math.floor(n),i="";for(o=0;o<Math.floor(n);o++){i=Math.floor(Math.random()*t).toString(t)+i}if(r){var s=Math.pow(t,r);i=Math.floor(Math.random()*s).toString(t)+i}var a=parseInt(i,t);return a!==1/0&&a>=Math.pow(2,e)?c(e,t):i};c.rack=function(o,r,i){var n=function(e){var t=0;do{if(10<t++){if(!i)throw new Error("too many ID collisions, use more bits");o+=i}var n=c(o,r)}while(Object.hasOwnProperty.call(s,n));return s[n]=e,n},s=n.hats={};return n.get=function(e){return n.hats[e]},n.set=function(e,t){return n.hats[e]=t,n},n.bits=o||128,n.base=r||16,n}},{}],15:[function(o,t,r){(function(n){var e=function(){var e=function(e,t,n,o){for(n=n||{},o=e.length;o--;n[e[o]]=t);return n},t=[1,12],n=[1,13],o=[1,9],r=[1,10],i=[1,11],s=[1,14],a=[1,15],c=[14,18,22,24],u=[18,22],l=[22,24],p={trace:function(){},yy:{},symbols_:{error:2,JSONString:3,STRING:4,JSONNumber:5,NUMBER:6,JSONNullLiteral:7,NULL:8,JSONBooleanLiteral:9,TRUE:10,FALSE:11,JSONText:12,JSONValue:13,EOF:14,JSONObject:15,JSONArray:16,"{":17,"}":18,JSONMemberList:19,JSONMember:20,":":21,",":22,"[":23,"]":24,JSONElementList:25,$accept:0,$end:1},terminals_:{2:"error",4:"STRING",6:"NUMBER",8:"NULL",10:"TRUE",11:"FALSE",14:"EOF",17:"{",18:"}",21:":",22:",",23:"[",24:"]"},productions_:[0,[3,1],[5,1],[7,1],[9,1],[9,1],[12,2],[13,1],[13,1],[13,1],[13,1],[13,1],[13,1],[15,2],[15,3],[20,3],[19,1],[19,3],[16,2],[16,3],[25,1],[25,3]],performAction:function(e,t,n,o,r,i,s){var a=i.length-1;switch(r){case 1:this.$=e.replace(/\\(\\|")/g,"$1").replace(/\\n/g,"\n").replace(/\\r/g,"\r").replace(/\\t/g,"\t").replace(/\\v/g,"\v").replace(/\\f/g,"\f").replace(/\\b/g,"\b");break;case 2:this.$=Number(e);break;case 3:this.$=null;break;case 4:this.$=!0;break;case 5:this.$=!1;break;case 6:return this.$=i[a-1];case 13:this.$={},Object.defineProperty(this.$,"__line__",{value:this._$.first_line,enumerable:!1});break;case 14:case 19:this.$=i[a-1],Object.defineProperty(this.$,"__line__",{value:this._$.first_line,enumerable:!1});break;case 15:this.$=[i[a-2],i[a]];break;case 16:this.$={},this.$[i[a][0]]=i[a][1];break;case 17:this.$=i[a-2],void 0!==i[a-2][i[a][0]]&&(this.$.__duplicateProperties__||Object.defineProperty(this.$,"__duplicateProperties__",{value:[],enumerable:!1}),this.$.__duplicateProperties__.push(i[a][0])),i[a-2][i[a][0]]=i[a][1];break;case 18:this.$=[],Object.defineProperty(this.$,"__line__",{value:this._$.first_line,enumerable:!1});break;case 20:this.$=[i[a]];break;case 21:this.$=i[a-2],i[a-2].push(i[a])}},table:[{3:5,4:t,5:6,6:n,7:3,8:o,9:4,10:r,11:i,12:1,13:2,15:7,16:8,17:s,23:a},{1:[3]},{14:[1,16]},e(c,[2,7]),e(c,[2,8]),e(c,[2,9]),e(c,[2,10]),e(c,[2,11]),e(c,[2,12]),e(c,[2,3]),e(c,[2,4]),e(c,[2,5]),e([14,18,21,22,24],[2,1]),e(c,[2,2]),{3:20,4:t,18:[1,17],19:18,20:19},{3:5,4:t,5:6,6:n,7:3,8:o,9:4,10:r,11:i,13:23,15:7,16:8,17:s,23:a,24:[1,21],25:22},{1:[2,6]},e(c,[2,13]),{18:[1,24],22:[1,25]},e(u,[2,16]),{21:[1,26]},e(c,[2,18]),{22:[1,28],24:[1,27]},e(l,[2,20]),e(c,[2,14]),{3:20,4:t,20:29},{3:5,4:t,5:6,6:n,7:3,8:o,9:4,10:r,11:i,13:30,15:7,16:8,17:s,23:a},e(c,[2,19]),{3:5,4:t,5:6,6:n,7:3,8:o,9:4,10:r,11:i,13:31,15:7,16:8,17:s,23:a},e(u,[2,17]),e(u,[2,15]),e(l,[2,21])],defaultActions:{16:[2,6]},parseError:function(e,t){if(!t.recoverable){function n(e,t){this.message=e,this.hash=t}throw n.prototype=Error,new n(e,t)}this.trace(e)},parse:function(e){var t=this,n=[0],o=[null],r=[],i=this.table,s="",a=0,c=0,u=0,l=r.slice.call(arguments,1),p=Object.create(this.lexer),f={yy:{}};for(var h in this.yy)Object.prototype.hasOwnProperty.call(this.yy,h)&&(f.yy[h]=this.yy[h]);p.setInput(e,f.yy),f.yy.lexer=p,f.yy.parser=this,void 0===p.yylloc&&(p.yylloc={});var d=p.yylloc;r.push(d);var g=p.options&&p.options.ranges;"function"==typeof f.yy.parseError?this.parseError=f.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var y,m,_,v,b,E,T,x,S,C=function(){var e;return"number"!=typeof(e=p.lex()||1)&&(e=t.symbols_[e]||e),e},O={};;){if(_=n[n.length-1],void 0===(v=this.defaultActions[_]?this.defaultActions[_]:(null==y&&(y=C()),i[_]&&i[_][y]))||!v.length||!v[0]){var I="";for(E in S=[],i[_])this.terminals_[E]&&2<E&&S.push("'"+this.terminals_[E]+"'");I=p.showPosition?"Parse error on line "+(a+1)+":\n"+p.showPosition()+"\nExpecting "+S.join(", ")+", got '"+(this.terminals_[y]||y)+"'":"Parse error on line "+(a+1)+": Unexpected "+(1==y?"end of input":"'"+(this.terminals_[y]||y)+"'"),this.parseError(I,{text:p.match,token:this.terminals_[y]||y,line:p.yylineno,loc:d,expected:S})}if(v[0]instanceof Array&&1<v.length)throw new Error("Parse Error: multiple actions possible at state: "+_+", token: "+y);switch(v[0]){case 1:n.push(y),o.push(p.yytext),r.push(p.yylloc),n.push(v[1]),y=null,m?(y=m,m=null):(c=p.yyleng,s=p.yytext,a=p.yylineno,d=p.yylloc,0<u&&u--);break;case 2:if(T=this.productions_[v[1]][1],O.$=o[o.length-T],O._$={first_line:r[r.length-(T||1)].first_line,last_line:r[r.length-1].last_line,first_column:r[r.length-(T||1)].first_column,last_column:r[r.length-1].last_column},g&&(O._$.range=[r[r.length-(T||1)].range[0],r[r.length-1].range[1]]),void 0!==(b=this.performAction.apply(O,[s,c,a,f.yy,v[1],o,r].concat(l))))return b;T&&(n=n.slice(0,-1*T*2),o=o.slice(0,-1*T),r=r.slice(0,-1*T)),n.push(this.productions_[v[1]][0]),o.push(O.$),r.push(O._$),x=i[n[n.length-2]][n[n.length-1]],n.push(x);break;case 3:return!0}}return!0}},f={EOF:1,parseError:function(e,t){if(!this.yy.parser)throw new Error(e);this.yy.parser.parseError(e,t)},setInput:function(e,t){return this.yy=t||this.yy||{},this._input=e,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var e=this._input[0];return this.yytext+=e,this.yyleng++,this.offset++,this.match+=e,this.matched+=e,e.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),e},unput:function(e){var t=e.length,n=e.split(/(?:\r\n?|\n)/g);this._input=e+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-t),this.offset-=t;var o=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),n.length-1&&(this.yylineno-=n.length-1);var r=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:n?(n.length===o.length?this.yylloc.first_column:0)+o[o.length-n.length].length-n[0].length:this.yylloc.first_column-t},this.options.ranges&&(this.yylloc.range=[r[0],r[0]+this.yyleng-t]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(e){this.unput(this.match.slice(e))},pastInput:function(){var e=this.matched.substr(0,this.matched.length-this.match.length);return(20<e.length?"...":"")+e.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var e=this.match;return e.length<20&&(e+=this._input.substr(0,20-e.length)),(e.substr(0,20)+(20<e.length?"...":"")).replace(/\n/g,"")},showPosition:function(){var e=this.pastInput(),t=new Array(e.length+1).join("-");return e+this.upcomingInput()+"\n"+t+"^"},test_match:function(e,t){var n,o,r;if(this.options.backtrack_lexer&&(r={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(r.yylloc.range=this.yylloc.range.slice(0))),(o=e[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=o.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:o?o[o.length-1].length-o[o.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+e[0].length},this.yytext+=e[0],this.match+=e[0],this.matches=e,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(e[0].length),this.matched+=e[0],n=this.performAction.call(this,this.yy,this,t,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),n)return n;if(this._backtrack){for(var i in r)this[i]=r[i];return!1}return!1},next:function(){if(this.done)return this.EOF;var e,t,n,o;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var r=this._currentRules(),i=0;i<r.length;i++)if((n=this._input.match(this.rules[r[i]]))&&(!t||n[0].length>t[0].length)){if(t=n,o=i,this.options.backtrack_lexer){if(!1!==(e=this.test_match(n,r[i])))return e;if(this._backtrack){t=!1;continue}return!1}if(!this.options.flex)break}return t?!1!==(e=this.test_match(t,r[o]))&&e:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var e=this.next();return e||this.lex()},begin:function(e){this.conditionStack.push(e)},popState:function(){return 0<this.conditionStack.length-1?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(e){return 0<=(e=this.conditionStack.length-1-Math.abs(e||0))?this.conditionStack[e]:"INITIAL"},pushState:function(e){this.begin(e)},stateStackSize:function(){return this.conditionStack.length},options:{},performAction:function(e,t,n,o){switch(n){case 0:break;case 1:return 6;case 2:return t.yytext=t.yytext.substr(1,t.yyleng-2),4;case 3:return 17;case 4:return 18;case 5:return 23;case 6:return 24;case 7:return 22;case 8:return 21;case 9:return 10;case 10:return 11;case 11:return 8;case 12:return 14;case 13:return"INVALID"}},rules:[/^(?:\s+)/,/^(?:(-?([0-9]|[1-9][0-9]+))(\.[0-9]+)?([eE][-+]?[0-9]+)?\b)/,/^(?:"(?:\\[\\"bfnrt\/]|\\u[a-fA-F0-9]{4}|[^\\\0-\x09\x0a-\x1f"])*")/,/^(?:\{)/,/^(?:\})/,/^(?:\[)/,/^(?:\])/,/^(?:,)/,/^(?::)/,/^(?:true\b)/,/^(?:false\b)/,/^(?:null\b)/,/^(?:$)/,/^(?:.)/],conditions:{INITIAL:{rules:[0,1,2,3,4,5,6,7,8,9,10,11,12,13],inclusive:!0}}};function h(){this.yy={}}return p.lexer=f,new((h.prototype=p).Parser=h)}();void 0!==o&&void 0!==r&&(r.parser=e,r.Parser=e.Parser,r.parse=function(){return e.parse.apply(e,arguments)},r.main=function(e){e[1]||(console.log("Usage: "+e[0]+" FILE"),n.exit(1));var t=o("fs").readFileSync(o("path").normalize(e[1]),"utf8");return r.parser.parse(t)},void 0!==t&&o.main===t&&r.main(n.argv.slice(1)))}).call(this,o("_process"))},{_process:18,fs:12,path:17}],16:[function(e,Qe,et){(function(e){var o="__lodash_hash_undefined__",b=1,m=2,n=9007199254740991,_="[object Arguments]",v="[object Array]",r="[object AsyncFunction]",E="[object Boolean]",T="[object Date]",x="[object Error]",i="[object Function]",s="[object GeneratorFunction]",S="[object Map]",C="[object Number]",a="[object Null]",O="[object Object]",c="[object Promise]",u="[object Proxy]",I="[object RegExp]",L="[object Set]",M="[object String]",w="[object Symbol]",l="[object Undefined]",p="[object WeakMap]",N="[object ArrayBuffer]",A="[object DataView]",f=/^\[object .+?Constructor\]$/,h=/^(?:0|[1-9]\d*)$/,t={};t["[object Float32Array]"]=t["[object Float64Array]"]=t["[object Int8Array]"]=t["[object Int16Array]"]=t["[object Int32Array]"]=t["[object Uint8Array]"]=t["[object Uint8ClampedArray]"]=t["[object Uint16Array]"]=t["[object Uint32Array]"]=!0,t[_]=t[v]=t[N]=t[E]=t[A]=t[T]=t[x]=t[i]=t[S]=t[C]=t[O]=t[I]=t[L]=t[M]=t[p]=!1;var d="object"==typeof e&&e&&e.Object===Object&&e,g="object"==typeof self&&self&&self.Object===Object&&self,y=d||g||Function("return this")(),P="object"==typeof et&&et&&!et.nodeType&&et,F=P&&"object"==typeof Qe&&Qe&&!Qe.nodeType&&Qe,j=F&&F.exports===P,k=j&&d.process,R=function(){try{return k&&k.binding&&k.binding("util")}catch(e){}}(),D=R&&R.isTypedArray;function U(e,t){for(var n=-1,o=null==e?0:e.length;++n<o;)if(t(e[n],n,e))return!0;return!1}function V(e){var n=-1,o=Array(e.size);return e.forEach(function(e,t){o[++n]=[t,e]}),o}function G(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var B,$,J,z=Array.prototype,q=Function.prototype,Y=Object.prototype,X=y["__core-js_shared__"],K=q.toString,W=Y.hasOwnProperty,H=(B=/[^.]+$/.exec(X&&X.keys&&X.keys.IE_PROTO||""))?"Symbol(src)_1."+B:"",Z=Y.toString,Q=RegExp("^"+K.call(W).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ee=j?y.Buffer:void 0,te=y.Symbol,ne=y.Uint8Array,oe=Y.propertyIsEnumerable,re=z.splice,ie=te?te.toStringTag:void 0,se=Object.getOwnPropertySymbols,ae=ee?ee.isBuffer:void 0,ce=($=Object.keys,J=Object,function(e){return $(J(e))}),ue=Re(y,"DataView"),le=Re(y,"Map"),pe=Re(y,"Promise"),fe=Re(y,"Set"),he=Re(y,"WeakMap"),de=Re(Object,"create"),ge=Ge(ue),ye=Ge(le),me=Ge(pe),_e=Ge(fe),ve=Ge(he),be=te?te.prototype:void 0,Ee=be?be.valueOf:void 0;function Te(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var o=e[t];this.set(o[0],o[1])}}function xe(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var o=e[t];this.set(o[0],o[1])}}function Se(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var o=e[t];this.set(o[0],o[1])}}function Ce(e){var t=-1,n=null==e?0:e.length;for(this.__data__=new Se;++t<n;)this.add(e[t])}function Oe(e){var t=this.__data__=new xe(e);this.size=t.size}function Ie(e,t){var n=Je(e),o=!n&&$e(e),r=!n&&!o&&ze(e),i=!n&&!o&&!r&&He(e),s=n||o||r||i,a=s?function(e,t){for(var n=-1,o=Array(e);++n<e;)o[n]=t(n);return o}(e.length,String):[],c=a.length;for(var u in e)!t&&!W.call(e,u)||s&&("length"==u||r&&("offset"==u||"parent"==u)||i&&("buffer"==u||"byteLength"==u||"byteOffset"==u)||Ve(u,c))||a.push(u);return a}function Le(e,t){for(var n=e.length;n--;)if(Be(e[n][0],t))return n;return-1}function Me(e){return null==e?void 0===e?l:a:ie&&ie in Object(e)?function(e){var t=W.call(e,ie),n=e[ie];try{var o=!(e[ie]=void 0)}catch(e){}var r=Z.call(e);o&&(t?e[ie]=n:delete e[ie]);return r}(e):(t=e,Z.call(t));var t}function we(e){return Ke(e)&&Me(e)==_}function Ne(e,t,n,o,r){return e===t||(null==e||null==t||!Ke(e)&&!Ke(t)?e!=e&&t!=t:function(e,t,n,o,r,i){var s=Je(e),a=Je(t),c=s?v:Ue(e),u=a?v:Ue(t),l=(c=c==_?O:c)==O,p=(u=u==_?O:u)==O,f=c==u;if(f&&ze(e)){if(!ze(t))return!1;l=!(s=!0)}if(f&&!l)return i||(i=new Oe),s||He(e)?Fe(e,t,n,o,r,i):function(e,t,n,o,r,i,s){switch(n){case A:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case N:return!(e.byteLength!=t.byteLength||!i(new ne(e),new ne(t)));case E:case T:case C:return Be(+e,+t);case x:return e.name==t.name&&e.message==t.message;case I:case M:return e==t+"";case S:var a=V;case L:var c=o&b;if(a||(a=G),e.size!=t.size&&!c)return!1;var u=s.get(e);if(u)return u==t;o|=m,s.set(e,t);var l=Fe(a(e),a(t),o,r,i,s);return s.delete(e),l;case w:if(Ee)return Ee.call(e)==Ee.call(t)}return!1}(e,t,c,n,o,r,i);if(!(n&b)){var h=l&&W.call(e,"__wrapped__"),d=p&&W.call(t,"__wrapped__");if(h||d){var g=h?e.value():e,y=d?t.value():t;return i||(i=new Oe),r(g,y,n,o,i)}}return!!f&&(i||(i=new Oe),function(e,t,n,o,r,i){var s=n&b,a=je(e),c=a.length,u=je(t).length;if(c!=u&&!s)return!1;for(var l=c;l--;){var p=a[l];if(!(s?p in t:W.call(t,p)))return!1}var f=i.get(e);if(f&&i.get(t))return f==t;var h=!0;i.set(e,t),i.set(t,e);for(var d=s;++l<c;){p=a[l];var g=e[p],y=t[p];if(o)var m=s?o(y,g,p,t,e,i):o(g,y,p,e,t,i);if(!(void 0===m?g===y||r(g,y,n,o,i):m)){h=!1;break}d||(d="constructor"==p)}if(h&&!d){var _=e.constructor,v=t.constructor;_!=v&&"constructor"in e&&"constructor"in t&&!("function"==typeof _&&_ instanceof _&&"function"==typeof v&&v instanceof v)&&(h=!1)}return i.delete(e),i.delete(t),h}(e,t,n,o,r,i))}(e,t,n,o,Ne,r))}function Ae(e){return!(!Xe(e)||(t=e,H&&H in t))&&(qe(e)?Q:f).test(Ge(e));var t}function Pe(e){if(n=(t=e)&&t.constructor,o="function"==typeof n&&n.prototype||Y,t!==o)return ce(e);var t,n,o,r=[];for(var i in Object(e))W.call(e,i)&&"constructor"!=i&&r.push(i);return r}function Fe(e,t,o,r,i,s){var n=o&b,a=e.length,c=t.length;if(a!=c&&!(n&&a<c))return!1;var u=s.get(e);if(u&&s.get(t))return u==t;var l=-1,p=!0,f=o&m?new Ce:void 0;for(s.set(e,t),s.set(t,e);++l<a;){var h=e[l],d=t[l];if(r)var g=n?r(d,h,l,t,e,s):r(h,d,l,e,t,s);if(void 0!==g){if(g)continue;p=!1;break}if(f){if(!U(t,function(e,t){if(n=t,!f.has(n)&&(h===e||i(h,e,o,r,s)))return f.push(t);var n})){p=!1;break}}else if(h!==d&&!i(h,d,o,r,s)){p=!1;break}}return s.delete(e),s.delete(t),p}function je(e){return n=De,o=Ze(t=e),Je(t)?o:function(e,t){for(var n=-1,o=t.length,r=e.length;++n<o;)e[r+n]=t[n];return e}(o,n(t));var t,n,o}function ke(e,t){var n,o,r=e.__data__;return("string"==(o=typeof(n=t))||"number"==o||"symbol"==o||"boolean"==o?"__proto__"!==n:null===n)?r["string"==typeof t?"string":"hash"]:r.map}function Re(e,t){var n,o,r=(o=t,null==(n=e)?void 0:n[o]);return Ae(r)?r:void 0}Te.prototype.clear=function(){this.__data__=de?de(null):{},this.size=0},Te.prototype.delete=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},Te.prototype.get=function(e){var t=this.__data__;if(de){var n=t[e];return n===o?void 0:n}return W.call(t,e)?t[e]:void 0},Te.prototype.has=function(e){var t=this.__data__;return de?void 0!==t[e]:W.call(t,e)},Te.prototype.set=function(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=de&&void 0===t?o:t,this},xe.prototype.clear=function(){this.__data__=[],this.size=0},xe.prototype.delete=function(e){var t=this.__data__,n=Le(t,e);return!(n<0||(n==t.length-1?t.pop():re.call(t,n,1),--this.size,0))},xe.prototype.get=function(e){var t=this.__data__,n=Le(t,e);return n<0?void 0:t[n][1]},xe.prototype.has=function(e){return-1<Le(this.__data__,e)},xe.prototype.set=function(e,t){var n=this.__data__,o=Le(n,e);return o<0?(++this.size,n.push([e,t])):n[o][1]=t,this},Se.prototype.clear=function(){this.size=0,this.__data__={hash:new Te,map:new(le||xe),string:new Te}},Se.prototype.delete=function(e){var t=ke(this,e).delete(e);return this.size-=t?1:0,t},Se.prototype.get=function(e){return ke(this,e).get(e)},Se.prototype.has=function(e){return ke(this,e).has(e)},Se.prototype.set=function(e,t){var n=ke(this,e),o=n.size;return n.set(e,t),this.size+=n.size==o?0:1,this},Ce.prototype.add=Ce.prototype.push=function(e){return this.__data__.set(e,o),this},Ce.prototype.has=function(e){return this.__data__.has(e)},Oe.prototype.clear=function(){this.__data__=new xe,this.size=0},Oe.prototype.delete=function(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n},Oe.prototype.get=function(e){return this.__data__.get(e)},Oe.prototype.has=function(e){return this.__data__.has(e)},Oe.prototype.set=function(e,t){var n=this.__data__;if(n instanceof xe){var o=n.__data__;if(!le||o.length<199)return o.push([e,t]),this.size=++n.size,this;n=this.__data__=new Se(o)}return n.set(e,t),this.size=n.size,this};var De=se?function(t){return null==t?[]:(t=Object(t),function(e,t){for(var n=-1,o=null==e?0:e.length,r=0,i=[];++n<o;){var s=e[n];t(s,n,e)&&(i[r++]=s)}return i}(se(t),function(e){return oe.call(t,e)}))}:function(){return[]},Ue=Me;function Ve(e,t){return!!(t=null==t?n:t)&&("number"==typeof e||h.test(e))&&-1<e&&e%1==0&&e<t}function Ge(e){if(null!=e){try{return K.call(e)}catch(e){}try{return e+""}catch(e){}}return""}function Be(e,t){return e===t||e!=e&&t!=t}(ue&&Ue(new ue(new ArrayBuffer(1)))!=A||le&&Ue(new le)!=S||pe&&Ue(pe.resolve())!=c||fe&&Ue(new fe)!=L||he&&Ue(new he)!=p)&&(Ue=function(e){var t=Me(e),n=t==O?e.constructor:void 0,o=n?Ge(n):"";if(o)switch(o){case ge:return A;case ye:return S;case me:return c;case _e:return L;case ve:return p}return t});var $e=we(function(){return arguments}())?we:function(e){return Ke(e)&&W.call(e,"callee")&&!oe.call(e,"callee")},Je=Array.isArray;var ze=ae||function(){return!1};function qe(e){if(!Xe(e))return!1;var t=Me(e);return t==i||t==s||t==r||t==u}function Ye(e){return"number"==typeof e&&-1<e&&e%1==0&&e<=n}function Xe(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}function Ke(e){return null!=e&&"object"==typeof e}var We,He=D?(We=D,function(e){return We(e)}):function(e){return Ke(e)&&Ye(e.length)&&!!t[Me(e)]};function Ze(e){return null!=(t=e)&&Ye(t.length)&&!qe(t)?Ie(e):Pe(e);var t}Qe.exports=function(e,t){return Ne(e,t)}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],17:[function(e,t,u){(function(r){function i(e,t){for(var n=0,o=e.length-1;0<=o;o--){var r=e[o];"."===r?e.splice(o,1):".."===r?(e.splice(o,1),n++):n&&(e.splice(o,1),n--)}if(t)for(;n--;n)e.unshift("..");return e}function s(e,t){if(e.filter)return e.filter(t);for(var n=[],o=0;o<e.length;o++)t(e[o],o,e)&&n.push(e[o]);return n}u.resolve=function(){for(var e="",t=!1,n=arguments.length-1;-1<=n&&!t;n--){var o=0<=n?arguments[n]:r.cwd();if("string"!=typeof o)throw new TypeError("Arguments to path.resolve must be strings");o&&(e=o+"/"+e,t="/"===o.charAt(0))}return(t?"/":"")+(e=i(s(e.split("/"),function(e){return!!e}),!t).join("/"))||"."},u.normalize=function(e){var t=u.isAbsolute(e),n="/"===o(e,-1);return(e=i(s(e.split("/"),function(e){return!!e}),!t).join("/"))||t||(e="."),e&&n&&(e+="/"),(t?"/":"")+e},u.isAbsolute=function(e){return"/"===e.charAt(0)},u.join=function(){var e=Array.prototype.slice.call(arguments,0);return u.normalize(s(e,function(e,t){if("string"!=typeof e)throw new TypeError("Arguments to path.join must be strings");return e}).join("/"))},u.relative=function(e,t){function n(e){for(var t=0;t<e.length&&""===e[t];t++);for(var n=e.length-1;0<=n&&""===e[n];n--);return n<t?[]:e.slice(t,n-t+1)}e=u.resolve(e).substr(1),t=u.resolve(t).substr(1);for(var o=n(e.split("/")),r=n(t.split("/")),i=Math.min(o.length,r.length),s=i,a=0;a<i;a++)if(o[a]!==r[a]){s=a;break}var c=[];for(a=s;a<o.length;a++)c.push("..");return(c=c.concat(r.slice(s))).join("/")},u.sep="/",u.delimiter=":",u.dirname=function(e){if("string"!=typeof e&&(e+=""),0===e.length)return".";for(var t=e.charCodeAt(0),n=47===t,o=-1,r=!0,i=e.length-1;1<=i;--i)if(47===(t=e.charCodeAt(i))){if(!r){o=i;break}}else r=!1;return-1===o?n?"/":".":n&&1===o?"/":e.slice(0,o)},u.basename=function(e,t){var n=function(e){"string"!=typeof e&&(e+="");var t,n=0,o=-1,r=!0;for(t=e.length-1;0<=t;--t)if(47===e.charCodeAt(t)){if(!r){n=t+1;break}}else-1===o&&(r=!1,o=t+1);return-1===o?"":e.slice(n,o)}(e);return t&&n.substr(-1*t.length)===t&&(n=n.substr(0,n.length-t.length)),n},u.extname=function(e){"string"!=typeof e&&(e+="");for(var t=-1,n=0,o=-1,r=!0,i=0,s=e.length-1;0<=s;--s){var a=e.charCodeAt(s);if(47===a){if(r)continue;n=s+1;break}-1===o&&(r=!1,o=s+1),46===a?-1===t?t=s:1!==i&&(i=1):-1!==t&&(i=-1)}return-1===t||-1===o||0===i||1===i&&t===o-1&&t===n+1?"":e.slice(t,o)};var o="b"==="ab".substr(-1)?function(e,t,n){return e.substr(t,n)}:function(e,t,n){return t<0&&(t=e.length+t),e.substr(t,n)}}).call(this,e("_process"))},{_process:18}],18:[function(e,t,n){var o,r,i=t.exports={};function s(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function c(t){if(o===setTimeout)return setTimeout(t,0);if((o===s||!o)&&setTimeout)return o=setTimeout,setTimeout(t,0);try{return o(t,0)}catch(e){try{return o.call(null,t,0)}catch(e){return o.call(this,t,0)}}}!function(){try{o="function"==typeof setTimeout?setTimeout:s}catch(e){o=s}try{r="function"==typeof clearTimeout?clearTimeout:a}catch(e){r=a}}();var u,l=[],p=!1,f=-1;function h(){p&&u&&(p=!1,u.length?l=u.concat(l):f=-1,l.length&&d())}function d(){if(!p){var e=c(h);p=!0;for(var t=l.length;t;){for(u=l,l=[];++f<t;)u&&u[f].run();f=-1,t=l.length}u=null,p=!1,function(t){if(r===clearTimeout)return clearTimeout(t);if((r===a||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(t);try{r(t)}catch(e){try{return r.call(null,t)}catch(e){return r.call(this,t)}}}(e)}}function g(e,t){this.fun=e,this.array=t}function y(){}i.nextTick=function(e){var t=new Array(arguments.length-1);if(1<arguments.length)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];l.push(new g(e,t)),1!==l.length||p||c(d)},g.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=y,i.addListener=y,i.once=y,i.off=y,i.removeListener=y,i.removeAllListeners=y,i.emit=y,i.prependListener=y,i.prependOnceListener=y,i.listeners=function(e){return[]},i.binding=function(e){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(e){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},{}],19:[function(e,t,n){var r=t.exports=function(e){return new i(e)};function i(e){this.value=e}function o(e,c,u){var l=[],p=[],f=!0;return function o(t){var e=u?h(t):t,r={},n=!0,i={node:e,node_:t,path:[].concat(l),parent:p[p.length-1],parents:p,key:l.slice(-1)[0],isRoot:0===l.length,level:l.length,circular:null,update:function(e,t){i.isRoot||(i.parent.node[i.key]=e),i.node=e,t&&(n=!1)},delete:function(e){delete i.parent.node[i.key],e&&(n=!1)},remove:function(e){g(i.parent.node)?i.parent.node.splice(i.key,1):delete i.parent.node[i.key],e&&(n=!1)},keys:null,before:function(e){r.before=e},after:function(e){r.after=e},pre:function(e){r.pre=e},post:function(e){r.post=e},stop:function(){f=!1},block:function(){n=!1}};if(!f)return i;function s(){if("object"==typeof i.node&&null!==i.node){i.keys&&i.node_===i.node||(i.keys=d(i.node)),i.isLeaf=0==i.keys.length;for(var e=0;e<p.length;e++)if(p[e].node_===t){i.circular=p[e];break}}else i.isLeaf=!0,i.keys=null;i.notLeaf=!i.isLeaf,i.notRoot=!i.isRoot}s();var a=c.call(i,i.node);return void 0!==a&&i.update&&i.update(a),r.before&&r.before.call(i,i.node),n&&("object"!=typeof i.node||null===i.node||i.circular||(p.push(i),s(),y(i.keys,function(e,t){l.push(e),r.pre&&r.pre.call(i,i.node[e],e);var n=o(i.node[e]);u&&m.call(i.node,e)&&(i.node[e]=n.node),n.isLast=t==i.keys.length-1,n.isFirst=0==t,r.post&&r.post.call(i,n),l.pop()}),p.pop()),r.after&&r.after.call(i,i.node)),i}(e).node}function h(t){if("object"!=typeof t||null===t)return t;var n;if(g(t))n=[];else if("[object Date]"===s(t))n=new Date(t.getTime?t.getTime():t);else if("[object RegExp]"===s(t))n=new RegExp(t);else if("[object Error]"===s(t))n={message:t.message};else if("[object Boolean]"===s(t))n=new Boolean(t);else if("[object Number]"===s(t))n=new Number(t);else if("[object String]"===s(t))n=new String(t);else if(Object.create&&Object.getPrototypeOf)n=Object.create(Object.getPrototypeOf(t));else if(t.constructor===Object)n={};else{var e=t.constructor&&t.constructor.prototype||t.__proto__||{},o=function(){};o.prototype=e,n=new o}return y(d(t),function(e){n[e]=t[e]}),n}i.prototype.get=function(e){for(var t=this.value,n=0;n<e.length;n++){var o=e[n];if(!t||!m.call(t,o)){t=void 0;break}t=t[o]}return t},i.prototype.has=function(e){for(var t=this.value,n=0;n<e.length;n++){var o=e[n];if(!t||!m.call(t,o))return!1;t=t[o]}return!0},i.prototype.set=function(e,t){for(var n=this.value,o=0;o<e.length-1;o++){var r=e[o];m.call(n,r)||(n[r]={}),n=n[r]}return n[e[o]]=t},i.prototype.map=function(e){return o(this.value,e,!0)},i.prototype.forEach=function(e){return this.value=o(this.value,e,!1),this.value},i.prototype.reduce=function(t,e){var n=1===arguments.length,o=n?this.value:e;return this.forEach(function(e){this.isRoot&&n||(o=t.call(this,o,e))}),o},i.prototype.paths=function(){var t=[];return this.forEach(function(e){t.push(this.path)}),t},i.prototype.nodes=function(){var t=[];return this.forEach(function(e){t.push(this.node)}),t},i.prototype.clone=function(){var r=[],i=[];return function t(n){for(var e=0;e<r.length;e++)if(r[e]===n)return i[e];if("object"!=typeof n||null===n)return n;var o=h(n);return r.push(n),i.push(o),y(d(n),function(e){o[e]=t(n[e])}),r.pop(),i.pop(),o}(this.value)};var d=Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t};function s(e){return Object.prototype.toString.call(e)}var g=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},y=function(e,t){if(e.forEach)return e.forEach(t);for(var n=0;n<e.length;n++)t(e[n],n,e)};y(d(i.prototype),function(o){r[o]=function(e){var t=[].slice.call(arguments,1),n=new i(e);return n[o].apply(n,t)}});var m=Object.hasOwnProperty||function(e,t){return t in e}},{}],20:[function(e,t,n){t.exports.RADIUS=6378137,t.exports.FLATTENING=1/298.257223563,t.exports.POLAR_RADIUS=6356752.3142},{}],21:[function(e,t,n){t.exports=function(){for(var e={},t=0;t<arguments.length;t++){var n=arguments[t];for(var o in n)r.call(n,o)&&(e[o]=n[o])}return e};var r=Object.prototype.hasOwnProperty},{}],22:[function(e,t,n){"use strict";var r=e("lodash.isequal"),o=e("@mapbox/geojson-normalize"),a=e("hat"),c=e("./lib/features_at"),u=e("./lib/string_sets_are_equal"),l=e("@mapbox/geojsonhint"),p=e("./constants"),f=e("./lib/string_set"),h={Polygon:e("./feature_types/polygon"),LineString:e("./feature_types/line_string"),Point:e("./feature_types/point"),MultiPolygon:e("./feature_types/multi_feature"),MultiLineString:e("./feature_types/multi_feature"),MultiPoint:e("./feature_types/multi_feature")};t.exports=function(i,s){return s.modes=p.modes,s.getFeatureIdsAt=function(e){return c.click({point:e},null,i).map(function(e){return e.properties.id})},s.getSelectedIds=function(){return i.store.getSelectedIds()},s.getSelected=function(){return{type:p.geojsonTypes.FEATURE_COLLECTION,features:i.store.getSelectedIds().map(function(e){return i.store.get(e)}).map(function(e){return e.toGeoJSON()})}},s.getSelectedPoints=function(){return{type:p.geojsonTypes.FEATURE_COLLECTION,features:i.store.getSelectedCoordinates().map(function(e){return{type:p.geojsonTypes.FEATURE,properties:{},geometry:{type:p.geojsonTypes.POINT,coordinates:e.coordinates}}})}},s.set=function(e){if(void 0===e.type||e.type!==p.geojsonTypes.FEATURE_COLLECTION||!Array.isArray(e.features))throw new Error("Invalid FeatureCollection");var t=i.store.createRenderBatch(),n=i.store.getAllIds().slice(),o=s.add(e),r=new f(o);return(n=n.filter(function(e){return!r.has(e)})).length&&s.delete(n),t(),o},s.add=function(e){var t=l.hint(e,{precisionWarning:!1}).filter(function(e){return"message"!==e.level});if(t.length)throw new Error(t[0].message);var n=JSON.parse(JSON.stringify(o(e))).features.map(function(e){if(e.id=e.id||a(),null===e.geometry)throw new Error("Invalid geometry: null");if(void 0===i.store.get(e.id)||i.store.get(e.id).type!==e.geometry.type){var t=h[e.geometry.type];if(void 0===t)throw new Error("Invalid geometry type: ".concat(e.geometry.type,"."));var n=new t(i,e);i.store.add(n)}else{var o=i.store.get(e.id);o.properties=e.properties,r(o.getCoordinates(),e.geometry.coordinates)||o.incomingCoords(e.geometry.coordinates)}return e.id});return i.store.render(),n},s.get=function(e){var t=i.store.get(e);if(t)return t.toGeoJSON()},s.getAll=function(){return{type:p.geojsonTypes.FEATURE_COLLECTION,features:i.store.getAll().map(function(e){return e.toGeoJSON()})}},s.delete=function(e){return i.store.delete(e,{silent:!0}),s.getMode()!==p.modes.DIRECT_SELECT||i.store.getSelectedIds().length?i.store.render():i.events.changeMode(p.modes.SIMPLE_SELECT,void 0,{silent:!0}),s},s.deleteAll=function(){return i.store.delete(i.store.getAllIds(),{silent:!0}),s.getMode()===p.modes.DIRECT_SELECT?i.events.changeMode(p.modes.SIMPLE_SELECT,void 0,{silent:!0}):i.store.render(),s},s.changeMode=function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return e===p.modes.SIMPLE_SELECT&&s.getMode()===p.modes.SIMPLE_SELECT?u(t.featureIds||[],i.store.getSelectedIds())||(i.store.setSelected(t.featureIds,{silent:!0}),i.store.render()):e===p.modes.DIRECT_SELECT&&s.getMode()===p.modes.DIRECT_SELECT&&t.featureId===i.store.getSelectedIds()[0]||i.events.changeMode(e,t,{silent:!0}),s},s.getMode=function(){return i.events.getMode()},s.trash=function(){return i.events.trash({silent:!0}),s},s.combineFeatures=function(){return i.events.combineFeatures({silent:!0}),s},s.uncombineFeatures=function(){return i.events.uncombineFeatures({silent:!0}),s},s.setFeatureProperty=function(e,t,n){return i.store.setFeatureProperty(e,t,n),s},s}},{"./constants":23,"./feature_types/line_string":26,"./feature_types/multi_feature":27,"./feature_types/point":28,"./feature_types/polygon":29,"./lib/features_at":37,"./lib/string_set":47,"./lib/string_sets_are_equal":48,"@mapbox/geojson-normalize":7,"@mapbox/geojsonhint":8,hat:14,"lodash.isequal":16}],23:[function(e,t,n){"use strict";t.exports={classes:{CONTROL_BASE:"mapboxgl-ctrl",CONTROL_PREFIX:"mapboxgl-ctrl-",CONTROL_BUTTON:"mapbox-gl-draw_ctrl-draw-btn",CONTROL_BUTTON_LINE:"mapbox-gl-draw_line",CONTROL_BUTTON_POLYGON:"mapbox-gl-draw_polygon",CONTROL_BUTTON_POINT:"mapbox-gl-draw_point",CONTROL_BUTTON_TRASH:"mapbox-gl-draw_trash",CONTROL_BUTTON_COMBINE_FEATURES:"mapbox-gl-draw_combine",CONTROL_BUTTON_UNCOMBINE_FEATURES:"mapbox-gl-draw_uncombine",CONTROL_GROUP:"mapboxgl-ctrl-group",ATTRIBUTION:"mapboxgl-ctrl-attrib",ACTIVE_BUTTON:"active",BOX_SELECT:"mapbox-gl-draw_boxselect"},sources:{HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},cursors:{ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},types:{POLYGON:"polygon",LINE:"line_string",POINT:"point"},geojsonTypes:{FEATURE:"Feature",POLYGON:"Polygon",LINE_STRING:"LineString",POINT:"Point",FEATURE_COLLECTION:"FeatureCollection",MULTI_PREFIX:"Multi",MULTI_POINT:"MultiPoint",MULTI_LINE_STRING:"MultiLineString",MULTI_POLYGON:"MultiPolygon"},modes:{DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select",STATIC:"static"},events:{CREATE:"draw.create",DELETE:"draw.delete",UPDATE:"draw.update",SELECTION_CHANGE:"draw.selectionchange",MODE_CHANGE:"draw.modechange",ACTIONABLE:"draw.actionable",RENDER:"draw.render",COMBINE_FEATURES:"draw.combine",UNCOMBINE_FEATURES:"draw.uncombine"},updateActions:{MOVE:"move",CHANGE_COORDINATES:"change_coordinates"},meta:{FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},activeStates:{ACTIVE:"true",INACTIVE:"false"},interactions:["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"],LAT_MIN:-90,LAT_RENDERED_MIN:-85,LAT_MAX:90,LAT_RENDERED_MAX:85,LNG_MIN:-270,LNG_MAX:270}},{}],24:[function(e,t,n){"use strict";var p=e("./lib/mode_handler"),f=e("./lib/get_features_and_set_cursor"),h=e("./lib/features_at"),d=e("./lib/is_click"),g=e("./lib/is_tap"),y=e("./constants"),m=e("./modes/object_to_mode");t.exports=function(i){var s=Object.keys(i.options.modes).reduce(function(e,t){return e[t]=m(i.options.modes[t]),e},{}),n={},o={},r={},a=null,c=null;r.drag=function(e,t){t({point:e.point,time:(new Date).getTime()})?(i.ui.queueMapClasses({mouse:y.cursors.DRAG}),c.drag(e)):e.originalEvent.stopPropagation()},r.mousedrag=function(e){r.drag(e,function(e){return!d(n,e)})},r.touchdrag=function(e){r.drag(e,function(e){return!g(o,e)})},r.mousemove=function(e){if(1===(void 0!==e.originalEvent.buttons?e.originalEvent.buttons:e.originalEvent.which))return r.mousedrag(e);var t=f(e,i);e.featureTarget=t,c.mousemove(e)},r.mousedown=function(e){n={time:(new Date).getTime(),point:e.point};var t=f(e,i);e.featureTarget=t,c.mousedown(e)},r.mouseup=function(e){var t=f(e,i);e.featureTarget=t,d(n,{point:e.point,time:(new Date).getTime()})?c.click(e):c.mouseup(e)},r.mouseout=function(e){c.mouseout(e)},r.touchstart=function(e){if(i.options.touchEnabled){o={time:(new Date).getTime(),point:e.point};var t=h.touch(e,null,i)[0];t&&(e.originalEvent.preventDefault(),e.featureTarget=t,c.touchstart(e))}},r.touchmove=function(e){if(e.originalEvent.preventDefault(),i.options.touchEnabled)return c.touchmove(e),r.touchdrag(e)},r.touchend=function(e){if(i.options.touchEnabled){var t=h.touch(e,null,i)[0];t&&(e.originalEvent.preventDefault(),e.featureTarget=t,g(o,{time:(new Date).getTime(),point:e.point})?c.tap(e):c.touchend(e))}};var t=function(e){return!(8===e||46===e||48<=e&&e<=57)};function u(e,t){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};c.stop();var o=s[e];if(void 0===o)throw new Error("".concat(e," is not valid"));a=e;var r=o(i,t);c=p(r,i),n.silent||i.map.fire(y.events.MODE_CHANGE,{mode:e}),i.store.setDirty(),i.store.render()}r.keydown=function(e){"mapboxgl-canvas"===(e.srcElement||e.target).classList[0]&&(8!==e.keyCode&&46!==e.keyCode||!i.options.controls.trash?t(e.keyCode)?c.keydown(e):49===e.keyCode&&i.options.controls.point?u(y.modes.DRAW_POINT):50===e.keyCode&&i.options.controls.line_string?u(y.modes.DRAW_LINE_STRING):51===e.keyCode&&i.options.controls.polygon&&u(y.modes.DRAW_POLYGON):(e.preventDefault(),c.trash()))},r.keyup=function(e){t(e.keyCode)&&c.keyup(e)},r.zoomend=function(){i.store.changeZoom()};var l={trash:!(r.data=function(e){if("style"===e.dataType){var t=i.setup,n=i.map,o=i.options,r=i.store;o.styles.some(function(e){return n.getLayer(e.id)})||(t.addLayers(),r.setDirty(),r.render())}}),combineFeatures:!1,uncombineFeatures:!1};return{start:function(){a=i.options.defaultMode,c=p(s[a](i),i)},changeMode:u,actionable:function(t){var n=!1;Object.keys(t).forEach(function(e){if(void 0===l[e])throw new Error("Invalid action type");l[e]!==t[e]&&(n=!0),l[e]=t[e]}),n&&i.map.fire(y.events.ACTIONABLE,{actions:l})},currentModeName:function(){return a},currentModeRender:function(e,t){return c.render(e,t)},fire:function(e,t){r[e]&&r[e](t)},addEventListeners:function(){i.map.on("mousemove",r.mousemove),i.map.on("mousedown",r.mousedown),i.map.on("mouseup",r.mouseup),i.map.on("data",r.data),i.map.on("touchmove",r.touchmove),i.map.on("touchstart",r.touchstart),i.map.on("touchend",r.touchend),i.container.addEventListener("mouseout",r.mouseout),i.options.keybindings&&(i.container.addEventListener("keydown",r.keydown),i.container.addEventListener("keyup",r.keyup))},removeEventListeners:function(){i.map.off("mousemove",r.mousemove),i.map.off("mousedown",r.mousedown),i.map.off("mouseup",r.mouseup),i.map.off("data",r.data),i.map.off("touchmove",r.touchmove),i.map.off("touchstart",r.touchstart),i.map.off("touchend",r.touchend),i.container.removeEventListener("mouseout",r.mouseout),i.options.keybindings&&(i.container.removeEventListener("keydown",r.keydown),i.container.removeEventListener("keyup",r.keyup))},trash:function(e){c.trash(e)},combineFeatures:function(){c.combineFeatures()},uncombineFeatures:function(){c.uncombineFeatures()},getMode:function(){return a}}}},{"./constants":23,"./lib/features_at":37,"./lib/get_features_and_set_cursor":38,"./lib/is_click":39,"./lib/is_tap":41,"./lib/mode_handler":43,"./modes/object_to_mode":59}],25:[function(e,t,n){"use strict";var o=e("hat"),r=e("../constants"),i=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||o(),this.type=t.geometry.type};i.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},i.prototype.incomingCoords=function(e){this.setCoordinates(e)},i.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},i.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},i.prototype.setProperty=function(e,t){this.properties[e]=t},i.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:r.geojsonTypes.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},i.prototype.internal=function(e){var t={id:this.id,meta:r.meta.FEATURE,"meta:type":this.type,active:r.activeStates.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(var n in this.properties)t["user_".concat(n)]=this.properties[n];return{type:r.geojsonTypes.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}},t.exports=i},{"../constants":23,hat:14}],26:[function(e,t,n){"use strict";var o=e("./feature"),r=function(e,t){o.call(this,e,t)};(r.prototype=Object.create(o.prototype)).isValid=function(){return 1<this.coordinates.length},r.prototype.addCoordinate=function(e,t,n){this.changed();var o=parseInt(e,10);this.coordinates.splice(o,0,[t,n])},r.prototype.getCoordinate=function(e){var t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},r.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},r.prototype.updateCoordinate=function(e,t,n){var o=parseInt(e,10);this.coordinates[o]=[t,n],this.changed()},t.exports=r},{"./feature":25}],27:[function(e,t,n){"use strict";var o=e("./feature"),r=e("../constants"),i=e("hat"),s={MultiPoint:e("./point"),MultiLineString:e("./line_string"),MultiPolygon:e("./polygon")},a=function(e,t,n,o,r){var i=n.split("."),s=parseInt(i[0],10),a=i[1]?i.slice(1).join("."):null;return e[s][t](a,o,r)},c=function(e,t){if(o.call(this,e,t),delete this.coordinates,this.model=s[t.geometry.type],void 0===this.model)throw new TypeError("".concat(t.geometry.type," is not a valid type"));this.features=this._coordinatesToFeatures(t.geometry.coordinates)};(c.prototype=Object.create(o.prototype))._coordinatesToFeatures=function(e){var t=this,n=this.model.bind(this);return e.map(function(e){return new n(t.ctx,{id:i(),type:r.geojsonTypes.FEATURE,properties:{},geometry:{coordinates:e,type:t.type.replace("Multi","")}})})},c.prototype.isValid=function(){return this.features.every(function(e){return e.isValid()})},c.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},c.prototype.getCoordinate=function(e){return a(this.features,"getCoordinate",e)},c.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(function(e){return e.type===r.geojsonTypes.POLYGON?e.getCoordinates():e.coordinates})))},c.prototype.updateCoordinate=function(e,t,n){a(this.features,"updateCoordinate",e,t,n),this.changed()},c.prototype.addCoordinate=function(e,t,n){a(this.features,"addCoordinate",e,t,n),this.changed()},c.prototype.removeCoordinate=function(e){a(this.features,"removeCoordinate",e),this.changed()},c.prototype.getFeatures=function(){return this.features},t.exports=c},{"../constants":23,"./feature":25,"./line_string":26,"./point":28,"./polygon":29,hat:14}],28:[function(e,t,n){"use strict";var o=e("./feature"),r=function(e,t){o.call(this,e,t)};(r.prototype=Object.create(o.prototype)).isValid=function(){return"number"==typeof this.coordinates[0]&&"number"==typeof this.coordinates[1]},r.prototype.updateCoordinate=function(e,t,n){3===arguments.length?this.coordinates=[t,n]:this.coordinates=[e,t],this.changed()},r.prototype.getCoordinate=function(){return this.getCoordinates()},t.exports=r},{"./feature":25}],29:[function(e,t,n){"use strict";var o=e("./feature"),r=function(e,t){o.call(this,e,t),this.coordinates=this.coordinates.map(function(e){return e.slice(0,-1)})};(r.prototype=Object.create(o.prototype)).isValid=function(){return 0!==this.coordinates.length&&this.coordinates.every(function(e){return 2<e.length})},r.prototype.incomingCoords=function(e){this.coordinates=e.map(function(e){return e.slice(0,-1)}),this.changed()},r.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},r.prototype.addCoordinate=function(e,t,n){this.changed();var o=e.split(".").map(function(e){return parseInt(e,10)});this.coordinates[o[0]].splice(o[1],0,[t,n])},r.prototype.removeCoordinate=function(e){this.changed();var t=e.split(".").map(function(e){return parseInt(e,10)}),n=this.coordinates[t[0]];n&&(n.splice(t[1],1),n.length<3&&this.coordinates.splice(t[0],1))},r.prototype.getCoordinate=function(e){var t=e.split(".").map(function(e){return parseInt(e,10)}),n=this.coordinates[t[0]];return JSON.parse(JSON.stringify(n[t[1]]))},r.prototype.getCoordinates=function(){return this.coordinates.map(function(e){return e.concat([e[0]])})},r.prototype.updateCoordinate=function(e,t,n){this.changed();var o=e.split("."),r=parseInt(o[0],10),i=parseInt(o[1],10);void 0===this.coordinates[r]&&(this.coordinates[r]=[]),this.coordinates[r][i]=[t,n]},t.exports=r},{"./feature":25}],30:[function(e,t,n){"use strict";var o=e("../constants");t.exports={isOfMetaType:function(n){return function(e){var t=e.featureTarget;return!!t&&(!!t.properties&&t.properties.meta===n)}},isShiftMousedown:function(e){return!!e.originalEvent&&(!!e.originalEvent.shiftKey&&0===e.originalEvent.button)},isActiveFeature:function(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===o.activeStates.ACTIVE&&e.featureTarget.properties.meta===o.meta.FEATURE))},isInactiveFeature:function(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&(e.featureTarget.properties.active===o.activeStates.INACTIVE&&e.featureTarget.properties.meta===o.meta.FEATURE))},noTarget:function(e){return void 0===e.featureTarget},isFeature:function(e){return!!e.featureTarget&&(!!e.featureTarget.properties&&e.featureTarget.properties.meta===o.meta.FEATURE)},isVertex:function(e){var t=e.featureTarget;return!!t&&(!!t.properties&&t.properties.meta===o.meta.VERTEX)},isShiftDown:function(e){return!!e.originalEvent&&!0===e.originalEvent.shiftKey},isEscapeKey:function(e){return 27===e.keyCode},isEnterKey:function(e){return 13===e.keyCode},true:function(){return!0}}},{"../constants":23}],31:[function(e,t,n){"use strict";var f=e("@mapbox/geojson-extent"),o=e("../constants"),r=o.LAT_MIN,i=o.LAT_MAX,h=o.LAT_RENDERED_MIN,d=o.LAT_RENDERED_MAX,g=o.LNG_MIN,y=o.LNG_MAX;t.exports=function(e,t){var s=r,a=i,c=r,u=i,l=y,p=g;e.forEach(function(e){var t=f(e),n=t[1],o=t[3],r=t[0],i=t[2];s<n&&(s=n),o<a&&(a=o),c<o&&(c=o),n<u&&(u=n),r<l&&(l=r),p<i&&(p=i)});var n=t;return s+n.lat>d&&(n.lat=d-s),c+n.lat>i&&(n.lat=i-c),a+n.lat<h&&(n.lat=h-a),u+n.lat<r&&(n.lat=r-u),l+n.lng<=g&&(n.lng+=360*Math.ceil(Math.abs(n.lng)/360)),p+n.lng>=y&&(n.lng-=360*Math.ceil(Math.abs(n.lng)/360)),n}},{"../constants":23,"@mapbox/geojson-extent":6}],32:[function(e,t,n){"use strict";var u=e("../constants");t.exports=function(e,t,n,o){var r=t.geometry.coordinates,i=n.geometry.coordinates;if(r[1]>u.LAT_RENDERED_MAX||r[1]<u.LAT_RENDERED_MIN||i[1]>u.LAT_RENDERED_MAX||i[1]<u.LAT_RENDERED_MIN)return null;var s=o.project([r[0],r[1]]),a=o.project([i[0],i[1]]),c=o.unproject([(s.x+a.x)/2,(s.y+a.y)/2]);return{type:u.geojsonTypes.FEATURE,properties:{meta:u.meta.MIDPOINT,parent:e,lng:c.lng,lat:c.lat,coord_path:n.properties.coord_path},geometry:{type:u.geojsonTypes.POINT,coordinates:[c.lng,c.lat]}}}},{"../constants":23}],33:[function(e,t,n){"use strict";var h=e("./create_vertex"),d=e("./create_midpoint"),c=e("../constants");t.exports=function o(r){var i,u=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:null,e=r.geometry,t=e.type,s=e.coordinates,l=r.properties&&r.properties.id,p=[];function a(e,s){var a="",c=null;e.forEach(function(e,t){var n=null!=s?"".concat(s,".").concat(t):String(t),o=h(l,e,n,f(n));if(u.midpoints&&c){var r=d(l,c,o,u.map);r&&p.push(r)}c=o;var i=JSON.stringify(e);a!==i&&p.push(o),0===t&&(a=i)})}function f(e){return!!u.selectedPaths&&-1!==u.selectedPaths.indexOf(e)}return t===c.geojsonTypes.POINT?p.push(h(l,s,n,f(n))):t===c.geojsonTypes.POLYGON?s.forEach(function(e,t){a(e,null!==n?"".concat(n,".").concat(t):String(t))}):t===c.geojsonTypes.LINE_STRING?a(s,n):0===t.indexOf(c.geojsonTypes.MULTI_PREFIX)&&(i=t.replace(c.geojsonTypes.MULTI_PREFIX,""),s.forEach(function(e,t){var n={type:c.geojsonTypes.FEATURE,properties:r.properties,geometry:{type:i,coordinates:e}};p=p.concat(o(n,u,t))})),p}},{"../constants":23,"./create_midpoint":32,"./create_vertex":34}],34:[function(e,t,n){"use strict";var r=e("../constants");t.exports=function(e,t,n,o){return{type:r.geojsonTypes.FEATURE,properties:{meta:r.meta.VERTEX,parent:e,coord_path:n,active:o?r.activeStates.ACTIVE:r.activeStates.INACTIVE},geometry:{type:r.geojsonTypes.POINT,coordinates:t}}}},{"../constants":23}],35:[function(e,t,n){"use strict";t.exports={enable:function(e){setTimeout(function(){e.map&&e.map.doubleClickZoom&&e._ctx&&e._ctx.store&&e._ctx.store.getInitialConfigValue&&e._ctx.store.getInitialConfigValue("doubleClickZoom")&&e.map.doubleClickZoom.enable()},0)},disable:function(e){setTimeout(function(){e.map&&e.map.doubleClickZoom&&e.map.doubleClickZoom.disable()},0)}}},{}],36:[function(e,t,n){"use strict";t.exports=function(e,t){var n=e.x-t.x,o=e.y-t.y;return Math.sqrt(n*n+o*o)}},{}],37:[function(e,t,n){"use strict";var u=e("./sort_features"),l=e("./map_event_to_bounding_box"),o=e("../constants"),p=e("./string_set"),f=[o.meta.FEATURE,o.meta.MIDPOINT,o.meta.VERTEX];function r(e,t,n,o){if(null===n.map)return[];var r=e?l(e,o):t,i={};n.options.styles&&(i.layers=n.options.styles.map(function(e){return e.id}));var s=n.map.queryRenderedFeatures(r,i).filter(function(e){return-1!==f.indexOf(e.properties.meta)}),a=new p,c=[];return s.forEach(function(e){var t=e.properties.id;a.has(t)||(a.add(t),c.push(e))}),u(c)}t.exports={click:function(e,t,n){return r(e,t,n,n.options.clickBuffer)},touch:function(e,t,n){return r(e,t,n,n.options.touchBuffer)}}},{"../constants":23,"./map_event_to_bounding_box":42,"./sort_features":46,"./string_set":47}],38:[function(e,t,n){"use strict";var r=e("./features_at"),i=e("../constants");t.exports=function(e,t){var n=r.click(e,null,t),o={mouse:i.cursors.NONE};return n[0]&&(o.mouse=n[0].properties.active===i.activeStates.ACTIVE?i.cursors.MOVE:i.cursors.POINTER,o.feature=n[0].properties.meta),-1!==t.events.currentModeName().indexOf("draw")&&(o.mouse=i.cursors.ADD),t.ui.queueMapClasses(o),t.ui.updateMapClasses(),n[0]}},{"../constants":23,"./features_at":37}],39:[function(e,t,n){"use strict";var a=e("./euclidean_distance");t.exports=function(e,t){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},o=null!=n.fineTolerance?n.fineTolerance:4,r=null!=n.grossTolerance?n.grossTolerance:12,i=null!=n.interval?n.interval:500;e.point=e.point||t.point,e.time=e.time||t.time;var s=a(e.point,t.point);return s<o||s<r&&t.time-e.time<i}},{"./euclidean_distance":36}],40:[function(e,t,n){"use strict";t.exports=function(e,t){return!!e.lngLat&&e.lngLat.lng===t[0]&&e.lngLat.lat===t[1]}},{}],41:[function(e,t,n){"use strict";var i=e("./euclidean_distance");t.exports=function(e,t){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},o=null!=n.tolerance?n.tolerance:25,r=null!=n.interval?n.interval:250;return e.point=e.point||t.point,e.time=e.time||t.time,i(e.point,t.point)<o&&t.time-e.time<r}},{"./euclidean_distance":36}],42:[function(e,t,n){"use strict";t.exports=function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0;return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}},{}],43:[function(e,t,n){"use strict";t.exports=function(e,i){var s={drag:[],click:[],mousemove:[],mousedown:[],mouseup:[],mouseout:[],keydown:[],keyup:[],touchstart:[],touchmove:[],touchend:[],tap:[]},a={on:function(e,t,n){if(void 0===s[e])throw new Error("Invalid event type: ".concat(e));s[e].push({selector:t,fn:n})},render:function(e){i.store.featureChanged(e)}},t=function(e,t){for(var n=s[e],o=n.length;o--;){var r=n[o];if(r.selector(t)){r.fn.call(a,t),i.store.render(),i.ui.updateMapClasses();break}}};return e.start.call(a),{render:e.render,stop:function(){e.stop&&e.stop()},trash:function(){e.trash&&(e.trash(),i.store.render())},combineFeatures:function(){e.combineFeatures&&e.combineFeatures()},uncombineFeatures:function(){e.uncombineFeatures&&e.uncombineFeatures()},drag:function(e){t("drag",e)},click:function(e){t("click",e)},mousemove:function(e){t("mousemove",e)},mousedown:function(e){t("mousedown",e)},mouseup:function(e){t("mouseup",e)},mouseout:function(e){t("mouseout",e)},keydown:function(e){t("keydown",e)},keyup:function(e){t("keyup",e)},touchstart:function(e){t("touchstart",e)},touchmove:function(e){t("touchmove",e)},touchend:function(e){t("touchend",e)},tap:function(e){t("tap",e)}}}},{}],44:[function(e,t,n){"use strict";var o=e("@mapbox/point-geometry");t.exports=function(e,t){var n=t.getBoundingClientRect();return new o(e.clientX-n.left-(t.clientLeft||0),e.clientY-n.top-(t.clientTop||0))}},{"@mapbox/point-geometry":11}],45:[function(e,t,n){"use strict";var o=e("./constrain_feature_movement"),s=e("../constants");t.exports=function(e,t){var i=o(e.map(function(e){return e.toGeoJSON()}),t);e.forEach(function(e){var t,n=e.getCoordinates(),o=function(e){var t={lng:e[0]+i.lng,lat:e[1]+i.lat};return[t.lng,t.lat]},r=function(e){return e.map(function(e){return o(e)})};e.type===s.geojsonTypes.POINT?t=o(n):e.type===s.geojsonTypes.LINE_STRING||e.type===s.geojsonTypes.MULTI_POINT?t=n.map(o):e.type===s.geojsonTypes.POLYGON||e.type===s.geojsonTypes.MULTI_LINE_STRING?t=n.map(r):e.type===s.geojsonTypes.MULTI_POLYGON&&(t=n.map(function(e){return e.map(function(e){return r(e)})})),e.incomingCoords(t)})}},{"../constants":23,"./constrain_feature_movement":31}],46:[function(e,t,n){"use strict";var o=e("@mapbox/geojson-area"),r=e("../constants"),i={Point:0,LineString:1,Polygon:2};function s(e,t){var n=i[e.geometry.type]-i[t.geometry.type];return 0===n&&e.geometry.type===r.geojsonTypes.POLYGON?e.area-t.area:n}t.exports=function(e){return e.map(function(e){return e.geometry.type===r.geojsonTypes.POLYGON&&(e.area=o.geometry({type:r.geojsonTypes.FEATURE,property:{},geometry:e.geometry})),e}).sort(s).map(function(e){return delete e.area,e})}},{"../constants":23,"@mapbox/geojson-area":3}],47:[function(e,t,n){"use strict";function o(e){if(this._items={},this._nums={},this._length=e?e.length:0,e)for(var t=0,n=e.length;t<n;t++)this.add(e[t]),void 0!==e[t]&&("string"==typeof e[t]?this._items[e[t]]=t:this._nums[e[t]]=t)}o.prototype.add=function(e){return this.has(e)||(this._length++,"string"==typeof e?this._items[e]=this._length:this._nums[e]=this._length),this},o.prototype.delete=function(e){return!1===this.has(e)||(this._length--,delete this._items[e],delete this._nums[e]),this},o.prototype.has=function(e){return("string"==typeof e||"number"==typeof e)&&(void 0!==this._items[e]||void 0!==this._nums[e])},o.prototype.values=function(){var t=this,n=[];return Object.keys(this._items).forEach(function(e){n.push({k:e,v:t._items[e]})}),Object.keys(this._nums).forEach(function(e){n.push({k:JSON.parse(e),v:t._nums[e]})}),n.sort(function(e,t){return e.v-t.v}).map(function(e){return e.k})},o.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this},t.exports=o},{}],48:[function(e,t,n){"use strict";t.exports=function(e,t){return e.length===t.length&&JSON.stringify(e.map(function(e){return e}).sort())===JSON.stringify(t.map(function(e){return e}).sort())}},{}],49:[function(e,t,n){"use strict";t.exports=[{id:"gl-draw-polygon-fill-inactive",type:"fill",filter:["all",["==","active","false"],["==","$type","Polygon"],["!=","mode","static"]],paint:{"fill-color":"#3bb2d0","fill-outline-color":"#3bb2d0","fill-opacity":.1}},{id:"gl-draw-polygon-fill-active",type:"fill",filter:["all",["==","active","true"],["==","$type","Polygon"]],paint:{"fill-color":"#fbb03b","fill-outline-color":"#fbb03b","fill-opacity":.1}},{id:"gl-draw-polygon-midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":"#fbb03b"}},{id:"gl-draw-polygon-stroke-inactive",type:"line",filter:["all",["==","active","false"],["==","$type","Polygon"],["!=","mode","static"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":"#3bb2d0","line-width":2}},{id:"gl-draw-polygon-stroke-active",type:"line",filter:["all",["==","active","true"],["==","$type","Polygon"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":"#fbb03b","line-dasharray":[.2,2],"line-width":2}},{id:"gl-draw-line-inactive",type:"line",filter:["all",["==","active","false"],["==","$type","LineString"],["!=","mode","static"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":"#3bb2d0","line-width":2}},{id:"gl-draw-line-active",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":"#fbb03b","line-dasharray":[.2,2],"line-width":2}},{id:"gl-draw-polygon-and-line-vertex-stroke-inactive",type:"circle",filter:["all",["==","meta","vertex"],["==","$type","Point"],["!=","mode","static"]],paint:{"circle-radius":5,"circle-color":"#fff"}},{id:"gl-draw-polygon-and-line-vertex-inactive",type:"circle",filter:["all",["==","meta","vertex"],["==","$type","Point"],["!=","mode","static"]],paint:{"circle-radius":3,"circle-color":"#fbb03b"}},{id:"gl-draw-point-point-stroke-inactive",type:"circle",filter:["all",["==","active","false"],["==","$type","Point"],["==","meta","feature"],["!=","mode","static"]],paint:{"circle-radius":5,"circle-opacity":1,"circle-color":"#fff"}},{id:"gl-draw-point-inactive",type:"circle",filter:["all",["==","active","false"],["==","$type","Point"],["==","meta","feature"],["!=","mode","static"]],paint:{"circle-radius":3,"circle-color":"#3bb2d0"}},{id:"gl-draw-point-stroke-active",type:"circle",filter:["all",["==","$type","Point"],["==","active","true"],["!=","meta","midpoint"]],paint:{"circle-radius":7,"circle-color":"#fff"}},{id:"gl-draw-point-active",type:"circle",filter:["all",["==","$type","Point"],["!=","meta","midpoint"],["==","active","true"]],paint:{"circle-radius":5,"circle-color":"#fbb03b"}},{id:"gl-draw-polygon-fill-static",type:"fill",filter:["all",["==","mode","static"],["==","$type","Polygon"]],paint:{"fill-color":"#404040","fill-outline-color":"#404040","fill-opacity":.1}},{id:"gl-draw-polygon-stroke-static",type:"line",filter:["all",["==","mode","static"],["==","$type","Polygon"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":"#404040","line-width":2}},{id:"gl-draw-line-static",type:"line",filter:["all",["==","mode","static"],["==","$type","LineString"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":"#404040","line-width":2}},{id:"gl-draw-point-static",type:"circle",filter:["all",["==","mode","static"],["==","$type","Point"]],paint:{"circle-radius":5,"circle-color":"#404040"}}]},{}],50:[function(e,t,n){"use strict";t.exports=function(e,t,n){var o,r;function i(){o=!1,r&&(s.apply(n,r),r=!1)}function s(){o?r=arguments:(o=!0,e.apply(n,arguments),setTimeout(i,t))}return s}},{}],51:[function(e,t,n){"use strict";t.exports=function(e){return[].concat(e).filter(function(e){return void 0!==e})}},{}],52:[function(e,t,n){"use strict";var o=e("../lib/common_selectors"),r=o.noTarget,i=o.isOfMetaType,s=o.isInactiveFeature,a=o.isShiftDown,c=e("../lib/create_supplementary_points"),u=e("../lib/constrain_feature_movement"),l=e("../lib/double_click_zoom"),p=e("../constants"),f=e("../lib/common_selectors"),h=e("../lib/move_features"),d=i(p.meta.VERTEX),g=i(p.meta.MIDPOINT),y={fireUpdate:function(){this.map.fire(p.events.UPDATE,{action:p.updateActions.CHANGE_COORDINATES,features:this.getSelected().map(function(e){return e.toGeoJSON()})})},fireActionable:function(e){this.setActionableState({combineFeatures:!1,uncombineFeatures:!1,trash:0<e.selectedCoordPaths.length})},startDragging:function(e,t){this.map.dragPan.disable(),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},stopDragging:function(e){this.map.dragPan.enable(),e.dragMoving=!1,e.canDragMove=!1,e.dragMoveLocation=null},onVertex:function(e,t){this.startDragging(e,t);var n=t.featureTarget.properties,o=e.selectedCoordPaths.indexOf(n.coord_path);a(t)||-1!==o?a(t)&&-1===o&&e.selectedCoordPaths.push(n.coord_path):e.selectedCoordPaths=[n.coord_path];var r=this.pathsToCoordinates(e.featureId,e.selectedCoordPaths);this.setSelectedCoordinates(r)},onMidpoint:function(e,t){this.startDragging(e,t);var n=t.featureTarget.properties;e.feature.addCoordinate(n.coord_path,n.lng,n.lat),this.fireUpdate(),e.selectedCoordPaths=[n.coord_path]},pathsToCoordinates:function(t,e){return e.map(function(e){return{feature_id:t,coord_path:e}})},onFeature:function(e,t){0===e.selectedCoordPaths.length?this.startDragging(e,t):this.stopDragging(e)},dragFeature:function(e,t,n){h(this.getSelected(),n),e.dragMoveLocation=t.lngLat},dragVertex:function(t,e,n){for(var o=t.selectedCoordPaths.map(function(e){return t.feature.getCoordinate(e)}),r=o.map(function(e){return{type:p.geojsonTypes.FEATURE,properties:{},geometry:{type:p.geojsonTypes.POINT,coordinates:e}}}),i=u(r,n),s=0;s<o.length;s++){var a=o[s];t.feature.updateCoordinate(t.selectedCoordPaths[s],a[0]+i.lng,a[1]+i.lat)}},clickNoTarget:function(){this.changeMode(p.modes.SIMPLE_SELECT)},clickInactive:function(){this.changeMode(p.modes.SIMPLE_SELECT)},clickActiveFeature:function(e){e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed()},onSetup:function(e){var t=e.featureId,n=this.getFeature(t);if(!n)throw new Error("You must provide a featureId to enter direct_select mode");if(n.type===p.geojsonTypes.POINT)throw new TypeError("direct_select mode doesn't handle point features");var o={featureId:t,feature:n,dragMoveLocation:e.startPos||null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:e.coordPath?[e.coordPath]:[]};return this.setSelectedCoordinates(this.pathsToCoordinates(t,o.selectedCoordPaths)),this.setSelected(t),l.disable(this),this.setActionableState({trash:!0}),o},onStop:function(){l.enable(this),this.clearSelectedCoordinates()},toDisplayFeatures:function(e,t,n){e.featureId===t.properties.id?(t.properties.active=p.activeStates.ACTIVE,n(t),c(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(n)):(t.properties.active=p.activeStates.INACTIVE,n(t)),this.fireActionable(e)},onTrash:function(t){t.selectedCoordPaths.sort().reverse().forEach(function(e){return t.feature.removeCoordinate(e)}),this.fireUpdate(),t.selectedCoordPaths=[],this.clearSelectedCoordinates(),this.fireActionable(t),!1===t.feature.isValid()&&(this.deleteFeature([t.featureId]),this.changeMode(p.modes.SIMPLE_SELECT,{}))},onMouseMove:function(e,t){var n=f.isActiveFeature(t),o=d(t),r=0===e.selectedCoordPaths.length;n&&r?this.updateUIClasses({mouse:p.cursors.MOVE}):o&&!r?this.updateUIClasses({mouse:p.cursors.MOVE}):this.updateUIClasses({mouse:p.cursors.NONE}),this.stopDragging(e)},onMouseOut:function(e){e.dragMoving&&this.fireUpdate()}};y.onTouchStart=y.onMouseDown=function(e,t){return d(t)?this.onVertex(e,t):f.isActiveFeature(t)?this.onFeature(e,t):g(t)?this.onMidpoint(e,t):void 0},y.onDrag=function(e,t){if(!0===e.canDragMove){e.dragMoving=!0,t.originalEvent.stopPropagation();var n={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};0<e.selectedCoordPaths.length?this.dragVertex(e,t,n):this.dragFeature(e,t,n),e.dragMoveLocation=t.lngLat}},y.onClick=function(e,t){return r(t)?this.clickNoTarget(e,t):f.isActiveFeature(t)?this.clickActiveFeature(e,t):s(t)?this.clickInactive(e,t):void this.stopDragging(e)},y.onTap=function(e,t){return r(t)?this.clickNoTarget(e,t):f.isActiveFeature(t)?this.clickActiveFeature(e,t):s(t)?this.clickInactive(e,t):void 0},y.onTouchEnd=y.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)},t.exports=y},{"../constants":23,"../lib/common_selectors":30,"../lib/constrain_feature_movement":31,"../lib/create_supplementary_points":33,"../lib/double_click_zoom":35,"../lib/move_features":45}],53:[function(e,t,n){"use strict";function u(e){return function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var o=e("../lib/common_selectors"),r=e("../lib/is_event_at_coordinates"),l=e("../lib/double_click_zoom"),p=e("../constants"),i=e("../lib/create_vertex"),s={onSetup:function(e){var t,n,o=(e=e||{}).featureId,r="forward";if(o){if(!(t=this.getFeature(o)))throw new Error("Could not find a feature with the provided featureId");var i=e.from;if(i&&"Feature"===i.type&&i.geometry&&"Point"===i.geometry.type&&(i=i.geometry),i&&"Point"===i.type&&i.coordinates&&2===i.coordinates.length&&(i=i.coordinates),!i||!Array.isArray(i))throw new Error("Please use the `from` property to indicate which point to continue the line from");var s=t.coordinates.length-1;if(t.coordinates[s][0]===i[0]&&t.coordinates[s][1]===i[1]){var a;n=s+1,(a=t).addCoordinate.apply(a,[n].concat(u(t.coordinates[s])))}else{if(t.coordinates[0][0]!==i[0]||t.coordinates[0][1]!==i[1])throw new Error("`from` should match the point at either the start or the end of the provided LineString");var c;r="backwards",n=0,(c=t).addCoordinate.apply(c,[n].concat(u(t.coordinates[0])))}}else t=this.newFeature({type:p.geojsonTypes.FEATURE,properties:{},geometry:{type:p.geojsonTypes.LINE_STRING,coordinates:[]}}),n=0,this.addFeature(t);return this.clearSelectedFeatures(),l.disable(this),this.updateUIClasses({mouse:p.cursors.ADD}),this.activateUIButton(p.types.LINE),this.setActionableState({trash:!0}),{line:t,currentVertexPosition:n,direction:r}},clickAnywhere:function(e,t){if(0<e.currentVertexPosition&&r(t,e.line.coordinates[e.currentVertexPosition-1])||"backwards"===e.direction&&r(t,e.line.coordinates[e.currentVertexPosition+1]))return this.changeMode(p.modes.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:p.cursors.ADD}),e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),"forward"===e.direction?(e.currentVertexPosition++,e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat)):e.line.addCoordinate(0,t.lngLat.lng,t.lngLat.lat)},clickOnVertex:function(e){return this.changeMode(p.modes.SIMPLE_SELECT,{featureIds:[e.line.id]})},onMouseMove:function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),o.isVertex(t)&&this.updateUIClasses({mouse:p.cursors.POINTER})}};s.onTap=s.onClick=function(e,t){if(o.isVertex(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},s.onKeyUp=function(e,t){o.isEnterKey(t)?this.changeMode(p.modes.SIMPLE_SELECT,{featureIds:[e.line.id]}):o.isEscapeKey(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(p.modes.SIMPLE_SELECT))},s.onStop=function(e){l.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.line.id)&&(e.line.removeCoordinate("".concat(e.currentVertexPosition)),e.line.isValid()?this.map.fire(p.events.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(p.modes.SIMPLE_SELECT,{},{silent:!0})))},s.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(p.modes.SIMPLE_SELECT)},s.toDisplayFeatures=function(e,t,n){var o=t.properties.id===e.line.id;if(t.properties.active=o?p.activeStates.ACTIVE:p.activeStates.INACTIVE,!o)return n(t);t.geometry.coordinates.length<2||(t.properties.meta=p.meta.FEATURE,n(i(e.line.id,t.geometry.coordinates["forward"===e.direction?t.geometry.coordinates.length-2:1],"".concat("forward"===e.direction?t.geometry.coordinates.length-2:1),!1)),n(t))},t.exports=s},{"../constants":23,"../lib/common_selectors":30,"../lib/create_vertex":34,"../lib/double_click_zoom":35,"../lib/is_event_at_coordinates":40}],54:[function(e,t,n){"use strict";var o=e("../lib/common_selectors"),r=e("../constants"),i={onSetup:function(){var e=this.newFeature({type:r.geojsonTypes.FEATURE,properties:{},geometry:{type:r.geojsonTypes.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:r.cursors.ADD}),this.activateUIButton(r.types.POINT),this.setActionableState({trash:!0}),{point:e}},stopDrawingAndRemove:function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(r.modes.SIMPLE_SELECT)}};i.onTap=i.onClick=function(e,t){this.updateUIClasses({mouse:r.cursors.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.map.fire(r.events.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(r.modes.SIMPLE_SELECT,{featureIds:[e.point.id]})},i.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},i.toDisplayFeatures=function(e,t,n){var o=t.properties.id===e.point.id;if(t.properties.active=o?r.activeStates.ACTIVE:r.activeStates.INACTIVE,!o)return n(t)},i.onTrash=i.stopDrawingAndRemove,i.onKeyUp=function(e,t){if(o.isEscapeKey(t)||o.isEnterKey(t))return this.stopDrawingAndRemove(e,t)},t.exports=i},{"../constants":23,"../lib/common_selectors":30}],55:[function(e,t,n){"use strict";var o=e("../lib/common_selectors"),r=e("../lib/double_click_zoom"),a=e("../constants"),i=e("../lib/is_event_at_coordinates"),c=e("../lib/create_vertex"),s={onSetup:function(){var e=this.newFeature({type:a.geojsonTypes.FEATURE,properties:{},geometry:{type:a.geojsonTypes.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),r.disable(this),this.updateUIClasses({mouse:a.cursors.ADD}),this.activateUIButton(a.types.POLYGON),this.setActionableState({trash:!0}),{polygon:e,currentVertexPosition:0}},clickAnywhere:function(e,t){if(0<e.currentVertexPosition&&i(t,e.polygon.coordinates[0][e.currentVertexPosition-1]))return this.changeMode(a.modes.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:a.cursors.ADD}),e.polygon.updateCoordinate("0.".concat(e.currentVertexPosition),t.lngLat.lng,t.lngLat.lat),e.currentVertexPosition++,e.polygon.updateCoordinate("0.".concat(e.currentVertexPosition),t.lngLat.lng,t.lngLat.lat)},clickOnVertex:function(e){return this.changeMode(a.modes.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},onMouseMove:function(e,t){e.polygon.updateCoordinate("0.".concat(e.currentVertexPosition),t.lngLat.lng,t.lngLat.lat),o.isVertex(t)&&this.updateUIClasses({mouse:a.cursors.POINTER})}};s.onTap=s.onClick=function(e,t){return o.isVertex(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},s.onKeyUp=function(e,t){o.isEscapeKey(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(a.modes.SIMPLE_SELECT)):o.isEnterKey(t)&&this.changeMode(a.modes.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},s.onStop=function(e){this.updateUIClasses({mouse:a.cursors.NONE}),r.enable(this),this.activateUIButton(),void 0!==this.getFeature(e.polygon.id)&&(e.polygon.removeCoordinate("0.".concat(e.currentVertexPosition)),e.polygon.isValid()?this.map.fire(a.events.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(a.modes.SIMPLE_SELECT,{},{silent:!0})))},s.toDisplayFeatures=function(e,t,n){var o=t.properties.id===e.polygon.id;if(t.properties.active=o?a.activeStates.ACTIVE:a.activeStates.INACTIVE,!o)return n(t);if(0!==t.geometry.coordinates.length){var r=t.geometry.coordinates[0].length;if(!(r<3)){if(t.properties.meta=a.meta.FEATURE,n(c(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),3<r){var i=t.geometry.coordinates[0].length-3;n(c(e.polygon.id,t.geometry.coordinates[0][i],"0.".concat(i),!1))}if(r<=4){var s=[[t.geometry.coordinates[0][0][0],t.geometry.coordinates[0][0][1]],[t.geometry.coordinates[0][1][0],t.geometry.coordinates[0][1][1]]];if(n({type:a.geojsonTypes.FEATURE,properties:t.properties,geometry:{coordinates:s,type:a.geojsonTypes.LINE_STRING}}),3===r)return}return n(t)}}},s.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(a.modes.SIMPLE_SELECT)},t.exports=s},{"../constants":23,"../lib/common_selectors":30,"../lib/create_vertex":34,"../lib/double_click_zoom":35,"../lib/is_event_at_coordinates":40}],56:[function(e,t,n){"use strict";t.exports={simple_select:e("./simple_select"),direct_select:e("./direct_select"),draw_point:e("./draw_point"),draw_polygon:e("./draw_polygon"),draw_line_string:e("./draw_line_string")}},{"./direct_select":52,"./draw_line_string":53,"./draw_point":54,"./draw_polygon":55,"./simple_select":60}],57:[function(e,t,n){"use strict";var o=t.exports=e("./mode_interface_accessors");o.prototype.onSetup=function(){},o.prototype.onDrag=function(){},o.prototype.onClick=function(){},o.prototype.onMouseMove=function(){},o.prototype.onMouseDown=function(){},o.prototype.onMouseUp=function(){},o.prototype.onMouseOut=function(){},o.prototype.onKeyUp=function(){},o.prototype.onKeyDown=function(){},o.prototype.onTouchStart=function(){},o.prototype.onTouchMove=function(){},o.prototype.onTouchEnd=function(){},o.prototype.onTap=function(){},o.prototype.onStop=function(){},o.prototype.onTrash=function(){},o.prototype.onCombineFeature=function(){},o.prototype.onUncombineFeature=function(){},o.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")}},{"./mode_interface_accessors":58}],58:[function(e,t,n){"use strict";var o=e("../constants"),r=e("../lib/features_at"),i=e("../feature_types/point"),s=e("../feature_types/line_string"),a=e("../feature_types/polygon"),c=e("../feature_types/multi_feature"),u=t.exports=function(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e};u.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},u.prototype.setSelectedCoordinates=function(e){var n=this;this._ctx.store.setSelectedCoordinates(e),e.reduce(function(e,t){return void 0===e[t.feature_id]&&(e[t.feature_id]=!0,n._ctx.store.get(t.feature_id).changed()),e},{})},u.prototype.getSelected=function(){return this._ctx.store.getSelected()},u.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},u.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},u.prototype.getFeature=function(e){return this._ctx.store.get(e)},u.prototype.select=function(e){return this._ctx.store.select(e)},u.prototype.deselect=function(e){return this._ctx.store.deselect(e)},u.prototype.deleteFeature=function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return this._ctx.store.delete(e,t)},u.prototype.addFeature=function(e){return this._ctx.store.add(e)},u.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},u.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},u.prototype.setActionableState=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},u.prototype.changeMode=function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return this._ctx.events.changeMode(e,t,n)},u.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},u.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},u.prototype.featuresAt=function(e,t){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"click";if("click"!==n&&"touch"!==n)throw new Error("invalid buffer type");return r[n](e,t,this._ctx)},u.prototype.newFeature=function(e){var t=e.geometry.type;return t===o.geojsonTypes.POINT?new i(this._ctx,e):t===o.geojsonTypes.LINE_STRING?new s(this._ctx,e):t===o.geojsonTypes.POLYGON?new a(this._ctx,e):new c(this._ctx,e)},u.prototype.isInstanceOf=function(e,t){if(e===o.geojsonTypes.POINT)return t instanceof i;if(e===o.geojsonTypes.LINE_STRING)return t instanceof s;if(e===o.geojsonTypes.POLYGON)return t instanceof a;if("MultiFeature"===e)return t instanceof c;throw new Error("Unknown feature class: ".concat(e))},u.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)}},{"../constants":23,"../feature_types/line_string":26,"../feature_types/multi_feature":27,"../feature_types/point":28,"../feature_types/polygon":29,"../lib/features_at":37}],59:[function(e,t,n){"use strict";var o=e("./mode_interface"),c={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},u=Object.keys(c);t.exports=function(a){var n=Object.keys(a);return function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},i={},s=n.reduce(function(e,t){return e[t]=a[t],e},new o(e));return{start:function(){var r=this;i=s.onSetup(t),u.forEach(function(e){var t,n=c[e],o=function(){return!1};a[n]&&(o=function(){return!0}),r.on(e,o,(t=n,function(e){s[t](i,e)}))})},stop:function(){s.onStop(i)},trash:function(){s.onTrash(i)},combineFeatures:function(){s.onCombineFeatures(i)},uncombineFeatures:function(){s.onUncombineFeatures(i)},render:function(e,t){s.toDisplayFeatures(i,e,t)}}}}},{"./mode_interface":57}],60:[function(e,t,n){"use strict";var a=e("../lib/common_selectors"),c=e("../lib/mouse_event_point"),o=e("../lib/create_supplementary_points"),r=e("../lib/string_set"),u=e("../lib/double_click_zoom"),i=e("../lib/move_features"),l=e("../constants"),s={onSetup:function(e){var t=this,n={dragMoveLocation:null,boxSelectStartLocation:null,boxSelectElement:void 0,boxSelecting:!1,canBoxSelect:!1,dragMoveing:!1,canDragMove:!1,initiallySelectedFeatureIds:e.featureIds||[]};return this.setSelected(n.initiallySelectedFeatureIds.filter(function(e){return void 0!==t.getFeature(e)})),this.fireActionable(),this.setActionableState({combineFeatures:!0,uncombineFeatures:!0,trash:!0}),n},fireUpdate:function(){this.map.fire(l.events.UPDATE,{action:l.updateActions.MOVE,features:this.getSelected().map(function(e){return e.toGeoJSON()})})},fireActionable:function(){var t=this,e=this.getSelected(),n=e.filter(function(e){return t.isInstanceOf("MultiFeature",e)}),o=!1;if(1<e.length){o=!0;var r=e[0].type.replace("Multi","");e.forEach(function(e){e.type.replace("Multi","")!==r&&(o=!1)})}var i=0<n.length,s=0<e.length;this.setActionableState({combineFeatures:o,uncombineFeatures:i,trash:s})},getUniqueIds:function(e){return e.length?e.map(function(e){return e.properties.id}).filter(function(e){return void 0!==e}).reduce(function(e,t){return e.add(t),e},new r).values():[]},stopExtendedInteractions:function(e){e.boxSelectElement&&(e.boxSelectElement.parentNode&&e.boxSelectElement.parentNode.removeChild(e.boxSelectElement),e.boxSelectElement=null),this.map.dragPan.enable(),e.boxSelecting=!1,e.canBoxSelect=!1,e.dragMoving=!1,e.canDragMove=!1},onStop:function(){u.enable(this)},onMouseMove:function(e){return this.stopExtendedInteractions(e)},onMouseOut:function(e){if(e.dragMoving)return this.fireUpdate()}};s.onTap=s.onClick=function(e,t){return a.noTarget(t)?this.clickAnywhere(e,t):a.isOfMetaType(l.meta.VERTEX)(t)?this.clickOnVertex(e,t):a.isFeature(t)?this.clickOnFeature(e,t):void 0},s.clickAnywhere=function(e){var t=this,n=this.getSelectedIds();n.length&&(this.clearSelectedFeatures(),n.forEach(function(e){return t.doRender(e)})),u.enable(this),this.stopExtendedInteractions(e)},s.clickOnVertex=function(e,t){this.changeMode(l.modes.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:l.cursors.MOVE})},s.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},s.clickOnFeature=function(e,t){var n=this;u.disable(this),this.stopExtendedInteractions(e);var o=a.isShiftDown(t),r=this.getSelectedIds(),i=t.featureTarget.properties.id,s=this.isSelected(i);if(!o&&s&&this.getFeature(i).type!==l.geojsonTypes.POINT)return this.changeMode(l.modes.DIRECT_SELECT,{featureId:i});s&&o?(this.deselect(i),this.updateUIClasses({mouse:l.cursors.POINTER}),1===r.length&&u.enable(this)):!s&&o?(this.select(i),this.updateUIClasses({mouse:l.cursors.MOVE})):s||o||(r.forEach(function(e){return n.doRender(e)}),this.setSelected(i),this.updateUIClasses({mouse:l.cursors.MOVE})),this.doRender(i)},s.onMouseDown=function(e,t){return a.isActiveFeature(t)?this.startOnActiveFeature(e,t):this.drawConfig.boxSelect&&a.isShiftMousedown(t)?this.startBoxSelect(e,t):void 0},s.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=c(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},s.onTouchStart=function(e,t){if(a.isActiveFeature(t))return this.startOnActiveFeature(e,t)},s.onDrag=function(e,t){return e.canDragMove?this.dragMove(e,t):this.drawConfig.boxSelect&&e.canBoxSelect?this.whileBoxSelect(e,t):void 0},s.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:l.cursors.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(l.classes.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));var n=c(t.originalEvent,this.map.getContainer()),o=Math.min(e.boxSelectStartLocation.x,n.x),r=Math.max(e.boxSelectStartLocation.x,n.x),i=Math.min(e.boxSelectStartLocation.y,n.y),s=Math.max(e.boxSelectStartLocation.y,n.y),a="translate(".concat(o,"px, ").concat(i,"px)");e.boxSelectElement.style.transform=a,e.boxSelectElement.style.WebkitTransform=a,e.boxSelectElement.style.width="".concat(r-o,"px"),e.boxSelectElement.style.height="".concat(s-i,"px")},s.dragMove=function(e,t){e.dragMoving=!0,t.originalEvent.stopPropagation();var n={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};i(this.getSelected(),n),e.dragMoveLocation=t.lngLat},s.onMouseUp=function(e,t){var n=this;if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){var o=[e.boxSelectStartLocation,c(t.originalEvent,this.map.getContainer())],r=this.featuresAt(null,o,"click"),i=this.getUniqueIds(r).filter(function(e){return!n.isSelected(e)});i.length&&(this.select(i),i.forEach(function(e){return n.doRender(e)}),this.updateUIClasses({mouse:l.cursors.MOVE}))}this.stopExtendedInteractions(e)},s.toDisplayFeatures=function(e,t,n){t.properties.active=this.isSelected(t.properties.id)?l.activeStates.ACTIVE:l.activeStates.INACTIVE,n(t),this.fireActionable(),t.properties.active===l.activeStates.ACTIVE&&t.geometry.type!==l.geojsonTypes.POINT&&o(t).forEach(n)},s.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},s.onCombineFeatures=function(){var e=this.getSelected();if(!(0===e.length||e.length<2)){for(var t=[],n=[],o=e[0].type.replace("Multi",""),r=0;r<e.length;r++){var i=e[r];if(i.type.replace("Multi","")!==o)return;i.type.includes("Multi")?i.getCoordinates().forEach(function(e){t.push(e)}):t.push(i.getCoordinates()),n.push(i.toGeoJSON())}if(1<n.length){var s=this.newFeature({type:l.geojsonTypes.FEATURE,properties:n[0].properties,geometry:{type:"Multi".concat(o),coordinates:t}});this.addFeature(s),this.deleteFeature(this.getSelectedIds(),{silent:!0}),this.setSelected([s.id]),this.map.fire(l.events.COMBINE_FEATURES,{createdFeatures:[s.toGeoJSON()],deletedFeatures:n})}this.fireActionable()}},s.onUncombineFeatures=function(){var n=this,o=this.getSelected();if(0!==o.length){for(var r=[],i=[],e=function(e){var t=o[e];n.isInstanceOf("MultiFeature",t)&&(t.getFeatures().forEach(function(e){n.addFeature(e),e.properties=t.properties,r.push(e.toGeoJSON()),n.select([e.id])}),n.deleteFeature(t.id,{silent:!0}),i.push(t.toGeoJSON()))},t=0;t<o.length;t++)e(t);1<r.length&&this.map.fire(l.events.UNCOMBINE_FEATURES,{createdFeatures:r,deletedFeatures:i}),this.fireActionable()}},t.exports=s},{"../constants":23,"../lib/common_selectors":30,"../lib/create_supplementary_points":33,"../lib/double_click_zoom":35,"../lib/mouse_event_point":44,"../lib/move_features":45,"../lib/string_set":47}],61:[function(e,t,n){"use strict";var o=e("xtend"),r=e("./constants"),i={defaultMode:r.modes.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:e("./lib/theme"),modes:e("./modes"),controls:{},userProperties:!1},s={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},a={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function c(e,t){return e.map(function(e){return e.source?e:o(e,{id:"".concat(e.id,".").concat(t),source:"hot"===t?r.sources.HOT:r.sources.COLD})})}t.exports=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=o(e);return e.controls||(t.controls={}),!1===e.displayControlsDefault?t.controls=o(a,e.controls):t.controls=o(s,e.controls),(t=o(i,t)).styles=c(t.styles,"cold").concat(c(t.styles,"hot")),t}},{"./constants":23,"./lib/theme":49,"./modes":56,xtend:21}],62:[function(e,t,n){"use strict";var u=e("./constants");t.exports=function(){var o=this;if(!(o.ctx.map&&void 0!==o.ctx.map.getSource(u.sources.HOT)))return c();var r=o.ctx.events.currentModeName();o.ctx.ui.queueMapClasses({mode:r});var n=[],e=[];e=o.isDirty?o.getAllIds():(n=o.getChangedIds().filter(function(e){return void 0!==o.get(e)}),o.sources.hot.filter(function(e){return e.properties.id&&-1===n.indexOf(e.properties.id)&&void 0!==o.get(e.properties.id)}).map(function(e){return e.properties.id})),o.sources.hot=[];var t=o.sources.cold.length;o.sources.cold=o.isDirty?[]:o.sources.cold.filter(function(e){var t=e.properties.id||e.properties.parent;return-1===n.indexOf(t)});var i=t!==o.sources.cold.length||0<e.length;function s(e,t){var n=o.get(e).internal(r);o.ctx.events.currentModeRender(n,function(e){o.sources[t].push(e)})}if(n.forEach(function(e){return s(e,"hot")}),e.forEach(function(e){return s(e,"cold")}),i&&o.ctx.map.getSource(u.sources.COLD).setData({type:u.geojsonTypes.FEATURE_COLLECTION,features:o.sources.cold}),o.ctx.map.getSource(u.sources.HOT).setData({type:u.geojsonTypes.FEATURE_COLLECTION,features:o.sources.hot}),o._emitSelectionChange&&(o.ctx.map.fire(u.events.SELECTION_CHANGE,{features:o.getSelected().map(function(e){return e.toGeoJSON()}),points:o.getSelectedCoordinates().map(function(e){return{type:u.geojsonTypes.FEATURE,properties:{},geometry:{type:u.geojsonTypes.POINT,coordinates:e.coordinates}}})}),o._emitSelectionChange=!1),o._deletedFeaturesToEmit.length){var a=o._deletedFeaturesToEmit.map(function(e){return e.toGeoJSON()});o._deletedFeaturesToEmit=[],o.ctx.map.fire(u.events.DELETE,{features:a})}function c(){o.isDirty=!1,o.clearChangedIds()}c(),o.ctx.map.fire(u.events.RENDER,{})}},{"./constants":23}],63:[function(e,t,n){"use strict";var s=e("./events"),a=e("./store"),c=e("./ui"),o=e("./constants"),u=e("xtend");t.exports=function(t){var e=null,n=null,i={onRemove:function(){return t.map.off("load",i.connect),clearInterval(n),i.removeLayers(),t.store.restoreMapConfig(),t.ui.removeButtons(),t.events.removeEventListeners(),t.ui.clearMapClasses(),t.map=null,t.container=null,t.store=null,e&&e.parentNode&&e.parentNode.removeChild(e),e=null,this},connect:function(){t.map.off("load",i.connect),clearInterval(n),i.addLayers(),t.store.storeMapConfig(),t.events.addEventListeners()},onAdd:function(o){var r=o.fire;return o.fire=function(e,t){var n=arguments;return 1===r.length&&1!==arguments.length&&(n=[u({},{type:e},t)]),r.apply(o,n)},t.map=o,t.events=s(t),t.ui=c(t),t.container=o.getContainer(),t.store=new a(t),e=t.ui.addButtons(),t.options.boxSelect&&(o.boxZoom.disable(),o.dragPan.disable(),o.dragPan.enable()),o.loaded()?i.connect():(o.on("load",i.connect),n=setInterval(function(){o.loaded()&&i.connect()},16)),t.events.start(),e},addLayers:function(){t.map.addSource(o.sources.COLD,{data:{type:o.geojsonTypes.FEATURE_COLLECTION,features:[]},type:"geojson"}),t.map.addSource(o.sources.HOT,{data:{type:o.geojsonTypes.FEATURE_COLLECTION,features:[]},type:"geojson"}),t.options.styles.forEach(function(e){t.map.addLayer(e)}),t.store.setDirty(!0),t.store.render()},removeLayers:function(){t.options.styles.forEach(function(e){t.map.getLayer(e.id)&&t.map.removeLayer(e.id)}),t.map.getSource(o.sources.COLD)&&t.map.removeSource(o.sources.COLD),t.map.getSource(o.sources.HOT)&&t.map.removeSource(o.sources.HOT)}};return t.setup=i}},{"./constants":23,"./events":24,"./store":64,"./ui":65,xtend:21}],64:[function(e,t,n){"use strict";var o=e("./lib/throttle"),r=e("./lib/to_dense_array"),i=e("./lib/string_set"),s=e("./render"),a=e("./constants").interactions,c=t.exports=function(e){this._features={},this._featureIds=new i,this._selectedFeatureIds=new i,this._selectedCoordinates=[],this._changedFeatureIds=new i,this._deletedFeaturesToEmit=[],this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]},this.render=o(s,16,this),this.isDirty=!1};function u(e){var t=this,n=this._selectedCoordinates.filter(function(e){return t._selectedFeatureIds.has(e.feature_id)});this._selectedCoordinates.length===n.length||e.silent||(this._emitSelectionChange=!0),this._selectedCoordinates=n}c.prototype.createRenderBatch=function(){var e=this,t=this.render,n=0;return this.render=function(){n++},function(){e.render=t,0<n&&e.render()}},c.prototype.setDirty=function(){return this.isDirty=!0,this},c.prototype.featureChanged=function(e){return this._changedFeatureIds.add(e),this},c.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},c.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},c.prototype.getAllIds=function(){return this._featureIds.values()},c.prototype.add=function(e){return this.featureChanged(e.id),this._features[e.id]=e,this._featureIds.add(e.id),this},c.prototype.delete=function(e){var t=this,n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return r(e).forEach(function(e){t._featureIds.has(e)&&(t._featureIds.delete(e),t._selectedFeatureIds.delete(e),n.silent||-1===t._deletedFeaturesToEmit.indexOf(t._features[e])&&t._deletedFeaturesToEmit.push(t._features[e]),delete t._features[e],t.isDirty=!0)}),u.call(this,n),this},c.prototype.get=function(e){return this._features[e]},c.prototype.getAll=function(){var t=this;return Object.keys(this._features).map(function(e){return t._features[e]})},c.prototype.select=function(e){var t=this,n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return r(e).forEach(function(e){t._selectedFeatureIds.has(e)||(t._selectedFeatureIds.add(e),t._changedFeatureIds.add(e),n.silent||(t._emitSelectionChange=!0))}),this},c.prototype.deselect=function(e){var t=this,n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return r(e).forEach(function(e){t._selectedFeatureIds.has(e)&&(t._selectedFeatureIds.delete(e),t._changedFeatureIds.add(e),n.silent||(t._emitSelectionChange=!0))}),u.call(this,n),this},c.prototype.clearSelected=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},c.prototype.setSelected=function(t){var n=this,e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return t=r(t),this.deselect(this._selectedFeatureIds.values().filter(function(e){return-1===t.indexOf(e)}),{silent:e.silent}),this.select(t.filter(function(e){return!n._selectedFeatureIds.has(e)}),{silent:e.silent}),this},c.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},c.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},c.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},c.prototype.getSelected=function(){var t=this;return this._selectedFeatureIds.values().map(function(e){return t.get(e)})},c.prototype.getSelectedCoordinates=function(){var t=this;return this._selectedCoordinates.map(function(e){return{coordinates:t.get(e.feature_id).getCoordinate(e.coord_path)}})},c.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},c.prototype.setFeatureProperty=function(e,t,n){this.get(e).setProperty(t,n),this.featureChanged(e)},c.prototype.storeMapConfig=function(){var t=this;a.forEach(function(e){t.ctx.map[e]&&(t._mapInitialConfig[e]=t.ctx.map[e].isEnabled())})},c.prototype.restoreMapConfig=function(){var t=this;Object.keys(this._mapInitialConfig).forEach(function(e){t._mapInitialConfig[e]?t.ctx.map[e].enable():t.ctx.map[e].disable()})},c.prototype.getInitialConfigValue=function(e){return void 0===this._mapInitialConfig[e]||this._mapInitialConfig[e]}},{"./constants":23,"./lib/string_set":47,"./lib/throttle":50,"./lib/to_dense_array":51,"./render":62}],65:[function(e,t,n){"use strict";var l=e("xtend"),p=e("./constants"),f=["mode","feature","mouse"];t.exports=function(o){var n={},r=null,i={mode:null,feature:null,mouse:null},s={mode:null,feature:null,mouse:null};function e(e){s=l(s,e)}function t(){if(o.container){var t=[],n=[];f.forEach(function(e){s[e]!==i[e]&&(t.push("".concat(e,"-").concat(i[e])),null!==s[e]&&n.push("".concat(e,"-").concat(s[e])))}),0<t.length&&o.container.classList.remove.apply(o.container.classList,t),0<n.length&&o.container.classList.add.apply(o.container.classList,n),i=l(i,s)}}function a(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},e=document.createElement("button");return e.className="".concat(p.classes.CONTROL_BUTTON," ").concat(n.className),e.setAttribute("title",n.title),n.container.appendChild(e),e.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation(),e.target!==r?(u(t),n.onActivate()):c()},!0),e}function c(){r&&(r.classList.remove(p.classes.ACTIVE_BUTTON),r=null)}function u(e){c();var t=n[e];t&&t&&"trash"!==e&&(t.classList.add(p.classes.ACTIVE_BUTTON),r=t)}return{setActiveButton:u,queueMapClasses:e,updateMapClasses:t,clearMapClasses:function(){e({mode:null,feature:null,mouse:null}),t()},addButtons:function(){var e=o.options.controls,t=document.createElement("div");return t.className="".concat(p.classes.CONTROL_GROUP," ").concat(p.classes.CONTROL_BASE),e&&(e[p.types.LINE]&&(n[p.types.LINE]=a(p.types.LINE,{container:t,className:p.classes.CONTROL_BUTTON_LINE,title:"LineString tool ".concat(o.options.keybindings?"(l)":""),onActivate:function(){return o.events.changeMode(p.modes.DRAW_LINE_STRING)}})),e[p.types.POLYGON]&&(n[p.types.POLYGON]=a(p.types.POLYGON,{container:t,className:p.classes.CONTROL_BUTTON_POLYGON,title:"Polygon tool ".concat(o.options.keybindings?"(p)":""),onActivate:function(){return o.events.changeMode(p.modes.DRAW_POLYGON)}})),e[p.types.POINT]&&(n[p.types.POINT]=a(p.types.POINT,{container:t,className:p.classes.CONTROL_BUTTON_POINT,title:"Marker tool ".concat(o.options.keybindings?"(m)":""),onActivate:function(){return o.events.changeMode(p.modes.DRAW_POINT)}})),e.trash&&(n.trash=a("trash",{container:t,className:p.classes.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:function(){o.events.trash()}})),e.combine_features&&(n.combine_features=a("combineFeatures",{container:t,className:p.classes.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:function(){o.events.combineFeatures()}})),e.uncombine_features&&(n.uncombine_features=a("uncombineFeatures",{container:t,className:p.classes.CONTROL_BUTTON_UNCOMBINE_FEATURES,title:"Uncombine",onActivate:function(){o.events.uncombineFeatures()}}))),t},removeButtons:function(){Object.keys(n).forEach(function(e){var t=n[e];t.parentNode&&t.parentNode.removeChild(t),delete n[e]})}}}},{"./constants":23,xtend:21}]},{},[1])(1)});
@radekdob
Copy link

Hey, thank you for this code ! It solved my issue with mapbox gl draw.
Do you still use this library ? This code is from early 2019 and many updates of Mapbox gl draw were announced and in the latets version 1.2.0 that issue still exists. I wonder if you maybe still use this library and modify the latest version to be out of that bug ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment