exists
+ _layer = selection.selectAll('.layer-ai-features')
+ .data(_enabled$1 ? [0] : []);
+
+ _layer.exit()
+ .remove();
+
+ let layerEnter = _layer.enter()
+ .append('g')
+ .attr('class', 'layer-ai-features');
+
+ layerEnter
+ .append('defs')
+ .attr('class', 'rapid-defs');
+
+ _layer = layerEnter
+ .merge(_layer);
+
+ const surface = context.surface();
+ const waitingForTaskExtent = gpxInUrl && !rapidContext.getTaskExtent();
+ if (!surface || surface.empty() || waitingForTaskExtent) return; // not ready to draw yet, starting up
+
+
+ // Gather available datasets, generate a unique fill pattern
+ // and a layer group for each dataset. Fill pattern styling is complicated.
+ // Style needs to apply in the def, not where the pattern is used.
+ const rapidDatasets = rapidContext.datasets();
+ const datasets = Object.values(rapidDatasets)
+ .filter(dataset => dataset.added && dataset.enabled);
+
+ let defs = _layer.selectAll('.rapid-defs');
+ let dsPatterns = defs.selectAll('.rapid-fill-pattern')
+ .data(datasets, d => d.id);
+
+ // exit
+ dsPatterns.exit()
+ .remove();
+
+ // enter
+ let dsPatternsEnter = dsPatterns.enter()
+ .append('pattern')
+ .attr('id', d => `fill-${d.id}`)
+ .attr('class', 'rapid-fill-pattern')
+ .attr('width', 5)
+ .attr('height', 15)
+ .attr('patternUnits', 'userSpaceOnUse')
+ .attr('patternTransform', (d, i) => {
+ const r = (45 + (67 * i)) % 180; // generate something different for each layer
+ return `rotate(${r})`;
+ });
+
+ dsPatternsEnter
+ .append('line')
+ .attr('class', 'ai-building-line')
+ .attr('stroke', 'currentColor')
+ .attr('stroke-width', '2px')
+ .attr('stroke-opacity', 0.6)
+ .attr('y2', '15');
+
+ // update
+ dsPatterns = dsPatternsEnter
+ .merge(dsPatterns)
+ .style('color', d => d.color || RAPID_MAGENTA);
+
+
+ let dsGroups = _layer.selectAll('.layer-rapid-dataset')
+ .data(datasets, d => d.id);
+
+ // exit
+ dsGroups.exit()
+ .remove();
+
+ // enter/update
+ dsGroups = dsGroups.enter()
+ .append('g')
+ .attr('class', d => `layer-rapid-dataset layer-rapid-dataset-${d.id}`)
+ .merge(dsGroups)
+ .style('color', d => d.color || RAPID_MAGENTA)
+ .each(eachDataset);
+ }
+
+
+ function eachDataset(dataset, i, nodes) {
+ const rapidContext = context.rapidContext();
+ const selection = select(nodes[i]);
+ const service = dataset.service === 'fbml' ? getFbMlService(): getEsriService();
+ if (!service) return;
+
+ // Adjust the dataset id for whether we want the data conflated or not.
+ const internalID = dataset.id + (dataset.conflated ? '-conflated' : '');
+ const graph = service.graph(internalID);
+ const getPath = svgPath(projection, graph);
+ const getTransform = svgPointTransform(projection);
+
+ // Gather data
+ let geoData = {
+ paths: [],
+ vertices: [],
+ points: []
+ };
+
+ if (context.map().zoom() >= context.minEditableZoom()) {
+ /* Facebook AI/ML */
+ if (dataset.service === 'fbml') {
+
+ service.loadTiles(internalID, projection, rapidContext.getTaskExtent());
+ let pathData = service
+ .intersects(internalID, context.map().extent())
+ .filter(d => d.type === 'way' && !_actioned.has(d.id) && !_actioned.has(d.__origid__) ) // see onHistoryRestore()
+ .filter(getPath);
+
+ // fb_ai service gives us roads and buildings together,
+ // so filter further according to which dataset we're drawing
+ if (dataset.id === 'fbRoads' || dataset.id === 'rapid_intro_graph') {
+ geoData.paths = pathData.filter(d => !!d.tags.highway);
+
+ let seen = {};
+ geoData.paths.forEach(d => {
+ const first = d.first();
+ const last = d.last();
+ if (!seen[first]) {
+ seen[first] = true;
+ geoData.vertices.push(graph.entity(first));
+ }
+ if (!seen[last]) {
+ seen[last] = true;
+ geoData.vertices.push(graph.entity(last));
+ }
+ });
+
+ } else if (dataset.id === 'msBuildings') {
+ geoData.paths = pathData.filter(isArea);
+ // no vertices
+
+ } else {
+ // esri data via fb service
+ geoData.paths = pathData.filter(isArea);
+ }
+
+ /* ESRI ArcGIS */
+ } else if (dataset.service === 'esri') {
+ service.loadTiles(internalID, projection);
+ let visibleData = service
+ .intersects(internalID, context.map().extent())
+ .filter(d => !_actioned.has(d.id) && !_actioned.has(d.__origid__) ); // see onHistoryRestore()
+
+ geoData.points = visibleData
+ .filter(d => d.type === 'node' && !!d.__fbid__); // standalone only (not vertices/childnodes)
+
+ geoData.paths = visibleData
+ .filter(d => d.type === 'way' || d.type === 'relation')
+ .filter(getPath);
+ }
+ }
+
+ selection
+ .call(drawPaths, geoData.paths, dataset, getPath)
+ .call(drawVertices, geoData.vertices, getTransform)
+ .call(drawPoints, geoData.points, getTransform);
+ }
+
+
+ function drawPaths(selection, pathData, dataset, getPath) {
+ // Draw shadow, casing, stroke layers
+ let linegroups = selection
+ .selectAll('g.linegroup')
+ .data(['shadow', 'casing', 'stroke']);
+
+ linegroups = linegroups.enter()
+ .append('g')
+ .attr('class', d => `linegroup linegroup-${d}`)
+ .merge(linegroups);
+
+ // Draw paths
+ let paths = linegroups
+ .selectAll('path')
+ .data(pathData, featureKey);
+
+ // exit
+ paths.exit()
+ .remove();
+
+ // enter/update
+ paths = paths.enter()
+ .append('path')
+ .attr('style', d => isArea(d) ? `fill: url(#fill-${dataset.id})` : null)
+ .attr('class', (d, i, nodes) => {
+ const currNode = nodes[i];
+ const linegroup = currNode.parentNode.__data__;
+ const klass = isArea(d) ? 'building' : 'road';
+ return `line ${linegroup} ${klass} data${d.__fbid__}`;
+ })
+ .merge(paths)
+ .attr('d', getPath);
+ }
+
+
+ function drawVertices(selection, vertexData, getTransform) {
+ const vertRadii = {
+ // z16-, z17, z18+
+ stroke: [3.5, 4, 4.5],
+ fill: [2, 2, 2.5]
+ };
+
+ let vertexGroup = selection
+ .selectAll('g.vertexgroup')
+ .data(vertexData.length ? [0] : []);
+
+ vertexGroup.exit()
+ .remove();
+
+ vertexGroup = vertexGroup.enter()
+ .append('g')
+ .attr('class', 'vertexgroup')
+ .merge(vertexGroup);
+
+
+ let vertices = vertexGroup
+ .selectAll('g.vertex')
+ .data(vertexData, d => d.id);
+
+ // exit
+ vertices.exit()
+ .remove();
+
+ // enter
+ let enter = vertices.enter()
+ .append('g')
+ .attr('class', d => `node vertex ${d.id}`);
+
+ enter
+ .append('circle')
+ .attr('class', 'stroke');
+
+ enter
+ .append('circle')
+ .attr('class', 'fill');
+
+ // update
+ const zoom = geoScaleToZoom(projection.scale());
+ const radiusIdx = (zoom < 17 ? 0 : zoom < 18 ? 1 : 2);
+ vertices = vertices
+ .merge(enter)
+ .attr('transform', getTransform)
+ .call(selection => {
+ ['stroke', 'fill'].forEach(klass => {
+ selection.selectAll('.' + klass)
+ .attr('r', vertRadii[klass][radiusIdx]);
+ });
+ });
+ }
+
+
+ function drawPoints(selection, pointData, getTransform) {
+ const pointRadii = {
+ // z16-, z17, z18+
+ shadow: [4.5, 7, 8],
+ stroke: [4.5, 7, 8],
+ fill: [2.5, 4, 5]
+ };
+
+ let pointGroup = selection
+ .selectAll('g.pointgroup')
+ .data(pointData.length ? [0] : []);
+
+ pointGroup.exit()
+ .remove();
+
+ pointGroup = pointGroup.enter()
+ .append('g')
+ .attr('class', 'pointgroup')
+ .merge(pointGroup);
+
+ let points = pointGroup
+ .selectAll('g.point')
+ .data(pointData, featureKey);
+
+ // exit
+ points.exit()
+ .remove();
+
+ // enter
+ let enter = points.enter()
+ .append('g')
+ .attr('class', d => `node point data${d.__fbid__}`);
+
+ enter
+ .append('circle')
+ .attr('class', 'shadow');
+
+ enter
+ .append('circle')
+ .attr('class', 'stroke');
+
+ enter
+ .append('circle')
+ .attr('class', 'fill');
+
+ // update
+ const zoom = geoScaleToZoom(projection.scale());
+ const radiusIdx = (zoom < 17 ? 0 : zoom < 18 ? 1 : 2);
+ points = points
+ .merge(enter)
+ .attr('transform', getTransform)
+ .call(selection => {
+ ['shadow', 'stroke', 'fill'].forEach(klass => {
+ selection.selectAll('.' + klass)
+ .attr('r', pointRadii[klass][radiusIdx]);
+ });
+ });
+ }
+
+
+ render.showAll = function() {
+ return _enabled$1;
+ };
+
+
+ render.enabled = function(val) {
+ if (!arguments.length) return _enabled$1;
+
+ _enabled$1 = val;
+ if (_enabled$1) {
+ showLayer();
+ } else {
+ hideLayer();
+ }
+
+ dispatch.call('change');
+ return render;
+ };
+
+
+ init();
+ return render;
+ }
+
+ function svgLayers(projection, context) {
+ var dispatch$1 = dispatch('change');
+ var svg = select(null);
+ var _layers = [
+ { id: 'ai-features', layer: svgRapidFeatures(projection, context, dispatch$1) },
+ { id: 'osm', layer: svgOsm(projection, context, dispatch$1) },
+ { id: 'notes', layer: svgNotes(projection, context, dispatch$1) },
+ { id: 'data', layer: svgData(projection, context, dispatch$1) },
+ { id: 'keepRight', layer: svgKeepRight(projection, context, dispatch$1) },
+ { id: 'improveOSM', layer: svgImproveOSM(projection, context, dispatch$1) },
+ { id: 'osmose', layer: svgOsmose(projection, context, dispatch$1) },
+ { id: 'streetside', layer: svgStreetside(projection, context, dispatch$1)},
+ { id: 'mapillary', layer: svgMapillaryImages(projection, context, dispatch$1) },
+ { id: 'mapillary-map-features', layer: svgMapillaryMapFeatures(projection, context, dispatch$1) },
+ { id: 'mapillary-signs', layer: svgMapillarySigns(projection, context, dispatch$1) },
+ { id: 'openstreetcam', layer: svgOpenstreetcamImages(projection, context, dispatch$1) },
+ { id: 'debug', layer: svgDebug(projection, context) },
+ { id: 'geolocate', layer: svgGeolocate(projection) },
+ { id: 'touch', layer: svgTouch() }
+ ];
+
+
+ function drawLayers(selection) {
+ svg = selection.selectAll('.surface')
+ .data([0]);
+
+ svg = svg.enter()
+ .append('svg')
+ .attr('class', 'surface')
+ .merge(svg);
+
+ var defs = svg.selectAll('.surface-defs')
+ .data([0]);
+
+ defs.enter()
+ .append('defs')
+ .attr('class', 'surface-defs');
+
+ defs.enter()
+ .append('svg')
+ .attr('class', 'grids-svg');
+
+ var groups = svg.selectAll('.data-layer')
+ .data(_layers);
+
+ groups.exit()
+ .remove();
+
+ groups.enter()
+ .append('g')
+ .attr('class', function(d) { return 'data-layer ' + d.id; })
+ .merge(groups)
+ .each(function(d) { select(this).call(d.layer); });
+ }
+
+
+ drawLayers.all = function() {
+ return _layers;
+ };
+
+
+ drawLayers.layer = function(id) {
+ var obj = _layers.find(function(o) { return o.id === id; });
+ return obj && obj.layer;
+ };
+
+
+ drawLayers.only = function(what) {
+ var arr = [].concat(what);
+ var all = _layers.map(function(layer) { return layer.id; });
+ return drawLayers.remove(utilArrayDifference(all, arr));
+ };
+
+
+ drawLayers.remove = function(what) {
+ var arr = [].concat(what);
+ arr.forEach(function(id) {
+ _layers = _layers.filter(function(o) { return o.id !== id; });
+ });
+ dispatch$1.call('change');
+ return this;
+ };
+
+
+ drawLayers.add = function(what) {
+ var arr = [].concat(what);
+ arr.forEach(function(obj) {
+ if ('id' in obj && 'layer' in obj) {
+ _layers.push(obj);
+ }
+ });
+ dispatch$1.call('change');
+ return this;
+ };
+
+
+ drawLayers.dimensions = function(val) {
+ if (!arguments.length) return utilGetDimensions(svg);
+ utilSetDimensions(svg, val);
+ return this;
+ };
+
+
+ return utilRebind(drawLayers, dispatch$1, 'on');
+ }
+
+ /**
+ * Removes all key-value entries from the list cache.
+ *
+ * @private
+ * @name clear
+ * @memberOf ListCache
+ */
+ function listCacheClear() {
+ this.__data__ = [];
+ this.size = 0;
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * 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;
+ }
+
+ /** Used for built-in method references. */
+ var arrayProto = Array.prototype;
+
+ /** Built-in value references. */
+ var splice = arrayProto.splice;
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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]);
+ }
+ }
+
+ // Add methods to `ListCache`.
+ ListCache.prototype.clear = listCacheClear;
+ ListCache.prototype['delete'] = listCacheDelete;
+ ListCache.prototype.get = listCacheGet;
+ ListCache.prototype.has = listCacheHas;
+ ListCache.prototype.set = listCacheSet;
+
+ /**
+ * 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);
+ }
+
+ /** `Object#toString` result references. */
+ var asyncTag = '[object AsyncFunction]',
+ funcTag = '[object Function]',
+ genTag = '[object GeneratorFunction]',
+ proxyTag = '[object Proxy]';
+
+ /**
+ * 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$2(value) {
+ if (!isObject$1(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;
+ }
+
+ /** Used to detect overreaching core-js shims. */
+ var coreJsData = root$2['__core-js_shared__'];
+
+ /** 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) : '';
+ }());
+
+ /**
+ * 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);
+ }
+
+ /** Used for built-in method references. */
+ var funcProto = Function.prototype;
+
+ /** Used to resolve the decompiled source of functions. */
+ var funcToString = funcProto.toString;
+
+ /**
+ * 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 '';
+ }
+
+ /**
+ * 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 for built-in method references. */
+ var funcProto$1 = Function.prototype,
+ objectProto$2 = Object.prototype;
+
+ /** Used to resolve the decompiled source of functions. */
+ var funcToString$1 = funcProto$1.toString;
+
+ /** Used to check objects for own properties. */
+ var hasOwnProperty$3 = objectProto$2.hasOwnProperty;
+
+ /** Used to detect if a method is native. */
+ var reIsNative = RegExp('^' +
+ funcToString$1.call(hasOwnProperty$3).replace(reRegExpChar, '\\$&')
+ .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
+ );
+
+ /**
+ * 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$1(value) || isMasked(value)) {
+ return false;
+ }
+ var pattern = isFunction$2(value) ? reIsNative : reIsHostCtor;
+ return pattern.test(toSource(value));
+ }
+
+ /**
+ * 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];
+ }
+
+ /**
+ * 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;
+ }
+
+ /* Built-in method references that are verified to be native. */
+ var Map$2 = getNative(root$2, 'Map');
+
+ /* Built-in method references that are verified to be native. */
+ var nativeCreate = getNative(Object, 'create');
+
+ /**
+ * 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;
+ }
+
+ /** Used to stand-in for `undefined` hash values. */
+ var HASH_UNDEFINED = '__lodash_hash_undefined__';
+
+ /** Used for built-in method references. */
+ var objectProto$3 = Object.prototype;
+
+ /** Used to check objects for own properties. */
+ var hasOwnProperty$4 = objectProto$3.hasOwnProperty;
+
+ /**
+ * 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$4.call(data, key) ? data[key] : undefined;
+ }
+
+ /** Used for built-in method references. */
+ var objectProto$4 = Object.prototype;
+
+ /** Used to check objects for own properties. */
+ var hasOwnProperty$5 = objectProto$4.hasOwnProperty;
+
+ /**
+ * 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$5.call(data, key);
+ }
+
+ /** Used to stand-in for `undefined` hash values. */
+ var HASH_UNDEFINED$1 = '__lodash_hash_undefined__';
+
+ /**
+ * 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$1 : value;
+ return this;
+ }
+
+ /**
+ * 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]);
+ }
+ }
+
+ // Add methods to `Hash`.
+ Hash.prototype.clear = hashClear;
+ Hash.prototype['delete'] = hashDelete;
+ Hash.prototype.get = hashGet;
+ Hash.prototype.has = hashHas;
+ Hash.prototype.set = hashSet;
+
+ /**
+ * 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$2 || ListCache),
+ 'string': new Hash
+ };
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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]);
+ }
+ }
+
+ // Add methods to `MapCache`.
+ MapCache.prototype.clear = mapCacheClear;
+ MapCache.prototype['delete'] = mapCacheDelete;
+ MapCache.prototype.get = mapCacheGet;
+ MapCache.prototype.has = mapCacheHas;
+ MapCache.prototype.set = mapCacheSet;
+
+ /** Used as the size to enable large array optimizations. */
+ var LARGE_ARRAY_SIZE = 200;
+
+ /**
+ * 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$2 || (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;
+ }
+
+ /**
+ * 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;
+ }
+
+ // Add methods to `Stack`.
+ Stack.prototype.clear = stackClear;
+ Stack.prototype['delete'] = stackDelete;
+ Stack.prototype.get = stackGet;
+ Stack.prototype.has = stackHas;
+ Stack.prototype.set = stackSet;
+
+ /** Used to stand-in for `undefined` hash values. */
+ var HASH_UNDEFINED$2 = '__lodash_hash_undefined__';
+
+ /**
+ * 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$2);
+ 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);
+ }
+
+ /**
+ *
+ * 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]);
+ }
+ }
+
+ // Add methods to `SetCache`.
+ SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
+ SetCache.prototype.has = setCacheHas;
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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);
+ }
+
+ /** Used to compose bitmasks for value comparisons. */
+ var COMPARE_PARTIAL_FLAG = 1,
+ COMPARE_UNORDERED_FLAG = 2;
+
+ /**
+ * 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;
+ }
+
+ /** Built-in value references. */
+ var Uint8Array$1 = root$2.Uint8Array;
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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 to compose bitmasks for value comparisons. */
+ var COMPARE_PARTIAL_FLAG$1 = 1,
+ COMPARE_UNORDERED_FLAG$1 = 2;
+
+ /** `Object#toString` result references. */
+ var boolTag = '[object Boolean]',
+ dateTag = '[object Date]',
+ errorTag = '[object Error]',
+ mapTag = '[object Map]',
+ numberTag = '[object Number]',
+ regexpTag = '[object RegExp]',
+ setTag = '[object Set]',
+ stringTag = '[object String]',
+ symbolTag$1 = '[object Symbol]';
+
+ var arrayBufferTag = '[object ArrayBuffer]',
+ dataViewTag = '[object DataView]';
+
+ /** Used to convert symbols to primitives and strings. */
+ var symbolProto = Symbol$1 ? Symbol$1.prototype : undefined,
+ symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
+
+ /**
+ * 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$1(object), new Uint8Array$1(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$1;
+ 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$1;
+
+ // 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$1:
+ if (symbolValueOf) {
+ return symbolValueOf.call(object) == symbolValueOf.call(other);
+ }
+ }
+ return false;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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$5 = Array.isArray;
+
+ /**
+ * 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$5(object) ? result : arrayPush(result, symbolsFunc(object));
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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 [];
+ }
+
+ /** Used for built-in method references. */
+ var objectProto$5 = Object.prototype;
+
+ /** Built-in value references. */
+ var propertyIsEnumerable = objectProto$5.propertyIsEnumerable;
+
+ /* Built-in method references for those with the same name as other `lodash` methods. */
+ var nativeGetSymbols = Object.getOwnPropertySymbols;
+
+ /**
+ * 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);
+ });
+ };
+
+ /**
+ * 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;
+ }
+
+ /** `Object#toString` result references. */
+ var argsTag = '[object Arguments]';
+
+ /**
+ * 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;
+ }
+
+ /** Used for built-in method references. */
+ var objectProto$6 = Object.prototype;
+
+ /** Used to check objects for own properties. */
+ var hasOwnProperty$6 = objectProto$6.hasOwnProperty;
+
+ /** Built-in value references. */
+ var propertyIsEnumerable$1 = objectProto$6.propertyIsEnumerable;
+
+ /**
+ * 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$2 = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
+ return isObjectLike(value) && hasOwnProperty$6.call(value, 'callee') &&
+ !propertyIsEnumerable$1.call(value, 'callee');
+ };
+
+ /**
+ * 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;
+ }
+
+ /** 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;
+
+ /** Built-in value references. */
+ var Buffer = moduleExports ? root$2.Buffer : undefined;
+
+ /* Built-in method references for those with the same name as other `lodash` methods. */
+ var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined;
+
+ /**
+ * 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;
+
+ /** Used as references for various `Number` constants. */
+ var MAX_SAFE_INTEGER = 9007199254740991;
+
+ /** Used to detect unsigned integer values. */
+ var reIsUint = /^(?:0|[1-9]\d*)$/;
+
+ /**
+ * 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) {
+ var type = typeof value;
+ length = length == null ? MAX_SAFE_INTEGER : length;
+
+ return !!length &&
+ (type == 'number' ||
+ (type != 'symbol' && reIsUint.test(value))) &&
+ (value > -1 && value % 1 == 0 && value < length);
+ }
+
+ /** Used as references for various `Number` constants. */
+ var MAX_SAFE_INTEGER$1 = 9007199254740991;
+
+ /**
+ * 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$1;
+ }
+
+ /** `Object#toString` result references. */
+ var argsTag$1 = '[object Arguments]',
+ arrayTag = '[object Array]',
+ boolTag$1 = '[object Boolean]',
+ dateTag$1 = '[object Date]',
+ errorTag$1 = '[object Error]',
+ funcTag$1 = '[object Function]',
+ mapTag$1 = '[object Map]',
+ numberTag$1 = '[object Number]',
+ objectTag = '[object Object]',
+ regexpTag$1 = '[object RegExp]',
+ setTag$1 = '[object Set]',
+ stringTag$1 = '[object String]',
+ weakMapTag = '[object WeakMap]';
+
+ var arrayBufferTag$1 = '[object ArrayBuffer]',
+ dataViewTag$1 = '[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 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$1] = typedArrayTags[arrayTag] =
+ typedArrayTags[arrayBufferTag$1] = typedArrayTags[boolTag$1] =
+ typedArrayTags[dataViewTag$1] = typedArrayTags[dateTag$1] =
+ typedArrayTags[errorTag$1] = typedArrayTags[funcTag$1] =
+ typedArrayTags[mapTag$1] = typedArrayTags[numberTag$1] =
+ typedArrayTags[objectTag] = typedArrayTags[regexpTag$1] =
+ typedArrayTags[setTag$1] = typedArrayTags[stringTag$1] =
+ typedArrayTags[weakMapTag] = false;
+
+ /**
+ * 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 `_.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);
+ };
+ }
+
+ /** Detect free variable `exports`. */
+ var freeExports$1 = typeof exports == 'object' && exports && !exports.nodeType && exports;
+
+ /** Detect free variable `module`. */
+ var freeModule$1 = freeExports$1 && typeof module == 'object' && module && !module.nodeType && module;
+
+ /** Detect the popular CommonJS extension `module.exports`. */
+ var moduleExports$1 = freeModule$1 && freeModule$1.exports === freeExports$1;
+
+ /** Detect free variable `process` from Node.js. */
+ var freeProcess = moduleExports$1 && freeGlobal.process;
+
+ /** Used to access faster Node.js helpers. */
+ var nodeUtil = (function() {
+ try {
+ // Use `util.types` for Node.js 10+.
+ var types = freeModule$1 && freeModule$1.require && freeModule$1.require('util').types;
+
+ if (types) {
+ return types;
+ }
+
+ // Legacy `process.binding('util')` for Node.js < 10.
+ return freeProcess && freeProcess.binding && freeProcess.binding('util');
+ } catch (e) {}
+ }());
+
+ /* Node.js helper references. */
+ var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
+
+ /**
+ * 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;
+
+ /** Used for built-in method references. */
+ var objectProto$7 = Object.prototype;
+
+ /** Used to check objects for own properties. */
+ var hasOwnProperty$7 = objectProto$7.hasOwnProperty;
+
+ /**
+ * 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$5(value),
+ isArg = !isArr && isArguments$2(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$7.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;
+ }
+
+ /** Used for built-in method references. */
+ var objectProto$8 = Object.prototype;
+
+ /**
+ * 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$8;
+
+ return value === proto;
+ }
+
+ /**
+ * 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));
+ };
+ }
+
+ /* Built-in method references for those with the same name as other `lodash` methods. */
+ var nativeKeys = overArg(Object.keys, Object);
+
+ /** Used for built-in method references. */
+ var objectProto$9 = Object.prototype;
+
+ /** Used to check objects for own properties. */
+ var hasOwnProperty$8 = objectProto$9.hasOwnProperty;
+
+ /**
+ * 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$8.call(object, key) && key != 'constructor') {
+ result.push(key);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * 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$2(value);
+ }
+
+ /**
+ * 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$3(object) {
+ return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
+ }
+
+ /**
+ * 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$3, getSymbols);
+ }
+
+ /** Used to compose bitmasks for value comparisons. */
+ var COMPARE_PARTIAL_FLAG$2 = 1;
+
+ /** Used for built-in method references. */
+ var objectProto$a = Object.prototype;
+
+ /** Used to check objects for own properties. */
+ var hasOwnProperty$9 = objectProto$a.hasOwnProperty;
+
+ /**
+ * 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$2,
+ 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$9.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;
+ }
+
+ /* Built-in method references that are verified to be native. */
+ var DataView$1 = getNative(root$2, 'DataView');
+
+ /* Built-in method references that are verified to be native. */
+ var Promise$2 = getNative(root$2, 'Promise');
+
+ /* Built-in method references that are verified to be native. */
+ var Set$2 = getNative(root$2, 'Set');
+
+ /* Built-in method references that are verified to be native. */
+ var WeakMap$1 = getNative(root$2, 'WeakMap');
+
+ /** `Object#toString` result references. */
+ var mapTag$2 = '[object Map]',
+ objectTag$1 = '[object Object]',
+ promiseTag = '[object Promise]',
+ setTag$2 = '[object Set]',
+ weakMapTag$1 = '[object WeakMap]';
+
+ var dataViewTag$2 = '[object DataView]';
+
+ /** Used to detect maps, sets, and weakmaps. */
+ var dataViewCtorString = toSource(DataView$1),
+ mapCtorString = toSource(Map$2),
+ promiseCtorString = toSource(Promise$2),
+ setCtorString = toSource(Set$2),
+ weakMapCtorString = toSource(WeakMap$1);
+
+ /**
+ * 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$1 && getTag(new DataView$1(new ArrayBuffer(1))) != dataViewTag$2) ||
+ (Map$2 && getTag(new Map$2) != mapTag$2) ||
+ (Promise$2 && getTag(Promise$2.resolve()) != promiseTag) ||
+ (Set$2 && getTag(new Set$2) != setTag$2) ||
+ (WeakMap$1 && getTag(new WeakMap$1) != weakMapTag$1)) {
+ getTag = function(value) {
+ var result = baseGetTag(value),
+ Ctor = result == objectTag$1 ? value.constructor : undefined,
+ ctorString = Ctor ? toSource(Ctor) : '';
+
+ if (ctorString) {
+ switch (ctorString) {
+ case dataViewCtorString: return dataViewTag$2;
+ case mapCtorString: return mapTag$2;
+ case promiseCtorString: return promiseTag;
+ case setCtorString: return setTag$2;
+ case weakMapCtorString: return weakMapTag$1;
+ }
+ }
+ return result;
+ };
+ }
+
+ var getTag$1 = getTag;
+
+ /** Used to compose bitmasks for value comparisons. */
+ var COMPARE_PARTIAL_FLAG$3 = 1;
+
+ /** `Object#toString` result references. */
+ var argsTag$2 = '[object Arguments]',
+ arrayTag$1 = '[object Array]',
+ objectTag$2 = '[object Object]';
+
+ /** Used for built-in method references. */
+ var objectProto$b = Object.prototype;
+
+ /** Used to check objects for own properties. */
+ var hasOwnProperty$a = objectProto$b.hasOwnProperty;
+
+ /**
+ * 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$5(object),
+ othIsArr = isArray$5(other),
+ objTag = objIsArr ? arrayTag$1 : getTag$1(object),
+ othTag = othIsArr ? arrayTag$1 : getTag$1(other);
+
+ objTag = objTag == argsTag$2 ? objectTag$2 : objTag;
+ othTag = othTag == argsTag$2 ? objectTag$2 : othTag;
+
+ var objIsObj = objTag == objectTag$2,
+ othIsObj = othTag == objectTag$2,
+ 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$3)) {
+ var objIsWrapped = objIsObj && hasOwnProperty$a.call(object, '__wrapped__'),
+ othIsWrapped = othIsObj && hasOwnProperty$a.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 `_.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);
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * A specialized version of `_.map` for arrays without support for iteratee
+ * shorthands.
+ *
+ * @private
+ * @param {Array} [array] The array to iterate over.
+ * @param {Function} iteratee The function invoked per iteration.
+ * @returns {Array} Returns the new mapped array.
+ */
+ function arrayMap(array, iteratee) {
+ var index = -1,
+ length = array == null ? 0 : array.length,
+ result = Array(length);
+
+ while (++index < length) {
+ result[index] = iteratee(array[index], index, array);
+ }
+ return result;
+ }
+
+ /**
+ * A specialized version of `_.forEach` for arrays without support for
+ * iteratee shorthands.
+ *
+ * @private
+ * @param {Array} [array] The array to iterate over.
+ * @param {Function} iteratee The function invoked per iteration.
+ * @returns {Array} Returns `array`.
+ */
+ function arrayEach(array, iteratee) {
+ var index = -1,
+ length = array == null ? 0 : array.length;
+
+ while (++index < length) {
+ if (iteratee(array[index], index, array) === false) {
+ break;
+ }
+ }
+ return array;
+ }
+
+ var defineProperty$9 = (function() {
+ try {
+ var func = getNative(Object, 'defineProperty');
+ func({}, '', {});
+ return func;
+ } catch (e) {}
+ }());
+
+ /**
+ * The base implementation of `assignValue` and `assignMergeValue` without
+ * value checks.
+ *
+ * @private
+ * @param {Object} object The object to modify.
+ * @param {string} key The key of the property to assign.
+ * @param {*} value The value to assign.
+ */
+ function baseAssignValue(object, key, value) {
+ if (key == '__proto__' && defineProperty$9) {
+ defineProperty$9(object, key, {
+ 'configurable': true,
+ 'enumerable': true,
+ 'value': value,
+ 'writable': true
+ });
+ } else {
+ object[key] = value;
+ }
+ }
+
+ /** Used for built-in method references. */
+ var objectProto$c = Object.prototype;
+
+ /** Used to check objects for own properties. */
+ var hasOwnProperty$b = objectProto$c.hasOwnProperty;
+
+ /**
+ * Assigns `value` to `key` of `object` if the existing value is not equivalent
+ * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
+ * for equality comparisons.
+ *
+ * @private
+ * @param {Object} object The object to modify.
+ * @param {string} key The key of the property to assign.
+ * @param {*} value The value to assign.
+ */
+ function assignValue(object, key, value) {
+ var objValue = object[key];
+ if (!(hasOwnProperty$b.call(object, key) && eq(objValue, value)) ||
+ (value === undefined && !(key in object))) {
+ baseAssignValue(object, key, value);
+ }
+ }
+
+ /**
+ * Copies properties of `source` to `object`.
+ *
+ * @private
+ * @param {Object} source The object to copy properties from.
+ * @param {Array} props The property identifiers to copy.
+ * @param {Object} [object={}] The object to copy properties to.
+ * @param {Function} [customizer] The function to customize copied values.
+ * @returns {Object} Returns `object`.
+ */
+ function copyObject(source, props, object, customizer) {
+ var isNew = !object;
+ object || (object = {});
+
+ var index = -1,
+ length = props.length;
+
+ while (++index < length) {
+ var key = props[index];
+
+ var newValue = customizer
+ ? customizer(object[key], source[key], key, object, source)
+ : undefined;
+
+ if (newValue === undefined) {
+ newValue = source[key];
+ }
+ if (isNew) {
+ baseAssignValue(object, key, newValue);
+ } else {
+ assignValue(object, key, newValue);
+ }
+ }
+ return object;
+ }
+
+ /**
+ * The base implementation of `_.assign` without support for multiple sources
+ * or `customizer` functions.
+ *
+ * @private
+ * @param {Object} object The destination object.
+ * @param {Object} source The source object.
+ * @returns {Object} Returns `object`.
+ */
+ function baseAssign(object, source) {
+ return object && copyObject(source, keys$3(source), object);
+ }
+
+ /**
+ * This function is like
+ * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
+ * except that it includes inherited enumerable properties.
+ *
+ * @private
+ * @param {Object} object The object to query.
+ * @returns {Array} Returns the array of property names.
+ */
+ function nativeKeysIn(object) {
+ var result = [];
+ if (object != null) {
+ for (var key in Object(object)) {
+ result.push(key);
+ }
+ }
+ return result;
+ }
+
+ /** Used for built-in method references. */
+ var objectProto$d = Object.prototype;
+
+ /** Used to check objects for own properties. */
+ var hasOwnProperty$c = objectProto$d.hasOwnProperty;
+
+ /**
+ * The base implementation of `_.keysIn` 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 baseKeysIn(object) {
+ if (!isObject$1(object)) {
+ return nativeKeysIn(object);
+ }
+ var isProto = isPrototype(object),
+ result = [];
+
+ for (var key in object) {
+ if (!(key == 'constructor' && (isProto || !hasOwnProperty$c.call(object, key)))) {
+ result.push(key);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Creates an array of the own and inherited enumerable property names of `object`.
+ *
+ * **Note:** Non-object values are coerced to objects.
+ *
+ * @static
+ * @memberOf _
+ * @since 3.0.0
+ * @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;
+ *
+ * _.keysIn(new Foo);
+ * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
+ */
+ function keysIn$1(object) {
+ return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
+ }
+
+ /**
+ * The base implementation of `_.assignIn` without support for multiple sources
+ * or `customizer` functions.
+ *
+ * @private
+ * @param {Object} object The destination object.
+ * @param {Object} source The source object.
+ * @returns {Object} Returns `object`.
+ */
+ function baseAssignIn(object, source) {
+ return object && copyObject(source, keysIn$1(source), object);
+ }
+
+ /** Detect free variable `exports`. */
+ var freeExports$2 = typeof exports == 'object' && exports && !exports.nodeType && exports;
+
+ /** Detect free variable `module`. */
+ var freeModule$2 = freeExports$2 && typeof module == 'object' && module && !module.nodeType && module;
+
+ /** Detect the popular CommonJS extension `module.exports`. */
+ var moduleExports$2 = freeModule$2 && freeModule$2.exports === freeExports$2;
+
+ /** Built-in value references. */
+ var Buffer$1 = moduleExports$2 ? root$2.Buffer : undefined,
+ allocUnsafe = Buffer$1 ? Buffer$1.allocUnsafe : undefined;
+
+ /**
+ * Creates a clone of `buffer`.
+ *
+ * @private
+ * @param {Buffer} buffer The buffer to clone.
+ * @param {boolean} [isDeep] Specify a deep clone.
+ * @returns {Buffer} Returns the cloned buffer.
+ */
+ function cloneBuffer(buffer, isDeep) {
+ if (isDeep) {
+ return buffer.slice();
+ }
+ var length = buffer.length,
+ result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
+
+ buffer.copy(result);
+ return result;
+ }
+
+ /**
+ * Copies the values of `source` to `array`.
+ *
+ * @private
+ * @param {Array} source The array to copy values from.
+ * @param {Array} [array=[]] The array to copy values to.
+ * @returns {Array} Returns `array`.
+ */
+ function copyArray(source, array) {
+ var index = -1,
+ length = source.length;
+
+ array || (array = Array(length));
+ while (++index < length) {
+ array[index] = source[index];
+ }
+ return array;
+ }
+
+ /**
+ * Copies own symbols of `source` to `object`.
+ *
+ * @private
+ * @param {Object} source The object to copy symbols from.
+ * @param {Object} [object={}] The object to copy symbols to.
+ * @returns {Object} Returns `object`.
+ */
+ function copySymbols(source, object) {
+ return copyObject(source, getSymbols(source), object);
+ }
+
+ /** Built-in value references. */
+ var getPrototype = overArg(Object.getPrototypeOf, Object);
+
+ /* Built-in method references for those with the same name as other `lodash` methods. */
+ var nativeGetSymbols$1 = Object.getOwnPropertySymbols;
+
+ /**
+ * Creates an array of the own and inherited enumerable symbols of `object`.
+ *
+ * @private
+ * @param {Object} object The object to query.
+ * @returns {Array} Returns the array of symbols.
+ */
+ var getSymbolsIn = !nativeGetSymbols$1 ? stubArray : function(object) {
+ var result = [];
+ while (object) {
+ arrayPush(result, getSymbols(object));
+ object = getPrototype(object);
+ }
+ return result;
+ };
+
+ /**
+ * Copies own and inherited symbols of `source` to `object`.
+ *
+ * @private
+ * @param {Object} source The object to copy symbols from.
+ * @param {Object} [object={}] The object to copy symbols to.
+ * @returns {Object} Returns `object`.
+ */
+ function copySymbolsIn(source, object) {
+ return copyObject(source, getSymbolsIn(source), object);
+ }
+
+ /**
+ * Creates an array of own and inherited 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 getAllKeysIn(object) {
+ return baseGetAllKeys(object, keysIn$1, getSymbolsIn);
+ }
+
+ /** Used for built-in method references. */
+ var objectProto$e = Object.prototype;
+
+ /** Used to check objects for own properties. */
+ var hasOwnProperty$d = objectProto$e.hasOwnProperty;
+
+ /**
+ * Initializes an array clone.
+ *
+ * @private
+ * @param {Array} array The array to clone.
+ * @returns {Array} Returns the initialized clone.
+ */
+ function initCloneArray(array) {
+ var length = array.length,
+ result = new array.constructor(length);
+
+ // Add properties assigned by `RegExp#exec`.
+ if (length && typeof array[0] == 'string' && hasOwnProperty$d.call(array, 'index')) {
+ result.index = array.index;
+ result.input = array.input;
+ }
+ return result;
+ }
+
+ /**
+ * Creates a clone of `arrayBuffer`.
+ *
+ * @private
+ * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
+ * @returns {ArrayBuffer} Returns the cloned array buffer.
+ */
+ function cloneArrayBuffer(arrayBuffer) {
+ var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
+ new Uint8Array$1(result).set(new Uint8Array$1(arrayBuffer));
+ return result;
+ }
+
+ /**
+ * Creates a clone of `dataView`.
+ *
+ * @private
+ * @param {Object} dataView The data view to clone.
+ * @param {boolean} [isDeep] Specify a deep clone.
+ * @returns {Object} Returns the cloned data view.
+ */
+ function cloneDataView(dataView, isDeep) {
+ var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
+ return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
+ }
+
+ /** Used to match `RegExp` flags from their coerced string values. */
+ var reFlags = /\w*$/;
+
+ /**
+ * Creates a clone of `regexp`.
+ *
+ * @private
+ * @param {Object} regexp The regexp to clone.
+ * @returns {Object} Returns the cloned regexp.
+ */
+ function cloneRegExp(regexp) {
+ var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
+ result.lastIndex = regexp.lastIndex;
+ return result;
+ }
+
+ /** Used to convert symbols to primitives and strings. */
+ var symbolProto$1 = Symbol$1 ? Symbol$1.prototype : undefined,
+ symbolValueOf$1 = symbolProto$1 ? symbolProto$1.valueOf : undefined;
+
+ /**
+ * Creates a clone of the `symbol` object.
+ *
+ * @private
+ * @param {Object} symbol The symbol object to clone.
+ * @returns {Object} Returns the cloned symbol object.
+ */
+ function cloneSymbol(symbol) {
+ return symbolValueOf$1 ? Object(symbolValueOf$1.call(symbol)) : {};
+ }
+
+ /**
+ * Creates a clone of `typedArray`.
+ *
+ * @private
+ * @param {Object} typedArray The typed array to clone.
+ * @param {boolean} [isDeep] Specify a deep clone.
+ * @returns {Object} Returns the cloned typed array.
+ */
+ function cloneTypedArray(typedArray, isDeep) {
+ var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
+ return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
+ }
+
+ /** `Object#toString` result references. */
+ var boolTag$2 = '[object Boolean]',
+ dateTag$2 = '[object Date]',
+ mapTag$3 = '[object Map]',
+ numberTag$2 = '[object Number]',
+ regexpTag$2 = '[object RegExp]',
+ setTag$3 = '[object Set]',
+ stringTag$2 = '[object String]',
+ symbolTag$2 = '[object Symbol]';
+
+ var arrayBufferTag$2 = '[object ArrayBuffer]',
+ dataViewTag$3 = '[object DataView]',
+ float32Tag$1 = '[object Float32Array]',
+ float64Tag$1 = '[object Float64Array]',
+ int8Tag$1 = '[object Int8Array]',
+ int16Tag$1 = '[object Int16Array]',
+ int32Tag$1 = '[object Int32Array]',
+ uint8Tag$1 = '[object Uint8Array]',
+ uint8ClampedTag$1 = '[object Uint8ClampedArray]',
+ uint16Tag$1 = '[object Uint16Array]',
+ uint32Tag$1 = '[object Uint32Array]';
+
+ /**
+ * Initializes an object clone based on its `toStringTag`.
+ *
+ * **Note:** This function only supports cloning values with tags of
+ * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
+ *
+ * @private
+ * @param {Object} object The object to clone.
+ * @param {string} tag The `toStringTag` of the object to clone.
+ * @param {boolean} [isDeep] Specify a deep clone.
+ * @returns {Object} Returns the initialized clone.
+ */
+ function initCloneByTag(object, tag, isDeep) {
+ var Ctor = object.constructor;
+ switch (tag) {
+ case arrayBufferTag$2:
+ return cloneArrayBuffer(object);
+
+ case boolTag$2:
+ case dateTag$2:
+ return new Ctor(+object);
+
+ case dataViewTag$3:
+ return cloneDataView(object, isDeep);
+
+ case float32Tag$1: case float64Tag$1:
+ case int8Tag$1: case int16Tag$1: case int32Tag$1:
+ case uint8Tag$1: case uint8ClampedTag$1: case uint16Tag$1: case uint32Tag$1:
+ return cloneTypedArray(object, isDeep);
+
+ case mapTag$3:
+ return new Ctor;
+
+ case numberTag$2:
+ case stringTag$2:
+ return new Ctor(object);
+
+ case regexpTag$2:
+ return cloneRegExp(object);
+
+ case setTag$3:
+ return new Ctor;
+
+ case symbolTag$2:
+ return cloneSymbol(object);
+ }
+ }
+
+ /** Built-in value references. */
+ var objectCreate = Object.create;
+
+ /**
+ * The base implementation of `_.create` without support for assigning
+ * properties to the created object.
+ *
+ * @private
+ * @param {Object} proto The object to inherit from.
+ * @returns {Object} Returns the new object.
+ */
+ var baseCreate = (function() {
+ function object() {}
+ return function(proto) {
+ if (!isObject$1(proto)) {
+ return {};
+ }
+ if (objectCreate) {
+ return objectCreate(proto);
+ }
+ object.prototype = proto;
+ var result = new object;
+ object.prototype = undefined;
+ return result;
+ };
+ }());
+
+ /**
+ * Initializes an object clone.
+ *
+ * @private
+ * @param {Object} object The object to clone.
+ * @returns {Object} Returns the initialized clone.
+ */
+ function initCloneObject(object) {
+ return (typeof object.constructor == 'function' && !isPrototype(object))
+ ? baseCreate(getPrototype(object))
+ : {};
+ }
+
+ /** `Object#toString` result references. */
+ var mapTag$4 = '[object Map]';
+
+ /**
+ * The base implementation of `_.isMap` without Node.js optimizations.
+ *
+ * @private
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is a map, else `false`.
+ */
+ function baseIsMap(value) {
+ return isObjectLike(value) && getTag$1(value) == mapTag$4;
+ }
+
+ /* Node.js helper references. */
+ var nodeIsMap = nodeUtil && nodeUtil.isMap;
+
+ /**
+ * Checks if `value` is classified as a `Map` object.
+ *
+ * @static
+ * @memberOf _
+ * @since 4.3.0
+ * @category Lang
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is a map, else `false`.
+ * @example
+ *
+ * _.isMap(new Map);
+ * // => true
+ *
+ * _.isMap(new WeakMap);
+ * // => false
+ */
+ var isMap$1 = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
+
+ /** `Object#toString` result references. */
+ var setTag$4 = '[object Set]';
+
+ /**
+ * The base implementation of `_.isSet` without Node.js optimizations.
+ *
+ * @private
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is a set, else `false`.
+ */
+ function baseIsSet(value) {
+ return isObjectLike(value) && getTag$1(value) == setTag$4;
+ }
+
+ /* Node.js helper references. */
+ var nodeIsSet = nodeUtil && nodeUtil.isSet;
+
+ /**
+ * Checks if `value` is classified as a `Set` object.
+ *
+ * @static
+ * @memberOf _
+ * @since 4.3.0
+ * @category Lang
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is a set, else `false`.
+ * @example
+ *
+ * _.isSet(new Set);
+ * // => true
+ *
+ * _.isSet(new WeakSet);
+ * // => false
+ */
+ var isSet$1 = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
+
+ /** Used to compose bitmasks for cloning. */
+ var CLONE_DEEP_FLAG = 1,
+ CLONE_FLAT_FLAG = 2,
+ CLONE_SYMBOLS_FLAG = 4;
+
+ /** `Object#toString` result references. */
+ var argsTag$3 = '[object Arguments]',
+ arrayTag$2 = '[object Array]',
+ boolTag$3 = '[object Boolean]',
+ dateTag$3 = '[object Date]',
+ errorTag$2 = '[object Error]',
+ funcTag$2 = '[object Function]',
+ genTag$1 = '[object GeneratorFunction]',
+ mapTag$5 = '[object Map]',
+ numberTag$3 = '[object Number]',
+ objectTag$3 = '[object Object]',
+ regexpTag$3 = '[object RegExp]',
+ setTag$5 = '[object Set]',
+ stringTag$3 = '[object String]',
+ symbolTag$3 = '[object Symbol]',
+ weakMapTag$2 = '[object WeakMap]';
+
+ var arrayBufferTag$3 = '[object ArrayBuffer]',
+ dataViewTag$4 = '[object DataView]',
+ float32Tag$2 = '[object Float32Array]',
+ float64Tag$2 = '[object Float64Array]',
+ int8Tag$2 = '[object Int8Array]',
+ int16Tag$2 = '[object Int16Array]',
+ int32Tag$2 = '[object Int32Array]',
+ uint8Tag$2 = '[object Uint8Array]',
+ uint8ClampedTag$2 = '[object Uint8ClampedArray]',
+ uint16Tag$2 = '[object Uint16Array]',
+ uint32Tag$2 = '[object Uint32Array]';
+
+ /** Used to identify `toStringTag` values supported by `_.clone`. */
+ var cloneableTags = {};
+ cloneableTags[argsTag$3] = cloneableTags[arrayTag$2] =
+ cloneableTags[arrayBufferTag$3] = cloneableTags[dataViewTag$4] =
+ cloneableTags[boolTag$3] = cloneableTags[dateTag$3] =
+ cloneableTags[float32Tag$2] = cloneableTags[float64Tag$2] =
+ cloneableTags[int8Tag$2] = cloneableTags[int16Tag$2] =
+ cloneableTags[int32Tag$2] = cloneableTags[mapTag$5] =
+ cloneableTags[numberTag$3] = cloneableTags[objectTag$3] =
+ cloneableTags[regexpTag$3] = cloneableTags[setTag$5] =
+ cloneableTags[stringTag$3] = cloneableTags[symbolTag$3] =
+ cloneableTags[uint8Tag$2] = cloneableTags[uint8ClampedTag$2] =
+ cloneableTags[uint16Tag$2] = cloneableTags[uint32Tag$2] = true;
+ cloneableTags[errorTag$2] = cloneableTags[funcTag$2] =
+ cloneableTags[weakMapTag$2] = false;
+
+ /**
+ * The base implementation of `_.clone` and `_.cloneDeep` which tracks
+ * traversed objects.
+ *
+ * @private
+ * @param {*} value The value to clone.
+ * @param {boolean} bitmask The bitmask flags.
+ * 1 - Deep clone
+ * 2 - Flatten inherited properties
+ * 4 - Clone symbols
+ * @param {Function} [customizer] The function to customize cloning.
+ * @param {string} [key] The key of `value`.
+ * @param {Object} [object] The parent object of `value`.
+ * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
+ * @returns {*} Returns the cloned value.
+ */
+ function baseClone(value, bitmask, customizer, key, object, stack) {
+ var result,
+ isDeep = bitmask & CLONE_DEEP_FLAG,
+ isFlat = bitmask & CLONE_FLAT_FLAG,
+ isFull = bitmask & CLONE_SYMBOLS_FLAG;
+
+ if (customizer) {
+ result = object ? customizer(value, key, object, stack) : customizer(value);
+ }
+ if (result !== undefined) {
+ return result;
+ }
+ if (!isObject$1(value)) {
+ return value;
+ }
+ var isArr = isArray$5(value);
+ if (isArr) {
+ result = initCloneArray(value);
+ if (!isDeep) {
+ return copyArray(value, result);
+ }
+ } else {
+ var tag = getTag$1(value),
+ isFunc = tag == funcTag$2 || tag == genTag$1;
+
+ if (isBuffer(value)) {
+ return cloneBuffer(value, isDeep);
+ }
+ if (tag == objectTag$3 || tag == argsTag$3 || (isFunc && !object)) {
+ result = (isFlat || isFunc) ? {} : initCloneObject(value);
+ if (!isDeep) {
+ return isFlat
+ ? copySymbolsIn(value, baseAssignIn(result, value))
+ : copySymbols(value, baseAssign(result, value));
+ }
+ } else {
+ if (!cloneableTags[tag]) {
+ return object ? value : {};
+ }
+ result = initCloneByTag(value, tag, isDeep);
+ }
+ }
+ // Check for circular references and return its corresponding clone.
+ stack || (stack = new Stack);
+ var stacked = stack.get(value);
+ if (stacked) {
+ return stacked;
+ }
+ stack.set(value, result);
+
+ if (isSet$1(value)) {
+ value.forEach(function(subValue) {
+ result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
+ });
+ } else if (isMap$1(value)) {
+ value.forEach(function(subValue, key) {
+ result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
+ });
+ }
+
+ var keysFunc = isFull
+ ? (isFlat ? getAllKeysIn : getAllKeys)
+ : (isFlat ? keysIn : keys$3);
+
+ var props = isArr ? undefined : keysFunc(value);
+ arrayEach(props || value, function(subValue, key) {
+ if (props) {
+ key = subValue;
+ subValue = value[key];
+ }
+ // Recursively populate clone (susceptible to call stack limits).
+ assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
+ });
+ return result;
+ }
+
+ /** Used to match property names within property paths. */
+ var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
+ reIsPlainProp = /^\w*$/;
+
+ /**
+ * Checks if `value` is a property name and not a property path.
+ *
+ * @private
+ * @param {*} value The value to check.
+ * @param {Object} [object] The object to query keys on.
+ * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
+ */
+ function isKey(value, object) {
+ if (isArray$5(value)) {
+ return false;
+ }
+ var type = typeof value;
+ if (type == 'number' || type == 'symbol' || type == 'boolean' ||
+ value == null || isSymbol$4(value)) {
+ return true;
+ }
+ return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
+ (object != null && value in Object(object));
+ }
+
+ /** Error message constants. */
+ var FUNC_ERROR_TEXT$2 = 'Expected a function';
+
+ /**
+ * Creates a function that memoizes the result of `func`. If `resolver` is
+ * provided, it determines the cache key for storing the result based on the
+ * arguments provided to the memoized function. By default, the first argument
+ * provided to the memoized function is used as the map cache key. The `func`
+ * is invoked with the `this` binding of the memoized function.
+ *
+ * **Note:** The cache is exposed as the `cache` property on the memoized
+ * function. Its creation may be customized by replacing the `_.memoize.Cache`
+ * constructor with one whose instances implement the
+ * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
+ * method interface of `clear`, `delete`, `get`, `has`, and `set`.
+ *
+ * @static
+ * @memberOf _
+ * @since 0.1.0
+ * @category Function
+ * @param {Function} func The function to have its output memoized.
+ * @param {Function} [resolver] The function to resolve the cache key.
+ * @returns {Function} Returns the new memoized function.
+ * @example
+ *
+ * var object = { 'a': 1, 'b': 2 };
+ * var other = { 'c': 3, 'd': 4 };
+ *
+ * var values = _.memoize(_.values);
+ * values(object);
+ * // => [1, 2]
+ *
+ * values(other);
+ * // => [3, 4]
+ *
+ * object.a = 2;
+ * values(object);
+ * // => [1, 2]
+ *
+ * // Modify the result cache.
+ * values.cache.set(object, ['a', 'b']);
+ * values(object);
+ * // => ['a', 'b']
+ *
+ * // Replace `_.memoize.Cache`.
+ * _.memoize.Cache = WeakMap;
+ */
+ function memoize(func, resolver) {
+ if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
+ throw new TypeError(FUNC_ERROR_TEXT$2);
+ }
+ var memoized = function() {
+ var args = arguments,
+ key = resolver ? resolver.apply(this, args) : args[0],
+ cache = memoized.cache;
+
+ if (cache.has(key)) {
+ return cache.get(key);
+ }
+ var result = func.apply(this, args);
+ memoized.cache = cache.set(key, result) || cache;
+ return result;
+ };
+ memoized.cache = new (memoize.Cache || MapCache);
+ return memoized;
+ }
+
+ // Expose `MapCache`.
+ memoize.Cache = MapCache;
+
+ /** Used as the maximum memoize cache size. */
+ var MAX_MEMOIZE_SIZE = 500;
+
+ /**
+ * A specialized version of `_.memoize` which clears the memoized function's
+ * cache when it exceeds `MAX_MEMOIZE_SIZE`.
+ *
+ * @private
+ * @param {Function} func The function to have its output memoized.
+ * @returns {Function} Returns the new memoized function.
+ */
+ function memoizeCapped(func) {
+ var result = memoize(func, function(key) {
+ if (cache.size === MAX_MEMOIZE_SIZE) {
+ cache.clear();
+ }
+ return key;
+ });
+
+ var cache = result.cache;
+ return result;
+ }
+
+ /** Used to match property names within property paths. */
+ var rePropName$2 = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
+
+ /** Used to match backslashes in property paths. */
+ var reEscapeChar$2 = /\\(\\)?/g;
+
+ /**
+ * Converts `string` to a property path array.
+ *
+ * @private
+ * @param {string} string The string to convert.
+ * @returns {Array} Returns the property path array.
+ */
+ var stringToPath$2 = memoizeCapped(function(string) {
+ var result = [];
+ if (string.charCodeAt(0) === 46 /* . */) {
+ result.push('');
+ }
+ string.replace(rePropName$2, function(match, number, quote, subString) {
+ result.push(quote ? subString.replace(reEscapeChar$2, '$1') : (number || match));
+ });
+ return result;
+ });
+
+ /** Used as references for various `Number` constants. */
+ var INFINITY = 1 / 0;
+
+ /** Used to convert symbols to primitives and strings. */
+ var symbolProto$2 = Symbol$1 ? Symbol$1.prototype : undefined,
+ symbolToString = symbolProto$2 ? symbolProto$2.toString : undefined;
+
+ /**
+ * The base implementation of `_.toString` which doesn't convert nullish
+ * values to empty strings.
+ *
+ * @private
+ * @param {*} value The value to process.
+ * @returns {string} Returns the string.
+ */
+ function baseToString(value) {
+ // Exit early for strings to avoid a performance hit in some environments.
+ if (typeof value == 'string') {
+ return value;
+ }
+ if (isArray$5(value)) {
+ // Recursively convert values (susceptible to call stack limits).
+ return arrayMap(value, baseToString) + '';
+ }
+ if (isSymbol$4(value)) {
+ return symbolToString ? symbolToString.call(value) : '';
+ }
+ var result = (value + '');
+ return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
+ }
+
+ /**
+ * Converts `value` to a string. An empty string is returned for `null`
+ * and `undefined` values. The sign of `-0` is preserved.
+ *
+ * @static
+ * @memberOf _
+ * @since 4.0.0
+ * @category Lang
+ * @param {*} value The value to convert.
+ * @returns {string} Returns the converted string.
+ * @example
+ *
+ * _.toString(null);
+ * // => ''
+ *
+ * _.toString(-0);
+ * // => '-0'
+ *
+ * _.toString([1, 2, 3]);
+ * // => '1,2,3'
+ */
+ function toString(value) {
+ return value == null ? '' : baseToString(value);
+ }
+
+ /**
+ * Casts `value` to a path array if it's not one.
+ *
+ * @private
+ * @param {*} value The value to inspect.
+ * @param {Object} [object] The object to query keys on.
+ * @returns {Array} Returns the cast property path array.
+ */
+ function castPath(value, object) {
+ if (isArray$5(value)) {
+ return value;
+ }
+ return isKey(value, object) ? [value] : stringToPath$2(toString(value));
+ }
+
+ /**
+ * Gets the last element of `array`.
+ *
+ * @static
+ * @memberOf _
+ * @since 0.1.0
+ * @category Array
+ * @param {Array} array The array to query.
+ * @returns {*} Returns the last element of `array`.
+ * @example
+ *
+ * _.last([1, 2, 3]);
+ * // => 3
+ */
+ function last$1(array) {
+ var length = array == null ? 0 : array.length;
+ return length ? array[length - 1] : undefined;
+ }
+
+ /** Used as references for various `Number` constants. */
+ var INFINITY$1 = 1 / 0;
+
+ /**
+ * Converts `value` to a string key if it's not a string or symbol.
+ *
+ * @private
+ * @param {*} value The value to inspect.
+ * @returns {string|symbol} Returns the key.
+ */
+ function toKey(value) {
+ if (typeof value == 'string' || isSymbol$4(value)) {
+ return value;
+ }
+ var result = (value + '');
+ return (result == '0' && (1 / value) == -INFINITY$1) ? '-0' : result;
+ }
+
+ /**
+ * The base implementation of `_.get` without support for default values.
+ *
+ * @private
+ * @param {Object} object The object to query.
+ * @param {Array|string} path The path of the property to get.
+ * @returns {*} Returns the resolved value.
+ */
+ function baseGet(object, path) {
+ path = castPath(path, object);
+
+ var index = 0,
+ length = path.length;
+
+ while (object != null && index < length) {
+ object = object[toKey(path[index++])];
+ }
+ return (index && index == length) ? object : undefined;
+ }
+
+ /**
+ * The base implementation of `_.slice` without an iteratee call guard.
+ *
+ * @private
+ * @param {Array} array The array to slice.
+ * @param {number} [start=0] The start position.
+ * @param {number} [end=array.length] The end position.
+ * @returns {Array} Returns the slice of `array`.
+ */
+ function baseSlice(array, start, end) {
+ var index = -1,
+ length = array.length;
+
+ if (start < 0) {
+ start = -start > length ? 0 : (length + start);
+ }
+ end = end > length ? length : end;
+ if (end < 0) {
+ end += length;
+ }
+ length = start > end ? 0 : ((end - start) >>> 0);
+ start >>>= 0;
+
+ var result = Array(length);
+ while (++index < length) {
+ result[index] = array[index + start];
+ }
+ return result;
+ }
+
+ /**
+ * Gets the parent value at `path` of `object`.
+ *
+ * @private
+ * @param {Object} object The object to query.
+ * @param {Array} path The path to get the parent value of.
+ * @returns {*} Returns the parent value.
+ */
+ function parent(object, path) {
+ return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
+ }
+
+ /**
+ * The base implementation of `_.unset`.
+ *
+ * @private
+ * @param {Object} object The object to modify.
+ * @param {Array|string} path The property path to unset.
+ * @returns {boolean} Returns `true` if the property is deleted, else `false`.
+ */
+ function baseUnset(object, path) {
+ path = castPath(path, object);
+ object = parent(object, path);
+ return object == null || delete object[toKey(last$1(path))];
+ }
+
+ /** `Object#toString` result references. */
+ var objectTag$4 = '[object Object]';
+
+ /** Used for built-in method references. */
+ var funcProto$2 = Function.prototype,
+ objectProto$f = Object.prototype;
+
+ /** Used to resolve the decompiled source of functions. */
+ var funcToString$2 = funcProto$2.toString;
+
+ /** Used to check objects for own properties. */
+ var hasOwnProperty$e = objectProto$f.hasOwnProperty;
+
+ /** Used to infer the `Object` constructor. */
+ var objectCtorString = funcToString$2.call(Object);
+
+ /**
+ * Checks if `value` is a plain object, that is, an object created by the
+ * `Object` constructor or one with a `[[Prototype]]` of `null`.
+ *
+ * @static
+ * @memberOf _
+ * @since 0.8.0
+ * @category Lang
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
+ * @example
+ *
+ * function Foo() {
+ * this.a = 1;
+ * }
+ *
+ * _.isPlainObject(new Foo);
+ * // => false
+ *
+ * _.isPlainObject([1, 2, 3]);
+ * // => false
+ *
+ * _.isPlainObject({ 'x': 0, 'y': 0 });
+ * // => true
+ *
+ * _.isPlainObject(Object.create(null));
+ * // => true
+ */
+ function isPlainObject(value) {
+ if (!isObjectLike(value) || baseGetTag(value) != objectTag$4) {
+ return false;
+ }
+ var proto = getPrototype(value);
+ if (proto === null) {
+ return true;
+ }
+ var Ctor = hasOwnProperty$e.call(proto, 'constructor') && proto.constructor;
+ return typeof Ctor == 'function' && Ctor instanceof Ctor &&
+ funcToString$2.call(Ctor) == objectCtorString;
+ }
+
+ /**
+ * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
+ * objects.
+ *
+ * @private
+ * @param {*} value The value to inspect.
+ * @param {string} key The key of the property to inspect.
+ * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
+ */
+ function customOmitClone(value) {
+ return isPlainObject(value) ? undefined : value;
+ }
+
+ /** Built-in value references. */
+ var spreadableSymbol = Symbol$1 ? Symbol$1.isConcatSpreadable : undefined;
+
+ /**
+ * Checks if `value` is a flattenable `arguments` object or array.
+ *
+ * @private
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
+ */
+ function isFlattenable(value) {
+ return isArray$5(value) || isArguments$2(value) ||
+ !!(spreadableSymbol && value && value[spreadableSymbol]);
+ }
+
+ /**
+ * The base implementation of `_.flatten` with support for restricting flattening.
+ *
+ * @private
+ * @param {Array} array The array to flatten.
+ * @param {number} depth The maximum recursion depth.
+ * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
+ * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
+ * @param {Array} [result=[]] The initial result value.
+ * @returns {Array} Returns the new flattened array.
+ */
+ function baseFlatten(array, depth, predicate, isStrict, result) {
+ var index = -1,
+ length = array.length;
+
+ predicate || (predicate = isFlattenable);
+ result || (result = []);
+
+ while (++index < length) {
+ var value = array[index];
+ if (depth > 0 && predicate(value)) {
+ if (depth > 1) {
+ // Recursively flatten arrays (susceptible to call stack limits).
+ baseFlatten(value, depth - 1, predicate, isStrict, result);
+ } else {
+ arrayPush(result, value);
+ }
+ } else if (!isStrict) {
+ result[result.length] = value;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Flattens `array` a single level deep.
+ *
+ * @static
+ * @memberOf _
+ * @since 0.1.0
+ * @category Array
+ * @param {Array} array The array to flatten.
+ * @returns {Array} Returns the new flattened array.
+ * @example
+ *
+ * _.flatten([1, [2, [3, [4]], 5]]);
+ * // => [1, 2, [3, [4]], 5]
+ */
+ function flatten(array) {
+ var length = array == null ? 0 : array.length;
+ return length ? baseFlatten(array, 1) : [];
+ }
+
+ /**
+ * A faster alternative to `Function#apply`, this function invokes `func`
+ * with the `this` binding of `thisArg` and the arguments of `args`.
+ *
+ * @private
+ * @param {Function} func The function to invoke.
+ * @param {*} thisArg The `this` binding of `func`.
+ * @param {Array} args The arguments to invoke `func` with.
+ * @returns {*} Returns the result of `func`.
+ */
+ function apply$1(func, thisArg, args) {
+ switch (args.length) {
+ case 0: return func.call(thisArg);
+ case 1: return func.call(thisArg, args[0]);
+ case 2: return func.call(thisArg, args[0], args[1]);
+ case 3: return func.call(thisArg, args[0], args[1], args[2]);
+ }
+ return func.apply(thisArg, args);
+ }
+
+ /* Built-in method references for those with the same name as other `lodash` methods. */
+ var nativeMax$1 = Math.max;
+
+ /**
+ * A specialized version of `baseRest` which transforms the rest array.
+ *
+ * @private
+ * @param {Function} func The function to apply a rest parameter to.
+ * @param {number} [start=func.length-1] The start position of the rest parameter.
+ * @param {Function} transform The rest array transform.
+ * @returns {Function} Returns the new function.
+ */
+ function overRest(func, start, transform) {
+ start = nativeMax$1(start === undefined ? (func.length - 1) : start, 0);
+ return function() {
+ var args = arguments,
+ index = -1,
+ length = nativeMax$1(args.length - start, 0),
+ array = Array(length);
+
+ while (++index < length) {
+ array[index] = args[start + index];
+ }
+ index = -1;
+ var otherArgs = Array(start + 1);
+ while (++index < start) {
+ otherArgs[index] = args[index];
+ }
+ otherArgs[start] = transform(array);
+ return apply$1(func, this, otherArgs);
+ };
+ }
+
+ /**
+ * Creates a function that returns `value`.
+ *
+ * @static
+ * @memberOf _
+ * @since 2.4.0
+ * @category Util
+ * @param {*} value The value to return from the new function.
+ * @returns {Function} Returns the new constant function.
+ * @example
+ *
+ * var objects = _.times(2, _.constant({ 'a': 1 }));
+ *
+ * console.log(objects);
+ * // => [{ 'a': 1 }, { 'a': 1 }]
+ *
+ * console.log(objects[0] === objects[1]);
+ * // => true
+ */
+ function constant$5(value) {
+ return function() {
+ return value;
+ };
+ }
+
+ /**
+ * This method returns the first argument it receives.
+ *
+ * @static
+ * @since 0.1.0
+ * @memberOf _
+ * @category Util
+ * @param {*} value Any value.
+ * @returns {*} Returns `value`.
+ * @example
+ *
+ * var object = { 'a': 1 };
+ *
+ * console.log(_.identity(object) === object);
+ * // => true
+ */
+ function identity$5(value) {
+ return value;
+ }
+
+ /**
+ * The base implementation of `setToString` without support for hot loop shorting.
+ *
+ * @private
+ * @param {Function} func The function to modify.
+ * @param {Function} string The `toString` result.
+ * @returns {Function} Returns `func`.
+ */
+ var baseSetToString = !defineProperty$9 ? identity$5 : function(func, string) {
+ return defineProperty$9(func, 'toString', {
+ 'configurable': true,
+ 'enumerable': false,
+ 'value': constant$5(string),
+ 'writable': true
+ });
+ };
+
+ /** Used to detect hot functions by number of calls within a span of milliseconds. */
+ var HOT_COUNT = 800,
+ HOT_SPAN = 16;
+
+ /* Built-in method references for those with the same name as other `lodash` methods. */
+ var nativeNow = Date.now;
+
+ /**
+ * Creates a function that'll short out and invoke `identity` instead
+ * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
+ * milliseconds.
+ *
+ * @private
+ * @param {Function} func The function to restrict.
+ * @returns {Function} Returns the new shortable function.
+ */
+ function shortOut(func) {
+ var count = 0,
+ lastCalled = 0;
+
+ return function() {
+ var stamp = nativeNow(),
+ remaining = HOT_SPAN - (stamp - lastCalled);
+
+ lastCalled = stamp;
+ if (remaining > 0) {
+ if (++count >= HOT_COUNT) {
+ return arguments[0];
+ }
+ } else {
+ count = 0;
+ }
+ return func.apply(undefined, arguments);
+ };
+ }
+
+ /**
+ * Sets the `toString` method of `func` to return `string`.
+ *
+ * @private
+ * @param {Function} func The function to modify.
+ * @param {Function} string The `toString` result.
+ * @returns {Function} Returns `func`.
+ */
+ var setToString = shortOut(baseSetToString);
+
+ /**
+ * A specialized version of `baseRest` which flattens the rest array.
+ *
+ * @private
+ * @param {Function} func The function to apply a rest parameter to.
+ * @returns {Function} Returns the new function.
+ */
+ function flatRest(func) {
+ return setToString(overRest(func, undefined, flatten), func + '');
+ }
+
+ /** Used to compose bitmasks for cloning. */
+ var CLONE_DEEP_FLAG$1 = 1,
+ CLONE_FLAT_FLAG$1 = 2,
+ CLONE_SYMBOLS_FLAG$1 = 4;
+
+ /**
+ * The opposite of `_.pick`; this method creates an object composed of the
+ * own and inherited enumerable property paths of `object` that are not omitted.
+ *
+ * **Note:** This method is considerably slower than `_.pick`.
+ *
+ * @static
+ * @since 0.1.0
+ * @memberOf _
+ * @category Object
+ * @param {Object} object The source object.
+ * @param {...(string|string[])} [paths] The property paths to omit.
+ * @returns {Object} Returns the new object.
+ * @example
+ *
+ * var object = { 'a': 1, 'b': '2', 'c': 3 };
+ *
+ * _.omit(object, ['a', 'c']);
+ * // => { 'b': '2' }
+ */
+ var omit = flatRest(function(object, paths) {
+ var result = {};
+ if (object == null) {
+ return result;
+ }
+ var isDeep = false;
+ paths = arrayMap(paths, function(path) {
+ path = castPath(path, object);
+ isDeep || (isDeep = path.length > 1);
+ return path;
+ });
+ copyObject(object, getAllKeysIn(object), result);
+ if (isDeep) {
+ result = baseClone(result, CLONE_DEEP_FLAG$1 | CLONE_FLAT_FLAG$1 | CLONE_SYMBOLS_FLAG$1, customOmitClone);
+ }
+ var length = paths.length;
+ while (length--) {
+ baseUnset(result, paths[length]);
+ }
+ return result;
+ });
+
+ function svgLines(projection, context) {
+ var detected = utilDetect();
+
+ var highway_stack = {
+ motorway: 0,
+ motorway_link: 1,
+ trunk: 2,
+ trunk_link: 3,
+ primary: 4,
+ primary_link: 5,
+ secondary: 6,
+ tertiary: 7,
+ unclassified: 8,
+ residential: 9,
+ service: 10,
+ footway: 11
+ };
+
+ function drawTargets(selection, graph, entities, filter) {
+ var targetClass = context.getDebug('target') ? 'pink ' : 'nocolor ';
+ var nopeClass = context.getDebug('target') ? 'red ' : 'nocolor ';
+ var getPath = svgPath(projection).geojson;
+ var activeID = context.activeID();
+ var base = context.history().base();
+
+ // The targets and nopes will be MultiLineString sub-segments of the ways
+ var data = { targets: [], nopes: [] };
+
+ entities.forEach(function(way) {
+ var features = svgSegmentWay(way, graph, activeID);
+ data.targets.push.apply(data.targets, features.passive);
+ data.nopes.push.apply(data.nopes, features.active);
+ });
+
+
+ // Targets allow hover and vertex snapping
+ var targetData = data.targets.filter(getPath);
+ var targets = selection.selectAll('.line.target-allowed')
+ .filter(function(d) { return filter(d.properties.entity); })
+ .data(targetData, function key(d) { return d.id; });
+
+ // exit
+ targets.exit()
+ .remove();
+
+ var segmentWasEdited = function(d) {
+ var wayID = d.properties.entity.id;
+ // if the whole line was edited, don't draw segment changes
+ if (!base.entities[wayID] ||
+ !fastDeepEqual(graph.entities[wayID].nodes, base.entities[wayID].nodes)) {
+ return false;
+ }
+ return d.properties.nodes.some(function(n) {
+ return !base.entities[n.id] ||
+ !fastDeepEqual(graph.entities[n.id].loc, base.entities[n.id].loc);
+ });
+ };
+
+ // enter/update
+ targets.enter()
+ .append('path')
+ .merge(targets)
+ .attr('d', getPath)
+ .attr('class', function(d) {
+ return 'way line target target-allowed ' + targetClass + d.id;
+ })
+ .classed('segment-edited', segmentWasEdited);
+
+ // NOPE
+ var nopeData = data.nopes.filter(getPath);
+ var nopes = selection.selectAll('.line.target-nope')
+ .filter(function(d) { return filter(d.properties.entity); })
+ .data(nopeData, function key(d) { return d.id; });
+
+ // exit
+ nopes.exit()
+ .remove();
+
+ // enter/update
+ nopes.enter()
+ .append('path')
+ .merge(nopes)
+ .attr('d', getPath)
+ .attr('class', function(d) {
+ return 'way line target target-nope ' + nopeClass + d.id;
+ })
+ .classed('segment-edited', segmentWasEdited);
+ }
+
+
+ function drawLines(selection, graph, entities, filter) {
+ var base = context.history().base();
+
+ function waystack(a, b) {
+ var selected = context.selectedIDs();
+ var scoreA = selected.indexOf(a.id) !== -1 ? 20 : 0;
+ var scoreB = selected.indexOf(b.id) !== -1 ? 20 : 0;
+
+ if (a.tags.highway) { scoreA -= highway_stack[a.tags.highway]; }
+ if (b.tags.highway) { scoreB -= highway_stack[b.tags.highway]; }
+ return scoreA - scoreB;
+ }
+
+ var getAIRoadStylingClass = function(d){
+ return '';
+ };
+
+ // Class for styling currently edited lines
+ var tagEditClass = function(d) {
+ var result = graph.entities[d.id] && base.entities[d.id] && !isEqual(graph.entities[d.id].tags, base.entities[d.id].tags);
+
+ return result ?
+ ' tagedited ' : '';
+ };
+
+ // Class for styling currently edited lines
+ var graphEditClass = function(d) {
+ if (!base.entities[d.id]) {
+ return ' graphedited ';
+ }
+
+ var result = graph.entities[d.id] && base.entities[d.id] && !isEqual(omit(graph.entities[d.id], ['tags', 'v']), omit(base.entities[d.id], ['tags', 'v']));
+
+ return result ? ' graphedited ' : '';
+ };
+
+ function drawLineGroup(selection, klass, isSelected) {
+ // Note: Don't add `.selected` class in draw modes
+ var mode = context.mode();
+ var isDrawing = mode && /^draw/.test(mode.id);
+ var selectedClass = (!isDrawing && isSelected) ? 'selected ' : '';
+
+ var lines = selection
+ .selectAll('path')
+ .filter(filter)
+ .data(getPathData(isSelected), osmEntity.key);
+
+ lines.exit()
+ .remove();
+
+ // Optimization: Call expensive TagClasses only on enter selection. This
+ // works because osmEntity.key is defined to include the entity v attribute.
+ lines.enter()
+ .append('path')
+ .attr('class', function(d) {
+
+ var prefix = 'way line';
+
+ // if this line isn't styled by its own tags
+ if (!d.hasInterestingTags()) {
+
+ var parentRelations = graph.parentRelations(d);
+ var parentMultipolygons = parentRelations.filter(function(relation) {
+ return relation.isMultipolygon();
+ });
+
+ // and if it's a member of at least one multipolygon relation
+ if (parentMultipolygons.length > 0 &&
+ // and only multipolygon relations
+ parentRelations.length === parentMultipolygons.length) {
+ // then fudge the classes to style this as an area edge
+ prefix = 'relation area';
+ }
+ }
+
+ var oldMPClass = oldMultiPolygonOuters[d.id] ? 'old-multipolygon ' : '';
+ return prefix + ' ' + klass + ' ' + selectedClass + oldMPClass + graphEditClass(d) + tagEditClass(d) + getAIRoadStylingClass() + d.id;
+ })
+ .classed('added', function(d) {
+ return !base.entities[d.id];
+ })
+ .classed('geometry-edited', function(d) {
+ return graph.entities[d.id] &&
+ base.entities[d.id] &&
+ !fastDeepEqual(graph.entities[d.id].nodes, base.entities[d.id].nodes);
+ })
+ .classed('retagged', function(d) {
+ return graph.entities[d.id] &&
+ base.entities[d.id] &&
+ !fastDeepEqual(graph.entities[d.id].tags, base.entities[d.id].tags);
+ })
+ .call(svgTagClasses())
+ .merge(lines)
+ .sort(waystack)
+ .attr('d', getPath)
+ .call(svgTagClasses().tags(svgRelationMemberTags(graph)));
+
+ return selection;
+ }
+
+
+ function getPathData(isSelected) {
+ return function() {
+ var layer = this.parentNode.__data__;
+ var data = pathdata[layer] || [];
+ return data.filter(function(d) {
+ if (isSelected)
+ return context.selectedIDs().indexOf(d.id) !== -1;
+ else
+ return context.selectedIDs().indexOf(d.id) === -1;
+ });
+ };
+ }
+
+ function addMarkers(layergroup, pathclass, groupclass, groupdata, marker) {
+ var markergroup = layergroup
+ .selectAll('g.' + groupclass)
+ .data([pathclass]);
+
+ markergroup = markergroup.enter()
+ .append('g')
+ .attr('class', groupclass)
+ .merge(markergroup);
+
+ var markers = markergroup
+ .selectAll('path')
+ .filter(filter)
+ .data(
+ function data() { return groupdata[this.parentNode.__data__] || []; },
+ function key(d) { return [d.id, d.index]; }
+ );
+
+ markers.exit()
+ .remove();
+
+ markers = markers.enter()
+ .append('path')
+ .attr('class', pathclass)
+ .merge(markers)
+ .attr('marker-mid', marker)
+ .attr('d', function(d) { return d.d; });
+
+ if (detected.ie) {
+ markers.each(function() { this.parentNode.insertBefore(this, this); });
+ }
+ }
+
+
+ var getPath = svgPath(projection, graph);
+ var ways = [];
+ var onewaydata = {};
+ var sideddata = {};
+ var oldMultiPolygonOuters = {};
+
+ for (var i = 0; i < entities.length; i++) {
+ var entity = entities[i];
+ var outer = osmOldMultipolygonOuterMember(entity, graph);
+ if (outer) {
+ ways.push(entity.mergeTags(outer.tags));
+ oldMultiPolygonOuters[outer.id] = true;
+ } else if (entity.geometry(graph) === 'line') {
+ ways.push(entity);
+ }
+ }
+
+ ways = ways.filter(getPath);
+ var pathdata = utilArrayGroupBy(ways, function(way) { return way.layer(); });
+
+ Object.keys(pathdata).forEach(function(k) {
+ var v = pathdata[k];
+ var onewayArr = v.filter(function(d) { return d.isOneWay(); });
+ var onewaySegments = svgMarkerSegments(
+ projection, graph, 35,
+ function shouldReverse(entity) { return entity.tags.oneway === '-1'; },
+ function bothDirections(entity) {
+ return entity.tags.oneway === 'reversible' || entity.tags.oneway === 'alternating';
+ }
+ );
+ onewaydata[k] = utilArrayFlatten(onewayArr.map(onewaySegments));
+
+ var sidedArr = v.filter(function(d) { return d.isSided(); });
+ var sidedSegments = svgMarkerSegments(
+ projection, graph, 30,
+ function shouldReverse() { return false; },
+ function bothDirections() { return false; }
+ );
+ sideddata[k] = utilArrayFlatten(sidedArr.map(sidedSegments));
+ });
+
+
+ var covered = selection.selectAll('.layer-osm.covered'); // under areas
+ var uncovered = selection.selectAll('.layer-osm.lines'); // over areas
+ var touchLayer = selection.selectAll('.layer-touch.lines');
+
+ // Draw lines..
+ [covered, uncovered].forEach(function(selection) {
+ var range = (selection === covered ? range$1(-10,0) : range$1(0,11));
+ var layergroup = selection
+ .selectAll('g.layergroup')
+ .data(range);
+
+ layergroup = layergroup.enter()
+ .append('g')
+ .attr('class', function(d) { return 'layergroup layer' + String(d); })
+ .merge(layergroup);
+
+ layergroup
+ .selectAll('g.linegroup')
+ .data(['shadow', 'casing', 'stroke', 'shadow-highlighted', 'casing-highlighted', 'stroke-highlighted'])
+ .enter()
+ .append('g')
+ .attr('class', function(d) { return 'linegroup line-' + d; });
+
+ layergroup.selectAll('g.line-shadow')
+ .call(drawLineGroup, 'shadow', false);
+ layergroup.selectAll('g.line-casing')
+ .call(drawLineGroup, 'casing', false);
+ layergroup.selectAll('g.line-stroke')
+ .call(drawLineGroup, 'stroke', false);
+
+ layergroup.selectAll('g.line-shadow-highlighted')
+ .call(drawLineGroup, 'shadow', true);
+ layergroup.selectAll('g.line-casing-highlighted')
+ .call(drawLineGroup, 'casing', true);
+ layergroup.selectAll('g.line-stroke-highlighted')
+ .call(drawLineGroup, 'stroke', true);
+
+ addMarkers(layergroup, 'oneway', 'onewaygroup', onewaydata, 'url(#ideditor-oneway-marker)');
+ addMarkers(layergroup, 'sided', 'sidedgroup', sideddata,
+ function marker(d) {
+ var category = graph.entity(d.id).sidednessIdentifier();
+ return 'url(#ideditor-sided-marker-' + category + ')';
+ }
+ );
+ });
+
+ // Draw touch targets..
+ touchLayer
+ .call(drawTargets, graph, ways, filter);
+ }
+
+
+ return drawLines;
+ }
+
+ function svgMidpoints(projection, context) {
+ var targetRadius = 8;
+
+ function drawTargets(selection, graph, entities, filter) {
+ var fillClass = context.getDebug('target') ? 'pink ' : 'nocolor ';
+ var getTransform = svgPointTransform(projection).geojson;
+
+ var data = entities.map(function(midpoint) {
+ return {
+ type: 'Feature',
+ id: midpoint.id,
+ properties: {
+ target: true,
+ entity: midpoint
+ },
+ geometry: {
+ type: 'Point',
+ coordinates: midpoint.loc
+ }
+ };
+ });
+
+ var targets = selection.selectAll('.midpoint.target')
+ .filter(function(d) { return filter(d.properties.entity); })
+ .data(data, function key(d) { return d.id; });
+
+ // exit
+ targets.exit()
+ .remove();
+
+ // enter/update
+ targets.enter()
+ .append('circle')
+ .attr('r', targetRadius)
+ .merge(targets)
+ .attr('class', function(d) { return 'node midpoint target ' + fillClass + d.id; })
+ .attr('transform', getTransform);
+ }
+
+
+ function drawMidpoints(selection, graph, entities, filter, extent) {
+ var drawLayer = selection.selectAll('.layer-osm.points .points-group.midpoints');
+ var touchLayer = selection.selectAll('.layer-touch.points');
+
+ var mode = context.mode();
+ if ((mode && mode.id !== 'select') || !context.map().withinEditableZoom()) {
+ drawLayer.selectAll('.midpoint').remove();
+ touchLayer.selectAll('.midpoint.target').remove();
+ return;
+ }
+
+ var poly = extent.polygon();
+ var midpoints = {};
+
+ for (var i = 0; i < entities.length; i++) {
+ var entity = entities[i];
+
+ if (entity.type !== 'way') continue;
+ if (!filter(entity)) continue;
+ if (context.selectedIDs().indexOf(entity.id) < 0) continue;
+
+ var nodes = graph.childNodes(entity);
+ for (var j = 0; j < nodes.length - 1; j++) {
+ var a = nodes[j];
+ var b = nodes[j + 1];
+ var id = [a.id, b.id].sort().join('-');
+
+ if (midpoints[id]) {
+ midpoints[id].parents.push(entity);
+ } else if (geoVecLength(projection(a.loc), projection(b.loc)) > 40) {
+ var point = geoVecInterp(a.loc, b.loc, 0.5);
+ var loc = null;
+
+ if (extent.intersects(point)) {
+ loc = point;
+ } else {
+ for (var k = 0; k < 4; k++) {
+ point = geoLineIntersection([a.loc, b.loc], [poly[k], poly[k + 1]]);
+ if (point &&
+ geoVecLength(projection(a.loc), projection(point)) > 20 &&
+ geoVecLength(projection(b.loc), projection(point)) > 20)
+ {
+ loc = point;
+ break;
+ }
+ }
+ }
+
+ if (loc) {
+ midpoints[id] = {
+ type: 'midpoint',
+ id: id,
+ loc: loc,
+ edge: [a.id, b.id],
+ parents: [entity]
+ };
+ }
+ }
+ }
+ }
+
+
+ function midpointFilter(d) {
+ if (midpoints[d.id])
+ return true;
+
+ for (var i = 0; i < d.parents.length; i++) {
+ if (filter(d.parents[i])) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+
+ var groups = drawLayer.selectAll('.midpoint')
+ .filter(midpointFilter)
+ .data(Object.values(midpoints), function(d) { return d.id; });
+
+ groups.exit()
+ .remove();
+
+ var enter = groups.enter()
+ .insert('g', ':first-child')
+ .attr('class', 'midpoint');
+
+ enter
+ .append('polygon')
+ .attr('points', '-6,8 10,0 -6,-8')
+ .attr('class', 'shadow');
+
+ enter
+ .append('polygon')
+ .attr('points', '-3,4 5,0 -3,-4')
+ .attr('class', 'fill');
+
+ groups = groups
+ .merge(enter)
+ .attr('transform', function(d) {
+ var translate = svgPointTransform(projection);
+ var a = graph.entity(d.edge[0]);
+ var b = graph.entity(d.edge[1]);
+ var angle = geoAngle(a, b, projection) * (180 / Math.PI);
+ return translate(d) + ' rotate(' + angle + ')';
+ })
+ .call(svgTagClasses().tags(
+ function(d) { return d.parents[0].tags; }
+ ));
+
+ // Propagate data bindings.
+ groups.select('polygon.shadow');
+ groups.select('polygon.fill');
+
+
+ // Draw touch targets..
+ touchLayer
+ .call(drawTargets, graph, Object.values(midpoints), midpointFilter);
+ }
+
+ return drawMidpoints;
+ }
+
+ function svgPoints(projection, context) {
+
+ function markerPath(selection, klass) {
+ selection
+ .attr('class', klass)
+ .attr('transform', 'translate(-8, -23)')
+ .attr('d', 'M 17,8 C 17,13 11,21 8.5,23.5 C 6,21 0,13 0,8 C 0,4 4,-0.5 8.5,-0.5 C 13,-0.5 17,4 17,8 z');
+ }
+
+ function sortY(a, b) {
+ return b.loc[1] - a.loc[1];
+ }
+
+
+ // Avoid exit/enter if we're just moving stuff around.
+ // The node will get a new version but we only need to run the update selection.
+ function fastEntityKey(d) {
+ var mode = context.mode();
+ var isMoving = mode && /^(add|draw|drag|move|rotate)/.test(mode.id);
+ return isMoving ? d.id : osmEntity.key(d);
+ }
+
+
+ function drawTargets(selection, graph, entities, filter) {
+ var fillClass = context.getDebug('target') ? 'pink ' : 'nocolor ';
+ var getTransform = svgPointTransform(projection).geojson;
+ var activeID = context.activeID();
+ var data = [];
+
+ entities.forEach(function(node) {
+ if (activeID === node.id) return; // draw no target on the activeID
+
+ data.push({
+ type: 'Feature',
+ id: node.id,
+ properties: {
+ target: true,
+ entity: node
+ },
+ geometry: node.asGeoJSON()
+ });
+ });
+
+ var targets = selection.selectAll('.point.target')
+ .filter(function(d) { return filter(d.properties.entity); })
+ .data(data, function key(d) { return d.id; });
+
+ // exit
+ targets.exit()
+ .remove();
+
+ // enter/update
+ targets.enter()
+ .append('rect')
+ .attr('x', -10)
+ .attr('y', -26)
+ .attr('width', 20)
+ .attr('height', 30)
+ .merge(targets)
+ .attr('class', function(d) { return 'node point target ' + fillClass + d.id; })
+ .attr('transform', getTransform);
+ }
+
+
+ function drawPoints(selection, graph, entities, filter) {
+ var wireframe = context.surface().classed('fill-wireframe');
+ var zoom = geoScaleToZoom(projection.scale());
+ var base = context.history().base();
+
+ // Points with a direction will render as vertices at higher zooms..
+ function renderAsPoint(entity) {
+ return entity.geometry(graph) === 'point' &&
+ !(zoom >= 18 && entity.directions(graph, projection).length);
+ }
+
+ // All points will render as vertices in wireframe mode too..
+ var points = wireframe ? [] : entities.filter(renderAsPoint);
+ points.sort(sortY);
+
+
+ var drawLayer = selection.selectAll('.layer-osm.points .points-group.points');
+ var touchLayer = selection.selectAll('.layer-touch.points');
+
+ // Draw points..
+ var groups = drawLayer.selectAll('g.point')
+ .filter(filter)
+ .data(points, fastEntityKey);
+
+ groups.exit()
+ .remove();
+
+ var enter = groups.enter()
+ .append('g')
+ .attr('class', function(d) { return 'node point ' + d.id; })
+ .order();
+
+ enter
+ .append('path')
+ .call(markerPath, 'shadow');
+
+ enter
+ .append('ellipse')
+ .attr('cx', 0.5)
+ .attr('cy', 1)
+ .attr('rx', 6.5)
+ .attr('ry', 3)
+ .attr('class', 'stroke');
+
+ enter
+ .append('path')
+ .call(markerPath, 'stroke');
+
+ enter
+ .append('use')
+ .attr('transform', 'translate(-5, -19)')
+ .attr('class', 'icon')
+ .attr('width', '11px')
+ .attr('height', '11px');
+
+ groups = groups
+ .merge(enter)
+ .attr('transform', svgPointTransform(projection))
+ .classed('added', function(d) {
+ return !base.entities[d.id]; // if it doesn't exist in the base graph, it's new
+ })
+ .classed('moved', function(d) {
+ return base.entities[d.id] && !fastDeepEqual(graph.entities[d.id].loc, base.entities[d.id].loc);
+ })
+ .classed('retagged', function(d) {
+ return base.entities[d.id] && !fastDeepEqual(graph.entities[d.id].tags, base.entities[d.id].tags);
+ })
+ .call(svgTagClasses());
+
+ groups.select('.shadow'); // propagate bound data
+ groups.select('.stroke'); // propagate bound data
+ groups.select('.icon') // propagate bound data
+ .attr('xlink:href', function(entity) {
+ var preset = _mainPresetIndex.match(entity, graph);
+ var picon = preset && preset.icon;
+
+ if (!picon) {
+ return '';
+ } else {
+ var isMaki = /^maki-/.test(picon);
+ return '#' + picon + (isMaki ? '-11' : '');
+ }
+ });
+
+
+ // Draw touch targets..
+ touchLayer
+ .call(drawTargets, graph, points, filter);
+ }
+
+
+ return drawPoints;
+ }
+
+ function svgTurns(projection, context) {
+
+ function icon(turn) {
+ var u = turn.u ? '-u' : '';
+ if (turn.no) return '#iD-turn-no' + u;
+ if (turn.only) return '#iD-turn-only' + u;
+ return '#iD-turn-yes' + u;
+ }
+
+ function drawTurns(selection, graph, turns) {
+
+ function turnTransform(d) {
+ var pxRadius = 50;
+ var toWay = graph.entity(d.to.way);
+ var toPoints = graph.childNodes(toWay)
+ .map(function (n) { return n.loc; })
+ .map(projection);
+ var toLength = geoPathLength(toPoints);
+ var mid = toLength / 2; // midpoint of destination way
+
+ var toNode = graph.entity(d.to.node);
+ var toVertex = graph.entity(d.to.vertex);
+ var a = geoAngle(toVertex, toNode, projection);
+ var o = projection(toVertex.loc);
+ var r = d.u ? 0 // u-turn: no radius
+ : !toWay.__via ? pxRadius // leaf way: put marker at pxRadius
+ : Math.min(mid, pxRadius); // via way: prefer pxRadius, fallback to mid for very short ways
+
+ return 'translate(' + (r * Math.cos(a) + o[0]) + ',' + (r * Math.sin(a) + o[1]) + ') ' +
+ 'rotate(' + a * 180 / Math.PI + ')';
+ }
+
+
+ var drawLayer = selection.selectAll('.layer-osm.points .points-group.turns');
+ var touchLayer = selection.selectAll('.layer-touch.turns');
+
+ // Draw turns..
+ var groups = drawLayer.selectAll('g.turn')
+ .data(turns, function(d) { return d.key; });
+
+ // exit
+ groups.exit()
+ .remove();
+
+ // enter
+ var groupsEnter = groups.enter()
+ .append('g')
+ .attr('class', function(d) { return 'turn ' + d.key; });
+
+ var turnsEnter = groupsEnter
+ .filter(function(d) { return !d.u; });
+
+ turnsEnter.append('rect')
+ .attr('transform', 'translate(-22, -12)')
+ .attr('width', '44')
+ .attr('height', '24');
+
+ turnsEnter.append('use')
+ .attr('transform', 'translate(-22, -12)')
+ .attr('width', '44')
+ .attr('height', '24');
+
+ var uEnter = groupsEnter
+ .filter(function(d) { return d.u; });
+
+ uEnter.append('circle')
+ .attr('r', '16');
+
+ uEnter.append('use')
+ .attr('transform', 'translate(-16, -16)')
+ .attr('width', '32')
+ .attr('height', '32');
+
+ // update
+ groups = groups
+ .merge(groupsEnter)
+ .attr('opacity', function(d) { return d.direct === false ? '0.7' : null; })
+ .attr('transform', turnTransform);
+
+ groups.select('use')
+ .attr('xlink:href', icon);
+
+ groups.select('rect'); // propagate bound data
+ groups.select('circle'); // propagate bound data
+
+
+ // Draw touch targets..
+ var fillClass = context.getDebug('target') ? 'pink ' : 'nocolor ';
+ groups = touchLayer.selectAll('g.turn')
+ .data(turns, function(d) { return d.key; });
+
+ // exit
+ groups.exit()
+ .remove();
+
+ // enter
+ groupsEnter = groups.enter()
+ .append('g')
+ .attr('class', function(d) { return 'turn ' + d.key; });
+
+ turnsEnter = groupsEnter
+ .filter(function(d) { return !d.u; });
+
+ turnsEnter.append('rect')
+ .attr('class', 'target ' + fillClass)
+ .attr('transform', 'translate(-22, -12)')
+ .attr('width', '44')
+ .attr('height', '24');
+
+ uEnter = groupsEnter
+ .filter(function(d) { return d.u; });
+
+ uEnter.append('circle')
+ .attr('class', 'target ' + fillClass)
+ .attr('r', '16');
+
+ // update
+ groups = groups
+ .merge(groupsEnter)
+ .attr('transform', turnTransform);
+
+ groups.select('rect'); // propagate bound data
+ groups.select('circle'); // propagate bound data
+
+
+ return this;
+ }
+
+ return drawTurns;
+ }
+
+ function svgVertices(projection, context) {
+ var radiuses = {
+ // z16-, z17, z18+, w/icon
+ shadow: [6, 7.5, 7.5, 12],
+ stroke: [2.5, 3.5, 3.5, 8],
+ fill: [1, 1.5, 1.5, 1.5]
+ };
+
+ var _currHoverTarget;
+ var _currPersistent = {};
+ var _currHover = {};
+ var _prevHover = {};
+ var _currSelected = {};
+ var _prevSelected = {};
+ var _radii = {};
+
+
+ function sortY(a, b) {
+ return b.loc[1] - a.loc[1];
+ }
+
+ // Avoid exit/enter if we're just moving stuff around.
+ // The node will get a new version but we only need to run the update selection.
+ function fastEntityKey(d) {
+ var mode = context.mode();
+ var isMoving = mode && /^(add|draw|drag|move|rotate)/.test(mode.id);
+ return isMoving ? d.id : osmEntity.key(d);
+ }
+
+
+ function draw(selection, graph, vertices, sets, filter) {
+ sets = sets || { selected: {}, important: {}, hovered: {} };
+
+ var icons = {};
+ var directions = {};
+ var wireframe = context.surface().classed('fill-wireframe');
+ var zoom = geoScaleToZoom(projection.scale());
+ var z = (zoom < 17 ? 0 : zoom < 18 ? 1 : 2);
+ var activeID = context.activeID();
+ var base = context.history().base();
+
+
+ function getIcon(d) {
+ // always check latest entity, as fastEntityKey avoids enter/exit now
+ var entity = graph.entity(d.id);
+ if (entity.id in icons) return icons[entity.id];
+
+ icons[entity.id] =
+ entity.hasInterestingTags() &&
+ _mainPresetIndex.match(entity, graph).icon;
+
+ return icons[entity.id];
+ }
+
+
+ // memoize directions results, return false for empty arrays (for use in filter)
+ function getDirections(entity) {
+ if (entity.id in directions) return directions[entity.id];
+
+ var angles = entity.directions(graph, projection);
+ directions[entity.id] = angles.length ? angles : false;
+ return angles;
+ }
+
+
+ function updateAttributes(selection) {
+ ['shadow', 'stroke', 'fill'].forEach(function(klass) {
+ var rads = radiuses[klass];
+ selection.selectAll('.' + klass)
+ .each(function(entity) {
+ var i = z && getIcon(entity);
+ var r = rads[i ? 3 : z];
+
+ // slightly increase the size of unconnected endpoints #3775
+ if (entity.id !== activeID && entity.isEndpoint(graph) && !entity.isConnected(graph)) {
+ r += 1.5;
+ }
+
+ if (klass === 'shadow') { // remember this value, so we don't need to
+ _radii[entity.id] = r; // recompute it when we draw the touch targets
+ }
+
+ select(this)
+ .attr('r', r)
+ .attr('visibility', (i && klass === 'fill') ? 'hidden' : null);
+ });
+ });
+ }
+
+ vertices.sort(sortY);
+
+ var groups = selection.selectAll('g.vertex')
+ .filter(filter)
+ .data(vertices, fastEntityKey);
+
+ // exit
+ groups.exit()
+ .remove();
+
+ // enter
+ var enter = groups.enter()
+ .append('g')
+ .attr('class', function(d) { return 'node vertex ' + d.id; })
+ .order();
+
+ enter
+ .append('circle')
+ .attr('class', 'shadow');
+
+ enter
+ .append('circle')
+ .attr('class', 'stroke');
+
+ // Vertices with tags get a fill.
+ enter.filter(function(d) { return d.hasInterestingTags(); })
+ .append('circle')
+ .attr('class', 'fill');
+
+ // update
+ groups = groups
+ .merge(enter)
+ .attr('transform', svgPointTransform(projection))
+ .classed('sibling', function(d) { return d.id in sets.selected; })
+ .classed('shared', function(d) { return graph.isShared(d); })
+ .classed('endpoint', function(d) { return d.isEndpoint(graph); })
+ .classed('added', function(d) {
+ return !base.entities[d.id]; // if it doesn't exist in the base graph, it's new
+ })
+ .classed('moved', function(d) {
+ return base.entities[d.id] && !fastDeepEqual(graph.entities[d.id].loc, base.entities[d.id].loc);
+ })
+ .classed('retagged', function(d) {
+ return base.entities[d.id] && !fastDeepEqual(graph.entities[d.id].tags, base.entities[d.id].tags);
+ })
+ .call(updateAttributes);
+
+ // Vertices with icons get a `use`.
+ var iconUse = groups
+ .selectAll('.icon')
+ .data(function data(d) { return zoom >= 17 && getIcon(d) ? [d] : []; }, fastEntityKey);
+
+ // exit
+ iconUse.exit()
+ .remove();
+
+ // enter
+ iconUse.enter()
+ .append('use')
+ .attr('class', 'icon')
+ .attr('width', '11px')
+ .attr('height', '11px')
+ .attr('transform', 'translate(-5.5, -5.5)')
+ .attr('xlink:href', function(d) {
+ var picon = getIcon(d);
+ var isMaki = /^maki-/.test(picon);
+ return '#' + picon + (isMaki ? '-11' : '');
+ });
+
+
+ // Vertices with directions get viewfields
+ var dgroups = groups
+ .selectAll('.viewfieldgroup')
+ .data(function data(d) { return zoom >= 18 && getDirections(d) ? [d] : []; }, fastEntityKey);
+
+ // exit
+ dgroups.exit()
+ .remove();
+
+ // enter/update
+ dgroups = dgroups.enter()
+ .insert('g', '.shadow')
+ .attr('class', 'viewfieldgroup')
+ .merge(dgroups);
+
+ var viewfields = dgroups.selectAll('.viewfield')
+ .data(getDirections, function key(d) { return osmEntity.key(d); });
+
+ // exit
+ viewfields.exit()
+ .remove();
+
+ // enter/update
+ viewfields.enter()
+ .append('path')
+ .attr('class', 'viewfield')
+ .attr('d', 'M0,0H0')
+ .merge(viewfields)
+ .attr('marker-start', 'url(#ideditor-viewfield-marker' + (wireframe ? '-wireframe' : '') + ')')
+ .attr('transform', function(d) { return 'rotate(' + d + ')'; });
+ }
+
+
+ function drawTargets(selection, graph, entities, filter) {
+ var targetClass = context.getDebug('target') ? 'pink ' : 'nocolor ';
+ var nopeClass = context.getDebug('target') ? 'red ' : 'nocolor ';
+ var getTransform = svgPointTransform(projection).geojson;
+ var activeID = context.activeID();
+ var data = { targets: [], nopes: [] };
+ var base = context.history().base();
+
+ entities.forEach(function(node) {
+ if (activeID === node.id) return; // draw no target on the activeID
+
+ var vertexType = svgPassiveVertex(node, graph, activeID);
+ if (vertexType !== 0) { // passive or adjacent - allow to connect
+ data.targets.push({
+ type: 'Feature',
+ id: node.id,
+ properties: {
+ target: true,
+ entity: node
+ },
+ geometry: node.asGeoJSON()
+ });
+ } else {
+ data.nopes.push({
+ type: 'Feature',
+ id: node.id + '-nope',
+ properties: {
+ nope: true,
+ target: true,
+ entity: node
+ },
+ geometry: node.asGeoJSON()
+ });
+ }
+ });
+
+ // Targets allow hover and vertex snapping
+ var targets = selection.selectAll('.vertex.target-allowed')
+ .filter(function(d) { return filter(d.properties.entity); })
+ .data(data.targets, function key(d) { return d.id; });
+
+ // exit
+ targets.exit()
+ .remove();
+
+ // enter/update
+ targets.enter()
+ .append('circle')
+ .attr('r', function(d) {
+ return _radii[d.id]
+ || radiuses.shadow[3];
+ })
+ .merge(targets)
+ .attr('class', function(d) {
+ return 'node vertex target target-allowed '
+ + targetClass + d.id;
+ })
+ .attr('transform', getTransform);
+
+
+ // NOPE
+ var nopes = selection.selectAll('.vertex.target-nope')
+ .filter(function(d) { return filter(d.properties.entity); })
+ .data(data.nopes, function key(d) { return d.id; });
+
+ // exit
+ nopes.exit()
+ .remove();
+
+ // enter/update
+ nopes.enter()
+ .append('circle')
+ .attr('r', function(d) { return (_radii[d.properties.entity.id] || radiuses.shadow[3]); })
+ .merge(nopes)
+ .attr('class', function(d) { return 'node vertex target target-nope ' + nopeClass + d.id; })
+ .attr('transform', getTransform);
+ }
+
+
+ // Points can also render as vertices:
+ // 1. in wireframe mode or
+ // 2. at higher zooms if they have a direction
+ function renderAsVertex(entity, graph, wireframe, zoom) {
+ var geometry = entity.geometry(graph);
+ return geometry === 'vertex' || (geometry === 'point' && (
+ wireframe || (zoom >= 18 && entity.directions(graph, projection).length)
+ ));
+ }
+
+
+ function isEditedNode(node, base, head) {
+ var baseNode = base.entities[node.id];
+ var headNode = head.entities[node.id];
+ return !headNode ||
+ !baseNode ||
+ !fastDeepEqual(headNode.tags, baseNode.tags) ||
+ !fastDeepEqual(headNode.loc, baseNode.loc);
+ }
+
+
+ function getSiblingAndChildVertices(ids, graph, wireframe, zoom) {
+ var results = {};
+
+ var seenIds = {};
+
+ function addChildVertices(entity) {
+
+ // avoid redunant work and infinite recursion of circular relations
+ if (seenIds[entity.id]) return;
+ seenIds[entity.id] = true;
+
+ var geometry = entity.geometry(graph);
+ if (!context.features().isHiddenFeature(entity, graph, geometry)) {
+ var i;
+ if (entity.type === 'way') {
+ for (i = 0; i < entity.nodes.length; i++) {
+ var child = graph.hasEntity(entity.nodes[i]);
+ if (child) {
+ addChildVertices(child);
+ }
+ }
+ } else if (entity.type === 'relation') {
+ for (i = 0; i < entity.members.length; i++) {
+ var member = graph.hasEntity(entity.members[i].id);
+ if (member) {
+ addChildVertices(member);
+ }
+ }
+ } else if (renderAsVertex(entity, graph, wireframe, zoom)) {
+ results[entity.id] = entity;
+ }
+ }
+ }
+
+ ids.forEach(function(id) {
+ var entity = graph.hasEntity(id);
+ if (!entity) return;
+
+ if (entity.type === 'node') {
+ if (renderAsVertex(entity, graph, wireframe, zoom)) {
+ results[entity.id] = entity;
+ graph.parentWays(entity).forEach(function(entity) {
+ addChildVertices(entity);
+ });
+ }
+ } else { // way, relation
+ addChildVertices(entity);
+ }
+ });
+
+ return results;
+ }
+
+
+ function drawVertices(selection, graph, entities, filter, extent, fullRedraw) {
+ var wireframe = context.surface().classed('fill-wireframe');
+ var visualDiff = context.surface().classed('highlight-edited');
+ var zoom = geoScaleToZoom(projection.scale());
+ var mode = context.mode();
+ var isMoving = mode && /^(add|draw|drag|move|rotate)/.test(mode.id);
+ var base = context.history().base();
+
+ var drawLayer = selection.selectAll('.layer-osm.points .points-group.vertices');
+ var touchLayer = selection.selectAll('.layer-touch.points');
+
+ if (fullRedraw) {
+ _currPersistent = {};
+ _radii = {};
+ }
+
+ // Collect important vertices from the `entities` list..
+ // (during a paritial redraw, it will not contain everything)
+ for (var i = 0; i < entities.length; i++) {
+ var entity = entities[i];
+ var geometry = entity.geometry(graph);
+ var keep = false;
+
+ // a point that looks like a vertex..
+ if ((geometry === 'point') && renderAsVertex(entity, graph, wireframe, zoom)) {
+ _currPersistent[entity.id] = entity;
+ keep = true;
+
+ // a vertex of some importance..
+ } else if (geometry === 'vertex' &&
+ (entity.hasInterestingTags() || entity.isEndpoint(graph) || entity.isConnected(graph)
+ || (visualDiff && isEditedNode(entity, base, graph)))) {
+ _currPersistent[entity.id] = entity;
+ keep = true;
+ }
+
+ // whatever this is, it's not a persistent vertex..
+ if (!keep && !fullRedraw) {
+ delete _currPersistent[entity.id];
+ }
+ }
+
+ // 3 sets of vertices to consider:
+ var sets = {
+ persistent: _currPersistent, // persistent = important vertices (render always)
+ selected: _currSelected, // selected + siblings of selected (render always)
+ hovered: _currHover // hovered + siblings of hovered (render only in draw modes)
+ };
+
+ var all = Object.assign({}, (isMoving ? _currHover : {}), _currSelected, _currPersistent);
+
+ // Draw the vertices..
+ // The filter function controls the scope of what objects d3 will touch (exit/enter/update)
+ // Adjust the filter function to expand the scope beyond whatever entities were passed in.
+ var filterRendered = function(d) {
+ return d.id in _currPersistent || d.id in _currSelected || d.id in _currHover || filter(d);
+ };
+ drawLayer
+ .call(draw, graph, currentVisible(all), sets, filterRendered);
+
+ // Draw touch targets..
+ // When drawing, render all targets (not just those affected by a partial redraw)
+ var filterTouch = function(d) {
+ return isMoving ? true : filterRendered(d);
+ };
+ touchLayer
+ .call(drawTargets, graph, currentVisible(all), filterTouch);
+
+
+ function currentVisible(which) {
+ return Object.keys(which)
+ .map(graph.hasEntity, graph) // the current version of this entity
+ .filter(function (entity) { return entity && entity.intersects(extent, graph); });
+ }
+ }
+
+
+ // partial redraw - only update the selected items..
+ drawVertices.drawSelected = function(selection, graph, extent) {
+ var wireframe = context.surface().classed('fill-wireframe');
+ var zoom = geoScaleToZoom(projection.scale());
+
+ _prevSelected = _currSelected || {};
+ if (context.map().isInWideSelection()) {
+ _currSelected = {};
+ context.selectedIDs().forEach(function(id) {
+ var entity = graph.hasEntity(id);
+ if (!entity) return;
+
+ if (entity.type === 'node') {
+ if (renderAsVertex(entity, graph, wireframe, zoom)) {
+ _currSelected[entity.id] = entity;
+ }
+ }
+ });
+
+ } else {
+ _currSelected = getSiblingAndChildVertices(context.selectedIDs(), graph, wireframe, zoom);
+ }
+
+ // note that drawVertices will add `_currSelected` automatically if needed..
+ var filter = function(d) { return d.id in _prevSelected; };
+ drawVertices(selection, graph, Object.values(_prevSelected), filter, extent, false);
+ };
+
+
+ // partial redraw - only update the hovered items..
+ drawVertices.drawHover = function(selection, graph, target, extent) {
+ if (target === _currHoverTarget) return; // continue only if something changed
+
+ var wireframe = context.surface().classed('fill-wireframe');
+ var zoom = geoScaleToZoom(projection.scale());
+
+ _prevHover = _currHover || {};
+ _currHoverTarget = target;
+ var entity = target && target.properties && target.properties.entity;
+
+ if (entity) {
+ _currHover = getSiblingAndChildVertices([entity.id], graph, wireframe, zoom);
+ } else {
+ _currHover = {};
+ }
+
+ // note that drawVertices will add `_currHover` automatically if needed..
+ var filter = function(d) { return d.id in _prevHover; };
+ drawVertices(selection, graph, Object.values(_prevHover), filter, extent, false);
+ };
+
+ return drawVertices;
+ }
+
+ var _languagesArray = [];
+
+
+ function uiFieldLocalized(field, context) {
+ var dispatch$1 = dispatch('change', 'input');
+ var wikipedia = services.wikipedia;
+ var input = select(null);
+ var localizedInputs = select(null);
+ var _countryCode;
+ var _tags;
+
+
+ // A concern here in switching to async data means that _languagesArray will not
+ // be available the first time through, so things like the fetchers and
+ // the language() function will not work immediately.
+ _mainFileFetcher.get('languages')
+ .then(loadLanguagesArray)
+ .catch(function() { /* ignore */ });
+
+ var _territoryLanguages = {};
+ _mainFileFetcher.get('territory_languages')
+ .then(function(d) { _territoryLanguages = d; })
+ .catch(function() { /* ignore */ });
+
+
+ var allSuggestions = _mainPresetIndex.collection.filter(function(p) {
+ return p.suggestion === true;
+ });
+
+ // reuse these combos
+ var langCombo = uiCombobox(context, 'localized-lang')
+ .fetcher(fetchLanguages)
+ .minItems(0);
+
+ var brandCombo = uiCombobox(context, 'localized-brand')
+ .canAutocomplete(false)
+ .minItems(1);
+
+ var _selection = select(null);
+ var _multilingual = [];
+ var _buttonTip = uiTooltip()
+ .title(_t('translate.translate'))
+ .placement('left');
+ var _wikiTitles;
+ var _entityIDs = [];
+
+
+ function loadLanguagesArray(dataLanguages) {
+ if (_languagesArray.length !== 0) return;
+
+ // some conversion is needed to ensure correct OSM tags are used
+ var replacements = {
+ sr: 'sr-Cyrl', // in OSM, `sr` implies Cyrillic
+ 'sr-Cyrl': false // `sr-Cyrl` isn't used in OSM
+ };
+
+ for (var code in dataLanguages) {
+ if (replacements[code] === false) continue;
+ var metaCode = code;
+ if (replacements[code]) metaCode = replacements[code];
+
+ _languagesArray.push({
+ localName: _mainLocalizer.languageName(metaCode, { localOnly: true }),
+ nativeName: dataLanguages[metaCode].nativeName,
+ code: code,
+ label: _mainLocalizer.languageName(metaCode)
+ });
+ }
+ }
+
+
+ function calcLocked() {
+
+ // only lock the Name field
+ var isLocked = field.id === 'name' &&
+ _entityIDs.length &&
+ // lock the field if any feature needs it
+ _entityIDs.some(function(entityID) {
+
+ var entity = context.graph().hasEntity(entityID);
+ if (!entity) return false;
+
+ var original = context.graph().base().entities[_entityIDs[0]];
+ var hasOriginalName = original && entity.tags.name && entity.tags.name === original.tags.name;
+ // if the name was already edited manually then allow further editing
+ if (!hasOriginalName) return false;
+
+ // features linked to Wikidata are likely important and should be protected
+ if (entity.tags.wikidata) return true;
+
+ // assume the name has already been confirmed if its source has been researched
+ if (entity.tags['name:etymology:wikidata']) return true;
+
+ var preset = _mainPresetIndex.match(entity, context.graph());
+ var isSuggestion = preset && preset.suggestion;
+ var showsBrand = preset && preset.originalFields.filter(function(d) {
+ return d.id === 'brand';
+ }).length;
+ // protect standardized brand names
+ return isSuggestion && !showsBrand;
+ });
+
+ field.locked(isLocked);
+ }
+
+
+ // update _multilingual, maintaining the existing order
+ function calcMultilingual(tags) {
+ var existingLangsOrdered = _multilingual.map(function(item) {
+ return item.lang;
+ });
+ var existingLangs = new Set(existingLangsOrdered.filter(Boolean));
+
+ for (var k in tags) {
+ var m = k.match(/^(.*):([a-zA-Z_-]+)$/);
+ if (m && m[1] === field.key && m[2]) {
+ var item = { lang: m[2], value: tags[k] };
+ if (existingLangs.has(item.lang)) {
+ // update the value
+ _multilingual[existingLangsOrdered.indexOf(item.lang)].value = item.value;
+ existingLangs.delete(item.lang);
+ } else {
+ _multilingual.push(item);
+ }
+ }
+ }
+
+ _multilingual = _multilingual.filter(function(item) {
+ return !item.lang || !existingLangs.has(item.lang);
+ });
+ }
+
+
+ function localized(selection) {
+ _selection = selection;
+ calcLocked();
+ var isLocked = field.locked();
+ var singularEntity = _entityIDs.length === 1 && context.hasEntity(_entityIDs[0]);
+ var preset = singularEntity && _mainPresetIndex.match(singularEntity, context.graph());
+
+ var wrap = selection.selectAll('.form-field-input-wrap')
+ .data([0]);
+
+ // enter/update
+ wrap = wrap.enter()
+ .append('div')
+ .attr('class', 'form-field-input-wrap form-field-input-' + field.type)
+ .merge(wrap);
+
+ input = wrap.selectAll('.localized-main')
+ .data([0]);
+
+ // enter/update
+ input = input.enter()
+ .append('input')
+ .attr('type', 'text')
+ .attr('id', field.domId)
+ .attr('class', 'localized-main')
+ .call(utilNoAuto)
+ .merge(input);
+
+ if (preset && field.id === 'name') {
+ var pTag = preset.id.split('/', 2);
+ var pKey = pTag[0];
+ var pValue = pTag[1];
+
+ if (!preset.suggestion) {
+ // Not a suggestion preset - Add a suggestions dropdown if it makes sense to.
+ // This code attempts to determine if the matched preset is the
+ // kind of preset that even can benefit from name suggestions..
+ // - true = shops, cafes, hotels, etc. (also generic and fallback presets)
+ // - false = churches, parks, hospitals, etc. (things not in the index)
+ var isFallback = preset.isFallback();
+ var goodSuggestions = allSuggestions.filter(function(s) {
+ if (isFallback) return true;
+ var sTag = s.id.split('/', 2);
+ var sKey = sTag[0];
+ var sValue = sTag[1];
+ return pKey === sKey && (!pValue || pValue === sValue);
+ });
+
+ // Show the suggestions.. If the user picks one, change the tags..
+ if (allSuggestions.length && goodSuggestions.length) {
+ input
+ .on('blur.localized', checkBrandOnBlur)
+ .call(brandCombo
+ .fetcher(fetchBrandNames(preset, allSuggestions))
+ .on('accept', acceptBrand)
+ .on('cancel', cancelBrand)
+ );
+ }
+ }
+ }
+
+ input
+ .classed('disabled', !!isLocked)
+ .attr('readonly', isLocked || null)
+ .on('input', change(true))
+ .on('blur', change())
+ .on('change', change());
+
+
+ var translateButton = wrap.selectAll('.localized-add')
+ .data([0]);
+
+ translateButton = translateButton.enter()
+ .append('button')
+ .attr('class', 'localized-add form-field-button')
+ .attr('tabindex', -1)
+ .call(svgIcon('#iD-icon-plus'))
+ .merge(translateButton);
+
+ translateButton
+ .classed('disabled', !!isLocked)
+ .call(isLocked ? _buttonTip.destroy : _buttonTip)
+ .on('click', addNew);
+
+
+ if (_tags && !_multilingual.length) {
+ calcMultilingual(_tags);
+ }
+
+ localizedInputs = selection.selectAll('.localized-multilingual')
+ .data([0]);
+
+ localizedInputs = localizedInputs.enter()
+ .append('div')
+ .attr('class', 'localized-multilingual')
+ .merge(localizedInputs);
+
+ localizedInputs
+ .call(renderMultilingual);
+
+ localizedInputs.selectAll('button, input')
+ .classed('disabled', !!isLocked)
+ .attr('readonly', isLocked || null);
+
+
+
+ // We are not guaranteed to get an `accept` or `cancel` when blurring the field.
+ // (This can happen if the user actives the combo, arrows down, and then clicks off to blur)
+ // So compare the current field value against the suggestions one last time.
+ function checkBrandOnBlur() {
+ var latest = _entityIDs.length === 1 && context.hasEntity(_entityIDs[0]);
+ if (!latest) return; // deleting the entity blurred the field?
+
+ var preset = _mainPresetIndex.match(latest, context.graph());
+ if (preset && preset.suggestion) return; // already accepted
+
+ // note: here we are testing against "decorated" names, i.e. 'Starbucks – Cafe'
+ var name = utilGetSetValue(input).trim();
+ var matched = allSuggestions.filter(function(s) { return name === s.name(); });
+
+ if (matched.length === 1) {
+ acceptBrand({ suggestion: matched[0] });
+ } else {
+ cancelBrand();
+ }
+ }
+
+
+ function acceptBrand(d) {
+
+ var entity = _entityIDs.length === 1 && context.hasEntity(_entityIDs[0]);
+
+ if (!d || !entity) {
+ cancelBrand();
+ return;
+ }
+
+ var tags = entity.tags;
+ var geometry = entity.geometry(context.graph());
+ var removed = preset.unsetTags(tags, geometry);
+ for (var k in tags) {
+ tags[k] = removed[k]; // set removed tags to `undefined`
+ }
+ tags = d.suggestion.setTags(tags, geometry);
+ utilGetSetValue(input, tags.name);
+ dispatch$1.call('change', this, tags);
+ }
+
+
+ // user hit escape, clean whatever preset name appears after the last ' – '
+ function cancelBrand() {
+ var name = utilGetSetValue(input);
+ var clean = cleanName(name);
+ if (clean !== name) {
+ utilGetSetValue(input, clean);
+ dispatch$1.call('change', this, { name: clean });
+ }
+ }
+
+ // Remove whatever is after the last ' – '
+ // NOTE: split/join on en-dash, not a hypen (to avoid conflict with fr - nl names in Brussels etc)
+ function cleanName(name) {
+ var parts = name.split(' – ');
+ if (parts.length > 1) {
+ parts.pop();
+ name = parts.join(' – ');
+ }
+ return name;
+ }
+
+
+ function fetchBrandNames(preset, suggestions) {
+ var pTag = preset.id.split('/', 2);
+ var pKey = pTag[0];
+ var pValue = pTag[1];
+
+ return function(value, callback) {
+ var results = [];
+ if (value && value.length > 2) {
+ for (var i = 0; i < suggestions.length; i++) {
+ var s = suggestions[i];
+
+ // don't suggest brands from incompatible countries
+ if (_countryCode && s.countryCodes &&
+ s.countryCodes.indexOf(_countryCode) === -1) continue;
+
+ var sTag = s.id.split('/', 2);
+ var sKey = sTag[0];
+ var sValue = sTag[1];
+ var name = s.name();
+ var dist = utilEditDistance(value, name.substring(0, value.length));
+ var matchesPreset = (pKey === sKey && (!pValue || pValue === sValue));
+
+ if (dist < 1 || (matchesPreset && dist < 3)) {
+ var obj = {
+ title: name,
+ value: name,
+ suggestion: s,
+ dist: dist + (matchesPreset ? 0 : 1) // penalize if not matched preset
+ };
+ results.push(obj);
+ }
+ }
+ results.sort(function(a, b) { return a.dist - b.dist; });
+ }
+ results = results.slice(0, 10);
+ callback(results);
+ };
+ }
+
+
+ function addNew() {
+ event.preventDefault();
+ if (field.locked()) return;
+
+ var defaultLang = _mainLocalizer.languageCode().toLowerCase();
+ var langExists = _multilingual.find(function(datum) { return datum.lang === defaultLang; });
+ var isLangEn = defaultLang.indexOf('en') > -1;
+ if (isLangEn || langExists) {
+ defaultLang = '';
+ langExists = _multilingual.find(function(datum) { return datum.lang === defaultLang; });
+ }
+
+ if (!langExists) {
+ // prepend the value so it appears at the top
+ _multilingual.unshift({ lang: defaultLang, value: '' });
+
+ localizedInputs
+ .call(renderMultilingual);
+ }
+ }
+
+
+ function change(onInput) {
+ return function() {
+ if (field.locked()) {
+ event.preventDefault();
+ return;
+ }
+
+ var val = utilGetSetValue(select(this));
+ if (!onInput) val = context.cleanTagValue(val);
+
+ // don't override multiple values with blank string
+ if (!val && Array.isArray(_tags[field.key])) return;
+
+ var t = {};
+
+ t[field.key] = val || undefined;
+ dispatch$1.call('change', this, t, onInput);
+ };
+ }
+ }
+
+
+ function key(lang) {
+ return field.key + ':' + lang;
+ }
+
+
+ function changeLang(d) {
+ var tags = {};
+
+ // make sure unrecognized suffixes are lowercase - #7156
+ var lang = utilGetSetValue(select(this)).toLowerCase();
+
+ var language = _languagesArray.find(function(d) {
+ return d.label.toLowerCase() === lang ||
+ (d.localName && d.localName.toLowerCase() === lang) ||
+ (d.nativeName && d.nativeName.toLowerCase() === lang);
+ });
+ if (language) lang = language.code;
+
+ if (d.lang && d.lang !== lang) {
+ tags[key(d.lang)] = undefined;
+ }
+
+ var newKey = lang && context.cleanTagKey(key(lang));
+
+ var value = utilGetSetValue(select(this.parentNode).selectAll('.localized-value'));
+
+ if (newKey && value) {
+ tags[newKey] = value;
+ } else if (newKey && _wikiTitles && _wikiTitles[d.lang]) {
+ tags[newKey] = _wikiTitles[d.lang];
+ }
+
+ d.lang = lang;
+ dispatch$1.call('change', this, tags);
+ }
+
+
+ function changeValue(d) {
+ if (!d.lang) return;
+ var value = context.cleanTagValue(utilGetSetValue(select(this))) || undefined;
+
+ // don't override multiple values with blank string
+ if (!value && Array.isArray(d.value)) return;
+
+ var t = {};
+ t[key(d.lang)] = value;
+ d.value = value;
+ dispatch$1.call('change', this, t);
+ }
+
+
+ function fetchLanguages(value, cb) {
+ var v = value.toLowerCase();
+
+ // show the user's language first
+ var langCodes = [_mainLocalizer.localeCode(), _mainLocalizer.languageCode()];
+
+ if (_countryCode && _territoryLanguages[_countryCode]) {
+ langCodes = langCodes.concat(_territoryLanguages[_countryCode]);
+ }
+
+ var langItems = [];
+ langCodes.forEach(function(code) {
+ var langItem = _languagesArray.find(function(item) {
+ return item.code === code;
+ });
+ if (langItem) langItems.push(langItem);
+ });
+ langItems = utilArrayUniq(langItems.concat(_languagesArray));
+
+ cb(langItems.filter(function(d) {
+ return d.label.toLowerCase().indexOf(v) >= 0 ||
+ (d.localName && d.localName.toLowerCase().indexOf(v) >= 0) ||
+ (d.nativeName && d.nativeName.toLowerCase().indexOf(v) >= 0) ||
+ d.code.toLowerCase().indexOf(v) >= 0;
+ }).map(function(d) {
+ return { value: d.label };
+ }));
+ }
+
+
+ function renderMultilingual(selection) {
+ var entries = selection.selectAll('div.entry')
+ .data(_multilingual, function(d) { return d.lang; });
+
+ entries.exit()
+ .style('top', '0')
+ .style('max-height', '240px')
+ .transition()
+ .duration(200)
+ .style('opacity', '0')
+ .style('max-height', '0px')
+ .remove();
+
+ var entriesEnter = entries.enter()
+ .append('div')
+ .attr('class', 'entry')
+ .each(function(_, index) {
+ var wrap = select(this);
+
+ var domId = utilUniqueDomId(index);
+
+ var label = wrap
+ .append('label')
+ .attr('class', 'field-label')
+ .attr('for', domId);
+
+ var text = label
+ .append('span')
+ .attr('class', 'label-text');
+
+ text
+ .append('span')
+ .attr('class', 'label-textvalue')
+ .text(_t('translate.localized_translation_label'));
+
+ text
+ .append('span')
+ .attr('class', 'label-textannotation');
+
+ label
+ .append('button')
+ .attr('class', 'remove-icon-multilingual')
+ .on('click', function(d, index) {
+ if (field.locked()) return;
+ event.preventDefault();
+
+ if (!d.lang || !d.value) {
+ _multilingual.splice(index, 1);
+ renderMultilingual(selection);
+ } else {
+ // remove from entity tags
+ var t = {};
+ t[key(d.lang)] = undefined;
+ dispatch$1.call('change', this, t);
+ }
+
+ })
+ .call(svgIcon('#iD-operation-delete'));
+
+ wrap
+ .append('input')
+ .attr('class', 'localized-lang')
+ .attr('id', domId)
+ .attr('type', 'text')
+ .attr('placeholder', _t('translate.localized_translation_language'))
+ .on('blur', changeLang)
+ .on('change', changeLang)
+ .call(langCombo);
+
+ wrap
+ .append('input')
+ .attr('type', 'text')
+ .attr('class', 'localized-value')
+ .on('blur', changeValue)
+ .on('change', changeValue);
+ });
+
+ entriesEnter
+ .style('margin-top', '0px')
+ .style('max-height', '0px')
+ .style('opacity', '0')
+ .transition()
+ .duration(200)
+ .style('margin-top', '10px')
+ .style('max-height', '240px')
+ .style('opacity', '1')
+ .on('end', function() {
+ select(this)
+ .style('max-height', '')
+ .style('overflow', 'visible');
+ });
+
+ entries = entries.merge(entriesEnter);
+
+ entries.order();
+
+ entries.classed('present', function(d) {
+ return d.lang && d.value;
+ });
+
+ utilGetSetValue(entries.select('.localized-lang'), function(d) {
+ return _mainLocalizer.languageName(d.lang);
+ });
+
+ utilGetSetValue(entries.select('.localized-value'), function(d) {
+ return typeof d.value === 'string' ? d.value : '';
+ })
+ .attr('title', function(d) {
+ return Array.isArray(d.value) ? d.value.filter(Boolean).join('\n') : null;
+ })
+ .attr('placeholder', function(d) {
+ return Array.isArray(d.value) ? _t('inspector.multiple_values') : _t('translate.localized_translation_name');
+ })
+ .classed('mixed', function(d) {
+ return Array.isArray(d.value);
+ });
+ }
+
+
+ localized.tags = function(tags) {
+ _tags = tags;
+
+ // Fetch translations from wikipedia
+ if (typeof tags.wikipedia === 'string' && !_wikiTitles) {
+ _wikiTitles = {};
+ var wm = tags.wikipedia.match(/([^:]+):(.+)/);
+ if (wm && wm[0] && wm[1]) {
+ wikipedia.translations(wm[1], wm[2], function(err, d) {
+ if (err || !d) return;
+ _wikiTitles = d;
+ });
+ }
+ }
+
+ var isMixed = Array.isArray(tags[field.key]);
+
+ utilGetSetValue(input, typeof tags[field.key] === 'string' ? tags[field.key] : '')
+ .attr('title', isMixed ? tags[field.key].filter(Boolean).join('\n') : undefined)
+ .attr('placeholder', isMixed ? _t('inspector.multiple_values') : field.placeholder())
+ .classed('mixed', isMixed);
+
+ calcMultilingual(tags);
+
+ _selection
+ .call(localized);
+ };
+
+
+ localized.focus = function() {
+ input.node().focus();
+ };
+
+
+ localized.entityIDs = function(val) {
+ if (!arguments.length) return _entityIDs;
+ _entityIDs = val;
+ _multilingual = [];
+ loadCountryCode();
+ return localized;
+ };
+
+ function loadCountryCode() {
+ var extent = combinedEntityExtent();
+ var countryCode = extent && iso1A2Code(extent.center());
+ _countryCode = countryCode && countryCode.toLowerCase();
+ }
+
+ function combinedEntityExtent() {
+ return _entityIDs && _entityIDs.length && utilTotalExtent(_entityIDs, context.graph());
+ }
+
+ return utilRebind(localized, dispatch$1, 'on');
+ }
+
+ function uiFieldMaxspeed(field, context) {
+ var dispatch$1 = dispatch('change');
+ var unitInput = select(null);
+ var input = select(null);
+ var _entityIDs = [];
+ var _tags;
+ var _isImperial;
+
+ var speedCombo = uiCombobox(context, 'maxspeed');
+ var unitCombo = uiCombobox(context, 'maxspeed-unit')
+ .data(['km/h', 'mph'].map(comboValues));
+
+ var metricValues = [20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120];
+ var imperialValues = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80];
+
+
+ function maxspeed(selection) {
+
+ var wrap = selection.selectAll('.form-field-input-wrap')
+ .data([0]);
+
+ wrap = wrap.enter()
+ .append('div')
+ .attr('class', 'form-field-input-wrap form-field-input-' + field.type)
+ .merge(wrap);
+
+
+ input = wrap.selectAll('input.maxspeed-number')
+ .data([0]);
+
+ input = input.enter()
+ .append('input')
+ .attr('type', 'text')
+ .attr('class', 'maxspeed-number')
+ .attr('id', field.domId)
+ .call(utilNoAuto)
+ .call(speedCombo)
+ .merge(input);
+
+ input
+ .on('change', change)
+ .on('blur', change);
+
+ var loc = combinedEntityExtent().center();
+ _isImperial = roadSpeedUnit(loc) === 'mph';
+
+ unitInput = wrap.selectAll('input.maxspeed-unit')
+ .data([0]);
+
+ unitInput = unitInput.enter()
+ .append('input')
+ .attr('type', 'text')
+ .attr('class', 'maxspeed-unit')
+ .call(unitCombo)
+ .merge(unitInput);
+
+ unitInput
+ .on('blur', changeUnits)
+ .on('change', changeUnits);
+
+
+ function changeUnits() {
+ _isImperial = utilGetSetValue(unitInput) === 'mph';
+ utilGetSetValue(unitInput, _isImperial ? 'mph' : 'km/h');
+ setUnitSuggestions();
+ change();
+ }
+ }
+
+
+ function setUnitSuggestions() {
+ speedCombo.data((_isImperial ? imperialValues : metricValues).map(comboValues));
+ utilGetSetValue(unitInput, _isImperial ? 'mph' : 'km/h');
+ }
+
+
+ function comboValues(d) {
+ return {
+ value: d.toString(),
+ title: d.toString()
+ };
+ }
+
+
+ function change() {
+ var tag = {};
+ var value = utilGetSetValue(input).trim();
+
+ // don't override multiple values with blank string
+ if (!value && Array.isArray(_tags[field.key])) return;
+
+ if (!value) {
+ tag[field.key] = undefined;
+ } else if (isNaN(value) || !_isImperial) {
+ tag[field.key] = context.cleanTagValue(value);
+ } else {
+ tag[field.key] = context.cleanTagValue(value + ' mph');
+ }
+
+ dispatch$1.call('change', this, tag);
+ }
+
+
+ maxspeed.tags = function(tags) {
+ _tags = tags;
+
+ var value = tags[field.key];
+ var isMixed = Array.isArray(value);
+
+ if (!isMixed) {
+ if (value && value.indexOf('mph') >= 0) {
+ value = parseInt(value, 10).toString();
+ _isImperial = true;
+ } else if (value) {
+ _isImperial = false;
+ }
+ }
+
+ setUnitSuggestions();
+
+ utilGetSetValue(input, typeof value === 'string' ? value : '')
+ .attr('title', isMixed ? value.filter(Boolean).join('\n') : null)
+ .attr('placeholder', isMixed ? _t('inspector.multiple_values') : field.placeholder())
+ .classed('mixed', isMixed);
+ };
+
+
+ maxspeed.focus = function() {
+ input.node().focus();
+ };
+
+
+ maxspeed.entityIDs = function(val) {
+ _entityIDs = val;
+ };
+
+
+ function combinedEntityExtent() {
+ return _entityIDs && _entityIDs.length && utilTotalExtent(_entityIDs, context.graph());
+ }
+
+
+ return utilRebind(maxspeed, dispatch$1, 'on');
+ }
+
+ function uiFieldRadio(field, context) {
+ var dispatch$1 = dispatch('change');
+ var placeholder = select(null);
+ var wrap = select(null);
+ var labels = select(null);
+ var radios = select(null);
+ var radioData = (field.options || (field.strings && field.strings.options && Object.keys(field.strings.options)) || field.keys).slice(); // shallow copy
+ var typeField;
+ var layerField;
+ var _oldType = {};
+ var _entityIDs = [];
+
+
+ function selectedKey() {
+ var node = wrap.selectAll('.form-field-input-radio label.active input');
+ return !node.empty() && node.datum();
+ }
+
+
+ function radio(selection) {
+ selection.classed('preset-radio', true);
+
+ wrap = selection.selectAll('.form-field-input-wrap')
+ .data([0]);
+
+ var enter = wrap.enter()
+ .append('div')
+ .attr('class', 'form-field-input-wrap form-field-input-radio');
+
+ enter
+ .append('span')
+ .attr('class', 'placeholder');
+
+ wrap = wrap
+ .merge(enter);
+
+
+ placeholder = wrap.selectAll('.placeholder');
+
+ labels = wrap.selectAll('label')
+ .data(radioData);
+
+ enter = labels.enter()
+ .append('label');
+
+ enter
+ .append('input')
+ .attr('type', 'radio')
+ .attr('name', field.id)
+ .attr('value', function(d) { return field.t('options.' + d, { 'default': d }); })
+ .attr('checked', false);
+
+ enter
+ .append('span')
+ .text(function(d) { return field.t('options.' + d, { 'default': d }); });
+
+ labels = labels
+ .merge(enter);
+
+ radios = labels.selectAll('input')
+ .on('change', changeRadio);
+
+ }
+
+
+ function structureExtras(selection, tags) {
+ var selected = selectedKey() || tags.layer !== undefined;
+ var type = _mainPresetIndex.field(selected);
+ var layer = _mainPresetIndex.field('layer');
+ var showLayer = (selected === 'bridge' || selected === 'tunnel' || tags.layer !== undefined);
+
+
+ var extrasWrap = selection.selectAll('.structure-extras-wrap')
+ .data(selected ? [0] : []);
+
+ extrasWrap.exit()
+ .remove();
+
+ extrasWrap = extrasWrap.enter()
+ .append('div')
+ .attr('class', 'structure-extras-wrap')
+ .merge(extrasWrap);
+
+ var list = extrasWrap.selectAll('ul')
+ .data([0]);
+
+ list = list.enter()
+ .append('ul')
+ .attr('class', 'rows')
+ .merge(list);
+
+
+ // Type
+ if (type) {
+ if (!typeField || typeField.id !== selected) {
+ typeField = uiField(context, type, _entityIDs, { wrap: false })
+ .on('change', changeType);
+ }
+ typeField.tags(tags);
+ } else {
+ typeField = null;
+ }
+
+ var typeItem = list.selectAll('.structure-type-item')
+ .data(typeField ? [typeField] : [], function(d) { return d.id; });
+
+ // Exit
+ typeItem.exit()
+ .remove();
+
+ // Enter
+ var typeEnter = typeItem.enter()
+ .insert('li', ':first-child')
+ .attr('class', 'labeled-input structure-type-item');
+
+ typeEnter
+ .append('span')
+ .attr('class', 'label structure-label-type')
+ .attr('for', 'preset-input-' + selected)
+ .text(_t('inspector.radio.structure.type'));
+
+ typeEnter
+ .append('div')
+ .attr('class', 'structure-input-type-wrap');
+
+ // Update
+ typeItem = typeItem
+ .merge(typeEnter);
+
+ if (typeField) {
+ typeItem.selectAll('.structure-input-type-wrap')
+ .call(typeField.render);
+ }
+
+
+ // Layer
+ if (layer && showLayer) {
+ if (!layerField) {
+ layerField = uiField(context, layer, _entityIDs, { wrap: false })
+ .on('change', changeLayer);
+ }
+ layerField.tags(tags);
+ field.keys = utilArrayUnion(field.keys, ['layer']);
+ } else {
+ layerField = null;
+ field.keys = field.keys.filter(function(k) { return k !== 'layer'; });
+ }
+
+ var layerItem = list.selectAll('.structure-layer-item')
+ .data(layerField ? [layerField] : []);
+
+ // Exit
+ layerItem.exit()
+ .remove();
+
+ // Enter
+ var layerEnter = layerItem.enter()
+ .append('li')
+ .attr('class', 'labeled-input structure-layer-item');
+
+ layerEnter
+ .append('span')
+ .attr('class', 'label structure-label-layer')
+ .attr('for', 'preset-input-layer')
+ .text(_t('inspector.radio.structure.layer'));
+
+ layerEnter
+ .append('div')
+ .attr('class', 'structure-input-layer-wrap');
+
+ // Update
+ layerItem = layerItem
+ .merge(layerEnter);
+
+ if (layerField) {
+ layerItem.selectAll('.structure-input-layer-wrap')
+ .call(layerField.render);
+ }
+ }
+
+
+ function changeType(t, onInput) {
+ var key = selectedKey();
+ if (!key) return;
+
+ var val = t[key];
+ if (val !== 'no') {
+ _oldType[key] = val;
+ }
+
+ if (field.type === 'structureRadio') {
+ // remove layer if it should not be set
+ if (val === 'no' ||
+ (key !== 'bridge' && key !== 'tunnel') ||
+ (key === 'tunnel' && val === 'building_passage')) {
+ t.layer = undefined;
+ }
+ // add layer if it should be set
+ if (t.layer === undefined) {
+ if (key === 'bridge' && val !== 'no') {
+ t.layer = '1';
+ }
+ if (key === 'tunnel' && val !== 'no' && val !== 'building_passage') {
+ t.layer = '-1';
+ }
+ }
+ }
+
+ dispatch$1.call('change', this, t, onInput);
+ }
+
+
+ function changeLayer(t, onInput) {
+ if (t.layer === '0') {
+ t.layer = undefined;
+ }
+ dispatch$1.call('change', this, t, onInput);
+ }
+
+
+ function changeRadio() {
+ var t = {};
+ var activeKey;
+
+ if (field.key) {
+ t[field.key] = undefined;
+ }
+
+ radios.each(function(d) {
+ var active = select(this).property('checked');
+ if (active) activeKey = d;
+
+ if (field.key) {
+ if (active) t[field.key] = d;
+ } else {
+ var val = _oldType[activeKey] || 'yes';
+ t[d] = active ? val : undefined;
+ }
+ });
+
+ if (field.type === 'structureRadio') {
+ if (activeKey === 'bridge') {
+ t.layer = '1';
+ } else if (activeKey === 'tunnel' && t.tunnel !== 'building_passage') {
+ t.layer = '-1';
+ } else {
+ t.layer = undefined;
+ }
+ }
+
+ dispatch$1.call('change', this, t);
+ }
+
+
+ radio.tags = function(tags) {
+
+ radios.property('checked', function(d) {
+ if (field.key) {
+ return tags[field.key] === d;
+ }
+ return !!(typeof tags[d] === 'string' && tags[d].toLowerCase() !== 'no');
+ });
+
+ function isMixed(d) {
+ if (field.key) {
+ return Array.isArray(tags[field.key]) && tags[field.key].includes(d);
+ }
+ return Array.isArray(tags[d]);
+ }
+
+ labels
+ .classed('active', function(d) {
+ if (field.key) {
+ return (Array.isArray(tags[field.key]) && tags[field.key].includes(d))
+ || tags[field.key] === d;
+ }
+ return Array.isArray(tags[d]) || !!(tags[d] && tags[d].toLowerCase() !== 'no');
+ })
+ .classed('mixed', isMixed)
+ .attr('title', function(d) {
+ return isMixed(d) ? _t('inspector.unshared_value_tooltip') : null;
+ });
+
+
+ var selection = radios.filter(function() { return this.checked; });
+
+ if (selection.empty()) {
+ placeholder.text(_t('inspector.none'));
+ } else {
+ placeholder.text(selection.attr('value'));
+ _oldType[selection.datum()] = tags[selection.datum()];
+ }
+
+ if (field.type === 'structureRadio') {
+ // For waterways without a tunnel tag, set 'culvert' as
+ // the _oldType to default to if the user picks 'tunnel'
+ if (!!tags.waterway && !_oldType.tunnel) {
+ _oldType.tunnel = 'culvert';
+ }
+
+ wrap.call(structureExtras, tags);
+ }
+ };
+
+
+ radio.focus = function() {
+ radios.node().focus();
+ };
+
+
+ radio.entityIDs = function(val) {
+ if (!arguments.length) return _entityIDs;
+ _entityIDs = val;
+ _oldType = {};
+ return radio;
+ };
+
+
+ radio.isAllowed = function() {
+ return _entityIDs.length === 1;
+ };
+
+
+ return utilRebind(radio, dispatch$1, 'on');
+ }
+
+ function uiFieldRestrictions(field, context) {
+ var dispatch$1 = dispatch('change');
+ var breathe = behaviorBreathe();
+
+ corePreferences('turn-restriction-via-way', null); // remove old key
+ var storedViaWay = corePreferences('turn-restriction-via-way0'); // use new key #6922
+ var storedDistance = corePreferences('turn-restriction-distance');
+
+ var _maxViaWay = storedViaWay !== null ? (+storedViaWay) : 0;
+ var _maxDistance = storedDistance ? (+storedDistance) : 30;
+ var _initialized = false;
+ var _parent = select(null); // the entire field
+ var _container = select(null); // just the map
+ var _oldTurns;
+ var _graph;
+ var _vertexID;
+ var _intersection;
+ var _fromWayID;
+
+ var _lastXPos;
+
+
+ function restrictions(selection) {
+ _parent = selection;
+
+ // try to reuse the intersection, but always rebuild it if the graph has changed
+ if (_vertexID && (context.graph() !== _graph || !_intersection)) {
+ _graph = context.graph();
+ _intersection = osmIntersection(_graph, _vertexID, _maxDistance);
+ }
+
+ // It's possible for there to be no actual intersection here.
+ // for example, a vertex of two `highway=path`
+ // In this case, hide the field.
+ var isOK = (
+ _intersection &&
+ _intersection.vertices.length && // has vertices
+ _intersection.vertices // has the vertex that the user selected
+ .filter(function(vertex) { return vertex.id === _vertexID; }).length &&
+ _intersection.ways.length > 2 && // has more than 2 ways
+ _intersection.ways // has more than 1 TO way
+ .filter(function(way) { return way.__to; }).length > 1
+ );
+
+ // Also hide in the case where
+ select(selection.node().parentNode).classed('hide', !isOK);
+
+ // if form field is hidden or has detached from dom, clean up.
+ if (!isOK ||
+ !context.container().select('.inspector-wrap.inspector-hidden').empty() ||
+ !selection.node().parentNode ||
+ !selection.node().parentNode.parentNode) {
+ selection.call(restrictions.off);
+ return;
+ }
+
+
+ var wrap = selection.selectAll('.form-field-input-wrap')
+ .data([0]);
+
+ wrap = wrap.enter()
+ .append('div')
+ .attr('class', 'form-field-input-wrap form-field-input-' + field.type)
+ .merge(wrap);
+
+ var container = wrap.selectAll('.restriction-container')
+ .data([0]);
+
+ // enter
+ var containerEnter = container.enter()
+ .append('div')
+ .attr('class', 'restriction-container');
+
+ containerEnter
+ .append('div')
+ .attr('class', 'restriction-help');
+
+ // update
+ _container = containerEnter
+ .merge(container)
+ .call(renderViewer);
+
+ var controls = wrap.selectAll('.restriction-controls')
+ .data([0]);
+
+ // enter/update
+ controls.enter()
+ .append('div')
+ .attr('class', 'restriction-controls-container')
+ .append('div')
+ .attr('class', 'restriction-controls')
+ .merge(controls)
+ .call(renderControls);
+ }
+
+
+ function renderControls(selection) {
+ var distControl = selection.selectAll('.restriction-distance')
+ .data([0]);
+
+ distControl.exit()
+ .remove();
+
+ var distControlEnter = distControl.enter()
+ .append('div')
+ .attr('class', 'restriction-control restriction-distance');
+
+ distControlEnter
+ .append('span')
+ .attr('class', 'restriction-control-label restriction-distance-label')
+ .text(_t('restriction.controls.distance') + ':');
+
+ distControlEnter
+ .append('input')
+ .attr('class', 'restriction-distance-input')
+ .attr('type', 'range')
+ .attr('min', '20')
+ .attr('max', '50')
+ .attr('step', '5');
+
+ distControlEnter
+ .append('span')
+ .attr('class', 'restriction-distance-text');
+
+ // update
+ selection.selectAll('.restriction-distance-input')
+ .property('value', _maxDistance)
+ .on('input', function() {
+ var val = select(this).property('value');
+ _maxDistance = +val;
+ _intersection = null;
+ _container.selectAll('.layer-osm .layer-turns *').remove();
+ corePreferences('turn-restriction-distance', _maxDistance);
+ _parent.call(restrictions);
+ });
+
+ selection.selectAll('.restriction-distance-text')
+ .text(displayMaxDistance(_maxDistance));
+
+
+ var viaControl = selection.selectAll('.restriction-via-way')
+ .data([0]);
+
+ viaControl.exit()
+ .remove();
+
+ var viaControlEnter = viaControl.enter()
+ .append('div')
+ .attr('class', 'restriction-control restriction-via-way');
+
+ viaControlEnter
+ .append('span')
+ .attr('class', 'restriction-control-label restriction-via-way-label')
+ .text(_t('restriction.controls.via') + ':');
+
+ viaControlEnter
+ .append('input')
+ .attr('class', 'restriction-via-way-input')
+ .attr('type', 'range')
+ .attr('min', '0')
+ .attr('max', '2')
+ .attr('step', '1');
+
+ viaControlEnter
+ .append('span')
+ .attr('class', 'restriction-via-way-text');
+
+ // update
+ selection.selectAll('.restriction-via-way-input')
+ .property('value', _maxViaWay)
+ .on('input', function() {
+ var val = select(this).property('value');
+ _maxViaWay = +val;
+ _container.selectAll('.layer-osm .layer-turns *').remove();
+ corePreferences('turn-restriction-via-way0', _maxViaWay);
+ _parent.call(restrictions);
+ });
+
+ selection.selectAll('.restriction-via-way-text')
+ .text(displayMaxVia(_maxViaWay));
+ }
+
+
+ function renderViewer(selection) {
+ if (!_intersection) return;
+
+ var vgraph = _intersection.graph;
+ var filter = utilFunctor(true);
+ var projection = geoRawMercator();
+
+ // Reflow warning: `utilGetDimensions` calls `getBoundingClientRect`
+ // Instead of asking the restriction-container for its dimensions,
+ // we can ask the .sidebar, which can have its dimensions cached.
+ // width: calc as sidebar - padding
+ // height: hardcoded (from `80_app.css`)
+ // var d = utilGetDimensions(selection);
+ var sdims = utilGetDimensions(context.container().select('.sidebar'));
+ var d = [ sdims[0] - 50, 370 ];
+ var c = geoVecScale(d, 0.5);
+ var z = 22;
+
+ projection.scale(geoZoomToScale(z));
+
+ // Calculate extent of all key vertices
+ var extent = geoExtent();
+ for (var i = 0; i < _intersection.vertices.length; i++) {
+ extent._extend(_intersection.vertices[i].extent());
+ }
+
+ // If this is a large intersection, adjust zoom to fit extent
+ if (_intersection.vertices.length > 1) {
+ var padding = 180; // in z22 pixels
+ var tl = projection([extent[0][0], extent[1][1]]);
+ var br = projection([extent[1][0], extent[0][1]]);
+ var hFactor = (br[0] - tl[0]) / (d[0] - padding);
+ var vFactor = (br[1] - tl[1]) / (d[1] - padding);
+ var hZoomDiff = Math.log(Math.abs(hFactor)) / Math.LN2;
+ var vZoomDiff = Math.log(Math.abs(vFactor)) / Math.LN2;
+ z = z - Math.max(hZoomDiff, vZoomDiff);
+ projection.scale(geoZoomToScale(z));
+ }
+
+ var padTop = 35; // reserve top space for hint text
+ var extentCenter = projection(extent.center());
+ extentCenter[1] = extentCenter[1] - padTop;
+
+ projection
+ .translate(geoVecSubtract(c, extentCenter))
+ .clipExtent([[0, 0], d]);
+
+ var drawLayers = svgLayers(projection, context).only(['osm','touch']).dimensions(d);
+ var drawVertices = svgVertices(projection, context);
+ var drawLines = svgLines(projection, context);
+ var drawTurns = svgTurns(projection, context);
+
+ var firstTime = selection.selectAll('.surface').empty();
+
+ selection
+ .call(drawLayers);
+
+ var surface = selection.selectAll('.surface')
+ .classed('tr', true);
+
+ if (firstTime) {
+ _initialized = true;
+
+ surface
+ .call(breathe);
+ }
+
+ // This can happen if we've lowered the detail while a FROM way
+ // is selected, and that way is no longer part of the intersection.
+ if (_fromWayID && !vgraph.hasEntity(_fromWayID)) {
+ _fromWayID = null;
+ _oldTurns = null;
+ }
+
+ surface
+ .call(utilSetDimensions, d)
+ .call(drawVertices, vgraph, _intersection.vertices, filter, extent, z)
+ .call(drawLines, vgraph, _intersection.ways, filter)
+ .call(drawTurns, vgraph, _intersection.turns(_fromWayID, _maxViaWay));
+
+ surface
+ .on('click.restrictions', click)
+ .on('mouseover.restrictions', mouseover);
+
+ surface
+ .selectAll('.selected')
+ .classed('selected', false);
+
+ surface
+ .selectAll('.related')
+ .classed('related', false);
+
+ if (_fromWayID) {
+ var way = vgraph.entity(_fromWayID);
+ surface
+ .selectAll('.' + _fromWayID)
+ .classed('selected', true)
+ .classed('related', true);
+ }
+
+ document.addEventListener('resizeWindow', function () {
+ utilSetDimensions(_container, null);
+ redraw(1);
+ }, false);
+
+ updateHints(null);
+
+
+ function click() {
+ surface
+ .call(breathe.off)
+ .call(breathe);
+
+ var datum = event.target.__data__;
+ var entity = datum && datum.properties && datum.properties.entity;
+ if (entity) {
+ datum = entity;
+ }
+
+ if (datum instanceof osmWay && (datum.__from || datum.__via)) {
+ _fromWayID = datum.id;
+ _oldTurns = null;
+ redraw();
+
+ } else if (datum instanceof osmTurn) {
+ var actions, extraActions, turns, i;
+ var restrictionType = osmInferRestriction(vgraph, datum, projection);
+
+ if (datum.restrictionID && !datum.direct) {
+ return;
+
+ } else if (datum.restrictionID && !datum.only) { // NO -> ONLY
+ var seen = {};
+ var datumOnly = JSON.parse(JSON.stringify(datum)); // deep clone the datum
+ datumOnly.only = true; // but change this property
+ restrictionType = restrictionType.replace(/^no/, 'only');
+
+ // Adding an ONLY restriction should destroy all other direct restrictions from the FROM towards the VIA.
+ // We will remember them in _oldTurns, and restore them if the user clicks again.
+ turns = _intersection.turns(_fromWayID, 2);
+ extraActions = [];
+ _oldTurns = [];
+ for (i = 0; i < turns.length; i++) {
+ var turn = turns[i];
+ if (seen[turn.restrictionID]) continue; // avoid deleting the turn twice (#4968, #4928)
+
+ if (turn.direct && turn.path[1] === datum.path[1]) {
+ seen[turns[i].restrictionID] = true;
+ turn.restrictionType = osmInferRestriction(vgraph, turn, projection);
+ _oldTurns.push(turn);
+ extraActions.push(actionUnrestrictTurn(turn));
+ }
+ }
+
+ actions = _intersection.actions.concat(extraActions, [
+ actionRestrictTurn(datumOnly, restrictionType),
+ _t('operations.restriction.annotation.create')
+ ]);
+
+ } else if (datum.restrictionID) { // ONLY -> Allowed
+ // Restore whatever restrictions we might have destroyed by cycling thru the ONLY state.
+ // This relies on the assumption that the intersection was already split up when we
+ // performed the previous action (NO -> ONLY), so the IDs in _oldTurns shouldn't have changed.
+ turns = _oldTurns || [];
+ extraActions = [];
+ for (i = 0; i < turns.length; i++) {
+ if (turns[i].key !== datum.key) {
+ extraActions.push(actionRestrictTurn(turns[i], turns[i].restrictionType));
+ }
+ }
+ _oldTurns = null;
+
+ actions = _intersection.actions.concat(extraActions, [
+ actionUnrestrictTurn(datum),
+ _t('operations.restriction.annotation.delete')
+ ]);
+
+ } else { // Allowed -> NO
+ actions = _intersection.actions.concat([
+ actionRestrictTurn(datum, restrictionType),
+ _t('operations.restriction.annotation.create')
+ ]);
+ }
+
+ context.perform.apply(context, actions);
+
+ // At this point the datum will be changed, but will have same key..
+ // Refresh it and update the help..
+ var s = surface.selectAll('.' + datum.key);
+ datum = s.empty() ? null : s.datum();
+ updateHints(datum);
+
+ } else {
+ _fromWayID = null;
+ _oldTurns = null;
+ redraw();
+ }
+ }
+
+
+ function mouseover() {
+ var datum = event.target.__data__;
+ updateHints(datum);
+ }
+
+ _lastXPos = _lastXPos || sdims[0];
+
+ function redraw(minChange) {
+ var xPos = -1;
+
+ if (minChange) {
+ xPos = utilGetDimensions(context.container().select('.sidebar'))[0];
+ }
+
+ if (!minChange || (minChange && Math.abs(xPos - _lastXPos) >= minChange)) {
+ if (context.hasEntity(_vertexID)) {
+ _lastXPos = xPos;
+ _container.call(renderViewer);
+ }
+ }
+ }
+
+
+ function highlightPathsFrom(wayID) {
+ surface.selectAll('.related')
+ .classed('related', false)
+ .classed('allow', false)
+ .classed('restrict', false)
+ .classed('only', false);
+
+ surface.selectAll('.' + wayID)
+ .classed('related', true);
+
+ if (wayID) {
+ var turns = _intersection.turns(wayID, _maxViaWay);
+ for (var i = 0; i < turns.length; i++) {
+ var turn = turns[i];
+ var ids = [turn.to.way];
+ var klass = (turn.no ? 'restrict' : (turn.only ? 'only' : 'allow'));
+
+ if (turn.only || turns.length === 1) {
+ if (turn.via.ways) {
+ ids = ids.concat(turn.via.ways);
+ }
+ } else if (turn.to.way === wayID) {
+ continue;
+ }
+
+ surface.selectAll(utilEntitySelector(ids))
+ .classed('related', true)
+ .classed('allow', (klass === 'allow'))
+ .classed('restrict', (klass === 'restrict'))
+ .classed('only', (klass === 'only'));
+ }
+ }
+ }
+
+
+ function updateHints(datum) {
+ var help = _container.selectAll('.restriction-help').html('');
+
+ var placeholders = {};
+ ['from', 'via', 'to'].forEach(function(k) {
+ placeholders[k] = '' + _t('restriction.help.' + k) + ' ';
+ });
+
+ var entity = datum && datum.properties && datum.properties.entity;
+ if (entity) {
+ datum = entity;
+ }
+
+ if (_fromWayID) {
+ way = vgraph.entity(_fromWayID);
+ surface
+ .selectAll('.' + _fromWayID)
+ .classed('selected', true)
+ .classed('related', true);
+ }
+
+ // Hovering a way
+ if (datum instanceof osmWay && datum.__from) {
+ way = datum;
+
+ highlightPathsFrom(_fromWayID ? null : way.id);
+ surface.selectAll('.' + way.id)
+ .classed('related', true);
+
+ var clickSelect = (!_fromWayID || _fromWayID !== way.id);
+ help
+ .append('div') // "Click to select FROM {fromName}." / "FROM {fromName}"
+ .html(_t('restriction.help.' + (clickSelect ? 'select_from_name' : 'from_name'), {
+ from: placeholders.from,
+ fromName: displayName(way.id, vgraph)
+ }));
+
+
+ // Hovering a turn arrow
+ } else if (datum instanceof osmTurn) {
+ var restrictionType = osmInferRestriction(vgraph, datum, projection);
+ var turnType = restrictionType.replace(/^(only|no)\_/, '');
+ var indirect = (datum.direct === false ? _t('restriction.help.indirect') : '');
+ var klass, turnText, nextText;
+
+ if (datum.no) {
+ klass = 'restrict';
+ turnText = _t('restriction.help.turn.no_' + turnType, { indirect: indirect });
+ nextText = _t('restriction.help.turn.only_' + turnType, { indirect: '' });
+ } else if (datum.only) {
+ klass = 'only';
+ turnText = _t('restriction.help.turn.only_' + turnType, { indirect: indirect });
+ nextText = _t('restriction.help.turn.allowed_' + turnType, { indirect: '' });
+ } else {
+ klass = 'allow';
+ turnText = _t('restriction.help.turn.allowed_' + turnType, { indirect: indirect });
+ nextText = _t('restriction.help.turn.no_' + turnType, { indirect: '' });
+ }
+
+ help
+ .append('div') // "NO Right Turn (indirect)"
+ .attr('class', 'qualifier ' + klass)
+ .text(turnText);
+
+ help
+ .append('div') // "FROM {fromName} TO {toName}"
+ .html(_t('restriction.help.from_name_to_name', {
+ from: placeholders.from,
+ fromName: displayName(datum.from.way, vgraph),
+ to: placeholders.to,
+ toName: displayName(datum.to.way, vgraph)
+ }));
+
+ if (datum.via.ways && datum.via.ways.length) {
+ var names = [];
+ for (var i = 0; i < datum.via.ways.length; i++) {
+ var prev = names[names.length - 1];
+ var curr = displayName(datum.via.ways[i], vgraph);
+ if (!prev || curr !== prev) // collapse identical names
+ names.push(curr);
+ }
+
+ help
+ .append('div') // "VIA {viaNames}"
+ .html(_t('restriction.help.via_names', {
+ via: placeholders.via,
+ viaNames: names.join(', ')
+ }));
+ }
+
+ if (!indirect) {
+ help
+ .append('div') // Click for "No Right Turn"
+ .text(_t('restriction.help.toggle', { turn: nextText.trim() }));
+ }
+
+ highlightPathsFrom(null);
+ var alongIDs = datum.path.slice();
+ surface.selectAll(utilEntitySelector(alongIDs))
+ .classed('related', true)
+ .classed('allow', (klass === 'allow'))
+ .classed('restrict', (klass === 'restrict'))
+ .classed('only', (klass === 'only'));
+
+
+ // Hovering empty surface
+ } else {
+ highlightPathsFrom(null);
+ if (_fromWayID) {
+ help
+ .append('div') // "FROM {fromName}"
+ .html(_t('restriction.help.from_name', {
+ from: placeholders.from,
+ fromName: displayName(_fromWayID, vgraph)
+ }));
+
+ } else {
+ help
+ .append('div') // "Click to select a FROM segment."
+ .html(_t('restriction.help.select_from', {
+ from: placeholders.from
+ }));
+ }
+ }
+ }
+ }
+
+
+ function displayMaxDistance(maxDist) {
+ var isImperial = !_mainLocalizer.usesMetric();
+ var opts;
+
+ if (isImperial) {
+ var distToFeet = { // imprecise conversion for prettier display
+ 20: 70, 25: 85, 30: 100, 35: 115, 40: 130, 45: 145, 50: 160
+ }[maxDist];
+ opts = { distance: _t('units.feet', { quantity: distToFeet }) };
+ } else {
+ opts = { distance: _t('units.meters', { quantity: maxDist }) };
+ }
+
+ return _t('restriction.controls.distance_up_to', opts);
+ }
+
+
+ function displayMaxVia(maxVia) {
+ return maxVia === 0 ? _t('restriction.controls.via_node_only')
+ : maxVia === 1 ? _t('restriction.controls.via_up_to_one')
+ : _t('restriction.controls.via_up_to_two');
+ }
+
+
+ function displayName(entityID, graph) {
+ var entity = graph.entity(entityID);
+ var name = utilDisplayName(entity) || '';
+ var matched = _mainPresetIndex.match(entity, graph);
+ var type = (matched && matched.name()) || utilDisplayType(entity.id);
+ return name || type;
+ }
+
+
+ restrictions.entityIDs = function(val) {
+ _intersection = null;
+ _fromWayID = null;
+ _oldTurns = null;
+ _vertexID = val[0];
+ };
+
+
+ restrictions.tags = function() {};
+ restrictions.focus = function() {};
+
+
+ restrictions.off = function(selection) {
+ if (!_initialized) return;
+
+ selection.selectAll('.surface')
+ .call(breathe.off)
+ .on('click.restrictions', null)
+ .on('mouseover.restrictions', null);
+
+ select(window)
+ .on('resize.restrictions', null);
+ };
+
+
+ return utilRebind(restrictions, dispatch$1, 'on');
+ }
+
+ uiFieldRestrictions.supportsMultiselection = false;
+
+ function uiFieldTextarea(field, context) {
+ var dispatch$1 = dispatch('change');
+ var input = select(null);
+ var _tags;
+
+
+ function textarea(selection) {
+ var wrap = selection.selectAll('.form-field-input-wrap')
+ .data([0]);
+
+ wrap = wrap.enter()
+ .append('div')
+ .attr('class', 'form-field-input-wrap form-field-input-' + field.type)
+ .merge(wrap);
+
+ input = wrap.selectAll('textarea')
+ .data([0]);
+
+ input = input.enter()
+ .append('textarea')
+ .attr('id', field.domId)
+ .call(utilNoAuto)
+ .on('input', change(true))
+ .on('blur', change())
+ .on('change', change())
+ .merge(input);
+ }
+
+
+ function change(onInput) {
+ return function() {
+
+ var val = utilGetSetValue(input);
+ if (!onInput) val = context.cleanTagValue(val);
+
+ // don't override multiple values with blank string
+ if (!val && Array.isArray(_tags[field.key])) return;
+
+ var t = {};
+ t[field.key] = val || undefined;
+ dispatch$1.call('change', this, t, onInput);
+ };
+ }
+
+
+ textarea.tags = function(tags) {
+ _tags = tags;
+
+ var isMixed = Array.isArray(tags[field.key]);
+
+ utilGetSetValue(input, !isMixed && tags[field.key] ? tags[field.key] : '')
+ .attr('title', isMixed ? tags[field.key].filter(Boolean).join('\n') : undefined)
+ .attr('placeholder', isMixed ? _t('inspector.multiple_values') : (field.placeholder() || _t('inspector.unknown')))
+ .classed('mixed', isMixed);
+ };
+
+
+ textarea.focus = function() {
+ input.node().focus();
+ };
+
+
+ return utilRebind(textarea, dispatch$1, 'on');
+ }
+
+ function uiFieldWikidata(field, context) {
+ var wikidata = services.wikidata;
+ var dispatch$1 = dispatch('change');
+
+ var _selection = select(null);
+ var _searchInput = select(null);
+ var _qid = null;
+ var _wikidataEntity = null;
+ var _wikiURL = '';
+ var _entityIDs = [];
+
+ var _wikipediaKey = field.keys && field.keys.find(function(key) {
+ return key.includes('wikipedia');
+ }),
+ _hintKey = field.key === 'wikidata' ? 'name' : field.key.split(':')[0];
+
+ var combobox = uiCombobox(context, 'combo-' + field.safeid)
+ .caseSensitive(true)
+ .minItems(1);
+
+ function wiki(selection) {
+
+ _selection = selection;
+
+ var wrap = selection.selectAll('.form-field-input-wrap')
+ .data([0]);
+
+ wrap = wrap.enter()
+ .append('div')
+ .attr('class', 'form-field-input-wrap form-field-input-' + field.type)
+ .merge(wrap);
+
+
+ var list = wrap.selectAll('ul')
+ .data([0]);
+
+ list = list.enter()
+ .append('ul')
+ .attr('class', 'rows')
+ .merge(list);
+
+ var searchRow = list.selectAll('li.wikidata-search')
+ .data([0]);
+
+ var searchRowEnter = searchRow.enter()
+ .append('li')
+ .attr('class', 'wikidata-search');
+
+ searchRowEnter
+ .append('input')
+ .attr('type', 'text')
+ .attr('id', field.domId)
+ .style('flex', '1')
+ .call(utilNoAuto)
+ .on('focus', function() {
+ var node = select(this).node();
+ node.setSelectionRange(0, node.value.length);
+ })
+ .on('blur', function() {
+ setLabelForEntity();
+ })
+ .call(combobox.fetcher(fetchWikidataItems));
+
+ combobox.on('accept', function(d) {
+ _qid = d.id;
+ change();
+ }).on('cancel', function() {
+ setLabelForEntity();
+ });
+
+ searchRowEnter
+ .append('button')
+ .attr('class', 'form-field-button wiki-link')
+ .attr('title', _t('icons.view_on', { domain: 'wikidata.org' }))
+ .attr('tabindex', -1)
+ .call(svgIcon('#iD-icon-out-link'))
+ .on('click', function() {
+ event.preventDefault();
+ if (_wikiURL) window.open(_wikiURL, '_blank');
+ });
+
+ searchRow = searchRow.merge(searchRowEnter);
+
+ _searchInput = searchRow.select('input');
+
+ var wikidataProperties = ['description', 'identifier'];
+
+ var items = list.selectAll('li.labeled-input')
+ .data(wikidataProperties);
+
+ // Enter
+ var enter = items.enter()
+ .append('li')
+ .attr('class', function(d) { return 'labeled-input preset-wikidata-' + d; });
+
+ enter
+ .append('span')
+ .attr('class', 'label')
+ .text(function(d) { return _t('wikidata.' + d); });
+
+ enter
+ .append('input')
+ .attr('type', 'text')
+ .call(utilNoAuto)
+ .classed('disabled', 'true')
+ .attr('readonly', 'true');
+
+ enter
+ .append('button')
+ .attr('class', 'form-field-button')
+ .attr('title', _t('icons.copy'))
+ .attr('tabindex', -1)
+ .call(svgIcon('#iD-operation-copy'))
+ .on('click', function() {
+ event.preventDefault();
+ select(this.parentNode)
+ .select('input')
+ .node()
+ .select();
+ document.execCommand('copy');
+ });
+
+ }
+
+ function fetchWikidataItems(q, callback) {
+
+ if (!q && _hintKey) {
+ // other tags may be good search terms
+ for (var i in _entityIDs) {
+ var entity = context.hasEntity(_entityIDs[i]);
+ if (entity.tags[_hintKey]) {
+ q = entity.tags[_hintKey];
+ break;
+ }
+ }
+ }
+
+ wikidata.itemsForSearchQuery(q, function(err, data) {
+ if (err) return;
+
+ for (var i in data) {
+ data[i].value = data[i].label + ' (' + data[i].id + ')';
+ data[i].title = data[i].description;
+ }
+
+ if (callback) callback(data);
+ });
+ }
+
+
+ function change() {
+ var syncTags = {};
+ syncTags[field.key] = _qid;
+ dispatch$1.call('change', this, syncTags);
+
+ // attempt asynchronous update of wikidata tag..
+ var initGraph = context.graph();
+ var initEntityIDs = _entityIDs;
+
+ wikidata.entityByQID(_qid, function(err, entity) {
+ if (err) return;
+
+ // If graph has changed, we can't apply this update.
+ if (context.graph() !== initGraph) return;
+
+ if (!entity.sitelinks) return;
+
+ var langs = wikidata.languagesToQuery();
+ // use the label and description languages as fallbacks
+ ['labels', 'descriptions'].forEach(function(key) {
+ if (!entity[key]) return;
+
+ var valueLangs = Object.keys(entity[key]);
+ if (valueLangs.length === 0) return;
+ var valueLang = valueLangs[0];
+
+ if (langs.indexOf(valueLang) === -1) {
+ langs.push(valueLang);
+ }
+ });
+
+ var newWikipediaValue;
+
+ if (_wikipediaKey) {
+ var foundPreferred;
+ for (var i in langs) {
+ var lang = langs[i];
+ var siteID = lang.replace('-', '_') + 'wiki';
+ if (entity.sitelinks[siteID]) {
+ foundPreferred = true;
+ newWikipediaValue = lang + ':' + entity.sitelinks[siteID].title;
+ // use the first match
+ break;
+ }
+ }
+
+ if (!foundPreferred) {
+ // No wikipedia sites available in the user's language or the fallback languages,
+ // default to any wikipedia sitelink
+
+ var wikiSiteKeys = Object.keys(entity.sitelinks).filter(function(site) {
+ return site.endsWith('wiki');
+ });
+
+ if (wikiSiteKeys.length === 0) {
+ // if no wikipedia pages are linked to this wikidata entity, delete that tag
+ newWikipediaValue = null;
+ } else {
+ var wikiLang = wikiSiteKeys[0].slice(0, -4).replace('_', '-');
+ var wikiTitle = entity.sitelinks[wikiSiteKeys[0]].title;
+ newWikipediaValue = wikiLang + ':' + wikiTitle;
+ }
+ }
+ }
+
+ if (newWikipediaValue) {
+ newWikipediaValue = context.cleanTagValue(newWikipediaValue);
+ }
+
+ if (typeof newWikipediaValue === 'undefined') return;
+
+ var actions = initEntityIDs.map(function(entityID) {
+ var entity = context.hasEntity(entityID);
+ if (!entity) return;
+
+ var currTags = Object.assign({}, entity.tags); // shallow copy
+ if (newWikipediaValue === null) {
+ if (!currTags[_wikipediaKey]) return;
+
+ delete currTags[_wikipediaKey];
+ } else {
+ currTags[_wikipediaKey] = newWikipediaValue;
+ }
+
+ return actionChangeTags(entityID, currTags);
+ }).filter(Boolean);
+
+ if (!actions.length) return;
+
+ // Coalesce the update of wikidata tag into the previous tag change
+ context.overwrite(
+ function actionUpdateWikipediaTags(graph) {
+ actions.forEach(function(action) {
+ graph = action(graph);
+ });
+ return graph;
+ },
+ context.history().undoAnnotation()
+ );
+
+ // do not dispatch.call('change') here, because entity_editor
+ // changeTags() is not intended to be called asynchronously
+ });
+ }
+
+ function setLabelForEntity() {
+ var label = '';
+ if (_wikidataEntity) {
+ label = entityPropertyForDisplay(_wikidataEntity, 'labels');
+ if (label.length === 0) {
+ label = _wikidataEntity.id.toString();
+ }
+ }
+ utilGetSetValue(_searchInput, label);
+ }
+
+
+ wiki.tags = function(tags) {
+
+ var isMixed = Array.isArray(tags[field.key]);
+ _searchInput
+ .attr('title', isMixed ? tags[field.key].filter(Boolean).join('\n') : null)
+ .attr('placeholder', isMixed ? _t('inspector.multiple_values') : '')
+ .classed('mixed', isMixed);
+
+ _qid = typeof tags[field.key] === 'string' && tags[field.key] || '';
+
+ if (!/^Q[0-9]*$/.test(_qid)) { // not a proper QID
+ unrecognized();
+ return;
+ }
+
+ // QID value in correct format
+ _wikiURL = 'https://wikidata.org/wiki/' + _qid;
+ wikidata.entityByQID(_qid, function(err, entity) {
+ if (err) {
+ unrecognized();
+ return;
+ }
+ _wikidataEntity = entity;
+
+ setLabelForEntity();
+
+ var description = entityPropertyForDisplay(entity, 'descriptions');
+
+ _selection.select('button.wiki-link')
+ .classed('disabled', false);
+
+ _selection.select('.preset-wikidata-description')
+ .style('display', function(){
+ return description.length > 0 ? 'flex' : 'none';
+ })
+ .select('input')
+ .attr('value', description);
+
+ _selection.select('.preset-wikidata-identifier')
+ .style('display', function(){
+ return entity.id ? 'flex' : 'none';
+ })
+ .select('input')
+ .attr('value', entity.id);
+ });
+
+
+ // not a proper QID
+ function unrecognized() {
+ _wikidataEntity = null;
+ setLabelForEntity();
+
+ _selection.select('.preset-wikidata-description')
+ .style('display', 'none');
+ _selection.select('.preset-wikidata-identifier')
+ .style('display', 'none');
+
+ _selection.select('button.wiki-link')
+ .classed('disabled', true);
+
+ if (_qid && _qid !== '') {
+ _wikiURL = 'https://wikidata.org/wiki/Special:Search?search=' + _qid;
+ } else {
+ _wikiURL = '';
+ }
+ }
+ };
+
+ function entityPropertyForDisplay(wikidataEntity, propKey) {
+ if (!wikidataEntity[propKey]) return '';
+ var propObj = wikidataEntity[propKey];
+ var langKeys = Object.keys(propObj);
+ if (langKeys.length === 0) return '';
+ // sorted by priority, since we want to show the user's language first if possible
+ var langs = wikidata.languagesToQuery();
+ for (var i in langs) {
+ var lang = langs[i];
+ var valueObj = propObj[lang];
+ if (valueObj && valueObj.value && valueObj.value.length > 0) return valueObj.value;
+ }
+ // default to any available value
+ return propObj[langKeys[0]].value;
+ }
+
+
+ wiki.entityIDs = function(val) {
+ if (!arguments.length) return _entityIDs;
+ _entityIDs = val;
+ return wiki;
+ };
+
+
+ wiki.focus = function() {
+ _searchInput.node().focus();
+ };
+
+
+ return utilRebind(wiki, dispatch$1, 'on');
+ }
+
+ function uiFieldWikipedia(field, context) {
+ const dispatch$1 = dispatch('change');
+ const wikipedia = services.wikipedia;
+ const wikidata = services.wikidata;
+ let _langInput = select(null);
+ let _titleInput = select(null);
+ let _wikiURL = '';
+ let _entityIDs;
+ let _tags;
+
+ let _dataWikipedia = [];
+ _mainFileFetcher.get('wmf_sitematrix')
+ .then(d => {
+ _dataWikipedia = d;
+ if (_tags) updateForTags(_tags);
+ })
+ .catch(() => { /* ignore */ });
+
+
+ const langCombo = uiCombobox(context, 'wikipedia-lang')
+ .fetcher((value, callback) => {
+ const v = value.toLowerCase();
+ callback(_dataWikipedia
+ .filter(d => {
+ return d[0].toLowerCase().indexOf(v) >= 0 ||
+ d[1].toLowerCase().indexOf(v) >= 0 ||
+ d[2].toLowerCase().indexOf(v) >= 0;
+ })
+ .map(d => ({ value: d[1] }))
+ );
+ });
+
+ const titleCombo = uiCombobox(context, 'wikipedia-title')
+ .fetcher((value, callback) => {
+ if (!value) {
+ value = '';
+ for (let i in _entityIDs) {
+ let entity = context.hasEntity(_entityIDs[i]);
+ if (entity.tags.name) {
+ value = entity.tags.name;
+ break;
+ }
+ }
+ }
+ const searchfn = value.length > 7 ? wikipedia.search : wikipedia.suggestions;
+ searchfn(language()[2], value, (query, data) => {
+ callback( data.map(d => ({ value: d })) );
+ });
+ });
+
+
+ function wiki(selection) {
+ let wrap = selection.selectAll('.form-field-input-wrap')
+ .data([0]);
+
+ wrap = wrap.enter()
+ .append('div')
+ .attr('class', `form-field-input-wrap form-field-input-${field.type}`)
+ .merge(wrap);
+
+
+ let langContainer = wrap.selectAll('.wiki-lang-container')
+ .data([0]);
+
+ langContainer = langContainer.enter()
+ .append('div')
+ .attr('class', 'wiki-lang-container')
+ .merge(langContainer);
+
+
+ _langInput = langContainer.selectAll('input.wiki-lang')
+ .data([0]);
+
+ _langInput = _langInput.enter()
+ .append('input')
+ .attr('type', 'text')
+ .attr('class', 'wiki-lang')
+ .attr('placeholder', _t('translate.localized_translation_language'))
+ .call(utilNoAuto)
+ .call(langCombo)
+ .merge(_langInput);
+
+ utilGetSetValue(_langInput, language()[1]);
+
+ _langInput
+ .on('blur', changeLang)
+ .on('change', changeLang);
+
+
+ let titleContainer = wrap.selectAll('.wiki-title-container')
+ .data([0]);
+
+ titleContainer = titleContainer.enter()
+ .append('div')
+ .attr('class', 'wiki-title-container')
+ .merge(titleContainer);
+
+ _titleInput = titleContainer.selectAll('input.wiki-title')
+ .data([0]);
+
+ _titleInput = _titleInput.enter()
+ .append('input')
+ .attr('type', 'text')
+ .attr('class', 'wiki-title')
+ .attr('id', field.domId)
+ .call(utilNoAuto)
+ .call(titleCombo)
+ .merge(_titleInput);
+
+ _titleInput
+ .on('blur', blur)
+ .on('change', change);
+
+
+ let link = titleContainer.selectAll('.wiki-link')
+ .data([0]);
+
+ link = link.enter()
+ .append('button')
+ .attr('class', 'form-field-button wiki-link')
+ .attr('tabindex', -1)
+ .attr('title', _t('icons.view_on', { domain: 'wikipedia.org' }))
+ .call(svgIcon('#iD-icon-out-link'))
+ .merge(link);
+
+ link
+ .on('click', () => {
+ event.preventDefault();
+ if (_wikiURL) window.open(_wikiURL, '_blank');
+ });
+ }
+
+
+ function language() {
+ const value = utilGetSetValue(_langInput).toLowerCase();
+ const locale = _mainLocalizer.localeCode().toLowerCase();
+ let localeLanguage;
+ return _dataWikipedia.find(d => {
+ if (d[2] === locale) localeLanguage = d;
+ return d[0].toLowerCase() === value || d[1].toLowerCase() === value || d[2] === value;
+ }) || localeLanguage || ['English', 'English', 'en'];
+ }
+
+
+ function changeLang() {
+ utilGetSetValue(_langInput, language()[1]);
+ change(true);
+ }
+
+
+ function blur() {
+ change(true);
+ }
+
+
+ function change(skipWikidata) {
+ let value = utilGetSetValue(_titleInput);
+ const m = value.match(/https?:\/\/([-a-z]+)\.wikipedia\.org\/(?:wiki|\1-[-a-z]+)\/([^#]+)(?:#(.+))?/);
+ const l = m && _dataWikipedia.find(d => m[1] === d[2]);
+ let syncTags = {};
+
+ if (l) {
+ // Normalize title http://www.mediawiki.org/wiki/API:Query#Title_normalization
+ value = decodeURIComponent(m[2]).replace(/_/g, ' ');
+ if (m[3]) {
+ let anchor;
+ // try {
+ // leave this out for now - #6232
+ // Best-effort `anchordecode:` implementation
+ // anchor = decodeURIComponent(m[3].replace(/\.([0-9A-F]{2})/g, '%$1'));
+ // } catch (e) {
+ anchor = decodeURIComponent(m[3]);
+ // }
+ value += '#' + anchor.replace(/_/g, ' ');
+ }
+ value = value.slice(0, 1).toUpperCase() + value.slice(1);
+ utilGetSetValue(_langInput, l[1]);
+ utilGetSetValue(_titleInput, value);
+ }
+
+ if (value) {
+ syncTags.wikipedia = context.cleanTagValue(language()[2] + ':' + value);
+ } else {
+ syncTags.wikipedia = undefined;
+ }
+
+ dispatch$1.call('change', this, syncTags);
+
+
+ if (skipWikidata || !value || !language()[2]) return;
+
+ // attempt asynchronous update of wikidata tag..
+ const initGraph = context.graph();
+ const initEntityIDs = _entityIDs;
+
+ wikidata.itemsByTitle(language()[2], value, (err, data) => {
+ if (err || !data || !Object.keys(data).length) return;
+
+ // If graph has changed, we can't apply this update.
+ if (context.graph() !== initGraph) return;
+
+ const qids = Object.keys(data);
+ const value = qids && qids.find(id => id.match(/^Q\d+$/));
+
+ let actions = initEntityIDs.map((entityID) => {
+ let entity = context.entity(entityID).tags;
+ let currTags = Object.assign({}, entity); // shallow copy
+ if (currTags.wikidata !== value) {
+ currTags.wikidata = value;
+ return actionChangeTags(entityID, currTags);
+ }
+ }).filter(Boolean);
+
+ if (!actions.length) return;
+
+ // Coalesce the update of wikidata tag into the previous tag change
+ context.overwrite(
+ function actionUpdateWikidataTags(graph) {
+ actions.forEach(function(action) {
+ graph = action(graph);
+ });
+ return graph;
+ },
+ context.history().undoAnnotation()
+ );
+
+ // do not dispatch.call('change') here, because entity_editor
+ // changeTags() is not intended to be called asynchronously
+ });
+ }
+
+
+ wiki.tags = (tags) => {
+ _tags = tags;
+ updateForTags(tags);
+ };
+
+ function updateForTags(tags) {
+
+ const value = typeof tags[field.key] === 'string' ? tags[field.key] : '';
+ const m = value.match(/([^:]+):([^#]+)(?:#(.+))?/);
+ const l = m && _dataWikipedia.find(d => m[1] === d[2]);
+ let anchor = m && m[3];
+
+ // value in correct format
+ if (l) {
+ utilGetSetValue(_langInput, l[1]);
+ utilGetSetValue(_titleInput, m[2] + (anchor ? ('#' + anchor) : ''));
+ if (anchor) {
+ try {
+ // Best-effort `anchorencode:` implementation
+ anchor = encodeURIComponent(anchor.replace(/ /g, '_')).replace(/%/g, '.');
+ } catch (e) {
+ anchor = anchor.replace(/ /g, '_');
+ }
+ }
+ _wikiURL = 'https://' + m[1] + '.wikipedia.org/wiki/' +
+ m[2].replace(/ /g, '_') + (anchor ? ('#' + anchor) : '');
+
+ // unrecognized value format
+ } else {
+ utilGetSetValue(_titleInput, value);
+ if (value && value !== '') {
+ utilGetSetValue(_langInput, '');
+ _wikiURL = `https://en.wikipedia.org/wiki/Special:Search?search=${value}`;
+ } else {
+ _wikiURL = '';
+ }
+ }
+ }
+
+
+ wiki.entityIDs = (val) => {
+ if (!arguments.length) return _entityIDs;
+ _entityIDs = val;
+ return wiki;
+ };
+
+
+ wiki.focus = () => {
+ _titleInput.node().focus();
+ };
+
+
+ return utilRebind(wiki, dispatch$1, 'on');
+ }
+
+ uiFieldWikipedia.supportsMultiselection = false;
+
+ var uiFields = {
+ access: uiFieldAccess,
+ address: uiFieldAddress,
+ check: uiFieldCheck,
+ combo: uiFieldCombo,
+ cycleway: uiFieldCycleway,
+ defaultCheck: uiFieldCheck,
+ email: uiFieldText,
+ identifier: uiFieldText,
+ lanes: uiFieldLanes,
+ localized: uiFieldLocalized,
+ maxspeed: uiFieldMaxspeed,
+ multiCombo: uiFieldCombo,
+ networkCombo: uiFieldCombo,
+ number: uiFieldText,
+ onewayCheck: uiFieldCheck,
+ radio: uiFieldRadio,
+ restrictions: uiFieldRestrictions,
+ semiCombo: uiFieldCombo,
+ structureRadio: uiFieldRadio,
+ tel: uiFieldText,
+ text: uiFieldText,
+ textarea: uiFieldTextarea,
+ typeCombo: uiFieldCombo,
+ url: uiFieldText,
+ wikidata: uiFieldWikidata,
+ wikipedia: uiFieldWikipedia
+ };
+
+ // Pass `which` object of the form:
+ // {
+ // key: 'string', // required
+ // value: 'string' // optional
+ // }
+ // -or-
+ // {
+ // rtype: 'string' // relation type (e.g. 'multipolygon')
+ // }
+ // -or-
+ // {
+ // qid: 'string' // brand wikidata (e.g. 'Q37158')
+ // }
+ //
+ function uiTagReference(what) {
+ var wikibase = what.qid ? services.wikidata : services.osmWikibase;
+ var tagReference = {};
+
+ var _button = select(null);
+ var _body = select(null);
+ var _loaded;
+ var _showing;
+
+
+ function load() {
+ if (!wikibase) return;
+
+ _button
+ .classed('tag-reference-loading', true);
+
+ wikibase.getDocs(what, gotDocs);
+ }
+
+
+ function gotDocs(err, docs) {
+ _body.html('');
+
+ if (!docs || !docs.title) {
+ _body
+ .append('p')
+ .attr('class', 'tag-reference-description')
+ .text(_t('inspector.no_documentation_key'));
+ done();
+ return;
+ }
+
+ if (docs.imageURL) {
+ _body
+ .append('img')
+ .attr('class', 'tag-reference-wiki-image')
+ .attr('src', docs.imageURL)
+ .on('load', function() { done(); })
+ .on('error', function() { select(this).remove(); done(); });
+ } else {
+ done();
+ }
+
+ _body
+ .append('p')
+ .attr('class', 'tag-reference-description')
+ .text(docs.description || _t('inspector.no_documentation_key'))
+ .append('a')
+ .attr('class', 'tag-reference-edit')
+ .attr('target', '_blank')
+ .attr('tabindex', -1)
+ .attr('title', _t('inspector.edit_reference'))
+ .attr('href', docs.editURL)
+ .call(svgIcon('#iD-icon-edit', 'inline'));
+
+ if (docs.wiki) {
+ _body
+ .append('a')
+ .attr('class', 'tag-reference-link')
+ .attr('target', '_blank')
+ .attr('tabindex', -1)
+ .attr('href', docs.wiki.url)
+ .call(svgIcon('#iD-icon-out-link', 'inline'))
+ .append('span')
+ .text(_t(docs.wiki.text));
+ }
+
+ // Add link to info about "good changeset comments" - #2923
+ if (what.key === 'comment') {
+ _body
+ .append('a')
+ .attr('class', 'tag-reference-comment-link')
+ .attr('target', '_blank')
+ .attr('tabindex', -1)
+ .call(svgIcon('#iD-icon-out-link', 'inline'))
+ .attr('href', _t('commit.about_changeset_comments_link'))
+ .append('span')
+ .text(_t('commit.about_changeset_comments'));
+ }
+ }
+
+
+ function done() {
+ _loaded = true;
+
+ _button
+ .classed('tag-reference-loading', false);
+
+ _body
+ .classed('expanded', true)
+ .transition()
+ .duration(200)
+ .style('max-height', '200px')
+ .style('opacity', '1');
+
+ _showing = true;
+
+ _button.selectAll('svg.icon use').each(function() {
+ var iconUse = select(this);
+ if (iconUse.attr('href') === '#iD-icon-info') {
+ iconUse.attr('href', '#iD-icon-info-filled');
+ }
+ });
+ }
+
+
+ function hide() {
+ _body
+ .transition()
+ .duration(200)
+ .style('max-height', '0px')
+ .style('opacity', '0')
+ .on('end', function () {
+ _body.classed('expanded', false);
+ });
+
+ _showing = false;
+
+ _button.selectAll('svg.icon use').each(function() {
+ var iconUse = select(this);
+ if (iconUse.attr('href') === '#iD-icon-info-filled') {
+ iconUse.attr('href', '#iD-icon-info');
+ }
+ });
+
+ }
+
+
+ tagReference.button = function(selection, klass, iconName) {
+ _button = selection.selectAll('.tag-reference-button')
+ .data([0]);
+
+ _button = _button.enter()
+ .append('button')
+ .attr('class', 'tag-reference-button ' + klass)
+ .attr('title', _t('icons.information'))
+ .attr('tabindex', -1)
+ .call(svgIcon('#iD-icon-' + (iconName || 'inspect')))
+ .merge(_button);
+
+ _button
+ .on('click', function () {
+ event.stopPropagation();
+ event.preventDefault();
+ this.blur(); // avoid keeping focus on the button - #4641
+ if (_showing) {
+ hide();
+ } else if (_loaded) {
+ done();
+ } else {
+ load();
+ }
+ });
+ };
+
+
+ tagReference.body = function(selection) {
+ var itemID = what.qid || what.rtype || (what.key + '-' + what.value);
+ _body = selection.selectAll('.tag-reference-body')
+ .data([itemID], function(d) { return d; });
+
+ _body.exit()
+ .remove();
+
+ _body = _body.enter()
+ .append('div')
+ .attr('class', 'tag-reference-body')
+ .style('max-height', '0')
+ .style('opacity', '0')
+ .merge(_body);
+
+ if (_showing === false) {
+ hide();
+ }
+ };
+
+
+ tagReference.showing = function(val) {
+ if (!arguments.length) return _showing;
+ _showing = val;
+ return tagReference;
+ };
+
+
+ return tagReference;
+ }
+
+ function uiField(context, presetField, entityIDs, options) {
+ options = Object.assign({
+ show: true,
+ wrap: true,
+ remove: true,
+ revert: true,
+ info: true
+ }, options);
+
+ // Don't show the remove and revert buttons if any of the entity IDs are FB features
+ // with source=digitalglobe or source=maxar
+ var someFbRoadsSelected = entityIDs ? entityIDs.some(function(entity) {
+ return entity.__fbid__ && (entity.tags.source === 'maxar' || entity.tags.source === 'digitalglobe');
+ }) : false;
+
+
+ if ( someFbRoadsSelected ) {
+ options.remove = false;
+ options.revert = false;
+ }
+
+ var dispatch$1 = dispatch('change', 'revert');
+ var field = Object.assign({}, presetField); // shallow copy
+ field.domId = utilUniqueDomId('form-field-' + field.safeid);
+ var _show = options.show;
+ var _state = '';
+ var _tags = {};
+
+ var _locked = false;
+ var _lockedTip = uiTooltip()
+ .title(_t('inspector.lock.suggestion', { label: field.label }))
+ .placement('bottom');
+
+
+ field.keys = field.keys || [field.key];
+
+ // only create the fields that are actually being shown
+ if (_show && !field.impl) {
+ createField();
+ }
+
+ // Creates the field.. This is done lazily,
+ // once we know that the field will be shown.
+ function createField() {
+ field.impl = uiFields[field.type](field, context)
+ .on('change', function(t, onInput) {
+ dispatch$1.call('change', field, t, onInput);
+ });
+
+ if (entityIDs) {
+ field.entityIDs = entityIDs;
+ // if this field cares about the entities, pass them along
+ if (field.impl.entityIDs) {
+ field.impl.entityIDs(entityIDs);
+ }
+ }
+ }
+
+
+ function isModified() {
+ if (!entityIDs || !entityIDs.length) return false;
+ return entityIDs.some(function(entityID) {
+ var original = context.graph().base().entities[entityID];
+ var latest = context.graph().entity(entityID);
+ return field.keys.some(function(key) {
+ return original ? latest.tags[key] !== original.tags[key] : latest.tags[key];
+ });
+ });
+ }
+
+
+ function tagsContainFieldKey() {
+ return field.keys.some(function(key) {
+ if (field.type === 'multiCombo') {
+ for (var tagKey in _tags) {
+ if (tagKey.indexOf(key) === 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+ return _tags[key] !== undefined;
+ });
+ }
+
+
+ function revert(d) {
+ event.stopPropagation();
+ event.preventDefault();
+ if (!entityIDs || _locked) return;
+
+ dispatch$1.call('revert', d, d.keys);
+ }
+
+
+ function remove(d) {
+ event.stopPropagation();
+ event.preventDefault();
+ if (_locked) return;
+
+ var t = {};
+ d.keys.forEach(function(key) {
+ t[key] = undefined;
+ });
+
+ dispatch$1.call('change', d, t);
+ }
+
+
+ field.render = function(selection) {
+ var container = selection.selectAll('.form-field')
+ .data([field]);
+
+ // Enter
+ var enter = container.enter()
+ .append('div')
+ .attr('class', function(d) { return 'form-field form-field-' + d.safeid; })
+ .classed('nowrap', !options.wrap);
+
+ if (options.wrap) {
+ var labelEnter = enter
+ .append('label')
+ .attr('class', 'field-label')
+ .attr('for', function(d) { return d.domId; });
+
+ var textEnter = labelEnter
+ .append('span')
+ .attr('class', 'label-text');
+
+ textEnter
+ .append('span')
+ .attr('class', 'label-textvalue')
+ .text(function(d) { return d.label(); });
+
+ textEnter
+ .append('span')
+ .attr('class', 'label-textannotation');
+
+ if (options.remove) {
+ labelEnter
+ .append('button')
+ .attr('class', 'remove-icon')
+ .attr('title', _t('icons.remove'))
+ .attr('tabindex', -1)
+ .call(svgIcon('#iD-operation-delete'));
+ }
+
+ if (options.revert) {
+ labelEnter
+ .append('button')
+ .attr('class', 'modified-icon')
+ .attr('title', _t('icons.undo'))
+ .attr('tabindex', -1)
+ .call(svgIcon((_mainLocalizer.textDirection() === 'rtl') ? '#iD-icon-redo' : '#iD-icon-undo'));
+ }
+ }
+
+
+ // Update
+ container = container
+ .merge(enter);
+
+ container.select('.field-label > .remove-icon') // propagate bound data
+ .on('click', remove);
+
+ container.select('.field-label > .modified-icon') // propagate bound data
+ .on('click', revert);
+
+ container
+ .each(function(d) {
+ var selection = select(this);
+
+ if (!d.impl) {
+ createField();
+ }
+
+ var reference, help;
+
+ // instantiate field help
+ if (options.wrap && field.type === 'restrictions') {
+ help = uiFieldHelp(context, 'restrictions');
+ }
+
+ // instantiate tag reference
+ if (options.wrap && options.info) {
+ var referenceKey = d.key;
+ if (d.type === 'multiCombo') { // lookup key without the trailing ':'
+ referenceKey = referenceKey.replace(/:$/, '');
+ }
+
+ reference = uiTagReference(d.reference || { key: referenceKey });
+ if (_state === 'hover') {
+ reference.showing(false);
+ }
+ }
+
+ selection
+ .call(d.impl);
+
+ // add field help components
+ if (help) {
+ selection
+ .call(help.body)
+ .select('.field-label')
+ .call(help.button);
+ }
+
+ // add tag reference components
+ if (reference) {
+ selection
+ .call(reference.body)
+ .select('.field-label')
+ .call(reference.button);
+ }
+
+ d.impl.tags(_tags);
+ });
+
+
+ container
+ .classed('locked', _locked)
+ .classed('modified', isModified())
+ .classed('present', tagsContainFieldKey());
+
+
+ // show a tip and lock icon if the field is locked
+ var annotation = container.selectAll('.field-label .label-textannotation');
+ var icon = annotation.selectAll('.icon')
+ .data(_locked ? [0]: []);
+
+ icon.exit()
+ .remove();
+
+ icon.enter()
+ .append('svg')
+ .attr('class', 'icon')
+ .append('use')
+ .attr('xlink:href', '#fas-lock');
+
+ container.call(_locked ? _lockedTip : _lockedTip.destroy);
+ };
+
+
+ field.state = function(val) {
+ if (!arguments.length) return _state;
+ _state = val;
+ return field;
+ };
+
+
+ field.tags = function(val) {
+ if (!arguments.length) return _tags;
+ _tags = val;
+
+ if (tagsContainFieldKey() && !_show) {
+ // always show a field if it has a value to display
+ _show = true;
+ if (!field.impl) {
+ createField();
+ }
+ }
+
+ return field;
+ };
+
+
+ field.locked = function(val) {
+ if (!arguments.length) return _locked;
+ _locked = val;
+ return field;
+ };
+
+
+ field.show = function() {
+ _show = true;
+ if (!field.impl) {
+ createField();
+ }
+ if (field.default && field.key && _tags[field.key] !== field.default) {
+ var t = {};
+ t[field.key] = field.default;
+ dispatch$1.call('change', this, t);
+ }
+ };
+
+ // A shown field has a visible UI, a non-shown field is in the 'Add field' dropdown
+ field.isShown = function() {
+ return _show;
+ };
+
+
+ // An allowed field can appear in the UI or in the 'Add field' dropdown.
+ // A non-allowed field is hidden from the user altogether
+ field.isAllowed = function() {
+
+ if (entityIDs &&
+ entityIDs.length > 1 &&
+ uiFields[field.type].supportsMultiselection === false) return false;
+
+ if (field.geometry && !entityIDs.every(function(entityID) {
+ return field.matchGeometry(context.graph().geometry(entityID));
+ })) return false;
+
+ if (field.countryCodes || field.notCountryCodes) {
+ var extent = combinedEntityExtent();
+ if (!extent) return true;
+
+ var center = extent.center();
+ var countryCode = iso1A2Code(center);
+
+ if (!countryCode) return false;
+
+ countryCode = countryCode.toLowerCase();
+
+ if (field.countryCodes && field.countryCodes.indexOf(countryCode) === -1) {
+ return false;
+ }
+ if (field.notCountryCodes && field.notCountryCodes.indexOf(countryCode) !== -1) {
+ return false;
+ }
+ }
+
+ var prerequisiteTag = field.prerequisiteTag;
+
+ if (entityIDs &&
+ !tagsContainFieldKey() && // ignore tagging prerequisites if a value is already present
+ prerequisiteTag) {
+
+ if (!entityIDs.every(function(entityID) {
+ var entity = context.graph().entity(entityID);
+ if (prerequisiteTag.key) {
+ var value = entity.tags[prerequisiteTag.key];
+ if (!value) return false;
+
+ if (prerequisiteTag.valueNot) {
+ return prerequisiteTag.valueNot !== value;
+ }
+ if (prerequisiteTag.value) {
+ return prerequisiteTag.value === value;
+ }
+ } else if (prerequisiteTag.keyNot) {
+ if (entity.tags[prerequisiteTag.keyNot]) return false;
+ }
+ return true;
+ })) return false;
+ }
+
+ return true;
+ };
+
+
+ field.focus = function() {
+ if (field.impl) {
+ field.impl.focus();
+ }
+ };
+
+
+ function combinedEntityExtent() {
+ return entityIDs && entityIDs.length && entityIDs.reduce(function(extent, entityID) {
+ var entity = context.graph().entity(entityID);
+ return extent.extend(entity.extent(context.graph()));
+ }, geoExtent());
+ }
+
+
+ return utilRebind(field, dispatch$1, 'on');
+ }
+
+ function uiFormFields(context) {
+ var moreCombo = uiCombobox(context, 'more-fields').minItems(1);
+ var _fieldsArr = [];
+ var _lastPlaceholder = '';
+ var _state = '';
+ var _klass = '';
+
+
+ function formFields(selection) {
+ var allowedFields = _fieldsArr.filter(function(field) { return field.isAllowed(); });
+ var shown = allowedFields.filter(function(field) { return field.isShown(); });
+ var notShown = allowedFields.filter(function(field) { return !field.isShown(); });
+
+ var container = selection.selectAll('.form-fields-container')
+ .data([0]);
+
+ container = container.enter()
+ .append('div')
+ .attr('class', 'form-fields-container ' + (_klass || ''))
+ .merge(container);
+
+
+ var fields = container.selectAll('.wrap-form-field')
+ .data(shown, function(d) { return d.id + (d.entityIDs ? d.entityIDs.join() : ''); });
+
+ fields.exit()
+ .remove();
+
+ // Enter
+ var enter = fields.enter()
+ .append('div')
+ .attr('class', function(d) { return 'wrap-form-field wrap-form-field-' + d.safeid; });
+
+ // Update
+ fields = fields
+ .merge(enter);
+
+ fields
+ .order()
+ .each(function(d) {
+ select(this)
+ .call(d.render);
+ });
+
+
+ var titles = [];
+ var moreFields = notShown.map(function(field) {
+ var label = field.label();
+ titles.push(label);
+
+ var terms = field.terms();
+ if (field.key) terms.push(field.key);
+ if (field.keys) terms = terms.concat(field.keys);
+
+ return {
+ title: label,
+ value: label,
+ field: field,
+ terms: terms
+ };
+ });
+
+ var placeholder = titles.slice(0,3).join(', ') + ((titles.length > 3) ? '…' : '');
+
+
+ var more = selection.selectAll('.more-fields')
+ .data((_state === 'hover' || moreFields.length === 0) ? [] : [0]);
+
+ more.exit()
+ .remove();
+
+ var moreEnter = more.enter()
+ .append('div')
+ .attr('class', 'more-fields')
+ .append('label');
+
+ moreEnter
+ .append('span')
+ .text(_t('inspector.add_fields'));
+
+ more = moreEnter
+ .merge(more);
+
+
+ var input = more.selectAll('.value')
+ .data([0]);
+
+ input.exit()
+ .remove();
+
+ input = input.enter()
+ .append('input')
+ .attr('class', 'value')
+ .attr('type', 'text')
+ .attr('placeholder', placeholder)
+ .call(utilNoAuto)
+ .merge(input);
+
+ input
+ .call(utilGetSetValue, '')
+ .call(moreCombo
+ .data(moreFields)
+ .on('accept', function (d) {
+ if (!d) return; // user entered something that was not matched
+ var field = d.field;
+ field.show();
+ selection.call(formFields); // rerender
+ if (field.type !== 'semiCombo' && field.type !== 'multiCombo') {
+ field.focus();
+ }
+ })
+ );
+
+ // avoid updating placeholder excessively (triggers style recalc)
+ if (_lastPlaceholder !== placeholder) {
+ input.attr('placeholder', placeholder);
+ _lastPlaceholder = placeholder;
+ }
+ }
+
+
+ formFields.fieldsArr = function(val) {
+ if (!arguments.length) return _fieldsArr;
+ _fieldsArr = val || [];
+ return formFields;
+ };
+
+ formFields.state = function(val) {
+ if (!arguments.length) return _state;
+ _state = val;
+ return formFields;
+ };
+
+ formFields.klass = function(val) {
+ if (!arguments.length) return _klass;
+ _klass = val;
+ return formFields;
+ };
+
+
+ return formFields;
+ }
+
+ function uiChangesetEditor(context) {
+ var dispatch$1 = dispatch('change');
+ var formFields = uiFormFields(context);
+ var commentCombo = uiCombobox(context, 'comment').caseSensitive(true);
+ var _fieldsArr;
+ var _tags;
+ var _changesetID;
+
+
+ function changesetEditor(selection) {
+ render(selection);
+ }
+
+
+ function render(selection) {
+ var initial = false;
+
+ if (!_fieldsArr) {
+ initial = true;
+ var presets = _mainPresetIndex;
+
+ _fieldsArr = [
+ uiField(context, presets.field('comment'), null, { show: true, revert: false }),
+ uiField(context, presets.field('source'), null, { show: false, revert: false }),
+ uiField(context, presets.field('hashtags'), null, { show: false, revert: false }),
+ ];
+
+ _fieldsArr.forEach(function(field) {
+ field
+ .on('change', function(t, onInput) {
+ dispatch$1.call('change', field, undefined, t, onInput);
+ });
+ });
+ }
+
+ _fieldsArr.forEach(function(field) {
+ field
+ .tags(_tags);
+ });
+
+
+ selection
+ .call(formFields.fieldsArr(_fieldsArr));
+
+
+ if (initial) {
+ var commentField = selection.select('.form-field-comment textarea');
+ var commentNode = commentField.node();
+
+ if (commentNode) {
+ commentNode.focus();
+ commentNode.select();
+ }
+
+ // trigger a 'blur' event so that comment field can be cleaned
+ // and checked for hashtags, even if retrieved from localstorage
+ utilTriggerEvent(commentField, 'blur');
+
+ var osm = context.connection();
+ if (osm) {
+ osm.userChangesets(function (err, changesets) {
+ if (err) return;
+
+ var comments = changesets.map(function(changeset) {
+ var comment = changeset.tags.comment;
+ return comment ? { title: comment, value: comment } : null;
+ }).filter(Boolean);
+
+ commentField
+ .call(commentCombo
+ .data(utilArrayUniqBy(comments, 'title'))
+ );
+ });
+ }
+ }
+
+ // Add warning if comment mentions Google
+ var hasGoogle = _tags.comment.match(/google/i);
+ var commentWarning = selection.select('.form-field-comment').selectAll('.comment-warning')
+ .data(hasGoogle ? [0] : []);
+
+ commentWarning.exit()
+ .transition()
+ .duration(200)
+ .style('opacity', 0)
+ .remove();
+
+ var commentEnter = commentWarning.enter()
+ .insert('div', '.tag-reference-body')
+ .attr('class', 'field-warning comment-warning')
+ .style('opacity', 0);
+
+ commentEnter
+ .append('a')
+ .attr('target', '_blank')
+ .attr('tabindex', -1)
+ .call(svgIcon('#iD-icon-alert', 'inline'))
+ .attr('href', _t('commit.google_warning_link'))
+ .append('span')
+ .text(_t('commit.google_warning'));
+
+ commentEnter
+ .transition()
+ .duration(200)
+ .style('opacity', 1);
+ }
+
+
+ changesetEditor.tags = function(_) {
+ if (!arguments.length) return _tags;
+ _tags = _;
+ // Don't reset _fieldsArr here.
+ return changesetEditor;
+ };
+
+
+ changesetEditor.changesetID = function(_) {
+ if (!arguments.length) return _changesetID;
+ if (_changesetID === _) return changesetEditor;
+ _changesetID = _;
+ _fieldsArr = null;
+ return changesetEditor;
+ };
+
+
+ return utilRebind(changesetEditor, dispatch$1, 'on');
+ }
+
+ // toggles the visibility of ui elements, using a combination of the
+ // hide class, which sets display=none, and a d3 transition for opacity.
+ // this will cause blinking when called repeatedly, so check that the
+ // value actually changes between calls.
+ function uiToggle(show, callback) {
+ return function(selection) {
+ selection
+ .style('opacity', show ? 0 : 1)
+ .classed('hide', false)
+ .transition()
+ .style('opacity', show ? 1 : 0)
+ .on('end', function() {
+ select(this)
+ .classed('hide', !show)
+ .style('opacity', null);
+ if (callback) callback.apply(this);
+ });
+ };
+ }
+
+ function uiDisclosure(context, key, expandedDefault) {
+ var dispatch$1 = dispatch('toggled');
+ var _expanded;
+ var _title = utilFunctor('');
+ var _updatePreference = true;
+ var _content = function () {};
+
+
+ var disclosure = function(selection) {
+
+ if (_expanded === undefined || _expanded === null) {
+ // loading _expanded here allows it to be reset by calling `disclosure.expanded(null)`
+
+ var preference = corePreferences('disclosure.' + key + '.expanded');
+ _expanded = preference === null ? !!expandedDefault : (preference === 'true');
+ }
+
+ var hideToggle = selection.selectAll('.hide-toggle-' + key)
+ .data([0]);
+
+ // enter
+ var hideToggleEnter = hideToggle.enter()
+ .append('a')
+ .attr('href', '#')
+ .attr('class', 'hide-toggle hide-toggle-' + key)
+ .call(svgIcon('', 'pre-text', 'hide-toggle-icon'));
+
+ hideToggleEnter
+ .append('span')
+ .attr('class', 'hide-toggle-text');
+
+ // update
+ hideToggle = hideToggleEnter
+ .merge(hideToggle);
+
+ hideToggle
+ .on('click', toggle)
+ .classed('expanded', _expanded);
+
+ hideToggle.selectAll('.hide-toggle-text')
+ .text(_title());
+
+ hideToggle.selectAll('.hide-toggle-icon')
+ .attr('xlink:href', _expanded ? '#iD-icon-down'
+ : (_mainLocalizer.textDirection() === 'rtl') ? '#iD-icon-backward' : '#iD-icon-forward'
+ );
+
+
+ var wrap = selection.selectAll('.disclosure-wrap')
+ .data([0]);
+
+ // enter/update
+ wrap = wrap.enter()
+ .append('div')
+ .attr('class', 'disclosure-wrap disclosure-wrap-' + key)
+ .merge(wrap)
+ .classed('hide', !_expanded);
+
+ if (_expanded) {
+ wrap
+ .call(_content);
+ }
+
+
+ function toggle() {
+ event.preventDefault();
+
+ _expanded = !_expanded;
+
+ if (_updatePreference) {
+ corePreferences('disclosure.' + key + '.expanded', _expanded);
+ }
+
+ hideToggle
+ .classed('expanded', _expanded);
+
+ hideToggle.selectAll('.hide-toggle-icon')
+ .attr('xlink:href', _expanded ? '#iD-icon-down'
+ : (_mainLocalizer.textDirection() === 'rtl') ? '#iD-icon-backward' : '#iD-icon-forward'
+ );
+
+ wrap
+ .call(uiToggle(_expanded));
+
+ if (_expanded) {
+ wrap
+ .call(_content);
+ }
+
+ dispatch$1.call('toggled', this, _expanded);
+ }
+ };
+
+
+ disclosure.title = function(val) {
+ if (!arguments.length) return _title;
+ _title = utilFunctor(val);
+ return disclosure;
+ };
+
+
+ disclosure.expanded = function(val) {
+ if (!arguments.length) return _expanded;
+ _expanded = val;
+ return disclosure;
+ };
+
+
+ disclosure.updatePreference = function(val) {
+ if (!arguments.length) return _updatePreference;
+ _updatePreference = val;
+ return disclosure;
+ };
+
+
+ disclosure.content = function(val) {
+ if (!arguments.length) return _content;
+ _content = val;
+ return disclosure;
+ };
+
+
+ return utilRebind(disclosure, dispatch$1, 'on');
+ }
+
+ // A unit of controls or info to be used in a layout, such as within a pane.
+ // Can be labeled and collapsible.
+ function uiSection(id, context) {
+
+ var _classes = utilFunctor('');
+ var _shouldDisplay;
+ var _content;
+
+ var _disclosure;
+ var _title;
+ var _expandedByDefault = utilFunctor(true);
+ var _disclosureContent;
+ var _disclosureExpanded;
+
+ var _containerSelection = select(null);
+
+ var section = {
+ id: id
+ };
+
+ section.classes = function(val) {
+ if (!arguments.length) return _classes;
+ _classes = utilFunctor(val);
+ return section;
+ };
+
+ section.title = function(val) {
+ if (!arguments.length) return _title;
+ _title = utilFunctor(val);
+ return section;
+ };
+
+ section.expandedByDefault = function(val) {
+ if (!arguments.length) return _expandedByDefault;
+ _expandedByDefault = utilFunctor(val);
+ return section;
+ };
+
+ section.shouldDisplay = function(val) {
+ if (!arguments.length) return _shouldDisplay;
+ _shouldDisplay = utilFunctor(val);
+ return section;
+ };
+
+ section.content = function(val) {
+ if (!arguments.length) return _content;
+ _content = val;
+ return section;
+ };
+
+ section.disclosureContent = function(val) {
+ if (!arguments.length) return _disclosureContent;
+ _disclosureContent = val;
+ return section;
+ };
+
+ section.disclosureExpanded = function(val) {
+ if (!arguments.length) return _disclosureExpanded;
+ _disclosureExpanded = val;
+ return section;
+ };
+
+ // may be called multiple times
+ section.render = function(selection) {
+
+ _containerSelection = selection
+ .selectAll('.section-' + id)
+ .data([0]);
+
+ var sectionEnter = _containerSelection
+ .enter()
+ .append('div')
+ .attr('class', 'section section-' + id + ' ' + (_classes && _classes() || ''));
+
+ _containerSelection = sectionEnter
+ .merge(_containerSelection);
+
+ _containerSelection
+ .call(renderContent);
+ };
+
+ section.reRender = function() {
+ _containerSelection
+ .call(renderContent);
+ };
+
+ section.selection = function() {
+ return _containerSelection;
+ };
+
+ section.disclosure = function() {
+ return _disclosure;
+ };
+
+ // may be called multiple times
+ function renderContent(selection) {
+ if (_shouldDisplay) {
+ var shouldDisplay = _shouldDisplay();
+ selection.classed('hide', !shouldDisplay);
+ if (!shouldDisplay) {
+ selection.html('');
+ return;
+ }
+ }
+
+ if (_disclosureContent) {
+ if (!_disclosure) {
+ _disclosure = uiDisclosure(context, id.replace(/-/g, '_'), _expandedByDefault())
+ .title(_title || '')
+ /*.on('toggled', function(expanded) {
+ if (expanded) { selection.node().parentNode.scrollTop += 200; }
+ })*/
+ .content(_disclosureContent);
+ }
+ if (_disclosureExpanded !== undefined) {
+ _disclosure.expanded(_disclosureExpanded);
+ _disclosureExpanded = undefined;
+ }
+ selection
+ .call(_disclosure);
+
+ return;
+ }
+
+ if (_content) {
+ selection
+ .call(_content);
+ }
+ }
+
+ return section;
+ }
+
+ function uiSectionChanges(context) {
+ var detected = utilDetect();
+
+ var _discardTags = {};
+ _mainFileFetcher.get('discarded')
+ .then(function(d) { _discardTags = d; })
+ .catch(function() { /* ignore */ });
+
+ var section = uiSection('changes-list', context)
+ .title(function() {
+ var history = context.history();
+ var summary = history.difference().summary();
+ return _t('commit.changes', { count: summary.length });
+ })
+ .disclosureContent(renderDisclosureContent);
+
+ function renderDisclosureContent(selection) {
+ var history = context.history();
+ var summary = history.difference().summary();
+
+ var container = selection.selectAll('.commit-section')
+ .data([0]);
+
+ var containerEnter = container.enter()
+ .append('div')
+ .attr('class', 'commit-section');
+
+ containerEnter
+ .append('ul')
+ .attr('class', 'changeset-list');
+
+ container = containerEnter
+ .merge(container);
+
+
+ var items = container.select('ul').selectAll('li')
+ .data(summary);
+
+ var itemsEnter = items.enter()
+ .append('li')
+ .attr('class', 'change-item');
+
+ itemsEnter
+ .each(function(d) {
+ select(this)
+ .call(svgIcon('#iD-icon-' + d.entity.geometry(d.graph), 'pre-text ' + d.changeType));
+ });
+
+ itemsEnter
+ .append('span')
+ .attr('class', 'change-type')
+ .text(function(d) { return _t('commit.' + d.changeType) + ' '; });
+
+ itemsEnter
+ .append('strong')
+ .attr('class', 'entity-type')
+ .text(function(d) {
+ var matched = _mainPresetIndex.match(d.entity, d.graph);
+ return (matched && matched.name()) || utilDisplayType(d.entity.id);
+ });
+
+ itemsEnter
+ .append('span')
+ .attr('class', 'entity-name')
+ .text(function(d) {
+ var name = utilDisplayName(d.entity) || '',
+ string = '';
+ if (name !== '') {
+ string += ':';
+ }
+ return string += ' ' + name;
+ });
+
+ itemsEnter
+ .style('opacity', 0)
+ .transition()
+ .style('opacity', 1);
+
+ items = itemsEnter
+ .merge(items);
+
+ items
+ .on('mouseover', mouseover)
+ .on('mouseout', mouseout)
+ .on('click', click);
+
+
+ // Download changeset link
+ var changeset = new osmChangeset().update({ id: undefined });
+ var changes = history.changes(actionDiscardTags(history.difference(), _discardTags));
+
+ delete changeset.id; // Export without chnageset_id
+
+ var data = JXON.stringify(changeset.osmChangeJXON(changes));
+ var blob = new Blob([data], {type: 'text/xml;charset=utf-8;'});
+ var fileName = 'changes.osc';
+
+ var linkEnter = container.selectAll('.download-changes')
+ .data([0])
+ .enter()
+ .append('a')
+ .attr('class', 'download-changes');
+
+ if (detected.download) { // All except IE11 and Edge
+ linkEnter // download the data as a file
+ .attr('href', window.URL.createObjectURL(blob))
+ .attr('download', fileName);
+
+ } else { // IE11 and Edge
+ linkEnter // open data uri in a new tab
+ .attr('target', '_blank')
+ .on('click.download', function() {
+ navigator.msSaveBlob(blob, fileName);
+ });
+ }
+
+ linkEnter
+ .call(svgIcon('#iD-icon-load', 'inline'))
+ .append('span')
+ .text(_t('commit.download_changes'));
+
+
+ function mouseover(d) {
+ if (d.entity) {
+ context.surface().selectAll(
+ utilEntityOrMemberSelector([d.entity.id], context.graph())
+ ).classed('hover', true);
+ }
+ }
+
+
+ function mouseout() {
+ context.surface().selectAll('.hover')
+ .classed('hover', false);
+ }
+
+
+ function click(change) {
+ if (change.changeType !== 'deleted') {
+ var entity = change.entity;
+ context.map().zoomToEase(entity);
+ context.surface().selectAll(utilEntityOrMemberSelector([entity.id], context.graph()))
+ .classed('hover', true);
+ }
+ }
+ }
+
+ return section;
+ }
+
+ function uiCommitWarnings(context) {
+
+ function commitWarnings(selection) {
+ var issuesBySeverity = context.validator()
+ .getIssuesBySeverity({ what: 'edited', where: 'all', includeDisabledRules: true });
+
+ for (var severity in issuesBySeverity) {
+ var issues = issuesBySeverity[severity];
+ var section = severity + '-section';
+ var issueItem = severity + '-item';
+
+ var container = selection.selectAll('.' + section)
+ .data(issues.length ? [0] : []);
+
+ container.exit()
+ .remove();
+
+ var containerEnter = container.enter()
+ .append('div')
+ .attr('class', 'modal-section ' + section + ' fillL2');
+
+ containerEnter
+ .append('h3')
+ .text(severity === 'warning' ? _t('commit.warnings') : _t('commit.errors'));
+
+ containerEnter
+ .append('ul')
+ .attr('class', 'changeset-list');
+
+ container = containerEnter
+ .merge(container);
+
+
+ var items = container.select('ul').selectAll('li')
+ .data(issues, function(d) { return d.id; });
+
+ items.exit()
+ .remove();
+
+ var itemsEnter = items.enter()
+ .append('li')
+ .attr('class', issueItem);
+
+ itemsEnter
+ .call(svgIcon('#iD-icon-alert', 'pre-text'));
+
+ itemsEnter
+ .append('strong')
+ .attr('class', 'issue-message');
+
+ itemsEnter.filter(function(d) { return d.tooltip; })
+ .call(uiTooltip()
+ .title(function(d) { return d.tooltip; })
+ .placement('top')
+ );
+
+ items = itemsEnter
+ .merge(items);
+
+ items.selectAll('.issue-message')
+ .text(function(d) {
+ return d.message(context);
+ });
+
+ items
+ .on('mouseover', function(d) {
+ if (d.entityIds) {
+ context.surface().selectAll(
+ utilEntityOrMemberSelector(
+ d.entityIds,
+ context.graph()
+ )
+ ).classed('hover', true);
+ }
+ })
+ .on('mouseout', function() {
+ context.surface().selectAll('.hover')
+ .classed('hover', false);
+ })
+ .on('click', function(d) {
+ context.validator().focusIssue(d);
+ });
+ }
+ }
+
+
+ return commitWarnings;
+ }
+
+ function uiSectionRawTagEditor(id, context) {
+
+ var section = uiSection(id, context)
+ .classes('raw-tag-editor')
+ .title(function() {
+ var count = Object.keys(_tags).filter(function(d) { return d; }).length;
+ return _t('inspector.title_count', { title: _t('inspector.tags'), count: count });
+ })
+ .expandedByDefault(false)
+ .disclosureContent(renderDisclosureContent);
+
+ var taginfo = services.taginfo;
+ var dispatch$1 = dispatch('change');
+ var availableViews = [
+ { id: 'text', icon: '#fas-i-cursor' },
+ { id: 'list', icon: '#fas-th-list' }
+ ];
+
+ var _tagView = (corePreferences('raw-tag-editor-view') || 'list'); // 'list, 'text'
+ var _readOnlyTags = [];
+ // the keys in the order we want them to display
+ var _orderedKeys = [];
+ var _showBlank = false;
+ var _pendingChange = null;
+ var _state;
+ var _presets;
+ var _tags;
+ var _entityIDs;
+
+ function renderDisclosureContent(wrap) {
+
+ // remove deleted keys
+ _orderedKeys = _orderedKeys.filter(function(key) {
+ return _tags[key] !== undefined;
+ });
+
+ // When switching to a different entity or changing the state (hover/select)
+ // reorder the keys alphabetically.
+ // We trigger this by emptying the `_orderedKeys` array, then it will be rebuilt here.
+ // Otherwise leave their order alone - #5857, #5927
+ var all = Object.keys(_tags).sort();
+ var missingKeys = utilArrayDifference(all, _orderedKeys);
+ for (var i in missingKeys) {
+ _orderedKeys.push(missingKeys[i]);
+ }
+
+ // assemble row data
+ var rowData = _orderedKeys.map(function(key, i) {
+ return { index: i, key: key, value: _tags[key] };
+ });
+
+ // append blank row last, if necessary
+ if (!rowData.length || _showBlank) {
+ _showBlank = false;
+ rowData.push({ index: rowData.length, key: '', value: '' });
+ }
+
+
+ // View Options
+ var options = wrap.selectAll('.raw-tag-options')
+ .data([0]);
+
+ options.exit()
+ .remove();
+
+ var optionsEnter = options.enter()
+ .insert('div', ':first-child')
+ .attr('class', 'raw-tag-options');
+
+ var optionEnter = optionsEnter.selectAll('.raw-tag-option')
+ .data(availableViews, function(d) { return d.id; })
+ .enter();
+
+ optionEnter
+ .append('button')
+ .attr('class', function(d) {
+ return 'raw-tag-option raw-tag-option-' + d.id + (_tagView === d.id ? ' selected' : '');
+ })
+ .attr('title', function(d) { return _t('icons.' + d.id); })
+ .on('click', function(d) {
+ _tagView = d.id;
+ corePreferences('raw-tag-editor-view', d.id);
+
+ wrap.selectAll('.raw-tag-option')
+ .classed('selected', function(datum) { return datum === d; });
+
+ wrap.selectAll('.tag-text')
+ .classed('hide', (d.id !== 'text'))
+ .each(setTextareaHeight);
+
+ wrap.selectAll('.tag-list, .add-row')
+ .classed('hide', (d.id !== 'list'));
+ })
+ .each(function(d) {
+ select(this)
+ .call(svgIcon(d.icon));
+ });
+
+
+ // View as Text
+ var textData = rowsToText(rowData);
+ var textarea = wrap.selectAll('.tag-text')
+ .data([0]);
+
+ textarea = textarea.enter()
+ .append('textarea')
+ .attr('class', 'tag-text' + (_tagView !== 'text' ? ' hide' : ''))
+ .call(utilNoAuto)
+ .attr('placeholder', _t('inspector.key_value'))
+ .attr('spellcheck', 'false')
+ .merge(textarea);
+
+ textarea
+ .call(utilGetSetValue, textData)
+ .each(setTextareaHeight)
+ .on('input', setTextareaHeight)
+ .on('blur', textChanged)
+ .on('change', textChanged);
+
+
+ // View as List
+ var list = wrap.selectAll('.tag-list')
+ .data([0]);
+
+ list = list.enter()
+ .append('ul')
+ .attr('class', 'tag-list' + (_tagView !== 'list' ? ' hide' : ''))
+ .merge(list);
+
+
+ // Container for the Add button
+ var addRowEnter = wrap.selectAll('.add-row')
+ .data([0])
+ .enter()
+ .append('div')
+ .attr('class', 'add-row' + (_tagView !== 'list' ? ' hide' : ''));
+
+ addRowEnter
+ .append('button')
+ .attr('class', 'add-tag')
+ .call(svgIcon('#iD-icon-plus', 'light'))
+ .on('click', addTag);
+
+ addRowEnter
+ .append('div')
+ .attr('class', 'space-value'); // preserve space
+
+ addRowEnter
+ .append('div')
+ .attr('class', 'space-buttons'); // preserve space
+
+
+ // Tag list items
+ var items = list.selectAll('.tag-row')
+ .data(rowData, function(d) { return d.key; });
+
+ items.exit()
+ .each(unbind)
+ .remove();
+
+
+ // Enter
+ var itemsEnter = items.enter()
+ .append('li')
+ .attr('class', 'tag-row')
+ .classed('readonly', isReadOnly);
+
+ var innerWrap = itemsEnter.append('div')
+ .attr('class', 'inner-wrap');
+
+ innerWrap
+ .append('div')
+ .attr('class', 'key-wrap')
+ .append('input')
+ .property('type', 'text')
+ .attr('class', 'key')
+ .call(utilNoAuto)
+ .on('blur', keyChange)
+ .on('change', keyChange);
+
+ innerWrap
+ .append('div')
+ .attr('class', 'value-wrap')
+ .append('input')
+ .property('type', 'text')
+ .attr('class', 'value')
+ .call(utilNoAuto)
+ .on('blur', valueChange)
+ .on('change', valueChange)
+ .on('keydown.push-more', pushMore);
+
+ innerWrap
+ .append('button')
+ .attr('tabindex', -1)
+ .attr('class', 'form-field-button remove')
+ .attr('title', _t('icons.remove'))
+ .call(svgIcon('#iD-operation-delete'));
+
+
+ // Update
+ items = items
+ .merge(itemsEnter)
+ .sort(function(a, b) { return a.index - b.index; });
+
+ items
+ .each(function(d) {
+ var row = select(this);
+ var key = row.select('input.key'); // propagate bound data
+ var value = row.select('input.value'); // propagate bound data
+
+ if (_entityIDs && taginfo && _state !== 'hover') {
+ bindTypeahead(key, value);
+ }
+
+ var reference;
+
+ if (typeof d.value !== 'string') {
+ reference = uiTagReference({ key: d.key });
+ } else {
+ var isRelation = _entityIDs && _entityIDs.some(function(entityID) {
+ return context.entity(entityID).type === 'relation';
+ });
+ if (isRelation && d.key === 'type') {
+ reference = uiTagReference({ rtype: d.value });
+ } else {
+ reference = uiTagReference({ key: d.key, value: d.value });
+ }
+ }
+
+ if (_state === 'hover') {
+ reference.showing(false);
+ }
+
+ row.select('.inner-wrap') // propagate bound data
+ .call(reference.button);
+
+ row.call(reference.body);
+
+ row.select('button.remove'); // propagate bound data
+ });
+
+ items.selectAll('input.key')
+ .attr('title', function(d) { return d.key; })
+ .call(utilGetSetValue, function(d) { return d.key; })
+ .attr('readonly', function(d) {
+ return (isReadOnly(d) || (typeof d.value !== 'string')) || null;
+ });
+
+ items.selectAll('input.value')
+ .attr('title', function(d) {
+ return Array.isArray(d.value) ? d.value.filter(Boolean).join('\n') : d.value;
+ })
+ .classed('mixed', function(d) {
+ return Array.isArray(d.value);
+ })
+ .attr('placeholder', function(d) {
+ return typeof d.value === 'string' ? null : _t('inspector.multiple_values');
+ })
+ .call(utilGetSetValue, function(d) {
+ return typeof d.value === 'string' ? d.value : '';
+ })
+ .attr('readonly', function(d) {
+ return isReadOnly(d) || null;
+ });
+
+ items.selectAll('button.remove')
+ .on(('PointerEvent' in window ? 'pointer' : 'mouse') + 'down', removeTag); // 'click' fires too late - #5878
+
+ }
+
+ function isReadOnly(d) {
+ for (var i = 0; i < _readOnlyTags.length; i++) {
+ if (d.key.match(_readOnlyTags[i]) !== null) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ function setTextareaHeight() {
+ if (_tagView !== 'text') return;
+
+ var selection = select(this);
+ selection.style('height', null);
+ selection.style('height', selection.node().scrollHeight + 5 + 'px');
+ }
+
+ function stringify(s) {
+ return JSON.stringify(s).slice(1, -1); // without leading/trailing "
+ }
+
+ function unstringify(s) {
+ var leading = '';
+ var trailing = '';
+ if (s.length < 1 || s.charAt(0) !== '"') {
+ leading = '"';
+ }
+ if (s.length < 2 || s.charAt(s.length - 1) !== '"' ||
+ (s.charAt(s.length - 1) === '"' && s.charAt(s.length - 2) === '\\')
+ ) {
+ trailing = '"';
+ }
+ return JSON.parse(leading + s + trailing);
+ }
+
+ function rowsToText(rows) {
+ var str = rows
+ .filter(function(row) { return row.key && row.key.trim() !== ''; })
+ .map(function(row) {
+ var rawVal = row.value;
+ if (typeof rawVal !== 'string') rawVal = '*';
+ var val = rawVal ? stringify(rawVal) : '';
+ return stringify(row.key) + '=' + val;
+ })
+ .join('\n');
+
+ if (_state !== 'hover' && str.length) {
+ return str + '\n';
+ }
+ return str;
+ }
+
+ function textChanged() {
+ var newText = this.value.trim();
+ var newTags = {};
+ newText.split('\n').forEach(function(row) {
+ var m = row.match(/^\s*([^=]+)=(.*)$/);
+ if (m !== null) {
+ var k = context.cleanTagKey(unstringify(m[1].trim()));
+ var v = context.cleanTagValue(unstringify(m[2].trim()));
+ newTags[k] = v;
+ }
+ });
+
+ var tagDiff = utilTagDiff(_tags, newTags);
+ if (!tagDiff.length) return;
+
+ _pendingChange = _pendingChange || {};
+
+ tagDiff.forEach(function(change) {
+ if (isReadOnly({ key: change.key })) return;
+
+ // skip unchanged multiselection placeholders
+ if (change.newVal === '*' && typeof change.oldVal !== 'string') return;
+
+ if (change.type === '-') {
+ _pendingChange[change.key] = undefined;
+ } else if (change.type === '+') {
+ _pendingChange[change.key] = change.newVal || '';
+ }
+ });
+
+ if (Object.keys(_pendingChange).length === 0) {
+ _pendingChange = null;
+ return;
+ }
+
+ scheduleChange();
+ }
+
+ function pushMore() {
+ // if pressing Tab on the last value field with content, add a blank row
+ if (event.keyCode === 9 && !event.shiftKey &&
+ section.selection().selectAll('.tag-list li:last-child input.value').node() === this &&
+ utilGetSetValue(select(this))) {
+ addTag();
+ }
+ }
+
+ function bindTypeahead(key, value) {
+ if (isReadOnly(key.datum())) return;
+
+ if (Array.isArray(value.datum().value)) {
+ value.call(uiCombobox(context, 'tag-value')
+ .minItems(1)
+ .fetcher(function(value, callback) {
+ var keyString = utilGetSetValue(key);
+ if (!_tags[keyString]) return;
+ var data = _tags[keyString].filter(Boolean).map(function(tagValue) {
+ return {
+ value: tagValue,
+ title: tagValue
+ };
+ });
+ callback(data);
+ }));
+ return;
+ }
+
+ var geometry = context.graph().geometry(_entityIDs[0]);
+
+ key.call(uiCombobox(context, 'tag-key')
+ .fetcher(function(value, callback) {
+ taginfo.keys({
+ debounce: true,
+ geometry: geometry,
+ query: value
+ }, function(err, data) {
+ if (!err) {
+ var filtered = data.filter(function(d) { return _tags[d.value] === undefined; });
+ callback(sort(value, filtered));
+ }
+ });
+ }));
+
+ value.call(uiCombobox(context, 'tag-value')
+ .fetcher(function(value, callback) {
+ taginfo.values({
+ debounce: true,
+ key: utilGetSetValue(key),
+ geometry: geometry,
+ query: value
+ }, function(err, data) {
+ if (!err) callback(sort(value, data));
+ });
+ }));
+
+
+ function sort(value, data) {
+ var sameletter = [];
+ var other = [];
+ for (var i = 0; i < data.length; i++) {
+ if (data[i].value.substring(0, value.length) === value) {
+ sameletter.push(data[i]);
+ } else {
+ other.push(data[i]);
+ }
+ }
+ return sameletter.concat(other);
+ }
+ }
+
+ function unbind() {
+ var row = select(this);
+
+ row.selectAll('input.key')
+ .call(uiCombobox.off, context);
+
+ row.selectAll('input.value')
+ .call(uiCombobox.off, context);
+ }
+
+ function keyChange(d) {
+ if (select(this).attr('readonly')) return;
+
+ var kOld = d.key;
+
+ // exit if we are currently about to delete this row anyway - #6366
+ if (_pendingChange && _pendingChange.hasOwnProperty(kOld) && _pendingChange[kOld] === undefined) return;
+
+ var kNew = context.cleanTagKey(this.value.trim());
+
+ // allow no change if the key should be readonly
+ if (isReadOnly({ key: kNew })) {
+ this.value = kOld;
+ return;
+ }
+
+ if (kNew &&
+ kNew !== kOld &&
+ _tags[kNew] !== undefined) {
+ // new key is already in use, switch focus to the existing row
+
+ this.value = kOld; // reset the key
+ section.selection().selectAll('.tag-list input.value')
+ .each(function(d) {
+ if (d.key === kNew) { // send focus to that other value combo instead
+ var input = select(this).node();
+ input.focus();
+ input.select();
+ }
+ });
+ return;
+ }
+
+
+ var row = this.parentNode.parentNode;
+ var inputVal = select(row).selectAll('input.value');
+ var vNew = context.cleanTagValue(utilGetSetValue(inputVal));
+
+ _pendingChange = _pendingChange || {};
+
+ if (kOld) {
+ _pendingChange[kOld] = undefined;
+ }
+
+ _pendingChange[kNew] = vNew;
+
+ // update the ordered key index so this row doesn't change position
+ var existingKeyIndex = _orderedKeys.indexOf(kOld);
+ if (existingKeyIndex !== -1) _orderedKeys[existingKeyIndex] = kNew;
+
+ d.key = kNew; // update datum to avoid exit/enter on tag update
+ d.value = vNew;
+
+ this.value = kNew;
+ utilGetSetValue(inputVal, vNew);
+ scheduleChange();
+ }
+
+ function valueChange(d) {
+ if (isReadOnly(d)) return;
+
+ // exit if this is a multiselection and no value was entered
+ if (typeof d.value !== 'string' && !this.value) return;
+
+ // exit if we are currently about to delete this row anyway - #6366
+ if (_pendingChange && _pendingChange.hasOwnProperty(d.key) && _pendingChange[d.key] === undefined) return;
+
+ _pendingChange = _pendingChange || {};
+
+ _pendingChange[d.key] = context.cleanTagValue(this.value);
+ scheduleChange();
+ }
+
+ function removeTag(d) {
+ if (isReadOnly(d)) return;
+
+ if (d.key === '') { // removing the blank row
+ _showBlank = false;
+ section.reRender();
+
+ } else {
+ // remove the key from the ordered key index
+ _orderedKeys = _orderedKeys.filter(function(key) { return key !== d.key; });
+
+ _pendingChange = _pendingChange || {};
+ _pendingChange[d.key] = undefined;
+ scheduleChange();
+ }
+ }
+
+ function addTag() {
+ // Delay render in case this click is blurring an edited combo.
+ // Without the setTimeout, the `content` render would wipe out the pending tag change.
+ window.setTimeout(function() {
+ _showBlank = true;
+ section.reRender();
+ section.selection().selectAll('.tag-list li:last-child input.key').node().focus();
+ }, 20);
+ }
+
+ function scheduleChange() {
+ // Cache IDs in case the editor is reloaded before the change event is called. - #6028
+ var entityIDs = _entityIDs;
+
+ // Delay change in case this change is blurring an edited combo. - #5878
+ window.setTimeout(function() {
+ if (!_pendingChange) return;
+
+ dispatch$1.call('change', this, entityIDs, _pendingChange);
+ _pendingChange = null;
+ }, 10);
+ }
+
+
+ section.state = function(val) {
+ if (!arguments.length) return _state;
+ if (_state !== val) {
+ _orderedKeys = [];
+ _state = val;
+ }
+ return section;
+ };
+
+
+ section.presets = function(val) {
+ if (!arguments.length) return _presets;
+ _presets = val;
+ if (_presets && _presets.length && _presets[0].isFallback()) {
+ section.disclosureExpanded(true);
+ } else {
+ section.disclosureExpanded(null);
+ }
+ return section;
+ };
+
+
+ section.tags = function(val) {
+ if (!arguments.length) return _tags;
+ _tags = val;
+ return section;
+ };
+
+
+ section.entityIDs = function(val) {
+ if (!arguments.length) return _entityIDs;
+ if (!_entityIDs || !val || !utilArrayIdentical(_entityIDs, val)) {
+ _entityIDs = val;
+ _orderedKeys = [];
+ }
+ return section;
+ };
+
+
+ // pass an array of regular expressions to test against the tag key
+ section.readOnlyTags = function(val) {
+ if (!arguments.length) return _readOnlyTags;
+ _readOnlyTags = val;
+ return section;
+ };
+
+
+ return utilRebind(section, dispatch$1, 'on');
+ }
+
+ var readOnlyTags = [
+ /^changesets_count$/,
+ /^created_by$/,
+ /^ideditor:/,
+ /^imagery_used$/,
+ /^host$/,
+ /^locale$/,
+ /^warnings:/,
+ /^resolved:/,
+ /^closed:note$/,
+ /^closed:keepright$/,
+ /^closed:improveosm:/,
+ /^closed:osmose:/
+ ];
+
+ // treat most punctuation (except -, _, +, &) as hashtag delimiters - #4398
+ // from https://stackoverflow.com/a/25575009
+ var hashtagRegex = /(#[^\u2000-\u206F\u2E00-\u2E7F\s\\'!"#$%()*,.\/:;<=>?@\[\]^`{|}~]+)/g;
+
+
+ function uiCommit(context) {
+ var dispatch$1 = dispatch('cancel');
+ var _userDetails;
+ var _selection;
+
+ var changesetEditor = uiChangesetEditor(context)
+ .on('change', changeTags);
+ var rawTagEditor = uiSectionRawTagEditor('changeset-tag-editor', context)
+ .on('change', changeTags)
+ .readOnlyTags(readOnlyTags);
+ var commitChanges = uiSectionChanges(context);
+ var commitWarnings = uiCommitWarnings(context);
+
+
+ function commit(selection) {
+ _selection = selection;
+
+ // Initialize changeset if one does not exist yet.
+ if (!context.changeset) initChangeset();
+
+ loadDerivedChangesetTags();
+
+ selection.call(render);
+ }
+
+ function initChangeset() {
+
+ // expire stored comment, hashtags, source after cutoff datetime - #3947 #4899
+ var commentDate = +corePreferences('commentDate') || 0;
+ var currDate = Date.now();
+ var cutoff = 2 * 86400 * 1000; // 2 days
+ if (commentDate > currDate || currDate - commentDate > cutoff) {
+ corePreferences('comment', null);
+ corePreferences('hashtags', null);
+ corePreferences('source', null);
+ }
+
+ // load in explicitly-set values, if any
+ if (context.defaultChangesetComment()) {
+ corePreferences('comment', context.defaultChangesetComment());
+ corePreferences('commentDate', Date.now());
+ }
+ if (context.defaultChangesetSource()) {
+ corePreferences('source', context.defaultChangesetSource());
+ corePreferences('commentDate', Date.now());
+ }
+ if (context.defaultChangesetHashtags()) {
+ corePreferences('hashtags', context.defaultChangesetHashtags());
+ corePreferences('commentDate', Date.now());
+ }
+
+ var detected = utilDetect();
+ var tags = {
+ comment: corePreferences('comment') || '',
+ created_by: context.cleanTagValue('RapiD ' + context.rapidContext().version),
+ host: context.cleanTagValue(detected.host),
+ locale: context.cleanTagValue(_mainLocalizer.localeCode())
+ };
+
+ // call findHashtags initially - this will remove stored
+ // hashtags if any hashtags are found in the comment - #4304
+ findHashtags(tags, true);
+
+ var hashtags = corePreferences('hashtags');
+ if (hashtags) {
+ tags.hashtags = hashtags;
+ }
+
+ var source = corePreferences('source');
+ if (source) {
+ tags.source = source;
+ }
+ var photoOverlaysUsed = context.history().photoOverlaysUsed();
+ if (photoOverlaysUsed.length) {
+ var sources = (tags.source || '').split(';');
+
+ // include this tag for any photo layer
+ if (sources.indexOf('streetlevel imagery') === -1) {
+ sources.push('streetlevel imagery');
+ }
+
+ // add the photo overlays used during editing as sources
+ photoOverlaysUsed.forEach(function(photoOverlay) {
+ if (sources.indexOf(photoOverlay) === -1) {
+ sources.push(photoOverlay);
+ }
+ });
+
+ tags.source = context.cleanTagValue(sources.join(';'));
+ }
+
+ context.changeset = new osmChangeset({ tags: tags });
+ }
+
+ // Calculates read-only metadata tags based on the user's editing session and applies
+ // them to the changeset.
+ function loadDerivedChangesetTags() {
+
+ var osm = context.connection();
+ if (!osm) return;
+
+ var tags = Object.assign({}, context.changeset.tags); // shallow copy
+
+ // assign tags for imagery used
+ var imageryUsed = context.cleanTagValue(context.history().imageryUsed().join(';'));
+ tags.imagery_used = imageryUsed || 'None';
+
+ // assign tags for closed issues and notes
+ var osmClosed = osm.getClosedIDs();
+ var itemType;
+ if (osmClosed.length) {
+ tags['closed:note'] = context.cleanTagValue(osmClosed.join(';'));
+ }
+ if (services.keepRight) {
+ var krClosed = services.keepRight.getClosedIDs();
+ if (krClosed.length) {
+ tags['closed:keepright'] = context.cleanTagValue(krClosed.join(';'));
+ }
+ }
+ if (services.improveOSM) {
+ var iOsmClosed = services.improveOSM.getClosedCounts();
+ for (itemType in iOsmClosed) {
+ tags['closed:improveosm:' + itemType] = context.cleanTagValue(iOsmClosed[itemType].toString());
+ }
+ }
+ if (services.osmose) {
+ var osmoseClosed = services.osmose.getClosedCounts();
+ for (itemType in osmoseClosed) {
+ tags['closed:osmose:' + itemType] = context.cleanTagValue(osmoseClosed[itemType].toString());
+ }
+ }
+
+ // remove existing issue counts
+ for (var key in tags) {
+ if (key.match(/(^warnings:)|(^resolved:)/)) {
+ delete tags[key];
+ }
+ }
+
+ function addIssueCounts(issues, prefix) {
+ var issuesByType = utilArrayGroupBy(issues, 'type');
+ for (var issueType in issuesByType) {
+ var issuesOfType = issuesByType[issueType];
+ if (issuesOfType[0].subtype) {
+ var issuesBySubtype = utilArrayGroupBy(issuesOfType, 'subtype');
+ for (var issueSubtype in issuesBySubtype) {
+ var issuesOfSubtype = issuesBySubtype[issueSubtype];
+ tags[prefix + ':' + issueType + ':' + issueSubtype] = context.cleanTagValue(issuesOfSubtype.length.toString());
+ }
+ } else {
+ tags[prefix + ':' + issueType] = context.cleanTagValue(issuesOfType.length.toString());
+ }
+ }
+ }
+
+ // add counts of warnings generated by the user's edits
+ var warnings = context.validator()
+ .getIssuesBySeverity({ what: 'edited', where: 'all', includeIgnored: true, includeDisabledRules: true }).warning;
+ addIssueCounts(warnings, 'warnings');
+
+ // add counts of issues resolved by the user's edits
+ var resolvedIssues = context.validator().getResolvedIssues();
+ addIssueCounts(resolvedIssues, 'resolved');
+
+ context.changeset = context.changeset.update({ tags: tags });
+ }
+
+ function render(selection) {
+
+ var osm = context.connection();
+ if (!osm) return;
+
+ var header = selection.selectAll('.header')
+ .data([0]);
+
+ var headerTitle = header.enter()
+ .append('div')
+ .attr('class', 'header fillL header-container');
+
+ headerTitle
+ .append('div')
+ .attr('class', 'header-block header-block-outer');
+
+ headerTitle
+ .append('div')
+ .attr('class', 'header-block')
+ .append('h3')
+ .text(_t('commit.title'));
+
+ headerTitle
+ .append('div')
+ .attr('class', 'header-block header-block-outer header-block-close')
+ .append('button')
+ .attr('class', 'close')
+ .on('click', function() {
+ dispatch$1.call('cancel', this);
+ })
+ .call(svgIcon('#iD-icon-close'));
+
+ var body = selection.selectAll('.body')
+ .data([0]);
+
+ body = body.enter()
+ .append('div')
+ .attr('class', 'body')
+ .merge(body);
+
+
+ // Changeset Section
+ var changesetSection = body.selectAll('.changeset-editor')
+ .data([0]);
+
+ changesetSection = changesetSection.enter()
+ .append('div')
+ .attr('class', 'modal-section changeset-editor')
+ .merge(changesetSection);
+
+ changesetSection
+ .call(changesetEditor
+ .changesetID(context.changeset.id)
+ .tags(context.changeset.tags)
+ );
+
+
+ // Warnings
+ body.call(commitWarnings);
+
+
+ // Upload Explanation
+ var saveSection = body.selectAll('.save-section')
+ .data([0]);
+
+ saveSection = saveSection.enter()
+ .append('div')
+ .attr('class','modal-section save-section fillL')
+ .merge(saveSection);
+
+ var prose = saveSection.selectAll('.commit-info')
+ .data([0]);
+
+ if (prose.enter().size()) { // first time, make sure to update user details in prose
+ _userDetails = null;
+ }
+
+ prose = prose.enter()
+ .append('p')
+ .attr('class', 'commit-info')
+ .text(_t('commit.upload_explanation'))
+ .merge(prose);
+
+ // always check if this has changed, but only update prose.html()
+ // if needed, because it can trigger a style recalculation
+ osm.userDetails(function(err, user) {
+ if (err) return;
+
+ if (_userDetails === user) return; // no change
+ _userDetails = user;
+
+ var userLink = select(document.createElement('div'));
+
+ if (user.image_url) {
+ userLink
+ .append('img')
+ .attr('src', user.image_url)
+ .attr('class', 'icon pre-text user-icon');
+ }
+
+ userLink
+ .append('a')
+ .attr('class', 'user-info')
+ .text(user.display_name)
+ .attr('href', osm.userURL(user.display_name))
+ .attr('target', '_blank');
+
+ prose
+ .html(_t('commit.upload_explanation_with_user', { user: userLink.html() }));
+ });
+
+
+ // Request Review
+ var requestReview = saveSection.selectAll('.request-review')
+ .data([0]);
+
+ // Enter
+ var requestReviewEnter = requestReview.enter()
+ .append('div')
+ .attr('class', 'request-review');
+
+ var requestReviewDomId = utilUniqueDomId('commit-input-request-review');
+
+ var labelEnter = requestReviewEnter
+ .append('label')
+ .attr('for', requestReviewDomId);
+
+ labelEnter
+ .append('input')
+ .attr('type', 'checkbox')
+ .attr('id', requestReviewDomId);
+
+ labelEnter
+ .append('span')
+ .text(_t('commit.request_review'));
+
+ // Update
+ requestReview = requestReview
+ .merge(requestReviewEnter);
+
+ var requestReviewInput = requestReview.selectAll('input')
+ .property('checked', isReviewRequested(context.changeset.tags))
+ .on('change', toggleRequestReview);
+
+
+ // Buttons
+ var buttonSection = saveSection.selectAll('.buttons')
+ .data([0]);
+
+ // enter
+ var buttonEnter = buttonSection.enter()
+ .append('div')
+ .attr('class', 'buttons fillL');
+
+ buttonEnter
+ .append('button')
+ .attr('class', 'secondary-action button cancel-button')
+ .append('span')
+ .attr('class', 'label')
+ .text(_t('commit.cancel'));
+
+ var uploadButton = buttonEnter
+ .append('button')
+ .attr('class', 'action button save-button');
+
+ uploadButton.append('span')
+ .attr('class', 'label')
+ .text(_t('commit.save'));
+
+ var uploadBlockerTooltipText = getUploadBlockerMessage();
+
+ // update
+ buttonSection = buttonSection
+ .merge(buttonEnter);
+
+ buttonSection.selectAll('.cancel-button')
+ .on('click.cancel', function() {
+ dispatch$1.call('cancel', this);
+ });
+
+ buttonSection.selectAll('.save-button')
+ .classed('disabled', uploadBlockerTooltipText !== null)
+ .on('click.save', function() {
+ if (!select(this).classed('disabled')) {
+ this.blur(); // avoid keeping focus on the button - #4641
+ context.uploader().save(context.changeset);
+ }
+ });
+
+ // remove any existing tooltip
+ uiTooltip().destroyAny(buttonSection.selectAll('.save-button'));
+
+ if (uploadBlockerTooltipText) {
+ buttonSection.selectAll('.save-button')
+ .call(uiTooltip().title(uploadBlockerTooltipText).placement('top'));
+ }
+
+ // Raw Tag Editor
+ var tagSection = body.selectAll('.tag-section.raw-tag-editor')
+ .data([0]);
+
+ tagSection = tagSection.enter()
+ .append('div')
+ .attr('class', 'modal-section tag-section raw-tag-editor')
+ .merge(tagSection);
+
+ tagSection
+ .call(rawTagEditor
+ .tags(Object.assign({}, context.changeset.tags)) // shallow copy
+ .render
+ );
+
+ var changesSection = body.selectAll('.commit-changes-section')
+ .data([0]);
+
+ changesSection = changesSection.enter()
+ .append('div')
+ .attr('class', 'modal-section commit-changes-section')
+ .merge(changesSection);
+
+ // Change summary
+ changesSection.call(commitChanges.render);
+
+
+ function toggleRequestReview() {
+ var rr = requestReviewInput.property('checked');
+ updateChangeset({ review_requested: (rr ? 'yes' : undefined) });
+
+ tagSection
+ .call(rawTagEditor
+ .tags(Object.assign({}, context.changeset.tags)) // shallow copy
+ .render
+ );
+ }
+ }
+
+
+ function getUploadBlockerMessage() {
+ var errors = context.validator()
+ .getIssuesBySeverity({ what: 'edited', where: 'all' }).error;
+
+ if (errors.length) {
+ return _t('commit.outstanding_errors_message', { count: errors.length });
+
+ } else {
+ var hasChangesetComment = context.changeset && context.changeset.tags.comment && context.changeset.tags.comment.trim().length;
+ if (!hasChangesetComment) {
+ return _t('commit.comment_needed_message');
+ }
+ }
+ return null;
+ }
+
+
+ function changeTags(_, changed, onInput) {
+ if (changed.hasOwnProperty('comment')) {
+ if (changed.comment === undefined) {
+ changed.comment = '';
+ }
+ if (!onInput) {
+ corePreferences('comment', changed.comment);
+ corePreferences('commentDate', Date.now());
+ }
+ }
+ if (changed.hasOwnProperty('source')) {
+ if (changed.source === undefined) {
+ corePreferences('source', null);
+ } else if (!onInput) {
+ corePreferences('source', changed.source);
+ corePreferences('commentDate', Date.now());
+ }
+ }
+ // no need to update `prefs` for `hashtags` here since it's done in `updateChangeset`
+
+ updateChangeset(changed, onInput);
+
+ if (_selection) {
+ _selection.call(render);
+ }
+ }
+
+
+ function findHashtags(tags, commentOnly) {
+ var detectedHashtags = commentHashtags();
+
+ if (detectedHashtags.length) {
+ // always remove stored hashtags if there are hashtags in the comment - #4304
+ corePreferences('hashtags', null);
+ }
+ if (!detectedHashtags.length || !commentOnly) {
+ detectedHashtags = detectedHashtags.concat(hashtagHashtags());
+ }
+
+ var allLowerCase = new Set();
+ return detectedHashtags.filter(function(hashtag) {
+ // Compare tags as lowercase strings, but keep original case tags
+ var lowerCase = hashtag.toLowerCase();
+ if (!allLowerCase.has(lowerCase)) {
+ allLowerCase.add(lowerCase);
+ return true;
+ }
+ return false;
+ });
+
+ // Extract hashtags from `comment`
+ function commentHashtags() {
+ var matches = (tags.comment || '')
+ .replace(/http\S*/g, '') // drop anything that looks like a URL - #4289
+ .match(hashtagRegex);
+
+ return matches || [];
+ }
+
+ // Extract and clean hashtags from `hashtags`
+ function hashtagHashtags() {
+ var matches = (tags.hashtags || '')
+ .split(/[,;\s]+/)
+ .map(function (s) {
+ if (s[0] !== '#') { s = '#' + s; } // prepend '#'
+ var matched = s.match(hashtagRegex);
+ return matched && matched[0];
+ }).filter(Boolean); // exclude falsy
+
+ return matches || [];
+ }
+ }
+
+
+ function isReviewRequested(tags) {
+ var rr = tags.review_requested;
+ if (rr === undefined) return false;
+ rr = rr.trim().toLowerCase();
+ return !(rr === '' || rr === 'no');
+ }
+
+
+ function updateChangeset(changed, onInput) {
+ var tags = Object.assign({}, context.changeset.tags); // shallow copy
+
+ Object.keys(changed).forEach(function(k) {
+ var v = changed[k];
+ k = context.cleanTagKey(k);
+ if (readOnlyTags.indexOf(k) !== -1) return;
+
+ if (k !== '' && v !== undefined) {
+ if (onInput) {
+ tags[k] = v;
+ } else {
+ tags[k] = context.cleanTagValue(v);
+ }
+ } else {
+ delete tags[k];
+ }
+ });
+
+ if (!onInput) {
+ // when changing the comment, override hashtags with any found in comment.
+ var commentOnly = changed.hasOwnProperty('comment') && (changed.comment !== '');
+ var arr = findHashtags(tags, commentOnly);
+ if (arr.length) {
+ tags.hashtags = context.cleanTagValue(arr.join(';'));
+ corePreferences('hashtags', tags.hashtags);
+ } else {
+ delete tags.hashtags;
+ corePreferences('hashtags', null);
+ }
+ }
+
+ // always update userdetails, just in case user reauthenticates as someone else
+ if (_userDetails && _userDetails.changesets_count !== undefined) {
+ var changesetsCount = parseInt(_userDetails.changesets_count, 10) + 1; // #4283
+ tags.changesets_count = String(changesetsCount);
+
+ // first 100 edits - new user
+ if (changesetsCount <= 100) {
+ var s;
+ s = corePreferences('walkthrough_completed');
+ if (s) {
+ tags['ideditor:walkthrough_completed'] = s;
+ }
+
+ s = corePreferences('walkthrough_progress');
+ if (s) {
+ tags['ideditor:walkthrough_progress'] = s;
+ }
+
+ s = corePreferences('walkthrough_started');
+ if (s) {
+ tags['ideditor:walkthrough_started'] = s;
+ }
+ }
+ } else {
+ delete tags.changesets_count;
+ }
+
+ if (!fastDeepEqual(context.changeset.tags, tags)) {
+ context.changeset = context.changeset.update({ tags: tags });
+ }
+ }
+
+
+ commit.reset = function() {
+ context.changeset = null;
+ };
+
+
+ return utilRebind(commit, dispatch$1, 'on');
+ }
+
+ var RADIUS = 6378137;
+ var FLATTENING = 1/298.257223563;
+ var POLAR_RADIUS$1 = 6356752.3142;
+
+ var wgs84 = {
+ RADIUS: RADIUS,
+ FLATTENING: FLATTENING,
+ POLAR_RADIUS: POLAR_RADIUS$1
+ };
+
+ var geometry_1 = geometry;
+ var 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;
+ }
+
+ var geojsonArea = {
+ geometry: geometry_1,
+ ring: ring
+ };
+
+ function toRadians(angleInDegrees) {
+ return (angleInDegrees * Math.PI) / 180;
+ }
+
+ function toDegrees(angleInRadians) {
+ return (angleInRadians * 180) / Math.PI;
+ }
+
+ function offset(c1, distance, bearing) {
+ var lat1 = toRadians(c1[1]);
+ var lon1 = toRadians(c1[0]);
+ var dByR = distance / 6378137; // distance divided by 6378137 (radius of the earth) wgs84
+ var lat = Math.asin(
+ Math.sin(lat1) * Math.cos(dByR) +
+ Math.cos(lat1) * Math.sin(dByR) * Math.cos(bearing)
+ );
+ var lon =
+ lon1 +
+ Math.atan2(
+ Math.sin(bearing) * Math.sin(dByR) * Math.cos(lat1),
+ Math.cos(dByR) - Math.sin(lat1) * Math.sin(lat)
+ );
+ return [toDegrees(lon), toDegrees(lat)];
+ }
+
+ function validateCenter(center) {
+ const validCenterLengths = [2, 3];
+ if (!Array.isArray(center) || !validCenterLengths.includes(center.length)) {
+ throw new Error("ERROR! Center has to be an array of length two or three");
+ }
+ const [lng, lat] = center;
+ if (typeof lng !== "number" || typeof lat !== "number") {
+ throw new Error(
+ `ERROR! Longitude and Latitude has to be numbers but where ${typeof lng} and ${typeof lat}`
+ );
+ }
+ if (lng > 180 || lng < -180) {
+ throw new Error(
+ `ERROR! Longitude has to be between -180 and 180 but was ${lng}`
+ );
+ }
+
+ if (lat > 90 || lat < -90) {
+ throw new Error(
+ `ERROR! Latitude has to be between -90 and 90 but was ${lat}`
+ );
+ }
+ }
+
+ function validateRadius(radius) {
+ if (typeof radius !== "number") {
+ throw new Error(
+ `ERROR! Radius has to be a positive number but was: ${typeof radius}`
+ );
+ }
+
+ if (radius <= 0) {
+ throw new Error(
+ `ERROR! Radius has to be a positive number but was: ${radius}`
+ );
+ }
+ }
+
+ function validateNumberOfSegments(numberOfSegments) {
+ if (typeof numberOfSegments !== "number" && numberOfSegments !== undefined) {
+ throw new Error(
+ `ERROR! Number of segments has to be a number but was: ${typeof numberOfSegments}`
+ );
+ }
+
+ if (numberOfSegments < 3) {
+ throw new Error(
+ `ERROR! Number of segments has to be at least 3 but was: ${numberOfSegments}`
+ );
+ }
+ }
+
+ function validateInput({ center, radius, numberOfSegments }) {
+ validateCenter(center);
+ validateRadius(radius);
+ validateNumberOfSegments(numberOfSegments);
+ }
+
+ var circleToPolygon = function circleToPolygon(center, radius, numberOfSegments) {
+ var n = numberOfSegments ? numberOfSegments : 32;
+
+ // validateInput() throws error on invalid input and do nothing on valid input
+ validateInput({ center, radius, numberOfSegments });
+
+ var coordinates = [];
+ for (var i = 0; i < n; ++i) {
+ coordinates.push(offset(center, radius, (2 * Math.PI * -i) / n));
+ }
+ coordinates.push(coordinates[0]);
+
+ return {
+ type: "Polygon",
+ coordinates: [coordinates]
+ };
+ };
+
+ var geojsonPrecision = createCommonjsModule(function (module) {
+ (function() {
+
+ function parse(t, coordinatePrecision, extrasPrecision) {
+
+ function point(p) {
+ return p.map(function(e, index) {
+ if (index < 2) {
+ return 1 * e.toFixed(coordinatePrecision);
+ } else {
+ return 1 * e.toFixed(extrasPrecision);
+ }
+ });
+ }
+
+ function multi(l) {
+ return l.map(point);
+ }
+
+ function poly(p) {
+ return p.map(multi);
+ }
+
+ function multiPoly(m) {
+ return m.map(poly);
+ }
+
+ function geometry(obj) {
+ if (!obj) {
+ return {};
+ }
+
+ switch (obj.type) {
+ case "Point":
+ obj.coordinates = point(obj.coordinates);
+ return obj;
+ case "LineString":
+ case "MultiPoint":
+ obj.coordinates = multi(obj.coordinates);
+ return obj;
+ case "Polygon":
+ case "MultiLineString":
+ obj.coordinates = poly(obj.coordinates);
+ return obj;
+ case "MultiPolygon":
+ obj.coordinates = multiPoly(obj.coordinates);
+ return obj;
+ case "GeometryCollection":
+ obj.geometries = obj.geometries.map(geometry);
+ return obj;
+ default :
+ return {};
+ }
+ }
+
+ function feature(obj) {
+ obj.geometry = geometry(obj.geometry);
+ return obj
+ }
+
+ function featureCollection(f) {
+ f.features = f.features.map(feature);
+ return f;
+ }
+
+ function geometryCollection(g) {
+ g.geometries = g.geometries.map(geometry);
+ return g;
+ }
+
+ if (!t) {
+ return t;
+ }
+
+ switch (t.type) {
+ case "Feature":
+ return feature(t);
+ case "GeometryCollection" :
+ return geometryCollection(t);
+ case "FeatureCollection" :
+ return featureCollection(t);
+ case "Point":
+ case "LineString":
+ case "Polygon":
+ case "MultiPoint":
+ case "MultiPolygon":
+ case "MultiLineString":
+ return geometry(t);
+ default :
+ return t;
+ }
+
+ }
+
+ module.exports = parse;
+ module.exports.parse = parse;
+
+ }());
+ });
+
+ /* Polyfill service v3.13.0
+ * For detailed credits and licence information see http://github.com/financial-times/polyfill-service
+ *
+ * - Array.prototype.fill, License: CC0 */
+
+ if (!('fill' in Array.prototype)) {
+ Object.defineProperty(Array.prototype, 'fill', {
+ configurable: true,
+ value: function fill (value) {
+ if (this === undefined || this === null) {
+ throw new TypeError(this + ' is not an object')
+ }
+
+ var arrayLike = Object(this);
+
+ var length = Math.max(Math.min(arrayLike.length, 9007199254740991), 0) || 0;
+
+ var relativeStart = 1 in arguments ? parseInt(Number(arguments[1]), 10) || 0 : 0;
+
+ relativeStart = relativeStart < 0 ? Math.max(length + relativeStart, 0) : Math.min(relativeStart, length);
+
+ var relativeEnd = 2 in arguments && arguments[2] !== undefined ? parseInt(Number(arguments[2]), 10) || 0 : length;
+
+ relativeEnd = relativeEnd < 0 ? Math.max(length + arguments[2], 0) : Math.min(relativeEnd, length);
+
+ while (relativeStart < relativeEnd) {
+ arrayLike[relativeStart] = value;
+
+ ++relativeStart;
+ }
+
+ return arrayLike
+ },
+ writable: true
+ });
+ }
+
+ /**
+ * Polyfill for IE support
+ */
+ Number.isFinite = Number.isFinite || function (value) {
+ return typeof value === 'number' && isFinite(value)
+ };
+
+ Number.isInteger = Number.isInteger || function (val) {
+ return typeof val === 'number' &&
+ isFinite(val) &&
+ Math.floor(val) === val
+ };
+
+ Number.parseFloat = Number.parseFloat || parseFloat;
+
+ Number.isNaN = Number.isNaN || function (value) {
+ return value !== value // eslint-disable-line
+ };
+
+ /**
+ * Polyfill for IE support
+ */
+ Math.trunc = Math.trunc || function (x) {
+ return x < 0 ? Math.ceil(x) : Math.floor(x)
+ };
+
+ var NumberUtil = function NumberUtil () {};
+
+ NumberUtil.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ NumberUtil.prototype.getClass = function getClass () {
+ return NumberUtil
+ };
+ NumberUtil.prototype.equalsWithTolerance = function equalsWithTolerance (x1, x2, tolerance) {
+ return Math.abs(x1 - x2) <= tolerance
+ };
+
+ var IllegalArgumentException = (function (Error) {
+ function IllegalArgumentException (message) {
+ Error.call(this, message);
+ this.name = 'IllegalArgumentException';
+ this.message = message;
+ this.stack = (new Error()).stack;
+ }
+
+ if ( Error ) IllegalArgumentException.__proto__ = Error;
+ IllegalArgumentException.prototype = Object.create( Error && Error.prototype );
+ IllegalArgumentException.prototype.constructor = IllegalArgumentException;
+
+ return IllegalArgumentException;
+ }(Error));
+
+ var Double = function Double () {};
+
+ var staticAccessors$1 = { MAX_VALUE: { configurable: true } };
+
+ Double.isNaN = function isNaN (n) { return Number.isNaN(n) };
+ Double.doubleToLongBits = function doubleToLongBits (n) { return n };
+ Double.longBitsToDouble = function longBitsToDouble (n) { return n };
+ Double.isInfinite = function isInfinite (n) { return !Number.isFinite(n) };
+ staticAccessors$1.MAX_VALUE.get = function () { return Number.MAX_VALUE };
+
+ Object.defineProperties( Double, staticAccessors$1 );
+
+ var Comparable = function Comparable () {};
+
+ var Clonable = function Clonable () {};
+
+ var Comparator = function Comparator () {};
+
+ function Serializable () {}
+
+ // import Assert from '../util/Assert'
+
+ var Coordinate = function Coordinate () {
+ this.x = null;
+ this.y = null;
+ this.z = null;
+ if (arguments.length === 0) {
+ this.x = 0.0;
+ this.y = 0.0;
+ this.z = Coordinate.NULL_ORDINATE;
+ } else if (arguments.length === 1) {
+ var c = arguments[0];
+ this.x = c.x;
+ this.y = c.y;
+ this.z = c.z;
+ } else if (arguments.length === 2) {
+ this.x = arguments[0];
+ this.y = arguments[1];
+ this.z = Coordinate.NULL_ORDINATE;
+ } else if (arguments.length === 3) {
+ this.x = arguments[0];
+ this.y = arguments[1];
+ this.z = arguments[2];
+ }
+ };
+
+ var staticAccessors = { DimensionalComparator: { configurable: true },serialVersionUID: { configurable: true },NULL_ORDINATE: { configurable: true },X: { configurable: true },Y: { configurable: true },Z: { configurable: true } };
+ Coordinate.prototype.setOrdinate = function setOrdinate (ordinateIndex, value) {
+ switch (ordinateIndex) {
+ case Coordinate.X:
+ this.x = value;
+ break
+ case Coordinate.Y:
+ this.y = value;
+ break
+ case Coordinate.Z:
+ this.z = value;
+ break
+ default:
+ throw new IllegalArgumentException('Invalid ordinate index: ' + ordinateIndex)
+ }
+ };
+ Coordinate.prototype.equals2D = function equals2D () {
+ if (arguments.length === 1) {
+ var other = arguments[0];
+ if (this.x !== other.x) {
+ return false
+ }
+ if (this.y !== other.y) {
+ return false
+ }
+ return true
+ } else if (arguments.length === 2) {
+ var c = arguments[0];
+ var tolerance = arguments[1];
+ if (!NumberUtil.equalsWithTolerance(this.x, c.x, tolerance)) {
+ return false
+ }
+ if (!NumberUtil.equalsWithTolerance(this.y, c.y, tolerance)) {
+ return false
+ }
+ return true
+ }
+ };
+ Coordinate.prototype.getOrdinate = function getOrdinate (ordinateIndex) {
+ switch (ordinateIndex) {
+ case Coordinate.X:
+ return this.x
+ case Coordinate.Y:
+ return this.y
+ case Coordinate.Z:
+ return this.z
+ }
+ throw new IllegalArgumentException('Invalid ordinate index: ' + ordinateIndex)
+ };
+ Coordinate.prototype.equals3D = function equals3D (other) {
+ return this.x === other.x &&
+ this.y === other.y &&
+ ((this.z === other.z || Double.isNaN(this.z)) &&
+ Double.isNaN(other.z))
+ };
+ Coordinate.prototype.equals = function equals (other) {
+ if (!(other instanceof Coordinate)) {
+ return false
+ }
+ return this.equals2D(other)
+ };
+ Coordinate.prototype.equalInZ = function equalInZ (c, tolerance) {
+ return NumberUtil.equalsWithTolerance(this.z, c.z, tolerance)
+ };
+ Coordinate.prototype.compareTo = function compareTo (o) {
+ var other = o;
+ if (this.x < other.x) { return -1 }
+ if (this.x > other.x) { return 1 }
+ if (this.y < other.y) { return -1 }
+ if (this.y > other.y) { return 1 }
+ return 0
+ };
+ Coordinate.prototype.clone = function clone () {
+ // try {
+ // var coord = null
+ // return coord
+ // } catch (e) {
+ // if (e instanceof CloneNotSupportedException) {
+ // Assert.shouldNeverReachHere("this shouldn't happen because this class is Cloneable")
+ // return null
+ // } else throw e
+ // } finally {}
+ };
+ Coordinate.prototype.copy = function copy () {
+ return new Coordinate(this)
+ };
+ Coordinate.prototype.toString = function toString () {
+ return '(' + this.x + ', ' + this.y + ', ' + this.z + ')'
+ };
+ Coordinate.prototype.distance3D = function distance3D (c) {
+ var dx = this.x - c.x;
+ var dy = this.y - c.y;
+ var dz = this.z - c.z;
+ return Math.sqrt(dx * dx + dy * dy + dz * dz)
+ };
+ Coordinate.prototype.distance = function distance (c) {
+ var dx = this.x - c.x;
+ var dy = this.y - c.y;
+ return Math.sqrt(dx * dx + dy * dy)
+ };
+ Coordinate.prototype.hashCode = function hashCode () {
+ var result = 17;
+ result = 37 * result + Coordinate.hashCode(this.x);
+ result = 37 * result + Coordinate.hashCode(this.y);
+ return result
+ };
+ Coordinate.prototype.setCoordinate = function setCoordinate (other) {
+ this.x = other.x;
+ this.y = other.y;
+ this.z = other.z;
+ };
+ Coordinate.prototype.interfaces_ = function interfaces_ () {
+ return [Comparable, Clonable, Serializable]
+ };
+ Coordinate.prototype.getClass = function getClass () {
+ return Coordinate
+ };
+ Coordinate.hashCode = function hashCode () {
+ if (arguments.length === 1) {
+ var x = arguments[0];
+ var f = Double.doubleToLongBits(x);
+ return Math.trunc((f ^ f) >>> 32)
+ }
+ };
+ staticAccessors.DimensionalComparator.get = function () { return DimensionalComparator };
+ staticAccessors.serialVersionUID.get = function () { return 6683108902428366910 };
+ staticAccessors.NULL_ORDINATE.get = function () { return Double.NaN };
+ staticAccessors.X.get = function () { return 0 };
+ staticAccessors.Y.get = function () { return 1 };
+ staticAccessors.Z.get = function () { return 2 };
+
+ Object.defineProperties( Coordinate, staticAccessors );
+
+ var DimensionalComparator = function DimensionalComparator (dimensionsToTest) {
+ this._dimensionsToTest = 2;
+ if (arguments.length === 0) ; else if (arguments.length === 1) {
+ var dimensionsToTest$1 = arguments[0];
+ if (dimensionsToTest$1 !== 2 && dimensionsToTest$1 !== 3) { throw new IllegalArgumentException('only 2 or 3 dimensions may be specified') }
+ this._dimensionsToTest = dimensionsToTest$1;
+ }
+ };
+ DimensionalComparator.prototype.compare = function compare (o1, o2) {
+ var c1 = o1;
+ var c2 = o2;
+ var compX = DimensionalComparator.compare(c1.x, c2.x);
+ if (compX !== 0) { return compX }
+ var compY = DimensionalComparator.compare(c1.y, c2.y);
+ if (compY !== 0) { return compY }
+ if (this._dimensionsToTest <= 2) { return 0 }
+ var compZ = DimensionalComparator.compare(c1.z, c2.z);
+ return compZ
+ };
+ DimensionalComparator.prototype.interfaces_ = function interfaces_ () {
+ return [Comparator]
+ };
+ DimensionalComparator.prototype.getClass = function getClass () {
+ return DimensionalComparator
+ };
+ DimensionalComparator.compare = function compare (a, b) {
+ if (a < b) { return -1 }
+ if (a > b) { return 1 }
+ if (Double.isNaN(a)) {
+ if (Double.isNaN(b)) { return 0 }
+ return -1
+ }
+ if (Double.isNaN(b)) { return 1 }
+ return 0
+ };
+
+ // import hasInterface from '../../../../hasInterface'
+ // import CoordinateSequence from './CoordinateSequence'
+
+ var CoordinateSequenceFactory = function CoordinateSequenceFactory () {};
+
+ CoordinateSequenceFactory.prototype.create = function create () {
+ // if (arguments.length === 1) {
+ // if (arguments[0] instanceof Array) {
+ // let coordinates = arguments[0]
+ // } else if (hasInterface(arguments[0], CoordinateSequence)) {
+ // let coordSeq = arguments[0]
+ // }
+ // } else if (arguments.length === 2) {
+ // let size = arguments[0]
+ // let dimension = arguments[1]
+ // }
+ };
+ CoordinateSequenceFactory.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ CoordinateSequenceFactory.prototype.getClass = function getClass () {
+ return CoordinateSequenceFactory
+ };
+
+ var Location = function Location () {};
+
+ var staticAccessors$4 = { INTERIOR: { configurable: true },BOUNDARY: { configurable: true },EXTERIOR: { configurable: true },NONE: { configurable: true } };
+
+ Location.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ Location.prototype.getClass = function getClass () {
+ return Location
+ };
+ Location.toLocationSymbol = function toLocationSymbol (locationValue) {
+ switch (locationValue) {
+ case Location.EXTERIOR:
+ return 'e'
+ case Location.BOUNDARY:
+ return 'b'
+ case Location.INTERIOR:
+ return 'i'
+ case Location.NONE:
+ return '-'
+ }
+ throw new IllegalArgumentException('Unknown location value: ' + locationValue)
+ };
+ staticAccessors$4.INTERIOR.get = function () { return 0 };
+ staticAccessors$4.BOUNDARY.get = function () { return 1 };
+ staticAccessors$4.EXTERIOR.get = function () { return 2 };
+ staticAccessors$4.NONE.get = function () { return -1 };
+
+ Object.defineProperties( Location, staticAccessors$4 );
+
+ var hasInterface = function (o, i) {
+ return o.interfaces_ && o.interfaces_().indexOf(i) > -1
+ };
+
+ var MathUtil = function MathUtil () {};
+
+ var staticAccessors$5 = { LOG_10: { configurable: true } };
+
+ MathUtil.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ MathUtil.prototype.getClass = function getClass () {
+ return MathUtil
+ };
+ MathUtil.log10 = function log10 (x) {
+ var ln = Math.log(x);
+ if (Double.isInfinite(ln)) { return ln }
+ if (Double.isNaN(ln)) { return ln }
+ return ln / MathUtil.LOG_10
+ };
+ MathUtil.min = function min (v1, v2, v3, v4) {
+ var min = v1;
+ if (v2 < min) { min = v2; }
+ if (v3 < min) { min = v3; }
+ if (v4 < min) { min = v4; }
+ return min
+ };
+ MathUtil.clamp = function clamp () {
+ if (typeof arguments[2] === 'number' && (typeof arguments[0] === 'number' && typeof arguments[1] === 'number')) {
+ var x = arguments[0];
+ var min = arguments[1];
+ var max = arguments[2];
+ if (x < min) { return min }
+ if (x > max) { return max }
+ return x
+ } else if (Number.isInteger(arguments[2]) && (Number.isInteger(arguments[0]) && Number.isInteger(arguments[1]))) {
+ var x$1 = arguments[0];
+ var min$1 = arguments[1];
+ var max$1 = arguments[2];
+ if (x$1 < min$1) { return min$1 }
+ if (x$1 > max$1) { return max$1 }
+ return x$1
+ }
+ };
+ MathUtil.wrap = function wrap (index, max) {
+ if (index < 0) {
+ return max - -index % max
+ }
+ return index % max
+ };
+ MathUtil.max = function max () {
+ if (arguments.length === 3) {
+ var v1 = arguments[0];
+ var v2 = arguments[1];
+ var v3 = arguments[2];
+ var max = v1;
+ if (v2 > max) { max = v2; }
+ if (v3 > max) { max = v3; }
+ return max
+ } else if (arguments.length === 4) {
+ var v1$1 = arguments[0];
+ var v2$1 = arguments[1];
+ var v3$1 = arguments[2];
+ var v4 = arguments[3];
+ var max$1 = v1$1;
+ if (v2$1 > max$1) { max$1 = v2$1; }
+ if (v3$1 > max$1) { max$1 = v3$1; }
+ if (v4 > max$1) { max$1 = v4; }
+ return max$1
+ }
+ };
+ MathUtil.average = function average (x1, x2) {
+ return (x1 + x2) / 2.0
+ };
+ staticAccessors$5.LOG_10.get = function () { return Math.log(10) };
+
+ Object.defineProperties( MathUtil, staticAccessors$5 );
+
+ var StringBuffer = function StringBuffer (str) {
+ this.str = str;
+ };
+ StringBuffer.prototype.append = function append (e) {
+ this.str += e;
+ };
+
+ StringBuffer.prototype.setCharAt = function setCharAt (i, c) {
+ this.str = this.str.substr(0, i) + c + this.str.substr(i + 1);
+ };
+
+ StringBuffer.prototype.toString = function toString (e) {
+ return this.str
+ };
+
+ var Integer = function Integer (value) {
+ this.value = value;
+ };
+ Integer.prototype.intValue = function intValue () {
+ return this.value
+ };
+ Integer.prototype.compareTo = function compareTo (o) {
+ if (this.value < o) { return -1 }
+ if (this.value > o) { return 1 }
+ return 0
+ };
+ Integer.isNaN = function isNaN (n) { return Number.isNaN(n) };
+
+ var Character = function Character () {};
+
+ Character.isWhitespace = function isWhitespace (c) { return ((c <= 32 && c >= 0) || c === 127) };
+ Character.toUpperCase = function toUpperCase (c) { return c.toUpperCase() };
+
+ var DD = function DD () {
+ this._hi = 0.0;
+ this._lo = 0.0;
+ if (arguments.length === 0) {
+ this.init(0.0);
+ } else if (arguments.length === 1) {
+ if (typeof arguments[0] === 'number') {
+ var x = arguments[0];
+ this.init(x);
+ } else if (arguments[0] instanceof DD) {
+ var dd = arguments[0];
+ this.init(dd);
+ } else if (typeof arguments[0] === 'string') {
+ var str = arguments[0];
+ DD.call(this, DD.parse(str));
+ }
+ } else if (arguments.length === 2) {
+ var hi = arguments[0];
+ var lo = arguments[1];
+ this.init(hi, lo);
+ }
+ };
+
+ var staticAccessors$7 = { PI: { configurable: true },TWO_PI: { configurable: true },PI_2: { configurable: true },E: { configurable: true },NaN: { configurable: true },EPS: { configurable: true },SPLIT: { configurable: true },MAX_PRINT_DIGITS: { configurable: true },TEN: { configurable: true },ONE: { configurable: true },SCI_NOT_EXPONENT_CHAR: { configurable: true },SCI_NOT_ZERO: { configurable: true } };
+ DD.prototype.le = function le (y) {
+ return (this._hi < y._hi || this._hi === y._hi) && this._lo <= y._lo
+ };
+ DD.prototype.extractSignificantDigits = function extractSignificantDigits (insertDecimalPoint, magnitude) {
+ var y = this.abs();
+ var mag = DD.magnitude(y._hi);
+ var scale = DD.TEN.pow(mag);
+ y = y.divide(scale);
+ if (y.gt(DD.TEN)) {
+ y = y.divide(DD.TEN);
+ mag += 1;
+ } else if (y.lt(DD.ONE)) {
+ y = y.multiply(DD.TEN);
+ mag -= 1;
+ }
+ var decimalPointPos = mag + 1;
+ var buf = new StringBuffer();
+ var numDigits = DD.MAX_PRINT_DIGITS - 1;
+ for (var i = 0; i <= numDigits; i++) {
+ if (insertDecimalPoint && i === decimalPointPos) {
+ buf.append('.');
+ }
+ var digit = Math.trunc(y._hi);
+ if (digit < 0) {
+ break
+ }
+ var rebiasBy10 = false;
+ var digitChar = 0;
+ if (digit > 9) {
+ rebiasBy10 = true;
+ digitChar = '9';
+ } else {
+ digitChar = '0' + digit;
+ }
+ buf.append(digitChar);
+ y = y.subtract(DD.valueOf(digit)).multiply(DD.TEN);
+ if (rebiasBy10) { y.selfAdd(DD.TEN); }
+ var continueExtractingDigits = true;
+ var remMag = DD.magnitude(y._hi);
+ if (remMag < 0 && Math.abs(remMag) >= numDigits - i) { continueExtractingDigits = false; }
+ if (!continueExtractingDigits) { break }
+ }
+ magnitude[0] = mag;
+ return buf.toString()
+ };
+ DD.prototype.sqr = function sqr () {
+ return this.multiply(this)
+ };
+ DD.prototype.doubleValue = function doubleValue () {
+ return this._hi + this._lo
+ };
+ DD.prototype.subtract = function subtract () {
+ if (arguments[0] instanceof DD) {
+ var y = arguments[0];
+ return this.add(y.negate())
+ } else if (typeof arguments[0] === 'number') {
+ var y$1 = arguments[0];
+ return this.add(-y$1)
+ }
+ };
+ DD.prototype.equals = function equals () {
+ if (arguments.length === 1) {
+ var y = arguments[0];
+ return this._hi === y._hi && this._lo === y._lo
+ }
+ };
+ DD.prototype.isZero = function isZero () {
+ return this._hi === 0.0 && this._lo === 0.0
+ };
+ DD.prototype.selfSubtract = function selfSubtract () {
+ if (arguments[0] instanceof DD) {
+ var y = arguments[0];
+ if (this.isNaN()) { return this }
+ return this.selfAdd(-y._hi, -y._lo)
+ } else if (typeof arguments[0] === 'number') {
+ var y$1 = arguments[0];
+ if (this.isNaN()) { return this }
+ return this.selfAdd(-y$1, 0.0)
+ }
+ };
+ DD.prototype.getSpecialNumberString = function getSpecialNumberString () {
+ if (this.isZero()) { return '0.0' }
+ if (this.isNaN()) { return 'NaN ' }
+ return null
+ };
+ DD.prototype.min = function min (x) {
+ if (this.le(x)) {
+ return this
+ } else {
+ return x
+ }
+ };
+ DD.prototype.selfDivide = function selfDivide () {
+ if (arguments.length === 1) {
+ if (arguments[0] instanceof DD) {
+ var y = arguments[0];
+ return this.selfDivide(y._hi, y._lo)
+ } else if (typeof arguments[0] === 'number') {
+ var y$1 = arguments[0];
+ return this.selfDivide(y$1, 0.0)
+ }
+ } else if (arguments.length === 2) {
+ var yhi = arguments[0];
+ var ylo = arguments[1];
+ var hc = null;
+ var tc = null;
+ var hy = null;
+ var ty = null;
+ var C = null;
+ var c = null;
+ var U = null;
+ var u = null;
+ C = this._hi / yhi;
+ c = DD.SPLIT * C;
+ hc = c - C;
+ u = DD.SPLIT * yhi;
+ hc = c - hc;
+ tc = C - hc;
+ hy = u - yhi;
+ U = C * yhi;
+ hy = u - hy;
+ ty = yhi - hy;
+ u = hc * hy - U + hc * ty + tc * hy + tc * ty;
+ c = (this._hi - U - u + this._lo - C * ylo) / yhi;
+ u = C + c;
+ this._hi = u;
+ this._lo = C - u + c;
+ return this
+ }
+ };
+ DD.prototype.dump = function dump () {
+ return 'DD<' + this._hi + ', ' + this._lo + '>'
+ };
+ DD.prototype.divide = function divide () {
+ if (arguments[0] instanceof DD) {
+ var y = arguments[0];
+ var hc = null;
+ var tc = null;
+ var hy = null;
+ var ty = null;
+ var C = null;
+ var c = null;
+ var U = null;
+ var u = null;
+ C = this._hi / y._hi;
+ c = DD.SPLIT * C;
+ hc = c - C;
+ u = DD.SPLIT * y._hi;
+ hc = c - hc;
+ tc = C - hc;
+ hy = u - y._hi;
+ U = C * y._hi;
+ hy = u - hy;
+ ty = y._hi - hy;
+ u = hc * hy - U + hc * ty + tc * hy + tc * ty;
+ c = (this._hi - U - u + this._lo - C * y._lo) / y._hi;
+ u = C + c;
+ var zhi = u;
+ var zlo = C - u + c;
+ return new DD(zhi, zlo)
+ } else if (typeof arguments[0] === 'number') {
+ var y$1 = arguments[0];
+ if (Double.isNaN(y$1)) { return DD.createNaN() }
+ return DD.copy(this).selfDivide(y$1, 0.0)
+ }
+ };
+ DD.prototype.ge = function ge (y) {
+ return (this._hi > y._hi || this._hi === y._hi) && this._lo >= y._lo
+ };
+ DD.prototype.pow = function pow (exp) {
+ if (exp === 0.0) { return DD.valueOf(1.0) }
+ var r = new DD(this);
+ var s = DD.valueOf(1.0);
+ var n = Math.abs(exp);
+ if (n > 1) {
+ while (n > 0) {
+ if (n % 2 === 1) {
+ s.selfMultiply(r);
+ }
+ n /= 2;
+ if (n > 0) { r = r.sqr(); }
+ }
+ } else {
+ s = r;
+ }
+ if (exp < 0) { return s.reciprocal() }
+ return s
+ };
+ DD.prototype.ceil = function ceil () {
+ if (this.isNaN()) { return DD.NaN }
+ var fhi = Math.ceil(this._hi);
+ var flo = 0.0;
+ if (fhi === this._hi) {
+ flo = Math.ceil(this._lo);
+ }
+ return new DD(fhi, flo)
+ };
+ DD.prototype.compareTo = function compareTo (o) {
+ var other = o;
+ if (this._hi < other._hi) { return -1 }
+ if (this._hi > other._hi) { return 1 }
+ if (this._lo < other._lo) { return -1 }
+ if (this._lo > other._lo) { return 1 }
+ return 0
+ };
+ DD.prototype.rint = function rint () {
+ if (this.isNaN()) { return this }
+ var plus5 = this.add(0.5);
+ return plus5.floor()
+ };
+ DD.prototype.setValue = function setValue () {
+ if (arguments[0] instanceof DD) {
+ var value = arguments[0];
+ this.init(value);
+ return this
+ } else if (typeof arguments[0] === 'number') {
+ var value$1 = arguments[0];
+ this.init(value$1);
+ return this
+ }
+ };
+ DD.prototype.max = function max (x) {
+ if (this.ge(x)) {
+ return this
+ } else {
+ return x
+ }
+ };
+ DD.prototype.sqrt = function sqrt () {
+ if (this.isZero()) { return DD.valueOf(0.0) }
+ if (this.isNegative()) {
+ return DD.NaN
+ }
+ var x = 1.0 / Math.sqrt(this._hi);
+ var ax = this._hi * x;
+ var axdd = DD.valueOf(ax);
+ var diffSq = this.subtract(axdd.sqr());
+ var d2 = diffSq._hi * (x * 0.5);
+ return axdd.add(d2)
+ };
+ DD.prototype.selfAdd = function selfAdd () {
+ if (arguments.length === 1) {
+ if (arguments[0] instanceof DD) {
+ var y = arguments[0];
+ return this.selfAdd(y._hi, y._lo)
+ } else if (typeof arguments[0] === 'number') {
+ var y$1 = arguments[0];
+ var H = null;
+ var h = null;
+ var S = null;
+ var s = null;
+ var e = null;
+ var f = null;
+ S = this._hi + y$1;
+ e = S - this._hi;
+ s = S - e;
+ s = y$1 - e + (this._hi - s);
+ f = s + this._lo;
+ H = S + f;
+ h = f + (S - H);
+ this._hi = H + h;
+ this._lo = h + (H - this._hi);
+ return this
+ }
+ } else if (arguments.length === 2) {
+ var yhi = arguments[0];
+ var ylo = arguments[1];
+ var H$1 = null;
+ var h$1 = null;
+ var T = null;
+ var t = null;
+ var S$1 = null;
+ var s$1 = null;
+ var e$1 = null;
+ var f$1 = null;
+ S$1 = this._hi + yhi;
+ T = this._lo + ylo;
+ e$1 = S$1 - this._hi;
+ f$1 = T - this._lo;
+ s$1 = S$1 - e$1;
+ t = T - f$1;
+ s$1 = yhi - e$1 + (this._hi - s$1);
+ t = ylo - f$1 + (this._lo - t);
+ e$1 = s$1 + T;
+ H$1 = S$1 + e$1;
+ h$1 = e$1 + (S$1 - H$1);
+ e$1 = t + h$1;
+ var zhi = H$1 + e$1;
+ var zlo = e$1 + (H$1 - zhi);
+ this._hi = zhi;
+ this._lo = zlo;
+ return this
+ }
+ };
+ DD.prototype.selfMultiply = function selfMultiply () {
+ if (arguments.length === 1) {
+ if (arguments[0] instanceof DD) {
+ var y = arguments[0];
+ return this.selfMultiply(y._hi, y._lo)
+ } else if (typeof arguments[0] === 'number') {
+ var y$1 = arguments[0];
+ return this.selfMultiply(y$1, 0.0)
+ }
+ } else if (arguments.length === 2) {
+ var yhi = arguments[0];
+ var ylo = arguments[1];
+ var hx = null;
+ var tx = null;
+ var hy = null;
+ var ty = null;
+ var C = null;
+ var c = null;
+ C = DD.SPLIT * this._hi;
+ hx = C - this._hi;
+ c = DD.SPLIT * yhi;
+ hx = C - hx;
+ tx = this._hi - hx;
+ hy = c - yhi;
+ C = this._hi * yhi;
+ hy = c - hy;
+ ty = yhi - hy;
+ c = hx * hy - C + hx * ty + tx * hy + tx * ty + (this._hi * ylo + this._lo * yhi);
+ var zhi = C + c;
+ hx = C - zhi;
+ var zlo = c + hx;
+ this._hi = zhi;
+ this._lo = zlo;
+ return this
+ }
+ };
+ DD.prototype.selfSqr = function selfSqr () {
+ return this.selfMultiply(this)
+ };
+ DD.prototype.floor = function floor () {
+ if (this.isNaN()) { return DD.NaN }
+ var fhi = Math.floor(this._hi);
+ var flo = 0.0;
+ if (fhi === this._hi) {
+ flo = Math.floor(this._lo);
+ }
+ return new DD(fhi, flo)
+ };
+ DD.prototype.negate = function negate () {
+ if (this.isNaN()) { return this }
+ return new DD(-this._hi, -this._lo)
+ };
+ DD.prototype.clone = function clone () {
+ // try {
+ // return null
+ // } catch (ex) {
+ // if (ex instanceof CloneNotSupportedException) {
+ // return null
+ // } else throw ex
+ // } finally {}
+ };
+ DD.prototype.multiply = function multiply () {
+ if (arguments[0] instanceof DD) {
+ var y = arguments[0];
+ if (y.isNaN()) { return DD.createNaN() }
+ return DD.copy(this).selfMultiply(y)
+ } else if (typeof arguments[0] === 'number') {
+ var y$1 = arguments[0];
+ if (Double.isNaN(y$1)) { return DD.createNaN() }
+ return DD.copy(this).selfMultiply(y$1, 0.0)
+ }
+ };
+ DD.prototype.isNaN = function isNaN () {
+ return Double.isNaN(this._hi)
+ };
+ DD.prototype.intValue = function intValue () {
+ return Math.trunc(this._hi)
+ };
+ DD.prototype.toString = function toString () {
+ var mag = DD.magnitude(this._hi);
+ if (mag >= -3 && mag <= 20) { return this.toStandardNotation() }
+ return this.toSciNotation()
+ };
+ DD.prototype.toStandardNotation = function toStandardNotation () {
+ var specialStr = this.getSpecialNumberString();
+ if (specialStr !== null) { return specialStr }
+ var magnitude = new Array(1).fill(null);
+ var sigDigits = this.extractSignificantDigits(true, magnitude);
+ var decimalPointPos = magnitude[0] + 1;
+ var num = sigDigits;
+ if (sigDigits.charAt(0) === '.') {
+ num = '0' + sigDigits;
+ } else if (decimalPointPos < 0) {
+ num = '0.' + DD.stringOfChar('0', -decimalPointPos) + sigDigits;
+ } else if (sigDigits.indexOf('.') === -1) {
+ var numZeroes = decimalPointPos - sigDigits.length;
+ var zeroes = DD.stringOfChar('0', numZeroes);
+ num = sigDigits + zeroes + '.0';
+ }
+ if (this.isNegative()) { return '-' + num }
+ return num
+ };
+ DD.prototype.reciprocal = function reciprocal () {
+ var hc = null;
+ var tc = null;
+ var hy = null;
+ var ty = null;
+ var C = null;
+ var c = null;
+ var U = null;
+ var u = null;
+ C = 1.0 / this._hi;
+ c = DD.SPLIT * C;
+ hc = c - C;
+ u = DD.SPLIT * this._hi;
+ hc = c - hc;
+ tc = C - hc;
+ hy = u - this._hi;
+ U = C * this._hi;
+ hy = u - hy;
+ ty = this._hi - hy;
+ u = hc * hy - U + hc * ty + tc * hy + tc * ty;
+ c = (1.0 - U - u - C * this._lo) / this._hi;
+ var zhi = C + c;
+ var zlo = C - zhi + c;
+ return new DD(zhi, zlo)
+ };
+ DD.prototype.toSciNotation = function toSciNotation () {
+ if (this.isZero()) { return DD.SCI_NOT_ZERO }
+ var specialStr = this.getSpecialNumberString();
+ if (specialStr !== null) { return specialStr }
+ var magnitude = new Array(1).fill(null);
+ var digits = this.extractSignificantDigits(false, magnitude);
+ var expStr = DD.SCI_NOT_EXPONENT_CHAR + magnitude[0];
+ if (digits.charAt(0) === '0') {
+ throw new Error('Found leading zero: ' + digits)
+ }
+ var trailingDigits = '';
+ if (digits.length > 1) { trailingDigits = digits.substring(1); }
+ var digitsWithDecimal = digits.charAt(0) + '.' + trailingDigits;
+ if (this.isNegative()) { return '-' + digitsWithDecimal + expStr }
+ return digitsWithDecimal + expStr
+ };
+ DD.prototype.abs = function abs () {
+ if (this.isNaN()) { return DD.NaN }
+ if (this.isNegative()) { return this.negate() }
+ return new DD(this)
+ };
+ DD.prototype.isPositive = function isPositive () {
+ return (this._hi > 0.0 || this._hi === 0.0) && this._lo > 0.0
+ };
+ DD.prototype.lt = function lt (y) {
+ return (this._hi < y._hi || this._hi === y._hi) && this._lo < y._lo
+ };
+ DD.prototype.add = function add () {
+ if (arguments[0] instanceof DD) {
+ var y = arguments[0];
+ return DD.copy(this).selfAdd(y)
+ } else if (typeof arguments[0] === 'number') {
+ var y$1 = arguments[0];
+ return DD.copy(this).selfAdd(y$1)
+ }
+ };
+ DD.prototype.init = function init () {
+ if (arguments.length === 1) {
+ if (typeof arguments[0] === 'number') {
+ var x = arguments[0];
+ this._hi = x;
+ this._lo = 0.0;
+ } else if (arguments[0] instanceof DD) {
+ var dd = arguments[0];
+ this._hi = dd._hi;
+ this._lo = dd._lo;
+ }
+ } else if (arguments.length === 2) {
+ var hi = arguments[0];
+ var lo = arguments[1];
+ this._hi = hi;
+ this._lo = lo;
+ }
+ };
+ DD.prototype.gt = function gt (y) {
+ return (this._hi > y._hi || this._hi === y._hi) && this._lo > y._lo
+ };
+ DD.prototype.isNegative = function isNegative () {
+ return (this._hi < 0.0 || this._hi === 0.0) && this._lo < 0.0
+ };
+ DD.prototype.trunc = function trunc () {
+ if (this.isNaN()) { return DD.NaN }
+ if (this.isPositive()) { return this.floor(); } else { return this.ceil() }
+ };
+ DD.prototype.signum = function signum () {
+ if (this._hi > 0) { return 1 }
+ if (this._hi < 0) { return -1 }
+ if (this._lo > 0) { return 1 }
+ if (this._lo < 0) { return -1 }
+ return 0
+ };
+ DD.prototype.interfaces_ = function interfaces_ () {
+ return [Serializable, Comparable, Clonable]
+ };
+ DD.prototype.getClass = function getClass () {
+ return DD
+ };
+ DD.sqr = function sqr (x) {
+ return DD.valueOf(x).selfMultiply(x)
+ };
+ DD.valueOf = function valueOf () {
+ if (typeof arguments[0] === 'string') {
+ var str = arguments[0];
+ return DD.parse(str)
+ } else if (typeof arguments[0] === 'number') {
+ var x = arguments[0];
+ return new DD(x)
+ }
+ };
+ DD.sqrt = function sqrt (x) {
+ return DD.valueOf(x).sqrt()
+ };
+ DD.parse = function parse (str) {
+ var i = 0;
+ var strlen = str.length;
+ while (Character.isWhitespace(str.charAt(i))) { i++; }
+ var isNegative = false;
+ if (i < strlen) {
+ var signCh = str.charAt(i);
+ if (signCh === '-' || signCh === '+') {
+ i++;
+ if (signCh === '-') { isNegative = true; }
+ }
+ }
+ var val = new DD();
+ var numDigits = 0;
+ var numBeforeDec = 0;
+ var exp = 0;
+ while (true) {
+ if (i >= strlen) { break }
+ var ch = str.charAt(i);
+ i++;
+ if (Character.isDigit(ch)) {
+ var d = ch - '0';
+ val.selfMultiply(DD.TEN);
+ val.selfAdd(d);
+ numDigits++;
+ continue
+ }
+ if (ch === '.') {
+ numBeforeDec = numDigits;
+ continue
+ }
+ if (ch === 'e' || ch === 'E') {
+ var expStr = str.substring(i);
+ try {
+ exp = Integer.parseInt(expStr);
+ } catch (ex) {
+ if (ex instanceof Error) {
+ throw new Error('Invalid exponent ' + expStr + ' in string ' + str)
+ } else { throw ex }
+ } finally {}
+ break
+ }
+ throw new Error("Unexpected character '" + ch + "' at position " + i + ' in string ' + str)
+ }
+ var val2 = val;
+ var numDecPlaces = numDigits - numBeforeDec - exp;
+ if (numDecPlaces === 0) {
+ val2 = val;
+ } else if (numDecPlaces > 0) {
+ var scale = DD.TEN.pow(numDecPlaces);
+ val2 = val.divide(scale);
+ } else if (numDecPlaces < 0) {
+ var scale$1 = DD.TEN.pow(-numDecPlaces);
+ val2 = val.multiply(scale$1);
+ }
+ if (isNegative) {
+ return val2.negate()
+ }
+ return val2
+ };
+ DD.createNaN = function createNaN () {
+ return new DD(Double.NaN, Double.NaN)
+ };
+ DD.copy = function copy (dd) {
+ return new DD(dd)
+ };
+ DD.magnitude = function magnitude (x) {
+ var xAbs = Math.abs(x);
+ var xLog10 = Math.log(xAbs) / Math.log(10);
+ var xMag = Math.trunc(Math.floor(xLog10));
+ var xApprox = Math.pow(10, xMag);
+ if (xApprox * 10 <= xAbs) { xMag += 1; }
+ return xMag
+ };
+ DD.stringOfChar = function stringOfChar (ch, len) {
+ var buf = new StringBuffer();
+ for (var i = 0; i < len; i++) {
+ buf.append(ch);
+ }
+ return buf.toString()
+ };
+ staticAccessors$7.PI.get = function () { return new DD(3.141592653589793116e+00, 1.224646799147353207e-16) };
+ staticAccessors$7.TWO_PI.get = function () { return new DD(6.283185307179586232e+00, 2.449293598294706414e-16) };
+ staticAccessors$7.PI_2.get = function () { return new DD(1.570796326794896558e+00, 6.123233995736766036e-17) };
+ staticAccessors$7.E.get = function () { return new DD(2.718281828459045091e+00, 1.445646891729250158e-16) };
+ staticAccessors$7.NaN.get = function () { return new DD(Double.NaN, Double.NaN) };
+ staticAccessors$7.EPS.get = function () { return 1.23259516440783e-32 };
+ staticAccessors$7.SPLIT.get = function () { return 134217729.0 };
+ staticAccessors$7.MAX_PRINT_DIGITS.get = function () { return 32 };
+ staticAccessors$7.TEN.get = function () { return DD.valueOf(10.0) };
+ staticAccessors$7.ONE.get = function () { return DD.valueOf(1.0) };
+ staticAccessors$7.SCI_NOT_EXPONENT_CHAR.get = function () { return 'E' };
+ staticAccessors$7.SCI_NOT_ZERO.get = function () { return '0.0E0' };
+
+ Object.defineProperties( DD, staticAccessors$7 );
+
+ var CGAlgorithmsDD = function CGAlgorithmsDD () {};
+
+ var staticAccessors$6 = { DP_SAFE_EPSILON: { configurable: true } };
+
+ CGAlgorithmsDD.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ CGAlgorithmsDD.prototype.getClass = function getClass () {
+ return CGAlgorithmsDD
+ };
+ CGAlgorithmsDD.orientationIndex = function orientationIndex (p1, p2, q) {
+ var index = CGAlgorithmsDD.orientationIndexFilter(p1, p2, q);
+ if (index <= 1) { return index }
+ var dx1 = DD.valueOf(p2.x).selfAdd(-p1.x);
+ var dy1 = DD.valueOf(p2.y).selfAdd(-p1.y);
+ var dx2 = DD.valueOf(q.x).selfAdd(-p2.x);
+ var dy2 = DD.valueOf(q.y).selfAdd(-p2.y);
+ return dx1.selfMultiply(dy2).selfSubtract(dy1.selfMultiply(dx2)).signum()
+ };
+ CGAlgorithmsDD.signOfDet2x2 = function signOfDet2x2 (x1, y1, x2, y2) {
+ var det = x1.multiply(y2).selfSubtract(y1.multiply(x2));
+ return det.signum()
+ };
+ CGAlgorithmsDD.intersection = function intersection (p1, p2, q1, q2) {
+ var denom1 = DD.valueOf(q2.y).selfSubtract(q1.y).selfMultiply(DD.valueOf(p2.x).selfSubtract(p1.x));
+ var denom2 = DD.valueOf(q2.x).selfSubtract(q1.x).selfMultiply(DD.valueOf(p2.y).selfSubtract(p1.y));
+ var denom = denom1.subtract(denom2);
+ var numx1 = DD.valueOf(q2.x).selfSubtract(q1.x).selfMultiply(DD.valueOf(p1.y).selfSubtract(q1.y));
+ var numx2 = DD.valueOf(q2.y).selfSubtract(q1.y).selfMultiply(DD.valueOf(p1.x).selfSubtract(q1.x));
+ var numx = numx1.subtract(numx2);
+ var fracP = numx.selfDivide(denom).doubleValue();
+ var x = DD.valueOf(p1.x).selfAdd(DD.valueOf(p2.x).selfSubtract(p1.x).selfMultiply(fracP)).doubleValue();
+ var numy1 = DD.valueOf(p2.x).selfSubtract(p1.x).selfMultiply(DD.valueOf(p1.y).selfSubtract(q1.y));
+ var numy2 = DD.valueOf(p2.y).selfSubtract(p1.y).selfMultiply(DD.valueOf(p1.x).selfSubtract(q1.x));
+ var numy = numy1.subtract(numy2);
+ var fracQ = numy.selfDivide(denom).doubleValue();
+ var y = DD.valueOf(q1.y).selfAdd(DD.valueOf(q2.y).selfSubtract(q1.y).selfMultiply(fracQ)).doubleValue();
+ return new Coordinate(x, y)
+ };
+ CGAlgorithmsDD.orientationIndexFilter = function orientationIndexFilter (pa, pb, pc) {
+ var detsum = null;
+ var detleft = (pa.x - pc.x) * (pb.y - pc.y);
+ var detright = (pa.y - pc.y) * (pb.x - pc.x);
+ var det = detleft - detright;
+ if (detleft > 0.0) {
+ if (detright <= 0.0) {
+ return CGAlgorithmsDD.signum(det)
+ } else {
+ detsum = detleft + detright;
+ }
+ } else if (detleft < 0.0) {
+ if (detright >= 0.0) {
+ return CGAlgorithmsDD.signum(det)
+ } else {
+ detsum = -detleft - detright;
+ }
+ } else {
+ return CGAlgorithmsDD.signum(det)
+ }
+ var errbound = CGAlgorithmsDD.DP_SAFE_EPSILON * detsum;
+ if (det >= errbound || -det >= errbound) {
+ return CGAlgorithmsDD.signum(det)
+ }
+ return 2
+ };
+ CGAlgorithmsDD.signum = function signum (x) {
+ if (x > 0) { return 1 }
+ if (x < 0) { return -1 }
+ return 0
+ };
+ staticAccessors$6.DP_SAFE_EPSILON.get = function () { return 1e-15 };
+
+ Object.defineProperties( CGAlgorithmsDD, staticAccessors$6 );
+
+ var CoordinateSequence = function CoordinateSequence () {};
+
+ var staticAccessors$8 = { X: { configurable: true },Y: { configurable: true },Z: { configurable: true },M: { configurable: true } };
+
+ staticAccessors$8.X.get = function () { return 0 };
+ staticAccessors$8.Y.get = function () { return 1 };
+ staticAccessors$8.Z.get = function () { return 2 };
+ staticAccessors$8.M.get = function () { return 3 };
+ CoordinateSequence.prototype.setOrdinate = function setOrdinate (index, ordinateIndex, value) {};
+ CoordinateSequence.prototype.size = function size () {};
+ CoordinateSequence.prototype.getOrdinate = function getOrdinate (index, ordinateIndex) {};
+ CoordinateSequence.prototype.getCoordinate = function getCoordinate () {};
+ CoordinateSequence.prototype.getCoordinateCopy = function getCoordinateCopy (i) {};
+ CoordinateSequence.prototype.getDimension = function getDimension () {};
+ CoordinateSequence.prototype.getX = function getX (index) {};
+ CoordinateSequence.prototype.clone = function clone () {};
+ CoordinateSequence.prototype.expandEnvelope = function expandEnvelope (env) {};
+ CoordinateSequence.prototype.copy = function copy () {};
+ CoordinateSequence.prototype.getY = function getY (index) {};
+ CoordinateSequence.prototype.toCoordinateArray = function toCoordinateArray () {};
+ CoordinateSequence.prototype.interfaces_ = function interfaces_ () {
+ return [Clonable]
+ };
+ CoordinateSequence.prototype.getClass = function getClass () {
+ return CoordinateSequence
+ };
+
+ Object.defineProperties( CoordinateSequence, staticAccessors$8 );
+
+ var Exception = function Exception () {};
+
+ var NotRepresentableException = (function (Exception$$1) {
+ function NotRepresentableException () {
+ Exception$$1.call(this, 'Projective point not representable on the Cartesian plane.');
+ }
+
+ if ( Exception$$1 ) NotRepresentableException.__proto__ = Exception$$1;
+ NotRepresentableException.prototype = Object.create( Exception$$1 && Exception$$1.prototype );
+ NotRepresentableException.prototype.constructor = NotRepresentableException;
+ NotRepresentableException.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ NotRepresentableException.prototype.getClass = function getClass () {
+ return NotRepresentableException
+ };
+
+ return NotRepresentableException;
+ }(Exception));
+
+ var System = function System () {};
+
+ System.arraycopy = function arraycopy (src, srcPos, dest, destPos, len) {
+ var c = 0;
+ for (var i = srcPos; i < srcPos + len; i++) {
+ dest[destPos + c] = src[i];
+ c++;
+ }
+ };
+
+ System.getProperty = function getProperty (name) {
+ return {
+ 'line.separator': '\n'
+ }[name]
+ };
+
+ var HCoordinate = function HCoordinate () {
+ this.x = null;
+ this.y = null;
+ this.w = null;
+ if (arguments.length === 0) {
+ this.x = 0.0;
+ this.y = 0.0;
+ this.w = 1.0;
+ } else if (arguments.length === 1) {
+ var p = arguments[0];
+ this.x = p.x;
+ this.y = p.y;
+ this.w = 1.0;
+ } else if (arguments.length === 2) {
+ if (typeof arguments[0] === 'number' && typeof arguments[1] === 'number') {
+ var _x = arguments[0];
+ var _y = arguments[1];
+ this.x = _x;
+ this.y = _y;
+ this.w = 1.0;
+ } else if (arguments[0] instanceof HCoordinate && arguments[1] instanceof HCoordinate) {
+ var p1 = arguments[0];
+ var p2 = arguments[1];
+ this.x = p1.y * p2.w - p2.y * p1.w;
+ this.y = p2.x * p1.w - p1.x * p2.w;
+ this.w = p1.x * p2.y - p2.x * p1.y;
+ } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Coordinate) {
+ var p1$1 = arguments[0];
+ var p2$1 = arguments[1];
+ this.x = p1$1.y - p2$1.y;
+ this.y = p2$1.x - p1$1.x;
+ this.w = p1$1.x * p2$1.y - p2$1.x * p1$1.y;
+ }
+ } else if (arguments.length === 3) {
+ var _x$1 = arguments[0];
+ var _y$1 = arguments[1];
+ var _w = arguments[2];
+ this.x = _x$1;
+ this.y = _y$1;
+ this.w = _w;
+ } else if (arguments.length === 4) {
+ var p1$2 = arguments[0];
+ var p2$2 = arguments[1];
+ var q1 = arguments[2];
+ var q2 = arguments[3];
+ var px = p1$2.y - p2$2.y;
+ var py = p2$2.x - p1$2.x;
+ var pw = p1$2.x * p2$2.y - p2$2.x * p1$2.y;
+ var qx = q1.y - q2.y;
+ var qy = q2.x - q1.x;
+ var qw = q1.x * q2.y - q2.x * q1.y;
+ this.x = py * qw - qy * pw;
+ this.y = qx * pw - px * qw;
+ this.w = px * qy - qx * py;
+ }
+ };
+ HCoordinate.prototype.getY = function getY () {
+ var a = this.y / this.w;
+ if (Double.isNaN(a) || Double.isInfinite(a)) {
+ throw new NotRepresentableException()
+ }
+ return a
+ };
+ HCoordinate.prototype.getX = function getX () {
+ var a = this.x / this.w;
+ if (Double.isNaN(a) || Double.isInfinite(a)) {
+ throw new NotRepresentableException()
+ }
+ return a
+ };
+ HCoordinate.prototype.getCoordinate = function getCoordinate () {
+ var p = new Coordinate();
+ p.x = this.getX();
+ p.y = this.getY();
+ return p
+ };
+ HCoordinate.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ HCoordinate.prototype.getClass = function getClass () {
+ return HCoordinate
+ };
+ HCoordinate.intersection = function intersection (p1, p2, q1, q2) {
+ var px = p1.y - p2.y;
+ var py = p2.x - p1.x;
+ var pw = p1.x * p2.y - p2.x * p1.y;
+ var qx = q1.y - q2.y;
+ var qy = q2.x - q1.x;
+ var qw = q1.x * q2.y - q2.x * q1.y;
+ var x = py * qw - qy * pw;
+ var y = qx * pw - px * qw;
+ var w = px * qy - qx * py;
+ var xInt = x / w;
+ var yInt = y / w;
+ if (Double.isNaN(xInt) || (Double.isInfinite(xInt) || Double.isNaN(yInt)) || Double.isInfinite(yInt)) {
+ throw new NotRepresentableException()
+ }
+ return new Coordinate(xInt, yInt)
+ };
+
+ var Envelope = function Envelope () {
+ this._minx = null;
+ this._maxx = null;
+ this._miny = null;
+ this._maxy = null;
+ if (arguments.length === 0) {
+ this.init();
+ } else if (arguments.length === 1) {
+ if (arguments[0] instanceof Coordinate) {
+ var p = arguments[0];
+ this.init(p.x, p.x, p.y, p.y);
+ } else if (arguments[0] instanceof Envelope) {
+ var env = arguments[0];
+ this.init(env);
+ }
+ } else if (arguments.length === 2) {
+ var p1 = arguments[0];
+ var p2 = arguments[1];
+ this.init(p1.x, p2.x, p1.y, p2.y);
+ } else if (arguments.length === 4) {
+ var x1 = arguments[0];
+ var x2 = arguments[1];
+ var y1 = arguments[2];
+ var y2 = arguments[3];
+ this.init(x1, x2, y1, y2);
+ }
+ };
+
+ var staticAccessors$9 = { serialVersionUID: { configurable: true } };
+ Envelope.prototype.getArea = function getArea () {
+ return this.getWidth() * this.getHeight()
+ };
+ Envelope.prototype.equals = function equals (other) {
+ if (!(other instanceof Envelope)) {
+ return false
+ }
+ var otherEnvelope = other;
+ if (this.isNull()) {
+ return otherEnvelope.isNull()
+ }
+ return this._maxx === otherEnvelope.getMaxX() && this._maxy === otherEnvelope.getMaxY() && this._minx === otherEnvelope.getMinX() && this._miny === otherEnvelope.getMinY()
+ };
+ Envelope.prototype.intersection = function intersection (env) {
+ if (this.isNull() || env.isNull() || !this.intersects(env)) { return new Envelope() }
+ var intMinX = this._minx > env._minx ? this._minx : env._minx;
+ var intMinY = this._miny > env._miny ? this._miny : env._miny;
+ var intMaxX = this._maxx < env._maxx ? this._maxx : env._maxx;
+ var intMaxY = this._maxy < env._maxy ? this._maxy : env._maxy;
+ return new Envelope(intMinX, intMaxX, intMinY, intMaxY)
+ };
+ Envelope.prototype.isNull = function isNull () {
+ return this._maxx < this._minx
+ };
+ Envelope.prototype.getMaxX = function getMaxX () {
+ return this._maxx
+ };
+ Envelope.prototype.covers = function covers () {
+ if (arguments.length === 1) {
+ if (arguments[0] instanceof Coordinate) {
+ var p = arguments[0];
+ return this.covers(p.x, p.y)
+ } else if (arguments[0] instanceof Envelope) {
+ var other = arguments[0];
+ if (this.isNull() || other.isNull()) {
+ return false
+ }
+ return other.getMinX() >= this._minx && other.getMaxX() <= this._maxx && other.getMinY() >= this._miny && other.getMaxY() <= this._maxy
+ }
+ } else if (arguments.length === 2) {
+ var x = arguments[0];
+ var y = arguments[1];
+ if (this.isNull()) { return false }
+ return x >= this._minx && x <= this._maxx && y >= this._miny && y <= this._maxy
+ }
+ };
+ Envelope.prototype.intersects = function intersects () {
+ if (arguments.length === 1) {
+ if (arguments[0] instanceof Envelope) {
+ var other = arguments[0];
+ if (this.isNull() || other.isNull()) {
+ return false
+ }
+ return !(other._minx > this._maxx || other._maxx < this._minx || other._miny > this._maxy || other._maxy < this._miny)
+ } else if (arguments[0] instanceof Coordinate) {
+ var p = arguments[0];
+ return this.intersects(p.x, p.y)
+ }
+ } else if (arguments.length === 2) {
+ var x = arguments[0];
+ var y = arguments[1];
+ if (this.isNull()) { return false }
+ return !(x > this._maxx || x < this._minx || y > this._maxy || y < this._miny)
+ }
+ };
+ Envelope.prototype.getMinY = function getMinY () {
+ return this._miny
+ };
+ Envelope.prototype.getMinX = function getMinX () {
+ return this._minx
+ };
+ Envelope.prototype.expandToInclude = function expandToInclude () {
+ if (arguments.length === 1) {
+ if (arguments[0] instanceof Coordinate) {
+ var p = arguments[0];
+ this.expandToInclude(p.x, p.y);
+ } else if (arguments[0] instanceof Envelope) {
+ var other = arguments[0];
+ if (other.isNull()) {
+ return null
+ }
+ if (this.isNull()) {
+ this._minx = other.getMinX();
+ this._maxx = other.getMaxX();
+ this._miny = other.getMinY();
+ this._maxy = other.getMaxY();
+ } else {
+ if (other._minx < this._minx) {
+ this._minx = other._minx;
+ }
+ if (other._maxx > this._maxx) {
+ this._maxx = other._maxx;
+ }
+ if (other._miny < this._miny) {
+ this._miny = other._miny;
+ }
+ if (other._maxy > this._maxy) {
+ this._maxy = other._maxy;
+ }
+ }
+ }
+ } else if (arguments.length === 2) {
+ var x = arguments[0];
+ var y = arguments[1];
+ if (this.isNull()) {
+ this._minx = x;
+ this._maxx = x;
+ this._miny = y;
+ this._maxy = y;
+ } else {
+ if (x < this._minx) {
+ this._minx = x;
+ }
+ if (x > this._maxx) {
+ this._maxx = x;
+ }
+ if (y < this._miny) {
+ this._miny = y;
+ }
+ if (y > this._maxy) {
+ this._maxy = y;
+ }
+ }
+ }
+ };
+ Envelope.prototype.minExtent = function minExtent () {
+ if (this.isNull()) { return 0.0 }
+ var w = this.getWidth();
+ var h = this.getHeight();
+ if (w < h) { return w }
+ return h
+ };
+ Envelope.prototype.getWidth = function getWidth () {
+ if (this.isNull()) {
+ return 0
+ }
+ return this._maxx - this._minx
+ };
+ Envelope.prototype.compareTo = function compareTo (o) {
+ var env = o;
+ if (this.isNull()) {
+ if (env.isNull()) { return 0 }
+ return -1
+ } else {
+ if (env.isNull()) { return 1 }
+ }
+ if (this._minx < env._minx) { return -1 }
+ if (this._minx > env._minx) { return 1 }
+ if (this._miny < env._miny) { return -1 }
+ if (this._miny > env._miny) { return 1 }
+ if (this._maxx < env._maxx) { return -1 }
+ if (this._maxx > env._maxx) { return 1 }
+ if (this._maxy < env._maxy) { return -1 }
+ if (this._maxy > env._maxy) { return 1 }
+ return 0
+ };
+ Envelope.prototype.translate = function translate (transX, transY) {
+ if (this.isNull()) {
+ return null
+ }
+ this.init(this.getMinX() + transX, this.getMaxX() + transX, this.getMinY() + transY, this.getMaxY() + transY);
+ };
+ Envelope.prototype.toString = function toString () {
+ return 'Env[' + this._minx + ' : ' + this._maxx + ', ' + this._miny + ' : ' + this._maxy + ']'
+ };
+ Envelope.prototype.setToNull = function setToNull () {
+ this._minx = 0;
+ this._maxx = -1;
+ this._miny = 0;
+ this._maxy = -1;
+ };
+ Envelope.prototype.getHeight = function getHeight () {
+ if (this.isNull()) {
+ return 0
+ }
+ return this._maxy - this._miny
+ };
+ Envelope.prototype.maxExtent = function maxExtent () {
+ if (this.isNull()) { return 0.0 }
+ var w = this.getWidth();
+ var h = this.getHeight();
+ if (w > h) { return w }
+ return h
+ };
+ Envelope.prototype.expandBy = function expandBy () {
+ if (arguments.length === 1) {
+ var distance = arguments[0];
+ this.expandBy(distance, distance);
+ } else if (arguments.length === 2) {
+ var deltaX = arguments[0];
+ var deltaY = arguments[1];
+ if (this.isNull()) { return null }
+ this._minx -= deltaX;
+ this._maxx += deltaX;
+ this._miny -= deltaY;
+ this._maxy += deltaY;
+ if (this._minx > this._maxx || this._miny > this._maxy) { this.setToNull(); }
+ }
+ };
+ Envelope.prototype.contains = function contains () {
+ if (arguments.length === 1) {
+ if (arguments[0] instanceof Envelope) {
+ var other = arguments[0];
+ return this.covers(other)
+ } else if (arguments[0] instanceof Coordinate) {
+ var p = arguments[0];
+ return this.covers(p)
+ }
+ } else if (arguments.length === 2) {
+ var x = arguments[0];
+ var y = arguments[1];
+ return this.covers(x, y)
+ }
+ };
+ Envelope.prototype.centre = function centre () {
+ if (this.isNull()) { return null }
+ return new Coordinate((this.getMinX() + this.getMaxX()) / 2.0, (this.getMinY() + this.getMaxY()) / 2.0)
+ };
+ Envelope.prototype.init = function init () {
+ if (arguments.length === 0) {
+ this.setToNull();
+ } else if (arguments.length === 1) {
+ if (arguments[0] instanceof Coordinate) {
+ var p = arguments[0];
+ this.init(p.x, p.x, p.y, p.y);
+ } else if (arguments[0] instanceof Envelope) {
+ var env = arguments[0];
+ this._minx = env._minx;
+ this._maxx = env._maxx;
+ this._miny = env._miny;
+ this._maxy = env._maxy;
+ }
+ } else if (arguments.length === 2) {
+ var p1 = arguments[0];
+ var p2 = arguments[1];
+ this.init(p1.x, p2.x, p1.y, p2.y);
+ } else if (arguments.length === 4) {
+ var x1 = arguments[0];
+ var x2 = arguments[1];
+ var y1 = arguments[2];
+ var y2 = arguments[3];
+ if (x1 < x2) {
+ this._minx = x1;
+ this._maxx = x2;
+ } else {
+ this._minx = x2;
+ this._maxx = x1;
+ }
+ if (y1 < y2) {
+ this._miny = y1;
+ this._maxy = y2;
+ } else {
+ this._miny = y2;
+ this._maxy = y1;
+ }
+ }
+ };
+ Envelope.prototype.getMaxY = function getMaxY () {
+ return this._maxy
+ };
+ Envelope.prototype.distance = function distance (env) {
+ if (this.intersects(env)) { return 0 }
+ var dx = 0.0;
+ if (this._maxx < env._minx) { dx = env._minx - this._maxx; } else if (this._minx > env._maxx) { dx = this._minx - env._maxx; }
+ var dy = 0.0;
+ if (this._maxy < env._miny) { dy = env._miny - this._maxy; } else if (this._miny > env._maxy) { dy = this._miny - env._maxy; }
+ if (dx === 0.0) { return dy }
+ if (dy === 0.0) { return dx }
+ return Math.sqrt(dx * dx + dy * dy)
+ };
+ Envelope.prototype.hashCode = function hashCode () {
+ var result = 17;
+ result = 37 * result + Coordinate.hashCode(this._minx);
+ result = 37 * result + Coordinate.hashCode(this._maxx);
+ result = 37 * result + Coordinate.hashCode(this._miny);
+ result = 37 * result + Coordinate.hashCode(this._maxy);
+ return result
+ };
+ Envelope.prototype.interfaces_ = function interfaces_ () {
+ return [Comparable, Serializable]
+ };
+ Envelope.prototype.getClass = function getClass () {
+ return Envelope
+ };
+ Envelope.intersects = function intersects () {
+ if (arguments.length === 3) {
+ var p1 = arguments[0];
+ var p2 = arguments[1];
+ var q = arguments[2];
+ if (q.x >= (p1.x < p2.x ? p1.x : p2.x) && q.x <= (p1.x > p2.x ? p1.x : p2.x) && (q.y >= (p1.y < p2.y ? p1.y : p2.y) && q.y <= (p1.y > p2.y ? p1.y : p2.y))) {
+ return true
+ }
+ return false
+ } else if (arguments.length === 4) {
+ var p1$1 = arguments[0];
+ var p2$1 = arguments[1];
+ var q1 = arguments[2];
+ var q2 = arguments[3];
+ var minq = Math.min(q1.x, q2.x);
+ var maxq = Math.max(q1.x, q2.x);
+ var minp = Math.min(p1$1.x, p2$1.x);
+ var maxp = Math.max(p1$1.x, p2$1.x);
+ if (minp > maxq) { return false }
+ if (maxp < minq) { return false }
+ minq = Math.min(q1.y, q2.y);
+ maxq = Math.max(q1.y, q2.y);
+ minp = Math.min(p1$1.y, p2$1.y);
+ maxp = Math.max(p1$1.y, p2$1.y);
+ if (minp > maxq) { return false }
+ if (maxp < minq) { return false }
+ return true
+ }
+ };
+ staticAccessors$9.serialVersionUID.get = function () { return 5873921885273102420 };
+
+ Object.defineProperties( Envelope, staticAccessors$9 );
+
+ var regExes = {
+ 'typeStr': /^\s*(\w+)\s*\(\s*(.*)\s*\)\s*$/,
+ 'emptyTypeStr': /^\s*(\w+)\s*EMPTY\s*$/,
+ 'spaces': /\s+/,
+ 'parenComma': /\)\s*,\s*\(/,
+ 'doubleParenComma': /\)\s*\)\s*,\s*\(\s*\(/, // can't use {2} here
+ 'trimParens': /^\s*\(?(.*?)\)?\s*$/
+ };
+
+ /**
+ * Class for reading and writing Well-Known Text.
+ *
+ * NOTE: Adapted from OpenLayers 2.11 implementation.
+ */
+
+ /** Create a new parser for WKT
+ *
+ * @param {GeometryFactory} geometryFactory
+ * @return An instance of WKTParser.
+ * @constructor
+ * @private
+ */
+ var WKTParser = function WKTParser (geometryFactory) {
+ this.geometryFactory = geometryFactory || new GeometryFactory();
+ };
+ /**
+ * Deserialize a WKT string and return a geometry. Supports WKT for POINT,
+ * MULTIPOINT, LINESTRING, LINEARRING, MULTILINESTRING, POLYGON, MULTIPOLYGON,
+ * and GEOMETRYCOLLECTION.
+ *
+ * @param {String} wkt A WKT string.
+ * @return {Geometry} A geometry instance.
+ * @private
+ */
+ WKTParser.prototype.read = function read (wkt) {
+ var geometry, type, str;
+ wkt = wkt.replace(/[\n\r]/g, ' ');
+ var matches = regExes.typeStr.exec(wkt);
+ if (wkt.search('EMPTY') !== -1) {
+ matches = regExes.emptyTypeStr.exec(wkt);
+ matches[2] = undefined;
+ }
+ if (matches) {
+ type = matches[1].toLowerCase();
+ str = matches[2];
+ if (parse$1[type]) {
+ geometry = parse$1[type].apply(this, [str]);
+ }
+ }
+
+ if (geometry === undefined) { throw new Error('Could not parse WKT ' + wkt) }
+
+ return geometry
+ };
+
+ /**
+ * Serialize a geometry into a WKT string.
+ *
+ * @param {Geometry} geometry A feature or array of features.
+ * @return {String} The WKT string representation of the input geometries.
+ * @private
+ */
+ WKTParser.prototype.write = function write (geometry) {
+ return this.extractGeometry(geometry)
+ };
+
+ /**
+ * Entry point to construct the WKT for a single Geometry object.
+ *
+ * @param {Geometry} geometry
+ * @return {String} A WKT string of representing the geometry.
+ * @private
+ */
+ WKTParser.prototype.extractGeometry = function extractGeometry (geometry) {
+ var type = geometry.getGeometryType().toLowerCase();
+ if (!extract$1[type]) {
+ return null
+ }
+ var wktType = type.toUpperCase();
+ var data;
+ if (geometry.isEmpty()) {
+ data = wktType + ' EMPTY';
+ } else {
+ data = wktType + '(' + extract$1[type].apply(this, [geometry]) + ')';
+ }
+ return data
+ };
+
+ /**
+ * Object with properties corresponding to the geometry types. Property values
+ * are functions that do the actual data extraction.
+ * @private
+ */
+ var extract$1 = {
+ coordinate: function coordinate (coordinate$1) {
+ return coordinate$1.x + ' ' + coordinate$1.y
+ },
+
+ /**
+ * Return a space delimited string of point coordinates.
+ *
+ * @param {Point}
+ * point
+ * @return {String} A string of coordinates representing the point.
+ */
+ point: function point (point$1) {
+ return extract$1.coordinate.call(this, point$1._coordinates._coordinates[0])
+ },
+
+ /**
+ * Return a comma delimited string of point coordinates from a multipoint.
+ *
+ * @param {MultiPoint}
+ * multipoint
+ * @return {String} A string of point coordinate strings representing the
+ * multipoint.
+ */
+ multipoint: function multipoint (multipoint$1) {
+ var this$1 = this;
+
+ var array = [];
+ for (var i = 0, len = multipoint$1._geometries.length; i < len; ++i) {
+ array.push('(' + extract$1.point.apply(this$1, [multipoint$1._geometries[i]]) + ')');
+ }
+ return array.join(',')
+ },
+
+ /**
+ * Return a comma delimited string of point coordinates from a line.
+ *
+ * @param {LineString} linestring
+ * @return {String} A string of point coordinate strings representing the linestring.
+ */
+ linestring: function linestring (linestring$1) {
+ var this$1 = this;
+
+ var array = [];
+ for (var i = 0, len = linestring$1._points._coordinates.length; i < len; ++i) {
+ array.push(extract$1.coordinate.apply(this$1, [linestring$1._points._coordinates[i]]));
+ }
+ return array.join(',')
+ },
+
+ linearring: function linearring (linearring$1) {
+ var this$1 = this;
+
+ var array = [];
+ for (var i = 0, len = linearring$1._points._coordinates.length; i < len; ++i) {
+ array.push(extract$1.coordinate.apply(this$1, [linearring$1._points._coordinates[i]]));
+ }
+ return array.join(',')
+ },
+
+ /**
+ * Return a comma delimited string of linestring strings from a
+ * multilinestring.
+ *
+ * @param {MultiLineString} multilinestring
+ * @return {String} A string of of linestring strings representing the multilinestring.
+ */
+ multilinestring: function multilinestring (multilinestring$1) {
+ var this$1 = this;
+
+ var array = [];
+ for (var i = 0, len = multilinestring$1._geometries.length; i < len; ++i) {
+ array.push('(' +
+ extract$1.linestring.apply(this$1, [multilinestring$1._geometries[i]]) +
+ ')');
+ }
+ return array.join(',')
+ },
+
+ /**
+ * Return a comma delimited string of linear ring arrays from a polygon.
+ *
+ * @param {Polygon} polygon
+ * @return {String} An array of linear ring arrays representing the polygon.
+ */
+ polygon: function polygon (polygon$1) {
+ var this$1 = this;
+
+ var array = [];
+ array.push('(' + extract$1.linestring.apply(this, [polygon$1._shell]) + ')');
+ for (var i = 0, len = polygon$1._holes.length; i < len; ++i) {
+ array.push('(' + extract$1.linestring.apply(this$1, [polygon$1._holes[i]]) + ')');
+ }
+ return array.join(',')
+ },
+
+ /**
+ * Return an array of polygon arrays from a multipolygon.
+ *
+ * @param {MultiPolygon} multipolygon
+ * @return {String} An array of polygon arrays representing the multipolygon.
+ */
+ multipolygon: function multipolygon (multipolygon$1) {
+ var this$1 = this;
+
+ var array = [];
+ for (var i = 0, len = multipolygon$1._geometries.length; i < len; ++i) {
+ array.push('(' + extract$1.polygon.apply(this$1, [multipolygon$1._geometries[i]]) + ')');
+ }
+ return array.join(',')
+ },
+
+ /**
+ * Return the WKT portion between 'GEOMETRYCOLLECTION(' and ')' for an
+ * geometrycollection.
+ *
+ * @param {GeometryCollection} collection
+ * @return {String} internal WKT representation of the collection.
+ */
+ geometrycollection: function geometrycollection (collection) {
+ var this$1 = this;
+
+ var array = [];
+ for (var i = 0, len = collection._geometries.length; i < len; ++i) {
+ array.push(this$1.extractGeometry(collection._geometries[i]));
+ }
+ return array.join(',')
+ }
+ };
+
+ /**
+ * Object with properties corresponding to the geometry types. Property values
+ * are functions that do the actual parsing.
+ * @private
+ */
+ var parse$1 = {
+ /**
+ * Return point geometry given a point WKT fragment.
+ *
+ * @param {String} str A WKT fragment representing the point.
+ * @return {Point} A point geometry.
+ * @private
+ */
+ point: function point (str) {
+ if (str === undefined) {
+ return this.geometryFactory.createPoint()
+ }
+
+ var coords = str.trim().split(regExes.spaces);
+ return this.geometryFactory.createPoint(new Coordinate(Number.parseFloat(coords[0]),
+ Number.parseFloat(coords[1])))
+ },
+
+ /**
+ * Return a multipoint geometry given a multipoint WKT fragment.
+ *
+ * @param {String} str A WKT fragment representing the multipoint.
+ * @return {Point} A multipoint feature.
+ * @private
+ */
+ multipoint: function multipoint (str) {
+ var this$1 = this;
+
+ if (str === undefined) {
+ return this.geometryFactory.createMultiPoint()
+ }
+
+ var point;
+ var points = str.trim().split(',');
+ var components = [];
+ for (var i = 0, len = points.length; i < len; ++i) {
+ point = points[i].replace(regExes.trimParens, '$1');
+ components.push(parse$1.point.apply(this$1, [point]));
+ }
+ return this.geometryFactory.createMultiPoint(components)
+ },
+
+ /**
+ * Return a linestring geometry given a linestring WKT fragment.
+ *
+ * @param {String} str A WKT fragment representing the linestring.
+ * @return {LineString} A linestring geometry.
+ * @private
+ */
+ linestring: function linestring (str) {
+ if (str === undefined) {
+ return this.geometryFactory.createLineString()
+ }
+
+ var points = str.trim().split(',');
+ var components = [];
+ var coords;
+ for (var i = 0, len = points.length; i < len; ++i) {
+ coords = points[i].trim().split(regExes.spaces);
+ components.push(new Coordinate(Number.parseFloat(coords[0]), Number.parseFloat(coords[1])));
+ }
+ return this.geometryFactory.createLineString(components)
+ },
+
+ /**
+ * Return a linearring geometry given a linearring WKT fragment.
+ *
+ * @param {String} str A WKT fragment representing the linearring.
+ * @return {LinearRing} A linearring geometry.
+ * @private
+ */
+ linearring: function linearring (str) {
+ if (str === undefined) {
+ return this.geometryFactory.createLinearRing()
+ }
+
+ var points = str.trim().split(',');
+ var components = [];
+ var coords;
+ for (var i = 0, len = points.length; i < len; ++i) {
+ coords = points[i].trim().split(regExes.spaces);
+ components.push(new Coordinate(Number.parseFloat(coords[0]), Number.parseFloat(coords[1])));
+ }
+ return this.geometryFactory.createLinearRing(components)
+ },
+
+ /**
+ * Return a multilinestring geometry given a multilinestring WKT fragment.
+ *
+ * @param {String} str A WKT fragment representing the multilinestring.
+ * @return {MultiLineString} A multilinestring geometry.
+ * @private
+ */
+ multilinestring: function multilinestring (str) {
+ var this$1 = this;
+
+ if (str === undefined) {
+ return this.geometryFactory.createMultiLineString()
+ }
+
+ var line;
+ var lines = str.trim().split(regExes.parenComma);
+ var components = [];
+ for (var i = 0, len = lines.length; i < len; ++i) {
+ line = lines[i].replace(regExes.trimParens, '$1');
+ components.push(parse$1.linestring.apply(this$1, [line]));
+ }
+ return this.geometryFactory.createMultiLineString(components)
+ },
+
+ /**
+ * Return a polygon geometry given a polygon WKT fragment.
+ *
+ * @param {String} str A WKT fragment representing the polygon.
+ * @return {Polygon} A polygon geometry.
+ * @private
+ */
+ polygon: function polygon (str) {
+ var this$1 = this;
+
+ if (str === undefined) {
+ return this.geometryFactory.createPolygon()
+ }
+
+ var ring, linestring, linearring;
+ var rings = str.trim().split(regExes.parenComma);
+ var shell;
+ var holes = [];
+ for (var i = 0, len = rings.length; i < len; ++i) {
+ ring = rings[i].replace(regExes.trimParens, '$1');
+ linestring = parse$1.linestring.apply(this$1, [ring]);
+ linearring = this$1.geometryFactory.createLinearRing(linestring._points);
+ if (i === 0) {
+ shell = linearring;
+ } else {
+ holes.push(linearring);
+ }
+ }
+ return this.geometryFactory.createPolygon(shell, holes)
+ },
+
+ /**
+ * Return a multipolygon geometry given a multipolygon WKT fragment.
+ *
+ * @param {String} str A WKT fragment representing the multipolygon.
+ * @return {MultiPolygon} A multipolygon geometry.
+ * @private
+ */
+ multipolygon: function multipolygon (str) {
+ var this$1 = this;
+
+ if (str === undefined) {
+ return this.geometryFactory.createMultiPolygon()
+ }
+
+ var polygon;
+ var polygons = str.trim().split(regExes.doubleParenComma);
+ var components = [];
+ for (var i = 0, len = polygons.length; i < len; ++i) {
+ polygon = polygons[i].replace(regExes.trimParens, '$1');
+ components.push(parse$1.polygon.apply(this$1, [polygon]));
+ }
+ return this.geometryFactory.createMultiPolygon(components)
+ },
+
+ /**
+ * Return a geometrycollection given a geometrycollection WKT fragment.
+ *
+ * @param {String} str A WKT fragment representing the geometrycollection.
+ * @return {GeometryCollection}
+ * @private
+ */
+ geometrycollection: function geometrycollection (str) {
+ var this$1 = this;
+
+ if (str === undefined) {
+ return this.geometryFactory.createGeometryCollection()
+ }
+
+ // separate components of the collection with |
+ str = str.replace(/,\s*([A-Za-z])/g, '|$1');
+ var wktArray = str.trim().split('|');
+ var components = [];
+ for (var i = 0, len = wktArray.length; i < len; ++i) {
+ components.push(this$1.read(wktArray[i]));
+ }
+ return this.geometryFactory.createGeometryCollection(components)
+ }
+ };
+
+ /**
+ * Writes the Well-Known Text representation of a {@link Geometry}. The
+ * Well-Known Text format is defined in the OGC Simple Features
+ * Specification for SQL .
+ *
+ * The WKTWriter
outputs coordinates rounded to the precision
+ * model. Only the maximum number of decimal places necessary to represent the
+ * ordinates to the required precision will be output.
+ *
+ * The SFS WKT spec does not define a special tag for {@link LinearRing}s.
+ * Under the spec, rings are output as LINESTRING
s.
+ */
+
+ /**
+ * @param {GeometryFactory} geometryFactory
+ * @constructor
+ */
+ var WKTWriter = function WKTWriter (geometryFactory) {
+ this.parser = new WKTParser(geometryFactory);
+ };
+
+ /**
+ * Converts a Geometry
to its Well-known Text representation.
+ *
+ * @param {Geometry} geometry a Geometry
to process.
+ * @return {string} a string (see the OpenGIS Simple
+ * Features Specification).
+ * @memberof WKTWriter
+ */
+ WKTWriter.prototype.write = function write (geometry) {
+ return this.parser.write(geometry)
+ };
+ /**
+ * Generates the WKT for a LINESTRING specified by two
+ * {@link Coordinate}s.
+ *
+ * @param p0 the first coordinate.
+ * @param p1 the second coordinate.
+ *
+ * @return the WKT.
+ * @private
+ */
+ WKTWriter.toLineString = function toLineString (p0, p1) {
+ if (arguments.length !== 2) {
+ throw new Error('Not implemented')
+ }
+ return 'LINESTRING ( ' + p0.x + ' ' + p0.y + ', ' + p1.x + ' ' + p1.y + ' )'
+ };
+
+ var RuntimeException = (function (Error) {
+ function RuntimeException (message) {
+ Error.call(this, message);
+ this.name = 'RuntimeException';
+ this.message = message;
+ this.stack = (new Error()).stack;
+ }
+
+ if ( Error ) RuntimeException.__proto__ = Error;
+ RuntimeException.prototype = Object.create( Error && Error.prototype );
+ RuntimeException.prototype.constructor = RuntimeException;
+
+ return RuntimeException;
+ }(Error));
+
+ var AssertionFailedException = (function (RuntimeException$$1) {
+ function AssertionFailedException () {
+ RuntimeException$$1.call(this);
+ if (arguments.length === 0) {
+ RuntimeException$$1.call(this);
+ } else if (arguments.length === 1) {
+ var message = arguments[0];
+ RuntimeException$$1.call(this, message);
+ }
+ }
+
+ if ( RuntimeException$$1 ) AssertionFailedException.__proto__ = RuntimeException$$1;
+ AssertionFailedException.prototype = Object.create( RuntimeException$$1 && RuntimeException$$1.prototype );
+ AssertionFailedException.prototype.constructor = AssertionFailedException;
+ AssertionFailedException.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ AssertionFailedException.prototype.getClass = function getClass () {
+ return AssertionFailedException
+ };
+
+ return AssertionFailedException;
+ }(RuntimeException));
+
+ var Assert = function Assert () {};
+
+ Assert.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ Assert.prototype.getClass = function getClass () {
+ return Assert
+ };
+ Assert.shouldNeverReachHere = function shouldNeverReachHere () {
+ if (arguments.length === 0) {
+ Assert.shouldNeverReachHere(null);
+ } else if (arguments.length === 1) {
+ var message = arguments[0];
+ throw new AssertionFailedException('Should never reach here' + (message !== null ? ': ' + message : ''))
+ }
+ };
+ Assert.isTrue = function isTrue () {
+ var assertion;
+ var message;
+ if (arguments.length === 1) {
+ assertion = arguments[0];
+ Assert.isTrue(assertion, null);
+ } else if (arguments.length === 2) {
+ assertion = arguments[0];
+ message = arguments[1];
+ if (!assertion) {
+ if (message === null) {
+ throw new AssertionFailedException()
+ } else {
+ throw new AssertionFailedException(message)
+ }
+ }
+ }
+ };
+ Assert.equals = function equals () {
+ var expectedValue;
+ var actualValue;
+ var message;
+ if (arguments.length === 2) {
+ expectedValue = arguments[0];
+ actualValue = arguments[1];
+ Assert.equals(expectedValue, actualValue, null);
+ } else if (arguments.length === 3) {
+ expectedValue = arguments[0];
+ actualValue = arguments[1];
+ message = arguments[2];
+ if (!actualValue.equals(expectedValue)) {
+ throw new AssertionFailedException('Expected ' + expectedValue + ' but encountered ' + actualValue + (message !== null ? ': ' + message : ''))
+ }
+ }
+ };
+
+ var LineIntersector = function LineIntersector () {
+ this._result = null;
+ this._inputLines = Array(2).fill().map(function () { return Array(2); });
+ this._intPt = new Array(2).fill(null);
+ this._intLineIndex = null;
+ this._isProper = null;
+ this._pa = null;
+ this._pb = null;
+ this._precisionModel = null;
+ this._intPt[0] = new Coordinate();
+ this._intPt[1] = new Coordinate();
+ this._pa = this._intPt[0];
+ this._pb = this._intPt[1];
+ this._result = 0;
+ };
+
+ var staticAccessors$10 = { DONT_INTERSECT: { configurable: true },DO_INTERSECT: { configurable: true },COLLINEAR: { configurable: true },NO_INTERSECTION: { configurable: true },POINT_INTERSECTION: { configurable: true },COLLINEAR_INTERSECTION: { configurable: true } };
+ LineIntersector.prototype.getIndexAlongSegment = function getIndexAlongSegment (segmentIndex, intIndex) {
+ this.computeIntLineIndex();
+ return this._intLineIndex[segmentIndex][intIndex]
+ };
+ LineIntersector.prototype.getTopologySummary = function getTopologySummary () {
+ var catBuf = new StringBuffer();
+ if (this.isEndPoint()) { catBuf.append(' endpoint'); }
+ if (this._isProper) { catBuf.append(' proper'); }
+ if (this.isCollinear()) { catBuf.append(' collinear'); }
+ return catBuf.toString()
+ };
+ LineIntersector.prototype.computeIntersection = function computeIntersection (p1, p2, p3, p4) {
+ this._inputLines[0][0] = p1;
+ this._inputLines[0][1] = p2;
+ this._inputLines[1][0] = p3;
+ this._inputLines[1][1] = p4;
+ this._result = this.computeIntersect(p1, p2, p3, p4);
+ };
+ LineIntersector.prototype.getIntersectionNum = function getIntersectionNum () {
+ return this._result
+ };
+ LineIntersector.prototype.computeIntLineIndex = function computeIntLineIndex () {
+ if (arguments.length === 0) {
+ if (this._intLineIndex === null) {
+ this._intLineIndex = Array(2).fill().map(function () { return Array(2); });
+ this.computeIntLineIndex(0);
+ this.computeIntLineIndex(1);
+ }
+ } else if (arguments.length === 1) {
+ var segmentIndex = arguments[0];
+ var dist0 = this.getEdgeDistance(segmentIndex, 0);
+ var dist1 = this.getEdgeDistance(segmentIndex, 1);
+ if (dist0 > dist1) {
+ this._intLineIndex[segmentIndex][0] = 0;
+ this._intLineIndex[segmentIndex][1] = 1;
+ } else {
+ this._intLineIndex[segmentIndex][0] = 1;
+ this._intLineIndex[segmentIndex][1] = 0;
+ }
+ }
+ };
+ LineIntersector.prototype.isProper = function isProper () {
+ return this.hasIntersection() && this._isProper
+ };
+ LineIntersector.prototype.setPrecisionModel = function setPrecisionModel (precisionModel) {
+ this._precisionModel = precisionModel;
+ };
+ LineIntersector.prototype.isInteriorIntersection = function isInteriorIntersection () {
+ var this$1 = this;
+
+ if (arguments.length === 0) {
+ if (this.isInteriorIntersection(0)) { return true }
+ if (this.isInteriorIntersection(1)) { return true }
+ return false
+ } else if (arguments.length === 1) {
+ var inputLineIndex = arguments[0];
+ for (var i = 0; i < this._result; i++) {
+ if (!(this$1._intPt[i].equals2D(this$1._inputLines[inputLineIndex][0]) || this$1._intPt[i].equals2D(this$1._inputLines[inputLineIndex][1]))) {
+ return true
+ }
+ }
+ return false
+ }
+ };
+ LineIntersector.prototype.getIntersection = function getIntersection (intIndex) {
+ return this._intPt[intIndex]
+ };
+ LineIntersector.prototype.isEndPoint = function isEndPoint () {
+ return this.hasIntersection() && !this._isProper
+ };
+ LineIntersector.prototype.hasIntersection = function hasIntersection () {
+ return this._result !== LineIntersector.NO_INTERSECTION
+ };
+ LineIntersector.prototype.getEdgeDistance = function getEdgeDistance (segmentIndex, intIndex) {
+ var dist = LineIntersector.computeEdgeDistance(this._intPt[intIndex], this._inputLines[segmentIndex][0], this._inputLines[segmentIndex][1]);
+ return dist
+ };
+ LineIntersector.prototype.isCollinear = function isCollinear () {
+ return this._result === LineIntersector.COLLINEAR_INTERSECTION
+ };
+ LineIntersector.prototype.toString = function toString () {
+ return WKTWriter.toLineString(this._inputLines[0][0], this._inputLines[0][1]) + ' - ' + WKTWriter.toLineString(this._inputLines[1][0], this._inputLines[1][1]) + this.getTopologySummary()
+ };
+ LineIntersector.prototype.getEndpoint = function getEndpoint (segmentIndex, ptIndex) {
+ return this._inputLines[segmentIndex][ptIndex]
+ };
+ LineIntersector.prototype.isIntersection = function isIntersection (pt) {
+ var this$1 = this;
+
+ for (var i = 0; i < this._result; i++) {
+ if (this$1._intPt[i].equals2D(pt)) {
+ return true
+ }
+ }
+ return false
+ };
+ LineIntersector.prototype.getIntersectionAlongSegment = function getIntersectionAlongSegment (segmentIndex, intIndex) {
+ this.computeIntLineIndex();
+ return this._intPt[this._intLineIndex[segmentIndex][intIndex]]
+ };
+ LineIntersector.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ LineIntersector.prototype.getClass = function getClass () {
+ return LineIntersector
+ };
+ LineIntersector.computeEdgeDistance = function computeEdgeDistance (p, p0, p1) {
+ var dx = Math.abs(p1.x - p0.x);
+ var dy = Math.abs(p1.y - p0.y);
+ var dist = -1.0;
+ if (p.equals(p0)) {
+ dist = 0.0;
+ } else if (p.equals(p1)) {
+ if (dx > dy) { dist = dx; } else { dist = dy; }
+ } else {
+ var pdx = Math.abs(p.x - p0.x);
+ var pdy = Math.abs(p.y - p0.y);
+ if (dx > dy) { dist = pdx; } else { dist = pdy; }
+ if (dist === 0.0 && !p.equals(p0)) {
+ dist = Math.max(pdx, pdy);
+ }
+ }
+ Assert.isTrue(!(dist === 0.0 && !p.equals(p0)), 'Bad distance calculation');
+ return dist
+ };
+ LineIntersector.nonRobustComputeEdgeDistance = function nonRobustComputeEdgeDistance (p, p1, p2) {
+ var dx = p.x - p1.x;
+ var dy = p.y - p1.y;
+ var dist = Math.sqrt(dx * dx + dy * dy);
+ Assert.isTrue(!(dist === 0.0 && !p.equals(p1)), 'Invalid distance calculation');
+ return dist
+ };
+ staticAccessors$10.DONT_INTERSECT.get = function () { return 0 };
+ staticAccessors$10.DO_INTERSECT.get = function () { return 1 };
+ staticAccessors$10.COLLINEAR.get = function () { return 2 };
+ staticAccessors$10.NO_INTERSECTION.get = function () { return 0 };
+ staticAccessors$10.POINT_INTERSECTION.get = function () { return 1 };
+ staticAccessors$10.COLLINEAR_INTERSECTION.get = function () { return 2 };
+
+ Object.defineProperties( LineIntersector, staticAccessors$10 );
+
+ var RobustLineIntersector = (function (LineIntersector$$1) {
+ function RobustLineIntersector () {
+ LineIntersector$$1.apply(this, arguments);
+ }
+
+ if ( LineIntersector$$1 ) RobustLineIntersector.__proto__ = LineIntersector$$1;
+ RobustLineIntersector.prototype = Object.create( LineIntersector$$1 && LineIntersector$$1.prototype );
+ RobustLineIntersector.prototype.constructor = RobustLineIntersector;
+
+ RobustLineIntersector.prototype.isInSegmentEnvelopes = function isInSegmentEnvelopes (intPt) {
+ var env0 = new Envelope(this._inputLines[0][0], this._inputLines[0][1]);
+ var env1 = new Envelope(this._inputLines[1][0], this._inputLines[1][1]);
+ return env0.contains(intPt) && env1.contains(intPt)
+ };
+ RobustLineIntersector.prototype.computeIntersection = function computeIntersection () {
+ if (arguments.length === 3) {
+ var p = arguments[0];
+ var p1 = arguments[1];
+ var p2 = arguments[2];
+ this._isProper = false;
+ if (Envelope.intersects(p1, p2, p)) {
+ if (CGAlgorithms.orientationIndex(p1, p2, p) === 0 && CGAlgorithms.orientationIndex(p2, p1, p) === 0) {
+ this._isProper = true;
+ if (p.equals(p1) || p.equals(p2)) {
+ this._isProper = false;
+ }
+ this._result = LineIntersector$$1.POINT_INTERSECTION;
+ return null
+ }
+ }
+ this._result = LineIntersector$$1.NO_INTERSECTION;
+ } else { return LineIntersector$$1.prototype.computeIntersection.apply(this, arguments) }
+ };
+ RobustLineIntersector.prototype.normalizeToMinimum = function normalizeToMinimum (n1, n2, n3, n4, normPt) {
+ normPt.x = this.smallestInAbsValue(n1.x, n2.x, n3.x, n4.x);
+ normPt.y = this.smallestInAbsValue(n1.y, n2.y, n3.y, n4.y);
+ n1.x -= normPt.x;
+ n1.y -= normPt.y;
+ n2.x -= normPt.x;
+ n2.y -= normPt.y;
+ n3.x -= normPt.x;
+ n3.y -= normPt.y;
+ n4.x -= normPt.x;
+ n4.y -= normPt.y;
+ };
+ RobustLineIntersector.prototype.safeHCoordinateIntersection = function safeHCoordinateIntersection (p1, p2, q1, q2) {
+ var intPt = null;
+ try {
+ intPt = HCoordinate.intersection(p1, p2, q1, q2);
+ } catch (e) {
+ if (e instanceof NotRepresentableException) {
+ intPt = RobustLineIntersector.nearestEndpoint(p1, p2, q1, q2);
+ } else { throw e }
+ } finally {}
+ return intPt
+ };
+ RobustLineIntersector.prototype.intersection = function intersection (p1, p2, q1, q2) {
+ var intPt = this.intersectionWithNormalization(p1, p2, q1, q2);
+ if (!this.isInSegmentEnvelopes(intPt)) {
+ intPt = new Coordinate(RobustLineIntersector.nearestEndpoint(p1, p2, q1, q2));
+ }
+ if (this._precisionModel !== null) {
+ this._precisionModel.makePrecise(intPt);
+ }
+ return intPt
+ };
+ RobustLineIntersector.prototype.smallestInAbsValue = function smallestInAbsValue (x1, x2, x3, x4) {
+ var x = x1;
+ var xabs = Math.abs(x);
+ if (Math.abs(x2) < xabs) {
+ x = x2;
+ xabs = Math.abs(x2);
+ }
+ if (Math.abs(x3) < xabs) {
+ x = x3;
+ xabs = Math.abs(x3);
+ }
+ if (Math.abs(x4) < xabs) {
+ x = x4;
+ }
+ return x
+ };
+ RobustLineIntersector.prototype.checkDD = function checkDD (p1, p2, q1, q2, intPt) {
+ var intPtDD = CGAlgorithmsDD.intersection(p1, p2, q1, q2);
+ var isIn = this.isInSegmentEnvelopes(intPtDD);
+ System.out.println('DD in env = ' + isIn + ' --------------------- ' + intPtDD);
+ if (intPt.distance(intPtDD) > 0.0001) {
+ System.out.println('Distance = ' + intPt.distance(intPtDD));
+ }
+ };
+ RobustLineIntersector.prototype.intersectionWithNormalization = function intersectionWithNormalization (p1, p2, q1, q2) {
+ var n1 = new Coordinate(p1);
+ var n2 = new Coordinate(p2);
+ var n3 = new Coordinate(q1);
+ var n4 = new Coordinate(q2);
+ var normPt = new Coordinate();
+ this.normalizeToEnvCentre(n1, n2, n3, n4, normPt);
+ var intPt = this.safeHCoordinateIntersection(n1, n2, n3, n4);
+ intPt.x += normPt.x;
+ intPt.y += normPt.y;
+ return intPt
+ };
+ RobustLineIntersector.prototype.computeCollinearIntersection = function computeCollinearIntersection (p1, p2, q1, q2) {
+ var p1q1p2 = Envelope.intersects(p1, p2, q1);
+ var p1q2p2 = Envelope.intersects(p1, p2, q2);
+ var q1p1q2 = Envelope.intersects(q1, q2, p1);
+ var q1p2q2 = Envelope.intersects(q1, q2, p2);
+ if (p1q1p2 && p1q2p2) {
+ this._intPt[0] = q1;
+ this._intPt[1] = q2;
+ return LineIntersector$$1.COLLINEAR_INTERSECTION
+ }
+ if (q1p1q2 && q1p2q2) {
+ this._intPt[0] = p1;
+ this._intPt[1] = p2;
+ return LineIntersector$$1.COLLINEAR_INTERSECTION
+ }
+ if (p1q1p2 && q1p1q2) {
+ this._intPt[0] = q1;
+ this._intPt[1] = p1;
+ return q1.equals(p1) && !p1q2p2 && !q1p2q2 ? LineIntersector$$1.POINT_INTERSECTION : LineIntersector$$1.COLLINEAR_INTERSECTION
+ }
+ if (p1q1p2 && q1p2q2) {
+ this._intPt[0] = q1;
+ this._intPt[1] = p2;
+ return q1.equals(p2) && !p1q2p2 && !q1p1q2 ? LineIntersector$$1.POINT_INTERSECTION : LineIntersector$$1.COLLINEAR_INTERSECTION
+ }
+ if (p1q2p2 && q1p1q2) {
+ this._intPt[0] = q2;
+ this._intPt[1] = p1;
+ return q2.equals(p1) && !p1q1p2 && !q1p2q2 ? LineIntersector$$1.POINT_INTERSECTION : LineIntersector$$1.COLLINEAR_INTERSECTION
+ }
+ if (p1q2p2 && q1p2q2) {
+ this._intPt[0] = q2;
+ this._intPt[1] = p2;
+ return q2.equals(p2) && !p1q1p2 && !q1p1q2 ? LineIntersector$$1.POINT_INTERSECTION : LineIntersector$$1.COLLINEAR_INTERSECTION
+ }
+ return LineIntersector$$1.NO_INTERSECTION
+ };
+ RobustLineIntersector.prototype.normalizeToEnvCentre = function normalizeToEnvCentre (n00, n01, n10, n11, normPt) {
+ var minX0 = n00.x < n01.x ? n00.x : n01.x;
+ var minY0 = n00.y < n01.y ? n00.y : n01.y;
+ var maxX0 = n00.x > n01.x ? n00.x : n01.x;
+ var maxY0 = n00.y > n01.y ? n00.y : n01.y;
+ var minX1 = n10.x < n11.x ? n10.x : n11.x;
+ var minY1 = n10.y < n11.y ? n10.y : n11.y;
+ var maxX1 = n10.x > n11.x ? n10.x : n11.x;
+ var maxY1 = n10.y > n11.y ? n10.y : n11.y;
+ var intMinX = minX0 > minX1 ? minX0 : minX1;
+ var intMaxX = maxX0 < maxX1 ? maxX0 : maxX1;
+ var intMinY = minY0 > minY1 ? minY0 : minY1;
+ var intMaxY = maxY0 < maxY1 ? maxY0 : maxY1;
+ var intMidX = (intMinX + intMaxX) / 2.0;
+ var intMidY = (intMinY + intMaxY) / 2.0;
+ normPt.x = intMidX;
+ normPt.y = intMidY;
+ n00.x -= normPt.x;
+ n00.y -= normPt.y;
+ n01.x -= normPt.x;
+ n01.y -= normPt.y;
+ n10.x -= normPt.x;
+ n10.y -= normPt.y;
+ n11.x -= normPt.x;
+ n11.y -= normPt.y;
+ };
+ RobustLineIntersector.prototype.computeIntersect = function computeIntersect (p1, p2, q1, q2) {
+ this._isProper = false;
+ if (!Envelope.intersects(p1, p2, q1, q2)) { return LineIntersector$$1.NO_INTERSECTION }
+ var Pq1 = CGAlgorithms.orientationIndex(p1, p2, q1);
+ var Pq2 = CGAlgorithms.orientationIndex(p1, p2, q2);
+ if ((Pq1 > 0 && Pq2 > 0) || (Pq1 < 0 && Pq2 < 0)) {
+ return LineIntersector$$1.NO_INTERSECTION
+ }
+ var Qp1 = CGAlgorithms.orientationIndex(q1, q2, p1);
+ var Qp2 = CGAlgorithms.orientationIndex(q1, q2, p2);
+ if ((Qp1 > 0 && Qp2 > 0) || (Qp1 < 0 && Qp2 < 0)) {
+ return LineIntersector$$1.NO_INTERSECTION
+ }
+ var collinear = Pq1 === 0 && Pq2 === 0 && Qp1 === 0 && Qp2 === 0;
+ if (collinear) {
+ return this.computeCollinearIntersection(p1, p2, q1, q2)
+ }
+ if (Pq1 === 0 || Pq2 === 0 || Qp1 === 0 || Qp2 === 0) {
+ this._isProper = false;
+ if (p1.equals2D(q1) || p1.equals2D(q2)) {
+ this._intPt[0] = p1;
+ } else if (p2.equals2D(q1) || p2.equals2D(q2)) {
+ this._intPt[0] = p2;
+ } else if (Pq1 === 0) {
+ this._intPt[0] = new Coordinate(q1);
+ } else if (Pq2 === 0) {
+ this._intPt[0] = new Coordinate(q2);
+ } else if (Qp1 === 0) {
+ this._intPt[0] = new Coordinate(p1);
+ } else if (Qp2 === 0) {
+ this._intPt[0] = new Coordinate(p2);
+ }
+ } else {
+ this._isProper = true;
+ this._intPt[0] = this.intersection(p1, p2, q1, q2);
+ }
+ return LineIntersector$$1.POINT_INTERSECTION
+ };
+ RobustLineIntersector.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ RobustLineIntersector.prototype.getClass = function getClass () {
+ return RobustLineIntersector
+ };
+ RobustLineIntersector.nearestEndpoint = function nearestEndpoint (p1, p2, q1, q2) {
+ var nearestPt = p1;
+ var minDist = CGAlgorithms.distancePointLine(p1, q1, q2);
+ var dist = CGAlgorithms.distancePointLine(p2, q1, q2);
+ if (dist < minDist) {
+ minDist = dist;
+ nearestPt = p2;
+ }
+ dist = CGAlgorithms.distancePointLine(q1, p1, p2);
+ if (dist < minDist) {
+ minDist = dist;
+ nearestPt = q1;
+ }
+ dist = CGAlgorithms.distancePointLine(q2, p1, p2);
+ if (dist < minDist) {
+ minDist = dist;
+ nearestPt = q2;
+ }
+ return nearestPt
+ };
+
+ return RobustLineIntersector;
+ }(LineIntersector));
+
+ var RobustDeterminant = function RobustDeterminant () {};
+
+ RobustDeterminant.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ RobustDeterminant.prototype.getClass = function getClass () {
+ return RobustDeterminant
+ };
+ RobustDeterminant.orientationIndex = function orientationIndex (p1, p2, q) {
+ var dx1 = p2.x - p1.x;
+ var dy1 = p2.y - p1.y;
+ var dx2 = q.x - p2.x;
+ var dy2 = q.y - p2.y;
+ return RobustDeterminant.signOfDet2x2(dx1, dy1, dx2, dy2)
+ };
+ RobustDeterminant.signOfDet2x2 = function signOfDet2x2 (x1, y1, x2, y2) {
+ var sign = null;
+ var swap = null;
+ var k = null;
+ sign = 1;
+ if (x1 === 0.0 || y2 === 0.0) {
+ if (y1 === 0.0 || x2 === 0.0) {
+ return 0
+ } else if (y1 > 0) {
+ if (x2 > 0) {
+ return -sign
+ } else {
+ return sign
+ }
+ } else {
+ if (x2 > 0) {
+ return sign
+ } else {
+ return -sign
+ }
+ }
+ }
+ if (y1 === 0.0 || x2 === 0.0) {
+ if (y2 > 0) {
+ if (x1 > 0) {
+ return sign
+ } else {
+ return -sign
+ }
+ } else {
+ if (x1 > 0) {
+ return -sign
+ } else {
+ return sign
+ }
+ }
+ }
+ if (y1 > 0.0) {
+ if (y2 > 0.0) {
+ if (y1 <= y2) ; else {
+ sign = -sign;
+ swap = x1;
+ x1 = x2;
+ x2 = swap;
+ swap = y1;
+ y1 = y2;
+ y2 = swap;
+ }
+ } else {
+ if (y1 <= -y2) {
+ sign = -sign;
+ x2 = -x2;
+ y2 = -y2;
+ } else {
+ swap = x1;
+ x1 = -x2;
+ x2 = swap;
+ swap = y1;
+ y1 = -y2;
+ y2 = swap;
+ }
+ }
+ } else {
+ if (y2 > 0.0) {
+ if (-y1 <= y2) {
+ sign = -sign;
+ x1 = -x1;
+ y1 = -y1;
+ } else {
+ swap = -x1;
+ x1 = x2;
+ x2 = swap;
+ swap = -y1;
+ y1 = y2;
+ y2 = swap;
+ }
+ } else {
+ if (y1 >= y2) {
+ x1 = -x1;
+ y1 = -y1;
+ x2 = -x2;
+ y2 = -y2;
+ } else {
+ sign = -sign;
+ swap = -x1;
+ x1 = -x2;
+ x2 = swap;
+ swap = -y1;
+ y1 = -y2;
+ y2 = swap;
+ }
+ }
+ }
+ if (x1 > 0.0) {
+ if (x2 > 0.0) {
+ if (x1 <= x2) ; else {
+ return sign
+ }
+ } else {
+ return sign
+ }
+ } else {
+ if (x2 > 0.0) {
+ return -sign
+ } else {
+ if (x1 >= x2) {
+ sign = -sign;
+ x1 = -x1;
+ x2 = -x2;
+ } else {
+ return -sign
+ }
+ }
+ }
+ while (true) {
+ k = Math.floor(x2 / x1);
+ x2 = x2 - k * x1;
+ y2 = y2 - k * y1;
+ if (y2 < 0.0) {
+ return -sign
+ }
+ if (y2 > y1) {
+ return sign
+ }
+ if (x1 > x2 + x2) {
+ if (y1 < y2 + y2) {
+ return sign
+ }
+ } else {
+ if (y1 > y2 + y2) {
+ return -sign
+ } else {
+ x2 = x1 - x2;
+ y2 = y1 - y2;
+ sign = -sign;
+ }
+ }
+ if (y2 === 0.0) {
+ if (x2 === 0.0) {
+ return 0
+ } else {
+ return -sign
+ }
+ }
+ if (x2 === 0.0) {
+ return sign
+ }
+ k = Math.floor(x1 / x2);
+ x1 = x1 - k * x2;
+ y1 = y1 - k * y2;
+ if (y1 < 0.0) {
+ return sign
+ }
+ if (y1 > y2) {
+ return -sign
+ }
+ if (x2 > x1 + x1) {
+ if (y2 < y1 + y1) {
+ return -sign
+ }
+ } else {
+ if (y2 > y1 + y1) {
+ return sign
+ } else {
+ x1 = x2 - x1;
+ y1 = y2 - y1;
+ sign = -sign;
+ }
+ }
+ if (y1 === 0.0) {
+ if (x1 === 0.0) {
+ return 0
+ } else {
+ return sign
+ }
+ }
+ if (x1 === 0.0) {
+ return -sign
+ }
+ }
+ };
+
+ var RayCrossingCounter = function RayCrossingCounter () {
+ this._p = null;
+ this._crossingCount = 0;
+ this._isPointOnSegment = false;
+ var p = arguments[0];
+ this._p = p;
+ };
+ RayCrossingCounter.prototype.countSegment = function countSegment (p1, p2) {
+ if (p1.x < this._p.x && p2.x < this._p.x) { return null }
+ if (this._p.x === p2.x && this._p.y === p2.y) {
+ this._isPointOnSegment = true;
+ return null
+ }
+ if (p1.y === this._p.y && p2.y === this._p.y) {
+ var minx = p1.x;
+ var maxx = p2.x;
+ if (minx > maxx) {
+ minx = p2.x;
+ maxx = p1.x;
+ }
+ if (this._p.x >= minx && this._p.x <= maxx) {
+ this._isPointOnSegment = true;
+ }
+ return null
+ }
+ if ((p1.y > this._p.y && p2.y <= this._p.y) || (p2.y > this._p.y && p1.y <= this._p.y)) {
+ var x1 = p1.x - this._p.x;
+ var y1 = p1.y - this._p.y;
+ var x2 = p2.x - this._p.x;
+ var y2 = p2.y - this._p.y;
+ var xIntSign = RobustDeterminant.signOfDet2x2(x1, y1, x2, y2);
+ if (xIntSign === 0.0) {
+ this._isPointOnSegment = true;
+ return null
+ }
+ if (y2 < y1) { xIntSign = -xIntSign; }
+ if (xIntSign > 0.0) {
+ this._crossingCount++;
+ }
+ }
+ };
+ RayCrossingCounter.prototype.isPointInPolygon = function isPointInPolygon () {
+ return this.getLocation() !== Location.EXTERIOR
+ };
+ RayCrossingCounter.prototype.getLocation = function getLocation () {
+ if (this._isPointOnSegment) { return Location.BOUNDARY }
+ if (this._crossingCount % 2 === 1) {
+ return Location.INTERIOR
+ }
+ return Location.EXTERIOR
+ };
+ RayCrossingCounter.prototype.isOnSegment = function isOnSegment () {
+ return this._isPointOnSegment
+ };
+ RayCrossingCounter.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ RayCrossingCounter.prototype.getClass = function getClass () {
+ return RayCrossingCounter
+ };
+ RayCrossingCounter.locatePointInRing = function locatePointInRing () {
+ if (arguments[0] instanceof Coordinate && hasInterface(arguments[1], CoordinateSequence)) {
+ var p = arguments[0];
+ var ring = arguments[1];
+ var counter = new RayCrossingCounter(p);
+ var p1 = new Coordinate();
+ var p2 = new Coordinate();
+ for (var i = 1; i < ring.size(); i++) {
+ ring.getCoordinate(i, p1);
+ ring.getCoordinate(i - 1, p2);
+ counter.countSegment(p1, p2);
+ if (counter.isOnSegment()) { return counter.getLocation() }
+ }
+ return counter.getLocation()
+ } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Array) {
+ var p$1 = arguments[0];
+ var ring$1 = arguments[1];
+ var counter$1 = new RayCrossingCounter(p$1);
+ for (var i$1 = 1; i$1 < ring$1.length; i$1++) {
+ var p1$1 = ring$1[i$1];
+ var p2$1 = ring$1[i$1 - 1];
+ counter$1.countSegment(p1$1, p2$1);
+ if (counter$1.isOnSegment()) { return counter$1.getLocation() }
+ }
+ return counter$1.getLocation()
+ }
+ };
+
+ var CGAlgorithms = function CGAlgorithms () {};
+
+ var staticAccessors$3 = { CLOCKWISE: { configurable: true },RIGHT: { configurable: true },COUNTERCLOCKWISE: { configurable: true },LEFT: { configurable: true },COLLINEAR: { configurable: true },STRAIGHT: { configurable: true } };
+
+ CGAlgorithms.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ CGAlgorithms.prototype.getClass = function getClass () {
+ return CGAlgorithms
+ };
+ CGAlgorithms.orientationIndex = function orientationIndex (p1, p2, q) {
+ return CGAlgorithmsDD.orientationIndex(p1, p2, q)
+ };
+ CGAlgorithms.signedArea = function signedArea () {
+ if (arguments[0] instanceof Array) {
+ var ring = arguments[0];
+ if (ring.length < 3) { return 0.0 }
+ var sum = 0.0;
+ var x0 = ring[0].x;
+ for (var i = 1; i < ring.length - 1; i++) {
+ var x = ring[i].x - x0;
+ var y1 = ring[i + 1].y;
+ var y2 = ring[i - 1].y;
+ sum += x * (y2 - y1);
+ }
+ return sum / 2.0
+ } else if (hasInterface(arguments[0], CoordinateSequence)) {
+ var ring$1 = arguments[0];
+ var n = ring$1.size();
+ if (n < 3) { return 0.0 }
+ var p0 = new Coordinate();
+ var p1 = new Coordinate();
+ var p2 = new Coordinate();
+ ring$1.getCoordinate(0, p1);
+ ring$1.getCoordinate(1, p2);
+ var x0$1 = p1.x;
+ p2.x -= x0$1;
+ var sum$1 = 0.0;
+ for (var i$1 = 1; i$1 < n - 1; i$1++) {
+ p0.y = p1.y;
+ p1.x = p2.x;
+ p1.y = p2.y;
+ ring$1.getCoordinate(i$1 + 1, p2);
+ p2.x -= x0$1;
+ sum$1 += p1.x * (p0.y - p2.y);
+ }
+ return sum$1 / 2.0
+ }
+ };
+ CGAlgorithms.distanceLineLine = function distanceLineLine (A, B, C, D) {
+ if (A.equals(B)) { return CGAlgorithms.distancePointLine(A, C, D) }
+ if (C.equals(D)) { return CGAlgorithms.distancePointLine(D, A, B) }
+ var noIntersection = false;
+ if (!Envelope.intersects(A, B, C, D)) {
+ noIntersection = true;
+ } else {
+ var denom = (B.x - A.x) * (D.y - C.y) - (B.y - A.y) * (D.x - C.x);
+ if (denom === 0) {
+ noIntersection = true;
+ } else {
+ var rNumb = (A.y - C.y) * (D.x - C.x) - (A.x - C.x) * (D.y - C.y);
+ var sNum = (A.y - C.y) * (B.x - A.x) - (A.x - C.x) * (B.y - A.y);
+ var s = sNum / denom;
+ var r = rNumb / denom;
+ if (r < 0 || r > 1 || s < 0 || s > 1) {
+ noIntersection = true;
+ }
+ }
+ }
+ if (noIntersection) {
+ return MathUtil.min(CGAlgorithms.distancePointLine(A, C, D), CGAlgorithms.distancePointLine(B, C, D), CGAlgorithms.distancePointLine(C, A, B), CGAlgorithms.distancePointLine(D, A, B))
+ }
+ return 0.0
+ };
+ CGAlgorithms.isPointInRing = function isPointInRing (p, ring) {
+ return CGAlgorithms.locatePointInRing(p, ring) !== Location.EXTERIOR
+ };
+ CGAlgorithms.computeLength = function computeLength (pts) {
+ var n = pts.size();
+ if (n <= 1) { return 0.0 }
+ var len = 0.0;
+ var p = new Coordinate();
+ pts.getCoordinate(0, p);
+ var x0 = p.x;
+ var y0 = p.y;
+ for (var i = 1; i < n; i++) {
+ pts.getCoordinate(i, p);
+ var x1 = p.x;
+ var y1 = p.y;
+ var dx = x1 - x0;
+ var dy = y1 - y0;
+ len += Math.sqrt(dx * dx + dy * dy);
+ x0 = x1;
+ y0 = y1;
+ }
+ return len
+ };
+ CGAlgorithms.isCCW = function isCCW (ring) {
+ var nPts = ring.length - 1;
+ if (nPts < 3) { throw new IllegalArgumentException('Ring has fewer than 4 points, so orientation cannot be determined') }
+ var hiPt = ring[0];
+ var hiIndex = 0;
+ for (var i = 1; i <= nPts; i++) {
+ var p = ring[i];
+ if (p.y > hiPt.y) {
+ hiPt = p;
+ hiIndex = i;
+ }
+ }
+ var iPrev = hiIndex;
+ do {
+ iPrev = iPrev - 1;
+ if (iPrev < 0) { iPrev = nPts; }
+ } while (ring[iPrev].equals2D(hiPt) && iPrev !== hiIndex)
+ var iNext = hiIndex;
+ do {
+ iNext = (iNext + 1) % nPts;
+ } while (ring[iNext].equals2D(hiPt) && iNext !== hiIndex)
+ var prev = ring[iPrev];
+ var next = ring[iNext];
+ if (prev.equals2D(hiPt) || next.equals2D(hiPt) || prev.equals2D(next)) { return false }
+ var disc = CGAlgorithms.computeOrientation(prev, hiPt, next);
+ var isCCW = false;
+ if (disc === 0) {
+ isCCW = prev.x > next.x;
+ } else {
+ isCCW = disc > 0;
+ }
+ return isCCW
+ };
+ CGAlgorithms.locatePointInRing = function locatePointInRing (p, ring) {
+ return RayCrossingCounter.locatePointInRing(p, ring)
+ };
+ CGAlgorithms.distancePointLinePerpendicular = function distancePointLinePerpendicular (p, A, B) {
+ var len2 = (B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y);
+ var s = ((A.y - p.y) * (B.x - A.x) - (A.x - p.x) * (B.y - A.y)) / len2;
+ return Math.abs(s) * Math.sqrt(len2)
+ };
+ CGAlgorithms.computeOrientation = function computeOrientation (p1, p2, q) {
+ return CGAlgorithms.orientationIndex(p1, p2, q)
+ };
+ CGAlgorithms.distancePointLine = function distancePointLine () {
+ if (arguments.length === 2) {
+ var p = arguments[0];
+ var line = arguments[1];
+ if (line.length === 0) { throw new IllegalArgumentException('Line array must contain at least one vertex') }
+ var minDistance = p.distance(line[0]);
+ for (var i = 0; i < line.length - 1; i++) {
+ var dist = CGAlgorithms.distancePointLine(p, line[i], line[i + 1]);
+ if (dist < minDistance) {
+ minDistance = dist;
+ }
+ }
+ return minDistance
+ } else if (arguments.length === 3) {
+ var p$1 = arguments[0];
+ var A = arguments[1];
+ var B = arguments[2];
+ if (A.x === B.x && A.y === B.y) { return p$1.distance(A) }
+ var len2 = (B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y);
+ var r = ((p$1.x - A.x) * (B.x - A.x) + (p$1.y - A.y) * (B.y - A.y)) / len2;
+ if (r <= 0.0) { return p$1.distance(A) }
+ if (r >= 1.0) { return p$1.distance(B) }
+ var s = ((A.y - p$1.y) * (B.x - A.x) - (A.x - p$1.x) * (B.y - A.y)) / len2;
+ return Math.abs(s) * Math.sqrt(len2)
+ }
+ };
+ CGAlgorithms.isOnLine = function isOnLine (p, pt) {
+ var lineIntersector = new RobustLineIntersector();
+ for (var i = 1; i < pt.length; i++) {
+ var p0 = pt[i - 1];
+ var p1 = pt[i];
+ lineIntersector.computeIntersection(p, p0, p1);
+ if (lineIntersector.hasIntersection()) {
+ return true
+ }
+ }
+ return false
+ };
+ staticAccessors$3.CLOCKWISE.get = function () { return -1 };
+ staticAccessors$3.RIGHT.get = function () { return CGAlgorithms.CLOCKWISE };
+ staticAccessors$3.COUNTERCLOCKWISE.get = function () { return 1 };
+ staticAccessors$3.LEFT.get = function () { return CGAlgorithms.COUNTERCLOCKWISE };
+ staticAccessors$3.COLLINEAR.get = function () { return 0 };
+ staticAccessors$3.STRAIGHT.get = function () { return CGAlgorithms.COLLINEAR };
+
+ Object.defineProperties( CGAlgorithms, staticAccessors$3 );
+
+ var GeometryComponentFilter = function GeometryComponentFilter () {};
+
+ GeometryComponentFilter.prototype.filter = function filter (geom) {};
+ GeometryComponentFilter.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ GeometryComponentFilter.prototype.getClass = function getClass () {
+ return GeometryComponentFilter
+ };
+
+ var Geometry = function Geometry () {
+ var factory = arguments[0];
+
+ this._envelope = null;
+ this._factory = null;
+ this._SRID = null;
+ this._userData = null;
+ this._factory = factory;
+ this._SRID = factory.getSRID();
+ };
+
+ var staticAccessors$11 = { serialVersionUID: { configurable: true },SORTINDEX_POINT: { configurable: true },SORTINDEX_MULTIPOINT: { configurable: true },SORTINDEX_LINESTRING: { configurable: true },SORTINDEX_LINEARRING: { configurable: true },SORTINDEX_MULTILINESTRING: { configurable: true },SORTINDEX_POLYGON: { configurable: true },SORTINDEX_MULTIPOLYGON: { configurable: true },SORTINDEX_GEOMETRYCOLLECTION: { configurable: true },geometryChangedFilter: { configurable: true } };
+ Geometry.prototype.isGeometryCollection = function isGeometryCollection () {
+ return this.getSortIndex() === Geometry.SORTINDEX_GEOMETRYCOLLECTION
+ };
+ Geometry.prototype.getFactory = function getFactory () {
+ return this._factory
+ };
+ Geometry.prototype.getGeometryN = function getGeometryN (n) {
+ return this
+ };
+ Geometry.prototype.getArea = function getArea () {
+ return 0.0
+ };
+ Geometry.prototype.isRectangle = function isRectangle () {
+ return false
+ };
+ Geometry.prototype.equals = function equals () {
+ if (arguments[0] instanceof Geometry) {
+ var g$1 = arguments[0];
+ if (g$1 === null) { return false }
+ return this.equalsTopo(g$1)
+ } else if (arguments[0] instanceof Object) {
+ var o = arguments[0];
+ if (!(o instanceof Geometry)) { return false }
+ var g = o;
+ return this.equalsExact(g)
+ }
+ };
+ Geometry.prototype.equalsExact = function equalsExact (other) {
+ return this === other || this.equalsExact(other, 0)
+ };
+ Geometry.prototype.geometryChanged = function geometryChanged () {
+ this.apply(Geometry.geometryChangedFilter);
+ };
+ Geometry.prototype.geometryChangedAction = function geometryChangedAction () {
+ this._envelope = null;
+ };
+ Geometry.prototype.equalsNorm = function equalsNorm (g) {
+ if (g === null) { return false }
+ return this.norm().equalsExact(g.norm())
+ };
+ Geometry.prototype.getLength = function getLength () {
+ return 0.0
+ };
+ Geometry.prototype.getNumGeometries = function getNumGeometries () {
+ return 1
+ };
+ Geometry.prototype.compareTo = function compareTo () {
+ if (arguments.length === 1) {
+ var o = arguments[0];
+ var other = o;
+ if (this.getSortIndex() !== other.getSortIndex()) {
+ return this.getSortIndex() - other.getSortIndex()
+ }
+ if (this.isEmpty() && other.isEmpty()) {
+ return 0
+ }
+ if (this.isEmpty()) {
+ return -1
+ }
+ if (other.isEmpty()) {
+ return 1
+ }
+ return this.compareToSameClass(o)
+ } else if (arguments.length === 2) {
+ var other$1 = arguments[0];
+ var comp = arguments[1];
+ if (this.getSortIndex() !== other$1.getSortIndex()) {
+ return this.getSortIndex() - other$1.getSortIndex()
+ }
+ if (this.isEmpty() && other$1.isEmpty()) {
+ return 0
+ }
+ if (this.isEmpty()) {
+ return -1
+ }
+ if (other$1.isEmpty()) {
+ return 1
+ }
+ return this.compareToSameClass(other$1, comp)
+ }
+ };
+ Geometry.prototype.getUserData = function getUserData () {
+ return this._userData
+ };
+ Geometry.prototype.getSRID = function getSRID () {
+ return this._SRID
+ };
+ Geometry.prototype.getEnvelope = function getEnvelope () {
+ return this.getFactory().toGeometry(this.getEnvelopeInternal())
+ };
+ Geometry.prototype.checkNotGeometryCollection = function checkNotGeometryCollection (g) {
+ if (g.getSortIndex() === Geometry.SORTINDEX_GEOMETRYCOLLECTION) {
+ throw new IllegalArgumentException('This method does not support GeometryCollection arguments')
+ }
+ };
+ Geometry.prototype.equal = function equal (a, b, tolerance) {
+ if (tolerance === 0) {
+ return a.equals(b)
+ }
+ return a.distance(b) <= tolerance
+ };
+ Geometry.prototype.norm = function norm () {
+ var copy = this.copy();
+ copy.normalize();
+ return copy
+ };
+ Geometry.prototype.getPrecisionModel = function getPrecisionModel () {
+ return this._factory.getPrecisionModel()
+ };
+ Geometry.prototype.getEnvelopeInternal = function getEnvelopeInternal () {
+ if (this._envelope === null) {
+ this._envelope = this.computeEnvelopeInternal();
+ }
+ return new Envelope(this._envelope)
+ };
+ Geometry.prototype.setSRID = function setSRID (SRID) {
+ this._SRID = SRID;
+ };
+ Geometry.prototype.setUserData = function setUserData (userData) {
+ this._userData = userData;
+ };
+ Geometry.prototype.compare = function compare (a, b) {
+ var i = a.iterator();
+ var j = b.iterator();
+ while (i.hasNext() && j.hasNext()) {
+ var aElement = i.next();
+ var bElement = j.next();
+ var comparison = aElement.compareTo(bElement);
+ if (comparison !== 0) {
+ return comparison
+ }
+ }
+ if (i.hasNext()) {
+ return 1
+ }
+ if (j.hasNext()) {
+ return -1
+ }
+ return 0
+ };
+ Geometry.prototype.hashCode = function hashCode () {
+ return this.getEnvelopeInternal().hashCode()
+ };
+ Geometry.prototype.isGeometryCollectionOrDerived = function isGeometryCollectionOrDerived () {
+ if (this.getSortIndex() === Geometry.SORTINDEX_GEOMETRYCOLLECTION || this.getSortIndex() === Geometry.SORTINDEX_MULTIPOINT || this.getSortIndex() === Geometry.SORTINDEX_MULTILINESTRING || this.getSortIndex() === Geometry.SORTINDEX_MULTIPOLYGON) {
+ return true
+ }
+ return false
+ };
+ Geometry.prototype.interfaces_ = function interfaces_ () {
+ return [Clonable, Comparable, Serializable]
+ };
+ Geometry.prototype.getClass = function getClass () {
+ return Geometry
+ };
+ Geometry.hasNonEmptyElements = function hasNonEmptyElements (geometries) {
+ for (var i = 0; i < geometries.length; i++) {
+ if (!geometries[i].isEmpty()) {
+ return true
+ }
+ }
+ return false
+ };
+ Geometry.hasNullElements = function hasNullElements (array) {
+ for (var i = 0; i < array.length; i++) {
+ if (array[i] === null) {
+ return true
+ }
+ }
+ return false
+ };
+ staticAccessors$11.serialVersionUID.get = function () { return 8763622679187376702 };
+ staticAccessors$11.SORTINDEX_POINT.get = function () { return 0 };
+ staticAccessors$11.SORTINDEX_MULTIPOINT.get = function () { return 1 };
+ staticAccessors$11.SORTINDEX_LINESTRING.get = function () { return 2 };
+ staticAccessors$11.SORTINDEX_LINEARRING.get = function () { return 3 };
+ staticAccessors$11.SORTINDEX_MULTILINESTRING.get = function () { return 4 };
+ staticAccessors$11.SORTINDEX_POLYGON.get = function () { return 5 };
+ staticAccessors$11.SORTINDEX_MULTIPOLYGON.get = function () { return 6 };
+ staticAccessors$11.SORTINDEX_GEOMETRYCOLLECTION.get = function () { return 7 };
+ staticAccessors$11.geometryChangedFilter.get = function () { return geometryChangedFilter };
+
+ Object.defineProperties( Geometry, staticAccessors$11 );
+
+ var geometryChangedFilter = function geometryChangedFilter () {};
+
+ geometryChangedFilter.interfaces_ = function interfaces_ () {
+ return [GeometryComponentFilter]
+ };
+ geometryChangedFilter.filter = function filter (geom) {
+ geom.geometryChangedAction();
+ };
+
+ var CoordinateFilter = function CoordinateFilter () {};
+
+ CoordinateFilter.prototype.filter = function filter (coord) {};
+ CoordinateFilter.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ CoordinateFilter.prototype.getClass = function getClass () {
+ return CoordinateFilter
+ };
+
+ var BoundaryNodeRule = function BoundaryNodeRule () {};
+
+ var staticAccessors$12 = { Mod2BoundaryNodeRule: { configurable: true },EndPointBoundaryNodeRule: { configurable: true },MultiValentEndPointBoundaryNodeRule: { configurable: true },MonoValentEndPointBoundaryNodeRule: { configurable: true },MOD2_BOUNDARY_RULE: { configurable: true },ENDPOINT_BOUNDARY_RULE: { configurable: true },MULTIVALENT_ENDPOINT_BOUNDARY_RULE: { configurable: true },MONOVALENT_ENDPOINT_BOUNDARY_RULE: { configurable: true },OGC_SFS_BOUNDARY_RULE: { configurable: true } };
+
+ BoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {};
+ BoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ BoundaryNodeRule.prototype.getClass = function getClass () {
+ return BoundaryNodeRule
+ };
+ staticAccessors$12.Mod2BoundaryNodeRule.get = function () { return Mod2BoundaryNodeRule };
+ staticAccessors$12.EndPointBoundaryNodeRule.get = function () { return EndPointBoundaryNodeRule };
+ staticAccessors$12.MultiValentEndPointBoundaryNodeRule.get = function () { return MultiValentEndPointBoundaryNodeRule };
+ staticAccessors$12.MonoValentEndPointBoundaryNodeRule.get = function () { return MonoValentEndPointBoundaryNodeRule };
+ staticAccessors$12.MOD2_BOUNDARY_RULE.get = function () { return new Mod2BoundaryNodeRule() };
+ staticAccessors$12.ENDPOINT_BOUNDARY_RULE.get = function () { return new EndPointBoundaryNodeRule() };
+ staticAccessors$12.MULTIVALENT_ENDPOINT_BOUNDARY_RULE.get = function () { return new MultiValentEndPointBoundaryNodeRule() };
+ staticAccessors$12.MONOVALENT_ENDPOINT_BOUNDARY_RULE.get = function () { return new MonoValentEndPointBoundaryNodeRule() };
+ staticAccessors$12.OGC_SFS_BOUNDARY_RULE.get = function () { return BoundaryNodeRule.MOD2_BOUNDARY_RULE };
+
+ Object.defineProperties( BoundaryNodeRule, staticAccessors$12 );
+
+ var Mod2BoundaryNodeRule = function Mod2BoundaryNodeRule () {};
+
+ Mod2BoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {
+ return boundaryCount % 2 === 1
+ };
+ Mod2BoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {
+ return [BoundaryNodeRule]
+ };
+ Mod2BoundaryNodeRule.prototype.getClass = function getClass () {
+ return Mod2BoundaryNodeRule
+ };
+
+ var EndPointBoundaryNodeRule = function EndPointBoundaryNodeRule () {};
+
+ EndPointBoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {
+ return boundaryCount > 0
+ };
+ EndPointBoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {
+ return [BoundaryNodeRule]
+ };
+ EndPointBoundaryNodeRule.prototype.getClass = function getClass () {
+ return EndPointBoundaryNodeRule
+ };
+
+ var MultiValentEndPointBoundaryNodeRule = function MultiValentEndPointBoundaryNodeRule () {};
+
+ MultiValentEndPointBoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {
+ return boundaryCount > 1
+ };
+ MultiValentEndPointBoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {
+ return [BoundaryNodeRule]
+ };
+ MultiValentEndPointBoundaryNodeRule.prototype.getClass = function getClass () {
+ return MultiValentEndPointBoundaryNodeRule
+ };
+
+ var MonoValentEndPointBoundaryNodeRule = function MonoValentEndPointBoundaryNodeRule () {};
+
+ MonoValentEndPointBoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {
+ return boundaryCount === 1
+ };
+ MonoValentEndPointBoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {
+ return [BoundaryNodeRule]
+ };
+ MonoValentEndPointBoundaryNodeRule.prototype.getClass = function getClass () {
+ return MonoValentEndPointBoundaryNodeRule
+ };
+
+ // import Iterator from './Iterator'
+
+ /**
+ * @see http://download.oracle.com/javase/6/docs/api/java/util/Collection.html
+ *
+ * @constructor
+ * @private
+ */
+ var Collection = function Collection () {};
+
+ Collection.prototype.add = function add () {};
+
+ /**
+ * Appends all of the elements in the specified collection to the end of this
+ * list, in the order that they are returned by the specified collection's
+ * iterator (optional operation).
+ * @param {javascript.util.Collection} c
+ * @return {boolean}
+ */
+ Collection.prototype.addAll = function addAll () {};
+
+ /**
+ * Returns true if this collection contains no elements.
+ * @return {boolean}
+ */
+ Collection.prototype.isEmpty = function isEmpty () {};
+
+ /**
+ * Returns an iterator over the elements in this collection.
+ * @return {javascript.util.Iterator}
+ */
+ Collection.prototype.iterator = function iterator () {};
+
+ /**
+ * Returns an iterator over the elements in this collection.
+ * @return {number}
+ */
+ Collection.prototype.size = function size () {};
+
+ /**
+ * Returns an array containing all of the elements in this collection.
+ * @return {Array}
+ */
+ Collection.prototype.toArray = function toArray () {};
+
+ /**
+ * Removes a single instance of the specified element from this collection if it
+ * is present. (optional)
+ * @param {Object} e
+ * @return {boolean}
+ */
+ Collection.prototype.remove = function remove () {};
+
+ /**
+ * @param {string=} message Optional message
+ * @extends {Error}
+ * @constructor
+ * @private
+ */
+ function IndexOutOfBoundsException (message) {
+ this.message = message || '';
+ }
+ IndexOutOfBoundsException.prototype = new Error();
+
+ /**
+ * @type {string}
+ */
+ IndexOutOfBoundsException.prototype.name = 'IndexOutOfBoundsException';
+
+ /**
+ * @see http://download.oracle.com/javase/6/docs/api/java/util/Iterator.html
+ * @constructor
+ * @private
+ */
+ var Iterator$1 = function Iterator () {};
+
+ Iterator$1.prototype.hasNext = function hasNext () {};
+
+ /**
+ * Returns the next element in the iteration.
+ * @return {Object}
+ */
+ Iterator$1.prototype.next = function next () {};
+
+ /**
+ * Removes from the underlying collection the last element returned by the
+ * iterator (optional operation).
+ */
+ Iterator$1.prototype.remove = function remove () {};
+
+ /**
+ * @see http://download.oracle.com/javase/6/docs/api/java/util/List.html
+ *
+ * @extends {javascript.util.Collection}
+ * @constructor
+ * @private
+ */
+ var List = (function (Collection$$1) {
+ function List () {
+ Collection$$1.apply(this, arguments);
+ }
+
+ if ( Collection$$1 ) List.__proto__ = Collection$$1;
+ List.prototype = Object.create( Collection$$1 && Collection$$1.prototype );
+ List.prototype.constructor = List;
+
+ List.prototype.get = function get () { };
+
+ /**
+ * Replaces the element at the specified position in this list with the
+ * specified element (optional operation).
+ * @param {number} index
+ * @param {Object} e
+ * @return {Object}
+ */
+ List.prototype.set = function set () { };
+
+ /**
+ * Returns true if this collection contains no elements.
+ * @return {boolean}
+ */
+ List.prototype.isEmpty = function isEmpty () { };
+
+ return List;
+ }(Collection));
+
+ /**
+ * @param {string=} message Optional message
+ * @extends {Error}
+ * @constructor
+ * @private
+ */
+ function NoSuchElementException (message) {
+ this.message = message || '';
+ }
+ NoSuchElementException.prototype = new Error();
+
+ /**
+ * @type {string}
+ */
+ NoSuchElementException.prototype.name = 'NoSuchElementException';
+
+ // import OperationNotSupported from './OperationNotSupported'
+
+ /**
+ * @see http://download.oracle.com/javase/6/docs/api/java/util/ArrayList.html
+ *
+ * @extends List
+ * @private
+ */
+ var ArrayList = (function (List$$1) {
+ function ArrayList () {
+ List$$1.call(this);
+ this.array_ = [];
+
+ if (arguments[0] instanceof Collection) {
+ this.addAll(arguments[0]);
+ }
+ }
+
+ if ( List$$1 ) ArrayList.__proto__ = List$$1;
+ ArrayList.prototype = Object.create( List$$1 && List$$1.prototype );
+ ArrayList.prototype.constructor = ArrayList;
+
+ ArrayList.prototype.ensureCapacity = function ensureCapacity () {};
+ ArrayList.prototype.interfaces_ = function interfaces_ () { return [List$$1, Collection] };
+
+ /**
+ * @override
+ */
+ ArrayList.prototype.add = function add (e) {
+ if (arguments.length === 1) {
+ this.array_.push(e);
+ } else {
+ this.array_.splice(arguments[0], arguments[1]);
+ }
+ return true
+ };
+
+ ArrayList.prototype.clear = function clear () {
+ this.array_ = [];
+ };
+
+ /**
+ * @override
+ */
+ ArrayList.prototype.addAll = function addAll (c) {
+ var this$1 = this;
+
+ for (var i = c.iterator(); i.hasNext();) {
+ this$1.add(i.next());
+ }
+ return true
+ };
+
+ /**
+ * @override
+ */
+ ArrayList.prototype.set = function set (index, element) {
+ var oldElement = this.array_[index];
+ this.array_[index] = element;
+ return oldElement
+ };
+
+ /**
+ * @override
+ */
+ ArrayList.prototype.iterator = function iterator () {
+ return new Iterator_(this)
+ };
+
+ /**
+ * @override
+ */
+ ArrayList.prototype.get = function get (index) {
+ if (index < 0 || index >= this.size()) {
+ throw new IndexOutOfBoundsException()
+ }
+
+ return this.array_[index]
+ };
+
+ /**
+ * @override
+ */
+ ArrayList.prototype.isEmpty = function isEmpty () {
+ return this.array_.length === 0
+ };
+
+ /**
+ * @override
+ */
+ ArrayList.prototype.size = function size () {
+ return this.array_.length
+ };
+
+ /**
+ * @override
+ */
+ ArrayList.prototype.toArray = function toArray () {
+ var this$1 = this;
+
+ var array = [];
+
+ for (var i = 0, len = this.array_.length; i < len; i++) {
+ array.push(this$1.array_[i]);
+ }
+
+ return array
+ };
+
+ /**
+ * @override
+ */
+ ArrayList.prototype.remove = function remove (o) {
+ var this$1 = this;
+
+ var found = false;
+
+ for (var i = 0, len = this.array_.length; i < len; i++) {
+ if (this$1.array_[i] === o) {
+ this$1.array_.splice(i, 1);
+ found = true;
+ break
+ }
+ }
+
+ return found
+ };
+
+ return ArrayList;
+ }(List));
+
+ /**
+ * @extends {Iterator}
+ * @param {ArrayList} arrayList
+ * @constructor
+ * @private
+ */
+ var Iterator_ = (function (Iterator$$1) {
+ function Iterator_ (arrayList) {
+ Iterator$$1.call(this);
+ /**
+ * @type {ArrayList}
+ * @private
+ */
+ this.arrayList_ = arrayList;
+ /**
+ * @type {number}
+ * @private
+ */
+ this.position_ = 0;
+ }
+
+ if ( Iterator$$1 ) Iterator_.__proto__ = Iterator$$1;
+ Iterator_.prototype = Object.create( Iterator$$1 && Iterator$$1.prototype );
+ Iterator_.prototype.constructor = Iterator_;
+
+ /**
+ * @override
+ */
+ Iterator_.prototype.next = function next () {
+ if (this.position_ === this.arrayList_.size()) {
+ throw new NoSuchElementException()
+ }
+ return this.arrayList_.get(this.position_++)
+ };
+
+ /**
+ * @override
+ */
+ Iterator_.prototype.hasNext = function hasNext () {
+ if (this.position_ < this.arrayList_.size()) {
+ return true
+ } else {
+ return false
+ }
+ };
+
+ /**
+ * TODO: should be in ListIterator
+ * @override
+ */
+ Iterator_.prototype.set = function set (element) {
+ return this.arrayList_.set(this.position_ - 1, element)
+ };
+
+ /**
+ * @override
+ */
+ Iterator_.prototype.remove = function remove () {
+ this.arrayList_.remove(this.arrayList_.get(this.position_));
+ };
+
+ return Iterator_;
+ }(Iterator$1));
+
+ var CoordinateList = (function (ArrayList$$1) {
+ function CoordinateList () {
+ ArrayList$$1.call(this);
+ if (arguments.length === 0) ; else if (arguments.length === 1) {
+ var coord = arguments[0];
+ this.ensureCapacity(coord.length);
+ this.add(coord, true);
+ } else if (arguments.length === 2) {
+ var coord$1 = arguments[0];
+ var allowRepeated = arguments[1];
+ this.ensureCapacity(coord$1.length);
+ this.add(coord$1, allowRepeated);
+ }
+ }
+
+ if ( ArrayList$$1 ) CoordinateList.__proto__ = ArrayList$$1;
+ CoordinateList.prototype = Object.create( ArrayList$$1 && ArrayList$$1.prototype );
+ CoordinateList.prototype.constructor = CoordinateList;
+
+ var staticAccessors = { coordArrayType: { configurable: true } };
+ staticAccessors.coordArrayType.get = function () { return new Array(0).fill(null) };
+ CoordinateList.prototype.getCoordinate = function getCoordinate (i) {
+ return this.get(i)
+ };
+ CoordinateList.prototype.addAll = function addAll () {
+ var this$1 = this;
+
+ if (arguments.length === 2) {
+ var coll = arguments[0];
+ var allowRepeated = arguments[1];
+ var isChanged = false;
+ for (var i = coll.iterator(); i.hasNext();) {
+ this$1.add(i.next(), allowRepeated);
+ isChanged = true;
+ }
+ return isChanged
+ } else { return ArrayList$$1.prototype.addAll.apply(this, arguments) }
+ };
+ CoordinateList.prototype.clone = function clone () {
+ var this$1 = this;
+
+ var clone = ArrayList$$1.prototype.clone.call(this);
+ for (var i = 0; i < this.size(); i++) {
+ clone.add(i, this$1.get(i).copy());
+ }
+ return clone
+ };
+ CoordinateList.prototype.toCoordinateArray = function toCoordinateArray () {
+ return this.toArray(CoordinateList.coordArrayType)
+ };
+ CoordinateList.prototype.add = function add () {
+ var this$1 = this;
+
+ if (arguments.length === 1) {
+ var coord = arguments[0];
+ ArrayList$$1.prototype.add.call(this, coord);
+ } else if (arguments.length === 2) {
+ if (arguments[0] instanceof Array && typeof arguments[1] === 'boolean') {
+ var coord$1 = arguments[0];
+ var allowRepeated = arguments[1];
+ this.add(coord$1, allowRepeated, true);
+ return true
+ } else if (arguments[0] instanceof Coordinate && typeof arguments[1] === 'boolean') {
+ var coord$2 = arguments[0];
+ var allowRepeated$1 = arguments[1];
+ if (!allowRepeated$1) {
+ if (this.size() >= 1) {
+ var last = this.get(this.size() - 1);
+ if (last.equals2D(coord$2)) { return null }
+ }
+ }
+ ArrayList$$1.prototype.add.call(this, coord$2);
+ } else if (arguments[0] instanceof Object && typeof arguments[1] === 'boolean') {
+ var obj = arguments[0];
+ var allowRepeated$2 = arguments[1];
+ this.add(obj, allowRepeated$2);
+ return true
+ }
+ } else if (arguments.length === 3) {
+ if (typeof arguments[2] === 'boolean' && (arguments[0] instanceof Array && typeof arguments[1] === 'boolean')) {
+ var coord$3 = arguments[0];
+ var allowRepeated$3 = arguments[1];
+ var direction = arguments[2];
+ if (direction) {
+ for (var i$1 = 0; i$1 < coord$3.length; i$1++) {
+ this$1.add(coord$3[i$1], allowRepeated$3);
+ }
+ } else {
+ for (var i$2 = coord$3.length - 1; i$2 >= 0; i$2--) {
+ this$1.add(coord$3[i$2], allowRepeated$3);
+ }
+ }
+ return true
+ } else if (typeof arguments[2] === 'boolean' && (Number.isInteger(arguments[0]) && arguments[1] instanceof Coordinate)) {
+ var i$3 = arguments[0];
+ var coord$4 = arguments[1];
+ var allowRepeated$4 = arguments[2];
+ if (!allowRepeated$4) {
+ var size = this.size();
+ if (size > 0) {
+ if (i$3 > 0) {
+ var prev = this.get(i$3 - 1);
+ if (prev.equals2D(coord$4)) { return null }
+ }
+ if (i$3 < size) {
+ var next = this.get(i$3);
+ if (next.equals2D(coord$4)) { return null }
+ }
+ }
+ }
+ ArrayList$$1.prototype.add.call(this, i$3, coord$4);
+ }
+ } else if (arguments.length === 4) {
+ var coord$5 = arguments[0];
+ var allowRepeated$5 = arguments[1];
+ var start = arguments[2];
+ var end = arguments[3];
+ var inc = 1;
+ if (start > end) { inc = -1; }
+ for (var i = start; i !== end; i += inc) {
+ this$1.add(coord$5[i], allowRepeated$5);
+ }
+ return true
+ }
+ };
+ CoordinateList.prototype.closeRing = function closeRing () {
+ if (this.size() > 0) { this.add(new Coordinate(this.get(0)), false); }
+ };
+ CoordinateList.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ CoordinateList.prototype.getClass = function getClass () {
+ return CoordinateList
+ };
+
+ Object.defineProperties( CoordinateList, staticAccessors );
+
+ return CoordinateList;
+ }(ArrayList));
+
+ var CoordinateArrays = function CoordinateArrays () {};
+
+ var staticAccessors$13 = { ForwardComparator: { configurable: true },BidirectionalComparator: { configurable: true },coordArrayType: { configurable: true } };
+
+ staticAccessors$13.ForwardComparator.get = function () { return ForwardComparator };
+ staticAccessors$13.BidirectionalComparator.get = function () { return BidirectionalComparator };
+ staticAccessors$13.coordArrayType.get = function () { return new Array(0).fill(null) };
+
+ CoordinateArrays.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ CoordinateArrays.prototype.getClass = function getClass () {
+ return CoordinateArrays
+ };
+ CoordinateArrays.isRing = function isRing (pts) {
+ if (pts.length < 4) { return false }
+ if (!pts[0].equals2D(pts[pts.length - 1])) { return false }
+ return true
+ };
+ CoordinateArrays.ptNotInList = function ptNotInList (testPts, pts) {
+ for (var i = 0; i < testPts.length; i++) {
+ var testPt = testPts[i];
+ if (CoordinateArrays.indexOf(testPt, pts) < 0) { return testPt }
+ }
+ return null
+ };
+ CoordinateArrays.scroll = function scroll (coordinates, firstCoordinate) {
+ var i = CoordinateArrays.indexOf(firstCoordinate, coordinates);
+ if (i < 0) { return null }
+ var newCoordinates = new Array(coordinates.length).fill(null);
+ System.arraycopy(coordinates, i, newCoordinates, 0, coordinates.length - i);
+ System.arraycopy(coordinates, 0, newCoordinates, coordinates.length - i, i);
+ System.arraycopy(newCoordinates, 0, coordinates, 0, coordinates.length);
+ };
+ CoordinateArrays.equals = function equals () {
+ if (arguments.length === 2) {
+ var coord1 = arguments[0];
+ var coord2 = arguments[1];
+ if (coord1 === coord2) { return true }
+ if (coord1 === null || coord2 === null) { return false }
+ if (coord1.length !== coord2.length) { return false }
+ for (var i = 0; i < coord1.length; i++) {
+ if (!coord1[i].equals(coord2[i])) { return false }
+ }
+ return true
+ } else if (arguments.length === 3) {
+ var coord1$1 = arguments[0];
+ var coord2$1 = arguments[1];
+ var coordinateComparator = arguments[2];
+ if (coord1$1 === coord2$1) { return true }
+ if (coord1$1 === null || coord2$1 === null) { return false }
+ if (coord1$1.length !== coord2$1.length) { return false }
+ for (var i$1 = 0; i$1 < coord1$1.length; i$1++) {
+ if (coordinateComparator.compare(coord1$1[i$1], coord2$1[i$1]) !== 0) { return false }
+ }
+ return true
+ }
+ };
+ CoordinateArrays.intersection = function intersection (coordinates, env) {
+ var coordList = new CoordinateList();
+ for (var i = 0; i < coordinates.length; i++) {
+ if (env.intersects(coordinates[i])) { coordList.add(coordinates[i], true); }
+ }
+ return coordList.toCoordinateArray()
+ };
+ CoordinateArrays.hasRepeatedPoints = function hasRepeatedPoints (coord) {
+ for (var i = 1; i < coord.length; i++) {
+ if (coord[i - 1].equals(coord[i])) {
+ return true
+ }
+ }
+ return false
+ };
+ CoordinateArrays.removeRepeatedPoints = function removeRepeatedPoints (coord) {
+ if (!CoordinateArrays.hasRepeatedPoints(coord)) { return coord }
+ var coordList = new CoordinateList(coord, false);
+ return coordList.toCoordinateArray()
+ };
+ CoordinateArrays.reverse = function reverse (coord) {
+ var last = coord.length - 1;
+ var mid = Math.trunc(last / 2);
+ for (var i = 0; i <= mid; i++) {
+ var tmp = coord[i];
+ coord[i] = coord[last - i];
+ coord[last - i] = tmp;
+ }
+ };
+ CoordinateArrays.removeNull = function removeNull (coord) {
+ var nonNull = 0;
+ for (var i = 0; i < coord.length; i++) {
+ if (coord[i] !== null) { nonNull++; }
+ }
+ var newCoord = new Array(nonNull).fill(null);
+ if (nonNull === 0) { return newCoord }
+ var j = 0;
+ for (var i$1 = 0; i$1 < coord.length; i$1++) {
+ if (coord[i$1] !== null) { newCoord[j++] = coord[i$1]; }
+ }
+ return newCoord
+ };
+ CoordinateArrays.copyDeep = function copyDeep () {
+ if (arguments.length === 1) {
+ var coordinates = arguments[0];
+ var copy = new Array(coordinates.length).fill(null);
+ for (var i = 0; i < coordinates.length; i++) {
+ copy[i] = new Coordinate(coordinates[i]);
+ }
+ return copy
+ } else if (arguments.length === 5) {
+ var src = arguments[0];
+ var srcStart = arguments[1];
+ var dest = arguments[2];
+ var destStart = arguments[3];
+ var length = arguments[4];
+ for (var i$1 = 0; i$1 < length; i$1++) {
+ dest[destStart + i$1] = new Coordinate(src[srcStart + i$1]);
+ }
+ }
+ };
+ CoordinateArrays.isEqualReversed = function isEqualReversed (pts1, pts2) {
+ for (var i = 0; i < pts1.length; i++) {
+ var p1 = pts1[i];
+ var p2 = pts2[pts1.length - i - 1];
+ if (p1.compareTo(p2) !== 0) { return false }
+ }
+ return true
+ };
+ CoordinateArrays.envelope = function envelope (coordinates) {
+ var env = new Envelope();
+ for (var i = 0; i < coordinates.length; i++) {
+ env.expandToInclude(coordinates[i]);
+ }
+ return env
+ };
+ CoordinateArrays.toCoordinateArray = function toCoordinateArray (coordList) {
+ return coordList.toArray(CoordinateArrays.coordArrayType)
+ };
+ CoordinateArrays.atLeastNCoordinatesOrNothing = function atLeastNCoordinatesOrNothing (n, c) {
+ return c.length >= n ? c : []
+ };
+ CoordinateArrays.indexOf = function indexOf (coordinate, coordinates) {
+ for (var i = 0; i < coordinates.length; i++) {
+ if (coordinate.equals(coordinates[i])) {
+ return i
+ }
+ }
+ return -1
+ };
+ CoordinateArrays.increasingDirection = function increasingDirection (pts) {
+ for (var i = 0; i < Math.trunc(pts.length / 2); i++) {
+ var j = pts.length - 1 - i;
+ var comp = pts[i].compareTo(pts[j]);
+ if (comp !== 0) { return comp }
+ }
+ return 1
+ };
+ CoordinateArrays.compare = function compare (pts1, pts2) {
+ var i = 0;
+ while (i < pts1.length && i < pts2.length) {
+ var compare = pts1[i].compareTo(pts2[i]);
+ if (compare !== 0) { return compare }
+ i++;
+ }
+ if (i < pts2.length) { return -1 }
+ if (i < pts1.length) { return 1 }
+ return 0
+ };
+ CoordinateArrays.minCoordinate = function minCoordinate (coordinates) {
+ var minCoord = null;
+ for (var i = 0; i < coordinates.length; i++) {
+ if (minCoord === null || minCoord.compareTo(coordinates[i]) > 0) {
+ minCoord = coordinates[i];
+ }
+ }
+ return minCoord
+ };
+ CoordinateArrays.extract = function extract (pts, start, end) {
+ start = MathUtil.clamp(start, 0, pts.length);
+ end = MathUtil.clamp(end, -1, pts.length);
+ var npts = end - start + 1;
+ if (end < 0) { npts = 0; }
+ if (start >= pts.length) { npts = 0; }
+ if (end < start) { npts = 0; }
+ var extractPts = new Array(npts).fill(null);
+ if (npts === 0) { return extractPts }
+ var iPts = 0;
+ for (var i = start; i <= end; i++) {
+ extractPts[iPts++] = pts[i];
+ }
+ return extractPts
+ };
+
+ Object.defineProperties( CoordinateArrays, staticAccessors$13 );
+
+ var ForwardComparator = function ForwardComparator () {};
+
+ ForwardComparator.prototype.compare = function compare (o1, o2) {
+ var pts1 = o1;
+ var pts2 = o2;
+ return CoordinateArrays.compare(pts1, pts2)
+ };
+ ForwardComparator.prototype.interfaces_ = function interfaces_ () {
+ return [Comparator]
+ };
+ ForwardComparator.prototype.getClass = function getClass () {
+ return ForwardComparator
+ };
+
+ var BidirectionalComparator = function BidirectionalComparator () {};
+
+ BidirectionalComparator.prototype.compare = function compare (o1, o2) {
+ var pts1 = o1;
+ var pts2 = o2;
+ if (pts1.length < pts2.length) { return -1 }
+ if (pts1.length > pts2.length) { return 1 }
+ if (pts1.length === 0) { return 0 }
+ var forwardComp = CoordinateArrays.compare(pts1, pts2);
+ var isEqualRev = CoordinateArrays.isEqualReversed(pts1, pts2);
+ if (isEqualRev) { return 0 }
+ return forwardComp
+ };
+ BidirectionalComparator.prototype.OLDcompare = function OLDcompare (o1, o2) {
+ var pts1 = o1;
+ var pts2 = o2;
+ if (pts1.length < pts2.length) { return -1 }
+ if (pts1.length > pts2.length) { return 1 }
+ if (pts1.length === 0) { return 0 }
+ var dir1 = CoordinateArrays.increasingDirection(pts1);
+ var dir2 = CoordinateArrays.increasingDirection(pts2);
+ var i1 = dir1 > 0 ? 0 : pts1.length - 1;
+ var i2 = dir2 > 0 ? 0 : pts1.length - 1;
+ for (var i = 0; i < pts1.length; i++) {
+ var comparePt = pts1[i1].compareTo(pts2[i2]);
+ if (comparePt !== 0) { return comparePt }
+ i1 += dir1;
+ i2 += dir2;
+ }
+ return 0
+ };
+ BidirectionalComparator.prototype.interfaces_ = function interfaces_ () {
+ return [Comparator]
+ };
+ BidirectionalComparator.prototype.getClass = function getClass () {
+ return BidirectionalComparator
+ };
+
+ /**
+ * @see http://download.oracle.com/javase/6/docs/api/java/util/Map.html
+ *
+ * @constructor
+ * @private
+ */
+ var Map$1$1 = function Map () {};
+
+ Map$1$1.prototype.get = function get () {};
+ /**
+ * Associates the specified value with the specified key in this map (optional
+ * operation).
+ * @param {Object} key
+ * @param {Object} value
+ * @return {Object}
+ */
+ Map$1$1.prototype.put = function put () {};
+
+ /**
+ * Returns the number of key-value mappings in this map.
+ * @return {number}
+ */
+ Map$1$1.prototype.size = function size () {};
+
+ /**
+ * Returns a Collection view of the values contained in this map.
+ * @return {javascript.util.Collection}
+ */
+ Map$1$1.prototype.values = function values () {};
+
+ /**
+ * Returns a {@link Set} view of the mappings contained in this map.
+ * The set is backed by the map, so changes to the map are
+ * reflected in the set, and vice-versa.If the map is modified
+ * while an iteration over the set is in progress (except through
+ * the iterator's own remove operation, or through the
+ * setValue operation on a map entry returned by the
+ * iterator) the results of the iteration are undefined.The set
+ * supports element removal, which removes the corresponding
+ * mapping from the map, via the Iterator.remove ,
+ * Set.remove , removeAll , retainAll and
+ * clear operations.It does not support the
+ * add or addAll operations.
+ *
+ * @return {Set} a set view of the mappings contained in this map
+ */
+ Map$1$1.prototype.entrySet = function entrySet () {};
+
+ /**
+ * @see http://download.oracle.com/javase/6/docs/api/java/util/SortedMap.html
+ *
+ * @extends {Map}
+ * @constructor
+ * @private
+ */
+ var SortedMap = (function (Map) {
+ function SortedMap () {
+ Map.apply(this, arguments);
+ }if ( Map ) SortedMap.__proto__ = Map;
+ SortedMap.prototype = Object.create( Map && Map.prototype );
+ SortedMap.prototype.constructor = SortedMap;
+
+
+
+ return SortedMap;
+ }(Map$1$1));
+
+ /**
+ * @param {string=} message Optional message
+ * @extends {Error}
+ * @constructor
+ * @private
+ */
+ function OperationNotSupported (message) {
+ this.message = message || '';
+ }
+ OperationNotSupported.prototype = new Error();
+
+ /**
+ * @type {string}
+ */
+ OperationNotSupported.prototype.name = 'OperationNotSupported';
+
+ /**
+ * @see http://download.oracle.com/javase/6/docs/api/java/util/Set.html
+ *
+ * @extends {Collection}
+ * @constructor
+ * @private
+ */
+ function Set$3() {}
+ Set$3.prototype = new Collection();
+
+
+ /**
+ * Returns true if this set contains the specified element. More formally,
+ * returns true if and only if this set contains an element e such that (o==null ?
+ * e==null : o.equals(e)).
+ * @param {Object} e
+ * @return {boolean}
+ */
+ Set$3.prototype.contains = function() {};
+
+ /**
+ * @see http://docs.oracle.com/javase/6/docs/api/java/util/HashSet.html
+ *
+ * @extends {javascript.util.Set}
+ * @constructor
+ * @private
+ */
+ var HashSet = (function (Set$$1) {
+ function HashSet () {
+ Set$$1.call(this);
+ this.array_ = [];
+
+ if (arguments[0] instanceof Collection) {
+ this.addAll(arguments[0]);
+ }
+ }
+
+ if ( Set$$1 ) HashSet.__proto__ = Set$$1;
+ HashSet.prototype = Object.create( Set$$1 && Set$$1.prototype );
+ HashSet.prototype.constructor = HashSet;
+
+ /**
+ * @override
+ */
+ HashSet.prototype.contains = function contains (o) {
+ var this$1 = this;
+
+ for (var i = 0, len = this.array_.length; i < len; i++) {
+ var e = this$1.array_[i];
+ if (e === o) {
+ return true
+ }
+ }
+ return false
+ };
+
+ /**
+ * @override
+ */
+ HashSet.prototype.add = function add (o) {
+ if (this.contains(o)) {
+ return false
+ }
+
+ this.array_.push(o);
+
+ return true
+ };
+
+ /**
+ * @override
+ */
+ HashSet.prototype.addAll = function addAll (c) {
+ var this$1 = this;
+
+ for (var i = c.iterator(); i.hasNext();) {
+ this$1.add(i.next());
+ }
+ return true
+ };
+
+ /**
+ * @override
+ */
+ HashSet.prototype.remove = function remove (o) {
+ // throw new javascript.util.OperationNotSupported()
+ throw new Error()
+ };
+
+ /**
+ * @override
+ */
+ HashSet.prototype.size = function size () {
+ return this.array_.length
+ };
+
+ /**
+ * @override
+ */
+ HashSet.prototype.isEmpty = function isEmpty () {
+ return this.array_.length === 0
+ };
+
+ /**
+ * @override
+ */
+ HashSet.prototype.toArray = function toArray () {
+ var this$1 = this;
+
+ var array = [];
+
+ for (var i = 0, len = this.array_.length; i < len; i++) {
+ array.push(this$1.array_[i]);
+ }
+
+ return array
+ };
+
+ /**
+ * @override
+ */
+ HashSet.prototype.iterator = function iterator () {
+ return new Iterator_$1(this)
+ };
+
+ return HashSet;
+ }(Set$3));
+
+ /**
+ * @extends {Iterator}
+ * @param {HashSet} hashSet
+ * @constructor
+ * @private
+ */
+ var Iterator_$1 = (function (Iterator$$1) {
+ function Iterator_ (hashSet) {
+ Iterator$$1.call(this);
+ /**
+ * @type {HashSet}
+ * @private
+ */
+ this.hashSet_ = hashSet;
+ /**
+ * @type {number}
+ * @private
+ */
+ this.position_ = 0;
+ }
+
+ if ( Iterator$$1 ) Iterator_.__proto__ = Iterator$$1;
+ Iterator_.prototype = Object.create( Iterator$$1 && Iterator$$1.prototype );
+ Iterator_.prototype.constructor = Iterator_;
+
+ /**
+ * @override
+ */
+ Iterator_.prototype.next = function next () {
+ if (this.position_ === this.hashSet_.size()) {
+ throw new NoSuchElementException()
+ }
+ return this.hashSet_.array_[this.position_++]
+ };
+
+ /**
+ * @override
+ */
+ Iterator_.prototype.hasNext = function hasNext () {
+ if (this.position_ < this.hashSet_.size()) {
+ return true
+ } else {
+ return false
+ }
+ };
+
+ /**
+ * @override
+ */
+ Iterator_.prototype.remove = function remove () {
+ throw new OperationNotSupported()
+ };
+
+ return Iterator_;
+ }(Iterator$1));
+
+ var BLACK = 0;
+ var RED = 1;
+ function colorOf (p) { return (p === null ? BLACK : p.color) }
+ function parentOf (p) { return (p === null ? null : p.parent) }
+ function setColor (p, c) { if (p !== null) { p.color = c; } }
+ function leftOf (p) { return (p === null ? null : p.left) }
+ function rightOf (p) { return (p === null ? null : p.right) }
+
+ /**
+ * @see http://download.oracle.com/javase/6/docs/api/java/util/TreeMap.html
+ *
+ * @extends {SortedMap}
+ * @constructor
+ * @private
+ */
+ function TreeMap () {
+ /**
+ * @type {Object}
+ * @private
+ */
+ this.root_ = null;
+ /**
+ * @type {number}
+ * @private
+ */
+ this.size_ = 0;
+ }
+ TreeMap.prototype = new SortedMap();
+
+ /**
+ * @override
+ */
+ TreeMap.prototype.get = function (key) {
+ var p = this.root_;
+ while (p !== null) {
+ var cmp = key['compareTo'](p.key);
+ if (cmp < 0) { p = p.left; }
+ else if (cmp > 0) { p = p.right; }
+ else { return p.value }
+ }
+ return null
+ };
+
+ /**
+ * @override
+ */
+ TreeMap.prototype.put = function (key, value) {
+ if (this.root_ === null) {
+ this.root_ = {
+ key: key,
+ value: value,
+ left: null,
+ right: null,
+ parent: null,
+ color: BLACK,
+ getValue: function getValue () { return this.value },
+ getKey: function getKey () { return this.key }
+ };
+ this.size_ = 1;
+ return null
+ }
+ var t = this.root_;
+ var parent;
+ var cmp;
+ do {
+ parent = t;
+ cmp = key['compareTo'](t.key);
+ if (cmp < 0) {
+ t = t.left;
+ } else if (cmp > 0) {
+ t = t.right;
+ } else {
+ var oldValue = t.value;
+ t.value = value;
+ return oldValue
+ }
+ } while (t !== null)
+ var e = {
+ key: key,
+ left: null,
+ right: null,
+ value: value,
+ parent: parent,
+ color: BLACK,
+ getValue: function getValue () { return this.value },
+ getKey: function getKey () { return this.key }
+ };
+ if (cmp < 0) {
+ parent.left = e;
+ } else {
+ parent.right = e;
+ }
+ this.fixAfterInsertion(e);
+ this.size_++;
+ return null
+ };
+
+ /**
+ * @param {Object} x
+ */
+ TreeMap.prototype.fixAfterInsertion = function (x) {
+ var this$1 = this;
+
+ x.color = RED;
+ while (x != null && x !== this.root_ && x.parent.color === RED) {
+ if (parentOf(x) === leftOf(parentOf(parentOf(x)))) {
+ var y = rightOf(parentOf(parentOf(x)));
+ if (colorOf(y) === RED) {
+ setColor(parentOf(x), BLACK);
+ setColor(y, BLACK);
+ setColor(parentOf(parentOf(x)), RED);
+ x = parentOf(parentOf(x));
+ } else {
+ if (x === rightOf(parentOf(x))) {
+ x = parentOf(x);
+ this$1.rotateLeft(x);
+ }
+ setColor(parentOf(x), BLACK);
+ setColor(parentOf(parentOf(x)), RED);
+ this$1.rotateRight(parentOf(parentOf(x)));
+ }
+ } else {
+ var y$1 = leftOf(parentOf(parentOf(x)));
+ if (colorOf(y$1) === RED) {
+ setColor(parentOf(x), BLACK);
+ setColor(y$1, BLACK);
+ setColor(parentOf(parentOf(x)), RED);
+ x = parentOf(parentOf(x));
+ } else {
+ if (x === leftOf(parentOf(x))) {
+ x = parentOf(x);
+ this$1.rotateRight(x);
+ }
+ setColor(parentOf(x), BLACK);
+ setColor(parentOf(parentOf(x)), RED);
+ this$1.rotateLeft(parentOf(parentOf(x)));
+ }
+ }
+ }
+ this.root_.color = BLACK;
+ };
+
+ /**
+ * @override
+ */
+ TreeMap.prototype.values = function () {
+ var arrayList = new ArrayList();
+ var p = this.getFirstEntry();
+ if (p !== null) {
+ arrayList.add(p.value);
+ while ((p = TreeMap.successor(p)) !== null) {
+ arrayList.add(p.value);
+ }
+ }
+ return arrayList
+ };
+
+ /**
+ * @override
+ */
+ TreeMap.prototype.entrySet = function () {
+ var hashSet = new HashSet();
+ var p = this.getFirstEntry();
+ if (p !== null) {
+ hashSet.add(p);
+ while ((p = TreeMap.successor(p)) !== null) {
+ hashSet.add(p);
+ }
+ }
+ return hashSet
+ };
+
+ /**
+ * @param {Object} p
+ */
+ TreeMap.prototype.rotateLeft = function (p) {
+ if (p != null) {
+ var r = p.right;
+ p.right = r.left;
+ if (r.left != null) { r.left.parent = p; }
+ r.parent = p.parent;
+ if (p.parent === null) { this.root_ = r; } else if (p.parent.left === p) { p.parent.left = r; } else { p.parent.right = r; }
+ r.left = p;
+ p.parent = r;
+ }
+ };
+
+ /**
+ * @param {Object} p
+ */
+ TreeMap.prototype.rotateRight = function (p) {
+ if (p != null) {
+ var l = p.left;
+ p.left = l.right;
+ if (l.right != null) { l.right.parent = p; }
+ l.parent = p.parent;
+ if (p.parent === null) { this.root_ = l; } else if (p.parent.right === p) { p.parent.right = l; } else { p.parent.left = l; }
+ l.right = p;
+ p.parent = l;
+ }
+ };
+
+ /**
+ * @return {Object}
+ */
+ TreeMap.prototype.getFirstEntry = function () {
+ var p = this.root_;
+ if (p != null) {
+ while (p.left != null) {
+ p = p.left;
+ }
+ }
+ return p
+ };
+
+ /**
+ * @param {Object} t
+ * @return {Object}
+ * @private
+ */
+ TreeMap.successor = function (t) {
+ if (t === null) { return null } else if (t.right !== null) {
+ var p = t.right;
+ while (p.left !== null) {
+ p = p.left;
+ }
+ return p
+ } else {
+ var p$1 = t.parent;
+ var ch = t;
+ while (p$1 !== null && ch === p$1.right) {
+ ch = p$1;
+ p$1 = p$1.parent;
+ }
+ return p$1
+ }
+ };
+
+ /**
+ * @override
+ */
+ TreeMap.prototype.size = function () {
+ return this.size_
+ };
+
+ var Lineal = function Lineal () {};
+
+ Lineal.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ Lineal.prototype.getClass = function getClass () {
+ return Lineal
+ };
+
+ /**
+ * @see http://download.oracle.com/javase/6/docs/api/java/util/SortedSet.html
+ *
+ * @extends {Set}
+ * @constructor
+ * @private
+ */
+ function SortedSet () {}
+ SortedSet.prototype = new Set$3();
+
+ // import Iterator from './Iterator'
+ /**
+ * @see http://download.oracle.com/javase/6/docs/api/java/util/TreeSet.html
+ *
+ * @extends {SortedSet}
+ * @constructor
+ * @private
+ */
+ function TreeSet () {
+ /**
+ * @type {Array}
+ * @private
+ */
+ this.array_ = [];
+
+ if (arguments[0] instanceof Collection) {
+ this.addAll(arguments[0]);
+ }
+ }
+ TreeSet.prototype = new SortedSet();
+
+ /**
+ * @override
+ */
+ TreeSet.prototype.contains = function (o) {
+ var this$1 = this;
+
+ for (var i = 0, len = this.array_.length; i < len; i++) {
+ var e = this$1.array_[i];
+ if (e['compareTo'](o) === 0) {
+ return true
+ }
+ }
+ return false
+ };
+
+ /**
+ * @override
+ */
+ TreeSet.prototype.add = function (o) {
+ var this$1 = this;
+
+ if (this.contains(o)) {
+ return false
+ }
+
+ for (var i = 0, len = this.array_.length; i < len; i++) {
+ var e = this$1.array_[i];
+ if (e['compareTo'](o) === 1) {
+ this$1.array_.splice(i, 0, o);
+ return true
+ }
+ }
+
+ this.array_.push(o);
+
+ return true
+ };
+
+ /**
+ * @override
+ */
+ TreeSet.prototype.addAll = function (c) {
+ var this$1 = this;
+
+ for (var i = c.iterator(); i.hasNext();) {
+ this$1.add(i.next());
+ }
+ return true
+ };
+
+ /**
+ * @override
+ */
+ TreeSet.prototype.remove = function (e) {
+ throw new OperationNotSupported()
+ };
+
+ /**
+ * @override
+ */
+ TreeSet.prototype.size = function () {
+ return this.array_.length
+ };
+
+ /**
+ * @override
+ */
+ TreeSet.prototype.isEmpty = function () {
+ return this.array_.length === 0
+ };
+
+ /**
+ * @override
+ */
+ TreeSet.prototype.toArray = function () {
+ var this$1 = this;
+
+ var array = [];
+
+ for (var i = 0, len = this.array_.length; i < len; i++) {
+ array.push(this$1.array_[i]);
+ }
+
+ return array
+ };
+
+ /**
+ * @override
+ */
+ TreeSet.prototype.iterator = function () {
+ return new Iterator_$2(this)
+ };
+
+ /**
+ * @extends {javascript.util.Iterator}
+ * @param {javascript.util.TreeSet} treeSet
+ * @constructor
+ * @private
+ */
+ var Iterator_$2 = function (treeSet) {
+ /**
+ * @type {javascript.util.TreeSet}
+ * @private
+ */
+ this.treeSet_ = treeSet;
+ /**
+ * @type {number}
+ * @private
+ */
+ this.position_ = 0;
+ };
+
+ /**
+ * @override
+ */
+ Iterator_$2.prototype.next = function () {
+ if (this.position_ === this.treeSet_.size()) {
+ throw new NoSuchElementException()
+ }
+ return this.treeSet_.array_[this.position_++]
+ };
+
+ /**
+ * @override
+ */
+ Iterator_$2.prototype.hasNext = function () {
+ if (this.position_ < this.treeSet_.size()) {
+ return true
+ } else {
+ return false
+ }
+ };
+
+ /**
+ * @override
+ */
+ Iterator_$2.prototype.remove = function () {
+ throw new OperationNotSupported()
+ };
+
+ /**
+ * @see http://download.oracle.com/javase/6/docs/api/java/util/Arrays.html
+ *
+ * @constructor
+ * @private
+ */
+ var Arrays = function Arrays () {};
+
+ Arrays.sort = function sort () {
+ var a = arguments[0];
+ var i;
+ var t;
+ var comparator;
+ var compare;
+ if (arguments.length === 1) {
+ compare = function (a, b) {
+ return a.compareTo(b)
+ };
+ a.sort(compare);
+ } else if (arguments.length === 2) {
+ comparator = arguments[1];
+ compare = function (a, b) {
+ return comparator['compare'](a, b)
+ };
+ a.sort(compare);
+ } else if (arguments.length === 3) {
+ t = a.slice(arguments[1], arguments[2]);
+ t.sort();
+ var r = a.slice(0, arguments[1]).concat(t, a.slice(arguments[2], a.length));
+ a.splice(0, a.length);
+ for (i = 0; i < r.length; i++) {
+ a.push(r[i]);
+ }
+ } else if (arguments.length === 4) {
+ t = a.slice(arguments[1], arguments[2]);
+ comparator = arguments[3];
+ compare = function (a, b) {
+ return comparator['compare'](a, b)
+ };
+ t.sort(compare);
+ r = a.slice(0, arguments[1]).concat(t, a.slice(arguments[2], a.length));
+ a.splice(0, a.length);
+ for (i = 0; i < r.length; i++) {
+ a.push(r[i]);
+ }
+ }
+ };
+ /**
+ * @param {Array} array
+ * @return {ArrayList}
+ */
+ Arrays.asList = function asList (array) {
+ var arrayList = new ArrayList();
+ for (var i = 0, len = array.length; i < len; i++) {
+ arrayList.add(array[i]);
+ }
+ return arrayList
+ };
+
+ var Dimension = function Dimension () {};
+
+ var staticAccessors$14 = { P: { configurable: true },L: { configurable: true },A: { configurable: true },FALSE: { configurable: true },TRUE: { configurable: true },DONTCARE: { configurable: true },SYM_FALSE: { configurable: true },SYM_TRUE: { configurable: true },SYM_DONTCARE: { configurable: true },SYM_P: { configurable: true },SYM_L: { configurable: true },SYM_A: { configurable: true } };
+
+ staticAccessors$14.P.get = function () { return 0 };
+ staticAccessors$14.L.get = function () { return 1 };
+ staticAccessors$14.A.get = function () { return 2 };
+ staticAccessors$14.FALSE.get = function () { return -1 };
+ staticAccessors$14.TRUE.get = function () { return -2 };
+ staticAccessors$14.DONTCARE.get = function () { return -3 };
+ staticAccessors$14.SYM_FALSE.get = function () { return 'F' };
+ staticAccessors$14.SYM_TRUE.get = function () { return 'T' };
+ staticAccessors$14.SYM_DONTCARE.get = function () { return '*' };
+ staticAccessors$14.SYM_P.get = function () { return '0' };
+ staticAccessors$14.SYM_L.get = function () { return '1' };
+ staticAccessors$14.SYM_A.get = function () { return '2' };
+
+ Dimension.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ Dimension.prototype.getClass = function getClass () {
+ return Dimension
+ };
+ Dimension.toDimensionSymbol = function toDimensionSymbol (dimensionValue) {
+ switch (dimensionValue) {
+ case Dimension.FALSE:
+ return Dimension.SYM_FALSE
+ case Dimension.TRUE:
+ return Dimension.SYM_TRUE
+ case Dimension.DONTCARE:
+ return Dimension.SYM_DONTCARE
+ case Dimension.P:
+ return Dimension.SYM_P
+ case Dimension.L:
+ return Dimension.SYM_L
+ case Dimension.A:
+ return Dimension.SYM_A
+ }
+ throw new IllegalArgumentException('Unknown dimension value: ' + dimensionValue)
+ };
+ Dimension.toDimensionValue = function toDimensionValue (dimensionSymbol) {
+ switch (Character.toUpperCase(dimensionSymbol)) {
+ case Dimension.SYM_FALSE:
+ return Dimension.FALSE
+ case Dimension.SYM_TRUE:
+ return Dimension.TRUE
+ case Dimension.SYM_DONTCARE:
+ return Dimension.DONTCARE
+ case Dimension.SYM_P:
+ return Dimension.P
+ case Dimension.SYM_L:
+ return Dimension.L
+ case Dimension.SYM_A:
+ return Dimension.A
+ }
+ throw new IllegalArgumentException('Unknown dimension symbol: ' + dimensionSymbol)
+ };
+
+ Object.defineProperties( Dimension, staticAccessors$14 );
+
+ var GeometryFilter = function GeometryFilter () {};
+
+ GeometryFilter.prototype.filter = function filter (geom) {};
+ GeometryFilter.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ GeometryFilter.prototype.getClass = function getClass () {
+ return GeometryFilter
+ };
+
+ var CoordinateSequenceFilter = function CoordinateSequenceFilter () {};
+
+ CoordinateSequenceFilter.prototype.filter = function filter (seq, i) {};
+ CoordinateSequenceFilter.prototype.isDone = function isDone () {};
+ CoordinateSequenceFilter.prototype.isGeometryChanged = function isGeometryChanged () {};
+ CoordinateSequenceFilter.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ CoordinateSequenceFilter.prototype.getClass = function getClass () {
+ return CoordinateSequenceFilter
+ };
+
+ var GeometryCollection = (function (Geometry$$1) {
+ function GeometryCollection (geometries, factory) {
+ Geometry$$1.call(this, factory);
+ this._geometries = geometries || [];
+
+ if (Geometry$$1.hasNullElements(this._geometries)) {
+ throw new IllegalArgumentException('geometries must not contain null elements')
+ }
+ }
+
+ if ( Geometry$$1 ) GeometryCollection.__proto__ = Geometry$$1;
+ GeometryCollection.prototype = Object.create( Geometry$$1 && Geometry$$1.prototype );
+ GeometryCollection.prototype.constructor = GeometryCollection;
+
+ var staticAccessors = { serialVersionUID: { configurable: true } };
+ GeometryCollection.prototype.computeEnvelopeInternal = function computeEnvelopeInternal () {
+ var this$1 = this;
+
+ var envelope = new Envelope();
+ for (var i = 0; i < this._geometries.length; i++) {
+ envelope.expandToInclude(this$1._geometries[i].getEnvelopeInternal());
+ }
+ return envelope
+ };
+ GeometryCollection.prototype.getGeometryN = function getGeometryN (n) {
+ return this._geometries[n]
+ };
+ GeometryCollection.prototype.getSortIndex = function getSortIndex () {
+ return Geometry$$1.SORTINDEX_GEOMETRYCOLLECTION
+ };
+ GeometryCollection.prototype.getCoordinates = function getCoordinates () {
+ var this$1 = this;
+
+ var coordinates = new Array(this.getNumPoints()).fill(null);
+ var k = -1;
+ for (var i = 0; i < this._geometries.length; i++) {
+ var childCoordinates = this$1._geometries[i].getCoordinates();
+ for (var j = 0; j < childCoordinates.length; j++) {
+ k++;
+ coordinates[k] = childCoordinates[j];
+ }
+ }
+ return coordinates
+ };
+ GeometryCollection.prototype.getArea = function getArea () {
+ var this$1 = this;
+
+ var area = 0.0;
+ for (var i = 0; i < this._geometries.length; i++) {
+ area += this$1._geometries[i].getArea();
+ }
+ return area
+ };
+ GeometryCollection.prototype.equalsExact = function equalsExact () {
+ var this$1 = this;
+
+ if (arguments.length === 2) {
+ var other = arguments[0];
+ var tolerance = arguments[1];
+ if (!this.isEquivalentClass(other)) {
+ return false
+ }
+ var otherCollection = other;
+ if (this._geometries.length !== otherCollection._geometries.length) {
+ return false
+ }
+ for (var i = 0; i < this._geometries.length; i++) {
+ if (!this$1._geometries[i].equalsExact(otherCollection._geometries[i], tolerance)) {
+ return false
+ }
+ }
+ return true
+ } else { return Geometry$$1.prototype.equalsExact.apply(this, arguments) }
+ };
+ GeometryCollection.prototype.normalize = function normalize () {
+ var this$1 = this;
+
+ for (var i = 0; i < this._geometries.length; i++) {
+ this$1._geometries[i].normalize();
+ }
+ Arrays.sort(this._geometries);
+ };
+ GeometryCollection.prototype.getCoordinate = function getCoordinate () {
+ if (this.isEmpty()) { return null }
+ return this._geometries[0].getCoordinate()
+ };
+ GeometryCollection.prototype.getBoundaryDimension = function getBoundaryDimension () {
+ var this$1 = this;
+
+ var dimension = Dimension.FALSE;
+ for (var i = 0; i < this._geometries.length; i++) {
+ dimension = Math.max(dimension, this$1._geometries[i].getBoundaryDimension());
+ }
+ return dimension
+ };
+ GeometryCollection.prototype.getDimension = function getDimension () {
+ var this$1 = this;
+
+ var dimension = Dimension.FALSE;
+ for (var i = 0; i < this._geometries.length; i++) {
+ dimension = Math.max(dimension, this$1._geometries[i].getDimension());
+ }
+ return dimension
+ };
+ GeometryCollection.prototype.getLength = function getLength () {
+ var this$1 = this;
+
+ var sum = 0.0;
+ for (var i = 0; i < this._geometries.length; i++) {
+ sum += this$1._geometries[i].getLength();
+ }
+ return sum
+ };
+ GeometryCollection.prototype.getNumPoints = function getNumPoints () {
+ var this$1 = this;
+
+ var numPoints = 0;
+ for (var i = 0; i < this._geometries.length; i++) {
+ numPoints += this$1._geometries[i].getNumPoints();
+ }
+ return numPoints
+ };
+ GeometryCollection.prototype.getNumGeometries = function getNumGeometries () {
+ return this._geometries.length
+ };
+ GeometryCollection.prototype.reverse = function reverse () {
+ var this$1 = this;
+
+ var n = this._geometries.length;
+ var revGeoms = new Array(n).fill(null);
+ for (var i = 0; i < this._geometries.length; i++) {
+ revGeoms[i] = this$1._geometries[i].reverse();
+ }
+ return this.getFactory().createGeometryCollection(revGeoms)
+ };
+ GeometryCollection.prototype.compareToSameClass = function compareToSameClass () {
+ var this$1 = this;
+
+ if (arguments.length === 1) {
+ var o = arguments[0];
+ var theseElements = new TreeSet(Arrays.asList(this._geometries));
+ var otherElements = new TreeSet(Arrays.asList(o._geometries));
+ return this.compare(theseElements, otherElements)
+ } else if (arguments.length === 2) {
+ var o$1 = arguments[0];
+ var comp = arguments[1];
+ var gc = o$1;
+ var n1 = this.getNumGeometries();
+ var n2 = gc.getNumGeometries();
+ var i = 0;
+ while (i < n1 && i < n2) {
+ var thisGeom = this$1.getGeometryN(i);
+ var otherGeom = gc.getGeometryN(i);
+ var holeComp = thisGeom.compareToSameClass(otherGeom, comp);
+ if (holeComp !== 0) { return holeComp }
+ i++;
+ }
+ if (i < n1) { return 1 }
+ if (i < n2) { return -1 }
+ return 0
+ }
+ };
+ GeometryCollection.prototype.apply = function apply () {
+ var this$1 = this;
+
+ if (hasInterface(arguments[0], CoordinateFilter)) {
+ var filter = arguments[0];
+ for (var i = 0; i < this._geometries.length; i++) {
+ this$1._geometries[i].apply(filter);
+ }
+ } else if (hasInterface(arguments[0], CoordinateSequenceFilter)) {
+ var filter$1 = arguments[0];
+ if (this._geometries.length === 0) { return null }
+ for (var i$1 = 0; i$1 < this._geometries.length; i$1++) {
+ this$1._geometries[i$1].apply(filter$1);
+ if (filter$1.isDone()) {
+ break
+ }
+ }
+ if (filter$1.isGeometryChanged()) { this.geometryChanged(); }
+ } else if (hasInterface(arguments[0], GeometryFilter)) {
+ var filter$2 = arguments[0];
+ filter$2.filter(this);
+ for (var i$2 = 0; i$2 < this._geometries.length; i$2++) {
+ this$1._geometries[i$2].apply(filter$2);
+ }
+ } else if (hasInterface(arguments[0], GeometryComponentFilter)) {
+ var filter$3 = arguments[0];
+ filter$3.filter(this);
+ for (var i$3 = 0; i$3 < this._geometries.length; i$3++) {
+ this$1._geometries[i$3].apply(filter$3);
+ }
+ }
+ };
+ GeometryCollection.prototype.getBoundary = function getBoundary () {
+ this.checkNotGeometryCollection(this);
+ Assert.shouldNeverReachHere();
+ return null
+ };
+ GeometryCollection.prototype.clone = function clone () {
+ var this$1 = this;
+
+ var gc = Geometry$$1.prototype.clone.call(this);
+ gc._geometries = new Array(this._geometries.length).fill(null);
+ for (var i = 0; i < this._geometries.length; i++) {
+ gc._geometries[i] = this$1._geometries[i].clone();
+ }
+ return gc
+ };
+ GeometryCollection.prototype.getGeometryType = function getGeometryType () {
+ return 'GeometryCollection'
+ };
+ GeometryCollection.prototype.copy = function copy () {
+ var this$1 = this;
+
+ var geometries = new Array(this._geometries.length).fill(null);
+ for (var i = 0; i < geometries.length; i++) {
+ geometries[i] = this$1._geometries[i].copy();
+ }
+ return new GeometryCollection(geometries, this._factory)
+ };
+ GeometryCollection.prototype.isEmpty = function isEmpty () {
+ var this$1 = this;
+
+ for (var i = 0; i < this._geometries.length; i++) {
+ if (!this$1._geometries[i].isEmpty()) {
+ return false
+ }
+ }
+ return true
+ };
+ GeometryCollection.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ GeometryCollection.prototype.getClass = function getClass () {
+ return GeometryCollection
+ };
+ staticAccessors.serialVersionUID.get = function () { return -5694727726395021467 };
+
+ Object.defineProperties( GeometryCollection, staticAccessors );
+
+ return GeometryCollection;
+ }(Geometry));
+
+ var MultiLineString = (function (GeometryCollection$$1) {
+ function MultiLineString () {
+ GeometryCollection$$1.apply(this, arguments);
+ }
+
+ if ( GeometryCollection$$1 ) MultiLineString.__proto__ = GeometryCollection$$1;
+ MultiLineString.prototype = Object.create( GeometryCollection$$1 && GeometryCollection$$1.prototype );
+ MultiLineString.prototype.constructor = MultiLineString;
+
+ var staticAccessors = { serialVersionUID: { configurable: true } };
+
+ MultiLineString.prototype.getSortIndex = function getSortIndex () {
+ return Geometry.SORTINDEX_MULTILINESTRING
+ };
+ MultiLineString.prototype.equalsExact = function equalsExact () {
+ if (arguments.length === 2) {
+ var other = arguments[0];
+ var tolerance = arguments[1];
+ if (!this.isEquivalentClass(other)) {
+ return false
+ }
+ return GeometryCollection$$1.prototype.equalsExact.call(this, other, tolerance)
+ } else { return GeometryCollection$$1.prototype.equalsExact.apply(this, arguments) }
+ };
+ MultiLineString.prototype.getBoundaryDimension = function getBoundaryDimension () {
+ if (this.isClosed()) {
+ return Dimension.FALSE
+ }
+ return 0
+ };
+ MultiLineString.prototype.isClosed = function isClosed () {
+ var this$1 = this;
+
+ if (this.isEmpty()) {
+ return false
+ }
+ for (var i = 0; i < this._geometries.length; i++) {
+ if (!this$1._geometries[i].isClosed()) {
+ return false
+ }
+ }
+ return true
+ };
+ MultiLineString.prototype.getDimension = function getDimension () {
+ return 1
+ };
+ MultiLineString.prototype.reverse = function reverse () {
+ var this$1 = this;
+
+ var nLines = this._geometries.length;
+ var revLines = new Array(nLines).fill(null);
+ for (var i = 0; i < this._geometries.length; i++) {
+ revLines[nLines - 1 - i] = this$1._geometries[i].reverse();
+ }
+ return this.getFactory().createMultiLineString(revLines)
+ };
+ MultiLineString.prototype.getBoundary = function getBoundary () {
+ return new BoundaryOp(this).getBoundary()
+ };
+ MultiLineString.prototype.getGeometryType = function getGeometryType () {
+ return 'MultiLineString'
+ };
+ MultiLineString.prototype.copy = function copy () {
+ var this$1 = this;
+
+ var lineStrings = new Array(this._geometries.length).fill(null);
+ for (var i = 0; i < lineStrings.length; i++) {
+ lineStrings[i] = this$1._geometries[i].copy();
+ }
+ return new MultiLineString(lineStrings, this._factory)
+ };
+ MultiLineString.prototype.interfaces_ = function interfaces_ () {
+ return [Lineal]
+ };
+ MultiLineString.prototype.getClass = function getClass () {
+ return MultiLineString
+ };
+ staticAccessors.serialVersionUID.get = function () { return 8166665132445433741 };
+
+ Object.defineProperties( MultiLineString, staticAccessors );
+
+ return MultiLineString;
+ }(GeometryCollection));
+
+ var BoundaryOp = function BoundaryOp () {
+ this._geom = null;
+ this._geomFact = null;
+ this._bnRule = null;
+ this._endpointMap = null;
+ if (arguments.length === 1) {
+ var geom = arguments[0];
+ var bnRule = BoundaryNodeRule.MOD2_BOUNDARY_RULE;
+ this._geom = geom;
+ this._geomFact = geom.getFactory();
+ this._bnRule = bnRule;
+ } else if (arguments.length === 2) {
+ var geom$1 = arguments[0];
+ var bnRule$1 = arguments[1];
+ this._geom = geom$1;
+ this._geomFact = geom$1.getFactory();
+ this._bnRule = bnRule$1;
+ }
+ };
+ BoundaryOp.prototype.boundaryMultiLineString = function boundaryMultiLineString (mLine) {
+ if (this._geom.isEmpty()) {
+ return this.getEmptyMultiPoint()
+ }
+ var bdyPts = this.computeBoundaryCoordinates(mLine);
+ if (bdyPts.length === 1) {
+ return this._geomFact.createPoint(bdyPts[0])
+ }
+ return this._geomFact.createMultiPointFromCoords(bdyPts)
+ };
+ BoundaryOp.prototype.getBoundary = function getBoundary () {
+ if (this._geom instanceof LineString) { return this.boundaryLineString(this._geom) }
+ if (this._geom instanceof MultiLineString) { return this.boundaryMultiLineString(this._geom) }
+ return this._geom.getBoundary()
+ };
+ BoundaryOp.prototype.boundaryLineString = function boundaryLineString (line) {
+ if (this._geom.isEmpty()) {
+ return this.getEmptyMultiPoint()
+ }
+ if (line.isClosed()) {
+ var closedEndpointOnBoundary = this._bnRule.isInBoundary(2);
+ if (closedEndpointOnBoundary) {
+ return line.getStartPoint()
+ } else {
+ return this._geomFact.createMultiPoint()
+ }
+ }
+ return this._geomFact.createMultiPoint([line.getStartPoint(), line.getEndPoint()])
+ };
+ BoundaryOp.prototype.getEmptyMultiPoint = function getEmptyMultiPoint () {
+ return this._geomFact.createMultiPoint()
+ };
+ BoundaryOp.prototype.computeBoundaryCoordinates = function computeBoundaryCoordinates (mLine) {
+ var this$1 = this;
+
+ var bdyPts = new ArrayList();
+ this._endpointMap = new TreeMap();
+ for (var i = 0; i < mLine.getNumGeometries(); i++) {
+ var line = mLine.getGeometryN(i);
+ if (line.getNumPoints() === 0) { continue }
+ this$1.addEndpoint(line.getCoordinateN(0));
+ this$1.addEndpoint(line.getCoordinateN(line.getNumPoints() - 1));
+ }
+ for (var it = this._endpointMap.entrySet().iterator(); it.hasNext();) {
+ var entry = it.next();
+ var counter = entry.getValue();
+ var valence = counter.count;
+ if (this$1._bnRule.isInBoundary(valence)) {
+ bdyPts.add(entry.getKey());
+ }
+ }
+ return CoordinateArrays.toCoordinateArray(bdyPts)
+ };
+ BoundaryOp.prototype.addEndpoint = function addEndpoint (pt) {
+ var counter = this._endpointMap.get(pt);
+ if (counter === null) {
+ counter = new Counter();
+ this._endpointMap.put(pt, counter);
+ }
+ counter.count++;
+ };
+ BoundaryOp.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ BoundaryOp.prototype.getClass = function getClass () {
+ return BoundaryOp
+ };
+ BoundaryOp.getBoundary = function getBoundary () {
+ if (arguments.length === 1) {
+ var g = arguments[0];
+ var bop = new BoundaryOp(g);
+ return bop.getBoundary()
+ } else if (arguments.length === 2) {
+ var g$1 = arguments[0];
+ var bnRule = arguments[1];
+ var bop$1 = new BoundaryOp(g$1, bnRule);
+ return bop$1.getBoundary()
+ }
+ };
+
+ var Counter = function Counter () {
+ this.count = null;
+ };
+ Counter.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ Counter.prototype.getClass = function getClass () {
+ return Counter
+ };
+
+ // boundary
+
+ function PrintStream () {}
+
+ function StringReader () {}
+
+ var DecimalFormat = function DecimalFormat () {};
+
+ function ByteArrayOutputStream () {}
+
+ function IOException () {}
+
+ function LineNumberReader () {}
+
+ var StringUtil = function StringUtil () {};
+
+ var staticAccessors$15 = { NEWLINE: { configurable: true },SIMPLE_ORDINATE_FORMAT: { configurable: true } };
+
+ StringUtil.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ StringUtil.prototype.getClass = function getClass () {
+ return StringUtil
+ };
+ StringUtil.chars = function chars (c, n) {
+ var ch = new Array(n).fill(null);
+ for (var i = 0; i < n; i++) {
+ ch[i] = c;
+ }
+ return String(ch)
+ };
+ StringUtil.getStackTrace = function getStackTrace () {
+ if (arguments.length === 1) {
+ var t = arguments[0];
+ var os = new ByteArrayOutputStream();
+ var ps = new PrintStream(os);
+ t.printStackTrace(ps);
+ return os.toString()
+ } else if (arguments.length === 2) {
+ var t$1 = arguments[0];
+ var depth = arguments[1];
+ var stackTrace = '';
+ var stringReader = new StringReader(StringUtil.getStackTrace(t$1));
+ var lineNumberReader = new LineNumberReader(stringReader);
+ for (var i = 0; i < depth; i++) {
+ try {
+ stackTrace += lineNumberReader.readLine() + StringUtil.NEWLINE;
+ } catch (e) {
+ if (e instanceof IOException) {
+ Assert.shouldNeverReachHere();
+ } else { throw e }
+ } finally {}
+ }
+ return stackTrace
+ }
+ };
+ StringUtil.split = function split (s, separator) {
+ var separatorlen = separator.length;
+ var tokenList = new ArrayList();
+ var tmpString = '' + s;
+ var pos = tmpString.indexOf(separator);
+ while (pos >= 0) {
+ var token = tmpString.substring(0, pos);
+ tokenList.add(token);
+ tmpString = tmpString.substring(pos + separatorlen);
+ pos = tmpString.indexOf(separator);
+ }
+ if (tmpString.length > 0) { tokenList.add(tmpString); }
+ var res = new Array(tokenList.size()).fill(null);
+ for (var i = 0; i < res.length; i++) {
+ res[i] = tokenList.get(i);
+ }
+ return res
+ };
+ StringUtil.toString = function toString () {
+ if (arguments.length === 1) {
+ var d = arguments[0];
+ return StringUtil.SIMPLE_ORDINATE_FORMAT.format(d)
+ }
+ };
+ StringUtil.spaces = function spaces (n) {
+ return StringUtil.chars(' ', n)
+ };
+ staticAccessors$15.NEWLINE.get = function () { return System.getProperty('line.separator') };
+ staticAccessors$15.SIMPLE_ORDINATE_FORMAT.get = function () { return new DecimalFormat('0.#') };
+
+ Object.defineProperties( StringUtil, staticAccessors$15 );
+
+ var CoordinateSequences = function CoordinateSequences () {};
+
+ CoordinateSequences.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ CoordinateSequences.prototype.getClass = function getClass () {
+ return CoordinateSequences
+ };
+ CoordinateSequences.copyCoord = function copyCoord (src, srcPos, dest, destPos) {
+ var minDim = Math.min(src.getDimension(), dest.getDimension());
+ for (var dim = 0; dim < minDim; dim++) {
+ dest.setOrdinate(destPos, dim, src.getOrdinate(srcPos, dim));
+ }
+ };
+ CoordinateSequences.isRing = function isRing (seq) {
+ var n = seq.size();
+ if (n === 0) { return true }
+ if (n <= 3) { return false }
+ return seq.getOrdinate(0, CoordinateSequence.X) === seq.getOrdinate(n - 1, CoordinateSequence.X) && seq.getOrdinate(0, CoordinateSequence.Y) === seq.getOrdinate(n - 1, CoordinateSequence.Y)
+ };
+ CoordinateSequences.isEqual = function isEqual (cs1, cs2) {
+ var cs1Size = cs1.size();
+ var cs2Size = cs2.size();
+ if (cs1Size !== cs2Size) { return false }
+ var dim = Math.min(cs1.getDimension(), cs2.getDimension());
+ for (var i = 0; i < cs1Size; i++) {
+ for (var d = 0; d < dim; d++) {
+ var v1 = cs1.getOrdinate(i, d);
+ var v2 = cs2.getOrdinate(i, d);
+ if (cs1.getOrdinate(i, d) === cs2.getOrdinate(i, d)) { continue }
+ if (Double.isNaN(v1) && Double.isNaN(v2)) { continue }
+ return false
+ }
+ }
+ return true
+ };
+ CoordinateSequences.extend = function extend (fact, seq, size) {
+ var newseq = fact.create(size, seq.getDimension());
+ var n = seq.size();
+ CoordinateSequences.copy(seq, 0, newseq, 0, n);
+ if (n > 0) {
+ for (var i = n; i < size; i++) { CoordinateSequences.copy(seq, n - 1, newseq, i, 1); }
+ }
+ return newseq
+ };
+ CoordinateSequences.reverse = function reverse (seq) {
+ var last = seq.size() - 1;
+ var mid = Math.trunc(last / 2);
+ for (var i = 0; i <= mid; i++) {
+ CoordinateSequences.swap(seq, i, last - i);
+ }
+ };
+ CoordinateSequences.swap = function swap (seq, i, j) {
+ if (i === j) { return null }
+ for (var dim = 0; dim < seq.getDimension(); dim++) {
+ var tmp = seq.getOrdinate(i, dim);
+ seq.setOrdinate(i, dim, seq.getOrdinate(j, dim));
+ seq.setOrdinate(j, dim, tmp);
+ }
+ };
+ CoordinateSequences.copy = function copy (src, srcPos, dest, destPos, length) {
+ for (var i = 0; i < length; i++) {
+ CoordinateSequences.copyCoord(src, srcPos + i, dest, destPos + i);
+ }
+ };
+ CoordinateSequences.toString = function toString () {
+ if (arguments.length === 1) {
+ var cs = arguments[0];
+ var size = cs.size();
+ if (size === 0) { return '()' }
+ var dim = cs.getDimension();
+ var buf = new StringBuffer();
+ buf.append('(');
+ for (var i = 0; i < size; i++) {
+ if (i > 0) { buf.append(' '); }
+ for (var d = 0; d < dim; d++) {
+ if (d > 0) { buf.append(','); }
+ buf.append(StringUtil.toString(cs.getOrdinate(i, d)));
+ }
+ }
+ buf.append(')');
+ return buf.toString()
+ }
+ };
+ CoordinateSequences.ensureValidRing = function ensureValidRing (fact, seq) {
+ var n = seq.size();
+ if (n === 0) { return seq }
+ if (n <= 3) { return CoordinateSequences.createClosedRing(fact, seq, 4) }
+ var isClosed = seq.getOrdinate(0, CoordinateSequence.X) === seq.getOrdinate(n - 1, CoordinateSequence.X) && seq.getOrdinate(0, CoordinateSequence.Y) === seq.getOrdinate(n - 1, CoordinateSequence.Y);
+ if (isClosed) { return seq }
+ return CoordinateSequences.createClosedRing(fact, seq, n + 1)
+ };
+ CoordinateSequences.createClosedRing = function createClosedRing (fact, seq, size) {
+ var newseq = fact.create(size, seq.getDimension());
+ var n = seq.size();
+ CoordinateSequences.copy(seq, 0, newseq, 0, n);
+ for (var i = n; i < size; i++) { CoordinateSequences.copy(seq, 0, newseq, i, 1); }
+ return newseq
+ };
+
+ var LineString = (function (Geometry$$1) {
+ function LineString (points, factory) {
+ Geometry$$1.call(this, factory);
+ this._points = null;
+ this.init(points);
+ }
+
+ if ( Geometry$$1 ) LineString.__proto__ = Geometry$$1;
+ LineString.prototype = Object.create( Geometry$$1 && Geometry$$1.prototype );
+ LineString.prototype.constructor = LineString;
+
+ var staticAccessors = { serialVersionUID: { configurable: true } };
+ LineString.prototype.computeEnvelopeInternal = function computeEnvelopeInternal () {
+ if (this.isEmpty()) {
+ return new Envelope()
+ }
+ return this._points.expandEnvelope(new Envelope())
+ };
+ LineString.prototype.isRing = function isRing () {
+ return this.isClosed() && this.isSimple()
+ };
+ LineString.prototype.getSortIndex = function getSortIndex () {
+ return Geometry$$1.SORTINDEX_LINESTRING
+ };
+ LineString.prototype.getCoordinates = function getCoordinates () {
+ return this._points.toCoordinateArray()
+ };
+ LineString.prototype.equalsExact = function equalsExact () {
+ var this$1 = this;
+
+ if (arguments.length === 2) {
+ var other = arguments[0];
+ var tolerance = arguments[1];
+ if (!this.isEquivalentClass(other)) {
+ return false
+ }
+ var otherLineString = other;
+ if (this._points.size() !== otherLineString._points.size()) {
+ return false
+ }
+ for (var i = 0; i < this._points.size(); i++) {
+ if (!this$1.equal(this$1._points.getCoordinate(i), otherLineString._points.getCoordinate(i), tolerance)) {
+ return false
+ }
+ }
+ return true
+ } else { return Geometry$$1.prototype.equalsExact.apply(this, arguments) }
+ };
+ LineString.prototype.normalize = function normalize () {
+ var this$1 = this;
+
+ for (var i = 0; i < Math.trunc(this._points.size() / 2); i++) {
+ var j = this$1._points.size() - 1 - i;
+ if (!this$1._points.getCoordinate(i).equals(this$1._points.getCoordinate(j))) {
+ if (this$1._points.getCoordinate(i).compareTo(this$1._points.getCoordinate(j)) > 0) {
+ CoordinateSequences.reverse(this$1._points);
+ }
+ return null
+ }
+ }
+ };
+ LineString.prototype.getCoordinate = function getCoordinate () {
+ if (this.isEmpty()) { return null }
+ return this._points.getCoordinate(0)
+ };
+ LineString.prototype.getBoundaryDimension = function getBoundaryDimension () {
+ if (this.isClosed()) {
+ return Dimension.FALSE
+ }
+ return 0
+ };
+ LineString.prototype.isClosed = function isClosed () {
+ if (this.isEmpty()) {
+ return false
+ }
+ return this.getCoordinateN(0).equals2D(this.getCoordinateN(this.getNumPoints() - 1))
+ };
+ LineString.prototype.getEndPoint = function getEndPoint () {
+ if (this.isEmpty()) {
+ return null
+ }
+ return this.getPointN(this.getNumPoints() - 1)
+ };
+ LineString.prototype.getDimension = function getDimension () {
+ return 1
+ };
+ LineString.prototype.getLength = function getLength () {
+ return CGAlgorithms.computeLength(this._points)
+ };
+ LineString.prototype.getNumPoints = function getNumPoints () {
+ return this._points.size()
+ };
+ LineString.prototype.reverse = function reverse () {
+ var seq = this._points.copy();
+ CoordinateSequences.reverse(seq);
+ var revLine = this.getFactory().createLineString(seq);
+ return revLine
+ };
+ LineString.prototype.compareToSameClass = function compareToSameClass () {
+ var this$1 = this;
+
+ if (arguments.length === 1) {
+ var o = arguments[0];
+ var line = o;
+ var i = 0;
+ var j = 0;
+ while (i < this._points.size() && j < line._points.size()) {
+ var comparison = this$1._points.getCoordinate(i).compareTo(line._points.getCoordinate(j));
+ if (comparison !== 0) {
+ return comparison
+ }
+ i++;
+ j++;
+ }
+ if (i < this._points.size()) {
+ return 1
+ }
+ if (j < line._points.size()) {
+ return -1
+ }
+ return 0
+ } else if (arguments.length === 2) {
+ var o$1 = arguments[0];
+ var comp = arguments[1];
+ var line$1 = o$1;
+ return comp.compare(this._points, line$1._points)
+ }
+ };
+ LineString.prototype.apply = function apply () {
+ var this$1 = this;
+
+ if (hasInterface(arguments[0], CoordinateFilter)) {
+ var filter = arguments[0];
+ for (var i = 0; i < this._points.size(); i++) {
+ filter.filter(this$1._points.getCoordinate(i));
+ }
+ } else if (hasInterface(arguments[0], CoordinateSequenceFilter)) {
+ var filter$1 = arguments[0];
+ if (this._points.size() === 0) { return null }
+ for (var i$1 = 0; i$1 < this._points.size(); i$1++) {
+ filter$1.filter(this$1._points, i$1);
+ if (filter$1.isDone()) { break }
+ }
+ if (filter$1.isGeometryChanged()) { this.geometryChanged(); }
+ } else if (hasInterface(arguments[0], GeometryFilter)) {
+ var filter$2 = arguments[0];
+ filter$2.filter(this);
+ } else if (hasInterface(arguments[0], GeometryComponentFilter)) {
+ var filter$3 = arguments[0];
+ filter$3.filter(this);
+ }
+ };
+ LineString.prototype.getBoundary = function getBoundary () {
+ return new BoundaryOp(this).getBoundary()
+ };
+ LineString.prototype.isEquivalentClass = function isEquivalentClass (other) {
+ return other instanceof LineString
+ };
+ LineString.prototype.clone = function clone () {
+ var ls = Geometry$$1.prototype.clone.call(this);
+ ls._points = this._points.clone();
+ return ls
+ };
+ LineString.prototype.getCoordinateN = function getCoordinateN (n) {
+ return this._points.getCoordinate(n)
+ };
+ LineString.prototype.getGeometryType = function getGeometryType () {
+ return 'LineString'
+ };
+ LineString.prototype.copy = function copy () {
+ return new LineString(this._points.copy(), this._factory)
+ };
+ LineString.prototype.getCoordinateSequence = function getCoordinateSequence () {
+ return this._points
+ };
+ LineString.prototype.isEmpty = function isEmpty () {
+ return this._points.size() === 0
+ };
+ LineString.prototype.init = function init (points) {
+ if (points === null) {
+ points = this.getFactory().getCoordinateSequenceFactory().create([]);
+ }
+ if (points.size() === 1) {
+ throw new IllegalArgumentException('Invalid number of points in LineString (found ' + points.size() + ' - must be 0 or >= 2)')
+ }
+ this._points = points;
+ };
+ LineString.prototype.isCoordinate = function isCoordinate (pt) {
+ var this$1 = this;
+
+ for (var i = 0; i < this._points.size(); i++) {
+ if (this$1._points.getCoordinate(i).equals(pt)) {
+ return true
+ }
+ }
+ return false
+ };
+ LineString.prototype.getStartPoint = function getStartPoint () {
+ if (this.isEmpty()) {
+ return null
+ }
+ return this.getPointN(0)
+ };
+ LineString.prototype.getPointN = function getPointN (n) {
+ return this.getFactory().createPoint(this._points.getCoordinate(n))
+ };
+ LineString.prototype.interfaces_ = function interfaces_ () {
+ return [Lineal]
+ };
+ LineString.prototype.getClass = function getClass () {
+ return LineString
+ };
+ staticAccessors.serialVersionUID.get = function () { return 3110669828065365560 };
+
+ Object.defineProperties( LineString, staticAccessors );
+
+ return LineString;
+ }(Geometry));
+
+ var Puntal = function Puntal () {};
+
+ Puntal.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ Puntal.prototype.getClass = function getClass () {
+ return Puntal
+ };
+
+ var Point = (function (Geometry$$1) {
+ function Point (coordinates, factory) {
+ Geometry$$1.call(this, factory);
+ this._coordinates = coordinates || null;
+ this.init(this._coordinates);
+ }
+
+ if ( Geometry$$1 ) Point.__proto__ = Geometry$$1;
+ Point.prototype = Object.create( Geometry$$1 && Geometry$$1.prototype );
+ Point.prototype.constructor = Point;
+
+ var staticAccessors = { serialVersionUID: { configurable: true } };
+ Point.prototype.computeEnvelopeInternal = function computeEnvelopeInternal () {
+ if (this.isEmpty()) {
+ return new Envelope()
+ }
+ var env = new Envelope();
+ env.expandToInclude(this._coordinates.getX(0), this._coordinates.getY(0));
+ return env
+ };
+ Point.prototype.getSortIndex = function getSortIndex () {
+ return Geometry$$1.SORTINDEX_POINT
+ };
+ Point.prototype.getCoordinates = function getCoordinates () {
+ return this.isEmpty() ? [] : [this.getCoordinate()]
+ };
+ Point.prototype.equalsExact = function equalsExact () {
+ if (arguments.length === 2) {
+ var other = arguments[0];
+ var tolerance = arguments[1];
+ if (!this.isEquivalentClass(other)) {
+ return false
+ }
+ if (this.isEmpty() && other.isEmpty()) {
+ return true
+ }
+ if (this.isEmpty() !== other.isEmpty()) {
+ return false
+ }
+ return this.equal(other.getCoordinate(), this.getCoordinate(), tolerance)
+ } else { return Geometry$$1.prototype.equalsExact.apply(this, arguments) }
+ };
+ Point.prototype.normalize = function normalize () {};
+ Point.prototype.getCoordinate = function getCoordinate () {
+ return this._coordinates.size() !== 0 ? this._coordinates.getCoordinate(0) : null
+ };
+ Point.prototype.getBoundaryDimension = function getBoundaryDimension () {
+ return Dimension.FALSE
+ };
+ Point.prototype.getDimension = function getDimension () {
+ return 0
+ };
+ Point.prototype.getNumPoints = function getNumPoints () {
+ return this.isEmpty() ? 0 : 1
+ };
+ Point.prototype.reverse = function reverse () {
+ return this.copy()
+ };
+ Point.prototype.getX = function getX () {
+ if (this.getCoordinate() === null) {
+ throw new Error('getX called on empty Point')
+ }
+ return this.getCoordinate().x
+ };
+ Point.prototype.compareToSameClass = function compareToSameClass () {
+ if (arguments.length === 1) {
+ var other = arguments[0];
+ var point$1 = other;
+ return this.getCoordinate().compareTo(point$1.getCoordinate())
+ } else if (arguments.length === 2) {
+ var other$1 = arguments[0];
+ var comp = arguments[1];
+ var point = other$1;
+ return comp.compare(this._coordinates, point._coordinates)
+ }
+ };
+ Point.prototype.apply = function apply () {
+ if (hasInterface(arguments[0], CoordinateFilter)) {
+ var filter = arguments[0];
+ if (this.isEmpty()) {
+ return null
+ }
+ filter.filter(this.getCoordinate());
+ } else if (hasInterface(arguments[0], CoordinateSequenceFilter)) {
+ var filter$1 = arguments[0];
+ if (this.isEmpty()) { return null }
+ filter$1.filter(this._coordinates, 0);
+ if (filter$1.isGeometryChanged()) { this.geometryChanged(); }
+ } else if (hasInterface(arguments[0], GeometryFilter)) {
+ var filter$2 = arguments[0];
+ filter$2.filter(this);
+ } else if (hasInterface(arguments[0], GeometryComponentFilter)) {
+ var filter$3 = arguments[0];
+ filter$3.filter(this);
+ }
+ };
+ Point.prototype.getBoundary = function getBoundary () {
+ return this.getFactory().createGeometryCollection(null)
+ };
+ Point.prototype.clone = function clone () {
+ var p = Geometry$$1.prototype.clone.call(this);
+ p._coordinates = this._coordinates.clone();
+ return p
+ };
+ Point.prototype.getGeometryType = function getGeometryType () {
+ return 'Point'
+ };
+ Point.prototype.copy = function copy () {
+ return new Point(this._coordinates.copy(), this._factory)
+ };
+ Point.prototype.getCoordinateSequence = function getCoordinateSequence () {
+ return this._coordinates
+ };
+ Point.prototype.getY = function getY () {
+ if (this.getCoordinate() === null) {
+ throw new Error('getY called on empty Point')
+ }
+ return this.getCoordinate().y
+ };
+ Point.prototype.isEmpty = function isEmpty () {
+ return this._coordinates.size() === 0
+ };
+ Point.prototype.init = function init (coordinates) {
+ if (coordinates === null) {
+ coordinates = this.getFactory().getCoordinateSequenceFactory().create([]);
+ }
+ Assert.isTrue(coordinates.size() <= 1);
+ this._coordinates = coordinates;
+ };
+ Point.prototype.isSimple = function isSimple () {
+ return true
+ };
+ Point.prototype.interfaces_ = function interfaces_ () {
+ return [Puntal]
+ };
+ Point.prototype.getClass = function getClass () {
+ return Point
+ };
+ staticAccessors.serialVersionUID.get = function () { return 4902022702746614570 };
+
+ Object.defineProperties( Point, staticAccessors );
+
+ return Point;
+ }(Geometry));
+
+ var Polygonal = function Polygonal () {};
+
+ Polygonal.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ Polygonal.prototype.getClass = function getClass () {
+ return Polygonal
+ };
+
+ var Polygon = (function (Geometry$$1) {
+ function Polygon (shell, holes, factory) {
+ Geometry$$1.call(this, factory);
+ this._shell = null;
+ this._holes = null;
+ if (shell === null) {
+ shell = this.getFactory().createLinearRing();
+ }
+ if (holes === null) {
+ holes = [];
+ }
+ if (Geometry$$1.hasNullElements(holes)) {
+ throw new IllegalArgumentException('holes must not contain null elements')
+ }
+ if (shell.isEmpty() && Geometry$$1.hasNonEmptyElements(holes)) {
+ throw new IllegalArgumentException('shell is empty but holes are not')
+ }
+ this._shell = shell;
+ this._holes = holes;
+ }
+
+ if ( Geometry$$1 ) Polygon.__proto__ = Geometry$$1;
+ Polygon.prototype = Object.create( Geometry$$1 && Geometry$$1.prototype );
+ Polygon.prototype.constructor = Polygon;
+
+ var staticAccessors = { serialVersionUID: { configurable: true } };
+ Polygon.prototype.computeEnvelopeInternal = function computeEnvelopeInternal () {
+ return this._shell.getEnvelopeInternal()
+ };
+ Polygon.prototype.getSortIndex = function getSortIndex () {
+ return Geometry$$1.SORTINDEX_POLYGON
+ };
+ Polygon.prototype.getCoordinates = function getCoordinates () {
+ var this$1 = this;
+
+ if (this.isEmpty()) {
+ return []
+ }
+ var coordinates = new Array(this.getNumPoints()).fill(null);
+ var k = -1;
+ var shellCoordinates = this._shell.getCoordinates();
+ for (var x = 0; x < shellCoordinates.length; x++) {
+ k++;
+ coordinates[k] = shellCoordinates[x];
+ }
+ for (var i = 0; i < this._holes.length; i++) {
+ var childCoordinates = this$1._holes[i].getCoordinates();
+ for (var j = 0; j < childCoordinates.length; j++) {
+ k++;
+ coordinates[k] = childCoordinates[j];
+ }
+ }
+ return coordinates
+ };
+ Polygon.prototype.getArea = function getArea () {
+ var this$1 = this;
+
+ var area = 0.0;
+ area += Math.abs(CGAlgorithms.signedArea(this._shell.getCoordinateSequence()));
+ for (var i = 0; i < this._holes.length; i++) {
+ area -= Math.abs(CGAlgorithms.signedArea(this$1._holes[i].getCoordinateSequence()));
+ }
+ return area
+ };
+ Polygon.prototype.isRectangle = function isRectangle () {
+ if (this.getNumInteriorRing() !== 0) { return false }
+ if (this._shell === null) { return false }
+ if (this._shell.getNumPoints() !== 5) { return false }
+ var seq = this._shell.getCoordinateSequence();
+ var env = this.getEnvelopeInternal();
+ for (var i = 0; i < 5; i++) {
+ var x = seq.getX(i);
+ if (!(x === env.getMinX() || x === env.getMaxX())) { return false }
+ var y = seq.getY(i);
+ if (!(y === env.getMinY() || y === env.getMaxY())) { return false }
+ }
+ var prevX = seq.getX(0);
+ var prevY = seq.getY(0);
+ for (var i$1 = 1; i$1 <= 4; i$1++) {
+ var x$1 = seq.getX(i$1);
+ var y$1 = seq.getY(i$1);
+ var xChanged = x$1 !== prevX;
+ var yChanged = y$1 !== prevY;
+ if (xChanged === yChanged) { return false }
+ prevX = x$1;
+ prevY = y$1;
+ }
+ return true
+ };
+ Polygon.prototype.equalsExact = function equalsExact () {
+ var this$1 = this;
+
+ if (arguments.length === 2) {
+ var other = arguments[0];
+ var tolerance = arguments[1];
+ if (!this.isEquivalentClass(other)) {
+ return false
+ }
+ var otherPolygon = other;
+ var thisShell = this._shell;
+ var otherPolygonShell = otherPolygon._shell;
+ if (!thisShell.equalsExact(otherPolygonShell, tolerance)) {
+ return false
+ }
+ if (this._holes.length !== otherPolygon._holes.length) {
+ return false
+ }
+ for (var i = 0; i < this._holes.length; i++) {
+ if (!this$1._holes[i].equalsExact(otherPolygon._holes[i], tolerance)) {
+ return false
+ }
+ }
+ return true
+ } else { return Geometry$$1.prototype.equalsExact.apply(this, arguments) }
+ };
+ Polygon.prototype.normalize = function normalize () {
+ var this$1 = this;
+
+ if (arguments.length === 0) {
+ this.normalize(this._shell, true);
+ for (var i = 0; i < this._holes.length; i++) {
+ this$1.normalize(this$1._holes[i], false);
+ }
+ Arrays.sort(this._holes);
+ } else if (arguments.length === 2) {
+ var ring = arguments[0];
+ var clockwise = arguments[1];
+ if (ring.isEmpty()) {
+ return null
+ }
+ var uniqueCoordinates = new Array(ring.getCoordinates().length - 1).fill(null);
+ System.arraycopy(ring.getCoordinates(), 0, uniqueCoordinates, 0, uniqueCoordinates.length);
+ var minCoordinate = CoordinateArrays.minCoordinate(ring.getCoordinates());
+ CoordinateArrays.scroll(uniqueCoordinates, minCoordinate);
+ System.arraycopy(uniqueCoordinates, 0, ring.getCoordinates(), 0, uniqueCoordinates.length);
+ ring.getCoordinates()[uniqueCoordinates.length] = uniqueCoordinates[0];
+ if (CGAlgorithms.isCCW(ring.getCoordinates()) === clockwise) {
+ CoordinateArrays.reverse(ring.getCoordinates());
+ }
+ }
+ };
+ Polygon.prototype.getCoordinate = function getCoordinate () {
+ return this._shell.getCoordinate()
+ };
+ Polygon.prototype.getNumInteriorRing = function getNumInteriorRing () {
+ return this._holes.length
+ };
+ Polygon.prototype.getBoundaryDimension = function getBoundaryDimension () {
+ return 1
+ };
+ Polygon.prototype.getDimension = function getDimension () {
+ return 2
+ };
+ Polygon.prototype.getLength = function getLength () {
+ var this$1 = this;
+
+ var len = 0.0;
+ len += this._shell.getLength();
+ for (var i = 0; i < this._holes.length; i++) {
+ len += this$1._holes[i].getLength();
+ }
+ return len
+ };
+ Polygon.prototype.getNumPoints = function getNumPoints () {
+ var this$1 = this;
+
+ var numPoints = this._shell.getNumPoints();
+ for (var i = 0; i < this._holes.length; i++) {
+ numPoints += this$1._holes[i].getNumPoints();
+ }
+ return numPoints
+ };
+ Polygon.prototype.reverse = function reverse () {
+ var this$1 = this;
+
+ var poly = this.copy();
+ poly._shell = this._shell.copy().reverse();
+ poly._holes = new Array(this._holes.length).fill(null);
+ for (var i = 0; i < this._holes.length; i++) {
+ poly._holes[i] = this$1._holes[i].copy().reverse();
+ }
+ return poly
+ };
+ Polygon.prototype.convexHull = function convexHull () {
+ return this.getExteriorRing().convexHull()
+ };
+ Polygon.prototype.compareToSameClass = function compareToSameClass () {
+ var this$1 = this;
+
+ if (arguments.length === 1) {
+ var o = arguments[0];
+ var thisShell = this._shell;
+ var otherShell = o._shell;
+ return thisShell.compareToSameClass(otherShell)
+ } else if (arguments.length === 2) {
+ var o$1 = arguments[0];
+ var comp = arguments[1];
+ var poly = o$1;
+ var thisShell$1 = this._shell;
+ var otherShell$1 = poly._shell;
+ var shellComp = thisShell$1.compareToSameClass(otherShell$1, comp);
+ if (shellComp !== 0) { return shellComp }
+ var nHole1 = this.getNumInteriorRing();
+ var nHole2 = poly.getNumInteriorRing();
+ var i = 0;
+ while (i < nHole1 && i < nHole2) {
+ var thisHole = this$1.getInteriorRingN(i);
+ var otherHole = poly.getInteriorRingN(i);
+ var holeComp = thisHole.compareToSameClass(otherHole, comp);
+ if (holeComp !== 0) { return holeComp }
+ i++;
+ }
+ if (i < nHole1) { return 1 }
+ if (i < nHole2) { return -1 }
+ return 0
+ }
+ };
+ Polygon.prototype.apply = function apply (filter) {
+ var this$1 = this;
+
+ if (hasInterface(filter, CoordinateFilter)) {
+ this._shell.apply(filter);
+ for (var i$1 = 0; i$1 < this._holes.length; i$1++) {
+ this$1._holes[i$1].apply(filter);
+ }
+ } else if (hasInterface(filter, CoordinateSequenceFilter)) {
+ this._shell.apply(filter);
+ if (!filter.isDone()) {
+ for (var i$2 = 0; i$2 < this._holes.length; i$2++) {
+ this$1._holes[i$2].apply(filter);
+ if (filter.isDone()) { break }
+ }
+ }
+ if (filter.isGeometryChanged()) { this.geometryChanged(); }
+ } else if (hasInterface(filter, GeometryFilter)) {
+ filter.filter(this);
+ } else if (hasInterface(filter, GeometryComponentFilter)) {
+ filter.filter(this);
+ this._shell.apply(filter);
+ for (var i = 0; i < this._holes.length; i++) {
+ this$1._holes[i].apply(filter);
+ }
+ }
+ };
+ Polygon.prototype.getBoundary = function getBoundary () {
+ var this$1 = this;
+
+ if (this.isEmpty()) {
+ return this.getFactory().createMultiLineString()
+ }
+ var rings = new Array(this._holes.length + 1).fill(null);
+ rings[0] = this._shell;
+ for (var i = 0; i < this._holes.length; i++) {
+ rings[i + 1] = this$1._holes[i];
+ }
+ if (rings.length <= 1) { return this.getFactory().createLinearRing(rings[0].getCoordinateSequence()) }
+ return this.getFactory().createMultiLineString(rings)
+ };
+ Polygon.prototype.clone = function clone () {
+ var this$1 = this;
+
+ var poly = Geometry$$1.prototype.clone.call(this);
+ poly._shell = this._shell.clone();
+ poly._holes = new Array(this._holes.length).fill(null);
+ for (var i = 0; i < this._holes.length; i++) {
+ poly._holes[i] = this$1._holes[i].clone();
+ }
+ return poly
+ };
+ Polygon.prototype.getGeometryType = function getGeometryType () {
+ return 'Polygon'
+ };
+ Polygon.prototype.copy = function copy () {
+ var this$1 = this;
+
+ var shell = this._shell.copy();
+ var holes = new Array(this._holes.length).fill(null);
+ for (var i = 0; i < holes.length; i++) {
+ holes[i] = this$1._holes[i].copy();
+ }
+ return new Polygon(shell, holes, this._factory)
+ };
+ Polygon.prototype.getExteriorRing = function getExteriorRing () {
+ return this._shell
+ };
+ Polygon.prototype.isEmpty = function isEmpty () {
+ return this._shell.isEmpty()
+ };
+ Polygon.prototype.getInteriorRingN = function getInteriorRingN (n) {
+ return this._holes[n]
+ };
+ Polygon.prototype.interfaces_ = function interfaces_ () {
+ return [Polygonal]
+ };
+ Polygon.prototype.getClass = function getClass () {
+ return Polygon
+ };
+ staticAccessors.serialVersionUID.get = function () { return -3494792200821764533 };
+
+ Object.defineProperties( Polygon, staticAccessors );
+
+ return Polygon;
+ }(Geometry));
+
+ var MultiPoint = (function (GeometryCollection$$1) {
+ function MultiPoint () {
+ GeometryCollection$$1.apply(this, arguments);
+ }
+
+ if ( GeometryCollection$$1 ) MultiPoint.__proto__ = GeometryCollection$$1;
+ MultiPoint.prototype = Object.create( GeometryCollection$$1 && GeometryCollection$$1.prototype );
+ MultiPoint.prototype.constructor = MultiPoint;
+
+ var staticAccessors = { serialVersionUID: { configurable: true } };
+
+ MultiPoint.prototype.getSortIndex = function getSortIndex () {
+ return Geometry.SORTINDEX_MULTIPOINT
+ };
+ MultiPoint.prototype.isValid = function isValid () {
+ return true
+ };
+ MultiPoint.prototype.equalsExact = function equalsExact () {
+ if (arguments.length === 2) {
+ var other = arguments[0];
+ var tolerance = arguments[1];
+ if (!this.isEquivalentClass(other)) {
+ return false
+ }
+ return GeometryCollection$$1.prototype.equalsExact.call(this, other, tolerance)
+ } else { return GeometryCollection$$1.prototype.equalsExact.apply(this, arguments) }
+ };
+ MultiPoint.prototype.getCoordinate = function getCoordinate () {
+ if (arguments.length === 1) {
+ var n = arguments[0];
+ return this._geometries[n].getCoordinate()
+ } else { return GeometryCollection$$1.prototype.getCoordinate.apply(this, arguments) }
+ };
+ MultiPoint.prototype.getBoundaryDimension = function getBoundaryDimension () {
+ return Dimension.FALSE
+ };
+ MultiPoint.prototype.getDimension = function getDimension () {
+ return 0
+ };
+ MultiPoint.prototype.getBoundary = function getBoundary () {
+ return this.getFactory().createGeometryCollection(null)
+ };
+ MultiPoint.prototype.getGeometryType = function getGeometryType () {
+ return 'MultiPoint'
+ };
+ MultiPoint.prototype.copy = function copy () {
+ var this$1 = this;
+
+ var points = new Array(this._geometries.length).fill(null);
+ for (var i = 0; i < points.length; i++) {
+ points[i] = this$1._geometries[i].copy();
+ }
+ return new MultiPoint(points, this._factory)
+ };
+ MultiPoint.prototype.interfaces_ = function interfaces_ () {
+ return [Puntal]
+ };
+ MultiPoint.prototype.getClass = function getClass () {
+ return MultiPoint
+ };
+ staticAccessors.serialVersionUID.get = function () { return -8048474874175355449 };
+
+ Object.defineProperties( MultiPoint, staticAccessors );
+
+ return MultiPoint;
+ }(GeometryCollection));
+
+ var LinearRing = (function (LineString$$1) {
+ function LinearRing (points, factory) {
+ if (points instanceof Coordinate && factory instanceof GeometryFactory) {
+ points = factory.getCoordinateSequenceFactory().create(points);
+ }
+ LineString$$1.call(this, points, factory);
+ this.validateConstruction();
+ }
+
+ if ( LineString$$1 ) LinearRing.__proto__ = LineString$$1;
+ LinearRing.prototype = Object.create( LineString$$1 && LineString$$1.prototype );
+ LinearRing.prototype.constructor = LinearRing;
+
+ var staticAccessors = { MINIMUM_VALID_SIZE: { configurable: true },serialVersionUID: { configurable: true } };
+ LinearRing.prototype.getSortIndex = function getSortIndex () {
+ return Geometry.SORTINDEX_LINEARRING
+ };
+ LinearRing.prototype.getBoundaryDimension = function getBoundaryDimension () {
+ return Dimension.FALSE
+ };
+ LinearRing.prototype.isClosed = function isClosed () {
+ if (this.isEmpty()) {
+ return true
+ }
+ return LineString$$1.prototype.isClosed.call(this)
+ };
+ LinearRing.prototype.reverse = function reverse () {
+ var seq = this._points.copy();
+ CoordinateSequences.reverse(seq);
+ var rev = this.getFactory().createLinearRing(seq);
+ return rev
+ };
+ LinearRing.prototype.validateConstruction = function validateConstruction () {
+ if (!this.isEmpty() && !LineString$$1.prototype.isClosed.call(this)) {
+ throw new IllegalArgumentException('Points of LinearRing do not form a closed linestring')
+ }
+ if (this.getCoordinateSequence().size() >= 1 && this.getCoordinateSequence().size() < LinearRing.MINIMUM_VALID_SIZE) {
+ throw new IllegalArgumentException('Invalid number of points in LinearRing (found ' + this.getCoordinateSequence().size() + ' - must be 0 or >= 4)')
+ }
+ };
+ LinearRing.prototype.getGeometryType = function getGeometryType () {
+ return 'LinearRing'
+ };
+ LinearRing.prototype.copy = function copy () {
+ return new LinearRing(this._points.copy(), this._factory)
+ };
+ LinearRing.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ LinearRing.prototype.getClass = function getClass () {
+ return LinearRing
+ };
+ staticAccessors.MINIMUM_VALID_SIZE.get = function () { return 4 };
+ staticAccessors.serialVersionUID.get = function () { return -4261142084085851829 };
+
+ Object.defineProperties( LinearRing, staticAccessors );
+
+ return LinearRing;
+ }(LineString));
+
+ var MultiPolygon = (function (GeometryCollection$$1) {
+ function MultiPolygon () {
+ GeometryCollection$$1.apply(this, arguments);
+ }
+
+ if ( GeometryCollection$$1 ) MultiPolygon.__proto__ = GeometryCollection$$1;
+ MultiPolygon.prototype = Object.create( GeometryCollection$$1 && GeometryCollection$$1.prototype );
+ MultiPolygon.prototype.constructor = MultiPolygon;
+
+ var staticAccessors = { serialVersionUID: { configurable: true } };
+
+ MultiPolygon.prototype.getSortIndex = function getSortIndex () {
+ return Geometry.SORTINDEX_MULTIPOLYGON
+ };
+ MultiPolygon.prototype.equalsExact = function equalsExact () {
+ if (arguments.length === 2) {
+ var other = arguments[0];
+ var tolerance = arguments[1];
+ if (!this.isEquivalentClass(other)) {
+ return false
+ }
+ return GeometryCollection$$1.prototype.equalsExact.call(this, other, tolerance)
+ } else { return GeometryCollection$$1.prototype.equalsExact.apply(this, arguments) }
+ };
+ MultiPolygon.prototype.getBoundaryDimension = function getBoundaryDimension () {
+ return 1
+ };
+ MultiPolygon.prototype.getDimension = function getDimension () {
+ return 2
+ };
+ MultiPolygon.prototype.reverse = function reverse () {
+ var this$1 = this;
+
+ var n = this._geometries.length;
+ var revGeoms = new Array(n).fill(null);
+ for (var i = 0; i < this._geometries.length; i++) {
+ revGeoms[i] = this$1._geometries[i].reverse();
+ }
+ return this.getFactory().createMultiPolygon(revGeoms)
+ };
+ MultiPolygon.prototype.getBoundary = function getBoundary () {
+ var this$1 = this;
+
+ if (this.isEmpty()) {
+ return this.getFactory().createMultiLineString()
+ }
+ var allRings = new ArrayList();
+ for (var i = 0; i < this._geometries.length; i++) {
+ var polygon = this$1._geometries[i];
+ var rings = polygon.getBoundary();
+ for (var j = 0; j < rings.getNumGeometries(); j++) {
+ allRings.add(rings.getGeometryN(j));
+ }
+ }
+ var allRingsArray = new Array(allRings.size()).fill(null);
+ return this.getFactory().createMultiLineString(allRings.toArray(allRingsArray))
+ };
+ MultiPolygon.prototype.getGeometryType = function getGeometryType () {
+ return 'MultiPolygon'
+ };
+ MultiPolygon.prototype.copy = function copy () {
+ var this$1 = this;
+
+ var polygons = new Array(this._geometries.length).fill(null);
+ for (var i = 0; i < polygons.length; i++) {
+ polygons[i] = this$1._geometries[i].copy();
+ }
+ return new MultiPolygon(polygons, this._factory)
+ };
+ MultiPolygon.prototype.interfaces_ = function interfaces_ () {
+ return [Polygonal]
+ };
+ MultiPolygon.prototype.getClass = function getClass () {
+ return MultiPolygon
+ };
+ staticAccessors.serialVersionUID.get = function () { return -551033529766975875 };
+
+ Object.defineProperties( MultiPolygon, staticAccessors );
+
+ return MultiPolygon;
+ }(GeometryCollection));
+
+ var GeometryEditor = function GeometryEditor (factory) {
+ this._factory = factory || null;
+ this._isUserDataCopied = false;
+ };
+
+ var staticAccessors$16 = { NoOpGeometryOperation: { configurable: true },CoordinateOperation: { configurable: true },CoordinateSequenceOperation: { configurable: true } };
+ GeometryEditor.prototype.setCopyUserData = function setCopyUserData (isUserDataCopied) {
+ this._isUserDataCopied = isUserDataCopied;
+ };
+ GeometryEditor.prototype.edit = function edit (geometry, operation) {
+ if (geometry === null) { return null }
+ var result = this.editInternal(geometry, operation);
+ if (this._isUserDataCopied) {
+ result.setUserData(geometry.getUserData());
+ }
+ return result
+ };
+ GeometryEditor.prototype.editInternal = function editInternal (geometry, operation) {
+ if (this._factory === null) { this._factory = geometry.getFactory(); }
+ if (geometry instanceof GeometryCollection) {
+ return this.editGeometryCollection(geometry, operation)
+ }
+ if (geometry instanceof Polygon) {
+ return this.editPolygon(geometry, operation)
+ }
+ if (geometry instanceof Point) {
+ return operation.edit(geometry, this._factory)
+ }
+ if (geometry instanceof LineString) {
+ return operation.edit(geometry, this._factory)
+ }
+ Assert.shouldNeverReachHere('Unsupported Geometry class: ' + geometry.getClass().getName());
+ return null
+ };
+ GeometryEditor.prototype.editGeometryCollection = function editGeometryCollection (collection, operation) {
+ var this$1 = this;
+
+ var collectionForType = operation.edit(collection, this._factory);
+ var geometries = new ArrayList();
+ for (var i = 0; i < collectionForType.getNumGeometries(); i++) {
+ var geometry = this$1.edit(collectionForType.getGeometryN(i), operation);
+ if (geometry === null || geometry.isEmpty()) {
+ continue
+ }
+ geometries.add(geometry);
+ }
+ if (collectionForType.getClass() === MultiPoint) {
+ return this._factory.createMultiPoint(geometries.toArray([]))
+ }
+ if (collectionForType.getClass() === MultiLineString) {
+ return this._factory.createMultiLineString(geometries.toArray([]))
+ }
+ if (collectionForType.getClass() === MultiPolygon) {
+ return this._factory.createMultiPolygon(geometries.toArray([]))
+ }
+ return this._factory.createGeometryCollection(geometries.toArray([]))
+ };
+ GeometryEditor.prototype.editPolygon = function editPolygon (polygon, operation) {
+ var this$1 = this;
+
+ var newPolygon = operation.edit(polygon, this._factory);
+ if (newPolygon === null) { newPolygon = this._factory.createPolygon(null); }
+ if (newPolygon.isEmpty()) {
+ return newPolygon
+ }
+ var shell = this.edit(newPolygon.getExteriorRing(), operation);
+ if (shell === null || shell.isEmpty()) {
+ return this._factory.createPolygon()
+ }
+ var holes = new ArrayList();
+ for (var i = 0; i < newPolygon.getNumInteriorRing(); i++) {
+ var hole = this$1.edit(newPolygon.getInteriorRingN(i), operation);
+ if (hole === null || hole.isEmpty()) {
+ continue
+ }
+ holes.add(hole);
+ }
+ return this._factory.createPolygon(shell, holes.toArray([]))
+ };
+ GeometryEditor.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ GeometryEditor.prototype.getClass = function getClass () {
+ return GeometryEditor
+ };
+ GeometryEditor.GeometryEditorOperation = function GeometryEditorOperation () {};
+ staticAccessors$16.NoOpGeometryOperation.get = function () { return NoOpGeometryOperation };
+ staticAccessors$16.CoordinateOperation.get = function () { return CoordinateOperation };
+ staticAccessors$16.CoordinateSequenceOperation.get = function () { return CoordinateSequenceOperation };
+
+ Object.defineProperties( GeometryEditor, staticAccessors$16 );
+
+ var NoOpGeometryOperation = function NoOpGeometryOperation () {};
+
+ NoOpGeometryOperation.prototype.edit = function edit (geometry, factory) {
+ return geometry
+ };
+ NoOpGeometryOperation.prototype.interfaces_ = function interfaces_ () {
+ return [GeometryEditor.GeometryEditorOperation]
+ };
+ NoOpGeometryOperation.prototype.getClass = function getClass () {
+ return NoOpGeometryOperation
+ };
+
+ var CoordinateOperation = function CoordinateOperation () {};
+
+ CoordinateOperation.prototype.edit = function edit (geometry, factory) {
+ var coords = this.editCoordinates(geometry.getCoordinates(), geometry);
+ if (coords === null) { return geometry }
+ if (geometry instanceof LinearRing) {
+ return factory.createLinearRing(coords)
+ }
+ if (geometry instanceof LineString) {
+ return factory.createLineString(coords)
+ }
+ if (geometry instanceof Point) {
+ if (coords.length > 0) {
+ return factory.createPoint(coords[0])
+ } else {
+ return factory.createPoint()
+ }
+ }
+ return geometry
+ };
+ CoordinateOperation.prototype.interfaces_ = function interfaces_ () {
+ return [GeometryEditor.GeometryEditorOperation]
+ };
+ CoordinateOperation.prototype.getClass = function getClass () {
+ return CoordinateOperation
+ };
+
+ var CoordinateSequenceOperation = function CoordinateSequenceOperation () {};
+
+ CoordinateSequenceOperation.prototype.edit = function edit (geometry, factory) {
+ if (geometry instanceof LinearRing) {
+ return factory.createLinearRing(this.edit(geometry.getCoordinateSequence(), geometry))
+ }
+ if (geometry instanceof LineString) {
+ return factory.createLineString(this.edit(geometry.getCoordinateSequence(), geometry))
+ }
+ if (geometry instanceof Point) {
+ return factory.createPoint(this.edit(geometry.getCoordinateSequence(), geometry))
+ }
+ return geometry
+ };
+ CoordinateSequenceOperation.prototype.interfaces_ = function interfaces_ () {
+ return [GeometryEditor.GeometryEditorOperation]
+ };
+ CoordinateSequenceOperation.prototype.getClass = function getClass () {
+ return CoordinateSequenceOperation
+ };
+
+ var CoordinateArraySequence = function CoordinateArraySequence () {
+ var this$1 = this;
+
+ this._dimension = 3;
+ this._coordinates = null;
+ if (arguments.length === 1) {
+ if (arguments[0] instanceof Array) {
+ this._coordinates = arguments[0];
+ this._dimension = 3;
+ } else if (Number.isInteger(arguments[0])) {
+ var size = arguments[0];
+ this._coordinates = new Array(size).fill(null);
+ for (var i = 0; i < size; i++) {
+ this$1._coordinates[i] = new Coordinate();
+ }
+ } else if (hasInterface(arguments[0], CoordinateSequence)) {
+ var coordSeq = arguments[0];
+ if (coordSeq === null) {
+ this._coordinates = new Array(0).fill(null);
+ return null
+ }
+ this._dimension = coordSeq.getDimension();
+ this._coordinates = new Array(coordSeq.size()).fill(null);
+ for (var i$1 = 0; i$1 < this._coordinates.length; i$1++) {
+ this$1._coordinates[i$1] = coordSeq.getCoordinateCopy(i$1);
+ }
+ }
+ } else if (arguments.length === 2) {
+ if (arguments[0] instanceof Array && Number.isInteger(arguments[1])) {
+ var coordinates = arguments[0];
+ var dimension = arguments[1];
+ this._coordinates = coordinates;
+ this._dimension = dimension;
+ if (coordinates === null) { this._coordinates = new Array(0).fill(null); }
+ } else if (Number.isInteger(arguments[0]) && Number.isInteger(arguments[1])) {
+ var size$1 = arguments[0];
+ var dimension$1 = arguments[1];
+ this._coordinates = new Array(size$1).fill(null);
+ this._dimension = dimension$1;
+ for (var i$2 = 0; i$2 < size$1; i$2++) {
+ this$1._coordinates[i$2] = new Coordinate();
+ }
+ }
+ }
+ };
+
+ var staticAccessors$18 = { serialVersionUID: { configurable: true } };
+ CoordinateArraySequence.prototype.setOrdinate = function setOrdinate (index, ordinateIndex, value) {
+ switch (ordinateIndex) {
+ case CoordinateSequence.X:
+ this._coordinates[index].x = value;
+ break
+ case CoordinateSequence.Y:
+ this._coordinates[index].y = value;
+ break
+ case CoordinateSequence.Z:
+ this._coordinates[index].z = value;
+ break
+ default:
+ throw new IllegalArgumentException('invalid ordinateIndex')
+ }
+ };
+ CoordinateArraySequence.prototype.size = function size () {
+ return this._coordinates.length
+ };
+ CoordinateArraySequence.prototype.getOrdinate = function getOrdinate (index, ordinateIndex) {
+ switch (ordinateIndex) {
+ case CoordinateSequence.X:
+ return this._coordinates[index].x
+ case CoordinateSequence.Y:
+ return this._coordinates[index].y
+ case CoordinateSequence.Z:
+ return this._coordinates[index].z
+ }
+ return Double.NaN
+ };
+ CoordinateArraySequence.prototype.getCoordinate = function getCoordinate () {
+ if (arguments.length === 1) {
+ var i = arguments[0];
+ return this._coordinates[i]
+ } else if (arguments.length === 2) {
+ var index = arguments[0];
+ var coord = arguments[1];
+ coord.x = this._coordinates[index].x;
+ coord.y = this._coordinates[index].y;
+ coord.z = this._coordinates[index].z;
+ }
+ };
+ CoordinateArraySequence.prototype.getCoordinateCopy = function getCoordinateCopy (i) {
+ return new Coordinate(this._coordinates[i])
+ };
+ CoordinateArraySequence.prototype.getDimension = function getDimension () {
+ return this._dimension
+ };
+ CoordinateArraySequence.prototype.getX = function getX (index) {
+ return this._coordinates[index].x
+ };
+ CoordinateArraySequence.prototype.clone = function clone () {
+ var this$1 = this;
+
+ var cloneCoordinates = new Array(this.size()).fill(null);
+ for (var i = 0; i < this._coordinates.length; i++) {
+ cloneCoordinates[i] = this$1._coordinates[i].clone();
+ }
+ return new CoordinateArraySequence(cloneCoordinates, this._dimension)
+ };
+ CoordinateArraySequence.prototype.expandEnvelope = function expandEnvelope (env) {
+ var this$1 = this;
+
+ for (var i = 0; i < this._coordinates.length; i++) {
+ env.expandToInclude(this$1._coordinates[i]);
+ }
+ return env
+ };
+ CoordinateArraySequence.prototype.copy = function copy () {
+ var this$1 = this;
+
+ var cloneCoordinates = new Array(this.size()).fill(null);
+ for (var i = 0; i < this._coordinates.length; i++) {
+ cloneCoordinates[i] = this$1._coordinates[i].copy();
+ }
+ return new CoordinateArraySequence(cloneCoordinates, this._dimension)
+ };
+ CoordinateArraySequence.prototype.toString = function toString () {
+ var this$1 = this;
+
+ if (this._coordinates.length > 0) {
+ var strBuf = new StringBuffer(17 * this._coordinates.length);
+ strBuf.append('(');
+ strBuf.append(this._coordinates[0]);
+ for (var i = 1; i < this._coordinates.length; i++) {
+ strBuf.append(', ');
+ strBuf.append(this$1._coordinates[i]);
+ }
+ strBuf.append(')');
+ return strBuf.toString()
+ } else {
+ return '()'
+ }
+ };
+ CoordinateArraySequence.prototype.getY = function getY (index) {
+ return this._coordinates[index].y
+ };
+ CoordinateArraySequence.prototype.toCoordinateArray = function toCoordinateArray () {
+ return this._coordinates
+ };
+ CoordinateArraySequence.prototype.interfaces_ = function interfaces_ () {
+ return [CoordinateSequence, Serializable]
+ };
+ CoordinateArraySequence.prototype.getClass = function getClass () {
+ return CoordinateArraySequence
+ };
+ staticAccessors$18.serialVersionUID.get = function () { return -915438501601840650 };
+
+ Object.defineProperties( CoordinateArraySequence, staticAccessors$18 );
+
+ var CoordinateArraySequenceFactory = function CoordinateArraySequenceFactory () {};
+
+ var staticAccessors$17 = { serialVersionUID: { configurable: true },instanceObject: { configurable: true } };
+
+ CoordinateArraySequenceFactory.prototype.readResolve = function readResolve () {
+ return CoordinateArraySequenceFactory.instance()
+ };
+ CoordinateArraySequenceFactory.prototype.create = function create () {
+ if (arguments.length === 1) {
+ if (arguments[0] instanceof Array) {
+ var coordinates = arguments[0];
+ return new CoordinateArraySequence(coordinates)
+ } else if (hasInterface(arguments[0], CoordinateSequence)) {
+ var coordSeq = arguments[0];
+ return new CoordinateArraySequence(coordSeq)
+ }
+ } else if (arguments.length === 2) {
+ var size = arguments[0];
+ var dimension = arguments[1];
+ if (dimension > 3) { dimension = 3; }
+ if (dimension < 2) { return new CoordinateArraySequence(size) }
+ return new CoordinateArraySequence(size, dimension)
+ }
+ };
+ CoordinateArraySequenceFactory.prototype.interfaces_ = function interfaces_ () {
+ return [CoordinateSequenceFactory, Serializable]
+ };
+ CoordinateArraySequenceFactory.prototype.getClass = function getClass () {
+ return CoordinateArraySequenceFactory
+ };
+ CoordinateArraySequenceFactory.instance = function instance () {
+ return CoordinateArraySequenceFactory.instanceObject
+ };
+
+ staticAccessors$17.serialVersionUID.get = function () { return -4099577099607551657 };
+ staticAccessors$17.instanceObject.get = function () { return new CoordinateArraySequenceFactory() };
+
+ Object.defineProperties( CoordinateArraySequenceFactory, staticAccessors$17 );
+
+ /**
+ * @see http://download.oracle.com/javase/6/docs/api/java/util/HashMap.html
+ *
+ * @extends {javascript.util.Map}
+ * @constructor
+ * @private
+ */
+ var HashMap = (function (MapInterface) {
+ function HashMap () {
+ MapInterface.call(this);
+ this.map_ = new Map();
+ }
+
+ if ( MapInterface ) HashMap.__proto__ = MapInterface;
+ HashMap.prototype = Object.create( MapInterface && MapInterface.prototype );
+ HashMap.prototype.constructor = HashMap;
+ /**
+ * @override
+ */
+ HashMap.prototype.get = function get (key) {
+ return this.map_.get(key) || null
+ };
+
+ /**
+ * @override
+ */
+ HashMap.prototype.put = function put (key, value) {
+ this.map_.set(key, value);
+ return value
+ };
+
+ /**
+ * @override
+ */
+ HashMap.prototype.values = function values () {
+ var arrayList = new ArrayList();
+ var it = this.map_.values();
+ var o = it.next();
+ while (!o.done) {
+ arrayList.add(o.value);
+ o = it.next();
+ }
+ return arrayList
+ };
+
+ /**
+ * @override
+ */
+ HashMap.prototype.entrySet = function entrySet () {
+ var hashSet = new HashSet();
+ this.map_.entries().forEach(function (entry) { return hashSet.add(entry); });
+ return hashSet
+ };
+
+ /**
+ * @override
+ */
+ HashMap.prototype.size = function size () {
+ return this.map_.size()
+ };
+
+ return HashMap;
+ }(Map$1$1));
+
+ var PrecisionModel = function PrecisionModel () {
+ this._modelType = null;
+ this._scale = null;
+ if (arguments.length === 0) {
+ this._modelType = PrecisionModel.FLOATING;
+ } else if (arguments.length === 1) {
+ if (arguments[0] instanceof Type) {
+ var modelType = arguments[0];
+ this._modelType = modelType;
+ if (modelType === PrecisionModel.FIXED) {
+ this.setScale(1.0);
+ }
+ } else if (typeof arguments[0] === 'number') {
+ var scale = arguments[0];
+ this._modelType = PrecisionModel.FIXED;
+ this.setScale(scale);
+ } else if (arguments[0] instanceof PrecisionModel) {
+ var pm = arguments[0];
+ this._modelType = pm._modelType;
+ this._scale = pm._scale;
+ }
+ }
+ };
+
+ var staticAccessors$19 = { serialVersionUID: { configurable: true },maximumPreciseValue: { configurable: true } };
+ PrecisionModel.prototype.equals = function equals (other) {
+ if (!(other instanceof PrecisionModel)) {
+ return false
+ }
+ var otherPrecisionModel = other;
+ return this._modelType === otherPrecisionModel._modelType && this._scale === otherPrecisionModel._scale
+ };
+ PrecisionModel.prototype.compareTo = function compareTo (o) {
+ var other = o;
+ var sigDigits = this.getMaximumSignificantDigits();
+ var otherSigDigits = other.getMaximumSignificantDigits();
+ return new Integer(sigDigits).compareTo(new Integer(otherSigDigits))
+ };
+ PrecisionModel.prototype.getScale = function getScale () {
+ return this._scale
+ };
+ PrecisionModel.prototype.isFloating = function isFloating () {
+ return this._modelType === PrecisionModel.FLOATING || this._modelType === PrecisionModel.FLOATING_SINGLE
+ };
+ PrecisionModel.prototype.getType = function getType () {
+ return this._modelType
+ };
+ PrecisionModel.prototype.toString = function toString () {
+ var description = 'UNKNOWN';
+ if (this._modelType === PrecisionModel.FLOATING) {
+ description = 'Floating';
+ } else if (this._modelType === PrecisionModel.FLOATING_SINGLE) {
+ description = 'Floating-Single';
+ } else if (this._modelType === PrecisionModel.FIXED) {
+ description = 'Fixed (Scale=' + this.getScale() + ')';
+ }
+ return description
+ };
+ PrecisionModel.prototype.makePrecise = function makePrecise () {
+ if (typeof arguments[0] === 'number') {
+ var val = arguments[0];
+ if (Double.isNaN(val)) { return val }
+ if (this._modelType === PrecisionModel.FLOATING_SINGLE) {
+ var floatSingleVal = val;
+ return floatSingleVal
+ }
+ if (this._modelType === PrecisionModel.FIXED) {
+ return Math.round(val * this._scale) / this._scale
+ }
+ return val
+ } else if (arguments[0] instanceof Coordinate) {
+ var coord = arguments[0];
+ if (this._modelType === PrecisionModel.FLOATING) { return null }
+ coord.x = this.makePrecise(coord.x);
+ coord.y = this.makePrecise(coord.y);
+ }
+ };
+ PrecisionModel.prototype.getMaximumSignificantDigits = function getMaximumSignificantDigits () {
+ var maxSigDigits = 16;
+ if (this._modelType === PrecisionModel.FLOATING) {
+ maxSigDigits = 16;
+ } else if (this._modelType === PrecisionModel.FLOATING_SINGLE) {
+ maxSigDigits = 6;
+ } else if (this._modelType === PrecisionModel.FIXED) {
+ maxSigDigits = 1 + Math.trunc(Math.ceil(Math.log(this.getScale()) / Math.log(10)));
+ }
+ return maxSigDigits
+ };
+ PrecisionModel.prototype.setScale = function setScale (scale) {
+ this._scale = Math.abs(scale);
+ };
+ PrecisionModel.prototype.interfaces_ = function interfaces_ () {
+ return [Serializable, Comparable]
+ };
+ PrecisionModel.prototype.getClass = function getClass () {
+ return PrecisionModel
+ };
+ PrecisionModel.mostPrecise = function mostPrecise (pm1, pm2) {
+ if (pm1.compareTo(pm2) >= 0) { return pm1 }
+ return pm2
+ };
+ staticAccessors$19.serialVersionUID.get = function () { return 7777263578777803835 };
+ staticAccessors$19.maximumPreciseValue.get = function () { return 9007199254740992.0 };
+
+ Object.defineProperties( PrecisionModel, staticAccessors$19 );
+
+ var Type = function Type (name) {
+ this._name = name || null;
+ Type.nameToTypeMap.put(name, this);
+ };
+
+ var staticAccessors$1$1 = { serialVersionUID: { configurable: true },nameToTypeMap: { configurable: true } };
+ Type.prototype.readResolve = function readResolve () {
+ return Type.nameToTypeMap.get(this._name)
+ };
+ Type.prototype.toString = function toString () {
+ return this._name
+ };
+ Type.prototype.interfaces_ = function interfaces_ () {
+ return [Serializable]
+ };
+ Type.prototype.getClass = function getClass () {
+ return Type
+ };
+ staticAccessors$1$1.serialVersionUID.get = function () { return -5528602631731589822 };
+ staticAccessors$1$1.nameToTypeMap.get = function () { return new HashMap() };
+
+ Object.defineProperties( Type, staticAccessors$1$1 );
+
+ PrecisionModel.Type = Type;
+ PrecisionModel.FIXED = new Type('FIXED');
+ PrecisionModel.FLOATING = new Type('FLOATING');
+ PrecisionModel.FLOATING_SINGLE = new Type('FLOATING SINGLE');
+
+ var GeometryFactory = function GeometryFactory () {
+ this._precisionModel = new PrecisionModel();
+ this._SRID = 0;
+ this._coordinateSequenceFactory = GeometryFactory.getDefaultCoordinateSequenceFactory();
+
+ if (arguments.length === 0) ; else if (arguments.length === 1) {
+ if (hasInterface(arguments[0], CoordinateSequenceFactory)) {
+ this._coordinateSequenceFactory = arguments[0];
+ } else if (arguments[0] instanceof PrecisionModel) {
+ this._precisionModel = arguments[0];
+ }
+ } else if (arguments.length === 2) {
+ this._precisionModel = arguments[0];
+ this._SRID = arguments[1];
+ } else if (arguments.length === 3) {
+ this._precisionModel = arguments[0];
+ this._SRID = arguments[1];
+ this._coordinateSequenceFactory = arguments[2];
+ }
+ };
+
+ var staticAccessors$2 = { serialVersionUID: { configurable: true } };
+ GeometryFactory.prototype.toGeometry = function toGeometry (envelope) {
+ if (envelope.isNull()) {
+ return this.createPoint(null)
+ }
+ if (envelope.getMinX() === envelope.getMaxX() && envelope.getMinY() === envelope.getMaxY()) {
+ return this.createPoint(new Coordinate(envelope.getMinX(), envelope.getMinY()))
+ }
+ if (envelope.getMinX() === envelope.getMaxX() || envelope.getMinY() === envelope.getMaxY()) {
+ return this.createLineString([new Coordinate(envelope.getMinX(), envelope.getMinY()), new Coordinate(envelope.getMaxX(), envelope.getMaxY())])
+ }
+ return this.createPolygon(this.createLinearRing([new Coordinate(envelope.getMinX(), envelope.getMinY()), new Coordinate(envelope.getMinX(), envelope.getMaxY()), new Coordinate(envelope.getMaxX(), envelope.getMaxY()), new Coordinate(envelope.getMaxX(), envelope.getMinY()), new Coordinate(envelope.getMinX(), envelope.getMinY())]), null)
+ };
+ GeometryFactory.prototype.createLineString = function createLineString (coordinates) {
+ if (!coordinates) { return new LineString(this.getCoordinateSequenceFactory().create([]), this) }
+ else if (coordinates instanceof Array) { return new LineString(this.getCoordinateSequenceFactory().create(coordinates), this) }
+ else if (hasInterface(coordinates, CoordinateSequence)) { return new LineString(coordinates, this) }
+ };
+ GeometryFactory.prototype.createMultiLineString = function createMultiLineString () {
+ if (arguments.length === 0) {
+ return new MultiLineString(null, this)
+ } else if (arguments.length === 1) {
+ var lineStrings = arguments[0];
+ return new MultiLineString(lineStrings, this)
+ }
+ };
+ GeometryFactory.prototype.buildGeometry = function buildGeometry (geomList) {
+ var geomClass = null;
+ var isHeterogeneous = false;
+ var hasGeometryCollection = false;
+ for (var i = geomList.iterator(); i.hasNext();) {
+ var geom = i.next();
+ var partClass = geom.getClass();
+ if (geomClass === null) {
+ geomClass = partClass;
+ }
+ if (partClass !== geomClass) {
+ isHeterogeneous = true;
+ }
+ if (geom.isGeometryCollectionOrDerived()) { hasGeometryCollection = true; }
+ }
+ if (geomClass === null) {
+ return this.createGeometryCollection()
+ }
+ if (isHeterogeneous || hasGeometryCollection) {
+ return this.createGeometryCollection(GeometryFactory.toGeometryArray(geomList))
+ }
+ var geom0 = geomList.iterator().next();
+ var isCollection = geomList.size() > 1;
+ if (isCollection) {
+ if (geom0 instanceof Polygon) {
+ return this.createMultiPolygon(GeometryFactory.toPolygonArray(geomList))
+ } else if (geom0 instanceof LineString) {
+ return this.createMultiLineString(GeometryFactory.toLineStringArray(geomList))
+ } else if (geom0 instanceof Point) {
+ return this.createMultiPoint(GeometryFactory.toPointArray(geomList))
+ }
+ Assert.shouldNeverReachHere('Unhandled class: ' + geom0.getClass().getName());
+ }
+ return geom0
+ };
+ GeometryFactory.prototype.createMultiPointFromCoords = function createMultiPointFromCoords (coordinates) {
+ return this.createMultiPoint(coordinates !== null ? this.getCoordinateSequenceFactory().create(coordinates) : null)
+ };
+ GeometryFactory.prototype.createPoint = function createPoint () {
+ if (arguments.length === 0) {
+ return this.createPoint(this.getCoordinateSequenceFactory().create([]))
+ } else if (arguments.length === 1) {
+ if (arguments[0] instanceof Coordinate) {
+ var coordinate = arguments[0];
+ return this.createPoint(coordinate !== null ? this.getCoordinateSequenceFactory().create([coordinate]) : null)
+ } else if (hasInterface(arguments[0], CoordinateSequence)) {
+ var coordinates = arguments[0];
+ return new Point(coordinates, this)
+ }
+ }
+ };
+ GeometryFactory.prototype.getCoordinateSequenceFactory = function getCoordinateSequenceFactory () {
+ return this._coordinateSequenceFactory
+ };
+ GeometryFactory.prototype.createPolygon = function createPolygon () {
+ if (arguments.length === 0) {
+ return new Polygon(null, null, this)
+ } else if (arguments.length === 1) {
+ if (hasInterface(arguments[0], CoordinateSequence)) {
+ var coordinates = arguments[0];
+ return this.createPolygon(this.createLinearRing(coordinates))
+ } else if (arguments[0] instanceof Array) {
+ var coordinates$1 = arguments[0];
+ return this.createPolygon(this.createLinearRing(coordinates$1))
+ } else if (arguments[0] instanceof LinearRing) {
+ var shell = arguments[0];
+ return this.createPolygon(shell, null)
+ }
+ } else if (arguments.length === 2) {
+ var shell$1 = arguments[0];
+ var holes = arguments[1];
+ return new Polygon(shell$1, holes, this)
+ }
+ };
+ GeometryFactory.prototype.getSRID = function getSRID () {
+ return this._SRID
+ };
+ GeometryFactory.prototype.createGeometryCollection = function createGeometryCollection () {
+ if (arguments.length === 0) {
+ return new GeometryCollection(null, this)
+ } else if (arguments.length === 1) {
+ var geometries = arguments[0];
+ return new GeometryCollection(geometries, this)
+ }
+ };
+ GeometryFactory.prototype.createGeometry = function createGeometry (g) {
+ var editor = new GeometryEditor(this);
+ return editor.edit(g, {
+ edit: function () {
+ if (arguments.length === 2) {
+ var coordSeq = arguments[0];
+ // const geometry = arguments[1]
+ return this._coordinateSequenceFactory.create(coordSeq)
+ }
+ }
+ })
+ };
+ GeometryFactory.prototype.getPrecisionModel = function getPrecisionModel () {
+ return this._precisionModel
+ };
+ GeometryFactory.prototype.createLinearRing = function createLinearRing () {
+ if (arguments.length === 0) {
+ return this.createLinearRing(this.getCoordinateSequenceFactory().create([]))
+ } else if (arguments.length === 1) {
+ if (arguments[0] instanceof Array) {
+ var coordinates = arguments[0];
+ return this.createLinearRing(coordinates !== null ? this.getCoordinateSequenceFactory().create(coordinates) : null)
+ } else if (hasInterface(arguments[0], CoordinateSequence)) {
+ var coordinates$1 = arguments[0];
+ return new LinearRing(coordinates$1, this)
+ }
+ }
+ };
+ GeometryFactory.prototype.createMultiPolygon = function createMultiPolygon () {
+ if (arguments.length === 0) {
+ return new MultiPolygon(null, this)
+ } else if (arguments.length === 1) {
+ var polygons = arguments[0];
+ return new MultiPolygon(polygons, this)
+ }
+ };
+ GeometryFactory.prototype.createMultiPoint = function createMultiPoint () {
+ var this$1 = this;
+
+ if (arguments.length === 0) {
+ return new MultiPoint(null, this)
+ } else if (arguments.length === 1) {
+ if (arguments[0] instanceof Array) {
+ var point = arguments[0];
+ return new MultiPoint(point, this)
+ } else if (arguments[0] instanceof Array) {
+ var coordinates = arguments[0];
+ return this.createMultiPoint(coordinates !== null ? this.getCoordinateSequenceFactory().create(coordinates) : null)
+ } else if (hasInterface(arguments[0], CoordinateSequence)) {
+ var coordinates$1 = arguments[0];
+ if (coordinates$1 === null) {
+ return this.createMultiPoint(new Array(0).fill(null))
+ }
+ var points = new Array(coordinates$1.size()).fill(null);
+ for (var i = 0; i < coordinates$1.size(); i++) {
+ var ptSeq = this$1.getCoordinateSequenceFactory().create(1, coordinates$1.getDimension());
+ CoordinateSequences.copy(coordinates$1, i, ptSeq, 0, 1);
+ points[i] = this$1.createPoint(ptSeq);
+ }
+ return this.createMultiPoint(points)
+ }
+ }
+ };
+ GeometryFactory.prototype.interfaces_ = function interfaces_ () {
+ return [Serializable]
+ };
+ GeometryFactory.prototype.getClass = function getClass () {
+ return GeometryFactory
+ };
+ GeometryFactory.toMultiPolygonArray = function toMultiPolygonArray (multiPolygons) {
+ var multiPolygonArray = new Array(multiPolygons.size()).fill(null);
+ return multiPolygons.toArray(multiPolygonArray)
+ };
+ GeometryFactory.toGeometryArray = function toGeometryArray (geometries) {
+ if (geometries === null) { return null }
+ var geometryArray = new Array(geometries.size()).fill(null);
+ return geometries.toArray(geometryArray)
+ };
+ GeometryFactory.getDefaultCoordinateSequenceFactory = function getDefaultCoordinateSequenceFactory () {
+ return CoordinateArraySequenceFactory.instance()
+ };
+ GeometryFactory.toMultiLineStringArray = function toMultiLineStringArray (multiLineStrings) {
+ var multiLineStringArray = new Array(multiLineStrings.size()).fill(null);
+ return multiLineStrings.toArray(multiLineStringArray)
+ };
+ GeometryFactory.toLineStringArray = function toLineStringArray (lineStrings) {
+ var lineStringArray = new Array(lineStrings.size()).fill(null);
+ return lineStrings.toArray(lineStringArray)
+ };
+ GeometryFactory.toMultiPointArray = function toMultiPointArray (multiPoints) {
+ var multiPointArray = new Array(multiPoints.size()).fill(null);
+ return multiPoints.toArray(multiPointArray)
+ };
+ GeometryFactory.toLinearRingArray = function toLinearRingArray (linearRings) {
+ var linearRingArray = new Array(linearRings.size()).fill(null);
+ return linearRings.toArray(linearRingArray)
+ };
+ GeometryFactory.toPointArray = function toPointArray (points) {
+ var pointArray = new Array(points.size()).fill(null);
+ return points.toArray(pointArray)
+ };
+ GeometryFactory.toPolygonArray = function toPolygonArray (polygons) {
+ var polygonArray = new Array(polygons.size()).fill(null);
+ return polygons.toArray(polygonArray)
+ };
+ GeometryFactory.createPointFromInternalCoord = function createPointFromInternalCoord (coord, exemplar) {
+ exemplar.getPrecisionModel().makePrecise(coord);
+ return exemplar.getFactory().createPoint(coord)
+ };
+ staticAccessors$2.serialVersionUID.get = function () { return -6820524753094095635 };
+
+ Object.defineProperties( GeometryFactory, staticAccessors$2 );
+
+ var geometryTypes = ['Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon'];
+
+ /**
+ * Class for reading and writing Well-Known Text.Create a new parser for GeoJSON
+ * NOTE: Adapted from OpenLayers 2.11 implementation.
+ */
+
+ /**
+ * Create a new parser for GeoJSON
+ *
+ * @param {GeometryFactory} geometryFactory
+ * @return An instance of GeoJsonParser.
+ * @constructor
+ * @private
+ */
+ var GeoJSONParser = function GeoJSONParser (geometryFactory) {
+ this.geometryFactory = geometryFactory || new GeometryFactory();
+ };
+ /**
+ * Deserialize a GeoJSON object and return the Geometry or Feature(Collection) with JSTS Geometries
+ *
+ * @param {}
+ * A GeoJSON object.
+ * @return {} A Geometry instance or object representing a Feature(Collection) with Geometry instances.
+ * @private
+ */
+ GeoJSONParser.prototype.read = function read (json) {
+ var obj;
+ if (typeof json === 'string') {
+ obj = JSON.parse(json);
+ } else {
+ obj = json;
+ }
+
+ var type = obj.type;
+
+ if (!parse$2[type]) {
+ throw new Error('Unknown GeoJSON type: ' + obj.type)
+ }
+
+ if (geometryTypes.indexOf(type) !== -1) {
+ return parse$2[type].apply(this, [obj.coordinates])
+ } else if (type === 'GeometryCollection') {
+ return parse$2[type].apply(this, [obj.geometries])
+ }
+
+ // feature or feature collection
+ return parse$2[type].apply(this, [obj])
+ };
+
+ /**
+ * Serialize a Geometry object into GeoJSON
+ *
+ * @param {Geometry}
+ * geometry A Geometry or array of Geometries.
+ * @return {Object} A GeoJSON object represting the input Geometry/Geometries.
+ * @private
+ */
+ GeoJSONParser.prototype.write = function write (geometry) {
+ var type = geometry.getGeometryType();
+
+ if (!extract[type]) {
+ throw new Error('Geometry is not supported')
+ }
+
+ return extract[type].apply(this, [geometry])
+ };
+
+ var parse$2 = {
+ /**
+ * Parse a GeoJSON Feature object
+ *
+ * @param {Object}
+ * obj Object to parse.
+ *
+ * @return {Object} Feature with geometry/bbox converted to JSTS Geometries.
+ */
+ Feature: function (obj) {
+ var feature = {};
+
+ // copy features
+ for (var key in obj) {
+ feature[key] = obj[key];
+ }
+
+ // parse geometry
+ if (obj.geometry) {
+ var type = obj.geometry.type;
+ if (!parse$2[type]) {
+ throw new Error('Unknown GeoJSON type: ' + obj.type)
+ }
+ feature.geometry = this.read(obj.geometry);
+ }
+
+ // bbox
+ if (obj.bbox) {
+ feature.bbox = parse$2.bbox.apply(this, [obj.bbox]);
+ }
+
+ return feature
+ },
+
+ /**
+ * Parse a GeoJSON FeatureCollection object
+ *
+ * @param {Object}
+ * obj Object to parse.
+ *
+ * @return {Object} FeatureCollection with geometry/bbox converted to JSTS Geometries.
+ */
+ FeatureCollection: function (obj) {
+ var this$1 = this;
+
+ var featureCollection = {};
+
+ if (obj.features) {
+ featureCollection.features = [];
+
+ for (var i = 0; i < obj.features.length; ++i) {
+ featureCollection.features.push(this$1.read(obj.features[i]));
+ }
+ }
+
+ if (obj.bbox) {
+ featureCollection.bbox = this.parse.bbox.apply(this, [obj.bbox]);
+ }
+
+ return featureCollection
+ },
+
+ /**
+ * Convert the ordinates in an array to an array of Coordinates
+ *
+ * @param {Array}
+ * array Array with {Number}s.
+ *
+ * @return {Array} Array with Coordinates.
+ */
+ coordinates: function (array) {
+ var coordinates = [];
+ for (var i = 0; i < array.length; ++i) {
+ var sub = array[i];
+ coordinates.push(new Coordinate(sub[0], sub[1]));
+ }
+ return coordinates
+ },
+
+ /**
+ * Convert the bbox to a LinearRing
+ *
+ * @param {Array}
+ * array Array with [xMin, yMin, xMax, yMax].
+ *
+ * @return {Array} Array with Coordinates.
+ */
+ bbox: function (array) {
+ return this.geometryFactory.createLinearRing([
+ new Coordinate(array[0], array[1]),
+ new Coordinate(array[2], array[1]),
+ new Coordinate(array[2], array[3]),
+ new Coordinate(array[0], array[3]),
+ new Coordinate(array[0], array[1])
+ ])
+ },
+
+ /**
+ * Convert an Array with ordinates to a Point
+ *
+ * @param {Array}
+ * array Array with ordinates.
+ *
+ * @return {Point} Point.
+ */
+ Point: function (array) {
+ var coordinate = new Coordinate(array[0], array[1]);
+ return this.geometryFactory.createPoint(coordinate)
+ },
+
+ /**
+ * Convert an Array with coordinates to a MultiPoint
+ *
+ * @param {Array}
+ * array Array with coordinates.
+ *
+ * @return {MultiPoint} MultiPoint.
+ */
+ MultiPoint: function (array) {
+ var this$1 = this;
+
+ var points = [];
+ for (var i = 0; i < array.length; ++i) {
+ points.push(parse$2.Point.apply(this$1, [array[i]]));
+ }
+ return this.geometryFactory.createMultiPoint(points)
+ },
+
+ /**
+ * Convert an Array with coordinates to a LineString
+ *
+ * @param {Array}
+ * array Array with coordinates.
+ *
+ * @return {LineString} LineString.
+ */
+ LineString: function (array) {
+ var coordinates = parse$2.coordinates.apply(this, [array]);
+ return this.geometryFactory.createLineString(coordinates)
+ },
+
+ /**
+ * Convert an Array with coordinates to a MultiLineString
+ *
+ * @param {Array}
+ * array Array with coordinates.
+ *
+ * @return {MultiLineString} MultiLineString.
+ */
+ MultiLineString: function (array) {
+ var this$1 = this;
+
+ var lineStrings = [];
+ for (var i = 0; i < array.length; ++i) {
+ lineStrings.push(parse$2.LineString.apply(this$1, [array[i]]));
+ }
+ return this.geometryFactory.createMultiLineString(lineStrings)
+ },
+
+ /**
+ * Convert an Array to a Polygon
+ *
+ * @param {Array}
+ * array Array with shell and holes.
+ *
+ * @return {Polygon} Polygon.
+ */
+ Polygon: function (array) {
+ var this$1 = this;
+
+ var shellCoordinates = parse$2.coordinates.apply(this, [array[0]]);
+ var shell = this.geometryFactory.createLinearRing(shellCoordinates);
+ var holes = [];
+ for (var i = 1; i < array.length; ++i) {
+ var hole = array[i];
+ var coordinates = parse$2.coordinates.apply(this$1, [hole]);
+ var linearRing = this$1.geometryFactory.createLinearRing(coordinates);
+ holes.push(linearRing);
+ }
+ return this.geometryFactory.createPolygon(shell, holes)
+ },
+
+ /**
+ * Convert an Array to a MultiPolygon
+ *
+ * @param {Array}
+ * array Array of arrays with shell and rings.
+ *
+ * @return {MultiPolygon} MultiPolygon.
+ */
+ MultiPolygon: function (array) {
+ var this$1 = this;
+
+ var polygons = [];
+ for (var i = 0; i < array.length; ++i) {
+ var polygon = array[i];
+ polygons.push(parse$2.Polygon.apply(this$1, [polygon]));
+ }
+ return this.geometryFactory.createMultiPolygon(polygons)
+ },
+
+ /**
+ * Convert an Array to a GeometryCollection
+ *
+ * @param {Array}
+ * array Array of GeoJSON geometries.
+ *
+ * @return {GeometryCollection} GeometryCollection.
+ */
+ GeometryCollection: function (array) {
+ var this$1 = this;
+
+ var geometries = [];
+ for (var i = 0; i < array.length; ++i) {
+ var geometry = array[i];
+ geometries.push(this$1.read(geometry));
+ }
+ return this.geometryFactory.createGeometryCollection(geometries)
+ }
+ };
+
+ var extract = {
+ /**
+ * Convert a Coordinate to an Array
+ *
+ * @param {Coordinate}
+ * coordinate Coordinate to convert.
+ *
+ * @return {Array} Array of ordinates.
+ */
+ coordinate: function (coordinate) {
+ return [coordinate.x, coordinate.y]
+ },
+
+ /**
+ * Convert a Point to a GeoJSON object
+ *
+ * @param {Point}
+ * point Point to convert.
+ *
+ * @return {Array} Array of 2 ordinates (paired to a coordinate).
+ */
+ Point: function (point) {
+ var array = extract.coordinate.apply(this, [point.getCoordinate()]);
+ return {
+ type: 'Point',
+ coordinates: array
+ }
+ },
+
+ /**
+ * Convert a MultiPoint to a GeoJSON object
+ *
+ * @param {MultiPoint}
+ * multipoint MultiPoint to convert.
+ *
+ * @return {Array} Array of coordinates.
+ */
+ MultiPoint: function (multipoint) {
+ var this$1 = this;
+
+ var array = [];
+ for (var i = 0; i < multipoint._geometries.length; ++i) {
+ var point = multipoint._geometries[i];
+ var geoJson = extract.Point.apply(this$1, [point]);
+ array.push(geoJson.coordinates);
+ }
+ return {
+ type: 'MultiPoint',
+ coordinates: array
+ }
+ },
+
+ /**
+ * Convert a LineString to a GeoJSON object
+ *
+ * @param {LineString}
+ * linestring LineString to convert.
+ *
+ * @return {Array} Array of coordinates.
+ */
+ LineString: function (linestring) {
+ var this$1 = this;
+
+ var array = [];
+ var coordinates = linestring.getCoordinates();
+ for (var i = 0; i < coordinates.length; ++i) {
+ var coordinate = coordinates[i];
+ array.push(extract.coordinate.apply(this$1, [coordinate]));
+ }
+ return {
+ type: 'LineString',
+ coordinates: array
+ }
+ },
+
+ /**
+ * Convert a MultiLineString to a GeoJSON object
+ *
+ * @param {MultiLineString}
+ * multilinestring MultiLineString to convert.
+ *
+ * @return {Array} Array of Array of coordinates.
+ */
+ MultiLineString: function (multilinestring) {
+ var this$1 = this;
+
+ var array = [];
+ for (var i = 0; i < multilinestring._geometries.length; ++i) {
+ var linestring = multilinestring._geometries[i];
+ var geoJson = extract.LineString.apply(this$1, [linestring]);
+ array.push(geoJson.coordinates);
+ }
+ return {
+ type: 'MultiLineString',
+ coordinates: array
+ }
+ },
+
+ /**
+ * Convert a Polygon to a GeoJSON object
+ *
+ * @param {Polygon}
+ * polygon Polygon to convert.
+ *
+ * @return {Array} Array with shell, holes.
+ */
+ Polygon: function (polygon) {
+ var this$1 = this;
+
+ var array = [];
+ var shellGeoJson = extract.LineString.apply(this, [polygon._shell]);
+ array.push(shellGeoJson.coordinates);
+ for (var i = 0; i < polygon._holes.length; ++i) {
+ var hole = polygon._holes[i];
+ var holeGeoJson = extract.LineString.apply(this$1, [hole]);
+ array.push(holeGeoJson.coordinates);
+ }
+ return {
+ type: 'Polygon',
+ coordinates: array
+ }
+ },
+
+ /**
+ * Convert a MultiPolygon to a GeoJSON object
+ *
+ * @param {MultiPolygon}
+ * multipolygon MultiPolygon to convert.
+ *
+ * @return {Array} Array of polygons.
+ */
+ MultiPolygon: function (multipolygon) {
+ var this$1 = this;
+
+ var array = [];
+ for (var i = 0; i < multipolygon._geometries.length; ++i) {
+ var polygon = multipolygon._geometries[i];
+ var geoJson = extract.Polygon.apply(this$1, [polygon]);
+ array.push(geoJson.coordinates);
+ }
+ return {
+ type: 'MultiPolygon',
+ coordinates: array
+ }
+ },
+
+ /**
+ * Convert a GeometryCollection to a GeoJSON object
+ *
+ * @param {GeometryCollection}
+ * collection GeometryCollection to convert.
+ *
+ * @return {Array} Array of geometries.
+ */
+ GeometryCollection: function (collection) {
+ var this$1 = this;
+
+ var array = [];
+ for (var i = 0; i < collection._geometries.length; ++i) {
+ var geometry = collection._geometries[i];
+ var type = geometry.getGeometryType();
+ array.push(extract[type].apply(this$1, [geometry]));
+ }
+ return {
+ type: 'GeometryCollection',
+ geometries: array
+ }
+ }
+ };
+
+ /**
+ * Converts a geometry in GeoJSON to a {@link Geometry}.
+ */
+
+ /**
+ * A GeoJSONReader
is parameterized by a GeometryFactory
,
+ * to allow it to create Geometry
objects of the appropriate
+ * implementation. In particular, the GeometryFactory
determines
+ * the PrecisionModel
and SRID
that is used.
+ *
+ * @param {GeometryFactory} geometryFactory
+ * @constructor
+ */
+ var GeoJSONReader = function GeoJSONReader (geometryFactory) {
+ this.geometryFactory = geometryFactory || new GeometryFactory();
+ this.precisionModel = this.geometryFactory.getPrecisionModel();
+ this.parser = new GeoJSONParser(this.geometryFactory);
+ };
+ /**
+ * Reads a GeoJSON representation of a {@link Geometry}
+ *
+ * Will also parse GeoJSON Features/FeatureCollections as custom objects.
+ *
+ * @param {Object|String} geoJson a GeoJSON Object or String.
+ * @return {Geometry|Object} a Geometry or Feature/FeatureCollection representation.
+ * @memberof GeoJSONReader
+ */
+ GeoJSONReader.prototype.read = function read (geoJson) {
+ var geometry = this.parser.read(geoJson);
+
+ if (this.precisionModel.getType() === PrecisionModel.FIXED) {
+ this.reducePrecision(geometry);
+ }
+
+ return geometry
+ };
+
+ // NOTE: this is a hack
+ GeoJSONReader.prototype.reducePrecision = function reducePrecision (geometry) {
+ var this$1 = this;
+
+ var i, len;
+
+ if (geometry.coordinate) {
+ this.precisionModel.makePrecise(geometry.coordinate);
+ } else if (geometry.points) {
+ for (i = 0, len = geometry.points.length; i < len; i++) {
+ this$1.precisionModel.makePrecise(geometry.points[i]);
+ }
+ } else if (geometry.geometries) {
+ for (i = 0, len = geometry.geometries.length; i < len; i++) {
+ this$1.reducePrecision(geometry.geometries[i]);
+ }
+ }
+ };
+
+ /**
+ * @module GeoJSONWriter
+ */
+
+ /**
+ * Writes the GeoJSON representation of a {@link Geometry}. The
+ * The GeoJSON format is defined here .
+ */
+
+ /**
+ * The GeoJSONWriter
outputs coordinates rounded to the precision
+ * model. Only the maximum number of decimal places necessary to represent the
+ * ordinates to the required precision will be output.
+ *
+ * @param {GeometryFactory} geometryFactory
+ * @constructor
+ */
+ var GeoJSONWriter = function GeoJSONWriter () {
+ this.parser = new GeoJSONParser(this.geometryFactory);
+ };
+ /**
+ * Converts a Geometry
to its GeoJSON representation.
+ *
+ * @param {Geometry}
+ * geometry a Geometry
to process.
+ * @return {Object} The GeoJSON representation of the Geometry.
+ * @memberof GeoJSONWriter
+ */
+ GeoJSONWriter.prototype.write = function write (geometry) {
+ return this.parser.write(geometry)
+ };
+
+ /* eslint-disable no-undef */
+
+ // io
+
+ var Position = function Position () {};
+
+ var staticAccessors$20 = { ON: { configurable: true },LEFT: { configurable: true },RIGHT: { configurable: true } };
+
+ Position.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ Position.prototype.getClass = function getClass () {
+ return Position
+ };
+ Position.opposite = function opposite (position) {
+ if (position === Position.LEFT) { return Position.RIGHT }
+ if (position === Position.RIGHT) { return Position.LEFT }
+ return position
+ };
+ staticAccessors$20.ON.get = function () { return 0 };
+ staticAccessors$20.LEFT.get = function () { return 1 };
+ staticAccessors$20.RIGHT.get = function () { return 2 };
+
+ Object.defineProperties( Position, staticAccessors$20 );
+
+ /**
+ * @param {string=} message Optional message
+ * @extends {Error}
+ * @constructor
+ * @private
+ */
+ function EmptyStackException (message) {
+ this.message = message || '';
+ }
+ EmptyStackException.prototype = new Error();
+
+ /**
+ * @type {string}
+ */
+ EmptyStackException.prototype.name = 'EmptyStackException';
+
+ /**
+ * @see http://download.oracle.com/javase/6/docs/api/java/util/Stack.html
+ *
+ * @extends {List}
+ * @constructor
+ * @private
+ */
+ function Stack$1 () {
+ /**
+ * @type {Array}
+ * @private
+ */
+ this.array_ = [];
+ }
+ Stack$1.prototype = new List();
+
+ /**
+ * @override
+ */
+ Stack$1.prototype.add = function (e) {
+ this.array_.push(e);
+ return true
+ };
+
+ /**
+ * @override
+ */
+ Stack$1.prototype.get = function (index) {
+ if (index < 0 || index >= this.size()) {
+ throw new Error()
+ }
+
+ return this.array_[index]
+ };
+
+ /**
+ * Pushes an item onto the top of this stack.
+ * @param {Object} e
+ * @return {Object}
+ */
+ Stack$1.prototype.push = function (e) {
+ this.array_.push(e);
+ return e
+ };
+
+ /**
+ * Pushes an item onto the top of this stack.
+ * @param {Object} e
+ * @return {Object}
+ */
+ Stack$1.prototype.pop = function (e) {
+ if (this.array_.length === 0) {
+ throw new EmptyStackException()
+ }
+
+ return this.array_.pop()
+ };
+
+ /**
+ * Looks at the object at the top of this stack without removing it from the
+ * stack.
+ * @return {Object}
+ */
+ Stack$1.prototype.peek = function () {
+ if (this.array_.length === 0) {
+ throw new EmptyStackException()
+ }
+
+ return this.array_[this.array_.length - 1]
+ };
+
+ /**
+ * Tests if this stack is empty.
+ * @return {boolean} true if and only if this stack contains no items; false
+ * otherwise.
+ */
+ Stack$1.prototype.empty = function () {
+ if (this.array_.length === 0) {
+ return true
+ } else {
+ return false
+ }
+ };
+
+ /**
+ * @return {boolean}
+ */
+ Stack$1.prototype.isEmpty = function () {
+ return this.empty()
+ };
+
+ /**
+ * Returns the 1-based position where an object is on this stack. If the object
+ * o occurs as an item in this stack, this method returns the distance from the
+ * top of the stack of the occurrence nearest the top of the stack; the topmost
+ * item on the stack is considered to be at distance 1. The equals method is
+ * used to compare o to the items in this stack.
+ *
+ * NOTE: does not currently actually use equals. (=== is used)
+ *
+ * @param {Object} o
+ * @return {number} the 1-based position from the top of the stack where the
+ * object is located; the return value -1 indicates that the object is
+ * not on the stack.
+ */
+ Stack$1.prototype.search = function (o) {
+ return this.array_.indexOf(o)
+ };
+
+ /**
+ * @return {number}
+ * @export
+ */
+ Stack$1.prototype.size = function () {
+ return this.array_.length
+ };
+
+ /**
+ * @return {Array}
+ */
+ Stack$1.prototype.toArray = function () {
+ var this$1 = this;
+
+ var array = [];
+
+ for (var i = 0, len = this.array_.length; i < len; i++) {
+ array.push(this$1.array_[i]);
+ }
+
+ return array
+ };
+
+ var RightmostEdgeFinder = function RightmostEdgeFinder () {
+ this._minIndex = -1;
+ this._minCoord = null;
+ this._minDe = null;
+ this._orientedDe = null;
+ };
+ RightmostEdgeFinder.prototype.getCoordinate = function getCoordinate () {
+ return this._minCoord
+ };
+ RightmostEdgeFinder.prototype.getRightmostSide = function getRightmostSide (de, index) {
+ var side = this.getRightmostSideOfSegment(de, index);
+ if (side < 0) { side = this.getRightmostSideOfSegment(de, index - 1); }
+ if (side < 0) {
+ this._minCoord = null;
+ this.checkForRightmostCoordinate(de);
+ }
+ return side
+ };
+ RightmostEdgeFinder.prototype.findRightmostEdgeAtVertex = function findRightmostEdgeAtVertex () {
+ var pts = this._minDe.getEdge().getCoordinates();
+ Assert.isTrue(this._minIndex > 0 && this._minIndex < pts.length, 'rightmost point expected to be interior vertex of edge');
+ var pPrev = pts[this._minIndex - 1];
+ var pNext = pts[this._minIndex + 1];
+ var orientation = CGAlgorithms.computeOrientation(this._minCoord, pNext, pPrev);
+ var usePrev = false;
+ if (pPrev.y < this._minCoord.y && pNext.y < this._minCoord.y && orientation === CGAlgorithms.COUNTERCLOCKWISE) {
+ usePrev = true;
+ } else if (pPrev.y > this._minCoord.y && pNext.y > this._minCoord.y && orientation === CGAlgorithms.CLOCKWISE) {
+ usePrev = true;
+ }
+ if (usePrev) {
+ this._minIndex = this._minIndex - 1;
+ }
+ };
+ RightmostEdgeFinder.prototype.getRightmostSideOfSegment = function getRightmostSideOfSegment (de, i) {
+ var e = de.getEdge();
+ var coord = e.getCoordinates();
+ if (i < 0 || i + 1 >= coord.length) { return -1 }
+ if (coord[i].y === coord[i + 1].y) { return -1 }
+ var pos = Position.LEFT;
+ if (coord[i].y < coord[i + 1].y) { pos = Position.RIGHT; }
+ return pos
+ };
+ RightmostEdgeFinder.prototype.getEdge = function getEdge () {
+ return this._orientedDe
+ };
+ RightmostEdgeFinder.prototype.checkForRightmostCoordinate = function checkForRightmostCoordinate (de) {
+ var this$1 = this;
+
+ var coord = de.getEdge().getCoordinates();
+ for (var i = 0; i < coord.length - 1; i++) {
+ if (this$1._minCoord === null || coord[i].x > this$1._minCoord.x) {
+ this$1._minDe = de;
+ this$1._minIndex = i;
+ this$1._minCoord = coord[i];
+ }
+ }
+ };
+ RightmostEdgeFinder.prototype.findRightmostEdgeAtNode = function findRightmostEdgeAtNode () {
+ var node = this._minDe.getNode();
+ var star = node.getEdges();
+ this._minDe = star.getRightmostEdge();
+ if (!this._minDe.isForward()) {
+ this._minDe = this._minDe.getSym();
+ this._minIndex = this._minDe.getEdge().getCoordinates().length - 1;
+ }
+ };
+ RightmostEdgeFinder.prototype.findEdge = function findEdge (dirEdgeList) {
+ var this$1 = this;
+
+ for (var i = dirEdgeList.iterator(); i.hasNext();) {
+ var de = i.next();
+ if (!de.isForward()) { continue }
+ this$1.checkForRightmostCoordinate(de);
+ }
+ Assert.isTrue(this._minIndex !== 0 || this._minCoord.equals(this._minDe.getCoordinate()), 'inconsistency in rightmost processing');
+ if (this._minIndex === 0) {
+ this.findRightmostEdgeAtNode();
+ } else {
+ this.findRightmostEdgeAtVertex();
+ }
+ this._orientedDe = this._minDe;
+ var rightmostSide = this.getRightmostSide(this._minDe, this._minIndex);
+ if (rightmostSide === Position.LEFT) {
+ this._orientedDe = this._minDe.getSym();
+ }
+ };
+ RightmostEdgeFinder.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ RightmostEdgeFinder.prototype.getClass = function getClass () {
+ return RightmostEdgeFinder
+ };
+
+ var TopologyException = (function (RuntimeException$$1) {
+ function TopologyException (msg, pt) {
+ RuntimeException$$1.call(this, TopologyException.msgWithCoord(msg, pt));
+ this.pt = pt ? new Coordinate(pt) : null;
+ this.name = 'TopologyException';
+ }
+
+ if ( RuntimeException$$1 ) TopologyException.__proto__ = RuntimeException$$1;
+ TopologyException.prototype = Object.create( RuntimeException$$1 && RuntimeException$$1.prototype );
+ TopologyException.prototype.constructor = TopologyException;
+ TopologyException.prototype.getCoordinate = function getCoordinate () {
+ return this.pt
+ };
+ TopologyException.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ TopologyException.prototype.getClass = function getClass () {
+ return TopologyException
+ };
+ TopologyException.msgWithCoord = function msgWithCoord (msg, pt) {
+ if (!pt) { return msg + ' [ ' + pt + ' ]' }
+ return msg
+ };
+
+ return TopologyException;
+ }(RuntimeException));
+
+ var LinkedList = function LinkedList () {
+ this.array_ = [];
+ };
+ LinkedList.prototype.addLast = function addLast (e) {
+ this.array_.push(e);
+ };
+ LinkedList.prototype.removeFirst = function removeFirst () {
+ return this.array_.shift()
+ };
+ LinkedList.prototype.isEmpty = function isEmpty () {
+ return this.array_.length === 0
+ };
+
+ var BufferSubgraph = function BufferSubgraph () {
+ this._finder = null;
+ this._dirEdgeList = new ArrayList();
+ this._nodes = new ArrayList();
+ this._rightMostCoord = null;
+ this._env = null;
+ this._finder = new RightmostEdgeFinder();
+ };
+ BufferSubgraph.prototype.clearVisitedEdges = function clearVisitedEdges () {
+ for (var it = this._dirEdgeList.iterator(); it.hasNext();) {
+ var de = it.next();
+ de.setVisited(false);
+ }
+ };
+ BufferSubgraph.prototype.getRightmostCoordinate = function getRightmostCoordinate () {
+ return this._rightMostCoord
+ };
+ BufferSubgraph.prototype.computeNodeDepth = function computeNodeDepth (n) {
+ var this$1 = this;
+
+ var startEdge = null;
+ for (var i = n.getEdges().iterator(); i.hasNext();) {
+ var de = i.next();
+ if (de.isVisited() || de.getSym().isVisited()) {
+ startEdge = de;
+ break
+ }
+ }
+ if (startEdge === null) { throw new TopologyException('unable to find edge to compute depths at ' + n.getCoordinate()) }
+ n.getEdges().computeDepths(startEdge);
+ for (var i$1 = n.getEdges().iterator(); i$1.hasNext();) {
+ var de$1 = i$1.next();
+ de$1.setVisited(true);
+ this$1.copySymDepths(de$1);
+ }
+ };
+ BufferSubgraph.prototype.computeDepth = function computeDepth (outsideDepth) {
+ this.clearVisitedEdges();
+ var de = this._finder.getEdge();
+ // const n = de.getNode()
+ // const label = de.getLabel()
+ de.setEdgeDepths(Position.RIGHT, outsideDepth);
+ this.copySymDepths(de);
+ this.computeDepths(de);
+ };
+ BufferSubgraph.prototype.create = function create (node) {
+ this.addReachable(node);
+ this._finder.findEdge(this._dirEdgeList);
+ this._rightMostCoord = this._finder.getCoordinate();
+ };
+ BufferSubgraph.prototype.findResultEdges = function findResultEdges () {
+ for (var it = this._dirEdgeList.iterator(); it.hasNext();) {
+ var de = it.next();
+ if (de.getDepth(Position.RIGHT) >= 1 && de.getDepth(Position.LEFT) <= 0 && !de.isInteriorAreaEdge()) {
+ de.setInResult(true);
+ }
+ }
+ };
+ BufferSubgraph.prototype.computeDepths = function computeDepths (startEdge) {
+ var this$1 = this;
+
+ var nodesVisited = new HashSet();
+ var nodeQueue = new LinkedList();
+ var startNode = startEdge.getNode();
+ nodeQueue.addLast(startNode);
+ nodesVisited.add(startNode);
+ startEdge.setVisited(true);
+ while (!nodeQueue.isEmpty()) {
+ var n = nodeQueue.removeFirst();
+ nodesVisited.add(n);
+ this$1.computeNodeDepth(n);
+ for (var i = n.getEdges().iterator(); i.hasNext();) {
+ var de = i.next();
+ var sym = de.getSym();
+ if (sym.isVisited()) { continue }
+ var adjNode = sym.getNode();
+ if (!nodesVisited.contains(adjNode)) {
+ nodeQueue.addLast(adjNode);
+ nodesVisited.add(adjNode);
+ }
+ }
+ }
+ };
+ BufferSubgraph.prototype.compareTo = function compareTo (o) {
+ var graph = o;
+ if (this._rightMostCoord.x < graph._rightMostCoord.x) {
+ return -1
+ }
+ if (this._rightMostCoord.x > graph._rightMostCoord.x) {
+ return 1
+ }
+ return 0
+ };
+ BufferSubgraph.prototype.getEnvelope = function getEnvelope () {
+ if (this._env === null) {
+ var edgeEnv = new Envelope();
+ for (var it = this._dirEdgeList.iterator(); it.hasNext();) {
+ var dirEdge = it.next();
+ var pts = dirEdge.getEdge().getCoordinates();
+ for (var i = 0; i < pts.length - 1; i++) {
+ edgeEnv.expandToInclude(pts[i]);
+ }
+ }
+ this._env = edgeEnv;
+ }
+ return this._env
+ };
+ BufferSubgraph.prototype.addReachable = function addReachable (startNode) {
+ var this$1 = this;
+
+ var nodeStack = new Stack$1();
+ nodeStack.add(startNode);
+ while (!nodeStack.empty()) {
+ var node = nodeStack.pop();
+ this$1.add(node, nodeStack);
+ }
+ };
+ BufferSubgraph.prototype.copySymDepths = function copySymDepths (de) {
+ var sym = de.getSym();
+ sym.setDepth(Position.LEFT, de.getDepth(Position.RIGHT));
+ sym.setDepth(Position.RIGHT, de.getDepth(Position.LEFT));
+ };
+ BufferSubgraph.prototype.add = function add (node, nodeStack) {
+ var this$1 = this;
+
+ node.setVisited(true);
+ this._nodes.add(node);
+ for (var i = node.getEdges().iterator(); i.hasNext();) {
+ var de = i.next();
+ this$1._dirEdgeList.add(de);
+ var sym = de.getSym();
+ var symNode = sym.getNode();
+ if (!symNode.isVisited()) { nodeStack.push(symNode); }
+ }
+ };
+ BufferSubgraph.prototype.getNodes = function getNodes () {
+ return this._nodes
+ };
+ BufferSubgraph.prototype.getDirectedEdges = function getDirectedEdges () {
+ return this._dirEdgeList
+ };
+ BufferSubgraph.prototype.interfaces_ = function interfaces_ () {
+ return [Comparable]
+ };
+ BufferSubgraph.prototype.getClass = function getClass () {
+ return BufferSubgraph
+ };
+
+ var TopologyLocation = function TopologyLocation () {
+ var this$1 = this;
+
+ this.location = null;
+ if (arguments.length === 1) {
+ if (arguments[0] instanceof Array) {
+ var location = arguments[0];
+ this.init(location.length);
+ } else if (Number.isInteger(arguments[0])) {
+ var on = arguments[0];
+ this.init(1);
+ this.location[Position.ON] = on;
+ } else if (arguments[0] instanceof TopologyLocation) {
+ var gl = arguments[0];
+ this.init(gl.location.length);
+ if (gl !== null) {
+ for (var i = 0; i < this.location.length; i++) {
+ this$1.location[i] = gl.location[i];
+ }
+ }
+ }
+ } else if (arguments.length === 3) {
+ var on$1 = arguments[0];
+ var left = arguments[1];
+ var right = arguments[2];
+ this.init(3);
+ this.location[Position.ON] = on$1;
+ this.location[Position.LEFT] = left;
+ this.location[Position.RIGHT] = right;
+ }
+ };
+ TopologyLocation.prototype.setAllLocations = function setAllLocations (locValue) {
+ var this$1 = this;
+
+ for (var i = 0; i < this.location.length; i++) {
+ this$1.location[i] = locValue;
+ }
+ };
+ TopologyLocation.prototype.isNull = function isNull () {
+ var this$1 = this;
+
+ for (var i = 0; i < this.location.length; i++) {
+ if (this$1.location[i] !== Location.NONE) { return false }
+ }
+ return true
+ };
+ TopologyLocation.prototype.setAllLocationsIfNull = function setAllLocationsIfNull (locValue) {
+ var this$1 = this;
+
+ for (var i = 0; i < this.location.length; i++) {
+ if (this$1.location[i] === Location.NONE) { this$1.location[i] = locValue; }
+ }
+ };
+ TopologyLocation.prototype.isLine = function isLine () {
+ return this.location.length === 1
+ };
+ TopologyLocation.prototype.merge = function merge (gl) {
+ var this$1 = this;
+
+ if (gl.location.length > this.location.length) {
+ var newLoc = new Array(3).fill(null);
+ newLoc[Position.ON] = this.location[Position.ON];
+ newLoc[Position.LEFT] = Location.NONE;
+ newLoc[Position.RIGHT] = Location.NONE;
+ this.location = newLoc;
+ }
+ for (var i = 0; i < this.location.length; i++) {
+ if (this$1.location[i] === Location.NONE && i < gl.location.length) { this$1.location[i] = gl.location[i]; }
+ }
+ };
+ TopologyLocation.prototype.getLocations = function getLocations () {
+ return this.location
+ };
+ TopologyLocation.prototype.flip = function flip () {
+ if (this.location.length <= 1) { return null }
+ var temp = this.location[Position.LEFT];
+ this.location[Position.LEFT] = this.location[Position.RIGHT];
+ this.location[Position.RIGHT] = temp;
+ };
+ TopologyLocation.prototype.toString = function toString () {
+ var buf = new StringBuffer();
+ if (this.location.length > 1) { buf.append(Location.toLocationSymbol(this.location[Position.LEFT])); }
+ buf.append(Location.toLocationSymbol(this.location[Position.ON]));
+ if (this.location.length > 1) { buf.append(Location.toLocationSymbol(this.location[Position.RIGHT])); }
+ return buf.toString()
+ };
+ TopologyLocation.prototype.setLocations = function setLocations (on, left, right) {
+ this.location[Position.ON] = on;
+ this.location[Position.LEFT] = left;
+ this.location[Position.RIGHT] = right;
+ };
+ TopologyLocation.prototype.get = function get (posIndex) {
+ if (posIndex < this.location.length) { return this.location[posIndex] }
+ return Location.NONE
+ };
+ TopologyLocation.prototype.isArea = function isArea () {
+ return this.location.length > 1
+ };
+ TopologyLocation.prototype.isAnyNull = function isAnyNull () {
+ var this$1 = this;
+
+ for (var i = 0; i < this.location.length; i++) {
+ if (this$1.location[i] === Location.NONE) { return true }
+ }
+ return false
+ };
+ TopologyLocation.prototype.setLocation = function setLocation () {
+ if (arguments.length === 1) {
+ var locValue = arguments[0];
+ this.setLocation(Position.ON, locValue);
+ } else if (arguments.length === 2) {
+ var locIndex = arguments[0];
+ var locValue$1 = arguments[1];
+ this.location[locIndex] = locValue$1;
+ }
+ };
+ TopologyLocation.prototype.init = function init (size) {
+ this.location = new Array(size).fill(null);
+ this.setAllLocations(Location.NONE);
+ };
+ TopologyLocation.prototype.isEqualOnSide = function isEqualOnSide (le, locIndex) {
+ return this.location[locIndex] === le.location[locIndex]
+ };
+ TopologyLocation.prototype.allPositionsEqual = function allPositionsEqual (loc) {
+ var this$1 = this;
+
+ for (var i = 0; i < this.location.length; i++) {
+ if (this$1.location[i] !== loc) { return false }
+ }
+ return true
+ };
+ TopologyLocation.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ TopologyLocation.prototype.getClass = function getClass () {
+ return TopologyLocation
+ };
+
+ var Label = function Label () {
+ this.elt = new Array(2).fill(null);
+ if (arguments.length === 1) {
+ if (Number.isInteger(arguments[0])) {
+ var onLoc = arguments[0];
+ this.elt[0] = new TopologyLocation(onLoc);
+ this.elt[1] = new TopologyLocation(onLoc);
+ } else if (arguments[0] instanceof Label) {
+ var lbl = arguments[0];
+ this.elt[0] = new TopologyLocation(lbl.elt[0]);
+ this.elt[1] = new TopologyLocation(lbl.elt[1]);
+ }
+ } else if (arguments.length === 2) {
+ var geomIndex = arguments[0];
+ var onLoc$1 = arguments[1];
+ this.elt[0] = new TopologyLocation(Location.NONE);
+ this.elt[1] = new TopologyLocation(Location.NONE);
+ this.elt[geomIndex].setLocation(onLoc$1);
+ } else if (arguments.length === 3) {
+ var onLoc$2 = arguments[0];
+ var leftLoc = arguments[1];
+ var rightLoc = arguments[2];
+ this.elt[0] = new TopologyLocation(onLoc$2, leftLoc, rightLoc);
+ this.elt[1] = new TopologyLocation(onLoc$2, leftLoc, rightLoc);
+ } else if (arguments.length === 4) {
+ var geomIndex$1 = arguments[0];
+ var onLoc$3 = arguments[1];
+ var leftLoc$1 = arguments[2];
+ var rightLoc$1 = arguments[3];
+ this.elt[0] = new TopologyLocation(Location.NONE, Location.NONE, Location.NONE);
+ this.elt[1] = new TopologyLocation(Location.NONE, Location.NONE, Location.NONE);
+ this.elt[geomIndex$1].setLocations(onLoc$3, leftLoc$1, rightLoc$1);
+ }
+ };
+ Label.prototype.getGeometryCount = function getGeometryCount () {
+ var count = 0;
+ if (!this.elt[0].isNull()) { count++; }
+ if (!this.elt[1].isNull()) { count++; }
+ return count
+ };
+ Label.prototype.setAllLocations = function setAllLocations (geomIndex, location) {
+ this.elt[geomIndex].setAllLocations(location);
+ };
+ Label.prototype.isNull = function isNull (geomIndex) {
+ return this.elt[geomIndex].isNull()
+ };
+ Label.prototype.setAllLocationsIfNull = function setAllLocationsIfNull () {
+ if (arguments.length === 1) {
+ var location = arguments[0];
+ this.setAllLocationsIfNull(0, location);
+ this.setAllLocationsIfNull(1, location);
+ } else if (arguments.length === 2) {
+ var geomIndex = arguments[0];
+ var location$1 = arguments[1];
+ this.elt[geomIndex].setAllLocationsIfNull(location$1);
+ }
+ };
+ Label.prototype.isLine = function isLine (geomIndex) {
+ return this.elt[geomIndex].isLine()
+ };
+ Label.prototype.merge = function merge (lbl) {
+ var this$1 = this;
+
+ for (var i = 0; i < 2; i++) {
+ if (this$1.elt[i] === null && lbl.elt[i] !== null) {
+ this$1.elt[i] = new TopologyLocation(lbl.elt[i]);
+ } else {
+ this$1.elt[i].merge(lbl.elt[i]);
+ }
+ }
+ };
+ Label.prototype.flip = function flip () {
+ this.elt[0].flip();
+ this.elt[1].flip();
+ };
+ Label.prototype.getLocation = function getLocation () {
+ if (arguments.length === 1) {
+ var geomIndex = arguments[0];
+ return this.elt[geomIndex].get(Position.ON)
+ } else if (arguments.length === 2) {
+ var geomIndex$1 = arguments[0];
+ var posIndex = arguments[1];
+ return this.elt[geomIndex$1].get(posIndex)
+ }
+ };
+ Label.prototype.toString = function toString () {
+ var buf = new StringBuffer();
+ if (this.elt[0] !== null) {
+ buf.append('A:');
+ buf.append(this.elt[0].toString());
+ }
+ if (this.elt[1] !== null) {
+ buf.append(' B:');
+ buf.append(this.elt[1].toString());
+ }
+ return buf.toString()
+ };
+ Label.prototype.isArea = function isArea () {
+ if (arguments.length === 0) {
+ return this.elt[0].isArea() || this.elt[1].isArea()
+ } else if (arguments.length === 1) {
+ var geomIndex = arguments[0];
+ return this.elt[geomIndex].isArea()
+ }
+ };
+ Label.prototype.isAnyNull = function isAnyNull (geomIndex) {
+ return this.elt[geomIndex].isAnyNull()
+ };
+ Label.prototype.setLocation = function setLocation () {
+ if (arguments.length === 2) {
+ var geomIndex = arguments[0];
+ var location = arguments[1];
+ this.elt[geomIndex].setLocation(Position.ON, location);
+ } else if (arguments.length === 3) {
+ var geomIndex$1 = arguments[0];
+ var posIndex = arguments[1];
+ var location$1 = arguments[2];
+ this.elt[geomIndex$1].setLocation(posIndex, location$1);
+ }
+ };
+ Label.prototype.isEqualOnSide = function isEqualOnSide (lbl, side) {
+ return this.elt[0].isEqualOnSide(lbl.elt[0], side) && this.elt[1].isEqualOnSide(lbl.elt[1], side)
+ };
+ Label.prototype.allPositionsEqual = function allPositionsEqual (geomIndex, loc) {
+ return this.elt[geomIndex].allPositionsEqual(loc)
+ };
+ Label.prototype.toLine = function toLine (geomIndex) {
+ if (this.elt[geomIndex].isArea()) { this.elt[geomIndex] = new TopologyLocation(this.elt[geomIndex].location[0]); }
+ };
+ Label.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ Label.prototype.getClass = function getClass () {
+ return Label
+ };
+ Label.toLineLabel = function toLineLabel (label) {
+ var lineLabel = new Label(Location.NONE);
+ for (var i = 0; i < 2; i++) {
+ lineLabel.setLocation(i, label.getLocation(i));
+ }
+ return lineLabel
+ };
+
+ var EdgeRing = function EdgeRing () {
+ this._startDe = null;
+ this._maxNodeDegree = -1;
+ this._edges = new ArrayList();
+ this._pts = new ArrayList();
+ this._label = new Label(Location.NONE);
+ this._ring = null;
+ this._isHole = null;
+ this._shell = null;
+ this._holes = new ArrayList();
+ this._geometryFactory = null;
+ var start = arguments[0];
+ var geometryFactory = arguments[1];
+ this._geometryFactory = geometryFactory;
+ this.computePoints(start);
+ this.computeRing();
+ };
+ EdgeRing.prototype.computeRing = function computeRing () {
+ var this$1 = this;
+
+ if (this._ring !== null) { return null }
+ var coord = new Array(this._pts.size()).fill(null);
+ for (var i = 0; i < this._pts.size(); i++) {
+ coord[i] = this$1._pts.get(i);
+ }
+ this._ring = this._geometryFactory.createLinearRing(coord);
+ this._isHole = CGAlgorithms.isCCW(this._ring.getCoordinates());
+ };
+ EdgeRing.prototype.isIsolated = function isIsolated () {
+ return this._label.getGeometryCount() === 1
+ };
+ EdgeRing.prototype.computePoints = function computePoints (start) {
+ var this$1 = this;
+
+ this._startDe = start;
+ var de = start;
+ var isFirstEdge = true;
+ do {
+ if (de === null) { throw new TopologyException('Found null DirectedEdge') }
+ if (de.getEdgeRing() === this$1) { throw new TopologyException('Directed Edge visited twice during ring-building at ' + de.getCoordinate()) }
+ this$1._edges.add(de);
+ var label = de.getLabel();
+ Assert.isTrue(label.isArea());
+ this$1.mergeLabel(label);
+ this$1.addPoints(de.getEdge(), de.isForward(), isFirstEdge);
+ isFirstEdge = false;
+ this$1.setEdgeRing(de, this$1);
+ de = this$1.getNext(de);
+ } while (de !== this._startDe)
+ };
+ EdgeRing.prototype.getLinearRing = function getLinearRing () {
+ return this._ring
+ };
+ EdgeRing.prototype.getCoordinate = function getCoordinate (i) {
+ return this._pts.get(i)
+ };
+ EdgeRing.prototype.computeMaxNodeDegree = function computeMaxNodeDegree () {
+ var this$1 = this;
+
+ this._maxNodeDegree = 0;
+ var de = this._startDe;
+ do {
+ var node = de.getNode();
+ var degree = node.getEdges().getOutgoingDegree(this$1);
+ if (degree > this$1._maxNodeDegree) { this$1._maxNodeDegree = degree; }
+ de = this$1.getNext(de);
+ } while (de !== this._startDe)
+ this._maxNodeDegree *= 2;
+ };
+ EdgeRing.prototype.addPoints = function addPoints (edge, isForward, isFirstEdge) {
+ var this$1 = this;
+
+ var edgePts = edge.getCoordinates();
+ if (isForward) {
+ var startIndex = 1;
+ if (isFirstEdge) { startIndex = 0; }
+ for (var i = startIndex; i < edgePts.length; i++) {
+ this$1._pts.add(edgePts[i]);
+ }
+ } else {
+ var startIndex$1 = edgePts.length - 2;
+ if (isFirstEdge) { startIndex$1 = edgePts.length - 1; }
+ for (var i$1 = startIndex$1; i$1 >= 0; i$1--) {
+ this$1._pts.add(edgePts[i$1]);
+ }
+ }
+ };
+ EdgeRing.prototype.isHole = function isHole () {
+ return this._isHole
+ };
+ EdgeRing.prototype.setInResult = function setInResult () {
+ var de = this._startDe;
+ do {
+ de.getEdge().setInResult(true);
+ de = de.getNext();
+ } while (de !== this._startDe)
+ };
+ EdgeRing.prototype.containsPoint = function containsPoint (p) {
+ var shell = this.getLinearRing();
+ var env = shell.getEnvelopeInternal();
+ if (!env.contains(p)) { return false }
+ if (!CGAlgorithms.isPointInRing(p, shell.getCoordinates())) { return false }
+ for (var i = this._holes.iterator(); i.hasNext();) {
+ var hole = i.next();
+ if (hole.containsPoint(p)) { return false }
+ }
+ return true
+ };
+ EdgeRing.prototype.addHole = function addHole (ring) {
+ this._holes.add(ring);
+ };
+ EdgeRing.prototype.isShell = function isShell () {
+ return this._shell === null
+ };
+ EdgeRing.prototype.getLabel = function getLabel () {
+ return this._label
+ };
+ EdgeRing.prototype.getEdges = function getEdges () {
+ return this._edges
+ };
+ EdgeRing.prototype.getMaxNodeDegree = function getMaxNodeDegree () {
+ if (this._maxNodeDegree < 0) { this.computeMaxNodeDegree(); }
+ return this._maxNodeDegree
+ };
+ EdgeRing.prototype.getShell = function getShell () {
+ return this._shell
+ };
+ EdgeRing.prototype.mergeLabel = function mergeLabel () {
+ if (arguments.length === 1) {
+ var deLabel = arguments[0];
+ this.mergeLabel(deLabel, 0);
+ this.mergeLabel(deLabel, 1);
+ } else if (arguments.length === 2) {
+ var deLabel$1 = arguments[0];
+ var geomIndex = arguments[1];
+ var loc = deLabel$1.getLocation(geomIndex, Position.RIGHT);
+ if (loc === Location.NONE) { return null }
+ if (this._label.getLocation(geomIndex) === Location.NONE) {
+ this._label.setLocation(geomIndex, loc);
+ return null
+ }
+ }
+ };
+ EdgeRing.prototype.setShell = function setShell (shell) {
+ this._shell = shell;
+ if (shell !== null) { shell.addHole(this); }
+ };
+ EdgeRing.prototype.toPolygon = function toPolygon (geometryFactory) {
+ var this$1 = this;
+
+ var holeLR = new Array(this._holes.size()).fill(null);
+ for (var i = 0; i < this._holes.size(); i++) {
+ holeLR[i] = this$1._holes.get(i).getLinearRing();
+ }
+ var poly = geometryFactory.createPolygon(this.getLinearRing(), holeLR);
+ return poly
+ };
+ EdgeRing.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ EdgeRing.prototype.getClass = function getClass () {
+ return EdgeRing
+ };
+
+ var MinimalEdgeRing = (function (EdgeRing$$1) {
+ function MinimalEdgeRing () {
+ var start = arguments[0];
+ var geometryFactory = arguments[1];
+ EdgeRing$$1.call(this, start, geometryFactory);
+ }
+
+ if ( EdgeRing$$1 ) MinimalEdgeRing.__proto__ = EdgeRing$$1;
+ MinimalEdgeRing.prototype = Object.create( EdgeRing$$1 && EdgeRing$$1.prototype );
+ MinimalEdgeRing.prototype.constructor = MinimalEdgeRing;
+ MinimalEdgeRing.prototype.setEdgeRing = function setEdgeRing (de, er) {
+ de.setMinEdgeRing(er);
+ };
+ MinimalEdgeRing.prototype.getNext = function getNext (de) {
+ return de.getNextMin()
+ };
+ MinimalEdgeRing.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ MinimalEdgeRing.prototype.getClass = function getClass () {
+ return MinimalEdgeRing
+ };
+
+ return MinimalEdgeRing;
+ }(EdgeRing));
+
+ var MaximalEdgeRing = (function (EdgeRing$$1) {
+ function MaximalEdgeRing () {
+ var start = arguments[0];
+ var geometryFactory = arguments[1];
+ EdgeRing$$1.call(this, start, geometryFactory);
+ }
+
+ if ( EdgeRing$$1 ) MaximalEdgeRing.__proto__ = EdgeRing$$1;
+ MaximalEdgeRing.prototype = Object.create( EdgeRing$$1 && EdgeRing$$1.prototype );
+ MaximalEdgeRing.prototype.constructor = MaximalEdgeRing;
+ MaximalEdgeRing.prototype.buildMinimalRings = function buildMinimalRings () {
+ var this$1 = this;
+
+ var minEdgeRings = new ArrayList();
+ var de = this._startDe;
+ do {
+ if (de.getMinEdgeRing() === null) {
+ var minEr = new MinimalEdgeRing(de, this$1._geometryFactory);
+ minEdgeRings.add(minEr);
+ }
+ de = de.getNext();
+ } while (de !== this._startDe)
+ return minEdgeRings
+ };
+ MaximalEdgeRing.prototype.setEdgeRing = function setEdgeRing (de, er) {
+ de.setEdgeRing(er);
+ };
+ MaximalEdgeRing.prototype.linkDirectedEdgesForMinimalEdgeRings = function linkDirectedEdgesForMinimalEdgeRings () {
+ var this$1 = this;
+
+ var de = this._startDe;
+ do {
+ var node = de.getNode();
+ node.getEdges().linkMinimalDirectedEdges(this$1);
+ de = de.getNext();
+ } while (de !== this._startDe)
+ };
+ MaximalEdgeRing.prototype.getNext = function getNext (de) {
+ return de.getNext()
+ };
+ MaximalEdgeRing.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ MaximalEdgeRing.prototype.getClass = function getClass () {
+ return MaximalEdgeRing
+ };
+
+ return MaximalEdgeRing;
+ }(EdgeRing));
+
+ var GraphComponent = function GraphComponent () {
+ this._label = null;
+ this._isInResult = false;
+ this._isCovered = false;
+ this._isCoveredSet = false;
+ this._isVisited = false;
+ if (arguments.length === 0) ; else if (arguments.length === 1) {
+ var label = arguments[0];
+ this._label = label;
+ }
+ };
+ GraphComponent.prototype.setVisited = function setVisited (isVisited) {
+ this._isVisited = isVisited;
+ };
+ GraphComponent.prototype.setInResult = function setInResult (isInResult) {
+ this._isInResult = isInResult;
+ };
+ GraphComponent.prototype.isCovered = function isCovered () {
+ return this._isCovered
+ };
+ GraphComponent.prototype.isCoveredSet = function isCoveredSet () {
+ return this._isCoveredSet
+ };
+ GraphComponent.prototype.setLabel = function setLabel (label) {
+ this._label = label;
+ };
+ GraphComponent.prototype.getLabel = function getLabel () {
+ return this._label
+ };
+ GraphComponent.prototype.setCovered = function setCovered (isCovered) {
+ this._isCovered = isCovered;
+ this._isCoveredSet = true;
+ };
+ GraphComponent.prototype.updateIM = function updateIM (im) {
+ Assert.isTrue(this._label.getGeometryCount() >= 2, 'found partial label');
+ this.computeIM(im);
+ };
+ GraphComponent.prototype.isInResult = function isInResult () {
+ return this._isInResult
+ };
+ GraphComponent.prototype.isVisited = function isVisited () {
+ return this._isVisited
+ };
+ GraphComponent.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ GraphComponent.prototype.getClass = function getClass () {
+ return GraphComponent
+ };
+
+ var Node$1 = (function (GraphComponent$$1) {
+ function Node () {
+ GraphComponent$$1.call(this);
+ this._coord = null;
+ this._edges = null;
+ var coord = arguments[0];
+ var edges = arguments[1];
+ this._coord = coord;
+ this._edges = edges;
+ this._label = new Label(0, Location.NONE);
+ }
+
+ if ( GraphComponent$$1 ) Node.__proto__ = GraphComponent$$1;
+ Node.prototype = Object.create( GraphComponent$$1 && GraphComponent$$1.prototype );
+ Node.prototype.constructor = Node;
+ Node.prototype.isIncidentEdgeInResult = function isIncidentEdgeInResult () {
+ for (var it = this.getEdges().getEdges().iterator(); it.hasNext();) {
+ var de = it.next();
+ if (de.getEdge().isInResult()) { return true }
+ }
+ return false
+ };
+ Node.prototype.isIsolated = function isIsolated () {
+ return this._label.getGeometryCount() === 1
+ };
+ Node.prototype.getCoordinate = function getCoordinate () {
+ return this._coord
+ };
+ Node.prototype.print = function print (out) {
+ out.println('node ' + this._coord + ' lbl: ' + this._label);
+ };
+ Node.prototype.computeIM = function computeIM (im) {};
+ Node.prototype.computeMergedLocation = function computeMergedLocation (label2, eltIndex) {
+ var loc = Location.NONE;
+ loc = this._label.getLocation(eltIndex);
+ if (!label2.isNull(eltIndex)) {
+ var nLoc = label2.getLocation(eltIndex);
+ if (loc !== Location.BOUNDARY) { loc = nLoc; }
+ }
+ return loc
+ };
+ Node.prototype.setLabel = function setLabel () {
+ if (arguments.length === 2) {
+ var argIndex = arguments[0];
+ var onLocation = arguments[1];
+ if (this._label === null) {
+ this._label = new Label(argIndex, onLocation);
+ } else { this._label.setLocation(argIndex, onLocation); }
+ } else { return GraphComponent$$1.prototype.setLabel.apply(this, arguments) }
+ };
+ Node.prototype.getEdges = function getEdges () {
+ return this._edges
+ };
+ Node.prototype.mergeLabel = function mergeLabel () {
+ var this$1 = this;
+
+ if (arguments[0] instanceof Node) {
+ var n = arguments[0];
+ this.mergeLabel(n._label);
+ } else if (arguments[0] instanceof Label) {
+ var label2 = arguments[0];
+ for (var i = 0; i < 2; i++) {
+ var loc = this$1.computeMergedLocation(label2, i);
+ var thisLoc = this$1._label.getLocation(i);
+ if (thisLoc === Location.NONE) { this$1._label.setLocation(i, loc); }
+ }
+ }
+ };
+ Node.prototype.add = function add (e) {
+ this._edges.insert(e);
+ e.setNode(this);
+ };
+ Node.prototype.setLabelBoundary = function setLabelBoundary (argIndex) {
+ if (this._label === null) { return null }
+ var loc = Location.NONE;
+ if (this._label !== null) { loc = this._label.getLocation(argIndex); }
+ var newLoc = null;
+ switch (loc) {
+ case Location.BOUNDARY:
+ newLoc = Location.INTERIOR;
+ break
+ case Location.INTERIOR:
+ newLoc = Location.BOUNDARY;
+ break
+ default:
+ newLoc = Location.BOUNDARY;
+ break
+ }
+ this._label.setLocation(argIndex, newLoc);
+ };
+ Node.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ Node.prototype.getClass = function getClass () {
+ return Node
+ };
+
+ return Node;
+ }(GraphComponent));
+
+ var NodeMap = function NodeMap () {
+ this.nodeMap = new TreeMap();
+ this.nodeFact = null;
+ var nodeFact = arguments[0];
+ this.nodeFact = nodeFact;
+ };
+ NodeMap.prototype.find = function find (coord) {
+ return this.nodeMap.get(coord)
+ };
+ NodeMap.prototype.addNode = function addNode () {
+ if (arguments[0] instanceof Coordinate) {
+ var coord = arguments[0];
+ var node = this.nodeMap.get(coord);
+ if (node === null) {
+ node = this.nodeFact.createNode(coord);
+ this.nodeMap.put(coord, node);
+ }
+ return node
+ } else if (arguments[0] instanceof Node$1) {
+ var n = arguments[0];
+ var node$1 = this.nodeMap.get(n.getCoordinate());
+ if (node$1 === null) {
+ this.nodeMap.put(n.getCoordinate(), n);
+ return n
+ }
+ node$1.mergeLabel(n);
+ return node$1
+ }
+ };
+ NodeMap.prototype.print = function print (out) {
+ for (var it = this.iterator(); it.hasNext();) {
+ var n = it.next();
+ n.print(out);
+ }
+ };
+ NodeMap.prototype.iterator = function iterator () {
+ return this.nodeMap.values().iterator()
+ };
+ NodeMap.prototype.values = function values () {
+ return this.nodeMap.values()
+ };
+ NodeMap.prototype.getBoundaryNodes = function getBoundaryNodes (geomIndex) {
+ var bdyNodes = new ArrayList();
+ for (var i = this.iterator(); i.hasNext();) {
+ var node = i.next();
+ if (node.getLabel().getLocation(geomIndex) === Location.BOUNDARY) { bdyNodes.add(node); }
+ }
+ return bdyNodes
+ };
+ NodeMap.prototype.add = function add (e) {
+ var p = e.getCoordinate();
+ var n = this.addNode(p);
+ n.add(e);
+ };
+ NodeMap.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ NodeMap.prototype.getClass = function getClass () {
+ return NodeMap
+ };
+
+ var Quadrant = function Quadrant () {};
+
+ var staticAccessors$21 = { NE: { configurable: true },NW: { configurable: true },SW: { configurable: true },SE: { configurable: true } };
+
+ Quadrant.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ Quadrant.prototype.getClass = function getClass () {
+ return Quadrant
+ };
+ Quadrant.isNorthern = function isNorthern (quad) {
+ return quad === Quadrant.NE || quad === Quadrant.NW
+ };
+ Quadrant.isOpposite = function isOpposite (quad1, quad2) {
+ if (quad1 === quad2) { return false }
+ var diff = (quad1 - quad2 + 4) % 4;
+ if (diff === 2) { return true }
+ return false
+ };
+ Quadrant.commonHalfPlane = function commonHalfPlane (quad1, quad2) {
+ if (quad1 === quad2) { return quad1 }
+ var diff = (quad1 - quad2 + 4) % 4;
+ if (diff === 2) { return -1 }
+ var min = quad1 < quad2 ? quad1 : quad2;
+ var max = quad1 > quad2 ? quad1 : quad2;
+ if (min === 0 && max === 3) { return 3 }
+ return min
+ };
+ Quadrant.isInHalfPlane = function isInHalfPlane (quad, halfPlane) {
+ if (halfPlane === Quadrant.SE) {
+ return quad === Quadrant.SE || quad === Quadrant.SW
+ }
+ return quad === halfPlane || quad === halfPlane + 1
+ };
+ Quadrant.quadrant = function quadrant () {
+ if (typeof arguments[0] === 'number' && typeof arguments[1] === 'number') {
+ var dx = arguments[0];
+ var dy = arguments[1];
+ if (dx === 0.0 && dy === 0.0) { throw new IllegalArgumentException('Cannot compute the quadrant for point ( ' + dx + ', ' + dy + ' )') }
+ if (dx >= 0.0) {
+ if (dy >= 0.0) { return Quadrant.NE; } else { return Quadrant.SE }
+ } else {
+ if (dy >= 0.0) { return Quadrant.NW; } else { return Quadrant.SW }
+ }
+ } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Coordinate) {
+ var p0 = arguments[0];
+ var p1 = arguments[1];
+ if (p1.x === p0.x && p1.y === p0.y) { throw new IllegalArgumentException('Cannot compute the quadrant for two identical points ' + p0) }
+ if (p1.x >= p0.x) {
+ if (p1.y >= p0.y) { return Quadrant.NE; } else { return Quadrant.SE }
+ } else {
+ if (p1.y >= p0.y) { return Quadrant.NW; } else { return Quadrant.SW }
+ }
+ }
+ };
+ staticAccessors$21.NE.get = function () { return 0 };
+ staticAccessors$21.NW.get = function () { return 1 };
+ staticAccessors$21.SW.get = function () { return 2 };
+ staticAccessors$21.SE.get = function () { return 3 };
+
+ Object.defineProperties( Quadrant, staticAccessors$21 );
+
+ var EdgeEnd = function EdgeEnd () {
+ this._edge = null;
+ this._label = null;
+ this._node = null;
+ this._p0 = null;
+ this._p1 = null;
+ this._dx = null;
+ this._dy = null;
+ this._quadrant = null;
+ if (arguments.length === 1) {
+ var edge = arguments[0];
+ this._edge = edge;
+ } else if (arguments.length === 3) {
+ var edge$1 = arguments[0];
+ var p0 = arguments[1];
+ var p1 = arguments[2];
+ var label = null;
+ this._edge = edge$1;
+ this.init(p0, p1);
+ this._label = label;
+ } else if (arguments.length === 4) {
+ var edge$2 = arguments[0];
+ var p0$1 = arguments[1];
+ var p1$1 = arguments[2];
+ var label$1 = arguments[3];
+ this._edge = edge$2;
+ this.init(p0$1, p1$1);
+ this._label = label$1;
+ }
+ };
+ EdgeEnd.prototype.compareDirection = function compareDirection (e) {
+ if (this._dx === e._dx && this._dy === e._dy) { return 0 }
+ if (this._quadrant > e._quadrant) { return 1 }
+ if (this._quadrant < e._quadrant) { return -1 }
+ return CGAlgorithms.computeOrientation(e._p0, e._p1, this._p1)
+ };
+ EdgeEnd.prototype.getDy = function getDy () {
+ return this._dy
+ };
+ EdgeEnd.prototype.getCoordinate = function getCoordinate () {
+ return this._p0
+ };
+ EdgeEnd.prototype.setNode = function setNode (node) {
+ this._node = node;
+ };
+ EdgeEnd.prototype.print = function print (out) {
+ var angle = Math.atan2(this._dy, this._dx);
+ var className = this.getClass().getName();
+ var lastDotPos = className.lastIndexOf('.');
+ var name = className.substring(lastDotPos + 1);
+ out.print(' ' + name + ': ' + this._p0 + ' - ' + this._p1 + ' ' + this._quadrant + ':' + angle + ' ' + this._label);
+ };
+ EdgeEnd.prototype.compareTo = function compareTo (obj) {
+ var e = obj;
+ return this.compareDirection(e)
+ };
+ EdgeEnd.prototype.getDirectedCoordinate = function getDirectedCoordinate () {
+ return this._p1
+ };
+ EdgeEnd.prototype.getDx = function getDx () {
+ return this._dx
+ };
+ EdgeEnd.prototype.getLabel = function getLabel () {
+ return this._label
+ };
+ EdgeEnd.prototype.getEdge = function getEdge () {
+ return this._edge
+ };
+ EdgeEnd.prototype.getQuadrant = function getQuadrant () {
+ return this._quadrant
+ };
+ EdgeEnd.prototype.getNode = function getNode () {
+ return this._node
+ };
+ EdgeEnd.prototype.toString = function toString () {
+ var angle = Math.atan2(this._dy, this._dx);
+ var className = this.getClass().getName();
+ var lastDotPos = className.lastIndexOf('.');
+ var name = className.substring(lastDotPos + 1);
+ return ' ' + name + ': ' + this._p0 + ' - ' + this._p1 + ' ' + this._quadrant + ':' + angle + ' ' + this._label
+ };
+ EdgeEnd.prototype.computeLabel = function computeLabel (boundaryNodeRule) {};
+ EdgeEnd.prototype.init = function init (p0, p1) {
+ this._p0 = p0;
+ this._p1 = p1;
+ this._dx = p1.x - p0.x;
+ this._dy = p1.y - p0.y;
+ this._quadrant = Quadrant.quadrant(this._dx, this._dy);
+ Assert.isTrue(!(this._dx === 0 && this._dy === 0), 'EdgeEnd with identical endpoints found');
+ };
+ EdgeEnd.prototype.interfaces_ = function interfaces_ () {
+ return [Comparable]
+ };
+ EdgeEnd.prototype.getClass = function getClass () {
+ return EdgeEnd
+ };
+
+ var DirectedEdge = (function (EdgeEnd$$1) {
+ function DirectedEdge () {
+ var edge = arguments[0];
+ var isForward = arguments[1];
+ EdgeEnd$$1.call(this, edge);
+ this._isForward = null;
+ this._isInResult = false;
+ this._isVisited = false;
+ this._sym = null;
+ this._next = null;
+ this._nextMin = null;
+ this._edgeRing = null;
+ this._minEdgeRing = null;
+ this._depth = [0, -999, -999];
+ this._isForward = isForward;
+ if (isForward) {
+ this.init(edge.getCoordinate(0), edge.getCoordinate(1));
+ } else {
+ var n = edge.getNumPoints() - 1;
+ this.init(edge.getCoordinate(n), edge.getCoordinate(n - 1));
+ }
+ this.computeDirectedLabel();
+ }
+
+ if ( EdgeEnd$$1 ) DirectedEdge.__proto__ = EdgeEnd$$1;
+ DirectedEdge.prototype = Object.create( EdgeEnd$$1 && EdgeEnd$$1.prototype );
+ DirectedEdge.prototype.constructor = DirectedEdge;
+ DirectedEdge.prototype.getNextMin = function getNextMin () {
+ return this._nextMin
+ };
+ DirectedEdge.prototype.getDepth = function getDepth (position) {
+ return this._depth[position]
+ };
+ DirectedEdge.prototype.setVisited = function setVisited (isVisited) {
+ this._isVisited = isVisited;
+ };
+ DirectedEdge.prototype.computeDirectedLabel = function computeDirectedLabel () {
+ this._label = new Label(this._edge.getLabel());
+ if (!this._isForward) { this._label.flip(); }
+ };
+ DirectedEdge.prototype.getNext = function getNext () {
+ return this._next
+ };
+ DirectedEdge.prototype.setDepth = function setDepth (position, depthVal) {
+ if (this._depth[position] !== -999) {
+ if (this._depth[position] !== depthVal) { throw new TopologyException('assigned depths do not match', this.getCoordinate()) }
+ }
+ this._depth[position] = depthVal;
+ };
+ DirectedEdge.prototype.isInteriorAreaEdge = function isInteriorAreaEdge () {
+ var this$1 = this;
+
+ var isInteriorAreaEdge = true;
+ for (var i = 0; i < 2; i++) {
+ if (!(this$1._label.isArea(i) && this$1._label.getLocation(i, Position.LEFT) === Location.INTERIOR && this$1._label.getLocation(i, Position.RIGHT) === Location.INTERIOR)) {
+ isInteriorAreaEdge = false;
+ }
+ }
+ return isInteriorAreaEdge
+ };
+ DirectedEdge.prototype.setNextMin = function setNextMin (nextMin) {
+ this._nextMin = nextMin;
+ };
+ DirectedEdge.prototype.print = function print (out) {
+ EdgeEnd$$1.prototype.print.call(this, out);
+ out.print(' ' + this._depth[Position.LEFT] + '/' + this._depth[Position.RIGHT]);
+ out.print(' (' + this.getDepthDelta() + ')');
+ if (this._isInResult) { out.print(' inResult'); }
+ };
+ DirectedEdge.prototype.setMinEdgeRing = function setMinEdgeRing (minEdgeRing) {
+ this._minEdgeRing = minEdgeRing;
+ };
+ DirectedEdge.prototype.isLineEdge = function isLineEdge () {
+ var isLine = this._label.isLine(0) || this._label.isLine(1);
+ var isExteriorIfArea0 = !this._label.isArea(0) || this._label.allPositionsEqual(0, Location.EXTERIOR);
+ var isExteriorIfArea1 = !this._label.isArea(1) || this._label.allPositionsEqual(1, Location.EXTERIOR);
+ return isLine && isExteriorIfArea0 && isExteriorIfArea1
+ };
+ DirectedEdge.prototype.setEdgeRing = function setEdgeRing (edgeRing) {
+ this._edgeRing = edgeRing;
+ };
+ DirectedEdge.prototype.getMinEdgeRing = function getMinEdgeRing () {
+ return this._minEdgeRing
+ };
+ DirectedEdge.prototype.getDepthDelta = function getDepthDelta () {
+ var depthDelta = this._edge.getDepthDelta();
+ if (!this._isForward) { depthDelta = -depthDelta; }
+ return depthDelta
+ };
+ DirectedEdge.prototype.setInResult = function setInResult (isInResult) {
+ this._isInResult = isInResult;
+ };
+ DirectedEdge.prototype.getSym = function getSym () {
+ return this._sym
+ };
+ DirectedEdge.prototype.isForward = function isForward () {
+ return this._isForward
+ };
+ DirectedEdge.prototype.getEdge = function getEdge () {
+ return this._edge
+ };
+ DirectedEdge.prototype.printEdge = function printEdge (out) {
+ this.print(out);
+ out.print(' ');
+ if (this._isForward) { this._edge.print(out); } else { this._edge.printReverse(out); }
+ };
+ DirectedEdge.prototype.setSym = function setSym (de) {
+ this._sym = de;
+ };
+ DirectedEdge.prototype.setVisitedEdge = function setVisitedEdge (isVisited) {
+ this.setVisited(isVisited);
+ this._sym.setVisited(isVisited);
+ };
+ DirectedEdge.prototype.setEdgeDepths = function setEdgeDepths (position, depth) {
+ var depthDelta = this.getEdge().getDepthDelta();
+ if (!this._isForward) { depthDelta = -depthDelta; }
+ var directionFactor = 1;
+ if (position === Position.LEFT) { directionFactor = -1; }
+ var oppositePos = Position.opposite(position);
+ var delta = depthDelta * directionFactor;
+ var oppositeDepth = depth + delta;
+ this.setDepth(position, depth);
+ this.setDepth(oppositePos, oppositeDepth);
+ };
+ DirectedEdge.prototype.getEdgeRing = function getEdgeRing () {
+ return this._edgeRing
+ };
+ DirectedEdge.prototype.isInResult = function isInResult () {
+ return this._isInResult
+ };
+ DirectedEdge.prototype.setNext = function setNext (next) {
+ this._next = next;
+ };
+ DirectedEdge.prototype.isVisited = function isVisited () {
+ return this._isVisited
+ };
+ DirectedEdge.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ DirectedEdge.prototype.getClass = function getClass () {
+ return DirectedEdge
+ };
+ DirectedEdge.depthFactor = function depthFactor (currLocation, nextLocation) {
+ if (currLocation === Location.EXTERIOR && nextLocation === Location.INTERIOR) { return 1; } else if (currLocation === Location.INTERIOR && nextLocation === Location.EXTERIOR) { return -1 }
+ return 0
+ };
+
+ return DirectedEdge;
+ }(EdgeEnd));
+
+ var NodeFactory = function NodeFactory () {};
+
+ NodeFactory.prototype.createNode = function createNode (coord) {
+ return new Node$1(coord, null)
+ };
+ NodeFactory.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ NodeFactory.prototype.getClass = function getClass () {
+ return NodeFactory
+ };
+
+ var PlanarGraph = function PlanarGraph () {
+ this._edges = new ArrayList();
+ this._nodes = null;
+ this._edgeEndList = new ArrayList();
+ if (arguments.length === 0) {
+ this._nodes = new NodeMap(new NodeFactory());
+ } else if (arguments.length === 1) {
+ var nodeFact = arguments[0];
+ this._nodes = new NodeMap(nodeFact);
+ }
+ };
+ PlanarGraph.prototype.printEdges = function printEdges (out) {
+ var this$1 = this;
+
+ out.println('Edges:');
+ for (var i = 0; i < this._edges.size(); i++) {
+ out.println('edge ' + i + ':');
+ var e = this$1._edges.get(i);
+ e.print(out);
+ e.eiList.print(out);
+ }
+ };
+ PlanarGraph.prototype.find = function find (coord) {
+ return this._nodes.find(coord)
+ };
+ PlanarGraph.prototype.addNode = function addNode () {
+ if (arguments[0] instanceof Node$1) {
+ var node = arguments[0];
+ return this._nodes.addNode(node)
+ } else if (arguments[0] instanceof Coordinate) {
+ var coord = arguments[0];
+ return this._nodes.addNode(coord)
+ }
+ };
+ PlanarGraph.prototype.getNodeIterator = function getNodeIterator () {
+ return this._nodes.iterator()
+ };
+ PlanarGraph.prototype.linkResultDirectedEdges = function linkResultDirectedEdges () {
+ for (var nodeit = this._nodes.iterator(); nodeit.hasNext();) {
+ var node = nodeit.next();
+ node.getEdges().linkResultDirectedEdges();
+ }
+ };
+ PlanarGraph.prototype.debugPrintln = function debugPrintln (o) {
+ System.out.println(o);
+ };
+ PlanarGraph.prototype.isBoundaryNode = function isBoundaryNode (geomIndex, coord) {
+ var node = this._nodes.find(coord);
+ if (node === null) { return false }
+ var label = node.getLabel();
+ if (label !== null && label.getLocation(geomIndex) === Location.BOUNDARY) { return true }
+ return false
+ };
+ PlanarGraph.prototype.linkAllDirectedEdges = function linkAllDirectedEdges () {
+ for (var nodeit = this._nodes.iterator(); nodeit.hasNext();) {
+ var node = nodeit.next();
+ node.getEdges().linkAllDirectedEdges();
+ }
+ };
+ PlanarGraph.prototype.matchInSameDirection = function matchInSameDirection (p0, p1, ep0, ep1) {
+ if (!p0.equals(ep0)) { return false }
+ if (CGAlgorithms.computeOrientation(p0, p1, ep1) === CGAlgorithms.COLLINEAR && Quadrant.quadrant(p0, p1) === Quadrant.quadrant(ep0, ep1)) { return true }
+ return false
+ };
+ PlanarGraph.prototype.getEdgeEnds = function getEdgeEnds () {
+ return this._edgeEndList
+ };
+ PlanarGraph.prototype.debugPrint = function debugPrint (o) {
+ System.out.print(o);
+ };
+ PlanarGraph.prototype.getEdgeIterator = function getEdgeIterator () {
+ return this._edges.iterator()
+ };
+ PlanarGraph.prototype.findEdgeInSameDirection = function findEdgeInSameDirection (p0, p1) {
+ var this$1 = this;
+
+ for (var i = 0; i < this._edges.size(); i++) {
+ var e = this$1._edges.get(i);
+ var eCoord = e.getCoordinates();
+ if (this$1.matchInSameDirection(p0, p1, eCoord[0], eCoord[1])) { return e }
+ if (this$1.matchInSameDirection(p0, p1, eCoord[eCoord.length - 1], eCoord[eCoord.length - 2])) { return e }
+ }
+ return null
+ };
+ PlanarGraph.prototype.insertEdge = function insertEdge (e) {
+ this._edges.add(e);
+ };
+ PlanarGraph.prototype.findEdgeEnd = function findEdgeEnd (e) {
+ for (var i = this.getEdgeEnds().iterator(); i.hasNext();) {
+ var ee = i.next();
+ if (ee.getEdge() === e) { return ee }
+ }
+ return null
+ };
+ PlanarGraph.prototype.addEdges = function addEdges (edgesToAdd) {
+ var this$1 = this;
+
+ for (var it = edgesToAdd.iterator(); it.hasNext();) {
+ var e = it.next();
+ this$1._edges.add(e);
+ var de1 = new DirectedEdge(e, true);
+ var de2 = new DirectedEdge(e, false);
+ de1.setSym(de2);
+ de2.setSym(de1);
+ this$1.add(de1);
+ this$1.add(de2);
+ }
+ };
+ PlanarGraph.prototype.add = function add (e) {
+ this._nodes.add(e);
+ this._edgeEndList.add(e);
+ };
+ PlanarGraph.prototype.getNodes = function getNodes () {
+ return this._nodes.values()
+ };
+ PlanarGraph.prototype.findEdge = function findEdge (p0, p1) {
+ var this$1 = this;
+
+ for (var i = 0; i < this._edges.size(); i++) {
+ var e = this$1._edges.get(i);
+ var eCoord = e.getCoordinates();
+ if (p0.equals(eCoord[0]) && p1.equals(eCoord[1])) { return e }
+ }
+ return null
+ };
+ PlanarGraph.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ PlanarGraph.prototype.getClass = function getClass () {
+ return PlanarGraph
+ };
+ PlanarGraph.linkResultDirectedEdges = function linkResultDirectedEdges (nodes) {
+ for (var nodeit = nodes.iterator(); nodeit.hasNext();) {
+ var node = nodeit.next();
+ node.getEdges().linkResultDirectedEdges();
+ }
+ };
+
+ var PolygonBuilder = function PolygonBuilder () {
+ this._geometryFactory = null;
+ this._shellList = new ArrayList();
+ var geometryFactory = arguments[0];
+ this._geometryFactory = geometryFactory;
+ };
+ PolygonBuilder.prototype.sortShellsAndHoles = function sortShellsAndHoles (edgeRings, shellList, freeHoleList) {
+ for (var it = edgeRings.iterator(); it.hasNext();) {
+ var er = it.next();
+ if (er.isHole()) {
+ freeHoleList.add(er);
+ } else {
+ shellList.add(er);
+ }
+ }
+ };
+ PolygonBuilder.prototype.computePolygons = function computePolygons (shellList) {
+ var this$1 = this;
+
+ var resultPolyList = new ArrayList();
+ for (var it = shellList.iterator(); it.hasNext();) {
+ var er = it.next();
+ var poly = er.toPolygon(this$1._geometryFactory);
+ resultPolyList.add(poly);
+ }
+ return resultPolyList
+ };
+ PolygonBuilder.prototype.placeFreeHoles = function placeFreeHoles (shellList, freeHoleList) {
+ var this$1 = this;
+
+ for (var it = freeHoleList.iterator(); it.hasNext();) {
+ var hole = it.next();
+ if (hole.getShell() === null) {
+ var shell = this$1.findEdgeRingContaining(hole, shellList);
+ if (shell === null) { throw new TopologyException('unable to assign hole to a shell', hole.getCoordinate(0)) }
+ hole.setShell(shell);
+ }
+ }
+ };
+ PolygonBuilder.prototype.buildMinimalEdgeRings = function buildMinimalEdgeRings (maxEdgeRings, shellList, freeHoleList) {
+ var this$1 = this;
+
+ var edgeRings = new ArrayList();
+ for (var it = maxEdgeRings.iterator(); it.hasNext();) {
+ var er = it.next();
+ if (er.getMaxNodeDegree() > 2) {
+ er.linkDirectedEdgesForMinimalEdgeRings();
+ var minEdgeRings = er.buildMinimalRings();
+ var shell = this$1.findShell(minEdgeRings);
+ if (shell !== null) {
+ this$1.placePolygonHoles(shell, minEdgeRings);
+ shellList.add(shell);
+ } else {
+ freeHoleList.addAll(minEdgeRings);
+ }
+ } else {
+ edgeRings.add(er);
+ }
+ }
+ return edgeRings
+ };
+ PolygonBuilder.prototype.containsPoint = function containsPoint (p) {
+ for (var it = this._shellList.iterator(); it.hasNext();) {
+ var er = it.next();
+ if (er.containsPoint(p)) { return true }
+ }
+ return false
+ };
+ PolygonBuilder.prototype.buildMaximalEdgeRings = function buildMaximalEdgeRings (dirEdges) {
+ var this$1 = this;
+
+ var maxEdgeRings = new ArrayList();
+ for (var it = dirEdges.iterator(); it.hasNext();) {
+ var de = it.next();
+ if (de.isInResult() && de.getLabel().isArea()) {
+ if (de.getEdgeRing() === null) {
+ var er = new MaximalEdgeRing(de, this$1._geometryFactory);
+ maxEdgeRings.add(er);
+ er.setInResult();
+ }
+ }
+ }
+ return maxEdgeRings
+ };
+ PolygonBuilder.prototype.placePolygonHoles = function placePolygonHoles (shell, minEdgeRings) {
+ for (var it = minEdgeRings.iterator(); it.hasNext();) {
+ var er = it.next();
+ if (er.isHole()) {
+ er.setShell(shell);
+ }
+ }
+ };
+ PolygonBuilder.prototype.getPolygons = function getPolygons () {
+ var resultPolyList = this.computePolygons(this._shellList);
+ return resultPolyList
+ };
+ PolygonBuilder.prototype.findEdgeRingContaining = function findEdgeRingContaining (testEr, shellList) {
+ var testRing = testEr.getLinearRing();
+ var testEnv = testRing.getEnvelopeInternal();
+ var testPt = testRing.getCoordinateN(0);
+ var minShell = null;
+ var minEnv = null;
+ for (var it = shellList.iterator(); it.hasNext();) {
+ var tryShell = it.next();
+ var tryRing = tryShell.getLinearRing();
+ var tryEnv = tryRing.getEnvelopeInternal();
+ if (minShell !== null) { minEnv = minShell.getLinearRing().getEnvelopeInternal(); }
+ var isContained = false;
+ if (tryEnv.contains(testEnv) && CGAlgorithms.isPointInRing(testPt, tryRing.getCoordinates())) { isContained = true; }
+ if (isContained) {
+ if (minShell === null || minEnv.contains(tryEnv)) {
+ minShell = tryShell;
+ }
+ }
+ }
+ return minShell
+ };
+ PolygonBuilder.prototype.findShell = function findShell (minEdgeRings) {
+ var shellCount = 0;
+ var shell = null;
+ for (var it = minEdgeRings.iterator(); it.hasNext();) {
+ var er = it.next();
+ if (!er.isHole()) {
+ shell = er;
+ shellCount++;
+ }
+ }
+ Assert.isTrue(shellCount <= 1, 'found two shells in MinimalEdgeRing list');
+ return shell
+ };
+ PolygonBuilder.prototype.add = function add () {
+ if (arguments.length === 1) {
+ var graph = arguments[0];
+ this.add(graph.getEdgeEnds(), graph.getNodes());
+ } else if (arguments.length === 2) {
+ var dirEdges = arguments[0];
+ var nodes = arguments[1];
+ PlanarGraph.linkResultDirectedEdges(nodes);
+ var maxEdgeRings = this.buildMaximalEdgeRings(dirEdges);
+ var freeHoleList = new ArrayList();
+ var edgeRings = this.buildMinimalEdgeRings(maxEdgeRings, this._shellList, freeHoleList);
+ this.sortShellsAndHoles(edgeRings, this._shellList, freeHoleList);
+ this.placeFreeHoles(this._shellList, freeHoleList);
+ }
+ };
+ PolygonBuilder.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ PolygonBuilder.prototype.getClass = function getClass () {
+ return PolygonBuilder
+ };
+
+ var Boundable = function Boundable () {};
+
+ Boundable.prototype.getBounds = function getBounds () {};
+ Boundable.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ Boundable.prototype.getClass = function getClass () {
+ return Boundable
+ };
+
+ var ItemBoundable = function ItemBoundable () {
+ this._bounds = null;
+ this._item = null;
+ var bounds = arguments[0];
+ var item = arguments[1];
+ this._bounds = bounds;
+ this._item = item;
+ };
+ ItemBoundable.prototype.getItem = function getItem () {
+ return this._item
+ };
+ ItemBoundable.prototype.getBounds = function getBounds () {
+ return this._bounds
+ };
+ ItemBoundable.prototype.interfaces_ = function interfaces_ () {
+ return [Boundable, Serializable]
+ };
+ ItemBoundable.prototype.getClass = function getClass () {
+ return ItemBoundable
+ };
+
+ var PriorityQueue = function PriorityQueue () {
+ this._size = null;
+ this._items = null;
+ this._size = 0;
+ this._items = new ArrayList();
+ this._items.add(null);
+ };
+ PriorityQueue.prototype.poll = function poll () {
+ if (this.isEmpty()) { return null }
+ var minItem = this._items.get(1);
+ this._items.set(1, this._items.get(this._size));
+ this._size -= 1;
+ this.reorder(1);
+ return minItem
+ };
+ PriorityQueue.prototype.size = function size () {
+ return this._size
+ };
+ PriorityQueue.prototype.reorder = function reorder (hole) {
+ var this$1 = this;
+
+ var child = null;
+ var tmp = this._items.get(hole);
+ for (; hole * 2 <= this._size; hole = child) {
+ child = hole * 2;
+ if (child !== this$1._size && this$1._items.get(child + 1).compareTo(this$1._items.get(child)) < 0) { child++; }
+ if (this$1._items.get(child).compareTo(tmp) < 0) { this$1._items.set(hole, this$1._items.get(child)); } else { break }
+ }
+ this._items.set(hole, tmp);
+ };
+ PriorityQueue.prototype.clear = function clear () {
+ this._size = 0;
+ this._items.clear();
+ };
+ PriorityQueue.prototype.isEmpty = function isEmpty () {
+ return this._size === 0
+ };
+ PriorityQueue.prototype.add = function add (x) {
+ var this$1 = this;
+
+ this._items.add(null);
+ this._size += 1;
+ var hole = this._size;
+ this._items.set(0, x);
+ for (; x.compareTo(this._items.get(Math.trunc(hole / 2))) < 0; hole /= 2) {
+ this$1._items.set(hole, this$1._items.get(Math.trunc(hole / 2)));
+ }
+ this._items.set(hole, x);
+ };
+ PriorityQueue.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ PriorityQueue.prototype.getClass = function getClass () {
+ return PriorityQueue
+ };
+
+ var ItemVisitor = function ItemVisitor () {};
+
+ ItemVisitor.prototype.visitItem = function visitItem (item) {};
+ ItemVisitor.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ ItemVisitor.prototype.getClass = function getClass () {
+ return ItemVisitor
+ };
+
+ var SpatialIndex = function SpatialIndex () {};
+
+ SpatialIndex.prototype.insert = function insert (itemEnv, item) {};
+ SpatialIndex.prototype.remove = function remove (itemEnv, item) {};
+ SpatialIndex.prototype.query = function query () {
+ // if (arguments.length === 1) {
+ // const searchEnv = arguments[0]
+ // } else if (arguments.length === 2) {
+ // const searchEnv = arguments[0]
+ // const visitor = arguments[1]
+ // }
+ };
+ SpatialIndex.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ SpatialIndex.prototype.getClass = function getClass () {
+ return SpatialIndex
+ };
+
+ var AbstractNode = function AbstractNode () {
+ this._childBoundables = new ArrayList();
+ this._bounds = null;
+ this._level = null;
+ if (arguments.length === 0) ; else if (arguments.length === 1) {
+ var level = arguments[0];
+ this._level = level;
+ }
+ };
+
+ var staticAccessors$22 = { serialVersionUID: { configurable: true } };
+ AbstractNode.prototype.getLevel = function getLevel () {
+ return this._level
+ };
+ AbstractNode.prototype.size = function size () {
+ return this._childBoundables.size()
+ };
+ AbstractNode.prototype.getChildBoundables = function getChildBoundables () {
+ return this._childBoundables
+ };
+ AbstractNode.prototype.addChildBoundable = function addChildBoundable (childBoundable) {
+ Assert.isTrue(this._bounds === null);
+ this._childBoundables.add(childBoundable);
+ };
+ AbstractNode.prototype.isEmpty = function isEmpty () {
+ return this._childBoundables.isEmpty()
+ };
+ AbstractNode.prototype.getBounds = function getBounds () {
+ if (this._bounds === null) {
+ this._bounds = this.computeBounds();
+ }
+ return this._bounds
+ };
+ AbstractNode.prototype.interfaces_ = function interfaces_ () {
+ return [Boundable, Serializable]
+ };
+ AbstractNode.prototype.getClass = function getClass () {
+ return AbstractNode
+ };
+ staticAccessors$22.serialVersionUID.get = function () { return 6493722185909573708 };
+
+ Object.defineProperties( AbstractNode, staticAccessors$22 );
+
+ var Collections = function Collections () {};
+
+ Collections.reverseOrder = function reverseOrder () {
+ return {
+ compare: function compare (a, b) {
+ return b.compareTo(a)
+ }
+ }
+ };
+ Collections.min = function min (l) {
+ Collections.sort(l);
+ return l.get(0)
+ };
+ Collections.sort = function sort (l, c) {
+ var a = l.toArray();
+ if (c) {
+ Arrays.sort(a, c);
+ } else {
+ Arrays.sort(a);
+ }
+ var i = l.iterator();
+ for (var pos = 0, alen = a.length; pos < alen; pos++) {
+ i.next();
+ i.set(a[pos]);
+ }
+ };
+ Collections.singletonList = function singletonList (o) {
+ var arrayList = new ArrayList();
+ arrayList.add(o);
+ return arrayList
+ };
+
+ var BoundablePair = function BoundablePair () {
+ this._boundable1 = null;
+ this._boundable2 = null;
+ this._distance = null;
+ this._itemDistance = null;
+ var boundable1 = arguments[0];
+ var boundable2 = arguments[1];
+ var itemDistance = arguments[2];
+ this._boundable1 = boundable1;
+ this._boundable2 = boundable2;
+ this._itemDistance = itemDistance;
+ this._distance = this.distance();
+ };
+ BoundablePair.prototype.expandToQueue = function expandToQueue (priQ, minDistance) {
+ var isComp1 = BoundablePair.isComposite(this._boundable1);
+ var isComp2 = BoundablePair.isComposite(this._boundable2);
+ if (isComp1 && isComp2) {
+ if (BoundablePair.area(this._boundable1) > BoundablePair.area(this._boundable2)) {
+ this.expand(this._boundable1, this._boundable2, priQ, minDistance);
+ return null
+ } else {
+ this.expand(this._boundable2, this._boundable1, priQ, minDistance);
+ return null
+ }
+ } else if (isComp1) {
+ this.expand(this._boundable1, this._boundable2, priQ, minDistance);
+ return null
+ } else if (isComp2) {
+ this.expand(this._boundable2, this._boundable1, priQ, minDistance);
+ return null
+ }
+ throw new IllegalArgumentException('neither boundable is composite')
+ };
+ BoundablePair.prototype.isLeaves = function isLeaves () {
+ return !(BoundablePair.isComposite(this._boundable1) || BoundablePair.isComposite(this._boundable2))
+ };
+ BoundablePair.prototype.compareTo = function compareTo (o) {
+ var nd = o;
+ if (this._distance < nd._distance) { return -1 }
+ if (this._distance > nd._distance) { return 1 }
+ return 0
+ };
+ BoundablePair.prototype.expand = function expand (bndComposite, bndOther, priQ, minDistance) {
+ var this$1 = this;
+
+ var children = bndComposite.getChildBoundables();
+ for (var i = children.iterator(); i.hasNext();) {
+ var child = i.next();
+ var bp = new BoundablePair(child, bndOther, this$1._itemDistance);
+ if (bp.getDistance() < minDistance) {
+ priQ.add(bp);
+ }
+ }
+ };
+ BoundablePair.prototype.getBoundable = function getBoundable (i) {
+ if (i === 0) { return this._boundable1 }
+ return this._boundable2
+ };
+ BoundablePair.prototype.getDistance = function getDistance () {
+ return this._distance
+ };
+ BoundablePair.prototype.distance = function distance () {
+ if (this.isLeaves()) {
+ return this._itemDistance.distance(this._boundable1, this._boundable2)
+ }
+ return this._boundable1.getBounds().distance(this._boundable2.getBounds())
+ };
+ BoundablePair.prototype.interfaces_ = function interfaces_ () {
+ return [Comparable]
+ };
+ BoundablePair.prototype.getClass = function getClass () {
+ return BoundablePair
+ };
+ BoundablePair.area = function area (b) {
+ return b.getBounds().getArea()
+ };
+ BoundablePair.isComposite = function isComposite (item) {
+ return item instanceof AbstractNode
+ };
+
+ var AbstractSTRtree = function AbstractSTRtree () {
+ this._root = null;
+ this._built = false;
+ this._itemBoundables = new ArrayList();
+ this._nodeCapacity = null;
+ if (arguments.length === 0) {
+ var nodeCapacity = AbstractSTRtree.DEFAULT_NODE_CAPACITY;
+ this._nodeCapacity = nodeCapacity;
+ } else if (arguments.length === 1) {
+ var nodeCapacity$1 = arguments[0];
+ Assert.isTrue(nodeCapacity$1 > 1, 'Node capacity must be greater than 1');
+ this._nodeCapacity = nodeCapacity$1;
+ }
+ };
+
+ var staticAccessors$23 = { IntersectsOp: { configurable: true },serialVersionUID: { configurable: true },DEFAULT_NODE_CAPACITY: { configurable: true } };
+ AbstractSTRtree.prototype.getNodeCapacity = function getNodeCapacity () {
+ return this._nodeCapacity
+ };
+ AbstractSTRtree.prototype.lastNode = function lastNode (nodes) {
+ return nodes.get(nodes.size() - 1)
+ };
+ AbstractSTRtree.prototype.size = function size () {
+ var this$1 = this;
+
+ if (arguments.length === 0) {
+ if (this.isEmpty()) {
+ return 0
+ }
+ this.build();
+ return this.size(this._root)
+ } else if (arguments.length === 1) {
+ var node = arguments[0];
+ var size = 0;
+ for (var i = node.getChildBoundables().iterator(); i.hasNext();) {
+ var childBoundable = i.next();
+ if (childBoundable instanceof AbstractNode) {
+ size += this$1.size(childBoundable);
+ } else if (childBoundable instanceof ItemBoundable) {
+ size += 1;
+ }
+ }
+ return size
+ }
+ };
+ AbstractSTRtree.prototype.removeItem = function removeItem (node, item) {
+ var childToRemove = null;
+ for (var i = node.getChildBoundables().iterator(); i.hasNext();) {
+ var childBoundable = i.next();
+ if (childBoundable instanceof ItemBoundable) {
+ if (childBoundable.getItem() === item) { childToRemove = childBoundable; }
+ }
+ }
+ if (childToRemove !== null) {
+ node.getChildBoundables().remove(childToRemove);
+ return true
+ }
+ return false
+ };
+ AbstractSTRtree.prototype.itemsTree = function itemsTree () {
+ var this$1 = this;
+
+ if (arguments.length === 0) {
+ this.build();
+ var valuesTree = this.itemsTree(this._root);
+ if (valuesTree === null) { return new ArrayList() }
+ return valuesTree
+ } else if (arguments.length === 1) {
+ var node = arguments[0];
+ var valuesTreeForNode = new ArrayList();
+ for (var i = node.getChildBoundables().iterator(); i.hasNext();) {
+ var childBoundable = i.next();
+ if (childBoundable instanceof AbstractNode) {
+ var valuesTreeForChild = this$1.itemsTree(childBoundable);
+ if (valuesTreeForChild !== null) { valuesTreeForNode.add(valuesTreeForChild); }
+ } else if (childBoundable instanceof ItemBoundable) {
+ valuesTreeForNode.add(childBoundable.getItem());
+ } else {
+ Assert.shouldNeverReachHere();
+ }
+ }
+ if (valuesTreeForNode.size() <= 0) { return null }
+ return valuesTreeForNode
+ }
+ };
+ AbstractSTRtree.prototype.insert = function insert (bounds, item) {
+ Assert.isTrue(!this._built, 'Cannot insert items into an STR packed R-tree after it has been built.');
+ this._itemBoundables.add(new ItemBoundable(bounds, item));
+ };
+ AbstractSTRtree.prototype.boundablesAtLevel = function boundablesAtLevel () {
+ var this$1 = this;
+
+ if (arguments.length === 1) {
+ var level = arguments[0];
+ var boundables = new ArrayList();
+ this.boundablesAtLevel(level, this._root, boundables);
+ return boundables
+ } else if (arguments.length === 3) {
+ var level$1 = arguments[0];
+ var top = arguments[1];
+ var boundables$1 = arguments[2];
+ Assert.isTrue(level$1 > -2);
+ if (top.getLevel() === level$1) {
+ boundables$1.add(top);
+ return null
+ }
+ for (var i = top.getChildBoundables().iterator(); i.hasNext();) {
+ var boundable = i.next();
+ if (boundable instanceof AbstractNode) {
+ this$1.boundablesAtLevel(level$1, boundable, boundables$1);
+ } else {
+ Assert.isTrue(boundable instanceof ItemBoundable);
+ if (level$1 === -1) {
+ boundables$1.add(boundable);
+ }
+ }
+ }
+ return null
+ }
+ };
+ AbstractSTRtree.prototype.query = function query () {
+ var this$1 = this;
+
+ if (arguments.length === 1) {
+ var searchBounds = arguments[0];
+ this.build();
+ var matches = new ArrayList();
+ if (this.isEmpty()) {
+ return matches
+ }
+ if (this.getIntersectsOp().intersects(this._root.getBounds(), searchBounds)) {
+ this.query(searchBounds, this._root, matches);
+ }
+ return matches
+ } else if (arguments.length === 2) {
+ var searchBounds$1 = arguments[0];
+ var visitor = arguments[1];
+ this.build();
+ if (this.isEmpty()) {
+ return null
+ }
+ if (this.getIntersectsOp().intersects(this._root.getBounds(), searchBounds$1)) {
+ this.query(searchBounds$1, this._root, visitor);
+ }
+ } else if (arguments.length === 3) {
+ if (hasInterface(arguments[2], ItemVisitor) && (arguments[0] instanceof Object && arguments[1] instanceof AbstractNode)) {
+ var searchBounds$2 = arguments[0];
+ var node = arguments[1];
+ var visitor$1 = arguments[2];
+ var childBoundables = node.getChildBoundables();
+ for (var i = 0; i < childBoundables.size(); i++) {
+ var childBoundable = childBoundables.get(i);
+ if (!this$1.getIntersectsOp().intersects(childBoundable.getBounds(), searchBounds$2)) {
+ continue
+ }
+ if (childBoundable instanceof AbstractNode) {
+ this$1.query(searchBounds$2, childBoundable, visitor$1);
+ } else if (childBoundable instanceof ItemBoundable) {
+ visitor$1.visitItem(childBoundable.getItem());
+ } else {
+ Assert.shouldNeverReachHere();
+ }
+ }
+ } else if (hasInterface(arguments[2], List) && (arguments[0] instanceof Object && arguments[1] instanceof AbstractNode)) {
+ var searchBounds$3 = arguments[0];
+ var node$1 = arguments[1];
+ var matches$1 = arguments[2];
+ var childBoundables$1 = node$1.getChildBoundables();
+ for (var i$1 = 0; i$1 < childBoundables$1.size(); i$1++) {
+ var childBoundable$1 = childBoundables$1.get(i$1);
+ if (!this$1.getIntersectsOp().intersects(childBoundable$1.getBounds(), searchBounds$3)) {
+ continue
+ }
+ if (childBoundable$1 instanceof AbstractNode) {
+ this$1.query(searchBounds$3, childBoundable$1, matches$1);
+ } else if (childBoundable$1 instanceof ItemBoundable) {
+ matches$1.add(childBoundable$1.getItem());
+ } else {
+ Assert.shouldNeverReachHere();
+ }
+ }
+ }
+ }
+ };
+ AbstractSTRtree.prototype.build = function build () {
+ if (this._built) { return null }
+ this._root = this._itemBoundables.isEmpty() ? this.createNode(0) : this.createHigherLevels(this._itemBoundables, -1);
+ this._itemBoundables = null;
+ this._built = true;
+ };
+ AbstractSTRtree.prototype.getRoot = function getRoot () {
+ this.build();
+ return this._root
+ };
+ AbstractSTRtree.prototype.remove = function remove () {
+ var this$1 = this;
+
+ if (arguments.length === 2) {
+ var searchBounds = arguments[0];
+ var item = arguments[1];
+ this.build();
+ if (this.getIntersectsOp().intersects(this._root.getBounds(), searchBounds)) {
+ return this.remove(searchBounds, this._root, item)
+ }
+ return false
+ } else if (arguments.length === 3) {
+ var searchBounds$1 = arguments[0];
+ var node = arguments[1];
+ var item$1 = arguments[2];
+ var found = this.removeItem(node, item$1);
+ if (found) { return true }
+ var childToPrune = null;
+ for (var i = node.getChildBoundables().iterator(); i.hasNext();) {
+ var childBoundable = i.next();
+ if (!this$1.getIntersectsOp().intersects(childBoundable.getBounds(), searchBounds$1)) {
+ continue
+ }
+ if (childBoundable instanceof AbstractNode) {
+ found = this$1.remove(searchBounds$1, childBoundable, item$1);
+ if (found) {
+ childToPrune = childBoundable;
+ break
+ }
+ }
+ }
+ if (childToPrune !== null) {
+ if (childToPrune.getChildBoundables().isEmpty()) {
+ node.getChildBoundables().remove(childToPrune);
+ }
+ }
+ return found
+ }
+ };
+ AbstractSTRtree.prototype.createHigherLevels = function createHigherLevels (boundablesOfALevel, level) {
+ Assert.isTrue(!boundablesOfALevel.isEmpty());
+ var parentBoundables = this.createParentBoundables(boundablesOfALevel, level + 1);
+ if (parentBoundables.size() === 1) {
+ return parentBoundables.get(0)
+ }
+ return this.createHigherLevels(parentBoundables, level + 1)
+ };
+ AbstractSTRtree.prototype.depth = function depth () {
+ var this$1 = this;
+
+ if (arguments.length === 0) {
+ if (this.isEmpty()) {
+ return 0
+ }
+ this.build();
+ return this.depth(this._root)
+ } else if (arguments.length === 1) {
+ var node = arguments[0];
+ var maxChildDepth = 0;
+ for (var i = node.getChildBoundables().iterator(); i.hasNext();) {
+ var childBoundable = i.next();
+ if (childBoundable instanceof AbstractNode) {
+ var childDepth = this$1.depth(childBoundable);
+ if (childDepth > maxChildDepth) { maxChildDepth = childDepth; }
+ }
+ }
+ return maxChildDepth + 1
+ }
+ };
+ AbstractSTRtree.prototype.createParentBoundables = function createParentBoundables (childBoundables, newLevel) {
+ var this$1 = this;
+
+ Assert.isTrue(!childBoundables.isEmpty());
+ var parentBoundables = new ArrayList();
+ parentBoundables.add(this.createNode(newLevel));
+ var sortedChildBoundables = new ArrayList(childBoundables);
+ Collections.sort(sortedChildBoundables, this.getComparator());
+ for (var i = sortedChildBoundables.iterator(); i.hasNext();) {
+ var childBoundable = i.next();
+ if (this$1.lastNode(parentBoundables).getChildBoundables().size() === this$1.getNodeCapacity()) {
+ parentBoundables.add(this$1.createNode(newLevel));
+ }
+ this$1.lastNode(parentBoundables).addChildBoundable(childBoundable);
+ }
+ return parentBoundables
+ };
+ AbstractSTRtree.prototype.isEmpty = function isEmpty () {
+ if (!this._built) { return this._itemBoundables.isEmpty() }
+ return this._root.isEmpty()
+ };
+ AbstractSTRtree.prototype.interfaces_ = function interfaces_ () {
+ return [Serializable]
+ };
+ AbstractSTRtree.prototype.getClass = function getClass () {
+ return AbstractSTRtree
+ };
+ AbstractSTRtree.compareDoubles = function compareDoubles (a, b) {
+ return a > b ? 1 : a < b ? -1 : 0
+ };
+ staticAccessors$23.IntersectsOp.get = function () { return IntersectsOp };
+ staticAccessors$23.serialVersionUID.get = function () { return -3886435814360241337 };
+ staticAccessors$23.DEFAULT_NODE_CAPACITY.get = function () { return 10 };
+
+ Object.defineProperties( AbstractSTRtree, staticAccessors$23 );
+
+ var IntersectsOp = function IntersectsOp () {};
+
+ var ItemDistance = function ItemDistance () {};
+
+ ItemDistance.prototype.distance = function distance (item1, item2) {};
+ ItemDistance.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ ItemDistance.prototype.getClass = function getClass () {
+ return ItemDistance
+ };
+
+ var STRtree = (function (AbstractSTRtree$$1) {
+ function STRtree (nodeCapacity) {
+ nodeCapacity = nodeCapacity || STRtree.DEFAULT_NODE_CAPACITY;
+ AbstractSTRtree$$1.call(this, nodeCapacity);
+ }
+
+ if ( AbstractSTRtree$$1 ) STRtree.__proto__ = AbstractSTRtree$$1;
+ STRtree.prototype = Object.create( AbstractSTRtree$$1 && AbstractSTRtree$$1.prototype );
+ STRtree.prototype.constructor = STRtree;
+
+ var staticAccessors = { STRtreeNode: { configurable: true },serialVersionUID: { configurable: true },xComparator: { configurable: true },yComparator: { configurable: true },intersectsOp: { configurable: true },DEFAULT_NODE_CAPACITY: { configurable: true } };
+ STRtree.prototype.createParentBoundablesFromVerticalSlices = function createParentBoundablesFromVerticalSlices (verticalSlices, newLevel) {
+ var this$1 = this;
+
+ Assert.isTrue(verticalSlices.length > 0);
+ var parentBoundables = new ArrayList();
+ for (var i = 0; i < verticalSlices.length; i++) {
+ parentBoundables.addAll(this$1.createParentBoundablesFromVerticalSlice(verticalSlices[i], newLevel));
+ }
+ return parentBoundables
+ };
+ STRtree.prototype.createNode = function createNode (level) {
+ return new STRtreeNode(level)
+ };
+ STRtree.prototype.size = function size () {
+ if (arguments.length === 0) {
+ return AbstractSTRtree$$1.prototype.size.call(this)
+ } else { return AbstractSTRtree$$1.prototype.size.apply(this, arguments) }
+ };
+ STRtree.prototype.insert = function insert () {
+ if (arguments.length === 2) {
+ var itemEnv = arguments[0];
+ var item = arguments[1];
+ if (itemEnv.isNull()) {
+ return null
+ }
+ AbstractSTRtree$$1.prototype.insert.call(this, itemEnv, item);
+ } else { return AbstractSTRtree$$1.prototype.insert.apply(this, arguments) }
+ };
+ STRtree.prototype.getIntersectsOp = function getIntersectsOp () {
+ return STRtree.intersectsOp
+ };
+ STRtree.prototype.verticalSlices = function verticalSlices (childBoundables, sliceCount) {
+ var sliceCapacity = Math.trunc(Math.ceil(childBoundables.size() / sliceCount));
+ var slices = new Array(sliceCount).fill(null);
+ var i = childBoundables.iterator();
+ for (var j = 0; j < sliceCount; j++) {
+ slices[j] = new ArrayList();
+ var boundablesAddedToSlice = 0;
+ while (i.hasNext() && boundablesAddedToSlice < sliceCapacity) {
+ var childBoundable = i.next();
+ slices[j].add(childBoundable);
+ boundablesAddedToSlice++;
+ }
+ }
+ return slices
+ };
+ STRtree.prototype.query = function query () {
+ if (arguments.length === 1) {
+ var searchEnv = arguments[0];
+ return AbstractSTRtree$$1.prototype.query.call(this, searchEnv)
+ } else if (arguments.length === 2) {
+ var searchEnv$1 = arguments[0];
+ var visitor = arguments[1];
+ AbstractSTRtree$$1.prototype.query.call(this, searchEnv$1, visitor);
+ } else if (arguments.length === 3) {
+ if (hasInterface(arguments[2], ItemVisitor) && (arguments[0] instanceof Object && arguments[1] instanceof AbstractNode)) {
+ var searchBounds = arguments[0];
+ var node = arguments[1];
+ var visitor$1 = arguments[2];
+ AbstractSTRtree$$1.prototype.query.call(this, searchBounds, node, visitor$1);
+ } else if (hasInterface(arguments[2], List) && (arguments[0] instanceof Object && arguments[1] instanceof AbstractNode)) {
+ var searchBounds$1 = arguments[0];
+ var node$1 = arguments[1];
+ var matches = arguments[2];
+ AbstractSTRtree$$1.prototype.query.call(this, searchBounds$1, node$1, matches);
+ }
+ }
+ };
+ STRtree.prototype.getComparator = function getComparator () {
+ return STRtree.yComparator
+ };
+ STRtree.prototype.createParentBoundablesFromVerticalSlice = function createParentBoundablesFromVerticalSlice (childBoundables, newLevel) {
+ return AbstractSTRtree$$1.prototype.createParentBoundables.call(this, childBoundables, newLevel)
+ };
+ STRtree.prototype.remove = function remove () {
+ if (arguments.length === 2) {
+ var itemEnv = arguments[0];
+ var item = arguments[1];
+ return AbstractSTRtree$$1.prototype.remove.call(this, itemEnv, item)
+ } else { return AbstractSTRtree$$1.prototype.remove.apply(this, arguments) }
+ };
+ STRtree.prototype.depth = function depth () {
+ if (arguments.length === 0) {
+ return AbstractSTRtree$$1.prototype.depth.call(this)
+ } else { return AbstractSTRtree$$1.prototype.depth.apply(this, arguments) }
+ };
+ STRtree.prototype.createParentBoundables = function createParentBoundables (childBoundables, newLevel) {
+ Assert.isTrue(!childBoundables.isEmpty());
+ var minLeafCount = Math.trunc(Math.ceil(childBoundables.size() / this.getNodeCapacity()));
+ var sortedChildBoundables = new ArrayList(childBoundables);
+ Collections.sort(sortedChildBoundables, STRtree.xComparator);
+ var verticalSlices = this.verticalSlices(sortedChildBoundables, Math.trunc(Math.ceil(Math.sqrt(minLeafCount))));
+ return this.createParentBoundablesFromVerticalSlices(verticalSlices, newLevel)
+ };
+ STRtree.prototype.nearestNeighbour = function nearestNeighbour () {
+ if (arguments.length === 1) {
+ if (hasInterface(arguments[0], ItemDistance)) {
+ var itemDist = arguments[0];
+ var bp = new BoundablePair(this.getRoot(), this.getRoot(), itemDist);
+ return this.nearestNeighbour(bp)
+ } else if (arguments[0] instanceof BoundablePair) {
+ var initBndPair = arguments[0];
+ return this.nearestNeighbour(initBndPair, Double.POSITIVE_INFINITY)
+ }
+ } else if (arguments.length === 2) {
+ if (arguments[0] instanceof STRtree && hasInterface(arguments[1], ItemDistance)) {
+ var tree = arguments[0];
+ var itemDist$1 = arguments[1];
+ var bp$1 = new BoundablePair(this.getRoot(), tree.getRoot(), itemDist$1);
+ return this.nearestNeighbour(bp$1)
+ } else if (arguments[0] instanceof BoundablePair && typeof arguments[1] === 'number') {
+ var initBndPair$1 = arguments[0];
+ var maxDistance = arguments[1];
+ var distanceLowerBound = maxDistance;
+ var minPair = null;
+ var priQ = new PriorityQueue();
+ priQ.add(initBndPair$1);
+ while (!priQ.isEmpty() && distanceLowerBound > 0.0) {
+ var bndPair = priQ.poll();
+ var currentDistance = bndPair.getDistance();
+ if (currentDistance >= distanceLowerBound) { break }
+ if (bndPair.isLeaves()) {
+ distanceLowerBound = currentDistance;
+ minPair = bndPair;
+ } else {
+ bndPair.expandToQueue(priQ, distanceLowerBound);
+ }
+ }
+ return [minPair.getBoundable(0).getItem(), minPair.getBoundable(1).getItem()]
+ }
+ } else if (arguments.length === 3) {
+ var env = arguments[0];
+ var item = arguments[1];
+ var itemDist$2 = arguments[2];
+ var bnd = new ItemBoundable(env, item);
+ var bp$2 = new BoundablePair(this.getRoot(), bnd, itemDist$2);
+ return this.nearestNeighbour(bp$2)[0]
+ }
+ };
+ STRtree.prototype.interfaces_ = function interfaces_ () {
+ return [SpatialIndex, Serializable]
+ };
+ STRtree.prototype.getClass = function getClass () {
+ return STRtree
+ };
+ STRtree.centreX = function centreX (e) {
+ return STRtree.avg(e.getMinX(), e.getMaxX())
+ };
+ STRtree.avg = function avg (a, b) {
+ return (a + b) / 2
+ };
+ STRtree.centreY = function centreY (e) {
+ return STRtree.avg(e.getMinY(), e.getMaxY())
+ };
+ staticAccessors.STRtreeNode.get = function () { return STRtreeNode };
+ staticAccessors.serialVersionUID.get = function () { return 259274702368956900 };
+ staticAccessors.xComparator.get = function () {
+ return {
+ interfaces_: function () {
+ return [Comparator]
+ },
+ compare: function (o1, o2) {
+ return AbstractSTRtree$$1.compareDoubles(STRtree.centreX(o1.getBounds()), STRtree.centreX(o2.getBounds()))
+ }
+ }
+ };
+ staticAccessors.yComparator.get = function () {
+ return {
+ interfaces_: function () {
+ return [Comparator]
+ },
+ compare: function (o1, o2) {
+ return AbstractSTRtree$$1.compareDoubles(STRtree.centreY(o1.getBounds()), STRtree.centreY(o2.getBounds()))
+ }
+ }
+ };
+ staticAccessors.intersectsOp.get = function () {
+ return {
+ interfaces_: function () {
+ return [AbstractSTRtree$$1.IntersectsOp]
+ },
+ intersects: function (aBounds, bBounds) {
+ return aBounds.intersects(bBounds)
+ }
+ }
+ };
+ staticAccessors.DEFAULT_NODE_CAPACITY.get = function () { return 10 };
+
+ Object.defineProperties( STRtree, staticAccessors );
+
+ return STRtree;
+ }(AbstractSTRtree));
+
+ var STRtreeNode = (function (AbstractNode$$1) {
+ function STRtreeNode () {
+ var level = arguments[0];
+ AbstractNode$$1.call(this, level);
+ }
+
+ if ( AbstractNode$$1 ) STRtreeNode.__proto__ = AbstractNode$$1;
+ STRtreeNode.prototype = Object.create( AbstractNode$$1 && AbstractNode$$1.prototype );
+ STRtreeNode.prototype.constructor = STRtreeNode;
+ STRtreeNode.prototype.computeBounds = function computeBounds () {
+ var bounds = null;
+ for (var i = this.getChildBoundables().iterator(); i.hasNext();) {
+ var childBoundable = i.next();
+ if (bounds === null) {
+ bounds = new Envelope(childBoundable.getBounds());
+ } else {
+ bounds.expandToInclude(childBoundable.getBounds());
+ }
+ }
+ return bounds
+ };
+ STRtreeNode.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ STRtreeNode.prototype.getClass = function getClass () {
+ return STRtreeNode
+ };
+
+ return STRtreeNode;
+ }(AbstractNode));
+
+ var SegmentPointComparator = function SegmentPointComparator () {};
+
+ SegmentPointComparator.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ SegmentPointComparator.prototype.getClass = function getClass () {
+ return SegmentPointComparator
+ };
+ SegmentPointComparator.relativeSign = function relativeSign (x0, x1) {
+ if (x0 < x1) { return -1 }
+ if (x0 > x1) { return 1 }
+ return 0
+ };
+ SegmentPointComparator.compare = function compare (octant, p0, p1) {
+ if (p0.equals2D(p1)) { return 0 }
+ var xSign = SegmentPointComparator.relativeSign(p0.x, p1.x);
+ var ySign = SegmentPointComparator.relativeSign(p0.y, p1.y);
+ switch (octant) {
+ case 0:
+ return SegmentPointComparator.compareValue(xSign, ySign)
+ case 1:
+ return SegmentPointComparator.compareValue(ySign, xSign)
+ case 2:
+ return SegmentPointComparator.compareValue(ySign, -xSign)
+ case 3:
+ return SegmentPointComparator.compareValue(-xSign, ySign)
+ case 4:
+ return SegmentPointComparator.compareValue(-xSign, -ySign)
+ case 5:
+ return SegmentPointComparator.compareValue(-ySign, -xSign)
+ case 6:
+ return SegmentPointComparator.compareValue(-ySign, xSign)
+ case 7:
+ return SegmentPointComparator.compareValue(xSign, -ySign)
+ }
+ Assert.shouldNeverReachHere('invalid octant value');
+ return 0
+ };
+ SegmentPointComparator.compareValue = function compareValue (compareSign0, compareSign1) {
+ if (compareSign0 < 0) { return -1 }
+ if (compareSign0 > 0) { return 1 }
+ if (compareSign1 < 0) { return -1 }
+ if (compareSign1 > 0) { return 1 }
+ return 0
+ };
+
+ var SegmentNode = function SegmentNode () {
+ this._segString = null;
+ this.coord = null;
+ this.segmentIndex = null;
+ this._segmentOctant = null;
+ this._isInterior = null;
+ var segString = arguments[0];
+ var coord = arguments[1];
+ var segmentIndex = arguments[2];
+ var segmentOctant = arguments[3];
+ this._segString = segString;
+ this.coord = new Coordinate(coord);
+ this.segmentIndex = segmentIndex;
+ this._segmentOctant = segmentOctant;
+ this._isInterior = !coord.equals2D(segString.getCoordinate(segmentIndex));
+ };
+ SegmentNode.prototype.getCoordinate = function getCoordinate () {
+ return this.coord
+ };
+ SegmentNode.prototype.print = function print (out) {
+ out.print(this.coord);
+ out.print(' seg # = ' + this.segmentIndex);
+ };
+ SegmentNode.prototype.compareTo = function compareTo (obj) {
+ var other = obj;
+ if (this.segmentIndex < other.segmentIndex) { return -1 }
+ if (this.segmentIndex > other.segmentIndex) { return 1 }
+ if (this.coord.equals2D(other.coord)) { return 0 }
+ return SegmentPointComparator.compare(this._segmentOctant, this.coord, other.coord)
+ };
+ SegmentNode.prototype.isEndPoint = function isEndPoint (maxSegmentIndex) {
+ if (this.segmentIndex === 0 && !this._isInterior) { return true }
+ if (this.segmentIndex === maxSegmentIndex) { return true }
+ return false
+ };
+ SegmentNode.prototype.isInterior = function isInterior () {
+ return this._isInterior
+ };
+ SegmentNode.prototype.interfaces_ = function interfaces_ () {
+ return [Comparable]
+ };
+ SegmentNode.prototype.getClass = function getClass () {
+ return SegmentNode
+ };
+
+ // import Iterator from '../../../../java/util/Iterator'
+ var SegmentNodeList = function SegmentNodeList () {
+ this._nodeMap = new TreeMap();
+ this._edge = null;
+ var edge = arguments[0];
+ this._edge = edge;
+ };
+ SegmentNodeList.prototype.getSplitCoordinates = function getSplitCoordinates () {
+ var this$1 = this;
+
+ var coordList = new CoordinateList();
+ this.addEndpoints();
+ var it = this.iterator();
+ var eiPrev = it.next();
+ while (it.hasNext()) {
+ var ei = it.next();
+ this$1.addEdgeCoordinates(eiPrev, ei, coordList);
+ eiPrev = ei;
+ }
+ return coordList.toCoordinateArray()
+ };
+ SegmentNodeList.prototype.addCollapsedNodes = function addCollapsedNodes () {
+ var this$1 = this;
+
+ var collapsedVertexIndexes = new ArrayList();
+ this.findCollapsesFromInsertedNodes(collapsedVertexIndexes);
+ this.findCollapsesFromExistingVertices(collapsedVertexIndexes);
+ for (var it = collapsedVertexIndexes.iterator(); it.hasNext();) {
+ var vertexIndex = it.next().intValue();
+ this$1.add(this$1._edge.getCoordinate(vertexIndex), vertexIndex);
+ }
+ };
+ SegmentNodeList.prototype.print = function print (out) {
+ out.println('Intersections:');
+ for (var it = this.iterator(); it.hasNext();) {
+ var ei = it.next();
+ ei.print(out);
+ }
+ };
+ SegmentNodeList.prototype.findCollapsesFromExistingVertices = function findCollapsesFromExistingVertices (collapsedVertexIndexes) {
+ var this$1 = this;
+
+ for (var i = 0; i < this._edge.size() - 2; i++) {
+ var p0 = this$1._edge.getCoordinate(i);
+ // const p1 = this._edge.getCoordinate(i + 1)
+ var p2 = this$1._edge.getCoordinate(i + 2);
+ if (p0.equals2D(p2)) {
+ collapsedVertexIndexes.add(new Integer(i + 1));
+ }
+ }
+ };
+ SegmentNodeList.prototype.addEdgeCoordinates = function addEdgeCoordinates (ei0, ei1, coordList) {
+ var this$1 = this;
+
+ // let npts = ei1.segmentIndex - ei0.segmentIndex + 2
+ var lastSegStartPt = this._edge.getCoordinate(ei1.segmentIndex);
+ var useIntPt1 = ei1.isInterior() || !ei1.coord.equals2D(lastSegStartPt);
+ // if (!useIntPt1) {
+ // npts--
+ // }
+ // const ipt = 0
+ coordList.add(new Coordinate(ei0.coord), false);
+ for (var i = ei0.segmentIndex + 1; i <= ei1.segmentIndex; i++) {
+ coordList.add(this$1._edge.getCoordinate(i));
+ }
+ if (useIntPt1) {
+ coordList.add(new Coordinate(ei1.coord));
+ }
+ };
+ SegmentNodeList.prototype.iterator = function iterator () {
+ return this._nodeMap.values().iterator()
+ };
+ SegmentNodeList.prototype.addSplitEdges = function addSplitEdges (edgeList) {
+ var this$1 = this;
+
+ this.addEndpoints();
+ this.addCollapsedNodes();
+ var it = this.iterator();
+ var eiPrev = it.next();
+ while (it.hasNext()) {
+ var ei = it.next();
+ var newEdge = this$1.createSplitEdge(eiPrev, ei);
+ edgeList.add(newEdge);
+ eiPrev = ei;
+ }
+ };
+ SegmentNodeList.prototype.findCollapseIndex = function findCollapseIndex (ei0, ei1, collapsedVertexIndex) {
+ if (!ei0.coord.equals2D(ei1.coord)) { return false }
+ var numVerticesBetween = ei1.segmentIndex - ei0.segmentIndex;
+ if (!ei1.isInterior()) {
+ numVerticesBetween--;
+ }
+ if (numVerticesBetween === 1) {
+ collapsedVertexIndex[0] = ei0.segmentIndex + 1;
+ return true
+ }
+ return false
+ };
+ SegmentNodeList.prototype.findCollapsesFromInsertedNodes = function findCollapsesFromInsertedNodes (collapsedVertexIndexes) {
+ var this$1 = this;
+
+ var collapsedVertexIndex = new Array(1).fill(null);
+ var it = this.iterator();
+ var eiPrev = it.next();
+ while (it.hasNext()) {
+ var ei = it.next();
+ var isCollapsed = this$1.findCollapseIndex(eiPrev, ei, collapsedVertexIndex);
+ if (isCollapsed) { collapsedVertexIndexes.add(new Integer(collapsedVertexIndex[0])); }
+ eiPrev = ei;
+ }
+ };
+ SegmentNodeList.prototype.getEdge = function getEdge () {
+ return this._edge
+ };
+ SegmentNodeList.prototype.addEndpoints = function addEndpoints () {
+ var maxSegIndex = this._edge.size() - 1;
+ this.add(this._edge.getCoordinate(0), 0);
+ this.add(this._edge.getCoordinate(maxSegIndex), maxSegIndex);
+ };
+ SegmentNodeList.prototype.createSplitEdge = function createSplitEdge (ei0, ei1) {
+ var this$1 = this;
+
+ var npts = ei1.segmentIndex - ei0.segmentIndex + 2;
+ var lastSegStartPt = this._edge.getCoordinate(ei1.segmentIndex);
+ var useIntPt1 = ei1.isInterior() || !ei1.coord.equals2D(lastSegStartPt);
+ if (!useIntPt1) {
+ npts--;
+ }
+ var pts = new Array(npts).fill(null);
+ var ipt = 0;
+ pts[ipt++] = new Coordinate(ei0.coord);
+ for (var i = ei0.segmentIndex + 1; i <= ei1.segmentIndex; i++) {
+ pts[ipt++] = this$1._edge.getCoordinate(i);
+ }
+ if (useIntPt1) { pts[ipt] = new Coordinate(ei1.coord); }
+ return new NodedSegmentString(pts, this._edge.getData())
+ };
+ SegmentNodeList.prototype.add = function add (intPt, segmentIndex) {
+ var eiNew = new SegmentNode(this._edge, intPt, segmentIndex, this._edge.getSegmentOctant(segmentIndex));
+ var ei = this._nodeMap.get(eiNew);
+ if (ei !== null) {
+ Assert.isTrue(ei.coord.equals2D(intPt), 'Found equal nodes with different coordinates');
+ return ei
+ }
+ this._nodeMap.put(eiNew, eiNew);
+ return eiNew
+ };
+ SegmentNodeList.prototype.checkSplitEdgesCorrectness = function checkSplitEdgesCorrectness (splitEdges) {
+ var edgePts = this._edge.getCoordinates();
+ var split0 = splitEdges.get(0);
+ var pt0 = split0.getCoordinate(0);
+ if (!pt0.equals2D(edgePts[0])) { throw new RuntimeException('bad split edge start point at ' + pt0) }
+ var splitn = splitEdges.get(splitEdges.size() - 1);
+ var splitnPts = splitn.getCoordinates();
+ var ptn = splitnPts[splitnPts.length - 1];
+ if (!ptn.equals2D(edgePts[edgePts.length - 1])) { throw new RuntimeException('bad split edge end point at ' + ptn) }
+ };
+ SegmentNodeList.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ SegmentNodeList.prototype.getClass = function getClass () {
+ return SegmentNodeList
+ };
+
+
+
+ // class NodeVertexIterator {
+ // constructor () {
+ // this._nodeList = null
+ // this._edge = null
+ // this._nodeIt = null
+ // this._currNode = null
+ // this._nextNode = null
+ // this._currSegIndex = 0
+ // let nodeList = arguments[0]
+ // this._nodeList = nodeList
+ // this._edge = nodeList.getEdge()
+ // this._nodeIt = nodeList.iterator()
+ // this.readNextNode()
+ // }
+ // next () {
+ // if (this._currNode === null) {
+ // this._currNode = this._nextNode
+ // this._currSegIndex = this._currNode.segmentIndex
+ // this.readNextNode()
+ // return this._currNode
+ // }
+ // if (this._nextNode === null) return null
+ // if (this._nextNode.segmentIndex === this._currNode.segmentIndex) {
+ // this._currNode = this._nextNode
+ // this._currSegIndex = this._currNode.segmentIndex
+ // this.readNextNode()
+ // return this._currNode
+ // }
+ // if (this._nextNode.segmentIndex > this._currNode.segmentIndex) {}
+ // return null
+ // }
+ // remove () {
+ // // throw new UnsupportedOperationException(this.getClass().getName())
+ // }
+ // hasNext () {
+ // if (this._nextNode === null) return false
+ // return true
+ // }
+ // readNextNode () {
+ // if (this._nodeIt.hasNext()) this._nextNode = this._nodeIt.next(); else this._nextNode = null
+ // }
+ // interfaces_ () {
+ // return [Iterator]
+ // }
+ // getClass () {
+ // return NodeVertexIterator
+ // }
+ // }
+
+ var Octant = function Octant () {};
+
+ Octant.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ Octant.prototype.getClass = function getClass () {
+ return Octant
+ };
+ Octant.octant = function octant () {
+ if (typeof arguments[0] === 'number' && typeof arguments[1] === 'number') {
+ var dx = arguments[0];
+ var dy = arguments[1];
+ if (dx === 0.0 && dy === 0.0) { throw new IllegalArgumentException('Cannot compute the octant for point ( ' + dx + ', ' + dy + ' )') }
+ var adx = Math.abs(dx);
+ var ady = Math.abs(dy);
+ if (dx >= 0) {
+ if (dy >= 0) {
+ if (adx >= ady) { return 0; } else { return 1 }
+ } else {
+ if (adx >= ady) { return 7; } else { return 6 }
+ }
+ } else {
+ if (dy >= 0) {
+ if (adx >= ady) { return 3; } else { return 2 }
+ } else {
+ if (adx >= ady) { return 4; } else { return 5 }
+ }
+ }
+ } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Coordinate) {
+ var p0 = arguments[0];
+ var p1 = arguments[1];
+ var dx$1 = p1.x - p0.x;
+ var dy$1 = p1.y - p0.y;
+ if (dx$1 === 0.0 && dy$1 === 0.0) { throw new IllegalArgumentException('Cannot compute the octant for two identical points ' + p0) }
+ return Octant.octant(dx$1, dy$1)
+ }
+ };
+
+ var SegmentString = function SegmentString () {};
+
+ SegmentString.prototype.getCoordinates = function getCoordinates () {};
+ SegmentString.prototype.size = function size () {};
+ SegmentString.prototype.getCoordinate = function getCoordinate (i) {};
+ SegmentString.prototype.isClosed = function isClosed () {};
+ SegmentString.prototype.setData = function setData (data) {};
+ SegmentString.prototype.getData = function getData () {};
+ SegmentString.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ SegmentString.prototype.getClass = function getClass () {
+ return SegmentString
+ };
+
+ var NodableSegmentString = function NodableSegmentString () {};
+
+ NodableSegmentString.prototype.addIntersection = function addIntersection (intPt, segmentIndex) {};
+ NodableSegmentString.prototype.interfaces_ = function interfaces_ () {
+ return [SegmentString]
+ };
+ NodableSegmentString.prototype.getClass = function getClass () {
+ return NodableSegmentString
+ };
+
+ var NodedSegmentString = function NodedSegmentString () {
+ this._nodeList = new SegmentNodeList(this);
+ this._pts = null;
+ this._data = null;
+ var pts = arguments[0];
+ var data = arguments[1];
+ this._pts = pts;
+ this._data = data;
+ };
+ NodedSegmentString.prototype.getCoordinates = function getCoordinates () {
+ return this._pts
+ };
+ NodedSegmentString.prototype.size = function size () {
+ return this._pts.length
+ };
+ NodedSegmentString.prototype.getCoordinate = function getCoordinate (i) {
+ return this._pts[i]
+ };
+ NodedSegmentString.prototype.isClosed = function isClosed () {
+ return this._pts[0].equals(this._pts[this._pts.length - 1])
+ };
+ NodedSegmentString.prototype.getSegmentOctant = function getSegmentOctant (index) {
+ if (index === this._pts.length - 1) { return -1 }
+ return this.safeOctant(this.getCoordinate(index), this.getCoordinate(index + 1))
+ };
+ NodedSegmentString.prototype.setData = function setData (data) {
+ this._data = data;
+ };
+ NodedSegmentString.prototype.safeOctant = function safeOctant (p0, p1) {
+ if (p0.equals2D(p1)) { return 0 }
+ return Octant.octant(p0, p1)
+ };
+ NodedSegmentString.prototype.getData = function getData () {
+ return this._data
+ };
+ NodedSegmentString.prototype.addIntersection = function addIntersection () {
+ if (arguments.length === 2) {
+ var intPt$1 = arguments[0];
+ var segmentIndex = arguments[1];
+ this.addIntersectionNode(intPt$1, segmentIndex);
+ } else if (arguments.length === 4) {
+ var li = arguments[0];
+ var segmentIndex$1 = arguments[1];
+ // const geomIndex = arguments[2]
+ var intIndex = arguments[3];
+ var intPt = new Coordinate(li.getIntersection(intIndex));
+ this.addIntersection(intPt, segmentIndex$1);
+ }
+ };
+ NodedSegmentString.prototype.toString = function toString () {
+ return WKTWriter.toLineString(new CoordinateArraySequence(this._pts))
+ };
+ NodedSegmentString.prototype.getNodeList = function getNodeList () {
+ return this._nodeList
+ };
+ NodedSegmentString.prototype.addIntersectionNode = function addIntersectionNode (intPt, segmentIndex) {
+ var normalizedSegmentIndex = segmentIndex;
+ var nextSegIndex = normalizedSegmentIndex + 1;
+ if (nextSegIndex < this._pts.length) {
+ var nextPt = this._pts[nextSegIndex];
+ if (intPt.equals2D(nextPt)) {
+ normalizedSegmentIndex = nextSegIndex;
+ }
+ }
+ var ei = this._nodeList.add(intPt, normalizedSegmentIndex);
+ return ei
+ };
+ NodedSegmentString.prototype.addIntersections = function addIntersections (li, segmentIndex, geomIndex) {
+ var this$1 = this;
+
+ for (var i = 0; i < li.getIntersectionNum(); i++) {
+ this$1.addIntersection(li, segmentIndex, geomIndex, i);
+ }
+ };
+ NodedSegmentString.prototype.interfaces_ = function interfaces_ () {
+ return [NodableSegmentString]
+ };
+ NodedSegmentString.prototype.getClass = function getClass () {
+ return NodedSegmentString
+ };
+ NodedSegmentString.getNodedSubstrings = function getNodedSubstrings () {
+ if (arguments.length === 1) {
+ var segStrings = arguments[0];
+ var resultEdgelist = new ArrayList();
+ NodedSegmentString.getNodedSubstrings(segStrings, resultEdgelist);
+ return resultEdgelist
+ } else if (arguments.length === 2) {
+ var segStrings$1 = arguments[0];
+ var resultEdgelist$1 = arguments[1];
+ for (var i = segStrings$1.iterator(); i.hasNext();) {
+ var ss = i.next();
+ ss.getNodeList().addSplitEdges(resultEdgelist$1);
+ }
+ }
+ };
+
+ var LineSegment = function LineSegment () {
+ this.p0 = null;
+ this.p1 = null;
+ if (arguments.length === 0) {
+ this.p0 = new Coordinate();
+ this.p1 = new Coordinate();
+ } else if (arguments.length === 1) {
+ var ls = arguments[0];
+ this.p0 = new Coordinate(ls.p0);
+ this.p1 = new Coordinate(ls.p1);
+ } else if (arguments.length === 2) {
+ this.p0 = arguments[0];
+ this.p1 = arguments[1];
+ } else if (arguments.length === 4) {
+ var x0 = arguments[0];
+ var y0 = arguments[1];
+ var x1 = arguments[2];
+ var y1 = arguments[3];
+ this.p0 = new Coordinate(x0, y0);
+ this.p1 = new Coordinate(x1, y1);
+ }
+ };
+
+ var staticAccessors$24 = { serialVersionUID: { configurable: true } };
+ LineSegment.prototype.minX = function minX () {
+ return Math.min(this.p0.x, this.p1.x)
+ };
+ LineSegment.prototype.orientationIndex = function orientationIndex () {
+ if (arguments[0] instanceof LineSegment) {
+ var seg = arguments[0];
+ var orient0 = CGAlgorithms.orientationIndex(this.p0, this.p1, seg.p0);
+ var orient1 = CGAlgorithms.orientationIndex(this.p0, this.p1, seg.p1);
+ if (orient0 >= 0 && orient1 >= 0) { return Math.max(orient0, orient1) }
+ if (orient0 <= 0 && orient1 <= 0) { return Math.max(orient0, orient1) }
+ return 0
+ } else if (arguments[0] instanceof Coordinate) {
+ var p = arguments[0];
+ return CGAlgorithms.orientationIndex(this.p0, this.p1, p)
+ }
+ };
+ LineSegment.prototype.toGeometry = function toGeometry (geomFactory) {
+ return geomFactory.createLineString([this.p0, this.p1])
+ };
+ LineSegment.prototype.isVertical = function isVertical () {
+ return this.p0.x === this.p1.x
+ };
+ LineSegment.prototype.equals = function equals (o) {
+ if (!(o instanceof LineSegment)) {
+ return false
+ }
+ var other = o;
+ return this.p0.equals(other.p0) && this.p1.equals(other.p1)
+ };
+ LineSegment.prototype.intersection = function intersection (line) {
+ var li = new RobustLineIntersector();
+ li.computeIntersection(this.p0, this.p1, line.p0, line.p1);
+ if (li.hasIntersection()) { return li.getIntersection(0) }
+ return null
+ };
+ LineSegment.prototype.project = function project () {
+ if (arguments[0] instanceof Coordinate) {
+ var p = arguments[0];
+ if (p.equals(this.p0) || p.equals(this.p1)) { return new Coordinate(p) }
+ var r = this.projectionFactor(p);
+ var coord = new Coordinate();
+ coord.x = this.p0.x + r * (this.p1.x - this.p0.x);
+ coord.y = this.p0.y + r * (this.p1.y - this.p0.y);
+ return coord
+ } else if (arguments[0] instanceof LineSegment) {
+ var seg = arguments[0];
+ var pf0 = this.projectionFactor(seg.p0);
+ var pf1 = this.projectionFactor(seg.p1);
+ if (pf0 >= 1.0 && pf1 >= 1.0) { return null }
+ if (pf0 <= 0.0 && pf1 <= 0.0) { return null }
+ var newp0 = this.project(seg.p0);
+ if (pf0 < 0.0) { newp0 = this.p0; }
+ if (pf0 > 1.0) { newp0 = this.p1; }
+ var newp1 = this.project(seg.p1);
+ if (pf1 < 0.0) { newp1 = this.p0; }
+ if (pf1 > 1.0) { newp1 = this.p1; }
+ return new LineSegment(newp0, newp1)
+ }
+ };
+ LineSegment.prototype.normalize = function normalize () {
+ if (this.p1.compareTo(this.p0) < 0) { this.reverse(); }
+ };
+ LineSegment.prototype.angle = function angle () {
+ return Math.atan2(this.p1.y - this.p0.y, this.p1.x - this.p0.x)
+ };
+ LineSegment.prototype.getCoordinate = function getCoordinate (i) {
+ if (i === 0) { return this.p0 }
+ return this.p1
+ };
+ LineSegment.prototype.distancePerpendicular = function distancePerpendicular (p) {
+ return CGAlgorithms.distancePointLinePerpendicular(p, this.p0, this.p1)
+ };
+ LineSegment.prototype.minY = function minY () {
+ return Math.min(this.p0.y, this.p1.y)
+ };
+ LineSegment.prototype.midPoint = function midPoint () {
+ return LineSegment.midPoint(this.p0, this.p1)
+ };
+ LineSegment.prototype.projectionFactor = function projectionFactor (p) {
+ if (p.equals(this.p0)) { return 0.0 }
+ if (p.equals(this.p1)) { return 1.0 }
+ var dx = this.p1.x - this.p0.x;
+ var dy = this.p1.y - this.p0.y;
+ var len = dx * dx + dy * dy;
+ if (len <= 0.0) { return Double.NaN }
+ var r = ((p.x - this.p0.x) * dx + (p.y - this.p0.y) * dy) / len;
+ return r
+ };
+ LineSegment.prototype.closestPoints = function closestPoints (line) {
+ var intPt = this.intersection(line);
+ if (intPt !== null) {
+ return [intPt, intPt]
+ }
+ var closestPt = new Array(2).fill(null);
+ var minDistance = Double.MAX_VALUE;
+ var dist = null;
+ var close00 = this.closestPoint(line.p0);
+ minDistance = close00.distance(line.p0);
+ closestPt[0] = close00;
+ closestPt[1] = line.p0;
+ var close01 = this.closestPoint(line.p1);
+ dist = close01.distance(line.p1);
+ if (dist < minDistance) {
+ minDistance = dist;
+ closestPt[0] = close01;
+ closestPt[1] = line.p1;
+ }
+ var close10 = line.closestPoint(this.p0);
+ dist = close10.distance(this.p0);
+ if (dist < minDistance) {
+ minDistance = dist;
+ closestPt[0] = this.p0;
+ closestPt[1] = close10;
+ }
+ var close11 = line.closestPoint(this.p1);
+ dist = close11.distance(this.p1);
+ if (dist < minDistance) {
+ minDistance = dist;
+ closestPt[0] = this.p1;
+ closestPt[1] = close11;
+ }
+ return closestPt
+ };
+ LineSegment.prototype.closestPoint = function closestPoint (p) {
+ var factor = this.projectionFactor(p);
+ if (factor > 0 && factor < 1) {
+ return this.project(p)
+ }
+ var dist0 = this.p0.distance(p);
+ var dist1 = this.p1.distance(p);
+ if (dist0 < dist1) { return this.p0 }
+ return this.p1
+ };
+ LineSegment.prototype.maxX = function maxX () {
+ return Math.max(this.p0.x, this.p1.x)
+ };
+ LineSegment.prototype.getLength = function getLength () {
+ return this.p0.distance(this.p1)
+ };
+ LineSegment.prototype.compareTo = function compareTo (o) {
+ var other = o;
+ var comp0 = this.p0.compareTo(other.p0);
+ if (comp0 !== 0) { return comp0 }
+ return this.p1.compareTo(other.p1)
+ };
+ LineSegment.prototype.reverse = function reverse () {
+ var temp = this.p0;
+ this.p0 = this.p1;
+ this.p1 = temp;
+ };
+ LineSegment.prototype.equalsTopo = function equalsTopo (other) {
+ return this.p0.equals(other.p0) &&
+ (this.p1.equals(other.p1) || this.p0.equals(other.p1)) &&
+ this.p1.equals(other.p0)
+ };
+ LineSegment.prototype.lineIntersection = function lineIntersection (line) {
+ try {
+ var intPt = HCoordinate.intersection(this.p0, this.p1, line.p0, line.p1);
+ return intPt
+ } catch (ex) {
+ if (ex instanceof NotRepresentableException) ; else { throw ex }
+ } finally {}
+ return null
+ };
+ LineSegment.prototype.maxY = function maxY () {
+ return Math.max(this.p0.y, this.p1.y)
+ };
+ LineSegment.prototype.pointAlongOffset = function pointAlongOffset (segmentLengthFraction, offsetDistance) {
+ var segx = this.p0.x + segmentLengthFraction * (this.p1.x - this.p0.x);
+ var segy = this.p0.y + segmentLengthFraction * (this.p1.y - this.p0.y);
+ var dx = this.p1.x - this.p0.x;
+ var dy = this.p1.y - this.p0.y;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var ux = 0.0;
+ var uy = 0.0;
+ if (offsetDistance !== 0.0) {
+ if (len <= 0.0) { throw new Error('Cannot compute offset from zero-length line segment') }
+ ux = offsetDistance * dx / len;
+ uy = offsetDistance * dy / len;
+ }
+ var offsetx = segx - uy;
+ var offsety = segy + ux;
+ var coord = new Coordinate(offsetx, offsety);
+ return coord
+ };
+ LineSegment.prototype.setCoordinates = function setCoordinates () {
+ if (arguments.length === 1) {
+ var ls = arguments[0];
+ this.setCoordinates(ls.p0, ls.p1);
+ } else if (arguments.length === 2) {
+ var p0 = arguments[0];
+ var p1 = arguments[1];
+ this.p0.x = p0.x;
+ this.p0.y = p0.y;
+ this.p1.x = p1.x;
+ this.p1.y = p1.y;
+ }
+ };
+ LineSegment.prototype.segmentFraction = function segmentFraction (inputPt) {
+ var segFrac = this.projectionFactor(inputPt);
+ if (segFrac < 0.0) { segFrac = 0.0; } else if (segFrac > 1.0 || Double.isNaN(segFrac)) { segFrac = 1.0; }
+ return segFrac
+ };
+ LineSegment.prototype.toString = function toString () {
+ return 'LINESTRING( ' + this.p0.x + ' ' + this.p0.y + ', ' + this.p1.x + ' ' + this.p1.y + ')'
+ };
+ LineSegment.prototype.isHorizontal = function isHorizontal () {
+ return this.p0.y === this.p1.y
+ };
+ LineSegment.prototype.distance = function distance () {
+ if (arguments[0] instanceof LineSegment) {
+ var ls = arguments[0];
+ return CGAlgorithms.distanceLineLine(this.p0, this.p1, ls.p0, ls.p1)
+ } else if (arguments[0] instanceof Coordinate) {
+ var p = arguments[0];
+ return CGAlgorithms.distancePointLine(p, this.p0, this.p1)
+ }
+ };
+ LineSegment.prototype.pointAlong = function pointAlong (segmentLengthFraction) {
+ var coord = new Coordinate();
+ coord.x = this.p0.x + segmentLengthFraction * (this.p1.x - this.p0.x);
+ coord.y = this.p0.y + segmentLengthFraction * (this.p1.y - this.p0.y);
+ return coord
+ };
+ LineSegment.prototype.hashCode = function hashCode () {
+ var bits0 = Double.doubleToLongBits(this.p0.x);
+ bits0 ^= Double.doubleToLongBits(this.p0.y) * 31;
+ var hash0 = Math.trunc(bits0) ^ Math.trunc(bits0 >> 32);
+ var bits1 = Double.doubleToLongBits(this.p1.x);
+ bits1 ^= Double.doubleToLongBits(this.p1.y) * 31;
+ var hash1 = Math.trunc(bits1) ^ Math.trunc(bits1 >> 32);
+ return hash0 ^ hash1
+ };
+ LineSegment.prototype.interfaces_ = function interfaces_ () {
+ return [Comparable, Serializable]
+ };
+ LineSegment.prototype.getClass = function getClass () {
+ return LineSegment
+ };
+ LineSegment.midPoint = function midPoint (p0, p1) {
+ return new Coordinate((p0.x + p1.x) / 2, (p0.y + p1.y) / 2)
+ };
+ staticAccessors$24.serialVersionUID.get = function () { return 3252005833466256227 };
+
+ Object.defineProperties( LineSegment, staticAccessors$24 );
+
+ var MonotoneChainOverlapAction = function MonotoneChainOverlapAction () {
+ this.tempEnv1 = new Envelope();
+ this.tempEnv2 = new Envelope();
+ this._overlapSeg1 = new LineSegment();
+ this._overlapSeg2 = new LineSegment();
+ };
+ MonotoneChainOverlapAction.prototype.overlap = function overlap () {
+ if (arguments.length === 2) ; else if (arguments.length === 4) {
+ var mc1 = arguments[0];
+ var start1 = arguments[1];
+ var mc2 = arguments[2];
+ var start2 = arguments[3];
+ mc1.getLineSegment(start1, this._overlapSeg1);
+ mc2.getLineSegment(start2, this._overlapSeg2);
+ this.overlap(this._overlapSeg1, this._overlapSeg2);
+ }
+ };
+ MonotoneChainOverlapAction.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ MonotoneChainOverlapAction.prototype.getClass = function getClass () {
+ return MonotoneChainOverlapAction
+ };
+
+ var MonotoneChain = function MonotoneChain () {
+ this._pts = null;
+ this._start = null;
+ this._end = null;
+ this._env = null;
+ this._context = null;
+ this._id = null;
+ var pts = arguments[0];
+ var start = arguments[1];
+ var end = arguments[2];
+ var context = arguments[3];
+ this._pts = pts;
+ this._start = start;
+ this._end = end;
+ this._context = context;
+ };
+ MonotoneChain.prototype.getLineSegment = function getLineSegment (index, ls) {
+ ls.p0 = this._pts[index];
+ ls.p1 = this._pts[index + 1];
+ };
+ MonotoneChain.prototype.computeSelect = function computeSelect (searchEnv, start0, end0, mcs) {
+ var p0 = this._pts[start0];
+ var p1 = this._pts[end0];
+ mcs.tempEnv1.init(p0, p1);
+ if (end0 - start0 === 1) {
+ mcs.select(this, start0);
+ return null
+ }
+ if (!searchEnv.intersects(mcs.tempEnv1)) { return null }
+ var mid = Math.trunc((start0 + end0) / 2);
+ if (start0 < mid) {
+ this.computeSelect(searchEnv, start0, mid, mcs);
+ }
+ if (mid < end0) {
+ this.computeSelect(searchEnv, mid, end0, mcs);
+ }
+ };
+ MonotoneChain.prototype.getCoordinates = function getCoordinates () {
+ var this$1 = this;
+
+ var coord = new Array(this._end - this._start + 1).fill(null);
+ var index = 0;
+ for (var i = this._start; i <= this._end; i++) {
+ coord[index++] = this$1._pts[i];
+ }
+ return coord
+ };
+ MonotoneChain.prototype.computeOverlaps = function computeOverlaps (mc, mco) {
+ this.computeOverlapsInternal(this._start, this._end, mc, mc._start, mc._end, mco);
+ };
+ MonotoneChain.prototype.setId = function setId (id) {
+ this._id = id;
+ };
+ MonotoneChain.prototype.select = function select (searchEnv, mcs) {
+ this.computeSelect(searchEnv, this._start, this._end, mcs);
+ };
+ MonotoneChain.prototype.getEnvelope = function getEnvelope () {
+ if (this._env === null) {
+ var p0 = this._pts[this._start];
+ var p1 = this._pts[this._end];
+ this._env = new Envelope(p0, p1);
+ }
+ return this._env
+ };
+ MonotoneChain.prototype.getEndIndex = function getEndIndex () {
+ return this._end
+ };
+ MonotoneChain.prototype.getStartIndex = function getStartIndex () {
+ return this._start
+ };
+ MonotoneChain.prototype.getContext = function getContext () {
+ return this._context
+ };
+ MonotoneChain.prototype.getId = function getId () {
+ return this._id
+ };
+ MonotoneChain.prototype.computeOverlapsInternal = function computeOverlapsInternal (start0, end0, mc, start1, end1, mco) {
+ var p00 = this._pts[start0];
+ var p01 = this._pts[end0];
+ var p10 = mc._pts[start1];
+ var p11 = mc._pts[end1];
+ if (end0 - start0 === 1 && end1 - start1 === 1) {
+ mco.overlap(this, start0, mc, start1);
+ return null
+ }
+ mco.tempEnv1.init(p00, p01);
+ mco.tempEnv2.init(p10, p11);
+ if (!mco.tempEnv1.intersects(mco.tempEnv2)) { return null }
+ var mid0 = Math.trunc((start0 + end0) / 2);
+ var mid1 = Math.trunc((start1 + end1) / 2);
+ if (start0 < mid0) {
+ if (start1 < mid1) { this.computeOverlapsInternal(start0, mid0, mc, start1, mid1, mco); }
+ if (mid1 < end1) { this.computeOverlapsInternal(start0, mid0, mc, mid1, end1, mco); }
+ }
+ if (mid0 < end0) {
+ if (start1 < mid1) { this.computeOverlapsInternal(mid0, end0, mc, start1, mid1, mco); }
+ if (mid1 < end1) { this.computeOverlapsInternal(mid0, end0, mc, mid1, end1, mco); }
+ }
+ };
+ MonotoneChain.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ MonotoneChain.prototype.getClass = function getClass () {
+ return MonotoneChain
+ };
+
+ var MonotoneChainBuilder = function MonotoneChainBuilder () {};
+
+ MonotoneChainBuilder.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ MonotoneChainBuilder.prototype.getClass = function getClass () {
+ return MonotoneChainBuilder
+ };
+ MonotoneChainBuilder.getChainStartIndices = function getChainStartIndices (pts) {
+ var start = 0;
+ var startIndexList = new ArrayList();
+ startIndexList.add(new Integer(start));
+ do {
+ var last = MonotoneChainBuilder.findChainEnd(pts, start);
+ startIndexList.add(new Integer(last));
+ start = last;
+ } while (start < pts.length - 1)
+ var startIndex = MonotoneChainBuilder.toIntArray(startIndexList);
+ return startIndex
+ };
+ MonotoneChainBuilder.findChainEnd = function findChainEnd (pts, start) {
+ var safeStart = start;
+ while (safeStart < pts.length - 1 && pts[safeStart].equals2D(pts[safeStart + 1])) {
+ safeStart++;
+ }
+ if (safeStart >= pts.length - 1) {
+ return pts.length - 1
+ }
+ var chainQuad = Quadrant.quadrant(pts[safeStart], pts[safeStart + 1]);
+ var last = start + 1;
+ while (last < pts.length) {
+ if (!pts[last - 1].equals2D(pts[last])) {
+ var quad = Quadrant.quadrant(pts[last - 1], pts[last]);
+ if (quad !== chainQuad) { break }
+ }
+ last++;
+ }
+ return last - 1
+ };
+ MonotoneChainBuilder.getChains = function getChains () {
+ if (arguments.length === 1) {
+ var pts = arguments[0];
+ return MonotoneChainBuilder.getChains(pts, null)
+ } else if (arguments.length === 2) {
+ var pts$1 = arguments[0];
+ var context = arguments[1];
+ var mcList = new ArrayList();
+ var startIndex = MonotoneChainBuilder.getChainStartIndices(pts$1);
+ for (var i = 0; i < startIndex.length - 1; i++) {
+ var mc = new MonotoneChain(pts$1, startIndex[i], startIndex[i + 1], context);
+ mcList.add(mc);
+ }
+ return mcList
+ }
+ };
+ MonotoneChainBuilder.toIntArray = function toIntArray (list) {
+ var array = new Array(list.size()).fill(null);
+ for (var i = 0; i < array.length; i++) {
+ array[i] = list.get(i).intValue();
+ }
+ return array
+ };
+
+ var Noder = function Noder () {};
+
+ Noder.prototype.computeNodes = function computeNodes (segStrings) {};
+ Noder.prototype.getNodedSubstrings = function getNodedSubstrings () {};
+ Noder.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ Noder.prototype.getClass = function getClass () {
+ return Noder
+ };
+
+ var SinglePassNoder = function SinglePassNoder () {
+ this._segInt = null;
+ if (arguments.length === 0) ; else if (arguments.length === 1) {
+ var segInt = arguments[0];
+ this.setSegmentIntersector(segInt);
+ }
+ };
+ SinglePassNoder.prototype.setSegmentIntersector = function setSegmentIntersector (segInt) {
+ this._segInt = segInt;
+ };
+ SinglePassNoder.prototype.interfaces_ = function interfaces_ () {
+ return [Noder]
+ };
+ SinglePassNoder.prototype.getClass = function getClass () {
+ return SinglePassNoder
+ };
+
+ var MCIndexNoder = (function (SinglePassNoder$$1) {
+ function MCIndexNoder (si) {
+ if (si) { SinglePassNoder$$1.call(this, si); }
+ else { SinglePassNoder$$1.call(this); }
+ this._monoChains = new ArrayList();
+ this._index = new STRtree();
+ this._idCounter = 0;
+ this._nodedSegStrings = null;
+ this._nOverlaps = 0;
+ }
+
+ if ( SinglePassNoder$$1 ) MCIndexNoder.__proto__ = SinglePassNoder$$1;
+ MCIndexNoder.prototype = Object.create( SinglePassNoder$$1 && SinglePassNoder$$1.prototype );
+ MCIndexNoder.prototype.constructor = MCIndexNoder;
+
+ var staticAccessors = { SegmentOverlapAction: { configurable: true } };
+ MCIndexNoder.prototype.getMonotoneChains = function getMonotoneChains () {
+ return this._monoChains
+ };
+ MCIndexNoder.prototype.getNodedSubstrings = function getNodedSubstrings () {
+ return NodedSegmentString.getNodedSubstrings(this._nodedSegStrings)
+ };
+ MCIndexNoder.prototype.getIndex = function getIndex () {
+ return this._index
+ };
+ MCIndexNoder.prototype.add = function add (segStr) {
+ var this$1 = this;
+
+ var segChains = MonotoneChainBuilder.getChains(segStr.getCoordinates(), segStr);
+ for (var i = segChains.iterator(); i.hasNext();) {
+ var mc = i.next();
+ mc.setId(this$1._idCounter++);
+ this$1._index.insert(mc.getEnvelope(), mc);
+ this$1._monoChains.add(mc);
+ }
+ };
+ MCIndexNoder.prototype.computeNodes = function computeNodes (inputSegStrings) {
+ var this$1 = this;
+
+ this._nodedSegStrings = inputSegStrings;
+ for (var i = inputSegStrings.iterator(); i.hasNext();) {
+ this$1.add(i.next());
+ }
+ this.intersectChains();
+ };
+ MCIndexNoder.prototype.intersectChains = function intersectChains () {
+ var this$1 = this;
+
+ var overlapAction = new SegmentOverlapAction(this._segInt);
+ for (var i = this._monoChains.iterator(); i.hasNext();) {
+ var queryChain = i.next();
+ var overlapChains = this$1._index.query(queryChain.getEnvelope());
+ for (var j = overlapChains.iterator(); j.hasNext();) {
+ var testChain = j.next();
+ if (testChain.getId() > queryChain.getId()) {
+ queryChain.computeOverlaps(testChain, overlapAction);
+ this$1._nOverlaps++;
+ }
+ if (this$1._segInt.isDone()) { return null }
+ }
+ }
+ };
+ MCIndexNoder.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ MCIndexNoder.prototype.getClass = function getClass () {
+ return MCIndexNoder
+ };
+ staticAccessors.SegmentOverlapAction.get = function () { return SegmentOverlapAction };
+
+ Object.defineProperties( MCIndexNoder, staticAccessors );
+
+ return MCIndexNoder;
+ }(SinglePassNoder));
+
+ var SegmentOverlapAction = (function (MonotoneChainOverlapAction$$1) {
+ function SegmentOverlapAction () {
+ MonotoneChainOverlapAction$$1.call(this);
+ this._si = null;
+ var si = arguments[0];
+ this._si = si;
+ }
+
+ if ( MonotoneChainOverlapAction$$1 ) SegmentOverlapAction.__proto__ = MonotoneChainOverlapAction$$1;
+ SegmentOverlapAction.prototype = Object.create( MonotoneChainOverlapAction$$1 && MonotoneChainOverlapAction$$1.prototype );
+ SegmentOverlapAction.prototype.constructor = SegmentOverlapAction;
+ SegmentOverlapAction.prototype.overlap = function overlap () {
+ if (arguments.length === 4) {
+ var mc1 = arguments[0];
+ var start1 = arguments[1];
+ var mc2 = arguments[2];
+ var start2 = arguments[3];
+ var ss1 = mc1.getContext();
+ var ss2 = mc2.getContext();
+ this._si.processIntersections(ss1, start1, ss2, start2);
+ } else { return MonotoneChainOverlapAction$$1.prototype.overlap.apply(this, arguments) }
+ };
+ SegmentOverlapAction.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ SegmentOverlapAction.prototype.getClass = function getClass () {
+ return SegmentOverlapAction
+ };
+
+ return SegmentOverlapAction;
+ }(MonotoneChainOverlapAction));
+
+ var BufferParameters = function BufferParameters () {
+ this._quadrantSegments = BufferParameters.DEFAULT_QUADRANT_SEGMENTS;
+ this._endCapStyle = BufferParameters.CAP_ROUND;
+ this._joinStyle = BufferParameters.JOIN_ROUND;
+ this._mitreLimit = BufferParameters.DEFAULT_MITRE_LIMIT;
+ this._isSingleSided = false;
+ this._simplifyFactor = BufferParameters.DEFAULT_SIMPLIFY_FACTOR;
+
+ if (arguments.length === 0) ; else if (arguments.length === 1) {
+ var quadrantSegments = arguments[0];
+ this.setQuadrantSegments(quadrantSegments);
+ } else if (arguments.length === 2) {
+ var quadrantSegments$1 = arguments[0];
+ var endCapStyle = arguments[1];
+ this.setQuadrantSegments(quadrantSegments$1);
+ this.setEndCapStyle(endCapStyle);
+ } else if (arguments.length === 4) {
+ var quadrantSegments$2 = arguments[0];
+ var endCapStyle$1 = arguments[1];
+ var joinStyle = arguments[2];
+ var mitreLimit = arguments[3];
+ this.setQuadrantSegments(quadrantSegments$2);
+ this.setEndCapStyle(endCapStyle$1);
+ this.setJoinStyle(joinStyle);
+ this.setMitreLimit(mitreLimit);
+ }
+ };
+
+ var staticAccessors$25 = { CAP_ROUND: { configurable: true },CAP_FLAT: { configurable: true },CAP_SQUARE: { configurable: true },JOIN_ROUND: { configurable: true },JOIN_MITRE: { configurable: true },JOIN_BEVEL: { configurable: true },DEFAULT_QUADRANT_SEGMENTS: { configurable: true },DEFAULT_MITRE_LIMIT: { configurable: true },DEFAULT_SIMPLIFY_FACTOR: { configurable: true } };
+ BufferParameters.prototype.getEndCapStyle = function getEndCapStyle () {
+ return this._endCapStyle
+ };
+ BufferParameters.prototype.isSingleSided = function isSingleSided () {
+ return this._isSingleSided
+ };
+ BufferParameters.prototype.setQuadrantSegments = function setQuadrantSegments (quadSegs) {
+ this._quadrantSegments = quadSegs;
+ if (this._quadrantSegments === 0) { this._joinStyle = BufferParameters.JOIN_BEVEL; }
+ if (this._quadrantSegments < 0) {
+ this._joinStyle = BufferParameters.JOIN_MITRE;
+ this._mitreLimit = Math.abs(this._quadrantSegments);
+ }
+ if (quadSegs <= 0) {
+ this._quadrantSegments = 1;
+ }
+ if (this._joinStyle !== BufferParameters.JOIN_ROUND) {
+ this._quadrantSegments = BufferParameters.DEFAULT_QUADRANT_SEGMENTS;
+ }
+ };
+ BufferParameters.prototype.getJoinStyle = function getJoinStyle () {
+ return this._joinStyle
+ };
+ BufferParameters.prototype.setJoinStyle = function setJoinStyle (joinStyle) {
+ this._joinStyle = joinStyle;
+ };
+ BufferParameters.prototype.setSimplifyFactor = function setSimplifyFactor (simplifyFactor) {
+ this._simplifyFactor = simplifyFactor < 0 ? 0 : simplifyFactor;
+ };
+ BufferParameters.prototype.getSimplifyFactor = function getSimplifyFactor () {
+ return this._simplifyFactor
+ };
+ BufferParameters.prototype.getQuadrantSegments = function getQuadrantSegments () {
+ return this._quadrantSegments
+ };
+ BufferParameters.prototype.setEndCapStyle = function setEndCapStyle (endCapStyle) {
+ this._endCapStyle = endCapStyle;
+ };
+ BufferParameters.prototype.getMitreLimit = function getMitreLimit () {
+ return this._mitreLimit
+ };
+ BufferParameters.prototype.setMitreLimit = function setMitreLimit (mitreLimit) {
+ this._mitreLimit = mitreLimit;
+ };
+ BufferParameters.prototype.setSingleSided = function setSingleSided (isSingleSided) {
+ this._isSingleSided = isSingleSided;
+ };
+ BufferParameters.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ BufferParameters.prototype.getClass = function getClass () {
+ return BufferParameters
+ };
+ BufferParameters.bufferDistanceError = function bufferDistanceError (quadSegs) {
+ var alpha = Math.PI / 2.0 / quadSegs;
+ return 1 - Math.cos(alpha / 2.0)
+ };
+ staticAccessors$25.CAP_ROUND.get = function () { return 1 };
+ staticAccessors$25.CAP_FLAT.get = function () { return 2 };
+ staticAccessors$25.CAP_SQUARE.get = function () { return 3 };
+ staticAccessors$25.JOIN_ROUND.get = function () { return 1 };
+ staticAccessors$25.JOIN_MITRE.get = function () { return 2 };
+ staticAccessors$25.JOIN_BEVEL.get = function () { return 3 };
+ staticAccessors$25.DEFAULT_QUADRANT_SEGMENTS.get = function () { return 8 };
+ staticAccessors$25.DEFAULT_MITRE_LIMIT.get = function () { return 5.0 };
+ staticAccessors$25.DEFAULT_SIMPLIFY_FACTOR.get = function () { return 0.01 };
+
+ Object.defineProperties( BufferParameters, staticAccessors$25 );
+
+ var BufferInputLineSimplifier = function BufferInputLineSimplifier (inputLine) {
+ this._distanceTol = null;
+ this._isDeleted = null;
+ this._angleOrientation = CGAlgorithms.COUNTERCLOCKWISE;
+ this._inputLine = inputLine || null;
+ };
+
+ var staticAccessors$26 = { INIT: { configurable: true },DELETE: { configurable: true },KEEP: { configurable: true },NUM_PTS_TO_CHECK: { configurable: true } };
+ BufferInputLineSimplifier.prototype.isDeletable = function isDeletable (i0, i1, i2, distanceTol) {
+ var p0 = this._inputLine[i0];
+ var p1 = this._inputLine[i1];
+ var p2 = this._inputLine[i2];
+ if (!this.isConcave(p0, p1, p2)) { return false }
+ if (!this.isShallow(p0, p1, p2, distanceTol)) { return false }
+ return this.isShallowSampled(p0, p1, i0, i2, distanceTol)
+ };
+ BufferInputLineSimplifier.prototype.deleteShallowConcavities = function deleteShallowConcavities () {
+ var this$1 = this;
+
+ var index = 1;
+ // const maxIndex = this._inputLine.length - 1
+ var midIndex = this.findNextNonDeletedIndex(index);
+ var lastIndex = this.findNextNonDeletedIndex(midIndex);
+ var isChanged = false;
+ while (lastIndex < this._inputLine.length) {
+ var isMiddleVertexDeleted = false;
+ if (this$1.isDeletable(index, midIndex, lastIndex, this$1._distanceTol)) {
+ this$1._isDeleted[midIndex] = BufferInputLineSimplifier.DELETE;
+ isMiddleVertexDeleted = true;
+ isChanged = true;
+ }
+ if (isMiddleVertexDeleted) { index = lastIndex; } else { index = midIndex; }
+ midIndex = this$1.findNextNonDeletedIndex(index);
+ lastIndex = this$1.findNextNonDeletedIndex(midIndex);
+ }
+ return isChanged
+ };
+ BufferInputLineSimplifier.prototype.isShallowConcavity = function isShallowConcavity (p0, p1, p2, distanceTol) {
+ var orientation = CGAlgorithms.computeOrientation(p0, p1, p2);
+ var isAngleToSimplify = orientation === this._angleOrientation;
+ if (!isAngleToSimplify) { return false }
+ var dist = CGAlgorithms.distancePointLine(p1, p0, p2);
+ return dist < distanceTol
+ };
+ BufferInputLineSimplifier.prototype.isShallowSampled = function isShallowSampled (p0, p2, i0, i2, distanceTol) {
+ var this$1 = this;
+
+ var inc = Math.trunc((i2 - i0) / BufferInputLineSimplifier.NUM_PTS_TO_CHECK);
+ if (inc <= 0) { inc = 1; }
+ for (var i = i0; i < i2; i += inc) {
+ if (!this$1.isShallow(p0, p2, this$1._inputLine[i], distanceTol)) { return false }
+ }
+ return true
+ };
+ BufferInputLineSimplifier.prototype.isConcave = function isConcave (p0, p1, p2) {
+ var orientation = CGAlgorithms.computeOrientation(p0, p1, p2);
+ var isConcave = orientation === this._angleOrientation;
+ return isConcave
+ };
+ BufferInputLineSimplifier.prototype.simplify = function simplify (distanceTol) {
+ var this$1 = this;
+
+ this._distanceTol = Math.abs(distanceTol);
+ if (distanceTol < 0) { this._angleOrientation = CGAlgorithms.CLOCKWISE; }
+ this._isDeleted = new Array(this._inputLine.length).fill(null);
+ var isChanged = false;
+ do {
+ isChanged = this$1.deleteShallowConcavities();
+ } while (isChanged)
+ return this.collapseLine()
+ };
+ BufferInputLineSimplifier.prototype.findNextNonDeletedIndex = function findNextNonDeletedIndex (index) {
+ var next = index + 1;
+ while (next < this._inputLine.length && this._isDeleted[next] === BufferInputLineSimplifier.DELETE) { next++; }
+ return next
+ };
+ BufferInputLineSimplifier.prototype.isShallow = function isShallow (p0, p1, p2, distanceTol) {
+ var dist = CGAlgorithms.distancePointLine(p1, p0, p2);
+ return dist < distanceTol
+ };
+ BufferInputLineSimplifier.prototype.collapseLine = function collapseLine () {
+ var this$1 = this;
+
+ var coordList = new CoordinateList();
+ for (var i = 0; i < this._inputLine.length; i++) {
+ if (this$1._isDeleted[i] !== BufferInputLineSimplifier.DELETE) { coordList.add(this$1._inputLine[i]); }
+ }
+ return coordList.toCoordinateArray()
+ };
+ BufferInputLineSimplifier.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ BufferInputLineSimplifier.prototype.getClass = function getClass () {
+ return BufferInputLineSimplifier
+ };
+ BufferInputLineSimplifier.simplify = function simplify (inputLine, distanceTol) {
+ var simp = new BufferInputLineSimplifier(inputLine);
+ return simp.simplify(distanceTol)
+ };
+ staticAccessors$26.INIT.get = function () { return 0 };
+ staticAccessors$26.DELETE.get = function () { return 1 };
+ staticAccessors$26.KEEP.get = function () { return 1 };
+ staticAccessors$26.NUM_PTS_TO_CHECK.get = function () { return 10 };
+
+ Object.defineProperties( BufferInputLineSimplifier, staticAccessors$26 );
+
+ var OffsetSegmentString = function OffsetSegmentString () {
+ this._ptList = null;
+ this._precisionModel = null;
+ this._minimimVertexDistance = 0.0;
+ this._ptList = new ArrayList();
+ };
+
+ var staticAccessors$28 = { COORDINATE_ARRAY_TYPE: { configurable: true } };
+ OffsetSegmentString.prototype.getCoordinates = function getCoordinates () {
+ var coord = this._ptList.toArray(OffsetSegmentString.COORDINATE_ARRAY_TYPE);
+ return coord
+ };
+ OffsetSegmentString.prototype.setPrecisionModel = function setPrecisionModel (precisionModel) {
+ this._precisionModel = precisionModel;
+ };
+ OffsetSegmentString.prototype.addPt = function addPt (pt) {
+ var bufPt = new Coordinate(pt);
+ this._precisionModel.makePrecise(bufPt);
+ if (this.isRedundant(bufPt)) { return null }
+ this._ptList.add(bufPt);
+ };
+ OffsetSegmentString.prototype.revere = function revere () {};
+ OffsetSegmentString.prototype.addPts = function addPts (pt, isForward) {
+ var this$1 = this;
+
+ if (isForward) {
+ for (var i = 0; i < pt.length; i++) {
+ this$1.addPt(pt[i]);
+ }
+ } else {
+ for (var i$1 = pt.length - 1; i$1 >= 0; i$1--) {
+ this$1.addPt(pt[i$1]);
+ }
+ }
+ };
+ OffsetSegmentString.prototype.isRedundant = function isRedundant (pt) {
+ if (this._ptList.size() < 1) { return false }
+ var lastPt = this._ptList.get(this._ptList.size() - 1);
+ var ptDist = pt.distance(lastPt);
+ if (ptDist < this._minimimVertexDistance) { return true }
+ return false
+ };
+ OffsetSegmentString.prototype.toString = function toString () {
+ var fact = new GeometryFactory();
+ var line = fact.createLineString(this.getCoordinates());
+ return line.toString()
+ };
+ OffsetSegmentString.prototype.closeRing = function closeRing () {
+ if (this._ptList.size() < 1) { return null }
+ var startPt = new Coordinate(this._ptList.get(0));
+ var lastPt = this._ptList.get(this._ptList.size() - 1);
+ // const last2Pt = null
+ // if (this._ptList.size() >= 2) last2Pt = this._ptList.get(this._ptList.size() - 2)
+ if (startPt.equals(lastPt)) { return null }
+ this._ptList.add(startPt);
+ };
+ OffsetSegmentString.prototype.setMinimumVertexDistance = function setMinimumVertexDistance (minimimVertexDistance) {
+ this._minimimVertexDistance = minimimVertexDistance;
+ };
+ OffsetSegmentString.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ OffsetSegmentString.prototype.getClass = function getClass () {
+ return OffsetSegmentString
+ };
+ staticAccessors$28.COORDINATE_ARRAY_TYPE.get = function () { return new Array(0).fill(null) };
+
+ Object.defineProperties( OffsetSegmentString, staticAccessors$28 );
+
+ var Angle = function Angle () {};
+
+ var staticAccessors$29 = { PI_TIMES_2: { configurable: true },PI_OVER_2: { configurable: true },PI_OVER_4: { configurable: true },COUNTERCLOCKWISE: { configurable: true },CLOCKWISE: { configurable: true },NONE: { configurable: true } };
+
+ Angle.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ Angle.prototype.getClass = function getClass () {
+ return Angle
+ };
+ Angle.toDegrees = function toDegrees (radians) {
+ return radians * 180 / Math.PI
+ };
+ Angle.normalize = function normalize (angle) {
+ while (angle > Math.PI) { angle -= Angle.PI_TIMES_2; }
+ while (angle <= -Math.PI) { angle += Angle.PI_TIMES_2; }
+ return angle
+ };
+ Angle.angle = function angle () {
+ if (arguments.length === 1) {
+ var p = arguments[0];
+ return Math.atan2(p.y, p.x)
+ } else if (arguments.length === 2) {
+ var p0 = arguments[0];
+ var p1 = arguments[1];
+ var dx = p1.x - p0.x;
+ var dy = p1.y - p0.y;
+ return Math.atan2(dy, dx)
+ }
+ };
+ Angle.isAcute = function isAcute (p0, p1, p2) {
+ var dx0 = p0.x - p1.x;
+ var dy0 = p0.y - p1.y;
+ var dx1 = p2.x - p1.x;
+ var dy1 = p2.y - p1.y;
+ var dotprod = dx0 * dx1 + dy0 * dy1;
+ return dotprod > 0
+ };
+ Angle.isObtuse = function isObtuse (p0, p1, p2) {
+ var dx0 = p0.x - p1.x;
+ var dy0 = p0.y - p1.y;
+ var dx1 = p2.x - p1.x;
+ var dy1 = p2.y - p1.y;
+ var dotprod = dx0 * dx1 + dy0 * dy1;
+ return dotprod < 0
+ };
+ Angle.interiorAngle = function interiorAngle (p0, p1, p2) {
+ var anglePrev = Angle.angle(p1, p0);
+ var angleNext = Angle.angle(p1, p2);
+ return Math.abs(angleNext - anglePrev)
+ };
+ Angle.normalizePositive = function normalizePositive (angle) {
+ if (angle < 0.0) {
+ while (angle < 0.0) { angle += Angle.PI_TIMES_2; }
+ if (angle >= Angle.PI_TIMES_2) { angle = 0.0; }
+ } else {
+ while (angle >= Angle.PI_TIMES_2) { angle -= Angle.PI_TIMES_2; }
+ if (angle < 0.0) { angle = 0.0; }
+ }
+ return angle
+ };
+ Angle.angleBetween = function angleBetween (tip1, tail, tip2) {
+ var a1 = Angle.angle(tail, tip1);
+ var a2 = Angle.angle(tail, tip2);
+ return Angle.diff(a1, a2)
+ };
+ Angle.diff = function diff (ang1, ang2) {
+ var delAngle = null;
+ if (ang1 < ang2) {
+ delAngle = ang2 - ang1;
+ } else {
+ delAngle = ang1 - ang2;
+ }
+ if (delAngle > Math.PI) {
+ delAngle = 2 * Math.PI - delAngle;
+ }
+ return delAngle
+ };
+ Angle.toRadians = function toRadians (angleDegrees) {
+ return angleDegrees * Math.PI / 180.0
+ };
+ Angle.getTurn = function getTurn (ang1, ang2) {
+ var crossproduct = Math.sin(ang2 - ang1);
+ if (crossproduct > 0) {
+ return Angle.COUNTERCLOCKWISE
+ }
+ if (crossproduct < 0) {
+ return Angle.CLOCKWISE
+ }
+ return Angle.NONE
+ };
+ Angle.angleBetweenOriented = function angleBetweenOriented (tip1, tail, tip2) {
+ var a1 = Angle.angle(tail, tip1);
+ var a2 = Angle.angle(tail, tip2);
+ var angDel = a2 - a1;
+ if (angDel <= -Math.PI) { return angDel + Angle.PI_TIMES_2 }
+ if (angDel > Math.PI) { return angDel - Angle.PI_TIMES_2 }
+ return angDel
+ };
+ staticAccessors$29.PI_TIMES_2.get = function () { return 2.0 * Math.PI };
+ staticAccessors$29.PI_OVER_2.get = function () { return Math.PI / 2.0 };
+ staticAccessors$29.PI_OVER_4.get = function () { return Math.PI / 4.0 };
+ staticAccessors$29.COUNTERCLOCKWISE.get = function () { return CGAlgorithms.COUNTERCLOCKWISE };
+ staticAccessors$29.CLOCKWISE.get = function () { return CGAlgorithms.CLOCKWISE };
+ staticAccessors$29.NONE.get = function () { return CGAlgorithms.COLLINEAR };
+
+ Object.defineProperties( Angle, staticAccessors$29 );
+
+ var OffsetSegmentGenerator = function OffsetSegmentGenerator () {
+ this._maxCurveSegmentError = 0.0;
+ this._filletAngleQuantum = null;
+ this._closingSegLengthFactor = 1;
+ this._segList = null;
+ this._distance = 0.0;
+ this._precisionModel = null;
+ this._bufParams = null;
+ this._li = null;
+ this._s0 = null;
+ this._s1 = null;
+ this._s2 = null;
+ this._seg0 = new LineSegment();
+ this._seg1 = new LineSegment();
+ this._offset0 = new LineSegment();
+ this._offset1 = new LineSegment();
+ this._side = 0;
+ this._hasNarrowConcaveAngle = false;
+ var precisionModel = arguments[0];
+ var bufParams = arguments[1];
+ var distance = arguments[2];
+ this._precisionModel = precisionModel;
+ this._bufParams = bufParams;
+ this._li = new RobustLineIntersector();
+ this._filletAngleQuantum = Math.PI / 2.0 / bufParams.getQuadrantSegments();
+ if (bufParams.getQuadrantSegments() >= 8 && bufParams.getJoinStyle() === BufferParameters.JOIN_ROUND) { this._closingSegLengthFactor = OffsetSegmentGenerator.MAX_CLOSING_SEG_LEN_FACTOR; }
+ this.init(distance);
+ };
+
+ var staticAccessors$27 = { OFFSET_SEGMENT_SEPARATION_FACTOR: { configurable: true },INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR: { configurable: true },CURVE_VERTEX_SNAP_DISTANCE_FACTOR: { configurable: true },MAX_CLOSING_SEG_LEN_FACTOR: { configurable: true } };
+ OffsetSegmentGenerator.prototype.addNextSegment = function addNextSegment (p, addStartPoint) {
+ this._s0 = this._s1;
+ this._s1 = this._s2;
+ this._s2 = p;
+ this._seg0.setCoordinates(this._s0, this._s1);
+ this.computeOffsetSegment(this._seg0, this._side, this._distance, this._offset0);
+ this._seg1.setCoordinates(this._s1, this._s2);
+ this.computeOffsetSegment(this._seg1, this._side, this._distance, this._offset1);
+ if (this._s1.equals(this._s2)) { return null }
+ var orientation = CGAlgorithms.computeOrientation(this._s0, this._s1, this._s2);
+ var outsideTurn = (orientation === CGAlgorithms.CLOCKWISE && this._side === Position.LEFT) || (orientation === CGAlgorithms.COUNTERCLOCKWISE && this._side === Position.RIGHT);
+ if (orientation === 0) {
+ this.addCollinear(addStartPoint);
+ } else if (outsideTurn) {
+ this.addOutsideTurn(orientation, addStartPoint);
+ } else {
+ this.addInsideTurn(orientation, addStartPoint);
+ }
+ };
+ OffsetSegmentGenerator.prototype.addLineEndCap = function addLineEndCap (p0, p1) {
+ var seg = new LineSegment(p0, p1);
+ var offsetL = new LineSegment();
+ this.computeOffsetSegment(seg, Position.LEFT, this._distance, offsetL);
+ var offsetR = new LineSegment();
+ this.computeOffsetSegment(seg, Position.RIGHT, this._distance, offsetR);
+ var dx = p1.x - p0.x;
+ var dy = p1.y - p0.y;
+ var angle = Math.atan2(dy, dx);
+ switch (this._bufParams.getEndCapStyle()) {
+ case BufferParameters.CAP_ROUND:
+ this._segList.addPt(offsetL.p1);
+ this.addFilletArc(p1, angle + Math.PI / 2, angle - Math.PI / 2, CGAlgorithms.CLOCKWISE, this._distance);
+ this._segList.addPt(offsetR.p1);
+ break
+ case BufferParameters.CAP_FLAT:
+ this._segList.addPt(offsetL.p1);
+ this._segList.addPt(offsetR.p1);
+ break
+ case BufferParameters.CAP_SQUARE:
+ var squareCapSideOffset = new Coordinate();
+ squareCapSideOffset.x = Math.abs(this._distance) * Math.cos(angle);
+ squareCapSideOffset.y = Math.abs(this._distance) * Math.sin(angle);
+ var squareCapLOffset = new Coordinate(offsetL.p1.x + squareCapSideOffset.x, offsetL.p1.y + squareCapSideOffset.y);
+ var squareCapROffset = new Coordinate(offsetR.p1.x + squareCapSideOffset.x, offsetR.p1.y + squareCapSideOffset.y);
+ this._segList.addPt(squareCapLOffset);
+ this._segList.addPt(squareCapROffset);
+ break
+ }
+ };
+ OffsetSegmentGenerator.prototype.getCoordinates = function getCoordinates () {
+ var pts = this._segList.getCoordinates();
+ return pts
+ };
+ OffsetSegmentGenerator.prototype.addMitreJoin = function addMitreJoin (p, offset0, offset1, distance) {
+ var isMitreWithinLimit = true;
+ var intPt = null;
+ try {
+ intPt = HCoordinate.intersection(offset0.p0, offset0.p1, offset1.p0, offset1.p1);
+ var mitreRatio = distance <= 0.0 ? 1.0 : intPt.distance(p) / Math.abs(distance);
+ if (mitreRatio > this._bufParams.getMitreLimit()) { isMitreWithinLimit = false; }
+ } catch (ex) {
+ if (ex instanceof NotRepresentableException) {
+ intPt = new Coordinate(0, 0);
+ isMitreWithinLimit = false;
+ } else { throw ex }
+ } finally {}
+ if (isMitreWithinLimit) {
+ this._segList.addPt(intPt);
+ } else {
+ this.addLimitedMitreJoin(offset0, offset1, distance, this._bufParams.getMitreLimit());
+ }
+ };
+ OffsetSegmentGenerator.prototype.addFilletCorner = function addFilletCorner (p, p0, p1, direction, radius) {
+ var dx0 = p0.x - p.x;
+ var dy0 = p0.y - p.y;
+ var startAngle = Math.atan2(dy0, dx0);
+ var dx1 = p1.x - p.x;
+ var dy1 = p1.y - p.y;
+ var endAngle = Math.atan2(dy1, dx1);
+ if (direction === CGAlgorithms.CLOCKWISE) {
+ if (startAngle <= endAngle) { startAngle += 2.0 * Math.PI; }
+ } else {
+ if (startAngle >= endAngle) { startAngle -= 2.0 * Math.PI; }
+ }
+ this._segList.addPt(p0);
+ this.addFilletArc(p, startAngle, endAngle, direction, radius);
+ this._segList.addPt(p1);
+ };
+ OffsetSegmentGenerator.prototype.addOutsideTurn = function addOutsideTurn (orientation, addStartPoint) {
+ if (this._offset0.p1.distance(this._offset1.p0) < this._distance * OffsetSegmentGenerator.OFFSET_SEGMENT_SEPARATION_FACTOR) {
+ this._segList.addPt(this._offset0.p1);
+ return null
+ }
+ if (this._bufParams.getJoinStyle() === BufferParameters.JOIN_MITRE) {
+ this.addMitreJoin(this._s1, this._offset0, this._offset1, this._distance);
+ } else if (this._bufParams.getJoinStyle() === BufferParameters.JOIN_BEVEL) {
+ this.addBevelJoin(this._offset0, this._offset1);
+ } else {
+ if (addStartPoint) { this._segList.addPt(this._offset0.p1); }
+ this.addFilletCorner(this._s1, this._offset0.p1, this._offset1.p0, orientation, this._distance);
+ this._segList.addPt(this._offset1.p0);
+ }
+ };
+ OffsetSegmentGenerator.prototype.createSquare = function createSquare (p) {
+ this._segList.addPt(new Coordinate(p.x + this._distance, p.y + this._distance));
+ this._segList.addPt(new Coordinate(p.x + this._distance, p.y - this._distance));
+ this._segList.addPt(new Coordinate(p.x - this._distance, p.y - this._distance));
+ this._segList.addPt(new Coordinate(p.x - this._distance, p.y + this._distance));
+ this._segList.closeRing();
+ };
+ OffsetSegmentGenerator.prototype.addSegments = function addSegments (pt, isForward) {
+ this._segList.addPts(pt, isForward);
+ };
+ OffsetSegmentGenerator.prototype.addFirstSegment = function addFirstSegment () {
+ this._segList.addPt(this._offset1.p0);
+ };
+ OffsetSegmentGenerator.prototype.addLastSegment = function addLastSegment () {
+ this._segList.addPt(this._offset1.p1);
+ };
+ OffsetSegmentGenerator.prototype.initSideSegments = function initSideSegments (s1, s2, side) {
+ this._s1 = s1;
+ this._s2 = s2;
+ this._side = side;
+ this._seg1.setCoordinates(s1, s2);
+ this.computeOffsetSegment(this._seg1, side, this._distance, this._offset1);
+ };
+ OffsetSegmentGenerator.prototype.addLimitedMitreJoin = function addLimitedMitreJoin (offset0, offset1, distance, mitreLimit) {
+ var basePt = this._seg0.p1;
+ var ang0 = Angle.angle(basePt, this._seg0.p0);
+ // const ang1 = Angle.angle(basePt, this._seg1.p1)
+ var angDiff = Angle.angleBetweenOriented(this._seg0.p0, basePt, this._seg1.p1);
+ var angDiffHalf = angDiff / 2;
+ var midAng = Angle.normalize(ang0 + angDiffHalf);
+ var mitreMidAng = Angle.normalize(midAng + Math.PI);
+ var mitreDist = mitreLimit * distance;
+ var bevelDelta = mitreDist * Math.abs(Math.sin(angDiffHalf));
+ var bevelHalfLen = distance - bevelDelta;
+ var bevelMidX = basePt.x + mitreDist * Math.cos(mitreMidAng);
+ var bevelMidY = basePt.y + mitreDist * Math.sin(mitreMidAng);
+ var bevelMidPt = new Coordinate(bevelMidX, bevelMidY);
+ var mitreMidLine = new LineSegment(basePt, bevelMidPt);
+ var bevelEndLeft = mitreMidLine.pointAlongOffset(1.0, bevelHalfLen);
+ var bevelEndRight = mitreMidLine.pointAlongOffset(1.0, -bevelHalfLen);
+ if (this._side === Position.LEFT) {
+ this._segList.addPt(bevelEndLeft);
+ this._segList.addPt(bevelEndRight);
+ } else {
+ this._segList.addPt(bevelEndRight);
+ this._segList.addPt(bevelEndLeft);
+ }
+ };
+ OffsetSegmentGenerator.prototype.computeOffsetSegment = function computeOffsetSegment (seg, side, distance, offset) {
+ var sideSign = side === Position.LEFT ? 1 : -1;
+ var dx = seg.p1.x - seg.p0.x;
+ var dy = seg.p1.y - seg.p0.y;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var ux = sideSign * distance * dx / len;
+ var uy = sideSign * distance * dy / len;
+ offset.p0.x = seg.p0.x - uy;
+ offset.p0.y = seg.p0.y + ux;
+ offset.p1.x = seg.p1.x - uy;
+ offset.p1.y = seg.p1.y + ux;
+ };
+ OffsetSegmentGenerator.prototype.addFilletArc = function addFilletArc (p, startAngle, endAngle, direction, radius) {
+ var this$1 = this;
+
+ var directionFactor = direction === CGAlgorithms.CLOCKWISE ? -1 : 1;
+ var totalAngle = Math.abs(startAngle - endAngle);
+ var nSegs = Math.trunc(totalAngle / this._filletAngleQuantum + 0.5);
+ if (nSegs < 1) { return null }
+ var initAngle = 0.0;
+ var currAngleInc = totalAngle / nSegs;
+ var currAngle = initAngle;
+ var pt = new Coordinate();
+ while (currAngle < totalAngle) {
+ var angle = startAngle + directionFactor * currAngle;
+ pt.x = p.x + radius * Math.cos(angle);
+ pt.y = p.y + radius * Math.sin(angle);
+ this$1._segList.addPt(pt);
+ currAngle += currAngleInc;
+ }
+ };
+ OffsetSegmentGenerator.prototype.addInsideTurn = function addInsideTurn (orientation, addStartPoint) {
+ this._li.computeIntersection(this._offset0.p0, this._offset0.p1, this._offset1.p0, this._offset1.p1);
+ if (this._li.hasIntersection()) {
+ this._segList.addPt(this._li.getIntersection(0));
+ } else {
+ this._hasNarrowConcaveAngle = true;
+ if (this._offset0.p1.distance(this._offset1.p0) < this._distance * OffsetSegmentGenerator.INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR) {
+ this._segList.addPt(this._offset0.p1);
+ } else {
+ this._segList.addPt(this._offset0.p1);
+ if (this._closingSegLengthFactor > 0) {
+ var mid0 = new Coordinate((this._closingSegLengthFactor * this._offset0.p1.x + this._s1.x) / (this._closingSegLengthFactor + 1), (this._closingSegLengthFactor * this._offset0.p1.y + this._s1.y) / (this._closingSegLengthFactor + 1));
+ this._segList.addPt(mid0);
+ var mid1 = new Coordinate((this._closingSegLengthFactor * this._offset1.p0.x + this._s1.x) / (this._closingSegLengthFactor + 1), (this._closingSegLengthFactor * this._offset1.p0.y + this._s1.y) / (this._closingSegLengthFactor + 1));
+ this._segList.addPt(mid1);
+ } else {
+ this._segList.addPt(this._s1);
+ }
+ this._segList.addPt(this._offset1.p0);
+ }
+ }
+ };
+ OffsetSegmentGenerator.prototype.createCircle = function createCircle (p) {
+ var pt = new Coordinate(p.x + this._distance, p.y);
+ this._segList.addPt(pt);
+ this.addFilletArc(p, 0.0, 2.0 * Math.PI, -1, this._distance);
+ this._segList.closeRing();
+ };
+ OffsetSegmentGenerator.prototype.addBevelJoin = function addBevelJoin (offset0, offset1) {
+ this._segList.addPt(offset0.p1);
+ this._segList.addPt(offset1.p0);
+ };
+ OffsetSegmentGenerator.prototype.init = function init (distance) {
+ this._distance = distance;
+ this._maxCurveSegmentError = distance * (1 - Math.cos(this._filletAngleQuantum / 2.0));
+ this._segList = new OffsetSegmentString();
+ this._segList.setPrecisionModel(this._precisionModel);
+ this._segList.setMinimumVertexDistance(distance * OffsetSegmentGenerator.CURVE_VERTEX_SNAP_DISTANCE_FACTOR);
+ };
+ OffsetSegmentGenerator.prototype.addCollinear = function addCollinear (addStartPoint) {
+ this._li.computeIntersection(this._s0, this._s1, this._s1, this._s2);
+ var numInt = this._li.getIntersectionNum();
+ if (numInt >= 2) {
+ if (this._bufParams.getJoinStyle() === BufferParameters.JOIN_BEVEL || this._bufParams.getJoinStyle() === BufferParameters.JOIN_MITRE) {
+ if (addStartPoint) { this._segList.addPt(this._offset0.p1); }
+ this._segList.addPt(this._offset1.p0);
+ } else {
+ this.addFilletCorner(this._s1, this._offset0.p1, this._offset1.p0, CGAlgorithms.CLOCKWISE, this._distance);
+ }
+ }
+ };
+ OffsetSegmentGenerator.prototype.closeRing = function closeRing () {
+ this._segList.closeRing();
+ };
+ OffsetSegmentGenerator.prototype.hasNarrowConcaveAngle = function hasNarrowConcaveAngle () {
+ return this._hasNarrowConcaveAngle
+ };
+ OffsetSegmentGenerator.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ OffsetSegmentGenerator.prototype.getClass = function getClass () {
+ return OffsetSegmentGenerator
+ };
+ staticAccessors$27.OFFSET_SEGMENT_SEPARATION_FACTOR.get = function () { return 1.0E-3 };
+ staticAccessors$27.INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR.get = function () { return 1.0E-3 };
+ staticAccessors$27.CURVE_VERTEX_SNAP_DISTANCE_FACTOR.get = function () { return 1.0E-6 };
+ staticAccessors$27.MAX_CLOSING_SEG_LEN_FACTOR.get = function () { return 80 };
+
+ Object.defineProperties( OffsetSegmentGenerator, staticAccessors$27 );
+
+ var OffsetCurveBuilder = function OffsetCurveBuilder () {
+ this._distance = 0.0;
+ this._precisionModel = null;
+ this._bufParams = null;
+ var precisionModel = arguments[0];
+ var bufParams = arguments[1];
+ this._precisionModel = precisionModel;
+ this._bufParams = bufParams;
+ };
+ OffsetCurveBuilder.prototype.getOffsetCurve = function getOffsetCurve (inputPts, distance) {
+ this._distance = distance;
+ if (distance === 0.0) { return null }
+ var isRightSide = distance < 0.0;
+ var posDistance = Math.abs(distance);
+ var segGen = this.getSegGen(posDistance);
+ if (inputPts.length <= 1) {
+ this.computePointCurve(inputPts[0], segGen);
+ } else {
+ this.computeOffsetCurve(inputPts, isRightSide, segGen);
+ }
+ var curvePts = segGen.getCoordinates();
+ if (isRightSide) { CoordinateArrays.reverse(curvePts); }
+ return curvePts
+ };
+ OffsetCurveBuilder.prototype.computeSingleSidedBufferCurve = function computeSingleSidedBufferCurve (inputPts, isRightSide, segGen) {
+ var distTol = this.simplifyTolerance(this._distance);
+ if (isRightSide) {
+ segGen.addSegments(inputPts, true);
+ var simp2 = BufferInputLineSimplifier.simplify(inputPts, -distTol);
+ var n2 = simp2.length - 1;
+ segGen.initSideSegments(simp2[n2], simp2[n2 - 1], Position.LEFT);
+ segGen.addFirstSegment();
+ for (var i = n2 - 2; i >= 0; i--) {
+ segGen.addNextSegment(simp2[i], true);
+ }
+ } else {
+ segGen.addSegments(inputPts, false);
+ var simp1 = BufferInputLineSimplifier.simplify(inputPts, distTol);
+ var n1 = simp1.length - 1;
+ segGen.initSideSegments(simp1[0], simp1[1], Position.LEFT);
+ segGen.addFirstSegment();
+ for (var i$1 = 2; i$1 <= n1; i$1++) {
+ segGen.addNextSegment(simp1[i$1], true);
+ }
+ }
+ segGen.addLastSegment();
+ segGen.closeRing();
+ };
+ OffsetCurveBuilder.prototype.computeRingBufferCurve = function computeRingBufferCurve (inputPts, side, segGen) {
+ var distTol = this.simplifyTolerance(this._distance);
+ if (side === Position.RIGHT) { distTol = -distTol; }
+ var simp = BufferInputLineSimplifier.simplify(inputPts, distTol);
+ var n = simp.length - 1;
+ segGen.initSideSegments(simp[n - 1], simp[0], side);
+ for (var i = 1; i <= n; i++) {
+ var addStartPoint = i !== 1;
+ segGen.addNextSegment(simp[i], addStartPoint);
+ }
+ segGen.closeRing();
+ };
+ OffsetCurveBuilder.prototype.computeLineBufferCurve = function computeLineBufferCurve (inputPts, segGen) {
+ var distTol = this.simplifyTolerance(this._distance);
+ var simp1 = BufferInputLineSimplifier.simplify(inputPts, distTol);
+ var n1 = simp1.length - 1;
+ segGen.initSideSegments(simp1[0], simp1[1], Position.LEFT);
+ for (var i = 2; i <= n1; i++) {
+ segGen.addNextSegment(simp1[i], true);
+ }
+ segGen.addLastSegment();
+ segGen.addLineEndCap(simp1[n1 - 1], simp1[n1]);
+ var simp2 = BufferInputLineSimplifier.simplify(inputPts, -distTol);
+ var n2 = simp2.length - 1;
+ segGen.initSideSegments(simp2[n2], simp2[n2 - 1], Position.LEFT);
+ for (var i$1 = n2 - 2; i$1 >= 0; i$1--) {
+ segGen.addNextSegment(simp2[i$1], true);
+ }
+ segGen.addLastSegment();
+ segGen.addLineEndCap(simp2[1], simp2[0]);
+ segGen.closeRing();
+ };
+ OffsetCurveBuilder.prototype.computePointCurve = function computePointCurve (pt, segGen) {
+ switch (this._bufParams.getEndCapStyle()) {
+ case BufferParameters.CAP_ROUND:
+ segGen.createCircle(pt);
+ break
+ case BufferParameters.CAP_SQUARE:
+ segGen.createSquare(pt);
+ break
+ }
+ };
+ OffsetCurveBuilder.prototype.getLineCurve = function getLineCurve (inputPts, distance) {
+ this._distance = distance;
+ if (distance < 0.0 && !this._bufParams.isSingleSided()) { return null }
+ if (distance === 0.0) { return null }
+ var posDistance = Math.abs(distance);
+ var segGen = this.getSegGen(posDistance);
+ if (inputPts.length <= 1) {
+ this.computePointCurve(inputPts[0], segGen);
+ } else {
+ if (this._bufParams.isSingleSided()) {
+ var isRightSide = distance < 0.0;
+ this.computeSingleSidedBufferCurve(inputPts, isRightSide, segGen);
+ } else { this.computeLineBufferCurve(inputPts, segGen); }
+ }
+ var lineCoord = segGen.getCoordinates();
+ return lineCoord
+ };
+ OffsetCurveBuilder.prototype.getBufferParameters = function getBufferParameters () {
+ return this._bufParams
+ };
+ OffsetCurveBuilder.prototype.simplifyTolerance = function simplifyTolerance (bufDistance) {
+ return bufDistance * this._bufParams.getSimplifyFactor()
+ };
+ OffsetCurveBuilder.prototype.getRingCurve = function getRingCurve (inputPts, side, distance) {
+ this._distance = distance;
+ if (inputPts.length <= 2) { return this.getLineCurve(inputPts, distance) }
+ if (distance === 0.0) {
+ return OffsetCurveBuilder.copyCoordinates(inputPts)
+ }
+ var segGen = this.getSegGen(distance);
+ this.computeRingBufferCurve(inputPts, side, segGen);
+ return segGen.getCoordinates()
+ };
+ OffsetCurveBuilder.prototype.computeOffsetCurve = function computeOffsetCurve (inputPts, isRightSide, segGen) {
+ var distTol = this.simplifyTolerance(this._distance);
+ if (isRightSide) {
+ var simp2 = BufferInputLineSimplifier.simplify(inputPts, -distTol);
+ var n2 = simp2.length - 1;
+ segGen.initSideSegments(simp2[n2], simp2[n2 - 1], Position.LEFT);
+ segGen.addFirstSegment();
+ for (var i = n2 - 2; i >= 0; i--) {
+ segGen.addNextSegment(simp2[i], true);
+ }
+ } else {
+ var simp1 = BufferInputLineSimplifier.simplify(inputPts, distTol);
+ var n1 = simp1.length - 1;
+ segGen.initSideSegments(simp1[0], simp1[1], Position.LEFT);
+ segGen.addFirstSegment();
+ for (var i$1 = 2; i$1 <= n1; i$1++) {
+ segGen.addNextSegment(simp1[i$1], true);
+ }
+ }
+ segGen.addLastSegment();
+ };
+ OffsetCurveBuilder.prototype.getSegGen = function getSegGen (distance) {
+ return new OffsetSegmentGenerator(this._precisionModel, this._bufParams, distance)
+ };
+ OffsetCurveBuilder.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ OffsetCurveBuilder.prototype.getClass = function getClass () {
+ return OffsetCurveBuilder
+ };
+ OffsetCurveBuilder.copyCoordinates = function copyCoordinates (pts) {
+ var copy = new Array(pts.length).fill(null);
+ for (var i = 0; i < copy.length; i++) {
+ copy[i] = new Coordinate(pts[i]);
+ }
+ return copy
+ };
+
+ var SubgraphDepthLocater = function SubgraphDepthLocater () {
+ this._subgraphs = null;
+ this._seg = new LineSegment();
+ this._cga = new CGAlgorithms();
+ var subgraphs = arguments[0];
+ this._subgraphs = subgraphs;
+ };
+
+ var staticAccessors$30 = { DepthSegment: { configurable: true } };
+ SubgraphDepthLocater.prototype.findStabbedSegments = function findStabbedSegments () {
+ var this$1 = this;
+
+ if (arguments.length === 1) {
+ var stabbingRayLeftPt = arguments[0];
+ var stabbedSegments = new ArrayList();
+ for (var i = this._subgraphs.iterator(); i.hasNext();) {
+ var bsg = i.next();
+ var env = bsg.getEnvelope();
+ if (stabbingRayLeftPt.y < env.getMinY() || stabbingRayLeftPt.y > env.getMaxY()) { continue }
+ this$1.findStabbedSegments(stabbingRayLeftPt, bsg.getDirectedEdges(), stabbedSegments);
+ }
+ return stabbedSegments
+ } else if (arguments.length === 3) {
+ if (hasInterface(arguments[2], List) && (arguments[0] instanceof Coordinate && arguments[1] instanceof DirectedEdge)) {
+ var stabbingRayLeftPt$1 = arguments[0];
+ var dirEdge = arguments[1];
+ var stabbedSegments$1 = arguments[2];
+ var pts = dirEdge.getEdge().getCoordinates();
+ for (var i$1 = 0; i$1 < pts.length - 1; i$1++) {
+ this$1._seg.p0 = pts[i$1];
+ this$1._seg.p1 = pts[i$1 + 1];
+ if (this$1._seg.p0.y > this$1._seg.p1.y) { this$1._seg.reverse(); }
+ var maxx = Math.max(this$1._seg.p0.x, this$1._seg.p1.x);
+ if (maxx < stabbingRayLeftPt$1.x) { continue }
+ if (this$1._seg.isHorizontal()) { continue }
+ if (stabbingRayLeftPt$1.y < this$1._seg.p0.y || stabbingRayLeftPt$1.y > this$1._seg.p1.y) { continue }
+ if (CGAlgorithms.computeOrientation(this$1._seg.p0, this$1._seg.p1, stabbingRayLeftPt$1) === CGAlgorithms.RIGHT) { continue }
+ var depth = dirEdge.getDepth(Position.LEFT);
+ if (!this$1._seg.p0.equals(pts[i$1])) { depth = dirEdge.getDepth(Position.RIGHT); }
+ var ds = new DepthSegment(this$1._seg, depth);
+ stabbedSegments$1.add(ds);
+ }
+ } else if (hasInterface(arguments[2], List) && (arguments[0] instanceof Coordinate && hasInterface(arguments[1], List))) {
+ var stabbingRayLeftPt$2 = arguments[0];
+ var dirEdges = arguments[1];
+ var stabbedSegments$2 = arguments[2];
+ for (var i$2 = dirEdges.iterator(); i$2.hasNext();) {
+ var de = i$2.next();
+ if (!de.isForward()) { continue }
+ this$1.findStabbedSegments(stabbingRayLeftPt$2, de, stabbedSegments$2);
+ }
+ }
+ }
+ };
+ SubgraphDepthLocater.prototype.getDepth = function getDepth (p) {
+ var stabbedSegments = this.findStabbedSegments(p);
+ if (stabbedSegments.size() === 0) { return 0 }
+ var ds = Collections.min(stabbedSegments);
+ return ds._leftDepth
+ };
+ SubgraphDepthLocater.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ SubgraphDepthLocater.prototype.getClass = function getClass () {
+ return SubgraphDepthLocater
+ };
+ staticAccessors$30.DepthSegment.get = function () { return DepthSegment };
+
+ Object.defineProperties( SubgraphDepthLocater, staticAccessors$30 );
+
+ var DepthSegment = function DepthSegment () {
+ this._upwardSeg = null;
+ this._leftDepth = null;
+ var seg = arguments[0];
+ var depth = arguments[1];
+ this._upwardSeg = new LineSegment(seg);
+ this._leftDepth = depth;
+ };
+ DepthSegment.prototype.compareTo = function compareTo (obj) {
+ var other = obj;
+ if (this._upwardSeg.minX() >= other._upwardSeg.maxX()) { return 1 }
+ if (this._upwardSeg.maxX() <= other._upwardSeg.minX()) { return -1 }
+ var orientIndex = this._upwardSeg.orientationIndex(other._upwardSeg);
+ if (orientIndex !== 0) { return orientIndex }
+ orientIndex = -1 * other._upwardSeg.orientationIndex(this._upwardSeg);
+ if (orientIndex !== 0) { return orientIndex }
+ return this._upwardSeg.compareTo(other._upwardSeg)
+ };
+ DepthSegment.prototype.compareX = function compareX (seg0, seg1) {
+ var compare0 = seg0.p0.compareTo(seg1.p0);
+ if (compare0 !== 0) { return compare0 }
+ return seg0.p1.compareTo(seg1.p1)
+ };
+ DepthSegment.prototype.toString = function toString () {
+ return this._upwardSeg.toString()
+ };
+ DepthSegment.prototype.interfaces_ = function interfaces_ () {
+ return [Comparable]
+ };
+ DepthSegment.prototype.getClass = function getClass () {
+ return DepthSegment
+ };
+
+ var Triangle = function Triangle (p0, p1, p2) {
+ this.p0 = p0 || null;
+ this.p1 = p1 || null;
+ this.p2 = p2 || null;
+ };
+ Triangle.prototype.area = function area () {
+ return Triangle.area(this.p0, this.p1, this.p2)
+ };
+ Triangle.prototype.signedArea = function signedArea () {
+ return Triangle.signedArea(this.p0, this.p1, this.p2)
+ };
+ Triangle.prototype.interpolateZ = function interpolateZ (p) {
+ if (p === null) { throw new IllegalArgumentException('Supplied point is null.') }
+ return Triangle.interpolateZ(p, this.p0, this.p1, this.p2)
+ };
+ Triangle.prototype.longestSideLength = function longestSideLength () {
+ return Triangle.longestSideLength(this.p0, this.p1, this.p2)
+ };
+ Triangle.prototype.isAcute = function isAcute () {
+ return Triangle.isAcute(this.p0, this.p1, this.p2)
+ };
+ Triangle.prototype.circumcentre = function circumcentre () {
+ return Triangle.circumcentre(this.p0, this.p1, this.p2)
+ };
+ Triangle.prototype.area3D = function area3D () {
+ return Triangle.area3D(this.p0, this.p1, this.p2)
+ };
+ Triangle.prototype.centroid = function centroid () {
+ return Triangle.centroid(this.p0, this.p1, this.p2)
+ };
+ Triangle.prototype.inCentre = function inCentre () {
+ return Triangle.inCentre(this.p0, this.p1, this.p2)
+ };
+ Triangle.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ Triangle.prototype.getClass = function getClass () {
+ return Triangle
+ };
+ Triangle.area = function area (a, b, c) {
+ return Math.abs(((c.x - a.x) * (b.y - a.y) - (b.x - a.x) * (c.y - a.y)) / 2)
+ };
+ Triangle.signedArea = function signedArea (a, b, c) {
+ return ((c.x - a.x) * (b.y - a.y) - (b.x - a.x) * (c.y - a.y)) / 2
+ };
+ Triangle.det = function det (m00, m01, m10, m11) {
+ return m00 * m11 - m01 * m10
+ };
+ Triangle.interpolateZ = function interpolateZ (p, v0, v1, v2) {
+ var x0 = v0.x;
+ var y0 = v0.y;
+ var a = v1.x - x0;
+ var b = v2.x - x0;
+ var c = v1.y - y0;
+ var d = v2.y - y0;
+ var det = a * d - b * c;
+ var dx = p.x - x0;
+ var dy = p.y - y0;
+ var t = (d * dx - b * dy) / det;
+ var u = (-c * dx + a * dy) / det;
+ var z = v0.z + t * (v1.z - v0.z) + u * (v2.z - v0.z);
+ return z
+ };
+ Triangle.longestSideLength = function longestSideLength (a, b, c) {
+ var lenAB = a.distance(b);
+ var lenBC = b.distance(c);
+ var lenCA = c.distance(a);
+ var maxLen = lenAB;
+ if (lenBC > maxLen) { maxLen = lenBC; }
+ if (lenCA > maxLen) { maxLen = lenCA; }
+ return maxLen
+ };
+ Triangle.isAcute = function isAcute (a, b, c) {
+ if (!Angle.isAcute(a, b, c)) { return false }
+ if (!Angle.isAcute(b, c, a)) { return false }
+ if (!Angle.isAcute(c, a, b)) { return false }
+ return true
+ };
+ Triangle.circumcentre = function circumcentre (a, b, c) {
+ var cx = c.x;
+ var cy = c.y;
+ var ax = a.x - cx;
+ var ay = a.y - cy;
+ var bx = b.x - cx;
+ var by = b.y - cy;
+ var denom = 2 * Triangle.det(ax, ay, bx, by);
+ var numx = Triangle.det(ay, ax * ax + ay * ay, by, bx * bx + by * by);
+ var numy = Triangle.det(ax, ax * ax + ay * ay, bx, bx * bx + by * by);
+ var ccx = cx - numx / denom;
+ var ccy = cy + numy / denom;
+ return new Coordinate(ccx, ccy)
+ };
+ Triangle.perpendicularBisector = function perpendicularBisector (a, b) {
+ var dx = b.x - a.x;
+ var dy = b.y - a.y;
+ var l1 = new HCoordinate(a.x + dx / 2.0, a.y + dy / 2.0, 1.0);
+ var l2 = new HCoordinate(a.x - dy + dx / 2.0, a.y + dx + dy / 2.0, 1.0);
+ return new HCoordinate(l1, l2)
+ };
+ Triangle.angleBisector = function angleBisector (a, b, c) {
+ var len0 = b.distance(a);
+ var len2 = b.distance(c);
+ var frac = len0 / (len0 + len2);
+ var dx = c.x - a.x;
+ var dy = c.y - a.y;
+ var splitPt = new Coordinate(a.x + frac * dx, a.y + frac * dy);
+ return splitPt
+ };
+ Triangle.area3D = function area3D (a, b, c) {
+ var ux = b.x - a.x;
+ var uy = b.y - a.y;
+ var uz = b.z - a.z;
+ var vx = c.x - a.x;
+ var vy = c.y - a.y;
+ var vz = c.z - a.z;
+ var crossx = uy * vz - uz * vy;
+ var crossy = uz * vx - ux * vz;
+ var crossz = ux * vy - uy * vx;
+ var absSq = crossx * crossx + crossy * crossy + crossz * crossz;
+ var area3D = Math.sqrt(absSq) / 2;
+ return area3D
+ };
+ Triangle.centroid = function centroid (a, b, c) {
+ var x = (a.x + b.x + c.x) / 3;
+ var y = (a.y + b.y + c.y) / 3;
+ return new Coordinate(x, y)
+ };
+ Triangle.inCentre = function inCentre (a, b, c) {
+ var len0 = b.distance(c);
+ var len1 = a.distance(c);
+ var len2 = a.distance(b);
+ var circum = len0 + len1 + len2;
+ var inCentreX = (len0 * a.x + len1 * b.x + len2 * c.x) / circum;
+ var inCentreY = (len0 * a.y + len1 * b.y + len2 * c.y) / circum;
+ return new Coordinate(inCentreX, inCentreY)
+ };
+
+ var OffsetCurveSetBuilder = function OffsetCurveSetBuilder () {
+ this._inputGeom = null;
+ this._distance = null;
+ this._curveBuilder = null;
+ this._curveList = new ArrayList();
+ var inputGeom = arguments[0];
+ var distance = arguments[1];
+ var curveBuilder = arguments[2];
+ this._inputGeom = inputGeom;
+ this._distance = distance;
+ this._curveBuilder = curveBuilder;
+ };
+ OffsetCurveSetBuilder.prototype.addPoint = function addPoint (p) {
+ if (this._distance <= 0.0) { return null }
+ var coord = p.getCoordinates();
+ var curve = this._curveBuilder.getLineCurve(coord, this._distance);
+ this.addCurve(curve, Location.EXTERIOR, Location.INTERIOR);
+ };
+ OffsetCurveSetBuilder.prototype.addPolygon = function addPolygon (p) {
+ var this$1 = this;
+
+ var offsetDistance = this._distance;
+ var offsetSide = Position.LEFT;
+ if (this._distance < 0.0) {
+ offsetDistance = -this._distance;
+ offsetSide = Position.RIGHT;
+ }
+ var shell = p.getExteriorRing();
+ var shellCoord = CoordinateArrays.removeRepeatedPoints(shell.getCoordinates());
+ if (this._distance < 0.0 && this.isErodedCompletely(shell, this._distance)) { return null }
+ if (this._distance <= 0.0 && shellCoord.length < 3) { return null }
+ this.addPolygonRing(shellCoord, offsetDistance, offsetSide, Location.EXTERIOR, Location.INTERIOR);
+ for (var i = 0; i < p.getNumInteriorRing(); i++) {
+ var hole = p.getInteriorRingN(i);
+ var holeCoord = CoordinateArrays.removeRepeatedPoints(hole.getCoordinates());
+ if (this$1._distance > 0.0 && this$1.isErodedCompletely(hole, -this$1._distance)) { continue }
+ this$1.addPolygonRing(holeCoord, offsetDistance, Position.opposite(offsetSide), Location.INTERIOR, Location.EXTERIOR);
+ }
+ };
+ OffsetCurveSetBuilder.prototype.isTriangleErodedCompletely = function isTriangleErodedCompletely (triangleCoord, bufferDistance) {
+ var tri = new Triangle(triangleCoord[0], triangleCoord[1], triangleCoord[2]);
+ var inCentre = tri.inCentre();
+ var distToCentre = CGAlgorithms.distancePointLine(inCentre, tri.p0, tri.p1);
+ return distToCentre < Math.abs(bufferDistance)
+ };
+ OffsetCurveSetBuilder.prototype.addLineString = function addLineString (line) {
+ if (this._distance <= 0.0 && !this._curveBuilder.getBufferParameters().isSingleSided()) { return null }
+ var coord = CoordinateArrays.removeRepeatedPoints(line.getCoordinates());
+ var curve = this._curveBuilder.getLineCurve(coord, this._distance);
+ this.addCurve(curve, Location.EXTERIOR, Location.INTERIOR);
+ };
+ OffsetCurveSetBuilder.prototype.addCurve = function addCurve (coord, leftLoc, rightLoc) {
+ if (coord === null || coord.length < 2) { return null }
+ var e = new NodedSegmentString(coord, new Label(0, Location.BOUNDARY, leftLoc, rightLoc));
+ this._curveList.add(e);
+ };
+ OffsetCurveSetBuilder.prototype.getCurves = function getCurves () {
+ this.add(this._inputGeom);
+ return this._curveList
+ };
+ OffsetCurveSetBuilder.prototype.addPolygonRing = function addPolygonRing (coord, offsetDistance, side, cwLeftLoc, cwRightLoc) {
+ if (offsetDistance === 0.0 && coord.length < LinearRing.MINIMUM_VALID_SIZE) { return null }
+ var leftLoc = cwLeftLoc;
+ var rightLoc = cwRightLoc;
+ if (coord.length >= LinearRing.MINIMUM_VALID_SIZE && CGAlgorithms.isCCW(coord)) {
+ leftLoc = cwRightLoc;
+ rightLoc = cwLeftLoc;
+ side = Position.opposite(side);
+ }
+ var curve = this._curveBuilder.getRingCurve(coord, side, offsetDistance);
+ this.addCurve(curve, leftLoc, rightLoc);
+ };
+ OffsetCurveSetBuilder.prototype.add = function add (g) {
+ if (g.isEmpty()) { return null }
+ if (g instanceof Polygon) { this.addPolygon(g); }
+ else if (g instanceof LineString) { this.addLineString(g); }
+ else if (g instanceof Point) { this.addPoint(g); }
+ else if (g instanceof MultiPoint) { this.addCollection(g); }
+ else if (g instanceof MultiLineString) { this.addCollection(g); }
+ else if (g instanceof MultiPolygon) { this.addCollection(g); }
+ else if (g instanceof GeometryCollection) { this.addCollection(g); }
+ // else throw new UnsupportedOperationException(g.getClass().getName())
+ };
+ OffsetCurveSetBuilder.prototype.isErodedCompletely = function isErodedCompletely (ring, bufferDistance) {
+ var ringCoord = ring.getCoordinates();
+ // const minDiam = 0.0
+ if (ringCoord.length < 4) { return bufferDistance < 0 }
+ if (ringCoord.length === 4) { return this.isTriangleErodedCompletely(ringCoord, bufferDistance) }
+ var env = ring.getEnvelopeInternal();
+ var envMinDimension = Math.min(env.getHeight(), env.getWidth());
+ if (bufferDistance < 0.0 && 2 * Math.abs(bufferDistance) > envMinDimension) { return true }
+ return false
+ };
+ OffsetCurveSetBuilder.prototype.addCollection = function addCollection (gc) {
+ var this$1 = this;
+
+ for (var i = 0; i < gc.getNumGeometries(); i++) {
+ var g = gc.getGeometryN(i);
+ this$1.add(g);
+ }
+ };
+ OffsetCurveSetBuilder.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ OffsetCurveSetBuilder.prototype.getClass = function getClass () {
+ return OffsetCurveSetBuilder
+ };
+
+ var PointOnGeometryLocator = function PointOnGeometryLocator () {};
+
+ PointOnGeometryLocator.prototype.locate = function locate (p) {};
+ PointOnGeometryLocator.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ PointOnGeometryLocator.prototype.getClass = function getClass () {
+ return PointOnGeometryLocator
+ };
+
+ var GeometryCollectionIterator = function GeometryCollectionIterator () {
+ this._parent = null;
+ this._atStart = null;
+ this._max = null;
+ this._index = null;
+ this._subcollectionIterator = null;
+ var parent = arguments[0];
+ this._parent = parent;
+ this._atStart = true;
+ this._index = 0;
+ this._max = parent.getNumGeometries();
+ };
+ GeometryCollectionIterator.prototype.next = function next () {
+ if (this._atStart) {
+ this._atStart = false;
+ if (GeometryCollectionIterator.isAtomic(this._parent)) { this._index++; }
+ return this._parent
+ }
+ if (this._subcollectionIterator !== null) {
+ if (this._subcollectionIterator.hasNext()) {
+ return this._subcollectionIterator.next()
+ } else {
+ this._subcollectionIterator = null;
+ }
+ }
+ if (this._index >= this._max) {
+ throw new NoSuchElementException()
+ }
+ var obj = this._parent.getGeometryN(this._index++);
+ if (obj instanceof GeometryCollection) {
+ this._subcollectionIterator = new GeometryCollectionIterator(obj);
+ return this._subcollectionIterator.next()
+ }
+ return obj
+ };
+ GeometryCollectionIterator.prototype.remove = function remove () {
+ throw new Error(this.getClass().getName())
+ };
+ GeometryCollectionIterator.prototype.hasNext = function hasNext () {
+ if (this._atStart) {
+ return true
+ }
+ if (this._subcollectionIterator !== null) {
+ if (this._subcollectionIterator.hasNext()) {
+ return true
+ }
+ this._subcollectionIterator = null;
+ }
+ if (this._index >= this._max) {
+ return false
+ }
+ return true
+ };
+ GeometryCollectionIterator.prototype.interfaces_ = function interfaces_ () {
+ return [Iterator$1]
+ };
+ GeometryCollectionIterator.prototype.getClass = function getClass () {
+ return GeometryCollectionIterator
+ };
+ GeometryCollectionIterator.isAtomic = function isAtomic (geom) {
+ return !(geom instanceof GeometryCollection)
+ };
+
+ var SimplePointInAreaLocator = function SimplePointInAreaLocator () {
+ this._geom = null;
+ var geom = arguments[0];
+ this._geom = geom;
+ };
+ SimplePointInAreaLocator.prototype.locate = function locate (p) {
+ return SimplePointInAreaLocator.locate(p, this._geom)
+ };
+ SimplePointInAreaLocator.prototype.interfaces_ = function interfaces_ () {
+ return [PointOnGeometryLocator]
+ };
+ SimplePointInAreaLocator.prototype.getClass = function getClass () {
+ return SimplePointInAreaLocator
+ };
+ SimplePointInAreaLocator.isPointInRing = function isPointInRing (p, ring) {
+ if (!ring.getEnvelopeInternal().intersects(p)) { return false }
+ return CGAlgorithms.isPointInRing(p, ring.getCoordinates())
+ };
+ SimplePointInAreaLocator.containsPointInPolygon = function containsPointInPolygon (p, poly) {
+ if (poly.isEmpty()) { return false }
+ var shell = poly.getExteriorRing();
+ if (!SimplePointInAreaLocator.isPointInRing(p, shell)) { return false }
+ for (var i = 0; i < poly.getNumInteriorRing(); i++) {
+ var hole = poly.getInteriorRingN(i);
+ if (SimplePointInAreaLocator.isPointInRing(p, hole)) { return false }
+ }
+ return true
+ };
+ SimplePointInAreaLocator.containsPoint = function containsPoint (p, geom) {
+ if (geom instanceof Polygon) {
+ return SimplePointInAreaLocator.containsPointInPolygon(p, geom)
+ } else if (geom instanceof GeometryCollection) {
+ var geomi = new GeometryCollectionIterator(geom);
+ while (geomi.hasNext()) {
+ var g2 = geomi.next();
+ if (g2 !== geom) { if (SimplePointInAreaLocator.containsPoint(p, g2)) { return true } }
+ }
+ }
+ return false
+ };
+ SimplePointInAreaLocator.locate = function locate (p, geom) {
+ if (geom.isEmpty()) { return Location.EXTERIOR }
+ if (SimplePointInAreaLocator.containsPoint(p, geom)) { return Location.INTERIOR }
+ return Location.EXTERIOR
+ };
+
+ var EdgeEndStar = function EdgeEndStar () {
+ this._edgeMap = new TreeMap();
+ this._edgeList = null;
+ this._ptInAreaLocation = [Location.NONE, Location.NONE];
+ };
+ EdgeEndStar.prototype.getNextCW = function getNextCW (ee) {
+ this.getEdges();
+ var i = this._edgeList.indexOf(ee);
+ var iNextCW = i - 1;
+ if (i === 0) { iNextCW = this._edgeList.size() - 1; }
+ return this._edgeList.get(iNextCW)
+ };
+ EdgeEndStar.prototype.propagateSideLabels = function propagateSideLabels (geomIndex) {
+ var startLoc = Location.NONE;
+ for (var it = this.iterator(); it.hasNext();) {
+ var e = it.next();
+ var label = e.getLabel();
+ if (label.isArea(geomIndex) && label.getLocation(geomIndex, Position.LEFT) !== Location.NONE) { startLoc = label.getLocation(geomIndex, Position.LEFT); }
+ }
+ if (startLoc === Location.NONE) { return null }
+ var currLoc = startLoc;
+ for (var it$1 = this.iterator(); it$1.hasNext();) {
+ var e$1 = it$1.next();
+ var label$1 = e$1.getLabel();
+ if (label$1.getLocation(geomIndex, Position.ON) === Location.NONE) { label$1.setLocation(geomIndex, Position.ON, currLoc); }
+ if (label$1.isArea(geomIndex)) {
+ var leftLoc = label$1.getLocation(geomIndex, Position.LEFT);
+ var rightLoc = label$1.getLocation(geomIndex, Position.RIGHT);
+ if (rightLoc !== Location.NONE) {
+ if (rightLoc !== currLoc) { throw new TopologyException('side location conflict', e$1.getCoordinate()) }
+ if (leftLoc === Location.NONE) {
+ Assert.shouldNeverReachHere('found single null side (at ' + e$1.getCoordinate() + ')');
+ }
+ currLoc = leftLoc;
+ } else {
+ Assert.isTrue(label$1.getLocation(geomIndex, Position.LEFT) === Location.NONE, 'found single null side');
+ label$1.setLocation(geomIndex, Position.RIGHT, currLoc);
+ label$1.setLocation(geomIndex, Position.LEFT, currLoc);
+ }
+ }
+ }
+ };
+ EdgeEndStar.prototype.getCoordinate = function getCoordinate () {
+ var it = this.iterator();
+ if (!it.hasNext()) { return null }
+ var e = it.next();
+ return e.getCoordinate()
+ };
+ EdgeEndStar.prototype.print = function print (out) {
+ System.out.println('EdgeEndStar: ' + this.getCoordinate());
+ for (var it = this.iterator(); it.hasNext();) {
+ var e = it.next();
+ e.print(out);
+ }
+ };
+ EdgeEndStar.prototype.isAreaLabelsConsistent = function isAreaLabelsConsistent (geomGraph) {
+ this.computeEdgeEndLabels(geomGraph.getBoundaryNodeRule());
+ return this.checkAreaLabelsConsistent(0)
+ };
+ EdgeEndStar.prototype.checkAreaLabelsConsistent = function checkAreaLabelsConsistent (geomIndex) {
+ var edges = this.getEdges();
+ if (edges.size() <= 0) { return true }
+ var lastEdgeIndex = edges.size() - 1;
+ var startLabel = edges.get(lastEdgeIndex).getLabel();
+ var startLoc = startLabel.getLocation(geomIndex, Position.LEFT);
+ Assert.isTrue(startLoc !== Location.NONE, 'Found unlabelled area edge');
+ var currLoc = startLoc;
+ for (var it = this.iterator(); it.hasNext();) {
+ var e = it.next();
+ var label = e.getLabel();
+ Assert.isTrue(label.isArea(geomIndex), 'Found non-area edge');
+ var leftLoc = label.getLocation(geomIndex, Position.LEFT);
+ var rightLoc = label.getLocation(geomIndex, Position.RIGHT);
+ if (leftLoc === rightLoc) {
+ return false
+ }
+ if (rightLoc !== currLoc) {
+ return false
+ }
+ currLoc = leftLoc;
+ }
+ return true
+ };
+ EdgeEndStar.prototype.findIndex = function findIndex (eSearch) {
+ var this$1 = this;
+
+ this.iterator();
+ for (var i = 0; i < this._edgeList.size(); i++) {
+ var e = this$1._edgeList.get(i);
+ if (e === eSearch) { return i }
+ }
+ return -1
+ };
+ EdgeEndStar.prototype.iterator = function iterator () {
+ return this.getEdges().iterator()
+ };
+ EdgeEndStar.prototype.getEdges = function getEdges () {
+ if (this._edgeList === null) {
+ this._edgeList = new ArrayList(this._edgeMap.values());
+ }
+ return this._edgeList
+ };
+ EdgeEndStar.prototype.getLocation = function getLocation (geomIndex, p, geom) {
+ if (this._ptInAreaLocation[geomIndex] === Location.NONE) {
+ this._ptInAreaLocation[geomIndex] = SimplePointInAreaLocator.locate(p, geom[geomIndex].getGeometry());
+ }
+ return this._ptInAreaLocation[geomIndex]
+ };
+ EdgeEndStar.prototype.toString = function toString () {
+ var buf = new StringBuffer();
+ buf.append('EdgeEndStar: ' + this.getCoordinate());
+ buf.append('\n');
+ for (var it = this.iterator(); it.hasNext();) {
+ var e = it.next();
+ buf.append(e);
+ buf.append('\n');
+ }
+ return buf.toString()
+ };
+ EdgeEndStar.prototype.computeEdgeEndLabels = function computeEdgeEndLabels (boundaryNodeRule) {
+ for (var it = this.iterator(); it.hasNext();) {
+ var ee = it.next();
+ ee.computeLabel(boundaryNodeRule);
+ }
+ };
+ EdgeEndStar.prototype.computeLabelling = function computeLabelling (geomGraph) {
+ var this$1 = this;
+
+ this.computeEdgeEndLabels(geomGraph[0].getBoundaryNodeRule());
+ this.propagateSideLabels(0);
+ this.propagateSideLabels(1);
+ var hasDimensionalCollapseEdge = [false, false];
+ for (var it = this.iterator(); it.hasNext();) {
+ var e = it.next();
+ var label = e.getLabel();
+ for (var geomi = 0; geomi < 2; geomi++) {
+ if (label.isLine(geomi) && label.getLocation(geomi) === Location.BOUNDARY) { hasDimensionalCollapseEdge[geomi] = true; }
+ }
+ }
+ for (var it$1 = this.iterator(); it$1.hasNext();) {
+ var e$1 = it$1.next();
+ var label$1 = e$1.getLabel();
+ for (var geomi$1 = 0; geomi$1 < 2; geomi$1++) {
+ if (label$1.isAnyNull(geomi$1)) {
+ var loc = Location.NONE;
+ if (hasDimensionalCollapseEdge[geomi$1]) {
+ loc = Location.EXTERIOR;
+ } else {
+ var p = e$1.getCoordinate();
+ loc = this$1.getLocation(geomi$1, p, geomGraph);
+ }
+ label$1.setAllLocationsIfNull(geomi$1, loc);
+ }
+ }
+ }
+ };
+ EdgeEndStar.prototype.getDegree = function getDegree () {
+ return this._edgeMap.size()
+ };
+ EdgeEndStar.prototype.insertEdgeEnd = function insertEdgeEnd (e, obj) {
+ this._edgeMap.put(e, obj);
+ this._edgeList = null;
+ };
+ EdgeEndStar.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ EdgeEndStar.prototype.getClass = function getClass () {
+ return EdgeEndStar
+ };
+
+ var DirectedEdgeStar = (function (EdgeEndStar$$1) {
+ function DirectedEdgeStar () {
+ EdgeEndStar$$1.call(this);
+ this._resultAreaEdgeList = null;
+ this._label = null;
+ this._SCANNING_FOR_INCOMING = 1;
+ this._LINKING_TO_OUTGOING = 2;
+ }
+
+ if ( EdgeEndStar$$1 ) DirectedEdgeStar.__proto__ = EdgeEndStar$$1;
+ DirectedEdgeStar.prototype = Object.create( EdgeEndStar$$1 && EdgeEndStar$$1.prototype );
+ DirectedEdgeStar.prototype.constructor = DirectedEdgeStar;
+ DirectedEdgeStar.prototype.linkResultDirectedEdges = function linkResultDirectedEdges () {
+ var this$1 = this;
+
+ this.getResultAreaEdges();
+ var firstOut = null;
+ var incoming = null;
+ var state = this._SCANNING_FOR_INCOMING;
+ for (var i = 0; i < this._resultAreaEdgeList.size(); i++) {
+ var nextOut = this$1._resultAreaEdgeList.get(i);
+ var nextIn = nextOut.getSym();
+ if (!nextOut.getLabel().isArea()) { continue }
+ if (firstOut === null && nextOut.isInResult()) { firstOut = nextOut; }
+ switch (state) {
+ case this$1._SCANNING_FOR_INCOMING:
+ if (!nextIn.isInResult()) { continue }
+ incoming = nextIn;
+ state = this$1._LINKING_TO_OUTGOING;
+ break
+ case this$1._LINKING_TO_OUTGOING:
+ if (!nextOut.isInResult()) { continue }
+ incoming.setNext(nextOut);
+ state = this$1._SCANNING_FOR_INCOMING;
+ break
+ }
+ }
+ if (state === this._LINKING_TO_OUTGOING) {
+ if (firstOut === null) { throw new TopologyException('no outgoing dirEdge found', this.getCoordinate()) }
+ Assert.isTrue(firstOut.isInResult(), 'unable to link last incoming dirEdge');
+ incoming.setNext(firstOut);
+ }
+ };
+ DirectedEdgeStar.prototype.insert = function insert (ee) {
+ var de = ee;
+ this.insertEdgeEnd(de, de);
+ };
+ DirectedEdgeStar.prototype.getRightmostEdge = function getRightmostEdge () {
+ var edges = this.getEdges();
+ var size = edges.size();
+ if (size < 1) { return null }
+ var de0 = edges.get(0);
+ if (size === 1) { return de0 }
+ var deLast = edges.get(size - 1);
+ var quad0 = de0.getQuadrant();
+ var quad1 = deLast.getQuadrant();
+ if (Quadrant.isNorthern(quad0) && Quadrant.isNorthern(quad1)) { return de0; } else if (!Quadrant.isNorthern(quad0) && !Quadrant.isNorthern(quad1)) { return deLast; } else {
+ // const nonHorizontalEdge = null
+ if (de0.getDy() !== 0) { return de0; } else if (deLast.getDy() !== 0) { return deLast }
+ }
+ Assert.shouldNeverReachHere('found two horizontal edges incident on node');
+ return null
+ };
+ DirectedEdgeStar.prototype.print = function print (out) {
+ System.out.println('DirectedEdgeStar: ' + this.getCoordinate());
+ for (var it = this.iterator(); it.hasNext();) {
+ var de = it.next();
+ out.print('out ');
+ de.print(out);
+ out.println();
+ out.print('in ');
+ de.getSym().print(out);
+ out.println();
+ }
+ };
+ DirectedEdgeStar.prototype.getResultAreaEdges = function getResultAreaEdges () {
+ var this$1 = this;
+
+ if (this._resultAreaEdgeList !== null) { return this._resultAreaEdgeList }
+ this._resultAreaEdgeList = new ArrayList();
+ for (var it = this.iterator(); it.hasNext();) {
+ var de = it.next();
+ if (de.isInResult() || de.getSym().isInResult()) { this$1._resultAreaEdgeList.add(de); }
+ }
+ return this._resultAreaEdgeList
+ };
+ DirectedEdgeStar.prototype.updateLabelling = function updateLabelling (nodeLabel) {
+ for (var it = this.iterator(); it.hasNext();) {
+ var de = it.next();
+ var label = de.getLabel();
+ label.setAllLocationsIfNull(0, nodeLabel.getLocation(0));
+ label.setAllLocationsIfNull(1, nodeLabel.getLocation(1));
+ }
+ };
+ DirectedEdgeStar.prototype.linkAllDirectedEdges = function linkAllDirectedEdges () {
+ var this$1 = this;
+
+ this.getEdges();
+ var prevOut = null;
+ var firstIn = null;
+ for (var i = this._edgeList.size() - 1; i >= 0; i--) {
+ var nextOut = this$1._edgeList.get(i);
+ var nextIn = nextOut.getSym();
+ if (firstIn === null) { firstIn = nextIn; }
+ if (prevOut !== null) { nextIn.setNext(prevOut); }
+ prevOut = nextOut;
+ }
+ firstIn.setNext(prevOut);
+ };
+ DirectedEdgeStar.prototype.computeDepths = function computeDepths () {
+ var this$1 = this;
+
+ if (arguments.length === 1) {
+ var de = arguments[0];
+ var edgeIndex = this.findIndex(de);
+ // const label = de.getLabel()
+ var startDepth = de.getDepth(Position.LEFT);
+ var targetLastDepth = de.getDepth(Position.RIGHT);
+ var nextDepth = this.computeDepths(edgeIndex + 1, this._edgeList.size(), startDepth);
+ var lastDepth = this.computeDepths(0, edgeIndex, nextDepth);
+ if (lastDepth !== targetLastDepth) { throw new TopologyException('depth mismatch at ' + de.getCoordinate()) }
+ } else if (arguments.length === 3) {
+ var startIndex = arguments[0];
+ var endIndex = arguments[1];
+ var startDepth$1 = arguments[2];
+ var currDepth = startDepth$1;
+ for (var i = startIndex; i < endIndex; i++) {
+ var nextDe = this$1._edgeList.get(i);
+ // const label = nextDe.getLabel()
+ nextDe.setEdgeDepths(Position.RIGHT, currDepth);
+ currDepth = nextDe.getDepth(Position.LEFT);
+ }
+ return currDepth
+ }
+ };
+ DirectedEdgeStar.prototype.mergeSymLabels = function mergeSymLabels () {
+ for (var it = this.iterator(); it.hasNext();) {
+ var de = it.next();
+ var label = de.getLabel();
+ label.merge(de.getSym().getLabel());
+ }
+ };
+ DirectedEdgeStar.prototype.linkMinimalDirectedEdges = function linkMinimalDirectedEdges (er) {
+ var this$1 = this;
+
+ var firstOut = null;
+ var incoming = null;
+ var state = this._SCANNING_FOR_INCOMING;
+ for (var i = this._resultAreaEdgeList.size() - 1; i >= 0; i--) {
+ var nextOut = this$1._resultAreaEdgeList.get(i);
+ var nextIn = nextOut.getSym();
+ if (firstOut === null && nextOut.getEdgeRing() === er) { firstOut = nextOut; }
+ switch (state) {
+ case this$1._SCANNING_FOR_INCOMING:
+ if (nextIn.getEdgeRing() !== er) { continue }
+ incoming = nextIn;
+ state = this$1._LINKING_TO_OUTGOING;
+ break
+ case this$1._LINKING_TO_OUTGOING:
+ if (nextOut.getEdgeRing() !== er) { continue }
+ incoming.setNextMin(nextOut);
+ state = this$1._SCANNING_FOR_INCOMING;
+ break
+ }
+ }
+ if (state === this._LINKING_TO_OUTGOING) {
+ Assert.isTrue(firstOut !== null, 'found null for first outgoing dirEdge');
+ Assert.isTrue(firstOut.getEdgeRing() === er, 'unable to link last incoming dirEdge');
+ incoming.setNextMin(firstOut);
+ }
+ };
+ DirectedEdgeStar.prototype.getOutgoingDegree = function getOutgoingDegree () {
+ if (arguments.length === 0) {
+ var degree = 0;
+ for (var it = this.iterator(); it.hasNext();) {
+ var de = it.next();
+ if (de.isInResult()) { degree++; }
+ }
+ return degree
+ } else if (arguments.length === 1) {
+ var er = arguments[0];
+ var degree$1 = 0;
+ for (var it$1 = this.iterator(); it$1.hasNext();) {
+ var de$1 = it$1.next();
+ if (de$1.getEdgeRing() === er) { degree$1++; }
+ }
+ return degree$1
+ }
+ };
+ DirectedEdgeStar.prototype.getLabel = function getLabel () {
+ return this._label
+ };
+ DirectedEdgeStar.prototype.findCoveredLineEdges = function findCoveredLineEdges () {
+ var startLoc = Location.NONE;
+ for (var it = this.iterator(); it.hasNext();) {
+ var nextOut = it.next();
+ var nextIn = nextOut.getSym();
+ if (!nextOut.isLineEdge()) {
+ if (nextOut.isInResult()) {
+ startLoc = Location.INTERIOR;
+ break
+ }
+ if (nextIn.isInResult()) {
+ startLoc = Location.EXTERIOR;
+ break
+ }
+ }
+ }
+ if (startLoc === Location.NONE) { return null }
+ var currLoc = startLoc;
+ for (var it$1 = this.iterator(); it$1.hasNext();) {
+ var nextOut$1 = it$1.next();
+ var nextIn$1 = nextOut$1.getSym();
+ if (nextOut$1.isLineEdge()) {
+ nextOut$1.getEdge().setCovered(currLoc === Location.INTERIOR);
+ } else {
+ if (nextOut$1.isInResult()) { currLoc = Location.EXTERIOR; }
+ if (nextIn$1.isInResult()) { currLoc = Location.INTERIOR; }
+ }
+ }
+ };
+ DirectedEdgeStar.prototype.computeLabelling = function computeLabelling (geom) {
+ var this$1 = this;
+
+ EdgeEndStar$$1.prototype.computeLabelling.call(this, geom);
+ this._label = new Label(Location.NONE);
+ for (var it = this.iterator(); it.hasNext();) {
+ var ee = it.next();
+ var e = ee.getEdge();
+ var eLabel = e.getLabel();
+ for (var i = 0; i < 2; i++) {
+ var eLoc = eLabel.getLocation(i);
+ if (eLoc === Location.INTERIOR || eLoc === Location.BOUNDARY) { this$1._label.setLocation(i, Location.INTERIOR); }
+ }
+ }
+ };
+ DirectedEdgeStar.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ DirectedEdgeStar.prototype.getClass = function getClass () {
+ return DirectedEdgeStar
+ };
+
+ return DirectedEdgeStar;
+ }(EdgeEndStar));
+
+ var OverlayNodeFactory = (function (NodeFactory$$1) {
+ function OverlayNodeFactory () {
+ NodeFactory$$1.apply(this, arguments);
+ }
+
+ if ( NodeFactory$$1 ) OverlayNodeFactory.__proto__ = NodeFactory$$1;
+ OverlayNodeFactory.prototype = Object.create( NodeFactory$$1 && NodeFactory$$1.prototype );
+ OverlayNodeFactory.prototype.constructor = OverlayNodeFactory;
+
+ OverlayNodeFactory.prototype.createNode = function createNode (coord) {
+ return new Node$1(coord, new DirectedEdgeStar())
+ };
+ OverlayNodeFactory.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ OverlayNodeFactory.prototype.getClass = function getClass () {
+ return OverlayNodeFactory
+ };
+
+ return OverlayNodeFactory;
+ }(NodeFactory));
+
+ var OrientedCoordinateArray = function OrientedCoordinateArray () {
+ this._pts = null;
+ this._orientation = null;
+ var pts = arguments[0];
+ this._pts = pts;
+ this._orientation = OrientedCoordinateArray.orientation(pts);
+ };
+ OrientedCoordinateArray.prototype.compareTo = function compareTo (o1) {
+ var oca = o1;
+ var comp = OrientedCoordinateArray.compareOriented(this._pts, this._orientation, oca._pts, oca._orientation);
+ return comp
+ };
+ OrientedCoordinateArray.prototype.interfaces_ = function interfaces_ () {
+ return [Comparable]
+ };
+ OrientedCoordinateArray.prototype.getClass = function getClass () {
+ return OrientedCoordinateArray
+ };
+ OrientedCoordinateArray.orientation = function orientation (pts) {
+ return CoordinateArrays.increasingDirection(pts) === 1
+ };
+ OrientedCoordinateArray.compareOriented = function compareOriented (pts1, orientation1, pts2, orientation2) {
+ var dir1 = orientation1 ? 1 : -1;
+ var dir2 = orientation2 ? 1 : -1;
+ var limit1 = orientation1 ? pts1.length : -1;
+ var limit2 = orientation2 ? pts2.length : -1;
+ var i1 = orientation1 ? 0 : pts1.length - 1;
+ var i2 = orientation2 ? 0 : pts2.length - 1;
+ // const comp = 0
+ while (true) {
+ var compPt = pts1[i1].compareTo(pts2[i2]);
+ if (compPt !== 0) { return compPt }
+ i1 += dir1;
+ i2 += dir2;
+ var done1 = i1 === limit1;
+ var done2 = i2 === limit2;
+ if (done1 && !done2) { return -1 }
+ if (!done1 && done2) { return 1 }
+ if (done1 && done2) { return 0 }
+ }
+ };
+
+ var EdgeList = function EdgeList () {
+ this._edges = new ArrayList();
+ this._ocaMap = new TreeMap();
+ };
+ EdgeList.prototype.print = function print (out) {
+ var this$1 = this;
+
+ out.print('MULTILINESTRING ( ');
+ for (var j = 0; j < this._edges.size(); j++) {
+ var e = this$1._edges.get(j);
+ if (j > 0) { out.print(','); }
+ out.print('(');
+ var pts = e.getCoordinates();
+ for (var i = 0; i < pts.length; i++) {
+ if (i > 0) { out.print(','); }
+ out.print(pts[i].x + ' ' + pts[i].y);
+ }
+ out.println(')');
+ }
+ out.print(') ');
+ };
+ EdgeList.prototype.addAll = function addAll (edgeColl) {
+ var this$1 = this;
+
+ for (var i = edgeColl.iterator(); i.hasNext();) {
+ this$1.add(i.next());
+ }
+ };
+ EdgeList.prototype.findEdgeIndex = function findEdgeIndex (e) {
+ var this$1 = this;
+
+ for (var i = 0; i < this._edges.size(); i++) {
+ if (this$1._edges.get(i).equals(e)) { return i }
+ }
+ return -1
+ };
+ EdgeList.prototype.iterator = function iterator () {
+ return this._edges.iterator()
+ };
+ EdgeList.prototype.getEdges = function getEdges () {
+ return this._edges
+ };
+ EdgeList.prototype.get = function get (i) {
+ return this._edges.get(i)
+ };
+ EdgeList.prototype.findEqualEdge = function findEqualEdge (e) {
+ var oca = new OrientedCoordinateArray(e.getCoordinates());
+ var matchEdge = this._ocaMap.get(oca);
+ return matchEdge
+ };
+ EdgeList.prototype.add = function add (e) {
+ this._edges.add(e);
+ var oca = new OrientedCoordinateArray(e.getCoordinates());
+ this._ocaMap.put(oca, e);
+ };
+ EdgeList.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ EdgeList.prototype.getClass = function getClass () {
+ return EdgeList
+ };
+
+ var SegmentIntersector = function SegmentIntersector () {};
+
+ SegmentIntersector.prototype.processIntersections = function processIntersections (e0, segIndex0, e1, segIndex1) {};
+ SegmentIntersector.prototype.isDone = function isDone () {};
+ SegmentIntersector.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ SegmentIntersector.prototype.getClass = function getClass () {
+ return SegmentIntersector
+ };
+
+ var IntersectionAdder = function IntersectionAdder () {
+ this._hasIntersection = false;
+ this._hasProper = false;
+ this._hasProperInterior = false;
+ this._hasInterior = false;
+ this._properIntersectionPoint = null;
+ this._li = null;
+ this._isSelfIntersection = null;
+ this.numIntersections = 0;
+ this.numInteriorIntersections = 0;
+ this.numProperIntersections = 0;
+ this.numTests = 0;
+ var li = arguments[0];
+ this._li = li;
+ };
+ IntersectionAdder.prototype.isTrivialIntersection = function isTrivialIntersection (e0, segIndex0, e1, segIndex1) {
+ if (e0 === e1) {
+ if (this._li.getIntersectionNum() === 1) {
+ if (IntersectionAdder.isAdjacentSegments(segIndex0, segIndex1)) { return true }
+ if (e0.isClosed()) {
+ var maxSegIndex = e0.size() - 1;
+ if ((segIndex0 === 0 && segIndex1 === maxSegIndex) ||
+ (segIndex1 === 0 && segIndex0 === maxSegIndex)) {
+ return true
+ }
+ }
+ }
+ }
+ return false
+ };
+ IntersectionAdder.prototype.getProperIntersectionPoint = function getProperIntersectionPoint () {
+ return this._properIntersectionPoint
+ };
+ IntersectionAdder.prototype.hasProperInteriorIntersection = function hasProperInteriorIntersection () {
+ return this._hasProperInterior
+ };
+ IntersectionAdder.prototype.getLineIntersector = function getLineIntersector () {
+ return this._li
+ };
+ IntersectionAdder.prototype.hasProperIntersection = function hasProperIntersection () {
+ return this._hasProper
+ };
+ IntersectionAdder.prototype.processIntersections = function processIntersections (e0, segIndex0, e1, segIndex1) {
+ if (e0 === e1 && segIndex0 === segIndex1) { return null }
+ this.numTests++;
+ var p00 = e0.getCoordinates()[segIndex0];
+ var p01 = e0.getCoordinates()[segIndex0 + 1];
+ var p10 = e1.getCoordinates()[segIndex1];
+ var p11 = e1.getCoordinates()[segIndex1 + 1];
+ this._li.computeIntersection(p00, p01, p10, p11);
+ if (this._li.hasIntersection()) {
+ this.numIntersections++;
+ if (this._li.isInteriorIntersection()) {
+ this.numInteriorIntersections++;
+ this._hasInterior = true;
+ }
+ if (!this.isTrivialIntersection(e0, segIndex0, e1, segIndex1)) {
+ this._hasIntersection = true;
+ e0.addIntersections(this._li, segIndex0, 0);
+ e1.addIntersections(this._li, segIndex1, 1);
+ if (this._li.isProper()) {
+ this.numProperIntersections++;
+ this._hasProper = true;
+ this._hasProperInterior = true;
+ }
+ }
+ }
+ };
+ IntersectionAdder.prototype.hasIntersection = function hasIntersection () {
+ return this._hasIntersection
+ };
+ IntersectionAdder.prototype.isDone = function isDone () {
+ return false
+ };
+ IntersectionAdder.prototype.hasInteriorIntersection = function hasInteriorIntersection () {
+ return this._hasInterior
+ };
+ IntersectionAdder.prototype.interfaces_ = function interfaces_ () {
+ return [SegmentIntersector]
+ };
+ IntersectionAdder.prototype.getClass = function getClass () {
+ return IntersectionAdder
+ };
+ IntersectionAdder.isAdjacentSegments = function isAdjacentSegments (i1, i2) {
+ return Math.abs(i1 - i2) === 1
+ };
+
+ var EdgeIntersection = function EdgeIntersection () {
+ this.coord = null;
+ this.segmentIndex = null;
+ this.dist = null;
+ var coord = arguments[0];
+ var segmentIndex = arguments[1];
+ var dist = arguments[2];
+ this.coord = new Coordinate(coord);
+ this.segmentIndex = segmentIndex;
+ this.dist = dist;
+ };
+ EdgeIntersection.prototype.getSegmentIndex = function getSegmentIndex () {
+ return this.segmentIndex
+ };
+ EdgeIntersection.prototype.getCoordinate = function getCoordinate () {
+ return this.coord
+ };
+ EdgeIntersection.prototype.print = function print (out) {
+ out.print(this.coord);
+ out.print(' seg # = ' + this.segmentIndex);
+ out.println(' dist = ' + this.dist);
+ };
+ EdgeIntersection.prototype.compareTo = function compareTo (obj) {
+ var other = obj;
+ return this.compare(other.segmentIndex, other.dist)
+ };
+ EdgeIntersection.prototype.isEndPoint = function isEndPoint (maxSegmentIndex) {
+ if (this.segmentIndex === 0 && this.dist === 0.0) { return true }
+ if (this.segmentIndex === maxSegmentIndex) { return true }
+ return false
+ };
+ EdgeIntersection.prototype.toString = function toString () {
+ return this.coord + ' seg # = ' + this.segmentIndex + ' dist = ' + this.dist
+ };
+ EdgeIntersection.prototype.getDistance = function getDistance () {
+ return this.dist
+ };
+ EdgeIntersection.prototype.compare = function compare (segmentIndex, dist) {
+ if (this.segmentIndex < segmentIndex) { return -1 }
+ if (this.segmentIndex > segmentIndex) { return 1 }
+ if (this.dist < dist) { return -1 }
+ if (this.dist > dist) { return 1 }
+ return 0
+ };
+ EdgeIntersection.prototype.interfaces_ = function interfaces_ () {
+ return [Comparable]
+ };
+ EdgeIntersection.prototype.getClass = function getClass () {
+ return EdgeIntersection
+ };
+
+ var EdgeIntersectionList = function EdgeIntersectionList () {
+ this._nodeMap = new TreeMap();
+ this.edge = null;
+ var edge = arguments[0];
+ this.edge = edge;
+ };
+ EdgeIntersectionList.prototype.print = function print (out) {
+ out.println('Intersections:');
+ for (var it = this.iterator(); it.hasNext();) {
+ var ei = it.next();
+ ei.print(out);
+ }
+ };
+ EdgeIntersectionList.prototype.iterator = function iterator () {
+ return this._nodeMap.values().iterator()
+ };
+ EdgeIntersectionList.prototype.addSplitEdges = function addSplitEdges (edgeList) {
+ var this$1 = this;
+
+ this.addEndpoints();
+ var it = this.iterator();
+ var eiPrev = it.next();
+ while (it.hasNext()) {
+ var ei = it.next();
+ var newEdge = this$1.createSplitEdge(eiPrev, ei);
+ edgeList.add(newEdge);
+ eiPrev = ei;
+ }
+ };
+ EdgeIntersectionList.prototype.addEndpoints = function addEndpoints () {
+ var maxSegIndex = this.edge.pts.length - 1;
+ this.add(this.edge.pts[0], 0, 0.0);
+ this.add(this.edge.pts[maxSegIndex], maxSegIndex, 0.0);
+ };
+ EdgeIntersectionList.prototype.createSplitEdge = function createSplitEdge (ei0, ei1) {
+ var this$1 = this;
+
+ var npts = ei1.segmentIndex - ei0.segmentIndex + 2;
+ var lastSegStartPt = this.edge.pts[ei1.segmentIndex];
+ var useIntPt1 = ei1.dist > 0.0 || !ei1.coord.equals2D(lastSegStartPt);
+ if (!useIntPt1) {
+ npts--;
+ }
+ var pts = new Array(npts).fill(null);
+ var ipt = 0;
+ pts[ipt++] = new Coordinate(ei0.coord);
+ for (var i = ei0.segmentIndex + 1; i <= ei1.segmentIndex; i++) {
+ pts[ipt++] = this$1.edge.pts[i];
+ }
+ if (useIntPt1) { pts[ipt] = ei1.coord; }
+ return new Edge(pts, new Label(this.edge._label))
+ };
+ EdgeIntersectionList.prototype.add = function add (intPt, segmentIndex, dist) {
+ var eiNew = new EdgeIntersection(intPt, segmentIndex, dist);
+ var ei = this._nodeMap.get(eiNew);
+ if (ei !== null) {
+ return ei
+ }
+ this._nodeMap.put(eiNew, eiNew);
+ return eiNew
+ };
+ EdgeIntersectionList.prototype.isIntersection = function isIntersection (pt) {
+ for (var it = this.iterator(); it.hasNext();) {
+ var ei = it.next();
+ if (ei.coord.equals(pt)) { return true }
+ }
+ return false
+ };
+ EdgeIntersectionList.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ EdgeIntersectionList.prototype.getClass = function getClass () {
+ return EdgeIntersectionList
+ };
+
+ var MonotoneChainIndexer = function MonotoneChainIndexer () {};
+
+ MonotoneChainIndexer.prototype.getChainStartIndices = function getChainStartIndices (pts) {
+ var this$1 = this;
+
+ var start = 0;
+ var startIndexList = new ArrayList();
+ startIndexList.add(new Integer(start));
+ do {
+ var last = this$1.findChainEnd(pts, start);
+ startIndexList.add(new Integer(last));
+ start = last;
+ } while (start < pts.length - 1)
+ var startIndex = MonotoneChainIndexer.toIntArray(startIndexList);
+ return startIndex
+ };
+ MonotoneChainIndexer.prototype.findChainEnd = function findChainEnd (pts, start) {
+ var chainQuad = Quadrant.quadrant(pts[start], pts[start + 1]);
+ var last = start + 1;
+ while (last < pts.length) {
+ var quad = Quadrant.quadrant(pts[last - 1], pts[last]);
+ if (quad !== chainQuad) { break }
+ last++;
+ }
+ return last - 1
+ };
+ MonotoneChainIndexer.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ MonotoneChainIndexer.prototype.getClass = function getClass () {
+ return MonotoneChainIndexer
+ };
+ MonotoneChainIndexer.toIntArray = function toIntArray (list) {
+ var array = new Array(list.size()).fill(null);
+ for (var i = 0; i < array.length; i++) {
+ array[i] = list.get(i).intValue();
+ }
+ return array
+ };
+
+ var MonotoneChainEdge = function MonotoneChainEdge () {
+ this.e = null;
+ this.pts = null;
+ this.startIndex = null;
+ this.env1 = new Envelope();
+ this.env2 = new Envelope();
+ var e = arguments[0];
+ this.e = e;
+ this.pts = e.getCoordinates();
+ var mcb = new MonotoneChainIndexer();
+ this.startIndex = mcb.getChainStartIndices(this.pts);
+ };
+ MonotoneChainEdge.prototype.getCoordinates = function getCoordinates () {
+ return this.pts
+ };
+ MonotoneChainEdge.prototype.getMaxX = function getMaxX (chainIndex) {
+ var x1 = this.pts[this.startIndex[chainIndex]].x;
+ var x2 = this.pts[this.startIndex[chainIndex + 1]].x;
+ return x1 > x2 ? x1 : x2
+ };
+ MonotoneChainEdge.prototype.getMinX = function getMinX (chainIndex) {
+ var x1 = this.pts[this.startIndex[chainIndex]].x;
+ var x2 = this.pts[this.startIndex[chainIndex + 1]].x;
+ return x1 < x2 ? x1 : x2
+ };
+ MonotoneChainEdge.prototype.computeIntersectsForChain = function computeIntersectsForChain () {
+ if (arguments.length === 4) {
+ var chainIndex0 = arguments[0];
+ var mce = arguments[1];
+ var chainIndex1 = arguments[2];
+ var si = arguments[3];
+ this.computeIntersectsForChain(this.startIndex[chainIndex0], this.startIndex[chainIndex0 + 1], mce, mce.startIndex[chainIndex1], mce.startIndex[chainIndex1 + 1], si);
+ } else if (arguments.length === 6) {
+ var start0 = arguments[0];
+ var end0 = arguments[1];
+ var mce$1 = arguments[2];
+ var start1 = arguments[3];
+ var end1 = arguments[4];
+ var ei = arguments[5];
+ var p00 = this.pts[start0];
+ var p01 = this.pts[end0];
+ var p10 = mce$1.pts[start1];
+ var p11 = mce$1.pts[end1];
+ if (end0 - start0 === 1 && end1 - start1 === 1) {
+ ei.addIntersections(this.e, start0, mce$1.e, start1);
+ return null
+ }
+ this.env1.init(p00, p01);
+ this.env2.init(p10, p11);
+ if (!this.env1.intersects(this.env2)) { return null }
+ var mid0 = Math.trunc((start0 + end0) / 2);
+ var mid1 = Math.trunc((start1 + end1) / 2);
+ if (start0 < mid0) {
+ if (start1 < mid1) { this.computeIntersectsForChain(start0, mid0, mce$1, start1, mid1, ei); }
+ if (mid1 < end1) { this.computeIntersectsForChain(start0, mid0, mce$1, mid1, end1, ei); }
+ }
+ if (mid0 < end0) {
+ if (start1 < mid1) { this.computeIntersectsForChain(mid0, end0, mce$1, start1, mid1, ei); }
+ if (mid1 < end1) { this.computeIntersectsForChain(mid0, end0, mce$1, mid1, end1, ei); }
+ }
+ }
+ };
+ MonotoneChainEdge.prototype.getStartIndexes = function getStartIndexes () {
+ return this.startIndex
+ };
+ MonotoneChainEdge.prototype.computeIntersects = function computeIntersects (mce, si) {
+ var this$1 = this;
+
+ for (var i = 0; i < this.startIndex.length - 1; i++) {
+ for (var j = 0; j < mce.startIndex.length - 1; j++) {
+ this$1.computeIntersectsForChain(i, mce, j, si);
+ }
+ }
+ };
+ MonotoneChainEdge.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ MonotoneChainEdge.prototype.getClass = function getClass () {
+ return MonotoneChainEdge
+ };
+
+ var Depth = function Depth () {
+ var this$1 = this;
+
+ this._depth = Array(2).fill().map(function () { return Array(3); });
+ for (var i = 0; i < 2; i++) {
+ for (var j = 0; j < 3; j++) {
+ this$1._depth[i][j] = Depth.NULL_VALUE;
+ }
+ }
+ };
+
+ var staticAccessors$31 = { NULL_VALUE: { configurable: true } };
+ Depth.prototype.getDepth = function getDepth (geomIndex, posIndex) {
+ return this._depth[geomIndex][posIndex]
+ };
+ Depth.prototype.setDepth = function setDepth (geomIndex, posIndex, depthValue) {
+ this._depth[geomIndex][posIndex] = depthValue;
+ };
+ Depth.prototype.isNull = function isNull () {
+ var this$1 = this;
+
+ if (arguments.length === 0) {
+ for (var i = 0; i < 2; i++) {
+ for (var j = 0; j < 3; j++) {
+ if (this$1._depth[i][j] !== Depth.NULL_VALUE) { return false }
+ }
+ }
+ return true
+ } else if (arguments.length === 1) {
+ var geomIndex = arguments[0];
+ return this._depth[geomIndex][1] === Depth.NULL_VALUE
+ } else if (arguments.length === 2) {
+ var geomIndex$1 = arguments[0];
+ var posIndex = arguments[1];
+ return this._depth[geomIndex$1][posIndex] === Depth.NULL_VALUE
+ }
+ };
+ Depth.prototype.normalize = function normalize () {
+ var this$1 = this;
+
+ for (var i = 0; i < 2; i++) {
+ if (!this$1.isNull(i)) {
+ var minDepth = this$1._depth[i][1];
+ if (this$1._depth[i][2] < minDepth) { minDepth = this$1._depth[i][2]; }
+ if (minDepth < 0) { minDepth = 0; }
+ for (var j = 1; j < 3; j++) {
+ var newValue = 0;
+ if (this$1._depth[i][j] > minDepth) { newValue = 1; }
+ this$1._depth[i][j] = newValue;
+ }
+ }
+ }
+ };
+ Depth.prototype.getDelta = function getDelta (geomIndex) {
+ return this._depth[geomIndex][Position.RIGHT] - this._depth[geomIndex][Position.LEFT]
+ };
+ Depth.prototype.getLocation = function getLocation (geomIndex, posIndex) {
+ if (this._depth[geomIndex][posIndex] <= 0) { return Location.EXTERIOR }
+ return Location.INTERIOR
+ };
+ Depth.prototype.toString = function toString () {
+ return 'A: ' + this._depth[0][1] + ',' + this._depth[0][2] + ' B: ' + this._depth[1][1] + ',' + this._depth[1][2]
+ };
+ Depth.prototype.add = function add () {
+ var this$1 = this;
+
+ if (arguments.length === 1) {
+ var lbl = arguments[0];
+ for (var i = 0; i < 2; i++) {
+ for (var j = 1; j < 3; j++) {
+ var loc = lbl.getLocation(i, j);
+ if (loc === Location.EXTERIOR || loc === Location.INTERIOR) {
+ if (this$1.isNull(i, j)) {
+ this$1._depth[i][j] = Depth.depthAtLocation(loc);
+ } else { this$1._depth[i][j] += Depth.depthAtLocation(loc); }
+ }
+ }
+ }
+ } else if (arguments.length === 3) {
+ var geomIndex = arguments[0];
+ var posIndex = arguments[1];
+ var location = arguments[2];
+ if (location === Location.INTERIOR) { this._depth[geomIndex][posIndex]++; }
+ }
+ };
+ Depth.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ Depth.prototype.getClass = function getClass () {
+ return Depth
+ };
+ Depth.depthAtLocation = function depthAtLocation (location) {
+ if (location === Location.EXTERIOR) { return 0 }
+ if (location === Location.INTERIOR) { return 1 }
+ return Depth.NULL_VALUE
+ };
+ staticAccessors$31.NULL_VALUE.get = function () { return -1 };
+
+ Object.defineProperties( Depth, staticAccessors$31 );
+
+ var Edge = (function (GraphComponent$$1) {
+ function Edge () {
+ GraphComponent$$1.call(this);
+ this.pts = null;
+ this._env = null;
+ this.eiList = new EdgeIntersectionList(this);
+ this._name = null;
+ this._mce = null;
+ this._isIsolated = true;
+ this._depth = new Depth();
+ this._depthDelta = 0;
+ if (arguments.length === 1) {
+ var pts = arguments[0];
+ Edge.call(this, pts, null);
+ } else if (arguments.length === 2) {
+ var pts$1 = arguments[0];
+ var label = arguments[1];
+ this.pts = pts$1;
+ this._label = label;
+ }
+ }
+
+ if ( GraphComponent$$1 ) Edge.__proto__ = GraphComponent$$1;
+ Edge.prototype = Object.create( GraphComponent$$1 && GraphComponent$$1.prototype );
+ Edge.prototype.constructor = Edge;
+ Edge.prototype.getDepth = function getDepth () {
+ return this._depth
+ };
+ Edge.prototype.getCollapsedEdge = function getCollapsedEdge () {
+ var newPts = new Array(2).fill(null);
+ newPts[0] = this.pts[0];
+ newPts[1] = this.pts[1];
+ var newe = new Edge(newPts, Label.toLineLabel(this._label));
+ return newe
+ };
+ Edge.prototype.isIsolated = function isIsolated () {
+ return this._isIsolated
+ };
+ Edge.prototype.getCoordinates = function getCoordinates () {
+ return this.pts
+ };
+ Edge.prototype.setIsolated = function setIsolated (isIsolated) {
+ this._isIsolated = isIsolated;
+ };
+ Edge.prototype.setName = function setName (name) {
+ this._name = name;
+ };
+ Edge.prototype.equals = function equals (o) {
+ var this$1 = this;
+
+ if (!(o instanceof Edge)) { return false }
+ var e = o;
+ if (this.pts.length !== e.pts.length) { return false }
+ var isEqualForward = true;
+ var isEqualReverse = true;
+ var iRev = this.pts.length;
+ for (var i = 0; i < this.pts.length; i++) {
+ if (!this$1.pts[i].equals2D(e.pts[i])) {
+ isEqualForward = false;
+ }
+ if (!this$1.pts[i].equals2D(e.pts[--iRev])) {
+ isEqualReverse = false;
+ }
+ if (!isEqualForward && !isEqualReverse) { return false }
+ }
+ return true
+ };
+ Edge.prototype.getCoordinate = function getCoordinate () {
+ if (arguments.length === 0) {
+ if (this.pts.length > 0) { return this.pts[0] }
+ return null
+ } else if (arguments.length === 1) {
+ var i = arguments[0];
+ return this.pts[i]
+ }
+ };
+ Edge.prototype.print = function print (out) {
+ var this$1 = this;
+
+ out.print('edge ' + this._name + ': ');
+ out.print('LINESTRING (');
+ for (var i = 0; i < this.pts.length; i++) {
+ if (i > 0) { out.print(','); }
+ out.print(this$1.pts[i].x + ' ' + this$1.pts[i].y);
+ }
+ out.print(') ' + this._label + ' ' + this._depthDelta);
+ };
+ Edge.prototype.computeIM = function computeIM (im) {
+ Edge.updateIM(this._label, im);
+ };
+ Edge.prototype.isCollapsed = function isCollapsed () {
+ if (!this._label.isArea()) { return false }
+ if (this.pts.length !== 3) { return false }
+ if (this.pts[0].equals(this.pts[2])) { return true }
+ return false
+ };
+ Edge.prototype.isClosed = function isClosed () {
+ return this.pts[0].equals(this.pts[this.pts.length - 1])
+ };
+ Edge.prototype.getMaximumSegmentIndex = function getMaximumSegmentIndex () {
+ return this.pts.length - 1
+ };
+ Edge.prototype.getDepthDelta = function getDepthDelta () {
+ return this._depthDelta
+ };
+ Edge.prototype.getNumPoints = function getNumPoints () {
+ return this.pts.length
+ };
+ Edge.prototype.printReverse = function printReverse (out) {
+ var this$1 = this;
+
+ out.print('edge ' + this._name + ': ');
+ for (var i = this.pts.length - 1; i >= 0; i--) {
+ out.print(this$1.pts[i] + ' ');
+ }
+ out.println('');
+ };
+ Edge.prototype.getMonotoneChainEdge = function getMonotoneChainEdge () {
+ if (this._mce === null) { this._mce = new MonotoneChainEdge(this); }
+ return this._mce
+ };
+ Edge.prototype.getEnvelope = function getEnvelope () {
+ var this$1 = this;
+
+ if (this._env === null) {
+ this._env = new Envelope();
+ for (var i = 0; i < this.pts.length; i++) {
+ this$1._env.expandToInclude(this$1.pts[i]);
+ }
+ }
+ return this._env
+ };
+ Edge.prototype.addIntersection = function addIntersection (li, segmentIndex, geomIndex, intIndex) {
+ var intPt = new Coordinate(li.getIntersection(intIndex));
+ var normalizedSegmentIndex = segmentIndex;
+ var dist = li.getEdgeDistance(geomIndex, intIndex);
+ var nextSegIndex = normalizedSegmentIndex + 1;
+ if (nextSegIndex < this.pts.length) {
+ var nextPt = this.pts[nextSegIndex];
+ if (intPt.equals2D(nextPt)) {
+ normalizedSegmentIndex = nextSegIndex;
+ dist = 0.0;
+ }
+ }
+ this.eiList.add(intPt, normalizedSegmentIndex, dist);
+ };
+ Edge.prototype.toString = function toString () {
+ var this$1 = this;
+
+ var buf = new StringBuffer();
+ buf.append('edge ' + this._name + ': ');
+ buf.append('LINESTRING (');
+ for (var i = 0; i < this.pts.length; i++) {
+ if (i > 0) { buf.append(','); }
+ buf.append(this$1.pts[i].x + ' ' + this$1.pts[i].y);
+ }
+ buf.append(') ' + this._label + ' ' + this._depthDelta);
+ return buf.toString()
+ };
+ Edge.prototype.isPointwiseEqual = function isPointwiseEqual (e) {
+ var this$1 = this;
+
+ if (this.pts.length !== e.pts.length) { return false }
+ for (var i = 0; i < this.pts.length; i++) {
+ if (!this$1.pts[i].equals2D(e.pts[i])) {
+ return false
+ }
+ }
+ return true
+ };
+ Edge.prototype.setDepthDelta = function setDepthDelta (depthDelta) {
+ this._depthDelta = depthDelta;
+ };
+ Edge.prototype.getEdgeIntersectionList = function getEdgeIntersectionList () {
+ return this.eiList
+ };
+ Edge.prototype.addIntersections = function addIntersections (li, segmentIndex, geomIndex) {
+ var this$1 = this;
+
+ for (var i = 0; i < li.getIntersectionNum(); i++) {
+ this$1.addIntersection(li, segmentIndex, geomIndex, i);
+ }
+ };
+ Edge.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ Edge.prototype.getClass = function getClass () {
+ return Edge
+ };
+ Edge.updateIM = function updateIM () {
+ if (arguments.length === 2) {
+ var label = arguments[0];
+ var im = arguments[1];
+ im.setAtLeastIfValid(label.getLocation(0, Position.ON), label.getLocation(1, Position.ON), 1);
+ if (label.isArea()) {
+ im.setAtLeastIfValid(label.getLocation(0, Position.LEFT), label.getLocation(1, Position.LEFT), 2);
+ im.setAtLeastIfValid(label.getLocation(0, Position.RIGHT), label.getLocation(1, Position.RIGHT), 2);
+ }
+ } else { return GraphComponent$$1.prototype.updateIM.apply(this, arguments) }
+ };
+
+ return Edge;
+ }(GraphComponent));
+
+ var BufferBuilder = function BufferBuilder (bufParams) {
+ this._workingPrecisionModel = null;
+ this._workingNoder = null;
+ this._geomFact = null;
+ this._graph = null;
+ this._edgeList = new EdgeList();
+ this._bufParams = bufParams || null;
+ };
+ BufferBuilder.prototype.setWorkingPrecisionModel = function setWorkingPrecisionModel (pm) {
+ this._workingPrecisionModel = pm;
+ };
+ BufferBuilder.prototype.insertUniqueEdge = function insertUniqueEdge (e) {
+ var existingEdge = this._edgeList.findEqualEdge(e);
+ if (existingEdge !== null) {
+ var existingLabel = existingEdge.getLabel();
+ var labelToMerge = e.getLabel();
+ if (!existingEdge.isPointwiseEqual(e)) {
+ labelToMerge = new Label(e.getLabel());
+ labelToMerge.flip();
+ }
+ existingLabel.merge(labelToMerge);
+ var mergeDelta = BufferBuilder.depthDelta(labelToMerge);
+ var existingDelta = existingEdge.getDepthDelta();
+ var newDelta = existingDelta + mergeDelta;
+ existingEdge.setDepthDelta(newDelta);
+ } else {
+ this._edgeList.add(e);
+ e.setDepthDelta(BufferBuilder.depthDelta(e.getLabel()));
+ }
+ };
+ BufferBuilder.prototype.buildSubgraphs = function buildSubgraphs (subgraphList, polyBuilder) {
+ var processedGraphs = new ArrayList();
+ for (var i = subgraphList.iterator(); i.hasNext();) {
+ var subgraph = i.next();
+ var p = subgraph.getRightmostCoordinate();
+ var locater = new SubgraphDepthLocater(processedGraphs);
+ var outsideDepth = locater.getDepth(p);
+ subgraph.computeDepth(outsideDepth);
+ subgraph.findResultEdges();
+ processedGraphs.add(subgraph);
+ polyBuilder.add(subgraph.getDirectedEdges(), subgraph.getNodes());
+ }
+ };
+ BufferBuilder.prototype.createSubgraphs = function createSubgraphs (graph) {
+ var subgraphList = new ArrayList();
+ for (var i = graph.getNodes().iterator(); i.hasNext();) {
+ var node = i.next();
+ if (!node.isVisited()) {
+ var subgraph = new BufferSubgraph();
+ subgraph.create(node);
+ subgraphList.add(subgraph);
+ }
+ }
+ Collections.sort(subgraphList, Collections.reverseOrder());
+ return subgraphList
+ };
+ BufferBuilder.prototype.createEmptyResultGeometry = function createEmptyResultGeometry () {
+ var emptyGeom = this._geomFact.createPolygon();
+ return emptyGeom
+ };
+ BufferBuilder.prototype.getNoder = function getNoder (precisionModel) {
+ if (this._workingNoder !== null) { return this._workingNoder }
+ var noder = new MCIndexNoder();
+ var li = new RobustLineIntersector();
+ li.setPrecisionModel(precisionModel);
+ noder.setSegmentIntersector(new IntersectionAdder(li));
+ return noder
+ };
+ BufferBuilder.prototype.buffer = function buffer (g, distance) {
+ var precisionModel = this._workingPrecisionModel;
+ if (precisionModel === null) { precisionModel = g.getPrecisionModel(); }
+ this._geomFact = g.getFactory();
+ var curveBuilder = new OffsetCurveBuilder(precisionModel, this._bufParams);
+ var curveSetBuilder = new OffsetCurveSetBuilder(g, distance, curveBuilder);
+ var bufferSegStrList = curveSetBuilder.getCurves();
+ if (bufferSegStrList.size() <= 0) {
+ return this.createEmptyResultGeometry()
+ }
+ this.computeNodedEdges(bufferSegStrList, precisionModel);
+ this._graph = new PlanarGraph(new OverlayNodeFactory());
+ this._graph.addEdges(this._edgeList.getEdges());
+ var subgraphList = this.createSubgraphs(this._graph);
+ var polyBuilder = new PolygonBuilder(this._geomFact);
+ this.buildSubgraphs(subgraphList, polyBuilder);
+ var resultPolyList = polyBuilder.getPolygons();
+ if (resultPolyList.size() <= 0) {
+ return this.createEmptyResultGeometry()
+ }
+ var resultGeom = this._geomFact.buildGeometry(resultPolyList);
+ return resultGeom
+ };
+ BufferBuilder.prototype.computeNodedEdges = function computeNodedEdges (bufferSegStrList, precisionModel) {
+ var this$1 = this;
+
+ var noder = this.getNoder(precisionModel);
+ noder.computeNodes(bufferSegStrList);
+ var nodedSegStrings = noder.getNodedSubstrings();
+ for (var i = nodedSegStrings.iterator(); i.hasNext();) {
+ var segStr = i.next();
+ var pts = segStr.getCoordinates();
+ if (pts.length === 2 && pts[0].equals2D(pts[1])) { continue }
+ var oldLabel = segStr.getData();
+ var edge = new Edge(segStr.getCoordinates(), new Label(oldLabel));
+ this$1.insertUniqueEdge(edge);
+ }
+ };
+ BufferBuilder.prototype.setNoder = function setNoder (noder) {
+ this._workingNoder = noder;
+ };
+ BufferBuilder.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ BufferBuilder.prototype.getClass = function getClass () {
+ return BufferBuilder
+ };
+ BufferBuilder.depthDelta = function depthDelta (label) {
+ var lLoc = label.getLocation(0, Position.LEFT);
+ var rLoc = label.getLocation(0, Position.RIGHT);
+ if (lLoc === Location.INTERIOR && rLoc === Location.EXTERIOR) { return 1; } else if (lLoc === Location.EXTERIOR && rLoc === Location.INTERIOR) { return -1 }
+ return 0
+ };
+ BufferBuilder.convertSegStrings = function convertSegStrings (it) {
+ var fact = new GeometryFactory();
+ var lines = new ArrayList();
+ while (it.hasNext()) {
+ var ss = it.next();
+ var line = fact.createLineString(ss.getCoordinates());
+ lines.add(line);
+ }
+ return fact.buildGeometry(lines)
+ };
+
+ var ScaledNoder = function ScaledNoder () {
+ this._noder = null;
+ this._scaleFactor = null;
+ this._offsetX = null;
+ this._offsetY = null;
+ this._isScaled = false;
+ if (arguments.length === 2) {
+ var noder = arguments[0];
+ var scaleFactor = arguments[1];
+ this._noder = noder;
+ this._scaleFactor = scaleFactor;
+ this._offsetX = 0.0;
+ this._offsetY = 0.0;
+ this._isScaled = !this.isIntegerPrecision();
+ } else if (arguments.length === 4) {
+ var noder$1 = arguments[0];
+ var scaleFactor$1 = arguments[1];
+ var offsetX = arguments[2];
+ var offsetY = arguments[3];
+ this._noder = noder$1;
+ this._scaleFactor = scaleFactor$1;
+ this._offsetX = offsetX;
+ this._offsetY = offsetY;
+ this._isScaled = !this.isIntegerPrecision();
+ }
+ };
+ ScaledNoder.prototype.rescale = function rescale () {
+ var this$1 = this;
+
+ if (hasInterface(arguments[0], Collection)) {
+ var segStrings = arguments[0];
+ for (var i = segStrings.iterator(); i.hasNext();) {
+ var ss = i.next();
+ this$1.rescale(ss.getCoordinates());
+ }
+ } else if (arguments[0] instanceof Array) {
+ var pts = arguments[0];
+ // let p0 = null
+ // let p1 = null
+ // if (pts.length === 2) {
+ // p0 = new Coordinate(pts[0])
+ // p1 = new Coordinate(pts[1])
+ // }
+ for (var i$1 = 0; i$1 < pts.length; i$1++) {
+ pts[i$1].x = pts[i$1].x / this$1._scaleFactor + this$1._offsetX;
+ pts[i$1].y = pts[i$1].y / this$1._scaleFactor + this$1._offsetY;
+ }
+ if (pts.length === 2 && pts[0].equals2D(pts[1])) {
+ System.out.println(pts);
+ }
+ }
+ };
+ ScaledNoder.prototype.scale = function scale () {
+ var this$1 = this;
+
+ if (hasInterface(arguments[0], Collection)) {
+ var segStrings = arguments[0];
+ var nodedSegmentStrings = new ArrayList();
+ for (var i = segStrings.iterator(); i.hasNext();) {
+ var ss = i.next();
+ nodedSegmentStrings.add(new NodedSegmentString(this$1.scale(ss.getCoordinates()), ss.getData()));
+ }
+ return nodedSegmentStrings
+ } else if (arguments[0] instanceof Array) {
+ var pts = arguments[0];
+ var roundPts = new Array(pts.length).fill(null);
+ for (var i$1 = 0; i$1 < pts.length; i$1++) {
+ roundPts[i$1] = new Coordinate(Math.round((pts[i$1].x - this$1._offsetX) * this$1._scaleFactor), Math.round((pts[i$1].y - this$1._offsetY) * this$1._scaleFactor), pts[i$1].z);
+ }
+ var roundPtsNoDup = CoordinateArrays.removeRepeatedPoints(roundPts);
+ return roundPtsNoDup
+ }
+ };
+ ScaledNoder.prototype.isIntegerPrecision = function isIntegerPrecision () {
+ return this._scaleFactor === 1.0
+ };
+ ScaledNoder.prototype.getNodedSubstrings = function getNodedSubstrings () {
+ var splitSS = this._noder.getNodedSubstrings();
+ if (this._isScaled) { this.rescale(splitSS); }
+ return splitSS
+ };
+ ScaledNoder.prototype.computeNodes = function computeNodes (inputSegStrings) {
+ var intSegStrings = inputSegStrings;
+ if (this._isScaled) { intSegStrings = this.scale(inputSegStrings); }
+ this._noder.computeNodes(intSegStrings);
+ };
+ ScaledNoder.prototype.interfaces_ = function interfaces_ () {
+ return [Noder]
+ };
+ ScaledNoder.prototype.getClass = function getClass () {
+ return ScaledNoder
+ };
+
+ var NodingValidator = function NodingValidator () {
+ this._li = new RobustLineIntersector();
+ this._segStrings = null;
+ var segStrings = arguments[0];
+ this._segStrings = segStrings;
+ };
+
+ var staticAccessors$33 = { fact: { configurable: true } };
+ NodingValidator.prototype.checkEndPtVertexIntersections = function checkEndPtVertexIntersections () {
+ var this$1 = this;
+
+ if (arguments.length === 0) {
+ for (var i = this._segStrings.iterator(); i.hasNext();) {
+ var ss = i.next();
+ var pts = ss.getCoordinates();
+ this$1.checkEndPtVertexIntersections(pts[0], this$1._segStrings);
+ this$1.checkEndPtVertexIntersections(pts[pts.length - 1], this$1._segStrings);
+ }
+ } else if (arguments.length === 2) {
+ var testPt = arguments[0];
+ var segStrings = arguments[1];
+ for (var i$1 = segStrings.iterator(); i$1.hasNext();) {
+ var ss$1 = i$1.next();
+ var pts$1 = ss$1.getCoordinates();
+ for (var j = 1; j < pts$1.length - 1; j++) {
+ if (pts$1[j].equals(testPt)) { throw new RuntimeException('found endpt/interior pt intersection at index ' + j + ' :pt ' + testPt) }
+ }
+ }
+ }
+ };
+ NodingValidator.prototype.checkInteriorIntersections = function checkInteriorIntersections () {
+ var this$1 = this;
+
+ if (arguments.length === 0) {
+ for (var i = this._segStrings.iterator(); i.hasNext();) {
+ var ss0 = i.next();
+ for (var j = this._segStrings.iterator(); j.hasNext();) {
+ var ss1 = j.next();
+ this$1.checkInteriorIntersections(ss0, ss1);
+ }
+ }
+ } else if (arguments.length === 2) {
+ var ss0$1 = arguments[0];
+ var ss1$1 = arguments[1];
+ var pts0 = ss0$1.getCoordinates();
+ var pts1 = ss1$1.getCoordinates();
+ for (var i0 = 0; i0 < pts0.length - 1; i0++) {
+ for (var i1 = 0; i1 < pts1.length - 1; i1++) {
+ this$1.checkInteriorIntersections(ss0$1, i0, ss1$1, i1);
+ }
+ }
+ } else if (arguments.length === 4) {
+ var e0 = arguments[0];
+ var segIndex0 = arguments[1];
+ var e1 = arguments[2];
+ var segIndex1 = arguments[3];
+ if (e0 === e1 && segIndex0 === segIndex1) { return null }
+ var p00 = e0.getCoordinates()[segIndex0];
+ var p01 = e0.getCoordinates()[segIndex0 + 1];
+ var p10 = e1.getCoordinates()[segIndex1];
+ var p11 = e1.getCoordinates()[segIndex1 + 1];
+ this._li.computeIntersection(p00, p01, p10, p11);
+ if (this._li.hasIntersection()) {
+ if (this._li.isProper() || this.hasInteriorIntersection(this._li, p00, p01) || this.hasInteriorIntersection(this._li, p10, p11)) {
+ throw new RuntimeException('found non-noded intersection at ' + p00 + '-' + p01 + ' and ' + p10 + '-' + p11)
+ }
+ }
+ }
+ };
+ NodingValidator.prototype.checkValid = function checkValid () {
+ this.checkEndPtVertexIntersections();
+ this.checkInteriorIntersections();
+ this.checkCollapses();
+ };
+ NodingValidator.prototype.checkCollapses = function checkCollapses () {
+ var this$1 = this;
+
+ if (arguments.length === 0) {
+ for (var i = this._segStrings.iterator(); i.hasNext();) {
+ var ss = i.next();
+ this$1.checkCollapses(ss);
+ }
+ } else if (arguments.length === 1) {
+ var ss$1 = arguments[0];
+ var pts = ss$1.getCoordinates();
+ for (var i$1 = 0; i$1 < pts.length - 2; i$1++) {
+ this$1.checkCollapse(pts[i$1], pts[i$1 + 1], pts[i$1 + 2]);
+ }
+ }
+ };
+ NodingValidator.prototype.hasInteriorIntersection = function hasInteriorIntersection (li, p0, p1) {
+ for (var i = 0; i < li.getIntersectionNum(); i++) {
+ var intPt = li.getIntersection(i);
+ if (!(intPt.equals(p0) || intPt.equals(p1))) { return true }
+ }
+ return false
+ };
+ NodingValidator.prototype.checkCollapse = function checkCollapse (p0, p1, p2) {
+ if (p0.equals(p2)) { throw new RuntimeException('found non-noded collapse at ' + NodingValidator.fact.createLineString([p0, p1, p2])) }
+ };
+ NodingValidator.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ NodingValidator.prototype.getClass = function getClass () {
+ return NodingValidator
+ };
+ staticAccessors$33.fact.get = function () { return new GeometryFactory() };
+
+ Object.defineProperties( NodingValidator, staticAccessors$33 );
+
+ var HotPixel = function HotPixel () {
+ this._li = null;
+ this._pt = null;
+ this._originalPt = null;
+ this._ptScaled = null;
+ this._p0Scaled = null;
+ this._p1Scaled = null;
+ this._scaleFactor = null;
+ this._minx = null;
+ this._maxx = null;
+ this._miny = null;
+ this._maxy = null;
+ this._corner = new Array(4).fill(null);
+ this._safeEnv = null;
+ var pt = arguments[0];
+ var scaleFactor = arguments[1];
+ var li = arguments[2];
+ this._originalPt = pt;
+ this._pt = pt;
+ this._scaleFactor = scaleFactor;
+ this._li = li;
+ if (scaleFactor <= 0) { throw new IllegalArgumentException('Scale factor must be non-zero') }
+ if (scaleFactor !== 1.0) {
+ this._pt = new Coordinate(this.scale(pt.x), this.scale(pt.y));
+ this._p0Scaled = new Coordinate();
+ this._p1Scaled = new Coordinate();
+ }
+ this.initCorners(this._pt);
+ };
+
+ var staticAccessors$34 = { SAFE_ENV_EXPANSION_FACTOR: { configurable: true } };
+ HotPixel.prototype.intersectsScaled = function intersectsScaled (p0, p1) {
+ var segMinx = Math.min(p0.x, p1.x);
+ var segMaxx = Math.max(p0.x, p1.x);
+ var segMiny = Math.min(p0.y, p1.y);
+ var segMaxy = Math.max(p0.y, p1.y);
+ var isOutsidePixelEnv = this._maxx < segMinx || this._minx > segMaxx || this._maxy < segMiny || this._miny > segMaxy;
+ if (isOutsidePixelEnv) { return false }
+ var intersects = this.intersectsToleranceSquare(p0, p1);
+ Assert.isTrue(!(isOutsidePixelEnv && intersects), 'Found bad envelope test');
+ return intersects
+ };
+ HotPixel.prototype.initCorners = function initCorners (pt) {
+ var tolerance = 0.5;
+ this._minx = pt.x - tolerance;
+ this._maxx = pt.x + tolerance;
+ this._miny = pt.y - tolerance;
+ this._maxy = pt.y + tolerance;
+ this._corner[0] = new Coordinate(this._maxx, this._maxy);
+ this._corner[1] = new Coordinate(this._minx, this._maxy);
+ this._corner[2] = new Coordinate(this._minx, this._miny);
+ this._corner[3] = new Coordinate(this._maxx, this._miny);
+ };
+ HotPixel.prototype.intersects = function intersects (p0, p1) {
+ if (this._scaleFactor === 1.0) { return this.intersectsScaled(p0, p1) }
+ this.copyScaled(p0, this._p0Scaled);
+ this.copyScaled(p1, this._p1Scaled);
+ return this.intersectsScaled(this._p0Scaled, this._p1Scaled)
+ };
+ HotPixel.prototype.scale = function scale (val) {
+ return Math.round(val * this._scaleFactor)
+ };
+ HotPixel.prototype.getCoordinate = function getCoordinate () {
+ return this._originalPt
+ };
+ HotPixel.prototype.copyScaled = function copyScaled (p, pScaled) {
+ pScaled.x = this.scale(p.x);
+ pScaled.y = this.scale(p.y);
+ };
+ HotPixel.prototype.getSafeEnvelope = function getSafeEnvelope () {
+ if (this._safeEnv === null) {
+ var safeTolerance = HotPixel.SAFE_ENV_EXPANSION_FACTOR / this._scaleFactor;
+ this._safeEnv = new Envelope(this._originalPt.x - safeTolerance, this._originalPt.x + safeTolerance, this._originalPt.y - safeTolerance, this._originalPt.y + safeTolerance);
+ }
+ return this._safeEnv
+ };
+ HotPixel.prototype.intersectsPixelClosure = function intersectsPixelClosure (p0, p1) {
+ this._li.computeIntersection(p0, p1, this._corner[0], this._corner[1]);
+ if (this._li.hasIntersection()) { return true }
+ this._li.computeIntersection(p0, p1, this._corner[1], this._corner[2]);
+ if (this._li.hasIntersection()) { return true }
+ this._li.computeIntersection(p0, p1, this._corner[2], this._corner[3]);
+ if (this._li.hasIntersection()) { return true }
+ this._li.computeIntersection(p0, p1, this._corner[3], this._corner[0]);
+ if (this._li.hasIntersection()) { return true }
+ return false
+ };
+ HotPixel.prototype.intersectsToleranceSquare = function intersectsToleranceSquare (p0, p1) {
+ var intersectsLeft = false;
+ var intersectsBottom = false;
+ this._li.computeIntersection(p0, p1, this._corner[0], this._corner[1]);
+ if (this._li.isProper()) { return true }
+ this._li.computeIntersection(p0, p1, this._corner[1], this._corner[2]);
+ if (this._li.isProper()) { return true }
+ if (this._li.hasIntersection()) { intersectsLeft = true; }
+ this._li.computeIntersection(p0, p1, this._corner[2], this._corner[3]);
+ if (this._li.isProper()) { return true }
+ if (this._li.hasIntersection()) { intersectsBottom = true; }
+ this._li.computeIntersection(p0, p1, this._corner[3], this._corner[0]);
+ if (this._li.isProper()) { return true }
+ if (intersectsLeft && intersectsBottom) { return true }
+ if (p0.equals(this._pt)) { return true }
+ if (p1.equals(this._pt)) { return true }
+ return false
+ };
+ HotPixel.prototype.addSnappedNode = function addSnappedNode (segStr, segIndex) {
+ var p0 = segStr.getCoordinate(segIndex);
+ var p1 = segStr.getCoordinate(segIndex + 1);
+ if (this.intersects(p0, p1)) {
+ segStr.addIntersection(this.getCoordinate(), segIndex);
+ return true
+ }
+ return false
+ };
+ HotPixel.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ HotPixel.prototype.getClass = function getClass () {
+ return HotPixel
+ };
+ staticAccessors$34.SAFE_ENV_EXPANSION_FACTOR.get = function () { return 0.75 };
+
+ Object.defineProperties( HotPixel, staticAccessors$34 );
+
+ var MonotoneChainSelectAction = function MonotoneChainSelectAction () {
+ this.tempEnv1 = new Envelope();
+ this.selectedSegment = new LineSegment();
+ };
+ MonotoneChainSelectAction.prototype.select = function select () {
+ if (arguments.length === 1) ; else if (arguments.length === 2) {
+ var mc = arguments[0];
+ var startIndex = arguments[1];
+ mc.getLineSegment(startIndex, this.selectedSegment);
+ this.select(this.selectedSegment);
+ }
+ };
+ MonotoneChainSelectAction.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ MonotoneChainSelectAction.prototype.getClass = function getClass () {
+ return MonotoneChainSelectAction
+ };
+
+ var MCIndexPointSnapper = function MCIndexPointSnapper () {
+ this._index = null;
+ var index = arguments[0];
+ this._index = index;
+ };
+
+ var staticAccessors$35 = { HotPixelSnapAction: { configurable: true } };
+ MCIndexPointSnapper.prototype.snap = function snap () {
+ if (arguments.length === 1) {
+ var hotPixel = arguments[0];
+ return this.snap(hotPixel, null, -1)
+ } else if (arguments.length === 3) {
+ var hotPixel$1 = arguments[0];
+ var parentEdge = arguments[1];
+ var hotPixelVertexIndex = arguments[2];
+ var pixelEnv = hotPixel$1.getSafeEnvelope();
+ var hotPixelSnapAction = new HotPixelSnapAction(hotPixel$1, parentEdge, hotPixelVertexIndex);
+ this._index.query(pixelEnv, {
+ interfaces_: function () {
+ return [ItemVisitor]
+ },
+ visitItem: function (item) {
+ var testChain = item;
+ testChain.select(pixelEnv, hotPixelSnapAction);
+ }
+ });
+ return hotPixelSnapAction.isNodeAdded()
+ }
+ };
+ MCIndexPointSnapper.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ MCIndexPointSnapper.prototype.getClass = function getClass () {
+ return MCIndexPointSnapper
+ };
+ staticAccessors$35.HotPixelSnapAction.get = function () { return HotPixelSnapAction };
+
+ Object.defineProperties( MCIndexPointSnapper, staticAccessors$35 );
+
+ var HotPixelSnapAction = (function (MonotoneChainSelectAction$$1) {
+ function HotPixelSnapAction () {
+ MonotoneChainSelectAction$$1.call(this);
+ this._hotPixel = null;
+ this._parentEdge = null;
+ this._hotPixelVertexIndex = null;
+ this._isNodeAdded = false;
+ var hotPixel = arguments[0];
+ var parentEdge = arguments[1];
+ var hotPixelVertexIndex = arguments[2];
+ this._hotPixel = hotPixel;
+ this._parentEdge = parentEdge;
+ this._hotPixelVertexIndex = hotPixelVertexIndex;
+ }
+
+ if ( MonotoneChainSelectAction$$1 ) HotPixelSnapAction.__proto__ = MonotoneChainSelectAction$$1;
+ HotPixelSnapAction.prototype = Object.create( MonotoneChainSelectAction$$1 && MonotoneChainSelectAction$$1.prototype );
+ HotPixelSnapAction.prototype.constructor = HotPixelSnapAction;
+ HotPixelSnapAction.prototype.isNodeAdded = function isNodeAdded () {
+ return this._isNodeAdded
+ };
+ HotPixelSnapAction.prototype.select = function select () {
+ if (arguments.length === 2) {
+ var mc = arguments[0];
+ var startIndex = arguments[1];
+ var ss = mc.getContext();
+ if (this._parentEdge !== null) {
+ if (ss === this._parentEdge && startIndex === this._hotPixelVertexIndex) { return null }
+ }
+ this._isNodeAdded = this._hotPixel.addSnappedNode(ss, startIndex);
+ } else { return MonotoneChainSelectAction$$1.prototype.select.apply(this, arguments) }
+ };
+ HotPixelSnapAction.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ HotPixelSnapAction.prototype.getClass = function getClass () {
+ return HotPixelSnapAction
+ };
+
+ return HotPixelSnapAction;
+ }(MonotoneChainSelectAction));
+
+ var InteriorIntersectionFinderAdder = function InteriorIntersectionFinderAdder () {
+ this._li = null;
+ this._interiorIntersections = null;
+ var li = arguments[0];
+ this._li = li;
+ this._interiorIntersections = new ArrayList();
+ };
+ InteriorIntersectionFinderAdder.prototype.processIntersections = function processIntersections (e0, segIndex0, e1, segIndex1) {
+ var this$1 = this;
+
+ if (e0 === e1 && segIndex0 === segIndex1) { return null }
+ var p00 = e0.getCoordinates()[segIndex0];
+ var p01 = e0.getCoordinates()[segIndex0 + 1];
+ var p10 = e1.getCoordinates()[segIndex1];
+ var p11 = e1.getCoordinates()[segIndex1 + 1];
+ this._li.computeIntersection(p00, p01, p10, p11);
+ if (this._li.hasIntersection()) {
+ if (this._li.isInteriorIntersection()) {
+ for (var intIndex = 0; intIndex < this._li.getIntersectionNum(); intIndex++) {
+ this$1._interiorIntersections.add(this$1._li.getIntersection(intIndex));
+ }
+ e0.addIntersections(this._li, segIndex0, 0);
+ e1.addIntersections(this._li, segIndex1, 1);
+ }
+ }
+ };
+ InteriorIntersectionFinderAdder.prototype.isDone = function isDone () {
+ return false
+ };
+ InteriorIntersectionFinderAdder.prototype.getInteriorIntersections = function getInteriorIntersections () {
+ return this._interiorIntersections
+ };
+ InteriorIntersectionFinderAdder.prototype.interfaces_ = function interfaces_ () {
+ return [SegmentIntersector]
+ };
+ InteriorIntersectionFinderAdder.prototype.getClass = function getClass () {
+ return InteriorIntersectionFinderAdder
+ };
+
+ var MCIndexSnapRounder = function MCIndexSnapRounder () {
+ this._pm = null;
+ this._li = null;
+ this._scaleFactor = null;
+ this._noder = null;
+ this._pointSnapper = null;
+ this._nodedSegStrings = null;
+ var pm = arguments[0];
+ this._pm = pm;
+ this._li = new RobustLineIntersector();
+ this._li.setPrecisionModel(pm);
+ this._scaleFactor = pm.getScale();
+ };
+ MCIndexSnapRounder.prototype.checkCorrectness = function checkCorrectness (inputSegmentStrings) {
+ var resultSegStrings = NodedSegmentString.getNodedSubstrings(inputSegmentStrings);
+ var nv = new NodingValidator(resultSegStrings);
+ try {
+ nv.checkValid();
+ } catch (ex) {
+ if (ex instanceof Exception) {
+ ex.printStackTrace();
+ } else { throw ex }
+ } finally {}
+ };
+ MCIndexSnapRounder.prototype.getNodedSubstrings = function getNodedSubstrings () {
+ return NodedSegmentString.getNodedSubstrings(this._nodedSegStrings)
+ };
+ MCIndexSnapRounder.prototype.snapRound = function snapRound (segStrings, li) {
+ var intersections = this.findInteriorIntersections(segStrings, li);
+ this.computeIntersectionSnaps(intersections);
+ this.computeVertexSnaps(segStrings);
+ };
+ MCIndexSnapRounder.prototype.findInteriorIntersections = function findInteriorIntersections (segStrings, li) {
+ var intFinderAdder = new InteriorIntersectionFinderAdder(li);
+ this._noder.setSegmentIntersector(intFinderAdder);
+ this._noder.computeNodes(segStrings);
+ return intFinderAdder.getInteriorIntersections()
+ };
+ MCIndexSnapRounder.prototype.computeVertexSnaps = function computeVertexSnaps () {
+ var this$1 = this;
+
+ if (hasInterface(arguments[0], Collection)) {
+ var edges = arguments[0];
+ for (var i0 = edges.iterator(); i0.hasNext();) {
+ var edge0 = i0.next();
+ this$1.computeVertexSnaps(edge0);
+ }
+ } else if (arguments[0] instanceof NodedSegmentString) {
+ var e = arguments[0];
+ var pts0 = e.getCoordinates();
+ for (var i = 0; i < pts0.length; i++) {
+ var hotPixel = new HotPixel(pts0[i], this$1._scaleFactor, this$1._li);
+ var isNodeAdded = this$1._pointSnapper.snap(hotPixel, e, i);
+ if (isNodeAdded) {
+ e.addIntersection(pts0[i], i);
+ }
+ }
+ }
+ };
+ MCIndexSnapRounder.prototype.computeNodes = function computeNodes (inputSegmentStrings) {
+ this._nodedSegStrings = inputSegmentStrings;
+ this._noder = new MCIndexNoder();
+ this._pointSnapper = new MCIndexPointSnapper(this._noder.getIndex());
+ this.snapRound(inputSegmentStrings, this._li);
+ };
+ MCIndexSnapRounder.prototype.computeIntersectionSnaps = function computeIntersectionSnaps (snapPts) {
+ var this$1 = this;
+
+ for (var it = snapPts.iterator(); it.hasNext();) {
+ var snapPt = it.next();
+ var hotPixel = new HotPixel(snapPt, this$1._scaleFactor, this$1._li);
+ this$1._pointSnapper.snap(hotPixel);
+ }
+ };
+ MCIndexSnapRounder.prototype.interfaces_ = function interfaces_ () {
+ return [Noder]
+ };
+ MCIndexSnapRounder.prototype.getClass = function getClass () {
+ return MCIndexSnapRounder
+ };
+
+ var BufferOp = function BufferOp () {
+ this._argGeom = null;
+ this._distance = null;
+ this._bufParams = new BufferParameters();
+ this._resultGeometry = null;
+ this._saveException = null;
+ if (arguments.length === 1) {
+ var g = arguments[0];
+ this._argGeom = g;
+ } else if (arguments.length === 2) {
+ var g$1 = arguments[0];
+ var bufParams = arguments[1];
+ this._argGeom = g$1;
+ this._bufParams = bufParams;
+ }
+ };
+
+ var staticAccessors$32 = { CAP_ROUND: { configurable: true },CAP_BUTT: { configurable: true },CAP_FLAT: { configurable: true },CAP_SQUARE: { configurable: true },MAX_PRECISION_DIGITS: { configurable: true } };
+ BufferOp.prototype.bufferFixedPrecision = function bufferFixedPrecision (fixedPM) {
+ var noder = new ScaledNoder(new MCIndexSnapRounder(new PrecisionModel(1.0)), fixedPM.getScale());
+ var bufBuilder = new BufferBuilder(this._bufParams);
+ bufBuilder.setWorkingPrecisionModel(fixedPM);
+ bufBuilder.setNoder(noder);
+ this._resultGeometry = bufBuilder.buffer(this._argGeom, this._distance);
+ };
+ BufferOp.prototype.bufferReducedPrecision = function bufferReducedPrecision () {
+ var this$1 = this;
+
+ if (arguments.length === 0) {
+ for (var precDigits = BufferOp.MAX_PRECISION_DIGITS; precDigits >= 0; precDigits--) {
+ try {
+ this$1.bufferReducedPrecision(precDigits);
+ } catch (ex) {
+ if (ex instanceof TopologyException) {
+ this$1._saveException = ex;
+ } else { throw ex }
+ } finally {}
+ if (this$1._resultGeometry !== null) { return null }
+ }
+ throw this._saveException
+ } else if (arguments.length === 1) {
+ var precisionDigits = arguments[0];
+ var sizeBasedScaleFactor = BufferOp.precisionScaleFactor(this._argGeom, this._distance, precisionDigits);
+ var fixedPM = new PrecisionModel(sizeBasedScaleFactor);
+ this.bufferFixedPrecision(fixedPM);
+ }
+ };
+ BufferOp.prototype.computeGeometry = function computeGeometry () {
+ this.bufferOriginalPrecision();
+ if (this._resultGeometry !== null) { return null }
+ var argPM = this._argGeom.getFactory().getPrecisionModel();
+ if (argPM.getType() === PrecisionModel.FIXED) { this.bufferFixedPrecision(argPM); } else { this.bufferReducedPrecision(); }
+ };
+ BufferOp.prototype.setQuadrantSegments = function setQuadrantSegments (quadrantSegments) {
+ this._bufParams.setQuadrantSegments(quadrantSegments);
+ };
+ BufferOp.prototype.bufferOriginalPrecision = function bufferOriginalPrecision () {
+ try {
+ var bufBuilder = new BufferBuilder(this._bufParams);
+ this._resultGeometry = bufBuilder.buffer(this._argGeom, this._distance);
+ } catch (ex) {
+ if (ex instanceof RuntimeException) {
+ this._saveException = ex;
+ } else { throw ex }
+ } finally {}
+ };
+ BufferOp.prototype.getResultGeometry = function getResultGeometry (distance) {
+ this._distance = distance;
+ this.computeGeometry();
+ return this._resultGeometry
+ };
+ BufferOp.prototype.setEndCapStyle = function setEndCapStyle (endCapStyle) {
+ this._bufParams.setEndCapStyle(endCapStyle);
+ };
+ BufferOp.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ BufferOp.prototype.getClass = function getClass () {
+ return BufferOp
+ };
+ BufferOp.bufferOp = function bufferOp () {
+ if (arguments.length === 2) {
+ var g = arguments[0];
+ var distance = arguments[1];
+ var gBuf = new BufferOp(g);
+ var geomBuf = gBuf.getResultGeometry(distance);
+ return geomBuf
+ } else if (arguments.length === 3) {
+ if (Number.isInteger(arguments[2]) && (arguments[0] instanceof Geometry && typeof arguments[1] === 'number')) {
+ var g$1 = arguments[0];
+ var distance$1 = arguments[1];
+ var quadrantSegments = arguments[2];
+ var bufOp = new BufferOp(g$1);
+ bufOp.setQuadrantSegments(quadrantSegments);
+ var geomBuf$1 = bufOp.getResultGeometry(distance$1);
+ return geomBuf$1
+ } else if (arguments[2] instanceof BufferParameters && (arguments[0] instanceof Geometry && typeof arguments[1] === 'number')) {
+ var g$2 = arguments[0];
+ var distance$2 = arguments[1];
+ var params = arguments[2];
+ var bufOp$1 = new BufferOp(g$2, params);
+ var geomBuf$2 = bufOp$1.getResultGeometry(distance$2);
+ return geomBuf$2
+ }
+ } else if (arguments.length === 4) {
+ var g$3 = arguments[0];
+ var distance$3 = arguments[1];
+ var quadrantSegments$1 = arguments[2];
+ var endCapStyle = arguments[3];
+ var bufOp$2 = new BufferOp(g$3);
+ bufOp$2.setQuadrantSegments(quadrantSegments$1);
+ bufOp$2.setEndCapStyle(endCapStyle);
+ var geomBuf$3 = bufOp$2.getResultGeometry(distance$3);
+ return geomBuf$3
+ }
+ };
+ BufferOp.precisionScaleFactor = function precisionScaleFactor (g, distance, maxPrecisionDigits) {
+ var env = g.getEnvelopeInternal();
+ var envMax = MathUtil.max(Math.abs(env.getMaxX()), Math.abs(env.getMaxY()), Math.abs(env.getMinX()), Math.abs(env.getMinY()));
+ var expandByDistance = distance > 0.0 ? distance : 0.0;
+ var bufEnvMax = envMax + 2 * expandByDistance;
+ var bufEnvPrecisionDigits = Math.trunc(Math.log(bufEnvMax) / Math.log(10) + 1.0);
+ var minUnitLog10 = maxPrecisionDigits - bufEnvPrecisionDigits;
+ var scaleFactor = Math.pow(10.0, minUnitLog10);
+ return scaleFactor
+ };
+ staticAccessors$32.CAP_ROUND.get = function () { return BufferParameters.CAP_ROUND };
+ staticAccessors$32.CAP_BUTT.get = function () { return BufferParameters.CAP_FLAT };
+ staticAccessors$32.CAP_FLAT.get = function () { return BufferParameters.CAP_FLAT };
+ staticAccessors$32.CAP_SQUARE.get = function () { return BufferParameters.CAP_SQUARE };
+ staticAccessors$32.MAX_PRECISION_DIGITS.get = function () { return 12 };
+
+ Object.defineProperties( BufferOp, staticAccessors$32 );
+
+ var PointPairDistance = function PointPairDistance () {
+ this._pt = [new Coordinate(), new Coordinate()];
+ this._distance = Double.NaN;
+ this._isNull = true;
+ };
+ PointPairDistance.prototype.getCoordinates = function getCoordinates () {
+ return this._pt
+ };
+ PointPairDistance.prototype.getCoordinate = function getCoordinate (i) {
+ return this._pt[i]
+ };
+ PointPairDistance.prototype.setMinimum = function setMinimum () {
+ if (arguments.length === 1) {
+ var ptDist = arguments[0];
+ this.setMinimum(ptDist._pt[0], ptDist._pt[1]);
+ } else if (arguments.length === 2) {
+ var p0 = arguments[0];
+ var p1 = arguments[1];
+ if (this._isNull) {
+ this.initialize(p0, p1);
+ return null
+ }
+ var dist = p0.distance(p1);
+ if (dist < this._distance) { this.initialize(p0, p1, dist); }
+ }
+ };
+ PointPairDistance.prototype.initialize = function initialize () {
+ if (arguments.length === 0) {
+ this._isNull = true;
+ } else if (arguments.length === 2) {
+ var p0 = arguments[0];
+ var p1 = arguments[1];
+ this._pt[0].setCoordinate(p0);
+ this._pt[1].setCoordinate(p1);
+ this._distance = p0.distance(p1);
+ this._isNull = false;
+ } else if (arguments.length === 3) {
+ var p0$1 = arguments[0];
+ var p1$1 = arguments[1];
+ var distance = arguments[2];
+ this._pt[0].setCoordinate(p0$1);
+ this._pt[1].setCoordinate(p1$1);
+ this._distance = distance;
+ this._isNull = false;
+ }
+ };
+ PointPairDistance.prototype.getDistance = function getDistance () {
+ return this._distance
+ };
+ PointPairDistance.prototype.setMaximum = function setMaximum () {
+ if (arguments.length === 1) {
+ var ptDist = arguments[0];
+ this.setMaximum(ptDist._pt[0], ptDist._pt[1]);
+ } else if (arguments.length === 2) {
+ var p0 = arguments[0];
+ var p1 = arguments[1];
+ if (this._isNull) {
+ this.initialize(p0, p1);
+ return null
+ }
+ var dist = p0.distance(p1);
+ if (dist > this._distance) { this.initialize(p0, p1, dist); }
+ }
+ };
+ PointPairDistance.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ PointPairDistance.prototype.getClass = function getClass () {
+ return PointPairDistance
+ };
+
+ var DistanceToPointFinder = function DistanceToPointFinder () {};
+
+ DistanceToPointFinder.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ DistanceToPointFinder.prototype.getClass = function getClass () {
+ return DistanceToPointFinder
+ };
+ DistanceToPointFinder.computeDistance = function computeDistance () {
+ if (arguments[2] instanceof PointPairDistance && (arguments[0] instanceof LineString && arguments[1] instanceof Coordinate)) {
+ var line = arguments[0];
+ var pt = arguments[1];
+ var ptDist = arguments[2];
+ var coords = line.getCoordinates();
+ var tempSegment = new LineSegment();
+ for (var i = 0; i < coords.length - 1; i++) {
+ tempSegment.setCoordinates(coords[i], coords[i + 1]);
+ var closestPt = tempSegment.closestPoint(pt);
+ ptDist.setMinimum(closestPt, pt);
+ }
+ } else if (arguments[2] instanceof PointPairDistance && (arguments[0] instanceof Polygon && arguments[1] instanceof Coordinate)) {
+ var poly = arguments[0];
+ var pt$1 = arguments[1];
+ var ptDist$1 = arguments[2];
+ DistanceToPointFinder.computeDistance(poly.getExteriorRing(), pt$1, ptDist$1);
+ for (var i$1 = 0; i$1 < poly.getNumInteriorRing(); i$1++) {
+ DistanceToPointFinder.computeDistance(poly.getInteriorRingN(i$1), pt$1, ptDist$1);
+ }
+ } else if (arguments[2] instanceof PointPairDistance && (arguments[0] instanceof Geometry && arguments[1] instanceof Coordinate)) {
+ var geom = arguments[0];
+ var pt$2 = arguments[1];
+ var ptDist$2 = arguments[2];
+ if (geom instanceof LineString) {
+ DistanceToPointFinder.computeDistance(geom, pt$2, ptDist$2);
+ } else if (geom instanceof Polygon) {
+ DistanceToPointFinder.computeDistance(geom, pt$2, ptDist$2);
+ } else if (geom instanceof GeometryCollection) {
+ var gc = geom;
+ for (var i$2 = 0; i$2 < gc.getNumGeometries(); i$2++) {
+ var g = gc.getGeometryN(i$2);
+ DistanceToPointFinder.computeDistance(g, pt$2, ptDist$2);
+ }
+ } else {
+ ptDist$2.setMinimum(geom.getCoordinate(), pt$2);
+ }
+ } else if (arguments[2] instanceof PointPairDistance && (arguments[0] instanceof LineSegment && arguments[1] instanceof Coordinate)) {
+ var segment = arguments[0];
+ var pt$3 = arguments[1];
+ var ptDist$3 = arguments[2];
+ var closestPt$1 = segment.closestPoint(pt$3);
+ ptDist$3.setMinimum(closestPt$1, pt$3);
+ }
+ };
+
+ var BufferCurveMaximumDistanceFinder = function BufferCurveMaximumDistanceFinder (inputGeom) {
+ this._maxPtDist = new PointPairDistance();
+ this._inputGeom = inputGeom || null;
+ };
+
+ var staticAccessors$36 = { MaxPointDistanceFilter: { configurable: true },MaxMidpointDistanceFilter: { configurable: true } };
+ BufferCurveMaximumDistanceFinder.prototype.computeMaxMidpointDistance = function computeMaxMidpointDistance (curve) {
+ var distFilter = new MaxMidpointDistanceFilter(this._inputGeom);
+ curve.apply(distFilter);
+ this._maxPtDist.setMaximum(distFilter.getMaxPointDistance());
+ };
+ BufferCurveMaximumDistanceFinder.prototype.computeMaxVertexDistance = function computeMaxVertexDistance (curve) {
+ var distFilter = new MaxPointDistanceFilter(this._inputGeom);
+ curve.apply(distFilter);
+ this._maxPtDist.setMaximum(distFilter.getMaxPointDistance());
+ };
+ BufferCurveMaximumDistanceFinder.prototype.findDistance = function findDistance (bufferCurve) {
+ this.computeMaxVertexDistance(bufferCurve);
+ this.computeMaxMidpointDistance(bufferCurve);
+ return this._maxPtDist.getDistance()
+ };
+ BufferCurveMaximumDistanceFinder.prototype.getDistancePoints = function getDistancePoints () {
+ return this._maxPtDist
+ };
+ BufferCurveMaximumDistanceFinder.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ BufferCurveMaximumDistanceFinder.prototype.getClass = function getClass () {
+ return BufferCurveMaximumDistanceFinder
+ };
+ staticAccessors$36.MaxPointDistanceFilter.get = function () { return MaxPointDistanceFilter };
+ staticAccessors$36.MaxMidpointDistanceFilter.get = function () { return MaxMidpointDistanceFilter };
+
+ Object.defineProperties( BufferCurveMaximumDistanceFinder, staticAccessors$36 );
+
+ var MaxPointDistanceFilter = function MaxPointDistanceFilter (geom) {
+ this._maxPtDist = new PointPairDistance();
+ this._minPtDist = new PointPairDistance();
+ this._geom = geom || null;
+ };
+ MaxPointDistanceFilter.prototype.filter = function filter (pt) {
+ this._minPtDist.initialize();
+ DistanceToPointFinder.computeDistance(this._geom, pt, this._minPtDist);
+ this._maxPtDist.setMaximum(this._minPtDist);
+ };
+ MaxPointDistanceFilter.prototype.getMaxPointDistance = function getMaxPointDistance () {
+ return this._maxPtDist
+ };
+ MaxPointDistanceFilter.prototype.interfaces_ = function interfaces_ () {
+ return [CoordinateFilter]
+ };
+ MaxPointDistanceFilter.prototype.getClass = function getClass () {
+ return MaxPointDistanceFilter
+ };
+
+ var MaxMidpointDistanceFilter = function MaxMidpointDistanceFilter (geom) {
+ this._maxPtDist = new PointPairDistance();
+ this._minPtDist = new PointPairDistance();
+ this._geom = geom || null;
+ };
+ MaxMidpointDistanceFilter.prototype.filter = function filter (seq, index) {
+ if (index === 0) { return null }
+ var p0 = seq.getCoordinate(index - 1);
+ var p1 = seq.getCoordinate(index);
+ var midPt = new Coordinate((p0.x + p1.x) / 2, (p0.y + p1.y) / 2);
+ this._minPtDist.initialize();
+ DistanceToPointFinder.computeDistance(this._geom, midPt, this._minPtDist);
+ this._maxPtDist.setMaximum(this._minPtDist);
+ };
+ MaxMidpointDistanceFilter.prototype.isDone = function isDone () {
+ return false
+ };
+ MaxMidpointDistanceFilter.prototype.isGeometryChanged = function isGeometryChanged () {
+ return false
+ };
+ MaxMidpointDistanceFilter.prototype.getMaxPointDistance = function getMaxPointDistance () {
+ return this._maxPtDist
+ };
+ MaxMidpointDistanceFilter.prototype.interfaces_ = function interfaces_ () {
+ return [CoordinateSequenceFilter]
+ };
+ MaxMidpointDistanceFilter.prototype.getClass = function getClass () {
+ return MaxMidpointDistanceFilter
+ };
+
+ var PolygonExtracter = function PolygonExtracter (comps) {
+ this._comps = comps || null;
+ };
+ PolygonExtracter.prototype.filter = function filter (geom) {
+ if (geom instanceof Polygon) { this._comps.add(geom); }
+ };
+ PolygonExtracter.prototype.interfaces_ = function interfaces_ () {
+ return [GeometryFilter]
+ };
+ PolygonExtracter.prototype.getClass = function getClass () {
+ return PolygonExtracter
+ };
+ PolygonExtracter.getPolygons = function getPolygons () {
+ if (arguments.length === 1) {
+ var geom = arguments[0];
+ return PolygonExtracter.getPolygons(geom, new ArrayList())
+ } else if (arguments.length === 2) {
+ var geom$1 = arguments[0];
+ var list = arguments[1];
+ if (geom$1 instanceof Polygon) {
+ list.add(geom$1);
+ } else if (geom$1 instanceof GeometryCollection) {
+ geom$1.apply(new PolygonExtracter(list));
+ }
+ return list
+ }
+ };
+
+ var LinearComponentExtracter = function LinearComponentExtracter () {
+ this._lines = null;
+ this._isForcedToLineString = false;
+ if (arguments.length === 1) {
+ var lines = arguments[0];
+ this._lines = lines;
+ } else if (arguments.length === 2) {
+ var lines$1 = arguments[0];
+ var isForcedToLineString = arguments[1];
+ this._lines = lines$1;
+ this._isForcedToLineString = isForcedToLineString;
+ }
+ };
+ LinearComponentExtracter.prototype.filter = function filter (geom) {
+ if (this._isForcedToLineString && geom instanceof LinearRing) {
+ var line = geom.getFactory().createLineString(geom.getCoordinateSequence());
+ this._lines.add(line);
+ return null
+ }
+ if (geom instanceof LineString) { this._lines.add(geom); }
+ };
+ LinearComponentExtracter.prototype.setForceToLineString = function setForceToLineString (isForcedToLineString) {
+ this._isForcedToLineString = isForcedToLineString;
+ };
+ LinearComponentExtracter.prototype.interfaces_ = function interfaces_ () {
+ return [GeometryComponentFilter]
+ };
+ LinearComponentExtracter.prototype.getClass = function getClass () {
+ return LinearComponentExtracter
+ };
+ LinearComponentExtracter.getGeometry = function getGeometry () {
+ if (arguments.length === 1) {
+ var geom = arguments[0];
+ return geom.getFactory().buildGeometry(LinearComponentExtracter.getLines(geom))
+ } else if (arguments.length === 2) {
+ var geom$1 = arguments[0];
+ var forceToLineString = arguments[1];
+ return geom$1.getFactory().buildGeometry(LinearComponentExtracter.getLines(geom$1, forceToLineString))
+ }
+ };
+ LinearComponentExtracter.getLines = function getLines () {
+ if (arguments.length === 1) {
+ var geom = arguments[0];
+ return LinearComponentExtracter.getLines(geom, false)
+ } else if (arguments.length === 2) {
+ if (hasInterface(arguments[0], Collection) && hasInterface(arguments[1], Collection)) {
+ var geoms = arguments[0];
+ var lines$1 = arguments[1];
+ for (var i = geoms.iterator(); i.hasNext();) {
+ var g = i.next();
+ LinearComponentExtracter.getLines(g, lines$1);
+ }
+ return lines$1
+ } else if (arguments[0] instanceof Geometry && typeof arguments[1] === 'boolean') {
+ var geom$1 = arguments[0];
+ var forceToLineString = arguments[1];
+ var lines = new ArrayList();
+ geom$1.apply(new LinearComponentExtracter(lines, forceToLineString));
+ return lines
+ } else if (arguments[0] instanceof Geometry && hasInterface(arguments[1], Collection)) {
+ var geom$2 = arguments[0];
+ var lines$2 = arguments[1];
+ if (geom$2 instanceof LineString) {
+ lines$2.add(geom$2);
+ } else {
+ geom$2.apply(new LinearComponentExtracter(lines$2));
+ }
+ return lines$2
+ }
+ } else if (arguments.length === 3) {
+ if (typeof arguments[2] === 'boolean' && (hasInterface(arguments[0], Collection) && hasInterface(arguments[1], Collection))) {
+ var geoms$1 = arguments[0];
+ var lines$3 = arguments[1];
+ var forceToLineString$1 = arguments[2];
+ for (var i$1 = geoms$1.iterator(); i$1.hasNext();) {
+ var g$1 = i$1.next();
+ LinearComponentExtracter.getLines(g$1, lines$3, forceToLineString$1);
+ }
+ return lines$3
+ } else if (typeof arguments[2] === 'boolean' && (arguments[0] instanceof Geometry && hasInterface(arguments[1], Collection))) {
+ var geom$3 = arguments[0];
+ var lines$4 = arguments[1];
+ var forceToLineString$2 = arguments[2];
+ geom$3.apply(new LinearComponentExtracter(lines$4, forceToLineString$2));
+ return lines$4
+ }
+ }
+ };
+
+ var PointLocator = function PointLocator () {
+ this._boundaryRule = BoundaryNodeRule.OGC_SFS_BOUNDARY_RULE;
+ this._isIn = null;
+ this._numBoundaries = null;
+ if (arguments.length === 0) ; else if (arguments.length === 1) {
+ var boundaryRule = arguments[0];
+ if (boundaryRule === null) { throw new IllegalArgumentException('Rule must be non-null') }
+ this._boundaryRule = boundaryRule;
+ }
+ };
+ PointLocator.prototype.locateInternal = function locateInternal () {
+ var this$1 = this;
+
+ if (arguments[0] instanceof Coordinate && arguments[1] instanceof Polygon) {
+ var p = arguments[0];
+ var poly = arguments[1];
+ if (poly.isEmpty()) { return Location.EXTERIOR }
+ var shell = poly.getExteriorRing();
+ var shellLoc = this.locateInPolygonRing(p, shell);
+ if (shellLoc === Location.EXTERIOR) { return Location.EXTERIOR }
+ if (shellLoc === Location.BOUNDARY) { return Location.BOUNDARY }
+ for (var i = 0; i < poly.getNumInteriorRing(); i++) {
+ var hole = poly.getInteriorRingN(i);
+ var holeLoc = this$1.locateInPolygonRing(p, hole);
+ if (holeLoc === Location.INTERIOR) { return Location.EXTERIOR }
+ if (holeLoc === Location.BOUNDARY) { return Location.BOUNDARY }
+ }
+ return Location.INTERIOR
+ } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof LineString) {
+ var p$1 = arguments[0];
+ var l = arguments[1];
+ if (!l.getEnvelopeInternal().intersects(p$1)) { return Location.EXTERIOR }
+ var pt = l.getCoordinates();
+ if (!l.isClosed()) {
+ if (p$1.equals(pt[0]) || p$1.equals(pt[pt.length - 1])) {
+ return Location.BOUNDARY
+ }
+ }
+ if (CGAlgorithms.isOnLine(p$1, pt)) { return Location.INTERIOR }
+ return Location.EXTERIOR
+ } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Point) {
+ var p$2 = arguments[0];
+ var pt$1 = arguments[1];
+ var ptCoord = pt$1.getCoordinate();
+ if (ptCoord.equals2D(p$2)) { return Location.INTERIOR }
+ return Location.EXTERIOR
+ }
+ };
+ PointLocator.prototype.locateInPolygonRing = function locateInPolygonRing (p, ring) {
+ if (!ring.getEnvelopeInternal().intersects(p)) { return Location.EXTERIOR }
+ return CGAlgorithms.locatePointInRing(p, ring.getCoordinates())
+ };
+ PointLocator.prototype.intersects = function intersects (p, geom) {
+ return this.locate(p, geom) !== Location.EXTERIOR
+ };
+ PointLocator.prototype.updateLocationInfo = function updateLocationInfo (loc) {
+ if (loc === Location.INTERIOR) { this._isIn = true; }
+ if (loc === Location.BOUNDARY) { this._numBoundaries++; }
+ };
+ PointLocator.prototype.computeLocation = function computeLocation (p, geom) {
+ var this$1 = this;
+
+ if (geom instanceof Point) {
+ this.updateLocationInfo(this.locateInternal(p, geom));
+ }
+ if (geom instanceof LineString) {
+ this.updateLocationInfo(this.locateInternal(p, geom));
+ } else if (geom instanceof Polygon) {
+ this.updateLocationInfo(this.locateInternal(p, geom));
+ } else if (geom instanceof MultiLineString) {
+ var ml = geom;
+ for (var i = 0; i < ml.getNumGeometries(); i++) {
+ var l = ml.getGeometryN(i);
+ this$1.updateLocationInfo(this$1.locateInternal(p, l));
+ }
+ } else if (geom instanceof MultiPolygon) {
+ var mpoly = geom;
+ for (var i$1 = 0; i$1 < mpoly.getNumGeometries(); i$1++) {
+ var poly = mpoly.getGeometryN(i$1);
+ this$1.updateLocationInfo(this$1.locateInternal(p, poly));
+ }
+ } else if (geom instanceof GeometryCollection) {
+ var geomi = new GeometryCollectionIterator(geom);
+ while (geomi.hasNext()) {
+ var g2 = geomi.next();
+ if (g2 !== geom) { this$1.computeLocation(p, g2); }
+ }
+ }
+ };
+ PointLocator.prototype.locate = function locate (p, geom) {
+ if (geom.isEmpty()) { return Location.EXTERIOR }
+ if (geom instanceof LineString) {
+ return this.locateInternal(p, geom)
+ } else if (geom instanceof Polygon) {
+ return this.locateInternal(p, geom)
+ }
+ this._isIn = false;
+ this._numBoundaries = 0;
+ this.computeLocation(p, geom);
+ if (this._boundaryRule.isInBoundary(this._numBoundaries)) { return Location.BOUNDARY }
+ if (this._numBoundaries > 0 || this._isIn) { return Location.INTERIOR }
+ return Location.EXTERIOR
+ };
+ PointLocator.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ PointLocator.prototype.getClass = function getClass () {
+ return PointLocator
+ };
+
+ var GeometryLocation = function GeometryLocation () {
+ this._component = null;
+ this._segIndex = null;
+ this._pt = null;
+ if (arguments.length === 2) {
+ var component = arguments[0];
+ var pt = arguments[1];
+ GeometryLocation.call(this, component, GeometryLocation.INSIDE_AREA, pt);
+ } else if (arguments.length === 3) {
+ var component$1 = arguments[0];
+ var segIndex = arguments[1];
+ var pt$1 = arguments[2];
+ this._component = component$1;
+ this._segIndex = segIndex;
+ this._pt = pt$1;
+ }
+ };
+
+ var staticAccessors$38 = { INSIDE_AREA: { configurable: true } };
+ GeometryLocation.prototype.isInsideArea = function isInsideArea () {
+ return this._segIndex === GeometryLocation.INSIDE_AREA
+ };
+ GeometryLocation.prototype.getCoordinate = function getCoordinate () {
+ return this._pt
+ };
+ GeometryLocation.prototype.getGeometryComponent = function getGeometryComponent () {
+ return this._component
+ };
+ GeometryLocation.prototype.getSegmentIndex = function getSegmentIndex () {
+ return this._segIndex
+ };
+ GeometryLocation.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ GeometryLocation.prototype.getClass = function getClass () {
+ return GeometryLocation
+ };
+ staticAccessors$38.INSIDE_AREA.get = function () { return -1 };
+
+ Object.defineProperties( GeometryLocation, staticAccessors$38 );
+
+ var PointExtracter = function PointExtracter (pts) {
+ this._pts = pts || null;
+ };
+ PointExtracter.prototype.filter = function filter (geom) {
+ if (geom instanceof Point) { this._pts.add(geom); }
+ };
+ PointExtracter.prototype.interfaces_ = function interfaces_ () {
+ return [GeometryFilter]
+ };
+ PointExtracter.prototype.getClass = function getClass () {
+ return PointExtracter
+ };
+ PointExtracter.getPoints = function getPoints () {
+ if (arguments.length === 1) {
+ var geom = arguments[0];
+ if (geom instanceof Point) {
+ return Collections.singletonList(geom)
+ }
+ return PointExtracter.getPoints(geom, new ArrayList())
+ } else if (arguments.length === 2) {
+ var geom$1 = arguments[0];
+ var list = arguments[1];
+ if (geom$1 instanceof Point) {
+ list.add(geom$1);
+ } else if (geom$1 instanceof GeometryCollection) {
+ geom$1.apply(new PointExtracter(list));
+ }
+ return list
+ }
+ };
+
+ var ConnectedElementLocationFilter = function ConnectedElementLocationFilter () {
+ this._locations = null;
+ var locations = arguments[0];
+ this._locations = locations;
+ };
+ ConnectedElementLocationFilter.prototype.filter = function filter (geom) {
+ if (geom instanceof Point || geom instanceof LineString || geom instanceof Polygon) { this._locations.add(new GeometryLocation(geom, 0, geom.getCoordinate())); }
+ };
+ ConnectedElementLocationFilter.prototype.interfaces_ = function interfaces_ () {
+ return [GeometryFilter]
+ };
+ ConnectedElementLocationFilter.prototype.getClass = function getClass () {
+ return ConnectedElementLocationFilter
+ };
+ ConnectedElementLocationFilter.getLocations = function getLocations (geom) {
+ var locations = new ArrayList();
+ geom.apply(new ConnectedElementLocationFilter(locations));
+ return locations
+ };
+
+ var DistanceOp = function DistanceOp () {
+ this._geom = null;
+ this._terminateDistance = 0.0;
+ this._ptLocator = new PointLocator();
+ this._minDistanceLocation = null;
+ this._minDistance = Double.MAX_VALUE;
+ if (arguments.length === 2) {
+ var g0 = arguments[0];
+ var g1 = arguments[1];
+ this._geom = [g0, g1];
+ this._terminateDistance = 0.0;
+ } else if (arguments.length === 3) {
+ var g0$1 = arguments[0];
+ var g1$1 = arguments[1];
+ var terminateDistance = arguments[2];
+ this._geom = new Array(2).fill(null);
+ this._geom[0] = g0$1;
+ this._geom[1] = g1$1;
+ this._terminateDistance = terminateDistance;
+ }
+ };
+ DistanceOp.prototype.computeContainmentDistance = function computeContainmentDistance () {
+ var this$1 = this;
+
+ if (arguments.length === 0) {
+ var locPtPoly = new Array(2).fill(null);
+ this.computeContainmentDistance(0, locPtPoly);
+ if (this._minDistance <= this._terminateDistance) { return null }
+ this.computeContainmentDistance(1, locPtPoly);
+ } else if (arguments.length === 2) {
+ var polyGeomIndex = arguments[0];
+ var locPtPoly$1 = arguments[1];
+ var locationsIndex = 1 - polyGeomIndex;
+ var polys = PolygonExtracter.getPolygons(this._geom[polyGeomIndex]);
+ if (polys.size() > 0) {
+ var insideLocs = ConnectedElementLocationFilter.getLocations(this._geom[locationsIndex]);
+ this.computeContainmentDistance(insideLocs, polys, locPtPoly$1);
+ if (this._minDistance <= this._terminateDistance) {
+ this._minDistanceLocation[locationsIndex] = locPtPoly$1[0];
+ this._minDistanceLocation[polyGeomIndex] = locPtPoly$1[1];
+ return null
+ }
+ }
+ } else if (arguments.length === 3) {
+ if (arguments[2] instanceof Array && (hasInterface(arguments[0], List) && hasInterface(arguments[1], List))) {
+ var locs = arguments[0];
+ var polys$1 = arguments[1];
+ var locPtPoly$2 = arguments[2];
+ for (var i = 0; i < locs.size(); i++) {
+ var loc = locs.get(i);
+ for (var j = 0; j < polys$1.size(); j++) {
+ this$1.computeContainmentDistance(loc, polys$1.get(j), locPtPoly$2);
+ if (this$1._minDistance <= this$1._terminateDistance) { return null }
+ }
+ }
+ } else if (arguments[2] instanceof Array && (arguments[0] instanceof GeometryLocation && arguments[1] instanceof Polygon)) {
+ var ptLoc = arguments[0];
+ var poly = arguments[1];
+ var locPtPoly$3 = arguments[2];
+ var pt = ptLoc.getCoordinate();
+ if (Location.EXTERIOR !== this._ptLocator.locate(pt, poly)) {
+ this._minDistance = 0.0;
+ locPtPoly$3[0] = ptLoc;
+ locPtPoly$3[1] = new GeometryLocation(poly, pt);
+
+ return null
+ }
+ }
+ }
+ };
+ DistanceOp.prototype.computeMinDistanceLinesPoints = function computeMinDistanceLinesPoints (lines, points, locGeom) {
+ var this$1 = this;
+
+ for (var i = 0; i < lines.size(); i++) {
+ var line = lines.get(i);
+ for (var j = 0; j < points.size(); j++) {
+ var pt = points.get(j);
+ this$1.computeMinDistance(line, pt, locGeom);
+ if (this$1._minDistance <= this$1._terminateDistance) { return null }
+ }
+ }
+ };
+ DistanceOp.prototype.computeFacetDistance = function computeFacetDistance () {
+ var locGeom = new Array(2).fill(null);
+ var lines0 = LinearComponentExtracter.getLines(this._geom[0]);
+ var lines1 = LinearComponentExtracter.getLines(this._geom[1]);
+ var pts0 = PointExtracter.getPoints(this._geom[0]);
+ var pts1 = PointExtracter.getPoints(this._geom[1]);
+ this.computeMinDistanceLines(lines0, lines1, locGeom);
+ this.updateMinDistance(locGeom, false);
+ if (this._minDistance <= this._terminateDistance) { return null }
+ locGeom[0] = null;
+ locGeom[1] = null;
+ this.computeMinDistanceLinesPoints(lines0, pts1, locGeom);
+ this.updateMinDistance(locGeom, false);
+ if (this._minDistance <= this._terminateDistance) { return null }
+ locGeom[0] = null;
+ locGeom[1] = null;
+ this.computeMinDistanceLinesPoints(lines1, pts0, locGeom);
+ this.updateMinDistance(locGeom, true);
+ if (this._minDistance <= this._terminateDistance) { return null }
+ locGeom[0] = null;
+ locGeom[1] = null;
+ this.computeMinDistancePoints(pts0, pts1, locGeom);
+ this.updateMinDistance(locGeom, false);
+ };
+ DistanceOp.prototype.nearestLocations = function nearestLocations () {
+ this.computeMinDistance();
+ return this._minDistanceLocation
+ };
+ DistanceOp.prototype.updateMinDistance = function updateMinDistance (locGeom, flip) {
+ if (locGeom[0] === null) { return null }
+ if (flip) {
+ this._minDistanceLocation[0] = locGeom[1];
+ this._minDistanceLocation[1] = locGeom[0];
+ } else {
+ this._minDistanceLocation[0] = locGeom[0];
+ this._minDistanceLocation[1] = locGeom[1];
+ }
+ };
+ DistanceOp.prototype.nearestPoints = function nearestPoints () {
+ this.computeMinDistance();
+ var nearestPts = [this._minDistanceLocation[0].getCoordinate(), this._minDistanceLocation[1].getCoordinate()];
+ return nearestPts
+ };
+ DistanceOp.prototype.computeMinDistance = function computeMinDistance () {
+ var this$1 = this;
+
+ if (arguments.length === 0) {
+ if (this._minDistanceLocation !== null) { return null }
+ this._minDistanceLocation = new Array(2).fill(null);
+ this.computeContainmentDistance();
+ if (this._minDistance <= this._terminateDistance) { return null }
+ this.computeFacetDistance();
+ } else if (arguments.length === 3) {
+ if (arguments[2] instanceof Array && (arguments[0] instanceof LineString && arguments[1] instanceof Point)) {
+ var line = arguments[0];
+ var pt = arguments[1];
+ var locGeom = arguments[2];
+ if (line.getEnvelopeInternal().distance(pt.getEnvelopeInternal()) > this._minDistance) { return null }
+ var coord0 = line.getCoordinates();
+ var coord = pt.getCoordinate();
+ for (var i = 0; i < coord0.length - 1; i++) {
+ var dist = CGAlgorithms.distancePointLine(coord, coord0[i], coord0[i + 1]);
+ if (dist < this$1._minDistance) {
+ this$1._minDistance = dist;
+ var seg = new LineSegment(coord0[i], coord0[i + 1]);
+ var segClosestPoint = seg.closestPoint(coord);
+ locGeom[0] = new GeometryLocation(line, i, segClosestPoint);
+ locGeom[1] = new GeometryLocation(pt, 0, coord);
+ }
+ if (this$1._minDistance <= this$1._terminateDistance) { return null }
+ }
+ } else if (arguments[2] instanceof Array && (arguments[0] instanceof LineString && arguments[1] instanceof LineString)) {
+ var line0 = arguments[0];
+ var line1 = arguments[1];
+ var locGeom$1 = arguments[2];
+ if (line0.getEnvelopeInternal().distance(line1.getEnvelopeInternal()) > this._minDistance) { return null }
+ var coord0$1 = line0.getCoordinates();
+ var coord1 = line1.getCoordinates();
+ for (var i$1 = 0; i$1 < coord0$1.length - 1; i$1++) {
+ for (var j = 0; j < coord1.length - 1; j++) {
+ var dist$1 = CGAlgorithms.distanceLineLine(coord0$1[i$1], coord0$1[i$1 + 1], coord1[j], coord1[j + 1]);
+ if (dist$1 < this$1._minDistance) {
+ this$1._minDistance = dist$1;
+ var seg0 = new LineSegment(coord0$1[i$1], coord0$1[i$1 + 1]);
+ var seg1 = new LineSegment(coord1[j], coord1[j + 1]);
+ var closestPt = seg0.closestPoints(seg1);
+ locGeom$1[0] = new GeometryLocation(line0, i$1, closestPt[0]);
+ locGeom$1[1] = new GeometryLocation(line1, j, closestPt[1]);
+ }
+ if (this$1._minDistance <= this$1._terminateDistance) { return null }
+ }
+ }
+ }
+ }
+ };
+ DistanceOp.prototype.computeMinDistancePoints = function computeMinDistancePoints (points0, points1, locGeom) {
+ var this$1 = this;
+
+ for (var i = 0; i < points0.size(); i++) {
+ var pt0 = points0.get(i);
+ for (var j = 0; j < points1.size(); j++) {
+ var pt1 = points1.get(j);
+ var dist = pt0.getCoordinate().distance(pt1.getCoordinate());
+ if (dist < this$1._minDistance) {
+ this$1._minDistance = dist;
+ locGeom[0] = new GeometryLocation(pt0, 0, pt0.getCoordinate());
+ locGeom[1] = new GeometryLocation(pt1, 0, pt1.getCoordinate());
+ }
+ if (this$1._minDistance <= this$1._terminateDistance) { return null }
+ }
+ }
+ };
+ DistanceOp.prototype.distance = function distance () {
+ if (this._geom[0] === null || this._geom[1] === null) { throw new IllegalArgumentException('null geometries are not supported') }
+ if (this._geom[0].isEmpty() || this._geom[1].isEmpty()) { return 0.0 }
+ this.computeMinDistance();
+ return this._minDistance
+ };
+ DistanceOp.prototype.computeMinDistanceLines = function computeMinDistanceLines (lines0, lines1, locGeom) {
+ var this$1 = this;
+
+ for (var i = 0; i < lines0.size(); i++) {
+ var line0 = lines0.get(i);
+ for (var j = 0; j < lines1.size(); j++) {
+ var line1 = lines1.get(j);
+ this$1.computeMinDistance(line0, line1, locGeom);
+ if (this$1._minDistance <= this$1._terminateDistance) { return null }
+ }
+ }
+ };
+ DistanceOp.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ DistanceOp.prototype.getClass = function getClass () {
+ return DistanceOp
+ };
+ DistanceOp.distance = function distance (g0, g1) {
+ var distOp = new DistanceOp(g0, g1);
+ return distOp.distance()
+ };
+ DistanceOp.isWithinDistance = function isWithinDistance (g0, g1, distance) {
+ var distOp = new DistanceOp(g0, g1, distance);
+ return distOp.distance() <= distance
+ };
+ DistanceOp.nearestPoints = function nearestPoints (g0, g1) {
+ var distOp = new DistanceOp(g0, g1);
+ return distOp.nearestPoints()
+ };
+
+ var PointPairDistance$2 = function PointPairDistance () {
+ this._pt = [new Coordinate(), new Coordinate()];
+ this._distance = Double.NaN;
+ this._isNull = true;
+ };
+ PointPairDistance$2.prototype.getCoordinates = function getCoordinates () {
+ return this._pt
+ };
+ PointPairDistance$2.prototype.getCoordinate = function getCoordinate (i) {
+ return this._pt[i]
+ };
+ PointPairDistance$2.prototype.setMinimum = function setMinimum () {
+ if (arguments.length === 1) {
+ var ptDist = arguments[0];
+ this.setMinimum(ptDist._pt[0], ptDist._pt[1]);
+ } else if (arguments.length === 2) {
+ var p0 = arguments[0];
+ var p1 = arguments[1];
+ if (this._isNull) {
+ this.initialize(p0, p1);
+ return null
+ }
+ var dist = p0.distance(p1);
+ if (dist < this._distance) { this.initialize(p0, p1, dist); }
+ }
+ };
+ PointPairDistance$2.prototype.initialize = function initialize () {
+ if (arguments.length === 0) {
+ this._isNull = true;
+ } else if (arguments.length === 2) {
+ var p0 = arguments[0];
+ var p1 = arguments[1];
+ this._pt[0].setCoordinate(p0);
+ this._pt[1].setCoordinate(p1);
+ this._distance = p0.distance(p1);
+ this._isNull = false;
+ } else if (arguments.length === 3) {
+ var p0$1 = arguments[0];
+ var p1$1 = arguments[1];
+ var distance = arguments[2];
+ this._pt[0].setCoordinate(p0$1);
+ this._pt[1].setCoordinate(p1$1);
+ this._distance = distance;
+ this._isNull = false;
+ }
+ };
+ PointPairDistance$2.prototype.toString = function toString () {
+ return WKTWriter.toLineString(this._pt[0], this._pt[1])
+ };
+ PointPairDistance$2.prototype.getDistance = function getDistance () {
+ return this._distance
+ };
+ PointPairDistance$2.prototype.setMaximum = function setMaximum () {
+ if (arguments.length === 1) {
+ var ptDist = arguments[0];
+ this.setMaximum(ptDist._pt[0], ptDist._pt[1]);
+ } else if (arguments.length === 2) {
+ var p0 = arguments[0];
+ var p1 = arguments[1];
+ if (this._isNull) {
+ this.initialize(p0, p1);
+ return null
+ }
+ var dist = p0.distance(p1);
+ if (dist > this._distance) { this.initialize(p0, p1, dist); }
+ }
+ };
+ PointPairDistance$2.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ PointPairDistance$2.prototype.getClass = function getClass () {
+ return PointPairDistance$2
+ };
+
+ var DistanceToPoint = function DistanceToPoint () {};
+
+ DistanceToPoint.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ DistanceToPoint.prototype.getClass = function getClass () {
+ return DistanceToPoint
+ };
+ DistanceToPoint.computeDistance = function computeDistance () {
+ if (arguments[2] instanceof PointPairDistance$2 && (arguments[0] instanceof LineString && arguments[1] instanceof Coordinate)) {
+ var line = arguments[0];
+ var pt = arguments[1];
+ var ptDist = arguments[2];
+ var tempSegment = new LineSegment();
+ var coords = line.getCoordinates();
+ for (var i = 0; i < coords.length - 1; i++) {
+ tempSegment.setCoordinates(coords[i], coords[i + 1]);
+ var closestPt = tempSegment.closestPoint(pt);
+ ptDist.setMinimum(closestPt, pt);
+ }
+ } else if (arguments[2] instanceof PointPairDistance$2 && (arguments[0] instanceof Polygon && arguments[1] instanceof Coordinate)) {
+ var poly = arguments[0];
+ var pt$1 = arguments[1];
+ var ptDist$1 = arguments[2];
+ DistanceToPoint.computeDistance(poly.getExteriorRing(), pt$1, ptDist$1);
+ for (var i$1 = 0; i$1 < poly.getNumInteriorRing(); i$1++) {
+ DistanceToPoint.computeDistance(poly.getInteriorRingN(i$1), pt$1, ptDist$1);
+ }
+ } else if (arguments[2] instanceof PointPairDistance$2 && (arguments[0] instanceof Geometry && arguments[1] instanceof Coordinate)) {
+ var geom = arguments[0];
+ var pt$2 = arguments[1];
+ var ptDist$2 = arguments[2];
+ if (geom instanceof LineString) {
+ DistanceToPoint.computeDistance(geom, pt$2, ptDist$2);
+ } else if (geom instanceof Polygon) {
+ DistanceToPoint.computeDistance(geom, pt$2, ptDist$2);
+ } else if (geom instanceof GeometryCollection) {
+ var gc = geom;
+ for (var i$2 = 0; i$2 < gc.getNumGeometries(); i$2++) {
+ var g = gc.getGeometryN(i$2);
+ DistanceToPoint.computeDistance(g, pt$2, ptDist$2);
+ }
+ } else {
+ ptDist$2.setMinimum(geom.getCoordinate(), pt$2);
+ }
+ } else if (arguments[2] instanceof PointPairDistance$2 && (arguments[0] instanceof LineSegment && arguments[1] instanceof Coordinate)) {
+ var segment = arguments[0];
+ var pt$3 = arguments[1];
+ var ptDist$3 = arguments[2];
+ var closestPt$1 = segment.closestPoint(pt$3);
+ ptDist$3.setMinimum(closestPt$1, pt$3);
+ }
+ };
+
+ var DiscreteHausdorffDistance = function DiscreteHausdorffDistance () {
+ this._g0 = null;
+ this._g1 = null;
+ this._ptDist = new PointPairDistance$2();
+ this._densifyFrac = 0.0;
+ var g0 = arguments[0];
+ var g1 = arguments[1];
+ this._g0 = g0;
+ this._g1 = g1;
+ };
+
+ var staticAccessors$39 = { MaxPointDistanceFilter: { configurable: true },MaxDensifiedByFractionDistanceFilter: { configurable: true } };
+ DiscreteHausdorffDistance.prototype.getCoordinates = function getCoordinates () {
+ return this._ptDist.getCoordinates()
+ };
+ DiscreteHausdorffDistance.prototype.setDensifyFraction = function setDensifyFraction (densifyFrac) {
+ if (densifyFrac > 1.0 || densifyFrac <= 0.0) { throw new IllegalArgumentException('Fraction is not in range (0.0 - 1.0]') }
+ this._densifyFrac = densifyFrac;
+ };
+ DiscreteHausdorffDistance.prototype.compute = function compute (g0, g1) {
+ this.computeOrientedDistance(g0, g1, this._ptDist);
+ this.computeOrientedDistance(g1, g0, this._ptDist);
+ };
+ DiscreteHausdorffDistance.prototype.distance = function distance () {
+ this.compute(this._g0, this._g1);
+ return this._ptDist.getDistance()
+ };
+ DiscreteHausdorffDistance.prototype.computeOrientedDistance = function computeOrientedDistance (discreteGeom, geom, ptDist) {
+ var distFilter = new MaxPointDistanceFilter$1(geom);
+ discreteGeom.apply(distFilter);
+ ptDist.setMaximum(distFilter.getMaxPointDistance());
+ if (this._densifyFrac > 0) {
+ var fracFilter = new MaxDensifiedByFractionDistanceFilter(geom, this._densifyFrac);
+ discreteGeom.apply(fracFilter);
+ ptDist.setMaximum(fracFilter.getMaxPointDistance());
+ }
+ };
+ DiscreteHausdorffDistance.prototype.orientedDistance = function orientedDistance () {
+ this.computeOrientedDistance(this._g0, this._g1, this._ptDist);
+ return this._ptDist.getDistance()
+ };
+ DiscreteHausdorffDistance.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ DiscreteHausdorffDistance.prototype.getClass = function getClass () {
+ return DiscreteHausdorffDistance
+ };
+ DiscreteHausdorffDistance.distance = function distance () {
+ if (arguments.length === 2) {
+ var g0 = arguments[0];
+ var g1 = arguments[1];
+ var dist = new DiscreteHausdorffDistance(g0, g1);
+ return dist.distance()
+ } else if (arguments.length === 3) {
+ var g0$1 = arguments[0];
+ var g1$1 = arguments[1];
+ var densifyFrac = arguments[2];
+ var dist$1 = new DiscreteHausdorffDistance(g0$1, g1$1);
+ dist$1.setDensifyFraction(densifyFrac);
+ return dist$1.distance()
+ }
+ };
+ staticAccessors$39.MaxPointDistanceFilter.get = function () { return MaxPointDistanceFilter$1 };
+ staticAccessors$39.MaxDensifiedByFractionDistanceFilter.get = function () { return MaxDensifiedByFractionDistanceFilter };
+
+ Object.defineProperties( DiscreteHausdorffDistance, staticAccessors$39 );
+
+ var MaxPointDistanceFilter$1 = function MaxPointDistanceFilter () {
+ this._maxPtDist = new PointPairDistance$2();
+ this._minPtDist = new PointPairDistance$2();
+ this._euclideanDist = new DistanceToPoint();
+ this._geom = null;
+ var geom = arguments[0];
+ this._geom = geom;
+ };
+ MaxPointDistanceFilter$1.prototype.filter = function filter (pt) {
+ this._minPtDist.initialize();
+ DistanceToPoint.computeDistance(this._geom, pt, this._minPtDist);
+ this._maxPtDist.setMaximum(this._minPtDist);
+ };
+ MaxPointDistanceFilter$1.prototype.getMaxPointDistance = function getMaxPointDistance () {
+ return this._maxPtDist
+ };
+ MaxPointDistanceFilter$1.prototype.interfaces_ = function interfaces_ () {
+ return [CoordinateFilter]
+ };
+ MaxPointDistanceFilter$1.prototype.getClass = function getClass () {
+ return MaxPointDistanceFilter$1
+ };
+
+ var MaxDensifiedByFractionDistanceFilter = function MaxDensifiedByFractionDistanceFilter () {
+ this._maxPtDist = new PointPairDistance$2();
+ this._minPtDist = new PointPairDistance$2();
+ this._geom = null;
+ this._numSubSegs = 0;
+ var geom = arguments[0];
+ var fraction = arguments[1];
+ this._geom = geom;
+ this._numSubSegs = Math.trunc(Math.round(1.0 / fraction));
+ };
+ MaxDensifiedByFractionDistanceFilter.prototype.filter = function filter (seq, index) {
+ var this$1 = this;
+
+ if (index === 0) { return null }
+ var p0 = seq.getCoordinate(index - 1);
+ var p1 = seq.getCoordinate(index);
+ var delx = (p1.x - p0.x) / this._numSubSegs;
+ var dely = (p1.y - p0.y) / this._numSubSegs;
+ for (var i = 0; i < this._numSubSegs; i++) {
+ var x = p0.x + i * delx;
+ var y = p0.y + i * dely;
+ var pt = new Coordinate(x, y);
+ this$1._minPtDist.initialize();
+ DistanceToPoint.computeDistance(this$1._geom, pt, this$1._minPtDist);
+ this$1._maxPtDist.setMaximum(this$1._minPtDist);
+ }
+ };
+ MaxDensifiedByFractionDistanceFilter.prototype.isDone = function isDone () {
+ return false
+ };
+ MaxDensifiedByFractionDistanceFilter.prototype.isGeometryChanged = function isGeometryChanged () {
+ return false
+ };
+ MaxDensifiedByFractionDistanceFilter.prototype.getMaxPointDistance = function getMaxPointDistance () {
+ return this._maxPtDist
+ };
+ MaxDensifiedByFractionDistanceFilter.prototype.interfaces_ = function interfaces_ () {
+ return [CoordinateSequenceFilter]
+ };
+ MaxDensifiedByFractionDistanceFilter.prototype.getClass = function getClass () {
+ return MaxDensifiedByFractionDistanceFilter
+ };
+
+ var BufferDistanceValidator = function BufferDistanceValidator (input, bufDistance, result) {
+ this._minValidDistance = null;
+ this._maxValidDistance = null;
+ this._minDistanceFound = null;
+ this._maxDistanceFound = null;
+ this._isValid = true;
+ this._errMsg = null;
+ this._errorLocation = null;
+ this._errorIndicator = null;
+ this._input = input || null;
+ this._bufDistance = bufDistance || null;
+ this._result = result || null;
+ };
+
+ var staticAccessors$37 = { VERBOSE: { configurable: true },MAX_DISTANCE_DIFF_FRAC: { configurable: true } };
+ BufferDistanceValidator.prototype.checkMaximumDistance = function checkMaximumDistance (input, bufCurve, maxDist) {
+ var haus = new DiscreteHausdorffDistance(bufCurve, input);
+ haus.setDensifyFraction(0.25);
+ this._maxDistanceFound = haus.orientedDistance();
+ if (this._maxDistanceFound > maxDist) {
+ this._isValid = false;
+ var pts = haus.getCoordinates();
+ this._errorLocation = pts[1];
+ this._errorIndicator = input.getFactory().createLineString(pts);
+ this._errMsg = 'Distance between buffer curve and input is too large (' + this._maxDistanceFound + ' at ' + WKTWriter.toLineString(pts[0], pts[1]) + ')';
+ }
+ };
+ BufferDistanceValidator.prototype.isValid = function isValid () {
+ var posDistance = Math.abs(this._bufDistance);
+ var distDelta = BufferDistanceValidator.MAX_DISTANCE_DIFF_FRAC * posDistance;
+ this._minValidDistance = posDistance - distDelta;
+ this._maxValidDistance = posDistance + distDelta;
+ if (this._input.isEmpty() || this._result.isEmpty()) { return true }
+ if (this._bufDistance > 0.0) {
+ this.checkPositiveValid();
+ } else {
+ this.checkNegativeValid();
+ }
+ if (BufferDistanceValidator.VERBOSE) {
+ System.out.println('Min Dist= ' + this._minDistanceFound + ' err= ' + (1.0 - this._minDistanceFound / this._bufDistance) + ' Max Dist= ' + this._maxDistanceFound + ' err= ' + (this._maxDistanceFound / this._bufDistance - 1.0));
+ }
+ return this._isValid
+ };
+ BufferDistanceValidator.prototype.checkNegativeValid = function checkNegativeValid () {
+ if (!(this._input instanceof Polygon || this._input instanceof MultiPolygon || this._input instanceof GeometryCollection)) {
+ return null
+ }
+ var inputCurve = this.getPolygonLines(this._input);
+ this.checkMinimumDistance(inputCurve, this._result, this._minValidDistance);
+ if (!this._isValid) { return null }
+ this.checkMaximumDistance(inputCurve, this._result, this._maxValidDistance);
+ };
+ BufferDistanceValidator.prototype.getErrorIndicator = function getErrorIndicator () {
+ return this._errorIndicator
+ };
+ BufferDistanceValidator.prototype.checkMinimumDistance = function checkMinimumDistance (g1, g2, minDist) {
+ var distOp = new DistanceOp(g1, g2, minDist);
+ this._minDistanceFound = distOp.distance();
+ if (this._minDistanceFound < minDist) {
+ this._isValid = false;
+ var pts = distOp.nearestPoints();
+ this._errorLocation = distOp.nearestPoints()[1];
+ this._errorIndicator = g1.getFactory().createLineString(pts);
+ this._errMsg = 'Distance between buffer curve and input is too small (' + this._minDistanceFound + ' at ' + WKTWriter.toLineString(pts[0], pts[1]) + ' )';
+ }
+ };
+ BufferDistanceValidator.prototype.checkPositiveValid = function checkPositiveValid () {
+ var bufCurve = this._result.getBoundary();
+ this.checkMinimumDistance(this._input, bufCurve, this._minValidDistance);
+ if (!this._isValid) { return null }
+ this.checkMaximumDistance(this._input, bufCurve, this._maxValidDistance);
+ };
+ BufferDistanceValidator.prototype.getErrorLocation = function getErrorLocation () {
+ return this._errorLocation
+ };
+ BufferDistanceValidator.prototype.getPolygonLines = function getPolygonLines (g) {
+ var lines = new ArrayList();
+ var lineExtracter = new LinearComponentExtracter(lines);
+ var polys = PolygonExtracter.getPolygons(g);
+ for (var i = polys.iterator(); i.hasNext();) {
+ var poly = i.next();
+ poly.apply(lineExtracter);
+ }
+ return g.getFactory().buildGeometry(lines)
+ };
+ BufferDistanceValidator.prototype.getErrorMessage = function getErrorMessage () {
+ return this._errMsg
+ };
+ BufferDistanceValidator.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ BufferDistanceValidator.prototype.getClass = function getClass () {
+ return BufferDistanceValidator
+ };
+ staticAccessors$37.VERBOSE.get = function () { return false };
+ staticAccessors$37.MAX_DISTANCE_DIFF_FRAC.get = function () { return 0.012 };
+
+ Object.defineProperties( BufferDistanceValidator, staticAccessors$37 );
+
+ var BufferResultValidator = function BufferResultValidator (input, distance, result) {
+ this._isValid = true;
+ this._errorMsg = null;
+ this._errorLocation = null;
+ this._errorIndicator = null;
+ this._input = input || null;
+ this._distance = distance || null;
+ this._result = result || null;
+ };
+
+ var staticAccessors$40 = { VERBOSE: { configurable: true },MAX_ENV_DIFF_FRAC: { configurable: true } };
+ BufferResultValidator.prototype.isValid = function isValid () {
+ this.checkPolygonal();
+ if (!this._isValid) { return this._isValid }
+ this.checkExpectedEmpty();
+ if (!this._isValid) { return this._isValid }
+ this.checkEnvelope();
+ if (!this._isValid) { return this._isValid }
+ this.checkArea();
+ if (!this._isValid) { return this._isValid }
+ this.checkDistance();
+ return this._isValid
+ };
+ BufferResultValidator.prototype.checkEnvelope = function checkEnvelope () {
+ if (this._distance < 0.0) { return null }
+ var padding = this._distance * BufferResultValidator.MAX_ENV_DIFF_FRAC;
+ if (padding === 0.0) { padding = 0.001; }
+ var expectedEnv = new Envelope(this._input.getEnvelopeInternal());
+ expectedEnv.expandBy(this._distance);
+ var bufEnv = new Envelope(this._result.getEnvelopeInternal());
+ bufEnv.expandBy(padding);
+ if (!bufEnv.contains(expectedEnv)) {
+ this._isValid = false;
+ this._errorMsg = 'Buffer envelope is incorrect';
+ this._errorIndicator = this._input.getFactory().toGeometry(bufEnv);
+ }
+ this.report('Envelope');
+ };
+ BufferResultValidator.prototype.checkDistance = function checkDistance () {
+ var distValid = new BufferDistanceValidator(this._input, this._distance, this._result);
+ if (!distValid.isValid()) {
+ this._isValid = false;
+ this._errorMsg = distValid.getErrorMessage();
+ this._errorLocation = distValid.getErrorLocation();
+ this._errorIndicator = distValid.getErrorIndicator();
+ }
+ this.report('Distance');
+ };
+ BufferResultValidator.prototype.checkArea = function checkArea () {
+ var inputArea = this._input.getArea();
+ var resultArea = this._result.getArea();
+ if (this._distance > 0.0 && inputArea > resultArea) {
+ this._isValid = false;
+ this._errorMsg = 'Area of positive buffer is smaller than input';
+ this._errorIndicator = this._result;
+ }
+ if (this._distance < 0.0 && inputArea < resultArea) {
+ this._isValid = false;
+ this._errorMsg = 'Area of negative buffer is larger than input';
+ this._errorIndicator = this._result;
+ }
+ this.report('Area');
+ };
+ BufferResultValidator.prototype.checkPolygonal = function checkPolygonal () {
+ if (!(this._result instanceof Polygon || this._result instanceof MultiPolygon)) { this._isValid = false; }
+ this._errorMsg = 'Result is not polygonal';
+ this._errorIndicator = this._result;
+ this.report('Polygonal');
+ };
+ BufferResultValidator.prototype.getErrorIndicator = function getErrorIndicator () {
+ return this._errorIndicator
+ };
+ BufferResultValidator.prototype.getErrorLocation = function getErrorLocation () {
+ return this._errorLocation
+ };
+ BufferResultValidator.prototype.checkExpectedEmpty = function checkExpectedEmpty () {
+ if (this._input.getDimension() >= 2) { return null }
+ if (this._distance > 0.0) { return null }
+ if (!this._result.isEmpty()) {
+ this._isValid = false;
+ this._errorMsg = 'Result is non-empty';
+ this._errorIndicator = this._result;
+ }
+ this.report('ExpectedEmpty');
+ };
+ BufferResultValidator.prototype.report = function report (checkName) {
+ if (!BufferResultValidator.VERBOSE) { return null }
+ System.out.println('Check ' + checkName + ': ' + (this._isValid ? 'passed' : 'FAILED'));
+ };
+ BufferResultValidator.prototype.getErrorMessage = function getErrorMessage () {
+ return this._errorMsg
+ };
+ BufferResultValidator.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ BufferResultValidator.prototype.getClass = function getClass () {
+ return BufferResultValidator
+ };
+ BufferResultValidator.isValidMsg = function isValidMsg (g, distance, result) {
+ var validator = new BufferResultValidator(g, distance, result);
+ if (!validator.isValid()) { return validator.getErrorMessage() }
+ return null
+ };
+ BufferResultValidator.isValid = function isValid (g, distance, result) {
+ var validator = new BufferResultValidator(g, distance, result);
+ if (validator.isValid()) { return true }
+ return false
+ };
+ staticAccessors$40.VERBOSE.get = function () { return false };
+ staticAccessors$40.MAX_ENV_DIFF_FRAC.get = function () { return 0.012 };
+
+ Object.defineProperties( BufferResultValidator, staticAccessors$40 );
+
+ // operation.buffer
+
+ var BasicSegmentString = function BasicSegmentString () {
+ this._pts = null;
+ this._data = null;
+ var pts = arguments[0];
+ var data = arguments[1];
+ this._pts = pts;
+ this._data = data;
+ };
+ BasicSegmentString.prototype.getCoordinates = function getCoordinates () {
+ return this._pts
+ };
+ BasicSegmentString.prototype.size = function size () {
+ return this._pts.length
+ };
+ BasicSegmentString.prototype.getCoordinate = function getCoordinate (i) {
+ return this._pts[i]
+ };
+ BasicSegmentString.prototype.isClosed = function isClosed () {
+ return this._pts[0].equals(this._pts[this._pts.length - 1])
+ };
+ BasicSegmentString.prototype.getSegmentOctant = function getSegmentOctant (index) {
+ if (index === this._pts.length - 1) { return -1 }
+ return Octant.octant(this.getCoordinate(index), this.getCoordinate(index + 1))
+ };
+ BasicSegmentString.prototype.setData = function setData (data) {
+ this._data = data;
+ };
+ BasicSegmentString.prototype.getData = function getData () {
+ return this._data
+ };
+ BasicSegmentString.prototype.toString = function toString () {
+ return WKTWriter.toLineString(new CoordinateArraySequence(this._pts))
+ };
+ BasicSegmentString.prototype.interfaces_ = function interfaces_ () {
+ return [SegmentString]
+ };
+ BasicSegmentString.prototype.getClass = function getClass () {
+ return BasicSegmentString
+ };
+
+ var InteriorIntersectionFinder = function InteriorIntersectionFinder () {
+ this._findAllIntersections = false;
+ this._isCheckEndSegmentsOnly = false;
+ this._li = null;
+ this._interiorIntersection = null;
+ this._intSegments = null;
+ this._intersections = new ArrayList();
+ this._intersectionCount = 0;
+ this._keepIntersections = true;
+ var li = arguments[0];
+ this._li = li;
+ this._interiorIntersection = null;
+ };
+ InteriorIntersectionFinder.prototype.getInteriorIntersection = function getInteriorIntersection () {
+ return this._interiorIntersection
+ };
+ InteriorIntersectionFinder.prototype.setCheckEndSegmentsOnly = function setCheckEndSegmentsOnly (isCheckEndSegmentsOnly) {
+ this._isCheckEndSegmentsOnly = isCheckEndSegmentsOnly;
+ };
+ InteriorIntersectionFinder.prototype.getIntersectionSegments = function getIntersectionSegments () {
+ return this._intSegments
+ };
+ InteriorIntersectionFinder.prototype.count = function count () {
+ return this._intersectionCount
+ };
+ InteriorIntersectionFinder.prototype.getIntersections = function getIntersections () {
+ return this._intersections
+ };
+ InteriorIntersectionFinder.prototype.setFindAllIntersections = function setFindAllIntersections (findAllIntersections) {
+ this._findAllIntersections = findAllIntersections;
+ };
+ InteriorIntersectionFinder.prototype.setKeepIntersections = function setKeepIntersections (keepIntersections) {
+ this._keepIntersections = keepIntersections;
+ };
+ InteriorIntersectionFinder.prototype.processIntersections = function processIntersections (e0, segIndex0, e1, segIndex1) {
+ if (!this._findAllIntersections && this.hasIntersection()) { return null }
+ if (e0 === e1 && segIndex0 === segIndex1) { return null }
+ if (this._isCheckEndSegmentsOnly) {
+ var isEndSegPresent = this.isEndSegment(e0, segIndex0) || this.isEndSegment(e1, segIndex1);
+ if (!isEndSegPresent) { return null }
+ }
+ var p00 = e0.getCoordinates()[segIndex0];
+ var p01 = e0.getCoordinates()[segIndex0 + 1];
+ var p10 = e1.getCoordinates()[segIndex1];
+ var p11 = e1.getCoordinates()[segIndex1 + 1];
+ this._li.computeIntersection(p00, p01, p10, p11);
+ if (this._li.hasIntersection()) {
+ if (this._li.isInteriorIntersection()) {
+ this._intSegments = new Array(4).fill(null);
+ this._intSegments[0] = p00;
+ this._intSegments[1] = p01;
+ this._intSegments[2] = p10;
+ this._intSegments[3] = p11;
+ this._interiorIntersection = this._li.getIntersection(0);
+ if (this._keepIntersections) { this._intersections.add(this._interiorIntersection); }
+ this._intersectionCount++;
+ }
+ }
+ };
+ InteriorIntersectionFinder.prototype.isEndSegment = function isEndSegment (segStr, index) {
+ if (index === 0) { return true }
+ if (index >= segStr.size() - 2) { return true }
+ return false
+ };
+ InteriorIntersectionFinder.prototype.hasIntersection = function hasIntersection () {
+ return this._interiorIntersection !== null
+ };
+ InteriorIntersectionFinder.prototype.isDone = function isDone () {
+ if (this._findAllIntersections) { return false }
+ return this._interiorIntersection !== null
+ };
+ InteriorIntersectionFinder.prototype.interfaces_ = function interfaces_ () {
+ return [SegmentIntersector]
+ };
+ InteriorIntersectionFinder.prototype.getClass = function getClass () {
+ return InteriorIntersectionFinder
+ };
+ InteriorIntersectionFinder.createAllIntersectionsFinder = function createAllIntersectionsFinder (li) {
+ var finder = new InteriorIntersectionFinder(li);
+ finder.setFindAllIntersections(true);
+ return finder
+ };
+ InteriorIntersectionFinder.createAnyIntersectionFinder = function createAnyIntersectionFinder (li) {
+ return new InteriorIntersectionFinder(li)
+ };
+ InteriorIntersectionFinder.createIntersectionCounter = function createIntersectionCounter (li) {
+ var finder = new InteriorIntersectionFinder(li);
+ finder.setFindAllIntersections(true);
+ finder.setKeepIntersections(false);
+ return finder
+ };
+
+ var FastNodingValidator = function FastNodingValidator () {
+ this._li = new RobustLineIntersector();
+ this._segStrings = null;
+ this._findAllIntersections = false;
+ this._segInt = null;
+ this._isValid = true;
+ var segStrings = arguments[0];
+ this._segStrings = segStrings;
+ };
+ FastNodingValidator.prototype.execute = function execute () {
+ if (this._segInt !== null) { return null }
+ this.checkInteriorIntersections();
+ };
+ FastNodingValidator.prototype.getIntersections = function getIntersections () {
+ return this._segInt.getIntersections()
+ };
+ FastNodingValidator.prototype.isValid = function isValid () {
+ this.execute();
+ return this._isValid
+ };
+ FastNodingValidator.prototype.setFindAllIntersections = function setFindAllIntersections (findAllIntersections) {
+ this._findAllIntersections = findAllIntersections;
+ };
+ FastNodingValidator.prototype.checkInteriorIntersections = function checkInteriorIntersections () {
+ this._isValid = true;
+ this._segInt = new InteriorIntersectionFinder(this._li);
+ this._segInt.setFindAllIntersections(this._findAllIntersections);
+ var noder = new MCIndexNoder();
+ noder.setSegmentIntersector(this._segInt);
+ noder.computeNodes(this._segStrings);
+ if (this._segInt.hasIntersection()) {
+ this._isValid = false;
+ return null
+ }
+ };
+ FastNodingValidator.prototype.checkValid = function checkValid () {
+ this.execute();
+ if (!this._isValid) { throw new TopologyException(this.getErrorMessage(), this._segInt.getInteriorIntersection()) }
+ };
+ FastNodingValidator.prototype.getErrorMessage = function getErrorMessage () {
+ if (this._isValid) { return 'no intersections found' }
+ var intSegs = this._segInt.getIntersectionSegments();
+ return 'found non-noded intersection between ' + WKTWriter.toLineString(intSegs[0], intSegs[1]) + ' and ' + WKTWriter.toLineString(intSegs[2], intSegs[3])
+ };
+ FastNodingValidator.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ FastNodingValidator.prototype.getClass = function getClass () {
+ return FastNodingValidator
+ };
+ FastNodingValidator.computeIntersections = function computeIntersections (segStrings) {
+ var nv = new FastNodingValidator(segStrings);
+ nv.setFindAllIntersections(true);
+ nv.isValid();
+ return nv.getIntersections()
+ };
+
+ var EdgeNodingValidator = function EdgeNodingValidator () {
+ this._nv = null;
+ var edges = arguments[0];
+ this._nv = new FastNodingValidator(EdgeNodingValidator.toSegmentStrings(edges));
+ };
+ EdgeNodingValidator.prototype.checkValid = function checkValid () {
+ this._nv.checkValid();
+ };
+ EdgeNodingValidator.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ EdgeNodingValidator.prototype.getClass = function getClass () {
+ return EdgeNodingValidator
+ };
+ EdgeNodingValidator.toSegmentStrings = function toSegmentStrings (edges) {
+ var segStrings = new ArrayList();
+ for (var i = edges.iterator(); i.hasNext();) {
+ var e = i.next();
+ segStrings.add(new BasicSegmentString(e.getCoordinates(), e));
+ }
+ return segStrings
+ };
+ EdgeNodingValidator.checkValid = function checkValid (edges) {
+ var validator = new EdgeNodingValidator(edges);
+ validator.checkValid();
+ };
+
+ var GeometryCollectionMapper = function GeometryCollectionMapper (mapOp) {
+ this._mapOp = mapOp;
+ };
+ GeometryCollectionMapper.prototype.map = function map (gc) {
+ var this$1 = this;
+
+ var mapped = new ArrayList();
+ for (var i = 0; i < gc.getNumGeometries(); i++) {
+ var g = this$1._mapOp.map(gc.getGeometryN(i));
+ if (!g.isEmpty()) { mapped.add(g); }
+ }
+ return gc.getFactory().createGeometryCollection(GeometryFactory.toGeometryArray(mapped))
+ };
+ GeometryCollectionMapper.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ GeometryCollectionMapper.prototype.getClass = function getClass () {
+ return GeometryCollectionMapper
+ };
+ GeometryCollectionMapper.map = function map (gc, op) {
+ var mapper = new GeometryCollectionMapper(op);
+ return mapper.map(gc)
+ };
+
+ var LineBuilder = function LineBuilder () {
+ this._op = null;
+ this._geometryFactory = null;
+ this._ptLocator = null;
+ this._lineEdgesList = new ArrayList();
+ this._resultLineList = new ArrayList();
+ var op = arguments[0];
+ var geometryFactory = arguments[1];
+ var ptLocator = arguments[2];
+ this._op = op;
+ this._geometryFactory = geometryFactory;
+ this._ptLocator = ptLocator;
+ };
+ LineBuilder.prototype.collectLines = function collectLines (opCode) {
+ var this$1 = this;
+
+ for (var it = this._op.getGraph().getEdgeEnds().iterator(); it.hasNext();) {
+ var de = it.next();
+ this$1.collectLineEdge(de, opCode, this$1._lineEdgesList);
+ this$1.collectBoundaryTouchEdge(de, opCode, this$1._lineEdgesList);
+ }
+ };
+ LineBuilder.prototype.labelIsolatedLine = function labelIsolatedLine (e, targetIndex) {
+ var loc = this._ptLocator.locate(e.getCoordinate(), this._op.getArgGeometry(targetIndex));
+ e.getLabel().setLocation(targetIndex, loc);
+ };
+ LineBuilder.prototype.build = function build (opCode) {
+ this.findCoveredLineEdges();
+ this.collectLines(opCode);
+ this.buildLines(opCode);
+ return this._resultLineList
+ };
+ LineBuilder.prototype.collectLineEdge = function collectLineEdge (de, opCode, edges) {
+ var label = de.getLabel();
+ var e = de.getEdge();
+ if (de.isLineEdge()) {
+ if (!de.isVisited() && OverlayOp.isResultOfOp(label, opCode) && !e.isCovered()) {
+ edges.add(e);
+ de.setVisitedEdge(true);
+ }
+ }
+ };
+ LineBuilder.prototype.findCoveredLineEdges = function findCoveredLineEdges () {
+ var this$1 = this;
+
+ for (var nodeit = this._op.getGraph().getNodes().iterator(); nodeit.hasNext();) {
+ var node = nodeit.next();
+ node.getEdges().findCoveredLineEdges();
+ }
+ for (var it = this._op.getGraph().getEdgeEnds().iterator(); it.hasNext();) {
+ var de = it.next();
+ var e = de.getEdge();
+ if (de.isLineEdge() && !e.isCoveredSet()) {
+ var isCovered = this$1._op.isCoveredByA(de.getCoordinate());
+ e.setCovered(isCovered);
+ }
+ }
+ };
+ LineBuilder.prototype.labelIsolatedLines = function labelIsolatedLines (edgesList) {
+ var this$1 = this;
+
+ for (var it = edgesList.iterator(); it.hasNext();) {
+ var e = it.next();
+ var label = e.getLabel();
+ if (e.isIsolated()) {
+ if (label.isNull(0)) { this$1.labelIsolatedLine(e, 0); } else { this$1.labelIsolatedLine(e, 1); }
+ }
+ }
+ };
+ LineBuilder.prototype.buildLines = function buildLines (opCode) {
+ var this$1 = this;
+
+ for (var it = this._lineEdgesList.iterator(); it.hasNext();) {
+ var e = it.next();
+ // const label = e.getLabel()
+ var line = this$1._geometryFactory.createLineString(e.getCoordinates());
+ this$1._resultLineList.add(line);
+ e.setInResult(true);
+ }
+ };
+ LineBuilder.prototype.collectBoundaryTouchEdge = function collectBoundaryTouchEdge (de, opCode, edges) {
+ var label = de.getLabel();
+ if (de.isLineEdge()) { return null }
+ if (de.isVisited()) { return null }
+ if (de.isInteriorAreaEdge()) { return null }
+ if (de.getEdge().isInResult()) { return null }
+ Assert.isTrue(!(de.isInResult() || de.getSym().isInResult()) || !de.getEdge().isInResult());
+ if (OverlayOp.isResultOfOp(label, opCode) && opCode === OverlayOp.INTERSECTION) {
+ edges.add(de.getEdge());
+ de.setVisitedEdge(true);
+ }
+ };
+ LineBuilder.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ LineBuilder.prototype.getClass = function getClass () {
+ return LineBuilder
+ };
+
+ var PointBuilder = function PointBuilder () {
+ this._op = null;
+ this._geometryFactory = null;
+ this._resultPointList = new ArrayList();
+ var op = arguments[0];
+ var geometryFactory = arguments[1];
+ // const ptLocator = arguments[2]
+ this._op = op;
+ this._geometryFactory = geometryFactory;
+ };
+ PointBuilder.prototype.filterCoveredNodeToPoint = function filterCoveredNodeToPoint (n) {
+ var coord = n.getCoordinate();
+ if (!this._op.isCoveredByLA(coord)) {
+ var pt = this._geometryFactory.createPoint(coord);
+ this._resultPointList.add(pt);
+ }
+ };
+ PointBuilder.prototype.extractNonCoveredResultNodes = function extractNonCoveredResultNodes (opCode) {
+ var this$1 = this;
+
+ for (var nodeit = this._op.getGraph().getNodes().iterator(); nodeit.hasNext();) {
+ var n = nodeit.next();
+ if (n.isInResult()) { continue }
+ if (n.isIncidentEdgeInResult()) { continue }
+ if (n.getEdges().getDegree() === 0 || opCode === OverlayOp.INTERSECTION) {
+ var label = n.getLabel();
+ if (OverlayOp.isResultOfOp(label, opCode)) {
+ this$1.filterCoveredNodeToPoint(n);
+ }
+ }
+ }
+ };
+ PointBuilder.prototype.build = function build (opCode) {
+ this.extractNonCoveredResultNodes(opCode);
+ return this._resultPointList
+ };
+ PointBuilder.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ PointBuilder.prototype.getClass = function getClass () {
+ return PointBuilder
+ };
+
+ var GeometryTransformer = function GeometryTransformer () {
+ this._inputGeom = null;
+ this._factory = null;
+ this._pruneEmptyGeometry = true;
+ this._preserveGeometryCollectionType = true;
+ this._preserveCollections = false;
+ this._preserveType = false;
+ };
+ GeometryTransformer.prototype.transformPoint = function transformPoint (geom, parent) {
+ return this._factory.createPoint(this.transformCoordinates(geom.getCoordinateSequence(), geom))
+ };
+ GeometryTransformer.prototype.transformPolygon = function transformPolygon (geom, parent) {
+ var this$1 = this;
+
+ var isAllValidLinearRings = true;
+ var shell = this.transformLinearRing(geom.getExteriorRing(), geom);
+ if (shell === null || !(shell instanceof LinearRing) || shell.isEmpty()) { isAllValidLinearRings = false; }
+ var holes = new ArrayList();
+ for (var i = 0; i < geom.getNumInteriorRing(); i++) {
+ var hole = this$1.transformLinearRing(geom.getInteriorRingN(i), geom);
+ if (hole === null || hole.isEmpty()) {
+ continue
+ }
+ if (!(hole instanceof LinearRing)) { isAllValidLinearRings = false; }
+ holes.add(hole);
+ }
+ if (isAllValidLinearRings) { return this._factory.createPolygon(shell, holes.toArray([])); } else {
+ var components = new ArrayList();
+ if (shell !== null) { components.add(shell); }
+ components.addAll(holes);
+ return this._factory.buildGeometry(components)
+ }
+ };
+ GeometryTransformer.prototype.createCoordinateSequence = function createCoordinateSequence (coords) {
+ return this._factory.getCoordinateSequenceFactory().create(coords)
+ };
+ GeometryTransformer.prototype.getInputGeometry = function getInputGeometry () {
+ return this._inputGeom
+ };
+ GeometryTransformer.prototype.transformMultiLineString = function transformMultiLineString (geom, parent) {
+ var this$1 = this;
+
+ var transGeomList = new ArrayList();
+ for (var i = 0; i < geom.getNumGeometries(); i++) {
+ var transformGeom = this$1.transformLineString(geom.getGeometryN(i), geom);
+ if (transformGeom === null) { continue }
+ if (transformGeom.isEmpty()) { continue }
+ transGeomList.add(transformGeom);
+ }
+ return this._factory.buildGeometry(transGeomList)
+ };
+ GeometryTransformer.prototype.transformCoordinates = function transformCoordinates (coords, parent) {
+ return this.copy(coords)
+ };
+ GeometryTransformer.prototype.transformLineString = function transformLineString (geom, parent) {
+ return this._factory.createLineString(this.transformCoordinates(geom.getCoordinateSequence(), geom))
+ };
+ GeometryTransformer.prototype.transformMultiPoint = function transformMultiPoint (geom, parent) {
+ var this$1 = this;
+
+ var transGeomList = new ArrayList();
+ for (var i = 0; i < geom.getNumGeometries(); i++) {
+ var transformGeom = this$1.transformPoint(geom.getGeometryN(i), geom);
+ if (transformGeom === null) { continue }
+ if (transformGeom.isEmpty()) { continue }
+ transGeomList.add(transformGeom);
+ }
+ return this._factory.buildGeometry(transGeomList)
+ };
+ GeometryTransformer.prototype.transformMultiPolygon = function transformMultiPolygon (geom, parent) {
+ var this$1 = this;
+
+ var transGeomList = new ArrayList();
+ for (var i = 0; i < geom.getNumGeometries(); i++) {
+ var transformGeom = this$1.transformPolygon(geom.getGeometryN(i), geom);
+ if (transformGeom === null) { continue }
+ if (transformGeom.isEmpty()) { continue }
+ transGeomList.add(transformGeom);
+ }
+ return this._factory.buildGeometry(transGeomList)
+ };
+ GeometryTransformer.prototype.copy = function copy (seq) {
+ return seq.copy()
+ };
+ GeometryTransformer.prototype.transformGeometryCollection = function transformGeometryCollection (geom, parent) {
+ var this$1 = this;
+
+ var transGeomList = new ArrayList();
+ for (var i = 0; i < geom.getNumGeometries(); i++) {
+ var transformGeom = this$1.transform(geom.getGeometryN(i));
+ if (transformGeom === null) { continue }
+ if (this$1._pruneEmptyGeometry && transformGeom.isEmpty()) { continue }
+ transGeomList.add(transformGeom);
+ }
+ if (this._preserveGeometryCollectionType) { return this._factory.createGeometryCollection(GeometryFactory.toGeometryArray(transGeomList)) }
+ return this._factory.buildGeometry(transGeomList)
+ };
+ GeometryTransformer.prototype.transform = function transform (inputGeom) {
+ this._inputGeom = inputGeom;
+ this._factory = inputGeom.getFactory();
+ if (inputGeom instanceof Point) { return this.transformPoint(inputGeom, null) }
+ if (inputGeom instanceof MultiPoint) { return this.transformMultiPoint(inputGeom, null) }
+ if (inputGeom instanceof LinearRing) { return this.transformLinearRing(inputGeom, null) }
+ if (inputGeom instanceof LineString) { return this.transformLineString(inputGeom, null) }
+ if (inputGeom instanceof MultiLineString) { return this.transformMultiLineString(inputGeom, null) }
+ if (inputGeom instanceof Polygon) { return this.transformPolygon(inputGeom, null) }
+ if (inputGeom instanceof MultiPolygon) { return this.transformMultiPolygon(inputGeom, null) }
+ if (inputGeom instanceof GeometryCollection) { return this.transformGeometryCollection(inputGeom, null) }
+ throw new IllegalArgumentException('Unknown Geometry subtype: ' + inputGeom.getClass().getName())
+ };
+ GeometryTransformer.prototype.transformLinearRing = function transformLinearRing (geom, parent) {
+ var seq = this.transformCoordinates(geom.getCoordinateSequence(), geom);
+ if (seq === null) { return this._factory.createLinearRing(null) }
+ var seqSize = seq.size();
+ if (seqSize > 0 && seqSize < 4 && !this._preserveType) { return this._factory.createLineString(seq) }
+ return this._factory.createLinearRing(seq)
+ };
+ GeometryTransformer.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ GeometryTransformer.prototype.getClass = function getClass () {
+ return GeometryTransformer
+ };
+
+ var LineStringSnapper = function LineStringSnapper () {
+ this._snapTolerance = 0.0;
+ this._srcPts = null;
+ this._seg = new LineSegment();
+ this._allowSnappingToSourceVertices = false;
+ this._isClosed = false;
+ if (arguments[0] instanceof LineString && typeof arguments[1] === 'number') {
+ var srcLine = arguments[0];
+ var snapTolerance = arguments[1];
+ LineStringSnapper.call(this, srcLine.getCoordinates(), snapTolerance);
+ } else if (arguments[0] instanceof Array && typeof arguments[1] === 'number') {
+ var srcPts = arguments[0];
+ var snapTolerance$1 = arguments[1];
+ this._srcPts = srcPts;
+ this._isClosed = LineStringSnapper.isClosed(srcPts);
+ this._snapTolerance = snapTolerance$1;
+ }
+ };
+ LineStringSnapper.prototype.snapVertices = function snapVertices (srcCoords, snapPts) {
+ var this$1 = this;
+
+ var end = this._isClosed ? srcCoords.size() - 1 : srcCoords.size();
+ for (var i = 0; i < end; i++) {
+ var srcPt = srcCoords.get(i);
+ var snapVert = this$1.findSnapForVertex(srcPt, snapPts);
+ if (snapVert !== null) {
+ srcCoords.set(i, new Coordinate(snapVert));
+ if (i === 0 && this$1._isClosed) { srcCoords.set(srcCoords.size() - 1, new Coordinate(snapVert)); }
+ }
+ }
+ };
+ LineStringSnapper.prototype.findSnapForVertex = function findSnapForVertex (pt, snapPts) {
+ var this$1 = this;
+
+ for (var i = 0; i < snapPts.length; i++) {
+ if (pt.equals2D(snapPts[i])) { return null }
+ if (pt.distance(snapPts[i]) < this$1._snapTolerance) { return snapPts[i] }
+ }
+ return null
+ };
+ LineStringSnapper.prototype.snapTo = function snapTo (snapPts) {
+ var coordList = new CoordinateList(this._srcPts);
+ this.snapVertices(coordList, snapPts);
+ this.snapSegments(coordList, snapPts);
+ var newPts = coordList.toCoordinateArray();
+ return newPts
+ };
+ LineStringSnapper.prototype.snapSegments = function snapSegments (srcCoords, snapPts) {
+ var this$1 = this;
+
+ if (snapPts.length === 0) { return null }
+ var distinctPtCount = snapPts.length;
+ if (snapPts[0].equals2D(snapPts[snapPts.length - 1])) { distinctPtCount = snapPts.length - 1; }
+ for (var i = 0; i < distinctPtCount; i++) {
+ var snapPt = snapPts[i];
+ var index = this$1.findSegmentIndexToSnap(snapPt, srcCoords);
+ if (index >= 0) {
+ srcCoords.add(index + 1, new Coordinate(snapPt), false);
+ }
+ }
+ };
+ LineStringSnapper.prototype.findSegmentIndexToSnap = function findSegmentIndexToSnap (snapPt, srcCoords) {
+ var this$1 = this;
+
+ var minDist = Double.MAX_VALUE;
+ var snapIndex = -1;
+ for (var i = 0; i < srcCoords.size() - 1; i++) {
+ this$1._seg.p0 = srcCoords.get(i);
+ this$1._seg.p1 = srcCoords.get(i + 1);
+ if (this$1._seg.p0.equals2D(snapPt) || this$1._seg.p1.equals2D(snapPt)) {
+ if (this$1._allowSnappingToSourceVertices) { continue; } else { return -1 }
+ }
+ var dist = this$1._seg.distance(snapPt);
+ if (dist < this$1._snapTolerance && dist < minDist) {
+ minDist = dist;
+ snapIndex = i;
+ }
+ }
+ return snapIndex
+ };
+ LineStringSnapper.prototype.setAllowSnappingToSourceVertices = function setAllowSnappingToSourceVertices (allowSnappingToSourceVertices) {
+ this._allowSnappingToSourceVertices = allowSnappingToSourceVertices;
+ };
+ LineStringSnapper.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ LineStringSnapper.prototype.getClass = function getClass () {
+ return LineStringSnapper
+ };
+ LineStringSnapper.isClosed = function isClosed (pts) {
+ if (pts.length <= 1) { return false }
+ return pts[0].equals2D(pts[pts.length - 1])
+ };
+
+ var GeometrySnapper = function GeometrySnapper (srcGeom) {
+ this._srcGeom = srcGeom || null;
+ };
+
+ var staticAccessors$41 = { SNAP_PRECISION_FACTOR: { configurable: true } };
+ GeometrySnapper.prototype.snapTo = function snapTo (snapGeom, snapTolerance) {
+ var snapPts = this.extractTargetCoordinates(snapGeom);
+ var snapTrans = new SnapTransformer(snapTolerance, snapPts);
+ return snapTrans.transform(this._srcGeom)
+ };
+ GeometrySnapper.prototype.snapToSelf = function snapToSelf (snapTolerance, cleanResult) {
+ var snapPts = this.extractTargetCoordinates(this._srcGeom);
+ var snapTrans = new SnapTransformer(snapTolerance, snapPts, true);
+ var snappedGeom = snapTrans.transform(this._srcGeom);
+ var result = snappedGeom;
+ if (cleanResult && hasInterface(result, Polygonal)) {
+ result = snappedGeom.buffer(0);
+ }
+ return result
+ };
+ GeometrySnapper.prototype.computeSnapTolerance = function computeSnapTolerance (ringPts) {
+ var minSegLen = this.computeMinimumSegmentLength(ringPts);
+ var snapTol = minSegLen / 10;
+ return snapTol
+ };
+ GeometrySnapper.prototype.extractTargetCoordinates = function extractTargetCoordinates (g) {
+ var ptSet = new TreeSet();
+ var pts = g.getCoordinates();
+ for (var i = 0; i < pts.length; i++) {
+ ptSet.add(pts[i]);
+ }
+ return ptSet.toArray(new Array(0).fill(null))
+ };
+ GeometrySnapper.prototype.computeMinimumSegmentLength = function computeMinimumSegmentLength (pts) {
+ var minSegLen = Double.MAX_VALUE;
+ for (var i = 0; i < pts.length - 1; i++) {
+ var segLen = pts[i].distance(pts[i + 1]);
+ if (segLen < minSegLen) { minSegLen = segLen; }
+ }
+ return minSegLen
+ };
+ GeometrySnapper.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ GeometrySnapper.prototype.getClass = function getClass () {
+ return GeometrySnapper
+ };
+ GeometrySnapper.snap = function snap (g0, g1, snapTolerance) {
+ var snapGeom = new Array(2).fill(null);
+ var snapper0 = new GeometrySnapper(g0);
+ snapGeom[0] = snapper0.snapTo(g1, snapTolerance);
+ var snapper1 = new GeometrySnapper(g1);
+ snapGeom[1] = snapper1.snapTo(snapGeom[0], snapTolerance);
+ return snapGeom
+ };
+ GeometrySnapper.computeOverlaySnapTolerance = function computeOverlaySnapTolerance () {
+ if (arguments.length === 1) {
+ var g = arguments[0];
+ var snapTolerance = GeometrySnapper.computeSizeBasedSnapTolerance(g);
+ var pm = g.getPrecisionModel();
+ if (pm.getType() === PrecisionModel.FIXED) {
+ var fixedSnapTol = 1 / pm.getScale() * 2 / 1.415;
+ if (fixedSnapTol > snapTolerance) { snapTolerance = fixedSnapTol; }
+ }
+ return snapTolerance
+ } else if (arguments.length === 2) {
+ var g0 = arguments[0];
+ var g1 = arguments[1];
+ return Math.min(GeometrySnapper.computeOverlaySnapTolerance(g0), GeometrySnapper.computeOverlaySnapTolerance(g1))
+ }
+ };
+ GeometrySnapper.computeSizeBasedSnapTolerance = function computeSizeBasedSnapTolerance (g) {
+ var env = g.getEnvelopeInternal();
+ var minDimension = Math.min(env.getHeight(), env.getWidth());
+ var snapTol = minDimension * GeometrySnapper.SNAP_PRECISION_FACTOR;
+ return snapTol
+ };
+ GeometrySnapper.snapToSelf = function snapToSelf (geom, snapTolerance, cleanResult) {
+ var snapper0 = new GeometrySnapper(geom);
+ return snapper0.snapToSelf(snapTolerance, cleanResult)
+ };
+ staticAccessors$41.SNAP_PRECISION_FACTOR.get = function () { return 1e-9 };
+
+ Object.defineProperties( GeometrySnapper, staticAccessors$41 );
+
+ var SnapTransformer = (function (GeometryTransformer$$1) {
+ function SnapTransformer (snapTolerance, snapPts, isSelfSnap) {
+ GeometryTransformer$$1.call(this);
+ this._snapTolerance = snapTolerance || null;
+ this._snapPts = snapPts || null;
+ this._isSelfSnap = (isSelfSnap !== undefined) ? isSelfSnap : false;
+ }
+
+ if ( GeometryTransformer$$1 ) SnapTransformer.__proto__ = GeometryTransformer$$1;
+ SnapTransformer.prototype = Object.create( GeometryTransformer$$1 && GeometryTransformer$$1.prototype );
+ SnapTransformer.prototype.constructor = SnapTransformer;
+ SnapTransformer.prototype.snapLine = function snapLine (srcPts, snapPts) {
+ var snapper = new LineStringSnapper(srcPts, this._snapTolerance);
+ snapper.setAllowSnappingToSourceVertices(this._isSelfSnap);
+ return snapper.snapTo(snapPts)
+ };
+ SnapTransformer.prototype.transformCoordinates = function transformCoordinates (coords, parent) {
+ var srcPts = coords.toCoordinateArray();
+ var newPts = this.snapLine(srcPts, this._snapPts);
+ return this._factory.getCoordinateSequenceFactory().create(newPts)
+ };
+ SnapTransformer.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ SnapTransformer.prototype.getClass = function getClass () {
+ return SnapTransformer
+ };
+
+ return SnapTransformer;
+ }(GeometryTransformer));
+
+ var CommonBits = function CommonBits () {
+ this._isFirst = true;
+ this._commonMantissaBitsCount = 53;
+ this._commonBits = 0;
+ this._commonSignExp = null;
+ };
+ CommonBits.prototype.getCommon = function getCommon () {
+ return Double.longBitsToDouble(this._commonBits)
+ };
+ CommonBits.prototype.add = function add (num) {
+ var numBits = Double.doubleToLongBits(num);
+ if (this._isFirst) {
+ this._commonBits = numBits;
+ this._commonSignExp = CommonBits.signExpBits(this._commonBits);
+ this._isFirst = false;
+ return null
+ }
+ var numSignExp = CommonBits.signExpBits(numBits);
+ if (numSignExp !== this._commonSignExp) {
+ this._commonBits = 0;
+ return null
+ }
+ this._commonMantissaBitsCount = CommonBits.numCommonMostSigMantissaBits(this._commonBits, numBits);
+ this._commonBits = CommonBits.zeroLowerBits(this._commonBits, 64 - (12 + this._commonMantissaBitsCount));
+ };
+ CommonBits.prototype.toString = function toString () {
+ if (arguments.length === 1) {
+ var bits = arguments[0];
+ var x = Double.longBitsToDouble(bits);
+ var numStr = Double.toBinaryString(bits);
+ var padStr = '0000000000000000000000000000000000000000000000000000000000000000' + numStr;
+ var bitStr = padStr.substring(padStr.length - 64);
+ var str = bitStr.substring(0, 1) + ' ' + bitStr.substring(1, 12) + '(exp) ' + bitStr.substring(12) + ' [ ' + x + ' ]';
+ return str
+ }
+ };
+ CommonBits.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ CommonBits.prototype.getClass = function getClass () {
+ return CommonBits
+ };
+ CommonBits.getBit = function getBit (bits, i) {
+ var mask = 1 << i;
+ return (bits & mask) !== 0 ? 1 : 0
+ };
+ CommonBits.signExpBits = function signExpBits (num) {
+ return num >> 52
+ };
+ CommonBits.zeroLowerBits = function zeroLowerBits (bits, nBits) {
+ var invMask = (1 << nBits) - 1;
+ var mask = ~invMask;
+ var zeroed = bits & mask;
+ return zeroed
+ };
+ CommonBits.numCommonMostSigMantissaBits = function numCommonMostSigMantissaBits (num1, num2) {
+ var count = 0;
+ for (var i = 52; i >= 0; i--) {
+ if (CommonBits.getBit(num1, i) !== CommonBits.getBit(num2, i)) { return count }
+ count++;
+ }
+ return 52
+ };
+
+ var CommonBitsRemover = function CommonBitsRemover () {
+ this._commonCoord = null;
+ this._ccFilter = new CommonCoordinateFilter();
+ };
+
+ var staticAccessors$42 = { CommonCoordinateFilter: { configurable: true },Translater: { configurable: true } };
+ CommonBitsRemover.prototype.addCommonBits = function addCommonBits (geom) {
+ var trans = new Translater(this._commonCoord);
+ geom.apply(trans);
+ geom.geometryChanged();
+ };
+ CommonBitsRemover.prototype.removeCommonBits = function removeCommonBits (geom) {
+ if (this._commonCoord.x === 0.0 && this._commonCoord.y === 0.0) { return geom }
+ var invCoord = new Coordinate(this._commonCoord);
+ invCoord.x = -invCoord.x;
+ invCoord.y = -invCoord.y;
+ var trans = new Translater(invCoord);
+ geom.apply(trans);
+ geom.geometryChanged();
+ return geom
+ };
+ CommonBitsRemover.prototype.getCommonCoordinate = function getCommonCoordinate () {
+ return this._commonCoord
+ };
+ CommonBitsRemover.prototype.add = function add (geom) {
+ geom.apply(this._ccFilter);
+ this._commonCoord = this._ccFilter.getCommonCoordinate();
+ };
+ CommonBitsRemover.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ CommonBitsRemover.prototype.getClass = function getClass () {
+ return CommonBitsRemover
+ };
+ staticAccessors$42.CommonCoordinateFilter.get = function () { return CommonCoordinateFilter };
+ staticAccessors$42.Translater.get = function () { return Translater };
+
+ Object.defineProperties( CommonBitsRemover, staticAccessors$42 );
+
+ var CommonCoordinateFilter = function CommonCoordinateFilter () {
+ this._commonBitsX = new CommonBits();
+ this._commonBitsY = new CommonBits();
+ };
+ CommonCoordinateFilter.prototype.filter = function filter (coord) {
+ this._commonBitsX.add(coord.x);
+ this._commonBitsY.add(coord.y);
+ };
+ CommonCoordinateFilter.prototype.getCommonCoordinate = function getCommonCoordinate () {
+ return new Coordinate(this._commonBitsX.getCommon(), this._commonBitsY.getCommon())
+ };
+ CommonCoordinateFilter.prototype.interfaces_ = function interfaces_ () {
+ return [CoordinateFilter]
+ };
+ CommonCoordinateFilter.prototype.getClass = function getClass () {
+ return CommonCoordinateFilter
+ };
+
+ var Translater = function Translater () {
+ this.trans = null;
+ var trans = arguments[0];
+ this.trans = trans;
+ };
+ Translater.prototype.filter = function filter (seq, i) {
+ var xp = seq.getOrdinate(i, 0) + this.trans.x;
+ var yp = seq.getOrdinate(i, 1) + this.trans.y;
+ seq.setOrdinate(i, 0, xp);
+ seq.setOrdinate(i, 1, yp);
+ };
+ Translater.prototype.isDone = function isDone () {
+ return false
+ };
+ Translater.prototype.isGeometryChanged = function isGeometryChanged () {
+ return true
+ };
+ Translater.prototype.interfaces_ = function interfaces_ () {
+ return [CoordinateSequenceFilter]
+ };
+ Translater.prototype.getClass = function getClass () {
+ return Translater
+ };
+
+ var SnapOverlayOp = function SnapOverlayOp (g1, g2) {
+ this._geom = new Array(2).fill(null);
+ this._snapTolerance = null;
+ this._cbr = null;
+ this._geom[0] = g1;
+ this._geom[1] = g2;
+ this.computeSnapTolerance();
+ };
+ SnapOverlayOp.prototype.selfSnap = function selfSnap (geom) {
+ var snapper0 = new GeometrySnapper(geom);
+ var snapGeom = snapper0.snapTo(geom, this._snapTolerance);
+ return snapGeom
+ };
+ SnapOverlayOp.prototype.removeCommonBits = function removeCommonBits (geom) {
+ this._cbr = new CommonBitsRemover();
+ this._cbr.add(geom[0]);
+ this._cbr.add(geom[1]);
+ var remGeom = new Array(2).fill(null);
+ remGeom[0] = this._cbr.removeCommonBits(geom[0].copy());
+ remGeom[1] = this._cbr.removeCommonBits(geom[1].copy());
+ return remGeom
+ };
+ SnapOverlayOp.prototype.prepareResult = function prepareResult (geom) {
+ this._cbr.addCommonBits(geom);
+ return geom
+ };
+ SnapOverlayOp.prototype.getResultGeometry = function getResultGeometry (opCode) {
+ var prepGeom = this.snap(this._geom);
+ var result = OverlayOp.overlayOp(prepGeom[0], prepGeom[1], opCode);
+ return this.prepareResult(result)
+ };
+ SnapOverlayOp.prototype.checkValid = function checkValid (g) {
+ if (!g.isValid()) {
+ System.out.println('Snapped geometry is invalid');
+ }
+ };
+ SnapOverlayOp.prototype.computeSnapTolerance = function computeSnapTolerance () {
+ this._snapTolerance = GeometrySnapper.computeOverlaySnapTolerance(this._geom[0], this._geom[1]);
+ };
+ SnapOverlayOp.prototype.snap = function snap (geom) {
+ var remGeom = this.removeCommonBits(geom);
+ var snapGeom = GeometrySnapper.snap(remGeom[0], remGeom[1], this._snapTolerance);
+ return snapGeom
+ };
+ SnapOverlayOp.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ SnapOverlayOp.prototype.getClass = function getClass () {
+ return SnapOverlayOp
+ };
+ SnapOverlayOp.overlayOp = function overlayOp (g0, g1, opCode) {
+ var op = new SnapOverlayOp(g0, g1);
+ return op.getResultGeometry(opCode)
+ };
+ SnapOverlayOp.union = function union (g0, g1) {
+ return SnapOverlayOp.overlayOp(g0, g1, OverlayOp.UNION)
+ };
+ SnapOverlayOp.intersection = function intersection (g0, g1) {
+ return SnapOverlayOp.overlayOp(g0, g1, OverlayOp.INTERSECTION)
+ };
+ SnapOverlayOp.symDifference = function symDifference (g0, g1) {
+ return SnapOverlayOp.overlayOp(g0, g1, OverlayOp.SYMDIFFERENCE)
+ };
+ SnapOverlayOp.difference = function difference (g0, g1) {
+ return SnapOverlayOp.overlayOp(g0, g1, OverlayOp.DIFFERENCE)
+ };
+
+ var SnapIfNeededOverlayOp = function SnapIfNeededOverlayOp (g1, g2) {
+ this._geom = new Array(2).fill(null);
+ this._geom[0] = g1;
+ this._geom[1] = g2;
+ };
+ SnapIfNeededOverlayOp.prototype.getResultGeometry = function getResultGeometry (opCode) {
+ var result = null;
+ var isSuccess = false;
+ var savedException = null;
+ try {
+ result = OverlayOp.overlayOp(this._geom[0], this._geom[1], opCode);
+ var isValid = true;
+ if (isValid) { isSuccess = true; }
+ } catch (ex) {
+ if (ex instanceof RuntimeException) {
+ savedException = ex;
+ } else { throw ex }
+ } finally {}
+ if (!isSuccess) {
+ try {
+ result = SnapOverlayOp.overlayOp(this._geom[0], this._geom[1], opCode);
+ } catch (ex) {
+ if (ex instanceof RuntimeException) {
+ throw savedException
+ } else { throw ex }
+ } finally {}
+ }
+ return result
+ };
+ SnapIfNeededOverlayOp.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ SnapIfNeededOverlayOp.prototype.getClass = function getClass () {
+ return SnapIfNeededOverlayOp
+ };
+ SnapIfNeededOverlayOp.overlayOp = function overlayOp (g0, g1, opCode) {
+ var op = new SnapIfNeededOverlayOp(g0, g1);
+ return op.getResultGeometry(opCode)
+ };
+ SnapIfNeededOverlayOp.union = function union (g0, g1) {
+ return SnapIfNeededOverlayOp.overlayOp(g0, g1, OverlayOp.UNION)
+ };
+ SnapIfNeededOverlayOp.intersection = function intersection (g0, g1) {
+ return SnapIfNeededOverlayOp.overlayOp(g0, g1, OverlayOp.INTERSECTION)
+ };
+ SnapIfNeededOverlayOp.symDifference = function symDifference (g0, g1) {
+ return SnapIfNeededOverlayOp.overlayOp(g0, g1, OverlayOp.SYMDIFFERENCE)
+ };
+ SnapIfNeededOverlayOp.difference = function difference (g0, g1) {
+ return SnapIfNeededOverlayOp.overlayOp(g0, g1, OverlayOp.DIFFERENCE)
+ };
+
+ var MonotoneChain$2 = function MonotoneChain () {
+ this.mce = null;
+ this.chainIndex = null;
+ var mce = arguments[0];
+ var chainIndex = arguments[1];
+ this.mce = mce;
+ this.chainIndex = chainIndex;
+ };
+ MonotoneChain$2.prototype.computeIntersections = function computeIntersections (mc, si) {
+ this.mce.computeIntersectsForChain(this.chainIndex, mc.mce, mc.chainIndex, si);
+ };
+ MonotoneChain$2.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ MonotoneChain$2.prototype.getClass = function getClass () {
+ return MonotoneChain$2
+ };
+
+ var SweepLineEvent = function SweepLineEvent () {
+ this._label = null;
+ this._xValue = null;
+ this._eventType = null;
+ this._insertEvent = null;
+ this._deleteEventIndex = null;
+ this._obj = null;
+ if (arguments.length === 2) {
+ var x = arguments[0];
+ var insertEvent = arguments[1];
+ this._eventType = SweepLineEvent.DELETE;
+ this._xValue = x;
+ this._insertEvent = insertEvent;
+ } else if (arguments.length === 3) {
+ var label = arguments[0];
+ var x$1 = arguments[1];
+ var obj = arguments[2];
+ this._eventType = SweepLineEvent.INSERT;
+ this._label = label;
+ this._xValue = x$1;
+ this._obj = obj;
+ }
+ };
+
+ var staticAccessors$43 = { INSERT: { configurable: true },DELETE: { configurable: true } };
+ SweepLineEvent.prototype.isDelete = function isDelete () {
+ return this._eventType === SweepLineEvent.DELETE
+ };
+ SweepLineEvent.prototype.setDeleteEventIndex = function setDeleteEventIndex (deleteEventIndex) {
+ this._deleteEventIndex = deleteEventIndex;
+ };
+ SweepLineEvent.prototype.getObject = function getObject () {
+ return this._obj
+ };
+ SweepLineEvent.prototype.compareTo = function compareTo (o) {
+ var pe = o;
+ if (this._xValue < pe._xValue) { return -1 }
+ if (this._xValue > pe._xValue) { return 1 }
+ if (this._eventType < pe._eventType) { return -1 }
+ if (this._eventType > pe._eventType) { return 1 }
+ return 0
+ };
+ SweepLineEvent.prototype.getInsertEvent = function getInsertEvent () {
+ return this._insertEvent
+ };
+ SweepLineEvent.prototype.isInsert = function isInsert () {
+ return this._eventType === SweepLineEvent.INSERT
+ };
+ SweepLineEvent.prototype.isSameLabel = function isSameLabel (ev) {
+ if (this._label === null) { return false }
+ return this._label === ev._label
+ };
+ SweepLineEvent.prototype.getDeleteEventIndex = function getDeleteEventIndex () {
+ return this._deleteEventIndex
+ };
+ SweepLineEvent.prototype.interfaces_ = function interfaces_ () {
+ return [Comparable]
+ };
+ SweepLineEvent.prototype.getClass = function getClass () {
+ return SweepLineEvent
+ };
+ staticAccessors$43.INSERT.get = function () { return 1 };
+ staticAccessors$43.DELETE.get = function () { return 2 };
+
+ Object.defineProperties( SweepLineEvent, staticAccessors$43 );
+
+ var EdgeSetIntersector = function EdgeSetIntersector () {};
+
+ EdgeSetIntersector.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ EdgeSetIntersector.prototype.getClass = function getClass () {
+ return EdgeSetIntersector
+ };
+
+ var SegmentIntersector$2 = function SegmentIntersector () {
+ this._hasIntersection = false;
+ this._hasProper = false;
+ this._hasProperInterior = false;
+ this._properIntersectionPoint = null;
+ this._li = null;
+ this._includeProper = null;
+ this._recordIsolated = null;
+ this._isSelfIntersection = null;
+ this._numIntersections = 0;
+ this.numTests = 0;
+ this._bdyNodes = null;
+ this._isDone = false;
+ this._isDoneWhenProperInt = false;
+ var li = arguments[0];
+ var includeProper = arguments[1];
+ var recordIsolated = arguments[2];
+ this._li = li;
+ this._includeProper = includeProper;
+ this._recordIsolated = recordIsolated;
+ };
+ SegmentIntersector$2.prototype.isTrivialIntersection = function isTrivialIntersection (e0, segIndex0, e1, segIndex1) {
+ if (e0 === e1) {
+ if (this._li.getIntersectionNum() === 1) {
+ if (SegmentIntersector$2.isAdjacentSegments(segIndex0, segIndex1)) { return true }
+ if (e0.isClosed()) {
+ var maxSegIndex = e0.getNumPoints() - 1;
+ if ((segIndex0 === 0 && segIndex1 === maxSegIndex) ||
+ (segIndex1 === 0 && segIndex0 === maxSegIndex)) {
+ return true
+ }
+ }
+ }
+ }
+ return false
+ };
+ SegmentIntersector$2.prototype.getProperIntersectionPoint = function getProperIntersectionPoint () {
+ return this._properIntersectionPoint
+ };
+ SegmentIntersector$2.prototype.setIsDoneIfProperInt = function setIsDoneIfProperInt (isDoneWhenProperInt) {
+ this._isDoneWhenProperInt = isDoneWhenProperInt;
+ };
+ SegmentIntersector$2.prototype.hasProperInteriorIntersection = function hasProperInteriorIntersection () {
+ return this._hasProperInterior
+ };
+ SegmentIntersector$2.prototype.isBoundaryPointInternal = function isBoundaryPointInternal (li, bdyNodes) {
+ for (var i = bdyNodes.iterator(); i.hasNext();) {
+ var node = i.next();
+ var pt = node.getCoordinate();
+ if (li.isIntersection(pt)) { return true }
+ }
+ return false
+ };
+ SegmentIntersector$2.prototype.hasProperIntersection = function hasProperIntersection () {
+ return this._hasProper
+ };
+ SegmentIntersector$2.prototype.hasIntersection = function hasIntersection () {
+ return this._hasIntersection
+ };
+ SegmentIntersector$2.prototype.isDone = function isDone () {
+ return this._isDone
+ };
+ SegmentIntersector$2.prototype.isBoundaryPoint = function isBoundaryPoint (li, bdyNodes) {
+ if (bdyNodes === null) { return false }
+ if (this.isBoundaryPointInternal(li, bdyNodes[0])) { return true }
+ if (this.isBoundaryPointInternal(li, bdyNodes[1])) { return true }
+ return false
+ };
+ SegmentIntersector$2.prototype.setBoundaryNodes = function setBoundaryNodes (bdyNodes0, bdyNodes1) {
+ this._bdyNodes = new Array(2).fill(null);
+ this._bdyNodes[0] = bdyNodes0;
+ this._bdyNodes[1] = bdyNodes1;
+ };
+ SegmentIntersector$2.prototype.addIntersections = function addIntersections (e0, segIndex0, e1, segIndex1) {
+ if (e0 === e1 && segIndex0 === segIndex1) { return null }
+ this.numTests++;
+ var p00 = e0.getCoordinates()[segIndex0];
+ var p01 = e0.getCoordinates()[segIndex0 + 1];
+ var p10 = e1.getCoordinates()[segIndex1];
+ var p11 = e1.getCoordinates()[segIndex1 + 1];
+ this._li.computeIntersection(p00, p01, p10, p11);
+ if (this._li.hasIntersection()) {
+ if (this._recordIsolated) {
+ e0.setIsolated(false);
+ e1.setIsolated(false);
+ }
+ this._numIntersections++;
+ if (!this.isTrivialIntersection(e0, segIndex0, e1, segIndex1)) {
+ this._hasIntersection = true;
+ if (this._includeProper || !this._li.isProper()) {
+ e0.addIntersections(this._li, segIndex0, 0);
+ e1.addIntersections(this._li, segIndex1, 1);
+ }
+ if (this._li.isProper()) {
+ this._properIntersectionPoint = this._li.getIntersection(0).copy();
+ this._hasProper = true;
+ if (this._isDoneWhenProperInt) {
+ this._isDone = true;
+ }
+ if (!this.isBoundaryPoint(this._li, this._bdyNodes)) { this._hasProperInterior = true; }
+ }
+ }
+ }
+ };
+ SegmentIntersector$2.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ SegmentIntersector$2.prototype.getClass = function getClass () {
+ return SegmentIntersector$2
+ };
+ SegmentIntersector$2.isAdjacentSegments = function isAdjacentSegments (i1, i2) {
+ return Math.abs(i1 - i2) === 1
+ };
+
+ var SimpleMCSweepLineIntersector = (function (EdgeSetIntersector$$1) {
+ function SimpleMCSweepLineIntersector () {
+ EdgeSetIntersector$$1.call(this);
+ this.events = new ArrayList();
+ this.nOverlaps = null;
+ }
+
+ if ( EdgeSetIntersector$$1 ) SimpleMCSweepLineIntersector.__proto__ = EdgeSetIntersector$$1;
+ SimpleMCSweepLineIntersector.prototype = Object.create( EdgeSetIntersector$$1 && EdgeSetIntersector$$1.prototype );
+ SimpleMCSweepLineIntersector.prototype.constructor = SimpleMCSweepLineIntersector;
+ SimpleMCSweepLineIntersector.prototype.prepareEvents = function prepareEvents () {
+ var this$1 = this;
+
+ Collections.sort(this.events);
+ for (var i = 0; i < this.events.size(); i++) {
+ var ev = this$1.events.get(i);
+ if (ev.isDelete()) {
+ ev.getInsertEvent().setDeleteEventIndex(i);
+ }
+ }
+ };
+ SimpleMCSweepLineIntersector.prototype.computeIntersections = function computeIntersections () {
+ var this$1 = this;
+
+ if (arguments.length === 1) {
+ var si = arguments[0];
+ this.nOverlaps = 0;
+ this.prepareEvents();
+ for (var i = 0; i < this.events.size(); i++) {
+ var ev = this$1.events.get(i);
+ if (ev.isInsert()) {
+ this$1.processOverlaps(i, ev.getDeleteEventIndex(), ev, si);
+ }
+ if (si.isDone()) {
+ break
+ }
+ }
+ } else if (arguments.length === 3) {
+ if (arguments[2] instanceof SegmentIntersector$2 && (hasInterface(arguments[0], List) && hasInterface(arguments[1], List))) {
+ var edges0 = arguments[0];
+ var edges1 = arguments[1];
+ var si$1 = arguments[2];
+ this.addEdges(edges0, edges0);
+ this.addEdges(edges1, edges1);
+ this.computeIntersections(si$1);
+ } else if (typeof arguments[2] === 'boolean' && (hasInterface(arguments[0], List) && arguments[1] instanceof SegmentIntersector$2)) {
+ var edges = arguments[0];
+ var si$2 = arguments[1];
+ var testAllSegments = arguments[2];
+ if (testAllSegments) { this.addEdges(edges, null); } else { this.addEdges(edges); }
+ this.computeIntersections(si$2);
+ }
+ }
+ };
+ SimpleMCSweepLineIntersector.prototype.addEdge = function addEdge (edge, edgeSet) {
+ var this$1 = this;
+
+ var mce = edge.getMonotoneChainEdge();
+ var startIndex = mce.getStartIndexes();
+ for (var i = 0; i < startIndex.length - 1; i++) {
+ var mc = new MonotoneChain$2(mce, i);
+ var insertEvent = new SweepLineEvent(edgeSet, mce.getMinX(i), mc);
+ this$1.events.add(insertEvent);
+ this$1.events.add(new SweepLineEvent(mce.getMaxX(i), insertEvent));
+ }
+ };
+ SimpleMCSweepLineIntersector.prototype.processOverlaps = function processOverlaps (start, end, ev0, si) {
+ var this$1 = this;
+
+ var mc0 = ev0.getObject();
+ for (var i = start; i < end; i++) {
+ var ev1 = this$1.events.get(i);
+ if (ev1.isInsert()) {
+ var mc1 = ev1.getObject();
+ if (!ev0.isSameLabel(ev1)) {
+ mc0.computeIntersections(mc1, si);
+ this$1.nOverlaps++;
+ }
+ }
+ }
+ };
+ SimpleMCSweepLineIntersector.prototype.addEdges = function addEdges () {
+ var this$1 = this;
+
+ if (arguments.length === 1) {
+ var edges = arguments[0];
+ for (var i = edges.iterator(); i.hasNext();) {
+ var edge = i.next();
+ this$1.addEdge(edge, edge);
+ }
+ } else if (arguments.length === 2) {
+ var edges$1 = arguments[0];
+ var edgeSet = arguments[1];
+ for (var i$1 = edges$1.iterator(); i$1.hasNext();) {
+ var edge$1 = i$1.next();
+ this$1.addEdge(edge$1, edgeSet);
+ }
+ }
+ };
+ SimpleMCSweepLineIntersector.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ SimpleMCSweepLineIntersector.prototype.getClass = function getClass () {
+ return SimpleMCSweepLineIntersector
+ };
+
+ return SimpleMCSweepLineIntersector;
+ }(EdgeSetIntersector));
+
+ var IntervalRTreeNode = function IntervalRTreeNode () {
+ this._min = Double.POSITIVE_INFINITY;
+ this._max = Double.NEGATIVE_INFINITY;
+ };
+
+ var staticAccessors$45 = { NodeComparator: { configurable: true } };
+ IntervalRTreeNode.prototype.getMin = function getMin () {
+ return this._min
+ };
+ IntervalRTreeNode.prototype.intersects = function intersects (queryMin, queryMax) {
+ if (this._min > queryMax || this._max < queryMin) { return false }
+ return true
+ };
+ IntervalRTreeNode.prototype.getMax = function getMax () {
+ return this._max
+ };
+ IntervalRTreeNode.prototype.toString = function toString () {
+ return WKTWriter.toLineString(new Coordinate(this._min, 0), new Coordinate(this._max, 0))
+ };
+ IntervalRTreeNode.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ IntervalRTreeNode.prototype.getClass = function getClass () {
+ return IntervalRTreeNode
+ };
+ staticAccessors$45.NodeComparator.get = function () { return NodeComparator };
+
+ Object.defineProperties( IntervalRTreeNode, staticAccessors$45 );
+
+ var NodeComparator = function NodeComparator () {};
+
+ NodeComparator.prototype.compare = function compare (o1, o2) {
+ var n1 = o1;
+ var n2 = o2;
+ var mid1 = (n1._min + n1._max) / 2;
+ var mid2 = (n2._min + n2._max) / 2;
+ if (mid1 < mid2) { return -1 }
+ if (mid1 > mid2) { return 1 }
+ return 0
+ };
+ NodeComparator.prototype.interfaces_ = function interfaces_ () {
+ return [Comparator]
+ };
+ NodeComparator.prototype.getClass = function getClass () {
+ return NodeComparator
+ };
+
+ var IntervalRTreeLeafNode = (function (IntervalRTreeNode$$1) {
+ function IntervalRTreeLeafNode () {
+ IntervalRTreeNode$$1.call(this);
+ this._item = null;
+ var min = arguments[0];
+ var max = arguments[1];
+ var item = arguments[2];
+ this._min = min;
+ this._max = max;
+ this._item = item;
+ }
+
+ if ( IntervalRTreeNode$$1 ) IntervalRTreeLeafNode.__proto__ = IntervalRTreeNode$$1;
+ IntervalRTreeLeafNode.prototype = Object.create( IntervalRTreeNode$$1 && IntervalRTreeNode$$1.prototype );
+ IntervalRTreeLeafNode.prototype.constructor = IntervalRTreeLeafNode;
+ IntervalRTreeLeafNode.prototype.query = function query (queryMin, queryMax, visitor) {
+ if (!this.intersects(queryMin, queryMax)) { return null }
+ visitor.visitItem(this._item);
+ };
+ IntervalRTreeLeafNode.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ IntervalRTreeLeafNode.prototype.getClass = function getClass () {
+ return IntervalRTreeLeafNode
+ };
+
+ return IntervalRTreeLeafNode;
+ }(IntervalRTreeNode));
+
+ var IntervalRTreeBranchNode = (function (IntervalRTreeNode$$1) {
+ function IntervalRTreeBranchNode () {
+ IntervalRTreeNode$$1.call(this);
+ this._node1 = null;
+ this._node2 = null;
+ var n1 = arguments[0];
+ var n2 = arguments[1];
+ this._node1 = n1;
+ this._node2 = n2;
+ this.buildExtent(this._node1, this._node2);
+ }
+
+ if ( IntervalRTreeNode$$1 ) IntervalRTreeBranchNode.__proto__ = IntervalRTreeNode$$1;
+ IntervalRTreeBranchNode.prototype = Object.create( IntervalRTreeNode$$1 && IntervalRTreeNode$$1.prototype );
+ IntervalRTreeBranchNode.prototype.constructor = IntervalRTreeBranchNode;
+ IntervalRTreeBranchNode.prototype.buildExtent = function buildExtent (n1, n2) {
+ this._min = Math.min(n1._min, n2._min);
+ this._max = Math.max(n1._max, n2._max);
+ };
+ IntervalRTreeBranchNode.prototype.query = function query (queryMin, queryMax, visitor) {
+ if (!this.intersects(queryMin, queryMax)) {
+ return null
+ }
+ if (this._node1 !== null) { this._node1.query(queryMin, queryMax, visitor); }
+ if (this._node2 !== null) { this._node2.query(queryMin, queryMax, visitor); }
+ };
+ IntervalRTreeBranchNode.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ IntervalRTreeBranchNode.prototype.getClass = function getClass () {
+ return IntervalRTreeBranchNode
+ };
+
+ return IntervalRTreeBranchNode;
+ }(IntervalRTreeNode));
+
+ var SortedPackedIntervalRTree = function SortedPackedIntervalRTree () {
+ this._leaves = new ArrayList();
+ this._root = null;
+ this._level = 0;
+ };
+ SortedPackedIntervalRTree.prototype.buildTree = function buildTree () {
+ var this$1 = this;
+
+ Collections.sort(this._leaves, new IntervalRTreeNode.NodeComparator());
+ var src = this._leaves;
+ var temp = null;
+ var dest = new ArrayList();
+ while (true) {
+ this$1.buildLevel(src, dest);
+ if (dest.size() === 1) { return dest.get(0) }
+ temp = src;
+ src = dest;
+ dest = temp;
+ }
+ };
+ SortedPackedIntervalRTree.prototype.insert = function insert (min, max, item) {
+ if (this._root !== null) { throw new Error('Index cannot be added to once it has been queried') }
+ this._leaves.add(new IntervalRTreeLeafNode(min, max, item));
+ };
+ SortedPackedIntervalRTree.prototype.query = function query (min, max, visitor) {
+ this.init();
+ this._root.query(min, max, visitor);
+ };
+ SortedPackedIntervalRTree.prototype.buildRoot = function buildRoot () {
+ if (this._root !== null) { return null }
+ this._root = this.buildTree();
+ };
+ SortedPackedIntervalRTree.prototype.printNode = function printNode (node) {
+ System.out.println(WKTWriter.toLineString(new Coordinate(node._min, this._level), new Coordinate(node._max, this._level)));
+ };
+ SortedPackedIntervalRTree.prototype.init = function init () {
+ if (this._root !== null) { return null }
+ this.buildRoot();
+ };
+ SortedPackedIntervalRTree.prototype.buildLevel = function buildLevel (src, dest) {
+ this._level++;
+ dest.clear();
+ for (var i = 0; i < src.size(); i += 2) {
+ var n1 = src.get(i);
+ var n2 = i + 1 < src.size() ? src.get(i) : null;
+ if (n2 === null) {
+ dest.add(n1);
+ } else {
+ var node = new IntervalRTreeBranchNode(src.get(i), src.get(i + 1));
+ dest.add(node);
+ }
+ }
+ };
+ SortedPackedIntervalRTree.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ SortedPackedIntervalRTree.prototype.getClass = function getClass () {
+ return SortedPackedIntervalRTree
+ };
+
+ var ArrayListVisitor = function ArrayListVisitor () {
+ this._items = new ArrayList();
+ };
+ ArrayListVisitor.prototype.visitItem = function visitItem (item) {
+ this._items.add(item);
+ };
+ ArrayListVisitor.prototype.getItems = function getItems () {
+ return this._items
+ };
+ ArrayListVisitor.prototype.interfaces_ = function interfaces_ () {
+ return [ItemVisitor]
+ };
+ ArrayListVisitor.prototype.getClass = function getClass () {
+ return ArrayListVisitor
+ };
+
+ var IndexedPointInAreaLocator = function IndexedPointInAreaLocator () {
+ this._index = null;
+ var g = arguments[0];
+ if (!hasInterface(g, Polygonal)) { throw new IllegalArgumentException('Argument must be Polygonal') }
+ this._index = new IntervalIndexedGeometry(g);
+ };
+
+ var staticAccessors$44 = { SegmentVisitor: { configurable: true },IntervalIndexedGeometry: { configurable: true } };
+ IndexedPointInAreaLocator.prototype.locate = function locate (p) {
+ var rcc = new RayCrossingCounter(p);
+ var visitor = new SegmentVisitor(rcc);
+ this._index.query(p.y, p.y, visitor);
+ return rcc.getLocation()
+ };
+ IndexedPointInAreaLocator.prototype.interfaces_ = function interfaces_ () {
+ return [PointOnGeometryLocator]
+ };
+ IndexedPointInAreaLocator.prototype.getClass = function getClass () {
+ return IndexedPointInAreaLocator
+ };
+ staticAccessors$44.SegmentVisitor.get = function () { return SegmentVisitor };
+ staticAccessors$44.IntervalIndexedGeometry.get = function () { return IntervalIndexedGeometry };
+
+ Object.defineProperties( IndexedPointInAreaLocator, staticAccessors$44 );
+
+ var SegmentVisitor = function SegmentVisitor () {
+ this._counter = null;
+ var counter = arguments[0];
+ this._counter = counter;
+ };
+ SegmentVisitor.prototype.visitItem = function visitItem (item) {
+ var seg = item;
+ this._counter.countSegment(seg.getCoordinate(0), seg.getCoordinate(1));
+ };
+ SegmentVisitor.prototype.interfaces_ = function interfaces_ () {
+ return [ItemVisitor]
+ };
+ SegmentVisitor.prototype.getClass = function getClass () {
+ return SegmentVisitor
+ };
+
+ var IntervalIndexedGeometry = function IntervalIndexedGeometry () {
+ this._index = new SortedPackedIntervalRTree();
+ var geom = arguments[0];
+ this.init(geom);
+ };
+ IntervalIndexedGeometry.prototype.init = function init (geom) {
+ var this$1 = this;
+
+ var lines = LinearComponentExtracter.getLines(geom);
+ for (var i = lines.iterator(); i.hasNext();) {
+ var line = i.next();
+ var pts = line.getCoordinates();
+ this$1.addLine(pts);
+ }
+ };
+ IntervalIndexedGeometry.prototype.addLine = function addLine (pts) {
+ var this$1 = this;
+
+ for (var i = 1; i < pts.length; i++) {
+ var seg = new LineSegment(pts[i - 1], pts[i]);
+ var min = Math.min(seg.p0.y, seg.p1.y);
+ var max = Math.max(seg.p0.y, seg.p1.y);
+ this$1._index.insert(min, max, seg);
+ }
+ };
+ IntervalIndexedGeometry.prototype.query = function query () {
+ if (arguments.length === 2) {
+ var min = arguments[0];
+ var max = arguments[1];
+ var visitor = new ArrayListVisitor();
+ this._index.query(min, max, visitor);
+ return visitor.getItems()
+ } else if (arguments.length === 3) {
+ var min$1 = arguments[0];
+ var max$1 = arguments[1];
+ var visitor$1 = arguments[2];
+ this._index.query(min$1, max$1, visitor$1);
+ }
+ };
+ IntervalIndexedGeometry.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ IntervalIndexedGeometry.prototype.getClass = function getClass () {
+ return IntervalIndexedGeometry
+ };
+
+ var GeometryGraph = (function (PlanarGraph$$1) {
+ function GeometryGraph () {
+ PlanarGraph$$1.call(this);
+ this._parentGeom = null;
+ this._lineEdgeMap = new HashMap();
+ this._boundaryNodeRule = null;
+ this._useBoundaryDeterminationRule = true;
+ this._argIndex = null;
+ this._boundaryNodes = null;
+ this._hasTooFewPoints = false;
+ this._invalidPoint = null;
+ this._areaPtLocator = null;
+ this._ptLocator = new PointLocator();
+ if (arguments.length === 2) {
+ var argIndex = arguments[0];
+ var parentGeom = arguments[1];
+ var boundaryNodeRule = BoundaryNodeRule.OGC_SFS_BOUNDARY_RULE;
+ this._argIndex = argIndex;
+ this._parentGeom = parentGeom;
+ this._boundaryNodeRule = boundaryNodeRule;
+ if (parentGeom !== null) {
+ this.add(parentGeom);
+ }
+ } else if (arguments.length === 3) {
+ var argIndex$1 = arguments[0];
+ var parentGeom$1 = arguments[1];
+ var boundaryNodeRule$1 = arguments[2];
+ this._argIndex = argIndex$1;
+ this._parentGeom = parentGeom$1;
+ this._boundaryNodeRule = boundaryNodeRule$1;
+ if (parentGeom$1 !== null) {
+ this.add(parentGeom$1);
+ }
+ }
+ }
+
+ if ( PlanarGraph$$1 ) GeometryGraph.__proto__ = PlanarGraph$$1;
+ GeometryGraph.prototype = Object.create( PlanarGraph$$1 && PlanarGraph$$1.prototype );
+ GeometryGraph.prototype.constructor = GeometryGraph;
+ GeometryGraph.prototype.insertBoundaryPoint = function insertBoundaryPoint (argIndex, coord) {
+ var n = this._nodes.addNode(coord);
+ var lbl = n.getLabel();
+ var boundaryCount = 1;
+ var loc = Location.NONE;
+ loc = lbl.getLocation(argIndex, Position.ON);
+ if (loc === Location.BOUNDARY) { boundaryCount++; }
+ var newLoc = GeometryGraph.determineBoundary(this._boundaryNodeRule, boundaryCount);
+ lbl.setLocation(argIndex, newLoc);
+ };
+ GeometryGraph.prototype.computeSelfNodes = function computeSelfNodes () {
+ if (arguments.length === 2) {
+ var li = arguments[0];
+ var computeRingSelfNodes = arguments[1];
+ return this.computeSelfNodes(li, computeRingSelfNodes, false)
+ } else if (arguments.length === 3) {
+ var li$1 = arguments[0];
+ var computeRingSelfNodes$1 = arguments[1];
+ var isDoneIfProperInt = arguments[2];
+ var si = new SegmentIntersector$2(li$1, true, false);
+ si.setIsDoneIfProperInt(isDoneIfProperInt);
+ var esi = this.createEdgeSetIntersector();
+ var isRings = this._parentGeom instanceof LinearRing || this._parentGeom instanceof Polygon || this._parentGeom instanceof MultiPolygon;
+ var computeAllSegments = computeRingSelfNodes$1 || !isRings;
+ esi.computeIntersections(this._edges, si, computeAllSegments);
+ this.addSelfIntersectionNodes(this._argIndex);
+ return si
+ }
+ };
+ GeometryGraph.prototype.computeSplitEdges = function computeSplitEdges (edgelist) {
+ for (var i = this._edges.iterator(); i.hasNext();) {
+ var e = i.next();
+ e.eiList.addSplitEdges(edgelist);
+ }
+ };
+ GeometryGraph.prototype.computeEdgeIntersections = function computeEdgeIntersections (g, li, includeProper) {
+ var si = new SegmentIntersector$2(li, includeProper, true);
+ si.setBoundaryNodes(this.getBoundaryNodes(), g.getBoundaryNodes());
+ var esi = this.createEdgeSetIntersector();
+ esi.computeIntersections(this._edges, g._edges, si);
+ return si
+ };
+ GeometryGraph.prototype.getGeometry = function getGeometry () {
+ return this._parentGeom
+ };
+ GeometryGraph.prototype.getBoundaryNodeRule = function getBoundaryNodeRule () {
+ return this._boundaryNodeRule
+ };
+ GeometryGraph.prototype.hasTooFewPoints = function hasTooFewPoints () {
+ return this._hasTooFewPoints
+ };
+ GeometryGraph.prototype.addPoint = function addPoint () {
+ if (arguments[0] instanceof Point) {
+ var p = arguments[0];
+ var coord = p.getCoordinate();
+ this.insertPoint(this._argIndex, coord, Location.INTERIOR);
+ } else if (arguments[0] instanceof Coordinate) {
+ var pt = arguments[0];
+ this.insertPoint(this._argIndex, pt, Location.INTERIOR);
+ }
+ };
+ GeometryGraph.prototype.addPolygon = function addPolygon (p) {
+ var this$1 = this;
+
+ this.addPolygonRing(p.getExteriorRing(), Location.EXTERIOR, Location.INTERIOR);
+ for (var i = 0; i < p.getNumInteriorRing(); i++) {
+ var hole = p.getInteriorRingN(i);
+ this$1.addPolygonRing(hole, Location.INTERIOR, Location.EXTERIOR);
+ }
+ };
+ GeometryGraph.prototype.addEdge = function addEdge (e) {
+ this.insertEdge(e);
+ var coord = e.getCoordinates();
+ this.insertPoint(this._argIndex, coord[0], Location.BOUNDARY);
+ this.insertPoint(this._argIndex, coord[coord.length - 1], Location.BOUNDARY);
+ };
+ GeometryGraph.prototype.addLineString = function addLineString (line) {
+ var coord = CoordinateArrays.removeRepeatedPoints(line.getCoordinates());
+ if (coord.length < 2) {
+ this._hasTooFewPoints = true;
+ this._invalidPoint = coord[0];
+ return null
+ }
+ var e = new Edge(coord, new Label(this._argIndex, Location.INTERIOR));
+ this._lineEdgeMap.put(line, e);
+ this.insertEdge(e);
+ Assert.isTrue(coord.length >= 2, 'found LineString with single point');
+ this.insertBoundaryPoint(this._argIndex, coord[0]);
+ this.insertBoundaryPoint(this._argIndex, coord[coord.length - 1]);
+ };
+ GeometryGraph.prototype.getInvalidPoint = function getInvalidPoint () {
+ return this._invalidPoint
+ };
+ GeometryGraph.prototype.getBoundaryPoints = function getBoundaryPoints () {
+ var coll = this.getBoundaryNodes();
+ var pts = new Array(coll.size()).fill(null);
+ var i = 0;
+ for (var it = coll.iterator(); it.hasNext();) {
+ var node = it.next();
+ pts[i++] = node.getCoordinate().copy();
+ }
+ return pts
+ };
+ GeometryGraph.prototype.getBoundaryNodes = function getBoundaryNodes () {
+ if (this._boundaryNodes === null) { this._boundaryNodes = this._nodes.getBoundaryNodes(this._argIndex); }
+ return this._boundaryNodes
+ };
+ GeometryGraph.prototype.addSelfIntersectionNode = function addSelfIntersectionNode (argIndex, coord, loc) {
+ if (this.isBoundaryNode(argIndex, coord)) { return null }
+ if (loc === Location.BOUNDARY && this._useBoundaryDeterminationRule) { this.insertBoundaryPoint(argIndex, coord); } else { this.insertPoint(argIndex, coord, loc); }
+ };
+ GeometryGraph.prototype.addPolygonRing = function addPolygonRing (lr, cwLeft, cwRight) {
+ if (lr.isEmpty()) { return null }
+ var coord = CoordinateArrays.removeRepeatedPoints(lr.getCoordinates());
+ if (coord.length < 4) {
+ this._hasTooFewPoints = true;
+ this._invalidPoint = coord[0];
+ return null
+ }
+ var left = cwLeft;
+ var right = cwRight;
+ if (CGAlgorithms.isCCW(coord)) {
+ left = cwRight;
+ right = cwLeft;
+ }
+ var e = new Edge(coord, new Label(this._argIndex, Location.BOUNDARY, left, right));
+ this._lineEdgeMap.put(lr, e);
+ this.insertEdge(e);
+ this.insertPoint(this._argIndex, coord[0], Location.BOUNDARY);
+ };
+ GeometryGraph.prototype.insertPoint = function insertPoint (argIndex, coord, onLocation) {
+ var n = this._nodes.addNode(coord);
+ var lbl = n.getLabel();
+ if (lbl === null) {
+ n._label = new Label(argIndex, onLocation);
+ } else { lbl.setLocation(argIndex, onLocation); }
+ };
+ GeometryGraph.prototype.createEdgeSetIntersector = function createEdgeSetIntersector () {
+ return new SimpleMCSweepLineIntersector()
+ };
+ GeometryGraph.prototype.addSelfIntersectionNodes = function addSelfIntersectionNodes (argIndex) {
+ var this$1 = this;
+
+ for (var i = this._edges.iterator(); i.hasNext();) {
+ var e = i.next();
+ var eLoc = e.getLabel().getLocation(argIndex);
+ for (var eiIt = e.eiList.iterator(); eiIt.hasNext();) {
+ var ei = eiIt.next();
+ this$1.addSelfIntersectionNode(argIndex, ei.coord, eLoc);
+ }
+ }
+ };
+ GeometryGraph.prototype.add = function add () {
+ if (arguments.length === 1) {
+ var g = arguments[0];
+ if (g.isEmpty()) { return null }
+ if (g instanceof MultiPolygon) { this._useBoundaryDeterminationRule = false; }
+ if (g instanceof Polygon) { this.addPolygon(g); }
+ else if (g instanceof LineString) { this.addLineString(g); }
+ else if (g instanceof Point) { this.addPoint(g); }
+ else if (g instanceof MultiPoint) { this.addCollection(g); }
+ else if (g instanceof MultiLineString) { this.addCollection(g); }
+ else if (g instanceof MultiPolygon) { this.addCollection(g); }
+ else if (g instanceof GeometryCollection) { this.addCollection(g); }
+ else { throw new Error(g.getClass().getName()) }
+ } else { return PlanarGraph$$1.prototype.add.apply(this, arguments) }
+ };
+ GeometryGraph.prototype.addCollection = function addCollection (gc) {
+ var this$1 = this;
+
+ for (var i = 0; i < gc.getNumGeometries(); i++) {
+ var g = gc.getGeometryN(i);
+ this$1.add(g);
+ }
+ };
+ GeometryGraph.prototype.locate = function locate (pt) {
+ if (hasInterface(this._parentGeom, Polygonal) && this._parentGeom.getNumGeometries() > 50) {
+ if (this._areaPtLocator === null) {
+ this._areaPtLocator = new IndexedPointInAreaLocator(this._parentGeom);
+ }
+ return this._areaPtLocator.locate(pt)
+ }
+ return this._ptLocator.locate(pt, this._parentGeom)
+ };
+ GeometryGraph.prototype.findEdge = function findEdge () {
+ if (arguments.length === 1) {
+ var line = arguments[0];
+ return this._lineEdgeMap.get(line)
+ } else { return PlanarGraph$$1.prototype.findEdge.apply(this, arguments) }
+ };
+ GeometryGraph.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ GeometryGraph.prototype.getClass = function getClass () {
+ return GeometryGraph
+ };
+ GeometryGraph.determineBoundary = function determineBoundary (boundaryNodeRule, boundaryCount) {
+ return boundaryNodeRule.isInBoundary(boundaryCount) ? Location.BOUNDARY : Location.INTERIOR
+ };
+
+ return GeometryGraph;
+ }(PlanarGraph));
+
+ var GeometryGraphOp = function GeometryGraphOp () {
+ this._li = new RobustLineIntersector();
+ this._resultPrecisionModel = null;
+ this._arg = null;
+ if (arguments.length === 1) {
+ var g0 = arguments[0];
+ this.setComputationPrecision(g0.getPrecisionModel());
+ this._arg = new Array(1).fill(null);
+ this._arg[0] = new GeometryGraph(0, g0);
+ } else if (arguments.length === 2) {
+ var g0$1 = arguments[0];
+ var g1 = arguments[1];
+ var boundaryNodeRule = BoundaryNodeRule.OGC_SFS_BOUNDARY_RULE;
+ if (g0$1.getPrecisionModel().compareTo(g1.getPrecisionModel()) >= 0) { this.setComputationPrecision(g0$1.getPrecisionModel()); } else { this.setComputationPrecision(g1.getPrecisionModel()); }
+ this._arg = new Array(2).fill(null);
+ this._arg[0] = new GeometryGraph(0, g0$1, boundaryNodeRule);
+ this._arg[1] = new GeometryGraph(1, g1, boundaryNodeRule);
+ } else if (arguments.length === 3) {
+ var g0$2 = arguments[0];
+ var g1$1 = arguments[1];
+ var boundaryNodeRule$1 = arguments[2];
+ if (g0$2.getPrecisionModel().compareTo(g1$1.getPrecisionModel()) >= 0) { this.setComputationPrecision(g0$2.getPrecisionModel()); } else { this.setComputationPrecision(g1$1.getPrecisionModel()); }
+ this._arg = new Array(2).fill(null);
+ this._arg[0] = new GeometryGraph(0, g0$2, boundaryNodeRule$1);
+ this._arg[1] = new GeometryGraph(1, g1$1, boundaryNodeRule$1);
+ }
+ };
+ GeometryGraphOp.prototype.getArgGeometry = function getArgGeometry (i) {
+ return this._arg[i].getGeometry()
+ };
+ GeometryGraphOp.prototype.setComputationPrecision = function setComputationPrecision (pm) {
+ this._resultPrecisionModel = pm;
+ this._li.setPrecisionModel(this._resultPrecisionModel);
+ };
+ GeometryGraphOp.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ GeometryGraphOp.prototype.getClass = function getClass () {
+ return GeometryGraphOp
+ };
+
+ // operation.geometrygraph
+
+ var GeometryMapper = function GeometryMapper () {};
+
+ GeometryMapper.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ GeometryMapper.prototype.getClass = function getClass () {
+ return GeometryMapper
+ };
+ GeometryMapper.map = function map () {
+ if (arguments[0] instanceof Geometry && hasInterface(arguments[1], GeometryMapper.MapOp)) {
+ var geom = arguments[0];
+ var op = arguments[1];
+ var mapped = new ArrayList();
+ for (var i = 0; i < geom.getNumGeometries(); i++) {
+ var g = op.map(geom.getGeometryN(i));
+ if (g !== null) { mapped.add(g); }
+ }
+ return geom.getFactory().buildGeometry(mapped)
+ } else if (hasInterface(arguments[0], Collection) && hasInterface(arguments[1], GeometryMapper.MapOp)) {
+ var geoms = arguments[0];
+ var op$1 = arguments[1];
+ var mapped$1 = new ArrayList();
+ for (var i$1 = geoms.iterator(); i$1.hasNext();) {
+ var g$1 = i$1.next();
+ var gr = op$1.map(g$1);
+ if (gr !== null) { mapped$1.add(gr); }
+ }
+ return mapped$1
+ }
+ };
+ GeometryMapper.MapOp = function MapOp () {};
+
+ var OverlayOp = (function (GeometryGraphOp) {
+ function OverlayOp () {
+ var g0 = arguments[0];
+ var g1 = arguments[1];
+ GeometryGraphOp.call(this, g0, g1);
+ this._ptLocator = new PointLocator();
+ this._geomFact = null;
+ this._resultGeom = null;
+ this._graph = null;
+ this._edgeList = new EdgeList();
+ this._resultPolyList = new ArrayList();
+ this._resultLineList = new ArrayList();
+ this._resultPointList = new ArrayList();
+ this._graph = new PlanarGraph(new OverlayNodeFactory());
+ this._geomFact = g0.getFactory();
+ }
+
+ if ( GeometryGraphOp ) OverlayOp.__proto__ = GeometryGraphOp;
+ OverlayOp.prototype = Object.create( GeometryGraphOp && GeometryGraphOp.prototype );
+ OverlayOp.prototype.constructor = OverlayOp;
+ OverlayOp.prototype.insertUniqueEdge = function insertUniqueEdge (e) {
+ var existingEdge = this._edgeList.findEqualEdge(e);
+ if (existingEdge !== null) {
+ var existingLabel = existingEdge.getLabel();
+ var labelToMerge = e.getLabel();
+ if (!existingEdge.isPointwiseEqual(e)) {
+ labelToMerge = new Label(e.getLabel());
+ labelToMerge.flip();
+ }
+ var depth = existingEdge.getDepth();
+ if (depth.isNull()) {
+ depth.add(existingLabel);
+ }
+ depth.add(labelToMerge);
+ existingLabel.merge(labelToMerge);
+ } else {
+ this._edgeList.add(e);
+ }
+ };
+ OverlayOp.prototype.getGraph = function getGraph () {
+ return this._graph
+ };
+ OverlayOp.prototype.cancelDuplicateResultEdges = function cancelDuplicateResultEdges () {
+ for (var it = this._graph.getEdgeEnds().iterator(); it.hasNext();) {
+ var de = it.next();
+ var sym = de.getSym();
+ if (de.isInResult() && sym.isInResult()) {
+ de.setInResult(false);
+ sym.setInResult(false);
+ }
+ }
+ };
+ OverlayOp.prototype.isCoveredByLA = function isCoveredByLA (coord) {
+ if (this.isCovered(coord, this._resultLineList)) { return true }
+ if (this.isCovered(coord, this._resultPolyList)) { return true }
+ return false
+ };
+ OverlayOp.prototype.computeGeometry = function computeGeometry (resultPointList, resultLineList, resultPolyList, opcode) {
+ var geomList = new ArrayList();
+ geomList.addAll(resultPointList);
+ geomList.addAll(resultLineList);
+ geomList.addAll(resultPolyList);
+ if (geomList.isEmpty()) { return OverlayOp.createEmptyResult(opcode, this._arg[0].getGeometry(), this._arg[1].getGeometry(), this._geomFact) }
+ return this._geomFact.buildGeometry(geomList)
+ };
+ OverlayOp.prototype.mergeSymLabels = function mergeSymLabels () {
+ for (var nodeit = this._graph.getNodes().iterator(); nodeit.hasNext();) {
+ var node = nodeit.next();
+ node.getEdges().mergeSymLabels();
+ }
+ };
+ OverlayOp.prototype.isCovered = function isCovered (coord, geomList) {
+ var this$1 = this;
+
+ for (var it = geomList.iterator(); it.hasNext();) {
+ var geom = it.next();
+ var loc = this$1._ptLocator.locate(coord, geom);
+ if (loc !== Location.EXTERIOR) { return true }
+ }
+ return false
+ };
+ OverlayOp.prototype.replaceCollapsedEdges = function replaceCollapsedEdges () {
+ var newEdges = new ArrayList();
+ for (var it = this._edgeList.iterator(); it.hasNext();) {
+ var e = it.next();
+ if (e.isCollapsed()) {
+ it.remove();
+ newEdges.add(e.getCollapsedEdge());
+ }
+ }
+ this._edgeList.addAll(newEdges);
+ };
+ OverlayOp.prototype.updateNodeLabelling = function updateNodeLabelling () {
+ for (var nodeit = this._graph.getNodes().iterator(); nodeit.hasNext();) {
+ var node = nodeit.next();
+ var lbl = node.getEdges().getLabel();
+ node.getLabel().merge(lbl);
+ }
+ };
+ OverlayOp.prototype.getResultGeometry = function getResultGeometry (overlayOpCode) {
+ this.computeOverlay(overlayOpCode);
+ return this._resultGeom
+ };
+ OverlayOp.prototype.insertUniqueEdges = function insertUniqueEdges (edges) {
+ var this$1 = this;
+
+ for (var i = edges.iterator(); i.hasNext();) {
+ var e = i.next();
+ this$1.insertUniqueEdge(e);
+ }
+ };
+ OverlayOp.prototype.computeOverlay = function computeOverlay (opCode) {
+ this.copyPoints(0);
+ this.copyPoints(1);
+ this._arg[0].computeSelfNodes(this._li, false);
+ this._arg[1].computeSelfNodes(this._li, false);
+ this._arg[0].computeEdgeIntersections(this._arg[1], this._li, true);
+ var baseSplitEdges = new ArrayList();
+ this._arg[0].computeSplitEdges(baseSplitEdges);
+ this._arg[1].computeSplitEdges(baseSplitEdges);
+ // const splitEdges = baseSplitEdges
+ this.insertUniqueEdges(baseSplitEdges);
+ this.computeLabelsFromDepths();
+ this.replaceCollapsedEdges();
+ EdgeNodingValidator.checkValid(this._edgeList.getEdges());
+ this._graph.addEdges(this._edgeList.getEdges());
+ this.computeLabelling();
+ this.labelIncompleteNodes();
+ this.findResultAreaEdges(opCode);
+ this.cancelDuplicateResultEdges();
+ var polyBuilder = new PolygonBuilder(this._geomFact);
+ polyBuilder.add(this._graph);
+ this._resultPolyList = polyBuilder.getPolygons();
+ var lineBuilder = new LineBuilder(this, this._geomFact, this._ptLocator);
+ this._resultLineList = lineBuilder.build(opCode);
+ var pointBuilder = new PointBuilder(this, this._geomFact, this._ptLocator);
+ this._resultPointList = pointBuilder.build(opCode);
+ this._resultGeom = this.computeGeometry(this._resultPointList, this._resultLineList, this._resultPolyList, opCode);
+ };
+ OverlayOp.prototype.labelIncompleteNode = function labelIncompleteNode (n, targetIndex) {
+ var loc = this._ptLocator.locate(n.getCoordinate(), this._arg[targetIndex].getGeometry());
+ n.getLabel().setLocation(targetIndex, loc);
+ };
+ OverlayOp.prototype.copyPoints = function copyPoints (argIndex) {
+ var this$1 = this;
+
+ for (var i = this._arg[argIndex].getNodeIterator(); i.hasNext();) {
+ var graphNode = i.next();
+ var newNode = this$1._graph.addNode(graphNode.getCoordinate());
+ newNode.setLabel(argIndex, graphNode.getLabel().getLocation(argIndex));
+ }
+ };
+ OverlayOp.prototype.findResultAreaEdges = function findResultAreaEdges (opCode) {
+ for (var it = this._graph.getEdgeEnds().iterator(); it.hasNext();) {
+ var de = it.next();
+ var label = de.getLabel();
+ if (label.isArea() && !de.isInteriorAreaEdge() && OverlayOp.isResultOfOp(label.getLocation(0, Position.RIGHT), label.getLocation(1, Position.RIGHT), opCode)) {
+ de.setInResult(true);
+ }
+ }
+ };
+ OverlayOp.prototype.computeLabelsFromDepths = function computeLabelsFromDepths () {
+ for (var it = this._edgeList.iterator(); it.hasNext();) {
+ var e = it.next();
+ var lbl = e.getLabel();
+ var depth = e.getDepth();
+ if (!depth.isNull()) {
+ depth.normalize();
+ for (var i = 0; i < 2; i++) {
+ if (!lbl.isNull(i) && lbl.isArea() && !depth.isNull(i)) {
+ if (depth.getDelta(i) === 0) {
+ lbl.toLine(i);
+ } else {
+ Assert.isTrue(!depth.isNull(i, Position.LEFT), 'depth of LEFT side has not been initialized');
+ lbl.setLocation(i, Position.LEFT, depth.getLocation(i, Position.LEFT));
+ Assert.isTrue(!depth.isNull(i, Position.RIGHT), 'depth of RIGHT side has not been initialized');
+ lbl.setLocation(i, Position.RIGHT, depth.getLocation(i, Position.RIGHT));
+ }
+ }
+ }
+ }
+ }
+ };
+ OverlayOp.prototype.computeLabelling = function computeLabelling () {
+ var this$1 = this;
+
+ for (var nodeit = this._graph.getNodes().iterator(); nodeit.hasNext();) {
+ var node = nodeit.next();
+ node.getEdges().computeLabelling(this$1._arg);
+ }
+ this.mergeSymLabels();
+ this.updateNodeLabelling();
+ };
+ OverlayOp.prototype.labelIncompleteNodes = function labelIncompleteNodes () {
+ var this$1 = this;
+
+ // let nodeCount = 0
+ for (var ni = this._graph.getNodes().iterator(); ni.hasNext();) {
+ var n = ni.next();
+ var label = n.getLabel();
+ if (n.isIsolated()) {
+ // nodeCount++
+ if (label.isNull(0)) { this$1.labelIncompleteNode(n, 0); } else { this$1.labelIncompleteNode(n, 1); }
+ }
+ n.getEdges().updateLabelling(label);
+ }
+ };
+ OverlayOp.prototype.isCoveredByA = function isCoveredByA (coord) {
+ if (this.isCovered(coord, this._resultPolyList)) { return true }
+ return false
+ };
+ OverlayOp.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ OverlayOp.prototype.getClass = function getClass () {
+ return OverlayOp
+ };
+
+ return OverlayOp;
+ }(GeometryGraphOp));
+
+ OverlayOp.overlayOp = function (geom0, geom1, opCode) {
+ var gov = new OverlayOp(geom0, geom1);
+ var geomOv = gov.getResultGeometry(opCode);
+ return geomOv
+ };
+ OverlayOp.intersection = function (g, other) {
+ if (g.isEmpty() || other.isEmpty()) { return OverlayOp.createEmptyResult(OverlayOp.INTERSECTION, g, other, g.getFactory()) }
+ if (g.isGeometryCollection()) {
+ var g2 = other;
+ return GeometryCollectionMapper.map(g, {
+ interfaces_: function () {
+ return [GeometryMapper.MapOp]
+ },
+ map: function (g) {
+ return g.intersection(g2)
+ }
+ })
+ }
+ g.checkNotGeometryCollection(g);
+ g.checkNotGeometryCollection(other);
+ return SnapIfNeededOverlayOp.overlayOp(g, other, OverlayOp.INTERSECTION)
+ };
+ OverlayOp.symDifference = function (g, other) {
+ if (g.isEmpty() || other.isEmpty()) {
+ if (g.isEmpty() && other.isEmpty()) { return OverlayOp.createEmptyResult(OverlayOp.SYMDIFFERENCE, g, other, g.getFactory()) }
+ if (g.isEmpty()) { return other.copy() }
+ if (other.isEmpty()) { return g.copy() }
+ }
+ g.checkNotGeometryCollection(g);
+ g.checkNotGeometryCollection(other);
+ return SnapIfNeededOverlayOp.overlayOp(g, other, OverlayOp.SYMDIFFERENCE)
+ };
+ OverlayOp.resultDimension = function (opCode, g0, g1) {
+ var dim0 = g0.getDimension();
+ var dim1 = g1.getDimension();
+ var resultDimension = -1;
+ switch (opCode) {
+ case OverlayOp.INTERSECTION:
+ resultDimension = Math.min(dim0, dim1);
+ break
+ case OverlayOp.UNION:
+ resultDimension = Math.max(dim0, dim1);
+ break
+ case OverlayOp.DIFFERENCE:
+ resultDimension = dim0;
+ break
+ case OverlayOp.SYMDIFFERENCE:
+ resultDimension = Math.max(dim0, dim1);
+ break
+ }
+ return resultDimension
+ };
+ OverlayOp.createEmptyResult = function (overlayOpCode, a, b, geomFact) {
+ var result = null;
+ switch (OverlayOp.resultDimension(overlayOpCode, a, b)) {
+ case -1:
+ result = geomFact.createGeometryCollection(new Array(0).fill(null));
+ break
+ case 0:
+ result = geomFact.createPoint();
+ break
+ case 1:
+ result = geomFact.createLineString();
+ break
+ case 2:
+ result = geomFact.createPolygon();
+ break
+ }
+ return result
+ };
+ OverlayOp.difference = function (g, other) {
+ if (g.isEmpty()) { return OverlayOp.createEmptyResult(OverlayOp.DIFFERENCE, g, other, g.getFactory()) }
+ if (other.isEmpty()) { return g.copy() }
+ g.checkNotGeometryCollection(g);
+ g.checkNotGeometryCollection(other);
+ return SnapIfNeededOverlayOp.overlayOp(g, other, OverlayOp.DIFFERENCE)
+ };
+ OverlayOp.isResultOfOp = function () {
+ if (arguments.length === 2) {
+ var label = arguments[0];
+ var opCode = arguments[1];
+ var loc0 = label.getLocation(0);
+ var loc1 = label.getLocation(1);
+ return OverlayOp.isResultOfOp(loc0, loc1, opCode)
+ } else if (arguments.length === 3) {
+ var loc0$1 = arguments[0];
+ var loc1$1 = arguments[1];
+ var overlayOpCode = arguments[2];
+ if (loc0$1 === Location.BOUNDARY) { loc0$1 = Location.INTERIOR; }
+ if (loc1$1 === Location.BOUNDARY) { loc1$1 = Location.INTERIOR; }
+ switch (overlayOpCode) {
+ case OverlayOp.INTERSECTION:
+ return loc0$1 === Location.INTERIOR && loc1$1 === Location.INTERIOR
+ case OverlayOp.UNION:
+ return loc0$1 === Location.INTERIOR || loc1$1 === Location.INTERIOR
+ case OverlayOp.DIFFERENCE:
+ return loc0$1 === Location.INTERIOR && loc1$1 !== Location.INTERIOR
+ case OverlayOp.SYMDIFFERENCE:
+ return (loc0$1 === Location.INTERIOR && loc1$1 !== Location.INTERIOR) || (loc0$1 !== Location.INTERIOR && loc1$1 === Location.INTERIOR)
+ }
+ return false
+ }
+ };
+ OverlayOp.INTERSECTION = 1;
+ OverlayOp.UNION = 2;
+ OverlayOp.DIFFERENCE = 3;
+ OverlayOp.SYMDIFFERENCE = 4;
+
+ var FuzzyPointLocator = function FuzzyPointLocator () {
+ this._g = null;
+ this._boundaryDistanceTolerance = null;
+ this._linework = null;
+ this._ptLocator = new PointLocator();
+ this._seg = new LineSegment();
+ var g = arguments[0];
+ var boundaryDistanceTolerance = arguments[1];
+ this._g = g;
+ this._boundaryDistanceTolerance = boundaryDistanceTolerance;
+ this._linework = this.extractLinework(g);
+ };
+ FuzzyPointLocator.prototype.isWithinToleranceOfBoundary = function isWithinToleranceOfBoundary (pt) {
+ var this$1 = this;
+
+ for (var i = 0; i < this._linework.getNumGeometries(); i++) {
+ var line = this$1._linework.getGeometryN(i);
+ var seq = line.getCoordinateSequence();
+ for (var j = 0; j < seq.size() - 1; j++) {
+ seq.getCoordinate(j, this$1._seg.p0);
+ seq.getCoordinate(j + 1, this$1._seg.p1);
+ var dist = this$1._seg.distance(pt);
+ if (dist <= this$1._boundaryDistanceTolerance) { return true }
+ }
+ }
+ return false
+ };
+ FuzzyPointLocator.prototype.getLocation = function getLocation (pt) {
+ if (this.isWithinToleranceOfBoundary(pt)) { return Location.BOUNDARY }
+ return this._ptLocator.locate(pt, this._g)
+ };
+ FuzzyPointLocator.prototype.extractLinework = function extractLinework (g) {
+ var extracter = new PolygonalLineworkExtracter();
+ g.apply(extracter);
+ var linework = extracter.getLinework();
+ var lines = GeometryFactory.toLineStringArray(linework);
+ return g.getFactory().createMultiLineString(lines)
+ };
+ FuzzyPointLocator.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ FuzzyPointLocator.prototype.getClass = function getClass () {
+ return FuzzyPointLocator
+ };
+
+ var PolygonalLineworkExtracter = function PolygonalLineworkExtracter () {
+ this._linework = null;
+ this._linework = new ArrayList();
+ };
+ PolygonalLineworkExtracter.prototype.getLinework = function getLinework () {
+ return this._linework
+ };
+ PolygonalLineworkExtracter.prototype.filter = function filter (g) {
+ var this$1 = this;
+
+ if (g instanceof Polygon) {
+ var poly = g;
+ this._linework.add(poly.getExteriorRing());
+ for (var i = 0; i < poly.getNumInteriorRing(); i++) {
+ this$1._linework.add(poly.getInteriorRingN(i));
+ }
+ }
+ };
+ PolygonalLineworkExtracter.prototype.interfaces_ = function interfaces_ () {
+ return [GeometryFilter]
+ };
+ PolygonalLineworkExtracter.prototype.getClass = function getClass () {
+ return PolygonalLineworkExtracter
+ };
+
+ var OffsetPointGenerator = function OffsetPointGenerator () {
+ this._g = null;
+ this._doLeft = true;
+ this._doRight = true;
+ var g = arguments[0];
+ this._g = g;
+ };
+ OffsetPointGenerator.prototype.extractPoints = function extractPoints (line, offsetDistance, offsetPts) {
+ var this$1 = this;
+
+ var pts = line.getCoordinates();
+ for (var i = 0; i < pts.length - 1; i++) {
+ this$1.computeOffsetPoints(pts[i], pts[i + 1], offsetDistance, offsetPts);
+ }
+ };
+ OffsetPointGenerator.prototype.setSidesToGenerate = function setSidesToGenerate (doLeft, doRight) {
+ this._doLeft = doLeft;
+ this._doRight = doRight;
+ };
+ OffsetPointGenerator.prototype.getPoints = function getPoints (offsetDistance) {
+ var this$1 = this;
+
+ var offsetPts = new ArrayList();
+ var lines = LinearComponentExtracter.getLines(this._g);
+ for (var i = lines.iterator(); i.hasNext();) {
+ var line = i.next();
+ this$1.extractPoints(line, offsetDistance, offsetPts);
+ }
+ return offsetPts
+ };
+ OffsetPointGenerator.prototype.computeOffsetPoints = function computeOffsetPoints (p0, p1, offsetDistance, offsetPts) {
+ var dx = p1.x - p0.x;
+ var dy = p1.y - p0.y;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ var ux = offsetDistance * dx / len;
+ var uy = offsetDistance * dy / len;
+ var midX = (p1.x + p0.x) / 2;
+ var midY = (p1.y + p0.y) / 2;
+ if (this._doLeft) {
+ var offsetLeft = new Coordinate(midX - uy, midY + ux);
+ offsetPts.add(offsetLeft);
+ }
+ if (this._doRight) {
+ var offsetRight = new Coordinate(midX + uy, midY - ux);
+ offsetPts.add(offsetRight);
+ }
+ };
+ OffsetPointGenerator.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ OffsetPointGenerator.prototype.getClass = function getClass () {
+ return OffsetPointGenerator
+ };
+
+ var OverlayResultValidator = function OverlayResultValidator () {
+ this._geom = null;
+ this._locFinder = null;
+ this._location = new Array(3).fill(null);
+ this._invalidLocation = null;
+ this._boundaryDistanceTolerance = OverlayResultValidator.TOLERANCE;
+ this._testCoords = new ArrayList();
+ var a = arguments[0];
+ var b = arguments[1];
+ var result = arguments[2];
+ this._boundaryDistanceTolerance = OverlayResultValidator.computeBoundaryDistanceTolerance(a, b);
+ this._geom = [a, b, result];
+ this._locFinder = [new FuzzyPointLocator(this._geom[0], this._boundaryDistanceTolerance), new FuzzyPointLocator(this._geom[1], this._boundaryDistanceTolerance), new FuzzyPointLocator(this._geom[2], this._boundaryDistanceTolerance)];
+ };
+
+ var staticAccessors$46 = { TOLERANCE: { configurable: true } };
+ OverlayResultValidator.prototype.reportResult = function reportResult (overlayOp, location, expectedInterior) {
+ System.out.println('Overlay result invalid - A:' + Location.toLocationSymbol(location[0]) + ' B:' + Location.toLocationSymbol(location[1]) + ' expected:' + (expectedInterior ? 'i' : 'e') + ' actual:' + Location.toLocationSymbol(location[2]));
+ };
+ OverlayResultValidator.prototype.isValid = function isValid (overlayOp) {
+ this.addTestPts(this._geom[0]);
+ this.addTestPts(this._geom[1]);
+ var isValid = this.checkValid(overlayOp);
+ return isValid
+ };
+ OverlayResultValidator.prototype.checkValid = function checkValid () {
+ var this$1 = this;
+
+ if (arguments.length === 1) {
+ var overlayOp = arguments[0];
+ for (var i = 0; i < this._testCoords.size(); i++) {
+ var pt = this$1._testCoords.get(i);
+ if (!this$1.checkValid(overlayOp, pt)) {
+ this$1._invalidLocation = pt;
+ return false
+ }
+ }
+ return true
+ } else if (arguments.length === 2) {
+ var overlayOp$1 = arguments[0];
+ var pt$1 = arguments[1];
+ this._location[0] = this._locFinder[0].getLocation(pt$1);
+ this._location[1] = this._locFinder[1].getLocation(pt$1);
+ this._location[2] = this._locFinder[2].getLocation(pt$1);
+ if (OverlayResultValidator.hasLocation(this._location, Location.BOUNDARY)) { return true }
+ return this.isValidResult(overlayOp$1, this._location)
+ }
+ };
+ OverlayResultValidator.prototype.addTestPts = function addTestPts (g) {
+ var ptGen = new OffsetPointGenerator(g);
+ this._testCoords.addAll(ptGen.getPoints(5 * this._boundaryDistanceTolerance));
+ };
+ OverlayResultValidator.prototype.isValidResult = function isValidResult (overlayOp, location) {
+ var expectedInterior = OverlayOp.isResultOfOp(location[0], location[1], overlayOp);
+ var resultInInterior = location[2] === Location.INTERIOR;
+ var isValid = !(expectedInterior ^ resultInInterior);
+ if (!isValid) { this.reportResult(overlayOp, location, expectedInterior); }
+ return isValid
+ };
+ OverlayResultValidator.prototype.getInvalidLocation = function getInvalidLocation () {
+ return this._invalidLocation
+ };
+ OverlayResultValidator.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ OverlayResultValidator.prototype.getClass = function getClass () {
+ return OverlayResultValidator
+ };
+ OverlayResultValidator.hasLocation = function hasLocation (location, loc) {
+ for (var i = 0; i < 3; i++) {
+ if (location[i] === loc) { return true }
+ }
+ return false
+ };
+ OverlayResultValidator.computeBoundaryDistanceTolerance = function computeBoundaryDistanceTolerance (g0, g1) {
+ return Math.min(GeometrySnapper.computeSizeBasedSnapTolerance(g0), GeometrySnapper.computeSizeBasedSnapTolerance(g1))
+ };
+ OverlayResultValidator.isValid = function isValid (a, b, overlayOp, result) {
+ var validator = new OverlayResultValidator(a, b, result);
+ return validator.isValid(overlayOp)
+ };
+ staticAccessors$46.TOLERANCE.get = function () { return 0.000001 };
+
+ Object.defineProperties( OverlayResultValidator, staticAccessors$46 );
+
+ // operation.overlay
+
+ var GeometryCombiner = function GeometryCombiner (geoms) {
+ this._geomFactory = null;
+ this._skipEmpty = false;
+ this._inputGeoms = null;
+ this._geomFactory = GeometryCombiner.extractFactory(geoms);
+ this._inputGeoms = geoms;
+ };
+ GeometryCombiner.prototype.extractElements = function extractElements (geom, elems) {
+ var this$1 = this;
+
+ if (geom === null) { return null }
+ for (var i = 0; i < geom.getNumGeometries(); i++) {
+ var elemGeom = geom.getGeometryN(i);
+ if (this$1._skipEmpty && elemGeom.isEmpty()) { continue }
+ elems.add(elemGeom);
+ }
+ };
+ GeometryCombiner.prototype.combine = function combine () {
+ var this$1 = this;
+
+ var elems = new ArrayList();
+ for (var i = this._inputGeoms.iterator(); i.hasNext();) {
+ var g = i.next();
+ this$1.extractElements(g, elems);
+ }
+ if (elems.size() === 0) {
+ if (this._geomFactory !== null) {
+ return this._geomFactory.createGeometryCollection(null)
+ }
+ return null
+ }
+ return this._geomFactory.buildGeometry(elems)
+ };
+ GeometryCombiner.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ GeometryCombiner.prototype.getClass = function getClass () {
+ return GeometryCombiner
+ };
+ GeometryCombiner.combine = function combine () {
+ if (arguments.length === 1) {
+ var geoms = arguments[0];
+ var combiner = new GeometryCombiner(geoms);
+ return combiner.combine()
+ } else if (arguments.length === 2) {
+ var g0 = arguments[0];
+ var g1 = arguments[1];
+ var combiner$1 = new GeometryCombiner(GeometryCombiner.createList(g0, g1));
+ return combiner$1.combine()
+ } else if (arguments.length === 3) {
+ var g0$1 = arguments[0];
+ var g1$1 = arguments[1];
+ var g2 = arguments[2];
+ var combiner$2 = new GeometryCombiner(GeometryCombiner.createList(g0$1, g1$1, g2));
+ return combiner$2.combine()
+ }
+ };
+ GeometryCombiner.extractFactory = function extractFactory (geoms) {
+ if (geoms.isEmpty()) { return null }
+ return geoms.iterator().next().getFactory()
+ };
+ GeometryCombiner.createList = function createList () {
+ if (arguments.length === 2) {
+ var obj0 = arguments[0];
+ var obj1 = arguments[1];
+ var list = new ArrayList();
+ list.add(obj0);
+ list.add(obj1);
+ return list
+ } else if (arguments.length === 3) {
+ var obj0$1 = arguments[0];
+ var obj1$1 = arguments[1];
+ var obj2 = arguments[2];
+ var list$1 = new ArrayList();
+ list$1.add(obj0$1);
+ list$1.add(obj1$1);
+ list$1.add(obj2);
+ return list$1
+ }
+ };
+
+ var CascadedPolygonUnion = function CascadedPolygonUnion () {
+ this._inputPolys = null;
+ this._geomFactory = null;
+ var polys = arguments[0];
+ this._inputPolys = polys;
+ if (this._inputPolys === null) { this._inputPolys = new ArrayList(); }
+ };
+
+ var staticAccessors$47 = { STRTREE_NODE_CAPACITY: { configurable: true } };
+ CascadedPolygonUnion.prototype.reduceToGeometries = function reduceToGeometries (geomTree) {
+ var this$1 = this;
+
+ var geoms = new ArrayList();
+ for (var i = geomTree.iterator(); i.hasNext();) {
+ var o = i.next();
+ var geom = null;
+ if (hasInterface(o, List)) {
+ geom = this$1.unionTree(o);
+ } else if (o instanceof Geometry) {
+ geom = o;
+ }
+ geoms.add(geom);
+ }
+ return geoms
+ };
+ CascadedPolygonUnion.prototype.extractByEnvelope = function extractByEnvelope (env, geom, disjointGeoms) {
+ var intersectingGeoms = new ArrayList();
+ for (var i = 0; i < geom.getNumGeometries(); i++) {
+ var elem = geom.getGeometryN(i);
+ if (elem.getEnvelopeInternal().intersects(env)) { intersectingGeoms.add(elem); } else { disjointGeoms.add(elem); }
+ }
+ return this._geomFactory.buildGeometry(intersectingGeoms)
+ };
+ CascadedPolygonUnion.prototype.unionOptimized = function unionOptimized (g0, g1) {
+ var g0Env = g0.getEnvelopeInternal();
+ var g1Env = g1.getEnvelopeInternal();
+ if (!g0Env.intersects(g1Env)) {
+ var combo = GeometryCombiner.combine(g0, g1);
+ return combo
+ }
+ if (g0.getNumGeometries() <= 1 && g1.getNumGeometries() <= 1) { return this.unionActual(g0, g1) }
+ var commonEnv = g0Env.intersection(g1Env);
+ return this.unionUsingEnvelopeIntersection(g0, g1, commonEnv)
+ };
+ CascadedPolygonUnion.prototype.union = function union () {
+ if (this._inputPolys === null) { throw new Error('union() method cannot be called twice') }
+ if (this._inputPolys.isEmpty()) { return null }
+ this._geomFactory = this._inputPolys.iterator().next().getFactory();
+ var index = new STRtree(CascadedPolygonUnion.STRTREE_NODE_CAPACITY);
+ for (var i = this._inputPolys.iterator(); i.hasNext();) {
+ var item = i.next();
+ index.insert(item.getEnvelopeInternal(), item);
+ }
+ this._inputPolys = null;
+ var itemTree = index.itemsTree();
+ var unionAll = this.unionTree(itemTree);
+ return unionAll
+ };
+ CascadedPolygonUnion.prototype.binaryUnion = function binaryUnion () {
+ if (arguments.length === 1) {
+ var geoms = arguments[0];
+ return this.binaryUnion(geoms, 0, geoms.size())
+ } else if (arguments.length === 3) {
+ var geoms$1 = arguments[0];
+ var start = arguments[1];
+ var end = arguments[2];
+ if (end - start <= 1) {
+ var g0 = CascadedPolygonUnion.getGeometry(geoms$1, start);
+ return this.unionSafe(g0, null)
+ } else if (end - start === 2) {
+ return this.unionSafe(CascadedPolygonUnion.getGeometry(geoms$1, start), CascadedPolygonUnion.getGeometry(geoms$1, start + 1))
+ } else {
+ var mid = Math.trunc((end + start) / 2);
+ var g0$1 = this.binaryUnion(geoms$1, start, mid);
+ var g1 = this.binaryUnion(geoms$1, mid, end);
+ return this.unionSafe(g0$1, g1)
+ }
+ }
+ };
+ CascadedPolygonUnion.prototype.repeatedUnion = function repeatedUnion (geoms) {
+ var union = null;
+ for (var i = geoms.iterator(); i.hasNext();) {
+ var g = i.next();
+ if (union === null) { union = g.copy(); } else { union = union.union(g); }
+ }
+ return union
+ };
+ CascadedPolygonUnion.prototype.unionSafe = function unionSafe (g0, g1) {
+ if (g0 === null && g1 === null) { return null }
+ if (g0 === null) { return g1.copy() }
+ if (g1 === null) { return g0.copy() }
+ return this.unionOptimized(g0, g1)
+ };
+ CascadedPolygonUnion.prototype.unionActual = function unionActual (g0, g1) {
+ return CascadedPolygonUnion.restrictToPolygons(g0.union(g1))
+ };
+ CascadedPolygonUnion.prototype.unionTree = function unionTree (geomTree) {
+ var geoms = this.reduceToGeometries(geomTree);
+ var union = this.binaryUnion(geoms);
+ return union
+ };
+ CascadedPolygonUnion.prototype.unionUsingEnvelopeIntersection = function unionUsingEnvelopeIntersection (g0, g1, common) {
+ var disjointPolys = new ArrayList();
+ var g0Int = this.extractByEnvelope(common, g0, disjointPolys);
+ var g1Int = this.extractByEnvelope(common, g1, disjointPolys);
+ var union = this.unionActual(g0Int, g1Int);
+ disjointPolys.add(union);
+ var overallUnion = GeometryCombiner.combine(disjointPolys);
+ return overallUnion
+ };
+ CascadedPolygonUnion.prototype.bufferUnion = function bufferUnion () {
+ if (arguments.length === 1) {
+ var geoms = arguments[0];
+ var factory = geoms.get(0).getFactory();
+ var gColl = factory.buildGeometry(geoms);
+ var unionAll = gColl.buffer(0.0);
+ return unionAll
+ } else if (arguments.length === 2) {
+ var g0 = arguments[0];
+ var g1 = arguments[1];
+ var factory$1 = g0.getFactory();
+ var gColl$1 = factory$1.createGeometryCollection([g0, g1]);
+ var unionAll$1 = gColl$1.buffer(0.0);
+ return unionAll$1
+ }
+ };
+ CascadedPolygonUnion.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ CascadedPolygonUnion.prototype.getClass = function getClass () {
+ return CascadedPolygonUnion
+ };
+ CascadedPolygonUnion.restrictToPolygons = function restrictToPolygons (g) {
+ if (hasInterface(g, Polygonal)) {
+ return g
+ }
+ var polygons = PolygonExtracter.getPolygons(g);
+ if (polygons.size() === 1) { return polygons.get(0) }
+ return g.getFactory().createMultiPolygon(GeometryFactory.toPolygonArray(polygons))
+ };
+ CascadedPolygonUnion.getGeometry = function getGeometry (list, index) {
+ if (index >= list.size()) { return null }
+ return list.get(index)
+ };
+ CascadedPolygonUnion.union = function union (polys) {
+ var op = new CascadedPolygonUnion(polys);
+ return op.union()
+ };
+ staticAccessors$47.STRTREE_NODE_CAPACITY.get = function () { return 4 };
+
+ Object.defineProperties( CascadedPolygonUnion, staticAccessors$47 );
+
+ var UnionOp = function UnionOp () {};
+
+ UnionOp.prototype.interfaces_ = function interfaces_ () {
+ return []
+ };
+ UnionOp.prototype.getClass = function getClass () {
+ return UnionOp
+ };
+ UnionOp.union = function union (g, other) {
+ if (g.isEmpty() || other.isEmpty()) {
+ if (g.isEmpty() && other.isEmpty()) { return OverlayOp.createEmptyResult(OverlayOp.UNION, g, other, g.getFactory()) }
+ if (g.isEmpty()) { return other.copy() }
+ if (other.isEmpty()) { return g.copy() }
+ }
+ g.checkNotGeometryCollection(g);
+ g.checkNotGeometryCollection(other);
+ return SnapIfNeededOverlayOp.overlayOp(g, other, OverlayOp.UNION)
+ };
+
+ /**
+ * Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth.
+ */
+
+ /**
+ * Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}.
+ *
+ * @name feature
+ * @param {Geometry} geometry input geometry
+ * @param {Object} [properties={}] an Object of key-value pairs to add as properties
+ * @param {Object} [options={}] Optional Parameters
+ * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
+ * @param {string|number} [options.id] Identifier associated with the Feature
+ * @returns {Feature} a GeoJSON Feature
+ * @example
+ * var geometry = {
+ * "type": "Point",
+ * "coordinates": [110, 50]
+ * };
+ *
+ * var feature = turf.feature(geometry);
+ *
+ * //=feature
+ */
+ function feature$1(geometry, properties, options) {
+ // Optional Parameters
+ options = options || {};
+ if (!isObject$2(options)) throw new Error('options is invalid');
+ var bbox = options.bbox;
+ var id = options.id;
+
+ // Validation
+ if (geometry === undefined) throw new Error('geometry is required');
+ if (properties && properties.constructor !== Object) throw new Error('properties must be an Object');
+ if (bbox) validateBBox(bbox);
+ if (id) validateId(id);
+
+ // Main
+ var feat = {type: 'Feature'};
+ if (id) feat.id = id;
+ if (bbox) feat.bbox = bbox;
+ feat.properties = properties || {};
+ feat.geometry = geometry;
+ return feat;
+ }
+
+ /**
+ * isNumber
+ *
+ * @param {*} num Number to validate
+ * @returns {boolean} true/false
+ * @example
+ * turf.isNumber(123)
+ * //=true
+ * turf.isNumber('foo')
+ * //=false
+ */
+ function isNumber$1(num) {
+ return !isNaN(num) && num !== null && !Array.isArray(num);
+ }
+
+ /**
+ * isObject
+ *
+ * @param {*} input variable to validate
+ * @returns {boolean} true/false
+ * @example
+ * turf.isObject({elevation: 10})
+ * //=true
+ * turf.isObject('foo')
+ * //=false
+ */
+ function isObject$2(input) {
+ return (!!input) && (input.constructor === Object);
+ }
+
+ /**
+ * Validate BBox
+ *
+ * @private
+ * @param {Array} bbox BBox to validate
+ * @returns {void}
+ * @throws Error if BBox is not valid
+ * @example
+ * validateBBox([-180, -40, 110, 50])
+ * //=OK
+ * validateBBox([-180, -40])
+ * //=Error
+ * validateBBox('Foo')
+ * //=Error
+ * validateBBox(5)
+ * //=Error
+ * validateBBox(null)
+ * //=Error
+ * validateBBox(undefined)
+ * //=Error
+ */
+ function validateBBox(bbox) {
+ if (!bbox) throw new Error('bbox is required');
+ if (!Array.isArray(bbox)) throw new Error('bbox must be an Array');
+ if (bbox.length !== 4 && bbox.length !== 6) throw new Error('bbox must be an Array of 4 or 6 numbers');
+ bbox.forEach(function (num) {
+ if (!isNumber$1(num)) throw new Error('bbox must only contain numbers');
+ });
+ }
+
+ /**
+ * Validate Id
+ *
+ * @private
+ * @param {string|number} id Id to validate
+ * @returns {void}
+ * @throws Error if Id is not valid
+ * @example
+ * validateId([-180, -40, 110, 50])
+ * //=Error
+ * validateId([-180, -40])
+ * //=Error
+ * validateId('Foo')
+ * //=OK
+ * validateId(5)
+ * //=OK
+ * validateId(null)
+ * //=Error
+ * validateId(undefined)
+ * //=Error
+ */
+ function validateId(id) {
+ if (!id) throw new Error('id is required');
+ if (['string', 'number'].indexOf(typeof id) === -1) throw new Error('id must be a number or a string');
+ }
+
+ /**
+ * Callback for geomEach
+ *
+ * @callback geomEachCallback
+ * @param {Geometry} currentGeometry The current Geometry being processed.
+ * @param {number} featureIndex The current index of the Feature being processed.
+ * @param {Object} featureProperties The current Feature Properties being processed.
+ * @param {Array} featureBBox The current Feature BBox being processed.
+ * @param {number|string} featureId The current Feature Id being processed.
+ */
+
+ /**
+ * Iterate over each geometry in any GeoJSON object, similar to Array.forEach()
+ *
+ * @name geomEach
+ * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
+ * @param {Function} callback a method that takes (currentGeometry, featureIndex, featureProperties, featureBBox, featureId)
+ * @returns {void}
+ * @example
+ * var features = turf.featureCollection([
+ * turf.point([26, 37], {foo: 'bar'}),
+ * turf.point([36, 53], {hello: 'world'})
+ * ]);
+ *
+ * turf.geomEach(features, function (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {
+ * //=currentGeometry
+ * //=featureIndex
+ * //=featureProperties
+ * //=featureBBox
+ * //=featureId
+ * });
+ */
+ function geomEach(geojson, callback) {
+ var i, j, g, geometry, stopG,
+ geometryMaybeCollection,
+ isGeometryCollection,
+ featureProperties,
+ featureBBox,
+ featureId,
+ featureIndex = 0,
+ isFeatureCollection = geojson.type === 'FeatureCollection',
+ isFeature = geojson.type === 'Feature',
+ stop = isFeatureCollection ? geojson.features.length : 1;
+
+ // This logic may look a little weird. The reason why it is that way
+ // is because it's trying to be fast. GeoJSON supports multiple kinds
+ // of objects at its root: FeatureCollection, Features, Geometries.
+ // This function has the responsibility of handling all of them, and that
+ // means that some of the `for` loops you see below actually just don't apply
+ // to certain inputs. For instance, if you give this just a
+ // Point geometry, then both loops are short-circuited and all we do
+ // is gradually rename the input until it's called 'geometry'.
+ //
+ // This also aims to allocate as few resources as possible: just a
+ // few numbers and booleans, rather than any temporary arrays as would
+ // be required with the normalization approach.
+ for (i = 0; i < stop; i++) {
+
+ geometryMaybeCollection = (isFeatureCollection ? geojson.features[i].geometry :
+ (isFeature ? geojson.geometry : geojson));
+ featureProperties = (isFeatureCollection ? geojson.features[i].properties :
+ (isFeature ? geojson.properties : {}));
+ featureBBox = (isFeatureCollection ? geojson.features[i].bbox :
+ (isFeature ? geojson.bbox : undefined));
+ featureId = (isFeatureCollection ? geojson.features[i].id :
+ (isFeature ? geojson.id : undefined));
+ isGeometryCollection = (geometryMaybeCollection) ? geometryMaybeCollection.type === 'GeometryCollection' : false;
+ stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;
+
+ for (g = 0; g < stopG; g++) {
+ geometry = isGeometryCollection ?
+ geometryMaybeCollection.geometries[g] : geometryMaybeCollection;
+
+ // Handle null Geometry
+ if (geometry === null) {
+ if (callback(null, featureIndex, featureProperties, featureBBox, featureId) === false) return false;
+ continue;
+ }
+ switch (geometry.type) {
+ case 'Point':
+ case 'LineString':
+ case 'MultiPoint':
+ case 'Polygon':
+ case 'MultiLineString':
+ case 'MultiPolygon': {
+ if (callback(geometry, featureIndex, featureProperties, featureBBox, featureId) === false) return false;
+ break;
+ }
+ case 'GeometryCollection': {
+ for (j = 0; j < geometry.geometries.length; j++) {
+ if (callback(geometry.geometries[j], featureIndex, featureProperties, featureBBox, featureId) === false) return false;
+ }
+ break;
+ }
+ default:
+ throw new Error('Unknown Geometry Type');
+ }
+ }
+ // Only increase `featureIndex` per each feature
+ featureIndex++;
+ }
+ }
+
+ /**
+ * Callback for geomReduce
+ *
+ * The first time the callback function is called, the values provided as arguments depend
+ * on whether the reduce method has an initialValue argument.
+ *
+ * If an initialValue is provided to the reduce method:
+ * - The previousValue argument is initialValue.
+ * - The currentValue argument is the value of the first element present in the array.
+ *
+ * If an initialValue is not provided:
+ * - The previousValue argument is the value of the first element present in the array.
+ * - The currentValue argument is the value of the second element present in the array.
+ *
+ * @callback geomReduceCallback
+ * @param {*} previousValue The accumulated value previously returned in the last invocation
+ * of the callback, or initialValue, if supplied.
+ * @param {Geometry} currentGeometry The current Geometry being processed.
+ * @param {number} featureIndex The current index of the Feature being processed.
+ * @param {Object} featureProperties The current Feature Properties being processed.
+ * @param {Array} featureBBox The current Feature BBox being processed.
+ * @param {number|string} featureId The current Feature Id being processed.
+ */
+
+ /**
+ * Reduce geometry in any GeoJSON object, similar to Array.reduce().
+ *
+ * @name geomReduce
+ * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
+ * @param {Function} callback a method that takes (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId)
+ * @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
+ * @returns {*} The value that results from the reduction.
+ * @example
+ * var features = turf.featureCollection([
+ * turf.point([26, 37], {foo: 'bar'}),
+ * turf.point([36, 53], {hello: 'world'})
+ * ]);
+ *
+ * turf.geomReduce(features, function (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {
+ * //=previousValue
+ * //=currentGeometry
+ * //=featureIndex
+ * //=featureProperties
+ * //=featureBBox
+ * //=featureId
+ * return currentGeometry
+ * });
+ */
+ function geomReduce(geojson, callback, initialValue) {
+ var previousValue = initialValue;
+ geomEach(geojson, function (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {
+ if (featureIndex === 0 && initialValue === undefined) previousValue = currentGeometry;
+ else previousValue = callback(previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId);
+ });
+ return previousValue;
+ }
+
+ /**
+ * Callback for flattenEach
+ *
+ * @callback flattenEachCallback
+ * @param {Feature} currentFeature The current flattened feature being processed.
+ * @param {number} featureIndex The current index of the Feature being processed.
+ * @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
+ */
+
+ /**
+ * Iterate over flattened features in any GeoJSON object, similar to
+ * Array.forEach.
+ *
+ * @name flattenEach
+ * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
+ * @param {Function} callback a method that takes (currentFeature, featureIndex, multiFeatureIndex)
+ * @example
+ * var features = turf.featureCollection([
+ * turf.point([26, 37], {foo: 'bar'}),
+ * turf.multiPoint([[40, 30], [36, 53]], {hello: 'world'})
+ * ]);
+ *
+ * turf.flattenEach(features, function (currentFeature, featureIndex, multiFeatureIndex) {
+ * //=currentFeature
+ * //=featureIndex
+ * //=multiFeatureIndex
+ * });
+ */
+ function flattenEach(geojson, callback) {
+ geomEach(geojson, function (geometry, featureIndex, properties, bbox, id) {
+ // Callback for single geometry
+ var type = (geometry === null) ? null : geometry.type;
+ switch (type) {
+ case null:
+ case 'Point':
+ case 'LineString':
+ case 'Polygon':
+ if (callback(feature$1(geometry, properties, {bbox: bbox, id: id}), featureIndex, 0) === false) return false;
+ return;
+ }
+
+ var geomType;
+
+ // Callback for multi-geometry
+ switch (type) {
+ case 'MultiPoint':
+ geomType = 'Point';
+ break;
+ case 'MultiLineString':
+ geomType = 'LineString';
+ break;
+ case 'MultiPolygon':
+ geomType = 'Polygon';
+ break;
+ }
+
+ for (var multiFeatureIndex = 0; multiFeatureIndex < geometry.coordinates.length; multiFeatureIndex++) {
+ var coordinate = geometry.coordinates[multiFeatureIndex];
+ var geom = {
+ type: geomType,
+ coordinates: coordinate
+ };
+ if (callback(feature$1(geom, properties), featureIndex, multiFeatureIndex) === false) return false;
+ }
+ });
+ }
+
+ /**
+ * Takes one or more features and returns their area in square meters.
+ *
+ * @name area
+ * @param {GeoJSON} geojson input GeoJSON feature(s)
+ * @returns {number} area in square meters
+ * @example
+ * var polygon = turf.polygon([[[125, -15], [113, -22], [154, -27], [144, -15], [125, -15]]]);
+ *
+ * var area = turf.area(polygon);
+ *
+ * //addToMap
+ * var addToMap = [polygon]
+ * polygon.properties.area = area
+ */
+ function area(geojson) {
+ return geomReduce(geojson, function (value, geom) {
+ return value + calculateArea(geom);
+ }, 0);
+ }
+
+ var RADIUS$1 = 6378137;
+ // var FLATTENING_DENOM = 298.257223563;
+ // var FLATTENING = 1 / FLATTENING_DENOM;
+ // var POLAR_RADIUS = RADIUS * (1 - FLATTENING);
+
+ /**
+ * Calculate Area
+ *
+ * @private
+ * @param {GeoJSON} geojson GeoJSON
+ * @returns {number} area
+ */
+ function calculateArea(geojson) {
+ var area = 0, i;
+ switch (geojson.type) {
+ case 'Polygon':
+ return polygonArea$1(geojson.coordinates);
+ case 'MultiPolygon':
+ for (i = 0; i < geojson.coordinates.length; i++) {
+ area += polygonArea$1(geojson.coordinates[i]);
+ }
+ return area;
+ case 'Point':
+ case 'MultiPoint':
+ case 'LineString':
+ case 'MultiLineString':
+ return 0;
+ case 'GeometryCollection':
+ for (i = 0; i < geojson.geometries.length; i++) {
+ area += calculateArea(geojson.geometries[i]);
+ }
+ return area;
+ }
+ }
+
+ function polygonArea$1(coords) {
+ var area = 0;
+ if (coords && coords.length > 0) {
+ area += Math.abs(ringArea$1(coords[0]));
+ for (var i = 1; i < coords.length; i++) {
+ area -= Math.abs(ringArea$1(coords[i]));
+ }
+ }
+ return area;
+ }
+
+ /**
+ * @private
+ * Calculate the approximate area of the polygon were it projected onto the earth.
+ * Note that this area will be positive if ring is oriented clockwise, otherwise it will be negative.
+ *
+ * Reference:
+ * Robert. G. Chamberlain and William H. Duquette, "Some Algorithms for Polygons on a Sphere", JPL Publication 07-03, Jet Propulsion
+ * Laboratory, Pasadena, CA, June 2007 http://trs-new.jpl.nasa.gov/dspace/handle/2014/40409
+ *
+ * @param {Array>} coords Ring Coordinates
+ * @returns {number} The approximate signed geodesic area of the polygon in square meters.
+ */
+ function ringArea$1(coords) {
+ var p1;
+ var p2;
+ var p3;
+ var lowerIndex;
+ var middleIndex;
+ var upperIndex;
+ var i;
+ var area = 0;
+ var coordsLength = coords.length;
+
+ if (coordsLength > 2) {
+ for (i = 0; i < coordsLength; i++) {
+ if (i === coordsLength - 2) { // i = N-2
+ lowerIndex = coordsLength - 2;
+ middleIndex = coordsLength - 1;
+ upperIndex = 0;
+ } else if (i === coordsLength - 1) { // i = N-1
+ lowerIndex = coordsLength - 1;
+ middleIndex = 0;
+ upperIndex = 1;
+ } else { // i = 0 to N-3
+ lowerIndex = i;
+ middleIndex = i + 1;
+ upperIndex = i + 2;
+ }
+ p1 = coords[lowerIndex];
+ p2 = coords[middleIndex];
+ p3 = coords[upperIndex];
+ area += (rad$1(p3[0]) - rad$1(p1[0])) * Math.sin(rad$1(p2[1]));
+ }
+
+ area = area * RADIUS$1 * RADIUS$1 / 2;
+ }
+
+ return area;
+ }
+
+ function rad$1(_) {
+ return _ * Math.PI / 180;
+ }
+
+ /**
+ * Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth.
+ */
+
+ /**
+ * Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}.
+ *
+ * @name feature
+ * @param {Geometry} geometry input geometry
+ * @param {Object} [properties={}] an Object of key-value pairs to add as properties
+ * @param {Object} [options={}] Optional Parameters
+ * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
+ * @param {string|number} [options.id] Identifier associated with the Feature
+ * @returns {Feature} a GeoJSON Feature
+ * @example
+ * var geometry = {
+ * "type": "Point",
+ * "coordinates": [110, 50]
+ * };
+ *
+ * var feature = turf.feature(geometry);
+ *
+ * //=feature
+ */
+ function feature$2(geometry, properties, options) {
+ // Optional Parameters
+ options = options || {};
+ if (!isObject$3(options)) throw new Error('options is invalid');
+ var bbox = options.bbox;
+ var id = options.id;
+
+ // Validation
+ if (geometry === undefined) throw new Error('geometry is required');
+ if (properties && properties.constructor !== Object) throw new Error('properties must be an Object');
+ if (bbox) validateBBox$1(bbox);
+ if (id) validateId$1(id);
+
+ // Main
+ var feat = {type: 'Feature'};
+ if (id) feat.id = id;
+ if (bbox) feat.bbox = bbox;
+ feat.properties = properties || {};
+ feat.geometry = geometry;
+ return feat;
+ }
+
+ /**
+ * isNumber
+ *
+ * @param {*} num Number to validate
+ * @returns {boolean} true/false
+ * @example
+ * turf.isNumber(123)
+ * //=true
+ * turf.isNumber('foo')
+ * //=false
+ */
+ function isNumber$2(num) {
+ return !isNaN(num) && num !== null && !Array.isArray(num);
+ }
+
+ /**
+ * isObject
+ *
+ * @param {*} input variable to validate
+ * @returns {boolean} true/false
+ * @example
+ * turf.isObject({elevation: 10})
+ * //=true
+ * turf.isObject('foo')
+ * //=false
+ */
+ function isObject$3(input) {
+ return (!!input) && (input.constructor === Object);
+ }
+
+ /**
+ * Validate BBox
+ *
+ * @private
+ * @param {Array} bbox BBox to validate
+ * @returns {void}
+ * @throws Error if BBox is not valid
+ * @example
+ * validateBBox([-180, -40, 110, 50])
+ * //=OK
+ * validateBBox([-180, -40])
+ * //=Error
+ * validateBBox('Foo')
+ * //=Error
+ * validateBBox(5)
+ * //=Error
+ * validateBBox(null)
+ * //=Error
+ * validateBBox(undefined)
+ * //=Error
+ */
+ function validateBBox$1(bbox) {
+ if (!bbox) throw new Error('bbox is required');
+ if (!Array.isArray(bbox)) throw new Error('bbox must be an Array');
+ if (bbox.length !== 4 && bbox.length !== 6) throw new Error('bbox must be an Array of 4 or 6 numbers');
+ bbox.forEach(function (num) {
+ if (!isNumber$2(num)) throw new Error('bbox must only contain numbers');
+ });
+ }
+
+ /**
+ * Validate Id
+ *
+ * @private
+ * @param {string|number} id Id to validate
+ * @returns {void}
+ * @throws Error if Id is not valid
+ * @example
+ * validateId([-180, -40, 110, 50])
+ * //=Error
+ * validateId([-180, -40])
+ * //=Error
+ * validateId('Foo')
+ * //=OK
+ * validateId(5)
+ * //=OK
+ * validateId(null)
+ * //=Error
+ * validateId(undefined)
+ * //=Error
+ */
+ function validateId$1(id) {
+ if (!id) throw new Error('id is required');
+ if (['string', 'number'].indexOf(typeof id) === -1) throw new Error('id must be a number or a string');
+ }
+
+ /**
+ * Get Geometry from Feature or Geometry Object
+ *
+ * @param {Feature|Geometry} geojson GeoJSON Feature or Geometry Object
+ * @returns {Geometry|null} GeoJSON Geometry Object
+ * @throws {Error} if geojson is not a Feature or Geometry Object
+ * @example
+ * var point = {
+ * "type": "Feature",
+ * "properties": {},
+ * "geometry": {
+ * "type": "Point",
+ * "coordinates": [110, 40]
+ * }
+ * }
+ * var geom = turf.getGeom(point)
+ * //={"type": "Point", "coordinates": [110, 40]}
+ */
+ function getGeom(geojson) {
+ if (!geojson) throw new Error('geojson is required');
+ if (geojson.geometry !== undefined) return geojson.geometry;
+ if (geojson.coordinates || geojson.geometries) return geojson;
+ throw new Error('geojson must be a valid Feature or Geometry Object');
+ }
+
+ /**
+ * Finds the difference between two {@link Polygon|polygons} by clipping the second polygon from the first.
+ *
+ * @name difference
+ * @param {Feature} polygon1 input Polygon feature
+ * @param {Feature} polygon2 Polygon feature to difference from polygon1
+ * @returns {Feature|null} a Polygon or MultiPolygon feature showing the area of `polygon1` excluding the area of `polygon2` (if empty returns `null`)
+ * @example
+ * var polygon1 = turf.polygon([[
+ * [128, -26],
+ * [141, -26],
+ * [141, -21],
+ * [128, -21],
+ * [128, -26]
+ * ]], {
+ * "fill": "#F00",
+ * "fill-opacity": 0.1
+ * });
+ * var polygon2 = turf.polygon([[
+ * [126, -28],
+ * [140, -28],
+ * [140, -20],
+ * [126, -20],
+ * [126, -28]
+ * ]], {
+ * "fill": "#00F",
+ * "fill-opacity": 0.1
+ * });
+ *
+ * var difference = turf.difference(polygon1, polygon2);
+ *
+ * //addToMap
+ * var addToMap = [polygon1, polygon2, difference];
+ */
+ function difference(polygon1, polygon2) {
+ var geom1 = getGeom(polygon1);
+ var geom2 = getGeom(polygon2);
+ var properties = polygon1.properties || {};
+
+ // Issue #721 - JSTS can't handle empty polygons
+ geom1 = removeEmptyPolygon(geom1);
+ geom2 = removeEmptyPolygon(geom2);
+ if (!geom1) return null;
+ if (!geom2) return feature$2(geom1, properties);
+
+ // JSTS difference operation
+ var reader = new GeoJSONReader();
+ var a = reader.read(geom1);
+ var b = reader.read(geom2);
+ var differenced = OverlayOp.difference(a, b);
+ if (differenced.isEmpty()) return null;
+ var writer = new GeoJSONWriter();
+ var geom = writer.write(differenced);
+
+ return feature$2(geom, properties);
+ }
+
+ /**
+ * Detect Empty Polygon
+ *
+ * @private
+ * @param {Geometry} geom Geometry Object
+ * @returns {Geometry|null} removed any polygons with no areas
+ */
+ function removeEmptyPolygon(geom) {
+ switch (geom.type) {
+ case 'Polygon':
+ if (area(geom) > 1) return geom;
+ return null;
+ case 'MultiPolygon':
+ var coordinates = [];
+ flattenEach(geom, function (feature$$1) {
+ if (area(feature$$1) > 1) coordinates.push(feature$$1.geometry.coordinates);
+ });
+ if (coordinates.length) return {type: 'MultiPolygon', coordinates: coordinates};
+ }
+ }
+
+ /**
+ * Takes two or more {@link Polygon|polygons} and returns a combined polygon. If the input polygons are not contiguous, this function returns a {@link MultiPolygon} feature.
+ *
+ * @name union
+ * @param {...Feature} A polygon to combine
+ * @returns {Feature<(Polygon|MultiPolygon)>} a combined {@link Polygon} or {@link MultiPolygon} feature
+ * @example
+ * var poly1 = turf.polygon([[
+ * [-82.574787, 35.594087],
+ * [-82.574787, 35.615581],
+ * [-82.545261, 35.615581],
+ * [-82.545261, 35.594087],
+ * [-82.574787, 35.594087]
+ * ]], {"fill": "#0f0"});
+ * var poly2 = turf.polygon([[
+ * [-82.560024, 35.585153],
+ * [-82.560024, 35.602602],
+ * [-82.52964, 35.602602],
+ * [-82.52964, 35.585153],
+ * [-82.560024, 35.585153]
+ * ]], {"fill": "#00f"});
+ *
+ * var union = turf.union(poly1, poly2);
+ *
+ * //addToMap
+ * var addToMap = [poly1, poly2, union];
+ */
+ function union() {
+ var reader = new GeoJSONReader();
+ var result = reader.read(JSON.stringify(arguments[0].geometry));
+
+ for (var i = 1; i < arguments.length; i++) {
+ result = UnionOp.union(result, reader.read(JSON.stringify(arguments[i].geometry)));
+ }
+
+ var writer = new GeoJSONWriter();
+ result = writer.write(result);
+
+ return {
+ type: 'Feature',
+ geometry: result,
+ properties: arguments[0].properties
+ };
+ }
+
+ // Reduce an array of locations into a single GeoJSON feature
+ function _locationReducer(accumulator, location) {
+ /* eslint-disable no-console, no-invalid-this */
+ let result;
+ try {
+ let resolved = this.resolveLocation(location);
+ if (!resolved || !resolved.feature) {
+ console.warn(`Warning: Couldn't resolve location "${location}"`);
+ return accumulator;
+ }
+ result = !accumulator ? resolved.feature : union(accumulator, resolved.feature);
+ } catch (e) {
+ console.warn(`Warning: Error resolving location "${location}"`);
+ console.warn(e);
+ result = accumulator;
+ }
+
+ return result;
+ /* eslint-enable no-console, no-invalid-this */
+ }
+
+
+
+ function _cloneDeep(obj) {
+ return JSON.parse(JSON.stringify(obj));
+ }
+
+
+ class LocationConflation {
+
+ // constructor
+ //
+ // Optionally pass a GeoJSON FeatureCollection of known features which we can refer to later.
+ // Each feature must have a filename-like `id`, for example: `something.geojson`
+ //
+ // {
+ // "type": "FeatureCollection"
+ // "features": [
+ // {
+ // "type": "Feature",
+ // "id": "philly_metro.geojson",
+ // "properties": { … },
+ // "geometry": { … }
+ // }
+ // ]
+ // }
+ constructor(fc) {
+ this._cache = {};
+
+ // process input FeatureCollection
+ if (fc && fc.type === 'FeatureCollection' && Array.isArray(fc.features)) {
+ fc.features.forEach(feature => {
+ feature.properties = feature.properties || {};
+ let props = feature.properties;
+
+ // get `id` from either `id` or `properties`
+ let id = feature.id || props.id;
+ if (!id || !/^\S+\.geojson$/i.test(id)) return;
+
+ // ensure id exists and is lowercase
+ id = id.toLowerCase();
+ feature.id = id;
+ props.id = id;
+
+ // ensure area property exists
+ if (!props.area) {
+ const area = geojsonArea.geometry(feature.geometry) / 1e6; // m² to km²
+ props.area = Number(area.toFixed(2));
+ }
+
+ this._cache[id] = feature;
+ });
+ }
+
+ // Replace CountryCoder world geometry to have a polygon covering the world.
+ let world = _cloneDeep(feature('Q2'));
+ world.geometry = {
+ type: 'Polygon',
+ coordinates: [[[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]]]
+ };
+ world.id = 'Q2';
+ world.properties.id = 'Q2';
+ world.properties.area = geojsonArea.geometry(world.geometry) / 1e6; // m² to km²
+ this._cache.Q2 = world;
+ }
+
+
+ // validateLocation
+ //
+ // Pass a `location` identifier
+ // Returns a result like
+ // {
+ // type: 'point', 'geojson', or 'countrycoder'
+ // location: the queried location
+ // id: a unique identifier
+ // }
+ // or `null` if the location is invalid
+ //
+ validateLocation(location) {
+ if (Array.isArray(location)) { // a [lon,lat] coordinate pair?
+ if (location.length === 2 && Number.isFinite(location[0]) && Number.isFinite(location[1]) &&
+ location[0] >= -180 && location[0] <= 180 && location[1] >= -90 && location[1] <= 90
+ ) {
+ const id = '[' + location.toString() + ']';
+ return { type: 'point', location: location, id: id };
+ }
+
+ } else if (typeof location === 'string' && /^\S+\.geojson$/i.test(location)) { // a .geojson filename?
+ const id = location.toLowerCase();
+ if (this._cache[id]) {
+ return { type: 'geojson', location: location, id: id };
+ }
+
+ } else if (typeof location === 'string' || typeof location === 'number') { // a country-coder value?
+ const feature$1 = feature(location);
+ if (feature$1) {
+ // Use wikidata QID as the identifier, since that seems to be the only
+ // property that everything in CountryCoder is guaranteed to have.
+ const id = feature$1.properties.wikidata;
+ return { type: 'countrycoder', location: location, id: id };
+ }
+ }
+
+ return null;
+ }
+
+
+ // resolveLocation
+ //
+ // Pass a `location` identifier
+ // Returns a result like
+ // {
+ // type: 'point', 'geojson', or 'countrycoder'
+ // location: the queried location
+ // id: a unique identifier
+ // feature: the geojson feature
+ // }
+ // or `null` if the location is invalid
+ //
+ resolveLocation(location) {
+ const valid = this.validateLocation(location);
+ if (!valid) return null;
+
+ // return a result from cache if we can
+ if (this._cache[valid.id]) {
+ return Object.assign(valid, { feature: this._cache[valid.id] });
+ }
+
+ // a [lon,lat] coordinate pair?
+ if (valid.type === 'point') {
+ const RADIUS = 25000; // meters
+ const EDGES = 10;
+ const PRECISION = 3;
+ const area = Math.PI * RADIUS * RADIUS / 1e6; // m² to km²
+ const feature = this._cache[valid.id] = geojsonPrecision({
+ type: 'Feature',
+ id: valid.id,
+ properties: { id: valid.id, area: Number(area.toFixed(2)) },
+ geometry: circleToPolygon(location, RADIUS, EDGES)
+ }, PRECISION);
+ return Object.assign(valid, { feature: feature });
+
+ // a .geojson filename?
+ } else if (valid.type === 'geojson') ; else if (valid.type === 'countrycoder') {
+ let feature$1 = _cloneDeep(feature(valid.id));
+ let props = feature$1.properties;
+
+ // -> This block of code is weird and requires some explanation. <-
+ // CountryCoder includes higher level features which are made up of members.
+ // These features don't have their own geometry, but CountryCoder provides an
+ // `aggregateFeature` method to combine these members into a MultiPolygon.
+ // BUT, when we try to actually work with these aggregated MultiPolygons,
+ // Turf/JSTS gets crashy because of topography bugs.
+ // SO, we'll aggregate the features ourselves by unioning them together.
+ // This approach also has the benefit of removing all the internal boaders and
+ // simplifying the regional polygons a lot.
+ if (Array.isArray(props.members)) {
+ let seed = feature$1.geometry ? feature$1 : null;
+ let aggregate = props.members.reduce(_locationReducer.bind(this), seed);
+ feature$1.geometry = aggregate.geometry;
+ }
+
+ // ensure area property exists
+ if (!props.area) {
+ const area = geojsonArea.geometry(feature$1.geometry) / 1e6; // m² to km²
+ props.area = Number(area.toFixed(2));
+ }
+
+ // ensure id property exists
+ feature$1.id = valid.id;
+ props.id = valid.id;
+
+ this._cache[valid.id] = feature$1;
+ return Object.assign(valid, { feature: feature$1 });
+ }
+
+ return null;
+ }
+
+
+ // resolveLocationSet
+ //
+ // Pass a `locationSet` Object like:
+ // `{ include: [ Array ], exclude: [ Array ] }`
+ // Returns a stable identifier string of the form:
+ // "+[included]-[excluded]"
+ //
+ resolveLocationSet(locationSet) {
+ locationSet = locationSet || {};
+ const resolve = this.resolveLocation.bind(this);
+ let include = (locationSet.include || []).map(resolve).filter(Boolean);
+ let exclude = (locationSet.exclude || []).map(resolve).filter(Boolean);
+
+ if (!include.length) {
+ include = [resolve('Q2')]; // default to 'the world'
+ }
+
+ // return quickly if it's a single included location..
+ if (include.length === 1 && exclude.length === 0) {
+ return include[0].feature;
+ }
+
+ // generate stable identifier
+ include.sort(sortFeatures);
+ let id = '+[' + include.map(d => d.id).join(',') + ']';
+ if (exclude.length) {
+ exclude.sort(sortFeatures);
+ id += '-[' + exclude.map(d => d.id).join(',') + ']';
+ }
+
+ // return cached?
+ if (this._cache[id]) {
+ return this._cache[id];
+ }
+
+ // calculate unions
+ let includeGeoJSON = include.map(d => d.location).reduce(_locationReducer.bind(this), null);
+ let excludeGeoJSON = exclude.map(d => d.location).reduce(_locationReducer.bind(this), null);
+
+ // calculate difference, update area and return result
+ let resultGeoJSON = excludeGeoJSON ? difference(includeGeoJSON, excludeGeoJSON) : includeGeoJSON;
+ const area = geojsonArea.geometry(resultGeoJSON.geometry) / 1e6; // m² to km²
+ resultGeoJSON.id = id;
+ resultGeoJSON.properties = { id: id, area: Number(area.toFixed(2)) };
+
+ return this._cache[id] = resultGeoJSON;
+
+
+ // Sorting the location lists is ok because they end up unioned together.
+ // This sorting makes it possible to generate a deterministic id.
+ function sortFeatures(a, b) {
+ const rank = { countrycoder: 1, geojson: 2, point: 3 };
+ const aRank = rank[a.type];
+ const bRank = rank[b.type];
+
+ return (aRank > bRank) ? 1
+ : (aRank < bRank) ? -1
+ : a.id.localeCompare(b.id);
+ }
+ }
+
+
+ cache() {
+ return this._cache;
+ }
+ }
+
+ let _oci = null;
+
+ function uiSuccess(context) {
+ const MAXEVENTS = 2;
+ const dispatch$1 = dispatch('cancel');
+ let _changeset;
+ let _location;
+ ensureOSMCommunityIndex(); // start fetching the data
+
+
+ function ensureOSMCommunityIndex() {
+ const data = _mainFileFetcher;
+ return Promise.all([ data.get('oci_resources'), data.get('oci_features') ])
+ .then(vals => {
+ if (_oci) return _oci;
+
+ const ociResources = vals[0].resources;
+ const loco = new LocationConflation(vals[1]);
+ let ociFeatures = {};
+
+ Object.values(ociResources).forEach(resource => {
+ const feature = loco.resolveLocationSet(resource.locationSet);
+ let ociFeature = ociFeatures[feature.id];
+ if (!ociFeature) {
+ ociFeature = JSON.parse(JSON.stringify(feature)); // deep clone
+ ociFeature.properties.resourceIDs = new Set();
+ ociFeatures[feature.id] = ociFeature;
+ }
+ ociFeature.properties.resourceIDs.add(resource.id);
+ });
+
+ return _oci = {
+ features: ociFeatures,
+ resources: ociResources,
+ query: whichPolygon_1({ type: 'FeatureCollection', features: Object.values(ociFeatures) })
+ };
+ });
+ }
+
+
+ // string-to-date parsing in JavaScript is weird
+ function parseEventDate(when) {
+ if (!when) return;
+
+ let raw = when.trim();
+ if (!raw) return;
+
+ if (!/Z$/.test(raw)) { // if no trailing 'Z', add one
+ raw += 'Z'; // this forces date to be parsed as a UTC date
+ }
+
+ const parsed = new Date(raw);
+ return new Date(parsed.toUTCString().substr(0, 25)); // convert to local timezone
+ }
+
+
+ function success(selection) {
+ let header = selection
+ .append('div')
+ .attr('class', 'header fillL');
+
+ header
+ .append('h3')
+ .text(_t('success.just_edited'));
+
+ header
+ .append('button')
+ .attr('class', 'close')
+ .on('click', () => dispatch$1.call('cancel'))
+ .call(svgIcon('#iD-icon-close'));
+
+ let body = selection
+ .append('div')
+ .attr('class', 'body save-success fillL');
+
+ let summary = body
+ .append('div')
+ .attr('class', 'save-summary');
+
+ summary
+ .append('h3')
+ .text(_t('success.thank_you' + (_location ? '_location' : ''), { where: _location }));
+
+ summary
+ .append('p')
+ .text(_t('success.help_html'))
+ .append('a')
+ .attr('class', 'link-out')
+ .attr('target', '_blank')
+ .attr('tabindex', -1)
+ .attr('href', _t('success.help_link_url'))
+ .call(svgIcon('#iD-icon-out-link', 'inline'))
+ .append('span')
+ .text(_t('success.help_link_text'));
+
+ let osm = context.connection();
+ if (!osm) return;
+
+ let changesetURL = osm.changesetURL(_changeset.id);
+
+ let table = summary
+ .append('table')
+ .attr('class', 'summary-table');
+
+ let row = table
+ .append('tr')
+ .attr('class', 'summary-row');
+
+ row
+ .append('td')
+ .attr('class', 'cell-icon summary-icon')
+ .append('a')
+ .attr('target', '_blank')
+ .attr('href', changesetURL)
+ .append('svg')
+ .attr('class', 'logo-small')
+ .append('use')
+ .attr('xlink:href', '#iD-logo-osm');
+
+ let summaryDetail = row
+ .append('td')
+ .attr('class', 'cell-detail summary-detail');
+
+ summaryDetail
+ .append('a')
+ .attr('class', 'cell-detail summary-view-on-osm')
+ .attr('target', '_blank')
+ .attr('href', changesetURL)
+ .text(_t('success.view_on_osm'));
+
+ summaryDetail
+ .append('div')
+ .html(_t('success.changeset_id', {
+ changeset_id: `${_changeset.id} `
+ }));
+
+
+ // Get OSM community index features intersecting the map..
+ ensureOSMCommunityIndex()
+ .then(oci => {
+ let communities = [];
+ const properties = oci.query(context.map().center(), true) || [];
+
+ // Gather the communities from the result
+ properties.forEach(props => {
+ const resourceIDs = Array.from(props.resourceIDs);
+ resourceIDs.forEach(resourceID => {
+ const resource = oci.resources[resourceID];
+ communities.push({
+ area: props.area || Infinity,
+ order: resource.order || 0,
+ resource: resource
+ });
+ });
+ });
+
+ // sort communities by feature area ascending, community order descending
+ communities.sort((a, b) => a.area - b.area || b.order - a.order);
+
+ body
+ .call(showCommunityLinks, communities.map(c => c.resource));
+ });
+ }
+
+
+ function showCommunityLinks(selection, resources) {
+ let communityLinks = selection
+ .append('div')
+ .attr('class', 'save-communityLinks');
+
+ communityLinks
+ .append('h3')
+ .text(_t('success.like_osm'));
+
+ let table = communityLinks
+ .append('table')
+ .attr('class', 'community-table');
+
+ let row = table.selectAll('.community-row')
+ .data(resources);
+
+ let rowEnter = row.enter()
+ .append('tr')
+ .attr('class', 'community-row');
+
+ rowEnter
+ .append('td')
+ .attr('class', 'cell-icon community-icon')
+ .append('a')
+ .attr('target', '_blank')
+ .attr('href', d => d.url)
+ .append('svg')
+ .attr('class', 'logo-small')
+ .append('use')
+ .attr('xlink:href', d => `#community-${d.type}`);
+
+ let communityDetail = rowEnter
+ .append('td')
+ .attr('class', 'cell-detail community-detail');
+
+ communityDetail
+ .each(showCommunityDetails);
+
+ communityLinks
+ .append('div')
+ .attr('class', 'community-missing')
+ .text(_t('success.missing'))
+ .append('a')
+ .attr('class', 'link-out')
+ .attr('target', '_blank')
+ .attr('tabindex', -1)
+ .call(svgIcon('#iD-icon-out-link', 'inline'))
+ .attr('href', 'https://github.com/osmlab/osm-community-index/issues')
+ .append('span')
+ .text(_t('success.tell_us'));
+ }
+
+
+ function showCommunityDetails(d) {
+ let selection = select(this);
+ let communityID = d.id;
+ let replacements = {
+ url: linkify(d.url),
+ signupUrl: linkify(d.signupUrl || d.url)
+ };
+
+ selection
+ .append('div')
+ .attr('class', 'community-name')
+ .append('a')
+ .attr('target', '_blank')
+ .attr('href', d.url)
+ .text(_t(`community.${d.id}.name`));
+
+ let descriptionHTML = _t(`community.${d.id}.description`, replacements);
+
+ if (d.type === 'reddit') { // linkify subreddits #4997
+ descriptionHTML = descriptionHTML
+ .replace(/(\/r\/\w*\/*)/i, match => linkify(d.url, match));
+ }
+
+ selection
+ .append('div')
+ .attr('class', 'community-description')
+ .html(descriptionHTML);
+
+ if (d.extendedDescription || (d.languageCodes && d.languageCodes.length)) {
+ selection
+ .append('div')
+ .call(uiDisclosure(context, `community-more-${d.id}`, false)
+ .expanded(false)
+ .updatePreference(false)
+ .title(_t('success.more'))
+ .content(showMore)
+ );
+ }
+
+ let nextEvents = (d.events || [])
+ .map(event => {
+ event.date = parseEventDate(event.when);
+ return event;
+ })
+ .filter(event => { // date is valid and future (or today)
+ const t = event.date.getTime();
+ const now = (new Date()).setHours(0,0,0,0);
+ return !isNaN(t) && t >= now;
+ })
+ .sort((a, b) => { // sort by date ascending
+ return a.date < b.date ? -1 : a.date > b.date ? 1 : 0;
+ })
+ .slice(0, MAXEVENTS); // limit number of events shown
+
+ if (nextEvents.length) {
+ selection
+ .append('div')
+ .call(uiDisclosure(context, `community-events-${d.id}`, false)
+ .expanded(false)
+ .updatePreference(false)
+ .title(_t('success.events'))
+ .content(showNextEvents)
+ )
+ .select('.hide-toggle')
+ .append('span')
+ .attr('class', 'badge-text')
+ .text(nextEvents.length);
+ }
+
+
+ function showMore(selection) {
+ let more = selection.selectAll('.community-more')
+ .data([0]);
+
+ let moreEnter = more.enter()
+ .append('div')
+ .attr('class', 'community-more');
+
+ if (d.extendedDescription) {
+ moreEnter
+ .append('div')
+ .attr('class', 'community-extended-description')
+ .html(_t(`community.${d.id}.extendedDescription`, replacements));
+ }
+
+ if (d.languageCodes && d.languageCodes.length) {
+ const languageList = d.languageCodes
+ .map(code => _mainLocalizer.languageName(code))
+ .join(', ');
+
+ moreEnter
+ .append('div')
+ .attr('class', 'community-languages')
+ .text(_t('success.languages', { languages: languageList }));
+ }
+ }
+
+
+ function showNextEvents(selection) {
+ let events = selection
+ .append('div')
+ .attr('class', 'community-events');
+
+ let item = events.selectAll('.community-event')
+ .data(nextEvents);
+
+ let itemEnter = item.enter()
+ .append('div')
+ .attr('class', 'community-event');
+
+ itemEnter
+ .append('div')
+ .attr('class', 'community-event-name')
+ .append('a')
+ .attr('target', '_blank')
+ .attr('href', d => d.url)
+ .text(d => {
+ let name = d.name;
+ if (d.i18n && d.id) {
+ name = _t(`community.${communityID}.events.${d.id}.name`, { default: name });
+ }
+ return name;
+ });
+
+ itemEnter
+ .append('div')
+ .attr('class', 'community-event-when')
+ .text(d => {
+ let options = { weekday: 'short', day: 'numeric', month: 'short', year: 'numeric' };
+ if (d.date.getHours() || d.date.getMinutes()) { // include time if it has one
+ options.hour = 'numeric';
+ options.minute = 'numeric';
+ }
+ return d.date.toLocaleString(_mainLocalizer.localeCode(), options);
+ });
+
+ itemEnter
+ .append('div')
+ .attr('class', 'community-event-where')
+ .text(d => {
+ let where = d.where;
+ if (d.i18n && d.id) {
+ where = _t(`community.${communityID}.events.${d.id}.where`, { default: where });
+ }
+ return where;
+ });
+
+ itemEnter
+ .append('div')
+ .attr('class', 'community-event-description')
+ .text(d => {
+ let description = d.description;
+ if (d.i18n && d.id) {
+ description = _t(`community.${communityID}.events.${d.id}.description`, { default: description });
+ }
+ return description;
+ });
+ }
+
+
+ function linkify(url, text) {
+ text = text || url;
+ return `${text} `;
+ }
+ }
+
+
+ success.changeset = function(val) {
+ if (!arguments.length) return _changeset;
+ _changeset = val;
+ return success;
+ };
+
+
+ success.location = function(val) {
+ if (!arguments.length) return _location;
+ _location = val;
+ return success;
+ };
+
+
+ return utilRebind(success, dispatch$1, 'on');
+ }
+
+ function modeSave(context) {
+ var mode = { id: 'save' };
+ var keybinding = utilKeybinding('modeSave');
+
+ var commit = uiCommit(context)
+ .on('cancel', cancel);
+ var _conflictsUi; // uiConflicts
+
+ var _location;
+ var _success;
+
+ var uploader = context.uploader()
+ .on('saveStarted.modeSave', function() {
+ keybindingOff();
+ })
+ // fire off some async work that we want to be ready later
+ .on('willAttemptUpload.modeSave', prepareForSuccess)
+ .on('progressChanged.modeSave', showProgress)
+ .on('resultNoChanges.modeSave', function() {
+ cancel();
+ })
+ .on('resultErrors.modeSave', showErrors)
+ .on('resultConflicts.modeSave', showConflicts)
+ .on('resultSuccess.modeSave', showSuccess);
+
+
+ function cancel() {
+ context.enter(modeBrowse(context));
+ }
+
+
+ function showProgress(num, total) {
+ var modal = context.container().select('.loading-modal .modal-section');
+ var progress = modal.selectAll('.progress')
+ .data([0]);
+
+ // enter/update
+ progress.enter()
+ .append('div')
+ .attr('class', 'progress')
+ .merge(progress)
+ .text(_t('save.conflict_progress', { num: num, total: total }));
+ }
+
+
+ function showConflicts(changeset, conflicts, origChanges) {
+
+ var selection = context.container()
+ .select('.sidebar')
+ .append('div')
+ .attr('class','sidebar-component');
+
+ context.container().selectAll('.main-content')
+ .classed('active', true)
+ .classed('inactive', false);
+
+ _conflictsUi = uiConflicts(context)
+ .conflictList(conflicts)
+ .origChanges(origChanges)
+ .on('cancel', function() {
+ context.container().selectAll('.main-content')
+ .classed('active', false)
+ .classed('inactive', true);
+ selection.remove();
+ keybindingOn();
+
+ uploader.cancelConflictResolution();
+ })
+ .on('save', function() {
+ context.container().selectAll('.main-content')
+ .classed('active', false)
+ .classed('inactive', true);
+ selection.remove();
+
+ uploader.processResolvedConflicts(changeset);
+ });
+
+ selection.call(_conflictsUi);
+ }
+
+
+ function showErrors(errors) {
+ keybindingOn();
+
+ var selection = uiConfirm(context.container());
+ selection
+ .select('.modal-section.header')
+ .append('h3')
+ .text(_t('save.error'));
+
+ addErrors(selection, errors);
+ selection.okButton();
+ }
+
+
+ function addErrors(selection, data) {
+ var message = selection
+ .select('.modal-section.message-text');
+
+ var items = message
+ .selectAll('.error-container')
+ .data(data);
+
+ var enter = items.enter()
+ .append('div')
+ .attr('class', 'error-container');
+
+ enter
+ .append('a')
+ .attr('class', 'error-description')
+ .attr('href', '#')
+ .classed('hide-toggle', true)
+ .text(function(d) { return d.msg || _t('save.unknown_error_details'); })
+ .on('click', function() {
+ event.preventDefault();
+
+ var error = select(this);
+ var detail = select(this.nextElementSibling);
+ var exp = error.classed('expanded');
+
+ detail.style('display', exp ? 'none' : 'block');
+ error.classed('expanded', !exp);
+ });
+
+ var details = enter
+ .append('div')
+ .attr('class', 'error-detail-container')
+ .style('display', 'none');
+
+ details
+ .append('ul')
+ .attr('class', 'error-detail-list')
+ .selectAll('li')
+ .data(function(d) { return d.details || []; })
+ .enter()
+ .append('li')
+ .attr('class', 'error-detail-item')
+ .text(function(d) { return d; });
+
+ items.exit()
+ .remove();
+ }
+
+
+ function showSuccess(changeset) {
+ commit.reset();
+
+ var ui = _success
+ .changeset(changeset)
+ .location(_location)
+ .on('cancel', function() { context.ui().sidebar.hide(); });
+
+ context.enter(modeBrowse(context).sidebar(ui));
+ }
+
+
+ function keybindingOn() {
+ select(document)
+ .call(keybinding.on('⎋', cancel, true));
+ }
+
+
+ function keybindingOff() {
+ select(document)
+ .call(keybinding.unbind);
+ }
+
+
+ // Reverse geocode current map location so we can display a message on
+ // the success screen like "Thank you for editing around place, region."
+ function prepareForSuccess() {
+ _success = uiSuccess(context);
+ _location = null;
+ if (!services.geocoder) return;
+
+ services.geocoder.reverse(context.map().center(), function(err, result) {
+ if (err || !result || !result.address) return;
+
+ var addr = result.address;
+ var place = (addr && (addr.town || addr.city || addr.county)) || '';
+ var region = (addr && (addr.state || addr.country)) || '';
+ var separator = (place && region) ? _t('success.thank_you_where.separator') : '';
+
+ _location = _t('success.thank_you_where.format',
+ { place: place, separator: separator, region: region }
+ );
+ });
+ }
+
+
+ mode.selectedIDs = function() {
+ return _conflictsUi ? _conflictsUi.shownEntityIds() : [];
+ };
+
+
+ mode.enter = function() {
+ // Show sidebar
+ context.ui().sidebar.expand();
+
+ function done() {
+ context.ui().sidebar.show(commit);
+ }
+
+ keybindingOn();
+
+ context.container().selectAll('.main-content')
+ .classed('active', false)
+ .classed('inactive', true);
+
+ var osm = context.connection();
+ if (!osm) {
+ cancel();
+ return;
+ }
+
+ if (osm.authenticated()) {
+ done();
+ } else {
+ osm.authenticate(function(err) {
+ if (err) {
+ cancel();
+ } else {
+ done();
+ }
+ });
+ }
+ };
+
+
+ mode.exit = function() {
+
+ keybindingOff();
+
+ context.container().selectAll('.main-content')
+ .classed('active', true)
+ .classed('inactive', false);
+
+ context.ui().sidebar.hide();
+ };
+
+ return mode;
+ }
+
+ function uiImproveOsmComments() {
+ let _qaItem;
+
+ function issueComments(selection) {
+ // make the div immediately so it appears above the buttons
+ let comments = selection.selectAll('.comments-container')
+ .data([0]);
+
+ comments = comments.enter()
+ .append('div')
+ .attr('class', 'comments-container')
+ .merge(comments);
+
+ // must retrieve comments from API before they can be displayed
+ services.improveOSM.getComments(_qaItem)
+ .then(d => {
+ if (!d.comments) return; // nothing to do here
+
+ const commentEnter = comments.selectAll('.comment')
+ .data(d.comments)
+ .enter()
+ .append('div')
+ .attr('class', 'comment');
+
+ commentEnter
+ .append('div')
+ .attr('class', 'comment-avatar')
+ .call(svgIcon('#iD-icon-avatar', 'comment-avatar-icon'));
+
+ const mainEnter = commentEnter
+ .append('div')
+ .attr('class', 'comment-main');
+
+ const metadataEnter = mainEnter
+ .append('div')
+ .attr('class', 'comment-metadata');
+
+ metadataEnter
+ .append('div')
+ .attr('class', 'comment-author')
+ .each(function(d) {
+ const osm = services.osm;
+ let selection = select(this);
+ if (osm && d.username) {
+ selection = selection
+ .append('a')
+ .attr('class', 'comment-author-link')
+ .attr('href', osm.userURL(d.username))
+ .attr('tabindex', -1)
+ .attr('target', '_blank');
+ }
+ selection
+ .text(d => d.username);
+ });
+
+ metadataEnter
+ .append('div')
+ .attr('class', 'comment-date')
+ .text(d => _t('note.status.commented', { when: localeDateString(d.timestamp) }));
+
+ mainEnter
+ .append('div')
+ .attr('class', 'comment-text')
+ .append('p')
+ .text(d => d.text);
+ })
+ .catch(err => {
+ console.log(err); // eslint-disable-line no-console
+ });
+ }
+
+ function localeDateString(s) {
+ if (!s) return null;
+ const options = { day: 'numeric', month: 'short', year: 'numeric' };
+ const d = new Date(s * 1000); // timestamp is served in seconds, date takes ms
+ if (isNaN(d.getTime())) return null;
+ return d.toLocaleDateString(_mainLocalizer.localeCode(), options);
+ }
+
+ issueComments.issue = function(val) {
+ if (!arguments.length) return _qaItem;
+ _qaItem = val;
+ return issueComments;
+ };
+
+ return issueComments;
+ }
+
+ function uiImproveOsmDetails(context) {
+ let _qaItem;
+
+
+ function issueDetail(d) {
+ if (d.desc) return d.desc;
+ const issueKey = d.issueKey;
+ d.replacements = d.replacements || {};
+ d.replacements.default = _t('inspector.unknown'); // special key `default` works as a fallback string
+ return _t(`QA.improveOSM.error_types.${issueKey}.description`, d.replacements);
+ }
+
+
+ function improveOsmDetails(selection) {
+ const details = selection.selectAll('.error-details')
+ .data(
+ (_qaItem ? [_qaItem] : []),
+ d => `${d.id}-${d.status || 0}`
+ );
+
+ details.exit()
+ .remove();
+
+ const detailsEnter = details.enter()
+ .append('div')
+ .attr('class', 'error-details qa-details-container');
+
+
+ // description
+ const descriptionEnter = detailsEnter
+ .append('div')
+ .attr('class', 'qa-details-subsection');
+
+ descriptionEnter
+ .append('h4')
+ .text(() => _t('QA.keepRight.detail_description'));
+
+ descriptionEnter
+ .append('div')
+ .attr('class', 'qa-details-description-text')
+ .html(issueDetail);
+
+ // If there are entity links in the error message..
+ let relatedEntities = [];
+ descriptionEnter.selectAll('.error_entity_link, .error_object_link')
+ .each(function() {
+ const link = select(this);
+ const isObjectLink = link.classed('error_object_link');
+ const entityID = isObjectLink ?
+ (utilEntityRoot(_qaItem.objectType) + _qaItem.objectId)
+ : this.textContent;
+ const entity = context.hasEntity(entityID);
+
+ relatedEntities.push(entityID);
+
+ // Add click handler
+ link
+ .on('mouseenter', () => {
+ utilHighlightEntities([entityID], true, context);
+ })
+ .on('mouseleave', () => {
+ utilHighlightEntities([entityID], false, context);
+ })
+ .on('click', () => {
+ event.preventDefault();
+
+ utilHighlightEntities([entityID], false, context);
+
+ const osmlayer = context.layers().layer('osm');
+ if (!osmlayer.enabled()) {
+ osmlayer.enabled(true);
+ }
+
+ context.map().centerZoom(_qaItem.loc, 20);
+
+ if (entity) {
+ context.enter(modeSelect(context, [entityID]));
+ } else {
+ context.loadEntity(entityID, () => {
+ context.enter(modeSelect(context, [entityID]));
+ });
+ }
+ });
+
+ // Replace with friendly name if possible
+ // (The entity may not yet be loaded into the graph)
+ if (entity) {
+ let name = utilDisplayName(entity); // try to use common name
+
+ if (!name && !isObjectLink) {
+ const preset = _mainPresetIndex.match(entity, context.graph());
+ name = preset && !preset.isFallback() && preset.name(); // fallback to preset name
+ }
+
+ if (name) {
+ this.innerText = name;
+ }
+ }
+ });
+
+ // Don't hide entities related to this error - #5880
+ context.features().forceVisible(relatedEntities);
+ context.map().pan([0,0]); // trigger a redraw
+ }
+
+ improveOsmDetails.issue = function(val) {
+ if (!arguments.length) return _qaItem;
+ _qaItem = val;
+ return improveOsmDetails;
+ };
+
+ return improveOsmDetails;
+ }
+
+ function uiImproveOsmHeader() {
+ let _qaItem;
+
+
+ function issueTitle(d) {
+ const issueKey = d.issueKey;
+ d.replacements = d.replacements || {};
+ d.replacements.default = _t('inspector.unknown'); // special key `default` works as a fallback string
+ return _t(`QA.improveOSM.error_types.${issueKey}.title`, d.replacements);
+ }
+
+
+ function improveOsmHeader(selection) {
+ const header = selection.selectAll('.qa-header')
+ .data(
+ (_qaItem ? [_qaItem] : []),
+ d => `${d.id}-${d.status || 0}`
+ );
+
+ header.exit()
+ .remove();
+
+ const headerEnter = header.enter()
+ .append('div')
+ .attr('class', 'qa-header');
+
+ const svgEnter = headerEnter
+ .append('div')
+ .attr('class', 'qa-header-icon')
+ .classed('new', d => d.id < 0)
+ .append('svg')
+ .attr('width', '20px')
+ .attr('height', '30px')
+ .attr('viewbox', '0 0 20 30')
+ .attr('class', d => `preset-icon-28 qaItem ${d.service} itemId-${d.id} itemType-${d.itemType}`);
+
+ svgEnter
+ .append('polygon')
+ .attr('fill', 'currentColor')
+ .attr('class', 'qaItem-fill')
+ .attr('points', '16,3 4,3 1,6 1,17 4,20 7,20 10,27 13,20 16,20 19,17.033 19,6');
+
+ svgEnter
+ .append('use')
+ .attr('class', 'icon-annotation')
+ .attr('width', '13px')
+ .attr('height', '13px')
+ .attr('transform', 'translate(3.5, 5)')
+ .attr('xlink:href', d => {
+ const picon = d.icon;
+ if (!picon) {
+ return '';
+ } else {
+ const isMaki = /^maki-/.test(picon);
+ return `#${picon}${isMaki ? '-11' : ''}`;
+ }
+ });
+
+ headerEnter
+ .append('div')
+ .attr('class', 'qa-header-label')
+ .text(issueTitle);
+ }
+
+ improveOsmHeader.issue = function(val) {
+ if (!arguments.length) return _qaItem;
+ _qaItem = val;
+ return improveOsmHeader;
+ };
+
+ return improveOsmHeader;
+ }
+
+ function uiImproveOsmEditor(context) {
+ const dispatch$1 = dispatch('change');
+ const qaDetails = uiImproveOsmDetails(context);
+ const qaComments = uiImproveOsmComments();
+ const qaHeader = uiImproveOsmHeader();
+
+ let _qaItem;
+
+ function improveOsmEditor(selection) {
+
+ const headerEnter = selection.selectAll('.header')
+ .data([0])
+ .enter()
+ .append('div')
+ .attr('class', 'header fillL');
+
+ headerEnter
+ .append('button')
+ .attr('class', 'close')
+ .on('click', () => context.enter(modeBrowse(context)))
+ .call(svgIcon('#iD-icon-close'));
+
+ headerEnter
+ .append('h3')
+ .text(_t('QA.improveOSM.title'));
+
+ let body = selection.selectAll('.body')
+ .data([0]);
+
+ body = body.enter()
+ .append('div')
+ .attr('class', 'body')
+ .merge(body);
+
+ const editor = body.selectAll('.qa-editor')
+ .data([0]);
+
+ editor.enter()
+ .append('div')
+ .attr('class', 'modal-section qa-editor')
+ .merge(editor)
+ .call(qaHeader.issue(_qaItem))
+ .call(qaDetails.issue(_qaItem))
+ .call(qaComments.issue(_qaItem))
+ .call(improveOsmSaveSection);
+ }
+
+ function improveOsmSaveSection(selection) {
+ const isSelected = (_qaItem && _qaItem.id === context.selectedErrorID());
+ const isShown = (_qaItem && (isSelected || _qaItem.newComment || _qaItem.comment));
+ let saveSection = selection.selectAll('.qa-save')
+ .data(
+ (isShown ? [_qaItem] : []),
+ d => `${d.id}-${d.status || 0}`
+ );
+
+ // exit
+ saveSection.exit()
+ .remove();
+
+ // enter
+ const saveSectionEnter = saveSection.enter()
+ .append('div')
+ .attr('class', 'qa-save save-section cf');
+
+ saveSectionEnter
+ .append('h4')
+ .attr('class', '.qa-save-header')
+ .text(_t('note.newComment'));
+
+ saveSectionEnter
+ .append('textarea')
+ .attr('class', 'new-comment-input')
+ .attr('placeholder', _t('QA.keepRight.comment_placeholder'))
+ .attr('maxlength', 1000)
+ .property('value', d => d.newComment)
+ .call(utilNoAuto)
+ .on('input', changeInput)
+ .on('blur', changeInput);
+
+ // update
+ saveSection = saveSectionEnter
+ .merge(saveSection)
+ .call(qaSaveButtons);
+
+ function changeInput() {
+ const input = select(this);
+ let val = input.property('value').trim();
+
+ if (val === '') {
+ val = undefined;
+ }
+
+ // store the unsaved comment with the issue itself
+ _qaItem = _qaItem.update({ newComment: val });
+
+ const qaService = services.improveOSM;
+ if (qaService) {
+ qaService.replaceItem(_qaItem);
+ }
+
+ saveSection
+ .call(qaSaveButtons);
+ }
+ }
+
+ function qaSaveButtons(selection) {
+ const isSelected = (_qaItem && _qaItem.id === context.selectedErrorID());
+ let buttonSection = selection.selectAll('.buttons')
+ .data((isSelected ? [_qaItem] : []), d => d.status + d.id);
+
+ // exit
+ buttonSection.exit()
+ .remove();
+
+ // enter
+ const buttonEnter = buttonSection.enter()
+ .append('div')
+ .attr('class', 'buttons');
+
+ buttonEnter
+ .append('button')
+ .attr('class', 'button comment-button action')
+ .text(_t('QA.keepRight.save_comment'));
+
+ buttonEnter
+ .append('button')
+ .attr('class', 'button close-button action');
+
+ buttonEnter
+ .append('button')
+ .attr('class', 'button ignore-button action');
+
+ // update
+ buttonSection = buttonSection
+ .merge(buttonEnter);
+
+ buttonSection.select('.comment-button')
+ .attr('disabled', d => d.newComment ? null : true)
+ .on('click.comment', function(d) {
+ this.blur(); // avoid keeping focus on the button - #4641
+ const qaService = services.improveOSM;
+ if (qaService) {
+ qaService.postUpdate(d, (err, item) => dispatch$1.call('change', item));
+ }
+ });
+
+ buttonSection.select('.close-button')
+ .text(d => {
+ const andComment = (d.newComment ? '_comment' : '');
+ return _t(`QA.keepRight.close${andComment}`);
+ })
+ .on('click.close', function(d) {
+ this.blur(); // avoid keeping focus on the button - #4641
+ const qaService = services.improveOSM;
+ if (qaService) {
+ d.newStatus = 'SOLVED';
+ qaService.postUpdate(d, (err, item) => dispatch$1.call('change', item));
+ }
+ });
+
+ buttonSection.select('.ignore-button')
+ .text(d => {
+ const andComment = (d.newComment ? '_comment' : '');
+ return _t(`QA.keepRight.ignore${andComment}`);
+ })
+ .on('click.ignore', function(d) {
+ this.blur(); // avoid keeping focus on the button - #4641
+ const qaService = services.improveOSM;
+ if (qaService) {
+ d.newStatus = 'INVALID';
+ qaService.postUpdate(d, (err, item) => dispatch$1.call('change', item));
+ }
+ });
+ }
+
+ // NOTE: Don't change method name until UI v3 is merged
+ improveOsmEditor.error = function(val) {
+ if (!arguments.length) return _qaItem;
+ _qaItem = val;
+ return improveOsmEditor;
+ };
+
+ return utilRebind(improveOsmEditor, dispatch$1, 'on');
+ }
+
+ function uiKeepRightDetails(context) {
+ let _qaItem;
+
+
+ function issueDetail(d) {
+ const { itemType, parentIssueType } = d;
+ const unknown = _t('inspector.unknown');
+ let replacements = d.replacements || {};
+ replacements.default = unknown; // special key `default` works as a fallback string
+
+ let detail = _t(`QA.keepRight.errorTypes.${itemType}.description`, replacements);
+ if (detail === unknown) {
+ detail = _t(`QA.keepRight.errorTypes.${parentIssueType}.description`, replacements);
+ }
+ return detail;
+ }
+
+
+ function keepRightDetails(selection) {
+ const details = selection.selectAll('.error-details')
+ .data(
+ (_qaItem ? [_qaItem] : []),
+ d => `${d.id}-${d.status || 0}`
+ );
+
+ details.exit()
+ .remove();
+
+ const detailsEnter = details.enter()
+ .append('div')
+ .attr('class', 'error-details qa-details-container');
+
+ // description
+ const descriptionEnter = detailsEnter
+ .append('div')
+ .attr('class', 'qa-details-subsection');
+
+ descriptionEnter
+ .append('h4')
+ .text(() => _t('QA.keepRight.detail_description'));
+
+ descriptionEnter
+ .append('div')
+ .attr('class', 'qa-details-description-text')
+ .html(issueDetail);
+
+ // If there are entity links in the error message..
+ let relatedEntities = [];
+ descriptionEnter.selectAll('.error_entity_link, .error_object_link')
+ .each(function() {
+ const link = select(this);
+ const isObjectLink = link.classed('error_object_link');
+ const entityID = isObjectLink ?
+ (utilEntityRoot(_qaItem.objectType) + _qaItem.objectId)
+ : this.textContent;
+ const entity = context.hasEntity(entityID);
+
+ relatedEntities.push(entityID);
+
+ // Add click handler
+ link
+ .on('mouseenter', () => {
+ utilHighlightEntities([entityID], true, context);
+ })
+ .on('mouseleave', () => {
+ utilHighlightEntities([entityID], false, context);
+ })
+ .on('click', () => {
+ event.preventDefault();
+
+ utilHighlightEntities([entityID], false, context);
+
+ const osmlayer = context.layers().layer('osm');
+ if (!osmlayer.enabled()) {
+ osmlayer.enabled(true);
+ }
+
+ context.map().centerZoomEase(_qaItem.loc, 20);
+
+ if (entity) {
+ context.enter(modeSelect(context, [entityID]));
+ } else {
+ context.loadEntity(entityID, () => {
+ context.enter(modeSelect(context, [entityID]));
+ });
+ }
+ });
+
+ // Replace with friendly name if possible
+ // (The entity may not yet be loaded into the graph)
+ if (entity) {
+ let name = utilDisplayName(entity); // try to use common name
+
+ if (!name && !isObjectLink) {
+ const preset = _mainPresetIndex.match(entity, context.graph());
+ name = preset && !preset.isFallback() && preset.name(); // fallback to preset name
+ }
+
+ if (name) {
+ this.innerText = name;
+ }
+ }
+ });
+
+ // Don't hide entities related to this issue - #5880
+ context.features().forceVisible(relatedEntities);
+ context.map().pan([0,0]); // trigger a redraw
+ }
+
+ keepRightDetails.issue = function(val) {
+ if (!arguments.length) return _qaItem;
+ _qaItem = val;
+ return keepRightDetails;
+ };
+
+ return keepRightDetails;
+ }
+
+ function uiKeepRightHeader() {
+ let _qaItem;
+
+
+ function issueTitle(d) {
+ const { itemType, parentIssueType } = d;
+ const unknown = _t('inspector.unknown');
+ let replacements = d.replacements || {};
+ replacements.default = unknown; // special key `default` works as a fallback string
+
+ let title = _t(`QA.keepRight.errorTypes.${itemType}.title`, replacements);
+ if (title === unknown) {
+ title = _t(`QA.keepRight.errorTypes.${parentIssueType}.title`, replacements);
+ }
+ return title;
+ }
+
+
+ function keepRightHeader(selection) {
+ const header = selection.selectAll('.qa-header')
+ .data(
+ (_qaItem ? [_qaItem] : []),
+ d => `${d.id}-${d.status || 0}`
+ );
+
+ header.exit()
+ .remove();
+
+ const headerEnter = header.enter()
+ .append('div')
+ .attr('class', 'qa-header');
+
+ const iconEnter = headerEnter
+ .append('div')
+ .attr('class', 'qa-header-icon')
+ .classed('new', d => d.id < 0);
+
+ iconEnter
+ .append('div')
+ .attr('class', d => `preset-icon-28 qaItem ${d.service} itemId-${d.id} itemType-${d.parentIssueType}`)
+ .call(svgIcon('#iD-icon-bolt', 'qaItem-fill'));
+
+ headerEnter
+ .append('div')
+ .attr('class', 'qa-header-label')
+ .text(issueTitle);
+ }
+
+
+ keepRightHeader.issue = function(val) {
+ if (!arguments.length) return _qaItem;
+ _qaItem = val;
+ return keepRightHeader;
+ };
+
+ return keepRightHeader;
+ }
+
+ function uiViewOnKeepRight() {
+ let _qaItem;
+
+ function viewOnKeepRight(selection) {
+ let url;
+ if (services.keepRight && (_qaItem instanceof QAItem)) {
+ url = services.keepRight.issueURL(_qaItem);
+ }
+
+ const link = selection.selectAll('.view-on-keepRight')
+ .data(url ? [url] : []);
+
+ // exit
+ link.exit()
+ .remove();
+
+ // enter
+ const linkEnter = link.enter()
+ .append('a')
+ .attr('class', 'view-on-keepRight')
+ .attr('target', '_blank')
+ .attr('rel', 'noopener') // security measure
+ .attr('href', d => d)
+ .call(svgIcon('#iD-icon-out-link', 'inline'));
+
+ linkEnter
+ .append('span')
+ .text(_t('inspector.view_on_keepRight'));
+ }
+
+ viewOnKeepRight.what = function(val) {
+ if (!arguments.length) return _qaItem;
+ _qaItem = val;
+ return viewOnKeepRight;
+ };
+
+ return viewOnKeepRight;
+ }
+
+ function uiKeepRightEditor(context) {
+ const dispatch$1 = dispatch('change');
+ const qaDetails = uiKeepRightDetails(context);
+ const qaHeader = uiKeepRightHeader();
+
+ let _qaItem;
+
+ function keepRightEditor(selection) {
+
+ const headerEnter = selection.selectAll('.header')
+ .data([0])
+ .enter()
+ .append('div')
+ .attr('class', 'header fillL');
+
+ headerEnter
+ .append('button')
+ .attr('class', 'close')
+ .on('click', () => context.enter(modeBrowse(context)))
+ .call(svgIcon('#iD-icon-close'));
+
+ headerEnter
+ .append('h3')
+ .text(_t('QA.keepRight.title'));
+
+
+ let body = selection.selectAll('.body')
+ .data([0]);
+
+ body = body.enter()
+ .append('div')
+ .attr('class', 'body')
+ .merge(body);
+
+ const editor = body.selectAll('.qa-editor')
+ .data([0]);
+
+ editor.enter()
+ .append('div')
+ .attr('class', 'modal-section qa-editor')
+ .merge(editor)
+ .call(qaHeader.issue(_qaItem))
+ .call(qaDetails.issue(_qaItem))
+ .call(keepRightSaveSection);
+
+
+ const footer = selection.selectAll('.footer')
+ .data([0]);
+
+ footer.enter()
+ .append('div')
+ .attr('class', 'footer')
+ .merge(footer)
+ .call(uiViewOnKeepRight().what(_qaItem));
+ }
+
+
+ function keepRightSaveSection(selection) {
+ const isSelected = (_qaItem && _qaItem.id === context.selectedErrorID());
+ const isShown = (_qaItem && (isSelected || _qaItem.newComment || _qaItem.comment));
+ let saveSection = selection.selectAll('.qa-save')
+ .data(
+ (isShown ? [_qaItem] : []),
+ d => `${d.id}-${d.status || 0}`
+ );
+
+ // exit
+ saveSection.exit()
+ .remove();
+
+ // enter
+ const saveSectionEnter = saveSection.enter()
+ .append('div')
+ .attr('class', 'qa-save save-section cf');
+
+ saveSectionEnter
+ .append('h4')
+ .attr('class', '.qa-save-header')
+ .text(_t('QA.keepRight.comment'));
+
+ saveSectionEnter
+ .append('textarea')
+ .attr('class', 'new-comment-input')
+ .attr('placeholder', _t('QA.keepRight.comment_placeholder'))
+ .attr('maxlength', 1000)
+ .property('value', d => d.newComment || d.comment)
+ .call(utilNoAuto)
+ .on('input', changeInput)
+ .on('blur', changeInput);
+
+ // update
+ saveSection = saveSectionEnter
+ .merge(saveSection)
+ .call(qaSaveButtons);
+
+ function changeInput() {
+ const input = select(this);
+ let val = input.property('value').trim();
+
+ if (val === _qaItem.comment) {
+ val = undefined;
+ }
+
+ // store the unsaved comment with the issue itself
+ _qaItem = _qaItem.update({ newComment: val });
+
+ const qaService = services.keepRight;
+ if (qaService) {
+ qaService.replaceItem(_qaItem); // update keepright cache
+ }
+
+ saveSection
+ .call(qaSaveButtons);
+ }
+ }
+
+
+ function qaSaveButtons(selection) {
+ const isSelected = (_qaItem && _qaItem.id === context.selectedErrorID());
+ let buttonSection = selection.selectAll('.buttons')
+ .data((isSelected ? [_qaItem] : []), d => d.status + d.id);
+
+ // exit
+ buttonSection.exit()
+ .remove();
+
+ // enter
+ const buttonEnter = buttonSection.enter()
+ .append('div')
+ .attr('class', 'buttons');
+
+ buttonEnter
+ .append('button')
+ .attr('class', 'button comment-button action')
+ .text(_t('QA.keepRight.save_comment'));
+
+ buttonEnter
+ .append('button')
+ .attr('class', 'button close-button action');
+
+ buttonEnter
+ .append('button')
+ .attr('class', 'button ignore-button action');
+
+ // update
+ buttonSection = buttonSection
+ .merge(buttonEnter);
+
+ buttonSection.select('.comment-button') // select and propagate data
+ .attr('disabled', d => d.newComment ? null : true)
+ .on('click.comment', function(d) {
+ this.blur(); // avoid keeping focus on the button - #4641
+ const qaService = services.keepRight;
+ if (qaService) {
+ qaService.postUpdate(d, (err, item) => dispatch$1.call('change', item));
+ }
+ });
+
+ buttonSection.select('.close-button') // select and propagate data
+ .text(d => {
+ const andComment = (d.newComment ? '_comment' : '');
+ return _t(`QA.keepRight.close${andComment}`);
+ })
+ .on('click.close', function(d) {
+ this.blur(); // avoid keeping focus on the button - #4641
+ const qaService = services.keepRight;
+ if (qaService) {
+ d.newStatus = 'ignore_t'; // ignore temporarily (item fixed)
+ qaService.postUpdate(d, (err, item) => dispatch$1.call('change', item));
+ }
+ });
+
+ buttonSection.select('.ignore-button') // select and propagate data
+ .text(d => {
+ const andComment = (d.newComment ? '_comment' : '');
+ return _t(`QA.keepRight.ignore${andComment}`);
+ })
+ .on('click.ignore', function(d) {
+ this.blur(); // avoid keeping focus on the button - #4641
+ const qaService = services.keepRight;
+ if (qaService) {
+ d.newStatus = 'ignore'; // ignore permanently (false positive)
+ qaService.postUpdate(d, (err, item) => dispatch$1.call('change', item));
+ }
+ });
+ }
+
+ // NOTE: Don't change method name until UI v3 is merged
+ keepRightEditor.error = function(val) {
+ if (!arguments.length) return _qaItem;
+ _qaItem = val;
+ return keepRightEditor;
+ };
+
+ return utilRebind(keepRightEditor, dispatch$1, 'on');
+ }
+
+ function uiOsmoseDetails(context) {
+ let _qaItem;
+
+ function issueString(d, type) {
+ if (!d) return '';
+
+ // Issue strings are cached from Osmose API
+ const s = services.osmose.getStrings(d.itemType);
+ return (type in s) ? s[type] : '';
+ }
+
+
+ function osmoseDetails(selection) {
+ const details = selection.selectAll('.error-details')
+ .data(
+ _qaItem ? [_qaItem] : [],
+ d => `${d.id}-${d.status || 0}`
+ );
+
+ details.exit()
+ .remove();
+
+ const detailsEnter = details.enter()
+ .append('div')
+ .attr('class', 'error-details qa-details-container');
+
+
+ // Description
+ if (issueString(_qaItem, 'detail')) {
+ const div = detailsEnter
+ .append('div')
+ .attr('class', 'qa-details-subsection');
+
+ div
+ .append('h4')
+ .text(() => _t('QA.keepRight.detail_description'));
+
+ div
+ .append('p')
+ .attr('class', 'qa-details-description-text')
+ .html(d => issueString(d, 'detail'))
+ .selectAll('a')
+ .attr('rel', 'noopener')
+ .attr('target', '_blank');
+ }
+
+ // Elements (populated later as data is requested)
+ const detailsDiv = detailsEnter
+ .append('div')
+ .attr('class', 'qa-details-subsection');
+
+ const elemsDiv = detailsEnter
+ .append('div')
+ .attr('class', 'qa-details-subsection');
+
+ // Suggested Fix (musn't exist for every issue type)
+ if (issueString(_qaItem, 'fix')) {
+ const div = detailsEnter
+ .append('div')
+ .attr('class', 'qa-details-subsection');
+
+ div
+ .append('h4')
+ .text(() => _t('QA.osmose.fix_title'));
+
+ div
+ .append('p')
+ .html(d => issueString(d, 'fix'))
+ .selectAll('a')
+ .attr('rel', 'noopener')
+ .attr('target', '_blank');
+ }
+
+ // Common Pitfalls (musn't exist for every issue type)
+ if (issueString(_qaItem, 'trap')) {
+ const div = detailsEnter
+ .append('div')
+ .attr('class', 'qa-details-subsection');
+
+ div
+ .append('h4')
+ .text(() => _t('QA.osmose.trap_title'));
+
+ div
+ .append('p')
+ .html(d => issueString(d, 'trap'))
+ .selectAll('a')
+ .attr('rel', 'noopener')
+ .attr('target', '_blank');
+ }
+
+ // Save current item to check if UI changed by time request resolves
+ const thisItem = _qaItem;
+ services.osmose.loadIssueDetail(_qaItem)
+ .then(d => {
+ // No details to add if there are no associated issue elements
+ if (!d.elems || d.elems.length === 0) return;
+
+ // Do nothing if UI has moved on by the time this resolves
+ if (
+ context.selectedErrorID() !== thisItem.id
+ && context.container().selectAll(`.qaItem.osmose.hover.itemId-${thisItem.id}`).empty()
+ ) return;
+
+ // Things like keys and values are dynamically added to a subtitle string
+ if (d.detail) {
+ detailsDiv
+ .append('h4')
+ .text(() => _t('QA.osmose.detail_title'));
+
+ detailsDiv
+ .append('p')
+ .html(d => d.detail)
+ .selectAll('a')
+ .attr('rel', 'noopener')
+ .attr('target', '_blank');
+ }
+
+ // Create list of linked issue elements
+ elemsDiv
+ .append('h4')
+ .text(() => _t('QA.osmose.elems_title'));
+
+ elemsDiv
+ .append('ul').selectAll('li')
+ .data(d.elems)
+ .enter()
+ .append('li')
+ .append('a')
+ .attr('class', 'error_entity_link')
+ .text(d => d)
+ .each(function() {
+ const link = select(this);
+ const entityID = this.textContent;
+ const entity = context.hasEntity(entityID);
+
+ // Add click handler
+ link
+ .on('mouseenter', () => {
+ utilHighlightEntities([entityID], true, context);
+ })
+ .on('mouseleave', () => {
+ utilHighlightEntities([entityID], false, context);
+ })
+ .on('click', () => {
+ event.preventDefault();
+
+ utilHighlightEntities([entityID], false, context);
+
+ const osmlayer = context.layers().layer('osm');
+ if (!osmlayer.enabled()) {
+ osmlayer.enabled(true);
+ }
+
+ context.map().centerZoom(d.loc, 20);
+
+ if (entity) {
+ context.enter(modeSelect(context, [entityID]));
+ } else {
+ context.loadEntity(entityID, () => {
+ context.enter(modeSelect(context, [entityID]));
+ });
+ }
+ });
+
+ // Replace with friendly name if possible
+ // (The entity may not yet be loaded into the graph)
+ if (entity) {
+ let name = utilDisplayName(entity); // try to use common name
+
+ if (!name) {
+ const preset = _mainPresetIndex.match(entity, context.graph());
+ name = preset && !preset.isFallback() && preset.name(); // fallback to preset name
+ }
+
+ if (name) {
+ this.innerText = name;
+ }
+ }
+ });
+
+ // Don't hide entities related to this issue - #5880
+ context.features().forceVisible(d.elems);
+ context.map().pan([0,0]); // trigger a redraw
+ })
+ .catch(err => {
+ console.log(err); // eslint-disable-line no-console
+ });
+ }
+
+
+ osmoseDetails.issue = function(val) {
+ if (!arguments.length) return _qaItem;
+ _qaItem = val;
+ return osmoseDetails;
+ };
+
+
+ return osmoseDetails;
+ }
+
+ function uiOsmoseHeader() {
+ let _qaItem;
+
+ function issueTitle(d) {
+ const unknown = _t('inspector.unknown');
+
+ if (!d) return unknown;
+
+ // Issue titles supplied by Osmose
+ const s = services.osmose.getStrings(d.itemType);
+ return ('title' in s) ? s.title : unknown;
+ }
+
+ function osmoseHeader(selection) {
+ const header = selection.selectAll('.qa-header')
+ .data(
+ (_qaItem ? [_qaItem] : []),
+ d => `${d.id}-${d.status || 0}`
+ );
+
+ header.exit()
+ .remove();
+
+ const headerEnter = header.enter()
+ .append('div')
+ .attr('class', 'qa-header');
+
+ const svgEnter = headerEnter
+ .append('div')
+ .attr('class', 'qa-header-icon')
+ .classed('new', d => d.id < 0)
+ .append('svg')
+ .attr('width', '20px')
+ .attr('height', '30px')
+ .attr('viewbox', '0 0 20 30')
+ .attr('class', d => `preset-icon-28 qaItem ${d.service} itemId-${d.id} itemType-${d.itemType}`);
+
+ svgEnter
+ .append('polygon')
+ .attr('fill', d => services.osmose.getColor(d.item))
+ .attr('class', 'qaItem-fill')
+ .attr('points', '16,3 4,3 1,6 1,17 4,20 7,20 10,27 13,20 16,20 19,17.033 19,6');
+
+ svgEnter
+ .append('use')
+ .attr('class', 'icon-annotation')
+ .attr('width', '13px')
+ .attr('height', '13px')
+ .attr('transform', 'translate(3.5, 5)')
+ .attr('xlink:href', d => {
+ const picon = d.icon;
+
+ if (!picon) {
+ return '';
+ } else {
+ const isMaki = /^maki-/.test(picon);
+ return `#${picon}${isMaki ? '-11' : ''}`;
+ }
+ });
+
+ headerEnter
+ .append('div')
+ .attr('class', 'qa-header-label')
+ .text(issueTitle);
+ }
+
+ osmoseHeader.issue = function(val) {
+ if (!arguments.length) return _qaItem;
+ _qaItem = val;
+ return osmoseHeader;
+ };
+
+ return osmoseHeader;
+ }
+
+ function uiViewOnOsmose() {
+ let _qaItem;
+
+ function viewOnOsmose(selection) {
+ let url;
+ if (services.osmose && (_qaItem instanceof QAItem)) {
+ url = services.osmose.itemURL(_qaItem);
+ }
+
+ const link = selection.selectAll('.view-on-osmose')
+ .data(url ? [url] : []);
+
+ // exit
+ link.exit()
+ .remove();
+
+ // enter
+ const linkEnter = link.enter()
+ .append('a')
+ .attr('class', 'view-on-osmose')
+ .attr('target', '_blank')
+ .attr('rel', 'noopener') // security measure
+ .attr('href', d => d)
+ .call(svgIcon('#iD-icon-out-link', 'inline'));
+
+ linkEnter
+ .append('span')
+ .text(_t('inspector.view_on_osmose'));
+ }
+
+ viewOnOsmose.what = function(val) {
+ if (!arguments.length) return _qaItem;
+ _qaItem = val;
+ return viewOnOsmose;
+ };
+
+ return viewOnOsmose;
+ }
+
+ function uiOsmoseEditor(context) {
+ const dispatch$1 = dispatch('change');
+ const qaDetails = uiOsmoseDetails(context);
+ const qaHeader = uiOsmoseHeader();
+
+ let _qaItem;
+
+ function osmoseEditor(selection) {
+
+ const header = selection.selectAll('.header')
+ .data([0]);
+
+ const headerEnter = header.enter()
+ .append('div')
+ .attr('class', 'header fillL');
+
+ headerEnter
+ .append('button')
+ .attr('class', 'close')
+ .on('click', () => context.enter(modeBrowse(context)))
+ .call(svgIcon('#iD-icon-close'));
+
+ headerEnter
+ .append('h3')
+ .text(_t('QA.osmose.title'));
+
+ let body = selection.selectAll('.body')
+ .data([0]);
+
+ body = body.enter()
+ .append('div')
+ .attr('class', 'body')
+ .merge(body);
+
+ let editor = body.selectAll('.qa-editor')
+ .data([0]);
+
+ editor.enter()
+ .append('div')
+ .attr('class', 'modal-section qa-editor')
+ .merge(editor)
+ .call(qaHeader.issue(_qaItem))
+ .call(qaDetails.issue(_qaItem))
+ .call(osmoseSaveSection);
+
+ const footer = selection.selectAll('.footer')
+ .data([0]);
+
+ footer.enter()
+ .append('div')
+ .attr('class', 'footer')
+ .merge(footer)
+ .call(uiViewOnOsmose().what(_qaItem));
+ }
+
+ function osmoseSaveSection(selection) {
+ const isSelected = (_qaItem && _qaItem.id === context.selectedErrorID());
+ const isShown = (_qaItem && isSelected);
+ let saveSection = selection.selectAll('.qa-save')
+ .data(
+ (isShown ? [_qaItem] : []),
+ d => `${d.id}-${d.status || 0}`
+ );
+
+ // exit
+ saveSection.exit()
+ .remove();
+
+ // enter
+ const saveSectionEnter = saveSection.enter()
+ .append('div')
+ .attr('class', 'qa-save save-section cf');
+
+ // update
+ saveSection = saveSectionEnter
+ .merge(saveSection)
+ .call(qaSaveButtons);
+ }
+
+ function qaSaveButtons(selection) {
+ const isSelected = (_qaItem && _qaItem.id === context.selectedErrorID());
+ let buttonSection = selection.selectAll('.buttons')
+ .data((isSelected ? [_qaItem] : []), d => d.status + d.id);
+
+ // exit
+ buttonSection.exit()
+ .remove();
+
+ // enter
+ const buttonEnter = buttonSection.enter()
+ .append('div')
+ .attr('class', 'buttons');
+
+ buttonEnter
+ .append('button')
+ .attr('class', 'button close-button action');
+
+ buttonEnter
+ .append('button')
+ .attr('class', 'button ignore-button action');
+
+ // update
+ buttonSection = buttonSection
+ .merge(buttonEnter);
+
+ buttonSection.select('.close-button')
+ .text(() => _t('QA.keepRight.close'))
+ .on('click.close', function(d) {
+ this.blur(); // avoid keeping focus on the button - #4641
+ const qaService = services.osmose;
+ if (qaService) {
+ d.newStatus = 'done';
+ qaService.postUpdate(d, (err, item) => dispatch$1.call('change', item));
+ }
+ });
+
+ buttonSection.select('.ignore-button')
+ .text(() => _t('QA.keepRight.ignore'))
+ .on('click.ignore', function(d) {
+ this.blur(); // avoid keeping focus on the button - #4641
+ const qaService = services.osmose;
+ if (qaService) {
+ d.newStatus = 'false';
+ qaService.postUpdate(d, (err, item) => dispatch$1.call('change', item));
+ }
+ });
+ }
+
+ // NOTE: Don't change method name until UI v3 is merged
+ osmoseEditor.error = function(val) {
+ if (!arguments.length) return _qaItem;
+ _qaItem = val;
+ return osmoseEditor;
+ };
+
+ return utilRebind(osmoseEditor, dispatch$1, 'on');
+ }
+
+ // NOTE: Don't change name of this until UI v3 is merged
+ function modeSelectError(context, selectedErrorID, selectedErrorService) {
+ var mode = {
+ id: 'select-error',
+ button: 'browse'
+ };
+
+ var keybinding = utilKeybinding('select-error');
+
+ var errorService = services[selectedErrorService];
+ var errorEditor;
+ switch (selectedErrorService) {
+ case 'improveOSM':
+ errorEditor = uiImproveOsmEditor(context)
+ .on('change', function() {
+ context.map().pan([0,0]); // trigger a redraw
+ var error = checkSelectedID();
+ if (!error) return;
+ context.ui().sidebar
+ .show(errorEditor.error(error));
+ });
+ break;
+ case 'keepRight':
+ errorEditor = uiKeepRightEditor(context)
+ .on('change', function() {
+ context.map().pan([0,0]); // trigger a redraw
+ var error = checkSelectedID();
+ if (!error) return;
+ context.ui().sidebar
+ .show(errorEditor.error(error));
+ });
+ break;
+ case 'osmose':
+ errorEditor = uiOsmoseEditor(context)
+ .on('change', function() {
+ context.map().pan([0,0]); // trigger a redraw
+ var error = checkSelectedID();
+ if (!error) return;
+ context.ui().sidebar
+ .show(errorEditor.error(error));
+ });
+ break;
+ }
+
+
+ var behaviors = [
+ behaviorBreathe(),
+ behaviorHover(context),
+ behaviorSelect(context),
+ behaviorLasso(context),
+ modeDragNode(context).behavior,
+ modeDragNote(context).behavior
+ ];
+
+
+ function checkSelectedID() {
+ if (!errorService) return;
+ var error = errorService.getError(selectedErrorID);
+ if (!error) {
+ context.enter(modeBrowse(context));
+ }
+ return error;
+ }
+
+
+ mode.zoomToSelected = function() {
+ if (!errorService) return;
+ var error = errorService.getError(selectedErrorID);
+ if (error) {
+ context.map().centerZoomEase(error.loc, 20);
+ }
+ };
+
+
+ mode.enter = function() {
+ var error = checkSelectedID();
+ if (!error) return;
+
+ behaviors.forEach(context.install);
+ keybinding
+ .on(_t('inspector.zoom_to.key'), mode.zoomToSelected)
+ .on('⎋', esc, true);
+
+ select(document)
+ .call(keybinding);
+
+ selectError();
+
+ var sidebar = context.ui().sidebar;
+ sidebar.show(errorEditor.error(error));
+
+ context.map()
+ .on('drawn.select-error', selectError);
+
+
+ // class the error as selected, or return to browse mode if the error is gone
+ function selectError(drawn) {
+ if (!checkSelectedID()) return;
+
+ var selection = context.surface()
+ .selectAll('.itemId-' + selectedErrorID + '.' + selectedErrorService);
+
+ if (selection.empty()) {
+ // Return to browse mode if selected DOM elements have
+ // disappeared because the user moved them out of view..
+ var source = event && event.type === 'zoom' && event.sourceEvent;
+ if (drawn && source && (source.type === 'pointermove' || source.type === 'mousemove' || source.type === 'touchmove')) {
+ context.enter(modeBrowse(context));
+ }
+
+ } else {
+ selection
+ .classed('selected', true);
+
+ context.selectedErrorID(selectedErrorID);
+ }
+ }
+
+ function esc() {
+ if (context.container().select('.combobox').size()) return;
+ context.enter(modeBrowse(context));
+ }
+ };
+
+
+ mode.exit = function() {
+ behaviors.forEach(context.uninstall);
+
+ select(document)
+ .call(keybinding.unbind);
+
+ context.surface()
+ .selectAll('.qaItem.selected')
+ .classed('selected hover', false);
+
+ context.map()
+ .on('drawn.select-error', null);
+
+ context.ui().sidebar
+ .hide();
+
+ context.selectedErrorID(null);
+ context.features().forceVisible([]);
+ };
+
+
+ return mode;
+ }
+
+ function uiAccount(context) {
+ var osm = context.connection();
+
+
+ function update(selection) {
+ if (!osm) return;
+
+ if (!osm.authenticated()) {
+ selection.selectAll('.userLink, .logoutLink')
+ .classed('hide', true);
+ return;
+ }
+
+ osm.userDetails(function(err, details) {
+ var userLink = selection.select('.userLink'),
+ logoutLink = selection.select('.logoutLink');
+
+ userLink.html('');
+ logoutLink.html('');
+
+ if (err || !details) return;
+
+ selection.selectAll('.userLink, .logoutLink')
+ .classed('hide', false);
+
+ // Link
+ userLink.append('a')
+ .attr('href', osm.userURL(details.display_name))
+ .attr('target', '_blank');
+
+ // Add thumbnail or dont
+ if (details.image_url) {
+ userLink.append('img')
+ .attr('class', 'icon pre-text user-icon')
+ .attr('src', details.image_url);
+ } else {
+ userLink
+ .call(svgIcon('#iD-icon-avatar', 'pre-text light'));
+ }
+
+ // Add user name
+ userLink.append('span')
+ .attr('class', 'label')
+ .text(details.display_name);
+
+ logoutLink.append('a')
+ .attr('class', 'logout')
+ .attr('href', '#')
+ .text(_t('logout'))
+ .on('click.logout', function() {
+ event.preventDefault();
+ osm.logout();
+ });
+ });
+ }
+
+
+ return function(selection) {
+ selection.append('li')
+ .attr('class', 'logoutLink')
+ .classed('hide', true);
+
+ selection.append('li')
+ .attr('class', 'userLink')
+ .classed('hide', true);
+
+ if (osm) {
+ osm.on('change.account', function() { update(selection); });
+ update(selection);
+ }
+ };
+ }
+
+ function uiAttribution(context) {
+ let _selection = select(null);
+
+
+ function render(selection, data, klass) {
+ let div = selection.selectAll(`.${klass}`)
+ .data([0]);
+
+ div = div.enter()
+ .append('div')
+ .attr('class', klass)
+ .merge(div);
+
+
+ let attributions = div.selectAll('.attribution')
+ .data(data, d => d.id);
+
+ attributions.exit()
+ .remove();
+
+ attributions = attributions.enter()
+ .append('span')
+ .attr('class', 'attribution')
+ .each((d, i, nodes) => {
+ let attribution = select(nodes[i]);
+
+ if (d.terms_html) {
+ attribution.html(d.terms_html);
+ return;
+ }
+
+ if (d.terms_url) {
+ attribution = attribution
+ .append('a')
+ .attr('href', d.terms_url)
+ .attr('target', '_blank');
+ }
+
+ const sourceID = d.id.replace(/\./g, '');
+ const terms_text = _t(`imagery.${sourceID}.attribution.text`,
+ { default: d.terms_text || d.id || d.name() }
+ );
+
+ if (d.icon && !d.overlay) {
+ attribution
+ .append('img')
+ .attr('class', 'source-image')
+ .attr('src', d.icon);
+ }
+
+ attribution
+ .append('span')
+ .attr('class', 'attribution-text')
+ .text(terms_text);
+ })
+ .merge(attributions);
+
+
+ let copyright = attributions.selectAll('.copyright-notice')
+ .data(d => {
+ let notice = d.copyrightNotices(context.map().zoom(), context.map().extent());
+ return notice ? [notice] : [];
+ });
+
+ copyright.exit()
+ .remove();
+
+ copyright = copyright.enter()
+ .append('span')
+ .attr('class', 'copyright-notice')
+ .merge(copyright);
+
+ copyright
+ .text(String);
+ }
+
+
+ function update() {
+ let baselayer = context.background().baseLayerSource();
+ _selection
+ .call(render, (baselayer ? [baselayer] : []), 'base-layer-attribution');
+
+ const z = context.map().zoom();
+ let overlays = context.background().overlayLayerSources() || [];
+ _selection
+ .call(render, overlays.filter(s => s.validZoom(z)), 'overlay-layer-attribution');
+ }
+
+
+ return function(selection) {
+ _selection = selection;
+
+ context.background()
+ .on('change.attribution', update);
+
+ context.map()
+ .on('move.attribution', throttle(update, 400, { leading: false }));
+
+ update();
+ };
+ }
+
+ function uiContributors(context) {
+ var osm = context.connection(),
+ debouncedUpdate = debounce(function() { update(); }, 1000),
+ limit = 4,
+ hidden = false,
+ wrap = select(null);
+
+
+ function update() {
+ if (!osm) return;
+
+ var users = {},
+ entities = context.history().intersects(context.map().extent());
+
+ entities.forEach(function(entity) {
+ if (entity && entity.user) users[entity.user] = true;
+ });
+
+ var u = Object.keys(users),
+ subset = u.slice(0, u.length > limit ? limit - 1 : limit);
+
+ wrap.html('')
+ .call(svgIcon('#iD-icon-nearby', 'pre-text light'));
+
+ var userList = select(document.createElement('span'));
+
+ userList.selectAll()
+ .data(subset)
+ .enter()
+ .append('a')
+ .attr('class', 'user-link')
+ .attr('href', function(d) { return osm.userURL(d); })
+ .attr('target', '_blank')
+ .text(String);
+
+ if (u.length > limit) {
+ var count = select(document.createElement('span'));
+
+ count.append('a')
+ .attr('target', '_blank')
+ .attr('href', function() {
+ return osm.changesetsURL(context.map().center(), context.map().zoom());
+ })
+ .text(u.length - limit + 1);
+
+ wrap.append('span')
+ .html(_t('contributors.truncated_list', { users: userList.html(), count: count.html() }));
+
+ } else {
+ wrap.append('span')
+ .html(_t('contributors.list', { users: userList.html() }));
+ }
+
+ if (!u.length) {
+ hidden = true;
+ wrap
+ .transition()
+ .style('opacity', 0);
+
+ } else if (hidden) {
+ wrap
+ .transition()
+ .style('opacity', 1);
+ }
+ }
+
+
+ return function(selection) {
+ if (!osm) return;
+ wrap = selection;
+ update();
+
+ osm.on('loaded.contributors', debouncedUpdate);
+ context.map().on('move.contributors', debouncedUpdate);
+ };
+ }
+
+ function uiEditMenu(context) {
+ var dispatch$1 = dispatch('toggled');
+
+ var _menu = select(null);
+ var _operations = [];
+ // the position the menu should be displayed relative to
+ var _anchorLoc = [0, 0];
+ var _anchorLocLonLat = [0, 0];
+ // a string indicating how the menu was opened
+ var _triggerType = '';
+
+ var _vpTopMargin = 85; // viewport top margin
+ var _vpBottomMargin = 45; // viewport bottom margin
+ var _vpSideMargin = 35; // viewport side margin
+
+ var _menuTop = false;
+ var _menuHeight;
+ var _menuWidth;
+
+ // hardcode these values to make menu positioning easier
+ var _verticalPadding = 4;
+
+ // see also `.edit-menu .tooltip` CSS; include margin
+ var _tooltipWidth = 210;
+
+ // offset the menu slightly from the target location
+ var _menuSideMargin = 10;
+
+ var _tooltips = [];
+
+ var editMenu = function(selection) {
+
+ var isTouchMenu = _triggerType.includes('touch') || _triggerType.includes('pen');
+
+ var ops = _operations.filter(function(op) {
+ return !isTouchMenu || !op.mouseOnly;
+ });
+
+ if (!ops.length) return;
+
+ _tooltips = [];
+
+ // Position the menu above the anchor for stylus and finger input
+ // since the mapper's hand likely obscures the screen below the anchor
+ _menuTop = isTouchMenu;
+
+ // Show labels for touch input since there aren't hover tooltips
+ var showLabels = isTouchMenu;
+
+ var buttonHeight = showLabels ? 32 : 34;
+ if (showLabels) {
+ // Get a general idea of the width based on the length of the label
+ _menuWidth = 52 + Math.min(120, 6 * Math.max.apply(Math, ops.map(function(op) {
+ return op.title.length;
+ })));
+ } else {
+ _menuWidth = 44;
+ }
+
+ _menuHeight = _verticalPadding * 2 + ops.length * buttonHeight;
+
+ _menu = selection
+ .append('div')
+ .attr('class', 'edit-menu')
+ .classed('touch-menu', isTouchMenu)
+ .style('padding', _verticalPadding + 'px 0');
+
+ var buttons = _menu.selectAll('.edit-menu-item')
+ .data(ops);
+
+ // enter
+ var buttonsEnter = buttons.enter()
+ .append('button')
+ .attr('class', function (d) { return 'edit-menu-item edit-menu-item-' + d.id; })
+ .style('height', buttonHeight + 'px')
+ .on('click', click)
+ // don't listen for `mouseup` because we only care about non-mouse pointer types
+ .on('pointerup', pointerup)
+ .on('pointerdown mousedown', function pointerdown() {
+ // don't let button presses also act as map input - #1869
+ event.stopPropagation();
+ });
+
+ buttonsEnter.each(function(d) {
+ var tooltip = uiTooltip()
+ .heading(d.title)
+ .title(d.tooltip())
+ .keys([d.keys[0]]);
+
+ _tooltips.push(tooltip);
+
+ select(this)
+ .call(tooltip)
+ .append('div')
+ .attr('class', 'icon-wrap')
+ .call(svgIcon('#iD-operation-' + d.id, 'operation'));
+ });
+
+ if (showLabels) {
+ buttonsEnter.append('span')
+ .attr('class', 'label')
+ .text(function(d) {
+ return d.title;
+ });
+ }
+
+ // update
+ buttons = buttonsEnter
+ .merge(buttons)
+ .classed('disabled', function(d) { return d.disabled(); });
+
+ updatePosition();
+
+ var initialScale = context.projection.scale();
+ context.map()
+ .on('move.edit-menu', function() {
+ if (initialScale !== context.projection.scale()) {
+ editMenu.close();
+ }
+ })
+ .on('drawn.edit-menu', function(info) {
+ if (info.full) updatePosition();
+ });
+
+ var lastPointerUpType;
+ // `pointerup` is always called before `click`
+ function pointerup() {
+ lastPointerUpType = event.pointerType;
+ }
+
+ function click(operation) {
+ event.stopPropagation();
+ if (operation.disabled()) {
+ if (lastPointerUpType === 'touch' ||
+ lastPointerUpType === 'pen') {
+ // there are no tooltips for touch interactions so flash feedback instead
+ context.ui().flash
+ .duration(4000)
+ .iconName('#iD-operation-' + operation.id)
+ .iconClass('operation disabled')
+ .text(operation.tooltip)();
+ }
+ } else {
+ if (lastPointerUpType === 'touch' ||
+ lastPointerUpType === 'pen') {
+ context.ui().flash
+ .duration(2000)
+ .iconName('#iD-operation-' + operation.id)
+ .iconClass('operation')
+ .text(operation.annotation() || operation.title)();
+ }
+
+ operation();
+ editMenu.close();
+ }
+ lastPointerUpType = null;
+ }
+
+ dispatch$1.call('toggled', this, true);
+ };
+
+ function updatePosition() {
+
+ if (!_menu || _menu.empty()) return;
+
+ var anchorLoc = context.projection(_anchorLocLonLat);
+
+ var viewport = context.surfaceRect();
+
+ if (anchorLoc[0] < 0 ||
+ anchorLoc[0] > viewport.width ||
+ anchorLoc[1] < 0 ||
+ anchorLoc[1] > viewport.height) {
+ // close the menu if it's gone offscreen
+
+ editMenu.close();
+ return;
+ }
+
+ var menuLeft = displayOnLeft(viewport);
+
+ var offset = [0, 0];
+
+ offset[0] = menuLeft ? -1 * (_menuSideMargin + _menuWidth) : _menuSideMargin;
+
+ if (_menuTop) {
+ if (anchorLoc[1] - _menuHeight < _vpTopMargin) {
+ // menu is near top viewport edge, shift downward
+ offset[1] = -anchorLoc[1] + _vpTopMargin;
+ } else {
+ offset[1] = -_menuHeight;
+ }
+ } else {
+ if (anchorLoc[1] + _menuHeight > (viewport.height - _vpBottomMargin)) {
+ // menu is near bottom viewport edge, shift upwards
+ offset[1] = -anchorLoc[1] - _menuHeight + viewport.height - _vpBottomMargin;
+ } else {
+ offset[1] = 0;
+ }
+ }
+
+ var origin = geoVecAdd(anchorLoc, offset);
+
+ _menu
+ .style('left', origin[0] + 'px')
+ .style('top', origin[1] + 'px');
+
+ var tooltipSide = tooltipPosition(viewport, menuLeft);
+ _tooltips.forEach(function(tooltip) {
+ tooltip.placement(tooltipSide);
+ });
+
+ function displayOnLeft(viewport) {
+ if (_mainLocalizer.textDirection() === 'ltr') {
+ if ((anchorLoc[0] + _menuSideMargin + _menuWidth) > (viewport.width - _vpSideMargin)) {
+ // right menu would be too close to the right viewport edge, go left
+ return true;
+ }
+ // prefer right menu
+ return false;
+
+ } else { // rtl
+ if ((anchorLoc[0] - _menuSideMargin - _menuWidth) < _vpSideMargin) {
+ // left menu would be too close to the left viewport edge, go right
+ return false;
+ }
+ // prefer left menu
+ return true;
+ }
+ }
+
+ function tooltipPosition(viewport, menuLeft) {
+ if (_mainLocalizer.textDirection() === 'ltr') {
+ if (menuLeft) {
+ // if there's not room for a right-side menu then there definitely
+ // isn't room for right-side tooltips
+ return 'left';
+ }
+ if ((anchorLoc[0] + _menuSideMargin + _menuWidth + _tooltipWidth) > (viewport.width - _vpSideMargin)) {
+ // right tooltips would be too close to the right viewport edge, go left
+ return 'left';
+ }
+ // prefer right tooltips
+ return 'right';
+
+ } else { // rtl
+ if (!menuLeft) {
+ return 'right';
+ }
+ if ((anchorLoc[0] - _menuSideMargin - _menuWidth - _tooltipWidth) < _vpSideMargin) {
+ // left tooltips would be too close to the left viewport edge, go right
+ return 'right';
+ }
+ // prefer left tooltips
+ return 'left';
+ }
+ }
+ }
+
+ editMenu.close = function () {
+
+ context.map()
+ .on('move.edit-menu', null)
+ .on('drawn.edit-menu', null);
+
+ _menu.remove();
+ _tooltips = [];
+
+ dispatch$1.call('toggled', this, false);
+ };
+
+ editMenu.anchorLoc = function(val) {
+ if (!arguments.length) return _anchorLoc;
+ _anchorLoc = val;
+ _anchorLocLonLat = context.projection.invert(_anchorLoc);
+ return editMenu;
+ };
+
+ editMenu.triggerType = function(val) {
+ if (!arguments.length) return _triggerType;
+ _triggerType = val;
+ return editMenu;
+ };
+
+ editMenu.operations = function(val) {
+ if (!arguments.length) return _operations;
+ _operations = val;
+ return editMenu;
+ };
+
+ return utilRebind(editMenu, dispatch$1, 'on');
+ }
+
+ function uiFeatureInfo(context) {
+ function update(selection) {
+ var features = context.features();
+ var stats = features.stats();
+ var count = 0;
+ var hiddenList = features.hidden().map(function(k) {
+ if (stats[k]) {
+ count += stats[k];
+ return String(stats[k]) + ' ' + _t('feature.' + k + '.description');
+ }
+ }).filter(Boolean);
+
+ selection.html('');
+
+ if (hiddenList.length) {
+ var tooltipBehavior = uiTooltip()
+ .placement('top')
+ .title(function() {
+ return hiddenList.join(' ');
+ });
+
+ selection.append('a')
+ .attr('class', 'chip')
+ .attr('href', '#')
+ .attr('tabindex', -1)
+ .html(_t('feature_info.hidden_warning', { count: count }))
+ .call(tooltipBehavior)
+ .on('click', function() {
+ tooltipBehavior.hide();
+ event.preventDefault();
+ // open the Map Data pane
+ context.ui().togglePanes(context.container().select('.map-panes .map-data-pane'));
+ });
+ }
+
+ selection
+ .classed('hide', !hiddenList.length);
+ }
+
+
+ return function(selection) {
+ update(selection);
+
+ context.features().on('change.feature_info', function() {
+ update(selection);
+ });
+ };
+ }
+
+ function uiFlash(context) {
+ var _flashTimer;
+
+ var _duration = 2000;
+ var _iconName = '#iD-icon-no';
+ var _iconClass = 'disabled';
+ var _text = '';
+ var _textClass;
+
+ function flash() {
+ if (_flashTimer) {
+ _flashTimer.stop();
+ }
+
+ context.container().select('.main-footer-wrap')
+ .classed('footer-hide', true)
+ .classed('footer-show', false);
+ context.container().select('.flash-wrap')
+ .classed('footer-hide', false)
+ .classed('footer-show', true);
+
+ var content = context.container().select('.flash-wrap').selectAll('.flash-content')
+ .data([0]);
+
+ // Enter
+ var contentEnter = content.enter()
+ .append('div')
+ .attr('class', 'flash-content');
+
+ var iconEnter = contentEnter
+ .append('svg')
+ .attr('class', 'flash-icon icon')
+ .append('g')
+ .attr('transform', 'translate(10,10)');
+
+ iconEnter
+ .append('circle')
+ .attr('r', 9);
+
+ iconEnter
+ .append('use')
+ .attr('transform', 'translate(-7,-7)')
+ .attr('width', '14')
+ .attr('height', '14');
+
+ contentEnter
+ .append('div')
+ .attr('class', 'flash-text');
+
+
+ // Update
+ content = content
+ .merge(contentEnter);
+
+ content
+ .selectAll('.flash-icon')
+ .attr('class', 'icon flash-icon ' + (_iconClass || ''));
+
+ content
+ .selectAll('.flash-icon use')
+ .attr('xlink:href', _iconName);
+
+ content
+ .selectAll('.flash-text')
+ .attr('class', 'flash-text ' + (_textClass || ''))
+ .text(_text);
+
+
+ _flashTimer = d3_timeout(function() {
+ _flashTimer = null;
+ context.container().select('.main-footer-wrap')
+ .classed('footer-hide', false)
+ .classed('footer-show', true);
+ context.container().select('.flash-wrap')
+ .classed('footer-hide', true)
+ .classed('footer-show', false);
+ }, _duration);
+
+ return content;
+ }
+
+
+ flash.duration = function(_) {
+ if (!arguments.length) return _duration;
+ _duration = _;
+ return flash;
+ };
+
+ flash.text = function(_) {
+ if (!arguments.length) return _text;
+ _text = _;
+ return flash;
+ };
+
+ flash.textClass = function(_) {
+ if (!arguments.length) return _textClass;
+ _textClass = _;
+ return flash;
+ };
+
+ flash.iconName = function(_) {
+ if (!arguments.length) return _iconName;
+ _iconName = _;
+ return flash;
+ };
+
+ flash.iconClass = function(_) {
+ if (!arguments.length) return _iconClass;
+ _iconClass = _;
+ return flash;
+ };
+
+ return flash;
+ }
+
+ function uiFullScreen(context) {
+ var element = context.container().node();
+ // var button = d3_select(null);
+
+
+ function getFullScreenFn() {
+ if (element.requestFullscreen) {
+ return element.requestFullscreen;
+ } else if (element.msRequestFullscreen) {
+ return element.msRequestFullscreen;
+ } else if (element.mozRequestFullScreen) {
+ return element.mozRequestFullScreen;
+ } else if (element.webkitRequestFullscreen) {
+ return element.webkitRequestFullscreen;
+ }
+ }
+
+
+ function getExitFullScreenFn() {
+ if (document.exitFullscreen) {
+ return document.exitFullscreen;
+ } else if (document.msExitFullscreen) {
+ return document.msExitFullscreen;
+ } else if (document.mozCancelFullScreen) {
+ return document.mozCancelFullScreen;
+ } else if (document.webkitExitFullscreen) {
+ return document.webkitExitFullscreen;
+ }
+ }
+
+
+ function isFullScreen() {
+ return document.fullscreenElement ||
+ document.mozFullScreenElement ||
+ document.webkitFullscreenElement ||
+ document.msFullscreenElement;
+ }
+
+
+ function isSupported() {
+ return !!getFullScreenFn();
+ }
+
+
+ function fullScreen() {
+ event.preventDefault();
+ if (!isFullScreen()) {
+ // button.classed('active', true);
+ getFullScreenFn().apply(element);
+ } else {
+ // button.classed('active', false);
+ getExitFullScreenFn().apply(document);
+ }
+ }
+
+
+ return function() { // selection) {
+ if (!isSupported()) return;
+
+ // button = selection.append('button')
+ // .attr('title', t('full_screen'))
+ // .attr('tabindex', -1)
+ // .on('click', fullScreen)
+ // .call(tooltip);
+
+ // button.append('span')
+ // .attr('class', 'icon full-screen');
+
+ var detected = utilDetect();
+ var keys = (detected.os === 'mac' ? [uiCmd('⌃⌘F'), 'f11'] : ['f11']);
+ context.keybinding().on(keys, fullScreen);
+ };
+ }
+
+ function uiGeolocate(context) {
+ var _geolocationOptions = {
+ // prioritize speed and power usage over precision
+ enableHighAccuracy: false,
+ // don't hang indefinitely getting the location
+ timeout: 6000 // 6sec
+ };
+ var _locating = uiLoading(context).message(_t('geolocate.locating')).blocking(true);
+ var _layer = context.layers().layer('geolocate');
+ var _position;
+ var _extent;
+ var _timeoutID;
+ var _button = select(null);
+
+ function click() {
+ if (context.inIntro()) return;
+ if (!_layer.enabled() && !_locating.isShown()) {
+
+ // This timeout ensures that we still call finish() even if
+ // the user declines to share their location in Firefox
+ _timeoutID = setTimeout(error, 10000 /* 10sec */ );
+
+ context.container().call(_locating);
+ // get the latest position even if we already have one
+ navigator.geolocation.getCurrentPosition(success, error, _geolocationOptions);
+ } else {
+ _locating.close();
+ _layer.enabled(null, false);
+ updateButtonState();
+ }
+ }
+
+ function zoomTo() {
+ context.enter(modeBrowse(context));
+
+ var map = context.map();
+ _layer.enabled(_position, true);
+ updateButtonState();
+ map.centerZoomEase(_extent.center(), Math.min(20, map.extentZoom(_extent)));
+ }
+
+ function success(geolocation) {
+ _position = geolocation;
+ var coords = _position.coords;
+ _extent = geoExtent([coords.longitude, coords.latitude]).padByMeters(coords.accuracy);
+ zoomTo();
+ finish();
+ }
+
+ function error() {
+ if (_position) {
+ // use the position from a previous call if we have one
+ zoomTo();
+ } else {
+ context.ui().flash
+ .text(_t('geolocate.location_unavailable'))
+ .iconName('#iD-icon-geolocate')();
+ }
+
+ finish();
+ }
+
+ function finish() {
+ _locating.close(); // unblock ui
+ if (_timeoutID) { clearTimeout(_timeoutID); }
+ _timeoutID = undefined;
+ }
+
+ function updateButtonState() {
+ _button.classed('active', _layer.enabled());
+ }
+
+ return function(selection) {
+ if (!navigator.geolocation || !navigator.geolocation.getCurrentPosition) return;
+
+ _button = selection
+ .append('button')
+ .on('click', click)
+ .call(svgIcon('#iD-icon-geolocate', 'light'))
+ .call(uiTooltip()
+ .placement((_mainLocalizer.textDirection() === 'rtl') ? 'right' : 'left')
+ .title(_t('geolocate.title'))
+ .keys([_t('geolocate.key')])
+ );
+
+ context.keybinding().on(_t('geolocate.key'), click);
+ };
+ }
+
+ function uiPanelBackground(context) {
+ var background = context.background();
+ var currSourceName = null;
+ var metadata = {};
+ var metadataKeys = [
+ 'zoom', 'vintage', 'source', 'description', 'resolution', 'accuracy'
+ ];
+
+ var debouncedRedraw = debounce(redraw, 250);
+
+ function redraw(selection) {
+ var source = background.baseLayerSource();
+ if (!source) return;
+
+ var isDG = (source.id.match(/^DigitalGlobe/i) !== null);
+
+ if (currSourceName !== source.name()) {
+ currSourceName = source.name();
+ metadata = {};
+ }
+
+ selection.html('');
+
+ var list = selection
+ .append('ul')
+ .attr('class', 'background-info');
+
+ list
+ .append('li')
+ .text(currSourceName);
+
+ metadataKeys.forEach(function(k) {
+ // DigitalGlobe vintage is available in raster layers for now.
+ if (isDG && k === 'vintage') return;
+
+ list
+ .append('li')
+ .attr('class', 'background-info-list-' + k)
+ .classed('hide', !metadata[k])
+ .text(_t('info_panels.background.' + k) + ':')
+ .append('span')
+ .attr('class', 'background-info-span-' + k)
+ .text(metadata[k]);
+ });
+
+ debouncedGetMetadata(selection);
+
+ var toggleTiles = context.getDebug('tile') ? 'hide_tiles' : 'show_tiles';
+
+ selection
+ .append('a')
+ .text(_t('info_panels.background.' + toggleTiles))
+ .attr('href', '#')
+ .attr('class', 'button button-toggle-tiles')
+ .on('click', function() {
+ event.preventDefault();
+ context.setDebug('tile', !context.getDebug('tile'));
+ selection.call(redraw);
+ });
+
+ if (isDG) {
+ var key = source.id + '-vintage';
+ var sourceVintage = context.background().findSource(key);
+ var showsVintage = context.background().showsLayer(sourceVintage);
+ var toggleVintage = showsVintage ? 'hide_vintage' : 'show_vintage';
+ selection
+ .append('a')
+ .text(_t('info_panels.background.' + toggleVintage))
+ .attr('href', '#')
+ .attr('class', 'button button-toggle-vintage')
+ .on('click', function() {
+ event.preventDefault();
+ context.background().toggleOverlayLayer(sourceVintage);
+ selection.call(redraw);
+ });
+ }
+
+ // disable if necessary
+ ['DigitalGlobe-Premium', 'DigitalGlobe-Standard'].forEach(function(layerId) {
+ if (source.id !== layerId) {
+ var key = layerId + '-vintage';
+ var sourceVintage = context.background().findSource(key);
+ if (context.background().showsLayer(sourceVintage)) {
+ context.background().toggleOverlayLayer(sourceVintage);
+ }
+ }
+ });
+ }
+
+
+ var debouncedGetMetadata = debounce(getMetadata, 250);
+
+ function getMetadata(selection) {
+ var tile = context.container().select('.layer-background img.tile-center'); // tile near viewport center
+ if (tile.empty()) return;
+
+ var sourceName = currSourceName;
+ var d = tile.datum();
+ var zoom = (d && d.length >= 3 && d[2]) || Math.floor(context.map().zoom());
+ var center = context.map().center();
+
+ // update zoom
+ metadata.zoom = String(zoom);
+ selection.selectAll('.background-info-list-zoom')
+ .classed('hide', false)
+ .selectAll('.background-info-span-zoom')
+ .text(metadata.zoom);
+
+ if (!d || !d.length >= 3) return;
+
+ background.baseLayerSource().getMetadata(center, d, function(err, result) {
+ if (err || currSourceName !== sourceName) return;
+
+ // update vintage
+ var vintage = result.vintage;
+ metadata.vintage = (vintage && vintage.range) || _t('info_panels.background.unknown');
+ selection.selectAll('.background-info-list-vintage')
+ .classed('hide', false)
+ .selectAll('.background-info-span-vintage')
+ .text(metadata.vintage);
+
+ // update other metdata
+ metadataKeys.forEach(function(k) {
+ if (k === 'zoom' || k === 'vintage') return; // done already
+ var val = result[k];
+ metadata[k] = val;
+ selection.selectAll('.background-info-list-' + k)
+ .classed('hide', !val)
+ .selectAll('.background-info-span-' + k)
+ .text(val);
+ });
+ });
+ }
+
+
+ var panel = function(selection) {
+ selection.call(redraw);
+
+ context.map()
+ .on('drawn.info-background', function() {
+ selection.call(debouncedRedraw);
+ })
+ .on('move.info-background', function() {
+ selection.call(debouncedGetMetadata);
+ });
+
+ };
+
+ panel.off = function() {
+ context.map()
+ .on('drawn.info-background', null)
+ .on('move.info-background', null);
+ };
+
+ panel.id = 'background';
+ panel.title = _t('info_panels.background.title');
+ panel.key = _t('info_panels.background.key');
+
+
+ return panel;
+ }
+
+ function uiPanelHistory(context) {
+ var osm;
+
+ function displayTimestamp(timestamp) {
+ if (!timestamp) return _t('info_panels.history.unknown');
+ var options = {
+ day: 'numeric', month: 'short', year: 'numeric',
+ hour: 'numeric', minute: 'numeric', second: 'numeric'
+ };
+ var d = new Date(timestamp);
+ if (isNaN(d.getTime())) return _t('info_panels.history.unknown');
+ return d.toLocaleString(_mainLocalizer.localeCode(), options);
+ }
+
+
+ function displayUser(selection, userName) {
+ if (!userName) {
+ selection
+ .append('span')
+ .text(_t('info_panels.history.unknown'));
+ return;
+ }
+
+ selection
+ .append('span')
+ .attr('class', 'user-name')
+ .text(userName);
+
+ var links = selection
+ .append('div')
+ .attr('class', 'links');
+
+ if (osm) {
+ links
+ .append('a')
+ .attr('class', 'user-osm-link')
+ .attr('href', osm.userURL(userName))
+ .attr('target', '_blank')
+ .attr('tabindex', -1)
+ .text('OSM');
+ }
+
+ links
+ .append('a')
+ .attr('class', 'user-hdyc-link')
+ .attr('href', 'https://hdyc.neis-one.org/?' + userName)
+ .attr('target', '_blank')
+ .attr('tabindex', -1)
+ .text('HDYC');
+ }
+
+
+ function displayChangeset(selection, changeset) {
+ if (!changeset) {
+ selection
+ .append('span')
+ .text(_t('info_panels.history.unknown'));
+ return;
+ }
+
+ selection
+ .append('span')
+ .attr('class', 'changeset-id')
+ .text(changeset);
+
+ var links = selection
+ .append('div')
+ .attr('class', 'links');
+
+ if (osm) {
+ links
+ .append('a')
+ .attr('class', 'changeset-osm-link')
+ .attr('href', osm.changesetURL(changeset))
+ .attr('target', '_blank')
+ .attr('tabindex', -1)
+ .text('OSM');
+ }
+
+ links
+ .append('a')
+ .attr('class', 'changeset-osmcha-link')
+ .attr('href', 'https://osmcha.org/changesets/' + changeset)
+ .attr('target', '_blank')
+ .attr('tabindex', -1)
+ .text('OSMCha');
+
+ links
+ .append('a')
+ .attr('class', 'changeset-achavi-link')
+ .attr('href', 'https://overpass-api.de/achavi/?changeset=' + changeset)
+ .attr('target', '_blank')
+ .attr('tabindex', -1)
+ .text('Achavi');
+ }
+
+
+ function redraw(selection) {
+ var selectedNoteID = context.selectedNoteID();
+ osm = context.connection();
+
+ var selected, note, entity;
+ if (selectedNoteID && osm) { // selected 1 note
+ selected = [ _t('note.note') + ' ' + selectedNoteID ];
+ note = osm.getNote(selectedNoteID);
+ } else { // selected 1..n entities
+ selected = context.selectedIDs()
+ .filter(function(e) { return context.hasEntity(e); });
+ if (selected.length) {
+ entity = context.entity(selected[0]);
+ }
+ }
+
+ var singular = selected.length === 1 ? selected[0] : null;
+
+ selection.html('');
+
+ selection
+ .append('h4')
+ .attr('class', 'history-heading')
+ .text(singular || _t('info_panels.history.selected', { n: selected.length }));
+
+ if (!singular) return;
+
+ if (entity) {
+ selection.call(redrawEntity, entity);
+ } else if (note) {
+ selection.call(redrawNote, note);
+ }
+ }
+
+
+ function redrawNote(selection, note) {
+ if (!note || note.isNew()) {
+ selection
+ .append('div')
+ .text(_t('info_panels.history.note_no_history'));
+ return;
+ }
+
+ var list = selection
+ .append('ul');
+
+ list
+ .append('li')
+ .text(_t('info_panels.history.note_comments') + ':')
+ .append('span')
+ .text(note.comments.length);
+
+ if (note.comments.length) {
+ list
+ .append('li')
+ .text(_t('info_panels.history.note_created_date') + ':')
+ .append('span')
+ .text(displayTimestamp(note.comments[0].date));
+
+ list
+ .append('li')
+ .text(_t('info_panels.history.note_created_user') + ':')
+ .call(displayUser, note.comments[0].user);
+ }
+
+ if (osm) {
+ selection
+ .append('a')
+ .attr('class', 'view-history-on-osm')
+ .attr('target', '_blank')
+ .attr('tabindex', -1)
+ .attr('href', osm.noteURL(note))
+ .call(svgIcon('#iD-icon-out-link', 'inline'))
+ .append('span')
+ .text(_t('info_panels.history.note_link_text'));
+ }
+ }
+
+
+ function redrawEntity(selection, entity) {
+ if (!entity || entity.isNew()) {
+ selection
+ .append('div')
+ .text(_t('info_panels.history.no_history'));
+ return;
+ }
+
+ var links = selection
+ .append('div')
+ .attr('class', 'links');
+
+ if (osm) {
+ links
+ .append('a')
+ .attr('class', 'view-history-on-osm')
+ .attr('href', osm.historyURL(entity))
+ .attr('target', '_blank')
+ .attr('tabindex', -1)
+ .attr('title', _t('info_panels.history.link_text'))
+ .text('OSM');
+ }
+ links
+ .append('a')
+ .attr('class', 'pewu-history-viewer-link')
+ .attr('href', 'https://pewu.github.io/osm-history/#/' + entity.type + '/' + entity.osmId())
+ .attr('target', '_blank')
+ .attr('tabindex', -1)
+ .text('PeWu');
+
+ var list = selection
+ .append('ul');
+
+ list
+ .append('li')
+ .text(_t('info_panels.history.version') + ':')
+ .append('span')
+ .text(entity.version);
+
+ list
+ .append('li')
+ .text(_t('info_panels.history.last_edit') + ':')
+ .append('span')
+ .text(displayTimestamp(entity.timestamp));
+
+ list
+ .append('li')
+ .text(_t('info_panels.history.edited_by') + ':')
+ .call(displayUser, entity.user);
+
+ list
+ .append('li')
+ .text(_t('info_panels.history.changeset') + ':')
+ .call(displayChangeset, entity.changeset);
+ }
+
+
+ var panel = function(selection) {
+ selection.call(redraw);
+
+ context.map()
+ .on('drawn.info-history', function() {
+ selection.call(redraw);
+ });
+
+ context
+ .on('enter.info-history', function() {
+ selection.call(redraw);
+ });
+ };
+
+ panel.off = function() {
+ context.map().on('drawn.info-history', null);
+ context.on('enter.info-history', null);
+ };
+
+ panel.id = 'history';
+ panel.title = _t('info_panels.history.title');
+ panel.key = _t('info_panels.history.key');
+
+
+ return panel;
+ }
+
+ var OSM_PRECISION = 7;
+
+ /**
+ * Returns a localized representation of the given length measurement.
+ *
+ * @param {Number} m area in meters
+ * @param {Boolean} isImperial true for U.S. customary units; false for metric
+ */
+ function displayLength(m, isImperial) {
+ var d = m * (isImperial ? 3.28084 : 1);
+ var unit;
+
+ if (isImperial) {
+ if (d >= 5280) {
+ d /= 5280;
+ unit = 'miles';
+ } else {
+ unit = 'feet';
+ }
+ } else {
+ if (d >= 1000) {
+ d /= 1000;
+ unit = 'kilometers';
+ } else {
+ unit = 'meters';
+ }
+ }
+
+ return _t('units.' + unit, {
+ quantity: d.toLocaleString(_mainLocalizer.localeCode(), {
+ maximumSignificantDigits: 4
+ })
+ });
+ }
+
+ /**
+ * Returns a localized representation of the given area measurement.
+ *
+ * @param {Number} m2 area in square meters
+ * @param {Boolean} isImperial true for U.S. customary units; false for metric
+ */
+ function displayArea(m2, isImperial) {
+ var locale = _mainLocalizer.localeCode();
+ var d = m2 * (isImperial ? 10.7639111056 : 1);
+ var d1, d2, area;
+ var unit1 = '';
+ var unit2 = '';
+
+ if (isImperial) {
+ if (d >= 6969600) { // > 0.25mi² show mi²
+ d1 = d / 27878400;
+ unit1 = 'square_miles';
+ } else {
+ d1 = d;
+ unit1 = 'square_feet';
+ }
+
+ if (d > 4356 && d < 43560000) { // 0.1 - 1000 acres
+ d2 = d / 43560;
+ unit2 = 'acres';
+ }
+
+ } else {
+ if (d >= 250000) { // > 0.25km² show km²
+ d1 = d / 1000000;
+ unit1 = 'square_kilometers';
+ } else {
+ d1 = d;
+ unit1 = 'square_meters';
+ }
+
+ if (d > 1000 && d < 10000000) { // 0.1 - 1000 hectares
+ d2 = d / 10000;
+ unit2 = 'hectares';
+ }
+ }
+
+ area = _t('units.' + unit1, {
+ quantity: d1.toLocaleString(locale, {
+ maximumSignificantDigits: 4
+ })
+ });
+
+ if (d2) {
+ return _t('units.area_pair', {
+ area1: area,
+ area2: _t('units.' + unit2, {
+ quantity: d2.toLocaleString(locale, {
+ maximumSignificantDigits: 2
+ })
+ })
+ });
+ } else {
+ return area;
+ }
+ }
+
+ function wrap(x, min, max) {
+ var d = max - min;
+ return ((x - min) % d + d) % d + min;
+ }
+
+ function clamp(x, min, max) {
+ return Math.max(min, Math.min(x, max));
+ }
+
+ function displayCoordinate(deg, pos, neg) {
+ var locale = _mainLocalizer.localeCode();
+ var min = (Math.abs(deg) - Math.floor(Math.abs(deg))) * 60;
+ var sec = (min - Math.floor(min)) * 60;
+ var displayDegrees = _t('units.arcdegrees', {
+ quantity: Math.floor(Math.abs(deg)).toLocaleString(locale)
+ });
+ var displayCoordinate;
+
+ if (Math.floor(sec) > 0) {
+ displayCoordinate = displayDegrees +
+ _t('units.arcminutes', {
+ quantity: Math.floor(min).toLocaleString(locale)
+ }) +
+ _t('units.arcseconds', {
+ quantity: Math.round(sec).toLocaleString(locale)
+ });
+ } else if (Math.floor(min) > 0) {
+ displayCoordinate = displayDegrees +
+ _t('units.arcminutes', {
+ quantity: Math.round(min).toLocaleString(locale)
+ });
+ } else {
+ displayCoordinate = _t('units.arcdegrees', {
+ quantity: Math.round(Math.abs(deg)).toLocaleString(locale)
+ });
+ }
+
+ if (deg === 0) {
+ return displayCoordinate;
+ } else {
+ return _t('units.coordinate', {
+ coordinate: displayCoordinate,
+ direction: _t('units.' + (deg > 0 ? pos : neg))
+ });
+ }
+ }
+
+ /**
+ * Returns given coordinate pair in degree-minute-second format.
+ *
+ * @param {Array} coord longitude and latitude
+ */
+ function dmsCoordinatePair(coord) {
+ return _t('units.coordinate_pair', {
+ latitude: displayCoordinate(clamp(coord[1], -90, 90), 'north', 'south'),
+ longitude: displayCoordinate(wrap(coord[0], -180, 180), 'east', 'west')
+ });
+ }
+
+ /**
+ * Returns the given coordinate pair in decimal format.
+ * note: unlocalized to avoid comma ambiguity - see #4765
+ *
+ * @param {Array} coord longitude and latitude
+ */
+ function decimalCoordinatePair(coord) {
+ return _t('units.coordinate_pair', {
+ latitude: clamp(coord[1], -90, 90).toFixed(OSM_PRECISION),
+ longitude: wrap(coord[0], -180, 180).toFixed(OSM_PRECISION)
+ });
+ }
+
+ function uiPanelLocation(context) {
+ var currLocation = '';
+
+
+ function redraw(selection) {
+ selection.html('');
+
+ var list = selection
+ .append('ul');
+
+ // Mouse coordinates
+ var coord = context.map().mouseCoordinates();
+ if (coord.some(isNaN)) {
+ coord = context.map().center();
+ }
+
+ list
+ .append('li')
+ .text(dmsCoordinatePair(coord))
+ .append('li')
+ .text(decimalCoordinatePair(coord));
+
+ // Location Info
+ selection
+ .append('div')
+ .attr('class', 'location-info')
+ .text(currLocation || ' ');
+
+ debouncedGetLocation(selection, coord);
+ }
+
+
+ var debouncedGetLocation = debounce(getLocation, 250);
+ function getLocation(selection, coord) {
+ if (!services.geocoder) {
+ currLocation = _t('info_panels.location.unknown_location');
+ selection.selectAll('.location-info')
+ .text(currLocation);
+ } else {
+ services.geocoder.reverse(coord, function(err, result) {
+ currLocation = result ? result.display_name : _t('info_panels.location.unknown_location');
+ selection.selectAll('.location-info')
+ .text(currLocation);
+ });
+ }
+ }
+
+
+ var panel = function(selection) {
+ selection.call(redraw);
+
+ context.surface()
+ .on(('PointerEvent' in window ? 'pointer' : 'mouse') + 'move.info-location', function() {
+ selection.call(redraw);
+ });
+ };
+
+ panel.off = function() {
+ context.surface()
+ .on('.info-location', null);
+ };
+
+ panel.id = 'location';
+ panel.title = _t('info_panels.location.title');
+ panel.key = _t('info_panels.location.key');
+
+
+ return panel;
+ }
+
+ function uiPanelMeasurement(context) {
+ var locale = _mainLocalizer.localeCode();
+ var isImperial = !_mainLocalizer.usesMetric();
+
+
+ function radiansToMeters(r) {
+ // using WGS84 authalic radius (6371007.1809 m)
+ return r * 6371007.1809;
+ }
+
+ function steradiansToSqmeters(r) {
+ // http://gis.stackexchange.com/a/124857/40446
+ return r / (4 * Math.PI) * 510065621724000;
+ }
+
+
+ function toLineString(feature) {
+ if (feature.type === 'LineString') return feature;
+
+ var result = { type: 'LineString', coordinates: [] };
+ if (feature.type === 'Polygon') {
+ result.coordinates = feature.coordinates[0];
+ } else if (feature.type === 'MultiPolygon') {
+ result.coordinates = feature.coordinates[0][0];
+ }
+
+ return result;
+ }
+
+
+ function redraw(selection) {
+ var graph = context.graph();
+ var selectedNoteID = context.selectedNoteID();
+ var osm = services.osm;
+
+ var heading;
+ var center, location, centroid;
+ var closed, geometry;
+ var totalNodeCount, length = 0, area = 0;
+
+ if (selectedNoteID && osm) { // selected 1 note
+
+ var note = osm.getNote(selectedNoteID);
+ heading = _t('note.note') + ' ' + selectedNoteID;
+ location = note.loc;
+ geometry = 'note';
+
+ } else { // selected 1..n entities
+ var selectedIDs = context.selectedIDs().filter(function(id) {
+ return context.hasEntity(id);
+ });
+ var selected = selectedIDs.map(function(id) {
+ return context.entity(id);
+ });
+
+ heading = selected.length === 1 ? selected[0].id :
+ _t('info_panels.measurement.selected', { n: selected.length.toLocaleString(locale) });
+
+ if (selected.length) {
+ var extent = geoExtent();
+ for (var i in selected) {
+ var entity = selected[i];
+ extent._extend(entity.extent(graph));
+
+ geometry = entity.geometry(graph);
+ if (geometry === 'line' || geometry === 'area') {
+ closed = (entity.type === 'relation') || (entity.isClosed() && !entity.isDegenerate());
+ var feature = entity.asGeoJSON(graph);
+ length += radiansToMeters(d3_geoLength(toLineString(feature)));
+ centroid = d3_geoCentroid(feature);
+ if (closed) {
+ area += steradiansToSqmeters(entity.area(graph));
+ }
+ }
+ }
+
+ if (selected.length > 1) {
+ geometry = null;
+ closed = null;
+ centroid = null;
+ }
+
+ if (selected.length === 1 && selected[0].type === 'node') {
+ location = selected[0].loc;
+ } else {
+ totalNodeCount = utilGetAllNodes(selectedIDs, context.graph()).length;
+ }
+
+ if (!location && !centroid) {
+ center = extent.center();
+ }
+ }
+ }
+
+ selection.html('');
+
+ if (heading) {
+ selection
+ .append('h4')
+ .attr('class', 'measurement-heading')
+ .text(heading);
+ }
+
+ var list = selection
+ .append('ul');
+ var coordItem;
+
+ if (geometry) {
+ list
+ .append('li')
+ .text(_t('info_panels.measurement.geometry') + ':')
+ .append('span')
+ .text(
+ closed ? _t('info_panels.measurement.closed_' + geometry) : _t('geometry.' + geometry)
+ );
+ }
+
+ if (totalNodeCount) {
+ list
+ .append('li')
+ .text(_t('info_panels.measurement.node_count') + ':')
+ .append('span')
+ .text(totalNodeCount.toLocaleString(locale));
+ }
+
+ if (area) {
+ list
+ .append('li')
+ .text(_t('info_panels.measurement.area') + ':')
+ .append('span')
+ .text(displayArea(area, isImperial));
+ }
+
+ if (length) {
+ var lengthLabel = _t('info_panels.measurement.' + (closed ? 'perimeter' : 'length'));
+ list
+ .append('li')
+ .text(lengthLabel + ':')
+ .append('span')
+ .text(displayLength(length, isImperial));
+ }
+
+ if (location) {
+ coordItem = list
+ .append('li')
+ .text(_t('info_panels.measurement.location') + ':');
+ coordItem.append('span')
+ .text(dmsCoordinatePair(location));
+ coordItem.append('span')
+ .text(decimalCoordinatePair(location));
+ }
+
+ if (centroid) {
+ coordItem = list
+ .append('li')
+ .text(_t('info_panels.measurement.centroid') + ':');
+ coordItem.append('span')
+ .text(dmsCoordinatePair(centroid));
+ coordItem.append('span')
+ .text(decimalCoordinatePair(centroid));
+ }
+
+ if (center) {
+ coordItem = list
+ .append('li')
+ .text(_t('info_panels.measurement.center') + ':');
+ coordItem.append('span')
+ .text(dmsCoordinatePair(center));
+ coordItem.append('span')
+ .text(decimalCoordinatePair(center));
+ }
+
+ if (length || area) {
+ var toggle = isImperial ? 'imperial' : 'metric';
+ selection
+ .append('a')
+ .text(_t('info_panels.measurement.' + toggle))
+ .attr('href', '#')
+ .attr('class', 'button button-toggle-units')
+ .on('click', function() {
+ event.preventDefault();
+ isImperial = !isImperial;
+ selection.call(redraw);
+ });
+ }
+ }
+
+
+ var panel = function(selection) {
+ selection.call(redraw);
+
+ context.map()
+ .on('drawn.info-measurement', function() {
+ selection.call(redraw);
+ });
+
+ context
+ .on('enter.info-measurement', function() {
+ selection.call(redraw);
+ });
+ };
+
+ panel.off = function() {
+ context.map().on('drawn.info-measurement', null);
+ context.on('enter.info-measurement', null);
+ };
+
+ panel.id = 'measurement';
+ panel.title = _t('info_panels.measurement.title');
+ panel.key = _t('info_panels.measurement.key');
+
+
+ return panel;
+ }
+
+ var uiInfoPanels = {
+ background: uiPanelBackground,
+ history: uiPanelHistory,
+ location: uiPanelLocation,
+ measurement: uiPanelMeasurement,
+ };
+
+ function uiInfo(context) {
+ var ids = Object.keys(uiInfoPanels);
+ var wasActive = ['measurement'];
+ var panels = {};
+ var active = {};
+
+ // create panels
+ ids.forEach(function(k) {
+ if (!panels[k]) {
+ panels[k] = uiInfoPanels[k](context);
+ active[k] = false;
+ }
+ });
+
+
+ function info(selection) {
+
+ function redraw() {
+ var activeids = ids.filter(function(k) { return active[k]; }).sort();
+
+ var containers = infoPanels.selectAll('.panel-container')
+ .data(activeids, function(k) { return k; });
+
+ containers.exit()
+ .style('opacity', 1)
+ .transition()
+ .duration(200)
+ .style('opacity', 0)
+ .on('end', function(d) {
+ select(this)
+ .call(panels[d].off)
+ .remove();
+ });
+
+ var enter = containers.enter()
+ .append('div')
+ .attr('class', function(d) { return 'fillD2 panel-container panel-container-' + d; });
+
+ enter
+ .style('opacity', 0)
+ .transition()
+ .duration(200)
+ .style('opacity', 1);
+
+ var title = enter
+ .append('div')
+ .attr('class', 'panel-title fillD2');
+
+ title
+ .append('h3')
+ .text(function(d) { return panels[d].title; });
+
+ title
+ .append('button')
+ .attr('class', 'close')
+ .on('click', function (d) { info.toggle(d); })
+ .call(svgIcon('#iD-icon-close'));
+
+ enter
+ .append('div')
+ .attr('class', function(d) { return 'panel-content panel-content-' + d; });
+
+
+ // redraw the panels
+ infoPanels.selectAll('.panel-content')
+ .each(function(d) {
+ select(this).call(panels[d]);
+ });
+ }
+
+
+ info.toggle = function(which) {
+ if (event) {
+ event.stopImmediatePropagation();
+ event.preventDefault();
+ }
+
+ var activeids = ids.filter(function(k) { return active[k]; });
+
+ if (which) { // toggle one
+ active[which] = !active[which];
+ if (activeids.length === 1 && activeids[0] === which) { // none active anymore
+ wasActive = [which];
+ }
+
+ context.container().select('.' + which + '-panel-toggle-item')
+ .classed('active', active[which])
+ .select('input')
+ .property('checked', active[which]);
+
+ } else { // toggle all
+ if (activeids.length) {
+ wasActive = activeids;
+ activeids.forEach(function(k) { active[k] = false; });
+ } else {
+ wasActive.forEach(function(k) { active[k] = true; });
+ }
+ }
+
+ redraw();
+ };
+
+
+ var infoPanels = selection.selectAll('.info-panels')
+ .data([0]);
+
+ infoPanels = infoPanels.enter()
+ .append('div')
+ .attr('class', 'info-panels')
+ .merge(infoPanels);
+
+ redraw();
+
+ context.keybinding()
+ .on(uiCmd('⌘' + _t('info_panels.key')), info.toggle);
+
+ ids.forEach(function(k) {
+ var key = _t('info_panels.' + k + '.key', { default: null });
+ if (!key) return;
+ context.keybinding()
+ .on(uiCmd('⌘⇧' + key), function() { info.toggle(k); });
+ });
+ }
+
+ return info;
+ }
+
+ // Tooltips and svg mask used to highlight certain features
+ function uiCurtain(containerNode) {
+
+ var surface = select(null),
+ tooltip = select(null),
+ darkness = select(null);
+
+ function curtain(selection) {
+ surface = selection
+ .append('svg')
+ .attr('class', 'curtain')
+ .style('top', 0)
+ .style('left', 0);
+
+ darkness = surface.append('path')
+ .attr('x', 0)
+ .attr('y', 0)
+ .attr('class', 'curtain-darkness');
+
+ select(window).on('resize.curtain', resize);
+
+ tooltip = selection.append('div')
+ .attr('class', 'tooltip');
+
+ tooltip
+ .append('div')
+ .attr('class', 'popover-arrow');
+
+ tooltip
+ .append('div')
+ .attr('class', 'popover-inner');
+
+ resize();
+
+
+ function resize() {
+ surface
+ .attr('width', containerNode.clientWidth)
+ .attr('height', containerNode.clientHeight);
+ curtain.cut(darkness.datum());
+ }
+ }
+
+
+ /**
+ * Reveal cuts the curtain to highlight the given box,
+ * and shows a tooltip with instructions next to the box.
+ *
+ * @param {String|ClientRect} [box] box used to cut the curtain
+ * @param {String} [text] text for a tooltip
+ * @param {Object} [options]
+ * @param {string} [options.tooltipClass] optional class to add to the tooltip
+ * @param {integer} [options.duration] transition time in milliseconds
+ * @param {string} [options.buttonText] if set, create a button with this text label
+ * @param {function} [options.buttonCallback] if set, the callback for the button
+ * @param {function} [options.padding] extra margin in px to put around bbox
+ * @param {String|ClientRect} [options.tooltipBox] box for tooltip position, if different from box for the curtain
+ */
+ curtain.reveal = function(box, text, options) {
+ options = options || {};
+
+ if (typeof box === 'string') {
+ box = select(box).node();
+ }
+ if (box && box.getBoundingClientRect) {
+ box = copyBox(box.getBoundingClientRect());
+ var containerRect = containerNode.getBoundingClientRect();
+ box.top -= containerRect.top;
+ box.left -= containerRect.left;
+ }
+ if (box && options.padding) {
+ box.top -= options.padding;
+ box.left -= options.padding;
+ box.bottom += options.padding;
+ box.right += options.padding;
+ box.height += options.padding * 2;
+ box.width += options.padding * 2;
+ }
+
+ var tooltipBox;
+ if (options.tooltipBox) {
+ tooltipBox = options.tooltipBox;
+ if (typeof tooltipBox === 'string') {
+ tooltipBox = select(tooltipBox).node();
+ }
+ if (tooltipBox && tooltipBox.getBoundingClientRect) {
+ tooltipBox = copyBox(tooltipBox.getBoundingClientRect());
+ }
+ } else {
+ tooltipBox = box;
+ }
+
+ if (tooltipBox && text) {
+ // pseudo markdown bold text for the instruction section..
+ var parts = text.split('**');
+ var html = parts[0] ? '' + parts[0] + ' ' : '';
+ if (parts[1]) {
+ html += '' + parts[1] + ' ';
+ }
+
+ html = html.replace(/\*(.*?)\*/g, '$1 '); // emphasis
+ html = html.replace(/\{br\}/g, ' '); // linebreak
+
+ if (options.buttonText && options.buttonCallback) {
+ html += '' +
+ '' + options.buttonText + '
';
+ }
+
+ var classes = 'curtain-tooltip popover tooltip arrowed in ' + (options.tooltipClass || '');
+ tooltip
+ .classed(classes, true)
+ .selectAll('.popover-inner')
+ .html(html);
+
+ if (options.buttonText && options.buttonCallback) {
+ var button = tooltip.selectAll('.button-section .button.action');
+ button
+ .on('click', function() {
+ event.preventDefault();
+ options.buttonCallback();
+ });
+ }
+
+ var tip = copyBox(tooltip.node().getBoundingClientRect()),
+ w = containerNode.clientWidth,
+ h = containerNode.clientHeight,
+ tooltipWidth = 200,
+ tooltipArrow = 5,
+ side, pos;
+
+
+ // hack: this will have bottom placement,
+ // so need to reserve extra space for the tooltip illustration.
+ if (options.tooltipClass === 'intro-mouse') {
+ tip.height += 80;
+ }
+
+ // trim box dimensions to just the portion that fits in the container..
+ if (tooltipBox.top + tooltipBox.height > h) {
+ tooltipBox.height -= (tooltipBox.top + tooltipBox.height - h);
+ }
+ if (tooltipBox.left + tooltipBox.width > w) {
+ tooltipBox.width -= (tooltipBox.left + tooltipBox.width - w);
+ }
+
+ // determine tooltip placement..
+
+ if (tooltipBox.top + tooltipBox.height < 100) {
+ // tooltip below box..
+ side = 'bottom';
+ pos = [
+ tooltipBox.left + tooltipBox.width / 2 - tip.width / 2,
+ tooltipBox.top + tooltipBox.height
+ ];
+
+ } else if (tooltipBox.top > h - 140) {
+ // tooltip above box..
+ side = 'top';
+ pos = [
+ tooltipBox.left + tooltipBox.width / 2 - tip.width / 2,
+ tooltipBox.top - tip.height
+ ];
+
+ } else {
+ // tooltip to the side of the tooltipBox..
+ var tipY = tooltipBox.top + tooltipBox.height / 2 - tip.height / 2;
+
+ if (_mainLocalizer.textDirection() === 'rtl') {
+ if (tooltipBox.left - tooltipWidth - tooltipArrow < 70) {
+ side = 'right';
+ pos = [tooltipBox.left + tooltipBox.width + tooltipArrow, tipY];
+
+ } else {
+ side = 'left';
+ pos = [tooltipBox.left - tooltipWidth - tooltipArrow, tipY];
+ }
+
+ } else {
+ if (tooltipBox.left + tooltipBox.width + tooltipArrow + tooltipWidth > w - 70) {
+ side = 'left';
+ pos = [tooltipBox.left - tooltipWidth - tooltipArrow, tipY];
+ }
+ else {
+ side = 'right';
+ pos = [tooltipBox.left + tooltipBox.width + tooltipArrow, tipY];
+ }
+ }
+ }
+
+ if (options.duration !== 0 || !tooltip.classed(side)) {
+ tooltip.call(uiToggle(true));
+ }
+
+ tooltip
+ .style('top', pos[1] + 'px')
+ .style('left', pos[0] + 'px')
+ .attr('class', classes + ' ' + side);
+
+
+ // shift popover-inner if it is very close to the top or bottom edge
+ // (doesn't affect the placement of the popover-arrow)
+ var shiftY = 0;
+ if (side === 'left' || side === 'right') {
+ if (pos[1] < 60) {
+ shiftY = 60 - pos[1];
+ }
+ else if (pos[1] + tip.height > h - 100) {
+ shiftY = h - pos[1] - tip.height - 100;
+ }
+ }
+ tooltip.selectAll('.popover-inner')
+ .style('top', shiftY + 'px');
+
+ } else {
+ tooltip
+ .classed('in', false)
+ .call(uiToggle(false));
+ }
+
+ curtain.cut(box, options.duration);
+
+ return tooltip;
+ };
+
+
+ curtain.cut = function(datum, duration) {
+ darkness.datum(datum)
+ .interrupt();
+
+ var selection;
+ if (duration === 0) {
+ selection = darkness;
+ } else {
+ selection = darkness
+ .transition()
+ .duration(duration || 600)
+ .ease(linear$1);
+ }
+
+ selection
+ .attr('d', function(d) {
+ var containerWidth = containerNode.clientWidth;
+ var containerHeight = containerNode.clientHeight;
+ var string = 'M 0,0 L 0,' + containerHeight + ' L ' +
+ containerWidth + ',' + containerHeight + 'L' +
+ containerWidth + ',0 Z';
+
+ if (!d) return string;
+ return string + 'M' +
+ d.left + ',' + d.top + 'L' +
+ d.left + ',' + (d.top + d.height) + 'L' +
+ (d.left + d.width) + ',' + (d.top + d.height) + 'L' +
+ (d.left + d.width) + ',' + (d.top) + 'Z';
+
+ });
+ };
+
+
+ curtain.remove = function() {
+ surface.remove();
+ tooltip.remove();
+ select(window).on('resize.curtain', null);
+ };
+
+
+ // ClientRects are immutable, so copy them to an object,
+ // in case we need to trim the height/width.
+ function copyBox(src) {
+ return {
+ top: src.top,
+ right: src.right,
+ bottom: src.bottom,
+ left: src.left,
+ width: src.width,
+ height: src.height
+ };
+ }
+
+
+ return curtain;
+ }
+
+ function uiIntroWelcome(context, reveal) {
+ var dispatch$1 = dispatch('done');
+
+ var chapter = {
+ title: 'intro.welcome.title'
+ };
+
+
+ function welcome() {
+ context.map().centerZoom([-85.63591, 41.94285], 19);
+ reveal('.intro-nav-wrap .chapter-welcome',
+ helpString('intro.welcome.welcome'),
+ { buttonText: _t('intro.ok'), buttonCallback: practice }
+ );
+ }
+
+ function practice() {
+ reveal('.intro-nav-wrap .chapter-welcome',
+ helpString('intro.welcome.practice'),
+ { buttonText: _t('intro.ok'), buttonCallback: words }
+ );
+ }
+
+ function words() {
+ reveal('.intro-nav-wrap .chapter-welcome',
+ helpString('intro.welcome.words'),
+ { buttonText: _t('intro.ok'), buttonCallback: chapters }
+ );
+ }
+
+
+ function chapters() {
+ dispatch$1.call('done');
+ reveal('.intro-nav-wrap .chapter-navigation',
+ helpString('intro.welcome.chapters', { next: _t('intro.navigation.title') })
+ );
+ }
+
+
+ chapter.enter = function() {
+ welcome();
+ };
+
+
+ chapter.exit = function() {
+ context.container().select('.curtain-tooltip.intro-mouse')
+ .selectAll('.counter')
+ .remove();
+ };
+
+
+ chapter.restart = function() {
+ chapter.exit();
+ chapter.enter();
+ };
+
+
+ return utilRebind(chapter, dispatch$1, 'on');
+ }
+
+ function uiIntroNavigation(context, reveal) {
+ var dispatch$1 = dispatch('done');
+ var timeouts = [];
+ var hallId = 'n2061';
+ var townHall = [-85.63591, 41.94285];
+ var springStreetId = 'w397';
+ var springStreetEndId = 'n1834';
+ var springStreet = [-85.63582, 41.94255];
+ var onewayField = _mainPresetIndex.field('oneway');
+ var maxspeedField = _mainPresetIndex.field('maxspeed');
+
+
+ var chapter = {
+ title: 'intro.navigation.title'
+ };
+
+
+ function timeout(f, t) {
+ timeouts.push(window.setTimeout(f, t));
+ }
+
+
+ function eventCancel() {
+ event.stopPropagation();
+ event.preventDefault();
+ }
+
+
+ function isTownHallSelected() {
+ var ids = context.selectedIDs();
+ return ids.length === 1 && ids[0] === hallId;
+ }
+
+
+ function dragMap() {
+ context.enter(modeBrowse(context));
+ context.history().reset('initial');
+
+ var msec = transitionTime(townHall, context.map().center());
+ if (msec) { reveal(null, null, { duration: 0 }); }
+ context.map().centerZoomEase(townHall, 19, msec);
+
+ timeout(function() {
+ var centerStart = context.map().center();
+
+ var textId = context.lastPointerType() === 'mouse' ? 'drag' : 'drag_touch';
+ var dragString = helpString('intro.navigation.map_info') + '{br}' + helpString('intro.navigation.' + textId);
+ reveal('.surface', dragString);
+ context.map().on('drawn.intro', function() {
+ reveal('.surface', dragString, { duration: 0 });
+ });
+
+ context.map().on('move.intro', function() {
+ var centerNow = context.map().center();
+ if (centerStart[0] !== centerNow[0] || centerStart[1] !== centerNow[1]) {
+ context.map().on('move.intro', null);
+ timeout(function() { continueTo(zoomMap); }, 3000);
+ }
+ });
+
+ }, msec + 100);
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function zoomMap() {
+ var zoomStart = context.map().zoom();
+
+ var textId = context.lastPointerType() === 'mouse' ? 'zoom' : 'zoom_touch';
+ var zoomString = helpString('intro.navigation.' + textId);
+
+ reveal('.surface', zoomString);
+
+ context.map().on('drawn.intro', function() {
+ reveal('.surface', zoomString, { duration: 0 });
+ });
+
+ context.map().on('move.intro', function() {
+ if (context.map().zoom() !== zoomStart) {
+ context.map().on('move.intro', null);
+ timeout(function() { continueTo(features); }, 3000);
+ }
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function features() {
+ var onClick = function() { continueTo(pointsLinesAreas); };
+
+ reveal('.surface', helpString('intro.navigation.features'),
+ { buttonText: _t('intro.ok'), buttonCallback: onClick }
+ );
+
+ context.map().on('drawn.intro', function() {
+ reveal('.surface', helpString('intro.navigation.features'),
+ { duration: 0, buttonText: _t('intro.ok'), buttonCallback: onClick }
+ );
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('drawn.intro', null);
+ nextStep();
+ }
+ }
+
+ function pointsLinesAreas() {
+ var onClick = function() { continueTo(nodesWays); };
+
+ reveal('.surface', helpString('intro.navigation.points_lines_areas'),
+ { buttonText: _t('intro.ok'), buttonCallback: onClick }
+ );
+
+ context.map().on('drawn.intro', function() {
+ reveal('.surface', helpString('intro.navigation.points_lines_areas'),
+ { duration: 0, buttonText: _t('intro.ok'), buttonCallback: onClick }
+ );
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('drawn.intro', null);
+ nextStep();
+ }
+ }
+
+ function nodesWays() {
+ var onClick = function() { continueTo(clickTownHall); };
+
+ reveal('.surface', helpString('intro.navigation.nodes_ways'),
+ { buttonText: _t('intro.ok'), buttonCallback: onClick }
+ );
+
+ context.map().on('drawn.intro', function() {
+ reveal('.surface', helpString('intro.navigation.nodes_ways'),
+ { duration: 0, buttonText: _t('intro.ok'), buttonCallback: onClick }
+ );
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('drawn.intro', null);
+ nextStep();
+ }
+ }
+
+ function clickTownHall() {
+ context.enter(modeBrowse(context));
+ context.history().reset('initial');
+
+ var entity = context.hasEntity(hallId);
+ if (!entity) return;
+ reveal(null, null, { duration: 0 });
+ context.map().centerZoomEase(entity.loc, 19, 500);
+
+ timeout(function() {
+ var entity = context.hasEntity(hallId);
+ if (!entity) return;
+ var box = pointBox(entity.loc, context);
+ var textId = context.lastPointerType() === 'mouse' ? 'click_townhall' : 'tap_townhall';
+ reveal(box, helpString('intro.navigation.' + textId));
+
+ context.map().on('move.intro drawn.intro', function() {
+ var entity = context.hasEntity(hallId);
+ if (!entity) return;
+ var box = pointBox(entity.loc, context);
+ reveal(box, helpString('intro.navigation.' + textId), { duration: 0 });
+ });
+
+ context.on('enter.intro', function() {
+ if (isTownHallSelected()) continueTo(selectedTownHall);
+ });
+
+ }, 550); // after centerZoomEase
+
+ context.history().on('change.intro', function() {
+ if (!context.hasEntity(hallId)) {
+ continueTo(clickTownHall);
+ }
+ });
+
+ function continueTo(nextStep) {
+ context.on('enter.intro', null);
+ context.map().on('move.intro drawn.intro', null);
+ context.history().on('change.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function selectedTownHall() {
+ if (!isTownHallSelected()) return clickTownHall();
+
+ var entity = context.hasEntity(hallId);
+ if (!entity) return clickTownHall();
+
+ var box = pointBox(entity.loc, context);
+ var onClick = function() { continueTo(editorTownHall); };
+
+ reveal(box, helpString('intro.navigation.selected_townhall'),
+ { buttonText: _t('intro.ok'), buttonCallback: onClick }
+ );
+
+ context.map().on('move.intro drawn.intro', function() {
+ var entity = context.hasEntity(hallId);
+ if (!entity) return;
+ var box = pointBox(entity.loc, context);
+ reveal(box, helpString('intro.navigation.selected_townhall'),
+ { duration: 0, buttonText: _t('intro.ok'), buttonCallback: onClick }
+ );
+ });
+
+ context.history().on('change.intro', function() {
+ if (!context.hasEntity(hallId)) {
+ continueTo(clickTownHall);
+ }
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.history().on('change.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function editorTownHall() {
+ if (!isTownHallSelected()) return clickTownHall();
+
+ // disallow scrolling
+ context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);
+
+ var onClick = function() { continueTo(presetTownHall); };
+
+ reveal('.entity-editor-pane',
+ helpString('intro.navigation.editor_townhall'),
+ { buttonText: _t('intro.ok'), buttonCallback: onClick }
+ );
+
+ context.on('exit.intro', function() {
+ continueTo(clickTownHall);
+ });
+
+ context.history().on('change.intro', function() {
+ if (!context.hasEntity(hallId)) {
+ continueTo(clickTownHall);
+ }
+ });
+
+ function continueTo(nextStep) {
+ context.on('exit.intro', null);
+ context.history().on('change.intro', null);
+ context.container().select('.inspector-wrap').on('wheel.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function presetTownHall() {
+ if (!isTownHallSelected()) return clickTownHall();
+
+ // reset pane, in case user happened to change it..
+ context.container().select('.inspector-wrap .panewrap').style('right', '0%');
+ // disallow scrolling
+ context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);
+
+ // preset match, in case the user happened to change it.
+ var entity = context.entity(context.selectedIDs()[0]);
+ var preset = _mainPresetIndex.match(entity, context.graph());
+
+ var onClick = function() { continueTo(fieldsTownHall); };
+
+ reveal('.entity-editor-pane .section-feature-type',
+ helpString('intro.navigation.preset_townhall', { preset: preset.name() }),
+ { buttonText: _t('intro.ok'), buttonCallback: onClick }
+ );
+
+ context.on('exit.intro', function() {
+ continueTo(clickTownHall);
+ });
+
+ context.history().on('change.intro', function() {
+ if (!context.hasEntity(hallId)) {
+ continueTo(clickTownHall);
+ }
+ });
+
+ function continueTo(nextStep) {
+ context.on('exit.intro', null);
+ context.history().on('change.intro', null);
+ context.container().select('.inspector-wrap').on('wheel.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function fieldsTownHall() {
+ if (!isTownHallSelected()) return clickTownHall();
+
+ // reset pane, in case user happened to change it..
+ context.container().select('.inspector-wrap .panewrap').style('right', '0%');
+ // disallow scrolling
+ context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);
+
+ var onClick = function() { continueTo(closeTownHall); };
+
+ reveal('.entity-editor-pane .section-preset-fields',
+ helpString('intro.navigation.fields_townhall'),
+ { buttonText: _t('intro.ok'), buttonCallback: onClick }
+ );
+
+ context.on('exit.intro', function() {
+ continueTo(clickTownHall);
+ });
+
+ context.history().on('change.intro', function() {
+ if (!context.hasEntity(hallId)) {
+ continueTo(clickTownHall);
+ }
+ });
+
+ function continueTo(nextStep) {
+ context.on('exit.intro', null);
+ context.history().on('change.intro', null);
+ context.container().select('.inspector-wrap').on('wheel.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function closeTownHall() {
+ if (!isTownHallSelected()) return clickTownHall();
+
+ var selector = '.entity-editor-pane button.close svg use';
+ var href = select(selector).attr('href') || '#iD-icon-close';
+
+ reveal('.entity-editor-pane',
+ helpString('intro.navigation.close_townhall', { button: icon(href, 'pre-text') })
+ );
+
+ context.on('exit.intro', function() {
+ continueTo(searchStreet);
+ });
+
+ context.history().on('change.intro', function() {
+ // update the close icon in the tooltip if the user edits something.
+ var selector = '.entity-editor-pane button.close svg use';
+ var href = select(selector).attr('href') || '#iD-icon-close';
+
+ reveal('.entity-editor-pane',
+ helpString('intro.navigation.close_townhall', { button: icon(href, 'pre-text') }),
+ { duration: 0 }
+ );
+ });
+
+ function continueTo(nextStep) {
+ context.on('exit.intro', null);
+ context.history().on('change.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function searchStreet() {
+ context.enter(modeBrowse(context));
+ context.history().reset('initial'); // ensure spring street exists
+
+ var msec = transitionTime(springStreet, context.map().center());
+ if (msec) { reveal(null, null, { duration: 0 }); }
+ context.map().centerZoomEase(springStreet, 19, msec); // ..and user can see it
+
+ timeout(function() {
+ reveal('.search-header input',
+ helpString('intro.navigation.search_street', { name: _t('intro.graph.name.spring-street') })
+ );
+
+ context.container().select('.search-header input')
+ .on('keyup.intro', checkSearchResult);
+ }, msec + 100);
+ }
+
+
+ function checkSearchResult() {
+ var first = context.container().select('.feature-list-item:nth-child(0n+2)'); // skip "No Results" item
+ var firstName = first.select('.entity-name');
+ var name = _t('intro.graph.name.spring-street');
+
+ if (!firstName.empty() && firstName.text() === name) {
+ reveal(first.node(),
+ helpString('intro.navigation.choose_street', { name: name }),
+ { duration: 300 }
+ );
+
+ context.on('exit.intro', function() {
+ continueTo(selectedStreet);
+ });
+
+ context.container().select('.search-header input')
+ .on('keydown.intro', eventCancel, true)
+ .on('keyup.intro', null);
+ }
+
+ function continueTo(nextStep) {
+ context.on('exit.intro', null);
+ context.container().select('.search-header input')
+ .on('keydown.intro', null)
+ .on('keyup.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function selectedStreet() {
+ if (!context.hasEntity(springStreetEndId) || !context.hasEntity(springStreetId)) {
+ return searchStreet();
+ }
+
+ var onClick = function() { continueTo(editorStreet); };
+ var entity = context.entity(springStreetEndId);
+ var box = pointBox(entity.loc, context);
+ box.height = 500;
+
+ reveal(box,
+ helpString('intro.navigation.selected_street', { name: _t('intro.graph.name.spring-street') }),
+ { duration: 600, buttonText: _t('intro.ok'), buttonCallback: onClick }
+ );
+
+ timeout(function() {
+ context.map().on('move.intro drawn.intro', function() {
+ var entity = context.hasEntity(springStreetEndId);
+ if (!entity) return;
+ var box = pointBox(entity.loc, context);
+ box.height = 500;
+ reveal(box,
+ helpString('intro.navigation.selected_street', { name: _t('intro.graph.name.spring-street') }),
+ { duration: 0, buttonText: _t('intro.ok'), buttonCallback: onClick }
+ );
+ });
+ }, 600); // after reveal.
+
+ context.on('enter.intro', function(mode) {
+ if (!context.hasEntity(springStreetId)) {
+ return continueTo(searchStreet);
+ }
+ var ids = context.selectedIDs();
+ if (mode.id !== 'select' || !ids.length || ids[0] !== springStreetId) {
+ // keep Spring Street selected..
+ context.enter(modeSelect(context, [springStreetId]));
+ }
+ });
+
+ context.history().on('change.intro', function() {
+ if (!context.hasEntity(springStreetEndId) || !context.hasEntity(springStreetId)) {
+ timeout(function() {
+ continueTo(searchStreet);
+ }, 300); // after any transition (e.g. if user deleted intersection)
+ }
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.on('enter.intro', null);
+ context.history().on('change.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function editorStreet() {
+ var selector = '.entity-editor-pane button.close svg use';
+ var href = select(selector).attr('href') || '#iD-icon-close';
+
+ reveal('.entity-editor-pane', helpString('intro.navigation.street_different_fields') + '{br}' +
+ helpString('intro.navigation.editor_street', {
+ button: icon(href, 'pre-text'),
+ field1: onewayField.label(),
+ field2: maxspeedField.label()
+ }));
+
+ context.on('exit.intro', function() {
+ continueTo(play);
+ });
+
+ context.history().on('change.intro', function() {
+ // update the close icon in the tooltip if the user edits something.
+ var selector = '.entity-editor-pane button.close svg use';
+ var href = select(selector).attr('href') || '#iD-icon-close';
+
+ reveal('.entity-editor-pane', helpString('intro.navigation.street_different_fields') + '{br}' +
+ helpString('intro.navigation.editor_street', {
+ button: icon(href, 'pre-text'),
+ field1: onewayField.label(),
+ field2: maxspeedField.label()
+ }), { duration: 0 }
+ );
+ });
+
+ function continueTo(nextStep) {
+ context.on('exit.intro', null);
+ context.history().on('change.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function play() {
+ dispatch$1.call('done');
+ reveal('.ideditor',
+ helpString('intro.navigation.play', { next: _t('intro.points.title') }), {
+ tooltipBox: '.intro-nav-wrap .chapter-point',
+ buttonText: _t('intro.ok'),
+ buttonCallback: function() { reveal('.ideditor'); }
+ }
+ );
+ }
+
+
+ chapter.enter = function() {
+ dragMap();
+ };
+
+
+ chapter.exit = function() {
+ timeouts.forEach(window.clearTimeout);
+ context.on('enter.intro exit.intro', null);
+ context.map().on('move.intro drawn.intro', null);
+ context.history().on('change.intro', null);
+ context.container().select('.inspector-wrap').on('wheel.intro', null);
+ context.container().select('.search-header input').on('keydown.intro keyup.intro', null);
+ };
+
+
+ chapter.restart = function() {
+ chapter.exit();
+ chapter.enter();
+ };
+
+
+ return utilRebind(chapter, dispatch$1, 'on');
+ }
+
+ function uiIntroPoint(context, reveal) {
+ var dispatch$1 = dispatch('done');
+ var timeouts = [];
+ var intersection = [-85.63279, 41.94394];
+ var building = [-85.632422, 41.944045];
+ var cafePreset = _mainPresetIndex.item('amenity/cafe');
+ var _pointID = null;
+
+
+ var chapter = {
+ title: 'intro.points.title'
+ };
+
+
+ function timeout(f, t) {
+ timeouts.push(window.setTimeout(f, t));
+ }
+
+
+ function eventCancel() {
+ event.stopPropagation();
+ event.preventDefault();
+ }
+
+
+ function addPoint() {
+ context.enter(modeBrowse(context));
+ context.history().reset('initial');
+
+ var msec = transitionTime(intersection, context.map().center());
+ if (msec) { reveal(null, null, { duration: 0 }); }
+ context.map().centerZoomEase(intersection, 19, msec);
+
+ timeout(function() {
+ var tooltip = reveal('button.add-point',
+ helpString('intro.points.points_info') + '{br}' + helpString('intro.points.add_point'));
+
+ _pointID = null;
+
+ tooltip.selectAll('.popover-inner')
+ .insert('svg', 'span')
+ .attr('class', 'tooltip-illustration')
+ .append('use')
+ .attr('xlink:href', '#iD-graphic-points');
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id !== 'add-point') return;
+ continueTo(placePoint);
+ });
+ }, msec + 100);
+
+ function continueTo(nextStep) {
+ context.on('enter.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function placePoint() {
+ if (context.mode().id !== 'add-point') {
+ return chapter.restart();
+ }
+
+ var pointBox = pad(building, 150, context);
+ var textId = context.lastPointerType() === 'mouse' ? 'place_point' : 'place_point_touch';
+ reveal(pointBox, helpString('intro.points.' + textId));
+
+ context.map().on('move.intro drawn.intro', function() {
+ pointBox = pad(building, 150, context);
+ reveal(pointBox, helpString('intro.points.' + textId), { duration: 0 });
+ });
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id !== 'select') return chapter.restart();
+ _pointID = context.mode().selectedIDs()[0];
+ continueTo(searchPreset);
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.on('enter.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function searchPreset() {
+ if (context.mode().id !== 'select' || !_pointID || !context.hasEntity(_pointID)) {
+ return addPoint();
+ }
+
+ // disallow scrolling
+ context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);
+
+ context.container().select('.preset-search-input')
+ .on('keydown.intro', null)
+ .on('keyup.intro', checkPresetSearch);
+
+ reveal('.preset-search-input',
+ helpString('intro.points.search_cafe', { preset: cafePreset.name() })
+ );
+
+ context.on('enter.intro', function(mode) {
+ if (!_pointID || !context.hasEntity(_pointID)) {
+ return continueTo(addPoint);
+ }
+
+ var ids = context.selectedIDs();
+ if (mode.id !== 'select' || !ids.length || ids[0] !== _pointID) {
+ // keep the user's point selected..
+ context.enter(modeSelect(context, [_pointID]));
+
+ // disallow scrolling
+ context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);
+
+ context.container().select('.preset-search-input')
+ .on('keydown.intro', null)
+ .on('keyup.intro', checkPresetSearch);
+
+ reveal('.preset-search-input',
+ helpString('intro.points.search_cafe', { preset: cafePreset.name() })
+ );
+
+ context.history().on('change.intro', null);
+ }
+ });
+
+
+ function checkPresetSearch() {
+ var first = context.container().select('.preset-list-item:first-child');
+
+ if (first.classed('preset-amenity-cafe')) {
+ context.container().select('.preset-search-input')
+ .on('keydown.intro', eventCancel, true)
+ .on('keyup.intro', null);
+
+ reveal(first.select('.preset-list-button').node(),
+ helpString('intro.points.choose_cafe', { preset: cafePreset.name() }),
+ { duration: 300 }
+ );
+
+ context.history().on('change.intro', function() {
+ continueTo(aboutFeatureEditor);
+ });
+ }
+ }
+
+ function continueTo(nextStep) {
+ context.on('enter.intro', null);
+ context.history().on('change.intro', null);
+ context.container().select('.inspector-wrap').on('wheel.intro', null);
+ context.container().select('.preset-search-input').on('keydown.intro keyup.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function aboutFeatureEditor() {
+ if (context.mode().id !== 'select' || !_pointID || !context.hasEntity(_pointID)) {
+ return addPoint();
+ }
+
+ timeout(function() {
+ reveal('.entity-editor-pane', helpString('intro.points.feature_editor'), {
+ tooltipClass: 'intro-points-describe',
+ buttonText: _t('intro.ok'),
+ buttonCallback: function() { continueTo(addName); }
+ });
+ }, 400);
+
+ context.on('exit.intro', function() {
+ // if user leaves select mode here, just continue with the tutorial.
+ continueTo(reselectPoint);
+ });
+
+ function continueTo(nextStep) {
+ context.on('exit.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function addName() {
+ if (context.mode().id !== 'select' || !_pointID || !context.hasEntity(_pointID)) {
+ return addPoint();
+ }
+
+ // reset pane, in case user happened to change it..
+ context.container().select('.inspector-wrap .panewrap').style('right', '0%');
+
+ var addNameString = helpString('intro.points.fields_info') + '{br}' + helpString('intro.points.add_name');
+
+ timeout(function() {
+ // It's possible for the user to add a name in a previous step..
+ // If so, don't tell them to add the name in this step.
+ // Give them an OK button instead.
+ var entity = context.entity(_pointID);
+ if (entity.tags.name) {
+ var tooltip = reveal('.entity-editor-pane', addNameString, {
+ tooltipClass: 'intro-points-describe',
+ buttonText: _t('intro.ok'),
+ buttonCallback: function() { continueTo(addCloseEditor); }
+ });
+ tooltip.select('.instruction').style('display', 'none');
+
+ } else {
+ reveal('.entity-editor-pane', addNameString,
+ { tooltipClass: 'intro-points-describe' }
+ );
+ }
+ }, 400);
+
+ context.history().on('change.intro', function() {
+ continueTo(addCloseEditor);
+ });
+
+ context.on('exit.intro', function() {
+ // if user leaves select mode here, just continue with the tutorial.
+ continueTo(reselectPoint);
+ });
+
+ function continueTo(nextStep) {
+ context.on('exit.intro', null);
+ context.history().on('change.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function addCloseEditor() {
+ // reset pane, in case user happened to change it..
+ context.container().select('.inspector-wrap .panewrap').style('right', '0%');
+
+ var selector = '.entity-editor-pane button.close svg use';
+ var href = select(selector).attr('href') || '#iD-icon-close';
+
+ context.on('exit.intro', function() {
+ continueTo(reselectPoint);
+ });
+
+ reveal('.entity-editor-pane',
+ helpString('intro.points.add_close', { button: icon(href, 'pre-text') })
+ );
+
+ function continueTo(nextStep) {
+ context.on('exit.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function reselectPoint() {
+ if (!_pointID) return chapter.restart();
+ var entity = context.hasEntity(_pointID);
+ if (!entity) return chapter.restart();
+
+ // make sure it's still a cafe, in case user somehow changed it..
+ var oldPreset = _mainPresetIndex.match(entity, context.graph());
+ context.replace(actionChangePreset(_pointID, oldPreset, cafePreset));
+
+ context.enter(modeBrowse(context));
+
+ var msec = transitionTime(entity.loc, context.map().center());
+ if (msec) { reveal(null, null, { duration: 0 }); }
+ context.map().centerEase(entity.loc, msec);
+
+ timeout(function() {
+ var box = pointBox(entity.loc, context);
+ reveal(box, helpString('intro.points.reselect'), { duration: 600 });
+
+ timeout(function() {
+ context.map().on('move.intro drawn.intro', function() {
+ var entity = context.hasEntity(_pointID);
+ if (!entity) return chapter.restart();
+ var box = pointBox(entity.loc, context);
+ reveal(box, helpString('intro.points.reselect'), { duration: 0 });
+ });
+ }, 600); // after reveal..
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id !== 'select') return;
+ continueTo(updatePoint);
+ });
+
+ }, msec + 100);
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.on('enter.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function updatePoint() {
+ if (context.mode().id !== 'select' || !_pointID || !context.hasEntity(_pointID)) {
+ return continueTo(reselectPoint);
+ }
+
+ // reset pane, in case user happened to untag the point..
+ context.container().select('.inspector-wrap .panewrap').style('right', '0%');
+
+ context.on('exit.intro', function() {
+ continueTo(reselectPoint);
+ });
+
+ context.history().on('change.intro', function() {
+ continueTo(updateCloseEditor);
+ });
+
+ timeout(function() {
+ reveal('.entity-editor-pane', helpString('intro.points.update'),
+ { tooltipClass: 'intro-points-describe' }
+ );
+ }, 400);
+
+ function continueTo(nextStep) {
+ context.on('exit.intro', null);
+ context.history().on('change.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function updateCloseEditor() {
+ if (context.mode().id !== 'select' || !_pointID || !context.hasEntity(_pointID)) {
+ return continueTo(reselectPoint);
+ }
+
+ // reset pane, in case user happened to change it..
+ context.container().select('.inspector-wrap .panewrap').style('right', '0%');
+
+ context.on('exit.intro', function() {
+ continueTo(rightClickPoint);
+ });
+
+ timeout(function() {
+ reveal('.entity-editor-pane',
+ helpString('intro.points.update_close', { button: icon('#iD-icon-close', 'pre-text') })
+ );
+ }, 500);
+
+ function continueTo(nextStep) {
+ context.on('exit.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function rightClickPoint() {
+ if (!_pointID) return chapter.restart();
+ var entity = context.hasEntity(_pointID);
+ if (!entity) return chapter.restart();
+
+ context.enter(modeBrowse(context));
+
+ var box = pointBox(entity.loc, context);
+ var textId = context.lastPointerType() === 'mouse' ? 'rightclick' : 'edit_menu_touch';
+ reveal(box, helpString('intro.points.' + textId), { duration: 600 });
+
+ timeout(function() {
+ context.map().on('move.intro', function() {
+ var entity = context.hasEntity(_pointID);
+ if (!entity) return chapter.restart();
+ var box = pointBox(entity.loc, context);
+ reveal(box, helpString('intro.points.' + textId), { duration: 0 });
+ });
+ }, 600); // after reveal
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id !== 'select') return;
+ var ids = context.selectedIDs();
+ if (ids.length !== 1 || ids[0] !== _pointID) return;
+
+ timeout(function() {
+ var node = selectMenuItem(context, 'delete').node();
+ if (!node) return;
+ continueTo(enterDelete);
+ }, 50); // after menu visible
+ });
+
+ function continueTo(nextStep) {
+ context.on('enter.intro', null);
+ context.map().on('move.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function enterDelete() {
+ if (!_pointID) return chapter.restart();
+ var entity = context.hasEntity(_pointID);
+ if (!entity) return chapter.restart();
+
+ var node = selectMenuItem(context, 'delete').node();
+ if (!node) { return continueTo(rightClickPoint); }
+
+ reveal('.edit-menu',
+ helpString('intro.points.delete'),
+ { padding: 50 }
+ );
+
+ timeout(function() {
+ context.map().on('move.intro', function() {
+ reveal('.edit-menu',
+ helpString('intro.points.delete'),
+ { duration: 0, padding: 50 }
+ );
+ });
+ }, 300); // after menu visible
+
+ context.on('exit.intro', function() {
+ if (!_pointID) return chapter.restart();
+ var entity = context.hasEntity(_pointID);
+ if (entity) return continueTo(rightClickPoint); // point still exists
+ });
+
+ context.history().on('change.intro', function(changed) {
+ if (changed.deleted().length) {
+ continueTo(undo);
+ }
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro', null);
+ context.history().on('change.intro', null);
+ context.on('exit.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function undo() {
+ context.history().on('change.intro', function() {
+ continueTo(play);
+ });
+
+ reveal('.top-toolbar button.undo-button',
+ helpString('intro.points.undo')
+ );
+
+ function continueTo(nextStep) {
+ context.history().on('change.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function play() {
+ dispatch$1.call('done');
+ reveal('.ideditor',
+ helpString('intro.points.play', { next: _t('intro.areas.title') }), {
+ tooltipBox: '.intro-nav-wrap .chapter-area',
+ buttonText: _t('intro.ok'),
+ buttonCallback: function() { reveal('.ideditor'); }
+ }
+ );
+ }
+
+
+ chapter.enter = function() {
+ addPoint();
+ };
+
+
+ chapter.exit = function() {
+ timeouts.forEach(window.clearTimeout);
+ context.on('enter.intro exit.intro', null);
+ context.map().on('move.intro drawn.intro', null);
+ context.history().on('change.intro', null);
+ context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);
+ context.container().select('.preset-search-input').on('keydown.intro keyup.intro', null);
+ };
+
+
+ chapter.restart = function() {
+ chapter.exit();
+ chapter.enter();
+ };
+
+
+ return utilRebind(chapter, dispatch$1, 'on');
+ }
+
+ function uiIntroArea(context, reveal) {
+ var dispatch$1 = dispatch('done');
+ var playground = [-85.63552, 41.94159];
+ var playgroundPreset = _mainPresetIndex.item('leisure/playground');
+ var nameField = _mainPresetIndex.field('name');
+ var descriptionField = _mainPresetIndex.field('description');
+ var timeouts = [];
+ var _areaID;
+
+
+ var chapter = {
+ title: 'intro.areas.title'
+ };
+
+
+ function timeout(f, t) {
+ timeouts.push(window.setTimeout(f, t));
+ }
+
+
+ function eventCancel() {
+ event.stopPropagation();
+ event.preventDefault();
+ }
+
+
+ function revealPlayground(center, text, options) {
+ var padding = 180 * Math.pow(2, context.map().zoom() - 19.5);
+ var box = pad(center, padding, context);
+ reveal(box, text, options);
+ }
+
+
+ function addArea() {
+ context.enter(modeBrowse(context));
+ context.history().reset('initial');
+ _areaID = null;
+
+ var msec = transitionTime(playground, context.map().center());
+ if (msec) { reveal(null, null, { duration: 0 }); }
+ context.map().centerZoomEase(playground, 19, msec);
+
+ timeout(function() {
+ var tooltip = reveal('button.add-area',
+ helpString('intro.areas.add_playground'));
+
+ tooltip.selectAll('.popover-inner')
+ .insert('svg', 'span')
+ .attr('class', 'tooltip-illustration')
+ .append('use')
+ .attr('xlink:href', '#iD-graphic-areas');
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id !== 'add-area') return;
+ continueTo(startPlayground);
+ });
+ }, msec + 100);
+
+ function continueTo(nextStep) {
+ context.on('enter.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function startPlayground() {
+ if (context.mode().id !== 'add-area') {
+ return chapter.restart();
+ }
+
+ _areaID = null;
+ context.map().zoomEase(19.5, 500);
+
+ timeout(function() {
+ var textId = context.lastPointerType() === 'mouse' ? 'starting_node_click' : 'starting_node_tap';
+ var startDrawString = helpString('intro.areas.start_playground') + helpString('intro.areas.' + textId);
+ revealPlayground(playground,
+ startDrawString, { duration: 250 }
+ );
+
+ timeout(function() {
+ context.map().on('move.intro drawn.intro', function() {
+ revealPlayground(playground,
+ startDrawString, { duration: 0 }
+ );
+ });
+ context.on('enter.intro', function(mode) {
+ if (mode.id !== 'draw-area') return chapter.restart();
+ continueTo(continuePlayground);
+ });
+ }, 250); // after reveal
+
+ }, 550); // after easing
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.on('enter.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function continuePlayground() {
+ if (context.mode().id !== 'draw-area') {
+ return chapter.restart();
+ }
+
+ _areaID = null;
+ revealPlayground(playground,
+ helpString('intro.areas.continue_playground'),
+ { duration: 250 }
+ );
+
+ timeout(function() {
+ context.map().on('move.intro drawn.intro', function() {
+ revealPlayground(playground,
+ helpString('intro.areas.continue_playground'),
+ { duration: 0 }
+ );
+ });
+ }, 250); // after reveal
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id === 'draw-area') {
+ var entity = context.hasEntity(context.selectedIDs()[0]);
+ if (entity && entity.nodes.length >= 6) {
+ return continueTo(finishPlayground);
+ } else {
+ return;
+ }
+ } else if (mode.id === 'select') {
+ _areaID = context.selectedIDs()[0];
+ return continueTo(searchPresets);
+ } else {
+ return chapter.restart();
+ }
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.on('enter.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function finishPlayground() {
+ if (context.mode().id !== 'draw-area') {
+ return chapter.restart();
+ }
+
+ _areaID = null;
+
+ var finishString = helpString('intro.areas.finish_area_' + (context.lastPointerType() === 'mouse' ? 'click' : 'tap')) +
+ helpString('intro.areas.finish_playground');
+ revealPlayground(playground,
+ finishString, { duration: 250 }
+ );
+
+ timeout(function() {
+ context.map().on('move.intro drawn.intro', function() {
+ revealPlayground(playground,
+ finishString, { duration: 0 }
+ );
+ });
+ }, 250); // after reveal
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id === 'draw-area') {
+ return;
+ } else if (mode.id === 'select') {
+ _areaID = context.selectedIDs()[0];
+ return continueTo(searchPresets);
+ } else {
+ return chapter.restart();
+ }
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.on('enter.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function searchPresets() {
+ if (!_areaID || !context.hasEntity(_areaID)) {
+ return addArea();
+ }
+ var ids = context.selectedIDs();
+ if (context.mode().id !== 'select' || !ids.length || ids[0] !== _areaID) {
+ context.enter(modeSelect(context, [_areaID]));
+ }
+
+ // disallow scrolling
+ context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);
+
+ timeout(function() {
+ // reset pane, in case user somehow happened to change it..
+ context.container().select('.inspector-wrap .panewrap').style('right', '-100%');
+
+ context.container().select('.preset-search-input')
+ .on('keydown.intro', null)
+ .on('keyup.intro', checkPresetSearch);
+
+ reveal('.preset-search-input',
+ helpString('intro.areas.search_playground', { preset: playgroundPreset.name() })
+ );
+ }, 400); // after preset list pane visible..
+
+ context.on('enter.intro', function(mode) {
+ if (!_areaID || !context.hasEntity(_areaID)) {
+ return continueTo(addArea);
+ }
+
+ var ids = context.selectedIDs();
+ if (mode.id !== 'select' || !ids.length || ids[0] !== _areaID) {
+ // keep the user's area selected..
+ context.enter(modeSelect(context, [_areaID]));
+
+ // reset pane, in case user somehow happened to change it..
+ context.container().select('.inspector-wrap .panewrap').style('right', '-100%');
+ // disallow scrolling
+ context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);
+
+ context.container().select('.preset-search-input')
+ .on('keydown.intro', null)
+ .on('keyup.intro', checkPresetSearch);
+
+ reveal('.preset-search-input',
+ helpString('intro.areas.search_playground', { preset: playgroundPreset.name() })
+ );
+
+ context.history().on('change.intro', null);
+ }
+ });
+
+ function checkPresetSearch() {
+ var first = context.container().select('.preset-list-item:first-child');
+
+ if (first.classed('preset-leisure-playground')) {
+ reveal(first.select('.preset-list-button').node(),
+ helpString('intro.areas.choose_playground', { preset: playgroundPreset.name() }),
+ { duration: 300 }
+ );
+
+ context.container().select('.preset-search-input')
+ .on('keydown.intro', eventCancel, true)
+ .on('keyup.intro', null);
+
+ context.history().on('change.intro', function() {
+ continueTo(clickAddField);
+ });
+ }
+ }
+
+ function continueTo(nextStep) {
+ context.container().select('.inspector-wrap').on('wheel.intro', null);
+ context.on('enter.intro', null);
+ context.history().on('change.intro', null);
+ context.container().select('.preset-search-input').on('keydown.intro keyup.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function clickAddField() {
+ if (!_areaID || !context.hasEntity(_areaID)) {
+ return addArea();
+ }
+ var ids = context.selectedIDs();
+ if (context.mode().id !== 'select' || !ids.length || ids[0] !== _areaID) {
+ return searchPresets();
+ }
+
+ if (!context.container().select('.form-field-description').empty()) {
+ return continueTo(describePlayground);
+ }
+
+ // disallow scrolling
+ context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);
+
+ timeout(function() {
+ // reset pane, in case user somehow happened to change it..
+ context.container().select('.inspector-wrap .panewrap').style('right', '0%');
+
+ // It's possible for the user to add a description in a previous step..
+ // If they did this already, just continue to next step.
+ var entity = context.entity(_areaID);
+ if (entity.tags.description) {
+ return continueTo(play);
+ }
+
+ // scroll "Add field" into view
+ var box = context.container().select('.more-fields').node().getBoundingClientRect();
+ if (box.top > 300) {
+ var pane = context.container().select('.entity-editor-pane .inspector-body');
+ var start = pane.node().scrollTop;
+ var end = start + (box.top - 300);
+
+ pane
+ .transition()
+ .duration(250)
+ .tween('scroll.inspector', function() {
+ var node = this;
+ var i = d3_interpolateNumber(start, end);
+ return function(t) {
+ node.scrollTop = i(t);
+ };
+ });
+ }
+
+ timeout(function() {
+ reveal('.more-fields .combobox-input',
+ helpString('intro.areas.add_field', {
+ name: nameField.label(),
+ description: descriptionField.label()
+ }),
+ { duration: 300 }
+ );
+
+ context.container().select('.more-fields .combobox-input')
+ .on('click.intro', function() {
+ // Watch for the combobox to appear...
+ var watcher;
+ watcher = window.setInterval(function() {
+ if (!context.container().select('div.combobox').empty()) {
+ window.clearInterval(watcher);
+ continueTo(chooseDescriptionField);
+ }
+ }, 300);
+ });
+ }, 300); // after "Add Field" visible
+
+ }, 400); // after editor pane visible
+
+ context.on('exit.intro', function() {
+ return continueTo(searchPresets);
+ });
+
+ function continueTo(nextStep) {
+ context.container().select('.inspector-wrap').on('wheel.intro', null);
+ context.container().select('.more-fields .combobox-input').on('click.intro', null);
+ context.on('exit.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function chooseDescriptionField() {
+ if (!_areaID || !context.hasEntity(_areaID)) {
+ return addArea();
+ }
+ var ids = context.selectedIDs();
+ if (context.mode().id !== 'select' || !ids.length || ids[0] !== _areaID) {
+ return searchPresets();
+ }
+
+ if (!context.container().select('.form-field-description').empty()) {
+ return continueTo(describePlayground);
+ }
+
+ // Make sure combobox is ready..
+ if (context.container().select('div.combobox').empty()) {
+ return continueTo(clickAddField);
+ }
+ // Watch for the combobox to go away..
+ var watcher;
+ watcher = window.setInterval(function() {
+ if (context.container().select('div.combobox').empty()) {
+ window.clearInterval(watcher);
+ timeout(function() {
+ if (context.container().select('.form-field-description').empty()) {
+ continueTo(retryChooseDescription);
+ } else {
+ continueTo(describePlayground);
+ }
+ }, 300); // after description field added.
+ }
+ }, 300);
+
+ reveal('div.combobox',
+ helpString('intro.areas.choose_field', { field: descriptionField.label() }),
+ { duration: 300 }
+ );
+
+ context.on('exit.intro', function() {
+ return continueTo(searchPresets);
+ });
+
+ function continueTo(nextStep) {
+ if (watcher) window.clearInterval(watcher);
+ context.on('exit.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function describePlayground() {
+ if (!_areaID || !context.hasEntity(_areaID)) {
+ return addArea();
+ }
+ var ids = context.selectedIDs();
+ if (context.mode().id !== 'select' || !ids.length || ids[0] !== _areaID) {
+ return searchPresets();
+ }
+
+ // reset pane, in case user happened to change it..
+ context.container().select('.inspector-wrap .panewrap').style('right', '0%');
+
+ if (context.container().select('.form-field-description').empty()) {
+ return continueTo(retryChooseDescription);
+ }
+
+ context.on('exit.intro', function() {
+ continueTo(play);
+ });
+
+ reveal('.entity-editor-pane',
+ helpString('intro.areas.describe_playground', { button: icon('#iD-icon-close', 'pre-text') }),
+ { duration: 300 }
+ );
+
+ function continueTo(nextStep) {
+ context.on('exit.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function retryChooseDescription() {
+ if (!_areaID || !context.hasEntity(_areaID)) {
+ return addArea();
+ }
+ var ids = context.selectedIDs();
+ if (context.mode().id !== 'select' || !ids.length || ids[0] !== _areaID) {
+ return searchPresets();
+ }
+
+ // reset pane, in case user happened to change it..
+ context.container().select('.inspector-wrap .panewrap').style('right', '0%');
+
+ reveal('.entity-editor-pane',
+ helpString('intro.areas.retry_add_field', { field: descriptionField.label() }), {
+ buttonText: _t('intro.ok'),
+ buttonCallback: function() { continueTo(clickAddField); }
+ });
+
+ context.on('exit.intro', function() {
+ return continueTo(searchPresets);
+ });
+
+ function continueTo(nextStep) {
+ context.on('exit.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function play() {
+ dispatch$1.call('done');
+ reveal('.ideditor',
+ helpString('intro.areas.play', { next: _t('intro.lines.title') }), {
+ tooltipBox: '.intro-nav-wrap .chapter-line',
+ buttonText: _t('intro.ok'),
+ buttonCallback: function() { reveal('.ideditor'); }
+ }
+ );
+ }
+
+
+ chapter.enter = function() {
+ addArea();
+ };
+
+
+ chapter.exit = function() {
+ timeouts.forEach(window.clearTimeout);
+ context.on('enter.intro exit.intro', null);
+ context.map().on('move.intro drawn.intro', null);
+ context.history().on('change.intro', null);
+ context.container().select('.inspector-wrap').on('wheel.intro', null);
+ context.container().select('.preset-search-input').on('keydown.intro keyup.intro', null);
+ context.container().select('.more-fields .combobox-input').on('click.intro', null);
+ };
+
+
+ chapter.restart = function() {
+ chapter.exit();
+ chapter.enter();
+ };
+
+
+ return utilRebind(chapter, dispatch$1, 'on');
+ }
+
+ function uiIntroLine(context, reveal) {
+ var dispatch$1 = dispatch('done');
+ var timeouts = [];
+ var _tulipRoadID = null;
+ var flowerRoadID = 'w646';
+ var tulipRoadStart = [-85.6297754121684, 41.95805253325314];
+ var tulipRoadMidpoint = [-85.62975395449628, 41.95787501510204];
+ var tulipRoadIntersection = [-85.62974496187628, 41.95742515554585];
+ var roadCategory = _mainPresetIndex.item('category-road_minor');
+ var residentialPreset = _mainPresetIndex.item('highway/residential');
+ var woodRoadID = 'w525';
+ var woodRoadEndID = 'n2862';
+ var woodRoadAddNode = [-85.62390110349587, 41.95397111462291];
+ var woodRoadDragEndpoint = [-85.623867390213, 41.95466987786487];
+ var woodRoadDragMidpoint = [-85.62386254803509, 41.95430395953872];
+ var washingtonStreetID = 'w522';
+ var twelfthAvenueID = 'w1';
+ var eleventhAvenueEndID = 'n3550';
+ var twelfthAvenueEndID = 'n5';
+ var _washingtonSegmentID = null;
+ var eleventhAvenueEnd = context.entity(eleventhAvenueEndID).loc;
+ var twelfthAvenueEnd = context.entity(twelfthAvenueEndID).loc;
+ var deleteLinesLoc = [-85.6219395542764, 41.95228033922477];
+ var twelfthAvenue = [-85.62219310052491, 41.952505413152956];
+
+
+ var chapter = {
+ title: 'intro.lines.title'
+ };
+
+
+ function timeout(f, t) {
+ timeouts.push(window.setTimeout(f, t));
+ }
+
+
+ function eventCancel() {
+ event.stopPropagation();
+ event.preventDefault();
+ }
+
+
+ function addLine() {
+ context.enter(modeBrowse(context));
+ context.history().reset('initial');
+
+ var msec = transitionTime(tulipRoadStart, context.map().center());
+ if (msec) { reveal(null, null, { duration: 0 }); }
+ context.map().centerZoomEase(tulipRoadStart, 18.5, msec);
+
+ timeout(function() {
+ var tooltip = reveal('button.add-line',
+ helpString('intro.lines.add_line'));
+
+ tooltip.selectAll('.popover-inner')
+ .insert('svg', 'span')
+ .attr('class', 'tooltip-illustration')
+ .append('use')
+ .attr('xlink:href', '#iD-graphic-lines');
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id !== 'add-line') return;
+ continueTo(startLine);
+ });
+ }, msec + 100);
+
+ function continueTo(nextStep) {
+ context.on('enter.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function startLine() {
+ if (context.mode().id !== 'add-line') return chapter.restart();
+
+ _tulipRoadID = null;
+
+ var padding = 70 * Math.pow(2, context.map().zoom() - 18);
+ var box = pad(tulipRoadStart, padding, context);
+ box.height = box.height + 100;
+
+ var textId = context.lastPointerType() === 'mouse' ? 'start_line' : 'start_line_tap';
+ var startLineString = helpString('intro.lines.missing_road') + '{br}' +
+ helpString('intro.lines.line_draw_info') +
+ helpString('intro.lines.' + textId);
+ reveal(box, startLineString);
+
+ context.map().on('move.intro drawn.intro', function() {
+ padding = 70 * Math.pow(2, context.map().zoom() - 18);
+ box = pad(tulipRoadStart, padding, context);
+ box.height = box.height + 100;
+ reveal(box, startLineString, { duration: 0 });
+ });
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id !== 'draw-line') return chapter.restart();
+ continueTo(drawLine);
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.on('enter.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function drawLine() {
+ if (context.mode().id !== 'draw-line') return chapter.restart();
+
+ _tulipRoadID = context.mode().selectedIDs()[0];
+ context.map().centerEase(tulipRoadMidpoint, 500);
+
+ timeout(function() {
+ var padding = 200 * Math.pow(2, context.map().zoom() - 18.5);
+ var box = pad(tulipRoadMidpoint, padding, context);
+ box.height = box.height * 2;
+ reveal(box,
+ helpString('intro.lines.intersect', { name: _t('intro.graph.name.flower-street') })
+ );
+
+ context.map().on('move.intro drawn.intro', function() {
+ padding = 200 * Math.pow(2, context.map().zoom() - 18.5);
+ box = pad(tulipRoadMidpoint, padding, context);
+ box.height = box.height * 2;
+ reveal(box,
+ helpString('intro.lines.intersect', { name: _t('intro.graph.name.flower-street') }),
+ { duration: 0 }
+ );
+ });
+ }, 550); // after easing..
+
+ context.history().on('change.intro', function() {
+ if (isLineConnected()) {
+ continueTo(continueLine);
+ }
+ });
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id === 'draw-line') {
+ return;
+ } else if (mode.id === 'select') {
+ continueTo(retryIntersect);
+ return;
+ } else {
+ return chapter.restart();
+ }
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.history().on('change.intro', null);
+ context.on('enter.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function isLineConnected() {
+ var entity = _tulipRoadID && context.hasEntity(_tulipRoadID);
+ if (!entity) return false;
+
+ var drawNodes = context.graph().childNodes(entity);
+ return drawNodes.some(function(node) {
+ return context.graph().parentWays(node).some(function(parent) {
+ return parent.id === flowerRoadID;
+ });
+ });
+ }
+
+
+ function retryIntersect() {
+ select(window).on('pointerdown.intro mousedown.intro', eventCancel, true);
+
+ var box = pad(tulipRoadIntersection, 80, context);
+ reveal(box,
+ helpString('intro.lines.retry_intersect', { name: _t('intro.graph.name.flower-street') })
+ );
+
+ timeout(chapter.restart, 3000);
+ }
+
+
+ function continueLine() {
+ if (context.mode().id !== 'draw-line') return chapter.restart();
+ var entity = _tulipRoadID && context.hasEntity(_tulipRoadID);
+ if (!entity) return chapter.restart();
+
+ context.map().centerEase(tulipRoadIntersection, 500);
+
+ var continueLineText = helpString('intro.lines.continue_line') + '{br}' +
+ helpString('intro.lines.finish_line_' + (context.lastPointerType() === 'mouse' ? 'click' : 'tap')) +
+ helpString('intro.lines.finish_road');
+
+ reveal('.surface', continueLineText);
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id === 'draw-line')
+ return;
+ else if (mode.id === 'select')
+ return continueTo(chooseCategoryRoad);
+ else
+ return chapter.restart();
+ });
+
+ function continueTo(nextStep) {
+ context.on('enter.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function chooseCategoryRoad() {
+ if (context.mode().id !== 'select') return chapter.restart();
+
+ context.on('exit.intro', function() {
+ return chapter.restart();
+ });
+
+ var button = context.container().select('.preset-category-road_minor .preset-list-button');
+ if (button.empty()) return chapter.restart();
+
+ // disallow scrolling
+ context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);
+
+ timeout(function() {
+ // reset pane, in case user somehow happened to change it..
+ context.container().select('.inspector-wrap .panewrap').style('right', '-100%');
+
+ reveal(button.node(),
+ helpString('intro.lines.choose_category_road', { category: roadCategory.name() })
+ );
+
+ button.on('click.intro', function() {
+ continueTo(choosePresetResidential);
+ });
+
+ }, 400); // after editor pane visible
+
+ function continueTo(nextStep) {
+ context.container().select('.inspector-wrap').on('wheel.intro', null);
+ context.container().select('.preset-list-button').on('click.intro', null);
+ context.on('exit.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function choosePresetResidential() {
+ if (context.mode().id !== 'select') return chapter.restart();
+
+ context.on('exit.intro', function() {
+ return chapter.restart();
+ });
+
+ var subgrid = context.container().select('.preset-category-road_minor .subgrid');
+ if (subgrid.empty()) return chapter.restart();
+
+ subgrid.selectAll(':not(.preset-highway-residential) .preset-list-button')
+ .on('click.intro', function() {
+ continueTo(retryPresetResidential);
+ });
+
+ subgrid.selectAll('.preset-highway-residential .preset-list-button')
+ .on('click.intro', function() {
+ continueTo(nameRoad);
+ });
+
+ timeout(function() {
+ reveal(subgrid.node(),
+ helpString('intro.lines.choose_preset_residential', { preset: residentialPreset.name() }),
+ { tooltipBox: '.preset-highway-residential .preset-list-button', duration: 300 }
+ );
+ }, 300);
+
+ function continueTo(nextStep) {
+ context.container().select('.preset-list-button').on('click.intro', null);
+ context.on('exit.intro', null);
+ nextStep();
+ }
+ }
+
+
+ // selected wrong road type
+ function retryPresetResidential() {
+ if (context.mode().id !== 'select') return chapter.restart();
+
+ context.on('exit.intro', function() {
+ return chapter.restart();
+ });
+
+ // disallow scrolling
+ context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);
+
+ timeout(function() {
+ var button = context.container().select('.entity-editor-pane .preset-list-button');
+
+ reveal(button.node(),
+ helpString('intro.lines.retry_preset_residential', { preset: residentialPreset.name() })
+ );
+
+ button.on('click.intro', function() {
+ continueTo(chooseCategoryRoad);
+ });
+
+ }, 500);
+
+ function continueTo(nextStep) {
+ context.container().select('.inspector-wrap').on('wheel.intro', null);
+ context.container().select('.preset-list-button').on('click.intro', null);
+ context.on('exit.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function nameRoad() {
+ context.on('exit.intro', function() {
+ continueTo(didNameRoad);
+ });
+
+ timeout(function() {
+ reveal('.entity-editor-pane',
+ helpString('intro.lines.name_road', { button: icon('#iD-icon-close', 'pre-text') }),
+ { tooltipClass: 'intro-lines-name_road' }
+ );
+ }, 500);
+
+ function continueTo(nextStep) {
+ context.on('exit.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function didNameRoad() {
+ context.history().checkpoint('doneAddLine');
+
+ timeout(function() {
+ reveal('.surface', helpString('intro.lines.did_name_road'), {
+ buttonText: _t('intro.ok'),
+ buttonCallback: function() { continueTo(updateLine); }
+ });
+ }, 500);
+
+ function continueTo(nextStep) {
+ nextStep();
+ }
+ }
+
+
+ function updateLine() {
+ context.history().reset('doneAddLine');
+ if (!context.hasEntity(woodRoadID) || !context.hasEntity(woodRoadEndID)) {
+ return chapter.restart();
+ }
+
+ var msec = transitionTime(woodRoadDragMidpoint, context.map().center());
+ if (msec) { reveal(null, null, { duration: 0 }); }
+ context.map().centerZoomEase(woodRoadDragMidpoint, 19, msec);
+
+ timeout(function() {
+ var padding = 250 * Math.pow(2, context.map().zoom() - 19);
+ var box = pad(woodRoadDragMidpoint, padding, context);
+ var advance = function() { continueTo(addNode); };
+
+ reveal(box, helpString('intro.lines.update_line'),
+ { buttonText: _t('intro.ok'), buttonCallback: advance }
+ );
+
+ context.map().on('move.intro drawn.intro', function() {
+ var padding = 250 * Math.pow(2, context.map().zoom() - 19);
+ var box = pad(woodRoadDragMidpoint, padding, context);
+ reveal(box, helpString('intro.lines.update_line'),
+ { duration: 0, buttonText: _t('intro.ok'), buttonCallback: advance }
+ );
+ });
+ }, msec + 100);
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function addNode() {
+ context.history().reset('doneAddLine');
+ if (!context.hasEntity(woodRoadID) || !context.hasEntity(woodRoadEndID)) {
+ return chapter.restart();
+ }
+
+ var padding = 40 * Math.pow(2, context.map().zoom() - 19);
+ var box = pad(woodRoadAddNode, padding, context);
+ var addNodeString = helpString('intro.lines.add_node' + (context.lastPointerType() === 'mouse' ? '' : '_touch'));
+ reveal(box, addNodeString);
+
+ context.map().on('move.intro drawn.intro', function() {
+ var padding = 40 * Math.pow(2, context.map().zoom() - 19);
+ var box = pad(woodRoadAddNode, padding, context);
+ reveal(box, addNodeString, { duration: 0 });
+ });
+
+ context.history().on('change.intro', function(changed) {
+ if (!context.hasEntity(woodRoadID) || !context.hasEntity(woodRoadEndID)) {
+ return continueTo(updateLine);
+ }
+ if (changed.created().length === 1) {
+ timeout(function() { continueTo(startDragEndpoint); }, 500);
+ }
+ });
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id !== 'select') {
+ continueTo(updateLine);
+ }
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.history().on('change.intro', null);
+ context.on('enter.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function startDragEndpoint() {
+ if (!context.hasEntity(woodRoadID) || !context.hasEntity(woodRoadEndID)) {
+ return continueTo(updateLine);
+ }
+ var padding = 100 * Math.pow(2, context.map().zoom() - 19);
+ var box = pad(woodRoadDragEndpoint, padding, context);
+ var startDragString = helpString('intro.lines.start_drag_endpoint' + (context.lastPointerType() === 'mouse' ? '' : '_touch')) +
+ helpString('intro.lines.drag_to_intersection');
+ reveal(box, startDragString);
+
+ context.map().on('move.intro drawn.intro', function() {
+ if (!context.hasEntity(woodRoadID) || !context.hasEntity(woodRoadEndID)) {
+ return continueTo(updateLine);
+ }
+ var padding = 100 * Math.pow(2, context.map().zoom() - 19);
+ var box = pad(woodRoadDragEndpoint, padding, context);
+ reveal(box, startDragString, { duration: 0 });
+
+ var entity = context.entity(woodRoadEndID);
+ if (geoSphericalDistance(entity.loc, woodRoadDragEndpoint) <= 4) {
+ continueTo(finishDragEndpoint);
+ }
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function finishDragEndpoint() {
+ if (!context.hasEntity(woodRoadID) || !context.hasEntity(woodRoadEndID)) {
+ return continueTo(updateLine);
+ }
+
+ var padding = 100 * Math.pow(2, context.map().zoom() - 19);
+ var box = pad(woodRoadDragEndpoint, padding, context);
+ var finishDragString = helpString('intro.lines.spot_looks_good') +
+ helpString('intro.lines.finish_drag_endpoint' + (context.lastPointerType() === 'mouse' ? '' : '_touch'));
+ reveal(box, finishDragString);
+
+ context.map().on('move.intro drawn.intro', function() {
+ if (!context.hasEntity(woodRoadID) || !context.hasEntity(woodRoadEndID)) {
+ return continueTo(updateLine);
+ }
+ var padding = 100 * Math.pow(2, context.map().zoom() - 19);
+ var box = pad(woodRoadDragEndpoint, padding, context);
+ reveal(box, finishDragString, { duration: 0 });
+
+ var entity = context.entity(woodRoadEndID);
+ if (geoSphericalDistance(entity.loc, woodRoadDragEndpoint) > 4) {
+ continueTo(startDragEndpoint);
+ }
+ });
+
+ context.on('enter.intro', function() {
+ continueTo(startDragMidpoint);
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.on('enter.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function startDragMidpoint() {
+ if (!context.hasEntity(woodRoadID) || !context.hasEntity(woodRoadEndID)) {
+ return continueTo(updateLine);
+ }
+ if (context.selectedIDs().indexOf(woodRoadID) === -1) {
+ context.enter(modeSelect(context, [woodRoadID]));
+ }
+
+ var padding = 80 * Math.pow(2, context.map().zoom() - 19);
+ var box = pad(woodRoadDragMidpoint, padding, context);
+ reveal(box, helpString('intro.lines.start_drag_midpoint'));
+
+ context.map().on('move.intro drawn.intro', function() {
+ if (!context.hasEntity(woodRoadID) || !context.hasEntity(woodRoadEndID)) {
+ return continueTo(updateLine);
+ }
+ var padding = 80 * Math.pow(2, context.map().zoom() - 19);
+ var box = pad(woodRoadDragMidpoint, padding, context);
+ reveal(box, helpString('intro.lines.start_drag_midpoint'), { duration: 0 });
+ });
+
+ context.history().on('change.intro', function(changed) {
+ if (changed.created().length === 1) {
+ continueTo(continueDragMidpoint);
+ }
+ });
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id !== 'select') {
+ // keep Wood Road selected so midpoint triangles are drawn..
+ context.enter(modeSelect(context, [woodRoadID]));
+ }
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.history().on('change.intro', null);
+ context.on('enter.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function continueDragMidpoint() {
+ if (!context.hasEntity(woodRoadID) || !context.hasEntity(woodRoadEndID)) {
+ return continueTo(updateLine);
+ }
+
+ var padding = 100 * Math.pow(2, context.map().zoom() - 19);
+ var box = pad(woodRoadDragEndpoint, padding, context);
+ box.height += 400;
+
+ var advance = function() {
+ context.history().checkpoint('doneUpdateLine');
+ continueTo(deleteLines);
+ };
+
+ reveal(box, helpString('intro.lines.continue_drag_midpoint'),
+ { buttonText: _t('intro.ok'), buttonCallback: advance }
+ );
+
+ context.map().on('move.intro drawn.intro', function() {
+ if (!context.hasEntity(woodRoadID) || !context.hasEntity(woodRoadEndID)) {
+ return continueTo(updateLine);
+ }
+ var padding = 100 * Math.pow(2, context.map().zoom() - 19);
+ var box = pad(woodRoadDragEndpoint, padding, context);
+ box.height += 400;
+ reveal(box, helpString('intro.lines.continue_drag_midpoint'),
+ { duration: 0, buttonText: _t('intro.ok'), buttonCallback: advance }
+ );
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function deleteLines() {
+ context.history().reset('doneUpdateLine');
+ context.enter(modeBrowse(context));
+
+ if (!context.hasEntity(washingtonStreetID) ||
+ !context.hasEntity(twelfthAvenueID) ||
+ !context.hasEntity(eleventhAvenueEndID)) {
+ return chapter.restart();
+ }
+
+ var msec = transitionTime(deleteLinesLoc, context.map().center());
+ if (msec) { reveal(null, null, { duration: 0 }); }
+ context.map().centerZoomEase(deleteLinesLoc, 18, msec);
+
+ timeout(function() {
+ var padding = 200 * Math.pow(2, context.map().zoom() - 18);
+ var box = pad(deleteLinesLoc, padding, context);
+ box.top -= 200;
+ box.height += 400;
+ var advance = function() { continueTo(rightClickIntersection); };
+
+ reveal(box, helpString('intro.lines.delete_lines', { street: _t('intro.graph.name.12th-avenue') }),
+ { buttonText: _t('intro.ok'), buttonCallback: advance }
+ );
+
+ context.map().on('move.intro drawn.intro', function() {
+ var padding = 200 * Math.pow(2, context.map().zoom() - 18);
+ var box = pad(deleteLinesLoc, padding, context);
+ box.top -= 200;
+ box.height += 400;
+ reveal(box, helpString('intro.lines.delete_lines', { street: _t('intro.graph.name.12th-avenue') }),
+ { duration: 0, buttonText: _t('intro.ok'), buttonCallback: advance }
+ );
+ });
+
+ context.history().on('change.intro', function() {
+ timeout(function() {
+ continueTo(deleteLines);
+ }, 500); // after any transition (e.g. if user deleted intersection)
+ });
+
+ }, msec + 100);
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.history().on('change.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function rightClickIntersection() {
+ context.history().reset('doneUpdateLine');
+ context.enter(modeBrowse(context));
+
+ context.map().centerZoomEase(eleventhAvenueEnd, 18, 500);
+
+ var rightClickString = helpString('intro.lines.split_street', {
+ street1: _t('intro.graph.name.11th-avenue'),
+ street2: _t('intro.graph.name.washington-street')
+ }) +
+ helpString('intro.lines.' + (context.lastPointerType() === 'mouse' ? 'rightclick_intersection' : 'edit_menu_intersection_touch'));
+
+ timeout(function() {
+ var padding = 60 * Math.pow(2, context.map().zoom() - 18);
+ var box = pad(eleventhAvenueEnd, padding, context);
+ reveal(box, rightClickString);
+
+ context.map().on('move.intro drawn.intro', function() {
+ var padding = 60 * Math.pow(2, context.map().zoom() - 18);
+ var box = pad(eleventhAvenueEnd, padding, context);
+ reveal(box, rightClickString,
+ { duration: 0 }
+ );
+ });
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id !== 'select') return;
+ var ids = context.selectedIDs();
+ if (ids.length !== 1 || ids[0] !== eleventhAvenueEndID) return;
+
+ timeout(function() {
+ var node = selectMenuItem(context, 'split').node();
+ if (!node) return;
+ continueTo(splitIntersection);
+ }, 50); // after menu visible
+ });
+
+ context.history().on('change.intro', function() {
+ timeout(function() {
+ continueTo(deleteLines);
+ }, 300); // after any transition (e.g. if user deleted intersection)
+ });
+
+ }, 600);
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.on('enter.intro', null);
+ context.history().on('change.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function splitIntersection() {
+ if (!context.hasEntity(washingtonStreetID) ||
+ !context.hasEntity(twelfthAvenueID) ||
+ !context.hasEntity(eleventhAvenueEndID)) {
+ return continueTo(deleteLines);
+ }
+
+ var node = selectMenuItem(context, 'split').node();
+ if (!node) { return continueTo(rightClickIntersection); }
+
+ var wasChanged = false;
+ _washingtonSegmentID = null;
+
+ reveal('.edit-menu', helpString('intro.lines.split_intersection',
+ { street: _t('intro.graph.name.washington-street') }),
+ { padding: 50 }
+ );
+
+ context.map().on('move.intro drawn.intro', function() {
+ var node = selectMenuItem(context, 'split').node();
+ if (!wasChanged && !node) { return continueTo(rightClickIntersection); }
+
+ reveal('.edit-menu', helpString('intro.lines.split_intersection',
+ { street: _t('intro.graph.name.washington-street') }),
+ { duration: 0, padding: 50 }
+ );
+ });
+
+ context.history().on('change.intro', function(changed) {
+ wasChanged = true;
+ timeout(function() {
+ if (context.history().undoAnnotation() === _t('operations.split.annotation.line')) {
+ _washingtonSegmentID = changed.created()[0].id;
+ continueTo(didSplit);
+ } else {
+ _washingtonSegmentID = null;
+ continueTo(retrySplit);
+ }
+ }, 300); // after any transition (e.g. if user deleted intersection)
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.history().on('change.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function retrySplit() {
+ context.enter(modeBrowse(context));
+ context.map().centerZoomEase(eleventhAvenueEnd, 18, 500);
+ var advance = function() { continueTo(rightClickIntersection); };
+
+ var padding = 60 * Math.pow(2, context.map().zoom() - 18);
+ var box = pad(eleventhAvenueEnd, padding, context);
+ reveal(box, helpString('intro.lines.retry_split'),
+ { buttonText: _t('intro.ok'), buttonCallback: advance }
+ );
+
+ context.map().on('move.intro drawn.intro', function() {
+ var padding = 60 * Math.pow(2, context.map().zoom() - 18);
+ var box = pad(eleventhAvenueEnd, padding, context);
+ reveal(box, helpString('intro.lines.retry_split'),
+ { duration: 0, buttonText: _t('intro.ok'), buttonCallback: advance }
+ );
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function didSplit() {
+ if (!_washingtonSegmentID ||
+ !context.hasEntity(_washingtonSegmentID) ||
+ !context.hasEntity(washingtonStreetID) ||
+ !context.hasEntity(twelfthAvenueID) ||
+ !context.hasEntity(eleventhAvenueEndID)) {
+ return continueTo(rightClickIntersection);
+ }
+
+ var ids = context.selectedIDs();
+ var string = 'intro.lines.did_split_' + (ids.length > 1 ? 'multi' : 'single');
+ var street = _t('intro.graph.name.washington-street');
+
+ var padding = 200 * Math.pow(2, context.map().zoom() - 18);
+ var box = pad(twelfthAvenue, padding, context);
+ box.width = box.width / 2;
+ reveal(box, helpString(string, { street1: street, street2: street }),
+ { duration: 500 }
+ );
+
+ timeout(function() {
+ context.map().centerZoomEase(twelfthAvenue, 18, 500);
+
+ context.map().on('move.intro drawn.intro', function() {
+ var padding = 200 * Math.pow(2, context.map().zoom() - 18);
+ var box = pad(twelfthAvenue, padding, context);
+ box.width = box.width / 2;
+ reveal(box, helpString(string, { street1: street, street2: street }),
+ { duration: 0 }
+ );
+ });
+ }, 600); // after initial reveal and curtain cut
+
+ context.on('enter.intro', function() {
+ var ids = context.selectedIDs();
+ if (ids.length === 1 && ids[0] === _washingtonSegmentID) {
+ continueTo(multiSelect);
+ }
+ });
+
+ context.history().on('change.intro', function() {
+ if (!_washingtonSegmentID ||
+ !context.hasEntity(_washingtonSegmentID) ||
+ !context.hasEntity(washingtonStreetID) ||
+ !context.hasEntity(twelfthAvenueID) ||
+ !context.hasEntity(eleventhAvenueEndID)) {
+ return continueTo(rightClickIntersection);
+ }
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.on('enter.intro', null);
+ context.history().on('change.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function multiSelect() {
+ if (!_washingtonSegmentID ||
+ !context.hasEntity(_washingtonSegmentID) ||
+ !context.hasEntity(washingtonStreetID) ||
+ !context.hasEntity(twelfthAvenueID) ||
+ !context.hasEntity(eleventhAvenueEndID)) {
+ return continueTo(rightClickIntersection);
+ }
+
+ var ids = context.selectedIDs();
+ var hasWashington = ids.indexOf(_washingtonSegmentID) !== -1;
+ var hasTwelfth = ids.indexOf(twelfthAvenueID) !== -1;
+
+ if (hasWashington && hasTwelfth) {
+ return continueTo(multiRightClick);
+ } else if (!hasWashington && !hasTwelfth) {
+ return continueTo(didSplit);
+ }
+
+ context.map().centerZoomEase(twelfthAvenue, 18, 500);
+
+ timeout(function() {
+ var selected, other, padding, box;
+ if (hasWashington) {
+ selected = _t('intro.graph.name.washington-street');
+ other = _t('intro.graph.name.12th-avenue');
+ padding = 60 * Math.pow(2, context.map().zoom() - 18);
+ box = pad(twelfthAvenueEnd, padding, context);
+ box.width *= 3;
+ } else {
+ selected = _t('intro.graph.name.12th-avenue');
+ other = _t('intro.graph.name.washington-street');
+ padding = 200 * Math.pow(2, context.map().zoom() - 18);
+ box = pad(twelfthAvenue, padding, context);
+ box.width /= 2;
+ }
+
+ reveal(box,
+ helpString('intro.lines.multi_select',
+ { selected: selected, other1: other }) + ' ' +
+ helpString('intro.lines.add_to_selection_' + (context.lastPointerType() === 'mouse' ? 'click' : 'touch'),
+ { selected: selected, other2: other })
+ );
+
+ context.map().on('move.intro drawn.intro', function() {
+ if (hasWashington) {
+ selected = _t('intro.graph.name.washington-street');
+ other = _t('intro.graph.name.12th-avenue');
+ padding = 60 * Math.pow(2, context.map().zoom() - 18);
+ box = pad(twelfthAvenueEnd, padding, context);
+ box.width *= 3;
+ } else {
+ selected = _t('intro.graph.name.12th-avenue');
+ other = _t('intro.graph.name.washington-street');
+ padding = 200 * Math.pow(2, context.map().zoom() - 18);
+ box = pad(twelfthAvenue, padding, context);
+ box.width /= 2;
+ }
+
+ reveal(box,
+ helpString('intro.lines.multi_select',
+ { selected: selected, other1: other }) + ' ' +
+ helpString('intro.lines.add_to_selection_' + (context.lastPointerType() === 'mouse' ? 'click' : 'touch'),
+ { selected: selected, other2: other }),
+ { duration: 0 }
+ );
+ });
+
+ context.on('enter.intro', function() {
+ continueTo(multiSelect);
+ });
+
+ context.history().on('change.intro', function() {
+ if (!_washingtonSegmentID ||
+ !context.hasEntity(_washingtonSegmentID) ||
+ !context.hasEntity(washingtonStreetID) ||
+ !context.hasEntity(twelfthAvenueID) ||
+ !context.hasEntity(eleventhAvenueEndID)) {
+ return continueTo(rightClickIntersection);
+ }
+ });
+ }, 600);
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.on('enter.intro', null);
+ context.history().on('change.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function multiRightClick() {
+ if (!_washingtonSegmentID ||
+ !context.hasEntity(_washingtonSegmentID) ||
+ !context.hasEntity(washingtonStreetID) ||
+ !context.hasEntity(twelfthAvenueID) ||
+ !context.hasEntity(eleventhAvenueEndID)) {
+ return continueTo(rightClickIntersection);
+ }
+
+ var padding = 200 * Math.pow(2, context.map().zoom() - 18);
+ var box = pad(twelfthAvenue, padding, context);
+
+ var rightClickString = helpString('intro.lines.multi_select_success') +
+ helpString('intro.lines.multi_' + (context.lastPointerType() === 'mouse' ? 'rightclick' : 'edit_menu_touch'));
+ reveal(box, rightClickString);
+
+ context.map().on('move.intro drawn.intro', function() {
+ var padding = 200 * Math.pow(2, context.map().zoom() - 18);
+ var box = pad(twelfthAvenue, padding, context);
+ reveal(box, rightClickString, { duration: 0 });
+ });
+
+ context.ui().editMenu().on('toggled.intro', function(open) {
+ if (!open) return;
+
+ timeout(function() {
+ var ids = context.selectedIDs();
+ if (ids.length === 2 &&
+ ids.indexOf(twelfthAvenueID) !== -1 &&
+ ids.indexOf(_washingtonSegmentID) !== -1) {
+ var node = selectMenuItem(context, 'delete').node();
+ if (!node) return;
+ continueTo(multiDelete);
+ } else if (ids.length === 1 &&
+ ids.indexOf(_washingtonSegmentID) !== -1) {
+ return continueTo(multiSelect);
+ } else {
+ return continueTo(didSplit);
+ }
+ }, 300); // after edit menu visible
+ });
+
+ context.history().on('change.intro', function() {
+ if (!_washingtonSegmentID ||
+ !context.hasEntity(_washingtonSegmentID) ||
+ !context.hasEntity(washingtonStreetID) ||
+ !context.hasEntity(twelfthAvenueID) ||
+ !context.hasEntity(eleventhAvenueEndID)) {
+ return continueTo(rightClickIntersection);
+ }
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.ui().editMenu().on('toggled.intro', null);
+ context.history().on('change.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function multiDelete() {
+ if (!_washingtonSegmentID ||
+ !context.hasEntity(_washingtonSegmentID) ||
+ !context.hasEntity(washingtonStreetID) ||
+ !context.hasEntity(twelfthAvenueID) ||
+ !context.hasEntity(eleventhAvenueEndID)) {
+ return continueTo(rightClickIntersection);
+ }
+
+ var node = selectMenuItem(context, 'delete').node();
+ if (!node) return continueTo(multiRightClick);
+
+ reveal('.edit-menu',
+ helpString('intro.lines.multi_delete'),
+ { padding: 50 }
+ );
+
+ context.map().on('move.intro drawn.intro', function() {
+ reveal('.edit-menu',
+ helpString('intro.lines.multi_delete'),
+ { duration: 0, padding: 50 }
+ );
+ });
+
+ context.on('exit.intro', function() {
+ if (context.hasEntity(_washingtonSegmentID) || context.hasEntity(twelfthAvenueID)) {
+ return continueTo(multiSelect); // left select mode but roads still exist
+ }
+ });
+
+ context.history().on('change.intro', function() {
+ if (context.hasEntity(_washingtonSegmentID) || context.hasEntity(twelfthAvenueID)) {
+ continueTo(retryDelete); // changed something but roads still exist
+ } else {
+ continueTo(play);
+ }
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.on('exit.intro', null);
+ context.history().on('change.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function retryDelete() {
+ context.enter(modeBrowse(context));
+
+ var padding = 200 * Math.pow(2, context.map().zoom() - 18);
+ var box = pad(twelfthAvenue, padding, context);
+ reveal(box, helpString('intro.lines.retry_delete'), {
+ buttonText: _t('intro.ok'),
+ buttonCallback: function() { continueTo(multiSelect); }
+ });
+
+ function continueTo(nextStep) {
+ nextStep();
+ }
+ }
+
+
+ function play() {
+ dispatch$1.call('done');
+ reveal('.ideditor',
+ helpString('intro.lines.play', { next: _t('intro.buildings.title') }), {
+ tooltipBox: '.intro-nav-wrap .chapter-building',
+ buttonText: _t('intro.ok'),
+ buttonCallback: function() { reveal('.ideditor'); }
+ }
+ );
+ }
+
+
+ chapter.enter = function() {
+ addLine();
+ };
+
+
+ chapter.exit = function() {
+ timeouts.forEach(window.clearTimeout);
+ select(window).on('pointerdown.intro mousedown.intro', null, true);
+ context.on('enter.intro exit.intro', null);
+ context.map().on('move.intro drawn.intro', null);
+ context.history().on('change.intro', null);
+ context.container().select('.inspector-wrap').on('wheel.intro', null);
+ context.container().select('.preset-list-button').on('click.intro', null);
+ };
+
+
+ chapter.restart = function() {
+ chapter.exit();
+ chapter.enter();
+ };
+
+
+ return utilRebind(chapter, dispatch$1, 'on');
+ }
+
+ function uiIntroBuilding(context, reveal) {
+ var dispatch$1 = dispatch('done');
+ var house = [-85.62815, 41.95638];
+ var tank = [-85.62732, 41.95347];
+ var buildingCatetory = _mainPresetIndex.item('category-building');
+ var housePreset = _mainPresetIndex.item('building/house');
+ var tankPreset = _mainPresetIndex.item('man_made/storage_tank');
+ var timeouts = [];
+ var _houseID = null;
+ var _tankID = null;
+
+
+ var chapter = {
+ title: 'intro.buildings.title'
+ };
+
+
+ function timeout(f, t) {
+ timeouts.push(window.setTimeout(f, t));
+ }
+
+
+ function eventCancel() {
+ event.stopPropagation();
+ event.preventDefault();
+ }
+
+
+ function revealHouse(center, text, options) {
+ var padding = 160 * Math.pow(2, context.map().zoom() - 20);
+ var box = pad(center, padding, context);
+ reveal(box, text, options);
+ }
+
+
+ function revealTank(center, text, options) {
+ var padding = 190 * Math.pow(2, context.map().zoom() - 19.5);
+ var box = pad(center, padding, context);
+ reveal(box, text, options);
+ }
+
+
+ function addHouse() {
+ context.enter(modeBrowse(context));
+ context.history().reset('initial');
+ _houseID = null;
+
+ var msec = transitionTime(house, context.map().center());
+ if (msec) { reveal(null, null, { duration: 0 }); }
+ context.map().centerZoomEase(house, 19, msec);
+
+ timeout(function() {
+ var tooltip = reveal('button.add-area',
+ helpString('intro.buildings.add_building'));
+
+ tooltip.selectAll('.popover-inner')
+ .insert('svg', 'span')
+ .attr('class', 'tooltip-illustration')
+ .append('use')
+ .attr('xlink:href', '#iD-graphic-buildings');
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id !== 'add-area') return;
+ continueTo(startHouse);
+ });
+ }, msec + 100);
+
+ function continueTo(nextStep) {
+ context.on('enter.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function startHouse() {
+ if (context.mode().id !== 'add-area') {
+ return continueTo(addHouse);
+ }
+
+ _houseID = null;
+ context.map().zoomEase(20, 500);
+
+ timeout(function() {
+ var startString = helpString('intro.buildings.start_building') +
+ helpString('intro.buildings.building_corner_' + (context.lastPointerType() === 'mouse' ? 'click' : 'tap'));
+ revealHouse(house, startString);
+
+ context.map().on('move.intro drawn.intro', function() {
+ revealHouse(house, startString, { duration: 0 });
+ });
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id !== 'draw-area') return chapter.restart();
+ continueTo(continueHouse);
+ });
+
+ }, 550); // after easing
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.on('enter.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function continueHouse() {
+ if (context.mode().id !== 'draw-area') {
+ return continueTo(addHouse);
+ }
+
+ _houseID = null;
+
+ var continueString = helpString('intro.buildings.continue_building') + '{br}' +
+ helpString('intro.areas.finish_area_' + (context.lastPointerType() === 'mouse' ? 'click' : 'tap')) +
+ helpString('intro.buildings.finish_building');
+
+ revealHouse(house, continueString);
+
+ context.map().on('move.intro drawn.intro', function() {
+ revealHouse(house, continueString, { duration: 0 });
+ });
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id === 'draw-area') {
+ return;
+ } else if (mode.id === 'select') {
+ var graph = context.graph();
+ var way = context.entity(context.selectedIDs()[0]);
+ var nodes = graph.childNodes(way);
+ var points = utilArrayUniq(nodes)
+ .map(function(n) { return context.projection(n.loc); });
+
+ if (isMostlySquare(points)) {
+ _houseID = way.id;
+ return continueTo(chooseCategoryBuilding);
+ } else {
+ return continueTo(retryHouse);
+ }
+
+ } else {
+ return chapter.restart();
+ }
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.on('enter.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function retryHouse() {
+ var onClick = function() { continueTo(addHouse); };
+
+ revealHouse(house, helpString('intro.buildings.retry_building'),
+ { buttonText: _t('intro.ok'), buttonCallback: onClick }
+ );
+
+ context.map().on('move.intro drawn.intro', function() {
+ revealHouse(house, helpString('intro.buildings.retry_building'),
+ { duration: 0, buttonText: _t('intro.ok'), buttonCallback: onClick }
+ );
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function chooseCategoryBuilding() {
+ if (!_houseID || !context.hasEntity(_houseID)) {
+ return addHouse();
+ }
+ var ids = context.selectedIDs();
+ if (context.mode().id !== 'select' || !ids.length || ids[0] !== _houseID) {
+ context.enter(modeSelect(context, [_houseID]));
+ }
+
+ // disallow scrolling
+ context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);
+
+ timeout(function() {
+ // reset pane, in case user somehow happened to change it..
+ context.container().select('.inspector-wrap .panewrap').style('right', '-100%');
+
+ var button = context.container().select('.preset-category-building .preset-list-button');
+
+ reveal(button.node(),
+ helpString('intro.buildings.choose_category_building', { category: buildingCatetory.name() })
+ );
+
+ button.on('click.intro', function() {
+ button.on('click.intro', null);
+ continueTo(choosePresetHouse);
+ });
+
+ }, 400); // after preset list pane visible..
+
+
+ context.on('enter.intro', function(mode) {
+ if (!_houseID || !context.hasEntity(_houseID)) {
+ return continueTo(addHouse);
+ }
+ var ids = context.selectedIDs();
+ if (mode.id !== 'select' || !ids.length || ids[0] !== _houseID) {
+ return continueTo(chooseCategoryBuilding);
+ }
+ });
+
+ function continueTo(nextStep) {
+ context.container().select('.inspector-wrap').on('wheel.intro', null);
+ context.container().select('.preset-list-button').on('click.intro', null);
+ context.on('enter.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function choosePresetHouse() {
+ if (!_houseID || !context.hasEntity(_houseID)) {
+ return addHouse();
+ }
+ var ids = context.selectedIDs();
+ if (context.mode().id !== 'select' || !ids.length || ids[0] !== _houseID) {
+ context.enter(modeSelect(context, [_houseID]));
+ }
+
+ // disallow scrolling
+ context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);
+
+ timeout(function() {
+ // reset pane, in case user somehow happened to change it..
+ context.container().select('.inspector-wrap .panewrap').style('right', '-100%');
+
+ var button = context.container().select('.preset-building-house .preset-list-button');
+
+ reveal(button.node(),
+ helpString('intro.buildings.choose_preset_house', { preset: housePreset.name() }),
+ { duration: 300 }
+ );
+
+ button.on('click.intro', function() {
+ button.on('click.intro', null);
+ continueTo(closeEditorHouse);
+ });
+
+ }, 400); // after preset list pane visible..
+
+ context.on('enter.intro', function(mode) {
+ if (!_houseID || !context.hasEntity(_houseID)) {
+ return continueTo(addHouse);
+ }
+ var ids = context.selectedIDs();
+ if (mode.id !== 'select' || !ids.length || ids[0] !== _houseID) {
+ return continueTo(chooseCategoryBuilding);
+ }
+ });
+
+ function continueTo(nextStep) {
+ context.container().select('.inspector-wrap').on('wheel.intro', null);
+ context.container().select('.preset-list-button').on('click.intro', null);
+ context.on('enter.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function closeEditorHouse() {
+ if (!_houseID || !context.hasEntity(_houseID)) {
+ return addHouse();
+ }
+ var ids = context.selectedIDs();
+ if (context.mode().id !== 'select' || !ids.length || ids[0] !== _houseID) {
+ context.enter(modeSelect(context, [_houseID]));
+ }
+
+ context.history().checkpoint('hasHouse');
+
+ context.on('exit.intro', function() {
+ continueTo(rightClickHouse);
+ });
+
+ timeout(function() {
+ reveal('.entity-editor-pane',
+ helpString('intro.buildings.close', { button: icon('#iD-icon-close', 'pre-text') })
+ );
+ }, 500);
+
+ function continueTo(nextStep) {
+ context.on('exit.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function rightClickHouse() {
+ if (!_houseID) return chapter.restart();
+
+ context.enter(modeBrowse(context));
+ context.history().reset('hasHouse');
+ var zoom = context.map().zoom();
+ if (zoom < 20) {
+ zoom = 20;
+ }
+ context.map().centerZoomEase(house, zoom, 500);
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id !== 'select') return;
+ var ids = context.selectedIDs();
+ if (ids.length !== 1 || ids[0] !== _houseID) return;
+
+ timeout(function() {
+ var node = selectMenuItem(context, 'orthogonalize').node();
+ if (!node) return;
+ continueTo(clickSquare);
+ }, 50); // after menu visible
+ });
+
+ context.map().on('move.intro drawn.intro', function() {
+ var rightclickString = helpString('intro.buildings.' + (context.lastPointerType() === 'mouse' ? 'rightclick_building' : 'edit_menu_building_touch'));
+ revealHouse(house, rightclickString, { duration: 0 });
+ });
+
+ context.history().on('change.intro', function() {
+ continueTo(rightClickHouse);
+ });
+
+ function continueTo(nextStep) {
+ context.on('enter.intro', null);
+ context.map().on('move.intro drawn.intro', null);
+ context.history().on('change.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function clickSquare() {
+ if (!_houseID) return chapter.restart();
+ var entity = context.hasEntity(_houseID);
+ if (!entity) return continueTo(rightClickHouse);
+
+ var node = selectMenuItem(context, 'orthogonalize').node();
+ if (!node) { return continueTo(rightClickHouse); }
+
+ var wasChanged = false;
+
+ reveal('.edit-menu',
+ helpString('intro.buildings.square_building'),
+ { padding: 50 }
+ );
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id === 'browse') {
+ continueTo(rightClickHouse);
+ } else if (mode.id === 'move' || mode.id === 'rotate') {
+ continueTo(retryClickSquare);
+ }
+ });
+
+ context.map().on('move.intro', function() {
+ var node = selectMenuItem(context, 'orthogonalize').node();
+ if (!wasChanged && !node) { return continueTo(rightClickHouse); }
+
+ reveal('.edit-menu',
+ helpString('intro.buildings.square_building'),
+ { duration: 0, padding: 50 }
+ );
+ });
+
+ context.history().on('change.intro', function() {
+ wasChanged = true;
+ context.history().on('change.intro', null);
+
+ // Something changed. Wait for transition to complete and check undo annotation.
+ timeout(function() {
+ if (context.history().undoAnnotation() === _t('operations.orthogonalize.annotation.feature.single')) {
+ continueTo(doneSquare);
+ } else {
+ continueTo(retryClickSquare);
+ }
+ }, 500); // after transitioned actions
+ });
+
+ function continueTo(nextStep) {
+ context.on('enter.intro', null);
+ context.map().on('move.intro', null);
+ context.history().on('change.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function retryClickSquare() {
+ context.enter(modeBrowse(context));
+
+ revealHouse(house, helpString('intro.buildings.retry_square'), {
+ buttonText: _t('intro.ok'),
+ buttonCallback: function() { continueTo(rightClickHouse); }
+ });
+
+ function continueTo(nextStep) {
+ nextStep();
+ }
+ }
+
+
+ function doneSquare() {
+ context.history().checkpoint('doneSquare');
+
+ revealHouse(house, helpString('intro.buildings.done_square'), {
+ buttonText: _t('intro.ok'),
+ buttonCallback: function() { continueTo(addTank); }
+ });
+
+ function continueTo(nextStep) {
+ nextStep();
+ }
+ }
+
+
+ function addTank() {
+ context.enter(modeBrowse(context));
+ context.history().reset('doneSquare');
+ _tankID = null;
+
+ var msec = transitionTime(tank, context.map().center());
+ if (msec) { reveal(null, null, { duration: 0 }); }
+ context.map().centerZoomEase(tank, 19.5, msec);
+
+ timeout(function() {
+ reveal('button.add-area',
+ helpString('intro.buildings.add_tank')
+ );
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id !== 'add-area') return;
+ continueTo(startTank);
+ });
+ }, msec + 100);
+
+ function continueTo(nextStep) {
+ context.on('enter.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function startTank() {
+ if (context.mode().id !== 'add-area') {
+ return continueTo(addTank);
+ }
+
+ _tankID = null;
+
+ timeout(function() {
+ var startString = helpString('intro.buildings.start_tank') +
+ helpString('intro.buildings.tank_edge_' + (context.lastPointerType() === 'mouse' ? 'click' : 'tap'));
+ revealTank(tank, startString);
+
+ context.map().on('move.intro drawn.intro', function() {
+ revealTank(tank, startString, { duration: 0 });
+ });
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id !== 'draw-area') return chapter.restart();
+ continueTo(continueTank);
+ });
+
+ }, 550); // after easing
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.on('enter.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function continueTank() {
+ if (context.mode().id !== 'draw-area') {
+ return continueTo(addTank);
+ }
+
+ _tankID = null;
+
+ var continueString = helpString('intro.buildings.continue_tank') + '{br}' +
+ helpString('intro.areas.finish_area_' + (context.lastPointerType() === 'mouse' ? 'click' : 'tap')) +
+ helpString('intro.buildings.finish_tank');
+
+ revealTank(tank, continueString);
+
+ context.map().on('move.intro drawn.intro', function() {
+ revealTank(tank, continueString, { duration: 0 });
+ });
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id === 'draw-area') {
+ return;
+ } else if (mode.id === 'select') {
+ _tankID = context.selectedIDs()[0];
+ return continueTo(searchPresetTank);
+ } else {
+ return continueTo(addTank);
+ }
+ });
+
+ function continueTo(nextStep) {
+ context.map().on('move.intro drawn.intro', null);
+ context.on('enter.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function searchPresetTank() {
+ if (!_tankID || !context.hasEntity(_tankID)) {
+ return addTank();
+ }
+ var ids = context.selectedIDs();
+ if (context.mode().id !== 'select' || !ids.length || ids[0] !== _tankID) {
+ context.enter(modeSelect(context, [_tankID]));
+ }
+
+ // disallow scrolling
+ context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);
+
+ timeout(function() {
+ // reset pane, in case user somehow happened to change it..
+ context.container().select('.inspector-wrap .panewrap').style('right', '-100%');
+
+ context.container().select('.preset-search-input')
+ .on('keydown.intro', null)
+ .on('keyup.intro', checkPresetSearch);
+
+ reveal('.preset-search-input',
+ helpString('intro.buildings.search_tank', { preset: tankPreset.name() })
+ );
+ }, 400); // after preset list pane visible..
+
+ context.on('enter.intro', function(mode) {
+ if (!_tankID || !context.hasEntity(_tankID)) {
+ return continueTo(addTank);
+ }
+
+ var ids = context.selectedIDs();
+ if (mode.id !== 'select' || !ids.length || ids[0] !== _tankID) {
+ // keep the user's area selected..
+ context.enter(modeSelect(context, [_tankID]));
+
+ // reset pane, in case user somehow happened to change it..
+ context.container().select('.inspector-wrap .panewrap').style('right', '-100%');
+ // disallow scrolling
+ context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);
+
+ context.container().select('.preset-search-input')
+ .on('keydown.intro', null)
+ .on('keyup.intro', checkPresetSearch);
+
+ reveal('.preset-search-input',
+ helpString('intro.buildings.search_tank', { preset: tankPreset.name() })
+ );
+
+ context.history().on('change.intro', null);
+ }
+ });
+
+ function checkPresetSearch() {
+ var first = context.container().select('.preset-list-item:first-child');
+
+ if (first.classed('preset-man_made-storage_tank')) {
+ reveal(first.select('.preset-list-button').node(),
+ helpString('intro.buildings.choose_tank', { preset: tankPreset.name() }),
+ { duration: 300 }
+ );
+
+ context.container().select('.preset-search-input')
+ .on('keydown.intro', eventCancel, true)
+ .on('keyup.intro', null);
+
+ context.history().on('change.intro', function() {
+ continueTo(closeEditorTank);
+ });
+ }
+ }
+
+ function continueTo(nextStep) {
+ context.container().select('.inspector-wrap').on('wheel.intro', null);
+ context.on('enter.intro', null);
+ context.history().on('change.intro', null);
+ context.container().select('.preset-search-input').on('keydown.intro keyup.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function closeEditorTank() {
+ if (!_tankID || !context.hasEntity(_tankID)) {
+ return addTank();
+ }
+ var ids = context.selectedIDs();
+ if (context.mode().id !== 'select' || !ids.length || ids[0] !== _tankID) {
+ context.enter(modeSelect(context, [_tankID]));
+ }
+
+ context.history().checkpoint('hasTank');
+
+ context.on('exit.intro', function() {
+ continueTo(rightClickTank);
+ });
+
+ timeout(function() {
+ reveal('.entity-editor-pane',
+ helpString('intro.buildings.close', { button: icon('#iD-icon-close', 'pre-text') })
+ );
+ }, 500);
+
+ function continueTo(nextStep) {
+ context.on('exit.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function rightClickTank() {
+ if (!_tankID) return continueTo(addTank);
+
+ context.enter(modeBrowse(context));
+ context.history().reset('hasTank');
+ context.map().centerEase(tank, 500);
+
+ timeout(function() {
+ context.on('enter.intro', function(mode) {
+ if (mode.id !== 'select') return;
+ var ids = context.selectedIDs();
+ if (ids.length !== 1 || ids[0] !== _tankID) return;
+
+ timeout(function() {
+ var node = selectMenuItem(context, 'circularize').node();
+ if (!node) return;
+ continueTo(clickCircle);
+ }, 50); // after menu visible
+ });
+
+ var rightclickString = helpString('intro.buildings.' + (context.lastPointerType() === 'mouse' ? 'rightclick_tank' : 'edit_menu_tank_touch'));
+
+ revealTank(tank, rightclickString);
+
+ context.map().on('move.intro drawn.intro', function() {
+ revealTank(tank, rightclickString, { duration: 0 });
+ });
+
+ context.history().on('change.intro', function() {
+ continueTo(rightClickTank);
+ });
+
+ }, 600);
+
+ function continueTo(nextStep) {
+ context.on('enter.intro', null);
+ context.map().on('move.intro drawn.intro', null);
+ context.history().on('change.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function clickCircle() {
+ if (!_tankID) return chapter.restart();
+ var entity = context.hasEntity(_tankID);
+ if (!entity) return continueTo(rightClickTank);
+
+ var node = selectMenuItem(context, 'circularize').node();
+ if (!node) { return continueTo(rightClickTank); }
+
+ var wasChanged = false;
+
+ reveal('.edit-menu',
+ helpString('intro.buildings.circle_tank'),
+ { padding: 50 }
+ );
+
+ context.on('enter.intro', function(mode) {
+ if (mode.id === 'browse') {
+ continueTo(rightClickTank);
+ } else if (mode.id === 'move' || mode.id === 'rotate') {
+ continueTo(retryClickCircle);
+ }
+ });
+
+ context.map().on('move.intro', function() {
+ var node = selectMenuItem(context, 'circularize').node();
+ if (!wasChanged && !node) { return continueTo(rightClickTank); }
+
+ reveal('.edit-menu',
+ helpString('intro.buildings.circle_tank'),
+ { duration: 0, padding: 50 }
+ );
+ });
+
+ context.history().on('change.intro', function() {
+ wasChanged = true;
+ context.history().on('change.intro', null);
+
+ // Something changed. Wait for transition to complete and check undo annotation.
+ timeout(function() {
+ if (context.history().undoAnnotation() === _t('operations.circularize.annotation.single')) {
+ continueTo(play);
+ } else {
+ continueTo(retryClickCircle);
+ }
+ }, 500); // after transitioned actions
+ });
+
+ function continueTo(nextStep) {
+ context.on('enter.intro', null);
+ context.map().on('move.intro', null);
+ context.history().on('change.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function retryClickCircle() {
+ context.enter(modeBrowse(context));
+
+ revealTank(tank, helpString('intro.buildings.retry_circle'), {
+ buttonText: _t('intro.ok'),
+ buttonCallback: function() { continueTo(rightClickTank); }
+ });
+
+ function continueTo(nextStep) {
+ nextStep();
+ }
+ }
+
+
+ function play() {
+ dispatch$1.call('done');
+ reveal('#id-container',
+ _t('intro.buildings.play', { next: _t('intro.rapid.title') }), {
+ tooltipBox: '.intro-nav-wrap .chapter-rapid',
+ buttonText: _t('intro.ok'),
+ buttonCallback: function() { reveal('.ideditor'); }
+ }
+ );
+ }
+
+
+ chapter.enter = function() {
+ addHouse();
+ };
+
+
+ chapter.exit = function() {
+ timeouts.forEach(window.clearTimeout);
+ context.on('enter.intro exit.intro', null);
+ context.map().on('move.intro drawn.intro', null);
+ context.history().on('change.intro', null);
+ context.container().select('.inspector-wrap').on('wheel.intro', null);
+ context.container().select('.preset-search-input').on('keydown.intro keyup.intro', null);
+ context.container().select('.more-fields .combobox-input').on('click.intro', null);
+ };
+
+
+ chapter.restart = function() {
+ chapter.exit();
+ chapter.enter();
+ };
+
+
+ return utilRebind(chapter, dispatch$1, 'on');
+ }
+
+ function uiIntroStartEditing(context, reveal) {
+ var dispatch$1 = dispatch('done', 'startEditing');
+ var modalSelection = select(null);
+
+
+ var chapter = {
+ title: 'intro.startediting.title'
+ };
+
+ function showHelp() {
+ reveal('.map-control.help-control',
+ helpString('intro.startediting.help'), {
+ buttonText: _t('intro.ok'),
+ buttonCallback: function() { shortcuts(); }
+ }
+ );
+ }
+
+ function shortcuts() {
+ reveal('.map-control.help-control',
+ helpString('intro.startediting.shortcuts'), {
+ buttonText: _t('intro.ok'),
+ buttonCallback: function() { showSave(); }
+ }
+ );
+ }
+
+ function showSave() {
+ context.container().selectAll('.shaded').remove(); // in case user opened keyboard shortcuts
+ reveal('.top-toolbar button.save',
+ helpString('intro.startediting.save'), {
+ buttonText: _t('intro.ok'),
+ buttonCallback: function() { showStart(); }
+ }
+ );
+ }
+
+ function showStart() {
+ context.container().selectAll('.shaded').remove(); // in case user opened keyboard shortcuts
+
+ modalSelection = uiModal(context.container());
+
+ modalSelection.select('.modal')
+ .attr('class', 'modal-splash modal');
+
+ modalSelection.selectAll('.close').remove();
+
+ var startbutton = modalSelection.select('.content')
+ .attr('class', 'fillL')
+ .append('button')
+ .attr('class', 'modal-section huge-modal-button')
+ .on('click', function() {
+ modalSelection.remove();
+ });
+
+ startbutton
+ .append('svg')
+ .attr('class', 'illustration')
+ .append('use')
+ .attr('xlink:href', '#iD-logo-walkthrough');
+
+ startbutton
+ .append('h2')
+ .text(_t('intro.startediting.start'));
+
+ dispatch$1.call('startEditing');
+ }
+
+
+ chapter.enter = function() {
+ showHelp();
+ };
+
+
+ chapter.exit = function() {
+ modalSelection.remove();
+ context.container().selectAll('.shaded').remove(); // in case user opened keyboard shortcuts
+ };
+
+
+ return utilRebind(chapter, dispatch$1, 'on');
+ }
+
+ function uiIntroRapid(context, reveal) {
+ const dispatch$1 = dispatch('done');
+ let chapter = { title: 'intro.rapid.title' };
+ let timeouts = [];
+
+ const tulipLaneStart = [-85.6297512, 41.9561476];
+ const tulipLaneMid = [-85.6281089, 41.9561288];
+ const tulipLaneEnd = [-85.6272670, 41.9558780];
+
+
+ function timeout(f, t) {
+ timeouts.push(window.setTimeout(f, t));
+ }
+
+
+ function tulipLaneEndBoundingBox(){
+ const padding = 70 * Math.pow(2, context.map().zoom() - 18);
+ let box = pad(tulipLaneEnd, padding, context);
+ box.height = box.height + 65;
+ box.width = box.width + 65;
+ return box;
+ }
+
+ function tulipLaneBoundingBox(){
+ const padding = 70 * Math.pow(2, context.map().zoom() - 18);
+ let box = pad(tulipLaneStart, padding, context);
+ box.height = box.height + 65;
+ box.width = box.width + 600;
+ return box;
+ }
+
+
+ function eventCancel() {
+ event.stopPropagation();
+ event.preventDefault();
+ }
+
+
+ function welcome() {
+ context.layers().layer('ai-features').enabled(true);
+ context.enter(modeBrowse(context));
+ context.history().reset('initial');
+ reveal('.intro-nav-wrap .chapter-rapid',
+ _t('intro.rapid.start', { rapid: icon('#iD-logo-rapid', 'pre-text') }),
+ { buttonText: _t('intro.ok'), buttonCallback: showHideRoads }
+ );
+ }
+
+
+ function showHideRoads() {
+ const msec = transitionTime(tulipLaneMid, context.map().center());
+ if (msec) { reveal(null, null, { duration: 0 }); }
+ context.map().centerZoomEase(tulipLaneMid, 18.5, msec);
+
+ reveal(
+ 'button.rapid-features',
+ _t('intro.rapid.ai_roads', { rapid: icon('#iD-logo-rapid', 'pre-text') }),
+ { buttonText: _t('intro.ok'), buttonCallback: selectRoad }
+ );
+ }
+
+
+ function selectRoad() {
+ context.layers().layer('ai-features').enabled(true);
+
+ // disallow scrolling
+ select('.inspector-wrap').on('wheel.intro', eventCancel);
+ reveal(tulipLaneBoundingBox(), _t('intro.rapid.select_road'));
+
+ timeout(() => {
+ let fbRoad = select('.data-layer.ai-features');
+ fbRoad.on('click.intro', addRoad);
+ }, 250);
+ }
+
+
+ function addRoad() {
+ timeout(() => {
+ reveal('.rapid-inspector-choice-accept', _t('intro.rapid.add_road'));
+ let button = select('.choice-button-accept');
+ button.on('click.intro', roadAdded);
+ }, 250);
+ }
+
+
+ function roadAdded() {
+ if (context.mode().id !== 'select') return chapter.restart();
+
+ timeout(() => {
+ reveal(tulipLaneBoundingBox(),
+ _t('intro.rapid.add_road_not_saved_yet', { rapid: icon('#iD-logo-rapid', 'pre-text') }),
+ { buttonText: _t('intro.ok'), buttonCallback: showLint }
+ );
+ }, 250);
+ }
+
+
+ function showLint() {
+ if (context.mode().id !== 'select') return chapter.restart();
+
+ let button = select('li.issue-list-item.actionable > button');
+ button.on('click.intro', () => continueTo(fixLint));
+
+ timeout(() => {
+ reveal('div.issue.severity-warning',
+ _t('intro.rapid.new_lints'),
+ { buttonText: _t('intro.ok'), buttonCallback: fixLint }
+ );
+ }, 250);
+
+ function continueTo(nextStep) {
+ button.on('click.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function fixLint() {
+ if (context.mode().id !== 'select') return chapter.restart();
+
+ let button = select('li.issue-fix-item.actionable');
+ button.on('click.intro', () => continueTo(showFixedRoad));
+
+ timeout(() => {
+ reveal('li.issue-fix-item.actionable',
+ _t('intro.rapid.fix_lint', {connect: icon('#iD-icon-crossing', 'pre-text') })
+ );
+ }, 250);
+
+ function continueTo(nextStep) {
+ button.on('click.intro', null);
+ nextStep();
+ }
+ }
+
+
+ function showFixedRoad() {
+ if (context.mode().id !== 'select') return chapter.restart();
+
+ timeout(() => {
+ reveal(
+ tulipLaneEndBoundingBox(),
+ _t('intro.rapid.fixed_lint'),
+ { buttonText: _t('intro.ok'), buttonCallback: undoFixLint }
+ );
+ }, 250);
+ }
+
+
+ function undoFixLint() {
+ if (context.mode().id !== 'select') return chapter.restart();
+
+ timeout(() => {
+ let button = select('.top-toolbar button.undo-button');
+ let iconName = '#iD-icon-undo';
+ reveal('.top-toolbar button.undo-button',
+ _t('intro.rapid.undo_fix_lint', { button: icon(iconName, 'pre-text') })
+ );
+ button.on('click.intro', undoRoadAdd);
+ }, 250);
+ }
+
+
+ function undoRoadAdd() {
+ if (context.mode().id !== 'select') return chapter.restart();
+
+ timeout(() => {
+ let button = select('.top-toolbar button.undo-button');
+ const iconName = '#iD-icon-undo';
+ reveal('.top-toolbar button.undo-button',
+ _t('intro.rapid.undo_road_add', { button: icon(iconName, 'pre-text') })
+ );
+ button.on('click.intro', afterUndoRoadAdd);
+ }, 250);
+ }
+
+
+ function afterUndoRoadAdd() {
+ timeout(() => {
+ reveal(
+ tulipLaneBoundingBox(),
+ _t('intro.rapid.undo_road_add_aftermath'),
+ { buttonText: _t('intro.ok'), buttonCallback: selectRoadAgain }
+ );
+ }, 250);
+ }
+
+
+ function selectRoadAgain() {
+ timeout(() => {
+ reveal(tulipLaneBoundingBox(), _t('intro.rapid.select_road_again'));
+ let fbRoad = select('.data-layer.ai-features');
+ fbRoad.on('click.intro', ignoreRoad);
+ }, 250);
+ }
+
+
+ function ignoreRoad() {
+ timeout(() => {
+ reveal('.rapid-inspector-choice-ignore', _t('intro.rapid.ignore_road'));
+ let button = select('.choice-button-ignore');
+ button.on('click.intro', showHelp);
+ }, 250);
+ }
+
+
+ function showHelp() {
+ reveal(
+ '.map-control.help-control',
+ _t('intro.rapid.help', {
+ rapid: icon('#iD-logo-rapid', 'pre-text'),
+ button: icon('#iD-icon-help', 'pre-text'),
+ key: _t('help.key')
+ }),
+ { buttonText: _t('intro.ok'), buttonCallback: allDone }
+ );
+ }
+
+
+ function allDone() {
+ if (context.mode().id !== 'browse') return chapter.restart();
+
+ dispatch$1.call('done');
+ reveal('.intro-nav-wrap .chapter-startEditing',
+ marked_1(_t('intro.rapid.done', { next: _t('intro.startediting.title') }))
+ );
+ }
+
+
+ chapter.enter = () => {
+ welcome();
+ };
+
+
+ chapter.exit = () => {
+ timeouts.forEach(window.clearTimeout);
+ select(window).on('mousedown.intro-rapid', null, true);
+ context.on('enter.intro-rapid exit.intro-rapid', null);
+ context.map().on('move.intro-rapid drawn.intro-rapid', null);
+ context.history().on('change.intro-rapid', null);
+ select('.inspector-wrap').on('wheel.intro-rapid', null);
+ select('.preset-list-button').on('click.intro-rapid', null);
+ };
+
+
+ chapter.restart = () => {
+ chapter.exit();
+ chapter.enter();
+ };
+
+
+ return utilRebind(chapter, dispatch$1, 'on');
+ }
+
+ const chapterUi = {
+ welcome: uiIntroWelcome,
+ navigation: uiIntroNavigation,
+ point: uiIntroPoint,
+ area: uiIntroArea,
+ line: uiIntroLine,
+ building: uiIntroBuilding,
+ rapid: uiIntroRapid,
+ startEditing: uiIntroStartEditing
+ };
+
+ const chapterFlow = [
+ 'welcome',
+ 'navigation',
+ 'point',
+ 'area',
+ 'line',
+ 'building',
+ 'rapid',
+ 'startEditing'
+ ];
+
+
+ function uiIntro(context, skipToRapid) {
+ const INTRO_IMAGERY = 'EsriWorldImageryClarity';
+ let _introGraph = {};
+ let _rapidGraph = {};
+ let _currChapter;
+
+
+ function intro(selection) {
+ Promise.all([
+ _mainFileFetcher.get('intro_rapid_graph'),
+ _mainFileFetcher.get('intro_graph')
+ ])
+ .then(values => {
+ const rapidData = values[0];
+ const introData = values[1];
+
+ for (const id in rapidData) {
+ if (!_rapidGraph[id]) {
+ _rapidGraph[id] = osmEntity(localize(rapidData[id]));
+ }
+ }
+ for (const id in introData) {
+ if (!_introGraph[id]) {
+ _introGraph[id] = osmEntity(localize(introData[id]));
+ }
+ }
+
+ selection.call(startIntro);
+ });
+ }
+
+
+ function startIntro(selection) {
+ context.enter(modeBrowse(context));
+
+ // Save current map state
+ let osm = context.connection();
+ let history = context.history().toJSON();
+ let hash = window.location.hash;
+ let center = context.map().center();
+ let zoom = context.map().zoom();
+ let background = context.background().baseLayerSource();
+ let overlays = context.background().overlayLayerSources();
+ let opacity = context.container().selectAll('.main-map .layer-background').style('opacity');
+ let caches = osm && osm.caches();
+ let baseEntities = context.history().graph().base().entities;
+
+ // Show sidebar and disable the sidebar resizing button
+ // (this needs to be before `context.inIntro(true)`)
+ context.ui().sidebar.expand();
+ context.container().selectAll('button.sidebar-toggle').classed('disabled', true);
+
+ // Block saving
+ context.inIntro(true);
+
+ // Load semi-real data used in intro
+ if (osm) { osm.toggle(false).reset(); }
+ context.history().reset();
+ context.history().merge(Object.values(coreGraph().load(_introGraph).entities));
+ context.history().checkpoint('initial');
+
+ // Setup imagery
+ let imagery = context.background().findSource(INTRO_IMAGERY);
+ if (imagery) {
+ context.background().baseLayerSource(imagery);
+ } else {
+ context.background().bing();
+ }
+ overlays.forEach(d => context.background().toggleOverlayLayer(d));
+
+ // Setup data layers (only OSM & ai-features)
+ let layers = context.layers();
+ layers.all().forEach(item => {
+ // if the layer has the function `enabled`
+ if (typeof item.layer.enabled === 'function') {
+ item.layer.enabled(item.id === 'osm' || item.id === 'ai-features');
+ }
+ });
+
+ // Setup RapiD Walkthrough dataset and disable service
+ let rapidDatasets = context.rapidContext().datasets();
+ const rapidDatasetsCopy = JSON.parse(JSON.stringify(rapidDatasets)); // deep copy
+ Object.keys(rapidDatasets).forEach(id => rapidDatasets[id].enabled = false);
+
+ rapidDatasets.rapid_intro_graph = {
+ id: 'rapid_intro_graph',
+ beta: false,
+ added: true,
+ enabled: true,
+ conflated: false,
+ service: 'fbml',
+ color: '#da26d3',
+ label: 'RapiD Walkthrough'
+ };
+
+ if (services.fbMLRoads) {
+ services.fbMLRoads.toggle(false); // disable network
+ const entities = Object.values(coreGraph().load(_rapidGraph).entities);
+ services.fbMLRoads.merge('rapid_intro_graph', entities);
+ }
+
+ context.container().selectAll('.main-map .layer-background').style('opacity', 1);
+
+ let curtain = uiCurtain(context.container().node());
+ selection.call(curtain);
+
+ // Store that the user started the walkthrough..
+ corePreferences('walkthrough_started', 'yes');
+
+ // Restore previous walkthrough progress..
+ let storedProgress = corePreferences('walkthrough_progress') || '';
+ let progress = storedProgress.split(';').filter(Boolean);
+
+ let chapters = chapterFlow.map((chapter, i) => {
+ let s = chapterUi[chapter](context, curtain.reveal)
+ .on('done', () => {
+
+ buttons
+ .filter(d => d.title === s.title)
+ .classed('finished', true);
+
+ if (i < chapterFlow.length - 1) {
+ const next = chapterFlow[i + 1];
+ context.container().select(`button.chapter-${next}`)
+ .classed('next', true);
+ }
+
+ // Store walkthrough progress..
+ progress.push(chapter);
+ corePreferences('walkthrough_progress', utilArrayUniq(progress).join(';'));
+ });
+ return s;
+ });
+
+ chapters[chapters.length - 1].on('startEditing', () => {
+ // Store walkthrough progress..
+ progress.push('startEditing');
+ corePreferences('walkthrough_progress', utilArrayUniq(progress).join(';'));
+
+ // Store if walkthrough is completed..
+ let incomplete = utilArrayDifference(chapterFlow, progress);
+ if (!incomplete.length) {
+ corePreferences('walkthrough_completed', 'yes');
+ }
+
+ // Restore RapiD datasets and service
+ let rapidDatasets = context.rapidContext().datasets();
+ delete rapidDatasets.rapid_intro_graph;
+ Object.keys(rapidDatasetsCopy).forEach(id => rapidDatasets[id].enabled = rapidDatasetsCopy[id].enabled);
+ Object.assign(rapidDatasets, rapidDatasetsCopy);
+ if (services.fbMLRoads) {
+ services.fbMLRoads.toggle(true);
+ }
+
+ curtain.remove();
+ navwrap.remove();
+ context.container().selectAll('.main-map .layer-background').style('opacity', opacity);
+ context.container().selectAll('button.sidebar-toggle').classed('disabled', false);
+ if (osm) { osm.toggle(true).reset().caches(caches); }
+ context.history().reset().merge(Object.values(baseEntities));
+ context.background().baseLayerSource(background);
+ overlays.forEach(d => context.background().toggleOverlayLayer(d));
+ if (history) { context.history().fromJSON(history, false); }
+ context.map().centerZoom(center, zoom);
+ window.location.replace(hash);
+ context.inIntro(false);
+ });
+
+ let navwrap = selection
+ .append('div')
+ .attr('class', 'intro-nav-wrap fillD');
+
+ navwrap
+ .append('svg')
+ .attr('class', 'intro-nav-wrap-logo')
+ .append('use')
+ .attr('xlink:href', '#iD-logo-walkthrough');
+
+ let buttonwrap = navwrap
+ .append('div')
+ .attr('class', 'joined')
+ .selectAll('button.chapter');
+
+ let buttons = buttonwrap
+ .data(chapters)
+ .enter()
+ .append('button')
+ .attr('class', (d, i) => `chapter chapter-${chapterFlow[i]}`)
+ .on('click', enterChapter);
+
+ buttons
+ .append('span')
+ .text(d => _t(d.title));
+
+ buttons
+ .append('span')
+ .attr('class', 'status')
+ .call(svgIcon((_mainLocalizer.textDirection() === 'rtl' ? '#iD-icon-backward' : '#iD-icon-forward'), 'inline'));
+
+ enterChapter(chapters[skipToRapid ? 6 : 0]);
+
+ function enterChapter(newChapter) {
+ if (_currChapter) { _currChapter.exit(); }
+ context.enter(modeBrowse(context));
+
+ _currChapter = newChapter;
+ _currChapter.enter();
+
+ buttons
+ .classed('next', false)
+ .classed('active', d => d.title === _currChapter.title);
+ }
+ }
+
+
+ return intro;
+ }
+
+ function uiIssuesInfo(context) {
+
+ var warningsItem = {
+ id: 'warnings',
+ count: 0,
+ iconID: 'iD-icon-alert',
+ descriptionID: 'issues.warnings_and_errors'
+ };
+
+ var resolvedItem = {
+ id: 'resolved',
+ count: 0,
+ iconID: 'iD-icon-apply',
+ descriptionID: 'issues.user_resolved_issues'
+ };
+
+ function update(selection) {
+
+ var shownItems = [];
+
+ var liveIssues = context.validator().getIssues({
+ what: corePreferences('validate-what') || 'edited',
+ where: corePreferences('validate-where') || 'all'
+ });
+ if (liveIssues.length) {
+ warningsItem.count = liveIssues.length;
+ shownItems.push(warningsItem);
+ }
+
+ if (corePreferences('validate-what') === 'all') {
+ var resolvedIssues = context.validator().getResolvedIssues();
+ if (resolvedIssues.length) {
+ resolvedItem.count = resolvedIssues.length;
+ shownItems.push(resolvedItem);
+ }
+ }
+
+ var chips = selection.selectAll('.chip')
+ .data(shownItems, function(d) {
+ return d.id;
+ });
+
+ chips.exit().remove();
+
+ var enter = chips.enter()
+ .append('a')
+ .attr('class', function(d) {
+ return 'chip ' + d.id + '-count';
+ })
+ .attr('href', '#')
+ .attr('tabindex', -1)
+ .each(function(d) {
+
+ var chipSelection = select(this);
+
+ var tooltipBehavior = uiTooltip()
+ .placement('top')
+ .title(_t(d.descriptionID));
+
+ chipSelection
+ .call(tooltipBehavior)
+ .on('click', function() {
+ event.preventDefault();
+
+ tooltipBehavior.hide(select(this));
+ // open the Issues pane
+ context.ui().togglePanes(context.container().select('.map-panes .issues-pane'));
+ });
+
+ chipSelection.call(svgIcon('#' + d.iconID));
+
+ });
+
+ enter.append('span')
+ .attr('class', 'count');
+
+ enter.merge(chips)
+ .selectAll('span.count')
+ .text(function(d) {
+ return d.count.toString();
+ });
+ }
+
+
+ return function(selection) {
+ update(selection);
+
+ context.validator().on('validated.infobox', function() {
+ update(selection);
+ });
+ };
+ }
+
+ var isRetina = window.devicePixelRatio && window.devicePixelRatio >= 2;
+
+ // listen for DPI change, e.g. when dragging a browser window from a retina to non-retina screen
+ window.matchMedia(`
+ (-webkit-min-device-pixel-ratio: 2), /* Safari */
+ (min-resolution: 2dppx), /* standard */
+ (min-resolution: 192dpi) /* fallback */
+ `).addListener(function() {
+
+ isRetina = window.devicePixelRatio && window.devicePixelRatio >= 2;
+ });
+
+
+ function localeDateString(s) {
+ if (!s) return null;
+ var options = { day: 'numeric', month: 'short', year: 'numeric' };
+ var d = new Date(s);
+ if (isNaN(d.getTime())) return null;
+ return d.toLocaleDateString(_mainLocalizer.localeCode(), options);
+ }
+
+ function vintageRange(vintage) {
+ var s;
+ if (vintage.start || vintage.end) {
+ s = (vintage.start || '?');
+ if (vintage.start !== vintage.end) {
+ s += ' - ' + (vintage.end || '?');
+ }
+ }
+ return s;
+ }
+
+
+ function rendererBackgroundSource(data) {
+ var source = Object.assign({}, data); // shallow copy
+ var _offset = [0, 0];
+ var _name = source.name;
+ var _description = source.description;
+ var _best = !!source.best;
+ var _template = source.encrypted ? utilAesDecrypt(source.template) : source.template;
+
+ source.tileSize = data.tileSize || 256;
+ source.zoomExtent = data.zoomExtent || [0, 22];
+ source.overzoom = data.overzoom !== false;
+
+ source.offset = function(val) {
+ if (!arguments.length) return _offset;
+ _offset = val;
+ return source;
+ };
+
+
+ source.nudge = function(val, zoomlevel) {
+ _offset[0] += val[0] / Math.pow(2, zoomlevel);
+ _offset[1] += val[1] / Math.pow(2, zoomlevel);
+ return source;
+ };
+
+
+ source.name = function() {
+ var id_safe = source.id.replace(/\./g, '');
+ return _t('imagery.' + id_safe + '.name', { default: _name });
+ };
+
+
+ source.description = function() {
+ var id_safe = source.id.replace(/\./g, '');
+ return _t('imagery.' + id_safe + '.description', { default: _description });
+ };
+
+
+ source.best = function() {
+ return _best;
+ };
+
+
+ source.area = function() {
+ if (!data.polygon) return Number.MAX_VALUE; // worldwide
+ var area = d3_geoArea({ type: 'MultiPolygon', coordinates: [ data.polygon ] });
+ return isNaN(area) ? 0 : area;
+ };
+
+
+ source.imageryUsed = function() {
+ return name || source.id;
+ };
+
+
+ source.template = function(val) {
+ if (!arguments.length) return _template;
+ if (source.id === 'custom') {
+ _template = val;
+ }
+ return source;
+ };
+
+
+ source.url = function(coord) {
+ var result = _template;
+ if (result === '') return result; // source 'none'
+
+
+ // Guess a type based on the tokens present in the template
+ // (This is for 'custom' source, where we don't know)
+ if (!source.type) {
+ if (/\{(proj|wkid|bbox)\}/.test(_template)) {
+ source.type = 'wms';
+ source.projection = 'EPSG:3857'; // guess
+ } else if (/\{(x|y)\}/.test(_template)) {
+ source.type = 'tms';
+ } else if (/\{u\}/.test(_template)) {
+ source.type = 'bing';
+ }
+ }
+
+
+ if (source.type === 'wms') {
+ var tileToProjectedCoords = (function(x, y, z) {
+ //polyfill for IE11, PhantomJS
+ var sinh = Math.sinh || function(x) {
+ var y = Math.exp(x);
+ return (y - 1 / y) / 2;
+ };
+
+ var zoomSize = Math.pow(2, z);
+ var lon = x / zoomSize * Math.PI * 2 - Math.PI;
+ var lat = Math.atan(sinh(Math.PI * (1 - 2 * y / zoomSize)));
+
+ switch (source.projection) {
+ case 'EPSG:4326':
+ return {
+ x: lon * 180 / Math.PI,
+ y: lat * 180 / Math.PI
+ };
+ default: // EPSG:3857 and synonyms
+ var mercCoords = mercatorRaw(lon, lat);
+ return {
+ x: 20037508.34 / Math.PI * mercCoords[0],
+ y: 20037508.34 / Math.PI * mercCoords[1]
+ };
+ }
+ });
+
+ var tileSize = source.tileSize;
+ var projection = source.projection;
+ var minXmaxY = tileToProjectedCoords(coord[0], coord[1], coord[2]);
+ var maxXminY = tileToProjectedCoords(coord[0]+1, coord[1]+1, coord[2]);
+
+ result = result.replace(/\{(\w+)\}/g, function (token, key) {
+ switch (key) {
+ case 'width':
+ case 'height':
+ return tileSize;
+ case 'proj':
+ return projection;
+ case 'wkid':
+ return projection.replace(/^EPSG:/, '');
+ case 'bbox':
+ return minXmaxY.x + ',' + maxXminY.y + ',' + maxXminY.x + ',' + minXmaxY.y;
+ case 'w':
+ return minXmaxY.x;
+ case 's':
+ return maxXminY.y;
+ case 'n':
+ return maxXminY.x;
+ case 'e':
+ return minXmaxY.y;
+ default:
+ return token;
+ }
+ });
+
+ } else if (source.type === 'tms') {
+ result = result
+ .replace('{x}', coord[0])
+ .replace('{y}', coord[1])
+ // TMS-flipped y coordinate
+ .replace(/\{[t-]y\}/, Math.pow(2, coord[2]) - coord[1] - 1)
+ .replace(/\{z(oom)?\}/, coord[2])
+ // only fetch retina tiles for retina screens
+ .replace(/\{@2x\}|\{r\}/, isRetina ? '@2x' : '');
+
+ } else if (source.type === 'bing') {
+ result = result
+ .replace('{u}', function() {
+ var u = '';
+ for (var zoom = coord[2]; zoom > 0; zoom--) {
+ var b = 0;
+ var mask = 1 << (zoom - 1);
+ if ((coord[0] & mask) !== 0) b++;
+ if ((coord[1] & mask) !== 0) b += 2;
+ u += b.toString();
+ }
+ return u;
+ });
+ }
+
+ // these apply to any type..
+ result = result.replace(/\{switch:([^}]+)\}/, function(s, r) {
+ var subdomains = r.split(',');
+ return subdomains[(coord[0] + coord[1]) % subdomains.length];
+ });
+
+
+ return result;
+ };
+
+
+ source.validZoom = function(z) {
+ return source.zoomExtent[0] <= z &&
+ (source.overzoom || source.zoomExtent[1] > z);
+ };
+
+
+ source.isLocatorOverlay = function() {
+ return source.id === 'mapbox_locator_overlay';
+ };
+
+
+ /* hides a source from the list, but leaves it available for use */
+ source.isHidden = function() {
+ return source.id === 'DigitalGlobe-Premium-vintage' ||
+ source.id === 'DigitalGlobe-Standard-vintage';
+ };
+
+
+ source.copyrightNotices = function() {};
+
+
+ source.getMetadata = function(center, tileCoord, callback) {
+ var vintage = {
+ start: localeDateString(source.startDate),
+ end: localeDateString(source.endDate)
+ };
+ vintage.range = vintageRange(vintage);
+
+ var metadata = { vintage: vintage };
+ callback(null, metadata);
+ };
+
+
+ return source;
+ }
+
+
+ rendererBackgroundSource.Bing = function(data, dispatch) {
+ // http://msdn.microsoft.com/en-us/library/ff701716.aspx
+ // http://msdn.microsoft.com/en-us/library/ff701701.aspx
+
+ data.template = 'https://ecn.t{switch:0,1,2,3}.tiles.virtualearth.net/tiles/a{u}.jpeg?g=587&mkt=en-gb&n=z';
+
+ var bing = rendererBackgroundSource(data);
+ // var key = 'Arzdiw4nlOJzRwOz__qailc8NiR31Tt51dN2D7cm57NrnceZnCpgOkmJhNpGoppU'; // P2, JOSM, etc
+ var key = 'Ak5oTE46TUbjRp08OFVcGpkARErDobfpuyNKa-W2mQ8wbt1K1KL8p1bIRwWwcF-Q'; // iD
+
+
+ var url = 'https://dev.virtualearth.net/REST/v1/Imagery/Metadata/Aerial?include=ImageryProviders&key=' + key;
+ var cache = {};
+ var inflight = {};
+ var providers = [];
+
+ d3_json(url)
+ .then(function(json) {
+ providers = json.resourceSets[0].resources[0].imageryProviders.map(function(provider) {
+ return {
+ attribution: provider.attribution,
+ areas: provider.coverageAreas.map(function(area) {
+ return {
+ zoom: [area.zoomMin, area.zoomMax],
+ extent: geoExtent([area.bbox[1], area.bbox[0]], [area.bbox[3], area.bbox[2]])
+ };
+ })
+ };
+ });
+ dispatch.call('change');
+ })
+ .catch(function() {
+ /* ignore */
+ });
+
+
+ bing.copyrightNotices = function(zoom, extent) {
+ zoom = Math.min(zoom, 21);
+ return providers.filter(function(provider) {
+ return provider.areas.some(function(area) {
+ return extent.intersects(area.extent) &&
+ area.zoom[0] <= zoom &&
+ area.zoom[1] >= zoom;
+ });
+ }).map(function(provider) {
+ return provider.attribution;
+ }).join(', ');
+ };
+
+
+ bing.getMetadata = function(center, tileCoord, callback) {
+ var tileID = tileCoord.slice(0, 3).join('/');
+ var zoom = Math.min(tileCoord[2], 21);
+ var centerPoint = center[1] + ',' + center[0]; // lat,lng
+ var url = 'https://dev.virtualearth.net/REST/v1/Imagery/Metadata/Aerial/' + centerPoint +
+ '?zl=' + zoom + '&key=' + key;
+
+ if (inflight[tileID]) return;
+
+ if (!cache[tileID]) {
+ cache[tileID] = {};
+ }
+ if (cache[tileID] && cache[tileID].metadata) {
+ return callback(null, cache[tileID].metadata);
+ }
+
+ inflight[tileID] = true;
+ d3_json(url)
+ .then(function(result) {
+ delete inflight[tileID];
+ if (!result) {
+ throw new Error('Unknown Error');
+ }
+ var vintage = {
+ start: localeDateString(result.resourceSets[0].resources[0].vintageStart),
+ end: localeDateString(result.resourceSets[0].resources[0].vintageEnd)
+ };
+ vintage.range = vintageRange(vintage);
+
+ var metadata = { vintage: vintage };
+ cache[tileID].metadata = metadata;
+ if (callback) callback(null, metadata);
+ })
+ .catch(function(err) {
+ delete inflight[tileID];
+ if (callback) callback(err.message);
+ });
+ };
+
+
+ bing.terms_url = 'https://blog.openstreetmap.org/2010/11/30/microsoft-imagery-details';
+
+
+ return bing;
+ };
+
+
+
+ rendererBackgroundSource.Esri = function(data) {
+ // in addition to using the tilemap at zoom level 20, overzoom real tiles - #4327 (deprecated technique, but it works)
+ if (data.template.match(/blankTile/) === null) {
+ data.template = data.template + '?blankTile=false';
+ }
+
+ var esri = rendererBackgroundSource(data);
+ var cache = {};
+ var inflight = {};
+ var _prevCenter;
+
+ // use a tilemap service to set maximum zoom for esri tiles dynamically
+ // https://developers.arcgis.com/documentation/tiled-elevation-service/
+ esri.fetchTilemap = function(center) {
+ // skip if we have already fetched a tilemap within 5km
+ if (_prevCenter && geoSphericalDistance(center, _prevCenter) < 5000) return;
+ _prevCenter = center;
+
+ // tiles are available globally to zoom level 19, afterward they may or may not be present
+ var z = 20;
+
+ // first generate a random url using the template
+ var dummyUrl = esri.url([1,2,3]);
+
+ // calculate url z/y/x from the lat/long of the center of the map
+ var x = (Math.floor((center[0] + 180) / 360 * Math.pow(2, z)));
+ var y = (Math.floor((1 - Math.log(Math.tan(center[1] * Math.PI / 180) + 1 / Math.cos(center[1] * Math.PI / 180)) / Math.PI) / 2 * Math.pow(2, z)));
+
+ // fetch an 8x8 grid to leverage cache
+ var tilemapUrl = dummyUrl.replace(/tile\/[0-9]+\/[0-9]+\/[0-9]+\?blankTile=false/, 'tilemap') + '/' + z + '/' + y + '/' + x + '/8/8';
+
+ // make the request and introspect the response from the tilemap server
+ d3_json(tilemapUrl)
+ .then(function(tilemap) {
+ if (!tilemap) {
+ throw new Error('Unknown Error');
+ }
+ var hasTiles = true;
+ for (var i = 0; i < tilemap.data.length; i++) {
+ // 0 means an individual tile in the grid doesn't exist
+ if (!tilemap.data[i]) {
+ hasTiles = false;
+ break;
+ }
+ }
+
+ // if any tiles are missing at level 20 we restrict maxZoom to 19
+ esri.zoomExtent[1] = (hasTiles ? 22 : 19);
+ })
+ .catch(function() {
+ /* ignore */
+ });
+ };
+
+
+ esri.getMetadata = function(center, tileCoord, callback) {
+ var tileID = tileCoord.slice(0, 3).join('/');
+ var zoom = Math.min(tileCoord[2], esri.zoomExtent[1]);
+ var centerPoint = center[0] + ',' + center[1]; // long, lat (as it should be)
+ var unknown = _t('info_panels.background.unknown');
+ var metadataLayer;
+ var vintage = {};
+ var metadata = {};
+
+ if (inflight[tileID]) return;
+
+ switch (true) {
+ case (zoom >= 20 && esri.id === 'EsriWorldImageryClarity'):
+ metadataLayer = 4;
+ break;
+ case zoom >= 19:
+ metadataLayer = 3;
+ break;
+ case zoom >= 17:
+ metadataLayer = 2;
+ break;
+ case zoom >= 13:
+ metadataLayer = 0;
+ break;
+ default:
+ metadataLayer = 99;
+ }
+
+ var url;
+ // build up query using the layer appropriate to the current zoom
+ if (esri.id === 'EsriWorldImagery') {
+ url = 'https://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/';
+ } else if (esri.id === 'EsriWorldImageryClarity') {
+ url = 'https://serviceslab.arcgisonline.com/arcgis/rest/services/Clarity_World_Imagery/MapServer/';
+ }
+
+ url += metadataLayer + '/query?returnGeometry=false&geometry=' + centerPoint + '&inSR=4326&geometryType=esriGeometryPoint&outFields=*&f=json';
+
+ if (!cache[tileID]) {
+ cache[tileID] = {};
+ }
+ if (cache[tileID] && cache[tileID].metadata) {
+ return callback(null, cache[tileID].metadata);
+ }
+
+ // accurate metadata is only available >= 13
+ if (metadataLayer === 99) {
+ vintage = {
+ start: null,
+ end: null,
+ range: null
+ };
+ metadata = {
+ vintage: null,
+ source: unknown,
+ description: unknown,
+ resolution: unknown,
+ accuracy: unknown
+ };
+
+ callback(null, metadata);
+
+ } else {
+ inflight[tileID] = true;
+ d3_json(url)
+ .then(function(result) {
+ delete inflight[tileID];
+ if (!result) {
+ throw new Error('Unknown Error');
+ } else if (result.features && result.features.length < 1) {
+ throw new Error('No Results');
+ } else if (result.error && result.error.message) {
+ throw new Error(result.error.message);
+ }
+
+ // pass through the discrete capture date from metadata
+ var captureDate = localeDateString(result.features[0].attributes.SRC_DATE2);
+ vintage = {
+ start: captureDate,
+ end: captureDate,
+ range: captureDate
+ };
+ metadata = {
+ vintage: vintage,
+ source: clean(result.features[0].attributes.NICE_NAME),
+ description: clean(result.features[0].attributes.NICE_DESC),
+ resolution: clean(+parseFloat(result.features[0].attributes.SRC_RES).toFixed(4)),
+ accuracy: clean(+parseFloat(result.features[0].attributes.SRC_ACC).toFixed(4))
+ };
+
+ // append units - meters
+ if (isFinite(metadata.resolution)) {
+ metadata.resolution += ' m';
+ }
+ if (isFinite(metadata.accuracy)) {
+ metadata.accuracy += ' m';
+ }
+
+ cache[tileID].metadata = metadata;
+ if (callback) callback(null, metadata);
+ })
+ .catch(function(err) {
+ delete inflight[tileID];
+ if (callback) callback(err.message);
+ });
+ }
+
+
+ function clean(val) {
+ return String(val).trim() || unknown;
+ }
+ };
+
+ return esri;
+ };
+
+
+ rendererBackgroundSource.None = function() {
+ var source = rendererBackgroundSource({ id: 'none', template: '' });
+
+
+ source.name = function() {
+ return _t('background.none');
+ };
+
+
+ source.imageryUsed = function() {
+ return null;
+ };
+
+
+ source.area = function() {
+ return -1; // sources in background pane are sorted by area
+ };
+
+
+ return source;
+ };
+
+
+ rendererBackgroundSource.Custom = function(template) {
+ var source = rendererBackgroundSource({ id: 'custom', template: template });
+
+
+ source.name = function() {
+ return _t('background.custom');
+ };
+
+
+ source.imageryUsed = function() {
+ // sanitize personal connection tokens - #6801
+ var cleaned = source.template();
+
+ // from query string parameters
+ if (cleaned.indexOf('?') !== -1) {
+ var parts = cleaned.split('?', 2);
+ var qs = utilStringQs(parts[1]);
+
+ ['access_token', 'connectId', 'token'].forEach(function(param) {
+ if (qs[param]) {
+ qs[param] = '{apikey}';
+ }
+ });
+ cleaned = parts[0] + '?' + utilQsString(qs, true); // true = soft encode
+ }
+
+ // from wms/wmts api path parameters
+ cleaned = cleaned.replace(/token\/(\w+)/, 'token/{apikey}');
+
+ return 'Custom (' + cleaned + ' )';
+ };
+
+
+ source.area = function() {
+ return -2; // sources in background pane are sorted by area
+ };
+
+
+ return source;
+ };
+
+ function rendererTileLayer(context) {
+ var transformProp = utilPrefixCSSProperty('Transform');
+ var tiler = utilTiler();
+
+ var _tileSize = 256;
+ var _projection;
+ var _cache = {};
+ var _tileOrigin;
+ var _zoom;
+ var _source;
+
+
+ function tileSizeAtZoom(d, z) {
+ var EPSILON = 0.002; // close seams
+ return ((_tileSize * Math.pow(2, z - d[2])) / _tileSize) + EPSILON;
+ }
+
+
+ function atZoom(t, distance) {
+ var power = Math.pow(2, distance);
+ return [
+ Math.floor(t[0] * power),
+ Math.floor(t[1] * power),
+ t[2] + distance
+ ];
+ }
+
+
+ function lookUp(d) {
+ for (var up = -1; up > -d[2]; up--) {
+ var tile = atZoom(d, up);
+ if (_cache[_source.url(tile)] !== false) {
+ return tile;
+ }
+ }
+ }
+
+
+ function uniqueBy(a, n) {
+ var o = [];
+ var seen = {};
+ for (var i = 0; i < a.length; i++) {
+ if (seen[a[i][n]] === undefined) {
+ o.push(a[i]);
+ seen[a[i][n]] = true;
+ }
+ }
+ return o;
+ }
+
+
+ function addSource(d) {
+ d.push(_source.url(d));
+ return d;
+ }
+
+
+ // Update tiles based on current state of `projection`.
+ function background(selection) {
+ _zoom = geoScaleToZoom(_projection.scale(), _tileSize);
+
+ var pixelOffset;
+ if (_source) {
+ pixelOffset = [
+ _source.offset()[0] * Math.pow(2, _zoom),
+ _source.offset()[1] * Math.pow(2, _zoom)
+ ];
+ } else {
+ pixelOffset = [0, 0];
+ }
+
+ var translate = [
+ _projection.translate()[0] + pixelOffset[0],
+ _projection.translate()[1] + pixelOffset[1]
+ ];
+
+ tiler
+ .scale(_projection.scale() * 2 * Math.PI)
+ .translate(translate);
+
+ _tileOrigin = [
+ _projection.scale() * Math.PI - translate[0],
+ _projection.scale() * Math.PI - translate[1]
+ ];
+
+ render(selection);
+ }
+
+
+ // Derive the tiles onscreen, remove those offscreen and position them.
+ // Important that this part not depend on `_projection` because it's
+ // rentered when tiles load/error (see #644).
+ function render(selection) {
+ if (!_source) return;
+ var requests = [];
+ var showDebug = context.getDebug('tile') && !_source.overlay;
+
+ if (_source.validZoom(_zoom)) {
+ tiler.skipNullIsland(!!_source.overlay);
+
+ tiler().forEach(function(d) {
+ addSource(d);
+ if (d[3] === '') return;
+ if (typeof d[3] !== 'string') return; // Workaround for #2295
+ requests.push(d);
+ if (_cache[d[3]] === false && lookUp(d)) {
+ requests.push(addSource(lookUp(d)));
+ }
+ });
+
+ requests = uniqueBy(requests, 3).filter(function(r) {
+ // don't re-request tiles which have failed in the past
+ return _cache[r[3]] !== false;
+ });
+ }
+
+ function load(d) {
+ _cache[d[3]] = true;
+ select(this)
+ .on('error', null)
+ .on('load', null)
+ .classed('tile-loaded', true);
+ render(selection);
+ }
+
+ function error(d) {
+ _cache[d[3]] = false;
+ select(this)
+ .on('error', null)
+ .on('load', null)
+ .remove();
+ render(selection);
+ }
+
+ function imageTransform(d) {
+ var ts = _tileSize * Math.pow(2, _zoom - d[2]);
+ var scale = tileSizeAtZoom(d, _zoom);
+ return 'translate(' +
+ ((d[0] * ts) - _tileOrigin[0]) + 'px,' +
+ ((d[1] * ts) - _tileOrigin[1]) + 'px) ' +
+ 'scale(' + scale + ',' + scale + ')';
+ }
+
+ function tileCenter(d) {
+ var ts = _tileSize * Math.pow(2, _zoom - d[2]);
+ return [
+ ((d[0] * ts) - _tileOrigin[0] + (ts / 2)),
+ ((d[1] * ts) - _tileOrigin[1] + (ts / 2))
+ ];
+ }
+
+ function debugTransform(d) {
+ var coord = tileCenter(d);
+ return 'translate(' + coord[0] + 'px,' + coord[1] + 'px)';
+ }
+
+
+ // Pick a representative tile near the center of the viewport
+ // (This is useful for sampling the imagery vintage)
+ var dims = tiler.size();
+ var mapCenter = [dims[0] / 2, dims[1] / 2];
+ var minDist = Math.max(dims[0], dims[1]);
+ var nearCenter;
+
+ requests.forEach(function(d) {
+ var c = tileCenter(d);
+ var dist = geoVecLength(c, mapCenter);
+ if (dist < minDist) {
+ minDist = dist;
+ nearCenter = d;
+ }
+ });
+
+
+ var image = selection.selectAll('img')
+ .data(requests, function(d) { return d[3]; });
+
+ image.exit()
+ .style(transformProp, imageTransform)
+ .classed('tile-removing', true)
+ .classed('tile-center', false)
+ .each(function() {
+ var tile = select(this);
+ window.setTimeout(function() {
+ if (tile.classed('tile-removing')) {
+ tile.remove();
+ }
+ }, 300);
+ });
+
+ image.enter()
+ .append('img')
+ .attr('class', 'tile')
+ .attr('draggable', 'false')
+ .style('width', _tileSize + 'px')
+ .style('height', _tileSize + 'px')
+ .attr('src', function(d) { return d[3]; })
+ .on('error', error)
+ .on('load', load)
+ .merge(image)
+ .style(transformProp, imageTransform)
+ .classed('tile-debug', showDebug)
+ .classed('tile-removing', false)
+ .classed('tile-center', function(d) { return d === nearCenter; });
+
+
+
+ var debug = selection.selectAll('.tile-label-debug')
+ .data(showDebug ? requests : [], function(d) { return d[3]; });
+
+ debug.exit()
+ .remove();
+
+ if (showDebug) {
+ var debugEnter = debug.enter()
+ .append('div')
+ .attr('class', 'tile-label-debug');
+
+ debugEnter
+ .append('div')
+ .attr('class', 'tile-label-debug-coord');
+
+ debugEnter
+ .append('div')
+ .attr('class', 'tile-label-debug-vintage');
+
+ debug = debug.merge(debugEnter);
+
+ debug
+ .style(transformProp, debugTransform);
+
+ debug
+ .selectAll('.tile-label-debug-coord')
+ .text(function(d) { return d[2] + ' / ' + d[0] + ' / ' + d[1]; });
+
+ debug
+ .selectAll('.tile-label-debug-vintage')
+ .each(function(d) {
+ var span = select(this);
+ var center = context.projection.invert(tileCenter(d));
+ _source.getMetadata(center, d, function(err, result) {
+ span.text((result && result.vintage && result.vintage.range) ||
+ _t('info_panels.background.vintage') + ': ' + _t('info_panels.background.unknown')
+ );
+ });
+ });
+ }
+
+ }
+
+
+ background.projection = function(val) {
+ if (!arguments.length) return _projection;
+ _projection = val;
+ return background;
+ };
+
+
+ background.dimensions = function(val) {
+ if (!arguments.length) return tiler.size();
+ tiler.size(val);
+ return background;
+ };
+
+
+ background.source = function(val) {
+ if (!arguments.length) return _source;
+ _source = val;
+ _tileSize = _source.tileSize;
+ _cache = {};
+ tiler.tileSize(_source.tileSize).zoomExtent(_source.zoomExtent);
+ return background;
+ };
+
+
+ return background;
+ }
+
+ let _imageryIndex = null;
+
+ function rendererBackground(context) {
+ const dispatch$1 = dispatch('change');
+ const detected = utilDetect();
+ const baseLayer = rendererTileLayer(context).projection(context.projection);
+ let _isValid = true;
+ let _overlayLayers = [];
+ let _brightness = 1;
+ let _contrast = 1;
+ let _saturation = 1;
+ let _sharpness = 1;
+ var _numGridSplits = 0; // No grid by default.
+
+
+ function ensureImageryIndex() {
+ return _mainFileFetcher.get('imagery')
+ .then(sources => {
+ if (_imageryIndex) return _imageryIndex;
+
+ _imageryIndex = {
+ imagery: sources,
+ features: {}
+ };
+
+ // use which-polygon to support efficient index and querying for imagery
+ const features = sources.map(source => {
+ if (!source.polygon) return null;
+ // workaround for editor-layer-index weirdness..
+ // Add an extra array nest to each element in `source.polygon`
+ // so the rings are not treated as a bunch of holes:
+ // what we have: [ [[outer],[hole],[hole]] ]
+ // what we want: [ [[outer]],[[outer]],[[outer]] ]
+ const rings = source.polygon.map(ring => [ring]);
+
+ const feature = {
+ type: 'Feature',
+ properties: { id: source.id },
+ geometry: { type: 'MultiPolygon', coordinates: rings }
+ };
+
+ _imageryIndex.features[source.id] = feature;
+ return feature;
+
+ }).filter(Boolean);
+
+ _imageryIndex.query = whichPolygon_1({ type: 'FeatureCollection', features: features });
+
+
+ // Instantiate `rendererBackgroundSource` objects for each source
+ _imageryIndex.backgrounds = sources.map(source => {
+ if (source.type === 'bing') {
+ return rendererBackgroundSource.Bing(source, dispatch$1);
+ } else if (/^EsriWorldImagery/.test(source.id)) {
+ return rendererBackgroundSource.Esri(source);
+ } else {
+ return rendererBackgroundSource(source);
+ }
+ });
+
+ // Add 'None'
+ _imageryIndex.backgrounds.unshift(rendererBackgroundSource.None());
+
+ // Add 'Custom'
+ let template = corePreferences('background-custom-template') || '';
+ const custom = rendererBackgroundSource.Custom(template);
+ _imageryIndex.backgrounds.unshift(custom);
+
+ return _imageryIndex;
+ });
+ }
+
+
+ function background(selection) {
+ const currSource = baseLayer.source();
+
+ // If we are displaying an Esri basemap at high zoom,
+ // check its tilemap to see how high the zoom can go
+ if (context.map().zoom() > 18) {
+ if (currSource && /^EsriWorldImagery/.test(currSource.id)) {
+ const center = context.map().center();
+ currSource.fetchTilemap(center);
+ }
+ }
+
+ // Is the imagery valid here? - #4827
+ const sources = background.sources(context.map().extent());
+ const wasValid = _isValid;
+ _isValid = !!sources.filter(d => d === currSource).length;
+
+ if (wasValid !== _isValid) { // change in valid status
+ background.updateImagery();
+ }
+
+
+ let baseFilter = '';
+ if (detected.cssfilters) {
+ if (_brightness !== 1) {
+ baseFilter += ` brightness(${_brightness})`;
+ }
+ if (_contrast !== 1) {
+ baseFilter += ` contrast(${_contrast})`;
+ }
+ if (_saturation !== 1) {
+ baseFilter += ` saturate(${_saturation})`;
+ }
+ if (_sharpness < 1) { // gaussian blur
+ const blur = d3_interpolateNumber(0.5, 5)(1 - _sharpness);
+ baseFilter += ` blur(${blur}px)`;
+ }
+ }
+
+ let base = selection.selectAll('.layer-background')
+ .data([0]);
+
+ base = base.enter()
+ .insert('div', '.layer-data')
+ .attr('class', 'layer layer-background')
+ .merge(base);
+
+ if (detected.cssfilters) {
+ base.style('filter', baseFilter || null);
+ } else {
+ base.style('opacity', _brightness);
+ }
+
+
+ let imagery = base.selectAll('.layer-imagery')
+ .data([0]);
+
+ imagery.enter()
+ .append('div')
+ .attr('class', 'layer layer-imagery')
+ .merge(imagery)
+ .call(baseLayer);
+
+
+ let maskFilter = '';
+ let mixBlendMode = '';
+ if (detected.cssfilters && _sharpness > 1) { // apply unsharp mask
+ mixBlendMode = 'overlay';
+ maskFilter = 'saturate(0) blur(3px) invert(1)';
+
+ let contrast = _sharpness - 1;
+ maskFilter += ` contrast(${contrast})`;
+
+ let brightness = d3_interpolateNumber(1, 0.85)(_sharpness - 1);
+ maskFilter += ` brightness(${brightness})`;
+ }
+
+ let mask = base.selectAll('.layer-unsharp-mask')
+ .data(detected.cssfilters && _sharpness > 1 ? [0] : []);
+
+ mask.exit()
+ .remove();
+
+ mask.enter()
+ .append('div')
+ .attr('class', 'layer layer-mask layer-unsharp-mask')
+ .merge(mask)
+ .call(baseLayer)
+ .style('filter', maskFilter || null)
+ .style('mix-blend-mode', mixBlendMode || null);
+
+
+ let overlays = selection.selectAll('.layer-overlay')
+ .data(_overlayLayers, d => d.source().name());
+
+ overlays.exit()
+ .remove();
+
+ overlays.enter()
+ .insert('div', '.layer-data')
+ .attr('class', 'layer layer-overlay')
+ .merge(overlays)
+ .each((layer, i, nodes) => select(nodes[i]).call(layer));
+ }
+
+ background.numGridSplits = function(_) {
+ if (!arguments.length) return _numGridSplits;
+ _numGridSplits = _;
+ dispatch$1.call('change');
+ return background;
+ };
+
+ background.updateImagery = function() {
+ let currSource = baseLayer.source();
+ if (context.inIntro() || !currSource) return;
+
+ let o = _overlayLayers
+ .filter(d => !d.source().isLocatorOverlay() && !d.source().isHidden())
+ .map(d => d.source().id)
+ .join(',');
+
+ const meters = geoOffsetToMeters(currSource.offset());
+ const EPSILON = 0.01;
+ const x = +meters[0].toFixed(2);
+ const y = +meters[1].toFixed(2);
+ let hash = utilStringQs(window.location.hash);
+
+ let id = currSource.id;
+ if (id === 'custom') {
+ id = `custom:${currSource.template()}`;
+ }
+
+ if (id) {
+ hash.background = id;
+ } else {
+ delete hash.background;
+ }
+
+ if (o) {
+ hash.overlays = o;
+ } else {
+ delete hash.overlays;
+ }
+
+ if (Math.abs(x) > EPSILON || Math.abs(y) > EPSILON) {
+ hash.offset = `${x},${y}`;
+ } else {
+ delete hash.offset;
+ }
+
+ if (!window.mocha) {
+ window.location.replace('#' + utilQsString(hash, true));
+ }
+
+ let imageryUsed = [];
+ let photoOverlaysUsed = [];
+
+ const currUsed = currSource.imageryUsed();
+ if (currUsed && _isValid) {
+ imageryUsed.push(currUsed);
+ }
+
+ _overlayLayers
+ .filter(d => !d.source().isLocatorOverlay() && !d.source().isHidden())
+ .forEach(d => imageryUsed.push(d.source().imageryUsed()));
+
+ const dataLayer = context.layers().layer('data');
+ if (dataLayer && dataLayer.enabled() && dataLayer.hasData()) {
+ imageryUsed.push(dataLayer.getSrc());
+ }
+
+ const photoOverlayLayers = {
+ streetside: 'Bing Streetside',
+ mapillary: 'Mapillary Images',
+ 'mapillary-map-features': 'Mapillary Map Features',
+ 'mapillary-signs': 'Mapillary Signs',
+ openstreetcam: 'OpenStreetCam Images'
+ };
+
+ for (let layerID in photoOverlayLayers) {
+ const layer = context.layers().layer(layerID);
+ if (layer && layer.enabled()) {
+ photoOverlaysUsed.push(layerID);
+ imageryUsed.push(photoOverlayLayers[layerID]);
+ }
+ }
+
+ context.history().imageryUsed(imageryUsed);
+ context.history().photoOverlaysUsed(photoOverlaysUsed);
+ };
+
+
+ background.sources = (extent, zoom, includeCurrent) => {
+ if (!_imageryIndex) return []; // called before init()?
+
+ let visible = {};
+ (_imageryIndex.query.bbox(extent.rectangle(), true) || [])
+ .forEach(d => visible[d.id] = true);
+
+ const currSource = baseLayer.source();
+
+ return _imageryIndex.backgrounds.filter(source => {
+ if (!source.polygon) return true; // always include imagery with worldwide coverage
+ if (includeCurrent && currSource === source) return true; // optionally include the current imagery
+ if (zoom && zoom < 6) return false; // optionally exclude local imagery at low zooms
+ return visible[source.id]; // include imagery visible in given extent
+ });
+ };
+
+
+ background.dimensions = (val) => {
+ if (!val) return;
+ baseLayer.dimensions(val);
+ _overlayLayers.forEach(layer => layer.dimensions(val));
+ };
+
+
+ background.baseLayerSource = function(d) {
+ if (!arguments.length) return baseLayer.source();
+
+ // test source against OSM imagery blacklists..
+ const osm = context.connection();
+ if (!osm) return background;
+
+ const blacklists = osm.imageryBlacklists();
+ const template = d.template();
+ let fail = false;
+ let tested = 0;
+ let regex;
+
+ for (let i = 0; i < blacklists.length; i++) {
+ try {
+ regex = new RegExp(blacklists[i]);
+ fail = regex.test(template);
+ tested++;
+ if (fail) break;
+ } catch (e) {
+ /* noop */
+ }
+ }
+
+ // ensure at least one test was run.
+ if (!tested) {
+ regex = new RegExp('.*\.google(apis)?\..*/(vt|kh)[\?/].*([xyz]=.*){3}.*');
+ fail = regex.test(template);
+ }
+
+ baseLayer.source(!fail ? d : background.findSource('none'));
+ dispatch$1.call('change');
+ background.updateImagery();
+ return background;
+ };
+
+
+ background.findSource = (id) => {
+ if (!id || !_imageryIndex) return null; // called before init()?
+ return _imageryIndex.backgrounds.find(d => d.id && d.id === id);
+ };
+
+
+ background.bing = () => {
+ background.baseLayerSource(background.findSource('Bing'));
+ };
+
+
+ background.showsLayer = (d) => {
+ const currSource = baseLayer.source();
+ if (!d || !currSource) return false;
+ return d.id === currSource.id || _overlayLayers.some(layer => d.id === layer.source().id);
+ };
+
+
+ background.overlayLayerSources = () => {
+ return _overlayLayers.map(layer => layer.source());
+ };
+
+
+ background.toggleOverlayLayer = (d) => {
+ let layer;
+ for (let i = 0; i < _overlayLayers.length; i++) {
+ layer = _overlayLayers[i];
+ if (layer.source() === d) {
+ _overlayLayers.splice(i, 1);
+ dispatch$1.call('change');
+ background.updateImagery();
+ return;
+ }
+ }
+
+ layer = rendererTileLayer(context)
+ .source(d)
+ .projection(context.projection)
+ .dimensions(baseLayer.dimensions()
+ );
+
+ _overlayLayers.push(layer);
+ dispatch$1.call('change');
+ background.updateImagery();
+ };
+
+
+ background.nudge = (d, zoom) => {
+ const currSource = baseLayer.source();
+ if (currSource) {
+ currSource.nudge(d, zoom);
+ dispatch$1.call('change');
+ background.updateImagery();
+ }
+ return background;
+ };
+
+
+ background.offset = function(d) {
+ const currSource = baseLayer.source();
+ if (!arguments.length) {
+ return (currSource && currSource.offset()) || [0, 0];
+ }
+ if (currSource) {
+ currSource.offset(d);
+ dispatch$1.call('change');
+ background.updateImagery();
+ }
+ return background;
+ };
+
+
+ background.brightness = function(d) {
+ if (!arguments.length) return _brightness;
+ _brightness = d;
+ if (context.mode()) dispatch$1.call('change');
+ return background;
+ };
+
+
+ background.contrast = function(d) {
+ if (!arguments.length) return _contrast;
+ _contrast = d;
+ if (context.mode()) dispatch$1.call('change');
+ return background;
+ };
+
+
+ background.saturation = function(d) {
+ if (!arguments.length) return _saturation;
+ _saturation = d;
+ if (context.mode()) dispatch$1.call('change');
+ return background;
+ };
+
+
+ background.sharpness = function(d) {
+ if (!arguments.length) return _sharpness;
+ _sharpness = d;
+ if (context.mode()) dispatch$1.call('change');
+ return background;
+ };
+
+ let _loadPromise;
+
+ background.ensureLoaded = () => {
+
+ if (_loadPromise) return _loadPromise;
+
+ function parseMapParams(qmap) {
+ if (!qmap) return false;
+ const params = qmap.split('/').map(Number);
+ if (params.length < 3 || params.some(isNaN)) return false;
+ return geoExtent([params[2], params[1]]); // lon,lat
+ }
+
+ const hash = utilStringQs(window.location.hash);
+ const requested = hash.background || hash.layer;
+ let extent = parseMapParams(hash.map);
+
+ return _loadPromise = ensureImageryIndex()
+ .then(imageryIndex => {
+ const first = imageryIndex.backgrounds.length && imageryIndex.backgrounds[0];
+
+ let best;
+ if (!requested && extent) {
+ best = background.sources(extent).find(s => s.best());
+ }
+
+ // Decide which background layer to display
+ if (requested && requested.indexOf('custom:') === 0) {
+ const template = requested.replace(/^custom:/, '');
+ const custom = background.findSource('custom');
+ background.baseLayerSource(custom.template(template));
+ corePreferences('background-custom-template', template);
+ } else {
+ background.baseLayerSource(
+ background.findSource(requested) ||
+ best ||
+ background.findSource(corePreferences('background-last-used')) ||
+ background.findSource('Maxar-Premium') ||
+ background.findSource('Bing') ||
+ first ||
+ background.findSource('none')
+ );
+ }
+
+ const locator = imageryIndex.backgrounds.find(d => d.overlay && d.default);
+ if (locator) {
+ background.toggleOverlayLayer(locator);
+ }
+
+ const overlays = (hash.overlays || '').split(',');
+ overlays.forEach(overlay => {
+ overlay = background.findSource(overlay);
+ if (overlay) {
+ background.toggleOverlayLayer(overlay);
+ }
+ });
+
+ if (hash.gpx) {
+ const gpx = context.layers().layer('data');
+ if (gpx) {
+ gpx.url(hash.gpx, '.gpx');
+ }
+ }
+
+ if (hash.offset) {
+ const offset = hash.offset
+ .replace(/;/g, ',')
+ .split(',')
+ .map(n => !isNaN(n) && n);
+
+ if (offset.length === 2) {
+ background.offset(geoMetersToOffset(offset));
+ }
+ }
+ })
+ .catch(() => { /* ignore */ });
+ };
+
+
+ return utilRebind(background, dispatch$1, 'on');
+ }
+
+ function rendererFeatures(context) {
+ var dispatch$1 = dispatch('change', 'redraw');
+ var features = utilRebind({}, dispatch$1, 'on');
+ var _deferred = new Set();
+
+ var traffic_roads = {
+ 'motorway': true,
+ 'motorway_link': true,
+ 'trunk': true,
+ 'trunk_link': true,
+ 'primary': true,
+ 'primary_link': true,
+ 'secondary': true,
+ 'secondary_link': true,
+ 'tertiary': true,
+ 'tertiary_link': true,
+ 'residential': true,
+ 'unclassified': true,
+ 'living_street': true
+ };
+
+ var service_roads = {
+ 'service': true,
+ 'road': true,
+ 'track': true
+ };
+
+ var paths = {
+ 'path': true,
+ 'footway': true,
+ 'cycleway': true,
+ 'bridleway': true,
+ 'steps': true,
+ 'pedestrian': true
+ };
+
+ var past_futures = {
+ 'proposed': true,
+ 'construction': true,
+ 'abandoned': true,
+ 'dismantled': true,
+ 'disused': true,
+ 'razed': true,
+ 'demolished': true,
+ 'obliterated': true
+ };
+
+ var _cullFactor = 1;
+ var _cache = {};
+ var _rules = {};
+ var _stats = {};
+ var _keys = [];
+ var _hidden = [];
+ var _forceVisible = {};
+
+
+ function update() {
+ if (!window.mocha) {
+ var hash = utilStringQs(window.location.hash);
+ var disabled = features.disabled();
+ if (disabled.length) {
+ hash.disable_features = disabled.join(',');
+ } else {
+ delete hash.disable_features;
+ }
+ window.location.replace('#' + utilQsString(hash, true));
+ corePreferences('disabled-features', disabled.join(','));
+ }
+ _hidden = features.hidden();
+ dispatch$1.call('change');
+ dispatch$1.call('redraw');
+ }
+
+
+ function defineRule(k, filter, max) {
+ var isEnabled = true;
+
+ _keys.push(k);
+ _rules[k] = {
+ filter: filter,
+ enabled: isEnabled, // whether the user wants it enabled..
+ count: 0,
+ currentMax: (max || Infinity),
+ defaultMax: (max || Infinity),
+ enable: function() { this.enabled = true; this.currentMax = this.defaultMax; },
+ disable: function() { this.enabled = false; this.currentMax = 0; },
+ hidden: function() {
+ return (this.count === 0 && !this.enabled) ||
+ this.count > this.currentMax * _cullFactor;
+ },
+ autoHidden: function() { return this.hidden() && this.currentMax > 0; }
+ };
+ }
+
+
+ defineRule('points', function isPoint(tags, geometry) {
+ return geometry === 'point';
+ }, 200);
+
+ defineRule('traffic_roads', function isTrafficRoad(tags) {
+ return traffic_roads[tags.highway];
+ });
+
+ defineRule('service_roads', function isServiceRoad(tags) {
+ return service_roads[tags.highway];
+ });
+
+ defineRule('paths', function isPath(tags) {
+ return paths[tags.highway];
+ });
+
+ defineRule('buildings', function isBuilding(tags) {
+ return (
+ (!!tags.building && tags.building !== 'no') ||
+ tags.parking === 'multi-storey' ||
+ tags.parking === 'sheds' ||
+ tags.parking === 'carports' ||
+ tags.parking === 'garage_boxes'
+ );
+ }, 250);
+
+ defineRule('building_parts', function isBuildingPart(tags) {
+ return tags['building:part'];
+ });
+
+ defineRule('indoor', function isIndoor(tags) {
+ return tags.indoor;
+ });
+
+ defineRule('landuse', function isLanduse(tags, geometry) {
+ return geometry === 'area' &&
+ !_rules.buildings.filter(tags) &&
+ !_rules.building_parts.filter(tags) &&
+ !_rules.indoor.filter(tags) &&
+ !_rules.water.filter(tags) &&
+ !_rules.pistes.filter(tags);
+ });
+
+ defineRule('boundaries', function isBoundary(tags) {
+ return (
+ !!tags.boundary
+ ) && !(
+ traffic_roads[tags.highway] ||
+ service_roads[tags.highway] ||
+ paths[tags.highway] ||
+ tags.waterway ||
+ tags.railway ||
+ tags.landuse ||
+ tags.natural ||
+ tags.building ||
+ tags.power
+ );
+ });
+
+ defineRule('water', function isWater(tags) {
+ return (
+ !!tags.waterway ||
+ tags.natural === 'water' ||
+ tags.natural === 'coastline' ||
+ tags.natural === 'bay' ||
+ tags.landuse === 'pond' ||
+ tags.landuse === 'basin' ||
+ tags.landuse === 'reservoir' ||
+ tags.landuse === 'salt_pond'
+ );
+ });
+
+ defineRule('rail', function isRail(tags) {
+ return (
+ !!tags.railway ||
+ tags.landuse === 'railway'
+ ) && !(
+ traffic_roads[tags.highway] ||
+ service_roads[tags.highway] ||
+ paths[tags.highway]
+ );
+ });
+
+ defineRule('pistes', function isPiste(tags) {
+ return tags['piste:type'];
+ });
+
+ defineRule('aerialways', function isPiste(tags) {
+ return tags.aerialway &&
+ tags.aerialway !== 'yes' &&
+ tags.aerialway !== 'station';
+ });
+
+ defineRule('power', function isPower(tags) {
+ return !!tags.power;
+ });
+
+ // contains a past/future tag, but not in active use as a road/path/cycleway/etc..
+ defineRule('past_future', function isPastFuture(tags) {
+ if (
+ traffic_roads[tags.highway] ||
+ service_roads[tags.highway] ||
+ paths[tags.highway]
+ ) { return false; }
+
+ var strings = Object.keys(tags);
+
+ for (var i = 0; i < strings.length; i++) {
+ var s = strings[i];
+ if (past_futures[s] || past_futures[tags[s]]) { return true; }
+ }
+ return false;
+ });
+
+ // Lines or areas that don't match another feature filter.
+ // IMPORTANT: The 'others' feature must be the last one defined,
+ // so that code in getMatches can skip this test if `hasMatch = true`
+ defineRule('others', function isOther(tags, geometry) {
+ return (geometry === 'line' || geometry === 'area');
+ });
+
+
+
+ features.features = function() {
+ return _rules;
+ };
+
+
+ features.keys = function() {
+ return _keys;
+ };
+
+
+ features.enabled = function(k) {
+ if (!arguments.length) {
+ return _keys.filter(function(k) { return _rules[k].enabled; });
+ }
+ return _rules[k] && _rules[k].enabled;
+ };
+
+
+ features.disabled = function(k) {
+ if (!arguments.length) {
+ return _keys.filter(function(k) { return !_rules[k].enabled; });
+ }
+ return _rules[k] && !_rules[k].enabled;
+ };
+
+
+ features.hidden = function(k) {
+ if (!arguments.length) {
+ return _keys.filter(function(k) { return _rules[k].hidden(); });
+ }
+ return _rules[k] && _rules[k].hidden();
+ };
+
+
+ features.autoHidden = function(k) {
+ if (!arguments.length) {
+ return _keys.filter(function(k) { return _rules[k].autoHidden(); });
+ }
+ return _rules[k] && _rules[k].autoHidden();
+ };
+
+
+ features.enable = function(k) {
+ if (_rules[k] && !_rules[k].enabled) {
+ _rules[k].enable();
+ update();
+ }
+ };
+
+ features.enableAll = function() {
+ var didEnable = false;
+ for (var k in _rules) {
+ if (!_rules[k].enabled) {
+ didEnable = true;
+ _rules[k].enable();
+ }
+ }
+ if (didEnable) update();
+ };
+
+
+ features.disable = function(k) {
+ if (_rules[k] && _rules[k].enabled) {
+ _rules[k].disable();
+ update();
+ }
+ };
+
+ features.disableAll = function() {
+ var didDisable = false;
+ for (var k in _rules) {
+ if (_rules[k].enabled) {
+ didDisable = true;
+ _rules[k].disable();
+ }
+ }
+ if (didDisable) update();
+ };
+
+
+ features.toggle = function(k) {
+ if (_rules[k]) {
+ (function(f) { return f.enabled ? f.disable() : f.enable(); }(_rules[k]));
+ update();
+ }
+ };
+
+
+ features.resetStats = function() {
+ for (var i = 0; i < _keys.length; i++) {
+ _rules[_keys[i]].count = 0;
+ }
+ dispatch$1.call('change');
+ };
+
+
+ features.gatherStats = function(d, resolver, dimensions) {
+ var needsRedraw = false;
+ var types = utilArrayGroupBy(d, 'type');
+ var entities = [].concat(types.relation || [], types.way || [], types.node || []);
+ var currHidden, geometry, matches, i, j;
+
+ for (i = 0; i < _keys.length; i++) {
+ _rules[_keys[i]].count = 0;
+ }
+
+ // adjust the threshold for point/building culling based on viewport size..
+ // a _cullFactor of 1 corresponds to a 1000x1000px viewport..
+ _cullFactor = dimensions[0] * dimensions[1] / 1000000;
+
+ for (i = 0; i < entities.length; i++) {
+ geometry = entities[i].geometry(resolver);
+ matches = Object.keys(features.getMatches(entities[i], resolver, geometry));
+ for (j = 0; j < matches.length; j++) {
+ _rules[matches[j]].count++;
+ }
+ }
+
+ currHidden = features.hidden();
+ if (currHidden !== _hidden) {
+ _hidden = currHidden;
+ needsRedraw = true;
+ dispatch$1.call('change');
+ }
+
+ return needsRedraw;
+ };
+
+
+ features.stats = function() {
+ for (var i = 0; i < _keys.length; i++) {
+ _stats[_keys[i]] = _rules[_keys[i]].count;
+ }
+
+ return _stats;
+ };
+
+
+ features.clear = function(d) {
+ for (var i = 0; i < d.length; i++) {
+ features.clearEntity(d[i]);
+ }
+ };
+
+
+ features.clearEntity = function(entity) {
+ delete _cache[osmEntity.key(entity)];
+ };
+
+
+ features.reset = function() {
+ Array.from(_deferred).forEach(function(handle) {
+ window.cancelIdleCallback(handle);
+ _deferred.delete(handle);
+ });
+
+ _cache = {};
+ };
+
+ // only certain relations are worth checking
+ function relationShouldBeChecked(relation) {
+ // multipolygon features have `area` geometry and aren't checked here
+ return relation.tags.type === 'boundary';
+ }
+
+ features.getMatches = function(entity, resolver, geometry) {
+ if (geometry === 'vertex' ||
+ (geometry === 'relation' && !relationShouldBeChecked(entity))) return {};
+
+ var ent = osmEntity.key(entity);
+ if (!_cache[ent]) {
+ _cache[ent] = {};
+ }
+
+ if (!_cache[ent].matches) {
+ var matches = {};
+ var hasMatch = false;
+
+ for (var i = 0; i < _keys.length; i++) {
+ if (_keys[i] === 'others') {
+ if (hasMatch) continue;
+
+ // If an entity...
+ // 1. is a way that hasn't matched other 'interesting' feature rules,
+ if (entity.type === 'way') {
+ var parents = features.getParents(entity, resolver, geometry);
+
+ // 2a. belongs only to a single multipolygon relation
+ if ((parents.length === 1 && parents[0].isMultipolygon()) ||
+ // 2b. or belongs only to boundary relations
+ (parents.length > 0 && parents.every(function(parent) { return parent.tags.type === 'boundary'; }))) {
+
+ // ...then match whatever feature rules the parent relation has matched.
+ // see #2548, #2887
+ //
+ // IMPORTANT:
+ // For this to work, getMatches must be called on relations before ways.
+ //
+ var pkey = osmEntity.key(parents[0]);
+ if (_cache[pkey] && _cache[pkey].matches) {
+ matches = Object.assign({}, _cache[pkey].matches); // shallow copy
+ continue;
+ }
+ }
+ }
+ }
+
+ if (_rules[_keys[i]].filter(entity.tags, geometry)) {
+ matches[_keys[i]] = hasMatch = true;
+ }
+ }
+ _cache[ent].matches = matches;
+ }
+
+ return _cache[ent].matches;
+ };
+
+
+ features.getParents = function(entity, resolver, geometry) {
+ if (geometry === 'point') return [];
+
+ var ent = osmEntity.key(entity);
+ if (!_cache[ent]) {
+ _cache[ent] = {};
+ }
+
+ if (!_cache[ent].parents) {
+ var parents = [];
+ if (geometry === 'vertex') {
+ parents = resolver.parentWays(entity);
+ } else { // 'line', 'area', 'relation'
+ parents = resolver.parentRelations(entity);
+ }
+ _cache[ent].parents = parents;
+ }
+ return _cache[ent].parents;
+ };
+
+
+ features.isHiddenPreset = function(preset, geometry) {
+ if (!_hidden.length) return false;
+ if (!preset.tags) return false;
+
+ var test = preset.setTags({}, geometry);
+ for (var key in _rules) {
+ if (_rules[key].filter(test, geometry)) {
+ if (_hidden.indexOf(key) !== -1) {
+ return key;
+ }
+ return false;
+ }
+ }
+ return false;
+ };
+
+
+ features.isHiddenFeature = function(entity, resolver, geometry) {
+ if (!_hidden.length) return false;
+ if (!entity.version) return false;
+ if (_forceVisible[entity.id]) return false;
+
+ var matches = Object.keys(features.getMatches(entity, resolver, geometry));
+ return matches.length && matches.every(function(k) { return features.hidden(k); });
+ };
+
+
+ features.isHiddenChild = function(entity, resolver, geometry) {
+ if (!_hidden.length) return false;
+ if (!entity.version || geometry === 'point') return false;
+ if (_forceVisible[entity.id]) return false;
+
+ var parents = features.getParents(entity, resolver, geometry);
+ if (!parents.length) return false;
+
+ for (var i = 0; i < parents.length; i++) {
+ if (!features.isHidden(parents[i], resolver, parents[i].geometry(resolver))) {
+ return false;
+ }
+ }
+ return true;
+ };
+
+
+ features.hasHiddenConnections = function(entity, resolver) {
+ if (!_hidden.length) return false;
+
+ var childNodes, connections;
+ if (entity.type === 'midpoint') {
+ childNodes = [resolver.entity(entity.edge[0]), resolver.entity(entity.edge[1])];
+ connections = [];
+ } else {
+ childNodes = entity.nodes ? resolver.childNodes(entity) : [];
+ connections = features.getParents(entity, resolver, entity.geometry(resolver));
+ }
+
+ // gather ways connected to child nodes..
+ connections = childNodes.reduce(function(result, e) {
+ return resolver.isShared(e) ? utilArrayUnion(result, resolver.parentWays(e)) : result;
+ }, connections);
+
+ return connections.some(function(e) {
+ return features.isHidden(e, resolver, e.geometry(resolver));
+ });
+ };
+
+
+ features.isHidden = function(entity, resolver, geometry) {
+ if (!_hidden.length) return false;
+ if (!entity.version) return false;
+
+ var fn = (geometry === 'vertex' ? features.isHiddenChild : features.isHiddenFeature);
+ return fn(entity, resolver, geometry);
+ };
+
+
+ features.filter = function(d, resolver) {
+ if (!_hidden.length) return d;
+
+ var result = [];
+ for (var i = 0; i < d.length; i++) {
+ var entity = d[i];
+ if (!features.isHidden(entity, resolver, entity.geometry(resolver))) {
+ result.push(entity);
+ }
+ }
+ return result;
+ };
+
+
+ features.forceVisible = function(entityIDs) {
+ if (!arguments.length) return Object.keys(_forceVisible);
+
+ _forceVisible = {};
+ for (var i = 0; i < entityIDs.length; i++) {
+ _forceVisible[entityIDs[i]] = true;
+ var entity = context.hasEntity(entityIDs[i]);
+ if (entity && entity.type === 'relation') {
+ // also show relation members (one level deep)
+ for (var j in entity.members) {
+ _forceVisible[entity.members[j].id] = true;
+ }
+ }
+ }
+ return features;
+ };
+
+
+ features.init = function() {
+ var storage = corePreferences('disabled-features');
+ if (storage) {
+ var storageDisabled = storage.replace(/;/g, ',').split(',');
+ storageDisabled.forEach(features.disable);
+ }
+
+ var hash = utilStringQs(window.location.hash);
+ if (hash.disable_features) {
+ var hashDisabled = hash.disable_features.replace(/;/g, ',').split(',');
+ hashDisabled.forEach(features.disable);
+ }
+ };
+
+
+ // warm up the feature matching cache upon merging fetched data
+ context.history().on('merge.features', function(newEntities) {
+ if (!newEntities) return;
+ var handle = window.requestIdleCallback(function() {
+ var graph = context.graph();
+ var types = utilArrayGroupBy(newEntities, 'type');
+ // ensure that getMatches is called on relations before ways
+ var entities = [].concat(types.relation || [], types.way || [], types.node || []);
+ for (var i = 0; i < entities.length; i++) {
+ var geometry = entities[i].geometry(graph);
+ features.getMatches(entities[i], graph, geometry);
+ }
+ });
+ _deferred.add(handle);
+ });
+
+
+ return features;
+ }
+
+ function utilBindOnce(target, type, listener, capture) {
+ var typeOnce = type + '.once';
+ function one() {
+ target.on(typeOnce, null);
+ listener.apply(this, arguments);
+ }
+ target.on(typeOnce, one, capture);
+ return this;
+ }
+
+ // Adapted from d3-zoom to handle pointer events.
+
+ // Ignore right-click, since that should open the context menu.
+ function defaultFilter$2() {
+ return !event.ctrlKey && !event.button;
+ }
+
+ function defaultExtent$1() {
+ var e = this;
+ if (e instanceof SVGElement) {
+ e = e.ownerSVGElement || e;
+ if (e.hasAttribute('viewBox')) {
+ e = e.viewBox.baseVal;
+ return [[e.x, e.y], [e.x + e.width, e.y + e.height]];
+ }
+ return [[0, 0], [e.width.baseVal.value, e.height.baseVal.value]];
+ }
+ return [[0, 0], [e.clientWidth, e.clientHeight]];
+ }
+
+ function defaultWheelDelta$1() {
+ return -event.deltaY * (event.deltaMode === 1 ? 0.05 : event.deltaMode ? 1 : 0.002);
+ }
+
+ function defaultConstrain$1(transform, extent, translateExtent) {
+ var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
+ dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
+ dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
+ dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
+ return transform.translate(
+ dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
+ dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
+ );
+ }
+
+ function utilZoomPan() {
+ var filter = defaultFilter$2,
+ extent = defaultExtent$1,
+ constrain = defaultConstrain$1,
+ wheelDelta = defaultWheelDelta$1,
+ scaleExtent = [0, Infinity],
+ translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
+ interpolate = interpolateZoom,
+ listeners = dispatch('start', 'zoom', 'end'),
+ _wheelDelay = 150,
+ _transform = identity$2,
+ _activeGesture;
+
+ function zoom(selection) {
+ selection
+ .on('pointerdown.zoom', pointerdown)
+ .on('wheel.zoom', wheeled)
+ .style('touch-action', 'none')
+ .style('-webkit-tap-highlight-color', 'rgba(0,0,0,0)');
+
+ select(window)
+ .on('pointermove.zoompan', pointermove)
+ .on('pointerup.zoompan pointercancel.zoompan', pointerup);
+ }
+
+ zoom.transform = function(collection, transform, point) {
+ var selection = collection.selection ? collection.selection() : collection;
+ if (collection !== selection) {
+ schedule(collection, transform, point);
+ } else {
+ selection.interrupt().each(function() {
+ gesture(this, arguments)
+ .start()
+ .zoom(null, typeof transform === 'function' ? transform.apply(this, arguments) : transform)
+ .end();
+ });
+ }
+ };
+
+ zoom.scaleBy = function(selection, k, p) {
+ zoom.scaleTo(selection, function() {
+ var k0 = _transform.k,
+ k1 = typeof k === 'function' ? k.apply(this, arguments) : k;
+ return k0 * k1;
+ }, p);
+ };
+
+ zoom.scaleTo = function(selection, k, p) {
+ zoom.transform(selection, function() {
+ var e = extent.apply(this, arguments),
+ t0 = _transform,
+ p0 = p == null ? centroid(e) : typeof p === 'function' ? p.apply(this, arguments) : p,
+ p1 = t0.invert(p0),
+ k1 = typeof k === 'function' ? k.apply(this, arguments) : k;
+ return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
+ }, p);
+ };
+
+ zoom.translateBy = function(selection, x, y) {
+ zoom.transform(selection, function() {
+ return constrain(_transform.translate(
+ typeof x === 'function' ? x.apply(this, arguments) : x,
+ typeof y === 'function' ? y.apply(this, arguments) : y
+ ), extent.apply(this, arguments), translateExtent);
+ });
+ };
+
+ zoom.translateTo = function(selection, x, y, p) {
+ zoom.transform(selection, function() {
+ var e = extent.apply(this, arguments),
+ t = _transform,
+ p0 = p == null ? centroid(e) : typeof p === 'function' ? p.apply(this, arguments) : p;
+ return constrain(identity$2.translate(p0[0], p0[1]).scale(t.k).translate(
+ typeof x === 'function' ? -x.apply(this, arguments) : -x,
+ typeof y === 'function' ? -y.apply(this, arguments) : -y
+ ), e, translateExtent);
+ }, p);
+ };
+
+ function scale(transform, k) {
+ k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
+ return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
+ }
+
+ function translate(transform, p0, p1) {
+ var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
+ return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
+ }
+
+ function centroid(extent) {
+ return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
+ }
+
+ function schedule(transition, transform, point) {
+ transition
+ .on('start.zoom', function() { gesture(this, arguments).start(); })
+ .on('interrupt.zoom end.zoom', function() { gesture(this, arguments).end(); })
+ .tween('zoom', function() {
+ var that = this,
+ args = arguments,
+ g = gesture(that, args),
+ e = extent.apply(that, args),
+ p = point == null ? centroid(e) : typeof point === 'function' ? point.apply(that, args) : point,
+ w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
+ a = _transform,
+ b = typeof transform === 'function' ? transform.apply(that, args) : transform,
+ i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
+ return function(t) {
+ if (t === 1) t = b; // Avoid rounding error on end.
+ else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
+ g.zoom(null, t);
+ };
+ });
+ }
+
+ function gesture(that, args, clean) {
+ return (!clean && _activeGesture) || new Gesture(that, args);
+ }
+
+ function Gesture(that, args) {
+ this.that = that;
+ this.args = args;
+ this.active = 0;
+ this.extent = extent.apply(that, args);
+ }
+
+ Gesture.prototype = {
+ start: function() {
+ if (++this.active === 1) {
+ _activeGesture = this;
+ this.emit('start');
+ }
+ return this;
+ },
+ zoom: function(key, transform) {
+ if (this.mouse && key !== 'mouse') this.mouse[1] = transform.invert(this.mouse[0]);
+ if (this.pointer0 && key !== 'touch') this.pointer0[1] = transform.invert(this.pointer0[0]);
+ if (this.pointer1 && key !== 'touch') this.pointer1[1] = transform.invert(this.pointer1[0]);
+ _transform = transform;
+ this.emit('zoom');
+ return this;
+ },
+ end: function() {
+ if (--this.active === 0) {
+ _activeGesture = null;
+ this.emit('end');
+ }
+ return this;
+ },
+ emit: function(type) {
+ customEvent(new ZoomEvent(zoom, type, _transform), listeners.apply, listeners, [type, this.that, this.args]);
+ }
+ };
+
+ function wheeled() {
+ if (!filter.apply(this, arguments)) return;
+ var g = gesture(this, arguments),
+ t = _transform,
+ k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
+ p = utilFastMouse(this)(event);
+
+ // If the mouse is in the same location as before, reuse it.
+ // If there were recent wheel events, reset the wheel idle timeout.
+ if (g.wheel) {
+ if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
+ g.mouse[1] = t.invert(g.mouse[0] = p);
+ }
+ clearTimeout(g.wheel);
+
+ // Otherwise, capture the mouse point and location at the start.
+ } else {
+ g.mouse = [p, t.invert(p)];
+ interrupt(this);
+ g.start();
+ }
+
+ event.preventDefault();
+ event.stopImmediatePropagation();
+ g.wheel = setTimeout(wheelidled, _wheelDelay);
+ g.zoom('mouse', constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
+
+ function wheelidled() {
+ g.wheel = null;
+ g.end();
+ }
+ }
+
+ var _downPointerIDs = new Set();
+ var _pointerLocGetter;
+
+ function pointerdown() {
+ _downPointerIDs.add(event.pointerId);
+
+ if (!filter.apply(this, arguments)) return;
+
+ var g = gesture(this, arguments, _downPointerIDs.size === 1);
+ var started;
+
+ event.stopImmediatePropagation();
+ _pointerLocGetter = utilFastMouse(this);
+ var loc = _pointerLocGetter(event);
+ var p = [loc, _transform.invert(loc), event.pointerId];
+ if (!g.pointer0) {
+ g.pointer0 = p;
+ started = true;
+
+ } else if (!g.pointer1 && g.pointer0[2] !== p[2]) {
+ g.pointer1 = p;
+ }
+
+ if (started) {
+ interrupt(this);
+ g.start();
+ }
+ }
+
+ function pointermove() {
+ if (!_downPointerIDs.has(event.pointerId)) return;
+
+ if (!_activeGesture || !_pointerLocGetter) return;
+
+ var g = gesture(this, arguments);
+
+ var isPointer0 = g.pointer0 && g.pointer0[2] === event.pointerId;
+ var isPointer1 = !isPointer0 && g.pointer1 && g.pointer1[2] === event.pointerId;
+
+ if ((isPointer0 || isPointer1) && 'buttons' in event && !event.buttons) {
+ // The pointer went up without ending the gesture somehow, e.g.
+ // a down mouse was moved off the map and released. End it here.
+ if (g.pointer0) _downPointerIDs.delete(g.pointer0[2]);
+ if (g.pointer1) _downPointerIDs.delete(g.pointer1[2]);
+ g.end();
+ return;
+ }
+
+ event.preventDefault();
+ event.stopImmediatePropagation();
+
+ var loc = _pointerLocGetter(event);
+ var t, p, l;
+
+ if (isPointer0) g.pointer0[0] = loc;
+ else if (isPointer1) g.pointer1[0] = loc;
+
+ t = _transform;
+ if (g.pointer1) {
+ var p0 = g.pointer0[0], l0 = g.pointer0[1],
+ p1 = g.pointer1[0], l1 = g.pointer1[1],
+ dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
+ dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
+ t = scale(t, Math.sqrt(dp / dl));
+ p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
+ l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
+ } else if (g.pointer0) {
+ p = g.pointer0[0];
+ l = g.pointer0[1];
+ }
+ else return;
+ g.zoom('touch', constrain(translate(t, p, l), g.extent, translateExtent));
+ }
+
+ function pointerup() {
+ if (!_downPointerIDs.has(event.pointerId)) return;
+
+ _downPointerIDs.delete(event.pointerId);
+
+ if (!_activeGesture) return;
+
+ var g = gesture(this, arguments);
+
+ event.stopImmediatePropagation();
+
+ if (g.pointer0 && g.pointer0[2] === event.pointerId) delete g.pointer0;
+ else if (g.pointer1 && g.pointer1[2] === event.pointerId) delete g.pointer1;
+
+ if (g.pointer1 && !g.pointer0) {
+ g.pointer0 = g.pointer1;
+ delete g.pointer1;
+ }
+ if (g.pointer0) g.pointer0[1] = _transform.invert(g.pointer0[0]);
+ else {
+ g.end();
+ }
+ }
+
+ zoom.wheelDelta = function(_) {
+ return arguments.length ? (wheelDelta = utilFunctor(+_), zoom) : wheelDelta;
+ };
+
+ zoom.filter = function(_) {
+ return arguments.length ? (filter = utilFunctor(!!_), zoom) : filter;
+ };
+
+ zoom.extent = function(_) {
+ return arguments.length ? (extent = utilFunctor([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
+ };
+
+ zoom.scaleExtent = function(_) {
+ return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
+ };
+
+ zoom.translateExtent = function(_) {
+ return arguments.length ? (translateExtent[0][0] = +_[0][0], translateExtent[1][0] = +_[1][0], translateExtent[0][1] = +_[0][1], translateExtent[1][1] = +_[1][1], zoom) : [[translateExtent[0][0], translateExtent[0][1]], [translateExtent[1][0], translateExtent[1][1]]];
+ };
+
+ zoom.constrain = function(_) {
+ return arguments.length ? (constrain = _, zoom) : constrain;
+ };
+
+ zoom.interpolate = function(_) {
+ return arguments.length ? (interpolate = _, zoom) : interpolate;
+ };
+
+ zoom._transform = function(_) {
+ return arguments.length ? (_transform = _, zoom) : _transform;
+ };
+
+ zoom.on = function() {
+ var value = listeners.on.apply(listeners, arguments);
+ return value === listeners ? zoom : value;
+ };
+
+ return zoom;
+ }
+
+ // A custom double-click / double-tap event detector that works on touch devices
+ // if pointer events are supported. Falls back to default `dblclick` event.
+ function utilDoubleUp() {
+
+ var dispatch$1 = dispatch('doubleUp');
+
+ var _maxTimespan = 500; // milliseconds
+ var _maxDistance = 20; // web pixels; be somewhat generous to account for touch devices
+ var _pointer; // object representing the pointer that could trigger double up
+
+ function pointerIsValidFor(loc) {
+ // second pointerup must occur within a small timeframe after the first pointerdown
+ return new Date().getTime() - _pointer.startTime <= _maxTimespan &&
+ // all pointer events must occur within a small distance of the first pointerdown
+ geoVecLength(_pointer.startLoc, loc) <= _maxDistance;
+ }
+
+ function pointerdown() {
+
+ // ignore right-click
+ if (event.ctrlKey || event.button === 2) return;
+
+ var loc = [event.clientX, event.clientY];
+
+ // Don't rely on pointerId here since it can change between pointerdown
+ // events on touch devices
+ if (_pointer && !pointerIsValidFor(loc)) {
+ // if this pointer is no longer valid, clear it so another can be started
+ _pointer = undefined;
+ }
+
+ if (!_pointer) {
+ _pointer = {
+ startLoc: loc,
+ startTime: new Date().getTime(),
+ upCount: 0,
+ pointerId: event.pointerId
+ };
+ } else { // double down
+ _pointer.pointerId = event.pointerId;
+ }
+ }
+
+ function pointerup() {
+
+ // ignore right-click
+ if (event.ctrlKey || event.button === 2) return;
+
+ if (!_pointer || _pointer.pointerId !== event.pointerId) return;
+
+ _pointer.upCount += 1;
+
+ if (_pointer.upCount === 2) { // double up!
+ var loc = [event.clientX, event.clientY];
+ if (pointerIsValidFor(loc)) {
+ var locInThis = utilFastMouse(this)(event);
+ dispatch$1.call('doubleUp', this, locInThis);
+ }
+ // clear the pointer info in any case
+ _pointer = undefined;
+ }
+ }
+
+ function doubleUp(selection) {
+ if ('PointerEvent' in window) {
+ // dblclick isn't well supported on touch devices so manually use
+ // pointer events if they're available
+ selection
+ .on('pointerdown.doubleUp', pointerdown)
+ .on('pointerup.doubleUp', pointerup);
+ } else {
+ // fallback to dblclick
+ selection
+ .on('dblclick.doubleUp', function() {
+ dispatch$1.call('doubleUp', this, utilFastMouse(this)(event));
+ });
+ }
+ }
+
+ doubleUp.off = function(selection) {
+ selection
+ .on('pointerdown.doubleUp', null)
+ .on('pointerup.doubleUp', null)
+ .on('dblclick.doubleUp', null);
+ };
+
+ return utilRebind(doubleUp, dispatch$1, 'on');
+ }
+
+ // constants
+ var TILESIZE = 256;
+ var minZoom = 2;
+ var maxZoom = 24;
+ var kMin = geoZoomToScale(minZoom, TILESIZE);
+ var kMax = geoZoomToScale(maxZoom, TILESIZE);
+
+ function clamp$1(num, min, max) {
+ return Math.max(min, Math.min(num, max));
+ }
+
+
+ function rendererMap(context) {
+ var dispatch$1 = dispatch(
+ 'move', 'drawn',
+ 'crossEditableZoom', 'hitMinZoom',
+ 'changeHighlighting', 'changeAreaFill'
+ );
+ var projection = context.projection;
+ var curtainProjection = context.curtainProjection;
+ var drawLayers;
+ var drawPoints;
+ var drawVertices;
+ var drawLines;
+ var drawAreas;
+ var drawMidpoints;
+ var drawLabels;
+
+ var _selection = select(null);
+ var supersurface = select(null);
+ var wrapper = select(null);
+ var surface = select(null);
+
+ var _dimensions = [1, 1];
+ var _dblClickZoomEnabled = true;
+ var _redrawEnabled = true;
+ var _gestureTransformStart;
+ var _transformStart = projection.transform();
+ var _transformLast;
+ var _isTransformed = false;
+ var _minzoom = 0;
+ var _getMouseCoords;
+ var _lastPointerEvent;
+ var _lastWithinEditableZoom;
+
+ // whether a pointerdown event started the zoom
+ var _pointerDown = false;
+
+ // use pointer events on supported platforms; fallback to mouse events
+ var _pointerPrefix = 'PointerEvent' in window ? 'pointer' : 'mouse';
+
+ // use pointer event interaction if supported; fallback to touch/mouse events in d3-zoom
+ var _zoomerPannerFunction = 'PointerEvent' in window ? utilZoomPan : d3_zoom;
+
+ var _zoomerPanner = _zoomerPannerFunction()
+ .scaleExtent([kMin, kMax])
+ .interpolate(interpolate)
+ .filter(zoomEventFilter)
+ .on('zoom.map', zoomPan)
+ .on('start.map', function() {
+ _pointerDown = event.sourceEvent && event.sourceEvent.type === 'pointerdown';
+ })
+ .on('end.map', function() {
+ _pointerDown = false;
+ });
+ var _doubleUpHandler = utilDoubleUp();
+
+ var scheduleRedraw = throttle(redraw, 750);
+ // var isRedrawScheduled = false;
+ // var pendingRedrawCall;
+ // function scheduleRedraw() {
+ // // Only schedule the redraw if one has not already been set.
+ // if (isRedrawScheduled) return;
+ // isRedrawScheduled = true;
+ // var that = this;
+ // var args = arguments;
+ // pendingRedrawCall = window.requestIdleCallback(function () {
+ // // Reset the boolean so future redraws can be set.
+ // isRedrawScheduled = false;
+ // redraw.apply(that, args);
+ // }, { timeout: 1400 });
+ // }
+
+ function cancelPendingRedraw() {
+ scheduleRedraw.cancel();
+ // isRedrawScheduled = false;
+ // window.cancelIdleCallback(pendingRedrawCall);
+ }
+
+
+ function map(selection) {
+ _selection = selection;
+
+ context
+ .on('change.map', immediateRedraw);
+
+ var osm = context.connection();
+ if (osm) {
+ osm.on('change.map', immediateRedraw);
+ }
+
+ function didUndoOrRedo(targetTransform) {
+ var mode = context.mode().id;
+ if (mode !== 'browse' && mode !== 'select') return;
+ if (targetTransform) {
+ map.transformEase(targetTransform);
+ }
+ }
+
+ context.history()
+ .on('merge.map', function() { scheduleRedraw(); })
+ .on('change.map', immediateRedraw)
+ .on('undone.map', function(stack, fromStack) {
+ didUndoOrRedo(fromStack.transform);
+ })
+ .on('redone.map', function(stack) {
+ didUndoOrRedo(stack.transform);
+ });
+
+ context.background()
+ .on('change.map', immediateRedraw);
+
+ context.features()
+ .on('redraw.map', immediateRedraw);
+
+ drawLayers
+ .on('change.map', function() {
+ context.background().updateImagery();
+ immediateRedraw();
+ });
+
+ selection
+ .on('wheel.map mousewheel.map', function() {
+ // disable swipe-to-navigate browser pages on trackpad/magic mouse – #5552
+ event.preventDefault();
+ })
+ .call(_zoomerPanner)
+ .call(_zoomerPanner.transform, projection.transform())
+ .on('dblclick.zoom', null); // override d3-zoom dblclick handling
+
+ map.supersurface = supersurface = selection.append('div')
+ .attr('class', 'supersurface')
+ .call(utilSetTransform, 0, 0);
+
+ // Need a wrapper div because Opera can't cope with an absolutely positioned
+ // SVG element: http://bl.ocks.org/jfirebaugh/6fbfbd922552bf776c16
+ wrapper = supersurface
+ .append('div')
+ .attr('class', 'layer layer-data');
+
+ map.surface = surface = wrapper
+ .call(drawLayers)
+ .selectAll('.surface');
+
+ surface
+ .call(drawLabels.observe)
+ .call(_doubleUpHandler)
+ .on(_pointerPrefix + 'down.zoom', function() {
+ _lastPointerEvent = event;
+ if (event.button === 2) {
+ event.stopPropagation();
+ }
+ }, true)
+ .on(_pointerPrefix + 'up.zoom', function() {
+ _lastPointerEvent = event;
+ if (resetTransform()) {
+ immediateRedraw();
+ }
+ })
+ .on(_pointerPrefix + 'move.map', function() {
+ _lastPointerEvent = event;
+ })
+ .on(_pointerPrefix + 'over.vertices', function() {
+ if (map.editableDataEnabled() && !_isTransformed) {
+ var hover = event.target.__data__;
+ surface.call(drawVertices.drawHover, context.graph(), hover, map.extent());
+ dispatch$1.call('drawn', this, { full: false });
+ }
+ })
+ .on(_pointerPrefix + 'out.vertices', function() {
+ if (map.editableDataEnabled() && !_isTransformed) {
+ var hover = event.relatedTarget && event.relatedTarget.__data__;
+ surface.call(drawVertices.drawHover, context.graph(), hover, map.extent());
+ dispatch$1.call('drawn', this, { full: false });
+ }
+ });
+
+ var detected = utilDetect();
+
+ // only WebKit supports gesture events
+ if ('GestureEvent' in window &&
+ // Listening for gesture events on iOS 13.4+ breaks double-tapping,
+ // but we only need to do this on desktop Safari anyway. – #7694
+ !detected.isMobileWebKit) {
+
+ // Desktop Safari sends gesture events for multitouch trackpad pinches.
+ // We can listen for these and translate them into map zooms.
+ surface
+ .on('gesturestart.surface', function() {
+ event.preventDefault();
+ _gestureTransformStart = projection.transform();
+ })
+ .on('gesturechange.surface', gestureChange);
+ }
+
+ // must call after surface init
+ updateAreaFill();
+
+ _doubleUpHandler.on('doubleUp.map', function(p0) {
+ if (!_dblClickZoomEnabled) return;
+
+ // don't zoom if targeting something other than the map itself
+ if (typeof event.target.__data__ === 'object' &&
+ // or area fills
+ !select(event.target).classed('fill')) return;
+
+ var zoomOut = event.shiftKey;
+
+ var t = projection.transform();
+
+ var p1 = t.invert(p0);
+
+ t = t.scale(zoomOut ? 0.5 : 2);
+
+ t.x = p0[0] - p1[0] * t.k;
+ t.y = p0[1] - p1[1] * t.k;
+
+ map.transformEase(t);
+ });
+
+ context.on('enter.map', function() {
+ if (!map.editableDataEnabled(true /* skip zoom check */)) return;
+
+ // redraw immediately any objects affected by a change in selectedIDs.
+ var graph = context.graph();
+ var selectedAndParents = {};
+ context.selectedIDs().forEach(function(id) {
+ var entity = graph.hasEntity(id);
+ if (entity) {
+ selectedAndParents[entity.id] = entity;
+ if (entity.type === 'node') {
+ graph.parentWays(entity).forEach(function(parent) {
+ selectedAndParents[parent.id] = parent;
+ });
+ }
+ }
+ });
+ var data = Object.values(selectedAndParents);
+ var filter = function(d) { return d.id in selectedAndParents; };
+
+ data = context.features().filter(data, graph);
+
+ surface
+ .call(drawVertices.drawSelected, graph, map.extent())
+ .call(drawLines, graph, data, filter)
+ .call(drawAreas, graph, data, filter)
+ .call(drawMidpoints, graph, data, filter, map.trimmedExtent());
+
+ dispatch$1.call('drawn', this, { full: false });
+
+ // redraw everything else later
+ scheduleRedraw();
+ });
+
+ map.dimensions(utilGetDimensions(selection));
+ }
+
+
+ function zoomEventFilter() {
+ // Fix for #2151, (see also d3/d3-zoom#60, d3/d3-brush#18)
+ // Intercept `mousedown` and check if there is an orphaned zoom gesture.
+ // This can happen if a previous `mousedown` occurred without a `mouseup`.
+ // If we detect this, dispatch `mouseup` to complete the orphaned gesture,
+ // so that d3-zoom won't stop propagation of new `mousedown` events.
+ if (event.type === 'mousedown') {
+ var hasOrphan = false;
+ var listeners = window.__on;
+ for (var i = 0; i < listeners.length; i++) {
+ var listener = listeners[i];
+ if (listener.name === 'zoom' && listener.type === 'mouseup') {
+ hasOrphan = true;
+ break;
+ }
+ }
+ if (hasOrphan) {
+ var event$1 = window.CustomEvent;
+ if (event$1) {
+ event$1 = new event$1('mouseup');
+ } else {
+ event$1 = window.document.createEvent('Event');
+ event$1.initEvent('mouseup', false, false);
+ }
+ // Event needs to be dispatched with an event.view property.
+ event$1.view = window;
+ window.dispatchEvent(event$1);
+ }
+ }
+
+ return event.button !== 2; // ignore right clicks
+ }
+
+
+ function pxCenter() {
+ return [_dimensions[0] / 2, _dimensions[1] / 2];
+ }
+
+
+ function drawEditable(difference, extent) {
+ var mode = context.mode();
+ var graph = context.graph();
+ var features = context.features();
+ var all = context.history().intersects(map.extent());
+ var fullRedraw = false;
+ var data;
+ var set;
+ var filter;
+ var applyFeatureLayerFilters = true;
+
+ if (map.isInWideSelection()) {
+ data = [];
+ utilEntityAndDeepMemberIDs(mode.selectedIDs(), context.graph()).forEach(function(id) {
+ var entity = context.hasEntity(id);
+ if (entity) data.push(entity);
+ });
+ fullRedraw = true;
+ filter = utilFunctor(true);
+ // selected features should always be visible, so we can skip filtering
+ applyFeatureLayerFilters = false;
+
+ } else if (difference) {
+ var complete = difference.complete(map.extent());
+ data = Object.values(complete).filter(Boolean);
+ set = new Set(Object.keys(complete));
+ filter = function(d) { return set.has(d.id); };
+ features.clear(data);
+
+ } else {
+ // force a full redraw if gatherStats detects that a feature
+ // should be auto-hidden (e.g. points or buildings)..
+ if (features.gatherStats(all, graph, _dimensions)) {
+ extent = undefined;
+ }
+
+ if (extent) {
+ data = context.history().intersects(map.extent().intersection(extent));
+ set = new Set(data.map(function(entity) { return entity.id; }));
+ filter = function(d) { return set.has(d.id); };
+
+ } else {
+ data = all;
+ fullRedraw = true;
+ filter = utilFunctor(true);
+ }
+ }
+
+ if (applyFeatureLayerFilters) {
+ data = features.filter(data, graph);
+ } else {
+ context.features().resetStats();
+ }
+
+ if (mode && mode.id === 'select') {
+ // update selected vertices - the user might have just double-clicked a way,
+ // creating a new vertex, triggering a partial redraw without a mode change
+ surface.call(drawVertices.drawSelected, graph, map.extent());
+ }
+
+ surface
+ .call(drawVertices, graph, data, filter, map.extent(), fullRedraw)
+ .call(drawLines, graph, data, filter)
+ .call(drawAreas, graph, data, filter)
+ .call(drawMidpoints, graph, data, filter, map.trimmedExtent())
+ .call(drawLabels, graph, data, filter, _dimensions, fullRedraw)
+ .call(drawPoints, graph, data, filter);
+
+ dispatch$1.call('drawn', this, {full: true});
+ }
+
+ map.init = function() {
+ drawLayers = svgLayers(projection, context);
+ drawPoints = svgPoints(projection, context);
+ drawVertices = svgVertices(projection, context);
+ drawLines = svgLines(projection, context);
+ drawAreas = svgAreas(projection, context);
+ drawMidpoints = svgMidpoints(projection, context);
+ drawLabels = svgLabels(projection, context);
+ };
+
+ function editOff() {
+ context.features().resetStats();
+ surface.selectAll('.layer-osm *').remove();
+ surface.selectAll('.layer-touch:not(.markers) *').remove();
+
+ var allowed = {
+ 'browse': true,
+ 'save': true,
+ 'select-note': true,
+ 'select-data': true,
+ 'select-error': true
+ };
+
+ var mode = context.mode();
+ if (mode && !allowed[mode.id]) {
+ context.enter(modeBrowse(context));
+ }
+
+ dispatch$1.call('drawn', this, {full: true});
+ }
+
+
+
+
+
+ function gestureChange() {
+ // Remap Safari gesture events to wheel events - #5492
+ // We want these disabled most places, but enabled for zoom/unzoom on map surface
+ // https://developer.mozilla.org/en-US/docs/Web/API/GestureEvent
+ var e = event;
+ e.preventDefault();
+
+ var props = {
+ deltaMode: 0, // dummy values to ignore in zoomPan
+ deltaY: 1, // dummy values to ignore in zoomPan
+ clientX: e.clientX,
+ clientY: e.clientY,
+ screenX: e.screenX,
+ screenY: e.screenY,
+ x: e.x,
+ y: e.y
+ };
+
+ var e2 = new WheelEvent('wheel', props);
+ e2._scale = e.scale; // preserve the original scale
+ e2._rotation = e.rotation; // preserve the original rotation
+
+ _selection.node().dispatchEvent(e2);
+ }
+
+
+ function zoomPan(manualEvent) {
+ var event$1 = (manualEvent || event);
+ var source = event$1.sourceEvent;
+ var eventTransform = event$1.transform;
+ var x = eventTransform.x;
+ var y = eventTransform.y;
+ var k = eventTransform.k;
+
+ // Special handling of 'wheel' events:
+ // They might be triggered by the user scrolling the mouse wheel,
+ // or 2-finger pinch/zoom gestures, the transform may need adjustment.
+ if (source && source.type === 'wheel') {
+
+ // assume that the gesture is already handled by pointer events
+ if (_pointerDown) return;
+
+ var detected = utilDetect();
+ var dX = source.deltaX;
+ var dY = source.deltaY;
+ var x2 = x;
+ var y2 = y;
+ var k2 = k;
+ var t0, p0, p1;
+
+ // Normalize mousewheel scroll speed (Firefox) - #3029
+ // If wheel delta is provided in LINE units, recalculate it in PIXEL units
+ // We are essentially redoing the calculations that occur here:
+ // https://github.com/d3/d3-zoom/blob/78563a8348aa4133b07cac92e2595c2227ca7cd7/src/zoom.js#L203
+ // See this for more info:
+ // https://github.com/basilfx/normalize-wheel/blob/master/src/normalizeWheel.js
+ if (source.deltaMode === 1 /* LINE */) {
+ // Convert from lines to pixels, more if the user is scrolling fast.
+ // (I made up the exp function to roughly match Firefox to what Chrome does)
+ // These numbers should be floats, because integers are treated as pan gesture below.
+ var lines = Math.abs(source.deltaY);
+ var sign = (source.deltaY > 0) ? 1 : -1;
+ dY = sign * clamp$1(
+ Math.exp((lines - 1) * 0.75) * 4.000244140625,
+ 4.000244140625, // min
+ 350.000244140625 // max
+ );
+
+ // On Firefox Windows and Linux we always get +/- the scroll line amount (default 3)
+ // There doesn't seem to be any scroll accelleration.
+ // This multiplier increases the speed a little bit - #5512
+ if (detected.os !== 'mac') {
+ dY *= 5;
+ }
+
+ // recalculate x2,y2,k2
+ t0 = _isTransformed ? _transformLast : _transformStart;
+ p0 = _getMouseCoords(source);
+ p1 = t0.invert(p0);
+ k2 = t0.k * Math.pow(2, -dY / 500);
+ k2 = clamp$1(k2, kMin, kMax);
+ x2 = p0[0] - p1[0] * k2;
+ y2 = p0[1] - p1[1] * k2;
+
+ // 2 finger map pinch zooming (Safari) - #5492
+ // These are fake `wheel` events we made from Safari `gesturechange` events..
+ } else if (source._scale) {
+ // recalculate x2,y2,k2
+ t0 = _gestureTransformStart;
+ p0 = _getMouseCoords(source);
+ p1 = t0.invert(p0);
+ k2 = t0.k * source._scale;
+ k2 = clamp$1(k2, kMin, kMax);
+ x2 = p0[0] - p1[0] * k2;
+ y2 = p0[1] - p1[1] * k2;
+
+ // 2 finger map pinch zooming (all browsers except Safari) - #5492
+ // Pinch zooming via the `wheel` event will always have:
+ // - `ctrlKey = true`
+ // - `deltaY` is not round integer pixels (ignore `deltaX`)
+ } else if (source.ctrlKey && !isInteger(dY)) {
+ dY *= 6; // slightly scale up whatever the browser gave us
+
+ // recalculate x2,y2,k2
+ t0 = _isTransformed ? _transformLast : _transformStart;
+ p0 = _getMouseCoords(source);
+ p1 = t0.invert(p0);
+ k2 = t0.k * Math.pow(2, -dY / 500);
+ k2 = clamp$1(k2, kMin, kMax);
+ x2 = p0[0] - p1[0] * k2;
+ y2 = p0[1] - p1[1] * k2;
+
+ // Trackpad scroll zooming with shift or alt/option key down
+ } else if ((source.altKey || source.shiftKey) && isInteger(dY)) {
+ // recalculate x2,y2,k2
+ t0 = _isTransformed ? _transformLast : _transformStart;
+ p0 = _getMouseCoords(source);
+ p1 = t0.invert(p0);
+ k2 = t0.k * Math.pow(2, -dY / 500);
+ k2 = clamp$1(k2, kMin, kMax);
+ x2 = p0[0] - p1[0] * k2;
+ y2 = p0[1] - p1[1] * k2;
+
+ // 2 finger map panning (Mac only, all browsers) - #5492, #5512
+ // Panning via the `wheel` event will always have:
+ // - `ctrlKey = false`
+ // - `deltaX`,`deltaY` are round integer pixels
+ } else if (detected.os === 'mac' && !source.ctrlKey && isInteger(dX) && isInteger(dY)) {
+ p1 = projection.translate();
+ x2 = p1[0] - dX;
+ y2 = p1[1] - dY;
+ k2 = projection.scale();
+ k2 = clamp$1(k2, kMin, kMax);
+ }
+
+ // something changed - replace the event transform
+ if (x2 !== x || y2 !== y || k2 !== k) {
+ x = x2;
+ y = y2;
+ k = k2;
+ eventTransform = identity$2.translate(x2, y2).scale(k2);
+ if (_zoomerPanner._transform) {
+ // utilZoomPan interface
+ _zoomerPanner._transform(eventTransform);
+ } else {
+ // d3_zoom interface
+ _selection.node().__zoom = eventTransform;
+ }
+ }
+
+ }
+
+ if (_transformStart.x === x &&
+ _transformStart.y === y &&
+ _transformStart.k === k) {
+ return; // no change
+ }
+
+ var withinEditableZoom = map.withinEditableZoom();
+ if (_lastWithinEditableZoom !== withinEditableZoom) {
+ if (_lastWithinEditableZoom !== undefined) {
+ // notify that the map zoomed in or out over the editable zoom threshold
+ dispatch$1.call('crossEditableZoom', this, withinEditableZoom);
+ }
+ _lastWithinEditableZoom = withinEditableZoom;
+ }
+
+ if (geoScaleToZoom(k, TILESIZE) < _minzoom) {
+ surface.interrupt();
+ dispatch$1.call('hitMinZoom', this, map);
+ setCenterZoom(map.center(), context.minEditableZoom(), 0, true);
+ scheduleRedraw();
+ dispatch$1.call('move', this, map);
+ return;
+ }
+
+ projection.transform(eventTransform);
+
+ var scale = k / _transformStart.k;
+ var tX = (x / scale - _transformStart.x) * scale;
+ var tY = (y / scale - _transformStart.y) * scale;
+
+ if (context.inIntro()) {
+ curtainProjection.transform({
+ x: x - tX,
+ y: y - tY,
+ k: k
+ });
+ }
+
+ if (source) {
+ _lastPointerEvent = event$1;
+ }
+ _isTransformed = true;
+ _transformLast = eventTransform;
+ utilSetTransform(supersurface, tX, tY, scale);
+ scheduleRedraw();
+
+ dispatch$1.call('move', this, map);
+
+
+ function isInteger(val) {
+ return typeof val === 'number' && isFinite(val) && Math.floor(val) === val;
+ }
+ }
+
+
+ function resetTransform() {
+ if (!_isTransformed) return false;
+
+ utilSetTransform(supersurface, 0, 0);
+ _isTransformed = false;
+ if (context.inIntro()) {
+ curtainProjection.transform(projection.transform());
+ }
+ return true;
+ }
+
+
+ function drawMapGrid() {
+ // Add bounding box to imported OSM file layer
+ var d3Path = d3_geoPath(projection),
+ mapBoundsExtent = context.rapidContext().getTaskExtent();
+ var minlat = mapBoundsExtent[0][1],
+ minlon = mapBoundsExtent[0][0],
+ maxlat = mapBoundsExtent[1][1],
+ maxlon = mapBoundsExtent[1][0],
+ numGridSplits = context.background().numGridSplits();
+
+ var gridsSvg = surface.selectAll('.grids-svg')
+ .data([0]);
+
+ // Since there is no z-order within an svg,
+ // and we want the grid to appear on top of everything else,
+ // insert(), not append(), it at the start of the data layer.
+ gridsSvg.enter()
+ .insert('svg', ':first-child')
+ .attr('class', 'grids-svg');
+
+ gridsSvg.exit()
+ .remove();
+
+ var gridsData = [];
+
+ for (var i = 1; i < numGridSplits; i++) {
+ var midlon = minlon + (maxlon - minlon) * i / numGridSplits,
+ midlat = minlat + (maxlat - minlat) * i / numGridSplits;
+ gridsData.push({
+ type: 'LineString',
+ coordinates:[[midlon, minlat], [midlon, maxlat]]
+ });
+ gridsData.push({
+ type: 'LineString',
+ coordinates:[[minlon, midlat], [maxlon, midlat]]
+ });
+ }
+
+ var gridsPath = gridsSvg.selectAll('.map-grids')
+ .data(gridsData);
+
+ gridsPath.attr('d', d3Path);
+
+ gridsPath.enter()
+ .append('path')
+ .attr('class', 'map-grids')
+ .attr('d', d3Path);
+
+ gridsPath.exit()
+ .remove();
+ }
+
+
+ function redraw(difference, extent) {
+ if (surface.empty() || !_redrawEnabled) return;
+
+ // If we are in the middle of a zoom/pan, we can't do differenced redraws.
+ // It would result in artifacts where differenced entities are redrawn with
+ // one transform and unchanged entities with another.
+ if (resetTransform()) {
+ difference = extent = undefined;
+ }
+
+ var zoom = map.zoom();
+ var z = String(~~zoom);
+
+ if (surface.attr('data-zoom') !== z) {
+ surface.attr('data-zoom', z);
+ }
+
+ // class surface as `lowzoom` around z17-z18.5 (based on latitude)
+ var lat = map.center()[1];
+ var lowzoom = linear$2()
+ .domain([-60, 0, 60])
+ .range([17, 18.5, 17])
+ .clamp(true);
+
+ surface
+ .classed('low-zoom', zoom <= lowzoom(lat));
+
+ if (context.rapidContext().isTaskRectangular()) {
+ drawMapGrid();
+ }
+
+ if (!difference) {
+ supersurface.call(context.background());
+ wrapper.call(drawLayers);
+ }
+
+ // OSM
+ if (map.editableDataEnabled() || map.isInWideSelection()) {
+ context.loadTiles(projection);
+ drawEditable(difference, extent);
+ } else {
+ editOff();
+ }
+
+ _transformStart = projection.transform();
+
+ return map;
+ }
+
+
+
+ var immediateRedraw = function(difference, extent) {
+ if (!difference && !extent) cancelPendingRedraw();
+ redraw(difference, extent);
+ };
+
+
+ map.lastPointerEvent = function() {
+ return _lastPointerEvent;
+ };
+
+
+ map.mouse = function() {
+ var event$1 = _lastPointerEvent || event;
+ if (event$1) {
+ var s;
+ while ((s = event$1.sourceEvent)) { event$1 = s; }
+ return _getMouseCoords(event$1);
+ }
+ return null;
+ };
+
+
+ // returns Lng/Lat
+ map.mouseCoordinates = function() {
+ var coord = map.mouse() || pxCenter();
+ return projection.invert(coord);
+ };
+
+
+ map.dblclickZoomEnable = function(val) {
+ if (!arguments.length) return _dblClickZoomEnabled;
+ _dblClickZoomEnabled = val;
+ return map;
+ };
+
+
+ map.redrawEnable = function(val) {
+ if (!arguments.length) return _redrawEnabled;
+ _redrawEnabled = val;
+ return map;
+ };
+
+
+ map.isTransformed = function() {
+ return _isTransformed;
+ };
+
+
+ function setTransform(t2, duration, force) {
+ var t = projection.transform();
+ if (!force && t2.k === t.k && t2.x === t.x && t2.y === t.y) return false;
+
+ if (duration) {
+ _selection
+ .transition()
+ .duration(duration)
+ .on('start', function() { map.startEase(); })
+ .call(_zoomerPanner.transform, identity$2.translate(t2.x, t2.y).scale(t2.k));
+ } else {
+ projection.transform(t2);
+ _transformStart = t2;
+ _selection.call(_zoomerPanner.transform, _transformStart);
+ }
+
+ return true;
+ }
+
+
+ function setCenterZoom(loc2, z2, duration, force) {
+ var c = map.center();
+ var z = map.zoom();
+ if (loc2[0] === c[0] && loc2[1] === c[1] && z2 === z && !force) return false;
+
+ var proj = geoRawMercator().transform(projection.transform()); // copy projection
+
+ var k2 = clamp$1(geoZoomToScale(z2, TILESIZE), kMin, kMax);
+ proj.scale(k2);
+
+ var t = proj.translate();
+ var point = proj(loc2);
+
+ var center = pxCenter();
+ t[0] += center[0] - point[0];
+ t[1] += center[1] - point[1];
+
+ return setTransform(identity$2.translate(t[0], t[1]).scale(k2), duration, force);
+ }
+
+
+ map.pan = function(delta, duration) {
+ var t = projection.translate();
+ var k = projection.scale();
+
+ t[0] += delta[0];
+ t[1] += delta[1];
+
+ if (duration) {
+ _selection
+ .transition()
+ .duration(duration)
+ .on('start', function() { map.startEase(); })
+ .call(_zoomerPanner.transform, identity$2.translate(t[0], t[1]).scale(k));
+ } else {
+ projection.translate(t);
+ _transformStart = projection.transform();
+ _selection.call(_zoomerPanner.transform, _transformStart);
+ dispatch$1.call('move', this, map);
+ immediateRedraw();
+ }
+
+ return map;
+ };
+
+
+ map.dimensions = function(val) {
+ if (!arguments.length) return _dimensions;
+
+ _dimensions = val;
+ drawLayers.dimensions(_dimensions);
+ context.background().dimensions(_dimensions);
+ projection.clipExtent([[0, 0], _dimensions]);
+ _getMouseCoords = utilFastMouse(supersurface.node());
+
+ scheduleRedraw();
+ return map;
+ };
+
+
+ function zoomIn(delta) {
+ setCenterZoom(map.center(), ~~map.zoom() + delta, 250, true);
+ }
+
+ function zoomOut(delta) {
+ setCenterZoom(map.center(), ~~map.zoom() - delta, 250, true);
+ }
+
+ map.zoomIn = function() { zoomIn(1); };
+ map.zoomInFurther = function() { zoomIn(4); };
+ map.canZoomIn = function() { return map.zoom() < maxZoom; };
+
+ map.zoomOut = function() { zoomOut(1); };
+ map.zoomOutFurther = function() { zoomOut(4); };
+ map.canZoomOut = function() { return map.zoom() > minZoom; };
+
+ map.center = function(loc2) {
+ if (!arguments.length) {
+ return projection.invert(pxCenter());
+ }
+
+ if (setCenterZoom(loc2, map.zoom())) {
+ dispatch$1.call('move', this, map);
+ }
+
+ scheduleRedraw();
+ return map;
+ };
+
+ map.unobscuredCenterZoomEase = function(loc, zoom) {
+ var offset = map.unobscuredOffsetPx();
+
+ var proj = geoRawMercator().transform(projection.transform()); // copy projection
+ // use the target zoom to calculate the offset center
+ proj.scale(geoZoomToScale(zoom, TILESIZE));
+
+ var locPx = proj(loc);
+ var offsetLocPx = [locPx[0] + offset[0], locPx[1] + offset[1]];
+ var offsetLoc = proj.invert(offsetLocPx);
+
+ map.centerZoomEase(offsetLoc, zoom);
+ };
+
+ map.unobscuredOffsetPx = function() {
+ var openPane = context.container().select('.map-panes .map-pane.shown');
+ if (!openPane.empty()) {
+ return [openPane.node().offsetWidth/2, 0];
+ }
+ return [0, 0];
+ };
+
+ map.zoom = function(z2) {
+ if (!arguments.length) {
+ return Math.max(geoScaleToZoom(projection.scale(), TILESIZE), 0);
+ }
+
+ if (z2 < _minzoom) {
+ surface.interrupt();
+ dispatch$1.call('hitMinZoom', this, map);
+ z2 = context.minEditableZoom();
+ }
+
+ if (setCenterZoom(map.center(), z2)) {
+ dispatch$1.call('move', this, map);
+ }
+
+ scheduleRedraw();
+ return map;
+ };
+
+
+ map.centerZoom = function(loc2, z2) {
+ if (setCenterZoom(loc2, z2)) {
+ dispatch$1.call('move', this, map);
+ }
+
+ scheduleRedraw();
+ return map;
+ };
+
+
+ map.zoomTo = function(entity) {
+ var extent = entity.extent(context.graph());
+ if (!isFinite(extent.area())) return map;
+
+ var z2 = clamp$1(map.trimmedExtentZoom(extent), 0, 20);
+ return map.centerZoom(extent.center(), z2);
+ };
+
+
+ map.centerEase = function(loc2, duration) {
+ duration = duration || 250;
+ setCenterZoom(loc2, map.zoom(), duration);
+ return map;
+ };
+
+
+ map.zoomEase = function(z2, duration) {
+ duration = duration || 250;
+ setCenterZoom(map.center(), z2, duration, false);
+ return map;
+ };
+
+
+ map.centerZoomEase = function(loc2, z2, duration) {
+ duration = duration || 250;
+ setCenterZoom(loc2, z2, duration, false);
+ return map;
+ };
+
+
+ map.transformEase = function(t2, duration) {
+ duration = duration || 250;
+ setTransform(t2, duration, false /* don't force */);
+ return map;
+ };
+
+
+ map.zoomToEase = function(obj, duration) {
+ var extent;
+ if (Array.isArray(obj)) {
+ obj.forEach(function(entity) {
+ var entityExtent = entity.extent(context.graph());
+ if (!extent) {
+ extent = entityExtent;
+ } else {
+ extent = extent.extend(entityExtent);
+ }
+ });
+ } else {
+ extent = obj.extent(context.graph());
+ }
+ if (!isFinite(extent.area())) return map;
+
+ var z2 = clamp$1(map.trimmedExtentZoom(extent), 0, 20);
+ return map.centerZoomEase(extent.center(), z2, duration);
+ };
+
+
+ map.startEase = function() {
+ utilBindOnce(surface, _pointerPrefix + 'down.ease', function() {
+ map.cancelEase();
+ });
+ return map;
+ };
+
+
+ map.cancelEase = function() {
+ _selection.interrupt();
+ return map;
+ };
+
+
+ map.extent = function(val) {
+ if (!arguments.length) {
+ return new geoExtent(
+ projection.invert([0, _dimensions[1]]),
+ projection.invert([_dimensions[0], 0])
+ );
+ } else {
+ var extent = geoExtent(val);
+ map.centerZoom(extent.center(), map.extentZoom(extent));
+ }
+ };
+
+
+ map.trimmedExtent = function(val) {
+ if (!arguments.length) {
+ var headerY = 71;
+ var footerY = 30;
+ var pad = 10;
+ return new geoExtent(
+ projection.invert([pad, _dimensions[1] - footerY - pad]),
+ projection.invert([_dimensions[0] - pad, headerY + pad])
+ );
+ } else {
+ var extent = geoExtent(val);
+ map.centerZoom(extent.center(), map.trimmedExtentZoom(extent));
+ }
+ };
+
+
+ function calcExtentZoom(extent, dim) {
+ var tl = projection([extent[0][0], extent[1][1]]);
+ var br = projection([extent[1][0], extent[0][1]]);
+
+ // Calculate maximum zoom that fits extent
+ var hFactor = (br[0] - tl[0]) / dim[0];
+ var vFactor = (br[1] - tl[1]) / dim[1];
+ var hZoomDiff = Math.log(Math.abs(hFactor)) / Math.LN2;
+ var vZoomDiff = Math.log(Math.abs(vFactor)) / Math.LN2;
+ var newZoom = map.zoom() - Math.max(hZoomDiff, vZoomDiff);
+
+ return newZoom;
+ }
+
+
+ map.extentZoom = function(val) {
+ return calcExtentZoom(geoExtent(val), _dimensions);
+ };
+
+
+ map.trimmedExtentZoom = function(val) {
+ var trimY = 120;
+ var trimX = 40;
+ var trimmed = [_dimensions[0] - trimX, _dimensions[1] - trimY];
+ return calcExtentZoom(geoExtent(val), trimmed);
+ };
+
+
+ map.withinEditableZoom = function() {
+ return map.zoom() >= context.minEditableZoom();
+ };
+
+
+ map.isInWideSelection = function() {
+ return !map.withinEditableZoom() && context.selectedIDs().length;
+ };
+
+
+ map.editableDataEnabled = function(skipZoomCheck) {
+
+ var layer = context.layers().layer('osm');
+ if (!layer || !layer.enabled()) return false;
+
+ return skipZoomCheck || map.withinEditableZoom();
+ };
+
+
+ map.notesEditable = function() {
+ var layer = context.layers().layer('notes');
+ if (!layer || !layer.enabled()) return false;
+
+ return map.withinEditableZoom();
+ };
+
+
+ map.minzoom = function(val) {
+ if (!arguments.length) return _minzoom;
+ _minzoom = val;
+ return map;
+ };
+
+
+ map.toggleHighlightEdited = function() {
+ surface.classed('highlight-edited', !surface.classed('highlight-edited'));
+ map.pan([0,0]); // trigger a redraw
+ dispatch$1.call('changeHighlighting', this);
+ };
+
+
+ map.areaFillOptions = ['wireframe', 'partial', 'full'];
+
+ map.activeAreaFill = function(val) {
+ if (!arguments.length) return corePreferences('area-fill') || 'partial';
+
+ corePreferences('area-fill', val);
+ if (val !== 'wireframe') {
+ corePreferences('area-fill-toggle', val);
+ }
+ updateAreaFill();
+ map.pan([0,0]); // trigger a redraw
+ dispatch$1.call('changeAreaFill', this);
+ return map;
+ };
+
+ map.toggleWireframe = function() {
+
+ var activeFill = map.activeAreaFill();
+
+ if (activeFill === 'wireframe') {
+ activeFill = corePreferences('area-fill-toggle') || 'partial';
+ } else {
+ activeFill = 'wireframe';
+ }
+
+ map.activeAreaFill(activeFill);
+ };
+
+ function updateAreaFill() {
+ var activeFill = map.activeAreaFill();
+ map.areaFillOptions.forEach(function(opt) {
+ surface.classed('fill-' + opt, Boolean(opt === activeFill));
+ });
+ }
+
+
+ map.layers = () => drawLayers;
+
+
+ map.doubleUpHandler = function() {
+ return _doubleUpHandler;
+ };
+
+
+ return utilRebind(map, dispatch$1, 'on');
+ }
+
+ function rendererPhotos(context) {
+ var dispatch$1 = dispatch('change');
+ var _layerIDs = ['streetside', 'mapillary', 'mapillary-map-features', 'mapillary-signs', 'openstreetcam'];
+ var _allPhotoTypes = ['flat', 'panoramic'];
+ var _shownPhotoTypes = _allPhotoTypes.slice(); // shallow copy
+
+ function photos() {}
+
+ function updateStorage() {
+ if (window.mocha) return;
+
+ var hash = utilStringQs(window.location.hash);
+ var enabled = context.layers().all().filter(function(d) {
+ return _layerIDs.indexOf(d.id) !== -1 && d.layer && d.layer.supported() && d.layer.enabled();
+ }).map(function(d) {
+ return d.id;
+ });
+ if (enabled.length) {
+ hash.photo_overlay = enabled.join(',');
+ } else {
+ delete hash.photo_overlay;
+ }
+ window.location.replace('#' + utilQsString(hash, true));
+ }
+
+ photos.overlayLayerIDs = function() {
+ return _layerIDs;
+ };
+
+ photos.allPhotoTypes = function() {
+ return _allPhotoTypes;
+ };
+
+ function showsLayer(id) {
+ var layer = context.layers().layer(id);
+ return layer && layer.supported() && layer.enabled();
+ }
+
+ photos.shouldFilterByPhotoType = function() {
+ return showsLayer('mapillary') ||
+ (showsLayer('streetside') && showsLayer('openstreetcam'));
+ };
+
+ photos.showsPhotoType = function(val) {
+ if (!photos.shouldFilterByPhotoType()) return true;
+
+ return _shownPhotoTypes.indexOf(val) !== -1;
+ };
+
+ photos.showsFlat = function() {
+ return photos.showsPhotoType('flat');
+ };
+
+ photos.showsPanoramic = function() {
+ return photos.showsPhotoType('panoramic');
+ };
+
+ photos.togglePhotoType = function(val) {
+ var index = _shownPhotoTypes.indexOf(val);
+ if (index !== -1) {
+ _shownPhotoTypes.splice(index, 1);
+ } else {
+ _shownPhotoTypes.push(val);
+ }
+ dispatch$1.call('change', this);
+ return photos;
+ };
+
+ photos.init = function() {
+ var hash = utilStringQs(window.location.hash);
+ if (hash.photo_overlay) {
+ var hashOverlayIDs = hash.photo_overlay.replace(/;/g, ',').split(',');
+ hashOverlayIDs.forEach(function(id) {
+ var layer = context.layers().layer(id);
+ if (layer) layer.enabled(true);
+ });
+ }
+
+ context.layers().on('change.rendererPhotos', updateStorage);
+ };
+
+ return utilRebind(photos, dispatch$1, 'on');
+ }
+
+ // import { utilGetDimensions } from '../util/dimensions';
+
+
+ function uiMapInMap(context) {
+
+ function mapInMap(selection) {
+ var backgroundLayer = rendererTileLayer(context);
+ var overlayLayers = {};
+ var projection = geoRawMercator();
+ var dataLayer = svgData(projection, context).showLabels(false);
+ var debugLayer = svgDebug(projection, context);
+ var zoom = d3_zoom()
+ .scaleExtent([geoZoomToScale(0.5), geoZoomToScale(24)])
+ .on('start', zoomStarted)
+ .on('zoom', zoomed)
+ .on('end', zoomEnded);
+
+ var wrap = select(null);
+ var tiles = select(null);
+ var viewport = select(null);
+
+ var _isTransformed = false;
+ var _isHidden = true;
+ var _skipEvents = false;
+ var _gesture = null;
+ var _zDiff = 6; // by default, minimap renders at (main zoom - 6)
+ var _dMini; // dimensions of minimap
+ var _cMini; // center pixel of minimap
+ var _tStart; // transform at start of gesture
+ var _tCurr; // transform at most recent event
+ var _timeoutID;
+
+
+ function zoomStarted() {
+ if (_skipEvents) return;
+ _tStart = _tCurr = projection.transform();
+ _gesture = null;
+ }
+
+
+ function zoomed() {
+ if (_skipEvents) return;
+
+ var x = event.transform.x;
+ var y = event.transform.y;
+ var k = event.transform.k;
+ var isZooming = (k !== _tStart.k);
+ var isPanning = (x !== _tStart.x || y !== _tStart.y);
+
+ if (!isZooming && !isPanning) {
+ return; // no change
+ }
+
+ // lock in either zooming or panning, don't allow both in minimap.
+ if (!_gesture) {
+ _gesture = isZooming ? 'zoom' : 'pan';
+ }
+
+ var tMini = projection.transform();
+ var tX, tY, scale;
+
+ if (_gesture === 'zoom') {
+ scale = k / tMini.k;
+ tX = (_cMini[0] / scale - _cMini[0]) * scale;
+ tY = (_cMini[1] / scale - _cMini[1]) * scale;
+ } else {
+ k = tMini.k;
+ scale = 1;
+ tX = x - tMini.x;
+ tY = y - tMini.y;
+ }
+
+ utilSetTransform(tiles, tX, tY, scale);
+ utilSetTransform(viewport, 0, 0, scale);
+ _isTransformed = true;
+ _tCurr = identity$2.translate(x, y).scale(k);
+
+ var zMain = geoScaleToZoom(context.projection.scale());
+ var zMini = geoScaleToZoom(k);
+
+ _zDiff = zMain - zMini;
+
+ queueRedraw();
+ }
+
+
+ function zoomEnded() {
+ if (_skipEvents) return;
+ if (_gesture !== 'pan') return;
+
+ updateProjection();
+ _gesture = null;
+ context.map().center(projection.invert(_cMini)); // recenter main map..
+ }
+
+
+ function updateProjection() {
+ var loc = context.map().center();
+ var tMain = context.projection.transform();
+ var zMain = geoScaleToZoom(tMain.k);
+ var zMini = Math.max(zMain - _zDiff, 0.5);
+ var kMini = geoZoomToScale(zMini);
+
+ projection
+ .translate([tMain.x, tMain.y])
+ .scale(kMini);
+
+ var point = projection(loc);
+ var mouse = (_gesture === 'pan') ? geoVecSubtract([_tCurr.x, _tCurr.y], [_tStart.x, _tStart.y]) : [0, 0];
+ var xMini = _cMini[0] - point[0] + tMain.x + mouse[0];
+ var yMini = _cMini[1] - point[1] + tMain.y + mouse[1];
+
+ projection
+ .translate([xMini, yMini])
+ .clipExtent([[0, 0], _dMini]);
+
+ _tCurr = projection.transform();
+
+ if (_isTransformed) {
+ utilSetTransform(tiles, 0, 0);
+ utilSetTransform(viewport, 0, 0);
+ _isTransformed = false;
+ }
+
+ zoom
+ .scaleExtent([geoZoomToScale(0.5), geoZoomToScale(zMain - 3)]);
+
+ _skipEvents = true;
+ wrap.call(zoom.transform, _tCurr);
+ _skipEvents = false;
+ }
+
+
+ function redraw() {
+ clearTimeout(_timeoutID);
+ if (_isHidden) return;
+
+ updateProjection();
+ var zMini = geoScaleToZoom(projection.scale());
+
+ // setup tile container
+ tiles = wrap
+ .selectAll('.map-in-map-tiles')
+ .data([0]);
+
+ tiles = tiles.enter()
+ .append('div')
+ .attr('class', 'map-in-map-tiles')
+ .merge(tiles);
+
+ // redraw background
+ backgroundLayer
+ .source(context.background().baseLayerSource())
+ .projection(projection)
+ .dimensions(_dMini);
+
+ var background = tiles
+ .selectAll('.map-in-map-background')
+ .data([0]);
+
+ background.enter()
+ .append('div')
+ .attr('class', 'map-in-map-background')
+ .merge(background)
+ .call(backgroundLayer);
+
+
+ // redraw overlay
+ var overlaySources = context.background().overlayLayerSources();
+ var activeOverlayLayers = [];
+ for (var i = 0; i < overlaySources.length; i++) {
+ if (overlaySources[i].validZoom(zMini)) {
+ if (!overlayLayers[i]) overlayLayers[i] = rendererTileLayer(context);
+ activeOverlayLayers.push(overlayLayers[i]
+ .source(overlaySources[i])
+ .projection(projection)
+ .dimensions(_dMini));
+ }
+ }
+
+ var overlay = tiles
+ .selectAll('.map-in-map-overlay')
+ .data([0]);
+
+ overlay = overlay.enter()
+ .append('div')
+ .attr('class', 'map-in-map-overlay')
+ .merge(overlay);
+
+
+ var overlays = overlay
+ .selectAll('div')
+ .data(activeOverlayLayers, function(d) { return d.source().name(); });
+
+ overlays.exit()
+ .remove();
+
+ overlays = overlays.enter()
+ .append('div')
+ .merge(overlays)
+ .each(function(layer) { select(this).call(layer); });
+
+
+ var dataLayers = tiles
+ .selectAll('.map-in-map-data')
+ .data([0]);
+
+ dataLayers.exit()
+ .remove();
+
+ dataLayers = dataLayers.enter()
+ .append('svg')
+ .attr('class', 'map-in-map-data')
+ .merge(dataLayers)
+ .call(dataLayer)
+ .call(debugLayer);
+
+
+ // redraw viewport bounding box
+ if (_gesture !== 'pan') {
+ var getPath = d3_geoPath(projection);
+ var bbox = { type: 'Polygon', coordinates: [context.map().extent().polygon()] };
+
+ viewport = wrap.selectAll('.map-in-map-viewport')
+ .data([0]);
+
+ viewport = viewport.enter()
+ .append('svg')
+ .attr('class', 'map-in-map-viewport')
+ .merge(viewport);
+
+
+ var path = viewport.selectAll('.map-in-map-bbox')
+ .data([bbox]);
+
+ path.enter()
+ .append('path')
+ .attr('class', 'map-in-map-bbox')
+ .merge(path)
+ .attr('d', getPath)
+ .classed('thick', function(d) { return getPath.area(d) < 30; });
+ }
+ }
+
+
+ function queueRedraw() {
+ clearTimeout(_timeoutID);
+ _timeoutID = setTimeout(function() { redraw(); }, 750);
+ }
+
+
+ function toggle() {
+ if (event) event.preventDefault();
+
+ _isHidden = !_isHidden;
+
+ context.container().select('.minimap-toggle-item')
+ .classed('active', !_isHidden)
+ .select('input')
+ .property('checked', !_isHidden);
+
+ if (_isHidden) {
+ wrap
+ .style('display', 'block')
+ .style('opacity', '1')
+ .transition()
+ .duration(200)
+ .style('opacity', '0')
+ .on('end', function() {
+ selection.selectAll('.map-in-map')
+ .style('display', 'none');
+ });
+ } else {
+ wrap
+ .style('display', 'block')
+ .style('opacity', '0')
+ .transition()
+ .duration(200)
+ .style('opacity', '1')
+ .on('end', function() {
+ redraw();
+ });
+ }
+ }
+
+
+ uiMapInMap.toggle = toggle;
+
+ wrap = selection.selectAll('.map-in-map')
+ .data([0]);
+
+ wrap = wrap.enter()
+ .append('div')
+ .attr('class', 'map-in-map')
+ .style('display', (_isHidden ? 'none' : 'block'))
+ .call(zoom)
+ .on('dblclick.zoom', null)
+ .merge(wrap);
+
+ // reflow warning: Hardcode dimensions - currently can't resize it anyway..
+ _dMini = [200,150]; //utilGetDimensions(wrap);
+ _cMini = geoVecScale(_dMini, 0.5);
+
+ context.map()
+ .on('drawn.map-in-map', function(drawn) {
+ if (drawn.full === true) {
+ redraw();
+ }
+ });
+
+ redraw();
+
+ context.keybinding()
+ .on(_t('background.minimap.key'), toggle);
+ }
+
+ return mapInMap;
+ }
+
+ function uiNotice(context) {
+
+ return function(selection) {
+ var div = selection
+ .append('div')
+ .attr('class', 'notice');
+
+ var button = div
+ .append('button')
+ .attr('class', 'zoom-to notice fillD')
+ .on('click', function() {
+ context.map().zoomEase(context.minEditableZoom());
+ })
+ .on('wheel', function() { // let wheel events pass through #4482
+ var e2 = new WheelEvent(event.type, event);
+ context.surface().node().dispatchEvent(e2);
+ });
+
+ button
+ .call(svgIcon('#iD-icon-plus', 'pre-text'))
+ .append('span')
+ .attr('class', 'label')
+ .text(_t('zoom_in_edit'));
+
+
+ function disableTooHigh() {
+ var canEdit = context.map().zoom() >= context.minEditableZoom();
+ div.style('display', canEdit ? 'none' : 'block');
+ }
+
+ context.map()
+ .on('move.notice', debounce(disableTooHigh, 500));
+
+ disableTooHigh();
+ };
+ }
+
+ function uiPhotoviewer(context) {
+
+ var dispatch$1 = dispatch('resize');
+
+ var _pointerPrefix = 'PointerEvent' in window ? 'pointer' : 'mouse';
+
+ function photoviewer(selection) {
+ selection
+ .append('button')
+ .attr('class', 'thumb-hide')
+ .on('click', function () {
+ if (services.streetside) { services.streetside.hideViewer(context); }
+ if (services.mapillary) { services.mapillary.hideViewer(context); }
+ if (services.openstreetcam) { services.openstreetcam.hideViewer(context); }
+ })
+ .append('div')
+ .call(svgIcon('#iD-icon-close'));
+
+ function preventDefault() {
+ event.preventDefault();
+ }
+
+ selection
+ .append('button')
+ .attr('class', 'resize-handle-xy')
+ .on('touchstart touchdown touchend', preventDefault)
+ .on(
+ _pointerPrefix + 'down',
+ buildResizeListener(selection, 'resize', dispatch$1, { resizeOnX: true, resizeOnY: true })
+ );
+
+ selection
+ .append('button')
+ .attr('class', 'resize-handle-x')
+ .on('touchstart touchdown touchend', preventDefault)
+ .on(
+ _pointerPrefix + 'down',
+ buildResizeListener(selection, 'resize', dispatch$1, { resizeOnX: true })
+ );
+
+ selection
+ .append('button')
+ .attr('class', 'resize-handle-y')
+ .on('touchstart touchdown touchend', preventDefault)
+ .on(
+ _pointerPrefix + 'down',
+ buildResizeListener(selection, 'resize', dispatch$1, { resizeOnY: true })
+ );
+
+ services.streetside.loadViewer(context);
+ services.mapillary.loadViewer(context);
+ services.openstreetcam.loadViewer(context);
+
+ function buildResizeListener(target, eventName, dispatch, options) {
+
+ var resizeOnX = !!options.resizeOnX;
+ var resizeOnY = !!options.resizeOnY;
+ var minHeight = options.minHeight || 240;
+ var minWidth = options.minWidth || 320;
+ var pointerId;
+ var startX;
+ var startY;
+ var startWidth;
+ var startHeight;
+
+ function startResize() {
+ if (pointerId !== (event.pointerId || 'mouse')) return;
+
+ event.preventDefault();
+ event.stopPropagation();
+
+ var mapSize = context.map().dimensions();
+
+ if (resizeOnX) {
+ var maxWidth = mapSize[0];
+ var newWidth = clamp((startWidth + event.clientX - startX), minWidth, maxWidth);
+ target.style('width', newWidth + 'px');
+ }
+
+ if (resizeOnY) {
+ var maxHeight = mapSize[1] - 90; // preserve space at top/bottom of map
+ var newHeight = clamp((startHeight + startY - event.clientY), minHeight, maxHeight);
+ target.style('height', newHeight + 'px');
+ }
+
+ dispatch.call(eventName, target, utilGetDimensions(target, true));
+ }
+
+ function clamp(num, min, max) {
+ return Math.max(min, Math.min(num, max));
+ }
+
+ function stopResize() {
+ if (pointerId !== (event.pointerId || 'mouse')) return;
+
+ event.preventDefault();
+ event.stopPropagation();
+
+ // remove all the listeners we added
+ select(window)
+ .on('.' + eventName, null);
+ }
+
+ return function initResize() {
+ event.preventDefault();
+ event.stopPropagation();
+
+ pointerId = event.pointerId || 'mouse';
+
+ startX = event.clientX;
+ startY = event.clientY;
+ var targetRect = target.node().getBoundingClientRect();
+ startWidth = targetRect.width;
+ startHeight = targetRect.height;
+
+ select(window)
+ .on(_pointerPrefix + 'move.' + eventName, startResize, false)
+ .on(_pointerPrefix + 'up.' + eventName, stopResize, false);
+
+ if (_pointerPrefix === 'pointer') {
+ select(window)
+ .on('pointercancel.' + eventName, stopResize, false);
+ }
+ };
+ }
+ }
+
+ photoviewer.onMapResize = function() {
+ var photoviewer = context.container().select('.photoviewer');
+ var content = context.container().select('.main-content');
+ var mapDimensions = utilGetDimensions(content, true);
+ // shrink photo viewer if it is too big
+ // (-90 preserves space at top and bottom of map used by menus)
+ var photoDimensions = utilGetDimensions(photoviewer, true);
+ if (photoDimensions[0] > mapDimensions[0] || photoDimensions[1] > (mapDimensions[1] - 90)) {
+ var setPhotoDimensions = [
+ Math.min(photoDimensions[0], mapDimensions[0]),
+ Math.min(photoDimensions[1], mapDimensions[1] - 90),
+ ];
+
+ photoviewer
+ .style('width', setPhotoDimensions[0] + 'px')
+ .style('height', setPhotoDimensions[1] + 'px');
+
+ dispatch$1.call('resize', photoviewer, setPhotoDimensions);
+ }
+ };
+
+ return utilRebind(photoviewer, dispatch$1, 'on');
+ }
+
+ function uiRestore(context) {
+ return function(selection) {
+ if (!context.history().hasRestorableChanges()) return;
+
+ let modalSelection = uiModal(selection, true);
+
+ modalSelection.select('.modal')
+ .attr('class', 'modal fillL');
+
+ let introModal = modalSelection.select('.content');
+
+ introModal
+ .append('div')
+ .attr('class', 'modal-section')
+ .append('h3')
+ .text(_t('restore.heading'));
+
+ introModal
+ .append('div')
+ .attr('class','modal-section')
+ .append('p')
+ .text(_t('restore.description'));
+
+ let buttonWrap = introModal
+ .append('div')
+ .attr('class', 'modal-actions');
+
+ let restore = buttonWrap
+ .append('button')
+ .attr('class', 'restore')
+ .on('click', () => {
+ context.history().restore();
+ modalSelection.remove();
+ });
+
+ restore
+ .append('svg')
+ .attr('class', 'logo logo-restore')
+ .append('use')
+ .attr('xlink:href', '#iD-logo-restore');
+
+ restore
+ .append('div')
+ .text(_t('restore.restore'));
+
+ let reset = buttonWrap
+ .append('button')
+ .attr('class', 'reset')
+ .on('click', () => {
+ context.history().clearSaved();
+ modalSelection.remove();
+ });
+
+ reset
+ .append('svg')
+ .attr('class', 'logo logo-reset')
+ .append('use')
+ .attr('xlink:href', '#iD-logo-reset');
+
+ reset
+ .append('div')
+ .text(_t('restore.reset'));
+
+ restore.node().focus();
+ };
+ }
+
+ function uiScale(context) {
+ var projection = context.projection,
+ isImperial = !_mainLocalizer.usesMetric(),
+ maxLength = 180,
+ tickHeight = 8;
+
+
+ function scaleDefs(loc1, loc2) {
+ var lat = (loc2[1] + loc1[1]) / 2,
+ conversion = (isImperial ? 3.28084 : 1),
+ dist = geoLonToMeters(loc2[0] - loc1[0], lat) * conversion,
+ scale = { dist: 0, px: 0, text: '' },
+ buckets, i, val, dLon;
+
+ if (isImperial) {
+ buckets = [5280000, 528000, 52800, 5280, 500, 50, 5, 1];
+ } else {
+ buckets = [5000000, 500000, 50000, 5000, 500, 50, 5, 1];
+ }
+
+ // determine a user-friendly endpoint for the scale
+ for (i = 0; i < buckets.length; i++) {
+ val = buckets[i];
+ if (dist >= val) {
+ scale.dist = Math.floor(dist / val) * val;
+ break;
+ } else {
+ scale.dist = +dist.toFixed(2);
+ }
+ }
+
+ dLon = geoMetersToLon(scale.dist / conversion, lat);
+ scale.px = Math.round(projection([loc1[0] + dLon, loc1[1]])[0]);
+
+ scale.text = displayLength(scale.dist / conversion, isImperial);
+
+ return scale;
+ }
+
+
+ function update(selection) {
+ // choose loc1, loc2 along bottom of viewport (near where the scale will be drawn)
+ var dims = context.map().dimensions(),
+ loc1 = projection.invert([0, dims[1]]),
+ loc2 = projection.invert([maxLength, dims[1]]),
+ scale = scaleDefs(loc1, loc2);
+
+ selection.select('.scale-path')
+ .attr('d', 'M0.5,0.5v' + tickHeight + 'h' + scale.px + 'v-' + tickHeight);
+
+ selection.select('.scale-textgroup')
+ .attr('transform', 'translate(' + (scale.px + 8) + ',' + tickHeight + ')');
+
+ selection.select('.scale-text')
+ .text(scale.text);
+ }
+
+
+ return function(selection) {
+ function switchUnits() {
+ isImperial = !isImperial;
+ selection.call(update);
+ }
+
+ var scalegroup = selection.append('svg')
+ .attr('class', 'scale')
+ .on('click', switchUnits)
+ .append('g')
+ .attr('transform', 'translate(10,11)');
+
+ scalegroup
+ .append('path')
+ .attr('class', 'scale-path');
+
+ scalegroup
+ .append('g')
+ .attr('class', 'scale-textgroup')
+ .append('text')
+ .attr('class', 'scale-text');
+
+ selection.call(update);
+
+ context.map().on('move.scale', function() {
+ update(selection);
+ });
+ };
+ }
+
+ function uiShortcuts(context) {
+ var detected = utilDetect();
+ var _activeTab = 0;
+ var _modalSelection;
+ var _selection = select(null);
+
+
+ context.keybinding()
+ .on([_t('shortcuts.toggle.key'), '?'], function () {
+ if (context.container().selectAll('.modal-shortcuts').size()) { // already showing
+ if (_modalSelection) {
+ _modalSelection.close();
+ _modalSelection = null;
+ }
+ } else {
+ _modalSelection = uiModal(_selection);
+ _modalSelection.call(shortcutsModal);
+ }
+ });
+
+
+ function shortcutsModal(_modalSelection) {
+ _modalSelection.select('.modal')
+ .classed('modal-shortcuts', true);
+
+ var content = _modalSelection.select('.content');
+
+ content
+ .append('div')
+ .attr('class', 'modal-section')
+ .append('h3')
+ .text(_t('shortcuts.title'));
+
+ _mainFileFetcher.get('shortcuts')
+ .then(function(data) { content.call(render, data); })
+ .catch(function() { /* ignore */ });
+ }
+
+
+ function render(selection, dataShortcuts) {
+ var wrapper = selection
+ .selectAll('.wrapper')
+ .data([0]);
+
+ var wrapperEnter = wrapper
+ .enter()
+ .append('div')
+ .attr('class', 'wrapper modal-section');
+
+ var tabsBar = wrapperEnter
+ .append('div')
+ .attr('class', 'tabs-bar');
+
+ var shortcutsList = wrapperEnter
+ .append('div')
+ .attr('class', 'shortcuts-list');
+
+ wrapper = wrapper.merge(wrapperEnter);
+
+ var tabs = tabsBar
+ .selectAll('.tab')
+ .data(dataShortcuts);
+
+ var tabsEnter = tabs
+ .enter()
+ .append('div')
+ .attr('class', 'tab')
+ .on('click', function (d, i) {
+ _activeTab = i;
+ render(selection, dataShortcuts);
+ });
+
+ tabsEnter
+ .append('span')
+ .text(function (d) { return _t(d.text); });
+
+ tabs = tabs
+ .merge(tabsEnter);
+
+ // Update
+ wrapper.selectAll('.tab')
+ .classed('active', function (d, i) {
+ return i === _activeTab;
+ });
+
+
+ var shortcuts = shortcutsList
+ .selectAll('.shortcut-tab')
+ .data(dataShortcuts);
+
+ var shortcutsEnter = shortcuts
+ .enter()
+ .append('div')
+ .attr('class', function(d) { return 'shortcut-tab shortcut-tab-' + d.tab; });
+
+ var columnsEnter = shortcutsEnter
+ .selectAll('.shortcut-column')
+ .data(function (d) { return d.columns; })
+ .enter()
+ .append('table')
+ .attr('class', 'shortcut-column');
+
+ var rowsEnter = columnsEnter
+ .selectAll('.shortcut-row')
+ .data(function (d) { return d.rows; })
+ .enter()
+ .append('tr')
+ .attr('class', 'shortcut-row');
+
+
+ var sectionRows = rowsEnter
+ .filter(function (d) { return !d.shortcuts; });
+
+ sectionRows
+ .append('td');
+
+ sectionRows
+ .append('td')
+ .attr('class', 'shortcut-section')
+ .append('h3')
+ .text(function (d) { return _t(d.text); });
+
+
+ var shortcutRows = rowsEnter
+ .filter(function (d) { return d.shortcuts; });
+
+ var shortcutKeys = shortcutRows
+ .append('td')
+ .attr('class', 'shortcut-keys');
+
+ var modifierKeys = shortcutKeys
+ .filter(function (d) { return d.modifiers; });
+
+ modifierKeys
+ .selectAll('kbd.modifier')
+ .data(function (d) {
+ if (detected.os === 'win' && d.text === 'shortcuts.editing.commands.redo') {
+ return ['⌘'];
+ } else if (detected.os !== 'mac' && d.text === 'shortcuts.browsing.display_options.fullscreen') {
+ return [];
+ } else {
+ return d.modifiers;
+ }
+ })
+ .enter()
+ .each(function () {
+ var selection = select(this);
+
+ selection
+ .append('kbd')
+ .attr('class', 'modifier')
+ .text(function (d) { return uiCmd.display(d); });
+
+ selection
+ .append('span')
+ .text('+');
+ });
+
+
+ shortcutKeys
+ .selectAll('kbd.shortcut')
+ .data(function (d) {
+ var arr = d.shortcuts;
+ if (detected.os === 'win' && d.text === 'shortcuts.editing.commands.redo') {
+ arr = ['Y'];
+ } else if (detected.os !== 'mac' && d.text === 'shortcuts.browsing.display_options.fullscreen') {
+ arr = ['F11'];
+ }
+
+ // replace translations
+ arr = arr.map(function(s) {
+ return uiCmd.display(s.indexOf('.') !== -1 ? _t(s) : s);
+ });
+
+ return utilArrayUniq(arr).map(function(s) {
+ return {
+ shortcut: s,
+ separator: d.separator,
+ suffix: d.suffix,
+ rapid: d.rapid
+ };
+ });
+ })
+ .enter()
+ .each(function (d, i, nodes) {
+ var selection = select(this);
+ var click = d.shortcut.toLowerCase().match(/(.*).click/);
+
+ if (click && click[1]) { // replace "left_click", "right_click" with mouse icon
+ selection
+ .call(svgIcon('#iD-walkthrough-mouse-' + click[1], 'operation'));
+ } else if (d.shortcut.toLowerCase() === 'long-press') {
+ selection
+ .call(svgIcon('#iD-walkthrough-longpress', 'longpress operation'));
+ } else if (d.shortcut.toLowerCase() === 'tap') {
+ selection
+ .call(svgIcon('#iD-walkthrough-tap', 'tap operation'));
+ } else {
+ selection
+ .append('kbd')
+ .attr('class', 'shortcut')
+ .text(function (d) { return d.shortcut; });
+ }
+
+ if (i < nodes.length - 1) {
+ selection
+ .append('span')
+ .text(d.separator || '\u00a0' + _t('shortcuts.or') + '\u00a0');
+ } else if (i === nodes.length - 1 && d.suffix) {
+ selection
+ .append('span')
+ .text(d.suffix);
+ }
+
+ if (d.rapid){
+ selection
+ .append('svg')
+ .lower()
+ .attr('class', 'icon logo-rapid')
+ .append('use')
+ .attr('xlink:href', '#iD-logo-rapid')
+ .attr('class', '#iD-logo-rapid');
+ }
+ });
+
+ shortcutKeys
+ .filter(function(d) { return d.gesture; })
+ .each(function () {
+ var selection = select(this);
+
+ selection
+ .append('span')
+ .text('+');
+
+ selection
+ .append('span')
+ .attr('class', 'gesture')
+ .text(function (d) { return _t(d.gesture); });
+ });
+
+
+ shortcutRows
+ .append('td')
+ .attr('class', 'shortcut-desc')
+ .text(function (d) { return d.text ? _t(d.text) : '\u00a0'; });
+
+
+ shortcuts = shortcuts
+ .merge(shortcutsEnter);
+
+ // Update
+ wrapper.selectAll('.shortcut-tab')
+ .style('display', function (d, i) {
+ return i === _activeTab ? 'flex' : 'none';
+ });
+ }
+
+
+ return function(selection, show) {
+ _selection = selection;
+ if (show) {
+ _modalSelection = uiModal(selection);
+ _modalSelection.call(shortcutsModal);
+ }
+ };
+ }
+
+ function uiDataHeader() {
+ var _datum;
+
+
+ function dataHeader(selection) {
+ var header = selection.selectAll('.data-header')
+ .data(
+ (_datum ? [_datum] : []),
+ function(d) { return d.__featurehash__; }
+ );
+
+ header.exit()
+ .remove();
+
+ var headerEnter = header.enter()
+ .append('div')
+ .attr('class', 'data-header');
+
+ var iconEnter = headerEnter
+ .append('div')
+ .attr('class', 'data-header-icon');
+
+ iconEnter
+ .append('div')
+ .attr('class', 'preset-icon-28')
+ .call(svgIcon('#iD-icon-data', 'note-fill'));
+
+ headerEnter
+ .append('div')
+ .attr('class', 'data-header-label')
+ .text(_t('map_data.layers.custom.title'));
+ }
+
+
+ dataHeader.datum = function(val) {
+ if (!arguments.length) return _datum;
+ _datum = val;
+ return this;
+ };
+
+
+ return dataHeader;
+ }
+
+ function uiDataEditor(context) {
+ var dataHeader = uiDataHeader();
+ var rawTagEditor = uiSectionRawTagEditor('custom-data-tag-editor', context)
+ .expandedByDefault(true)
+ .readOnlyTags([/./]);
+ var _datum;
+
+
+ function dataEditor(selection) {
+
+ var header = selection.selectAll('.header')
+ .data([0]);
+
+ var headerEnter = header.enter()
+ .append('div')
+ .attr('class', 'header fillL');
+
+ headerEnter
+ .append('button')
+ .attr('class', 'close')
+ .on('click', function() {
+ context.enter(modeBrowse(context));
+ })
+ .call(svgIcon('#iD-icon-close'));
+
+ headerEnter
+ .append('h3')
+ .text(_t('map_data.title'));
+
+
+ var body = selection.selectAll('.body')
+ .data([0]);
+
+ body = body.enter()
+ .append('div')
+ .attr('class', 'body')
+ .merge(body);
+
+ var editor = body.selectAll('.data-editor')
+ .data([0]);
+
+ // enter/update
+ editor.enter()
+ .append('div')
+ .attr('class', 'modal-section data-editor')
+ .merge(editor)
+ .call(dataHeader.datum(_datum));
+
+ var rte = body.selectAll('.raw-tag-editor')
+ .data([0]);
+
+ // enter/update
+ rte.enter()
+ .append('div')
+ .attr('class', 'raw-tag-editor data-editor')
+ .merge(rte)
+ .call(rawTagEditor
+ .tags((_datum && _datum.properties) || {})
+ .state('hover')
+ .render
+ )
+ .selectAll('textarea.tag-text')
+ .attr('readonly', true)
+ .classed('readonly', true);
+ }
+
+
+ dataEditor.datum = function(val) {
+ if (!arguments.length) return _datum;
+ _datum = val;
+ return this;
+ };
+
+
+ return dataEditor;
+ }
+
+ var pair_1 = pair;
+
+
+ function search(input, dims) {
+ if (!dims) dims = 'NSEW';
+ if (typeof input !== 'string') return null;
+
+ input = input.toUpperCase();
+ var regex = /^[\s\,]*([NSEW])?\s*([\-|\—|\―]?[0-9.]+)[°º˚]?\s*(?:([0-9.]+)['’′‘]\s*)?(?:([0-9.]+)(?:''|"|”|″)\s*)?([NSEW])?/;
+
+ var m = input.match(regex);
+ if (!m) return null; // no match
+
+ var matched = m[0];
+
+ // extract dimension.. m[1] = leading, m[5] = trailing
+ var dim;
+ if (m[1] && m[5]) { // if matched both..
+ dim = m[1]; // keep leading
+ matched = matched.slice(0, -1); // remove trailing dimension from match
+ } else {
+ dim = m[1] || m[5];
+ }
+
+ // if unrecognized dimension
+ if (dim && dims.indexOf(dim) === -1) return null;
+
+ // extract DMS
+ var deg = m[2] ? parseFloat(m[2]) : 0;
+ var min = m[3] ? parseFloat(m[3]) / 60 : 0;
+ var sec = m[4] ? parseFloat(m[4]) / 3600 : 0;
+ var sign = (deg < 0) ? -1 : 1;
+ if (dim === 'S' || dim === 'W') sign *= -1;
+
+ return {
+ val: (Math.abs(deg) + min + sec) * sign,
+ dim: dim,
+ matched: matched,
+ remain: input.slice(matched.length)
+ };
+ }
+
+
+ function pair(input, dims) {
+ input = input.trim();
+ var one = search(input, dims);
+ if (!one) return null;
+
+ input = one.remain.trim();
+ var two = search(input, dims);
+ if (!two || two.remain) return null;
+
+ if (one.dim) {
+ return swapdim(one.val, two.val, one.dim);
+ } else {
+ return [one.val, two.val];
+ }
+ }
+
+
+ function swapdim(a, b, dim) {
+ if (dim === 'N' || dim === 'S') return [a, b];
+ if (dim === 'W' || dim === 'E') return [b, a];
+ }
+
+ function uiFeatureList(context) {
+ var _geocodeResults;
+
+
+ function featureList(selection) {
+ var header = selection
+ .append('div')
+ .attr('class', 'header fillL cf');
+
+ header
+ .append('h3')
+ .text(_t('inspector.feature_list'));
+
+ var searchWrap = selection
+ .append('div')
+ .attr('class', 'search-header');
+
+ var search = searchWrap
+ .append('input')
+ .attr('placeholder', _t('inspector.search'))
+ .attr('type', 'search')
+ .call(utilNoAuto)
+ .on('keypress', keypress)
+ .on('keydown', keydown)
+ .on('input', inputevent);
+
+ searchWrap
+ .call(svgIcon('#iD-icon-search', 'pre-text'));
+
+ var listWrap = selection
+ .append('div')
+ .attr('class', 'inspector-body');
+
+ var list = listWrap
+ .append('div')
+ .attr('class', 'feature-list cf');
+
+ context
+ .on('exit.feature-list', clearSearch);
+ context.map()
+ .on('drawn.feature-list', mapDrawn);
+
+ context.keybinding()
+ .on(uiCmd('⌘F'), focusSearch);
+
+
+ function focusSearch() {
+ var mode = context.mode() && context.mode().id;
+ if (mode !== 'browse') return;
+
+ event.preventDefault();
+ search.node().focus();
+ }
+
+
+ function keydown() {
+ if (event.keyCode === 27) { // escape
+ search.node().blur();
+ }
+ }
+
+
+ function keypress() {
+ var q = search.property('value'),
+ items = list.selectAll('.feature-list-item');
+ if (event.keyCode === 13 && q.length && items.size()) { // return
+ click(items.datum());
+ }
+ }
+
+
+ function inputevent() {
+ _geocodeResults = undefined;
+ drawList();
+ }
+
+
+ function clearSearch() {
+ search.property('value', '');
+ drawList();
+ }
+
+
+ function mapDrawn(e) {
+ if (e.full) {
+ drawList();
+ }
+ }
+
+
+ function features() {
+ var result = [];
+ var graph = context.graph();
+ var visibleCenter = context.map().extent().center();
+ var q = search.property('value').toLowerCase();
+
+ if (!q) return result;
+
+ var idMatch = q.match(/(?:^|\W)(node|way|relation|[nwr])\W?0*([1-9]\d*)(?:\W|$)/i);
+
+ if (idMatch) {
+ var elemType = idMatch[1].charAt(0);
+ var elemId = idMatch[2];
+ result.push({
+ id: elemType + elemId,
+ geometry: elemType === 'n' ? 'point' : elemType === 'w' ? 'line' : 'relation',
+ type: elemType === 'n' ? _t('inspector.node') : elemType === 'w' ? _t('inspector.way') : _t('inspector.relation'),
+ name: elemId
+ });
+ }
+
+ var locationMatch = pair_1(q.toUpperCase()) || q.match(/^(-?\d+\.?\d*)\s+(-?\d+\.?\d*)$/);
+
+ if (locationMatch) {
+ var loc = [parseFloat(locationMatch[0]), parseFloat(locationMatch[1])];
+ result.push({
+ id: -1,
+ geometry: 'point',
+ type: _t('inspector.location'),
+ name: dmsCoordinatePair([loc[1], loc[0]]),
+ location: loc
+ });
+ }
+
+ var allEntities = graph.entities;
+ var localResults = [];
+ for (var id in allEntities) {
+ var entity = allEntities[id];
+ if (!entity) continue;
+
+ var name = utilDisplayName(entity) || '';
+ if (name.toLowerCase().indexOf(q) < 0) continue;
+
+ var matched = _mainPresetIndex.match(entity, graph);
+ var type = (matched && matched.name()) || utilDisplayType(entity.id);
+ var extent = entity.extent(graph);
+ var distance = extent ? geoSphericalDistance(visibleCenter, extent.center()) : 0;
+
+ localResults.push({
+ id: entity.id,
+ entity: entity,
+ geometry: entity.geometry(graph),
+ type: type,
+ name: name,
+ distance: distance
+ });
+
+ if (localResults.length > 100) break;
+ }
+ localResults = localResults.sort(function byDistance(a, b) {
+ return a.distance - b.distance;
+ });
+ result = result.concat(localResults);
+
+ (_geocodeResults || []).forEach(function(d) {
+ if (d.osm_type && d.osm_id) { // some results may be missing these - #1890
+
+ // Make a temporary osmEntity so we can preset match
+ // and better localize the search result - #4725
+ var id = osmEntity.id.fromOSM(d.osm_type, d.osm_id);
+ var tags = {};
+ tags[d.class] = d.type;
+
+ var attrs = { id: id, type: d.osm_type, tags: tags };
+ if (d.osm_type === 'way') { // for ways, add some fake closed nodes
+ attrs.nodes = ['a','a']; // so that geometry area is possible
+ }
+
+ var tempEntity = osmEntity(attrs);
+ var tempGraph = coreGraph([tempEntity]);
+ var matched = _mainPresetIndex.match(tempEntity, tempGraph);
+ var type = (matched && matched.name()) || utilDisplayType(id);
+
+ result.push({
+ id: tempEntity.id,
+ geometry: tempEntity.geometry(tempGraph),
+ type: type,
+ name: d.display_name,
+ extent: new geoExtent(
+ [parseFloat(d.boundingbox[3]), parseFloat(d.boundingbox[0])],
+ [parseFloat(d.boundingbox[2]), parseFloat(d.boundingbox[1])])
+ });
+ }
+ });
+
+ if (q.match(/^[0-9]+$/)) {
+ // if query is just a number, possibly an OSM ID without a prefix
+ result.push({
+ id: 'n' + q,
+ geometry: 'point',
+ type: _t('inspector.node'),
+ name: q
+ });
+ result.push({
+ id: 'w' + q,
+ geometry: 'line',
+ type: _t('inspector.way'),
+ name: q
+ });
+ result.push({
+ id: 'r' + q,
+ geometry: 'relation',
+ type: _t('inspector.relation'),
+ name: q
+ });
+ }
+
+ return result;
+ }
+
+
+ function drawList() {
+ var value = search.property('value');
+ var results = features();
+
+ list.classed('filtered', value.length);
+
+ var resultsIndicator = list.selectAll('.no-results-item')
+ .data([0])
+ .enter()
+ .append('button')
+ .property('disabled', true)
+ .attr('class', 'no-results-item')
+ .call(svgIcon('#iD-icon-alert', 'pre-text'));
+
+ resultsIndicator.append('span')
+ .attr('class', 'entity-name');
+
+ list.selectAll('.no-results-item .entity-name')
+ .text(_t('geocoder.no_results_worldwide'));
+
+ if (services.geocoder) {
+ list.selectAll('.geocode-item')
+ .data([0])
+ .enter()
+ .append('button')
+ .attr('class', 'geocode-item')
+ .on('click', geocoderSearch)
+ .append('div')
+ .attr('class', 'label')
+ .append('span')
+ .attr('class', 'entity-name')
+ .text(_t('geocoder.search'));
+ }
+
+ list.selectAll('.no-results-item')
+ .style('display', (value.length && !results.length) ? 'block' : 'none');
+
+ list.selectAll('.geocode-item')
+ .style('display', (value && _geocodeResults === undefined) ? 'block' : 'none');
+
+ list.selectAll('.feature-list-item')
+ .data([-1])
+ .remove();
+
+ var items = list.selectAll('.feature-list-item')
+ .data(results, function(d) { return d.id; });
+
+ var enter = items.enter()
+ .insert('button', '.geocode-item')
+ .attr('class', 'feature-list-item')
+ .on('mouseover', mouseover)
+ .on('mouseout', mouseout)
+ .on('click', click);
+
+ var label = enter
+ .append('div')
+ .attr('class', 'label');
+
+ label
+ .each(function(d) {
+ select(this)
+ .call(svgIcon('#iD-icon-' + d.geometry, 'pre-text'));
+ });
+
+ label
+ .append('span')
+ .attr('class', 'entity-type')
+ .text(function(d) { return d.type; });
+
+ label
+ .append('span')
+ .attr('class', 'entity-name')
+ .text(function(d) { return d.name; });
+
+ enter
+ .style('opacity', 0)
+ .transition()
+ .style('opacity', 1);
+
+ items.order();
+
+ items.exit()
+ .remove();
+ }
+
+
+ function mouseover(d) {
+ if (d.id === -1) return;
+
+ utilHighlightEntities([d.id], true, context);
+ }
+
+
+ function mouseout(d) {
+ if (d.id === -1) return;
+
+ utilHighlightEntities([d.id], false, context);
+ }
+
+
+ function click(d) {
+ event.preventDefault();
+
+ if (d.location) {
+ context.map().centerZoomEase([d.location[1], d.location[0]], 19);
+
+ } else if (d.entity) {
+ utilHighlightEntities([d.id], false, context);
+
+ context.enter(modeSelect(context, [d.entity.id]));
+ context.map().zoomToEase(d.entity);
+
+ } else {
+ // download, zoom to, and select the entity with the given ID
+ context.zoomToEntity(d.id);
+ }
+ }
+
+
+ function geocoderSearch() {
+ services.geocoder.search(search.property('value'), function (err, resp) {
+ _geocodeResults = resp || [];
+ drawList();
+ });
+ }
+ }
+
+
+ return featureList;
+ }
+
+ function uiSectionEntityIssues(context) {
+
+ var _entityIDs = [];
+ var _issues = [];
+ var _activeIssueID;
+
+ var section = uiSection('entity-issues', context)
+ .shouldDisplay(function() {
+ return _issues.length > 0;
+ })
+ .title(function() {
+ return _t('issues.list_title', { count: _issues.length });
+ })
+ .disclosureContent(renderDisclosureContent);
+
+ context.validator()
+ .on('validated.entity_issues', function() {
+ // Refresh on validated events
+ reloadIssues();
+ section.reRender();
+ })
+ .on('focusedIssue.entity_issues', function(issue) {
+ makeActiveIssue(issue.id);
+ });
+
+ function reloadIssues() {
+ _issues = context.validator().getSharedEntityIssues(_entityIDs, { includeDisabledRules: true });
+ }
+
+ function makeActiveIssue(issueID) {
+ _activeIssueID = issueID;
+ section.selection().selectAll('.issue-container')
+ .classed('active', function(d) { return d.id === _activeIssueID; });
+ }
+
+ function renderDisclosureContent(selection) {
+
+ selection.classed('grouped-items-area', true);
+
+ _activeIssueID = _issues.length > 0 ? _issues[0].id : null;
+
+ var containers = selection.selectAll('.issue-container')
+ .data(_issues, function(d) { return d.id; });
+
+ // Exit
+ containers.exit()
+ .remove();
+
+ // Enter
+ var containersEnter = containers.enter()
+ .append('div')
+ .attr('class', 'issue-container');
+
+
+ var itemsEnter = containersEnter
+ .append('div')
+ .attr('class', function(d) { return 'issue severity-' + d.severity; })
+ .on('mouseover.highlight', function(d) {
+ // don't hover-highlight the selected entity
+ var ids = d.entityIds
+ .filter(function(e) { return _entityIDs.indexOf(e) === -1; });
+
+ utilHighlightEntities(ids, true, context);
+ })
+ .on('mouseout.highlight', function(d) {
+ var ids = d.entityIds
+ .filter(function(e) { return _entityIDs.indexOf(e) === -1; });
+
+ utilHighlightEntities(ids, false, context);
+ });
+
+ var labelsEnter = itemsEnter
+ .append('div')
+ .attr('class', 'issue-label')
+ .on('click', function(d) {
+
+ makeActiveIssue(d.id); // expand only the clicked item
+
+ var extent = d.extent(context.graph());
+ if (extent) {
+ var setZoom = Math.max(context.map().zoom(), 19);
+ context.map().unobscuredCenterZoomEase(extent.center(), setZoom);
+ }
+ });
+
+ var textEnter = labelsEnter
+ .append('span')
+ .attr('class', 'issue-text');
+
+ textEnter
+ .append('span')
+ .attr('class', 'issue-icon')
+ .each(function(d) {
+ var iconName = '#iD-icon-' + (d.severity === 'warning' ? 'alert' : 'error');
+ select(this)
+ .call(svgIcon(iconName));
+ });
+
+ textEnter
+ .append('span')
+ .attr('class', 'issue-message');
+
+
+ var infoButton = labelsEnter
+ .append('button')
+ .attr('class', 'issue-info-button')
+ .attr('title', _t('icons.information'))
+ .attr('tabindex', -1)
+ .call(svgIcon('#iD-icon-inspect'));
+
+ infoButton
+ .on('click', function () {
+ event.stopPropagation();
+ event.preventDefault();
+ this.blur(); // avoid keeping focus on the button - #4641
+
+ var container = select(this.parentNode.parentNode.parentNode);
+ var info = container.selectAll('.issue-info');
+ var isExpanded = info.classed('expanded');
+
+ if (isExpanded) {
+ info
+ .transition()
+ .duration(200)
+ .style('max-height', '0px')
+ .style('opacity', '0')
+ .on('end', function () {
+ info.classed('expanded', false);
+ });
+ } else {
+ info
+ .classed('expanded', true)
+ .transition()
+ .duration(200)
+ .style('max-height', '200px')
+ .style('opacity', '1')
+ .on('end', function () {
+ info.style('max-height', null);
+ });
+ }
+ });
+
+ itemsEnter
+ .append('ul')
+ .attr('class', 'issue-fix-list');
+
+ containersEnter
+ .append('div')
+ .attr('class', 'issue-info')
+ .style('max-height', '0')
+ .style('opacity', '0')
+ .each(function(d) {
+ if (typeof d.reference === 'function') {
+ select(this)
+ .call(d.reference);
+ } else {
+ select(this)
+ .text(_t('inspector.no_documentation_key'));
+ }
+ });
+
+
+ // Update
+ containers = containers
+ .merge(containersEnter)
+ .classed('active', function(d) { return d.id === _activeIssueID; });
+
+ containers.selectAll('.issue-message')
+ .text(function(d) {
+ return d.message(context);
+ });
+
+ // fixes
+ var fixLists = containers.selectAll('.issue-fix-list');
+
+ var fixes = fixLists.selectAll('.issue-fix-item')
+ .data(function(d) { return d.fixes ? d.fixes(context) : []; }, function(fix) { return fix.id; });
+
+ fixes.exit()
+ .remove();
+
+ var fixesEnter = fixes.enter()
+ .append('li')
+ .attr('class', 'issue-fix-item')
+ .on('click', function(d) {
+ // not all fixes are actionable
+ if (!select(this).classed('actionable') || !d.onClick) return;
+
+ // Don't run another fix for this issue within a second of running one
+ // (Necessary for "Select a feature type" fix. Most fixes should only ever run once)
+ if (d.issue.dateLastRanFix && new Date() - d.issue.dateLastRanFix < 1000) return;
+ d.issue.dateLastRanFix = new Date();
+
+ // remove hover-highlighting
+ utilHighlightEntities(d.issue.entityIds.concat(d.entityIds), false, context);
+
+ new Promise(function(resolve, reject) {
+ d.onClick(context, resolve, reject);
+ if (d.onClick.length <= 1) {
+ // if the fix doesn't take any completion parameters then consider it resolved
+ resolve();
+ }
+ })
+ .then(function() {
+ // revalidate whenever the fix has finished running successfully
+ context.validator().validate();
+ });
+ })
+ .on('mouseover.highlight', function(d) {
+ utilHighlightEntities(d.entityIds, true, context);
+ })
+ .on('mouseout.highlight', function(d) {
+ utilHighlightEntities(d.entityIds, false, context);
+ });
+
+ fixesEnter
+ .append('span')
+ .attr('class', 'fix-icon')
+ .each(function(d) {
+ var iconName = d.icon || 'iD-icon-wrench';
+ if (iconName.startsWith('maki')) {
+ iconName += '-15';
+ }
+ select(this).call(svgIcon('#' + iconName));
+ });
+
+ fixesEnter
+ .append('span')
+ .attr('class', 'fix-message')
+ .text(function(d) { return d.title; });
+
+ fixesEnter.merge(fixes)
+ .classed('actionable', function(d) {
+ return d.onClick;
+ })
+ .attr('title', function(d) {
+ if (d.disabledReason) {
+ return d.disabledReason;
+ }
+ return null;
+ });
+ }
+
+ section.entityIDs = function(val) {
+ if (!arguments.length) return _entityIDs;
+ if (!_entityIDs || !val || !utilArrayIdentical(_entityIDs, val)) {
+ _entityIDs = val;
+ _activeIssueID = null;
+ reloadIssues();
+ }
+ return section;
+ };
+
+ return section;
+ }
+
+ function uiPresetIcon() {
+ let _preset;
+ let _geometry;
+ let _sizeClass = 'medium';
+
+
+ function isSmall() {
+ return _sizeClass === 'small';
+ }
+
+
+ function presetIcon(selection) {
+ selection.each(render);
+ }
+
+
+ function getIcon(p, geom) {
+ if (isSmall() && p.isFallback && p.isFallback())
+ return 'iD-icon-' + p.id;
+ else if (p.icon)
+ return p.icon;
+ else if (geom === 'line')
+ return 'iD-other-line';
+ else if (geom === 'vertex')
+ return p.isFallback() ? '' : 'temaki-vertex';
+ else if (isSmall() && geom === 'point')
+ return '';
+ else
+ return 'maki-marker-stroked';
+ }
+
+
+ function renderPointBorder(enter) {
+ const w = 40;
+ const h = 40;
+
+ enter
+ .append('svg')
+ .attr('class', 'preset-icon-fill preset-icon-point-border')
+ .attr('width', w)
+ .attr('height', h)
+ .attr('viewBox', `0 0 ${w} ${h}`)
+ .append('path')
+ .attr('transform', 'translate(11.5, 8)')
+ .attr('d', 'M 17,8 C 17,13 11,21 8.5,23.5 C 6,21 0,13 0,8 C 0,4 4,-0.5 8.5,-0.5 C 13,-0.5 17,4 17,8 z');
+ }
+
+
+ function renderCircleFill(fillEnter) {
+ const w = 60;
+ const h = 60;
+ const d = 40;
+
+ fillEnter
+ .append('svg')
+ .attr('class', 'preset-icon-fill preset-icon-fill-vertex')
+ .attr('width', w)
+ .attr('height', h)
+ .attr('viewBox', `0 0 ${w} ${h}`)
+ .append('circle')
+ .attr('cx', w / 2)
+ .attr('cy', h / 2)
+ .attr('r', d / 2);
+ }
+
+
+ function renderSquareFill(fillEnter) {
+ const d = isSmall() ? 40 : 60;
+ const w = d;
+ const h = d;
+ const l = d * 2/3;
+ const c1 = (w-l) / 2;
+ const c2 = c1 + l;
+
+ fillEnter = fillEnter
+ .append('svg')
+ .attr('class', 'preset-icon-fill preset-icon-fill-area')
+ .attr('width', w)
+ .attr('height', h)
+ .attr('viewBox', `0 0 ${w} ${h}`);
+
+ ['fill', 'stroke'].forEach(klass => {
+ fillEnter
+ .append('path')
+ .attr('d', `M${c1} ${c1} L${c1} ${c2} L${c2} ${c2} L${c2} ${c1} Z`)
+ .attr('class', `line area ${klass}`);
+ });
+
+ const rVertex = 2.5;
+ [[c1, c1], [c1, c2], [c2, c2], [c2, c1]].forEach(point => {
+ fillEnter
+ .append('circle')
+ .attr('class', 'vertex')
+ .attr('cx', point[0])
+ .attr('cy', point[1])
+ .attr('r', rVertex);
+ });
+
+ if (!isSmall()) {
+ const rMidpoint = 1.25;
+ [[c1, w/2], [c2, w/2], [h/2, c1], [h/2, c2]].forEach(point => {
+ fillEnter
+ .append('circle')
+ .attr('class', 'midpoint')
+ .attr('cx', point[0])
+ .attr('cy', point[1])
+ .attr('r', rMidpoint);
+ });
+ }
+ }
+
+
+ function renderLine(lineEnter) {
+ const d = isSmall() ? 40 : 60;
+ // draw the line parametrically
+ const w = d;
+ const h = d;
+ const y = Math.round(d * 0.72);
+ const l = Math.round(d * 0.6);
+ const r = 2.5;
+ const x1 = (w - l) / 2;
+ const x2 = x1 + l;
+
+ lineEnter = lineEnter
+ .append('svg')
+ .attr('class', 'preset-icon-line')
+ .attr('width', w)
+ .attr('height', h)
+ .attr('viewBox', `0 0 ${w} ${h}`);
+
+ ['casing', 'stroke'].forEach(klass => {
+ lineEnter
+ .append('path')
+ .attr('d', `M${x1} ${y} L${x2} ${y}`)
+ .attr('class', `line ${klass}`);
+ });
+
+ [[x1-1, y], [x2+1, y]].forEach(point => {
+ lineEnter
+ .append('circle')
+ .attr('class', 'vertex')
+ .attr('cx', point[0])
+ .attr('cy', point[1])
+ .attr('r', r);
+ });
+ }
+
+
+ function renderRoute(routeEnter) {
+ const d = isSmall() ? 40 : 60;
+ // draw the route parametrically
+ const w = d;
+ const h = d;
+ const y1 = Math.round(d * 0.80);
+ const y2 = Math.round(d * 0.68);
+ const l = Math.round(d * 0.6);
+ const r = 2;
+ const x1 = (w - l) / 2;
+ const x2 = x1 + l / 3;
+ const x3 = x2 + l / 3;
+ const x4 = x3 + l / 3;
+
+ routeEnter = routeEnter
+ .append('svg')
+ .attr('class', 'preset-icon-route')
+ .attr('width', w)
+ .attr('height', h)
+ .attr('viewBox', `0 0 ${w} ${h}`);
+
+ ['casing', 'stroke'].forEach(klass => {
+ routeEnter
+ .append('path')
+ .attr('d', `M${x1} ${y1} L${x2} ${y2}`)
+ .attr('class', `segment0 line ${klass}`);
+ routeEnter
+ .append('path')
+ .attr('d', `M${x2} ${y2} L${x3} ${y1}`)
+ .attr('class', `segment1 line ${klass}`);
+ routeEnter
+ .append('path')
+ .attr('d', `M${x3} ${y1} L${x4} ${y2}`)
+ .attr('class', `segment2 line ${klass}`);
+ });
+
+ [[x1, y1], [x2, y2], [x3, y1], [x4, y2]].forEach(point => {
+ routeEnter
+ .append('circle')
+ .attr('class', 'vertex')
+ .attr('cx', point[0])
+ .attr('cy', point[1])
+ .attr('r', r);
+ });
+ }
+
+
+ // Route icons are drawn with a zigzag annotation underneath:
+ // o o
+ // / \ /
+ // o o
+ // This dataset defines the styles that are used to draw the zigzag segments.
+ const routeSegments = {
+ bicycle: ['highway/cycleway', 'highway/cycleway', 'highway/cycleway'],
+ bus: ['highway/unclassified', 'highway/secondary', 'highway/primary'],
+ trolleybus: ['highway/unclassified', 'highway/secondary', 'highway/primary'],
+ detour: ['highway/tertiary', 'highway/residential', 'highway/unclassified'],
+ ferry: ['route/ferry', 'route/ferry', 'route/ferry'],
+ foot: ['highway/footway', 'highway/footway', 'highway/footway'],
+ hiking: ['highway/path', 'highway/path', 'highway/path'],
+ horse: ['highway/bridleway', 'highway/bridleway', 'highway/bridleway'],
+ light_rail: ['railway/light_rail', 'railway/light_rail', 'railway/light_rail'],
+ monorail: ['railway/monorail', 'railway/monorail', 'railway/monorail'],
+ pipeline: ['man_made/pipeline', 'man_made/pipeline', 'man_made/pipeline'],
+ piste: ['piste/downhill', 'piste/hike', 'piste/nordic'],
+ power: ['power/line', 'power/line', 'power/line'],
+ road: ['highway/secondary', 'highway/primary', 'highway/trunk'],
+ subway: ['railway/subway', 'railway/subway', 'railway/subway'],
+ train: ['railway/rail', 'railway/rail', 'railway/rail'],
+ tram: ['railway/tram', 'railway/tram', 'railway/tram'],
+ waterway: ['waterway/stream', 'waterway/stream', 'waterway/stream']
+ };
+
+
+ function render() {
+ let p = _preset.apply(this, arguments);
+ let geom = _geometry ? _geometry.apply(this, arguments) : null;
+ if (geom === 'relation' && p.tags && ((p.tags.type === 'route' && p.tags.route && routeSegments[p.tags.route]) || p.tags.type === 'waterway')) {
+ geom = 'route';
+ }
+
+ const showThirdPartyIcons = corePreferences('preferences.privacy.thirdpartyicons') || 'true';
+ const isFallback = isSmall() && p.isFallback && p.isFallback();
+ const imageURL = (showThirdPartyIcons === 'true') && p.imageURL;
+ const picon = getIcon(p, geom);
+ const isMaki = picon && /^maki-/.test(picon);
+ const isTemaki = picon && /^temaki-/.test(picon);
+ const isFa = picon && /^fa[srb]-/.test(picon);
+ const isTnp = picon && /^tnp-/.test(picon);
+ const isiDIcon = picon && !(isMaki || isTemaki || isFa || isTnp);
+ const isCategory = !p.setTags;
+ const drawPoint = picon && geom === 'point' && isSmall() && !isFallback;
+ const drawVertex = picon !== null && geom === 'vertex' && (!isSmall() || !isFallback);
+ const drawLine = picon && geom === 'line' && !isFallback && !isCategory;
+ const drawArea = picon && geom === 'area' && !isFallback;
+ const drawRoute = picon && geom === 'route';
+ const isFramed = (drawVertex || drawArea || drawLine || drawRoute);
+
+ let tags = !isCategory ? p.setTags({}, geom) : {};
+ for (let k in tags) {
+ if (tags[k] === '*') {
+ tags[k] = 'yes';
+ }
+ }
+
+ let tagClasses = svgTagClasses().getClassesString(tags, '');
+ let selection = select(this);
+
+ let container = selection.selectAll('.preset-icon-container')
+ .data([0]);
+
+ container = container.enter()
+ .append('div')
+ .attr('class', `preset-icon-container ${_sizeClass}`)
+ .merge(container);
+
+ container
+ .classed('showing-img', !!imageURL)
+ .classed('fallback', isFallback);
+
+
+ let pointBorder = container.selectAll('.preset-icon-point-border')
+ .data(drawPoint ? [0] : []);
+
+ pointBorder.exit()
+ .remove();
+
+ let pointBorderEnter = pointBorder.enter();
+ renderPointBorder(pointBorderEnter);
+ pointBorder = pointBorderEnter.merge(pointBorder);
+
+
+ let vertexFill = container.selectAll('.preset-icon-fill-vertex')
+ .data(drawVertex ? [0] : []);
+
+ vertexFill.exit()
+ .remove();
+
+ let vertexFillEnter = vertexFill.enter();
+ renderCircleFill(vertexFillEnter);
+ vertexFill = vertexFillEnter.merge(vertexFill);
+
+
+ let fill = container.selectAll('.preset-icon-fill-area')
+ .data(drawArea ? [0] : []);
+
+ fill.exit()
+ .remove();
+
+ let fillEnter = fill.enter();
+ renderSquareFill(fillEnter);
+ fill = fillEnter.merge(fill);
+
+ fill.selectAll('path.stroke')
+ .attr('class', `area stroke ${tagClasses}`);
+ fill.selectAll('path.fill')
+ .attr('class', `area fill ${tagClasses}`);
+
+
+ let line = container.selectAll('.preset-icon-line')
+ .data(drawLine ? [0] : []);
+
+ line.exit()
+ .remove();
+
+ let lineEnter = line.enter();
+ renderLine(lineEnter);
+ line = lineEnter.merge(line);
+
+ line.selectAll('path.stroke')
+ .attr('class', `line stroke ${tagClasses}`);
+ line.selectAll('path.casing')
+ .attr('class', `line casing ${tagClasses}`);
+
+
+ let route = container.selectAll('.preset-icon-route')
+ .data(drawRoute ? [0] : []);
+
+ route.exit()
+ .remove();
+
+ let routeEnter = route.enter();
+ renderRoute(routeEnter);
+ route = routeEnter.merge(route);
+
+ if (drawRoute) {
+ let routeType = p.tags.type === 'waterway' ? 'waterway' : p.tags.route;
+ const segmentPresetIDs = routeSegments[routeType];
+ for (let i in segmentPresetIDs) {
+ const segmentPreset = _mainPresetIndex.item(segmentPresetIDs[i]);
+ const segmentTagClasses = svgTagClasses().getClassesString(segmentPreset.tags, '');
+ route.selectAll(`path.stroke.segment${i}`)
+ .attr('class', `segment${i} line stroke ${segmentTagClasses}`);
+ route.selectAll(`path.casing.segment${i}`)
+ .attr('class', `segment${i} line casing ${segmentTagClasses}`);
+ }
+ }
+
+
+ let icon = container.selectAll('.preset-icon')
+ .data(picon ? [0] : []);
+
+ icon.exit()
+ .remove();
+
+ icon = icon.enter()
+ .append('div')
+ .attr('class', 'preset-icon')
+ .call(svgIcon(''))
+ .merge(icon);
+
+ icon
+ .attr('class', 'preset-icon ' + (geom ? geom + '-geom' : ''))
+ .classed('framed', isFramed)
+ .classed('preset-icon-iD', isiDIcon);
+
+ icon.selectAll('svg')
+ .attr('class', 'icon ' + picon + ' ' + (!isiDIcon && geom !== 'line' ? '' : tagClasses));
+
+ icon.selectAll('use')
+ .attr('href', '#' + picon + (isMaki ? (isSmall() && geom === 'point' ? '-11' : '-15') : ''));
+
+ let imageIcon = container.selectAll('img.image-icon')
+ .data(imageURL ? [0] : []);
+
+ imageIcon.exit()
+ .remove();
+
+ imageIcon = imageIcon.enter()
+ .append('img')
+ .attr('class', 'image-icon')
+ .on('load', () => container.classed('showing-img', true) )
+ .on('error', () => container.classed('showing-img', false) )
+ .merge(imageIcon);
+
+ imageIcon
+ .attr('src', imageURL);
+ }
+
+
+ presetIcon.preset = function(val) {
+ if (!arguments.length) return _preset;
+ _preset = utilFunctor(val);
+ return presetIcon;
+ };
+
+
+ presetIcon.geometry = function(val) {
+ if (!arguments.length) return _geometry;
+ _geometry = utilFunctor(val);
+ return presetIcon;
+ };
+
+
+ presetIcon.sizeClass = function(val) {
+ if (!arguments.length) return _sizeClass;
+ _sizeClass = val;
+ return presetIcon;
+ };
+
+ return presetIcon;
+ }
+
+ function uiSectionFeatureType(context) {
+
+ var dispatch$1 = dispatch('choose');
+
+ var _entityIDs = [];
+ var _presets = [];
+
+ var _tagReference;
+
+ var section = uiSection('feature-type', context)
+ .title(_t('inspector.feature_type'))
+ .disclosureContent(renderDisclosureContent);
+
+ function renderDisclosureContent(selection) {
+
+ selection.classed('preset-list-item', true);
+ selection.classed('mixed-types', _presets.length > 1);
+
+ var presetButtonWrap = selection
+ .selectAll('.preset-list-button-wrap')
+ .data([0])
+ .enter()
+ .append('div')
+ .attr('class', 'preset-list-button-wrap');
+
+ var presetButton = presetButtonWrap
+ .append('button')
+ .attr('class', 'preset-list-button preset-reset')
+ .call(uiTooltip()
+ .title(_t('inspector.back_tooltip'))
+ .placement('bottom')
+ );
+
+ presetButton.append('div')
+ .attr('class', 'preset-icon-container');
+
+ presetButton
+ .append('div')
+ .attr('class', 'label')
+ .append('div')
+ .attr('class', 'label-inner');
+
+ presetButtonWrap.append('div')
+ .attr('class', 'accessory-buttons');
+
+ var tagReferenceBodyWrap = selection
+ .selectAll('.tag-reference-body-wrap')
+ .data([0]);
+
+ tagReferenceBodyWrap = tagReferenceBodyWrap
+ .enter()
+ .append('div')
+ .attr('class', 'tag-reference-body-wrap')
+ .merge(tagReferenceBodyWrap);
+
+ // update header
+ if (_tagReference) {
+ selection.selectAll('.preset-list-button-wrap .accessory-buttons')
+ .style('display', _presets.length === 1 ? null : 'none')
+ .call(_tagReference.button);
+
+ tagReferenceBodyWrap
+ .style('display', _presets.length === 1 ? null : 'none')
+ .call(_tagReference.body);
+ }
+
+ selection.selectAll('.preset-reset')
+ .on('click', function() {
+ dispatch$1.call('choose', this, _presets);
+ })
+ .on('pointerdown pointerup mousedown mouseup', function() {
+ event.preventDefault();
+ event.stopPropagation();
+ });
+
+ var geometries = entityGeometries();
+ selection.select('.preset-list-item button')
+ .call(uiPresetIcon()
+ .geometry(_presets.length === 1 ? (geometries.length === 1 && geometries[0]) : null)
+ .preset(_presets.length === 1 ? _presets[0] : _mainPresetIndex.item('point'))
+ );
+
+ // NOTE: split on en-dash, not a hypen (to avoid conflict with hyphenated names)
+ var names = _presets.length === 1 ? _presets[0].name().split(' – ') : [_t('inspector.multiple_types')];
+
+ var label = selection.select('.label-inner');
+ var nameparts = label.selectAll('.namepart')
+ .data(names, function(d) { return d; });
+
+ nameparts.exit()
+ .remove();
+
+ nameparts
+ .enter()
+ .append('div')
+ .attr('class', 'namepart')
+ .text(function(d) { return d; });
+ }
+
+ section.entityIDs = function(val) {
+ if (!arguments.length) return _entityIDs;
+ _entityIDs = val;
+ return section;
+ };
+
+ section.presets = function(val) {
+ if (!arguments.length) return _presets;
+
+ // don't reload the same preset
+ if (!utilArrayIdentical(val, _presets)) {
+ _presets = val;
+
+ var geometries = entityGeometries();
+ if (_presets.length === 1 && geometries.length) {
+ _tagReference = uiTagReference(_presets[0].reference(geometries[0]))
+ .showing(false);
+ }
+ }
+
+ return section;
+ };
+
+ function entityGeometries() {
+
+ var counts = {};
+
+ for (var i in _entityIDs) {
+ var geometry = context.graph().geometry(_entityIDs[i]);
+ if (!counts[geometry]) counts[geometry] = 0;
+ counts[geometry] += 1;
+ }
+
+ return Object.keys(counts).sort(function(geom1, geom2) {
+ return counts[geom2] - counts[geom1];
+ });
+ }
+
+ return utilRebind(section, dispatch$1, 'on');
+ }
+
+ function uiSectionPresetFields(context) {
+
+ var section = uiSection('preset-fields', context)
+ .title(function() {
+ return _t('inspector.fields');
+ })
+ .disclosureContent(renderDisclosureContent);
+
+ var dispatch$1 = dispatch('change', 'revert');
+ var formFields = uiFormFields(context);
+ var _state;
+ var _fieldsArr;
+ var _presets = [];
+ var _tags;
+ var _entityIDs;
+
+ function renderDisclosureContent(selection) {
+ if (!_fieldsArr) {
+
+ var graph = context.graph();
+
+ var geometries = Object.keys(_entityIDs.reduce(function(geoms, entityID) {
+ return geoms[graph.entity(entityID).geometry(graph)] = true;
+ }, {}));
+
+ var presetsManager = _mainPresetIndex;
+
+ var allFields = [];
+ var allMoreFields = [];
+ var sharedTotalFields;
+
+ _presets.forEach(function(preset) {
+ var fields = preset.fields();
+ var moreFields = preset.moreFields();
+
+ allFields = utilArrayUnion(allFields, fields);
+ allMoreFields = utilArrayUnion(allMoreFields, moreFields);
+
+ if (!sharedTotalFields) {
+ sharedTotalFields = utilArrayUnion(fields, moreFields);
+ } else {
+ sharedTotalFields = sharedTotalFields.filter(function(field) {
+ return fields.indexOf(field) !== -1 || moreFields.indexOf(field) !== -1;
+ });
+ }
+ });
+
+ var sharedFields = allFields.filter(function(field) {
+ return sharedTotalFields.indexOf(field) !== -1;
+ });
+ var sharedMoreFields = allMoreFields.filter(function(field) {
+ return sharedTotalFields.indexOf(field) !== -1;
+ });
+
+ _fieldsArr = [];
+
+ sharedFields.forEach(function(field) {
+ if (field.matchAllGeometry(geometries)) {
+ _fieldsArr.push(
+ uiField(context, field, _entityIDs)
+ );
+ }
+ });
+
+ var singularEntity = _entityIDs.length === 1 && graph.hasEntity(_entityIDs[0]);
+ if (singularEntity && singularEntity.isHighwayIntersection(graph) && presetsManager.field('restrictions')) {
+ _fieldsArr.push(
+ uiField(context, presetsManager.field('restrictions'), _entityIDs)
+ );
+ }
+
+ var additionalFields = utilArrayUnion(sharedMoreFields, presetsManager.universal());
+ additionalFields.sort(function(field1, field2) {
+ return field1.label().localeCompare(field2.label(), _mainLocalizer.localeCode());
+ });
+
+ additionalFields.forEach(function(field) {
+ if (sharedFields.indexOf(field) === -1 &&
+ field.matchAllGeometry(geometries)) {
+ _fieldsArr.push(
+ uiField(context, field, _entityIDs, { show: false })
+ );
+ }
+ });
+
+ _fieldsArr.forEach(function(field) {
+ field
+ .on('change', function(t, onInput) {
+ dispatch$1.call('change', field, _entityIDs, t, onInput);
+ })
+ .on('revert', function(keys) {
+ dispatch$1.call('revert', field, keys);
+ });
+ });
+ }
+
+ _fieldsArr.forEach(function(field) {
+ field
+ .state(_state)
+ .tags(_tags);
+ });
+
+
+ selection
+ .call(formFields
+ .fieldsArr(_fieldsArr)
+ .state(_state)
+ .klass('grouped-items-area')
+ );
+
+
+ selection.selectAll('.wrap-form-field input')
+ .on('keydown', function() {
+ // if user presses enter, and combobox is not active, accept edits..
+ if (event.keyCode === 13 && context.container().select('.combobox').empty()) {
+ context.enter(modeBrowse(context));
+ }
+ });
+ }
+
+ section.presets = function(val) {
+ if (!arguments.length) return _presets;
+ if (!_presets || !val || !utilArrayIdentical(_presets, val)) {
+ _presets = val;
+ _fieldsArr = null;
+ }
+ return section;
+ };
+
+ section.state = function(val) {
+ if (!arguments.length) return _state;
+ _state = val;
+ return section;
+ };
+
+ section.tags = function(val) {
+ if (!arguments.length) return _tags;
+ _tags = val;
+ // Don't reset _fieldsArr here.
+ return section;
+ };
+
+ section.entityIDs = function(val) {
+ if (!arguments.length) return _entityIDs;
+ if (!val || !_entityIDs || !utilArrayIdentical(_entityIDs, val)) {
+ _entityIDs = val;
+ _fieldsArr = null;
+ }
+ return section;
+ };
+
+ return utilRebind(section, dispatch$1, 'on');
+ }
+
+ function uiSectionRawMemberEditor(context) {
+
+ var section = uiSection('raw-member-editor', context)
+ .shouldDisplay(function() {
+ if (!_entityIDs || _entityIDs.length !== 1) return false;
+
+ var entity = context.hasEntity(_entityIDs[0]);
+ return entity && entity.type === 'relation';
+ })
+ .title(function() {
+ var entity = context.hasEntity(_entityIDs[0]);
+ if (!entity) return '';
+
+ var gt = entity.members.length > _maxMembers ? '>' : '';
+ var count = gt + entity.members.slice(0, _maxMembers).length;
+ return _t('inspector.title_count', { title: _t('inspector.members'), count: count });
+ })
+ .disclosureContent(renderDisclosureContent);
+
+ var taginfo = services.taginfo;
+ var _entityIDs;
+ var _maxMembers = 1000;
+
+ function downloadMember(d) {
+ event.preventDefault();
+
+ // display the loading indicator
+ select(this.parentNode).classed('tag-reference-loading', true);
+ context.loadEntity(d.id, function() {
+ section.reRender();
+ });
+ }
+
+ function zoomToMember(d) {
+ event.preventDefault();
+
+ var entity = context.entity(d.id);
+ context.map().zoomToEase(entity);
+
+ // highlight the feature in case it wasn't previously on-screen
+ utilHighlightEntities([d.id], true, context);
+ }
+
+
+ function selectMember(d) {
+ event.preventDefault();
+
+ // remove the hover-highlight styling
+ utilHighlightEntities([d.id], false, context);
+
+ var entity = context.entity(d.id);
+ var mapExtent = context.map().extent();
+ if (!entity.intersects(mapExtent, context.graph())) {
+ // zoom to the entity if its extent is not visible now
+ context.map().zoomToEase(entity);
+ }
+
+ context.enter(modeSelect(context, [d.id]));
+ }
+
+
+ function changeRole(d) {
+ var oldRole = d.role;
+ var newRole = context.cleanRelationRole(select(this).property('value'));
+
+ if (oldRole !== newRole) {
+ var member = { id: d.id, type: d.type, role: newRole };
+ context.perform(
+ actionChangeMember(d.relation.id, member, d.index),
+ _t('operations.change_role.annotation')
+ );
+ }
+ }
+
+
+ function deleteMember(d) {
+
+ // remove the hover-highlight styling
+ utilHighlightEntities([d.id], false, context);
+
+ context.perform(
+ actionDeleteMember(d.relation.id, d.index),
+ _t('operations.delete_member.annotation')
+ );
+
+ if (!context.hasEntity(d.relation.id)) {
+ context.enter(modeBrowse(context));
+ }
+ }
+
+ function renderDisclosureContent(selection) {
+
+ var entityID = _entityIDs[0];
+
+ var memberships = [];
+ var entity = context.entity(entityID);
+ entity.members.slice(0, _maxMembers).forEach(function(member, index) {
+ memberships.push({
+ index: index,
+ id: member.id,
+ type: member.type,
+ role: member.role,
+ relation: entity,
+ member: context.hasEntity(member.id),
+ domId: utilUniqueDomId(entityID + '-member-' + index)
+ });
+ });
+
+ var list = selection.selectAll('.member-list')
+ .data([0]);
+
+ list = list.enter()
+ .append('ul')
+ .attr('class', 'member-list')
+ .merge(list);
+
+
+ var items = list.selectAll('li')
+ .data(memberships, function(d) {
+ return osmEntity.key(d.relation) + ',' + d.index + ',' +
+ (d.member ? osmEntity.key(d.member) : 'incomplete');
+ });
+
+ items.exit()
+ .each(unbind)
+ .remove();
+
+ var itemsEnter = items.enter()
+ .append('li')
+ .attr('class', 'member-row form-field')
+ .classed('member-incomplete', function(d) { return !d.member; });
+
+ itemsEnter
+ .each(function(d) {
+ var item = select(this);
+
+ var label = item
+ .append('label')
+ .attr('class', 'field-label')
+ .attr('for', d.domId);
+
+ if (d.member) {
+ // highlight the member feature in the map while hovering on the list item
+ item
+ .on('mouseover', function() {
+ utilHighlightEntities([d.id], true, context);
+ })
+ .on('mouseout', function() {
+ utilHighlightEntities([d.id], false, context);
+ });
+
+ var labelLink = label
+ .append('span')
+ .attr('class', 'label-text')
+ .append('a')
+ .attr('href', '#')
+ .on('click', selectMember);
+
+ labelLink
+ .append('span')
+ .attr('class', 'member-entity-type')
+ .text(function(d) {
+ var matched = _mainPresetIndex.match(d.member, context.graph());
+ return (matched && matched.name()) || utilDisplayType(d.member.id);
+ });
+
+ labelLink
+ .append('span')
+ .attr('class', 'member-entity-name')
+ .text(function(d) { return utilDisplayName(d.member); });
+
+ label
+ .append('button')
+ .attr('tabindex', -1)
+ .attr('title', _t('icons.remove'))
+ .attr('class', 'remove member-delete')
+ .call(svgIcon('#iD-operation-delete'));
+
+ label
+ .append('button')
+ .attr('class', 'member-zoom')
+ .attr('title', _t('icons.zoom_to'))
+ .call(svgIcon('#iD-icon-framed-dot', 'monochrome'))
+ .on('click', zoomToMember);
+
+ } else {
+ var labelText = label
+ .append('span')
+ .attr('class', 'label-text');
+
+ labelText
+ .append('span')
+ .attr('class', 'member-entity-type')
+ .text(_t('inspector.' + d.type, { id: d.id }));
+
+ labelText
+ .append('span')
+ .attr('class', 'member-entity-name')
+ .text(_t('inspector.incomplete', { id: d.id }));
+
+ label
+ .append('button')
+ .attr('class', 'member-download')
+ .attr('title', _t('icons.download'))
+ .attr('tabindex', -1)
+ .call(svgIcon('#iD-icon-load'))
+ .on('click', downloadMember);
+ }
+ });
+
+ var wrapEnter = itemsEnter
+ .append('div')
+ .attr('class', 'form-field-input-wrap form-field-input-member');
+
+ wrapEnter
+ .append('input')
+ .attr('class', 'member-role')
+ .attr('id', function(d) {
+ return d.domId;
+ })
+ .property('type', 'text')
+ .attr('placeholder', _t('inspector.role'))
+ .call(utilNoAuto);
+
+ if (taginfo) {
+ wrapEnter.each(bindTypeahead);
+ }
+
+ // update
+ items = items
+ .merge(itemsEnter)
+ .order();
+
+ items.select('input.member-role')
+ .property('value', function(d) { return d.role; })
+ .on('blur', changeRole)
+ .on('change', changeRole);
+
+ items.select('button.member-delete')
+ .on('click', deleteMember);
+
+ var dragOrigin, targetIndex;
+
+ items.call(d3_drag()
+ .on('start', function() {
+ dragOrigin = {
+ x: event.x,
+ y: event.y
+ };
+ targetIndex = null;
+ })
+ .on('drag', function(d, index) {
+ var x = event.x - dragOrigin.x,
+ y = event.y - dragOrigin.y;
+
+ if (!select(this).classed('dragging') &&
+ // don't display drag until dragging beyond a distance threshold
+ Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)) <= 5) return;
+
+ select(this)
+ .classed('dragging', true);
+
+ targetIndex = null;
+
+ selection.selectAll('li.member-row')
+ .style('transform', function(d2, index2) {
+ var node = select(this).node();
+ if (index === index2) {
+ return 'translate(' + x + 'px, ' + y + 'px)';
+ } else if (index2 > index && event.y > node.offsetTop) {
+ if (targetIndex === null || index2 > targetIndex) {
+ targetIndex = index2;
+ }
+ return 'translateY(-100%)';
+ } else if (index2 < index && event.y < node.offsetTop + node.offsetHeight) {
+ if (targetIndex === null || index2 < targetIndex) {
+ targetIndex = index2;
+ }
+ return 'translateY(100%)';
+ }
+ return null;
+ });
+ })
+ .on('end', function(d, index) {
+
+ if (!select(this).classed('dragging')) {
+ return;
+ }
+
+ select(this)
+ .classed('dragging', false);
+
+ selection.selectAll('li.member-row')
+ .style('transform', null);
+
+ if (targetIndex !== null) {
+ // dragged to a new position, reorder
+ context.perform(
+ actionMoveMember(d.relation.id, index, targetIndex),
+ _t('operations.reorder_members.annotation')
+ );
+ }
+ })
+ );
+
+
+
+ function bindTypeahead(d) {
+ var row = select(this);
+ var role = row.selectAll('input.member-role');
+ var origValue = role.property('value');
+
+ function sort(value, data) {
+ var sameletter = [];
+ var other = [];
+ for (var i = 0; i < data.length; i++) {
+ if (data[i].value.substring(0, value.length) === value) {
+ sameletter.push(data[i]);
+ } else {
+ other.push(data[i]);
+ }
+ }
+ return sameletter.concat(other);
+ }
+
+ role.call(uiCombobox(context, 'member-role')
+ .fetcher(function(role, callback) {
+ // The `geometry` param is used in the `taginfo.js` interface for
+ // filtering results, as a key into the `tag_members_fractions`
+ // object. If we don't know the geometry because the member is
+ // not yet downloaded, it's ok to guess based on type.
+ var geometry;
+ if (d.member) {
+ geometry = context.graph().geometry(d.member.id);
+ } else if (d.type === 'relation') {
+ geometry = 'relation';
+ } else if (d.type === 'way') {
+ geometry = 'line';
+ } else {
+ geometry = 'point';
+ }
+
+ var rtype = entity.tags.type;
+ taginfo.roles({
+ debounce: true,
+ rtype: rtype || '',
+ geometry: geometry,
+ query: role
+ }, function(err, data) {
+ if (!err) callback(sort(role, data));
+ });
+ })
+ .on('cancel', function() {
+ role.property('value', origValue);
+ })
+ );
+ }
+
+
+ function unbind() {
+ var row = select(this);
+
+ row.selectAll('input.member-role')
+ .call(uiCombobox.off, context);
+ }
+ }
+
+ section.entityIDs = function(val) {
+ if (!arguments.length) return _entityIDs;
+ _entityIDs = val;
+ return section;
+ };
+
+
+ return section;
+ }
+
+ function uiSectionRawMembershipEditor(context) {
+
+ var section = uiSection('raw-membership-editor', context)
+ .shouldDisplay(function() {
+ return _entityIDs && _entityIDs.length === 1;
+ })
+ .title(function() {
+ var entity = context.hasEntity(_entityIDs[0]);
+ if (!entity) return '';
+
+ var parents = context.graph().parentRelations(entity);
+ var gt = parents.length > _maxMemberships ? '>' : '';
+ var count = gt + parents.slice(0, _maxMemberships).length;
+ return _t('inspector.title_count', { title: _t('inspector.relations'), count: count });
+ })
+ .disclosureContent(renderDisclosureContent);
+
+ var taginfo = services.taginfo;
+ var nearbyCombo = uiCombobox(context, 'parent-relation')
+ .minItems(1)
+ .fetcher(fetchNearbyRelations)
+ .itemsMouseEnter(function(d) {
+ if (d.relation) utilHighlightEntities([d.relation.id], true, context);
+ })
+ .itemsMouseLeave(function(d) {
+ if (d.relation) utilHighlightEntities([d.relation.id], false, context);
+ });
+ var _inChange = false;
+ var _entityIDs = [];
+ var _showBlank;
+ var _maxMemberships = 1000;
+
+ function selectRelation(d) {
+ event.preventDefault();
+
+ // remove the hover-highlight styling
+ utilHighlightEntities([d.relation.id], false, context);
+
+ context.enter(modeSelect(context, [d.relation.id]));
+ }
+
+ function zoomToRelation(d) {
+ event.preventDefault();
+
+ var entity = context.entity(d.relation.id);
+ context.map().zoomToEase(entity);
+
+ // highlight the relation in case it wasn't previously on-screen
+ utilHighlightEntities([d.relation.id], true, context);
+ }
+
+
+ function changeRole(d) {
+ if (d === 0) return; // called on newrow (shoudn't happen)
+ if (_inChange) return; // avoid accidental recursive call #5731
+
+ var oldRole = d.member.role;
+ var newRole = context.cleanRelationRole(select(this).property('value'));
+
+ if (oldRole !== newRole) {
+ _inChange = true;
+ context.perform(
+ actionChangeMember(d.relation.id, Object.assign({}, d.member, { role: newRole }), d.index),
+ _t('operations.change_role.annotation')
+ );
+ }
+ _inChange = false;
+ }
+
+
+ function addMembership(d, role) {
+ this.blur(); // avoid keeping focus on the button
+ _showBlank = false;
+
+ var member = { id: _entityIDs[0], type: context.entity(_entityIDs[0]).type, role: role };
+
+ if (d.relation) {
+ context.perform(
+ actionAddMember(d.relation.id, member),
+ _t('operations.add_member.annotation')
+ );
+
+ } else {
+ var relation = osmRelation();
+ context.perform(
+ actionAddEntity(relation),
+ actionAddMember(relation.id, member),
+ _t('operations.add.annotation.relation')
+ );
+
+ context.enter(modeSelect(context, [relation.id]).newFeature(true));
+ }
+ }
+
+
+ function deleteMembership(d) {
+ this.blur(); // avoid keeping focus on the button
+ if (d === 0) return; // called on newrow (shoudn't happen)
+
+ // remove the hover-highlight styling
+ utilHighlightEntities([d.relation.id], false, context);
+
+ context.perform(
+ actionDeleteMember(d.relation.id, d.index),
+ _t('operations.delete_member.annotation')
+ );
+ }
+
+
+ function fetchNearbyRelations(q, callback) {
+ var newRelation = { relation: null, value: _t('inspector.new_relation') };
+
+ var entityID = _entityIDs[0];
+
+ var result = [];
+
+ var graph = context.graph();
+
+ function baseDisplayLabel(entity) {
+ var matched = _mainPresetIndex.match(entity, graph);
+ var presetName = (matched && matched.name()) || _t('inspector.relation');
+ var entityName = utilDisplayName(entity) || '';
+
+ return presetName + ' ' + entityName;
+ }
+
+ var explicitRelation = q && context.hasEntity(q.toLowerCase());
+ if (explicitRelation && explicitRelation.type === 'relation' && explicitRelation.id !== entityID) {
+ // loaded relation is specified explicitly, only show that
+
+ result.push({
+ relation: explicitRelation,
+ value: baseDisplayLabel(explicitRelation) + ' ' + explicitRelation.id
+ });
+ } else {
+
+ context.history().intersects(context.map().extent()).forEach(function(entity) {
+ if (entity.type !== 'relation' || entity.id === entityID) return;
+
+ var value = baseDisplayLabel(entity);
+ if (q && (value + ' ' + entity.id).toLowerCase().indexOf(q.toLowerCase()) === -1) return;
+
+ result.push({ relation: entity, value: value });
+ });
+
+ result.sort(function(a, b) {
+ return osmRelation.creationOrder(a.relation, b.relation);
+ });
+
+ // Dedupe identical names by appending relation id - see #2891
+ var dupeGroups = Object.values(utilArrayGroupBy(result, 'value'))
+ .filter(function(v) { return v.length > 1; });
+
+ dupeGroups.forEach(function(group) {
+ group.forEach(function(obj) {
+ obj.value += ' ' + obj.relation.id;
+ });
+ });
+ }
+
+ result.forEach(function(obj) {
+ obj.title = obj.value;
+ });
+
+ result.unshift(newRelation);
+ callback(result);
+ }
+
+ function renderDisclosureContent(selection) {
+
+ var entityID = _entityIDs[0];
+
+ var entity = context.entity(entityID);
+ var parents = context.graph().parentRelations(entity);
+
+ var memberships = [];
+
+ parents.slice(0, _maxMemberships).forEach(function(relation) {
+ relation.members.forEach(function(member, index) {
+ if (member.id === entity.id) {
+ memberships.push({
+ relation: relation,
+ member: member,
+ index: index,
+ domId: utilUniqueDomId(entityID + '-membership-' + relation.id + '-' + index)
+ });
+ }
+ });
+ });
+
+ var list = selection.selectAll('.member-list')
+ .data([0]);
+
+ list = list.enter()
+ .append('ul')
+ .attr('class', 'member-list')
+ .merge(list);
+
+
+ var items = list.selectAll('li.member-row-normal')
+ .data(memberships, function(d) {
+ return osmEntity.key(d.relation) + ',' + d.index;
+ });
+
+ items.exit()
+ .each(unbind)
+ .remove();
+
+ // Enter
+ var itemsEnter = items.enter()
+ .append('li')
+ .attr('class', 'member-row member-row-normal form-field');
+
+ // highlight the relation in the map while hovering on the list item
+ itemsEnter.on('mouseover', function(d) {
+ utilHighlightEntities([d.relation.id], true, context);
+ })
+ .on('mouseout', function(d) {
+ utilHighlightEntities([d.relation.id], false, context);
+ });
+
+ var labelEnter = itemsEnter
+ .append('label')
+ .attr('class', 'field-label')
+ .attr('for', function(d) {
+ return d.domId;
+ });
+
+ var labelLink = labelEnter
+ .append('span')
+ .attr('class', 'label-text')
+ .append('a')
+ .attr('href', '#')
+ .on('click', selectRelation);
+
+ labelLink
+ .append('span')
+ .attr('class', 'member-entity-type')
+ .text(function(d) {
+ var matched = _mainPresetIndex.match(d.relation, context.graph());
+ return (matched && matched.name()) || _t('inspector.relation');
+ });
+
+ labelLink
+ .append('span')
+ .attr('class', 'member-entity-name')
+ .text(function(d) { return utilDisplayName(d.relation); });
+
+ labelEnter
+ .append('button')
+ .attr('tabindex', -1)
+ .attr('class', 'remove member-delete')
+ .call(svgIcon('#iD-operation-delete'))
+ .on('click', deleteMembership);
+
+ labelEnter
+ .append('button')
+ .attr('class', 'member-zoom')
+ .attr('title', _t('icons.zoom_to'))
+ .call(svgIcon('#iD-icon-framed-dot', 'monochrome'))
+ .on('click', zoomToRelation);
+
+ var wrapEnter = itemsEnter
+ .append('div')
+ .attr('class', 'form-field-input-wrap form-field-input-member');
+
+ wrapEnter
+ .append('input')
+ .attr('class', 'member-role')
+ .attr('id', function(d) {
+ return d.domId;
+ })
+ .property('type', 'text')
+ .attr('placeholder', _t('inspector.role'))
+ .call(utilNoAuto)
+ .property('value', function(d) { return d.member.role; })
+ .on('blur', changeRole)
+ .on('change', changeRole);
+
+ if (taginfo) {
+ wrapEnter.each(bindTypeahead);
+ }
+
+
+ var newMembership = list.selectAll('.member-row-new')
+ .data(_showBlank ? [0] : []);
+
+ // Exit
+ newMembership.exit()
+ .remove();
+
+ // Enter
+ var newMembershipEnter = newMembership.enter()
+ .append('li')
+ .attr('class', 'member-row member-row-new form-field');
+
+ var newLabelEnter = newMembershipEnter
+ .append('label')
+ .attr('class', 'field-label');
+
+ newLabelEnter
+ .append('input')
+ .attr('placeholder', _t('inspector.choose_relation'))
+ .attr('type', 'text')
+ .attr('class', 'member-entity-input')
+ .call(utilNoAuto);
+
+ newLabelEnter
+ .append('button')
+ .attr('tabindex', -1)
+ .attr('class', 'remove member-delete')
+ .call(svgIcon('#iD-operation-delete'))
+ .on('click', function() {
+ list.selectAll('.member-row-new')
+ .remove();
+ });
+
+ var newWrapEnter = newMembershipEnter
+ .append('div')
+ .attr('class', 'form-field-input-wrap form-field-input-member');
+
+ newWrapEnter
+ .append('input')
+ .attr('class', 'member-role')
+ .property('type', 'text')
+ .attr('placeholder', _t('inspector.role'))
+ .call(utilNoAuto);
+
+ // Update
+ newMembership = newMembership
+ .merge(newMembershipEnter);
+
+ newMembership.selectAll('.member-entity-input')
+ .on('blur', cancelEntity) // if it wasn't accepted normally, cancel it
+ .call(nearbyCombo
+ .on('accept', acceptEntity)
+ .on('cancel', cancelEntity)
+ );
+
+
+ // Container for the Add button
+ var addRow = selection.selectAll('.add-row')
+ .data([0]);
+
+ // enter
+ var addRowEnter = addRow.enter()
+ .append('div')
+ .attr('class', 'add-row');
+
+ var addRelationButton = addRowEnter
+ .append('button')
+ .attr('class', 'add-relation');
+
+ addRelationButton
+ .call(svgIcon('#iD-icon-plus', 'light'));
+ addRelationButton
+ .call(uiTooltip().title(_t('inspector.add_to_relation')).placement(_mainLocalizer.textDirection() === 'ltr' ? 'right' : 'left'));
+
+ addRowEnter
+ .append('div')
+ .attr('class', 'space-value'); // preserve space
+
+ addRowEnter
+ .append('div')
+ .attr('class', 'space-buttons'); // preserve space
+
+ // update
+ addRow = addRow
+ .merge(addRowEnter);
+
+ addRow.select('.add-relation')
+ .on('click', function() {
+ _showBlank = true;
+ section.reRender();
+ list.selectAll('.member-entity-input').node().focus();
+ });
+
+
+ function acceptEntity(d) {
+ if (!d) {
+ cancelEntity();
+ return;
+ }
+ // remove hover-higlighting
+ if (d.relation) utilHighlightEntities([d.relation.id], false, context);
+
+ var role = context.cleanRelationRole(list.selectAll('.member-row-new .member-role').property('value'));
+ addMembership(d, role);
+ }
+
+
+ function cancelEntity() {
+ var input = newMembership.selectAll('.member-entity-input');
+ input.property('value', '');
+
+ // remove hover-higlighting
+ context.surface().selectAll('.highlighted')
+ .classed('highlighted', false);
+ }
+
+
+ function bindTypeahead(d) {
+ var row = select(this);
+ var role = row.selectAll('input.member-role');
+ var origValue = role.property('value');
+
+ function sort(value, data) {
+ var sameletter = [];
+ var other = [];
+ for (var i = 0; i < data.length; i++) {
+ if (data[i].value.substring(0, value.length) === value) {
+ sameletter.push(data[i]);
+ } else {
+ other.push(data[i]);
+ }
+ }
+ return sameletter.concat(other);
+ }
+
+ role.call(uiCombobox(context, 'member-role')
+ .fetcher(function(role, callback) {
+ var rtype = d.relation.tags.type;
+ taginfo.roles({
+ debounce: true,
+ rtype: rtype || '',
+ geometry: context.graph().geometry(entityID),
+ query: role
+ }, function(err, data) {
+ if (!err) callback(sort(role, data));
+ });
+ })
+ .on('cancel', function() {
+ role.property('value', origValue);
+ })
+ );
+ }
+
+
+ function unbind() {
+ var row = select(this);
+
+ row.selectAll('input.member-role')
+ .call(uiCombobox.off, context);
+ }
+ }
+
+
+ section.entityIDs = function(val) {
+ if (!arguments.length) return _entityIDs;
+ _entityIDs = val;
+ _showBlank = false;
+ return section;
+ };
+
+
+ return section;
+ }
+
+ function uiSectionSelectionList(context) {
+
+ var _selectedIDs = [];
+
+ var section = uiSection('selected-features', context)
+ .shouldDisplay(function() {
+ return _selectedIDs.length > 1;
+ })
+ .title(function() {
+ return _t('inspector.title_count', { title: _t('inspector.features'), count: _selectedIDs.length });
+ })
+ .disclosureContent(renderDisclosureContent);
+
+ context.history()
+ .on('change.selectionList', function(difference) {
+ if (difference) {
+ section.reRender();
+ }
+ });
+
+ section.entityIDs = function(val) {
+ if (!arguments.length) return _selectedIDs;
+ _selectedIDs = val;
+ return section;
+ };
+
+ function selectEntity(entity) {
+ context.enter(modeSelect(context, [entity.id]));
+ }
+
+ function deselectEntity(entity) {
+ event.stopPropagation();
+
+ var selectedIDs = _selectedIDs.slice();
+ var index = selectedIDs.indexOf(entity.id);
+ if (index > -1) {
+ selectedIDs.splice(index, 1);
+ context.enter(modeSelect(context, selectedIDs));
+ }
+ }
+
+ function renderDisclosureContent(selection) {
+
+ var list = selection.selectAll('.feature-list')
+ .data([0]);
+
+ list = list.enter()
+ .append('div')
+ .attr('class', 'feature-list')
+ .merge(list);
+
+ var entities = _selectedIDs
+ .map(function(id) { return context.hasEntity(id); })
+ .filter(Boolean);
+
+ var items = list.selectAll('.feature-list-item')
+ .data(entities, osmEntity.key);
+
+ items.exit()
+ .remove();
+
+ // Enter
+ var enter = items.enter()
+ .append('div')
+ .attr('class', 'feature-list-item')
+ .on('click', selectEntity);
+
+ enter
+ .each(function(d) {
+ select(this).on('mouseover', function() {
+ utilHighlightEntities([d.id], true, context);
+ });
+ select(this).on('mouseout', function() {
+ utilHighlightEntities([d.id], false, context);
+ });
+ });
+
+ var label = enter
+ .append('button')
+ .attr('class', 'label');
+
+ enter
+ .append('button')
+ .attr('class', 'close')
+ .attr('title', _t('icons.deselect'))
+ .on('click', deselectEntity)
+ .call(svgIcon('#iD-icon-close'));
+
+ label
+ .append('span')
+ .attr('class', 'entity-geom-icon')
+ .call(svgIcon('', 'pre-text'));
+
+ label
+ .append('span')
+ .attr('class', 'entity-type');
+
+ label
+ .append('span')
+ .attr('class', 'entity-name');
+
+ // Update
+ items = items.merge(enter);
+
+ items.selectAll('.entity-geom-icon use')
+ .attr('href', function() {
+ var entity = this.parentNode.parentNode.__data__;
+ return '#iD-icon-' + entity.geometry(context.graph());
+ });
+
+ items.selectAll('.entity-type')
+ .text(function(entity) { return _mainPresetIndex.match(entity, context.graph()).name(); });
+
+ items.selectAll('.entity-name')
+ .text(function(d) {
+ // fetch latest entity
+ var entity = context.entity(d.id);
+ return utilDisplayName(entity);
+ });
+ }
+
+ return section;
+ }
+
+ function uiEntityEditor(context) {
+ var dispatch$1 = dispatch('choose');
+ var _state = 'select';
+ var _coalesceChanges = false;
+ var _modified = false;
+ var _base;
+ var _entityIDs;
+ var _activePresets = [];
+ var _newFeature;
+
+ var _sections;
+
+ function entityEditor(selection) {
+
+ var combinedTags = utilCombinedTags(_entityIDs, context.graph());
+
+ // Header
+ var header = selection.selectAll('.header')
+ .data([0]);
+
+ // Enter
+ var headerEnter = header.enter()
+ .append('div')
+ .attr('class', 'header fillL cf');
+
+ headerEnter
+ .append('button')
+ .attr('class', 'preset-reset preset-choose')
+ .call(svgIcon((_mainLocalizer.textDirection() === 'rtl') ? '#iD-icon-forward' : '#iD-icon-backward'));
+
+ headerEnter
+ .append('button')
+ .attr('class', 'close')
+ .on('click', function() { context.enter(modeBrowse(context)); })
+ .call(svgIcon(_modified ? '#iD-icon-apply' : '#iD-icon-close'));
+
+ headerEnter
+ .append('h3');
+
+ // Update
+ header = header
+ .merge(headerEnter);
+
+ header.selectAll('h3')
+ .text(_entityIDs.length === 1 ? _t('inspector.edit') : _t('inspector.edit_features'));
+
+ header.selectAll('.preset-reset')
+ .on('click', function() {
+ dispatch$1.call('choose', this, _activePresets);
+ });
+
+ // Body
+ var body = selection.selectAll('.inspector-body')
+ .data([0]);
+
+ // Enter
+ var bodyEnter = body.enter()
+ .append('div')
+ .attr('class', 'entity-editor inspector-body sep-top');
+
+ // Update
+ body = body
+ .merge(bodyEnter);
+
+ if (!_sections) {
+ _sections = [
+ uiSectionSelectionList(context),
+ uiSectionFeatureType(context).on('choose', function(presets) {
+ dispatch$1.call('choose', this, presets);
+ }),
+ uiSectionEntityIssues(context),
+ uiSectionPresetFields(context).on('change', changeTags).on('revert', revertTags),
+ uiSectionRawTagEditor('raw-tag-editor', context).on('change', changeTags),
+ uiSectionRawMemberEditor(context),
+ uiSectionRawMembershipEditor(context)
+ ];
+ }
+
+ _sections.forEach(function(section) {
+ if (section.entityIDs) {
+ section.entityIDs(_entityIDs);
+ }
+ if (section.presets) {
+ section.presets(_activePresets);
+ }
+ if (section.tags) {
+ section.tags(combinedTags);
+ }
+ if (section.state) {
+ section.state(_state);
+ }
+ body.call(section.render);
+ });
+
+ body
+ .selectAll('.key-trap-wrap')
+ .data([0])
+ .enter()
+ .append('div')
+ .attr('class', 'key-trap-wrap')
+ .append('input')
+ .attr('type', 'text')
+ .attr('class', 'key-trap')
+ .on('keydown.key-trap', function() {
+ // On tabbing, send focus back to the first field on the inspector-body
+ // (probably the `name` field) #4159
+ if (event.keyCode === 9 && !event.shiftKey) {
+ event.preventDefault();
+ body.select('input').node().focus();
+ }
+ });
+
+ context.history()
+ .on('change.entity-editor', historyChanged);
+
+ function historyChanged(difference) {
+ if (selection.selectAll('.entity-editor').empty()) return;
+ if (_state === 'hide') return;
+ var significant = !difference ||
+ difference.didChange.properties ||
+ difference.didChange.addition ||
+ difference.didChange.deletion;
+ if (!significant) return;
+
+ _entityIDs = _entityIDs.filter(context.hasEntity);
+ if (!_entityIDs.length) return;
+
+ var priorActivePreset = _activePresets.length === 1 && _activePresets[0];
+
+ loadActivePresets();
+
+ var graph = context.graph();
+ entityEditor.modified(_base !== graph);
+ entityEditor(selection);
+
+ if (priorActivePreset && _activePresets.length === 1 && priorActivePreset !== _activePresets[0]) {
+ // flash the button to indicate the preset changed
+ context.container().selectAll('.entity-editor button.preset-reset .label')
+ .style('background-color', '#fff')
+ .transition()
+ .duration(750)
+ .style('background-color', null);
+ }
+ }
+ }
+
+
+ // Tag changes that fire on input can all get coalesced into a single
+ // history operation when the user leaves the field. #2342
+ // Use explicit entityIDs in case the selection changes before the event is fired.
+ function changeTags(entityIDs, changed, onInput) {
+
+ var actions = [];
+ for (var i in entityIDs) {
+ var entityID = entityIDs[i];
+ var entity = context.entity(entityID);
+
+ var tags = Object.assign({}, entity.tags); // shallow copy
+
+ for (var k in changed) {
+ if (!k) continue;
+ // No op for source=digitalglobe or source=maxar on ML roads. TODO: switch to check on __fbid__
+ if (entity.__fbid__ && k === 'source' &&
+ (entity.tags.source === 'digitalglobe' || entity.tags.source === 'maxar')) continue;
+ var v = changed[k];
+ if (v !== undefined || tags.hasOwnProperty(k)) {
+ tags[k] = v;
+ }
+ }
+
+ if (!onInput) {
+ tags = utilCleanTags(tags);
+ }
+
+ if (!fastDeepEqual(entity.tags, tags)) {
+ actions.push(actionChangeTags(entityID, tags));
+ }
+ }
+
+ if (actions.length) {
+ var combinedAction = function(graph) {
+ actions.forEach(function(action) {
+ graph = action(graph);
+ });
+ return graph;
+ };
+
+ var annotation = _t('operations.change_tags.annotation');
+
+ if (_coalesceChanges) {
+ context.overwrite(combinedAction, annotation);
+ } else {
+ context.perform(combinedAction, annotation);
+ _coalesceChanges = !!onInput;
+ }
+ }
+
+ // if leaving field (blur event), rerun validation
+ if (!onInput) {
+ context.validator().validate();
+ }
+ }
+
+ function revertTags(keys) {
+
+ var actions = [];
+ for (var i in _entityIDs) {
+ var entityID = _entityIDs[i];
+
+ var original = context.graph().base().entities[entityID];
+ var changed = {};
+ for (var j in keys) {
+ var key = keys[j];
+ changed[key] = original ? original.tags[key] : undefined;
+ }
+
+ var entity = context.entity(entityID);
+ var tags = Object.assign({}, entity.tags); // shallow copy
+
+ for (var k in changed) {
+ if (!k) continue;
+ var v = changed[k];
+ if (v !== undefined || tags.hasOwnProperty(k)) {
+ tags[k] = v;
+ }
+ }
+
+
+ tags = utilCleanTags(tags);
+
+ if (!fastDeepEqual(entity.tags, tags)) {
+ actions.push(actionChangeTags(entityID, tags));
+ }
+
+ }
+
+ if (actions.length) {
+ var combinedAction = function(graph) {
+ actions.forEach(function(action) {
+ graph = action(graph);
+ });
+ return graph;
+ };
+
+ var annotation = _t('operations.change_tags.annotation');
+
+ if (_coalesceChanges) {
+ context.overwrite(combinedAction, annotation);
+ } else {
+ context.perform(combinedAction, annotation);
+ _coalesceChanges = false;
+ }
+ }
+
+ context.validator().validate();
+ }
+
+
+ entityEditor.modified = function(val) {
+ if (!arguments.length) return _modified;
+ _modified = val;
+ return entityEditor;
+ };
+
+
+ entityEditor.state = function(val) {
+ if (!arguments.length) return _state;
+ _state = val;
+ return entityEditor;
+ };
+
+
+ entityEditor.entityIDs = function(val) {
+ if (!arguments.length) return _entityIDs;
+ if (val && _entityIDs && utilArrayIdentical(_entityIDs, val)) return entityEditor; // exit early if no change
+
+ _entityIDs = val;
+ _base = context.graph();
+ _coalesceChanges = false;
+
+ loadActivePresets(true);
+
+ return entityEditor
+ .modified(false);
+ };
+
+
+ entityEditor.newFeature = function(val) {
+ if (!arguments.length) return _newFeature;
+ _newFeature = val;
+ return entityEditor;
+ };
+
+
+ function loadActivePresets(isForNewSelection) {
+
+ var graph = context.graph();
+
+ var counts = {};
+
+ for (var i in _entityIDs) {
+ var entity = graph.hasEntity(_entityIDs[i]);
+ if (!entity) return;
+
+ var match = _mainPresetIndex.match(entity, graph);
+
+ if (!counts[match.id]) counts[match.id] = 0;
+ counts[match.id] += 1;
+ }
+
+ var matches = Object.keys(counts).sort(function(p1, p2) {
+ return counts[p2] - counts[p1];
+ }).map(function(pID) {
+ return _mainPresetIndex.item(pID);
+ });
+
+ if (!isForNewSelection) {
+ // A "weak" preset doesn't set any tags. (e.g. "Address")
+ var weakPreset = _activePresets.length === 1 &&
+ !_activePresets[0].isFallback() &&
+ Object.keys(_activePresets[0].addTags || {}).length === 0;
+ // Don't replace a weak preset with a fallback preset (e.g. "Point")
+ if (weakPreset && matches.length === 1 && matches[0].isFallback()) return;
+ }
+
+ entityEditor.presets(matches);
+ }
+
+ entityEditor.presets = function(val) {
+ if (!arguments.length) return _activePresets;
+
+ // don't reload the same preset
+ if (!utilArrayIdentical(val, _activePresets)) {
+ _activePresets = val;
+ }
+ return entityEditor;
+ };
+
+ return utilRebind(entityEditor, dispatch$1, 'on');
+ }
+
+ function uiPresetList(context) {
+ var dispatch$1 = dispatch('cancel', 'choose');
+ var _entityIDs;
+ var _currentPresets;
+ var _autofocus = false;
+
+
+ function presetList(selection) {
+ if (!_entityIDs) return;
+
+ var presets = _mainPresetIndex.matchAllGeometry(entityGeometries());
+
+ selection.html('');
+
+ var messagewrap = selection
+ .append('div')
+ .attr('class', 'header fillL');
+
+ var message = messagewrap
+ .append('h3')
+ .text(_t('inspector.choose'));
+
+ messagewrap
+ .append('button')
+ .attr('class', 'preset-choose')
+ .on('click', function() { dispatch$1.call('cancel', this); })
+ .call(svgIcon((_mainLocalizer.textDirection() === 'rtl') ? '#iD-icon-backward' : '#iD-icon-forward'));
+
+ function initialKeydown() {
+ // hack to let delete shortcut work when search is autofocused
+ if (search.property('value').length === 0 &&
+ (event.keyCode === utilKeybinding.keyCodes['⌫'] ||
+ event.keyCode === utilKeybinding.keyCodes['⌦'])) {
+ event.preventDefault();
+ event.stopPropagation();
+ operationDelete(context, _entityIDs)();
+
+ // hack to let undo work when search is autofocused
+ } else if (search.property('value').length === 0 &&
+ (event.ctrlKey || event.metaKey) &&
+ event.keyCode === utilKeybinding.keyCodes.z) {
+ event.preventDefault();
+ event.stopPropagation();
+ context.undo();
+ } else if (!event.ctrlKey && !event.metaKey) {
+ // don't check for delete/undo hack on future keydown events
+ select(this).on('keydown', keydown);
+ keydown.call(this);
+ }
+ }
+
+ function keydown() {
+ // down arrow
+ if (event.keyCode === utilKeybinding.keyCodes['↓'] &&
+ // if insertion point is at the end of the string
+ search.node().selectionStart === search.property('value').length) {
+ event.preventDefault();
+ event.stopPropagation();
+ // move focus to the first item in the preset list
+ var buttons = list.selectAll('.preset-list-button');
+ if (!buttons.empty()) buttons.nodes()[0].focus();
+ }
+ }
+
+ function keypress() {
+ // enter
+ var value = search.property('value');
+ if (event.keyCode === 13 && value.length) {
+ list.selectAll('.preset-list-item:first-child')
+ .each(function(d) { d.choose.call(this); });
+ }
+ }
+
+ function inputevent() {
+ var value = search.property('value');
+ list.classed('filtered', value.length);
+ var extent = combinedEntityExtent();
+ var results, messageText;
+ if (value.length && extent) {
+ var center = extent.center();
+ var countryCode = iso1A2Code(center);
+
+ results = presets.search(value, entityGeometries()[0], countryCode && countryCode.toLowerCase());
+ messageText = _t('inspector.results', {
+ n: results.collection.length,
+ search: value
+ });
+ } else {
+ results = _mainPresetIndex.defaults(entityGeometries()[0], 36, !context.inIntro());
+ messageText = _t('inspector.choose');
+ }
+ list.call(drawList, results);
+ message.text(messageText);
+ }
+
+ var searchWrap = selection
+ .append('div')
+ .attr('class', 'search-header');
+
+ var search = searchWrap
+ .append('input')
+ .attr('class', 'preset-search-input')
+ .attr('placeholder', _t('inspector.search'))
+ .attr('type', 'search')
+ .call(utilNoAuto)
+ .on('keydown', initialKeydown)
+ .on('keypress', keypress)
+ .on('input', inputevent);
+
+ searchWrap
+ .call(svgIcon('#iD-icon-search', 'pre-text'));
+
+ if (_autofocus) {
+ search.node().focus();
+ }
+
+ var listWrap = selection
+ .append('div')
+ .attr('class', 'inspector-body');
+
+ var list = listWrap
+ .append('div')
+ .attr('class', 'preset-list')
+ .call(drawList, _mainPresetIndex.defaults(entityGeometries()[0], 36, !context.inIntro()));
+
+ context.features().on('change.preset-list', updateForFeatureHiddenState);
+ }
+
+
+ function drawList(list, presets) {
+ presets = presets.matchAllGeometry(entityGeometries());
+ var collection = presets.collection.reduce(function(collection, preset) {
+ if (!preset) return collection;
+
+ if (preset.members) {
+ if (preset.members.collection.filter(function(preset) {
+ return preset.addable();
+ }).length > 1) {
+ collection.push(CategoryItem(preset));
+ }
+ } else if (preset.addable()) {
+ collection.push(PresetItem(preset));
+ }
+ return collection;
+ }, []);
+
+ var items = list.selectAll('.preset-list-item')
+ .data(collection, function(d) { return d.preset.id; });
+
+ items.order();
+
+ items.exit()
+ .remove();
+
+ items.enter()
+ .append('div')
+ .attr('class', function(item) { return 'preset-list-item preset-' + item.preset.id.replace('/', '-'); })
+ .classed('current', function(item) { return _currentPresets.indexOf(item.preset) !== -1; })
+ .each(function(item) { select(this).call(item); })
+ .style('opacity', 0)
+ .transition()
+ .style('opacity', 1);
+
+ updateForFeatureHiddenState();
+ }
+
+ function itemKeydown(){
+ // the actively focused item
+ var item = select(this.closest('.preset-list-item'));
+ var parentItem = select(item.node().parentNode.closest('.preset-list-item'));
+
+ // arrow down, move focus to the next, lower item
+ if (event.keyCode === utilKeybinding.keyCodes['↓']) {
+ event.preventDefault();
+ event.stopPropagation();
+ // the next item in the list at the same level
+ var nextItem = select(item.node().nextElementSibling);
+ // if there is no next item in this list
+ if (nextItem.empty()) {
+ // if there is a parent item
+ if (!parentItem.empty()) {
+ // the item is the last item of a sublist,
+ // select the next item at the parent level
+ nextItem = select(parentItem.node().nextElementSibling);
+ }
+ // if the focused item is expanded
+ } else if (select(this).classed('expanded')) {
+ // select the first subitem instead
+ nextItem = item.select('.subgrid .preset-list-item:first-child');
+ }
+ if (!nextItem.empty()) {
+ // focus on the next item
+ nextItem.select('.preset-list-button').node().focus();
+ }
+
+ // arrow up, move focus to the previous, higher item
+ } else if (event.keyCode === utilKeybinding.keyCodes['↑']) {
+ event.preventDefault();
+ event.stopPropagation();
+ // the previous item in the list at the same level
+ var previousItem = select(item.node().previousElementSibling);
+
+ // if there is no previous item in this list
+ if (previousItem.empty()) {
+ // if there is a parent item
+ if (!parentItem.empty()) {
+ // the item is the first subitem of a sublist select the parent item
+ previousItem = parentItem;
+ }
+ // if the previous item is expanded
+ } else if (previousItem.select('.preset-list-button').classed('expanded')) {
+ // select the last subitem of the sublist of the previous item
+ previousItem = previousItem.select('.subgrid .preset-list-item:last-child');
+ }
+
+ if (!previousItem.empty()) {
+ // focus on the previous item
+ previousItem.select('.preset-list-button').node().focus();
+ } else {
+ // the focus is at the top of the list, move focus back to the search field
+ var search = select(this.closest('.preset-list-pane')).select('.preset-search-input');
+ search.node().focus();
+ }
+
+ // arrow left, move focus to the parent item if there is one
+ } else if (event.keyCode === utilKeybinding.keyCodes[(_mainLocalizer.textDirection() === 'rtl') ? '→' : '←']) {
+ event.preventDefault();
+ event.stopPropagation();
+ // if there is a parent item, focus on the parent item
+ if (!parentItem.empty()) {
+ parentItem.select('.preset-list-button').node().focus();
+ }
+
+ // arrow right, choose this item
+ } else if (event.keyCode === utilKeybinding.keyCodes[(_mainLocalizer.textDirection() === 'rtl') ? '←' : '→']) {
+ event.preventDefault();
+ event.stopPropagation();
+ item.datum().choose.call(select(this).node());
+ }
+ }
+
+
+ function CategoryItem(preset) {
+ var box, sublist, shown = false;
+
+ function item(selection) {
+ var wrap = selection.append('div')
+ .attr('class', 'preset-list-button-wrap category');
+
+ function click() {
+ var isExpanded = select(this).classed('expanded');
+ var iconName = isExpanded ?
+ (_mainLocalizer.textDirection() === 'rtl' ? '#iD-icon-backward' : '#iD-icon-forward') : '#iD-icon-down';
+ select(this)
+ .classed('expanded', !isExpanded);
+ select(this).selectAll('div.label-inner svg.icon use')
+ .attr('href', iconName);
+ item.choose();
+ }
+
+ var geometries = entityGeometries();
+
+ var button = wrap
+ .append('button')
+ .attr('class', 'preset-list-button')
+ .classed('expanded', false)
+ .call(uiPresetIcon()
+ .geometry(geometries.length === 1 && geometries[0])
+ .preset(preset))
+ .on('click', click)
+ .on('keydown', function() {
+ // right arrow, expand the focused item
+ if (event.keyCode === utilKeybinding.keyCodes[(_mainLocalizer.textDirection() === 'rtl') ? '←' : '→']) {
+ event.preventDefault();
+ event.stopPropagation();
+ // if the item isn't expanded
+ if (!select(this).classed('expanded')) {
+ // toggle expansion (expand the item)
+ click.call(this);
+ }
+ // left arrow, collapse the focused item
+ } else if (event.keyCode === utilKeybinding.keyCodes[(_mainLocalizer.textDirection() === 'rtl') ? '→' : '←']) {
+ event.preventDefault();
+ event.stopPropagation();
+ // if the item is expanded
+ if (select(this).classed('expanded')) {
+ // toggle expansion (collapse the item)
+ click.call(this);
+ }
+ } else {
+ itemKeydown.call(this);
+ }
+ });
+
+ var label = button
+ .append('div')
+ .attr('class', 'label')
+ .append('div')
+ .attr('class', 'label-inner');
+
+ label
+ .append('div')
+ .attr('class', 'namepart')
+ .call(svgIcon((_mainLocalizer.textDirection() === 'rtl' ? '#iD-icon-backward' : '#iD-icon-forward'), 'inline'))
+ .append('span')
+ .html(function() { return preset.name() + '…'; });
+
+ box = selection.append('div')
+ .attr('class', 'subgrid')
+ .style('max-height', '0px')
+ .style('opacity', 0);
+
+ box.append('div')
+ .attr('class', 'arrow');
+
+ sublist = box.append('div')
+ .attr('class', 'preset-list fillL3');
+ }
+
+
+ item.choose = function() {
+ if (!box || !sublist) return;
+
+ if (shown) {
+ shown = false;
+ box.transition()
+ .duration(200)
+ .style('opacity', '0')
+ .style('max-height', '0px')
+ .style('padding-bottom', '0px');
+ } else {
+ shown = true;
+ var members = preset.members.matchAllGeometry(entityGeometries());
+ sublist.call(drawList, members);
+ box.transition()
+ .duration(200)
+ .style('opacity', '1')
+ .style('max-height', 200 + members.collection.length * 190 + 'px')
+ .style('padding-bottom', '10px');
+ }
+ };
+
+ item.preset = preset;
+ return item;
+ }
+
+
+ function PresetItem(preset) {
+ function item(selection) {
+ var wrap = selection.append('div')
+ .attr('class', 'preset-list-button-wrap');
+
+ var geometries = entityGeometries();
+
+ var button = wrap.append('button')
+ .attr('class', 'preset-list-button')
+ .call(uiPresetIcon()
+ .geometry(geometries.length === 1 && geometries[0])
+ .preset(preset))
+ .on('click', item.choose)
+ .on('keydown', itemKeydown);
+
+ var label = button
+ .append('div')
+ .attr('class', 'label')
+ .append('div')
+ .attr('class', 'label-inner');
+
+ // NOTE: split/join on en-dash, not a hypen (to avoid conflict with fr - nl names in Brussels etc)
+ label.selectAll('.namepart')
+ .data(preset.name().split(' – '))
+ .enter()
+ .append('div')
+ .attr('class', 'namepart')
+ .text(function(d) { return d; });
+
+ wrap.call(item.reference.button);
+ selection.call(item.reference.body);
+ }
+
+ item.choose = function() {
+ if (select(this).classed('disabled')) return;
+ if (!context.inIntro()) {
+ _mainPresetIndex.setMostRecent(preset, entityGeometries()[0]);
+ }
+ context.perform(
+ function(graph) {
+ for (var i in _entityIDs) {
+ var entityID = _entityIDs[i];
+ var oldPreset = _mainPresetIndex.match(graph.entity(entityID), graph);
+ graph = actionChangePreset(entityID, oldPreset, preset)(graph);
+ }
+ return graph;
+ },
+ _t('operations.change_tags.annotation')
+ );
+
+ context.validator().validate(); // rerun validation
+ dispatch$1.call('choose', this, preset);
+ };
+
+ item.help = function() {
+ event.stopPropagation();
+ item.reference.toggle();
+ };
+
+ item.preset = preset;
+ item.reference = uiTagReference(preset.reference(entityGeometries()[0]));
+
+ return item;
+ }
+
+
+ function updateForFeatureHiddenState() {
+ if (!_entityIDs.every(context.hasEntity)) return;
+
+ var geometries = entityGeometries();
+ var button = context.container().selectAll('.preset-list .preset-list-button');
+
+ // remove existing tooltips
+ button.call(uiTooltip().destroyAny);
+
+ button.each(function(item, index) {
+ var hiddenPresetFeaturesId;
+ for (var i in geometries) {
+ hiddenPresetFeaturesId = context.features().isHiddenPreset(item.preset, geometries[i]);
+ if (hiddenPresetFeaturesId) break;
+ }
+ var isHiddenPreset = !context.inIntro() &&
+ !!hiddenPresetFeaturesId &&
+ (_currentPresets.length !== 1 || item.preset !== _currentPresets[0]);
+
+ select(this)
+ .classed('disabled', isHiddenPreset);
+
+ if (isHiddenPreset) {
+ var isAutoHidden = context.features().autoHidden(hiddenPresetFeaturesId);
+ var tooltipIdSuffix = isAutoHidden ? 'zoom' : 'manual';
+ var tooltipObj = { features: _t('feature.' + hiddenPresetFeaturesId + '.description') };
+ select(this).call(uiTooltip()
+ .title(_t('inspector.hidden_preset.' + tooltipIdSuffix, tooltipObj))
+ .placement(index < 2 ? 'bottom' : 'top')
+ );
+ }
+ });
+ }
+
+ presetList.autofocus = function(val) {
+ if (!arguments.length) return _autofocus;
+ _autofocus = val;
+ return presetList;
+ };
+
+ presetList.entityIDs = function(val) {
+ if (!arguments.length) return _entityIDs;
+ _entityIDs = val;
+ if (_entityIDs && _entityIDs.length) {
+ var presets = _entityIDs.map(function(entityID) {
+ return _mainPresetIndex.match(context.entity(entityID), context.graph());
+ });
+ presetList.presets(presets);
+ }
+ return presetList;
+ };
+
+ presetList.presets = function(val) {
+ if (!arguments.length) return _currentPresets;
+ _currentPresets = val;
+ return presetList;
+ };
+
+ function entityGeometries() {
+
+ var counts = {};
+
+ for (var i in _entityIDs) {
+ var entityID = _entityIDs[i];
+ var entity = context.entity(entityID);
+ var geometry = entity.geometry(context.graph());
+
+ // Treat entities on addr:interpolation lines as points, not vertices (#3241)
+ if (geometry === 'vertex' && entity.isOnAddressLine(context.graph())) {
+ geometry = 'point';
+ }
+
+ if (!counts[geometry]) counts[geometry] = 0;
+ counts[geometry] += 1;
+ }
+
+ return Object.keys(counts).sort(function(geom1, geom2) {
+ return counts[geom2] - counts[geom1];
+ });
+ }
+
+ function combinedEntityExtent() {
+ return _entityIDs.reduce(function(extent, entityID) {
+ var entity = context.graph().entity(entityID);
+ return extent.extend(entity.extent(context.graph()));
+ }, geoExtent());
+ }
+
+ return utilRebind(presetList, dispatch$1, 'on');
+ }
+
+ function uiInspector(context) {
+ var presetList = uiPresetList(context);
+ var entityEditor = uiEntityEditor(context);
+ var wrap = select(null),
+ presetPane = select(null),
+ editorPane = select(null);
+ var _state = 'select';
+ var _entityIDs;
+ var _newFeature = false;
+
+
+ function inspector(selection) {
+ presetList
+ .entityIDs(_entityIDs)
+ .autofocus(_newFeature)
+ .on('choose', inspector.setPreset)
+ .on('cancel', function() {
+ wrap.transition()
+ .styleTween('right', function() { return interpolate('-100%', '0%'); });
+ editorPane.call(entityEditor);
+ });
+
+ entityEditor
+ .state(_state)
+ .entityIDs(_entityIDs)
+ .on('choose', inspector.showList);
+
+ wrap = selection.selectAll('.panewrap')
+ .data([0]);
+
+ var enter = wrap.enter()
+ .append('div')
+ .attr('class', 'panewrap');
+
+ enter
+ .append('div')
+ .attr('class', 'preset-list-pane pane');
+
+ enter
+ .append('div')
+ .attr('class', 'entity-editor-pane pane');
+
+ wrap = wrap.merge(enter);
+ presetPane = wrap.selectAll('.preset-list-pane');
+ editorPane = wrap.selectAll('.entity-editor-pane');
+
+ function shouldDefaultToPresetList() {
+ // always show the inspector on hover
+ if (_state !== 'select') return false;
+
+ // can only change preset on single selection
+ if (_entityIDs.length !== 1) return false;
+
+ var entityID = _entityIDs[0];
+ var entity = context.hasEntity(entityID);
+ if (!entity) return false;
+
+ // default to inspector if there are already tags
+ if (entity.hasNonGeometryTags()) return false;
+
+ // prompt to select preset if feature is new and untagged
+ if (_newFeature) return true;
+
+ // all existing features except vertices should default to inspector
+ if (entity.geometry(context.graph()) !== 'vertex') return false;
+
+ // show vertex relations if any
+ if (context.graph().parentRelations(entity).length) return false;
+
+ // show vertex issues if there are any
+ if (context.validator().getEntityIssues(entityID).length) return false;
+
+ // show turn retriction editor for junction vertices
+ if (entity.isHighwayIntersection(context.graph())) return false;
+
+ // otherwise show preset list for uninteresting vertices
+ return true;
+ }
+
+ if (shouldDefaultToPresetList()) {
+ wrap.style('right', '-100%');
+ presetPane.call(presetList);
+ } else {
+ wrap.style('right', '0%');
+ editorPane.call(entityEditor);
+ }
+
+ var footer = selection.selectAll('.footer')
+ .data([0]);
+
+ footer = footer.enter()
+ .append('div')
+ .attr('class', 'footer')
+ .merge(footer);
+
+ footer
+ .call(uiViewOnOSM(context)
+ .what(context.hasEntity(_entityIDs.length === 1 && _entityIDs[0]))
+ );
+ }
+
+ inspector.showList = function(presets) {
+
+ wrap.transition()
+ .styleTween('right', function() { return interpolate('0%', '-100%'); });
+
+ if (presets) {
+ presetList.presets(presets);
+ }
+
+ presetPane
+ .call(presetList.autofocus(true));
+ };
+
+ inspector.setPreset = function(preset) {
+
+ // upon setting multipolygon, go to the area preset list instead of the editor
+ if (preset.id === 'type/multipolygon') {
+ presetPane
+ .call(presetList.autofocus(true));
+
+ } else {
+ wrap.transition()
+ .styleTween('right', function() { return interpolate('-100%', '0%'); });
+
+ editorPane
+ .call(entityEditor.presets([preset]));
+ }
+
+ };
+
+ inspector.state = function(val) {
+ if (!arguments.length) return _state;
+ _state = val;
+ entityEditor.state(_state);
+
+ // remove any old field help overlay that might have gotten attached to the inspector
+ context.container().selectAll('.field-help-body').remove();
+
+ return inspector;
+ };
+
+
+ inspector.entityIDs = function(val) {
+ if (!arguments.length) return _entityIDs;
+ _entityIDs = val;
+ return inspector;
+ };
+
+
+ inspector.newFeature = function(val) {
+ if (!arguments.length) return _newFeature;
+ _newFeature = val;
+ return inspector;
+ };
+
+
+ return inspector;
+ }
+
+ function uiRapidSplash(context) {
+
+ return function(selection) {
+ if (corePreferences('sawRapidSplash')) return;
+ corePreferences('sawRapidSplash', true);
+
+ const modalSelection = uiModal(selection);
+
+ modalSelection.select('.modal')
+ .attr('class', 'modal rapid-modal modal-splash'); // RapiD styling
+
+ let introModal = modalSelection.select('.content');
+
+ introModal
+ .append('div')
+ .attr('class','modal-section')
+ .append('h3').text(_t('rapid_splash.welcome'));
+
+ introModal
+ .append('div')
+ .attr('class','modal-section')
+ .append('p')
+ .html(_t('rapid_splash.text', {
+ rapidicon: icon('#iD-logo-rapid', 'logo-rapid'),
+ walkthrough: icon('#iD-logo-walkthrough', 'logo-walkthrough'),
+ edit: icon('#iD-logo-features', 'logo-features')
+ }));
+
+ let buttonWrap = introModal
+ .append('div')
+ .attr('class', 'modal-actions');
+
+ let walkthrough = buttonWrap
+ .append('button')
+ .attr('class', 'walkthrough')
+ .on('click', (d, i, nodes) => {
+ select(nodes[i]).node().blur();
+ context.container().call(uiIntro(context, false));
+ modalSelection.close();
+ });
+
+ walkthrough
+ .append('svg')
+ .attr('class', 'logo logo-features')
+ .append('use')
+ .attr('xlink:href', '#iD-logo-walkthrough');
+
+ walkthrough
+ .append('div')
+ .text(_t('rapid_splash.walkthrough'));
+
+ let rapidWalkthrough = buttonWrap
+ .append('button')
+ .attr('class', 'rapid-walkthrough')
+ .on('click', (d, i, nodes) => {
+ select(nodes[i]).node().blur();
+ context.container().call(uiIntro(context, true));
+ modalSelection.close();
+ });
+
+ rapidWalkthrough
+ .append('svg')
+ .attr('class', 'logo logo-rapid')
+ .append('use')
+ .attr('xlink:href', '#iD-logo-rapid');
+
+ rapidWalkthrough
+ .append('div')
+ .text(_t('rapid_splash.skip_to_rapid'));
+
+ let startEditing = buttonWrap
+ .append('button')
+ .attr('class', 'start-editing')
+ .on('click', (d, i, nodes) => {
+ select(nodes[i]).node().blur();
+ modalSelection.close();
+ });
+
+ startEditing
+ .append('svg')
+ .attr('class', 'logo logo-features')
+ .append('use')
+ .attr('xlink:href', '#iD-logo-features');
+
+ startEditing
+ .append('div')
+ .text(_t('rapid_splash.start'));
+
+ modalSelection.select('button.close')
+ .attr('class', 'hide');
+ };
+ }
+
+ function uiRapidFirstEditDialog(context) {
+
+ return function(selection) {
+ let modalSelection = uiModal(selection);
+
+ modalSelection.select('.modal')
+ .attr('class', 'modal rapid-modal'); // RapiD styling
+
+ let firstEditModal = modalSelection.select('.content');
+
+ firstEditModal
+ .append('div')
+ .attr('class', 'modal-section')
+ .append('h3')
+ .html(_t('rapid_first_edit.nice', { rapidicon: icon('#iD-logo-rapid', 'logo-rapid') }));
+
+ firstEditModal
+ .append('div')
+ .attr('class', 'modal-section')
+ .append('p')
+ .text(_t('rapid_first_edit.text'));
+
+ let buttonWrap = firstEditModal
+ .append('div')
+ .attr('class', 'modal-actions');
+
+ let exploring = buttonWrap
+ .append('button')
+ .attr('class', 'rapid-explore')
+ .on('click', (d, i, nodes) => {
+ select(nodes[i]).node().blur();
+ modalSelection.close();
+ });
+
+ exploring
+ .append('div')
+ .text(_t('rapid_first_edit.exploring'));
+
+ let loginToOsm = buttonWrap
+ .append('button')
+ .attr('class', 'rapid-login-to-osm')
+ .on('click', (d, i, nodes) => {
+ select(nodes[i]).node().blur();
+ modalSelection.close();
+ const osm = context.connection();
+ if (!osm) return;
+ osm.authenticate(() => context.container().call(uiRapidSplash(context)) );
+ });
+
+ loginToOsm
+ .append('div')
+ .text(_t('rapid_first_edit.login_with_osm'));
+
+ modalSelection.select('button.close')
+ .attr('class', 'hide');
+ };
+ }
+
+ function uiRapidFeatureInspector(context, keybinding) {
+ const rapidContext = context.rapidContext();
+ const showPowerUser = rapidContext.showPowerUser;
+ const ACCEPT_FEATURES_LIMIT = showPowerUser ? Infinity : 50;
+ let _datum;
+
+
+ function isAddFeatureDisabled() {
+ // when task GPX is set in URL (TM mode), "add roads" is always enabled
+ const gpxInUrl = utilStringQs(window.location.hash).gpx;
+ if (gpxInUrl) return false;
+
+ const annotations = context.history().peekAllAnnotations();
+ const aiFeatureAccepts = annotations.filter(a => a.type === 'rapid_accept_feature');
+ return aiFeatureAccepts.length >= ACCEPT_FEATURES_LIMIT;
+ }
+
+
+ function onAcceptFeature() {
+ if (!_datum) return;
+
+ if (isAddFeatureDisabled()) {
+ const flash = uiFlash(context)
+ .duration(5000)
+ .text(_t(
+ 'rapid_feature_inspector.option_accept.disabled_flash',
+ { n: ACCEPT_FEATURES_LIMIT }
+ ));
+ flash();
+ return;
+ }
+
+ // In place of a string annotation, this introduces an "object-style"
+ // annotation, where "type" and "description" are standard keys,
+ // and there may be additional properties. Note that this will be
+ // serialized to JSON while saving undo/redo state in history.save().
+ const annotation = {
+ type: 'rapid_accept_feature',
+ description: _t('rapid_feature_inspector.option_accept.annotation'),
+ id: _datum.id,
+ origid: _datum.__origid__,
+ };
+
+ const service = _datum.__service__ === 'esri' ? services.esriData : services.fbMLRoads;
+ const graph = service.graph(_datum.__datasetid__);
+ context.perform(actionRapidAcceptFeature(_datum.id, graph), annotation);
+ context.enter(modeSelect(context, [_datum.id]));
+
+ if (context.inIntro()) return;
+
+ // remember sources for later when we prepare the changeset
+ const source = _datum.tags && _datum.tags.source;
+ if (source) {
+ rapidContext.sources.add(source);
+ }
+
+ if (window.sessionStorage.getItem('acknowledgedLogin') === 'true') return;
+ window.sessionStorage.setItem('acknowledgedLogin', 'true');
+
+ const osm = context.connection();
+ if (!osm.authenticated()) {
+ context.container()
+ .call(uiRapidFirstEditDialog(context));
+ }
+ }
+
+
+ function onIgnoreFeature() {
+ if (!_datum) return;
+
+ const annotation = {
+ type: 'rapid_ignore_feature',
+ description: _t('rapid_feature_inspector.option_ignore.annotation'),
+ id: _datum.id,
+ origid: _datum.__origid__
+ };
+ context.perform(actionNoop(), annotation);
+ context.enter(modeBrowse(context));
+ }
+
+
+ // https://www.w3.org/TR/AERT#color-contrast
+ // https://trendct.org/2016/01/22/how-to-choose-a-label-color-to-contrast-with-background/
+ // pass color as a hexstring like '#rgb', '#rgba', '#rrggbb', '#rrggbbaa' (alpha values are ignored)
+ function getBrightness(color) {
+ const short = (color.length < 6);
+ const r = parseInt(short ? color[1] + color[1] : color[1] + color[2], 16);
+ const g = parseInt(short ? color[2] + color[2] : color[3] + color[4], 16);
+ const b = parseInt(short ? color[3] + color[3] : color[5] + color[6], 16);
+ return ((r * 299) + (g * 587) + (b * 114)) / 1000;
+ }
+
+
+ function featureInfo(selection) {
+ if (!_datum) return;
+
+ const datasetID = _datum.__datasetid__.replace('-conflated', '');
+ const dataset = rapidContext.datasets()[datasetID];
+ const color = dataset.color;
+
+ let featureInfo = selection.selectAll('.feature-info')
+ .data([color]);
+
+ // enter
+ let featureInfoEnter = featureInfo
+ .enter()
+ .append('div')
+ .attr('class', 'feature-info');
+
+ featureInfoEnter
+ .append('div')
+ .attr('class', 'dataset-label')
+ .text(dataset.label || dataset.id); // fallback to dataset ID
+
+ if (dataset.beta) {
+ featureInfoEnter
+ .append('div')
+ .attr('class', 'dataset-beta beta')
+ .attr('title', _t('rapid_poweruser_features.beta'));
+ }
+
+ // update
+ featureInfo = featureInfo
+ .merge(featureInfoEnter)
+ .style('background', d => d)
+ .style('color', d => getBrightness(d) > 140.5 ? '#333' : '#fff');
+ }
+
+
+ function tagInfo(selection) {
+ const tags = _datum && _datum.tags;
+ if (!tags) return;
+
+ let tagInfoEnter = selection.selectAll('.tag-info')
+ .data([0])
+ .enter()
+ .append('div')
+ .attr('class', 'tag-info');
+
+ let tagBagEnter = tagInfoEnter
+ .append('div')
+ .attr('class', 'tag-bag');
+
+ tagBagEnter
+ .append('div')
+ .attr('class', 'tag-heading')
+ .text(_t('rapid_feature_inspector.tags'));
+
+ const tagEntries = Object.keys(tags).map(k => ({ key: k, value: tags[k] }) );
+
+ tagEntries.forEach(e => {
+ let entryDiv = tagBagEnter.append('div')
+ .attr('class', 'tag-entry');
+
+ entryDiv.append('div').attr('class', 'tag-key').text(e.key);
+ entryDiv.append('div').attr('class', 'tag-value').text(e.value);
+ });
+ }
+
+
+ function rapidInspector(selection) {
+ let inspector = selection.selectAll('.rapid-inspector')
+ .data([0]);
+
+ let inspectorEnter = inspector
+ .enter()
+ .append('div')
+ .attr('class', 'rapid-inspector');
+
+ inspector = inspector
+ .merge(inspectorEnter);
+
+
+ // Header
+ let headerEnter = inspector.selectAll('.header')
+ .data([0])
+ .enter()
+ .append('div')
+ .attr('class', 'header');
+
+ headerEnter
+ .append('h3')
+ .append('svg')
+ .attr('class', 'logo-rapid dark')
+ .append('use')
+ .attr('xlink:href', '#iD-logo-rapid');
+
+ headerEnter
+ .append('button')
+ .attr('class', 'fr rapid-inspector-close')
+ .on('click', (d, i, nodes) => {
+ select(nodes[i]).node().blur();
+ context.enter(modeBrowse(context));
+ })
+ .call(svgIcon('#iD-icon-close'));
+
+
+ // Body
+ let body = inspector.selectAll('.body')
+ .data([0]);
+
+ let bodyEnter = body
+ .enter()
+ .append('div')
+ .attr('class', 'body');
+
+ body = body
+ .merge(bodyEnter)
+ .call(featureInfo)
+ .call(tagInfo);
+
+
+ // Choices
+ const choiceData = [
+ {
+ key: 'accept',
+ iconName: '#iD-icon-rapid-plus-circle',
+ label: _t('rapid_feature_inspector.option_accept.label'),
+ description: _t('rapid_feature_inspector.option_accept.description'),
+ onClick: onAcceptFeature
+ }, {
+ key: 'ignore',
+ iconName: '#iD-icon-rapid-minus-circle',
+ label: _t('rapid_feature_inspector.option_ignore.label'),
+ description: _t('rapid_feature_inspector.option_ignore.description'),
+ onClick: onIgnoreFeature
+ }
+ ];
+
+ let choices = body.selectAll('.rapid-inspector-choices')
+ .data([0]);
+
+ let choicesEnter = choices
+ .enter()
+ .append('div')
+ .attr('class', 'rapid-inspector-choices');
+
+ choicesEnter
+ .append('p')
+ .text(_t('rapid_feature_inspector.prompt'));
+
+ choicesEnter.selectAll('.rapid-inspector-choice')
+ .data(choiceData, d => d.key)
+ .enter()
+ .append('div')
+ .attr('class', d => `rapid-inspector-choice rapid-inspector-choice-${d.key}`)
+ .each(showChoice);
+ }
+
+
+ function showChoice(d, i, nodes) {
+ let selection = select(nodes[i]);
+ const disableClass = (d.key === 'accept' && isAddFeatureDisabled()) ? 'secondary disabled': '';
+
+ let choiceWrap = selection
+ .append('div')
+ .attr('class', `choice-wrap choice-wrap-${d.key}`);
+
+ let choiceReference = selection
+ .append('div')
+ .attr('class', 'tag-reference-body');
+
+ choiceReference
+ .text(d.description);
+
+ const onClick = d.onClick;
+ let choiceButton = choiceWrap
+ .append('button')
+ .attr('class', `choice-button choice-button-${d.key} ${disableClass}`)
+ .on('click', (d, i, nodes) => {
+ select(nodes[i]).node().blur();
+ onClick();
+ });
+
+ // build tooltips
+ let title, keys;
+ if (d.key === 'accept') {
+ if (isAddFeatureDisabled()) {
+ title = _t('rapid_feature_inspector.option_accept.disabled', { n: ACCEPT_FEATURES_LIMIT } );
+ keys = [];
+ } else {
+ title = _t('rapid_feature_inspector.option_accept.tooltip');
+ keys = [_t('rapid_feature_inspector.option_accept.key')];
+ }
+ } else if (d.key === 'ignore') {
+ title = _t('rapid_feature_inspector.option_ignore.tooltip');
+ keys = [_t('rapid_feature_inspector.option_ignore.key')];
+ }
+
+ if (title && keys) {
+ choiceButton = choiceButton
+ .call(uiTooltip().placement('bottom').title(title).keys(keys));
+ }
+
+ choiceButton
+ .append('svg')
+ .attr('class', 'choice-icon icon')
+ .append('use')
+ .attr('xlink:href', d.iconName);
+
+ choiceButton
+ .append('div')
+ .attr('class', 'choice-label')
+ .text(d.label);
+
+ choiceWrap
+ .append('button')
+ .attr('class', `tag-reference-button ${disableClass}`)
+ .attr('title', 'info')
+ .attr('tabindex', '-1')
+ .on('click', (d, i, nodes) => {
+ select(nodes[i]).node().blur();
+ choiceReference.classed('expanded', !choiceReference.classed('expanded'));
+ })
+ .call(svgIcon('#iD-icon-inspect'));
+ }
+
+
+ rapidInspector.datum = function(val) {
+ if (!arguments.length) return _datum;
+ _datum = val;
+ return this;
+ };
+
+ if (keybinding) {
+ keybinding()
+ .on(_t('rapid_feature_inspector.option_accept.key'), onAcceptFeature)
+ .on(_t('rapid_feature_inspector.option_ignore.key'), onIgnoreFeature);
+ }
+
+ return rapidInspector;
+ }
+
+ function uiSidebar(context) {
+ var inspector = uiInspector(context);
+ var rapidInspector = uiRapidFeatureInspector(context);
+ var dataEditor = uiDataEditor(context);
+ var noteEditor = uiNoteEditor(context);
+ var improveOsmEditor = uiImproveOsmEditor(context);
+ var keepRightEditor = uiKeepRightEditor(context);
+ var osmoseEditor = uiOsmoseEditor(context);
+ var _current;
+ var _wasRapiD = false;
+ var _wasData = false;
+ var _wasNote = false;
+ var _wasQaItem = false;
+
+ // use pointer events on supported platforms; fallback to mouse events
+ var _pointerPrefix = 'PointerEvent' in window ? 'pointer' : 'mouse';
+
+
+ function sidebar(selection) {
+ var container = context.container();
+ var minWidth = 240;
+ var sidebarWidth;
+ var containerWidth;
+ var dragOffset;
+
+ // Set the initial width constraints
+ selection
+ .style('min-width', minWidth + 'px')
+ .style('max-width', '400px')
+ .style('width', '33.3333%');
+
+ var resizer = selection
+ .append('div')
+ .attr('class', 'sidebar-resizer')
+ .on(_pointerPrefix + 'down.sidebar-resizer', pointerdown);
+
+ var downPointerId, lastClientX, containerLocGetter;
+
+ function pointerdown() {
+ if (downPointerId) return;
+
+ if ('button' in event && event.button !== 0) return;
+
+ downPointerId = event.pointerId || 'mouse';
+
+ lastClientX = event.clientX;
+
+ containerLocGetter = utilFastMouse(container.node());
+
+ // offset from edge of sidebar-resizer
+ dragOffset = utilFastMouse(resizer.node())(event)[0] - 1;
+
+ sidebarWidth = selection.node().getBoundingClientRect().width;
+ containerWidth = container.node().getBoundingClientRect().width;
+ var widthPct = (sidebarWidth / containerWidth) * 100;
+ selection
+ .style('width', widthPct + '%') // lock in current width
+ .style('max-width', '85%'); // but allow larger widths
+
+ resizer.classed('dragging', true);
+
+ select(window)
+ .on('touchmove.sidebar-resizer', function() {
+ // disable page scrolling while resizing on touch input
+ event.preventDefault();
+ }, { passive: false })
+ .on(_pointerPrefix + 'move.sidebar-resizer', pointermove)
+ .on(_pointerPrefix + 'up.sidebar-resizer pointercancel.sidebar-resizer', pointerup);
+ }
+
+ function pointermove() {
+
+ if (downPointerId !== (event.pointerId || 'mouse')) return;
+
+ event.preventDefault();
+
+ var dx = event.clientX - lastClientX;
+
+ lastClientX = event.clientX;
+
+ var isRTL = (_mainLocalizer.textDirection() === 'rtl');
+ var scaleX = isRTL ? 0 : 1;
+ var xMarginProperty = isRTL ? 'margin-right' : 'margin-left';
+
+ var x = containerLocGetter(event)[0] - dragOffset;
+ sidebarWidth = isRTL ? containerWidth - x : x;
+
+ var isCollapsed = selection.classed('collapsed');
+ var shouldCollapse = sidebarWidth < minWidth;
+
+ selection.classed('collapsed', shouldCollapse);
+
+ if (shouldCollapse) {
+ if (!isCollapsed) {
+ selection
+ .style(xMarginProperty, '-400px')
+ .style('width', '400px');
+
+ context.ui().onResize([(sidebarWidth - dx) * scaleX, 0]);
+ }
+
+ } else {
+ var widthPct = (sidebarWidth / containerWidth) * 100;
+ selection
+ .style(xMarginProperty, null)
+ .style('width', widthPct + '%');
+
+ if (isCollapsed) {
+ context.ui().onResize([-sidebarWidth * scaleX, 0]);
+ } else {
+ context.ui().onResize([-dx * scaleX, 0]);
+ }
+ }
+ }
+
+ function pointerup() {
+ if (downPointerId !== (event.pointerId || 'mouse')) return;
+
+ downPointerId = null;
+
+ resizer.classed('dragging', false);
+
+ select(window)
+ .on('touchmove.sidebar-resizer', null)
+ .on(_pointerPrefix + 'move.sidebar-resizer', null)
+ .on(_pointerPrefix + 'up.sidebar-resizer pointercancel.sidebar-resizer', null);
+ }
+
+ var featureListWrap = selection
+ .append('div')
+ .attr('class', 'feature-list-pane')
+ .call(uiFeatureList(context));
+
+ var inspectorWrap = selection
+ .append('div')
+ .attr('class', 'inspector-hidden inspector-wrap');
+
+ var hoverModeSelect = function(targets) {
+ context.container().selectAll('.feature-list-item').classed('hover', false);
+
+ if (context.selectedIDs().length > 1 &&
+ targets && targets.length) {
+
+ var elements = context.container().selectAll('.feature-list-item')
+ .filter(function (node) {
+ return targets.indexOf(node) !== -1;
+ });
+
+ if (!elements.empty()) {
+ elements.classed('hover', true);
+ }
+ }
+ };
+
+ sidebar.hoverModeSelect = throttle(hoverModeSelect, 200);
+
+ function hover(targets) {
+ var datum = targets && targets.length && targets[0];
+ if (datum && datum.__featurehash__) { // hovering on data
+ _wasData = true;
+ sidebar
+ .show(dataEditor.datum(datum));
+
+ selection.selectAll('.sidebar-component')
+ .classed('inspector-hover', true);
+
+ } else if (datum && datum.__fbid__) { // hovering on RapiD data
+ _wasRapiD = true;
+ sidebar
+ .show(rapidInspector.datum(datum));
+
+ selection.selectAll('.sidebar-component')
+ .classed('inspector-hover', true);
+
+ } else if (datum instanceof osmNote) {
+ if (context.mode().id === 'drag-note') return;
+ _wasNote = true;
+
+ var osm = services.osm;
+ if (osm) {
+ datum = osm.getNote(datum.id); // marker may contain stale data - get latest
+ }
+
+ sidebar
+ .show(noteEditor.note(datum));
+
+ selection.selectAll('.sidebar-component')
+ .classed('inspector-hover', true);
+
+ } else if (datum instanceof QAItem) {
+ _wasQaItem = true;
+
+ var errService = services[datum.service];
+ if (errService) {
+ // marker may contain stale data - get latest
+ datum = errService.getError(datum.id);
+ }
+
+ // Currently only three possible services
+ var errEditor;
+ if (datum.service === 'keepRight') {
+ errEditor = keepRightEditor;
+ } else if (datum.service === 'osmose') {
+ errEditor = osmoseEditor;
+ } else {
+ errEditor = improveOsmEditor;
+ }
+
+ context.container().selectAll('.qaItem.' + datum.service)
+ .classed('hover', function(d) { return d.id === datum.id; });
+
+ sidebar
+ .show(errEditor.error(datum));
+
+ selection.selectAll('.sidebar-component')
+ .classed('inspector-hover', true);
+
+ } else if (!_current && (datum instanceof osmEntity)) {
+ featureListWrap
+ .classed('inspector-hidden', true);
+
+ inspectorWrap
+ .classed('inspector-hidden', false)
+ .classed('inspector-hover', true);
+
+ if (!inspector.entityIDs() || !utilArrayIdentical(inspector.entityIDs(), [datum.id]) || inspector.state() !== 'hover') {
+ inspector
+ .state('hover')
+ .entityIDs([datum.id])
+ .newFeature(false);
+
+ inspectorWrap
+ .call(inspector);
+ }
+
+ } else if (!_current) {
+ featureListWrap
+ .classed('inspector-hidden', false);
+ inspectorWrap
+ .classed('inspector-hidden', true);
+ inspector
+ .state('hide');
+
+ } else if (_wasRapiD || _wasData || _wasNote || _wasQaItem) {
+ _wasRapiD = false;
+ _wasNote = false;
+ _wasData = false;
+ _wasQaItem = false;
+ context.container().selectAll('.layer-ai-features .hover').classed('hover', false);
+ context.container().selectAll('.note').classed('hover', false);
+ context.container().selectAll('.qaItem').classed('hover', false);
+ sidebar.hide();
+ }
+ }
+
+ sidebar.hover = throttle(hover, 200);
+
+
+ sidebar.intersects = function(extent) {
+ var rect = selection.node().getBoundingClientRect();
+ return extent.intersects([
+ context.projection.invert([0, rect.height]),
+ context.projection.invert([rect.width, 0])
+ ]);
+ };
+
+
+ sidebar.select = function(ids, newFeature) {
+ sidebar.hide();
+
+ if (ids && ids.length) {
+
+ var entity = ids.length === 1 && context.entity(ids[0]);
+ if (entity && newFeature && selection.classed('collapsed')) {
+ // uncollapse the sidebar
+ var extent = entity.extent(context.graph());
+ sidebar.expand(sidebar.intersects(extent));
+ }
+
+ featureListWrap
+ .classed('inspector-hidden', true);
+
+ inspectorWrap
+ .classed('inspector-hidden', false)
+ .classed('inspector-hover', false);
+
+ if (!inspector.entityIDs() || !utilArrayIdentical(inspector.entityIDs(), ids) || inspector.state() !== 'select') {
+ inspector
+ .state('select')
+ .entityIDs(ids)
+ .newFeature(newFeature);
+
+ inspectorWrap
+ .call(inspector);
+ }
+
+ } else {
+ inspector
+ .state('hide');
+ }
+ };
+
+
+ sidebar.showPresetList = function() {
+ inspector.showList();
+ };
+
+
+ sidebar.show = function(component, element) {
+ featureListWrap
+ .classed('inspector-hidden', true);
+ inspectorWrap
+ .classed('inspector-hidden', true);
+
+ if (_current) _current.remove();
+ _current = selection
+ .append('div')
+ .attr('class', 'sidebar-component')
+ .call(component, element);
+ };
+
+
+ sidebar.hide = function() {
+ featureListWrap
+ .classed('inspector-hidden', false);
+ inspectorWrap
+ .classed('inspector-hidden', true);
+
+ if (_current) _current.remove();
+ _current = null;
+ };
+
+
+ sidebar.expand = function(moveMap) {
+ if (selection.classed('collapsed')) {
+ sidebar.toggle(moveMap);
+ }
+ };
+
+
+ sidebar.collapse = function(moveMap) {
+ if (!selection.classed('collapsed')) {
+ sidebar.toggle(moveMap);
+ }
+ };
+
+
+ sidebar.toggle = function(moveMap) {
+ var e = event;
+ if (e && e.sourceEvent) {
+ e.sourceEvent.preventDefault();
+ } else if (e) {
+ e.preventDefault();
+ }
+
+ // Don't allow sidebar to toggle when the user is in the walkthrough.
+ if (context.inIntro()) return;
+
+ var isCollapsed = selection.classed('collapsed');
+ var isCollapsing = !isCollapsed;
+ var isRTL = (_mainLocalizer.textDirection() === 'rtl');
+ var scaleX = isRTL ? 0 : 1;
+ var xMarginProperty = isRTL ? 'margin-right' : 'margin-left';
+
+ sidebarWidth = selection.node().getBoundingClientRect().width;
+
+ // switch from % to px
+ selection.style('width', sidebarWidth + 'px');
+
+ var startMargin, endMargin, lastMargin;
+ if (isCollapsing) {
+ startMargin = lastMargin = 0;
+ endMargin = -sidebarWidth;
+ } else {
+ startMargin = lastMargin = -sidebarWidth;
+ endMargin = 0;
+ }
+
+ selection.transition()
+ .style(xMarginProperty, endMargin + 'px')
+ .tween('panner', function() {
+ var i = d3_interpolateNumber(startMargin, endMargin);
+ return function(t) {
+ var dx = lastMargin - Math.round(i(t));
+ lastMargin = lastMargin - dx;
+ context.ui().onResize(moveMap ? undefined : [dx * scaleX, 0]);
+ };
+ })
+ .on('end', function() {
+ selection.classed('collapsed', isCollapsing);
+
+ // switch back from px to %
+ if (!isCollapsing) {
+ var containerWidth = container.node().getBoundingClientRect().width;
+ var widthPct = (sidebarWidth / containerWidth) * 100;
+ selection
+ .style(xMarginProperty, null)
+ .style('width', widthPct + '%');
+ }
+ });
+ };
+
+ // toggle the sidebar collapse when double-clicking the resizer
+ resizer.on('dblclick', sidebar.toggle);
+
+ // ensure hover sidebar is closed when zooming out beyond editable zoom
+ context.map().on('crossEditableZoom.sidebar', function(within) {
+ if (!within && !selection.select('.inspector-hover').empty()) {
+ hover([]);
+ }
+ });
+ }
+
+ sidebar.showPresetList = function() {};
+ sidebar.hover = function() {};
+ sidebar.hover.cancel = function() {};
+ sidebar.intersects = function() {};
+ sidebar.select = function() {};
+ sidebar.show = function() {};
+ sidebar.hide = function() {};
+ sidebar.expand = function() {};
+ sidebar.collapse = function() {};
+ sidebar.toggle = function() {};
+
+ return sidebar;
+ }
+
+ function uiSourceSwitch(context) {
+ var keys;
+
+
+ function click() {
+ event.preventDefault();
+
+ var osm = context.connection();
+ if (!osm) return;
+
+ if (context.inIntro()) return;
+
+ if (context.history().hasChanges() &&
+ !window.confirm(_t('source_switch.lose_changes'))) return;
+
+ var isLive = select(this)
+ .classed('live');
+
+ isLive = !isLive;
+ context.enter(modeBrowse(context));
+ context.history().clearSaved(); // remove saved history
+ context.flush(); // remove stored data
+
+ select(this)
+ .text(isLive ? _t('source_switch.live') : _t('source_switch.dev'))
+ .classed('live', isLive)
+ .classed('chip', isLive);
+
+ osm.switch(isLive ? keys[0] : keys[1]); // switch connection (warning: dispatches 'change' event)
+ }
+
+ var sourceSwitch = function(selection) {
+ selection
+ .append('a')
+ .attr('href', '#')
+ .text(_t('source_switch.live'))
+ .attr('class', 'live chip')
+ .on('click', click);
+ };
+
+
+ sourceSwitch.keys = function(_) {
+ if (!arguments.length) return keys;
+ keys = _;
+ return sourceSwitch;
+ };
+
+
+ return sourceSwitch;
+ }
+
+ function uiSpinner(context) {
+ var osm = context.connection();
+
+
+ return function(selection) {
+ var img = selection
+ .append('img')
+ .attr('src', context.imagePath('loader-black.gif'))
+ .style('opacity', 0);
+
+ if (osm) {
+ osm
+ .on('loading.spinner', function() {
+ img.transition()
+ .style('opacity', 1);
+ })
+ .on('loaded.spinner', function() {
+ img.transition()
+ .style('opacity', 0);
+ });
+ }
+ };
+ }
+
+ function uiStatus(context) {
+ var osm = context.connection();
+
+
+ return function(selection) {
+ if (!osm) return;
+
+ function update(err, apiStatus) {
+ selection.html('');
+
+ if (err) {
+ if (apiStatus === 'connectionSwitched') {
+ // if the connection was just switched, we can't rely on
+ // the status (we're getting the status of the previous api)
+ return;
+
+ } else if (apiStatus === 'rateLimited') {
+ selection
+ .text(_t('osm_api_status.message.rateLimit'))
+ .append('a')
+ .attr('class', 'api-status-login')
+ .attr('target', '_blank')
+ .call(svgIcon('#iD-icon-out-link', 'inline'))
+ .append('span')
+ .text(_t('login'))
+ .on('click.login', function() {
+ event.preventDefault();
+ osm.authenticate();
+ });
+ } else {
+
+ // don't allow retrying too rapidly
+ var throttledRetry = throttle(function() {
+ // try loading the visible tiles
+ context.loadTiles(context.projection);
+ // manually reload the status too in case all visible tiles were already loaded
+ osm.reloadApiStatus();
+ }, 2000);
+
+ // eslint-disable-next-line no-warning-comments
+ // TODO: nice messages for different error types
+ selection
+ .text(_t('osm_api_status.message.error') + ' ')
+ .append('a')
+ // let the user manually retry their connection directly
+ .text(_t('osm_api_status.retry'))
+ .on('click.retry', function() {
+ event.preventDefault();
+ throttledRetry();
+ });
+ }
+
+ } else if (apiStatus === 'readonly') {
+ selection.text(_t('osm_api_status.message.readonly'));
+ } else if (apiStatus === 'offline') {
+ selection.text(_t('osm_api_status.message.offline'));
+ }
+
+ selection.attr('class', 'api-status ' + (err ? 'error' : apiStatus));
+ }
+
+ osm.on('apiStatusChange.uiStatus', update);
+
+ // reload the status periodically regardless of other factors
+ window.setInterval(function() {
+ osm.reloadApiStatus();
+ }, 90000);
+
+ // load the initial status in case no OSM data was loaded yet
+ osm.reloadApiStatus();
+ };
+ }
+
+ function uiToolDownloadOsc(context) {
+
+ var tool = {
+ id: 'download_osc',
+ label: _t('download_osc.title')
+ };
+
+ var button = null;
+ var tooltipBehavior = null;
+ var history = context.history();
+ var _numChanges = 0;
+
+ function isDisabled() {
+ return _numChanges === 0;
+ }
+
+ function downloadOsc() {
+ event.preventDefault();
+ if (!context.inIntro() && history.hasChanges()) {
+ var _changeset = new osmChangeset();
+ var changes = history.changes(actionDiscardTags(history.difference()));
+ var osc = JXON.stringify(_changeset.osmChangeJXON(changes));
+ downloadFile(osc,'change.osc');
+ }
+ }
+
+ function updateCount() {
+ var val = history.difference().summary().length;
+ if (val === _numChanges) return;
+ _numChanges = val;
+
+ if (tooltipBehavior) {
+ tooltipBehavior
+ .title(
+ _t(_numChanges > 0 ? 'download_osc.help' : 'download_osc.no_changes')
+ );
+ }
+
+ if (button) {
+ button.classed('disabled', isDisabled());
+ }
+ }
+
+ function downloadFile(data, fileName) {
+ // Create an invisible A element
+ var a = document.createElement('a');
+ a.style.display = 'none';
+ document.body.appendChild(a);
+
+ // Set the HREF to a Blob representation of the data to be downloaded
+ a.href = window.URL.createObjectURL(
+ new Blob([data])
+ );
+
+ // Use download attribute to set set desired file name
+ a.setAttribute('download', fileName);
+
+ // Trigger the download by simulating click
+ a.click();
+
+ // Cleanup
+ window.URL.revokeObjectURL(a.href);
+ document.body.removeChild(a);
+ }
+
+
+ tool.render = function(selection) {
+
+ tooltipBehavior = uiTooltip()
+ .placement('bottom')
+ .title(_t('download_osc.no_changes'));
+
+ button = selection
+ .append('button')
+ .attr('class', 'downloadOsc disabled bar-button')
+ .on('click', downloadOsc)
+ .call(tooltipBehavior);
+
+ button
+ .call(svgIcon('#iD-icon-download-osc'));
+
+
+ updateCount();
+
+
+ context.history()
+ .on('change.download_osc', updateCount);
+
+ context
+ .on('enter.download_osc', function() {
+ if (button) {
+ button
+ .classed('disabled', isDisabled());
+ }
+ });
+ };
+
+ tool.uninstall = function() {
+
+ context.history()
+ .on('change.download', null);
+
+ context
+ .on('enter.download', null);
+
+ button = null;
+ tooltipBehavior = null;
+ };
+
+ return tool;
+ }
+
+ function uiToolOldDrawModes(context) {
+
+ var tool = {
+ id: 'old_modes',
+ label: _t('toolbar.add_feature')
+ };
+
+ var modes = [
+ modeAddPoint(context, {
+ title: _t('modes.add_point.title'),
+ button: 'point',
+ description: _t('modes.add_point.description'),
+ preset: _mainPresetIndex.item('point'),
+ key: '1'
+ }),
+ modeAddLine(context, {
+ title: _t('modes.add_line.title'),
+ button: 'line',
+ description: _t('modes.add_line.description'),
+ preset: _mainPresetIndex.item('line'),
+ key: '2'
+ }),
+ modeAddArea(context, {
+ title: _t('modes.add_area.title'),
+ button: 'area',
+ description: _t('modes.add_area.description'),
+ preset: _mainPresetIndex.item('area'),
+ key: '3'
+ })
+ ];
+
+
+ function enabled() {
+ return osmEditable();
+ }
+
+ function osmEditable() {
+ return context.editable();
+ }
+
+ modes.forEach(function(mode) {
+ context.keybinding().on(mode.key, function() {
+ if (!enabled()) return;
+
+ if (mode.id === context.mode().id) {
+ context.enter(modeBrowse(context));
+ } else {
+ context.enter(mode);
+ }
+ });
+ });
+
+ tool.render = function(selection) {
+
+ var wrap = selection
+ .append('div')
+ .attr('class', 'joined')
+ .style('display', 'flex');
+
+ var debouncedUpdate = debounce(update, 500, { leading: true, trailing: true });
+
+ context.map()
+ .on('move.modes', debouncedUpdate)
+ .on('drawn.modes', debouncedUpdate);
+
+ context
+ .on('enter.modes', update);
+
+ update();
+
+
+ function update() {
+
+ var buttons = wrap.selectAll('button.add-button')
+ .data(modes, function(d) { return d.id; });
+
+ // exit
+ buttons.exit()
+ .remove();
+
+ // enter
+ var buttonsEnter = buttons.enter()
+ .append('button')
+ .attr('class', function(d) { return d.id + ' add-button bar-button'; })
+ .on('click.mode-buttons', function(d) {
+ if (!enabled()) return;
+
+ // When drawing, ignore accidental clicks on mode buttons - #4042
+ var currMode = context.mode().id;
+ if (/^draw/.test(currMode)) return;
+
+ if (d.id === currMode) {
+ context.enter(modeBrowse(context));
+ } else {
+ context.enter(d);
+ }
+ })
+ .call(uiTooltip()
+ .placement('bottom')
+ .title(function(d) { return d.description; })
+ .keys(function(d) { return [d.key]; })
+ .scrollContainer(context.container().select('.top-toolbar'))
+ );
+
+ buttonsEnter
+ .each(function(d) {
+ select(this)
+ .call(svgIcon('#iD-icon-' + d.button));
+ });
+
+ buttonsEnter
+ .append('span')
+ .attr('class', 'label')
+ .text(function(mode) { return mode.title; });
+
+ // if we are adding/removing the buttons, check if toolbar has overflowed
+ if (buttons.enter().size() || buttons.exit().size()) {
+ context.ui().checkOverflow('.top-toolbar', true);
+ }
+
+ // update
+ buttons = buttons
+ .merge(buttonsEnter)
+ .classed('disabled', function(d) { return !enabled(); })
+ .classed('active', function(d) { return context.mode() && context.mode().button === d.button; });
+ }
+ };
+
+ return tool;
+ }
+
+ function uiToolNotes(context) {
+
+ var tool = {
+ id: 'notes',
+ label: _t('modes.add_note.label')
+ };
+
+ var mode = modeAddNote(context);
+
+ function enabled() {
+ return notesEnabled() && notesEditable();
+ }
+
+ function notesEnabled() {
+ var noteLayer = context.layers().layer('notes');
+ return noteLayer && noteLayer.enabled();
+ }
+
+ function notesEditable() {
+ var mode = context.mode();
+ return context.map().notesEditable() && mode && mode.id !== 'save';
+ }
+
+ context.keybinding().on(mode.key, function() {
+ if (!enabled()) return;
+
+ if (mode.id === context.mode().id) {
+ context.enter(modeBrowse(context));
+ } else {
+ context.enter(mode);
+ }
+ });
+
+ tool.render = function(selection) {
+
+
+ var debouncedUpdate = debounce(update, 500, { leading: true, trailing: true });
+
+ context.map()
+ .on('move.notes', debouncedUpdate)
+ .on('drawn.notes', debouncedUpdate);
+
+ context
+ .on('enter.notes', update);
+
+ update();
+
+
+ function update() {
+ var showNotes = notesEnabled();
+ var data = showNotes ? [mode] : [];
+
+ var buttons = selection.selectAll('button.add-button')
+ .data(data, function(d) { return d.id; });
+
+ // exit
+ buttons.exit()
+ .remove();
+
+ // enter
+ var buttonsEnter = buttons.enter()
+ .append('button')
+ .attr('tabindex', -1)
+ .attr('class', function(d) { return d.id + ' add-button bar-button'; })
+ .on('click.notes', function(d) {
+ if (!enabled()) return;
+
+ // When drawing, ignore accidental clicks on mode buttons - #4042
+ var currMode = context.mode().id;
+ if (/^draw/.test(currMode)) return;
+
+ if (d.id === currMode) {
+ context.enter(modeBrowse(context));
+ } else {
+ context.enter(d);
+ }
+ })
+ .call(uiTooltip()
+ .placement('bottom')
+ .title(function(d) { return d.description; })
+ .keys(function(d) { return [d.key]; })
+ .scrollContainer(context.container().select('.top-toolbar'))
+ );
+
+ buttonsEnter
+ .each(function(d) {
+ select(this)
+ .call(svgIcon(d.icon || '#iD-icon-' + d.button));
+ });
+
+ // if we are adding/removing the buttons, check if toolbar has overflowed
+ if (buttons.enter().size() || buttons.exit().size()) {
+ context.ui().checkOverflow('.top-toolbar', true);
+ }
+
+ // update
+ buttons = buttons
+ .merge(buttonsEnter)
+ .classed('disabled', function(d) { return !enabled(); })
+ .classed('active', function(d) { return context.mode() && context.mode().button === d.button; });
+ }
+ };
+
+ tool.uninstall = function() {
+ context
+ .on('enter.editor.notes', null)
+ .on('exit.editor.notes', null)
+ .on('enter.notes', null);
+
+ context.map()
+ .on('move.notes', null)
+ .on('drawn.notes', null);
+ };
+
+ return tool;
+ }
+
+ function uiToolSave(context) {
+
+ var tool = {
+ id: 'save',
+ label: _t('save.title')
+ };
+
+ var button = null;
+ var tooltipBehavior = null;
+ var history = context.history();
+ var key = uiCmd('⌘S');
+ var _numChanges = 0;
+
+ function isSaving() {
+ var mode = context.mode();
+ return mode && mode.id === 'save';
+ }
+
+ function isDisabled() {
+ return _numChanges === 0 || isSaving();
+ }
+
+ function save() {
+ event.preventDefault();
+ if (!context.inIntro() && !isSaving() && history.hasChanges()) {
+ context.enter(modeSave(context));
+ }
+ }
+
+ function bgColor() {
+ var step;
+ if (_numChanges === 0) {
+ return null;
+ } else if (_numChanges <= 50) {
+ step = _numChanges / 50;
+ return d3_interpolateRgb('#fff', '#ff8')(step); // white -> yellow
+ } else {
+ step = Math.min((_numChanges - 50) / 50, 1.0);
+ return d3_interpolateRgb('#ff8', '#f88')(step); // yellow -> red
+ }
+ }
+
+ function updateCount() {
+ var val = history.difference().summary().length;
+ if (val === _numChanges) return;
+
+ _numChanges = val;
+
+ if (tooltipBehavior) {
+ tooltipBehavior
+ .title(_t(_numChanges > 0 ? 'save.help' : 'save.no_changes'))
+ .keys([key]);
+ }
+
+ if (button) {
+ button
+ .classed('disabled', isDisabled())
+ .style('background', bgColor());
+
+ button.select('span.count')
+ .text(_numChanges);
+ }
+ }
+
+
+ tool.render = function(selection) {
+ tooltipBehavior = uiTooltip()
+ .placement('bottom')
+ .title(_t('save.no_changes'))
+ .keys([key])
+ .scrollContainer(context.container().select('.top-toolbar'));
+
+ var lastPointerUpType;
+
+ button = selection
+ .append('button')
+ .attr('class', 'save disabled bar-button')
+ .on('pointerup', function() {
+ lastPointerUpType = event.pointerType;
+ })
+ .on('click', function() {
+ event.preventDefault();
+
+ save();
+
+ if (_numChanges === 0 && (
+ lastPointerUpType === 'touch' ||
+ lastPointerUpType === 'pen')
+ ) {
+ // there are no tooltips for touch interactions so flash feedback instead
+ context.ui().flash
+ .duration(2000)
+ .iconName('#iD-icon-save')
+ .iconClass('disabled')
+ .text(_t('save.no_changes'))();
+ }
+ lastPointerUpType = null;
+ })
+ .call(tooltipBehavior);
+
+ button
+ .call(svgIcon('#iD-icon-save'));
+
+ button
+ .append('span')
+ .attr('class', 'count')
+ .attr('aria-hidden', 'true')
+ .text('0');
+
+ updateCount();
+
+
+ context.keybinding()
+ .on(key, save, true);
+
+
+ context.history()
+ .on('change.save', updateCount);
+
+ context
+ .on('enter.save', function() {
+ if (button) {
+ button
+ .classed('disabled', isDisabled());
+
+ if (isSaving()) {
+ button.call(tooltipBehavior.hide);
+ }
+ }
+ });
+ };
+
+
+ tool.uninstall = function() {
+ context.keybinding()
+ .off(key, true);
+
+ context.history()
+ .on('change.save', null);
+
+ context
+ .on('enter.save', null);
+
+ button = null;
+ tooltipBehavior = null;
+ };
+
+ return tool;
+ }
+
+ function uiToolSidebarToggle(context) {
+
+ var tool = {
+ id: 'sidebar_toggle',
+ label: _t('toolbar.inspect')
+ };
+
+ tool.render = function(selection) {
+ selection
+ .append('button')
+ .attr('class', 'bar-button')
+ .on('click', function() {
+ context.ui().sidebar.toggle();
+ })
+ .call(uiTooltip()
+ .placement('bottom')
+ .title(_t('sidebar.tooltip'))
+ .keys([_t('sidebar.key')])
+ .scrollContainer(context.container().select('.top-toolbar'))
+ )
+ .call(svgIcon('#iD-icon-sidebar-' + (_mainLocalizer.textDirection() === 'rtl' ? 'right' : 'left')));
+ };
+
+ return tool;
+ }
+
+ function uiToolUndoRedo(context) {
+
+ var tool = {
+ id: 'undo_redo',
+ label: _t('toolbar.undo_redo')
+ };
+
+ var commands = [{
+ id: 'undo',
+ cmd: uiCmd('⌘Z'),
+ action: function() {
+ context.undo();
+ },
+ annotation: function() {
+ return context.history().undoAnnotation();
+ },
+ icon: 'iD-icon-' + (_mainLocalizer.textDirection() === 'rtl' ? 'redo' : 'undo')
+ }, {
+ id: 'redo',
+ cmd: uiCmd('⌘⇧Z'),
+ action: function() {
+ context.redo();
+ },
+ annotation: function() {
+ return context.history().redoAnnotation();
+ },
+ icon: 'iD-icon-' + (_mainLocalizer.textDirection() === 'rtl' ? 'undo' : 'redo')
+ }];
+
+
+ function editable() {
+ return context.mode() && context.mode().id !== 'save' && context.map().editableDataEnabled(true /* ignore min zoom */);
+ }
+
+
+ tool.render = function(selection) {
+ var tooltipBehavior = uiTooltip()
+ .placement('bottom')
+ .title(function (d) {
+ // Handle string- or object-style annotations. Object-style
+ // should include "type" and "description" keys, where
+ // "description" is used in place of a string-style annotation.
+ // See ui/rapid_feature_inspector.js for the motivating use case.
+ return (d.annotation() ?
+ _t(d.id + '.tooltip', {
+ action: d.annotation().description
+ ? d.annotation().description
+ : d.annotation(),
+ }) :
+ _t(d.id + '.nothing'), d.cmd);
+ })
+ .keys(function(d) {
+ return [d.cmd];
+ })
+ .scrollContainer(context.container().select('.top-toolbar'));
+
+ var lastPointerUpType;
+
+ var buttons = selection.selectAll('button')
+ .data(commands)
+ .enter()
+ .append('button')
+ .attr('class', function(d) { return 'disabled ' + d.id + '-button bar-button'; })
+ .on('pointerup', function() {
+ // `pointerup` is always called before `click`
+ lastPointerUpType = event.pointerType;
+ })
+ .on('click', function(d) {
+ event.preventDefault();
+
+ var annotation = d.annotation();
+
+ if (editable() && annotation) {
+ d.action();
+ }
+
+ if (editable() && (
+ lastPointerUpType === 'touch' ||
+ lastPointerUpType === 'pen')
+ ) {
+ // there are no tooltips for touch interactions so flash feedback instead
+
+ var text = annotation ?
+ _t(d.id + '.tooltip', { action: annotation }) :
+ _t(d.id + '.nothing');
+ context.ui().flash
+ .duration(2000)
+ .iconName('#' + d.icon)
+ .iconClass(annotation ? '' : 'disabled')
+ .text(text)();
+ }
+ lastPointerUpType = null;
+ })
+ .call(tooltipBehavior);
+
+ buttons.each(function(d) {
+ select(this)
+ .call(svgIcon('#' + d.icon));
+ });
+
+ context.keybinding()
+ .on(commands[0].cmd, function() {
+ event.preventDefault();
+ if (editable()) commands[0].action();
+ })
+ .on(commands[1].cmd, function() {
+ event.preventDefault();
+ if (editable()) commands[1].action();
+ });
+
+
+ var debouncedUpdate = debounce(update, 500, { leading: true, trailing: true });
+
+ context.map()
+ .on('move.undo_redo', debouncedUpdate)
+ .on('drawn.undo_redo', debouncedUpdate);
+
+ context.history()
+ .on('change.undo_redo', function(difference) {
+ if (difference) update();
+ });
+
+ context
+ .on('enter.undo_redo', update);
+
+
+ function update() {
+ buttons
+ .classed('disabled', function(d) {
+ return !editable() || !d.annotation();
+ })
+ .each(function() {
+ var selection = select(this);
+ if (!selection.select('.tooltip.in').empty()) {
+ selection.call(tooltipBehavior.updateContent);
+ }
+ });
+ }
+ };
+
+ tool.uninstall = function() {
+ context.keybinding()
+ .off(commands[0].cmd)
+ .off(commands[1].cmd);
+
+ context.map()
+ .on('move.undo_redo', null)
+ .on('drawn.undo_redo', null);
+
+ context.history()
+ .on('change.undo_redo', null);
+
+ context
+ .on('enter.undo_redo', null);
+ };
+
+ return tool;
+ }
+
+ function uiRapidColorpicker(context, parentModal) {
+ const rapidContext = context.rapidContext();
+ const dispatch$1 = dispatch('change', 'done');
+
+ let _close = () => {};
+
+
+ function togglePopup(d, i, nodes) {
+ const shaded = context.container().selectAll('.shaded'); // container for the existing modal
+ if (shaded.empty()) return;
+
+ if (shaded.selectAll('.colorpicker-popup').size()) {
+ _close();
+ } else {
+ renderPopup(shaded, nodes[i]);
+ }
+ }
+
+
+ // if user clicks outside the colorpicker, dismiss
+ function handleClick() {
+ const target = event.target;
+ const className = (target && target.className) || '';
+ if (!/colorpicker/i.test(className)) {
+ event.stopPropagation();
+ event.preventDefault();
+ _close();
+ }
+ }
+
+ // https://www.w3.org/TR/AERT#color-contrast
+ // https://trendct.org/2016/01/22/how-to-choose-a-label-color-to-contrast-with-background/
+ // pass color as a hexstring like '#rgb', '#rgba', '#rrggbb', '#rrggbbaa' (alpha values are ignored)
+ function getBrightness(color) {
+ const short = (color.length < 6);
+ const r = parseInt(short ? color[1] + color[1] : color[1] + color[2], 16);
+ const g = parseInt(short ? color[2] + color[2] : color[3] + color[4], 16);
+ const b = parseInt(short ? color[3] + color[3] : color[5] + color[6], 16);
+ return ((r * 299) + (g * 587) + (b * 114)) / 1000;
+ }
+
+
+ function render(selection) {
+ let colorpicker = selection.selectAll('.rapid-colorpicker')
+ .data(d => [d], d => d.id); // retain data from parent
+
+ // enter
+ let colorpickerEnter = colorpicker.enter()
+ .append('div')
+ .attr('class', 'rapid-colorpicker')
+ .on('click', togglePopup);
+
+ colorpickerEnter
+ .append('div')
+ .attr('class', 'rapid-colorpicker-fill')
+ .call(svgIcon('#fas-palette'));
+
+ // update
+ colorpicker
+ .merge(colorpickerEnter)
+ .selectAll('.rapid-colorpicker-fill')
+ .style('background', d => d.color)
+ .select('.icon') // propagate bound data
+ .style('color', d => getBrightness(d.color) > 140.5 ? '#333' : '#fff');
+ }
+
+
+ function renderPopup(selection, forNode) {
+ const dataset = forNode.__data__;
+ const rect = forNode.getBoundingClientRect();
+ const popWidth = 180;
+ const popTop = rect.bottom + 15;
+ const popLeft = _mainLocalizer.textDirection() === 'rtl'
+ ? rect.right - (0.3333 * popWidth)
+ : rect.left - (0.6666 * popWidth);
+ const arrowLeft = _mainLocalizer.textDirection() === 'rtl'
+ ? (0.3333 * popWidth) - rect.width + 10
+ : (0.6666 * popWidth) + 10;
+
+ const origClose = parentModal.close;
+ parentModal.close = () => { /* ignore */ };
+
+ _close = () => {
+ popup
+ .transition()
+ .duration(200)
+ .style('opacity', 0)
+ .remove();
+
+ parentModal.close = origClose; // restore close handler
+
+ let keybinding = utilKeybinding('modal');
+ keybinding.on(['⌫', '⎋'], origClose);
+ select(document).call(keybinding);
+ select(document).on('click.colorpicker', null);
+ _close = () => {};
+ dispatch$1.call('done');
+ };
+
+ let keybinding = utilKeybinding('modal');
+ keybinding.on(['⌫', '⎋'], _close);
+ select(document).call(keybinding);
+ select(document).on('click.colorpicker', handleClick);
+
+ let popup = selection
+ .append('div')
+ .attr('class', 'colorpicker-popup')
+ .style('opacity', 0)
+ .style('width', popWidth + 'px')
+ .style('top', popTop + 'px')
+ .style('left', popLeft + 'px');
+
+ popup
+ .append('div')
+ .attr('class', 'colorpicker-arrow')
+ .style('left', arrowLeft + 'px');
+
+ let content = popup
+ .append('div')
+ .attr('class', 'colorpicker-content');
+
+ let colorlist = content.selectAll('.colorpicker-colors')
+ .data([0]);
+
+ colorlist = colorlist.enter()
+ .append('div')
+ .attr('class', 'colorpicker-colors')
+ .merge(colorlist);
+
+ let colorItems = colorlist.selectAll('.colorpicker-option')
+ .data(rapidContext.colors());
+
+ // enter
+ let colorItemsEnter = colorItems.enter()
+ .append('div')
+ .attr('class', 'colorpicker-option')
+ .style('color', d => d)
+ .on('click', selectedColor => {
+ dispatch$1.call('change', this, dataset.id, selectedColor);
+ colorItems.classed('selected', d => d === selectedColor);
+ });
+
+ colorItemsEnter
+ .append('div')
+ .attr('class', 'colorpicker-option-fill');
+
+ // update
+ colorItems = colorItems
+ .merge(colorItemsEnter);
+
+ colorItems
+ .classed('selected', d => d === dataset.color);
+
+ popup
+ .transition()
+ .style('opacity', 1);
+ }
+
+ return utilRebind(render, dispatch$1, 'on');
+ }
+
+ function uiRapidViewManageDatasets(context, parentModal) {
+ const rapidContext = context.rapidContext();
+ const dispatch$1 = dispatch('done');
+ const PERPAGE = 4;
+
+ let _content = select(null);
+ let _datasetInfo;
+ let _datasetStart = 0;
+ let _myClose = () => true; // custom close handler
+
+
+ function clamp(num, min, max) {
+ return Math.max(min, Math.min(num, max));
+ }
+
+
+ function clickPage(d) {
+ if (!Array.isArray(_datasetInfo)) return;
+
+ const pages = Math.ceil(_datasetInfo.length / PERPAGE);
+ _datasetStart = clamp(d, 0, pages - 1) * PERPAGE;
+
+ _content
+ .call(renderModalContent);
+ }
+
+
+ function nextPreviousPage(d) {
+ if (!Array.isArray(_datasetInfo)) return;
+
+ const pages = Math.ceil(_datasetInfo.length / PERPAGE);
+ const currPage = Math.floor(_datasetStart / PERPAGE);
+ const nextPage = utilWrap(currPage + d, pages);
+ _datasetStart = nextPage * PERPAGE;
+
+ _content
+ .call(renderModalContent);
+ }
+
+
+ function render() {
+ // Unfortunately `uiModal` is written in a way that there can be only one at a time.
+ // So we have to roll our own modal here instead of just creating a second `uiModal`.
+ let shaded = context.container().selectAll('.shaded'); // container for the existing modal
+ if (shaded.empty()) return;
+ if (shaded.selectAll('.modal-view-manage').size()) return; // view/manage modal exists already
+
+ const origClose = parentModal.close;
+ parentModal.close = () => { /* ignore */ };
+
+ // override the close handler
+ _myClose = () => {
+ myModal
+ .transition()
+ .duration(200)
+ .style('top', '0px')
+ .on('end', () => myShaded.remove());
+
+ parentModal.close = origClose; // restore close handler
+
+ let keybinding = utilKeybinding('modal');
+ keybinding.on(['⌫', '⎋'], origClose);
+ select(document).call(keybinding);
+ dispatch$1.call('done');
+ };
+
+
+ let keybinding = utilKeybinding('modal');
+ keybinding.on(['⌫', '⎋'], _myClose);
+ select(document).call(keybinding);
+
+ let myShaded = shaded
+ .append('div')
+ .attr('class', 'view-manage-wrap'); // need absolutely positioned div here for new stacking context
+
+ let myModal = myShaded
+ .append('div')
+ .attr('class', 'modal rapid-modal modal-view-manage') // RapiD styling
+ .style('opacity', 0);
+
+ myModal
+ .append('button')
+ .attr('class', 'close')
+ .on('click', _myClose)
+ .call(svgIcon('#iD-icon-close'));
+
+ _content = myModal
+ .append('div')
+ .attr('class', 'rapid-stack content');
+
+ _content
+ .call(renderModalContent);
+
+ _content.selectAll('.ok-button')
+ .node()
+ .focus();
+
+ myModal
+ .transition()
+ .style('opacity', 1);
+ }
+
+
+ function renderModalContent(selection) {
+ const isRTL = _mainLocalizer.textDirection() === 'rtl';
+
+ /* Header section */
+ let headerEnter = selection.selectAll('.rapid-view-manage-header')
+ .data([0])
+ .enter()
+ .append('div')
+ .attr('class', 'modal-section rapid-view-manage-header');
+
+ let line1 = headerEnter
+ .append('div');
+
+ line1
+ .append('div')
+ .attr('class', 'rapid-view-manage-header-icon')
+ .call(svgIcon('#iD-icon-data', 'icon-30'));
+
+ line1
+ .append('div')
+ .attr('class', 'rapid-view-manage-header-text')
+ .text(_t('rapid_feature_toggle.esri.title'));
+
+ line1
+ .append('div')
+ .attr('class', 'rapid-view-manage-header-inputs');
+ // .text('Home / Search');
+
+ let line2 = headerEnter
+ .append('div');
+
+ line2
+ .append('div')
+ .attr('class', 'rapid-view-manage-header-about')
+ .html(marked_1(_t('rapid_feature_toggle.esri.about')));
+
+ line2.selectAll('a')
+ .attr('target', '_blank');
+
+
+ /* Pages section */
+ let pagesSection = selection.selectAll('.rapid-view-manage-pages')
+ .data([0]);
+
+ let pagesSectionEnter = pagesSection.enter()
+ .append('div')
+ .attr('class', 'modal-section rapid-view-manage-pages');
+
+ pagesSection = pagesSection
+ .merge(pagesSectionEnter)
+ .call(renderPages);
+
+
+ /* Dataset section */
+ let dsSection = selection.selectAll('.rapid-view-manage-datasets-section')
+ .data([0]);
+
+ // enter
+ let dsSectionEnter = dsSection.enter()
+ .append('div')
+ .attr('class', 'modal-section rapid-view-manage-datasets-section');
+
+ dsSectionEnter
+ .append('div')
+ .attr('class', 'rapid-view-manage-pageleft')
+ .call(svgIcon(isRTL ? '#iD-icon-forward' : '#iD-icon-backward'))
+ .on('click', () => nextPreviousPage(isRTL ? 1 : -1) );
+
+ dsSectionEnter
+ .append('div')
+ .attr('class', 'rapid-view-manage-datasets');
+
+ dsSectionEnter
+ .append('div')
+ .attr('class', 'rapid-view-manage-pageright')
+ .call(svgIcon(isRTL ? '#iD-icon-backward' : '#iD-icon-forward'))
+ .on('click', () => nextPreviousPage(isRTL ? -1 : 1) );
+
+ // update
+ dsSection = dsSection
+ .merge(dsSectionEnter);
+
+ dsSection.selectAll('.rapid-view-manage-datasets')
+ .call(renderDatasets);
+
+
+ /* OK Button */
+ let buttonsEnter = selection.selectAll('.modal-section.buttons')
+ .data([0])
+ .enter()
+ .append('div')
+ .attr('class', 'modal-section buttons');
+
+ buttonsEnter
+ .append('button')
+ .attr('class', 'button ok-button action')
+ .on('click', _myClose)
+ .text(_t('confirm.okay'));
+ }
+
+
+ function renderDatasets(selection) {
+ const showPreview = corePreferences('rapid-internal-feature.previewDatasets') === 'true';
+ const service = services.esriData;
+ if (!service || (Array.isArray(_datasetInfo) && !_datasetInfo.length)) {
+ selection.text(_t('rapid_feature_toggle.esri.no_datasets'));
+ return;
+ }
+
+ if (!_datasetInfo) {
+ selection.text(_t('rapid_feature_toggle.esri.fetching_datasets'));
+ service.loadDatasets()
+ .then(results => {
+ // exclude preview datasets unless user has opted into them
+ return _datasetInfo = Object.values(results)
+ .filter(d => showPreview || !d.groupCategories.some(category => category === '/Categories/Preview'));
+ })
+ .then(() => _content.call(renderModalContent));
+ return;
+ }
+
+ selection.text('');
+
+ let page = _datasetInfo.slice(_datasetStart, _datasetStart + PERPAGE);
+ let datasets = selection.selectAll('.rapid-view-manage-dataset')
+ .data(page, d => d.id);
+
+ // exit
+ datasets.exit()
+ .remove();
+
+ // enter
+ let datasetsEnter = datasets.enter()
+ .append('div')
+ .attr('class', 'rapid-view-manage-dataset');
+
+ let labelsEnter = datasetsEnter
+ .append('div')
+ .attr('class', 'rapid-view-manage-dataset-label');
+
+ labelsEnter
+ .append('div')
+ .attr('class', 'rapid-view-manage-dataset-name')
+ .text(d => d.title);
+
+ labelsEnter
+ .append('div')
+ .attr('class', 'rapid-view-manage-dataset-license')
+ .append('a')
+ .attr('class', 'rapid-view-manage-dataset-link')
+ .attr('target', '_blank')
+ .attr('href', d => d.itemURL)
+ .text(_t('rapid_feature_toggle.esri.more_info'))
+ .call(svgIcon('#iD-icon-out-link', 'inline'));
+
+ labelsEnter.selectAll('.rapid-view-manage-dataset-beta')
+ .data(d => d.groupCategories.filter(d => d === '/Categories/Preview'))
+ .enter()
+ .append('div')
+ .attr('class', 'rapid-view-manage-dataset-beta beta')
+ .attr('title', _t('rapid_poweruser_features.beta'));
+
+ labelsEnter
+ .append('div')
+ .text(d => d.snippet);
+
+ labelsEnter
+ .append('button')
+ .attr('class', 'rapid-view-manage-dataset-action')
+ .on('click', toggleDataset);
+
+ let thumbsEnter = datasetsEnter
+ .append('div')
+ .attr('class', 'rapid-view-manage-dataset-thumb');
+
+ thumbsEnter
+ .append('img')
+ .attr('class', 'rapid-view-manage-dataset-thumbnail')
+ .attr('src', d => `https://openstreetmap.maps.arcgis.com/sharing/rest/content/items/${d.id}/info/${d.thumbnail}?w=400`);
+
+ // update
+ datasets = datasets
+ .merge(datasetsEnter);
+
+ datasets.selectAll('.rapid-view-manage-dataset-action')
+ .classed('secondary', d => datasetAdded(d))
+ .text(d => datasetAdded(d) ? _t('rapid_feature_toggle.esri.remove') : _t('rapid_feature_toggle.esri.add_to_map'));
+ }
+
+
+ function renderPages(selection) {
+ if (!_datasetInfo) return;
+
+ const total = _datasetInfo.length;
+ const numPages = Math.ceil(total / PERPAGE);
+ const currPage = Math.floor(_datasetStart / PERPAGE);
+ const pages = Array.from(Array(numPages).keys());
+
+ let dots = selection.selectAll('.rapid-view-manage-page')
+ .data(pages);
+
+ // exit
+ dots.exit()
+ .remove();
+
+ // enter/update
+ dots.enter()
+ .append('span')
+ .attr('class', 'rapid-view-manage-page')
+ .html('⬤')
+ .on('click', clickPage)
+ .merge(dots)
+ .classed('current', d => d === currPage);
+ }
+
+
+ function toggleDataset(d, i, nodes) {
+ const datasets = rapidContext.datasets();
+ const ds = datasets[d.id];
+
+ if (ds) {
+ ds.added = !ds.added;
+
+ } else { // hasn't been added yet
+ const isBeta = d.groupCategories.some(d => d === '/Categories/Preview');
+ const isBuildings = d.groupCategories.some(d => d === '/Categories/Buildings');
+
+ // pick a new color
+ const colors = rapidContext.colors();
+ const colorIndex = Object.keys(datasets).length % colors.length;
+
+ let dataset = {
+ id: d.id,
+ beta: isBeta,
+ added: true, // whether it should appear in the list
+ enabled: true, // whether the user has checked it on
+ conflated: false,
+ service: 'esri',
+ color: colors[colorIndex],
+ label: d.title,
+ license_markdown: _t('rapid_feature_toggle.esri.license_markdown')
+ };
+
+ if (d.extent) {
+ dataset.extent = geoExtent(d.extent);
+ }
+
+ // Test running building layers only through conflation service
+ if (isBuildings) {
+ dataset.conflated = true;
+ dataset.service = 'fbml';
+ }
+
+ datasets[d.id] = dataset;
+ }
+
+ nodes[i].blur();
+ _content.call(renderModalContent);
+
+ context.enter(modeBrowse(context)); // return to browse mode (in case something was selected)
+ context.map().pan([0,0]); // trigger a map redraw
+ }
+
+
+ function datasetAdded(d) {
+ const datasets = rapidContext.datasets();
+ return datasets[d.id] && datasets[d.id].added;
+ }
+
+
+ return utilRebind(render, dispatch$1, 'on');
+ }
+
+ function uiRapidFeatureToggleDialog(context, AIFeatureToggleKey, featureToggleKeyDispatcher) {
+ const rapidContext = context.rapidContext();
+
+ let _modalSelection = select(null);
+ let _content = select(null);
+ let _viewManageModal;
+ let _colorpicker;
+
+
+ function datasetEnabled(d) {
+ const dataset = rapidContext.datasets()[d.id];
+ return dataset && dataset.enabled;
+ }
+
+ function toggleDataset(d) {
+ const dataset = rapidContext.datasets()[d.id];
+ if (dataset) {
+ dataset.enabled = !dataset.enabled;
+ context.enter(modeBrowse(context)); // return to browse mode (in case something was selected)
+ context.map().pan([0,0]); // trigger a map redraw
+ }
+ }
+
+ function changeColor(datasetID, color) {
+ const dataset = rapidContext.datasets()[datasetID];
+ if (dataset) {
+ dataset.color = color;
+ context.map().pan([0,0]); // trigger a map redraw
+ _content.call(renderModalContent);
+
+ // if a RapiD feature is selected, reselect it to update sidebar too
+ const mode = context.mode();
+ if (mode && mode.id === 'select-ai-features')
+ context.enter(mode, mode.selectedDatum());
+ }
+ }
+
+ function toggleRapid() {
+ const rapidLayer = context.layers().layer('ai-features');
+ rapidLayer.enabled(!rapidLayer.enabled()); // toggling the layer will trigger a map redraw
+ _content.call(renderModalContent);
+ }
+
+
+ function keyPressHandler() {
+ if (event.shiftKey && event.key === _t('map_data.layers.ai-features.key')) {
+ toggleRapid();
+ }
+ }
+
+
+ return function render(selection) {
+ _modalSelection = uiModal(selection);
+
+ _modalSelection.select('.modal')
+ .attr('class', 'modal rapid-modal'); // RapiD styling
+
+ _viewManageModal = uiRapidViewManageDatasets(context, _modalSelection)
+ .on('done', () => _content.call(renderModalContent));
+
+ _colorpicker = uiRapidColorpicker(context, _modalSelection)
+ .on('change', changeColor);
+
+ _content = _modalSelection.select('.content')
+ .append('div')
+ .attr('class', 'rapid-stack')
+ .on('keypress', keyPressHandler);
+
+ _content
+ .call(renderModalContent);
+
+ _content.selectAll('.ok-button')
+ .node()
+ .focus();
+
+ featureToggleKeyDispatcher
+ .on('ai_feature_toggle', () => _content.call(renderModalContent) );
+ };
+
+
+ function renderModalContent(selection) {
+ const rapidLayer = context.layers().layer('ai-features');
+
+ /* Toggle All */
+ let toggleAll = selection.selectAll('.rapid-toggle-all')
+ .data([0]);
+
+ // enter
+ let toggleAllEnter = toggleAll
+ .enter()
+ .append('div')
+ .attr('class', 'modal-section rapid-checkbox rapid-toggle-all');
+
+ let toggleAllTextEnter = toggleAllEnter
+ .append('div')
+ .attr('class', 'rapid-feature-label-container');
+
+ toggleAllTextEnter
+ .append('div')
+ .attr('class', 'rapid-feature-label')
+ .html(_t('rapid_feature_toggle.toggle_all', { rapidicon: icon('#iD-logo-rapid', 'logo-rapid') }));
+
+ toggleAllTextEnter
+ .append('span')
+ .attr('class', 'rapid-feature-hotkey')
+ .html('(' + AIFeatureToggleKey + ')');
+
+ let toggleAllCheckboxEnter = toggleAllEnter
+ .append('div')
+ .attr('class', 'rapid-checkbox-inputs')
+ .append('label')
+ .attr('class', 'rapid-checkbox-label');
+
+ toggleAllCheckboxEnter
+ .append('input')
+ .attr('type', 'checkbox')
+ .attr('class', 'rapid-feature-checkbox')
+ .on('click', toggleRapid);
+
+ toggleAllCheckboxEnter
+ .append('div')
+ .attr('class', 'rapid-checkbox-custom');
+
+ // update
+ toggleAll = toggleAll
+ .merge(toggleAllEnter);
+
+ toggleAll.selectAll('.rapid-feature-checkbox')
+ .property('checked', rapidLayer.showAll());
+
+
+ /* Dataset List */
+ let datasets = selection.selectAll('.rapid-datasets-container')
+ .data([0]);
+
+ let datasetsEnter = datasets.enter()
+ .append('div')
+ .attr('class', 'rapid-datasets-container');
+
+ datasets
+ .merge(datasetsEnter)
+ .call(renderDatasets);
+
+
+ /* View/Manage Datasets */
+ let manageDatasetsEnter = selection.selectAll('.rapid-manage-datasets')
+ .data([0])
+ .enter()
+ .append('div')
+ .attr('class', 'modal-section rapid-checkbox rapid-manage-datasets')
+ .on('click', () => context.container().call(_viewManageModal));
+
+ manageDatasetsEnter
+ .append('div')
+ .attr('class', 'rapid-feature-label-container')
+ .append('div')
+ .attr('class', 'rapid-feature-label')
+ .text(_t('rapid_feature_toggle.view_manage_datasets'));
+
+ manageDatasetsEnter
+ .append('div')
+ .attr('class', 'rapid-checkbox-inputs')
+ .append('div')
+ .attr('class', 'rapid-checkbox-label')
+ .call(svgIcon(_mainLocalizer.textDirection() === 'rtl' ? '#iD-icon-backward' : '#iD-icon-forward', 'icon-30'));
+
+
+ /* OK Button */
+ let buttonsEnter = selection.selectAll('.modal-section.buttons')
+ .data([0])
+ .enter()
+ .append('div')
+ .attr('class', 'modal-section buttons');
+
+ buttonsEnter
+ .append('button')
+ .attr('class', 'button ok-button action')
+ .on('click', () => _modalSelection.remove())
+ .text(_t('confirm.okay'));
+ }
+
+
+ function renderDatasets(selection) {
+ const showPreview = corePreferences('rapid-internal-feature.previewDatasets') === 'true';
+ const datasets = Object.values(rapidContext.datasets())
+ .filter(d => d.added && (showPreview || !d.beta)); // exclude preview datasets unless user has opted into them
+
+ const rapidLayer = context.layers().layer('ai-features');
+
+ let rows = selection.selectAll('.rapid-checkbox-dataset')
+ .data(datasets, d => d.id);
+
+ // exit
+ rows.exit()
+ .remove();
+
+ // enter
+ let rowsEnter = rows.enter()
+ .append('div')
+ .attr('class', 'modal-section rapid-checkbox rapid-checkbox-dataset');
+
+ rowsEnter
+ .append('div')
+ .attr('class', 'rapid-feature')
+ .each((d, i, nodes) => {
+ let selection = select(nodes[i]);
+
+ // line1: name and details
+ let labelEnter = selection
+ .append('div')
+ .attr('class', 'rapid-feature-label-container');
+
+ labelEnter
+ .append('div')
+ .attr('class', 'rapid-feature-label')
+ .text(d.label || d.id); // fallback to dataset ID
+
+ if (d.beta) {
+ labelEnter
+ .append('div')
+ .attr('class', 'rapid-feature-label-beta beta')
+ .attr('title', _t('rapid_poweruser_features.beta'));
+ }
+
+ if (d.description) {
+ labelEnter
+ .append('div')
+ .attr('class', 'rapid-feature-label-divider');
+
+ labelEnter
+ .append('div')
+ .attr('class', 'rapid-feature-description')
+ .text(d.description);
+ }
+
+ if (d.license_markdown) {
+ labelEnter
+ .append('div')
+ .attr('class', 'rapid-feature-label-divider');
+
+ labelEnter
+ .append('div')
+ .attr('class', 'rapid-feature-license')
+ .html(marked_1(d.license_markdown));
+
+ labelEnter.select('p a')
+ .attr('target', '_blank');
+ }
+
+ // line2: dataset extent
+ selection
+ .append('div')
+ .attr('class', 'rapid-feature-extent-container')
+ .each((d, i, nodes) => {
+ let selection = select(nodes[i]);
+
+ // if the data spans more than 100°*100°, it might as well be worldwide
+ if (d.extent && d.extent.area() < 10000) {
+ selection
+ .append('a')
+ .attr('href', '#')
+ .text(_t('rapid_feature_toggle.center_map'))
+ .on('click', () => {
+ event.preventDefault();
+ context.map().extent(d.extent);
+ });
+ } else {
+ selection
+ .text(_t('rapid_feature_toggle.worldwide'));
+ }
+ });
+ });
+
+ let inputsEnter = rowsEnter
+ .append('div')
+ .attr('class', 'rapid-checkbox-inputs');
+
+ inputsEnter
+ .append('label')
+ .attr('class', 'rapid-colorpicker-label');
+
+ let checkboxEnter = inputsEnter
+ .append('label')
+ .attr('class', 'rapid-checkbox-label');
+
+ checkboxEnter
+ .append('input')
+ .attr('type', 'checkbox')
+ .attr('class', 'rapid-feature-checkbox')
+ .on('click', toggleDataset);
+
+ checkboxEnter
+ .append('div')
+ .attr('class', 'rapid-checkbox-custom');
+
+
+ // update
+ rows = rows
+ .merge(rowsEnter)
+ .classed('disabled', !rapidLayer.showAll());
+
+ rows.selectAll('.rapid-colorpicker-label')
+ .attr('disabled', rapidLayer.showAll() ? null : true)
+ .call(_colorpicker);
+
+ rows.selectAll('.rapid-checkbox-label')
+ .classed('disabled', !rapidLayer.showAll());
+
+ rows.selectAll('.rapid-feature-checkbox')
+ .property('checked', datasetEnabled)
+ .attr('disabled', rapidLayer.showAll() ? null : true);
+ }
+ }
+
+ function uiRapidPowerUserFeaturesDialog(context) {
+ const featureFlags = ['previewDatasets', 'tagnosticRoadCombine', 'tagSources', 'showAutoFix'];
+ const rapidContext = context.rapidContext();
+ const showPowerUser = rapidContext.showPowerUser;
+ let _modalSelection = select(null);
+ let _content = select(null);
+
+ // if we are not currently showing poweruser features, move all the feature flags to a different keyspace
+ if (!showPowerUser) {
+ featureFlags.forEach(featureFlag => {
+ const val = corePreferences(`rapid-internal-feature.${featureFlag}`);
+ if (val) {
+ corePreferences(`rapid-internal-feature.was.${featureFlag}`, val);
+ corePreferences(`rapid-internal-feature.${featureFlag}`, null);
+ }
+ });
+ } else {
+ featureFlags.forEach(featureFlag => {
+ const val = corePreferences(`rapid-internal-feature.was.${featureFlag}`);
+ if (val) {
+ corePreferences(`rapid-internal-feature.${featureFlag}`, val);
+ corePreferences(`rapid-internal-feature.was.${featureFlag}`, null);
+ }
+ });
+ }
+
+
+ function isEnabled(featureFlag) {
+ return corePreferences(`rapid-internal-feature.${featureFlag}`) === 'true';
+ }
+
+ function toggleFeature(featureFlag) {
+ let enabled = corePreferences(`rapid-internal-feature.${featureFlag}`) === 'true';
+ enabled = !enabled;
+ corePreferences(`rapid-internal-feature.${featureFlag}`, enabled);
+
+ // custom on-toggle behaviors can go here
+ if (featureFlag === 'previewDatasets' && !enabled) { // user unchecked previewDatasets feature
+ const datasets = rapidContext.datasets();
+ Object.values(datasets).forEach(ds => {
+ if (ds.beta) {
+ ds.added = false;
+ ds.enabled = false;
+ }
+ });
+ context.enter(modeBrowse(context)); // return to browse mode (in case something was selected)
+ context.map().pan([0,0]); // trigger a map redraw
+ }
+ }
+
+
+ return (selection) => {
+ _modalSelection = uiModal(selection);
+
+ _modalSelection.select('.modal')
+ .attr('class', 'modal rapid-modal'); // RapiD styling
+
+ _content = _modalSelection.select('.content')
+ .append('div')
+ .attr('class', 'rapid-stack poweruser');
+
+ _content
+ .call(renderModalContent);
+
+ _content.selectAll('.ok-button')
+ .node()
+ .focus();
+ };
+
+
+ function renderModalContent(selection) {
+ /* Header */
+ let headerEnter = selection.selectAll('.modal-section-heading')
+ .data([0])
+ .enter()
+ .append('div')
+ .attr('class', 'modal-section-heading');
+
+ headerEnter
+ .append('h3')
+ .attr('class', 'modal-heading')
+ .html(_t('rapid_poweruser_features.heading.label'));
+
+ headerEnter
+ .append('div')
+ .attr('class', 'modal-heading-desc')
+ .text(_t('rapid_poweruser_features.heading.description'))
+ .append('span')
+ .attr('class', 'smile')
+ .text('😎');
+
+
+ /* Features */
+ let features = selection.selectAll('.rapid-features-container')
+ .data([0]);
+
+ let featuresEnter = features.enter()
+ .append('div')
+ .attr('class', 'rapid-features-container');
+
+ features
+ .merge(featuresEnter)
+ .call(renderFeatures);
+
+
+ /* OK Button */
+ let buttonsEnter = selection.selectAll('.modal-section.buttons')
+ .data([0])
+ .enter()
+ .append('div')
+ .attr('class', 'modal-section buttons');
+
+ buttonsEnter
+ .append('button')
+ .attr('class', 'button ok-button action')
+ .on('click', () => _modalSelection.remove())
+ .text(_t('confirm.okay'));
+ }
+
+
+ function renderFeatures(selection) {
+ let rows = selection.selectAll('.rapid-checkbox-feature')
+ .data(featureFlags, d => d);
+
+ // enter
+ let rowsEnter = rows.enter()
+ .append('div')
+ .attr('class', 'modal-section rapid-checkbox rapid-checkbox-feature');
+
+ rowsEnter
+ .append('div')
+ .attr('class', 'rapid-feature')
+ .each((d, i, nodes) => {
+ let selection = select(nodes[i]);
+
+ // line1: Label
+ selection
+ .append('div')
+ .attr('class', 'rapid-feature-label')
+ .text(d => _t(`rapid_poweruser_features.${d}.label`));
+
+ // line2: description
+ selection
+ .append('div')
+ .attr('class', 'rapid-feature-description')
+ .text(d => _t(`rapid_poweruser_features.${d}.description`));
+ });
+
+ let inputsEnter = rowsEnter
+ .append('div')
+ .attr('class', 'rapid-checkbox-inputs');
+
+ let checkboxEnter = inputsEnter
+ .append('label')
+ .attr('class', 'rapid-checkbox-label');
+
+ checkboxEnter
+ .append('input')
+ .attr('type', 'checkbox')
+ .attr('class', 'rapid-feature-checkbox')
+ .on('click', toggleFeature);
+
+ checkboxEnter
+ .append('div')
+ .attr('class', 'rapid-checkbox-custom');
+
+
+ // update
+ rows = rows
+ .merge(rowsEnter);
+
+ rows.selectAll('.rapid-feature-checkbox')
+ .property('checked', isEnabled);
+ }
+
+ }
+
+ function uiToolRapidFeatures(context) {
+ const toggleKeyDispatcher = dispatch('ai_feature_toggle');
+ const rapidFeaturesToggleKey = uiCmd('⇧' + _t('map_data.layers.ai-features.key'));
+ const datasetDialog = uiRapidFeatureToggleDialog(context, rapidFeaturesToggleKey, toggleKeyDispatcher);
+ const powerUserDialog = uiRapidPowerUserFeaturesDialog(context);
+ const showPowerUser = context.rapidContext().showPowerUser;
+
+ let tool = {
+ id: 'rapid_features',
+ label: _t('toolbar.rapid_features')
+ };
+
+ context.keybinding()
+ .on(rapidFeaturesToggleKey, () => {
+ event.preventDefault();
+ event.stopPropagation();
+ toggleFeatures();
+ });
+
+
+ function layerEnabled() {
+ return context.layers().layer('ai-features').enabled();
+ }
+
+
+ function toggleFeatures() {
+ let layer = context.layers().layer('ai-features');
+ layer.enabled(!layer.enabled());
+ toggleKeyDispatcher.call('ai_feature_toggle');
+ }
+
+
+ function showFeatureToggleDialog(d, i, nodes) {
+ select(nodes[i]).node().blur();
+ context.container().call(datasetDialog);
+ }
+
+ function showPowerUserFeaturesDialog(d, i, nodes) {
+ select(nodes[i]).node().blur();
+ context.container().call(powerUserDialog);
+ }
+
+
+ tool.render = (selection) => {
+ const debouncedUpdate = debounce(update, 100, { leading: true, trailing: true });
+ let wrap = selection
+ .append('div')
+ .attr('class', showPowerUser ? 'joined' : null)
+ .style('display', 'flex');
+
+ context.map()
+ .on('move.rapid_features', debouncedUpdate)
+ .on('drawn.rapid_features', debouncedUpdate);
+
+ context
+ .on('enter.rapid_features', update);
+
+ update();
+
+
+ function update() {
+ let rapidButton = wrap.selectAll('.rapid-features')
+ .data([0]);
+
+ // enter
+ let rapidButtonEnter = rapidButton.enter()
+ .append('button')
+ .attr('class', 'bar-button rapid-features')
+ .attr('tabindex', -1)
+ .on('click', showFeatureToggleDialog)
+ .call(uiTooltip()
+ .placement('bottom')
+ .title(_t('shortcuts.browsing.display_options.rapid_features_data'))
+ .keys(rapidFeaturesToggleKey)
+ );
+
+ rapidButtonEnter
+ .append('svg')
+ .attr('class', 'logo-rapid')
+ .append('use')
+ .attr('xlink:href', '#iD-logo-rapid');
+
+ // update
+ rapidButton.merge(rapidButtonEnter)
+ .classed('layer-off', !layerEnabled());
+
+
+ let powerUserButton = wrap.selectAll('.rapid-poweruser-features')
+ .data(showPowerUser ? [0] : []);
+
+ powerUserButton.enter()
+ .append('button')
+ .attr('class', 'bar-button rapid-poweruser-features')
+ .attr('tabindex', -1)
+ .on('click', showPowerUserFeaturesDialog)
+ .call(uiTooltip()
+ .placement('bottom')
+ .title(_t('rapid_poweruser_features.heading.label'))
+ )
+ .append('div')
+ .attr('class', 'beta');
+ }
+ };
+
+ return tool;
+ }
+
+ function uiTopToolbar(context) {
+
+ var sidebarToggle = uiToolSidebarToggle(context),
+ rapidFeatures = uiToolRapidFeatures(context),
+ modes = uiToolOldDrawModes(context),
+ notes = uiToolNotes(context),
+ undoRedo = uiToolUndoRedo(context),
+ save = uiToolSave(context),
+ downloadOsc = uiToolDownloadOsc(context);
+
+ function notesEnabled() {
+ var noteLayer = context.layers().layer('notes');
+ return noteLayer && noteLayer.enabled();
+ }
+
+ function topToolbar(bar) {
+
+ bar.on('wheel.topToolbar', function() {
+ if (!event.deltaX) {
+ // translate vertical scrolling into horizontal scrolling in case
+ // the user doesn't have an input device that can scroll horizontally
+ bar.node().scrollLeft += event.deltaY;
+ }
+ });
+
+ var debouncedUpdate = debounce(update, 500, { leading: true, trailing: true });
+ context.layers()
+ .on('change.topToolbar', debouncedUpdate);
+
+ update();
+
+ function update() {
+
+ var tools = [
+ sidebarToggle,
+ 'spacer',
+ modes,
+ rapidFeatures
+ // searchAdd
+ ];
+
+ tools.push('spacer');
+
+ if (notesEnabled()) {
+ tools = tools.concat([notes, 'spacer']);
+ }
+
+ var q = utilStringQs(window.location.hash.substring(1));
+ if (q.support_download_osc === 'true') {
+ tools.push(downloadOsc);
+ }
+ tools = tools.concat([undoRedo, save]);
+
+ var toolbarItems = bar.selectAll('.toolbar-item')
+ .data(tools, function(d) {
+ return d.id || d;
+ });
+
+ toolbarItems.exit()
+ .each(function(d) {
+ if (d.uninstall) {
+ d.uninstall();
+ }
+ })
+ .remove();
+
+ var itemsEnter = toolbarItems
+ .enter()
+ .append('div')
+ .attr('class', function(d) {
+ var classes = 'toolbar-item ' + (d.id || d).replace('_', '-');
+ if (d.klass) classes += ' ' + d.klass;
+ return classes;
+ });
+
+ var actionableItems = itemsEnter.filter(function(d) { return d !== 'spacer'; });
+
+ actionableItems
+ .append('div')
+ .attr('class', 'item-content')
+ .each(function(d) {
+ select(this).call(d.render, bar);
+ });
+
+ actionableItems
+ .append('div')
+ .attr('class', 'item-label')
+ .text(function(d) {
+ return d.label;
+ });
+ }
+
+ }
+
+ return topToolbar;
+ }
+
+ // these are module variables so they are preserved through a ui.restart()
+ var sawVersion = null;
+ var isNewVersion = false;
+ var isNewUser = false;
+
+
+ function uiVersion(context) {
+
+ var currVersion = context.rapidContext().version;
+ var matchedVersion = currVersion.match(/\d+\.\d+\.\d+.*/);
+
+ if (sawVersion === null && matchedVersion !== null) {
+ if (corePreferences('sawVersion')) {
+ isNewUser = false;
+ isNewVersion = corePreferences('sawVersion') !== currVersion && currVersion.indexOf('-') === -1;
+ } else {
+ isNewUser = true;
+ isNewVersion = true;
+ }
+ corePreferences('sawVersion', currVersion);
+ sawVersion = currVersion;
+ }
+
+ return function(selection) {
+ selection
+ .append('a')
+ .attr('target', '_blank')
+ .attr('tabindex', -1)
+ .attr('href', 'https://github.com/facebookincubator/RapiD')
+ .text(currVersion);
+
+ // only show new version indicator to users that have used iD before
+ if (isNewVersion && !isNewUser) {
+ selection
+ .append('div')
+ .attr('class', 'badge')
+ .append('a')
+ .attr('target', '_blank')
+ .attr('tabindex', -1)
+ .attr('href', 'https://github.com/facebookincubator/RapiD/blob/master/CHANGELOG.md')
+ .call(svgIcon('#maki-gift-11'))
+ .call(uiTooltip()
+ .title(_t('version.whats_new', { version: currVersion }))
+ .placement('top')
+ );
+ }
+ };
+ }
+
+ function uiZoom(context) {
+
+ var zooms = [{
+ id: 'zoom-in',
+ icon: 'iD-icon-plus',
+ title: _t('zoom.in'),
+ action: zoomIn,
+ disabled: function() {
+ return !context.map().canZoomIn();
+ },
+ disabledTitle: _t('zoom.disabled.in'),
+ key: '+'
+ }, {
+ id: 'zoom-out',
+ icon: 'iD-icon-minus',
+ title: _t('zoom.out'),
+ action: zoomOut,
+ disabled: function() {
+ return !context.map().canZoomOut();
+ },
+ disabledTitle: _t('zoom.disabled.out'),
+ key: '-'
+ }];
+
+ function zoomIn() {
+ event.preventDefault();
+ context.map().zoomIn();
+ }
+
+ function zoomOut() {
+ event.preventDefault();
+ context.map().zoomOut();
+ }
+
+ function zoomInFurther() {
+ event.preventDefault();
+ context.map().zoomInFurther();
+ }
+
+ function zoomOutFurther() {
+ event.preventDefault();
+ context.map().zoomOutFurther();
+ }
+
+ return function(selection) {
+ var tooltipBehavior = uiTooltip()
+ .placement((_mainLocalizer.textDirection() === 'rtl') ? 'right' : 'left')
+ .title(function(d) {
+ if (d.disabled()) {
+ return d.disabledTitle;
+ }
+ return d.title;
+ })
+ .keys(function(d) {
+ return [d.key];
+ });
+
+ var lastPointerUpType;
+
+ var buttons = selection.selectAll('button')
+ .data(zooms)
+ .enter()
+ .append('button')
+ .attr('class', function(d) { return d.id; })
+ .on('pointerup.editor', function() {
+ lastPointerUpType = event.pointerType;
+ })
+ .on('click.editor', function(d) {
+ if (!d.disabled()) {
+ d.action();
+ } else if (lastPointerUpType === 'touch' || lastPointerUpType === 'pen') {
+ context.ui().flash
+ .duration(2000)
+ .iconName('#' + d.icon)
+ .iconClass('disabled')
+ .text(d.disabledTitle)();
+ }
+ lastPointerUpType = null;
+ })
+ .call(tooltipBehavior);
+
+ buttons.each(function(d) {
+ select(this)
+ .call(svgIcon('#' + d.icon, 'light'));
+ });
+
+ ['plus', 'ffplus', '=', 'ffequals'].forEach(function(key) {
+ context.keybinding().on([key], zoomIn);
+ context.keybinding().on([uiCmd('⌘' + key)], zoomInFurther);
+ });
+
+ ['_', '-', 'ffminus', 'dash'].forEach(function(key) {
+ context.keybinding().on([key], zoomOut);
+ context.keybinding().on([uiCmd('⌘' + key)], zoomOutFurther);
+ });
+
+ function updateButtonStates() {
+ buttons
+ .classed('disabled', function(d) {
+ return d.disabled();
+ })
+ .each(function() {
+ var selection = select(this);
+ if (!selection.select('.tooltip.in').empty()) {
+ selection.call(tooltipBehavior.updateContent);
+ }
+ });
+ }
+
+ updateButtonStates();
+
+ context.map().on('move.uiZoom', updateButtonStates);
+ };
+ }
+
+ function uiZoomToSelection(context) {
+
+ function isDisabled() {
+ var mode = context.mode();
+ return !mode || !mode.zoomToSelected;
+ }
+
+ var _lastPointerUpType;
+
+ function pointerup() {
+ _lastPointerUpType = event.pointerType;
+ }
+
+ function click() {
+ event.preventDefault();
+
+ if (isDisabled()) {
+ if (_lastPointerUpType === 'touch' || _lastPointerUpType === 'pen') {
+ context.ui().flash
+ .duration(2000)
+ .iconName('#iD-icon-framed-dot')
+ .iconClass('disabled')
+ .text(_t('inspector.zoom_to.no_selection'))();
+ }
+ } else {
+ var mode = context.mode();
+ if (mode && mode.zoomToSelected) {
+ mode.zoomToSelected();
+ }
+ }
+
+ _lastPointerUpType = null;
+ }
+
+ return function(selection) {
+
+ var tooltipBehavior = uiTooltip()
+ .placement((_mainLocalizer.textDirection() === 'rtl') ? 'right' : 'left')
+ .title(function() {
+ if (isDisabled()) {
+ return _t('inspector.zoom_to.no_selection');
+ }
+ return _t('inspector.zoom_to.title');
+ })
+ .keys([_t('inspector.zoom_to.key')]);
+
+ var button = selection
+ .append('button')
+ .on('pointerup', pointerup)
+ .on('click', click)
+ .call(svgIcon('#iD-icon-framed-dot', 'light'))
+ .call(tooltipBehavior);
+
+ function setEnabledState() {
+ button.classed('disabled', isDisabled());
+ if (!button.select('.tooltip.in').empty()) {
+ button.call(tooltipBehavior.updateContent);
+ }
+ }
+
+ context.on('enter.uiZoomToSelection', setEnabledState);
+
+ setEnabledState();
+ };
+ }
+
+ function uiPane(id, context) {
+
+ var _key;
+ var _title = '';
+ var _description = '';
+ var _iconName = '';
+ var _sections; // array of uiSection objects
+
+ var _paneSelection = select(null);
+
+ var _paneTooltip;
+
+ var pane = {
+ id: id
+ };
+
+ pane.title = function(val) {
+ if (!arguments.length) return _title;
+ _title = val;
+ return pane;
+ };
+
+ pane.key = function(val) {
+ if (!arguments.length) return _key;
+ _key = val;
+ return pane;
+ };
+
+ pane.description = function(val) {
+ if (!arguments.length) return _description;
+ _description = val;
+ return pane;
+ };
+
+ pane.iconName = function(val) {
+ if (!arguments.length) return _iconName;
+ _iconName = val;
+ return pane;
+ };
+
+ pane.sections = function(val) {
+ if (!arguments.length) return _sections;
+ _sections = val;
+ return pane;
+ };
+
+ pane.selection = function() {
+ return _paneSelection;
+ };
+
+ function hidePane() {
+ context.ui().togglePanes();
+ }
+
+ pane.togglePane = function() {
+ if (event) event.preventDefault();
+ _paneTooltip.hide();
+ context.ui().togglePanes(!_paneSelection.classed('shown') ? _paneSelection : undefined);
+ };
+
+ pane.renderToggleButton = function(selection) {
+
+ if (!_paneTooltip) {
+ _paneTooltip = uiTooltip()
+ .placement((_mainLocalizer.textDirection() === 'rtl') ? 'right' : 'left')
+ .title(_description)
+ .keys([_key]);
+ }
+
+ selection
+ .append('button')
+ .on('click', pane.togglePane)
+ .call(svgIcon('#' + _iconName, 'light'))
+ .call(_paneTooltip);
+ };
+
+ pane.renderContent = function(selection) {
+ // override to fully customize content
+
+ if (_sections) {
+ _sections.forEach(function(section) {
+ selection.call(section.render);
+ });
+ }
+ };
+
+ pane.renderPane = function(selection) {
+
+ _paneSelection = selection
+ .append('div')
+ .attr('class', 'fillL map-pane hide ' + id + '-pane')
+ .attr('pane', id);
+
+ var heading = _paneSelection
+ .append('div')
+ .attr('class', 'pane-heading');
+
+ heading
+ .append('h2')
+ .text(_title);
+
+ heading
+ .append('button')
+ .on('click', hidePane)
+ .call(svgIcon('#iD-icon-close'));
+
+
+ _paneSelection
+ .append('div')
+ .attr('class', 'pane-content')
+ .call(pane.renderContent);
+
+ if (_key) {
+ context.keybinding()
+ .on(_key, pane.togglePane);
+ }
+ };
+
+ return pane;
+ }
+
+ function uiSectionBackgroundDisplayOptions(context) {
+
+ var section = uiSection('background-display-options', context)
+ .title(_t('background.display_options'))
+ .disclosureContent(renderDisclosureContent);
+
+ var _detected = utilDetect();
+ var _storedOpacity = corePreferences('background-opacity');
+ var _minVal = 0.25;
+ var _maxVal = _detected.cssfilters ? 2 : 1;
+
+ var _sliders = _detected.cssfilters
+ ? ['brightness', 'contrast', 'saturation', 'sharpness']
+ : ['brightness'];
+
+ var _options = {
+ brightness: (_storedOpacity !== null ? (+_storedOpacity) : 1),
+ contrast: 1,
+ saturation: 1,
+ sharpness: 1
+ };
+
+ function clamp(x, min, max) {
+ return Math.max(min, Math.min(x, max));
+ }
+
+ function updateValue(d, val) {
+ if (!val && event && event.target) {
+ val = event.target.value;
+ }
+
+ val = clamp(val, _minVal, _maxVal);
+
+ _options[d] = val;
+ context.background()[d](val);
+
+ if (d === 'brightness') {
+ corePreferences('background-opacity', val);
+ }
+
+ section.reRender();
+ }
+
+ function renderDisclosureContent(selection) {
+ var container = selection.selectAll('.display-options-container')
+ .data([0]);
+
+ var containerEnter = container.enter()
+ .append('div')
+ .attr('class', 'display-options-container controls-list');
+
+ // add slider controls
+ var slidersEnter = containerEnter.selectAll('.display-control')
+ .data(_sliders)
+ .enter()
+ .append('div')
+ .attr('class', function(d) { return 'display-control display-control-' + d; });
+
+ slidersEnter
+ .append('h5')
+ .text(function(d) { return _t('background.' + d); })
+ .append('span')
+ .attr('class', function(d) { return 'display-option-value display-option-value-' + d; });
+
+ slidersEnter
+ .append('input')
+ .attr('class', function(d) { return 'display-option-input display-option-input-' + d; })
+ .attr('type', 'range')
+ .attr('min', _minVal)
+ .attr('max', _maxVal)
+ .attr('step', '0.05')
+ .on('input', function(d) {
+ var val = select(this).property('value');
+ updateValue(d, val);
+ });
+
+ slidersEnter
+ .append('button')
+ .attr('title', _t('background.reset'))
+ .attr('class', function(d) { return 'display-option-reset display-option-reset-' + d; })
+ .on('click', function(d) {
+ if (event.button !== 0) return;
+ updateValue(d, 1);
+ })
+ .call(svgIcon('#iD-icon-' + (_mainLocalizer.textDirection() === 'rtl' ? 'redo' : 'undo')));
+
+ // reset all button
+ containerEnter
+ .append('a')
+ .attr('class', 'display-option-resetlink')
+ .attr('href', '#')
+ .text(_t('background.reset_all'))
+ .on('click', function() {
+ for (var i = 0; i < _sliders.length; i++) {
+ updateValue(_sliders[i],1);
+ }
+ });
+
+ // update
+ container = containerEnter
+ .merge(container);
+
+ container.selectAll('.display-option-input')
+ .property('value', function(d) { return _options[d]; });
+
+ container.selectAll('.display-option-value')
+ .text(function(d) { return Math.floor(_options[d] * 100) + '%'; });
+
+ container.selectAll('.display-option-reset')
+ .classed('disabled', function(d) { return _options[d] === 1; });
+
+ // first time only, set brightness if needed
+ if (containerEnter.size() && _options.brightness !== 1) {
+ context.background().brightness(_options.brightness);
+ }
+ }
+
+ return section;
+ }
+
+ function uiSettingsCustomBackground() {
+ var dispatch$1 = dispatch('change');
+
+ function render(selection) {
+ // keep separate copies of original and current settings
+ var _origSettings = {
+ template: corePreferences('background-custom-template')
+ };
+ var _currSettings = {
+ template: corePreferences('background-custom-template')
+ };
+
+ var example = 'https://{switch:a,b,c}.tile.openstreetmap.org/{zoom}/{x}/{y}.png';
+ var modal = uiConfirm(selection).okButton();
+
+ modal
+ .classed('settings-modal settings-custom-background', true);
+
+ modal.select('.modal-section.header')
+ .append('h3')
+ .text(_t('settings.custom_background.header'));
+
+
+ var textSection = modal.select('.modal-section.message-text');
+
+ var instructions =
+ `${_t('settings.custom_background.instructions.info')}\n` +
+ '\n' +
+ `#### ${_t('settings.custom_background.instructions.wms.tokens_label')}\n` +
+ `* ${_t('settings.custom_background.instructions.wms.tokens.proj')}\n` +
+ `* ${_t('settings.custom_background.instructions.wms.tokens.wkid')}\n` +
+ `* ${_t('settings.custom_background.instructions.wms.tokens.dimensions')}\n` +
+ `* ${_t('settings.custom_background.instructions.wms.tokens.bbox')}\n` +
+ '\n' +
+ `#### ${_t('settings.custom_background.instructions.tms.tokens_label')}\n` +
+ `* ${_t('settings.custom_background.instructions.tms.tokens.xyz')}\n` +
+ `* ${_t('settings.custom_background.instructions.tms.tokens.flipped_y')}\n` +
+ `* ${_t('settings.custom_background.instructions.tms.tokens.switch')}\n` +
+ `* ${_t('settings.custom_background.instructions.tms.tokens.quadtile')}\n` +
+ `* ${_t('settings.custom_background.instructions.tms.tokens.scale_factor')}\n` +
+ '\n' +
+ `#### ${_t('settings.custom_background.instructions.example')}\n` +
+ `\`${example}\``;
+
+ textSection
+ .append('div')
+ .attr('class', 'instructions-template')
+ .html(marked_1(instructions));
+
+ textSection
+ .append('textarea')
+ .attr('class', 'field-template')
+ .attr('placeholder', _t('settings.custom_background.template.placeholder'))
+ .call(utilNoAuto)
+ .property('value', _currSettings.template);
+
+
+ // insert a cancel button
+ var buttonSection = modal.select('.modal-section.buttons');
+
+ buttonSection
+ .insert('button', '.ok-button')
+ .attr('class', 'button cancel-button secondary-action')
+ .text(_t('confirm.cancel'));
+
+
+ buttonSection.select('.cancel-button')
+ .on('click.cancel', clickCancel);
+
+ buttonSection.select('.ok-button')
+ .attr('disabled', isSaveDisabled)
+ .on('click.save', clickSave);
+
+
+ function isSaveDisabled() {
+ return null;
+ }
+
+
+ // restore the original template
+ function clickCancel() {
+ textSection.select('.field-template').property('value', _origSettings.template);
+ corePreferences('background-custom-template', _origSettings.template);
+ this.blur();
+ modal.close();
+ }
+
+ // accept the current template
+ function clickSave() {
+ _currSettings.template = textSection.select('.field-template').property('value');
+ corePreferences('background-custom-template', _currSettings.template);
+ this.blur();
+ modal.close();
+ dispatch$1.call('change', this, _currSettings);
+ }
+ }
+
+ return utilRebind(render, dispatch$1, 'on');
+ }
+
+ function uiSectionBackgroundList(context) {
+
+ let _backgroundList = select(null);
+
+ const _customSource = context.background().findSource('custom');
+
+ const _settingsCustomBackground = uiSettingsCustomBackground()
+ .on('change', customChanged);
+
+ const section = uiSection('background-list', context)
+ .title(_t('background.backgrounds'))
+ .disclosureContent(renderDisclosureContent);
+
+ const favoriteBackgroundsJSON = corePreferences('background-favorites');
+ const _favoriteBackgrounds = favoriteBackgroundsJSON ? JSON.parse(favoriteBackgroundsJSON) : {};
+
+ function previousBackgroundID() {
+ return corePreferences('background-last-used-toggle');
+ }
+
+ function renderDisclosureContent(selection) {
+
+ // the background list
+ const container = selection.selectAll('.layer-background-list')
+ .data([0]);
+
+ _backgroundList = container.enter()
+ .append('ul')
+ .attr('class', 'layer-list layer-background-list')
+ .attr('dir', 'auto')
+ .merge(container);
+
+
+ // add minimap toggle below list
+ const bgExtrasListEnter = selection.selectAll('.bg-extras-list')
+ .data([0])
+ .enter()
+ .append('ul')
+ .attr('class', 'layer-list bg-extras-list');
+
+ const minimapLabelEnter = bgExtrasListEnter
+ .append('li')
+ .attr('class', 'minimap-toggle-item')
+ .append('label')
+ .call(uiTooltip()
+ .title(_t('background.minimap.tooltip'))
+ .keys([_t('background.minimap.key')])
+ .placement('top')
+ );
+
+ minimapLabelEnter
+ .append('input')
+ .attr('type', 'checkbox')
+ .on('change', () => {
+ event.preventDefault();
+ uiMapInMap.toggle();
+ });
+
+ minimapLabelEnter
+ .append('span')
+ .text(_t('background.minimap.description'));
+
+
+ const panelLabelEnter = bgExtrasListEnter
+ .append('li')
+ .attr('class', 'background-panel-toggle-item')
+ .append('label')
+ .call(uiTooltip()
+ .title(_t('background.panel.tooltip'))
+ .keys([uiCmd('⌘⇧' + _t('info_panels.background.key'))])
+ .placement('top')
+ );
+
+ panelLabelEnter
+ .append('input')
+ .attr('type', 'checkbox')
+ .on('change', () => {
+ event.preventDefault();
+ context.ui().info.toggle('background');
+ });
+
+ panelLabelEnter
+ .append('span')
+ .text(_t('background.panel.description'));
+
+ const locPanelLabelEnter = bgExtrasListEnter
+ .append('li')
+ .attr('class', 'location-panel-toggle-item')
+ .append('label')
+ .call(uiTooltip()
+ .title(_t('background.location_panel.tooltip'))
+ .keys([uiCmd('⌘⇧' + _t('info_panels.location.key'))])
+ .placement('top')
+ );
+
+ locPanelLabelEnter
+ .append('input')
+ .attr('type', 'checkbox')
+ .on('change', () => {
+ event.preventDefault();
+ context.ui().info.toggle('location');
+ });
+
+ locPanelLabelEnter
+ .append('span')
+ .text(_t('background.location_panel.description'));
+
+
+ // "Info / Report a Problem" link
+ selection.selectAll('.imagery-faq')
+ .data([0])
+ .enter()
+ .append('div')
+ .attr('class', 'imagery-faq')
+ .append('a')
+ .attr('target', '_blank')
+ .call(svgIcon('#iD-icon-out-link', 'inline'))
+ .attr('href', 'https://github.com/openstreetmap/iD/blob/develop/FAQ.md#how-can-i-report-an-issue-with-background-imagery')
+ .append('span')
+ .text(_t('background.imagery_problem_faq'));
+
+ _backgroundList
+ .call(drawListItems, 'radio', chooseBackground, (d) => { return !d.isHidden() && !d.overlay; });
+ }
+
+ function setTooltips(selection) {
+ selection.each((d, i, nodes) => {
+ const item = select(nodes[i]).select('label');
+ const span = item.select('span');
+ const placement = (i < nodes.length / 2) ? 'bottom' : 'top';
+ const description = d.description();
+ const isOverflowing = (span.property('clientWidth') !== span.property('scrollWidth'));
+
+ item.call(uiTooltip().destroyAny);
+
+ if (d.id === previousBackgroundID()) {
+ item.call(uiTooltip()
+ .placement(placement)
+ .title('' + _t('background.switch') + '
')
+ .keys([uiCmd('⌘' + _t('background.key'))])
+ );
+ } else if (description || isOverflowing) {
+ item.call(uiTooltip()
+ .placement(placement)
+ .title(description || d.name())
+ );
+ }
+ });
+ }
+
+ function sortSources(a, b) {
+ return _favoriteBackgrounds[a.id] && !_favoriteBackgrounds[b.id] ? -1
+ : _favoriteBackgrounds[b.id] && !_favoriteBackgrounds[a.id] ? 1
+ : a.best() && !b.best() ? -1 : b.best() && !a.best() ? 1
+ : d3_descending(a.area(), b.area()) || d3_ascending(a.name(), b.name()) || 0;
+ }
+
+ function drawListItems(layerList, type, change, filter) {
+ const sources = context.background()
+ .sources(context.map().extent(), context.map().zoom(), true)
+ .filter(filter);
+
+ const layerLinks = layerList.selectAll('li')
+ .data(sources, (d) => { return d.id; });
+
+ layerLinks.exit()
+ .remove();
+
+ const layerLinksEnter = layerLinks.enter()
+ .append('li')
+ .classed('layer-custom', (d) => { return d.id === 'custom'; })
+ .classed('best', (d) =>{ return d.best(); });
+
+ const label = layerLinksEnter
+ .append('label');
+
+ label
+ .append('input')
+ .attr('type', type)
+ .attr('name', 'layers')
+ .on('change', change);
+
+ label
+ .append('span')
+ .attr('class', 'background-name')
+ .text((d) => { return d.name(); });
+
+ layerLinksEnter
+ .append('button')
+ .attr('class', 'background-favorite-button')
+ .classed('active', (d) => { return !!_favoriteBackgrounds[d.id]; })
+ .attr('tabindex', -1)
+ .call(svgIcon('#iD-icon-favorite'))
+ .on('click', (d, i, nodes) => {
+ if (_favoriteBackgrounds[d.id]) {
+ select(nodes[i]).classed('active', false);
+ delete _favoriteBackgrounds[d.id];
+ } else {
+ select(nodes[i]).classed('active', true);
+ _favoriteBackgrounds[d.id] = true;
+ }
+ corePreferences('background-favorites', JSON.stringify(_favoriteBackgrounds));
+
+ select(nodes[i].parentElement)
+ .transition()
+ .duration(300)
+ .ease(cubicInOut)
+ .style('background-color', 'orange')
+ .transition()
+ .duration(300)
+ .ease(cubicInOut)
+ .style('background-color', null);
+
+ layerList.selectAll('li')
+ .sort(sortSources);
+ layerList
+ .call(updateLayerSelections);
+ nodes[i].blur(); // Stop old de-stars from having grey background
+ });
+
+ layerLinksEnter.filter((d) => { return d.id === 'custom'; })
+ .append('button')
+ .attr('class', 'layer-browse')
+ .call(uiTooltip()
+ .title(_t('settings.custom_background.tooltip'))
+ .placement((_mainLocalizer.textDirection() === 'rtl') ? 'right' : 'left')
+ )
+ .on('click', editCustom)
+ .call(svgIcon('#iD-icon-more'));
+
+ layerLinksEnter.filter((d) => { return d.best(); })
+ .selectAll('label')
+ .append('span')
+ .attr('class', 'best')
+ .call(uiTooltip()
+ .title(_t('background.best_imagery'))
+ .placement('bottom')
+ )
+ .call(svgIcon('#iD-icon-best-background'));
+
+ layerList.selectAll('li')
+ .sort(sortSources);
+
+ layerList
+ .call(updateLayerSelections);
+
+ }
+
+ function updateLayerSelections(selection) {
+ function active(d) {
+ return context.background().showsLayer(d);
+ }
+
+ selection.selectAll('li')
+ .classed('active', active)
+ .classed('switch', (d) => { return d.id === previousBackgroundID(); })
+ .call(setTooltips)
+ .selectAll('input')
+ .property('checked', active);
+ }
+
+
+ function chooseBackground(d) {
+ if (d.id === 'custom' && !d.template()) {
+ return editCustom();
+ }
+
+ event.preventDefault();
+ const previousBackground = context.background().baseLayerSource();
+ corePreferences('background-last-used-toggle', previousBackground.id);
+ corePreferences('background-last-used', d.id);
+ context.background().baseLayerSource(d);
+ document.activeElement.blur();
+ }
+
+
+ function customChanged(d) {
+ if (d && d.template) {
+ _customSource.template(d.template);
+ chooseBackground(_customSource);
+ } else {
+ _customSource.template('');
+ chooseBackground(context.background().findSource('none'));
+ }
+ }
+
+
+ function editCustom() {
+ event.preventDefault();
+ context.container()
+ .call(_settingsCustomBackground);
+ }
+
+
+ context.background()
+ .on('change.background_list', () => {
+ _backgroundList.call(updateLayerSelections);
+ });
+
+ context.map()
+ .on('move.background_list',
+ debounce(() => {
+ // layers in-view may have changed due to map move
+ window.requestIdleCallback(section.reRender);
+ }, 1000)
+ );
+
+ function getBackgrounds(filter) {
+ return context.background()
+ .sources(context.map().extent(), context.map().zoom(), true)
+ .filter(filter);
+ }
+
+ function chooseBackgroundAtOffset(offset) {
+ const backgrounds = getBackgrounds((d) => { return !d.isHidden() && !d.overlay; });
+ backgrounds.sort(sortSources);
+ const currentBackground = context.background().baseLayerSource();
+ const foundIndex = backgrounds.indexOf(currentBackground);
+ if (foundIndex === -1) {
+ // Can't find the current background, so just do nothing
+ return;
+ }
+
+ let nextBackgroundIndex = (foundIndex + offset + backgrounds.length) % backgrounds.length;
+ let nextBackground = backgrounds[nextBackgroundIndex];
+ if (nextBackground.id === 'custom' && !nextBackground.template()) {
+ nextBackgroundIndex = (nextBackgroundIndex + offset + backgrounds.length) % backgrounds.length;
+ nextBackground = backgrounds[nextBackgroundIndex];
+ }
+ chooseBackground(nextBackground);
+ }
+
+ function nextBackground() {
+ chooseBackgroundAtOffset(1);
+ }
+
+ function previousBackground() {
+ chooseBackgroundAtOffset(-1);
+ }
+
+ context.keybinding()
+ .on(_t('background.next_background.key'), nextBackground)
+ .on(_t('background.previous_background.key'), previousBackground);
+
+ return section;
+ }
+
+ function uiSectionBackgroundOffset(context) {
+
+ var section = uiSection('background-offset', context)
+ .title(_t('background.fix_misalignment'))
+ .disclosureContent(renderDisclosureContent)
+ .expandedByDefault(false);
+
+ var _pointerPrefix = 'PointerEvent' in window ? 'pointer' : 'mouse';
+
+ var _directions = [
+ ['right', [0.5, 0]],
+ ['top', [0, -0.5]],
+ ['left', [-0.5, 0]],
+ ['bottom', [0, 0.5]]
+ ];
+
+
+ function cancelEvent() {
+ event.stopPropagation();
+ event.preventDefault();
+ }
+
+
+ function updateValue() {
+ var meters = geoOffsetToMeters(context.background().offset());
+ var x = +meters[0].toFixed(2);
+ var y = +meters[1].toFixed(2);
+
+ context.container().selectAll('.nudge-inner-rect')
+ .select('input')
+ .classed('error', false)
+ .property('value', x + ', ' + y);
+
+ context.container().selectAll('.nudge-reset')
+ .classed('disabled', function() {
+ return (x === 0 && y === 0);
+ });
+ }
+
+
+ function resetOffset() {
+ context.background().offset([0, 0]);
+ updateValue();
+ }
+
+
+ function nudge(d) {
+ context.background().nudge(d, context.map().zoom());
+ updateValue();
+ }
+
+
+ function pointerdownNudgeButton(d) {
+ var interval;
+ var timeout = window.setTimeout(function() {
+ interval = window.setInterval(nudge.bind(null, d), 100);
+ }, 500);
+
+ function doneNudge() {
+ window.clearTimeout(timeout);
+ window.clearInterval(interval);
+ select(window)
+ .on(_pointerPrefix + 'up.buttonoffset', null, true)
+ .on(_pointerPrefix + 'down.buttonoffset', null, true);
+ }
+
+ select(window)
+ .on(_pointerPrefix + 'up.buttonoffset', doneNudge, true)
+ .on(_pointerPrefix + 'down.buttonoffset', doneNudge, true);
+
+ nudge(d);
+ }
+
+
+ function inputOffset() {
+ var input = select(this);
+ var d = input.node().value;
+
+ if (d === '') return resetOffset();
+
+ d = d.replace(/;/g, ',').split(',').map(function(n) {
+ // if n is NaN, it will always get mapped to false.
+ return !isNaN(n) && n;
+ });
+
+ if (d.length !== 2 || !d[0] || !d[1]) {
+ input.classed('error', true);
+ return;
+ }
+
+ context.background().offset(geoMetersToOffset(d));
+ updateValue();
+ }
+
+
+ function dragOffset() {
+ if (event.button !== 0) return;
+
+ var origin = [event.clientX, event.clientY];
+
+ var pointerId = event.pointerId || 'mouse';
+
+ context.container()
+ .append('div')
+ .attr('class', 'nudge-surface');
+
+ select(window)
+ .on(_pointerPrefix + 'move.drag-bg-offset', pointermove)
+ .on(_pointerPrefix + 'up.drag-bg-offset', pointerup);
+
+ if (_pointerPrefix === 'pointer') {
+ select(window)
+ .on('pointercancel.drag-bg-offset', pointerup);
+ }
+
+ function pointermove() {
+ if (pointerId !== (event.pointerId || 'mouse')) return;
+
+ var latest = [event.clientX, event.clientY];
+ var d = [
+ -(origin[0] - latest[0]) / 4,
+ -(origin[1] - latest[1]) / 4
+ ];
+
+ origin = latest;
+ nudge(d);
+ }
+
+ function pointerup() {
+ if (pointerId !== (event.pointerId || 'mouse')) return;
+ if (event.button !== 0) return;
+
+ context.container().selectAll('.nudge-surface')
+ .remove();
+
+ select(window)
+ .on('.drag-bg-offset', null);
+ }
+ }
+
+
+ function renderDisclosureContent(selection) {
+ var container = selection.selectAll('.nudge-container')
+ .data([0]);
+
+ var containerEnter = container.enter()
+ .append('div')
+ .attr('class', 'nudge-container cf');
+
+ containerEnter
+ .append('div')
+ .attr('class', 'nudge-instructions')
+ .text(_t('background.offset'));
+
+ var nudgeEnter = containerEnter
+ .append('div')
+ .attr('class', 'nudge-outer-rect')
+ .on(_pointerPrefix + 'down', dragOffset);
+
+ nudgeEnter
+ .append('div')
+ .attr('class', 'nudge-inner-rect')
+ .append('input')
+ .on('change', inputOffset);
+
+ containerEnter
+ .append('div')
+ .selectAll('button')
+ .data(_directions).enter()
+ .append('button')
+ .attr('class', function(d) { return d[0] + ' nudge'; })
+ .on('contextmenu', cancelEvent)
+ .on(_pointerPrefix + 'down', function(d) {
+ if (event.button !== 0) return;
+ pointerdownNudgeButton(d[1]);
+ });
+
+ containerEnter
+ .append('button')
+ .attr('title', _t('background.reset'))
+ .attr('class', 'nudge-reset disabled')
+ .on('contextmenu', cancelEvent)
+ .on('click', function() {
+ event.preventDefault();
+ if (event.button !== 0) return;
+ resetOffset();
+ })
+ .call(svgIcon('#iD-icon-' + (_mainLocalizer.textDirection() === 'rtl' ? 'redo' : 'undo')));
+
+ updateValue();
+ }
+
+ context.background()
+ .on('change.backgroundOffset-update', updateValue);
+
+ return section;
+ }
+
+ function uiSectionOverlayList(context) {
+
+ var section = uiSection('overlay-list', context)
+ .title(_t('background.overlays'))
+ .disclosureContent(renderDisclosureContent);
+
+ var _overlayList = select(null);
+
+ function setTooltips(selection) {
+ selection.each(function(d, i, nodes) {
+ var item = select(this).select('label');
+ var span = item.select('span');
+ var placement = (i < nodes.length / 2) ? 'bottom' : 'top';
+ var description = d.description();
+ var isOverflowing = (span.property('clientWidth') !== span.property('scrollWidth'));
+
+ item.call(uiTooltip().destroyAny);
+
+ if (description || isOverflowing) {
+ item.call(uiTooltip()
+ .placement(placement)
+ .title(description || d.name())
+ );
+ }
+ });
+ }
+
+ function updateLayerSelections(selection) {
+ function active(d) {
+ return context.background().showsLayer(d);
+ }
+
+ selection.selectAll('li')
+ .classed('active', active)
+ .call(setTooltips)
+ .selectAll('input')
+ .property('checked', active);
+ }
+
+
+ function chooseOverlay(d) {
+ event.preventDefault();
+ context.background().toggleOverlayLayer(d);
+ _overlayList.call(updateLayerSelections);
+ document.activeElement.blur();
+ }
+
+ function drawListItems(layerList, type, change, filter) {
+ var sources = context.background()
+ .sources(context.map().extent(), context.map().zoom(), true)
+ .filter(filter);
+
+ var layerLinks = layerList.selectAll('li')
+ .data(sources, function(d) { return d.name(); });
+
+ layerLinks.exit()
+ .remove();
+
+ var enter = layerLinks.enter()
+ .append('li');
+
+ var label = enter
+ .append('label');
+
+ label
+ .append('input')
+ .attr('type', type)
+ .attr('name', 'layers')
+ .on('change', change);
+
+ label
+ .append('span')
+ .text(function(d) { return d.name(); });
+
+
+ layerList.selectAll('li')
+ .sort(sortSources);
+
+ layerList
+ .call(updateLayerSelections);
+
+
+ function sortSources(a, b) {
+ return a.best() && !b.best() ? -1
+ : b.best() && !a.best() ? 1
+ : d3_descending(a.area(), b.area()) || d3_ascending(a.name(), b.name()) || 0;
+ }
+ }
+
+ function renderDisclosureContent(selection) {
+
+ var container = selection.selectAll('.layer-overlay-list')
+ .data([0]);
+
+ _overlayList = container.enter()
+ .append('ul')
+ .attr('class', 'layer-list layer-overlay-list')
+ .attr('dir', 'auto')
+ .merge(container);
+
+ _overlayList
+ .call(drawListItems, 'checkbox', chooseOverlay, function(d) { return !d.isHidden() && d.overlay; });
+ }
+
+ context.map()
+ .on('move.overlay_list',
+ debounce(function() {
+ // layers in-view may have changed due to map move
+ window.requestIdleCallback(section.reRender);
+ }, 1000)
+ );
+
+ return section;
+ }
+
+ function uiSectionGridDisplayOptions(context) {
+
+
+ var section = uiSection('grid-display-options', context)
+ .title(_t('background.grid.grids'))
+ .disclosureContent(gridDisplayOptions);
+
+
+ function chooseGrid(d) {
+ event.preventDefault();
+ context.background().numGridSplits(d.numSplit);
+ }
+
+
+ function render(selection) {
+ // the grid list
+ var container = selection.selectAll('.layer-grid-list')
+ .data([0]);
+
+ var gridList = container.enter()
+ .append('ul')
+ .attr('class', 'layer-list layer-grid-list')
+ .attr('dir', 'auto')
+ .merge(container);
+
+ var gridItems = gridList.selectAll('li')
+ .data(
+ [{numSplit: 0, name: _t('background.grid.no_grid')},
+ {numSplit: 2, name: _t('background.grid.n_by_n', {num: 2})},
+ {numSplit: 3, name: _t('background.grid.n_by_n', {num: 3})},
+ {numSplit: 4, name: _t('background.grid.n_by_n', {num: 4})},
+ {numSplit: 5, name: _t('background.grid.n_by_n', {num: 5})},
+ {numSplit: 6, name: _t('background.grid.n_by_n', {num: 6})}],
+ function(d) { return d.name; }
+ );
+
+ var enter = gridItems.enter()
+ .insert('li', '.custom-gridsopt')
+ .attr('class', 'gridsopt');
+
+ var label = enter.append('label');
+ label.append('input')
+ .attr('type', 'radio')
+ .attr('name', 'grids')
+ .property('checked', function(d){
+ return (d.numSplit === context.background().numGridSplits());
+ })
+ .on('change', chooseGrid);
+
+ label.append('span')
+ .text(function(d) {return d.name;});
+
+ gridItems.exit()
+ .remove();
+ }
+
+
+ function gridDisplayOptions(selection) {
+ var gridOptionsSection = select('.section-grid-display-options');
+
+ context.rapidContext().on('task_extent_set.grid_display_options', function() {
+ if (context.rapidContext().isTaskRectangular()) {
+ gridOptionsSection.classed('hide', false);
+ selection.call(render);
+ }
+ });
+
+ if (!context.rapidContext().isTaskRectangular()){
+ gridOptionsSection.classed('hide', true);
+ return;
+ }
+ }
+
+
+ return section;
+ }
+
+ function uiPaneBackground(context) {
+
+ var backgroundPane = uiPane('background', context)
+ .key(_t('background.key'))
+ .title(_t('background.title'))
+ .description(_t('background.description'))
+ .iconName('iD-icon-layers')
+ .sections([
+ uiSectionBackgroundList(context),
+ uiSectionOverlayList(context),
+ uiSectionGridDisplayOptions(context),
+ uiSectionBackgroundDisplayOptions(context),
+ uiSectionBackgroundOffset(context)
+ ]);
+
+ return backgroundPane;
+ }
+
+ function uiPaneHelp(context) {
+
+ var docKeys = [
+ ['help', [
+ 'welcome',
+ 'open_data_h',
+ 'open_data',
+ 'before_start_h',
+ 'before_start',
+ 'open_source_h',
+ 'open_source',
+ 'open_source_help'
+ ]],
+ ['overview', [
+ 'navigation_h',
+ 'navigation_drag',
+ 'navigation_zoom',
+ 'features_h',
+ 'features',
+ 'nodes_ways'
+ ]],
+ ['editing', [
+ 'select_h',
+ 'select_left_click',
+ 'select_right_click',
+ 'select_space',
+ 'multiselect_h',
+ 'multiselect',
+ 'multiselect_shift_click',
+ 'multiselect_lasso',
+ 'undo_redo_h',
+ 'undo_redo',
+ 'save_h',
+ 'save',
+ 'save_validation',
+ 'upload_h',
+ 'upload',
+ 'backups_h',
+ 'backups',
+ 'keyboard_h',
+ 'keyboard'
+ ]],
+ ['feature_editor', [
+ 'intro',
+ 'definitions',
+ 'type_h',
+ 'type',
+ 'type_picker',
+ 'fields_h',
+ 'fields_all_fields',
+ 'fields_example',
+ 'fields_add_field',
+ 'tags_h',
+ 'tags_all_tags',
+ 'tags_resources'
+ ]],
+ ['points', [
+ 'intro',
+ 'add_point_h',
+ 'add_point',
+ 'add_point_finish',
+ 'move_point_h',
+ 'move_point',
+ 'delete_point_h',
+ 'delete_point',
+ 'delete_point_command'
+ ]],
+ ['lines', [
+ 'intro',
+ 'add_line_h',
+ 'add_line',
+ 'add_line_draw',
+ 'add_line_continue',
+ 'add_line_finish',
+ 'modify_line_h',
+ 'modify_line_dragnode',
+ 'modify_line_addnode',
+ 'connect_line_h',
+ 'connect_line',
+ 'connect_line_display',
+ 'connect_line_drag',
+ 'connect_line_tag',
+ 'disconnect_line_h',
+ 'disconnect_line_command',
+ 'move_line_h',
+ 'move_line_command',
+ 'move_line_connected',
+ 'delete_line_h',
+ 'delete_line',
+ 'delete_line_command'
+ ]],
+ ['areas', [
+ 'intro',
+ 'point_or_area_h',
+ 'point_or_area',
+ 'add_area_h',
+ 'add_area_command',
+ 'add_area_draw',
+ 'add_area_continue',
+ 'add_area_finish',
+ 'square_area_h',
+ 'square_area_command',
+ 'modify_area_h',
+ 'modify_area_dragnode',
+ 'modify_area_addnode',
+ 'delete_area_h',
+ 'delete_area',
+ 'delete_area_command'
+ ]],
+ ['relations', [
+ 'intro',
+ 'edit_relation_h',
+ 'edit_relation',
+ 'edit_relation_add',
+ 'edit_relation_delete',
+ 'maintain_relation_h',
+ 'maintain_relation',
+ 'relation_types_h',
+ 'multipolygon_h',
+ 'multipolygon',
+ 'multipolygon_create',
+ 'multipolygon_merge',
+ 'turn_restriction_h',
+ 'turn_restriction',
+ 'turn_restriction_field',
+ 'turn_restriction_editing',
+ 'route_h',
+ 'route',
+ 'route_add',
+ 'boundary_h',
+ 'boundary',
+ 'boundary_add'
+ ]],
+ ['notes', [
+ 'intro',
+ 'add_note_h',
+ 'add_note',
+ 'place_note',
+ 'move_note',
+ 'update_note_h',
+ 'update_note',
+ 'save_note_h',
+ 'save_note'
+ ]],
+ ['imagery', [
+ 'intro',
+ 'sources_h',
+ 'choosing',
+ 'sources',
+ 'offsets_h',
+ 'offset',
+ 'offset_change'
+ ]],
+ ['streetlevel', [
+ 'intro',
+ 'using_h',
+ 'using',
+ 'photos',
+ 'viewer'
+ ]],
+ ['gps', [
+ 'intro',
+ 'survey',
+ 'using_h',
+ 'using',
+ 'tracing',
+ 'upload'
+ ]],
+ ['qa', [
+ 'intro',
+ 'tools_h',
+ 'tools',
+ 'issues_h',
+ 'issues'
+ ]]
+ ];
+
+ var headings = {
+ 'help.help.open_data_h': 3,
+ 'help.help.before_start_h': 3,
+ 'help.help.open_source_h': 3,
+ 'help.overview.navigation_h': 3,
+ 'help.overview.features_h': 3,
+ 'help.editing.select_h': 3,
+ 'help.editing.multiselect_h': 3,
+ 'help.editing.undo_redo_h': 3,
+ 'help.editing.save_h': 3,
+ 'help.editing.upload_h': 3,
+ 'help.editing.backups_h': 3,
+ 'help.editing.keyboard_h': 3,
+ 'help.feature_editor.type_h': 3,
+ 'help.feature_editor.fields_h': 3,
+ 'help.feature_editor.tags_h': 3,
+ 'help.points.add_point_h': 3,
+ 'help.points.move_point_h': 3,
+ 'help.points.delete_point_h': 3,
+ 'help.lines.add_line_h': 3,
+ 'help.lines.modify_line_h': 3,
+ 'help.lines.connect_line_h': 3,
+ 'help.lines.disconnect_line_h': 3,
+ 'help.lines.move_line_h': 3,
+ 'help.lines.delete_line_h': 3,
+ 'help.areas.point_or_area_h': 3,
+ 'help.areas.add_area_h': 3,
+ 'help.areas.square_area_h': 3,
+ 'help.areas.modify_area_h': 3,
+ 'help.areas.delete_area_h': 3,
+ 'help.relations.edit_relation_h': 3,
+ 'help.relations.maintain_relation_h': 3,
+ 'help.relations.relation_types_h': 2,
+ 'help.relations.multipolygon_h': 3,
+ 'help.relations.turn_restriction_h': 3,
+ 'help.relations.route_h': 3,
+ 'help.relations.boundary_h': 3,
+ 'help.notes.add_note_h': 3,
+ 'help.notes.update_note_h': 3,
+ 'help.notes.save_note_h': 3,
+ 'help.imagery.sources_h': 3,
+ 'help.imagery.offsets_h': 3,
+ 'help.streetlevel.using_h': 3,
+ 'help.gps.using_h': 3,
+ 'help.qa.tools_h': 3,
+ 'help.qa.issues_h': 3
+ };
+
+ // For each section, squash all the texts into a single markdown document
+ var docs = docKeys.map(function(key) {
+ var helpkey = 'help.' + key[0];
+ var helpPaneReplacements = { version: context.rapidContext().version };
+ var text = key[1].reduce(function(all, part) {
+ var subkey = helpkey + '.' + part;
+ var depth = headings[subkey]; // is this subkey a heading?
+ var hhh = depth ? Array(depth + 1).join('#') + ' ' : ''; // if so, prepend with some ##'s
+ return all + hhh + helpString(subkey, helpPaneReplacements) + '\n\n';
+ }, '');
+
+ return {
+ title: _t(helpkey + '.title'),
+ html: marked_1(text.trim())
+ // use keyboard key styling for shortcuts
+ .replace(//g, '')
+ .replace(/<\/code>/g, '<\/kbd>')
+ };
+ });
+
+ var helpPane = uiPane('help', context)
+ .key(_t('help.key'))
+ .title(_t('help.title'))
+ .description(_t('help.title'))
+ .iconName('iD-icon-help');
+
+ helpPane.renderContent = function(content) {
+
+ function clickHelp(d, i) {
+ var rtl = (_mainLocalizer.textDirection() === 'rtl');
+ content.property('scrollTop', 0);
+ helpPane.selection().select('.pane-heading h2').html(d.title);
+
+ body.html(d.html);
+ body.selectAll('a')
+ .attr('target', '_blank');
+ menuItems.classed('selected', function(m) {
+ return m.title === d.title;
+ });
+
+ nav.html('');
+ if (rtl) {
+ nav.call(drawNext).call(drawPrevious);
+ } else {
+ nav.call(drawPrevious).call(drawNext);
+ }
+
+
+ function drawNext(selection) {
+ if (i < docs.length - 1) {
+ var nextLink = selection
+ .append('a')
+ .attr('class', 'next')
+ .on('click', function() {
+ clickHelp(docs[i + 1], i + 1);
+ });
+
+ nextLink
+ .append('span')
+ .text(docs[i + 1].title)
+ .call(svgIcon((rtl ? '#iD-icon-backward' : '#iD-icon-forward'), 'inline'));
+ }
+ }
+
+
+ function drawPrevious(selection) {
+ if (i > 0) {
+ var prevLink = selection
+ .append('a')
+ .attr('class', 'previous')
+ .on('click', function() {
+ clickHelp(docs[i - 1], i - 1);
+ });
+
+ prevLink
+ .call(svgIcon((rtl ? '#iD-icon-forward' : '#iD-icon-backward'), 'inline'))
+ .append('span')
+ .text(docs[i - 1].title);
+ }
+ }
+ }
+
+
+ function clickWalkthrough() {
+ if (context.inIntro()) return;
+ context.container().call(uiIntro(context));
+ context.ui().togglePanes();
+ }
+
+
+ function clickShortcuts() {
+ context.container().call(uiShortcuts(context), true);
+ }
+
+ var toc = content
+ .append('ul')
+ .attr('class', 'toc');
+
+ var menuItems = toc.selectAll('li')
+ .data(docs)
+ .enter()
+ .append('li')
+ .append('a')
+ .html(function(d) { return d.title; })
+ .on('click', clickHelp);
+
+ var shortcuts = toc
+ .append('li')
+ .attr('class', 'shortcuts')
+ .call(uiTooltip()
+ .title(_t('shortcuts.tooltip'))
+ .keys(['?'])
+ .placement('top')
+ )
+ .append('a')
+ .on('click', clickShortcuts);
+
+ shortcuts
+ .append('div')
+ .text(_t('shortcuts.title'));
+
+ var walkthrough = toc
+ .append('li')
+ .attr('class', 'walkthrough')
+ .append('a')
+ .on('click', clickWalkthrough);
+
+ walkthrough
+ .append('svg')
+ .attr('class', 'logo logo-walkthrough')
+ .append('use')
+ .attr('xlink:href', '#iD-logo-walkthrough');
+
+ walkthrough
+ .append('div')
+ .text(_t('splash.walkthrough'));
+
+
+ var helpContent = content
+ .append('div')
+ .attr('class', 'left-content');
+
+ var body = helpContent
+ .append('div')
+ .attr('class', 'body');
+
+ var nav = helpContent
+ .append('div')
+ .attr('class', 'nav');
+
+ clickHelp(docs[0], 0);
+
+ };
+
+ return helpPane;
+ }
+
+ function uiSectionValidationIssues(id, severity, context) {
+
+ var _issues = [];
+
+ var section = uiSection(id, context)
+ .title(function() {
+ if (!_issues) return '';
+ var issueCountText = _issues.length > 1000 ? '1000+' : String(_issues.length);
+ return _t('issues.' + severity + 's.list_title', { count: issueCountText });
+ })
+ .disclosureContent(renderDisclosureContent)
+ .shouldDisplay(function() {
+ return _issues && _issues.length;
+ });
+
+ function getOptions() {
+ return {
+ what: corePreferences('validate-what') || 'edited',
+ where: corePreferences('validate-where') || 'all'
+ };
+ }
+
+ // get and cache the issues to display, unordered
+ function reloadIssues() {
+ _issues = context.validator().getIssuesBySeverity(getOptions())[severity];
+ }
+
+ function renderDisclosureContent(selection) {
+
+ var center = context.map().center();
+ var graph = context.graph();
+
+ // sort issues by distance away from the center of the map
+ var issues = _issues.map(function withDistance(issue) {
+ var extent = issue.extent(graph);
+ var dist = extent ? geoSphericalDistance(center, extent.center()) : 0;
+ return Object.assign(issue, { dist: dist });
+ })
+ .sort(function byDistance(a, b) {
+ return a.dist - b.dist;
+ });
+
+ // cut off at 1000
+ issues = issues.slice(0, 1000);
+
+ //renderIgnoredIssuesReset(_warningsSelection);
+
+ selection
+ .call(drawIssuesList, issues);
+ }
+
+ function drawIssuesList(selection, issues) {
+ const showAutoFix = corePreferences('rapid-internal-feature.showAutoFix') === 'true';
+
+ var list = selection.selectAll('.issues-list')
+ .data([0]);
+
+ list = list.enter()
+ .append('ul')
+ .attr('class', 'layer-list issues-list ' + severity + 's-list')
+ .merge(list);
+
+
+ var items = list.selectAll('li')
+ .data(issues, function(d) { return d.id; });
+
+ // Exit
+ items.exit()
+ .remove();
+
+ // Enter
+ var itemsEnter = items.enter()
+ .append('li')
+ .attr('class', function (d) { return 'issue severity-' + d.severity; })
+ .on('click', function(d) {
+ context.validator().focusIssue(d);
+ })
+ .on('mouseover', function(d) {
+ utilHighlightEntities(d.entityIds, true, context);
+ })
+ .on('mouseout', function(d) {
+ utilHighlightEntities(d.entityIds, false, context);
+ });
+
+
+ var labelsEnter = itemsEnter
+ .append('div')
+ .attr('class', 'issue-label');
+
+ var textEnter = labelsEnter
+ .append('span')
+ .attr('class', 'issue-text');
+
+ textEnter
+ .append('span')
+ .attr('class', 'issue-icon')
+ .each(function(d) {
+ var iconName = '#iD-icon-' + (d.severity === 'warning' ? 'alert' : 'error');
+ select(this)
+ .call(svgIcon(iconName));
+ });
+
+ textEnter
+ .append('span')
+ .attr('class', 'issue-message');
+
+ if (showAutoFix) {
+ labelsEnter
+ .append('span')
+ .attr('class', 'issue-autofix')
+ .each(function(d) {
+ if (!d.autoArgs) return;
+
+ select(this)
+ .append('button')
+ .attr('title', _t('issues.fix_one.title'))
+ .datum(d) // set button datum to the issue
+ .attr('class', 'autofix action')
+ .on('click', function(d) {
+ event.preventDefault();
+ event.stopPropagation();
+
+ utilHighlightEntities(d.entityIds, false, context); // unhighlight
+ context.perform.apply(context, d.autoArgs);
+ context.validator().validate();
+ })
+ .call(svgIcon('#iD-icon-wrench'));
+ });
+ } /* show autoFix */
+
+ // Update
+ items = items
+ .merge(itemsEnter)
+ .order();
+
+ items.selectAll('.issue-message')
+ .text(function(d) {
+ return d.message(context);
+ });
+
+ var canAutoFix = issues.filter(function(issue) { return issue.autoArgs; });
+ var autoFixAll = selection.selectAll('.autofix-all')
+ .data(showAutoFix && canAutoFix.length ? [0] : []);
+
+ // exit
+ autoFixAll.exit()
+ .remove();
+
+ // enter
+ var autoFixAllEnter = autoFixAll.enter()
+ .insert('div', '.issues-list')
+ .attr('class', 'autofix-all');
+
+ var linkEnter = autoFixAllEnter
+ .append('a')
+ .attr('class', 'autofix-all-link')
+ .attr('href', '#');
+
+ linkEnter
+ .append('span')
+ .attr('class', 'autofix-all-link-text')
+ .text(_t('issues.fix_all.title'));
+
+ linkEnter
+ .append('span')
+ .attr('class', 'autofix-all-link-icon')
+ .call(svgIcon('#iD-icon-wrench'));
+
+ // if (severity === 'warning') {
+ // renderIgnoredIssuesReset(selection);
+ // }
+
+ // update
+ autoFixAll = autoFixAll
+ .merge(autoFixAllEnter);
+
+ autoFixAll.selectAll('.autofix-all-link')
+ .on('click', function() {
+ context.pauseChangeDispatch();
+ context.perform(actionNoop());
+ canAutoFix.forEach(function(issue) {
+ var args = issue.autoArgs.slice(); // copy
+ if (typeof args[args.length - 1] !== 'function') {
+ args.pop();
+ }
+ args.push(_t('issues.fix_all.annotation'));
+ context.replace.apply(context, args);
+ });
+ context.resumeChangeDispatch();
+ context.validator().validate();
+ });
+ }
+
+ context.validator().on('validated.uiSectionValidationIssues' + id, function() {
+ window.requestIdleCallback(function() {
+ reloadIssues();
+ section.reRender();
+ });
+ });
+
+ context.map().on('move.uiSectionValidationIssues' + id,
+ debounce(function() {
+ window.requestIdleCallback(function() {
+ if (getOptions().where === 'visible') {
+ // must refetch issues if they are viewport-dependent
+ reloadIssues();
+ }
+ // always reload list to re-sort-by-distance
+ section.reRender();
+ });
+ }, 1000)
+ );
+
+ return section;
+ }
+
+ function uiSectionValidationOptions(context) {
+
+ var section = uiSection('issues-options', context)
+ .content(renderContent);
+
+ function renderContent(selection) {
+
+ var container = selection.selectAll('.issues-options-container')
+ .data([0]);
+
+ container = container.enter()
+ .append('div')
+ .attr('class', 'issues-options-container')
+ .merge(container);
+
+ var data = [
+ { key: 'what', values: ['edited', 'all'] },
+ { key: 'where', values: ['visible', 'all'] }
+ ];
+
+ var options = container.selectAll('.issues-option')
+ .data(data, function(d) { return d.key; });
+
+ var optionsEnter = options.enter()
+ .append('div')
+ .attr('class', function(d) { return 'issues-option issues-option-' + d.key; });
+
+ optionsEnter
+ .append('div')
+ .attr('class', 'issues-option-title')
+ .text(function(d) { return _t('issues.options.' + d.key + '.title'); });
+
+ var valuesEnter = optionsEnter.selectAll('label')
+ .data(function(d) {
+ return d.values.map(function(val) { return { value: val, key: d.key }; });
+ })
+ .enter()
+ .append('label');
+
+ valuesEnter
+ .append('input')
+ .attr('type', 'radio')
+ .attr('name', function(d) { return 'issues-option-' + d.key; })
+ .attr('value', function(d) { return d.value; })
+ .property('checked', function(d) { return getOptions()[d.key] === d.value; })
+ .on('change', function(d) { updateOptionValue(d.key, d.value); });
+
+ valuesEnter
+ .append('span')
+ .text(function(d) { return _t('issues.options.' + d.key + '.' + d.value); });
+ }
+
+ function getOptions() {
+ return {
+ what: corePreferences('validate-what') || 'edited', // 'all', 'edited'
+ where: corePreferences('validate-where') || 'all' // 'all', 'visible'
+ };
+ }
+
+ function updateOptionValue(d, val) {
+ if (!val && event && event.target) {
+ val = event.target.value;
+ }
+
+ corePreferences('validate-' + d, val);
+ context.validator().validate();
+ }
+
+ return section;
+ }
+
+ function uiSectionValidationRules(context) {
+
+ var MINSQUARE = 0;
+ var MAXSQUARE = 20;
+ var DEFAULTSQUARE = 5; // see also unsquare_way.js
+
+ var section = uiSection('issues-rules', context)
+ .disclosureContent(renderDisclosureContent)
+ .title(_t('issues.rules.title'));
+
+ var _ruleKeys = context.validator().getRuleKeys()
+ .filter(function(key) { return key !== 'maprules'; })
+ .sort(function(key1, key2) {
+ // alphabetize by localized title
+ return _t('issues.' + key1 + '.title') < _t('issues.' + key2 + '.title') ? -1 : 1;
+ });
+
+ function renderDisclosureContent(selection) {
+ var container = selection.selectAll('.issues-rulelist-container')
+ .data([0]);
+
+ var containerEnter = container.enter()
+ .append('div')
+ .attr('class', 'issues-rulelist-container');
+
+ containerEnter
+ .append('ul')
+ .attr('class', 'layer-list issue-rules-list');
+
+ var ruleLinks = containerEnter
+ .append('div')
+ .attr('class', 'issue-rules-links section-footer');
+
+ ruleLinks
+ .append('a')
+ .attr('class', 'issue-rules-link')
+ .attr('href', '#')
+ .text(_t('issues.enable_all'))
+ .on('click', function() {
+ context.validator().disableRules([]);
+ });
+
+ ruleLinks
+ .append('a')
+ .attr('class', 'issue-rules-link')
+ .attr('href', '#')
+ .text(_t('issues.disable_all'))
+ .on('click', function() {
+ context.validator().disableRules(_ruleKeys);
+ });
+
+
+ // Update
+ container = container
+ .merge(containerEnter);
+
+ container.selectAll('.issue-rules-list')
+ .call(drawListItems, _ruleKeys, 'checkbox', 'rule', toggleRule, isRuleEnabled);
+ }
+
+ function drawListItems(selection, data, type, name, change, active) {
+ var items = selection.selectAll('li')
+ .data(data);
+
+ // Exit
+ items.exit()
+ .remove();
+
+ // Enter
+ var enter = items.enter()
+ .append('li');
+
+ if (name === 'rule') {
+ enter
+ .call(uiTooltip()
+ .title(function(d) { return _t('issues.' + d + '.tip'); })
+ .placement('top')
+ );
+ }
+
+ var label = enter
+ .append('label');
+
+ label
+ .append('input')
+ .attr('type', type)
+ .attr('name', name)
+ .on('change', change);
+
+ label
+ .append('span')
+ .html(function(d) {
+ var params = {};
+ if (d === 'unsquare_way') {
+ params.val = ' ';
+ }
+ return _t('issues.' + d + '.title', params);
+ });
+
+ // Update
+ items = items
+ .merge(enter);
+
+ items
+ .classed('active', active)
+ .selectAll('input')
+ .property('checked', active)
+ .property('indeterminate', false);
+
+
+ // user-configurable square threshold
+ var degStr = corePreferences('validate-square-degrees');
+ if (degStr === null) {
+ degStr = '' + DEFAULTSQUARE;
+ }
+
+ var span = items.selectAll('.square-degrees');
+ var input = span.selectAll('.square-degrees-input')
+ .data([0]);
+
+ // enter / update
+ input.enter()
+ .append('input')
+ .attr('type', 'number')
+ .attr('min', '' + MINSQUARE)
+ .attr('max', '' + MAXSQUARE)
+ .attr('step', '0.5')
+ .attr('class', 'square-degrees-input')
+ .call(utilNoAuto)
+ .on('click', function () {
+ event.preventDefault();
+ event.stopPropagation();
+ this.select();
+ })
+ .on('keyup', function () {
+ if (event.keyCode === 13) { // enter
+ this.blur();
+ this.select();
+ }
+ })
+ .on('blur', changeSquare)
+ .merge(input)
+ .property('value', degStr);
+ }
+
+ function changeSquare() {
+ var input = select(this);
+ var degStr = utilGetSetValue(input).trim();
+ var degNum = parseFloat(degStr, 10);
+
+ if (!isFinite(degNum)) {
+ degNum = DEFAULTSQUARE;
+ } else if (degNum > MAXSQUARE) {
+ degNum = MAXSQUARE;
+ } else if (degNum < MINSQUARE) {
+ degNum = MINSQUARE;
+ }
+
+ degNum = Math.round(degNum * 10 ) / 10; // round to 1 decimal
+ degStr = '' + degNum;
+
+ input
+ .property('value', degStr);
+
+ corePreferences('validate-square-degrees', degStr);
+ context.validator().reloadUnsquareIssues();
+ }
+
+ function isRuleEnabled(d) {
+ return context.validator().isRuleEnabled(d);
+ }
+
+ function toggleRule(d) {
+ context.validator().toggleRule(d);
+ }
+
+ context.validator().on('validated.uiSectionValidationRules', function() {
+ window.requestIdleCallback(section.reRender);
+ });
+
+ return section;
+ }
+
+ function uiSectionValidationStatus(context) {
+
+ var section = uiSection('issues-status', context)
+ .content(renderContent)
+ .shouldDisplay(function() {
+ var issues = context.validator().getIssues(getOptions());
+ return issues.length === 0;
+ });
+
+ function getOptions() {
+ return {
+ what: corePreferences('validate-what') || 'edited',
+ where: corePreferences('validate-where') || 'all'
+ };
+ }
+
+ function renderContent(selection) {
+
+ var box = selection.selectAll('.box')
+ .data([0]);
+
+ var boxEnter = box.enter()
+ .append('div')
+ .attr('class', 'box');
+
+ boxEnter
+ .append('div')
+ .call(svgIcon('#iD-icon-apply', 'pre-text'));
+
+ var noIssuesMessage = boxEnter
+ .append('span');
+
+ noIssuesMessage
+ .append('strong')
+ .attr('class', 'message');
+
+ noIssuesMessage
+ .append('br');
+
+ noIssuesMessage
+ .append('span')
+ .attr('class', 'details');
+
+ renderIgnoredIssuesReset(selection);
+ setNoIssuesText(selection);
+ }
+
+ function renderIgnoredIssuesReset(selection) {
+
+ var ignoredIssues = context.validator()
+ .getIssues({ what: 'all', where: 'all', includeDisabledRules: true, includeIgnored: 'only' });
+
+ var resetIgnored = selection.selectAll('.reset-ignored')
+ .data(ignoredIssues.length ? [0] : []);
+
+ // exit
+ resetIgnored.exit()
+ .remove();
+
+ // enter
+ var resetIgnoredEnter = resetIgnored.enter()
+ .append('div')
+ .attr('class', 'reset-ignored section-footer');
+
+ resetIgnoredEnter
+ .append('a')
+ .attr('href', '#');
+
+ // update
+ resetIgnored = resetIgnored
+ .merge(resetIgnoredEnter);
+
+ resetIgnored.select('a')
+ .text(_t('issues.reset_ignored', { count: ignoredIssues.length.toString() }));
+
+ resetIgnored.on('click', function() {
+ context.validator().resetIgnoredIssues();
+ });
+ }
+
+ function setNoIssuesText(selection) {
+
+ var opts = getOptions();
+
+ function checkForHiddenIssues(cases) {
+ for (var type in cases) {
+ var hiddenOpts = cases[type];
+ var hiddenIssues = context.validator().getIssues(hiddenOpts);
+ if (hiddenIssues.length) {
+ selection.select('.box .details')
+ .text(_t(
+ 'issues.no_issues.hidden_issues.' + type,
+ { count: hiddenIssues.length.toString() }
+ ));
+ return;
+ }
+ }
+ selection.select('.box .details')
+ .text(_t('issues.no_issues.hidden_issues.none'));
+ }
+
+ var messageType;
+
+ if (opts.what === 'edited' && opts.where === 'visible') {
+
+ messageType = 'edits_in_view';
+
+ checkForHiddenIssues({
+ elsewhere: { what: 'edited', where: 'all' },
+ everything_else: { what: 'all', where: 'visible' },
+ disabled_rules: { what: 'edited', where: 'visible', includeDisabledRules: 'only' },
+ everything_else_elsewhere: { what: 'all', where: 'all' },
+ disabled_rules_elsewhere: { what: 'edited', where: 'all', includeDisabledRules: 'only' },
+ ignored_issues: { what: 'edited', where: 'visible', includeIgnored: 'only' },
+ ignored_issues_elsewhere: { what: 'edited', where: 'all', includeIgnored: 'only' }
+ });
+
+ } else if (opts.what === 'edited' && opts.where === 'all') {
+
+ messageType = 'edits';
+
+ checkForHiddenIssues({
+ everything_else: { what: 'all', where: 'all' },
+ disabled_rules: { what: 'edited', where: 'all', includeDisabledRules: 'only' },
+ ignored_issues: { what: 'edited', where: 'all', includeIgnored: 'only' }
+ });
+
+ } else if (opts.what === 'all' && opts.where === 'visible') {
+
+ messageType = 'everything_in_view';
+
+ checkForHiddenIssues({
+ elsewhere: { what: 'all', where: 'all' },
+ disabled_rules: { what: 'all', where: 'visible', includeDisabledRules: 'only' },
+ disabled_rules_elsewhere: { what: 'all', where: 'all', includeDisabledRules: 'only' },
+ ignored_issues: { what: 'all', where: 'visible', includeIgnored: 'only' },
+ ignored_issues_elsewhere: { what: 'all', where: 'all', includeIgnored: 'only' }
+ });
+ } else if (opts.what === 'all' && opts.where === 'all') {
+
+ messageType = 'everything';
+
+ checkForHiddenIssues({
+ disabled_rules: { what: 'all', where: 'all', includeDisabledRules: 'only' },
+ ignored_issues: { what: 'all', where: 'all', includeIgnored: 'only' }
+ });
+ }
+
+ if (opts.what === 'edited' && context.history().difference().summary().length === 0) {
+ messageType = 'no_edits';
+ }
+
+ selection.select('.box .message')
+ .text(_t('issues.no_issues.message.' + messageType));
+
+ }
+
+ context.validator().on('validated.uiSectionValidationStatus', function() {
+ window.requestIdleCallback(section.reRender);
+ });
+
+ context.map().on('move.uiSectionValidationStatus',
+ debounce(function() {
+ window.requestIdleCallback(section.reRender);
+ }, 1000)
+ );
+
+ return section;
+ }
+
+ function uiPaneIssues(context) {
+
+ var issuesPane = uiPane('issues', context)
+ .key(_t('issues.key'))
+ .title(_t('issues.title'))
+ .description(_t('issues.title'))
+ .iconName('iD-icon-alert')
+ .sections([
+ uiSectionValidationOptions(context),
+ uiSectionValidationStatus(context),
+ uiSectionValidationIssues('issues-errors', 'error', context),
+ uiSectionValidationIssues('issues-warnings', 'warning', context),
+ uiSectionValidationRules(context)
+ ]);
+
+ return issuesPane;
+ }
+
+ function uiSettingsCustomData(context) {
+ var dispatch$1 = dispatch('change');
+
+ function render(selection) {
+ var dataLayer = context.layers().layer('data');
+
+ // keep separate copies of original and current settings
+ var _origSettings = {
+ fileList: (dataLayer && dataLayer.fileList()) || null,
+ url: corePreferences('settings-custom-data-url')
+ };
+ var _currSettings = {
+ fileList: (dataLayer && dataLayer.fileList()) || null,
+ url: corePreferences('settings-custom-data-url')
+ };
+
+ // var example = 'https://{switch:a,b,c}.tile.openstreetmap.org/{zoom}/{x}/{y}.png';
+ var modal = uiConfirm(selection).okButton();
+
+ modal
+ .classed('settings-modal settings-custom-data', true);
+
+ modal.select('.modal-section.header')
+ .append('h3')
+ .text(_t('settings.custom_data.header'));
+
+
+ var textSection = modal.select('.modal-section.message-text');
+
+ textSection
+ .append('pre')
+ .attr('class', 'instructions-file')
+ .text(_t('settings.custom_data.file.instructions'));
+
+ textSection
+ .append('input')
+ .attr('class', 'field-file')
+ .attr('type', 'file')
+ .property('files', _currSettings.fileList) // works for all except IE11
+ .on('change', function() {
+ var files = event.target.files;
+ if (files && files.length) {
+ _currSettings.url = '';
+ textSection.select('.field-url').property('value', '');
+ _currSettings.fileList = files;
+ } else {
+ _currSettings.fileList = null;
+ }
+ });
+
+ textSection
+ .append('h4')
+ .text(_t('settings.custom_data.or'));
+
+ textSection
+ .append('pre')
+ .attr('class', 'instructions-url')
+ .text(_t('settings.custom_data.url.instructions'));
+
+ textSection
+ .append('textarea')
+ .attr('class', 'field-url')
+ .attr('placeholder', _t('settings.custom_data.url.placeholder'))
+ .call(utilNoAuto)
+ .property('value', _currSettings.url);
+
+
+ // insert a cancel button
+ var buttonSection = modal.select('.modal-section.buttons');
+
+ buttonSection
+ .insert('button', '.ok-button')
+ .attr('class', 'button cancel-button secondary-action')
+ .text(_t('confirm.cancel'));
+
+
+ buttonSection.select('.cancel-button')
+ .on('click.cancel', clickCancel);
+
+ buttonSection.select('.ok-button')
+ .attr('disabled', isSaveDisabled)
+ .on('click.save', clickSave);
+
+
+ function isSaveDisabled() {
+ return null;
+ }
+
+
+ // restore the original url
+ function clickCancel() {
+ textSection.select('.field-url').property('value', _origSettings.url);
+ corePreferences('settings-custom-data-url', _origSettings.url);
+ this.blur();
+ modal.close();
+ }
+
+ // accept the current url
+ function clickSave() {
+ _currSettings.url = textSection.select('.field-url').property('value').trim();
+
+ // one or the other but not both
+ if (_currSettings.url) { _currSettings.fileList = null; }
+ if (_currSettings.fileList) { _currSettings.url = ''; }
+
+ corePreferences('settings-custom-data-url', _currSettings.url);
+ this.blur();
+ modal.close();
+ dispatch$1.call('change', this, _currSettings);
+ }
+ }
+
+ return utilRebind(render, dispatch$1, 'on');
+ }
+
+ function uiSectionDataLayers(context) {
+
+ var settingsCustomData = uiSettingsCustomData(context)
+ .on('change', customChanged);
+
+ var layers = context.layers();
+
+ var section = uiSection('data-layers', context)
+ .title(_t('map_data.data_layers'))
+ .disclosureContent(renderDisclosureContent);
+
+ function renderDisclosureContent(selection) {
+ var container = selection.selectAll('.data-layer-container')
+ .data([0]);
+
+ container.enter()
+ .append('div')
+ .attr('class', 'data-layer-container')
+ .merge(container)
+ .call(drawOsmItems)
+ .call(drawQAItems)
+ .call(drawCustomDataItems)
+ .call(drawVectorItems) // Beta - Detroit mapping challenge
+ .call(drawPanelItems);
+ }
+
+ function showsLayer(which) {
+ var layer = layers.layer(which);
+ if (layer) {
+ return layer.enabled();
+ }
+ return false;
+ }
+
+ function setLayer(which, enabled) {
+ // Don't allow layer changes while drawing - #6584
+ var mode = context.mode();
+ if (mode && /^draw/.test(mode.id)) return;
+
+ var layer = layers.layer(which);
+ if (layer) {
+ layer.enabled(enabled);
+
+ if (!enabled && (which === 'osm' || which === 'notes')) {
+ context.enter(modeBrowse(context));
+ }
+ }
+ }
+
+ function toggleLayer(which) {
+ setLayer(which, !showsLayer(which));
+ }
+
+ function drawOsmItems(selection) {
+ var osmKeys = ['osm', 'notes'];
+ var osmLayers = layers.all().filter(function(obj) { return osmKeys.indexOf(obj.id) !== -1; });
+
+ var ul = selection
+ .selectAll('.layer-list-osm')
+ .data([0]);
+
+ ul = ul.enter()
+ .append('ul')
+ .attr('class', 'layer-list layer-list-osm')
+ .merge(ul);
+
+ var li = ul.selectAll('.list-item')
+ .data(osmLayers);
+
+ li.exit()
+ .remove();
+
+ var liEnter = li.enter()
+ .append('li')
+ .attr('class', function(d) { return 'list-item list-item-' + d.id; });
+
+ var labelEnter = liEnter
+ .append('label')
+ .each(function(d) {
+ if (d.id === 'osm') {
+ select(this)
+ .call(uiTooltip()
+ .title(_t('map_data.layers.' + d.id + '.tooltip'))
+ .keys([uiCmd('⌥' + _t('area_fill.wireframe.key'))])
+ .placement('bottom')
+ );
+ } else {
+ select(this)
+ .call(uiTooltip()
+ .title(_t('map_data.layers.' + d.id + '.tooltip'))
+ .placement('bottom')
+ );
+ }
+ });
+
+ labelEnter
+ .append('input')
+ .attr('type', 'checkbox')
+ .on('change', function(d) { toggleLayer(d.id); });
+
+ labelEnter
+ .append('span')
+ .text(function(d) { return _t('map_data.layers.' + d.id + '.title'); });
+
+
+ // Update
+ li
+ .merge(liEnter)
+ .classed('active', function (d) { return d.layer.enabled(); })
+ .selectAll('input')
+ .property('checked', function (d) { return d.layer.enabled(); });
+ }
+
+ function drawQAItems(selection) {
+ var qaKeys = ['keepRight', 'improveOSM', 'osmose'];
+ var qaLayers = layers.all().filter(function(obj) { return qaKeys.indexOf(obj.id) !== -1; });
+
+ var ul = selection
+ .selectAll('.layer-list-qa')
+ .data([0]);
+
+ ul = ul.enter()
+ .append('ul')
+ .attr('class', 'layer-list layer-list-qa')
+ .merge(ul);
+
+ var li = ul.selectAll('.list-item')
+ .data(qaLayers);
+
+ li.exit()
+ .remove();
+
+ var liEnter = li.enter()
+ .append('li')
+ .attr('class', function(d) { return 'list-item list-item-' + d.id; });
+
+ var labelEnter = liEnter
+ .append('label')
+ .each(function(d) {
+ select(this)
+ .call(uiTooltip()
+ .title(_t('map_data.layers.' + d.id + '.tooltip'))
+ .placement('bottom')
+ );
+ });
+
+ labelEnter
+ .append('input')
+ .attr('type', 'checkbox')
+ .on('change', function(d) { toggleLayer(d.id); });
+
+ labelEnter
+ .append('span')
+ .text(function(d) { return _t('map_data.layers.' + d.id + '.title'); });
+
+
+ // Update
+ li
+ .merge(liEnter)
+ .classed('active', function (d) { return d.layer.enabled(); })
+ .selectAll('input')
+ .property('checked', function (d) { return d.layer.enabled(); });
+ }
+
+ // Beta feature - sample vector layers to support Detroit Mapping Challenge
+ // https://github.com/osmus/detroit-mapping-challenge
+ function drawVectorItems(selection) {
+ var dataLayer = layers.layer('data');
+ var vtData = [
+ {
+ name: 'Detroit Neighborhoods/Parks',
+ src: 'neighborhoods-parks',
+ tooltip: 'Neighborhood boundaries and parks as compiled by City of Detroit in concert with community groups.',
+ template: 'https://{switch:a,b,c,d}.tiles.mapbox.com/v4/jonahadkins.cjksmur6x34562qp9iv1u3ksf-54hev,jonahadkins.cjksmqxdx33jj2wp90xd9x2md-4e5y2/{z}/{x}/{y}.vector.pbf?access_token=pk.eyJ1Ijoiam9uYWhhZGtpbnMiLCJhIjoiRlVVVkx3VSJ9.9sdVEK_B_VkEXPjssU5MqA'
+ }, {
+ name: 'Detroit Composite POIs',
+ src: 'composite-poi',
+ tooltip: 'Fire Inspections, Business Licenses, and other public location data collated from the City of Detroit.',
+ template: 'https://{switch:a,b,c,d}.tiles.mapbox.com/v4/jonahadkins.cjksmm6a02sli31myxhsr7zf3-2sw8h/{z}/{x}/{y}.vector.pbf?access_token=pk.eyJ1Ijoiam9uYWhhZGtpbnMiLCJhIjoiRlVVVkx3VSJ9.9sdVEK_B_VkEXPjssU5MqA'
+ }, {
+ name: 'Detroit All-The-Places POIs',
+ src: 'alltheplaces-poi',
+ tooltip: 'Public domain business location data created by web scrapers.',
+ template: 'https://{switch:a,b,c,d}.tiles.mapbox.com/v4/jonahadkins.cjksmswgk340g2vo06p1w9w0j-8fjjc/{z}/{x}/{y}.vector.pbf?access_token=pk.eyJ1Ijoiam9uYWhhZGtpbnMiLCJhIjoiRlVVVkx3VSJ9.9sdVEK_B_VkEXPjssU5MqA'
+ }
+ ];
+
+ // Only show this if the map is around Detroit..
+ var detroit = geoExtent([-83.5, 42.1], [-82.8, 42.5]);
+ var showVectorItems = (context.map().zoom() > 9 && detroit.contains(context.map().center()));
+
+ var container = selection.selectAll('.vectortile-container')
+ .data(showVectorItems ? [0] : []);
+
+ container.exit()
+ .remove();
+
+ var containerEnter = container.enter()
+ .append('div')
+ .attr('class', 'vectortile-container');
+
+ containerEnter
+ .append('h4')
+ .attr('class', 'vectortile-header')
+ .text('Detroit Vector Tiles (Beta)');
+
+ containerEnter
+ .append('ul')
+ .attr('class', 'layer-list layer-list-vectortile');
+
+ containerEnter
+ .append('div')
+ .attr('class', 'vectortile-footer')
+ .append('a')
+ .attr('target', '_blank')
+ .attr('tabindex', -1)
+ .call(svgIcon('#iD-icon-out-link', 'inline'))
+ .attr('href', 'https://github.com/osmus/detroit-mapping-challenge')
+ .append('span')
+ .text('About these layers');
+
+ container = container
+ .merge(containerEnter);
+
+
+ var ul = container.selectAll('.layer-list-vectortile');
+
+ var li = ul.selectAll('.list-item')
+ .data(vtData);
+
+ li.exit()
+ .remove();
+
+ var liEnter = li.enter()
+ .append('li')
+ .attr('class', function(d) { return 'list-item list-item-' + d.src; });
+
+ var labelEnter = liEnter
+ .append('label')
+ .each(function(d) {
+ select(this).call(
+ uiTooltip().title(d.tooltip).placement('top')
+ );
+ });
+
+ labelEnter
+ .append('input')
+ .attr('type', 'radio')
+ .attr('name', 'vectortile')
+ .on('change', selectVTLayer);
+
+ labelEnter
+ .append('span')
+ .text(function(d) { return d.name; });
+
+ // Update
+ li
+ .merge(liEnter)
+ .classed('active', isVTLayerSelected)
+ .selectAll('input')
+ .property('checked', isVTLayerSelected);
+
+
+ function isVTLayerSelected(d) {
+ return dataLayer && dataLayer.template() === d.template;
+ }
+
+ function selectVTLayer(d) {
+ corePreferences('settings-custom-data-url', d.template);
+ if (dataLayer) {
+ dataLayer.template(d.template, d.src);
+ dataLayer.enabled(true);
+ }
+ }
+ }
+
+ function drawCustomDataItems(selection) {
+ var dataLayer = layers.layer('data');
+ var hasData = dataLayer && dataLayer.hasData();
+ var showsData = hasData && dataLayer.enabled();
+
+ var ul = selection
+ .selectAll('.layer-list-data')
+ .data(dataLayer ? [0] : []);
+
+ // Exit
+ ul.exit()
+ .remove();
+
+ // Enter
+ var ulEnter = ul.enter()
+ .append('ul')
+ .attr('class', 'layer-list layer-list-data');
+
+ var liEnter = ulEnter
+ .append('li')
+ .attr('class', 'list-item-data');
+
+ var labelEnter = liEnter
+ .append('label')
+ .call(uiTooltip()
+ .title(_t('map_data.layers.custom.tooltip'))
+ .placement('top')
+ );
+
+ labelEnter
+ .append('input')
+ .attr('type', 'checkbox')
+ .on('change', function() { toggleLayer('data'); });
+
+ labelEnter
+ .append('span')
+ .text(_t('map_data.layers.custom.title'));
+
+ liEnter
+ .append('button')
+ .call(uiTooltip()
+ .title(_t('settings.custom_data.tooltip'))
+ .placement((_mainLocalizer.textDirection() === 'rtl') ? 'right' : 'left')
+ )
+ .on('click', editCustom)
+ .call(svgIcon('#iD-icon-more'));
+
+ liEnter
+ .append('button')
+ .call(uiTooltip()
+ .title(_t('map_data.layers.custom.zoom'))
+ .placement((_mainLocalizer.textDirection() === 'rtl') ? 'right' : 'left')
+ )
+ .on('click', function() {
+ event.preventDefault();
+ event.stopPropagation();
+ dataLayer.fitZoom();
+ })
+ .call(svgIcon('#iD-icon-framed-dot'));
+
+ // Update
+ ul = ul
+ .merge(ulEnter);
+
+ ul.selectAll('.list-item-data')
+ .classed('active', showsData)
+ .selectAll('label')
+ .classed('deemphasize', !hasData)
+ .selectAll('input')
+ .property('disabled', !hasData)
+ .property('checked', showsData);
+ }
+
+ function editCustom() {
+ event.preventDefault();
+ context.container()
+ .call(settingsCustomData);
+ }
+
+ function customChanged(d) {
+ var dataLayer = layers.layer('data');
+
+ if (d && d.url) {
+ dataLayer.url(d.url);
+ } else if (d && d.fileList) {
+ dataLayer.fileList(d.fileList);
+ }
+ }
+
+
+ function drawPanelItems(selection) {
+
+ var panelsListEnter = selection.selectAll('.md-extras-list')
+ .data([0])
+ .enter()
+ .append('ul')
+ .attr('class', 'layer-list md-extras-list');
+
+ var historyPanelLabelEnter = panelsListEnter
+ .append('li')
+ .attr('class', 'history-panel-toggle-item')
+ .append('label')
+ .call(uiTooltip()
+ .title(_t('map_data.history_panel.tooltip'))
+ .keys([uiCmd('⌘⇧' + _t('info_panels.history.key'))])
+ .placement('top')
+ );
+
+ historyPanelLabelEnter
+ .append('input')
+ .attr('type', 'checkbox')
+ .on('change', function() {
+ event.preventDefault();
+ context.ui().info.toggle('history');
+ });
+
+ historyPanelLabelEnter
+ .append('span')
+ .text(_t('map_data.history_panel.title'));
+
+ var measurementPanelLabelEnter = panelsListEnter
+ .append('li')
+ .attr('class', 'measurement-panel-toggle-item')
+ .append('label')
+ .call(uiTooltip()
+ .title(_t('map_data.measurement_panel.tooltip'))
+ .keys([uiCmd('⌘⇧' + _t('info_panels.measurement.key'))])
+ .placement('top')
+ );
+
+ measurementPanelLabelEnter
+ .append('input')
+ .attr('type', 'checkbox')
+ .on('change', function() {
+ event.preventDefault();
+ context.ui().info.toggle('measurement');
+ });
+
+ measurementPanelLabelEnter
+ .append('span')
+ .text(_t('map_data.measurement_panel.title'));
+ }
+
+ context.layers().on('change.uiSectionDataLayers', section.reRender);
+
+ context.map()
+ .on('move.uiSectionDataLayers',
+ debounce(function() {
+ // Detroit layers may have moved in or out of view
+ window.requestIdleCallback(section.reRender);
+ }, 1000)
+ );
+
+ return section;
+ }
+
+ function uiSectionMapFeatures(context) {
+
+ var _features = context.features().keys();
+
+ var section = uiSection('map-features', context)
+ .title(_t('map_data.map_features'))
+ .disclosureContent(renderDisclosureContent)
+ .expandedByDefault(false);
+
+ function renderDisclosureContent(selection) {
+
+ var container = selection.selectAll('.layer-feature-list-container')
+ .data([0]);
+
+ var containerEnter = container.enter()
+ .append('div')
+ .attr('class', 'layer-feature-list-container');
+
+ containerEnter
+ .append('ul')
+ .attr('class', 'layer-list layer-feature-list');
+
+ var footer = containerEnter
+ .append('div')
+ .attr('class', 'feature-list-links section-footer');
+
+ footer
+ .append('a')
+ .attr('class', 'feature-list-link')
+ .attr('href', '#')
+ .text(_t('issues.enable_all'))
+ .on('click', function() {
+ context.features().enableAll();
+ });
+
+ footer
+ .append('a')
+ .attr('class', 'feature-list-link')
+ .attr('href', '#')
+ .text(_t('issues.disable_all'))
+ .on('click', function() {
+ context.features().disableAll();
+ });
+
+ // Update
+ container = container
+ .merge(containerEnter);
+
+ container.selectAll('.layer-feature-list')
+ .call(drawListItems, _features, 'checkbox', 'feature', clickFeature, showsFeature);
+ }
+
+ function drawListItems(selection, data, type, name, change, active) {
+ var items = selection.selectAll('li')
+ .data(data);
+
+ // Exit
+ items.exit()
+ .remove();
+
+ // Enter
+ var enter = items.enter()
+ .append('li')
+ .call(uiTooltip()
+ .title(function(d) {
+ var tip = _t(name + '.' + d + '.tooltip');
+ if (autoHiddenFeature(d)) {
+ var msg = showsLayer('osm') ? _t('map_data.autohidden') : _t('map_data.osmhidden');
+ tip += '' + msg + '
';
+ }
+ return tip;
+ })
+ .placement('top')
+ );
+
+ var label = enter
+ .append('label');
+
+ label
+ .append('input')
+ .attr('type', type)
+ .attr('name', name)
+ .on('change', change);
+
+ label
+ .append('span')
+ .text(function(d) { return _t(name + '.' + d + '.description'); });
+
+ // Update
+ items = items
+ .merge(enter);
+
+ items
+ .classed('active', active)
+ .selectAll('input')
+ .property('checked', active)
+ .property('indeterminate', autoHiddenFeature);
+ }
+
+ function autoHiddenFeature(d) {
+ return context.features().autoHidden(d);
+ }
+
+ function showsFeature(d) {
+ return context.features().enabled(d);
+ }
+
+ function clickFeature(d) {
+ context.features().toggle(d);
+ }
+
+ function showsLayer(id) {
+ var layer = context.layers().layer(id);
+ return layer && layer.enabled();
+ }
+
+ // add listeners
+ context.features()
+ .on('change.map_features', section.reRender);
+
+ return section;
+ }
+
+ function uiSectionMapStyleOptions(context) {
+
+ var section = uiSection('fill-area', context)
+ .title(_t('map_data.style_options'))
+ .disclosureContent(renderDisclosureContent)
+ .expandedByDefault(false);
+
+ function renderDisclosureContent(selection) {
+ var container = selection.selectAll('.layer-fill-list')
+ .data([0]);
+
+ container.enter()
+ .append('ul')
+ .attr('class', 'layer-list layer-fill-list')
+ .merge(container)
+ .call(drawListItems, context.map().areaFillOptions, 'radio', 'area_fill', setFill, isActiveFill);
+
+ var container2 = selection.selectAll('.layer-visual-diff-list')
+ .data([0]);
+
+ container2.enter()
+ .append('ul')
+ .attr('class', 'layer-list layer-visual-diff-list')
+ .merge(container2)
+ .call(drawListItems, ['highlight_edits'], 'checkbox', 'visual_diff', toggleHighlightEdited, function() {
+ return context.surface().classed('highlight-edited');
+ });
+ }
+
+ function drawListItems(selection, data, type, name, change, active) {
+ var items = selection.selectAll('li')
+ .data(data);
+
+ // Exit
+ items.exit()
+ .remove();
+
+ // Enter
+ var enter = items.enter()
+ .append('li')
+ .call(uiTooltip()
+ .title(function(d) {
+ return _t(name + '.' + d + '.tooltip');
+ })
+ .keys(function(d) {
+ var key = (d === 'wireframe' ? _t('area_fill.wireframe.key') : null);
+ if (d === 'highlight_edits') key = _t('map_data.highlight_edits.key');
+ return key ? [key] : null;
+ })
+ .placement('top')
+ );
+
+ var label = enter
+ .append('label');
+
+ label
+ .append('input')
+ .attr('type', type)
+ .attr('name', name)
+ .on('change', change);
+
+ label
+ .append('span')
+ .text(function(d) { return _t(name + '.' + d + '.description'); });
+
+ // Update
+ items = items
+ .merge(enter);
+
+ items
+ .classed('active', active)
+ .selectAll('input')
+ .property('checked', active)
+ .property('indeterminate', false);
+ }
+
+ function isActiveFill(d) {
+ return context.map().activeAreaFill() === d;
+ }
+
+ function toggleHighlightEdited() {
+ event.preventDefault();
+ context.map().toggleHighlightEdited();
+ }
+
+ function setFill(d) {
+ context.map().activeAreaFill(d);
+ }
+
+ context.map()
+ .on('changeHighlighting.ui_style, changeAreaFill.ui_style', section.reRender);
+
+ return section;
+ }
+
+ function uiSectionPhotoOverlays(context) {
+
+ var layers = context.layers();
+
+ var section = uiSection('photo-overlays', context)
+ .title(_t('photo_overlays.title'))
+ .disclosureContent(renderDisclosureContent)
+ .expandedByDefault(false);
+
+ function renderDisclosureContent(selection) {
+ var container = selection.selectAll('.photo-overlay-container')
+ .data([0]);
+
+ container.enter()
+ .append('div')
+ .attr('class', 'photo-overlay-container')
+ .merge(container)
+ .call(drawPhotoItems)
+ .call(drawPhotoTypeItems);
+ }
+
+ function drawPhotoItems(selection) {
+ var photoKeys = context.photos().overlayLayerIDs();
+ var photoLayers = layers.all().filter(function(obj) { return photoKeys.indexOf(obj.id) !== -1; });
+ var data = photoLayers.filter(function(obj) { return obj.layer.supported(); });
+
+ function layerSupported(d) {
+ return d.layer && d.layer.supported();
+ }
+ function layerEnabled(d) {
+ return layerSupported(d) && d.layer.enabled();
+ }
+
+ var ul = selection
+ .selectAll('.layer-list-photos')
+ .data([0]);
+
+ ul = ul.enter()
+ .append('ul')
+ .attr('class', 'layer-list layer-list-photos')
+ .merge(ul);
+
+ var li = ul.selectAll('.list-item-photos')
+ .data(data);
+
+ li.exit()
+ .remove();
+
+ var liEnter = li.enter()
+ .append('li')
+ .attr('class', function(d) {
+ var classes = 'list-item-photos list-item-' + d.id;
+ if (d.id === 'mapillary-signs' || d.id === 'mapillary-map-features') {
+ classes += ' indented';
+ }
+ return classes;
+ });
+
+ var labelEnter = liEnter
+ .append('label')
+ .each(function(d) {
+ var titleID;
+ if (d.id === 'mapillary-signs') titleID = 'mapillary.signs.tooltip';
+ else if (d.id === 'mapillary') titleID = 'mapillary_images.tooltip';
+ else if (d.id === 'openstreetcam') titleID = 'openstreetcam_images.tooltip';
+ else titleID = d.id.replace(/-/g, '_') + '.tooltip';
+ select(this)
+ .call(uiTooltip()
+ .title(_t(titleID))
+ .placement('top')
+ );
+ });
+
+ labelEnter
+ .append('input')
+ .attr('type', 'checkbox')
+ .on('change', function(d) { toggleLayer(d.id); });
+
+ labelEnter
+ .append('span')
+ .text(function(d) {
+ var id = d.id;
+ if (id === 'mapillary-signs') id = 'photo_overlays.traffic_signs';
+ return _t(id.replace(/-/g, '_') + '.title');
+ });
+
+
+ // Update
+ li
+ .merge(liEnter)
+ .classed('active', layerEnabled)
+ .selectAll('input')
+ .property('checked', layerEnabled);
+ }
+
+ function drawPhotoTypeItems(selection) {
+ var data = context.photos().allPhotoTypes();
+
+ function typeEnabled(d) {
+ return context.photos().showsPhotoType(d);
+ }
+
+ var ul = selection
+ .selectAll('.layer-list-photo-types')
+ .data(context.photos().shouldFilterByPhotoType() ? [0] : []);
+
+ ul.exit()
+ .remove();
+
+ ul = ul.enter()
+ .append('ul')
+ .attr('class', 'layer-list layer-list-photo-types')
+ .merge(ul);
+
+ var li = ul.selectAll('.list-item-photo-types')
+ .data(data);
+
+ li.exit()
+ .remove();
+
+ var liEnter = li.enter()
+ .append('li')
+ .attr('class', function(d) {
+ return 'list-item-photo-types list-item-' + d;
+ });
+
+ var labelEnter = liEnter
+ .append('label')
+ .each(function(d) {
+ select(this)
+ .call(uiTooltip()
+ .title(_t('photo_overlays.photo_type.' + d + '.tooltip'))
+ .placement('top')
+ );
+ });
+
+ labelEnter
+ .append('input')
+ .attr('type', 'checkbox')
+ .on('change', function(d) {
+ context.photos().togglePhotoType(d);
+ });
+
+ labelEnter
+ .append('span')
+ .text(function(d) {
+ return _t('photo_overlays.photo_type.' + d + '.title');
+ });
+
+
+ // Update
+ li
+ .merge(liEnter)
+ .classed('active', typeEnabled)
+ .selectAll('input')
+ .property('checked', typeEnabled);
+ }
+
+ function toggleLayer(which) {
+ setLayer(which, !showsLayer(which));
+ }
+
+ function showsLayer(which) {
+ var layer = layers.layer(which);
+ if (layer) {
+ return layer.enabled();
+ }
+ return false;
+ }
+
+ function setLayer(which, enabled) {
+ var layer = layers.layer(which);
+ if (layer) {
+ layer.enabled(enabled);
+ }
+ }
+
+ context.layers().on('change.uiSectionPhotoOverlays', section.reRender);
+ context.photos().on('change.uiSectionPhotoOverlays', section.reRender);
+
+ return section;
+ }
+
+ function uiPaneMapData(context) {
+
+ var mapDataPane = uiPane('map-data', context)
+ .key(_t('map_data.key'))
+ .title(_t('map_data.title'))
+ .description(_t('map_data.description'))
+ .iconName('iD-icon-data')
+ .sections([
+ uiSectionDataLayers(context),
+ uiSectionPhotoOverlays(context),
+ uiSectionMapStyleOptions(context),
+ uiSectionMapFeatures(context)
+ ]);
+
+ return mapDataPane;
+ }
+
+ function uiSectionPrivacy(context) {
+
+ let section = uiSection('preferences-third-party', context)
+ .title(_t('preferences.privacy.title'))
+ .disclosureContent(renderDisclosureContent);
+
+ let _showThirdPartyIcons = corePreferences('preferences.privacy.thirdpartyicons') || 'true';
+
+ function renderDisclosureContent(selection) {
+ // enter
+ let privacyOptionsListEnter = selection.selectAll('.privacy-options-list')
+ .data([0])
+ .enter()
+ .append('ul')
+ .attr('class', 'layer-list privacy-options-list');
+
+ let thirdPartyIconsEnter = privacyOptionsListEnter
+ .append('li')
+ .attr('class', 'privacy-third-party-icons-item')
+ .append('label')
+ .call(uiTooltip()
+ .title(_t('preferences.privacy.third_party_icons.tooltip'))
+ .placement('bottom')
+ );
+
+ thirdPartyIconsEnter
+ .append('input')
+ .attr('type', 'checkbox')
+ .on('change', () => {
+ event.preventDefault();
+ _showThirdPartyIcons = (_showThirdPartyIcons === 'true') ? 'false' : 'true';
+ corePreferences('preferences.privacy.thirdpartyicons', _showThirdPartyIcons);
+ update();
+ });
+
+ thirdPartyIconsEnter
+ .append('span')
+ .text(_t('preferences.privacy.third_party_icons.description'));
+
+
+ // Privacy Policy link
+ selection.selectAll('.privacy-link')
+ .data([0])
+ .enter()
+ .append('div')
+ .attr('class', 'privacy-link')
+ .append('a')
+ .attr('target', '_blank')
+ .call(svgIcon('#iD-icon-out-link', 'inline'))
+ .attr('href', 'https://github.com/openstreetmap/iD/blob/release/PRIVACY.md')
+ .append('span')
+ .text(_t('preferences.privacy.privacy_link'));
+
+ update();
+
+
+ function update() {
+ selection.selectAll('.privacy-third-party-icons-item')
+ .classed('active', (_showThirdPartyIcons === 'true'))
+ .select('input')
+ .property('checked', (_showThirdPartyIcons === 'true'));
+ }
+ }
+
+ return section;
+ }
+
+ function uiPanePreferences(context) {
+
+ let preferencesPane = uiPane('preferences', context)
+ .key(_t('preferences.key'))
+ .title(_t('preferences.title'))
+ .description(_t('preferences.description'))
+ .iconName('fas-user-cog')
+ .sections([
+ uiSectionPrivacy(context)
+ ]);
+
+ return preferencesPane;
+ }
+
+ function uiRapidServiceLicense() {
+ return function(selection) {
+ selection.append('a')
+ .attr('href', 'https://mapwith.ai/doc/license/MapWithAILicense.pdf')
+ .attr('target', '_blank')
+ .text(_t('rapid_feature_license'));
+ };
+ }
+
+ function uiInit(context) {
+ var _initCounter = 0;
+ var _needWidth = {};
+
+ var _lastPointerType;
+
+
+ function render(container) {
+
+ container
+ .on('click.ui', function() {
+ // we're only concerned with the primary mouse button
+ if (event.button !== 0) return;
+
+ if (!event.composedPath) return;
+
+ // some targets have default click events we don't want to override
+ var isOkayTarget = event.composedPath().some(function(node) {
+ // we only care about element nodes
+ return node.nodeType === 1 &&
+ // clicking focuses it and/or changes a value
+ (node.nodeName === 'INPUT' ||
+ // clicking affects its by default
+ node.nodeName === 'LABEL' ||
+ // clicking opens a hyperlink by default
+ node.nodeName === 'A');
+ });
+ if (isOkayTarget) return;
+
+ // disable double-tap-to-zoom on touchscreens
+ event.preventDefault();
+ });
+
+ var detected = utilDetect();
+
+ // only WebKit supports gesture events
+ if ('GestureEvent' in window &&
+ // Listening for gesture events on iOS 13.4+ breaks double-tapping,
+ // but we only need to do this on desktop Safari anyway. – #7694
+ !detected.isMobileWebKit) {
+
+ // On iOS we disable pinch-to-zoom of the UI via the `touch-action`
+ // CSS property, but on desktop Safari we need to manually cancel the
+ // default gesture events.
+ container.on('gesturestart.ui gesturechange.ui gestureend.ui', function() {
+ // disable pinch-to-zoom of the UI via multitouch trackpads on macOS Safari
+ event.preventDefault();
+ });
+ }
+
+ if ('PointerEvent' in window) {
+ select(window)
+ .on('pointerdown.ui pointerup.ui', function() {
+ var pointerType = event.pointerType || 'mouse';
+ if (_lastPointerType !== pointerType) {
+ _lastPointerType = pointerType;
+ container
+ .attr('pointer', pointerType);
+ }
+ }, true);
+ } else {
+ _lastPointerType = 'mouse';
+ container
+ .attr('pointer', 'mouse');
+ }
+
+ container
+ .attr('dir', _mainLocalizer.textDirection());
+
+ // setup fullscreen keybindings (no button shown at this time)
+ container
+ .call(uiFullScreen(context));
+
+ var map = context.map();
+ map.redrawEnable(false); // don't draw until we've set zoom/lat/long
+
+ map
+ .on('hitMinZoom.ui', function() {
+ ui.flash.text(_t('cannot_zoom'))();
+ });
+
+ container
+ .append('svg')
+ .attr('id', 'ideditor-defs')
+ .call(svgDefs(context));
+
+ container
+ .append('div')
+ .attr('class', 'sidebar')
+ .call(ui.sidebar);
+
+ var content = container
+ .append('div')
+ .attr('class', 'main-content active');
+
+ // Top toolbar
+ content
+ .append('div')
+ .attr('class', 'top-toolbar-wrap')
+ .append('div')
+ .attr('class', 'top-toolbar fillD')
+ .call(uiTopToolbar(context));
+
+ content
+ .append('div')
+ .attr('class', 'main-map')
+ .attr('dir', 'ltr')
+ .call(map);
+
+ content
+ .append('div')
+ .attr('class', 'spinner')
+ .call(uiSpinner(context));
+
+ // Add attribution and footer
+ var about = content
+ .append('div')
+ .attr('class', 'map-footer');
+
+ about
+ .append('div')
+ .attr('class', 'attribution-wrap')
+ .attr('dir', 'ltr')
+ .call(uiAttribution(context));
+
+ about
+ .append('div')
+ .attr('class', 'api-status')
+ .call(uiStatus(context));
+
+
+ var footer = about
+ .append('div')
+ .attr('class', 'map-footer-bar fillD');
+
+ footer
+ .append('div')
+ .attr('class', 'flash-wrap footer-hide');
+
+ var footerWrap = footer
+ .append('div')
+ .attr('class', 'main-footer-wrap footer-show');
+
+ footerWrap
+ .append('div')
+ .attr('class', 'scale-block')
+ .call(uiScale(context));
+
+ var aboutList = footerWrap
+ .append('div')
+ .attr('class', 'info-block')
+ .append('ul')
+ .attr('class', 'map-footer-list');
+
+ if (!context.embed()) {
+ aboutList
+ .call(uiAccount(context));
+ }
+
+ aboutList
+ .append('li')
+ .attr('class', 'version')
+ .call(uiVersion(context));
+
+ var issueLinks = aboutList
+ .append('li');
+
+ issueLinks
+ .append('a')
+ .attr('target', '_blank')
+ .attr('tabindex', -1)
+ .attr('href', 'https://github.com/facebookincubator/RapiD/issues')
+ .call(svgIcon('#iD-icon-bug', 'light'))
+ .call(uiTooltip().title(_t('report_a_bug')).placement('top'));
+
+ issueLinks
+ .append('a')
+ .attr('target', '_blank')
+ .attr('href', 'https://github.com/openstreetmap/iD/blob/develop/CONTRIBUTING.md#translating')
+ .call(svgIcon('#iD-icon-translate', 'light'))
+ .call(uiTooltip().title(_t('help_translate')).placement('top'));
+
+ aboutList
+ .append('li')
+ .attr('class', 'feature-warning')
+ .attr('tabindex', -1)
+ .call(uiFeatureInfo(context));
+
+ aboutList
+ .append('li')
+ .attr('class', 'issues-info')
+ .attr('tabindex', -1)
+ .call(uiIssuesInfo(context));
+
+ var apiConnections = context.apiConnections();
+ if (apiConnections && apiConnections.length > 1) {
+ aboutList
+ .append('li')
+ .attr('class', 'source-switch')
+ .attr('tabindex', -1)
+ .call(uiSourceSwitch(context)
+ .keys(apiConnections)
+ );
+ }
+
+ aboutList
+ .append('li')
+ .attr('class', 'user-list')
+ .attr('tabindex', -1)
+ .call(uiContributors(context));
+
+ aboutList
+ .append('li')
+ .attr('class', 'fb-road-license')
+ .attr('tabindex', -1)
+ .call(uiRapidServiceLicense());
+
+
+ // Setup map dimensions and move map to initial center/zoom.
+ // This should happen after .main-content and toolbars exist.
+ ui.onResize();
+ map.redrawEnable(true);
+
+ ui.hash = behaviorHash(context);
+ ui.hash();
+ if (!ui.hash.hadHash) {
+ map.centerZoom([0, 0], 2);
+ }
+
+
+ var overMap = content
+ .append('div')
+ .attr('class', 'over-map');
+
+ // Map controls
+ var controls = overMap
+ .append('div')
+ .attr('class', 'map-controls');
+
+ controls
+ .append('div')
+ .attr('class', 'map-control zoombuttons')
+ .call(uiZoom(context));
+
+ controls
+ .append('div')
+ .attr('class', 'map-control zoom-to-selection-control')
+ .call(uiZoomToSelection(context));
+
+ controls
+ .append('div')
+ .attr('class', 'map-control geolocate-control')
+ .call(uiGeolocate(context));
+
+ // Add panes
+ // This should happen after map is initialized, as some require surface()
+ var panes = overMap
+ .append('div')
+ .attr('class', 'map-panes');
+
+ var uiPanes = [
+ uiPaneBackground(context),
+ uiPaneMapData(context),
+ uiPaneIssues(context),
+ uiPanePreferences(context),
+ uiPaneHelp(context)
+ ];
+
+ uiPanes.forEach(function(pane) {
+ controls
+ .append('div')
+ .attr('class', 'map-control map-pane-control ' + pane.id + '-control')
+ .call(pane.renderToggleButton);
+
+ panes
+ .call(pane.renderPane);
+ });
+
+ ui.info = uiInfo(context);
+
+ // Add absolutely-positioned elements that sit on top of the map
+ // This should happen after the map is ready (center/zoom)
+ overMap
+ .call(uiMapInMap(context))
+ .call(ui.info)
+ .call(uiNotice(context));
+
+
+ overMap
+ .append('div')
+ .attr('class', 'photoviewer')
+ .classed('al', true) // 'al'=left, 'ar'=right
+ .classed('hide', true)
+ .call(ui.photoviewer);
+
+
+ // Bind events
+ window.onbeforeunload = function() {
+ return context.save();
+ };
+ window.onunload = function() {
+ context.history().unlock();
+ };
+
+ select(window)
+ .on('resize.editor', ui.onResize);
+
+
+ var panPixels = 80;
+ context.keybinding()
+ .on('⌫', function() { event.preventDefault(); })
+ .on([_t('sidebar.key'), '`', '²', '@'], ui.sidebar.toggle) // #5663, #6864 - common QWERTY, AZERTY
+ .on('←', pan([panPixels, 0]))
+ .on('↑', pan([0, panPixels]))
+ .on('→', pan([-panPixels, 0]))
+ .on('↓', pan([0, -panPixels]))
+ .on(uiCmd('⌘←'), pan([map.dimensions()[0], 0]))
+ .on(uiCmd('⌘↑'), pan([0, map.dimensions()[1]]))
+ .on(uiCmd('⌘→'), pan([-map.dimensions()[0], 0]))
+ .on(uiCmd('⌘↓'), pan([0, -map.dimensions()[1]]))
+ .on(uiCmd('⌘' + _t('background.key')), function quickSwitch() {
+ if (event) {
+ event.stopImmediatePropagation();
+ event.preventDefault();
+ }
+ var previousBackground = context.background().findSource(corePreferences('background-last-used-toggle'));
+ if (previousBackground) {
+ var currentBackground = context.background().baseLayerSource();
+ corePreferences('background-last-used-toggle', currentBackground.id);
+ corePreferences('background-last-used', previousBackground.id);
+ context.background().baseLayerSource(previousBackground);
+ }
+ })
+ .on(_t('area_fill.wireframe.key'), function toggleWireframe() {
+ event.preventDefault();
+ event.stopPropagation();
+ context.map().toggleWireframe();
+ })
+ .on(uiCmd('⌥' + _t('area_fill.wireframe.key')), function toggleOsmData() {
+ event.preventDefault();
+ event.stopPropagation();
+
+ // Don't allow layer changes while drawing - #6584
+ var mode = context.mode();
+ if (mode && /^draw/.test(mode.id)) return;
+
+ var layer = context.layers().layer('osm');
+ if (layer) {
+ layer.enabled(!layer.enabled());
+ if (!layer.enabled()) {
+ context.enter(modeBrowse(context));
+ }
+ }
+ })
+ .on(_t('map_data.highlight_edits.key'), function toggleHighlightEdited() {
+ event.preventDefault();
+ context.map().toggleHighlightEdited();
+ });
+
+ context
+ .on('enter.editor', function(entered) {
+ container
+ .classed('mode-' + entered.id, true);
+ })
+ .on('exit.editor', function(exited) {
+ container
+ .classed('mode-' + exited.id, false);
+ });
+
+ context.enter(modeBrowse(context));
+
+ var osm = context.connection();
+
+ if (!_initCounter++) {
+ if (!ui.hash.startWalkthrough) {
+ if (context.history().lock() && context.history().hasRestorableChanges()) {
+ context.container()
+ .call(uiRestore(context));
+
+ // // If users have already seen the 'welcome to RapiD' splash screen, don't also
+ // // show them the what's new screen
+ // } else if (prefs('sawRapidSplash')) {
+ // context.container()
+ // .call(uiRapidWhatsNew(context));
+ } else if (osm.authenticated()) {
+ context.container()
+ .call(uiRapidSplash(context));
+ }
+ }
+
+ context.container()
+ .call(uiShortcuts(context));
+ }
+
+ var auth = uiLoading(context).message(_t('loading_auth')).blocking(true);
+
+ if (osm && auth) {
+ osm
+ .on('authLoading.ui', function() {
+ context.container()
+ .call(auth);
+ })
+ .on('authDone.ui', function() {
+ auth.close();
+ });
+ }
+
+ _initCounter++;
+
+ if (ui.hash.startWalkthrough) {
+ ui.hash.startWalkthrough = false;
+ context.container().call(uiIntro(context));
+ }
+
+
+ function pan(d) {
+ return function() {
+ if (event.shiftKey) return;
+ if (context.container().select('.combobox').size()) return;
+ event.preventDefault();
+ context.map().pan(d, 100);
+ };
+ }
+
+ }
+
+
+ let ui = {};
+
+ let _loadPromise;
+ // renders the iD interface into the container node
+ ui.ensureLoaded = () => {
+
+ if (_loadPromise) return _loadPromise;
+
+ return _loadPromise = Promise.all([
+ // must have strings and presets before loading the UI
+ _mainLocalizer.ensureLoaded(),
+ _mainPresetIndex.ensureLoaded()
+ ])
+ .then(() => {
+ if (!context.container().empty()) render(context.container());
+ })
+ .catch(err => console.error(err)); // eslint-disable-line
+ };
+
+
+ // `ui.restart()` will destroy and rebuild the entire iD interface,
+ // for example to switch the locale while iD is running.
+ ui.restart = function() {
+ context.keybinding().clear();
+
+ _loadPromise = null;
+
+ context.container().selectAll('*').remove();
+
+ ui.ensureLoaded();
+ };
+
+ ui.lastPointerType = function() {
+ return _lastPointerType;
+ };
+
+ ui.flash = uiFlash(context);
+
+ ui.sidebar = uiSidebar(context);
+
+ ui.photoviewer = uiPhotoviewer(context);
+
+ ui.onResize = function(withPan) {
+ var map = context.map();
+
+ // Recalc dimensions of map and sidebar.. (`true` = force recalc)
+ // This will call `getBoundingClientRect` and trigger reflow,
+ // but the values will be cached for later use.
+ var mapDimensions = utilGetDimensions(context.container().select('.main-content'), true);
+ utilGetDimensions(context.container().select('.sidebar'), true);
+
+ if (withPan !== undefined) {
+ map.redrawEnable(false);
+ map.pan(withPan);
+ map.redrawEnable(true);
+ }
+ map.dimensions(mapDimensions);
+
+ ui.photoviewer.onMapResize();
+
+ // check if header or footer have overflowed
+ ui.checkOverflow('.top-toolbar');
+ ui.checkOverflow('.map-footer-bar');
+
+ // Use outdated code so it works on Explorer
+ var resizeWindowEvent = document.createEvent('Event');
+
+ resizeWindowEvent.initEvent('resizeWindow', true, true);
+
+ document.dispatchEvent(resizeWindowEvent);
+ };
+
+
+ // Call checkOverflow when resizing or whenever the contents change.
+ ui.checkOverflow = function(selector, reset) {
+ if (reset) {
+ delete _needWidth[selector];
+ }
+
+ var element = select(selector);
+ var scrollWidth = element.property('scrollWidth');
+ var clientWidth = element.property('clientWidth');
+ var needed = _needWidth[selector] || scrollWidth;
+
+ if (scrollWidth > clientWidth) { // overflow happening
+ element.classed('narrow', true);
+ if (!_needWidth[selector]) {
+ _needWidth[selector] = scrollWidth;
+ }
+
+ } else if (scrollWidth >= needed) {
+ element.classed('narrow', false);
+ }
+ };
+
+ ui.togglePanes = function(showPane) {
+ var shownPanes = context.container().selectAll('.map-pane.shown');
+
+ var side = _mainLocalizer.textDirection() === 'ltr' ? 'right' : 'left';
+
+ shownPanes
+ .classed('shown', false);
+
+ context.container().selectAll('.map-pane-control button')
+ .classed('active', false);
+
+ if (showPane) {
+ shownPanes
+ .style('display', 'none')
+ .style(side, '-500px');
+
+ context.container().selectAll('.' + showPane.attr('pane') + '-control button')
+ .classed('active', true);
+
+ showPane
+ .classed('shown', true)
+ .style('display', 'block');
+ if (shownPanes.empty()) {
+ showPane
+ .style('display', 'block')
+ .style(side, '-500px')
+ .transition()
+ .duration(200)
+ .style(side, '0px');
+ } else {
+ showPane
+ .style(side, '0px');
+ }
+ } else {
+ shownPanes
+ .style('display', 'block')
+ .style(side, '0px')
+ .transition()
+ .duration(200)
+ .style(side, '-500px')
+ .on('end', function() {
+ select(this).style('display', 'none');
+ });
+ }
+ };
+
+
+ var _editMenu = uiEditMenu(context);
+
+ ui.editMenu = function() {
+ return _editMenu;
+ };
+
+ ui.showEditMenu = function(anchorPoint, triggerType, operations) {
+
+ // remove any displayed menu
+ ui.closeEditMenu();
+
+ if (!operations && context.mode().operations) operations = context.mode().operations();
+ if (!operations || !operations.length) return;
+
+ // disable menu if in wide selection, for example
+ if (!context.map().editableDataEnabled()) return;
+
+ var surfaceNode = context.surface().node();
+ if (surfaceNode.focus) { // FF doesn't support it
+ // focus the surface or else clicking off the menu may not trigger modeBrowse
+ surfaceNode.focus();
+ }
+
+ operations.forEach(function(operation) {
+ if (operation.point) operation.point(anchorPoint);
+ });
+
+ _editMenu
+ .anchorLoc(anchorPoint)
+ .triggerType(triggerType)
+ .operations(operations);
+
+ // render the menu
+ context.map().supersurface.call(_editMenu);
+ };
+
+ ui.closeEditMenu = function() {
+ // remove any existing menu no matter how it was added
+ context.map().supersurface
+ .select('.edit-menu').remove();
+ };
+
+
+ var _saveLoading = select(null);
+
+ context.uploader()
+ .on('saveStarted.ui', function() {
+ _saveLoading = uiLoading(context)
+ .message(_t('save.uploading'))
+ .blocking(true);
+ context.container().call(_saveLoading); // block input during upload
+ })
+ .on('saveEnded.ui', function() {
+ _saveLoading.close();
+ _saveLoading = select(null);
+ });
+
+ return ui;
+ }
+
+ function uiLasso(context) {
+ var group, polygon;
+
+ lasso.coordinates = [];
+
+ function lasso(selection) {
+ context.container()
+ .classed('lasso', true);
+
+ group = selection
+ .append('g')
+ .attr('class', 'lasso hide');
+
+ polygon = group
+ .append('path')
+ .attr('class', 'lasso-path');
+
+ group
+ .call(uiToggle(true));
+ }
+
+
+ function draw() {
+ if (polygon) {
+ polygon.data([lasso.coordinates])
+ .attr('d', function(d) { return 'M' + d.join(' L') + ' Z'; });
+ }
+ }
+
+
+ lasso.extent = function () {
+ return lasso.coordinates.reduce(function(extent, point) {
+ return extent.extend(geoExtent(point));
+ }, geoExtent());
+ };
+
+
+ lasso.p = function(_) {
+ if (!arguments.length) return lasso;
+ lasso.coordinates.push(_);
+ draw();
+ return lasso;
+ };
+
+
+ lasso.close = function() {
+ if (group) {
+ group.call(uiToggle(false, function() {
+ select(this).remove();
+ }));
+ }
+ context.container().classed('lasso', false);
+ };
+
+
+ return lasso;
+ }
+
+ function uiSplash(context) {
+ return (selection) => {
+ // Exception - if there are restorable changes, skip this splash screen.
+ // This is because we currently only support one `uiModal` at a time
+ // and we need to show them `uiRestore`` instead of this one.
+ if (context.history().hasRestorableChanges()) return;
+
+ // If user has not seen this version of the privacy policy, show the splash again.
+ let updateMessage = '';
+ const sawPrivacyVersion = corePreferences('sawPrivacyVersion');
+ let showSplash = !corePreferences('sawSplash');
+ if (sawPrivacyVersion !== context.privacyVersion) {
+ updateMessage = _t('splash.privacy_update');
+ showSplash = true;
+ }
+
+ if (!showSplash) return;
+
+ corePreferences('sawSplash', true);
+ corePreferences('sawPrivacyVersion', context.privacyVersion);
+
+ // fetch intro graph data now, while user is looking at the splash screen
+ _mainFileFetcher.get('intro_graph');
+
+ let modalSelection = uiModal(selection);
+
+ modalSelection.select('.modal')
+ .attr('class', 'modal-splash modal');
+
+ let introModal = modalSelection.select('.content')
+ .append('div')
+ .attr('class', 'fillL');
+
+ introModal
+ .append('div')
+ .attr('class','modal-section')
+ .append('h3')
+ .text(_t('splash.welcome'));
+
+ let modalSection = introModal
+ .append('div')
+ .attr('class','modal-section');
+
+ modalSection
+ .append('p')
+ .html(_t('splash.text', {
+ version: context.version,
+ website: ' ideditor.blog ',
+ github: 'github.com '
+ }));
+
+ modalSection
+ .append('p')
+ .html(_t('splash.privacy', {
+ updateMessage: updateMessage,
+ privacyLink: '' +
+ _t('splash.privacy_policy') + ' '
+ }));
+
+ let buttonWrap = introModal
+ .append('div')
+ .attr('class', 'modal-actions');
+
+ let walkthrough = buttonWrap
+ .append('button')
+ .attr('class', 'walkthrough')
+ .on('click', () => {
+ context.container().call(uiIntro(context));
+ modalSelection.close();
+ });
+
+ walkthrough
+ .append('svg')
+ .attr('class', 'logo logo-walkthrough')
+ .append('use')
+ .attr('xlink:href', '#iD-logo-walkthrough');
+
+ walkthrough
+ .append('div')
+ .text(_t('splash.walkthrough'));
+
+ let startEditing = buttonWrap
+ .append('button')
+ .attr('class', 'start-editing')
+ .on('click', modalSelection.close);
+
+ startEditing
+ .append('svg')
+ .attr('class', 'logo logo-features')
+ .append('use')
+ .attr('xlink:href', '#iD-logo-features');
+
+ startEditing
+ .append('div')
+ .text(_t('splash.start'));
+
+ modalSelection.select('button.close')
+ .attr('class','hide');
+ };
+ }
+
+ function uiRapidWhatsNew(context) {
+ let _dontShowAgain = false;
+
+
+ return function(selection) {
+ if (corePreferences('sawWhatsNew') === 'true') return;
+
+ const modalSelection = uiModal(selection);
+
+ modalSelection.select('.modal')
+ .attr('class', 'modal rapid-modal modal-splash modal-whatsnew'); // RapiD styling
+
+ let whatsNewModal = modalSelection.select('.content');
+
+ whatsNewModal
+ .append('div')
+ .attr('class','modal-section')
+ .append('h3')
+ .html(_t('rapid_whats_new.welcome', { rapidicon: icon('#iD-logo-rapid', 'logo-rapid') }));
+
+
+ let body = whatsNewModal
+ .append('div')
+ .attr('class','modal-section body')
+ .html(marked_1(_t('rapid_whats_new.text', {rapidicon: icon('#iD-logo-rapid', 'logo-rapid') })));
+
+
+ body
+ .append('img')
+ .attr('class', 'whatsnew-image')
+ .attr('src', context.asset('img/rapid-esri-splash.jpg'));
+
+ body.select('p a')
+ .attr('target', '_blank');
+
+
+ let checkboxContainer = whatsNewModal
+ .append('div')
+ .attr('class', 'modal-section rapid-checkbox dontshow')
+ .attr('id', 'dontshowagain');
+
+ let checkbox = checkboxContainer
+ .append('label')
+ .attr('class', 'rapid-checkbox-label dontshow');
+
+ checkbox
+ .append('span')
+ .attr('class', 'rapid-checkbox-text')
+ .text(_t('rapid_whats_new.dontshowagain'));
+
+ checkbox
+ .append('input')
+ .attr('type', 'checkbox')
+ .attr('class', 'rapid-feature-checkbox')
+ .property('checked', false)
+ .on('click', (d, i, nodes) => {
+ select(nodes[i]).node().blur();
+ _dontShowAgain = !_dontShowAgain;
+ });
+
+ checkbox
+ .append('div')
+ .attr('class', 'rapid-checkbox-custom');
+
+ let buttonWrap = whatsNewModal
+ .append('div')
+ .attr('class', 'modal-actions');
+
+ let nothanks = buttonWrap
+ .append('button')
+ .attr('class', 'whats-new-nothanks')
+ .on('click', (d, i, nodes) => {
+ select(nodes[i]).node().blur();
+ corePreferences('sawWhatsNew', _dontShowAgain);
+ modalSelection.close();
+ });
+
+ nothanks
+ .append('div')
+ .text(_t('rapid_whats_new.nope'));
+
+ let okayButton = buttonWrap
+ .append('button')
+ .attr('class', 'whats-new-okay');
+
+ okayButton
+ .append('div')
+ .text(_t('rapid_whats_new.ok'))
+ .on('click', (d, i, nodes) => {
+ select(nodes[i]).node().blur();
+ corePreferences('sawWhatsNew', _dontShowAgain);
+ modalSelection.close();
+ window.open('https://mapwith.ai/rapid-esri', '_blank');
+ });
+
+ modalSelection.select('button.close')
+ .attr('class','hide');
+ };
+ }
+
+ let _expandedOnce = false;
+
+
+ function modeRapidSelectFeatures(context, selectedDatum) {
+ let mode = {
+ id: 'select-ai-features',
+ button: 'browse'
+ };
+
+ const keybinding = utilKeybinding('select-ai-features');
+ const rapidInspector = uiRapidFeatureInspector(context, keybinding);
+ const service = selectedDatum.__service__ === 'esri' ? services.esriData : services.fbMLRoads;
+ const rapidGraph = service.graph(selectedDatum.__datasetid__);
+
+ let behaviors = [
+ behaviorBreathe(),
+ behaviorHover(context),
+ behaviorSelect(context),
+ behaviorLasso(context),
+ modeDragNode(context).behavior,
+ modeDragNote(context).behavior
+ ];
+
+
+ // class the data as selected, or return to browse mode if the data is gone
+ function selectData(drawn) {
+ let selection = context.surface().selectAll('.layer-ai-features .data' + selectedDatum.__fbid__);
+
+ if (selection.empty()) {
+ // Return to browse mode if selected DOM elements have
+ // disappeared because the user moved them out of view..
+ const source = event && event.type === 'zoom' && event.sourceEvent;
+ if (drawn && source && (source.type === 'mousemove' || source.type === 'touchmove')) {
+ context.enter(modeBrowse(context));
+ }
+ } else {
+ selection.classed('selected', true);
+ }
+ }
+
+
+ function esc() {
+ if (select('.combobox').size()) return;
+ context.enter(modeBrowse(context));
+ }
+
+
+ mode.selectedIDs = function() {
+ return [selectedDatum.id];
+ };
+
+
+ mode.selectedDatum = function() {
+ return selectedDatum;
+ };
+
+
+ mode.zoomToSelected = function() {
+ const extent = selectedDatum.extent(rapidGraph);
+ context.map().centerZoomEase(extent.center(), context.map().trimmedExtentZoom(extent));
+ };
+
+
+ mode.enter = function() {
+ behaviors.forEach(context.install);
+
+ keybinding
+ .on(_t('inspector.zoom_to.key'), mode.zoomToSelected)
+ .on('⎋', esc, true);
+
+ select(document)
+ .call(keybinding);
+
+ selectData();
+
+ const sidebar = context.ui().sidebar;
+ sidebar.show(rapidInspector.datum(selectedDatum));
+
+ if (!_expandedOnce) {
+ // Expand sidebar at least once per session to inform user how to
+ // accept and reject proposed roads.
+ _expandedOnce = true;
+ // expand the sidebar, avoid obscuring the data if needed
+ const extent = selectedDatum.extent(rapidGraph);
+ sidebar.expand(sidebar.intersects(extent));
+ }
+
+ context.map()
+ .on('drawn.select-ai-features', selectData);
+ };
+
+
+ mode.exit = function() {
+ behaviors.forEach(context.uninstall);
+
+ select(document)
+ .call(keybinding.unbind);
+
+ context.surface()
+ .selectAll('.layer-ai-features .selected')
+ .classed('selected hover', false);
+
+ context.map()
+ .on('drawn.select-ai-features', null);
+
+ context.ui().sidebar
+ .hide();
+ };
+
+
+ return mode;
+ }
+
+ function operationContinue(context, selectedIDs) {
+ var graph = context.graph();
+ var entities = selectedIDs.map(function(id) { return graph.entity(id); });
+ var geometries = Object.assign(
+ { line: [], vertex: [] },
+ utilArrayGroupBy(entities, function(entity) { return entity.geometry(graph); })
+ );
+ var vertex = geometries.vertex[0];
+
+
+ function candidateWays() {
+ return graph.parentWays(vertex).filter(function(parent) {
+ return parent.geometry(graph) === 'line' &&
+ !parent.isClosed() &&
+ parent.affix(vertex.id) &&
+ (geometries.line.length === 0 || geometries.line[0] === parent);
+ });
+ }
+
+
+ var operation = function() {
+ var candidate = candidateWays()[0];
+ context.enter(
+ modeDrawLine(context, candidate.id, context.graph(), 'line', candidate.affix(vertex.id), true)
+ );
+ };
+
+
+ operation.available = function() {
+ return geometries.vertex.length === 1 &&
+ geometries.line.length <= 1 &&
+ !context.features().hasHiddenConnections(vertex, context.graph());
+ };
+
+
+ operation.disabled = function() {
+ var candidates = candidateWays();
+ if (candidates.length === 0) {
+ return 'not_eligible';
+ } else if (candidates.length > 1) {
+ return 'multiple';
+ }
+
+ return false;
+ };
+
+
+ operation.tooltip = function() {
+ var disable = operation.disabled();
+ return disable ?
+ _t('operations.continue.' + disable) :
+ _t('operations.continue.description');
+ };
+
+
+ operation.annotation = function() {
+ return _t('operations.continue.annotation.line');
+ };
+
+
+ operation.id = 'continue';
+ operation.keys = [_t('operations.continue.key')];
+ operation.title = _t('operations.continue.title');
+ operation.behavior = behaviorOperation(context).which(operation);
+
+ return operation;
+ }
+
+ function operationCycleHighwayTag(context, selectedIDs) {
+ var _entityID = selectedIDs[0];
+ var _entity = context.entity(_entityID);
+ var _prevSelectedIDs;
+ var ROAD_TYPES = ['residential', 'service', 'track', 'unclassified', 'tertiary'];
+
+
+ var updateHighwayTag = function (tags) {
+ var idx = tags.highway ? ROAD_TYPES.indexOf(tags.highway) : -1;
+ tags.highway = ROAD_TYPES[(idx + 1) % ROAD_TYPES.length];
+
+ if (tags.highway === 'track') {
+ tags.surface = 'unpaved';
+ }
+ else {
+ delete tags.surface;
+ }
+ };
+
+
+ var operation = function() {
+ _entity = context.entity(_entityID);
+ // Calculate whether the changes since the last time this action ran
+ // are only to highway tags.
+ if (_prevSelectedIDs) {
+ var sameSelection = _prevSelectedIDs ? _prevSelectedIDs[0] === selectedIDs[0] : false;
+ }
+
+ var tags = Object.assign({}, _entity.tags);
+ updateHighwayTag(tags);
+
+ _prevSelectedIDs = selectedIDs;
+
+ // context peeking tells us the last operation performed. Was it cycle road tags?
+ if (sameSelection && context.history().peekAnnotation() === operation.annotation()) {
+ // Coalesce the update of Highway type tags into the previous tag change
+ context.replace(actionChangeTags(_entityID, tags), operation.annotation());
+ } else {
+ context.perform(actionChangeTags(_entityID, tags), operation.annotation());
+ }
+ };
+
+
+ operation.available = function() {
+ return selectedIDs.length === 1 &&
+ _entity.type === 'way' &&
+ new Set(_entity.nodes).size > 1;
+ };
+
+
+ operation.disabled = function() {
+ if ( Object.keys(_entity.tags).length > 0 && !_entity.tags.highway) {
+ return 'restriction';
+ }
+ };
+
+
+ operation.tooltip = function() {
+ var disable = operation.disabled();
+ return disable ?
+ _t('operations.cycle_highway_tag.' + disable) :
+ _t('operations.cycle_highway_tag.description');
+ };
+
+
+ operation.annotation = function() {
+ return _t('operations.cycle_highway_tag.annotation');
+ };
+
+
+ operation.id = 'cycle_highway_tag';
+ operation.keys = ['⇧' + _t('operations.cycle_highway_tag.key')];
+ operation.title = _t('operations.cycle_highway_tag.title');
+ operation.behavior = behaviorOperation(context).which(operation);
+
+ return operation;
+ }
+
+ function operationCopy(context, selectedIDs) {
+
+ var _multi = selectedIDs.length === 1 ? 'single' : 'multiple';
+
+ function getFilteredIdsToCopy() {
+ return selectedIDs.filter(function(selectedID) {
+ var entity = context.graph().hasEntity(selectedID);
+ // don't copy untagged vertices separately from ways
+ return entity.hasInterestingTags() || entity.geometry(context.graph()) !== 'vertex';
+ });
+ }
+
+ var operation = function() {
+
+ if (!getSelectionText()) {
+ event.preventDefault();
+ }
+
+ var graph = context.graph();
+ var selected = groupEntities(getFilteredIdsToCopy(), graph);
+ var canCopy = [];
+ var skip = {};
+ var entity;
+ var i;
+
+ for (i = 0; i < selected.relation.length; i++) {
+ entity = selected.relation[i];
+ if (!skip[entity.id] && entity.isComplete(graph)) {
+ canCopy.push(entity.id);
+ skip = getDescendants(entity.id, graph, skip);
+ }
+ }
+ for (i = 0; i < selected.way.length; i++) {
+ entity = selected.way[i];
+ if (!skip[entity.id]) {
+ canCopy.push(entity.id);
+ skip = getDescendants(entity.id, graph, skip);
+ }
+ }
+ for (i = 0; i < selected.node.length; i++) {
+ entity = selected.node[i];
+ if (!skip[entity.id]) {
+ canCopy.push(entity.id);
+ }
+ }
+
+ context.copyIDs(canCopy);
+ if (_point &&
+ (canCopy.length !== 1 || graph.entity(canCopy[0]).type !== 'node')) {
+ // store the anchor coordinates if copying more than a single node
+ context.copyLonLat(context.projection.invert(_point));
+ } else {
+ context.copyLonLat(null);
+ }
+
+ };
+
+
+ function groupEntities(ids, graph) {
+ var entities = ids.map(function (id) { return graph.entity(id); });
+ return Object.assign(
+ { relation: [], way: [], node: [] },
+ utilArrayGroupBy(entities, 'type')
+ );
+ }
+
+
+ function getDescendants(id, graph, descendants) {
+ var entity = graph.entity(id);
+ var children;
+
+ descendants = descendants || {};
+
+ if (entity.type === 'relation') {
+ children = entity.members.map(function(m) { return m.id; });
+ } else if (entity.type === 'way') {
+ children = entity.nodes;
+ } else {
+ children = [];
+ }
+
+ for (var i = 0; i < children.length; i++) {
+ if (!descendants[children[i]]) {
+ descendants[children[i]] = true;
+ descendants = getDescendants(children[i], graph, descendants);
+ }
+ }
+
+ return descendants;
+ }
+
+
+ function getSelectionText() {
+ return window.getSelection().toString();
+ }
+
+
+ operation.available = function() {
+ return getFilteredIdsToCopy().length > 0;
+ };
+
+
+ operation.disabled = function() {
+ var extent = utilTotalExtent(getFilteredIdsToCopy(), context.graph());
+ if (extent.percentContainedIn(context.map().extent()) < 0.8) {
+ return 'too_large';
+ }
+ return false;
+ };
+
+
+ operation.tooltip = function() {
+ var disable = operation.disabled();
+ return disable ?
+ _t('operations.copy.' + disable + '.' + _multi) :
+ _t('operations.copy.description' + '.' + _multi);
+ };
+
+
+ operation.annotation = function() {
+ return selectedIDs.length === 1 ?
+ _t('operations.copy.annotation.single') :
+ _t('operations.copy.annotation.multiple', { n: selectedIDs.length.toString() });
+ };
+
+
+ var _point;
+ operation.point = function(val) {
+ _point = val;
+ return operation;
+ };
+
+
+ operation.id = 'copy';
+ operation.keys = [uiCmd('⌘C')];
+ operation.title = _t('operations.copy.title');
+ operation.behavior = behaviorOperation(context).which(operation);
+
+ return operation;
+ }
+
+ function operationDisconnect(context, selectedIDs) {
+ var _vertexIDs = [];
+ var _wayIDs = [];
+ var _otherIDs = [];
+ var _actions = [];
+
+ selectedIDs.forEach(function(id) {
+ var entity = context.entity(id);
+ if (entity.type === 'way'){
+ _wayIDs.push(id);
+ } else if (entity.geometry(context.graph()) === 'vertex') {
+ _vertexIDs.push(id);
+ } else {
+ _otherIDs.push(id);
+ }
+ });
+
+ var _extent, _nodes, _coords, _descriptionID = '', _annotationID = 'features';
+
+ if (_vertexIDs.length > 0) {
+ // At the selected vertices, disconnect the selected ways, if any, else
+ // disconnect all connected ways
+
+ _extent = utilTotalExtent(_vertexIDs, context.graph());
+
+ _vertexIDs.forEach(function(vertexID) {
+ var action = actionDisconnect(vertexID);
+
+ if (_wayIDs.length > 0) {
+ var waysIDsForVertex = _wayIDs.filter(function(wayID) {
+ var way = context.entity(wayID);
+ return way.nodes.indexOf(vertexID) !== -1;
+ });
+ action.limitWays(waysIDsForVertex);
+ }
+ _actions.push(action);
+ });
+
+ _descriptionID += _actions.length === 1 ? 'single_point.' : 'multiple_points.';
+ if (_wayIDs.length === 1) {
+ _descriptionID += 'single_way.' + context.graph().geometry(_wayIDs[0]);
+ } else {
+ _descriptionID += _wayIDs.length === 0 ? 'no_ways' : 'multiple_ways';
+ }
+
+ } else if (_wayIDs.length > 0) {
+ // Disconnect the selected ways from each other, if they're connected,
+ // else disconnect them from all connected ways
+
+ var ways = _wayIDs.map(function(id) {
+ return context.entity(id);
+ });
+ _nodes = utilGetAllNodes(_wayIDs, context.graph());
+ _coords = _nodes.map(function(n) { return n.loc; });
+ _extent = utilTotalExtent(ways, context.graph());
+
+ // actions for connected nodes shared by at least two selected ways
+ var sharedActions = [];
+ // actions for connected nodes
+ var unsharedActions = [];
+
+ _nodes.forEach(function(node) {
+ var action = actionDisconnect(node.id).limitWays(_wayIDs);
+ if (action.disabled(context.graph()) !== 'not_connected') {
+
+ var count = 0;
+ for (var i in ways) {
+ var way = ways[i];
+ if (way.nodes.indexOf(node.id) !== -1) {
+ count += 1;
+ }
+ if (count > 1) break;
+ }
+
+ if (count > 1) {
+ sharedActions.push(action);
+ } else {
+ unsharedActions.push(action);
+ }
+ }
+ });
+
+ _descriptionID += 'no_points.';
+ _descriptionID += _wayIDs.length === 1 ? 'single_way.' : 'multiple_ways.';
+
+ if (sharedActions.length) {
+ // if any nodes are shared, only disconnect the selected ways from each other
+ _actions = sharedActions;
+ _descriptionID += 'conjoined';
+ _annotationID = 'from_each_other';
+ } else {
+ // if no nodes are shared, disconnect the selected ways from all connected ways
+ _actions = unsharedActions;
+ if (_wayIDs.length === 1) {
+ _descriptionID += context.graph().geometry(_wayIDs[0]);
+ } else {
+ _descriptionID += 'separate';
+ }
+ }
+ }
+
+
+ var operation = function() {
+ context.perform(function(graph) {
+ return _actions.reduce(function(graph, action) { return action(graph); }, graph);
+ }, operation.annotation());
+
+ context.validator().validate();
+ };
+
+
+ operation.available = function() {
+ if (_actions.length === 0) return false;
+ if (_otherIDs.length !== 0) return false;
+
+ if (_vertexIDs.length !== 0 && _wayIDs.length !== 0 && !_wayIDs.every(function(wayID) {
+ return _vertexIDs.some(function(vertexID) {
+ var way = context.entity(wayID);
+ return way.nodes.indexOf(vertexID) !== -1;
+ });
+ })) return false;
+
+ return true;
+ };
+
+
+ operation.disabled = function() {
+ var reason;
+ for (var actionIndex in _actions) {
+ reason = _actions[actionIndex].disabled(context.graph());
+ if (reason) return reason;
+ }
+
+ if (_extent && _extent.percentContainedIn(context.map().extent()) < 0.8) {
+ return 'too_large.' + ((_vertexIDs.length ? _vertexIDs : _wayIDs).length === 1 ? 'single' : 'multiple');
+ } else if (_coords && someMissing()) {
+ return 'not_downloaded';
+ } else if (selectedIDs.some(context.hasHiddenConnections)) {
+ return 'connected_to_hidden';
+ }
+
+ return false;
+
+
+ function someMissing() {
+ if (context.inIntro()) return false;
+ var osm = context.connection();
+ if (osm) {
+ var missing = _coords.filter(function(loc) { return !osm.isDataLoaded(loc); });
+ if (missing.length) {
+ missing.forEach(function(loc) { context.loadTileAtLoc(loc); });
+ return true;
+ }
+ }
+ return false;
+ }
+ };
+
+
+ operation.tooltip = function() {
+ var disable = operation.disabled();
+ if (disable) {
+ return _t('operations.disconnect.' + disable);
+ }
+ return _t('operations.disconnect.description.' + _descriptionID);
+ };
+
+
+ operation.annotation = function() {
+ return _t('operations.disconnect.annotation.' + _annotationID);
+ };
+
+
+ operation.id = 'disconnect';
+ operation.keys = [_t('operations.disconnect.key')];
+ operation.title = _t('operations.disconnect.title');
+ operation.behavior = behaviorOperation(context).which(operation);
+
+ return operation;
+ }
+
+ function operationDowngrade(context, selectedIDs) {
+ var affectedFeatureCount = 0;
+ var downgradeType;
+
+ setDowngradeTypeForEntityIDs();
+
+ var multi = affectedFeatureCount === 1 ? 'single' : 'multiple';
+
+ function setDowngradeTypeForEntityIDs() {
+ for (var i in selectedIDs) {
+ var entityID = selectedIDs[i];
+ var type = downgradeTypeForEntityID(entityID);
+ if (type) {
+ affectedFeatureCount += 1;
+ if (downgradeType && type !== downgradeType) {
+ downgradeType = 'building_address';
+ } else {
+ downgradeType = type;
+ }
+ }
+ }
+ }
+
+ function downgradeTypeForEntityID(entityID) {
+ var graph = context.graph();
+ var entity = graph.entity(entityID);
+ var preset = _mainPresetIndex.match(entity, graph);
+
+ if (!preset || preset.isFallback()) return null;
+
+ if (entity.type === 'node' &&
+ preset.id !== 'address' &&
+ Object.keys(entity.tags).some(function(key) {
+ return key.match(/^addr:.{1,}/);
+ })) {
+
+ return 'address';
+ }
+ if (entity.geometry(graph) === 'area' &&
+ entity.tags.building &&
+ !preset.tags.building) {
+
+ return 'building';
+ }
+
+ return null;
+ }
+
+ var buildingKeysToKeep = ['architect', 'building', 'height', 'layer', 'source', 'type', 'wheelchair'];
+ var addressKeysToKeep = ['source'];
+
+ var operation = function () {
+ context.perform(function(graph) {
+
+ for (var i in selectedIDs) {
+ var entityID = selectedIDs[i];
+ var type = downgradeTypeForEntityID(entityID);
+ if (!type) continue;
+
+ var tags = Object.assign({}, graph.entity(entityID).tags); // shallow copy
+ for (var key in tags) {
+ if (type === 'address' && addressKeysToKeep.indexOf(key) !== -1) continue;
+ if (type === 'building') {
+ if (buildingKeysToKeep.indexOf(key) !== -1 ||
+ key.match(/^building:.{1,}/) ||
+ key.match(/^roof:.{1,}/)) continue;
+ }
+ // keep address tags for buildings too
+ if (key.match(/^addr:.{1,}/)) continue;
+
+ delete tags[key];
+ }
+ graph = actionChangeTags(entityID, tags)(graph);
+ }
+ return graph;
+ }, operation.annotation());
+
+ context.validator().validate();
+
+ // refresh the select mode to enable the delete operation
+ context.enter(modeSelect(context, selectedIDs));
+ };
+
+
+ operation.available = function () {
+ return downgradeType;
+ };
+
+
+ operation.disabled = function () {
+ if (selectedIDs.some(hasWikidataTag)) {
+ return 'has_wikidata_tag';
+ }
+ return false;
+
+ function hasWikidataTag(id) {
+ var entity = context.entity(id);
+ return entity.tags.wikidata && entity.tags.wikidata.trim().length > 0;
+ }
+ };
+
+
+ operation.tooltip = function () {
+ var disable = operation.disabled();
+ return disable ?
+ _t('operations.downgrade.' + disable + '.' + multi) :
+ _t('operations.downgrade.description.' + downgradeType);
+ };
+
+
+ operation.annotation = function () {
+ var suffix;
+ if (downgradeType === 'building_address') {
+ suffix = 'multiple';
+ } else {
+ suffix = downgradeType + '.' + multi;
+ }
+ return _t('operations.downgrade.annotation.' + suffix, { n: affectedFeatureCount});
+ };
+
+
+ operation.id = 'downgrade';
+ operation.keys = [uiCmd('⌘⌫'), uiCmd('⌘⌦'), uiCmd('⌦')];
+ operation.title = _t('operations.downgrade.title');
+ operation.behavior = behaviorOperation(context).which(operation);
+
+
+ return operation;
+ }
+
+ function operationExtract(context, selectedIDs) {
+
+ var _amount = selectedIDs.length === 1 ? 'single' : 'multiple';
+ var _geometries = utilArrayUniq(selectedIDs.map(function(entityID) {
+ return context.graph().hasEntity(entityID) && context.graph().geometry(entityID);
+ }).filter(Boolean));
+ var _geometryID = _geometries.length === 1 ? _geometries[0] : 'feature';
+
+ var _extent;
+ var _actions = selectedIDs.map(function(entityID) {
+ var graph = context.graph();
+ var entity = graph.hasEntity(entityID);
+ if (!entity || !entity.hasInterestingTags()) return;
+
+ if (entity.type === 'node' && graph.parentWays(entity).length === 0) return;
+
+ if (entity.type !== 'node') {
+ var preset = _mainPresetIndex.match(entity, graph);
+ // only allow extraction from ways/relations if the preset supports points
+ if (preset.geometry.indexOf('point') === -1) return;
+ }
+
+ _extent = _extent ? _extent.extend(entity.extent(graph)) : entity.extent(graph);
+
+ return actionExtract(entityID);
+ }).filter(Boolean);
+
+
+ var operation = function () {
+ var combinedAction = function(graph) {
+ _actions.forEach(function(action) {
+ graph = action(graph);
+ });
+ return graph;
+ };
+ context.perform(combinedAction, operation.annotation()); // do the extract
+
+ var extractedNodeIDs = _actions.map(function(action) {
+ return action.getExtractedNodeID();
+ });
+ context.enter(modeSelect(context, extractedNodeIDs));
+ };
+
+
+ operation.available = function () {
+ return _actions.length && selectedIDs.length === _actions.length;
+ };
+
+
+ operation.disabled = function () {
+
+ if (_extent && _extent.percentContainedIn(context.map().extent()) < 0.8) {
+ return 'too_large';
+ } else if (selectedIDs.some(function(entityID) {
+ return context.graph().geometry(entityID) === 'vertex' && context.hasHiddenConnections(entityID);
+ })) {
+ return 'connected_to_hidden';
+ }
+
+ return false;
+ };
+
+
+ operation.tooltip = function () {
+ var disableReason = operation.disabled();
+ if (disableReason) {
+ return _t('operations.extract.' + disableReason + '.' + _amount);
+ } else {
+ return _t('operations.extract.description.' + _geometryID + '.' + _amount);
+ }
+ };
+
+
+ operation.annotation = function () {
+ return _t('operations.extract.annotation.' + _amount, { n: selectedIDs.length });
+ };
+
+
+ operation.id = 'extract';
+ operation.keys = [_t('operations.extract.key')];
+ operation.title = _t('operations.extract.title');
+ operation.behavior = behaviorOperation(context).which(operation);
+
+
+ return operation;
+ }
+
+ function operationMerge(context, selectedIDs) {
+
+ var _action = getAction();
+
+ function getAction() {
+ // prefer a non-disabled action first
+ var join = actionJoin(selectedIDs);
+ if (!join.disabled(context.graph())) return join;
+
+ var merge = actionMerge(selectedIDs);
+ if (!merge.disabled(context.graph())) return merge;
+
+ var mergePolygon = actionMergePolygon(selectedIDs);
+ if (!mergePolygon.disabled(context.graph())) return mergePolygon;
+
+ var mergeNodes = actionMergeNodes(selectedIDs);
+ if (!mergeNodes.disabled(context.graph())) return mergeNodes;
+
+ // otherwise prefer an action with an interesting disabled reason
+ if (join.disabled(context.graph()) !== 'not_eligible') return join;
+ if (merge.disabled(context.graph()) !== 'not_eligible') return merge;
+ if (mergePolygon.disabled(context.graph()) !== 'not_eligible') return mergePolygon;
+
+ return mergeNodes;
+ }
+
+ var operation = function() {
+
+ if (operation.disabled()) return;
+
+ context.perform(_action, operation.annotation());
+
+ context.validator().validate();
+
+ var resultIDs = selectedIDs.filter(context.hasEntity);
+ if (resultIDs.length > 1) {
+ var interestingIDs = resultIDs.filter(function(id) {
+ return context.entity(id).hasInterestingTags();
+ });
+ if (interestingIDs.length) resultIDs = interestingIDs;
+ }
+ context.enter(modeSelect(context, resultIDs));
+ };
+
+ operation.available = function() {
+ return selectedIDs.length >= 2;
+ };
+
+ operation.disabled = function() {
+ var actionDisabled = _action.disabled(context.graph());
+ if (actionDisabled) return actionDisabled;
+
+ var osm = context.connection();
+ if (osm &&
+ _action.resultingWayNodesLength &&
+ _action.resultingWayNodesLength(context.graph()) > osm.maxWayNodes()) {
+ return 'too_many_vertices';
+ }
+
+ return false;
+ };
+
+ operation.tooltip = function() {
+ var disabled = operation.disabled();
+ if (disabled) {
+ if (disabled === 'restriction') {
+ return _t('operations.merge.restriction',
+ { relation: _mainPresetIndex.item('type/restriction').name() });
+ }
+ return _t('operations.merge.' + disabled);
+ }
+ return _t('operations.merge.description');
+ };
+
+ operation.annotation = function() {
+ return _t('operations.merge.annotation', { n: selectedIDs.length });
+ };
+
+ operation.id = 'merge';
+ operation.keys = [_t('operations.merge.key')];
+ operation.title = _t('operations.merge.title');
+ operation.behavior = behaviorOperation(context).which(operation);
+
+ return operation;
+ }
+
+ // see also `behaviorPaste`
+ function operationPaste(context) {
+
+ var _pastePoint;
+
+ var operation = function() {
+
+ if (!_pastePoint) return;
+
+ var oldIDs = context.copyIDs();
+ if (!oldIDs.length) return;
+
+ var projection = context.projection;
+ var extent = geoExtent();
+ var oldGraph = context.copyGraph();
+ var newIDs = [];
+
+ var action = actionCopyEntities(oldIDs, oldGraph);
+ context.perform(action);
+
+ var copies = action.copies();
+ var originals = new Set();
+ Object.values(copies).forEach(function(entity) { originals.add(entity.id); });
+
+ for (var id in copies) {
+ var oldEntity = oldGraph.entity(id);
+ var newEntity = copies[id];
+
+ extent._extend(oldEntity.extent(oldGraph));
+
+ // Exclude child nodes from newIDs if their parent way was also copied.
+ var parents = context.graph().parentWays(newEntity);
+ var parentCopied = parents.some(function(parent) {
+ return originals.has(parent.id);
+ });
+
+ if (!parentCopied) {
+ newIDs.push(newEntity.id);
+ }
+ }
+
+ // Use the location of the copy operation to offset the paste location,
+ // or else use the center of the pasted extent
+ var copyPoint = (context.copyLonLat() && projection(context.copyLonLat())) ||
+ projection(extent.center());
+ var delta = geoVecSubtract(_pastePoint, copyPoint);
+
+ // Move the pasted objects to be anchored at the paste location
+ context.replace(actionMove(newIDs, delta, projection), operation.annotation());
+ context.enter(modeSelect(context, newIDs));
+ };
+
+ operation.point = function(val) {
+ _pastePoint = val;
+ return operation;
+ };
+
+ operation.available = function() {
+ return context.mode().id === 'browse';
+ };
+
+ operation.disabled = function() {
+ return !context.copyIDs().length;
+ };
+
+ operation.tooltip = function() {
+ var oldGraph = context.copyGraph();
+ var ids = context.copyIDs();
+ if (!ids.length) {
+ return _t('operations.paste.nothing_copied');
+ }
+ return ids.length === 1 ?
+ _t('operations.paste.description.single', { feature: utilDisplayLabel(oldGraph.entity(ids[0]), oldGraph) }) :
+ _t('operations.paste.description.multiple', { n: ids.length.toString() });
+ };
+
+ operation.annotation = function() {
+ var ids = context.copyIDs();
+ return ids.length === 1 ?
+ _t('operations.paste.annotation.single') :
+ _t('operations.paste.annotation.multiple', { n: ids.length.toString() });
+ };
+
+ operation.id = 'paste';
+ operation.keys = [uiCmd('⌘V')];
+ operation.title = _t('operations.paste.title');
+
+ return operation;
+ }
+
+ function operationReverse(context, selectedIDs) {
+
+ var operation = function() {
+ context.perform(function combinedReverseAction(graph) {
+ actions().forEach(function(action) {
+ graph = action(graph);
+ });
+ return graph;
+ }, operation.annotation());
+ context.validator().validate();
+ };
+
+ function actions(situation) {
+ return selectedIDs.map(function(entityID) {
+ var entity = context.hasEntity(entityID);
+ if (!entity) return;
+
+ if (situation === 'toolbar') {
+ if (entity.type === 'way' &&
+ (!entity.isOneWay() && !entity.isSided())) return;
+ }
+
+ var geometry = entity.geometry(context.graph());
+ if (entity.type !== 'node' && geometry !== 'line') return;
+
+ var action = actionReverse(entityID);
+ if (action.disabled(context.graph())) return;
+
+ return action;
+ }).filter(Boolean);
+ }
+
+ function reverseTypeID() {
+ var acts = actions();
+ var nodeActionCount = acts.filter(function(act) {
+ var entity = context.hasEntity(act.entityID());
+ return entity && entity.type === 'node';
+ }).length;
+ var typeID = nodeActionCount === 0 ? 'line' : (nodeActionCount === acts.length ? 'point' : 'features');
+ if (typeID !== 'features' && acts.length > 1) typeID += 's';
+ return typeID;
+ }
+
+
+ operation.available = function(situation) {
+ return actions(situation).length > 0;
+ };
+
+
+ operation.disabled = function() {
+ return false;
+ };
+
+
+ operation.tooltip = function() {
+ return _t('operations.reverse.description.' + reverseTypeID());
+ };
+
+
+ operation.annotation = function() {
+ return _t('operations.reverse.annotation.' + reverseTypeID());
+ };
+
+
+ operation.id = 'reverse';
+ operation.keys = [_t('operations.reverse.key')];
+ operation.title = _t('operations.reverse.title');
+ operation.behavior = behaviorOperation(context).which(operation);
+
+ return operation;
+ }
+
+ function operationSplit(context, selectedIDs) {
+ var vertices = selectedIDs
+ .filter(function(id) { return context.graph().geometry(id) === 'vertex'; });
+ var entityID = vertices[0];
+ var action = actionSplit(entityID);
+ var ways = [];
+
+ if (vertices.length === 1) {
+ if (entityID && selectedIDs.length > 1) {
+ var ids = selectedIDs.filter(function(id) { return id !== entityID; });
+ action.limitWays(ids);
+ }
+ ways = action.ways(context.graph());
+ }
+
+
+ var operation = function() {
+ var difference = context.perform(action, operation.annotation());
+ context.enter(modeSelect(context, difference.extantIDs()));
+ };
+
+
+ operation.available = function() {
+ return vertices.length === 1;
+ };
+
+
+ operation.disabled = function() {
+ var reason = action.disabled(context.graph());
+ if (reason) {
+ return reason;
+ } else if (selectedIDs.some(context.hasHiddenConnections)) {
+ return 'connected_to_hidden';
+ }
+
+ return false;
+ };
+
+
+ operation.tooltip = function() {
+ var disable = operation.disabled();
+ if (disable) {
+ return _t('operations.split.' + disable);
+ } else if (ways.length === 1) {
+ return _t('operations.split.description.' + context.graph().geometry(ways[0].id));
+ } else {
+ return _t('operations.split.description.multiple');
+ }
+ };
+
+
+ operation.annotation = function() {
+ return ways.length === 1 ?
+ _t('operations.split.annotation.' + context.graph().geometry(ways[0].id)) :
+ _t('operations.split.annotation.multiple', { n: ways.length });
+ };
+
+
+ operation.id = 'split';
+ operation.keys = [_t('operations.split.key')];
+ operation.title = _t('operations.split.title');
+ operation.behavior = behaviorOperation(context).which(operation);
+
+ return operation;
+ }
+
+ function operationStraighten(context, selectedIDs) {
+ var _wayIDs = selectedIDs.filter(function(id) { return id.charAt(0) === 'w'; });
+ var _nodeIDs = selectedIDs.filter(function(id) { return id.charAt(0) === 'n'; });
+ var _amount = ((_wayIDs.length ? _wayIDs : _nodeIDs).length === 1 ? 'single' : 'multiple');
+
+ var _nodes = utilGetAllNodes(selectedIDs, context.graph());
+ var _coords = _nodes.map(function(n) { return n.loc; });
+ var _extent = utilTotalExtent(selectedIDs, context.graph());
+ var _action = chooseAction();
+ var _geometry;
+
+
+ function chooseAction() {
+ // straighten selected nodes
+ if (_wayIDs.length === 0 && _nodeIDs.length > 2) {
+ _geometry = 'points';
+ return actionStraightenNodes(_nodeIDs, context.projection);
+
+ // straighten selected ways (possibly between range of 2 selected nodes)
+ } else if (_wayIDs.length > 0 && (_nodeIDs.length === 0 || _nodeIDs.length === 2)) {
+ var startNodeIDs = [];
+ var endNodeIDs = [];
+
+ for (var i = 0; i < selectedIDs.length; i++) {
+ var entity = context.entity(selectedIDs[i]);
+ if (entity.type === 'node') {
+ continue;
+ } else if (entity.type !== 'way' || entity.isClosed()) {
+ return null; // exit early, can't straighten these
+ }
+
+ startNodeIDs.push(entity.first());
+ endNodeIDs.push(entity.last());
+ }
+
+ // Remove duplicate end/startNodeIDs (duplicate nodes cannot be at the line end)
+ startNodeIDs = startNodeIDs.filter(function(n) {
+ return startNodeIDs.indexOf(n) === startNodeIDs.lastIndexOf(n);
+ });
+ endNodeIDs = endNodeIDs.filter(function(n) {
+ return endNodeIDs.indexOf(n) === endNodeIDs.lastIndexOf(n);
+ });
+
+ // Ensure all ways are connected (i.e. only 2 unique endpoints/startpoints)
+ if (utilArrayDifference(startNodeIDs, endNodeIDs).length +
+ utilArrayDifference(endNodeIDs, startNodeIDs).length !== 2) return null;
+
+ // Ensure path contains at least 3 unique nodes
+ var wayNodeIDs = utilGetAllNodes(_wayIDs, context.graph())
+ .map(function(node) { return node.id; });
+ if (wayNodeIDs.length <= 2) return null;
+
+ // If range of 2 selected nodes is supplied, ensure nodes lie on the selected path
+ if (_nodeIDs.length === 2 && (
+ wayNodeIDs.indexOf(_nodeIDs[0]) === -1 || wayNodeIDs.indexOf(_nodeIDs[1]) === -1
+ )) return null;
+
+ if (_nodeIDs.length) {
+ // If we're only straightenting between two points, we only need that extent visible
+ _extent = utilTotalExtent(_nodeIDs, context.graph());
+ }
+
+ _geometry = _wayIDs.length === 1 ? 'line' : 'lines';
+ return actionStraightenWay(selectedIDs, context.projection);
+ }
+
+ return null;
+ }
+
+
+ function operation() {
+ if (!_action) return;
+
+ context.perform(_action, operation.annotation());
+
+ window.setTimeout(function() {
+ context.validator().validate();
+ }, 300); // after any transition
+ }
+
+
+ operation.available = function() {
+ return Boolean(_action);
+ };
+
+
+ operation.disabled = function() {
+ var reason = _action.disabled(context.graph());
+ if (reason) {
+ return reason;
+ } else if (_extent.percentContainedIn(context.map().extent()) < 0.8) {
+ return 'too_large';
+ } else if (someMissing()) {
+ return 'not_downloaded';
+ } else if (selectedIDs.some(context.hasHiddenConnections)) {
+ return 'connected_to_hidden';
+ }
+
+ return false;
+
+
+ function someMissing() {
+ if (context.inIntro()) return false;
+ var osm = context.connection();
+ if (osm) {
+ var missing = _coords.filter(function(loc) { return !osm.isDataLoaded(loc); });
+ if (missing.length) {
+ missing.forEach(function(loc) { context.loadTileAtLoc(loc); });
+ return true;
+ }
+ }
+ return false;
+ }
+ };
+
+
+ operation.tooltip = function() {
+ var disable = operation.disabled();
+ return disable ?
+ _t('operations.straighten.' + disable + '.' + _amount) :
+ _t('operations.straighten.description.' + _geometry);
+ };
+
+
+ operation.annotation = function() {
+ return _t('operations.straighten.annotation.' + _geometry);
+ };
+
+
+ operation.id = 'straighten';
+ operation.keys = [_t('operations.straighten.key')];
+ operation.title = _t('operations.straighten.title');
+ operation.behavior = behaviorOperation(context).which(operation);
+
+ return operation;
+ }
+
+ var Operations = /*#__PURE__*/Object.freeze({
+ __proto__: null,
+ operationCircularize: operationCircularize,
+ operationContinue: operationContinue,
+ operationCycleHighwayTag: operationCycleHighwayTag,
+ operationCopy: operationCopy,
+ operationDelete: operationDelete,
+ operationDisconnect: operationDisconnect,
+ operationDowngrade: operationDowngrade,
+ operationExtract: operationExtract,
+ operationMerge: operationMerge,
+ operationMove: operationMove,
+ operationOrthogonalize: operationOrthogonalize,
+ operationPaste: operationPaste,
+ operationReflectShort: operationReflectShort,
+ operationReflectLong: operationReflectLong,
+ operationReverse: operationReverse,
+ operationRotate: operationRotate,
+ operationSplit: operationSplit,
+ operationStraighten: operationStraighten
+ });
+
+ function validationShortRoad(context) {
+ var type = 'short_road';
+
+ // Thresholds for number of nodes and total length for a short road. A road
+ // is considered as "short" only if it has less than 7 nodes and is shorter
+ // than 20 meters.
+ var SHORT_WAY_NODES_THD = 7;
+ var SHORT_WAY_LENGTH_THD_METERS = 20;
+
+
+ function wayLength(way, graph) {
+ var length = 0;
+ for (var i = 0; i < way.nodes.length - 1; i++) {
+ var n1 = graph.entity(way.nodes[i]),
+ n2 = graph.entity(way.nodes[i + 1]);
+ length += geoSphericalDistance(n1.loc, n2.loc);
+ }
+ return length;
+ }
+
+ function continueDrawing(way, vertex, context) {
+ // make sure the vertex is actually visible and editable
+ var map = context.map();
+ if (!map.editable() || !map.trimmedExtent().contains(vertex.loc)) {
+ map.zoomToEase(vertex);
+ }
+
+ context.enter(
+ modeDrawLine(context, way.id, context.graph(), context.graph(), '', way.affix(vertex.id))
+ );
+ }
+
+
+ var validation = function(entity, graph) {
+ if (entity.type !== 'way' || !entity.tags.highway || entity.isClosed() || entity.nodes.length >= SHORT_WAY_NODES_THD) return [];
+
+ var firstNode = graph.entity(entity.first()),
+ lastNode = graph.entity(entity.last()),
+ pwaysStart = graph.parentWays(firstNode),
+ pwaysEnd = graph.parentWays(lastNode),
+ firstNodeOK = pwaysStart.length > 1 || firstNode.tags.noexit === 'yes',
+ lastNodeOK = pwaysEnd.length > 1 || lastNode.tags.noexit === 'yes';
+ // only do check on roads with open ends
+ if ((firstNodeOK && lastNodeOK) || wayLength(entity, graph) >= SHORT_WAY_LENGTH_THD_METERS) return [];
+
+ var fixes = [];
+ if (!firstNodeOK) {
+ fixes.push(new validationIssueFix({
+ icon: 'iD-operation-continue-left',
+ title: _t('issues.fix.continue_from_start.title'),
+ entityIds: [entity.first()],
+ onClick: function() {
+ var vertex = context.entity(entity.first());
+ continueDrawing(entity, vertex, context);
+ }
+ }));
+ }
+ if (!lastNodeOK) {
+ fixes.push(new validationIssueFix({
+ icon: 'iD-operation-continue',
+ title: _t('issues.fix.continue_from_end.title'),
+ entityIds: [entity.last()],
+ onClick: function() {
+ var vertex = context.entity(entity.last());
+ continueDrawing(entity, vertex, context);
+ }
+ }));
+ }
+ if (!operationDelete(context, [entity.id]).disabled()) {
+ fixes.push(new validationIssueFix({
+ icon: 'iD-operation-delete',
+ title: _t('issues.fix.delete_feature.title'),
+ entityIds: [entity.id],
+ onClick: function() {
+ var id = this.issue.entityIds[0];
+ var operation = operationDelete(context, [id]);
+ if (!operation.disabled()) {
+ operation();
+ }
+ }
+ }));
+ }
+
+ return [new validationIssue({
+ type: type,
+ severity: 'warning',
+ message: function(context) {
+ var entity = context.hasEntity(this.entityIds[0]);
+ if (!entity) return '';
+ var entityLabel = utilDisplayLabel(entity, context.graph());
+ return _t('issues.short_road.message', { highway: entityLabel });
+ },
+ reference: function(selection) {
+ selection.selectAll('.issue-reference')
+ .data([0])
+ .enter()
+ .append('div')
+ .attr('class', 'issue-reference')
+ .text(_t('issues.short_road.reference'));
+ },
+ entityIds: [entity.id],
+ fixes: fixes
+ })];
+ };
+
+
+ validation.type = type;
+
+ return validation;
+ }
+
+ function validationYShapedConnection(context) {
+ /* We want to catch and warn about the following "shapes of connections"
+ * that may appear in ML-generated roads:
+ * (1) Two short edges around a connection node, causing a "Y-shaped" connection
+ * ________ _______
+ * V
+ * |
+ * |
+ * |
+ * (2) One short edges around a connection node. The connection is not exactly
+ * "Y-shaped", but still a little too detailed.
+ * _______
+ * ___________ /
+ * |
+ * |
+ * |
+ * The potential fix is to remove the non-connection nodes causing the short edges,
+ * so that the shape of the connection becomes more like a "T".
+ *
+ * This validation will flag issues on those excessive non-connection nodes around
+ * Y-shaped connections and suggest deletion or move as possible fixes.
+ */
+
+ var type = 'y_shaped_connection';
+ // THD means "threshold"
+ var SHORT_EDGE_THD_METERS = 12;
+ var NON_FLAT_ANGLE_THD_DEGREES = 5;
+
+ var relatedHighways = {
+ residential: true, service: true, track: true, unclassified: true,
+ tertiary: true, secondary: true, primary: true, living_street: true,
+ cycleway: true, trunk: true, motorway: true, road: true, raceway: true
+ };
+
+
+ function isTaggedAsRelatedHighway(entity) {
+ return relatedHighways[entity.tags.highway];
+ }
+
+ function getRelatedHighwayParents(node, graph) {
+ var parentWays = graph.parentWays(node);
+ return parentWays.filter(function (way) {
+ return isTaggedAsRelatedHighway(way);
+ });
+ }
+
+ function createIssueAndFixForNode(node, context) {
+ var deletable = !operationDelete(context, [node.id]).disabled();
+ var fix = undefined;
+ if (deletable) {
+ fix = new validationIssueFix({
+ icon: 'iD-operation-delete',
+ title: _t('issues.fix.delete_node_around_conn.title'),
+ entityIds: [node.id],
+ onClick: function() {
+ var id = this.entityIds[0];
+ var operation = operationDelete(context, [id]);
+ if (!operation.disabled()) {
+ operation();
+ }
+ }
+ });
+ } else {
+ fix = new validationIssueFix({
+ icon: 'iD-operation-move',
+ title: _t('issues.fix.move_node_around_conn.title'),
+ entityIds: [node.id]
+ });
+ }
+
+ return new validationIssue({
+ type: type,
+ severity: 'warning',
+ message: function() {
+ return _t('issues.y_shaped_connection.message');
+ },
+ reference: function(selection) {
+ selection.selectAll('.issue-reference')
+ .data([0])
+ .enter()
+ .append('div')
+ .attr('class', 'issue-reference')
+ .text(_t('issues.y_shaped_connection.reference'));
+ },
+ entityIds: [node.id],
+ fixes: [fix]
+ });
+ }
+
+ // Check
+ // (1) if the edge between connNodeIdx and edgeNodeIdx is a short edge
+ // (2) if the node at connNodeIdx is a Y-shaped connection
+ // return true only if both (1) and (2) hold.
+ function isShortEdgeAndYShapedConnection(graph, way, connNodeIdx, edgeNodeIdx) {
+ // conditions for connNode to be a possible Y-shaped connection:
+ // (1) it is a connection node with edges on both side
+ // (2) at least one edge is short
+ // (3) the angle between the two edges are not close to 180 degrees
+
+ if (connNodeIdx <= 0 || connNodeIdx >= way.nodes.length - 1) return false;
+
+ // make sure the node at connNodeIdx is really a connection node
+ var connNid = way.nodes[connNodeIdx];
+ var connNode = graph.entity(connNid);
+ var pways = getRelatedHighwayParents(connNode, graph);
+ if (pways.length < 2) return false;
+
+ // check if the edge between connNode and edgeNode is short
+ var edgeNid = way.nodes[edgeNodeIdx];
+ var edgeNode = graph.entity(edgeNid);
+ var edgeLen = geoSphericalDistance(connNode.loc, edgeNode.loc);
+ if (edgeLen > SHORT_EDGE_THD_METERS) return false;
+
+ // check if connNode is a Y-shaped connection
+ var prevEdgeGeoAngle = 0;
+ var nextEdgeGeoAngle = 0;
+ var angleBetweenEdges = 0;
+ var otherNodeIdx = connNodeIdx < edgeNodeIdx ? connNodeIdx - 1 : connNodeIdx + 1;
+ var otherNid = way.nodes[otherNodeIdx];
+ var otherNode = graph.entity(otherNid);
+ if (otherNodeIdx < edgeNodeIdx) {
+ // node order along way: otherNode -> connNode -> edgeNode
+ prevEdgeGeoAngle = geoAngle(otherNode, connNode, context.projection);
+ nextEdgeGeoAngle = geoAngle(connNode, edgeNode, context.projection);
+ angleBetweenEdges = Math.abs(nextEdgeGeoAngle - prevEdgeGeoAngle) / Math.PI * 180.0;
+ } else {
+ // node order along way: edgeNode -> connNode -> otherNode
+ prevEdgeGeoAngle = geoAngle(edgeNode, connNode, context.projection);
+ nextEdgeGeoAngle = geoAngle(connNode, otherNode, context.projection);
+ angleBetweenEdges = Math.abs(nextEdgeGeoAngle - prevEdgeGeoAngle) / Math.PI * 180.0;
+ }
+
+ return angleBetweenEdges > NON_FLAT_ANGLE_THD_DEGREES;
+ }
+
+
+ var validation = function(entity, graph) {
+ // Only flag issue on non-connection nodes on negative ways
+ if (entity.type !== 'node') return [];
+ var pways = getRelatedHighwayParents(entity, graph);
+ if (pways.length !== 1 || !pways[0].id.startsWith('w-')) return [];
+
+ // check if either neighbor node on its parent way is a connection node
+ var issues = [];
+ var way = pways[0];
+ var idx = way.nodes.indexOf(entity.id);
+ if (idx <= 0) return issues;
+ if (isShortEdgeAndYShapedConnection(graph, way, idx - 1, idx) ||
+ isShortEdgeAndYShapedConnection(graph, way, idx + 1, idx)) {
+ issues.push(createIssueAndFixForNode(entity, context));
+ }
+ return issues;
+ };
+
+
+ validation.type = type;
+
+ return validation;
+ }
+
+ let _discardNameRegexes = [];
+
+ function validationSuspiciousName() {
+ const type = 'suspicious_name';
+ const keysToTestForGenericValues = [
+ 'aerialway', 'aeroway', 'amenity', 'building', 'craft', 'highway',
+ 'leisure', 'railway', 'man_made', 'office', 'shop', 'tourism', 'waterway'
+ ];
+
+ // A concern here in switching to async data means that `_nsiFilters` will not
+ // be available at first, so the data on early tiles may not have tags validated fully.
+
+ _mainFileFetcher.get('nsi_filters')
+ .then(filters => {
+ // known list of generic names (e.g. "bar")
+ _discardNameRegexes = filters.discardNames
+ .map(discardName => new RegExp(discardName, 'i'));
+ })
+ .catch(() => { /* ignore */ });
+
+
+ function isDiscardedSuggestionName(lowercaseName) {
+ return _discardNameRegexes.some(regex => regex.test(lowercaseName));
+ }
+
+ // test if the name is just the key or tag value (e.g. "park")
+ function nameMatchesRawTag(lowercaseName, tags) {
+ for (let i = 0; i < keysToTestForGenericValues.length; i++) {
+ let key = keysToTestForGenericValues[i];
+ let val = tags[key];
+ if (val) {
+ val = val.toLowerCase();
+ if (key === lowercaseName ||
+ val === lowercaseName ||
+ key.replace(/\_/g, ' ') === lowercaseName ||
+ val.replace(/\_/g, ' ') === lowercaseName) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ function isGenericName(name, tags) {
+ name = name.toLowerCase();
+ return nameMatchesRawTag(name, tags) || isDiscardedSuggestionName(name);
+ }
+
+ function makeGenericNameIssue(entityId, nameKey, genericName, langCode) {
+ return new validationIssue({
+ type: type,
+ subtype: 'generic_name',
+ severity: 'warning',
+ message: function(context) {
+ let entity = context.hasEntity(this.entityIds[0]);
+ if (!entity) return '';
+ let preset = _mainPresetIndex.match(entity, context.graph());
+ let langName = langCode && _mainLocalizer.languageName(langCode);
+ return _t('issues.generic_name.message' + (langName ? '_language' : ''),
+ { feature: preset.name(), name: genericName, language: langName }
+ );
+ },
+ reference: showReference,
+ entityIds: [entityId],
+ hash: nameKey + '=' + genericName,
+ dynamicFixes: function() {
+ return [
+ new validationIssueFix({
+ icon: 'iD-operation-delete',
+ title: _t('issues.fix.remove_the_name.title'),
+ onClick: function(context) {
+ let entityId = this.issue.entityIds[0];
+ let entity = context.entity(entityId);
+ let tags = Object.assign({}, entity.tags); // shallow copy
+ delete tags[nameKey];
+ context.perform(
+ actionChangeTags(entityId, tags), _t('issues.fix.remove_generic_name.annotation')
+ );
+ }
+ })
+ ];
+ }
+ });
+
+ function showReference(selection) {
+ selection.selectAll('.issue-reference')
+ .data([0])
+ .enter()
+ .append('div')
+ .attr('class', 'issue-reference')
+ .text(_t('issues.generic_name.reference'));
+ }
+ }
+
+ function makeIncorrectNameIssue(entityId, nameKey, incorrectName, langCode) {
+ return new validationIssue({
+ type: type,
+ subtype: 'not_name',
+ severity: 'warning',
+ message: function(context) {
+ const entity = context.hasEntity(this.entityIds[0]);
+ if (!entity) return '';
+ const preset = _mainPresetIndex.match(entity, context.graph());
+ const langName = langCode && _mainLocalizer.languageName(langCode);
+ return _t('issues.incorrect_name.message' + (langName ? '_language' : ''),
+ { feature: preset.name(), name: incorrectName, language: langName }
+ );
+ },
+ reference: showReference,
+ entityIds: [entityId],
+ hash: nameKey + '=' + incorrectName,
+ dynamicFixes: function() {
+ return [
+ new validationIssueFix({
+ icon: 'iD-operation-delete',
+ title: _t('issues.fix.remove_the_name.title'),
+ onClick: function(context) {
+ const entityId = this.issue.entityIds[0];
+ const entity = context.entity(entityId);
+ let tags = Object.assign({}, entity.tags); // shallow copy
+ delete tags[nameKey];
+ context.perform(
+ actionChangeTags(entityId, tags), _t('issues.fix.remove_mistaken_name.annotation')
+ );
+ }
+ })
+ ];
+ }
+ });
+
+ function showReference(selection) {
+ selection.selectAll('.issue-reference')
+ .data([0])
+ .enter()
+ .append('div')
+ .attr('class', 'issue-reference')
+ .text(_t('issues.generic_name.reference'));
+ }
+ }
+
+
+ let validation = function checkGenericName(entity) {
+ // a generic name is okay if it's a known brand or entity
+ if (entity.hasWikidata()) return [];
+
+ let issues = [];
+ const notNames = (entity.tags['not:name'] || '').split(';');
+
+ for (let key in entity.tags) {
+ const m = key.match(/^name(?:(?::)([a-zA-Z_-]+))?$/);
+ if (!m) continue;
+
+ const langCode = m.length >= 2 ? m[1] : null;
+ const value = entity.tags[key];
+ if (notNames.length) {
+ for (let i in notNames) {
+ const notName = notNames[i];
+ if (notName && value === notName) {
+ issues.push(makeIncorrectNameIssue(entity.id, key, value, langCode));
+ continue;
+ }
+ }
+ }
+ if (isGenericName(value, entity.tags)) {
+ issues.push(makeGenericNameIssue(entity.id, key, value, langCode));
+ }
+ }
+
+ return issues;
+ };
+
+
+ validation.type = type;
+
+ return validation;
+ }
+
+ function validationUnsquareWay(context) {
+ var type = 'unsquare_way';
+ var DEFAULT_DEG_THRESHOLD = 5; // see also issues.js
+
+ // use looser epsilon for detection to reduce warnings of buildings that are essentially square already
+ var epsilon = 0.05;
+ var nodeThreshold = 10;
+
+ function isBuilding(entity, graph) {
+ if (entity.type !== 'way' || entity.geometry(graph) !== 'area') return false;
+ return entity.tags.building && entity.tags.building !== 'no';
+ }
+
+
+ var validation = function checkUnsquareWay(entity, graph) {
+
+ if (!isBuilding(entity, graph)) return [];
+
+ // don't flag ways marked as physically unsquare
+ if (entity.tags.nonsquare === 'yes') return [];
+
+ var isClosed = entity.isClosed();
+ if (!isClosed) return []; // this building has bigger problems
+
+ // don't flag ways with lots of nodes since they are likely detail-mapped
+ var nodes = graph.childNodes(entity).slice(); // shallow copy
+ if (nodes.length > nodeThreshold + 1) return []; // +1 because closing node appears twice
+
+ // ignore if not all nodes are fully downloaded
+ var osm = services.osm;
+ if (!osm || nodes.some(function(node) { return !osm.isDataLoaded(node.loc); })) return [];
+
+ // don't flag connected ways to avoid unresolvable unsquare loops
+ var hasConnectedSquarableWays = nodes.some(function(node) {
+ return graph.parentWays(node).some(function(way) {
+ if (way.id === entity.id) return false;
+ if (isBuilding(way, graph)) return true;
+ return graph.parentRelations(way).some(function(parentRelation) {
+ return parentRelation.isMultipolygon() &&
+ parentRelation.tags.building &&
+ parentRelation.tags.building !== 'no';
+ });
+ });
+ });
+ if (hasConnectedSquarableWays) return [];
+
+
+ // user-configurable square threshold
+ var storedDegreeThreshold = corePreferences('validate-square-degrees');
+ var degreeThreshold = isNaN(storedDegreeThreshold) ? DEFAULT_DEG_THRESHOLD : parseFloat(storedDegreeThreshold);
+
+ var points = nodes.map(function(node) { return context.projection(node.loc); });
+ if (!geoOrthoCanOrthogonalize(points, isClosed, epsilon, degreeThreshold, true)) return [];
+
+ var autoArgs;
+ // don't allow autosquaring features linked to wikidata
+ if (!entity.tags.wikidata) {
+ // use same degree threshold as for detection
+ var autoAction = actionOrthogonalize(entity.id, context.projection, undefined, degreeThreshold);
+ autoAction.transitionable = false; // when autofixing, do it instantly
+ autoArgs = [autoAction, _t('operations.orthogonalize.annotation.feature.single')];
+ }
+
+ return [new validationIssue({
+ type: type,
+ subtype: 'building',
+ severity: 'warning',
+ message: function(context) {
+ var entity = context.hasEntity(this.entityIds[0]);
+ return entity ? _t('issues.unsquare_way.message', { feature: utilDisplayLabel(entity, context.graph()) }) : '';
+ },
+ reference: showReference,
+ entityIds: [entity.id],
+ hash: JSON.stringify(autoArgs !== undefined) + degreeThreshold,
+ autoArgs: autoArgs,
+ dynamicFixes: function() {
+ return [
+ new validationIssueFix({
+ icon: 'iD-operation-orthogonalize',
+ title: _t('issues.fix.square_feature.title'),
+ // autoArgs: autoArgs,
+ onClick: function(context, completionHandler) {
+ var entityId = this.issue.entityIds[0];
+ // use same degree threshold as for detection
+ context.perform(
+ actionOrthogonalize(entityId, context.projection, undefined, degreeThreshold),
+ _t('operations.orthogonalize.annotation.feature.single')
+ );
+ // run after the squaring transition (currently 150ms)
+ window.setTimeout(function() { completionHandler(); }, 175);
+ }
+ }),
+ /*
+ new validationIssueFix({
+ title: t('issues.fix.tag_as_unsquare.title'),
+ onClick: function(context) {
+ var entityId = this.issue.entityIds[0];
+ var entity = context.entity(entityId);
+ var tags = Object.assign({}, entity.tags); // shallow copy
+ tags.nonsquare = 'yes';
+ context.perform(
+ actionChangeTags(entityId, tags),
+ t('issues.fix.tag_as_unsquare.annotation')
+ );
+ }
+ })
+ */
+ ];
+ }
+ })];
+
+ function showReference(selection) {
+ selection.selectAll('.issue-reference')
+ .data([0])
+ .enter()
+ .append('div')
+ .attr('class', 'issue-reference')
+ .text(_t('issues.unsquare_way.buildings.reference'));
+ }
+ };
+
+ validation.type = type;
+
+ return validation;
+ }
+
+ var Validations = /*#__PURE__*/Object.freeze({
+ __proto__: null,
+ validationAlmostJunction: validationAlmostJunction,
+ validationCloseNodes: validationCloseNodes,
+ validationCrossingWays: validationCrossingWays,
+ validationDisconnectedWay: validationDisconnectedWay,
+ validationFormatting: validationFormatting,
+ validationHelpRequest: validationHelpRequest,
+ validationImpossibleOneway: validationImpossibleOneway,
+ validationIncompatibleSource: validationIncompatibleSource,
+ validationMaprules: validationMaprules,
+ validationMismatchedGeometry: validationMismatchedGeometry,
+ validationMissingRole: validationMissingRole,
+ validationMissingTag: validationMissingTag,
+ validationOutdatedTags: validationOutdatedTags,
+ validationPrivateData: validationPrivateData,
+ validationShortRoad: validationShortRoad,
+ validationYShapedConnection: validationYShapedConnection,
+ validationSuspiciousName: validationSuspiciousName,
+ validationUnsquareWay: validationUnsquareWay
+ });
+
+ function coreValidator(context) {
+ var dispatch$1 = dispatch('validated', 'focusedIssue');
+ var validator = utilRebind({}, dispatch$1, 'on');
+
+ var _rules = {};
+ var _disabledRules = {};
+
+ var _ignoredIssueIDs = {}; // issue.id -> true
+ var _baseCache = validationCache(); // issues before any user edits
+ var _headCache = validationCache(); // issues after all user edits
+ var _validatedGraph = null;
+ var _deferred = new Set();
+
+ //
+ // initialize the validator rulesets
+ //
+ validator.init = function() {
+ Object.values(Validations).forEach(function(validation) {
+ if (typeof validation !== 'function') return;
+
+ var fn = validation(context);
+ var key = fn.type;
+ _rules[key] = fn;
+ });
+
+ var disabledRules = corePreferences('validate-disabledRules');
+ if (disabledRules) {
+ disabledRules.split(',')
+ .forEach(function(key) { _disabledRules[key] = true; });
+ }
+ };
+
+
+ //
+ // clear caches, called whenever iD resets after a save
+ //
+ validator.reset = function() {
+ Array.from(_deferred).forEach(function(handle) {
+ window.cancelIdleCallback(handle);
+ _deferred.delete(handle);
+ });
+
+ // clear caches
+ _ignoredIssueIDs = {};
+ _baseCache = validationCache();
+ _headCache = validationCache();
+ _validatedGraph = null;
+ };
+
+ validator.resetIgnoredIssues = function() {
+ _ignoredIssueIDs = {};
+ // reload UI
+ dispatch$1.call('validated');
+ };
+
+
+ // must update issues when the user changes the unsquare thereshold
+ validator.reloadUnsquareIssues = function() {
+
+ reloadUnsquareIssues(_headCache, context.graph());
+ reloadUnsquareIssues(_baseCache, context.history().base());
+
+ dispatch$1.call('validated');
+ };
+
+ function reloadUnsquareIssues(cache, graph) {
+
+ var checkUnsquareWay = _rules.unsquare_way;
+ if (typeof checkUnsquareWay !== 'function') return;
+
+ // uncache existing
+ cache.uncacheIssuesOfType('unsquare_way');
+
+ var buildings = context.history().tree().intersects(geoExtent([-180,-90],[180, 90]), graph) // everywhere
+ .filter(function(entity) {
+ return entity.type === 'way' && entity.tags.building && entity.tags.building !== 'no';
+ });
+
+ // rerun for all buildings
+ buildings.forEach(function(entity) {
+ var detected = checkUnsquareWay(entity, graph);
+ if (detected.length !== 1) return;
+ var issue = detected[0];
+ if (!cache.issuesByEntityID[entity.id]) {
+ cache.issuesByEntityID[entity.id] = new Set();
+ }
+ cache.issuesByEntityID[entity.id].add(issue.id);
+ cache.issuesByIssueID[issue.id] = issue;
+ });
+ }
+
+ // options = {
+ // what: 'all', // 'all' or 'edited'
+ // where: 'all', // 'all' or 'visible'
+ // includeIgnored: false // true, false, or 'only'
+ // includeDisabledRules: false // true, false, or 'only'
+ // };
+ validator.getIssues = function(options) {
+ var opts = Object.assign({ what: 'all', where: 'all', includeIgnored: false, includeDisabledRules: false }, options);
+ var issues = Object.values(_headCache.issuesByIssueID);
+ var view = context.map().extent();
+
+ return issues.filter(function(issue) {
+ if (!issue) return false;
+ if (opts.includeDisabledRules === 'only' && !_disabledRules[issue.type]) return false;
+ if (!opts.includeDisabledRules && _disabledRules[issue.type]) return false;
+
+ if (opts.includeIgnored === 'only' && !_ignoredIssueIDs[issue.id]) return false;
+ if (!opts.includeIgnored && _ignoredIssueIDs[issue.id]) return false;
+
+ // Sanity check: This issue may be for an entity that not longer exists.
+ // If we detect this, uncache and return false so it is not included..
+ var entityIds = issue.entityIds || [];
+ for (var i = 0; i < entityIds.length; i++) {
+ var entityId = entityIds[i];
+ if (!context.hasEntity(entityId)) {
+ delete _headCache.issuesByEntityID[entityId];
+ delete _headCache.issuesByIssueID[issue.id];
+ return false;
+ }
+ }
+
+ if (opts.what === 'edited' && _baseCache.issuesByIssueID[issue.id]) return false;
+
+ if (opts.where === 'visible') {
+ var extent = issue.extent(context.graph());
+ if (!view.intersects(extent)) return false;
+ }
+
+ return true;
+ });
+ };
+
+ validator.getResolvedIssues = function() {
+ var baseIssues = Object.values(_baseCache.issuesByIssueID);
+ return baseIssues.filter(function(issue) {
+ return !_headCache.issuesByIssueID[issue.id];
+ });
+ };
+
+ validator.focusIssue = function(issue) {
+ var extent = issue.extent(context.graph());
+
+ if (extent) {
+ var setZoom = Math.max(context.map().zoom(), 19);
+ context.map().unobscuredCenterZoomEase(extent.center(), setZoom);
+
+ // select the first entity
+ if (issue.entityIds && issue.entityIds.length) {
+ window.setTimeout(function() {
+ var ids = issue.entityIds;
+ context.enter(modeSelect(context, [ids[0]]));
+ dispatch$1.call('focusedIssue', this, issue);
+ }, 250); // after ease
+ }
+ }
+ };
+
+
+ validator.getIssuesBySeverity = function(options) {
+ var groups = utilArrayGroupBy(validator.getIssues(options), 'severity');
+ groups.error = groups.error || [];
+ groups.warning = groups.warning || [];
+ return groups;
+ };
+
+ // show some issue types in a particular order
+ var orderedIssueTypes = [
+ // flag missing data first
+ 'missing_tag', 'missing_role',
+ // then flag identity issues
+ 'outdated_tags', 'mismatched_geometry',
+ // flag geometry issues where fixing them might solve connectivity issues
+ 'crossing_ways', 'almost_junction',
+ // then flag connectivity issues
+ 'disconnected_way', 'impossible_oneway'
+ ];
+
+ // returns the issues that the given entity IDs have in common, matching the given options
+ validator.getSharedEntityIssues = function(entityIDs, options) {
+ var cache = _headCache;
+
+ // gather the issues that are common to all the entities
+ var issueIDs = entityIDs.reduce(function(acc, entityID) {
+ var entityIssueIDs = cache.issuesByEntityID[entityID] || new Set();
+ if (!acc) {
+ return new Set(entityIssueIDs);
+ }
+ return new Set([...acc].filter(function(elem) {
+ return entityIssueIDs.has(elem);
+ }));
+ }, null) || [];
+
+ var opts = options || {};
+
+ return Array.from(issueIDs)
+ .map(function(id) { return cache.issuesByIssueID[id]; })
+ .filter(function(issue) {
+ if (!issue) return false;
+ if (opts.includeDisabledRules === 'only' && !_disabledRules[issue.type]) return false;
+ if (!opts.includeDisabledRules && _disabledRules[issue.type]) return false;
+
+ if (opts.includeIgnored === 'only' && !_ignoredIssueIDs[issue.id]) return false;
+ if (!opts.includeIgnored && _ignoredIssueIDs[issue.id]) return false;
+
+ return true;
+ }).sort(function(issue1, issue2) {
+ if (issue1.type === issue2.type) {
+ // issues of the same type, sort deterministically
+ return issue1.id < issue2.id ? -1 : 1;
+ }
+ var index1 = orderedIssueTypes.indexOf(issue1.type);
+ var index2 = orderedIssueTypes.indexOf(issue2.type);
+ if (index1 !== -1 && index2 !== -1) {
+ // both issue types have explicit sort orders
+ return index1 - index2;
+ } else if (index1 === -1 && index2 === -1) {
+ // neither issue type has an explicit sort order, sort by type
+ return issue1.type < issue2.type ? -1 : 1;
+ } else {
+ // order explicit types before everything else
+ return index1 !== -1 ? -1 : 1;
+ }
+ });
+ };
+
+
+ validator.getEntityIssues = function(entityID, options) {
+ return validator.getSharedEntityIssues([entityID], options);
+ };
+
+
+ validator.getRuleKeys = function() {
+ return Object.keys(_rules);
+ };
+
+
+ validator.isRuleEnabled = function(key) {
+ return !_disabledRules[key];
+ };
+
+
+ validator.toggleRule = function(key) {
+ if (_disabledRules[key]) {
+ delete _disabledRules[key];
+ } else {
+ _disabledRules[key] = true;
+ }
+
+ corePreferences('validate-disabledRules', Object.keys(_disabledRules).join(','));
+ validator.validate();
+ };
+
+
+ validator.disableRules = function(keys) {
+ _disabledRules = {};
+ keys.forEach(function(k) {
+ _disabledRules[k] = true;
+ });
+
+ corePreferences('validate-disabledRules', Object.keys(_disabledRules).join(','));
+ validator.validate();
+ };
+
+
+ validator.ignoreIssue = function(id) {
+ _ignoredIssueIDs[id] = true;
+ };
+
+
+ //
+ // Run validation on a single entity for the given graph
+ //
+ function validateEntity(entity, graph) {
+ var entityIssues = [];
+
+ // runs validation and appends resulting issues
+ function runValidation(key) {
+
+ var fn = _rules[key];
+ if (typeof fn !== 'function') {
+ console.error('no such validation rule = ' + key); // eslint-disable-line no-console
+ return;
+ }
+
+ var detected = fn(entity, graph);
+ entityIssues = entityIssues.concat(detected);
+ }
+
+ // run all rules
+ Object.keys(_rules).forEach(runValidation);
+
+ return entityIssues;
+ }
+
+ function entityIDsToValidate(entityIDs, graph) {
+ var processedIDs = new Set();
+ return entityIDs.reduce(function(acc, entityID) {
+ // keep redundancy check separate from `acc` because an `entityID`
+ // could have been added to `acc` as a related entity through an earlier pass
+ if (processedIDs.has(entityID)) return acc;
+ processedIDs.add(entityID);
+
+ var entity = graph.hasEntity(entityID);
+ if (!entity) return acc;
+
+ acc.add(entityID);
+
+ var checkParentRels = [entity];
+
+ if (entity.type === 'node') {
+ graph.parentWays(entity).forEach(function(parentWay) {
+ acc.add(parentWay.id); // include parent ways
+ checkParentRels.push(parentWay);
+ });
+ } else if (entity.type === 'relation') {
+ entity.members.forEach(function(member) {
+ acc.add(member.id); // include members
+ });
+ } else if (entity.type === 'way') {
+ entity.nodes.forEach(function(nodeID) {
+ acc.add(nodeID); // include child nodes
+ graph._parentWays[nodeID].forEach(function(wayID) {
+ acc.add(wayID); // include connected ways
+ });
+ });
+ }
+
+ checkParentRels.forEach(function(entity) { // include parent relations
+ if (entity.type !== 'relation') { // but not super-relations
+ graph.parentRelations(entity).forEach(function(parentRelation) {
+ acc.add(parentRelation.id);
+ });
+ }
+ });
+
+ return acc;
+
+ }, new Set());
+ }
+
+ //
+ // Run validation for several entities, supplied `entityIDs`,
+ // against `graph` for the given `cache`
+ //
+ function validateEntities(entityIDs, graph, cache) {
+
+ // clear caches for existing issues related to these entities
+ entityIDs.forEach(cache.uncacheEntityID);
+
+ // detect new issues and update caches
+ entityIDs.forEach(function(entityID) {
+ var entity = graph.hasEntity(entityID);
+ // don't validate deleted entities
+ if (!entity) return;
+
+ var issues = validateEntity(entity, graph);
+ cache.cacheIssues(issues);
+ });
+ }
+
+
+ //
+ // Validates anything that has changed since the last time it was run.
+ // Also updates the "validatedGraph" to be the current graph
+ // and dispatches a `validated` event when finished.
+ //
+ validator.validate = function() {
+
+ var currGraph = context.graph();
+ _validatedGraph = _validatedGraph || context.history().base();
+ if (currGraph === _validatedGraph) {
+ dispatch$1.call('validated');
+ return;
+ }
+ var oldGraph = _validatedGraph;
+ var difference = coreDifference(oldGraph, currGraph);
+ _validatedGraph = currGraph;
+
+ var createdAndModifiedEntityIDs = difference.extantIDs(true); // created/modified (true = w/relation members)
+ var entityIDsToCheck = entityIDsToValidate(createdAndModifiedEntityIDs, currGraph);
+
+ // check modified and deleted entities against the old graph in order to update their related entities
+ // (e.g. deleting the only highway connected to a road should create a disconnected highway issue)
+ var modifiedAndDeletedEntityIDs = difference.deleted().concat(difference.modified())
+ .map(function(entity) { return entity.id; });
+ var entityIDsToCheckForOldGraph = entityIDsToValidate(modifiedAndDeletedEntityIDs, oldGraph);
+
+ // concat the sets
+ entityIDsToCheckForOldGraph.forEach(entityIDsToCheck.add, entityIDsToCheck);
+
+ validateEntities(entityIDsToCheck, context.graph(), _headCache);
+
+ dispatch$1.call('validated');
+ };
+
+
+ // WHEN TO RUN VALIDATION:
+ // When graph changes:
+ context.history()
+ .on('restore.validator', validator.validate) // restore saved history
+ .on('undone.validator', validator.validate) // undo
+ .on('redone.validator', validator.validate); // redo
+ // but not on 'change' (e.g. while drawing)
+
+ // When user chages editing modes:
+ context
+ .on('exit.validator', validator.validate);
+
+ // When merging fetched data:
+ context.history()
+ .on('merge.validator', function(entities) {
+ if (!entities) return;
+ var handle = window.requestIdleCallback(function() {
+ var entityIDs = entities.map(function(entity) { return entity.id; });
+ var headGraph = context.graph();
+ validateEntities(entityIDsToValidate(entityIDs, headGraph), headGraph, _headCache);
+
+ var baseGraph = context.history().base();
+ validateEntities(entityIDsToValidate(entityIDs, baseGraph), baseGraph, _baseCache);
+
+ dispatch$1.call('validated');
+ });
+ _deferred.add(handle);
+ });
+
+
+ return validator;
+ }
+
+
+ function validationCache() {
+
+ var cache = {
+ issuesByIssueID: {}, // issue.id -> issue
+ issuesByEntityID: {} // entity.id -> set(issue.id)
+ };
+
+ cache.cacheIssues = function(issues) {
+ issues.forEach(function(issue) {
+ var entityIds = issue.entityIds || [];
+ entityIds.forEach(function(entityId) {
+ if (!cache.issuesByEntityID[entityId]) {
+ cache.issuesByEntityID[entityId] = new Set();
+ }
+ cache.issuesByEntityID[entityId].add(issue.id);
+ });
+ cache.issuesByIssueID[issue.id] = issue;
+ });
+ };
+
+ cache.uncacheIssue = function(issue) {
+ // When multiple entities are involved (e.g. crossing_ways),
+ // remove this issue from the other entity caches too..
+ var entityIds = issue.entityIds || [];
+ entityIds.forEach(function(entityId) {
+ if (cache.issuesByEntityID[entityId]) {
+ cache.issuesByEntityID[entityId].delete(issue.id);
+ }
+ });
+ delete cache.issuesByIssueID[issue.id];
+ };
+
+ cache.uncacheIssues = function(issues) {
+ issues.forEach(cache.uncacheIssue);
+ };
+
+ cache.uncacheIssuesOfType = function(type) {
+ var issuesOfType = Object.values(cache.issuesByIssueID)
+ .filter(function(issue) { return issue.type === type; });
+ cache.uncacheIssues(issuesOfType);
+ };
+
+ //
+ // Remove a single entity and all its related issues from the caches
+ //
+ cache.uncacheEntityID = function(entityID) {
+ var issueIDs = cache.issuesByEntityID[entityID];
+ if (!issueIDs) return;
+
+ issueIDs.forEach(function(issueID) {
+ var issue = cache.issuesByIssueID[issueID];
+ if (issue) {
+ cache.uncacheIssue(issue);
+ } else {
+ delete cache.issuesByIssueID[issueID];
+ }
+ });
+
+ delete cache.issuesByEntityID[entityID];
+ };
+
+ return cache;
+ }
+
+ function coreUploader(context) {
+
+ var dispatch$1 = dispatch(
+ // Start and end events are dispatched exactly once each per legitimate outside call to `save`
+ 'saveStarted', // dispatched as soon as a call to `save` has been deemed legitimate
+ 'saveEnded', // dispatched after the result event has been dispatched
+
+ 'willAttemptUpload', // dispatched before the actual upload call occurs, if it will
+ 'progressChanged',
+
+ // Each save results in one of these outcomes:
+ 'resultNoChanges', // upload wasn't attempted since there were no edits
+ 'resultErrors', // upload failed due to errors
+ 'resultConflicts', // upload failed due to data conflicts
+ 'resultSuccess' // upload completed without errors
+ );
+
+ var _isSaving = false;
+
+ var _conflicts = [];
+ var _errors = [];
+ var _origChanges;
+
+ var _discardTags = {};
+ _mainFileFetcher.get('discarded')
+ .then(function(d) { _discardTags = d; })
+ .catch(function() { /* ignore */ });
+
+ var uploader = utilRebind({}, dispatch$1, 'on');
+
+ uploader.isSaving = function() {
+ return _isSaving;
+ };
+
+ uploader.save = function(changeset, tryAgain, checkConflicts) {
+ // Guard against accidentally entering save code twice - #4641
+ if (_isSaving && !tryAgain) {
+ return;
+ }
+
+ var osm = context.connection();
+ if (!osm) return;
+
+ // If user somehow got logged out mid-save, try to reauthenticate..
+ // This can happen if they were logged in from before, but the tokens are no longer valid.
+ if (!osm.authenticated()) {
+ osm.authenticate(function(err) {
+ if (!err) {
+ uploader.save(changeset, tryAgain, checkConflicts); // continue where we left off..
+ }
+ });
+ return;
+ }
+
+ if (!_isSaving) {
+ _isSaving = true;
+ dispatch$1.call('saveStarted', this);
+ }
+
+ var history = context.history();
+
+ _conflicts = [];
+ _errors = [];
+
+ // Store original changes, in case user wants to download them as an .osc file
+ _origChanges = history.changes(actionDiscardTags(history.difference(), _discardTags));
+
+ // First time, `history.perform` a no-op action.
+ // Any conflict resolutions will be done as `history.replace`
+ // Remember to pop this later if needed
+ if (!tryAgain) {
+ history.perform(actionNoop());
+ }
+
+ // Attempt a fast upload.. If there are conflicts, re-enter with `checkConflicts = true`
+ if (!checkConflicts) {
+ upload(changeset);
+
+ // Do the full (slow) conflict check..
+ } else {
+ performFullConflictCheck(changeset);
+ }
+
+ };
+
+
+ function performFullConflictCheck(changeset) {
+
+ var osm = context.connection();
+ if (!osm) return;
+
+ var history = context.history();
+
+ var localGraph = context.graph();
+ var remoteGraph = coreGraph(history.base(), true);
+
+ var summary = history.difference().summary();
+ var _toCheck = [];
+ for (var i = 0; i < summary.length; i++) {
+ var item = summary[i];
+ if (item.changeType === 'modified') {
+ _toCheck.push(item.entity.id);
+ }
+ }
+
+ var _toLoad = withChildNodes(_toCheck, localGraph);
+ var _loaded = {};
+ var _toLoadCount = 0;
+ var _toLoadTotal = _toLoad.length;
+
+ if (_toCheck.length) {
+ dispatch$1.call('progressChanged', this, _toLoadCount, _toLoadTotal);
+ _toLoad.forEach(function(id) { _loaded[id] = false; });
+ osm.loadMultiple(_toLoad, loaded);
+ } else {
+ upload(changeset);
+ }
+
+ return;
+
+ function withChildNodes(ids, graph) {
+ var s = new Set(ids);
+ ids.forEach(function(id) {
+ var entity = graph.entity(id);
+ if (entity.type !== 'way') return;
+
+ graph.childNodes(entity).forEach(function(child) {
+ if (child.version !== undefined) {
+ s.add(child.id);
+ }
+ });
+ });
+
+ return Array.from(s);
+ }
+
+
+ // Reload modified entities into an alternate graph and check for conflicts..
+ function loaded(err, result) {
+ if (_errors.length) return;
+
+ if (err) {
+ _errors.push({
+ msg: err.message || err.responseText,
+ details: [ _t('save.status_code', { code: err.status }) ]
+ });
+ didResultInErrors();
+
+ } else {
+ var loadMore = [];
+
+ result.data.forEach(function(entity) {
+ remoteGraph.replace(entity);
+ _loaded[entity.id] = true;
+ _toLoad = _toLoad.filter(function(val) { return val !== entity.id; });
+
+ if (!entity.visible) return;
+
+ // Because loadMultiple doesn't download /full like loadEntity,
+ // need to also load children that aren't already being checked..
+ var i, id;
+ if (entity.type === 'way') {
+ for (i = 0; i < entity.nodes.length; i++) {
+ id = entity.nodes[i];
+ if (_loaded[id] === undefined) {
+ _loaded[id] = false;
+ loadMore.push(id);
+ }
+ }
+ } else if (entity.type === 'relation' && entity.isMultipolygon()) {
+ for (i = 0; i < entity.members.length; i++) {
+ id = entity.members[i].id;
+ if (_loaded[id] === undefined) {
+ _loaded[id] = false;
+ loadMore.push(id);
+ }
+ }
+ }
+ });
+
+ _toLoadCount += result.data.length;
+ _toLoadTotal += loadMore.length;
+ dispatch$1.call('progressChanged', this, _toLoadCount, _toLoadTotal);
+
+ if (loadMore.length) {
+ _toLoad.push.apply(_toLoad, loadMore);
+ osm.loadMultiple(loadMore, loaded);
+ }
+
+ if (!_toLoad.length) {
+ detectConflicts();
+ upload(changeset);
+ }
+ }
+ }
+
+
+ function detectConflicts() {
+ function choice(id, text, action) {
+ return {
+ id: id,
+ text: text,
+ action: function() {
+ history.replace(action);
+ }
+ };
+ }
+ function formatUser(d) {
+ return '' + d + ' ';
+ }
+ function entityName(entity) {
+ return utilDisplayName(entity) || (utilDisplayType(entity.id) + ' ' + entity.id);
+ }
+
+ function sameVersions(local, remote) {
+ if (local.version !== remote.version) return false;
+
+ if (local.type === 'way') {
+ var children = utilArrayUnion(local.nodes, remote.nodes);
+ for (var i = 0; i < children.length; i++) {
+ var a = localGraph.hasEntity(children[i]);
+ var b = remoteGraph.hasEntity(children[i]);
+ if (a && b && a.version !== b.version) return false;
+ }
+ }
+
+ return true;
+ }
+
+ _toCheck.forEach(function(id) {
+ var local = localGraph.entity(id);
+ var remote = remoteGraph.entity(id);
+
+ if (sameVersions(local, remote)) return;
+
+ var merge = actionMergeRemoteChanges(id, localGraph, remoteGraph, _discardTags, formatUser);
+
+ history.replace(merge);
+
+ var mergeConflicts = merge.conflicts();
+ if (!mergeConflicts.length) return; // merged safely
+
+ var forceLocal = actionMergeRemoteChanges(id, localGraph, remoteGraph, _discardTags).withOption('force_local');
+ var forceRemote = actionMergeRemoteChanges(id, localGraph, remoteGraph, _discardTags).withOption('force_remote');
+ var keepMine = _t('save.conflict.' + (remote.visible ? 'keep_local' : 'restore'));
+ var keepTheirs = _t('save.conflict.' + (remote.visible ? 'keep_remote' : 'delete'));
+
+ _conflicts.push({
+ id: id,
+ name: entityName(local),
+ details: mergeConflicts,
+ chosen: 1,
+ choices: [
+ choice(id, keepMine, forceLocal),
+ choice(id, keepTheirs, forceRemote)
+ ]
+ });
+ });
+ }
+ }
+
+
+ function upload(changeset) {
+ var osm = context.connection();
+ if (!osm) {
+ _errors.push({ msg: 'No OSM Service' });
+ }
+
+ if (_conflicts.length) {
+ didResultInConflicts(changeset);
+
+ } else if (_errors.length) {
+ didResultInErrors();
+
+ } else {
+ var history = context.history();
+ var changes = history.changes(actionDiscardTags(history.difference(), _discardTags));
+ if (changes.modified.length || changes.created.length || changes.deleted.length) {
+
+ dispatch$1.call('willAttemptUpload', this);
+
+ osm.putChangeset(changeset, changes, uploadCallback);
+
+ } else {
+ // changes were insignificant or reverted by user
+ didResultInNoChanges();
+ }
+ }
+ }
+
+
+ function uploadCallback(err, changeset) {
+ if (err) {
+ if (err.status === 409) { // 409 Conflict
+ uploader.save(changeset, true, true); // tryAgain = true, checkConflicts = true
+ } else {
+ _errors.push({
+ msg: err.message || err.responseText,
+ details: [ _t('save.status_code', { code: err.status }) ]
+ });
+ didResultInErrors();
+ }
+
+ } else {
+ didResultInSuccess(changeset);
+ }
+ }
+
+ function didResultInNoChanges() {
+
+ dispatch$1.call('resultNoChanges', this);
+
+ endSave();
+
+ context.flush(); // reset iD
+ }
+
+ function didResultInErrors() {
+
+ context.history().pop();
+
+ dispatch$1.call('resultErrors', this, _errors);
+
+ endSave();
+ }
+
+
+ function didResultInConflicts(changeset) {
+
+ _conflicts.sort(function(a, b) { return b.id.localeCompare(a.id); });
+
+ dispatch$1.call('resultConflicts', this, changeset, _conflicts, _origChanges);
+
+ endSave();
+ }
+
+
+ function didResultInSuccess(changeset) {
+
+ // delete the edit stack cached to local storage
+ context.history().clearSaved();
+
+ dispatch$1.call('resultSuccess', this, changeset);
+
+ // Add delay to allow for postgres replication #1646 #2678
+ window.setTimeout(function() {
+
+ endSave();
+
+ context.flush(); // reset iD
+ }, 2500);
+ }
+
+
+ function endSave() {
+ _isSaving = false;
+
+ dispatch$1.call('saveEnded', this);
+ }
+
+
+ uploader.cancelConflictResolution = function() {
+ context.history().pop();
+ };
+
+
+ uploader.processResolvedConflicts = function(changeset) {
+ var history = context.history();
+
+ for (var i = 0; i < _conflicts.length; i++) {
+ if (_conflicts[i].chosen === 1) { // user chose "use theirs"
+ var entity = context.hasEntity(_conflicts[i].id);
+ if (entity && entity.type === 'way') {
+ var children = utilArrayUniq(entity.nodes);
+ for (var j = 0; j < children.length; j++) {
+ history.replace(actionRevert(children[j]));
+ }
+ }
+ history.replace(actionRevert(_conflicts[i].id));
+ }
+ }
+
+ uploader.save(changeset, true, false); // tryAgain = true, checkConflicts = false
+ };
+
+
+ uploader.reset = function() {
+
+ };
+
+
+ return uploader;
+ }
+
+ function coreContext() {
+ const dispatch$1 = dispatch('enter', 'exit', 'change');
+ let context = utilRebind({}, dispatch$1, 'on');
+ let _deferred = new Set();
+
+ context.version = '2.18.3';
+ context.privacyVersion = '20200407';
+
+ // iD will alter the hash so cache the parameters intended to setup the session
+ context.initialHashParams = window.location.hash ? utilStringQs(window.location.hash) : {};
+
+ context.isFirstSession = !corePreferences('sawSplash') && !corePreferences('sawPrivacyVersion');
+
+ /* Changeset */
+ // An osmChangeset object. Not loaded until needed.
+ context.changeset = null;
+
+ let _defaultChangesetComment = context.initialHashParams.comment;
+ let _defaultChangesetSource = context.initialHashParams.source;
+ let _defaultChangesetHashtags = context.initialHashParams.hashtags;
+ context.defaultChangesetComment = function(val) {
+ if (!arguments.length) return _defaultChangesetComment;
+ _defaultChangesetComment = val;
+ return context;
+ };
+ context.defaultChangesetSource = function(val) {
+ if (!arguments.length) return _defaultChangesetSource;
+ _defaultChangesetSource = val;
+ return context;
+ };
+ context.defaultChangesetHashtags = function(val) {
+ if (!arguments.length) return _defaultChangesetHashtags;
+ _defaultChangesetHashtags = val;
+ return context;
+ };
+
+ /* Document title */
+ /* (typically shown as the label for the browser window/tab) */
+
+ // If true, iD will update the title based on what the user is doing
+ let _setsDocumentTitle = true;
+ context.setsDocumentTitle = function(val) {
+ if (!arguments.length) return _setsDocumentTitle;
+ _setsDocumentTitle = val;
+ return context;
+ };
+ // The part of the title that is always the same
+ let _documentTitleBase = document.title;
+ context.documentTitleBase = function(val) {
+ if (!arguments.length) return _documentTitleBase;
+ _documentTitleBase = val;
+ return context;
+ };
+
+
+ /* User interface and keybinding */
+ let _ui;
+ context.ui = () => _ui;
+ context.lastPointerType = () => _ui.lastPointerType();
+
+ let _keybinding = utilKeybinding('context');
+ context.keybinding = () => _keybinding;
+ select(document).call(_keybinding);
+
+
+ /* Straight accessors. Avoid using these if you can. */
+ // Instantiate the connection here because it doesn't require passing in
+ // `context` and it's needed for pre-init calls like `preauth`
+ let _connection = services.osm;
+ let _history;
+ let _validator;
+ let _uploader;
+ context.connection = () => _connection;
+ context.history = () => _history;
+ context.validator = () => _validator;
+ context.uploader = () => _uploader;
+
+ /* Connection */
+ context.preauth = (options) => {
+ if (_connection) {
+ _connection.switch(options);
+ }
+ return context;
+ };
+
+ /* connection options for source switcher (optional) */
+ let _apiConnections;
+ context.apiConnections = function(val) {
+ if (!arguments.length) return _apiConnections;
+ _apiConnections = val;
+ return context;
+ };
+
+
+ // A string or array or locale codes to prefer over the browser's settings
+ context.locale = function(locale) {
+ if (!arguments.length) return _mainLocalizer.localeCode();
+ _mainLocalizer.preferredLocaleCodes(locale);
+ return context;
+ };
+
+
+ function afterLoad(cid, callback) {
+ return (err, result) => {
+ if (err) {
+ // 400 Bad Request, 401 Unauthorized, 403 Forbidden..
+ if (err.status === 400 || err.status === 401 || err.status === 403) {
+ if (_connection) {
+ _connection.logout();
+ }
+ }
+ if (typeof callback === 'function') {
+ callback(err);
+ }
+ return;
+
+ } else if (_connection && _connection.getConnectionId() !== cid) {
+ if (typeof callback === 'function') {
+ callback({ message: 'Connection Switched', status: -1 });
+ }
+ return;
+
+ } else {
+ _history.merge(result.data, result.extent);
+ if (typeof callback === 'function') {
+ callback(err, result);
+ }
+ return;
+ }
+ };
+ }
+
+
+ context.loadTiles = (projection, callback) => {
+ const handle = window.requestIdleCallback(() => {
+ _deferred.delete(handle);
+ if (_connection && context.editableDataEnabled()) {
+ const cid = _connection.getConnectionId();
+ _connection.loadTiles(projection, afterLoad(cid, callback));
+ }
+ });
+ _deferred.add(handle);
+ };
+
+ context.loadTileAtLoc = (loc, callback) => {
+ const handle = window.requestIdleCallback(() => {
+ _deferred.delete(handle);
+ if (_connection && context.editableDataEnabled()) {
+ const cid = _connection.getConnectionId();
+ _connection.loadTileAtLoc(loc, afterLoad(cid, callback));
+ }
+ });
+ _deferred.add(handle);
+ };
+
+ context.loadEntity = (entityID, callback) => {
+ if (_connection) {
+ const cid = _connection.getConnectionId();
+ _connection.loadEntity(entityID, afterLoad(cid, callback));
+ }
+ };
+
+ context.zoomToEntity = (entityID, zoomTo) => {
+ if (zoomTo !== false) {
+ context.loadEntity(entityID, (err, result) => {
+ if (err) return;
+ const entity = result.data.find(e => e.id === entityID);
+ if (entity) {
+ _map.zoomTo(entity);
+ }
+ });
+ }
+
+ _map.on('drawn.zoomToEntity', () => {
+ if (!context.hasEntity(entityID)) return;
+ _map.on('drawn.zoomToEntity', null);
+ context.on('enter.zoomToEntity', null);
+ context.enter(modeSelect(context, [entityID]));
+ });
+
+ context.on('enter.zoomToEntity', () => {
+ if (_mode.id !== 'browse') {
+ _map.on('drawn.zoomToEntity', null);
+ context.on('enter.zoomToEntity', null);
+ }
+ });
+ };
+
+ let _minEditableZoom = 16;
+ context.minEditableZoom = function(val) {
+ if (!arguments.length) return _minEditableZoom;
+ _minEditableZoom = val;
+ if (_connection) {
+ _connection.tileZoom(val);
+ }
+ return context;
+ };
+
+ // String length limits in Unicode characters, not JavaScript UTF-16 code units
+ context.maxCharsForTagKey = () => 255;
+ context.maxCharsForTagValue = () => 255;
+ context.maxCharsForRelationRole = () => 255;
+
+ function cleanOsmString(val, maxChars) {
+ // be lenient with input
+ if (val === undefined || val === null) {
+ val = '';
+ } else {
+ val = val.toString();
+ }
+
+ // remove whitespace
+ val = val.trim();
+
+ // use the canonical form of the string
+ if (val.normalize) val = val.normalize('NFC');
+
+ // trim to the number of allowed characters
+ return utilUnicodeCharsTruncated(val, maxChars);
+ }
+ context.cleanTagKey = (val) => cleanOsmString(val, context.maxCharsForTagKey());
+ context.cleanTagValue = (val) => cleanOsmString(val, context.maxCharsForTagValue());
+ context.cleanRelationRole = (val) => cleanOsmString(val, context.maxCharsForRelationRole());
+
+
+ /* History */
+ let _inIntro = false;
+ context.inIntro = function(val) {
+ if (!arguments.length) return _inIntro;
+ _inIntro = val;
+ return context;
+ };
+
+ // Immediately save the user's history to localstorage, if possible
+ // This is called someteimes, but also on the `window.onbeforeunload` handler
+ context.save = () => {
+ // no history save, no message onbeforeunload
+ if (_inIntro || context.container().select('.modal').size()) return;
+
+ let canSave;
+ if (_mode && _mode.id === 'save') {
+ canSave = false;
+
+ // Attempt to prevent user from creating duplicate changes - see #5200
+ if (services.osm && services.osm.isChangesetInflight()) {
+ _history.clearSaved();
+ return;
+ }
+
+ } else {
+ canSave = context.selectedIDs().every(id => {
+ const entity = context.hasEntity(id);
+ return entity && !entity.isDegenerate();
+ });
+ }
+
+ if (canSave) {
+ _history.save();
+ }
+ if (_history.hasChanges()) {
+ return _t('save.unsaved_changes');
+ }
+ };
+
+ // Debounce save, since it's a synchronous localStorage write,
+ // and history changes can happen frequently (e.g. when dragging).
+ context.debouncedSave = debounce(context.save, 350);
+
+ function withDebouncedSave(fn) {
+ return function() {
+ const result = fn.apply(_history, arguments);
+ context.debouncedSave();
+ return result;
+ };
+ }
+
+
+ /* Graph */
+ context.hasEntity = (id) => _history.graph().hasEntity(id);
+ context.entity = (id) => _history.graph().entity(id);
+
+
+ /* Modes */
+ let _mode;
+ context.mode = () => _mode;
+ context.enter = (newMode) => {
+ if (_mode) {
+ _mode.exit();
+ dispatch$1.call('exit', this, _mode);
+ }
+
+ _mode = newMode;
+ _mode.enter();
+ dispatch$1.call('enter', this, _mode);
+ };
+
+ context.selectedIDs = () => (_mode && _mode.selectedIDs && _mode.selectedIDs()) || [];
+ context.activeID = () => _mode && _mode.activeID && _mode.activeID();
+
+ let _selectedNoteID;
+ context.selectedNoteID = function(noteID) {
+ if (!arguments.length) return _selectedNoteID;
+ _selectedNoteID = noteID;
+ return context;
+ };
+
+ // NOTE: Don't change the name of this until UI v3 is merged
+ let _selectedErrorID;
+ context.selectedErrorID = function(errorID) {
+ if (!arguments.length) return _selectedErrorID;
+ _selectedErrorID = errorID;
+ return context;
+ };
+
+
+ /* Behaviors */
+ context.install = (behavior) => context.surface().call(behavior);
+ context.uninstall = (behavior) => context.surface().call(behavior.off);
+
+
+ /* Copy/Paste */
+ let _copyGraph;
+ context.copyGraph = () => _copyGraph;
+
+ let _copyIDs = [];
+ context.copyIDs = function(val) {
+ if (!arguments.length) return _copyIDs;
+ _copyIDs = val;
+ _copyGraph = _history.graph();
+ return context;
+ };
+
+ let _copyLonLat;
+ context.copyLonLat = function(val) {
+ if (!arguments.length) return _copyLonLat;
+ _copyLonLat = val;
+ return context;
+ };
+
+
+ /* Background */
+ let _background;
+ context.background = () => _background;
+
+
+ /* Features */
+ let _features;
+ context.features = () => _features;
+ context.hasHiddenConnections = (id) => {
+ const graph = _history.graph();
+ const entity = graph.entity(id);
+ return _features.hasHiddenConnections(entity, graph);
+ };
+
+
+ /* Photos */
+ let _photos;
+ context.photos = () => _photos;
+
+
+ /* Map */
+ let _map;
+ context.map = () => _map;
+ context.layers = () => _map.layers();
+ context.surface = () => _map.surface;
+ context.editableDataEnabled = () => _map.editableDataEnabled();
+ context.surfaceRect = () => _map.surface.node().getBoundingClientRect();
+ context.editable = () => {
+ // don't allow editing during save
+ const mode = context.mode();
+ if (!mode || mode.id === 'save') return false;
+ return _map.editableDataEnabled();
+ };
+
+
+ /* Debug */
+ let _debugFlags = {
+ tile: false, // tile boundaries
+ collision: false, // label collision bounding boxes
+ imagery: false, // imagery bounding polygons
+ target: false, // touch targets
+ downloaded: false // downloaded data from osm
+ };
+ context.debugFlags = () => _debugFlags;
+ context.getDebug = (flag) => flag && _debugFlags[flag];
+ context.setDebug = function(flag, val) {
+ if (arguments.length === 1) val = true;
+ _debugFlags[flag] = val;
+ dispatch$1.call('change');
+ return context;
+ };
+
+
+ /* Container */
+ let _container = select(null);
+ context.container = function(val) {
+ if (!arguments.length) return _container;
+ _container = val;
+ _container.classed('ideditor', true);
+ return context;
+ };
+ context.containerNode = function(val) {
+ if (!arguments.length) return context.container().node();
+ context.container(select(val));
+ return context;
+ };
+
+ let _embed;
+ context.embed = function(val) {
+ if (!arguments.length) return _embed;
+ _embed = val;
+ return context;
+ };
+
+
+ /* Assets */
+ let _assetPath = '';
+ context.assetPath = function(val) {
+ if (!arguments.length) return _assetPath;
+ _assetPath = val;
+ _mainFileFetcher.assetPath(val);
+ return context;
+ };
+
+ let _assetMap = {};
+ context.assetMap = function(val) {
+ if (!arguments.length) return _assetMap;
+ _assetMap = val;
+ _mainFileFetcher.assetMap(val);
+ return context;
+ };
+
+ context.asset = (val) => {
+ if (/^http(s)?:\/\//i.test(val)) return val;
+ const filename = _assetPath + val;
+ return _assetMap[filename] || filename;
+ };
+
+ context.imagePath = (val) => context.asset(`img/${val}`);
+
+
+ /* reset (aka flush) */
+ context.reset = context.flush = () => {
+ context.debouncedSave.cancel();
+
+ Array.from(_deferred).forEach(handle => {
+ window.cancelIdleCallback(handle);
+ _deferred.delete(handle);
+ });
+
+ Object.values(services).forEach(service => {
+ if (service && typeof service.reset === 'function') {
+ service.reset(context);
+ }
+ });
+
+ context.changeset = null;
+
+ _validator.reset();
+ _features.reset();
+ _history.reset();
+ _uploader.reset();
+
+ // don't leave stale state in the inspector
+ context.container().select('.inspector-wrap *').remove();
+
+ return context;
+ };
+
+
+ /* Projections */
+ context.projection = geoRawMercator();
+ context.curtainProjection = geoRawMercator();
+
+ /* RapiD */
+ let _rapidContext;
+ context.rapidContext = () => _rapidContext;
+
+
+ /* Init */
+ context.init = () => {
+
+ instantiateInternal();
+
+ initializeDependents();
+
+ return context;
+
+ // Load variables and properties. No property of `context` should be accessed
+ // until this is complete since load statuses are indeterminate. The order
+ // of instantiation shouldn't matter.
+ function instantiateInternal() {
+
+ _history = coreHistory(context);
+ context.graph = _history.graph;
+ context.pauseChangeDispatch = _history.pauseChangeDispatch;
+ context.resumeChangeDispatch = _history.resumeChangeDispatch;
+ context.perform = withDebouncedSave(_history.perform);
+ context.replace = withDebouncedSave(_history.replace);
+ context.pop = withDebouncedSave(_history.pop);
+ context.overwrite = withDebouncedSave(_history.overwrite);
+ context.undo = withDebouncedSave(_history.undo);
+ context.redo = withDebouncedSave(_history.redo);
+
+ _rapidContext = coreRapidContext(context);
+ _validator = coreValidator(context);
+ _uploader = coreUploader(context);
+
+ _background = rendererBackground(context);
+ _features = rendererFeatures(context);
+ _map = rendererMap(context);
+ _photos = rendererPhotos(context);
+
+ _ui = uiInit(context);
+ }
+
+ // Set up objects that might need to access properties of `context`. The order
+ // might matter if dependents make calls to each other. Be wary of async calls.
+ function initializeDependents() {
+
+ if (context.initialHashParams.presets) {
+ _mainPresetIndex.addablePresetIDs(new Set(context.initialHashParams.presets.split(',')));
+ }
+
+ if (context.initialHashParams.locale) {
+ _mainLocalizer.preferredLocaleCodes(context.initialHashParams.locale);
+ }
+
+ // kick off some async work
+ _mainLocalizer.ensureLoaded();
+ _background.ensureLoaded();
+ _mainPresetIndex.ensureLoaded();
+
+ Object.values(services).forEach(service => {
+ if (service && typeof service.init === 'function') {
+ service.init();
+ }
+ });
+
+ _map.init();
+ _validator.init();
+ _features.init();
+ _photos.init();
+ _rapidContext.init();
+
+ if (services.maprules && context.initialHashParams.maprules) {
+ d3_json(context.initialHashParams.maprules)
+ .then(mapcss => {
+ services.maprules.init();
+ mapcss.forEach(mapcssSelector => services.maprules.addRule(mapcssSelector));
+ })
+ .catch(() => { /* ignore */ });
+ }
+
+ // if the container isn't available, e.g. when testing, don't load the UI
+ if (!context.container().empty()) _ui.ensureLoaded();
+ }
+ };
+
+
+ return context;
+ }
+
+ const GROUPID = 'bdf6c800b3ae453b9db239e03d7c1727';
+ const APIROOT = 'https://openstreetmap.maps.arcgis.com/sharing/rest/content';
+ const HOMEROOT = 'https://openstreetmap.maps.arcgis.com/home';
+ const TILEZOOM = 14;
+ const tiler = utilTiler().zoomExtent([TILEZOOM, TILEZOOM]);
+ const dispatch$1 = dispatch('loadedData');
+
+ let _datasets = {};
+ let _off;
+
+
+ function abortRequest(controller) {
+ controller.abort();
+ }
+
+
+ // API
+ function searchURL() {
+ return `${APIROOT}/groups/${GROUPID}/search?num=20&start=1&sortField=title&sortOrder=asc&f=json`;
+ // use to get
+ // .results[]
+ // .extent
+ // .id
+ // .thumbnail
+ // .title
+ // .snippet
+ // .url (featureServer)
+ }
+
+ function layerURL(featureServerURL) {
+ return `${featureServerURL}/layers?f=json`;
+ // should return single layer(?)
+ // .layers[0]
+ // .copyrightText
+ // .fields
+ // .geometryType "esriGeometryPoint" or "esriGeometryPolygon" ?
+ }
+
+ function itemURL(itemID) {
+ return `${HOMEROOT}/item.html?id=${itemID}`;
+ }
+
+ function tileURL(dataset, extent) {
+ const layerId = dataset.layer.id;
+ const bbox = extent.toParam();
+ return `${dataset.url}/${layerId}/query?f=geojson&outfields=*&outSR=4326&geometryType=esriGeometryEnvelope&geometry=${bbox}`;
+ }
+
+
+ function parseTile(dataset, tile, geojson, callback) {
+ if (!geojson) return callback({ message: 'No GeoJSON', status: -1 });
+
+ // expect a FeatureCollection with `features` array
+ let results = [];
+ (geojson.features || []).forEach(f => {
+ let entities = parseFeature(f, dataset);
+ if (entities) results.push.apply(results, entities);
+ });
+
+ callback(null, results);
+ }
+
+
+ function parseFeature(feature, dataset) {
+ const geom = feature.geometry;
+ const props = feature.properties;
+ if (!geom || !props) return null;
+
+ const featureID = props[dataset.layer.idfield] || props.OBJECTID || props.FID || props.id;
+ if (!featureID) return null;
+
+ // skip if we've seen this feature already on another tile
+ if (dataset.cache.seen[featureID]) return null;
+ dataset.cache.seen[featureID] = true;
+
+ const id = `${dataset.id}-${featureID}`;
+ const meta = { __fbid__: id, __origid__: id, __service__: 'esri', __datasetid__: dataset.id };
+ let entities = [];
+ let nodemap = new Map();
+
+ // Point: make a single node
+ if (geom.type === 'Point') {
+ return [ new osmNode({ loc: geom.coordinates, tags: parseTags(props) }, meta) ];
+
+ // LineString: make nodes, single way
+ } else if (geom.type === 'LineString') {
+ const nodelist = parseCoordinates(geom.coordinates);
+ if (nodelist.length < 2) return null;
+
+ const w = new osmWay({ nodes: nodelist, tags: parseTags(props) }, meta);
+ entities.push(w);
+ return entities;
+
+ // Polygon: make nodes, way(s), possibly a relation
+ } else if (geom.type === 'Polygon') {
+ let ways = [];
+ geom.coordinates.forEach(ring => {
+ const nodelist = parseCoordinates(ring);
+ if (nodelist.length < 3) return null;
+
+ const first = nodelist[0];
+ const last = nodelist[nodelist.length - 1];
+ if (first !== last) nodelist.push(first); // sanity check, ensure rings are closed
+
+ const w = new osmWay({ nodes: nodelist });
+ ways.push(w);
+ });
+
+ if (ways.length === 1) { // single ring, assign tags and return
+ entities.push(
+ ways[0].update( Object.assign({ tags: parseTags(props) }, meta) )
+ );
+ } else { // multiple rings, make a multipolygon relation with inner/outer members
+ const members = ways.map((w, i) => {
+ entities.push(w);
+ return { id: w.id, role: (i === 0 ? 'outer' : 'inner'), type: 'way' };
+ });
+ const tags = Object.assign(parseTags(props), { type: 'multipolygon' });
+ const r = new osmRelation({ members: members, tags: tags }, meta);
+ entities.push(r);
+ }
+
+ return entities;
+ }
+ // no Multitypes for now (maybe not needed)
+
+ function parseCoordinates(coords) {
+ let nodelist = [];
+ coords.forEach(coord => {
+ const key = coord.toString();
+ let n = nodemap.get(key);
+ if (!n) {
+ n = new osmNode({ loc: coord });
+ entities.push(n);
+ nodemap.set(key, n);
+ }
+ nodelist.push(n.id);
+ });
+ return nodelist;
+ }
+
+ function parseTags(props) {
+ let tags = {};
+ Object.keys(props).forEach(prop => {
+ const k = clean(dataset.layer.tagmap[prop]);
+ const v = clean(props[prop]);
+ if (k && v) {
+ tags[k] = v;
+ }
+ });
+
+ tags.source = `esri/${dataset.name}`;
+ return tags;
+ }
+
+ function clean(val) {
+ return val ? val.toString().trim() : null;
+ }
+ }
+
+
+ var serviceEsriData = {
+
+ init: function () {
+ this.event = utilRebind(this, dispatch$1, 'on');
+ },
+
+
+ reset: function () {
+ Object.values(_datasets).forEach(ds => {
+ if (ds.cache.inflight) {
+ Object.values(ds.cache.inflight).forEach(abortRequest);
+ }
+ ds.graph = coreGraph();
+ ds.tree = coreTree(ds.graph);
+ ds.cache = { inflight: {}, loaded: {}, seen: {}, origIdTile: {} };
+ });
+
+ return this;
+ },
+
+
+ graph: function (datasetID) {
+ const ds = _datasets[datasetID];
+ return ds && ds.graph;
+ },
+
+
+ intersects: function (datasetID, extent) {
+ const ds = _datasets[datasetID];
+ if (!ds || !ds.tree || !ds.graph) return [];
+ return ds.tree.intersects(extent, ds.graph);
+ },
+
+
+ toggle: function (val) {
+ _off = !val;
+ return this;
+ },
+
+
+ loadTiles: function (datasetID, projection) {
+ if (_off) return;
+
+ // `loadDatasets` and `loadLayer` are asynchronous,
+ // so ensure both have completed before we start requesting tiles.
+ const ds = _datasets[datasetID];
+ if (!ds || !ds.layer) return;
+
+ const cache = ds.cache;
+ const tree = ds.tree;
+ const graph = ds.graph;
+ const tiles = tiler.getTiles(projection);
+
+ // abort inflight requests that are no longer needed
+ Object.keys(cache.inflight).forEach(k => {
+ const wanted = tiles.find(tile => tile.id === k);
+ if (!wanted) {
+ abortRequest(cache.inflight[k]);
+ delete cache.inflight[k];
+ }
+ });
+
+ tiles.forEach(tile => {
+ if (cache.loaded[tile.id] || cache.inflight[tile.id]) return;
+
+ const controller = new AbortController();
+ const url = tileURL(ds, tile.extent);
+
+ d3_json(url, { signal: controller.signal })
+ .then(geojson => {
+ delete cache.inflight[tile.id];
+ if (!geojson) throw new Error('no geojson');
+ parseTile(ds, tile, geojson, (err, results) => {
+ if (err) throw new Error(err);
+ graph.rebase(results, [graph], true);
+ tree.rebase(results, true);
+ cache.loaded[tile.id] = true;
+ dispatch$1.call('loadedData');
+ });
+ })
+ .catch(() => { /* ignore */ });
+
+ cache.inflight[tile.id] = controller;
+ });
+ },
+
+
+ loadDatasets: function () { // eventually pass search params?
+ if (Object.keys(_datasets).length) { // for now, if we have fetched datasets, return them
+ return Promise.resolve(_datasets);
+ }
+
+ const that = this;
+ return d3_json(searchURL())
+ .then(json => {
+ (json.results || []).forEach(ds => { // add each one to _datasets, create internal state
+ if (_datasets[ds.id]) return; // unless we've seen it already
+ _datasets[ds.id] = ds;
+ ds.graph = coreGraph();
+ ds.tree = coreTree(ds.graph);
+ ds.cache = { inflight: {}, loaded: {}, seen: {}, origIdTile: {} };
+
+ // cleanup the `licenseInfo` field by removing styles (not used currently)
+ let license = select(document.createElement('div'));
+ license.html(ds.licenseInfo); // set innerHtml
+ license.selectAll('*')
+ .attr('style', null)
+ .attr('size', null);
+ ds.license_html = license.html(); // get innerHtml
+
+ // generate public link to this item
+ ds.itemURL = itemURL(ds.id);
+
+ // preload the layer info (or we could wait do this once the user actually clicks 'add to map')
+ that.loadLayer(ds.id);
+ });
+ return _datasets;
+ })
+ .catch(() => { /* ignore */ });
+ },
+
+
+ loadLayer: function (datasetID) {
+ let ds = _datasets[datasetID];
+ if (!ds || !ds.url) {
+ return Promise.reject(`Unknown datasetID: ${datasetID}`);
+ } else if (ds.layer) {
+ return Promise.resolve(ds.layer);
+ }
+
+ return d3_json(layerURL(ds.url))
+ .then(json => {
+ if (!json.layers || !json.layers.length) {
+ throw new Error(`Missing layer info for datasetID: ${datasetID}`);
+ }
+
+ ds.layer = json.layers[0]; // should return a single layer
+
+ // Use the field metadata to map to OSM tags
+ let tagmap = {};
+ ds.layer.fields.forEach(f => {
+ if (f.type === 'esriFieldTypeOID') { // this is an id field, remember it
+ ds.layer.idfield = f.name;
+ }
+ if (!f.editable) return; // 1. keep "editable" fields only
+ tagmap[f.name] = f.alias; // 2. field `name` -> OSM tag (stored in `alias`)
+ });
+ ds.layer.tagmap = tagmap;
+
+ return ds.layer;
+ })
+ .catch(() => { /* ignore */ });
+ }
+ };
+
+ /**
+ * Creates a base function for methods like `_.forIn` and `_.forOwn`.
+ *
+ * @private
+ * @param {boolean} [fromRight] Specify iterating from right to left.
+ * @returns {Function} Returns the new base function.
+ */
+ function createBaseFor(fromRight) {
+ return function(object, iteratee, keysFunc) {
+ var index = -1,
+ iterable = Object(object),
+ props = keysFunc(object),
+ length = props.length;
+
+ while (length--) {
+ var key = props[fromRight ? length : ++index];
+ if (iteratee(iterable[key], key, iterable) === false) {
+ break;
+ }
+ }
+ return object;
+ };
+ }
+
+ /**
+ * The base implementation of `baseForOwn` which iterates over `object`
+ * properties returned by `keysFunc` and invokes `iteratee` for each property.
+ * Iteratee functions may exit iteration early by explicitly returning `false`.
+ *
+ * @private
+ * @param {Object} object The object to iterate over.
+ * @param {Function} iteratee The function invoked per iteration.
+ * @param {Function} keysFunc The function to get the keys of `object`.
+ * @returns {Object} Returns `object`.
+ */
+ var baseFor = createBaseFor();
+
+ /**
+ * The base implementation of `_.forOwn` without support for iteratee shorthands.
+ *
+ * @private
+ * @param {Object} object The object to iterate over.
+ * @param {Function} iteratee The function invoked per iteration.
+ * @returns {Object} Returns `object`.
+ */
+ function baseForOwn(object, iteratee) {
+ return object && baseFor(object, iteratee, keys$3);
+ }
+
+ /**
+ * Creates a `baseEach` or `baseEachRight` function.
+ *
+ * @private
+ * @param {Function} eachFunc The function to iterate over a collection.
+ * @param {boolean} [fromRight] Specify iterating from right to left.
+ * @returns {Function} Returns the new base function.
+ */
+ function createBaseEach(eachFunc, fromRight) {
+ return function(collection, iteratee) {
+ if (collection == null) {
+ return collection;
+ }
+ if (!isArrayLike(collection)) {
+ return eachFunc(collection, iteratee);
+ }
+ var length = collection.length,
+ index = fromRight ? length : -1,
+ iterable = Object(collection);
+
+ while ((fromRight ? index-- : ++index < length)) {
+ if (iteratee(iterable[index], index, iterable) === false) {
+ break;
+ }
+ }
+ return collection;
+ };
+ }
+
+ /**
+ * The base implementation of `_.forEach` without support for iteratee shorthands.
+ *
+ * @private
+ * @param {Array|Object} collection The collection to iterate over.
+ * @param {Function} iteratee The function invoked per iteration.
+ * @returns {Array|Object} Returns `collection`.
+ */
+ var baseEach = createBaseEach(baseForOwn);
+
+ /**
+ * Casts `value` to `identity` if it's not a function.
+ *
+ * @private
+ * @param {*} value The value to inspect.
+ * @returns {Function} Returns cast function.
+ */
+ function castFunction(value) {
+ return typeof value == 'function' ? value : identity$5;
+ }
+
+ /**
+ * Iterates over elements of `collection` and invokes `iteratee` for each element.
+ * The iteratee is invoked with three arguments: (value, index|key, collection).
+ * Iteratee functions may exit iteration early by explicitly returning `false`.
+ *
+ * **Note:** As with other "Collections" methods, objects with a "length"
+ * property are iterated like arrays. To avoid this behavior use `_.forIn`
+ * or `_.forOwn` for object iteration.
+ *
+ * @static
+ * @memberOf _
+ * @since 0.1.0
+ * @alias each
+ * @category Collection
+ * @param {Array|Object} collection The collection to iterate over.
+ * @param {Function} [iteratee=_.identity] The function invoked per iteration.
+ * @returns {Array|Object} Returns `collection`.
+ * @see _.forEachRight
+ * @example
+ *
+ * _.forEach([1, 2], function(value) {
+ * console.log(value);
+ * });
+ * // => Logs `1` then `2`.
+ *
+ * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
+ * console.log(key);
+ * });
+ * // => Logs 'a' then 'b' (iteration order is not guaranteed).
+ */
+ function forEach$4(collection, iteratee) {
+ var func = isArray$5(collection) ? arrayEach : baseEach;
+ return func(collection, castFunction(iteratee));
+ }
+
+ // constants
+ var APIROOT$1 = 'https://mapwith.ai/maps/ml_roads';
+ var TILEZOOM$1 = 16;
+ var tiler$1 = utilTiler().zoomExtent([TILEZOOM$1, TILEZOOM$1]);
+ var dispatch$2 = dispatch('loadedData');
+
+ var _datasets$1 = {};
+ var _deferredAiFeaturesParsing = new Set();
+ var _off$1;
+
+
+ function abortRequest$1(i) {
+ i.abort();
+ }
+
+
+ function tileURL$1(dataset, extent, taskExtent) {
+ // Conflated datasets have a different ID, so they get stored in their own graph/tree
+ var isConflated = /-conflated$/.test(dataset.id);
+ var datasetID = dataset.id.replace('-conflated', '');
+
+ var qs = {
+ conflate_with_osm: isConflated,
+ theme: 'ml_road_vector',
+ collaborator: 'fbid',
+ token: 'ASZUVdYpCkd3M6ZrzjXdQzHulqRMnxdlkeBJWEKOeTUoY_Gwm9fuEd2YObLrClgDB_xfavizBsh0oDfTWTF7Zb4C',
+ hash: 'ASYM8LPNy8k1XoJiI7A'
+ };
+
+ if (datasetID === 'fbRoads') {
+ qs.result_type = 'road_vector_xml';
+
+ } else if (datasetID === 'msBuildings') {
+ qs.result_type = 'road_building_vector_xml';
+ qs.building_source = 'microsoft';
+
+ } else {
+ qs.result_type = 'osm_xml';
+ qs.sources = `esri_building.${datasetID}`;
+ }
+
+ qs.bbox = extent.toParam();
+
+ if (taskExtent) qs.crop_bbox = taskExtent.toParam();
+
+ // Note: we are not sure whether the `fb_ml_road_url` and `fb_ml_road_tags` query params are used anymore.
+ var customUrlRoot = utilStringQs(window.location.hash).fb_ml_road_url;
+ var customRoadTags = utilStringQs(window.location.hash).fb_ml_road_tags;
+
+ var urlRoot = customUrlRoot || APIROOT$1;
+ var url = urlRoot + '?' + utilQsString(qs, true); // true = noencode
+
+ if (customRoadTags) {
+ customRoadTags.split(',').forEach(function (tag) {
+ url += '&allow_tags[]=' + tag;
+ });
+ }
+
+ return url;
+
+
+ // This utilQsString does not sort the keys, because the fbml service needs them to be ordered a certain way.
+ function utilQsString(obj, noencode) {
+ // encode everything except special characters used in certain hash parameters:
+ // "/" in map states, ":", ",", {" and "}" in background
+ function softEncode(s) {
+ return encodeURIComponent(s).replace(/(%2F|%3A|%2C|%7B|%7D)/g, decodeURIComponent);
+ }
+
+ return Object.keys(obj).map(function(key) { // NO SORT
+ return encodeURIComponent(key) + '=' + (
+ noencode ? softEncode(obj[key]) : encodeURIComponent(obj[key]));
+ }).join('&');
+ }
+
+ }
+
+
+ function getLoc(attrs) {
+ var lon = attrs.lon && attrs.lon.value;
+ var lat = attrs.lat && attrs.lat.value;
+ return [parseFloat(lon), parseFloat(lat)];
+ }
+
+
+ function getNodes(obj) {
+ var elems = obj.getElementsByTagName('nd');
+ var nodes = new Array(elems.length);
+ for (var i = 0, l = elems.length; i < l; i++) {
+ nodes[i] = 'n' + elems[i].attributes.ref.value;
+ }
+ return nodes;
+ }
+
+
+ function getTags(obj) {
+ var elems = obj.getElementsByTagName('tag');
+ var tags = {};
+ for (var i = 0, l = elems.length; i < l; i++) {
+ var attrs = elems[i].attributes;
+ var k = (attrs.k.value || '').trim();
+ var v = (attrs.v.value || '').trim();
+ if (k && v) {
+ tags[k] = v;
+ }
+ }
+
+ return tags;
+ }
+
+
+ function getVisible(attrs) {
+ return (!attrs.visible || attrs.visible.value !== 'false');
+ }
+
+
+ var parsers = {
+ node: function nodeData(obj, uid) {
+ var attrs = obj.attributes;
+ return new osmNode({
+ id: uid,
+ visible: getVisible(attrs),
+ loc: getLoc(attrs),
+ tags: getTags(obj)
+ });
+ },
+
+ way: function wayData(obj, uid) {
+ var attrs = obj.attributes;
+ return new osmWay({
+ id: uid,
+ visible: getVisible(attrs),
+ tags: getTags(obj),
+ nodes: getNodes(obj),
+ });
+ }
+ };
+
+
+ function parseXML(dataset, xml, tile, callback, options) {
+ options = Object.assign({ skipSeen: true }, options);
+ if (!xml || !xml.childNodes) {
+ return callback({ message: 'No XML', status: -1 });
+ }
+
+ var graph = dataset.graph;
+ var cache = dataset.cache;
+
+ var root = xml.childNodes[0];
+ var children = root.childNodes;
+ var handle = window.requestIdleCallback(function() {
+ _deferredAiFeaturesParsing.delete(handle);
+ var results = [];
+ for (var i = 0; i < children.length; i++) {
+ var result = parseChild(children[i]);
+ if (result) results.push(result);
+ }
+ callback(null, results);
+ });
+ _deferredAiFeaturesParsing.add(handle);
+
+
+ function parseChild(child) {
+ var parser = parsers[child.nodeName];
+ if (!parser) return null;
+
+ var uid = osmEntity.id.fromOSM(child.nodeName, child.attributes.id.value);
+ if (options.skipSeen) {
+ if (cache.seen[uid]) return null; // avoid reparsing a "seen" entity
+ if (cache.origIdTile[uid]) return null; // avoid double-parsing a split way
+ cache.seen[uid] = true;
+ }
+
+ // Handle non-deterministic way splitting from Roads Service. Splits
+ // are consistent within a single request.
+ var origUid;
+ if (child.attributes.orig_id) {
+ origUid = osmEntity.id.fromOSM(child.nodeName, child.attributes.orig_id.value);
+ if (graph.entities[origUid] ||
+ (cache.origIdTile[origUid] && cache.origIdTile[origUid] !== tile.id)) {
+ return null;
+ }
+ cache.origIdTile[origUid] = tile.id;
+ }
+
+ var entity = parser(child, uid);
+ var meta = {
+ __fbid__: child.attributes.id.value,
+ __origid__: origUid,
+ __service__: 'fbml',
+ __datasetid__: dataset.id
+ };
+ return Object.assign(entity, meta);
+ }
+ }
+
+
+ var serviceFbAIFeatures = {
+
+ init: function() {
+ this.event = utilRebind(this, dispatch$2, 'on');
+
+ // allocate a special dataset for the rapid intro graph.
+ var datasetID = 'rapid_intro_graph';
+ var graph = coreGraph();
+ var tree = coreTree(graph);
+ var cache = { inflight: {}, loaded: {}, seen: {}, origIdTile: {} };
+ var ds = { id: datasetID, graph: graph, tree: tree, cache: cache };
+ _datasets$1[datasetID] = ds;
+ },
+
+ reset: function() {
+ Array.from(_deferredAiFeaturesParsing).forEach(function(handle) {
+ window.cancelIdleCallback(handle);
+ _deferredAiFeaturesParsing.delete(handle);
+ });
+
+ Object.values(_datasets$1).forEach(function(ds) {
+ if (ds.cache.inflight) {
+ Object.values(ds.cache.inflight).forEach(abortRequest$1);
+ }
+ ds.graph = coreGraph();
+ ds.tree = coreTree(ds.graph);
+ ds.cache = { inflight: {}, loaded: {}, seen: {}, origIdTile: {} };
+ });
+
+ return this;
+ },
+
+
+ graph: function (datasetID) {
+ var ds = _datasets$1[datasetID];
+ return ds && ds.graph;
+ },
+
+
+ intersects: function (datasetID, extent) {
+ var ds = _datasets$1[datasetID];
+ if (!ds || !ds.tree || !ds.graph) return [];
+ return ds.tree.intersects(extent, ds.graph);
+ },
+
+
+ merge: function(datasetID, entities) {
+ var ds = _datasets$1[datasetID];
+ if (!ds || !ds.tree || !ds.graph) return;
+ ds.graph.rebase(entities, [ds.graph], false);
+ ds.tree.rebase(entities, false);
+ },
+
+
+ cache: function (datasetID, obj) {
+ var ds = _datasets$1[datasetID];
+ if (!ds || !ds.cache) return;
+
+ function cloneDeep(source) {
+ return JSON.parse(JSON.stringify(source));
+ }
+
+ if (!arguments.length) {
+ return {
+ tile: cloneDeep(ds.cache)
+ };
+ }
+
+ // access cache directly for testing
+ if (obj === 'get') {
+ return ds.cache;
+ }
+
+ ds.cache = obj;
+ },
+
+
+ toggle: function(val) {
+ _off$1 = !val;
+ return this;
+ },
+
+
+ loadTiles: function(datasetID, projection, taskExtent) {
+ if (_off$1) return;
+
+ var ds = _datasets$1[datasetID];
+ var graph, tree, cache;
+ if (ds) {
+ graph = ds.graph;
+ tree = ds.tree;
+ cache = ds.cache;
+ } else {
+ // as tile requests arrive, setup the resources needed to hold the results
+ graph = coreGraph();
+ tree = coreTree(graph);
+ cache = { inflight: {}, loaded: {}, seen: {}, origIdTile: {} };
+ ds = { id: datasetID, graph: graph, tree: tree, cache: cache };
+ _datasets$1[datasetID] = ds;
+ }
+
+
+ var tiles = tiler$1.getTiles(projection);
+
+ // abort inflight requests that are no longer needed
+ forEach$4(cache.inflight, function(v, k) {
+ var wanted = tiles.find(function(tile) { return k === tile.id; });
+ if (!wanted) {
+ abortRequest$1(v);
+ delete cache.inflight[k];
+ }
+ });
+
+ tiles.forEach(function(tile) {
+ if (cache.loaded[tile.id] || cache.inflight[tile.id]) return;
+
+ var controller = new AbortController();
+ d3_xml(tileURL$1(ds, tile.extent, taskExtent), { signal: controller.signal })
+ .then(function (dom) {
+ delete cache.inflight[tile.id];
+ if (!dom) return;
+ parseXML(ds, dom, tile, function(err, results) {
+ if (err) return;
+ graph.rebase(results, [graph], true);
+ tree.rebase(results, true);
+ cache.loaded[tile.id] = true;
+ dispatch$2.call('loadedData');
+ });
+ })
+ .catch(function() {});
+
+ cache.inflight[tile.id] = controller;
+ });
+ }
+ };
+
+ const tiler$2 = utilTiler();
+ const dispatch$3 = dispatch('loaded');
+ const _tileZoom = 14;
+ const _krUrlRoot = 'https://www.keepright.at';
+ let _krData = { errorTypes: {}, localizeStrings: {} };
+
+ // This gets reassigned if reset
+ let _cache;
+
+ const _krRuleset = [
+ // no 20 - multiple node on same spot - these are mostly boundaries overlapping roads
+ 30, 40, 50, 60, 70, 90, 100, 110, 120, 130, 150, 160, 170, 180,
+ 190, 191, 192, 193, 194, 195, 196, 197, 198,
+ 200, 201, 202, 203, 204, 205, 206, 207, 208, 210, 220,
+ 230, 231, 232, 270, 280, 281, 282, 283, 284, 285,
+ 290, 291, 292, 293, 294, 295, 296, 297, 298, 300, 310, 311, 312, 313,
+ 320, 350, 360, 370, 380, 390, 400, 401, 402, 410, 411, 412, 413
+ ];
+
+
+ function abortRequest$2(controller) {
+ if (controller) {
+ controller.abort();
+ }
+ }
+
+ function abortUnwantedRequests(cache, tiles) {
+ Object.keys(cache.inflightTile).forEach(k => {
+ const wanted = tiles.find(tile => k === tile.id);
+ if (!wanted) {
+ abortRequest$2(cache.inflightTile[k]);
+ delete cache.inflightTile[k];
+ }
+ });
+ }
+
+
+ function encodeIssueRtree(d) {
+ return { minX: d.loc[0], minY: d.loc[1], maxX: d.loc[0], maxY: d.loc[1], data: d };
+ }
+
+
+ // Replace or remove QAItem from rtree
+ function updateRtree(item, replace) {
+ _cache.rtree.remove(item, (a, b) => a.data.id === b.data.id);
+
+ if (replace) {
+ _cache.rtree.insert(item);
+ }
+ }
+
+
+ function tokenReplacements(d) {
+ if (!(d instanceof QAItem)) return;
+
+ const htmlRegex = new RegExp(/<\/[a-z][\s\S]*>/);
+ const replacements = {};
+
+ const issueTemplate = _krData.errorTypes[d.whichType];
+ if (!issueTemplate) {
+ /* eslint-disable no-console */
+ console.log('No Template: ', d.whichType);
+ console.log(' ', d.description);
+ /* eslint-enable no-console */
+ return;
+ }
+
+ // some descriptions are just fixed text
+ if (!issueTemplate.regex) return;
+
+ // regex pattern should match description with variable details captured
+ const errorRegex = new RegExp(issueTemplate.regex, 'i');
+ const errorMatch = errorRegex.exec(d.description);
+ if (!errorMatch) {
+ /* eslint-disable no-console */
+ console.log('Unmatched: ', d.whichType);
+ console.log(' ', d.description);
+ console.log(' ', errorRegex);
+ /* eslint-enable no-console */
+ return;
+ }
+
+ for (let i = 1; i < errorMatch.length; i++) { // skip first
+ let capture = errorMatch[i];
+ let idType;
+
+ idType = 'IDs' in issueTemplate ? issueTemplate.IDs[i-1] : '';
+ if (idType && capture) { // link IDs if present in the capture
+ capture = parseError(capture, idType);
+ } else if (htmlRegex.test(capture)) { // escape any html in non-IDs
+ capture = '\\' + capture + '\\';
+ } else {
+ const compare = capture.toLowerCase();
+ if (_krData.localizeStrings[compare]) { // some replacement strings can be localized
+ capture = _t('QA.keepRight.error_parts.' + _krData.localizeStrings[compare]);
+ }
+ }
+
+ replacements['var' + i] = capture;
+ }
+
+ return replacements;
+ }
+
+
+ function parseError(capture, idType) {
+ const compare = capture.toLowerCase();
+ if (_krData.localizeStrings[compare]) { // some replacement strings can be localized
+ capture = _t('QA.keepRight.error_parts.' + _krData.localizeStrings[compare]);
+ }
+
+ switch (idType) {
+ // link a string like "this node"
+ case 'this':
+ capture = linkErrorObject(capture);
+ break;
+
+ case 'url':
+ capture = linkURL(capture);
+ break;
+
+ // link an entity ID
+ case 'n':
+ case 'w':
+ case 'r':
+ capture = linkEntity(idType + capture);
+ break;
+
+ // some errors have more complex ID lists/variance
+ case '20':
+ capture = parse20(capture);
+ break;
+ case '211':
+ capture = parse211(capture);
+ break;
+ case '231':
+ capture = parse231(capture);
+ break;
+ case '294':
+ capture = parse294(capture);
+ break;
+ case '370':
+ capture = parse370(capture);
+ break;
+ }
+
+ return capture;
+
+
+ function linkErrorObject(d) {
+ return `${d} `;
+ }
+
+ function linkEntity(d) {
+ return `${d} `;
+ }
+
+ function linkURL(d) {
+ return `${d} `;
+ }
+
+ // arbitrary node list of form: #ID, #ID, #ID...
+ function parse211(capture) {
+ let newList = [];
+ const items = capture.split(', ');
+
+ items.forEach(item => {
+ // ID has # at the front
+ let id = linkEntity('n' + item.slice(1));
+ newList.push(id);
+ });
+
+ return newList.join(', ');
+ }
+
+ // arbitrary way list of form: #ID(layer),#ID(layer),#ID(layer)...
+ function parse231(capture) {
+ let newList = [];
+ // unfortunately 'layer' can itself contain commas, so we split on '),'
+ const items = capture.split('),');
+
+ items.forEach(item => {
+ const match = item.match(/\#(\d+)\((.+)\)?/);
+ if (match !== null && match.length > 2) {
+ newList.push(linkEntity('w' + match[1]) + ' ' +
+ _t('QA.keepRight.errorTypes.231.layer', { layer: match[2] })
+ );
+ }
+ });
+
+ return newList.join(', ');
+ }
+
+ // arbitrary node/relation list of form: from node #ID,to relation #ID,to node #ID...
+ function parse294(capture) {
+ let newList = [];
+ const items = capture.split(',');
+
+ items.forEach(item => {
+ // item of form "from/to node/relation #ID"
+ item = item.split(' ');
+
+ // to/from role is more clear in quotes
+ const role = `"${item[0]}"`;
+
+ // first letter of node/relation provides the type
+ const idType = item[1].slice(0,1);
+
+ // ID has # at the front
+ let id = item[2].slice(1);
+ id = linkEntity(idType + id);
+
+ newList.push(`${role} ${item[1]} ${id}`);
+ });
+
+ return newList.join(', ');
+ }
+
+ // may or may not include the string "(including the name 'name')"
+ function parse370(capture) {
+ if (!capture) return '';
+
+ const match = capture.match(/\(including the name (\'.+\')\)/);
+ if (match && match.length) {
+ return _t('QA.keepRight.errorTypes.370.including_the_name', { name: match[1] });
+ }
+ return '';
+ }
+
+ // arbitrary node list of form: #ID,#ID,#ID...
+ function parse20(capture) {
+ let newList = [];
+ const items = capture.split(',');
+
+ items.forEach(item => {
+ // ID has # at the front
+ const id = linkEntity('n' + item.slice(1));
+ newList.push(id);
+ });
+
+ return newList.join(', ');
+ }
+ }
+
+
+ var serviceKeepRight = {
+ title: 'keepRight',
+
+ init() {
+ _mainFileFetcher.get('keepRight')
+ .then(d => _krData = d);
+
+ if (!_cache) {
+ this.reset();
+ }
+
+ this.event = utilRebind(this, dispatch$3, 'on');
+ },
+
+ reset() {
+ if (_cache) {
+ Object.values(_cache.inflightTile).forEach(abortRequest$2);
+ }
+
+ _cache = {
+ data: {},
+ loadedTile: {},
+ inflightTile: {},
+ inflightPost: {},
+ closed: {},
+ rtree: new RBush()
+ };
+ },
+
+
+ // KeepRight API: http://osm.mueschelsoft.de/keepright/interfacing.php
+ loadIssues(projection) {
+ const options = {
+ format: 'geojson',
+ ch: _krRuleset
+ };
+
+ // determine the needed tiles to cover the view
+ const tiles = tiler$2
+ .zoomExtent([_tileZoom, _tileZoom])
+ .getTiles(projection);
+
+ // abort inflight requests that are no longer needed
+ abortUnwantedRequests(_cache, tiles);
+
+ // issue new requests..
+ tiles.forEach(tile => {
+ if (_cache.loadedTile[tile.id] || _cache.inflightTile[tile.id]) return;
+
+ const [ left, top, right, bottom ] = tile.extent.rectangle();
+ const params = Object.assign({}, options, { left, bottom, right, top });
+ const url = `${_krUrlRoot}/export.php?` + utilQsString(params);
+ const controller = new AbortController();
+
+ _cache.inflightTile[tile.id] = controller;
+
+ d3_json(url, { signal: controller.signal })
+ .then(data => {
+ delete _cache.inflightTile[tile.id];
+ _cache.loadedTile[tile.id] = true;
+ if (!data || !data.features || !data.features.length) {
+ throw new Error('No Data');
+ }
+
+ data.features.forEach(feature => {
+ const {
+ properties: {
+ error_type: itemType,
+ error_id: id,
+ comment = null,
+ object_id: objectId,
+ object_type: objectType,
+ schema,
+ title
+ }
+ } = feature;
+ let {
+ geometry: { coordinates: loc },
+ properties: { description = '' }
+ } = feature;
+
+ // if there is a parent, save its error type e.g.:
+ // Error 191 = "highway-highway"
+ // Error 190 = "intersections without junctions" (parent)
+ const issueTemplate = _krData.errorTypes[itemType];
+ const parentIssueType = (Math.floor(itemType / 10) * 10).toString();
+
+ // try to handle error type directly, fallback to parent error type.
+ const whichType = issueTemplate ? itemType : parentIssueType;
+ const whichTemplate = _krData.errorTypes[whichType];
+
+ // Rewrite a few of the errors at this point..
+ // This is done to make them easier to linkify and translate.
+ switch (whichType) {
+ case '170':
+ description = `This feature has a FIXME tag: ${description}`;
+ break;
+ case '292':
+ case '293':
+ description = description.replace('A turn-', 'This turn-');
+ break;
+ case '294':
+ case '295':
+ case '296':
+ case '297':
+ case '298':
+ description = `This turn-restriction~${description}`;
+ break;
+ case '300':
+ description = 'This highway is missing a maxspeed tag';
+ break;
+ case '411':
+ case '412':
+ case '413':
+ description = `This feature~${description}`;
+ break;
+ }
+
+ // move markers slightly so it doesn't obscure the geometry,
+ // then move markers away from other coincident markers
+ let coincident = false;
+ do {
+ // first time, move marker up. after that, move marker right.
+ let delta = coincident ? [0.00001, 0] : [0, 0.00001];
+ loc = geoVecAdd(loc, delta);
+ let bbox = geoExtent(loc).bbox();
+ coincident = _cache.rtree.search(bbox).length;
+ } while (coincident);
+
+ let d = new QAItem(loc, this, itemType, id, {
+ comment,
+ description,
+ whichType,
+ parentIssueType,
+ severity: whichTemplate.severity || 'error',
+ objectId,
+ objectType,
+ schema,
+ title
+ });
+
+ d.replacements = tokenReplacements(d);
+
+ _cache.data[id] = d;
+ _cache.rtree.insert(encodeIssueRtree(d));
+ });
+
+ dispatch$3.call('loaded');
+ })
+ .catch(() => {
+ delete _cache.inflightTile[tile.id];
+ _cache.loadedTile[tile.id] = true;
+ });
+
+ });
+ },
+
+
+ postUpdate(d, callback) {
+ if (_cache.inflightPost[d.id]) {
+ return callback({ message: 'Error update already inflight', status: -2 }, d);
+ }
+
+ const params = { schema: d.schema, id: d.id };
+
+ if (d.newStatus) {
+ params.st = d.newStatus;
+ }
+ if (d.newComment !== undefined) {
+ params.co = d.newComment;
+ }
+
+ // NOTE: This throws a CORS err, but it seems successful.
+ // We don't care too much about the response, so this is fine.
+ const url = `${_krUrlRoot}/comment.php?` + utilQsString(params);
+ const controller = new AbortController();
+
+ _cache.inflightPost[d.id] = controller;
+
+ // Since this is expected to throw an error just continue as if it worked
+ // (worst case scenario the request truly fails and issue will show up if iD restarts)
+ d3_json(url, { signal: controller.signal })
+ .finally(() => {
+ delete _cache.inflightPost[d.id];
+
+ if (d.newStatus === 'ignore') {
+ // ignore permanently (false positive)
+ this.removeItem(d);
+ } else if (d.newStatus === 'ignore_t') {
+ // ignore temporarily (error fixed)
+ this.removeItem(d);
+ _cache.closed[`${d.schema}:${d.id}`] = true;
+ } else {
+ d = this.replaceItem(d.update({
+ comment: d.newComment,
+ newComment: undefined,
+ newState: undefined
+ }));
+ }
+
+ if (callback) callback(null, d);
+ });
+ },
+
+ // Get all cached QAItems covering the viewport
+ getItems(projection) {
+ const viewport = projection.clipExtent();
+ const min = [viewport[0][0], viewport[1][1]];
+ const max = [viewport[1][0], viewport[0][1]];
+ const bbox = geoExtent(projection.invert(min), projection.invert(max)).bbox();
+
+ return _cache.rtree.search(bbox).map(d => d.data);
+ },
+
+ // Get a QAItem from cache
+ // NOTE: Don't change method name until UI v3 is merged
+ getError(id) {
+ return _cache.data[id];
+ },
+
+ // Replace a single QAItem in the cache
+ replaceItem(item) {
+ if (!(item instanceof QAItem) || !item.id) return;
+
+ _cache.data[item.id] = item;
+ updateRtree(encodeIssueRtree(item), true); // true = replace
+ return item;
+ },
+
+ // Remove a single QAItem from the cache
+ removeItem(item) {
+ if (!(item instanceof QAItem) || !item.id) return;
+
+ delete _cache.data[item.id];
+ updateRtree(encodeIssueRtree(item), false); // false = remove
+ },
+
+ issueURL(item) {
+ return `${_krUrlRoot}/report_map.php?schema=${item.schema}&error=${item.id}`;
+ },
+
+ // Get an array of issues closed during this session.
+ // Used to populate `closed:keepright` changeset tag
+ getClosedIDs() {
+ return Object.keys(_cache.closed).sort();
+ }
+
+ };
+
+ const tiler$3 = utilTiler();
+ const dispatch$4 = dispatch('loaded');
+ const _tileZoom$1 = 14;
+ const _impOsmUrls = {
+ ow: 'https://grab.community.improve-osm.org/directionOfFlowService',
+ mr: 'https://grab.community.improve-osm.org/missingGeoService',
+ tr: 'https://grab.community.improve-osm.org/turnRestrictionService'
+ };
+ let _impOsmData = { icons: {} };
+
+
+ // This gets reassigned if reset
+ let _cache$1;
+
+ function abortRequest$3(i) {
+ Object.values(i).forEach(controller => {
+ if (controller) {
+ controller.abort();
+ }
+ });
+ }
+
+ function abortUnwantedRequests$1(cache, tiles) {
+ Object.keys(cache.inflightTile).forEach(k => {
+ const wanted = tiles.find(tile => k === tile.id);
+ if (!wanted) {
+ abortRequest$3(cache.inflightTile[k]);
+ delete cache.inflightTile[k];
+ }
+ });
+ }
+
+ function encodeIssueRtree$1(d) {
+ return { minX: d.loc[0], minY: d.loc[1], maxX: d.loc[0], maxY: d.loc[1], data: d };
+ }
+
+ // Replace or remove QAItem from rtree
+ function updateRtree$1(item, replace) {
+ _cache$1.rtree.remove(item, (a, b) => a.data.id === b.data.id);
+
+ if (replace) {
+ _cache$1.rtree.insert(item);
+ }
+ }
+
+ function linkErrorObject(d) {
+ return `${d} `;
+ }
+
+ function linkEntity(d) {
+ return `${d} `;
+ }
+
+ function pointAverage(points) {
+ if (points.length) {
+ const sum = points.reduce(
+ (acc, point) => geoVecAdd(acc, [point.lon, point.lat]),
+ [0,0]
+ );
+ return geoVecScale(sum, 1 / points.length);
+ } else {
+ return [0,0];
+ }
+ }
+
+ function relativeBearing(p1, p2) {
+ let angle = Math.atan2(p2.lon - p1.lon, p2.lat - p1.lat);
+ if (angle < 0) {
+ angle += 2 * Math.PI;
+ }
+
+ // Return degrees
+ return angle * 180 / Math.PI;
+ }
+
+ // Assuming range [0,360)
+ function cardinalDirection(bearing) {
+ const dir = 45 * Math.round(bearing / 45);
+ const compass = {
+ 0: 'north',
+ 45: 'northeast',
+ 90: 'east',
+ 135: 'southeast',
+ 180: 'south',
+ 225: 'southwest',
+ 270: 'west',
+ 315: 'northwest',
+ 360: 'north'
+ };
+
+ return _t(`QA.improveOSM.directions.${compass[dir]}`);
+ }
+
+ // Errors shouldn't obscure eachother
+ function preventCoincident(loc, bumpUp) {
+ let coincident = false;
+ do {
+ // first time, move marker up. after that, move marker right.
+ let delta = coincident ? [0.00001, 0] : (bumpUp ? [0, 0.00001] : [0, 0]);
+ loc = geoVecAdd(loc, delta);
+ let bbox = geoExtent(loc).bbox();
+ coincident = _cache$1.rtree.search(bbox).length;
+ } while (coincident);
+
+ return loc;
+ }
+
+ var serviceImproveOSM = {
+ title: 'improveOSM',
+
+ init() {
+ _mainFileFetcher.get('qa_data')
+ .then(d => _impOsmData = d.improveOSM);
+
+ if (!_cache$1) {
+ this.reset();
+ }
+
+ this.event = utilRebind(this, dispatch$4, 'on');
+ },
+
+ reset() {
+ if (_cache$1) {
+ Object.values(_cache$1.inflightTile).forEach(abortRequest$3);
+ }
+ _cache$1 = {
+ data: {},
+ loadedTile: {},
+ inflightTile: {},
+ inflightPost: {},
+ closed: {},
+ rtree: new RBush()
+ };
+ },
+
+ loadIssues(projection) {
+ const options = {
+ client: 'iD',
+ status: 'OPEN',
+ zoom: '19' // Use a high zoom so that clusters aren't returned
+ };
+
+ // determine the needed tiles to cover the view
+ const tiles = tiler$3
+ .zoomExtent([_tileZoom$1, _tileZoom$1])
+ .getTiles(projection);
+
+ // abort inflight requests that are no longer needed
+ abortUnwantedRequests$1(_cache$1, tiles);
+
+ // issue new requests..
+ tiles.forEach(tile => {
+ if (_cache$1.loadedTile[tile.id] || _cache$1.inflightTile[tile.id]) return;
+
+ const [ east, north, west, south ] = tile.extent.rectangle();
+ const params = Object.assign({}, options, { east, south, west, north });
+
+ // 3 separate requests to store for each tile
+ const requests = {};
+
+ Object.keys(_impOsmUrls).forEach(k => {
+ // We exclude WATER from missing geometry as it doesn't seem useful
+ // We use most confident one-way and turn restrictions only, still have false positives
+ const kParams = Object.assign({},
+ params,
+ (k === 'mr') ? { type: 'PARKING,ROAD,BOTH,PATH' } : { confidenceLevel: 'C1' }
+ );
+ const url = `${_impOsmUrls[k]}/search?` + utilQsString(kParams);
+ const controller = new AbortController();
+
+ requests[k] = controller;
+
+ d3_json(url, { signal: controller.signal })
+ .then(data => {
+ delete _cache$1.inflightTile[tile.id][k];
+ if (!Object.keys(_cache$1.inflightTile[tile.id]).length) {
+ delete _cache$1.inflightTile[tile.id];
+ _cache$1.loadedTile[tile.id] = true;
+ }
+
+ // Road segments at high zoom == oneways
+ if (data.roadSegments) {
+ data.roadSegments.forEach(feature => {
+ // Position error at the approximate middle of the segment
+ const { points, wayId, fromNodeId, toNodeId } = feature;
+ const itemId = `${wayId}${fromNodeId}${toNodeId}`;
+ let mid = points.length / 2;
+ let loc;
+
+ // Even number of points, find midpoint of the middle two
+ // Odd number of points, use position of very middle point
+ if (mid % 1 === 0) {
+ loc = pointAverage([points[mid - 1], points[mid]]);
+ } else {
+ mid = points[Math.floor(mid)];
+ loc = [mid.lon, mid.lat];
+ }
+
+ // One-ways can land on same segment in opposite direction
+ loc = preventCoincident(loc, false);
+
+ let d = new QAItem(loc, this, k, itemId, {
+ issueKey: k, // used as a category
+ identifier: { // used to post changes
+ wayId,
+ fromNodeId,
+ toNodeId
+ },
+ objectId: wayId,
+ objectType: 'way'
+ });
+
+ // Variables used in the description
+ d.replacements = {
+ percentage: feature.percentOfTrips,
+ num_trips: feature.numberOfTrips,
+ highway: linkErrorObject(_t('QA.keepRight.error_parts.highway')),
+ from_node: linkEntity('n' + feature.fromNodeId),
+ to_node: linkEntity('n' + feature.toNodeId)
+ };
+
+ _cache$1.data[d.id] = d;
+ _cache$1.rtree.insert(encodeIssueRtree$1(d));
+ });
+ }
+
+ // Tiles at high zoom == missing roads
+ if (data.tiles) {
+ data.tiles.forEach(feature => {
+ const { type, x, y, numberOfTrips } = feature;
+ const geoType = type.toLowerCase();
+ const itemId = `${geoType}${x}${y}${numberOfTrips}`;
+
+ // Average of recorded points should land on the missing geometry
+ // Missing geometry could happen to land on another error
+ let loc = pointAverage(feature.points);
+ loc = preventCoincident(loc, false);
+
+ let d = new QAItem(loc, this, `${k}-${geoType}`, itemId, {
+ issueKey: k,
+ identifier: { x, y }
+ });
+
+ d.replacements = {
+ num_trips: numberOfTrips,
+ geometry_type: _t(`QA.improveOSM.geometry_types.${geoType}`)
+ };
+
+ // -1 trips indicates data came from a 3rd party
+ if (numberOfTrips === -1) {
+ d.desc = _t('QA.improveOSM.error_types.mr.description_alt', d.replacements);
+ }
+
+ _cache$1.data[d.id] = d;
+ _cache$1.rtree.insert(encodeIssueRtree$1(d));
+ });
+ }
+
+ // Entities at high zoom == turn restrictions
+ if (data.entities) {
+ data.entities.forEach(feature => {
+ const { point, id, segments, numberOfPasses, turnType } = feature;
+ const itemId = `${id.replace(/[,:+#]/g, '_')}`;
+
+ // Turn restrictions could be missing at same junction
+ // We also want to bump the error up so node is accessible
+ const loc = preventCoincident([point.lon, point.lat], true);
+
+ // Elements are presented in a strange way
+ const ids = id.split(',');
+ const from_way = ids[0];
+ const via_node = ids[3];
+ const to_way = ids[2].split(':')[1];
+
+ let d = new QAItem(loc, this, k, itemId, {
+ issueKey: k,
+ identifier: id,
+ objectId: via_node,
+ objectType: 'node'
+ });
+
+ // Travel direction along from_way clarifies the turn restriction
+ const [ p1, p2 ] = segments[0].points;
+ const dir_of_travel = cardinalDirection(relativeBearing(p1, p2));
+
+ // Variables used in the description
+ d.replacements = {
+ num_passed: numberOfPasses,
+ num_trips: segments[0].numberOfTrips,
+ turn_restriction: turnType.toLowerCase(),
+ from_way: linkEntity('w' + from_way),
+ to_way: linkEntity('w' + to_way),
+ travel_direction: dir_of_travel,
+ junction: linkErrorObject(_t('QA.keepRight.error_parts.this_node'))
+ };
+
+ _cache$1.data[d.id] = d;
+ _cache$1.rtree.insert(encodeIssueRtree$1(d));
+ dispatch$4.call('loaded');
+ });
+ }
+ })
+ .catch(() => {
+ delete _cache$1.inflightTile[tile.id][k];
+ if (!Object.keys(_cache$1.inflightTile[tile.id]).length) {
+ delete _cache$1.inflightTile[tile.id];
+ _cache$1.loadedTile[tile.id] = true;
+ }
+ });
+ });
+
+ _cache$1.inflightTile[tile.id] = requests;
+ });
+ },
+
+ getComments(item) {
+ // If comments already retrieved no need to do so again
+ if (item.comments) {
+ return Promise.resolve(item);
+ }
+
+ const key = item.issueKey;
+ let qParams = {};
+
+ if (key === 'ow') {
+ qParams = item.identifier;
+ } else if (key === 'mr') {
+ qParams.tileX = item.identifier.x;
+ qParams.tileY = item.identifier.y;
+ } else if (key === 'tr') {
+ qParams.targetId = item.identifier;
+ }
+
+ const url = `${_impOsmUrls[key]}/retrieveComments?` + utilQsString(qParams);
+ const cacheComments = data => {
+ // Assign directly for immediate use afterwards
+ // comments are served newest to oldest
+ item.comments = data.comments ? data.comments.reverse() : [];
+ this.replaceItem(item);
+ };
+
+ return d3_json(url).then(cacheComments).then(() => item);
+ },
+
+ postUpdate(d, callback) {
+ if (!serviceOsm.authenticated()) { // Username required in payload
+ return callback({ message: 'Not Authenticated', status: -3}, d);
+ }
+ if (_cache$1.inflightPost[d.id]) {
+ return callback({ message: 'Error update already inflight', status: -2 }, d);
+ }
+
+ // Payload can only be sent once username is established
+ serviceOsm.userDetails(sendPayload.bind(this));
+
+ function sendPayload(err, user) {
+ if (err) { return callback(err, d); }
+
+ const key = d.issueKey;
+ const url = `${_impOsmUrls[key]}/comment`;
+ const payload = {
+ username: user.display_name,
+ targetIds: [ d.identifier ]
+ };
+
+ if (d.newStatus) {
+ payload.status = d.newStatus;
+ payload.text = 'status changed';
+ }
+
+ // Comment take place of default text
+ if (d.newComment) {
+ payload.text = d.newComment;
+ }
+
+ const controller = new AbortController();
+ _cache$1.inflightPost[d.id] = controller;
+
+ const options = {
+ method: 'POST',
+ signal: controller.signal,
+ body: JSON.stringify(payload)
+ };
+
+ d3_json(url, options)
+ .then(() => {
+ delete _cache$1.inflightPost[d.id];
+
+ // Just a comment, update error in cache
+ if (!d.newStatus) {
+ const now = new Date();
+ let comments = d.comments ? d.comments : [];
+
+ comments.push({
+ username: payload.username,
+ text: payload.text,
+ timestamp: now.getTime() / 1000
+ });
+
+ this.replaceItem(d.update({
+ comments: comments,
+ newComment: undefined
+ }));
+ } else {
+ this.removeItem(d);
+ if (d.newStatus === 'SOLVED') {
+ // Keep track of the number of issues closed per type to tag the changeset
+ if (!(d.issueKey in _cache$1.closed)) {
+ _cache$1.closed[d.issueKey] = 0;
+ }
+ _cache$1.closed[d.issueKey] += 1;
+ }
+ }
+ if (callback) callback(null, d);
+ })
+ .catch(err => {
+ delete _cache$1.inflightPost[d.id];
+ if (callback) callback(err.message);
+ });
+ }
+ },
+
+
+ // Get all cached QAItems covering the viewport
+ getItems(projection) {
+ const viewport = projection.clipExtent();
+ const min = [viewport[0][0], viewport[1][1]];
+ const max = [viewport[1][0], viewport[0][1]];
+ const bbox = geoExtent(projection.invert(min), projection.invert(max)).bbox();
+
+ return _cache$1.rtree.search(bbox).map(d => d.data);
+ },
+
+ // Get a QAItem from cache
+ // NOTE: Don't change method name until UI v3 is merged
+ getError(id) {
+ return _cache$1.data[id];
+ },
+
+ // get the name of the icon to display for this item
+ getIcon(itemType) {
+ return _impOsmData.icons[itemType];
+ },
+
+ // Replace a single QAItem in the cache
+ replaceItem(issue) {
+ if (!(issue instanceof QAItem) || !issue.id) return;
+
+ _cache$1.data[issue.id] = issue;
+ updateRtree$1(encodeIssueRtree$1(issue), true); // true = replace
+ return issue;
+ },
+
+ // Remove a single QAItem from the cache
+ removeItem(issue) {
+ if (!(issue instanceof QAItem) || !issue.id) return;
+
+ delete _cache$1.data[issue.id];
+ updateRtree$1(encodeIssueRtree$1(issue), false); // false = remove
+ },
+
+ // Used to populate `closed:improveosm:*` changeset tags
+ getClosedCounts() {
+ return _cache$1.closed;
+ }
+ };
+
+ const tiler$4 = utilTiler();
+ const dispatch$5 = dispatch('loaded');
+ const _tileZoom$2 = 14;
+ const _osmoseUrlRoot = 'https://osmose.openstreetmap.fr/api/0.3';
+ let _osmoseData = { icons: {}, items: [] };
+
+ // This gets reassigned if reset
+ let _cache$2;
+
+ function abortRequest$4(controller) {
+ if (controller) {
+ controller.abort();
+ }
+ }
+
+ function abortUnwantedRequests$2(cache, tiles) {
+ Object.keys(cache.inflightTile).forEach(k => {
+ let wanted = tiles.find(tile => k === tile.id);
+ if (!wanted) {
+ abortRequest$4(cache.inflightTile[k]);
+ delete cache.inflightTile[k];
+ }
+ });
+ }
+
+ function encodeIssueRtree$2(d) {
+ return { minX: d.loc[0], minY: d.loc[1], maxX: d.loc[0], maxY: d.loc[1], data: d };
+ }
+
+ // Replace or remove QAItem from rtree
+ function updateRtree$2(item, replace) {
+ _cache$2.rtree.remove(item, (a, b) => a.data.id === b.data.id);
+
+ if (replace) {
+ _cache$2.rtree.insert(item);
+ }
+ }
+
+ // Issues shouldn't obscure eachother
+ function preventCoincident$1(loc) {
+ let coincident = false;
+ do {
+ // first time, move marker up. after that, move marker right.
+ let delta = coincident ? [0.00001, 0] : [0, 0.00001];
+ loc = geoVecAdd(loc, delta);
+ let bbox = geoExtent(loc).bbox();
+ coincident = _cache$2.rtree.search(bbox).length;
+ } while (coincident);
+
+ return loc;
+ }
+
+ var serviceOsmose = {
+ title: 'osmose',
+
+ init() {
+ _mainFileFetcher.get('qa_data')
+ .then(d => {
+ _osmoseData = d.osmose;
+ _osmoseData.items = Object.keys(d.osmose.icons)
+ .map(s => s.split('-')[0])
+ .reduce((unique, item) => unique.indexOf(item) !== -1 ? unique : [...unique, item], []);
+ });
+
+ if (!_cache$2) {
+ this.reset();
+ }
+
+ this.event = utilRebind(this, dispatch$5, 'on');
+ },
+
+ reset() {
+ let _strings = {};
+ let _colors = {};
+ if (_cache$2) {
+ Object.values(_cache$2.inflightTile).forEach(abortRequest$4);
+ // Strings and colors are static and should not be re-populated
+ _strings = _cache$2.strings;
+ _colors = _cache$2.colors;
+ }
+ _cache$2 = {
+ data: {},
+ loadedTile: {},
+ inflightTile: {},
+ inflightPost: {},
+ closed: {},
+ rtree: new RBush(),
+ strings: _strings,
+ colors: _colors
+ };
+ },
+
+ loadIssues(projection) {
+ let params = {
+ // Tiles return a maximum # of issues
+ // So we want to filter our request for only types iD supports
+ item: _osmoseData.items
+ };
+
+ // determine the needed tiles to cover the view
+ let tiles = tiler$4
+ .zoomExtent([_tileZoom$2, _tileZoom$2])
+ .getTiles(projection);
+
+ // abort inflight requests that are no longer needed
+ abortUnwantedRequests$2(_cache$2, tiles);
+
+ // issue new requests..
+ tiles.forEach(tile => {
+ if (_cache$2.loadedTile[tile.id] || _cache$2.inflightTile[tile.id]) return;
+
+ let [ x, y, z ] = tile.xyz;
+ let url = `${_osmoseUrlRoot}/issues/${z}/${x}/${y}.json?` + utilQsString(params);
+
+ let controller = new AbortController();
+ _cache$2.inflightTile[tile.id] = controller;
+
+ d3_json(url, { signal: controller.signal })
+ .then(data => {
+ delete _cache$2.inflightTile[tile.id];
+ _cache$2.loadedTile[tile.id] = true;
+
+ if (data.features) {
+ data.features.forEach(issue => {
+ const { item, class: cl, uuid: id } = issue.properties;
+ /* Osmose issues are uniquely identified by a unique
+ `item` and `class` combination (both integer values) */
+ const itemType = `${item}-${cl}`;
+
+ // Filter out unsupported issue types (some are too specific or advanced)
+ if (itemType in _osmoseData.icons) {
+ let loc = issue.geometry.coordinates; // lon, lat
+ loc = preventCoincident$1(loc);
+
+ let d = new QAItem(loc, this, itemType, id, { item });
+
+ // Setting elems here prevents UI detail requests
+ if (item === 8300 || item === 8360) {
+ d.elems = [];
+ }
+
+ _cache$2.data[d.id] = d;
+ _cache$2.rtree.insert(encodeIssueRtree$2(d));
+ }
+ });
+ }
+
+ dispatch$5.call('loaded');
+ })
+ .catch(() => {
+ delete _cache$2.inflightTile[tile.id];
+ _cache$2.loadedTile[tile.id] = true;
+ });
+ });
+ },
+
+ loadIssueDetail(issue) {
+ // Issue details only need to be fetched once
+ if (issue.elems !== undefined) {
+ return Promise.resolve(issue);
+ }
+
+ const url = `${_osmoseUrlRoot}/issue/${issue.id}?langs=${_mainLocalizer.localeCode()}`;
+ const cacheDetails = data => {
+ // Associated elements used for highlighting
+ // Assign directly for immediate use in the callback
+ issue.elems = data.elems.map(e => e.type.substring(0,1) + e.id);
+
+ // Some issues have instance specific detail in a subtitle
+ issue.detail = data.subtitle ? marked_1(data.subtitle.auto) : '';
+
+ this.replaceItem(issue);
+ };
+
+ return d3_json(url).then(cacheDetails).then(() => issue);
+ },
+
+ loadStrings(locale=_mainLocalizer.localeCode()) {
+ const items = Object.keys(_osmoseData.icons);
+
+ if (
+ locale in _cache$2.strings
+ && Object.keys(_cache$2.strings[locale]).length === items.length
+ ) {
+ return Promise.resolve(_cache$2.strings[locale]);
+ }
+
+ // May be partially populated already if some requests were successful
+ if (!(locale in _cache$2.strings)) {
+ _cache$2.strings[locale] = {};
+ }
+
+ // Only need to cache strings for supported issue types
+ // Using multiple individual item + class requests to reduce fetched data size
+ const allRequests = items.map(itemType => {
+ // No need to request data we already have
+ if (itemType in _cache$2.strings[locale]) return;
+
+ const cacheData = data => {
+ // Bunch of nested single value arrays of objects
+ const [ cat = {items:[]} ] = data.categories;
+ const [ item = {class:[]} ] = cat.items;
+ const [ cl = null ] = item.class;
+
+ // If null default value is reached, data wasn't as expected (or was empty)
+ if (!cl) {
+ /* eslint-disable no-console */
+ console.log(`Osmose strings request (${itemType}) had unexpected data`);
+ /* eslint-enable no-console */
+ return;
+ }
+
+ // Cache served item colors to automatically style issue markers later
+ const { item: itemInt, color } = item;
+ if (/^#[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}/.test(color)) {
+ _cache$2.colors[itemInt] = color;
+ }
+
+ // Value of root key will be null if no string exists
+ // If string exists, value is an object with key 'auto' for string
+ const { title, detail, fix, trap } = cl;
+
+ // Osmose titles shouldn't contain markdown
+ let issueStrings = {};
+ if (title) issueStrings.title = title.auto;
+ if (detail) issueStrings.detail = marked_1(detail.auto);
+ if (trap) issueStrings.trap = marked_1(trap.auto);
+ if (fix) issueStrings.fix = marked_1(fix.auto);
+
+ _cache$2.strings[locale][itemType] = issueStrings;
+ };
+
+ const [ item, cl ] = itemType.split('-');
+
+ // Osmose API falls back to English strings where untranslated or if locale doesn't exist
+ const url = `${_osmoseUrlRoot}/items/${item}/class/${cl}?langs=${locale}`;
+
+ return d3_json(url).then(cacheData);
+ });
+
+ return Promise.all(allRequests).then(() => _cache$2.strings[locale]);
+ },
+
+ getStrings(itemType, locale=_mainLocalizer.localeCode()) {
+ // No need to fallback to English, Osmose API handles this for us
+ return (locale in _cache$2.strings) ? _cache$2.strings[locale][itemType] : {};
+ },
+
+ getColor(itemType) {
+ return (itemType in _cache$2.colors) ? _cache$2.colors[itemType] : '#FFFFFF';
+ },
+
+ postUpdate(issue, callback) {
+ if (_cache$2.inflightPost[issue.id]) {
+ return callback({ message: 'Issue update already inflight', status: -2 }, issue);
+ }
+
+ // UI sets the status to either 'done' or 'false'
+ const url = `${_osmoseUrlRoot}/issue/${issue.id}/${issue.newStatus}`;
+ const controller = new AbortController();
+ const after = () => {
+ delete _cache$2.inflightPost[issue.id];
+
+ this.removeItem(issue);
+ if (issue.newStatus === 'done') {
+ // Keep track of the number of issues closed per `item` to tag the changeset
+ if (!(issue.item in _cache$2.closed)) {
+ _cache$2.closed[issue.item] = 0;
+ }
+ _cache$2.closed[issue.item] += 1;
+ }
+ if (callback) callback(null, issue);
+ };
+
+ _cache$2.inflightPost[issue.id] = controller;
+
+ fetch(url, { signal: controller.signal })
+ .then(after)
+ .catch(err => {
+ delete _cache$2.inflightPost[issue.id];
+ if (callback) callback(err.message);
+ });
+ },
+
+ // Get all cached QAItems covering the viewport
+ getItems(projection) {
+ const viewport = projection.clipExtent();
+ const min = [viewport[0][0], viewport[1][1]];
+ const max = [viewport[1][0], viewport[0][1]];
+ const bbox = geoExtent(projection.invert(min), projection.invert(max)).bbox();
+
+ return _cache$2.rtree.search(bbox).map(d => d.data);
+ },
+
+ // Get a QAItem from cache
+ // NOTE: Don't change method name until UI v3 is merged
+ getError(id) {
+ return _cache$2.data[id];
+ },
+
+ // get the name of the icon to display for this item
+ getIcon(itemType) {
+ return _osmoseData.icons[itemType];
+ },
+
+ // Replace a single QAItem in the cache
+ replaceItem(item) {
+ if (!(item instanceof QAItem) || !item.id) return;
+
+ _cache$2.data[item.id] = item;
+ updateRtree$2(encodeIssueRtree$2(item), true); // true = replace
+ return item;
+ },
+
+ // Remove a single QAItem from the cache
+ removeItem(item) {
+ if (!(item instanceof QAItem) || !item.id) return;
+
+ delete _cache$2.data[item.id];
+ updateRtree$2(encodeIssueRtree$2(item), false); // false = remove
+ },
+
+ // Used to populate `closed:osmose:*` changeset tags
+ getClosedCounts() {
+ return _cache$2.closed;
+ },
+
+ itemURL(item) {
+ return `https://osmose.openstreetmap.fr/en/error/${item.id}`;
+ }
+ };
+
+ /* global Mapillary:false */
+
+
+ var apibase = 'https://a.mapillary.com/v3/';
+ var viewercss = 'mapillary-js/mapillary.min.css';
+ var viewerjs = 'mapillary-js/mapillary.min.js';
+ var clientId = 'NzNRM2otQkR2SHJzaXJmNmdQWVQ0dzo1ZWYyMmYwNjdmNDdlNmVi';
+ var mapFeatureConfig = {
+ values: [
+ 'construction--flat--crosswalk-plain',
+ 'marking--discrete--crosswalk-zebra',
+ 'object--banner',
+ 'object--bench',
+ 'object--bike-rack',
+ 'object--billboard',
+ 'object--catch-basin',
+ 'object--cctv-camera',
+ 'object--fire-hydrant',
+ 'object--mailbox',
+ 'object--manhole',
+ 'object--phone-booth',
+ 'object--sign--advertisement',
+ 'object--sign--information',
+ 'object--sign--store',
+ 'object--street-light',
+ 'object--support--utility-pole',
+ 'object--traffic-light--*',
+ 'object--traffic-light--pedestrians',
+ 'object--trash-can'
+ ].join(',')
+ };
+ var maxResults = 1000;
+ var tileZoom = 14;
+ var tiler$5 = utilTiler().zoomExtent([tileZoom, tileZoom]).skipNullIsland(true);
+ var dispatch$6 = dispatch('loadedImages', 'loadedSigns', 'loadedMapFeatures', 'bearingChanged');
+ var _mlyFallback = false;
+ var _mlyCache;
+ var _mlyClicks;
+ var _mlySelectedImageKey;
+ var _mlyViewer;
+
+
+ function abortRequest$5(controller) {
+ controller.abort();
+ }
+
+
+ function maxPageAtZoom(z) {
+ if (z < 15) return 2;
+ if (z === 15) return 5;
+ if (z === 16) return 10;
+ if (z === 17) return 20;
+ if (z === 18) return 40;
+ if (z > 18) return 80;
+ }
+
+
+ function loadTiles(which, url, projection) {
+ var currZoom = Math.floor(geoScaleToZoom(projection.scale()));
+ var tiles = tiler$5.getTiles(projection);
+
+ // abort inflight requests that are no longer needed
+ var cache = _mlyCache[which];
+ Object.keys(cache.inflight).forEach(function(k) {
+ var wanted = tiles.find(function(tile) { return k.indexOf(tile.id + ',') === 0; });
+ if (!wanted) {
+ abortRequest$5(cache.inflight[k]);
+ delete cache.inflight[k];
+ }
+ });
+
+ tiles.forEach(function(tile) {
+ loadNextTilePage(which, currZoom, url, tile);
+ });
+ }
+
+
+ function loadNextTilePage(which, currZoom, url, tile) {
+ var cache = _mlyCache[which];
+ var rect = tile.extent.rectangle();
+ var maxPages = maxPageAtZoom(currZoom);
+ var nextPage = cache.nextPage[tile.id] || 0;
+ var nextURL = cache.nextURL[tile.id] || url +
+ utilQsString({
+ per_page: maxResults,
+ page: nextPage,
+ client_id: clientId,
+ bbox: [rect[0], rect[1], rect[2], rect[3]].join(','),
+ });
+
+ if (nextPage > maxPages) return;
+
+ var id = tile.id + ',' + String(nextPage);
+ if (cache.loaded[id] || cache.inflight[id]) return;
+
+ var controller = new AbortController();
+ cache.inflight[id] = controller;
+
+ var options = {
+ method: 'GET',
+ signal: controller.signal,
+ headers: { 'Content-Type': 'application/json' }
+ };
+
+ fetch(nextURL, options)
+ .then(function(response) {
+ if (!response.ok) {
+ throw new Error(response.status + ' ' + response.statusText);
+ }
+ var linkHeader = response.headers.get('Link');
+ if (linkHeader) {
+ var pagination = parsePagination(linkHeader);
+ if (pagination.next) {
+ cache.nextURL[tile.id] = pagination.next;
+ }
+ }
+ return response.json();
+ })
+ .then(function(data) {
+ cache.loaded[id] = true;
+ delete cache.inflight[id];
+ if (!data || !data.features || !data.features.length) {
+ throw new Error('No Data');
+ }
+
+ var features = data.features.map(function(feature) {
+ var loc = feature.geometry.coordinates;
+ var d;
+
+ // An image (shown as a green dot on the map) is a single street photo with extra
+ // information such as location, camera angle (CA), camera model, and so on.
+ // Each image feature is a GeoJSON Point
+ if (which === 'images') {
+ d = {
+ loc: loc,
+ key: feature.properties.key,
+ ca: feature.properties.ca,
+ captured_at: feature.properties.captured_at,
+ captured_by: feature.properties.username,
+ pano: feature.properties.pano
+ };
+
+ cache.forImageKey[d.key] = d; // cache imageKey -> image
+
+ // Mapillary organizes images as sequences. A sequence of images are continuously captured
+ // by a user at a give time. Sequences are shown on the map as green lines.
+ // Each sequence feature is a GeoJSON LineString
+ } else if (which === 'sequences') {
+ var sequenceKey = feature.properties.key;
+ cache.lineString[sequenceKey] = feature; // cache sequenceKey -> lineString
+ feature.properties.coordinateProperties.image_keys.forEach(function(imageKey) {
+ cache.forImageKey[imageKey] = sequenceKey; // cache imageKey -> sequenceKey
+ });
+ return false; // because no `d` data worth loading into an rbush
+
+ // An image detection is a semantic pixel area on an image. The area could indicate
+ // sky, trees, sidewalk in the image. A detection can be a polygon, a bounding box, or a point.
+ // Each image_detection feature is a GeoJSON Point (located where the image was taken)
+ } else if (which === 'image_detections') {
+ d = {
+ key: feature.properties.key,
+ image_key: feature.properties.image_key,
+ value: feature.properties.value,
+ package: feature.properties.package,
+ shape: feature.properties.shape
+ };
+
+ // cache imageKey -> image_detections
+ if (!cache.forImageKey[d.image_key]) {
+ cache.forImageKey[d.image_key] = [];
+ }
+ cache.forImageKey[d.image_key].push(d);
+ return false; // because no `d` data worth loading into an rbush
+
+
+ // A map feature is a real world object that can be shown on a map. It could be any object
+ // recognized from images, manually added in images, or added on the map.
+ // Each map feature is a GeoJSON Point (located where the feature is)
+ } else if (which === 'map_features' || which === 'points') {
+ d = {
+ loc: loc,
+ key: feature.properties.key,
+ value: feature.properties.value,
+ package: feature.properties.package,
+ detections: feature.properties.detections
+ };
+ }
+
+ return {
+ minX: loc[0], minY: loc[1], maxX: loc[0], maxY: loc[1], data: d
+ };
+
+ }).filter(Boolean);
+
+ if (cache.rtree && features) {
+ cache.rtree.load(features);
+ }
+
+ if (data.features.length === maxResults) { // more pages to load
+ cache.nextPage[tile.id] = nextPage + 1;
+ loadNextTilePage(which, currZoom, url, tile);
+ } else {
+ cache.nextPage[tile.id] = Infinity; // no more pages to load
+ }
+
+ if (which === 'images' || which === 'sequences') {
+ dispatch$6.call('loadedImages');
+ } else if (which === 'map_features') {
+ dispatch$6.call('loadedSigns');
+ } else if (which === 'points') {
+ dispatch$6.call('loadedMapFeatures');
+ }
+ })
+ .catch(function() {
+ cache.loaded[id] = true;
+ delete cache.inflight[id];
+ });
+ }
+
+ // extract links to pages of API results
+ function parsePagination(links) {
+ return links.split(',').map(function(rel) {
+ var elements = rel.split(';');
+ if (elements.length === 2) {
+ return [
+ /<(.+)>/.exec(elements[0])[1],
+ /rel="(.+)"/.exec(elements[1])[1]
+ ];
+ } else {
+ return ['',''];
+ }
+ }).reduce(function(pagination, val) {
+ pagination[val[1]] = val[0];
+ return pagination;
+ }, {});
+ }
+
+
+ // partition viewport into higher zoom tiles
+ function partitionViewport(projection) {
+ var z = geoScaleToZoom(projection.scale());
+ var z2 = (Math.ceil(z * 2) / 2) + 2.5; // round to next 0.5 and add 2.5
+ var tiler = utilTiler().zoomExtent([z2, z2]);
+
+ return tiler.getTiles(projection)
+ .map(function(tile) { return tile.extent; });
+ }
+
+
+ // no more than `limit` results per partition.
+ function searchLimited(limit, projection, rtree) {
+ limit = limit || 5;
+
+ return partitionViewport(projection)
+ .reduce(function(result, extent) {
+ var found = rtree.search(extent.bbox())
+ .slice(0, limit)
+ .map(function(d) { return d.data; });
+
+ return (found.length ? result.concat(found) : result);
+ }, []);
+ }
+
+
+
+ var serviceMapillary = {
+
+ init: function() {
+ if (!_mlyCache) {
+ this.reset();
+ }
+
+ this.event = utilRebind(this, dispatch$6, 'on');
+ },
+
+ reset: function() {
+ if (_mlyCache) {
+ Object.values(_mlyCache.images.inflight).forEach(abortRequest$5);
+ Object.values(_mlyCache.image_detections.inflight).forEach(abortRequest$5);
+ Object.values(_mlyCache.map_features.inflight).forEach(abortRequest$5);
+ Object.values(_mlyCache.points.inflight).forEach(abortRequest$5);
+ Object.values(_mlyCache.sequences.inflight).forEach(abortRequest$5);
+ }
+
+ _mlyCache = {
+ images: { inflight: {}, loaded: {}, nextPage: {}, nextURL: {}, rtree: new RBush(), forImageKey: {} },
+ image_detections: { inflight: {}, loaded: {}, nextPage: {}, nextURL: {}, forImageKey: {} },
+ map_features: { inflight: {}, loaded: {}, nextPage: {}, nextURL: {}, rtree: new RBush() },
+ points: { inflight: {}, loaded: {}, nextPage: {}, nextURL: {}, rtree: new RBush() },
+ sequences: { inflight: {}, loaded: {}, nextPage: {}, nextURL: {}, rtree: new RBush(), forImageKey: {}, lineString: {} }
+ };
+
+ _mlySelectedImageKey = null;
+ _mlyClicks = [];
+ },
+
+
+ images: function(projection) {
+ var limit = 5;
+ return searchLimited(limit, projection, _mlyCache.images.rtree);
+ },
+
+
+ signs: function(projection) {
+ var limit = 5;
+ return searchLimited(limit, projection, _mlyCache.map_features.rtree);
+ },
+
+
+ mapFeatures: function(projection) {
+ var limit = 5;
+ return searchLimited(limit, projection, _mlyCache.points.rtree);
+ },
+
+
+ cachedImage: function(imageKey) {
+ return _mlyCache.images.forImageKey[imageKey];
+ },
+
+
+ sequences: function(projection) {
+ var viewport = projection.clipExtent();
+ var min = [viewport[0][0], viewport[1][1]];
+ var max = [viewport[1][0], viewport[0][1]];
+ var bbox = geoExtent(projection.invert(min), projection.invert(max)).bbox();
+ var sequenceKeys = {};
+
+ // all sequences for images in viewport
+ _mlyCache.images.rtree.search(bbox)
+ .forEach(function(d) {
+ var sequenceKey = _mlyCache.sequences.forImageKey[d.data.key];
+ if (sequenceKey) {
+ sequenceKeys[sequenceKey] = true;
+ }
+ });
+
+ // Return lineStrings for the sequences
+ return Object.keys(sequenceKeys).map(function(sequenceKey) {
+ return _mlyCache.sequences.lineString[sequenceKey];
+ });
+ },
+
+
+ signsSupported: function() {
+ return true;
+ },
+
+
+ loadImages: function(projection) {
+ loadTiles('images', apibase + 'images?sort_by=key&', projection);
+ loadTiles('sequences', apibase + 'sequences?sort_by=key&', projection);
+ },
+
+
+ loadSigns: function(projection) {
+ // if we are looking at signs, we'll actually need to fetch images too
+ loadTiles('images', apibase + 'images?sort_by=key&', projection);
+ loadTiles('map_features', apibase + 'map_features?layers=trafficsigns&min_nbr_image_detections=2&sort_by=key&', projection);
+ loadTiles('image_detections', apibase + 'image_detections?layers=trafficsigns&sort_by=key&', projection);
+ },
+
+
+ loadMapFeatures: function(projection) {
+ // if we are looking at signs, we'll actually need to fetch images too
+ loadTiles('images', apibase + 'images?sort_by=key', projection);
+ loadTiles('points', apibase + 'map_features?layers=points&min_nbr_image_detections=2&sort_by=key&values=' + mapFeatureConfig.values + '&', projection);
+ loadTiles('image_detections', apibase + 'image_detections?layers=points&sort_by=key&values=' + mapFeatureConfig.values + '&', projection);
+ },
+
+
+ loadViewer: function(context) {
+ // add mly-wrapper
+ var wrap = context.container().select('.photoviewer')
+ .selectAll('.mly-wrapper')
+ .data([0]);
+
+ wrap.enter()
+ .append('div')
+ .attr('id', 'ideditor-mly')
+ .attr('class', 'photo-wrapper mly-wrapper')
+ .classed('hide', true);
+
+ // load mapillary-viewercss
+ select('head').selectAll('#ideditor-mapillary-viewercss')
+ .data([0])
+ .enter()
+ .append('link')
+ .attr('id', 'ideditor-mapillary-viewercss')
+ .attr('rel', 'stylesheet')
+ .attr('href', context.asset(viewercss));
+
+ // load mapillary-viewerjs
+ select('head').selectAll('#ideditor-mapillary-viewerjs')
+ .data([0])
+ .enter()
+ .append('script')
+ .attr('id', 'ideditor-mapillary-viewerjs')
+ .attr('src', context.asset(viewerjs));
+
+ // load mapillary signs sprite
+ var defs = context.container().select('defs');
+ defs.call(svgDefs(context).addSprites, ['mapillary-sprite', 'mapillary-object-sprite'], false /* don't override colors */ );
+
+ // Register viewer resize handler
+ context.ui().photoviewer.on('resize.mapillary', function() {
+ if (_mlyViewer) {
+ _mlyViewer.resize();
+ }
+ });
+ },
+
+
+ showViewer: function(context) {
+ var wrap = context.container().select('.photoviewer')
+ .classed('hide', false);
+
+ var isHidden = wrap.selectAll('.photo-wrapper.mly-wrapper.hide').size();
+
+ if (isHidden && _mlyViewer) {
+ wrap
+ .selectAll('.photo-wrapper:not(.mly-wrapper)')
+ .classed('hide', true);
+
+ wrap
+ .selectAll('.photo-wrapper.mly-wrapper')
+ .classed('hide', false);
+
+ _mlyViewer.resize();
+ }
+
+ return this;
+ },
+
+
+ hideViewer: function(context) {
+ _mlySelectedImageKey = null;
+
+ if (!_mlyFallback && _mlyViewer) {
+ _mlyViewer.getComponent('sequence').stop();
+ }
+
+ var viewer = context.container().select('.photoviewer');
+ if (!viewer.empty()) viewer.datum(null);
+
+ viewer
+ .classed('hide', true)
+ .selectAll('.photo-wrapper')
+ .classed('hide', true);
+
+ context.container().selectAll('.viewfield-group, .sequence, .icon-detected')
+ .classed('currentView', false);
+
+ return this.setStyles(context, null, true);
+ },
+
+
+ parsePagination: parsePagination,
+
+
+ updateViewer: function(context, imageKey) {
+ if (!imageKey) return this;
+
+ if (!_mlyViewer) {
+ this.initViewer(context, imageKey);
+ } else {
+ _mlyViewer.moveToKey(imageKey)
+ .catch(function(e) { console.error('mly3', e); }); // eslint-disable-line no-console
+ }
+
+ return this;
+ },
+
+
+ initViewer: function(context, imageKey) {
+ var that = this;
+ if (window.Mapillary && imageKey) {
+ var opts = {
+ baseImageSize: 320,
+ component: {
+ cover: false,
+ keyboard: false,
+ tag: true
+ }
+ };
+
+ // Disable components requiring WebGL support
+ if (!Mapillary.isSupported() && Mapillary.isFallbackSupported()) {
+ _mlyFallback = true;
+ opts.component = {
+ cover: false,
+ direction: false,
+ imagePlane: false,
+ keyboard: false,
+ mouse: false,
+ sequence: false,
+ tag: false,
+ image: true, // fallback
+ navigation: true // fallback
+ };
+ }
+
+ _mlyViewer = new Mapillary.Viewer('ideditor-mly', clientId, null, opts);
+ _mlyViewer.on('nodechanged', nodeChanged);
+ _mlyViewer.on('bearingchanged', bearingChanged);
+ _mlyViewer.moveToKey(imageKey)
+ .catch(function(e) { console.error('mly3', e); }); // eslint-disable-line no-console
+ }
+
+ // nodeChanged: called after the viewer has changed images and is ready.
+ //
+ // There is some logic here to batch up clicks into a _mlyClicks array
+ // because the user might click on a lot of markers quickly and nodechanged
+ // may be called out of order asychronously.
+ //
+ // Clicks are added to the array in `selectedImage` and removed here.
+ //
+ function nodeChanged(node) {
+ if (!_mlyFallback) {
+ _mlyViewer.getComponent('tag').removeAll(); // remove previous detections
+ }
+
+ var clicks = _mlyClicks;
+ var index = clicks.indexOf(node.key);
+ var selectedKey = _mlySelectedImageKey;
+
+ if (index > -1) { // `nodechanged` initiated from clicking on a marker..
+ clicks.splice(index, 1); // remove the click
+ // If `node.key` matches the current _mlySelectedImageKey, call `selectImage()`
+ // one more time to update the detections and attribution..
+ if (node.key === selectedKey) {
+ that.selectImage(context, _mlySelectedImageKey, true);
+ }
+ } else { // `nodechanged` initiated from the Mapillary viewer controls..
+ var loc = node.computedLatLon ? [node.computedLatLon.lon, node.computedLatLon.lat] : [node.latLon.lon, node.latLon.lat];
+ context.map().centerEase(loc);
+ that.selectImage(context, node.key, true);
+ }
+ }
+
+ function bearingChanged(e) {
+ dispatch$6.call('bearingChanged', undefined, e);
+ }
+ },
+
+
+ // Pass in the image key string as `imageKey`.
+ // This allows images to be selected from places that dont have access
+ // to the full image datum (like the street signs layer or the js viewer)
+ selectImage: function(context, imageKey, fromViewer) {
+
+ _mlySelectedImageKey = imageKey;
+
+ // Note the datum could be missing, but we'll try to carry on anyway.
+ // There just might be a delay before user sees detections, captured_at, etc.
+ var d = _mlyCache.images.forImageKey[imageKey];
+
+ var viewer = context.container().select('.photoviewer');
+ if (!viewer.empty()) viewer.datum(d);
+
+ imageKey = (d && d.key) || imageKey;
+ if (!fromViewer && imageKey) {
+ _mlyClicks.push(imageKey);
+ }
+
+ this.setStyles(context, null, true);
+
+ // if signs signs are shown, highlight the ones that appear in this image
+ context.container().selectAll('.layer-mapillary-signs .icon-detected')
+ .classed('currentView', function(d) {
+ return d.detections.some(function(detection) {
+ return detection.image_key === imageKey;
+ });
+ });
+
+ if (d) {
+ this.updateDetections(d);
+ }
+
+ return this;
+ },
+
+
+ getSelectedImageKey: function() {
+ return _mlySelectedImageKey;
+ },
+
+
+ getSequenceKeyForImageKey: function(imageKey) {
+ return _mlyCache.sequences.forImageKey[imageKey];
+ },
+
+
+ // Updates the currently highlighted sequence and selected bubble.
+ // Reset is only necessary when interacting with the viewport because
+ // this implicitly changes the currently selected bubble/sequence
+ setStyles: function(context, hovered, reset) {
+ if (reset) { // reset all layers
+ context.container().selectAll('.viewfield-group')
+ .classed('highlighted', false)
+ .classed('hovered', false)
+ .classed('currentView', false);
+
+ context.container().selectAll('.sequence')
+ .classed('highlighted', false)
+ .classed('currentView', false);
+ }
+
+ var hoveredImageKey = hovered && hovered.key;
+ var hoveredSequenceKey = hoveredImageKey && this.getSequenceKeyForImageKey(hoveredImageKey);
+ var hoveredLineString = hoveredSequenceKey && _mlyCache.sequences.lineString[hoveredSequenceKey];
+ var hoveredImageKeys = (hoveredLineString && hoveredLineString.properties.coordinateProperties.image_keys) || [];
+
+ var selectedImageKey = _mlySelectedImageKey;
+ var selectedSequenceKey = selectedImageKey && this.getSequenceKeyForImageKey(selectedImageKey);
+ var selectedLineString = selectedSequenceKey && _mlyCache.sequences.lineString[selectedSequenceKey];
+ var selectedImageKeys = (selectedLineString && selectedLineString.properties.coordinateProperties.image_keys) || [];
+
+ // highlight sibling viewfields on either the selected or the hovered sequences
+ var highlightedImageKeys = utilArrayUnion(hoveredImageKeys, selectedImageKeys);
+
+ context.container().selectAll('.layer-mapillary .viewfield-group')
+ .classed('highlighted', function(d) { return highlightedImageKeys.indexOf(d.key) !== -1; })
+ .classed('hovered', function(d) { return d.key === hoveredImageKey; })
+ .classed('currentView', function(d) { return d.key === selectedImageKey; });
+
+ context.container().selectAll('.layer-mapillary .sequence')
+ .classed('highlighted', function(d) { return d.properties.key === hoveredSequenceKey; })
+ .classed('currentView', function(d) { return d.properties.key === selectedSequenceKey; });
+
+ // update viewfields if needed
+ context.container().selectAll('.viewfield-group .viewfield')
+ .attr('d', viewfieldPath);
+
+ function viewfieldPath() {
+ var d = this.parentNode.__data__;
+ if (d.pano && d.key !== selectedImageKey) {
+ return 'M 8,13 m -10,0 a 10,10 0 1,0 20,0 a 10,10 0 1,0 -20,0';
+ } else {
+ return 'M 6,9 C 8,8.4 8,8.4 10,9 L 16,-2 C 12,-5 4,-5 0,-2 z';
+ }
+ }
+
+ return this;
+ },
+
+
+ updateDetections: function(d) {
+ if (!_mlyViewer || _mlyFallback) return;
+
+ var imageKey = d && d.key;
+ if (!imageKey) return;
+
+ var detections = _mlyCache.image_detections.forImageKey[imageKey] || [];
+ detections.forEach(function(data) {
+ var tag = makeTag(data);
+ if (tag) {
+ var tagComponent = _mlyViewer.getComponent('tag');
+ tagComponent.add([tag]);
+ }
+ });
+
+ function makeTag(data) {
+ var valueParts = data.value.split('--');
+ if (valueParts.length !== 3) return;
+
+ var text = valueParts[1].replace(/-/g, ' ');
+ var tag;
+
+ // Currently only two shapes
+ if (data.shape.type === 'Polygon') {
+ var polygonGeometry = new Mapillary
+ .TagComponent
+ .PolygonGeometry(data.shape.coordinates[0]);
+
+ tag = new Mapillary.TagComponent.OutlineTag(
+ data.key,
+ polygonGeometry,
+ {
+ text: text,
+ textColor: 0xffff00,
+ lineColor: 0xffff00,
+ lineWidth: 2,
+ fillColor: 0xffff00,
+ fillOpacity: 0.3,
+ }
+ );
+
+ } else if (data.shape.type === 'Point') {
+ var pointGeometry = new Mapillary
+ .TagComponent
+ .PointGeometry(data.shape.coordinates[0]);
+
+ tag = new Mapillary.TagComponent.SpotTag(
+ data.key,
+ pointGeometry,
+ {
+ text: text,
+ color: 0xffff00,
+ textColor: 0xffff00
+ }
+ );
+ }
+
+ return tag;
+ }
+ },
+
+
+ cache: function() {
+ return _mlyCache;
+ }
+
+ };
+
+ var buildRuleChecks = function() {
+ return {
+ equals: function (equals) {
+ return function(tags) {
+ return Object.keys(equals).every(function(k) {
+ return equals[k] === tags[k];
+ });
+ };
+ },
+ notEquals: function (notEquals) {
+ return function(tags) {
+ return Object.keys(notEquals).some(function(k) {
+ return notEquals[k] !== tags[k];
+ });
+ };
+ },
+ absence: function(absence) {
+ return function(tags) {
+ return Object.keys(tags).indexOf(absence) === -1;
+ };
+ },
+ presence: function(presence) {
+ return function(tags) {
+ return Object.keys(tags).indexOf(presence) > -1;
+ };
+ },
+ greaterThan: function(greaterThan) {
+ var key = Object.keys(greaterThan)[0];
+ var value = greaterThan[key];
+
+ return function(tags) {
+ return tags[key] > value;
+ };
+ },
+ greaterThanEqual: function(greaterThanEqual) {
+ var key = Object.keys(greaterThanEqual)[0];
+ var value = greaterThanEqual[key];
+
+ return function(tags) {
+ return tags[key] >= value;
+ };
+ },
+ lessThan: function(lessThan) {
+ var key = Object.keys(lessThan)[0];
+ var value = lessThan[key];
+
+ return function(tags) {
+ return tags[key] < value;
+ };
+ },
+ lessThanEqual: function(lessThanEqual) {
+ var key = Object.keys(lessThanEqual)[0];
+ var value = lessThanEqual[key];
+
+ return function(tags) {
+ return tags[key] <= value;
+ };
+ },
+ positiveRegex: function(positiveRegex) {
+ var tagKey = Object.keys(positiveRegex)[0];
+ var expression = positiveRegex[tagKey].join('|');
+ var regex = new RegExp(expression);
+
+ return function(tags) {
+ return regex.test(tags[tagKey]);
+ };
+ },
+ negativeRegex: function(negativeRegex) {
+ var tagKey = Object.keys(negativeRegex)[0];
+ var expression = negativeRegex[tagKey].join('|');
+ var regex = new RegExp(expression);
+
+ return function(tags) {
+ return !regex.test(tags[tagKey]);
+ };
+ }
+ };
+ };
+
+ var buildLineKeys = function() {
+ return {
+ highway: {
+ rest_area: true,
+ services: true
+ },
+ railway: {
+ roundhouse: true,
+ station: true,
+ traverser: true,
+ turntable: true,
+ wash: true
+ }
+ };
+ };
+
+ var serviceMapRules = {
+ init: function() {
+ this._ruleChecks = buildRuleChecks();
+ this._validationRules = [];
+ this._areaKeys = osmAreaKeys;
+ this._lineKeys = buildLineKeys();
+ },
+
+ // list of rules only relevant to tag checks...
+ filterRuleChecks: function(selector) {
+ var _ruleChecks = this._ruleChecks;
+ return Object.keys(selector).reduce(function(rules, key) {
+ if (['geometry', 'error', 'warning'].indexOf(key) === -1) {
+ rules.push(_ruleChecks[key](selector[key]));
+ }
+ return rules;
+ }, []);
+ },
+
+ // builds tagMap from mapcss-parse selector object...
+ buildTagMap: function(selector) {
+ var getRegexValues = function(regexes) {
+ return regexes.map(function(regex) {
+ return regex.replace(/\$|\^/g, '');
+ });
+ };
+
+ var tagMap = Object.keys(selector).reduce(function (expectedTags, key) {
+ var values;
+ var isRegex = /regex/gi.test(key);
+ var isEqual = /equals/gi.test(key);
+
+ if (isRegex || isEqual) {
+ Object.keys(selector[key]).forEach(function(selectorKey) {
+ values = isEqual ? [selector[key][selectorKey]] : getRegexValues(selector[key][selectorKey]);
+
+ if (expectedTags.hasOwnProperty(selectorKey)) {
+ values = values.concat(expectedTags[selectorKey]);
+ }
+
+ expectedTags[selectorKey] = values;
+ });
+
+ } else if (/(greater|less)Than(Equal)?|presence/g.test(key)) {
+ var tagKey = /presence/.test(key) ? selector[key] : Object.keys(selector[key])[0];
+
+ values = [selector[key][tagKey]];
+
+ if (expectedTags.hasOwnProperty(tagKey)) {
+ values = values.concat(expectedTags[tagKey]);
+ }
+
+ expectedTags[tagKey] = values;
+ }
+
+ return expectedTags;
+ }, {});
+
+ return tagMap;
+ },
+
+ // inspired by osmWay#isArea()
+ inferGeometry: function(tagMap) {
+ var _lineKeys = this._lineKeys;
+ var _areaKeys = this._areaKeys;
+
+ var keyValueDoesNotImplyArea = function(key) {
+ return utilArrayIntersection(tagMap[key], Object.keys(_areaKeys[key])).length > 0;
+ };
+ var keyValueImpliesLine = function(key) {
+ return utilArrayIntersection(tagMap[key], Object.keys(_lineKeys[key])).length > 0;
+ };
+
+ if (tagMap.hasOwnProperty('area')) {
+ if (tagMap.area.indexOf('yes') > -1) {
+ return 'area';
+ }
+ if (tagMap.area.indexOf('no') > -1) {
+ return 'line';
+ }
+ }
+
+ for (var key in tagMap) {
+ if (key in _areaKeys && !keyValueDoesNotImplyArea(key)) {
+ return 'area';
+ }
+ if (key in _lineKeys && keyValueImpliesLine(key)) {
+ return 'area';
+ }
+ }
+
+ return 'line';
+ },
+
+ // adds from mapcss-parse selector check...
+ addRule: function(selector) {
+ var rule = {
+ // checks relevant to mapcss-selector
+ checks: this.filterRuleChecks(selector),
+ // true if all conditions for a tag error are true..
+ matches: function(entity) {
+ return this.checks.every(function(check) {
+ return check(entity.tags);
+ });
+ },
+ // borrowed from Way#isArea()
+ inferredGeometry: this.inferGeometry(this.buildTagMap(selector), this._areaKeys),
+ geometryMatches: function(entity, graph) {
+ if (entity.type === 'node' || entity.type === 'relation') {
+ return selector.geometry === entity.type;
+ } else if (entity.type === 'way') {
+ return this.inferredGeometry === entity.geometry(graph);
+ }
+ },
+ // when geometries match and tag matches are present, return a warning...
+ findIssues: function (entity, graph, issues) {
+ if (this.geometryMatches(entity, graph) && this.matches(entity)) {
+ var severity = Object.keys(selector).indexOf('error') > -1
+ ? 'error'
+ : 'warning';
+ var message = selector[severity];
+ issues.push(new validationIssue({
+ type: 'maprules',
+ severity: severity,
+ message: function() {
+ return message;
+ },
+ entityIds: [entity.id]
+ }));
+ }
+ }
+ };
+ this._validationRules.push(rule);
+ },
+
+ clearRules: function() { this._validationRules = []; },
+
+ // returns validationRules...
+ validationRules: function() { return this._validationRules; },
+
+ // returns ruleChecks
+ ruleChecks: function() { return this._ruleChecks; }
+ };
+
+ var apibase$1 = 'https://nominatim.openstreetmap.org/';
+ var _inflight = {};
+ var _nominatimCache;
+
+
+ var serviceNominatim = {
+
+ init: function() {
+ _inflight = {};
+ _nominatimCache = new RBush();
+ },
+
+ reset: function() {
+ Object.values(_inflight).forEach(function(controller) { controller.abort(); });
+ _inflight = {};
+ _nominatimCache = new RBush();
+ },
+
+
+ countryCode: function (location, callback) {
+ this.reverse(location, function(err, result) {
+ if (err) {
+ return callback(err);
+ } else if (result.address) {
+ return callback(null, result.address.country_code);
+ } else {
+ return callback('Unable to geocode', null);
+ }
+ });
+ },
+
+
+ reverse: function (loc, callback) {
+ var cached = _nominatimCache.search(
+ { minX: loc[0], minY: loc[1], maxX: loc[0], maxY: loc[1] }
+ );
+
+ if (cached.length > 0) {
+ if (callback) callback(null, cached[0].data);
+ return;
+ }
+
+ var params = { zoom: 13, format: 'json', addressdetails: 1, lat: loc[1], lon: loc[0] };
+ var url = apibase$1 + 'reverse?' + utilQsString(params);
+
+ if (_inflight[url]) return;
+ var controller = new AbortController();
+ _inflight[url] = controller;
+
+ d3_json(url, { signal: controller.signal })
+ .then(function(result) {
+ delete _inflight[url];
+ if (result && result.error) {
+ throw new Error(result.error);
+ }
+ var extent = geoExtent(loc).padByMeters(200);
+ _nominatimCache.insert(Object.assign(extent.bbox(), {data: result}));
+ if (callback) callback(null, result);
+ })
+ .catch(function(err) {
+ delete _inflight[url];
+ if (err.name === 'AbortError') return;
+ if (callback) callback(err.message);
+ });
+ },
+
+
+ search: function (val, callback) {
+ var searchVal = encodeURIComponent(val);
+ var url = apibase$1 + 'search/' + searchVal + '?limit=10&format=json';
+
+ if (_inflight[url]) return;
+ var controller = new AbortController();
+ _inflight[url] = controller;
+
+ d3_json(url, { signal: controller.signal })
+ .then(function(result) {
+ delete _inflight[url];
+ if (result && result.error) {
+ throw new Error(result.error);
+ }
+ if (callback) callback(null, result);
+ })
+ .catch(function(err) {
+ delete _inflight[url];
+ if (err.name === 'AbortError') return;
+ if (callback) callback(err.message);
+ });
+ }
+
+ };
+
+ var apibase$2 = 'https://openstreetcam.org';
+ var maxResults$1 = 1000;
+ var tileZoom$1 = 14;
+ var tiler$6 = utilTiler().zoomExtent([tileZoom$1, tileZoom$1]).skipNullIsland(true);
+ var dispatch$7 = dispatch('loadedImages');
+ var imgZoom = d3_zoom()
+ .extent([[0, 0], [320, 240]])
+ .translateExtent([[0, 0], [320, 240]])
+ .scaleExtent([1, 15]);
+ var _oscCache;
+ var _oscSelectedImage;
+
+
+ function abortRequest$6(controller) {
+ controller.abort();
+ }
+
+
+ function maxPageAtZoom$1(z) {
+ if (z < 15) return 2;
+ if (z === 15) return 5;
+ if (z === 16) return 10;
+ if (z === 17) return 20;
+ if (z === 18) return 40;
+ if (z > 18) return 80;
+ }
+
+
+ function loadTiles$1(which, url, projection) {
+ var currZoom = Math.floor(geoScaleToZoom(projection.scale()));
+ var tiles = tiler$6.getTiles(projection);
+
+ // abort inflight requests that are no longer needed
+ var cache = _oscCache[which];
+ Object.keys(cache.inflight).forEach(function(k) {
+ var wanted = tiles.find(function(tile) { return k.indexOf(tile.id + ',') === 0; });
+ if (!wanted) {
+ abortRequest$6(cache.inflight[k]);
+ delete cache.inflight[k];
+ }
+ });
+
+ tiles.forEach(function(tile) {
+ loadNextTilePage$1(which, currZoom, url, tile);
+ });
+ }
+
+
+ function loadNextTilePage$1(which, currZoom, url, tile) {
+ var cache = _oscCache[which];
+ var bbox = tile.extent.bbox();
+ var maxPages = maxPageAtZoom$1(currZoom);
+ var nextPage = cache.nextPage[tile.id] || 1;
+ var params = utilQsString({
+ ipp: maxResults$1,
+ page: nextPage,
+ // client_id: clientId,
+ bbTopLeft: [bbox.maxY, bbox.minX].join(','),
+ bbBottomRight: [bbox.minY, bbox.maxX].join(',')
+ }, true);
+
+ if (nextPage > maxPages) return;
+
+ var id = tile.id + ',' + String(nextPage);
+ if (cache.loaded[id] || cache.inflight[id]) return;
+
+ var controller = new AbortController();
+ cache.inflight[id] = controller;
+
+ var options = {
+ method: 'POST',
+ signal: controller.signal,
+ body: params,
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
+ };
+
+ d3_json(url, options)
+ .then(function(data) {
+ cache.loaded[id] = true;
+ delete cache.inflight[id];
+ if (!data || !data.currentPageItems || !data.currentPageItems.length) {
+ throw new Error('No Data');
+ }
+
+ var features = data.currentPageItems.map(function(item) {
+ var loc = [+item.lng, +item.lat];
+ var d;
+
+ if (which === 'images') {
+ d = {
+ loc: loc,
+ key: item.id,
+ ca: +item.heading,
+ captured_at: (item.shot_date || item.date_added),
+ captured_by: item.username,
+ imagePath: item.lth_name,
+ sequence_id: item.sequence_id,
+ sequence_index: +item.sequence_index
+ };
+
+ // cache sequence info
+ var seq = _oscCache.sequences[d.sequence_id];
+ if (!seq) {
+ seq = { rotation: 0, images: [] };
+ _oscCache.sequences[d.sequence_id] = seq;
+ }
+ seq.images[d.sequence_index] = d;
+ }
+
+ return {
+ minX: loc[0], minY: loc[1], maxX: loc[0], maxY: loc[1], data: d
+ };
+ });
+
+ cache.rtree.load(features);
+
+ if (data.currentPageItems.length === maxResults$1) { // more pages to load
+ cache.nextPage[tile.id] = nextPage + 1;
+ loadNextTilePage$1(which, currZoom, url, tile);
+ } else {
+ cache.nextPage[tile.id] = Infinity; // no more pages to load
+ }
+
+ if (which === 'images') {
+ dispatch$7.call('loadedImages');
+ }
+ })
+ .catch(function() {
+ cache.loaded[id] = true;
+ delete cache.inflight[id];
+ });
+ }
+
+
+ // partition viewport into higher zoom tiles
+ function partitionViewport$1(projection) {
+ var z = geoScaleToZoom(projection.scale());
+ var z2 = (Math.ceil(z * 2) / 2) + 2.5; // round to next 0.5 and add 2.5
+ var tiler = utilTiler().zoomExtent([z2, z2]);
+
+ return tiler.getTiles(projection)
+ .map(function(tile) { return tile.extent; });
+ }
+
+
+ // no more than `limit` results per partition.
+ function searchLimited$1(limit, projection, rtree) {
+ limit = limit || 5;
+
+ return partitionViewport$1(projection)
+ .reduce(function(result, extent) {
+ var found = rtree.search(extent.bbox())
+ .slice(0, limit)
+ .map(function(d) { return d.data; });
+
+ return (found.length ? result.concat(found) : result);
+ }, []);
+ }
+
+
+ var serviceOpenstreetcam = {
+
+ init: function() {
+ if (!_oscCache) {
+ this.reset();
+ }
+
+ this.event = utilRebind(this, dispatch$7, 'on');
+ },
+
+ reset: function() {
+ if (_oscCache) {
+ Object.values(_oscCache.images.inflight).forEach(abortRequest$6);
+ }
+
+ _oscCache = {
+ images: { inflight: {}, loaded: {}, nextPage: {}, rtree: new RBush() },
+ sequences: {}
+ };
+
+ _oscSelectedImage = null;
+ },
+
+
+ images: function(projection) {
+ var limit = 5;
+ return searchLimited$1(limit, projection, _oscCache.images.rtree);
+ },
+
+
+ sequences: function(projection) {
+ var viewport = projection.clipExtent();
+ var min = [viewport[0][0], viewport[1][1]];
+ var max = [viewport[1][0], viewport[0][1]];
+ var bbox = geoExtent(projection.invert(min), projection.invert(max)).bbox();
+ var sequenceKeys = {};
+
+ // all sequences for images in viewport
+ _oscCache.images.rtree.search(bbox)
+ .forEach(function(d) { sequenceKeys[d.data.sequence_id] = true; });
+
+ // make linestrings from those sequences
+ var lineStrings = [];
+ Object.keys(sequenceKeys)
+ .forEach(function(sequenceKey) {
+ var seq = _oscCache.sequences[sequenceKey];
+ var images = seq && seq.images;
+ if (images) {
+ lineStrings.push({
+ type: 'LineString',
+ coordinates: images.map(function (d) { return d.loc; }).filter(Boolean),
+ properties: { key: sequenceKey }
+ });
+ }
+ });
+ return lineStrings;
+ },
+
+
+ loadImages: function(projection) {
+ var url = apibase$2 + '/1.0/list/nearby-photos/';
+ loadTiles$1('images', url, projection);
+ },
+
+
+ loadViewer: function(context) {
+ var that = this;
+
+ // add osc-wrapper
+ var wrap = context.container().select('.photoviewer').selectAll('.osc-wrapper')
+ .data([0]);
+
+ var wrapEnter = wrap.enter()
+ .append('div')
+ .attr('class', 'photo-wrapper osc-wrapper')
+ .classed('hide', true)
+ .call(imgZoom.on('zoom', zoomPan))
+ .on('dblclick.zoom', null);
+
+ wrapEnter
+ .append('div')
+ .attr('class', 'photo-attribution fillD');
+
+ var controlsEnter = wrapEnter
+ .append('div')
+ .attr('class', 'photo-controls-wrap')
+ .append('div')
+ .attr('class', 'photo-controls');
+
+ controlsEnter
+ .append('button')
+ .on('click.back', step(-1))
+ .text('◄');
+
+ controlsEnter
+ .append('button')
+ .on('click.rotate-ccw', rotate(-90))
+ .text('⤿');
+
+ controlsEnter
+ .append('button')
+ .on('click.rotate-cw', rotate(90))
+ .text('⤾');
+
+ controlsEnter
+ .append('button')
+ .on('click.forward', step(1))
+ .text('►');
+
+ wrapEnter
+ .append('div')
+ .attr('class', 'osc-image-wrap');
+
+
+ // Register viewer resize handler
+ context.ui().photoviewer.on('resize.openstreetcam', function(dimensions) {
+ imgZoom = d3_zoom()
+ .extent([[0, 0], dimensions])
+ .translateExtent([[0, 0], dimensions])
+ .scaleExtent([1, 15])
+ .on('zoom', zoomPan);
+ });
+
+
+ function zoomPan() {
+ var t = event.transform;
+ context.container().select('.photoviewer .osc-image-wrap')
+ .call(utilSetTransform, t.x, t.y, t.k);
+ }
+
+
+ function rotate(deg) {
+ return function() {
+ if (!_oscSelectedImage) return;
+ var sequenceKey = _oscSelectedImage.sequence_id;
+ var sequence = _oscCache.sequences[sequenceKey];
+ if (!sequence) return;
+
+ var r = sequence.rotation || 0;
+ r += deg;
+
+ if (r > 180) r -= 360;
+ if (r < -180) r += 360;
+ sequence.rotation = r;
+
+ var wrap = context.container().select('.photoviewer .osc-wrapper');
+
+ wrap
+ .transition()
+ .duration(100)
+ .call(imgZoom.transform, identity$2);
+
+ wrap.selectAll('.osc-image')
+ .transition()
+ .duration(100)
+ .style('transform', 'rotate(' + r + 'deg)');
+ };
+ }
+
+ function step(stepBy) {
+ return function() {
+ if (!_oscSelectedImage) return;
+ var sequenceKey = _oscSelectedImage.sequence_id;
+ var sequence = _oscCache.sequences[sequenceKey];
+ if (!sequence) return;
+
+ var nextIndex = _oscSelectedImage.sequence_index + stepBy;
+ var nextImage = sequence.images[nextIndex];
+ if (!nextImage) return;
+
+ context.map().centerEase(nextImage.loc);
+
+ that
+ .selectImage(context, nextImage)
+ .updateViewer(context, nextImage);
+ };
+ }
+ },
+
+
+ showViewer: function(context) {
+ var viewer = context.container().select('.photoviewer')
+ .classed('hide', false);
+
+ var isHidden = viewer.selectAll('.photo-wrapper.osc-wrapper.hide').size();
+
+ if (isHidden) {
+ viewer
+ .selectAll('.photo-wrapper:not(.osc-wrapper)')
+ .classed('hide', true);
+
+ viewer
+ .selectAll('.photo-wrapper.osc-wrapper')
+ .classed('hide', false);
+ }
+
+ return this;
+ },
+
+
+ hideViewer: function(context) {
+ _oscSelectedImage = null;
+
+ var viewer = context.container().select('.photoviewer');
+ if (!viewer.empty()) viewer.datum(null);
+
+ viewer
+ .classed('hide', true)
+ .selectAll('.photo-wrapper')
+ .classed('hide', true);
+
+ context.container().selectAll('.viewfield-group, .sequence, .icon-sign')
+ .classed('currentView', false);
+
+ return this.setStyles(context, null, true);
+ },
+
+
+ updateViewer: function(context, d) {
+ var wrap = context.container().select('.photoviewer .osc-wrapper');
+ var imageWrap = wrap.selectAll('.osc-image-wrap');
+ var attribution = wrap.selectAll('.photo-attribution').html('');
+
+ wrap
+ .transition()
+ .duration(100)
+ .call(imgZoom.transform, identity$2);
+
+ imageWrap
+ .selectAll('.osc-image')
+ .remove();
+
+ if (d) {
+ var sequence = _oscCache.sequences[d.sequence_id];
+ var r = (sequence && sequence.rotation) || 0;
+
+ imageWrap
+ .append('img')
+ .attr('class', 'osc-image')
+ .attr('src', apibase$2 + '/' + d.imagePath)
+ .style('transform', 'rotate(' + r + 'deg)');
+
+ if (d.captured_by) {
+ attribution
+ .append('a')
+ .attr('class', 'captured_by')
+ .attr('target', '_blank')
+ .attr('href', 'https://openstreetcam.org/user/' + encodeURIComponent(d.captured_by))
+ .text('@' + d.captured_by);
+
+ attribution
+ .append('span')
+ .text('|');
+ }
+
+ if (d.captured_at) {
+ attribution
+ .append('span')
+ .attr('class', 'captured_at')
+ .text(localeDateString(d.captured_at));
+
+ attribution
+ .append('span')
+ .text('|');
+ }
+
+ attribution
+ .append('a')
+ .attr('class', 'image-link')
+ .attr('target', '_blank')
+ .attr('href', 'https://openstreetcam.org/details/' + d.sequence_id + '/' + d.sequence_index)
+ .text('openstreetcam.org');
+ }
+
+ return this;
+
+
+ function localeDateString(s) {
+ if (!s) return null;
+ var options = { day: 'numeric', month: 'short', year: 'numeric' };
+ var d = new Date(s);
+ if (isNaN(d.getTime())) return null;
+ return d.toLocaleDateString(_mainLocalizer.localeCode(), options);
+ }
+ },
+
+
+ selectImage: function(context, d) {
+ _oscSelectedImage = d;
+ var viewer = context.container().select('.photoviewer');
+ if (!viewer.empty()) viewer.datum(d);
+
+ this.setStyles(context, null, true);
+
+ context.container().selectAll('.icon-sign')
+ .classed('currentView', false);
+
+ return this;
+ },
+
+
+ getSelectedImage: function() {
+ return _oscSelectedImage;
+ },
+
+
+ getSequenceKeyForImage: function(d) {
+ return d && d.sequence_id;
+ },
+
+
+ // Updates the currently highlighted sequence and selected bubble.
+ // Reset is only necessary when interacting with the viewport because
+ // this implicitly changes the currently selected bubble/sequence
+ setStyles: function(context, hovered, reset) {
+ if (reset) { // reset all layers
+ context.container().selectAll('.viewfield-group')
+ .classed('highlighted', false)
+ .classed('hovered', false)
+ .classed('currentView', false);
+
+ context.container().selectAll('.sequence')
+ .classed('highlighted', false)
+ .classed('currentView', false);
+ }
+
+ var hoveredImageKey = hovered && hovered.key;
+ var hoveredSequenceKey = this.getSequenceKeyForImage(hovered);
+ var hoveredSequence = hoveredSequenceKey && _oscCache.sequences[hoveredSequenceKey];
+ var hoveredImageKeys = (hoveredSequence && hoveredSequence.images.map(function (d) { return d.key; })) || [];
+
+ var viewer = context.container().select('.photoviewer');
+ var selected = viewer.empty() ? undefined : viewer.datum();
+ var selectedImageKey = selected && selected.key;
+ var selectedSequenceKey = this.getSequenceKeyForImage(selected);
+ var selectedSequence = selectedSequenceKey && _oscCache.sequences[selectedSequenceKey];
+ var selectedImageKeys = (selectedSequence && selectedSequence.images.map(function (d) { return d.key; })) || [];
+
+ // highlight sibling viewfields on either the selected or the hovered sequences
+ var highlightedImageKeys = utilArrayUnion(hoveredImageKeys, selectedImageKeys);
+
+ context.container().selectAll('.layer-openstreetcam .viewfield-group')
+ .classed('highlighted', function(d) { return highlightedImageKeys.indexOf(d.key) !== -1; })
+ .classed('hovered', function(d) { return d.key === hoveredImageKey; })
+ .classed('currentView', function(d) { return d.key === selectedImageKey; });
+
+ context.container().selectAll('.layer-openstreetcam .sequence')
+ .classed('highlighted', function(d) { return d.properties.key === hoveredSequenceKey; })
+ .classed('currentView', function(d) { return d.properties.key === selectedSequenceKey; });
+
+ // update viewfields if needed
+ context.container().selectAll('.viewfield-group .viewfield')
+ .attr('d', viewfieldPath);
+
+ function viewfieldPath() {
+ var d = this.parentNode.__data__;
+ if (d.pano && d.key !== selectedImageKey) {
+ return 'M 8,13 m -10,0 a 10,10 0 1,0 20,0 a 10,10 0 1,0 -20,0';
+ } else {
+ return 'M 6,9 C 8,8.4 8,8.4 10,9 L 16,-2 C 12,-5 4,-5 0,-2 z';
+ }
+ }
+
+ return this;
+ },
+
+
+ cache: function() {
+ return _oscCache;
+ }
+
+ };
+
+ var hashes = createCommonjsModule(function (module, exports) {
+ /**
+ * jshashes - https://github.com/h2non/jshashes
+ * Released under the "New BSD" license
+ *
+ * Algorithms specification:
+ *
+ * MD5 - http://www.ietf.org/rfc/rfc1321.txt
+ * RIPEMD-160 - http://homes.esat.kuleuven.be/~bosselae/ripemd160.html
+ * SHA1 - http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf
+ * SHA256 - http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf
+ * SHA512 - http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf
+ * HMAC - http://www.ietf.org/rfc/rfc2104.txt
+ */
+ (function() {
+ var Hashes;
+
+ function utf8Encode(str) {
+ var x, y, output = '',
+ i = -1,
+ l;
+
+ if (str && str.length) {
+ l = str.length;
+ while ((i += 1) < l) {
+ /* Decode utf-16 surrogate pairs */
+ x = str.charCodeAt(i);
+ y = i + 1 < l ? str.charCodeAt(i + 1) : 0;
+ if (0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) {
+ x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
+ i += 1;
+ }
+ /* Encode output as utf-8 */
+ if (x <= 0x7F) {
+ output += String.fromCharCode(x);
+ } else if (x <= 0x7FF) {
+ output += String.fromCharCode(0xC0 | ((x >>> 6) & 0x1F),
+ 0x80 | (x & 0x3F));
+ } else if (x <= 0xFFFF) {
+ output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),
+ 0x80 | ((x >>> 6) & 0x3F),
+ 0x80 | (x & 0x3F));
+ } else if (x <= 0x1FFFFF) {
+ output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),
+ 0x80 | ((x >>> 12) & 0x3F),
+ 0x80 | ((x >>> 6) & 0x3F),
+ 0x80 | (x & 0x3F));
+ }
+ }
+ }
+ return output;
+ }
+
+ function utf8Decode(str) {
+ var i, ac, c1, c2, c3, arr = [],
+ l;
+ i = ac = c1 = c2 = c3 = 0;
+
+ if (str && str.length) {
+ l = str.length;
+ str += '';
+
+ while (i < l) {
+ c1 = str.charCodeAt(i);
+ ac += 1;
+ if (c1 < 128) {
+ arr[ac] = String.fromCharCode(c1);
+ i += 1;
+ } else if (c1 > 191 && c1 < 224) {
+ c2 = str.charCodeAt(i + 1);
+ arr[ac] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
+ i += 2;
+ } else {
+ c2 = str.charCodeAt(i + 1);
+ c3 = str.charCodeAt(i + 2);
+ arr[ac] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
+ i += 3;
+ }
+ }
+ }
+ return arr.join('');
+ }
+
+ /**
+ * Add integers, wrapping at 2^32. This uses 16-bit operations internally
+ * to work around bugs in some JS interpreters.
+ */
+
+ function safe_add(x, y) {
+ var lsw = (x & 0xFFFF) + (y & 0xFFFF),
+ msw = (x >> 16) + (y >> 16) + (lsw >> 16);
+ return (msw << 16) | (lsw & 0xFFFF);
+ }
+
+ /**
+ * Bitwise rotate a 32-bit number to the left.
+ */
+
+ function bit_rol(num, cnt) {
+ return (num << cnt) | (num >>> (32 - cnt));
+ }
+
+ /**
+ * Convert a raw string to a hex string
+ */
+
+ function rstr2hex(input, hexcase) {
+ var hex_tab = hexcase ? '0123456789ABCDEF' : '0123456789abcdef',
+ output = '',
+ x, i = 0,
+ l = input.length;
+ for (; i < l; i += 1) {
+ x = input.charCodeAt(i);
+ output += hex_tab.charAt((x >>> 4) & 0x0F) + hex_tab.charAt(x & 0x0F);
+ }
+ return output;
+ }
+
+ /**
+ * Convert an array of big-endian words to a string
+ */
+
+ function binb2rstr(input) {
+ var i, l = input.length * 32,
+ output = '';
+ for (i = 0; i < l; i += 8) {
+ output += String.fromCharCode((input[i >> 5] >>> (24 - i % 32)) & 0xFF);
+ }
+ return output;
+ }
+
+ /**
+ * Convert an array of little-endian words to a string
+ */
+
+ function binl2rstr(input) {
+ var i, l = input.length * 32,
+ output = '';
+ for (i = 0; i < l; i += 8) {
+ output += String.fromCharCode((input[i >> 5] >>> (i % 32)) & 0xFF);
+ }
+ return output;
+ }
+
+ /**
+ * Convert a raw string to an array of little-endian words
+ * Characters >255 have their high-byte silently ignored.
+ */
+
+ function rstr2binl(input) {
+ var i, l = input.length * 8,
+ output = Array(input.length >> 2),
+ lo = output.length;
+ for (i = 0; i < lo; i += 1) {
+ output[i] = 0;
+ }
+ for (i = 0; i < l; i += 8) {
+ output[i >> 5] |= (input.charCodeAt(i / 8) & 0xFF) << (i % 32);
+ }
+ return output;
+ }
+
+ /**
+ * Convert a raw string to an array of big-endian words
+ * Characters >255 have their high-byte silently ignored.
+ */
+
+ function rstr2binb(input) {
+ var i, l = input.length * 8,
+ output = Array(input.length >> 2),
+ lo = output.length;
+ for (i = 0; i < lo; i += 1) {
+ output[i] = 0;
+ }
+ for (i = 0; i < l; i += 8) {
+ output[i >> 5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);
+ }
+ return output;
+ }
+
+ /**
+ * Convert a raw string to an arbitrary string encoding
+ */
+
+ function rstr2any(input, encoding) {
+ var divisor = encoding.length,
+ remainders = Array(),
+ i, q, x, ld, quotient, dividend, output, full_length;
+
+ /* Convert to an array of 16-bit big-endian values, forming the dividend */
+ dividend = Array(Math.ceil(input.length / 2));
+ ld = dividend.length;
+ for (i = 0; i < ld; i += 1) {
+ dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
+ }
+
+ /**
+ * Repeatedly perform a long division. The binary array forms the dividend,
+ * the length of the encoding is the divisor. Once computed, the quotient
+ * forms the dividend for the next step. We stop when the dividend is zerHashes.
+ * All remainders are stored for later use.
+ */
+ while (dividend.length > 0) {
+ quotient = Array();
+ x = 0;
+ for (i = 0; i < dividend.length; i += 1) {
+ x = (x << 16) + dividend[i];
+ q = Math.floor(x / divisor);
+ x -= q * divisor;
+ if (quotient.length > 0 || q > 0) {
+ quotient[quotient.length] = q;
+ }
+ }
+ remainders[remainders.length] = x;
+ dividend = quotient;
+ }
+
+ /* Convert the remainders to the output string */
+ output = '';
+ for (i = remainders.length - 1; i >= 0; i--) {
+ output += encoding.charAt(remainders[i]);
+ }
+
+ /* Append leading zero equivalents */
+ full_length = Math.ceil(input.length * 8 / (Math.log(encoding.length) / Math.log(2)));
+ for (i = output.length; i < full_length; i += 1) {
+ output = encoding[0] + output;
+ }
+ return output;
+ }
+
+ /**
+ * Convert a raw string to a base-64 string
+ */
+
+ function rstr2b64(input, b64pad) {
+ var tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
+ output = '',
+ len = input.length,
+ i, j, triplet;
+ b64pad = b64pad || '=';
+ for (i = 0; i < len; i += 3) {
+ triplet = (input.charCodeAt(i) << 16) | (i + 1 < len ? input.charCodeAt(i + 1) << 8 : 0) | (i + 2 < len ? input.charCodeAt(i + 2) : 0);
+ for (j = 0; j < 4; j += 1) {
+ if (i * 8 + j * 6 > input.length * 8) {
+ output += b64pad;
+ } else {
+ output += tab.charAt((triplet >>> 6 * (3 - j)) & 0x3F);
+ }
+ }
+ }
+ return output;
+ }
+
+ Hashes = {
+ /**
+ * @property {String} version
+ * @readonly
+ */
+ VERSION: '1.0.6',
+ /**
+ * @member Hashes
+ * @class Base64
+ * @constructor
+ */
+ Base64: function() {
+ // private properties
+ var tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
+ pad = '=', // default pad according with the RFC standard
+ utf8 = true; // by default enable UTF-8 support encoding
+
+ // public method for encoding
+ this.encode = function(input) {
+ var i, j, triplet,
+ output = '',
+ len = input.length;
+
+ pad = pad || '=';
+ input = (utf8) ? utf8Encode(input) : input;
+
+ for (i = 0; i < len; i += 3) {
+ triplet = (input.charCodeAt(i) << 16) | (i + 1 < len ? input.charCodeAt(i + 1) << 8 : 0) | (i + 2 < len ? input.charCodeAt(i + 2) : 0);
+ for (j = 0; j < 4; j += 1) {
+ if (i * 8 + j * 6 > len * 8) {
+ output += pad;
+ } else {
+ output += tab.charAt((triplet >>> 6 * (3 - j)) & 0x3F);
+ }
+ }
+ }
+ return output;
+ };
+
+ // public method for decoding
+ this.decode = function(input) {
+ // var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
+ var i, o1, o2, o3, h1, h2, h3, h4, bits, ac,
+ dec = '',
+ arr = [];
+ if (!input) {
+ return input;
+ }
+
+ i = ac = 0;
+ input = input.replace(new RegExp('\\' + pad, 'gi'), ''); // use '='
+ //input += '';
+
+ do { // unpack four hexets into three octets using index points in b64
+ h1 = tab.indexOf(input.charAt(i += 1));
+ h2 = tab.indexOf(input.charAt(i += 1));
+ h3 = tab.indexOf(input.charAt(i += 1));
+ h4 = tab.indexOf(input.charAt(i += 1));
+
+ bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
+
+ o1 = bits >> 16 & 0xff;
+ o2 = bits >> 8 & 0xff;
+ o3 = bits & 0xff;
+ ac += 1;
+
+ if (h3 === 64) {
+ arr[ac] = String.fromCharCode(o1);
+ } else if (h4 === 64) {
+ arr[ac] = String.fromCharCode(o1, o2);
+ } else {
+ arr[ac] = String.fromCharCode(o1, o2, o3);
+ }
+ } while (i < input.length);
+
+ dec = arr.join('');
+ dec = (utf8) ? utf8Decode(dec) : dec;
+
+ return dec;
+ };
+
+ // set custom pad string
+ this.setPad = function(str) {
+ pad = str || pad;
+ return this;
+ };
+ // set custom tab string characters
+ this.setTab = function(str) {
+ tab = str || tab;
+ return this;
+ };
+ this.setUTF8 = function(bool) {
+ if (typeof bool === 'boolean') {
+ utf8 = bool;
+ }
+ return this;
+ };
+ },
+
+ /**
+ * CRC-32 calculation
+ * @member Hashes
+ * @method CRC32
+ * @static
+ * @param {String} str Input String
+ * @return {String}
+ */
+ CRC32: function(str) {
+ var crc = 0,
+ x = 0,
+ y = 0,
+ table, i, iTop;
+ str = utf8Encode(str);
+
+ table = [
+ '00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 ',
+ '79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 ',
+ '84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F ',
+ '63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD ',
+ 'A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC ',
+ '51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 ',
+ 'B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 ',
+ '06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 ',
+ 'E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 ',
+ '12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 ',
+ 'D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 ',
+ '33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 ',
+ 'CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 ',
+ '9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E ',
+ '7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D ',
+ '806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 ',
+ '60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA ',
+ 'AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 ',
+ '5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 ',
+ 'B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 ',
+ '05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 ',
+ 'F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA ',
+ '11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 ',
+ 'D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F ',
+ '30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E ',
+ 'C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D'
+ ].join('');
+
+ crc = crc ^ (-1);
+ for (i = 0, iTop = str.length; i < iTop; i += 1) {
+ y = (crc ^ str.charCodeAt(i)) & 0xFF;
+ x = '0x' + table.substr(y * 9, 8);
+ crc = (crc >>> 8) ^ x;
+ }
+ // always return a positive number (that's what >>> 0 does)
+ return (crc ^ (-1)) >>> 0;
+ },
+ /**
+ * @member Hashes
+ * @class MD5
+ * @constructor
+ * @param {Object} [config]
+ *
+ * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
+ * Digest Algorithm, as defined in RFC 1321.
+ * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
+ * See for more infHashes.
+ */
+ MD5: function(options) {
+ /**
+ * Private config properties. You may need to tweak these to be compatible with
+ * the server-side, but the defaults work in most cases.
+ * See {@link Hashes.MD5#method-setUpperCase} and {@link Hashes.SHA1#method-setUpperCase}
+ */
+ var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false, // hexadecimal output case format. false - lowercase; true - uppercase
+ b64pad = (options && typeof options.pad === 'string') ? options.pad : '=', // base-64 pad character. Defaults to '=' for strict RFC compliance
+ utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true; // enable/disable utf8 encoding
+
+ // privileged (public) methods
+ this.hex = function(s) {
+ return rstr2hex(rstr(s), hexcase);
+ };
+ this.b64 = function(s) {
+ return rstr2b64(rstr(s), b64pad);
+ };
+ this.any = function(s, e) {
+ return rstr2any(rstr(s), e);
+ };
+ this.raw = function(s) {
+ return rstr(s);
+ };
+ this.hex_hmac = function(k, d) {
+ return rstr2hex(rstr_hmac(k, d), hexcase);
+ };
+ this.b64_hmac = function(k, d) {
+ return rstr2b64(rstr_hmac(k, d), b64pad);
+ };
+ this.any_hmac = function(k, d, e) {
+ return rstr2any(rstr_hmac(k, d), e);
+ };
+ /**
+ * Perform a simple self-test to see if the VM is working
+ * @return {String} Hexadecimal hash sample
+ */
+ this.vm_test = function() {
+ return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
+ };
+ /**
+ * Enable/disable uppercase hexadecimal returned string
+ * @param {Boolean}
+ * @return {Object} this
+ */
+ this.setUpperCase = function(a) {
+ if (typeof a === 'boolean') {
+ hexcase = a;
+ }
+ return this;
+ };
+ /**
+ * Defines a base64 pad string
+ * @param {String} Pad
+ * @return {Object} this
+ */
+ this.setPad = function(a) {
+ b64pad = a || b64pad;
+ return this;
+ };
+ /**
+ * Defines a base64 pad string
+ * @param {Boolean}
+ * @return {Object} [this]
+ */
+ this.setUTF8 = function(a) {
+ if (typeof a === 'boolean') {
+ utf8 = a;
+ }
+ return this;
+ };
+
+ // private methods
+
+ /**
+ * Calculate the MD5 of a raw string
+ */
+
+ function rstr(s) {
+ s = (utf8) ? utf8Encode(s) : s;
+ return binl2rstr(binl(rstr2binl(s), s.length * 8));
+ }
+
+ /**
+ * Calculate the HMAC-MD5, of a key and some data (raw strings)
+ */
+
+ function rstr_hmac(key, data) {
+ var bkey, ipad, opad, hash, i;
+
+ key = (utf8) ? utf8Encode(key) : key;
+ data = (utf8) ? utf8Encode(data) : data;
+ bkey = rstr2binl(key);
+ if (bkey.length > 16) {
+ bkey = binl(bkey, key.length * 8);
+ }
+
+ ipad = Array(16), opad = Array(16);
+ for (i = 0; i < 16; i += 1) {
+ ipad[i] = bkey[i] ^ 0x36363636;
+ opad[i] = bkey[i] ^ 0x5C5C5C5C;
+ }
+ hash = binl(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
+ return binl2rstr(binl(opad.concat(hash), 512 + 128));
+ }
+
+ /**
+ * Calculate the MD5 of an array of little-endian words, and a bit length.
+ */
+
+ function binl(x, len) {
+ var i, olda, oldb, oldc, oldd,
+ a = 1732584193,
+ b = -271733879,
+ c = -1732584194,
+ d = 271733878;
+
+ /* append padding */
+ x[len >> 5] |= 0x80 << ((len) % 32);
+ x[(((len + 64) >>> 9) << 4) + 14] = len;
+
+ for (i = 0; i < x.length; i += 16) {
+ olda = a;
+ oldb = b;
+ oldc = c;
+ oldd = d;
+
+ a = md5_ff(a, b, c, d, x[i + 0], 7, -680876936);
+ d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586);
+ c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819);
+ b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330);
+ a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897);
+ d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);
+ c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341);
+ b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983);
+ a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);
+ d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417);
+ c = md5_ff(c, d, a, b, x[i + 10], 17, -42063);
+ b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162);
+ a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);
+ d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101);
+ c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290);
+ b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);
+
+ a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510);
+ d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632);
+ c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713);
+ b = md5_gg(b, c, d, a, x[i + 0], 20, -373897302);
+ a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691);
+ d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083);
+ c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335);
+ b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848);
+ a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438);
+ d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690);
+ c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961);
+ b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);
+ a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467);
+ d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784);
+ c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);
+ b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734);
+
+ a = md5_hh(a, b, c, d, x[i + 5], 4, -378558);
+ d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463);
+ c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);
+ b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556);
+ a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060);
+ d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);
+ c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632);
+ b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640);
+ a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174);
+ d = md5_hh(d, a, b, c, x[i + 0], 11, -358537222);
+ c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979);
+ b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189);
+ a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487);
+ d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835);
+ c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520);
+ b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651);
+
+ a = md5_ii(a, b, c, d, x[i + 0], 6, -198630844);
+ d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);
+ c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905);
+ b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055);
+ a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);
+ d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606);
+ c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523);
+ b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799);
+ a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);
+ d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744);
+ c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380);
+ b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);
+ a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070);
+ d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379);
+ c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259);
+ b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551);
+
+ a = safe_add(a, olda);
+ b = safe_add(b, oldb);
+ c = safe_add(c, oldc);
+ d = safe_add(d, oldd);
+ }
+ return Array(a, b, c, d);
+ }
+
+ /**
+ * These functions implement the four basic operations the algorithm uses.
+ */
+
+ function md5_cmn(q, a, b, x, s, t) {
+ return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b);
+ }
+
+ function md5_ff(a, b, c, d, x, s, t) {
+ return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
+ }
+
+ function md5_gg(a, b, c, d, x, s, t) {
+ return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
+ }
+
+ function md5_hh(a, b, c, d, x, s, t) {
+ return md5_cmn(b ^ c ^ d, a, b, x, s, t);
+ }
+
+ function md5_ii(a, b, c, d, x, s, t) {
+ return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
+ }
+ },
+ /**
+ * @member Hashes
+ * @class Hashes.SHA1
+ * @param {Object} [config]
+ * @constructor
+ *
+ * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined in FIPS 180-1
+ * Version 2.2 Copyright Paul Johnston 2000 - 2009.
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
+ * See http://pajhome.org.uk/crypt/md5 for details.
+ */
+ SHA1: function(options) {
+ /**
+ * Private config properties. You may need to tweak these to be compatible with
+ * the server-side, but the defaults work in most cases.
+ * See {@link Hashes.MD5#method-setUpperCase} and {@link Hashes.SHA1#method-setUpperCase}
+ */
+ var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false, // hexadecimal output case format. false - lowercase; true - uppercase
+ b64pad = (options && typeof options.pad === 'string') ? options.pad : '=', // base-64 pad character. Defaults to '=' for strict RFC compliance
+ utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true; // enable/disable utf8 encoding
+
+ // public methods
+ this.hex = function(s) {
+ return rstr2hex(rstr(s), hexcase);
+ };
+ this.b64 = function(s) {
+ return rstr2b64(rstr(s), b64pad);
+ };
+ this.any = function(s, e) {
+ return rstr2any(rstr(s), e);
+ };
+ this.raw = function(s) {
+ return rstr(s);
+ };
+ this.hex_hmac = function(k, d) {
+ return rstr2hex(rstr_hmac(k, d));
+ };
+ this.b64_hmac = function(k, d) {
+ return rstr2b64(rstr_hmac(k, d), b64pad);
+ };
+ this.any_hmac = function(k, d, e) {
+ return rstr2any(rstr_hmac(k, d), e);
+ };
+ /**
+ * Perform a simple self-test to see if the VM is working
+ * @return {String} Hexadecimal hash sample
+ * @public
+ */
+ this.vm_test = function() {
+ return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
+ };
+ /**
+ * @description Enable/disable uppercase hexadecimal returned string
+ * @param {boolean}
+ * @return {Object} this
+ * @public
+ */
+ this.setUpperCase = function(a) {
+ if (typeof a === 'boolean') {
+ hexcase = a;
+ }
+ return this;
+ };
+ /**
+ * @description Defines a base64 pad string
+ * @param {string} Pad
+ * @return {Object} this
+ * @public
+ */
+ this.setPad = function(a) {
+ b64pad = a || b64pad;
+ return this;
+ };
+ /**
+ * @description Defines a base64 pad string
+ * @param {boolean}
+ * @return {Object} this
+ * @public
+ */
+ this.setUTF8 = function(a) {
+ if (typeof a === 'boolean') {
+ utf8 = a;
+ }
+ return this;
+ };
+
+ // private methods
+
+ /**
+ * Calculate the SHA-512 of a raw string
+ */
+
+ function rstr(s) {
+ s = (utf8) ? utf8Encode(s) : s;
+ return binb2rstr(binb(rstr2binb(s), s.length * 8));
+ }
+
+ /**
+ * Calculate the HMAC-SHA1 of a key and some data (raw strings)
+ */
+
+ function rstr_hmac(key, data) {
+ var bkey, ipad, opad, i, hash;
+ key = (utf8) ? utf8Encode(key) : key;
+ data = (utf8) ? utf8Encode(data) : data;
+ bkey = rstr2binb(key);
+
+ if (bkey.length > 16) {
+ bkey = binb(bkey, key.length * 8);
+ }
+ ipad = Array(16), opad = Array(16);
+ for (i = 0; i < 16; i += 1) {
+ ipad[i] = bkey[i] ^ 0x36363636;
+ opad[i] = bkey[i] ^ 0x5C5C5C5C;
+ }
+ hash = binb(ipad.concat(rstr2binb(data)), 512 + data.length * 8);
+ return binb2rstr(binb(opad.concat(hash), 512 + 160));
+ }
+
+ /**
+ * Calculate the SHA-1 of an array of big-endian words, and a bit length
+ */
+
+ function binb(x, len) {
+ var i, j, t, olda, oldb, oldc, oldd, olde,
+ w = Array(80),
+ a = 1732584193,
+ b = -271733879,
+ c = -1732584194,
+ d = 271733878,
+ e = -1009589776;
+
+ /* append padding */
+ x[len >> 5] |= 0x80 << (24 - len % 32);
+ x[((len + 64 >> 9) << 4) + 15] = len;
+
+ for (i = 0; i < x.length; i += 16) {
+ olda = a;
+ oldb = b;
+ oldc = c;
+ oldd = d;
+ olde = e;
+
+ for (j = 0; j < 80; j += 1) {
+ if (j < 16) {
+ w[j] = x[i + j];
+ } else {
+ w[j] = bit_rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1);
+ }
+ t = safe_add(safe_add(bit_rol(a, 5), sha1_ft(j, b, c, d)),
+ safe_add(safe_add(e, w[j]), sha1_kt(j)));
+ e = d;
+ d = c;
+ c = bit_rol(b, 30);
+ b = a;
+ a = t;
+ }
+
+ a = safe_add(a, olda);
+ b = safe_add(b, oldb);
+ c = safe_add(c, oldc);
+ d = safe_add(d, oldd);
+ e = safe_add(e, olde);
+ }
+ return Array(a, b, c, d, e);
+ }
+
+ /**
+ * Perform the appropriate triplet combination function for the current
+ * iteration
+ */
+
+ function sha1_ft(t, b, c, d) {
+ if (t < 20) {
+ return (b & c) | ((~b) & d);
+ }
+ if (t < 40) {
+ return b ^ c ^ d;
+ }
+ if (t < 60) {
+ return (b & c) | (b & d) | (c & d);
+ }
+ return b ^ c ^ d;
+ }
+
+ /**
+ * Determine the appropriate additive constant for the current iteration
+ */
+
+ function sha1_kt(t) {
+ return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
+ (t < 60) ? -1894007588 : -899497514;
+ }
+ },
+ /**
+ * @class Hashes.SHA256
+ * @param {config}
+ *
+ * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined in FIPS 180-2
+ * Version 2.2 Copyright Angel Marin, Paul Johnston 2000 - 2009.
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
+ * See http://pajhome.org.uk/crypt/md5 for details.
+ * Also http://anmar.eu.org/projects/jssha2/
+ */
+ SHA256: function(options) {
+ /**
+ * Private properties configuration variables. You may need to tweak these to be compatible with
+ * the server-side, but the defaults work in most cases.
+ * @see this.setUpperCase() method
+ * @see this.setPad() method
+ */
+ var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false, // hexadecimal output case format. false - lowercase; true - uppercase */
+ b64pad = (options && typeof options.pad === 'string') ? options.pad : '=',
+ /* base-64 pad character. Default '=' for strict RFC compliance */
+ utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true,
+ /* enable/disable utf8 encoding */
+ sha256_K;
+
+ /* privileged (public) methods */
+ this.hex = function(s) {
+ return rstr2hex(rstr(s, utf8));
+ };
+ this.b64 = function(s) {
+ return rstr2b64(rstr(s, utf8), b64pad);
+ };
+ this.any = function(s, e) {
+ return rstr2any(rstr(s, utf8), e);
+ };
+ this.raw = function(s) {
+ return rstr(s, utf8);
+ };
+ this.hex_hmac = function(k, d) {
+ return rstr2hex(rstr_hmac(k, d));
+ };
+ this.b64_hmac = function(k, d) {
+ return rstr2b64(rstr_hmac(k, d), b64pad);
+ };
+ this.any_hmac = function(k, d, e) {
+ return rstr2any(rstr_hmac(k, d), e);
+ };
+ /**
+ * Perform a simple self-test to see if the VM is working
+ * @return {String} Hexadecimal hash sample
+ * @public
+ */
+ this.vm_test = function() {
+ return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
+ };
+ /**
+ * Enable/disable uppercase hexadecimal returned string
+ * @param {boolean}
+ * @return {Object} this
+ * @public
+ */
+ this.setUpperCase = function(a) {
+ if (typeof a === 'boolean') {
+ hexcase = a;
+ }
+ return this;
+ };
+ /**
+ * @description Defines a base64 pad string
+ * @param {string} Pad
+ * @return {Object} this
+ * @public
+ */
+ this.setPad = function(a) {
+ b64pad = a || b64pad;
+ return this;
+ };
+ /**
+ * Defines a base64 pad string
+ * @param {boolean}
+ * @return {Object} this
+ * @public
+ */
+ this.setUTF8 = function(a) {
+ if (typeof a === 'boolean') {
+ utf8 = a;
+ }
+ return this;
+ };
+
+ // private methods
+
+ /**
+ * Calculate the SHA-512 of a raw string
+ */
+
+ function rstr(s, utf8) {
+ s = (utf8) ? utf8Encode(s) : s;
+ return binb2rstr(binb(rstr2binb(s), s.length * 8));
+ }
+
+ /**
+ * Calculate the HMAC-sha256 of a key and some data (raw strings)
+ */
+
+ function rstr_hmac(key, data) {
+ key = (utf8) ? utf8Encode(key) : key;
+ data = (utf8) ? utf8Encode(data) : data;
+ var hash, i = 0,
+ bkey = rstr2binb(key),
+ ipad = Array(16),
+ opad = Array(16);
+
+ if (bkey.length > 16) {
+ bkey = binb(bkey, key.length * 8);
+ }
+
+ for (; i < 16; i += 1) {
+ ipad[i] = bkey[i] ^ 0x36363636;
+ opad[i] = bkey[i] ^ 0x5C5C5C5C;
+ }
+
+ hash = binb(ipad.concat(rstr2binb(data)), 512 + data.length * 8);
+ return binb2rstr(binb(opad.concat(hash), 512 + 256));
+ }
+
+ /*
+ * Main sha256 function, with its support functions
+ */
+
+ function sha256_S(X, n) {
+ return (X >>> n) | (X << (32 - n));
+ }
+
+ function sha256_R(X, n) {
+ return (X >>> n);
+ }
+
+ function sha256_Ch(x, y, z) {
+ return ((x & y) ^ ((~x) & z));
+ }
+
+ function sha256_Maj(x, y, z) {
+ return ((x & y) ^ (x & z) ^ (y & z));
+ }
+
+ function sha256_Sigma0256(x) {
+ return (sha256_S(x, 2) ^ sha256_S(x, 13) ^ sha256_S(x, 22));
+ }
+
+ function sha256_Sigma1256(x) {
+ return (sha256_S(x, 6) ^ sha256_S(x, 11) ^ sha256_S(x, 25));
+ }
+
+ function sha256_Gamma0256(x) {
+ return (sha256_S(x, 7) ^ sha256_S(x, 18) ^ sha256_R(x, 3));
+ }
+
+ function sha256_Gamma1256(x) {
+ return (sha256_S(x, 17) ^ sha256_S(x, 19) ^ sha256_R(x, 10));
+ }
+
+ sha256_K = [
+ 1116352408, 1899447441, -1245643825, -373957723, 961987163, 1508970993, -1841331548, -1424204075, -670586216, 310598401, 607225278, 1426881987,
+ 1925078388, -2132889090, -1680079193, -1046744716, -459576895, -272742522,
+ 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, -1740746414, -1473132947, -1341970488, -1084653625, -958395405, -710438585,
+ 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291,
+ 1695183700, 1986661051, -2117940946, -1838011259, -1564481375, -1474664885, -1035236496, -949202525, -778901479, -694614492, -200395387, 275423344,
+ 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218,
+ 1537002063, 1747873779, 1955562222, 2024104815, -2067236844, -1933114872, -1866530822, -1538233109, -1090935817, -965641998
+ ];
+
+ function binb(m, l) {
+ var HASH = [1779033703, -1150833019, 1013904242, -1521486534,
+ 1359893119, -1694144372, 528734635, 1541459225
+ ];
+ var W = new Array(64);
+ var a, b, c, d, e, f, g, h;
+ var i, j, T1, T2;
+
+ /* append padding */
+ m[l >> 5] |= 0x80 << (24 - l % 32);
+ m[((l + 64 >> 9) << 4) + 15] = l;
+
+ for (i = 0; i < m.length; i += 16) {
+ a = HASH[0];
+ b = HASH[1];
+ c = HASH[2];
+ d = HASH[3];
+ e = HASH[4];
+ f = HASH[5];
+ g = HASH[6];
+ h = HASH[7];
+
+ for (j = 0; j < 64; j += 1) {
+ if (j < 16) {
+ W[j] = m[j + i];
+ } else {
+ W[j] = safe_add(safe_add(safe_add(sha256_Gamma1256(W[j - 2]), W[j - 7]),
+ sha256_Gamma0256(W[j - 15])), W[j - 16]);
+ }
+
+ T1 = safe_add(safe_add(safe_add(safe_add(h, sha256_Sigma1256(e)), sha256_Ch(e, f, g)),
+ sha256_K[j]), W[j]);
+ T2 = safe_add(sha256_Sigma0256(a), sha256_Maj(a, b, c));
+ h = g;
+ g = f;
+ f = e;
+ e = safe_add(d, T1);
+ d = c;
+ c = b;
+ b = a;
+ a = safe_add(T1, T2);
+ }
+
+ HASH[0] = safe_add(a, HASH[0]);
+ HASH[1] = safe_add(b, HASH[1]);
+ HASH[2] = safe_add(c, HASH[2]);
+ HASH[3] = safe_add(d, HASH[3]);
+ HASH[4] = safe_add(e, HASH[4]);
+ HASH[5] = safe_add(f, HASH[5]);
+ HASH[6] = safe_add(g, HASH[6]);
+ HASH[7] = safe_add(h, HASH[7]);
+ }
+ return HASH;
+ }
+
+ },
+
+ /**
+ * @class Hashes.SHA512
+ * @param {config}
+ *
+ * A JavaScript implementation of the Secure Hash Algorithm, SHA-512, as defined in FIPS 180-2
+ * Version 2.2 Copyright Anonymous Contributor, Paul Johnston 2000 - 2009.
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
+ * See http://pajhome.org.uk/crypt/md5 for details.
+ */
+ SHA512: function(options) {
+ /**
+ * Private properties configuration variables. You may need to tweak these to be compatible with
+ * the server-side, but the defaults work in most cases.
+ * @see this.setUpperCase() method
+ * @see this.setPad() method
+ */
+ var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false,
+ /* hexadecimal output case format. false - lowercase; true - uppercase */
+ b64pad = (options && typeof options.pad === 'string') ? options.pad : '=',
+ /* base-64 pad character. Default '=' for strict RFC compliance */
+ utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true,
+ /* enable/disable utf8 encoding */
+ sha512_k;
+
+ /* privileged (public) methods */
+ this.hex = function(s) {
+ return rstr2hex(rstr(s));
+ };
+ this.b64 = function(s) {
+ return rstr2b64(rstr(s), b64pad);
+ };
+ this.any = function(s, e) {
+ return rstr2any(rstr(s), e);
+ };
+ this.raw = function(s) {
+ return rstr(s);
+ };
+ this.hex_hmac = function(k, d) {
+ return rstr2hex(rstr_hmac(k, d));
+ };
+ this.b64_hmac = function(k, d) {
+ return rstr2b64(rstr_hmac(k, d), b64pad);
+ };
+ this.any_hmac = function(k, d, e) {
+ return rstr2any(rstr_hmac(k, d), e);
+ };
+ /**
+ * Perform a simple self-test to see if the VM is working
+ * @return {String} Hexadecimal hash sample
+ * @public
+ */
+ this.vm_test = function() {
+ return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
+ };
+ /**
+ * @description Enable/disable uppercase hexadecimal returned string
+ * @param {boolean}
+ * @return {Object} this
+ * @public
+ */
+ this.setUpperCase = function(a) {
+ if (typeof a === 'boolean') {
+ hexcase = a;
+ }
+ return this;
+ };
+ /**
+ * @description Defines a base64 pad string
+ * @param {string} Pad
+ * @return {Object} this
+ * @public
+ */
+ this.setPad = function(a) {
+ b64pad = a || b64pad;
+ return this;
+ };
+ /**
+ * @description Defines a base64 pad string
+ * @param {boolean}
+ * @return {Object} this
+ * @public
+ */
+ this.setUTF8 = function(a) {
+ if (typeof a === 'boolean') {
+ utf8 = a;
+ }
+ return this;
+ };
+
+ /* private methods */
+
+ /**
+ * Calculate the SHA-512 of a raw string
+ */
+
+ function rstr(s) {
+ s = (utf8) ? utf8Encode(s) : s;
+ return binb2rstr(binb(rstr2binb(s), s.length * 8));
+ }
+ /*
+ * Calculate the HMAC-SHA-512 of a key and some data (raw strings)
+ */
+
+ function rstr_hmac(key, data) {
+ key = (utf8) ? utf8Encode(key) : key;
+ data = (utf8) ? utf8Encode(data) : data;
+
+ var hash, i = 0,
+ bkey = rstr2binb(key),
+ ipad = Array(32),
+ opad = Array(32);
+
+ if (bkey.length > 32) {
+ bkey = binb(bkey, key.length * 8);
+ }
+
+ for (; i < 32; i += 1) {
+ ipad[i] = bkey[i] ^ 0x36363636;
+ opad[i] = bkey[i] ^ 0x5C5C5C5C;
+ }
+
+ hash = binb(ipad.concat(rstr2binb(data)), 1024 + data.length * 8);
+ return binb2rstr(binb(opad.concat(hash), 1024 + 512));
+ }
+
+ /**
+ * Calculate the SHA-512 of an array of big-endian dwords, and a bit length
+ */
+
+ function binb(x, len) {
+ var j, i, l,
+ W = new Array(80),
+ hash = new Array(16),
+ //Initial hash values
+ H = [
+ new int64(0x6a09e667, -205731576),
+ new int64(-1150833019, -2067093701),
+ new int64(0x3c6ef372, -23791573),
+ new int64(-1521486534, 0x5f1d36f1),
+ new int64(0x510e527f, -1377402159),
+ new int64(-1694144372, 0x2b3e6c1f),
+ new int64(0x1f83d9ab, -79577749),
+ new int64(0x5be0cd19, 0x137e2179)
+ ],
+ T1 = new int64(0, 0),
+ T2 = new int64(0, 0),
+ a = new int64(0, 0),
+ b = new int64(0, 0),
+ c = new int64(0, 0),
+ d = new int64(0, 0),
+ e = new int64(0, 0),
+ f = new int64(0, 0),
+ g = new int64(0, 0),
+ h = new int64(0, 0),
+ //Temporary variables not specified by the document
+ s0 = new int64(0, 0),
+ s1 = new int64(0, 0),
+ Ch = new int64(0, 0),
+ Maj = new int64(0, 0),
+ r1 = new int64(0, 0),
+ r2 = new int64(0, 0),
+ r3 = new int64(0, 0);
+
+ if (sha512_k === undefined) {
+ //SHA512 constants
+ sha512_k = [
+ new int64(0x428a2f98, -685199838), new int64(0x71374491, 0x23ef65cd),
+ new int64(-1245643825, -330482897), new int64(-373957723, -2121671748),
+ new int64(0x3956c25b, -213338824), new int64(0x59f111f1, -1241133031),
+ new int64(-1841331548, -1357295717), new int64(-1424204075, -630357736),
+ new int64(-670586216, -1560083902), new int64(0x12835b01, 0x45706fbe),
+ new int64(0x243185be, 0x4ee4b28c), new int64(0x550c7dc3, -704662302),
+ new int64(0x72be5d74, -226784913), new int64(-2132889090, 0x3b1696b1),
+ new int64(-1680079193, 0x25c71235), new int64(-1046744716, -815192428),
+ new int64(-459576895, -1628353838), new int64(-272742522, 0x384f25e3),
+ new int64(0xfc19dc6, -1953704523), new int64(0x240ca1cc, 0x77ac9c65),
+ new int64(0x2de92c6f, 0x592b0275), new int64(0x4a7484aa, 0x6ea6e483),
+ new int64(0x5cb0a9dc, -1119749164), new int64(0x76f988da, -2096016459),
+ new int64(-1740746414, -295247957), new int64(-1473132947, 0x2db43210),
+ new int64(-1341970488, -1728372417), new int64(-1084653625, -1091629340),
+ new int64(-958395405, 0x3da88fc2), new int64(-710438585, -1828018395),
+ new int64(0x6ca6351, -536640913), new int64(0x14292967, 0xa0e6e70),
+ new int64(0x27b70a85, 0x46d22ffc), new int64(0x2e1b2138, 0x5c26c926),
+ new int64(0x4d2c6dfc, 0x5ac42aed), new int64(0x53380d13, -1651133473),
+ new int64(0x650a7354, -1951439906), new int64(0x766a0abb, 0x3c77b2a8),
+ new int64(-2117940946, 0x47edaee6), new int64(-1838011259, 0x1482353b),
+ new int64(-1564481375, 0x4cf10364), new int64(-1474664885, -1136513023),
+ new int64(-1035236496, -789014639), new int64(-949202525, 0x654be30),
+ new int64(-778901479, -688958952), new int64(-694614492, 0x5565a910),
+ new int64(-200395387, 0x5771202a), new int64(0x106aa070, 0x32bbd1b8),
+ new int64(0x19a4c116, -1194143544), new int64(0x1e376c08, 0x5141ab53),
+ new int64(0x2748774c, -544281703), new int64(0x34b0bcb5, -509917016),
+ new int64(0x391c0cb3, -976659869), new int64(0x4ed8aa4a, -482243893),
+ new int64(0x5b9cca4f, 0x7763e373), new int64(0x682e6ff3, -692930397),
+ new int64(0x748f82ee, 0x5defb2fc), new int64(0x78a5636f, 0x43172f60),
+ new int64(-2067236844, -1578062990), new int64(-1933114872, 0x1a6439ec),
+ new int64(-1866530822, 0x23631e28), new int64(-1538233109, -561857047),
+ new int64(-1090935817, -1295615723), new int64(-965641998, -479046869),
+ new int64(-903397682, -366583396), new int64(-779700025, 0x21c0c207),
+ new int64(-354779690, -840897762), new int64(-176337025, -294727304),
+ new int64(0x6f067aa, 0x72176fba), new int64(0xa637dc5, -1563912026),
+ new int64(0x113f9804, -1090974290), new int64(0x1b710b35, 0x131c471b),
+ new int64(0x28db77f5, 0x23047d84), new int64(0x32caab7b, 0x40c72493),
+ new int64(0x3c9ebe0a, 0x15c9bebc), new int64(0x431d67c4, -1676669620),
+ new int64(0x4cc5d4be, -885112138), new int64(0x597f299c, -60457430),
+ new int64(0x5fcb6fab, 0x3ad6faec), new int64(0x6c44198c, 0x4a475817)
+ ];
+ }
+
+ for (i = 0; i < 80; i += 1) {
+ W[i] = new int64(0, 0);
+ }
+
+ // append padding to the source string. The format is described in the FIPS.
+ x[len >> 5] |= 0x80 << (24 - (len & 0x1f));
+ x[((len + 128 >> 10) << 5) + 31] = len;
+ l = x.length;
+ for (i = 0; i < l; i += 32) { //32 dwords is the block size
+ int64copy(a, H[0]);
+ int64copy(b, H[1]);
+ int64copy(c, H[2]);
+ int64copy(d, H[3]);
+ int64copy(e, H[4]);
+ int64copy(f, H[5]);
+ int64copy(g, H[6]);
+ int64copy(h, H[7]);
+
+ for (j = 0; j < 16; j += 1) {
+ W[j].h = x[i + 2 * j];
+ W[j].l = x[i + 2 * j + 1];
+ }
+
+ for (j = 16; j < 80; j += 1) {
+ //sigma1
+ int64rrot(r1, W[j - 2], 19);
+ int64revrrot(r2, W[j - 2], 29);
+ int64shr(r3, W[j - 2], 6);
+ s1.l = r1.l ^ r2.l ^ r3.l;
+ s1.h = r1.h ^ r2.h ^ r3.h;
+ //sigma0
+ int64rrot(r1, W[j - 15], 1);
+ int64rrot(r2, W[j - 15], 8);
+ int64shr(r3, W[j - 15], 7);
+ s0.l = r1.l ^ r2.l ^ r3.l;
+ s0.h = r1.h ^ r2.h ^ r3.h;
+
+ int64add4(W[j], s1, W[j - 7], s0, W[j - 16]);
+ }
+
+ for (j = 0; j < 80; j += 1) {
+ //Ch
+ Ch.l = (e.l & f.l) ^ (~e.l & g.l);
+ Ch.h = (e.h & f.h) ^ (~e.h & g.h);
+
+ //Sigma1
+ int64rrot(r1, e, 14);
+ int64rrot(r2, e, 18);
+ int64revrrot(r3, e, 9);
+ s1.l = r1.l ^ r2.l ^ r3.l;
+ s1.h = r1.h ^ r2.h ^ r3.h;
+
+ //Sigma0
+ int64rrot(r1, a, 28);
+ int64revrrot(r2, a, 2);
+ int64revrrot(r3, a, 7);
+ s0.l = r1.l ^ r2.l ^ r3.l;
+ s0.h = r1.h ^ r2.h ^ r3.h;
+
+ //Maj
+ Maj.l = (a.l & b.l) ^ (a.l & c.l) ^ (b.l & c.l);
+ Maj.h = (a.h & b.h) ^ (a.h & c.h) ^ (b.h & c.h);
+
+ int64add5(T1, h, s1, Ch, sha512_k[j], W[j]);
+ int64add(T2, s0, Maj);
+
+ int64copy(h, g);
+ int64copy(g, f);
+ int64copy(f, e);
+ int64add(e, d, T1);
+ int64copy(d, c);
+ int64copy(c, b);
+ int64copy(b, a);
+ int64add(a, T1, T2);
+ }
+ int64add(H[0], H[0], a);
+ int64add(H[1], H[1], b);
+ int64add(H[2], H[2], c);
+ int64add(H[3], H[3], d);
+ int64add(H[4], H[4], e);
+ int64add(H[5], H[5], f);
+ int64add(H[6], H[6], g);
+ int64add(H[7], H[7], h);
+ }
+
+ //represent the hash as an array of 32-bit dwords
+ for (i = 0; i < 8; i += 1) {
+ hash[2 * i] = H[i].h;
+ hash[2 * i + 1] = H[i].l;
+ }
+ return hash;
+ }
+
+ //A constructor for 64-bit numbers
+
+ function int64(h, l) {
+ this.h = h;
+ this.l = l;
+ //this.toString = int64toString;
+ }
+
+ //Copies src into dst, assuming both are 64-bit numbers
+
+ function int64copy(dst, src) {
+ dst.h = src.h;
+ dst.l = src.l;
+ }
+
+ //Right-rotates a 64-bit number by shift
+ //Won't handle cases of shift>=32
+ //The function revrrot() is for that
+
+ function int64rrot(dst, x, shift) {
+ dst.l = (x.l >>> shift) | (x.h << (32 - shift));
+ dst.h = (x.h >>> shift) | (x.l << (32 - shift));
+ }
+
+ //Reverses the dwords of the source and then rotates right by shift.
+ //This is equivalent to rotation by 32+shift
+
+ function int64revrrot(dst, x, shift) {
+ dst.l = (x.h >>> shift) | (x.l << (32 - shift));
+ dst.h = (x.l >>> shift) | (x.h << (32 - shift));
+ }
+
+ //Bitwise-shifts right a 64-bit number by shift
+ //Won't handle shift>=32, but it's never needed in SHA512
+
+ function int64shr(dst, x, shift) {
+ dst.l = (x.l >>> shift) | (x.h << (32 - shift));
+ dst.h = (x.h >>> shift);
+ }
+
+ //Adds two 64-bit numbers
+ //Like the original implementation, does not rely on 32-bit operations
+
+ function int64add(dst, x, y) {
+ var w0 = (x.l & 0xffff) + (y.l & 0xffff);
+ var w1 = (x.l >>> 16) + (y.l >>> 16) + (w0 >>> 16);
+ var w2 = (x.h & 0xffff) + (y.h & 0xffff) + (w1 >>> 16);
+ var w3 = (x.h >>> 16) + (y.h >>> 16) + (w2 >>> 16);
+ dst.l = (w0 & 0xffff) | (w1 << 16);
+ dst.h = (w2 & 0xffff) | (w3 << 16);
+ }
+
+ //Same, except with 4 addends. Works faster than adding them one by one.
+
+ function int64add4(dst, a, b, c, d) {
+ var w0 = (a.l & 0xffff) + (b.l & 0xffff) + (c.l & 0xffff) + (d.l & 0xffff);
+ var w1 = (a.l >>> 16) + (b.l >>> 16) + (c.l >>> 16) + (d.l >>> 16) + (w0 >>> 16);
+ var w2 = (a.h & 0xffff) + (b.h & 0xffff) + (c.h & 0xffff) + (d.h & 0xffff) + (w1 >>> 16);
+ var w3 = (a.h >>> 16) + (b.h >>> 16) + (c.h >>> 16) + (d.h >>> 16) + (w2 >>> 16);
+ dst.l = (w0 & 0xffff) | (w1 << 16);
+ dst.h = (w2 & 0xffff) | (w3 << 16);
+ }
+
+ //Same, except with 5 addends
+
+ function int64add5(dst, a, b, c, d, e) {
+ var w0 = (a.l & 0xffff) + (b.l & 0xffff) + (c.l & 0xffff) + (d.l & 0xffff) + (e.l & 0xffff),
+ w1 = (a.l >>> 16) + (b.l >>> 16) + (c.l >>> 16) + (d.l >>> 16) + (e.l >>> 16) + (w0 >>> 16),
+ w2 = (a.h & 0xffff) + (b.h & 0xffff) + (c.h & 0xffff) + (d.h & 0xffff) + (e.h & 0xffff) + (w1 >>> 16),
+ w3 = (a.h >>> 16) + (b.h >>> 16) + (c.h >>> 16) + (d.h >>> 16) + (e.h >>> 16) + (w2 >>> 16);
+ dst.l = (w0 & 0xffff) | (w1 << 16);
+ dst.h = (w2 & 0xffff) | (w3 << 16);
+ }
+ },
+ /**
+ * @class Hashes.RMD160
+ * @constructor
+ * @param {Object} [config]
+ *
+ * A JavaScript implementation of the RIPEMD-160 Algorithm
+ * Version 2.2 Copyright Jeremy Lin, Paul Johnston 2000 - 2009.
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
+ * See http://pajhome.org.uk/crypt/md5 for details.
+ * Also http://www.ocf.berkeley.edu/~jjlin/jsotp/
+ */
+ RMD160: function(options) {
+ /**
+ * Private properties configuration variables. You may need to tweak these to be compatible with
+ * the server-side, but the defaults work in most cases.
+ * @see this.setUpperCase() method
+ * @see this.setPad() method
+ */
+ var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false,
+ /* hexadecimal output case format. false - lowercase; true - uppercase */
+ b64pad = (options && typeof options.pad === 'string') ? options.pa : '=',
+ /* base-64 pad character. Default '=' for strict RFC compliance */
+ utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true,
+ /* enable/disable utf8 encoding */
+ rmd160_r1 = [
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
+ 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
+ 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
+ 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
+ ],
+ rmd160_r2 = [
+ 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
+ 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
+ 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
+ 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
+ 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
+ ],
+ rmd160_s1 = [
+ 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
+ 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
+ 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
+ 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
+ 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
+ ],
+ rmd160_s2 = [
+ 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
+ 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
+ 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
+ 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
+ 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
+ ];
+
+ /* privileged (public) methods */
+ this.hex = function(s) {
+ return rstr2hex(rstr(s));
+ };
+ this.b64 = function(s) {
+ return rstr2b64(rstr(s), b64pad);
+ };
+ this.any = function(s, e) {
+ return rstr2any(rstr(s), e);
+ };
+ this.raw = function(s) {
+ return rstr(s);
+ };
+ this.hex_hmac = function(k, d) {
+ return rstr2hex(rstr_hmac(k, d));
+ };
+ this.b64_hmac = function(k, d) {
+ return rstr2b64(rstr_hmac(k, d), b64pad);
+ };
+ this.any_hmac = function(k, d, e) {
+ return rstr2any(rstr_hmac(k, d), e);
+ };
+ /**
+ * Perform a simple self-test to see if the VM is working
+ * @return {String} Hexadecimal hash sample
+ * @public
+ */
+ this.vm_test = function() {
+ return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
+ };
+ /**
+ * @description Enable/disable uppercase hexadecimal returned string
+ * @param {boolean}
+ * @return {Object} this
+ * @public
+ */
+ this.setUpperCase = function(a) {
+ if (typeof a === 'boolean') {
+ hexcase = a;
+ }
+ return this;
+ };
+ /**
+ * @description Defines a base64 pad string
+ * @param {string} Pad
+ * @return {Object} this
+ * @public
+ */
+ this.setPad = function(a) {
+ if (typeof a !== 'undefined') {
+ b64pad = a;
+ }
+ return this;
+ };
+ /**
+ * @description Defines a base64 pad string
+ * @param {boolean}
+ * @return {Object} this
+ * @public
+ */
+ this.setUTF8 = function(a) {
+ if (typeof a === 'boolean') {
+ utf8 = a;
+ }
+ return this;
+ };
+
+ /* private methods */
+
+ /**
+ * Calculate the rmd160 of a raw string
+ */
+
+ function rstr(s) {
+ s = (utf8) ? utf8Encode(s) : s;
+ return binl2rstr(binl(rstr2binl(s), s.length * 8));
+ }
+
+ /**
+ * Calculate the HMAC-rmd160 of a key and some data (raw strings)
+ */
+
+ function rstr_hmac(key, data) {
+ key = (utf8) ? utf8Encode(key) : key;
+ data = (utf8) ? utf8Encode(data) : data;
+ var i, hash,
+ bkey = rstr2binl(key),
+ ipad = Array(16),
+ opad = Array(16);
+
+ if (bkey.length > 16) {
+ bkey = binl(bkey, key.length * 8);
+ }
+
+ for (i = 0; i < 16; i += 1) {
+ ipad[i] = bkey[i] ^ 0x36363636;
+ opad[i] = bkey[i] ^ 0x5C5C5C5C;
+ }
+ hash = binl(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
+ return binl2rstr(binl(opad.concat(hash), 512 + 160));
+ }
+
+ /**
+ * Convert an array of little-endian words to a string
+ */
+
+ function binl2rstr(input) {
+ var i, output = '',
+ l = input.length * 32;
+ for (i = 0; i < l; i += 8) {
+ output += String.fromCharCode((input[i >> 5] >>> (i % 32)) & 0xFF);
+ }
+ return output;
+ }
+
+ /**
+ * Calculate the RIPE-MD160 of an array of little-endian words, and a bit length.
+ */
+
+ function binl(x, len) {
+ var T, j, i, l,
+ h0 = 0x67452301,
+ h1 = 0xefcdab89,
+ h2 = 0x98badcfe,
+ h3 = 0x10325476,
+ h4 = 0xc3d2e1f0,
+ A1, B1, C1, D1, E1,
+ A2, B2, C2, D2, E2;
+
+ /* append padding */
+ x[len >> 5] |= 0x80 << (len % 32);
+ x[(((len + 64) >>> 9) << 4) + 14] = len;
+ l = x.length;
+
+ for (i = 0; i < l; i += 16) {
+ A1 = A2 = h0;
+ B1 = B2 = h1;
+ C1 = C2 = h2;
+ D1 = D2 = h3;
+ E1 = E2 = h4;
+ for (j = 0; j <= 79; j += 1) {
+ T = safe_add(A1, rmd160_f(j, B1, C1, D1));
+ T = safe_add(T, x[i + rmd160_r1[j]]);
+ T = safe_add(T, rmd160_K1(j));
+ T = safe_add(bit_rol(T, rmd160_s1[j]), E1);
+ A1 = E1;
+ E1 = D1;
+ D1 = bit_rol(C1, 10);
+ C1 = B1;
+ B1 = T;
+ T = safe_add(A2, rmd160_f(79 - j, B2, C2, D2));
+ T = safe_add(T, x[i + rmd160_r2[j]]);
+ T = safe_add(T, rmd160_K2(j));
+ T = safe_add(bit_rol(T, rmd160_s2[j]), E2);
+ A2 = E2;
+ E2 = D2;
+ D2 = bit_rol(C2, 10);
+ C2 = B2;
+ B2 = T;
+ }
+
+ T = safe_add(h1, safe_add(C1, D2));
+ h1 = safe_add(h2, safe_add(D1, E2));
+ h2 = safe_add(h3, safe_add(E1, A2));
+ h3 = safe_add(h4, safe_add(A1, B2));
+ h4 = safe_add(h0, safe_add(B1, C2));
+ h0 = T;
+ }
+ return [h0, h1, h2, h3, h4];
+ }
+
+ // specific algorithm methods
+
+ function rmd160_f(j, x, y, z) {
+ return (0 <= j && j <= 15) ? (x ^ y ^ z) :
+ (16 <= j && j <= 31) ? (x & y) | (~x & z) :
+ (32 <= j && j <= 47) ? (x | ~y) ^ z :
+ (48 <= j && j <= 63) ? (x & z) | (y & ~z) :
+ (64 <= j && j <= 79) ? x ^ (y | ~z) :
+ 'rmd160_f: j out of range';
+ }
+
+ function rmd160_K1(j) {
+ return (0 <= j && j <= 15) ? 0x00000000 :
+ (16 <= j && j <= 31) ? 0x5a827999 :
+ (32 <= j && j <= 47) ? 0x6ed9eba1 :
+ (48 <= j && j <= 63) ? 0x8f1bbcdc :
+ (64 <= j && j <= 79) ? 0xa953fd4e :
+ 'rmd160_K1: j out of range';
+ }
+
+ function rmd160_K2(j) {
+ return (0 <= j && j <= 15) ? 0x50a28be6 :
+ (16 <= j && j <= 31) ? 0x5c4dd124 :
+ (32 <= j && j <= 47) ? 0x6d703ef3 :
+ (48 <= j && j <= 63) ? 0x7a6d76e9 :
+ (64 <= j && j <= 79) ? 0x00000000 :
+ 'rmd160_K2: j out of range';
+ }
+ }
+ };
+
+ // exposes Hashes
+ (function(window, undefined$1) {
+ var freeExports = false;
+ {
+ freeExports = exports;
+ if (exports && typeof commonjsGlobal === 'object' && commonjsGlobal && commonjsGlobal === commonjsGlobal.global) {
+ window = commonjsGlobal;
+ }
+ }
+
+ if (typeof undefined$1 === 'function' && typeof undefined$1.amd === 'object' && undefined$1.amd) {
+ // define as an anonymous module, so, through path mapping, it can be aliased
+ undefined$1(function() {
+ return Hashes;
+ });
+ } else if (freeExports) {
+ // in Node.js or RingoJS v0.8.0+
+ if ( module && module.exports === freeExports) {
+ module.exports = Hashes;
+ }
+ // in Narwhal or RingoJS v0.7.0-
+ else {
+ freeExports.Hashes = Hashes;
+ }
+ } else {
+ // in a browser or Rhino
+ window.Hashes = Hashes;
+ }
+ }(this));
+ }()); // IIFE
+ });
+
+ var immutable = extend$3;
+
+ var hasOwnProperty$f = Object.prototype.hasOwnProperty;
+
+ function extend$3() {
+ var target = {};
+
+ for (var i = 0; i < arguments.length; i++) {
+ var source = arguments[i];
+
+ for (var key in source) {
+ if (hasOwnProperty$f.call(source, key)) {
+ target[key] = source[key];
+ }
+ }
+ }
+
+ return target
+ }
+
+ var sha1 = new hashes.SHA1();
+
+ var ohauth = {};
+
+ ohauth.qsString = function(obj) {
+ return Object.keys(obj).sort().map(function(key) {
+ return ohauth.percentEncode(key) + '=' +
+ ohauth.percentEncode(obj[key]);
+ }).join('&');
+ };
+
+ ohauth.stringQs = function(str) {
+ return str.split('&').filter(function (pair) {
+ return pair !== '';
+ }).reduce(function(obj, pair){
+ var parts = pair.split('=');
+ obj[decodeURIComponent(parts[0])] = (null === parts[1]) ?
+ '' : decodeURIComponent(parts[1]);
+ return obj;
+ }, {});
+ };
+
+ ohauth.rawxhr = function(method, url, data, headers, callback) {
+ var xhr = new XMLHttpRequest(),
+ twoHundred = /^20\d$/;
+ xhr.onreadystatechange = function() {
+ if (4 === xhr.readyState && 0 !== xhr.status) {
+ if (twoHundred.test(xhr.status)) callback(null, xhr);
+ else return callback(xhr, null);
+ }
+ };
+ xhr.onerror = function(e) { return callback(e, null); };
+ xhr.open(method, url, true);
+ for (var h in headers) xhr.setRequestHeader(h, headers[h]);
+ xhr.send(data);
+ return xhr;
+ };
+
+ ohauth.xhr = function(method, url, auth, data, options, callback) {
+ var headers = (options && options.header) || {
+ 'Content-Type': 'application/x-www-form-urlencoded'
+ };
+ headers.Authorization = 'OAuth ' + ohauth.authHeader(auth);
+ return ohauth.rawxhr(method, url, data, headers, callback);
+ };
+
+ ohauth.nonce = function() {
+ for (var o = ''; o.length < 6;) {
+ o += '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'[Math.floor(Math.random() * 61)];
+ }
+ return o;
+ };
+
+ ohauth.authHeader = function(obj) {
+ return Object.keys(obj).sort().map(function(key) {
+ return encodeURIComponent(key) + '="' + encodeURIComponent(obj[key]) + '"';
+ }).join(', ');
+ };
+
+ ohauth.timestamp = function() { return ~~((+new Date()) / 1000); };
+
+ ohauth.percentEncode = function(s) {
+ return encodeURIComponent(s)
+ .replace(/\!/g, '%21').replace(/\'/g, '%27')
+ .replace(/\*/g, '%2A').replace(/\(/g, '%28').replace(/\)/g, '%29');
+ };
+
+ ohauth.baseString = function(method, url, params) {
+ if (params.oauth_signature) delete params.oauth_signature;
+ return [
+ method,
+ ohauth.percentEncode(url),
+ ohauth.percentEncode(ohauth.qsString(params))].join('&');
+ };
+
+ ohauth.signature = function(oauth_secret, token_secret, baseString) {
+ return sha1.b64_hmac(
+ ohauth.percentEncode(oauth_secret) + '&' +
+ ohauth.percentEncode(token_secret),
+ baseString);
+ };
+
+ /**
+ * Takes an options object for configuration (consumer_key,
+ * consumer_secret, version, signature_method, token, token_secret)
+ * and returns a function that generates the Authorization header
+ * for given data.
+ *
+ * The returned function takes these parameters:
+ * - method: GET/POST/...
+ * - uri: full URI with protocol, port, path and query string
+ * - extra_params: any extra parameters (that are passed in the POST data),
+ * can be an object or a from-urlencoded string.
+ *
+ * Returned function returns full OAuth header with "OAuth" string in it.
+ */
+
+ ohauth.headerGenerator = function(options) {
+ options = options || {};
+ var consumer_key = options.consumer_key || '',
+ consumer_secret = options.consumer_secret || '',
+ signature_method = options.signature_method || 'HMAC-SHA1',
+ version = options.version || '1.0',
+ token = options.token || '',
+ token_secret = options.token_secret || '';
+
+ return function(method, uri, extra_params) {
+ method = method.toUpperCase();
+ if (typeof extra_params === 'string' && extra_params.length > 0) {
+ extra_params = ohauth.stringQs(extra_params);
+ }
+
+ var uri_parts = uri.split('?', 2),
+ base_uri = uri_parts[0];
+
+ var query_params = uri_parts.length === 2 ?
+ ohauth.stringQs(uri_parts[1]) : {};
+
+ var oauth_params = {
+ oauth_consumer_key: consumer_key,
+ oauth_signature_method: signature_method,
+ oauth_version: version,
+ oauth_timestamp: ohauth.timestamp(),
+ oauth_nonce: ohauth.nonce()
+ };
+
+ if (token) oauth_params.oauth_token = token;
+
+ var all_params = immutable({}, oauth_params, query_params, extra_params),
+ base_str = ohauth.baseString(method, base_uri, all_params);
+
+ oauth_params.oauth_signature = ohauth.signature(consumer_secret, token_secret, base_str);
+
+ return 'OAuth ' + ohauth.authHeader(oauth_params);
+ };
+ };
+
+ var ohauth_1 = ohauth;
+
+ var resolveUrl$1 = createCommonjsModule(function (module, exports) {
+ // Copyright 2014 Simon Lydell
+ // X11 (“MIT”) Licensed. (See LICENSE.)
+
+ void (function(root, factory) {
+ {
+ module.exports = factory();
+ }
+ }(commonjsGlobal, function() {
+
+ function resolveUrl(/* ...urls */) {
+ var numUrls = arguments.length;
+
+ if (numUrls === 0) {
+ throw new Error("resolveUrl requires at least one argument; got none.")
+ }
+
+ var base = document.createElement("base");
+ base.href = arguments[0];
+
+ if (numUrls === 1) {
+ return base.href
+ }
+
+ var head = document.getElementsByTagName("head")[0];
+ head.insertBefore(base, head.firstChild);
+
+ var a = document.createElement("a");
+ var resolved;
+
+ for (var index = 1; index < numUrls; index++) {
+ a.href = arguments[index];
+ resolved = a.href;
+ base.href = resolved;
+ }
+
+ head.removeChild(base);
+
+ return resolved
+ }
+
+ return resolveUrl
+
+ }));
+ });
+
+ var assign$2 = make_assign();
+ var create$8 = make_create();
+ var trim$1 = make_trim();
+ var Global = (typeof window !== 'undefined' ? window : commonjsGlobal);
+
+ var util = {
+ assign: assign$2,
+ create: create$8,
+ trim: trim$1,
+ bind: bind$3,
+ slice: slice$5,
+ each: each,
+ map: map$5,
+ pluck: pluck,
+ isList: isList,
+ isFunction: isFunction$3,
+ isObject: isObject$4,
+ Global: Global
+ };
+
+ function make_assign() {
+ if (Object.assign) {
+ return Object.assign
+ } else {
+ return function shimAssign(obj, props1, props2, etc) {
+ for (var i = 1; i < arguments.length; i++) {
+ each(Object(arguments[i]), function(val, key) {
+ obj[key] = val;
+ });
+ }
+ return obj
+ }
+ }
+ }
+
+ function make_create() {
+ if (Object.create) {
+ return function create(obj, assignProps1, assignProps2, etc) {
+ var assignArgsList = slice$5(arguments, 1);
+ return assign$2.apply(this, [Object.create(obj)].concat(assignArgsList))
+ }
+ } else {
+ function F() {} // eslint-disable-line no-inner-declarations
+ return function create(obj, assignProps1, assignProps2, etc) {
+ var assignArgsList = slice$5(arguments, 1);
+ F.prototype = obj;
+ return assign$2.apply(this, [new F()].concat(assignArgsList))
+ }
+ }
+ }
+
+ function make_trim() {
+ if (String.prototype.trim) {
+ return function trim(str) {
+ return String.prototype.trim.call(str)
+ }
+ } else {
+ return function trim(str) {
+ return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '')
+ }
+ }
+ }
+
+ function bind$3(obj, fn) {
+ return function() {
+ return fn.apply(obj, Array.prototype.slice.call(arguments, 0))
+ }
+ }
+
+ function slice$5(arr, index) {
+ return Array.prototype.slice.call(arr, index || 0)
+ }
+
+ function each(obj, fn) {
+ pluck(obj, function(val, key) {
+ fn(val, key);
+ return false
+ });
+ }
+
+ function map$5(obj, fn) {
+ var res = (isList(obj) ? [] : {});
+ pluck(obj, function(v, k) {
+ res[k] = fn(v, k);
+ return false
+ });
+ return res
+ }
+
+ function pluck(obj, fn) {
+ if (isList(obj)) {
+ for (var i=0; i= 0; i--) {
+ var key = localStorage$1().key(i);
+ fn(read(key), key);
+ }
+ }
+
+ function remove$2(key) {
+ return localStorage$1().removeItem(key)
+ }
+
+ function clearAll() {
+ return localStorage$1().clear()
+ }
+
+ // oldFF-globalStorage provides storage for Firefox
+ // versions 6 and 7, where no localStorage, etc
+ // is available.
+
+
+ var Global$2 = util.Global;
+
+ var oldFFGlobalStorage = {
+ name: 'oldFF-globalStorage',
+ read: read$1,
+ write: write$1,
+ each: each$3,
+ remove: remove$3,
+ clearAll: clearAll$1,
+ };
+
+ var globalStorage = Global$2.globalStorage;
+
+ function read$1(key) {
+ return globalStorage[key]
+ }
+
+ function write$1(key, data) {
+ globalStorage[key] = data;
+ }
+
+ function each$3(fn) {
+ for (var i = globalStorage.length - 1; i >= 0; i--) {
+ var key = globalStorage.key(i);
+ fn(globalStorage[key], key);
+ }
+ }
+
+ function remove$3(key) {
+ return globalStorage.removeItem(key)
+ }
+
+ function clearAll$1() {
+ each$3(function(key, _) {
+ delete globalStorage[key];
+ });
+ }
+
+ // oldIE-userDataStorage provides storage for Internet Explorer
+ // versions 6 and 7, where no localStorage, sessionStorage, etc
+ // is available.
+
+
+ var Global$3 = util.Global;
+
+ var oldIEUserDataStorage = {
+ name: 'oldIE-userDataStorage',
+ write: write$2,
+ read: read$2,
+ each: each$4,
+ remove: remove$4,
+ clearAll: clearAll$2,
+ };
+
+ var storageName = 'storejs';
+ var doc = Global$3.document;
+ var _withStorageEl = _makeIEStorageElFunction();
+ var disable = (Global$3.navigator ? Global$3.navigator.userAgent : '').match(/ (MSIE 8|MSIE 9|MSIE 10)\./); // MSIE 9.x, MSIE 10.x
+
+ function write$2(unfixedKey, data) {
+ if (disable) { return }
+ var fixedKey = fixKey(unfixedKey);
+ _withStorageEl(function(storageEl) {
+ storageEl.setAttribute(fixedKey, data);
+ storageEl.save(storageName);
+ });
+ }
+
+ function read$2(unfixedKey) {
+ if (disable) { return }
+ var fixedKey = fixKey(unfixedKey);
+ var res = null;
+ _withStorageEl(function(storageEl) {
+ res = storageEl.getAttribute(fixedKey);
+ });
+ return res
+ }
+
+ function each$4(callback) {
+ _withStorageEl(function(storageEl) {
+ var attributes = storageEl.XMLDocument.documentElement.attributes;
+ for (var i=attributes.length-1; i>=0; i--) {
+ var attr = attributes[i];
+ callback(storageEl.getAttribute(attr.name), attr.name);
+ }
+ });
+ }
+
+ function remove$4(unfixedKey) {
+ var fixedKey = fixKey(unfixedKey);
+ _withStorageEl(function(storageEl) {
+ storageEl.removeAttribute(fixedKey);
+ storageEl.save(storageName);
+ });
+ }
+
+ function clearAll$2() {
+ _withStorageEl(function(storageEl) {
+ var attributes = storageEl.XMLDocument.documentElement.attributes;
+ storageEl.load(storageName);
+ for (var i=attributes.length-1; i>=0; i--) {
+ storageEl.removeAttribute(attributes[i].name);
+ }
+ storageEl.save(storageName);
+ });
+ }
+
+ // Helpers
+ //////////
+
+ // In IE7, keys cannot start with a digit or contain certain chars.
+ // See https://github.com/marcuswestin/store.js/issues/40
+ // See https://github.com/marcuswestin/store.js/issues/83
+ var forbiddenCharsRegex = new RegExp("[!\"#$%&'()*+,/\\\\:;<=>?@[\\]^`{|}~]", "g");
+ function fixKey(key) {
+ return key.replace(/^\d/, '___$&').replace(forbiddenCharsRegex, '___')
+ }
+
+ function _makeIEStorageElFunction() {
+ if (!doc || !doc.documentElement || !doc.documentElement.addBehavior) {
+ return null
+ }
+ var scriptTag = 'script',
+ storageOwner,
+ storageContainer,
+ storageEl;
+
+ // Since #userData storage applies only to specific paths, we need to
+ // somehow link our data to a specific path. We choose /favicon.ico
+ // as a pretty safe option, since all browsers already make a request to
+ // this URL anyway and being a 404 will not hurt us here. We wrap an
+ // iframe pointing to the favicon in an ActiveXObject(htmlfile) object
+ // (see: http://msdn.microsoft.com/en-us/library/aa752574(v=VS.85).aspx)
+ // since the iframe access rules appear to allow direct access and
+ // manipulation of the document element, even for a 404 page. This
+ // document can be used instead of the current document (which would
+ // have been limited to the current path) to perform #userData storage.
+ try {
+ /* global ActiveXObject */
+ storageContainer = new ActiveXObject('htmlfile');
+ storageContainer.open();
+ storageContainer.write('<'+scriptTag+'>document.w=window'+scriptTag+'>');
+ storageContainer.close();
+ storageOwner = storageContainer.w.frames[0].document;
+ storageEl = storageOwner.createElement('div');
+ } catch(e) {
+ // somehow ActiveXObject instantiation failed (perhaps some special
+ // security settings or otherwse), fall back to per-path storage
+ storageEl = doc.createElement('div');
+ storageOwner = doc.body;
+ }
+
+ return function(storeFunction) {
+ var args = [].slice.call(arguments, 0);
+ args.unshift(storageEl);
+ // See http://msdn.microsoft.com/en-us/library/ms531081(v=VS.85).aspx
+ // and http://msdn.microsoft.com/en-us/library/ms531424(v=VS.85).aspx
+ storageOwner.appendChild(storageEl);
+ storageEl.addBehavior('#default#userData');
+ storageEl.load(storageName);
+ storeFunction.apply(this, args);
+ storageOwner.removeChild(storageEl);
+ return
+ }
+ }
+
+ // cookieStorage is useful Safari private browser mode, where localStorage
+ // doesn't work but cookies do. This implementation is adopted from
+ // https://developer.mozilla.org/en-US/docs/Web/API/Storage/LocalStorage
+
+
+ var Global$4 = util.Global;
+ var trim$2 = util.trim;
+
+ var cookieStorage = {
+ name: 'cookieStorage',
+ read: read$3,
+ write: write$3,
+ each: each$5,
+ remove: remove$5,
+ clearAll: clearAll$3,
+ };
+
+ var doc$1 = Global$4.document;
+
+ function read$3(key) {
+ if (!key || !_has(key)) { return null }
+ var regexpStr = "(?:^|.*;\\s*)" +
+ escape(key).replace(/[\-\.\+\*]/g, "\\$&") +
+ "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*";
+ return unescape(doc$1.cookie.replace(new RegExp(regexpStr), "$1"))
+ }
+
+ function each$5(callback) {
+ var cookies = doc$1.cookie.split(/; ?/g);
+ for (var i = cookies.length - 1; i >= 0; i--) {
+ if (!trim$2(cookies[i])) {
+ continue
+ }
+ var kvp = cookies[i].split('=');
+ var key = unescape(kvp[0]);
+ var val = unescape(kvp[1]);
+ callback(val, key);
+ }
+ }
+
+ function write$3(key, data) {
+ if(!key) { return }
+ doc$1.cookie = escape(key) + "=" + escape(data) + "; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/";
+ }
+
+ function remove$5(key) {
+ if (!key || !_has(key)) {
+ return
+ }
+ doc$1.cookie = escape(key) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/";
+ }
+
+ function clearAll$3() {
+ each$5(function(_, key) {
+ remove$5(key);
+ });
+ }
+
+ function _has(key) {
+ return (new RegExp("(?:^|;\\s*)" + escape(key).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(doc$1.cookie)
+ }
+
+ var Global$5 = util.Global;
+
+ var sessionStorage_1 = {
+ name: 'sessionStorage',
+ read: read$4,
+ write: write$4,
+ each: each$6,
+ remove: remove$6,
+ clearAll: clearAll$4
+ };
+
+ function sessionStorage() {
+ return Global$5.sessionStorage
+ }
+
+ function read$4(key) {
+ return sessionStorage().getItem(key)
+ }
+
+ function write$4(key, data) {
+ return sessionStorage().setItem(key, data)
+ }
+
+ function each$6(fn) {
+ for (var i = sessionStorage().length - 1; i >= 0; i--) {
+ var key = sessionStorage().key(i);
+ fn(read$4(key), key);
+ }
+ }
+
+ function remove$6(key) {
+ return sessionStorage().removeItem(key)
+ }
+
+ function clearAll$4() {
+ return sessionStorage().clear()
+ }
+
+ // memoryStorage is a useful last fallback to ensure that the store
+ // is functions (meaning store.get(), store.set(), etc will all function).
+ // However, stored values will not persist when the browser navigates to
+ // a new page or reloads the current page.
+
+ var memoryStorage_1 = {
+ name: 'memoryStorage',
+ read: read$5,
+ write: write$5,
+ each: each$7,
+ remove: remove$7,
+ clearAll: clearAll$5,
+ };
+
+ var memoryStorage = {};
+
+ function read$5(key) {
+ return memoryStorage[key]
+ }
+
+ function write$5(key, data) {
+ memoryStorage[key] = data;
+ }
+
+ function each$7(callback) {
+ for (var key in memoryStorage) {
+ if (memoryStorage.hasOwnProperty(key)) {
+ callback(memoryStorage[key], key);
+ }
+ }
+ }
+
+ function remove$7(key) {
+ delete memoryStorage[key];
+ }
+
+ function clearAll$5(key) {
+ memoryStorage = {};
+ }
+
+ var all = [
+ // Listed in order of usage preference
+ localStorage_1,
+ oldFFGlobalStorage,
+ oldIEUserDataStorage,
+ cookieStorage,
+ sessionStorage_1,
+ memoryStorage_1
+ ];
+
+ /* eslint-disable */
+
+ // json2.js
+ // 2016-10-28
+ // Public Domain.
+ // NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
+ // See http://www.JSON.org/js.html
+ // This code should be minified before deployment.
+ // See http://javascript.crockford.com/jsmin.html
+
+ // USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
+ // NOT CONTROL.
+
+ // This file creates a global JSON object containing two methods: stringify
+ // and parse. This file provides the ES5 JSON capability to ES3 systems.
+ // If a project might run on IE8 or earlier, then this file should be included.
+ // This file does nothing on ES5 systems.
+
+ // JSON.stringify(value, replacer, space)
+ // value any JavaScript value, usually an object or array.
+ // replacer an optional parameter that determines how object
+ // values are stringified for objects. It can be a
+ // function or an array of strings.
+ // space an optional parameter that specifies the indentation
+ // of nested structures. If it is omitted, the text will
+ // be packed without extra whitespace. If it is a number,
+ // it will specify the number of spaces to indent at each
+ // level. If it is a string (such as "\t" or " "),
+ // it contains the characters used to indent at each level.
+ // This method produces a JSON text from a JavaScript value.
+ // When an object value is found, if the object contains a toJSON
+ // method, its toJSON method will be called and the result will be
+ // stringified. A toJSON method does not serialize: it returns the
+ // value represented by the name/value pair that should be serialized,
+ // or undefined if nothing should be serialized. The toJSON method
+ // will be passed the key associated with the value, and this will be
+ // bound to the value.
+
+ // For example, this would serialize Dates as ISO strings.
+
+ // Date.prototype.toJSON = function (key) {
+ // function f(n) {
+ // // Format integers to have at least two digits.
+ // return (n < 10)
+ // ? "0" + n
+ // : n;
+ // }
+ // return this.getUTCFullYear() + "-" +
+ // f(this.getUTCMonth() + 1) + "-" +
+ // f(this.getUTCDate()) + "T" +
+ // f(this.getUTCHours()) + ":" +
+ // f(this.getUTCMinutes()) + ":" +
+ // f(this.getUTCSeconds()) + "Z";
+ // };
+
+ // You can provide an optional replacer method. It will be passed the
+ // key and value of each member, with this bound to the containing
+ // object. The value that is returned from your method will be
+ // serialized. If your method returns undefined, then the member will
+ // be excluded from the serialization.
+
+ // If the replacer parameter is an array of strings, then it will be
+ // used to select the members to be serialized. It filters the results
+ // such that only members with keys listed in the replacer array are
+ // stringified.
+
+ // Values that do not have JSON representations, such as undefined or
+ // functions, will not be serialized. Such values in objects will be
+ // dropped; in arrays they will be replaced with null. You can use
+ // a replacer function to replace those with JSON values.
+
+ // JSON.stringify(undefined) returns undefined.
+
+ // The optional space parameter produces a stringification of the
+ // value that is filled with line breaks and indentation to make it
+ // easier to read.
+
+ // If the space parameter is a non-empty string, then that string will
+ // be used for indentation. If the space parameter is a number, then
+ // the indentation will be that many spaces.
+
+ // Example:
+
+ // text = JSON.stringify(["e", {pluribus: "unum"}]);
+ // // text is '["e",{"pluribus":"unum"}]'
+
+ // text = JSON.stringify(["e", {pluribus: "unum"}], null, "\t");
+ // // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
+
+ // text = JSON.stringify([new Date()], function (key, value) {
+ // return this[key] instanceof Date
+ // ? "Date(" + this[key] + ")"
+ // : value;
+ // });
+ // // text is '["Date(---current time---)"]'
+
+ // JSON.parse(text, reviver)
+ // This method parses a JSON text to produce an object or array.
+ // It can throw a SyntaxError exception.
+
+ // The optional reviver parameter is a function that can filter and
+ // transform the results. It receives each of the keys and values,
+ // and its return value is used instead of the original value.
+ // If it returns what it received, then the structure is not modified.
+ // If it returns undefined then the member is deleted.
+
+ // Example:
+
+ // // Parse the text. Values that look like ISO date strings will
+ // // be converted to Date objects.
+
+ // myData = JSON.parse(text, function (key, value) {
+ // var a;
+ // if (typeof value === "string") {
+ // a =
+ // /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
+ // if (a) {
+ // return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
+ // +a[5], +a[6]));
+ // }
+ // }
+ // return value;
+ // });
+
+ // myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
+ // var d;
+ // if (typeof value === "string" &&
+ // value.slice(0, 5) === "Date(" &&
+ // value.slice(-1) === ")") {
+ // d = new Date(value.slice(5, -1));
+ // if (d) {
+ // return d;
+ // }
+ // }
+ // return value;
+ // });
+
+ // This is a reference implementation. You are free to copy, modify, or
+ // redistribute.
+
+ /*jslint
+ eval, for, this
+ */
+
+ /*property
+ JSON, apply, call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
+ getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
+ lastIndex, length, parse, prototype, push, replace, slice, stringify,
+ test, toJSON, toString, valueOf
+ */
+
+
+ // Create a JSON object only if one does not already exist. We create the
+ // methods in a closure to avoid creating global variables.
+
+ if (typeof JSON !== "object") {
+ JSON = {};
+ }
+
+ (function () {
+
+ var rx_one = /^[\],:{}\s]*$/;
+ var rx_two = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g;
+ var rx_three = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g;
+ var rx_four = /(?:^|:|,)(?:\s*\[)+/g;
+ var rx_escapable = /[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
+ var rx_dangerous = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
+
+ function f(n) {
+ // Format integers to have at least two digits.
+ return n < 10
+ ? "0" + n
+ : n;
+ }
+
+ function this_value() {
+ return this.valueOf();
+ }
+
+ if (typeof Date.prototype.toJSON !== "function") {
+
+ Date.prototype.toJSON = function () {
+
+ return isFinite(this.valueOf())
+ ? this.getUTCFullYear() + "-" +
+ f(this.getUTCMonth() + 1) + "-" +
+ f(this.getUTCDate()) + "T" +
+ f(this.getUTCHours()) + ":" +
+ f(this.getUTCMinutes()) + ":" +
+ f(this.getUTCSeconds()) + "Z"
+ : null;
+ };
+
+ Boolean.prototype.toJSON = this_value;
+ Number.prototype.toJSON = this_value;
+ String.prototype.toJSON = this_value;
+ }
+
+ var gap;
+ var indent;
+ var meta;
+ var rep;
+
+
+ function quote(string) {
+
+ // If the string contains no control characters, no quote characters, and no
+ // backslash characters, then we can safely slap some quotes around it.
+ // Otherwise we must also replace the offending characters with safe escape
+ // sequences.
+
+ rx_escapable.lastIndex = 0;
+ return rx_escapable.test(string)
+ ? "\"" + string.replace(rx_escapable, function (a) {
+ var c = meta[a];
+ return typeof c === "string"
+ ? c
+ : "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4);
+ }) + "\""
+ : "\"" + string + "\"";
+ }
+
+
+ function str(key, holder) {
+
+ // Produce a string from holder[key].
+
+ var i; // The loop counter.
+ var k; // The member key.
+ var v; // The member value.
+ var length;
+ var mind = gap;
+ var partial;
+ var value = holder[key];
+
+ // If the value has a toJSON method, call it to obtain a replacement value.
+
+ if (value && typeof value === "object" &&
+ typeof value.toJSON === "function") {
+ value = value.toJSON(key);
+ }
+
+ // If we were called with a replacer function, then call the replacer to
+ // obtain a replacement value.
+
+ if (typeof rep === "function") {
+ value = rep.call(holder, key, value);
+ }
+
+ // What happens next depends on the value's type.
+
+ switch (typeof value) {
+ case "string":
+ return quote(value);
+
+ case "number":
+
+ // JSON numbers must be finite. Encode non-finite numbers as null.
+
+ return isFinite(value)
+ ? String(value)
+ : "null";
+
+ case "boolean":
+ case "null":
+
+ // If the value is a boolean or null, convert it to a string. Note:
+ // typeof null does not produce "null". The case is included here in
+ // the remote chance that this gets fixed someday.
+
+ return String(value);
+
+ // If the type is "object", we might be dealing with an object or an array or
+ // null.
+
+ case "object":
+
+ // Due to a specification blunder in ECMAScript, typeof null is "object",
+ // so watch out for that case.
+
+ if (!value) {
+ return "null";
+ }
+
+ // Make an array to hold the partial results of stringifying this object value.
+
+ gap += indent;
+ partial = [];
+
+ // Is the value an array?
+
+ if (Object.prototype.toString.apply(value) === "[object Array]") {
+
+ // The value is an array. Stringify every element. Use null as a placeholder
+ // for non-JSON values.
+
+ length = value.length;
+ for (i = 0; i < length; i += 1) {
+ partial[i] = str(i, value) || "null";
+ }
+
+ // Join all of the elements together, separated with commas, and wrap them in
+ // brackets.
+
+ v = partial.length === 0
+ ? "[]"
+ : gap
+ ? "[\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "]"
+ : "[" + partial.join(",") + "]";
+ gap = mind;
+ return v;
+ }
+
+ // If the replacer is an array, use it to select the members to be stringified.
+
+ if (rep && typeof rep === "object") {
+ length = rep.length;
+ for (i = 0; i < length; i += 1) {
+ if (typeof rep[i] === "string") {
+ k = rep[i];
+ v = str(k, value);
+ if (v) {
+ partial.push(quote(k) + (
+ gap
+ ? ": "
+ : ":"
+ ) + v);
+ }
+ }
+ }
+ } else {
+
+ // Otherwise, iterate through all of the keys in the object.
+
+ for (k in value) {
+ if (Object.prototype.hasOwnProperty.call(value, k)) {
+ v = str(k, value);
+ if (v) {
+ partial.push(quote(k) + (
+ gap
+ ? ": "
+ : ":"
+ ) + v);
+ }
+ }
+ }
+ }
+
+ // Join all of the member texts together, separated with commas,
+ // and wrap them in braces.
+
+ v = partial.length === 0
+ ? "{}"
+ : gap
+ ? "{\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "}"
+ : "{" + partial.join(",") + "}";
+ gap = mind;
+ return v;
+ }
+ }
+
+ // If the JSON object does not yet have a stringify method, give it one.
+
+ if (typeof JSON.stringify !== "function") {
+ meta = { // table of character substitutions
+ "\b": "\\b",
+ "\t": "\\t",
+ "\n": "\\n",
+ "\f": "\\f",
+ "\r": "\\r",
+ "\"": "\\\"",
+ "\\": "\\\\"
+ };
+ JSON.stringify = function (value, replacer, space) {
+
+ // The stringify method takes a value and an optional replacer, and an optional
+ // space parameter, and returns a JSON text. The replacer can be a function
+ // that can replace values, or an array of strings that will select the keys.
+ // A default replacer method can be provided. Use of the space parameter can
+ // produce text that is more easily readable.
+
+ var i;
+ gap = "";
+ indent = "";
+
+ // If the space parameter is a number, make an indent string containing that
+ // many spaces.
+
+ if (typeof space === "number") {
+ for (i = 0; i < space; i += 1) {
+ indent += " ";
+ }
+
+ // If the space parameter is a string, it will be used as the indent string.
+
+ } else if (typeof space === "string") {
+ indent = space;
+ }
+
+ // If there is a replacer, it must be a function or an array.
+ // Otherwise, throw an error.
+
+ rep = replacer;
+ if (replacer && typeof replacer !== "function" &&
+ (typeof replacer !== "object" ||
+ typeof replacer.length !== "number")) {
+ throw new Error("JSON.stringify");
+ }
+
+ // Make a fake root object containing our value under the key of "".
+ // Return the result of stringifying the value.
+
+ return str("", {"": value});
+ };
+ }
+
+
+ // If the JSON object does not yet have a parse method, give it one.
+
+ if (typeof JSON.parse !== "function") {
+ JSON.parse = function (text, reviver) {
+
+ // The parse method takes a text and an optional reviver function, and returns
+ // a JavaScript value if the text is a valid JSON text.
+
+ var j;
+
+ function walk(holder, key) {
+
+ // The walk method is used to recursively walk the resulting structure so
+ // that modifications can be made.
+
+ var k;
+ var v;
+ var value = holder[key];
+ if (value && typeof value === "object") {
+ for (k in value) {
+ if (Object.prototype.hasOwnProperty.call(value, k)) {
+ v = walk(value, k);
+ if (v !== undefined) {
+ value[k] = v;
+ } else {
+ delete value[k];
+ }
+ }
+ }
+ }
+ return reviver.call(holder, key, value);
+ }
+
+
+ // Parsing happens in four stages. In the first stage, we replace certain
+ // Unicode characters with escape sequences. JavaScript handles many characters
+ // incorrectly, either silently deleting them, or treating them as line endings.
+
+ text = String(text);
+ rx_dangerous.lastIndex = 0;
+ if (rx_dangerous.test(text)) {
+ text = text.replace(rx_dangerous, function (a) {
+ return "\\u" +
+ ("0000" + a.charCodeAt(0).toString(16)).slice(-4);
+ });
+ }
+
+ // In the second stage, we run the text against regular expressions that look
+ // for non-JSON patterns. We are especially concerned with "()" and "new"
+ // because they can cause invocation, and "=" because it can cause mutation.
+ // But just to be safe, we want to reject all unexpected forms.
+
+ // We split the second stage into 4 regexp operations in order to work around
+ // crippling inefficiencies in IE's and Safari's regexp engines. First we
+ // replace the JSON backslash pairs with "@" (a non-JSON character). Second, we
+ // replace all simple value tokens with "]" characters. Third, we delete all
+ // open brackets that follow a colon or comma or that begin the text. Finally,
+ // we look to see that the remaining characters are only whitespace or "]" or
+ // "," or ":" or "{" or "}". If that is so, then the text is safe for eval.
+
+ if (
+ rx_one.test(
+ text
+ .replace(rx_two, "@")
+ .replace(rx_three, "]")
+ .replace(rx_four, "")
+ )
+ ) {
+
+ // In the third stage we use the eval function to compile the text into a
+ // JavaScript structure. The "{" operator is subject to a syntactic ambiguity
+ // in JavaScript: it can begin a block or an object literal. We wrap the text
+ // in parens to eliminate the ambiguity.
+
+ j = eval("(" + text + ")");
+
+ // In the optional fourth stage, we recursively walk the new structure, passing
+ // each name/value pair to a reviver function for possible transformation.
+
+ return (typeof reviver === "function")
+ ? walk({"": j}, "")
+ : j;
+ }
+
+ // If the text is not JSON parseable, then a SyntaxError is thrown.
+
+ throw new SyntaxError("JSON.parse");
+ };
+ }
+ }());
+
+ var json2 = json2Plugin;
+
+ function json2Plugin() {
+
+ return {}
+ }
+
+ var plugins = [json2];
+
+ var store_legacy = storeEngine.createStore(all, plugins);
+
+ // # osm-auth
+ //
+ // This code is only compatible with IE10+ because the [XDomainRequest](http://bit.ly/LfO7xo)
+ // object, IE<10's idea of [CORS](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing),
+ // does not support custom headers, which this uses everywhere.
+ var osmAuth = function(o) {
+
+ var oauth = {};
+
+ // authenticated users will also have a request token secret, but it's
+ // not used in transactions with the server
+ oauth.authenticated = function() {
+ return !!(token('oauth_token') && token('oauth_token_secret'));
+ };
+
+ oauth.logout = function() {
+ token('oauth_token', '');
+ token('oauth_token_secret', '');
+ token('oauth_request_token_secret', '');
+ return oauth;
+ };
+
+ // TODO: detect lack of click event
+ oauth.authenticate = function(callback) {
+ if (oauth.authenticated()) return callback();
+
+ oauth.logout();
+
+ // ## Getting a request token
+ var params = timenonce(getAuth(o)),
+ url = o.url + '/oauth/request_token';
+
+ params.oauth_signature = ohauth_1.signature(
+ o.oauth_secret, '',
+ ohauth_1.baseString('POST', url, params));
+
+ if (!o.singlepage) {
+ // Create a 600x550 popup window in the center of the screen
+ var w = 600, h = 550,
+ settings = [
+ ['width', w], ['height', h],
+ ['left', screen.width / 2 - w / 2],
+ ['top', screen.height / 2 - h / 2]].map(function(x) {
+ return x.join('=');
+ }).join(','),
+ popup = window.open('about:blank', 'oauth_window', settings);
+ }
+
+ // Request a request token. When this is complete, the popup
+ // window is redirected to OSM's authorization page.
+ ohauth_1.xhr('POST', url, params, null, {}, reqTokenDone);
+ o.loading();
+
+ function reqTokenDone(err, xhr) {
+ o.done();
+ if (err) return callback(err);
+ var resp = ohauth_1.stringQs(xhr.response);
+ token('oauth_request_token_secret', resp.oauth_token_secret);
+ var authorize_url = o.url + '/oauth/authorize?' + ohauth_1.qsString({
+ oauth_token: resp.oauth_token,
+ oauth_callback: resolveUrl$1(o.landing)
+ });
+
+ if (o.singlepage) {
+ location.href = authorize_url;
+ } else {
+ popup.location = authorize_url;
+ }
+ }
+
+ // Called by a function in a landing page, in the popup window. The
+ // window closes itself.
+ window.authComplete = function(token) {
+ var oauth_token = ohauth_1.stringQs(token.split('?')[1]);
+ get_access_token(oauth_token.oauth_token);
+ delete window.authComplete;
+ };
+
+ // ## Getting an request token
+ //
+ // At this point we have an `oauth_token`, brought in from a function
+ // call on a landing page popup.
+ function get_access_token(oauth_token) {
+ var url = o.url + '/oauth/access_token',
+ params = timenonce(getAuth(o)),
+ request_token_secret = token('oauth_request_token_secret');
+ params.oauth_token = oauth_token;
+ params.oauth_signature = ohauth_1.signature(
+ o.oauth_secret,
+ request_token_secret,
+ ohauth_1.baseString('POST', url, params));
+
+ // ## Getting an access token
+ //
+ // The final token required for authentication. At this point
+ // we have a `request token secret`
+ ohauth_1.xhr('POST', url, params, null, {}, accessTokenDone);
+ o.loading();
+ }
+
+ function accessTokenDone(err, xhr) {
+ o.done();
+ if (err) return callback(err);
+ var access_token = ohauth_1.stringQs(xhr.response);
+ token('oauth_token', access_token.oauth_token);
+ token('oauth_token_secret', access_token.oauth_token_secret);
+ callback(null, oauth);
+ }
+ };
+
+ oauth.bootstrapToken = function(oauth_token, callback) {
+ // ## Getting an request token
+ // At this point we have an `oauth_token`, brought in from a function
+ // call on a landing page popup.
+ function get_access_token(oauth_token) {
+ var url = o.url + '/oauth/access_token',
+ params = timenonce(getAuth(o)),
+ request_token_secret = token('oauth_request_token_secret');
+ params.oauth_token = oauth_token;
+ params.oauth_signature = ohauth_1.signature(
+ o.oauth_secret,
+ request_token_secret,
+ ohauth_1.baseString('POST', url, params));
+
+ // ## Getting an access token
+ // The final token required for authentication. At this point
+ // we have a `request token secret`
+ ohauth_1.xhr('POST', url, params, null, {}, accessTokenDone);
+ o.loading();
+ }
+
+ function accessTokenDone(err, xhr) {
+ o.done();
+ if (err) return callback(err);
+ var access_token = ohauth_1.stringQs(xhr.response);
+ token('oauth_token', access_token.oauth_token);
+ token('oauth_token_secret', access_token.oauth_token_secret);
+ callback(null, oauth);
+ }
+
+ get_access_token(oauth_token);
+ };
+
+ // # xhr
+ //
+ // A single XMLHttpRequest wrapper that does authenticated calls if the
+ // user has logged in.
+ oauth.xhr = function(options, callback) {
+ if (!oauth.authenticated()) {
+ if (o.auto) {
+ return oauth.authenticate(run);
+ } else {
+ callback('not authenticated', null);
+ return;
+ }
+ } else {
+ return run();
+ }
+
+ function run() {
+ var params = timenonce(getAuth(o)),
+ oauth_token_secret = token('oauth_token_secret'),
+ url = (options.prefix !== false) ? o.url + options.path : options.path,
+ url_parts = url.replace(/#.*$/, '').split('?', 2),
+ base_url = url_parts[0],
+ query = (url_parts.length === 2) ? url_parts[1] : '';
+
+ // https://tools.ietf.org/html/rfc5849#section-3.4.1.3.1
+ if ((!options.options || !options.options.header ||
+ options.options.header['Content-Type'] === 'application/x-www-form-urlencoded') &&
+ options.content) {
+ params = immutable(params, ohauth_1.stringQs(options.content));
+ }
+
+ params.oauth_token = token('oauth_token');
+ params.oauth_signature = ohauth_1.signature(
+ o.oauth_secret,
+ oauth_token_secret,
+ ohauth_1.baseString(options.method, base_url, immutable(params, ohauth_1.stringQs(query)))
+ );
+
+ return ohauth_1.xhr(options.method, url, params, options.content, options.options, done);
+ }
+
+ function done(err, xhr) {
+ if (err) return callback(err);
+ else if (xhr.responseXML) return callback(err, xhr.responseXML);
+ else return callback(err, xhr.response);
+ }
+ };
+
+ // pre-authorize this object, if we can just get a token and token_secret
+ // from the start
+ oauth.preauth = function(c) {
+ if (!c) return;
+ if (c.oauth_token) token('oauth_token', c.oauth_token);
+ if (c.oauth_token_secret) token('oauth_token_secret', c.oauth_token_secret);
+ return oauth;
+ };
+
+ oauth.options = function(_) {
+ if (!arguments.length) return o;
+
+ o = _;
+ o.url = o.url || 'https://www.openstreetmap.org';
+ o.landing = o.landing || 'land.html';
+ o.singlepage = o.singlepage || false;
+
+ // Optional loading and loading-done functions for nice UI feedback.
+ // by default, no-ops
+ o.loading = o.loading || function() {};
+ o.done = o.done || function() {};
+
+ return oauth.preauth(o);
+ };
+
+ // 'stamp' an authentication object from `getAuth()`
+ // with a [nonce](http://en.wikipedia.org/wiki/Cryptographic_nonce)
+ // and timestamp
+ function timenonce(o) {
+ o.oauth_timestamp = ohauth_1.timestamp();
+ o.oauth_nonce = ohauth_1.nonce();
+ return o;
+ }
+
+ // get/set tokens. These are prefixed with the base URL so that `osm-auth`
+ // can be used with multiple APIs and the keys in `localStorage`
+ // will not clash
+ var token;
+
+ if (store_legacy.enabled) {
+ token = function (x, y) {
+ if (arguments.length === 1) return store_legacy.get(o.url + x);
+ else if (arguments.length === 2) return store_legacy.set(o.url + x, y);
+ };
+ } else {
+ var storage = {};
+ token = function (x, y) {
+ if (arguments.length === 1) return storage[o.url + x];
+ else if (arguments.length === 2) return storage[o.url + x] = y;
+ };
+ }
+
+ // Get an authentication object. If you just add and remove properties
+ // from a single object, you'll need to use `delete` to make sure that
+ // it doesn't contain undesired properties for authentication
+ function getAuth(o) {
+ return {
+ oauth_consumer_key: o.oauth_consumer_key,
+ oauth_signature_method: 'HMAC-SHA1'
+ };
+ }
+
+ // potentially pre-authorize
+ oauth.options(o);
+
+ return oauth;
+ };
+
+ var tiler$7 = utilTiler();
+ var dispatch$8 = dispatch('apiStatusChange', 'authLoading', 'authDone', 'change', 'loading', 'loaded', 'loadedNotes');
+ var urlroot = 'https://www.openstreetmap.org';
+ var q = utilStringQs(window.location.hash.substring(1));
+ var credentialsMode = 'omit';
+ if (q.hasOwnProperty('osm_api_url')) {
+ urlroot = q.osm_api_url;
+ credentialsMode = 'include';
+ }
+ var oauth = osmAuth({
+ url: urlroot,
+ oauth_consumer_key: 'MlAcABGGdqadlgrjpmG6qSQu3bwbAgxC7hW0vRwm',
+ oauth_secret: 'M0g3lCJTvpnwMic0HYYwwTMpVvugNRlkycQL7so5',
+ loading: authLoading,
+ done: authDone
+ });
+
+ var _blacklists = ['.*\.google(apis)?\..*/(vt|kh)[\?/].*([xyz]=.*){3}.*'];
+ var _tileCache = { toLoad: {}, loaded: {}, inflight: {}, seen: {}, rtree: new RBush() };
+ var _noteCache = { toLoad: {}, loaded: {}, inflight: {}, inflightPost: {}, note: {}, closed: {}, rtree: new RBush() };
+ var _userCache = { toLoad: {}, user: {} };
+ var _cachedApiStatus;
+ var _changeset = {};
+
+ var _deferred = new Set();
+ var _connectionID = 1;
+ var _tileZoom$3 = 16;
+ var _noteZoom = 12;
+ var _rateLimitError;
+ var _userChangesets;
+ var _userDetails;
+ var _off$2;
+
+ // set a default but also load this from the API status
+ var _maxWayNodes = 2000;
+
+
+ function authLoading() {
+ dispatch$8.call('authLoading');
+ }
+
+
+ function authDone() {
+ dispatch$8.call('authDone');
+ }
+
+
+ function abortRequest$7(controllerOrXHR) {
+ if (controllerOrXHR) {
+ controllerOrXHR.abort();
+ }
+ }
+
+
+ function hasInflightRequests(cache) {
+ return Object.keys(cache.inflight).length;
+ }
+
+
+ function abortUnwantedRequests$3(cache, visibleTiles) {
+ Object.keys(cache.inflight).forEach(function(k) {
+ if (cache.toLoad[k]) return;
+ if (visibleTiles.find(function(tile) { return k === tile.id; })) return;
+
+ abortRequest$7(cache.inflight[k]);
+ delete cache.inflight[k];
+ });
+ }
+
+
+ function getLoc$1(attrs) {
+ var lon = attrs.lon && attrs.lon.value;
+ var lat = attrs.lat && attrs.lat.value;
+ return [parseFloat(lon), parseFloat(lat)];
+ }
+
+
+ function getNodes$1(obj) {
+ var elems = obj.getElementsByTagName('nd');
+ var nodes = new Array(elems.length);
+ for (var i = 0, l = elems.length; i < l; i++) {
+ nodes[i] = 'n' + elems[i].attributes.ref.value;
+ }
+ return nodes;
+ }
+
+ function getNodesJSON(obj) {
+ var elems = obj.nodes;
+ var nodes = new Array(elems.length);
+ for (var i = 0, l = elems.length; i < l; i++) {
+ nodes[i] = 'n' + elems[i];
+ }
+ return nodes;
+ }
+
+ function getTags$1(obj) {
+ var elems = obj.getElementsByTagName('tag');
+ var tags = {};
+ for (var i = 0, l = elems.length; i < l; i++) {
+ var attrs = elems[i].attributes;
+ tags[attrs.k.value] = attrs.v.value;
+ }
+
+ return tags;
+ }
+
+
+ function getMembers(obj) {
+ var elems = obj.getElementsByTagName('member');
+ var members = new Array(elems.length);
+ for (var i = 0, l = elems.length; i < l; i++) {
+ var attrs = elems[i].attributes;
+ members[i] = {
+ id: attrs.type.value[0] + attrs.ref.value,
+ type: attrs.type.value,
+ role: attrs.role.value
+ };
+ }
+ return members;
+ }
+
+ function getMembersJSON(obj) {
+ var elems = obj.members;
+ var members = new Array(elems.length);
+ for (var i = 0, l = elems.length; i < l; i++) {
+ var attrs = elems[i];
+ members[i] = {
+ id: attrs.type[0] + attrs.ref,
+ type: attrs.type,
+ role: attrs.role
+ };
+ }
+ return members;
+ }
+
+ function getVisible$1(attrs) {
+ return (!attrs.visible || attrs.visible.value !== 'false');
+ }
+
+
+ function parseComments(comments) {
+ var parsedComments = [];
+
+ // for each comment
+ for (var i = 0; i < comments.length; i++) {
+ var comment = comments[i];
+ if (comment.nodeName === 'comment') {
+ var childNodes = comment.childNodes;
+ var parsedComment = {};
+
+ for (var j = 0; j < childNodes.length; j++) {
+ var node = childNodes[j];
+ var nodeName = node.nodeName;
+ if (nodeName === '#text') continue;
+ parsedComment[nodeName] = node.textContent;
+
+ if (nodeName === 'uid') {
+ var uid = node.textContent;
+ if (uid && !_userCache.user[uid]) {
+ _userCache.toLoad[uid] = true;
+ }
+ }
+ }
+
+ if (parsedComment) {
+ parsedComments.push(parsedComment);
+ }
+ }
+ }
+ return parsedComments;
+ }
+
+
+ function encodeNoteRtree(note) {
+ return {
+ minX: note.loc[0],
+ minY: note.loc[1],
+ maxX: note.loc[0],
+ maxY: note.loc[1],
+ data: note
+ };
+ }
+
+
+ var jsonparsers = {
+
+ node: function nodeData(obj, uid) {
+ return new osmNode({
+ id: uid,
+ visible: typeof obj.visible === 'boolean' ? obj.visible : true,
+ version: obj.version && obj.version.toString(),
+ changeset: obj.changeset && obj.changeset.toString(),
+ timestamp: obj.timestamp,
+ user: obj.user,
+ uid: obj.uid && obj.uid.toString(),
+ loc: [parseFloat(obj.lon), parseFloat(obj.lat)],
+ tags: obj.tags
+ });
+ },
+
+ way: function wayData(obj, uid) {
+ return new osmWay({
+ id: uid,
+ visible: typeof obj.visible === 'boolean' ? obj.visible : true,
+ version: obj.version && obj.version.toString(),
+ changeset: obj.changeset && obj.changeset.toString(),
+ timestamp: obj.timestamp,
+ user: obj.user,
+ uid: obj.uid && obj.uid.toString(),
+ tags: obj.tags,
+ nodes: getNodesJSON(obj)
+ });
+ },
+
+ relation: function relationData(obj, uid) {
+ return new osmRelation({
+ id: uid,
+ visible: typeof obj.visible === 'boolean' ? obj.visible : true,
+ version: obj.version && obj.version.toString(),
+ changeset: obj.changeset && obj.changeset.toString(),
+ timestamp: obj.timestamp,
+ user: obj.user,
+ uid: obj.uid && obj.uid.toString(),
+ tags: obj.tags,
+ members: getMembersJSON(obj)
+ });
+ }
+ };
+
+ function parseJSON(payload, callback, options) {
+ options = Object.assign({ skipSeen: true }, options);
+ if (!payload) {
+ return callback({ message: 'No JSON', status: -1 });
+ }
+
+ var json = payload;
+ if (typeof json !== 'object')
+ json = JSON.parse(payload);
+
+ if (!json.elements)
+ return callback({ message: 'No JSON', status: -1 });
+
+ var children = json.elements;
+
+ var handle = window.requestIdleCallback(function() {
+ var results = [];
+ var result;
+ for (var i = 0; i < children.length; i++) {
+ result = parseChild(children[i]);
+ if (result) results.push(result);
+ }
+ callback(null, results);
+ });
+
+ _deferred.add(handle);
+
+ function parseChild(child) {
+ var parser = jsonparsers[child.type];
+ if (!parser) return null;
+
+ var uid;
+
+ uid = osmEntity.id.fromOSM(child.type, child.id);
+ if (options.skipSeen) {
+ if (_tileCache.seen[uid]) return null; // avoid reparsing a "seen" entity
+ _tileCache.seen[uid] = true;
+ }
+
+ return parser(child, uid);
+ }
+ }
+
+ var parsers$1 = {
+ node: function nodeData(obj, uid) {
+ var attrs = obj.attributes;
+ return new osmNode({
+ id: uid,
+ visible: getVisible$1(attrs),
+ version: attrs.version.value,
+ changeset: attrs.changeset && attrs.changeset.value,
+ timestamp: attrs.timestamp && attrs.timestamp.value,
+ user: attrs.user && attrs.user.value,
+ uid: attrs.uid && attrs.uid.value,
+ loc: getLoc$1(attrs),
+ tags: getTags$1(obj)
+ });
+ },
+
+ way: function wayData(obj, uid) {
+ var attrs = obj.attributes;
+ return new osmWay({
+ id: uid,
+ visible: getVisible$1(attrs),
+ version: attrs.version.value,
+ changeset: attrs.changeset && attrs.changeset.value,
+ timestamp: attrs.timestamp && attrs.timestamp.value,
+ user: attrs.user && attrs.user.value,
+ uid: attrs.uid && attrs.uid.value,
+ tags: getTags$1(obj),
+ nodes: getNodes$1(obj),
+ });
+ },
+
+ relation: function relationData(obj, uid) {
+ var attrs = obj.attributes;
+ return new osmRelation({
+ id: uid,
+ visible: getVisible$1(attrs),
+ version: attrs.version.value,
+ changeset: attrs.changeset && attrs.changeset.value,
+ timestamp: attrs.timestamp && attrs.timestamp.value,
+ user: attrs.user && attrs.user.value,
+ uid: attrs.uid && attrs.uid.value,
+ tags: getTags$1(obj),
+ members: getMembers(obj)
+ });
+ },
+
+ note: function parseNote(obj, uid) {
+ var attrs = obj.attributes;
+ var childNodes = obj.childNodes;
+ var props = {};
+
+ props.id = uid;
+ props.loc = getLoc$1(attrs);
+
+ // if notes are coincident, move them apart slightly
+ var coincident = false;
+ var epsilon = 0.00001;
+ do {
+ if (coincident) {
+ props.loc = geoVecAdd(props.loc, [epsilon, epsilon]);
+ }
+ var bbox = geoExtent(props.loc).bbox();
+ coincident = _noteCache.rtree.search(bbox).length;
+ } while (coincident);
+
+ // parse note contents
+ for (var i = 0; i < childNodes.length; i++) {
+ var node = childNodes[i];
+ var nodeName = node.nodeName;
+ if (nodeName === '#text') continue;
+
+ // if the element is comments, parse the comments
+ if (nodeName === 'comments') {
+ props[nodeName] = parseComments(node.childNodes);
+ } else {
+ props[nodeName] = node.textContent;
+ }
+ }
+
+ var note = new osmNote(props);
+ var item = encodeNoteRtree(note);
+ _noteCache.note[note.id] = note;
+ _noteCache.rtree.insert(item);
+
+ return note;
+ },
+
+ user: function parseUser(obj, uid) {
+ var attrs = obj.attributes;
+ var user = {
+ id: uid,
+ display_name: attrs.display_name && attrs.display_name.value,
+ account_created: attrs.account_created && attrs.account_created.value,
+ changesets_count: '0',
+ active_blocks: '0'
+ };
+
+ var img = obj.getElementsByTagName('img');
+ if (img && img[0] && img[0].getAttribute('href')) {
+ user.image_url = img[0].getAttribute('href');
+ }
+
+ var changesets = obj.getElementsByTagName('changesets');
+ if (changesets && changesets[0] && changesets[0].getAttribute('count')) {
+ user.changesets_count = changesets[0].getAttribute('count');
+ }
+
+ var blocks = obj.getElementsByTagName('blocks');
+ if (blocks && blocks[0]) {
+ var received = blocks[0].getElementsByTagName('received');
+ if (received && received[0] && received[0].getAttribute('active')) {
+ user.active_blocks = received[0].getAttribute('active');
+ }
+ }
+
+ _userCache.user[uid] = user;
+ delete _userCache.toLoad[uid];
+ return user;
+ }
+ };
+
+
+ function parseXML$1(xml, callback, options) {
+ options = Object.assign({ skipSeen: true }, options);
+ if (!xml || !xml.childNodes) {
+ return callback({ message: 'No XML', status: -1 });
+ }
+
+ var root = xml.childNodes[0];
+ var children = root.childNodes;
+
+ var handle = window.requestIdleCallback(function() {
+ var results = [];
+ var result;
+ for (var i = 0; i < children.length; i++) {
+ result = parseChild(children[i]);
+ if (result) results.push(result);
+ }
+ callback(null, results);
+ });
+
+ _deferred.add(handle);
+
+
+ function parseChild(child) {
+ var parser = parsers$1[child.nodeName];
+ if (!parser) return null;
+
+ var uid;
+ if (child.nodeName === 'user') {
+ uid = child.attributes.id.value;
+ if (options.skipSeen && _userCache.user[uid]) {
+ delete _userCache.toLoad[uid];
+ return null;
+ }
+
+ } else if (child.nodeName === 'note') {
+ uid = child.getElementsByTagName('id')[0].textContent;
+
+ } else {
+ uid = osmEntity.id.fromOSM(child.nodeName, child.attributes.id.value);
+ if (options.skipSeen) {
+ if (_tileCache.seen[uid]) return null; // avoid reparsing a "seen" entity
+ _tileCache.seen[uid] = true;
+ }
+ }
+
+ return parser(child, uid);
+ }
+ }
+
+
+ // replace or remove note from rtree
+ function updateRtree$3(item, replace) {
+ _noteCache.rtree.remove(item, function isEql(a, b) { return a.data.id === b.data.id; });
+
+ if (replace) {
+ _noteCache.rtree.insert(item);
+ }
+ }
+
+
+ function wrapcb(thisArg, callback, cid) {
+ return function(err, result) {
+ if (err) {
+ // 400 Bad Request, 401 Unauthorized, 403 Forbidden..
+ if (err.status === 400 || err.status === 401 || err.status === 403) {
+ thisArg.logout();
+ }
+ return callback.call(thisArg, err);
+
+ } else if (thisArg.getConnectionId() !== cid) {
+ return callback.call(thisArg, { message: 'Connection Switched', status: -1 });
+
+ } else {
+ return callback.call(thisArg, err, result);
+ }
+ };
+ }
+
+
+ var serviceOsm = {
+
+ init: function() {
+ utilRebind(this, dispatch$8, 'on');
+ },
+
+
+ reset: function() {
+ Array.from(_deferred).forEach(function(handle) {
+ window.cancelIdleCallback(handle);
+ _deferred.delete(handle);
+ });
+
+ _connectionID++;
+ _userChangesets = undefined;
+ _userDetails = undefined;
+ _rateLimitError = undefined;
+
+ Object.values(_tileCache.inflight).forEach(abortRequest$7);
+ Object.values(_noteCache.inflight).forEach(abortRequest$7);
+ Object.values(_noteCache.inflightPost).forEach(abortRequest$7);
+ if (_changeset.inflight) abortRequest$7(_changeset.inflight);
+
+ _tileCache = { toLoad: {}, loaded: {}, inflight: {}, seen: {}, rtree: new RBush() };
+ _noteCache = { toLoad: {}, loaded: {}, inflight: {}, inflightPost: {}, note: {}, closed: {}, rtree: new RBush() };
+ _userCache = { toLoad: {}, user: {} };
+ _cachedApiStatus = undefined;
+ _changeset = {};
+
+ return this;
+ },
+
+
+ getConnectionId: function() {
+ return _connectionID;
+ },
+
+
+ changesetURL: function(changesetID) {
+ return urlroot + '/changeset/' + changesetID;
+ },
+
+
+ changesetsURL: function(center, zoom) {
+ var precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
+ return urlroot + '/history#map=' +
+ Math.floor(zoom) + '/' +
+ center[1].toFixed(precision) + '/' +
+ center[0].toFixed(precision);
+ },
+
+
+ entityURL: function(entity) {
+ return urlroot + '/' + entity.type + '/' + entity.osmId();
+ },
+
+
+ historyURL: function(entity) {
+ return urlroot + '/' + entity.type + '/' + entity.osmId() + '/history';
+ },
+
+
+ userURL: function(username) {
+ return urlroot + '/user/' + username;
+ },
+
+
+ noteURL: function(note) {
+ return urlroot + '/note/' + note.id;
+ },
+
+
+ noteReportURL: function(note) {
+ return urlroot + '/reports/new?reportable_type=Note&reportable_id=' + note.id;
+ },
+
+
+ // Generic method to load data from the OSM API
+ // Can handle either auth or unauth calls.
+ loadFromAPI: function(path, callback, options) {
+ options = Object.assign({ skipSeen: true }, options);
+ var that = this;
+ var cid = _connectionID;
+
+ function done(err, payload) {
+ if (that.getConnectionId() !== cid) {
+ if (callback) callback({ message: 'Connection Switched', status: -1 });
+ return;
+ }
+
+ var isAuthenticated = that.authenticated();
+
+ // 400 Bad Request, 401 Unauthorized, 403 Forbidden
+ // Logout and retry the request..
+ if (isAuthenticated && err && err.status &&
+ (err.status === 400 || err.status === 401 || err.status === 403)) {
+ that.logout();
+ that.loadFromAPI(path, callback, options);
+
+ // else, no retry..
+ } else {
+ // 509 Bandwidth Limit Exceeded, 429 Too Many Requests
+ // Set the rateLimitError flag and trigger a warning..
+ if (!isAuthenticated && !_rateLimitError && err && err.status &&
+ (err.status === 509 || err.status === 429)) {
+ _rateLimitError = err;
+ dispatch$8.call('change');
+ that.reloadApiStatus();
+
+ } else if ((err && _cachedApiStatus === 'online') ||
+ (!err && _cachedApiStatus !== 'online')) {
+ // If the response's error state doesn't match the status,
+ // it's likely we lost or gained the connection so reload the status
+ that.reloadApiStatus();
+ }
+
+ if (callback) {
+ if (err) {
+ return callback(err);
+ } else {
+ if (path.indexOf('.json') !== -1) {
+ return parseJSON(payload, callback, options);
+ } else {
+ return parseXML$1(payload, callback, options);
+ }
+ }
+ }
+ }
+ }
+
+ if (this.authenticated()) {
+ return oauth.xhr({ method: 'GET', path: path }, done);
+ } else {
+ var url = urlroot + path;
+ var controller = new AbortController();
+ d3_json(url, { signal: controller.signal })
+ .then(function(data) {
+ done(null, data);
+ })
+ .catch(function(err) {
+ if (err.name === 'AbortError') return;
+ // d3-fetch includes status in the error message,
+ // but we can't access the response itself
+ // https://github.com/d3/d3-fetch/issues/27
+ var match = err.message.match(/^\d{3}/);
+ if (match) {
+ done({ status: +match[0], statusText: err.message });
+ } else {
+ done(err.message);
+ }
+ });
+ return controller;
+ }
+ },
+
+
+ // Load a single entity by id (ways and relations use the `/full` call)
+ // GET /api/0.6/node/#id
+ // GET /api/0.6/[way|relation]/#id/full
+ loadEntity: function(id, callback) {
+ var type = osmEntity.id.type(id);
+ var osmID = osmEntity.id.toOSM(id);
+ var options = { skipSeen: false };
+
+ this.loadFromAPI(
+ '/api/0.6/' + type + '/' + osmID + (type !== 'node' ? '/full' : '') + '.json',
+ function(err, entities) {
+ if (callback) callback(err, { data: entities });
+ },
+ options
+ );
+ },
+
+
+ // Load a single entity with a specific version
+ // GET /api/0.6/[node|way|relation]/#id/#version
+ loadEntityVersion: function(id, version, callback) {
+ var type = osmEntity.id.type(id);
+ var osmID = osmEntity.id.toOSM(id);
+ var options = { skipSeen: false };
+
+ this.loadFromAPI(
+ '/api/0.6/' + type + '/' + osmID + '/' + version + '.json',
+ function(err, entities) {
+ if (callback) callback(err, { data: entities });
+ },
+ options
+ );
+ },
+
+
+ // Load multiple entities in chunks
+ // (note: callback may be called multiple times)
+ // Unlike `loadEntity`, child nodes and members are not fetched
+ // GET /api/0.6/[nodes|ways|relations]?#parameters
+ loadMultiple: function(ids, callback) {
+ var that = this;
+ var groups = utilArrayGroupBy(utilArrayUniq(ids), osmEntity.id.type);
+
+ Object.keys(groups).forEach(function(k) {
+ var type = k + 's'; // nodes, ways, relations
+ var osmIDs = groups[k].map(function(id) { return osmEntity.id.toOSM(id); });
+ var options = { skipSeen: false };
+
+ utilArrayChunk(osmIDs, 150).forEach(function(arr) {
+ that.loadFromAPI(
+ '/api/0.6/' + type + '.json?' + type + '=' + arr.join(),
+ function(err, entities) {
+ if (callback) callback(err, { data: entities });
+ },
+ options
+ );
+ });
+ });
+ },
+
+
+ // Create, upload, and close a changeset
+ // PUT /api/0.6/changeset/create
+ // POST /api/0.6/changeset/#id/upload
+ // PUT /api/0.6/changeset/#id/close
+ putChangeset: function(changeset, changes, callback) {
+ var cid = _connectionID;
+
+ if (_changeset.inflight) {
+ return callback({ message: 'Changeset already inflight', status: -2 }, changeset);
+
+ } else if (_changeset.open) { // reuse existing open changeset..
+ return createdChangeset.call(this, null, _changeset.open);
+
+ } else { // Open a new changeset..
+ var options = {
+ method: 'PUT',
+ path: '/api/0.6/changeset/create',
+ options: { header: { 'Content-Type': 'text/xml' } },
+ content: JXON.stringify(changeset.asJXON())
+ };
+ _changeset.inflight = oauth.xhr(
+ options,
+ wrapcb(this, createdChangeset, cid)
+ );
+ }
+
+
+ function createdChangeset(err, changesetID) {
+ _changeset.inflight = null;
+ if (err) { return callback(err, changeset); }
+
+ _changeset.open = changesetID;
+ changeset = changeset.update({ id: changesetID });
+
+ // Upload the changeset..
+ var options = {
+ method: 'POST',
+ path: '/api/0.6/changeset/' + changesetID + '/upload',
+ options: { header: { 'Content-Type': 'text/xml' } },
+ content: JXON.stringify(changeset.osmChangeJXON(changes))
+ };
+ _changeset.inflight = oauth.xhr(
+ options,
+ wrapcb(this, uploadedChangeset, cid)
+ );
+ }
+
+
+ function uploadedChangeset(err) {
+ _changeset.inflight = null;
+ if (err) return callback(err, changeset);
+
+ // Upload was successful, safe to call the callback.
+ // Add delay to allow for postgres replication #1646 #2678
+ window.setTimeout(function() { callback(null, changeset); }, 2500);
+ _changeset.open = null;
+
+ // At this point, we don't really care if the connection was switched..
+ // Only try to close the changeset if we're still talking to the same server.
+ if (this.getConnectionId() === cid) {
+ // Still attempt to close changeset, but ignore response because #2667
+ oauth.xhr({
+ method: 'PUT',
+ path: '/api/0.6/changeset/' + changeset.id + '/close',
+ options: { header: { 'Content-Type': 'text/xml' } }
+ }, function() { return true; });
+ }
+ }
+ },
+
+
+ // Load multiple users in chunks
+ // (note: callback may be called multiple times)
+ // GET /api/0.6/users?users=#id1,#id2,...,#idn
+ loadUsers: function(uids, callback) {
+ var toLoad = [];
+ var cached = [];
+
+ utilArrayUniq(uids).forEach(function(uid) {
+ if (_userCache.user[uid]) {
+ delete _userCache.toLoad[uid];
+ cached.push(_userCache.user[uid]);
+ } else {
+ toLoad.push(uid);
+ }
+ });
+
+ if (cached.length || !this.authenticated()) {
+ callback(undefined, cached);
+ if (!this.authenticated()) return; // require auth
+ }
+
+ utilArrayChunk(toLoad, 150).forEach(function(arr) {
+ oauth.xhr(
+ { method: 'GET', path: '/api/0.6/users?users=' + arr.join() },
+ wrapcb(this, done, _connectionID)
+ );
+ }.bind(this));
+
+ function done(err, xml) {
+ if (err) { return callback(err); }
+
+ var options = { skipSeen: true };
+ return parseXML$1(xml, function(err, results) {
+ if (err) {
+ return callback(err);
+ } else {
+ return callback(undefined, results);
+ }
+ }, options);
+ }
+ },
+
+
+ // Load a given user by id
+ // GET /api/0.6/user/#id
+ loadUser: function(uid, callback) {
+ if (_userCache.user[uid] || !this.authenticated()) { // require auth
+ delete _userCache.toLoad[uid];
+ return callback(undefined, _userCache.user[uid]);
+ }
+
+ oauth.xhr(
+ { method: 'GET', path: '/api/0.6/user/' + uid },
+ wrapcb(this, done, _connectionID)
+ );
+
+ function done(err, xml) {
+ if (err) { return callback(err); }
+
+ var options = { skipSeen: true };
+ return parseXML$1(xml, function(err, results) {
+ if (err) {
+ return callback(err);
+ } else {
+ return callback(undefined, results[0]);
+ }
+ }, options);
+ }
+ },
+
+
+ // Load the details of the logged-in user
+ // GET /api/0.6/user/details
+ userDetails: function(callback) {
+ if (_userDetails) { // retrieve cached
+ return callback(undefined, _userDetails);
+ }
+
+ oauth.xhr(
+ { method: 'GET', path: '/api/0.6/user/details' },
+ wrapcb(this, done, _connectionID)
+ );
+
+ function done(err, xml) {
+ if (err) { return callback(err); }
+
+ var options = { skipSeen: false };
+ return parseXML$1(xml, function(err, results) {
+ if (err) {
+ return callback(err);
+ } else {
+ _userDetails = results[0];
+ return callback(undefined, _userDetails);
+ }
+ }, options);
+ }
+ },
+
+
+ // Load previous changesets for the logged in user
+ // GET /api/0.6/changesets?user=#id
+ userChangesets: function(callback) {
+ if (_userChangesets) { // retrieve cached
+ return callback(undefined, _userChangesets);
+ }
+
+ this.userDetails(
+ wrapcb(this, gotDetails, _connectionID)
+ );
+
+
+ function gotDetails(err, user) {
+ if (err) { return callback(err); }
+
+ oauth.xhr(
+ { method: 'GET', path: '/api/0.6/changesets?user=' + user.id },
+ wrapcb(this, done, _connectionID)
+ );
+ }
+
+ function done(err, xml) {
+ if (err) { return callback(err); }
+
+ _userChangesets = Array.prototype.map.call(
+ xml.getElementsByTagName('changeset'),
+ function (changeset) { return { tags: getTags$1(changeset) }; }
+ ).filter(function (changeset) {
+ var comment = changeset.tags.comment;
+ return comment && comment !== '';
+ });
+
+ return callback(undefined, _userChangesets);
+ }
+ },
+
+
+ // Fetch the status of the OSM API
+ // GET /api/capabilities
+ status: function(callback) {
+ var url = urlroot + '/api/capabilities';
+ var errback = wrapcb(this, done, _connectionID);
+ d3_xml(url, { credentials: credentialsMode })
+ .then(function(data) { errback(null, data); })
+ .catch(function(err) { errback(err.message); });
+
+ function done(err, xml) {
+ if (err) {
+ // the status is null if no response could be retrieved
+ return callback(err, null);
+ }
+
+ // update blacklists
+ var elements = xml.getElementsByTagName('blacklist');
+ var regexes = [];
+ for (var i = 0; i < elements.length; i++) {
+ var regex = elements[i].getAttribute('regex'); // needs unencode?
+ if (regex) {
+ regexes.push(regex);
+ }
+ }
+ if (regexes.length) {
+ _blacklists = regexes;
+ }
+
+ if (_rateLimitError) {
+ return callback(_rateLimitError, 'rateLimited');
+ } else {
+ var waynodes = xml.getElementsByTagName('waynodes');
+ var maxWayNodes = waynodes.length && parseInt(waynodes[0].getAttribute('maximum'), 10);
+ if (maxWayNodes && isFinite(maxWayNodes)) _maxWayNodes = maxWayNodes;
+
+ var apiStatus = xml.getElementsByTagName('status');
+ var val = apiStatus[0].getAttribute('api');
+ return callback(undefined, val);
+ }
+ }
+ },
+
+ // Calls `status` and dispatches an `apiStatusChange` event if the returned
+ // status differs from the cached status.
+ reloadApiStatus: function() {
+ // throttle to avoid unncessary API calls
+ if (!this.throttledReloadApiStatus) {
+ var that = this;
+ this.throttledReloadApiStatus = throttle(function() {
+ that.status(function(err, status) {
+ if (status !== _cachedApiStatus) {
+ _cachedApiStatus = status;
+ dispatch$8.call('apiStatusChange', that, err, status);
+ }
+ });
+ }, 500);
+ }
+ this.throttledReloadApiStatus();
+ },
+
+
+ // Returns the maximum number of nodes a single way can have
+ maxWayNodes: function() {
+ return _maxWayNodes;
+ },
+
+
+ // Load data (entities) from the API in tiles
+ // GET /api/0.6/map?bbox=
+ loadTiles: function(projection, callback) {
+ if (_off$2) return;
+
+ // determine the needed tiles to cover the view
+ var tiles = tiler$7.zoomExtent([_tileZoom$3, _tileZoom$3]).getTiles(projection);
+
+ // abort inflight requests that are no longer needed
+ var hadRequests = hasInflightRequests(_tileCache);
+ abortUnwantedRequests$3(_tileCache, tiles);
+ if (hadRequests && !hasInflightRequests(_tileCache)) {
+ dispatch$8.call('loaded'); // stop the spinner
+ }
+
+ // issue new requests..
+ tiles.forEach(function(tile) {
+ this.loadTile(tile, callback);
+ }, this);
+ },
+
+
+ // Load a single data tile
+ // GET /api/0.6/map?bbox=
+ loadTile: function(tile, callback) {
+ if (_off$2) return;
+ if (_tileCache.loaded[tile.id] || _tileCache.inflight[tile.id]) return;
+
+ if (!hasInflightRequests(_tileCache)) {
+ dispatch$8.call('loading'); // start the spinner
+ }
+
+ var path = '/api/0.6/map.json?bbox=';
+ var options = { skipSeen: true };
+
+ _tileCache.inflight[tile.id] = this.loadFromAPI(
+ path + tile.extent.toParam(),
+ tileCallback,
+ options
+ );
+
+ function tileCallback(err, parsed) {
+ delete _tileCache.inflight[tile.id];
+ if (!err) {
+ delete _tileCache.toLoad[tile.id];
+ _tileCache.loaded[tile.id] = true;
+ var bbox = tile.extent.bbox();
+ bbox.id = tile.id;
+ _tileCache.rtree.insert(bbox);
+ }
+ if (callback) {
+ callback(err, Object.assign({ data: parsed }, tile));
+ }
+ if (!hasInflightRequests(_tileCache)) {
+ dispatch$8.call('loaded'); // stop the spinner
+ }
+ }
+ },
+
+
+ isDataLoaded: function(loc) {
+ var bbox = { minX: loc[0], minY: loc[1], maxX: loc[0], maxY: loc[1] };
+ return _tileCache.rtree.collides(bbox);
+ },
+
+
+ // load the tile that covers the given `loc`
+ loadTileAtLoc: function(loc, callback) {
+ // Back off if the toLoad queue is filling up.. re #6417
+ // (Currently `loadTileAtLoc` requests are considered low priority - used by operations to
+ // let users safely edit geometries which extend to unloaded tiles. We can drop some.)
+ if (Object.keys(_tileCache.toLoad).length > 50) return;
+
+ var k = geoZoomToScale(_tileZoom$3 + 1);
+ var offset = geoRawMercator().scale(k)(loc);
+ var projection = geoRawMercator().transform({ k: k, x: -offset[0], y: -offset[1] });
+ var tiles = tiler$7.zoomExtent([_tileZoom$3, _tileZoom$3]).getTiles(projection);
+
+ tiles.forEach(function(tile) {
+ if (_tileCache.toLoad[tile.id] || _tileCache.loaded[tile.id] || _tileCache.inflight[tile.id]) return;
+
+ _tileCache.toLoad[tile.id] = true;
+ this.loadTile(tile, callback);
+ }, this);
+ },
+
+
+ // Load notes from the API in tiles
+ // GET /api/0.6/notes?bbox=
+ loadNotes: function(projection, noteOptions) {
+ noteOptions = Object.assign({ limit: 10000, closed: 7 }, noteOptions);
+ if (_off$2) return;
+
+ var that = this;
+ var path = '/api/0.6/notes?limit=' + noteOptions.limit + '&closed=' + noteOptions.closed + '&bbox=';
+ var throttleLoadUsers = throttle(function() {
+ var uids = Object.keys(_userCache.toLoad);
+ if (!uids.length) return;
+ that.loadUsers(uids, function() {}); // eagerly load user details
+ }, 750);
+
+ // determine the needed tiles to cover the view
+ var tiles = tiler$7.zoomExtent([_noteZoom, _noteZoom]).getTiles(projection);
+
+ // abort inflight requests that are no longer needed
+ abortUnwantedRequests$3(_noteCache, tiles);
+
+ // issue new requests..
+ tiles.forEach(function(tile) {
+ if (_noteCache.loaded[tile.id] || _noteCache.inflight[tile.id]) return;
+
+ var options = { skipSeen: false };
+ _noteCache.inflight[tile.id] = that.loadFromAPI(
+ path + tile.extent.toParam(),
+ function(err) {
+ delete _noteCache.inflight[tile.id];
+ if (!err) {
+ _noteCache.loaded[tile.id] = true;
+ }
+ throttleLoadUsers();
+ dispatch$8.call('loadedNotes');
+ },
+ options
+ );
+ });
+ },
+
+
+ // Create a note
+ // POST /api/0.6/notes?params
+ postNoteCreate: function(note, callback) {
+ if (!this.authenticated()) {
+ return callback({ message: 'Not Authenticated', status: -3 }, note);
+ }
+ if (_noteCache.inflightPost[note.id]) {
+ return callback({ message: 'Note update already inflight', status: -2 }, note);
+ }
+
+ if (!note.loc[0] || !note.loc[1] || !note.newComment) return; // location & description required
+
+ var comment = note.newComment;
+ if (note.newCategory && note.newCategory !== 'None') { comment += ' #' + note.newCategory; }
+
+ var path = '/api/0.6/notes?' + utilQsString({ lon: note.loc[0], lat: note.loc[1], text: comment });
+
+ _noteCache.inflightPost[note.id] = oauth.xhr(
+ { method: 'POST', path: path },
+ wrapcb(this, done, _connectionID)
+ );
+
+
+ function done(err, xml) {
+ delete _noteCache.inflightPost[note.id];
+ if (err) { return callback(err); }
+
+ // we get the updated note back, remove from caches and reparse..
+ this.removeNote(note);
+
+ var options = { skipSeen: false };
+ return parseXML$1(xml, function(err, results) {
+ if (err) {
+ return callback(err);
+ } else {
+ return callback(undefined, results[0]);
+ }
+ }, options);
+ }
+ },
+
+
+ // Update a note
+ // POST /api/0.6/notes/#id/comment?text=comment
+ // POST /api/0.6/notes/#id/close?text=comment
+ // POST /api/0.6/notes/#id/reopen?text=comment
+ postNoteUpdate: function(note, newStatus, callback) {
+ if (!this.authenticated()) {
+ return callback({ message: 'Not Authenticated', status: -3 }, note);
+ }
+ if (_noteCache.inflightPost[note.id]) {
+ return callback({ message: 'Note update already inflight', status: -2 }, note);
+ }
+
+ var action;
+ if (note.status !== 'closed' && newStatus === 'closed') {
+ action = 'close';
+ } else if (note.status !== 'open' && newStatus === 'open') {
+ action = 'reopen';
+ } else {
+ action = 'comment';
+ if (!note.newComment) return; // when commenting, comment required
+ }
+
+ var path = '/api/0.6/notes/' + note.id + '/' + action;
+ if (note.newComment) {
+ path += '?' + utilQsString({ text: note.newComment });
+ }
+
+ _noteCache.inflightPost[note.id] = oauth.xhr(
+ { method: 'POST', path: path },
+ wrapcb(this, done, _connectionID)
+ );
+
+
+ function done(err, xml) {
+ delete _noteCache.inflightPost[note.id];
+ if (err) { return callback(err); }
+
+ // we get the updated note back, remove from caches and reparse..
+ this.removeNote(note);
+
+ // update closed note cache - used to populate `closed:note` changeset tag
+ if (action === 'close') {
+ _noteCache.closed[note.id] = true;
+ } else if (action === 'reopen') {
+ delete _noteCache.closed[note.id];
+ }
+
+ var options = { skipSeen: false };
+ return parseXML$1(xml, function(err, results) {
+ if (err) {
+ return callback(err);
+ } else {
+ return callback(undefined, results[0]);
+ }
+ }, options);
+ }
+ },
+
+
+ switch: function(options) {
+ urlroot = options.urlroot;
+
+ oauth.options(Object.assign({
+ url: urlroot,
+ loading: authLoading,
+ done: authDone
+ }, options));
+
+ this.reset();
+ this.userChangesets(function() {}); // eagerly load user details/changesets
+ dispatch$8.call('change');
+ return this;
+ },
+
+
+ toggle: function(val) {
+ _off$2 = !val;
+ return this;
+ },
+
+
+ isChangesetInflight: function() {
+ return !!_changeset.inflight;
+ },
+
+
+ // get/set cached data
+ // This is used to save/restore the state when entering/exiting the walkthrough
+ // Also used for testing purposes.
+ caches: function(obj) {
+ function cloneCache(source) {
+ var target = {};
+ Object.keys(source).forEach(function(k) {
+ if (k === 'rtree') {
+ target.rtree = new RBush().fromJSON(source.rtree.toJSON()); // clone rbush
+ } else if (k === 'note') {
+ target.note = {};
+ Object.keys(source.note).forEach(function(id) {
+ target.note[id] = osmNote(source.note[id]); // copy notes
+ });
+ } else {
+ target[k] = JSON.parse(JSON.stringify(source[k])); // clone deep
+ }
+ });
+ return target;
+ }
+
+ if (!arguments.length) {
+ return {
+ tile: cloneCache(_tileCache),
+ note: cloneCache(_noteCache),
+ user: cloneCache(_userCache)
+ };
+ }
+
+ // access caches directly for testing (e.g., loading notes rtree)
+ if (obj === 'get') {
+ return {
+ tile: _tileCache,
+ note: _noteCache,
+ user: _userCache
+ };
+ }
+
+ if (obj.tile) {
+ _tileCache = obj.tile;
+ _tileCache.inflight = {};
+ }
+ if (obj.note) {
+ _noteCache = obj.note;
+ _noteCache.inflight = {};
+ _noteCache.inflightPost = {};
+ }
+ if (obj.user) {
+ _userCache = obj.user;
+ }
+
+ return this;
+ },
+
+
+ logout: function() {
+ _userChangesets = undefined;
+ _userDetails = undefined;
+ oauth.logout();
+ dispatch$8.call('change');
+ return this;
+ },
+
+
+ authenticated: function() {
+ return oauth.authenticated();
+ },
+
+
+ authenticate: function(callback) {
+ var that = this;
+ var cid = _connectionID;
+ _userChangesets = undefined;
+ _userDetails = undefined;
+
+ function done(err, res) {
+ if (err) {
+ if (callback) callback(err);
+ return;
+ }
+ if (that.getConnectionId() !== cid) {
+ if (callback) callback({ message: 'Connection Switched', status: -1 });
+ return;
+ }
+ _rateLimitError = undefined;
+ dispatch$8.call('change');
+ if (callback) callback(err, res);
+ that.userChangesets(function() {}); // eagerly load user details/changesets
+ }
+
+ return oauth.authenticate(done);
+ },
+
+
+ imageryBlacklists: function() {
+ return _blacklists;
+ },
+
+
+ tileZoom: function(val) {
+ if (!arguments.length) return _tileZoom$3;
+ _tileZoom$3 = val;
+ return this;
+ },
+
+
+ // get all cached notes covering the viewport
+ notes: function(projection) {
+ var viewport = projection.clipExtent();
+ var min = [viewport[0][0], viewport[1][1]];
+ var max = [viewport[1][0], viewport[0][1]];
+ var bbox = geoExtent(projection.invert(min), projection.invert(max)).bbox();
+
+ return _noteCache.rtree.search(bbox)
+ .map(function(d) { return d.data; });
+ },
+
+
+ // get a single note from the cache
+ getNote: function(id) {
+ return _noteCache.note[id];
+ },
+
+
+ // remove a single note from the cache
+ removeNote: function(note) {
+ if (!(note instanceof osmNote) || !note.id) return;
+
+ delete _noteCache.note[note.id];
+ updateRtree$3(encodeNoteRtree(note), false); // false = remove
+ },
+
+
+ // replace a single note in the cache
+ replaceNote: function(note) {
+ if (!(note instanceof osmNote) || !note.id) return;
+
+ _noteCache.note[note.id] = note;
+ updateRtree$3(encodeNoteRtree(note), true); // true = replace
+ return note;
+ },
+
+
+ // Get an array of note IDs closed during this session.
+ // Used to populate `closed:note` changeset tag
+ getClosedIDs: function() {
+ return Object.keys(_noteCache.closed).sort();
+ }
+
+ };
+
+ var apibase$3 = 'https://wiki.openstreetmap.org/w/api.php';
+ var _inflight$1 = {};
+ var _wikibaseCache = {};
+ var _localeIDs = { en: false };
+
+
+ var debouncedRequest = debounce(request, 500, { leading: false });
+
+ function request(url, callback) {
+ if (_inflight$1[url]) return;
+ var controller = new AbortController();
+ _inflight$1[url] = controller;
+
+ d3_json(url, { signal: controller.signal })
+ .then(function(result) {
+ delete _inflight$1[url];
+ if (callback) callback(null, result);
+ })
+ .catch(function(err) {
+ delete _inflight$1[url];
+ if (err.name === 'AbortError') return;
+ if (callback) callback(err.message);
+ });
+ }
+
+
+ /**
+ * Get the best string value from the descriptions/labels result
+ * Note that if mediawiki doesn't recognize language code, it will return all values.
+ * In that case, fallback to use English.
+ * @param values object - either descriptions or labels
+ * @param langCode String
+ * @returns localized string
+ */
+ function localizedToString(values, langCode) {
+ if (values) {
+ values = values[langCode] || values.en;
+ }
+ return values ? values.value : '';
+ }
+
+
+ var serviceOsmWikibase = {
+
+ init: function() {
+ _inflight$1 = {};
+ _wikibaseCache = {};
+ _localeIDs = {};
+ },
+
+
+ reset: function() {
+ Object.values(_inflight$1).forEach(function(controller) { controller.abort(); });
+ _inflight$1 = {};
+ },
+
+
+ /**
+ * Get the best value for the property, or undefined if not found
+ * @param entity object from wikibase
+ * @param property string e.g. 'P4' for image
+ * @param langCode string e.g. 'fr' for French
+ */
+ claimToValue: function(entity, property, langCode) {
+ if (!entity.claims[property]) return undefined;
+ var locale = _localeIDs[langCode];
+ var preferredPick, localePick;
+
+ entity.claims[property].forEach(function(stmt) {
+ // If exists, use value limited to the needed language (has a qualifier P26 = locale)
+ // Or if not found, use the first value with the "preferred" rank
+ if (!preferredPick && stmt.rank === 'preferred') {
+ preferredPick = stmt;
+ }
+ if (locale && stmt.qualifiers && stmt.qualifiers.P26 &&
+ stmt.qualifiers.P26[0].datavalue.value.id === locale
+ ) {
+ localePick = stmt;
+ }
+ });
+
+ var result = localePick || preferredPick;
+ if (result) {
+ var datavalue = result.mainsnak.datavalue;
+ return datavalue.type === 'wikibase-entityid' ? datavalue.value.id : datavalue.value;
+ } else {
+ return undefined;
+ }
+ },
+
+
+ /**
+ * Convert monolingual property into a key-value object (language -> value)
+ * @param entity object from wikibase
+ * @param property string e.g. 'P31' for monolingual wiki page title
+ */
+ monolingualClaimToValueObj: function(entity, property) {
+ if (!entity || !entity.claims[property]) return undefined;
+
+ return entity.claims[property].reduce(function(acc, obj) {
+ var value = obj.mainsnak.datavalue.value;
+ acc[value.language] = value.text;
+ return acc;
+ }, {});
+ },
+
+
+ toSitelink: function(key, value) {
+ var result = value ? ('Tag:' + key + '=' + value) : 'Key:' + key;
+ return result.replace(/_/g, ' ').trim();
+ },
+
+
+ //
+ // Pass params object of the form:
+ // {
+ // key: 'string',
+ // value: 'string',
+ // rtype: 'string',
+ // langCode: 'string'
+ // }
+ //
+ getEntity: function(params, callback) {
+ var doRequest = params.debounce ? debouncedRequest : request;
+ var that = this;
+ var titles = [];
+ var result = {};
+ var rtypeSitelink = params.rtype ? ('Relation:' + params.rtype).replace(/_/g, ' ').trim() : false;
+ var keySitelink = params.key ? this.toSitelink(params.key) : false;
+ var tagSitelink = (params.key && params.value) ? this.toSitelink(params.key, params.value) : false;
+ var localeSitelink;
+
+ if (params.langCode && _localeIDs[params.langCode] === undefined) {
+ // If this is the first time we are asking about this locale,
+ // fetch corresponding entity (if it exists), and cache it.
+ // If there is no such entry, cache `false` value to avoid re-requesting it.
+ localeSitelink = ('Locale:' + params.langCode).replace(/_/g, ' ').trim();
+ titles.push(localeSitelink);
+ }
+
+ if (rtypeSitelink) {
+ if (_wikibaseCache[rtypeSitelink]) {
+ result.rtype = _wikibaseCache[rtypeSitelink];
+ } else {
+ titles.push(rtypeSitelink);
+ }
+ }
+
+ if (keySitelink) {
+ if (_wikibaseCache[keySitelink]) {
+ result.key = _wikibaseCache[keySitelink];
+ } else {
+ titles.push(keySitelink);
+ }
+ }
+
+ if (tagSitelink) {
+ if (_wikibaseCache[tagSitelink]) {
+ result.tag = _wikibaseCache[tagSitelink];
+ } else {
+ titles.push(tagSitelink);
+ }
+ }
+
+ if (!titles.length) {
+ // Nothing to do, we already had everything in the cache
+ return callback(null, result);
+ }
+
+ // Requesting just the user language code
+ // If backend recognizes the code, it will perform proper fallbacks,
+ // and the result will contain the requested code. If not, all values are returned:
+ // {"zh-tw":{"value":"...","language":"zh-tw","source-language":"zh-hant"}
+ // {"pt-br":{"value":"...","language":"pt","for-language":"pt-br"}}
+ var obj = {
+ action: 'wbgetentities',
+ sites: 'wiki',
+ titles: titles.join('|'),
+ languages: params.langCode,
+ languagefallback: 1,
+ origin: '*',
+ format: 'json',
+ // There is an MW Wikibase API bug https://phabricator.wikimedia.org/T212069
+ // We shouldn't use v1 until it gets fixed, but should switch to it afterwards
+ // formatversion: 2,
+ };
+
+ var url = apibase$3 + '?' + utilQsString(obj);
+ doRequest(url, function(err, d) {
+ if (err) {
+ callback(err);
+ } else if (!d.success || d.error) {
+ callback(d.error.messages.map(function(v) { return v.html['*']; }).join(' '));
+ } else {
+ var localeID = false;
+ Object.values(d.entities).forEach(function(res) {
+ if (res.missing !== '') {
+ // Simplify access to the localized values
+ res.description = localizedToString(res.descriptions, params.langCode);
+ res.label = localizedToString(res.labels, params.langCode);
+
+ var title = res.sitelinks.wiki.title;
+ if (title === rtypeSitelink) {
+ _wikibaseCache[rtypeSitelink] = res;
+ result.rtype = res;
+ } else if (title === keySitelink) {
+ _wikibaseCache[keySitelink] = res;
+ result.key = res;
+ } else if (title === tagSitelink) {
+ _wikibaseCache[tagSitelink] = res;
+ result.tag = res;
+ } else if (title === localeSitelink) {
+ localeID = res.id;
+ } else {
+ console.log('Unexpected title ' + title); // eslint-disable-line no-console
+ }
+ }
+ });
+
+ if (localeSitelink) {
+ // If locale ID is not found, store false to prevent repeated queries
+ that.addLocale(params.langCode, localeID);
+ }
+
+ callback(null, result);
+ }
+ });
+ },
+
+
+ //
+ // Pass params object of the form:
+ // {
+ // key: 'string', // required
+ // value: 'string' // optional
+ // }
+ // -or-
+ // {
+ // rtype: 'rtype' // relation type (e.g. 'multipolygon')
+ // }
+ //
+ // Get an result object used to display tag documentation
+ // {
+ // title: 'string',
+ // description: 'string',
+ // editURL: 'string',
+ // imageURL: 'string',
+ // wiki: { title: 'string', text: 'string', url: 'string' }
+ // }
+ //
+ getDocs: function(params, callback) {
+ var that = this;
+ var langCode = _mainLocalizer.localeCode().toLowerCase();
+ params.langCode = langCode;
+
+ this.getEntity(params, function(err, data) {
+ if (err) {
+ callback(err);
+ return;
+ }
+
+ var entity = data.rtype || data.tag || data.key;
+ if (!entity) {
+ callback('No entity');
+ return;
+ }
+
+ // prepare result
+ var result = {
+ title: entity.title,
+ description: entity.description,
+ editURL: 'https://wiki.openstreetmap.org/wiki/' + entity.title
+ };
+
+ // add image
+ if (entity.claims) {
+ var imageroot;
+ var image = that.claimToValue(entity, 'P4', langCode);
+ if (image) {
+ imageroot = 'https://commons.wikimedia.org/w/index.php';
+ } else {
+ image = that.claimToValue(entity, 'P28', langCode);
+ if (image) {
+ imageroot = 'https://wiki.openstreetmap.org/w/index.php';
+ }
+ }
+ if (imageroot && image) {
+ result.imageURL = imageroot + '?' + utilQsString({
+ title: 'Special:Redirect/file/' + image,
+ width: 400
+ });
+ }
+ }
+
+ // Try to get a wiki page from tag data item first, followed by the corresponding key data item.
+ // If neither tag nor key data item contain a wiki page in the needed language nor English,
+ // get the first found wiki page from either the tag or the key item.
+ var rtypeWiki = that.monolingualClaimToValueObj(data.rtype, 'P31');
+ var tagWiki = that.monolingualClaimToValueObj(data.tag, 'P31');
+ var keyWiki = that.monolingualClaimToValueObj(data.key, 'P31');
+
+ // If exact language code does not exist, try to find the first part before the '-'
+ // BUG: in some cases, a more elaborate fallback logic might be needed
+ var langPrefix = langCode.split('-', 2)[0];
+
+ // use the first acceptable wiki page
+ result.wiki =
+ getWikiInfo(rtypeWiki, langCode, 'inspector.wiki_reference') ||
+ getWikiInfo(rtypeWiki, langPrefix, 'inspector.wiki_reference') ||
+ getWikiInfo(rtypeWiki, 'en', 'inspector.wiki_en_reference') ||
+ getWikiInfo(tagWiki, langCode, 'inspector.wiki_reference') ||
+ getWikiInfo(tagWiki, langPrefix, 'inspector.wiki_reference') ||
+ getWikiInfo(tagWiki, 'en', 'inspector.wiki_en_reference') ||
+ getWikiInfo(keyWiki, langCode, 'inspector.wiki_reference') ||
+ getWikiInfo(keyWiki, langPrefix, 'inspector.wiki_reference') ||
+ getWikiInfo(keyWiki, 'en', 'inspector.wiki_en_reference');
+
+ callback(null, result);
+
+
+ // Helper method to get wiki info if a given language exists
+ function getWikiInfo(wiki, langCode, tKey) {
+ if (wiki && wiki[langCode]) {
+ return {
+ title: wiki[langCode],
+ text: tKey,
+ url: 'https://wiki.openstreetmap.org/wiki/' + wiki[langCode]
+ };
+ }
+ }
+ });
+ },
+
+
+ addLocale: function(langCode, qid) {
+ // Makes it easier to unit test
+ _localeIDs[langCode] = qid;
+ },
+
+
+ apibase: function(val) {
+ if (!arguments.length) return apibase$3;
+ apibase$3 = val;
+ return this;
+ }
+
+ };
+
+ var jsonpCache = {};
+ window.jsonpCache = jsonpCache;
+
+ function jsonpRequest(url, callback) {
+ var request = {
+ abort: function() {}
+ };
+
+ if (window.JSONP_FIX) {
+ if (window.JSONP_DELAY === 0) {
+ callback(window.JSONP_FIX);
+ } else {
+ var t = window.setTimeout(function() {
+ callback(window.JSONP_FIX);
+ }, window.JSONP_DELAY || 0);
+
+ request.abort = function() { window.clearTimeout(t); };
+ }
+
+ return request;
+ }
+
+ function rand() {
+ var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
+ var c = '';
+ var i = -1;
+ while (++i < 15) c += chars.charAt(Math.floor(Math.random() * 52));
+ return c;
+ }
+
+ function create(url) {
+ var e = url.match(/callback=(\w+)/);
+ var c = e ? e[1] : rand();
+
+ jsonpCache[c] = function(data) {
+ if (jsonpCache[c]) {
+ callback(data);
+ }
+ finalize();
+ };
+
+ function finalize() {
+ delete jsonpCache[c];
+ script.remove();
+ }
+
+ request.abort = finalize;
+ return 'jsonpCache.' + c;
+ }
+
+ var cb = create(url);
+
+ var script = select('head')
+ .append('script')
+ .attr('type', 'text/javascript')
+ .attr('src', url.replace(/(\{|%7B)callback(\}|%7D)/, cb));
+
+ return request;
+ }
+
+ const bubbleApi = 'https://dev.virtualearth.net/mapcontrol/HumanScaleServices/GetBubbles.ashx?';
+ const streetsideImagesApi = 'https://t.ssl.ak.tiles.virtualearth.net/tiles/';
+ const bubbleAppKey = 'AuftgJsO0Xs8Ts4M1xZUQJQXJNsvmh3IV8DkNieCiy3tCwCUMq76-WpkrBtNAuEm';
+ const pannellumViewerCSS = 'pannellum-streetside/pannellum.css';
+ const pannellumViewerJS = 'pannellum-streetside/pannellum.js';
+ const maxResults$2 = 2000;
+ const tileZoom$2 = 16.5;
+ const tiler$8 = utilTiler().zoomExtent([tileZoom$2, tileZoom$2]).skipNullIsland(true);
+ const dispatch$9 = dispatch('loadedBubbles', 'viewerChanged');
+ const minHfov = 10; // zoom in degrees: 20, 10, 5
+ const maxHfov = 90; // zoom out degrees
+ const defaultHfov = 45;
+
+ let _hires = false;
+ let _resolution = 512; // higher numbers are slower - 512, 1024, 2048, 4096
+ let _currScene = 0;
+ let _ssCache;
+ let _pannellumViewer;
+ let _sceneOptions;
+ let _dataUrlArray = [];
+
+
+ /**
+ * abortRequest().
+ */
+ function abortRequest$8(i) {
+ i.abort();
+ }
+
+
+ /**
+ * localeTimeStamp().
+ */
+ function localeTimestamp(s) {
+ if (!s) return null;
+ const options = { day: 'numeric', month: 'short', year: 'numeric' };
+ const d = new Date(s);
+ if (isNaN(d.getTime())) return null;
+ return d.toLocaleString(_mainLocalizer.localeCode(), options);
+ }
+
+
+ /**
+ * loadTiles() wraps the process of generating tiles and then fetching image points for each tile.
+ */
+ function loadTiles$2(which, url, projection, margin) {
+ const tiles = tiler$8.margin(margin).getTiles(projection);
+
+ // abort inflight requests that are no longer needed
+ const cache = _ssCache[which];
+ Object.keys(cache.inflight).forEach(k => {
+ const wanted = tiles.find(tile => k.indexOf(tile.id + ',') === 0);
+ if (!wanted) {
+ abortRequest$8(cache.inflight[k]);
+ delete cache.inflight[k];
+ }
+ });
+
+ tiles.forEach(tile => loadNextTilePage$2(which, url, tile));
+ }
+
+
+ /**
+ * loadNextTilePage() load data for the next tile page in line.
+ */
+ function loadNextTilePage$2(which, url, tile) {
+ const cache = _ssCache[which];
+ const nextPage = cache.nextPage[tile.id] || 0;
+ const id = tile.id + ',' + String(nextPage);
+ if (cache.loaded[id] || cache.inflight[id]) return;
+
+ cache.inflight[id] = getBubbles(url, tile, (bubbles) => {
+ cache.loaded[id] = true;
+ delete cache.inflight[id];
+ if (!bubbles) return;
+
+ // [].shift() removes the first element, some statistics info, not a bubble point
+ bubbles.shift();
+
+ const features = bubbles.map(bubble => {
+ if (cache.points[bubble.id]) return null; // skip duplicates
+
+ const loc = [bubble.lo, bubble.la];
+ const d = {
+ loc: loc,
+ key: bubble.id,
+ ca: bubble.he,
+ captured_at: bubble.cd,
+ captured_by: 'microsoft',
+ // nbn: bubble.nbn,
+ // pbn: bubble.pbn,
+ // ad: bubble.ad,
+ // rn: bubble.rn,
+ pr: bubble.pr, // previous
+ ne: bubble.ne, // next
+ pano: true,
+ sequenceKey: null
+ };
+
+ cache.points[bubble.id] = d;
+
+ // a sequence starts here
+ if (bubble.pr === undefined) {
+ cache.leaders.push(bubble.id);
+ }
+
+ return {
+ minX: loc[0], minY: loc[1], maxX: loc[0], maxY: loc[1], data: d
+ };
+
+ }).filter(Boolean);
+
+ cache.rtree.load(features);
+
+ connectSequences();
+
+ if (which === 'bubbles') {
+ dispatch$9.call('loadedBubbles');
+ }
+ });
+ }
+
+
+ // call this sometimes to connect the bubbles into sequences
+ function connectSequences() {
+ let cache = _ssCache.bubbles;
+ let keepLeaders = [];
+
+ for (let i = 0; i < cache.leaders.length; i++) {
+ let bubble = cache.points[cache.leaders[i]];
+ let seen = {};
+
+ // try to make a sequence.. use the key of the leader bubble.
+ let sequence = { key: bubble.key, bubbles: [] };
+ let complete = false;
+
+ do {
+ sequence.bubbles.push(bubble);
+ seen[bubble.key] = true;
+
+ if (bubble.ne === undefined) {
+ complete = true;
+ } else {
+ bubble = cache.points[bubble.ne]; // advance to next
+ }
+ } while (bubble && !seen[bubble.key] && !complete);
+
+
+ if (complete) {
+ _ssCache.sequences[sequence.key] = sequence;
+
+ // assign bubbles to the sequence
+ for (let j = 0; j < sequence.bubbles.length; j++) {
+ sequence.bubbles[j].sequenceKey = sequence.key;
+ }
+
+ // create a GeoJSON LineString
+ sequence.geojson = {
+ type: 'LineString',
+ properties: { key: sequence.key },
+ coordinates: sequence.bubbles.map(d => d.loc)
+ };
+
+ } else {
+ keepLeaders.push(cache.leaders[i]);
+ }
+ }
+
+ // couldn't complete these, save for later
+ cache.leaders = keepLeaders;
+ }
+
+
+ /**
+ * getBubbles() handles the request to the server for a tile extent of 'bubbles' (streetside image locations).
+ */
+ function getBubbles(url, tile, callback) {
+ let rect = tile.extent.rectangle();
+ let urlForRequest = url + utilQsString({
+ n: rect[3],
+ s: rect[1],
+ e: rect[2],
+ w: rect[0],
+ c: maxResults$2,
+ appkey: bubbleAppKey,
+ jsCallback: '{callback}'
+ });
+
+ return jsonpRequest(urlForRequest, (data) => {
+ if (!data || data.error) {
+ callback(null);
+ } else {
+ callback(data);
+ }
+ });
+ }
+
+
+ // partition viewport into higher zoom tiles
+ function partitionViewport$2(projection) {
+ let z = geoScaleToZoom(projection.scale());
+ let z2 = (Math.ceil(z * 2) / 2) + 2.5; // round to next 0.5 and add 2.5
+ let tiler = utilTiler().zoomExtent([z2, z2]);
+
+ return tiler.getTiles(projection)
+ .map(tile => tile.extent);
+ }
+
+
+ // no more than `limit` results per partition.
+ function searchLimited$2(limit, projection, rtree) {
+ limit = limit || 5;
+
+ return partitionViewport$2(projection)
+ .reduce((result, extent) => {
+ let found = rtree.search(extent.bbox())
+ .slice(0, limit)
+ .map(d => d.data);
+
+ return (found.length ? result.concat(found) : result);
+ }, []);
+ }
+
+
+ /**
+ * loadImage()
+ */
+ function loadImage(imgInfo) {
+ return new Promise(resolve => {
+ let img = new Image();
+ img.onload = () => {
+ let canvas = document.getElementById('ideditor-canvas' + imgInfo.face);
+ let ctx = canvas.getContext('2d');
+ ctx.drawImage(img, imgInfo.x, imgInfo.y);
+ resolve({ imgInfo: imgInfo, status: 'ok' });
+ };
+ img.onerror = () => {
+ resolve({ data: imgInfo, status: 'error' });
+ };
+ img.setAttribute('crossorigin', '');
+ img.src = imgInfo.url;
+ });
+ }
+
+
+ /**
+ * loadCanvas()
+ */
+ function loadCanvas(imageGroup) {
+ return Promise.all(imageGroup.map(loadImage))
+ .then((data) => {
+ let canvas = document.getElementById('ideditor-canvas' + data[0].imgInfo.face);
+ const which = { '01': 0, '02': 1, '03': 2, '10': 3, '11': 4, '12': 5 };
+ let face = data[0].imgInfo.face;
+ _dataUrlArray[which[face]] = canvas.toDataURL('image/jpeg', 1.0);
+ return { status: 'loadCanvas for face ' + data[0].imgInfo.face + 'ok'};
+ });
+ }
+
+
+ /**
+ * loadFaces()
+ */
+ function loadFaces(faceGroup) {
+ return Promise.all(faceGroup.map(loadCanvas))
+ .then(() => { return { status: 'loadFaces done' }; });
+ }
+
+
+ function setupCanvas(selection, reset) {
+ if (reset) {
+ selection.selectAll('#ideditor-stitcher-canvases')
+ .remove();
+ }
+
+ // Add the Streetside working canvases. These are used for 'stitching', or combining,
+ // multiple images for each of the six faces, before passing to the Pannellum control as DataUrls
+ selection.selectAll('#ideditor-stitcher-canvases')
+ .data([0])
+ .enter()
+ .append('div')
+ .attr('id', 'ideditor-stitcher-canvases')
+ .attr('display', 'none')
+ .selectAll('canvas')
+ .data(['canvas01', 'canvas02', 'canvas03', 'canvas10', 'canvas11', 'canvas12'])
+ .enter()
+ .append('canvas')
+ .attr('id', d => 'ideditor-' + d)
+ .attr('width', _resolution)
+ .attr('height', _resolution);
+ }
+
+
+ function qkToXY(qk) {
+ let x = 0;
+ let y = 0;
+ let scale = 256;
+ for (let i = qk.length; i > 0; i--) {
+ const key = qk[i-1];
+ x += (+(key === '1' || key === '3')) * scale;
+ y += (+(key === '2' || key === '3')) * scale;
+ scale *= 2;
+ }
+ return [x, y];
+ }
+
+
+ function getQuadKeys() {
+ let dim = _resolution / 256;
+ let quadKeys;
+
+ if (dim === 16) {
+ quadKeys = [
+ '0000','0001','0010','0011','0100','0101','0110','0111', '1000','1001','1010','1011','1100','1101','1110','1111',
+ '0002','0003','0012','0013','0102','0103','0112','0113', '1002','1003','1012','1013','1102','1103','1112','1113',
+ '0020','0021','0030','0031','0120','0121','0130','0131', '1020','1021','1030','1031','1120','1121','1130','1131',
+ '0022','0023','0032','0033','0122','0123','0132','0133', '1022','1023','1032','1033','1122','1123','1132','1133',
+ '0200','0201','0210','0211','0300','0301','0310','0311', '1200','1201','1210','1211','1300','1301','1310','1311',
+ '0202','0203','0212','0213','0302','0303','0312','0313', '1202','1203','1212','1213','1302','1303','1312','1313',
+ '0220','0221','0230','0231','0320','0321','0330','0331', '1220','1221','1230','1231','1320','1321','1330','1331',
+ '0222','0223','0232','0233','0322','0323','0332','0333', '1222','1223','1232','1233','1322','1323','1332','1333',
+
+ '2000','2001','2010','2011','2100','2101','2110','2111', '3000','3001','3010','3011','3100','3101','3110','3111',
+ '2002','2003','2012','2013','2102','2103','2112','2113', '3002','3003','3012','3013','3102','3103','3112','3113',
+ '2020','2021','2030','2031','2120','2121','2130','2131', '3020','3021','3030','3031','3120','3121','3130','3131',
+ '2022','2023','2032','2033','2122','2123','2132','2133', '3022','3023','3032','3033','3122','3123','3132','3133',
+ '2200','2201','2210','2211','2300','2301','2310','2311', '3200','3201','3210','3211','3300','3301','3310','3311',
+ '2202','2203','2212','2213','2302','2303','2312','2313', '3202','3203','3212','3213','3302','3303','3312','3313',
+ '2220','2221','2230','2231','2320','2321','2330','2331', '3220','3221','3230','3231','3320','3321','3330','3331',
+ '2222','2223','2232','2233','2322','2323','2332','2333', '3222','3223','3232','3233','3322','3323','3332','3333'
+ ];
+
+ } else if (dim === 8) {
+ quadKeys = [
+ '000','001','010','011', '100','101','110','111',
+ '002','003','012','013', '102','103','112','113',
+ '020','021','030','031', '120','121','130','131',
+ '022','023','032','033', '122','123','132','133',
+
+ '200','201','210','211', '300','301','310','311',
+ '202','203','212','213', '302','303','312','313',
+ '220','221','230','231', '320','321','330','331',
+ '222','223','232','233', '322','323','332','333'
+ ];
+
+ } else if (dim === 4) {
+ quadKeys = [
+ '00','01', '10','11',
+ '02','03', '12','13',
+
+ '20','21', '30','31',
+ '22','23', '32','33'
+ ];
+
+ } else { // dim === 2
+ quadKeys = [
+ '0', '1',
+ '2', '3'
+ ];
+ }
+
+ return quadKeys;
+ }
+
+
+
+ var serviceStreetside = {
+ /**
+ * init() initialize streetside.
+ */
+ init: function() {
+ if (!_ssCache) {
+ this.reset();
+ }
+
+ this.event = utilRebind(this, dispatch$9, 'on');
+ },
+
+ /**
+ * reset() reset the cache.
+ */
+ reset: function() {
+ if (_ssCache) {
+ Object.values(_ssCache.bubbles.inflight).forEach(abortRequest$8);
+ }
+
+ _ssCache = {
+ bubbles: { inflight: {}, loaded: {}, nextPage: {}, rtree: new RBush(), points: {}, leaders: [] },
+ sequences: {}
+ };
+ },
+
+ /**
+ * bubbles()
+ */
+ bubbles: function(projection) {
+ const limit = 5;
+ return searchLimited$2(limit, projection, _ssCache.bubbles.rtree);
+ },
+
+
+ sequences: function(projection) {
+ const viewport = projection.clipExtent();
+ const min = [viewport[0][0], viewport[1][1]];
+ const max = [viewport[1][0], viewport[0][1]];
+ const bbox = geoExtent(projection.invert(min), projection.invert(max)).bbox();
+ let seen = {};
+ let results = [];
+
+ // all sequences for bubbles in viewport
+ _ssCache.bubbles.rtree.search(bbox)
+ .forEach(d => {
+ const key = d.data.sequenceKey;
+ if (key && !seen[key]) {
+ seen[key] = true;
+ results.push(_ssCache.sequences[key].geojson);
+ }
+ });
+
+ return results;
+ },
+
+
+ /**
+ * loadBubbles()
+ */
+ loadBubbles: function(projection, margin) {
+ // by default: request 2 nearby tiles so we can connect sequences.
+ if (margin === undefined) margin = 2;
+
+ loadTiles$2('bubbles', bubbleApi, projection, margin);
+ },
+
+
+ viewer: function() {
+ return _pannellumViewer;
+ },
+
+
+ initViewer: function () {
+ if (!window.pannellum) return;
+ if (_pannellumViewer) return;
+
+ const sceneID = ++_currScene + '';
+ const options = {
+ 'default': { firstScene: sceneID },
+ scenes: {}
+ };
+ options.scenes[sceneID] = _sceneOptions;
+
+ _pannellumViewer = window.pannellum.viewer('ideditor-viewer-streetside', options);
+ },
+
+
+ /**
+ * loadViewer() create the streeside viewer.
+ */
+ loadViewer: function(context) {
+ let that = this;
+
+ let pointerPrefix = 'PointerEvent' in window ? 'pointer' : 'mouse';
+
+ // create ms-wrapper, a photo wrapper class
+ let wrap = context.container().select('.photoviewer').selectAll('.ms-wrapper')
+ .data([0]);
+
+ // inject ms-wrapper into the photoviewer div
+ // (used by all to house each custom photo viewer)
+ let wrapEnter = wrap.enter()
+ .append('div')
+ .attr('class', 'photo-wrapper ms-wrapper')
+ .classed('hide', true);
+
+ // inject div to support streetside viewer (pannellum) and attribution line
+ wrapEnter
+ .append('div')
+ .attr('id', 'ideditor-viewer-streetside')
+ .on(pointerPrefix + 'down.streetside', () => {
+ select(window)
+ .on(pointerPrefix + 'move.streetside', () => {
+ dispatch$9.call('viewerChanged');
+ }, true);
+ })
+ .on(pointerPrefix + 'up.streetside pointercancel.streetside', () => {
+ select(window)
+ .on(pointerPrefix + 'move.streetside', null);
+
+ // continue dispatching events for a few seconds, in case viewer has inertia.
+ let t = timer(elapsed => {
+ dispatch$9.call('viewerChanged');
+ if (elapsed > 2000) {
+ t.stop();
+ }
+ });
+ })
+ .append('div')
+ .attr('class', 'photo-attribution fillD');
+
+ let controlsEnter = wrapEnter
+ .append('div')
+ .attr('class', 'photo-controls-wrap')
+ .append('div')
+ .attr('class', 'photo-controls');
+
+ controlsEnter
+ .append('button')
+ .on('click.back', step(-1))
+ .text('◄');
+
+ controlsEnter
+ .append('button')
+ .on('click.forward', step(1))
+ .text('►');
+
+
+ // create working canvas for stitching together images
+ wrap = wrap
+ .merge(wrapEnter)
+ .call(setupCanvas, true);
+
+ // load streetside pannellum viewer css
+ select('head').selectAll('#ideditor-streetside-viewercss')
+ .data([0])
+ .enter()
+ .append('link')
+ .attr('id', 'ideditor-streetside-viewercss')
+ .attr('rel', 'stylesheet')
+ .attr('href', context.asset(pannellumViewerCSS));
+
+ // load streetside pannellum viewer js
+ select('head').selectAll('#ideditor-streetside-viewerjs')
+ .data([0])
+ .enter()
+ .append('script')
+ .attr('id', 'ideditor-streetside-viewerjs')
+ .attr('src', context.asset(pannellumViewerJS));
+
+
+ // Register viewer resize handler
+ context.ui().photoviewer.on('resize.streetside', () => {
+ if (_pannellumViewer) {
+ _pannellumViewer.resize();
+ }
+ });
+
+
+ function step(stepBy) {
+ return () => {
+ let viewer = context.container().select('.photoviewer');
+ let selected = viewer.empty() ? undefined : viewer.datum();
+ if (!selected) return;
+
+ let nextID = (stepBy === 1 ? selected.ne : selected.pr);
+ let yaw = _pannellumViewer.getYaw();
+ let ca = selected.ca + yaw;
+ let origin = selected.loc;
+
+ // construct a search trapezoid pointing out from current bubble
+ const meters = 35;
+ let p1 = [
+ origin[0] + geoMetersToLon(meters / 5, origin[1]),
+ origin[1]
+ ];
+ let p2 = [
+ origin[0] + geoMetersToLon(meters / 2, origin[1]),
+ origin[1] + geoMetersToLat(meters)
+ ];
+ let p3 = [
+ origin[0] - geoMetersToLon(meters / 2, origin[1]),
+ origin[1] + geoMetersToLat(meters)
+ ];
+ let p4 = [
+ origin[0] - geoMetersToLon(meters / 5, origin[1]),
+ origin[1]
+ ];
+
+ let poly = [p1, p2, p3, p4, p1];
+
+ // rotate it to face forward/backward
+ let angle = (stepBy === 1 ? ca : ca + 180) * (Math.PI / 180);
+ poly = geoRotate(poly, -angle, origin);
+
+ let extent = poly.reduce((extent, point) => {
+ return extent.extend(geoExtent(point));
+ }, geoExtent());
+
+ // find nearest other bubble in the search polygon
+ let minDist = Infinity;
+ _ssCache.bubbles.rtree.search(extent.bbox())
+ .forEach(d => {
+ if (d.data.key === selected.key) return;
+ if (!geoPointInPolygon(d.data.loc, poly)) return;
+
+ let dist = geoVecLength(d.data.loc, selected.loc);
+ let theta = selected.ca - d.data.ca;
+ let minTheta = Math.min(Math.abs(theta), 360 - Math.abs(theta));
+ if (minTheta > 20) {
+ dist += 5; // penalize distance if camera angles don't match
+ }
+
+ if (dist < minDist) {
+ nextID = d.data.key;
+ minDist = dist;
+ }
+ });
+
+ let nextBubble = nextID && _ssCache.bubbles.points[nextID];
+ if (!nextBubble) return;
+
+ context.map().centerEase(nextBubble.loc);
+
+ that.selectImage(context, nextBubble)
+ .then(response => {
+ if (response.status === 'ok') {
+ _sceneOptions.yaw = yaw;
+ that.showViewer(context);
+ }
+ });
+ };
+ }
+ },
+
+
+ /**
+ * showViewer()
+ */
+ showViewer: function(context, yaw) {
+ if (!_sceneOptions) return;
+
+ if (yaw !== undefined) {
+ _sceneOptions.yaw = yaw;
+ }
+
+ if (!_pannellumViewer) {
+ this.initViewer();
+ } else {
+ // make a new scene
+ let sceneID = ++_currScene + '';
+ _pannellumViewer
+ .addScene(sceneID, _sceneOptions)
+ .loadScene(sceneID);
+
+ // remove previous scene
+ if (_currScene > 2) {
+ sceneID = (_currScene - 1) + '';
+ _pannellumViewer
+ .removeScene(sceneID);
+ }
+ }
+
+ let wrap = context.container().select('.photoviewer')
+ .classed('hide', false);
+
+ let isHidden = wrap.selectAll('.photo-wrapper.ms-wrapper.hide').size();
+
+ if (isHidden) {
+ wrap
+ .selectAll('.photo-wrapper:not(.ms-wrapper)')
+ .classed('hide', true);
+
+ wrap
+ .selectAll('.photo-wrapper.ms-wrapper')
+ .classed('hide', false);
+ }
+
+ return this;
+ },
+
+
+ /**
+ * hideViewer()
+ */
+ hideViewer: function (context) {
+ let viewer = context.container().select('.photoviewer');
+ if (!viewer.empty()) viewer.datum(null);
+
+ viewer
+ .classed('hide', true)
+ .selectAll('.photo-wrapper')
+ .classed('hide', true);
+
+ context.container().selectAll('.viewfield-group, .sequence, .icon-sign')
+ .classed('currentView', false);
+
+ return this.setStyles(context, null, true);
+ },
+
+
+ /**
+ * selectImage().
+ */
+ selectImage: function (context, d) {
+ let that = this;
+ let viewer = context.container().select('.photoviewer');
+ if (!viewer.empty()) viewer.datum(d);
+
+ this.setStyles(context, null, true);
+
+ let wrap = context.container().select('.photoviewer .ms-wrapper');
+ let attribution = wrap.selectAll('.photo-attribution').html('');
+
+ wrap.selectAll('.pnlm-load-box') // display "loading.."
+ .style('display', 'block');
+
+ if (!d) {
+ return Promise.resolve({ status: 'ok' });
+ }
+
+ let line1 = attribution
+ .append('div')
+ .attr('class', 'attribution-row');
+
+ const hiresDomId = utilUniqueDomId('streetside-hires');
+
+ // Add hires checkbox
+ let label = line1
+ .append('label')
+ .attr('for', hiresDomId)
+ .attr('class', 'streetside-hires');
+
+ label
+ .append('input')
+ .attr('type', 'checkbox')
+ .attr('id', hiresDomId)
+ .property('checked', _hires)
+ .on('click', () => {
+ event.stopPropagation();
+
+ _hires = !_hires;
+ _resolution = _hires ? 1024 : 512;
+ wrap.call(setupCanvas, true);
+
+ let viewstate = {
+ yaw: _pannellumViewer.getYaw(),
+ pitch: _pannellumViewer.getPitch(),
+ hfov: _pannellumViewer.getHfov()
+ };
+
+ that.selectImage(context, d)
+ .then(response => {
+ if (response.status === 'ok') {
+ _sceneOptions = Object.assign(_sceneOptions, viewstate);
+ that.showViewer(context);
+ }
+ });
+ });
+
+ label
+ .append('span')
+ .text(_t('streetside.hires'));
+
+
+ let captureInfo = line1
+ .append('div')
+ .attr('class', 'attribution-capture-info');
+
+ // Add capture date
+ if (d.captured_by) {
+ const yyyy = (new Date()).getFullYear();
+
+ captureInfo
+ .append('a')
+ .attr('class', 'captured_by')
+ .attr('target', '_blank')
+ .attr('href', 'https://www.microsoft.com/en-us/maps/streetside')
+ .text('©' + yyyy + ' Microsoft');
+
+ captureInfo
+ .append('span')
+ .text('|');
+ }
+
+ if (d.captured_at) {
+ captureInfo
+ .append('span')
+ .attr('class', 'captured_at')
+ .text(localeTimestamp(d.captured_at));
+ }
+
+ // Add image links
+ let line2 = attribution
+ .append('div')
+ .attr('class', 'attribution-row');
+
+ line2
+ .append('a')
+ .attr('class', 'image-view-link')
+ .attr('target', '_blank')
+ .attr('href', 'https://www.bing.com/maps?cp=' + d.loc[1] + '~' + d.loc[0] +
+ '&lvl=17&dir=' + d.ca + '&style=x&v=2&sV=1')
+ .text(_t('streetside.view_on_bing'));
+
+ line2
+ .append('a')
+ .attr('class', 'image-report-link')
+ .attr('target', '_blank')
+ .attr('href', 'https://www.bing.com/maps/privacyreport/streetsideprivacyreport?bubbleid=' +
+ encodeURIComponent(d.key) + '&focus=photo&lat=' + d.loc[1] + '&lng=' + d.loc[0] + '&z=17')
+ .text(_t('streetside.report'));
+
+
+ let bubbleIdQuadKey = d.key.toString(4);
+ const paddingNeeded = 16 - bubbleIdQuadKey.length;
+ for (let i = 0; i < paddingNeeded; i++) {
+ bubbleIdQuadKey = '0' + bubbleIdQuadKey;
+ }
+ const imgUrlPrefix = streetsideImagesApi + 'hs' + bubbleIdQuadKey;
+ const imgUrlSuffix = '.jpg?g=6338&n=z';
+
+ // Cubemap face code order matters here: front=01, right=02, back=03, left=10, up=11, down=12
+ const faceKeys = ['01','02','03','10','11','12'];
+
+ // Map images to cube faces
+ let quadKeys = getQuadKeys();
+ let faces = faceKeys.map((faceKey) => {
+ return quadKeys.map((quadKey) =>{
+ const xy = qkToXY(quadKey);
+ return {
+ face: faceKey,
+ url: imgUrlPrefix + faceKey + quadKey + imgUrlSuffix,
+ x: xy[0],
+ y: xy[1]
+ };
+ });
+ });
+
+ return loadFaces(faces)
+ .then(() => {
+ _sceneOptions = {
+ showFullscreenCtrl: false,
+ autoLoad: true,
+ compass: true,
+ northOffset: d.ca,
+ yaw: 0,
+ minHfov: minHfov,
+ maxHfov: maxHfov,
+ hfov: defaultHfov,
+ type: 'cubemap',
+ cubeMap: [
+ _dataUrlArray[0],
+ _dataUrlArray[1],
+ _dataUrlArray[2],
+ _dataUrlArray[3],
+ _dataUrlArray[4],
+ _dataUrlArray[5]
+ ]
+ };
+ return { status: 'ok' };
+ });
+ },
+
+
+ getSequenceKeyForBubble: function(d) {
+ return d && d.sequenceKey;
+ },
+
+
+ // Updates the currently highlighted sequence and selected bubble.
+ // Reset is only necessary when interacting with the viewport because
+ // this implicitly changes the currently selected bubble/sequence
+ setStyles: function (context, hovered, reset) {
+ if (reset) { // reset all layers
+ context.container().selectAll('.viewfield-group')
+ .classed('highlighted', false)
+ .classed('hovered', false)
+ .classed('currentView', false);
+
+ context.container().selectAll('.sequence')
+ .classed('highlighted', false)
+ .classed('currentView', false);
+ }
+
+ let hoveredBubbleKey = hovered && hovered.key;
+ let hoveredSequenceKey = this.getSequenceKeyForBubble(hovered);
+ let hoveredSequence = hoveredSequenceKey && _ssCache.sequences[hoveredSequenceKey];
+ let hoveredBubbleKeys = (hoveredSequence && hoveredSequence.bubbles.map(d => d.key)) || [];
+
+ let viewer = context.container().select('.photoviewer');
+ let selected = viewer.empty() ? undefined : viewer.datum();
+ let selectedBubbleKey = selected && selected.key;
+ let selectedSequenceKey = this.getSequenceKeyForBubble(selected);
+ let selectedSequence = selectedSequenceKey && _ssCache.sequences[selectedSequenceKey];
+ let selectedBubbleKeys = (selectedSequence && selectedSequence.bubbles.map(d => d.key)) || [];
+
+ // highlight sibling viewfields on either the selected or the hovered sequences
+ let highlightedBubbleKeys = utilArrayUnion(hoveredBubbleKeys, selectedBubbleKeys);
+
+ context.container().selectAll('.layer-streetside-images .viewfield-group')
+ .classed('highlighted', d => highlightedBubbleKeys.indexOf(d.key) !== -1)
+ .classed('hovered', d => d.key === hoveredBubbleKey)
+ .classed('currentView', d => d.key === selectedBubbleKey);
+
+ context.container().selectAll('.layer-streetside-images .sequence')
+ .classed('highlighted', d => d.properties.key === hoveredSequenceKey)
+ .classed('currentView', d => d.properties.key === selectedSequenceKey);
+
+ // update viewfields if needed
+ context.container().selectAll('.viewfield-group .viewfield')
+ .attr('d', viewfieldPath);
+
+ function viewfieldPath() {
+ let d = this.parentNode.__data__;
+ if (d.pano && d.key !== selectedBubbleKey) {
+ return 'M 8,13 m -10,0 a 10,10 0 1,0 20,0 a 10,10 0 1,0 -20,0';
+ } else {
+ return 'M 6,9 C 8,8.4 8,8.4 10,9 L 16,-2 C 12,-5 4,-5 0,-2 z';
+ }
+ }
+
+ return this;
+ },
+
+
+ /**
+ * cache().
+ */
+ cache: function () {
+ return _ssCache;
+ }
+ };
+
+ var apibase$4 = 'https://taginfo.openstreetmap.org/api/4/';
+ var _inflight$2 = {};
+ var _popularKeys = {};
+ var _taginfoCache = {};
+
+ var tag_sorts = {
+ point: 'count_nodes',
+ vertex: 'count_nodes',
+ area: 'count_ways',
+ line: 'count_ways'
+ };
+ var tag_sort_members = {
+ point: 'count_node_members',
+ vertex: 'count_node_members',
+ area: 'count_way_members',
+ line: 'count_way_members',
+ relation: 'count_relation_members'
+ };
+ var tag_filters = {
+ point: 'nodes',
+ vertex: 'nodes',
+ area: 'ways',
+ line: 'ways'
+ };
+ var tag_members_fractions = {
+ point: 'count_node_members_fraction',
+ vertex: 'count_node_members_fraction',
+ area: 'count_way_members_fraction',
+ line: 'count_way_members_fraction',
+ relation: 'count_relation_members_fraction'
+ };
+
+
+ function sets(params, n, o) {
+ if (params.geometry && o[params.geometry]) {
+ params[n] = o[params.geometry];
+ }
+ return params;
+ }
+
+
+ function setFilter(params) {
+ return sets(params, 'filter', tag_filters);
+ }
+
+
+ function setSort(params) {
+ return sets(params, 'sortname', tag_sorts);
+ }
+
+
+ function setSortMembers(params) {
+ return sets(params, 'sortname', tag_sort_members);
+ }
+
+
+ function clean(params) {
+ return utilObjectOmit(params, ['geometry', 'debounce']);
+ }
+
+
+ function filterKeys(type) {
+ var count_type = type ? 'count_' + type : 'count_all';
+ return function(d) {
+ return parseFloat(d[count_type]) > 2500 || d.in_wiki;
+ };
+ }
+
+
+ function filterMultikeys(prefix) {
+ return function(d) {
+ // d.key begins with prefix, and d.key contains no additional ':'s
+ var re = new RegExp('^' + prefix + '(.*)$');
+ var matches = d.key.match(re) || [];
+ return (matches.length === 2 && matches[1].indexOf(':') === -1);
+ };
+ }
+
+
+ function filterValues(allowUpperCase) {
+ return function(d) {
+ if (d.value.match(/[;,]/) !== null) return false; // exclude some punctuation
+ if (!allowUpperCase && d.value.match(/[A-Z*]/) !== null) return false; // exclude uppercase letters
+ return parseFloat(d.fraction) > 0.0;
+ };
+ }
+
+
+ function filterRoles(geometry) {
+ return function(d) {
+ if (d.role === '') return false; // exclude empty role
+ if (d.role.match(/[A-Z*;,]/) !== null) return false; // exclude uppercase letters and some punctuation
+ return parseFloat(d[tag_members_fractions[geometry]]) > 0.0;
+ };
+ }
+
+
+ function valKey(d) {
+ return {
+ value: d.key,
+ title: d.key
+ };
+ }
+
+
+ function valKeyDescription(d) {
+ var obj = {
+ value: d.value,
+ title: d.description || d.value
+ };
+ if (d.count) {
+ obj.count = d.count;
+ }
+ return obj;
+ }
+
+
+ function roleKey(d) {
+ return {
+ value: d.role,
+ title: d.role
+ };
+ }
+
+
+ // sort keys with ':' lower than keys without ':'
+ function sortKeys(a, b) {
+ return (a.key.indexOf(':') === -1 && b.key.indexOf(':') !== -1) ? -1
+ : (a.key.indexOf(':') !== -1 && b.key.indexOf(':') === -1) ? 1
+ : 0;
+ }
+
+
+ var debouncedRequest$1 = debounce(request$1, 300, { leading: false });
+
+ function request$1(url, params, exactMatch, callback, loaded) {
+ if (_inflight$2[url]) return;
+
+ if (checkCache(url, params, exactMatch, callback)) return;
+
+ var controller = new AbortController();
+ _inflight$2[url] = controller;
+
+ d3_json(url, { signal: controller.signal })
+ .then(function(result) {
+ delete _inflight$2[url];
+ if (loaded) loaded(null, result);
+ })
+ .catch(function(err) {
+ delete _inflight$2[url];
+ if (err.name === 'AbortError') return;
+ if (loaded) loaded(err.message);
+ });
+ }
+
+
+ function checkCache(url, params, exactMatch, callback) {
+ var rp = params.rp || 25;
+ var testQuery = params.query || '';
+ var testUrl = url;
+
+ do {
+ var hit = _taginfoCache[testUrl];
+
+ // exact match, or shorter match yielding fewer than max results (rp)
+ if (hit && (url === testUrl || hit.length < rp)) {
+ callback(null, hit);
+ return true;
+ }
+
+ // don't try to shorten the query
+ if (exactMatch || !testQuery.length) return false;
+
+ // do shorten the query to see if we already have a cached result
+ // that has returned fewer than max results (rp)
+ testQuery = testQuery.slice(0, -1);
+ testUrl = url.replace(/&query=(.*?)&/, '&query=' + testQuery + '&');
+ } while (testQuery.length >= 0);
+
+ return false;
+ }
+
+
+ var serviceTaginfo = {
+
+ init: function() {
+ _inflight$2 = {};
+ _taginfoCache = {};
+ _popularKeys = {
+ // manually exclude some keys – #5377, #7485
+ postal_code: true,
+ full_name: true,
+ loc_name: true,
+ reg_name: true,
+ short_name: true,
+ sorting_name: true,
+ artist_name: true,
+ nat_name: true,
+ long_name: true,
+ 'bridge:name': true
+ };
+
+ // Fetch popular keys. We'll exclude these from `values`
+ // lookups because they stress taginfo, and they aren't likely
+ // to yield meaningful autocomplete results.. see #3955
+ var params = {
+ rp: 100,
+ sortname: 'values_all',
+ sortorder: 'desc',
+ page: 1,
+ debounce: false,
+ lang: _mainLocalizer.languageCode()
+ };
+ this.keys(params, function(err, data) {
+ if (err) return;
+ data.forEach(function(d) {
+ if (d.value === 'opening_hours') return; // exception
+ _popularKeys[d.value] = true;
+ });
+ });
+ },
+
+
+ reset: function() {
+ Object.values(_inflight$2).forEach(function(controller) { controller.abort(); });
+ _inflight$2 = {};
+ },
+
+
+ keys: function(params, callback) {
+ var doRequest = params.debounce ? debouncedRequest$1 : request$1;
+ params = clean(setSort(params));
+ params = Object.assign({
+ rp: 10,
+ sortname: 'count_all',
+ sortorder: 'desc',
+ page: 1,
+ lang: _mainLocalizer.languageCode()
+ }, params);
+
+ var url = apibase$4 + 'keys/all?' + utilQsString(params);
+ doRequest(url, params, false, callback, function(err, d) {
+ if (err) {
+ callback(err);
+ } else {
+ var f = filterKeys(params.filter);
+ var result = d.data.filter(f).sort(sortKeys).map(valKey);
+ _taginfoCache[url] = result;
+ callback(null, result);
+ }
+ });
+ },
+
+
+ multikeys: function(params, callback) {
+ var doRequest = params.debounce ? debouncedRequest$1 : request$1;
+ params = clean(setSort(params));
+ params = Object.assign({
+ rp: 25,
+ sortname: 'count_all',
+ sortorder: 'desc',
+ page: 1,
+ lang: _mainLocalizer.languageCode()
+ }, params);
+
+ var prefix = params.query;
+ var url = apibase$4 + 'keys/all?' + utilQsString(params);
+ doRequest(url, params, true, callback, function(err, d) {
+ if (err) {
+ callback(err);
+ } else {
+ var f = filterMultikeys(prefix);
+ var result = d.data.filter(f).map(valKey);
+ _taginfoCache[url] = result;
+ callback(null, result);
+ }
+ });
+ },
+
+
+ values: function(params, callback) {
+ // Exclude popular keys from values lookups.. see #3955
+ var key = params.key;
+ if (key && _popularKeys[key]) {
+ callback(null, []);
+ return;
+ }
+
+ var doRequest = params.debounce ? debouncedRequest$1 : request$1;
+ params = clean(setSort(setFilter(params)));
+ params = Object.assign({
+ rp: 25,
+ sortname: 'count_all',
+ sortorder: 'desc',
+ page: 1,
+ lang: _mainLocalizer.languageCode()
+ }, params);
+
+ var url = apibase$4 + 'key/values?' + utilQsString(params);
+ doRequest(url, params, false, callback, function(err, d) {
+ if (err) {
+ callback(err);
+ } else {
+ // In most cases we prefer taginfo value results with lowercase letters.
+ // A few OSM keys expect values to contain uppercase values (see #3377).
+ // This is not an exhaustive list (e.g. `name` also has uppercase values)
+ // but these are the fields where taginfo value lookup is most useful.
+ var re = /network|taxon|genus|species|brand|grape_variety|royal_cypher|listed_status|booth|rating|stars|:output|_hours|_times|_ref|manufacturer|country|target|brewery/;
+ var allowUpperCase = re.test(params.key);
+ var f = filterValues(allowUpperCase);
+
+ var result = d.data.filter(f).map(valKeyDescription);
+ _taginfoCache[url] = result;
+ callback(null, result);
+ }
+ });
+ },
+
+
+ roles: function(params, callback) {
+ var doRequest = params.debounce ? debouncedRequest$1 : request$1;
+ var geometry = params.geometry;
+ params = clean(setSortMembers(params));
+ params = Object.assign({
+ rp: 25,
+ sortname: 'count_all_members',
+ sortorder: 'desc',
+ page: 1,
+ lang: _mainLocalizer.languageCode()
+ }, params);
+
+ var url = apibase$4 + 'relation/roles?' + utilQsString(params);
+ doRequest(url, params, true, callback, function(err, d) {
+ if (err) {
+ callback(err);
+ } else {
+ var f = filterRoles(geometry);
+ var result = d.data.filter(f).map(roleKey);
+ _taginfoCache[url] = result;
+ callback(null, result);
+ }
+ });
+ },
+
+
+ docs: function(params, callback) {
+ var doRequest = params.debounce ? debouncedRequest$1 : request$1;
+ params = clean(setSort(params));
+
+ var path = 'key/wiki_pages?';
+ if (params.value) {
+ path = 'tag/wiki_pages?';
+ } else if (params.rtype) {
+ path = 'relation/wiki_pages?';
+ }
+
+ var url = apibase$4 + path + utilQsString(params);
+ doRequest(url, params, true, callback, function(err, d) {
+ if (err) {
+ callback(err);
+ } else {
+ _taginfoCache[url] = d.data;
+ callback(null, d.data);
+ }
+ });
+ },
+
+
+ apibase: function(_) {
+ if (!arguments.length) return apibase$4;
+ apibase$4 = _;
+ return this;
+ }
+
+ };
+
+ var helpers$1 = createCommonjsModule(function (module, exports) {
+ Object.defineProperty(exports, "__esModule", { value: true });
+ /**
+ * @module helpers
+ */
+ /**
+ * Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth.
+ *
+ * @memberof helpers
+ * @type {number}
+ */
+ exports.earthRadius = 6371008.8;
+ /**
+ * Unit of measurement factors using a spherical (non-ellipsoid) earth radius.
+ *
+ * @memberof helpers
+ * @type {Object}
+ */
+ exports.factors = {
+ centimeters: exports.earthRadius * 100,
+ centimetres: exports.earthRadius * 100,
+ degrees: exports.earthRadius / 111325,
+ feet: exports.earthRadius * 3.28084,
+ inches: exports.earthRadius * 39.370,
+ kilometers: exports.earthRadius / 1000,
+ kilometres: exports.earthRadius / 1000,
+ meters: exports.earthRadius,
+ metres: exports.earthRadius,
+ miles: exports.earthRadius / 1609.344,
+ millimeters: exports.earthRadius * 1000,
+ millimetres: exports.earthRadius * 1000,
+ nauticalmiles: exports.earthRadius / 1852,
+ radians: 1,
+ yards: exports.earthRadius / 1.0936,
+ };
+ /**
+ * Units of measurement factors based on 1 meter.
+ *
+ * @memberof helpers
+ * @type {Object}
+ */
+ exports.unitsFactors = {
+ centimeters: 100,
+ centimetres: 100,
+ degrees: 1 / 111325,
+ feet: 3.28084,
+ inches: 39.370,
+ kilometers: 1 / 1000,
+ kilometres: 1 / 1000,
+ meters: 1,
+ metres: 1,
+ miles: 1 / 1609.344,
+ millimeters: 1000,
+ millimetres: 1000,
+ nauticalmiles: 1 / 1852,
+ radians: 1 / exports.earthRadius,
+ yards: 1 / 1.0936,
+ };
+ /**
+ * Area of measurement factors based on 1 square meter.
+ *
+ * @memberof helpers
+ * @type {Object}
+ */
+ exports.areaFactors = {
+ acres: 0.000247105,
+ centimeters: 10000,
+ centimetres: 10000,
+ feet: 10.763910417,
+ inches: 1550.003100006,
+ kilometers: 0.000001,
+ kilometres: 0.000001,
+ meters: 1,
+ metres: 1,
+ miles: 3.86e-7,
+ millimeters: 1000000,
+ millimetres: 1000000,
+ yards: 1.195990046,
+ };
+ /**
+ * Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}.
+ *
+ * @name feature
+ * @param {Geometry} geometry input geometry
+ * @param {Object} [properties={}] an Object of key-value pairs to add as properties
+ * @param {Object} [options={}] Optional Parameters
+ * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
+ * @param {string|number} [options.id] Identifier associated with the Feature
+ * @returns {Feature} a GeoJSON Feature
+ * @example
+ * var geometry = {
+ * "type": "Point",
+ * "coordinates": [110, 50]
+ * };
+ *
+ * var feature = turf.feature(geometry);
+ *
+ * //=feature
+ */
+ function feature(geom, properties, options) {
+ if (options === void 0) { options = {}; }
+ var feat = { type: "Feature" };
+ if (options.id === 0 || options.id) {
+ feat.id = options.id;
+ }
+ if (options.bbox) {
+ feat.bbox = options.bbox;
+ }
+ feat.properties = properties || {};
+ feat.geometry = geom;
+ return feat;
+ }
+ exports.feature = feature;
+ /**
+ * Creates a GeoJSON {@link Geometry} from a Geometry string type & coordinates.
+ * For GeometryCollection type use `helpers.geometryCollection`
+ *
+ * @name geometry
+ * @param {string} type Geometry Type
+ * @param {Array} coordinates Coordinates
+ * @param {Object} [options={}] Optional Parameters
+ * @returns {Geometry} a GeoJSON Geometry
+ * @example
+ * var type = "Point";
+ * var coordinates = [110, 50];
+ * var geometry = turf.geometry(type, coordinates);
+ * // => geometry
+ */
+ function geometry(type, coordinates, options) {
+ switch (type) {
+ case "Point": return point(coordinates).geometry;
+ case "LineString": return lineString(coordinates).geometry;
+ case "Polygon": return polygon(coordinates).geometry;
+ case "MultiPoint": return multiPoint(coordinates).geometry;
+ case "MultiLineString": return multiLineString(coordinates).geometry;
+ case "MultiPolygon": return multiPolygon(coordinates).geometry;
+ default: throw new Error(type + " is invalid");
+ }
+ }
+ exports.geometry = geometry;
+ /**
+ * Creates a {@link Point} {@link Feature} from a Position.
+ *
+ * @name point
+ * @param {Array} coordinates longitude, latitude position (each in decimal degrees)
+ * @param {Object} [properties={}] an Object of key-value pairs to add as properties
+ * @param {Object} [options={}] Optional Parameters
+ * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
+ * @param {string|number} [options.id] Identifier associated with the Feature
+ * @returns {Feature} a Point feature
+ * @example
+ * var point = turf.point([-75.343, 39.984]);
+ *
+ * //=point
+ */
+ function point(coordinates, properties, options) {
+ if (options === void 0) { options = {}; }
+ var geom = {
+ type: "Point",
+ coordinates: coordinates,
+ };
+ return feature(geom, properties, options);
+ }
+ exports.point = point;
+ /**
+ * Creates a {@link Point} {@link FeatureCollection} from an Array of Point coordinates.
+ *
+ * @name points
+ * @param {Array>} coordinates an array of Points
+ * @param {Object} [properties={}] Translate these properties to each Feature
+ * @param {Object} [options={}] Optional Parameters
+ * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north]
+ * associated with the FeatureCollection
+ * @param {string|number} [options.id] Identifier associated with the FeatureCollection
+ * @returns {FeatureCollection} Point Feature
+ * @example
+ * var points = turf.points([
+ * [-75, 39],
+ * [-80, 45],
+ * [-78, 50]
+ * ]);
+ *
+ * //=points
+ */
+ function points(coordinates, properties, options) {
+ if (options === void 0) { options = {}; }
+ return featureCollection(coordinates.map(function (coords) {
+ return point(coords, properties);
+ }), options);
+ }
+ exports.points = points;
+ /**
+ * Creates a {@link Polygon} {@link Feature} from an Array of LinearRings.
+ *
+ * @name polygon
+ * @param {Array>>} coordinates an array of LinearRings
+ * @param {Object} [properties={}] an Object of key-value pairs to add as properties
+ * @param {Object} [options={}] Optional Parameters
+ * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
+ * @param {string|number} [options.id] Identifier associated with the Feature
+ * @returns {Feature} Polygon Feature
+ * @example
+ * var polygon = turf.polygon([[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]], { name: 'poly1' });
+ *
+ * //=polygon
+ */
+ function polygon(coordinates, properties, options) {
+ if (options === void 0) { options = {}; }
+ for (var _i = 0, coordinates_1 = coordinates; _i < coordinates_1.length; _i++) {
+ var ring = coordinates_1[_i];
+ if (ring.length < 4) {
+ throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");
+ }
+ for (var j = 0; j < ring[ring.length - 1].length; j++) {
+ // Check if first point of Polygon contains two numbers
+ if (ring[ring.length - 1][j] !== ring[0][j]) {
+ throw new Error("First and last Position are not equivalent.");
+ }
+ }
+ }
+ var geom = {
+ type: "Polygon",
+ coordinates: coordinates,
+ };
+ return feature(geom, properties, options);
+ }
+ exports.polygon = polygon;
+ /**
+ * Creates a {@link Polygon} {@link FeatureCollection} from an Array of Polygon coordinates.
+ *
+ * @name polygons
+ * @param {Array>>>} coordinates an array of Polygon coordinates
+ * @param {Object} [properties={}] an Object of key-value pairs to add as properties
+ * @param {Object} [options={}] Optional Parameters
+ * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
+ * @param {string|number} [options.id] Identifier associated with the FeatureCollection
+ * @returns {FeatureCollection} Polygon FeatureCollection
+ * @example
+ * var polygons = turf.polygons([
+ * [[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]],
+ * [[[-15, 42], [-14, 46], [-12, 41], [-17, 44], [-15, 42]]],
+ * ]);
+ *
+ * //=polygons
+ */
+ function polygons(coordinates, properties, options) {
+ if (options === void 0) { options = {}; }
+ return featureCollection(coordinates.map(function (coords) {
+ return polygon(coords, properties);
+ }), options);
+ }
+ exports.polygons = polygons;
+ /**
+ * Creates a {@link LineString} {@link Feature} from an Array of Positions.
+ *
+ * @name lineString
+ * @param {Array>} coordinates an array of Positions
+ * @param {Object} [properties={}] an Object of key-value pairs to add as properties
+ * @param {Object} [options={}] Optional Parameters
+ * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
+ * @param {string|number} [options.id] Identifier associated with the Feature
+ * @returns {Feature} LineString Feature
+ * @example
+ * var linestring1 = turf.lineString([[-24, 63], [-23, 60], [-25, 65], [-20, 69]], {name: 'line 1'});
+ * var linestring2 = turf.lineString([[-14, 43], [-13, 40], [-15, 45], [-10, 49]], {name: 'line 2'});
+ *
+ * //=linestring1
+ * //=linestring2
+ */
+ function lineString(coordinates, properties, options) {
+ if (options === void 0) { options = {}; }
+ if (coordinates.length < 2) {
+ throw new Error("coordinates must be an array of two or more positions");
+ }
+ var geom = {
+ type: "LineString",
+ coordinates: coordinates,
+ };
+ return feature(geom, properties, options);
+ }
+ exports.lineString = lineString;
+ /**
+ * Creates a {@link LineString} {@link FeatureCollection} from an Array of LineString coordinates.
+ *
+ * @name lineStrings
+ * @param {Array>>} coordinates an array of LinearRings
+ * @param {Object} [properties={}] an Object of key-value pairs to add as properties
+ * @param {Object} [options={}] Optional Parameters
+ * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north]
+ * associated with the FeatureCollection
+ * @param {string|number} [options.id] Identifier associated with the FeatureCollection
+ * @returns {FeatureCollection} LineString FeatureCollection
+ * @example
+ * var linestrings = turf.lineStrings([
+ * [[-24, 63], [-23, 60], [-25, 65], [-20, 69]],
+ * [[-14, 43], [-13, 40], [-15, 45], [-10, 49]]
+ * ]);
+ *
+ * //=linestrings
+ */
+ function lineStrings(coordinates, properties, options) {
+ if (options === void 0) { options = {}; }
+ return featureCollection(coordinates.map(function (coords) {
+ return lineString(coords, properties);
+ }), options);
+ }
+ exports.lineStrings = lineStrings;
+ /**
+ * Takes one or more {@link Feature|Features} and creates a {@link FeatureCollection}.
+ *
+ * @name featureCollection
+ * @param {Feature[]} features input features
+ * @param {Object} [options={}] Optional Parameters
+ * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
+ * @param {string|number} [options.id] Identifier associated with the Feature
+ * @returns {FeatureCollection} FeatureCollection of Features
+ * @example
+ * var locationA = turf.point([-75.343, 39.984], {name: 'Location A'});
+ * var locationB = turf.point([-75.833, 39.284], {name: 'Location B'});
+ * var locationC = turf.point([-75.534, 39.123], {name: 'Location C'});
+ *
+ * var collection = turf.featureCollection([
+ * locationA,
+ * locationB,
+ * locationC
+ * ]);
+ *
+ * //=collection
+ */
+ function featureCollection(features, options) {
+ if (options === void 0) { options = {}; }
+ var fc = { type: "FeatureCollection" };
+ if (options.id) {
+ fc.id = options.id;
+ }
+ if (options.bbox) {
+ fc.bbox = options.bbox;
+ }
+ fc.features = features;
+ return fc;
+ }
+ exports.featureCollection = featureCollection;
+ /**
+ * Creates a {@link Feature} based on a
+ * coordinate array. Properties can be added optionally.
+ *
+ * @name multiLineString
+ * @param {Array>>} coordinates an array of LineStrings
+ * @param {Object} [properties={}] an Object of key-value pairs to add as properties
+ * @param {Object} [options={}] Optional Parameters
+ * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
+ * @param {string|number} [options.id] Identifier associated with the Feature
+ * @returns {Feature} a MultiLineString feature
+ * @throws {Error} if no coordinates are passed
+ * @example
+ * var multiLine = turf.multiLineString([[[0,0],[10,10]]]);
+ *
+ * //=multiLine
+ */
+ function multiLineString(coordinates, properties, options) {
+ if (options === void 0) { options = {}; }
+ var geom = {
+ type: "MultiLineString",
+ coordinates: coordinates,
+ };
+ return feature(geom, properties, options);
+ }
+ exports.multiLineString = multiLineString;
+ /**
+ * Creates a {@link Feature} based on a
+ * coordinate array. Properties can be added optionally.
+ *
+ * @name multiPoint
+ * @param {Array>} coordinates an array of Positions
+ * @param {Object} [properties={}] an Object of key-value pairs to add as properties
+ * @param {Object} [options={}] Optional Parameters
+ * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
+ * @param {string|number} [options.id] Identifier associated with the Feature
+ * @returns {Feature} a MultiPoint feature
+ * @throws {Error} if no coordinates are passed
+ * @example
+ * var multiPt = turf.multiPoint([[0,0],[10,10]]);
+ *
+ * //=multiPt
+ */
+ function multiPoint(coordinates, properties, options) {
+ if (options === void 0) { options = {}; }
+ var geom = {
+ type: "MultiPoint",
+ coordinates: coordinates,
+ };
+ return feature(geom, properties, options);
+ }
+ exports.multiPoint = multiPoint;
+ /**
+ * Creates a {@link Feature} based on a
+ * coordinate array. Properties can be added optionally.
+ *
+ * @name multiPolygon
+ * @param {Array>>>} coordinates an array of Polygons
+ * @param {Object} [properties={}] an Object of key-value pairs to add as properties
+ * @param {Object} [options={}] Optional Parameters
+ * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
+ * @param {string|number} [options.id] Identifier associated with the Feature
+ * @returns {Feature} a multipolygon feature
+ * @throws {Error} if no coordinates are passed
+ * @example
+ * var multiPoly = turf.multiPolygon([[[[0,0],[0,10],[10,10],[10,0],[0,0]]]]);
+ *
+ * //=multiPoly
+ *
+ */
+ function multiPolygon(coordinates, properties, options) {
+ if (options === void 0) { options = {}; }
+ var geom = {
+ type: "MultiPolygon",
+ coordinates: coordinates,
+ };
+ return feature(geom, properties, options);
+ }
+ exports.multiPolygon = multiPolygon;
+ /**
+ * Creates a {@link Feature} based on a
+ * coordinate array. Properties can be added optionally.
+ *
+ * @name geometryCollection
+ * @param {Array} geometries an array of GeoJSON Geometries
+ * @param {Object} [properties={}] an Object of key-value pairs to add as properties
+ * @param {Object} [options={}] Optional Parameters
+ * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
+ * @param {string|number} [options.id] Identifier associated with the Feature
+ * @returns {Feature} a GeoJSON GeometryCollection Feature
+ * @example
+ * var pt = turf.geometry("Point", [100, 0]);
+ * var line = turf.geometry("LineString", [[101, 0], [102, 1]]);
+ * var collection = turf.geometryCollection([pt, line]);
+ *
+ * // => collection
+ */
+ function geometryCollection(geometries, properties, options) {
+ if (options === void 0) { options = {}; }
+ var geom = {
+ type: "GeometryCollection",
+ geometries: geometries,
+ };
+ return feature(geom, properties, options);
+ }
+ exports.geometryCollection = geometryCollection;
+ /**
+ * Round number to precision
+ *
+ * @param {number} num Number
+ * @param {number} [precision=0] Precision
+ * @returns {number} rounded number
+ * @example
+ * turf.round(120.4321)
+ * //=120
+ *
+ * turf.round(120.4321, 2)
+ * //=120.43
+ */
+ function round(num, precision) {
+ if (precision === void 0) { precision = 0; }
+ if (precision && !(precision >= 0)) {
+ throw new Error("precision must be a positive number");
+ }
+ var multiplier = Math.pow(10, precision || 0);
+ return Math.round(num * multiplier) / multiplier;
+ }
+ exports.round = round;
+ /**
+ * Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.
+ * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
+ *
+ * @name radiansToLength
+ * @param {number} radians in radians across the sphere
+ * @param {string} [units="kilometers"] can be degrees, radians, miles, or kilometers inches, yards, metres,
+ * meters, kilometres, kilometers.
+ * @returns {number} distance
+ */
+ function radiansToLength(radians, units) {
+ if (units === void 0) { units = "kilometers"; }
+ var factor = exports.factors[units];
+ if (!factor) {
+ throw new Error(units + " units is invalid");
+ }
+ return radians * factor;
+ }
+ exports.radiansToLength = radiansToLength;
+ /**
+ * Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians
+ * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
+ *
+ * @name lengthToRadians
+ * @param {number} distance in real units
+ * @param {string} [units="kilometers"] can be degrees, radians, miles, or kilometers inches, yards, metres,
+ * meters, kilometres, kilometers.
+ * @returns {number} radians
+ */
+ function lengthToRadians(distance, units) {
+ if (units === void 0) { units = "kilometers"; }
+ var factor = exports.factors[units];
+ if (!factor) {
+ throw new Error(units + " units is invalid");
+ }
+ return distance / factor;
+ }
+ exports.lengthToRadians = lengthToRadians;
+ /**
+ * Convert a distance measurement (assuming a spherical Earth) from a real-world unit into degrees
+ * Valid units: miles, nauticalmiles, inches, yards, meters, metres, centimeters, kilometres, feet
+ *
+ * @name lengthToDegrees
+ * @param {number} distance in real units
+ * @param {string} [units="kilometers"] can be degrees, radians, miles, or kilometers inches, yards, metres,
+ * meters, kilometres, kilometers.
+ * @returns {number} degrees
+ */
+ function lengthToDegrees(distance, units) {
+ return radiansToDegrees(lengthToRadians(distance, units));
+ }
+ exports.lengthToDegrees = lengthToDegrees;
+ /**
+ * Converts any bearing angle from the north line direction (positive clockwise)
+ * and returns an angle between 0-360 degrees (positive clockwise), 0 being the north line
+ *
+ * @name bearingToAzimuth
+ * @param {number} bearing angle, between -180 and +180 degrees
+ * @returns {number} angle between 0 and 360 degrees
+ */
+ function bearingToAzimuth(bearing) {
+ var angle = bearing % 360;
+ if (angle < 0) {
+ angle += 360;
+ }
+ return angle;
+ }
+ exports.bearingToAzimuth = bearingToAzimuth;
+ /**
+ * Converts an angle in radians to degrees
+ *
+ * @name radiansToDegrees
+ * @param {number} radians angle in radians
+ * @returns {number} degrees between 0 and 360 degrees
+ */
+ function radiansToDegrees(radians) {
+ var degrees = radians % (2 * Math.PI);
+ return degrees * 180 / Math.PI;
+ }
+ exports.radiansToDegrees = radiansToDegrees;
+ /**
+ * Converts an angle in degrees to radians
+ *
+ * @name degreesToRadians
+ * @param {number} degrees angle between 0 and 360 degrees
+ * @returns {number} angle in radians
+ */
+ function degreesToRadians(degrees) {
+ var radians = degrees % 360;
+ return radians * Math.PI / 180;
+ }
+ exports.degreesToRadians = degreesToRadians;
+ /**
+ * Converts a length to the requested unit.
+ * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
+ *
+ * @param {number} length to be converted
+ * @param {Units} [originalUnit="kilometers"] of the length
+ * @param {Units} [finalUnit="kilometers"] returned unit
+ * @returns {number} the converted length
+ */
+ function convertLength(length, originalUnit, finalUnit) {
+ if (originalUnit === void 0) { originalUnit = "kilometers"; }
+ if (finalUnit === void 0) { finalUnit = "kilometers"; }
+ if (!(length >= 0)) {
+ throw new Error("length must be a positive number");
+ }
+ return radiansToLength(lengthToRadians(length, originalUnit), finalUnit);
+ }
+ exports.convertLength = convertLength;
+ /**
+ * Converts a area to the requested unit.
+ * Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches
+ * @param {number} area to be converted
+ * @param {Units} [originalUnit="meters"] of the distance
+ * @param {Units} [finalUnit="kilometers"] returned unit
+ * @returns {number} the converted distance
+ */
+ function convertArea(area, originalUnit, finalUnit) {
+ if (originalUnit === void 0) { originalUnit = "meters"; }
+ if (finalUnit === void 0) { finalUnit = "kilometers"; }
+ if (!(area >= 0)) {
+ throw new Error("area must be a positive number");
+ }
+ var startFactor = exports.areaFactors[originalUnit];
+ if (!startFactor) {
+ throw new Error("invalid original units");
+ }
+ var finalFactor = exports.areaFactors[finalUnit];
+ if (!finalFactor) {
+ throw new Error("invalid final units");
+ }
+ return (area / startFactor) * finalFactor;
+ }
+ exports.convertArea = convertArea;
+ /**
+ * isNumber
+ *
+ * @param {*} num Number to validate
+ * @returns {boolean} true/false
+ * @example
+ * turf.isNumber(123)
+ * //=true
+ * turf.isNumber('foo')
+ * //=false
+ */
+ function isNumber(num) {
+ return !isNaN(num) && num !== null && !Array.isArray(num) && !/^\s*$/.test(num);
+ }
+ exports.isNumber = isNumber;
+ /**
+ * isObject
+ *
+ * @param {*} input variable to validate
+ * @returns {boolean} true/false
+ * @example
+ * turf.isObject({elevation: 10})
+ * //=true
+ * turf.isObject('foo')
+ * //=false
+ */
+ function isObject(input) {
+ return (!!input) && (input.constructor === Object);
+ }
+ exports.isObject = isObject;
+ /**
+ * Validate BBox
+ *
+ * @private
+ * @param {Array} bbox BBox to validate
+ * @returns {void}
+ * @throws Error if BBox is not valid
+ * @example
+ * validateBBox([-180, -40, 110, 50])
+ * //=OK
+ * validateBBox([-180, -40])
+ * //=Error
+ * validateBBox('Foo')
+ * //=Error
+ * validateBBox(5)
+ * //=Error
+ * validateBBox(null)
+ * //=Error
+ * validateBBox(undefined)
+ * //=Error
+ */
+ function validateBBox(bbox) {
+ if (!bbox) {
+ throw new Error("bbox is required");
+ }
+ if (!Array.isArray(bbox)) {
+ throw new Error("bbox must be an Array");
+ }
+ if (bbox.length !== 4 && bbox.length !== 6) {
+ throw new Error("bbox must be an Array of 4 or 6 numbers");
+ }
+ bbox.forEach(function (num) {
+ if (!isNumber(num)) {
+ throw new Error("bbox must only contain numbers");
+ }
+ });
+ }
+ exports.validateBBox = validateBBox;
+ /**
+ * Validate Id
+ *
+ * @private
+ * @param {string|number} id Id to validate
+ * @returns {void}
+ * @throws Error if Id is not valid
+ * @example
+ * validateId([-180, -40, 110, 50])
+ * //=Error
+ * validateId([-180, -40])
+ * //=Error
+ * validateId('Foo')
+ * //=OK
+ * validateId(5)
+ * //=OK
+ * validateId(null)
+ * //=Error
+ * validateId(undefined)
+ * //=Error
+ */
+ function validateId(id) {
+ if (!id) {
+ throw new Error("id is required");
+ }
+ if (["string", "number"].indexOf(typeof id) === -1) {
+ throw new Error("id must be a number or a string");
+ }
+ }
+ exports.validateId = validateId;
+ // Deprecated methods
+ function radians2degrees() {
+ throw new Error("method has been renamed to `radiansToDegrees`");
+ }
+ exports.radians2degrees = radians2degrees;
+ function degrees2radians() {
+ throw new Error("method has been renamed to `degreesToRadians`");
+ }
+ exports.degrees2radians = degrees2radians;
+ function distanceToDegrees() {
+ throw new Error("method has been renamed to `lengthToDegrees`");
+ }
+ exports.distanceToDegrees = distanceToDegrees;
+ function distanceToRadians() {
+ throw new Error("method has been renamed to `lengthToRadians`");
+ }
+ exports.distanceToRadians = distanceToRadians;
+ function radiansToDistance() {
+ throw new Error("method has been renamed to `radiansToLength`");
+ }
+ exports.radiansToDistance = radiansToDistance;
+ function bearingToAngle() {
+ throw new Error("method has been renamed to `bearingToAzimuth`");
+ }
+ exports.bearingToAngle = bearingToAngle;
+ function convertDistance() {
+ throw new Error("method has been renamed to `convertLength`");
+ }
+ exports.convertDistance = convertDistance;
+ });
+
+ var invariant = createCommonjsModule(function (module, exports) {
+ Object.defineProperty(exports, "__esModule", { value: true });
+
+ /**
+ * Unwrap a coordinate from a Point Feature, Geometry or a single coordinate.
+ *
+ * @name getCoord
+ * @param {Array|Geometry|Feature} coord GeoJSON Point or an Array of numbers
+ * @returns {Array} coordinates
+ * @example
+ * var pt = turf.point([10, 10]);
+ *
+ * var coord = turf.getCoord(pt);
+ * //= [10, 10]
+ */
+ function getCoord(coord) {
+ if (!coord) {
+ throw new Error("coord is required");
+ }
+ if (!Array.isArray(coord)) {
+ if (coord.type === "Feature" && coord.geometry !== null && coord.geometry.type === "Point") {
+ return coord.geometry.coordinates;
+ }
+ if (coord.type === "Point") {
+ return coord.coordinates;
+ }
+ }
+ if (Array.isArray(coord) && coord.length >= 2 && !Array.isArray(coord[0]) && !Array.isArray(coord[1])) {
+ return coord;
+ }
+ throw new Error("coord must be GeoJSON Point or an Array of numbers");
+ }
+ exports.getCoord = getCoord;
+ /**
+ * Unwrap coordinates from a Feature, Geometry Object or an Array
+ *
+ * @name getCoords
+ * @param {Array|Geometry|Feature} coords Feature, Geometry Object or an Array
+ * @returns {Array} coordinates
+ * @example
+ * var poly = turf.polygon([[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]);
+ *
+ * var coords = turf.getCoords(poly);
+ * //= [[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]
+ */
+ function getCoords(coords) {
+ if (Array.isArray(coords)) {
+ return coords;
+ }
+ // Feature
+ if (coords.type === "Feature") {
+ if (coords.geometry !== null) {
+ return coords.geometry.coordinates;
+ }
+ }
+ else {
+ // Geometry
+ if (coords.coordinates) {
+ return coords.coordinates;
+ }
+ }
+ throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array");
+ }
+ exports.getCoords = getCoords;
+ /**
+ * Checks if coordinates contains a number
+ *
+ * @name containsNumber
+ * @param {Array} coordinates GeoJSON Coordinates
+ * @returns {boolean} true if Array contains a number
+ */
+ function containsNumber(coordinates) {
+ if (coordinates.length > 1 && helpers$1.isNumber(coordinates[0]) && helpers$1.isNumber(coordinates[1])) {
+ return true;
+ }
+ if (Array.isArray(coordinates[0]) && coordinates[0].length) {
+ return containsNumber(coordinates[0]);
+ }
+ throw new Error("coordinates must only contain numbers");
+ }
+ exports.containsNumber = containsNumber;
+ /**
+ * Enforce expectations about types of GeoJSON objects for Turf.
+ *
+ * @name geojsonType
+ * @param {GeoJSON} value any GeoJSON object
+ * @param {string} type expected GeoJSON type
+ * @param {string} name name of calling function
+ * @throws {Error} if value is not the expected type.
+ */
+ function geojsonType(value, type, name) {
+ if (!type || !name) {
+ throw new Error("type and name required");
+ }
+ if (!value || value.type !== type) {
+ throw new Error("Invalid input to " + name + ": must be a " + type + ", given " + value.type);
+ }
+ }
+ exports.geojsonType = geojsonType;
+ /**
+ * Enforce expectations about types of {@link Feature} inputs for Turf.
+ * Internally this uses {@link geojsonType} to judge geometry types.
+ *
+ * @name featureOf
+ * @param {Feature} feature a feature with an expected geometry type
+ * @param {string} type expected GeoJSON type
+ * @param {string} name name of calling function
+ * @throws {Error} error if value is not the expected type.
+ */
+ function featureOf(feature, type, name) {
+ if (!feature) {
+ throw new Error("No feature passed");
+ }
+ if (!name) {
+ throw new Error(".featureOf() requires a name");
+ }
+ if (!feature || feature.type !== "Feature" || !feature.geometry) {
+ throw new Error("Invalid input to " + name + ", Feature with geometry required");
+ }
+ if (!feature.geometry || feature.geometry.type !== type) {
+ throw new Error("Invalid input to " + name + ": must be a " + type + ", given " + feature.geometry.type);
+ }
+ }
+ exports.featureOf = featureOf;
+ /**
+ * Enforce expectations about types of {@link FeatureCollection} inputs for Turf.
+ * Internally this uses {@link geojsonType} to judge geometry types.
+ *
+ * @name collectionOf
+ * @param {FeatureCollection} featureCollection a FeatureCollection for which features will be judged
+ * @param {string} type expected GeoJSON type
+ * @param {string} name name of calling function
+ * @throws {Error} if value is not the expected type.
+ */
+ function collectionOf(featureCollection, type, name) {
+ if (!featureCollection) {
+ throw new Error("No featureCollection passed");
+ }
+ if (!name) {
+ throw new Error(".collectionOf() requires a name");
+ }
+ if (!featureCollection || featureCollection.type !== "FeatureCollection") {
+ throw new Error("Invalid input to " + name + ", FeatureCollection required");
+ }
+ for (var _i = 0, _a = featureCollection.features; _i < _a.length; _i++) {
+ var feature = _a[_i];
+ if (!feature || feature.type !== "Feature" || !feature.geometry) {
+ throw new Error("Invalid input to " + name + ", Feature with geometry required");
+ }
+ if (!feature.geometry || feature.geometry.type !== type) {
+ throw new Error("Invalid input to " + name + ": must be a " + type + ", given " + feature.geometry.type);
+ }
+ }
+ }
+ exports.collectionOf = collectionOf;
+ /**
+ * Get Geometry from Feature or Geometry Object
+ *
+ * @param {Feature|Geometry} geojson GeoJSON Feature or Geometry Object
+ * @returns {Geometry|null} GeoJSON Geometry Object
+ * @throws {Error} if geojson is not a Feature or Geometry Object
+ * @example
+ * var point = {
+ * "type": "Feature",
+ * "properties": {},
+ * "geometry": {
+ * "type": "Point",
+ * "coordinates": [110, 40]
+ * }
+ * }
+ * var geom = turf.getGeom(point)
+ * //={"type": "Point", "coordinates": [110, 40]}
+ */
+ function getGeom(geojson) {
+ if (geojson.type === "Feature") {
+ return geojson.geometry;
+ }
+ return geojson;
+ }
+ exports.getGeom = getGeom;
+ /**
+ * Get GeoJSON object's type, Geometry type is prioritize.
+ *
+ * @param {GeoJSON} geojson GeoJSON object
+ * @param {string} [name="geojson"] name of the variable to display in error message
+ * @returns {string} GeoJSON type
+ * @example
+ * var point = {
+ * "type": "Feature",
+ * "properties": {},
+ * "geometry": {
+ * "type": "Point",
+ * "coordinates": [110, 40]
+ * }
+ * }
+ * var geom = turf.getType(point)
+ * //="Point"
+ */
+ function getType(geojson, name) {
+ if (geojson.type === "FeatureCollection") {
+ return "FeatureCollection";
+ }
+ if (geojson.type === "GeometryCollection") {
+ return "GeometryCollection";
+ }
+ if (geojson.type === "Feature" && geojson.geometry !== null) {
+ return geojson.geometry.type;
+ }
+ return geojson.type;
+ }
+ exports.getType = getType;
+ });
+
+ var lineclip_1$1 = lineclip$1;
+ var _default$1 = lineclip$1;
+
+ lineclip$1.polyline = lineclip$1;
+ lineclip$1.polygon = polygonclip$1;
+
+
+ // Cohen-Sutherland line clippign algorithm, adapted to efficiently
+ // handle polylines rather than just segments
+
+ function lineclip$1(points, bbox, result) {
+
+ var len = points.length,
+ codeA = bitCode$1(points[0], bbox),
+ part = [],
+ i, a, b, codeB, lastCode;
+
+ if (!result) result = [];
+
+ for (i = 1; i < len; i++) {
+ a = points[i - 1];
+ b = points[i];
+ codeB = lastCode = bitCode$1(b, bbox);
+
+ while (true) {
+
+ if (!(codeA | codeB)) { // accept
+ part.push(a);
+
+ if (codeB !== lastCode) { // segment went outside
+ part.push(b);
+
+ if (i < len - 1) { // start a new line
+ result.push(part);
+ part = [];
+ }
+ } else if (i === len - 1) {
+ part.push(b);
+ }
+ break;
+
+ } else if (codeA & codeB) { // trivial reject
+ break;
+
+ } else if (codeA) { // a outside, intersect with clip edge
+ a = intersect$1(a, b, codeA, bbox);
+ codeA = bitCode$1(a, bbox);
+
+ } else { // b outside
+ b = intersect$1(a, b, codeB, bbox);
+ codeB = bitCode$1(b, bbox);
+ }
+ }
+
+ codeA = lastCode;
+ }
+
+ if (part.length) result.push(part);
+
+ return result;
+ }
+
+ // Sutherland-Hodgeman polygon clipping algorithm
+
+ function polygonclip$1(points, bbox) {
+
+ var result, edge, prev, prevInside, i, p, inside;
+
+ // clip against each side of the clip rectangle
+ for (edge = 1; edge <= 8; edge *= 2) {
+ result = [];
+ prev = points[points.length - 1];
+ prevInside = !(bitCode$1(prev, bbox) & edge);
+
+ for (i = 0; i < points.length; i++) {
+ p = points[i];
+ inside = !(bitCode$1(p, bbox) & edge);
+
+ // if segment goes through the clip window, add an intersection
+ if (inside !== prevInside) result.push(intersect$1(prev, p, edge, bbox));
+
+ if (inside) result.push(p); // add a point if it's inside
+
+ prev = p;
+ prevInside = inside;
+ }
+
+ points = result;
+
+ if (!points.length) break;
+ }
+
+ return result;
+ }
+
+ // intersect a segment against one of the 4 lines that make up the bbox
+
+ function intersect$1(a, b, edge, bbox) {
+ return edge & 8 ? [a[0] + (b[0] - a[0]) * (bbox[3] - a[1]) / (b[1] - a[1]), bbox[3]] : // top
+ edge & 4 ? [a[0] + (b[0] - a[0]) * (bbox[1] - a[1]) / (b[1] - a[1]), bbox[1]] : // bottom
+ edge & 2 ? [bbox[2], a[1] + (b[1] - a[1]) * (bbox[2] - a[0]) / (b[0] - a[0])] : // right
+ edge & 1 ? [bbox[0], a[1] + (b[1] - a[1]) * (bbox[0] - a[0]) / (b[0] - a[0])] : // left
+ null;
+ }
+
+ // bit code reflects the point position relative to the bbox:
+
+ // left mid right
+ // top 1001 1000 1010
+ // mid 0001 0000 0010
+ // bottom 0101 0100 0110
+
+ function bitCode$1(p, bbox) {
+ var code = 0;
+
+ if (p[0] < bbox[0]) code |= 1; // left
+ else if (p[0] > bbox[2]) code |= 2; // right
+
+ if (p[1] < bbox[1]) code |= 4; // bottom
+ else if (p[1] > bbox[3]) code |= 8; // top
+
+ return code;
+ }
+ lineclip_1$1.default = _default$1;
+
+ var bboxClip_1 = createCommonjsModule(function (module, exports) {
+ var __importStar = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) {
+ if (mod && mod.__esModule) return mod;
+ var result = {};
+ if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+ result["default"] = mod;
+ return result;
+ };
+ Object.defineProperty(exports, "__esModule", { value: true });
+
+
+ var lineclip = __importStar(lineclip_1$1);
+ /**
+ * Takes a {@link Feature} and a bbox and clips the feature to the bbox using
+ * [lineclip](https://github.com/mapbox/lineclip).
+ * May result in degenerate edges when clipping Polygons.
+ *
+ * @name bboxClip
+ * @param {Feature} feature feature to clip to the bbox
+ * @param {BBox} bbox extent in [minX, minY, maxX, maxY] order
+ * @returns {Feature} clipped Feature
+ * @example
+ * var bbox = [0, 0, 10, 10];
+ * var poly = turf.polygon([[[2, 2], [8, 4], [12, 8], [3, 7], [2, 2]]]);
+ *
+ * var clipped = turf.bboxClip(poly, bbox);
+ *
+ * //addToMap
+ * var addToMap = [bbox, poly, clipped]
+ */
+ function bboxClip(feature, bbox) {
+ var geom = invariant.getGeom(feature);
+ var type = geom.type;
+ var properties = feature.type === "Feature" ? feature.properties : {};
+ var coords = geom.coordinates;
+ switch (type) {
+ case "LineString":
+ case "MultiLineString":
+ var lines_1 = [];
+ if (type === "LineString") {
+ coords = [coords];
+ }
+ coords.forEach(function (line) {
+ lineclip.polyline(line, bbox, lines_1);
+ });
+ if (lines_1.length === 1) {
+ return helpers$1.lineString(lines_1[0], properties);
+ }
+ return helpers$1.multiLineString(lines_1, properties);
+ case "Polygon":
+ return helpers$1.polygon(clipPolygon(coords, bbox), properties);
+ case "MultiPolygon":
+ return helpers$1.multiPolygon(coords.map(function (poly) {
+ return clipPolygon(poly, bbox);
+ }), properties);
+ default:
+ throw new Error("geometry " + type + " not supported");
+ }
+ }
+ exports.default = bboxClip;
+ function clipPolygon(rings, bbox) {
+ var outRings = [];
+ for (var _i = 0, rings_1 = rings; _i < rings_1.length; _i++) {
+ var ring = rings_1[_i];
+ var clipped = lineclip.polygon(ring, bbox);
+ if (clipped.length > 0) {
+ if (clipped[0][0] !== clipped[clipped.length - 1][0] || clipped[0][1] !== clipped[clipped.length - 1][1]) {
+ clipped.push(clipped[0]);
+ }
+ if (clipped.length >= 4) {
+ outRings.push(clipped);
+ }
+ }
+ }
+ return outRings;
+ }
+ });
+
+ function DEFAULT_COMPARE (a, b) { return a > b ? 1 : a < b ? -1 : 0; }
+
+ class SplayTree {
+
+ constructor(compare = DEFAULT_COMPARE, noDuplicates = false) {
+ this._compare = compare;
+ this._root = null;
+ this._size = 0;
+ this._noDuplicates = !!noDuplicates;
+ }
+
+
+ rotateLeft(x) {
+ var y = x.right;
+ if (y) {
+ x.right = y.left;
+ if (y.left) y.left.parent = x;
+ y.parent = x.parent;
+ }
+
+ if (!x.parent) this._root = y;
+ else if (x === x.parent.left) x.parent.left = y;
+ else x.parent.right = y;
+ if (y) y.left = x;
+ x.parent = y;
+ }
+
+
+ rotateRight(x) {
+ var y = x.left;
+ if (y) {
+ x.left = y.right;
+ if (y.right) y.right.parent = x;
+ y.parent = x.parent;
+ }
+
+ if (!x.parent) this._root = y;
+ else if(x === x.parent.left) x.parent.left = y;
+ else x.parent.right = y;
+ if (y) y.right = x;
+ x.parent = y;
+ }
+
+
+ _splay(x) {
+ while (x.parent) {
+ var p = x.parent;
+ if (!p.parent) {
+ if (p.left === x) this.rotateRight(p);
+ else this.rotateLeft(p);
+ } else if (p.left === x && p.parent.left === p) {
+ this.rotateRight(p.parent);
+ this.rotateRight(p);
+ } else if (p.right === x && p.parent.right === p) {
+ this.rotateLeft(p.parent);
+ this.rotateLeft(p);
+ } else if (p.left === x && p.parent.right === p) {
+ this.rotateRight(p);
+ this.rotateLeft(p);
+ } else {
+ this.rotateLeft(p);
+ this.rotateRight(p);
+ }
+ }
+ }
+
+
+ splay(x) {
+ var p, gp, ggp, l, r;
+
+ while (x.parent) {
+ p = x.parent;
+ gp = p.parent;
+
+ if (gp && gp.parent) {
+ ggp = gp.parent;
+ if (ggp.left === gp) ggp.left = x;
+ else ggp.right = x;
+ x.parent = ggp;
+ } else {
+ x.parent = null;
+ this._root = x;
+ }
+
+ l = x.left; r = x.right;
+
+ if (x === p.left) { // left
+ if (gp) {
+ if (gp.left === p) {
+ /* zig-zig */
+ if (p.right) {
+ gp.left = p.right;
+ gp.left.parent = gp;
+ } else gp.left = null;
+
+ p.right = gp;
+ gp.parent = p;
+ } else {
+ /* zig-zag */
+ if (l) {
+ gp.right = l;
+ l.parent = gp;
+ } else gp.right = null;
+
+ x.left = gp;
+ gp.parent = x;
+ }
+ }
+ if (r) {
+ p.left = r;
+ r.parent = p;
+ } else p.left = null;
+
+ x.right = p;
+ p.parent = x;
+ } else { // right
+ if (gp) {
+ if (gp.right === p) {
+ /* zig-zig */
+ if (p.left) {
+ gp.right = p.left;
+ gp.right.parent = gp;
+ } else gp.right = null;
+
+ p.left = gp;
+ gp.parent = p;
+ } else {
+ /* zig-zag */
+ if (r) {
+ gp.left = r;
+ r.parent = gp;
+ } else gp.left = null;
+
+ x.right = gp;
+ gp.parent = x;
+ }
+ }
+ if (l) {
+ p.right = l;
+ l.parent = p;
+ } else p.right = null;
+
+ x.left = p;
+ p.parent = x;
+ }
+ }
+ }
+
+
+ replace(u, v) {
+ if (!u.parent) this._root = v;
+ else if (u === u.parent.left) u.parent.left = v;
+ else u.parent.right = v;
+ if (v) v.parent = u.parent;
+ }
+
+
+ minNode(u = this._root) {
+ if (u) while (u.left) u = u.left;
+ return u;
+ }
+
+
+ maxNode(u = this._root) {
+ if (u) while (u.right) u = u.right;
+ return u;
+ }
+
+
+ insert(key, data) {
+ var z = this._root;
+ var p = null;
+ var comp = this._compare;
+ var cmp;
+
+ if (this._noDuplicates) {
+ while (z) {
+ p = z;
+ cmp = comp(z.key, key);
+ if (cmp === 0) return;
+ else if (comp(z.key, key) < 0) z = z.right;
+ else z = z.left;
+ }
+ } else {
+ while (z) {
+ p = z;
+ if (comp(z.key, key) < 0) z = z.right;
+ else z = z.left;
+ }
+ }
+
+ z = { key, data, left: null, right: null, parent: p };
+
+ if (!p) this._root = z;
+ else if (comp(p.key, z.key) < 0) p.right = z;
+ else p.left = z;
+
+ this.splay(z);
+ this._size++;
+ return z;
+ }
+
+
+ find (key) {
+ var z = this._root;
+ var comp = this._compare;
+ while (z) {
+ var cmp = comp(z.key, key);
+ if (cmp < 0) z = z.right;
+ else if (cmp > 0) z = z.left;
+ else return z;
+ }
+ return null;
+ }
+
+ /**
+ * Whether the tree contains a node with the given key
+ * @param {Key} key
+ * @return {boolean} true/false
+ */
+ contains (key) {
+ var node = this._root;
+ var comparator = this._compare;
+ while (node) {
+ var cmp = comparator(key, node.key);
+ if (cmp === 0) return true;
+ else if (cmp < 0) node = node.left;
+ else node = node.right;
+ }
+
+ return false;
+ }
+
+
+ remove (key) {
+ var z = this.find(key);
+
+ if (!z) return false;
+
+ this.splay(z);
+
+ if (!z.left) this.replace(z, z.right);
+ else if (!z.right) this.replace(z, z.left);
+ else {
+ var y = this.minNode(z.right);
+ if (y.parent !== z) {
+ this.replace(y, y.right);
+ y.right = z.right;
+ y.right.parent = y;
+ }
+ this.replace(z, y);
+ y.left = z.left;
+ y.left.parent = y;
+ }
+
+ this._size--;
+ return true;
+ }
+
+
+ removeNode(z) {
+ if (!z) return false;
+
+ this.splay(z);
+
+ if (!z.left) this.replace(z, z.right);
+ else if (!z.right) this.replace(z, z.left);
+ else {
+ var y = this.minNode(z.right);
+ if (y.parent !== z) {
+ this.replace(y, y.right);
+ y.right = z.right;
+ y.right.parent = y;
+ }
+ this.replace(z, y);
+ y.left = z.left;
+ y.left.parent = y;
+ }
+
+ this._size--;
+ return true;
+ }
+
+
+ erase (key) {
+ var z = this.find(key);
+ if (!z) return;
+
+ this.splay(z);
+
+ var s = z.left;
+ var t = z.right;
+
+ var sMax = null;
+ if (s) {
+ s.parent = null;
+ sMax = this.maxNode(s);
+ this.splay(sMax);
+ this._root = sMax;
+ }
+ if (t) {
+ if (s) sMax.right = t;
+ else this._root = t;
+ t.parent = sMax;
+ }
+
+ this._size--;
+ }
+
+ /**
+ * Removes and returns the node with smallest key
+ * @return {?Node}
+ */
+ pop () {
+ var node = this._root, returnValue = null;
+ if (node) {
+ while (node.left) node = node.left;
+ returnValue = { key: node.key, data: node.data };
+ this.remove(node.key);
+ }
+ return returnValue;
+ }
+
+
+ /* eslint-disable class-methods-use-this */
+
+ /**
+ * Successor node
+ * @param {Node} node
+ * @return {?Node}
+ */
+ next (node) {
+ var successor = node;
+ if (successor) {
+ if (successor.right) {
+ successor = successor.right;
+ while (successor && successor.left) successor = successor.left;
+ } else {
+ successor = node.parent;
+ while (successor && successor.right === node) {
+ node = successor; successor = successor.parent;
+ }
+ }
+ }
+ return successor;
+ }
+
+
+ /**
+ * Predecessor node
+ * @param {Node} node
+ * @return {?Node}
+ */
+ prev (node) {
+ var predecessor = node;
+ if (predecessor) {
+ if (predecessor.left) {
+ predecessor = predecessor.left;
+ while (predecessor && predecessor.right) predecessor = predecessor.right;
+ } else {
+ predecessor = node.parent;
+ while (predecessor && predecessor.left === node) {
+ node = predecessor;
+ predecessor = predecessor.parent;
+ }
+ }
+ }
+ return predecessor;
+ }
+ /* eslint-enable class-methods-use-this */
+
+
+ /**
+ * @param {forEachCallback} callback
+ * @return {SplayTree}
+ */
+ forEach(callback) {
+ var current = this._root;
+ var s = [], done = false, i = 0;
+
+ while (!done) {
+ // Reach the left most Node of the current Node
+ if (current) {
+ // Place pointer to a tree node on the stack
+ // before traversing the node's left subtree
+ s.push(current);
+ current = current.left;
+ } else {
+ // BackTrack from the empty subtree and visit the Node
+ // at the top of the stack; however, if the stack is
+ // empty you are done
+ if (s.length > 0) {
+ current = s.pop();
+ callback(current, i++);
+
+ // We have visited the node and its left
+ // subtree. Now, it's right subtree's turn
+ current = current.right;
+ } else done = true;
+ }
+ }
+ return this;
+ }
+
+
+ /**
+ * Walk key range from `low` to `high`. Stops if `fn` returns a value.
+ * @param {Key} low
+ * @param {Key} high
+ * @param {Function} fn
+ * @param {*?} ctx
+ * @return {SplayTree}
+ */
+ range(low, high, fn, ctx) {
+ const Q = [];
+ const compare = this._compare;
+ let node = this._root, cmp;
+
+ while (Q.length !== 0 || node) {
+ if (node) {
+ Q.push(node);
+ node = node.left;
+ } else {
+ node = Q.pop();
+ cmp = compare(node.key, high);
+ if (cmp > 0) {
+ break;
+ } else if (compare(node.key, low) >= 0) {
+ if (fn.call(ctx, node)) return this; // stop if smth is returned
+ }
+ node = node.right;
+ }
+ }
+ return this;
+ }
+
+ /**
+ * Returns all keys in order
+ * @return {Array}
+ */
+ keys () {
+ var current = this._root;
+ var s = [], r = [], done = false;
+
+ while (!done) {
+ if (current) {
+ s.push(current);
+ current = current.left;
+ } else {
+ if (s.length > 0) {
+ current = s.pop();
+ r.push(current.key);
+ current = current.right;
+ } else done = true;
+ }
+ }
+ return r;
+ }
+
+
+ /**
+ * Returns `data` fields of all nodes in order.
+ * @return {Array}
+ */
+ values () {
+ var current = this._root;
+ var s = [], r = [], done = false;
+
+ while (!done) {
+ if (current) {
+ s.push(current);
+ current = current.left;
+ } else {
+ if (s.length > 0) {
+ current = s.pop();
+ r.push(current.data);
+ current = current.right;
+ } else done = true;
+ }
+ }
+ return r;
+ }
+
+
+ /**
+ * Returns node at given index
+ * @param {number} index
+ * @return {?Node}
+ */
+ at (index) {
+ // removed after a consideration, more misleading than useful
+ // index = index % this.size;
+ // if (index < 0) index = this.size - index;
+
+ var current = this._root;
+ var s = [], done = false, i = 0;
+
+ while (!done) {
+ if (current) {
+ s.push(current);
+ current = current.left;
+ } else {
+ if (s.length > 0) {
+ current = s.pop();
+ if (i === index) return current;
+ i++;
+ current = current.right;
+ } else done = true;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Bulk-load items. Both array have to be same size
+ * @param {Array} keys
+ * @param {Array} [values]
+ * @param {Boolean} [presort=false] Pre-sort keys and values, using
+ * tree's comparator. Sorting is done
+ * in-place
+ * @return {AVLTree}
+ */
+ load(keys = [], values = [], presort = false) {
+ if (this._size !== 0) throw new Error('bulk-load: tree is not empty');
+ const size = keys.length;
+ if (presort) sort(keys, values, 0, size - 1, this._compare);
+ this._root = loadRecursive(null, keys, values, 0, size);
+ this._size = size;
+ return this;
+ }
+
+
+ min() {
+ var node = this.minNode(this._root);
+ if (node) return node.key;
+ else return null;
+ }
+
+
+ max() {
+ var node = this.maxNode(this._root);
+ if (node) return node.key;
+ else return null;
+ }
+
+ isEmpty() { return this._root === null; }
+ get size() { return this._size; }
+
+
+ /**
+ * Create a tree and load it with items
+ * @param {Array} keys
+ * @param {Array?} [values]
+
+ * @param {Function?} [comparator]
+ * @param {Boolean?} [presort=false] Pre-sort keys and values, using
+ * tree's comparator. Sorting is done
+ * in-place
+ * @param {Boolean?} [noDuplicates=false] Allow duplicates
+ * @return {SplayTree}
+ */
+ static createTree(keys, values, comparator, presort, noDuplicates) {
+ return new SplayTree(comparator, noDuplicates).load(keys, values, presort);
+ }
+ }
+
+
+ function loadRecursive (parent, keys, values, start, end) {
+ const size = end - start;
+ if (size > 0) {
+ const middle = start + Math.floor(size / 2);
+ const key = keys[middle];
+ const data = values[middle];
+ const node = { key, data, parent };
+ node.left = loadRecursive(node, keys, values, start, middle);
+ node.right = loadRecursive(node, keys, values, middle + 1, end);
+ return node;
+ }
+ return null;
+ }
+
+
+ function sort(keys, values, left, right, compare) {
+ if (left >= right) return;
+
+ const pivot = keys[(left + right) >> 1];
+ let i = left - 1;
+ let j = right + 1;
+
+ while (true) {
+ do i++; while (compare(keys[i], pivot) < 0);
+ do j--; while (compare(keys[j], pivot) > 0);
+ if (i >= j) break;
+
+ let tmp = keys[i];
+ keys[i] = keys[j];
+ keys[j] = tmp;
+
+ tmp = values[i];
+ values[i] = values[j];
+ values[j] = tmp;
+ }
+
+ sort(keys, values, left, j, compare);
+ sort(keys, values, j + 1, right, compare);
+ }
+
+ const NORMAL = 0;
+ const NON_CONTRIBUTING = 1;
+ const SAME_TRANSITION = 2;
+ const DIFFERENT_TRANSITION = 3;
+
+ const INTERSECTION = 0;
+ const UNION = 1;
+ const DIFFERENCE = 2;
+ const XOR = 3;
+
+ /**
+ * @param {SweepEvent} event
+ * @param {SweepEvent} prev
+ * @param {Operation} operation
+ */
+ function computeFields (event, prev, operation) {
+ // compute inOut and otherInOut fields
+ if (prev === null) {
+ event.inOut = false;
+ event.otherInOut = true;
+
+ // previous line segment in sweepline belongs to the same polygon
+ } else {
+ if (event.isSubject === prev.isSubject) {
+ event.inOut = !prev.inOut;
+ event.otherInOut = prev.otherInOut;
+
+ // previous line segment in sweepline belongs to the clipping polygon
+ } else {
+ event.inOut = !prev.otherInOut;
+ event.otherInOut = prev.isVertical() ? !prev.inOut : prev.inOut;
+ }
+
+ // compute prevInResult field
+ if (prev) {
+ event.prevInResult = (!inResult(prev, operation) || prev.isVertical())
+ ? prev.prevInResult : prev;
+ }
+ }
+
+ // check if the line segment belongs to the Boolean operation
+ let isInResult = inResult(event, operation);
+ if (isInResult) {
+ event.resultTransition = determineResultTransition(event, operation);
+ } else {
+ event.resultTransition = 0;
+ }
+ }
+
+
+ /* eslint-disable indent */
+ function inResult(event, operation) {
+ switch (event.type) {
+ case NORMAL:
+ switch (operation) {
+ case INTERSECTION:
+ return !event.otherInOut;
+ case UNION:
+ return event.otherInOut;
+ case DIFFERENCE:
+ // return (event.isSubject && !event.otherInOut) ||
+ // (!event.isSubject && event.otherInOut);
+ return (event.isSubject && event.otherInOut) ||
+ (!event.isSubject && !event.otherInOut);
+ case XOR:
+ return true;
+ }
+ break;
+ case SAME_TRANSITION:
+ return operation === INTERSECTION || operation === UNION;
+ case DIFFERENT_TRANSITION:
+ return operation === DIFFERENCE;
+ case NON_CONTRIBUTING:
+ return false;
+ }
+ return false;
+ }
+ /* eslint-enable indent */
+
+
+ function determineResultTransition(event, operation) {
+ let thisIn = !event.inOut;
+ let thatIn = !event.otherInOut;
+
+ let isIn;
+ switch (operation) {
+ case INTERSECTION:
+ isIn = thisIn && thatIn; break;
+ case UNION:
+ isIn = thisIn || thatIn; break;
+ case XOR:
+ isIn = thisIn ^ thatIn; break;
+ case DIFFERENCE:
+ if (event.isSubject) {
+ isIn = thisIn && !thatIn;
+ } else {
+ isIn = thatIn && !thisIn;
+ }
+ break;
+ }
+ return isIn ? +1 : -1;
+ }
+
+ class SweepEvent {
+
+
+ /**
+ * Sweepline event
+ *
+ * @class {SweepEvent}
+ * @param {Array.} point
+ * @param {Boolean} left
+ * @param {SweepEvent=} otherEvent
+ * @param {Boolean} isSubject
+ * @param {Number} edgeType
+ */
+ constructor (point, left, otherEvent, isSubject, edgeType) {
+
+ /**
+ * Is left endpoint?
+ * @type {Boolean}
+ */
+ this.left = left;
+
+ /**
+ * @type {Array.}
+ */
+ this.point = point;
+
+ /**
+ * Other edge reference
+ * @type {SweepEvent}
+ */
+ this.otherEvent = otherEvent;
+
+ /**
+ * Belongs to source or clipping polygon
+ * @type {Boolean}
+ */
+ this.isSubject = isSubject;
+
+ /**
+ * Edge contribution type
+ * @type {Number}
+ */
+ this.type = edgeType || NORMAL;
+
+
+ /**
+ * In-out transition for the sweepline crossing polygon
+ * @type {Boolean}
+ */
+ this.inOut = false;
+
+
+ /**
+ * @type {Boolean}
+ */
+ this.otherInOut = false;
+
+ /**
+ * Previous event in result?
+ * @type {SweepEvent}
+ */
+ this.prevInResult = null;
+
+ /**
+ * Type of result transition (0 = not in result, +1 = out-in, -1, in-out)
+ * @type {Number}
+ */
+ this.resultTransition = 0;
+
+ // connection step
+
+ /**
+ * @type {Number}
+ */
+ this.otherPos = -1;
+
+ /**
+ * @type {Number}
+ */
+ this.outputContourId = -1;
+
+ this.isExteriorRing = true; // TODO: Looks unused, remove?
+ }
+
+
+ /**
+ * @param {Array.} p
+ * @return {Boolean}
+ */
+ isBelow (p) {
+ const p0 = this.point, p1 = this.otherEvent.point;
+ return this.left
+ ? (p0[0] - p[0]) * (p1[1] - p[1]) - (p1[0] - p[0]) * (p0[1] - p[1]) > 0
+ // signedArea(this.point, this.otherEvent.point, p) > 0 :
+ : (p1[0] - p[0]) * (p0[1] - p[1]) - (p0[0] - p[0]) * (p1[1] - p[1]) > 0;
+ //signedArea(this.otherEvent.point, this.point, p) > 0;
+ }
+
+
+ /**
+ * @param {Array.} p
+ * @return {Boolean}
+ */
+ isAbove (p) {
+ return !this.isBelow(p);
+ }
+
+
+ /**
+ * @return {Boolean}
+ */
+ isVertical () {
+ return this.point[0] === this.otherEvent.point[0];
+ }
+
+
+ /**
+ * Does event belong to result?
+ * @return {Boolean}
+ */
+ get inResult() {
+ return this.resultTransition !== 0;
+ }
+
+
+ clone () {
+ const copy = new SweepEvent(
+ this.point, this.left, this.otherEvent, this.isSubject, this.type);
+
+ copy.contourId = this.contourId;
+ copy.resultTransition = this.resultTransition;
+ copy.prevInResult = this.prevInResult;
+ copy.isExteriorRing = this.isExteriorRing;
+ copy.inOut = this.inOut;
+ copy.otherInOut = this.otherInOut;
+
+ return copy;
+ }
+ }
+
+ function equals(p1, p2) {
+ if (p1[0] === p2[0]) {
+ if (p1[1] === p2[1]) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ return false;
+ }
+
+ // const EPSILON = 1e-9;
+ // const abs = Math.abs;
+ // TODO https://github.com/w8r/martinez/issues/6#issuecomment-262847164
+ // Precision problem.
+ //
+ // module.exports = function equals(p1, p2) {
+ // return abs(p1[0] - p2[0]) <= EPSILON && abs(p1[1] - p2[1]) <= EPSILON;
+ // };
+
+ const epsilon$1 = 1.1102230246251565e-16;
+ const splitter = 134217729;
+ const resulterrbound = (3 + 8 * epsilon$1) * epsilon$1;
+
+ // fast_expansion_sum_zeroelim routine from oritinal code
+ function sum$1(elen, e, flen, f, h) {
+ let Q, Qnew, hh, bvirt;
+ let enow = e[0];
+ let fnow = f[0];
+ let eindex = 0;
+ let findex = 0;
+ if ((fnow > enow) === (fnow > -enow)) {
+ Q = enow;
+ enow = e[++eindex];
+ } else {
+ Q = fnow;
+ fnow = f[++findex];
+ }
+ let hindex = 0;
+ if (eindex < elen && findex < flen) {
+ if ((fnow > enow) === (fnow > -enow)) {
+ Qnew = enow + Q;
+ hh = Q - (Qnew - enow);
+ enow = e[++eindex];
+ } else {
+ Qnew = fnow + Q;
+ hh = Q - (Qnew - fnow);
+ fnow = f[++findex];
+ }
+ Q = Qnew;
+ if (hh !== 0) {
+ h[hindex++] = hh;
+ }
+ while (eindex < elen && findex < flen) {
+ if ((fnow > enow) === (fnow > -enow)) {
+ Qnew = Q + enow;
+ bvirt = Qnew - Q;
+ hh = Q - (Qnew - bvirt) + (enow - bvirt);
+ enow = e[++eindex];
+ } else {
+ Qnew = Q + fnow;
+ bvirt = Qnew - Q;
+ hh = Q - (Qnew - bvirt) + (fnow - bvirt);
+ fnow = f[++findex];
+ }
+ Q = Qnew;
+ if (hh !== 0) {
+ h[hindex++] = hh;
+ }
+ }
+ }
+ while (eindex < elen) {
+ Qnew = Q + enow;
+ bvirt = Qnew - Q;
+ hh = Q - (Qnew - bvirt) + (enow - bvirt);
+ enow = e[++eindex];
+ Q = Qnew;
+ if (hh !== 0) {
+ h[hindex++] = hh;
+ }
+ }
+ while (findex < flen) {
+ Qnew = Q + fnow;
+ bvirt = Qnew - Q;
+ hh = Q - (Qnew - bvirt) + (fnow - bvirt);
+ fnow = f[++findex];
+ Q = Qnew;
+ if (hh !== 0) {
+ h[hindex++] = hh;
+ }
+ }
+ if (Q !== 0 || hindex === 0) {
+ h[hindex++] = Q;
+ }
+ return hindex;
+ }
+
+ function estimate(elen, e) {
+ let Q = e[0];
+ for (let i = 1; i < elen; i++) Q += e[i];
+ return Q;
+ }
+
+ function vec(n) {
+ return new Float64Array(n);
+ }
+
+ const ccwerrboundA = (3 + 16 * epsilon$1) * epsilon$1;
+ const ccwerrboundB = (2 + 12 * epsilon$1) * epsilon$1;
+ const ccwerrboundC = (9 + 64 * epsilon$1) * epsilon$1 * epsilon$1;
+
+ const B = vec(4);
+ const C1 = vec(8);
+ const C2 = vec(12);
+ const D = vec(16);
+ const u = vec(4);
+
+ function orient2dadapt(ax, ay, bx, by, cx, cy, detsum) {
+ let acxtail, acytail, bcxtail, bcytail;
+ let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3;
+
+ const acx = ax - cx;
+ const bcx = bx - cx;
+ const acy = ay - cy;
+ const bcy = by - cy;
+
+ s1 = acx * bcy;
+ c = splitter * acx;
+ ahi = c - (c - acx);
+ alo = acx - ahi;
+ c = splitter * bcy;
+ bhi = c - (c - bcy);
+ blo = bcy - bhi;
+ s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
+ t1 = acy * bcx;
+ c = splitter * acy;
+ ahi = c - (c - acy);
+ alo = acy - ahi;
+ c = splitter * bcx;
+ bhi = c - (c - bcx);
+ blo = bcx - bhi;
+ t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
+ _i = s0 - t0;
+ bvirt = s0 - _i;
+ B[0] = s0 - (_i + bvirt) + (bvirt - t0);
+ _j = s1 + _i;
+ bvirt = _j - s1;
+ _0 = s1 - (_j - bvirt) + (_i - bvirt);
+ _i = _0 - t1;
+ bvirt = _0 - _i;
+ B[1] = _0 - (_i + bvirt) + (bvirt - t1);
+ u3 = _j + _i;
+ bvirt = u3 - _j;
+ B[2] = _j - (u3 - bvirt) + (_i - bvirt);
+ B[3] = u3;
+
+ let det = estimate(4, B);
+ let errbound = ccwerrboundB * detsum;
+ if (det >= errbound || -det >= errbound) {
+ return det;
+ }
+
+ bvirt = ax - acx;
+ acxtail = ax - (acx + bvirt) + (bvirt - cx);
+ bvirt = bx - bcx;
+ bcxtail = bx - (bcx + bvirt) + (bvirt - cx);
+ bvirt = ay - acy;
+ acytail = ay - (acy + bvirt) + (bvirt - cy);
+ bvirt = by - bcy;
+ bcytail = by - (bcy + bvirt) + (bvirt - cy);
+
+ if (acxtail === 0 && acytail === 0 && bcxtail === 0 && bcytail === 0) {
+ return det;
+ }
+
+ errbound = ccwerrboundC * detsum + resulterrbound * Math.abs(det);
+ det += (acx * bcytail + bcy * acxtail) - (acy * bcxtail + bcx * acytail);
+ if (det >= errbound || -det >= errbound) return det;
+
+ s1 = acxtail * bcy;
+ c = splitter * acxtail;
+ ahi = c - (c - acxtail);
+ alo = acxtail - ahi;
+ c = splitter * bcy;
+ bhi = c - (c - bcy);
+ blo = bcy - bhi;
+ s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
+ t1 = acytail * bcx;
+ c = splitter * acytail;
+ ahi = c - (c - acytail);
+ alo = acytail - ahi;
+ c = splitter * bcx;
+ bhi = c - (c - bcx);
+ blo = bcx - bhi;
+ t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
+ _i = s0 - t0;
+ bvirt = s0 - _i;
+ u[0] = s0 - (_i + bvirt) + (bvirt - t0);
+ _j = s1 + _i;
+ bvirt = _j - s1;
+ _0 = s1 - (_j - bvirt) + (_i - bvirt);
+ _i = _0 - t1;
+ bvirt = _0 - _i;
+ u[1] = _0 - (_i + bvirt) + (bvirt - t1);
+ u3 = _j + _i;
+ bvirt = u3 - _j;
+ u[2] = _j - (u3 - bvirt) + (_i - bvirt);
+ u[3] = u3;
+ const C1len = sum$1(4, B, 4, u, C1);
+
+ s1 = acx * bcytail;
+ c = splitter * acx;
+ ahi = c - (c - acx);
+ alo = acx - ahi;
+ c = splitter * bcytail;
+ bhi = c - (c - bcytail);
+ blo = bcytail - bhi;
+ s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
+ t1 = acy * bcxtail;
+ c = splitter * acy;
+ ahi = c - (c - acy);
+ alo = acy - ahi;
+ c = splitter * bcxtail;
+ bhi = c - (c - bcxtail);
+ blo = bcxtail - bhi;
+ t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
+ _i = s0 - t0;
+ bvirt = s0 - _i;
+ u[0] = s0 - (_i + bvirt) + (bvirt - t0);
+ _j = s1 + _i;
+ bvirt = _j - s1;
+ _0 = s1 - (_j - bvirt) + (_i - bvirt);
+ _i = _0 - t1;
+ bvirt = _0 - _i;
+ u[1] = _0 - (_i + bvirt) + (bvirt - t1);
+ u3 = _j + _i;
+ bvirt = u3 - _j;
+ u[2] = _j - (u3 - bvirt) + (_i - bvirt);
+ u[3] = u3;
+ const C2len = sum$1(C1len, C1, 4, u, C2);
+
+ s1 = acxtail * bcytail;
+ c = splitter * acxtail;
+ ahi = c - (c - acxtail);
+ alo = acxtail - ahi;
+ c = splitter * bcytail;
+ bhi = c - (c - bcytail);
+ blo = bcytail - bhi;
+ s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
+ t1 = acytail * bcxtail;
+ c = splitter * acytail;
+ ahi = c - (c - acytail);
+ alo = acytail - ahi;
+ c = splitter * bcxtail;
+ bhi = c - (c - bcxtail);
+ blo = bcxtail - bhi;
+ t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
+ _i = s0 - t0;
+ bvirt = s0 - _i;
+ u[0] = s0 - (_i + bvirt) + (bvirt - t0);
+ _j = s1 + _i;
+ bvirt = _j - s1;
+ _0 = s1 - (_j - bvirt) + (_i - bvirt);
+ _i = _0 - t1;
+ bvirt = _0 - _i;
+ u[1] = _0 - (_i + bvirt) + (bvirt - t1);
+ u3 = _j + _i;
+ bvirt = u3 - _j;
+ u[2] = _j - (u3 - bvirt) + (_i - bvirt);
+ u[3] = u3;
+ const Dlen = sum$1(C2len, C2, 4, u, D);
+
+ return D[Dlen - 1];
+ }
+
+ function orient2d(ax, ay, bx, by, cx, cy) {
+ const detleft = (ay - cy) * (bx - cx);
+ const detright = (ax - cx) * (by - cy);
+ const det = detleft - detright;
+
+ if (detleft === 0 || detright === 0 || (detleft > 0) !== (detright > 0)) return det;
+
+ const detsum = Math.abs(detleft + detright);
+ if (Math.abs(det) >= ccwerrboundA * detsum) return det;
+
+ return -orient2dadapt(ax, ay, bx, by, cx, cy, detsum);
+ }
+
+ /**
+ * Signed area of the triangle (p0, p1, p2)
+ * @param {Array.} p0
+ * @param {Array.} p1
+ * @param {Array.} p2
+ * @return {Number}
+ */
+ function signedArea(p0, p1, p2) {
+ const res = orient2d(p0[0], p0[1], p1[0], p1[1], p2[0], p2[1]);
+ if (res > 0) return -1;
+ if (res < 0) return 1;
+ return 0;
+ }
+
+ /**
+ * @param {SweepEvent} e1
+ * @param {SweepEvent} e2
+ * @return {Number}
+ */
+ function compareEvents(e1, e2) {
+ const p1 = e1.point;
+ const p2 = e2.point;
+
+ // Different x-coordinate
+ if (p1[0] > p2[0]) return 1;
+ if (p1[0] < p2[0]) return -1;
+
+ // Different points, but same x-coordinate
+ // Event with lower y-coordinate is processed first
+ if (p1[1] !== p2[1]) return p1[1] > p2[1] ? 1 : -1;
+
+ return specialCases(e1, e2, p1);
+ }
+
+
+ /* eslint-disable no-unused-vars */
+ function specialCases(e1, e2, p1, p2) {
+ // Same coordinates, but one is a left endpoint and the other is
+ // a right endpoint. The right endpoint is processed first
+ if (e1.left !== e2.left)
+ return e1.left ? 1 : -1;
+
+ // const p2 = e1.otherEvent.point, p3 = e2.otherEvent.point;
+ // const sa = (p1[0] - p3[0]) * (p2[1] - p3[1]) - (p2[0] - p3[0]) * (p1[1] - p3[1])
+ // Same coordinates, both events
+ // are left endpoints or right endpoints.
+ // not collinear
+ if (signedArea(p1, e1.otherEvent.point, e2.otherEvent.point) !== 0) {
+ // the event associate to the bottom segment is processed first
+ return (!e1.isBelow(e2.otherEvent.point)) ? 1 : -1;
+ }
+
+ return (!e1.isSubject && e2.isSubject) ? 1 : -1;
+ }
+ /* eslint-enable no-unused-vars */
+
+ /**
+ * @param {SweepEvent} se
+ * @param {Array.} p
+ * @param {Queue} queue
+ * @return {Queue}
+ */
+ function divideSegment(se, p, queue) {
+ const r = new SweepEvent(p, false, se, se.isSubject);
+ const l = new SweepEvent(p, true, se.otherEvent, se.isSubject);
+
+ /* eslint-disable no-console */
+ if (equals(se.point, se.otherEvent.point)) {
+ console.warn('what is that, a collapsed segment?', se);
+ }
+ /* eslint-enable no-console */
+
+ r.contourId = l.contourId = se.contourId;
+
+ // avoid a rounding error. The left event would be processed after the right event
+ if (compareEvents(l, se.otherEvent) > 0) {
+ se.otherEvent.left = true;
+ l.left = false;
+ }
+
+ // avoid a rounding error. The left event would be processed after the right event
+ // if (compareEvents(se, r) > 0) {}
+
+ se.otherEvent.otherEvent = l;
+ se.otherEvent = r;
+
+ queue.push(l);
+ queue.push(r);
+
+ return queue;
+ }
+
+ //const EPS = 1e-9;
+
+ /**
+ * Finds the magnitude of the cross product of two vectors (if we pretend
+ * they're in three dimensions)
+ *
+ * @param {Object} a First vector
+ * @param {Object} b Second vector
+ * @private
+ * @returns {Number} The magnitude of the cross product
+ */
+ function crossProduct(a, b) {
+ return (a[0] * b[1]) - (a[1] * b[0]);
+ }
+
+ /**
+ * Finds the dot product of two vectors.
+ *
+ * @param {Object} a First vector
+ * @param {Object} b Second vector
+ * @private
+ * @returns {Number} The dot product
+ */
+ function dotProduct(a, b) {
+ return (a[0] * b[0]) + (a[1] * b[1]);
+ }
+
+ /**
+ * Finds the intersection (if any) between two line segments a and b, given the
+ * line segments' end points a1, a2 and b1, b2.
+ *
+ * This algorithm is based on Schneider and Eberly.
+ * http://www.cimec.org.ar/~ncalvo/Schneider_Eberly.pdf
+ * Page 244.
+ *
+ * @param {Array.} a1 point of first line
+ * @param {Array.} a2 point of first line
+ * @param {Array.} b1 point of second line
+ * @param {Array.} b2 point of second line
+ * @param {Boolean=} noEndpointTouch whether to skip single touchpoints
+ * (meaning connected segments) as
+ * intersections
+ * @returns {Array.>|Null} If the lines intersect, the point of
+ * intersection. If they overlap, the two end points of the overlapping segment.
+ * Otherwise, null.
+ */
+ function intersection (a1, a2, b1, b2, noEndpointTouch) {
+ // The algorithm expects our lines in the form P + sd, where P is a point,
+ // s is on the interval [0, 1], and d is a vector.
+ // We are passed two points. P can be the first point of each pair. The
+ // vector, then, could be thought of as the distance (in x and y components)
+ // from the first point to the second point.
+ // So first, let's make our vectors:
+ const va = [a2[0] - a1[0], a2[1] - a1[1]];
+ const vb = [b2[0] - b1[0], b2[1] - b1[1]];
+ // We also define a function to convert back to regular point form:
+
+ /* eslint-disable arrow-body-style */
+
+ function toPoint(p, s, d) {
+ return [
+ p[0] + s * d[0],
+ p[1] + s * d[1]
+ ];
+ }
+
+ /* eslint-enable arrow-body-style */
+
+ // The rest is pretty much a straight port of the algorithm.
+ const e = [b1[0] - a1[0], b1[1] - a1[1]];
+ let kross = crossProduct(va, vb);
+ let sqrKross = kross * kross;
+ const sqrLenA = dotProduct(va, va);
+ //const sqrLenB = dotProduct(vb, vb);
+
+ // Check for line intersection. This works because of the properties of the
+ // cross product -- specifically, two vectors are parallel if and only if the
+ // cross product is the 0 vector. The full calculation involves relative error
+ // to account for possible very small line segments. See Schneider & Eberly
+ // for details.
+ if (sqrKross > 0/* EPS * sqrLenB * sqLenA */) {
+ // If they're not parallel, then (because these are line segments) they
+ // still might not actually intersect. This code checks that the
+ // intersection point of the lines is actually on both line segments.
+ const s = crossProduct(e, vb) / kross;
+ if (s < 0 || s > 1) {
+ // not on line segment a
+ return null;
+ }
+ const t = crossProduct(e, va) / kross;
+ if (t < 0 || t > 1) {
+ // not on line segment b
+ return null;
+ }
+ if (s === 0 || s === 1) {
+ // on an endpoint of line segment a
+ return noEndpointTouch ? null : [toPoint(a1, s, va)];
+ }
+ if (t === 0 || t === 1) {
+ // on an endpoint of line segment b
+ return noEndpointTouch ? null : [toPoint(b1, t, vb)];
+ }
+ return [toPoint(a1, s, va)];
+ }
+
+ // If we've reached this point, then the lines are either parallel or the
+ // same, but the segments could overlap partially or fully, or not at all.
+ // So we need to find the overlap, if any. To do that, we can use e, which is
+ // the (vector) difference between the two initial points. If this is parallel
+ // with the line itself, then the two lines are the same line, and there will
+ // be overlap.
+ //const sqrLenE = dotProduct(e, e);
+ kross = crossProduct(e, va);
+ sqrKross = kross * kross;
+
+ if (sqrKross > 0 /* EPS * sqLenB * sqLenE */) {
+ // Lines are just parallel, not the same. No overlap.
+ return null;
+ }
+
+ const sa = dotProduct(va, e) / sqrLenA;
+ const sb = sa + dotProduct(va, vb) / sqrLenA;
+ const smin = Math.min(sa, sb);
+ const smax = Math.max(sa, sb);
+
+ // this is, essentially, the FindIntersection acting on floats from
+ // Schneider & Eberly, just inlined into this function.
+ if (smin <= 1 && smax >= 0) {
+
+ // overlap on an end point
+ if (smin === 1) {
+ return noEndpointTouch ? null : [toPoint(a1, smin > 0 ? smin : 0, va)];
+ }
+
+ if (smax === 0) {
+ return noEndpointTouch ? null : [toPoint(a1, smax < 1 ? smax : 1, va)];
+ }
+
+ if (noEndpointTouch && smin === 0 && smax === 1) return null;
+
+ // There's overlap on a segment -- two points of intersection. Return both.
+ return [
+ toPoint(a1, smin > 0 ? smin : 0, va),
+ toPoint(a1, smax < 1 ? smax : 1, va)
+ ];
+ }
+
+ return null;
+ }
+
+ /**
+ * @param {SweepEvent} se1
+ * @param {SweepEvent} se2
+ * @param {Queue} queue
+ * @return {Number}
+ */
+ function possibleIntersection (se1, se2, queue) {
+ // that disallows self-intersecting polygons,
+ // did cost us half a day, so I'll leave it
+ // out of respect
+ // if (se1.isSubject === se2.isSubject) return;
+ const inter = intersection(
+ se1.point, se1.otherEvent.point,
+ se2.point, se2.otherEvent.point
+ );
+
+ const nintersections = inter ? inter.length : 0;
+ if (nintersections === 0) return 0; // no intersection
+
+ // the line segments intersect at an endpoint of both line segments
+ if ((nintersections === 1) &&
+ (equals(se1.point, se2.point) ||
+ equals(se1.otherEvent.point, se2.otherEvent.point))) {
+ return 0;
+ }
+
+ if (nintersections === 2 && se1.isSubject === se2.isSubject) {
+ // if(se1.contourId === se2.contourId){
+ // console.warn('Edges of the same polygon overlap',
+ // se1.point, se1.otherEvent.point, se2.point, se2.otherEvent.point);
+ // }
+ //throw new Error('Edges of the same polygon overlap');
+ return 0;
+ }
+
+ // The line segments associated to se1 and se2 intersect
+ if (nintersections === 1) {
+
+ // if the intersection point is not an endpoint of se1
+ if (!equals(se1.point, inter[0]) && !equals(se1.otherEvent.point, inter[0])) {
+ divideSegment(se1, inter[0], queue);
+ }
+
+ // if the intersection point is not an endpoint of se2
+ if (!equals(se2.point, inter[0]) && !equals(se2.otherEvent.point, inter[0])) {
+ divideSegment(se2, inter[0], queue);
+ }
+ return 1;
+ }
+
+ // The line segments associated to se1 and se2 overlap
+ const events = [];
+ let leftCoincide = false;
+ let rightCoincide = false;
+
+ if (equals(se1.point, se2.point)) {
+ leftCoincide = true; // linked
+ } else if (compareEvents(se1, se2) === 1) {
+ events.push(se2, se1);
+ } else {
+ events.push(se1, se2);
+ }
+
+ if (equals(se1.otherEvent.point, se2.otherEvent.point)) {
+ rightCoincide = true;
+ } else if (compareEvents(se1.otherEvent, se2.otherEvent) === 1) {
+ events.push(se2.otherEvent, se1.otherEvent);
+ } else {
+ events.push(se1.otherEvent, se2.otherEvent);
+ }
+
+ if ((leftCoincide && rightCoincide) || leftCoincide) {
+ // both line segments are equal or share the left endpoint
+ se2.type = NON_CONTRIBUTING;
+ se1.type = (se2.inOut === se1.inOut)
+ ? SAME_TRANSITION : DIFFERENT_TRANSITION;
+
+ if (leftCoincide && !rightCoincide) {
+ // honestly no idea, but changing events selection from [2, 1]
+ // to [0, 1] fixes the overlapping self-intersecting polygons issue
+ divideSegment(events[1].otherEvent, events[0].point, queue);
+ }
+ return 2;
+ }
+
+ // the line segments share the right endpoint
+ if (rightCoincide) {
+ divideSegment(events[0], events[1].point, queue);
+ return 3;
+ }
+
+ // no line segment includes totally the other one
+ if (events[0] !== events[3].otherEvent) {
+ divideSegment(events[0], events[1].point, queue);
+ divideSegment(events[1], events[2].point, queue);
+ return 3;
+ }
+
+ // one line segment includes the other one
+ divideSegment(events[0], events[1].point, queue);
+ divideSegment(events[3].otherEvent, events[2].point, queue);
+
+ return 3;
+ }
+
+ /**
+ * @param {SweepEvent} le1
+ * @param {SweepEvent} le2
+ * @return {Number}
+ */
+ function compareSegments(le1, le2) {
+ if (le1 === le2) return 0;
+
+ // Segments are not collinear
+ if (signedArea(le1.point, le1.otherEvent.point, le2.point) !== 0 ||
+ signedArea(le1.point, le1.otherEvent.point, le2.otherEvent.point) !== 0) {
+
+ // If they share their left endpoint use the right endpoint to sort
+ if (equals(le1.point, le2.point)) return le1.isBelow(le2.otherEvent.point) ? -1 : 1;
+
+ // Different left endpoint: use the left endpoint to sort
+ if (le1.point[0] === le2.point[0]) return le1.point[1] < le2.point[1] ? -1 : 1;
+
+ // has the line segment associated to e1 been inserted
+ // into S after the line segment associated to e2 ?
+ if (compareEvents(le1, le2) === 1) return le2.isAbove(le1.point) ? -1 : 1;
+
+ // The line segment associated to e2 has been inserted
+ // into S after the line segment associated to e1
+ return le1.isBelow(le2.point) ? -1 : 1;
+ }
+
+ if (le1.isSubject === le2.isSubject) { // same polygon
+ let p1 = le1.point, p2 = le2.point;
+ if (p1[0] === p2[0] && p1[1] === p2[1]/*equals(le1.point, le2.point)*/) {
+ p1 = le1.otherEvent.point; p2 = le2.otherEvent.point;
+ if (p1[0] === p2[0] && p1[1] === p2[1]) return 0;
+ else return le1.contourId > le2.contourId ? 1 : -1;
+ }
+ } else { // Segments are collinear, but belong to separate polygons
+ return le1.isSubject ? -1 : 1;
+ }
+
+ return compareEvents(le1, le2) === 1 ? 1 : -1;
+ }
+
+ function subdivide(eventQueue, subject, clipping, sbbox, cbbox, operation) {
+ const sweepLine = new SplayTree(compareSegments);
+ const sortedEvents = [];
+
+ const rightbound = Math.min(sbbox[2], cbbox[2]);
+
+ let prev, next, begin;
+
+ while (eventQueue.length !== 0) {
+ let event = eventQueue.pop();
+ sortedEvents.push(event);
+
+ // optimization by bboxes for intersection and difference goes here
+ if ((operation === INTERSECTION && event.point[0] > rightbound) ||
+ (operation === DIFFERENCE && event.point[0] > sbbox[2])) {
+ break;
+ }
+
+ if (event.left) {
+ next = prev = sweepLine.insert(event);
+ begin = sweepLine.minNode();
+
+ if (prev !== begin) prev = sweepLine.prev(prev);
+ else prev = null;
+
+ next = sweepLine.next(next);
+
+ const prevEvent = prev ? prev.key : null;
+ let prevprevEvent;
+ computeFields(event, prevEvent, operation);
+ if (next) {
+ if (possibleIntersection(event, next.key, eventQueue) === 2) {
+ computeFields(event, prevEvent, operation);
+ computeFields(event, next.key, operation);
+ }
+ }
+
+ if (prev) {
+ if (possibleIntersection(prev.key, event, eventQueue) === 2) {
+ let prevprev = prev;
+ if (prevprev !== begin) prevprev = sweepLine.prev(prevprev);
+ else prevprev = null;
+
+ prevprevEvent = prevprev ? prevprev.key : null;
+ computeFields(prevEvent, prevprevEvent, operation);
+ computeFields(event, prevEvent, operation);
+ }
+ }
+ } else {
+ event = event.otherEvent;
+ next = prev = sweepLine.find(event);
+
+ if (prev && next) {
+
+ if (prev !== begin) prev = sweepLine.prev(prev);
+ else prev = null;
+
+ next = sweepLine.next(next);
+ sweepLine.remove(event);
+
+ if (next && prev) {
+ possibleIntersection(prev.key, next.key, eventQueue);
+ }
+ }
+ }
+ }
+ return sortedEvents;
+ }
+
+ class Contour {
+
+ /**
+ * Contour
+ *
+ * @class {Contour}
+ */
+ constructor() {
+ this.points = [];
+ this.holeIds = [];
+ this.holeOf = null;
+ this.depth = null;
+ }
+
+ isExterior() {
+ return this.holeOf == null;
+ }
+
+ }
+
+ /**
+ * @param {Array.} sortedEvents
+ * @return {Array.}
+ */
+ function orderEvents(sortedEvents) {
+ let event, i, len, tmp;
+ const resultEvents = [];
+ for (i = 0, len = sortedEvents.length; i < len; i++) {
+ event = sortedEvents[i];
+ if ((event.left && event.inResult) ||
+ (!event.left && event.otherEvent.inResult)) {
+ resultEvents.push(event);
+ }
+ }
+ // Due to overlapping edges the resultEvents array can be not wholly sorted
+ let sorted = false;
+ while (!sorted) {
+ sorted = true;
+ for (i = 0, len = resultEvents.length; i < len; i++) {
+ if ((i + 1) < len &&
+ compareEvents(resultEvents[i], resultEvents[i + 1]) === 1) {
+ tmp = resultEvents[i];
+ resultEvents[i] = resultEvents[i + 1];
+ resultEvents[i + 1] = tmp;
+ sorted = false;
+ }
+ }
+ }
+
+
+ for (i = 0, len = resultEvents.length; i < len; i++) {
+ event = resultEvents[i];
+ event.otherPos = i;
+ }
+
+ // imagine, the right event is found in the beginning of the queue,
+ // when his left counterpart is not marked yet
+ for (i = 0, len = resultEvents.length; i < len; i++) {
+ event = resultEvents[i];
+ if (!event.left) {
+ tmp = event.otherPos;
+ event.otherPos = event.otherEvent.otherPos;
+ event.otherEvent.otherPos = tmp;
+ }
+ }
+
+ return resultEvents;
+ }
+
+
+ /**
+ * @param {Number} pos
+ * @param {Array.} resultEvents
+ * @param {Object>} processed
+ * @return {Number}
+ */
+ function nextPos(pos, resultEvents, processed, origPos) {
+ let newPos = pos + 1,
+ p = resultEvents[pos].point,
+ p1;
+ const length = resultEvents.length;
+
+ if (newPos < length)
+ p1 = resultEvents[newPos].point;
+
+ while (newPos < length && p1[0] === p[0] && p1[1] === p[1]) {
+ if (!processed[newPos]) {
+ return newPos;
+ } else {
+ newPos++;
+ }
+ p1 = resultEvents[newPos].point;
+ }
+
+ newPos = pos - 1;
+
+ while (processed[newPos] && newPos > origPos) {
+ newPos--;
+ }
+
+ return newPos;
+ }
+
+
+ function initializeContourFromContext(event, contours, contourId) {
+ const contour = new Contour();
+ if (event.prevInResult != null) {
+ const prevInResult = event.prevInResult;
+ // Note that it is valid to query the "previous in result" for its output contour id,
+ // because we must have already processed it (i.e., assigned an output contour id)
+ // in an earlier iteration, otherwise it wouldn't be possible that it is "previous in
+ // result".
+ const lowerContourId = prevInResult.outputContourId;
+ const lowerResultTransition = prevInResult.resultTransition;
+ if (lowerResultTransition > 0) {
+ // We are inside. Now we have to check if the thing below us is another hole or
+ // an exterior contour.
+ const lowerContour = contours[lowerContourId];
+ if (lowerContour.holeOf != null) {
+ // The lower contour is a hole => Connect the new contour as a hole to its parent,
+ // and use same depth.
+ const parentContourId = lowerContour.holeOf;
+ contours[parentContourId].holeIds.push(contourId);
+ contour.holeOf = parentContourId;
+ contour.depth = contours[lowerContourId].depth;
+ } else {
+ // The lower contour is an exterior contour => Connect the new contour as a hole,
+ // and increment depth.
+ contours[lowerContourId].holeIds.push(contourId);
+ contour.holeOf = lowerContourId;
+ contour.depth = contours[lowerContourId].depth + 1;
+ }
+ } else {
+ // We are outside => this contour is an exterior contour of same depth.
+ contour.holeOf = null;
+ contour.depth = contours[lowerContourId].depth;
+ }
+ } else {
+ // There is no lower/previous contour => this contour is an exterior contour of depth 0.
+ contour.holeOf = null;
+ contour.depth = 0;
+ }
+ return contour;
+ }
+
+ /**
+ * @param {Array.} sortedEvents
+ * @return {Array.<*>} polygons
+ */
+ function connectEdges(sortedEvents) {
+ let i, len;
+ const resultEvents = orderEvents(sortedEvents);
+
+ // "false"-filled array
+ const processed = {};
+ const contours = [];
+
+ for (i = 0, len = resultEvents.length; i < len; i++) {
+
+ if (processed[i]) {
+ continue;
+ }
+
+ const contourId = contours.length;
+ const contour = initializeContourFromContext(resultEvents[i], contours, contourId);
+
+ // Helper function that combines marking an event as processed with assigning its output contour ID
+ const markAsProcessed = (pos) => {
+ processed[pos] = true;
+ resultEvents[pos].outputContourId = contourId;
+ };
+
+ let pos = i;
+ let origPos = i;
+
+ const initial = resultEvents[i].point;
+ contour.points.push(initial);
+
+ /* eslint no-constant-condition: "off" */
+ while (true) {
+ markAsProcessed(pos);
+
+ pos = resultEvents[pos].otherPos;
+
+ markAsProcessed(pos);
+ contour.points.push(resultEvents[pos].point);
+
+ pos = nextPos(pos, resultEvents, processed, origPos);
+
+ if (pos == origPos) {
+ break;
+ }
+ }
+
+ contours.push(contour);
+ }
+
+ return contours;
+ }
+
+ var tinyqueue = TinyQueue;
+ var _default$2 = TinyQueue;
+
+ function TinyQueue(data, compare) {
+ if (!(this instanceof TinyQueue)) return new TinyQueue(data, compare);
+
+ this.data = data || [];
+ this.length = this.data.length;
+ this.compare = compare || defaultCompare$1;
+
+ if (this.length > 0) {
+ for (var i = (this.length >> 1) - 1; i >= 0; i--) this._down(i);
+ }
+ }
+
+ function defaultCompare$1(a, b) {
+ return a < b ? -1 : a > b ? 1 : 0;
+ }
+
+ TinyQueue.prototype = {
+
+ push: function (item) {
+ this.data.push(item);
+ this.length++;
+ this._up(this.length - 1);
+ },
+
+ pop: function () {
+ if (this.length === 0) return undefined;
+
+ var top = this.data[0];
+ this.length--;
+
+ if (this.length > 0) {
+ this.data[0] = this.data[this.length];
+ this._down(0);
+ }
+ this.data.pop();
+
+ return top;
+ },
+
+ peek: function () {
+ return this.data[0];
+ },
+
+ _up: function (pos) {
+ var data = this.data;
+ var compare = this.compare;
+ var item = data[pos];
+
+ while (pos > 0) {
+ var parent = (pos - 1) >> 1;
+ var current = data[parent];
+ if (compare(item, current) >= 0) break;
+ data[pos] = current;
+ pos = parent;
+ }
+
+ data[pos] = item;
+ },
+
+ _down: function (pos) {
+ var data = this.data;
+ var compare = this.compare;
+ var halfLength = this.length >> 1;
+ var item = data[pos];
+
+ while (pos < halfLength) {
+ var left = (pos << 1) + 1;
+ var right = left + 1;
+ var best = data[left];
+
+ if (right < this.length && compare(data[right], best) < 0) {
+ left = right;
+ best = data[right];
+ }
+ if (compare(best, item) >= 0) break;
+
+ data[pos] = best;
+ pos = left;
+ }
+
+ data[pos] = item;
+ }
+ };
+ tinyqueue.default = _default$2;
+
+ const max$2 = Math.max;
+ const min = Math.min;
+
+ let contourId = 0;
+
+
+ function processPolygon(contourOrHole, isSubject, depth, Q, bbox, isExteriorRing) {
+ let i, len, s1, s2, e1, e2;
+ for (i = 0, len = contourOrHole.length - 1; i < len; i++) {
+ s1 = contourOrHole[i];
+ s2 = contourOrHole[i + 1];
+ e1 = new SweepEvent(s1, false, undefined, isSubject);
+ e2 = new SweepEvent(s2, false, e1, isSubject);
+ e1.otherEvent = e2;
+
+ if (s1[0] === s2[0] && s1[1] === s2[1]) {
+ continue; // skip collapsed edges, or it breaks
+ }
+
+ e1.contourId = e2.contourId = depth;
+ if (!isExteriorRing) {
+ e1.isExteriorRing = false;
+ e2.isExteriorRing = false;
+ }
+ if (compareEvents(e1, e2) > 0) {
+ e2.left = true;
+ } else {
+ e1.left = true;
+ }
+
+ const x = s1[0], y = s1[1];
+ bbox[0] = min(bbox[0], x);
+ bbox[1] = min(bbox[1], y);
+ bbox[2] = max$2(bbox[2], x);
+ bbox[3] = max$2(bbox[3], y);
+
+ // Pushing it so the queue is sorted from left to right,
+ // with object on the left having the highest priority.
+ Q.push(e1);
+ Q.push(e2);
+ }
+ }
+
+
+ function fillQueue(subject, clipping, sbbox, cbbox, operation) {
+ const eventQueue = new tinyqueue(null, compareEvents);
+ let polygonSet, isExteriorRing, i, ii, j, jj; //, k, kk;
+
+ for (i = 0, ii = subject.length; i < ii; i++) {
+ polygonSet = subject[i];
+ for (j = 0, jj = polygonSet.length; j < jj; j++) {
+ isExteriorRing = j === 0;
+ if (isExteriorRing) contourId++;
+ processPolygon(polygonSet[j], true, contourId, eventQueue, sbbox, isExteriorRing);
+ }
+ }
+
+ for (i = 0, ii = clipping.length; i < ii; i++) {
+ polygonSet = clipping[i];
+ for (j = 0, jj = polygonSet.length; j < jj; j++) {
+ isExteriorRing = j === 0;
+ if (operation === DIFFERENCE) isExteriorRing = false;
+ if (isExteriorRing) contourId++;
+ processPolygon(polygonSet[j], false, contourId, eventQueue, cbbox, isExteriorRing);
+ }
+ }
+
+ return eventQueue;
+ }
+
+ const EMPTY = [];
+
+
+ function trivialOperation(subject, clipping, operation) {
+ let result = null;
+ if (subject.length * clipping.length === 0) {
+ if (operation === INTERSECTION) {
+ result = EMPTY;
+ } else if (operation === DIFFERENCE) {
+ result = subject;
+ } else if (operation === UNION ||
+ operation === XOR) {
+ result = (subject.length === 0) ? clipping : subject;
+ }
+ }
+ return result;
+ }
+
+
+ function compareBBoxes(subject, clipping, sbbox, cbbox, operation) {
+ let result = null;
+ if (sbbox[0] > cbbox[2] ||
+ cbbox[0] > sbbox[2] ||
+ sbbox[1] > cbbox[3] ||
+ cbbox[1] > sbbox[3]) {
+ if (operation === INTERSECTION) {
+ result = EMPTY;
+ } else if (operation === DIFFERENCE) {
+ result = subject;
+ } else if (operation === UNION ||
+ operation === XOR) {
+ result = subject.concat(clipping);
+ }
+ }
+ return result;
+ }
+
+
+ function boolean(subject, clipping, operation) {
+ if (typeof subject[0][0][0] === 'number') {
+ subject = [subject];
+ }
+ if (typeof clipping[0][0][0] === 'number') {
+ clipping = [clipping];
+ }
+ let trivial = trivialOperation(subject, clipping, operation);
+ if (trivial) {
+ return trivial === EMPTY ? null : trivial;
+ }
+ const sbbox = [Infinity, Infinity, -Infinity, -Infinity];
+ const cbbox = [Infinity, Infinity, -Infinity, -Infinity];
+
+ // console.time('fill queue');
+ const eventQueue = fillQueue(subject, clipping, sbbox, cbbox, operation);
+ //console.timeEnd('fill queue');
+
+ trivial = compareBBoxes(subject, clipping, sbbox, cbbox, operation);
+ if (trivial) {
+ return trivial === EMPTY ? null : trivial;
+ }
+ // console.time('subdivide edges');
+ const sortedEvents = subdivide(eventQueue, subject, clipping, sbbox, cbbox, operation);
+ //console.timeEnd('subdivide edges');
+
+ // console.time('connect vertices');
+ const contours = connectEdges(sortedEvents);
+ //console.timeEnd('connect vertices');
+
+ // Convert contours to polygons
+ const polygons = [];
+ for (let i = 0; i < contours.length; i++) {
+ let contour = contours[i];
+ if (contour.isExterior()) {
+ // The exterior ring goes first
+ let rings = [contour.points];
+ // Followed by holes if any
+ for (let j = 0; j < contour.holeIds.length; j++) {
+ let holeId = contour.holeIds[j];
+ rings.push(contours[holeId].points);
+ }
+ polygons.push(rings);
+ }
+ }
+
+ return polygons;
+ }
+
+ function union$1 (subject, clipping) {
+ return boolean(subject, clipping, UNION);
+ }
+
+ var read$6 = function (buffer, offset, isLE, mLen, nBytes) {
+ var e, m;
+ var eLen = (nBytes * 8) - mLen - 1;
+ var eMax = (1 << eLen) - 1;
+ var eBias = eMax >> 1;
+ var nBits = -7;
+ var i = isLE ? (nBytes - 1) : 0;
+ var d = isLE ? -1 : 1;
+ var s = buffer[offset + i];
+
+ i += d;
+
+ e = s & ((1 << (-nBits)) - 1);
+ s >>= (-nBits);
+ nBits += eLen;
+ for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
+
+ m = e & ((1 << (-nBits)) - 1);
+ e >>= (-nBits);
+ nBits += mLen;
+ for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
+
+ if (e === 0) {
+ e = 1 - eBias;
+ } else if (e === eMax) {
+ return m ? NaN : ((s ? -1 : 1) * Infinity)
+ } else {
+ m = m + Math.pow(2, mLen);
+ e = e - eBias;
+ }
+ return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
+ };
+
+ var write$6 = function (buffer, value, offset, isLE, mLen, nBytes) {
+ var e, m, c;
+ var eLen = (nBytes * 8) - mLen - 1;
+ var eMax = (1 << eLen) - 1;
+ var eBias = eMax >> 1;
+ var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
+ var i = isLE ? 0 : (nBytes - 1);
+ var d = isLE ? 1 : -1;
+ var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
+
+ value = Math.abs(value);
+
+ if (isNaN(value) || value === Infinity) {
+ m = isNaN(value) ? 1 : 0;
+ e = eMax;
+ } else {
+ e = Math.floor(Math.log(value) / Math.LN2);
+ if (value * (c = Math.pow(2, -e)) < 1) {
+ e--;
+ c *= 2;
+ }
+ if (e + eBias >= 1) {
+ value += rt / c;
+ } else {
+ value += rt * Math.pow(2, 1 - eBias);
+ }
+ if (value * c >= 2) {
+ e++;
+ c /= 2;
+ }
+
+ if (e + eBias >= eMax) {
+ m = 0;
+ e = eMax;
+ } else if (e + eBias >= 1) {
+ m = ((value * c) - 1) * Math.pow(2, mLen);
+ e = e + eBias;
+ } else {
+ m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
+ e = 0;
+ }
+ }
+
+ for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
+
+ e = (e << mLen) | m;
+ eLen += mLen;
+ for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
+
+ buffer[offset + i - d] |= s * 128;
+ };
+
+ var ieee754 = {
+ read: read$6,
+ write: write$6
+ };
+
+ var pbf = Pbf;
+
+
+
+ function Pbf(buf) {
+ this.buf = ArrayBuffer.isView && ArrayBuffer.isView(buf) ? buf : new Uint8Array(buf || 0);
+ this.pos = 0;
+ this.type = 0;
+ this.length = this.buf.length;
+ }
+
+ Pbf.Varint = 0; // varint: int32, int64, uint32, uint64, sint32, sint64, bool, enum
+ Pbf.Fixed64 = 1; // 64-bit: double, fixed64, sfixed64
+ Pbf.Bytes = 2; // length-delimited: string, bytes, embedded messages, packed repeated fields
+ Pbf.Fixed32 = 5; // 32-bit: float, fixed32, sfixed32
+
+ var SHIFT_LEFT_32 = (1 << 16) * (1 << 16),
+ SHIFT_RIGHT_32 = 1 / SHIFT_LEFT_32;
+
+ // Threshold chosen based on both benchmarking and knowledge about browser string
+ // data structures (which currently switch structure types at 12 bytes or more)
+ var TEXT_DECODER_MIN_LENGTH = 12;
+ var utf8TextDecoder = typeof TextDecoder === 'undefined' ? null : new TextDecoder('utf8');
+
+ Pbf.prototype = {
+
+ destroy: function() {
+ this.buf = null;
+ },
+
+ // === READING =================================================================
+
+ readFields: function(readField, result, end) {
+ end = end || this.length;
+
+ while (this.pos < end) {
+ var val = this.readVarint(),
+ tag = val >> 3,
+ startPos = this.pos;
+
+ this.type = val & 0x7;
+ readField(tag, result, this);
+
+ if (this.pos === startPos) this.skip(val);
+ }
+ return result;
+ },
+
+ readMessage: function(readField, result) {
+ return this.readFields(readField, result, this.readVarint() + this.pos);
+ },
+
+ readFixed32: function() {
+ var val = readUInt32(this.buf, this.pos);
+ this.pos += 4;
+ return val;
+ },
+
+ readSFixed32: function() {
+ var val = readInt32(this.buf, this.pos);
+ this.pos += 4;
+ return val;
+ },
+
+ // 64-bit int handling is based on github.com/dpw/node-buffer-more-ints (MIT-licensed)
+
+ readFixed64: function() {
+ var val = readUInt32(this.buf, this.pos) + readUInt32(this.buf, this.pos + 4) * SHIFT_LEFT_32;
+ this.pos += 8;
+ return val;
+ },
+
+ readSFixed64: function() {
+ var val = readUInt32(this.buf, this.pos) + readInt32(this.buf, this.pos + 4) * SHIFT_LEFT_32;
+ this.pos += 8;
+ return val;
+ },
+
+ readFloat: function() {
+ var val = ieee754.read(this.buf, this.pos, true, 23, 4);
+ this.pos += 4;
+ return val;
+ },
+
+ readDouble: function() {
+ var val = ieee754.read(this.buf, this.pos, true, 52, 8);
+ this.pos += 8;
+ return val;
+ },
+
+ readVarint: function(isSigned) {
+ var buf = this.buf,
+ val, b;
+
+ b = buf[this.pos++]; val = b & 0x7f; if (b < 0x80) return val;
+ b = buf[this.pos++]; val |= (b & 0x7f) << 7; if (b < 0x80) return val;
+ b = buf[this.pos++]; val |= (b & 0x7f) << 14; if (b < 0x80) return val;
+ b = buf[this.pos++]; val |= (b & 0x7f) << 21; if (b < 0x80) return val;
+ b = buf[this.pos]; val |= (b & 0x0f) << 28;
+
+ return readVarintRemainder(val, isSigned, this);
+ },
+
+ readVarint64: function() { // for compatibility with v2.0.1
+ return this.readVarint(true);
+ },
+
+ readSVarint: function() {
+ var num = this.readVarint();
+ return num % 2 === 1 ? (num + 1) / -2 : num / 2; // zigzag encoding
+ },
+
+ readBoolean: function() {
+ return Boolean(this.readVarint());
+ },
+
+ readString: function() {
+ var end = this.readVarint() + this.pos;
+ var pos = this.pos;
+ this.pos = end;
+
+ if (end - pos >= TEXT_DECODER_MIN_LENGTH && utf8TextDecoder) {
+ // longer strings are fast with the built-in browser TextDecoder API
+ return readUtf8TextDecoder(this.buf, pos, end);
+ }
+ // short strings are fast with our custom implementation
+ return readUtf8(this.buf, pos, end);
+ },
+
+ readBytes: function() {
+ var end = this.readVarint() + this.pos,
+ buffer = this.buf.subarray(this.pos, end);
+ this.pos = end;
+ return buffer;
+ },
+
+ // verbose for performance reasons; doesn't affect gzipped size
+
+ readPackedVarint: function(arr, isSigned) {
+ if (this.type !== Pbf.Bytes) return arr.push(this.readVarint(isSigned));
+ var end = readPackedEnd(this);
+ arr = arr || [];
+ while (this.pos < end) arr.push(this.readVarint(isSigned));
+ return arr;
+ },
+ readPackedSVarint: function(arr) {
+ if (this.type !== Pbf.Bytes) return arr.push(this.readSVarint());
+ var end = readPackedEnd(this);
+ arr = arr || [];
+ while (this.pos < end) arr.push(this.readSVarint());
+ return arr;
+ },
+ readPackedBoolean: function(arr) {
+ if (this.type !== Pbf.Bytes) return arr.push(this.readBoolean());
+ var end = readPackedEnd(this);
+ arr = arr || [];
+ while (this.pos < end) arr.push(this.readBoolean());
+ return arr;
+ },
+ readPackedFloat: function(arr) {
+ if (this.type !== Pbf.Bytes) return arr.push(this.readFloat());
+ var end = readPackedEnd(this);
+ arr = arr || [];
+ while (this.pos < end) arr.push(this.readFloat());
+ return arr;
+ },
+ readPackedDouble: function(arr) {
+ if (this.type !== Pbf.Bytes) return arr.push(this.readDouble());
+ var end = readPackedEnd(this);
+ arr = arr || [];
+ while (this.pos < end) arr.push(this.readDouble());
+ return arr;
+ },
+ readPackedFixed32: function(arr) {
+ if (this.type !== Pbf.Bytes) return arr.push(this.readFixed32());
+ var end = readPackedEnd(this);
+ arr = arr || [];
+ while (this.pos < end) arr.push(this.readFixed32());
+ return arr;
+ },
+ readPackedSFixed32: function(arr) {
+ if (this.type !== Pbf.Bytes) return arr.push(this.readSFixed32());
+ var end = readPackedEnd(this);
+ arr = arr || [];
+ while (this.pos < end) arr.push(this.readSFixed32());
+ return arr;
+ },
+ readPackedFixed64: function(arr) {
+ if (this.type !== Pbf.Bytes) return arr.push(this.readFixed64());
+ var end = readPackedEnd(this);
+ arr = arr || [];
+ while (this.pos < end) arr.push(this.readFixed64());
+ return arr;
+ },
+ readPackedSFixed64: function(arr) {
+ if (this.type !== Pbf.Bytes) return arr.push(this.readSFixed64());
+ var end = readPackedEnd(this);
+ arr = arr || [];
+ while (this.pos < end) arr.push(this.readSFixed64());
+ return arr;
+ },
+
+ skip: function(val) {
+ var type = val & 0x7;
+ if (type === Pbf.Varint) while (this.buf[this.pos++] > 0x7f) {}
+ else if (type === Pbf.Bytes) this.pos = this.readVarint() + this.pos;
+ else if (type === Pbf.Fixed32) this.pos += 4;
+ else if (type === Pbf.Fixed64) this.pos += 8;
+ else throw new Error('Unimplemented type: ' + type);
+ },
+
+ // === WRITING =================================================================
+
+ writeTag: function(tag, type) {
+ this.writeVarint((tag << 3) | type);
+ },
+
+ realloc: function(min) {
+ var length = this.length || 16;
+
+ while (length < this.pos + min) length *= 2;
+
+ if (length !== this.length) {
+ var buf = new Uint8Array(length);
+ buf.set(this.buf);
+ this.buf = buf;
+ this.length = length;
+ }
+ },
+
+ finish: function() {
+ this.length = this.pos;
+ this.pos = 0;
+ return this.buf.subarray(0, this.length);
+ },
+
+ writeFixed32: function(val) {
+ this.realloc(4);
+ writeInt32(this.buf, val, this.pos);
+ this.pos += 4;
+ },
+
+ writeSFixed32: function(val) {
+ this.realloc(4);
+ writeInt32(this.buf, val, this.pos);
+ this.pos += 4;
+ },
+
+ writeFixed64: function(val) {
+ this.realloc(8);
+ writeInt32(this.buf, val & -1, this.pos);
+ writeInt32(this.buf, Math.floor(val * SHIFT_RIGHT_32), this.pos + 4);
+ this.pos += 8;
+ },
+
+ writeSFixed64: function(val) {
+ this.realloc(8);
+ writeInt32(this.buf, val & -1, this.pos);
+ writeInt32(this.buf, Math.floor(val * SHIFT_RIGHT_32), this.pos + 4);
+ this.pos += 8;
+ },
+
+ writeVarint: function(val) {
+ val = +val || 0;
+
+ if (val > 0xfffffff || val < 0) {
+ writeBigVarint(val, this);
+ return;
+ }
+
+ this.realloc(4);
+
+ this.buf[this.pos++] = val & 0x7f | (val > 0x7f ? 0x80 : 0); if (val <= 0x7f) return;
+ this.buf[this.pos++] = ((val >>>= 7) & 0x7f) | (val > 0x7f ? 0x80 : 0); if (val <= 0x7f) return;
+ this.buf[this.pos++] = ((val >>>= 7) & 0x7f) | (val > 0x7f ? 0x80 : 0); if (val <= 0x7f) return;
+ this.buf[this.pos++] = (val >>> 7) & 0x7f;
+ },
+
+ writeSVarint: function(val) {
+ this.writeVarint(val < 0 ? -val * 2 - 1 : val * 2);
+ },
+
+ writeBoolean: function(val) {
+ this.writeVarint(Boolean(val));
+ },
+
+ writeString: function(str) {
+ str = String(str);
+ this.realloc(str.length * 4);
+
+ this.pos++; // reserve 1 byte for short string length
+
+ var startPos = this.pos;
+ // write the string directly to the buffer and see how much was written
+ this.pos = writeUtf8(this.buf, str, this.pos);
+ var len = this.pos - startPos;
+
+ if (len >= 0x80) makeRoomForExtraLength(startPos, len, this);
+
+ // finally, write the message length in the reserved place and restore the position
+ this.pos = startPos - 1;
+ this.writeVarint(len);
+ this.pos += len;
+ },
+
+ writeFloat: function(val) {
+ this.realloc(4);
+ ieee754.write(this.buf, val, this.pos, true, 23, 4);
+ this.pos += 4;
+ },
+
+ writeDouble: function(val) {
+ this.realloc(8);
+ ieee754.write(this.buf, val, this.pos, true, 52, 8);
+ this.pos += 8;
+ },
+
+ writeBytes: function(buffer) {
+ var len = buffer.length;
+ this.writeVarint(len);
+ this.realloc(len);
+ for (var i = 0; i < len; i++) this.buf[this.pos++] = buffer[i];
+ },
+
+ writeRawMessage: function(fn, obj) {
+ this.pos++; // reserve 1 byte for short message length
+
+ // write the message directly to the buffer and see how much was written
+ var startPos = this.pos;
+ fn(obj, this);
+ var len = this.pos - startPos;
+
+ if (len >= 0x80) makeRoomForExtraLength(startPos, len, this);
+
+ // finally, write the message length in the reserved place and restore the position
+ this.pos = startPos - 1;
+ this.writeVarint(len);
+ this.pos += len;
+ },
+
+ writeMessage: function(tag, fn, obj) {
+ this.writeTag(tag, Pbf.Bytes);
+ this.writeRawMessage(fn, obj);
+ },
+
+ writePackedVarint: function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedVarint, arr); },
+ writePackedSVarint: function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedSVarint, arr); },
+ writePackedBoolean: function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedBoolean, arr); },
+ writePackedFloat: function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedFloat, arr); },
+ writePackedDouble: function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedDouble, arr); },
+ writePackedFixed32: function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedFixed32, arr); },
+ writePackedSFixed32: function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedSFixed32, arr); },
+ writePackedFixed64: function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedFixed64, arr); },
+ writePackedSFixed64: function(tag, arr) { if (arr.length) this.writeMessage(tag, writePackedSFixed64, arr); },
+
+ writeBytesField: function(tag, buffer) {
+ this.writeTag(tag, Pbf.Bytes);
+ this.writeBytes(buffer);
+ },
+ writeFixed32Field: function(tag, val) {
+ this.writeTag(tag, Pbf.Fixed32);
+ this.writeFixed32(val);
+ },
+ writeSFixed32Field: function(tag, val) {
+ this.writeTag(tag, Pbf.Fixed32);
+ this.writeSFixed32(val);
+ },
+ writeFixed64Field: function(tag, val) {
+ this.writeTag(tag, Pbf.Fixed64);
+ this.writeFixed64(val);
+ },
+ writeSFixed64Field: function(tag, val) {
+ this.writeTag(tag, Pbf.Fixed64);
+ this.writeSFixed64(val);
+ },
+ writeVarintField: function(tag, val) {
+ this.writeTag(tag, Pbf.Varint);
+ this.writeVarint(val);
+ },
+ writeSVarintField: function(tag, val) {
+ this.writeTag(tag, Pbf.Varint);
+ this.writeSVarint(val);
+ },
+ writeStringField: function(tag, str) {
+ this.writeTag(tag, Pbf.Bytes);
+ this.writeString(str);
+ },
+ writeFloatField: function(tag, val) {
+ this.writeTag(tag, Pbf.Fixed32);
+ this.writeFloat(val);
+ },
+ writeDoubleField: function(tag, val) {
+ this.writeTag(tag, Pbf.Fixed64);
+ this.writeDouble(val);
+ },
+ writeBooleanField: function(tag, val) {
+ this.writeVarintField(tag, Boolean(val));
+ }
+ };
+
+ function readVarintRemainder(l, s, p) {
+ var buf = p.buf,
+ h, b;
+
+ b = buf[p.pos++]; h = (b & 0x70) >> 4; if (b < 0x80) return toNum(l, h, s);
+ b = buf[p.pos++]; h |= (b & 0x7f) << 3; if (b < 0x80) return toNum(l, h, s);
+ b = buf[p.pos++]; h |= (b & 0x7f) << 10; if (b < 0x80) return toNum(l, h, s);
+ b = buf[p.pos++]; h |= (b & 0x7f) << 17; if (b < 0x80) return toNum(l, h, s);
+ b = buf[p.pos++]; h |= (b & 0x7f) << 24; if (b < 0x80) return toNum(l, h, s);
+ b = buf[p.pos++]; h |= (b & 0x01) << 31; if (b < 0x80) return toNum(l, h, s);
+
+ throw new Error('Expected varint not more than 10 bytes');
+ }
+
+ function readPackedEnd(pbf) {
+ return pbf.type === Pbf.Bytes ?
+ pbf.readVarint() + pbf.pos : pbf.pos + 1;
+ }
+
+ function toNum(low, high, isSigned) {
+ if (isSigned) {
+ return high * 0x100000000 + (low >>> 0);
+ }
+
+ return ((high >>> 0) * 0x100000000) + (low >>> 0);
+ }
+
+ function writeBigVarint(val, pbf) {
+ var low, high;
+
+ if (val >= 0) {
+ low = (val % 0x100000000) | 0;
+ high = (val / 0x100000000) | 0;
+ } else {
+ low = ~(-val % 0x100000000);
+ high = ~(-val / 0x100000000);
+
+ if (low ^ 0xffffffff) {
+ low = (low + 1) | 0;
+ } else {
+ low = 0;
+ high = (high + 1) | 0;
+ }
+ }
+
+ if (val >= 0x10000000000000000 || val < -0x10000000000000000) {
+ throw new Error('Given varint doesn\'t fit into 10 bytes');
+ }
+
+ pbf.realloc(10);
+
+ writeBigVarintLow(low, high, pbf);
+ writeBigVarintHigh(high, pbf);
+ }
+
+ function writeBigVarintLow(low, high, pbf) {
+ pbf.buf[pbf.pos++] = low & 0x7f | 0x80; low >>>= 7;
+ pbf.buf[pbf.pos++] = low & 0x7f | 0x80; low >>>= 7;
+ pbf.buf[pbf.pos++] = low & 0x7f | 0x80; low >>>= 7;
+ pbf.buf[pbf.pos++] = low & 0x7f | 0x80; low >>>= 7;
+ pbf.buf[pbf.pos] = low & 0x7f;
+ }
+
+ function writeBigVarintHigh(high, pbf) {
+ var lsb = (high & 0x07) << 4;
+
+ pbf.buf[pbf.pos++] |= lsb | ((high >>>= 3) ? 0x80 : 0); if (!high) return;
+ pbf.buf[pbf.pos++] = high & 0x7f | ((high >>>= 7) ? 0x80 : 0); if (!high) return;
+ pbf.buf[pbf.pos++] = high & 0x7f | ((high >>>= 7) ? 0x80 : 0); if (!high) return;
+ pbf.buf[pbf.pos++] = high & 0x7f | ((high >>>= 7) ? 0x80 : 0); if (!high) return;
+ pbf.buf[pbf.pos++] = high & 0x7f | ((high >>>= 7) ? 0x80 : 0); if (!high) return;
+ pbf.buf[pbf.pos++] = high & 0x7f;
+ }
+
+ function makeRoomForExtraLength(startPos, len, pbf) {
+ var extraLen =
+ len <= 0x3fff ? 1 :
+ len <= 0x1fffff ? 2 :
+ len <= 0xfffffff ? 3 : Math.floor(Math.log(len) / (Math.LN2 * 7));
+
+ // if 1 byte isn't enough for encoding message length, shift the data to the right
+ pbf.realloc(extraLen);
+ for (var i = pbf.pos - 1; i >= startPos; i--) pbf.buf[i + extraLen] = pbf.buf[i];
+ }
+
+ function writePackedVarint(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeVarint(arr[i]); }
+ function writePackedSVarint(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeSVarint(arr[i]); }
+ function writePackedFloat(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeFloat(arr[i]); }
+ function writePackedDouble(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeDouble(arr[i]); }
+ function writePackedBoolean(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeBoolean(arr[i]); }
+ function writePackedFixed32(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeFixed32(arr[i]); }
+ function writePackedSFixed32(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeSFixed32(arr[i]); }
+ function writePackedFixed64(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeFixed64(arr[i]); }
+ function writePackedSFixed64(arr, pbf) { for (var i = 0; i < arr.length; i++) pbf.writeSFixed64(arr[i]); }
+
+ // Buffer code below from https://github.com/feross/buffer, MIT-licensed
+
+ function readUInt32(buf, pos) {
+ return ((buf[pos]) |
+ (buf[pos + 1] << 8) |
+ (buf[pos + 2] << 16)) +
+ (buf[pos + 3] * 0x1000000);
+ }
+
+ function writeInt32(buf, val, pos) {
+ buf[pos] = val;
+ buf[pos + 1] = (val >>> 8);
+ buf[pos + 2] = (val >>> 16);
+ buf[pos + 3] = (val >>> 24);
+ }
+
+ function readInt32(buf, pos) {
+ return ((buf[pos]) |
+ (buf[pos + 1] << 8) |
+ (buf[pos + 2] << 16)) +
+ (buf[pos + 3] << 24);
+ }
+
+ function readUtf8(buf, pos, end) {
+ var str = '';
+ var i = pos;
+
+ while (i < end) {
+ var b0 = buf[i];
+ var c = null; // codepoint
+ var bytesPerSequence =
+ b0 > 0xEF ? 4 :
+ b0 > 0xDF ? 3 :
+ b0 > 0xBF ? 2 : 1;
+
+ if (i + bytesPerSequence > end) break;
+
+ var b1, b2, b3;
+
+ if (bytesPerSequence === 1) {
+ if (b0 < 0x80) {
+ c = b0;
+ }
+ } else if (bytesPerSequence === 2) {
+ b1 = buf[i + 1];
+ if ((b1 & 0xC0) === 0x80) {
+ c = (b0 & 0x1F) << 0x6 | (b1 & 0x3F);
+ if (c <= 0x7F) {
+ c = null;
+ }
+ }
+ } else if (bytesPerSequence === 3) {
+ b1 = buf[i + 1];
+ b2 = buf[i + 2];
+ if ((b1 & 0xC0) === 0x80 && (b2 & 0xC0) === 0x80) {
+ c = (b0 & 0xF) << 0xC | (b1 & 0x3F) << 0x6 | (b2 & 0x3F);
+ if (c <= 0x7FF || (c >= 0xD800 && c <= 0xDFFF)) {
+ c = null;
+ }
+ }
+ } else if (bytesPerSequence === 4) {
+ b1 = buf[i + 1];
+ b2 = buf[i + 2];
+ b3 = buf[i + 3];
+ if ((b1 & 0xC0) === 0x80 && (b2 & 0xC0) === 0x80 && (b3 & 0xC0) === 0x80) {
+ c = (b0 & 0xF) << 0x12 | (b1 & 0x3F) << 0xC | (b2 & 0x3F) << 0x6 | (b3 & 0x3F);
+ if (c <= 0xFFFF || c >= 0x110000) {
+ c = null;
+ }
+ }
+ }
+
+ if (c === null) {
+ c = 0xFFFD;
+ bytesPerSequence = 1;
+
+ } else if (c > 0xFFFF) {
+ c -= 0x10000;
+ str += String.fromCharCode(c >>> 10 & 0x3FF | 0xD800);
+ c = 0xDC00 | c & 0x3FF;
+ }
+
+ str += String.fromCharCode(c);
+ i += bytesPerSequence;
+ }
+
+ return str;
+ }
+
+ function readUtf8TextDecoder(buf, pos, end) {
+ return utf8TextDecoder.decode(buf.subarray(pos, end));
+ }
+
+ function writeUtf8(buf, str, pos) {
+ for (var i = 0, c, lead; i < str.length; i++) {
+ c = str.charCodeAt(i); // code point
+
+ if (c > 0xD7FF && c < 0xE000) {
+ if (lead) {
+ if (c < 0xDC00) {
+ buf[pos++] = 0xEF;
+ buf[pos++] = 0xBF;
+ buf[pos++] = 0xBD;
+ lead = c;
+ continue;
+ } else {
+ c = lead - 0xD800 << 10 | c - 0xDC00 | 0x10000;
+ lead = null;
+ }
+ } else {
+ if (c > 0xDBFF || (i + 1 === str.length)) {
+ buf[pos++] = 0xEF;
+ buf[pos++] = 0xBF;
+ buf[pos++] = 0xBD;
+ } else {
+ lead = c;
+ }
+ continue;
+ }
+ } else if (lead) {
+ buf[pos++] = 0xEF;
+ buf[pos++] = 0xBF;
+ buf[pos++] = 0xBD;
+ lead = null;
+ }
+
+ if (c < 0x80) {
+ buf[pos++] = c;
+ } else {
+ if (c < 0x800) {
+ buf[pos++] = c >> 0x6 | 0xC0;
+ } else {
+ if (c < 0x10000) {
+ buf[pos++] = c >> 0xC | 0xE0;
+ } else {
+ buf[pos++] = c >> 0x12 | 0xF0;
+ buf[pos++] = c >> 0xC & 0x3F | 0x80;
+ }
+ buf[pos++] = c >> 0x6 & 0x3F | 0x80;
+ }
+ buf[pos++] = c & 0x3F | 0x80;
+ }
+ }
+ return pos;
+ }
+
+ var pointGeometry = Point$1;
+
+ /**
+ * 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$1(x, y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ Point$1.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$1(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} 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|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$1.convert = function (a) {
+ if (a instanceof Point$1) {
+ return a;
+ }
+ if (Array.isArray(a)) {
+ return new Point$1(a[0], a[1]);
+ }
+ return a;
+ };
+
+ var vectortilefeature = VectorTileFeature;
+
+ function VectorTileFeature(pbf, end, extent, keys, values) {
+ // Public
+ this.properties = {};
+ this.extent = extent;
+ this.type = 0;
+
+ // Private
+ this._pbf = pbf;
+ this._geometry = -1;
+ this._keys = keys;
+ this._values = values;
+
+ pbf.readFields(readFeature, this, end);
+ }
+
+ function readFeature(tag, feature, pbf) {
+ if (tag == 1) feature.id = pbf.readVarint();
+ else if (tag == 2) readTag(pbf, feature);
+ else if (tag == 3) feature.type = pbf.readVarint();
+ else if (tag == 4) feature._geometry = pbf.pos;
+ }
+
+ function readTag(pbf, feature) {
+ var end = pbf.readVarint() + pbf.pos;
+
+ while (pbf.pos < end) {
+ var key = feature._keys[pbf.readVarint()],
+ value = feature._values[pbf.readVarint()];
+ feature.properties[key] = value;
+ }
+ }
+
+ VectorTileFeature.types = ['Unknown', 'Point', 'LineString', 'Polygon'];
+
+ VectorTileFeature.prototype.loadGeometry = function() {
+ var pbf = this._pbf;
+ pbf.pos = this._geometry;
+
+ var end = pbf.readVarint() + pbf.pos,
+ cmd = 1,
+ length = 0,
+ x = 0,
+ y = 0,
+ lines = [],
+ line;
+
+ while (pbf.pos < end) {
+ if (length <= 0) {
+ var cmdLen = pbf.readVarint();
+ cmd = cmdLen & 0x7;
+ length = cmdLen >> 3;
+ }
+
+ length--;
+
+ if (cmd === 1 || cmd === 2) {
+ x += pbf.readSVarint();
+ y += pbf.readSVarint();
+
+ if (cmd === 1) { // moveTo
+ if (line) lines.push(line);
+ line = [];
+ }
+
+ line.push(new pointGeometry(x, y));
+
+ } else if (cmd === 7) {
+
+ // Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90
+ if (line) {
+ line.push(line[0].clone()); // closePolygon
+ }
+
+ } else {
+ throw new Error('unknown command ' + cmd);
+ }
+ }
+
+ if (line) lines.push(line);
+
+ return lines;
+ };
+
+ VectorTileFeature.prototype.bbox = function() {
+ var pbf = this._pbf;
+ pbf.pos = this._geometry;
+
+ var end = pbf.readVarint() + pbf.pos,
+ cmd = 1,
+ length = 0,
+ x = 0,
+ y = 0,
+ x1 = Infinity,
+ x2 = -Infinity,
+ y1 = Infinity,
+ y2 = -Infinity;
+
+ while (pbf.pos < end) {
+ if (length <= 0) {
+ var cmdLen = pbf.readVarint();
+ cmd = cmdLen & 0x7;
+ length = cmdLen >> 3;
+ }
+
+ length--;
+
+ if (cmd === 1 || cmd === 2) {
+ x += pbf.readSVarint();
+ y += pbf.readSVarint();
+ if (x < x1) x1 = x;
+ if (x > x2) x2 = x;
+ if (y < y1) y1 = y;
+ if (y > y2) y2 = y;
+
+ } else if (cmd !== 7) {
+ throw new Error('unknown command ' + cmd);
+ }
+ }
+
+ return [x1, y1, x2, y2];
+ };
+
+ VectorTileFeature.prototype.toGeoJSON = function(x, y, z) {
+ var size = this.extent * Math.pow(2, z),
+ x0 = this.extent * x,
+ y0 = this.extent * y,
+ coords = this.loadGeometry(),
+ type = VectorTileFeature.types[this.type],
+ i, j;
+
+ function project(line) {
+ for (var j = 0; j < line.length; j++) {
+ var p = line[j], y2 = 180 - (p.y + y0) * 360 / size;
+ line[j] = [
+ (p.x + x0) * 360 / size - 180,
+ 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90
+ ];
+ }
+ }
+
+ switch (this.type) {
+ case 1:
+ var points = [];
+ for (i = 0; i < coords.length; i++) {
+ points[i] = coords[i][0];
+ }
+ coords = points;
+ project(coords);
+ break;
+
+ case 2:
+ for (i = 0; i < coords.length; i++) {
+ project(coords[i]);
+ }
+ break;
+
+ case 3:
+ coords = classifyRings(coords);
+ for (i = 0; i < coords.length; i++) {
+ for (j = 0; j < coords[i].length; j++) {
+ project(coords[i][j]);
+ }
+ }
+ break;
+ }
+
+ if (coords.length === 1) {
+ coords = coords[0];
+ } else {
+ type = 'Multi' + type;
+ }
+
+ var result = {
+ type: "Feature",
+ geometry: {
+ type: type,
+ coordinates: coords
+ },
+ properties: this.properties
+ };
+
+ if ('id' in this) {
+ result.id = this.id;
+ }
+
+ return result;
+ };
+
+ // classifies an array of rings into polygons with outer rings and holes
+
+ function classifyRings(rings) {
+ var len = rings.length;
+
+ if (len <= 1) return [rings];
+
+ var polygons = [],
+ polygon,
+ ccw;
+
+ for (var i = 0; i < len; i++) {
+ var area = signedArea$1(rings[i]);
+ if (area === 0) continue;
+
+ if (ccw === undefined) ccw = area < 0;
+
+ if (ccw === area < 0) {
+ if (polygon) polygons.push(polygon);
+ polygon = [rings[i]];
+
+ } else {
+ polygon.push(rings[i]);
+ }
+ }
+ if (polygon) polygons.push(polygon);
+
+ return polygons;
+ }
+
+ function signedArea$1(ring) {
+ var sum = 0;
+ for (var i = 0, len = ring.length, j = len - 1, p1, p2; i < len; j = i++) {
+ p1 = ring[i];
+ p2 = ring[j];
+ sum += (p2.x - p1.x) * (p1.y + p2.y);
+ }
+ return sum;
+ }
+
+ var vectortilelayer = VectorTileLayer;
+
+ function VectorTileLayer(pbf, end) {
+ // Public
+ this.version = 1;
+ this.name = null;
+ this.extent = 4096;
+ this.length = 0;
+
+ // Private
+ this._pbf = pbf;
+ this._keys = [];
+ this._values = [];
+ this._features = [];
+
+ pbf.readFields(readLayer, this, end);
+
+ this.length = this._features.length;
+ }
+
+ function readLayer(tag, layer, pbf) {
+ if (tag === 15) layer.version = pbf.readVarint();
+ else if (tag === 1) layer.name = pbf.readString();
+ else if (tag === 5) layer.extent = pbf.readVarint();
+ else if (tag === 2) layer._features.push(pbf.pos);
+ else if (tag === 3) layer._keys.push(pbf.readString());
+ else if (tag === 4) layer._values.push(readValueMessage(pbf));
+ }
+
+ function readValueMessage(pbf) {
+ var value = null,
+ end = pbf.readVarint() + pbf.pos;
+
+ while (pbf.pos < end) {
+ var tag = pbf.readVarint() >> 3;
+
+ value = tag === 1 ? pbf.readString() :
+ tag === 2 ? pbf.readFloat() :
+ tag === 3 ? pbf.readDouble() :
+ tag === 4 ? pbf.readVarint64() :
+ tag === 5 ? pbf.readVarint() :
+ tag === 6 ? pbf.readSVarint() :
+ tag === 7 ? pbf.readBoolean() : null;
+ }
+
+ return value;
+ }
+
+ // return feature `i` from this layer as a `VectorTileFeature`
+ VectorTileLayer.prototype.feature = function(i) {
+ if (i < 0 || i >= this._features.length) throw new Error('feature index out of bounds');
+
+ this._pbf.pos = this._features[i];
+
+ var end = this._pbf.readVarint() + this._pbf.pos;
+ return new vectortilefeature(this._pbf, end, this.extent, this._keys, this._values);
+ };
+
+ var vectortile = VectorTile;
+
+ function VectorTile(pbf, end) {
+ this.layers = pbf.readFields(readTile, {}, end);
+ }
+
+ function readTile(tag, layers, pbf) {
+ if (tag === 3) {
+ var layer = new vectortilelayer(pbf, pbf.readVarint() + pbf.pos);
+ if (layer.length) layers[layer.name] = layer;
+ }
+ }
+
+ var VectorTile$1 = vectortile;
+ var VectorTileFeature$1 = vectortilefeature;
+ var VectorTileLayer$1 = vectortilelayer;
+
+ var vectorTile = {
+ VectorTile: VectorTile$1,
+ VectorTileFeature: VectorTileFeature$1,
+ VectorTileLayer: VectorTileLayer$1
+ };
+
+ var tiler$9 = utilTiler().tileSize(512).margin(1);
+ var dispatch$a = dispatch('loadedData');
+ var _vtCache;
+
+
+ function abortRequest$9(controller) {
+ controller.abort();
+ }
+
+
+ function vtToGeoJSON(data, tile, mergeCache) {
+ var vectorTile$1 = new vectorTile.VectorTile(new pbf(data));
+ var layers = Object.keys(vectorTile$1.layers);
+ if (!Array.isArray(layers)) { layers = [layers]; }
+
+ var features = [];
+ layers.forEach(function(layerID) {
+ var layer = vectorTile$1.layers[layerID];
+ if (layer) {
+ for (var i = 0; i < layer.length; i++) {
+ var feature = layer.feature(i).toGeoJSON(tile.xyz[0], tile.xyz[1], tile.xyz[2]);
+ var geometry = feature.geometry;
+
+ // Treat all Polygons as MultiPolygons
+ if (geometry.type === 'Polygon') {
+ geometry.type = 'MultiPolygon';
+ geometry.coordinates = [geometry.coordinates];
+ }
+
+ // Clip to tile bounds
+ if (geometry.type === 'MultiPolygon') {
+ var isClipped = false;
+ var featureClip = bboxClip_1(feature, tile.extent.rectangle());
+ if (!fastDeepEqual(feature.geometry, featureClip.geometry)) {
+ // feature = featureClip;
+ isClipped = true;
+ }
+ if (!feature.geometry.coordinates.length) continue; // not actually on this tile
+ if (!feature.geometry.coordinates[0].length) continue; // not actually on this tile
+ }
+
+ // Generate some unique IDs and add some metadata
+ var featurehash = utilHashcode(fastJsonStableStringify(feature));
+ var propertyhash = utilHashcode(fastJsonStableStringify(feature.properties || {}));
+ feature.__layerID__ = layerID.replace(/[^_a-zA-Z0-9\-]/g, '_');
+ feature.__featurehash__ = featurehash;
+ feature.__propertyhash__ = propertyhash;
+ features.push(feature);
+
+ // Clipped Polygons at same zoom with identical properties can get merged
+ if (isClipped && geometry.type === 'MultiPolygon') {
+ var merged = mergeCache[propertyhash];
+ if (merged && merged.length) {
+ var other = merged[0];
+ var coords = union$1(
+ feature.geometry.coordinates,
+ other.geometry.coordinates
+ );
+
+ if (!coords || !coords.length) {
+ continue; // something failed in martinez union
+ }
+
+ merged.push(feature);
+ for (var j = 0; j < merged.length; j++) { // all these features get...
+ merged[j].geometry.coordinates = coords; // same coords
+ merged[j].__featurehash__ = featurehash; // same hash, so deduplication works
+ }
+ } else {
+ mergeCache[propertyhash] = [feature];
+ }
+ }
+ }
+ }
+ });
+
+ return features;
+ }
+
+
+ function loadTile(source, tile) {
+ if (source.loaded[tile.id] || source.inflight[tile.id]) return;
+
+ var url = source.template
+ .replace('{x}', tile.xyz[0])
+ .replace('{y}', tile.xyz[1])
+ // TMS-flipped y coordinate
+ .replace(/\{[t-]y\}/, Math.pow(2, tile.xyz[2]) - tile.xyz[1] - 1)
+ .replace(/\{z(oom)?\}/, tile.xyz[2])
+ .replace(/\{switch:([^}]+)\}/, function(s, r) {
+ var subdomains = r.split(',');
+ return subdomains[(tile.xyz[0] + tile.xyz[1]) % subdomains.length];
+ });
+
+
+ var controller = new AbortController();
+ source.inflight[tile.id] = controller;
+
+ fetch(url, { signal: controller.signal })
+ .then(function(response) {
+ if (!response.ok) {
+ throw new Error(response.status + ' ' + response.statusText);
+ }
+ source.loaded[tile.id] = [];
+ delete source.inflight[tile.id];
+ return response.arrayBuffer();
+ })
+ .then(function(data) {
+ if (!data) {
+ throw new Error('No Data');
+ }
+
+ var z = tile.xyz[2];
+ if (!source.canMerge[z]) {
+ source.canMerge[z] = {}; // initialize mergeCache
+ }
+
+ source.loaded[tile.id] = vtToGeoJSON(data, tile, source.canMerge[z]);
+ dispatch$a.call('loadedData');
+ })
+ .catch(function() {
+ source.loaded[tile.id] = [];
+ delete source.inflight[tile.id];
+ });
+ }
+
+
+ var serviceVectorTile = {
+
+ init: function() {
+ if (!_vtCache) {
+ this.reset();
+ }
+
+ this.event = utilRebind(this, dispatch$a, 'on');
+ },
+
+
+ reset: function() {
+ for (var sourceID in _vtCache) {
+ var source = _vtCache[sourceID];
+ if (source && source.inflight) {
+ Object.values(source.inflight).forEach(abortRequest$9);
+ }
+ }
+
+ _vtCache = {};
+ },
+
+
+ addSource: function(sourceID, template) {
+ _vtCache[sourceID] = { template: template, inflight: {}, loaded: {}, canMerge: {} };
+ return _vtCache[sourceID];
+ },
+
+
+ data: function(sourceID, projection) {
+ var source = _vtCache[sourceID];
+ if (!source) return [];
+
+ var tiles = tiler$9.getTiles(projection);
+ var seen = {};
+ var results = [];
+
+ for (var i = 0; i < tiles.length; i++) {
+ var features = source.loaded[tiles[i].id];
+ if (!features || !features.length) continue;
+
+ for (var j = 0; j < features.length; j++) {
+ var feature = features[j];
+ var hash = feature.__featurehash__;
+ if (seen[hash]) continue;
+ seen[hash] = true;
+
+ // return a shallow copy, because the hash may change
+ // later if this feature gets merged with another
+ results.push(Object.assign({}, feature)); // shallow copy
+ }
+ }
+
+ return results;
+ },
+
+
+ loadTiles: function(sourceID, template, projection) {
+ var source = _vtCache[sourceID];
+ if (!source) {
+ source = this.addSource(sourceID, template);
+ }
+
+ var tiles = tiler$9.getTiles(projection);
+
+ // abort inflight requests that are no longer needed
+ Object.keys(source.inflight).forEach(function(k) {
+ var wanted = tiles.find(function(tile) { return k === tile.id; });
+ if (!wanted) {
+ abortRequest$9(source.inflight[k]);
+ delete source.inflight[k];
+ }
+ });
+
+ tiles.forEach(function(tile) {
+ loadTile(source, tile);
+ });
+ },
+
+
+ cache: function() {
+ return _vtCache;
+ }
+
+ };
+
+ var apibase$5 = 'https://www.wikidata.org/w/api.php?';
+ var _wikidataCache = {};
+
+
+ var serviceWikidata = {
+
+ init: function() {},
+
+ reset: function() {
+ _wikidataCache = {};
+ },
+
+
+ // Search for Wikidata items matching the query
+ itemsForSearchQuery: function(query, callback) {
+ if (!query) {
+ if (callback) callback('No query', {});
+ return;
+ }
+
+ var lang = this.languagesToQuery()[0];
+
+ var url = apibase$5 + utilQsString({
+ action: 'wbsearchentities',
+ format: 'json',
+ formatversion: 2,
+ search: query,
+ type: 'item',
+ // the language to search
+ language: lang,
+ // the langauge for the label and description in the result
+ uselang: lang,
+ limit: 10,
+ origin: '*'
+ });
+
+ d3_json(url)
+ .then(function(result) {
+ if (result && result.error) {
+ throw new Error(result.error);
+ }
+ if (callback) callback(null, result.search || {});
+ })
+ .catch(function(err) {
+ if (callback) callback(err.message, {});
+ });
+ },
+
+
+ // Given a Wikipedia language and article title,
+ // return an array of corresponding Wikidata entities.
+ itemsByTitle: function(lang, title, callback) {
+ if (!title) {
+ if (callback) callback('No title', {});
+ return;
+ }
+
+ lang = lang || 'en';
+ var url = apibase$5 + utilQsString({
+ action: 'wbgetentities',
+ format: 'json',
+ formatversion: 2,
+ sites: lang.replace(/-/g, '_') + 'wiki',
+ titles: title,
+ languages: 'en', // shrink response by filtering to one language
+ origin: '*'
+ });
+
+ d3_json(url)
+ .then(function(result) {
+ if (result && result.error) {
+ throw new Error(result.error);
+ }
+ if (callback) callback(null, result.entities || {});
+ })
+ .catch(function(err) {
+ if (callback) callback(err.message, {});
+ });
+ },
+
+
+ languagesToQuery: function() {
+ var localeCode = _mainLocalizer.localeCode().toLowerCase();
+ // HACK: en-us isn't a wikidata language. We should really be filtering by
+ // the languages known to be supported by wikidata.
+ if (localeCode === 'en-us') localeCode = 'en';
+ return utilArrayUniq([
+ localeCode,
+ _mainLocalizer.languageCode().toLowerCase(),
+ 'en'
+ ]);
+ },
+
+
+ entityByQID: function(qid, callback) {
+ if (!qid) {
+ callback('No qid', {});
+ return;
+ }
+ if (_wikidataCache[qid]) {
+ if (callback) callback(null, _wikidataCache[qid]);
+ return;
+ }
+
+ var langs = this.languagesToQuery();
+ var url = apibase$5 + utilQsString({
+ action: 'wbgetentities',
+ format: 'json',
+ formatversion: 2,
+ ids: qid,
+ props: 'labels|descriptions|claims|sitelinks',
+ sitefilter: langs.map(function(d) { return d + 'wiki'; }).join('|'),
+ languages: langs.join('|'),
+ languagefallback: 1,
+ origin: '*'
+ });
+
+ d3_json(url)
+ .then(function(result) {
+ if (result && result.error) {
+ throw new Error(result.error);
+ }
+ if (callback) callback(null, result.entities[qid] || {});
+ })
+ .catch(function(err) {
+ if (callback) callback(err.message, {});
+ });
+ },
+
+
+ // Pass `params` object of the form:
+ // {
+ // qid: 'string' // brand wikidata (e.g. 'Q37158')
+ // }
+ //
+ // Get an result object used to display tag documentation
+ // {
+ // title: 'string',
+ // description: 'string',
+ // editURL: 'string',
+ // imageURL: 'string',
+ // wiki: { title: 'string', text: 'string', url: 'string' }
+ // }
+ //
+ getDocs: function(params, callback) {
+ var langs = this.languagesToQuery();
+ this.entityByQID(params.qid, function(err, entity) {
+ if (err || !entity) {
+ callback(err || 'No entity');
+ return;
+ }
+
+ var i;
+ var description;
+ if (entity.descriptions && Object.keys(entity.descriptions).length > 0) {
+ description = entity.descriptions[Object.keys(entity.descriptions)[0]].value;
+ }
+
+ // prepare result
+ var result = {
+ title: entity.id,
+ description: description,
+ editURL: 'https://www.wikidata.org/wiki/' + entity.id
+ };
+
+ // add image
+ if (entity.claims) {
+ var imageroot = 'https://commons.wikimedia.org/w/index.php';
+ var props = ['P154','P18']; // logo image, image
+ var prop, image;
+ for (i = 0; i < props.length; i++) {
+ prop = entity.claims[props[i]];
+ if (prop && Object.keys(prop).length > 0) {
+ image = prop[Object.keys(prop)[0]].mainsnak.datavalue.value;
+ if (image) {
+ result.imageURL = imageroot + '?' + utilQsString({
+ title: 'Special:Redirect/file/' + image,
+ width: 400
+ });
+ break;
+ }
+ }
+ }
+ }
+
+ if (entity.sitelinks) {
+ var englishLocale = _mainLocalizer.languageCode().toLowerCase() === 'en';
+
+ // must be one of these that we requested..
+ for (i = 0; i < langs.length; i++) { // check each, in order of preference
+ var w = langs[i] + 'wiki';
+ if (entity.sitelinks[w]) {
+ var title = entity.sitelinks[w].title;
+ var tKey = 'inspector.wiki_reference';
+ if (!englishLocale && langs[i] === 'en') { // user's locale isn't English but
+ tKey = 'inspector.wiki_en_reference'; // we are sending them to enwiki anyway..
+ }
+
+ result.wiki = {
+ title: title,
+ text: tKey,
+ url: 'https://' + langs[i] + '.wikipedia.org/wiki/' + title.replace(/ /g, '_')
+ };
+ break;
+ }
+ }
+ }
+
+ callback(null, result);
+ });
+ }
+
+ };
+
+ var endpoint = 'https://en.wikipedia.org/w/api.php?';
+
+ var serviceWikipedia = {
+
+ init: function() {},
+ reset: function() {},
+
+
+ search: function(lang, query, callback) {
+ if (!query) {
+ if (callback) callback('No Query', []);
+ return;
+ }
+
+ lang = lang || 'en';
+ var url = endpoint.replace('en', lang) +
+ utilQsString({
+ action: 'query',
+ list: 'search',
+ srlimit: '10',
+ srinfo: 'suggestion',
+ format: 'json',
+ origin: '*',
+ srsearch: query
+ });
+
+ d3_json(url)
+ .then(function(result) {
+ if (result && result.error) {
+ throw new Error(result.error);
+ } else if (!result || !result.query || !result.query.search) {
+ throw new Error('No Results');
+ }
+ if (callback) {
+ var titles = result.query.search.map(function(d) { return d.title; });
+ callback(null, titles);
+ }
+ })
+ .catch(function(err) {
+ if (callback) callback(err, []);
+ });
+ },
+
+
+ suggestions: function(lang, query, callback) {
+ if (!query) {
+ if (callback) callback('', []);
+ return;
+ }
+
+ lang = lang || 'en';
+ var url = endpoint.replace('en', lang) +
+ utilQsString({
+ action: 'opensearch',
+ namespace: 0,
+ suggest: '',
+ format: 'json',
+ origin: '*',
+ search: query
+ });
+
+ d3_json(url)
+ .then(function(result) {
+ if (result && result.error) {
+ throw new Error(result.error);
+ } else if (!result || result.length < 2) {
+ throw new Error('No Results');
+ }
+ if (callback) callback(null, result[1] || []);
+ })
+ .catch(function(err) {
+ if (callback) callback(err.message, []);
+ });
+ },
+
+
+ translations: function(lang, title, callback) {
+ if (!title) {
+ if (callback) callback('No Title');
+ return;
+ }
+
+ var url = endpoint.replace('en', lang) +
+ utilQsString({
+ action: 'query',
+ prop: 'langlinks',
+ format: 'json',
+ origin: '*',
+ lllimit: 500,
+ titles: title
+ });
+
+ d3_json(url)
+ .then(function(result) {
+ if (result && result.error) {
+ throw new Error(result.error);
+ } else if (!result || !result.query || !result.query.pages) {
+ throw new Error('No Results');
+ }
+ if (callback) {
+ var list = result.query.pages[Object.keys(result.query.pages)[0]];
+ var translations = {};
+ if (list && list.langlinks) {
+ list.langlinks.forEach(function(d) { translations[d.lang] = d['*']; });
+ }
+ callback(null, translations);
+ }
+ })
+ .catch(function(err) {
+ if (callback) callback(err.message);
+ });
+ }
+
+ };
+
+ var services = {
+ esriData: serviceEsriData,
+ fbMLRoads: serviceFbAIFeatures,
+ geocoder: serviceNominatim,
+ keepRight: serviceKeepRight,
+ improveOSM: serviceImproveOSM,
+ osmose: serviceOsmose,
+ mapillary: serviceMapillary,
+ openstreetcam: serviceOpenstreetcam,
+ osm: serviceOsm,
+ osmWikibase: serviceOsmWikibase,
+ maprules: serviceMapRules,
+ streetside: serviceStreetside,
+ taginfo: serviceTaginfo,
+ vectorTile: serviceVectorTile,
+ wikidata: serviceWikidata,
+ wikipedia: serviceWikipedia
+ };
+
+ function modeDragNote(context) {
+ var mode = {
+ id: 'drag-note',
+ button: 'browse'
+ };
+
+ var edit = behaviorEdit(context);
+
+ var _nudgeInterval;
+ var _lastLoc;
+ var _note; // most current note.. dragged note may have stale datum.
+
+
+ function startNudge(nudge) {
+ if (_nudgeInterval) window.clearInterval(_nudgeInterval);
+ _nudgeInterval = window.setInterval(function() {
+ context.map().pan(nudge);
+ doMove(nudge);
+ }, 50);
+ }
+
+
+ function stopNudge() {
+ if (_nudgeInterval) {
+ window.clearInterval(_nudgeInterval);
+ _nudgeInterval = null;
+ }
+ }
+
+
+ function origin(note) {
+ return context.projection(note.loc);
+ }
+
+
+ function start(note) {
+ _note = note;
+ var osm = services.osm;
+ if (osm) {
+ // Get latest note from cache.. The marker may have a stale datum bound to it
+ // and dragging it around can sometimes delete the users note comment.
+ _note = osm.getNote(_note.id);
+ }
+
+ context.surface().selectAll('.note-' + _note.id)
+ .classed('active', true);
+
+ context.perform(actionNoop());
+ context.enter(mode);
+ context.selectedNoteID(_note.id);
+ }
+
+
+ function move() {
+ event.sourceEvent.stopPropagation();
+ _lastLoc = context.projection.invert(event.point);
+
+ doMove();
+ var nudge = geoViewportEdge(event.point, context.map().dimensions());
+ if (nudge) {
+ startNudge(nudge);
+ } else {
+ stopNudge();
+ }
+ }
+
+
+ function doMove(nudge) {
+ nudge = nudge || [0, 0];
+
+ var currPoint = (event && event.point) || context.projection(_lastLoc);
+ var currMouse = geoVecSubtract(currPoint, nudge);
+ var loc = context.projection.invert(currMouse);
+
+ _note = _note.move(loc);
+
+ var osm = services.osm;
+ if (osm) {
+ osm.replaceNote(_note); // update note cache
+ }
+
+ context.replace(actionNoop()); // trigger redraw
+ }
+
+
+ function end() {
+ context.replace(actionNoop()); // trigger redraw
+
+ context
+ .selectedNoteID(_note.id)
+ .enter(modeSelectNote(context, _note.id));
+ }
+
+
+ var drag = behaviorDrag()
+ .selector('.layer-touch.markers .target.note.new')
+ .surface(context.container().select('.main-map').node())
+ .origin(origin)
+ .on('start', start)
+ .on('move', move)
+ .on('end', end);
+
+
+ mode.enter = function() {
+ context.install(edit);
+ };
+
+
+ mode.exit = function() {
+ context.ui().sidebar.hover.cancel();
+ context.uninstall(edit);
+
+ context.surface()
+ .selectAll('.active')
+ .classed('active', false);
+
+ stopNudge();
+ };
+
+ mode.behavior = drag;
+
+ return mode;
+ }
+
+ function modeSelectData(context, selectedDatum) {
+ var mode = {
+ id: 'select-data',
+ button: 'browse'
+ };
+
+ var keybinding = utilKeybinding('select-data');
+ var dataEditor = uiDataEditor(context);
+
+ var behaviors = [
+ behaviorBreathe(),
+ behaviorHover(context),
+ behaviorSelect(context),
+ behaviorLasso(context),
+ modeDragNode(context).behavior,
+ modeDragNote(context).behavior
+ ];
+
+
+ // class the data as selected, or return to browse mode if the data is gone
+ function selectData(drawn) {
+ var selection = context.surface().selectAll('.layer-mapdata .data' + selectedDatum.__featurehash__);
+
+ if (selection.empty()) {
+ // Return to browse mode if selected DOM elements have
+ // disappeared because the user moved them out of view..
+ var source = event && event.type === 'zoom' && event.sourceEvent;
+ if (drawn && source && (source.type === 'pointermove' || source.type === 'mousemove' || source.type === 'touchmove')) {
+ context.enter(modeBrowse(context));
+ }
+ } else {
+ selection.classed('selected', true);
+ }
+ }
+
+
+ function esc() {
+ if (context.container().select('.combobox').size()) return;
+ context.enter(modeBrowse(context));
+ }
+
+
+ mode.zoomToSelected = function() {
+ var extent = geoExtent(d3_geoBounds(selectedDatum));
+ context.map().centerZoomEase(extent.center(), context.map().trimmedExtentZoom(extent));
+ };
+
+
+ mode.enter = function() {
+ behaviors.forEach(context.install);
+
+ keybinding
+ .on(_t('inspector.zoom_to.key'), mode.zoomToSelected)
+ .on('⎋', esc, true);
+
+ select(document)
+ .call(keybinding);
+
+ selectData();
+
+ var sidebar = context.ui().sidebar;
+ sidebar.show(dataEditor.datum(selectedDatum));
+
+ // expand the sidebar, avoid obscuring the data if needed
+ var extent = geoExtent(d3_geoBounds(selectedDatum));
+ sidebar.expand(sidebar.intersects(extent));
+
+ context.map()
+ .on('drawn.select-data', selectData);
+ };
+
+
+ mode.exit = function() {
+ behaviors.forEach(context.uninstall);
+
+ select(document)
+ .call(keybinding.unbind);
+
+ context.surface()
+ .selectAll('.layer-mapdata .selected')
+ .classed('selected hover', false);
+
+ context.map()
+ .on('drawn.select-data', null);
+
+ context.ui().sidebar
+ .hide();
+ };
+
+
+ return mode;
+ }
+
+ function behaviorSelect(context) {
+ var _tolerancePx = 4; // see also behaviorDrag
+ var _lastMouseEvent = null;
+ var _showMenu = false;
+ var _downPointers = {};
+ var _longPressTimeout = null;
+ var _lastInteractionType = null;
+ // the id of the down pointer that's enabling multiselection while down
+ var _multiselectionPointerId = null;
+
+ // use pointer events on supported platforms; fallback to mouse events
+ var _pointerPrefix = 'PointerEvent' in window ? 'pointer' : 'mouse';
+
+
+ function keydown() {
+
+ if (event.keyCode === 32) {
+ // don't react to spacebar events during text input
+ var activeNode = document.activeElement;
+ if (activeNode && new Set(['INPUT', 'TEXTAREA']).has(activeNode.nodeName)) return;
+ }
+
+ if (event.keyCode === 93 || // context menu key
+ event.keyCode === 32) { // spacebar
+ event.preventDefault();
+ }
+
+ if (event.repeat) return; // ignore repeated events for held keys
+
+ // if any key is pressed the user is probably doing something other than long-pressing
+ cancelLongPress();
+
+ if (event.shiftKey) {
+ context.surface()
+ .classed('behavior-multiselect', true);
+ }
+
+ if (event.keyCode === 32) { // spacebar
+ if (!_downPointers.spacebar && _lastMouseEvent) {
+ cancelLongPress();
+ _longPressTimeout = window.setTimeout(didLongPress, 500, 'spacebar', 'spacebar');
+
+ _downPointers.spacebar = {
+ firstEvent: _lastMouseEvent,
+ lastEvent: _lastMouseEvent
+ };
+ }
+ }
+ }
+
+
+ function keyup() {
+ cancelLongPress();
+
+ if (!event.shiftKey) {
+ context.surface()
+ .classed('behavior-multiselect', false);
+ }
+
+ if (event.keyCode === 93) { // context menu key
+ event.preventDefault();
+ _lastInteractionType = 'menukey';
+ contextmenu();
+ } else if (event.keyCode === 32) { // spacebar
+ var pointer = _downPointers.spacebar;
+ if (pointer) {
+ delete _downPointers.spacebar;
+
+ if (pointer.done) return;
+
+ event.preventDefault();
+ _lastInteractionType = 'spacebar';
+ click(pointer.firstEvent, pointer.lastEvent, 'spacebar');
+ }
+ }
+ }
+
+
+ function pointerdown() {
+ var id = (event.pointerId || 'mouse').toString();
+
+ cancelLongPress();
+
+ if (event.buttons && event.buttons !== 1) return;
+
+ context.ui().closeEditMenu();
+
+ _longPressTimeout = window.setTimeout(didLongPress, 500, id, 'longdown-' + (event.pointerType || 'mouse'));
+
+ _downPointers[id] = {
+ firstEvent: event,
+ lastEvent: event
+ };
+ }
+
+
+ function didLongPress(id, interactionType) {
+ var pointer = _downPointers[id];
+ if (!pointer) return;
+
+ for (var i in _downPointers) {
+ // don't allow this or any currently down pointer to trigger another click
+ _downPointers[i].done = true;
+ }
+
+ // treat long presses like right-clicks
+ _longPressTimeout = null;
+ _lastInteractionType = interactionType;
+ _showMenu = true;
+
+ click(pointer.firstEvent, pointer.lastEvent, id);
+ }
+
+
+ function pointermove() {
+ var id = (event.pointerId || 'mouse').toString();
+ if (_downPointers[id]) {
+ _downPointers[id].lastEvent = event;
+ }
+ if (!event.pointerType || event.pointerType === 'mouse') {
+ _lastMouseEvent = event;
+ if (_downPointers.spacebar) {
+ _downPointers.spacebar.lastEvent = event;
+ }
+ }
+ }
+
+
+ function pointerup() {
+ var id = (event.pointerId || 'mouse').toString();
+ var pointer = _downPointers[id];
+ if (!pointer) return;
+
+ delete _downPointers[id];
+
+ if (_multiselectionPointerId === id) {
+ _multiselectionPointerId = null;
+ }
+
+ if (pointer.done) return;
+
+ click(pointer.firstEvent, event, id);
+ }
+
+
+ function pointercancel() {
+ var id = (event.pointerId || 'mouse').toString();
+ if (!_downPointers[id]) return;
+
+ delete _downPointers[id];
+
+ if (_multiselectionPointerId === id) {
+ _multiselectionPointerId = null;
+ }
+ }
+
+
+ function contextmenu() {
+ var e = event;
+ e.preventDefault();
+
+ if (!+e.clientX && !+e.clientY) {
+ if (_lastMouseEvent) {
+ e.sourceEvent = _lastMouseEvent;
+ } else {
+ return;
+ }
+ } else {
+ _lastMouseEvent = event;
+ _lastInteractionType = 'rightclick';
+ }
+
+ _showMenu = true;
+ click(event, event);
+ }
+
+
+ function click(firstEvent, lastEvent, pointerId) {
+ cancelLongPress();
+
+ var mapNode = context.container().select('.main-map').node();
+
+ // Use the `main-map` coordinate system since the surface and supersurface
+ // are transformed when drag-panning.
+ var pointGetter = utilFastMouse(mapNode);
+ var p1 = pointGetter(firstEvent);
+ var p2 = pointGetter(lastEvent);
+ var dist = geoVecLength(p1, p2);
+
+ if (dist > _tolerancePx ||
+ !mapContains(lastEvent)) {
+
+ resetProperties();
+ return;
+ }
+
+ var targetDatum = lastEvent.target.__data__;
+
+ var multiselectEntityId;
+
+ if (!_multiselectionPointerId) {
+ // If a different pointer than the one triggering this click is down on a
+ // feature, treat this and all future clicks as multiselection until that
+ // pointer is raised.
+ var selectPointerInfo = pointerDownOnSelection(pointerId);
+ if (selectPointerInfo) {
+ _multiselectionPointerId = selectPointerInfo.pointerId;
+ // if the other feature isn't selected yet, make sure we select it
+ multiselectEntityId = !selectPointerInfo.selected && selectPointerInfo.entityId;
+ _downPointers[selectPointerInfo.pointerId].done = true;
+ }
+ }
+
+ // support multiselect if data is already selected
+ var isMultiselect = context.mode().id === 'select' && (
+ // and shift key is down
+ (event && event.shiftKey) ||
+ // or we're lasso-selecting
+ context.surface().select('.lasso').node() ||
+ // or a pointer is down over a selected feature
+ (_multiselectionPointerId && !multiselectEntityId)
+ );
+
+ processClick(targetDatum, isMultiselect, p2, multiselectEntityId);
+
+ function mapContains(event) {
+ var rect = mapNode.getBoundingClientRect();
+ return event.clientX >= rect.left &&
+ event.clientX <= rect.right &&
+ event.clientY >= rect.top &&
+ event.clientY <= rect.bottom;
+ }
+
+ function pointerDownOnSelection(skipPointerId) {
+ var mode = context.mode();
+ var selectedIDs = mode.id === 'select' ? mode.selectedIDs() : [];
+ for (var pointerId in _downPointers) {
+ if (pointerId === 'spacebar' || pointerId === skipPointerId) continue;
+
+ var pointerInfo = _downPointers[pointerId];
+
+ var p1 = pointGetter(pointerInfo.firstEvent);
+ var p2 = pointGetter(pointerInfo.lastEvent);
+ if (geoVecLength(p1, p2) > _tolerancePx) continue;
+
+ var datum = pointerInfo.firstEvent.target.__data__;
+ var entity = (datum && datum.properties && datum.properties.entity) || datum;
+ if (context.graph().hasEntity(entity.id)) return {
+ pointerId: pointerId,
+ entityId: entity.id,
+ selected: selectedIDs.indexOf(entity.id) !== -1
+ };
+ }
+ return null;
+ }
+ }
+
+
+ function processClick(datum, isMultiselect, point, alsoSelectId) {
+ var mode = context.mode();
+ var showMenu = _showMenu;
+ var interactionType = _lastInteractionType;
+
+ var entity = datum && datum.properties && datum.properties.entity;
+ if (entity) datum = entity;
+
+ if (datum && datum.type === 'midpoint') {
+ // treat targeting midpoints as if targeting the parent way
+ datum = datum.parents[0];
+ }
+
+ var newMode;
+ if (datum && datum.__fbid__) { // clicked a RapiD feature ..
+ context
+ .selectedNoteID(null)
+ .selectedErrorID(null)
+ .enter(modeRapidSelectFeatures(context, datum));
+
+ } else if (datum instanceof osmEntity) { // clicked an entity..
+ var selectedIDs = context.selectedIDs();
+ context.selectedNoteID(null);
+ context.selectedErrorID(null);
+
+ if (!isMultiselect) {
+ // don't change the selection if we're toggling the menu atop a multiselection
+ if (!showMenu ||
+ selectedIDs.length <= 1 ||
+ selectedIDs.indexOf(datum.id) === -1) {
+
+ if (alsoSelectId === datum.id) alsoSelectId = null;
+
+ selectedIDs = (alsoSelectId ? [alsoSelectId] : []).concat([datum.id]);
+ // always enter modeSelect even if the entity is already
+ // selected since listeners may expect `context.enter` events,
+ // e.g. in the walkthrough
+ newMode = mode.id === 'select' ? mode.selectedIDs(selectedIDs) : modeSelect(context, selectedIDs).selectBehavior(behavior);
+ context.enter(newMode);
+ }
+
+ } else {
+ if (selectedIDs.indexOf(datum.id) !== -1) {
+ // clicked entity is already in the selectedIDs list..
+ if (!showMenu) {
+ // deselect clicked entity, then reenter select mode or return to browse mode..
+ selectedIDs = selectedIDs.filter(function(id) { return id !== datum.id; });
+ newMode = selectedIDs.length ? mode.selectedIDs(selectedIDs) : modeBrowse(context).selectBehavior(behavior);
+ context.enter(newMode);
+ }
+ } else {
+ // clicked entity is not in the selected list, add it..
+ selectedIDs = selectedIDs.concat([datum.id]);
+ newMode = mode.selectedIDs(selectedIDs);
+ context.enter(newMode);
+ }
+ }
+
+ } else if (datum && datum.__featurehash__ && !isMultiselect) {
+ // targeting custom data
+ context
+ .selectedNoteID(null)
+ .enter(modeSelectData(context, datum));
+
+ } else if (datum instanceof osmNote && !isMultiselect) {
+ // targeting a note
+ context
+ .selectedNoteID(datum.id)
+ .enter(modeSelectNote(context, datum.id));
+
+ } else if (datum instanceof QAItem & !isMultiselect) {
+ // targeting an external QA issue
+ context
+ .selectedErrorID(datum.id)
+ .enter(modeSelectError(context, datum.id, datum.service));
+
+ } else {
+ // targeting nothing
+ context.selectedNoteID(null);
+ context.selectedErrorID(null);
+ if (!isMultiselect && mode.id !== 'browse') {
+ context.enter(modeBrowse(context));
+ }
+ }
+
+ context.ui().closeEditMenu();
+
+ // always request to show the edit menu in case the mode needs it
+ if (showMenu) context.ui().showEditMenu(point, interactionType);
+
+ resetProperties();
+ }
+
+
+ function cancelLongPress() {
+ if (_longPressTimeout) window.clearTimeout(_longPressTimeout);
+ _longPressTimeout = null;
+ }
+
+
+ function resetProperties() {
+ cancelLongPress();
+ _showMenu = false;
+ _lastInteractionType = null;
+ // don't reset _lastMouseEvent since it might still be useful
+ }
+
+
+ function behavior(selection) {
+ resetProperties();
+ _lastMouseEvent = context.map().lastPointerEvent();
+
+ select(window)
+ .on('keydown.select', keydown)
+ .on('keyup.select', keyup)
+ .on(_pointerPrefix + 'move.select', pointermove, true)
+ .on(_pointerPrefix + 'up.select', pointerup, true)
+ .on('pointercancel.select', pointercancel, true)
+ .on('contextmenu.select-window', function() {
+ // Edge and IE really like to show the contextmenu on the
+ // menubar when user presses a keyboard menu button
+ // even after we've already preventdefaulted the key event.
+ var e = event;
+ if (+e.clientX === 0 && +e.clientY === 0) {
+ event.preventDefault();
+ }
+ });
+
+ selection
+ .on(_pointerPrefix + 'down.select', pointerdown)
+ .on('contextmenu.select', contextmenu);
+
+ if (event && event.shiftKey) {
+ context.surface()
+ .classed('behavior-multiselect', true);
+ }
+ }
+
+
+ behavior.off = function(selection) {
+ cancelLongPress();
+
+ select(window)
+ .on('keydown.select', null)
+ .on('keyup.select', null)
+ .on('contextmenu.select-window', null)
+ .on(_pointerPrefix + 'move.select', null, true)
+ .on(_pointerPrefix + 'up.select', null, true)
+ .on('pointercancel.select', null, true);
+
+ selection
+ .on(_pointerPrefix + 'down.select', null)
+ .on('contextmenu.select', null);
+
+ context.surface()
+ .classed('behavior-multiselect', false);
+ };
+
+
+ return behavior;
+ }
+
+ var _relatedParent;
+
+
+ function modeSelect(context, selectedIDs) {
+ var mode = {
+ id: 'select',
+ button: 'browse'
+ };
+
+ var keybinding = utilKeybinding('select');
+
+ var _breatheBehavior = behaviorBreathe();
+ var _modeDragNode = modeDragNode(context);
+ var _selectBehavior;
+ var _behaviors = [];
+
+ var _operations = [];
+ var _newFeature = false;
+ var _follow = false;
+
+
+ function singular() {
+ if (selectedIDs && selectedIDs.length === 1) {
+ return context.hasEntity(selectedIDs[0]);
+ }
+ }
+
+ function selectedEntities() {
+ return selectedIDs.map(function(id) {
+ return context.hasEntity(id);
+ }).filter(Boolean);
+ }
+
+
+ function checkSelectedIDs() {
+ var ids = [];
+ if (Array.isArray(selectedIDs)) {
+ ids = selectedIDs.filter(function(id) {
+ return context.hasEntity(id);
+ });
+ }
+
+ if (!ids.length) {
+ context.enter(modeBrowse(context));
+ return false;
+ } else if ((selectedIDs.length > 1 && ids.length === 1) ||
+ (selectedIDs.length === 1 && ids.length > 1)) {
+ // switch between single- and multi-select UI
+ context.enter(modeSelect(context, ids));
+ return false;
+ }
+
+ selectedIDs = ids;
+ return true;
+ }
+
+
+ // find the common parent ways for nextVertex, previousVertex
+ function commonParents() {
+ var graph = context.graph();
+ var commonParents = [];
+
+ for (var i = 0; i < selectedIDs.length; i++) {
+ var entity = context.hasEntity(selectedIDs[i]);
+ if (!entity || entity.geometry(graph) !== 'vertex') {
+ return []; // selection includes some not vertexes
+ }
+
+ var currParents = graph.parentWays(entity).map(function(w) { return w.id; });
+ if (!commonParents.length) {
+ commonParents = currParents;
+ continue;
+ }
+
+ commonParents = utilArrayIntersection(commonParents, currParents);
+ if (!commonParents.length) {
+ return [];
+ }
+ }
+
+ return commonParents;
+ }
+
+
+ function singularParent() {
+ var parents = commonParents();
+ if (!parents || parents.length === 0) {
+ _relatedParent = null;
+ return null;
+ }
+
+ // relatedParent is used when we visit a vertex with multiple
+ // parents, and we want to remember which parent line we started on.
+
+ if (parents.length === 1) {
+ _relatedParent = parents[0]; // remember this parent for later
+ return _relatedParent;
+ }
+
+ if (parents.indexOf(_relatedParent) !== -1) {
+ return _relatedParent; // prefer the previously seen parent
+ }
+
+ return parents[0];
+ }
+
+
+ mode.selectedIDs = function(val) {
+ if (!arguments.length) return selectedIDs;
+ selectedIDs = val;
+ return mode;
+ };
+
+
+ mode.zoomToSelected = function() {
+ context.map().zoomToEase(selectedEntities());
+ };
+
+
+ mode.newFeature = function(val) {
+ if (!arguments.length) return _newFeature;
+ _newFeature = val;
+ return mode;
+ };
+
+
+ mode.selectBehavior = function(val) {
+ if (!arguments.length) return _selectBehavior;
+ _selectBehavior = val;
+ return mode;
+ };
+
+
+ mode.follow = function(val) {
+ if (!arguments.length) return _follow;
+ _follow = val;
+ return mode;
+ };
+
+ function loadOperations() {
+
+ _operations.forEach(function(operation) {
+ if (operation.behavior) {
+ context.uninstall(operation.behavior);
+ }
+ });
+
+ _operations = Object.values(Operations)
+ .map(function(o) { return o(context, selectedIDs); })
+ .filter(function(o) { return o.available() && o.id !== 'delete' && o.id !== 'downgrade' && o.id !== 'copy'; });
+
+ var copyOperation = operationCopy(context, selectedIDs);
+ if (copyOperation.available()) {
+ // group copy operation with delete/downgrade
+ _operations.push(copyOperation);
+ }
+
+ var downgradeOperation = operationDowngrade(context, selectedIDs);
+ // don't allow delete if downgrade is available
+ var lastOperation = !context.inIntro() && downgradeOperation.available() ? downgradeOperation : operationDelete(context, selectedIDs);
+
+ _operations.push(lastOperation);
+
+ _operations.forEach(function(operation) {
+ if (operation.behavior) {
+ context.install(operation.behavior);
+ }
+ });
+
+ // remove any displayed menu
+ context.ui().closeEditMenu();
+ }
+
+ mode.operations = function() {
+ return _operations;
+ };
+
+
+ mode.enter = function() {
+ if (!checkSelectedIDs()) return;
+
+ context.features().forceVisible(selectedIDs);
+
+ _modeDragNode.restoreSelectedIDs(selectedIDs);
+
+ loadOperations();
+
+ if (!_behaviors.length) {
+ if (!_selectBehavior) _selectBehavior = behaviorSelect(context);
+
+ _behaviors = [
+ behaviorPaste(context),
+ _breatheBehavior,
+ behaviorHover(context).on('hover', context.ui().sidebar.hoverModeSelect),
+ _selectBehavior,
+ behaviorLasso(context),
+ _modeDragNode.behavior,
+ modeDragNote(context).behavior
+ ];
+ }
+ _behaviors.forEach(context.install);
+
+ keybinding
+ .on(_t('inspector.zoom_to.key'), mode.zoomToSelected)
+ .on(['[', 'pgup'], previousVertex)
+ .on([']', 'pgdown'], nextVertex)
+ .on(['{', uiCmd('⌘['), 'home'], firstVertex)
+ .on(['}', uiCmd('⌘]'), 'end'], lastVertex)
+ .on(uiCmd('⇧←'), nudgeSelection([-10, 0]))
+ .on(uiCmd('⇧↑'), nudgeSelection([0, -10]))
+ .on(uiCmd('⇧→'), nudgeSelection([10, 0]))
+ .on(uiCmd('⇧↓'), nudgeSelection([0, 10]))
+ .on(uiCmd('⇧⌘←'), nudgeSelection([-100, 0]))
+ .on(uiCmd('⇧⌘↑'), nudgeSelection([0, -100]))
+ .on(uiCmd('⇧⌘→'), nudgeSelection([100, 0]))
+ .on(uiCmd('⇧⌘↓'), nudgeSelection([0, 100]))
+ .on(['\\', 'pause'], nextParent)
+ .on('⎋', esc, true);
+
+ select(document)
+ .call(keybinding);
+
+ context.ui().sidebar
+ .select(selectedIDs, _newFeature);
+
+ context.history()
+ .on('change.select', function() {
+ loadOperations();
+ // reselect after change in case relation members were removed or added
+ selectElements();
+ })
+ .on('undone.select', checkSelectedIDs)
+ .on('redone.select', checkSelectedIDs);
+
+ context.map()
+ .on('drawn.select', selectElements)
+ .on('crossEditableZoom.select', function() {
+ selectElements();
+ _breatheBehavior.restartIfNeeded(context.surface());
+ });
+
+ context.map().doubleUpHandler()
+ .on('doubleUp.modeSelect', didDoubleUp);
+
+
+ selectElements();
+
+ if (_follow) {
+ var extent = geoExtent();
+ var graph = context.graph();
+ selectedIDs.forEach(function(id) {
+ var entity = context.entity(id);
+ extent._extend(entity.extent(graph));
+ });
+
+ var loc = extent.center();
+ context.map().centerEase(loc);
+ // we could enter the mode multiple times, so reset follow for next time
+ _follow = false;
+ }
+
+
+ function nudgeSelection(delta) {
+ return function() {
+ // prevent nudging during low zoom selection
+ if (!context.map().withinEditableZoom()) return;
+
+ var moveOp = operationMove(context, selectedIDs);
+ if (moveOp.disabled()) {
+ context.ui().flash
+ .duration(4000)
+ .iconName('#iD-operation-' + moveOp.id)
+ .iconClass('operation disabled')
+ .text(moveOp.tooltip)();
+ } else {
+ context.perform(actionMove(selectedIDs, delta, context.projection), moveOp.annotation());
+ }
+ };
+ }
+
+
+ function didDoubleUp(loc) {
+ if (!context.map().withinEditableZoom()) return;
+
+ var target = select(event.target);
+
+ var datum = target.datum();
+ var entity = datum && datum.properties && datum.properties.entity;
+ if (!entity) return;
+
+ if (entity instanceof osmWay && target.classed('target')) {
+ var choice = geoChooseEdge(context.graph().childNodes(entity), loc, context.projection);
+ var prev = entity.nodes[choice.index - 1];
+ var next = entity.nodes[choice.index];
+
+ context.perform(
+ actionAddMidpoint({ loc: choice.loc, edge: [prev, next] }, osmNode()),
+ _t('operations.add.annotation.vertex')
+ );
+
+ } else if (entity.type === 'midpoint') {
+ context.perform(
+ actionAddMidpoint({ loc: entity.loc, edge: entity.edge }, osmNode()),
+ _t('operations.add.annotation.vertex'));
+ }
+ }
+
+
+ function selectElements() {
+ if (!checkSelectedIDs()) return;
+
+ var surface = context.surface();
+
+ surface.selectAll('.selected-member')
+ .classed('selected-member', false);
+
+ surface.selectAll('.selected')
+ .classed('selected', false);
+
+ surface.selectAll('.related')
+ .classed('related', false);
+
+ singularParent();
+ if (_relatedParent) {
+ surface.selectAll(utilEntitySelector([_relatedParent]))
+ .classed('related', true);
+ }
+
+ if (context.map().withinEditableZoom()) {
+ // Apply selection styling if not in wide selection
+
+ surface
+ .selectAll(utilDeepMemberSelector(selectedIDs, context.graph(), true /* skipMultipolgonMembers */))
+ .classed('selected-member', true);
+ surface
+ .selectAll(utilEntityOrDeepMemberSelector(selectedIDs, context.graph()))
+ .classed('selected', true);
+ }
+
+ }
+
+
+ function esc() {
+ if (context.container().select('.combobox').size()) return;
+ context.enter(modeBrowse(context));
+ }
+
+
+ function firstVertex() {
+ event.preventDefault();
+ var entity = singular();
+ var parent = singularParent();
+ var way;
+
+ if (entity && entity.type === 'way') {
+ way = entity;
+ } else if (parent) {
+ way = context.entity(parent);
+ }
+
+ if (way) {
+ context.enter(
+ modeSelect(context, [way.first()]).follow(true)
+ );
+ }
+ }
+
+
+ function lastVertex() {
+ event.preventDefault();
+ var entity = singular();
+ var parent = singularParent();
+ var way;
+
+ if (entity && entity.type === 'way') {
+ way = entity;
+ } else if (parent) {
+ way = context.entity(parent);
+ }
+
+ if (way) {
+ context.enter(
+ modeSelect(context, [way.last()]).follow(true)
+ );
+ }
+ }
+
+
+ function previousVertex() {
+ event.preventDefault();
+ var parent = singularParent();
+ if (!parent) return;
+
+ var way = context.entity(parent);
+ var length = way.nodes.length;
+ var curr = way.nodes.indexOf(selectedIDs[0]);
+ var index = -1;
+
+ if (curr > 0) {
+ index = curr - 1;
+ } else if (way.isClosed()) {
+ index = length - 2;
+ }
+
+ if (index !== -1) {
+ context.enter(
+ modeSelect(context, [way.nodes[index]]).follow(true)
+ );
+ }
+ }
+
+
+ function nextVertex() {
+ event.preventDefault();
+ var parent = singularParent();
+ if (!parent) return;
+
+ var way = context.entity(parent);
+ var length = way.nodes.length;
+ var curr = way.nodes.indexOf(selectedIDs[0]);
+ var index = -1;
+
+ if (curr < length - 1) {
+ index = curr + 1;
+ } else if (way.isClosed()) {
+ index = 0;
+ }
+
+ if (index !== -1) {
+ context.enter(
+ modeSelect(context, [way.nodes[index]]).follow(true)
+ );
+ }
+ }
+
+
+ function nextParent() {
+ event.preventDefault();
+ var parents = commonParents();
+ if (!parents || parents.length < 2) return;
+
+ var index = parents.indexOf(_relatedParent);
+ if (index < 0 || index > parents.length - 2) {
+ _relatedParent = parents[0];
+ } else {
+ _relatedParent = parents[index + 1];
+ }
+
+ var surface = context.surface();
+ surface.selectAll('.related')
+ .classed('related', false);
+
+ if (_relatedParent) {
+ surface.selectAll(utilEntitySelector([_relatedParent]))
+ .classed('related', true);
+ }
+ }
+ };
+
+
+ mode.exit = function() {
+
+ _newFeature = false;
+
+ _operations.forEach(function(operation) {
+ if (operation.behavior) {
+ context.uninstall(operation.behavior);
+ }
+ });
+ _operations = [];
+
+ _behaviors.forEach(context.uninstall);
+
+ select(document)
+ .call(keybinding.unbind);
+
+ context.ui().closeEditMenu();
+
+ context.history()
+ .on('change.select', null)
+ .on('undone.select', null)
+ .on('redone.select', null);
+
+ var surface = context.surface();
+
+ surface
+ .selectAll('.selected-member')
+ .classed('selected-member', false);
+
+ surface
+ .selectAll('.selected')
+ .classed('selected', false);
+
+ surface
+ .selectAll('.highlighted')
+ .classed('highlighted', false);
+
+ surface
+ .selectAll('.related')
+ .classed('related', false);
+
+ context.map().on('drawn.select', null);
+ context.ui().sidebar.hide();
+ context.features().forceVisible([]);
+
+ var entity = singular();
+ if (_newFeature && entity && entity.type === 'relation' &&
+ // no tags
+ Object.keys(entity.tags).length === 0 &&
+ // no parent relations
+ context.graph().parentRelations(entity).length === 0 &&
+ // no members or one member with no role
+ (entity.members.length === 0 || (entity.members.length === 1 && !entity.members[0].role))
+ ) {
+ // the user added this relation but didn't edit it at all, so just delete it
+ var deleteAction = actionDeleteRelation(entity.id, true /* don't delete untagged members */);
+ context.perform(deleteAction, _t('operations.delete.annotation.relation'));
+ }
+ };
+
+
+ return mode;
+ }
+
+ function behaviorLasso(context) {
+
+ // use pointer events on supported platforms; fallback to mouse events
+ var _pointerPrefix = 'PointerEvent' in window ? 'pointer' : 'mouse';
+
+ var behavior = function(selection) {
+ var lasso;
+
+
+ function pointerdown() {
+ var button = 0; // left
+ if (event.button === button && event.shiftKey === true) {
+ lasso = null;
+
+ select(window)
+ .on(_pointerPrefix + 'move.lasso', pointermove)
+ .on(_pointerPrefix + 'up.lasso', pointerup);
+
+ event.stopPropagation();
+ }
+ }
+
+
+ function pointermove() {
+ if (!lasso) {
+ lasso = uiLasso(context);
+ context.surface().call(lasso);
+ }
+
+ lasso.p(context.map().mouse());
+ }
+
+
+ function normalize(a, b) {
+ return [
+ [Math.min(a[0], b[0]), Math.min(a[1], b[1])],
+ [Math.max(a[0], b[0]), Math.max(a[1], b[1])]
+ ];
+ }
+
+
+ function lassoed() {
+ if (!lasso) return [];
+
+ var graph = context.graph();
+ var limitToNodes;
+
+ if (context.map().editableDataEnabled(true /* skipZoomCheck */) && context.map().isInWideSelection()) {
+ // only select from the visible nodes
+ limitToNodes = new Set(utilGetAllNodes(context.selectedIDs(), graph));
+ } else if (!context.map().editableDataEnabled()) {
+ return [];
+ }
+
+ var bounds = lasso.extent().map(context.projection.invert);
+ var extent = geoExtent(normalize(bounds[0], bounds[1]));
+
+ var intersects = context.history().intersects(extent).filter(function(entity) {
+ return entity.type === 'node' &&
+ (!limitToNodes || limitToNodes.has(entity)) &&
+ geoPointInPolygon(context.projection(entity.loc), lasso.coordinates) &&
+ !context.features().isHidden(entity, graph, entity.geometry(graph));
+ });
+
+ // sort the lassoed nodes as best we can
+ intersects.sort(function(node1, node2) {
+ var parents1 = graph.parentWays(node1);
+ var parents2 = graph.parentWays(node2);
+ if (parents1.length && parents2.length) {
+ // both nodes are vertices
+
+ var sharedParents = utilArrayIntersection(parents1, parents2);
+ if (sharedParents.length) {
+ var sharedParentNodes = sharedParents[0].nodes;
+ // vertices are members of the same way; sort them in their listed order
+ return sharedParentNodes.indexOf(node1.id) -
+ sharedParentNodes.indexOf(node2.id);
+ } else {
+ // vertices do not share a way; group them by their respective parent ways
+ return parseFloat(parents1[0].id.slice(1)) -
+ parseFloat(parents2[0].id.slice(1));
+ }
+
+ } else if (parents1.length || parents2.length) {
+ // only one node is a vertex; sort standalone points before vertices
+ return parents1.length - parents2.length;
+ }
+ // both nodes are standalone points; sort left to right
+ return node1.loc[0] - node2.loc[0];
+ });
+
+ return intersects.map(function(entity) { return entity.id; });
+ }
+
+
+ function pointerup() {
+ select(window)
+ .on(_pointerPrefix + 'move.lasso', null)
+ .on(_pointerPrefix + 'up.lasso', null);
+
+ if (!lasso) return;
+
+ var ids = lassoed();
+ lasso.close();
+
+ if (ids.length) {
+ context.enter(modeSelect(context, ids));
+ }
+ }
+
+ selection
+ .on(_pointerPrefix + 'down.lasso', pointerdown);
+ };
+
+
+ behavior.off = function(selection) {
+ selection.on(_pointerPrefix + 'down.lasso', null);
+ };
+
+
+ return behavior;
+ }
+
+ function modeBrowse(context) {
+ var mode = {
+ button: 'browse',
+ id: 'browse',
+ title: _t('modes.browse.title'),
+ description: _t('modes.browse.description')
+ };
+ var sidebar;
+
+ var _selectBehavior;
+ var _behaviors = [];
+
+
+ mode.selectBehavior = function(val) {
+ if (!arguments.length) return _selectBehavior;
+ _selectBehavior = val;
+ return mode;
+ };
+
+
+ mode.enter = function() {
+ if (!_behaviors.length) {
+ if (!_selectBehavior) _selectBehavior = behaviorSelect(context);
+ _behaviors = [
+ behaviorPaste(context),
+ behaviorHover(context).on('hover', context.ui().sidebar.hover),
+ _selectBehavior,
+ behaviorLasso(context),
+ modeDragNode(context).behavior,
+ modeDragNote(context).behavior
+ ];
+ }
+ _behaviors.forEach(context.install);
+
+ // Get focus on the body.
+ if (document.activeElement && document.activeElement.blur) {
+ document.activeElement.blur();
+ }
+
+ if (sidebar) {
+ context.ui().sidebar.show(sidebar);
+ } else {
+ context.ui().sidebar.select(null);
+ }
+ };
+
+
+ mode.exit = function() {
+ context.ui().sidebar.hover.cancel();
+ _behaviors.forEach(context.uninstall);
+
+ if (sidebar) {
+ context.ui().sidebar.hide();
+ }
+ };
+
+
+ mode.sidebar = function(_) {
+ if (!arguments.length) return sidebar;
+ sidebar = _;
+ return mode;
+ };
+
+
+ mode.operations = function() {
+ return [operationPaste(context)];
+ };
+
+
+ return mode;
+ }
+
+ function behaviorAddWay(context) {
+ var dispatch$1 = dispatch('start', 'startFromWay', 'startFromNode');
+ var draw = behaviorDraw(context);
+
+ function behavior(surface) {
+ draw.on('click', function() { dispatch$1.apply('start', this, arguments); })
+ .on('clickWay', function() { dispatch$1.apply('startFromWay', this, arguments); })
+ .on('clickNode', function() { dispatch$1.apply('startFromNode', this, arguments); })
+ .on('cancel', behavior.cancel)
+ .on('finish', behavior.cancel);
+
+ context.map()
+ .dblclickZoomEnable(false);
+
+ surface.call(draw);
+ }
+
+
+ behavior.off = function(surface) {
+ surface.call(draw.off);
+ };
+
+
+ behavior.cancel = function() {
+ window.setTimeout(function() {
+ context.map().dblclickZoomEnable(true);
+ }, 1000);
+
+ context.enter(modeBrowse(context));
+ };
+
+
+ return utilRebind(behavior, dispatch$1, 'on');
+ }
+
+ function behaviorHash(context) {
+
+ // cached window.location.hash
+ var _cachedHash = null;
+ // allowable latitude range
+ var _latitudeLimit = 90 - 1e-8;
+
+ function computedHashParameters() {
+ var map = context.map();
+ var center = map.center();
+ var zoom = map.zoom();
+ var precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
+ var oldParams = utilObjectOmit(utilStringQs(window.location.hash),
+ ['comment', 'source', 'hashtags', 'walkthrough']
+ );
+ var newParams = {};
+
+ delete oldParams.id;
+ var selected = context.selectedIDs().filter(function(id) {
+ return context.hasEntity(id);
+ });
+ if (selected.length) {
+ newParams.id = selected.join(',');
+ }
+
+ newParams.map = zoom.toFixed(2) +
+ '/' + center[1].toFixed(precision) +
+ '/' + center[0].toFixed(precision);
+
+ return Object.assign(oldParams, newParams);
+ }
+
+ function computedHash() {
+ return '#' + utilQsString(computedHashParameters(), true);
+ }
+
+ function computedTitle(includeChangeCount) {
+
+ var baseTitle = context.documentTitleBase() || 'iD';
+ var contextual;
+ var changeCount;
+ var titleID;
+
+ var selected = context.selectedIDs().filter(function(id) {
+ return context.hasEntity(id);
+ });
+ if (selected.length) {
+ var firstLabel = utilDisplayLabel(context.entity(selected[0]), context.graph());
+ if (selected.length > 1 ) {
+ contextual = _t('title.labeled_and_more', {
+ labeled: firstLabel,
+ count: (selected.length - 1).toString()
+ });
+ } else {
+ contextual = firstLabel;
+ }
+ titleID = 'context';
+ }
+
+ if (includeChangeCount) {
+ changeCount = context.history().difference().summary().length;
+ if (changeCount > 0) {
+ titleID = contextual ? 'changes_context' : 'changes';
+ }
+ }
+
+ if (titleID) {
+ return _t('title.format.' + titleID, {
+ changes: changeCount,
+ base: baseTitle,
+ context: contextual
+ });
+ }
+
+ return baseTitle;
+ }
+
+ function updateTitle(includeChangeCount) {
+ if (!context.setsDocumentTitle()) return;
+
+ var newTitle = computedTitle(includeChangeCount);
+ if (document.title !== newTitle) {
+ document.title = newTitle;
+ }
+ }
+
+ function updateHashIfNeeded() {
+ if (context.inIntro()) return;
+
+ var latestHash = computedHash();
+ if (_cachedHash !== latestHash) {
+ _cachedHash = latestHash;
+
+ // Update the URL hash without affecting the browser navigation stack,
+ // though unavoidably creating a browser history entry
+ window.history.replaceState(null, computedTitle(false /* includeChangeCount */), latestHash);
+
+ // set the title we want displayed for the browser tab/window
+ updateTitle(true /* includeChangeCount */);
+ }
+ }
+
+ var _throttledUpdate = throttle(updateHashIfNeeded, 500);
+ var _throttledUpdateTitle = throttle(function() {
+ updateTitle(true /* includeChangeCount */);
+ }, 500);
+
+ function hashchange() {
+
+ // ignore spurious hashchange events
+ if (window.location.hash === _cachedHash) return;
+
+ _cachedHash = window.location.hash;
+
+ var q = utilStringQs(_cachedHash);
+ var mapArgs = (q.map || '').split('/').map(Number);
+
+ if (mapArgs.length < 3 || mapArgs.some(isNaN)) {
+ // replace bogus hash
+ updateHashIfNeeded();
+
+ } else {
+ // don't update if the new hash already reflects the state of iD
+ if (_cachedHash === computedHash()) return;
+
+ var mode = context.mode();
+
+ context.map().centerZoom([mapArgs[2], Math.min(_latitudeLimit, Math.max(-_latitudeLimit, mapArgs[1]))], mapArgs[0]);
+
+ if (q.id) {
+ var ids = q.id.split(',').filter(function(id) {
+ return context.hasEntity(id);
+ });
+ var skip = mode && mode.id === 'select' && utilArrayIdentical(mode.selectedIDs(), ids);
+ if (ids.length && !skip) {
+ context.enter(modeSelect(context, ids));
+ return;
+ }
+ }
+
+ var center = context.map().center();
+ var dist = geoSphericalDistance(center, [mapArgs[2], mapArgs[1]]);
+ var maxdist = 500;
+
+ // Don't allow the hash location to change too much while drawing
+ // This can happen if the user accidently hit the back button. #3996
+ if (mode && mode.id.match(/^draw/) !== null && dist > maxdist) {
+ context.enter(modeBrowse(context));
+ return;
+ }
+ }
+ }
+
+ function behavior() {
+ context.map()
+ .on('move.behaviorHash', _throttledUpdate);
+
+ context.history()
+ .on('change.behaviorHash', _throttledUpdateTitle);
+
+ context
+ .on('enter.behaviorHash', _throttledUpdate);
+
+ select(window)
+ .on('hashchange.behaviorHash', hashchange);
+
+ if (window.location.hash) {
+ var q = utilStringQs(window.location.hash);
+
+ if (q.id) {
+ //if (!context.history().hasRestorableChanges()) {
+ // targeting specific features: download, select, and zoom to them
+ context.zoomToEntity(q.id.split(',')[0], !q.map);
+ //}
+ }
+
+ if (q.walkthrough === 'true') {
+ behavior.startWalkthrough = true;
+ }
+
+ if (q.map) {
+ behavior.hadHash = true;
+ }
+
+ hashchange();
+
+ updateTitle(false);
+ }
+ }
+
+ behavior.off = function() {
+ _throttledUpdate.cancel();
+ _throttledUpdateTitle.cancel();
+
+ context.map()
+ .on('move.behaviorHash', null);
+
+ context
+ .on('enter.behaviorHash', null);
+
+ select(window)
+ .on('hashchange.behaviorHash', null);
+
+ window.location.hash = '';
+ };
+
+ return behavior;
+ }
+
+ // When `debug = true`, we use `Object.freeze` on immutables in iD.
+ // This is only done in testing because of the performance penalty.
+ let debug = false;
+ let d3 = {
+ customEvent: customEvent,
+ dispatch: dispatch,
+ event: event,
+ geoMercator: mercator,
+ geoProjection: projection,
+ polygonArea: d3_polygonArea,
+ polygonCentroid: d3_polygonCentroid,
+ select: select,
+ selectAll: selectAll,
+ timerFlush: timerFlush
+ };
+
+ var iD = /*#__PURE__*/Object.freeze({
+ __proto__: null,
+ debug: debug,
+ d3: d3,
+ actionAddEntity: actionAddEntity,
+ actionAddMember: actionAddMember,
+ actionAddMidpoint: actionAddMidpoint,
+ actionAddVertex: actionAddVertex,
+ actionChangeMember: actionChangeMember,
+ actionChangePreset: actionChangePreset,
+ actionChangeTags: actionChangeTags,
+ actionCircularize: actionCircularize,
+ actionConnect: actionConnect,
+ actionCopyEntities: actionCopyEntities,
+ actionDeleteMember: actionDeleteMember,
+ actionDeleteMultiple: actionDeleteMultiple,
+ actionDeleteNode: actionDeleteNode,
+ actionDeleteRelation: actionDeleteRelation,
+ actionDeleteWay: actionDeleteWay,
+ actionDiscardTags: actionDiscardTags,
+ actionDisconnect: actionDisconnect,
+ actionExtract: actionExtract,
+ actionJoin: actionJoin,
+ actionMerge: actionMerge,
+ actionMergeNodes: actionMergeNodes,
+ actionMergePolygon: actionMergePolygon,
+ actionMergeRemoteChanges: actionMergeRemoteChanges,
+ actionMove: actionMove,
+ actionMoveMember: actionMoveMember,
+ actionMoveNode: actionMoveNode,
+ actionNoop: actionNoop,
+ actionOrthogonalize: actionOrthogonalize,
+ actionRestrictTurn: actionRestrictTurn,
+ actionReverse: actionReverse,
+ actionRevert: actionRevert,
+ actionRotate: actionRotate,
+ actionSplit: actionSplit,
+ actionStraightenNodes: actionStraightenNodes,
+ actionStraightenWay: actionStraightenWay,
+ actionUnrestrictTurn: actionUnrestrictTurn,
+ actionReflect: actionReflect,
+ actionUpgradeTags: actionUpgradeTags,
+ actionRapidAcceptFeature: actionRapidAcceptFeature,
+ behaviorAddWay: behaviorAddWay,
+ behaviorBreathe: behaviorBreathe,
+ behaviorDrag: behaviorDrag,
+ behaviorDrawWay: behaviorDrawWay,
+ behaviorDraw: behaviorDraw,
+ behaviorEdit: behaviorEdit,
+ behaviorHash: behaviorHash,
+ behaviorHover: behaviorHover,
+ behaviorLasso: behaviorLasso,
+ behaviorOperation: behaviorOperation,
+ behaviorPaste: behaviorPaste,
+ behaviorSelect: behaviorSelect,
+ coreContext: coreContext,
+ coreFileFetcher: coreFileFetcher,
+ fileFetcher: _mainFileFetcher,
+ coreDifference: coreDifference,
+ coreGraph: coreGraph,
+ coreHistory: coreHistory,
+ coreRapidContext: coreRapidContext,
+ coreLocalizer: coreLocalizer,
+ t: _t,
+ localizer: _mainLocalizer,
+ prefs: corePreferences,
+ coreTree: coreTree,
+ coreUploader: coreUploader,
+ coreValidator: coreValidator,
+ geoExtent: geoExtent,
+ geoExtentFromBounds: geoExtentFromBounds,
+ geoLatToMeters: geoLatToMeters,
+ geoLonToMeters: geoLonToMeters,
+ geoMetersToLat: geoMetersToLat,
+ geoMetersToLon: geoMetersToLon,
+ geoMetersToOffset: geoMetersToOffset,
+ geoOffsetToMeters: geoOffsetToMeters,
+ geoScaleToZoom: geoScaleToZoom,
+ geoSphericalClosestNode: geoSphericalClosestNode,
+ geoSphericalDistance: geoSphericalDistance,
+ geoZoomToScale: geoZoomToScale,
+ geoAngle: geoAngle,
+ geoChooseEdge: geoChooseEdge,
+ geoEdgeEqual: geoEdgeEqual,
+ geoGetSmallestSurroundingRectangle: geoGetSmallestSurroundingRectangle,
+ geoHasLineIntersections: geoHasLineIntersections,
+ geoHasSelfIntersections: geoHasSelfIntersections,
+ geoRotate: geoRotate,
+ geoLineIntersection: geoLineIntersection,
+ geoPathHasIntersections: geoPathHasIntersections,
+ geoPathIntersections: geoPathIntersections,
+ geoPathLength: geoPathLength,
+ geoPointInPolygon: geoPointInPolygon,
+ geoPolygonContainsPolygon: geoPolygonContainsPolygon,
+ geoPolygonIntersectsPolygon: geoPolygonIntersectsPolygon,
+ geoViewportEdge: geoViewportEdge,
+ geoRawMercator: geoRawMercator,
+ geoVecAdd: geoVecAdd,
+ geoVecAngle: geoVecAngle,
+ geoVecCross: geoVecCross,
+ geoVecDot: geoVecDot,
+ geoVecEqual: geoVecEqual,
+ geoVecFloor: geoVecFloor,
+ geoVecInterp: geoVecInterp,
+ geoVecLength: geoVecLength,
+ geoVecLengthSquare: geoVecLengthSquare,
+ geoVecNormalize: geoVecNormalize,
+ geoVecNormalizedDot: geoVecNormalizedDot,
+ geoVecProject: geoVecProject,
+ geoVecSubtract: geoVecSubtract,
+ geoVecScale: geoVecScale,
+ geoOrthoNormalizedDotProduct: geoOrthoNormalizedDotProduct,
+ geoOrthoCalcScore: geoOrthoCalcScore,
+ geoOrthoMaxOffsetAngle: geoOrthoMaxOffsetAngle,
+ geoOrthoCanOrthogonalize: geoOrthoCanOrthogonalize,
+ modeAddArea: modeAddArea,
+ modeAddLine: modeAddLine,
+ modeAddPoint: modeAddPoint,
+ modeAddNote: modeAddNote,
+ modeBrowse: modeBrowse,
+ modeDragNode: modeDragNode,
+ modeDragNote: modeDragNote,
+ modeDrawArea: modeDrawArea,
+ modeDrawLine: modeDrawLine,
+ modeMove: modeMove,
+ modeRotate: modeRotate,
+ modeSave: modeSave,
+ modeSelect: modeSelect,
+ modeSelectData: modeSelectData,
+ modeSelectError: modeSelectError,
+ modeSelectNote: modeSelectNote,
+ modeRapidSelectFeatures: modeRapidSelectFeatures,
+ operationCircularize: operationCircularize,
+ operationContinue: operationContinue,
+ operationCycleHighwayTag: operationCycleHighwayTag,
+ operationCopy: operationCopy,
+ operationDelete: operationDelete,
+ operationDisconnect: operationDisconnect,
+ operationDowngrade: operationDowngrade,
+ operationExtract: operationExtract,
+ operationMerge: operationMerge,
+ operationMove: operationMove,
+ operationOrthogonalize: operationOrthogonalize,
+ operationPaste: operationPaste,
+ operationReflectShort: operationReflectShort,
+ operationReflectLong: operationReflectLong,
+ operationReverse: operationReverse,
+ operationRotate: operationRotate,
+ operationSplit: operationSplit,
+ operationStraighten: operationStraighten,
+ osmChangeset: osmChangeset,
+ osmEntity: osmEntity,
+ osmNode: osmNode,
+ osmNote: osmNote,
+ osmRelation: osmRelation,
+ osmWay: osmWay,
+ QAItem: QAItem,
+ osmIntersection: osmIntersection,
+ osmTurn: osmTurn,
+ osmInferRestriction: osmInferRestriction,
+ osmLanes: osmLanes,
+ osmOldMultipolygonOuterMemberOfRelation: osmOldMultipolygonOuterMemberOfRelation,
+ osmIsOldMultipolygonOuterMember: osmIsOldMultipolygonOuterMember,
+ osmOldMultipolygonOuterMember: osmOldMultipolygonOuterMember,
+ osmJoinWays: osmJoinWays,
+ get osmAreaKeys () { return osmAreaKeys; },
+ osmSetAreaKeys: osmSetAreaKeys,
+ osmTagSuggestingArea: osmTagSuggestingArea,
+ get osmPointTags () { return osmPointTags; },
+ osmSetPointTags: osmSetPointTags,
+ get osmVertexTags () { return osmVertexTags; },
+ osmSetVertexTags: osmSetVertexTags,
+ osmNodeGeometriesForTags: osmNodeGeometriesForTags,
+ osmOneWayTags: osmOneWayTags,
+ osmPavedTags: osmPavedTags,
+ osmIsInterestingTag: osmIsInterestingTag,
+ osmRoutableHighwayTagValues: osmRoutableHighwayTagValues,
+ osmFlowingWaterwayTagValues: osmFlowingWaterwayTagValues,
+ osmRailwayTrackTagValues: osmRailwayTrackTagValues,
+ presetCategory: presetCategory,
+ presetCollection: presetCollection,
+ presetField: presetField,
+ presetPreset: presetPreset,
+ presetManager: _mainPresetIndex,
+ presetIndex: presetIndex,
+ rendererBackgroundSource: rendererBackgroundSource,
+ rendererBackground: rendererBackground,
+ rendererFeatures: rendererFeatures,
+ rendererMap: rendererMap,
+ rendererPhotos: rendererPhotos,
+ rendererTileLayer: rendererTileLayer,
+ services: services,
+ serviceEsriData: serviceEsriData,
+ serviceFbAIFeatures: serviceFbAIFeatures,
+ serviceKeepRight: serviceKeepRight,
+ serviceImproveOSM: serviceImproveOSM,
+ serviceOsmose: serviceOsmose,
+ serviceMapillary: serviceMapillary,
+ serviceMapRules: serviceMapRules,
+ serviceNominatim: serviceNominatim,
+ serviceOpenstreetcam: serviceOpenstreetcam,
+ serviceOsm: serviceOsm,
+ serviceOsmWikibase: serviceOsmWikibase,
+ serviceStreetside: serviceStreetside,
+ serviceTaginfo: serviceTaginfo,
+ serviceVectorTile: serviceVectorTile,
+ serviceWikidata: serviceWikidata,
+ serviceWikipedia: serviceWikipedia,
+ svgAreas: svgAreas,
+ svgData: svgData,
+ svgDebug: svgDebug,
+ svgDefs: svgDefs,
+ svgKeepRight: svgKeepRight,
+ svgIcon: svgIcon,
+ svgGeolocate: svgGeolocate,
+ svgLabels: svgLabels,
+ svgLayers: svgLayers,
+ svgLines: svgLines,
+ svgMapillaryImages: svgMapillaryImages,
+ svgMapillarySigns: svgMapillarySigns,
+ svgMidpoints: svgMidpoints,
+ svgNotes: svgNotes,
+ svgMarkerSegments: svgMarkerSegments,
+ svgOpenstreetcamImages: svgOpenstreetcamImages,
+ svgOsm: svgOsm,
+ svgPassiveVertex: svgPassiveVertex,
+ svgPath: svgPath,
+ svgPointTransform: svgPointTransform,
+ svgPoints: svgPoints,
+ svgRelationMemberTags: svgRelationMemberTags,
+ svgSegmentWay: svgSegmentWay,
+ svgStreetside: svgStreetside,
+ svgTagClasses: svgTagClasses,
+ svgTagPattern: svgTagPattern,
+ svgTouch: svgTouch,
+ svgTurns: svgTurns,
+ svgVertices: svgVertices,
+ svgRapidFeatures: svgRapidFeatures,
+ uiFieldDefaultCheck: uiFieldCheck,
+ uiFieldOnewayCheck: uiFieldCheck,
+ uiFieldCheck: uiFieldCheck,
+ uiFieldMultiCombo: uiFieldCombo,
+ uiFieldNetworkCombo: uiFieldCombo,
+ uiFieldSemiCombo: uiFieldCombo,
+ uiFieldTypeCombo: uiFieldCombo,
+ uiFieldCombo: uiFieldCombo,
+ uiFieldUrl: uiFieldText,
+ uiFieldIdentifier: uiFieldText,
+ uiFieldNumber: uiFieldText,
+ uiFieldTel: uiFieldText,
+ uiFieldEmail: uiFieldText,
+ uiFieldText: uiFieldText,
+ uiFieldAccess: uiFieldAccess,
+ uiFieldAddress: uiFieldAddress,
+ uiFieldCycleway: uiFieldCycleway,
+ uiFieldLanes: uiFieldLanes,
+ uiFieldLocalized: uiFieldLocalized,
+ uiFieldMaxspeed: uiFieldMaxspeed,
+ uiFieldStructureRadio: uiFieldRadio,
+ uiFieldRadio: uiFieldRadio,
+ uiFieldRestrictions: uiFieldRestrictions,
+ uiFieldTextarea: uiFieldTextarea,
+ uiFieldWikidata: uiFieldWikidata,
+ uiFieldWikipedia: uiFieldWikipedia,
+ uiFields: uiFields,
+ uiIntro: uiIntro,
+ uiPanelBackground: uiPanelBackground,
+ uiPanelHistory: uiPanelHistory,
+ uiPanelLocation: uiPanelLocation,
+ uiPanelMeasurement: uiPanelMeasurement,
+ uiInfoPanels: uiInfoPanels,
+ uiPaneBackground: uiPaneBackground,
+ uiPaneHelp: uiPaneHelp,
+ uiPaneIssues: uiPaneIssues,
+ uiPaneMapData: uiPaneMapData,
+ uiPanePreferences: uiPanePreferences,
+ uiSectionBackgroundDisplayOptions: uiSectionBackgroundDisplayOptions,
+ uiSectionBackgroundList: uiSectionBackgroundList,
+ uiSectionBackgroundOffset: uiSectionBackgroundOffset,
+ uiSectionChanges: uiSectionChanges,
+ uiSectionDataLayers: uiSectionDataLayers,
+ uiSectionEntityIssues: uiSectionEntityIssues,
+ uiSectionFeatureType: uiSectionFeatureType,
+ uiSectionMapFeatures: uiSectionMapFeatures,
+ uiSectionMapStyleOptions: uiSectionMapStyleOptions,
+ uiSectionOverlayList: uiSectionOverlayList,
+ uiSectionPhotoOverlays: uiSectionPhotoOverlays,
+ uiSectionPresetFields: uiSectionPresetFields,
+ uiSectionPrivacy: uiSectionPrivacy,
+ uiSectionRawMemberEditor: uiSectionRawMemberEditor,
+ uiSectionRawMembershipEditor: uiSectionRawMembershipEditor,
+ uiSectionRawTagEditor: uiSectionRawTagEditor,
+ uiSectionSelectionList: uiSectionSelectionList,
+ uiSectionValidationIssues: uiSectionValidationIssues,
+ uiSectionValidationOptions: uiSectionValidationOptions,
+ uiSectionValidationRules: uiSectionValidationRules,
+ uiSectionValidationStatus: uiSectionValidationStatus,
+ uiSettingsCustomBackground: uiSettingsCustomBackground,
+ uiSettingsCustomData: uiSettingsCustomData,
+ uiInit: uiInit,
+ uiAccount: uiAccount,
+ uiAttribution: uiAttribution,
+ uiChangesetEditor: uiChangesetEditor,
+ uiCmd: uiCmd,
+ uiCombobox: uiCombobox,
+ uiCommit: uiCommit,
+ uiCommitWarnings: uiCommitWarnings,
+ uiConfirm: uiConfirm,
+ uiConflicts: uiConflicts,
+ uiContributors: uiContributors,
+ uiCurtain: uiCurtain,
+ uiDataEditor: uiDataEditor,
+ uiDataHeader: uiDataHeader,
+ uiDisclosure: uiDisclosure,
+ uiEditMenu: uiEditMenu,
+ uiEntityEditor: uiEntityEditor,
+ uiFeatureInfo: uiFeatureInfo,
+ uiFeatureList: uiFeatureList,
+ uiField: uiField,
+ uiFieldHelp: uiFieldHelp,
+ uiFlash: uiFlash,
+ uiFormFields: uiFormFields,
+ uiFullScreen: uiFullScreen,
+ uiGeolocate: uiGeolocate,
+ uiImproveOsmComments: uiImproveOsmComments,
+ uiImproveOsmDetails: uiImproveOsmDetails,
+ uiImproveOsmEditor: uiImproveOsmEditor,
+ uiImproveOsmHeader: uiImproveOsmHeader,
+ uiInfo: uiInfo,
+ uiInspector: uiInspector,
+ uiIssuesInfo: uiIssuesInfo,
+ uiKeepRightDetails: uiKeepRightDetails,
+ uiKeepRightEditor: uiKeepRightEditor,
+ uiKeepRightHeader: uiKeepRightHeader,
+ uiLasso: uiLasso,
+ uiLoading: uiLoading,
+ uiMapInMap: uiMapInMap,
+ uiModal: uiModal,
+ uiNotice: uiNotice,
+ uiNoteComments: uiNoteComments,
+ uiNoteEditor: uiNoteEditor,
+ uiNoteHeader: uiNoteHeader,
+ uiNoteReport: uiNoteReport,
+ uiPopover: uiPopover,
+ uiPresetIcon: uiPresetIcon,
+ uiPresetList: uiPresetList,
+ uiRestore: uiRestore,
+ uiScale: uiScale,
+ uiSidebar: uiSidebar,
+ uiSourceSwitch: uiSourceSwitch,
+ uiSpinner: uiSpinner,
+ uiSplash: uiSplash,
+ uiStatus: uiStatus,
+ uiSuccess: uiSuccess,
+ uiTagReference: uiTagReference,
+ uiToggle: uiToggle,
+ uiTooltip: uiTooltip,
+ uiVersion: uiVersion,
+ uiViewOnOSM: uiViewOnOSM,
+ uiViewOnKeepRight: uiViewOnKeepRight,
+ uiZoom: uiZoom,
+ uiRapidColorpicker: uiRapidColorpicker,
+ uiRapidFeatureInspector: uiRapidFeatureInspector,
+ uiRapidFirstEditDialog: uiRapidFirstEditDialog,
+ uiRapidFeatureToggleDialog: uiRapidFeatureToggleDialog,
+ uiRapidPowerUserFeaturesDialog: uiRapidPowerUserFeaturesDialog,
+ uiRapidServiceLicense: uiRapidServiceLicense,
+ uiRapidSplash: uiRapidSplash,
+ uiRapidWhatsNew: uiRapidWhatsNew,
+ uiRapidViewManageDatasets: uiRapidViewManageDatasets,
+ utilAesEncrypt: utilAesEncrypt,
+ utilAesDecrypt: utilAesDecrypt,
+ utilArrayChunk: utilArrayChunk,
+ utilArrayDifference: utilArrayDifference,
+ utilArrayFlatten: utilArrayFlatten,
+ utilArrayGroupBy: utilArrayGroupBy,
+ utilArrayIdentical: utilArrayIdentical,
+ utilArrayIntersection: utilArrayIntersection,
+ utilArrayUnion: utilArrayUnion,
+ utilArrayUniq: utilArrayUniq,
+ utilArrayUniqBy: utilArrayUniqBy,
+ utilAsyncMap: utilAsyncMap,
+ utilCleanTags: utilCleanTags,
+ utilCombinedTags: utilCombinedTags,
+ utilDeepMemberSelector: utilDeepMemberSelector,
+ utilDetect: utilDetect,
+ utilDisplayName: utilDisplayName,
+ utilDisplayNameForPath: utilDisplayNameForPath,
+ utilDisplayType: utilDisplayType,
+ utilDisplayLabel: utilDisplayLabel,
+ utilEntityRoot: utilEntityRoot,
+ utilEditDistance: utilEditDistance,
+ utilEntitySelector: utilEntitySelector,
+ utilEntityOrMemberSelector: utilEntityOrMemberSelector,
+ utilEntityOrDeepMemberSelector: utilEntityOrDeepMemberSelector,
+ utilFastMouse: utilFastMouse,
+ utilFunctor: utilFunctor,
+ utilGetAllNodes: utilGetAllNodes,
+ utilGetSetValue: utilGetSetValue,
+ utilHashcode: utilHashcode,
+ utilHighlightEntities: utilHighlightEntities,
+ utilKeybinding: utilKeybinding,
+ utilNoAuto: utilNoAuto,
+ utilObjectOmit: utilObjectOmit,
+ utilPrefixCSSProperty: utilPrefixCSSProperty,
+ utilPrefixDOMProperty: utilPrefixDOMProperty,
+ utilQsString: utilQsString,
+ utilRebind: utilRebind,
+ utilSafeClassName: utilSafeClassName,
+ utilSetTransform: utilSetTransform,
+ utilSessionMutex: utilSessionMutex,
+ utilStringQs: utilStringQs,
+ utilTagDiff: utilTagDiff,
+ utilTagText: utilTagText,
+ utilTiler: utilTiler,
+ utilTotalExtent: utilTotalExtent,
+ utilTriggerEvent: utilTriggerEvent,
+ utilUnicodeCharsCount: utilUnicodeCharsCount,
+ utilUnicodeCharsTruncated: utilUnicodeCharsTruncated,
+ utilUniqueDomId: utilUniqueDomId,
+ utilWrap: utilWrap,
+ validationAlmostJunction: validationAlmostJunction,
+ validationCloseNodes: validationCloseNodes,
+ validationCrossingWays: validationCrossingWays,
+ validationDisconnectedWay: validationDisconnectedWay,
+ validationFormatting: validationFormatting,
+ validationHelpRequest: validationHelpRequest,
+ validationImpossibleOneway: validationImpossibleOneway,
+ validationIncompatibleSource: validationIncompatibleSource,
+ validationMaprules: validationMaprules,
+ validationMismatchedGeometry: validationMismatchedGeometry,
+ validationMissingRole: validationMissingRole,
+ validationMissingTag: validationMissingTag,
+ validationOutdatedTags: validationOutdatedTags,
+ validationPrivateData: validationPrivateData,
+ validationShortRoad: validationShortRoad,
+ validationYShapedConnection: validationYShapedConnection,
+ validationSuspiciousName: validationSuspiciousName,
+ validationUnsquareWay: validationUnsquareWay
+ });
+
+ // polyfill requestIdleCallback
+ window.requestIdleCallback = window.requestIdleCallback ||
+ function(cb) {
+ var start = Date.now();
+ return window.requestAnimationFrame(function() {
+ cb({
+ didTimeout: false,
+ timeRemaining: function() {
+ return Math.max(0, 50 - (Date.now() - start));
+ }
+ });
+ });
+ };
+
+ window.cancelIdleCallback = window.cancelIdleCallback ||
+ function(id) {
+ window.cancelAnimationFrame(id);
+ };
+ window.iD = iD;
+
+}());
+//# sourceMappingURL=iD.js.map
diff --git a/dist/iD.js.map b/dist/iD.js.map
new file mode 100644
index 0000000000..866e000c56
--- /dev/null
+++ b/dist/iD.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"iD.js","sources":["../node_modules/es6-set/is-implemented.js","../node_modules/es5-ext/function/noop.js","../node_modules/es5-ext/object/is-value.js","../node_modules/es5-ext/object/valid-value.js","../node_modules/es5-ext/array/#/clear.js","../node_modules/es5-ext/number/is-nan/is-implemented.js","../node_modules/es5-ext/number/is-nan/shim.js","../node_modules/es5-ext/number/is-nan/index.js","../node_modules/es5-ext/math/sign/is-implemented.js","../node_modules/es5-ext/math/sign/shim.js","../node_modules/es5-ext/math/sign/index.js","../node_modules/es5-ext/number/to-integer.js","../node_modules/es5-ext/number/to-pos-integer.js","../node_modules/es5-ext/array/#/e-index-of.js","../node_modules/es5-ext/object/set-prototype-of/is-implemented.js","../node_modules/es5-ext/object/is-object.js","../node_modules/es5-ext/object/create.js","../node_modules/es5-ext/object/set-prototype-of/shim.js","../node_modules/es5-ext/object/set-prototype-of/index.js","../node_modules/es5-ext/object/valid-callable.js","../node_modules/type/value/is.js","../node_modules/type/object/is.js","../node_modules/type/prototype/is.js","../node_modules/type/function/is.js","../node_modules/type/plain-function/is.js","../node_modules/es5-ext/object/assign/is-implemented.js","../node_modules/es5-ext/object/keys/is-implemented.js","../node_modules/es5-ext/object/keys/shim.js","../node_modules/es5-ext/object/keys/index.js","../node_modules/es5-ext/object/assign/shim.js","../node_modules/es5-ext/object/assign/index.js","../node_modules/es5-ext/object/normalize-options.js","../node_modules/es5-ext/string/#/contains/is-implemented.js","../node_modules/es5-ext/string/#/contains/shim.js","../node_modules/es5-ext/string/#/contains/index.js","../node_modules/d/index.js","../node_modules/event-emitter/index.js","../node_modules/es6-set/node_modules/es6-symbol/is-implemented.js","../node_modules/es6-set/node_modules/es6-symbol/is-symbol.js","../node_modules/es6-set/node_modules/es6-symbol/validate-symbol.js","../node_modules/es6-set/node_modules/es6-symbol/polyfill.js","../node_modules/es6-set/node_modules/es6-symbol/index.js","../node_modules/es5-ext/function/is-arguments.js","../node_modules/es5-ext/string/is-string.js","../node_modules/es5-ext/global.js","../node_modules/es6-symbol/is-implemented.js","../node_modules/es6-symbol/is-symbol.js","../node_modules/es6-symbol/validate-symbol.js","../node_modules/es6-symbol/lib/private/generate-name.js","../node_modules/es6-symbol/lib/private/setup/standard-symbols.js","../node_modules/es6-symbol/lib/private/setup/symbol-registry.js","../node_modules/es6-symbol/polyfill.js","../node_modules/es6-symbol/index.js","../node_modules/es6-iterator/is-iterable.js","../node_modules/es6-iterator/valid-iterable.js","../node_modules/type/string/coerce.js","../node_modules/type/lib/safe-to-string.js","../node_modules/type/lib/to-short-string.js","../node_modules/type/lib/resolve-exception.js","../node_modules/type/value/ensure.js","../node_modules/type/plain-function/ensure.js","../node_modules/es5-ext/array/from/is-implemented.js","../node_modules/es5-ext/function/is-function.js","../node_modules/es5-ext/array/from/shim.js","../node_modules/es5-ext/array/from/index.js","../node_modules/es5-ext/object/copy.js","../node_modules/es5-ext/object/_iterate.js","../node_modules/es5-ext/object/for-each.js","../node_modules/es5-ext/object/map.js","../node_modules/d/auto-bind.js","../node_modules/es6-iterator/index.js","../node_modules/es6-iterator/array.js","../node_modules/es6-iterator/string.js","../node_modules/es6-iterator/get.js","../node_modules/es6-iterator/for-of.js","../node_modules/es6-set/lib/iterator.js","../node_modules/es6-set/is-native-implemented.js","../node_modules/es6-set/polyfill.js","../node_modules/es6-set/index.js","../node_modules/es6-map/is-implemented.js","../node_modules/es5-ext/object/primitive-set.js","../node_modules/es6-map/lib/iterator-kinds.js","../node_modules/es6-map/lib/iterator.js","../node_modules/es6-map/is-native-implemented.js","../node_modules/es6-map/polyfill.js","../node_modules/es6-map/index.js","../node_modules/object-keys/isArguments.js","../node_modules/object-keys/implementation.js","../node_modules/object-keys/index.js","../node_modules/define-properties/index.js","../node_modules/function-bind/implementation.js","../node_modules/function-bind/index.js","../node_modules/has/src/index.js","../node_modules/es-to-primitive/helpers/isPrimitive.js","../node_modules/is-callable/index.js","../node_modules/is-date-object/index.js","../node_modules/has-symbols/shams.js","../node_modules/has-symbols/index.js","../node_modules/is-symbol/index.js","../node_modules/es-to-primitive/es2015.js","../node_modules/es-to-primitive/es6.js","../node_modules/object-inspect/index.js","../node_modules/es-abstract/GetIntrinsic.js","../node_modules/es-abstract/helpers/assertRecord.js","../node_modules/es-abstract/helpers/isNaN.js","../node_modules/es-abstract/helpers/isFinite.js","../node_modules/es-abstract/helpers/maxSafeInteger.js","../node_modules/es-abstract/helpers/assign.js","../node_modules/es-abstract/helpers/sign.js","../node_modules/es-abstract/helpers/mod.js","../node_modules/es-abstract/helpers/isPrimitive.js","../node_modules/es-abstract/helpers/forEach.js","../node_modules/es-abstract/helpers/every.js","../node_modules/es-abstract/helpers/isSamePropertyDescriptor.js","../node_modules/es-abstract/helpers/isPropertyDescriptor.js","../node_modules/es-abstract/helpers/callBind.js","../node_modules/es-abstract/helpers/callBound.js","../node_modules/es-abstract/helpers/regexTester.js","../node_modules/es-abstract/helpers/isPrefixOf.js","../node_modules/es-to-primitive/es5.js","../node_modules/es-abstract/es5.js","../node_modules/is-regex/index.js","../node_modules/es-abstract/es2015.js","../node_modules/es-abstract/es6.js","../node_modules/array.prototype.find/implementation.js","../node_modules/array.prototype.find/polyfill.js","../node_modules/array.prototype.find/shim.js","../node_modules/array.prototype.find/index.js","../node_modules/array.prototype.findindex/implementation.js","../node_modules/array.prototype.findindex/polyfill.js","../node_modules/array.prototype.findindex/shim.js","../node_modules/array.prototype.findindex/index.js","../node_modules/array.from/implementation.js","../node_modules/array.from/polyfill.js","../node_modules/array.from/shim.js","../node_modules/array.from/index.js","../node_modules/es-abstract/es2016.js","../node_modules/es-abstract/es7.js","../node_modules/object.values/implementation.js","../node_modules/object.values/polyfill.js","../node_modules/object.values/shim.js","../node_modules/object.values/index.js","../node_modules/object.assign/implementation.js","../node_modules/object.assign/polyfill.js","../node_modules/object.assign/shim.js","../node_modules/object.assign/index.js","../node_modules/promise-polyfill/src/finally.js","../node_modules/promise-polyfill/src/index.js","../node_modules/promise-polyfill/src/polyfill.js","../node_modules/setasap/setAsap.js","../node_modules/performance-now/lib/performance-now.js","../node_modules/raf/index.js","../node_modules/whatwg-fetch/fetch.js","../node_modules/browser-polyfills/lib/index.js","../node_modules/string.fromcodepoint/node_modules/has-symbols/shams.js","../node_modules/string.fromcodepoint/node_modules/has-symbols/index.js","../node_modules/string.fromcodepoint/node_modules/es-abstract/GetIntrinsic.js","../node_modules/string.fromcodepoint/node_modules/es-abstract/helpers/callBind.js","../node_modules/string.fromcodepoint/node_modules/es-abstract/helpers/callBound.js","../node_modules/string.fromcodepoint/node_modules/es-abstract/helpers/regexTester.js","../node_modules/string.fromcodepoint/node_modules/es-abstract/helpers/isPrimitive.js","../node_modules/string.fromcodepoint/node_modules/es-to-primitive/helpers/isPrimitive.js","../node_modules/string.fromcodepoint/node_modules/is-callable/index.js","../node_modules/string.fromcodepoint/node_modules/es-to-primitive/es2015.js","../node_modules/string.fromcodepoint/node_modules/es-abstract/2019/ToPrimitive.js","../node_modules/string.fromcodepoint/node_modules/es-abstract/2019/ToNumber.js","../node_modules/string.fromcodepoint/node_modules/es-abstract/helpers/isNaN.js","../node_modules/string.fromcodepoint/node_modules/es-abstract/helpers/isFinite.js","../node_modules/string.fromcodepoint/node_modules/es-abstract/2019/IsInteger.js","../node_modules/string.fromcodepoint/implementation.js","../node_modules/string.fromcodepoint/polyfill.js","../node_modules/string.fromcodepoint/shim.js","../node_modules/string.fromcodepoint/auto.js","../node_modules/abortcontroller-polyfill/dist/polyfill-patch-fetch.js","../modules/actions/add_entity.js","../modules/actions/reverse.js","../modules/osm/tags.js","../node_modules/d3-geo/src/adder.js","../node_modules/d3-geo/src/math.js","../node_modules/d3-geo/src/noop.js","../node_modules/d3-geo/src/stream.js","../node_modules/d3-geo/src/area.js","../node_modules/d3-geo/src/cartesian.js","../node_modules/d3-geo/src/bounds.js","../node_modules/d3-geo/src/centroid.js","../node_modules/d3-geo/src/compose.js","../node_modules/d3-geo/src/rotation.js","../node_modules/d3-geo/src/circle.js","../node_modules/d3-geo/src/clip/buffer.js","../node_modules/d3-geo/src/pointEqual.js","../node_modules/d3-geo/src/clip/rejoin.js","../node_modules/d3-geo/src/polygonContains.js","../node_modules/d3-array/src/ascending.js","../node_modules/d3-array/src/bisector.js","../node_modules/d3-array/src/bisect.js","../node_modules/d3-array/src/descending.js","../node_modules/d3-array/src/number.js","../node_modules/d3-array/src/range.js","../node_modules/d3-array/src/ticks.js","../node_modules/d3-array/src/quantile.js","../node_modules/d3-array/src/median.js","../node_modules/d3-array/src/merge.js","../node_modules/d3-geo/src/clip/index.js","../node_modules/d3-geo/src/clip/antimeridian.js","../node_modules/d3-geo/src/clip/circle.js","../node_modules/d3-geo/src/clip/line.js","../node_modules/d3-geo/src/clip/rectangle.js","../node_modules/d3-geo/src/length.js","../node_modules/d3-geo/src/identity.js","../node_modules/d3-geo/src/path/area.js","../node_modules/d3-geo/src/path/bounds.js","../node_modules/d3-geo/src/path/centroid.js","../node_modules/d3-geo/src/path/context.js","../node_modules/d3-geo/src/path/measure.js","../node_modules/d3-geo/src/path/string.js","../node_modules/d3-geo/src/path/index.js","../node_modules/d3-geo/src/transform.js","../node_modules/d3-geo/src/projection/fit.js","../node_modules/d3-geo/src/projection/resample.js","../node_modules/d3-geo/src/projection/index.js","../node_modules/d3-geo/src/projection/mercator.js","../node_modules/d3-geo/src/projection/identity.js","../modules/geo/geo.js","../modules/geo/extent.js","../node_modules/d3-polygon/src/area.js","../node_modules/d3-polygon/src/centroid.js","../node_modules/d3-polygon/src/cross.js","../node_modules/d3-polygon/src/hull.js","../modules/geo/vector.js","../modules/geo/geom.js","../node_modules/d3-dispatch/src/dispatch.js","../node_modules/d3-selection/src/namespaces.js","../node_modules/d3-selection/src/namespace.js","../node_modules/d3-selection/src/creator.js","../node_modules/d3-selection/src/selector.js","../node_modules/d3-selection/src/selection/select.js","../node_modules/d3-selection/src/selectorAll.js","../node_modules/d3-selection/src/selection/selectAll.js","../node_modules/d3-selection/src/matcher.js","../node_modules/d3-selection/src/selection/filter.js","../node_modules/d3-selection/src/selection/sparse.js","../node_modules/d3-selection/src/selection/enter.js","../node_modules/d3-selection/src/constant.js","../node_modules/d3-selection/src/selection/data.js","../node_modules/d3-selection/src/selection/exit.js","../node_modules/d3-selection/src/selection/join.js","../node_modules/d3-selection/src/selection/merge.js","../node_modules/d3-selection/src/selection/order.js","../node_modules/d3-selection/src/selection/sort.js","../node_modules/d3-selection/src/selection/call.js","../node_modules/d3-selection/src/selection/nodes.js","../node_modules/d3-selection/src/selection/node.js","../node_modules/d3-selection/src/selection/size.js","../node_modules/d3-selection/src/selection/empty.js","../node_modules/d3-selection/src/selection/each.js","../node_modules/d3-selection/src/selection/attr.js","../node_modules/d3-selection/src/window.js","../node_modules/d3-selection/src/selection/style.js","../node_modules/d3-selection/src/selection/property.js","../node_modules/d3-selection/src/selection/classed.js","../node_modules/d3-selection/src/selection/text.js","../node_modules/d3-selection/src/selection/html.js","../node_modules/d3-selection/src/selection/raise.js","../node_modules/d3-selection/src/selection/lower.js","../node_modules/d3-selection/src/selection/append.js","../node_modules/d3-selection/src/selection/insert.js","../node_modules/d3-selection/src/selection/remove.js","../node_modules/d3-selection/src/selection/clone.js","../node_modules/d3-selection/src/selection/datum.js","../node_modules/d3-selection/src/selection/on.js","../node_modules/d3-selection/src/selection/dispatch.js","../node_modules/d3-selection/src/selection/index.js","../node_modules/d3-selection/src/select.js","../node_modules/d3-selection/src/sourceEvent.js","../node_modules/d3-selection/src/point.js","../node_modules/d3-selection/src/mouse.js","../node_modules/d3-selection/src/selectAll.js","../node_modules/d3-selection/src/touch.js","../node_modules/d3-drag/src/noevent.js","../node_modules/d3-drag/src/nodrag.js","../node_modules/d3-drag/src/constant.js","../node_modules/d3-drag/src/event.js","../node_modules/d3-drag/src/drag.js","../node_modules/d3-color/src/define.js","../node_modules/d3-color/src/color.js","../node_modules/d3-interpolate/src/constant.js","../node_modules/d3-interpolate/src/color.js","../node_modules/d3-interpolate/src/rgb.js","../node_modules/d3-interpolate/src/numberArray.js","../node_modules/d3-interpolate/src/array.js","../node_modules/d3-interpolate/src/date.js","../node_modules/d3-interpolate/src/number.js","../node_modules/d3-interpolate/src/object.js","../node_modules/d3-interpolate/src/string.js","../node_modules/d3-interpolate/src/value.js","../node_modules/d3-interpolate/src/round.js","../node_modules/d3-interpolate/src/transform/decompose.js","../node_modules/d3-interpolate/src/transform/parse.js","../node_modules/d3-interpolate/src/transform/index.js","../node_modules/d3-interpolate/src/zoom.js","../node_modules/d3-interpolate/src/quantize.js","../node_modules/d3-timer/src/timer.js","../node_modules/d3-timer/src/timeout.js","../node_modules/d3-transition/src/transition/schedule.js","../node_modules/d3-transition/src/interrupt.js","../node_modules/d3-transition/src/selection/interrupt.js","../node_modules/d3-transition/src/transition/tween.js","../node_modules/d3-transition/src/transition/interpolate.js","../node_modules/d3-transition/src/transition/attr.js","../node_modules/d3-transition/src/transition/attrTween.js","../node_modules/d3-transition/src/transition/delay.js","../node_modules/d3-transition/src/transition/duration.js","../node_modules/d3-transition/src/transition/ease.js","../node_modules/d3-transition/src/transition/filter.js","../node_modules/d3-transition/src/transition/merge.js","../node_modules/d3-transition/src/transition/on.js","../node_modules/d3-transition/src/transition/remove.js","../node_modules/d3-transition/src/transition/select.js","../node_modules/d3-transition/src/transition/selectAll.js","../node_modules/d3-transition/src/transition/selection.js","../node_modules/d3-transition/src/transition/style.js","../node_modules/d3-transition/src/transition/styleTween.js","../node_modules/d3-transition/src/transition/text.js","../node_modules/d3-transition/src/transition/textTween.js","../node_modules/d3-transition/src/transition/transition.js","../node_modules/d3-transition/src/transition/end.js","../node_modules/d3-transition/src/transition/index.js","../node_modules/d3-ease/src/linear.js","../node_modules/d3-ease/src/cubic.js","../node_modules/d3-transition/src/selection/transition.js","../node_modules/d3-transition/src/selection/index.js","../node_modules/d3-zoom/src/constant.js","../node_modules/d3-zoom/src/event.js","../node_modules/d3-zoom/src/transform.js","../node_modules/d3-zoom/src/noevent.js","../node_modules/d3-zoom/src/zoom.js","../modules/geo/raw_mercator.js","../modules/geo/ortho.js","../modules/util/array.js","../node_modules/diacritics/index.js","../node_modules/alif-toolkit/lib/isArabic.js","../node_modules/alif-toolkit/lib/unicode-arabic.js","../node_modules/alif-toolkit/lib/unicode-ligatures.js","../node_modules/alif-toolkit/lib/reference.js","../node_modules/alif-toolkit/lib/GlyphSplitter.js","../node_modules/alif-toolkit/lib/BaselineSplitter.js","../node_modules/alif-toolkit/lib/Normalization.js","../node_modules/alif-toolkit/lib/CharShaper.js","../node_modules/alif-toolkit/lib/WordShaper.js","../node_modules/alif-toolkit/lib/ParentLetter.js","../node_modules/alif-toolkit/lib/index.js","../modules/util/svg_paths_rtl_fix.js","../modules/core/preferences.js","../node_modules/d3-fetch/src/text.js","../node_modules/d3-fetch/src/json.js","../node_modules/d3-fetch/src/xml.js","../modules/core/file_fetcher.js","../modules/util/detect.js","../node_modules/aes-js/index.js","../modules/util/aes.js","../modules/util/clean_tags.js","../modules/util/get_set_value.js","../modules/util/keybinding.js","../modules/util/object.js","../modules/util/rebind.js","../modules/util/session_mutex.js","../modules/util/tiler.js","../modules/util/trigger_event.js","../modules/core/localizer.js","../modules/presets/collection.js","../modules/presets/category.js","../modules/presets/field.js","../modules/presets/preset.js","../modules/presets/index.js","../modules/util/util.js","../modules/osm/entity.js","../modules/osm/lanes.js","../modules/osm/way.js","../modules/osm/multipolygon.js","../modules/actions/add_member.js","../modules/actions/add_midpoint.js","../modules/actions/add_vertex.js","../modules/actions/change_member.js","../modules/actions/change_preset.js","../modules/actions/change_tags.js","../modules/osm/node.js","../modules/actions/circularize.js","../modules/actions/delete_way.js","../modules/actions/delete_multiple.js","../modules/actions/delete_relation.js","../modules/actions/delete_node.js","../modules/actions/connect.js","../modules/actions/copy_entities.js","../modules/actions/delete_member.js","../modules/actions/discard_tags.js","../modules/actions/disconnect.js","../modules/actions/extract.js","../modules/actions/join.js","../modules/actions/merge.js","../modules/actions/merge_nodes.js","../modules/osm/changeset.js","../modules/osm/note.js","../modules/osm/relation.js","../modules/osm/qa_item.js","../modules/actions/split.js","../modules/core/graph.js","../modules/osm/intersection.js","../modules/actions/merge_polygon.js","../node_modules/fast-deep-equal/index.js","../node_modules/node-diff3/index.mjs","../modules/actions/merge_remote_changes.js","../modules/actions/move.js","../modules/actions/move_member.js","../modules/actions/move_node.js","../modules/actions/noop.js","../modules/actions/orthogonalize.js","../modules/actions/restrict_turn.js","../modules/actions/revert.js","../modules/actions/rotate.js","../modules/actions/straighten_nodes.js","../modules/actions/straighten_way.js","../modules/actions/unrestrict_turn.js","../modules/actions/reflect.js","../modules/actions/upgrade_tags.js","../modules/actions/rapid_accept_feature.js","../modules/behavior/edit.js","../modules/behavior/hover.js","../modules/behavior/draw.js","../node_modules/d3-scale/src/init.js","../node_modules/d3-collection/src/map.js","../node_modules/d3-collection/src/set.js","../node_modules/d3-scale/src/array.js","../node_modules/d3-scale/src/constant.js","../node_modules/d3-scale/src/number.js","../node_modules/d3-scale/src/continuous.js","../node_modules/d3-format/src/formatDecimal.js","../node_modules/d3-format/src/exponent.js","../node_modules/d3-format/src/formatGroup.js","../node_modules/d3-format/src/formatNumerals.js","../node_modules/d3-format/src/formatSpecifier.js","../node_modules/d3-format/src/formatTrim.js","../node_modules/d3-format/src/formatPrefixAuto.js","../node_modules/d3-format/src/formatRounded.js","../node_modules/d3-format/src/formatTypes.js","../node_modules/d3-format/src/identity.js","../node_modules/d3-format/src/locale.js","../node_modules/d3-format/src/defaultLocale.js","../node_modules/d3-format/src/precisionFixed.js","../node_modules/d3-format/src/precisionPrefix.js","../node_modules/d3-format/src/precisionRound.js","../node_modules/d3-scale/src/tickFormat.js","../node_modules/d3-scale/src/linear.js","../node_modules/d3-scale/src/quantize.js","../modules/behavior/breathe.js","../modules/behavior/operation.js","../modules/operations/circularize.js","../modules/ui/cmd.js","../modules/operations/delete.js","../modules/operations/orthogonalize.js","../modules/operations/reflect.js","../modules/operations/move.js","../modules/modes/rotate.js","../modules/operations/rotate.js","../modules/modes/move.js","../modules/behavior/paste.js","../modules/behavior/drag.js","../modules/modes/drag_node.js","../node_modules/lodash-es/isObject.js","../node_modules/lodash-es/_freeGlobal.js","../node_modules/lodash-es/_root.js","../node_modules/lodash-es/now.js","../node_modules/lodash-es/_Symbol.js","../node_modules/lodash-es/_getRawTag.js","../node_modules/lodash-es/_objectToString.js","../node_modules/lodash-es/_baseGetTag.js","../node_modules/lodash-es/isObjectLike.js","../node_modules/lodash-es/isSymbol.js","../node_modules/lodash-es/toNumber.js","../node_modules/lodash-es/debounce.js","../node_modules/xmldom/sax.js","../node_modules/xmldom/dom.js","../node_modules/xmldom/dom-parser.js","../node_modules/@mapbox/togeojson/togeojson.js","../modules/core/rapid_context.js","../modules/core/difference.js","../node_modules/rbush/node_modules/quickselect/index.js","../node_modules/rbush/index.js","../modules/core/tree.js","../modules/svg/icon.js","../modules/ui/modal.js","../modules/ui/loading.js","../modules/core/history.js","../modules/core/validation/models.js","../modules/validations/almost_junction.js","../modules/validations/close_nodes.js","../modules/validations/crossing_ways.js","../modules/behavior/draw_way.js","../modules/modes/draw_line.js","../modules/validations/disconnected_way.js","../modules/validations/invalid_format.js","../modules/validations/help_request.js","../modules/validations/impossible_oneway.js","../modules/validations/incompatible_source.js","../modules/validations/maprules.js","../modules/validations/mismatched_geometry.js","../modules/validations/missing_role.js","../modules/validations/missing_tag.js","../node_modules/name-suggestion-index/lib/simplify.js","../node_modules/name-suggestion-index/lib/to_parts.js","../node_modules/name-suggestion-index/lib/matcher.js","../node_modules/quickselect/quickselect.js","../node_modules/which-polygon/node_modules/rbush/index.js","../node_modules/lineclip/index.js","../node_modules/which-polygon/index.js","../node_modules/@ideditor/country-coder/built/es6/country-coder.js","../modules/validations/outdated_tags.js","../modules/validations/private_data.js","../modules/modes/draw_area.js","../modules/modes/add_area.js","../modules/modes/add_line.js","../modules/modes/add_point.js","../modules/ui/note_comments.js","../modules/ui/note_header.js","../modules/ui/note_report.js","../modules/ui/view_on_osm.js","../modules/ui/note_editor.js","../modules/modes/select_note.js","../modules/modes/add_note.js","../modules/util/jxon.js","../modules/ui/conflicts.js","../modules/ui/confirm.js","../modules/ui/popover.js","../modules/ui/tooltip.js","../modules/ui/combobox.js","../node_modules/marked/src/defaults.js","../node_modules/marked/src/helpers.js","../node_modules/marked/src/Tokenizer.js","../node_modules/marked/src/rules.js","../node_modules/marked/src/Lexer.js","../node_modules/marked/src/Renderer.js","../node_modules/marked/src/TextRenderer.js","../node_modules/marked/src/Slugger.js","../node_modules/marked/src/Parser.js","../node_modules/marked/src/marked.js","../modules/ui/intro/helper.js","../modules/ui/field_help.js","../modules/ui/fields/check.js","../modules/ui/fields/combo.js","../modules/ui/fields/input.js","../modules/ui/fields/access.js","../modules/ui/fields/address.js","../modules/ui/fields/cycleway.js","../modules/util/dimensions.js","../modules/ui/fields/lanes.js","../modules/svg/helpers.js","../modules/svg/tag_classes.js","../modules/svg/tag_pattern.js","../modules/svg/areas.js","../node_modules/lodash-es/throttle.js","../node_modules/fast-json-stable-stringify/index.js","../modules/svg/data.js","../modules/svg/debug.js","../modules/svg/defs.js","../modules/svg/keepRight.js","../modules/svg/geolocate.js","../modules/svg/labels.js","../modules/svg/improveOSM.js","../modules/svg/osmose.js","../modules/svg/streetside.js","../modules/svg/mapillary_images.js","../modules/svg/mapillary_signs.js","../modules/svg/mapillary_map_features.js","../modules/svg/openstreetcam_images.js","../modules/svg/osm.js","../modules/svg/notes.js","../modules/svg/touch.js","../modules/svg/rapid_features.js","../modules/svg/layers.js","../node_modules/lodash-es/_listCacheClear.js","../node_modules/lodash-es/eq.js","../node_modules/lodash-es/_assocIndexOf.js","../node_modules/lodash-es/_listCacheDelete.js","../node_modules/lodash-es/_listCacheGet.js","../node_modules/lodash-es/_listCacheHas.js","../node_modules/lodash-es/_listCacheSet.js","../node_modules/lodash-es/_ListCache.js","../node_modules/lodash-es/_stackClear.js","../node_modules/lodash-es/_stackDelete.js","../node_modules/lodash-es/_stackGet.js","../node_modules/lodash-es/_stackHas.js","../node_modules/lodash-es/isFunction.js","../node_modules/lodash-es/_coreJsData.js","../node_modules/lodash-es/_isMasked.js","../node_modules/lodash-es/_toSource.js","../node_modules/lodash-es/_baseIsNative.js","../node_modules/lodash-es/_getValue.js","../node_modules/lodash-es/_getNative.js","../node_modules/lodash-es/_Map.js","../node_modules/lodash-es/_nativeCreate.js","../node_modules/lodash-es/_hashClear.js","../node_modules/lodash-es/_hashDelete.js","../node_modules/lodash-es/_hashGet.js","../node_modules/lodash-es/_hashHas.js","../node_modules/lodash-es/_hashSet.js","../node_modules/lodash-es/_Hash.js","../node_modules/lodash-es/_mapCacheClear.js","../node_modules/lodash-es/_isKeyable.js","../node_modules/lodash-es/_getMapData.js","../node_modules/lodash-es/_mapCacheDelete.js","../node_modules/lodash-es/_mapCacheGet.js","../node_modules/lodash-es/_mapCacheHas.js","../node_modules/lodash-es/_mapCacheSet.js","../node_modules/lodash-es/_MapCache.js","../node_modules/lodash-es/_stackSet.js","../node_modules/lodash-es/_Stack.js","../node_modules/lodash-es/_setCacheAdd.js","../node_modules/lodash-es/_setCacheHas.js","../node_modules/lodash-es/_SetCache.js","../node_modules/lodash-es/_arraySome.js","../node_modules/lodash-es/_cacheHas.js","../node_modules/lodash-es/_equalArrays.js","../node_modules/lodash-es/_Uint8Array.js","../node_modules/lodash-es/_mapToArray.js","../node_modules/lodash-es/_setToArray.js","../node_modules/lodash-es/_equalByTag.js","../node_modules/lodash-es/_arrayPush.js","../node_modules/lodash-es/isArray.js","../node_modules/lodash-es/_baseGetAllKeys.js","../node_modules/lodash-es/_arrayFilter.js","../node_modules/lodash-es/stubArray.js","../node_modules/lodash-es/_getSymbols.js","../node_modules/lodash-es/_baseTimes.js","../node_modules/lodash-es/_baseIsArguments.js","../node_modules/lodash-es/isArguments.js","../node_modules/lodash-es/stubFalse.js","../node_modules/lodash-es/isBuffer.js","../node_modules/lodash-es/_isIndex.js","../node_modules/lodash-es/isLength.js","../node_modules/lodash-es/_baseIsTypedArray.js","../node_modules/lodash-es/_baseUnary.js","../node_modules/lodash-es/_nodeUtil.js","../node_modules/lodash-es/isTypedArray.js","../node_modules/lodash-es/_arrayLikeKeys.js","../node_modules/lodash-es/_isPrototype.js","../node_modules/lodash-es/_overArg.js","../node_modules/lodash-es/_nativeKeys.js","../node_modules/lodash-es/_baseKeys.js","../node_modules/lodash-es/isArrayLike.js","../node_modules/lodash-es/keys.js","../node_modules/lodash-es/_getAllKeys.js","../node_modules/lodash-es/_equalObjects.js","../node_modules/lodash-es/_DataView.js","../node_modules/lodash-es/_Promise.js","../node_modules/lodash-es/_Set.js","../node_modules/lodash-es/_WeakMap.js","../node_modules/lodash-es/_getTag.js","../node_modules/lodash-es/_baseIsEqualDeep.js","../node_modules/lodash-es/_baseIsEqual.js","../node_modules/lodash-es/isEqual.js","../node_modules/lodash-es/_arrayMap.js","../node_modules/lodash-es/_arrayEach.js","../node_modules/lodash-es/_defineProperty.js","../node_modules/lodash-es/_baseAssignValue.js","../node_modules/lodash-es/_assignValue.js","../node_modules/lodash-es/_copyObject.js","../node_modules/lodash-es/_baseAssign.js","../node_modules/lodash-es/_nativeKeysIn.js","../node_modules/lodash-es/_baseKeysIn.js","../node_modules/lodash-es/keysIn.js","../node_modules/lodash-es/_baseAssignIn.js","../node_modules/lodash-es/_cloneBuffer.js","../node_modules/lodash-es/_copyArray.js","../node_modules/lodash-es/_copySymbols.js","../node_modules/lodash-es/_getPrototype.js","../node_modules/lodash-es/_getSymbolsIn.js","../node_modules/lodash-es/_copySymbolsIn.js","../node_modules/lodash-es/_getAllKeysIn.js","../node_modules/lodash-es/_initCloneArray.js","../node_modules/lodash-es/_cloneArrayBuffer.js","../node_modules/lodash-es/_cloneDataView.js","../node_modules/lodash-es/_cloneRegExp.js","../node_modules/lodash-es/_cloneSymbol.js","../node_modules/lodash-es/_cloneTypedArray.js","../node_modules/lodash-es/_initCloneByTag.js","../node_modules/lodash-es/_baseCreate.js","../node_modules/lodash-es/_initCloneObject.js","../node_modules/lodash-es/_baseIsMap.js","../node_modules/lodash-es/isMap.js","../node_modules/lodash-es/_baseIsSet.js","../node_modules/lodash-es/isSet.js","../node_modules/lodash-es/_baseClone.js","../node_modules/lodash-es/_isKey.js","../node_modules/lodash-es/memoize.js","../node_modules/lodash-es/_memoizeCapped.js","../node_modules/lodash-es/_stringToPath.js","../node_modules/lodash-es/_baseToString.js","../node_modules/lodash-es/toString.js","../node_modules/lodash-es/_castPath.js","../node_modules/lodash-es/last.js","../node_modules/lodash-es/_toKey.js","../node_modules/lodash-es/_baseGet.js","../node_modules/lodash-es/_baseSlice.js","../node_modules/lodash-es/_parent.js","../node_modules/lodash-es/_baseUnset.js","../node_modules/lodash-es/isPlainObject.js","../node_modules/lodash-es/_customOmitClone.js","../node_modules/lodash-es/_isFlattenable.js","../node_modules/lodash-es/_baseFlatten.js","../node_modules/lodash-es/flatten.js","../node_modules/lodash-es/_apply.js","../node_modules/lodash-es/_overRest.js","../node_modules/lodash-es/constant.js","../node_modules/lodash-es/identity.js","../node_modules/lodash-es/_baseSetToString.js","../node_modules/lodash-es/_shortOut.js","../node_modules/lodash-es/_setToString.js","../node_modules/lodash-es/_flatRest.js","../node_modules/lodash-es/omit.js","../modules/svg/lines.js","../modules/svg/midpoints.js","../modules/svg/points.js","../modules/svg/turns.js","../modules/svg/vertices.js","../modules/ui/fields/localized.js","../modules/ui/fields/maxspeed.js","../modules/ui/fields/radio.js","../modules/ui/fields/restrictions.js","../modules/ui/fields/textarea.js","../modules/ui/fields/wikidata.js","../modules/ui/fields/wikipedia.js","../modules/ui/fields/index.js","../modules/ui/tag_reference.js","../modules/ui/field.js","../modules/ui/form_fields.js","../modules/ui/changeset_editor.js","../modules/ui/toggle.js","../modules/ui/disclosure.js","../modules/ui/section.js","../modules/ui/sections/changes.js","../modules/ui/commit_warnings.js","../modules/ui/sections/raw_tag_editor.js","../modules/ui/commit.js","../node_modules/wgs84/index.js","../node_modules/@mapbox/geojson-area/index.js","../node_modules/circle-to-polygon/index.js","../node_modules/geojson-precision/index.js","../node_modules/turf-jsts/jsts.mjs","../node_modules/@turf/meta/node_modules/@turf/helpers/main.es.js","../node_modules/@turf/meta/main.es.js","../node_modules/@turf/area/main.es.js","../node_modules/@turf/difference/node_modules/@turf/helpers/main.es.js","../node_modules/@turf/difference/node_modules/@turf/invariant/main.es.js","../node_modules/@turf/difference/main.es.js","../node_modules/@turf/union/main.es.js","../node_modules/@ideditor/location-conflation/index.mjs","../modules/ui/success.js","../modules/modes/save.js","../modules/ui/improveOSM_comments.js","../modules/ui/improveOSM_details.js","../modules/ui/improveOSM_header.js","../modules/ui/improveOSM_editor.js","../modules/ui/keepRight_details.js","../modules/ui/keepRight_header.js","../modules/ui/view_on_keepRight.js","../modules/ui/keepRight_editor.js","../modules/ui/osmose_details.js","../modules/ui/osmose_header.js","../modules/ui/view_on_osmose.js","../modules/ui/osmose_editor.js","../modules/modes/select_error.js","../modules/ui/account.js","../modules/ui/attribution.js","../modules/ui/contributors.js","../modules/ui/edit_menu.js","../modules/ui/feature_info.js","../modules/ui/flash.js","../modules/ui/full_screen.js","../modules/ui/geolocate.js","../modules/ui/panels/background.js","../modules/ui/panels/history.js","../modules/util/units.js","../modules/ui/panels/location.js","../modules/ui/panels/measurement.js","../modules/ui/panels/index.js","../modules/ui/info.js","../modules/ui/curtain.js","../modules/ui/intro/welcome.js","../modules/ui/intro/navigation.js","../modules/ui/intro/point.js","../modules/ui/intro/area.js","../modules/ui/intro/line.js","../modules/ui/intro/building.js","../modules/ui/intro/start_editing.js","../modules/ui/intro/rapid.js","../modules/ui/intro/intro.js","../modules/ui/issues_info.js","../modules/renderer/background_source.js","../modules/renderer/tile_layer.js","../modules/renderer/background.js","../modules/renderer/features.js","../modules/util/bind_once.js","../modules/util/zoom_pan.js","../modules/util/double_up.js","../modules/renderer/map.js","../modules/renderer/photos.js","../modules/ui/map_in_map.js","../modules/ui/notice.js","../modules/ui/photoviewer.js","../modules/ui/restore.js","../modules/ui/scale.js","../modules/ui/shortcuts.js","../modules/ui/data_header.js","../modules/ui/data_editor.js","../node_modules/@mapbox/sexagesimal/index.js","../modules/ui/feature_list.js","../modules/ui/sections/entity_issues.js","../modules/ui/preset_icon.js","../modules/ui/sections/feature_type.js","../modules/ui/sections/preset_fields.js","../modules/ui/sections/raw_member_editor.js","../modules/ui/sections/raw_membership_editor.js","../modules/ui/sections/selection_list.js","../modules/ui/entity_editor.js","../modules/ui/preset_list.js","../modules/ui/inspector.js","../modules/ui/rapid_splash.js","../modules/ui/rapid_first_edit_dialog.js","../modules/ui/rapid_feature_inspector.js","../modules/ui/sidebar.js","../modules/ui/source_switch.js","../modules/ui/spinner.js","../modules/ui/status.js","../modules/ui/tools/download_osc.js","../modules/ui/tools/modes.js","../modules/ui/tools/notes.js","../modules/ui/tools/save.js","../modules/ui/tools/sidebar_toggle.js","../modules/ui/tools/undo_redo.js","../modules/ui/rapid_colorpicker.js","../modules/ui/rapid_view_manage_datasets.js","../modules/ui/rapid_feature_toggle_dialog.js","../modules/ui/rapid_poweruser_features_dialog.js","../modules/ui/tools/rapid_features.js","../modules/ui/top_toolbar.js","../modules/ui/version.js","../modules/ui/zoom.js","../modules/ui/zoom_to_selection.js","../modules/ui/pane.js","../modules/ui/sections/background_display_options.js","../modules/ui/settings/custom_background.js","../modules/ui/sections/background_list.js","../modules/ui/sections/background_offset.js","../modules/ui/sections/overlay_list.js","../modules/ui/sections/grid_display_options.js","../modules/ui/panes/background.js","../modules/ui/panes/help.js","../modules/ui/sections/validation_issues.js","../modules/ui/sections/validation_options.js","../modules/ui/sections/validation_rules.js","../modules/ui/sections/validation_status.js","../modules/ui/panes/issues.js","../modules/ui/settings/custom_data.js","../modules/ui/sections/data_layers.js","../modules/ui/sections/map_features.js","../modules/ui/sections/map_style_options.js","../modules/ui/sections/photo_overlays.js","../modules/ui/panes/map_data.js","../modules/ui/sections/privacy.js","../modules/ui/panes/preferences.js","../modules/ui/rapid_service_license.js","../modules/ui/init.js","../modules/ui/lasso.js","../modules/ui/splash.js","../modules/ui/rapid_whatsnew.js","../modules/modes/rapid_select_features.js","../modules/operations/continue.js","../modules/operations/cycle_highway_tag.js","../modules/operations/copy.js","../modules/operations/disconnect.js","../modules/operations/downgrade.js","../modules/operations/extract.js","../modules/operations/merge.js","../modules/operations/paste.js","../modules/operations/reverse.js","../modules/operations/split.js","../modules/operations/straighten.js","../modules/validations/short_road.js","../modules/validations/y_shaped_connection.js","../modules/validations/suspicious_name.js","../modules/validations/unsquare_way.js","../modules/core/validator.js","../modules/core/uploader.js","../modules/core/context.js","../modules/services/esri_data.js","../node_modules/lodash-es/_createBaseFor.js","../node_modules/lodash-es/_baseFor.js","../node_modules/lodash-es/_baseForOwn.js","../node_modules/lodash-es/_createBaseEach.js","../node_modules/lodash-es/_baseEach.js","../node_modules/lodash-es/_castFunction.js","../node_modules/lodash-es/forEach.js","../modules/services/fb_ai_features.js","../modules/services/keepRight.js","../modules/services/improveOSM.js","../modules/services/osmose.js","../modules/services/mapillary.js","../modules/services/maprules.js","../modules/services/nominatim.js","../modules/services/openstreetcam.js","../node_modules/jshashes/hashes.js","../node_modules/xtend/immutable.js","../node_modules/ohauth/index.js","../node_modules/resolve-url/resolve-url.js","../node_modules/store/src/util.js","../node_modules/store/src/store-engine.js","../node_modules/store/storages/localStorage.js","../node_modules/store/storages/oldFF-globalStorage.js","../node_modules/store/storages/oldIE-userDataStorage.js","../node_modules/store/storages/cookieStorage.js","../node_modules/store/storages/sessionStorage.js","../node_modules/store/storages/memoryStorage.js","../node_modules/store/storages/all.js","../node_modules/store/plugins/lib/json2.js","../node_modules/store/plugins/json2.js","../node_modules/store/dist/store.legacy.js","../node_modules/osm-auth/index.js","../modules/services/osm.js","../modules/services/osm_wikibase.js","../modules/util/jsonp_request.js","../modules/services/streetside.js","../modules/services/taginfo.js","../node_modules/@turf/helpers/index.js","../node_modules/@turf/invariant/index.js","../node_modules/@turf/bbox-clip/lib/lineclip.js","../node_modules/@turf/bbox-clip/index.js","../node_modules/splaytree/index.js","../node_modules/martinez-polygon-clipping/src/edge_type.js","../node_modules/martinez-polygon-clipping/src/operation.js","../node_modules/martinez-polygon-clipping/src/compute_fields.js","../node_modules/martinez-polygon-clipping/src/sweep_event.js","../node_modules/martinez-polygon-clipping/src/equals.js","../node_modules/robust-predicates/esm/util.js","../node_modules/robust-predicates/esm/orient2d.js","../node_modules/martinez-polygon-clipping/src/signed_area.js","../node_modules/martinez-polygon-clipping/src/compare_events.js","../node_modules/martinez-polygon-clipping/src/divide_segment.js","../node_modules/martinez-polygon-clipping/src/segment_intersection.js","../node_modules/martinez-polygon-clipping/src/possible_intersection.js","../node_modules/martinez-polygon-clipping/src/compare_segments.js","../node_modules/martinez-polygon-clipping/src/subdivide_segments.js","../node_modules/martinez-polygon-clipping/src/contour.js","../node_modules/martinez-polygon-clipping/src/connect_edges.js","../node_modules/tinyqueue/index.js","../node_modules/martinez-polygon-clipping/src/fill_queue.js","../node_modules/martinez-polygon-clipping/src/index.js","../node_modules/martinez-polygon-clipping/index.js","../node_modules/ieee754/index.js","../node_modules/pbf/index.js","../node_modules/@mapbox/point-geometry/index.js","../node_modules/@mapbox/vector-tile/lib/vectortilefeature.js","../node_modules/@mapbox/vector-tile/lib/vectortilelayer.js","../node_modules/@mapbox/vector-tile/lib/vectortile.js","../node_modules/@mapbox/vector-tile/index.js","../modules/services/vector_tile.js","../modules/services/wikidata.js","../modules/services/wikipedia.js","../modules/services/index.js","../modules/modes/drag_note.js","../modules/modes/select_data.js","../modules/behavior/select.js","../modules/modes/select.js","../modules/behavior/lasso.js","../modules/modes/browse.js","../modules/behavior/add_way.js","../modules/behavior/hash.js","../modules/index.js","../modules/id.js"],"sourcesContent":["'use strict';\n\nmodule.exports = function () {\n\tvar set, iterator, result;\n\tif (typeof Set !== 'function') return false;\n\tset = new Set(['raz', 'dwa', 'trzy']);\n\tif (String(set) !== '[object Set]') return false;\n\tif (set.size !== 3) return false;\n\tif (typeof set.add !== 'function') return false;\n\tif (typeof set.clear !== 'function') return false;\n\tif (typeof set.delete !== 'function') return false;\n\tif (typeof set.entries !== 'function') return false;\n\tif (typeof set.forEach !== 'function') return false;\n\tif (typeof set.has !== 'function') return false;\n\tif (typeof set.keys !== 'function') return false;\n\tif (typeof set.values !== 'function') return false;\n\n\titerator = set.values();\n\tresult = iterator.next();\n\tif (result.done !== false) return false;\n\tif (result.value !== 'raz') return false;\n\n\treturn true;\n};\n","\"use strict\";\n\n// eslint-disable-next-line no-empty-function\nmodule.exports = function () {};\n","\"use strict\";\n\nvar _undefined = require(\"../function/noop\")(); // Support ES3 engines\n\nmodule.exports = function (val) { return val !== _undefined && val !== null; };\n","\"use strict\";\n\nvar isValue = require(\"./is-value\");\n\nmodule.exports = function (value) {\n\tif (!isValue(value)) throw new TypeError(\"Cannot use null or undefined\");\n\treturn value;\n};\n","// Inspired by Google Closure:\n// http://closure-library.googlecode.com/svn/docs/\n// closure_goog_array_array.js.html#goog.array.clear\n\n\"use strict\";\n\nvar value = require(\"../../object/valid-value\");\n\nmodule.exports = function () {\n\tvalue(this).length = 0;\n\treturn this;\n};\n","\"use strict\";\n\nmodule.exports = function () {\n\tvar numberIsNaN = Number.isNaN;\n\tif (typeof numberIsNaN !== \"function\") return false;\n\treturn !numberIsNaN({}) && numberIsNaN(NaN) && !numberIsNaN(34);\n};\n","\"use strict\";\n\nmodule.exports = function (value) {\n\t// eslint-disable-next-line no-self-compare\n\treturn value !== value;\n};\n","\"use strict\";\n\nmodule.exports = require(\"./is-implemented\")() ? Number.isNaN : require(\"./shim\");\n","\"use strict\";\n\nmodule.exports = function () {\n\tvar sign = Math.sign;\n\tif (typeof sign !== \"function\") return false;\n\treturn sign(10) === 1 && sign(-20) === -1;\n};\n","\"use strict\";\n\nmodule.exports = function (value) {\n\tvalue = Number(value);\n\tif (isNaN(value) || value === 0) return value;\n\treturn value > 0 ? 1 : -1;\n};\n","\"use strict\";\n\nmodule.exports = require(\"./is-implemented\")() ? Math.sign : require(\"./shim\");\n","\"use strict\";\n\nvar sign = require(\"../math/sign\")\n , abs = Math.abs\n , floor = Math.floor;\n\nmodule.exports = function (value) {\n\tif (isNaN(value)) return 0;\n\tvalue = Number(value);\n\tif (value === 0 || !isFinite(value)) return value;\n\treturn sign(value) * floor(abs(value));\n};\n","\"use strict\";\n\nvar toInteger = require(\"./to-integer\")\n , max = Math.max;\n\nmodule.exports = function (value) { return max(0, toInteger(value)); };\n","\"use strict\";\n\nvar numberIsNaN = require(\"../../number/is-nan\")\n , toPosInt = require(\"../../number/to-pos-integer\")\n , value = require(\"../../object/valid-value\")\n , indexOf = Array.prototype.indexOf\n , objHasOwnProperty = Object.prototype.hasOwnProperty\n , abs = Math.abs\n , floor = Math.floor;\n\nmodule.exports = function (searchElement/*, fromIndex*/) {\n\tvar i, length, fromIndex, val;\n\tif (!numberIsNaN(searchElement)) return indexOf.apply(this, arguments);\n\n\tlength = toPosInt(value(this).length);\n\tfromIndex = arguments[1];\n\tif (isNaN(fromIndex)) fromIndex = 0;\n\telse if (fromIndex >= 0) fromIndex = floor(fromIndex);\n\telse fromIndex = toPosInt(this.length) - floor(abs(fromIndex));\n\n\tfor (i = fromIndex; i < length; ++i) {\n\t\tif (objHasOwnProperty.call(this, i)) {\n\t\t\tval = this[i];\n\t\t\tif (numberIsNaN(val)) return i; // Jslint: ignore\n\t\t}\n\t}\n\treturn -1;\n};\n","\"use strict\";\n\nvar create = Object.create, getPrototypeOf = Object.getPrototypeOf, plainObject = {};\n\nmodule.exports = function (/* CustomCreate*/) {\n\tvar setPrototypeOf = Object.setPrototypeOf, customCreate = arguments[0] || create;\n\tif (typeof setPrototypeOf !== \"function\") return false;\n\treturn getPrototypeOf(setPrototypeOf(customCreate(null), plainObject)) === plainObject;\n};\n","\"use strict\";\n\nvar isValue = require(\"./is-value\");\n\nvar map = { function: true, object: true };\n\nmodule.exports = function (value) { return (isValue(value) && map[typeof value]) || false; };\n","// Workaround for http://code.google.com/p/v8/issues/detail?id=2804\n\n\"use strict\";\n\nvar create = Object.create, shim;\n\nif (!require(\"./set-prototype-of/is-implemented\")()) {\n\tshim = require(\"./set-prototype-of/shim\");\n}\n\nmodule.exports = (function () {\n\tvar nullObject, polyProps, desc;\n\tif (!shim) return create;\n\tif (shim.level !== 1) return create;\n\n\tnullObject = {};\n\tpolyProps = {};\n\tdesc = { configurable: false, enumerable: false, writable: true, value: undefined };\n\tObject.getOwnPropertyNames(Object.prototype).forEach(function (name) {\n\t\tif (name === \"__proto__\") {\n\t\t\tpolyProps[name] = {\n\t\t\t\tconfigurable: true,\n\t\t\t\tenumerable: false,\n\t\t\t\twritable: true,\n\t\t\t\tvalue: undefined\n\t\t\t};\n\t\t\treturn;\n\t\t}\n\t\tpolyProps[name] = desc;\n\t});\n\tObject.defineProperties(nullObject, polyProps);\n\n\tObject.defineProperty(shim, \"nullPolyfill\", {\n\t\tconfigurable: false,\n\t\tenumerable: false,\n\t\twritable: false,\n\t\tvalue: nullObject\n\t});\n\n\treturn function (prototype, props) {\n\t\treturn create(prototype === null ? nullObject : prototype, props);\n\t};\n})();\n","/* eslint no-proto: \"off\" */\n\n// Big thanks to @WebReflection for sorting this out\n// https://gist.github.com/WebReflection/5593554\n\n\"use strict\";\n\nvar isObject = require(\"../is-object\")\n , value = require(\"../valid-value\")\n , objIsPrototypeOf = Object.prototype.isPrototypeOf\n , defineProperty = Object.defineProperty\n , nullDesc = { configurable: true, enumerable: false, writable: true, value: undefined }\n , validate;\n\nvalidate = function (obj, prototype) {\n\tvalue(obj);\n\tif (prototype === null || isObject(prototype)) return obj;\n\tthrow new TypeError(\"Prototype must be null or an object\");\n};\n\nmodule.exports = (function (status) {\n\tvar fn, set;\n\tif (!status) return null;\n\tif (status.level === 2) {\n\t\tif (status.set) {\n\t\t\tset = status.set;\n\t\t\tfn = function (obj, prototype) {\n\t\t\t\tset.call(validate(obj, prototype), prototype);\n\t\t\t\treturn obj;\n\t\t\t};\n\t\t} else {\n\t\t\tfn = function (obj, prototype) {\n\t\t\t\tvalidate(obj, prototype).__proto__ = prototype;\n\t\t\t\treturn obj;\n\t\t\t};\n\t\t}\n\t} else {\n\t\tfn = function self(obj, prototype) {\n\t\t\tvar isNullBase;\n\t\t\tvalidate(obj, prototype);\n\t\t\tisNullBase = objIsPrototypeOf.call(self.nullPolyfill, obj);\n\t\t\tif (isNullBase) delete self.nullPolyfill.__proto__;\n\t\t\tif (prototype === null) prototype = self.nullPolyfill;\n\t\t\tobj.__proto__ = prototype;\n\t\t\tif (isNullBase) defineProperty(self.nullPolyfill, \"__proto__\", nullDesc);\n\t\t\treturn obj;\n\t\t};\n\t}\n\treturn Object.defineProperty(fn, \"level\", {\n\t\tconfigurable: false,\n\t\tenumerable: false,\n\t\twritable: false,\n\t\tvalue: status.level\n\t});\n})(\n\t(function () {\n\t\tvar tmpObj1 = Object.create(null)\n\t\t , tmpObj2 = {}\n\t\t , set\n\t\t , desc = Object.getOwnPropertyDescriptor(Object.prototype, \"__proto__\");\n\n\t\tif (desc) {\n\t\t\ttry {\n\t\t\t\tset = desc.set; // Opera crashes at this point\n\t\t\t\tset.call(tmpObj1, tmpObj2);\n\t\t\t} catch (ignore) {}\n\t\t\tif (Object.getPrototypeOf(tmpObj1) === tmpObj2) return { set: set, level: 2 };\n\t\t}\n\n\t\ttmpObj1.__proto__ = tmpObj2;\n\t\tif (Object.getPrototypeOf(tmpObj1) === tmpObj2) return { level: 2 };\n\n\t\ttmpObj1 = {};\n\t\ttmpObj1.__proto__ = tmpObj2;\n\t\tif (Object.getPrototypeOf(tmpObj1) === tmpObj2) return { level: 1 };\n\n\t\treturn false;\n\t})()\n);\n\nrequire(\"../create\");\n","\"use strict\";\n\nmodule.exports = require(\"./is-implemented\")() ? Object.setPrototypeOf : require(\"./shim\");\n","\"use strict\";\n\nmodule.exports = function (fn) {\n\tif (typeof fn !== \"function\") throw new TypeError(fn + \" is not a function\");\n\treturn fn;\n};\n","\"use strict\";\n\n// ES3 safe\nvar _undefined = void 0;\n\nmodule.exports = function (value) { return value !== _undefined && value !== null; };\n","\"use strict\";\n\nvar isValue = require(\"../value/is\");\n\n// prettier-ignore\nvar possibleTypes = { \"object\": true, \"function\": true, \"undefined\": true /* document.all */ };\n\nmodule.exports = function (value) {\n\tif (!isValue(value)) return false;\n\treturn hasOwnProperty.call(possibleTypes, typeof value);\n};\n","\"use strict\";\n\nvar isObject = require(\"../object/is\");\n\nmodule.exports = function (value) {\n\tif (!isObject(value)) return false;\n\ttry {\n\t\tif (!value.constructor) return false;\n\t\treturn value.constructor.prototype === value;\n\t} catch (error) {\n\t\treturn false;\n\t}\n};\n","\"use strict\";\n\nvar isPrototype = require(\"../prototype/is\");\n\nmodule.exports = function (value) {\n\tif (typeof value !== \"function\") return false;\n\n\tif (!hasOwnProperty.call(value, \"length\")) return false;\n\n\ttry {\n\t\tif (typeof value.length !== \"number\") return false;\n\t\tif (typeof value.call !== \"function\") return false;\n\t\tif (typeof value.apply !== \"function\") return false;\n\t} catch (error) {\n\t\treturn false;\n\t}\n\n\treturn !isPrototype(value);\n};\n","\"use strict\";\n\nvar isFunction = require(\"../function/is\");\n\nvar classRe = /^\\s*class[\\s{/}]/, functionToString = Function.prototype.toString;\n\nmodule.exports = function (value) {\n\tif (!isFunction(value)) return false;\n\tif (classRe.test(functionToString.call(value))) return false;\n\treturn true;\n};\n","\"use strict\";\n\nmodule.exports = function () {\n\tvar assign = Object.assign, obj;\n\tif (typeof assign !== \"function\") return false;\n\tobj = { foo: \"raz\" };\n\tassign(obj, { bar: \"dwa\" }, { trzy: \"trzy\" });\n\treturn obj.foo + obj.bar + obj.trzy === \"razdwatrzy\";\n};\n","\"use strict\";\n\nmodule.exports = function () {\n\ttry {\n\t\tObject.keys(\"primitive\");\n\t\treturn true;\n\t} catch (e) {\n\t\treturn false;\n\t}\n};\n","\"use strict\";\n\nvar isValue = require(\"../is-value\");\n\nvar keys = Object.keys;\n\nmodule.exports = function (object) { return keys(isValue(object) ? Object(object) : object); };\n","\"use strict\";\n\nmodule.exports = require(\"./is-implemented\")() ? Object.keys : require(\"./shim\");\n","\"use strict\";\n\nvar keys = require(\"../keys\")\n , value = require(\"../valid-value\")\n , max = Math.max;\n\nmodule.exports = function (dest, src/*, …srcn*/) {\n\tvar error, i, length = max(arguments.length, 2), assign;\n\tdest = Object(value(dest));\n\tassign = function (key) {\n\t\ttry {\n\t\t\tdest[key] = src[key];\n\t\t} catch (e) {\n\t\t\tif (!error) error = e;\n\t\t}\n\t};\n\tfor (i = 1; i < length; ++i) {\n\t\tsrc = arguments[i];\n\t\tkeys(src).forEach(assign);\n\t}\n\tif (error !== undefined) throw error;\n\treturn dest;\n};\n","\"use strict\";\n\nmodule.exports = require(\"./is-implemented\")() ? Object.assign : require(\"./shim\");\n","\"use strict\";\n\nvar isValue = require(\"./is-value\");\n\nvar forEach = Array.prototype.forEach, create = Object.create;\n\nvar process = function (src, obj) {\n\tvar key;\n\tfor (key in src) obj[key] = src[key];\n};\n\n// eslint-disable-next-line no-unused-vars\nmodule.exports = function (opts1/*, …options*/) {\n\tvar result = create(null);\n\tforEach.call(arguments, function (options) {\n\t\tif (!isValue(options)) return;\n\t\tprocess(Object(options), result);\n\t});\n\treturn result;\n};\n","\"use strict\";\n\nvar str = \"razdwatrzy\";\n\nmodule.exports = function () {\n\tif (typeof str.contains !== \"function\") return false;\n\treturn str.contains(\"dwa\") === true && str.contains(\"foo\") === false;\n};\n","\"use strict\";\n\nvar indexOf = String.prototype.indexOf;\n\nmodule.exports = function (searchString/*, position*/) {\n\treturn indexOf.call(this, searchString, arguments[1]) > -1;\n};\n","\"use strict\";\n\nmodule.exports = require(\"./is-implemented\")() ? String.prototype.contains : require(\"./shim\");\n","\"use strict\";\n\nvar isValue = require(\"type/value/is\")\n , isPlainFunction = require(\"type/plain-function/is\")\n , assign = require(\"es5-ext/object/assign\")\n , normalizeOpts = require(\"es5-ext/object/normalize-options\")\n , contains = require(\"es5-ext/string/#/contains\");\n\nvar d = (module.exports = function (dscr, value/*, options*/) {\n\tvar c, e, w, options, desc;\n\tif (arguments.length < 2 || typeof dscr !== \"string\") {\n\t\toptions = value;\n\t\tvalue = dscr;\n\t\tdscr = null;\n\t} else {\n\t\toptions = arguments[2];\n\t}\n\tif (isValue(dscr)) {\n\t\tc = contains.call(dscr, \"c\");\n\t\te = contains.call(dscr, \"e\");\n\t\tw = contains.call(dscr, \"w\");\n\t} else {\n\t\tc = w = true;\n\t\te = false;\n\t}\n\n\tdesc = { value: value, configurable: c, enumerable: e, writable: w };\n\treturn !options ? desc : assign(normalizeOpts(options), desc);\n});\n\nd.gs = function (dscr, get, set/*, options*/) {\n\tvar c, e, options, desc;\n\tif (typeof dscr !== \"string\") {\n\t\toptions = set;\n\t\tset = get;\n\t\tget = dscr;\n\t\tdscr = null;\n\t} else {\n\t\toptions = arguments[3];\n\t}\n\tif (!isValue(get)) {\n\t\tget = undefined;\n\t} else if (!isPlainFunction(get)) {\n\t\toptions = get;\n\t\tget = set = undefined;\n\t} else if (!isValue(set)) {\n\t\tset = undefined;\n\t} else if (!isPlainFunction(set)) {\n\t\toptions = set;\n\t\tset = undefined;\n\t}\n\tif (isValue(dscr)) {\n\t\tc = contains.call(dscr, \"c\");\n\t\te = contains.call(dscr, \"e\");\n\t} else {\n\t\tc = true;\n\t\te = false;\n\t}\n\n\tdesc = { get: get, set: set, configurable: c, enumerable: e };\n\treturn !options ? desc : assign(normalizeOpts(options), desc);\n};\n","'use strict';\n\nvar d = require('d')\n , callable = require('es5-ext/object/valid-callable')\n\n , apply = Function.prototype.apply, call = Function.prototype.call\n , create = Object.create, defineProperty = Object.defineProperty\n , defineProperties = Object.defineProperties\n , hasOwnProperty = Object.prototype.hasOwnProperty\n , descriptor = { configurable: true, enumerable: false, writable: true }\n\n , on, once, off, emit, methods, descriptors, base;\n\non = function (type, listener) {\n\tvar data;\n\n\tcallable(listener);\n\n\tif (!hasOwnProperty.call(this, '__ee__')) {\n\t\tdata = descriptor.value = create(null);\n\t\tdefineProperty(this, '__ee__', descriptor);\n\t\tdescriptor.value = null;\n\t} else {\n\t\tdata = this.__ee__;\n\t}\n\tif (!data[type]) data[type] = listener;\n\telse if (typeof data[type] === 'object') data[type].push(listener);\n\telse data[type] = [data[type], listener];\n\n\treturn this;\n};\n\nonce = function (type, listener) {\n\tvar once, self;\n\n\tcallable(listener);\n\tself = this;\n\ton.call(this, type, once = function () {\n\t\toff.call(self, type, once);\n\t\tapply.call(listener, this, arguments);\n\t});\n\n\tonce.__eeOnceListener__ = listener;\n\treturn this;\n};\n\noff = function (type, listener) {\n\tvar data, listeners, candidate, i;\n\n\tcallable(listener);\n\n\tif (!hasOwnProperty.call(this, '__ee__')) return this;\n\tdata = this.__ee__;\n\tif (!data[type]) return this;\n\tlisteners = data[type];\n\n\tif (typeof listeners === 'object') {\n\t\tfor (i = 0; (candidate = listeners[i]); ++i) {\n\t\t\tif ((candidate === listener) ||\n\t\t\t\t\t(candidate.__eeOnceListener__ === listener)) {\n\t\t\t\tif (listeners.length === 2) data[type] = listeners[i ? 0 : 1];\n\t\t\t\telse listeners.splice(i, 1);\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif ((listeners === listener) ||\n\t\t\t\t(listeners.__eeOnceListener__ === listener)) {\n\t\t\tdelete data[type];\n\t\t}\n\t}\n\n\treturn this;\n};\n\nemit = function (type) {\n\tvar i, l, listener, listeners, args;\n\n\tif (!hasOwnProperty.call(this, '__ee__')) return;\n\tlisteners = this.__ee__[type];\n\tif (!listeners) return;\n\n\tif (typeof listeners === 'object') {\n\t\tl = arguments.length;\n\t\targs = new Array(l - 1);\n\t\tfor (i = 1; i < l; ++i) args[i - 1] = arguments[i];\n\n\t\tlisteners = listeners.slice();\n\t\tfor (i = 0; (listener = listeners[i]); ++i) {\n\t\t\tapply.call(listener, this, args);\n\t\t}\n\t} else {\n\t\tswitch (arguments.length) {\n\t\tcase 1:\n\t\t\tcall.call(listeners, this);\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tcall.call(listeners, this, arguments[1]);\n\t\t\tbreak;\n\t\tcase 3:\n\t\t\tcall.call(listeners, this, arguments[1], arguments[2]);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tl = arguments.length;\n\t\t\targs = new Array(l - 1);\n\t\t\tfor (i = 1; i < l; ++i) {\n\t\t\t\targs[i - 1] = arguments[i];\n\t\t\t}\n\t\t\tapply.call(listeners, this, args);\n\t\t}\n\t}\n};\n\nmethods = {\n\ton: on,\n\tonce: once,\n\toff: off,\n\temit: emit\n};\n\ndescriptors = {\n\ton: d(on),\n\tonce: d(once),\n\toff: d(off),\n\temit: d(emit)\n};\n\nbase = defineProperties({}, descriptors);\n\nmodule.exports = exports = function (o) {\n\treturn (o == null) ? create(base) : defineProperties(Object(o), descriptors);\n};\nexports.methods = methods;\n","'use strict';\n\nvar validTypes = { object: true, symbol: true };\n\nmodule.exports = function () {\n\tvar symbol;\n\tif (typeof Symbol !== 'function') return false;\n\tsymbol = Symbol('test symbol');\n\ttry { String(symbol); } catch (e) { return false; }\n\n\t// Return 'true' also for polyfills\n\tif (!validTypes[typeof Symbol.iterator]) return false;\n\tif (!validTypes[typeof Symbol.toPrimitive]) return false;\n\tif (!validTypes[typeof Symbol.toStringTag]) return false;\n\n\treturn true;\n};\n","'use strict';\n\nmodule.exports = function (x) {\n\tif (!x) return false;\n\tif (typeof x === 'symbol') return true;\n\tif (!x.constructor) return false;\n\tif (x.constructor.name !== 'Symbol') return false;\n\treturn (x[x.constructor.toStringTag] === 'Symbol');\n};\n","'use strict';\n\nvar isSymbol = require('./is-symbol');\n\nmodule.exports = function (value) {\n\tif (!isSymbol(value)) throw new TypeError(value + \" is not a symbol\");\n\treturn value;\n};\n","// ES2015 Symbol polyfill for environments that do not (or partially) support it\n\n'use strict';\n\nvar d = require('d')\n , validateSymbol = require('./validate-symbol')\n\n , create = Object.create, defineProperties = Object.defineProperties\n , defineProperty = Object.defineProperty, objPrototype = Object.prototype\n , NativeSymbol, SymbolPolyfill, HiddenSymbol, globalSymbols = create(null)\n , isNativeSafe;\n\nif (typeof Symbol === 'function') {\n\tNativeSymbol = Symbol;\n\ttry {\n\t\tString(NativeSymbol());\n\t\tisNativeSafe = true;\n\t} catch (ignore) {}\n}\n\nvar generateName = (function () {\n\tvar created = create(null);\n\treturn function (desc) {\n\t\tvar postfix = 0, name, ie11BugWorkaround;\n\t\twhile (created[desc + (postfix || '')]) ++postfix;\n\t\tdesc += (postfix || '');\n\t\tcreated[desc] = true;\n\t\tname = '@@' + desc;\n\t\tdefineProperty(objPrototype, name, d.gs(null, function (value) {\n\t\t\t// For IE11 issue see:\n\t\t\t// https://connect.microsoft.com/IE/feedbackdetail/view/1928508/\n\t\t\t// ie11-broken-getters-on-dom-objects\n\t\t\t// https://github.com/medikoo/es6-symbol/issues/12\n\t\t\tif (ie11BugWorkaround) return;\n\t\t\tie11BugWorkaround = true;\n\t\t\tdefineProperty(this, name, d(value));\n\t\t\tie11BugWorkaround = false;\n\t\t}));\n\t\treturn name;\n\t};\n}());\n\n// Internal constructor (not one exposed) for creating Symbol instances.\n// This one is used to ensure that `someSymbol instanceof Symbol` always return false\nHiddenSymbol = function Symbol(description) {\n\tif (this instanceof HiddenSymbol) throw new TypeError('Symbol is not a constructor');\n\treturn SymbolPolyfill(description);\n};\n\n// Exposed `Symbol` constructor\n// (returns instances of HiddenSymbol)\nmodule.exports = SymbolPolyfill = function Symbol(description) {\n\tvar symbol;\n\tif (this instanceof Symbol) throw new TypeError('Symbol is not a constructor');\n\tif (isNativeSafe) return NativeSymbol(description);\n\tsymbol = create(HiddenSymbol.prototype);\n\tdescription = (description === undefined ? '' : String(description));\n\treturn defineProperties(symbol, {\n\t\t__description__: d('', description),\n\t\t__name__: d('', generateName(description))\n\t});\n};\ndefineProperties(SymbolPolyfill, {\n\tfor: d(function (key) {\n\t\tif (globalSymbols[key]) return globalSymbols[key];\n\t\treturn (globalSymbols[key] = SymbolPolyfill(String(key)));\n\t}),\n\tkeyFor: d(function (s) {\n\t\tvar key;\n\t\tvalidateSymbol(s);\n\t\tfor (key in globalSymbols) if (globalSymbols[key] === s) return key;\n\t}),\n\n\t// To ensure proper interoperability with other native functions (e.g. Array.from)\n\t// fallback to eventual native implementation of given symbol\n\thasInstance: d('', (NativeSymbol && NativeSymbol.hasInstance) || SymbolPolyfill('hasInstance')),\n\tisConcatSpreadable: d('', (NativeSymbol && NativeSymbol.isConcatSpreadable) ||\n\t\tSymbolPolyfill('isConcatSpreadable')),\n\titerator: d('', (NativeSymbol && NativeSymbol.iterator) || SymbolPolyfill('iterator')),\n\tmatch: d('', (NativeSymbol && NativeSymbol.match) || SymbolPolyfill('match')),\n\treplace: d('', (NativeSymbol && NativeSymbol.replace) || SymbolPolyfill('replace')),\n\tsearch: d('', (NativeSymbol && NativeSymbol.search) || SymbolPolyfill('search')),\n\tspecies: d('', (NativeSymbol && NativeSymbol.species) || SymbolPolyfill('species')),\n\tsplit: d('', (NativeSymbol && NativeSymbol.split) || SymbolPolyfill('split')),\n\ttoPrimitive: d('', (NativeSymbol && NativeSymbol.toPrimitive) || SymbolPolyfill('toPrimitive')),\n\ttoStringTag: d('', (NativeSymbol && NativeSymbol.toStringTag) || SymbolPolyfill('toStringTag')),\n\tunscopables: d('', (NativeSymbol && NativeSymbol.unscopables) || SymbolPolyfill('unscopables'))\n});\n\n// Internal tweaks for real symbol producer\ndefineProperties(HiddenSymbol.prototype, {\n\tconstructor: d(SymbolPolyfill),\n\ttoString: d('', function () { return this.__name__; })\n});\n\n// Proper implementation of methods exposed on Symbol.prototype\n// They won't be accessible on produced symbol instances as they derive from HiddenSymbol.prototype\ndefineProperties(SymbolPolyfill.prototype, {\n\ttoString: d(function () { return 'Symbol (' + validateSymbol(this).__description__ + ')'; }),\n\tvalueOf: d(function () { return validateSymbol(this); })\n});\ndefineProperty(SymbolPolyfill.prototype, SymbolPolyfill.toPrimitive, d('', function () {\n\tvar symbol = validateSymbol(this);\n\tif (typeof symbol === 'symbol') return symbol;\n\treturn symbol.toString();\n}));\ndefineProperty(SymbolPolyfill.prototype, SymbolPolyfill.toStringTag, d('c', 'Symbol'));\n\n// Proper implementaton of toPrimitive and toStringTag for returned symbol instances\ndefineProperty(HiddenSymbol.prototype, SymbolPolyfill.toStringTag,\n\td('c', SymbolPolyfill.prototype[SymbolPolyfill.toStringTag]));\n\n// Note: It's important to define `toPrimitive` as last one, as some implementations\n// implement `toPrimitive` natively without implementing `toStringTag` (or other specified symbols)\n// And that may invoke error in definition flow:\n// See: https://github.com/medikoo/es6-symbol/issues/13#issuecomment-164146149\ndefineProperty(HiddenSymbol.prototype, SymbolPolyfill.toPrimitive,\n\td('c', SymbolPolyfill.prototype[SymbolPolyfill.toPrimitive]));\n","'use strict';\n\nmodule.exports = require('./is-implemented')() ? Symbol : require('./polyfill');\n","\"use strict\";\n\nvar objToString = Object.prototype.toString\n , id = objToString.call((function () { return arguments; })());\n\nmodule.exports = function (value) { return objToString.call(value) === id; };\n","\"use strict\";\n\nvar objToString = Object.prototype.toString, id = objToString.call(\"\");\n\nmodule.exports = function (value) {\n\treturn (\n\t\ttypeof value === \"string\" ||\n\t\t(value &&\n\t\t\ttypeof value === \"object\" &&\n\t\t\t(value instanceof String || objToString.call(value) === id)) ||\n\t\tfalse\n\t);\n};\n","module.exports = (function () {\n\tif (this) return this;\n\n\t// Unexpected strict mode (may happen if e.g. bundled into ESM module), be nice\n\n\t// Thanks @mathiasbynens -> https://mathiasbynens.be/notes/globalthis\n\t// In all ES5+ engines global object inherits from Object.prototype\n\t// (if you approached one that doesn't please report)\n\tObject.defineProperty(Object.prototype, \"__global__\", {\n\t\tget: function () { return this; },\n\t\tconfigurable: true\n\t});\n\ttry { return __global__; }\n\tfinally { delete Object.prototype.__global__; }\n})();\n","\"use strict\";\n\nvar global = require(\"es5-ext/global\")\n , validTypes = { object: true, symbol: true };\n\nmodule.exports = function () {\n\tvar Symbol = global.Symbol;\n\tvar symbol;\n\tif (typeof Symbol !== \"function\") return false;\n\tsymbol = Symbol(\"test symbol\");\n\ttry { String(symbol); }\n\tcatch (e) { return false; }\n\n\t// Return 'true' also for polyfills\n\tif (!validTypes[typeof Symbol.iterator]) return false;\n\tif (!validTypes[typeof Symbol.toPrimitive]) return false;\n\tif (!validTypes[typeof Symbol.toStringTag]) return false;\n\n\treturn true;\n};\n","\"use strict\";\n\nmodule.exports = function (value) {\n\tif (!value) return false;\n\tif (typeof value === \"symbol\") return true;\n\tif (!value.constructor) return false;\n\tif (value.constructor.name !== \"Symbol\") return false;\n\treturn value[value.constructor.toStringTag] === \"Symbol\";\n};\n","\"use strict\";\n\nvar isSymbol = require(\"./is-symbol\");\n\nmodule.exports = function (value) {\n\tif (!isSymbol(value)) throw new TypeError(value + \" is not a symbol\");\n\treturn value;\n};\n","\"use strict\";\n\nvar d = require(\"d\");\n\nvar create = Object.create, defineProperty = Object.defineProperty, objPrototype = Object.prototype;\n\nvar created = create(null);\nmodule.exports = function (desc) {\n\tvar postfix = 0, name, ie11BugWorkaround;\n\twhile (created[desc + (postfix || \"\")]) ++postfix;\n\tdesc += postfix || \"\";\n\tcreated[desc] = true;\n\tname = \"@@\" + desc;\n\tdefineProperty(\n\t\tobjPrototype,\n\t\tname,\n\t\td.gs(null, function (value) {\n\t\t\t// For IE11 issue see:\n\t\t\t// https://connect.microsoft.com/IE/feedbackdetail/view/1928508/\n\t\t\t// ie11-broken-getters-on-dom-objects\n\t\t\t// https://github.com/medikoo/es6-symbol/issues/12\n\t\t\tif (ie11BugWorkaround) return;\n\t\t\tie11BugWorkaround = true;\n\t\t\tdefineProperty(this, name, d(value));\n\t\t\tie11BugWorkaround = false;\n\t\t})\n\t);\n\treturn name;\n};\n","\"use strict\";\n\nvar d = require(\"d\")\n , NativeSymbol = require(\"es5-ext/global\").Symbol;\n\nmodule.exports = function (SymbolPolyfill) {\n\treturn Object.defineProperties(SymbolPolyfill, {\n\t\t// To ensure proper interoperability with other native functions (e.g. Array.from)\n\t\t// fallback to eventual native implementation of given symbol\n\t\thasInstance: d(\n\t\t\t\"\", (NativeSymbol && NativeSymbol.hasInstance) || SymbolPolyfill(\"hasInstance\")\n\t\t),\n\t\tisConcatSpreadable: d(\n\t\t\t\"\",\n\t\t\t(NativeSymbol && NativeSymbol.isConcatSpreadable) ||\n\t\t\t\tSymbolPolyfill(\"isConcatSpreadable\")\n\t\t),\n\t\titerator: d(\"\", (NativeSymbol && NativeSymbol.iterator) || SymbolPolyfill(\"iterator\")),\n\t\tmatch: d(\"\", (NativeSymbol && NativeSymbol.match) || SymbolPolyfill(\"match\")),\n\t\treplace: d(\"\", (NativeSymbol && NativeSymbol.replace) || SymbolPolyfill(\"replace\")),\n\t\tsearch: d(\"\", (NativeSymbol && NativeSymbol.search) || SymbolPolyfill(\"search\")),\n\t\tspecies: d(\"\", (NativeSymbol && NativeSymbol.species) || SymbolPolyfill(\"species\")),\n\t\tsplit: d(\"\", (NativeSymbol && NativeSymbol.split) || SymbolPolyfill(\"split\")),\n\t\ttoPrimitive: d(\n\t\t\t\"\", (NativeSymbol && NativeSymbol.toPrimitive) || SymbolPolyfill(\"toPrimitive\")\n\t\t),\n\t\ttoStringTag: d(\n\t\t\t\"\", (NativeSymbol && NativeSymbol.toStringTag) || SymbolPolyfill(\"toStringTag\")\n\t\t),\n\t\tunscopables: d(\n\t\t\t\"\", (NativeSymbol && NativeSymbol.unscopables) || SymbolPolyfill(\"unscopables\")\n\t\t)\n\t});\n};\n","\"use strict\";\n\nvar d = require(\"d\")\n , validateSymbol = require(\"../../../validate-symbol\");\n\nvar registry = Object.create(null);\n\nmodule.exports = function (SymbolPolyfill) {\n\treturn Object.defineProperties(SymbolPolyfill, {\n\t\tfor: d(function (key) {\n\t\t\tif (registry[key]) return registry[key];\n\t\t\treturn (registry[key] = SymbolPolyfill(String(key)));\n\t\t}),\n\t\tkeyFor: d(function (symbol) {\n\t\t\tvar key;\n\t\t\tvalidateSymbol(symbol);\n\t\t\tfor (key in registry) {\n\t\t\t\tif (registry[key] === symbol) return key;\n\t\t\t}\n\t\t\treturn undefined;\n\t\t})\n\t});\n};\n","// ES2015 Symbol polyfill for environments that do not (or partially) support it\n\n\"use strict\";\n\nvar d = require(\"d\")\n , validateSymbol = require(\"./validate-symbol\")\n , NativeSymbol = require(\"es5-ext/global\").Symbol\n , generateName = require(\"./lib/private/generate-name\")\n , setupStandardSymbols = require(\"./lib/private/setup/standard-symbols\")\n , setupSymbolRegistry = require(\"./lib/private/setup/symbol-registry\");\n\nvar create = Object.create\n , defineProperties = Object.defineProperties\n , defineProperty = Object.defineProperty;\n\nvar SymbolPolyfill, HiddenSymbol, isNativeSafe;\n\nif (typeof NativeSymbol === \"function\") {\n\ttry {\n\t\tString(NativeSymbol());\n\t\tisNativeSafe = true;\n\t} catch (ignore) {}\n} else {\n\tNativeSymbol = null;\n}\n\n// Internal constructor (not one exposed) for creating Symbol instances.\n// This one is used to ensure that `someSymbol instanceof Symbol` always return false\nHiddenSymbol = function Symbol(description) {\n\tif (this instanceof HiddenSymbol) throw new TypeError(\"Symbol is not a constructor\");\n\treturn SymbolPolyfill(description);\n};\n\n// Exposed `Symbol` constructor\n// (returns instances of HiddenSymbol)\nmodule.exports = SymbolPolyfill = function Symbol(description) {\n\tvar symbol;\n\tif (this instanceof Symbol) throw new TypeError(\"Symbol is not a constructor\");\n\tif (isNativeSafe) return NativeSymbol(description);\n\tsymbol = create(HiddenSymbol.prototype);\n\tdescription = description === undefined ? \"\" : String(description);\n\treturn defineProperties(symbol, {\n\t\t__description__: d(\"\", description),\n\t\t__name__: d(\"\", generateName(description))\n\t});\n};\n\nsetupStandardSymbols(SymbolPolyfill);\nsetupSymbolRegistry(SymbolPolyfill);\n\n// Internal tweaks for real symbol producer\ndefineProperties(HiddenSymbol.prototype, {\n\tconstructor: d(SymbolPolyfill),\n\ttoString: d(\"\", function () { return this.__name__; })\n});\n\n// Proper implementation of methods exposed on Symbol.prototype\n// They won't be accessible on produced symbol instances as they derive from HiddenSymbol.prototype\ndefineProperties(SymbolPolyfill.prototype, {\n\ttoString: d(function () { return \"Symbol (\" + validateSymbol(this).__description__ + \")\"; }),\n\tvalueOf: d(function () { return validateSymbol(this); })\n});\ndefineProperty(\n\tSymbolPolyfill.prototype,\n\tSymbolPolyfill.toPrimitive,\n\td(\"\", function () {\n\t\tvar symbol = validateSymbol(this);\n\t\tif (typeof symbol === \"symbol\") return symbol;\n\t\treturn symbol.toString();\n\t})\n);\ndefineProperty(SymbolPolyfill.prototype, SymbolPolyfill.toStringTag, d(\"c\", \"Symbol\"));\n\n// Proper implementaton of toPrimitive and toStringTag for returned symbol instances\ndefineProperty(\n\tHiddenSymbol.prototype, SymbolPolyfill.toStringTag,\n\td(\"c\", SymbolPolyfill.prototype[SymbolPolyfill.toStringTag])\n);\n\n// Note: It's important to define `toPrimitive` as last one, as some implementations\n// implement `toPrimitive` natively without implementing `toStringTag` (or other specified symbols)\n// And that may invoke error in definition flow:\n// See: https://github.com/medikoo/es6-symbol/issues/13#issuecomment-164146149\ndefineProperty(\n\tHiddenSymbol.prototype, SymbolPolyfill.toPrimitive,\n\td(\"c\", SymbolPolyfill.prototype[SymbolPolyfill.toPrimitive])\n);\n","\"use strict\";\n\nmodule.exports = require(\"./is-implemented\")()\n\t? require(\"es5-ext/global\").Symbol\n\t: require(\"./polyfill\");\n","\"use strict\";\n\nvar isArguments = require(\"es5-ext/function/is-arguments\")\n , isValue = require(\"es5-ext/object/is-value\")\n , isString = require(\"es5-ext/string/is-string\");\n\nvar iteratorSymbol = require(\"es6-symbol\").iterator\n , isArray = Array.isArray;\n\nmodule.exports = function (value) {\n\tif (!isValue(value)) return false;\n\tif (isArray(value)) return true;\n\tif (isString(value)) return true;\n\tif (isArguments(value)) return true;\n\treturn typeof value[iteratorSymbol] === \"function\";\n};\n","\"use strict\";\n\nvar isIterable = require(\"./is-iterable\");\n\nmodule.exports = function (value) {\n\tif (!isIterable(value)) throw new TypeError(value + \" is not iterable\");\n\treturn value;\n};\n","\"use strict\";\n\nvar isValue = require(\"../value/is\")\n , isObject = require(\"../object/is\");\n\nvar objectToString = Object.prototype.toString;\n\nmodule.exports = function (value) {\n\tif (!isValue(value)) return null;\n\tif (isObject(value)) {\n\t\t// Reject Object.prototype.toString coercion\n\t\tvar valueToString = value.toString;\n\t\tif (typeof valueToString !== \"function\") return null;\n\t\tif (valueToString === objectToString) return null;\n\t\t// Note: It can be object coming from other realm, still as there's no ES3 and CSP compliant\n\t\t// way to resolve its realm's Object.prototype.toString it's left as not addressed edge case\n\t}\n\ttry {\n\t\treturn \"\" + value; // Ensure implicit coercion\n\t} catch (error) {\n\t\treturn null;\n\t}\n};\n","\"use strict\";\n\nmodule.exports = function (value) {\n\ttry {\n\t\treturn value.toString();\n\t} catch (error) {\n\t\ttry { return String(value); }\n\t\tcatch (error2) { return null; }\n\t}\n};\n","\"use strict\";\n\nvar safeToString = require(\"./safe-to-string\");\n\nvar reNewLine = /[\\n\\r\\u2028\\u2029]/g;\n\nmodule.exports = function (value) {\n\tvar string = safeToString(value);\n\tif (string === null) return \"\";\n\t// Trim if too long\n\tif (string.length > 100) string = string.slice(0, 99) + \"…\";\n\t// Replace eventual new lines\n\tstring = string.replace(reNewLine, function (char) {\n\t\tswitch (char) {\n\t\t\tcase \"\\n\":\n\t\t\t\treturn \"\\\\n\";\n\t\t\tcase \"\\r\":\n\t\t\t\treturn \"\\\\r\";\n\t\t\tcase \"\\u2028\":\n\t\t\t\treturn \"\\\\u2028\";\n\t\t\tcase \"\\u2029\":\n\t\t\t\treturn \"\\\\u2029\";\n\t\t\t/* istanbul ignore next */\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Unexpected character\");\n\t\t}\n\t});\n\treturn string;\n};\n","\"use strict\";\n\nvar isValue = require(\"../value/is\")\n , isObject = require(\"../object/is\")\n , stringCoerce = require(\"../string/coerce\")\n , toShortString = require(\"./to-short-string\");\n\nvar resolveMessage = function (message, value) {\n\treturn message.replace(\"%v\", toShortString(value));\n};\n\nmodule.exports = function (value, defaultMessage, inputOptions) {\n\tif (!isObject(inputOptions)) throw new TypeError(resolveMessage(defaultMessage, value));\n\tif (!isValue(value)) {\n\t\tif (\"default\" in inputOptions) return inputOptions[\"default\"];\n\t\tif (inputOptions.isOptional) return null;\n\t}\n\tvar errorMessage = stringCoerce(inputOptions.errorMessage);\n\tif (!isValue(errorMessage)) errorMessage = defaultMessage;\n\tthrow new TypeError(resolveMessage(errorMessage, value));\n};\n","\"use strict\";\n\nvar resolveException = require(\"../lib/resolve-exception\")\n , is = require(\"./is\");\n\nmodule.exports = function (value/*, options*/) {\n\tif (is(value)) return value;\n\treturn resolveException(value, \"Cannot use %v\", arguments[1]);\n};\n","\"use strict\";\n\nvar resolveException = require(\"../lib/resolve-exception\")\n , is = require(\"./is\");\n\nmodule.exports = function (value/*, options*/) {\n\tif (is(value)) return value;\n\treturn resolveException(value, \"%v is not a plain function\", arguments[1]);\n};\n","\"use strict\";\n\nmodule.exports = function () {\n\tvar from = Array.from, arr, result;\n\tif (typeof from !== \"function\") return false;\n\tarr = [\"raz\", \"dwa\"];\n\tresult = from(arr);\n\treturn Boolean(result && result !== arr && result[1] === \"dwa\");\n};\n","\"use strict\";\n\nvar objToString = Object.prototype.toString\n , isFunctionStringTag = RegExp.prototype.test.bind(/^[object [A-Za-z0-9]*Function]$/);\n\nmodule.exports = function (value) {\n\treturn typeof value === \"function\" && isFunctionStringTag(objToString.call(value));\n};\n","\"use strict\";\n\nvar iteratorSymbol = require(\"es6-symbol\").iterator\n , isArguments = require(\"../../function/is-arguments\")\n , isFunction = require(\"../../function/is-function\")\n , toPosInt = require(\"../../number/to-pos-integer\")\n , callable = require(\"../../object/valid-callable\")\n , validValue = require(\"../../object/valid-value\")\n , isValue = require(\"../../object/is-value\")\n , isString = require(\"../../string/is-string\")\n , isArray = Array.isArray\n , call = Function.prototype.call\n , desc = { configurable: true, enumerable: true, writable: true, value: null }\n , defineProperty = Object.defineProperty;\n\n// eslint-disable-next-line complexity, max-lines-per-function\nmodule.exports = function (arrayLike/*, mapFn, thisArg*/) {\n\tvar mapFn = arguments[1]\n\t , thisArg = arguments[2]\n\t , Context\n\t , i\n\t , j\n\t , arr\n\t , length\n\t , code\n\t , iterator\n\t , result\n\t , getIterator\n\t , value;\n\n\tarrayLike = Object(validValue(arrayLike));\n\n\tif (isValue(mapFn)) callable(mapFn);\n\tif (!this || this === Array || !isFunction(this)) {\n\t\t// Result: Plain array\n\t\tif (!mapFn) {\n\t\t\tif (isArguments(arrayLike)) {\n\t\t\t\t// Source: Arguments\n\t\t\t\tlength = arrayLike.length;\n\t\t\t\tif (length !== 1) return Array.apply(null, arrayLike);\n\t\t\t\tarr = new Array(1);\n\t\t\t\tarr[0] = arrayLike[0];\n\t\t\t\treturn arr;\n\t\t\t}\n\t\t\tif (isArray(arrayLike)) {\n\t\t\t\t// Source: Array\n\t\t\t\tarr = new Array((length = arrayLike.length));\n\t\t\t\tfor (i = 0; i < length; ++i) arr[i] = arrayLike[i];\n\t\t\t\treturn arr;\n\t\t\t}\n\t\t}\n\t\tarr = [];\n\t} else {\n\t\t// Result: Non plain array\n\t\tContext = this;\n\t}\n\n\tif (!isArray(arrayLike)) {\n\t\tif ((getIterator = arrayLike[iteratorSymbol]) !== undefined) {\n\t\t\t// Source: Iterator\n\t\t\titerator = callable(getIterator).call(arrayLike);\n\t\t\tif (Context) arr = new Context();\n\t\t\tresult = iterator.next();\n\t\t\ti = 0;\n\t\t\twhile (!result.done) {\n\t\t\t\tvalue = mapFn ? call.call(mapFn, thisArg, result.value, i) : result.value;\n\t\t\t\tif (Context) {\n\t\t\t\t\tdesc.value = value;\n\t\t\t\t\tdefineProperty(arr, i, desc);\n\t\t\t\t} else {\n\t\t\t\t\tarr[i] = value;\n\t\t\t\t}\n\t\t\t\tresult = iterator.next();\n\t\t\t\t++i;\n\t\t\t}\n\t\t\tlength = i;\n\t\t} else if (isString(arrayLike)) {\n\t\t\t// Source: String\n\t\t\tlength = arrayLike.length;\n\t\t\tif (Context) arr = new Context();\n\t\t\tfor (i = 0, j = 0; i < length; ++i) {\n\t\t\t\tvalue = arrayLike[i];\n\t\t\t\tif (i + 1 < length) {\n\t\t\t\t\tcode = value.charCodeAt(0);\n\t\t\t\t\t// eslint-disable-next-line max-depth\n\t\t\t\t\tif (code >= 0xd800 && code <= 0xdbff) value += arrayLike[++i];\n\t\t\t\t}\n\t\t\t\tvalue = mapFn ? call.call(mapFn, thisArg, value, j) : value;\n\t\t\t\tif (Context) {\n\t\t\t\t\tdesc.value = value;\n\t\t\t\t\tdefineProperty(arr, j, desc);\n\t\t\t\t} else {\n\t\t\t\t\tarr[j] = value;\n\t\t\t\t}\n\t\t\t\t++j;\n\t\t\t}\n\t\t\tlength = j;\n\t\t}\n\t}\n\tif (length === undefined) {\n\t\t// Source: array or array-like\n\t\tlength = toPosInt(arrayLike.length);\n\t\tif (Context) arr = new Context(length);\n\t\tfor (i = 0; i < length; ++i) {\n\t\t\tvalue = mapFn ? call.call(mapFn, thisArg, arrayLike[i], i) : arrayLike[i];\n\t\t\tif (Context) {\n\t\t\t\tdesc.value = value;\n\t\t\t\tdefineProperty(arr, i, desc);\n\t\t\t} else {\n\t\t\t\tarr[i] = value;\n\t\t\t}\n\t\t}\n\t}\n\tif (Context) {\n\t\tdesc.value = null;\n\t\tarr.length = length;\n\t}\n\treturn arr;\n};\n","\"use strict\";\n\nmodule.exports = require(\"./is-implemented\")() ? Array.from : require(\"./shim\");\n","\"use strict\";\n\nvar aFrom = require(\"../array/from\")\n , assign = require(\"./assign\")\n , value = require(\"./valid-value\");\n\nmodule.exports = function (obj/*, propertyNames, options*/) {\n\tvar copy = Object(value(obj)), propertyNames = arguments[1], options = Object(arguments[2]);\n\tif (copy !== obj && !propertyNames) return copy;\n\tvar result = {};\n\tif (propertyNames) {\n\t\taFrom(propertyNames, function (propertyName) {\n\t\t\tif (options.ensure || propertyName in obj) result[propertyName] = obj[propertyName];\n\t\t});\n\t} else {\n\t\tassign(result, obj);\n\t}\n\treturn result;\n};\n","// Internal method, used by iteration functions.\n// Calls a function for each key-value pair found in object\n// Optionally takes compareFn to iterate object in specific order\n\n\"use strict\";\n\nvar callable = require(\"./valid-callable\")\n , value = require(\"./valid-value\")\n , bind = Function.prototype.bind\n , call = Function.prototype.call\n , keys = Object.keys\n , objPropertyIsEnumerable = Object.prototype.propertyIsEnumerable;\n\nmodule.exports = function (method, defVal) {\n\treturn function (obj, cb/*, thisArg, compareFn*/) {\n\t\tvar list, thisArg = arguments[2], compareFn = arguments[3];\n\t\tobj = Object(value(obj));\n\t\tcallable(cb);\n\n\t\tlist = keys(obj);\n\t\tif (compareFn) {\n\t\t\tlist.sort(typeof compareFn === \"function\" ? bind.call(compareFn, obj) : undefined);\n\t\t}\n\t\tif (typeof method !== \"function\") method = list[method];\n\t\treturn call.call(method, list, function (key, index) {\n\t\t\tif (!objPropertyIsEnumerable.call(obj, key)) return defVal;\n\t\t\treturn call.call(cb, thisArg, obj[key], key, obj, index);\n\t\t});\n\t};\n};\n","\"use strict\";\n\nmodule.exports = require(\"./_iterate\")(\"forEach\");\n","\"use strict\";\n\nvar callable = require(\"./valid-callable\")\n , forEach = require(\"./for-each\")\n , call = Function.prototype.call;\n\nmodule.exports = function (obj, cb/*, thisArg*/) {\n\tvar result = {}, thisArg = arguments[2];\n\tcallable(cb);\n\tforEach(obj, function (value, key, targetObj, index) {\n\t\tresult[key] = call.call(cb, thisArg, value, key, targetObj, index);\n\t});\n\treturn result;\n};\n","\"use strict\";\n\nvar isValue = require(\"type/value/is\")\n , ensureValue = require(\"type/value/ensure\")\n , ensurePlainFunction = require(\"type/plain-function/ensure\")\n , copy = require(\"es5-ext/object/copy\")\n , normalizeOptions = require(\"es5-ext/object/normalize-options\")\n , map = require(\"es5-ext/object/map\");\n\nvar bind = Function.prototype.bind\n , defineProperty = Object.defineProperty\n , hasOwnProperty = Object.prototype.hasOwnProperty\n , define;\n\ndefine = function (name, desc, options) {\n\tvar value = ensureValue(desc) && ensurePlainFunction(desc.value), dgs;\n\tdgs = copy(desc);\n\tdelete dgs.writable;\n\tdelete dgs.value;\n\tdgs.get = function () {\n\t\tif (!options.overwriteDefinition && hasOwnProperty.call(this, name)) return value;\n\t\tdesc.value = bind.call(value, options.resolveContext ? options.resolveContext(this) : this);\n\t\tdefineProperty(this, name, desc);\n\t\treturn this[name];\n\t};\n\treturn dgs;\n};\n\nmodule.exports = function (props/*, options*/) {\n\tvar options = normalizeOptions(arguments[1]);\n\tif (isValue(options.resolveContext)) ensurePlainFunction(options.resolveContext);\n\treturn map(props, function (desc, name) { return define(name, desc, options); });\n};\n","\"use strict\";\n\nvar clear = require(\"es5-ext/array/#/clear\")\n , assign = require(\"es5-ext/object/assign\")\n , callable = require(\"es5-ext/object/valid-callable\")\n , value = require(\"es5-ext/object/valid-value\")\n , d = require(\"d\")\n , autoBind = require(\"d/auto-bind\")\n , Symbol = require(\"es6-symbol\");\n\nvar defineProperty = Object.defineProperty, defineProperties = Object.defineProperties, Iterator;\n\nmodule.exports = Iterator = function (list, context) {\n\tif (!(this instanceof Iterator)) throw new TypeError(\"Constructor requires 'new'\");\n\tdefineProperties(this, {\n\t\t__list__: d(\"w\", value(list)),\n\t\t__context__: d(\"w\", context),\n\t\t__nextIndex__: d(\"w\", 0)\n\t});\n\tif (!context) return;\n\tcallable(context.on);\n\tcontext.on(\"_add\", this._onAdd);\n\tcontext.on(\"_delete\", this._onDelete);\n\tcontext.on(\"_clear\", this._onClear);\n};\n\n// Internal %IteratorPrototype% doesn't expose its constructor\ndelete Iterator.prototype.constructor;\n\ndefineProperties(\n\tIterator.prototype,\n\tassign(\n\t\t{\n\t\t\t_next: d(function () {\n\t\t\t\tvar i;\n\t\t\t\tif (!this.__list__) return undefined;\n\t\t\t\tif (this.__redo__) {\n\t\t\t\t\ti = this.__redo__.shift();\n\t\t\t\t\tif (i !== undefined) return i;\n\t\t\t\t}\n\t\t\t\tif (this.__nextIndex__ < this.__list__.length) return this.__nextIndex__++;\n\t\t\t\tthis._unBind();\n\t\t\t\treturn undefined;\n\t\t\t}),\n\t\t\tnext: d(function () {\n\t\t\t\treturn this._createResult(this._next());\n\t\t\t}),\n\t\t\t_createResult: d(function (i) {\n\t\t\t\tif (i === undefined) return { done: true, value: undefined };\n\t\t\t\treturn { done: false, value: this._resolve(i) };\n\t\t\t}),\n\t\t\t_resolve: d(function (i) {\n\t\t\t\treturn this.__list__[i];\n\t\t\t}),\n\t\t\t_unBind: d(function () {\n\t\t\t\tthis.__list__ = null;\n\t\t\t\tdelete this.__redo__;\n\t\t\t\tif (!this.__context__) return;\n\t\t\t\tthis.__context__.off(\"_add\", this._onAdd);\n\t\t\t\tthis.__context__.off(\"_delete\", this._onDelete);\n\t\t\t\tthis.__context__.off(\"_clear\", this._onClear);\n\t\t\t\tthis.__context__ = null;\n\t\t\t}),\n\t\t\ttoString: d(function () {\n\t\t\t\treturn \"[object \" + (this[Symbol.toStringTag] || \"Object\") + \"]\";\n\t\t\t})\n\t\t},\n\t\tautoBind({\n\t\t\t_onAdd: d(function (index) {\n\t\t\t\tif (index >= this.__nextIndex__) return;\n\t\t\t\t++this.__nextIndex__;\n\t\t\t\tif (!this.__redo__) {\n\t\t\t\t\tdefineProperty(this, \"__redo__\", d(\"c\", [index]));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.__redo__.forEach(function (redo, i) {\n\t\t\t\t\tif (redo >= index) this.__redo__[i] = ++redo;\n\t\t\t\t}, this);\n\t\t\t\tthis.__redo__.push(index);\n\t\t\t}),\n\t\t\t_onDelete: d(function (index) {\n\t\t\t\tvar i;\n\t\t\t\tif (index >= this.__nextIndex__) return;\n\t\t\t\t--this.__nextIndex__;\n\t\t\t\tif (!this.__redo__) return;\n\t\t\t\ti = this.__redo__.indexOf(index);\n\t\t\t\tif (i !== -1) this.__redo__.splice(i, 1);\n\t\t\t\tthis.__redo__.forEach(function (redo, j) {\n\t\t\t\t\tif (redo > index) this.__redo__[j] = --redo;\n\t\t\t\t}, this);\n\t\t\t}),\n\t\t\t_onClear: d(function () {\n\t\t\t\tif (this.__redo__) clear.call(this.__redo__);\n\t\t\t\tthis.__nextIndex__ = 0;\n\t\t\t})\n\t\t})\n\t)\n);\n\ndefineProperty(\n\tIterator.prototype,\n\tSymbol.iterator,\n\td(function () {\n\t\treturn this;\n\t})\n);\n","\"use strict\";\n\nvar setPrototypeOf = require(\"es5-ext/object/set-prototype-of\")\n , contains = require(\"es5-ext/string/#/contains\")\n , d = require(\"d\")\n , Symbol = require(\"es6-symbol\")\n , Iterator = require(\"./\");\n\nvar defineProperty = Object.defineProperty, ArrayIterator;\n\nArrayIterator = module.exports = function (arr, kind) {\n\tif (!(this instanceof ArrayIterator)) throw new TypeError(\"Constructor requires 'new'\");\n\tIterator.call(this, arr);\n\tif (!kind) kind = \"value\";\n\telse if (contains.call(kind, \"key+value\")) kind = \"key+value\";\n\telse if (contains.call(kind, \"key\")) kind = \"key\";\n\telse kind = \"value\";\n\tdefineProperty(this, \"__kind__\", d(\"\", kind));\n};\nif (setPrototypeOf) setPrototypeOf(ArrayIterator, Iterator);\n\n// Internal %ArrayIteratorPrototype% doesn't expose its constructor\ndelete ArrayIterator.prototype.constructor;\n\nArrayIterator.prototype = Object.create(Iterator.prototype, {\n\t_resolve: d(function (i) {\n\t\tif (this.__kind__ === \"value\") return this.__list__[i];\n\t\tif (this.__kind__ === \"key+value\") return [i, this.__list__[i]];\n\t\treturn i;\n\t})\n});\ndefineProperty(ArrayIterator.prototype, Symbol.toStringTag, d(\"c\", \"Array Iterator\"));\n","// Thanks @mathiasbynens\n// http://mathiasbynens.be/notes/javascript-unicode#iterating-over-symbols\n\n\"use strict\";\n\nvar setPrototypeOf = require(\"es5-ext/object/set-prototype-of\")\n , d = require(\"d\")\n , Symbol = require(\"es6-symbol\")\n , Iterator = require(\"./\");\n\nvar defineProperty = Object.defineProperty, StringIterator;\n\nStringIterator = module.exports = function (str) {\n\tif (!(this instanceof StringIterator)) throw new TypeError(\"Constructor requires 'new'\");\n\tstr = String(str);\n\tIterator.call(this, str);\n\tdefineProperty(this, \"__length__\", d(\"\", str.length));\n};\nif (setPrototypeOf) setPrototypeOf(StringIterator, Iterator);\n\n// Internal %ArrayIteratorPrototype% doesn't expose its constructor\ndelete StringIterator.prototype.constructor;\n\nStringIterator.prototype = Object.create(Iterator.prototype, {\n\t_next: d(function () {\n\t\tif (!this.__list__) return undefined;\n\t\tif (this.__nextIndex__ < this.__length__) return this.__nextIndex__++;\n\t\tthis._unBind();\n\t\treturn undefined;\n\t}),\n\t_resolve: d(function (i) {\n\t\tvar char = this.__list__[i], code;\n\t\tif (this.__nextIndex__ === this.__length__) return char;\n\t\tcode = char.charCodeAt(0);\n\t\tif (code >= 0xd800 && code <= 0xdbff) return char + this.__list__[this.__nextIndex__++];\n\t\treturn char;\n\t})\n});\ndefineProperty(StringIterator.prototype, Symbol.toStringTag, d(\"c\", \"String Iterator\"));\n","\"use strict\";\n\nvar isArguments = require(\"es5-ext/function/is-arguments\")\n , isString = require(\"es5-ext/string/is-string\")\n , ArrayIterator = require(\"./array\")\n , StringIterator = require(\"./string\")\n , iterable = require(\"./valid-iterable\")\n , iteratorSymbol = require(\"es6-symbol\").iterator;\n\nmodule.exports = function (obj) {\n\tif (typeof iterable(obj)[iteratorSymbol] === \"function\") return obj[iteratorSymbol]();\n\tif (isArguments(obj)) return new ArrayIterator(obj);\n\tif (isString(obj)) return new StringIterator(obj);\n\treturn new ArrayIterator(obj);\n};\n","\"use strict\";\n\nvar isArguments = require(\"es5-ext/function/is-arguments\")\n , callable = require(\"es5-ext/object/valid-callable\")\n , isString = require(\"es5-ext/string/is-string\")\n , get = require(\"./get\");\n\nvar isArray = Array.isArray, call = Function.prototype.call, some = Array.prototype.some;\n\nmodule.exports = function (iterable, cb /*, thisArg*/) {\n\tvar mode, thisArg = arguments[2], result, doBreak, broken, i, length, char, code;\n\tif (isArray(iterable) || isArguments(iterable)) mode = \"array\";\n\telse if (isString(iterable)) mode = \"string\";\n\telse iterable = get(iterable);\n\n\tcallable(cb);\n\tdoBreak = function () {\n\t\tbroken = true;\n\t};\n\tif (mode === \"array\") {\n\t\tsome.call(iterable, function (value) {\n\t\t\tcall.call(cb, thisArg, value, doBreak);\n\t\t\treturn broken;\n\t\t});\n\t\treturn;\n\t}\n\tif (mode === \"string\") {\n\t\tlength = iterable.length;\n\t\tfor (i = 0; i < length; ++i) {\n\t\t\tchar = iterable[i];\n\t\t\tif (i + 1 < length) {\n\t\t\t\tcode = char.charCodeAt(0);\n\t\t\t\tif (code >= 0xd800 && code <= 0xdbff) char += iterable[++i];\n\t\t\t}\n\t\t\tcall.call(cb, thisArg, char, doBreak);\n\t\t\tif (broken) break;\n\t\t}\n\t\treturn;\n\t}\n\tresult = iterable.next();\n\n\twhile (!result.done) {\n\t\tcall.call(cb, thisArg, result.value, doBreak);\n\t\tif (broken) return;\n\t\tresult = iterable.next();\n\t}\n};\n","'use strict';\n\nvar setPrototypeOf = require('es5-ext/object/set-prototype-of')\n , contains = require('es5-ext/string/#/contains')\n , d = require('d')\n , Iterator = require('es6-iterator')\n , toStringTagSymbol = require('es6-symbol').toStringTag\n\n , defineProperty = Object.defineProperty\n , SetIterator;\n\nSetIterator = module.exports = function (set, kind) {\n\tif (!(this instanceof SetIterator)) return new SetIterator(set, kind);\n\tIterator.call(this, set.__setData__, set);\n\tif (!kind) kind = 'value';\n\telse if (contains.call(kind, 'key+value')) kind = 'key+value';\n\telse kind = 'value';\n\tdefineProperty(this, '__kind__', d('', kind));\n};\nif (setPrototypeOf) setPrototypeOf(SetIterator, Iterator);\n\nSetIterator.prototype = Object.create(Iterator.prototype, {\n\tconstructor: d(SetIterator),\n\t_resolve: d(function (i) {\n\t\tif (this.__kind__ === 'value') return this.__list__[i];\n\t\treturn [this.__list__[i], this.__list__[i]];\n\t}),\n\ttoString: d(function () { return '[object Set Iterator]'; })\n});\ndefineProperty(SetIterator.prototype, toStringTagSymbol, d('c', 'Set Iterator'));\n","// Exports true if environment provides native `Set` implementation,\n// whatever that is.\n\n'use strict';\n\nmodule.exports = (function () {\n\tif (typeof Set === 'undefined') return false;\n\treturn (Object.prototype.toString.call(Set.prototype) === '[object Set]');\n}());\n","'use strict';\n\nvar clear = require('es5-ext/array/#/clear')\n , eIndexOf = require('es5-ext/array/#/e-index-of')\n , setPrototypeOf = require('es5-ext/object/set-prototype-of')\n , callable = require('es5-ext/object/valid-callable')\n , d = require('d')\n , ee = require('event-emitter')\n , Symbol = require('es6-symbol')\n , iterator = require('es6-iterator/valid-iterable')\n , forOf = require('es6-iterator/for-of')\n , Iterator = require('./lib/iterator')\n , isNative = require('./is-native-implemented')\n\n , call = Function.prototype.call\n , defineProperty = Object.defineProperty, getPrototypeOf = Object.getPrototypeOf\n , SetPoly, getValues, NativeSet;\n\nif (isNative) NativeSet = Set;\n\nmodule.exports = SetPoly = function Set(/*iterable*/) {\n\tvar iterable = arguments[0], self;\n\tif (!(this instanceof SetPoly)) throw new TypeError('Constructor requires \\'new\\'');\n\tif (isNative && setPrototypeOf) self = setPrototypeOf(new NativeSet(), getPrototypeOf(this));\n\telse self = this;\n\tif (iterable != null) iterator(iterable);\n\tdefineProperty(self, '__setData__', d('c', []));\n\tif (!iterable) return self;\n\tforOf(iterable, function (value) {\n\t\tif (eIndexOf.call(this, value) !== -1) return;\n\t\tthis.push(value);\n\t}, self.__setData__);\n\treturn self;\n};\n\nif (isNative) {\n\tif (setPrototypeOf) setPrototypeOf(SetPoly, NativeSet);\n\tSetPoly.prototype = Object.create(NativeSet.prototype, { constructor: d(SetPoly) });\n}\n\nee(Object.defineProperties(SetPoly.prototype, {\n\tadd: d(function (value) {\n\t\tif (this.has(value)) return this;\n\t\tthis.emit('_add', this.__setData__.push(value) - 1, value);\n\t\treturn this;\n\t}),\n\tclear: d(function () {\n\t\tif (!this.__setData__.length) return;\n\t\tclear.call(this.__setData__);\n\t\tthis.emit('_clear');\n\t}),\n\tdelete: d(function (value) {\n\t\tvar index = eIndexOf.call(this.__setData__, value);\n\t\tif (index === -1) return false;\n\t\tthis.__setData__.splice(index, 1);\n\t\tthis.emit('_delete', index, value);\n\t\treturn true;\n\t}),\n\tentries: d(function () { return new Iterator(this, 'key+value'); }),\n\tforEach: d(function (cb/*, thisArg*/) {\n\t\tvar thisArg = arguments[1], iterator, result, value;\n\t\tcallable(cb);\n\t\titerator = this.values();\n\t\tresult = iterator._next();\n\t\twhile (result !== undefined) {\n\t\t\tvalue = iterator._resolve(result);\n\t\t\tcall.call(cb, thisArg, value, value, this);\n\t\t\tresult = iterator._next();\n\t\t}\n\t}),\n\thas: d(function (value) {\n\t\treturn (eIndexOf.call(this.__setData__, value) !== -1);\n\t}),\n\tkeys: d(getValues = function () { return this.values(); }),\n\tsize: d.gs(function () { return this.__setData__.length; }),\n\tvalues: d(function () { return new Iterator(this); }),\n\ttoString: d(function () { return '[object Set]'; })\n}));\ndefineProperty(SetPoly.prototype, Symbol.iterator, d(getValues));\ndefineProperty(SetPoly.prototype, Symbol.toStringTag, d('c', 'Set'));\n","'use strict';\n\nmodule.exports = require('./is-implemented')() ? Set : require('./polyfill');\n","'use strict';\n\nmodule.exports = function () {\n\tvar map, iterator, result;\n\tif (typeof Map !== 'function') return false;\n\ttry {\n\t\t// WebKit doesn't support arguments and crashes\n\t\tmap = new Map([['raz', 'one'], ['dwa', 'two'], ['trzy', 'three']]);\n\t} catch (e) {\n\t\treturn false;\n\t}\n\tif (String(map) !== '[object Map]') return false;\n\tif (map.size !== 3) return false;\n\tif (typeof map.clear !== 'function') return false;\n\tif (typeof map.delete !== 'function') return false;\n\tif (typeof map.entries !== 'function') return false;\n\tif (typeof map.forEach !== 'function') return false;\n\tif (typeof map.get !== 'function') return false;\n\tif (typeof map.has !== 'function') return false;\n\tif (typeof map.keys !== 'function') return false;\n\tif (typeof map.set !== 'function') return false;\n\tif (typeof map.values !== 'function') return false;\n\n\titerator = map.entries();\n\tresult = iterator.next();\n\tif (result.done !== false) return false;\n\tif (!result.value) return false;\n\tif (result.value[0] !== 'raz') return false;\n\tif (result.value[1] !== 'one') return false;\n\n\treturn true;\n};\n","\"use strict\";\n\nvar forEach = Array.prototype.forEach, create = Object.create;\n\n// eslint-disable-next-line no-unused-vars\nmodule.exports = function (arg/*, …args*/) {\n\tvar set = create(null);\n\tforEach.call(arguments, function (name) { set[name] = true; });\n\treturn set;\n};\n","'use strict';\n\nmodule.exports = require('es5-ext/object/primitive-set')('key',\n\t'value', 'key+value');\n","'use strict';\n\nvar setPrototypeOf = require('es5-ext/object/set-prototype-of')\n , d = require('d')\n , Iterator = require('es6-iterator')\n , toStringTagSymbol = require('es6-symbol').toStringTag\n , kinds = require('./iterator-kinds')\n\n , defineProperties = Object.defineProperties\n , unBind = Iterator.prototype._unBind\n , MapIterator;\n\nMapIterator = module.exports = function (map, kind) {\n\tif (!(this instanceof MapIterator)) return new MapIterator(map, kind);\n\tIterator.call(this, map.__mapKeysData__, map);\n\tif (!kind || !kinds[kind]) kind = 'key+value';\n\tdefineProperties(this, {\n\t\t__kind__: d('', kind),\n\t\t__values__: d('w', map.__mapValuesData__)\n\t});\n};\nif (setPrototypeOf) setPrototypeOf(MapIterator, Iterator);\n\nMapIterator.prototype = Object.create(Iterator.prototype, {\n\tconstructor: d(MapIterator),\n\t_resolve: d(function (i) {\n\t\tif (this.__kind__ === 'value') return this.__values__[i];\n\t\tif (this.__kind__ === 'key') return this.__list__[i];\n\t\treturn [this.__list__[i], this.__values__[i]];\n\t}),\n\t_unBind: d(function () {\n\t\tthis.__values__ = null;\n\t\tunBind.call(this);\n\t}),\n\ttoString: d(function () { return '[object Map Iterator]'; })\n});\nObject.defineProperty(MapIterator.prototype, toStringTagSymbol,\n\td('c', 'Map Iterator'));\n","// Exports true if environment provides native `Map` implementation,\n// whatever that is.\n\n'use strict';\n\nmodule.exports = (function () {\n\tif (typeof Map === 'undefined') return false;\n\treturn (Object.prototype.toString.call(new Map()) === '[object Map]');\n}());\n","'use strict';\n\nvar clear = require('es5-ext/array/#/clear')\n , eIndexOf = require('es5-ext/array/#/e-index-of')\n , setPrototypeOf = require('es5-ext/object/set-prototype-of')\n , callable = require('es5-ext/object/valid-callable')\n , validValue = require('es5-ext/object/valid-value')\n , d = require('d')\n , ee = require('event-emitter')\n , Symbol = require('es6-symbol')\n , iterator = require('es6-iterator/valid-iterable')\n , forOf = require('es6-iterator/for-of')\n , Iterator = require('./lib/iterator')\n , isNative = require('./is-native-implemented')\n\n , call = Function.prototype.call\n , defineProperties = Object.defineProperties, getPrototypeOf = Object.getPrototypeOf\n , MapPoly;\n\nmodule.exports = MapPoly = function (/*iterable*/) {\n\tvar iterable = arguments[0], keys, values, self;\n\tif (!(this instanceof MapPoly)) throw new TypeError('Constructor requires \\'new\\'');\n\tif (isNative && setPrototypeOf && (Map !== MapPoly)) {\n\t\tself = setPrototypeOf(new Map(), getPrototypeOf(this));\n\t} else {\n\t\tself = this;\n\t}\n\tif (iterable != null) iterator(iterable);\n\tdefineProperties(self, {\n\t\t__mapKeysData__: d('c', keys = []),\n\t\t__mapValuesData__: d('c', values = [])\n\t});\n\tif (!iterable) return self;\n\tforOf(iterable, function (value) {\n\t\tvar key = validValue(value)[0];\n\t\tvalue = value[1];\n\t\tif (eIndexOf.call(keys, key) !== -1) return;\n\t\tkeys.push(key);\n\t\tvalues.push(value);\n\t}, self);\n\treturn self;\n};\n\nif (isNative) {\n\tif (setPrototypeOf) setPrototypeOf(MapPoly, Map);\n\tMapPoly.prototype = Object.create(Map.prototype, {\n\t\tconstructor: d(MapPoly)\n\t});\n}\n\nee(defineProperties(MapPoly.prototype, {\n\tclear: d(function () {\n\t\tif (!this.__mapKeysData__.length) return;\n\t\tclear.call(this.__mapKeysData__);\n\t\tclear.call(this.__mapValuesData__);\n\t\tthis.emit('_clear');\n\t}),\n\tdelete: d(function (key) {\n\t\tvar index = eIndexOf.call(this.__mapKeysData__, key);\n\t\tif (index === -1) return false;\n\t\tthis.__mapKeysData__.splice(index, 1);\n\t\tthis.__mapValuesData__.splice(index, 1);\n\t\tthis.emit('_delete', index, key);\n\t\treturn true;\n\t}),\n\tentries: d(function () { return new Iterator(this, 'key+value'); }),\n\tforEach: d(function (cb/*, thisArg*/) {\n\t\tvar thisArg = arguments[1], iterator, result;\n\t\tcallable(cb);\n\t\titerator = this.entries();\n\t\tresult = iterator._next();\n\t\twhile (result !== undefined) {\n\t\t\tcall.call(cb, thisArg, this.__mapValuesData__[result],\n\t\t\t\tthis.__mapKeysData__[result], this);\n\t\t\tresult = iterator._next();\n\t\t}\n\t}),\n\tget: d(function (key) {\n\t\tvar index = eIndexOf.call(this.__mapKeysData__, key);\n\t\tif (index === -1) return;\n\t\treturn this.__mapValuesData__[index];\n\t}),\n\thas: d(function (key) {\n\t\treturn (eIndexOf.call(this.__mapKeysData__, key) !== -1);\n\t}),\n\tkeys: d(function () { return new Iterator(this, 'key'); }),\n\tset: d(function (key, value) {\n\t\tvar index = eIndexOf.call(this.__mapKeysData__, key), emit;\n\t\tif (index === -1) {\n\t\t\tindex = this.__mapKeysData__.push(key) - 1;\n\t\t\temit = true;\n\t\t}\n\t\tthis.__mapValuesData__[index] = value;\n\t\tif (emit) this.emit('_add', index, key);\n\t\treturn this;\n\t}),\n\tsize: d.gs(function () { return this.__mapKeysData__.length; }),\n\tvalues: d(function () { return new Iterator(this, 'value'); }),\n\ttoString: d(function () { return '[object Map]'; })\n}));\nObject.defineProperty(MapPoly.prototype, Symbol.iterator, d(function () {\n\treturn this.entries();\n}));\nObject.defineProperty(MapPoly.prototype, Symbol.toStringTag, d('c', 'Map'));\n","'use strict';\n\nmodule.exports = require('./is-implemented')() ? Map : require('./polyfill');\n","'use strict';\n\nvar toStr = Object.prototype.toString;\n\nmodule.exports = function isArguments(value) {\n\tvar str = toStr.call(value);\n\tvar isArgs = str === '[object Arguments]';\n\tif (!isArgs) {\n\t\tisArgs = str !== '[object Array]' &&\n\t\t\tvalue !== null &&\n\t\t\ttypeof value === 'object' &&\n\t\t\ttypeof value.length === 'number' &&\n\t\t\tvalue.length >= 0 &&\n\t\t\ttoStr.call(value.callee) === '[object Function]';\n\t}\n\treturn isArgs;\n};\n","'use strict';\n\nvar keysShim;\nif (!Object.keys) {\n\t// modified from https://github.com/es-shims/es5-shim\n\tvar has = Object.prototype.hasOwnProperty;\n\tvar toStr = Object.prototype.toString;\n\tvar isArgs = require('./isArguments'); // eslint-disable-line global-require\n\tvar isEnumerable = Object.prototype.propertyIsEnumerable;\n\tvar hasDontEnumBug = !isEnumerable.call({ toString: null }, 'toString');\n\tvar hasProtoEnumBug = isEnumerable.call(function () {}, 'prototype');\n\tvar dontEnums = [\n\t\t'toString',\n\t\t'toLocaleString',\n\t\t'valueOf',\n\t\t'hasOwnProperty',\n\t\t'isPrototypeOf',\n\t\t'propertyIsEnumerable',\n\t\t'constructor'\n\t];\n\tvar equalsConstructorPrototype = function (o) {\n\t\tvar ctor = o.constructor;\n\t\treturn ctor && ctor.prototype === o;\n\t};\n\tvar excludedKeys = {\n\t\t$applicationCache: true,\n\t\t$console: true,\n\t\t$external: true,\n\t\t$frame: true,\n\t\t$frameElement: true,\n\t\t$frames: true,\n\t\t$innerHeight: true,\n\t\t$innerWidth: true,\n\t\t$onmozfullscreenchange: true,\n\t\t$onmozfullscreenerror: true,\n\t\t$outerHeight: true,\n\t\t$outerWidth: true,\n\t\t$pageXOffset: true,\n\t\t$pageYOffset: true,\n\t\t$parent: true,\n\t\t$scrollLeft: true,\n\t\t$scrollTop: true,\n\t\t$scrollX: true,\n\t\t$scrollY: true,\n\t\t$self: true,\n\t\t$webkitIndexedDB: true,\n\t\t$webkitStorageInfo: true,\n\t\t$window: true\n\t};\n\tvar hasAutomationEqualityBug = (function () {\n\t\t/* global window */\n\t\tif (typeof window === 'undefined') { return false; }\n\t\tfor (var k in window) {\n\t\t\ttry {\n\t\t\t\tif (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tequalsConstructorPrototype(window[k]);\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}());\n\tvar equalsConstructorPrototypeIfNotBuggy = function (o) {\n\t\t/* global window */\n\t\tif (typeof window === 'undefined' || !hasAutomationEqualityBug) {\n\t\t\treturn equalsConstructorPrototype(o);\n\t\t}\n\t\ttry {\n\t\t\treturn equalsConstructorPrototype(o);\n\t\t} catch (e) {\n\t\t\treturn false;\n\t\t}\n\t};\n\n\tkeysShim = function keys(object) {\n\t\tvar isObject = object !== null && typeof object === 'object';\n\t\tvar isFunction = toStr.call(object) === '[object Function]';\n\t\tvar isArguments = isArgs(object);\n\t\tvar isString = isObject && toStr.call(object) === '[object String]';\n\t\tvar theKeys = [];\n\n\t\tif (!isObject && !isFunction && !isArguments) {\n\t\t\tthrow new TypeError('Object.keys called on a non-object');\n\t\t}\n\n\t\tvar skipProto = hasProtoEnumBug && isFunction;\n\t\tif (isString && object.length > 0 && !has.call(object, 0)) {\n\t\t\tfor (var i = 0; i < object.length; ++i) {\n\t\t\t\ttheKeys.push(String(i));\n\t\t\t}\n\t\t}\n\n\t\tif (isArguments && object.length > 0) {\n\t\t\tfor (var j = 0; j < object.length; ++j) {\n\t\t\t\ttheKeys.push(String(j));\n\t\t\t}\n\t\t} else {\n\t\t\tfor (var name in object) {\n\t\t\t\tif (!(skipProto && name === 'prototype') && has.call(object, name)) {\n\t\t\t\t\ttheKeys.push(String(name));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (hasDontEnumBug) {\n\t\t\tvar skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);\n\n\t\t\tfor (var k = 0; k < dontEnums.length; ++k) {\n\t\t\t\tif (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) {\n\t\t\t\t\ttheKeys.push(dontEnums[k]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn theKeys;\n\t};\n}\nmodule.exports = keysShim;\n","'use strict';\n\nvar slice = Array.prototype.slice;\nvar isArgs = require('./isArguments');\n\nvar origKeys = Object.keys;\nvar keysShim = origKeys ? function keys(o) { return origKeys(o); } : require('./implementation');\n\nvar originalKeys = Object.keys;\n\nkeysShim.shim = function shimObjectKeys() {\n\tif (Object.keys) {\n\t\tvar keysWorksWithArguments = (function () {\n\t\t\t// Safari 5.0 bug\n\t\t\tvar args = Object.keys(arguments);\n\t\t\treturn args && args.length === arguments.length;\n\t\t}(1, 2));\n\t\tif (!keysWorksWithArguments) {\n\t\t\tObject.keys = function keys(object) { // eslint-disable-line func-name-matching\n\t\t\t\tif (isArgs(object)) {\n\t\t\t\t\treturn originalKeys(slice.call(object));\n\t\t\t\t}\n\t\t\t\treturn originalKeys(object);\n\t\t\t};\n\t\t}\n\t} else {\n\t\tObject.keys = keysShim;\n\t}\n\treturn Object.keys || keysShim;\n};\n\nmodule.exports = keysShim;\n","'use strict';\n\nvar keys = require('object-keys');\nvar hasSymbols = typeof Symbol === 'function' && typeof Symbol('foo') === 'symbol';\n\nvar toStr = Object.prototype.toString;\nvar concat = Array.prototype.concat;\nvar origDefineProperty = Object.defineProperty;\n\nvar isFunction = function (fn) {\n\treturn typeof fn === 'function' && toStr.call(fn) === '[object Function]';\n};\n\nvar arePropertyDescriptorsSupported = function () {\n\tvar obj = {};\n\ttry {\n\t\torigDefineProperty(obj, 'x', { enumerable: false, value: obj });\n\t\t// eslint-disable-next-line no-unused-vars, no-restricted-syntax\n\t\tfor (var _ in obj) { // jscs:ignore disallowUnusedVariables\n\t\t\treturn false;\n\t\t}\n\t\treturn obj.x === obj;\n\t} catch (e) { /* this is IE 8. */\n\t\treturn false;\n\t}\n};\nvar supportsDescriptors = origDefineProperty && arePropertyDescriptorsSupported();\n\nvar defineProperty = function (object, name, value, predicate) {\n\tif (name in object && (!isFunction(predicate) || !predicate())) {\n\t\treturn;\n\t}\n\tif (supportsDescriptors) {\n\t\torigDefineProperty(object, name, {\n\t\t\tconfigurable: true,\n\t\t\tenumerable: false,\n\t\t\tvalue: value,\n\t\t\twritable: true\n\t\t});\n\t} else {\n\t\tobject[name] = value;\n\t}\n};\n\nvar defineProperties = function (object, map) {\n\tvar predicates = arguments.length > 2 ? arguments[2] : {};\n\tvar props = keys(map);\n\tif (hasSymbols) {\n\t\tprops = concat.call(props, Object.getOwnPropertySymbols(map));\n\t}\n\tfor (var i = 0; i < props.length; i += 1) {\n\t\tdefineProperty(object, props[i], map[props[i]], predicates[props[i]]);\n\t}\n};\n\ndefineProperties.supportsDescriptors = !!supportsDescriptors;\n\nmodule.exports = defineProperties;\n","'use strict';\n\n/* eslint no-invalid-this: 1 */\n\nvar ERROR_MESSAGE = 'Function.prototype.bind called on incompatible ';\nvar slice = Array.prototype.slice;\nvar toStr = Object.prototype.toString;\nvar funcType = '[object Function]';\n\nmodule.exports = function bind(that) {\n var target = this;\n if (typeof target !== 'function' || toStr.call(target) !== funcType) {\n throw new TypeError(ERROR_MESSAGE + target);\n }\n var args = slice.call(arguments, 1);\n\n var bound;\n var binder = function () {\n if (this instanceof bound) {\n var result = target.apply(\n this,\n args.concat(slice.call(arguments))\n );\n if (Object(result) === result) {\n return result;\n }\n return this;\n } else {\n return target.apply(\n that,\n args.concat(slice.call(arguments))\n );\n }\n };\n\n var boundLength = Math.max(0, target.length - args.length);\n var boundArgs = [];\n for (var i = 0; i < boundLength; i++) {\n boundArgs.push('$' + i);\n }\n\n bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this,arguments); }')(binder);\n\n if (target.prototype) {\n var Empty = function Empty() {};\n Empty.prototype = target.prototype;\n bound.prototype = new Empty();\n Empty.prototype = null;\n }\n\n return bound;\n};\n","'use strict';\n\nvar implementation = require('./implementation');\n\nmodule.exports = Function.prototype.bind || implementation;\n","'use strict';\n\nvar bind = require('function-bind');\n\nmodule.exports = bind.call(Function.call, Object.prototype.hasOwnProperty);\n","module.exports = function isPrimitive(value) {\n\treturn value === null || (typeof value !== 'function' && typeof value !== 'object');\n};\n","'use strict';\n\nvar fnToStr = Function.prototype.toString;\n\nvar constructorRegex = /^\\s*class\\b/;\nvar isES6ClassFn = function isES6ClassFunction(value) {\n\ttry {\n\t\tvar fnStr = fnToStr.call(value);\n\t\treturn constructorRegex.test(fnStr);\n\t} catch (e) {\n\t\treturn false; // not a function\n\t}\n};\n\nvar tryFunctionObject = function tryFunctionToStr(value) {\n\ttry {\n\t\tif (isES6ClassFn(value)) { return false; }\n\t\tfnToStr.call(value);\n\t\treturn true;\n\t} catch (e) {\n\t\treturn false;\n\t}\n};\nvar toStr = Object.prototype.toString;\nvar fnClass = '[object Function]';\nvar genClass = '[object GeneratorFunction]';\nvar hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';\n\nmodule.exports = function isCallable(value) {\n\tif (!value) { return false; }\n\tif (typeof value !== 'function' && typeof value !== 'object') { return false; }\n\tif (typeof value === 'function' && !value.prototype) { return true; }\n\tif (hasToStringTag) { return tryFunctionObject(value); }\n\tif (isES6ClassFn(value)) { return false; }\n\tvar strClass = toStr.call(value);\n\treturn strClass === fnClass || strClass === genClass;\n};\n","'use strict';\n\nvar getDay = Date.prototype.getDay;\nvar tryDateObject = function tryDateObject(value) {\n\ttry {\n\t\tgetDay.call(value);\n\t\treturn true;\n\t} catch (e) {\n\t\treturn false;\n\t}\n};\n\nvar toStr = Object.prototype.toString;\nvar dateClass = '[object Date]';\nvar hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';\n\nmodule.exports = function isDateObject(value) {\n\tif (typeof value !== 'object' || value === null) { return false; }\n\treturn hasToStringTag ? tryDateObject(value) : toStr.call(value) === dateClass;\n};\n","'use strict';\n\n/* eslint complexity: [2, 17], max-statements: [2, 33] */\nmodule.exports = function hasSymbols() {\n\tif (typeof Symbol !== 'function' || typeof Object.getOwnPropertySymbols !== 'function') { return false; }\n\tif (typeof Symbol.iterator === 'symbol') { return true; }\n\n\tvar obj = {};\n\tvar sym = Symbol('test');\n\tvar symObj = Object(sym);\n\tif (typeof sym === 'string') { return false; }\n\n\tif (Object.prototype.toString.call(sym) !== '[object Symbol]') { return false; }\n\tif (Object.prototype.toString.call(symObj) !== '[object Symbol]') { return false; }\n\n\t// temp disabled per https://github.com/ljharb/object.assign/issues/17\n\t// if (sym instanceof Symbol) { return false; }\n\t// temp disabled per https://github.com/WebReflection/get-own-property-symbols/issues/4\n\t// if (!(symObj instanceof Symbol)) { return false; }\n\n\t// if (typeof Symbol.prototype.toString !== 'function') { return false; }\n\t// if (String(sym) !== Symbol.prototype.toString.call(sym)) { return false; }\n\n\tvar symVal = 42;\n\tobj[sym] = symVal;\n\tfor (sym in obj) { return false; } // eslint-disable-line no-restricted-syntax\n\tif (typeof Object.keys === 'function' && Object.keys(obj).length !== 0) { return false; }\n\n\tif (typeof Object.getOwnPropertyNames === 'function' && Object.getOwnPropertyNames(obj).length !== 0) { return false; }\n\n\tvar syms = Object.getOwnPropertySymbols(obj);\n\tif (syms.length !== 1 || syms[0] !== sym) { return false; }\n\n\tif (!Object.prototype.propertyIsEnumerable.call(obj, sym)) { return false; }\n\n\tif (typeof Object.getOwnPropertyDescriptor === 'function') {\n\t\tvar descriptor = Object.getOwnPropertyDescriptor(obj, sym);\n\t\tif (descriptor.value !== symVal || descriptor.enumerable !== true) { return false; }\n\t}\n\n\treturn true;\n};\n","'use strict';\n\nvar origSymbol = global.Symbol;\nvar hasSymbolSham = require('./shams');\n\nmodule.exports = function hasNativeSymbols() {\n\tif (typeof origSymbol !== 'function') { return false; }\n\tif (typeof Symbol !== 'function') { return false; }\n\tif (typeof origSymbol('foo') !== 'symbol') { return false; }\n\tif (typeof Symbol('bar') !== 'symbol') { return false; }\n\n\treturn hasSymbolSham();\n};\n","'use strict';\n\nvar toStr = Object.prototype.toString;\nvar hasSymbols = require('has-symbols')();\n\nif (hasSymbols) {\n\tvar symToStr = Symbol.prototype.toString;\n\tvar symStringRegex = /^Symbol\\(.*\\)$/;\n\tvar isSymbolObject = function isRealSymbolObject(value) {\n\t\tif (typeof value.valueOf() !== 'symbol') {\n\t\t\treturn false;\n\t\t}\n\t\treturn symStringRegex.test(symToStr.call(value));\n\t};\n\n\tmodule.exports = function isSymbol(value) {\n\t\tif (typeof value === 'symbol') {\n\t\t\treturn true;\n\t\t}\n\t\tif (toStr.call(value) !== '[object Symbol]') {\n\t\t\treturn false;\n\t\t}\n\t\ttry {\n\t\t\treturn isSymbolObject(value);\n\t\t} catch (e) {\n\t\t\treturn false;\n\t\t}\n\t};\n} else {\n\n\tmodule.exports = function isSymbol(value) {\n\t\t// this environment does not support Symbols.\n\t\treturn false && value;\n\t};\n}\n","'use strict';\n\nvar hasSymbols = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol';\n\nvar isPrimitive = require('./helpers/isPrimitive');\nvar isCallable = require('is-callable');\nvar isDate = require('is-date-object');\nvar isSymbol = require('is-symbol');\n\nvar ordinaryToPrimitive = function OrdinaryToPrimitive(O, hint) {\n\tif (typeof O === 'undefined' || O === null) {\n\t\tthrow new TypeError('Cannot call method on ' + O);\n\t}\n\tif (typeof hint !== 'string' || (hint !== 'number' && hint !== 'string')) {\n\t\tthrow new TypeError('hint must be \"string\" or \"number\"');\n\t}\n\tvar methodNames = hint === 'string' ? ['toString', 'valueOf'] : ['valueOf', 'toString'];\n\tvar method, result, i;\n\tfor (i = 0; i < methodNames.length; ++i) {\n\t\tmethod = O[methodNames[i]];\n\t\tif (isCallable(method)) {\n\t\t\tresult = method.call(O);\n\t\t\tif (isPrimitive(result)) {\n\t\t\t\treturn result;\n\t\t\t}\n\t\t}\n\t}\n\tthrow new TypeError('No default value');\n};\n\nvar GetMethod = function GetMethod(O, P) {\n\tvar func = O[P];\n\tif (func !== null && typeof func !== 'undefined') {\n\t\tif (!isCallable(func)) {\n\t\t\tthrow new TypeError(func + ' returned for property ' + P + ' of object ' + O + ' is not a function');\n\t\t}\n\t\treturn func;\n\t}\n\treturn void 0;\n};\n\n// http://www.ecma-international.org/ecma-262/6.0/#sec-toprimitive\nmodule.exports = function ToPrimitive(input) {\n\tif (isPrimitive(input)) {\n\t\treturn input;\n\t}\n\tvar hint = 'default';\n\tif (arguments.length > 1) {\n\t\tif (arguments[1] === String) {\n\t\t\thint = 'string';\n\t\t} else if (arguments[1] === Number) {\n\t\t\thint = 'number';\n\t\t}\n\t}\n\n\tvar exoticToPrim;\n\tif (hasSymbols) {\n\t\tif (Symbol.toPrimitive) {\n\t\t\texoticToPrim = GetMethod(input, Symbol.toPrimitive);\n\t\t} else if (isSymbol(input)) {\n\t\t\texoticToPrim = Symbol.prototype.valueOf;\n\t\t}\n\t}\n\tif (typeof exoticToPrim !== 'undefined') {\n\t\tvar result = exoticToPrim.call(input, hint);\n\t\tif (isPrimitive(result)) {\n\t\t\treturn result;\n\t\t}\n\t\tthrow new TypeError('unable to convert exotic object to primitive');\n\t}\n\tif (hint === 'default' && (isDate(input) || isSymbol(input))) {\n\t\thint = 'string';\n\t}\n\treturn ordinaryToPrimitive(input, hint === 'default' ? 'number' : hint);\n};\n","'use strict';\n\nmodule.exports = require('./es2015');\n","var hasMap = typeof Map === 'function' && Map.prototype;\nvar mapSizeDescriptor = Object.getOwnPropertyDescriptor && hasMap ? Object.getOwnPropertyDescriptor(Map.prototype, 'size') : null;\nvar mapSize = hasMap && mapSizeDescriptor && typeof mapSizeDescriptor.get === 'function' ? mapSizeDescriptor.get : null;\nvar mapForEach = hasMap && Map.prototype.forEach;\nvar hasSet = typeof Set === 'function' && Set.prototype;\nvar setSizeDescriptor = Object.getOwnPropertyDescriptor && hasSet ? Object.getOwnPropertyDescriptor(Set.prototype, 'size') : null;\nvar setSize = hasSet && setSizeDescriptor && typeof setSizeDescriptor.get === 'function' ? setSizeDescriptor.get : null;\nvar setForEach = hasSet && Set.prototype.forEach;\nvar booleanValueOf = Boolean.prototype.valueOf;\nvar objectToString = Object.prototype.toString;\n\nmodule.exports = function inspect_ (obj, opts, depth, seen) {\n if (typeof obj === 'undefined') {\n return 'undefined';\n }\n if (obj === null) {\n return 'null';\n }\n if (typeof obj === 'boolean') {\n return obj ? 'true' : 'false';\n }\n if (typeof obj === 'string') {\n return inspectString(obj);\n }\n if (typeof obj === 'number') {\n if (obj === 0) {\n return Infinity / obj > 0 ? '0' : '-0';\n }\n return String(obj);\n }\n\n if (!opts) opts = {};\n\n var maxDepth = typeof opts.depth === 'undefined' ? 5 : opts.depth;\n if (typeof depth === 'undefined') depth = 0;\n if (depth >= maxDepth && maxDepth > 0 && typeof obj === 'object') {\n return '[Object]';\n }\n\n if (typeof seen === 'undefined') seen = [];\n else if (indexOf(seen, obj) >= 0) {\n return '[Circular]';\n }\n\n function inspect (value, from) {\n if (from) {\n seen = seen.slice();\n seen.push(from);\n }\n return inspect_(value, opts, depth + 1, seen);\n }\n\n if (typeof obj === 'function') {\n var name = nameOf(obj);\n return '[Function' + (name ? ': ' + name : '') + ']';\n }\n if (isSymbol(obj)) {\n var symString = Symbol.prototype.toString.call(obj);\n return typeof obj === 'object' ? markBoxed(symString) : symString;\n }\n if (isElement(obj)) {\n var s = '<' + String(obj.nodeName).toLowerCase();\n var attrs = obj.attributes || [];\n for (var i = 0; i < attrs.length; i++) {\n s += ' ' + attrs[i].name + '=\"' + quote(attrs[i].value) + '\"';\n }\n s += '>';\n if (obj.childNodes && obj.childNodes.length) s += '...';\n s += '' + String(obj.nodeName).toLowerCase() + '>';\n return s;\n }\n if (isArray(obj)) {\n if (obj.length === 0) return '[]';\n return '[ ' + arrObjKeys(obj, inspect).join(', ') + ' ]';\n }\n if (isError(obj)) {\n var parts = arrObjKeys(obj, inspect);\n if (parts.length === 0) return '[' + String(obj) + ']';\n return '{ [' + String(obj) + '] ' + parts.join(', ') + ' }';\n }\n if (typeof obj === 'object' && typeof obj.inspect === 'function') {\n return obj.inspect();\n }\n if (isMap(obj)) {\n var parts = [];\n mapForEach.call(obj, function (value, key) {\n parts.push(inspect(key, obj) + ' => ' + inspect(value, obj));\n });\n return collectionOf('Map', mapSize.call(obj), parts);\n }\n if (isSet(obj)) {\n var parts = [];\n setForEach.call(obj, function (value ) {\n parts.push(inspect(value, obj));\n });\n return collectionOf('Set', setSize.call(obj), parts);\n }\n if (isNumber(obj)) {\n return markBoxed(Number(obj));\n }\n if (isBoolean(obj)) {\n return markBoxed(booleanValueOf.call(obj));\n }\n if (isString(obj)) {\n return markBoxed(inspect(String(obj)));\n }\n if (!isDate(obj) && !isRegExp(obj)) {\n var xs = arrObjKeys(obj, inspect);\n if (xs.length === 0) return '{}';\n return '{ ' + xs.join(', ') + ' }';\n }\n return String(obj);\n};\n\nfunction quote (s) {\n return String(s).replace(/\"/g, '"');\n}\n\nfunction isArray (obj) { return toStr(obj) === '[object Array]' }\nfunction isDate (obj) { return toStr(obj) === '[object Date]' }\nfunction isRegExp (obj) { return toStr(obj) === '[object RegExp]' }\nfunction isError (obj) { return toStr(obj) === '[object Error]' }\nfunction isSymbol (obj) { return toStr(obj) === '[object Symbol]' }\nfunction isString (obj) { return toStr(obj) === '[object String]' }\nfunction isNumber (obj) { return toStr(obj) === '[object Number]' }\nfunction isBoolean (obj) { return toStr(obj) === '[object Boolean]' }\n\nvar hasOwn = Object.prototype.hasOwnProperty || function (key) { return key in this; };\nfunction has (obj, key) {\n return hasOwn.call(obj, key);\n}\n\nfunction toStr (obj) {\n return objectToString.call(obj);\n}\n\nfunction nameOf (f) {\n if (f.name) return f.name;\n var m = String(f).match(/^function\\s*([\\w$]+)/);\n if (m) return m[1];\n}\n\nfunction indexOf (xs, x) {\n if (xs.indexOf) return xs.indexOf(x);\n for (var i = 0, l = xs.length; i < l; i++) {\n if (xs[i] === x) return i;\n }\n return -1;\n}\n\nfunction isMap (x) {\n if (!mapSize) {\n return false;\n }\n try {\n mapSize.call(x);\n try {\n setSize.call(x);\n } catch (s) {\n return true;\n }\n return x instanceof Map; // core-js workaround, pre-v2.5.0\n } catch (e) {}\n return false;\n}\n\nfunction isSet (x) {\n if (!setSize) {\n return false;\n }\n try {\n setSize.call(x);\n try {\n mapSize.call(x);\n } catch (m) {\n return true;\n }\n return x instanceof Set; // core-js workaround, pre-v2.5.0\n } catch (e) {}\n return false;\n}\n\nfunction isElement (x) {\n if (!x || typeof x !== 'object') return false;\n if (typeof HTMLElement !== 'undefined' && x instanceof HTMLElement) {\n return true;\n }\n return typeof x.nodeName === 'string'\n && typeof x.getAttribute === 'function'\n ;\n}\n\nfunction inspectString (str) {\n var s = str.replace(/(['\\\\])/g, '\\\\$1').replace(/[\\x00-\\x1f]/g, lowbyte);\n return \"'\" + s + \"'\";\n}\n\nfunction lowbyte (c) {\n var n = c.charCodeAt(0);\n var x = { 8: 'b', 9: 't', 10: 'n', 12: 'f', 13: 'r' }[n];\n if (x) return '\\\\' + x;\n return '\\\\x' + (n < 0x10 ? '0' : '') + n.toString(16);\n}\n\nfunction markBoxed (str) {\n return 'Object(' + str + ')';\n}\n\nfunction collectionOf (type, size, entries) {\n return type + ' (' + size + ') {' + entries.join(', ') + '}';\n}\n\nfunction arrObjKeys (obj, inspect) {\n var isArr = isArray(obj);\n var xs = [];\n if (isArr) {\n xs.length = obj.length;\n for (var i = 0; i < obj.length; i++) {\n xs[i] = has(obj, i) ? inspect(obj[i], obj) : '';\n }\n }\n for (var key in obj) {\n if (!has(obj, key)) continue;\n if (isArr && String(Number(key)) === key && key < obj.length) continue;\n if (/[^\\w$]/.test(key)) {\n xs.push(inspect(key, obj) + ': ' + inspect(obj[key], obj));\n } else {\n xs.push(key + ': ' + inspect(obj[key], obj));\n }\n }\n return xs;\n}\n","'use strict';\n\n/* globals\n\tAtomics,\n\tSharedArrayBuffer,\n*/\n\nvar undefined; // eslint-disable-line no-shadow-restricted-names\n\nvar $TypeError = TypeError;\n\nvar ThrowTypeError = Object.getOwnPropertyDescriptor\n\t? (function () { return Object.getOwnPropertyDescriptor(arguments, 'callee').get; }())\n\t: function () { throw new $TypeError(); };\n\nvar hasSymbols = require('has-symbols')();\n\nvar getProto = Object.getPrototypeOf || function (x) { return x.__proto__; }; // eslint-disable-line no-proto\n\nvar generator; // = function * () {};\nvar generatorFunction = generator ? getProto(generator) : undefined;\nvar asyncFn; // async function() {};\nvar asyncFunction = asyncFn ? asyncFn.constructor : undefined;\nvar asyncGen; // async function * () {};\nvar asyncGenFunction = asyncGen ? getProto(asyncGen) : undefined;\nvar asyncGenIterator = asyncGen ? asyncGen() : undefined;\n\nvar TypedArray = typeof Uint8Array === 'undefined' ? undefined : getProto(Uint8Array);\n\nvar INTRINSICS = {\n\t'$ %Array%': Array,\n\t'$ %ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined : ArrayBuffer,\n\t'$ %ArrayBufferPrototype%': typeof ArrayBuffer === 'undefined' ? undefined : ArrayBuffer.prototype,\n\t'$ %ArrayIteratorPrototype%': hasSymbols ? getProto([][Symbol.iterator]()) : undefined,\n\t'$ %ArrayPrototype%': Array.prototype,\n\t'$ %ArrayProto_entries%': Array.prototype.entries,\n\t'$ %ArrayProto_forEach%': Array.prototype.forEach,\n\t'$ %ArrayProto_keys%': Array.prototype.keys,\n\t'$ %ArrayProto_values%': Array.prototype.values,\n\t'$ %AsyncFromSyncIteratorPrototype%': undefined,\n\t'$ %AsyncFunction%': asyncFunction,\n\t'$ %AsyncFunctionPrototype%': asyncFunction ? asyncFunction.prototype : undefined,\n\t'$ %AsyncGenerator%': asyncGen ? getProto(asyncGenIterator) : undefined,\n\t'$ %AsyncGeneratorFunction%': asyncGenFunction,\n\t'$ %AsyncGeneratorPrototype%': asyncGenFunction ? asyncGenFunction.prototype : undefined,\n\t'$ %AsyncIteratorPrototype%': asyncGenIterator && hasSymbols && Symbol.asyncIterator ? asyncGenIterator[Symbol.asyncIterator]() : undefined,\n\t'$ %Atomics%': typeof Atomics === 'undefined' ? undefined : Atomics,\n\t'$ %Boolean%': Boolean,\n\t'$ %BooleanPrototype%': Boolean.prototype,\n\t'$ %DataView%': typeof DataView === 'undefined' ? undefined : DataView,\n\t'$ %DataViewPrototype%': typeof DataView === 'undefined' ? undefined : DataView.prototype,\n\t'$ %Date%': Date,\n\t'$ %DatePrototype%': Date.prototype,\n\t'$ %decodeURI%': decodeURI,\n\t'$ %decodeURIComponent%': decodeURIComponent,\n\t'$ %encodeURI%': encodeURI,\n\t'$ %encodeURIComponent%': encodeURIComponent,\n\t'$ %Error%': Error,\n\t'$ %ErrorPrototype%': Error.prototype,\n\t'$ %eval%': eval, // eslint-disable-line no-eval\n\t'$ %EvalError%': EvalError,\n\t'$ %EvalErrorPrototype%': EvalError.prototype,\n\t'$ %Float32Array%': typeof Float32Array === 'undefined' ? undefined : Float32Array,\n\t'$ %Float32ArrayPrototype%': typeof Float32Array === 'undefined' ? undefined : Float32Array.prototype,\n\t'$ %Float64Array%': typeof Float64Array === 'undefined' ? undefined : Float64Array,\n\t'$ %Float64ArrayPrototype%': typeof Float64Array === 'undefined' ? undefined : Float64Array.prototype,\n\t'$ %Function%': Function,\n\t'$ %FunctionPrototype%': Function.prototype,\n\t'$ %Generator%': generator ? getProto(generator()) : undefined,\n\t'$ %GeneratorFunction%': generatorFunction,\n\t'$ %GeneratorPrototype%': generatorFunction ? generatorFunction.prototype : undefined,\n\t'$ %Int8Array%': typeof Int8Array === 'undefined' ? undefined : Int8Array,\n\t'$ %Int8ArrayPrototype%': typeof Int8Array === 'undefined' ? undefined : Int8Array.prototype,\n\t'$ %Int16Array%': typeof Int16Array === 'undefined' ? undefined : Int16Array,\n\t'$ %Int16ArrayPrototype%': typeof Int16Array === 'undefined' ? undefined : Int8Array.prototype,\n\t'$ %Int32Array%': typeof Int32Array === 'undefined' ? undefined : Int32Array,\n\t'$ %Int32ArrayPrototype%': typeof Int32Array === 'undefined' ? undefined : Int32Array.prototype,\n\t'$ %isFinite%': isFinite,\n\t'$ %isNaN%': isNaN,\n\t'$ %IteratorPrototype%': hasSymbols ? getProto(getProto([][Symbol.iterator]())) : undefined,\n\t'$ %JSON%': JSON,\n\t'$ %JSONParse%': JSON.parse,\n\t'$ %Map%': typeof Map === 'undefined' ? undefined : Map,\n\t'$ %MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols ? undefined : getProto(new Map()[Symbol.iterator]()),\n\t'$ %MapPrototype%': typeof Map === 'undefined' ? undefined : Map.prototype,\n\t'$ %Math%': Math,\n\t'$ %Number%': Number,\n\t'$ %NumberPrototype%': Number.prototype,\n\t'$ %Object%': Object,\n\t'$ %ObjectPrototype%': Object.prototype,\n\t'$ %ObjProto_toString%': Object.prototype.toString,\n\t'$ %ObjProto_valueOf%': Object.prototype.valueOf,\n\t'$ %parseFloat%': parseFloat,\n\t'$ %parseInt%': parseInt,\n\t'$ %Promise%': typeof Promise === 'undefined' ? undefined : Promise,\n\t'$ %PromisePrototype%': typeof Promise === 'undefined' ? undefined : Promise.prototype,\n\t'$ %PromiseProto_then%': typeof Promise === 'undefined' ? undefined : Promise.prototype.then,\n\t'$ %Promise_all%': typeof Promise === 'undefined' ? undefined : Promise.all,\n\t'$ %Promise_reject%': typeof Promise === 'undefined' ? undefined : Promise.reject,\n\t'$ %Promise_resolve%': typeof Promise === 'undefined' ? undefined : Promise.resolve,\n\t'$ %Proxy%': typeof Proxy === 'undefined' ? undefined : Proxy,\n\t'$ %RangeError%': RangeError,\n\t'$ %RangeErrorPrototype%': RangeError.prototype,\n\t'$ %ReferenceError%': ReferenceError,\n\t'$ %ReferenceErrorPrototype%': ReferenceError.prototype,\n\t'$ %Reflect%': typeof Reflect === 'undefined' ? undefined : Reflect,\n\t'$ %RegExp%': RegExp,\n\t'$ %RegExpPrototype%': RegExp.prototype,\n\t'$ %Set%': typeof Set === 'undefined' ? undefined : Set,\n\t'$ %SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols ? undefined : getProto(new Set()[Symbol.iterator]()),\n\t'$ %SetPrototype%': typeof Set === 'undefined' ? undefined : Set.prototype,\n\t'$ %SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined : SharedArrayBuffer,\n\t'$ %SharedArrayBufferPrototype%': typeof SharedArrayBuffer === 'undefined' ? undefined : SharedArrayBuffer.prototype,\n\t'$ %String%': String,\n\t'$ %StringIteratorPrototype%': hasSymbols ? getProto(''[Symbol.iterator]()) : undefined,\n\t'$ %StringPrototype%': String.prototype,\n\t'$ %Symbol%': hasSymbols ? Symbol : undefined,\n\t'$ %SymbolPrototype%': hasSymbols ? Symbol.prototype : undefined,\n\t'$ %SyntaxError%': SyntaxError,\n\t'$ %SyntaxErrorPrototype%': SyntaxError.prototype,\n\t'$ %ThrowTypeError%': ThrowTypeError,\n\t'$ %TypedArray%': TypedArray,\n\t'$ %TypedArrayPrototype%': TypedArray ? TypedArray.prototype : undefined,\n\t'$ %TypeError%': $TypeError,\n\t'$ %TypeErrorPrototype%': $TypeError.prototype,\n\t'$ %Uint8Array%': typeof Uint8Array === 'undefined' ? undefined : Uint8Array,\n\t'$ %Uint8ArrayPrototype%': typeof Uint8Array === 'undefined' ? undefined : Uint8Array.prototype,\n\t'$ %Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined : Uint8ClampedArray,\n\t'$ %Uint8ClampedArrayPrototype%': typeof Uint8ClampedArray === 'undefined' ? undefined : Uint8ClampedArray.prototype,\n\t'$ %Uint16Array%': typeof Uint16Array === 'undefined' ? undefined : Uint16Array,\n\t'$ %Uint16ArrayPrototype%': typeof Uint16Array === 'undefined' ? undefined : Uint16Array.prototype,\n\t'$ %Uint32Array%': typeof Uint32Array === 'undefined' ? undefined : Uint32Array,\n\t'$ %Uint32ArrayPrototype%': typeof Uint32Array === 'undefined' ? undefined : Uint32Array.prototype,\n\t'$ %URIError%': URIError,\n\t'$ %URIErrorPrototype%': URIError.prototype,\n\t'$ %WeakMap%': typeof WeakMap === 'undefined' ? undefined : WeakMap,\n\t'$ %WeakMapPrototype%': typeof WeakMap === 'undefined' ? undefined : WeakMap.prototype,\n\t'$ %WeakSet%': typeof WeakSet === 'undefined' ? undefined : WeakSet,\n\t'$ %WeakSetPrototype%': typeof WeakSet === 'undefined' ? undefined : WeakSet.prototype\n};\n\nvar bind = require('function-bind');\nvar $replace = bind.call(Function.call, String.prototype.replace);\n\n/* adapted from https://github.com/lodash/lodash/blob/4.17.15/dist/lodash.js#L6735-L6744 */\nvar rePropName = /[^%.[\\]]+|\\[(?:(-?\\d+(?:\\.\\d+)?)|([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|%$))/g;\nvar reEscapeChar = /\\\\(\\\\)?/g; /** Used to match backslashes in property paths. */\nvar stringToPath = function stringToPath(string) {\n\tvar result = [];\n\t$replace(string, rePropName, function (match, number, quote, subString) {\n\t\tresult[result.length] = quote ? $replace(subString, reEscapeChar, '$1') : (number || match);\n\t});\n\treturn result;\n};\n/* end adaptation */\n\nvar getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) {\n\tvar key = '$ ' + name;\n\tif (!(key in INTRINSICS)) {\n\t\tthrow new SyntaxError('intrinsic ' + name + ' does not exist!');\n\t}\n\n\t// istanbul ignore if // hopefully this is impossible to test :-)\n\tif (typeof INTRINSICS[key] === 'undefined' && !allowMissing) {\n\t\tthrow new $TypeError('intrinsic ' + name + ' exists, but is not available. Please file an issue!');\n\t}\n\n\treturn INTRINSICS[key];\n};\n\nmodule.exports = function GetIntrinsic(name, allowMissing) {\n\tif (arguments.length > 1 && typeof allowMissing !== 'boolean') {\n\t\tthrow new TypeError('\"allowMissing\" argument must be a boolean');\n\t}\n\n\tvar parts = stringToPath(name);\n\n\tif (parts.length === 0) {\n\t\treturn getBaseIntrinsic(name, allowMissing);\n\t}\n\n\tvar value = getBaseIntrinsic('%' + parts[0] + '%', allowMissing);\n\tfor (var i = 1; i < parts.length; i += 1) {\n\t\tif (value != null) {\n\t\t\tvalue = value[parts[i]];\n\t\t}\n\t}\n\treturn value;\n};\n","'use strict';\n\nvar GetIntrinsic = require('../GetIntrinsic');\n\nvar $TypeError = GetIntrinsic('%TypeError%');\nvar $SyntaxError = GetIntrinsic('%SyntaxError%');\n\nvar has = require('has');\n\nvar predicates = {\n\t// https://ecma-international.org/ecma-262/6.0/#sec-property-descriptor-specification-type\n\t'Property Descriptor': function isPropertyDescriptor(ES, Desc) {\n\t\tif (ES.Type(Desc) !== 'Object') {\n\t\t\treturn false;\n\t\t}\n\t\tvar allowed = {\n\t\t\t'[[Configurable]]': true,\n\t\t\t'[[Enumerable]]': true,\n\t\t\t'[[Get]]': true,\n\t\t\t'[[Set]]': true,\n\t\t\t'[[Value]]': true,\n\t\t\t'[[Writable]]': true\n\t\t};\n\n\t\tfor (var key in Desc) { // eslint-disable-line\n\t\t\tif (has(Desc, key) && !allowed[key]) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tvar isData = has(Desc, '[[Value]]');\n\t\tvar IsAccessor = has(Desc, '[[Get]]') || has(Desc, '[[Set]]');\n\t\tif (isData && IsAccessor) {\n\t\t\tthrow new $TypeError('Property Descriptors may not be both accessor and data descriptors');\n\t\t}\n\t\treturn true;\n\t}\n};\n\nmodule.exports = function assertRecord(ES, recordType, argumentName, value) {\n\tvar predicate = predicates[recordType];\n\tif (typeof predicate !== 'function') {\n\t\tthrow new $SyntaxError('unknown record type: ' + recordType);\n\t}\n\tif (!predicate(ES, value)) {\n\t\tthrow new $TypeError(argumentName + ' must be a ' + recordType);\n\t}\n};\n","'use strict';\n\nmodule.exports = Number.isNaN || function isNaN(a) {\n\treturn a !== a;\n};\n","'use strict';\n\nvar $isNaN = Number.isNaN || function (a) { return a !== a; };\n\nmodule.exports = Number.isFinite || function (x) { return typeof x === 'number' && !$isNaN(x) && x !== Infinity && x !== -Infinity; };\n","'use strict';\n\nvar GetIntrinsic = require('../GetIntrinsic');\n\nvar $Math = GetIntrinsic('%Math%');\nvar $Number = GetIntrinsic('%Number%');\n\nmodule.exports = $Number.MAX_SAFE_INTEGER || $Math.pow(2, 53) - 1;\n","'use strict';\n\nvar GetIntrinsic = require('../GetIntrinsic');\n\nvar has = require('has');\n\nvar $assign = GetIntrinsic('%Object%').assign;\n\nmodule.exports = function assign(target, source) {\n\tif ($assign) {\n\t\treturn $assign(target, source);\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tfor (var key in source) {\n\t\tif (has(source, key)) {\n\t\t\ttarget[key] = source[key];\n\t\t}\n\t}\n\treturn target;\n};\n","'use strict';\n\nmodule.exports = function sign(number) {\n\treturn number >= 0 ? 1 : -1;\n};\n","'use strict';\n\nmodule.exports = function mod(number, modulo) {\n\tvar remain = number % modulo;\n\treturn Math.floor(remain >= 0 ? remain : remain + modulo);\n};\n","'use strict';\n\nmodule.exports = function isPrimitive(value) {\n\treturn value === null || (typeof value !== 'function' && typeof value !== 'object');\n};\n","'use strict';\n\nmodule.exports = function forEach(array, callback) {\n\tfor (var i = 0; i < array.length; i += 1) {\n\t\tcallback(array[i], i, array); // eslint-disable-line callback-return\n\t}\n};\n","'use strict';\n\nmodule.exports = function every(array, predicate) {\n\tfor (var i = 0; i < array.length; i += 1) {\n\t\tif (!predicate(array[i], i, array)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n};\n","'use strict';\n\nvar every = require('./every');\n\nmodule.exports = function isSamePropertyDescriptor(ES, D1, D2) {\n\tvar fields = [\n\t\t'[[Configurable]]',\n\t\t'[[Enumerable]]',\n\t\t'[[Get]]',\n\t\t'[[Set]]',\n\t\t'[[Value]]',\n\t\t'[[Writable]]'\n\t];\n\treturn every(fields, function (field) {\n\t\tif ((field in D1) !== (field in D2)) {\n\t\t\treturn false;\n\t\t}\n\t\treturn ES.SameValue(D1[field], D2[field]);\n\t});\n};\n","'use strict';\n\nvar GetIntrinsic = require('../GetIntrinsic');\n\nvar has = require('has');\nvar $TypeError = GetIntrinsic('%TypeError%');\n\nmodule.exports = function IsPropertyDescriptor(ES, Desc) {\n\tif (ES.Type(Desc) !== 'Object') {\n\t\treturn false;\n\t}\n\tvar allowed = {\n\t\t'[[Configurable]]': true,\n\t\t'[[Enumerable]]': true,\n\t\t'[[Get]]': true,\n\t\t'[[Set]]': true,\n\t\t'[[Value]]': true,\n\t\t'[[Writable]]': true\n\t};\n\n for (var key in Desc) { // eslint-disable-line\n\t\tif (has(Desc, key) && !allowed[key]) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tif (ES.IsDataDescriptor(Desc) && ES.IsAccessorDescriptor(Desc)) {\n\t\tthrow new $TypeError('Property Descriptors may not be both accessor and data descriptors');\n\t}\n\treturn true;\n};\n","'use strict';\n\nvar bind = require('function-bind');\n\nvar GetIntrinsic = require('../GetIntrinsic');\n\nvar $Function = GetIntrinsic('%Function%');\nvar $apply = $Function.apply;\nvar $call = $Function.call;\n\nmodule.exports = function callBind() {\n\treturn bind.apply($call, arguments);\n};\n\nmodule.exports.apply = function applyBind() {\n\treturn bind.apply($apply, arguments);\n};\n","'use strict';\n\nvar GetIntrinsic = require('../GetIntrinsic');\n\nvar callBind = require('./callBind');\n\nvar $indexOf = callBind(GetIntrinsic('String.prototype.indexOf'));\n\nmodule.exports = function callBoundIntrinsic(name, allowMissing) {\n\tvar intrinsic = GetIntrinsic(name, !!allowMissing);\n\tif (typeof intrinsic === 'function' && $indexOf(name, '.prototype.')) {\n\t\treturn callBind(intrinsic);\n\t}\n\treturn intrinsic;\n};\n","'use strict';\n\nvar GetIntrinsic = require('../GetIntrinsic');\n\nvar $test = GetIntrinsic('RegExp.prototype.test');\n\nvar callBind = require('./callBind');\n\nmodule.exports = function regexTester(regex) {\n\treturn callBind($test, regex);\n};\n","'use strict';\n\nvar $strSlice = require('../helpers/callBound')('String.prototype.slice');\n\nmodule.exports = function isPrefixOf(prefix, string) {\n\tif (prefix === string) {\n\t\treturn true;\n\t}\n\tif (prefix.length > string.length) {\n\t\treturn false;\n\t}\n\treturn $strSlice(string, 0, prefix.length) === prefix;\n};\n","'use strict';\n\nvar toStr = Object.prototype.toString;\n\nvar isPrimitive = require('./helpers/isPrimitive');\n\nvar isCallable = require('is-callable');\n\n// http://ecma-international.org/ecma-262/5.1/#sec-8.12.8\nvar ES5internalSlots = {\n\t'[[DefaultValue]]': function (O) {\n\t\tvar actualHint;\n\t\tif (arguments.length > 1) {\n\t\t\tactualHint = arguments[1];\n\t\t} else {\n\t\t\tactualHint = toStr.call(O) === '[object Date]' ? String : Number;\n\t\t}\n\n\t\tif (actualHint === String || actualHint === Number) {\n\t\t\tvar methods = actualHint === String ? ['toString', 'valueOf'] : ['valueOf', 'toString'];\n\t\t\tvar value, i;\n\t\t\tfor (i = 0; i < methods.length; ++i) {\n\t\t\t\tif (isCallable(O[methods[i]])) {\n\t\t\t\t\tvalue = O[methods[i]]();\n\t\t\t\t\tif (isPrimitive(value)) {\n\t\t\t\t\t\treturn value;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow new TypeError('No default value');\n\t\t}\n\t\tthrow new TypeError('invalid [[DefaultValue]] hint supplied');\n\t}\n};\n\n// http://ecma-international.org/ecma-262/5.1/#sec-9.1\nmodule.exports = function ToPrimitive(input) {\n\tif (isPrimitive(input)) {\n\t\treturn input;\n\t}\n\tif (arguments.length > 1) {\n\t\treturn ES5internalSlots['[[DefaultValue]]'](input, arguments[1]);\n\t}\n\treturn ES5internalSlots['[[DefaultValue]]'](input);\n};\n","'use strict';\n\nvar GetIntrinsic = require('./GetIntrinsic');\n\nvar $Object = GetIntrinsic('%Object%');\nvar $EvalError = GetIntrinsic('%EvalError%');\nvar $TypeError = GetIntrinsic('%TypeError%');\nvar $String = GetIntrinsic('%String%');\nvar $Date = GetIntrinsic('%Date%');\nvar $Number = GetIntrinsic('%Number%');\nvar $floor = GetIntrinsic('%Math.floor%');\nvar $DateUTC = GetIntrinsic('%Date.UTC%');\nvar $abs = GetIntrinsic('%Math.abs%');\n\nvar assertRecord = require('./helpers/assertRecord');\nvar isPropertyDescriptor = require('./helpers/isPropertyDescriptor');\nvar $isNaN = require('./helpers/isNaN');\nvar $isFinite = require('./helpers/isFinite');\nvar sign = require('./helpers/sign');\nvar mod = require('./helpers/mod');\nvar isPrefixOf = require('./helpers/isPrefixOf');\nvar callBound = require('./helpers/callBound');\n\nvar IsCallable = require('is-callable');\nvar toPrimitive = require('es-to-primitive/es5');\n\nvar has = require('has');\n\nvar $getUTCFullYear = callBound('Date.prototype.getUTCFullYear');\n\nvar HoursPerDay = 24;\nvar MinutesPerHour = 60;\nvar SecondsPerMinute = 60;\nvar msPerSecond = 1e3;\nvar msPerMinute = msPerSecond * SecondsPerMinute;\nvar msPerHour = msPerMinute * MinutesPerHour;\nvar msPerDay = 86400000;\n\n// https://es5.github.io/#x9\nvar ES5 = {\n\tToPrimitive: toPrimitive,\n\n\tToBoolean: function ToBoolean(value) {\n\t\treturn !!value;\n\t},\n\tToNumber: function ToNumber(value) {\n\t\treturn +value; // eslint-disable-line no-implicit-coercion\n\t},\n\tToInteger: function ToInteger(value) {\n\t\tvar number = this.ToNumber(value);\n\t\tif ($isNaN(number)) { return 0; }\n\t\tif (number === 0 || !$isFinite(number)) { return number; }\n\t\treturn sign(number) * Math.floor(Math.abs(number));\n\t},\n\tToInt32: function ToInt32(x) {\n\t\treturn this.ToNumber(x) >> 0;\n\t},\n\tToUint32: function ToUint32(x) {\n\t\treturn this.ToNumber(x) >>> 0;\n\t},\n\tToUint16: function ToUint16(value) {\n\t\tvar number = this.ToNumber(value);\n\t\tif ($isNaN(number) || number === 0 || !$isFinite(number)) { return 0; }\n\t\tvar posInt = sign(number) * Math.floor(Math.abs(number));\n\t\treturn mod(posInt, 0x10000);\n\t},\n\tToString: function ToString(value) {\n\t\treturn $String(value);\n\t},\n\tToObject: function ToObject(value) {\n\t\tthis.CheckObjectCoercible(value);\n\t\treturn $Object(value);\n\t},\n\tCheckObjectCoercible: function CheckObjectCoercible(value, optMessage) {\n\t\t/* jshint eqnull:true */\n\t\tif (value == null) {\n\t\t\tthrow new $TypeError(optMessage || 'Cannot call method on ' + value);\n\t\t}\n\t\treturn value;\n\t},\n\tIsCallable: IsCallable,\n\tSameValue: function SameValue(x, y) {\n\t\tif (x === y) { // 0 === -0, but they are not identical.\n\t\t\tif (x === 0) { return 1 / x === 1 / y; }\n\t\t\treturn true;\n\t\t}\n\t\treturn $isNaN(x) && $isNaN(y);\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-8\n\tType: function Type(x) {\n\t\tif (x === null) {\n\t\t\treturn 'Null';\n\t\t}\n\t\tif (typeof x === 'undefined') {\n\t\t\treturn 'Undefined';\n\t\t}\n\t\tif (typeof x === 'function' || typeof x === 'object') {\n\t\t\treturn 'Object';\n\t\t}\n\t\tif (typeof x === 'number') {\n\t\t\treturn 'Number';\n\t\t}\n\t\tif (typeof x === 'boolean') {\n\t\t\treturn 'Boolean';\n\t\t}\n\t\tif (typeof x === 'string') {\n\t\t\treturn 'String';\n\t\t}\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-property-descriptor-specification-type\n\tIsPropertyDescriptor: function IsPropertyDescriptor(Desc) {\n\t\treturn isPropertyDescriptor(this, Desc);\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-8.10.1\n\tIsAccessorDescriptor: function IsAccessorDescriptor(Desc) {\n\t\tif (typeof Desc === 'undefined') {\n\t\t\treturn false;\n\t\t}\n\n\t\tassertRecord(this, 'Property Descriptor', 'Desc', Desc);\n\n\t\tif (!has(Desc, '[[Get]]') && !has(Desc, '[[Set]]')) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-8.10.2\n\tIsDataDescriptor: function IsDataDescriptor(Desc) {\n\t\tif (typeof Desc === 'undefined') {\n\t\t\treturn false;\n\t\t}\n\n\t\tassertRecord(this, 'Property Descriptor', 'Desc', Desc);\n\n\t\tif (!has(Desc, '[[Value]]') && !has(Desc, '[[Writable]]')) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-8.10.3\n\tIsGenericDescriptor: function IsGenericDescriptor(Desc) {\n\t\tif (typeof Desc === 'undefined') {\n\t\t\treturn false;\n\t\t}\n\n\t\tassertRecord(this, 'Property Descriptor', 'Desc', Desc);\n\n\t\tif (!this.IsAccessorDescriptor(Desc) && !this.IsDataDescriptor(Desc)) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-8.10.4\n\tFromPropertyDescriptor: function FromPropertyDescriptor(Desc) {\n\t\tif (typeof Desc === 'undefined') {\n\t\t\treturn Desc;\n\t\t}\n\n\t\tassertRecord(this, 'Property Descriptor', 'Desc', Desc);\n\n\t\tif (this.IsDataDescriptor(Desc)) {\n\t\t\treturn {\n\t\t\t\tvalue: Desc['[[Value]]'],\n\t\t\t\twritable: !!Desc['[[Writable]]'],\n\t\t\t\tenumerable: !!Desc['[[Enumerable]]'],\n\t\t\t\tconfigurable: !!Desc['[[Configurable]]']\n\t\t\t};\n\t\t} else if (this.IsAccessorDescriptor(Desc)) {\n\t\t\treturn {\n\t\t\t\tget: Desc['[[Get]]'],\n\t\t\t\tset: Desc['[[Set]]'],\n\t\t\t\tenumerable: !!Desc['[[Enumerable]]'],\n\t\t\t\tconfigurable: !!Desc['[[Configurable]]']\n\t\t\t};\n\t\t} else {\n\t\t\tthrow new $TypeError('FromPropertyDescriptor must be called with a fully populated Property Descriptor');\n\t\t}\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-8.10.5\n\tToPropertyDescriptor: function ToPropertyDescriptor(Obj) {\n\t\tif (this.Type(Obj) !== 'Object') {\n\t\t\tthrow new $TypeError('ToPropertyDescriptor requires an object');\n\t\t}\n\n\t\tvar desc = {};\n\t\tif (has(Obj, 'enumerable')) {\n\t\t\tdesc['[[Enumerable]]'] = this.ToBoolean(Obj.enumerable);\n\t\t}\n\t\tif (has(Obj, 'configurable')) {\n\t\t\tdesc['[[Configurable]]'] = this.ToBoolean(Obj.configurable);\n\t\t}\n\t\tif (has(Obj, 'value')) {\n\t\t\tdesc['[[Value]]'] = Obj.value;\n\t\t}\n\t\tif (has(Obj, 'writable')) {\n\t\t\tdesc['[[Writable]]'] = this.ToBoolean(Obj.writable);\n\t\t}\n\t\tif (has(Obj, 'get')) {\n\t\t\tvar getter = Obj.get;\n\t\t\tif (typeof getter !== 'undefined' && !this.IsCallable(getter)) {\n\t\t\t\tthrow new TypeError('getter must be a function');\n\t\t\t}\n\t\t\tdesc['[[Get]]'] = getter;\n\t\t}\n\t\tif (has(Obj, 'set')) {\n\t\t\tvar setter = Obj.set;\n\t\t\tif (typeof setter !== 'undefined' && !this.IsCallable(setter)) {\n\t\t\t\tthrow new $TypeError('setter must be a function');\n\t\t\t}\n\t\t\tdesc['[[Set]]'] = setter;\n\t\t}\n\n\t\tif ((has(desc, '[[Get]]') || has(desc, '[[Set]]')) && (has(desc, '[[Value]]') || has(desc, '[[Writable]]'))) {\n\t\t\tthrow new $TypeError('Invalid property descriptor. Cannot both specify accessors and a value or writable attribute');\n\t\t}\n\t\treturn desc;\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-11.9.3\n\t'Abstract Equality Comparison': function AbstractEqualityComparison(x, y) {\n\t\tvar xType = this.Type(x);\n\t\tvar yType = this.Type(y);\n\t\tif (xType === yType) {\n\t\t\treturn x === y; // ES6+ specified this shortcut anyways.\n\t\t}\n\t\tif (x == null && y == null) {\n\t\t\treturn true;\n\t\t}\n\t\tif (xType === 'Number' && yType === 'String') {\n\t\t\treturn this['Abstract Equality Comparison'](x, this.ToNumber(y));\n\t\t}\n\t\tif (xType === 'String' && yType === 'Number') {\n\t\t\treturn this['Abstract Equality Comparison'](this.ToNumber(x), y);\n\t\t}\n\t\tif (xType === 'Boolean') {\n\t\t\treturn this['Abstract Equality Comparison'](this.ToNumber(x), y);\n\t\t}\n\t\tif (yType === 'Boolean') {\n\t\t\treturn this['Abstract Equality Comparison'](x, this.ToNumber(y));\n\t\t}\n\t\tif ((xType === 'String' || xType === 'Number') && yType === 'Object') {\n\t\t\treturn this['Abstract Equality Comparison'](x, this.ToPrimitive(y));\n\t\t}\n\t\tif (xType === 'Object' && (yType === 'String' || yType === 'Number')) {\n\t\t\treturn this['Abstract Equality Comparison'](this.ToPrimitive(x), y);\n\t\t}\n\t\treturn false;\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-11.9.6\n\t'Strict Equality Comparison': function StrictEqualityComparison(x, y) {\n\t\tvar xType = this.Type(x);\n\t\tvar yType = this.Type(y);\n\t\tif (xType !== yType) {\n\t\t\treturn false;\n\t\t}\n\t\tif (xType === 'Undefined' || xType === 'Null') {\n\t\t\treturn true;\n\t\t}\n\t\treturn x === y; // shortcut for steps 4-7\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-11.8.5\n\t// eslint-disable-next-line max-statements\n\t'Abstract Relational Comparison': function AbstractRelationalComparison(x, y, LeftFirst) {\n\t\tif (this.Type(LeftFirst) !== 'Boolean') {\n\t\t\tthrow new $TypeError('Assertion failed: LeftFirst argument must be a Boolean');\n\t\t}\n\t\tvar px;\n\t\tvar py;\n\t\tif (LeftFirst) {\n\t\t\tpx = this.ToPrimitive(x, $Number);\n\t\t\tpy = this.ToPrimitive(y, $Number);\n\t\t} else {\n\t\t\tpy = this.ToPrimitive(y, $Number);\n\t\t\tpx = this.ToPrimitive(x, $Number);\n\t\t}\n\t\tvar bothStrings = this.Type(px) === 'String' && this.Type(py) === 'String';\n\t\tif (!bothStrings) {\n\t\t\tvar nx = this.ToNumber(px);\n\t\t\tvar ny = this.ToNumber(py);\n\t\t\tif ($isNaN(nx) || $isNaN(ny)) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif ($isFinite(nx) && $isFinite(ny) && nx === ny) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (nx === 0 && ny === 0) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (nx === Infinity) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (ny === Infinity) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (ny === -Infinity) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (nx === -Infinity) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn nx < ny; // by now, these are both nonzero, finite, and not equal\n\t\t}\n\t\tif (isPrefixOf(py, px)) {\n\t\t\treturn false;\n\t\t}\n\t\tif (isPrefixOf(px, py)) {\n\t\t\treturn true;\n\t\t}\n\t\treturn px < py; // both strings, neither a prefix of the other. shortcut for steps c-f\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.10\n\tmsFromTime: function msFromTime(t) {\n\t\treturn mod(t, msPerSecond);\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.10\n\tSecFromTime: function SecFromTime(t) {\n\t\treturn mod($floor(t / msPerSecond), SecondsPerMinute);\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.10\n\tMinFromTime: function MinFromTime(t) {\n\t\treturn mod($floor(t / msPerMinute), MinutesPerHour);\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.10\n\tHourFromTime: function HourFromTime(t) {\n\t\treturn mod($floor(t / msPerHour), HoursPerDay);\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.2\n\tDay: function Day(t) {\n\t\treturn $floor(t / msPerDay);\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.2\n\tTimeWithinDay: function TimeWithinDay(t) {\n\t\treturn mod(t, msPerDay);\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.3\n\tDayFromYear: function DayFromYear(y) {\n\t\treturn (365 * (y - 1970)) + $floor((y - 1969) / 4) - $floor((y - 1901) / 100) + $floor((y - 1601) / 400);\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.3\n\tTimeFromYear: function TimeFromYear(y) {\n\t\treturn msPerDay * this.DayFromYear(y);\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.3\n\tYearFromTime: function YearFromTime(t) {\n\t\t// largest y such that this.TimeFromYear(y) <= t\n\t\treturn $getUTCFullYear(new $Date(t));\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.6\n\tWeekDay: function WeekDay(t) {\n\t\treturn mod(this.Day(t) + 4, 7);\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.3\n\tDaysInYear: function DaysInYear(y) {\n\t\tif (mod(y, 4) !== 0) {\n\t\t\treturn 365;\n\t\t}\n\t\tif (mod(y, 100) !== 0) {\n\t\t\treturn 366;\n\t\t}\n\t\tif (mod(y, 400) !== 0) {\n\t\t\treturn 365;\n\t\t}\n\t\treturn 366;\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.3\n\tInLeapYear: function InLeapYear(t) {\n\t\tvar days = this.DaysInYear(this.YearFromTime(t));\n\t\tif (days === 365) {\n\t\t\treturn 0;\n\t\t}\n\t\tif (days === 366) {\n\t\t\treturn 1;\n\t\t}\n\t\tthrow new $EvalError('Assertion failed: there are not 365 or 366 days in a year, got: ' + days);\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.4\n\tDayWithinYear: function DayWithinYear(t) {\n\t\treturn this.Day(t) - this.DayFromYear(this.YearFromTime(t));\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.4\n\tMonthFromTime: function MonthFromTime(t) {\n\t\tvar day = this.DayWithinYear(t);\n\t\tif (0 <= day && day < 31) {\n\t\t\treturn 0;\n\t\t}\n\t\tvar leap = this.InLeapYear(t);\n\t\tif (31 <= day && day < (59 + leap)) {\n\t\t\treturn 1;\n\t\t}\n\t\tif ((59 + leap) <= day && day < (90 + leap)) {\n\t\t\treturn 2;\n\t\t}\n\t\tif ((90 + leap) <= day && day < (120 + leap)) {\n\t\t\treturn 3;\n\t\t}\n\t\tif ((120 + leap) <= day && day < (151 + leap)) {\n\t\t\treturn 4;\n\t\t}\n\t\tif ((151 + leap) <= day && day < (181 + leap)) {\n\t\t\treturn 5;\n\t\t}\n\t\tif ((181 + leap) <= day && day < (212 + leap)) {\n\t\t\treturn 6;\n\t\t}\n\t\tif ((212 + leap) <= day && day < (243 + leap)) {\n\t\t\treturn 7;\n\t\t}\n\t\tif ((243 + leap) <= day && day < (273 + leap)) {\n\t\t\treturn 8;\n\t\t}\n\t\tif ((273 + leap) <= day && day < (304 + leap)) {\n\t\t\treturn 9;\n\t\t}\n\t\tif ((304 + leap) <= day && day < (334 + leap)) {\n\t\t\treturn 10;\n\t\t}\n\t\tif ((334 + leap) <= day && day < (365 + leap)) {\n\t\t\treturn 11;\n\t\t}\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.5\n\tDateFromTime: function DateFromTime(t) {\n\t\tvar m = this.MonthFromTime(t);\n\t\tvar d = this.DayWithinYear(t);\n\t\tif (m === 0) {\n\t\t\treturn d + 1;\n\t\t}\n\t\tif (m === 1) {\n\t\t\treturn d - 30;\n\t\t}\n\t\tvar leap = this.InLeapYear(t);\n\t\tif (m === 2) {\n\t\t\treturn d - 58 - leap;\n\t\t}\n\t\tif (m === 3) {\n\t\t\treturn d - 89 - leap;\n\t\t}\n\t\tif (m === 4) {\n\t\t\treturn d - 119 - leap;\n\t\t}\n\t\tif (m === 5) {\n\t\t\treturn d - 150 - leap;\n\t\t}\n\t\tif (m === 6) {\n\t\t\treturn d - 180 - leap;\n\t\t}\n\t\tif (m === 7) {\n\t\t\treturn d - 211 - leap;\n\t\t}\n\t\tif (m === 8) {\n\t\t\treturn d - 242 - leap;\n\t\t}\n\t\tif (m === 9) {\n\t\t\treturn d - 272 - leap;\n\t\t}\n\t\tif (m === 10) {\n\t\t\treturn d - 303 - leap;\n\t\t}\n\t\tif (m === 11) {\n\t\t\treturn d - 333 - leap;\n\t\t}\n\t\tthrow new $EvalError('Assertion failed: MonthFromTime returned an impossible value: ' + m);\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.12\n\tMakeDay: function MakeDay(year, month, date) {\n\t\tif (!$isFinite(year) || !$isFinite(month) || !$isFinite(date)) {\n\t\t\treturn NaN;\n\t\t}\n\t\tvar y = this.ToInteger(year);\n\t\tvar m = this.ToInteger(month);\n\t\tvar dt = this.ToInteger(date);\n\t\tvar ym = y + $floor(m / 12);\n\t\tvar mn = mod(m, 12);\n\t\tvar t = $DateUTC(ym, mn, 1);\n\t\tif (this.YearFromTime(t) !== ym || this.MonthFromTime(t) !== mn || this.DateFromTime(t) !== 1) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn this.Day(t) + dt - 1;\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.13\n\tMakeDate: function MakeDate(day, time) {\n\t\tif (!$isFinite(day) || !$isFinite(time)) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn (day * msPerDay) + time;\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.11\n\tMakeTime: function MakeTime(hour, min, sec, ms) {\n\t\tif (!$isFinite(hour) || !$isFinite(min) || !$isFinite(sec) || !$isFinite(ms)) {\n\t\t\treturn NaN;\n\t\t}\n\t\tvar h = this.ToInteger(hour);\n\t\tvar m = this.ToInteger(min);\n\t\tvar s = this.ToInteger(sec);\n\t\tvar milli = this.ToInteger(ms);\n\t\tvar t = (h * msPerHour) + (m * msPerMinute) + (s * msPerSecond) + milli;\n\t\treturn t;\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.14\n\tTimeClip: function TimeClip(time) {\n\t\tif (!$isFinite(time) || $abs(time) > 8.64e15) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn $Number(new $Date(this.ToNumber(time)));\n\t},\n\n\t// https://ecma-international.org/ecma-262/5.1/#sec-5.2\n\tmodulo: function modulo(x, y) {\n\t\treturn mod(x, y);\n\t}\n};\n\nmodule.exports = ES5;\n","'use strict';\n\nvar has = require('has');\nvar regexExec = RegExp.prototype.exec;\nvar gOPD = Object.getOwnPropertyDescriptor;\n\nvar tryRegexExecCall = function tryRegexExec(value) {\n\ttry {\n\t\tvar lastIndex = value.lastIndex;\n\t\tvalue.lastIndex = 0;\n\n\t\tregexExec.call(value);\n\t\treturn true;\n\t} catch (e) {\n\t\treturn false;\n\t} finally {\n\t\tvalue.lastIndex = lastIndex;\n\t}\n};\nvar toStr = Object.prototype.toString;\nvar regexClass = '[object RegExp]';\nvar hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';\n\nmodule.exports = function isRegex(value) {\n\tif (!value || typeof value !== 'object') {\n\t\treturn false;\n\t}\n\tif (!hasToStringTag) {\n\t\treturn toStr.call(value) === regexClass;\n\t}\n\n\tvar descriptor = gOPD(value, 'lastIndex');\n\tvar hasLastIndexDataProperty = descriptor && has(descriptor, 'value');\n\tif (!hasLastIndexDataProperty) {\n\t\treturn false;\n\t}\n\n\treturn tryRegexExecCall(value);\n};\n","'use strict';\n\nvar has = require('has');\nvar toPrimitive = require('es-to-primitive/es6');\nvar keys = require('object-keys');\nvar inspect = require('object-inspect');\n\nvar GetIntrinsic = require('./GetIntrinsic');\n\nvar $TypeError = GetIntrinsic('%TypeError%');\nvar $RangeError = GetIntrinsic('%RangeError%');\nvar $SyntaxError = GetIntrinsic('%SyntaxError%');\nvar $Array = GetIntrinsic('%Array%');\nvar $ArrayPrototype = $Array.prototype;\nvar $String = GetIntrinsic('%String%');\nvar $Object = GetIntrinsic('%Object%');\nvar $Number = GetIntrinsic('%Number%');\nvar $Symbol = GetIntrinsic('%Symbol%', true);\nvar $RegExp = GetIntrinsic('%RegExp%');\nvar $Date = GetIntrinsic('%Date%');\nvar $preventExtensions = $Object.preventExtensions;\n\nvar hasSymbols = require('has-symbols')();\n\nvar assertRecord = require('./helpers/assertRecord');\nvar $isNaN = require('./helpers/isNaN');\nvar $isFinite = require('./helpers/isFinite');\nvar MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1;\nvar MAX_SAFE_INTEGER = require('./helpers/maxSafeInteger');\n\nvar assign = require('./helpers/assign');\nvar sign = require('./helpers/sign');\nvar mod = require('./helpers/mod');\nvar isPrimitive = require('./helpers/isPrimitive');\nvar forEach = require('./helpers/forEach');\nvar every = require('./helpers/every');\nvar isSamePropertyDescriptor = require('./helpers/isSamePropertyDescriptor');\nvar isPropertyDescriptor = require('./helpers/isPropertyDescriptor');\nvar parseInteger = parseInt;\nvar callBound = require('./helpers/callBound');\nvar regexTester = require('./helpers/regexTester');\n\nvar $PromiseThen = callBound('Promise.prototype.then', true);\nvar arraySlice = callBound('Array.prototype.slice');\nvar strSlice = callBound('String.prototype.slice');\n\nvar isBinary = regexTester(/^0b[01]+$/i);\nvar isOctal = regexTester(/^0o[0-7]+$/i);\nvar isDigit = regexTester(/^[0-9]$/);\nvar regexExec = callBound('RegExp.prototype.exec');\nvar nonWS = ['\\u0085', '\\u200b', '\\ufffe'].join('');\nvar nonWSregex = new $RegExp('[' + nonWS + ']', 'g');\nvar hasNonWS = regexTester(nonWSregex);\nvar isInvalidHexLiteral = regexTester(/^[-+]0x[0-9a-f]+$/i);\nvar $charCodeAt = callBound('String.prototype.charCodeAt');\nvar $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');\n\nvar toStr = callBound('Object.prototype.toString');\n\nvar $NumberValueOf = callBound('Number.prototype.valueOf');\nvar $BooleanValueOf = callBound('Boolean.prototype.valueOf');\nvar $StringValueOf = callBound('String.prototype.valueOf');\nvar $DateValueOf = callBound('Date.prototype.valueOf');\nvar $SymbolToString = callBound('Symbol.prototype.toString', true);\n\nvar $floor = Math.floor;\nvar $abs = Math.abs;\n\nvar $ObjectCreate = $Object.create;\nvar $gOPD = $Object.getOwnPropertyDescriptor;\nvar $gOPN = $Object.getOwnPropertyNames;\nvar $gOPS = $Object.getOwnPropertySymbols;\nvar $isExtensible = $Object.isExtensible;\nvar $defineProperty = $Object.defineProperty;\nvar $setProto = Object.setPrototypeOf || (\n\t// eslint-disable-next-line no-proto, no-negated-condition\n\t[].__proto__ !== Array.prototype\n\t\t? null\n\t\t: function (O, proto) {\n\t\t\tO.__proto__ = proto; // eslint-disable-line no-proto\n\t\t\treturn O;\n\t\t}\n);\n\nvar DefineOwnProperty = function DefineOwnProperty(ES, O, P, desc) {\n\tif (!$defineProperty) {\n\t\tif (!ES.IsDataDescriptor(desc)) {\n\t\t\t// ES3 does not support getters/setters\n\t\t\treturn false;\n\t\t}\n\t\tif (!desc['[[Configurable]]'] || !desc['[[Writable]]']) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// fallback for ES3\n\t\tif (P in O && $isEnumerable(O, P) !== !!desc['[[Enumerable]]']) {\n\t\t\t// a non-enumerable existing property\n\t\t\treturn false;\n\t\t}\n\n\t\t// property does not exist at all, or exists but is enumerable\n\t\tvar V = desc['[[Value]]'];\n\t\tO[P] = V; // will use [[Define]]\n\t\treturn ES.SameValue(O[P], V);\n\t}\n\t$defineProperty(O, P, ES.FromPropertyDescriptor(desc));\n\treturn true;\n};\n\n// whitespace from: https://es5.github.io/#x15.5.4.20\n// implementation from https://github.com/es-shims/es5-shim/blob/v3.4.0/es5-shim.js#L1304-L1324\nvar ws = [\n\t'\\x09\\x0A\\x0B\\x0C\\x0D\\x20\\xA0\\u1680\\u180E\\u2000\\u2001\\u2002\\u2003',\n\t'\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200A\\u202F\\u205F\\u3000\\u2028',\n\t'\\u2029\\uFEFF'\n].join('');\nvar trimRegex = new RegExp('(^[' + ws + ']+)|([' + ws + ']+$)', 'g');\nvar $replace = callBound('String.prototype.replace');\nvar trim = function (value) {\n\treturn $replace(value, trimRegex, '');\n};\n\nvar ES5 = require('./es5');\n\nvar hasRegExpMatcher = require('is-regex');\n\n// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-abstract-operations\nvar ES6 = assign(assign({}, ES5), {\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-call-f-v-args\n\tCall: function Call(F, V) {\n\t\tvar args = arguments.length > 2 ? arguments[2] : [];\n\t\tif (!this.IsCallable(F)) {\n\t\t\tthrow new $TypeError(inspect(F) + ' is not a function');\n\t\t}\n\t\treturn F.apply(V, args);\n\t},\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-toprimitive\n\tToPrimitive: toPrimitive,\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-toboolean\n\t// ToBoolean: ES5.ToBoolean,\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-tonumber\n\tToNumber: function ToNumber(argument) {\n\t\tvar value = isPrimitive(argument) ? argument : toPrimitive(argument, $Number);\n\t\tif (typeof value === 'symbol') {\n\t\t\tthrow new $TypeError('Cannot convert a Symbol value to a number');\n\t\t}\n\t\tif (typeof value === 'string') {\n\t\t\tif (isBinary(value)) {\n\t\t\t\treturn this.ToNumber(parseInteger(strSlice(value, 2), 2));\n\t\t\t} else if (isOctal(value)) {\n\t\t\t\treturn this.ToNumber(parseInteger(strSlice(value, 2), 8));\n\t\t\t} else if (hasNonWS(value) || isInvalidHexLiteral(value)) {\n\t\t\t\treturn NaN;\n\t\t\t} else {\n\t\t\t\tvar trimmed = trim(value);\n\t\t\t\tif (trimmed !== value) {\n\t\t\t\t\treturn this.ToNumber(trimmed);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn $Number(value);\n\t},\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tointeger\n\t// ToInteger: ES5.ToNumber,\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-toint32\n\t// ToInt32: ES5.ToInt32,\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-touint32\n\t// ToUint32: ES5.ToUint32,\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-toint16\n\tToInt16: function ToInt16(argument) {\n\t\tvar int16bit = this.ToUint16(argument);\n\t\treturn int16bit >= 0x8000 ? int16bit - 0x10000 : int16bit;\n\t},\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-touint16\n\t// ToUint16: ES5.ToUint16,\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-toint8\n\tToInt8: function ToInt8(argument) {\n\t\tvar int8bit = this.ToUint8(argument);\n\t\treturn int8bit >= 0x80 ? int8bit - 0x100 : int8bit;\n\t},\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-touint8\n\tToUint8: function ToUint8(argument) {\n\t\tvar number = this.ToNumber(argument);\n\t\tif ($isNaN(number) || number === 0 || !$isFinite(number)) { return 0; }\n\t\tvar posInt = sign(number) * $floor($abs(number));\n\t\treturn mod(posInt, 0x100);\n\t},\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-touint8clamp\n\tToUint8Clamp: function ToUint8Clamp(argument) {\n\t\tvar number = this.ToNumber(argument);\n\t\tif ($isNaN(number) || number <= 0) { return 0; }\n\t\tif (number >= 0xFF) { return 0xFF; }\n\t\tvar f = $floor(argument);\n\t\tif (f + 0.5 < number) { return f + 1; }\n\t\tif (number < f + 0.5) { return f; }\n\t\tif (f % 2 !== 0) { return f + 1; }\n\t\treturn f;\n\t},\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tostring\n\tToString: function ToString(argument) {\n\t\tif (typeof argument === 'symbol') {\n\t\t\tthrow new $TypeError('Cannot convert a Symbol value to a string');\n\t\t}\n\t\treturn $String(argument);\n\t},\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-toobject\n\tToObject: function ToObject(value) {\n\t\tthis.RequireObjectCoercible(value);\n\t\treturn $Object(value);\n\t},\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-topropertykey\n\tToPropertyKey: function ToPropertyKey(argument) {\n\t\tvar key = this.ToPrimitive(argument, $String);\n\t\treturn typeof key === 'symbol' ? key : this.ToString(key);\n\t},\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength\n\tToLength: function ToLength(argument) {\n\t\tvar len = this.ToInteger(argument);\n\t\tif (len <= 0) { return 0; } // includes converting -0 to +0\n\t\tif (len > MAX_SAFE_INTEGER) { return MAX_SAFE_INTEGER; }\n\t\treturn len;\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-canonicalnumericindexstring\n\tCanonicalNumericIndexString: function CanonicalNumericIndexString(argument) {\n\t\tif (toStr(argument) !== '[object String]') {\n\t\t\tthrow new $TypeError('must be a string');\n\t\t}\n\t\tif (argument === '-0') { return -0; }\n\t\tvar n = this.ToNumber(argument);\n\t\tif (this.SameValue(this.ToString(n), argument)) { return n; }\n\t\treturn void 0;\n\t},\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-requireobjectcoercible\n\tRequireObjectCoercible: ES5.CheckObjectCoercible,\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-isarray\n\tIsArray: $Array.isArray || function IsArray(argument) {\n\t\treturn toStr(argument) === '[object Array]';\n\t},\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-iscallable\n\t// IsCallable: ES5.IsCallable,\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-isconstructor\n\tIsConstructor: function IsConstructor(argument) {\n\t\treturn typeof argument === 'function' && !!argument.prototype; // unfortunately there's no way to truly check this without try/catch `new argument`\n\t},\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-isextensible-o\n\tIsExtensible: $preventExtensions\n\t\t? function IsExtensible(obj) {\n\t\t\tif (isPrimitive(obj)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn $isExtensible(obj);\n\t\t}\n\t\t: function isExtensible(obj) { return true; }, // eslint-disable-line no-unused-vars\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-isinteger\n\tIsInteger: function IsInteger(argument) {\n\t\tif (typeof argument !== 'number' || $isNaN(argument) || !$isFinite(argument)) {\n\t\t\treturn false;\n\t\t}\n\t\tvar abs = $abs(argument);\n\t\treturn $floor(abs) === abs;\n\t},\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-ispropertykey\n\tIsPropertyKey: function IsPropertyKey(argument) {\n\t\treturn typeof argument === 'string' || typeof argument === 'symbol';\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-isregexp\n\tIsRegExp: function IsRegExp(argument) {\n\t\tif (!argument || typeof argument !== 'object') {\n\t\t\treturn false;\n\t\t}\n\t\tif (hasSymbols) {\n\t\t\tvar isRegExp = argument[$Symbol.match];\n\t\t\tif (typeof isRegExp !== 'undefined') {\n\t\t\t\treturn ES5.ToBoolean(isRegExp);\n\t\t\t}\n\t\t}\n\t\treturn hasRegExpMatcher(argument);\n\t},\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevalue\n\t// SameValue: ES5.SameValue,\n\n\t// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero\n\tSameValueZero: function SameValueZero(x, y) {\n\t\treturn (x === y) || ($isNaN(x) && $isNaN(y));\n\t},\n\n\t/**\n\t * 7.3.2 GetV (V, P)\n\t * 1. Assert: IsPropertyKey(P) is true.\n\t * 2. Let O be ToObject(V).\n\t * 3. ReturnIfAbrupt(O).\n\t * 4. Return O.[[Get]](P, V).\n\t */\n\tGetV: function GetV(V, P) {\n\t\t// 7.3.2.1\n\t\tif (!this.IsPropertyKey(P)) {\n\t\t\tthrow new $TypeError('Assertion failed: IsPropertyKey(P) is not true');\n\t\t}\n\n\t\t// 7.3.2.2-3\n\t\tvar O = this.ToObject(V);\n\n\t\t// 7.3.2.4\n\t\treturn O[P];\n\t},\n\n\t/**\n\t * 7.3.9 - https://ecma-international.org/ecma-262/6.0/#sec-getmethod\n\t * 1. Assert: IsPropertyKey(P) is true.\n\t * 2. Let func be GetV(O, P).\n\t * 3. ReturnIfAbrupt(func).\n\t * 4. If func is either undefined or null, return undefined.\n\t * 5. If IsCallable(func) is false, throw a TypeError exception.\n\t * 6. Return func.\n\t */\n\tGetMethod: function GetMethod(O, P) {\n\t\t// 7.3.9.1\n\t\tif (!this.IsPropertyKey(P)) {\n\t\t\tthrow new $TypeError('Assertion failed: IsPropertyKey(P) is not true');\n\t\t}\n\n\t\t// 7.3.9.2\n\t\tvar func = this.GetV(O, P);\n\n\t\t// 7.3.9.4\n\t\tif (func == null) {\n\t\t\treturn void 0;\n\t\t}\n\n\t\t// 7.3.9.5\n\t\tif (!this.IsCallable(func)) {\n\t\t\tthrow new $TypeError(P + 'is not a function');\n\t\t}\n\n\t\t// 7.3.9.6\n\t\treturn func;\n\t},\n\n\t/**\n\t * 7.3.1 Get (O, P) - https://ecma-international.org/ecma-262/6.0/#sec-get-o-p\n\t * 1. Assert: Type(O) is Object.\n\t * 2. Assert: IsPropertyKey(P) is true.\n\t * 3. Return O.[[Get]](P, O).\n\t */\n\tGet: function Get(O, P) {\n\t\t// 7.3.1.1\n\t\tif (this.Type(O) !== 'Object') {\n\t\t\tthrow new $TypeError('Assertion failed: Type(O) is not Object');\n\t\t}\n\t\t// 7.3.1.2\n\t\tif (!this.IsPropertyKey(P)) {\n\t\t\tthrow new $TypeError('Assertion failed: IsPropertyKey(P) is not true, got ' + inspect(P));\n\t\t}\n\t\t// 7.3.1.3\n\t\treturn O[P];\n\t},\n\n\tType: function Type(x) {\n\t\tif (typeof x === 'symbol') {\n\t\t\treturn 'Symbol';\n\t\t}\n\t\treturn ES5.Type(x);\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-speciesconstructor\n\tSpeciesConstructor: function SpeciesConstructor(O, defaultConstructor) {\n\t\tif (this.Type(O) !== 'Object') {\n\t\t\tthrow new $TypeError('Assertion failed: Type(O) is not Object');\n\t\t}\n\t\tvar C = O.constructor;\n\t\tif (typeof C === 'undefined') {\n\t\t\treturn defaultConstructor;\n\t\t}\n\t\tif (this.Type(C) !== 'Object') {\n\t\t\tthrow new $TypeError('O.constructor is not an Object');\n\t\t}\n\t\tvar S = hasSymbols && $Symbol.species ? C[$Symbol.species] : void 0;\n\t\tif (S == null) {\n\t\t\treturn defaultConstructor;\n\t\t}\n\t\tif (this.IsConstructor(S)) {\n\t\t\treturn S;\n\t\t}\n\t\tthrow new $TypeError('no constructor found');\n\t},\n\n\t// https://www.ecma-international.org/ecma-262/6.0/#sec-frompropertydescriptor\n\tFromPropertyDescriptor: function FromPropertyDescriptor(Desc) {\n\t\tif (typeof Desc === 'undefined') {\n\t\t\treturn Desc;\n\t\t}\n\n\t\tassertRecord(this, 'Property Descriptor', 'Desc', Desc);\n\n\t\tvar obj = {};\n\t\tif ('[[Value]]' in Desc) {\n\t\t\tobj.value = Desc['[[Value]]'];\n\t\t}\n\t\tif ('[[Writable]]' in Desc) {\n\t\t\tobj.writable = Desc['[[Writable]]'];\n\t\t}\n\t\tif ('[[Get]]' in Desc) {\n\t\t\tobj.get = Desc['[[Get]]'];\n\t\t}\n\t\tif ('[[Set]]' in Desc) {\n\t\t\tobj.set = Desc['[[Set]]'];\n\t\t}\n\t\tif ('[[Enumerable]]' in Desc) {\n\t\t\tobj.enumerable = Desc['[[Enumerable]]'];\n\t\t}\n\t\tif ('[[Configurable]]' in Desc) {\n\t\t\tobj.configurable = Desc['[[Configurable]]'];\n\t\t}\n\t\treturn obj;\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-completepropertydescriptor\n\tCompletePropertyDescriptor: function CompletePropertyDescriptor(Desc) {\n\t\tassertRecord(this, 'Property Descriptor', 'Desc', Desc);\n\n\t\tif (this.IsGenericDescriptor(Desc) || this.IsDataDescriptor(Desc)) {\n\t\t\tif (!has(Desc, '[[Value]]')) {\n\t\t\t\tDesc['[[Value]]'] = void 0;\n\t\t\t}\n\t\t\tif (!has(Desc, '[[Writable]]')) {\n\t\t\t\tDesc['[[Writable]]'] = false;\n\t\t\t}\n\t\t} else {\n\t\t\tif (!has(Desc, '[[Get]]')) {\n\t\t\t\tDesc['[[Get]]'] = void 0;\n\t\t\t}\n\t\t\tif (!has(Desc, '[[Set]]')) {\n\t\t\t\tDesc['[[Set]]'] = void 0;\n\t\t\t}\n\t\t}\n\t\tif (!has(Desc, '[[Enumerable]]')) {\n\t\t\tDesc['[[Enumerable]]'] = false;\n\t\t}\n\t\tif (!has(Desc, '[[Configurable]]')) {\n\t\t\tDesc['[[Configurable]]'] = false;\n\t\t}\n\t\treturn Desc;\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-set-o-p-v-throw\n\tSet: function Set(O, P, V, Throw) {\n\t\tif (this.Type(O) !== 'Object') {\n\t\t\tthrow new $TypeError('O must be an Object');\n\t\t}\n\t\tif (!this.IsPropertyKey(P)) {\n\t\t\tthrow new $TypeError('P must be a Property Key');\n\t\t}\n\t\tif (this.Type(Throw) !== 'Boolean') {\n\t\t\tthrow new $TypeError('Throw must be a Boolean');\n\t\t}\n\t\tif (Throw) {\n\t\t\tO[P] = V;\n\t\t\treturn true;\n\t\t} else {\n\t\t\ttry {\n\t\t\t\tO[P] = V;\n\t\t\t} catch (e) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-hasownproperty\n\tHasOwnProperty: function HasOwnProperty(O, P) {\n\t\tif (this.Type(O) !== 'Object') {\n\t\t\tthrow new $TypeError('O must be an Object');\n\t\t}\n\t\tif (!this.IsPropertyKey(P)) {\n\t\t\tthrow new $TypeError('P must be a Property Key');\n\t\t}\n\t\treturn has(O, P);\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-hasproperty\n\tHasProperty: function HasProperty(O, P) {\n\t\tif (this.Type(O) !== 'Object') {\n\t\t\tthrow new $TypeError('O must be an Object');\n\t\t}\n\t\tif (!this.IsPropertyKey(P)) {\n\t\t\tthrow new $TypeError('P must be a Property Key');\n\t\t}\n\t\treturn P in O;\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-isconcatspreadable\n\tIsConcatSpreadable: function IsConcatSpreadable(O) {\n\t\tif (this.Type(O) !== 'Object') {\n\t\t\treturn false;\n\t\t}\n\t\tif (hasSymbols && typeof $Symbol.isConcatSpreadable === 'symbol') {\n\t\t\tvar spreadable = this.Get(O, Symbol.isConcatSpreadable);\n\t\t\tif (typeof spreadable !== 'undefined') {\n\t\t\t\treturn this.ToBoolean(spreadable);\n\t\t\t}\n\t\t}\n\t\treturn this.IsArray(O);\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-invoke\n\tInvoke: function Invoke(O, P) {\n\t\tif (!this.IsPropertyKey(P)) {\n\t\t\tthrow new $TypeError('P must be a Property Key');\n\t\t}\n\t\tvar argumentsList = arraySlice(arguments, 2);\n\t\tvar func = this.GetV(O, P);\n\t\treturn this.Call(func, O, argumentsList);\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-getiterator\n\tGetIterator: function GetIterator(obj, method) {\n\t\tvar actualMethod = method;\n\t\tif (arguments.length < 2) {\n\t\t\tif (!hasSymbols) {\n\t\t\t\tthrow new SyntaxError('GetIterator depends on native Symbol support when `method` is not passed');\n\t\t\t}\n\t\t\tactualMethod = this.GetMethod(obj, $Symbol.iterator);\n\t\t}\n\t\tvar iterator = this.Call(actualMethod, obj);\n\t\tif (this.Type(iterator) !== 'Object') {\n\t\t\tthrow new $TypeError('iterator must return an object');\n\t\t}\n\n\t\treturn iterator;\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-iteratornext\n\tIteratorNext: function IteratorNext(iterator, value) {\n\t\tvar result = this.Invoke(iterator, 'next', arguments.length < 2 ? [] : [value]);\n\t\tif (this.Type(result) !== 'Object') {\n\t\t\tthrow new $TypeError('iterator next must return an object');\n\t\t}\n\t\treturn result;\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-iteratorcomplete\n\tIteratorComplete: function IteratorComplete(iterResult) {\n\t\tif (this.Type(iterResult) !== 'Object') {\n\t\t\tthrow new $TypeError('Assertion failed: Type(iterResult) is not Object');\n\t\t}\n\t\treturn this.ToBoolean(this.Get(iterResult, 'done'));\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-iteratorvalue\n\tIteratorValue: function IteratorValue(iterResult) {\n\t\tif (this.Type(iterResult) !== 'Object') {\n\t\t\tthrow new $TypeError('Assertion failed: Type(iterResult) is not Object');\n\t\t}\n\t\treturn this.Get(iterResult, 'value');\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-iteratorstep\n\tIteratorStep: function IteratorStep(iterator) {\n\t\tvar result = this.IteratorNext(iterator);\n\t\tvar done = this.IteratorComplete(result);\n\t\treturn done === true ? false : result;\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-iteratorclose\n\tIteratorClose: function IteratorClose(iterator, completion) {\n\t\tif (this.Type(iterator) !== 'Object') {\n\t\t\tthrow new $TypeError('Assertion failed: Type(iterator) is not Object');\n\t\t}\n\t\tif (!this.IsCallable(completion)) {\n\t\t\tthrow new $TypeError('Assertion failed: completion is not a thunk for a Completion Record');\n\t\t}\n\t\tvar completionThunk = completion;\n\n\t\tvar iteratorReturn = this.GetMethod(iterator, 'return');\n\n\t\tif (typeof iteratorReturn === 'undefined') {\n\t\t\treturn completionThunk();\n\t\t}\n\n\t\tvar completionRecord;\n\t\ttry {\n\t\t\tvar innerResult = this.Call(iteratorReturn, iterator, []);\n\t\t} catch (e) {\n\t\t\t// if we hit here, then \"e\" is the innerResult completion that needs re-throwing\n\n\t\t\t// if the completion is of type \"throw\", this will throw.\n\t\t\tcompletionRecord = completionThunk();\n\t\t\tcompletionThunk = null; // ensure it's not called twice.\n\n\t\t\t// if not, then return the innerResult completion\n\t\t\tthrow e;\n\t\t}\n\t\tcompletionRecord = completionThunk(); // if innerResult worked, then throw if the completion does\n\t\tcompletionThunk = null; // ensure it's not called twice.\n\n\t\tif (this.Type(innerResult) !== 'Object') {\n\t\t\tthrow new $TypeError('iterator .return must return an object');\n\t\t}\n\n\t\treturn completionRecord;\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-createiterresultobject\n\tCreateIterResultObject: function CreateIterResultObject(value, done) {\n\t\tif (this.Type(done) !== 'Boolean') {\n\t\t\tthrow new $TypeError('Assertion failed: Type(done) is not Boolean');\n\t\t}\n\t\treturn {\n\t\t\tvalue: value,\n\t\t\tdone: done\n\t\t};\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-regexpexec\n\tRegExpExec: function RegExpExec(R, S) {\n\t\tif (this.Type(R) !== 'Object') {\n\t\t\tthrow new $TypeError('R must be an Object');\n\t\t}\n\t\tif (this.Type(S) !== 'String') {\n\t\t\tthrow new $TypeError('S must be a String');\n\t\t}\n\t\tvar exec = this.Get(R, 'exec');\n\t\tif (this.IsCallable(exec)) {\n\t\t\tvar result = this.Call(exec, R, [S]);\n\t\t\tif (result === null || this.Type(result) === 'Object') {\n\t\t\t\treturn result;\n\t\t\t}\n\t\t\tthrow new $TypeError('\"exec\" method must return `null` or an Object');\n\t\t}\n\t\treturn regexExec(R, S);\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-arrayspeciescreate\n\tArraySpeciesCreate: function ArraySpeciesCreate(originalArray, length) {\n\t\tif (!this.IsInteger(length) || length < 0) {\n\t\t\tthrow new $TypeError('Assertion failed: length must be an integer >= 0');\n\t\t}\n\t\tvar len = length === 0 ? 0 : length;\n\t\tvar C;\n\t\tvar isArray = this.IsArray(originalArray);\n\t\tif (isArray) {\n\t\t\tC = this.Get(originalArray, 'constructor');\n\t\t\t// TODO: figure out how to make a cross-realm normal Array, a same-realm Array\n\t\t\t// if (this.IsConstructor(C)) {\n\t\t\t// \tif C is another realm's Array, C = undefined\n\t\t\t// \tObject.getPrototypeOf(Object.getPrototypeOf(Object.getPrototypeOf(Array))) === null ?\n\t\t\t// }\n\t\t\tif (this.Type(C) === 'Object' && hasSymbols && $Symbol.species) {\n\t\t\t\tC = this.Get(C, $Symbol.species);\n\t\t\t\tif (C === null) {\n\t\t\t\t\tC = void 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (typeof C === 'undefined') {\n\t\t\treturn $Array(len);\n\t\t}\n\t\tif (!this.IsConstructor(C)) {\n\t\t\tthrow new $TypeError('C must be a constructor');\n\t\t}\n\t\treturn new C(len); // this.Construct(C, len);\n\t},\n\n\tCreateDataProperty: function CreateDataProperty(O, P, V) {\n\t\tif (this.Type(O) !== 'Object') {\n\t\t\tthrow new $TypeError('Assertion failed: Type(O) is not Object');\n\t\t}\n\t\tif (!this.IsPropertyKey(P)) {\n\t\t\tthrow new $TypeError('Assertion failed: IsPropertyKey(P) is not true');\n\t\t}\n\t\tvar oldDesc = $gOPD(O, P);\n\t\tvar extensible = oldDesc || this.IsExtensible(O);\n\t\tvar immutable = oldDesc && (!oldDesc.writable || !oldDesc.configurable);\n\t\tif (immutable || !extensible) {\n\t\t\treturn false;\n\t\t}\n\t\treturn DefineOwnProperty(this, O, P, {\n\t\t\t'[[Configurable]]': true,\n\t\t\t'[[Enumerable]]': true,\n\t\t\t'[[Value]]': V,\n\t\t\t'[[Writable]]': true\n\t\t});\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-createdatapropertyorthrow\n\tCreateDataPropertyOrThrow: function CreateDataPropertyOrThrow(O, P, V) {\n\t\tif (this.Type(O) !== 'Object') {\n\t\t\tthrow new $TypeError('Assertion failed: Type(O) is not Object');\n\t\t}\n\t\tif (!this.IsPropertyKey(P)) {\n\t\t\tthrow new $TypeError('Assertion failed: IsPropertyKey(P) is not true');\n\t\t}\n\t\tvar success = this.CreateDataProperty(O, P, V);\n\t\tif (!success) {\n\t\t\tthrow new $TypeError('unable to create data property');\n\t\t}\n\t\treturn success;\n\t},\n\n\t// https://www.ecma-international.org/ecma-262/6.0/#sec-objectcreate\n\tObjectCreate: function ObjectCreate(proto, internalSlotsList) {\n\t\tif (proto !== null && this.Type(proto) !== 'Object') {\n\t\t\tthrow new $TypeError('Assertion failed: proto must be null or an object');\n\t\t}\n\t\tvar slots = arguments.length < 2 ? [] : internalSlotsList;\n\t\tif (slots.length > 0) {\n\t\t\tthrow new $SyntaxError('es-abstract does not yet support internal slots');\n\t\t}\n\n\t\tif (proto === null && !$ObjectCreate) {\n\t\t\tthrow new $SyntaxError('native Object.create support is required to create null objects');\n\t\t}\n\n\t\treturn $ObjectCreate(proto);\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-advancestringindex\n\tAdvanceStringIndex: function AdvanceStringIndex(S, index, unicode) {\n\t\tif (this.Type(S) !== 'String') {\n\t\t\tthrow new $TypeError('S must be a String');\n\t\t}\n\t\tif (!this.IsInteger(index) || index < 0 || index > MAX_SAFE_INTEGER) {\n\t\t\tthrow new $TypeError('Assertion failed: length must be an integer >= 0 and <= 2**53');\n\t\t}\n\t\tif (this.Type(unicode) !== 'Boolean') {\n\t\t\tthrow new $TypeError('Assertion failed: unicode must be a Boolean');\n\t\t}\n\t\tif (!unicode) {\n\t\t\treturn index + 1;\n\t\t}\n\t\tvar length = S.length;\n\t\tif ((index + 1) >= length) {\n\t\t\treturn index + 1;\n\t\t}\n\n\t\tvar first = $charCodeAt(S, index);\n\t\tif (first < 0xD800 || first > 0xDBFF) {\n\t\t\treturn index + 1;\n\t\t}\n\n\t\tvar second = $charCodeAt(S, index + 1);\n\t\tif (second < 0xDC00 || second > 0xDFFF) {\n\t\t\treturn index + 1;\n\t\t}\n\n\t\treturn index + 2;\n\t},\n\n\t// https://www.ecma-international.org/ecma-262/6.0/#sec-createmethodproperty\n\tCreateMethodProperty: function CreateMethodProperty(O, P, V) {\n\t\tif (this.Type(O) !== 'Object') {\n\t\t\tthrow new $TypeError('Assertion failed: Type(O) is not Object');\n\t\t}\n\n\t\tif (!this.IsPropertyKey(P)) {\n\t\t\tthrow new $TypeError('Assertion failed: IsPropertyKey(P) is not true');\n\t\t}\n\n\t\tvar newDesc = {\n\t\t\t'[[Configurable]]': true,\n\t\t\t'[[Enumerable]]': false,\n\t\t\t'[[Value]]': V,\n\t\t\t'[[Writable]]': true\n\t\t};\n\t\treturn DefineOwnProperty(this, O, P, newDesc);\n\t},\n\n\t// https://www.ecma-international.org/ecma-262/6.0/#sec-definepropertyorthrow\n\tDefinePropertyOrThrow: function DefinePropertyOrThrow(O, P, desc) {\n\t\tif (this.Type(O) !== 'Object') {\n\t\t\tthrow new $TypeError('Assertion failed: Type(O) is not Object');\n\t\t}\n\n\t\tif (!this.IsPropertyKey(P)) {\n\t\t\tthrow new $TypeError('Assertion failed: IsPropertyKey(P) is not true');\n\t\t}\n\n\t\tvar Desc = isPropertyDescriptor(this, desc) ? desc : this.ToPropertyDescriptor(desc);\n\t\tif (!isPropertyDescriptor(this, Desc)) {\n\t\t\tthrow new $TypeError('Assertion failed: Desc is not a valid Property Descriptor');\n\t\t}\n\n\t\treturn DefineOwnProperty(this, O, P, Desc);\n\t},\n\n\t// https://www.ecma-international.org/ecma-262/6.0/#sec-deletepropertyorthrow\n\tDeletePropertyOrThrow: function DeletePropertyOrThrow(O, P) {\n\t\tif (this.Type(O) !== 'Object') {\n\t\t\tthrow new $TypeError('Assertion failed: Type(O) is not Object');\n\t\t}\n\n\t\tif (!this.IsPropertyKey(P)) {\n\t\t\tthrow new $TypeError('Assertion failed: IsPropertyKey(P) is not true');\n\t\t}\n\n\t\tvar success = delete O[P];\n\t\tif (!success) {\n\t\t\tthrow new TypeError('Attempt to delete property failed.');\n\t\t}\n\t\treturn success;\n\t},\n\n\t// https://www.ecma-international.org/ecma-262/6.0/#sec-enumerableownnames\n\tEnumerableOwnNames: function EnumerableOwnNames(O) {\n\t\tif (this.Type(O) !== 'Object') {\n\t\t\tthrow new $TypeError('Assertion failed: Type(O) is not Object');\n\t\t}\n\n\t\treturn keys(O);\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-number-prototype-object\n\tthisNumberValue: function thisNumberValue(value) {\n\t\tif (this.Type(value) === 'Number') {\n\t\t\treturn value;\n\t\t}\n\n\t\treturn $NumberValueOf(value);\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-boolean-prototype-object\n\tthisBooleanValue: function thisBooleanValue(value) {\n\t\tif (this.Type(value) === 'Boolean') {\n\t\t\treturn value;\n\t\t}\n\n\t\treturn $BooleanValueOf(value);\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-string-prototype-object\n\tthisStringValue: function thisStringValue(value) {\n\t\tif (this.Type(value) === 'String') {\n\t\t\treturn value;\n\t\t}\n\n\t\treturn $StringValueOf(value);\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-date-prototype-object\n\tthisTimeValue: function thisTimeValue(value) {\n\t\treturn $DateValueOf(value);\n\t},\n\n\t// https://www.ecma-international.org/ecma-262/6.0/#sec-setintegritylevel\n\tSetIntegrityLevel: function SetIntegrityLevel(O, level) {\n\t\tif (this.Type(O) !== 'Object') {\n\t\t\tthrow new $TypeError('Assertion failed: Type(O) is not Object');\n\t\t}\n\t\tif (level !== 'sealed' && level !== 'frozen') {\n\t\t\tthrow new $TypeError('Assertion failed: `level` must be `\"sealed\"` or `\"frozen\"`');\n\t\t}\n\t\tif (!$preventExtensions) {\n\t\t\tthrow new $SyntaxError('SetIntegrityLevel requires native `Object.preventExtensions` support');\n\t\t}\n\t\tvar status = $preventExtensions(O);\n\t\tif (!status) {\n\t\t\treturn false;\n\t\t}\n\t\tif (!$gOPN) {\n\t\t\tthrow new $SyntaxError('SetIntegrityLevel requires native `Object.getOwnPropertyNames` support');\n\t\t}\n\t\tvar theKeys = $gOPN(O);\n\t\tvar ES = this;\n\t\tif (level === 'sealed') {\n\t\t\tforEach(theKeys, function (k) {\n\t\t\t\tES.DefinePropertyOrThrow(O, k, { configurable: false });\n\t\t\t});\n\t\t} else if (level === 'frozen') {\n\t\t\tforEach(theKeys, function (k) {\n\t\t\t\tvar currentDesc = $gOPD(O, k);\n\t\t\t\tif (typeof currentDesc !== 'undefined') {\n\t\t\t\t\tvar desc;\n\t\t\t\t\tif (ES.IsAccessorDescriptor(ES.ToPropertyDescriptor(currentDesc))) {\n\t\t\t\t\t\tdesc = { configurable: false };\n\t\t\t\t\t} else {\n\t\t\t\t\t\tdesc = { configurable: false, writable: false };\n\t\t\t\t\t}\n\t\t\t\t\tES.DefinePropertyOrThrow(O, k, desc);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\treturn true;\n\t},\n\n\t// https://www.ecma-international.org/ecma-262/6.0/#sec-testintegritylevel\n\tTestIntegrityLevel: function TestIntegrityLevel(O, level) {\n\t\tif (this.Type(O) !== 'Object') {\n\t\t\tthrow new $TypeError('Assertion failed: Type(O) is not Object');\n\t\t}\n\t\tif (level !== 'sealed' && level !== 'frozen') {\n\t\t\tthrow new $TypeError('Assertion failed: `level` must be `\"sealed\"` or `\"frozen\"`');\n\t\t}\n\t\tvar status = this.IsExtensible(O);\n\t\tif (status) {\n\t\t\treturn false;\n\t\t}\n\t\tvar theKeys = $gOPN(O);\n\t\tvar ES = this;\n\t\treturn theKeys.length === 0 || every(theKeys, function (k) {\n\t\t\tvar currentDesc = $gOPD(O, k);\n\t\t\tif (typeof currentDesc !== 'undefined') {\n\t\t\t\tif (currentDesc.configurable) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tif (level === 'frozen' && ES.IsDataDescriptor(ES.ToPropertyDescriptor(currentDesc)) && currentDesc.writable) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t});\n\t},\n\n\t// https://www.ecma-international.org/ecma-262/6.0/#sec-ordinaryhasinstance\n\tOrdinaryHasInstance: function OrdinaryHasInstance(C, O) {\n\t\tif (this.IsCallable(C) === false) {\n\t\t\treturn false;\n\t\t}\n\t\tif (this.Type(O) !== 'Object') {\n\t\t\treturn false;\n\t\t}\n\t\tvar P = this.Get(C, 'prototype');\n\t\tif (this.Type(P) !== 'Object') {\n\t\t\tthrow new $TypeError('OrdinaryHasInstance called on an object with an invalid prototype property.');\n\t\t}\n\t\treturn O instanceof C;\n\t},\n\n\t// https://www.ecma-international.org/ecma-262/6.0/#sec-ordinaryhasproperty\n\tOrdinaryHasProperty: function OrdinaryHasProperty(O, P) {\n\t\tif (this.Type(O) !== 'Object') {\n\t\t\tthrow new $TypeError('Assertion failed: Type(O) is not Object');\n\t\t}\n\t\tif (!this.IsPropertyKey(P)) {\n\t\t\tthrow new $TypeError('Assertion failed: P must be a Property Key');\n\t\t}\n\t\treturn P in O;\n\t},\n\n\t// https://www.ecma-international.org/ecma-262/6.0/#sec-instanceofoperator\n\tInstanceofOperator: function InstanceofOperator(O, C) {\n\t\tif (this.Type(O) !== 'Object') {\n\t\t\tthrow new $TypeError('Assertion failed: Type(O) is not Object');\n\t\t}\n\t\tvar instOfHandler = hasSymbols && $Symbol.hasInstance ? this.GetMethod(C, $Symbol.hasInstance) : void 0;\n\t\tif (typeof instOfHandler !== 'undefined') {\n\t\t\treturn this.ToBoolean(this.Call(instOfHandler, C, [O]));\n\t\t}\n\t\tif (!this.IsCallable(C)) {\n\t\t\tthrow new $TypeError('`C` is not Callable');\n\t\t}\n\t\treturn this.OrdinaryHasInstance(C, O);\n\t},\n\n\t// https://www.ecma-international.org/ecma-262/6.0/#sec-ispromise\n\tIsPromise: function IsPromise(x) {\n\t\tif (this.Type(x) !== 'Object') {\n\t\t\treturn false;\n\t\t}\n\t\tif (!$PromiseThen) { // Promises are not supported\n\t\t\treturn false;\n\t\t}\n\t\ttry {\n\t\t\t$PromiseThen(x); // throws if not a promise\n\t\t} catch (e) {\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t},\n\n\t// https://www.ecma-international.org/ecma-262/6.0/#sec-abstract-equality-comparison\n\t'Abstract Equality Comparison': function AbstractEqualityComparison(x, y) {\n\t\tvar xType = this.Type(x);\n\t\tvar yType = this.Type(y);\n\t\tif (xType === yType) {\n\t\t\treturn x === y; // ES6+ specified this shortcut anyways.\n\t\t}\n\t\tif (x == null && y == null) {\n\t\t\treturn true;\n\t\t}\n\t\tif (xType === 'Number' && yType === 'String') {\n\t\t\treturn this['Abstract Equality Comparison'](x, this.ToNumber(y));\n\t\t}\n\t\tif (xType === 'String' && yType === 'Number') {\n\t\t\treturn this['Abstract Equality Comparison'](this.ToNumber(x), y);\n\t\t}\n\t\tif (xType === 'Boolean') {\n\t\t\treturn this['Abstract Equality Comparison'](this.ToNumber(x), y);\n\t\t}\n\t\tif (yType === 'Boolean') {\n\t\t\treturn this['Abstract Equality Comparison'](x, this.ToNumber(y));\n\t\t}\n\t\tif ((xType === 'String' || xType === 'Number' || xType === 'Symbol') && yType === 'Object') {\n\t\t\treturn this['Abstract Equality Comparison'](x, this.ToPrimitive(y));\n\t\t}\n\t\tif (xType === 'Object' && (yType === 'String' || yType === 'Number' || yType === 'Symbol')) {\n\t\t\treturn this['Abstract Equality Comparison'](this.ToPrimitive(x), y);\n\t\t}\n\t\treturn false;\n\t},\n\n\t// eslint-disable-next-line max-lines-per-function, max-statements, id-length, max-params\n\tValidateAndApplyPropertyDescriptor: function ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc, current) {\n\t\t// this uses the ES2017+ logic, since it fixes a number of bugs in the ES2015 logic.\n\t\tvar oType = this.Type(O);\n\t\tif (oType !== 'Undefined' && oType !== 'Object') {\n\t\t\tthrow new $TypeError('Assertion failed: O must be undefined or an Object');\n\t\t}\n\t\tif (this.Type(extensible) !== 'Boolean') {\n\t\t\tthrow new $TypeError('Assertion failed: extensible must be a Boolean');\n\t\t}\n\t\tif (!isPropertyDescriptor(this, Desc)) {\n\t\t\tthrow new $TypeError('Assertion failed: Desc must be a Property Descriptor');\n\t\t}\n\t\tif (this.Type(current) !== 'Undefined' && !isPropertyDescriptor(this, current)) {\n\t\t\tthrow new $TypeError('Assertion failed: current must be a Property Descriptor, or undefined');\n\t\t}\n\t\tif (oType !== 'Undefined' && !this.IsPropertyKey(P)) {\n\t\t\tthrow new $TypeError('Assertion failed: if O is not undefined, P must be a Property Key');\n\t\t}\n\t\tif (this.Type(current) === 'Undefined') {\n\t\t\tif (!extensible) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (this.IsGenericDescriptor(Desc) || this.IsDataDescriptor(Desc)) {\n\t\t\t\tif (oType !== 'Undefined') {\n\t\t\t\t\tDefineOwnProperty(this, O, P, {\n\t\t\t\t\t\t'[[Configurable]]': Desc['[[Configurable]]'],\n\t\t\t\t\t\t'[[Enumerable]]': Desc['[[Enumerable]]'],\n\t\t\t\t\t\t'[[Value]]': Desc['[[Value]]'],\n\t\t\t\t\t\t'[[Writable]]': Desc['[[Writable]]']\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (!this.IsAccessorDescriptor(Desc)) {\n\t\t\t\t\tthrow new $TypeError('Assertion failed: Desc is not an accessor descriptor');\n\t\t\t\t}\n\t\t\t\tif (oType !== 'Undefined') {\n\t\t\t\t\treturn DefineOwnProperty(this, O, P, Desc);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tif (this.IsGenericDescriptor(Desc) && !('[[Configurable]]' in Desc) && !('[[Enumerable]]' in Desc)) {\n\t\t\treturn true;\n\t\t}\n\t\tif (isSamePropertyDescriptor(this, Desc, current)) {\n\t\t\treturn true; // removed by ES2017, but should still be correct\n\t\t}\n\t\t// \"if every field in Desc is absent, return true\" can't really match the assertion that it's a Property Descriptor\n\t\tif (!current['[[Configurable]]']) {\n\t\t\tif (Desc['[[Configurable]]']) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif ('[[Enumerable]]' in Desc && !Desc['[[Enumerable]]'] === !!current['[[Enumerable]]']) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\tif (this.IsGenericDescriptor(Desc)) {\n\t\t\t// no further validation is required.\n\t\t} else if (this.IsDataDescriptor(current) !== this.IsDataDescriptor(Desc)) {\n\t\t\tif (!current['[[Configurable]]']) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (this.IsDataDescriptor(current)) {\n\t\t\t\tif (oType !== 'Undefined') {\n\t\t\t\t\tDefineOwnProperty(this, O, P, {\n\t\t\t\t\t\t'[[Configurable]]': current['[[Configurable]]'],\n\t\t\t\t\t\t'[[Enumerable]]': current['[[Enumerable]]'],\n\t\t\t\t\t\t'[[Get]]': undefined\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} else if (oType !== 'Undefined') {\n\t\t\t\tDefineOwnProperty(this, O, P, {\n\t\t\t\t\t'[[Configurable]]': current['[[Configurable]]'],\n\t\t\t\t\t'[[Enumerable]]': current['[[Enumerable]]'],\n\t\t\t\t\t'[[Value]]': undefined\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (this.IsDataDescriptor(current) && this.IsDataDescriptor(Desc)) {\n\t\t\tif (!current['[[Configurable]]'] && !current['[[Writable]]']) {\n\t\t\t\tif ('[[Writable]]' in Desc && Desc['[[Writable]]']) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tif ('[[Value]]' in Desc && !this.SameValue(Desc['[[Value]]'], current['[[Value]]'])) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\t\t} else if (this.IsAccessorDescriptor(current) && this.IsAccessorDescriptor(Desc)) {\n\t\t\tif (!current['[[Configurable]]']) {\n\t\t\t\tif ('[[Set]]' in Desc && !this.SameValue(Desc['[[Set]]'], current['[[Set]]'])) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tif ('[[Get]]' in Desc && !this.SameValue(Desc['[[Get]]'], current['[[Get]]'])) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\t\t} else {\n\t\t\tthrow new $TypeError('Assertion failed: current and Desc are not both data, both accessors, or one accessor and one data.');\n\t\t}\n\t\tif (oType !== 'Undefined') {\n\t\t\treturn DefineOwnProperty(this, O, P, Desc);\n\t\t}\n\t\treturn true;\n\t},\n\n\t// https://www.ecma-international.org/ecma-262/6.0/#sec-ordinarydefineownproperty\n\tOrdinaryDefineOwnProperty: function OrdinaryDefineOwnProperty(O, P, Desc) {\n\t\tif (this.Type(O) !== 'Object') {\n\t\t\tthrow new $TypeError('Assertion failed: O must be an Object');\n\t\t}\n\t\tif (!this.IsPropertyKey(P)) {\n\t\t\tthrow new $TypeError('Assertion failed: P must be a Property Key');\n\t\t}\n\t\tif (!isPropertyDescriptor(this, Desc)) {\n\t\t\tthrow new $TypeError('Assertion failed: Desc must be a Property Descriptor');\n\t\t}\n\t\tvar desc = $gOPD(O, P);\n\t\tvar current = desc && this.ToPropertyDescriptor(desc);\n\t\tvar extensible = this.IsExtensible(O);\n\t\treturn this.ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc, current);\n\t},\n\n\t// https://www.ecma-international.org/ecma-262/6.0/#sec-ordinarygetownproperty\n\tOrdinaryGetOwnProperty: function OrdinaryGetOwnProperty(O, P) {\n\t\tif (this.Type(O) !== 'Object') {\n\t\t\tthrow new $TypeError('Assertion failed: O must be an Object');\n\t\t}\n\t\tif (!this.IsPropertyKey(P)) {\n\t\t\tthrow new $TypeError('Assertion failed: P must be a Property Key');\n\t\t}\n\t\tif (!has(O, P)) {\n\t\t\treturn void 0;\n\t\t}\n\t\tif (!$gOPD) {\n\t\t\t// ES3 fallback\n\t\t\tvar arrayLength = this.IsArray(O) && P === 'length';\n\t\t\tvar regexLastIndex = this.IsRegExp(O) && P === 'lastIndex';\n\t\t\treturn {\n\t\t\t\t'[[Configurable]]': !(arrayLength || regexLastIndex),\n\t\t\t\t'[[Enumerable]]': $isEnumerable(O, P),\n\t\t\t\t'[[Value]]': O[P],\n\t\t\t\t'[[Writable]]': true\n\t\t\t};\n\t\t}\n\t\treturn this.ToPropertyDescriptor($gOPD(O, P));\n\t},\n\n\t// https://www.ecma-international.org/ecma-262/6.0/#sec-arraycreate\n\tArrayCreate: function ArrayCreate(length) {\n\t\tif (!this.IsInteger(length) || length < 0) {\n\t\t\tthrow new $TypeError('Assertion failed: `length` must be an integer Number >= 0');\n\t\t}\n\t\tif (length > MAX_ARRAY_LENGTH) {\n\t\t\tthrow new $RangeError('length is greater than (2**32 - 1)');\n\t\t}\n\t\tvar proto = arguments.length > 1 ? arguments[1] : $ArrayPrototype;\n\t\tvar A = []; // steps 5 - 7, and 9\n\t\tif (proto !== $ArrayPrototype) { // step 8\n\t\t\tif (!$setProto) {\n\t\t\t\tthrow new $SyntaxError('ArrayCreate: a `proto` argument that is not `Array.prototype` is not supported in an environment that does not support setting the [[Prototype]]');\n\t\t\t}\n\t\t\t$setProto(A, proto);\n\t\t}\n\t\tif (length !== 0) { // bypasses the need for step 2\n\t\t\tA.length = length;\n\t\t}\n\t\t/* step 10, the above as a shortcut for the below\n\t\tthis.OrdinaryDefineOwnProperty(A, 'length', {\n\t\t\t'[[Configurable]]': false,\n\t\t\t'[[Enumerable]]': false,\n\t\t\t'[[Value]]': length,\n\t\t\t'[[Writable]]': true\n\t\t});\n\t\t*/\n\t\treturn A;\n\t},\n\n\t// eslint-disable-next-line max-statements, max-lines-per-function\n\tArraySetLength: function ArraySetLength(A, Desc) {\n\t\tif (!this.IsArray(A)) {\n\t\t\tthrow new $TypeError('Assertion failed: A must be an Array');\n\t\t}\n\t\tif (!isPropertyDescriptor(this, Desc)) {\n\t\t\tthrow new $TypeError('Assertion failed: Desc must be a Property Descriptor');\n\t\t}\n\t\tif (!('[[Value]]' in Desc)) {\n\t\t\treturn this.OrdinaryDefineOwnProperty(A, 'length', Desc);\n\t\t}\n\t\tvar newLenDesc = assign({}, Desc);\n\t\tvar newLen = this.ToUint32(Desc['[[Value]]']);\n\t\tvar numberLen = this.ToNumber(Desc['[[Value]]']);\n\t\tif (newLen !== numberLen) {\n\t\t\tthrow new $RangeError('Invalid array length');\n\t\t}\n\t\tnewLenDesc['[[Value]]'] = newLen;\n\t\tvar oldLenDesc = this.OrdinaryGetOwnProperty(A, 'length');\n\t\tif (!this.IsDataDescriptor(oldLenDesc)) {\n\t\t\tthrow new $TypeError('Assertion failed: an array had a non-data descriptor on `length`');\n\t\t}\n\t\tvar oldLen = oldLenDesc['[[Value]]'];\n\t\tif (newLen >= oldLen) {\n\t\t\treturn this.OrdinaryDefineOwnProperty(A, 'length', newLenDesc);\n\t\t}\n\t\tif (!oldLenDesc['[[Writable]]']) {\n\t\t\treturn false;\n\t\t}\n\t\tvar newWritable;\n\t\tif (!('[[Writable]]' in newLenDesc) || newLenDesc['[[Writable]]']) {\n\t\t\tnewWritable = true;\n\t\t} else {\n\t\t\tnewWritable = false;\n\t\t\tnewLenDesc['[[Writable]]'] = true;\n\t\t}\n\t\tvar succeeded = this.OrdinaryDefineOwnProperty(A, 'length', newLenDesc);\n\t\tif (!succeeded) {\n\t\t\treturn false;\n\t\t}\n\t\twhile (newLen < oldLen) {\n\t\t\toldLen -= 1;\n\t\t\tvar deleteSucceeded = delete A[this.ToString(oldLen)];\n\t\t\tif (!deleteSucceeded) {\n\t\t\t\tnewLenDesc['[[Value]]'] = oldLen + 1;\n\t\t\t\tif (!newWritable) {\n\t\t\t\t\tnewLenDesc['[[Writable]]'] = false;\n\t\t\t\t\tthis.OrdinaryDefineOwnProperty(A, 'length', newLenDesc);\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!newWritable) {\n\t\t\treturn this.OrdinaryDefineOwnProperty(A, 'length', { '[[Writable]]': false });\n\t\t}\n\t\treturn true;\n\t},\n\n\t// https://www.ecma-international.org/ecma-262/6.0/#sec-createhtml\n\tCreateHTML: function CreateHTML(string, tag, attribute, value) {\n\t\tif (this.Type(tag) !== 'String' || this.Type(attribute) !== 'String') {\n\t\t\tthrow new $TypeError('Assertion failed: `tag` and `attribute` must be strings');\n\t\t}\n\t\tvar str = this.RequireObjectCoercible(string);\n\t\tvar S = this.ToString(str);\n\t\tvar p1 = '<' + tag;\n\t\tif (attribute !== '') {\n\t\t\tvar V = this.ToString(value);\n\t\t\tvar escapedV = $replace(V, /\\x22/g, '"');\n\t\t\tp1 += '\\x20' + attribute + '\\x3D\\x22' + escapedV + '\\x22';\n\t\t}\n\t\treturn p1 + '>' + S + '' + tag + '>';\n\t},\n\n\t// https://www.ecma-international.org/ecma-262/6.0/#sec-getownpropertykeys\n\tGetOwnPropertyKeys: function GetOwnPropertyKeys(O, Type) {\n\t\tif (this.Type(O) !== 'Object') {\n\t\t\tthrow new $TypeError('Assertion failed: Type(O) is not Object');\n\t\t}\n\t\tif (Type === 'Symbol') {\n\t\t\treturn hasSymbols && $gOPS ? $gOPS(O) : [];\n\t\t}\n\t\tif (Type === 'String') {\n\t\t\tif (!$gOPN) {\n\t\t\t\treturn keys(O);\n\t\t\t}\n\t\t\treturn $gOPN(O);\n\t\t}\n\t\tthrow new $TypeError('Assertion failed: `Type` must be `\"String\"` or `\"Symbol\"`');\n\t},\n\n\t// https://www.ecma-international.org/ecma-262/6.0/#sec-symboldescriptivestring\n\tSymbolDescriptiveString: function SymbolDescriptiveString(sym) {\n\t\tif (this.Type(sym) !== 'Symbol') {\n\t\t\tthrow new $TypeError('Assertion failed: `sym` must be a Symbol');\n\t\t}\n\t\treturn $SymbolToString(sym);\n\t},\n\n\t// https://www.ecma-international.org/ecma-262/6.0/#sec-getsubstitution\n\t// eslint-disable-next-line max-statements, max-params, max-lines-per-function\n\tGetSubstitution: function GetSubstitution(matched, str, position, captures, replacement) {\n\t\tif (this.Type(matched) !== 'String') {\n\t\t\tthrow new $TypeError('Assertion failed: `matched` must be a String');\n\t\t}\n\t\tvar matchLength = matched.length;\n\n\t\tif (this.Type(str) !== 'String') {\n\t\t\tthrow new $TypeError('Assertion failed: `str` must be a String');\n\t\t}\n\t\tvar stringLength = str.length;\n\n\t\tif (!this.IsInteger(position) || position < 0 || position > stringLength) {\n\t\t\tthrow new $TypeError('Assertion failed: `position` must be a nonnegative integer, and less than or equal to the length of `string`, got ' + inspect(position));\n\t\t}\n\n\t\tvar ES = this;\n\t\tvar isStringOrHole = function (capture, index, arr) { return ES.Type(capture) === 'String' || !(index in arr); };\n\t\tif (!this.IsArray(captures) || !every(captures, isStringOrHole)) {\n\t\t\tthrow new $TypeError('Assertion failed: `captures` must be a List of Strings, got ' + inspect(captures));\n\t\t}\n\n\t\tif (this.Type(replacement) !== 'String') {\n\t\t\tthrow new $TypeError('Assertion failed: `replacement` must be a String');\n\t\t}\n\n\t\tvar tailPos = position + matchLength;\n\t\tvar m = captures.length;\n\n\t\tvar result = '';\n\t\tfor (var i = 0; i < replacement.length; i += 1) {\n\t\t\t// if this is a $, and it's not the end of the replacement\n\t\t\tvar current = replacement[i];\n\t\t\tvar isLast = (i + 1) >= replacement.length;\n\t\t\tvar nextIsLast = (i + 2) >= replacement.length;\n\t\t\tif (current === '$' && !isLast) {\n\t\t\t\tvar next = replacement[i + 1];\n\t\t\t\tif (next === '$') {\n\t\t\t\t\tresult += '$';\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (next === '&') {\n\t\t\t\t\tresult += matched;\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (next === '`') {\n\t\t\t\t\tresult += position === 0 ? '' : strSlice(str, 0, position - 1);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (next === \"'\") {\n\t\t\t\t\tresult += tailPos >= stringLength ? '' : strSlice(str, tailPos);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tvar nextNext = nextIsLast ? null : replacement[i + 2];\n\t\t\t\t\tif (isDigit(next) && next !== '0' && (nextIsLast || !isDigit(nextNext))) {\n\t\t\t\t\t\t// $1 through $9, and not followed by a digit\n\t\t\t\t\t\tvar n = parseInteger(next, 10);\n\t\t\t\t\t\t// if (n > m, impl-defined)\n\t\t\t\t\t\tresult += (n <= m && this.Type(captures[n - 1]) === 'Undefined') ? '' : captures[n - 1];\n\t\t\t\t\t\ti += 1;\n\t\t\t\t\t} else if (isDigit(next) && (nextIsLast || isDigit(nextNext))) {\n\t\t\t\t\t\t// $00 through $99\n\t\t\t\t\t\tvar nn = next + nextNext;\n\t\t\t\t\t\tvar nnI = parseInteger(nn, 10) - 1;\n\t\t\t\t\t\t// if nn === '00' or nn > m, impl-defined\n\t\t\t\t\t\tresult += (nn <= m && this.Type(captures[nnI]) === 'Undefined') ? '' : captures[nnI];\n\t\t\t\t\t\ti += 2;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult += '$';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// the final $, or else not a $\n\t\t\t\tresult += replacement[i];\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t},\n\n\t// https://ecma-international.org/ecma-262/6.0/#sec-todatestring\n\tToDateString: function ToDateString(tv) {\n\t\tif (this.Type(tv) !== 'Number') {\n\t\t\tthrow new $TypeError('Assertion failed: `tv` must be a Number');\n\t\t}\n\t\tif ($isNaN(tv)) {\n\t\t\treturn 'Invalid Date';\n\t\t}\n\t\treturn $Date(tv);\n\t}\n});\n\ndelete ES6.CheckObjectCoercible; // renamed in ES6 to RequireObjectCoercible\n\nmodule.exports = ES6;\n","'use strict';\n\nmodule.exports = require('./es2015');\n","'use strict';\n\nvar ES = require('es-abstract/es6');\n\nmodule.exports = function find(predicate) {\n\tvar list = ES.ToObject(this);\n\tvar length = ES.ToLength(list.length);\n\tif (!ES.IsCallable(predicate)) {\n\t\tthrow new TypeError('Array#find: predicate must be a function');\n\t}\n\tif (length === 0) {\n\t\treturn void 0;\n\t}\n\tvar thisArg;\n\tif (arguments.length > 0) {\n\t\tthisArg = arguments[1];\n\t}\n\n\tfor (var i = 0, value; i < length; i++) {\n\t\tvalue = list[i];\n\t\t// inlined for performance: if (ES.Call(predicate, thisArg, [value, i, list])) {\n\t\tif (predicate.apply(thisArg, [value, i, list])) {\n\t\t\treturn value;\n\t\t}\n\t}\n\treturn void 0;\n};\n","'use strict';\n\nmodule.exports = function getPolyfill() {\n\t// Detect if an implementation exists\n\t// Detect early implementations which skipped holes in sparse arrays\n\t// eslint-disable-next-line no-sparse-arrays\n\tvar implemented = Array.prototype.find && [, 1].find(function () {\n\t\treturn true;\n\t}) !== 1;\n\n\t// eslint-disable-next-line global-require\n\treturn implemented ? Array.prototype.find : require('./implementation');\n};\n","'use strict';\n\nvar define = require('define-properties');\nvar getPolyfill = require('./polyfill');\n\nmodule.exports = function shimArrayPrototypeFind() {\n\tvar polyfill = getPolyfill();\n\n\tdefine(Array.prototype, { find: polyfill }, {\n\t\tfind: function () {\n\t\t\treturn Array.prototype.find !== polyfill;\n\t\t}\n\t});\n\n\treturn polyfill;\n};\n","'use strict';\n\nvar define = require('define-properties');\nvar ES = require('es-abstract/es6');\n\nvar implementation = require('./implementation');\nvar getPolyfill = require('./polyfill');\nvar shim = require('./shim');\n\nvar slice = Array.prototype.slice;\n\nvar polyfill = getPolyfill();\n\nvar boundFindShim = function find(array, predicate) { // eslint-disable-line no-unused-vars\n\tES.RequireObjectCoercible(array);\n\tvar args = slice.call(arguments, 1);\n\treturn polyfill.apply(array, args);\n};\n\ndefine(boundFindShim, {\n\tgetPolyfill: getPolyfill,\n\timplementation: implementation,\n\tshim: shim\n});\n\nmodule.exports = boundFindShim;\n","// Array.prototype.findIndex - MIT License (c) 2013 Paul Miller \n// For all details and docs: \n'use strict';\nvar ES = require('es-abstract/es6');\n\nmodule.exports = function findIndex(predicate) {\n\tvar list = ES.ToObject(this);\n\tvar length = ES.ToLength(list.length);\n\tif (!ES.IsCallable(predicate)) {\n\t\tthrow new TypeError('Array#findIndex: predicate must be a function');\n\t}\n\tif (length === 0) return -1;\n\tvar thisArg = arguments[1];\n\tfor (var i = 0, value; i < length; i++) {\n\t\tvalue = list[i];\n\t\tif (ES.Call(predicate, thisArg, [value, i, list])) return i;\n\t}\n\treturn -1;\n};\n","'use strict';\n\nmodule.exports = function getPolyfill() {\n\t// Detect if an implementation exists\n\t// Detect early implementations which skipped holes in sparse arrays\n\tvar implemented = Array.prototype.findIndex && ([, 1].findIndex(function (item, idx) {\n\t\treturn idx === 0;\n\t}) === 0);\n\n\n\treturn implemented ? Array.prototype.findIndex : require('./implementation');\n};\n","'use strict';\n\nvar define = require('define-properties');\nvar getPolyfill = require('./polyfill');\n\nmodule.exports = function shimArrayPrototypeFindIndex() {\n\tvar polyfill = getPolyfill();\n\n\tdefine(Array.prototype, { findIndex: polyfill }, {\n\t\tfindIndex: function () {\n\t\t\treturn Array.prototype.findIndex !== polyfill;\n\t\t}\n\t});\n\n\treturn polyfill;\n};\n","'use strict';\n\nvar define = require('define-properties');\nvar ES = require('es-abstract/es6');\n\nvar implementation = require('./implementation');\nvar getPolyfill = require('./polyfill');\nvar shim = require('./shim');\n\nvar slice = Array.prototype.slice;\n\nvar polyfill = getPolyfill();\n\nvar boundShim = function findIndex(array, predicate) {\n\tES.RequireObjectCoercible(array);\n\tvar args = slice.call(arguments, 1);\n\treturn polyfill.apply(array, args);\n};\n\ndefine(boundShim, {\n\timplementation: implementation,\n\tgetPolyfill: getPolyfill,\n\tshim: shim\n});\n\nmodule.exports = boundShim;\n","'use strict';\nvar ES = require('es-abstract/es6');\nvar supportsDescriptors = require('define-properties').supportsDescriptors;\n\n/*! https://mths.be/array-from v0.2.0 by @mathias */\nmodule.exports = function from(arrayLike) {\n\tvar defineProperty = supportsDescriptors ? Object.defineProperty : function put(object, key, descriptor) {\n\t\tobject[key] = descriptor.value;\n\t};\n\tvar C = this;\n\tif (arrayLike === null || typeof arrayLike === 'undefined') {\n\t\tthrow new TypeError('`Array.from` requires an array-like object, not `null` or `undefined`');\n\t}\n\tvar items = ES.ToObject(arrayLike);\n\n\tvar mapFn, T;\n\tif (typeof arguments[1] !== 'undefined') {\n\t\tmapFn = arguments[1];\n\t\tif (!ES.IsCallable(mapFn)) {\n\t\t\tthrow new TypeError('When provided, the second argument to `Array.from` must be a function');\n\t\t}\n\t\tif (arguments.length > 2) {\n\t\t\tT = arguments[2];\n\t\t}\n\t}\n\n\tvar len = ES.ToLength(items.length);\n\tvar A = ES.IsCallable(C) ? ES.ToObject(new C(len)) : new Array(len);\n\tvar k = 0;\n\tvar kValue, mappedValue;\n\twhile (k < len) {\n\t\tkValue = items[k];\n\t\tif (mapFn) {\n\t\t\tmappedValue = typeof T === 'undefined' ? mapFn(kValue, k) : ES.Call(mapFn, T, [kValue, k]);\n\t\t} else {\n\t\t\tmappedValue = kValue;\n\t\t}\n\t\tdefineProperty(A, k, {\n\t\t\t'configurable': true,\n\t\t\t'enumerable': true,\n\t\t\t'value': mappedValue,\n\t\t\t'writable': true\n\t\t});\n\t\tk += 1;\n\t}\n\tA.length = len;\n\treturn A;\n};\n","'use strict';\n\nvar ES = require('es-abstract/es6');\nvar implementation = require('./implementation');\n\nvar tryCall = function (fn) {\n\ttry {\n\t\tfn();\n\t\treturn true;\n\t} catch (e) {\n\t\treturn false;\n\t}\n};\n\nmodule.exports = function getPolyfill() {\n\tvar implemented = ES.IsCallable(Array.from)\n\t\t&& tryCall(function () { Array.from({ 'length': -Infinity }); })\n\t\t&& !tryCall(function () { Array.from([], undefined); });\n\n\treturn implemented ? Array.from : implementation;\n};\n","'use strict';\n\nvar define = require('define-properties');\nvar getPolyfill = require('./polyfill');\n\nmodule.exports = function shimArrayFrom() {\n\tvar polyfill = getPolyfill();\n\n\tdefine(Array, { 'from': polyfill }, {\n\t\t'from': function () {\n\t\t\treturn Array.from !== polyfill;\n\t\t}\n\t});\n\n\treturn polyfill;\n};\n","'use strict';\n\nvar define = require('define-properties');\n\nvar implementation = require('./implementation');\nvar getPolyfill = require('./polyfill');\nvar shim = require('./shim');\n\n// eslint-disable-next-line no-unused-vars\nvar boundFromShim = function from(array) {\n // eslint-disable-next-line no-invalid-this\n\treturn implementation.apply(this || Array, arguments);\n};\n\ndefine(boundFromShim, {\n\t'getPolyfill': getPolyfill,\n\t'implementation': implementation,\n\t'shim': shim\n});\n\nmodule.exports = boundFromShim;\n","'use strict';\n\nvar hasSymbols = require('has-symbols')();\n\nvar ES2015 = require('./es2015');\nvar assign = require('./helpers/assign');\n\nvar callBound = require('./helpers/callBound');\n\nvar $arrayPush = callBound('Array.prototype.push');\nvar $arraySlice = callBound('Array.prototype.slice');\nvar $arrayJoin = callBound('Array.prototype.join');\n\nvar ES2016 = assign(assign({}, ES2015), {\n\t// https://www.ecma-international.org/ecma-262/7.0/#sec-samevaluenonnumber\n\tSameValueNonNumber: function SameValueNonNumber(x, y) {\n\t\tif (typeof x === 'number' || typeof x !== typeof y) {\n\t\t\tthrow new TypeError('SameValueNonNumber requires two non-number values of the same type.');\n\t\t}\n\t\treturn this.SameValue(x, y);\n\t},\n\n\t// https://www.ecma-international.org/ecma-262/7.0/#sec-iterabletoarraylike\n\tIterableToArrayLike: function IterableToArrayLike(items) {\n\t\tvar usingIterator;\n\t\tif (hasSymbols) {\n\t\t\tusingIterator = this.GetMethod(items, Symbol.iterator);\n\t\t} else if (this.IsArray(items)) {\n\t\t\tusingIterator = function () {\n\t\t\t\tvar i = -1;\n\t\t\t\tvar arr = this; // eslint-disable-line no-invalid-this\n\t\t\t\treturn {\n\t\t\t\t\tnext: function () {\n\t\t\t\t\t\ti += 1;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tdone: i >= arr.length,\n\t\t\t\t\t\t\tvalue: arr[i]\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t};\n\t\t} else if (this.Type(items) === 'String') {\n\t\t\tvar ES = this;\n\t\t\tusingIterator = function () {\n\t\t\t\tvar i = 0;\n\t\t\t\treturn {\n\t\t\t\t\tnext: function () {\n\t\t\t\t\t\tvar nextIndex = ES.AdvanceStringIndex(items, i, true);\n\t\t\t\t\t\tvar value = $arrayJoin($arraySlice(items, i, nextIndex), '');\n\t\t\t\t\t\ti = nextIndex;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tdone: nextIndex > items.length,\n\t\t\t\t\t\t\tvalue: value\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t};\n\t\t}\n\t\tif (typeof usingIterator !== 'undefined') {\n\t\t\tvar iterator = this.GetIterator(items, usingIterator);\n\t\t\tvar values = [];\n\t\t\tvar next = true;\n\t\t\twhile (next) {\n\t\t\t\tnext = this.IteratorStep(iterator);\n\t\t\t\tif (next) {\n\t\t\t\t\tvar nextValue = this.IteratorValue(next);\n\t\t\t\t\t$arrayPush(values, nextValue);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn values;\n\t\t}\n\n\t\treturn this.ToObject(items);\n\t}\n});\n\nmodule.exports = ES2016;\n","'use strict';\n\nmodule.exports = require('./es2016');\n","'use strict';\n\nvar ES = require('es-abstract/es7');\nvar has = require('has');\nvar bind = require('function-bind');\nvar isEnumerable = bind.call(Function.call, Object.prototype.propertyIsEnumerable);\n\nmodule.exports = function values(O) {\n\tvar obj = ES.RequireObjectCoercible(O);\n\tvar vals = [];\n\tfor (var key in obj) {\n\t\tif (has(obj, key) && isEnumerable(obj, key)) {\n\t\t\tvals.push(obj[key]);\n\t\t}\n\t}\n\treturn vals;\n};\n","'use strict';\n\nvar implementation = require('./implementation');\n\nmodule.exports = function getPolyfill() {\n\treturn typeof Object.values === 'function' ? Object.values : implementation;\n};\n","'use strict';\n\nvar getPolyfill = require('./polyfill');\nvar define = require('define-properties');\n\nmodule.exports = function shimValues() {\n\tvar polyfill = getPolyfill();\n\tdefine(Object, { values: polyfill }, {\n\t\tvalues: function testValues() {\n\t\t\treturn Object.values !== polyfill;\n\t\t}\n\t});\n\treturn polyfill;\n};\n","'use strict';\n\nvar define = require('define-properties');\n\nvar implementation = require('./implementation');\nvar getPolyfill = require('./polyfill');\nvar shim = require('./shim');\n\nvar polyfill = getPolyfill();\n\ndefine(polyfill, {\n\tgetPolyfill: getPolyfill,\n\timplementation: implementation,\n\tshim: shim\n});\n\nmodule.exports = polyfill;\n","'use strict';\n\n// modified from https://github.com/es-shims/es6-shim\nvar keys = require('object-keys');\nvar bind = require('function-bind');\nvar canBeObject = function (obj) {\n\treturn typeof obj !== 'undefined' && obj !== null;\n};\nvar hasSymbols = require('has-symbols/shams')();\nvar toObject = Object;\nvar push = bind.call(Function.call, Array.prototype.push);\nvar propIsEnumerable = bind.call(Function.call, Object.prototype.propertyIsEnumerable);\nvar originalGetSymbols = hasSymbols ? Object.getOwnPropertySymbols : null;\n\nmodule.exports = function assign(target, source1) {\n\tif (!canBeObject(target)) { throw new TypeError('target must be an object'); }\n\tvar objTarget = toObject(target);\n\tvar s, source, i, props, syms, value, key;\n\tfor (s = 1; s < arguments.length; ++s) {\n\t\tsource = toObject(arguments[s]);\n\t\tprops = keys(source);\n\t\tvar getSymbols = hasSymbols && (Object.getOwnPropertySymbols || originalGetSymbols);\n\t\tif (getSymbols) {\n\t\t\tsyms = getSymbols(source);\n\t\t\tfor (i = 0; i < syms.length; ++i) {\n\t\t\t\tkey = syms[i];\n\t\t\t\tif (propIsEnumerable(source, key)) {\n\t\t\t\t\tpush(props, key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (i = 0; i < props.length; ++i) {\n\t\t\tkey = props[i];\n\t\t\tvalue = source[key];\n\t\t\tif (propIsEnumerable(source, key)) {\n\t\t\t\tobjTarget[key] = value;\n\t\t\t}\n\t\t}\n\t}\n\treturn objTarget;\n};\n","'use strict';\n\nvar implementation = require('./implementation');\n\nvar lacksProperEnumerationOrder = function () {\n\tif (!Object.assign) {\n\t\treturn false;\n\t}\n\t// v8, specifically in node 4.x, has a bug with incorrect property enumeration order\n\t// note: this does not detect the bug unless there's 20 characters\n\tvar str = 'abcdefghijklmnopqrst';\n\tvar letters = str.split('');\n\tvar map = {};\n\tfor (var i = 0; i < letters.length; ++i) {\n\t\tmap[letters[i]] = letters[i];\n\t}\n\tvar obj = Object.assign({}, map);\n\tvar actual = '';\n\tfor (var k in obj) {\n\t\tactual += k;\n\t}\n\treturn str !== actual;\n};\n\nvar assignHasPendingExceptions = function () {\n\tif (!Object.assign || !Object.preventExtensions) {\n\t\treturn false;\n\t}\n\t// Firefox 37 still has \"pending exception\" logic in its Object.assign implementation,\n\t// which is 72% slower than our shim, and Firefox 40's native implementation.\n\tvar thrower = Object.preventExtensions({ 1: 2 });\n\ttry {\n\t\tObject.assign(thrower, 'xy');\n\t} catch (e) {\n\t\treturn thrower[1] === 'y';\n\t}\n\treturn false;\n};\n\nmodule.exports = function getPolyfill() {\n\tif (!Object.assign) {\n\t\treturn implementation;\n\t}\n\tif (lacksProperEnumerationOrder()) {\n\t\treturn implementation;\n\t}\n\tif (assignHasPendingExceptions()) {\n\t\treturn implementation;\n\t}\n\treturn Object.assign;\n};\n","'use strict';\n\nvar define = require('define-properties');\nvar getPolyfill = require('./polyfill');\n\nmodule.exports = function shimAssign() {\n\tvar polyfill = getPolyfill();\n\tdefine(\n\t\tObject,\n\t\t{ assign: polyfill },\n\t\t{ assign: function () { return Object.assign !== polyfill; } }\n\t);\n\treturn polyfill;\n};\n","'use strict';\n\nvar defineProperties = require('define-properties');\n\nvar implementation = require('./implementation');\nvar getPolyfill = require('./polyfill');\nvar shim = require('./shim');\n\nvar polyfill = getPolyfill();\n\ndefineProperties(polyfill, {\n\tgetPolyfill: getPolyfill,\n\timplementation: implementation,\n\tshim: shim\n});\n\nmodule.exports = polyfill;\n","/**\n * @this {Promise}\n */\nfunction finallyConstructor(callback) {\n var constructor = this.constructor;\n return this.then(\n function(value) {\n // @ts-ignore\n return constructor.resolve(callback()).then(function() {\n return value;\n });\n },\n function(reason) {\n // @ts-ignore\n return constructor.resolve(callback()).then(function() {\n // @ts-ignore\n return constructor.reject(reason);\n });\n }\n );\n}\n\nexport default finallyConstructor;\n","import promiseFinally from './finally';\n\n// Store setTimeout reference so promise-polyfill will be unaffected by\n// other code modifying setTimeout (like sinon.useFakeTimers())\nvar setTimeoutFunc = setTimeout;\n\nfunction isArray(x) {\n return Boolean(x && typeof x.length !== 'undefined');\n}\n\nfunction noop() {}\n\n// Polyfill for Function.prototype.bind\nfunction bind(fn, thisArg) {\n return function() {\n fn.apply(thisArg, arguments);\n };\n}\n\n/**\n * @constructor\n * @param {Function} fn\n */\nfunction Promise(fn) {\n if (!(this instanceof Promise))\n throw new TypeError('Promises must be constructed via new');\n if (typeof fn !== 'function') throw new TypeError('not a function');\n /** @type {!number} */\n this._state = 0;\n /** @type {!boolean} */\n this._handled = false;\n /** @type {Promise|undefined} */\n this._value = undefined;\n /** @type {!Array} */\n this._deferreds = [];\n\n doResolve(fn, this);\n}\n\nfunction handle(self, deferred) {\n while (self._state === 3) {\n self = self._value;\n }\n if (self._state === 0) {\n self._deferreds.push(deferred);\n return;\n }\n self._handled = true;\n Promise._immediateFn(function() {\n var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;\n if (cb === null) {\n (self._state === 1 ? resolve : reject)(deferred.promise, self._value);\n return;\n }\n var ret;\n try {\n ret = cb(self._value);\n } catch (e) {\n reject(deferred.promise, e);\n return;\n }\n resolve(deferred.promise, ret);\n });\n}\n\nfunction resolve(self, newValue) {\n try {\n // Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure\n if (newValue === self)\n throw new TypeError('A promise cannot be resolved with itself.');\n if (\n newValue &&\n (typeof newValue === 'object' || typeof newValue === 'function')\n ) {\n var then = newValue.then;\n if (newValue instanceof Promise) {\n self._state = 3;\n self._value = newValue;\n finale(self);\n return;\n } else if (typeof then === 'function') {\n doResolve(bind(then, newValue), self);\n return;\n }\n }\n self._state = 1;\n self._value = newValue;\n finale(self);\n } catch (e) {\n reject(self, e);\n }\n}\n\nfunction reject(self, newValue) {\n self._state = 2;\n self._value = newValue;\n finale(self);\n}\n\nfunction finale(self) {\n if (self._state === 2 && self._deferreds.length === 0) {\n Promise._immediateFn(function() {\n if (!self._handled) {\n Promise._unhandledRejectionFn(self._value);\n }\n });\n }\n\n for (var i = 0, len = self._deferreds.length; i < len; i++) {\n handle(self, self._deferreds[i]);\n }\n self._deferreds = null;\n}\n\n/**\n * @constructor\n */\nfunction Handler(onFulfilled, onRejected, promise) {\n this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;\n this.onRejected = typeof onRejected === 'function' ? onRejected : null;\n this.promise = promise;\n}\n\n/**\n * Take a potentially misbehaving resolver function and make sure\n * onFulfilled and onRejected are only called once.\n *\n * Makes no guarantees about asynchrony.\n */\nfunction doResolve(fn, self) {\n var done = false;\n try {\n fn(\n function(value) {\n if (done) return;\n done = true;\n resolve(self, value);\n },\n function(reason) {\n if (done) return;\n done = true;\n reject(self, reason);\n }\n );\n } catch (ex) {\n if (done) return;\n done = true;\n reject(self, ex);\n }\n}\n\nPromise.prototype['catch'] = function(onRejected) {\n return this.then(null, onRejected);\n};\n\nPromise.prototype.then = function(onFulfilled, onRejected) {\n // @ts-ignore\n var prom = new this.constructor(noop);\n\n handle(this, new Handler(onFulfilled, onRejected, prom));\n return prom;\n};\n\nPromise.prototype['finally'] = promiseFinally;\n\nPromise.all = function(arr) {\n return new Promise(function(resolve, reject) {\n if (!isArray(arr)) {\n return reject(new TypeError('Promise.all accepts an array'));\n }\n\n var args = Array.prototype.slice.call(arr);\n if (args.length === 0) return resolve([]);\n var remaining = args.length;\n\n function res(i, val) {\n try {\n if (val && (typeof val === 'object' || typeof val === 'function')) {\n var then = val.then;\n if (typeof then === 'function') {\n then.call(\n val,\n function(val) {\n res(i, val);\n },\n reject\n );\n return;\n }\n }\n args[i] = val;\n if (--remaining === 0) {\n resolve(args);\n }\n } catch (ex) {\n reject(ex);\n }\n }\n\n for (var i = 0; i < args.length; i++) {\n res(i, args[i]);\n }\n });\n};\n\nPromise.resolve = function(value) {\n if (value && typeof value === 'object' && value.constructor === Promise) {\n return value;\n }\n\n return new Promise(function(resolve) {\n resolve(value);\n });\n};\n\nPromise.reject = function(value) {\n return new Promise(function(resolve, reject) {\n reject(value);\n });\n};\n\nPromise.race = function(arr) {\n return new Promise(function(resolve, reject) {\n if (!isArray(arr)) {\n return reject(new TypeError('Promise.race accepts an array'));\n }\n\n for (var i = 0, len = arr.length; i < len; i++) {\n Promise.resolve(arr[i]).then(resolve, reject);\n }\n });\n};\n\n// Use polyfill for setImmediate for performance gains\nPromise._immediateFn =\n // @ts-ignore\n (typeof setImmediate === 'function' &&\n function(fn) {\n // @ts-ignore\n setImmediate(fn);\n }) ||\n function(fn) {\n setTimeoutFunc(fn, 0);\n };\n\nPromise._unhandledRejectionFn = function _unhandledRejectionFn(err) {\n if (typeof console !== 'undefined' && console) {\n console.warn('Possible Unhandled Promise Rejection:', err); // eslint-disable-line no-console\n }\n};\n\nexport default Promise;\n","import Promise from './index';\nimport promiseFinally from './finally';\n\n/** @suppress {undefinedVars} */\nvar globalNS = (function() {\n // the only reliable means to get the global object is\n // `Function('return this')()`\n // However, this causes CSP violations in Chrome apps.\n if (typeof self !== 'undefined') {\n return self;\n }\n if (typeof window !== 'undefined') {\n return window;\n }\n if (typeof global !== 'undefined') {\n return global;\n }\n throw new Error('unable to locate global object');\n})();\n\nif (!('Promise' in globalNS)) {\n globalNS['Promise'] = Promise;\n} else if (!globalNS.Promise.prototype['finally']) {\n globalNS.Promise.prototype['finally'] = promiseFinally;\n}\n","(function (thisVar, undefined) {\n\t'use strict';\n\tvar main = (typeof window === 'object' && window) || (typeof global === 'object' && global) ||\n\t\ttypeof self === 'object' && self || thisVar;\n\n\tvar hasSetImmediate = typeof setImmediate === 'function';\n\tvar hasNextTick = typeof process === 'object' && !!process && typeof process.nextTick === 'function';\n\tvar index = 0;\n\n\tfunction getNewIndex() {\n\t\tif (index === 9007199254740991) {\n\t\t\treturn 0;\n\t\t}\n\t\treturn ++index;\n\t}\n\n\tvar setAsap = (function () {\n\t\tvar hiddenDiv, scriptEl, timeoutFn, callbacks;\n\n\t\t// Modern browsers, fastest async\n\t\tif (main.MutationObserver) {\n\t\t\treturn function setAsap(callback) {\n\t\t\t\thiddenDiv = document.createElement(\"div\");\n\t\t\t\t(new MutationObserver(function() {\n\t\t\t\t\tcallback();\n\t\t\t\t\thiddenDiv = null;\n\t\t\t\t})).observe(hiddenDiv, { attributes: true });\n\t\t\t\thiddenDiv.setAttribute('i', '1');\n\t\t\t};\n\n\t\t// Browsers that support postMessage\n\t\t} else if (!hasSetImmediate && main.postMessage && !main.importScripts && main.addEventListener) {\n\n\t\t\tvar MESSAGE_PREFIX = \"com.setImmediate\" + Math.random();\n\t\t\tcallbacks = {};\n\n\t\t\tvar onGlobalMessage = function (event) {\n\t\t\t\tif (event.source === main && event.data.indexOf(MESSAGE_PREFIX) === 0) {\n\t\t\t\t\tvar i = +event.data.split(':')[1];\n\t\t\t\t\tcallbacks[i]();\n\t\t\t\t\tdelete callbacks[i];\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tmain.addEventListener(\"message\", onGlobalMessage, false);\n\n\t\t\treturn function setAsap(callback) {\n\t\t\t\tvar i = getNewIndex();\n\t\t\t\tcallbacks[i] = callback;\n\t\t\t\tmain.postMessage(MESSAGE_PREFIX + ':' + i, \"*\");\n\t\t\t};\n\n\t\t\t// IE browsers without postMessage\n\t\t} else if (!hasSetImmediate && main.document && 'onreadystatechange' in document.createElement('script')) {\n\n\t\t\treturn function setAsap(callback) {\n\t\t\t\tscriptEl = document.createElement(\"script\");\n\t\t\t\tscriptEl.onreadystatechange = function onreadystatechange() {\n\t\t\t\t\tscriptEl.onreadystatechange = null;\n\t\t\t\t\tscriptEl.parentNode.removeChild(scriptEl);\n\t\t\t\t\tscriptEl = null;\n\t\t\t\t\tcallback();\n\t\t\t\t};\n\t\t\t\tdocument.body.appendChild(scriptEl);\n\t\t\t};\n\n\t\t// All other browsers and node\n\t\t} else {\n\n\t\t\ttimeoutFn = (hasSetImmediate && setImmediate) || (hasNextTick && process.nextTick) || setTimeout;\n\t\t\treturn function setAsap(callback) {\n\t\t\t\ttimeoutFn(callback);\n\t\t\t};\n\t\t}\n\n\t})();\n\n\tif (typeof module !== 'undefined' && module.exports) {\n\t\tmodule.exports = setAsap;\n\t} else if (typeof require !== 'undefined' && require.amd) {\n\t\tdefine(function () {\n\t\t\treturn setAsap;\n\t\t});\n\t} else {\n\t\tmain.setAsap = setAsap;\n\t}\n})(this);\n","// Generated by CoffeeScript 1.12.2\n(function() {\n var getNanoSeconds, hrtime, loadTime, moduleLoadTime, nodeLoadTime, upTime;\n\n if ((typeof performance !== \"undefined\" && performance !== null) && performance.now) {\n module.exports = function() {\n return performance.now();\n };\n } else if ((typeof process !== \"undefined\" && process !== null) && process.hrtime) {\n module.exports = function() {\n return (getNanoSeconds() - nodeLoadTime) / 1e6;\n };\n hrtime = process.hrtime;\n getNanoSeconds = function() {\n var hr;\n hr = hrtime();\n return hr[0] * 1e9 + hr[1];\n };\n moduleLoadTime = getNanoSeconds();\n upTime = process.uptime() * 1e9;\n nodeLoadTime = moduleLoadTime - upTime;\n } else if (Date.now) {\n module.exports = function() {\n return Date.now() - loadTime;\n };\n loadTime = Date.now();\n } else {\n module.exports = function() {\n return new Date().getTime() - loadTime;\n };\n loadTime = new Date().getTime();\n }\n\n}).call(this);\n\n//# sourceMappingURL=performance-now.js.map\n","var now = require('performance-now')\n , root = typeof window === 'undefined' ? global : window\n , vendors = ['moz', 'webkit']\n , suffix = 'AnimationFrame'\n , raf = root['request' + suffix]\n , caf = root['cancel' + suffix] || root['cancelRequest' + suffix]\n\nfor(var i = 0; !raf && i < vendors.length; i++) {\n raf = root[vendors[i] + 'Request' + suffix]\n caf = root[vendors[i] + 'Cancel' + suffix]\n || root[vendors[i] + 'CancelRequest' + suffix]\n}\n\n// Some versions of FF have rAF but not cAF\nif(!raf || !caf) {\n var last = 0\n , id = 0\n , queue = []\n , frameDuration = 1000 / 60\n\n raf = function(callback) {\n if(queue.length === 0) {\n var _now = now()\n , next = Math.max(0, frameDuration - (_now - last))\n last = next + _now\n setTimeout(function() {\n var cp = queue.slice(0)\n // Clear queue here to prevent\n // callbacks from appending listeners\n // to the current frame's queue\n queue.length = 0\n for(var i = 0; i < cp.length; i++) {\n if(!cp[i].cancelled) {\n try{\n cp[i].callback(last)\n } catch(e) {\n setTimeout(function() { throw e }, 0)\n }\n }\n }\n }, Math.round(next))\n }\n queue.push({\n handle: ++id,\n callback: callback,\n cancelled: false\n })\n return id\n }\n\n caf = function(handle) {\n for(var i = 0; i < queue.length; i++) {\n if(queue[i].handle === handle) {\n queue[i].cancelled = true\n }\n }\n }\n}\n\nmodule.exports = function(fn) {\n // Wrap in a new function to prevent\n // `cancel` potentially being assigned\n // to the native rAF function\n return raf.call(root, fn)\n}\nmodule.exports.cancel = function() {\n caf.apply(root, arguments)\n}\nmodule.exports.polyfill = function(object) {\n if (!object) {\n object = root;\n }\n object.requestAnimationFrame = raf\n object.cancelAnimationFrame = caf\n}\n","var support = {\n searchParams: 'URLSearchParams' in self,\n iterable: 'Symbol' in self && 'iterator' in Symbol,\n blob:\n 'FileReader' in self &&\n 'Blob' in self &&\n (function() {\n try {\n new Blob()\n return true\n } catch (e) {\n return false\n }\n })(),\n formData: 'FormData' in self,\n arrayBuffer: 'ArrayBuffer' in self\n}\n\nfunction isDataView(obj) {\n return obj && DataView.prototype.isPrototypeOf(obj)\n}\n\nif (support.arrayBuffer) {\n var viewClasses = [\n '[object Int8Array]',\n '[object Uint8Array]',\n '[object Uint8ClampedArray]',\n '[object Int16Array]',\n '[object Uint16Array]',\n '[object Int32Array]',\n '[object Uint32Array]',\n '[object Float32Array]',\n '[object Float64Array]'\n ]\n\n var isArrayBufferView =\n ArrayBuffer.isView ||\n function(obj) {\n return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1\n }\n}\n\nfunction normalizeName(name) {\n if (typeof name !== 'string') {\n name = String(name)\n }\n if (/[^a-z0-9\\-#$%&'*+.^_`|~]/i.test(name)) {\n throw new TypeError('Invalid character in header field name')\n }\n return name.toLowerCase()\n}\n\nfunction normalizeValue(value) {\n if (typeof value !== 'string') {\n value = String(value)\n }\n return value\n}\n\n// Build a destructive iterator for the value list\nfunction iteratorFor(items) {\n var iterator = {\n next: function() {\n var value = items.shift()\n return {done: value === undefined, value: value}\n }\n }\n\n if (support.iterable) {\n iterator[Symbol.iterator] = function() {\n return iterator\n }\n }\n\n return iterator\n}\n\nexport function Headers(headers) {\n this.map = {}\n\n if (headers instanceof Headers) {\n headers.forEach(function(value, name) {\n this.append(name, value)\n }, this)\n } else if (Array.isArray(headers)) {\n headers.forEach(function(header) {\n this.append(header[0], header[1])\n }, this)\n } else if (headers) {\n Object.getOwnPropertyNames(headers).forEach(function(name) {\n this.append(name, headers[name])\n }, this)\n }\n}\n\nHeaders.prototype.append = function(name, value) {\n name = normalizeName(name)\n value = normalizeValue(value)\n var oldValue = this.map[name]\n this.map[name] = oldValue ? oldValue + ', ' + value : value\n}\n\nHeaders.prototype['delete'] = function(name) {\n delete this.map[normalizeName(name)]\n}\n\nHeaders.prototype.get = function(name) {\n name = normalizeName(name)\n return this.has(name) ? this.map[name] : null\n}\n\nHeaders.prototype.has = function(name) {\n return this.map.hasOwnProperty(normalizeName(name))\n}\n\nHeaders.prototype.set = function(name, value) {\n this.map[normalizeName(name)] = normalizeValue(value)\n}\n\nHeaders.prototype.forEach = function(callback, thisArg) {\n for (var name in this.map) {\n if (this.map.hasOwnProperty(name)) {\n callback.call(thisArg, this.map[name], name, this)\n }\n }\n}\n\nHeaders.prototype.keys = function() {\n var items = []\n this.forEach(function(value, name) {\n items.push(name)\n })\n return iteratorFor(items)\n}\n\nHeaders.prototype.values = function() {\n var items = []\n this.forEach(function(value) {\n items.push(value)\n })\n return iteratorFor(items)\n}\n\nHeaders.prototype.entries = function() {\n var items = []\n this.forEach(function(value, name) {\n items.push([name, value])\n })\n return iteratorFor(items)\n}\n\nif (support.iterable) {\n Headers.prototype[Symbol.iterator] = Headers.prototype.entries\n}\n\nfunction consumed(body) {\n if (body.bodyUsed) {\n return Promise.reject(new TypeError('Already read'))\n }\n body.bodyUsed = true\n}\n\nfunction fileReaderReady(reader) {\n return new Promise(function(resolve, reject) {\n reader.onload = function() {\n resolve(reader.result)\n }\n reader.onerror = function() {\n reject(reader.error)\n }\n })\n}\n\nfunction readBlobAsArrayBuffer(blob) {\n var reader = new FileReader()\n var promise = fileReaderReady(reader)\n reader.readAsArrayBuffer(blob)\n return promise\n}\n\nfunction readBlobAsText(blob) {\n var reader = new FileReader()\n var promise = fileReaderReady(reader)\n reader.readAsText(blob)\n return promise\n}\n\nfunction readArrayBufferAsText(buf) {\n var view = new Uint8Array(buf)\n var chars = new Array(view.length)\n\n for (var i = 0; i < view.length; i++) {\n chars[i] = String.fromCharCode(view[i])\n }\n return chars.join('')\n}\n\nfunction bufferClone(buf) {\n if (buf.slice) {\n return buf.slice(0)\n } else {\n var view = new Uint8Array(buf.byteLength)\n view.set(new Uint8Array(buf))\n return view.buffer\n }\n}\n\nfunction Body() {\n this.bodyUsed = false\n\n this._initBody = function(body) {\n this._bodyInit = body\n if (!body) {\n this._bodyText = ''\n } else if (typeof body === 'string') {\n this._bodyText = body\n } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {\n this._bodyBlob = body\n } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {\n this._bodyFormData = body\n } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {\n this._bodyText = body.toString()\n } else if (support.arrayBuffer && support.blob && isDataView(body)) {\n this._bodyArrayBuffer = bufferClone(body.buffer)\n // IE 10-11 can't handle a DataView body.\n this._bodyInit = new Blob([this._bodyArrayBuffer])\n } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {\n this._bodyArrayBuffer = bufferClone(body)\n } else {\n this._bodyText = body = Object.prototype.toString.call(body)\n }\n\n if (!this.headers.get('content-type')) {\n if (typeof body === 'string') {\n this.headers.set('content-type', 'text/plain;charset=UTF-8')\n } else if (this._bodyBlob && this._bodyBlob.type) {\n this.headers.set('content-type', this._bodyBlob.type)\n } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {\n this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8')\n }\n }\n }\n\n if (support.blob) {\n this.blob = function() {\n var rejected = consumed(this)\n if (rejected) {\n return rejected\n }\n\n if (this._bodyBlob) {\n return Promise.resolve(this._bodyBlob)\n } else if (this._bodyArrayBuffer) {\n return Promise.resolve(new Blob([this._bodyArrayBuffer]))\n } else if (this._bodyFormData) {\n throw new Error('could not read FormData body as blob')\n } else {\n return Promise.resolve(new Blob([this._bodyText]))\n }\n }\n\n this.arrayBuffer = function() {\n if (this._bodyArrayBuffer) {\n return consumed(this) || Promise.resolve(this._bodyArrayBuffer)\n } else {\n return this.blob().then(readBlobAsArrayBuffer)\n }\n }\n }\n\n this.text = function() {\n var rejected = consumed(this)\n if (rejected) {\n return rejected\n }\n\n if (this._bodyBlob) {\n return readBlobAsText(this._bodyBlob)\n } else if (this._bodyArrayBuffer) {\n return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))\n } else if (this._bodyFormData) {\n throw new Error('could not read FormData body as text')\n } else {\n return Promise.resolve(this._bodyText)\n }\n }\n\n if (support.formData) {\n this.formData = function() {\n return this.text().then(decode)\n }\n }\n\n this.json = function() {\n return this.text().then(JSON.parse)\n }\n\n return this\n}\n\n// HTTP methods whose capitalization should be normalized\nvar methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']\n\nfunction normalizeMethod(method) {\n var upcased = method.toUpperCase()\n return methods.indexOf(upcased) > -1 ? upcased : method\n}\n\nexport function Request(input, options) {\n options = options || {}\n var body = options.body\n\n if (input instanceof Request) {\n if (input.bodyUsed) {\n throw new TypeError('Already read')\n }\n this.url = input.url\n this.credentials = input.credentials\n if (!options.headers) {\n this.headers = new Headers(input.headers)\n }\n this.method = input.method\n this.mode = input.mode\n this.signal = input.signal\n if (!body && input._bodyInit != null) {\n body = input._bodyInit\n input.bodyUsed = true\n }\n } else {\n this.url = String(input)\n }\n\n this.credentials = options.credentials || this.credentials || 'same-origin'\n if (options.headers || !this.headers) {\n this.headers = new Headers(options.headers)\n }\n this.method = normalizeMethod(options.method || this.method || 'GET')\n this.mode = options.mode || this.mode || null\n this.signal = options.signal || this.signal\n this.referrer = null\n\n if ((this.method === 'GET' || this.method === 'HEAD') && body) {\n throw new TypeError('Body not allowed for GET or HEAD requests')\n }\n this._initBody(body)\n}\n\nRequest.prototype.clone = function() {\n return new Request(this, {body: this._bodyInit})\n}\n\nfunction decode(body) {\n var form = new FormData()\n body\n .trim()\n .split('&')\n .forEach(function(bytes) {\n if (bytes) {\n var split = bytes.split('=')\n var name = split.shift().replace(/\\+/g, ' ')\n var value = split.join('=').replace(/\\+/g, ' ')\n form.append(decodeURIComponent(name), decodeURIComponent(value))\n }\n })\n return form\n}\n\nfunction parseHeaders(rawHeaders) {\n var headers = new Headers()\n // Replace instances of \\r\\n and \\n followed by at least one space or horizontal tab with a space\n // https://tools.ietf.org/html/rfc7230#section-3.2\n var preProcessedHeaders = rawHeaders.replace(/\\r?\\n[\\t ]+/g, ' ')\n preProcessedHeaders.split(/\\r?\\n/).forEach(function(line) {\n var parts = line.split(':')\n var key = parts.shift().trim()\n if (key) {\n var value = parts.join(':').trim()\n headers.append(key, value)\n }\n })\n return headers\n}\n\nBody.call(Request.prototype)\n\nexport function Response(bodyInit, options) {\n if (!options) {\n options = {}\n }\n\n this.type = 'default'\n this.status = options.status === undefined ? 200 : options.status\n this.ok = this.status >= 200 && this.status < 300\n this.statusText = 'statusText' in options ? options.statusText : 'OK'\n this.headers = new Headers(options.headers)\n this.url = options.url || ''\n this._initBody(bodyInit)\n}\n\nBody.call(Response.prototype)\n\nResponse.prototype.clone = function() {\n return new Response(this._bodyInit, {\n status: this.status,\n statusText: this.statusText,\n headers: new Headers(this.headers),\n url: this.url\n })\n}\n\nResponse.error = function() {\n var response = new Response(null, {status: 0, statusText: ''})\n response.type = 'error'\n return response\n}\n\nvar redirectStatuses = [301, 302, 303, 307, 308]\n\nResponse.redirect = function(url, status) {\n if (redirectStatuses.indexOf(status) === -1) {\n throw new RangeError('Invalid status code')\n }\n\n return new Response(null, {status: status, headers: {location: url}})\n}\n\nexport var DOMException = self.DOMException\ntry {\n new DOMException()\n} catch (err) {\n DOMException = function(message, name) {\n this.message = message\n this.name = name\n var error = Error(message)\n this.stack = error.stack\n }\n DOMException.prototype = Object.create(Error.prototype)\n DOMException.prototype.constructor = DOMException\n}\n\nexport function fetch(input, init) {\n return new Promise(function(resolve, reject) {\n var request = new Request(input, init)\n\n if (request.signal && request.signal.aborted) {\n return reject(new DOMException('Aborted', 'AbortError'))\n }\n\n var xhr = new XMLHttpRequest()\n\n function abortXhr() {\n xhr.abort()\n }\n\n xhr.onload = function() {\n var options = {\n status: xhr.status,\n statusText: xhr.statusText,\n headers: parseHeaders(xhr.getAllResponseHeaders() || '')\n }\n options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL')\n var body = 'response' in xhr ? xhr.response : xhr.responseText\n resolve(new Response(body, options))\n }\n\n xhr.onerror = function() {\n reject(new TypeError('Network request failed'))\n }\n\n xhr.ontimeout = function() {\n reject(new TypeError('Network request failed'))\n }\n\n xhr.onabort = function() {\n reject(new DOMException('Aborted', 'AbortError'))\n }\n\n xhr.open(request.method, request.url, true)\n\n if (request.credentials === 'include') {\n xhr.withCredentials = true\n } else if (request.credentials === 'omit') {\n xhr.withCredentials = false\n }\n\n if ('responseType' in xhr && support.blob) {\n xhr.responseType = 'blob'\n }\n\n request.headers.forEach(function(value, name) {\n xhr.setRequestHeader(name, value)\n })\n\n if (request.signal) {\n request.signal.addEventListener('abort', abortXhr)\n\n xhr.onreadystatechange = function() {\n // DONE (success or failure)\n if (xhr.readyState === 4) {\n request.signal.removeEventListener('abort', abortXhr)\n }\n }\n }\n\n xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit)\n })\n}\n\nfetch.polyfill = true\n\nif (!self.fetch) {\n self.fetch = fetch\n self.Headers = Headers\n self.Request = Request\n self.Response = Response\n}\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar setPolyfill = require(\"es6-set\");\nvar mapPolyfill = require(\"es6-map\");\nvar arrayFindPolyfill = require(\"array.prototype.find\");\nvar arrayFindIndexPolyfill = require(\"array.prototype.findindex\");\nvar arrayFromPolyfill = require(\"array.from\");\nvar objectValuesPolyfill = require(\"object.values\");\nvar objectAssignPolyfill = require(\"object.assign\");\nvar promisePolyfill = require(\"promise-polyfill/src/polyfill\");\nvar setAsap = require(\"setasap\");\nvar rafPolyfill = require(\"raf\");\nif (!window.Set) {\n window.Set = setPolyfill;\n}\nif (!window.Map) {\n window.Map = mapPolyfill;\n}\nif (!window.Promise) {\n window.Promise = promisePolyfill;\n window.Promise._immediateFn = setAsap;\n}\nif (!Array.prototype.find) {\n arrayFindPolyfill.shim();\n}\nif (!Array.prototype.findIndex) {\n arrayFindIndexPolyfill.shim();\n}\nif (!Array.from) {\n arrayFromPolyfill.shim();\n}\nif (!Object.values) {\n objectValuesPolyfill.shim();\n}\nif (!Object.assign) {\n objectAssignPolyfill.shim();\n}\nif (!window.requestAnimationFrame || !window.cancelAnimationFrame) {\n window.requestAnimationFrame = rafPolyfill;\n window.cancelAnimationFrame = rafPolyfill.cancel;\n}\nrequire(\"whatwg-fetch\");\nvar finalFetch = window.fetch;\nvar finalPromise = window.Promise;\nwindow.fetch = function (input, init) {\n try {\n return finalFetch(input, init);\n }\n catch (error) {\n return new finalPromise(function (_, reject) { return reject(error); });\n }\n};\n","'use strict';\n\n/* eslint complexity: [2, 18], max-statements: [2, 33] */\nmodule.exports = function hasSymbols() {\n\tif (typeof Symbol !== 'function' || typeof Object.getOwnPropertySymbols !== 'function') { return false; }\n\tif (typeof Symbol.iterator === 'symbol') { return true; }\n\n\tvar obj = {};\n\tvar sym = Symbol('test');\n\tvar symObj = Object(sym);\n\tif (typeof sym === 'string') { return false; }\n\n\tif (Object.prototype.toString.call(sym) !== '[object Symbol]') { return false; }\n\tif (Object.prototype.toString.call(symObj) !== '[object Symbol]') { return false; }\n\n\t// temp disabled per https://github.com/ljharb/object.assign/issues/17\n\t// if (sym instanceof Symbol) { return false; }\n\t// temp disabled per https://github.com/WebReflection/get-own-property-symbols/issues/4\n\t// if (!(symObj instanceof Symbol)) { return false; }\n\n\t// if (typeof Symbol.prototype.toString !== 'function') { return false; }\n\t// if (String(sym) !== Symbol.prototype.toString.call(sym)) { return false; }\n\n\tvar symVal = 42;\n\tobj[sym] = symVal;\n\tfor (sym in obj) { return false; } // eslint-disable-line no-restricted-syntax\n\tif (typeof Object.keys === 'function' && Object.keys(obj).length !== 0) { return false; }\n\n\tif (typeof Object.getOwnPropertyNames === 'function' && Object.getOwnPropertyNames(obj).length !== 0) { return false; }\n\n\tvar syms = Object.getOwnPropertySymbols(obj);\n\tif (syms.length !== 1 || syms[0] !== sym) { return false; }\n\n\tif (!Object.prototype.propertyIsEnumerable.call(obj, sym)) { return false; }\n\n\tif (typeof Object.getOwnPropertyDescriptor === 'function') {\n\t\tvar descriptor = Object.getOwnPropertyDescriptor(obj, sym);\n\t\tif (descriptor.value !== symVal || descriptor.enumerable !== true) { return false; }\n\t}\n\n\treturn true;\n};\n","'use strict';\n\nvar origSymbol = global.Symbol;\nvar hasSymbolSham = require('./shams');\n\nmodule.exports = function hasNativeSymbols() {\n\tif (typeof origSymbol !== 'function') { return false; }\n\tif (typeof Symbol !== 'function') { return false; }\n\tif (typeof origSymbol('foo') !== 'symbol') { return false; }\n\tif (typeof Symbol('bar') !== 'symbol') { return false; }\n\n\treturn hasSymbolSham();\n};\n","'use strict';\n\n/* globals\n\tAtomics,\n\tSharedArrayBuffer,\n*/\n\nvar undefined;\n\nvar $TypeError = TypeError;\n\nvar $gOPD = Object.getOwnPropertyDescriptor;\nif ($gOPD) {\n\ttry {\n\t\t$gOPD({}, '');\n\t} catch (e) {\n\t\t$gOPD = null; // this is IE 8, which has a broken gOPD\n\t}\n}\n\nvar throwTypeError = function () { throw new $TypeError(); };\nvar ThrowTypeError = $gOPD\n\t? (function () {\n\t\ttry {\n\t\t\t// eslint-disable-next-line no-unused-expressions, no-caller, no-restricted-properties\n\t\t\targuments.callee; // IE 8 does not throw here\n\t\t\treturn throwTypeError;\n\t\t} catch (calleeThrows) {\n\t\t\ttry {\n\t\t\t\t// IE 8 throws on Object.getOwnPropertyDescriptor(arguments, '')\n\t\t\t\treturn $gOPD(arguments, 'callee').get;\n\t\t\t} catch (gOPDthrows) {\n\t\t\t\treturn throwTypeError;\n\t\t\t}\n\t\t}\n\t}())\n\t: throwTypeError;\n\nvar hasSymbols = require('has-symbols')();\n\nvar getProto = Object.getPrototypeOf || function (x) { return x.__proto__; }; // eslint-disable-line no-proto\n\nvar generator; // = function * () {};\nvar generatorFunction = generator ? getProto(generator) : undefined;\nvar asyncFn; // async function() {};\nvar asyncFunction = asyncFn ? asyncFn.constructor : undefined;\nvar asyncGen; // async function * () {};\nvar asyncGenFunction = asyncGen ? getProto(asyncGen) : undefined;\nvar asyncGenIterator = asyncGen ? asyncGen() : undefined;\n\nvar TypedArray = typeof Uint8Array === 'undefined' ? undefined : getProto(Uint8Array);\n\nvar INTRINSICS = {\n\t'%Array%': Array,\n\t'%ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined : ArrayBuffer,\n\t'%ArrayBufferPrototype%': typeof ArrayBuffer === 'undefined' ? undefined : ArrayBuffer.prototype,\n\t'%ArrayIteratorPrototype%': hasSymbols ? getProto([][Symbol.iterator]()) : undefined,\n\t'%ArrayPrototype%': Array.prototype,\n\t'%ArrayProto_entries%': Array.prototype.entries,\n\t'%ArrayProto_forEach%': Array.prototype.forEach,\n\t'%ArrayProto_keys%': Array.prototype.keys,\n\t'%ArrayProto_values%': Array.prototype.values,\n\t'%AsyncFromSyncIteratorPrototype%': undefined,\n\t'%AsyncFunction%': asyncFunction,\n\t'%AsyncFunctionPrototype%': asyncFunction ? asyncFunction.prototype : undefined,\n\t'%AsyncGenerator%': asyncGen ? getProto(asyncGenIterator) : undefined,\n\t'%AsyncGeneratorFunction%': asyncGenFunction,\n\t'%AsyncGeneratorPrototype%': asyncGenFunction ? asyncGenFunction.prototype : undefined,\n\t'%AsyncIteratorPrototype%': asyncGenIterator && hasSymbols && Symbol.asyncIterator ? asyncGenIterator[Symbol.asyncIterator]() : undefined,\n\t'%Atomics%': typeof Atomics === 'undefined' ? undefined : Atomics,\n\t'%Boolean%': Boolean,\n\t'%BooleanPrototype%': Boolean.prototype,\n\t'%DataView%': typeof DataView === 'undefined' ? undefined : DataView,\n\t'%DataViewPrototype%': typeof DataView === 'undefined' ? undefined : DataView.prototype,\n\t'%Date%': Date,\n\t'%DatePrototype%': Date.prototype,\n\t'%decodeURI%': decodeURI,\n\t'%decodeURIComponent%': decodeURIComponent,\n\t'%encodeURI%': encodeURI,\n\t'%encodeURIComponent%': encodeURIComponent,\n\t'%Error%': Error,\n\t'%ErrorPrototype%': Error.prototype,\n\t'%eval%': eval, // eslint-disable-line no-eval\n\t'%EvalError%': EvalError,\n\t'%EvalErrorPrototype%': EvalError.prototype,\n\t'%Float32Array%': typeof Float32Array === 'undefined' ? undefined : Float32Array,\n\t'%Float32ArrayPrototype%': typeof Float32Array === 'undefined' ? undefined : Float32Array.prototype,\n\t'%Float64Array%': typeof Float64Array === 'undefined' ? undefined : Float64Array,\n\t'%Float64ArrayPrototype%': typeof Float64Array === 'undefined' ? undefined : Float64Array.prototype,\n\t'%Function%': Function,\n\t'%FunctionPrototype%': Function.prototype,\n\t'%Generator%': generator ? getProto(generator()) : undefined,\n\t'%GeneratorFunction%': generatorFunction,\n\t'%GeneratorPrototype%': generatorFunction ? generatorFunction.prototype : undefined,\n\t'%Int8Array%': typeof Int8Array === 'undefined' ? undefined : Int8Array,\n\t'%Int8ArrayPrototype%': typeof Int8Array === 'undefined' ? undefined : Int8Array.prototype,\n\t'%Int16Array%': typeof Int16Array === 'undefined' ? undefined : Int16Array,\n\t'%Int16ArrayPrototype%': typeof Int16Array === 'undefined' ? undefined : Int8Array.prototype,\n\t'%Int32Array%': typeof Int32Array === 'undefined' ? undefined : Int32Array,\n\t'%Int32ArrayPrototype%': typeof Int32Array === 'undefined' ? undefined : Int32Array.prototype,\n\t'%isFinite%': isFinite,\n\t'%isNaN%': isNaN,\n\t'%IteratorPrototype%': hasSymbols ? getProto(getProto([][Symbol.iterator]())) : undefined,\n\t'%JSON%': typeof JSON === 'object' ? JSON : undefined,\n\t'%JSONParse%': typeof JSON === 'object' ? JSON.parse : undefined,\n\t'%Map%': typeof Map === 'undefined' ? undefined : Map,\n\t'%MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols ? undefined : getProto(new Map()[Symbol.iterator]()),\n\t'%MapPrototype%': typeof Map === 'undefined' ? undefined : Map.prototype,\n\t'%Math%': Math,\n\t'%Number%': Number,\n\t'%NumberPrototype%': Number.prototype,\n\t'%Object%': Object,\n\t'%ObjectPrototype%': Object.prototype,\n\t'%ObjProto_toString%': Object.prototype.toString,\n\t'%ObjProto_valueOf%': Object.prototype.valueOf,\n\t'%parseFloat%': parseFloat,\n\t'%parseInt%': parseInt,\n\t'%Promise%': typeof Promise === 'undefined' ? undefined : Promise,\n\t'%PromisePrototype%': typeof Promise === 'undefined' ? undefined : Promise.prototype,\n\t'%PromiseProto_then%': typeof Promise === 'undefined' ? undefined : Promise.prototype.then,\n\t'%Promise_all%': typeof Promise === 'undefined' ? undefined : Promise.all,\n\t'%Promise_reject%': typeof Promise === 'undefined' ? undefined : Promise.reject,\n\t'%Promise_resolve%': typeof Promise === 'undefined' ? undefined : Promise.resolve,\n\t'%Proxy%': typeof Proxy === 'undefined' ? undefined : Proxy,\n\t'%RangeError%': RangeError,\n\t'%RangeErrorPrototype%': RangeError.prototype,\n\t'%ReferenceError%': ReferenceError,\n\t'%ReferenceErrorPrototype%': ReferenceError.prototype,\n\t'%Reflect%': typeof Reflect === 'undefined' ? undefined : Reflect,\n\t'%RegExp%': RegExp,\n\t'%RegExpPrototype%': RegExp.prototype,\n\t'%Set%': typeof Set === 'undefined' ? undefined : Set,\n\t'%SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols ? undefined : getProto(new Set()[Symbol.iterator]()),\n\t'%SetPrototype%': typeof Set === 'undefined' ? undefined : Set.prototype,\n\t'%SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined : SharedArrayBuffer,\n\t'%SharedArrayBufferPrototype%': typeof SharedArrayBuffer === 'undefined' ? undefined : SharedArrayBuffer.prototype,\n\t'%String%': String,\n\t'%StringIteratorPrototype%': hasSymbols ? getProto(''[Symbol.iterator]()) : undefined,\n\t'%StringPrototype%': String.prototype,\n\t'%Symbol%': hasSymbols ? Symbol : undefined,\n\t'%SymbolPrototype%': hasSymbols ? Symbol.prototype : undefined,\n\t'%SyntaxError%': SyntaxError,\n\t'%SyntaxErrorPrototype%': SyntaxError.prototype,\n\t'%ThrowTypeError%': ThrowTypeError,\n\t'%TypedArray%': TypedArray,\n\t'%TypedArrayPrototype%': TypedArray ? TypedArray.prototype : undefined,\n\t'%TypeError%': $TypeError,\n\t'%TypeErrorPrototype%': $TypeError.prototype,\n\t'%Uint8Array%': typeof Uint8Array === 'undefined' ? undefined : Uint8Array,\n\t'%Uint8ArrayPrototype%': typeof Uint8Array === 'undefined' ? undefined : Uint8Array.prototype,\n\t'%Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined : Uint8ClampedArray,\n\t'%Uint8ClampedArrayPrototype%': typeof Uint8ClampedArray === 'undefined' ? undefined : Uint8ClampedArray.prototype,\n\t'%Uint16Array%': typeof Uint16Array === 'undefined' ? undefined : Uint16Array,\n\t'%Uint16ArrayPrototype%': typeof Uint16Array === 'undefined' ? undefined : Uint16Array.prototype,\n\t'%Uint32Array%': typeof Uint32Array === 'undefined' ? undefined : Uint32Array,\n\t'%Uint32ArrayPrototype%': typeof Uint32Array === 'undefined' ? undefined : Uint32Array.prototype,\n\t'%URIError%': URIError,\n\t'%URIErrorPrototype%': URIError.prototype,\n\t'%WeakMap%': typeof WeakMap === 'undefined' ? undefined : WeakMap,\n\t'%WeakMapPrototype%': typeof WeakMap === 'undefined' ? undefined : WeakMap.prototype,\n\t'%WeakSet%': typeof WeakSet === 'undefined' ? undefined : WeakSet,\n\t'%WeakSetPrototype%': typeof WeakSet === 'undefined' ? undefined : WeakSet.prototype\n};\n\nvar bind = require('function-bind');\nvar $replace = bind.call(Function.call, String.prototype.replace);\n\n/* adapted from https://github.com/lodash/lodash/blob/4.17.15/dist/lodash.js#L6735-L6744 */\nvar rePropName = /[^%.[\\]]+|\\[(?:(-?\\d+(?:\\.\\d+)?)|([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|%$))/g;\nvar reEscapeChar = /\\\\(\\\\)?/g; /** Used to match backslashes in property paths. */\nvar stringToPath = function stringToPath(string) {\n\tvar result = [];\n\t$replace(string, rePropName, function (match, number, quote, subString) {\n\t\tresult[result.length] = quote ? $replace(subString, reEscapeChar, '$1') : (number || match);\n\t});\n\treturn result;\n};\n/* end adaptation */\n\nvar getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) {\n\tif (!(name in INTRINSICS)) {\n\t\tthrow new SyntaxError('intrinsic ' + name + ' does not exist!');\n\t}\n\n\t// istanbul ignore if // hopefully this is impossible to test :-)\n\tif (typeof INTRINSICS[name] === 'undefined' && !allowMissing) {\n\t\tthrow new $TypeError('intrinsic ' + name + ' exists, but is not available. Please file an issue!');\n\t}\n\n\treturn INTRINSICS[name];\n};\n\nmodule.exports = function GetIntrinsic(name, allowMissing) {\n\tif (typeof name !== 'string' || name.length === 0) {\n\t\tthrow new TypeError('intrinsic name must be a non-empty string');\n\t}\n\tif (arguments.length > 1 && typeof allowMissing !== 'boolean') {\n\t\tthrow new TypeError('\"allowMissing\" argument must be a boolean');\n\t}\n\n\tvar parts = stringToPath(name);\n\n\tvar value = getBaseIntrinsic('%' + (parts.length > 0 ? parts[0] : '') + '%', allowMissing);\n\tfor (var i = 1; i < parts.length; i += 1) {\n\t\tif (value != null) {\n\t\t\tif ($gOPD && (i + 1) >= parts.length) {\n\t\t\t\tvar desc = $gOPD(value, parts[i]);\n\t\t\t\tif (!allowMissing && !(parts[i] in value)) {\n\t\t\t\t\tthrow new $TypeError('base intrinsic for ' + name + ' exists, but the property is not available.');\n\t\t\t\t}\n\t\t\t\t// By convention, when a data property is converted to an accessor\n\t\t\t\t// property to emulate a data property that does not suffer from\n\t\t\t\t// the override mistake, that accessor's getter is marked with\n\t\t\t\t// an `originalValue` property. Here, when we detect this, we\n\t\t\t\t// uphold the illusion by pretending to see that original data\n\t\t\t\t// property, i.e., returning the value rather than the getter\n\t\t\t\t// itself.\n\t\t\t\tvalue = desc && 'get' in desc && !('originalValue' in desc.get) ? desc.get : value[parts[i]];\n\t\t\t} else {\n\t\t\t\tvalue = value[parts[i]];\n\t\t\t}\n\t\t}\n\t}\n\treturn value;\n};\n","'use strict';\n\nvar bind = require('function-bind');\n\nvar GetIntrinsic = require('../GetIntrinsic');\n\nvar $apply = GetIntrinsic('%Function.prototype.apply%');\nvar $call = GetIntrinsic('%Function.prototype.call%');\nvar $reflectApply = GetIntrinsic('%Reflect.apply%', true) || bind.call($call, $apply);\n\nvar $defineProperty = GetIntrinsic('%Object.defineProperty%', true);\n\nif ($defineProperty) {\n\ttry {\n\t\t$defineProperty({}, 'a', { value: 1 });\n\t} catch (e) {\n\t\t// IE 8 has a broken defineProperty\n\t\t$defineProperty = null;\n\t}\n}\n\nmodule.exports = function callBind() {\n\treturn $reflectApply(bind, $call, arguments);\n};\n\nvar applyBind = function applyBind() {\n\treturn $reflectApply(bind, $apply, arguments);\n};\n\nif ($defineProperty) {\n\t$defineProperty(module.exports, 'apply', { value: applyBind });\n} else {\n\tmodule.exports.apply = applyBind;\n}\n","'use strict';\n\nvar GetIntrinsic = require('../GetIntrinsic');\n\nvar callBind = require('./callBind');\n\nvar $indexOf = callBind(GetIntrinsic('String.prototype.indexOf'));\n\nmodule.exports = function callBoundIntrinsic(name, allowMissing) {\n\tvar intrinsic = GetIntrinsic(name, !!allowMissing);\n\tif (typeof intrinsic === 'function' && $indexOf(name, '.prototype.')) {\n\t\treturn callBind(intrinsic);\n\t}\n\treturn intrinsic;\n};\n","'use strict';\n\nvar GetIntrinsic = require('../GetIntrinsic');\n\nvar $test = GetIntrinsic('RegExp.prototype.test');\n\nvar callBind = require('./callBind');\n\nmodule.exports = function regexTester(regex) {\n\treturn callBind($test, regex);\n};\n","'use strict';\n\nmodule.exports = function isPrimitive(value) {\n\treturn value === null || (typeof value !== 'function' && typeof value !== 'object');\n};\n","'use strict';\n\nmodule.exports = function isPrimitive(value) {\n\treturn value === null || (typeof value !== 'function' && typeof value !== 'object');\n};\n","'use strict';\n\nvar fnToStr = Function.prototype.toString;\nvar reflectApply = typeof Reflect === 'object' && Reflect !== null && Reflect.apply;\nvar badArrayLike;\nvar isCallableMarker;\nif (typeof reflectApply === 'function' && typeof Object.defineProperty === 'function') {\n\ttry {\n\t\tbadArrayLike = Object.defineProperty({}, 'length', {\n\t\t\tget: function () {\n\t\t\t\tthrow isCallableMarker;\n\t\t\t}\n\t\t});\n\t\tisCallableMarker = {};\n\t\t// eslint-disable-next-line no-throw-literal\n\t\treflectApply(function () { throw 42; }, null, badArrayLike);\n\t} catch (_) {\n\t\tif (_ !== isCallableMarker) {\n\t\t\treflectApply = null;\n\t\t}\n\t}\n} else {\n\treflectApply = null;\n}\n\nvar constructorRegex = /^\\s*class\\b/;\nvar isES6ClassFn = function isES6ClassFunction(value) {\n\ttry {\n\t\tvar fnStr = fnToStr.call(value);\n\t\treturn constructorRegex.test(fnStr);\n\t} catch (e) {\n\t\treturn false; // not a function\n\t}\n};\n\nvar tryFunctionObject = function tryFunctionToStr(value) {\n\ttry {\n\t\tif (isES6ClassFn(value)) { return false; }\n\t\tfnToStr.call(value);\n\t\treturn true;\n\t} catch (e) {\n\t\treturn false;\n\t}\n};\nvar toStr = Object.prototype.toString;\nvar fnClass = '[object Function]';\nvar genClass = '[object GeneratorFunction]';\nvar hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';\n\nmodule.exports = reflectApply\n\t? function isCallable(value) {\n\t\tif (!value) { return false; }\n\t\tif (typeof value !== 'function' && typeof value !== 'object') { return false; }\n\t\tif (typeof value === 'function' && !value.prototype) { return true; }\n\t\ttry {\n\t\t\treflectApply(value, null, badArrayLike);\n\t\t} catch (e) {\n\t\t\tif (e !== isCallableMarker) { return false; }\n\t\t}\n\t\treturn !isES6ClassFn(value);\n\t}\n\t: function isCallable(value) {\n\t\tif (!value) { return false; }\n\t\tif (typeof value !== 'function' && typeof value !== 'object') { return false; }\n\t\tif (typeof value === 'function' && !value.prototype) { return true; }\n\t\tif (hasToStringTag) { return tryFunctionObject(value); }\n\t\tif (isES6ClassFn(value)) { return false; }\n\t\tvar strClass = toStr.call(value);\n\t\treturn strClass === fnClass || strClass === genClass;\n\t};\n","'use strict';\n\nvar hasSymbols = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol';\n\nvar isPrimitive = require('./helpers/isPrimitive');\nvar isCallable = require('is-callable');\nvar isDate = require('is-date-object');\nvar isSymbol = require('is-symbol');\n\nvar ordinaryToPrimitive = function OrdinaryToPrimitive(O, hint) {\n\tif (typeof O === 'undefined' || O === null) {\n\t\tthrow new TypeError('Cannot call method on ' + O);\n\t}\n\tif (typeof hint !== 'string' || (hint !== 'number' && hint !== 'string')) {\n\t\tthrow new TypeError('hint must be \"string\" or \"number\"');\n\t}\n\tvar methodNames = hint === 'string' ? ['toString', 'valueOf'] : ['valueOf', 'toString'];\n\tvar method, result, i;\n\tfor (i = 0; i < methodNames.length; ++i) {\n\t\tmethod = O[methodNames[i]];\n\t\tif (isCallable(method)) {\n\t\t\tresult = method.call(O);\n\t\t\tif (isPrimitive(result)) {\n\t\t\t\treturn result;\n\t\t\t}\n\t\t}\n\t}\n\tthrow new TypeError('No default value');\n};\n\nvar GetMethod = function GetMethod(O, P) {\n\tvar func = O[P];\n\tif (func !== null && typeof func !== 'undefined') {\n\t\tif (!isCallable(func)) {\n\t\t\tthrow new TypeError(func + ' returned for property ' + P + ' of object ' + O + ' is not a function');\n\t\t}\n\t\treturn func;\n\t}\n\treturn void 0;\n};\n\n// http://www.ecma-international.org/ecma-262/6.0/#sec-toprimitive\nmodule.exports = function ToPrimitive(input) {\n\tif (isPrimitive(input)) {\n\t\treturn input;\n\t}\n\tvar hint = 'default';\n\tif (arguments.length > 1) {\n\t\tif (arguments[1] === String) {\n\t\t\thint = 'string';\n\t\t} else if (arguments[1] === Number) {\n\t\t\thint = 'number';\n\t\t}\n\t}\n\n\tvar exoticToPrim;\n\tif (hasSymbols) {\n\t\tif (Symbol.toPrimitive) {\n\t\t\texoticToPrim = GetMethod(input, Symbol.toPrimitive);\n\t\t} else if (isSymbol(input)) {\n\t\t\texoticToPrim = Symbol.prototype.valueOf;\n\t\t}\n\t}\n\tif (typeof exoticToPrim !== 'undefined') {\n\t\tvar result = exoticToPrim.call(input, hint);\n\t\tif (isPrimitive(result)) {\n\t\t\treturn result;\n\t\t}\n\t\tthrow new TypeError('unable to convert exotic object to primitive');\n\t}\n\tif (hint === 'default' && (isDate(input) || isSymbol(input))) {\n\t\thint = 'string';\n\t}\n\treturn ordinaryToPrimitive(input, hint === 'default' ? 'number' : hint);\n};\n","'use strict';\n\nvar toPrimitive = require('es-to-primitive/es2015');\n\n// https://www.ecma-international.org/ecma-262/6.0/#sec-toprimitive\n\nmodule.exports = function ToPrimitive(input) {\n\tif (arguments.length > 1) {\n\t\treturn toPrimitive(input, arguments[1]);\n\t}\n\treturn toPrimitive(input);\n};\n","'use strict';\n\nvar GetIntrinsic = require('../GetIntrinsic');\n\nvar $TypeError = GetIntrinsic('%TypeError%');\nvar $Number = GetIntrinsic('%Number%');\nvar $RegExp = GetIntrinsic('%RegExp%');\nvar $parseInteger = GetIntrinsic('%parseInt%');\n\nvar callBound = require('../helpers/callBound');\nvar regexTester = require('../helpers/regexTester');\nvar isPrimitive = require('../helpers/isPrimitive');\n\nvar $strSlice = callBound('String.prototype.slice');\nvar isBinary = regexTester(/^0b[01]+$/i);\nvar isOctal = regexTester(/^0o[0-7]+$/i);\nvar isInvalidHexLiteral = regexTester(/^[-+]0x[0-9a-f]+$/i);\nvar nonWS = ['\\u0085', '\\u200b', '\\ufffe'].join('');\nvar nonWSregex = new $RegExp('[' + nonWS + ']', 'g');\nvar hasNonWS = regexTester(nonWSregex);\n\n// whitespace from: https://es5.github.io/#x15.5.4.20\n// implementation from https://github.com/es-shims/es5-shim/blob/v3.4.0/es5-shim.js#L1304-L1324\nvar ws = [\n\t'\\x09\\x0A\\x0B\\x0C\\x0D\\x20\\xA0\\u1680\\u180E\\u2000\\u2001\\u2002\\u2003',\n\t'\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200A\\u202F\\u205F\\u3000\\u2028',\n\t'\\u2029\\uFEFF'\n].join('');\nvar trimRegex = new RegExp('(^[' + ws + ']+)|([' + ws + ']+$)', 'g');\nvar $replace = callBound('String.prototype.replace');\nvar $trim = function (value) {\n\treturn $replace(value, trimRegex, '');\n};\n\nvar ToPrimitive = require('./ToPrimitive');\n\n// https://www.ecma-international.org/ecma-262/6.0/#sec-tonumber\n\nmodule.exports = function ToNumber(argument) {\n\tvar value = isPrimitive(argument) ? argument : ToPrimitive(argument, $Number);\n\tif (typeof value === 'symbol') {\n\t\tthrow new $TypeError('Cannot convert a Symbol value to a number');\n\t}\n\tif (typeof value === 'string') {\n\t\tif (isBinary(value)) {\n\t\t\treturn ToNumber($parseInteger($strSlice(value, 2), 2));\n\t\t} else if (isOctal(value)) {\n\t\t\treturn ToNumber($parseInteger($strSlice(value, 2), 8));\n\t\t} else if (hasNonWS(value) || isInvalidHexLiteral(value)) {\n\t\t\treturn NaN;\n\t\t} else {\n\t\t\tvar trimmed = $trim(value);\n\t\t\tif (trimmed !== value) {\n\t\t\t\treturn ToNumber(trimmed);\n\t\t\t}\n\t\t}\n\t}\n\treturn $Number(value);\n};\n","'use strict';\n\nmodule.exports = Number.isNaN || function isNaN(a) {\n\treturn a !== a;\n};\n","'use strict';\n\nvar $isNaN = Number.isNaN || function (a) { return a !== a; };\n\nmodule.exports = Number.isFinite || function (x) { return typeof x === 'number' && !$isNaN(x) && x !== Infinity && x !== -Infinity; };\n","'use strict';\n\nvar GetIntrinsic = require('../GetIntrinsic');\n\nvar $Math = GetIntrinsic('%Math%');\n\nvar $floor = $Math.floor;\nvar $abs = $Math.abs;\n\nvar $isNaN = require('../helpers/isNaN');\nvar $isFinite = require('../helpers/isFinite');\n\n// https://www.ecma-international.org/ecma-262/6.0/#sec-isinteger\n\nmodule.exports = function IsInteger(argument) {\n\tif (typeof argument !== 'number' || $isNaN(argument) || !$isFinite(argument)) {\n\t\treturn false;\n\t}\n\tvar abs = $abs(argument);\n\treturn $floor(abs) === abs;\n};\n","/*! https://mths.be/fromcodepoint v1.0.0 by @mathias */\n\n'use strict';\n\nvar ToNumber = require('es-abstract/2019/ToNumber');\nvar IsInteger = require('es-abstract/2019/IsInteger');\nvar callBound = require('es-abstract/helpers/callBound');\nvar callBind = require('es-abstract/helpers/callBind');\nvar GetIntrinsic = require('es-abstract/GetIntrinsic');\n\nvar ArrayPush = callBound('Array.prototype.push');\nvar StringFromCharCodeSpread = callBind.apply(String.fromCharCode, null);\n\nmodule.exports = function fromCodePoint(_ /* fromCodePoint.length is 1 */) {\n\tvar MAX_SIZE = 0x4000;\n\tvar codeUnits = [];\n\tvar highSurrogate;\n\tvar lowSurrogate;\n\tvar index = -1;\n\tvar length = arguments.length;\n\tif (!length) {\n\t\treturn '';\n\t}\n\tvar result = '';\n\twhile (++index < length) {\n\t\tvar codePoint = ToNumber(arguments[index]);\n\t\tif (\n\t\t\t!IsInteger(codePoint) ||\n\t\t\tcodePoint < 0 || codePoint > 0x10FFFF // not a valid Unicode code point\n\t\t) {\n\t\t\tthrow RangeError('Invalid code point: ' + codePoint);\n\t\t}\n\t\tif (codePoint <= 0xFFFF) { // BMP code point\n\t\t\tArrayPush(codeUnits, codePoint);\n\t\t} else { // Astral code point; split in surrogate halves\n\t\t\t// https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae\n\t\t\tcodePoint -= 0x10000;\n\t\t\thighSurrogate = (codePoint >> 10) + 0xD800;\n\t\t\tlowSurrogate = (codePoint % 0x400) + 0xDC00;\n\t\t\tArrayPush(codeUnits, highSurrogate, lowSurrogate);\n\t\t}\n\t\tif (index + 1 == length || codeUnits.length > MAX_SIZE) {\n\t\t\tresult += StringFromCharCodeSpread(codeUnits);\n\t\t\tcodeUnits.length = 0;\n\t\t}\n\t}\n\treturn result;\n};\n","/*! https://mths.be/fromcodepoint v1.0.0 by @mathias */\n\n'use strict';\n\nvar implementation = require('./implementation');\n\nmodule.exports = function getPolyfill() {\n\treturn String.fromCodePoint || implementation;\n};\n","/*! https://mths.be/fromcodepoint v1.0.0 by @mathias */\n\n'use strict';\n\nvar define = require('define-properties');\n\nvar getPolyfill = require('./polyfill');\n\nmodule.exports = function shimFromCodePoint() {\n\tvar polyfill = getPolyfill();\n\n\tif (String.fromCodePoint !== polyfill) {\n\t\tdefine(String, { fromCodePoint: polyfill });\n\t}\n\n\treturn polyfill;\n};\n","/*! https://mths.be/fromcodepoint v1.0.0 by @mathias */\n\nrequire('./shim')();\n","(function (factory) {\n typeof define === 'function' && define.amd ? define(factory) :\n factory();\n}((function () { 'use strict';\n\n function _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n }\n\n function _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n Object.defineProperty(target, descriptor.key, descriptor);\n }\n }\n\n function _createClass(Constructor, protoProps, staticProps) {\n if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n if (staticProps) _defineProperties(Constructor, staticProps);\n return Constructor;\n }\n\n function _inherits(subClass, superClass) {\n if (typeof superClass !== \"function\" && superClass !== null) {\n throw new TypeError(\"Super expression must either be null or a function\");\n }\n\n subClass.prototype = Object.create(superClass && superClass.prototype, {\n constructor: {\n value: subClass,\n writable: true,\n configurable: true\n }\n });\n if (superClass) _setPrototypeOf(subClass, superClass);\n }\n\n function _getPrototypeOf(o) {\n _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {\n return o.__proto__ || Object.getPrototypeOf(o);\n };\n return _getPrototypeOf(o);\n }\n\n function _setPrototypeOf(o, p) {\n _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {\n o.__proto__ = p;\n return o;\n };\n\n return _setPrototypeOf(o, p);\n }\n\n function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n }\n\n function _possibleConstructorReturn(self, call) {\n if (call && (typeof call === \"object\" || typeof call === \"function\")) {\n return call;\n }\n\n return _assertThisInitialized(self);\n }\n\n function _superPropBase(object, property) {\n while (!Object.prototype.hasOwnProperty.call(object, property)) {\n object = _getPrototypeOf(object);\n if (object === null) break;\n }\n\n return object;\n }\n\n function _get(target, property, receiver) {\n if (typeof Reflect !== \"undefined\" && Reflect.get) {\n _get = Reflect.get;\n } else {\n _get = function _get(target, property, receiver) {\n var base = _superPropBase(target, property);\n\n if (!base) return;\n var desc = Object.getOwnPropertyDescriptor(base, property);\n\n if (desc.get) {\n return desc.get.call(receiver);\n }\n\n return desc.value;\n };\n }\n\n return _get(target, property, receiver || target);\n }\n\n var Emitter =\n /*#__PURE__*/\n function () {\n function Emitter() {\n _classCallCheck(this, Emitter);\n\n Object.defineProperty(this, 'listeners', {\n value: {},\n writable: true,\n configurable: true\n });\n }\n\n _createClass(Emitter, [{\n key: \"addEventListener\",\n value: function addEventListener(type, callback) {\n if (!(type in this.listeners)) {\n this.listeners[type] = [];\n }\n\n this.listeners[type].push(callback);\n }\n }, {\n key: \"removeEventListener\",\n value: function removeEventListener(type, callback) {\n if (!(type in this.listeners)) {\n return;\n }\n\n var stack = this.listeners[type];\n\n for (var i = 0, l = stack.length; i < l; i++) {\n if (stack[i] === callback) {\n stack.splice(i, 1);\n return;\n }\n }\n }\n }, {\n key: \"dispatchEvent\",\n value: function dispatchEvent(event) {\n var _this = this;\n\n if (!(event.type in this.listeners)) {\n return;\n }\n\n var debounce = function debounce(callback) {\n setTimeout(function () {\n return callback.call(_this, event);\n });\n };\n\n var stack = this.listeners[event.type];\n\n for (var i = 0, l = stack.length; i < l; i++) {\n debounce(stack[i]);\n }\n\n return !event.defaultPrevented;\n }\n }]);\n\n return Emitter;\n }();\n\n var AbortSignal =\n /*#__PURE__*/\n function (_Emitter) {\n _inherits(AbortSignal, _Emitter);\n\n function AbortSignal() {\n var _this2;\n\n _classCallCheck(this, AbortSignal);\n\n _this2 = _possibleConstructorReturn(this, _getPrototypeOf(AbortSignal).call(this)); // Some versions of babel does not transpile super() correctly for IE <= 10, if the parent\n // constructor has failed to run, then \"this.listeners\" will still be undefined and then we call\n // the parent constructor directly instead as a workaround. For general details, see babel bug:\n // https://github.com/babel/babel/issues/3041\n // This hack was added as a fix for the issue described here:\n // https://github.com/Financial-Times/polyfill-library/pull/59#issuecomment-477558042\n\n if (!_this2.listeners) {\n Emitter.call(_assertThisInitialized(_this2));\n } // Compared to assignment, Object.defineProperty makes properties non-enumerable by default and\n // we want Object.keys(new AbortController().signal) to be [] for compat with the native impl\n\n\n Object.defineProperty(_assertThisInitialized(_this2), 'aborted', {\n value: false,\n writable: true,\n configurable: true\n });\n Object.defineProperty(_assertThisInitialized(_this2), 'onabort', {\n value: null,\n writable: true,\n configurable: true\n });\n return _this2;\n }\n\n _createClass(AbortSignal, [{\n key: \"toString\",\n value: function toString() {\n return '[object AbortSignal]';\n }\n }, {\n key: \"dispatchEvent\",\n value: function dispatchEvent(event) {\n if (event.type === 'abort') {\n this.aborted = true;\n\n if (typeof this.onabort === 'function') {\n this.onabort.call(this, event);\n }\n }\n\n _get(_getPrototypeOf(AbortSignal.prototype), \"dispatchEvent\", this).call(this, event);\n }\n }]);\n\n return AbortSignal;\n }(Emitter);\n var AbortController =\n /*#__PURE__*/\n function () {\n function AbortController() {\n _classCallCheck(this, AbortController);\n\n // Compared to assignment, Object.defineProperty makes properties non-enumerable by default and\n // we want Object.keys(new AbortController()) to be [] for compat with the native impl\n Object.defineProperty(this, 'signal', {\n value: new AbortSignal(),\n writable: true,\n configurable: true\n });\n }\n\n _createClass(AbortController, [{\n key: \"abort\",\n value: function abort() {\n var event;\n\n try {\n event = new Event('abort');\n } catch (e) {\n if (typeof document !== 'undefined') {\n if (!document.createEvent) {\n // For Internet Explorer 8:\n event = document.createEventObject();\n event.type = 'abort';\n } else {\n // For Internet Explorer 11:\n event = document.createEvent('Event');\n event.initEvent('abort', false, false);\n }\n } else {\n // Fallback where document isn't available:\n event = {\n type: 'abort',\n bubbles: false,\n cancelable: false\n };\n }\n }\n\n this.signal.dispatchEvent(event);\n }\n }, {\n key: \"toString\",\n value: function toString() {\n return '[object AbortController]';\n }\n }]);\n\n return AbortController;\n }();\n\n if (typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n // These are necessary to make sure that we get correct output for:\n // Object.prototype.toString.call(new AbortController())\n AbortController.prototype[Symbol.toStringTag] = 'AbortController';\n AbortSignal.prototype[Symbol.toStringTag] = 'AbortSignal';\n }\n\n function polyfillNeeded(self) {\n if (self.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL) {\n console.log('__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill');\n return true;\n } // Note that the \"unfetch\" minimal fetch polyfill defines fetch() without\n // defining window.Request, and this polyfill need to work on top of unfetch\n // so the below feature detection needs the !self.AbortController part.\n // The Request.prototype check is also needed because Safari versions 11.1.2\n // up to and including 12.1.x has a window.AbortController present but still\n // does NOT correctly implement abortable fetch:\n // https://bugs.webkit.org/show_bug.cgi?id=174980#c2\n\n\n return typeof self.Request === 'function' && !self.Request.prototype.hasOwnProperty('signal') || !self.AbortController;\n }\n\n /**\n * Note: the \"fetch.Request\" default value is available for fetch imported from\n * the \"node-fetch\" package and not in browsers. This is OK since browsers\n * will be importing umd-polyfill.js from that path \"self\" is passed the\n * decorator so the default value will not be used (because browsers that define\n * fetch also has Request). One quirky setup where self.fetch exists but\n * self.Request does not is when the \"unfetch\" minimal fetch polyfill is used\n * on top of IE11; for this case the browser will try to use the fetch.Request\n * default value which in turn will be undefined but then then \"if (Request)\"\n * will ensure that you get a patched fetch but still no Request (as expected).\n * @param {fetch, Request = fetch.Request}\n * @returns {fetch: abortableFetch, Request: AbortableRequest}\n */\n\n function abortableFetchDecorator(patchTargets) {\n if ('function' === typeof patchTargets) {\n patchTargets = {\n fetch: patchTargets\n };\n }\n\n var _patchTargets = patchTargets,\n fetch = _patchTargets.fetch,\n _patchTargets$Request = _patchTargets.Request,\n NativeRequest = _patchTargets$Request === void 0 ? fetch.Request : _patchTargets$Request,\n NativeAbortController = _patchTargets.AbortController,\n _patchTargets$__FORCE = _patchTargets.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL,\n __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL = _patchTargets$__FORCE === void 0 ? false : _patchTargets$__FORCE;\n\n if (!polyfillNeeded({\n fetch: fetch,\n Request: NativeRequest,\n AbortController: NativeAbortController,\n __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL: __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL\n })) {\n return {\n fetch: fetch,\n Request: Request\n };\n }\n\n var Request = NativeRequest; // Note that the \"unfetch\" minimal fetch polyfill defines fetch() without\n // defining window.Request, and this polyfill need to work on top of unfetch\n // hence we only patch it if it's available. Also we don't patch it if signal\n // is already available on the Request prototype because in this case support\n // is present and the patching below can cause a crash since it assigns to\n // request.signal which is technically a read-only property. This latter error\n // happens when you run the main5.js node-fetch example in the repo\n // \"abortcontroller-polyfill-examples\". The exact error is:\n // request.signal = init.signal;\n // ^\n // TypeError: Cannot set property signal of # which has only a getter\n\n if (Request && !Request.prototype.hasOwnProperty('signal') || __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL) {\n Request = function Request(input, init) {\n var signal;\n\n if (init && init.signal) {\n signal = init.signal; // Never pass init.signal to the native Request implementation when the polyfill has\n // been installed because if we're running on top of a browser with a\n // working native AbortController (i.e. the polyfill was installed due to\n // __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL being set), then passing our\n // fake AbortSignal to the native fetch will trigger:\n // TypeError: Failed to construct 'Request': member signal is not of type AbortSignal.\n\n delete init.signal;\n }\n\n var request = new NativeRequest(input, init);\n\n if (signal) {\n Object.defineProperty(request, 'signal', {\n writable: false,\n enumerable: false,\n configurable: true,\n value: signal\n });\n }\n\n return request;\n };\n\n Request.prototype = NativeRequest.prototype;\n }\n\n var realFetch = fetch;\n\n var abortableFetch = function abortableFetch(input, init) {\n var signal = Request && Request.prototype.isPrototypeOf(input) ? input.signal : init ? init.signal : undefined;\n\n if (signal) {\n var abortError;\n\n try {\n abortError = new DOMException('Aborted', 'AbortError');\n } catch (err) {\n // IE 11 does not support calling the DOMException constructor, use a\n // regular error object on it instead.\n abortError = new Error('Aborted');\n abortError.name = 'AbortError';\n } // Return early if already aborted, thus avoiding making an HTTP request\n\n\n if (signal.aborted) {\n return Promise.reject(abortError);\n } // Turn an event into a promise, reject it once `abort` is dispatched\n\n\n var cancellation = new Promise(function (_, reject) {\n signal.addEventListener('abort', function () {\n return reject(abortError);\n }, {\n once: true\n });\n });\n\n if (init && init.signal) {\n // Never pass .signal to the native implementation when the polyfill has\n // been installed because if we're running on top of a browser with a\n // working native AbortController (i.e. the polyfill was installed due to\n // __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL being set), then passing our\n // fake AbortSignal to the native fetch will trigger:\n // TypeError: Failed to execute 'fetch' on 'Window': member signal is not of type AbortSignal.\n delete init.signal;\n } // Return the fastest promise (don't need to wait for request to finish)\n\n\n return Promise.race([cancellation, realFetch(input, init)]);\n }\n\n return realFetch(input, init);\n };\n\n return {\n fetch: abortableFetch,\n Request: Request\n };\n }\n\n (function (self) {\n\n if (!polyfillNeeded(self)) {\n return;\n }\n\n if (!self.fetch) {\n console.warn('fetch() is not available, cannot install abortcontroller-polyfill');\n return;\n }\n\n var _abortableFetch = abortableFetchDecorator(self),\n fetch = _abortableFetch.fetch,\n Request = _abortableFetch.Request;\n\n self.fetch = fetch;\n self.Request = Request;\n Object.defineProperty(self, 'AbortController', {\n writable: true,\n enumerable: false,\n configurable: true,\n value: AbortController\n });\n Object.defineProperty(self, 'AbortSignal', {\n writable: true,\n enumerable: false,\n configurable: true,\n value: AbortSignal\n });\n })(typeof self !== 'undefined' ? self : global);\n\n})));\n","export function actionAddEntity(way) {\n return function(graph) {\n return graph.replace(way);\n };\n}\n","/*\nOrder the nodes of a way in reverse order and reverse any direction dependent tags\nother than `oneway`. (We assume that correcting a backwards oneway is the primary\nreason for reversing a way.)\n\nIn addition, numeric-valued `incline` tags are negated.\n\nThe JOSM implementation was used as a guide, but transformations that were of unclear benefit\nor adjusted tags that don't seem to be used in practice were omitted.\n\nReferences:\n http://wiki.openstreetmap.org/wiki/Forward_%26_backward,_left_%26_right\n http://wiki.openstreetmap.org/wiki/Key:direction#Steps\n http://wiki.openstreetmap.org/wiki/Key:incline\n http://wiki.openstreetmap.org/wiki/Route#Members\n http://josm.openstreetmap.de/browser/josm/trunk/src/org/openstreetmap/josm/corrector/ReverseWayTagCorrector.java\n http://wiki.openstreetmap.org/wiki/Tag:highway%3Dstop\n http://wiki.openstreetmap.org/wiki/Key:traffic_sign#On_a_way_or_area\n*/\nexport function actionReverse(entityID, options) {\n var ignoreKey = /^.*(_|:)?(description|name|note|website|ref|source|comment|watch|attribution)(_|:)?/;\n var numeric = /^([+\\-]?)(?=[\\d.])/;\n var directionKey = /direction$/;\n var turn_lanes = /^turn:lanes:?/;\n var keyReplacements = [\n [/:right$/, ':left'],\n [/:left$/, ':right'],\n [/:forward$/, ':backward'],\n [/:backward$/, ':forward'],\n [/:right:/, ':left:'],\n [/:left:/, ':right:'],\n [/:forward:/, ':backward:'],\n [/:backward:/, ':forward:']\n ];\n var valueReplacements = {\n left: 'right',\n right: 'left',\n up: 'down',\n down: 'up',\n forward: 'backward',\n backward: 'forward',\n forwards: 'backward',\n backwards: 'forward',\n };\n var roleReplacements = {\n forward: 'backward',\n backward: 'forward',\n forwards: 'backward',\n backwards: 'forward'\n };\n var onewayReplacements = {\n yes: '-1',\n '1': '-1',\n '-1': 'yes'\n };\n\n var compassReplacements = {\n N: 'S',\n NNE: 'SSW',\n NE: 'SW',\n ENE: 'WSW',\n E: 'W',\n ESE: 'WNW',\n SE: 'NW',\n SSE: 'NNW',\n S: 'N',\n SSW: 'NNE',\n SW: 'NE',\n WSW: 'ENE',\n W: 'E',\n WNW: 'ESE',\n NW: 'SE',\n NNW: 'SSE'\n };\n\n\n function reverseKey(key) {\n for (var i = 0; i < keyReplacements.length; ++i) {\n var replacement = keyReplacements[i];\n if (replacement[0].test(key)) {\n return key.replace(replacement[0], replacement[1]);\n }\n }\n return key;\n }\n\n\n function reverseValue(key, value, includeAbsolute) {\n if (ignoreKey.test(key)) return value;\n\n // Turn lanes are left/right to key (not way) direction - #5674\n if (turn_lanes.test(key)) {\n return value;\n\n } else if (key === 'incline' && numeric.test(value)) {\n return value.replace(numeric, function(_, sign) { return sign === '-' ? '' : '-'; });\n\n } else if (options && options.reverseOneway && key === 'oneway') {\n return onewayReplacements[value] || value;\n\n } else if (includeAbsolute && directionKey.test(key)) {\n if (compassReplacements[value]) return compassReplacements[value];\n\n var degrees = parseFloat(value);\n if (typeof degrees === 'number' && !isNaN(degrees)) {\n if (degrees < 180) {\n degrees += 180;\n } else {\n degrees -= 180;\n }\n return degrees.toString();\n }\n }\n\n return valueReplacements[value] || value;\n }\n\n\n // Reverse the direction of tags attached to the nodes - #3076\n function reverseNodeTags(graph, nodeIDs) {\n for (var i = 0; i < nodeIDs.length; i++) {\n var node = graph.hasEntity(nodeIDs[i]);\n if (!node || !Object.keys(node.tags).length) continue;\n\n var tags = {};\n for (var key in node.tags) {\n tags[reverseKey(key)] = reverseValue(key, node.tags[key], node.id === entityID);\n }\n graph = graph.replace(node.update({tags: tags}));\n }\n return graph;\n }\n\n\n function reverseWay(graph, way) {\n var nodes = way.nodes.slice().reverse();\n var tags = {};\n var role;\n\n for (var key in way.tags) {\n tags[reverseKey(key)] = reverseValue(key, way.tags[key]);\n }\n\n graph.parentRelations(way).forEach(function(relation) {\n relation.members.forEach(function(member, index) {\n if (member.id === way.id && (role = roleReplacements[member.role])) {\n relation = relation.updateMember({role: role}, index);\n graph = graph.replace(relation);\n }\n });\n });\n\n // Reverse any associated directions on nodes on the way and then replace\n // the way itself with the reversed node ids and updated way tags\n return reverseNodeTags(graph, nodes)\n .replace(way.update({nodes: nodes, tags: tags}));\n }\n\n\n var action = function(graph) {\n var entity = graph.entity(entityID);\n if (entity.type === 'way') {\n return reverseWay(graph, entity);\n }\n return reverseNodeTags(graph, [entityID]);\n };\n\n action.disabled = function(graph) {\n var entity = graph.hasEntity(entityID);\n if (!entity || entity.type === 'way') return false;\n\n for (var key in entity.tags) {\n var value = entity.tags[key];\n if (reverseKey(key) !== key || reverseValue(key, value, true) !== value) {\n return false;\n }\n }\n return 'nondirectional_node';\n };\n\n action.entityID = function() {\n return entityID;\n };\n\n return action;\n}\n","export function osmIsInterestingTag(key) {\n return key !== 'attribution' &&\n key !== 'created_by' &&\n key !== 'source' &&\n key !== 'odbl' &&\n key.indexOf('source:') !== 0 &&\n key.indexOf('source_ref') !== 0 && // purposely exclude colon\n key.indexOf('tiger:') !== 0;\n}\n\nexport var osmAreaKeys = {};\nexport function osmSetAreaKeys(value) {\n osmAreaKeys = value;\n}\n\n// returns an object with the tag from `tags` that implies an area geometry, if any\nexport function osmTagSuggestingArea(tags) {\n if (tags.area === 'yes') return { area: 'yes' };\n if (tags.area === 'no') return null;\n\n // `highway` and `railway` are typically linear features, but there\n // are a few exceptions that should be treated as areas, even in the\n // absence of a proper `area=yes` or `areaKeys` tag.. see #4194\n var lineKeys = {\n highway: {\n rest_area: true,\n services: true\n },\n railway: {\n roundhouse: true,\n station: true,\n traverser: true,\n turntable: true,\n wash: true\n }\n };\n var returnTags = {};\n for (var key in tags) {\n if (key in osmAreaKeys && !(tags[key] in osmAreaKeys[key])) {\n returnTags[key] = tags[key];\n return returnTags;\n }\n if (key in lineKeys && tags[key] in lineKeys[key]) {\n returnTags[key] = tags[key];\n return returnTags;\n }\n }\n return null;\n}\n\n// Tags that indicate a node can be a standalone point\n// e.g. { amenity: { bar: true, parking: true, ... } ... }\nexport var osmPointTags = {};\nexport function osmSetPointTags(value) {\n osmPointTags = value;\n}\n// Tags that indicate a node can be part of a way\n// e.g. { amenity: { parking: true, ... }, highway: { stop: true ... } ... }\nexport var osmVertexTags = {};\nexport function osmSetVertexTags(value) {\n osmVertexTags = value;\n}\n\nexport function osmNodeGeometriesForTags(nodeTags) {\n var geometries = {};\n for (var key in nodeTags) {\n if (osmPointTags[key] &&\n (osmPointTags[key]['*'] || osmPointTags[key][nodeTags[key]])) {\n geometries.point = true;\n }\n if (osmVertexTags[key] &&\n (osmVertexTags[key]['*'] || osmVertexTags[key][nodeTags[key]])) {\n geometries.vertex = true;\n }\n // break early if both are already supported\n if (geometries.point && geometries.vertex) break;\n }\n return geometries;\n}\n\nexport var osmOneWayTags = {\n 'aerialway': {\n 'chair_lift': true,\n 'drag_lift': true,\n 'j-bar': true,\n 'magic_carpet': true,\n 'mixed_lift': true,\n 'platter': true,\n 'rope_tow': true,\n 't-bar': true,\n 'zip_line': true\n },\n 'highway': {\n 'motorway': true\n },\n 'junction': {\n 'circular': true,\n 'roundabout': true\n },\n 'man_made': {\n 'goods_conveyor': true,\n 'piste:halfpipe': true\n },\n 'piste:type': {\n 'downhill': true,\n 'sled': true,\n 'yes': true\n },\n 'waterway': {\n 'canal': true,\n 'ditch': true,\n 'drain': true,\n 'fish_pass': true,\n 'river': true,\n 'stream': true,\n 'tidal_channel': true\n }\n};\n\n// solid and smooth surfaces akin to the assumed default road surface in OSM\nexport var osmPavedTags = {\n 'surface': {\n 'paved': true,\n 'asphalt': true,\n 'concrete': true,\n 'concrete:lanes': true,\n 'concrete:plates': true\n },\n 'tracktype': {\n 'grade1': true\n }\n};\n\n// solid, if somewhat uncommon surfaces with a high range of smoothness\nexport var osmSemipavedTags = {\n 'surface': {\n 'cobblestone': true,\n 'cobblestone:flattened': true,\n 'unhewn_cobblestone': true,\n 'sett': true,\n 'paving_stones': true,\n 'metal': true,\n 'wood': true\n }\n};\n\nexport var osmRightSideIsInsideTags = {\n 'natural': {\n 'cliff': true,\n 'coastline': 'coastline',\n },\n 'barrier': {\n 'retaining_wall': true,\n 'kerb': true,\n 'guard_rail': true,\n 'city_wall': true,\n },\n 'man_made': {\n 'embankment': true\n },\n 'waterway': {\n 'weir': true\n }\n};\n\n// \"highway\" tag values for pedestrian or vehicle right-of-ways that make up the routable network\n// (does not include `raceway`)\nexport var osmRoutableHighwayTagValues = {\n motorway: true, trunk: true, primary: true, secondary: true, tertiary: true, residential: true,\n motorway_link: true, trunk_link: true, primary_link: true, secondary_link: true, tertiary_link: true,\n unclassified: true, road: true, service: true, track: true, living_street: true, bus_guideway: true,\n path: true, footway: true, cycleway: true, bridleway: true, pedestrian: true, corridor: true, steps: true\n};\n// \"highway\" tag values that generally do not allow motor vehicles\nexport var osmPathHighwayTagValues = {\n path: true, footway: true, cycleway: true, bridleway: true, pedestrian: true, corridor: true, steps: true\n};\n\n// \"railway\" tag values representing existing railroad tracks (purposely does not include 'abandoned')\nexport var osmRailwayTrackTagValues = {\n rail: true, light_rail: true, tram: true, subway: true,\n monorail: true, funicular: true, miniature: true, narrow_gauge: true,\n disused: true, preserved: true\n};\n\n// \"waterway\" tag values for line features representing water flow\nexport var osmFlowingWaterwayTagValues = {\n canal: true, ditch: true, drain: true, fish_pass: true, river: true, stream: true, tidal_channel: true\n};\n","// Adds floating point numbers with twice the normal precision.\n// Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and\n// Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)\n// 305–363 (1997).\n// Code adapted from GeographicLib by Charles F. F. Karney,\n// http://geographiclib.sourceforge.net/\n\nexport default function() {\n return new Adder;\n}\n\nfunction Adder() {\n this.reset();\n}\n\nAdder.prototype = {\n constructor: Adder,\n reset: function() {\n this.s = // rounded value\n this.t = 0; // exact error\n },\n add: function(y) {\n add(temp, y, this.t);\n add(this, temp.s, this.s);\n if (this.s) this.t += temp.t;\n else this.s = temp.t;\n },\n valueOf: function() {\n return this.s;\n }\n};\n\nvar temp = new Adder;\n\nfunction add(adder, a, b) {\n var x = adder.s = a + b,\n bv = x - a,\n av = x - bv;\n adder.t = (a - av) + (b - bv);\n}\n","export var epsilon = 1e-6;\nexport var epsilon2 = 1e-12;\nexport var pi = Math.PI;\nexport var halfPi = pi / 2;\nexport var quarterPi = pi / 4;\nexport var tau = pi * 2;\n\nexport var degrees = 180 / pi;\nexport var radians = pi / 180;\n\nexport var abs = Math.abs;\nexport var atan = Math.atan;\nexport var atan2 = Math.atan2;\nexport var cos = Math.cos;\nexport var ceil = Math.ceil;\nexport var exp = Math.exp;\nexport var floor = Math.floor;\nexport var log = Math.log;\nexport var pow = Math.pow;\nexport var sin = Math.sin;\nexport var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };\nexport var sqrt = Math.sqrt;\nexport var tan = Math.tan;\n\nexport function acos(x) {\n return x > 1 ? 0 : x < -1 ? pi : Math.acos(x);\n}\n\nexport function asin(x) {\n return x > 1 ? halfPi : x < -1 ? -halfPi : Math.asin(x);\n}\n\nexport function haversin(x) {\n return (x = sin(x / 2)) * x;\n}\n","export default function noop() {}\n","function streamGeometry(geometry, stream) {\n if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {\n streamGeometryType[geometry.type](geometry, stream);\n }\n}\n\nvar streamObjectType = {\n Feature: function(object, stream) {\n streamGeometry(object.geometry, stream);\n },\n FeatureCollection: function(object, stream) {\n var features = object.features, i = -1, n = features.length;\n while (++i < n) streamGeometry(features[i].geometry, stream);\n }\n};\n\nvar streamGeometryType = {\n Sphere: function(object, stream) {\n stream.sphere();\n },\n Point: function(object, stream) {\n object = object.coordinates;\n stream.point(object[0], object[1], object[2]);\n },\n MultiPoint: function(object, stream) {\n var coordinates = object.coordinates, i = -1, n = coordinates.length;\n while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);\n },\n LineString: function(object, stream) {\n streamLine(object.coordinates, stream, 0);\n },\n MultiLineString: function(object, stream) {\n var coordinates = object.coordinates, i = -1, n = coordinates.length;\n while (++i < n) streamLine(coordinates[i], stream, 0);\n },\n Polygon: function(object, stream) {\n streamPolygon(object.coordinates, stream);\n },\n MultiPolygon: function(object, stream) {\n var coordinates = object.coordinates, i = -1, n = coordinates.length;\n while (++i < n) streamPolygon(coordinates[i], stream);\n },\n GeometryCollection: function(object, stream) {\n var geometries = object.geometries, i = -1, n = geometries.length;\n while (++i < n) streamGeometry(geometries[i], stream);\n }\n};\n\nfunction streamLine(coordinates, stream, closed) {\n var i = -1, n = coordinates.length - closed, coordinate;\n stream.lineStart();\n while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);\n stream.lineEnd();\n}\n\nfunction streamPolygon(coordinates, stream) {\n var i = -1, n = coordinates.length;\n stream.polygonStart();\n while (++i < n) streamLine(coordinates[i], stream, 1);\n stream.polygonEnd();\n}\n\nexport default function(object, stream) {\n if (object && streamObjectType.hasOwnProperty(object.type)) {\n streamObjectType[object.type](object, stream);\n } else {\n streamGeometry(object, stream);\n }\n}\n","import adder from \"./adder.js\";\nimport {atan2, cos, quarterPi, radians, sin, tau} from \"./math.js\";\nimport noop from \"./noop.js\";\nimport stream from \"./stream.js\";\n\nexport var areaRingSum = adder();\n\nvar areaSum = adder(),\n lambda00,\n phi00,\n lambda0,\n cosPhi0,\n sinPhi0;\n\nexport var areaStream = {\n point: noop,\n lineStart: noop,\n lineEnd: noop,\n polygonStart: function() {\n areaRingSum.reset();\n areaStream.lineStart = areaRingStart;\n areaStream.lineEnd = areaRingEnd;\n },\n polygonEnd: function() {\n var areaRing = +areaRingSum;\n areaSum.add(areaRing < 0 ? tau + areaRing : areaRing);\n this.lineStart = this.lineEnd = this.point = noop;\n },\n sphere: function() {\n areaSum.add(tau);\n }\n};\n\nfunction areaRingStart() {\n areaStream.point = areaPointFirst;\n}\n\nfunction areaRingEnd() {\n areaPoint(lambda00, phi00);\n}\n\nfunction areaPointFirst(lambda, phi) {\n areaStream.point = areaPoint;\n lambda00 = lambda, phi00 = phi;\n lambda *= radians, phi *= radians;\n lambda0 = lambda, cosPhi0 = cos(phi = phi / 2 + quarterPi), sinPhi0 = sin(phi);\n}\n\nfunction areaPoint(lambda, phi) {\n lambda *= radians, phi *= radians;\n phi = phi / 2 + quarterPi; // half the angular distance from south pole\n\n // Spherical excess E for a spherical triangle with vertices: south pole,\n // previous point, current point. Uses a formula derived from Cagnoli’s\n // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).\n var dLambda = lambda - lambda0,\n sdLambda = dLambda >= 0 ? 1 : -1,\n adLambda = sdLambda * dLambda,\n cosPhi = cos(phi),\n sinPhi = sin(phi),\n k = sinPhi0 * sinPhi,\n u = cosPhi0 * cosPhi + k * cos(adLambda),\n v = k * sdLambda * sin(adLambda);\n areaRingSum.add(atan2(v, u));\n\n // Advance the previous points.\n lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;\n}\n\nexport default function(object) {\n areaSum.reset();\n stream(object, areaStream);\n return areaSum * 2;\n}\n","import {asin, atan2, cos, sin, sqrt} from \"./math.js\";\n\nexport function spherical(cartesian) {\n return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];\n}\n\nexport function cartesian(spherical) {\n var lambda = spherical[0], phi = spherical[1], cosPhi = cos(phi);\n return [cosPhi * cos(lambda), cosPhi * sin(lambda), sin(phi)];\n}\n\nexport function cartesianDot(a, b) {\n return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];\n}\n\nexport function cartesianCross(a, b) {\n return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];\n}\n\n// TODO return a\nexport function cartesianAddInPlace(a, b) {\n a[0] += b[0], a[1] += b[1], a[2] += b[2];\n}\n\nexport function cartesianScale(vector, k) {\n return [vector[0] * k, vector[1] * k, vector[2] * k];\n}\n\n// TODO return d\nexport function cartesianNormalizeInPlace(d) {\n var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);\n d[0] /= l, d[1] /= l, d[2] /= l;\n}\n","import adder from \"./adder.js\";\nimport {areaStream, areaRingSum} from \"./area.js\";\nimport {cartesian, cartesianCross, cartesianNormalizeInPlace, spherical} from \"./cartesian.js\";\nimport {abs, degrees, epsilon, radians} from \"./math.js\";\nimport stream from \"./stream.js\";\n\nvar lambda0, phi0, lambda1, phi1, // bounds\n lambda2, // previous lambda-coordinate\n lambda00, phi00, // first point\n p0, // previous 3D point\n deltaSum = adder(),\n ranges,\n range;\n\nvar boundsStream = {\n point: boundsPoint,\n lineStart: boundsLineStart,\n lineEnd: boundsLineEnd,\n polygonStart: function() {\n boundsStream.point = boundsRingPoint;\n boundsStream.lineStart = boundsRingStart;\n boundsStream.lineEnd = boundsRingEnd;\n deltaSum.reset();\n areaStream.polygonStart();\n },\n polygonEnd: function() {\n areaStream.polygonEnd();\n boundsStream.point = boundsPoint;\n boundsStream.lineStart = boundsLineStart;\n boundsStream.lineEnd = boundsLineEnd;\n if (areaRingSum < 0) lambda0 = -(lambda1 = 180), phi0 = -(phi1 = 90);\n else if (deltaSum > epsilon) phi1 = 90;\n else if (deltaSum < -epsilon) phi0 = -90;\n range[0] = lambda0, range[1] = lambda1;\n },\n sphere: function() {\n lambda0 = -(lambda1 = 180), phi0 = -(phi1 = 90);\n }\n};\n\nfunction boundsPoint(lambda, phi) {\n ranges.push(range = [lambda0 = lambda, lambda1 = lambda]);\n if (phi < phi0) phi0 = phi;\n if (phi > phi1) phi1 = phi;\n}\n\nfunction linePoint(lambda, phi) {\n var p = cartesian([lambda * radians, phi * radians]);\n if (p0) {\n var normal = cartesianCross(p0, p),\n equatorial = [normal[1], -normal[0], 0],\n inflection = cartesianCross(equatorial, normal);\n cartesianNormalizeInPlace(inflection);\n inflection = spherical(inflection);\n var delta = lambda - lambda2,\n sign = delta > 0 ? 1 : -1,\n lambdai = inflection[0] * degrees * sign,\n phii,\n antimeridian = abs(delta) > 180;\n if (antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {\n phii = inflection[1] * degrees;\n if (phii > phi1) phi1 = phii;\n } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {\n phii = -inflection[1] * degrees;\n if (phii < phi0) phi0 = phii;\n } else {\n if (phi < phi0) phi0 = phi;\n if (phi > phi1) phi1 = phi;\n }\n if (antimeridian) {\n if (lambda < lambda2) {\n if (angle(lambda0, lambda) > angle(lambda0, lambda1)) lambda1 = lambda;\n } else {\n if (angle(lambda, lambda1) > angle(lambda0, lambda1)) lambda0 = lambda;\n }\n } else {\n if (lambda1 >= lambda0) {\n if (lambda < lambda0) lambda0 = lambda;\n if (lambda > lambda1) lambda1 = lambda;\n } else {\n if (lambda > lambda2) {\n if (angle(lambda0, lambda) > angle(lambda0, lambda1)) lambda1 = lambda;\n } else {\n if (angle(lambda, lambda1) > angle(lambda0, lambda1)) lambda0 = lambda;\n }\n }\n }\n } else {\n ranges.push(range = [lambda0 = lambda, lambda1 = lambda]);\n }\n if (phi < phi0) phi0 = phi;\n if (phi > phi1) phi1 = phi;\n p0 = p, lambda2 = lambda;\n}\n\nfunction boundsLineStart() {\n boundsStream.point = linePoint;\n}\n\nfunction boundsLineEnd() {\n range[0] = lambda0, range[1] = lambda1;\n boundsStream.point = boundsPoint;\n p0 = null;\n}\n\nfunction boundsRingPoint(lambda, phi) {\n if (p0) {\n var delta = lambda - lambda2;\n deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);\n } else {\n lambda00 = lambda, phi00 = phi;\n }\n areaStream.point(lambda, phi);\n linePoint(lambda, phi);\n}\n\nfunction boundsRingStart() {\n areaStream.lineStart();\n}\n\nfunction boundsRingEnd() {\n boundsRingPoint(lambda00, phi00);\n areaStream.lineEnd();\n if (abs(deltaSum) > epsilon) lambda0 = -(lambda1 = 180);\n range[0] = lambda0, range[1] = lambda1;\n p0 = null;\n}\n\n// Finds the left-right distance between two longitudes.\n// This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want\n// the distance between ±180° to be 360°.\nfunction angle(lambda0, lambda1) {\n return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;\n}\n\nfunction rangeCompare(a, b) {\n return a[0] - b[0];\n}\n\nfunction rangeContains(range, x) {\n return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;\n}\n\nexport default function(feature) {\n var i, n, a, b, merged, deltaMax, delta;\n\n phi1 = lambda1 = -(lambda0 = phi0 = Infinity);\n ranges = [];\n stream(feature, boundsStream);\n\n // First, sort ranges by their minimum longitudes.\n if (n = ranges.length) {\n ranges.sort(rangeCompare);\n\n // Then, merge any ranges that overlap.\n for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {\n b = ranges[i];\n if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {\n if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];\n if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];\n } else {\n merged.push(a = b);\n }\n }\n\n // Finally, find the largest gap between the merged ranges.\n // The final bounding box will be the inverse of this gap.\n for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {\n b = merged[i];\n if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0 = b[0], lambda1 = a[1];\n }\n }\n\n ranges = range = null;\n\n return lambda0 === Infinity || phi0 === Infinity\n ? [[NaN, NaN], [NaN, NaN]]\n : [[lambda0, phi0], [lambda1, phi1]];\n}\n","import {asin, atan2, cos, degrees, epsilon, epsilon2, radians, sin, sqrt} from \"./math.js\";\nimport noop from \"./noop.js\";\nimport stream from \"./stream.js\";\n\nvar W0, W1,\n X0, Y0, Z0,\n X1, Y1, Z1,\n X2, Y2, Z2,\n lambda00, phi00, // first point\n x0, y0, z0; // previous point\n\nvar centroidStream = {\n sphere: noop,\n point: centroidPoint,\n lineStart: centroidLineStart,\n lineEnd: centroidLineEnd,\n polygonStart: function() {\n centroidStream.lineStart = centroidRingStart;\n centroidStream.lineEnd = centroidRingEnd;\n },\n polygonEnd: function() {\n centroidStream.lineStart = centroidLineStart;\n centroidStream.lineEnd = centroidLineEnd;\n }\n};\n\n// Arithmetic mean of Cartesian vectors.\nfunction centroidPoint(lambda, phi) {\n lambda *= radians, phi *= radians;\n var cosPhi = cos(phi);\n centroidPointCartesian(cosPhi * cos(lambda), cosPhi * sin(lambda), sin(phi));\n}\n\nfunction centroidPointCartesian(x, y, z) {\n ++W0;\n X0 += (x - X0) / W0;\n Y0 += (y - Y0) / W0;\n Z0 += (z - Z0) / W0;\n}\n\nfunction centroidLineStart() {\n centroidStream.point = centroidLinePointFirst;\n}\n\nfunction centroidLinePointFirst(lambda, phi) {\n lambda *= radians, phi *= radians;\n var cosPhi = cos(phi);\n x0 = cosPhi * cos(lambda);\n y0 = cosPhi * sin(lambda);\n z0 = sin(phi);\n centroidStream.point = centroidLinePoint;\n centroidPointCartesian(x0, y0, z0);\n}\n\nfunction centroidLinePoint(lambda, phi) {\n lambda *= radians, phi *= radians;\n var cosPhi = cos(phi),\n x = cosPhi * cos(lambda),\n y = cosPhi * sin(lambda),\n z = sin(phi),\n w = atan2(sqrt((w = y0 * z - z0 * y) * w + (w = z0 * x - x0 * z) * w + (w = x0 * y - y0 * x) * w), x0 * x + y0 * y + z0 * z);\n W1 += w;\n X1 += w * (x0 + (x0 = x));\n Y1 += w * (y0 + (y0 = y));\n Z1 += w * (z0 + (z0 = z));\n centroidPointCartesian(x0, y0, z0);\n}\n\nfunction centroidLineEnd() {\n centroidStream.point = centroidPoint;\n}\n\n// See J. E. Brock, The Inertia Tensor for a Spherical Triangle,\n// J. Applied Mechanics 42, 239 (1975).\nfunction centroidRingStart() {\n centroidStream.point = centroidRingPointFirst;\n}\n\nfunction centroidRingEnd() {\n centroidRingPoint(lambda00, phi00);\n centroidStream.point = centroidPoint;\n}\n\nfunction centroidRingPointFirst(lambda, phi) {\n lambda00 = lambda, phi00 = phi;\n lambda *= radians, phi *= radians;\n centroidStream.point = centroidRingPoint;\n var cosPhi = cos(phi);\n x0 = cosPhi * cos(lambda);\n y0 = cosPhi * sin(lambda);\n z0 = sin(phi);\n centroidPointCartesian(x0, y0, z0);\n}\n\nfunction centroidRingPoint(lambda, phi) {\n lambda *= radians, phi *= radians;\n var cosPhi = cos(phi),\n x = cosPhi * cos(lambda),\n y = cosPhi * sin(lambda),\n z = sin(phi),\n cx = y0 * z - z0 * y,\n cy = z0 * x - x0 * z,\n cz = x0 * y - y0 * x,\n m = sqrt(cx * cx + cy * cy + cz * cz),\n w = asin(m), // line weight = angle\n v = m && -w / m; // area weight multiplier\n X2 += v * cx;\n Y2 += v * cy;\n Z2 += v * cz;\n W1 += w;\n X1 += w * (x0 + (x0 = x));\n Y1 += w * (y0 + (y0 = y));\n Z1 += w * (z0 + (z0 = z));\n centroidPointCartesian(x0, y0, z0);\n}\n\nexport default function(object) {\n W0 = W1 =\n X0 = Y0 = Z0 =\n X1 = Y1 = Z1 =\n X2 = Y2 = Z2 = 0;\n stream(object, centroidStream);\n\n var x = X2,\n y = Y2,\n z = Z2,\n m = x * x + y * y + z * z;\n\n // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.\n if (m < epsilon2) {\n x = X1, y = Y1, z = Z1;\n // If the feature has zero length, fall back to arithmetic mean of point vectors.\n if (W1 < epsilon) x = X0, y = Y0, z = Z0;\n m = x * x + y * y + z * z;\n // If the feature still has an undefined ccentroid, then return.\n if (m < epsilon2) return [NaN, NaN];\n }\n\n return [atan2(y, x) * degrees, asin(z / sqrt(m)) * degrees];\n}\n","export default function(a, b) {\n\n function compose(x, y) {\n return x = a(x, y), b(x[0], x[1]);\n }\n\n if (a.invert && b.invert) compose.invert = function(x, y) {\n return x = b.invert(x, y), x && a.invert(x[0], x[1]);\n };\n\n return compose;\n}\n","import compose from \"./compose.js\";\nimport {abs, asin, atan2, cos, degrees, pi, radians, sin, tau} from \"./math.js\";\n\nfunction rotationIdentity(lambda, phi) {\n return [abs(lambda) > pi ? lambda + Math.round(-lambda / tau) * tau : lambda, phi];\n}\n\nrotationIdentity.invert = rotationIdentity;\n\nexport function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {\n return (deltaLambda %= tau) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))\n : rotationLambda(deltaLambda))\n : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)\n : rotationIdentity);\n}\n\nfunction forwardRotationLambda(deltaLambda) {\n return function(lambda, phi) {\n return lambda += deltaLambda, [lambda > pi ? lambda - tau : lambda < -pi ? lambda + tau : lambda, phi];\n };\n}\n\nfunction rotationLambda(deltaLambda) {\n var rotation = forwardRotationLambda(deltaLambda);\n rotation.invert = forwardRotationLambda(-deltaLambda);\n return rotation;\n}\n\nfunction rotationPhiGamma(deltaPhi, deltaGamma) {\n var cosDeltaPhi = cos(deltaPhi),\n sinDeltaPhi = sin(deltaPhi),\n cosDeltaGamma = cos(deltaGamma),\n sinDeltaGamma = sin(deltaGamma);\n\n function rotation(lambda, phi) {\n var cosPhi = cos(phi),\n x = cos(lambda) * cosPhi,\n y = sin(lambda) * cosPhi,\n z = sin(phi),\n k = z * cosDeltaPhi + x * sinDeltaPhi;\n return [\n atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),\n asin(k * cosDeltaGamma + y * sinDeltaGamma)\n ];\n }\n\n rotation.invert = function(lambda, phi) {\n var cosPhi = cos(phi),\n x = cos(lambda) * cosPhi,\n y = sin(lambda) * cosPhi,\n z = sin(phi),\n k = z * cosDeltaGamma - y * sinDeltaGamma;\n return [\n atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),\n asin(k * cosDeltaPhi - x * sinDeltaPhi)\n ];\n };\n\n return rotation;\n}\n\nexport default function(rotate) {\n rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);\n\n function forward(coordinates) {\n coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);\n return coordinates[0] *= degrees, coordinates[1] *= degrees, coordinates;\n }\n\n forward.invert = function(coordinates) {\n coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);\n return coordinates[0] *= degrees, coordinates[1] *= degrees, coordinates;\n };\n\n return forward;\n}\n","import {cartesian, cartesianNormalizeInPlace, spherical} from \"./cartesian.js\";\nimport constant from \"./constant.js\";\nimport {acos, cos, degrees, epsilon, radians, sin, tau} from \"./math.js\";\nimport {rotateRadians} from \"./rotation.js\";\n\n// Generates a circle centered at [0°, 0°], with a given radius and precision.\nexport function circleStream(stream, radius, delta, direction, t0, t1) {\n if (!delta) return;\n var cosRadius = cos(radius),\n sinRadius = sin(radius),\n step = direction * delta;\n if (t0 == null) {\n t0 = radius + direction * tau;\n t1 = radius - step / 2;\n } else {\n t0 = circleRadius(cosRadius, t0);\n t1 = circleRadius(cosRadius, t1);\n if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau;\n }\n for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {\n point = spherical([cosRadius, -sinRadius * cos(t), -sinRadius * sin(t)]);\n stream.point(point[0], point[1]);\n }\n}\n\n// Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].\nfunction circleRadius(cosRadius, point) {\n point = cartesian(point), point[0] -= cosRadius;\n cartesianNormalizeInPlace(point);\n var radius = acos(-point[1]);\n return ((-point[2] < 0 ? -radius : radius) + tau - epsilon) % tau;\n}\n\nexport default function() {\n var center = constant([0, 0]),\n radius = constant(90),\n precision = constant(6),\n ring,\n rotate,\n stream = {point: point};\n\n function point(x, y) {\n ring.push(x = rotate(x, y));\n x[0] *= degrees, x[1] *= degrees;\n }\n\n function circle() {\n var c = center.apply(this, arguments),\n r = radius.apply(this, arguments) * radians,\n p = precision.apply(this, arguments) * radians;\n ring = [];\n rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;\n circleStream(stream, r, p, 1);\n c = {type: \"Polygon\", coordinates: [ring]};\n ring = rotate = null;\n return c;\n }\n\n circle.center = function(_) {\n return arguments.length ? (center = typeof _ === \"function\" ? _ : constant([+_[0], +_[1]]), circle) : center;\n };\n\n circle.radius = function(_) {\n return arguments.length ? (radius = typeof _ === \"function\" ? _ : constant(+_), circle) : radius;\n };\n\n circle.precision = function(_) {\n return arguments.length ? (precision = typeof _ === \"function\" ? _ : constant(+_), circle) : precision;\n };\n\n return circle;\n}\n","import noop from \"../noop.js\";\n\nexport default function() {\n var lines = [],\n line;\n return {\n point: function(x, y, m) {\n line.push([x, y, m]);\n },\n lineStart: function() {\n lines.push(line = []);\n },\n lineEnd: noop,\n rejoin: function() {\n if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));\n },\n result: function() {\n var result = lines;\n lines = [];\n line = null;\n return result;\n }\n };\n}\n","import {abs, epsilon} from \"./math.js\";\n\nexport default function(a, b) {\n return abs(a[0] - b[0]) < epsilon && abs(a[1] - b[1]) < epsilon;\n}\n","import pointEqual from \"../pointEqual.js\";\nimport {epsilon} from \"../math.js\";\n\nfunction Intersection(point, points, other, entry) {\n this.x = point;\n this.z = points;\n this.o = other; // another intersection\n this.e = entry; // is an entry?\n this.v = false; // visited\n this.n = this.p = null; // next & previous\n}\n\n// A generalized polygon clipping algorithm: given a polygon that has been cut\n// into its visible line segments, and rejoins the segments by interpolating\n// along the clip edge.\nexport default function(segments, compareIntersection, startInside, interpolate, stream) {\n var subject = [],\n clip = [],\n i,\n n;\n\n segments.forEach(function(segment) {\n if ((n = segment.length - 1) <= 0) return;\n var n, p0 = segment[0], p1 = segment[n], x;\n\n if (pointEqual(p0, p1)) {\n if (!p0[2] && !p1[2]) {\n stream.lineStart();\n for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);\n stream.lineEnd();\n return;\n }\n // handle degenerate cases by moving the point\n p1[0] += 2 * epsilon;\n }\n\n subject.push(x = new Intersection(p0, segment, null, true));\n clip.push(x.o = new Intersection(p0, null, x, false));\n subject.push(x = new Intersection(p1, segment, null, false));\n clip.push(x.o = new Intersection(p1, null, x, true));\n });\n\n if (!subject.length) return;\n\n clip.sort(compareIntersection);\n link(subject);\n link(clip);\n\n for (i = 0, n = clip.length; i < n; ++i) {\n clip[i].e = startInside = !startInside;\n }\n\n var start = subject[0],\n points,\n point;\n\n while (1) {\n // Find first unvisited intersection.\n var current = start,\n isSubject = true;\n while (current.v) if ((current = current.n) === start) return;\n points = current.z;\n stream.lineStart();\n do {\n current.v = current.o.v = true;\n if (current.e) {\n if (isSubject) {\n for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);\n } else {\n interpolate(current.x, current.n.x, 1, stream);\n }\n current = current.n;\n } else {\n if (isSubject) {\n points = current.p.z;\n for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);\n } else {\n interpolate(current.x, current.p.x, -1, stream);\n }\n current = current.p;\n }\n current = current.o;\n points = current.z;\n isSubject = !isSubject;\n } while (!current.v);\n stream.lineEnd();\n }\n}\n\nfunction link(array) {\n if (!(n = array.length)) return;\n var n,\n i = 0,\n a = array[0],\n b;\n while (++i < n) {\n a.n = b = array[i];\n b.p = a;\n a = b;\n }\n a.n = b = array[0];\n b.p = a;\n}\n","import adder from \"./adder.js\";\nimport {cartesian, cartesianCross, cartesianNormalizeInPlace} from \"./cartesian.js\";\nimport {abs, asin, atan2, cos, epsilon, halfPi, pi, quarterPi, sign, sin, tau} from \"./math.js\";\n\nvar sum = adder();\n\nfunction longitude(point) {\n if (abs(point[0]) <= pi)\n return point[0];\n else\n return sign(point[0]) * ((abs(point[0]) + pi) % tau - pi);\n}\n\nexport default function(polygon, point) {\n var lambda = longitude(point),\n phi = point[1],\n sinPhi = sin(phi),\n normal = [sin(lambda), -cos(lambda), 0],\n angle = 0,\n winding = 0;\n\n sum.reset();\n\n if (sinPhi === 1) phi = halfPi + epsilon;\n else if (sinPhi === -1) phi = -halfPi - epsilon;\n\n for (var i = 0, n = polygon.length; i < n; ++i) {\n if (!(m = (ring = polygon[i]).length)) continue;\n var ring,\n m,\n point0 = ring[m - 1],\n lambda0 = longitude(point0),\n phi0 = point0[1] / 2 + quarterPi,\n sinPhi0 = sin(phi0),\n cosPhi0 = cos(phi0);\n\n for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {\n var point1 = ring[j],\n lambda1 = longitude(point1),\n phi1 = point1[1] / 2 + quarterPi,\n sinPhi1 = sin(phi1),\n cosPhi1 = cos(phi1),\n delta = lambda1 - lambda0,\n sign = delta >= 0 ? 1 : -1,\n absDelta = sign * delta,\n antimeridian = absDelta > pi,\n k = sinPhi0 * sinPhi1;\n\n sum.add(atan2(k * sign * sin(absDelta), cosPhi0 * cosPhi1 + k * cos(absDelta)));\n angle += antimeridian ? delta + sign * tau : delta;\n\n // Are the longitudes either side of the point’s meridian (lambda),\n // and are the latitudes smaller than the parallel (phi)?\n if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {\n var arc = cartesianCross(cartesian(point0), cartesian(point1));\n cartesianNormalizeInPlace(arc);\n var intersection = cartesianCross(normal, arc);\n cartesianNormalizeInPlace(intersection);\n var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);\n if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {\n winding += antimeridian ^ delta >= 0 ? 1 : -1;\n }\n }\n }\n }\n\n // First, determine whether the South pole is inside or outside:\n //\n // It is inside if:\n // * the polygon winds around it in a clockwise direction.\n // * the polygon does not (cumulatively) wind around it, but has a negative\n // (counter-clockwise) area.\n //\n // Second, count the (signed) number of times a segment crosses a lambda\n // from the point to the South pole. If it is zero, then the point is the\n // same side as the South pole.\n\n return (angle < -epsilon || angle < epsilon && sum < -epsilon) ^ (winding & 1);\n}\n","export default function(a, b) {\n return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;\n}\n","import ascending from \"./ascending\";\n\nexport default function(compare) {\n if (compare.length === 1) compare = ascendingComparator(compare);\n return {\n left: function(a, x, lo, hi) {\n if (lo == null) lo = 0;\n if (hi == null) hi = a.length;\n while (lo < hi) {\n var mid = lo + hi >>> 1;\n if (compare(a[mid], x) < 0) lo = mid + 1;\n else hi = mid;\n }\n return lo;\n },\n right: function(a, x, lo, hi) {\n if (lo == null) lo = 0;\n if (hi == null) hi = a.length;\n while (lo < hi) {\n var mid = lo + hi >>> 1;\n if (compare(a[mid], x) > 0) hi = mid;\n else lo = mid + 1;\n }\n return lo;\n }\n };\n}\n\nfunction ascendingComparator(f) {\n return function(d, x) {\n return ascending(f(d), x);\n };\n}\n","import ascending from \"./ascending\";\nimport bisector from \"./bisector\";\n\nvar ascendingBisect = bisector(ascending);\nexport var bisectRight = ascendingBisect.right;\nexport var bisectLeft = ascendingBisect.left;\nexport default bisectRight;\n","export default function(a, b) {\n return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;\n}\n","export default function(x) {\n return x === null ? NaN : +x;\n}\n","export default function(start, stop, step) {\n start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;\n\n var i = -1,\n n = Math.max(0, Math.ceil((stop - start) / step)) | 0,\n range = new Array(n);\n\n while (++i < n) {\n range[i] = start + i * step;\n }\n\n return range;\n}\n","var e10 = Math.sqrt(50),\n e5 = Math.sqrt(10),\n e2 = Math.sqrt(2);\n\nexport default function(start, stop, count) {\n var reverse,\n i = -1,\n n,\n ticks,\n step;\n\n stop = +stop, start = +start, count = +count;\n if (start === stop && count > 0) return [start];\n if (reverse = stop < start) n = start, start = stop, stop = n;\n if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];\n\n if (step > 0) {\n start = Math.ceil(start / step);\n stop = Math.floor(stop / step);\n ticks = new Array(n = Math.ceil(stop - start + 1));\n while (++i < n) ticks[i] = (start + i) * step;\n } else {\n start = Math.floor(start * step);\n stop = Math.ceil(stop * step);\n ticks = new Array(n = Math.ceil(start - stop + 1));\n while (++i < n) ticks[i] = (start - i) / step;\n }\n\n if (reverse) ticks.reverse();\n\n return ticks;\n}\n\nexport function tickIncrement(start, stop, count) {\n var step = (stop - start) / Math.max(0, count),\n power = Math.floor(Math.log(step) / Math.LN10),\n error = step / Math.pow(10, power);\n return power >= 0\n ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)\n : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);\n}\n\nexport function tickStep(start, stop, count) {\n var step0 = Math.abs(stop - start) / Math.max(0, count),\n step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),\n error = step0 / step1;\n if (error >= e10) step1 *= 10;\n else if (error >= e5) step1 *= 5;\n else if (error >= e2) step1 *= 2;\n return stop < start ? -step1 : step1;\n}\n","import number from \"./number\";\n\nexport default function(values, p, valueof) {\n if (valueof == null) valueof = number;\n if (!(n = values.length)) return;\n if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);\n if (p >= 1) return +valueof(values[n - 1], n - 1, values);\n var n,\n i = (n - 1) * p,\n i0 = Math.floor(i),\n value0 = +valueof(values[i0], i0, values),\n value1 = +valueof(values[i0 + 1], i0 + 1, values);\n return value0 + (value1 - value0) * (i - i0);\n}\n","import ascending from \"./ascending\";\nimport number from \"./number\";\nimport quantile from \"./quantile\";\n\nexport default function(values, valueof) {\n var n = values.length,\n i = -1,\n value,\n numbers = [];\n\n if (valueof == null) {\n while (++i < n) {\n if (!isNaN(value = number(values[i]))) {\n numbers.push(value);\n }\n }\n }\n\n else {\n while (++i < n) {\n if (!isNaN(value = number(valueof(values[i], i, values)))) {\n numbers.push(value);\n }\n }\n }\n\n return quantile(numbers.sort(ascending), 0.5);\n}\n","export default function(arrays) {\n var n = arrays.length,\n m,\n i = -1,\n j = 0,\n merged,\n array;\n\n while (++i < n) j += arrays[i].length;\n merged = new Array(j);\n\n while (--n >= 0) {\n array = arrays[n];\n m = array.length;\n while (--m >= 0) {\n merged[--j] = array[m];\n }\n }\n\n return merged;\n}\n","import clipBuffer from \"./buffer.js\";\nimport clipRejoin from \"./rejoin.js\";\nimport {epsilon, halfPi} from \"../math.js\";\nimport polygonContains from \"../polygonContains.js\";\nimport {merge} from \"d3-array\";\n\nexport default function(pointVisible, clipLine, interpolate, start) {\n return function(sink) {\n var line = clipLine(sink),\n ringBuffer = clipBuffer(),\n ringSink = clipLine(ringBuffer),\n polygonStarted = false,\n polygon,\n segments,\n ring;\n\n var clip = {\n point: point,\n lineStart: lineStart,\n lineEnd: lineEnd,\n polygonStart: function() {\n clip.point = pointRing;\n clip.lineStart = ringStart;\n clip.lineEnd = ringEnd;\n segments = [];\n polygon = [];\n },\n polygonEnd: function() {\n clip.point = point;\n clip.lineStart = lineStart;\n clip.lineEnd = lineEnd;\n segments = merge(segments);\n var startInside = polygonContains(polygon, start);\n if (segments.length) {\n if (!polygonStarted) sink.polygonStart(), polygonStarted = true;\n clipRejoin(segments, compareIntersection, startInside, interpolate, sink);\n } else if (startInside) {\n if (!polygonStarted) sink.polygonStart(), polygonStarted = true;\n sink.lineStart();\n interpolate(null, null, 1, sink);\n sink.lineEnd();\n }\n if (polygonStarted) sink.polygonEnd(), polygonStarted = false;\n segments = polygon = null;\n },\n sphere: function() {\n sink.polygonStart();\n sink.lineStart();\n interpolate(null, null, 1, sink);\n sink.lineEnd();\n sink.polygonEnd();\n }\n };\n\n function point(lambda, phi) {\n if (pointVisible(lambda, phi)) sink.point(lambda, phi);\n }\n\n function pointLine(lambda, phi) {\n line.point(lambda, phi);\n }\n\n function lineStart() {\n clip.point = pointLine;\n line.lineStart();\n }\n\n function lineEnd() {\n clip.point = point;\n line.lineEnd();\n }\n\n function pointRing(lambda, phi) {\n ring.push([lambda, phi]);\n ringSink.point(lambda, phi);\n }\n\n function ringStart() {\n ringSink.lineStart();\n ring = [];\n }\n\n function ringEnd() {\n pointRing(ring[0][0], ring[0][1]);\n ringSink.lineEnd();\n\n var clean = ringSink.clean(),\n ringSegments = ringBuffer.result(),\n i, n = ringSegments.length, m,\n segment,\n point;\n\n ring.pop();\n polygon.push(ring);\n ring = null;\n\n if (!n) return;\n\n // No intersections.\n if (clean & 1) {\n segment = ringSegments[0];\n if ((m = segment.length - 1) > 0) {\n if (!polygonStarted) sink.polygonStart(), polygonStarted = true;\n sink.lineStart();\n for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);\n sink.lineEnd();\n }\n return;\n }\n\n // Rejoin connected segments.\n // TODO reuse ringBuffer.rejoin()?\n if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));\n\n segments.push(ringSegments.filter(validSegment));\n }\n\n return clip;\n };\n}\n\nfunction validSegment(segment) {\n return segment.length > 1;\n}\n\n// Intersections are sorted along the clip edge. For both antimeridian cutting\n// and circle clipping, the same comparison is used.\nfunction compareIntersection(a, b) {\n return ((a = a.x)[0] < 0 ? a[1] - halfPi - epsilon : halfPi - a[1])\n - ((b = b.x)[0] < 0 ? b[1] - halfPi - epsilon : halfPi - b[1]);\n}\n","import clip from \"./index.js\";\nimport {abs, atan, cos, epsilon, halfPi, pi, sin} from \"../math.js\";\n\nexport default clip(\n function() { return true; },\n clipAntimeridianLine,\n clipAntimeridianInterpolate,\n [-pi, -halfPi]\n);\n\n// Takes a line and cuts into visible segments. Return values: 0 - there were\n// intersections or the line was empty; 1 - no intersections; 2 - there were\n// intersections, and the first and last segments should be rejoined.\nfunction clipAntimeridianLine(stream) {\n var lambda0 = NaN,\n phi0 = NaN,\n sign0 = NaN,\n clean; // no intersections\n\n return {\n lineStart: function() {\n stream.lineStart();\n clean = 1;\n },\n point: function(lambda1, phi1) {\n var sign1 = lambda1 > 0 ? pi : -pi,\n delta = abs(lambda1 - lambda0);\n if (abs(delta - pi) < epsilon) { // line crosses a pole\n stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi : -halfPi);\n stream.point(sign0, phi0);\n stream.lineEnd();\n stream.lineStart();\n stream.point(sign1, phi0);\n stream.point(lambda1, phi0);\n clean = 0;\n } else if (sign0 !== sign1 && delta >= pi) { // line crosses antimeridian\n if (abs(lambda0 - sign0) < epsilon) lambda0 -= sign0 * epsilon; // handle degeneracies\n if (abs(lambda1 - sign1) < epsilon) lambda1 -= sign1 * epsilon;\n phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);\n stream.point(sign0, phi0);\n stream.lineEnd();\n stream.lineStart();\n stream.point(sign1, phi0);\n clean = 0;\n }\n stream.point(lambda0 = lambda1, phi0 = phi1);\n sign0 = sign1;\n },\n lineEnd: function() {\n stream.lineEnd();\n lambda0 = phi0 = NaN;\n },\n clean: function() {\n return 2 - clean; // if intersections, rejoin first and last segments\n }\n };\n}\n\nfunction clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {\n var cosPhi0,\n cosPhi1,\n sinLambda0Lambda1 = sin(lambda0 - lambda1);\n return abs(sinLambda0Lambda1) > epsilon\n ? atan((sin(phi0) * (cosPhi1 = cos(phi1)) * sin(lambda1)\n - sin(phi1) * (cosPhi0 = cos(phi0)) * sin(lambda0))\n / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))\n : (phi0 + phi1) / 2;\n}\n\nfunction clipAntimeridianInterpolate(from, to, direction, stream) {\n var phi;\n if (from == null) {\n phi = direction * halfPi;\n stream.point(-pi, phi);\n stream.point(0, phi);\n stream.point(pi, phi);\n stream.point(pi, 0);\n stream.point(pi, -phi);\n stream.point(0, -phi);\n stream.point(-pi, -phi);\n stream.point(-pi, 0);\n stream.point(-pi, phi);\n } else if (abs(from[0] - to[0]) > epsilon) {\n var lambda = from[0] < to[0] ? pi : -pi;\n phi = direction * lambda / 2;\n stream.point(-lambda, phi);\n stream.point(0, phi);\n stream.point(lambda, phi);\n } else {\n stream.point(to[0], to[1]);\n }\n}\n","import {cartesian, cartesianAddInPlace, cartesianCross, cartesianDot, cartesianScale, spherical} from \"../cartesian.js\";\nimport {circleStream} from \"../circle.js\";\nimport {abs, cos, epsilon, pi, radians, sqrt} from \"../math.js\";\nimport pointEqual from \"../pointEqual.js\";\nimport clip from \"./index.js\";\n\nexport default function(radius) {\n var cr = cos(radius),\n delta = 6 * radians,\n smallRadius = cr > 0,\n notHemisphere = abs(cr) > epsilon; // TODO optimise for this common case\n\n function interpolate(from, to, direction, stream) {\n circleStream(stream, radius, delta, direction, from, to);\n }\n\n function visible(lambda, phi) {\n return cos(lambda) * cos(phi) > cr;\n }\n\n // Takes a line and cuts into visible segments. Return values used for polygon\n // clipping: 0 - there were intersections or the line was empty; 1 - no\n // intersections 2 - there were intersections, and the first and last segments\n // should be rejoined.\n function clipLine(stream) {\n var point0, // previous point\n c0, // code for previous point\n v0, // visibility of previous point\n v00, // visibility of first point\n clean; // no intersections\n return {\n lineStart: function() {\n v00 = v0 = false;\n clean = 1;\n },\n point: function(lambda, phi) {\n var point1 = [lambda, phi],\n point2,\n v = visible(lambda, phi),\n c = smallRadius\n ? v ? 0 : code(lambda, phi)\n : v ? code(lambda + (lambda < 0 ? pi : -pi), phi) : 0;\n if (!point0 && (v00 = v0 = v)) stream.lineStart();\n if (v !== v0) {\n point2 = intersect(point0, point1);\n if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2))\n point1[2] = 1;\n }\n if (v !== v0) {\n clean = 0;\n if (v) {\n // outside going in\n stream.lineStart();\n point2 = intersect(point1, point0);\n stream.point(point2[0], point2[1]);\n } else {\n // inside going out\n point2 = intersect(point0, point1);\n stream.point(point2[0], point2[1], 2);\n stream.lineEnd();\n }\n point0 = point2;\n } else if (notHemisphere && point0 && smallRadius ^ v) {\n var t;\n // If the codes for two points are different, or are both zero,\n // and there this segment intersects with the small circle.\n if (!(c & c0) && (t = intersect(point1, point0, true))) {\n clean = 0;\n if (smallRadius) {\n stream.lineStart();\n stream.point(t[0][0], t[0][1]);\n stream.point(t[1][0], t[1][1]);\n stream.lineEnd();\n } else {\n stream.point(t[1][0], t[1][1]);\n stream.lineEnd();\n stream.lineStart();\n stream.point(t[0][0], t[0][1], 3);\n }\n }\n }\n if (v && (!point0 || !pointEqual(point0, point1))) {\n stream.point(point1[0], point1[1]);\n }\n point0 = point1, v0 = v, c0 = c;\n },\n lineEnd: function() {\n if (v0) stream.lineEnd();\n point0 = null;\n },\n // Rejoin first and last segments if there were intersections and the first\n // and last points were visible.\n clean: function() {\n return clean | ((v00 && v0) << 1);\n }\n };\n }\n\n // Intersects the great circle between a and b with the clip circle.\n function intersect(a, b, two) {\n var pa = cartesian(a),\n pb = cartesian(b);\n\n // We have two planes, n1.p = d1 and n2.p = d2.\n // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).\n var n1 = [1, 0, 0], // normal\n n2 = cartesianCross(pa, pb),\n n2n2 = cartesianDot(n2, n2),\n n1n2 = n2[0], // cartesianDot(n1, n2),\n determinant = n2n2 - n1n2 * n1n2;\n\n // Two polar points.\n if (!determinant) return !two && a;\n\n var c1 = cr * n2n2 / determinant,\n c2 = -cr * n1n2 / determinant,\n n1xn2 = cartesianCross(n1, n2),\n A = cartesianScale(n1, c1),\n B = cartesianScale(n2, c2);\n cartesianAddInPlace(A, B);\n\n // Solve |p(t)|^2 = 1.\n var u = n1xn2,\n w = cartesianDot(A, u),\n uu = cartesianDot(u, u),\n t2 = w * w - uu * (cartesianDot(A, A) - 1);\n\n if (t2 < 0) return;\n\n var t = sqrt(t2),\n q = cartesianScale(u, (-w - t) / uu);\n cartesianAddInPlace(q, A);\n q = spherical(q);\n\n if (!two) return q;\n\n // Two intersection points.\n var lambda0 = a[0],\n lambda1 = b[0],\n phi0 = a[1],\n phi1 = b[1],\n z;\n\n if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;\n\n var delta = lambda1 - lambda0,\n polar = abs(delta - pi) < epsilon,\n meridian = polar || delta < epsilon;\n\n if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;\n\n // Check that the first point is between a and b.\n if (meridian\n ? polar\n ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon ? phi0 : phi1)\n : phi0 <= q[1] && q[1] <= phi1\n : delta > pi ^ (lambda0 <= q[0] && q[0] <= lambda1)) {\n var q1 = cartesianScale(u, (-w + t) / uu);\n cartesianAddInPlace(q1, A);\n return [q, spherical(q1)];\n }\n }\n\n // Generates a 4-bit vector representing the location of a point relative to\n // the small circle's bounding box.\n function code(lambda, phi) {\n var r = smallRadius ? radius : pi - radius,\n code = 0;\n if (lambda < -r) code |= 1; // left\n else if (lambda > r) code |= 2; // right\n if (phi < -r) code |= 4; // below\n else if (phi > r) code |= 8; // above\n return code;\n }\n\n return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi, radius - pi]);\n}\n","export default function(a, b, x0, y0, x1, y1) {\n var ax = a[0],\n ay = a[1],\n bx = b[0],\n by = b[1],\n t0 = 0,\n t1 = 1,\n dx = bx - ax,\n dy = by - ay,\n r;\n\n r = x0 - ax;\n if (!dx && r > 0) return;\n r /= dx;\n if (dx < 0) {\n if (r < t0) return;\n if (r < t1) t1 = r;\n } else if (dx > 0) {\n if (r > t1) return;\n if (r > t0) t0 = r;\n }\n\n r = x1 - ax;\n if (!dx && r < 0) return;\n r /= dx;\n if (dx < 0) {\n if (r > t1) return;\n if (r > t0) t0 = r;\n } else if (dx > 0) {\n if (r < t0) return;\n if (r < t1) t1 = r;\n }\n\n r = y0 - ay;\n if (!dy && r > 0) return;\n r /= dy;\n if (dy < 0) {\n if (r < t0) return;\n if (r < t1) t1 = r;\n } else if (dy > 0) {\n if (r > t1) return;\n if (r > t0) t0 = r;\n }\n\n r = y1 - ay;\n if (!dy && r < 0) return;\n r /= dy;\n if (dy < 0) {\n if (r > t1) return;\n if (r > t0) t0 = r;\n } else if (dy > 0) {\n if (r < t0) return;\n if (r < t1) t1 = r;\n }\n\n if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;\n if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;\n return true;\n}\n","import {abs, epsilon} from \"../math.js\";\nimport clipBuffer from \"./buffer.js\";\nimport clipLine from \"./line.js\";\nimport clipRejoin from \"./rejoin.js\";\nimport {merge} from \"d3-array\";\n\nvar clipMax = 1e9, clipMin = -clipMax;\n\n// TODO Use d3-polygon’s polygonContains here for the ring check?\n// TODO Eliminate duplicate buffering in clipBuffer and polygon.push?\n\nexport default function clipRectangle(x0, y0, x1, y1) {\n\n function visible(x, y) {\n return x0 <= x && x <= x1 && y0 <= y && y <= y1;\n }\n\n function interpolate(from, to, direction, stream) {\n var a = 0, a1 = 0;\n if (from == null\n || (a = corner(from, direction)) !== (a1 = corner(to, direction))\n || comparePoint(from, to) < 0 ^ direction > 0) {\n do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);\n while ((a = (a + direction + 4) % 4) !== a1);\n } else {\n stream.point(to[0], to[1]);\n }\n }\n\n function corner(p, direction) {\n return abs(p[0] - x0) < epsilon ? direction > 0 ? 0 : 3\n : abs(p[0] - x1) < epsilon ? direction > 0 ? 2 : 1\n : abs(p[1] - y0) < epsilon ? direction > 0 ? 1 : 0\n : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon\n }\n\n function compareIntersection(a, b) {\n return comparePoint(a.x, b.x);\n }\n\n function comparePoint(a, b) {\n var ca = corner(a, 1),\n cb = corner(b, 1);\n return ca !== cb ? ca - cb\n : ca === 0 ? b[1] - a[1]\n : ca === 1 ? a[0] - b[0]\n : ca === 2 ? a[1] - b[1]\n : b[0] - a[0];\n }\n\n return function(stream) {\n var activeStream = stream,\n bufferStream = clipBuffer(),\n segments,\n polygon,\n ring,\n x__, y__, v__, // first point\n x_, y_, v_, // previous point\n first,\n clean;\n\n var clipStream = {\n point: point,\n lineStart: lineStart,\n lineEnd: lineEnd,\n polygonStart: polygonStart,\n polygonEnd: polygonEnd\n };\n\n function point(x, y) {\n if (visible(x, y)) activeStream.point(x, y);\n }\n\n function polygonInside() {\n var winding = 0;\n\n for (var i = 0, n = polygon.length; i < n; ++i) {\n for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {\n a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];\n if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }\n else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }\n }\n }\n\n return winding;\n }\n\n // Buffer geometry within a polygon and then clip it en masse.\n function polygonStart() {\n activeStream = bufferStream, segments = [], polygon = [], clean = true;\n }\n\n function polygonEnd() {\n var startInside = polygonInside(),\n cleanInside = clean && startInside,\n visible = (segments = merge(segments)).length;\n if (cleanInside || visible) {\n stream.polygonStart();\n if (cleanInside) {\n stream.lineStart();\n interpolate(null, null, 1, stream);\n stream.lineEnd();\n }\n if (visible) {\n clipRejoin(segments, compareIntersection, startInside, interpolate, stream);\n }\n stream.polygonEnd();\n }\n activeStream = stream, segments = polygon = ring = null;\n }\n\n function lineStart() {\n clipStream.point = linePoint;\n if (polygon) polygon.push(ring = []);\n first = true;\n v_ = false;\n x_ = y_ = NaN;\n }\n\n // TODO rather than special-case polygons, simply handle them separately.\n // Ideally, coincident intersection points should be jittered to avoid\n // clipping issues.\n function lineEnd() {\n if (segments) {\n linePoint(x__, y__);\n if (v__ && v_) bufferStream.rejoin();\n segments.push(bufferStream.result());\n }\n clipStream.point = point;\n if (v_) activeStream.lineEnd();\n }\n\n function linePoint(x, y) {\n var v = visible(x, y);\n if (polygon) ring.push([x, y]);\n if (first) {\n x__ = x, y__ = y, v__ = v;\n first = false;\n if (v) {\n activeStream.lineStart();\n activeStream.point(x, y);\n }\n } else {\n if (v && v_) activeStream.point(x, y);\n else {\n var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],\n b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];\n if (clipLine(a, b, x0, y0, x1, y1)) {\n if (!v_) {\n activeStream.lineStart();\n activeStream.point(a[0], a[1]);\n }\n activeStream.point(b[0], b[1]);\n if (!v) activeStream.lineEnd();\n clean = false;\n } else if (v) {\n activeStream.lineStart();\n activeStream.point(x, y);\n clean = false;\n }\n }\n }\n x_ = x, y_ = y, v_ = v;\n }\n\n return clipStream;\n };\n}\n","import adder from \"./adder.js\";\nimport {abs, atan2, cos, radians, sin, sqrt} from \"./math.js\";\nimport noop from \"./noop.js\";\nimport stream from \"./stream.js\";\n\nvar lengthSum = adder(),\n lambda0,\n sinPhi0,\n cosPhi0;\n\nvar lengthStream = {\n sphere: noop,\n point: noop,\n lineStart: lengthLineStart,\n lineEnd: noop,\n polygonStart: noop,\n polygonEnd: noop\n};\n\nfunction lengthLineStart() {\n lengthStream.point = lengthPointFirst;\n lengthStream.lineEnd = lengthLineEnd;\n}\n\nfunction lengthLineEnd() {\n lengthStream.point = lengthStream.lineEnd = noop;\n}\n\nfunction lengthPointFirst(lambda, phi) {\n lambda *= radians, phi *= radians;\n lambda0 = lambda, sinPhi0 = sin(phi), cosPhi0 = cos(phi);\n lengthStream.point = lengthPoint;\n}\n\nfunction lengthPoint(lambda, phi) {\n lambda *= radians, phi *= radians;\n var sinPhi = sin(phi),\n cosPhi = cos(phi),\n delta = abs(lambda - lambda0),\n cosDelta = cos(delta),\n sinDelta = sin(delta),\n x = cosPhi * sinDelta,\n y = cosPhi0 * sinPhi - sinPhi0 * cosPhi * cosDelta,\n z = sinPhi0 * sinPhi + cosPhi0 * cosPhi * cosDelta;\n lengthSum.add(atan2(sqrt(x * x + y * y), z));\n lambda0 = lambda, sinPhi0 = sinPhi, cosPhi0 = cosPhi;\n}\n\nexport default function(object) {\n lengthSum.reset();\n stream(object, lengthStream);\n return +lengthSum;\n}\n","export default function(x) {\n return x;\n}\n","import adder from \"../adder.js\";\nimport {abs} from \"../math.js\";\nimport noop from \"../noop.js\";\n\nvar areaSum = adder(),\n areaRingSum = adder(),\n x00,\n y00,\n x0,\n y0;\n\nvar areaStream = {\n point: noop,\n lineStart: noop,\n lineEnd: noop,\n polygonStart: function() {\n areaStream.lineStart = areaRingStart;\n areaStream.lineEnd = areaRingEnd;\n },\n polygonEnd: function() {\n areaStream.lineStart = areaStream.lineEnd = areaStream.point = noop;\n areaSum.add(abs(areaRingSum));\n areaRingSum.reset();\n },\n result: function() {\n var area = areaSum / 2;\n areaSum.reset();\n return area;\n }\n};\n\nfunction areaRingStart() {\n areaStream.point = areaPointFirst;\n}\n\nfunction areaPointFirst(x, y) {\n areaStream.point = areaPoint;\n x00 = x0 = x, y00 = y0 = y;\n}\n\nfunction areaPoint(x, y) {\n areaRingSum.add(y0 * x - x0 * y);\n x0 = x, y0 = y;\n}\n\nfunction areaRingEnd() {\n areaPoint(x00, y00);\n}\n\nexport default areaStream;\n","import noop from \"../noop.js\";\n\nvar x0 = Infinity,\n y0 = x0,\n x1 = -x0,\n y1 = x1;\n\nvar boundsStream = {\n point: boundsPoint,\n lineStart: noop,\n lineEnd: noop,\n polygonStart: noop,\n polygonEnd: noop,\n result: function() {\n var bounds = [[x0, y0], [x1, y1]];\n x1 = y1 = -(y0 = x0 = Infinity);\n return bounds;\n }\n};\n\nfunction boundsPoint(x, y) {\n if (x < x0) x0 = x;\n if (x > x1) x1 = x;\n if (y < y0) y0 = y;\n if (y > y1) y1 = y;\n}\n\nexport default boundsStream;\n","import {sqrt} from \"../math.js\";\n\n// TODO Enforce positive area for exterior, negative area for interior?\n\nvar X0 = 0,\n Y0 = 0,\n Z0 = 0,\n X1 = 0,\n Y1 = 0,\n Z1 = 0,\n X2 = 0,\n Y2 = 0,\n Z2 = 0,\n x00,\n y00,\n x0,\n y0;\n\nvar centroidStream = {\n point: centroidPoint,\n lineStart: centroidLineStart,\n lineEnd: centroidLineEnd,\n polygonStart: function() {\n centroidStream.lineStart = centroidRingStart;\n centroidStream.lineEnd = centroidRingEnd;\n },\n polygonEnd: function() {\n centroidStream.point = centroidPoint;\n centroidStream.lineStart = centroidLineStart;\n centroidStream.lineEnd = centroidLineEnd;\n },\n result: function() {\n var centroid = Z2 ? [X2 / Z2, Y2 / Z2]\n : Z1 ? [X1 / Z1, Y1 / Z1]\n : Z0 ? [X0 / Z0, Y0 / Z0]\n : [NaN, NaN];\n X0 = Y0 = Z0 =\n X1 = Y1 = Z1 =\n X2 = Y2 = Z2 = 0;\n return centroid;\n }\n};\n\nfunction centroidPoint(x, y) {\n X0 += x;\n Y0 += y;\n ++Z0;\n}\n\nfunction centroidLineStart() {\n centroidStream.point = centroidPointFirstLine;\n}\n\nfunction centroidPointFirstLine(x, y) {\n centroidStream.point = centroidPointLine;\n centroidPoint(x0 = x, y0 = y);\n}\n\nfunction centroidPointLine(x, y) {\n var dx = x - x0, dy = y - y0, z = sqrt(dx * dx + dy * dy);\n X1 += z * (x0 + x) / 2;\n Y1 += z * (y0 + y) / 2;\n Z1 += z;\n centroidPoint(x0 = x, y0 = y);\n}\n\nfunction centroidLineEnd() {\n centroidStream.point = centroidPoint;\n}\n\nfunction centroidRingStart() {\n centroidStream.point = centroidPointFirstRing;\n}\n\nfunction centroidRingEnd() {\n centroidPointRing(x00, y00);\n}\n\nfunction centroidPointFirstRing(x, y) {\n centroidStream.point = centroidPointRing;\n centroidPoint(x00 = x0 = x, y00 = y0 = y);\n}\n\nfunction centroidPointRing(x, y) {\n var dx = x - x0,\n dy = y - y0,\n z = sqrt(dx * dx + dy * dy);\n\n X1 += z * (x0 + x) / 2;\n Y1 += z * (y0 + y) / 2;\n Z1 += z;\n\n z = y0 * x - x0 * y;\n X2 += z * (x0 + x);\n Y2 += z * (y0 + y);\n Z2 += z * 3;\n centroidPoint(x0 = x, y0 = y);\n}\n\nexport default centroidStream;\n","import {tau} from \"../math.js\";\nimport noop from \"../noop.js\";\n\nexport default function PathContext(context) {\n this._context = context;\n}\n\nPathContext.prototype = {\n _radius: 4.5,\n pointRadius: function(_) {\n return this._radius = _, this;\n },\n polygonStart: function() {\n this._line = 0;\n },\n polygonEnd: function() {\n this._line = NaN;\n },\n lineStart: function() {\n this._point = 0;\n },\n lineEnd: function() {\n if (this._line === 0) this._context.closePath();\n this._point = NaN;\n },\n point: function(x, y) {\n switch (this._point) {\n case 0: {\n this._context.moveTo(x, y);\n this._point = 1;\n break;\n }\n case 1: {\n this._context.lineTo(x, y);\n break;\n }\n default: {\n this._context.moveTo(x + this._radius, y);\n this._context.arc(x, y, this._radius, 0, tau);\n break;\n }\n }\n },\n result: noop\n};\n","import adder from \"../adder.js\";\nimport {sqrt} from \"../math.js\";\nimport noop from \"../noop.js\";\n\nvar lengthSum = adder(),\n lengthRing,\n x00,\n y00,\n x0,\n y0;\n\nvar lengthStream = {\n point: noop,\n lineStart: function() {\n lengthStream.point = lengthPointFirst;\n },\n lineEnd: function() {\n if (lengthRing) lengthPoint(x00, y00);\n lengthStream.point = noop;\n },\n polygonStart: function() {\n lengthRing = true;\n },\n polygonEnd: function() {\n lengthRing = null;\n },\n result: function() {\n var length = +lengthSum;\n lengthSum.reset();\n return length;\n }\n};\n\nfunction lengthPointFirst(x, y) {\n lengthStream.point = lengthPoint;\n x00 = x0 = x, y00 = y0 = y;\n}\n\nfunction lengthPoint(x, y) {\n x0 -= x, y0 -= y;\n lengthSum.add(sqrt(x0 * x0 + y0 * y0));\n x0 = x, y0 = y;\n}\n\nexport default lengthStream;\n","export default function PathString() {\n this._string = [];\n}\n\nPathString.prototype = {\n _radius: 4.5,\n _circle: circle(4.5),\n pointRadius: function(_) {\n if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;\n return this;\n },\n polygonStart: function() {\n this._line = 0;\n },\n polygonEnd: function() {\n this._line = NaN;\n },\n lineStart: function() {\n this._point = 0;\n },\n lineEnd: function() {\n if (this._line === 0) this._string.push(\"Z\");\n this._point = NaN;\n },\n point: function(x, y) {\n switch (this._point) {\n case 0: {\n this._string.push(\"M\", x, \",\", y);\n this._point = 1;\n break;\n }\n case 1: {\n this._string.push(\"L\", x, \",\", y);\n break;\n }\n default: {\n if (this._circle == null) this._circle = circle(this._radius);\n this._string.push(\"M\", x, \",\", y, this._circle);\n break;\n }\n }\n },\n result: function() {\n if (this._string.length) {\n var result = this._string.join(\"\");\n this._string = [];\n return result;\n } else {\n return null;\n }\n }\n};\n\nfunction circle(radius) {\n return \"m0,\" + radius\n + \"a\" + radius + \",\" + radius + \" 0 1,1 0,\" + -2 * radius\n + \"a\" + radius + \",\" + radius + \" 0 1,1 0,\" + 2 * radius\n + \"z\";\n}\n","import identity from \"../identity.js\";\nimport stream from \"../stream.js\";\nimport pathArea from \"./area.js\";\nimport pathBounds from \"./bounds.js\";\nimport pathCentroid from \"./centroid.js\";\nimport PathContext from \"./context.js\";\nimport pathMeasure from \"./measure.js\";\nimport PathString from \"./string.js\";\n\nexport default function(projection, context) {\n var pointRadius = 4.5,\n projectionStream,\n contextStream;\n\n function path(object) {\n if (object) {\n if (typeof pointRadius === \"function\") contextStream.pointRadius(+pointRadius.apply(this, arguments));\n stream(object, projectionStream(contextStream));\n }\n return contextStream.result();\n }\n\n path.area = function(object) {\n stream(object, projectionStream(pathArea));\n return pathArea.result();\n };\n\n path.measure = function(object) {\n stream(object, projectionStream(pathMeasure));\n return pathMeasure.result();\n };\n\n path.bounds = function(object) {\n stream(object, projectionStream(pathBounds));\n return pathBounds.result();\n };\n\n path.centroid = function(object) {\n stream(object, projectionStream(pathCentroid));\n return pathCentroid.result();\n };\n\n path.projection = function(_) {\n return arguments.length ? (projectionStream = _ == null ? (projection = null, identity) : (projection = _).stream, path) : projection;\n };\n\n path.context = function(_) {\n if (!arguments.length) return context;\n contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);\n if (typeof pointRadius !== \"function\") contextStream.pointRadius(pointRadius);\n return path;\n };\n\n path.pointRadius = function(_) {\n if (!arguments.length) return pointRadius;\n pointRadius = typeof _ === \"function\" ? _ : (contextStream.pointRadius(+_), +_);\n return path;\n };\n\n return path.projection(projection).context(context);\n}\n","export default function(methods) {\n return {\n stream: transformer(methods)\n };\n}\n\nexport function transformer(methods) {\n return function(stream) {\n var s = new TransformStream;\n for (var key in methods) s[key] = methods[key];\n s.stream = stream;\n return s;\n };\n}\n\nfunction TransformStream() {}\n\nTransformStream.prototype = {\n constructor: TransformStream,\n point: function(x, y) { this.stream.point(x, y); },\n sphere: function() { this.stream.sphere(); },\n lineStart: function() { this.stream.lineStart(); },\n lineEnd: function() { this.stream.lineEnd(); },\n polygonStart: function() { this.stream.polygonStart(); },\n polygonEnd: function() { this.stream.polygonEnd(); }\n};\n","import {default as geoStream} from \"../stream.js\";\nimport boundsStream from \"../path/bounds.js\";\n\nfunction fit(projection, fitBounds, object) {\n var clip = projection.clipExtent && projection.clipExtent();\n projection.scale(150).translate([0, 0]);\n if (clip != null) projection.clipExtent(null);\n geoStream(object, projection.stream(boundsStream));\n fitBounds(boundsStream.result());\n if (clip != null) projection.clipExtent(clip);\n return projection;\n}\n\nexport function fitExtent(projection, extent, object) {\n return fit(projection, function(b) {\n var w = extent[1][0] - extent[0][0],\n h = extent[1][1] - extent[0][1],\n k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),\n x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,\n y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;\n projection.scale(150 * k).translate([x, y]);\n }, object);\n}\n\nexport function fitSize(projection, size, object) {\n return fitExtent(projection, [[0, 0], size], object);\n}\n\nexport function fitWidth(projection, width, object) {\n return fit(projection, function(b) {\n var w = +width,\n k = w / (b[1][0] - b[0][0]),\n x = (w - k * (b[1][0] + b[0][0])) / 2,\n y = -k * b[0][1];\n projection.scale(150 * k).translate([x, y]);\n }, object);\n}\n\nexport function fitHeight(projection, height, object) {\n return fit(projection, function(b) {\n var h = +height,\n k = h / (b[1][1] - b[0][1]),\n x = -k * b[0][0],\n y = (h - k * (b[1][1] + b[0][1])) / 2;\n projection.scale(150 * k).translate([x, y]);\n }, object);\n}\n","import {cartesian} from \"../cartesian.js\";\nimport {abs, asin, atan2, cos, epsilon, radians, sqrt} from \"../math.js\";\nimport {transformer} from \"../transform.js\";\n\nvar maxDepth = 16, // maximum depth of subdivision\n cosMinDistance = cos(30 * radians); // cos(minimum angular distance)\n\nexport default function(project, delta2) {\n return +delta2 ? resample(project, delta2) : resampleNone(project);\n}\n\nfunction resampleNone(project) {\n return transformer({\n point: function(x, y) {\n x = project(x, y);\n this.stream.point(x[0], x[1]);\n }\n });\n}\n\nfunction resample(project, delta2) {\n\n function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {\n var dx = x1 - x0,\n dy = y1 - y0,\n d2 = dx * dx + dy * dy;\n if (d2 > 4 * delta2 && depth--) {\n var a = a0 + a1,\n b = b0 + b1,\n c = c0 + c1,\n m = sqrt(a * a + b * b + c * c),\n phi2 = asin(c /= m),\n lambda2 = abs(abs(c) - 1) < epsilon || abs(lambda0 - lambda1) < epsilon ? (lambda0 + lambda1) / 2 : atan2(b, a),\n p = project(lambda2, phi2),\n x2 = p[0],\n y2 = p[1],\n dx2 = x2 - x0,\n dy2 = y2 - y0,\n dz = dy * dx2 - dx * dy2;\n if (dz * dz / d2 > delta2 // perpendicular projected distance\n || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end\n || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance\n resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);\n stream.point(x2, y2);\n resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);\n }\n }\n }\n return function(stream) {\n var lambda00, x00, y00, a00, b00, c00, // first point\n lambda0, x0, y0, a0, b0, c0; // previous point\n\n var resampleStream = {\n point: point,\n lineStart: lineStart,\n lineEnd: lineEnd,\n polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },\n polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }\n };\n\n function point(x, y) {\n x = project(x, y);\n stream.point(x[0], x[1]);\n }\n\n function lineStart() {\n x0 = NaN;\n resampleStream.point = linePoint;\n stream.lineStart();\n }\n\n function linePoint(lambda, phi) {\n var c = cartesian([lambda, phi]), p = project(lambda, phi);\n resampleLineTo(x0, y0, lambda0, a0, b0, c0, x0 = p[0], y0 = p[1], lambda0 = lambda, a0 = c[0], b0 = c[1], c0 = c[2], maxDepth, stream);\n stream.point(x0, y0);\n }\n\n function lineEnd() {\n resampleStream.point = point;\n stream.lineEnd();\n }\n\n function ringStart() {\n lineStart();\n resampleStream.point = ringPoint;\n resampleStream.lineEnd = ringEnd;\n }\n\n function ringPoint(lambda, phi) {\n linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;\n resampleStream.point = linePoint;\n }\n\n function ringEnd() {\n resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);\n resampleStream.lineEnd = lineEnd;\n lineEnd();\n }\n\n return resampleStream;\n };\n}\n","import clipAntimeridian from \"../clip/antimeridian.js\";\nimport clipCircle from \"../clip/circle.js\";\nimport clipRectangle from \"../clip/rectangle.js\";\nimport compose from \"../compose.js\";\nimport identity from \"../identity.js\";\nimport {cos, degrees, radians, sin, sqrt} from \"../math.js\";\nimport {rotateRadians} from \"../rotation.js\";\nimport {transformer} from \"../transform.js\";\nimport {fitExtent, fitSize, fitWidth, fitHeight} from \"./fit.js\";\nimport resample from \"./resample.js\";\n\nvar transformRadians = transformer({\n point: function(x, y) {\n this.stream.point(x * radians, y * radians);\n }\n});\n\nfunction transformRotate(rotate) {\n return transformer({\n point: function(x, y) {\n var r = rotate(x, y);\n return this.stream.point(r[0], r[1]);\n }\n });\n}\n\nfunction scaleTranslate(k, dx, dy, sx, sy) {\n function transform(x, y) {\n x *= sx; y *= sy;\n return [dx + k * x, dy - k * y];\n }\n transform.invert = function(x, y) {\n return [(x - dx) / k * sx, (dy - y) / k * sy];\n };\n return transform;\n}\n\nfunction scaleTranslateRotate(k, dx, dy, sx, sy, alpha) {\n var cosAlpha = cos(alpha),\n sinAlpha = sin(alpha),\n a = cosAlpha * k,\n b = sinAlpha * k,\n ai = cosAlpha / k,\n bi = sinAlpha / k,\n ci = (sinAlpha * dy - cosAlpha * dx) / k,\n fi = (sinAlpha * dx + cosAlpha * dy) / k;\n function transform(x, y) {\n x *= sx; y *= sy;\n return [a * x - b * y + dx, dy - b * x - a * y];\n }\n transform.invert = function(x, y) {\n return [sx * (ai * x - bi * y + ci), sy * (fi - bi * x - ai * y)];\n };\n return transform;\n}\n\nexport default function projection(project) {\n return projectionMutator(function() { return project; })();\n}\n\nexport function projectionMutator(projectAt) {\n var project,\n k = 150, // scale\n x = 480, y = 250, // translate\n lambda = 0, phi = 0, // center\n deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate\n alpha = 0, // post-rotate angle\n sx = 1, // reflectX\n sy = 1, // reflectX\n theta = null, preclip = clipAntimeridian, // pre-clip angle\n x0 = null, y0, x1, y1, postclip = identity, // post-clip extent\n delta2 = 0.5, // precision\n projectResample,\n projectTransform,\n projectRotateTransform,\n cache,\n cacheStream;\n\n function projection(point) {\n return projectRotateTransform(point[0] * radians, point[1] * radians);\n }\n\n function invert(point) {\n point = projectRotateTransform.invert(point[0], point[1]);\n return point && [point[0] * degrees, point[1] * degrees];\n }\n\n projection.stream = function(stream) {\n return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));\n };\n\n projection.preclip = function(_) {\n return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;\n };\n\n projection.postclip = function(_) {\n return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;\n };\n\n projection.clipAngle = function(_) {\n return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees;\n };\n\n projection.clipExtent = function(_) {\n return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];\n };\n\n projection.scale = function(_) {\n return arguments.length ? (k = +_, recenter()) : k;\n };\n\n projection.translate = function(_) {\n return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];\n };\n\n projection.center = function(_) {\n return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees, phi * degrees];\n };\n\n projection.rotate = function(_) {\n return arguments.length ? (deltaLambda = _[0] % 360 * radians, deltaPhi = _[1] % 360 * radians, deltaGamma = _.length > 2 ? _[2] % 360 * radians : 0, recenter()) : [deltaLambda * degrees, deltaPhi * degrees, deltaGamma * degrees];\n };\n\n projection.angle = function(_) {\n return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees;\n };\n\n projection.reflectX = function(_) {\n return arguments.length ? (sx = _ ? -1 : 1, recenter()) : sx < 0;\n };\n\n projection.reflectY = function(_) {\n return arguments.length ? (sy = _ ? -1 : 1, recenter()) : sy < 0;\n };\n\n projection.precision = function(_) {\n return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);\n };\n\n projection.fitExtent = function(extent, object) {\n return fitExtent(projection, extent, object);\n };\n\n projection.fitSize = function(size, object) {\n return fitSize(projection, size, object);\n };\n\n projection.fitWidth = function(width, object) {\n return fitWidth(projection, width, object);\n };\n\n projection.fitHeight = function(height, object) {\n return fitHeight(projection, height, object);\n };\n\n function recenter() {\n var center = scaleTranslateRotate(k, 0, 0, sx, sy, alpha).apply(null, project(lambda, phi)),\n transform = (alpha ? scaleTranslateRotate : scaleTranslate)(k, x - center[0], y - center[1], sx, sy, alpha);\n rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);\n projectTransform = compose(project, transform);\n projectRotateTransform = compose(rotate, projectTransform);\n projectResample = resample(projectTransform, delta2);\n return reset();\n }\n\n function reset() {\n cache = cacheStream = null;\n return projection;\n }\n\n return function() {\n project = projectAt.apply(this, arguments);\n projection.invert = project.invert && invert;\n return recenter();\n };\n}\n","import {atan, exp, halfPi, log, pi, tan, tau} from \"../math.js\";\nimport rotation from \"../rotation.js\";\nimport projection from \"./index.js\";\n\nexport function mercatorRaw(lambda, phi) {\n return [lambda, log(tan((halfPi + phi) / 2))];\n}\n\nmercatorRaw.invert = function(x, y) {\n return [x, 2 * atan(exp(y)) - halfPi];\n};\n\nexport default function() {\n return mercatorProjection(mercatorRaw)\n .scale(961 / tau);\n}\n\nexport function mercatorProjection(project) {\n var m = projection(project),\n center = m.center,\n scale = m.scale,\n translate = m.translate,\n clipExtent = m.clipExtent,\n x0 = null, y0, x1, y1; // clip extent\n\n m.scale = function(_) {\n return arguments.length ? (scale(_), reclip()) : scale();\n };\n\n m.translate = function(_) {\n return arguments.length ? (translate(_), reclip()) : translate();\n };\n\n m.center = function(_) {\n return arguments.length ? (center(_), reclip()) : center();\n };\n\n m.clipExtent = function(_) {\n return arguments.length ? ((_ == null ? x0 = y0 = x1 = y1 = null : (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1])), reclip()) : x0 == null ? null : [[x0, y0], [x1, y1]];\n };\n\n function reclip() {\n var k = pi * scale(),\n t = m(rotation(m.rotate()).invert([0, 0]));\n return clipExtent(x0 == null\n ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw\n ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]\n : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);\n }\n\n return reclip();\n}\n","import clipRectangle from \"../clip/rectangle.js\";\nimport identity from \"../identity.js\";\nimport {transformer} from \"../transform.js\";\nimport {fitExtent, fitSize, fitWidth, fitHeight} from \"./fit.js\";\nimport {cos, degrees, radians, sin} from \"../math.js\";\n\nexport default function() {\n var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, // scale, translate and reflect\n alpha = 0, ca, sa, // angle\n x0 = null, y0, x1, y1, // clip extent\n kx = 1, ky = 1,\n transform = transformer({\n point: function(x, y) {\n var p = projection([x, y])\n this.stream.point(p[0], p[1]);\n }\n }),\n postclip = identity,\n cache,\n cacheStream;\n\n function reset() {\n kx = k * sx;\n ky = k * sy;\n cache = cacheStream = null;\n return projection;\n }\n\n function projection (p) {\n var x = p[0] * kx, y = p[1] * ky;\n if (alpha) {\n var t = y * ca - x * sa;\n x = x * ca + y * sa;\n y = t;\n } \n return [x + tx, y + ty];\n }\n projection.invert = function(p) {\n var x = p[0] - tx, y = p[1] - ty;\n if (alpha) {\n var t = y * ca + x * sa;\n x = x * ca - y * sa;\n y = t;\n }\n return [x / kx, y / ky];\n };\n projection.stream = function(stream) {\n return cache && cacheStream === stream ? cache : cache = transform(postclip(cacheStream = stream));\n };\n projection.postclip = function(_) {\n return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;\n };\n projection.clipExtent = function(_) {\n return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];\n };\n projection.scale = function(_) {\n return arguments.length ? (k = +_, reset()) : k;\n };\n projection.translate = function(_) {\n return arguments.length ? (tx = +_[0], ty = +_[1], reset()) : [tx, ty];\n }\n projection.angle = function(_) {\n return arguments.length ? (alpha = _ % 360 * radians, sa = sin(alpha), ca = cos(alpha), reset()) : alpha * degrees;\n };\n projection.reflectX = function(_) {\n return arguments.length ? (sx = _ ? -1 : 1, reset()) : sx < 0;\n };\n projection.reflectY = function(_) {\n return arguments.length ? (sy = _ ? -1 : 1, reset()) : sy < 0;\n };\n projection.fitExtent = function(extent, object) {\n return fitExtent(projection, extent, object);\n };\n projection.fitSize = function(size, object) {\n return fitSize(projection, size, object);\n };\n projection.fitWidth = function(width, object) {\n return fitWidth(projection, width, object);\n };\n projection.fitHeight = function(height, object) {\n return fitHeight(projection, height, object);\n };\n\n return projection;\n}\n","// constants\nvar TAU = 2 * Math.PI;\nvar EQUATORIAL_RADIUS = 6356752.314245179;\nvar POLAR_RADIUS = 6378137.0;\n\n\nexport function geoLatToMeters(dLat) {\n return dLat * (TAU * POLAR_RADIUS / 360);\n}\n\n\nexport function geoLonToMeters(dLon, atLat) {\n return Math.abs(atLat) >= 90 ? 0 :\n dLon * (TAU * EQUATORIAL_RADIUS / 360) * Math.abs(Math.cos(atLat * (Math.PI / 180)));\n}\n\n\nexport function geoMetersToLat(m) {\n return m / (TAU * POLAR_RADIUS / 360);\n}\n\n\nexport function geoMetersToLon(m, atLat) {\n return Math.abs(atLat) >= 90 ? 0 :\n m / (TAU * EQUATORIAL_RADIUS / 360) / Math.abs(Math.cos(atLat * (Math.PI / 180)));\n}\n\n\nexport function geoMetersToOffset(meters, tileSize) {\n tileSize = tileSize || 256;\n return [\n meters[0] * tileSize / (TAU * EQUATORIAL_RADIUS),\n -meters[1] * tileSize / (TAU * POLAR_RADIUS)\n ];\n}\n\n\nexport function geoOffsetToMeters(offset, tileSize) {\n tileSize = tileSize || 256;\n return [\n offset[0] * TAU * EQUATORIAL_RADIUS / tileSize,\n -offset[1] * TAU * POLAR_RADIUS / tileSize\n ];\n}\n\n\n// Equirectangular approximation of spherical distances on Earth\nexport function geoSphericalDistance(a, b) {\n var x = geoLonToMeters(a[0] - b[0], (a[1] + b[1]) / 2);\n var y = geoLatToMeters(a[1] - b[1]);\n return Math.sqrt((x * x) + (y * y));\n}\n\n\n// scale to zoom\nexport function geoScaleToZoom(k, tileSize) {\n tileSize = tileSize || 256;\n var log2ts = Math.log(tileSize) * Math.LOG2E;\n return Math.log(k * TAU) / Math.LN2 - log2ts;\n}\n\n\n// zoom to scale\nexport function geoZoomToScale(z, tileSize) {\n tileSize = tileSize || 256;\n return tileSize * Math.pow(2, z) / TAU;\n}\n\n\n// returns info about the node from `nodes` closest to the given `point`\nexport function geoSphericalClosestNode(nodes, point) {\n var minDistance = Infinity, distance;\n var indexOfMin;\n\n for (var i in nodes) {\n distance = geoSphericalDistance(nodes[i].loc, point);\n if (distance < minDistance) {\n minDistance = distance;\n indexOfMin = i;\n }\n }\n\n if (indexOfMin !== undefined) {\n return { index: indexOfMin, distance: minDistance, node: nodes[indexOfMin] };\n } else {\n return null;\n }\n}\n","import { geoMetersToLat, geoMetersToLon } from './geo';\n\n\nexport function geoExtent(min, max) {\n if (!(this instanceof geoExtent)) {\n return new geoExtent(min, max);\n } else if (min instanceof geoExtent) {\n return min;\n } else if (min && min.length === 2 && min[0].length === 2 && min[1].length === 2) {\n this[0] = min[0];\n this[1] = min[1];\n } else {\n this[0] = min || [ Infinity, Infinity];\n this[1] = max || min || [-Infinity, -Infinity];\n }\n}\n\n\nexport function geoExtentFromBounds(mapBounds) {\n return geoExtent([\n [mapBounds.minlon, mapBounds.minlat],\n [mapBounds.maxlon, mapBounds.maxlat]\n ]);\n}\n\n\ngeoExtent.prototype = new Array(2);\n\nObject.assign(geoExtent.prototype, {\n\n equals: function (obj) {\n return this[0][0] === obj[0][0] &&\n this[0][1] === obj[0][1] &&\n this[1][0] === obj[1][0] &&\n this[1][1] === obj[1][1];\n },\n\n\n extend: function(obj) {\n if (!(obj instanceof geoExtent)) obj = new geoExtent(obj);\n return geoExtent(\n [Math.min(obj[0][0], this[0][0]), Math.min(obj[0][1], this[0][1])],\n [Math.max(obj[1][0], this[1][0]), Math.max(obj[1][1], this[1][1])]\n );\n },\n\n\n _extend: function(extent) {\n this[0][0] = Math.min(extent[0][0], this[0][0]);\n this[0][1] = Math.min(extent[0][1], this[0][1]);\n this[1][0] = Math.max(extent[1][0], this[1][0]);\n this[1][1] = Math.max(extent[1][1], this[1][1]);\n },\n\n\n area: function() {\n return Math.abs((this[1][0] - this[0][0]) * (this[1][1] - this[0][1]));\n },\n\n\n center: function() {\n return [(this[0][0] + this[1][0]) / 2, (this[0][1] + this[1][1]) / 2];\n },\n\n\n rectangle: function() {\n return [this[0][0], this[0][1], this[1][0], this[1][1]];\n },\n\n\n bbox: function() {\n return { minX: this[0][0], minY: this[0][1], maxX: this[1][0], maxY: this[1][1] };\n },\n\n\n polygon: function() {\n return [\n [this[0][0], this[0][1]],\n [this[0][0], this[1][1]],\n [this[1][0], this[1][1]],\n [this[1][0], this[0][1]],\n [this[0][0], this[0][1]]\n ];\n },\n\n\n contains: function(obj) {\n if (!(obj instanceof geoExtent)) obj = new geoExtent(obj);\n return obj[0][0] >= this[0][0] &&\n obj[0][1] >= this[0][1] &&\n obj[1][0] <= this[1][0] &&\n obj[1][1] <= this[1][1];\n },\n\n\n intersects: function(obj) {\n if (!(obj instanceof geoExtent)) obj = new geoExtent(obj);\n return obj[0][0] <= this[1][0] &&\n obj[0][1] <= this[1][1] &&\n obj[1][0] >= this[0][0] &&\n obj[1][1] >= this[0][1];\n },\n\n\n intersection: function(obj) {\n if (!this.intersects(obj)) return new geoExtent();\n return new geoExtent(\n [Math.max(obj[0][0], this[0][0]), Math.max(obj[0][1], this[0][1])],\n [Math.min(obj[1][0], this[1][0]), Math.min(obj[1][1], this[1][1])]\n );\n },\n\n\n percentContainedIn: function(obj) {\n if (!(obj instanceof geoExtent)) obj = new geoExtent(obj);\n var a1 = this.intersection(obj).area();\n var a2 = this.area();\n\n if (a1 === Infinity || a2 === Infinity) {\n return 0;\n } else if (a1 === 0 || a2 === 0) {\n if (obj.contains(this)) {\n return 1;\n }\n return 0;\n } else {\n return a1 / a2;\n }\n },\n\n\n padByMeters: function(meters) {\n var dLat = geoMetersToLat(meters);\n var dLon = geoMetersToLon(meters, this.center()[1]);\n return geoExtent(\n [this[0][0] - dLon, this[0][1] - dLat],\n [this[1][0] + dLon, this[1][1] + dLat]\n );\n },\n\n\n toParam: function() {\n return this.rectangle().join(',');\n }\n\n});\n","export default function(polygon) {\n var i = -1,\n n = polygon.length,\n a,\n b = polygon[n - 1],\n area = 0;\n\n while (++i < n) {\n a = b;\n b = polygon[i];\n area += a[1] * b[0] - a[0] * b[1];\n }\n\n return area / 2;\n}\n","export default function(polygon) {\n var i = -1,\n n = polygon.length,\n x = 0,\n y = 0,\n a,\n b = polygon[n - 1],\n c,\n k = 0;\n\n while (++i < n) {\n a = b;\n b = polygon[i];\n k += c = a[0] * b[1] - b[0] * a[1];\n x += (a[0] + b[0]) * c;\n y += (a[1] + b[1]) * c;\n }\n\n return k *= 3, [x / k, y / k];\n}\n","// Returns the 2D cross product of AB and AC vectors, i.e., the z-component of\n// the 3D cross product in a quadrant I Cartesian coordinate system (+x is\n// right, +y is up). Returns a positive value if ABC is counter-clockwise,\n// negative if clockwise, and zero if the points are collinear.\nexport default function(a, b, c) {\n return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);\n}\n","import cross from \"./cross.js\";\n\nfunction lexicographicOrder(a, b) {\n return a[0] - b[0] || a[1] - b[1];\n}\n\n// Computes the upper convex hull per the monotone chain algorithm.\n// Assumes points.length >= 3, is sorted by x, unique in y.\n// Returns an array of indices into points in left-to-right order.\nfunction computeUpperHullIndexes(points) {\n var n = points.length,\n indexes = [0, 1],\n size = 2;\n\n for (var i = 2; i < n; ++i) {\n while (size > 1 && cross(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;\n indexes[size++] = i;\n }\n\n return indexes.slice(0, size); // remove popped points\n}\n\nexport default function(points) {\n if ((n = points.length) < 3) return null;\n\n var i,\n n,\n sortedPoints = new Array(n),\n flippedPoints = new Array(n);\n\n for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];\n sortedPoints.sort(lexicographicOrder);\n for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];\n\n var upperIndexes = computeUpperHullIndexes(sortedPoints),\n lowerIndexes = computeUpperHullIndexes(flippedPoints);\n\n // Construct the hull polygon, removing possible duplicate endpoints.\n var skipLeft = lowerIndexes[0] === upperIndexes[0],\n skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],\n hull = [];\n\n // Add upper hull in right-to-l order.\n // Then add lower hull in left-to-right order.\n for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);\n for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);\n\n return hull;\n}\n","// vector equals\nexport function geoVecEqual(a, b, epsilon) {\n if (epsilon) {\n return (Math.abs(a[0] - b[0]) <= epsilon) && (Math.abs(a[1] - b[1]) <= epsilon);\n } else {\n return (a[0] === b[0]) && (a[1] === b[1]);\n }\n}\n\n// vector addition\nexport function geoVecAdd(a, b) {\n return [ a[0] + b[0], a[1] + b[1] ];\n}\n\n// vector subtraction\nexport function geoVecSubtract(a, b) {\n return [ a[0] - b[0], a[1] - b[1] ];\n}\n\n// vector scaling\nexport function geoVecScale(a, mag) {\n return [ a[0] * mag, a[1] * mag ];\n}\n\n// vector rounding (was: geoRoundCoordinates)\nexport function geoVecFloor(a) {\n return [ Math.floor(a[0]), Math.floor(a[1]) ];\n}\n\n// linear interpolation\nexport function geoVecInterp(a, b, t) {\n return [\n a[0] + (b[0] - a[0]) * t,\n a[1] + (b[1] - a[1]) * t\n ];\n}\n\n// http://jsperf.com/id-dist-optimization\nexport function geoVecLength(a, b) {\n return Math.sqrt(geoVecLengthSquare(a,b));\n}\n\n// length of vector raised to the power two\nexport function geoVecLengthSquare(a, b) {\n b = b || [0, 0];\n var x = a[0] - b[0];\n var y = a[1] - b[1];\n return (x * x) + (y * y);\n}\n\n// get a unit vector\nexport function geoVecNormalize(a) {\n var length = Math.sqrt((a[0] * a[0]) + (a[1] * a[1]));\n if (length !== 0) {\n return geoVecScale(a, 1 / length);\n }\n return [0, 0];\n}\n\n// Return the counterclockwise angle in the range (-pi, pi)\n// between the positive X axis and the line intersecting a and b.\nexport function geoVecAngle(a, b) {\n return Math.atan2(b[1] - a[1], b[0] - a[0]);\n}\n\n// dot product\nexport function geoVecDot(a, b, origin) {\n origin = origin || [0, 0];\n var p = geoVecSubtract(a, origin);\n var q = geoVecSubtract(b, origin);\n return (p[0]) * (q[0]) + (p[1]) * (q[1]);\n}\n\n// normalized dot product\nexport function geoVecNormalizedDot(a, b, origin) {\n origin = origin || [0, 0];\n var p = geoVecNormalize(geoVecSubtract(a, origin));\n var q = geoVecNormalize(geoVecSubtract(b, origin));\n return geoVecDot(p, q);\n}\n\n// 2D cross product of OA and OB vectors, returns magnitude of Z vector\n// Returns a positive value, if OAB makes a counter-clockwise turn,\n// negative for clockwise turn, and zero if the points are collinear.\nexport function geoVecCross(a, b, origin) {\n origin = origin || [0, 0];\n var p = geoVecSubtract(a, origin);\n var q = geoVecSubtract(b, origin);\n return (p[0]) * (q[1]) - (p[1]) * (q[0]);\n}\n\n\n// find closest orthogonal projection of point onto points array\nexport function geoVecProject(a, points) {\n var min = Infinity;\n var idx;\n var target;\n\n for (var i = 0; i < points.length - 1; i++) {\n var o = points[i];\n var s = geoVecSubtract(points[i + 1], o);\n var v = geoVecSubtract(a, o);\n var proj = geoVecDot(v, s) / geoVecDot(s, s);\n var p;\n\n if (proj < 0) {\n p = o;\n } else if (proj > 1) {\n p = points[i + 1];\n } else {\n p = [o[0] + proj * s[0], o[1] + proj * s[1]];\n }\n\n var dist = geoVecLength(p, a);\n if (dist < min) {\n min = dist;\n idx = i + 1;\n target = p;\n }\n }\n\n if (idx !== undefined) {\n return { index: idx, distance: min, target: target };\n } else {\n return null;\n }\n}\n\n","import {\n polygonHull as d3_polygonHull,\n polygonCentroid as d3_polygonCentroid\n} from 'd3-polygon';\n\nimport { geoExtent } from './extent.js';\n\nimport {\n geoVecAngle, geoVecCross, geoVecDot, geoVecEqual,\n geoVecInterp, geoVecLength, geoVecSubtract\n} from './vector.js';\n\n\n// Return the counterclockwise angle in the range (-pi, pi)\n// between the positive X axis and the line intersecting a and b.\nexport function geoAngle(a, b, projection) {\n return geoVecAngle(projection(a.loc), projection(b.loc));\n}\n\n\nexport function geoEdgeEqual(a, b) {\n return (a[0] === b[0] && a[1] === b[1]) ||\n (a[0] === b[1] && a[1] === b[0]);\n}\n\n\n// Rotate all points counterclockwise around a pivot point by given angle\nexport function geoRotate(points, angle, around) {\n return points.map(function(point) {\n var radial = geoVecSubtract(point, around);\n return [\n radial[0] * Math.cos(angle) - radial[1] * Math.sin(angle) + around[0],\n radial[0] * Math.sin(angle) + radial[1] * Math.cos(angle) + around[1]\n ];\n });\n}\n\n\n// Choose the edge with the minimal distance from `point` to its orthogonal\n// projection onto that edge, if such a projection exists, or the distance to\n// the closest vertex on that edge. Returns an object with the `index` of the\n// chosen edge, the chosen `loc` on that edge, and the `distance` to to it.\nexport function geoChooseEdge(nodes, point, projection, activeID) {\n var dist = geoVecLength;\n var points = nodes.map(function(n) { return projection(n.loc); });\n var ids = nodes.map(function(n) { return n.id; });\n var min = Infinity;\n var idx;\n var loc;\n\n for (var i = 0; i < points.length - 1; i++) {\n if (ids[i] === activeID || ids[i + 1] === activeID) continue;\n\n var o = points[i];\n var s = geoVecSubtract(points[i + 1], o);\n var v = geoVecSubtract(point, o);\n var proj = geoVecDot(v, s) / geoVecDot(s, s);\n var p;\n\n if (proj < 0) {\n p = o;\n } else if (proj > 1) {\n p = points[i + 1];\n } else {\n p = [o[0] + proj * s[0], o[1] + proj * s[1]];\n }\n\n var d = dist(p, point);\n if (d < min) {\n min = d;\n idx = i + 1;\n loc = projection.invert(p);\n }\n }\n\n if (idx !== undefined) {\n return { index: idx, distance: min, loc: loc };\n } else {\n return null;\n }\n}\n\n\n// Test active (dragged or drawing) segments against inactive segments\n// This is used to test e.g. multipolygon rings that cross\n// `activeNodes` is the ring containing the activeID being dragged.\n// `inactiveNodes` is the other ring to test against\nexport function geoHasLineIntersections(activeNodes, inactiveNodes, activeID) {\n var actives = [];\n var inactives = [];\n var j, k, n1, n2, segment;\n\n // gather active segments (only segments in activeNodes that contain the activeID)\n for (j = 0; j < activeNodes.length - 1; j++) {\n n1 = activeNodes[j];\n n2 = activeNodes[j+1];\n segment = [n1.loc, n2.loc];\n if (n1.id === activeID || n2.id === activeID) {\n actives.push(segment);\n }\n }\n\n // gather inactive segments\n for (j = 0; j < inactiveNodes.length - 1; j++) {\n n1 = inactiveNodes[j];\n n2 = inactiveNodes[j+1];\n segment = [n1.loc, n2.loc];\n inactives.push(segment);\n }\n\n // test\n for (j = 0; j < actives.length; j++) {\n for (k = 0; k < inactives.length; k++) {\n var p = actives[j];\n var q = inactives[k];\n var hit = geoLineIntersection(p, q);\n if (hit) {\n return true;\n }\n }\n }\n\n return false;\n}\n\n\n// Test active (dragged or drawing) segments against inactive segments\n// This is used to test whether a way intersects with itself.\nexport function geoHasSelfIntersections(nodes, activeID) {\n var actives = [];\n var inactives = [];\n var j, k;\n\n // group active and passive segments along the nodes\n for (j = 0; j < nodes.length - 1; j++) {\n var n1 = nodes[j];\n var n2 = nodes[j+1];\n var segment = [n1.loc, n2.loc];\n if (n1.id === activeID || n2.id === activeID) {\n actives.push(segment);\n } else {\n inactives.push(segment);\n }\n }\n\n // test\n for (j = 0; j < actives.length; j++) {\n for (k = 0; k < inactives.length; k++) {\n var p = actives[j];\n var q = inactives[k];\n // skip if segments share an endpoint\n if (geoVecEqual(p[1], q[0]) || geoVecEqual(p[0], q[1]) ||\n geoVecEqual(p[0], q[0]) || geoVecEqual(p[1], q[1]) ) {\n continue;\n }\n\n var hit = geoLineIntersection(p, q);\n if (hit) {\n var epsilon = 1e-8;\n // skip if the hit is at the segment's endpoint\n if (geoVecEqual(p[1], hit, epsilon) || geoVecEqual(p[0], hit, epsilon) ||\n geoVecEqual(q[1], hit, epsilon) || geoVecEqual(q[0], hit, epsilon) ) {\n continue;\n } else {\n return true;\n }\n }\n }\n }\n\n return false;\n}\n\n\n// Return the intersection point of 2 line segments.\n// From https://github.com/pgkelley4/line-segments-intersect\n// This uses the vector cross product approach described below:\n// http://stackoverflow.com/a/565282/786339\nexport function geoLineIntersection(a, b) {\n var p = [a[0][0], a[0][1]];\n var p2 = [a[1][0], a[1][1]];\n var q = [b[0][0], b[0][1]];\n var q2 = [b[1][0], b[1][1]];\n var r = geoVecSubtract(p2, p);\n var s = geoVecSubtract(q2, q);\n var uNumerator = geoVecCross(geoVecSubtract(q, p), r);\n var denominator = geoVecCross(r, s);\n\n if (uNumerator && denominator) {\n var u = uNumerator / denominator;\n var t = geoVecCross(geoVecSubtract(q, p), s) / denominator;\n\n if ((t >= 0) && (t <= 1) && (u >= 0) && (u <= 1)) {\n return geoVecInterp(p, p2, t);\n }\n }\n\n return null;\n}\n\n\nexport function geoPathIntersections(path1, path2) {\n var intersections = [];\n for (var i = 0; i < path1.length - 1; i++) {\n for (var j = 0; j < path2.length - 1; j++) {\n var a = [ path1[i], path1[i+1] ];\n var b = [ path2[j], path2[j+1] ];\n var hit = geoLineIntersection(a, b);\n if (hit) {\n intersections.push(hit);\n }\n }\n }\n return intersections;\n}\n\nexport function geoPathHasIntersections(path1, path2) {\n for (var i = 0; i < path1.length - 1; i++) {\n for (var j = 0; j < path2.length - 1; j++) {\n var a = [ path1[i], path1[i+1] ];\n var b = [ path2[j], path2[j+1] ];\n var hit = geoLineIntersection(a, b);\n if (hit) {\n return true;\n }\n }\n }\n return false;\n}\n\n\n// Return whether point is contained in polygon.\n//\n// `point` should be a 2-item array of coordinates.\n// `polygon` should be an array of 2-item arrays of coordinates.\n//\n// From https://github.com/substack/point-in-polygon.\n// ray-casting algorithm based on\n// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html\n//\nexport function geoPointInPolygon(point, polygon) {\n var x = point[0];\n var y = point[1];\n var inside = false;\n\n for (var i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {\n var xi = polygon[i][0];\n var yi = polygon[i][1];\n var xj = polygon[j][0];\n var yj = polygon[j][1];\n\n var intersect = ((yi > y) !== (yj > y)) &&\n (x < (xj - xi) * (y - yi) / (yj - yi) + xi);\n if (intersect) inside = !inside;\n }\n\n return inside;\n}\n\n\nexport function geoPolygonContainsPolygon(outer, inner) {\n return inner.every(function(point) {\n return geoPointInPolygon(point, outer);\n });\n}\n\n\nexport function geoPolygonIntersectsPolygon(outer, inner, checkSegments) {\n function testPoints(outer, inner) {\n return inner.some(function(point) {\n return geoPointInPolygon(point, outer);\n });\n }\n\n return testPoints(outer, inner) || (!!checkSegments && geoPathHasIntersections(outer, inner));\n}\n\n\n// http://gis.stackexchange.com/questions/22895/finding-minimum-area-rectangle-for-given-points\n// http://gis.stackexchange.com/questions/3739/generalisation-strategies-for-building-outlines/3756#3756\nexport function geoGetSmallestSurroundingRectangle(points) {\n var hull = d3_polygonHull(points);\n var centroid = d3_polygonCentroid(hull);\n var minArea = Infinity;\n var ssrExtent = [];\n var ssrAngle = 0;\n var c1 = hull[0];\n\n for (var i = 0; i <= hull.length - 1; i++) {\n var c2 = (i === hull.length - 1) ? hull[0] : hull[i + 1];\n var angle = Math.atan2(c2[1] - c1[1], c2[0] - c1[0]);\n var poly = geoRotate(hull, -angle, centroid);\n var extent = poly.reduce(function(extent, point) {\n return extent.extend(geoExtent(point));\n }, geoExtent());\n\n var area = extent.area();\n if (area < minArea) {\n minArea = area;\n ssrExtent = extent;\n ssrAngle = angle;\n }\n c1 = c2;\n }\n\n return {\n poly: geoRotate(ssrExtent.polygon(), ssrAngle, centroid),\n angle: ssrAngle\n };\n}\n\n\nexport function geoPathLength(path) {\n var length = 0;\n for (var i = 0; i < path.length - 1; i++) {\n length += geoVecLength(path[i], path[i + 1]);\n }\n return length;\n}\n\n\n// If the given point is at the edge of the padded viewport,\n// return a vector that will nudge the viewport in that direction\nexport function geoViewportEdge(point, dimensions) {\n var pad = [80, 20, 50, 20]; // top, right, bottom, left\n var x = 0;\n var y = 0;\n\n if (point[0] > dimensions[0] - pad[1])\n x = -10;\n if (point[0] < pad[3])\n x = 10;\n if (point[1] > dimensions[1] - pad[2])\n y = -10;\n if (point[1] < pad[0])\n y = 10;\n\n if (x || y) {\n return [x, y];\n } else {\n return null;\n }\n}\n","var noop = {value: function() {}};\n\nfunction dispatch() {\n for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {\n if (!(t = arguments[i] + \"\") || (t in _) || /[\\s.]/.test(t)) throw new Error(\"illegal type: \" + t);\n _[t] = [];\n }\n return new Dispatch(_);\n}\n\nfunction Dispatch(_) {\n this._ = _;\n}\n\nfunction parseTypenames(typenames, types) {\n return typenames.trim().split(/^|\\s+/).map(function(t) {\n var name = \"\", i = t.indexOf(\".\");\n if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);\n if (t && !types.hasOwnProperty(t)) throw new Error(\"unknown type: \" + t);\n return {type: t, name: name};\n });\n}\n\nDispatch.prototype = dispatch.prototype = {\n constructor: Dispatch,\n on: function(typename, callback) {\n var _ = this._,\n T = parseTypenames(typename + \"\", _),\n t,\n i = -1,\n n = T.length;\n\n // If no callback was specified, return the callback of the given type and name.\n if (arguments.length < 2) {\n while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;\n return;\n }\n\n // If a type was specified, set the callback for the given type and name.\n // Otherwise, if a null callback was specified, remove callbacks of the given name.\n if (callback != null && typeof callback !== \"function\") throw new Error(\"invalid callback: \" + callback);\n while (++i < n) {\n if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);\n else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);\n }\n\n return this;\n },\n copy: function() {\n var copy = {}, _ = this._;\n for (var t in _) copy[t] = _[t].slice();\n return new Dispatch(copy);\n },\n call: function(type, that) {\n if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];\n if (!this._.hasOwnProperty(type)) throw new Error(\"unknown type: \" + type);\n for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);\n },\n apply: function(type, that, args) {\n if (!this._.hasOwnProperty(type)) throw new Error(\"unknown type: \" + type);\n for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);\n }\n};\n\nfunction get(type, name) {\n for (var i = 0, n = type.length, c; i < n; ++i) {\n if ((c = type[i]).name === name) {\n return c.value;\n }\n }\n}\n\nfunction set(type, name, callback) {\n for (var i = 0, n = type.length; i < n; ++i) {\n if (type[i].name === name) {\n type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));\n break;\n }\n }\n if (callback != null) type.push({name: name, value: callback});\n return type;\n}\n\nexport default dispatch;\n","export var xhtml = \"http://www.w3.org/1999/xhtml\";\n\nexport default {\n svg: \"http://www.w3.org/2000/svg\",\n xhtml: xhtml,\n xlink: \"http://www.w3.org/1999/xlink\",\n xml: \"http://www.w3.org/XML/1998/namespace\",\n xmlns: \"http://www.w3.org/2000/xmlns/\"\n};\n","import namespaces from \"./namespaces\";\n\nexport default function(name) {\n var prefix = name += \"\", i = prefix.indexOf(\":\");\n if (i >= 0 && (prefix = name.slice(0, i)) !== \"xmlns\") name = name.slice(i + 1);\n return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;\n}\n","import namespace from \"./namespace\";\nimport {xhtml} from \"./namespaces\";\n\nfunction creatorInherit(name) {\n return function() {\n var document = this.ownerDocument,\n uri = this.namespaceURI;\n return uri === xhtml && document.documentElement.namespaceURI === xhtml\n ? document.createElement(name)\n : document.createElementNS(uri, name);\n };\n}\n\nfunction creatorFixed(fullname) {\n return function() {\n return this.ownerDocument.createElementNS(fullname.space, fullname.local);\n };\n}\n\nexport default function(name) {\n var fullname = namespace(name);\n return (fullname.local\n ? creatorFixed\n : creatorInherit)(fullname);\n}\n","function none() {}\n\nexport default function(selector) {\n return selector == null ? none : function() {\n return this.querySelector(selector);\n };\n}\n","import {Selection} from \"./index\";\nimport selector from \"../selector\";\n\nexport default function(select) {\n if (typeof select !== \"function\") select = selector(select);\n\n for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {\n for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {\n if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {\n if (\"__data__\" in node) subnode.__data__ = node.__data__;\n subgroup[i] = subnode;\n }\n }\n }\n\n return new Selection(subgroups, this._parents);\n}\n","function empty() {\n return [];\n}\n\nexport default function(selector) {\n return selector == null ? empty : function() {\n return this.querySelectorAll(selector);\n };\n}\n","import {Selection} from \"./index\";\nimport selectorAll from \"../selectorAll\";\n\nexport default function(select) {\n if (typeof select !== \"function\") select = selectorAll(select);\n\n for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {\n for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {\n if (node = group[i]) {\n subgroups.push(select.call(node, node.__data__, i, group));\n parents.push(node);\n }\n }\n }\n\n return new Selection(subgroups, parents);\n}\n","export default function(selector) {\n return function() {\n return this.matches(selector);\n };\n}\n","import {Selection} from \"./index\";\nimport matcher from \"../matcher\";\n\nexport default function(match) {\n if (typeof match !== \"function\") match = matcher(match);\n\n for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {\n for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {\n if ((node = group[i]) && match.call(node, node.__data__, i, group)) {\n subgroup.push(node);\n }\n }\n }\n\n return new Selection(subgroups, this._parents);\n}\n","export default function(update) {\n return new Array(update.length);\n}\n","import sparse from \"./sparse\";\nimport {Selection} from \"./index\";\n\nexport default function() {\n return new Selection(this._enter || this._groups.map(sparse), this._parents);\n}\n\nexport function EnterNode(parent, datum) {\n this.ownerDocument = parent.ownerDocument;\n this.namespaceURI = parent.namespaceURI;\n this._next = null;\n this._parent = parent;\n this.__data__ = datum;\n}\n\nEnterNode.prototype = {\n constructor: EnterNode,\n appendChild: function(child) { return this._parent.insertBefore(child, this._next); },\n insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },\n querySelector: function(selector) { return this._parent.querySelector(selector); },\n querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }\n};\n","export default function(x) {\n return function() {\n return x;\n };\n}\n","import {Selection} from \"./index\";\nimport {EnterNode} from \"./enter\";\nimport constant from \"../constant\";\n\nvar keyPrefix = \"$\"; // Protect against keys like “__proto__”.\n\nfunction bindIndex(parent, group, enter, update, exit, data) {\n var i = 0,\n node,\n groupLength = group.length,\n dataLength = data.length;\n\n // Put any non-null nodes that fit into update.\n // Put any null nodes into enter.\n // Put any remaining data into enter.\n for (; i < dataLength; ++i) {\n if (node = group[i]) {\n node.__data__ = data[i];\n update[i] = node;\n } else {\n enter[i] = new EnterNode(parent, data[i]);\n }\n }\n\n // Put any non-null nodes that don’t fit into exit.\n for (; i < groupLength; ++i) {\n if (node = group[i]) {\n exit[i] = node;\n }\n }\n}\n\nfunction bindKey(parent, group, enter, update, exit, data, key) {\n var i,\n node,\n nodeByKeyValue = {},\n groupLength = group.length,\n dataLength = data.length,\n keyValues = new Array(groupLength),\n keyValue;\n\n // Compute the key for each node.\n // If multiple nodes have the same key, the duplicates are added to exit.\n for (i = 0; i < groupLength; ++i) {\n if (node = group[i]) {\n keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);\n if (keyValue in nodeByKeyValue) {\n exit[i] = node;\n } else {\n nodeByKeyValue[keyValue] = node;\n }\n }\n }\n\n // Compute the key for each datum.\n // If there a node associated with this key, join and add it to update.\n // If there is not (or the key is a duplicate), add it to enter.\n for (i = 0; i < dataLength; ++i) {\n keyValue = keyPrefix + key.call(parent, data[i], i, data);\n if (node = nodeByKeyValue[keyValue]) {\n update[i] = node;\n node.__data__ = data[i];\n nodeByKeyValue[keyValue] = null;\n } else {\n enter[i] = new EnterNode(parent, data[i]);\n }\n }\n\n // Add any remaining nodes that were not bound to data to exit.\n for (i = 0; i < groupLength; ++i) {\n if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {\n exit[i] = node;\n }\n }\n}\n\nexport default function(value, key) {\n if (!value) {\n data = new Array(this.size()), j = -1;\n this.each(function(d) { data[++j] = d; });\n return data;\n }\n\n var bind = key ? bindKey : bindIndex,\n parents = this._parents,\n groups = this._groups;\n\n if (typeof value !== \"function\") value = constant(value);\n\n for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {\n var parent = parents[j],\n group = groups[j],\n groupLength = group.length,\n data = value.call(parent, parent && parent.__data__, j, parents),\n dataLength = data.length,\n enterGroup = enter[j] = new Array(dataLength),\n updateGroup = update[j] = new Array(dataLength),\n exitGroup = exit[j] = new Array(groupLength);\n\n bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);\n\n // Now connect the enter nodes to their following update node, such that\n // appendChild can insert the materialized enter node before this node,\n // rather than at the end of the parent node.\n for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {\n if (previous = enterGroup[i0]) {\n if (i0 >= i1) i1 = i0 + 1;\n while (!(next = updateGroup[i1]) && ++i1 < dataLength);\n previous._next = next || null;\n }\n }\n }\n\n update = new Selection(update, parents);\n update._enter = enter;\n update._exit = exit;\n return update;\n}\n","import sparse from \"./sparse\";\nimport {Selection} from \"./index\";\n\nexport default function() {\n return new Selection(this._exit || this._groups.map(sparse), this._parents);\n}\n","export default function(onenter, onupdate, onexit) {\n var enter = this.enter(), update = this, exit = this.exit();\n enter = typeof onenter === \"function\" ? onenter(enter) : enter.append(onenter + \"\");\n if (onupdate != null) update = onupdate(update);\n if (onexit == null) exit.remove(); else onexit(exit);\n return enter && update ? enter.merge(update).order() : update;\n}\n","import {Selection} from \"./index\";\n\nexport default function(selection) {\n\n for (var groups0 = this._groups, groups1 = selection._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {\n for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {\n if (node = group0[i] || group1[i]) {\n merge[i] = node;\n }\n }\n }\n\n for (; j < m0; ++j) {\n merges[j] = groups0[j];\n }\n\n return new Selection(merges, this._parents);\n}\n","export default function() {\n\n for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {\n for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {\n if (node = group[i]) {\n if (next && node.compareDocumentPosition(next) ^ 4) next.parentNode.insertBefore(node, next);\n next = node;\n }\n }\n }\n\n return this;\n}\n","import {Selection} from \"./index\";\n\nexport default function(compare) {\n if (!compare) compare = ascending;\n\n function compareNode(a, b) {\n return a && b ? compare(a.__data__, b.__data__) : !a - !b;\n }\n\n for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {\n for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {\n if (node = group[i]) {\n sortgroup[i] = node;\n }\n }\n sortgroup.sort(compareNode);\n }\n\n return new Selection(sortgroups, this._parents).order();\n}\n\nfunction ascending(a, b) {\n return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;\n}\n","export default function() {\n var callback = arguments[0];\n arguments[0] = this;\n callback.apply(null, arguments);\n return this;\n}\n","export default function() {\n var nodes = new Array(this.size()), i = -1;\n this.each(function() { nodes[++i] = this; });\n return nodes;\n}\n","export default function() {\n\n for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {\n for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {\n var node = group[i];\n if (node) return node;\n }\n }\n\n return null;\n}\n","export default function() {\n var size = 0;\n this.each(function() { ++size; });\n return size;\n}\n","export default function() {\n return !this.node();\n}\n","export default function(callback) {\n\n for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {\n for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {\n if (node = group[i]) callback.call(node, node.__data__, i, group);\n }\n }\n\n return this;\n}\n","import namespace from \"../namespace\";\n\nfunction attrRemove(name) {\n return function() {\n this.removeAttribute(name);\n };\n}\n\nfunction attrRemoveNS(fullname) {\n return function() {\n this.removeAttributeNS(fullname.space, fullname.local);\n };\n}\n\nfunction attrConstant(name, value) {\n return function() {\n this.setAttribute(name, value);\n };\n}\n\nfunction attrConstantNS(fullname, value) {\n return function() {\n this.setAttributeNS(fullname.space, fullname.local, value);\n };\n}\n\nfunction attrFunction(name, value) {\n return function() {\n var v = value.apply(this, arguments);\n if (v == null) this.removeAttribute(name);\n else this.setAttribute(name, v);\n };\n}\n\nfunction attrFunctionNS(fullname, value) {\n return function() {\n var v = value.apply(this, arguments);\n if (v == null) this.removeAttributeNS(fullname.space, fullname.local);\n else this.setAttributeNS(fullname.space, fullname.local, v);\n };\n}\n\nexport default function(name, value) {\n var fullname = namespace(name);\n\n if (arguments.length < 2) {\n var node = this.node();\n return fullname.local\n ? node.getAttributeNS(fullname.space, fullname.local)\n : node.getAttribute(fullname);\n }\n\n return this.each((value == null\n ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === \"function\"\n ? (fullname.local ? attrFunctionNS : attrFunction)\n : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));\n}\n","export default function(node) {\n return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node\n || (node.document && node) // node is a Window\n || node.defaultView; // node is a Document\n}\n","import defaultView from \"../window\";\n\nfunction styleRemove(name) {\n return function() {\n this.style.removeProperty(name);\n };\n}\n\nfunction styleConstant(name, value, priority) {\n return function() {\n this.style.setProperty(name, value, priority);\n };\n}\n\nfunction styleFunction(name, value, priority) {\n return function() {\n var v = value.apply(this, arguments);\n if (v == null) this.style.removeProperty(name);\n else this.style.setProperty(name, v, priority);\n };\n}\n\nexport default function(name, value, priority) {\n return arguments.length > 1\n ? this.each((value == null\n ? styleRemove : typeof value === \"function\"\n ? styleFunction\n : styleConstant)(name, value, priority == null ? \"\" : priority))\n : styleValue(this.node(), name);\n}\n\nexport function styleValue(node, name) {\n return node.style.getPropertyValue(name)\n || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);\n}\n","function propertyRemove(name) {\n return function() {\n delete this[name];\n };\n}\n\nfunction propertyConstant(name, value) {\n return function() {\n this[name] = value;\n };\n}\n\nfunction propertyFunction(name, value) {\n return function() {\n var v = value.apply(this, arguments);\n if (v == null) delete this[name];\n else this[name] = v;\n };\n}\n\nexport default function(name, value) {\n return arguments.length > 1\n ? this.each((value == null\n ? propertyRemove : typeof value === \"function\"\n ? propertyFunction\n : propertyConstant)(name, value))\n : this.node()[name];\n}\n","function classArray(string) {\n return string.trim().split(/^|\\s+/);\n}\n\nfunction classList(node) {\n return node.classList || new ClassList(node);\n}\n\nfunction ClassList(node) {\n this._node = node;\n this._names = classArray(node.getAttribute(\"class\") || \"\");\n}\n\nClassList.prototype = {\n add: function(name) {\n var i = this._names.indexOf(name);\n if (i < 0) {\n this._names.push(name);\n this._node.setAttribute(\"class\", this._names.join(\" \"));\n }\n },\n remove: function(name) {\n var i = this._names.indexOf(name);\n if (i >= 0) {\n this._names.splice(i, 1);\n this._node.setAttribute(\"class\", this._names.join(\" \"));\n }\n },\n contains: function(name) {\n return this._names.indexOf(name) >= 0;\n }\n};\n\nfunction classedAdd(node, names) {\n var list = classList(node), i = -1, n = names.length;\n while (++i < n) list.add(names[i]);\n}\n\nfunction classedRemove(node, names) {\n var list = classList(node), i = -1, n = names.length;\n while (++i < n) list.remove(names[i]);\n}\n\nfunction classedTrue(names) {\n return function() {\n classedAdd(this, names);\n };\n}\n\nfunction classedFalse(names) {\n return function() {\n classedRemove(this, names);\n };\n}\n\nfunction classedFunction(names, value) {\n return function() {\n (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);\n };\n}\n\nexport default function(name, value) {\n var names = classArray(name + \"\");\n\n if (arguments.length < 2) {\n var list = classList(this.node()), i = -1, n = names.length;\n while (++i < n) if (!list.contains(names[i])) return false;\n return true;\n }\n\n return this.each((typeof value === \"function\"\n ? classedFunction : value\n ? classedTrue\n : classedFalse)(names, value));\n}\n","function textRemove() {\n this.textContent = \"\";\n}\n\nfunction textConstant(value) {\n return function() {\n this.textContent = value;\n };\n}\n\nfunction textFunction(value) {\n return function() {\n var v = value.apply(this, arguments);\n this.textContent = v == null ? \"\" : v;\n };\n}\n\nexport default function(value) {\n return arguments.length\n ? this.each(value == null\n ? textRemove : (typeof value === \"function\"\n ? textFunction\n : textConstant)(value))\n : this.node().textContent;\n}\n","function htmlRemove() {\n this.innerHTML = \"\";\n}\n\nfunction htmlConstant(value) {\n return function() {\n this.innerHTML = value;\n };\n}\n\nfunction htmlFunction(value) {\n return function() {\n var v = value.apply(this, arguments);\n this.innerHTML = v == null ? \"\" : v;\n };\n}\n\nexport default function(value) {\n return arguments.length\n ? this.each(value == null\n ? htmlRemove : (typeof value === \"function\"\n ? htmlFunction\n : htmlConstant)(value))\n : this.node().innerHTML;\n}\n","function raise() {\n if (this.nextSibling) this.parentNode.appendChild(this);\n}\n\nexport default function() {\n return this.each(raise);\n}\n","function lower() {\n if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);\n}\n\nexport default function() {\n return this.each(lower);\n}\n","import creator from \"../creator\";\n\nexport default function(name) {\n var create = typeof name === \"function\" ? name : creator(name);\n return this.select(function() {\n return this.appendChild(create.apply(this, arguments));\n });\n}\n","import creator from \"../creator\";\nimport selector from \"../selector\";\n\nfunction constantNull() {\n return null;\n}\n\nexport default function(name, before) {\n var create = typeof name === \"function\" ? name : creator(name),\n select = before == null ? constantNull : typeof before === \"function\" ? before : selector(before);\n return this.select(function() {\n return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);\n });\n}\n","function remove() {\n var parent = this.parentNode;\n if (parent) parent.removeChild(this);\n}\n\nexport default function() {\n return this.each(remove);\n}\n","function selection_cloneShallow() {\n var clone = this.cloneNode(false), parent = this.parentNode;\n return parent ? parent.insertBefore(clone, this.nextSibling) : clone;\n}\n\nfunction selection_cloneDeep() {\n var clone = this.cloneNode(true), parent = this.parentNode;\n return parent ? parent.insertBefore(clone, this.nextSibling) : clone;\n}\n\nexport default function(deep) {\n return this.select(deep ? selection_cloneDeep : selection_cloneShallow);\n}\n","export default function(value) {\n return arguments.length\n ? this.property(\"__data__\", value)\n : this.node().__data__;\n}\n","var filterEvents = {};\n\nexport var event = null;\n\nif (typeof document !== \"undefined\") {\n var element = document.documentElement;\n if (!(\"onmouseenter\" in element)) {\n filterEvents = {mouseenter: \"mouseover\", mouseleave: \"mouseout\"};\n }\n}\n\nfunction filterContextListener(listener, index, group) {\n listener = contextListener(listener, index, group);\n return function(event) {\n var related = event.relatedTarget;\n if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {\n listener.call(this, event);\n }\n };\n}\n\nfunction contextListener(listener, index, group) {\n return function(event1) {\n var event0 = event; // Events can be reentrant (e.g., focus).\n event = event1;\n try {\n listener.call(this, this.__data__, index, group);\n } finally {\n event = event0;\n }\n };\n}\n\nfunction parseTypenames(typenames) {\n return typenames.trim().split(/^|\\s+/).map(function(t) {\n var name = \"\", i = t.indexOf(\".\");\n if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);\n return {type: t, name: name};\n });\n}\n\nfunction onRemove(typename) {\n return function() {\n var on = this.__on;\n if (!on) return;\n for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {\n if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {\n this.removeEventListener(o.type, o.listener, o.capture);\n } else {\n on[++i] = o;\n }\n }\n if (++i) on.length = i;\n else delete this.__on;\n };\n}\n\nfunction onAdd(typename, value, capture) {\n var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;\n return function(d, i, group) {\n var on = this.__on, o, listener = wrap(value, i, group);\n if (on) for (var j = 0, m = on.length; j < m; ++j) {\n if ((o = on[j]).type === typename.type && o.name === typename.name) {\n this.removeEventListener(o.type, o.listener, o.capture);\n this.addEventListener(o.type, o.listener = listener, o.capture = capture);\n o.value = value;\n return;\n }\n }\n this.addEventListener(typename.type, listener, capture);\n o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};\n if (!on) this.__on = [o];\n else on.push(o);\n };\n}\n\nexport default function(typename, value, capture) {\n var typenames = parseTypenames(typename + \"\"), i, n = typenames.length, t;\n\n if (arguments.length < 2) {\n var on = this.node().__on;\n if (on) for (var j = 0, m = on.length, o; j < m; ++j) {\n for (i = 0, o = on[j]; i < n; ++i) {\n if ((t = typenames[i]).type === o.type && t.name === o.name) {\n return o.value;\n }\n }\n }\n return;\n }\n\n on = value ? onAdd : onRemove;\n if (capture == null) capture = false;\n for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));\n return this;\n}\n\nexport function customEvent(event1, listener, that, args) {\n var event0 = event;\n event1.sourceEvent = event;\n event = event1;\n try {\n return listener.apply(that, args);\n } finally {\n event = event0;\n }\n}\n","import defaultView from \"../window\";\n\nfunction dispatchEvent(node, type, params) {\n var window = defaultView(node),\n event = window.CustomEvent;\n\n if (typeof event === \"function\") {\n event = new event(type, params);\n } else {\n event = window.document.createEvent(\"Event\");\n if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;\n else event.initEvent(type, false, false);\n }\n\n node.dispatchEvent(event);\n}\n\nfunction dispatchConstant(type, params) {\n return function() {\n return dispatchEvent(this, type, params);\n };\n}\n\nfunction dispatchFunction(type, params) {\n return function() {\n return dispatchEvent(this, type, params.apply(this, arguments));\n };\n}\n\nexport default function(type, params) {\n return this.each((typeof params === \"function\"\n ? dispatchFunction\n : dispatchConstant)(type, params));\n}\n","import selection_select from \"./select\";\nimport selection_selectAll from \"./selectAll\";\nimport selection_filter from \"./filter\";\nimport selection_data from \"./data\";\nimport selection_enter from \"./enter\";\nimport selection_exit from \"./exit\";\nimport selection_join from \"./join\";\nimport selection_merge from \"./merge\";\nimport selection_order from \"./order\";\nimport selection_sort from \"./sort\";\nimport selection_call from \"./call\";\nimport selection_nodes from \"./nodes\";\nimport selection_node from \"./node\";\nimport selection_size from \"./size\";\nimport selection_empty from \"./empty\";\nimport selection_each from \"./each\";\nimport selection_attr from \"./attr\";\nimport selection_style from \"./style\";\nimport selection_property from \"./property\";\nimport selection_classed from \"./classed\";\nimport selection_text from \"./text\";\nimport selection_html from \"./html\";\nimport selection_raise from \"./raise\";\nimport selection_lower from \"./lower\";\nimport selection_append from \"./append\";\nimport selection_insert from \"./insert\";\nimport selection_remove from \"./remove\";\nimport selection_clone from \"./clone\";\nimport selection_datum from \"./datum\";\nimport selection_on from \"./on\";\nimport selection_dispatch from \"./dispatch\";\n\nexport var root = [null];\n\nexport function Selection(groups, parents) {\n this._groups = groups;\n this._parents = parents;\n}\n\nfunction selection() {\n return new Selection([[document.documentElement]], root);\n}\n\nSelection.prototype = selection.prototype = {\n constructor: Selection,\n select: selection_select,\n selectAll: selection_selectAll,\n filter: selection_filter,\n data: selection_data,\n enter: selection_enter,\n exit: selection_exit,\n join: selection_join,\n merge: selection_merge,\n order: selection_order,\n sort: selection_sort,\n call: selection_call,\n nodes: selection_nodes,\n node: selection_node,\n size: selection_size,\n empty: selection_empty,\n each: selection_each,\n attr: selection_attr,\n style: selection_style,\n property: selection_property,\n classed: selection_classed,\n text: selection_text,\n html: selection_html,\n raise: selection_raise,\n lower: selection_lower,\n append: selection_append,\n insert: selection_insert,\n remove: selection_remove,\n clone: selection_clone,\n datum: selection_datum,\n on: selection_on,\n dispatch: selection_dispatch\n};\n\nexport default selection;\n","import {Selection, root} from \"./selection/index\";\n\nexport default function(selector) {\n return typeof selector === \"string\"\n ? new Selection([[document.querySelector(selector)]], [document.documentElement])\n : new Selection([[selector]], root);\n}\n","import {event} from \"./selection/on\";\n\nexport default function() {\n var current = event, source;\n while (source = current.sourceEvent) current = source;\n return current;\n}\n","export default function(node, event) {\n var svg = node.ownerSVGElement || node;\n\n if (svg.createSVGPoint) {\n var point = svg.createSVGPoint();\n point.x = event.clientX, point.y = event.clientY;\n point = point.matrixTransform(node.getScreenCTM().inverse());\n return [point.x, point.y];\n }\n\n var rect = node.getBoundingClientRect();\n return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];\n}\n","import sourceEvent from \"./sourceEvent\";\nimport point from \"./point\";\n\nexport default function(node) {\n var event = sourceEvent();\n if (event.changedTouches) event = event.changedTouches[0];\n return point(node, event);\n}\n","import {Selection, root} from \"./selection/index\";\n\nexport default function(selector) {\n return typeof selector === \"string\"\n ? new Selection([document.querySelectorAll(selector)], [document.documentElement])\n : new Selection([selector == null ? [] : selector], root);\n}\n","import sourceEvent from \"./sourceEvent\";\nimport point from \"./point\";\n\nexport default function(node, touches, identifier) {\n if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;\n\n for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {\n if ((touch = touches[i]).identifier === identifier) {\n return point(node, touch);\n }\n }\n\n return null;\n}\n","import {event} from \"d3-selection\";\n\nexport function nopropagation() {\n event.stopImmediatePropagation();\n}\n\nexport default function() {\n event.preventDefault();\n event.stopImmediatePropagation();\n}\n","import {select} from \"d3-selection\";\nimport noevent from \"./noevent.js\";\n\nexport default function(view) {\n var root = view.document.documentElement,\n selection = select(view).on(\"dragstart.drag\", noevent, true);\n if (\"onselectstart\" in root) {\n selection.on(\"selectstart.drag\", noevent, true);\n } else {\n root.__noselect = root.style.MozUserSelect;\n root.style.MozUserSelect = \"none\";\n }\n}\n\nexport function yesdrag(view, noclick) {\n var root = view.document.documentElement,\n selection = select(view).on(\"dragstart.drag\", null);\n if (noclick) {\n selection.on(\"click.drag\", noevent, true);\n setTimeout(function() { selection.on(\"click.drag\", null); }, 0);\n }\n if (\"onselectstart\" in root) {\n selection.on(\"selectstart.drag\", null);\n } else {\n root.style.MozUserSelect = root.__noselect;\n delete root.__noselect;\n }\n}\n","export default function(x) {\n return function() {\n return x;\n };\n}\n","export default function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {\n this.target = target;\n this.type = type;\n this.subject = subject;\n this.identifier = id;\n this.active = active;\n this.x = x;\n this.y = y;\n this.dx = dx;\n this.dy = dy;\n this._ = dispatch;\n}\n\nDragEvent.prototype.on = function() {\n var value = this._.on.apply(this._, arguments);\n return value === this._ ? this : value;\n};\n","import {dispatch} from \"d3-dispatch\";\nimport {event, customEvent, select, mouse, touch} from \"d3-selection\";\nimport nodrag, {yesdrag} from \"./nodrag.js\";\nimport noevent, {nopropagation} from \"./noevent.js\";\nimport constant from \"./constant.js\";\nimport DragEvent from \"./event.js\";\n\n// Ignore right-click, since that should open the context menu.\nfunction defaultFilter() {\n return !event.ctrlKey && !event.button;\n}\n\nfunction defaultContainer() {\n return this.parentNode;\n}\n\nfunction defaultSubject(d) {\n return d == null ? {x: event.x, y: event.y} : d;\n}\n\nfunction defaultTouchable() {\n return navigator.maxTouchPoints || (\"ontouchstart\" in this);\n}\n\nexport default function() {\n var filter = defaultFilter,\n container = defaultContainer,\n subject = defaultSubject,\n touchable = defaultTouchable,\n gestures = {},\n listeners = dispatch(\"start\", \"drag\", \"end\"),\n active = 0,\n mousedownx,\n mousedowny,\n mousemoving,\n touchending,\n clickDistance2 = 0;\n\n function drag(selection) {\n selection\n .on(\"mousedown.drag\", mousedowned)\n .filter(touchable)\n .on(\"touchstart.drag\", touchstarted)\n .on(\"touchmove.drag\", touchmoved)\n .on(\"touchend.drag touchcancel.drag\", touchended)\n .style(\"touch-action\", \"none\")\n .style(\"-webkit-tap-highlight-color\", \"rgba(0,0,0,0)\");\n }\n\n function mousedowned() {\n if (touchending || !filter.apply(this, arguments)) return;\n var gesture = beforestart(\"mouse\", container.apply(this, arguments), mouse, this, arguments);\n if (!gesture) return;\n select(event.view).on(\"mousemove.drag\", mousemoved, true).on(\"mouseup.drag\", mouseupped, true);\n nodrag(event.view);\n nopropagation();\n mousemoving = false;\n mousedownx = event.clientX;\n mousedowny = event.clientY;\n gesture(\"start\");\n }\n\n function mousemoved() {\n noevent();\n if (!mousemoving) {\n var dx = event.clientX - mousedownx, dy = event.clientY - mousedowny;\n mousemoving = dx * dx + dy * dy > clickDistance2;\n }\n gestures.mouse(\"drag\");\n }\n\n function mouseupped() {\n select(event.view).on(\"mousemove.drag mouseup.drag\", null);\n yesdrag(event.view, mousemoving);\n noevent();\n gestures.mouse(\"end\");\n }\n\n function touchstarted() {\n if (!filter.apply(this, arguments)) return;\n var touches = event.changedTouches,\n c = container.apply(this, arguments),\n n = touches.length, i, gesture;\n\n for (i = 0; i < n; ++i) {\n if (gesture = beforestart(touches[i].identifier, c, touch, this, arguments)) {\n nopropagation();\n gesture(\"start\");\n }\n }\n }\n\n function touchmoved() {\n var touches = event.changedTouches,\n n = touches.length, i, gesture;\n\n for (i = 0; i < n; ++i) {\n if (gesture = gestures[touches[i].identifier]) {\n noevent();\n gesture(\"drag\");\n }\n }\n }\n\n function touchended() {\n var touches = event.changedTouches,\n n = touches.length, i, gesture;\n\n if (touchending) clearTimeout(touchending);\n touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!\n for (i = 0; i < n; ++i) {\n if (gesture = gestures[touches[i].identifier]) {\n nopropagation();\n gesture(\"end\");\n }\n }\n }\n\n function beforestart(id, container, point, that, args) {\n var p = point(container, id), s, dx, dy,\n sublisteners = listeners.copy();\n\n if (!customEvent(new DragEvent(drag, \"beforestart\", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {\n if ((event.subject = s = subject.apply(that, args)) == null) return false;\n dx = s.x - p[0] || 0;\n dy = s.y - p[1] || 0;\n return true;\n })) return;\n\n return function gesture(type) {\n var p0 = p, n;\n switch (type) {\n case \"start\": gestures[id] = gesture, n = active++; break;\n case \"end\": delete gestures[id], --active; // nobreak\n case \"drag\": p = point(container, id), n = active; break;\n }\n customEvent(new DragEvent(drag, type, s, id, n, p[0] + dx, p[1] + dy, p[0] - p0[0], p[1] - p0[1], sublisteners), sublisteners.apply, sublisteners, [type, that, args]);\n };\n }\n\n drag.filter = function(_) {\n return arguments.length ? (filter = typeof _ === \"function\" ? _ : constant(!!_), drag) : filter;\n };\n\n drag.container = function(_) {\n return arguments.length ? (container = typeof _ === \"function\" ? _ : constant(_), drag) : container;\n };\n\n drag.subject = function(_) {\n return arguments.length ? (subject = typeof _ === \"function\" ? _ : constant(_), drag) : subject;\n };\n\n drag.touchable = function(_) {\n return arguments.length ? (touchable = typeof _ === \"function\" ? _ : constant(!!_), drag) : touchable;\n };\n\n drag.on = function() {\n var value = listeners.on.apply(listeners, arguments);\n return value === listeners ? drag : value;\n };\n\n drag.clickDistance = function(_) {\n return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);\n };\n\n return drag;\n}\n","export default function(constructor, factory, prototype) {\n constructor.prototype = factory.prototype = prototype;\n prototype.constructor = constructor;\n}\n\nexport function extend(parent, definition) {\n var prototype = Object.create(parent.prototype);\n for (var key in definition) prototype[key] = definition[key];\n return prototype;\n}\n","import define, {extend} from \"./define.js\";\n\nexport function Color() {}\n\nexport var darker = 0.7;\nexport var brighter = 1 / darker;\n\nvar reI = \"\\\\s*([+-]?\\\\d+)\\\\s*\",\n reN = \"\\\\s*([+-]?\\\\d*\\\\.?\\\\d+(?:[eE][+-]?\\\\d+)?)\\\\s*\",\n reP = \"\\\\s*([+-]?\\\\d*\\\\.?\\\\d+(?:[eE][+-]?\\\\d+)?)%\\\\s*\",\n reHex = /^#([0-9a-f]{3,8})$/,\n reRgbInteger = new RegExp(\"^rgb\\\\(\" + [reI, reI, reI] + \"\\\\)$\"),\n reRgbPercent = new RegExp(\"^rgb\\\\(\" + [reP, reP, reP] + \"\\\\)$\"),\n reRgbaInteger = new RegExp(\"^rgba\\\\(\" + [reI, reI, reI, reN] + \"\\\\)$\"),\n reRgbaPercent = new RegExp(\"^rgba\\\\(\" + [reP, reP, reP, reN] + \"\\\\)$\"),\n reHslPercent = new RegExp(\"^hsl\\\\(\" + [reN, reP, reP] + \"\\\\)$\"),\n reHslaPercent = new RegExp(\"^hsla\\\\(\" + [reN, reP, reP, reN] + \"\\\\)$\");\n\nvar named = {\n aliceblue: 0xf0f8ff,\n antiquewhite: 0xfaebd7,\n aqua: 0x00ffff,\n aquamarine: 0x7fffd4,\n azure: 0xf0ffff,\n beige: 0xf5f5dc,\n bisque: 0xffe4c4,\n black: 0x000000,\n blanchedalmond: 0xffebcd,\n blue: 0x0000ff,\n blueviolet: 0x8a2be2,\n brown: 0xa52a2a,\n burlywood: 0xdeb887,\n cadetblue: 0x5f9ea0,\n chartreuse: 0x7fff00,\n chocolate: 0xd2691e,\n coral: 0xff7f50,\n cornflowerblue: 0x6495ed,\n cornsilk: 0xfff8dc,\n crimson: 0xdc143c,\n cyan: 0x00ffff,\n darkblue: 0x00008b,\n darkcyan: 0x008b8b,\n darkgoldenrod: 0xb8860b,\n darkgray: 0xa9a9a9,\n darkgreen: 0x006400,\n darkgrey: 0xa9a9a9,\n darkkhaki: 0xbdb76b,\n darkmagenta: 0x8b008b,\n darkolivegreen: 0x556b2f,\n darkorange: 0xff8c00,\n darkorchid: 0x9932cc,\n darkred: 0x8b0000,\n darksalmon: 0xe9967a,\n darkseagreen: 0x8fbc8f,\n darkslateblue: 0x483d8b,\n darkslategray: 0x2f4f4f,\n darkslategrey: 0x2f4f4f,\n darkturquoise: 0x00ced1,\n darkviolet: 0x9400d3,\n deeppink: 0xff1493,\n deepskyblue: 0x00bfff,\n dimgray: 0x696969,\n dimgrey: 0x696969,\n dodgerblue: 0x1e90ff,\n firebrick: 0xb22222,\n floralwhite: 0xfffaf0,\n forestgreen: 0x228b22,\n fuchsia: 0xff00ff,\n gainsboro: 0xdcdcdc,\n ghostwhite: 0xf8f8ff,\n gold: 0xffd700,\n goldenrod: 0xdaa520,\n gray: 0x808080,\n green: 0x008000,\n greenyellow: 0xadff2f,\n grey: 0x808080,\n honeydew: 0xf0fff0,\n hotpink: 0xff69b4,\n indianred: 0xcd5c5c,\n indigo: 0x4b0082,\n ivory: 0xfffff0,\n khaki: 0xf0e68c,\n lavender: 0xe6e6fa,\n lavenderblush: 0xfff0f5,\n lawngreen: 0x7cfc00,\n lemonchiffon: 0xfffacd,\n lightblue: 0xadd8e6,\n lightcoral: 0xf08080,\n lightcyan: 0xe0ffff,\n lightgoldenrodyellow: 0xfafad2,\n lightgray: 0xd3d3d3,\n lightgreen: 0x90ee90,\n lightgrey: 0xd3d3d3,\n lightpink: 0xffb6c1,\n lightsalmon: 0xffa07a,\n lightseagreen: 0x20b2aa,\n lightskyblue: 0x87cefa,\n lightslategray: 0x778899,\n lightslategrey: 0x778899,\n lightsteelblue: 0xb0c4de,\n lightyellow: 0xffffe0,\n lime: 0x00ff00,\n limegreen: 0x32cd32,\n linen: 0xfaf0e6,\n magenta: 0xff00ff,\n maroon: 0x800000,\n mediumaquamarine: 0x66cdaa,\n mediumblue: 0x0000cd,\n mediumorchid: 0xba55d3,\n mediumpurple: 0x9370db,\n mediumseagreen: 0x3cb371,\n mediumslateblue: 0x7b68ee,\n mediumspringgreen: 0x00fa9a,\n mediumturquoise: 0x48d1cc,\n mediumvioletred: 0xc71585,\n midnightblue: 0x191970,\n mintcream: 0xf5fffa,\n mistyrose: 0xffe4e1,\n moccasin: 0xffe4b5,\n navajowhite: 0xffdead,\n navy: 0x000080,\n oldlace: 0xfdf5e6,\n olive: 0x808000,\n olivedrab: 0x6b8e23,\n orange: 0xffa500,\n orangered: 0xff4500,\n orchid: 0xda70d6,\n palegoldenrod: 0xeee8aa,\n palegreen: 0x98fb98,\n paleturquoise: 0xafeeee,\n palevioletred: 0xdb7093,\n papayawhip: 0xffefd5,\n peachpuff: 0xffdab9,\n peru: 0xcd853f,\n pink: 0xffc0cb,\n plum: 0xdda0dd,\n powderblue: 0xb0e0e6,\n purple: 0x800080,\n rebeccapurple: 0x663399,\n red: 0xff0000,\n rosybrown: 0xbc8f8f,\n royalblue: 0x4169e1,\n saddlebrown: 0x8b4513,\n salmon: 0xfa8072,\n sandybrown: 0xf4a460,\n seagreen: 0x2e8b57,\n seashell: 0xfff5ee,\n sienna: 0xa0522d,\n silver: 0xc0c0c0,\n skyblue: 0x87ceeb,\n slateblue: 0x6a5acd,\n slategray: 0x708090,\n slategrey: 0x708090,\n snow: 0xfffafa,\n springgreen: 0x00ff7f,\n steelblue: 0x4682b4,\n tan: 0xd2b48c,\n teal: 0x008080,\n thistle: 0xd8bfd8,\n tomato: 0xff6347,\n turquoise: 0x40e0d0,\n violet: 0xee82ee,\n wheat: 0xf5deb3,\n white: 0xffffff,\n whitesmoke: 0xf5f5f5,\n yellow: 0xffff00,\n yellowgreen: 0x9acd32\n};\n\ndefine(Color, color, {\n copy: function(channels) {\n return Object.assign(new this.constructor, this, channels);\n },\n displayable: function() {\n return this.rgb().displayable();\n },\n hex: color_formatHex, // Deprecated! Use color.formatHex.\n formatHex: color_formatHex,\n formatHsl: color_formatHsl,\n formatRgb: color_formatRgb,\n toString: color_formatRgb\n});\n\nfunction color_formatHex() {\n return this.rgb().formatHex();\n}\n\nfunction color_formatHsl() {\n return hslConvert(this).formatHsl();\n}\n\nfunction color_formatRgb() {\n return this.rgb().formatRgb();\n}\n\nexport default function color(format) {\n var m, l;\n format = (format + \"\").trim().toLowerCase();\n return (m = reHex.exec(format)) ? (l = m[1].length, m = parseInt(m[1], 16), l === 6 ? rgbn(m) // #ff0000\n : l === 3 ? new Rgb((m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1) // #f00\n : l === 8 ? rgba(m >> 24 & 0xff, m >> 16 & 0xff, m >> 8 & 0xff, (m & 0xff) / 0xff) // #ff000000\n : l === 4 ? rgba((m >> 12 & 0xf) | (m >> 8 & 0xf0), (m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), (((m & 0xf) << 4) | (m & 0xf)) / 0xff) // #f000\n : null) // invalid hex\n : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)\n : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)\n : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)\n : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)\n : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)\n : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)\n : named.hasOwnProperty(format) ? rgbn(named[format]) // eslint-disable-line no-prototype-builtins\n : format === \"transparent\" ? new Rgb(NaN, NaN, NaN, 0)\n : null;\n}\n\nfunction rgbn(n) {\n return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);\n}\n\nfunction rgba(r, g, b, a) {\n if (a <= 0) r = g = b = NaN;\n return new Rgb(r, g, b, a);\n}\n\nexport function rgbConvert(o) {\n if (!(o instanceof Color)) o = color(o);\n if (!o) return new Rgb;\n o = o.rgb();\n return new Rgb(o.r, o.g, o.b, o.opacity);\n}\n\nexport function rgb(r, g, b, opacity) {\n return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);\n}\n\nexport function Rgb(r, g, b, opacity) {\n this.r = +r;\n this.g = +g;\n this.b = +b;\n this.opacity = +opacity;\n}\n\ndefine(Rgb, rgb, extend(Color, {\n brighter: function(k) {\n k = k == null ? brighter : Math.pow(brighter, k);\n return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);\n },\n darker: function(k) {\n k = k == null ? darker : Math.pow(darker, k);\n return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);\n },\n rgb: function() {\n return this;\n },\n displayable: function() {\n return (-0.5 <= this.r && this.r < 255.5)\n && (-0.5 <= this.g && this.g < 255.5)\n && (-0.5 <= this.b && this.b < 255.5)\n && (0 <= this.opacity && this.opacity <= 1);\n },\n hex: rgb_formatHex, // Deprecated! Use color.formatHex.\n formatHex: rgb_formatHex,\n formatRgb: rgb_formatRgb,\n toString: rgb_formatRgb\n}));\n\nfunction rgb_formatHex() {\n return \"#\" + hex(this.r) + hex(this.g) + hex(this.b);\n}\n\nfunction rgb_formatRgb() {\n var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));\n return (a === 1 ? \"rgb(\" : \"rgba(\")\n + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + \", \"\n + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + \", \"\n + Math.max(0, Math.min(255, Math.round(this.b) || 0))\n + (a === 1 ? \")\" : \", \" + a + \")\");\n}\n\nfunction hex(value) {\n value = Math.max(0, Math.min(255, Math.round(value) || 0));\n return (value < 16 ? \"0\" : \"\") + value.toString(16);\n}\n\nfunction hsla(h, s, l, a) {\n if (a <= 0) h = s = l = NaN;\n else if (l <= 0 || l >= 1) h = s = NaN;\n else if (s <= 0) h = NaN;\n return new Hsl(h, s, l, a);\n}\n\nexport function hslConvert(o) {\n if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);\n if (!(o instanceof Color)) o = color(o);\n if (!o) return new Hsl;\n if (o instanceof Hsl) return o;\n o = o.rgb();\n var r = o.r / 255,\n g = o.g / 255,\n b = o.b / 255,\n min = Math.min(r, g, b),\n max = Math.max(r, g, b),\n h = NaN,\n s = max - min,\n l = (max + min) / 2;\n if (s) {\n if (r === max) h = (g - b) / s + (g < b) * 6;\n else if (g === max) h = (b - r) / s + 2;\n else h = (r - g) / s + 4;\n s /= l < 0.5 ? max + min : 2 - max - min;\n h *= 60;\n } else {\n s = l > 0 && l < 1 ? 0 : h;\n }\n return new Hsl(h, s, l, o.opacity);\n}\n\nexport function hsl(h, s, l, opacity) {\n return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);\n}\n\nfunction Hsl(h, s, l, opacity) {\n this.h = +h;\n this.s = +s;\n this.l = +l;\n this.opacity = +opacity;\n}\n\ndefine(Hsl, hsl, extend(Color, {\n brighter: function(k) {\n k = k == null ? brighter : Math.pow(brighter, k);\n return new Hsl(this.h, this.s, this.l * k, this.opacity);\n },\n darker: function(k) {\n k = k == null ? darker : Math.pow(darker, k);\n return new Hsl(this.h, this.s, this.l * k, this.opacity);\n },\n rgb: function() {\n var h = this.h % 360 + (this.h < 0) * 360,\n s = isNaN(h) || isNaN(this.s) ? 0 : this.s,\n l = this.l,\n m2 = l + (l < 0.5 ? l : 1 - l) * s,\n m1 = 2 * l - m2;\n return new Rgb(\n hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),\n hsl2rgb(h, m1, m2),\n hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),\n this.opacity\n );\n },\n displayable: function() {\n return (0 <= this.s && this.s <= 1 || isNaN(this.s))\n && (0 <= this.l && this.l <= 1)\n && (0 <= this.opacity && this.opacity <= 1);\n },\n formatHsl: function() {\n var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));\n return (a === 1 ? \"hsl(\" : \"hsla(\")\n + (this.h || 0) + \", \"\n + (this.s || 0) * 100 + \"%, \"\n + (this.l || 0) * 100 + \"%\"\n + (a === 1 ? \")\" : \", \" + a + \")\");\n }\n}));\n\n/* From FvD 13.37, CSS Color Module Level 3 */\nfunction hsl2rgb(h, m1, m2) {\n return (h < 60 ? m1 + (m2 - m1) * h / 60\n : h < 180 ? m2\n : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60\n : m1) * 255;\n}\n","export default function(x) {\n return function() {\n return x;\n };\n}\n","import constant from \"./constant.js\";\n\nfunction linear(a, d) {\n return function(t) {\n return a + t * d;\n };\n}\n\nfunction exponential(a, b, y) {\n return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {\n return Math.pow(a + t * b, y);\n };\n}\n\nexport function hue(a, b) {\n var d = b - a;\n return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant(isNaN(a) ? b : a);\n}\n\nexport function gamma(y) {\n return (y = +y) === 1 ? nogamma : function(a, b) {\n return b - a ? exponential(a, b, y) : constant(isNaN(a) ? b : a);\n };\n}\n\nexport default function nogamma(a, b) {\n var d = b - a;\n return d ? linear(a, d) : constant(isNaN(a) ? b : a);\n}\n","import {rgb as colorRgb} from \"d3-color\";\nimport basis from \"./basis.js\";\nimport basisClosed from \"./basisClosed.js\";\nimport nogamma, {gamma} from \"./color.js\";\n\nexport default (function rgbGamma(y) {\n var color = gamma(y);\n\n function rgb(start, end) {\n var r = color((start = colorRgb(start)).r, (end = colorRgb(end)).r),\n g = color(start.g, end.g),\n b = color(start.b, end.b),\n opacity = nogamma(start.opacity, end.opacity);\n return function(t) {\n start.r = r(t);\n start.g = g(t);\n start.b = b(t);\n start.opacity = opacity(t);\n return start + \"\";\n };\n }\n\n rgb.gamma = rgbGamma;\n\n return rgb;\n})(1);\n\nfunction rgbSpline(spline) {\n return function(colors) {\n var n = colors.length,\n r = new Array(n),\n g = new Array(n),\n b = new Array(n),\n i, color;\n for (i = 0; i < n; ++i) {\n color = colorRgb(colors[i]);\n r[i] = color.r || 0;\n g[i] = color.g || 0;\n b[i] = color.b || 0;\n }\n r = spline(r);\n g = spline(g);\n b = spline(b);\n color.opacity = 1;\n return function(t) {\n color.r = r(t);\n color.g = g(t);\n color.b = b(t);\n return color + \"\";\n };\n };\n}\n\nexport var rgbBasis = rgbSpline(basis);\nexport var rgbBasisClosed = rgbSpline(basisClosed);\n","export default function(a, b) {\n if (!b) b = [];\n var n = a ? Math.min(b.length, a.length) : 0,\n c = b.slice(),\n i;\n return function(t) {\n for (i = 0; i < n; ++i) c[i] = a[i] * (1 - t) + b[i] * t;\n return c;\n };\n}\n\nexport function isNumberArray(x) {\n return ArrayBuffer.isView(x) && !(x instanceof DataView);\n}\n","import value from \"./value.js\";\nimport numberArray, {isNumberArray} from \"./numberArray.js\";\n\nexport default function(a, b) {\n return (isNumberArray(b) ? numberArray : genericArray)(a, b);\n}\n\nexport function genericArray(a, b) {\n var nb = b ? b.length : 0,\n na = a ? Math.min(nb, a.length) : 0,\n x = new Array(na),\n c = new Array(nb),\n i;\n\n for (i = 0; i < na; ++i) x[i] = value(a[i], b[i]);\n for (; i < nb; ++i) c[i] = b[i];\n\n return function(t) {\n for (i = 0; i < na; ++i) c[i] = x[i](t);\n return c;\n };\n}\n","export default function(a, b) {\n var d = new Date;\n return a = +a, b = +b, function(t) {\n return d.setTime(a * (1 - t) + b * t), d;\n };\n}\n","export default function(a, b) {\n return a = +a, b = +b, function(t) {\n return a * (1 - t) + b * t;\n };\n}\n","import value from \"./value.js\";\n\nexport default function(a, b) {\n var i = {},\n c = {},\n k;\n\n if (a === null || typeof a !== \"object\") a = {};\n if (b === null || typeof b !== \"object\") b = {};\n\n for (k in b) {\n if (k in a) {\n i[k] = value(a[k], b[k]);\n } else {\n c[k] = b[k];\n }\n }\n\n return function(t) {\n for (k in i) c[k] = i[k](t);\n return c;\n };\n}\n","import number from \"./number.js\";\n\nvar reA = /[-+]?(?:\\d+\\.?\\d*|\\.?\\d+)(?:[eE][-+]?\\d+)?/g,\n reB = new RegExp(reA.source, \"g\");\n\nfunction zero(b) {\n return function() {\n return b;\n };\n}\n\nfunction one(b) {\n return function(t) {\n return b(t) + \"\";\n };\n}\n\nexport default function(a, b) {\n var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b\n am, // current match in a\n bm, // current match in b\n bs, // string preceding current number in b, if any\n i = -1, // index in s\n s = [], // string constants and placeholders\n q = []; // number interpolators\n\n // Coerce inputs to strings.\n a = a + \"\", b = b + \"\";\n\n // Interpolate pairs of numbers in a & b.\n while ((am = reA.exec(a))\n && (bm = reB.exec(b))) {\n if ((bs = bm.index) > bi) { // a string precedes the next number in b\n bs = b.slice(bi, bs);\n if (s[i]) s[i] += bs; // coalesce with previous string\n else s[++i] = bs;\n }\n if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match\n if (s[i]) s[i] += bm; // coalesce with previous string\n else s[++i] = bm;\n } else { // interpolate non-matching numbers\n s[++i] = null;\n q.push({i: i, x: number(am, bm)});\n }\n bi = reB.lastIndex;\n }\n\n // Add remains of b.\n if (bi < b.length) {\n bs = b.slice(bi);\n if (s[i]) s[i] += bs; // coalesce with previous string\n else s[++i] = bs;\n }\n\n // Special optimization for only a single match.\n // Otherwise, interpolate each of the numbers and rejoin the string.\n return s.length < 2 ? (q[0]\n ? one(q[0].x)\n : zero(b))\n : (b = q.length, function(t) {\n for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);\n return s.join(\"\");\n });\n}\n","import {color} from \"d3-color\";\nimport rgb from \"./rgb.js\";\nimport {genericArray} from \"./array.js\";\nimport date from \"./date.js\";\nimport number from \"./number.js\";\nimport object from \"./object.js\";\nimport string from \"./string.js\";\nimport constant from \"./constant.js\";\nimport numberArray, {isNumberArray} from \"./numberArray.js\";\n\nexport default function(a, b) {\n var t = typeof b, c;\n return b == null || t === \"boolean\" ? constant(b)\n : (t === \"number\" ? number\n : t === \"string\" ? ((c = color(b)) ? (b = c, rgb) : string)\n : b instanceof color ? rgb\n : b instanceof Date ? date\n : isNumberArray(b) ? numberArray\n : Array.isArray(b) ? genericArray\n : typeof b.valueOf !== \"function\" && typeof b.toString !== \"function\" || isNaN(b) ? object\n : number)(a, b);\n}\n","export default function(a, b) {\n return a = +a, b = +b, function(t) {\n return Math.round(a * (1 - t) + b * t);\n };\n}\n","var degrees = 180 / Math.PI;\n\nexport var identity = {\n translateX: 0,\n translateY: 0,\n rotate: 0,\n skewX: 0,\n scaleX: 1,\n scaleY: 1\n};\n\nexport default function(a, b, c, d, e, f) {\n var scaleX, scaleY, skewX;\n if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;\n if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;\n if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;\n if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;\n return {\n translateX: e,\n translateY: f,\n rotate: Math.atan2(b, a) * degrees,\n skewX: Math.atan(skewX) * degrees,\n scaleX: scaleX,\n scaleY: scaleY\n };\n}\n","import decompose, {identity} from \"./decompose.js\";\n\nvar cssNode,\n cssRoot,\n cssView,\n svgNode;\n\nexport function parseCss(value) {\n if (value === \"none\") return identity;\n if (!cssNode) cssNode = document.createElement(\"DIV\"), cssRoot = document.documentElement, cssView = document.defaultView;\n cssNode.style.transform = value;\n value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue(\"transform\");\n cssRoot.removeChild(cssNode);\n value = value.slice(7, -1).split(\",\");\n return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);\n}\n\nexport function parseSvg(value) {\n if (value == null) return identity;\n if (!svgNode) svgNode = document.createElementNS(\"http://www.w3.org/2000/svg\", \"g\");\n svgNode.setAttribute(\"transform\", value);\n if (!(value = svgNode.transform.baseVal.consolidate())) return identity;\n value = value.matrix;\n return decompose(value.a, value.b, value.c, value.d, value.e, value.f);\n}\n","import number from \"../number.js\";\nimport {parseCss, parseSvg} from \"./parse.js\";\n\nfunction interpolateTransform(parse, pxComma, pxParen, degParen) {\n\n function pop(s) {\n return s.length ? s.pop() + \" \" : \"\";\n }\n\n function translate(xa, ya, xb, yb, s, q) {\n if (xa !== xb || ya !== yb) {\n var i = s.push(\"translate(\", null, pxComma, null, pxParen);\n q.push({i: i - 4, x: number(xa, xb)}, {i: i - 2, x: number(ya, yb)});\n } else if (xb || yb) {\n s.push(\"translate(\" + xb + pxComma + yb + pxParen);\n }\n }\n\n function rotate(a, b, s, q) {\n if (a !== b) {\n if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path\n q.push({i: s.push(pop(s) + \"rotate(\", null, degParen) - 2, x: number(a, b)});\n } else if (b) {\n s.push(pop(s) + \"rotate(\" + b + degParen);\n }\n }\n\n function skewX(a, b, s, q) {\n if (a !== b) {\n q.push({i: s.push(pop(s) + \"skewX(\", null, degParen) - 2, x: number(a, b)});\n } else if (b) {\n s.push(pop(s) + \"skewX(\" + b + degParen);\n }\n }\n\n function scale(xa, ya, xb, yb, s, q) {\n if (xa !== xb || ya !== yb) {\n var i = s.push(pop(s) + \"scale(\", null, \",\", null, \")\");\n q.push({i: i - 4, x: number(xa, xb)}, {i: i - 2, x: number(ya, yb)});\n } else if (xb !== 1 || yb !== 1) {\n s.push(pop(s) + \"scale(\" + xb + \",\" + yb + \")\");\n }\n }\n\n return function(a, b) {\n var s = [], // string constants and placeholders\n q = []; // number interpolators\n a = parse(a), b = parse(b);\n translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);\n rotate(a.rotate, b.rotate, s, q);\n skewX(a.skewX, b.skewX, s, q);\n scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);\n a = b = null; // gc\n return function(t) {\n var i = -1, n = q.length, o;\n while (++i < n) s[(o = q[i]).i] = o.x(t);\n return s.join(\"\");\n };\n };\n}\n\nexport var interpolateTransformCss = interpolateTransform(parseCss, \"px, \", \"px)\", \"deg)\");\nexport var interpolateTransformSvg = interpolateTransform(parseSvg, \", \", \")\", \")\");\n","var rho = Math.SQRT2,\n rho2 = 2,\n rho4 = 4,\n epsilon2 = 1e-12;\n\nfunction cosh(x) {\n return ((x = Math.exp(x)) + 1 / x) / 2;\n}\n\nfunction sinh(x) {\n return ((x = Math.exp(x)) - 1 / x) / 2;\n}\n\nfunction tanh(x) {\n return ((x = Math.exp(2 * x)) - 1) / (x + 1);\n}\n\n// p0 = [ux0, uy0, w0]\n// p1 = [ux1, uy1, w1]\nexport default function(p0, p1) {\n var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],\n ux1 = p1[0], uy1 = p1[1], w1 = p1[2],\n dx = ux1 - ux0,\n dy = uy1 - uy0,\n d2 = dx * dx + dy * dy,\n i,\n S;\n\n // Special case for u0 ≅ u1.\n if (d2 < epsilon2) {\n S = Math.log(w1 / w0) / rho;\n i = function(t) {\n return [\n ux0 + t * dx,\n uy0 + t * dy,\n w0 * Math.exp(rho * t * S)\n ];\n }\n }\n\n // General case.\n else {\n var d1 = Math.sqrt(d2),\n b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),\n b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),\n r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),\n r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);\n S = (r1 - r0) / rho;\n i = function(t) {\n var s = t * S,\n coshr0 = cosh(r0),\n u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));\n return [\n ux0 + u * dx,\n uy0 + u * dy,\n w0 * coshr0 / cosh(rho * s + r0)\n ];\n }\n }\n\n i.duration = S * 1000;\n\n return i;\n}\n","export default function(interpolator, n) {\n var samples = new Array(n);\n for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));\n return samples;\n}\n","var frame = 0, // is an animation frame pending?\n timeout = 0, // is a timeout pending?\n interval = 0, // are any timers active?\n pokeDelay = 1000, // how frequently we check for clock skew\n taskHead,\n taskTail,\n clockLast = 0,\n clockNow = 0,\n clockSkew = 0,\n clock = typeof performance === \"object\" && performance.now ? performance : Date,\n setFrame = typeof window === \"object\" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };\n\nexport function now() {\n return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);\n}\n\nfunction clearNow() {\n clockNow = 0;\n}\n\nexport function Timer() {\n this._call =\n this._time =\n this._next = null;\n}\n\nTimer.prototype = timer.prototype = {\n constructor: Timer,\n restart: function(callback, delay, time) {\n if (typeof callback !== \"function\") throw new TypeError(\"callback is not a function\");\n time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);\n if (!this._next && taskTail !== this) {\n if (taskTail) taskTail._next = this;\n else taskHead = this;\n taskTail = this;\n }\n this._call = callback;\n this._time = time;\n sleep();\n },\n stop: function() {\n if (this._call) {\n this._call = null;\n this._time = Infinity;\n sleep();\n }\n }\n};\n\nexport function timer(callback, delay, time) {\n var t = new Timer;\n t.restart(callback, delay, time);\n return t;\n}\n\nexport function timerFlush() {\n now(); // Get the current time, if not already set.\n ++frame; // Pretend we’ve set an alarm, if we haven’t already.\n var t = taskHead, e;\n while (t) {\n if ((e = clockNow - t._time) >= 0) t._call.call(null, e);\n t = t._next;\n }\n --frame;\n}\n\nfunction wake() {\n clockNow = (clockLast = clock.now()) + clockSkew;\n frame = timeout = 0;\n try {\n timerFlush();\n } finally {\n frame = 0;\n nap();\n clockNow = 0;\n }\n}\n\nfunction poke() {\n var now = clock.now(), delay = now - clockLast;\n if (delay > pokeDelay) clockSkew -= delay, clockLast = now;\n}\n\nfunction nap() {\n var t0, t1 = taskHead, t2, time = Infinity;\n while (t1) {\n if (t1._call) {\n if (time > t1._time) time = t1._time;\n t0 = t1, t1 = t1._next;\n } else {\n t2 = t1._next, t1._next = null;\n t1 = t0 ? t0._next = t2 : taskHead = t2;\n }\n }\n taskTail = t0;\n sleep(time);\n}\n\nfunction sleep(time) {\n if (frame) return; // Soonest alarm already set, or will be.\n if (timeout) timeout = clearTimeout(timeout);\n var delay = time - clockNow; // Strictly less than if we recomputed clockNow.\n if (delay > 24) {\n if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);\n if (interval) interval = clearInterval(interval);\n } else {\n if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);\n frame = 1, setFrame(wake);\n }\n}\n","import {Timer} from \"./timer.js\";\n\nexport default function(callback, delay, time) {\n var t = new Timer;\n delay = delay == null ? 0 : +delay;\n t.restart(function(elapsed) {\n t.stop();\n callback(elapsed + delay);\n }, delay, time);\n return t;\n}\n","import {dispatch} from \"d3-dispatch\";\nimport {timer, timeout} from \"d3-timer\";\n\nvar emptyOn = dispatch(\"start\", \"end\", \"cancel\", \"interrupt\");\nvar emptyTween = [];\n\nexport var CREATED = 0;\nexport var SCHEDULED = 1;\nexport var STARTING = 2;\nexport var STARTED = 3;\nexport var RUNNING = 4;\nexport var ENDING = 5;\nexport var ENDED = 6;\n\nexport default function(node, name, id, index, group, timing) {\n var schedules = node.__transition;\n if (!schedules) node.__transition = {};\n else if (id in schedules) return;\n create(node, id, {\n name: name,\n index: index, // For context during callback.\n group: group, // For context during callback.\n on: emptyOn,\n tween: emptyTween,\n time: timing.time,\n delay: timing.delay,\n duration: timing.duration,\n ease: timing.ease,\n timer: null,\n state: CREATED\n });\n}\n\nexport function init(node, id) {\n var schedule = get(node, id);\n if (schedule.state > CREATED) throw new Error(\"too late; already scheduled\");\n return schedule;\n}\n\nexport function set(node, id) {\n var schedule = get(node, id);\n if (schedule.state > STARTED) throw new Error(\"too late; already running\");\n return schedule;\n}\n\nexport function get(node, id) {\n var schedule = node.__transition;\n if (!schedule || !(schedule = schedule[id])) throw new Error(\"transition not found\");\n return schedule;\n}\n\nfunction create(node, id, self) {\n var schedules = node.__transition,\n tween;\n\n // Initialize the self timer when the transition is created.\n // Note the actual delay is not known until the first callback!\n schedules[id] = self;\n self.timer = timer(schedule, 0, self.time);\n\n function schedule(elapsed) {\n self.state = SCHEDULED;\n self.timer.restart(start, self.delay, self.time);\n\n // If the elapsed delay is less than our first sleep, start immediately.\n if (self.delay <= elapsed) start(elapsed - self.delay);\n }\n\n function start(elapsed) {\n var i, j, n, o;\n\n // If the state is not SCHEDULED, then we previously errored on start.\n if (self.state !== SCHEDULED) return stop();\n\n for (i in schedules) {\n o = schedules[i];\n if (o.name !== self.name) continue;\n\n // While this element already has a starting transition during this frame,\n // defer starting an interrupting transition until that transition has a\n // chance to tick (and possibly end); see d3/d3-transition#54!\n if (o.state === STARTED) return timeout(start);\n\n // Interrupt the active transition, if any.\n if (o.state === RUNNING) {\n o.state = ENDED;\n o.timer.stop();\n o.on.call(\"interrupt\", node, node.__data__, o.index, o.group);\n delete schedules[i];\n }\n\n // Cancel any pre-empted transitions.\n else if (+i < id) {\n o.state = ENDED;\n o.timer.stop();\n o.on.call(\"cancel\", node, node.__data__, o.index, o.group);\n delete schedules[i];\n }\n }\n\n // Defer the first tick to end of the current frame; see d3/d3#1576.\n // Note the transition may be canceled after start and before the first tick!\n // Note this must be scheduled before the start event; see d3/d3-transition#16!\n // Assuming this is successful, subsequent callbacks go straight to tick.\n timeout(function() {\n if (self.state === STARTED) {\n self.state = RUNNING;\n self.timer.restart(tick, self.delay, self.time);\n tick(elapsed);\n }\n });\n\n // Dispatch the start event.\n // Note this must be done before the tween are initialized.\n self.state = STARTING;\n self.on.call(\"start\", node, node.__data__, self.index, self.group);\n if (self.state !== STARTING) return; // interrupted\n self.state = STARTED;\n\n // Initialize the tween, deleting null tween.\n tween = new Array(n = self.tween.length);\n for (i = 0, j = -1; i < n; ++i) {\n if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {\n tween[++j] = o;\n }\n }\n tween.length = j + 1;\n }\n\n function tick(elapsed) {\n var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),\n i = -1,\n n = tween.length;\n\n while (++i < n) {\n tween[i].call(node, t);\n }\n\n // Dispatch the end event.\n if (self.state === ENDING) {\n self.on.call(\"end\", node, node.__data__, self.index, self.group);\n stop();\n }\n }\n\n function stop() {\n self.state = ENDED;\n self.timer.stop();\n delete schedules[id];\n for (var i in schedules) return; // eslint-disable-line no-unused-vars\n delete node.__transition;\n }\n}\n","import {STARTING, ENDING, ENDED} from \"./transition/schedule.js\";\n\nexport default function(node, name) {\n var schedules = node.__transition,\n schedule,\n active,\n empty = true,\n i;\n\n if (!schedules) return;\n\n name = name == null ? null : name + \"\";\n\n for (i in schedules) {\n if ((schedule = schedules[i]).name !== name) { empty = false; continue; }\n active = schedule.state > STARTING && schedule.state < ENDING;\n schedule.state = ENDED;\n schedule.timer.stop();\n schedule.on.call(active ? \"interrupt\" : \"cancel\", node, node.__data__, schedule.index, schedule.group);\n delete schedules[i];\n }\n\n if (empty) delete node.__transition;\n}\n","import interrupt from \"../interrupt.js\";\n\nexport default function(name) {\n return this.each(function() {\n interrupt(this, name);\n });\n}\n","import {get, set} from \"./schedule.js\";\n\nfunction tweenRemove(id, name) {\n var tween0, tween1;\n return function() {\n var schedule = set(this, id),\n tween = schedule.tween;\n\n // If this node shared tween with the previous node,\n // just assign the updated shared tween and we’re done!\n // Otherwise, copy-on-write.\n if (tween !== tween0) {\n tween1 = tween0 = tween;\n for (var i = 0, n = tween1.length; i < n; ++i) {\n if (tween1[i].name === name) {\n tween1 = tween1.slice();\n tween1.splice(i, 1);\n break;\n }\n }\n }\n\n schedule.tween = tween1;\n };\n}\n\nfunction tweenFunction(id, name, value) {\n var tween0, tween1;\n if (typeof value !== \"function\") throw new Error;\n return function() {\n var schedule = set(this, id),\n tween = schedule.tween;\n\n // If this node shared tween with the previous node,\n // just assign the updated shared tween and we’re done!\n // Otherwise, copy-on-write.\n if (tween !== tween0) {\n tween1 = (tween0 = tween).slice();\n for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {\n if (tween1[i].name === name) {\n tween1[i] = t;\n break;\n }\n }\n if (i === n) tween1.push(t);\n }\n\n schedule.tween = tween1;\n };\n}\n\nexport default function(name, value) {\n var id = this._id;\n\n name += \"\";\n\n if (arguments.length < 2) {\n var tween = get(this.node(), id).tween;\n for (var i = 0, n = tween.length, t; i < n; ++i) {\n if ((t = tween[i]).name === name) {\n return t.value;\n }\n }\n return null;\n }\n\n return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));\n}\n\nexport function tweenValue(transition, name, value) {\n var id = transition._id;\n\n transition.each(function() {\n var schedule = set(this, id);\n (schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments);\n });\n\n return function(node) {\n return get(node, id).value[name];\n };\n}\n","import {color} from \"d3-color\";\nimport {interpolateNumber, interpolateRgb, interpolateString} from \"d3-interpolate\";\n\nexport default function(a, b) {\n var c;\n return (typeof b === \"number\" ? interpolateNumber\n : b instanceof color ? interpolateRgb\n : (c = color(b)) ? (b = c, interpolateRgb)\n : interpolateString)(a, b);\n}\n","import {interpolateTransformSvg as interpolateTransform} from \"d3-interpolate\";\nimport {namespace} from \"d3-selection\";\nimport {tweenValue} from \"./tween.js\";\nimport interpolate from \"./interpolate.js\";\n\nfunction attrRemove(name) {\n return function() {\n this.removeAttribute(name);\n };\n}\n\nfunction attrRemoveNS(fullname) {\n return function() {\n this.removeAttributeNS(fullname.space, fullname.local);\n };\n}\n\nfunction attrConstant(name, interpolate, value1) {\n var string00,\n string1 = value1 + \"\",\n interpolate0;\n return function() {\n var string0 = this.getAttribute(name);\n return string0 === string1 ? null\n : string0 === string00 ? interpolate0\n : interpolate0 = interpolate(string00 = string0, value1);\n };\n}\n\nfunction attrConstantNS(fullname, interpolate, value1) {\n var string00,\n string1 = value1 + \"\",\n interpolate0;\n return function() {\n var string0 = this.getAttributeNS(fullname.space, fullname.local);\n return string0 === string1 ? null\n : string0 === string00 ? interpolate0\n : interpolate0 = interpolate(string00 = string0, value1);\n };\n}\n\nfunction attrFunction(name, interpolate, value) {\n var string00,\n string10,\n interpolate0;\n return function() {\n var string0, value1 = value(this), string1;\n if (value1 == null) return void this.removeAttribute(name);\n string0 = this.getAttribute(name);\n string1 = value1 + \"\";\n return string0 === string1 ? null\n : string0 === string00 && string1 === string10 ? interpolate0\n : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));\n };\n}\n\nfunction attrFunctionNS(fullname, interpolate, value) {\n var string00,\n string10,\n interpolate0;\n return function() {\n var string0, value1 = value(this), string1;\n if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);\n string0 = this.getAttributeNS(fullname.space, fullname.local);\n string1 = value1 + \"\";\n return string0 === string1 ? null\n : string0 === string00 && string1 === string10 ? interpolate0\n : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));\n };\n}\n\nexport default function(name, value) {\n var fullname = namespace(name), i = fullname === \"transform\" ? interpolateTransform : interpolate;\n return this.attrTween(name, typeof value === \"function\"\n ? (fullname.local ? attrFunctionNS : attrFunction)(fullname, i, tweenValue(this, \"attr.\" + name, value))\n : value == null ? (fullname.local ? attrRemoveNS : attrRemove)(fullname)\n : (fullname.local ? attrConstantNS : attrConstant)(fullname, i, value));\n}\n","import {namespace} from \"d3-selection\";\n\nfunction attrInterpolate(name, i) {\n return function(t) {\n this.setAttribute(name, i.call(this, t));\n };\n}\n\nfunction attrInterpolateNS(fullname, i) {\n return function(t) {\n this.setAttributeNS(fullname.space, fullname.local, i.call(this, t));\n };\n}\n\nfunction attrTweenNS(fullname, value) {\n var t0, i0;\n function tween() {\n var i = value.apply(this, arguments);\n if (i !== i0) t0 = (i0 = i) && attrInterpolateNS(fullname, i);\n return t0;\n }\n tween._value = value;\n return tween;\n}\n\nfunction attrTween(name, value) {\n var t0, i0;\n function tween() {\n var i = value.apply(this, arguments);\n if (i !== i0) t0 = (i0 = i) && attrInterpolate(name, i);\n return t0;\n }\n tween._value = value;\n return tween;\n}\n\nexport default function(name, value) {\n var key = \"attr.\" + name;\n if (arguments.length < 2) return (key = this.tween(key)) && key._value;\n if (value == null) return this.tween(key, null);\n if (typeof value !== \"function\") throw new Error;\n var fullname = namespace(name);\n return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));\n}\n","import {get, init} from \"./schedule.js\";\n\nfunction delayFunction(id, value) {\n return function() {\n init(this, id).delay = +value.apply(this, arguments);\n };\n}\n\nfunction delayConstant(id, value) {\n return value = +value, function() {\n init(this, id).delay = value;\n };\n}\n\nexport default function(value) {\n var id = this._id;\n\n return arguments.length\n ? this.each((typeof value === \"function\"\n ? delayFunction\n : delayConstant)(id, value))\n : get(this.node(), id).delay;\n}\n","import {get, set} from \"./schedule.js\";\n\nfunction durationFunction(id, value) {\n return function() {\n set(this, id).duration = +value.apply(this, arguments);\n };\n}\n\nfunction durationConstant(id, value) {\n return value = +value, function() {\n set(this, id).duration = value;\n };\n}\n\nexport default function(value) {\n var id = this._id;\n\n return arguments.length\n ? this.each((typeof value === \"function\"\n ? durationFunction\n : durationConstant)(id, value))\n : get(this.node(), id).duration;\n}\n","import {get, set} from \"./schedule.js\";\n\nfunction easeConstant(id, value) {\n if (typeof value !== \"function\") throw new Error;\n return function() {\n set(this, id).ease = value;\n };\n}\n\nexport default function(value) {\n var id = this._id;\n\n return arguments.length\n ? this.each(easeConstant(id, value))\n : get(this.node(), id).ease;\n}\n","import {matcher} from \"d3-selection\";\nimport {Transition} from \"./index.js\";\n\nexport default function(match) {\n if (typeof match !== \"function\") match = matcher(match);\n\n for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {\n for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {\n if ((node = group[i]) && match.call(node, node.__data__, i, group)) {\n subgroup.push(node);\n }\n }\n }\n\n return new Transition(subgroups, this._parents, this._name, this._id);\n}\n","import {Transition} from \"./index.js\";\n\nexport default function(transition) {\n if (transition._id !== this._id) throw new Error;\n\n for (var groups0 = this._groups, groups1 = transition._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {\n for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {\n if (node = group0[i] || group1[i]) {\n merge[i] = node;\n }\n }\n }\n\n for (; j < m0; ++j) {\n merges[j] = groups0[j];\n }\n\n return new Transition(merges, this._parents, this._name, this._id);\n}\n","import {get, set, init} from \"./schedule.js\";\n\nfunction start(name) {\n return (name + \"\").trim().split(/^|\\s+/).every(function(t) {\n var i = t.indexOf(\".\");\n if (i >= 0) t = t.slice(0, i);\n return !t || t === \"start\";\n });\n}\n\nfunction onFunction(id, name, listener) {\n var on0, on1, sit = start(name) ? init : set;\n return function() {\n var schedule = sit(this, id),\n on = schedule.on;\n\n // If this node shared a dispatch with the previous node,\n // just assign the updated shared dispatch and we’re done!\n // Otherwise, copy-on-write.\n if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);\n\n schedule.on = on1;\n };\n}\n\nexport default function(name, listener) {\n var id = this._id;\n\n return arguments.length < 2\n ? get(this.node(), id).on.on(name)\n : this.each(onFunction(id, name, listener));\n}\n","function removeFunction(id) {\n return function() {\n var parent = this.parentNode;\n for (var i in this.__transition) if (+i !== id) return;\n if (parent) parent.removeChild(this);\n };\n}\n\nexport default function() {\n return this.on(\"end.remove\", removeFunction(this._id));\n}\n","import {selector} from \"d3-selection\";\nimport {Transition} from \"./index.js\";\nimport schedule, {get} from \"./schedule.js\";\n\nexport default function(select) {\n var name = this._name,\n id = this._id;\n\n if (typeof select !== \"function\") select = selector(select);\n\n for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {\n for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {\n if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {\n if (\"__data__\" in node) subnode.__data__ = node.__data__;\n subgroup[i] = subnode;\n schedule(subgroup[i], name, id, i, subgroup, get(node, id));\n }\n }\n }\n\n return new Transition(subgroups, this._parents, name, id);\n}\n","import {selectorAll} from \"d3-selection\";\nimport {Transition} from \"./index.js\";\nimport schedule, {get} from \"./schedule.js\";\n\nexport default function(select) {\n var name = this._name,\n id = this._id;\n\n if (typeof select !== \"function\") select = selectorAll(select);\n\n for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {\n for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {\n if (node = group[i]) {\n for (var children = select.call(node, node.__data__, i, group), child, inherit = get(node, id), k = 0, l = children.length; k < l; ++k) {\n if (child = children[k]) {\n schedule(child, name, id, k, children, inherit);\n }\n }\n subgroups.push(children);\n parents.push(node);\n }\n }\n }\n\n return new Transition(subgroups, parents, name, id);\n}\n","import {selection} from \"d3-selection\";\n\nvar Selection = selection.prototype.constructor;\n\nexport default function() {\n return new Selection(this._groups, this._parents);\n}\n","import {interpolateTransformCss as interpolateTransform} from \"d3-interpolate\";\nimport {style} from \"d3-selection\";\nimport {set} from \"./schedule.js\";\nimport {tweenValue} from \"./tween.js\";\nimport interpolate from \"./interpolate.js\";\n\nfunction styleNull(name, interpolate) {\n var string00,\n string10,\n interpolate0;\n return function() {\n var string0 = style(this, name),\n string1 = (this.style.removeProperty(name), style(this, name));\n return string0 === string1 ? null\n : string0 === string00 && string1 === string10 ? interpolate0\n : interpolate0 = interpolate(string00 = string0, string10 = string1);\n };\n}\n\nfunction styleRemove(name) {\n return function() {\n this.style.removeProperty(name);\n };\n}\n\nfunction styleConstant(name, interpolate, value1) {\n var string00,\n string1 = value1 + \"\",\n interpolate0;\n return function() {\n var string0 = style(this, name);\n return string0 === string1 ? null\n : string0 === string00 ? interpolate0\n : interpolate0 = interpolate(string00 = string0, value1);\n };\n}\n\nfunction styleFunction(name, interpolate, value) {\n var string00,\n string10,\n interpolate0;\n return function() {\n var string0 = style(this, name),\n value1 = value(this),\n string1 = value1 + \"\";\n if (value1 == null) string1 = value1 = (this.style.removeProperty(name), style(this, name));\n return string0 === string1 ? null\n : string0 === string00 && string1 === string10 ? interpolate0\n : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));\n };\n}\n\nfunction styleMaybeRemove(id, name) {\n var on0, on1, listener0, key = \"style.\" + name, event = \"end.\" + key, remove;\n return function() {\n var schedule = set(this, id),\n on = schedule.on,\n listener = schedule.value[key] == null ? remove || (remove = styleRemove(name)) : undefined;\n\n // If this node shared a dispatch with the previous node,\n // just assign the updated shared dispatch and we’re done!\n // Otherwise, copy-on-write.\n if (on !== on0 || listener0 !== listener) (on1 = (on0 = on).copy()).on(event, listener0 = listener);\n\n schedule.on = on1;\n };\n}\n\nexport default function(name, value, priority) {\n var i = (name += \"\") === \"transform\" ? interpolateTransform : interpolate;\n return value == null ? this\n .styleTween(name, styleNull(name, i))\n .on(\"end.style.\" + name, styleRemove(name))\n : typeof value === \"function\" ? this\n .styleTween(name, styleFunction(name, i, tweenValue(this, \"style.\" + name, value)))\n .each(styleMaybeRemove(this._id, name))\n : this\n .styleTween(name, styleConstant(name, i, value), priority)\n .on(\"end.style.\" + name, null);\n}\n","function styleInterpolate(name, i, priority) {\n return function(t) {\n this.style.setProperty(name, i.call(this, t), priority);\n };\n}\n\nfunction styleTween(name, value, priority) {\n var t, i0;\n function tween() {\n var i = value.apply(this, arguments);\n if (i !== i0) t = (i0 = i) && styleInterpolate(name, i, priority);\n return t;\n }\n tween._value = value;\n return tween;\n}\n\nexport default function(name, value, priority) {\n var key = \"style.\" + (name += \"\");\n if (arguments.length < 2) return (key = this.tween(key)) && key._value;\n if (value == null) return this.tween(key, null);\n if (typeof value !== \"function\") throw new Error;\n return this.tween(key, styleTween(name, value, priority == null ? \"\" : priority));\n}\n","import {tweenValue} from \"./tween.js\";\n\nfunction textConstant(value) {\n return function() {\n this.textContent = value;\n };\n}\n\nfunction textFunction(value) {\n return function() {\n var value1 = value(this);\n this.textContent = value1 == null ? \"\" : value1;\n };\n}\n\nexport default function(value) {\n return this.tween(\"text\", typeof value === \"function\"\n ? textFunction(tweenValue(this, \"text\", value))\n : textConstant(value == null ? \"\" : value + \"\"));\n}\n","function textInterpolate(i) {\n return function(t) {\n this.textContent = i.call(this, t);\n };\n}\n\nfunction textTween(value) {\n var t0, i0;\n function tween() {\n var i = value.apply(this, arguments);\n if (i !== i0) t0 = (i0 = i) && textInterpolate(i);\n return t0;\n }\n tween._value = value;\n return tween;\n}\n\nexport default function(value) {\n var key = \"text\";\n if (arguments.length < 1) return (key = this.tween(key)) && key._value;\n if (value == null) return this.tween(key, null);\n if (typeof value !== \"function\") throw new Error;\n return this.tween(key, textTween(value));\n}\n","import {Transition, newId} from \"./index.js\";\nimport schedule, {get} from \"./schedule.js\";\n\nexport default function() {\n var name = this._name,\n id0 = this._id,\n id1 = newId();\n\n for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {\n for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {\n if (node = group[i]) {\n var inherit = get(node, id0);\n schedule(node, name, id1, i, group, {\n time: inherit.time + inherit.delay + inherit.duration,\n delay: 0,\n duration: inherit.duration,\n ease: inherit.ease\n });\n }\n }\n }\n\n return new Transition(groups, this._parents, name, id1);\n}\n","import {set} from \"./schedule.js\";\n\nexport default function() {\n var on0, on1, that = this, id = that._id, size = that.size();\n return new Promise(function(resolve, reject) {\n var cancel = {value: reject},\n end = {value: function() { if (--size === 0) resolve(); }};\n\n that.each(function() {\n var schedule = set(this, id),\n on = schedule.on;\n\n // If this node shared a dispatch with the previous node,\n // just assign the updated shared dispatch and we’re done!\n // Otherwise, copy-on-write.\n if (on !== on0) {\n on1 = (on0 = on).copy();\n on1._.cancel.push(cancel);\n on1._.interrupt.push(cancel);\n on1._.end.push(end);\n }\n\n schedule.on = on1;\n });\n });\n}\n","import {selection} from \"d3-selection\";\nimport transition_attr from \"./attr.js\";\nimport transition_attrTween from \"./attrTween.js\";\nimport transition_delay from \"./delay.js\";\nimport transition_duration from \"./duration.js\";\nimport transition_ease from \"./ease.js\";\nimport transition_filter from \"./filter.js\";\nimport transition_merge from \"./merge.js\";\nimport transition_on from \"./on.js\";\nimport transition_remove from \"./remove.js\";\nimport transition_select from \"./select.js\";\nimport transition_selectAll from \"./selectAll.js\";\nimport transition_selection from \"./selection.js\";\nimport transition_style from \"./style.js\";\nimport transition_styleTween from \"./styleTween.js\";\nimport transition_text from \"./text.js\";\nimport transition_textTween from \"./textTween.js\";\nimport transition_transition from \"./transition.js\";\nimport transition_tween from \"./tween.js\";\nimport transition_end from \"./end.js\";\n\nvar id = 0;\n\nexport function Transition(groups, parents, name, id) {\n this._groups = groups;\n this._parents = parents;\n this._name = name;\n this._id = id;\n}\n\nexport default function transition(name) {\n return selection().transition(name);\n}\n\nexport function newId() {\n return ++id;\n}\n\nvar selection_prototype = selection.prototype;\n\nTransition.prototype = transition.prototype = {\n constructor: Transition,\n select: transition_select,\n selectAll: transition_selectAll,\n filter: transition_filter,\n merge: transition_merge,\n selection: transition_selection,\n transition: transition_transition,\n call: selection_prototype.call,\n nodes: selection_prototype.nodes,\n node: selection_prototype.node,\n size: selection_prototype.size,\n empty: selection_prototype.empty,\n each: selection_prototype.each,\n on: transition_on,\n attr: transition_attr,\n attrTween: transition_attrTween,\n style: transition_style,\n styleTween: transition_styleTween,\n text: transition_text,\n textTween: transition_textTween,\n remove: transition_remove,\n tween: transition_tween,\n delay: transition_delay,\n duration: transition_duration,\n ease: transition_ease,\n end: transition_end\n};\n","export function linear(t) {\n return +t;\n}\n","export function cubicIn(t) {\n return t * t * t;\n}\n\nexport function cubicOut(t) {\n return --t * t * t + 1;\n}\n\nexport function cubicInOut(t) {\n return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;\n}\n","import {Transition, newId} from \"../transition/index.js\";\nimport schedule from \"../transition/schedule.js\";\nimport {easeCubicInOut} from \"d3-ease\";\nimport {now} from \"d3-timer\";\n\nvar defaultTiming = {\n time: null, // Set on use.\n delay: 0,\n duration: 250,\n ease: easeCubicInOut\n};\n\nfunction inherit(node, id) {\n var timing;\n while (!(timing = node.__transition) || !(timing = timing[id])) {\n if (!(node = node.parentNode)) {\n return defaultTiming.time = now(), defaultTiming;\n }\n }\n return timing;\n}\n\nexport default function(name) {\n var id,\n timing;\n\n if (name instanceof Transition) {\n id = name._id, name = name._name;\n } else {\n id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + \"\";\n }\n\n for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {\n for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {\n if (node = group[i]) {\n schedule(node, name, id, i, group, timing || inherit(node, id));\n }\n }\n }\n\n return new Transition(groups, this._parents, name, id);\n}\n","import {selection} from \"d3-selection\";\nimport selection_interrupt from \"./interrupt.js\";\nimport selection_transition from \"./transition.js\";\n\nselection.prototype.interrupt = selection_interrupt;\nselection.prototype.transition = selection_transition;\n","export default function(x) {\n return function() {\n return x;\n };\n}\n","export default function ZoomEvent(target, type, transform) {\n this.target = target;\n this.type = type;\n this.transform = transform;\n}\n","export function Transform(k, x, y) {\n this.k = k;\n this.x = x;\n this.y = y;\n}\n\nTransform.prototype = {\n constructor: Transform,\n scale: function(k) {\n return k === 1 ? this : new Transform(this.k * k, this.x, this.y);\n },\n translate: function(x, y) {\n return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);\n },\n apply: function(point) {\n return [point[0] * this.k + this.x, point[1] * this.k + this.y];\n },\n applyX: function(x) {\n return x * this.k + this.x;\n },\n applyY: function(y) {\n return y * this.k + this.y;\n },\n invert: function(location) {\n return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];\n },\n invertX: function(x) {\n return (x - this.x) / this.k;\n },\n invertY: function(y) {\n return (y - this.y) / this.k;\n },\n rescaleX: function(x) {\n return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));\n },\n rescaleY: function(y) {\n return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));\n },\n toString: function() {\n return \"translate(\" + this.x + \",\" + this.y + \") scale(\" + this.k + \")\";\n }\n};\n\nexport var identity = new Transform(1, 0, 0);\n\ntransform.prototype = Transform.prototype;\n\nexport default function transform(node) {\n while (!node.__zoom) if (!(node = node.parentNode)) return identity;\n return node.__zoom;\n}\n","import {event} from \"d3-selection\";\n\nexport function nopropagation() {\n event.stopImmediatePropagation();\n}\n\nexport default function() {\n event.preventDefault();\n event.stopImmediatePropagation();\n}\n","import {dispatch} from \"d3-dispatch\";\nimport {dragDisable, dragEnable} from \"d3-drag\";\nimport {interpolateZoom} from \"d3-interpolate\";\nimport {event, customEvent, select, mouse, touch} from \"d3-selection\";\nimport {interrupt} from \"d3-transition\";\nimport constant from \"./constant.js\";\nimport ZoomEvent from \"./event.js\";\nimport {Transform, identity} from \"./transform.js\";\nimport noevent, {nopropagation} from \"./noevent.js\";\n\n// Ignore right-click, since that should open the context menu.\nfunction defaultFilter() {\n return !event.ctrlKey && !event.button;\n}\n\nfunction defaultExtent() {\n var e = this;\n if (e instanceof SVGElement) {\n e = e.ownerSVGElement || e;\n if (e.hasAttribute(\"viewBox\")) {\n e = e.viewBox.baseVal;\n return [[e.x, e.y], [e.x + e.width, e.y + e.height]];\n }\n return [[0, 0], [e.width.baseVal.value, e.height.baseVal.value]];\n }\n return [[0, 0], [e.clientWidth, e.clientHeight]];\n}\n\nfunction defaultTransform() {\n return this.__zoom || identity;\n}\n\nfunction defaultWheelDelta() {\n return -event.deltaY * (event.deltaMode === 1 ? 0.05 : event.deltaMode ? 1 : 0.002);\n}\n\nfunction defaultTouchable() {\n return navigator.maxTouchPoints || (\"ontouchstart\" in this);\n}\n\nfunction defaultConstrain(transform, extent, translateExtent) {\n var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],\n dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],\n dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],\n dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];\n return transform.translate(\n dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),\n dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)\n );\n}\n\nexport default function() {\n var filter = defaultFilter,\n extent = defaultExtent,\n constrain = defaultConstrain,\n wheelDelta = defaultWheelDelta,\n touchable = defaultTouchable,\n scaleExtent = [0, Infinity],\n translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],\n duration = 250,\n interpolate = interpolateZoom,\n listeners = dispatch(\"start\", \"zoom\", \"end\"),\n touchstarting,\n touchending,\n touchDelay = 500,\n wheelDelay = 150,\n clickDistance2 = 0;\n\n function zoom(selection) {\n selection\n .property(\"__zoom\", defaultTransform)\n .on(\"wheel.zoom\", wheeled)\n .on(\"mousedown.zoom\", mousedowned)\n .on(\"dblclick.zoom\", dblclicked)\n .filter(touchable)\n .on(\"touchstart.zoom\", touchstarted)\n .on(\"touchmove.zoom\", touchmoved)\n .on(\"touchend.zoom touchcancel.zoom\", touchended)\n .style(\"touch-action\", \"none\")\n .style(\"-webkit-tap-highlight-color\", \"rgba(0,0,0,0)\");\n }\n\n zoom.transform = function(collection, transform, point) {\n var selection = collection.selection ? collection.selection() : collection;\n selection.property(\"__zoom\", defaultTransform);\n if (collection !== selection) {\n schedule(collection, transform, point);\n } else {\n selection.interrupt().each(function() {\n gesture(this, arguments)\n .start()\n .zoom(null, typeof transform === \"function\" ? transform.apply(this, arguments) : transform)\n .end();\n });\n }\n };\n\n zoom.scaleBy = function(selection, k, p) {\n zoom.scaleTo(selection, function() {\n var k0 = this.__zoom.k,\n k1 = typeof k === \"function\" ? k.apply(this, arguments) : k;\n return k0 * k1;\n }, p);\n };\n\n zoom.scaleTo = function(selection, k, p) {\n zoom.transform(selection, function() {\n var e = extent.apply(this, arguments),\n t0 = this.__zoom,\n p0 = p == null ? centroid(e) : typeof p === \"function\" ? p.apply(this, arguments) : p,\n p1 = t0.invert(p0),\n k1 = typeof k === \"function\" ? k.apply(this, arguments) : k;\n return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);\n }, p);\n };\n\n zoom.translateBy = function(selection, x, y) {\n zoom.transform(selection, function() {\n return constrain(this.__zoom.translate(\n typeof x === \"function\" ? x.apply(this, arguments) : x,\n typeof y === \"function\" ? y.apply(this, arguments) : y\n ), extent.apply(this, arguments), translateExtent);\n });\n };\n\n zoom.translateTo = function(selection, x, y, p) {\n zoom.transform(selection, function() {\n var e = extent.apply(this, arguments),\n t = this.__zoom,\n p0 = p == null ? centroid(e) : typeof p === \"function\" ? p.apply(this, arguments) : p;\n return constrain(identity.translate(p0[0], p0[1]).scale(t.k).translate(\n typeof x === \"function\" ? -x.apply(this, arguments) : -x,\n typeof y === \"function\" ? -y.apply(this, arguments) : -y\n ), e, translateExtent);\n }, p);\n };\n\n function scale(transform, k) {\n k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));\n return k === transform.k ? transform : new Transform(k, transform.x, transform.y);\n }\n\n function translate(transform, p0, p1) {\n var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;\n return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);\n }\n\n function centroid(extent) {\n return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];\n }\n\n function schedule(transition, transform, point) {\n transition\n .on(\"start.zoom\", function() { gesture(this, arguments).start(); })\n .on(\"interrupt.zoom end.zoom\", function() { gesture(this, arguments).end(); })\n .tween(\"zoom\", function() {\n var that = this,\n args = arguments,\n g = gesture(that, args),\n e = extent.apply(that, args),\n p = point == null ? centroid(e) : typeof point === \"function\" ? point.apply(that, args) : point,\n w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),\n a = that.__zoom,\n b = typeof transform === \"function\" ? transform.apply(that, args) : transform,\n i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));\n return function(t) {\n if (t === 1) t = b; // Avoid rounding error on end.\n else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }\n g.zoom(null, t);\n };\n });\n }\n\n function gesture(that, args, clean) {\n return (!clean && that.__zooming) || new Gesture(that, args);\n }\n\n function Gesture(that, args) {\n this.that = that;\n this.args = args;\n this.active = 0;\n this.extent = extent.apply(that, args);\n this.taps = 0;\n }\n\n Gesture.prototype = {\n start: function() {\n if (++this.active === 1) {\n this.that.__zooming = this;\n this.emit(\"start\");\n }\n return this;\n },\n zoom: function(key, transform) {\n if (this.mouse && key !== \"mouse\") this.mouse[1] = transform.invert(this.mouse[0]);\n if (this.touch0 && key !== \"touch\") this.touch0[1] = transform.invert(this.touch0[0]);\n if (this.touch1 && key !== \"touch\") this.touch1[1] = transform.invert(this.touch1[0]);\n this.that.__zoom = transform;\n this.emit(\"zoom\");\n return this;\n },\n end: function() {\n if (--this.active === 0) {\n delete this.that.__zooming;\n this.emit(\"end\");\n }\n return this;\n },\n emit: function(type) {\n customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);\n }\n };\n\n function wheeled() {\n if (!filter.apply(this, arguments)) return;\n var g = gesture(this, arguments),\n t = this.__zoom,\n k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),\n p = mouse(this);\n\n // If the mouse is in the same location as before, reuse it.\n // If there were recent wheel events, reset the wheel idle timeout.\n if (g.wheel) {\n if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {\n g.mouse[1] = t.invert(g.mouse[0] = p);\n }\n clearTimeout(g.wheel);\n }\n\n // If this wheel event won’t trigger a transform change, ignore it.\n else if (t.k === k) return;\n\n // Otherwise, capture the mouse point and location at the start.\n else {\n g.mouse = [p, t.invert(p)];\n interrupt(this);\n g.start();\n }\n\n noevent();\n g.wheel = setTimeout(wheelidled, wheelDelay);\n g.zoom(\"mouse\", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));\n\n function wheelidled() {\n g.wheel = null;\n g.end();\n }\n }\n\n function mousedowned() {\n if (touchending || !filter.apply(this, arguments)) return;\n var g = gesture(this, arguments, true),\n v = select(event.view).on(\"mousemove.zoom\", mousemoved, true).on(\"mouseup.zoom\", mouseupped, true),\n p = mouse(this),\n x0 = event.clientX,\n y0 = event.clientY;\n\n dragDisable(event.view);\n nopropagation();\n g.mouse = [p, this.__zoom.invert(p)];\n interrupt(this);\n g.start();\n\n function mousemoved() {\n noevent();\n if (!g.moved) {\n var dx = event.clientX - x0, dy = event.clientY - y0;\n g.moved = dx * dx + dy * dy > clickDistance2;\n }\n g.zoom(\"mouse\", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent, translateExtent));\n }\n\n function mouseupped() {\n v.on(\"mousemove.zoom mouseup.zoom\", null);\n dragEnable(event.view, g.moved);\n noevent();\n g.end();\n }\n }\n\n function dblclicked() {\n if (!filter.apply(this, arguments)) return;\n var t0 = this.__zoom,\n p0 = mouse(this),\n p1 = t0.invert(p0),\n k1 = t0.k * (event.shiftKey ? 0.5 : 2),\n t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments), translateExtent);\n\n noevent();\n if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);\n else select(this).call(zoom.transform, t1);\n }\n\n function touchstarted() {\n if (!filter.apply(this, arguments)) return;\n var touches = event.touches,\n n = touches.length,\n g = gesture(this, arguments, event.changedTouches.length === n),\n started, i, t, p;\n\n nopropagation();\n for (i = 0; i < n; ++i) {\n t = touches[i], p = touch(this, touches, t.identifier);\n p = [p, this.__zoom.invert(p), t.identifier];\n if (!g.touch0) g.touch0 = p, started = true, g.taps = 1 + !!touchstarting;\n else if (!g.touch1 && g.touch0[2] !== p[2]) g.touch1 = p, g.taps = 0;\n }\n\n if (touchstarting) touchstarting = clearTimeout(touchstarting);\n\n if (started) {\n if (g.taps < 2) touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);\n interrupt(this);\n g.start();\n }\n }\n\n function touchmoved() {\n if (!this.__zooming) return;\n var g = gesture(this, arguments),\n touches = event.changedTouches,\n n = touches.length, i, t, p, l;\n\n noevent();\n if (touchstarting) touchstarting = clearTimeout(touchstarting);\n g.taps = 0;\n for (i = 0; i < n; ++i) {\n t = touches[i], p = touch(this, touches, t.identifier);\n if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;\n else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;\n }\n t = g.that.__zoom;\n if (g.touch1) {\n var p0 = g.touch0[0], l0 = g.touch0[1],\n p1 = g.touch1[0], l1 = g.touch1[1],\n dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,\n dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;\n t = scale(t, Math.sqrt(dp / dl));\n p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];\n l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];\n }\n else if (g.touch0) p = g.touch0[0], l = g.touch0[1];\n else return;\n g.zoom(\"touch\", constrain(translate(t, p, l), g.extent, translateExtent));\n }\n\n function touchended() {\n if (!this.__zooming) return;\n var g = gesture(this, arguments),\n touches = event.changedTouches,\n n = touches.length, i, t;\n\n nopropagation();\n if (touchending) clearTimeout(touchending);\n touchending = setTimeout(function() { touchending = null; }, touchDelay);\n for (i = 0; i < n; ++i) {\n t = touches[i];\n if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;\n else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;\n }\n if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;\n if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);\n else {\n g.end();\n // If this was a dbltap, reroute to the (optional) dblclick.zoom handler.\n if (g.taps === 2) {\n var p = select(this).on(\"dblclick.zoom\");\n if (p) p.apply(this, arguments);\n }\n }\n }\n\n zoom.wheelDelta = function(_) {\n return arguments.length ? (wheelDelta = typeof _ === \"function\" ? _ : constant(+_), zoom) : wheelDelta;\n };\n\n zoom.filter = function(_) {\n return arguments.length ? (filter = typeof _ === \"function\" ? _ : constant(!!_), zoom) : filter;\n };\n\n zoom.touchable = function(_) {\n return arguments.length ? (touchable = typeof _ === \"function\" ? _ : constant(!!_), zoom) : touchable;\n };\n\n zoom.extent = function(_) {\n return arguments.length ? (extent = typeof _ === \"function\" ? _ : constant([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;\n };\n\n zoom.scaleExtent = function(_) {\n return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];\n };\n\n zoom.translateExtent = function(_) {\n return arguments.length ? (translateExtent[0][0] = +_[0][0], translateExtent[1][0] = +_[1][0], translateExtent[0][1] = +_[0][1], translateExtent[1][1] = +_[1][1], zoom) : [[translateExtent[0][0], translateExtent[0][1]], [translateExtent[1][0], translateExtent[1][1]]];\n };\n\n zoom.constrain = function(_) {\n return arguments.length ? (constrain = _, zoom) : constrain;\n };\n\n zoom.duration = function(_) {\n return arguments.length ? (duration = +_, zoom) : duration;\n };\n\n zoom.interpolate = function(_) {\n return arguments.length ? (interpolate = _, zoom) : interpolate;\n };\n\n zoom.on = function() {\n var value = listeners.on.apply(listeners, arguments);\n return value === listeners ? zoom : value;\n };\n\n zoom.clickDistance = function(_) {\n return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);\n };\n\n return zoom;\n}\n","import {\n geoMercatorRaw as d3_geoMercatorRaw,\n geoTransform as d3_geoTransform\n} from 'd3-geo';\n\nimport {\n zoomIdentity as d3_zoomIdentity\n} from 'd3-zoom';\n\n\n/*\n Bypasses features of D3's default projection stream pipeline that are unnecessary:\n * Antimeridian clipping\n * Spherical rotation\n * Resampling\n*/\nexport function geoRawMercator() {\n var project = d3_geoMercatorRaw;\n var k = 512 / Math.PI; // scale\n var x = 0;\n var y = 0; // translate\n var clipExtent = [[0, 0], [0, 0]];\n\n\n function projection(point) {\n point = project(point[0] * Math.PI / 180, point[1] * Math.PI / 180);\n return [point[0] * k + x, y - point[1] * k];\n }\n\n\n projection.invert = function(point) {\n point = project.invert((point[0] - x) / k, (y - point[1]) / k);\n return point && [point[0] * 180 / Math.PI, point[1] * 180 / Math.PI];\n };\n\n\n projection.scale = function(_) {\n if (!arguments.length) return k;\n k = +_;\n return projection;\n };\n\n\n projection.translate = function(_) {\n if (!arguments.length) return [x, y];\n x = +_[0];\n y = +_[1];\n return projection;\n };\n\n\n projection.clipExtent = function(_) {\n if (!arguments.length) return clipExtent;\n clipExtent = _;\n return projection;\n };\n\n\n projection.transform = function(obj) {\n if (!arguments.length) return d3_zoomIdentity.translate(x, y).scale(k);\n x = +obj.x;\n y = +obj.y;\n k = +obj.k;\n return projection;\n };\n\n\n projection.stream = d3_geoTransform({\n point: function(x, y) {\n var vec = projection([x, y]);\n this.stream.point(vec[0], vec[1]);\n }\n }).stream;\n\n\n return projection;\n}\n","import { geoVecEqual, geoVecNormalizedDot } from './vector';\n\n\nexport function geoOrthoNormalizedDotProduct(a, b, origin) {\n if (geoVecEqual(origin, a) || geoVecEqual(origin, b)) {\n return 1; // coincident points, treat as straight and try to remove\n }\n return geoVecNormalizedDot(a, b, origin);\n}\n\n\nfunction geoOrthoFilterDotProduct(dotp, epsilon, lowerThreshold, upperThreshold, allowStraightAngles) {\n var val = Math.abs(dotp);\n if (val < epsilon) {\n return 0; // already orthogonal\n } else if (allowStraightAngles && Math.abs(val-1) < epsilon) {\n return 0; // straight angle, which is okay in this case\n } else if (val < lowerThreshold || val > upperThreshold) {\n return dotp; // can be adjusted\n } else {\n return null; // ignore vertex\n }\n}\n\n\nexport function geoOrthoCalcScore(points, isClosed, epsilon, threshold) {\n var score = 0;\n var first = isClosed ? 0 : 1;\n var last = isClosed ? points.length : points.length - 1;\n var coords = points.map(function(p) { return p.coord; });\n\n var lowerThreshold = Math.cos((90 - threshold) * Math.PI / 180);\n var upperThreshold = Math.cos(threshold * Math.PI / 180);\n\n for (var i = first; i < last; i++) {\n var a = coords[(i - 1 + coords.length) % coords.length];\n var origin = coords[i];\n var b = coords[(i + 1) % coords.length];\n\n var dotp = geoOrthoFilterDotProduct(geoOrthoNormalizedDotProduct(a, b, origin), epsilon, lowerThreshold, upperThreshold);\n if (dotp === null) continue; // ignore vertex\n score = score + 2.0 * Math.min(Math.abs(dotp - 1.0), Math.min(Math.abs(dotp), Math.abs(dotp + 1)));\n }\n\n return score;\n}\n\n// returns the maximum angle less than `lessThan` between the actual corner and a 0° or 90° corner\nexport function geoOrthoMaxOffsetAngle(coords, isClosed, lessThan) {\n var max = -Infinity;\n\n var first = isClosed ? 0 : 1;\n var last = isClosed ? coords.length : coords.length - 1;\n\n for (var i = first; i < last; i++) {\n var a = coords[(i - 1 + coords.length) % coords.length];\n var origin = coords[i];\n var b = coords[(i + 1) % coords.length];\n var normalizedDotP = geoOrthoNormalizedDotProduct(a, b, origin);\n\n var angle = Math.acos(Math.abs(normalizedDotP)) * 180 / Math.PI;\n\n if (angle > 45) angle = 90 - angle;\n\n if (angle >= lessThan) continue;\n\n if (angle > max) max = angle;\n }\n\n if (max === -Infinity) return null;\n\n return max;\n}\n\n\n// similar to geoOrthoCalcScore, but returns quickly if there is something to do\nexport function geoOrthoCanOrthogonalize(coords, isClosed, epsilon, threshold, allowStraightAngles) {\n var score = null;\n var first = isClosed ? 0 : 1;\n var last = isClosed ? coords.length : coords.length - 1;\n\n var lowerThreshold = Math.cos((90 - threshold) * Math.PI / 180);\n var upperThreshold = Math.cos(threshold * Math.PI / 180);\n\n for (var i = first; i < last; i++) {\n var a = coords[(i - 1 + coords.length) % coords.length];\n var origin = coords[i];\n var b = coords[(i + 1) % coords.length];\n\n var dotp = geoOrthoFilterDotProduct(geoOrthoNormalizedDotProduct(a, b, origin), epsilon, lowerThreshold, upperThreshold, allowStraightAngles);\n if (dotp === null) continue; // ignore vertex\n if (Math.abs(dotp) > 0) return 1; // something to do\n score = 0; // already square\n }\n\n return score;\n}\n","\n// Returns true if a and b have the same elements at the same indices.\nexport function utilArrayIdentical(a, b) {\n // an array is always identical to itself\n if (a === b) return true;\n\n var i = a.length;\n if (i !== b.length) return false;\n while (i--) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n}\n\n// http://2ality.com/2015/01/es6-set-operations.html\n\n// Difference (a \\ b): create a set that contains those elements of set a that are not in set b.\n// This operation is also sometimes called minus (-).\n// var a = [1,2,3];\n// var b = [4,3,2];\n// utilArrayDifference(a, b)\n// [1]\n// utilArrayDifference(b, a)\n// [4]\nexport function utilArrayDifference(a, b) {\n var other = new Set(b);\n return Array.from(new Set(a))\n .filter(function(v) { return !other.has(v); });\n}\n\n// Intersection (a ∩ b): create a set that contains those elements of set a that are also in set b.\n// var a = [1,2,3];\n// var b = [4,3,2];\n// utilArrayIntersection(a, b)\n// [2,3]\nexport function utilArrayIntersection(a, b) {\n var other = new Set(b);\n return Array.from(new Set(a))\n .filter(function(v) { return other.has(v); });\n}\n\n// Union (a ∪ b): create a set that contains the elements of both set a and set b.\n// var a = [1,2,3];\n// var b = [4,3,2];\n// utilArrayUnion(a, b)\n// [1,2,3,4]\nexport function utilArrayUnion(a, b) {\n var result = new Set(a);\n b.forEach(function(v) { result.add(v); });\n return Array.from(result);\n}\n\n// Returns an Array with all the duplicates removed\n// var a = [1,1,2,3,3];\n// utilArrayUniq(a)\n// [1,2,3]\nexport function utilArrayUniq(a) {\n return Array.from(new Set(a));\n}\n\n\n// Splits array into chunks of given chunk size\n// var a = [1,2,3,4,5,6,7];\n// utilArrayChunk(a, 3);\n// [[1,2,3],[4,5,6],[7]];\nexport function utilArrayChunk(a, chunkSize) {\n if (!chunkSize || chunkSize < 0) return [a.slice()];\n\n var result = new Array(Math.ceil(a.length / chunkSize));\n return Array.from(result, function(item, i) {\n return a.slice(i * chunkSize, i * chunkSize + chunkSize);\n });\n}\n\n\n// Flattens two level array into a single level\n// var a = [[1,2,3],[4,5,6],[7]];\n// utilArrayFlatten(a);\n// [1,2,3,4,5,6,7];\nexport function utilArrayFlatten(a) {\n return a.reduce(function(acc, val) {\n return acc.concat(val);\n }, []);\n}\n\n\n// Groups the items of the Array according to the given key\n// `key` can be passed as a property or as a key function\n//\n// var pets = [\n// { type: 'Dog', name: 'Spot' },\n// { type: 'Cat', name: 'Tiger' },\n// { type: 'Dog', name: 'Rover' },\n// { type: 'Cat', name: 'Leo' }\n// ];\n//\n// utilArrayGroupBy(pets, 'type')\n// {\n// 'Dog': [{type: 'Dog', name: 'Spot'}, {type: 'Dog', name: 'Rover'}],\n// 'Cat': [{type: 'Cat', name: 'Tiger'}, {type: 'Cat', name: 'Leo'}]\n// }\n//\n// utilArrayGroupBy(pets, function(item) { return item.name.length; })\n// {\n// 3: [{type: 'Cat', name: 'Leo'}],\n// 4: [{type: 'Dog', name: 'Spot'}],\n// 5: [{type: 'Cat', name: 'Tiger'}, {type: 'Dog', name: 'Rover'}]\n// }\nexport function utilArrayGroupBy(a, key) {\n return a.reduce(function(acc, item) {\n var group = (typeof key === 'function') ? key(item) : item[key];\n (acc[group] = acc[group] || []).push(item);\n return acc;\n }, {});\n}\n\n\n// Returns an Array with all the duplicates removed\n// where uniqueness determined by the given key\n// `key` can be passed as a property or as a key function\n//\n// var pets = [\n// { type: 'Dog', name: 'Spot' },\n// { type: 'Cat', name: 'Tiger' },\n// { type: 'Dog', name: 'Rover' },\n// { type: 'Cat', name: 'Leo' }\n// ];\n//\n// utilArrayUniqBy(pets, 'type')\n// [\n// { type: 'Dog', name: 'Spot' },\n// { type: 'Cat', name: 'Tiger' }\n// ]\n//\n// utilArrayUniqBy(pets, function(item) { return item.name.length; })\n// [\n// { type: 'Dog', name: 'Spot' },\n// { type: 'Cat', name: 'Tiger' },\n// { type: 'Cat', name: 'Leo' }\n// }\nexport function utilArrayUniqBy(a, key) {\n var seen = new Set();\n return a.reduce(function(acc, item) {\n var val = (typeof key === 'function') ? key(item) : item[key];\n if (val && !seen.has(val)) {\n seen.add(val);\n acc.push(item);\n }\n return acc;\n }, []);\n}\n","exports.remove = removeDiacritics;\n\nvar replacementList = [\n {\n base: ' ',\n chars: \"\\u00A0\",\n }, {\n base: '0',\n chars: \"\\u07C0\",\n }, {\n base: 'A',\n chars: \"\\u24B6\\uFF21\\u00C0\\u00C1\\u00C2\\u1EA6\\u1EA4\\u1EAA\\u1EA8\\u00C3\\u0100\\u0102\\u1EB0\\u1EAE\\u1EB4\\u1EB2\\u0226\\u01E0\\u00C4\\u01DE\\u1EA2\\u00C5\\u01FA\\u01CD\\u0200\\u0202\\u1EA0\\u1EAC\\u1EB6\\u1E00\\u0104\\u023A\\u2C6F\",\n }, {\n base: 'AA',\n chars: \"\\uA732\",\n }, {\n base: 'AE',\n chars: \"\\u00C6\\u01FC\\u01E2\",\n }, {\n base: 'AO',\n chars: \"\\uA734\",\n }, {\n base: 'AU',\n chars: \"\\uA736\",\n }, {\n base: 'AV',\n chars: \"\\uA738\\uA73A\",\n }, {\n base: 'AY',\n chars: \"\\uA73C\",\n }, {\n base: 'B',\n chars: \"\\u24B7\\uFF22\\u1E02\\u1E04\\u1E06\\u0243\\u0181\",\n }, {\n base: 'C',\n chars: \"\\u24b8\\uff23\\uA73E\\u1E08\\u0106\\u0043\\u0108\\u010A\\u010C\\u00C7\\u0187\\u023B\",\n }, {\n base: 'D',\n chars: \"\\u24B9\\uFF24\\u1E0A\\u010E\\u1E0C\\u1E10\\u1E12\\u1E0E\\u0110\\u018A\\u0189\\u1D05\\uA779\",\n }, {\n base: 'Dh',\n chars: \"\\u00D0\",\n }, {\n base: 'DZ',\n chars: \"\\u01F1\\u01C4\",\n }, {\n base: 'Dz',\n chars: \"\\u01F2\\u01C5\",\n }, {\n base: 'E',\n chars: \"\\u025B\\u24BA\\uFF25\\u00C8\\u00C9\\u00CA\\u1EC0\\u1EBE\\u1EC4\\u1EC2\\u1EBC\\u0112\\u1E14\\u1E16\\u0114\\u0116\\u00CB\\u1EBA\\u011A\\u0204\\u0206\\u1EB8\\u1EC6\\u0228\\u1E1C\\u0118\\u1E18\\u1E1A\\u0190\\u018E\\u1D07\",\n }, {\n base: 'F',\n chars: \"\\uA77C\\u24BB\\uFF26\\u1E1E\\u0191\\uA77B\",\n }, {\n base: 'G',\n chars: \"\\u24BC\\uFF27\\u01F4\\u011C\\u1E20\\u011E\\u0120\\u01E6\\u0122\\u01E4\\u0193\\uA7A0\\uA77D\\uA77E\\u0262\",\n }, {\n base: 'H',\n chars: \"\\u24BD\\uFF28\\u0124\\u1E22\\u1E26\\u021E\\u1E24\\u1E28\\u1E2A\\u0126\\u2C67\\u2C75\\uA78D\",\n }, {\n base: 'I',\n chars: \"\\u24BE\\uFF29\\xCC\\xCD\\xCE\\u0128\\u012A\\u012C\\u0130\\xCF\\u1E2E\\u1EC8\\u01CF\\u0208\\u020A\\u1ECA\\u012E\\u1E2C\\u0197\",\n }, {\n base: 'J',\n chars: \"\\u24BF\\uFF2A\\u0134\\u0248\\u0237\",\n }, {\n base: 'K',\n chars: \"\\u24C0\\uFF2B\\u1E30\\u01E8\\u1E32\\u0136\\u1E34\\u0198\\u2C69\\uA740\\uA742\\uA744\\uA7A2\",\n }, {\n base: 'L',\n chars: \"\\u24C1\\uFF2C\\u013F\\u0139\\u013D\\u1E36\\u1E38\\u013B\\u1E3C\\u1E3A\\u0141\\u023D\\u2C62\\u2C60\\uA748\\uA746\\uA780\",\n }, {\n base: 'LJ',\n chars: \"\\u01C7\",\n }, {\n base: 'Lj',\n chars: \"\\u01C8\",\n }, {\n base: 'M',\n chars: \"\\u24C2\\uFF2D\\u1E3E\\u1E40\\u1E42\\u2C6E\\u019C\\u03FB\",\n }, {\n base: 'N',\n chars: \"\\uA7A4\\u0220\\u24C3\\uFF2E\\u01F8\\u0143\\xD1\\u1E44\\u0147\\u1E46\\u0145\\u1E4A\\u1E48\\u019D\\uA790\\u1D0E\",\n }, {\n base: 'NJ',\n chars: \"\\u01CA\",\n }, {\n base: 'Nj',\n chars: \"\\u01CB\",\n }, {\n base: 'O',\n chars: \"\\u24C4\\uFF2F\\xD2\\xD3\\xD4\\u1ED2\\u1ED0\\u1ED6\\u1ED4\\xD5\\u1E4C\\u022C\\u1E4E\\u014C\\u1E50\\u1E52\\u014E\\u022E\\u0230\\xD6\\u022A\\u1ECE\\u0150\\u01D1\\u020C\\u020E\\u01A0\\u1EDC\\u1EDA\\u1EE0\\u1EDE\\u1EE2\\u1ECC\\u1ED8\\u01EA\\u01EC\\xD8\\u01FE\\u0186\\u019F\\uA74A\\uA74C\",\n }, {\n base: 'OE',\n chars: \"\\u0152\",\n }, {\n base: 'OI',\n chars: \"\\u01A2\",\n }, {\n base: 'OO',\n chars: \"\\uA74E\",\n }, {\n base: 'OU',\n chars: \"\\u0222\",\n }, {\n base: 'P',\n chars: \"\\u24C5\\uFF30\\u1E54\\u1E56\\u01A4\\u2C63\\uA750\\uA752\\uA754\",\n }, {\n base: 'Q',\n chars: \"\\u24C6\\uFF31\\uA756\\uA758\\u024A\",\n }, {\n base: 'R',\n chars: \"\\u24C7\\uFF32\\u0154\\u1E58\\u0158\\u0210\\u0212\\u1E5A\\u1E5C\\u0156\\u1E5E\\u024C\\u2C64\\uA75A\\uA7A6\\uA782\",\n }, {\n base: 'S',\n chars: \"\\u24C8\\uFF33\\u1E9E\\u015A\\u1E64\\u015C\\u1E60\\u0160\\u1E66\\u1E62\\u1E68\\u0218\\u015E\\u2C7E\\uA7A8\\uA784\",\n }, {\n base: 'T',\n chars: \"\\u24C9\\uFF34\\u1E6A\\u0164\\u1E6C\\u021A\\u0162\\u1E70\\u1E6E\\u0166\\u01AC\\u01AE\\u023E\\uA786\",\n }, {\n base: 'Th',\n chars: \"\\u00DE\",\n }, {\n base: 'TZ',\n chars: \"\\uA728\",\n }, {\n base: 'U',\n chars: \"\\u24CA\\uFF35\\xD9\\xDA\\xDB\\u0168\\u1E78\\u016A\\u1E7A\\u016C\\xDC\\u01DB\\u01D7\\u01D5\\u01D9\\u1EE6\\u016E\\u0170\\u01D3\\u0214\\u0216\\u01AF\\u1EEA\\u1EE8\\u1EEE\\u1EEC\\u1EF0\\u1EE4\\u1E72\\u0172\\u1E76\\u1E74\\u0244\",\n }, {\n base: 'V',\n chars: \"\\u24CB\\uFF36\\u1E7C\\u1E7E\\u01B2\\uA75E\\u0245\",\n }, {\n base: 'VY',\n chars: \"\\uA760\",\n }, {\n base: 'W',\n chars: \"\\u24CC\\uFF37\\u1E80\\u1E82\\u0174\\u1E86\\u1E84\\u1E88\\u2C72\",\n }, {\n base: 'X',\n chars: \"\\u24CD\\uFF38\\u1E8A\\u1E8C\",\n }, {\n base: 'Y',\n chars: \"\\u24CE\\uFF39\\u1EF2\\xDD\\u0176\\u1EF8\\u0232\\u1E8E\\u0178\\u1EF6\\u1EF4\\u01B3\\u024E\\u1EFE\",\n }, {\n base: 'Z',\n chars: \"\\u24CF\\uFF3A\\u0179\\u1E90\\u017B\\u017D\\u1E92\\u1E94\\u01B5\\u0224\\u2C7F\\u2C6B\\uA762\",\n }, {\n base: 'a',\n chars: \"\\u24D0\\uFF41\\u1E9A\\u00E0\\u00E1\\u00E2\\u1EA7\\u1EA5\\u1EAB\\u1EA9\\u00E3\\u0101\\u0103\\u1EB1\\u1EAF\\u1EB5\\u1EB3\\u0227\\u01E1\\u00E4\\u01DF\\u1EA3\\u00E5\\u01FB\\u01CE\\u0201\\u0203\\u1EA1\\u1EAD\\u1EB7\\u1E01\\u0105\\u2C65\\u0250\\u0251\",\n }, {\n base: 'aa',\n chars: \"\\uA733\",\n }, {\n base: 'ae',\n chars: \"\\u00E6\\u01FD\\u01E3\",\n }, {\n base: 'ao',\n chars: \"\\uA735\",\n }, {\n base: 'au',\n chars: \"\\uA737\",\n }, {\n base: 'av',\n chars: \"\\uA739\\uA73B\",\n }, {\n base: 'ay',\n chars: \"\\uA73D\",\n }, {\n base: 'b',\n chars: \"\\u24D1\\uFF42\\u1E03\\u1E05\\u1E07\\u0180\\u0183\\u0253\\u0182\",\n }, {\n base: 'c',\n chars: \"\\uFF43\\u24D2\\u0107\\u0109\\u010B\\u010D\\u00E7\\u1E09\\u0188\\u023C\\uA73F\\u2184\",\n }, {\n base: 'd',\n chars: \"\\u24D3\\uFF44\\u1E0B\\u010F\\u1E0D\\u1E11\\u1E13\\u1E0F\\u0111\\u018C\\u0256\\u0257\\u018B\\u13E7\\u0501\\uA7AA\",\n }, {\n base: 'dh',\n chars: \"\\u00F0\",\n }, {\n base: 'dz',\n chars: \"\\u01F3\\u01C6\",\n }, {\n base: 'e',\n chars: \"\\u24D4\\uFF45\\u00E8\\u00E9\\u00EA\\u1EC1\\u1EBF\\u1EC5\\u1EC3\\u1EBD\\u0113\\u1E15\\u1E17\\u0115\\u0117\\u00EB\\u1EBB\\u011B\\u0205\\u0207\\u1EB9\\u1EC7\\u0229\\u1E1D\\u0119\\u1E19\\u1E1B\\u0247\\u01DD\",\n }, {\n base: 'f',\n chars: \"\\u24D5\\uFF46\\u1E1F\\u0192\",\n }, {\n base: 'ff',\n chars: \"\\uFB00\",\n }, {\n base: 'fi',\n chars: \"\\uFB01\",\n }, {\n base: 'fl',\n chars: \"\\uFB02\",\n }, {\n base: 'ffi',\n chars: \"\\uFB03\",\n }, {\n base: 'ffl',\n chars: \"\\uFB04\",\n }, {\n base: 'g',\n chars: \"\\u24D6\\uFF47\\u01F5\\u011D\\u1E21\\u011F\\u0121\\u01E7\\u0123\\u01E5\\u0260\\uA7A1\\uA77F\\u1D79\",\n }, {\n base: 'h',\n chars: \"\\u24D7\\uFF48\\u0125\\u1E23\\u1E27\\u021F\\u1E25\\u1E29\\u1E2B\\u1E96\\u0127\\u2C68\\u2C76\\u0265\",\n }, {\n base: 'hv',\n chars: \"\\u0195\",\n }, {\n base: 'i',\n chars: \"\\u24D8\\uFF49\\xEC\\xED\\xEE\\u0129\\u012B\\u012D\\xEF\\u1E2F\\u1EC9\\u01D0\\u0209\\u020B\\u1ECB\\u012F\\u1E2D\\u0268\\u0131\",\n }, {\n base: 'j',\n chars: \"\\u24D9\\uFF4A\\u0135\\u01F0\\u0249\",\n }, {\n base: 'k',\n chars: \"\\u24DA\\uFF4B\\u1E31\\u01E9\\u1E33\\u0137\\u1E35\\u0199\\u2C6A\\uA741\\uA743\\uA745\\uA7A3\",\n }, {\n base: 'l',\n chars: \"\\u24DB\\uFF4C\\u0140\\u013A\\u013E\\u1E37\\u1E39\\u013C\\u1E3D\\u1E3B\\u017F\\u0142\\u019A\\u026B\\u2C61\\uA749\\uA781\\uA747\\u026D\",\n }, {\n base: 'lj',\n chars: \"\\u01C9\",\n }, {\n base: 'm',\n chars: \"\\u24DC\\uFF4D\\u1E3F\\u1E41\\u1E43\\u0271\\u026F\",\n }, {\n base: 'n',\n chars: \"\\u24DD\\uFF4E\\u01F9\\u0144\\xF1\\u1E45\\u0148\\u1E47\\u0146\\u1E4B\\u1E49\\u019E\\u0272\\u0149\\uA791\\uA7A5\\u043B\\u0509\",\n }, {\n base: 'nj',\n chars: \"\\u01CC\",\n }, {\n base: 'o',\n chars: \"\\u24DE\\uFF4F\\xF2\\xF3\\xF4\\u1ED3\\u1ED1\\u1ED7\\u1ED5\\xF5\\u1E4D\\u022D\\u1E4F\\u014D\\u1E51\\u1E53\\u014F\\u022F\\u0231\\xF6\\u022B\\u1ECF\\u0151\\u01D2\\u020D\\u020F\\u01A1\\u1EDD\\u1EDB\\u1EE1\\u1EDF\\u1EE3\\u1ECD\\u1ED9\\u01EB\\u01ED\\xF8\\u01FF\\uA74B\\uA74D\\u0275\\u0254\\u1D11\",\n }, {\n base: 'oe',\n chars: \"\\u0153\",\n }, {\n base: 'oi',\n chars: \"\\u01A3\",\n }, {\n base: 'oo',\n chars: \"\\uA74F\",\n }, {\n base: 'ou',\n chars: \"\\u0223\",\n }, {\n base: 'p',\n chars: \"\\u24DF\\uFF50\\u1E55\\u1E57\\u01A5\\u1D7D\\uA751\\uA753\\uA755\\u03C1\",\n }, {\n base: 'q',\n chars: \"\\u24E0\\uFF51\\u024B\\uA757\\uA759\",\n }, {\n base: 'r',\n chars: \"\\u24E1\\uFF52\\u0155\\u1E59\\u0159\\u0211\\u0213\\u1E5B\\u1E5D\\u0157\\u1E5F\\u024D\\u027D\\uA75B\\uA7A7\\uA783\",\n }, {\n base: 's',\n chars: \"\\u24E2\\uFF53\\u015B\\u1E65\\u015D\\u1E61\\u0161\\u1E67\\u1E63\\u1E69\\u0219\\u015F\\u023F\\uA7A9\\uA785\\u1E9B\\u0282\",\n }, {\n base: 'ss',\n chars: \"\\xDF\",\n }, {\n base: 't',\n chars: \"\\u24E3\\uFF54\\u1E6B\\u1E97\\u0165\\u1E6D\\u021B\\u0163\\u1E71\\u1E6F\\u0167\\u01AD\\u0288\\u2C66\\uA787\",\n }, {\n base: 'th',\n chars: \"\\u00FE\",\n }, {\n base: 'tz',\n chars: \"\\uA729\",\n }, {\n base: 'u',\n chars: \"\\u24E4\\uFF55\\xF9\\xFA\\xFB\\u0169\\u1E79\\u016B\\u1E7B\\u016D\\xFC\\u01DC\\u01D8\\u01D6\\u01DA\\u1EE7\\u016F\\u0171\\u01D4\\u0215\\u0217\\u01B0\\u1EEB\\u1EE9\\u1EEF\\u1EED\\u1EF1\\u1EE5\\u1E73\\u0173\\u1E77\\u1E75\\u0289\",\n }, {\n base: 'v',\n chars: \"\\u24E5\\uFF56\\u1E7D\\u1E7F\\u028B\\uA75F\\u028C\",\n }, {\n base: 'vy',\n chars: \"\\uA761\",\n }, {\n base: 'w',\n chars: \"\\u24E6\\uFF57\\u1E81\\u1E83\\u0175\\u1E87\\u1E85\\u1E98\\u1E89\\u2C73\",\n }, {\n base: 'x',\n chars: \"\\u24E7\\uFF58\\u1E8B\\u1E8D\",\n }, {\n base: 'y',\n chars: \"\\u24E8\\uFF59\\u1EF3\\xFD\\u0177\\u1EF9\\u0233\\u1E8F\\xFF\\u1EF7\\u1E99\\u1EF5\\u01B4\\u024F\\u1EFF\",\n }, {\n base: 'z',\n chars: \"\\u24E9\\uFF5A\\u017A\\u1E91\\u017C\\u017E\\u1E93\\u1E95\\u01B6\\u0225\\u0240\\u2C6C\\uA763\",\n }\n];\n\nvar diacriticsMap = {};\nfor (var i = 0; i < replacementList.length; i += 1) {\n var chars = replacementList[i].chars;\n for (var j = 0; j < chars.length; j += 1) {\n diacriticsMap[chars[j]] = replacementList[i].base;\n }\n}\n\nfunction removeDiacritics(str) {\n return str.replace(/[^\\u0000-\\u007e]/g, function(c) {\n return diacriticsMap[c] || c;\n });\n}\n\nexports.replacementList = replacementList;\nexports.diacriticsMap = diacriticsMap;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst arabicBlocks = [\n [0x0600, 0x06FF],\n [0x0750, 0x077F],\n [0x08A0, 0x08FF],\n [0xFB50, 0xFDFF],\n [0xFE70, 0xFEFF],\n [0x10E60, 0x10E7F],\n [0x1EC70, 0x1ECBF],\n [0x1EE00, 0x1EEFF] // Mathematical Alphabetic symbols https://www.unicode.org/charts/PDF/U1EE00.pdf\n];\nfunction isArabic(char) {\n if (char.length > 1) {\n // allow the newer chars?\n throw new Error('isArabic works on only one-character strings');\n }\n let code = char.charCodeAt(0);\n for (let i = 0; i < arabicBlocks.length; i++) {\n let block = arabicBlocks[i];\n if (code >= block[0] && code <= block[1]) {\n return true;\n }\n }\n return false;\n}\nexports.isArabic = isArabic;\nfunction isMath(char) {\n if (char.length > 2) {\n // allow the newer chars?\n throw new Error('isMath works on only one-character strings');\n }\n let code = char.charCodeAt(0);\n return ((code >= 0x660 && code <= 0x66C) || (code >= 0x6F0 && code <= 0x6F9));\n}\nexports.isMath = isMath;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst arabicReference = {\n \"alef\": {\n \"normal\": [\n \"\\u0627\"\n ],\n \"madda_above\": {\n \"normal\": [\n \"\\u0627\\u0653\",\n \"\\u0622\"\n ],\n \"isolated\": \"\\uFE81\",\n \"final\": \"\\uFE82\"\n },\n \"hamza_above\": {\n \"normal\": [\n \"\\u0627\\u0654\",\n \"\\u0623\"\n ],\n \"isolated\": \"\\uFE83\",\n \"final\": \"\\uFE84\"\n },\n \"hamza_below\": {\n \"normal\": [\n \"\\u0627\\u0655\",\n \"\\u0625\"\n ],\n \"isolated\": \"\\uFE87\",\n \"final\": \"\\uFE88\"\n },\n \"wasla\": {\n \"normal\": \"\\u0671\",\n \"isolated\": \"\\uFB50\",\n \"final\": \"\\uFB51\"\n },\n \"wavy_hamza_above\": [\n \"\\u0672\"\n ],\n \"wavy_hamza_below\": [\n \"\\u0627\\u065F\",\n \"\\u0673\"\n ],\n \"high_hamza\": [\n \"\\u0675\",\n \"\\u0627\\u0674\"\n ],\n \"indic_two_above\": [\n \"\\u0773\"\n ],\n \"indic_three_above\": [\n \"\\u0774\"\n ],\n \"fathatan\": {\n \"normal\": [\n \"\\u0627\\u064B\"\n ],\n \"final\": \"\\uFD3C\",\n \"isolated\": \"\\uFD3D\"\n },\n \"isolated\": \"\\uFE8D\",\n \"final\": \"\\uFE8E\"\n },\n \"beh\": {\n \"normal\": [\n \"\\u0628\"\n ],\n \"dotless\": [\n \"\\u066E\"\n ],\n \"three_dots_horizontally_below\": [\n \"\\u0750\"\n ],\n \"dot_below_three_dots_above\": [\n \"\\u0751\"\n ],\n \"three_dots_pointing_upwards_below\": [\n \"\\u0752\"\n ],\n \"three_dots_pointing_upwards_below_two_dots_above\": [\n \"\\u0753\"\n ],\n \"two_dots_below_dot_above\": [\n \"\\u0754\"\n ],\n \"inverted_small_v_below\": [\n \"\\u0755\"\n ],\n \"small_v\": [\n \"\\u0756\"\n ],\n \"small_v_below\": [\n \"\\u08A0\"\n ],\n \"hamza_above\": [\n \"\\u08A1\"\n ],\n \"small_meem_above\": [\n \"\\u08B6\"\n ],\n \"isolated\": \"\\uFE8F\",\n \"final\": \"\\uFE90\",\n \"initial\": \"\\uFE91\",\n \"medial\": \"\\uFE92\"\n },\n \"teh marbuta\": {\n \"normal\": [\n \"\\u0629\"\n ],\n \"isolated\": \"\\uFE93\",\n \"final\": \"\\uFE94\"\n },\n \"teh\": {\n \"normal\": [\n \"\\u062A\"\n ],\n \"ring\": [\n \"\\u067C\"\n ],\n \"three_dots_above_downwards\": [\n \"\\u067D\"\n ],\n \"small_teh_above\": [\n \"\\u08B8\"\n ],\n \"isolated\": \"\\uFE95\",\n \"final\": \"\\uFE96\",\n \"initial\": \"\\uFE97\",\n \"medial\": \"\\uFE98\"\n },\n \"theh\": {\n \"normal\": [\n \"\\u062B\"\n ],\n \"isolated\": \"\\uFE99\",\n \"final\": \"\\uFE9A\",\n \"initial\": \"\\uFE9B\",\n \"medial\": \"\\uFE9C\"\n },\n \"jeem\": {\n \"normal\": [\n \"\\u062C\"\n ],\n \"two_dots_above\": [\n \"\\u08A2\"\n ],\n \"isolated\": \"\\uFE9D\",\n \"final\": \"\\uFE9E\",\n \"initial\": \"\\uFE9F\",\n \"medial\": \"\\uFEA0\"\n },\n \"hah\": {\n \"normal\": [\n \"\\u062D\"\n ],\n \"hamza_above\": [\n \"\\u0681\"\n ],\n \"two_dots_vertical_above\": [\n \"\\u0682\"\n ],\n \"three_dots_above\": [\n \"\\u0685\"\n ],\n \"two_dots_above\": [\n \"\\u0757\"\n ],\n \"three_dots_pointing_upwards_below\": [\n \"\\u0758\"\n ],\n \"small_tah_below\": [\n \"\\u076E\"\n ],\n \"small_tah_two_dots\": [\n \"\\u076F\"\n ],\n \"small_tah_above\": [\n \"\\u0772\"\n ],\n \"indic_four_below\": [\n \"\\u077C\"\n ],\n \"isolated\": \"\\uFEA1\",\n \"final\": \"\\uFEA2\",\n \"initial\": \"\\uFEA3\",\n \"medial\": \"\\uFEA4\"\n },\n \"khah\": {\n \"normal\": [\n \"\\u062E\"\n ],\n \"isolated\": \"\\uFEA5\",\n \"final\": \"\\uFEA6\",\n \"initial\": \"\\uFEA7\",\n \"medial\": \"\\uFEA8\"\n },\n \"dal\": {\n \"normal\": [\n \"\\u062F\"\n ],\n \"ring\": [\n \"\\u0689\"\n ],\n \"dot_below\": [\n \"\\u068A\"\n ],\n \"dot_below_small_tah\": [\n \"\\u068B\"\n ],\n \"three_dots_above_downwards\": [\n \"\\u068F\"\n ],\n \"four_dots_above\": [\n \"\\u0690\"\n ],\n \"inverted_v\": [\n \"\\u06EE\"\n ],\n \"two_dots_vertically_below_small_tah\": [\n \"\\u0759\"\n ],\n \"inverted_small_v_below\": [\n \"\\u075A\"\n ],\n \"three_dots_below\": [\n \"\\u08AE\"\n ],\n \"isolated\": \"\\uFEA9\",\n \"final\": \"\\uFEAA\"\n },\n \"thal\": {\n \"normal\": [\n \"\\u0630\"\n ],\n \"isolated\": \"\\uFEAB\",\n \"final\": \"\\uFEAC\"\n },\n \"reh\": {\n \"normal\": [\n \"\\u0631\"\n ],\n \"small_v\": [\n \"\\u0692\"\n ],\n \"ring\": [\n \"\\u0693\"\n ],\n \"dot_below\": [\n \"\\u0694\"\n ],\n \"small_v_below\": [\n \"\\u0695\"\n ],\n \"dot_below_dot_above\": [\n \"\\u0696\"\n ],\n \"two_dots_above\": [\n \"\\u0697\"\n ],\n \"four_dots_above\": [\n \"\\u0699\"\n ],\n \"inverted_v\": [\n \"\\u06EF\"\n ],\n \"stroke\": [\n \"\\u075B\"\n ],\n \"two_dots_vertically_above\": [\n \"\\u076B\"\n ],\n \"hamza_above\": [\n \"\\u076C\"\n ],\n \"small_tah_two_dots\": [\n \"\\u0771\"\n ],\n \"loop\": [\n \"\\u08AA\"\n ],\n \"small_noon_above\": [\n \"\\u08B9\"\n ],\n \"isolated\": \"\\uFEAD\",\n \"final\": \"\\uFEAE\"\n },\n \"zain\": {\n \"normal\": [\n \"\\u0632\"\n ],\n \"inverted_v_above\": [\n \"\\u08B2\"\n ],\n \"isolated\": \"\\uFEAF\",\n \"final\": \"\\uFEB0\"\n },\n \"seen\": {\n \"normal\": [\n \"\\u0633\"\n ],\n \"dot_below_dot_above\": [\n \"\\u069A\"\n ],\n \"three_dots_below\": [\n \"\\u069B\"\n ],\n \"three_dots_below_three_dots_above\": [\n \"\\u069C\"\n ],\n \"four_dots_above\": [\n \"\\u075C\"\n ],\n \"two_dots_vertically_above\": [\n \"\\u076D\"\n ],\n \"small_tah_two_dots\": [\n \"\\u0770\"\n ],\n \"indic_four_above\": [\n \"\\u077D\"\n ],\n \"inverted_v\": [\n \"\\u077E\"\n ],\n \"isolated\": \"\\uFEB1\",\n \"final\": \"\\uFEB2\",\n \"initial\": \"\\uFEB3\",\n \"medial\": \"\\uFEB4\"\n },\n \"sheen\": {\n \"normal\": [\n \"\\u0634\"\n ],\n \"dot_below\": [\n \"\\u06FA\"\n ],\n \"isolated\": \"\\uFEB5\",\n \"final\": \"\\uFEB6\",\n \"initial\": \"\\uFEB7\",\n \"medial\": \"\\uFEB8\"\n },\n \"sad\": {\n \"normal\": [\n \"\\u0635\"\n ],\n \"two_dots_below\": [\n \"\\u069D\"\n ],\n \"three_dots_above\": [\n \"\\u069E\"\n ],\n \"three_dots_below\": [\n \"\\u08AF\"\n ],\n \"isolated\": \"\\uFEB9\",\n \"final\": \"\\uFEBA\",\n \"initial\": \"\\uFEBB\",\n \"medial\": \"\\uFEBC\"\n },\n \"dad\": {\n \"normal\": [\n \"\\u0636\"\n ],\n \"dot_below\": [\n \"\\u06FB\"\n ],\n \"isolated\": \"\\uFEBD\",\n \"final\": \"\\uFEBE\",\n \"initial\": \"\\uFEBF\",\n \"medial\": \"\\uFEC0\"\n },\n \"tah\": {\n \"normal\": [\n \"\\u0637\"\n ],\n \"three_dots_above\": [\n \"\\u069F\"\n ],\n \"two_dots_above\": [\n \"\\u08A3\"\n ],\n \"isolated\": \"\\uFEC1\",\n \"final\": \"\\uFEC2\",\n \"initial\": \"\\uFEC3\",\n \"medial\": \"\\uFEC4\"\n },\n \"zah\": {\n \"normal\": [\n \"\\u0638\"\n ],\n \"isolated\": \"\\uFEC5\",\n \"final\": \"\\uFEC6\",\n \"initial\": \"\\uFEC7\",\n \"medial\": \"\\uFEC8\"\n },\n \"ain\": {\n \"normal\": [\n \"\\u0639\"\n ],\n \"three_dots_above\": [\n \"\\u06A0\"\n ],\n \"two_dots_above\": [\n \"\\u075D\"\n ],\n \"three_dots_pointing_downwards_above\": [\n \"\\u075E\"\n ],\n \"two_dots_vertically_above\": [\n \"\\u075F\"\n ],\n \"three_dots_below\": [\n \"\\u08B3\"\n ],\n \"isolated\": \"\\uFEC9\",\n \"final\": \"\\uFECA\",\n \"initial\": \"\\uFECB\",\n \"medial\": \"\\uFECC\"\n },\n \"ghain\": {\n \"normal\": [\n \"\\u063A\"\n ],\n \"dot_below\": [\n \"\\u06FC\"\n ],\n \"isolated\": \"\\uFECD\",\n \"final\": \"\\uFECE\",\n \"initial\": \"\\uFECF\",\n \"medial\": \"\\uFED0\"\n },\n \"feh\": {\n \"normal\": [\n \"\\u0641\"\n ],\n \"dotless\": [\n \"\\u06A1\"\n ],\n \"dot_moved_below\": [\n \"\\u06A2\"\n ],\n \"dot_below\": [\n \"\\u06A3\"\n ],\n \"three_dots_below\": [\n \"\\u06A5\"\n ],\n \"two_dots_below\": [\n \"\\u0760\"\n ],\n \"three_dots_pointing_upwards_below\": [\n \"\\u0761\"\n ],\n \"dot_below_three_dots_above\": [\n \"\\u08A4\"\n ],\n \"isolated\": \"\\uFED1\",\n \"final\": \"\\uFED2\",\n \"initial\": \"\\uFED3\",\n \"medial\": \"\\uFED4\"\n },\n \"qaf\": {\n \"normal\": [\n \"\\u0642\"\n ],\n \"dotless\": [\n \"\\u066F\"\n ],\n \"dot_above\": [\n \"\\u06A7\"\n ],\n \"three_dots_above\": [\n \"\\u06A8\"\n ],\n \"dot_below\": [\n \"\\u08A5\"\n ],\n \"isolated\": \"\\uFED5\",\n \"final\": \"\\uFED6\",\n \"initial\": \"\\uFED7\",\n \"medial\": \"\\uFED8\"\n },\n \"kaf\": {\n \"normal\": [\n \"\\u0643\"\n ],\n \"swash\": [\n \"\\u06AA\"\n ],\n \"ring\": [\n \"\\u06AB\"\n ],\n \"dot_above\": [\n \"\\u06AC\"\n ],\n \"three_dots_below\": [\n \"\\u06AE\"\n ],\n \"two_dots_above\": [\n \"\\u077F\"\n ],\n \"dot_below\": [\n \"\\u08B4\"\n ],\n \"isolated\": \"\\uFED9\",\n \"final\": \"\\uFEDA\",\n \"initial\": \"\\uFEDB\",\n \"medial\": \"\\uFEDC\"\n },\n \"lam\": {\n \"normal\": [\n \"\\u0644\"\n ],\n \"small_v\": [\n \"\\u06B5\"\n ],\n \"dot_above\": [\n \"\\u06B6\"\n ],\n \"three_dots_above\": [\n \"\\u06B7\"\n ],\n \"three_dots_below\": [\n \"\\u06B8\"\n ],\n \"bar\": [\n \"\\u076A\"\n ],\n \"double_bar\": [\n \"\\u08A6\"\n ],\n \"isolated\": \"\\uFEDD\",\n \"final\": \"\\uFEDE\",\n \"initial\": \"\\uFEDF\",\n \"medial\": \"\\uFEE0\"\n },\n \"meem\": {\n \"normal\": [\n \"\\u0645\"\n ],\n \"dot_above\": [\n \"\\u0765\"\n ],\n \"dot_below\": [\n \"\\u0766\"\n ],\n \"three_dots_above\": [\n \"\\u08A7\"\n ],\n \"isolated\": \"\\uFEE1\",\n \"final\": \"\\uFEE2\",\n \"initial\": \"\\uFEE3\",\n \"medial\": \"\\uFEE4\"\n },\n \"noon\": {\n \"normal\": [\n \"\\u0646\"\n ],\n \"dot_below\": [\n \"\\u06B9\"\n ],\n \"ring\": [\n \"\\u06BC\"\n ],\n \"three_dots_above\": [\n \"\\u06BD\"\n ],\n \"two_dots_below\": [\n \"\\u0767\"\n ],\n \"small_tah\": [\n \"\\u0768\"\n ],\n \"small_v\": [\n \"\\u0769\"\n ],\n \"isolated\": \"\\uFEE5\",\n \"final\": \"\\uFEE6\",\n \"initial\": \"\\uFEE7\",\n \"medial\": \"\\uFEE8\"\n },\n \"heh\": {\n \"normal\": [\n \"\\u0647\"\n ],\n \"isolated\": \"\\uFEE9\",\n \"final\": \"\\uFEEA\",\n \"initial\": \"\\uFEEB\",\n \"medial\": \"\\uFEEC\"\n },\n \"waw\": {\n \"normal\": [\n \"\\u0648\"\n ],\n \"hamza_above\": {\n \"normal\": [\n \"\\u0624\",\n \"\\u0648\\u0654\"\n ],\n \"isolated\": \"\\uFE85\",\n \"final\": \"\\uFE86\"\n },\n \"high_hamza\": [\n \"\\u0676\",\n \"\\u0648\\u0674\"\n ],\n \"ring\": [\n \"\\u06C4\"\n ],\n \"two_dots_above\": [\n \"\\u06CA\"\n ],\n \"dot_above\": [\n \"\\u06CF\"\n ],\n \"indic_two_above\": [\n \"\\u0778\"\n ],\n \"indic_three_above\": [\n \"\\u0779\"\n ],\n \"dot_within\": [\n \"\\u08AB\"\n ],\n \"isolated\": \"\\uFEED\",\n \"final\": \"\\uFEEE\"\n },\n \"alef_maksura\": {\n \"normal\": [\n \"\\u0649\"\n ],\n \"hamza_above\": [\n \"\\u0626\",\n \"\\u064A\\u0654\"\n ],\n \"initial\": \"\\uFBE8\",\n \"medial\": \"\\uFBE9\",\n \"isolated\": \"\\uFEEF\",\n \"final\": \"\\uFEF0\"\n },\n \"yeh\": {\n \"normal\": [\n \"\\u064A\"\n ],\n \"hamza_above\": {\n \"normal\": [\n \"\\u0626\",\n \"\\u0649\\u0654\"\n ],\n \"isolated\": \"\\uFE89\",\n \"final\": \"\\uFE8A\",\n \"initial\": \"\\uFE8B\",\n \"medial\": \"\\uFE8C\"\n },\n \"two_dots_below_hamza_above\": [\n \"\\u08A8\"\n ],\n \"high_hamza\": [\n \"\\u0678\",\n \"\\u064A\\u0674\"\n ],\n \"tail\": [\n \"\\u06CD\"\n ],\n \"small_v\": [\n \"\\u06CE\"\n ],\n \"three_dots_below\": [\n \"\\u06D1\"\n ],\n \"two_dots_below_dot_above\": [\n \"\\u08A9\"\n ],\n \"two_dots_below_small_noon_above\": [\n \"\\u08BA\"\n ],\n \"isolated\": \"\\uFEF1\",\n \"final\": \"\\uFEF2\",\n \"initial\": \"\\uFEF3\",\n \"medial\": \"\\uFEF4\"\n },\n \"tteh\": {\n \"normal\": [\n \"\\u0679\"\n ],\n \"isolated\": \"\\uFB66\",\n \"final\": \"\\uFB67\",\n \"initial\": \"\\uFB68\",\n \"medial\": \"\\uFB69\"\n },\n \"tteheh\": {\n \"normal\": [\n \"\\u067A\"\n ],\n \"isolated\": \"\\uFB5E\",\n \"final\": \"\\uFB5F\",\n \"initial\": \"\\uFB60\",\n \"medial\": \"\\uFB61\"\n },\n \"beeh\": {\n \"normal\": [\n \"\\u067B\"\n ],\n \"isolated\": \"\\uFB52\",\n \"final\": \"\\uFB53\",\n \"initial\": \"\\uFB54\",\n \"medial\": \"\\uFB55\"\n },\n \"peh\": {\n \"normal\": [\n \"\\u067E\"\n ],\n \"small_meem_above\": [\n \"\\u08B7\"\n ],\n \"isolated\": \"\\uFB56\",\n \"final\": \"\\uFB57\",\n \"initial\": \"\\uFB58\",\n \"medial\": \"\\uFB59\"\n },\n \"teheh\": {\n \"normal\": [\n \"\\u067F\"\n ],\n \"isolated\": \"\\uFB62\",\n \"final\": \"\\uFB63\",\n \"initial\": \"\\uFB64\",\n \"medial\": \"\\uFB65\"\n },\n \"beheh\": {\n \"normal\": [\n \"\\u0680\"\n ],\n \"isolated\": \"\\uFB5A\",\n \"final\": \"\\uFB5B\",\n \"initial\": \"\\uFB5C\",\n \"medial\": \"\\uFB5D\"\n },\n \"nyeh\": {\n \"normal\": [\n \"\\u0683\"\n ],\n \"isolated\": \"\\uFB76\",\n \"final\": \"\\uFB77\",\n \"initial\": \"\\uFB78\",\n \"medial\": \"\\uFB79\"\n },\n \"dyeh\": {\n \"normal\": [\n \"\\u0684\"\n ],\n \"isolated\": \"\\uFB72\",\n \"final\": \"\\uFB73\",\n \"initial\": \"\\uFB74\",\n \"medial\": \"\\uFB75\"\n },\n \"tcheh\": {\n \"normal\": [\n \"\\u0686\"\n ],\n \"dot_above\": [\n \"\\u06BF\"\n ],\n \"isolated\": \"\\uFB7A\",\n \"final\": \"\\uFB7B\",\n \"initial\": \"\\uFB7C\",\n \"medial\": \"\\uFB7D\"\n },\n \"tcheheh\": {\n \"normal\": [\n \"\\u0687\"\n ],\n \"isolated\": \"\\uFB7E\",\n \"final\": \"\\uFB7F\",\n \"initial\": \"\\uFB80\",\n \"medial\": \"\\uFB81\"\n },\n \"ddal\": {\n \"normal\": [\n \"\\u0688\"\n ],\n \"isolated\": \"\\uFB88\",\n \"final\": \"\\uFB89\"\n },\n \"dahal\": {\n \"normal\": [\n \"\\u068C\"\n ],\n \"isolated\": \"\\uFB84\",\n \"final\": \"\\uFB85\"\n },\n \"ddahal\": {\n \"normal\": [\n \"\\u068D\"\n ],\n \"isolated\": \"\\uFB82\",\n \"final\": \"\\uFB83\"\n },\n \"dul\": {\n \"normal\": [\n \"\\u068F\",\n \"\\u068E\"\n ],\n \"isolated\": \"\\uFB86\",\n \"final\": \"\\uFB87\"\n },\n \"rreh\": {\n \"normal\": [\n \"\\u0691\"\n ],\n \"isolated\": \"\\uFB8C\",\n \"final\": \"\\uFB8D\"\n },\n \"jeh\": {\n \"normal\": [\n \"\\u0698\"\n ],\n \"isolated\": \"\\uFB8A\",\n \"final\": \"\\uFB8B\"\n },\n \"veh\": {\n \"normal\": [\n \"\\u06A4\"\n ],\n \"isolated\": \"\\uFB6A\",\n \"final\": \"\\uFB6B\",\n \"initial\": \"\\uFB6C\",\n \"medial\": \"\\uFB6D\"\n },\n \"peheh\": {\n \"normal\": [\n \"\\u06A6\"\n ],\n \"isolated\": \"\\uFB6E\",\n \"final\": \"\\uFB6F\",\n \"initial\": \"\\uFB70\",\n \"medial\": \"\\uFB71\"\n },\n \"keheh\": {\n \"normal\": [\n \"\\u06A9\"\n ],\n \"dot_above\": [\n \"\\u0762\"\n ],\n \"three_dots_above\": [\n \"\\u0763\"\n ],\n \"three_dots_pointing_upwards_below\": [\n \"\\u0764\"\n ],\n \"isolated\": \"\\uFB8E\",\n \"final\": \"\\uFB8F\",\n \"initial\": \"\\uFB90\",\n \"medial\": \"\\uFB91\"\n },\n \"ng\": {\n \"normal\": [\n \"\\u06AD\"\n ],\n \"isolated\": \"\\uFBD3\",\n \"final\": \"\\uFBD4\",\n \"initial\": \"\\uFBD5\",\n \"medial\": \"\\uFBD6\"\n },\n \"gaf\": {\n \"normal\": [\n \"\\u06AF\"\n ],\n \"ring\": [\n \"\\u06B0\"\n ],\n \"two_dots_below\": [\n \"\\u06B2\"\n ],\n \"three_dots_above\": [\n \"\\u06B4\"\n ],\n \"inverted_stroke\": [\n \"\\u08B0\"\n ],\n \"isolated\": \"\\uFB92\",\n \"final\": \"\\uFB93\",\n \"initial\": \"\\uFB94\",\n \"medial\": \"\\uFB95\"\n },\n \"ngoeh\": {\n \"normal\": [\n \"\\u06B1\"\n ],\n \"isolated\": \"\\uFB9A\",\n \"final\": \"\\uFB9B\",\n \"initial\": \"\\uFB9C\",\n \"medial\": \"\\uFB9D\"\n },\n \"gueh\": {\n \"normal\": [\n \"\\u06B3\"\n ],\n \"isolated\": \"\\uFB96\",\n \"final\": \"\\uFB97\",\n \"initial\": \"\\uFB98\",\n \"medial\": \"\\uFB99\"\n },\n \"noon ghunna\": {\n \"normal\": [\n \"\\u06BA\"\n ],\n \"isolated\": \"\\uFB9E\",\n \"final\": \"\\uFB9F\"\n },\n \"rnoon\": {\n \"normal\": [\n \"\\u06BB\"\n ],\n \"isolated\": \"\\uFBA0\",\n \"final\": \"\\uFBA1\",\n \"initial\": \"\\uFBA2\",\n \"medial\": \"\\uFBA3\"\n },\n \"heh doachashmee\": {\n \"normal\": [\n \"\\u06BE\"\n ],\n \"isolated\": \"\\uFBAA\",\n \"final\": \"\\uFBAB\",\n \"initial\": \"\\uFBAC\",\n \"medial\": \"\\uFBAD\"\n },\n \"heh goal\": {\n \"normal\": [\n \"\\u06C1\"\n ],\n \"hamza_above\": [\n \"\\u06C1\\u0654\",\n \"\\u06C2\"\n ],\n \"isolated\": \"\\uFBA6\",\n \"final\": \"\\uFBA7\",\n \"initial\": \"\\uFBA8\",\n \"medial\": \"\\uFBA9\"\n },\n \"teh marbuta goal\": {\n \"normal\": [\n \"\\u06C3\"\n ]\n },\n \"kirghiz oe\": {\n \"normal\": [\n \"\\u06C5\"\n ],\n \"isolated\": \"\\uFBE0\",\n \"final\": \"\\uFBE1\"\n },\n \"oe\": {\n \"normal\": [\n \"\\u06C6\"\n ],\n \"isolated\": \"\\uFBD9\",\n \"final\": \"\\uFBDA\"\n },\n \"u\": {\n \"normal\": [\n \"\\u06C7\"\n ],\n \"hamza_above\": {\n \"normal\": [\n \"\\u0677\",\n \"\\u06C7\\u0674\"\n ],\n \"isolated\": \"\\uFBDD\"\n },\n \"isolated\": \"\\uFBD7\",\n \"final\": \"\\uFBD8\"\n },\n \"yu\": {\n \"normal\": [\n \"\\u06C8\"\n ],\n \"isolated\": \"\\uFBDB\",\n \"final\": \"\\uFBDC\"\n },\n \"kirghiz yu\": {\n \"normal\": [\n \"\\u06C9\"\n ],\n \"isolated\": \"\\uFBE2\",\n \"final\": \"\\uFBE3\"\n },\n \"ve\": {\n \"normal\": [\n \"\\u06CB\"\n ],\n \"isolated\": \"\\uFBDE\",\n \"final\": \"\\uFBDF\"\n },\n \"farsi yeh\": {\n \"normal\": [\n \"\\u06CC\"\n ],\n \"indic_two_above\": [\n \"\\u0775\"\n ],\n \"indic_three_above\": [\n \"\\u0776\"\n ],\n \"indic_four_above\": [\n \"\\u0777\"\n ],\n \"isolated\": \"\\uFBFC\",\n \"final\": \"\\uFBFD\",\n \"initial\": \"\\uFBFE\",\n \"medial\": \"\\uFBFF\"\n },\n \"e\": {\n \"normal\": [\n \"\\u06D0\"\n ],\n \"isolated\": \"\\uFBE4\",\n \"final\": \"\\uFBE5\",\n \"initial\": \"\\uFBE6\",\n \"medial\": \"\\uFBE7\"\n },\n \"yeh barree\": {\n \"normal\": [\n \"\\u06D2\"\n ],\n \"hamza_above\": {\n \"normal\": [\n \"\\u06D2\\u0654\",\n \"\\u06D3\"\n ],\n \"isolated\": \"\\uFBB0\",\n \"final\": \"\\uFBB1\"\n },\n \"indic_two_above\": [\n \"\\u077A\"\n ],\n \"indic_three_above\": [\n \"\\u077B\"\n ],\n \"isolated\": \"\\uFBAE\",\n \"final\": \"\\uFBAF\"\n },\n \"ae\": {\n \"normal\": [\n \"\\u06D5\"\n ],\n \"isolated\": \"\\u06D5\",\n \"final\": \"\\uFEEA\",\n \"yeh_above\": {\n \"normal\": [\n \"\\u06C0\",\n \"\\u06D5\\u0654\"\n ],\n \"isolated\": \"\\uFBA4\",\n \"final\": \"\\uFBA5\"\n }\n },\n \"rohingya yeh\": {\n \"normal\": [\n \"\\u08AC\"\n ]\n },\n \"low alef\": {\n \"normal\": [\n \"\\u08AD\"\n ]\n },\n \"straight waw\": {\n \"normal\": [\n \"\\u08B1\"\n ]\n },\n \"african feh\": {\n \"normal\": [\n \"\\u08BB\"\n ]\n },\n \"african qaf\": {\n \"normal\": [\n \"\\u08BC\"\n ]\n },\n \"african noon\": {\n \"normal\": [\n \"\\u08BD\"\n ]\n }\n};\nexports.default = arabicReference;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst ligatureReference = {\n \"\\u0626\\u0627\": {\n \"isolated\": \"\\uFBEA\",\n \"final\": \"\\uFBEB\"\n },\n \"\\u0626\\u06D5\": {\n \"isolated\": \"\\uFBEC\",\n \"final\": \"\\uFBED\"\n },\n \"\\u0626\\u0648\": {\n \"isolated\": \"\\uFBEE\",\n \"final\": \"\\uFBEF\"\n },\n \"\\u0626\\u06C7\": {\n \"isolated\": \"\\uFBF0\",\n \"final\": \"\\uFBF1\"\n },\n \"\\u0626\\u06C6\": {\n \"isolated\": \"\\uFBF2\",\n \"final\": \"\\uFBF3\"\n },\n \"\\u0626\\u06C8\": {\n \"isolated\": \"\\uFBF4\",\n \"final\": \"\\uFBF5\"\n },\n \"\\u0626\\u06D0\": {\n \"isolated\": \"\\uFBF6\",\n \"final\": \"\\uFBF7\",\n \"initial\": \"\\uFBF8\"\n },\n \"\\u0626\\u0649\": {\n \"uighur_kirghiz\": {\n \"isolated\": \"\\uFBF9\",\n \"final\": \"\\uFBFA\",\n \"initial\": \"\\uFBFB\"\n },\n \"isolated\": \"\\uFC03\",\n \"final\": \"\\uFC68\"\n },\n \"\\u0626\\u062C\": {\n \"isolated\": \"\\uFC00\",\n \"initial\": \"\\uFC97\"\n },\n \"\\u0626\\u062D\": {\n \"isolated\": \"\\uFC01\",\n \"initial\": \"\\uFC98\"\n },\n \"\\u0626\\u0645\": {\n \"isolated\": \"\\uFC02\",\n \"final\": \"\\uFC66\",\n \"initial\": \"\\uFC9A\",\n \"medial\": \"\\uFCDF\"\n },\n \"\\u0626\\u064A\": {\n \"isolated\": \"\\uFC04\",\n \"final\": \"\\uFC69\"\n },\n \"\\u0628\\u062C\": {\n \"isolated\": \"\\uFC05\",\n \"initial\": \"\\uFC9C\"\n },\n \"\\u0628\\u062D\": {\n \"isolated\": \"\\uFC06\",\n \"initial\": \"\\uFC9D\"\n },\n \"\\u0628\\u062E\": {\n \"isolated\": \"\\uFC07\",\n \"initial\": \"\\uFC9E\"\n },\n \"\\u0628\\u0645\": {\n \"isolated\": \"\\uFC08\",\n \"final\": \"\\uFC6C\",\n \"initial\": \"\\uFC9F\",\n \"medial\": \"\\uFCE1\"\n },\n \"\\u0628\\u0649\": {\n \"isolated\": \"\\uFC09\",\n \"final\": \"\\uFC6E\"\n },\n \"\\u0628\\u064A\": {\n \"isolated\": \"\\uFC0A\",\n \"final\": \"\\uFC6F\"\n },\n \"\\u062A\\u062C\": {\n \"isolated\": \"\\uFC0B\",\n \"initial\": \"\\uFCA1\"\n },\n \"\\u062A\\u062D\": {\n \"isolated\": \"\\uFC0C\",\n \"initial\": \"\\uFCA2\"\n },\n \"\\u062A\\u062E\": {\n \"isolated\": \"\\uFC0D\",\n \"initial\": \"\\uFCA3\"\n },\n \"\\u062A\\u0645\": {\n \"isolated\": \"\\uFC0E\",\n \"final\": \"\\uFC72\",\n \"initial\": \"\\uFCA4\",\n \"medial\": \"\\uFCE3\"\n },\n \"\\u062A\\u0649\": {\n \"isolated\": \"\\uFC0F\",\n \"final\": \"\\uFC74\"\n },\n \"\\u062A\\u064A\": {\n \"isolated\": \"\\uFC10\",\n \"final\": \"\\uFC75\"\n },\n \"\\u062B\\u062C\": {\n \"isolated\": \"\\uFC11\"\n },\n \"\\u062B\\u0645\": {\n \"isolated\": \"\\uFC12\",\n \"final\": \"\\uFC78\",\n \"initial\": \"\\uFCA6\",\n \"medial\": \"\\uFCE5\"\n },\n \"\\u062B\\u0649\": {\n \"isolated\": \"\\uFC13\",\n \"final\": \"\\uFC7A\"\n },\n \"\\u062B\\u0648\": {\n \"isolated\": \"\\uFC14\"\n },\n \"\\u062C\\u062D\": {\n \"isolated\": \"\\uFC15\",\n \"initial\": \"\\uFCA7\"\n },\n \"\\u062C\\u0645\": {\n \"isolated\": \"\\uFC16\",\n \"initial\": \"\\uFCA8\"\n },\n \"\\u062D\\u062C\": {\n \"isolated\": \"\\uFC17\",\n \"initial\": \"\\uFCA9\"\n },\n \"\\u062D\\u0645\": {\n \"isolated\": \"\\uFC18\",\n \"initial\": \"\\uFCAA\"\n },\n \"\\u062E\\u062C\": {\n \"isolated\": \"\\uFC19\",\n \"initial\": \"\\uFCAB\"\n },\n \"\\u062E\\u062D\": {\n \"isolated\": \"\\uFC1A\"\n },\n \"\\u062E\\u0645\": {\n \"isolated\": \"\\uFC1B\",\n \"initial\": \"\\uFCAC\"\n },\n \"\\u0633\\u062C\": {\n \"isolated\": \"\\uFC1C\",\n \"initial\": \"\\uFCAD\",\n \"medial\": \"\\uFD34\"\n },\n \"\\u0633\\u062D\": {\n \"isolated\": \"\\uFC1D\",\n \"initial\": \"\\uFCAE\",\n \"medial\": \"\\uFD35\"\n },\n \"\\u0633\\u062E\": {\n \"isolated\": \"\\uFC1E\",\n \"initial\": \"\\uFCAF\",\n \"medial\": \"\\uFD36\"\n },\n \"\\u0633\\u0645\": {\n \"isolated\": \"\\uFC1F\",\n \"initial\": \"\\uFCB0\",\n \"medial\": \"\\uFCE7\"\n },\n \"\\u0635\\u062D\": {\n \"isolated\": \"\\uFC20\",\n \"initial\": \"\\uFCB1\"\n },\n \"\\u0635\\u0645\": {\n \"isolated\": \"\\uFC21\",\n \"initial\": \"\\uFCB3\"\n },\n \"\\u0636\\u062C\": {\n \"isolated\": \"\\uFC22\",\n \"initial\": \"\\uFCB4\"\n },\n \"\\u0636\\u062D\": {\n \"isolated\": \"\\uFC23\",\n \"initial\": \"\\uFCB5\"\n },\n \"\\u0636\\u062E\": {\n \"isolated\": \"\\uFC24\",\n \"initial\": \"\\uFCB6\"\n },\n \"\\u0636\\u0645\": {\n \"isolated\": \"\\uFC25\",\n \"initial\": \"\\uFCB7\"\n },\n \"\\u0637\\u062D\": {\n \"isolated\": \"\\uFC26\",\n \"initial\": \"\\uFCB8\"\n },\n \"\\u0637\\u0645\": {\n \"isolated\": \"\\uFC27\",\n \"initial\": \"\\uFD33\",\n \"medial\": \"\\uFD3A\"\n },\n \"\\u0638\\u0645\": {\n \"isolated\": \"\\uFC28\",\n \"initial\": \"\\uFCB9\",\n \"medial\": \"\\uFD3B\"\n },\n \"\\u0639\\u062C\": {\n \"isolated\": \"\\uFC29\",\n \"initial\": \"\\uFCBA\"\n },\n \"\\u0639\\u0645\": {\n \"isolated\": \"\\uFC2A\",\n \"initial\": \"\\uFCBB\"\n },\n \"\\u063A\\u062C\": {\n \"isolated\": \"\\uFC2B\",\n \"initial\": \"\\uFCBC\"\n },\n \"\\u063A\\u0645\": {\n \"isolated\": \"\\uFC2C\",\n \"initial\": \"\\uFCBD\"\n },\n \"\\u0641\\u062C\": {\n \"isolated\": \"\\uFC2D\",\n \"initial\": \"\\uFCBE\"\n },\n \"\\u0641\\u062D\": {\n \"isolated\": \"\\uFC2E\",\n \"initial\": \"\\uFCBF\"\n },\n \"\\u0641\\u062E\": {\n \"isolated\": \"\\uFC2F\",\n \"initial\": \"\\uFCC0\"\n },\n \"\\u0641\\u0645\": {\n \"isolated\": \"\\uFC30\",\n \"initial\": \"\\uFCC1\"\n },\n \"\\u0641\\u0649\": {\n \"isolated\": \"\\uFC31\",\n \"final\": \"\\uFC7C\"\n },\n \"\\u0641\\u064A\": {\n \"isolated\": \"\\uFC32\",\n \"final\": \"\\uFC7D\"\n },\n \"\\u0642\\u062D\": {\n \"isolated\": \"\\uFC33\",\n \"initial\": \"\\uFCC2\"\n },\n \"\\u0642\\u0645\": {\n \"isolated\": \"\\uFC34\",\n \"initial\": \"\\uFCC3\"\n },\n \"\\u0642\\u0649\": {\n \"isolated\": \"\\uFC35\",\n \"final\": \"\\uFC7E\"\n },\n \"\\u0642\\u064A\": {\n \"isolated\": \"\\uFC36\",\n \"final\": \"\\uFC7F\"\n },\n \"\\u0643\\u0627\": {\n \"isolated\": \"\\uFC37\",\n \"final\": \"\\uFC80\"\n },\n \"\\u0643\\u062C\": {\n \"isolated\": \"\\uFC38\",\n \"initial\": \"\\uFCC4\"\n },\n \"\\u0643\\u062D\": {\n \"isolated\": \"\\uFC39\",\n \"initial\": \"\\uFCC5\"\n },\n \"\\u0643\\u062E\": {\n \"isolated\": \"\\uFC3A\",\n \"initial\": \"\\uFCC6\"\n },\n \"\\u0643\\u0644\": {\n \"isolated\": \"\\uFC3B\",\n \"final\": \"\\uFC81\",\n \"initial\": \"\\uFCC7\",\n \"medial\": \"\\uFCEB\"\n },\n \"\\u0643\\u0645\": {\n \"isolated\": \"\\uFC3C\",\n \"final\": \"\\uFC82\",\n \"initial\": \"\\uFCC8\",\n \"medial\": \"\\uFCEC\"\n },\n \"\\u0643\\u0649\": {\n \"isolated\": \"\\uFC3D\",\n \"final\": \"\\uFC83\"\n },\n \"\\u0643\\u064A\": {\n \"isolated\": \"\\uFC3E\",\n \"final\": \"\\uFC84\"\n },\n \"\\u0644\\u062C\": {\n \"isolated\": \"\\uFC3F\",\n \"initial\": \"\\uFCC9\"\n },\n \"\\u0644\\u062D\": {\n \"isolated\": \"\\uFC40\",\n \"initial\": \"\\uFCCA\"\n },\n \"\\u0644\\u062E\": {\n \"isolated\": \"\\uFC41\",\n \"initial\": \"\\uFCCB\"\n },\n \"\\u0644\\u0645\": {\n \"isolated\": \"\\uFC42\",\n \"final\": \"\\uFC85\",\n \"initial\": \"\\uFCCC\",\n \"medial\": \"\\uFCED\"\n },\n \"\\u0644\\u0649\": {\n \"isolated\": \"\\uFC43\",\n \"final\": \"\\uFC86\"\n },\n \"\\u0644\\u064A\": {\n \"isolated\": \"\\uFC44\",\n \"final\": \"\\uFC87\"\n },\n \"\\u0645\\u062C\": {\n \"isolated\": \"\\uFC45\",\n \"initial\": \"\\uFCCE\"\n },\n \"\\u0645\\u062D\": {\n \"isolated\": \"\\uFC46\",\n \"initial\": \"\\uFCCF\"\n },\n \"\\u0645\\u062E\": {\n \"isolated\": \"\\uFC47\",\n \"initial\": \"\\uFCD0\"\n },\n \"\\u0645\\u0645\": {\n \"isolated\": \"\\uFC48\",\n \"final\": \"\\uFC89\",\n \"initial\": \"\\uFCD1\"\n },\n \"\\u0645\\u0649\": {\n \"isolated\": \"\\uFC49\"\n },\n \"\\u0645\\u064A\": {\n \"isolated\": \"\\uFC4A\"\n },\n \"\\u0646\\u062C\": {\n \"isolated\": \"\\uFC4B\",\n \"initial\": \"\\uFCD2\"\n },\n \"\\u0646\\u062D\": {\n \"isolated\": \"\\uFC4C\",\n \"initial\": \"\\uFCD3\"\n },\n \"\\u0646\\u062E\": {\n \"isolated\": \"\\uFC4D\",\n \"initial\": \"\\uFCD4\"\n },\n \"\\u0646\\u0645\": {\n \"isolated\": \"\\uFC4E\",\n \"final\": \"\\uFC8C\",\n \"initial\": \"\\uFCD5\",\n \"medial\": \"\\uFCEE\"\n },\n \"\\u0646\\u0649\": {\n \"isolated\": \"\\uFC4F\",\n \"final\": \"\\uFC8E\"\n },\n \"\\u0646\\u064A\": {\n \"isolated\": \"\\uFC50\",\n \"final\": \"\\uFC8F\"\n },\n \"\\u0647\\u062C\": {\n \"isolated\": \"\\uFC51\",\n \"initial\": \"\\uFCD7\"\n },\n \"\\u0647\\u0645\": {\n \"isolated\": \"\\uFC52\",\n \"initial\": \"\\uFCD8\"\n },\n \"\\u0647\\u0649\": {\n \"isolated\": \"\\uFC53\"\n },\n \"\\u0647\\u064A\": {\n \"isolated\": \"\\uFC54\"\n },\n \"\\u064A\\u062C\": {\n \"isolated\": \"\\uFC55\",\n \"initial\": \"\\uFCDA\"\n },\n \"\\u064A\\u062D\": {\n \"isolated\": \"\\uFC56\",\n \"initial\": \"\\uFCDB\"\n },\n \"\\u064A\\u062E\": {\n \"isolated\": \"\\uFC57\",\n \"initial\": \"\\uFCDC\"\n },\n \"\\u064A\\u0645\": {\n \"isolated\": \"\\uFC58\",\n \"final\": \"\\uFC93\",\n \"initial\": \"\\uFCDD\",\n \"medial\": \"\\uFCF0\"\n },\n \"\\u064A\\u0649\": {\n \"isolated\": \"\\uFC59\",\n \"final\": \"\\uFC95\"\n },\n \"\\u064A\\u064A\": {\n \"isolated\": \"\\uFC5A\",\n \"final\": \"\\uFC96\"\n },\n \"\\u0630\\u0670\": {\n \"isolated\": \"\\uFC5B\"\n },\n \"\\u0631\\u0670\": {\n \"isolated\": \"\\uFC5C\"\n },\n \"\\u0649\\u0670\": {\n \"isolated\": \"\\uFC5D\",\n \"final\": \"\\uFC90\"\n },\n \"\\u064C\\u0651\": {\n \"isolated\": \"\\uFC5E\"\n },\n \"\\u064D\\u0651\": {\n \"isolated\": \"\\uFC5F\"\n },\n \"\\u064E\\u0651\": {\n \"isolated\": \"\\uFC60\"\n },\n \"\\u064F\\u0651\": {\n \"isolated\": \"\\uFC61\"\n },\n \"\\u0650\\u0651\": {\n \"isolated\": \"\\uFC62\"\n },\n \"\\u0651\\u0670\": {\n \"isolated\": \"\\uFC63\"\n },\n \"\\u0626\\u0631\": {\n \"final\": \"\\uFC64\"\n },\n \"\\u0626\\u0632\": {\n \"final\": \"\\uFC65\"\n },\n \"\\u0626\\u0646\": {\n \"final\": \"\\uFC67\"\n },\n \"\\u0628\\u0631\": {\n \"final\": \"\\uFC6A\"\n },\n \"\\u0628\\u0632\": {\n \"final\": \"\\uFC6B\"\n },\n \"\\u0628\\u0646\": {\n \"final\": \"\\uFC6D\"\n },\n \"\\u062A\\u0631\": {\n \"final\": \"\\uFC70\"\n },\n \"\\u062A\\u0632\": {\n \"final\": \"\\uFC71\"\n },\n \"\\u062A\\u0646\": {\n \"final\": \"\\uFC73\"\n },\n \"\\u062B\\u0631\": {\n \"final\": \"\\uFC76\"\n },\n \"\\u062B\\u0632\": {\n \"final\": \"\\uFC77\"\n },\n \"\\u062B\\u0646\": {\n \"final\": \"\\uFC79\"\n },\n \"\\u062B\\u064A\": {\n \"final\": \"\\uFC7B\"\n },\n \"\\u0645\\u0627\": {\n \"final\": \"\\uFC88\"\n },\n \"\\u0646\\u0631\": {\n \"final\": \"\\uFC8A\"\n },\n \"\\u0646\\u0632\": {\n \"final\": \"\\uFC8B\"\n },\n \"\\u0646\\u0646\": {\n \"final\": \"\\uFC8D\"\n },\n \"\\u064A\\u0631\": {\n \"final\": \"\\uFC91\"\n },\n \"\\u064A\\u0632\": {\n \"final\": \"\\uFC92\"\n },\n \"\\u064A\\u0646\": {\n \"final\": \"\\uFC94\"\n },\n \"\\u0626\\u062E\": {\n \"initial\": \"\\uFC99\"\n },\n \"\\u0626\\u0647\": {\n \"initial\": \"\\uFC9B\",\n \"medial\": \"\\uFCE0\"\n },\n \"\\u0628\\u0647\": {\n \"initial\": \"\\uFCA0\",\n \"medial\": \"\\uFCE2\"\n },\n \"\\u062A\\u0647\": {\n \"initial\": \"\\uFCA5\",\n \"medial\": \"\\uFCE4\"\n },\n \"\\u0635\\u062E\": {\n \"initial\": \"\\uFCB2\"\n },\n \"\\u0644\\u0647\": {\n \"initial\": \"\\uFCCD\"\n },\n \"\\u0646\\u0647\": {\n \"initial\": \"\\uFCD6\",\n \"medial\": \"\\uFCEF\"\n },\n \"\\u0647\\u0670\": {\n \"initial\": \"\\uFCD9\"\n },\n \"\\u064A\\u0647\": {\n \"initial\": \"\\uFCDE\",\n \"medial\": \"\\uFCF1\"\n },\n \"\\u062B\\u0647\": {\n \"medial\": \"\\uFCE6\"\n },\n \"\\u0633\\u0647\": {\n \"medial\": \"\\uFCE8\",\n \"initial\": \"\\uFD31\"\n },\n \"\\u0634\\u0645\": {\n \"medial\": \"\\uFCE9\",\n \"isolated\": \"\\uFD0C\",\n \"final\": \"\\uFD28\",\n \"initial\": \"\\uFD30\"\n },\n \"\\u0634\\u0647\": {\n \"medial\": \"\\uFCEA\",\n \"initial\": \"\\uFD32\"\n },\n \"\\u0640\\u064E\\u0651\": {\n \"medial\": \"\\uFCF2\"\n },\n \"\\u0640\\u064F\\u0651\": {\n \"medial\": \"\\uFCF3\"\n },\n \"\\u0640\\u0650\\u0651\": {\n \"medial\": \"\\uFCF4\"\n },\n \"\\u0637\\u0649\": {\n \"isolated\": \"\\uFCF5\",\n \"final\": \"\\uFD11\"\n },\n \"\\u0637\\u064A\": {\n \"isolated\": \"\\uFCF6\",\n \"final\": \"\\uFD12\"\n },\n \"\\u0639\\u0649\": {\n \"isolated\": \"\\uFCF7\",\n \"final\": \"\\uFD13\"\n },\n \"\\u0639\\u064A\": {\n \"isolated\": \"\\uFCF8\",\n \"final\": \"\\uFD14\"\n },\n \"\\u063A\\u0649\": {\n \"isolated\": \"\\uFCF9\",\n \"final\": \"\\uFD15\"\n },\n \"\\u063A\\u064A\": {\n \"isolated\": \"\\uFCFA\",\n \"final\": \"\\uFD16\"\n },\n \"\\u0633\\u0649\": {\n \"isolated\": \"\\uFCFB\"\n },\n \"\\u0633\\u064A\": {\n \"isolated\": \"\\uFCFC\",\n \"final\": \"\\uFD18\"\n },\n \"\\u0634\\u0649\": {\n \"isolated\": \"\\uFCFD\",\n \"final\": \"\\uFD19\"\n },\n \"\\u0634\\u064A\": {\n \"isolated\": \"\\uFCFE\",\n \"final\": \"\\uFD1A\"\n },\n \"\\u062D\\u0649\": {\n \"isolated\": \"\\uFCFF\",\n \"final\": \"\\uFD1B\"\n },\n \"\\u062D\\u064A\": {\n \"isolated\": \"\\uFD00\",\n \"final\": \"\\uFD1C\"\n },\n \"\\u062C\\u0649\": {\n \"isolated\": \"\\uFD01\",\n \"final\": \"\\uFD1D\"\n },\n \"\\u062C\\u064A\": {\n \"isolated\": \"\\uFD02\",\n \"final\": \"\\uFD1E\"\n },\n \"\\u062E\\u0649\": {\n \"isolated\": \"\\uFD03\",\n \"final\": \"\\uFD1F\"\n },\n \"\\u062E\\u064A\": {\n \"isolated\": \"\\uFD04\",\n \"final\": \"\\uFD20\"\n },\n \"\\u0635\\u0649\": {\n \"isolated\": \"\\uFD05\",\n \"final\": \"\\uFD21\"\n },\n \"\\u0635\\u064A\": {\n \"isolated\": \"\\uFD06\",\n \"final\": \"\\uFD22\"\n },\n \"\\u0636\\u0649\": {\n \"isolated\": \"\\uFD07\",\n \"final\": \"\\uFD23\"\n },\n \"\\u0636\\u064A\": {\n \"isolated\": \"\\uFD08\",\n \"final\": \"\\uFD24\"\n },\n \"\\u0634\\u062C\": {\n \"isolated\": \"\\uFD09\",\n \"final\": \"\\uFD25\",\n \"initial\": \"\\uFD2D\",\n \"medial\": \"\\uFD37\"\n },\n \"\\u0634\\u062D\": {\n \"isolated\": \"\\uFD0A\",\n \"final\": \"\\uFD26\",\n \"initial\": \"\\uFD2E\",\n \"medial\": \"\\uFD38\"\n },\n \"\\u0634\\u062E\": {\n \"isolated\": \"\\uFD0B\",\n \"final\": \"\\uFD27\",\n \"initial\": \"\\uFD2F\",\n \"medial\": \"\\uFD39\"\n },\n \"\\u0634\\u0631\": {\n \"isolated\": \"\\uFD0D\",\n \"final\": \"\\uFD29\"\n },\n \"\\u0633\\u0631\": {\n \"isolated\": \"\\uFD0E\",\n \"final\": \"\\uFD2A\"\n },\n \"\\u0635\\u0631\": {\n \"isolated\": \"\\uFD0F\",\n \"final\": \"\\uFD2B\"\n },\n \"\\u0636\\u0631\": {\n \"isolated\": \"\\uFD10\",\n \"final\": \"\\uFD2C\"\n },\n \"\\u0633\\u0639\": {\n \"final\": \"\\uFD17\"\n },\n \"\\u062A\\u062C\\u0645\": {\n \"initial\": \"\\uFD50\"\n },\n \"\\u062A\\u062D\\u062C\": {\n \"final\": \"\\uFD51\",\n \"initial\": \"\\uFD52\"\n },\n \"\\u062A\\u062D\\u0645\": {\n \"initial\": \"\\uFD53\"\n },\n \"\\u062A\\u062E\\u0645\": {\n \"initial\": \"\\uFD54\"\n },\n \"\\u062A\\u0645\\u062C\": {\n \"initial\": \"\\uFD55\"\n },\n \"\\u062A\\u0645\\u062D\": {\n \"initial\": \"\\uFD56\"\n },\n \"\\u062A\\u0645\\u062E\": {\n \"initial\": \"\\uFD57\"\n },\n \"\\u062C\\u0645\\u062D\": {\n \"final\": \"\\uFD58\",\n \"initial\": \"\\uFD59\"\n },\n \"\\u062D\\u0645\\u064A\": {\n \"final\": \"\\uFD5A\"\n },\n \"\\u062D\\u0645\\u0649\": {\n \"final\": \"\\uFD5B\"\n },\n \"\\u0633\\u062D\\u062C\": {\n \"initial\": \"\\uFD5C\"\n },\n \"\\u0633\\u062C\\u062D\": {\n \"initial\": \"\\uFD5D\"\n },\n \"\\u0633\\u062C\\u0649\": {\n \"final\": \"\\uFD5E\"\n },\n \"\\u0633\\u0645\\u062D\": {\n \"final\": \"\\uFD5F\",\n \"initial\": \"\\uFD60\"\n },\n \"\\u0633\\u0645\\u062C\": {\n \"initial\": \"\\uFD61\"\n },\n \"\\u0633\\u0645\\u0645\": {\n \"final\": \"\\uFD62\",\n \"initial\": \"\\uFD63\"\n },\n \"\\u0635\\u062D\\u062D\": {\n \"final\": \"\\uFD64\",\n \"initial\": \"\\uFD65\"\n },\n \"\\u0635\\u0645\\u0645\": {\n \"final\": \"\\uFD66\",\n \"initial\": \"\\uFDC5\"\n },\n \"\\u0634\\u062D\\u0645\": {\n \"final\": \"\\uFD67\",\n \"initial\": \"\\uFD68\"\n },\n \"\\u0634\\u062C\\u064A\": {\n \"final\": \"\\uFD69\"\n },\n \"\\u0634\\u0645\\u062E\": {\n \"final\": \"\\uFD6A\",\n \"initial\": \"\\uFD6B\"\n },\n \"\\u0634\\u0645\\u0645\": {\n \"final\": \"\\uFD6C\",\n \"initial\": \"\\uFD6D\"\n },\n \"\\u0636\\u062D\\u0649\": {\n \"final\": \"\\uFD6E\"\n },\n \"\\u0636\\u062E\\u0645\": {\n \"final\": \"\\uFD6F\",\n \"initial\": \"\\uFD70\"\n },\n \"\\u0636\\u0645\\u062D\": {\n \"final\": \"\\uFD71\"\n },\n \"\\u0637\\u0645\\u062D\": {\n \"initial\": \"\\uFD72\"\n },\n \"\\u0637\\u0645\\u0645\": {\n \"initial\": \"\\uFD73\"\n },\n \"\\u0637\\u0645\\u064A\": {\n \"final\": \"\\uFD74\"\n },\n \"\\u0639\\u062C\\u0645\": {\n \"final\": \"\\uFD75\",\n \"initial\": \"\\uFDC4\"\n },\n \"\\u0639\\u0645\\u0645\": {\n \"final\": \"\\uFD76\",\n \"initial\": \"\\uFD77\"\n },\n \"\\u0639\\u0645\\u0649\": {\n \"final\": \"\\uFD78\"\n },\n \"\\u063A\\u0645\\u0645\": {\n \"final\": \"\\uFD79\"\n },\n \"\\u063A\\u0645\\u064A\": {\n \"final\": \"\\uFD7A\"\n },\n \"\\u063A\\u0645\\u0649\": {\n \"final\": \"\\uFD7B\"\n },\n \"\\u0641\\u062E\\u0645\": {\n \"final\": \"\\uFD7C\",\n \"initial\": \"\\uFD7D\"\n },\n \"\\u0642\\u0645\\u062D\": {\n \"final\": \"\\uFD7E\",\n \"initial\": \"\\uFDB4\"\n },\n \"\\u0642\\u0645\\u0645\": {\n \"final\": \"\\uFD7F\"\n },\n \"\\u0644\\u062D\\u0645\": {\n \"final\": \"\\uFD80\",\n \"initial\": \"\\uFDB5\"\n },\n \"\\u0644\\u062D\\u064A\": {\n \"final\": \"\\uFD81\"\n },\n \"\\u0644\\u062D\\u0649\": {\n \"final\": \"\\uFD82\"\n },\n \"\\u0644\\u062C\\u062C\": {\n \"initial\": \"\\uFD83\",\n \"final\": \"\\uFD84\"\n },\n \"\\u0644\\u062E\\u0645\": {\n \"final\": \"\\uFD85\",\n \"initial\": \"\\uFD86\"\n },\n \"\\u0644\\u0645\\u062D\": {\n \"final\": \"\\uFD87\",\n \"initial\": \"\\uFD88\"\n },\n \"\\u0645\\u062D\\u062C\": {\n \"initial\": \"\\uFD89\"\n },\n \"\\u0645\\u062D\\u0645\": {\n \"initial\": \"\\uFD8A\"\n },\n \"\\u0645\\u062D\\u064A\": {\n \"final\": \"\\uFD8B\"\n },\n \"\\u0645\\u062C\\u062D\": {\n \"initial\": \"\\uFD8C\"\n },\n \"\\u0645\\u062C\\u0645\": {\n \"initial\": \"\\uFD8D\"\n },\n \"\\u0645\\u062E\\u062C\": {\n \"initial\": \"\\uFD8E\"\n },\n \"\\u0645\\u062E\\u0645\": {\n \"initial\": \"\\uFD8F\"\n },\n \"\\u0645\\u062C\\u062E\": {\n \"initial\": \"\\uFD92\"\n },\n \"\\u0647\\u0645\\u062C\": {\n \"initial\": \"\\uFD93\"\n },\n \"\\u0647\\u0645\\u0645\": {\n \"initial\": \"\\uFD94\"\n },\n \"\\u0646\\u062D\\u0645\": {\n \"initial\": \"\\uFD95\"\n },\n \"\\u0646\\u062D\\u0649\": {\n \"final\": \"\\uFD96\"\n },\n \"\\u0646\\u062C\\u0645\": {\n \"final\": \"\\uFD97\",\n \"initial\": \"\\uFD98\"\n },\n \"\\u0646\\u062C\\u0649\": {\n \"final\": \"\\uFD99\"\n },\n \"\\u0646\\u0645\\u064A\": {\n \"final\": \"\\uFD9A\"\n },\n \"\\u0646\\u0645\\u0649\": {\n \"final\": \"\\uFD9B\"\n },\n \"\\u064A\\u0645\\u0645\": {\n \"final\": \"\\uFD9C\",\n \"initial\": \"\\uFD9D\"\n },\n \"\\u0628\\u062E\\u064A\": {\n \"final\": \"\\uFD9E\"\n },\n \"\\u062A\\u062C\\u064A\": {\n \"final\": \"\\uFD9F\"\n },\n \"\\u062A\\u062C\\u0649\": {\n \"final\": \"\\uFDA0\"\n },\n \"\\u062A\\u062E\\u064A\": {\n \"final\": \"\\uFDA1\"\n },\n \"\\u062A\\u062E\\u0649\": {\n \"final\": \"\\uFDA2\"\n },\n \"\\u062A\\u0645\\u064A\": {\n \"final\": \"\\uFDA3\"\n },\n \"\\u062A\\u0645\\u0649\": {\n \"final\": \"\\uFDA4\"\n },\n \"\\u062C\\u0645\\u064A\": {\n \"final\": \"\\uFDA5\"\n },\n \"\\u062C\\u062D\\u0649\": {\n \"final\": \"\\uFDA6\"\n },\n \"\\u062C\\u0645\\u0649\": {\n \"final\": \"\\uFDA7\"\n },\n \"\\u0633\\u062E\\u0649\": {\n \"final\": \"\\uFDA8\"\n },\n \"\\u0635\\u062D\\u064A\": {\n \"final\": \"\\uFDA9\"\n },\n \"\\u0634\\u062D\\u064A\": {\n \"final\": \"\\uFDAA\"\n },\n \"\\u0636\\u062D\\u064A\": {\n \"final\": \"\\uFDAB\"\n },\n \"\\u0644\\u062C\\u064A\": {\n \"final\": \"\\uFDAC\"\n },\n \"\\u0644\\u0645\\u064A\": {\n \"final\": \"\\uFDAD\"\n },\n \"\\u064A\\u062D\\u064A\": {\n \"final\": \"\\uFDAE\"\n },\n \"\\u064A\\u062C\\u064A\": {\n \"final\": \"\\uFDAF\"\n },\n \"\\u064A\\u0645\\u064A\": {\n \"final\": \"\\uFDB0\"\n },\n \"\\u0645\\u0645\\u064A\": {\n \"final\": \"\\uFDB1\"\n },\n \"\\u0642\\u0645\\u064A\": {\n \"final\": \"\\uFDB2\"\n },\n \"\\u0646\\u062D\\u064A\": {\n \"final\": \"\\uFDB3\"\n },\n \"\\u0639\\u0645\\u064A\": {\n \"final\": \"\\uFDB6\"\n },\n \"\\u0643\\u0645\\u064A\": {\n \"final\": \"\\uFDB7\"\n },\n \"\\u0646\\u062C\\u062D\": {\n \"initial\": \"\\uFDB8\",\n \"final\": \"\\uFDBD\"\n },\n \"\\u0645\\u062E\\u064A\": {\n \"final\": \"\\uFDB9\"\n },\n \"\\u0644\\u062C\\u0645\": {\n \"initial\": \"\\uFDBA\",\n \"final\": \"\\uFDBC\"\n },\n \"\\u0643\\u0645\\u0645\": {\n \"final\": \"\\uFDBB\",\n \"initial\": \"\\uFDC3\"\n },\n \"\\u062C\\u062D\\u064A\": {\n \"final\": \"\\uFDBE\"\n },\n \"\\u062D\\u062C\\u064A\": {\n \"final\": \"\\uFDBF\"\n },\n \"\\u0645\\u062C\\u064A\": {\n \"final\": \"\\uFDC0\"\n },\n \"\\u0641\\u0645\\u064A\": {\n \"final\": \"\\uFDC1\"\n },\n \"\\u0628\\u062D\\u064A\": {\n \"final\": \"\\uFDC2\"\n },\n \"\\u0633\\u062E\\u064A\": {\n \"final\": \"\\uFDC6\"\n },\n \"\\u0646\\u062C\\u064A\": {\n \"final\": \"\\uFDC7\"\n },\n \"\\u0644\\u0622\": {\n \"isolated\": \"\\uFEF5\",\n \"final\": \"\\uFEF6\"\n },\n \"\\u0644\\u0623\": {\n \"isolated\": \"\\uFEF7\",\n \"final\": \"\\uFEF8\"\n },\n \"\\u0644\\u0625\": {\n \"isolated\": \"\\uFEF9\",\n \"final\": \"\\uFEFA\"\n },\n \"\\u0644\\u0627\": {\n \"isolated\": \"\\uFEFB\",\n \"final\": \"\\uFEFC\"\n },\n \"words\": {\n \"\\u0635\\u0644\\u06D2\": \"\\uFDF0\",\n \"\\u0642\\u0644\\u06D2\": \"\\uFDF1\",\n \"\\u0627\\u0644\\u0644\\u0647\": \"\\uFDF2\",\n \"\\u0627\\u0643\\u0628\\u0631\": \"\\uFDF3\",\n \"\\u0645\\u062D\\u0645\\u062F\": \"\\uFDF4\",\n \"\\u0635\\u0644\\u0639\\u0645\": \"\\uFDF5\",\n \"\\u0631\\u0633\\u0648\\u0644\": \"\\uFDF6\",\n \"\\u0639\\u0644\\u064A\\u0647\": \"\\uFDF7\",\n \"\\u0648\\u0633\\u0644\\u0645\": \"\\uFDF8\",\n \"\\u0635\\u0644\\u0649\": \"\\uFDF9\",\n \"\\u0635\\u0644\\u0649\\u0627\\u0644\\u0644\\u0647\\u0639\\u0644\\u064A\\u0647\\u0648\\u0633\\u0644\\u0645\": \"\\uFDFA\",\n \"\\u062C\\u0644\\u062C\\u0644\\u0627\\u0644\\u0647\": \"\\uFDFB\",\n \"\\u0631\\u06CC\\u0627\\u0644\": \"\\uFDFC\"\n }\n};\nexports.default = ligatureReference;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst unicode_arabic_1 = require(\"./unicode-arabic\");\nconst unicode_ligatures_1 = require(\"./unicode-ligatures\");\nconst letterList = Object.keys(unicode_arabic_1.default);\nexports.letterList = letterList;\nconst ligatureList = Object.keys(unicode_ligatures_1.default);\nexports.ligatureList = ligatureList;\nconst ligatureWordList = Object.keys(unicode_ligatures_1.default.words);\nexports.ligatureWordList = ligatureWordList;\nconst lams = '\\u0644\\u06B5\\u06B6\\u06B7\\u06B8';\nexports.lams = lams;\nconst alefs = '\\u0627\\u0622\\u0623\\u0625\\u0671\\u0672\\u0673\\u0675\\u0773\\u0774';\nexports.alefs = alefs;\n// for (var l = 1; l < lams.length; l++) {\n// console.log('-');\n// for (var a = 0; a < alefs.length; a++) {\n// console.log(a + ': ' + lams[l] + alefs[a]);\n// }\n// }\nlet tashkeel = '\\u0605\\u0640\\u0670\\u0674\\u06DF\\u06E7\\u06E8';\nexports.tashkeel = tashkeel;\nfunction addToTashkeel(start, finish) {\n for (var i = start; i <= finish; i++) {\n exports.tashkeel = tashkeel += String.fromCharCode(i);\n }\n}\naddToTashkeel(0x0610, 0x061A);\naddToTashkeel(0x064B, 0x065F);\naddToTashkeel(0x06D6, 0x06DC);\naddToTashkeel(0x06E0, 0x06E4);\naddToTashkeel(0x06EA, 0x06ED);\naddToTashkeel(0x08D3, 0x08E1);\naddToTashkeel(0x08E3, 0x08FF);\naddToTashkeel(0xFE70, 0xFE7F);\nlet lineBreakers = '\\u0627\\u0629\\u0648\\u06C0\\u06CF\\u06FD\\u06FE\\u076B\\u076C\\u0771\\u0773\\u0774\\u0778\\u0779\\u08E2\\u08B1\\u08B2\\u08B9';\nexports.lineBreakers = lineBreakers;\nfunction addToLineBreakers(start, finish) {\n for (var i = start; i <= finish; i++) {\n exports.lineBreakers = lineBreakers += String.fromCharCode(i);\n }\n}\naddToLineBreakers(0x0600, 0x061F); // it's OK to include tashkeel in this range as it is ignored\naddToLineBreakers(0x0621, 0x0625);\naddToLineBreakers(0x062F, 0x0632);\naddToLineBreakers(0x0660, 0x066D); // numerals, math\naddToLineBreakers(0x0671, 0x0677);\naddToLineBreakers(0x0688, 0x0699);\naddToLineBreakers(0x06C3, 0x06CB);\naddToLineBreakers(0x06D2, 0x06F9);\naddToLineBreakers(0x0759, 0x075B);\naddToLineBreakers(0x08AA, 0x08AE);\naddToLineBreakers(0xFB50, 0xFDFD); // presentation forms look like they could connect, but never do\n// Presentation Forms A includes diacritics but they are meant to stand alone\naddToLineBreakers(0xFE80, 0xFEFC); // presentation forms look like they could connect, but never do\n// numerals, math\naddToLineBreakers(0x10E60, 0x10E7F);\naddToLineBreakers(0x1EC70, 0x1ECBF);\naddToLineBreakers(0x1EE00, 0x1EEFF);\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst isArabic_1 = require(\"./isArabic\");\nconst reference_1 = require(\"./reference\");\nfunction GlyphSplitter(word) {\n let letters = [];\n let lastLetter = '';\n word.split('').forEach((letter) => {\n if (isArabic_1.isArabic(letter)) {\n if (reference_1.tashkeel.indexOf(letter) > -1) {\n letters[letters.length - 1] += letter;\n }\n else if (lastLetter.length && ((reference_1.lams.indexOf(lastLetter) === 0 && reference_1.alefs.indexOf(letter) > -1) || (reference_1.lams.indexOf(lastLetter) > 0 && reference_1.alefs.indexOf(letter) === 0))) {\n // valid LA forms\n letters[letters.length - 1] += letter;\n }\n else {\n letters.push(letter);\n }\n }\n else {\n letters.push(letter);\n }\n if (reference_1.tashkeel.indexOf(letter) === -1) {\n lastLetter = letter;\n }\n });\n return letters;\n}\nexports.GlyphSplitter = GlyphSplitter;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst isArabic_1 = require(\"./isArabic\");\nconst reference_1 = require(\"./reference\");\nfunction BaselineSplitter(word) {\n let letters = [];\n let lastLetter = '';\n word.split('').forEach((letter) => {\n if (isArabic_1.isArabic(letter) && isArabic_1.isArabic(lastLetter)) {\n if (lastLetter.length && reference_1.tashkeel.indexOf(letter) > -1) {\n letters[letters.length - 1] += letter;\n }\n else if (reference_1.lineBreakers.indexOf(lastLetter) > -1) {\n letters.push(letter);\n }\n else {\n letters[letters.length - 1] += letter;\n }\n }\n else {\n letters.push(letter);\n }\n if (reference_1.tashkeel.indexOf(letter) === -1) {\n // don't allow tashkeel to hide line break\n lastLetter = letter;\n }\n });\n return letters;\n}\nexports.BaselineSplitter = BaselineSplitter;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst unicode_arabic_1 = require(\"./unicode-arabic\");\nconst unicode_ligatures_1 = require(\"./unicode-ligatures\");\nconst isArabic_1 = require(\"./isArabic\");\nconst reference_1 = require(\"./reference\");\nfunction Normal(word, breakPresentationForm) {\n // default is to turn initial/isolated/medial/final presentation form to generic\n if (typeof breakPresentationForm === 'undefined') {\n breakPresentationForm = true;\n }\n let returnable = '';\n word.split('').forEach((letter) => {\n if (!isArabic_1.isArabic(letter)) {\n returnable += letter;\n return;\n }\n for (let w = 0; w < reference_1.letterList.length; w++) {\n // ok so we are checking this potential lettertron\n let letterForms = unicode_arabic_1.default[reference_1.letterList[w]];\n let versions = Object.keys(letterForms);\n for (let v = 0; v < versions.length; v++) {\n let localVersion = letterForms[versions[v]];\n if (typeof localVersion === 'object' && typeof localVersion.indexOf === 'undefined') {\n // look at this embedded object\n let embeddedForms = Object.keys(localVersion);\n for (let ef = 0; ef < embeddedForms.length; ef++) {\n let form = localVersion[embeddedForms[ef]];\n if (form === letter || (typeof form === 'object' && form.indexOf && form.indexOf(letter) > -1)) {\n // match\n // console.log('embedded match');\n if (form === letter) {\n // match exact\n if (breakPresentationForm && localVersion['normal'] && ['isolated', 'initial', 'medial', 'final'].indexOf(embeddedForms[ef]) > -1) {\n // replace presentation form\n // console.log('keeping normal form of the letter');\n if (typeof localVersion['normal'] === 'object') {\n returnable += localVersion['normal'][0];\n }\n else {\n returnable += localVersion['normal'];\n }\n return;\n }\n // console.log('keeping this letter');\n returnable += letter;\n return;\n }\n else if (typeof form === 'object' && form.indexOf && form.indexOf(letter) > -1) {\n // match\n returnable += form[0];\n // console.log('added the first letter from the same array');\n return;\n }\n }\n }\n }\n else if (localVersion === letter) {\n // match exact\n if (breakPresentationForm && letterForms['normal'] && ['isolated', 'initial', 'medial', 'final'].indexOf(versions[v]) > -1) {\n // replace presentation form\n // console.log('keeping normal form of the letter');\n if (typeof letterForms['normal'] === 'object') {\n returnable += letterForms['normal'][0];\n }\n else {\n returnable += letterForms['normal'];\n }\n return;\n }\n // console.log('keeping this letter');\n returnable += letter;\n return;\n }\n else if (typeof localVersion === 'object' && localVersion.indexOf && localVersion.indexOf(letter) > -1) {\n // match\n returnable += localVersion[0];\n // console.log('added the first letter from the same array');\n return;\n }\n }\n }\n // try ligatures\n for (let v2 = 0; v2 < reference_1.ligatureList.length; v2++) {\n let normalForm = reference_1.ligatureList[v2];\n if (normalForm !== 'words') {\n let ligForms = Object.keys(unicode_ligatures_1.default[normalForm]);\n for (let f = 0; f < ligForms.length; f++) {\n if (unicode_ligatures_1.default[normalForm][ligForms[f]] === letter) {\n returnable += normalForm;\n return;\n }\n }\n }\n }\n // try words ligatures\n for (let v3 = 0; v3 < reference_1.ligatureWordList.length; v3++) {\n let normalForm = reference_1.ligatureWordList[v3];\n if (unicode_ligatures_1.default.words[normalForm] === letter) {\n returnable += normalForm;\n return;\n }\n }\n returnable += letter;\n // console.log('kept the letter')\n });\n return returnable;\n}\nexports.Normal = Normal;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst unicode_arabic_1 = require(\"./unicode-arabic\");\nconst isArabic_1 = require(\"./isArabic\");\nconst reference_1 = require(\"./reference\");\nfunction CharShaper(letter, form) {\n if (!isArabic_1.isArabic(letter)) {\n // fail not Arabic\n throw new Error('Not Arabic');\n }\n if (letter === \"\\u0621\") {\n // hamza alone\n return \"\\u0621\";\n }\n for (let w = 0; w < reference_1.letterList.length; w++) {\n // ok so we are checking this potential lettertron\n let letterForms = unicode_arabic_1.default[reference_1.letterList[w]];\n let versions = Object.keys(letterForms);\n for (let v = 0; v < versions.length; v++) {\n let localVersion = letterForms[versions[v]];\n if ((localVersion === letter) ||\n (typeof localVersion === 'object' && localVersion.indexOf && localVersion.indexOf(letter) > -1)) {\n if (versions.indexOf(form) > -1) {\n return letterForms[form];\n }\n }\n else if (typeof localVersion === 'object' && typeof localVersion.indexOf === 'undefined') {\n // check embedded\n let embeddedVersions = Object.keys(localVersion);\n for (let ev = 0; ev < embeddedVersions.length; ev++) {\n if ((localVersion[embeddedVersions[ev]] === letter) ||\n (typeof localVersion[embeddedVersions[ev]] === 'object' && localVersion[embeddedVersions[ev]].indexOf && localVersion[embeddedVersions[ev]].indexOf(letter) > -1)) {\n if (embeddedVersions.indexOf(form) > -1) {\n return localVersion[form];\n }\n }\n }\n }\n }\n }\n}\nexports.CharShaper = CharShaper;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst isArabic_1 = require(\"./isArabic\");\nconst reference_1 = require(\"./reference\");\nconst CharShaper_1 = require(\"./CharShaper\");\nconst unicode_ligatures_1 = require(\"./unicode-ligatures\");\nfunction WordShaper(word) {\n let state = 'initial';\n let output = '';\n for (let w = 0; w < word.length; w++) {\n let nextLetter = ' ';\n for (let nxw = w + 1; nxw < word.length; nxw++) {\n if (!isArabic_1.isArabic(word[nxw])) {\n break;\n }\n if (reference_1.tashkeel.indexOf(word[nxw]) === -1) {\n nextLetter = word[nxw];\n break;\n }\n }\n if (!isArabic_1.isArabic(word[w]) || isArabic_1.isMath(word[w])) {\n // space or other non-Arabic\n output += word[w];\n state = 'initial';\n }\n else if (reference_1.tashkeel.indexOf(word[w]) > -1) {\n // tashkeel - add without changing state\n output += word[w];\n }\n else if ((nextLetter === ' ') // last Arabic letter in this word\n || (reference_1.lineBreakers.indexOf(word[w]) > -1)) { // the current letter is known to break lines\n output += CharShaper_1.CharShaper(word[w], state === 'initial' ? 'isolated' : 'final');\n state = 'initial';\n }\n else if (reference_1.lams.indexOf(word[w]) > -1 && reference_1.alefs.indexOf(nextLetter) > -1) {\n // LA letters - advance an additional letter after this\n output += unicode_ligatures_1.default[word[w] + nextLetter][(state === 'initial' ? 'isolated' : 'final')];\n while (word[w] !== nextLetter) {\n w++;\n }\n state = 'initial';\n }\n else {\n output += CharShaper_1.CharShaper(word[w], state);\n state = 'medial';\n }\n }\n return output;\n}\nexports.WordShaper = WordShaper;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst unicode_arabic_1 = require(\"./unicode-arabic\");\nconst isArabic_1 = require(\"./isArabic\");\nconst reference_1 = require(\"./reference\");\nfunction ParentLetter(letter) {\n if (!isArabic_1.isArabic(letter)) {\n throw new Error('Not an Arabic letter');\n }\n for (let w = 0; w < reference_1.letterList.length; w++) {\n // ok so we are checking this potential lettertron\n let letterForms = unicode_arabic_1.default[reference_1.letterList[w]];\n let versions = Object.keys(letterForms);\n for (let v = 0; v < versions.length; v++) {\n let localVersion = letterForms[versions[v]];\n if (typeof localVersion === 'object' && typeof localVersion.indexOf === 'undefined') {\n // look at this embedded object\n let embeddedForms = Object.keys(localVersion);\n for (let ef = 0; ef < embeddedForms.length; ef++) {\n let form = localVersion[embeddedForms[ef]];\n if (form === letter || (typeof form === 'object' && form.indexOf && form.indexOf(letter) > -1)) {\n // match\n return localVersion;\n }\n }\n }\n else if (localVersion === letter || (typeof localVersion === 'object' && localVersion.indexOf && localVersion.indexOf(letter) > -1)) {\n // match\n return letterForms;\n }\n }\n return null;\n }\n}\nexports.ParentLetter = ParentLetter;\nfunction GrandparentLetter(letter) {\n if (!isArabic_1.isArabic(letter)) {\n throw new Error('Not an Arabic letter');\n }\n for (let w = 0; w < reference_1.letterList.length; w++) {\n // ok so we are checking this potential lettertron\n let letterForms = unicode_arabic_1.default[reference_1.letterList[w]];\n let versions = Object.keys(letterForms);\n for (let v = 0; v < versions.length; v++) {\n let localVersion = letterForms[versions[v]];\n if (typeof localVersion === 'object' && typeof localVersion.indexOf === 'undefined') {\n // look at this embedded object\n let embeddedForms = Object.keys(localVersion);\n for (let ef = 0; ef < embeddedForms.length; ef++) {\n let form = localVersion[embeddedForms[ef]];\n if (form === letter || (typeof form === 'object' && form.indexOf && form.indexOf(letter) > -1)) {\n // match\n return letterForms;\n }\n }\n }\n else if (localVersion === letter || (typeof localVersion === 'object' && localVersion.indexOf && localVersion.indexOf(letter) > -1)) {\n // match\n return letterForms;\n }\n }\n return null;\n }\n}\nexports.GrandparentLetter = GrandparentLetter;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar isArabic_1 = require(\"./isArabic\");\nexports.isArabic = isArabic_1.isArabic;\nvar GlyphSplitter_1 = require(\"./GlyphSplitter\");\nexports.GlyphSplitter = GlyphSplitter_1.GlyphSplitter;\nvar BaselineSplitter_1 = require(\"./BaselineSplitter\");\nexports.BaselineSplitter = BaselineSplitter_1.BaselineSplitter;\nvar Normalization_1 = require(\"./Normalization\");\nexports.Normal = Normalization_1.Normal;\nvar CharShaper_1 = require(\"./CharShaper\");\nexports.CharShaper = CharShaper_1.CharShaper;\nvar WordShaper_1 = require(\"./WordShaper\");\nexports.WordShaper = WordShaper_1.WordShaper;\nvar ParentLetter_1 = require(\"./ParentLetter\");\nexports.ParentLetter = ParentLetter_1.ParentLetter;\nexports.GrandparentLetter = ParentLetter_1.GrandparentLetter;\n","// see https://github.com/openstreetmap/iD/pull/3707\n// https://gist.github.com/mapmeld/556b09ddec07a2044c76e1ef45f01c60\n\nimport { WordShaper } from 'alif-toolkit';\n\nexport var rtlRegex = /[\\u0590-\\u05FF\\u0600-\\u06FF\\u0750-\\u07BF\\u08A0–\\u08BF]/;\n\nexport function fixRTLTextForSvg(inputText) {\n var ret = '', rtlBuffer = [];\n var arabicRegex = /[\\u0600-\\u06FF]/g;\n var arabicDiacritics = /[\\u0610-\\u061A\\u064B-\\u065F\\u0670\\u06D6-\\u06ED]/g;\n var arabicMath = /[\\u0660-\\u066C\\u06F0-\\u06F9]+/g;\n var thaanaVowel = /[\\u07A6-\\u07B0]/;\n var hebrewSign = /[\\u0591-\\u05bd\\u05bf\\u05c1-\\u05c5\\u05c7]/;\n\n // Arabic word shaping\n if (arabicRegex.test(inputText)) {\n inputText = WordShaper(inputText);\n }\n\n for (var n = 0; n < inputText.length; n++) {\n var c = inputText[n];\n if (arabicMath.test(c)) {\n // Arabic numbers go LTR\n ret += rtlBuffer.reverse().join('');\n rtlBuffer = [c];\n } else {\n if (rtlBuffer.length && arabicMath.test(rtlBuffer[rtlBuffer.length - 1])) {\n ret += rtlBuffer.reverse().join('');\n rtlBuffer = [];\n }\n if ((thaanaVowel.test(c) || hebrewSign.test(c) || arabicDiacritics.test(c)) && rtlBuffer.length) {\n rtlBuffer[rtlBuffer.length - 1] += c;\n } else if (rtlRegex.test(c)\n // include Arabic presentation forms\n || (c.charCodeAt(0) >= 64336 && c.charCodeAt(0) <= 65023)\n || (c.charCodeAt(0) >= 65136 && c.charCodeAt(0) <= 65279)) {\n rtlBuffer.push(c);\n } else if (c === ' ' && rtlBuffer.length) {\n // whitespace within RTL text\n rtlBuffer = [rtlBuffer.reverse().join('') + ' '];\n } else {\n // non-RTL character\n ret += rtlBuffer.reverse().join('') + c;\n rtlBuffer = [];\n }\n }\n }\n ret += rtlBuffer.reverse().join('');\n return ret;\n}\n","\n// https://github.com/openstreetmap/iD/issues/772\n// http://mathiasbynens.be/notes/localstorage-pattern#comment-9\nlet _storage;\ntry { _storage = localStorage; } catch (e) {} // eslint-disable-line no-empty\n_storage = _storage || (() => {\n let s = {};\n return {\n getItem: (k) => s[k],\n setItem: (k, v) => s[k] = v,\n removeItem: (k) => delete s[k]\n };\n})();\n\n//\n// corePreferences is an interface for persisting basic key-value strings\n// within and between iD sessions on the same site.\n//\nfunction corePreferences(k, v) {\n\n try {\n if (arguments.length === 1) return _storage.getItem(k);\n else if (v === null) _storage.removeItem(k);\n else _storage.setItem(k, v);\n } catch (e) {\n /* eslint-disable no-console */\n if (typeof console !== 'undefined') {\n console.error('localStorage quota exceeded');\n }\n /* eslint-enable no-console */\n }\n\n}\n\nexport { corePreferences as prefs };\n","function responseText(response) {\n if (!response.ok) throw new Error(response.status + \" \" + response.statusText);\n return response.text();\n}\n\nexport default function(input, init) {\n return fetch(input, init).then(responseText);\n}\n","function responseJson(response) {\n if (!response.ok) throw new Error(response.status + \" \" + response.statusText);\n if (response.status === 204 || response.status === 205) return;\n return response.json();\n}\n\nexport default function(input, init) {\n return fetch(input, init).then(responseJson);\n}\n","import text from \"./text.js\";\n\nfunction parser(type) {\n return function(input, init) {\n return text(input, init).then(function(text) {\n return (new DOMParser).parseFromString(text, type);\n });\n };\n}\n\nexport default parser(\"application/xml\");\n\nexport var html = parser(\"text/html\");\n\nexport var svg = parser(\"image/svg+xml\");\n","import { json as d3_json } from 'd3-fetch';\n\nlet _mainFileFetcher = coreFileFetcher(); // singleton\n\nexport { _mainFileFetcher as fileFetcher };\n\n//\n// coreFileFetcher asynchronously fetches data from JSON files\n//\nexport function coreFileFetcher() {\n let _this = {};\n let _inflight = {};\n let _fileMap = {\n 'address_formats': 'data/address_formats.min.json',\n 'deprecated': 'data/deprecated.min.json',\n 'discarded': 'data/discarded.min.json',\n 'imagery': 'data/imagery.min.json',\n 'intro_graph': 'data/intro_graph.min.json',\n 'intro_rapid_graph': 'data/intro_rapid_graph.min.json',\n 'keepRight': 'data/keepRight.min.json',\n 'languages': 'data/languages.min.json',\n 'locales': 'data/locales.min.json',\n 'nsi_brands': 'https://cdn.jsdelivr.net/npm/name-suggestion-index@4/dist/brands.min.json',\n 'nsi_filters': 'https://cdn.jsdelivr.net/npm/name-suggestion-index@4/dist/filters.min.json',\n 'oci_features': 'https://cdn.jsdelivr.net/npm/osm-community-index@2/dist/features.min.json',\n 'oci_resources': 'https://cdn.jsdelivr.net/npm/osm-community-index@2/dist/resources.min.json',\n 'preset_categories': 'data/preset_categories.min.json',\n 'preset_defaults': 'data/preset_defaults.min.json',\n 'preset_fields': 'data/preset_fields.min.json',\n 'preset_presets': 'data/preset_presets.min.json',\n 'phone_formats': 'data/phone_formats.min.json',\n 'qa_data': 'data/qa_data.min.json',\n 'shortcuts': 'data/shortcuts.min.json',\n 'territory_languages': 'data/territory_languages.min.json',\n 'wmf_sitematrix': 'https://cdn.jsdelivr.net/npm/wmf-sitematrix@0.1/wikipedia.min.json'\n };\n\n let _cachedData = {};\n // expose the cache; useful for tests\n _this.cache = () => _cachedData;\n\n\n // Returns a Promise to fetch data\n // (resolved with the data if we have it already)\n _this.get = (which) => {\n if (_cachedData[which]) {\n return Promise.resolve(_cachedData[which]);\n }\n\n const file = _fileMap[which];\n const url = file && _this.asset(file);\n if (!url) {\n return Promise.reject(`Unknown data file for \"${which}\"`);\n }\n\n let prom = _inflight[url];\n if (!prom) {\n _inflight[url] = prom = d3_json(url)\n .then(result => {\n delete _inflight[url];\n if (!result) {\n throw new Error(`No data loaded for \"${which}\"`);\n }\n _cachedData[which] = result;\n return result;\n })\n .catch(err => {\n delete _inflight[url];\n throw err;\n });\n }\n\n return prom;\n };\n\n\n // Accessor for the file map\n _this.fileMap = function(val) {\n if (!arguments.length) return _fileMap;\n _fileMap = val;\n return _this;\n };\n\n let _assetPath = '';\n _this.assetPath = function(val) {\n if (!arguments.length) return _assetPath;\n _assetPath = val;\n return _this;\n };\n\n let _assetMap = {};\n _this.assetMap = function(val) {\n if (!arguments.length) return _assetMap;\n _assetMap = val;\n return _this;\n };\n\n _this.asset = (val) => {\n if (/^http(s)?:\\/\\//i.test(val)) return val;\n const filename = _assetPath + val;\n return _assetMap[filename] || filename;\n };\n\n return _this;\n}\n","\nlet _detected;\n\nexport function utilDetect(refresh) {\n if (_detected && !refresh) return _detected;\n _detected = {};\n\n const ua = navigator.userAgent;\n let m = null;\n\n /* Browser */\n m = ua.match(/(edge)\\/?\\s*(\\.?\\d+(\\.\\d+)*)/i); // Edge\n if (m !== null) {\n _detected.browser = m[1];\n _detected.version = m[2];\n }\n if (!_detected.browser) {\n m = ua.match(/Trident\\/.*rv:([0-9]{1,}[\\.0-9]{0,})/i); // IE11\n if (m !== null) {\n _detected.browser = 'msie';\n _detected.version = m[1];\n }\n }\n if (!_detected.browser) {\n m = ua.match(/(opr)\\/?\\s*(\\.?\\d+(\\.\\d+)*)/i); // Opera 15+\n if (m !== null) {\n _detected.browser = 'Opera';\n _detected.version = m[2];\n }\n }\n if (!_detected.browser) {\n m = ua.match(/(opera|chrome|safari|firefox|msie)\\/?\\s*(\\.?\\d+(\\.\\d+)*)/i);\n if (m !== null) {\n _detected.browser = m[1];\n _detected.version = m[2];\n m = ua.match(/version\\/([\\.\\d]+)/i);\n if (m !== null) _detected.version = m[1];\n }\n }\n if (!_detected.browser) {\n _detected.browser = navigator.appName;\n _detected.version = navigator.appVersion;\n }\n\n // keep major.minor version only..\n _detected.version = _detected.version.split(/\\W/).slice(0,2).join('.');\n\n // detect other browser capabilities\n // Legacy Opera has incomplete svg style support. See #715\n _detected.opera = (_detected.browser.toLowerCase() === 'opera' && parseFloat(_detected.version) < 15 );\n\n if (_detected.browser.toLowerCase() === 'msie') {\n _detected.ie = true;\n _detected.browser = 'Internet Explorer';\n _detected.support = parseFloat(_detected.version) >= 11;\n } else {\n _detected.ie = false;\n _detected.support = true;\n }\n\n _detected.filedrop = (window.FileReader && 'ondrop' in window);\n _detected.download = !(_detected.ie || _detected.browser.toLowerCase() === 'edge');\n _detected.cssfilters = !(_detected.ie || _detected.browser.toLowerCase() === 'edge');\n\n\n /* Platform */\n if (/Win/.test(ua)) {\n _detected.os = 'win';\n _detected.platform = 'Windows';\n } else if (/Mac/.test(ua)) {\n _detected.os = 'mac';\n _detected.platform = 'Macintosh';\n } else if (/X11/.test(ua) || /Linux/.test(ua)) {\n _detected.os = 'linux';\n _detected.platform = 'Linux';\n } else {\n _detected.os = 'win';\n _detected.platform = 'Unknown';\n }\n\n _detected.isMobileWebKit = (/\\b(iPad|iPhone|iPod)\\b/.test(ua) ||\n // HACK: iPadOS 13+ requests desktop sites by default by using a Mac user agent,\n // so assume any \"mac\" with multitouch is actually iOS\n (navigator.platform === 'MacIntel' && 'maxTouchPoints' in navigator && navigator.maxTouchPoints > 1)) &&\n /WebKit/.test(ua) &&\n !/Edge/.test(ua) &&\n !window.MSStream;\n\n\n /* Locale */\n // An array of locales requested by the browser in priority order.\n _detected.browserLocales = Array.from(new Set( // remove duplicates\n [navigator.language]\n .concat(navigator.languages || [])\n .concat([\n // old property for backwards compatibility\n navigator.userLanguage,\n // fallback to English\n 'en'\n ])\n // remove any undefined values\n .filter(Boolean)\n ));\n\n\n /* Host */\n const loc = window.top.location;\n let origin = loc.origin;\n if (!origin) { // for unpatched IE11\n origin = loc.protocol + '//' + loc.hostname + (loc.port ? ':' + loc.port: '');\n }\n\n _detected.host = origin + loc.pathname;\n\n\n return _detected;\n}\n","/*! MIT License. Copyright 2015-2018 Richard Moore . See LICENSE.txt. */\n(function(root) {\n \"use strict\";\n\n function checkInt(value) {\n return (parseInt(value) === value);\n }\n\n function checkInts(arrayish) {\n if (!checkInt(arrayish.length)) { return false; }\n\n for (var i = 0; i < arrayish.length; i++) {\n if (!checkInt(arrayish[i]) || arrayish[i] < 0 || arrayish[i] > 255) {\n return false;\n }\n }\n\n return true;\n }\n\n function coerceArray(arg, copy) {\n\n // ArrayBuffer view\n if (arg.buffer && arg.name === 'Uint8Array') {\n\n if (copy) {\n if (arg.slice) {\n arg = arg.slice();\n } else {\n arg = Array.prototype.slice.call(arg);\n }\n }\n\n return arg;\n }\n\n // It's an array; check it is a valid representation of a byte\n if (Array.isArray(arg)) {\n if (!checkInts(arg)) {\n throw new Error('Array contains invalid value: ' + arg);\n }\n\n return new Uint8Array(arg);\n }\n\n // Something else, but behaves like an array (maybe a Buffer? Arguments?)\n if (checkInt(arg.length) && checkInts(arg)) {\n return new Uint8Array(arg);\n }\n\n throw new Error('unsupported array-like object');\n }\n\n function createArray(length) {\n return new Uint8Array(length);\n }\n\n function copyArray(sourceArray, targetArray, targetStart, sourceStart, sourceEnd) {\n if (sourceStart != null || sourceEnd != null) {\n if (sourceArray.slice) {\n sourceArray = sourceArray.slice(sourceStart, sourceEnd);\n } else {\n sourceArray = Array.prototype.slice.call(sourceArray, sourceStart, sourceEnd);\n }\n }\n targetArray.set(sourceArray, targetStart);\n }\n\n\n\n var convertUtf8 = (function() {\n function toBytes(text) {\n var result = [], i = 0;\n text = encodeURI(text);\n while (i < text.length) {\n var c = text.charCodeAt(i++);\n\n // if it is a % sign, encode the following 2 bytes as a hex value\n if (c === 37) {\n result.push(parseInt(text.substr(i, 2), 16))\n i += 2;\n\n // otherwise, just the actual byte\n } else {\n result.push(c)\n }\n }\n\n return coerceArray(result);\n }\n\n function fromBytes(bytes) {\n var result = [], i = 0;\n\n while (i < bytes.length) {\n var c = bytes[i];\n\n if (c < 128) {\n result.push(String.fromCharCode(c));\n i++;\n } else if (c > 191 && c < 224) {\n result.push(String.fromCharCode(((c & 0x1f) << 6) | (bytes[i + 1] & 0x3f)));\n i += 2;\n } else {\n result.push(String.fromCharCode(((c & 0x0f) << 12) | ((bytes[i + 1] & 0x3f) << 6) | (bytes[i + 2] & 0x3f)));\n i += 3;\n }\n }\n\n return result.join('');\n }\n\n return {\n toBytes: toBytes,\n fromBytes: fromBytes,\n }\n })();\n\n var convertHex = (function() {\n function toBytes(text) {\n var result = [];\n for (var i = 0; i < text.length; i += 2) {\n result.push(parseInt(text.substr(i, 2), 16));\n }\n\n return result;\n }\n\n // http://ixti.net/development/javascript/2011/11/11/base64-encodedecode-of-utf8-in-browser-with-js.html\n var Hex = '0123456789abcdef';\n\n function fromBytes(bytes) {\n var result = [];\n for (var i = 0; i < bytes.length; i++) {\n var v = bytes[i];\n result.push(Hex[(v & 0xf0) >> 4] + Hex[v & 0x0f]);\n }\n return result.join('');\n }\n\n return {\n toBytes: toBytes,\n fromBytes: fromBytes,\n }\n })();\n\n\n // Number of rounds by keysize\n var numberOfRounds = {16: 10, 24: 12, 32: 14}\n\n // Round constant words\n var rcon = [0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91];\n\n // S-box and Inverse S-box (S is for Substitution)\n var S = [0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16];\n var Si =[0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e, 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84, 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73, 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4, 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61, 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d];\n\n // Transformations for encryption\n var T1 = [0xc66363a5, 0xf87c7c84, 0xee777799, 0xf67b7b8d, 0xfff2f20d, 0xd66b6bbd, 0xde6f6fb1, 0x91c5c554, 0x60303050, 0x02010103, 0xce6767a9, 0x562b2b7d, 0xe7fefe19, 0xb5d7d762, 0x4dababe6, 0xec76769a, 0x8fcaca45, 0x1f82829d, 0x89c9c940, 0xfa7d7d87, 0xeffafa15, 0xb25959eb, 0x8e4747c9, 0xfbf0f00b, 0x41adadec, 0xb3d4d467, 0x5fa2a2fd, 0x45afafea, 0x239c9cbf, 0x53a4a4f7, 0xe4727296, 0x9bc0c05b, 0x75b7b7c2, 0xe1fdfd1c, 0x3d9393ae, 0x4c26266a, 0x6c36365a, 0x7e3f3f41, 0xf5f7f702, 0x83cccc4f, 0x6834345c, 0x51a5a5f4, 0xd1e5e534, 0xf9f1f108, 0xe2717193, 0xabd8d873, 0x62313153, 0x2a15153f, 0x0804040c, 0x95c7c752, 0x46232365, 0x9dc3c35e, 0x30181828, 0x379696a1, 0x0a05050f, 0x2f9a9ab5, 0x0e070709, 0x24121236, 0x1b80809b, 0xdfe2e23d, 0xcdebeb26, 0x4e272769, 0x7fb2b2cd, 0xea75759f, 0x1209091b, 0x1d83839e, 0x582c2c74, 0x341a1a2e, 0x361b1b2d, 0xdc6e6eb2, 0xb45a5aee, 0x5ba0a0fb, 0xa45252f6, 0x763b3b4d, 0xb7d6d661, 0x7db3b3ce, 0x5229297b, 0xdde3e33e, 0x5e2f2f71, 0x13848497, 0xa65353f5, 0xb9d1d168, 0x00000000, 0xc1eded2c, 0x40202060, 0xe3fcfc1f, 0x79b1b1c8, 0xb65b5bed, 0xd46a6abe, 0x8dcbcb46, 0x67bebed9, 0x7239394b, 0x944a4ade, 0x984c4cd4, 0xb05858e8, 0x85cfcf4a, 0xbbd0d06b, 0xc5efef2a, 0x4faaaae5, 0xedfbfb16, 0x864343c5, 0x9a4d4dd7, 0x66333355, 0x11858594, 0x8a4545cf, 0xe9f9f910, 0x04020206, 0xfe7f7f81, 0xa05050f0, 0x783c3c44, 0x259f9fba, 0x4ba8a8e3, 0xa25151f3, 0x5da3a3fe, 0x804040c0, 0x058f8f8a, 0x3f9292ad, 0x219d9dbc, 0x70383848, 0xf1f5f504, 0x63bcbcdf, 0x77b6b6c1, 0xafdada75, 0x42212163, 0x20101030, 0xe5ffff1a, 0xfdf3f30e, 0xbfd2d26d, 0x81cdcd4c, 0x180c0c14, 0x26131335, 0xc3ecec2f, 0xbe5f5fe1, 0x359797a2, 0x884444cc, 0x2e171739, 0x93c4c457, 0x55a7a7f2, 0xfc7e7e82, 0x7a3d3d47, 0xc86464ac, 0xba5d5de7, 0x3219192b, 0xe6737395, 0xc06060a0, 0x19818198, 0x9e4f4fd1, 0xa3dcdc7f, 0x44222266, 0x542a2a7e, 0x3b9090ab, 0x0b888883, 0x8c4646ca, 0xc7eeee29, 0x6bb8b8d3, 0x2814143c, 0xa7dede79, 0xbc5e5ee2, 0x160b0b1d, 0xaddbdb76, 0xdbe0e03b, 0x64323256, 0x743a3a4e, 0x140a0a1e, 0x924949db, 0x0c06060a, 0x4824246c, 0xb85c5ce4, 0x9fc2c25d, 0xbdd3d36e, 0x43acacef, 0xc46262a6, 0x399191a8, 0x319595a4, 0xd3e4e437, 0xf279798b, 0xd5e7e732, 0x8bc8c843, 0x6e373759, 0xda6d6db7, 0x018d8d8c, 0xb1d5d564, 0x9c4e4ed2, 0x49a9a9e0, 0xd86c6cb4, 0xac5656fa, 0xf3f4f407, 0xcfeaea25, 0xca6565af, 0xf47a7a8e, 0x47aeaee9, 0x10080818, 0x6fbabad5, 0xf0787888, 0x4a25256f, 0x5c2e2e72, 0x381c1c24, 0x57a6a6f1, 0x73b4b4c7, 0x97c6c651, 0xcbe8e823, 0xa1dddd7c, 0xe874749c, 0x3e1f1f21, 0x964b4bdd, 0x61bdbddc, 0x0d8b8b86, 0x0f8a8a85, 0xe0707090, 0x7c3e3e42, 0x71b5b5c4, 0xcc6666aa, 0x904848d8, 0x06030305, 0xf7f6f601, 0x1c0e0e12, 0xc26161a3, 0x6a35355f, 0xae5757f9, 0x69b9b9d0, 0x17868691, 0x99c1c158, 0x3a1d1d27, 0x279e9eb9, 0xd9e1e138, 0xebf8f813, 0x2b9898b3, 0x22111133, 0xd26969bb, 0xa9d9d970, 0x078e8e89, 0x339494a7, 0x2d9b9bb6, 0x3c1e1e22, 0x15878792, 0xc9e9e920, 0x87cece49, 0xaa5555ff, 0x50282878, 0xa5dfdf7a, 0x038c8c8f, 0x59a1a1f8, 0x09898980, 0x1a0d0d17, 0x65bfbfda, 0xd7e6e631, 0x844242c6, 0xd06868b8, 0x824141c3, 0x299999b0, 0x5a2d2d77, 0x1e0f0f11, 0x7bb0b0cb, 0xa85454fc, 0x6dbbbbd6, 0x2c16163a];\n var T2 = [0xa5c66363, 0x84f87c7c, 0x99ee7777, 0x8df67b7b, 0x0dfff2f2, 0xbdd66b6b, 0xb1de6f6f, 0x5491c5c5, 0x50603030, 0x03020101, 0xa9ce6767, 0x7d562b2b, 0x19e7fefe, 0x62b5d7d7, 0xe64dabab, 0x9aec7676, 0x458fcaca, 0x9d1f8282, 0x4089c9c9, 0x87fa7d7d, 0x15effafa, 0xebb25959, 0xc98e4747, 0x0bfbf0f0, 0xec41adad, 0x67b3d4d4, 0xfd5fa2a2, 0xea45afaf, 0xbf239c9c, 0xf753a4a4, 0x96e47272, 0x5b9bc0c0, 0xc275b7b7, 0x1ce1fdfd, 0xae3d9393, 0x6a4c2626, 0x5a6c3636, 0x417e3f3f, 0x02f5f7f7, 0x4f83cccc, 0x5c683434, 0xf451a5a5, 0x34d1e5e5, 0x08f9f1f1, 0x93e27171, 0x73abd8d8, 0x53623131, 0x3f2a1515, 0x0c080404, 0x5295c7c7, 0x65462323, 0x5e9dc3c3, 0x28301818, 0xa1379696, 0x0f0a0505, 0xb52f9a9a, 0x090e0707, 0x36241212, 0x9b1b8080, 0x3ddfe2e2, 0x26cdebeb, 0x694e2727, 0xcd7fb2b2, 0x9fea7575, 0x1b120909, 0x9e1d8383, 0x74582c2c, 0x2e341a1a, 0x2d361b1b, 0xb2dc6e6e, 0xeeb45a5a, 0xfb5ba0a0, 0xf6a45252, 0x4d763b3b, 0x61b7d6d6, 0xce7db3b3, 0x7b522929, 0x3edde3e3, 0x715e2f2f, 0x97138484, 0xf5a65353, 0x68b9d1d1, 0x00000000, 0x2cc1eded, 0x60402020, 0x1fe3fcfc, 0xc879b1b1, 0xedb65b5b, 0xbed46a6a, 0x468dcbcb, 0xd967bebe, 0x4b723939, 0xde944a4a, 0xd4984c4c, 0xe8b05858, 0x4a85cfcf, 0x6bbbd0d0, 0x2ac5efef, 0xe54faaaa, 0x16edfbfb, 0xc5864343, 0xd79a4d4d, 0x55663333, 0x94118585, 0xcf8a4545, 0x10e9f9f9, 0x06040202, 0x81fe7f7f, 0xf0a05050, 0x44783c3c, 0xba259f9f, 0xe34ba8a8, 0xf3a25151, 0xfe5da3a3, 0xc0804040, 0x8a058f8f, 0xad3f9292, 0xbc219d9d, 0x48703838, 0x04f1f5f5, 0xdf63bcbc, 0xc177b6b6, 0x75afdada, 0x63422121, 0x30201010, 0x1ae5ffff, 0x0efdf3f3, 0x6dbfd2d2, 0x4c81cdcd, 0x14180c0c, 0x35261313, 0x2fc3ecec, 0xe1be5f5f, 0xa2359797, 0xcc884444, 0x392e1717, 0x5793c4c4, 0xf255a7a7, 0x82fc7e7e, 0x477a3d3d, 0xacc86464, 0xe7ba5d5d, 0x2b321919, 0x95e67373, 0xa0c06060, 0x98198181, 0xd19e4f4f, 0x7fa3dcdc, 0x66442222, 0x7e542a2a, 0xab3b9090, 0x830b8888, 0xca8c4646, 0x29c7eeee, 0xd36bb8b8, 0x3c281414, 0x79a7dede, 0xe2bc5e5e, 0x1d160b0b, 0x76addbdb, 0x3bdbe0e0, 0x56643232, 0x4e743a3a, 0x1e140a0a, 0xdb924949, 0x0a0c0606, 0x6c482424, 0xe4b85c5c, 0x5d9fc2c2, 0x6ebdd3d3, 0xef43acac, 0xa6c46262, 0xa8399191, 0xa4319595, 0x37d3e4e4, 0x8bf27979, 0x32d5e7e7, 0x438bc8c8, 0x596e3737, 0xb7da6d6d, 0x8c018d8d, 0x64b1d5d5, 0xd29c4e4e, 0xe049a9a9, 0xb4d86c6c, 0xfaac5656, 0x07f3f4f4, 0x25cfeaea, 0xafca6565, 0x8ef47a7a, 0xe947aeae, 0x18100808, 0xd56fbaba, 0x88f07878, 0x6f4a2525, 0x725c2e2e, 0x24381c1c, 0xf157a6a6, 0xc773b4b4, 0x5197c6c6, 0x23cbe8e8, 0x7ca1dddd, 0x9ce87474, 0x213e1f1f, 0xdd964b4b, 0xdc61bdbd, 0x860d8b8b, 0x850f8a8a, 0x90e07070, 0x427c3e3e, 0xc471b5b5, 0xaacc6666, 0xd8904848, 0x05060303, 0x01f7f6f6, 0x121c0e0e, 0xa3c26161, 0x5f6a3535, 0xf9ae5757, 0xd069b9b9, 0x91178686, 0x5899c1c1, 0x273a1d1d, 0xb9279e9e, 0x38d9e1e1, 0x13ebf8f8, 0xb32b9898, 0x33221111, 0xbbd26969, 0x70a9d9d9, 0x89078e8e, 0xa7339494, 0xb62d9b9b, 0x223c1e1e, 0x92158787, 0x20c9e9e9, 0x4987cece, 0xffaa5555, 0x78502828, 0x7aa5dfdf, 0x8f038c8c, 0xf859a1a1, 0x80098989, 0x171a0d0d, 0xda65bfbf, 0x31d7e6e6, 0xc6844242, 0xb8d06868, 0xc3824141, 0xb0299999, 0x775a2d2d, 0x111e0f0f, 0xcb7bb0b0, 0xfca85454, 0xd66dbbbb, 0x3a2c1616];\n var T3 = [0x63a5c663, 0x7c84f87c, 0x7799ee77, 0x7b8df67b, 0xf20dfff2, 0x6bbdd66b, 0x6fb1de6f, 0xc55491c5, 0x30506030, 0x01030201, 0x67a9ce67, 0x2b7d562b, 0xfe19e7fe, 0xd762b5d7, 0xabe64dab, 0x769aec76, 0xca458fca, 0x829d1f82, 0xc94089c9, 0x7d87fa7d, 0xfa15effa, 0x59ebb259, 0x47c98e47, 0xf00bfbf0, 0xadec41ad, 0xd467b3d4, 0xa2fd5fa2, 0xafea45af, 0x9cbf239c, 0xa4f753a4, 0x7296e472, 0xc05b9bc0, 0xb7c275b7, 0xfd1ce1fd, 0x93ae3d93, 0x266a4c26, 0x365a6c36, 0x3f417e3f, 0xf702f5f7, 0xcc4f83cc, 0x345c6834, 0xa5f451a5, 0xe534d1e5, 0xf108f9f1, 0x7193e271, 0xd873abd8, 0x31536231, 0x153f2a15, 0x040c0804, 0xc75295c7, 0x23654623, 0xc35e9dc3, 0x18283018, 0x96a13796, 0x050f0a05, 0x9ab52f9a, 0x07090e07, 0x12362412, 0x809b1b80, 0xe23ddfe2, 0xeb26cdeb, 0x27694e27, 0xb2cd7fb2, 0x759fea75, 0x091b1209, 0x839e1d83, 0x2c74582c, 0x1a2e341a, 0x1b2d361b, 0x6eb2dc6e, 0x5aeeb45a, 0xa0fb5ba0, 0x52f6a452, 0x3b4d763b, 0xd661b7d6, 0xb3ce7db3, 0x297b5229, 0xe33edde3, 0x2f715e2f, 0x84971384, 0x53f5a653, 0xd168b9d1, 0x00000000, 0xed2cc1ed, 0x20604020, 0xfc1fe3fc, 0xb1c879b1, 0x5bedb65b, 0x6abed46a, 0xcb468dcb, 0xbed967be, 0x394b7239, 0x4ade944a, 0x4cd4984c, 0x58e8b058, 0xcf4a85cf, 0xd06bbbd0, 0xef2ac5ef, 0xaae54faa, 0xfb16edfb, 0x43c58643, 0x4dd79a4d, 0x33556633, 0x85941185, 0x45cf8a45, 0xf910e9f9, 0x02060402, 0x7f81fe7f, 0x50f0a050, 0x3c44783c, 0x9fba259f, 0xa8e34ba8, 0x51f3a251, 0xa3fe5da3, 0x40c08040, 0x8f8a058f, 0x92ad3f92, 0x9dbc219d, 0x38487038, 0xf504f1f5, 0xbcdf63bc, 0xb6c177b6, 0xda75afda, 0x21634221, 0x10302010, 0xff1ae5ff, 0xf30efdf3, 0xd26dbfd2, 0xcd4c81cd, 0x0c14180c, 0x13352613, 0xec2fc3ec, 0x5fe1be5f, 0x97a23597, 0x44cc8844, 0x17392e17, 0xc45793c4, 0xa7f255a7, 0x7e82fc7e, 0x3d477a3d, 0x64acc864, 0x5de7ba5d, 0x192b3219, 0x7395e673, 0x60a0c060, 0x81981981, 0x4fd19e4f, 0xdc7fa3dc, 0x22664422, 0x2a7e542a, 0x90ab3b90, 0x88830b88, 0x46ca8c46, 0xee29c7ee, 0xb8d36bb8, 0x143c2814, 0xde79a7de, 0x5ee2bc5e, 0x0b1d160b, 0xdb76addb, 0xe03bdbe0, 0x32566432, 0x3a4e743a, 0x0a1e140a, 0x49db9249, 0x060a0c06, 0x246c4824, 0x5ce4b85c, 0xc25d9fc2, 0xd36ebdd3, 0xacef43ac, 0x62a6c462, 0x91a83991, 0x95a43195, 0xe437d3e4, 0x798bf279, 0xe732d5e7, 0xc8438bc8, 0x37596e37, 0x6db7da6d, 0x8d8c018d, 0xd564b1d5, 0x4ed29c4e, 0xa9e049a9, 0x6cb4d86c, 0x56faac56, 0xf407f3f4, 0xea25cfea, 0x65afca65, 0x7a8ef47a, 0xaee947ae, 0x08181008, 0xbad56fba, 0x7888f078, 0x256f4a25, 0x2e725c2e, 0x1c24381c, 0xa6f157a6, 0xb4c773b4, 0xc65197c6, 0xe823cbe8, 0xdd7ca1dd, 0x749ce874, 0x1f213e1f, 0x4bdd964b, 0xbddc61bd, 0x8b860d8b, 0x8a850f8a, 0x7090e070, 0x3e427c3e, 0xb5c471b5, 0x66aacc66, 0x48d89048, 0x03050603, 0xf601f7f6, 0x0e121c0e, 0x61a3c261, 0x355f6a35, 0x57f9ae57, 0xb9d069b9, 0x86911786, 0xc15899c1, 0x1d273a1d, 0x9eb9279e, 0xe138d9e1, 0xf813ebf8, 0x98b32b98, 0x11332211, 0x69bbd269, 0xd970a9d9, 0x8e89078e, 0x94a73394, 0x9bb62d9b, 0x1e223c1e, 0x87921587, 0xe920c9e9, 0xce4987ce, 0x55ffaa55, 0x28785028, 0xdf7aa5df, 0x8c8f038c, 0xa1f859a1, 0x89800989, 0x0d171a0d, 0xbfda65bf, 0xe631d7e6, 0x42c68442, 0x68b8d068, 0x41c38241, 0x99b02999, 0x2d775a2d, 0x0f111e0f, 0xb0cb7bb0, 0x54fca854, 0xbbd66dbb, 0x163a2c16];\n var T4 = [0x6363a5c6, 0x7c7c84f8, 0x777799ee, 0x7b7b8df6, 0xf2f20dff, 0x6b6bbdd6, 0x6f6fb1de, 0xc5c55491, 0x30305060, 0x01010302, 0x6767a9ce, 0x2b2b7d56, 0xfefe19e7, 0xd7d762b5, 0xababe64d, 0x76769aec, 0xcaca458f, 0x82829d1f, 0xc9c94089, 0x7d7d87fa, 0xfafa15ef, 0x5959ebb2, 0x4747c98e, 0xf0f00bfb, 0xadadec41, 0xd4d467b3, 0xa2a2fd5f, 0xafafea45, 0x9c9cbf23, 0xa4a4f753, 0x727296e4, 0xc0c05b9b, 0xb7b7c275, 0xfdfd1ce1, 0x9393ae3d, 0x26266a4c, 0x36365a6c, 0x3f3f417e, 0xf7f702f5, 0xcccc4f83, 0x34345c68, 0xa5a5f451, 0xe5e534d1, 0xf1f108f9, 0x717193e2, 0xd8d873ab, 0x31315362, 0x15153f2a, 0x04040c08, 0xc7c75295, 0x23236546, 0xc3c35e9d, 0x18182830, 0x9696a137, 0x05050f0a, 0x9a9ab52f, 0x0707090e, 0x12123624, 0x80809b1b, 0xe2e23ddf, 0xebeb26cd, 0x2727694e, 0xb2b2cd7f, 0x75759fea, 0x09091b12, 0x83839e1d, 0x2c2c7458, 0x1a1a2e34, 0x1b1b2d36, 0x6e6eb2dc, 0x5a5aeeb4, 0xa0a0fb5b, 0x5252f6a4, 0x3b3b4d76, 0xd6d661b7, 0xb3b3ce7d, 0x29297b52, 0xe3e33edd, 0x2f2f715e, 0x84849713, 0x5353f5a6, 0xd1d168b9, 0x00000000, 0xeded2cc1, 0x20206040, 0xfcfc1fe3, 0xb1b1c879, 0x5b5bedb6, 0x6a6abed4, 0xcbcb468d, 0xbebed967, 0x39394b72, 0x4a4ade94, 0x4c4cd498, 0x5858e8b0, 0xcfcf4a85, 0xd0d06bbb, 0xefef2ac5, 0xaaaae54f, 0xfbfb16ed, 0x4343c586, 0x4d4dd79a, 0x33335566, 0x85859411, 0x4545cf8a, 0xf9f910e9, 0x02020604, 0x7f7f81fe, 0x5050f0a0, 0x3c3c4478, 0x9f9fba25, 0xa8a8e34b, 0x5151f3a2, 0xa3a3fe5d, 0x4040c080, 0x8f8f8a05, 0x9292ad3f, 0x9d9dbc21, 0x38384870, 0xf5f504f1, 0xbcbcdf63, 0xb6b6c177, 0xdada75af, 0x21216342, 0x10103020, 0xffff1ae5, 0xf3f30efd, 0xd2d26dbf, 0xcdcd4c81, 0x0c0c1418, 0x13133526, 0xecec2fc3, 0x5f5fe1be, 0x9797a235, 0x4444cc88, 0x1717392e, 0xc4c45793, 0xa7a7f255, 0x7e7e82fc, 0x3d3d477a, 0x6464acc8, 0x5d5de7ba, 0x19192b32, 0x737395e6, 0x6060a0c0, 0x81819819, 0x4f4fd19e, 0xdcdc7fa3, 0x22226644, 0x2a2a7e54, 0x9090ab3b, 0x8888830b, 0x4646ca8c, 0xeeee29c7, 0xb8b8d36b, 0x14143c28, 0xdede79a7, 0x5e5ee2bc, 0x0b0b1d16, 0xdbdb76ad, 0xe0e03bdb, 0x32325664, 0x3a3a4e74, 0x0a0a1e14, 0x4949db92, 0x06060a0c, 0x24246c48, 0x5c5ce4b8, 0xc2c25d9f, 0xd3d36ebd, 0xacacef43, 0x6262a6c4, 0x9191a839, 0x9595a431, 0xe4e437d3, 0x79798bf2, 0xe7e732d5, 0xc8c8438b, 0x3737596e, 0x6d6db7da, 0x8d8d8c01, 0xd5d564b1, 0x4e4ed29c, 0xa9a9e049, 0x6c6cb4d8, 0x5656faac, 0xf4f407f3, 0xeaea25cf, 0x6565afca, 0x7a7a8ef4, 0xaeaee947, 0x08081810, 0xbabad56f, 0x787888f0, 0x25256f4a, 0x2e2e725c, 0x1c1c2438, 0xa6a6f157, 0xb4b4c773, 0xc6c65197, 0xe8e823cb, 0xdddd7ca1, 0x74749ce8, 0x1f1f213e, 0x4b4bdd96, 0xbdbddc61, 0x8b8b860d, 0x8a8a850f, 0x707090e0, 0x3e3e427c, 0xb5b5c471, 0x6666aacc, 0x4848d890, 0x03030506, 0xf6f601f7, 0x0e0e121c, 0x6161a3c2, 0x35355f6a, 0x5757f9ae, 0xb9b9d069, 0x86869117, 0xc1c15899, 0x1d1d273a, 0x9e9eb927, 0xe1e138d9, 0xf8f813eb, 0x9898b32b, 0x11113322, 0x6969bbd2, 0xd9d970a9, 0x8e8e8907, 0x9494a733, 0x9b9bb62d, 0x1e1e223c, 0x87879215, 0xe9e920c9, 0xcece4987, 0x5555ffaa, 0x28287850, 0xdfdf7aa5, 0x8c8c8f03, 0xa1a1f859, 0x89898009, 0x0d0d171a, 0xbfbfda65, 0xe6e631d7, 0x4242c684, 0x6868b8d0, 0x4141c382, 0x9999b029, 0x2d2d775a, 0x0f0f111e, 0xb0b0cb7b, 0x5454fca8, 0xbbbbd66d, 0x16163a2c];\n\n // Transformations for decryption\n var T5 = [0x51f4a750, 0x7e416553, 0x1a17a4c3, 0x3a275e96, 0x3bab6bcb, 0x1f9d45f1, 0xacfa58ab, 0x4be30393, 0x2030fa55, 0xad766df6, 0x88cc7691, 0xf5024c25, 0x4fe5d7fc, 0xc52acbd7, 0x26354480, 0xb562a38f, 0xdeb15a49, 0x25ba1b67, 0x45ea0e98, 0x5dfec0e1, 0xc32f7502, 0x814cf012, 0x8d4697a3, 0x6bd3f9c6, 0x038f5fe7, 0x15929c95, 0xbf6d7aeb, 0x955259da, 0xd4be832d, 0x587421d3, 0x49e06929, 0x8ec9c844, 0x75c2896a, 0xf48e7978, 0x99583e6b, 0x27b971dd, 0xbee14fb6, 0xf088ad17, 0xc920ac66, 0x7dce3ab4, 0x63df4a18, 0xe51a3182, 0x97513360, 0x62537f45, 0xb16477e0, 0xbb6bae84, 0xfe81a01c, 0xf9082b94, 0x70486858, 0x8f45fd19, 0x94de6c87, 0x527bf8b7, 0xab73d323, 0x724b02e2, 0xe31f8f57, 0x6655ab2a, 0xb2eb2807, 0x2fb5c203, 0x86c57b9a, 0xd33708a5, 0x302887f2, 0x23bfa5b2, 0x02036aba, 0xed16825c, 0x8acf1c2b, 0xa779b492, 0xf307f2f0, 0x4e69e2a1, 0x65daf4cd, 0x0605bed5, 0xd134621f, 0xc4a6fe8a, 0x342e539d, 0xa2f355a0, 0x058ae132, 0xa4f6eb75, 0x0b83ec39, 0x4060efaa, 0x5e719f06, 0xbd6e1051, 0x3e218af9, 0x96dd063d, 0xdd3e05ae, 0x4de6bd46, 0x91548db5, 0x71c45d05, 0x0406d46f, 0x605015ff, 0x1998fb24, 0xd6bde997, 0x894043cc, 0x67d99e77, 0xb0e842bd, 0x07898b88, 0xe7195b38, 0x79c8eedb, 0xa17c0a47, 0x7c420fe9, 0xf8841ec9, 0x00000000, 0x09808683, 0x322bed48, 0x1e1170ac, 0x6c5a724e, 0xfd0efffb, 0x0f853856, 0x3daed51e, 0x362d3927, 0x0a0fd964, 0x685ca621, 0x9b5b54d1, 0x24362e3a, 0x0c0a67b1, 0x9357e70f, 0xb4ee96d2, 0x1b9b919e, 0x80c0c54f, 0x61dc20a2, 0x5a774b69, 0x1c121a16, 0xe293ba0a, 0xc0a02ae5, 0x3c22e043, 0x121b171d, 0x0e090d0b, 0xf28bc7ad, 0x2db6a8b9, 0x141ea9c8, 0x57f11985, 0xaf75074c, 0xee99ddbb, 0xa37f60fd, 0xf701269f, 0x5c72f5bc, 0x44663bc5, 0x5bfb7e34, 0x8b432976, 0xcb23c6dc, 0xb6edfc68, 0xb8e4f163, 0xd731dcca, 0x42638510, 0x13972240, 0x84c61120, 0x854a247d, 0xd2bb3df8, 0xaef93211, 0xc729a16d, 0x1d9e2f4b, 0xdcb230f3, 0x0d8652ec, 0x77c1e3d0, 0x2bb3166c, 0xa970b999, 0x119448fa, 0x47e96422, 0xa8fc8cc4, 0xa0f03f1a, 0x567d2cd8, 0x223390ef, 0x87494ec7, 0xd938d1c1, 0x8ccaa2fe, 0x98d40b36, 0xa6f581cf, 0xa57ade28, 0xdab78e26, 0x3fadbfa4, 0x2c3a9de4, 0x5078920d, 0x6a5fcc9b, 0x547e4662, 0xf68d13c2, 0x90d8b8e8, 0x2e39f75e, 0x82c3aff5, 0x9f5d80be, 0x69d0937c, 0x6fd52da9, 0xcf2512b3, 0xc8ac993b, 0x10187da7, 0xe89c636e, 0xdb3bbb7b, 0xcd267809, 0x6e5918f4, 0xec9ab701, 0x834f9aa8, 0xe6956e65, 0xaaffe67e, 0x21bccf08, 0xef15e8e6, 0xbae79bd9, 0x4a6f36ce, 0xea9f09d4, 0x29b07cd6, 0x31a4b2af, 0x2a3f2331, 0xc6a59430, 0x35a266c0, 0x744ebc37, 0xfc82caa6, 0xe090d0b0, 0x33a7d815, 0xf104984a, 0x41ecdaf7, 0x7fcd500e, 0x1791f62f, 0x764dd68d, 0x43efb04d, 0xccaa4d54, 0xe49604df, 0x9ed1b5e3, 0x4c6a881b, 0xc12c1fb8, 0x4665517f, 0x9d5eea04, 0x018c355d, 0xfa877473, 0xfb0b412e, 0xb3671d5a, 0x92dbd252, 0xe9105633, 0x6dd64713, 0x9ad7618c, 0x37a10c7a, 0x59f8148e, 0xeb133c89, 0xcea927ee, 0xb761c935, 0xe11ce5ed, 0x7a47b13c, 0x9cd2df59, 0x55f2733f, 0x1814ce79, 0x73c737bf, 0x53f7cdea, 0x5ffdaa5b, 0xdf3d6f14, 0x7844db86, 0xcaaff381, 0xb968c43e, 0x3824342c, 0xc2a3405f, 0x161dc372, 0xbce2250c, 0x283c498b, 0xff0d9541, 0x39a80171, 0x080cb3de, 0xd8b4e49c, 0x6456c190, 0x7bcb8461, 0xd532b670, 0x486c5c74, 0xd0b85742];\n var T6 = [0x5051f4a7, 0x537e4165, 0xc31a17a4, 0x963a275e, 0xcb3bab6b, 0xf11f9d45, 0xabacfa58, 0x934be303, 0x552030fa, 0xf6ad766d, 0x9188cc76, 0x25f5024c, 0xfc4fe5d7, 0xd7c52acb, 0x80263544, 0x8fb562a3, 0x49deb15a, 0x6725ba1b, 0x9845ea0e, 0xe15dfec0, 0x02c32f75, 0x12814cf0, 0xa38d4697, 0xc66bd3f9, 0xe7038f5f, 0x9515929c, 0xebbf6d7a, 0xda955259, 0x2dd4be83, 0xd3587421, 0x2949e069, 0x448ec9c8, 0x6a75c289, 0x78f48e79, 0x6b99583e, 0xdd27b971, 0xb6bee14f, 0x17f088ad, 0x66c920ac, 0xb47dce3a, 0x1863df4a, 0x82e51a31, 0x60975133, 0x4562537f, 0xe0b16477, 0x84bb6bae, 0x1cfe81a0, 0x94f9082b, 0x58704868, 0x198f45fd, 0x8794de6c, 0xb7527bf8, 0x23ab73d3, 0xe2724b02, 0x57e31f8f, 0x2a6655ab, 0x07b2eb28, 0x032fb5c2, 0x9a86c57b, 0xa5d33708, 0xf2302887, 0xb223bfa5, 0xba02036a, 0x5ced1682, 0x2b8acf1c, 0x92a779b4, 0xf0f307f2, 0xa14e69e2, 0xcd65daf4, 0xd50605be, 0x1fd13462, 0x8ac4a6fe, 0x9d342e53, 0xa0a2f355, 0x32058ae1, 0x75a4f6eb, 0x390b83ec, 0xaa4060ef, 0x065e719f, 0x51bd6e10, 0xf93e218a, 0x3d96dd06, 0xaedd3e05, 0x464de6bd, 0xb591548d, 0x0571c45d, 0x6f0406d4, 0xff605015, 0x241998fb, 0x97d6bde9, 0xcc894043, 0x7767d99e, 0xbdb0e842, 0x8807898b, 0x38e7195b, 0xdb79c8ee, 0x47a17c0a, 0xe97c420f, 0xc9f8841e, 0x00000000, 0x83098086, 0x48322bed, 0xac1e1170, 0x4e6c5a72, 0xfbfd0eff, 0x560f8538, 0x1e3daed5, 0x27362d39, 0x640a0fd9, 0x21685ca6, 0xd19b5b54, 0x3a24362e, 0xb10c0a67, 0x0f9357e7, 0xd2b4ee96, 0x9e1b9b91, 0x4f80c0c5, 0xa261dc20, 0x695a774b, 0x161c121a, 0x0ae293ba, 0xe5c0a02a, 0x433c22e0, 0x1d121b17, 0x0b0e090d, 0xadf28bc7, 0xb92db6a8, 0xc8141ea9, 0x8557f119, 0x4caf7507, 0xbbee99dd, 0xfda37f60, 0x9ff70126, 0xbc5c72f5, 0xc544663b, 0x345bfb7e, 0x768b4329, 0xdccb23c6, 0x68b6edfc, 0x63b8e4f1, 0xcad731dc, 0x10426385, 0x40139722, 0x2084c611, 0x7d854a24, 0xf8d2bb3d, 0x11aef932, 0x6dc729a1, 0x4b1d9e2f, 0xf3dcb230, 0xec0d8652, 0xd077c1e3, 0x6c2bb316, 0x99a970b9, 0xfa119448, 0x2247e964, 0xc4a8fc8c, 0x1aa0f03f, 0xd8567d2c, 0xef223390, 0xc787494e, 0xc1d938d1, 0xfe8ccaa2, 0x3698d40b, 0xcfa6f581, 0x28a57ade, 0x26dab78e, 0xa43fadbf, 0xe42c3a9d, 0x0d507892, 0x9b6a5fcc, 0x62547e46, 0xc2f68d13, 0xe890d8b8, 0x5e2e39f7, 0xf582c3af, 0xbe9f5d80, 0x7c69d093, 0xa96fd52d, 0xb3cf2512, 0x3bc8ac99, 0xa710187d, 0x6ee89c63, 0x7bdb3bbb, 0x09cd2678, 0xf46e5918, 0x01ec9ab7, 0xa8834f9a, 0x65e6956e, 0x7eaaffe6, 0x0821bccf, 0xe6ef15e8, 0xd9bae79b, 0xce4a6f36, 0xd4ea9f09, 0xd629b07c, 0xaf31a4b2, 0x312a3f23, 0x30c6a594, 0xc035a266, 0x37744ebc, 0xa6fc82ca, 0xb0e090d0, 0x1533a7d8, 0x4af10498, 0xf741ecda, 0x0e7fcd50, 0x2f1791f6, 0x8d764dd6, 0x4d43efb0, 0x54ccaa4d, 0xdfe49604, 0xe39ed1b5, 0x1b4c6a88, 0xb8c12c1f, 0x7f466551, 0x049d5eea, 0x5d018c35, 0x73fa8774, 0x2efb0b41, 0x5ab3671d, 0x5292dbd2, 0x33e91056, 0x136dd647, 0x8c9ad761, 0x7a37a10c, 0x8e59f814, 0x89eb133c, 0xeecea927, 0x35b761c9, 0xede11ce5, 0x3c7a47b1, 0x599cd2df, 0x3f55f273, 0x791814ce, 0xbf73c737, 0xea53f7cd, 0x5b5ffdaa, 0x14df3d6f, 0x867844db, 0x81caaff3, 0x3eb968c4, 0x2c382434, 0x5fc2a340, 0x72161dc3, 0x0cbce225, 0x8b283c49, 0x41ff0d95, 0x7139a801, 0xde080cb3, 0x9cd8b4e4, 0x906456c1, 0x617bcb84, 0x70d532b6, 0x74486c5c, 0x42d0b857];\n var T7 = [0xa75051f4, 0x65537e41, 0xa4c31a17, 0x5e963a27, 0x6bcb3bab, 0x45f11f9d, 0x58abacfa, 0x03934be3, 0xfa552030, 0x6df6ad76, 0x769188cc, 0x4c25f502, 0xd7fc4fe5, 0xcbd7c52a, 0x44802635, 0xa38fb562, 0x5a49deb1, 0x1b6725ba, 0x0e9845ea, 0xc0e15dfe, 0x7502c32f, 0xf012814c, 0x97a38d46, 0xf9c66bd3, 0x5fe7038f, 0x9c951592, 0x7aebbf6d, 0x59da9552, 0x832dd4be, 0x21d35874, 0x692949e0, 0xc8448ec9, 0x896a75c2, 0x7978f48e, 0x3e6b9958, 0x71dd27b9, 0x4fb6bee1, 0xad17f088, 0xac66c920, 0x3ab47dce, 0x4a1863df, 0x3182e51a, 0x33609751, 0x7f456253, 0x77e0b164, 0xae84bb6b, 0xa01cfe81, 0x2b94f908, 0x68587048, 0xfd198f45, 0x6c8794de, 0xf8b7527b, 0xd323ab73, 0x02e2724b, 0x8f57e31f, 0xab2a6655, 0x2807b2eb, 0xc2032fb5, 0x7b9a86c5, 0x08a5d337, 0x87f23028, 0xa5b223bf, 0x6aba0203, 0x825ced16, 0x1c2b8acf, 0xb492a779, 0xf2f0f307, 0xe2a14e69, 0xf4cd65da, 0xbed50605, 0x621fd134, 0xfe8ac4a6, 0x539d342e, 0x55a0a2f3, 0xe132058a, 0xeb75a4f6, 0xec390b83, 0xefaa4060, 0x9f065e71, 0x1051bd6e, 0x8af93e21, 0x063d96dd, 0x05aedd3e, 0xbd464de6, 0x8db59154, 0x5d0571c4, 0xd46f0406, 0x15ff6050, 0xfb241998, 0xe997d6bd, 0x43cc8940, 0x9e7767d9, 0x42bdb0e8, 0x8b880789, 0x5b38e719, 0xeedb79c8, 0x0a47a17c, 0x0fe97c42, 0x1ec9f884, 0x00000000, 0x86830980, 0xed48322b, 0x70ac1e11, 0x724e6c5a, 0xfffbfd0e, 0x38560f85, 0xd51e3dae, 0x3927362d, 0xd9640a0f, 0xa621685c, 0x54d19b5b, 0x2e3a2436, 0x67b10c0a, 0xe70f9357, 0x96d2b4ee, 0x919e1b9b, 0xc54f80c0, 0x20a261dc, 0x4b695a77, 0x1a161c12, 0xba0ae293, 0x2ae5c0a0, 0xe0433c22, 0x171d121b, 0x0d0b0e09, 0xc7adf28b, 0xa8b92db6, 0xa9c8141e, 0x198557f1, 0x074caf75, 0xddbbee99, 0x60fda37f, 0x269ff701, 0xf5bc5c72, 0x3bc54466, 0x7e345bfb, 0x29768b43, 0xc6dccb23, 0xfc68b6ed, 0xf163b8e4, 0xdccad731, 0x85104263, 0x22401397, 0x112084c6, 0x247d854a, 0x3df8d2bb, 0x3211aef9, 0xa16dc729, 0x2f4b1d9e, 0x30f3dcb2, 0x52ec0d86, 0xe3d077c1, 0x166c2bb3, 0xb999a970, 0x48fa1194, 0x642247e9, 0x8cc4a8fc, 0x3f1aa0f0, 0x2cd8567d, 0x90ef2233, 0x4ec78749, 0xd1c1d938, 0xa2fe8cca, 0x0b3698d4, 0x81cfa6f5, 0xde28a57a, 0x8e26dab7, 0xbfa43fad, 0x9de42c3a, 0x920d5078, 0xcc9b6a5f, 0x4662547e, 0x13c2f68d, 0xb8e890d8, 0xf75e2e39, 0xaff582c3, 0x80be9f5d, 0x937c69d0, 0x2da96fd5, 0x12b3cf25, 0x993bc8ac, 0x7da71018, 0x636ee89c, 0xbb7bdb3b, 0x7809cd26, 0x18f46e59, 0xb701ec9a, 0x9aa8834f, 0x6e65e695, 0xe67eaaff, 0xcf0821bc, 0xe8e6ef15, 0x9bd9bae7, 0x36ce4a6f, 0x09d4ea9f, 0x7cd629b0, 0xb2af31a4, 0x23312a3f, 0x9430c6a5, 0x66c035a2, 0xbc37744e, 0xcaa6fc82, 0xd0b0e090, 0xd81533a7, 0x984af104, 0xdaf741ec, 0x500e7fcd, 0xf62f1791, 0xd68d764d, 0xb04d43ef, 0x4d54ccaa, 0x04dfe496, 0xb5e39ed1, 0x881b4c6a, 0x1fb8c12c, 0x517f4665, 0xea049d5e, 0x355d018c, 0x7473fa87, 0x412efb0b, 0x1d5ab367, 0xd25292db, 0x5633e910, 0x47136dd6, 0x618c9ad7, 0x0c7a37a1, 0x148e59f8, 0x3c89eb13, 0x27eecea9, 0xc935b761, 0xe5ede11c, 0xb13c7a47, 0xdf599cd2, 0x733f55f2, 0xce791814, 0x37bf73c7, 0xcdea53f7, 0xaa5b5ffd, 0x6f14df3d, 0xdb867844, 0xf381caaf, 0xc43eb968, 0x342c3824, 0x405fc2a3, 0xc372161d, 0x250cbce2, 0x498b283c, 0x9541ff0d, 0x017139a8, 0xb3de080c, 0xe49cd8b4, 0xc1906456, 0x84617bcb, 0xb670d532, 0x5c74486c, 0x5742d0b8];\n var T8 = [0xf4a75051, 0x4165537e, 0x17a4c31a, 0x275e963a, 0xab6bcb3b, 0x9d45f11f, 0xfa58abac, 0xe303934b, 0x30fa5520, 0x766df6ad, 0xcc769188, 0x024c25f5, 0xe5d7fc4f, 0x2acbd7c5, 0x35448026, 0x62a38fb5, 0xb15a49de, 0xba1b6725, 0xea0e9845, 0xfec0e15d, 0x2f7502c3, 0x4cf01281, 0x4697a38d, 0xd3f9c66b, 0x8f5fe703, 0x929c9515, 0x6d7aebbf, 0x5259da95, 0xbe832dd4, 0x7421d358, 0xe0692949, 0xc9c8448e, 0xc2896a75, 0x8e7978f4, 0x583e6b99, 0xb971dd27, 0xe14fb6be, 0x88ad17f0, 0x20ac66c9, 0xce3ab47d, 0xdf4a1863, 0x1a3182e5, 0x51336097, 0x537f4562, 0x6477e0b1, 0x6bae84bb, 0x81a01cfe, 0x082b94f9, 0x48685870, 0x45fd198f, 0xde6c8794, 0x7bf8b752, 0x73d323ab, 0x4b02e272, 0x1f8f57e3, 0x55ab2a66, 0xeb2807b2, 0xb5c2032f, 0xc57b9a86, 0x3708a5d3, 0x2887f230, 0xbfa5b223, 0x036aba02, 0x16825ced, 0xcf1c2b8a, 0x79b492a7, 0x07f2f0f3, 0x69e2a14e, 0xdaf4cd65, 0x05bed506, 0x34621fd1, 0xa6fe8ac4, 0x2e539d34, 0xf355a0a2, 0x8ae13205, 0xf6eb75a4, 0x83ec390b, 0x60efaa40, 0x719f065e, 0x6e1051bd, 0x218af93e, 0xdd063d96, 0x3e05aedd, 0xe6bd464d, 0x548db591, 0xc45d0571, 0x06d46f04, 0x5015ff60, 0x98fb2419, 0xbde997d6, 0x4043cc89, 0xd99e7767, 0xe842bdb0, 0x898b8807, 0x195b38e7, 0xc8eedb79, 0x7c0a47a1, 0x420fe97c, 0x841ec9f8, 0x00000000, 0x80868309, 0x2bed4832, 0x1170ac1e, 0x5a724e6c, 0x0efffbfd, 0x8538560f, 0xaed51e3d, 0x2d392736, 0x0fd9640a, 0x5ca62168, 0x5b54d19b, 0x362e3a24, 0x0a67b10c, 0x57e70f93, 0xee96d2b4, 0x9b919e1b, 0xc0c54f80, 0xdc20a261, 0x774b695a, 0x121a161c, 0x93ba0ae2, 0xa02ae5c0, 0x22e0433c, 0x1b171d12, 0x090d0b0e, 0x8bc7adf2, 0xb6a8b92d, 0x1ea9c814, 0xf1198557, 0x75074caf, 0x99ddbbee, 0x7f60fda3, 0x01269ff7, 0x72f5bc5c, 0x663bc544, 0xfb7e345b, 0x4329768b, 0x23c6dccb, 0xedfc68b6, 0xe4f163b8, 0x31dccad7, 0x63851042, 0x97224013, 0xc6112084, 0x4a247d85, 0xbb3df8d2, 0xf93211ae, 0x29a16dc7, 0x9e2f4b1d, 0xb230f3dc, 0x8652ec0d, 0xc1e3d077, 0xb3166c2b, 0x70b999a9, 0x9448fa11, 0xe9642247, 0xfc8cc4a8, 0xf03f1aa0, 0x7d2cd856, 0x3390ef22, 0x494ec787, 0x38d1c1d9, 0xcaa2fe8c, 0xd40b3698, 0xf581cfa6, 0x7ade28a5, 0xb78e26da, 0xadbfa43f, 0x3a9de42c, 0x78920d50, 0x5fcc9b6a, 0x7e466254, 0x8d13c2f6, 0xd8b8e890, 0x39f75e2e, 0xc3aff582, 0x5d80be9f, 0xd0937c69, 0xd52da96f, 0x2512b3cf, 0xac993bc8, 0x187da710, 0x9c636ee8, 0x3bbb7bdb, 0x267809cd, 0x5918f46e, 0x9ab701ec, 0x4f9aa883, 0x956e65e6, 0xffe67eaa, 0xbccf0821, 0x15e8e6ef, 0xe79bd9ba, 0x6f36ce4a, 0x9f09d4ea, 0xb07cd629, 0xa4b2af31, 0x3f23312a, 0xa59430c6, 0xa266c035, 0x4ebc3774, 0x82caa6fc, 0x90d0b0e0, 0xa7d81533, 0x04984af1, 0xecdaf741, 0xcd500e7f, 0x91f62f17, 0x4dd68d76, 0xefb04d43, 0xaa4d54cc, 0x9604dfe4, 0xd1b5e39e, 0x6a881b4c, 0x2c1fb8c1, 0x65517f46, 0x5eea049d, 0x8c355d01, 0x877473fa, 0x0b412efb, 0x671d5ab3, 0xdbd25292, 0x105633e9, 0xd647136d, 0xd7618c9a, 0xa10c7a37, 0xf8148e59, 0x133c89eb, 0xa927eece, 0x61c935b7, 0x1ce5ede1, 0x47b13c7a, 0xd2df599c, 0xf2733f55, 0x14ce7918, 0xc737bf73, 0xf7cdea53, 0xfdaa5b5f, 0x3d6f14df, 0x44db8678, 0xaff381ca, 0x68c43eb9, 0x24342c38, 0xa3405fc2, 0x1dc37216, 0xe2250cbc, 0x3c498b28, 0x0d9541ff, 0xa8017139, 0x0cb3de08, 0xb4e49cd8, 0x56c19064, 0xcb84617b, 0x32b670d5, 0x6c5c7448, 0xb85742d0];\n\n // Transformations for decryption key expansion\n var U1 = [0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927, 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45, 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb, 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381, 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf, 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66, 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28, 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012, 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec, 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e, 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd, 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7, 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89, 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b, 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815, 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f, 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa, 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8, 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36, 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c, 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742, 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea, 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4, 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e, 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360, 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502, 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87, 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd, 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3, 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621, 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f, 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55, 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26, 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844, 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba, 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480, 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce, 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67, 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929, 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713, 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed, 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f, 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3];\n var U2 = [0x00000000, 0x0b0e090d, 0x161c121a, 0x1d121b17, 0x2c382434, 0x27362d39, 0x3a24362e, 0x312a3f23, 0x58704868, 0x537e4165, 0x4e6c5a72, 0x4562537f, 0x74486c5c, 0x7f466551, 0x62547e46, 0x695a774b, 0xb0e090d0, 0xbbee99dd, 0xa6fc82ca, 0xadf28bc7, 0x9cd8b4e4, 0x97d6bde9, 0x8ac4a6fe, 0x81caaff3, 0xe890d8b8, 0xe39ed1b5, 0xfe8ccaa2, 0xf582c3af, 0xc4a8fc8c, 0xcfa6f581, 0xd2b4ee96, 0xd9bae79b, 0x7bdb3bbb, 0x70d532b6, 0x6dc729a1, 0x66c920ac, 0x57e31f8f, 0x5ced1682, 0x41ff0d95, 0x4af10498, 0x23ab73d3, 0x28a57ade, 0x35b761c9, 0x3eb968c4, 0x0f9357e7, 0x049d5eea, 0x198f45fd, 0x12814cf0, 0xcb3bab6b, 0xc035a266, 0xdd27b971, 0xd629b07c, 0xe7038f5f, 0xec0d8652, 0xf11f9d45, 0xfa119448, 0x934be303, 0x9845ea0e, 0x8557f119, 0x8e59f814, 0xbf73c737, 0xb47dce3a, 0xa96fd52d, 0xa261dc20, 0xf6ad766d, 0xfda37f60, 0xe0b16477, 0xebbf6d7a, 0xda955259, 0xd19b5b54, 0xcc894043, 0xc787494e, 0xaedd3e05, 0xa5d33708, 0xb8c12c1f, 0xb3cf2512, 0x82e51a31, 0x89eb133c, 0x94f9082b, 0x9ff70126, 0x464de6bd, 0x4d43efb0, 0x5051f4a7, 0x5b5ffdaa, 0x6a75c289, 0x617bcb84, 0x7c69d093, 0x7767d99e, 0x1e3daed5, 0x1533a7d8, 0x0821bccf, 0x032fb5c2, 0x32058ae1, 0x390b83ec, 0x241998fb, 0x2f1791f6, 0x8d764dd6, 0x867844db, 0x9b6a5fcc, 0x906456c1, 0xa14e69e2, 0xaa4060ef, 0xb7527bf8, 0xbc5c72f5, 0xd50605be, 0xde080cb3, 0xc31a17a4, 0xc8141ea9, 0xf93e218a, 0xf2302887, 0xef223390, 0xe42c3a9d, 0x3d96dd06, 0x3698d40b, 0x2b8acf1c, 0x2084c611, 0x11aef932, 0x1aa0f03f, 0x07b2eb28, 0x0cbce225, 0x65e6956e, 0x6ee89c63, 0x73fa8774, 0x78f48e79, 0x49deb15a, 0x42d0b857, 0x5fc2a340, 0x54ccaa4d, 0xf741ecda, 0xfc4fe5d7, 0xe15dfec0, 0xea53f7cd, 0xdb79c8ee, 0xd077c1e3, 0xcd65daf4, 0xc66bd3f9, 0xaf31a4b2, 0xa43fadbf, 0xb92db6a8, 0xb223bfa5, 0x83098086, 0x8807898b, 0x9515929c, 0x9e1b9b91, 0x47a17c0a, 0x4caf7507, 0x51bd6e10, 0x5ab3671d, 0x6b99583e, 0x60975133, 0x7d854a24, 0x768b4329, 0x1fd13462, 0x14df3d6f, 0x09cd2678, 0x02c32f75, 0x33e91056, 0x38e7195b, 0x25f5024c, 0x2efb0b41, 0x8c9ad761, 0x8794de6c, 0x9a86c57b, 0x9188cc76, 0xa0a2f355, 0xabacfa58, 0xb6bee14f, 0xbdb0e842, 0xd4ea9f09, 0xdfe49604, 0xc2f68d13, 0xc9f8841e, 0xf8d2bb3d, 0xf3dcb230, 0xeecea927, 0xe5c0a02a, 0x3c7a47b1, 0x37744ebc, 0x2a6655ab, 0x21685ca6, 0x10426385, 0x1b4c6a88, 0x065e719f, 0x0d507892, 0x640a0fd9, 0x6f0406d4, 0x72161dc3, 0x791814ce, 0x48322bed, 0x433c22e0, 0x5e2e39f7, 0x552030fa, 0x01ec9ab7, 0x0ae293ba, 0x17f088ad, 0x1cfe81a0, 0x2dd4be83, 0x26dab78e, 0x3bc8ac99, 0x30c6a594, 0x599cd2df, 0x5292dbd2, 0x4f80c0c5, 0x448ec9c8, 0x75a4f6eb, 0x7eaaffe6, 0x63b8e4f1, 0x68b6edfc, 0xb10c0a67, 0xba02036a, 0xa710187d, 0xac1e1170, 0x9d342e53, 0x963a275e, 0x8b283c49, 0x80263544, 0xe97c420f, 0xe2724b02, 0xff605015, 0xf46e5918, 0xc544663b, 0xce4a6f36, 0xd3587421, 0xd8567d2c, 0x7a37a10c, 0x7139a801, 0x6c2bb316, 0x6725ba1b, 0x560f8538, 0x5d018c35, 0x40139722, 0x4b1d9e2f, 0x2247e964, 0x2949e069, 0x345bfb7e, 0x3f55f273, 0x0e7fcd50, 0x0571c45d, 0x1863df4a, 0x136dd647, 0xcad731dc, 0xc1d938d1, 0xdccb23c6, 0xd7c52acb, 0xe6ef15e8, 0xede11ce5, 0xf0f307f2, 0xfbfd0eff, 0x92a779b4, 0x99a970b9, 0x84bb6bae, 0x8fb562a3, 0xbe9f5d80, 0xb591548d, 0xa8834f9a, 0xa38d4697];\n var U3 = [0x00000000, 0x0d0b0e09, 0x1a161c12, 0x171d121b, 0x342c3824, 0x3927362d, 0x2e3a2436, 0x23312a3f, 0x68587048, 0x65537e41, 0x724e6c5a, 0x7f456253, 0x5c74486c, 0x517f4665, 0x4662547e, 0x4b695a77, 0xd0b0e090, 0xddbbee99, 0xcaa6fc82, 0xc7adf28b, 0xe49cd8b4, 0xe997d6bd, 0xfe8ac4a6, 0xf381caaf, 0xb8e890d8, 0xb5e39ed1, 0xa2fe8cca, 0xaff582c3, 0x8cc4a8fc, 0x81cfa6f5, 0x96d2b4ee, 0x9bd9bae7, 0xbb7bdb3b, 0xb670d532, 0xa16dc729, 0xac66c920, 0x8f57e31f, 0x825ced16, 0x9541ff0d, 0x984af104, 0xd323ab73, 0xde28a57a, 0xc935b761, 0xc43eb968, 0xe70f9357, 0xea049d5e, 0xfd198f45, 0xf012814c, 0x6bcb3bab, 0x66c035a2, 0x71dd27b9, 0x7cd629b0, 0x5fe7038f, 0x52ec0d86, 0x45f11f9d, 0x48fa1194, 0x03934be3, 0x0e9845ea, 0x198557f1, 0x148e59f8, 0x37bf73c7, 0x3ab47dce, 0x2da96fd5, 0x20a261dc, 0x6df6ad76, 0x60fda37f, 0x77e0b164, 0x7aebbf6d, 0x59da9552, 0x54d19b5b, 0x43cc8940, 0x4ec78749, 0x05aedd3e, 0x08a5d337, 0x1fb8c12c, 0x12b3cf25, 0x3182e51a, 0x3c89eb13, 0x2b94f908, 0x269ff701, 0xbd464de6, 0xb04d43ef, 0xa75051f4, 0xaa5b5ffd, 0x896a75c2, 0x84617bcb, 0x937c69d0, 0x9e7767d9, 0xd51e3dae, 0xd81533a7, 0xcf0821bc, 0xc2032fb5, 0xe132058a, 0xec390b83, 0xfb241998, 0xf62f1791, 0xd68d764d, 0xdb867844, 0xcc9b6a5f, 0xc1906456, 0xe2a14e69, 0xefaa4060, 0xf8b7527b, 0xf5bc5c72, 0xbed50605, 0xb3de080c, 0xa4c31a17, 0xa9c8141e, 0x8af93e21, 0x87f23028, 0x90ef2233, 0x9de42c3a, 0x063d96dd, 0x0b3698d4, 0x1c2b8acf, 0x112084c6, 0x3211aef9, 0x3f1aa0f0, 0x2807b2eb, 0x250cbce2, 0x6e65e695, 0x636ee89c, 0x7473fa87, 0x7978f48e, 0x5a49deb1, 0x5742d0b8, 0x405fc2a3, 0x4d54ccaa, 0xdaf741ec, 0xd7fc4fe5, 0xc0e15dfe, 0xcdea53f7, 0xeedb79c8, 0xe3d077c1, 0xf4cd65da, 0xf9c66bd3, 0xb2af31a4, 0xbfa43fad, 0xa8b92db6, 0xa5b223bf, 0x86830980, 0x8b880789, 0x9c951592, 0x919e1b9b, 0x0a47a17c, 0x074caf75, 0x1051bd6e, 0x1d5ab367, 0x3e6b9958, 0x33609751, 0x247d854a, 0x29768b43, 0x621fd134, 0x6f14df3d, 0x7809cd26, 0x7502c32f, 0x5633e910, 0x5b38e719, 0x4c25f502, 0x412efb0b, 0x618c9ad7, 0x6c8794de, 0x7b9a86c5, 0x769188cc, 0x55a0a2f3, 0x58abacfa, 0x4fb6bee1, 0x42bdb0e8, 0x09d4ea9f, 0x04dfe496, 0x13c2f68d, 0x1ec9f884, 0x3df8d2bb, 0x30f3dcb2, 0x27eecea9, 0x2ae5c0a0, 0xb13c7a47, 0xbc37744e, 0xab2a6655, 0xa621685c, 0x85104263, 0x881b4c6a, 0x9f065e71, 0x920d5078, 0xd9640a0f, 0xd46f0406, 0xc372161d, 0xce791814, 0xed48322b, 0xe0433c22, 0xf75e2e39, 0xfa552030, 0xb701ec9a, 0xba0ae293, 0xad17f088, 0xa01cfe81, 0x832dd4be, 0x8e26dab7, 0x993bc8ac, 0x9430c6a5, 0xdf599cd2, 0xd25292db, 0xc54f80c0, 0xc8448ec9, 0xeb75a4f6, 0xe67eaaff, 0xf163b8e4, 0xfc68b6ed, 0x67b10c0a, 0x6aba0203, 0x7da71018, 0x70ac1e11, 0x539d342e, 0x5e963a27, 0x498b283c, 0x44802635, 0x0fe97c42, 0x02e2724b, 0x15ff6050, 0x18f46e59, 0x3bc54466, 0x36ce4a6f, 0x21d35874, 0x2cd8567d, 0x0c7a37a1, 0x017139a8, 0x166c2bb3, 0x1b6725ba, 0x38560f85, 0x355d018c, 0x22401397, 0x2f4b1d9e, 0x642247e9, 0x692949e0, 0x7e345bfb, 0x733f55f2, 0x500e7fcd, 0x5d0571c4, 0x4a1863df, 0x47136dd6, 0xdccad731, 0xd1c1d938, 0xc6dccb23, 0xcbd7c52a, 0xe8e6ef15, 0xe5ede11c, 0xf2f0f307, 0xfffbfd0e, 0xb492a779, 0xb999a970, 0xae84bb6b, 0xa38fb562, 0x80be9f5d, 0x8db59154, 0x9aa8834f, 0x97a38d46];\n var U4 = [0x00000000, 0x090d0b0e, 0x121a161c, 0x1b171d12, 0x24342c38, 0x2d392736, 0x362e3a24, 0x3f23312a, 0x48685870, 0x4165537e, 0x5a724e6c, 0x537f4562, 0x6c5c7448, 0x65517f46, 0x7e466254, 0x774b695a, 0x90d0b0e0, 0x99ddbbee, 0x82caa6fc, 0x8bc7adf2, 0xb4e49cd8, 0xbde997d6, 0xa6fe8ac4, 0xaff381ca, 0xd8b8e890, 0xd1b5e39e, 0xcaa2fe8c, 0xc3aff582, 0xfc8cc4a8, 0xf581cfa6, 0xee96d2b4, 0xe79bd9ba, 0x3bbb7bdb, 0x32b670d5, 0x29a16dc7, 0x20ac66c9, 0x1f8f57e3, 0x16825ced, 0x0d9541ff, 0x04984af1, 0x73d323ab, 0x7ade28a5, 0x61c935b7, 0x68c43eb9, 0x57e70f93, 0x5eea049d, 0x45fd198f, 0x4cf01281, 0xab6bcb3b, 0xa266c035, 0xb971dd27, 0xb07cd629, 0x8f5fe703, 0x8652ec0d, 0x9d45f11f, 0x9448fa11, 0xe303934b, 0xea0e9845, 0xf1198557, 0xf8148e59, 0xc737bf73, 0xce3ab47d, 0xd52da96f, 0xdc20a261, 0x766df6ad, 0x7f60fda3, 0x6477e0b1, 0x6d7aebbf, 0x5259da95, 0x5b54d19b, 0x4043cc89, 0x494ec787, 0x3e05aedd, 0x3708a5d3, 0x2c1fb8c1, 0x2512b3cf, 0x1a3182e5, 0x133c89eb, 0x082b94f9, 0x01269ff7, 0xe6bd464d, 0xefb04d43, 0xf4a75051, 0xfdaa5b5f, 0xc2896a75, 0xcb84617b, 0xd0937c69, 0xd99e7767, 0xaed51e3d, 0xa7d81533, 0xbccf0821, 0xb5c2032f, 0x8ae13205, 0x83ec390b, 0x98fb2419, 0x91f62f17, 0x4dd68d76, 0x44db8678, 0x5fcc9b6a, 0x56c19064, 0x69e2a14e, 0x60efaa40, 0x7bf8b752, 0x72f5bc5c, 0x05bed506, 0x0cb3de08, 0x17a4c31a, 0x1ea9c814, 0x218af93e, 0x2887f230, 0x3390ef22, 0x3a9de42c, 0xdd063d96, 0xd40b3698, 0xcf1c2b8a, 0xc6112084, 0xf93211ae, 0xf03f1aa0, 0xeb2807b2, 0xe2250cbc, 0x956e65e6, 0x9c636ee8, 0x877473fa, 0x8e7978f4, 0xb15a49de, 0xb85742d0, 0xa3405fc2, 0xaa4d54cc, 0xecdaf741, 0xe5d7fc4f, 0xfec0e15d, 0xf7cdea53, 0xc8eedb79, 0xc1e3d077, 0xdaf4cd65, 0xd3f9c66b, 0xa4b2af31, 0xadbfa43f, 0xb6a8b92d, 0xbfa5b223, 0x80868309, 0x898b8807, 0x929c9515, 0x9b919e1b, 0x7c0a47a1, 0x75074caf, 0x6e1051bd, 0x671d5ab3, 0x583e6b99, 0x51336097, 0x4a247d85, 0x4329768b, 0x34621fd1, 0x3d6f14df, 0x267809cd, 0x2f7502c3, 0x105633e9, 0x195b38e7, 0x024c25f5, 0x0b412efb, 0xd7618c9a, 0xde6c8794, 0xc57b9a86, 0xcc769188, 0xf355a0a2, 0xfa58abac, 0xe14fb6be, 0xe842bdb0, 0x9f09d4ea, 0x9604dfe4, 0x8d13c2f6, 0x841ec9f8, 0xbb3df8d2, 0xb230f3dc, 0xa927eece, 0xa02ae5c0, 0x47b13c7a, 0x4ebc3774, 0x55ab2a66, 0x5ca62168, 0x63851042, 0x6a881b4c, 0x719f065e, 0x78920d50, 0x0fd9640a, 0x06d46f04, 0x1dc37216, 0x14ce7918, 0x2bed4832, 0x22e0433c, 0x39f75e2e, 0x30fa5520, 0x9ab701ec, 0x93ba0ae2, 0x88ad17f0, 0x81a01cfe, 0xbe832dd4, 0xb78e26da, 0xac993bc8, 0xa59430c6, 0xd2df599c, 0xdbd25292, 0xc0c54f80, 0xc9c8448e, 0xf6eb75a4, 0xffe67eaa, 0xe4f163b8, 0xedfc68b6, 0x0a67b10c, 0x036aba02, 0x187da710, 0x1170ac1e, 0x2e539d34, 0x275e963a, 0x3c498b28, 0x35448026, 0x420fe97c, 0x4b02e272, 0x5015ff60, 0x5918f46e, 0x663bc544, 0x6f36ce4a, 0x7421d358, 0x7d2cd856, 0xa10c7a37, 0xa8017139, 0xb3166c2b, 0xba1b6725, 0x8538560f, 0x8c355d01, 0x97224013, 0x9e2f4b1d, 0xe9642247, 0xe0692949, 0xfb7e345b, 0xf2733f55, 0xcd500e7f, 0xc45d0571, 0xdf4a1863, 0xd647136d, 0x31dccad7, 0x38d1c1d9, 0x23c6dccb, 0x2acbd7c5, 0x15e8e6ef, 0x1ce5ede1, 0x07f2f0f3, 0x0efffbfd, 0x79b492a7, 0x70b999a9, 0x6bae84bb, 0x62a38fb5, 0x5d80be9f, 0x548db591, 0x4f9aa883, 0x4697a38d];\n\n function convertToInt32(bytes) {\n var result = [];\n for (var i = 0; i < bytes.length; i += 4) {\n result.push(\n (bytes[i ] << 24) |\n (bytes[i + 1] << 16) |\n (bytes[i + 2] << 8) |\n bytes[i + 3]\n );\n }\n return result;\n }\n\n var AES = function(key) {\n if (!(this instanceof AES)) {\n throw Error('AES must be instanitated with `new`');\n }\n\n Object.defineProperty(this, 'key', {\n value: coerceArray(key, true)\n });\n\n this._prepare();\n }\n\n\n AES.prototype._prepare = function() {\n\n var rounds = numberOfRounds[this.key.length];\n if (rounds == null) {\n throw new Error('invalid key size (must be 16, 24 or 32 bytes)');\n }\n\n // encryption round keys\n this._Ke = [];\n\n // decryption round keys\n this._Kd = [];\n\n for (var i = 0; i <= rounds; i++) {\n this._Ke.push([0, 0, 0, 0]);\n this._Kd.push([0, 0, 0, 0]);\n }\n\n var roundKeyCount = (rounds + 1) * 4;\n var KC = this.key.length / 4;\n\n // convert the key into ints\n var tk = convertToInt32(this.key);\n\n // copy values into round key arrays\n var index;\n for (var i = 0; i < KC; i++) {\n index = i >> 2;\n this._Ke[index][i % 4] = tk[i];\n this._Kd[rounds - index][i % 4] = tk[i];\n }\n\n // key expansion (fips-197 section 5.2)\n var rconpointer = 0;\n var t = KC, tt;\n while (t < roundKeyCount) {\n tt = tk[KC - 1];\n tk[0] ^= ((S[(tt >> 16) & 0xFF] << 24) ^\n (S[(tt >> 8) & 0xFF] << 16) ^\n (S[ tt & 0xFF] << 8) ^\n S[(tt >> 24) & 0xFF] ^\n (rcon[rconpointer] << 24));\n rconpointer += 1;\n\n // key expansion (for non-256 bit)\n if (KC != 8) {\n for (var i = 1; i < KC; i++) {\n tk[i] ^= tk[i - 1];\n }\n\n // key expansion for 256-bit keys is \"slightly different\" (fips-197)\n } else {\n for (var i = 1; i < (KC / 2); i++) {\n tk[i] ^= tk[i - 1];\n }\n tt = tk[(KC / 2) - 1];\n\n tk[KC / 2] ^= (S[ tt & 0xFF] ^\n (S[(tt >> 8) & 0xFF] << 8) ^\n (S[(tt >> 16) & 0xFF] << 16) ^\n (S[(tt >> 24) & 0xFF] << 24));\n\n for (var i = (KC / 2) + 1; i < KC; i++) {\n tk[i] ^= tk[i - 1];\n }\n }\n\n // copy values into round key arrays\n var i = 0, r, c;\n while (i < KC && t < roundKeyCount) {\n r = t >> 2;\n c = t % 4;\n this._Ke[r][c] = tk[i];\n this._Kd[rounds - r][c] = tk[i++];\n t++;\n }\n }\n\n // inverse-cipher-ify the decryption round key (fips-197 section 5.3)\n for (var r = 1; r < rounds; r++) {\n for (var c = 0; c < 4; c++) {\n tt = this._Kd[r][c];\n this._Kd[r][c] = (U1[(tt >> 24) & 0xFF] ^\n U2[(tt >> 16) & 0xFF] ^\n U3[(tt >> 8) & 0xFF] ^\n U4[ tt & 0xFF]);\n }\n }\n }\n\n AES.prototype.encrypt = function(plaintext) {\n if (plaintext.length != 16) {\n throw new Error('invalid plaintext size (must be 16 bytes)');\n }\n\n var rounds = this._Ke.length - 1;\n var a = [0, 0, 0, 0];\n\n // convert plaintext to (ints ^ key)\n var t = convertToInt32(plaintext);\n for (var i = 0; i < 4; i++) {\n t[i] ^= this._Ke[0][i];\n }\n\n // apply round transforms\n for (var r = 1; r < rounds; r++) {\n for (var i = 0; i < 4; i++) {\n a[i] = (T1[(t[ i ] >> 24) & 0xff] ^\n T2[(t[(i + 1) % 4] >> 16) & 0xff] ^\n T3[(t[(i + 2) % 4] >> 8) & 0xff] ^\n T4[ t[(i + 3) % 4] & 0xff] ^\n this._Ke[r][i]);\n }\n t = a.slice();\n }\n\n // the last round is special\n var result = createArray(16), tt;\n for (var i = 0; i < 4; i++) {\n tt = this._Ke[rounds][i];\n result[4 * i ] = (S[(t[ i ] >> 24) & 0xff] ^ (tt >> 24)) & 0xff;\n result[4 * i + 1] = (S[(t[(i + 1) % 4] >> 16) & 0xff] ^ (tt >> 16)) & 0xff;\n result[4 * i + 2] = (S[(t[(i + 2) % 4] >> 8) & 0xff] ^ (tt >> 8)) & 0xff;\n result[4 * i + 3] = (S[ t[(i + 3) % 4] & 0xff] ^ tt ) & 0xff;\n }\n\n return result;\n }\n\n AES.prototype.decrypt = function(ciphertext) {\n if (ciphertext.length != 16) {\n throw new Error('invalid ciphertext size (must be 16 bytes)');\n }\n\n var rounds = this._Kd.length - 1;\n var a = [0, 0, 0, 0];\n\n // convert plaintext to (ints ^ key)\n var t = convertToInt32(ciphertext);\n for (var i = 0; i < 4; i++) {\n t[i] ^= this._Kd[0][i];\n }\n\n // apply round transforms\n for (var r = 1; r < rounds; r++) {\n for (var i = 0; i < 4; i++) {\n a[i] = (T5[(t[ i ] >> 24) & 0xff] ^\n T6[(t[(i + 3) % 4] >> 16) & 0xff] ^\n T7[(t[(i + 2) % 4] >> 8) & 0xff] ^\n T8[ t[(i + 1) % 4] & 0xff] ^\n this._Kd[r][i]);\n }\n t = a.slice();\n }\n\n // the last round is special\n var result = createArray(16), tt;\n for (var i = 0; i < 4; i++) {\n tt = this._Kd[rounds][i];\n result[4 * i ] = (Si[(t[ i ] >> 24) & 0xff] ^ (tt >> 24)) & 0xff;\n result[4 * i + 1] = (Si[(t[(i + 3) % 4] >> 16) & 0xff] ^ (tt >> 16)) & 0xff;\n result[4 * i + 2] = (Si[(t[(i + 2) % 4] >> 8) & 0xff] ^ (tt >> 8)) & 0xff;\n result[4 * i + 3] = (Si[ t[(i + 1) % 4] & 0xff] ^ tt ) & 0xff;\n }\n\n return result;\n }\n\n\n /**\n * Mode Of Operation - Electonic Codebook (ECB)\n */\n var ModeOfOperationECB = function(key) {\n if (!(this instanceof ModeOfOperationECB)) {\n throw Error('AES must be instanitated with `new`');\n }\n\n this.description = \"Electronic Code Block\";\n this.name = \"ecb\";\n\n this._aes = new AES(key);\n }\n\n ModeOfOperationECB.prototype.encrypt = function(plaintext) {\n plaintext = coerceArray(plaintext);\n\n if ((plaintext.length % 16) !== 0) {\n throw new Error('invalid plaintext size (must be multiple of 16 bytes)');\n }\n\n var ciphertext = createArray(plaintext.length);\n var block = createArray(16);\n\n for (var i = 0; i < plaintext.length; i += 16) {\n copyArray(plaintext, block, 0, i, i + 16);\n block = this._aes.encrypt(block);\n copyArray(block, ciphertext, i);\n }\n\n return ciphertext;\n }\n\n ModeOfOperationECB.prototype.decrypt = function(ciphertext) {\n ciphertext = coerceArray(ciphertext);\n\n if ((ciphertext.length % 16) !== 0) {\n throw new Error('invalid ciphertext size (must be multiple of 16 bytes)');\n }\n\n var plaintext = createArray(ciphertext.length);\n var block = createArray(16);\n\n for (var i = 0; i < ciphertext.length; i += 16) {\n copyArray(ciphertext, block, 0, i, i + 16);\n block = this._aes.decrypt(block);\n copyArray(block, plaintext, i);\n }\n\n return plaintext;\n }\n\n\n /**\n * Mode Of Operation - Cipher Block Chaining (CBC)\n */\n var ModeOfOperationCBC = function(key, iv) {\n if (!(this instanceof ModeOfOperationCBC)) {\n throw Error('AES must be instanitated with `new`');\n }\n\n this.description = \"Cipher Block Chaining\";\n this.name = \"cbc\";\n\n if (!iv) {\n iv = createArray(16);\n\n } else if (iv.length != 16) {\n throw new Error('invalid initialation vector size (must be 16 bytes)');\n }\n\n this._lastCipherblock = coerceArray(iv, true);\n\n this._aes = new AES(key);\n }\n\n ModeOfOperationCBC.prototype.encrypt = function(plaintext) {\n plaintext = coerceArray(plaintext);\n\n if ((plaintext.length % 16) !== 0) {\n throw new Error('invalid plaintext size (must be multiple of 16 bytes)');\n }\n\n var ciphertext = createArray(plaintext.length);\n var block = createArray(16);\n\n for (var i = 0; i < plaintext.length; i += 16) {\n copyArray(plaintext, block, 0, i, i + 16);\n\n for (var j = 0; j < 16; j++) {\n block[j] ^= this._lastCipherblock[j];\n }\n\n this._lastCipherblock = this._aes.encrypt(block);\n copyArray(this._lastCipherblock, ciphertext, i);\n }\n\n return ciphertext;\n }\n\n ModeOfOperationCBC.prototype.decrypt = function(ciphertext) {\n ciphertext = coerceArray(ciphertext);\n\n if ((ciphertext.length % 16) !== 0) {\n throw new Error('invalid ciphertext size (must be multiple of 16 bytes)');\n }\n\n var plaintext = createArray(ciphertext.length);\n var block = createArray(16);\n\n for (var i = 0; i < ciphertext.length; i += 16) {\n copyArray(ciphertext, block, 0, i, i + 16);\n block = this._aes.decrypt(block);\n\n for (var j = 0; j < 16; j++) {\n plaintext[i + j] = block[j] ^ this._lastCipherblock[j];\n }\n\n copyArray(ciphertext, this._lastCipherblock, 0, i, i + 16);\n }\n\n return plaintext;\n }\n\n\n /**\n * Mode Of Operation - Cipher Feedback (CFB)\n */\n var ModeOfOperationCFB = function(key, iv, segmentSize) {\n if (!(this instanceof ModeOfOperationCFB)) {\n throw Error('AES must be instanitated with `new`');\n }\n\n this.description = \"Cipher Feedback\";\n this.name = \"cfb\";\n\n if (!iv) {\n iv = createArray(16);\n\n } else if (iv.length != 16) {\n throw new Error('invalid initialation vector size (must be 16 size)');\n }\n\n if (!segmentSize) { segmentSize = 1; }\n\n this.segmentSize = segmentSize;\n\n this._shiftRegister = coerceArray(iv, true);\n\n this._aes = new AES(key);\n }\n\n ModeOfOperationCFB.prototype.encrypt = function(plaintext) {\n if ((plaintext.length % this.segmentSize) != 0) {\n throw new Error('invalid plaintext size (must be segmentSize bytes)');\n }\n\n var encrypted = coerceArray(plaintext, true);\n\n var xorSegment;\n for (var i = 0; i < encrypted.length; i += this.segmentSize) {\n xorSegment = this._aes.encrypt(this._shiftRegister);\n for (var j = 0; j < this.segmentSize; j++) {\n encrypted[i + j] ^= xorSegment[j];\n }\n\n // Shift the register\n copyArray(this._shiftRegister, this._shiftRegister, 0, this.segmentSize);\n copyArray(encrypted, this._shiftRegister, 16 - this.segmentSize, i, i + this.segmentSize);\n }\n\n return encrypted;\n }\n\n ModeOfOperationCFB.prototype.decrypt = function(ciphertext) {\n if ((ciphertext.length % this.segmentSize) != 0) {\n throw new Error('invalid ciphertext size (must be segmentSize bytes)');\n }\n\n var plaintext = coerceArray(ciphertext, true);\n\n var xorSegment;\n for (var i = 0; i < plaintext.length; i += this.segmentSize) {\n xorSegment = this._aes.encrypt(this._shiftRegister);\n\n for (var j = 0; j < this.segmentSize; j++) {\n plaintext[i + j] ^= xorSegment[j];\n }\n\n // Shift the register\n copyArray(this._shiftRegister, this._shiftRegister, 0, this.segmentSize);\n copyArray(ciphertext, this._shiftRegister, 16 - this.segmentSize, i, i + this.segmentSize);\n }\n\n return plaintext;\n }\n\n /**\n * Mode Of Operation - Output Feedback (OFB)\n */\n var ModeOfOperationOFB = function(key, iv) {\n if (!(this instanceof ModeOfOperationOFB)) {\n throw Error('AES must be instanitated with `new`');\n }\n\n this.description = \"Output Feedback\";\n this.name = \"ofb\";\n\n if (!iv) {\n iv = createArray(16);\n\n } else if (iv.length != 16) {\n throw new Error('invalid initialation vector size (must be 16 bytes)');\n }\n\n this._lastPrecipher = coerceArray(iv, true);\n this._lastPrecipherIndex = 16;\n\n this._aes = new AES(key);\n }\n\n ModeOfOperationOFB.prototype.encrypt = function(plaintext) {\n var encrypted = coerceArray(plaintext, true);\n\n for (var i = 0; i < encrypted.length; i++) {\n if (this._lastPrecipherIndex === 16) {\n this._lastPrecipher = this._aes.encrypt(this._lastPrecipher);\n this._lastPrecipherIndex = 0;\n }\n encrypted[i] ^= this._lastPrecipher[this._lastPrecipherIndex++];\n }\n\n return encrypted;\n }\n\n // Decryption is symetric\n ModeOfOperationOFB.prototype.decrypt = ModeOfOperationOFB.prototype.encrypt;\n\n\n /**\n * Counter object for CTR common mode of operation\n */\n var Counter = function(initialValue) {\n if (!(this instanceof Counter)) {\n throw Error('Counter must be instanitated with `new`');\n }\n\n // We allow 0, but anything false-ish uses the default 1\n if (initialValue !== 0 && !initialValue) { initialValue = 1; }\n\n if (typeof(initialValue) === 'number') {\n this._counter = createArray(16);\n this.setValue(initialValue);\n\n } else {\n this.setBytes(initialValue);\n }\n }\n\n Counter.prototype.setValue = function(value) {\n if (typeof(value) !== 'number' || parseInt(value) != value) {\n throw new Error('invalid counter value (must be an integer)');\n }\n\n // We cannot safely handle numbers beyond the safe range for integers\n if (value > Number.MAX_SAFE_INTEGER) {\n throw new Error('integer value out of safe range');\n }\n\n for (var index = 15; index >= 0; --index) {\n this._counter[index] = value % 256;\n value = parseInt(value / 256);\n }\n }\n\n Counter.prototype.setBytes = function(bytes) {\n bytes = coerceArray(bytes, true);\n\n if (bytes.length != 16) {\n throw new Error('invalid counter bytes size (must be 16 bytes)');\n }\n\n this._counter = bytes;\n };\n\n Counter.prototype.increment = function() {\n for (var i = 15; i >= 0; i--) {\n if (this._counter[i] === 255) {\n this._counter[i] = 0;\n } else {\n this._counter[i]++;\n break;\n }\n }\n }\n\n\n /**\n * Mode Of Operation - Counter (CTR)\n */\n var ModeOfOperationCTR = function(key, counter) {\n if (!(this instanceof ModeOfOperationCTR)) {\n throw Error('AES must be instanitated with `new`');\n }\n\n this.description = \"Counter\";\n this.name = \"ctr\";\n\n if (!(counter instanceof Counter)) {\n counter = new Counter(counter)\n }\n\n this._counter = counter;\n\n this._remainingCounter = null;\n this._remainingCounterIndex = 16;\n\n this._aes = new AES(key);\n }\n\n ModeOfOperationCTR.prototype.encrypt = function(plaintext) {\n var encrypted = coerceArray(plaintext, true);\n\n for (var i = 0; i < encrypted.length; i++) {\n if (this._remainingCounterIndex === 16) {\n this._remainingCounter = this._aes.encrypt(this._counter._counter);\n this._remainingCounterIndex = 0;\n this._counter.increment();\n }\n encrypted[i] ^= this._remainingCounter[this._remainingCounterIndex++];\n }\n\n return encrypted;\n }\n\n // Decryption is symetric\n ModeOfOperationCTR.prototype.decrypt = ModeOfOperationCTR.prototype.encrypt;\n\n\n ///////////////////////\n // Padding\n\n // See:https://tools.ietf.org/html/rfc2315\n function pkcs7pad(data) {\n data = coerceArray(data, true);\n var padder = 16 - (data.length % 16);\n var result = createArray(data.length + padder);\n copyArray(data, result);\n for (var i = data.length; i < result.length; i++) {\n result[i] = padder;\n }\n return result;\n }\n\n function pkcs7strip(data) {\n data = coerceArray(data, true);\n if (data.length < 16) { throw new Error('PKCS#7 invalid length'); }\n\n var padder = data[data.length - 1];\n if (padder > 16) { throw new Error('PKCS#7 padding byte out of range'); }\n\n var length = data.length - padder;\n for (var i = 0; i < padder; i++) {\n if (data[length + i] !== padder) {\n throw new Error('PKCS#7 invalid padding byte');\n }\n }\n\n var result = createArray(length);\n copyArray(data, result, 0, 0, length);\n return result;\n }\n\n ///////////////////////\n // Exporting\n\n\n // The block cipher\n var aesjs = {\n AES: AES,\n Counter: Counter,\n\n ModeOfOperation: {\n ecb: ModeOfOperationECB,\n cbc: ModeOfOperationCBC,\n cfb: ModeOfOperationCFB,\n ofb: ModeOfOperationOFB,\n ctr: ModeOfOperationCTR\n },\n\n utils: {\n hex: convertHex,\n utf8: convertUtf8\n },\n\n padding: {\n pkcs7: {\n pad: pkcs7pad,\n strip: pkcs7strip\n }\n },\n\n _arrayTest: {\n coerceArray: coerceArray,\n createArray: createArray,\n copyArray: copyArray,\n }\n };\n\n\n // node.js\n if (typeof exports !== 'undefined') {\n module.exports = aesjs\n\n // RequireJS/AMD\n // http://www.requirejs.org/docs/api.html\n // https://github.com/amdjs/amdjs-api/wiki/AMD\n } else if (typeof(define) === 'function' && define.amd) {\n define([], function() { return aesjs; });\n\n // Web Browsers\n } else {\n\n // If there was an existing library at \"aesjs\" make sure it's still available\n if (root.aesjs) {\n aesjs._aesjs = root.aesjs;\n }\n\n root.aesjs = aesjs;\n }\n\n\n})(this);\n","import aesjs from 'aes-js';\n\n// See https://github.com/ricmoo/aes-js\n// We can use keys that are 128 bits (16 bytes), 192 bits (24 bytes) or 256 bits (32 bytes).\n// To generate a random key: window.crypto.getRandomValues(new Uint8Array(16));\n\n// This default signing key is built into iD and can be used to mask/unmask sensitive values.\nconst DEFAULT_128 = [250, 157, 60, 79, 142, 134, 229, 129, 138, 126, 210, 129, 29, 71, 160, 208];\n\n\nexport function utilAesEncrypt(text, key) {\n key = key || DEFAULT_128;\n const textBytes = aesjs.utils.utf8.toBytes(text);\n const aesCtr = new aesjs.ModeOfOperation.ctr(key);\n const encryptedBytes = aesCtr.encrypt(textBytes);\n const encryptedHex = aesjs.utils.hex.fromBytes(encryptedBytes);\n return encryptedHex;\n}\n\n\nexport function utilAesDecrypt(encryptedHex, key) {\n key = key || DEFAULT_128;\n const encryptedBytes = aesjs.utils.hex.toBytes(encryptedHex);\n const aesCtr = new aesjs.ModeOfOperation.ctr(key);\n const decryptedBytes = aesCtr.decrypt(encryptedBytes);\n const text = aesjs.utils.utf8.fromBytes(decryptedBytes);\n return text;\n}\n","export function utilCleanTags(tags) {\n var out = {};\n for (var k in tags) {\n if (!k) continue;\n var v = tags[k];\n if (v !== undefined) {\n out[k] = cleanValue(k, v);\n }\n }\n\n return out;\n\n\n function cleanValue(k, v) {\n function keepSpaces(k) {\n return /_hours|_times|:conditional$/.test(k);\n }\n\n function skip(k) {\n return /^(description|note|fixme)$/.test(k);\n }\n\n if (skip(k)) return v;\n\n var cleaned = v\n .split(';')\n .map(function(s) { return s.trim(); })\n .join(keepSpaces(k) ? '; ' : ';');\n\n // The code below is not intended to validate websites and emails.\n // It is only intended to prevent obvious copy-paste errors. (#2323)\n // clean website- and email-like tags\n if (k.indexOf('website') !== -1 ||\n k.indexOf('email') !== -1 ||\n cleaned.indexOf('http') === 0) {\n cleaned = cleaned\n .replace(/[\\u200B-\\u200F\\uFEFF]/g, ''); // strip LRM and other zero width chars\n\n }\n\n return cleaned;\n }\n}\n","// Like selection.property('value', ...), but avoids no-op value sets,\n// which can result in layout/repaint thrashing in some situations.\nexport function utilGetSetValue(selection, value) {\n function d3_selection_value(value) {\n function valueNull() {\n delete this.value;\n }\n\n function valueConstant() {\n if (this.value !== value) {\n this.value = value;\n }\n }\n\n function valueFunction() {\n var x = value.apply(this, arguments);\n if (x == null) {\n delete this.value;\n } else if (this.value !== x) {\n this.value = x;\n }\n }\n\n return value == null\n ? valueNull : (typeof value === 'function'\n ? valueFunction : valueConstant);\n }\n\n if (arguments.length === 1) {\n return selection.property('value');\n }\n\n return selection.each(d3_selection_value(value));\n}\n","import {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { utilArrayUniq } from './array';\n\n\nexport function utilKeybinding(namespace) {\n var _keybindings = {};\n\n\n function testBindings(isCapturing) {\n var didMatch = false;\n var bindings = Object.keys(_keybindings).map(function(id) { return _keybindings[id]; });\n var i, binding;\n\n // Most key shortcuts will accept either lower or uppercase ('h' or 'H'),\n // so we don't strictly match on the shift key, but we prioritize\n // shifted keybindings first, and fallback to unshifted only if no match.\n // (This lets us differentiate between '←'/'⇧←' or '⌘Z'/'⌘⇧Z')\n\n // priority match shifted keybindings first\n for (i = 0; i < bindings.length; i++) {\n binding = bindings[i];\n if (!binding.event.modifiers.shiftKey) continue; // no shift\n if (!!binding.capture !== isCapturing) continue;\n if (matches(binding, true)) {\n binding.callback();\n didMatch = true;\n }\n }\n\n // then unshifted keybindings\n if (didMatch) return;\n for (i = 0; i < bindings.length; i++) {\n binding = bindings[i];\n if (binding.event.modifiers.shiftKey) continue; // shift\n if (!!binding.capture !== isCapturing) continue;\n if (matches(binding, false)) {\n binding.callback();\n }\n }\n\n\n function matches(binding, testShift) {\n var event = d3_event;\n var isMatch = false;\n var tryKeyCode = true;\n\n // Prefer a match on `KeyboardEvent.key`\n if (event.key !== undefined) {\n tryKeyCode = (event.key.charCodeAt(0) > 255); // outside ISO-Latin-1\n isMatch = true;\n\n if (binding.event.key === undefined) {\n isMatch = false;\n } else if (Array.isArray(binding.event.key)) {\n if (binding.event.key.map(function(s) { return s.toLowerCase(); }).indexOf(event.key.toLowerCase()) === -1)\n isMatch = false;\n } else {\n if (event.key.toLowerCase() !== binding.event.key.toLowerCase())\n isMatch = false;\n }\n }\n\n // Fallback match on `KeyboardEvent.keyCode`, can happen if:\n // - browser doesn't support `KeyboardEvent.key`\n // - `KeyboardEvent.key` is outside ISO-Latin-1 range (cyrillic?)\n if (!isMatch && tryKeyCode) {\n isMatch = (event.keyCode === binding.event.keyCode);\n }\n\n if (!isMatch) return false;\n\n // test modifier keys\n if (!(event.ctrlKey && event.altKey)) { // if both are set, assume AltGr and skip it - #4096\n if (event.ctrlKey !== binding.event.modifiers.ctrlKey) return false;\n if (event.altKey !== binding.event.modifiers.altKey) return false;\n }\n if (event.metaKey !== binding.event.modifiers.metaKey) return false;\n if (testShift && event.shiftKey !== binding.event.modifiers.shiftKey) return false;\n\n return true;\n }\n }\n\n\n function capture() {\n testBindings(true);\n }\n\n\n function bubble() {\n var tagName = d3_select(d3_event.target).node().tagName;\n if (tagName === 'INPUT' || tagName === 'SELECT' || tagName === 'TEXTAREA') {\n return;\n }\n testBindings(false);\n }\n\n\n function keybinding(selection) {\n selection = selection || d3_select(document);\n selection.on('keydown.capture.' + namespace, capture, true);\n selection.on('keydown.bubble.' + namespace, bubble, false);\n return keybinding;\n }\n\n // was: keybinding.off()\n keybinding.unbind = function(selection) {\n _keybindings = [];\n selection = selection || d3_select(document);\n selection.on('keydown.capture.' + namespace, null);\n selection.on('keydown.bubble.' + namespace, null);\n return keybinding;\n };\n\n\n keybinding.clear = function() {\n _keybindings = {};\n return keybinding;\n };\n\n\n // Remove one or more keycode bindings.\n keybinding.off = function(codes, capture) {\n var arr = utilArrayUniq([].concat(codes));\n\n for (var i = 0; i < arr.length; i++) {\n var id = arr[i] + (capture ? '-capture' : '-bubble');\n delete _keybindings[id];\n }\n return keybinding;\n };\n\n\n // Add one or more keycode bindings.\n keybinding.on = function(codes, callback, capture) {\n if (typeof callback !== 'function') {\n return keybinding.off(codes, capture);\n }\n\n var arr = utilArrayUniq([].concat(codes));\n\n for (var i = 0; i < arr.length; i++) {\n var id = arr[i] + (capture ? '-capture' : '-bubble');\n var binding = {\n id: id,\n capture: capture,\n callback: callback,\n event: {\n key: undefined, // preferred\n keyCode: 0, // fallback\n modifiers: {\n shiftKey: false,\n ctrlKey: false,\n altKey: false,\n metaKey: false\n }\n }\n };\n\n if (_keybindings[id]) {\n console.warn('warning: duplicate keybinding for \"' + id + '\"'); // eslint-disable-line no-console\n }\n\n _keybindings[id] = binding;\n\n var matches = arr[i].toLowerCase().match(/(?:(?:[^+⇧⌃⌥⌘])+|[⇧⌃⌥⌘]|\\+\\+|^\\+$)/g);\n for (var j = 0; j < matches.length; j++) {\n // Normalise matching errors\n if (matches[j] === '++') matches[j] = '+';\n\n if (matches[j] in utilKeybinding.modifierCodes) {\n var prop = utilKeybinding.modifierProperties[utilKeybinding.modifierCodes[matches[j]]];\n binding.event.modifiers[prop] = true;\n } else {\n binding.event.key = utilKeybinding.keys[matches[j]] || matches[j];\n if (matches[j] in utilKeybinding.keyCodes) {\n binding.event.keyCode = utilKeybinding.keyCodes[matches[j]];\n }\n }\n }\n }\n\n return keybinding;\n };\n\n\n return keybinding;\n}\n\n\n/*\n * See https://github.com/keithamus/jwerty\n */\n\nutilKeybinding.modifierCodes = {\n // Shift key, ⇧\n '⇧': 16, shift: 16,\n // CTRL key, on Mac: ⌃\n '⌃': 17, ctrl: 17,\n // ALT key, on Mac: ⌥ (Alt)\n '⌥': 18, alt: 18, option: 18,\n // META, on Mac: ⌘ (CMD), on Windows (Win), on Linux (Super)\n '⌘': 91, meta: 91, cmd: 91, 'super': 91, win: 91\n};\n\nutilKeybinding.modifierProperties = {\n 16: 'shiftKey',\n 17: 'ctrlKey',\n 18: 'altKey',\n 91: 'metaKey'\n};\n\nutilKeybinding.keys = {\n // Backspace key, on Mac: ⌫ (Backspace)\n '⌫': 'Backspace', backspace: 'Backspace',\n // Tab Key, on Mac: ⇥ (Tab), on Windows ⇥⇥\n '⇥': 'Tab', '⇆': 'Tab', tab: 'Tab',\n // Return key, ↩\n '↩': 'Enter', 'return': 'Enter', enter: 'Enter', '⌅': 'Enter',\n // Pause/Break key\n 'pause': 'Pause', 'pause-break': 'Pause',\n // Caps Lock key, ⇪\n '⇪': 'CapsLock', caps: 'CapsLock', 'caps-lock': 'CapsLock',\n // Escape key, on Mac: ⎋, on Windows: Esc\n '⎋': ['Escape', 'Esc'], escape: ['Escape', 'Esc'], esc: ['Escape', 'Esc'],\n // Space key\n space: [' ', 'Spacebar'],\n // Page-Up key, or pgup, on Mac: ↖\n '↖': 'PageUp', pgup: 'PageUp', 'page-up': 'PageUp',\n // Page-Down key, or pgdown, on Mac: ↘\n '↘': 'PageDown', pgdown: 'PageDown', 'page-down': 'PageDown',\n // END key, on Mac: ⇟\n '⇟': 'End', end: 'End',\n // HOME key, on Mac: ⇞\n '⇞': 'Home', home: 'Home',\n // Insert key, or ins\n ins: 'Insert', insert: 'Insert',\n // Delete key, on Mac: ⌦ (Delete)\n '⌦': ['Delete', 'Del'], del: ['Delete', 'Del'], 'delete': ['Delete', 'Del'],\n // Left Arrow Key, or ←\n '←': ['ArrowLeft', 'Left'], left: ['ArrowLeft', 'Left'], 'arrow-left': ['ArrowLeft', 'Left'],\n // Up Arrow Key, or ↑\n '↑': ['ArrowUp', 'Up'], up: ['ArrowUp', 'Up'], 'arrow-up': ['ArrowUp', 'Up'],\n // Right Arrow Key, or →\n '→': ['ArrowRight', 'Right'], right: ['ArrowRight', 'Right'], 'arrow-right': ['ArrowRight', 'Right'],\n // Up Arrow Key, or ↓\n '↓': ['ArrowDown', 'Down'], down: ['ArrowDown', 'Down'], 'arrow-down': ['ArrowDown', 'Down'],\n // odities, stuff for backward compatibility (browsers and code):\n // Num-Multiply, or *\n '*': ['*', 'Multiply'], star: ['*', 'Multiply'], asterisk: ['*', 'Multiply'], multiply: ['*', 'Multiply'],\n // Num-Plus or +\n '+': ['+', 'Add'], 'plus': ['+', 'Add'],\n // Num-Subtract, or -\n '-': ['-', 'Subtract'], subtract: ['-', 'Subtract'], 'dash': ['-', 'Subtract'],\n // Semicolon\n semicolon: ';',\n // = or equals\n equals: '=',\n // Comma, or ,\n comma: ',',\n // Period, or ., or full-stop\n period: '.', 'full-stop': '.',\n // Slash, or /, or forward-slash\n slash: '/', 'forward-slash': '/',\n // Tick, or `, or back-quote\n tick: '`', 'back-quote': '`',\n // Open bracket, or [\n 'open-bracket': '[',\n // Back slash, or \\\n 'back-slash': '\\\\',\n // Close backet, or ]\n 'close-bracket': ']',\n // Apostrophe, or Quote, or '\n quote: '\\'', apostrophe: '\\'',\n // NUMPAD 0-9\n 'num-0': '0',\n 'num-1': '1',\n 'num-2': '2',\n 'num-3': '3',\n 'num-4': '4',\n 'num-5': '5',\n 'num-6': '6',\n 'num-7': '7',\n 'num-8': '8',\n 'num-9': '9',\n // F1-F25\n f1: 'F1',\n f2: 'F2',\n f3: 'F3',\n f4: 'F4',\n f5: 'F5',\n f6: 'F6',\n f7: 'F7',\n f8: 'F8',\n f9: 'F9',\n f10: 'F10',\n f11: 'F11',\n f12: 'F12',\n f13: 'F13',\n f14: 'F14',\n f15: 'F15',\n f16: 'F16',\n f17: 'F17',\n f18: 'F18',\n f19: 'F19',\n f20: 'F20',\n f21: 'F21',\n f22: 'F22',\n f23: 'F23',\n f24: 'F24',\n f25: 'F25'\n};\n\nutilKeybinding.keyCodes = {\n // Backspace key, on Mac: ⌫ (Backspace)\n '⌫': 8, backspace: 8,\n // Tab Key, on Mac: ⇥ (Tab), on Windows ⇥⇥\n '⇥': 9, '⇆': 9, tab: 9,\n // Return key, ↩\n '↩': 13, 'return': 13, enter: 13, '⌅': 13,\n // Pause/Break key\n 'pause': 19, 'pause-break': 19,\n // Caps Lock key, ⇪\n '⇪': 20, caps: 20, 'caps-lock': 20,\n // Escape key, on Mac: ⎋, on Windows: Esc\n '⎋': 27, escape: 27, esc: 27,\n // Space key\n space: 32,\n // Page-Up key, or pgup, on Mac: ↖\n '↖': 33, pgup: 33, 'page-up': 33,\n // Page-Down key, or pgdown, on Mac: ↘\n '↘': 34, pgdown: 34, 'page-down': 34,\n // END key, on Mac: ⇟\n '⇟': 35, end: 35,\n // HOME key, on Mac: ⇞\n '⇞': 36, home: 36,\n // Insert key, or ins\n ins: 45, insert: 45,\n // Delete key, on Mac: ⌦ (Delete)\n '⌦': 46, del: 46, 'delete': 46,\n // Left Arrow Key, or ←\n '←': 37, left: 37, 'arrow-left': 37,\n // Up Arrow Key, or ↑\n '↑': 38, up: 38, 'arrow-up': 38,\n // Right Arrow Key, or →\n '→': 39, right: 39, 'arrow-right': 39,\n // Up Arrow Key, or ↓\n '↓': 40, down: 40, 'arrow-down': 40,\n // odities, printing characters that come out wrong:\n // Firefox Equals\n 'ffequals': 61,\n // Num-Multiply, or *\n '*': 106, star: 106, asterisk: 106, multiply: 106,\n // Num-Plus or +\n '+': 107, 'plus': 107,\n // Num-Subtract, or -\n '-': 109, subtract: 109,\n // Firefox Plus\n 'ffplus': 171,\n // Firefox Minus\n 'ffminus': 173,\n // Semicolon\n ';': 186, semicolon: 186,\n // = or equals\n '=': 187, 'equals': 187,\n // Comma, or ,\n ',': 188, comma: 188,\n // Dash / Underscore key\n 'dash': 189,\n // Period, or ., or full-stop\n '.': 190, period: 190, 'full-stop': 190,\n // Slash, or /, or forward-slash\n '/': 191, slash: 191, 'forward-slash': 191,\n // Tick, or `, or back-quote\n '`': 192, tick: 192, 'back-quote': 192,\n // Open bracket, or [\n '[': 219, 'open-bracket': 219,\n // Back slash, or \\\n '\\\\': 220, 'back-slash': 220,\n // Close backet, or ]\n ']': 221, 'close-bracket': 221,\n // Apostrophe, or Quote, or '\n '\\'': 222, quote: 222, apostrophe: 222\n};\n\n// NUMPAD 0-9\nvar i = 95, n = 0;\nwhile (++i < 106) {\n utilKeybinding.keyCodes['num-' + n] = i;\n ++n;\n}\n\n// 0-9\ni = 47; n = 0;\nwhile (++i < 58) {\n utilKeybinding.keyCodes[n] = i;\n ++n;\n}\n\n// F1-F25\ni = 111; n = 1;\nwhile (++i < 136) {\n utilKeybinding.keyCodes['f' + n] = i;\n ++n;\n}\n\n// a-z\ni = 64;\nwhile (++i < 91) {\n utilKeybinding.keyCodes[String.fromCharCode(i).toLowerCase()] = i;\n}\n","\nexport function utilObjectOmit(obj, omitKeys) {\n return Object.keys(obj).reduce(function(result, key) {\n if (omitKeys.indexOf(key) === -1) {\n result[key] = obj[key]; // keep\n }\n return result;\n }, {});\n}\n","// Copies a variable number of methods from source to target.\nexport function utilRebind(target, source) {\n var i = 1, n = arguments.length, method;\n while (++i < n) {\n target[method = arguments[i]] = d3_rebind(target, source, source[method]);\n }\n return target;\n}\n\n// Method is assumed to be a standard D3 getter-setter:\n// If passed with no arguments, gets the value.\n// If passed with arguments, sets the value and returns the target.\nfunction d3_rebind(target, source, method) {\n return function() {\n var value = method.apply(source, arguments);\n return value === source ? target : value;\n };\n}\n","// A per-domain session mutex backed by a cookie and dead man's\n// switch. If the session crashes, the mutex will auto-release\n// after 5 seconds.\n\n// This accepts a string and returns an object that complies with utilSessionMutexType\nexport function utilSessionMutex(name) {\n var mutex = {};\n var intervalID;\n\n function renew() {\n var expires = new Date();\n expires.setSeconds(expires.getSeconds() + 5);\n document.cookie = name + '=1; expires=' + expires.toUTCString() + '; sameSite=strict';\n }\n\n mutex.lock = function () {\n if (intervalID) return true;\n var cookie = document.cookie.replace(new RegExp('(?:(?:^|.*;)\\\\s*' + name + '\\\\s*\\\\=\\\\s*([^;]*).*$)|^.*$'), '$1');\n if (cookie) return false;\n renew();\n intervalID = window.setInterval(renew, 4000);\n return true;\n };\n\n mutex.unlock = function () {\n if (!intervalID) return;\n document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; sameSite=strict';\n clearInterval(intervalID);\n intervalID = null;\n };\n\n mutex.locked = function () {\n return !!intervalID;\n };\n\n return mutex;\n}\n","import { range as d3_range } from 'd3-array';\nimport { geoExtent, geoScaleToZoom } from '../geo';\n\n\nexport function utilTiler() {\n var _size = [256, 256];\n var _scale = 256;\n var _tileSize = 256;\n var _zoomExtent = [0, 20];\n var _translate = [_size[0] / 2, _size[1] / 2];\n var _margin = 0;\n var _skipNullIsland = false;\n\n\n function clamp(num, min, max) {\n return Math.max(min, Math.min(num, max));\n }\n\n\n function nearNullIsland(tile) {\n var x = tile[0];\n var y = tile[1];\n var z = tile[2];\n if (z >= 7) {\n var center = Math.pow(2, z - 1);\n var width = Math.pow(2, z - 6);\n var min = center - (width / 2);\n var max = center + (width / 2) - 1;\n return x >= min && x <= max && y >= min && y <= max;\n }\n return false;\n }\n\n\n function tiler() {\n var z = geoScaleToZoom(_scale / (2 * Math.PI), _tileSize);\n var z0 = clamp(Math.round(z), _zoomExtent[0], _zoomExtent[1]);\n var tileMin = 0;\n var tileMax = Math.pow(2, z0) - 1;\n var log2ts = Math.log(_tileSize) * Math.LOG2E;\n var k = Math.pow(2, z - z0 + log2ts);\n var origin = [\n (_translate[0] - _scale / 2) / k,\n (_translate[1] - _scale / 2) / k\n ];\n\n var cols = d3_range(\n clamp(Math.floor(-origin[0]) - _margin, tileMin, tileMax + 1),\n clamp(Math.ceil(_size[0] / k - origin[0]) + _margin, tileMin, tileMax + 1)\n );\n var rows = d3_range(\n clamp(Math.floor(-origin[1]) - _margin, tileMin, tileMax + 1),\n clamp(Math.ceil(_size[1] / k - origin[1]) + _margin, tileMin, tileMax + 1)\n );\n\n var tiles = [];\n for (var i = 0; i < rows.length; i++) {\n var y = rows[i];\n for (var j = 0; j < cols.length; j++) {\n var x = cols[j];\n\n if (i >= _margin && i <= rows.length - _margin &&\n j >= _margin && j <= cols.length - _margin) {\n tiles.unshift([x, y, z0]); // tiles in view at beginning\n } else {\n tiles.push([x, y, z0]); // tiles in margin at the end\n }\n }\n }\n\n tiles.translate = origin;\n tiles.scale = k;\n\n return tiles;\n }\n\n\n /**\n * getTiles() returns an array of tiles that cover the map view\n */\n tiler.getTiles = function(projection) {\n var origin = [\n projection.scale() * Math.PI - projection.translate()[0],\n projection.scale() * Math.PI - projection.translate()[1]\n ];\n\n this\n .size(projection.clipExtent()[1])\n .scale(projection.scale() * 2 * Math.PI)\n .translate(projection.translate());\n\n var tiles = tiler();\n var ts = tiles.scale;\n\n return tiles\n .map(function(tile) {\n if (_skipNullIsland && nearNullIsland(tile)) {\n return false;\n }\n var x = tile[0] * ts - origin[0];\n var y = tile[1] * ts - origin[1];\n return {\n id: tile.toString(),\n xyz: tile,\n extent: geoExtent(\n projection.invert([x, y + ts]),\n projection.invert([x + ts, y])\n )\n };\n }).filter(Boolean);\n };\n\n\n /**\n * getGeoJSON() returns a FeatureCollection for debugging tiles\n */\n tiler.getGeoJSON = function(projection) {\n var features = tiler.getTiles(projection).map(function(tile) {\n return {\n type: 'Feature',\n properties: {\n id: tile.id,\n name: tile.id\n },\n geometry: {\n type: 'Polygon',\n coordinates: [ tile.extent.polygon() ]\n }\n };\n });\n\n return {\n type: 'FeatureCollection',\n features: features\n };\n };\n\n\n tiler.tileSize = function(val) {\n if (!arguments.length) return _tileSize;\n _tileSize = val;\n return tiler;\n };\n\n\n tiler.zoomExtent = function(val) {\n if (!arguments.length) return _zoomExtent;\n _zoomExtent = val;\n return tiler;\n };\n\n\n tiler.size = function(val) {\n if (!arguments.length) return _size;\n _size = val;\n return tiler;\n };\n\n\n tiler.scale = function(val) {\n if (!arguments.length) return _scale;\n _scale = val;\n return tiler;\n };\n\n\n tiler.translate = function(val) {\n if (!arguments.length) return _translate;\n _translate = val;\n return tiler;\n };\n\n\n // number to extend the rows/columns beyond those covering the viewport\n tiler.margin = function(val) {\n if (!arguments.length) return _margin;\n _margin = +val;\n return tiler;\n };\n\n\n tiler.skipNullIsland = function(val) {\n if (!arguments.length) return _skipNullIsland;\n _skipNullIsland = val;\n return tiler;\n };\n\n\n return tiler;\n}\n","export function utilTriggerEvent(target, type) {\n target.each(function() {\n var evt = document.createEvent('HTMLEvents');\n evt.initEvent(type, true, true);\n this.dispatchEvent(evt);\n });\n}\n","import { fileFetcher } from './file_fetcher';\nimport { utilDetect } from '../util/detect';\nimport { utilStringQs } from '../util';\n\nlet _mainLocalizer = coreLocalizer(); // singleton\nlet _t = _mainLocalizer.t;\n\nexport {\n _mainLocalizer as localizer,\n // export `t` function for ease-of-use\n _t as t\n};\n\n//\n// coreLocalizer manages language and locale parameters including translated strings\n//\nexport function coreLocalizer() {\n\n let localizer = {};\n\n let _dataLanguages = {};\n\n // `localeData` is an object containing all _supported_ locale codes -> language info.\n // {\n // en: { rtl: false, languageNames: {…}, scriptNames: {…} },\n // de: { rtl: false, languageNames: {…}, scriptNames: {…} },\n // …\n // }\n let _dataLocales = {};\n\n // `localeStrings` is an object containing all _loaded_ locale codes -> string data.\n // {\n // en: { icons: {…}, toolbar: {…}, modes: {…}, operations: {…}, … },\n // de: { icons: {…}, toolbar: {…}, modes: {…}, operations: {…}, … },\n // …\n // }\n let _localeStrings = {};\n\n // the current locale parameters\n let _localeCode = 'en-US';\n let _languageCode = 'en';\n let _textDirection = 'ltr';\n let _usesMetric = false;\n let _languageNames = {};\n let _scriptNames = {};\n\n // getters for the current locale parameters\n localizer.localeCode = () => _localeCode;\n localizer.languageCode = () => _languageCode;\n localizer.textDirection = () => _textDirection;\n localizer.usesMetric = () => _usesMetric;\n localizer.languageNames = () => _languageNames;\n localizer.scriptNames = () => _scriptNames;\n\n\n // The client app may want to manually set the locale, regardless of the\n // settings provided by the browser\n let _preferredLocaleCodes = [];\n localizer.preferredLocaleCodes = function(codes) {\n if (!arguments.length) return _preferredLocaleCodes;\n if (typeof codes === 'string') {\n // be generous and accept delimited strings as input\n _preferredLocaleCodes = codes.split(/,|;| /gi).filter(Boolean);\n } else {\n _preferredLocaleCodes = codes;\n }\n return localizer;\n };\n\n\n var _loadPromise;\n\n localizer.ensureLoaded = () => {\n\n if (_loadPromise) return _loadPromise;\n\n return _loadPromise = Promise.all([\n // load the list of langauges\n fileFetcher.get('languages'),\n // load the list of supported locales\n fileFetcher.get('locales')\n ])\n .then(results => {\n _dataLanguages = results[0];\n _dataLocales = results[1];\n })\n .then(() => {\n let requestedLocales = (_preferredLocaleCodes || [])\n // list of locales preferred by the browser in priority order\n .concat(utilDetect().browserLocales);\n _localeCode = bestSupportedLocale(requestedLocales);\n\n return Promise.all([\n // always load the English locale strings as fallbacks\n localizer.loadLocale('en'),\n // load the preferred locale\n localizer.loadLocale(_localeCode)\n ]);\n })\n .then(() => {\n updateForCurrentLocale();\n })\n .catch(err => console.error(err)); // eslint-disable-line\n };\n\n // Returns the best locale from `locales` supported by iD, if any\n function bestSupportedLocale(locales) {\n let supportedLocales = _dataLocales;\n\n for (let i in locales) {\n let locale = locales[i];\n if (locale.includes('-')) { // full locale ('es-ES')\n\n if (supportedLocales[locale]) return locale;\n\n // If full locale not supported ('es-FAKE'), fallback to the base ('es')\n let langPart = locale.split('-')[0];\n if (supportedLocales[langPart]) return langPart;\n\n } else { // base locale ('es')\n\n // prefer a lower-priority full locale with this base ('es' < 'es-ES')\n let fullLocale = locales.find((locale2, index) => {\n return index > i &&\n locale2 !== locale &&\n locale2.split('-')[0] === locale &&\n supportedLocales[locale2];\n });\n if (fullLocale) return fullLocale;\n\n if (supportedLocales[locale]) return locale;\n }\n }\n\n return null;\n }\n\n function updateForCurrentLocale() {\n if (!_localeCode) return;\n\n _languageCode = _localeCode.split('-')[0];\n\n const currentData = _dataLocales[_localeCode] || _dataLocales[_languageCode];\n\n const hash = utilStringQs(window.location.hash);\n\n if (hash.rtl === 'true') {\n _textDirection = 'rtl';\n } else if (hash.rtl === 'false') {\n _textDirection = 'ltr';\n } else {\n _textDirection = currentData && currentData.rtl ? 'rtl' : 'ltr';\n }\n\n _languageNames = currentData && currentData.languageNames;\n _scriptNames = currentData && currentData.scriptNames;\n\n _usesMetric = _localeCode.slice(-3).toLowerCase() !== '-us';\n }\n\n\n /* Locales */\n // Returns a Promise to load the strings for the requested locale\n localizer.loadLocale = (requested) => {\n\n if (!_dataLocales) {\n return Promise.reject('loadLocale called before init');\n }\n\n let locale = requested;\n\n // US English is the default\n if (locale.toLowerCase() === 'en-us') locale = 'en';\n\n if (!_dataLocales[locale]) {\n return Promise.reject(`Unsupported locale: ${requested}`);\n }\n\n if (_localeStrings[locale]) { // already loaded\n return Promise.resolve(locale);\n }\n\n let fileMap = fileFetcher.fileMap();\n const key = `locale_${locale}`;\n fileMap[key] = `locales/${locale}.json`;\n\n return fileFetcher.get(key)\n .then(d => {\n _localeStrings[locale] = d[locale];\n return locale;\n });\n };\n\n /**\n * Given a string identifier, try to find that string in the current\n * language, and return it. This function will be called recursively\n * with locale `en` if a string can not be found in the requested language.\n *\n * @param {string} s string identifier\n * @param {object?} replacements token replacements and default string\n * @param {string?} locale locale to use (defaults to currentLocale)\n * @return {string?} localized string\n */\n localizer.t = function(s, replacements, locale) {\n locale = locale || _localeCode;\n\n // US English is the default\n if (locale.toLowerCase() === 'en-us') locale = 'en';\n\n let path = s\n .split('.')\n .map(s => s.replace(//g, '.'))\n .reverse();\n\n let result = _localeStrings[locale];\n\n while (result !== undefined && path.length) {\n result = result[path.pop()];\n }\n\n if (result !== undefined) {\n if (replacements) {\n for (let k in replacements) {\n const token = `{${k}}`;\n const regex = new RegExp(token, 'g');\n result = result.replace(regex, replacements[k]);\n }\n }\n return result;\n }\n\n if (locale !== 'en') {\n return localizer.t(s, replacements, 'en'); // fallback - recurse with 'en'\n }\n\n if (replacements && 'default' in replacements) {\n return replacements.default; // fallback - replacements.default\n }\n\n const missing = `Missing ${locale} translation: ${s}`;\n if (typeof console !== 'undefined') console.error(missing); // eslint-disable-line\n\n return missing;\n };\n\n localizer.languageName = (code, options) => {\n\n if (_languageNames[code]) { // name in locale langauge\n // e.g. \"German\"\n return _languageNames[code];\n }\n\n // sometimes we only want the local name\n if (options && options.localOnly) return null;\n\n const langInfo = _dataLanguages[code];\n if (langInfo) {\n if (langInfo.nativeName) { // name in native language\n // e.g. \"Deutsch (de)\"\n return localizer.t('translate.language_and_code', { language: langInfo.nativeName, code: code });\n\n } else if (langInfo.base && langInfo.script) {\n const base = langInfo.base; // the code of the langauge this is based on\n\n if (_languageNames[base]) { // base language name in locale langauge\n const scriptCode = langInfo.script;\n const script = _scriptNames[scriptCode] || scriptCode;\n // e.g. \"Serbian (Cyrillic)\"\n return localizer.t('translate.language_and_code', { language: _languageNames[base], code: script });\n\n } else if (_dataLanguages[base] && _dataLanguages[base].nativeName) {\n // e.g. \"српски (sr-Cyrl)\"\n return localizer.t('translate.language_and_code', { language: _dataLanguages[base].nativeName, code: code });\n }\n }\n }\n return code; // if not found, use the code\n };\n\n return localizer;\n}\n","import { utilArrayUniq, utilEditDistance } from '../util';\n\n\n//\n// `presetCollection` is a wrapper around an `Array` of presets `collection`,\n// and decorated with some extra methods for searching and matching geometry\n//\nexport function presetCollection(collection) {\n const MAXRESULTS = 50;\n let _this = {};\n let _memo = {};\n\n _this.collection = collection;\n\n _this.item = (id) => {\n if (_memo[id]) return _memo[id];\n const found = _this.collection.find(d => d.id === id);\n if (found) _memo[id] = found;\n return found;\n };\n\n _this.index = (id) => _this.collection.findIndex(d => d.id === id);\n\n _this.matchGeometry = (geometry) => {\n return presetCollection(\n _this.collection.filter(d => d.matchGeometry(geometry))\n );\n };\n\n _this.matchAllGeometry = (geometries) => {\n return presetCollection(\n _this.collection.filter(d => d && d.matchAllGeometry(geometries))\n );\n };\n\n _this.matchAnyGeometry = (geometries) => {\n return presetCollection(\n _this.collection.filter(d => geometries.some(geom => d.matchGeometry(geom)))\n );\n };\n\n _this.fallback = (geometry) => {\n let id = geometry;\n if (id === 'vertex') id = 'point';\n return _this.item(id);\n };\n\n _this.search = (value, geometry, countryCode) => {\n if (!value) return _this;\n\n value = value.toLowerCase().trim();\n\n // match at name beginning or just after a space (e.g. \"office\" -> match \"Law Office\")\n function leading(a) {\n const index = a.indexOf(value);\n return index === 0 || a[index - 1] === ' ';\n }\n\n // match at name beginning only\n function leadingStrict(a) {\n const index = a.indexOf(value);\n return index === 0;\n }\n\n function sortNames(a, b) {\n let aCompare = (a.suggestion ? a.originalName : a.name()).toLowerCase();\n let bCompare = (b.suggestion ? b.originalName : b.name()).toLowerCase();\n\n // priority if search string matches preset name exactly - #4325\n if (value === aCompare) return -1;\n if (value === bCompare) return 1;\n\n // priority for higher matchScore\n let i = b.originalScore - a.originalScore;\n if (i !== 0) return i;\n\n // priority if search string appears earlier in preset name\n i = aCompare.indexOf(value) - bCompare.indexOf(value);\n if (i !== 0) return i;\n\n // priority for shorter preset names\n return aCompare.length - bCompare.length;\n }\n\n let pool = _this.collection;\n if (countryCode) {\n pool = pool.filter(a => {\n if (a.countryCodes && a.countryCodes.indexOf(countryCode) === -1) return false;\n if (a.notCountryCodes && a.notCountryCodes.indexOf(countryCode) !== -1) return false;\n return true;\n });\n }\n const searchable = pool.filter(a => a.searchable !== false && a.suggestion !== true);\n const suggestions = pool.filter(a => a.suggestion === true);\n\n // matches value to preset.name\n const leading_name = searchable\n .filter(a => leading(a.name().toLowerCase()))\n .sort(sortNames);\n\n // matches value to preset suggestion name (original name is unhyphenated)\n const leading_suggestions = suggestions\n .filter(a => leadingStrict(a.originalName.toLowerCase()))\n .sort(sortNames);\n\n // matches value to preset.terms values\n const leading_terms = searchable\n .filter(a => (a.terms() || []).some(leading));\n\n // matches value to preset.tags values\n const leading_tag_values = searchable\n .filter(a => Object.values(a.tags || {}).filter(val => val !== '*').some(leading));\n\n // finds close matches to value in preset.name\n const similar_name = searchable\n .map(a => ({ preset: a, dist: utilEditDistance(value, a.name()) }))\n .filter(a => a.dist + Math.min(value.length - a.preset.name().length, 0) < 3)\n .sort((a, b) => a.dist - b.dist)\n .map(a => a.preset);\n\n // finds close matches to value to preset suggestion name (original name is unhyphenated)\n const similar_suggestions = suggestions\n .map(a => ({ preset: a, dist: utilEditDistance(value, a.originalName.toLowerCase()) }))\n .filter(a => a.dist + Math.min(value.length - a.preset.originalName.length, 0) < 1)\n .sort((a, b) => a.dist - b.dist)\n .map(a => a.preset);\n\n // finds close matches to value in preset.terms\n const similar_terms = searchable\n .filter(a => {\n return (a.terms() || []).some(b => {\n return utilEditDistance(value, b) + Math.min(value.length - b.length, 0) < 3;\n });\n });\n\n let results = leading_name.concat(\n leading_suggestions,\n leading_terms,\n leading_tag_values,\n similar_name,\n similar_suggestions,\n similar_terms\n ).slice(0, MAXRESULTS - 1);\n\n if (geometry) {\n if (typeof geometry === 'string') {\n results.push(_this.fallback(geometry));\n } else {\n geometry.forEach(geom => results.push(_this.fallback(geom)));\n }\n }\n\n return presetCollection(utilArrayUniq(results));\n };\n\n\n return _this;\n}\n","import { t } from '../core/localizer';\nimport { presetCollection } from './collection';\n\n\n//\n// `presetCategory` builds a `presetCollection` of member presets,\n// decorated with some extra methods for searching and matching geometry\n//\nexport function presetCategory(categoryID, category, all) {\n let _this = Object.assign({}, category); // shallow copy\n\n _this.id = categoryID;\n\n _this.members = presetCollection(\n category.members.map(presetID => all.item(presetID)).filter(Boolean)\n );\n\n _this.geometry = _this.members.collection\n .reduce((acc, preset) => {\n for (let i in preset.geometry) {\n const geometry = preset.geometry[i];\n if (acc.indexOf(geometry) === -1) {\n acc.push(geometry);\n }\n }\n return acc;\n }, []);\n\n _this.matchGeometry = (geom) => _this.geometry.indexOf(geom) >= 0;\n\n _this.matchAllGeometry = (geometries) => _this.members.collection\n .some(preset => preset.matchAllGeometry(geometries));\n\n _this.matchScore = () => -1;\n\n _this.name = () => t(`presets.categories.${categoryID}.name`, { 'default': categoryID });\n\n _this.terms = () => [];\n\n\n return _this;\n}\n","import { t } from '../core/localizer';\nimport { utilSafeClassName } from '../util/util';\n\n\n//\n// `presetField` decorates a given `field` Object\n// with some extra methods for searching and matching geometry\n//\nexport function presetField(fieldID, field) {\n let _this = Object.assign({}, field); // shallow copy\n\n _this.id = fieldID;\n\n // for use in classes, element ids, css selectors\n _this.safeid = utilSafeClassName(fieldID);\n\n _this.matchGeometry = (geom) => !_this.geometry || _this.geometry.indexOf(geom) !== -1;\n\n _this.matchAllGeometry = (geometries) => {\n return !_this.geometry || geometries.every(geom => _this.geometry.indexOf(geom) !== -1);\n };\n\n _this.t = (scope, options) => t(`presets.fields.${fieldID}.${scope}`, options);\n\n _this.label = () => _this.overrideLabel || _this.t('label', { 'default': fieldID });\n\n const _placeholder = _this.placeholder;\n _this.placeholder = () => _this.t('placeholder', { 'default': _placeholder });\n\n _this.originalTerms = (_this.terms || []).join();\n\n _this.terms = () => _this.t('terms', { 'default': _this.originalTerms })\n .toLowerCase().trim().split(/\\s*,+\\s*/);\n\n\n return _this;\n}\n","import { t } from '../core/localizer';\nimport { osmAreaKeys } from '../osm/tags';\nimport { utilArrayUniq, utilObjectOmit } from '../util';\nimport { utilSafeClassName } from '../util/util';\n\n\n//\n// `presetPreset` decorates a given `preset` Object\n// with some extra methods for searching and matching geometry\n//\nexport function presetPreset(presetID, preset, addable, allFields, allPresets) {\n allFields = allFields || {};\n allPresets = allPresets || {};\n let _this = Object.assign({}, preset); // shallow copy\n let _addable = addable || false;\n let _resolvedFields; // cache\n let _resolvedMoreFields; // cache\n\n _this.id = presetID;\n\n _this.safeid = utilSafeClassName(presetID); // for use in css classes, selectors, element ids\n\n _this.originalTerms = (_this.terms || []).join();\n\n _this.originalName = _this.name || '';\n\n _this.originalScore = _this.matchScore || 1;\n\n _this.originalReference = _this.reference || {};\n\n _this.originalFields = (_this.fields || []);\n\n _this.originalMoreFields = (_this.moreFields || []);\n\n _this.fields = () => _resolvedFields || (_resolvedFields = resolve('fields'));\n\n _this.moreFields = () => _resolvedMoreFields || (_resolvedMoreFields = resolve('moreFields'));\n\n _this.resetFields = () => _resolvedFields = _resolvedMoreFields = null;\n\n _this.tags = _this.tags || {};\n\n _this.addTags = _this.addTags || _this.tags;\n\n _this.removeTags = _this.removeTags || _this.addTags;\n\n _this.geometry = (_this.geometry || []);\n\n _this.matchGeometry = (geom) => _this.geometry.indexOf(geom) >= 0;\n\n _this.matchAllGeometry = (geoms) => geoms.every(_this.matchGeometry);\n\n _this.matchScore = (entityTags) => {\n const tags = _this.tags;\n let seen = {};\n let score = 0;\n\n // match on tags\n for (let k in tags) {\n seen[k] = true;\n if (entityTags[k] === tags[k]) {\n score += _this.originalScore;\n } else if (tags[k] === '*' && k in entityTags) {\n score += _this.originalScore / 2;\n } else {\n return -1;\n }\n }\n\n // boost score for additional matches in addTags - #6802\n const addTags = _this.addTags;\n for (let k in addTags) {\n if (!seen[k] && entityTags[k] === addTags[k]) {\n score += _this.originalScore;\n }\n }\n\n return score;\n };\n\n\n let _textCache = {};\n _this.t = (scope, options) => {\n const textID = `presets.presets.${presetID}.${scope}`;\n if (_textCache[textID]) return _textCache[textID];\n return _textCache[textID] = t(textID, options);\n };\n\n\n _this.name = () => {\n if (_this.suggestion) {\n let path = presetID.split('/');\n path.pop(); // remove brand name\n // NOTE: insert an en-dash, not a hypen (to avoid conflict with fr - nl names in Brussels etc)\n return _this.originalName + ' – ' + t('presets.presets.' + path.join('/') + '.name');\n }\n return _this.t('name', { 'default': _this.originalName });\n };\n\n\n _this.terms = () => _this.t('terms', { 'default': _this.originalTerms })\n .toLowerCase().trim().split(/\\s*,+\\s*/);\n\n\n _this.isFallback = () => {\n const tagCount = Object.keys(_this.tags).length;\n return tagCount === 0 || (tagCount === 1 && _this.tags.hasOwnProperty('area'));\n };\n\n\n _this.addable = function(val) {\n if (!arguments.length) return _addable;\n _addable = val;\n return _this;\n };\n\n\n _this.reference = (geom) => {\n // Lookup documentation on Wikidata...\n const qid = _this.tags.wikidata || _this.tags['brand:wikidata'] || _this.tags['operator:wikidata'];\n if (qid) {\n return { qid: qid };\n }\n\n // Lookup documentation on OSM Wikibase...\n let key = _this.originalReference.key || Object.keys(utilObjectOmit(_this.tags, 'name'))[0];\n let value = _this.originalReference.value || _this.tags[key];\n\n if (geom === 'relation' && key === 'type') {\n if (value in _this.tags) {\n key = value;\n value = _this.tags[key];\n } else {\n return { rtype: value };\n }\n }\n\n if (value === '*') {\n return { key: key };\n } else {\n return { key: key, value: value };\n }\n };\n\n\n _this.unsetTags = (tags, geometry, skipFieldDefaults) => {\n tags = utilObjectOmit(tags, Object.keys(_this.removeTags));\n\n if (geometry && !skipFieldDefaults) {\n _this.fields().forEach(field => {\n if (field.matchGeometry(geometry) && field.key && field.default === tags[field.key]) {\n delete tags[field.key];\n }\n });\n }\n\n delete tags.area;\n return tags;\n };\n\n\n _this.setTags = (tags, geometry, skipFieldDefaults) => {\n const addTags = _this.addTags;\n tags = Object.assign({}, tags); // shallow copy\n\n for (let k in addTags) {\n if (addTags[k] === '*') {\n tags[k] = 'yes';\n } else {\n tags[k] = addTags[k];\n }\n }\n\n // Add area=yes if necessary.\n // This is necessary if the geometry is already an area (e.g. user drew an area) AND any of:\n // 1. chosen preset could be either an area or a line (`barrier=city_wall`)\n // 2. chosen preset doesn't have a key in osmAreaKeys (`railway=station`)\n if (!addTags.hasOwnProperty('area')) {\n delete tags.area;\n if (geometry === 'area') {\n let needsAreaTag = true;\n if (_this.geometry.indexOf('line') === -1) {\n for (let k in addTags) {\n if (k in osmAreaKeys) {\n needsAreaTag = false;\n break;\n }\n }\n }\n if (needsAreaTag) {\n tags.area = 'yes';\n }\n }\n }\n\n if (geometry && !skipFieldDefaults) {\n _this.fields().forEach(field => {\n if (field.matchGeometry(geometry) && field.key && !tags[field.key] && field.default) {\n tags[field.key] = field.default;\n }\n });\n }\n\n return tags;\n };\n\n\n // For a preset without fields, use the fields of the parent preset.\n // Replace {preset} placeholders with the fields of the specified presets.\n function resolve(which) {\n const fieldIDs = (which === 'fields' ? _this.originalFields : _this.originalMoreFields);\n let resolved = [];\n\n fieldIDs.forEach(fieldID => {\n const match = fieldID.match(/\\{(.*)\\}/);\n if (match !== null) { // a presetID wrapped in braces {}\n resolved = resolved.concat(inheritFields(match[1], which));\n } else if (allFields[fieldID]) { // a normal fieldID\n resolved.push(allFields[fieldID]);\n } else {\n console.log(`Cannot resolve \"${fieldID}\" found in ${_this.id}.${which}`); // eslint-disable-line no-console\n }\n });\n\n // no fields resolved, so use the parent's if possible\n if (!resolved.length) {\n const endIndex = _this.id.lastIndexOf('/');\n const parentID = endIndex && _this.id.substring(0, endIndex);\n if (parentID) {\n resolved = inheritFields(parentID, which);\n }\n }\n\n return utilArrayUniq(resolved);\n\n\n // returns an array of fields to inherit from the given presetID, if found\n function inheritFields(presetID, which) {\n const parent = allPresets[presetID];\n if (!parent) return [];\n\n if (which === 'fields') {\n return parent.fields().filter(shouldInherit);\n } else if (which === 'moreFields') {\n return parent.moreFields();\n } else {\n return [];\n }\n }\n\n\n // Skip `fields` for the keys which define the preset.\n // These are usually `typeCombo` fields like `shop=*`\n function shouldInherit(f) {\n if (f.key && _this.tags[f.key] !== undefined &&\n // inherit anyway if multiple values are allowed or just a checkbox\n f.type !== 'multiCombo' && f.type !== 'semiCombo' && f.type !== 'check'\n ) return false;\n\n return true;\n }\n }\n\n\n return _this;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\n\nimport { prefs } from '../core/preferences';\nimport { fileFetcher } from '../core/file_fetcher';\nimport { osmNodeGeometriesForTags, osmSetAreaKeys, osmSetPointTags, osmSetVertexTags } from '../osm/tags';\nimport { presetCategory } from './category';\nimport { presetCollection } from './collection';\nimport { presetField } from './field';\nimport { presetPreset } from './preset';\nimport { utilArrayUniq, utilRebind } from '../util';\n\nexport { presetCategory };\nexport { presetCollection };\nexport { presetField };\nexport { presetPreset };\n\nlet _mainPresetIndex = presetIndex(); // singleton\nexport { _mainPresetIndex as presetManager };\n\n//\n// `presetIndex` wraps a `presetCollection`\n// with methods for loading new data and returning defaults\n//\nexport function presetIndex() {\n const dispatch = d3_dispatch('favoritePreset', 'recentsChange');\n const MAXRECENTS = 30;\n\n // seed the preset lists with geometry fallbacks\n const POINT = presetPreset('point', { name: 'Point', tags: {}, geometry: ['point', 'vertex'], matchScore: 0.1 } );\n const LINE = presetPreset('line', { name: 'Line', tags: {}, geometry: ['line'], matchScore: 0.1 } );\n const AREA = presetPreset('area', { name: 'Area', tags: { area: 'yes' }, geometry: ['area'], matchScore: 0.1 } );\n const RELATION = presetPreset('relation', { name: 'Relation', tags: {}, geometry: ['relation'], matchScore: 0.1 } );\n\n let _this = presetCollection([POINT, LINE, AREA, RELATION]);\n let _presets = { point: POINT, line: LINE, area: AREA, relation: RELATION };\n\n let _defaults = {\n point: presetCollection([POINT]),\n vertex: presetCollection([POINT]),\n line: presetCollection([LINE]),\n area: presetCollection([AREA]),\n relation: presetCollection([RELATION])\n };\n\n let _fields = {};\n let _categories = {};\n let _universal = [];\n let _addablePresetIDs = null; // Set of preset IDs that the user can add\n let _recents;\n let _favorites;\n\n // Index of presets by (geometry, tag key).\n let _geometryIndex = { point: {}, vertex: {}, line: {}, area: {}, relation: {} };\n\n let _loadPromise;\n\n _this.ensureLoaded = () => {\n if (_loadPromise) return _loadPromise;\n\n return _loadPromise = Promise.all([\n fileFetcher.get('preset_categories'),\n fileFetcher.get('preset_defaults'),\n fileFetcher.get('preset_presets'),\n fileFetcher.get('preset_fields')\n ])\n .then(vals => {\n _this.merge({\n categories: vals[0],\n defaults: vals[1],\n presets: vals[2],\n fields: vals[3]\n });\n osmSetAreaKeys(_this.areaKeys());\n osmSetPointTags(_this.pointTags());\n osmSetVertexTags(_this.vertexTags());\n });\n };\n\n\n _this.merge = (d) => {\n // Merge Fields\n if (d.fields) {\n Object.keys(d.fields).forEach(fieldID => {\n const f = d.fields[fieldID];\n if (f) { // add or replace\n _fields[fieldID] = presetField(fieldID, f);\n } else { // remove\n delete _fields[fieldID];\n }\n });\n }\n\n // Merge Presets\n if (d.presets) {\n Object.keys(d.presets).forEach(presetID => {\n const p = d.presets[presetID];\n if (p) { // add or replace\n const isAddable = !_addablePresetIDs || _addablePresetIDs.has(presetID);\n _presets[presetID] = presetPreset(presetID, p, isAddable, _fields, _presets);\n } else { // remove (but not if it's a fallback)\n const existing = _presets[presetID];\n if (existing && !existing.isFallback()) {\n delete _presets[presetID];\n }\n }\n });\n }\n\n // Need to rebuild _this.collection before loading categories\n _this.collection = Object.values(_presets).concat(Object.values(_categories));\n\n // Merge Categories\n if (d.categories) {\n Object.keys(d.categories).forEach(categoryID => {\n const c = d.categories[categoryID];\n if (c) { // add or replace\n _categories[categoryID] = presetCategory(categoryID, c, _this);\n } else { // remove\n delete _categories[categoryID];\n }\n });\n }\n\n // Rebuild _this.collection after loading categories\n _this.collection = Object.values(_presets).concat(Object.values(_categories));\n\n // Merge Defaults\n if (d.defaults) {\n Object.keys(d.defaults).forEach(geometry => {\n const def = d.defaults[geometry];\n if (Array.isArray(def)) { // add or replace\n _defaults[geometry] = presetCollection(\n def.map(id => _presets[id] || _categories[id]).filter(Boolean)\n );\n } else { // remove\n delete _defaults[geometry];\n }\n });\n }\n\n // Rebuild universal fields array\n _universal = Object.values(_fields).filter(field => field.universal);\n\n // Reset all the preset fields - they'll need to be resolved again\n Object.values(_presets).forEach(preset => preset.resetFields());\n\n // Rebuild geometry index\n _geometryIndex = { point: {}, vertex: {}, line: {}, area: {}, relation: {} };\n _this.collection.forEach(preset => {\n (preset.geometry || []).forEach(geometry => {\n let g = _geometryIndex[geometry];\n for (let key in preset.tags) {\n (g[key] = g[key] || []).push(preset);\n }\n });\n });\n\n return _this;\n };\n\n\n _this.match = (entity, resolver) => {\n return resolver.transient(entity, 'presetMatch', () => {\n let geometry = entity.geometry(resolver);\n // Treat entities on addr:interpolation lines as points, not vertices - #3241\n if (geometry === 'vertex' && entity.isOnAddressLine(resolver)) {\n geometry = 'point';\n }\n return _this.matchTags(entity.tags, geometry);\n });\n };\n\n\n _this.matchTags = (tags, geometry) => {\n const geometryMatches = _geometryIndex[geometry];\n let address;\n let best = -1;\n let match;\n\n for (let k in tags) {\n // If any part of an address is present, allow fallback to \"Address\" preset - #4353\n if (/^addr:/.test(k) && geometryMatches['addr:*']) {\n address = geometryMatches['addr:*'][0];\n }\n\n const keyMatches = geometryMatches[k];\n if (!keyMatches) continue;\n\n for (let i = 0; i < keyMatches.length; i++) {\n const score = keyMatches[i].matchScore(tags);\n if (score > best) {\n best = score;\n match = keyMatches[i];\n }\n }\n }\n\n if (address && (!match || match.isFallback())) {\n match = address;\n }\n return match || _this.fallback(geometry);\n };\n\n\n _this.allowsVertex = (entity, resolver) => {\n if (entity.type !== 'node') return false;\n if (Object.keys(entity.tags).length === 0) return true;\n\n return resolver.transient(entity, 'vertexMatch', () => {\n // address lines allow vertices to act as standalone points\n if (entity.isOnAddressLine(resolver)) return true;\n\n const geometries = osmNodeGeometriesForTags(entity.tags);\n if (geometries.vertex) return true;\n if (geometries.point) return false;\n // allow vertices for unspecified points\n return true;\n });\n };\n\n\n // Because of the open nature of tagging, iD will never have a complete\n // list of tags used in OSM, so we want it to have logic like \"assume\n // that a closed way with an amenity tag is an area, unless the amenity\n // is one of these specific types\". This function computes a structure\n // that allows testing of such conditions, based on the presets designated\n // as as supporting (or not supporting) the area geometry.\n //\n // The returned object L is a keeplist/discardlist of tags. A closed way\n // with a tag (k, v) is considered to be an area if `k in L && !(v in L[k])`\n // (see `Way#isArea()`). In other words, the keys of L form the keeplist,\n // and the subkeys form the discardlist.\n _this.areaKeys = () => {\n // The ignore list is for keys that imply lines. (We always add `area=yes` for exceptions)\n const ignore = ['barrier', 'highway', 'footway', 'railway', 'junction', 'type'];\n let areaKeys = {};\n\n // ignore name-suggestion-index and deprecated presets\n const presets = _this.collection.filter(p => !p.suggestion && !p.replacement);\n\n // keeplist\n presets.forEach(p => {\n let key;\n for (key in p.tags) break; // pick the first tag\n if (!key) return;\n if (ignore.indexOf(key) !== -1) return;\n\n if (p.geometry.indexOf('area') !== -1) { // probably an area..\n areaKeys[key] = areaKeys[key] || {};\n }\n });\n\n // discardlist\n presets.forEach(p => {\n let key;\n for (key in p.addTags) {\n // examine all addTags to get a better sense of what can be tagged on lines - #6800\n const value = p.addTags[key];\n if (key in areaKeys && // probably an area...\n p.geometry.indexOf('line') !== -1 && // but sometimes a line\n value !== '*') {\n areaKeys[key][value] = true;\n }\n }\n });\n\n return areaKeys;\n };\n\n\n _this.pointTags = () => {\n return _this.collection.reduce((pointTags, d) => {\n // ignore name-suggestion-index, deprecated, and generic presets\n if (d.suggestion || d.replacement || d.searchable === false) return pointTags;\n\n // only care about the primary tag\n let key;\n for (key in d.tags) break; // pick the first tag\n if (!key) return pointTags;\n\n // if this can be a point\n if (d.geometry.indexOf('point') !== -1) {\n pointTags[key] = pointTags[key] || {};\n pointTags[key][d.tags[key]] = true;\n }\n return pointTags;\n }, {});\n };\n\n\n _this.vertexTags = () => {\n return _this.collection.reduce((vertexTags, d) => {\n // ignore name-suggestion-index, deprecated, and generic presets\n if (d.suggestion || d.replacement || d.searchable === false) return vertexTags;\n\n // only care about the primary tag\n let key;\n for (key in d.tags) break; // pick the first tag\n if (!key) return vertexTags;\n\n // if this can be a vertex\n if (d.geometry.indexOf('vertex') !== -1) {\n vertexTags[key] = vertexTags[key] || {};\n vertexTags[key][d.tags[key]] = true;\n }\n return vertexTags;\n }, {});\n };\n\n\n _this.field = (id) => _fields[id];\n\n _this.universal = () => _universal;\n\n\n _this.defaults = (geometry, n, startWithRecents) => {\n let recents = [];\n if (startWithRecents) {\n recents = _this.recent().matchGeometry(geometry).collection.slice(0, 4);\n }\n let defaults;\n if (_addablePresetIDs) {\n defaults = Array.from(_addablePresetIDs).map(function(id) {\n var preset = _this.item(id);\n if (preset && preset.matchGeometry(geometry)) return preset;\n return null;\n }).filter(Boolean);\n } else {\n defaults = _defaults[geometry].collection.concat(_this.fallback(geometry));\n }\n\n return presetCollection(\n utilArrayUniq(recents.concat(defaults)).slice(0, n - 1)\n );\n };\n\n // pass a Set of addable preset ids\n _this.addablePresetIDs = function(val) {\n if (!arguments.length) return _addablePresetIDs;\n\n // accept and convert arrays\n if (Array.isArray(val)) val = new Set(val);\n\n _addablePresetIDs = val;\n if (_addablePresetIDs) { // reset all presets\n _this.collection.forEach(p => {\n // categories aren't addable\n if (p.addable) p.addable(_addablePresetIDs.has(p.id));\n });\n } else {\n _this.collection.forEach(p => {\n if (p.addable) p.addable(true);\n });\n }\n\n return _this;\n };\n\n\n _this.recent = () => {\n return presetCollection(\n utilArrayUniq(_this.getRecents().map(d => d.preset))\n );\n };\n\n\n function RibbonItem(preset, source) {\n let item = {};\n item.preset = preset;\n item.source = source;\n\n item.isFavorite = () => item.source === 'favorite';\n item.isRecent = () => item.source === 'recent';\n item.matches = (preset) => item.preset.id === preset.id;\n item.minified = () => ({ pID: item.preset.id });\n\n return item;\n }\n\n\n function ribbonItemForMinified(d, source) {\n if (d && d.pID) {\n const preset = _this.item(d.pID);\n if (!preset) return null;\n return RibbonItem(preset, source);\n }\n return null;\n }\n\n\n _this.getGenericRibbonItems = () => {\n return ['point', 'line', 'area'].map(id => RibbonItem(_this.item(id), 'generic'));\n };\n\n\n _this.getAddable = () => {\n if (!_addablePresetIDs) return [];\n\n return _addablePresetIDs.map((id) => {\n const preset = _this.item(id);\n if (preset) {\n return RibbonItem(preset, 'addable');\n }\n }).filter(Boolean);\n };\n\n\n function setRecents(items) {\n _recents = items;\n const minifiedItems = items.map(d => d.minified());\n prefs('preset_recents', JSON.stringify(minifiedItems));\n dispatch.call('recentsChange');\n }\n\n\n _this.getRecents = () => {\n if (!_recents) {\n // fetch from local storage\n _recents = (JSON.parse(prefs('preset_recents')) || [])\n .reduce((acc, d) => {\n let item = ribbonItemForMinified(d, 'recent');\n if (item && item.preset.addable()) acc.push(item);\n return acc;\n }, []);\n }\n return _recents;\n };\n\n\n _this.addRecent = (preset, besidePreset, after) => {\n const recents = _this.getRecents();\n\n const beforeItem = _this.recentMatching(besidePreset);\n let toIndex = recents.indexOf(beforeItem);\n if (after) toIndex += 1;\n\n const newItem = RibbonItem(preset, 'recent');\n recents.splice(toIndex, 0, newItem);\n setRecents(recents);\n };\n\n\n _this.removeRecent = (preset) => {\n const item = _this.recentMatching(preset);\n if (item) {\n let items = _this.getRecents();\n items.splice(items.indexOf(item), 1);\n setRecents(items);\n }\n };\n\n\n _this.recentMatching = (preset) => {\n const items = _this.getRecents();\n for (let i in items) {\n if (items[i].matches(preset)) {\n return items[i];\n }\n }\n return null;\n };\n\n\n _this.moveItem = (items, fromIndex, toIndex) => {\n if (fromIndex === toIndex ||\n fromIndex < 0 || toIndex < 0 ||\n fromIndex >= items.length || toIndex >= items.length\n ) return null;\n\n items.splice(toIndex, 0, items.splice(fromIndex, 1)[0]);\n return items;\n };\n\n\n _this.moveRecent = (item, beforeItem) => {\n const recents = _this.getRecents();\n const fromIndex = recents.indexOf(item);\n const toIndex = recents.indexOf(beforeItem);\n const items = _this.moveItem(recents, fromIndex, toIndex);\n if (items) setRecents(items);\n };\n\n\n _this.setMostRecent = (preset) => {\n if (preset.searchable === false) return;\n\n let items = _this.getRecents();\n let item = _this.recentMatching(preset);\n if (item) {\n items.splice(items.indexOf(item), 1);\n } else {\n item = RibbonItem(preset, 'recent');\n }\n\n // remove the last recent (first in, first out)\n while (items.length >= MAXRECENTS) {\n items.pop();\n }\n\n // prepend array\n items.unshift(item);\n setRecents(items);\n };\n\n function setFavorites(items) {\n _favorites = items;\n const minifiedItems = items.map(d => d.minified());\n prefs('preset_favorites', JSON.stringify(minifiedItems));\n\n // call update\n dispatch.call('favoritePreset');\n }\n\n _this.addFavorite = (preset, besidePreset, after) => {\n const favorites = _this.getFavorites();\n\n const beforeItem = _this.favoriteMatching(besidePreset);\n let toIndex = favorites.indexOf(beforeItem);\n if (after) toIndex += 1;\n\n const newItem = RibbonItem(preset, 'favorite');\n favorites.splice(toIndex, 0, newItem);\n setFavorites(favorites);\n };\n\n _this.toggleFavorite = (preset) => {\n const favs = _this.getFavorites();\n const favorite = _this.favoriteMatching(preset);\n if (favorite) {\n favs.splice(favs.indexOf(favorite), 1);\n } else {\n // only allow 10 favorites\n if (favs.length === 10) {\n // remove the last favorite (last in, first out)\n favs.pop();\n }\n // append array\n favs.push(RibbonItem(preset, 'favorite'));\n }\n setFavorites(favs);\n };\n\n\n _this.removeFavorite = (preset) => {\n const item = _this.favoriteMatching(preset);\n if (item) {\n const items = _this.getFavorites();\n items.splice(items.indexOf(item), 1);\n setFavorites(items);\n }\n };\n\n\n _this.getFavorites = () => {\n if (!_favorites) {\n\n // fetch from local storage\n let rawFavorites = JSON.parse(prefs('preset_favorites'));\n\n if (!rawFavorites) {\n rawFavorites = [];\n prefs('preset_favorites', JSON.stringify(rawFavorites));\n }\n\n _favorites = rawFavorites.reduce((output, d) => {\n const item = ribbonItemForMinified(d, 'favorite');\n if (item && item.preset.addable()) output.push(item);\n return output;\n }, []);\n }\n return _favorites;\n };\n\n\n _this.favoriteMatching = (preset) => {\n const favs = _this.getFavorites();\n for (let index in favs) {\n if (favs[index].matches(preset)) {\n return favs[index];\n }\n }\n return null;\n };\n\n\n return utilRebind(_this, dispatch, 'on');\n}\n","import { remove as removeDiacritics } from 'diacritics';\nimport { fixRTLTextForSvg, rtlRegex } from './svg_paths_rtl_fix';\n\nimport { presetManager } from '../presets';\nimport { t, localizer } from '../core/localizer';\nimport { utilArrayUnion } from './array';\nimport { utilDetect } from './detect';\nimport { geoExtent } from '../geo/extent';\n\n\nexport function utilTagText(entity) {\n var obj = (entity && entity.tags) || {};\n return Object.keys(obj)\n .map(function(k) { return k + '=' + obj[k]; })\n .join(', ');\n}\n\n\nexport function utilTotalExtent(array, graph) {\n var extent = geoExtent();\n var val, entity;\n for (var i = 0; i < array.length; i++) {\n val = array[i];\n entity = typeof val === 'string' ? graph.hasEntity(val) : val;\n if (entity) {\n extent._extend(entity.extent(graph));\n }\n }\n return extent;\n}\n\n\nexport function utilTagDiff(oldTags, newTags) {\n var tagDiff = [];\n var keys = utilArrayUnion(Object.keys(oldTags), Object.keys(newTags)).sort();\n keys.forEach(function(k) {\n var oldVal = oldTags[k];\n var newVal = newTags[k];\n\n if ((oldVal || oldVal === '') && (newVal === undefined || newVal !== oldVal)) {\n tagDiff.push({\n type: '-',\n key: k,\n oldVal: oldVal,\n newVal: newVal,\n display: '- ' + k + '=' + oldVal\n });\n }\n if ((newVal || newVal === '') && (oldVal === undefined || newVal !== oldVal)) {\n tagDiff.push({\n type: '+',\n key: k,\n oldVal: oldVal,\n newVal: newVal,\n display: '+ ' + k + '=' + newVal\n });\n }\n });\n return tagDiff;\n}\n\n\nexport function utilEntitySelector(ids) {\n return ids.length ? '.' + ids.join(',.') : 'nothing';\n}\n\n\n// returns an selector to select entity ids for:\n// - entityIDs passed in\n// - shallow descendant entityIDs for any of those entities that are relations\nexport function utilEntityOrMemberSelector(ids, graph) {\n var seen = new Set(ids);\n ids.forEach(collectShallowDescendants);\n return utilEntitySelector(Array.from(seen));\n\n function collectShallowDescendants(id) {\n var entity = graph.hasEntity(id);\n if (!entity || entity.type !== 'relation') return;\n\n entity.members\n .map(function(member) { return member.id; })\n .forEach(function(id) { seen.add(id); });\n }\n}\n\n\n// returns an selector to select entity ids for:\n// - entityIDs passed in\n// - deep descendant entityIDs for any of those entities that are relations\nexport function utilEntityOrDeepMemberSelector(ids, graph) {\n return utilEntitySelector(utilEntityAndDeepMemberIDs(ids, graph));\n}\n\n\n// returns an selector to select entity ids for:\n// - entityIDs passed in\n// - deep descendant entityIDs for any of those entities that are relations\nexport function utilEntityAndDeepMemberIDs(ids, graph) {\n var seen = new Set();\n ids.forEach(collectDeepDescendants);\n return Array.from(seen);\n\n function collectDeepDescendants(id) {\n if (seen.has(id)) return;\n seen.add(id);\n\n var entity = graph.hasEntity(id);\n if (!entity || entity.type !== 'relation') return;\n\n entity.members\n .map(function(member) { return member.id; })\n .forEach(collectDeepDescendants); // recurse\n }\n}\n\n// returns an selector to select entity ids for:\n// - deep descendant entityIDs for any of those entities that are relations\nexport function utilDeepMemberSelector(ids, graph, skipMultipolgonMembers) {\n var idsSet = new Set(ids);\n var seen = new Set();\n var returners = new Set();\n ids.forEach(collectDeepDescendants);\n return utilEntitySelector(Array.from(returners));\n\n function collectDeepDescendants(id) {\n if (seen.has(id)) return;\n seen.add(id);\n\n if (!idsSet.has(id)) {\n returners.add(id);\n }\n\n var entity = graph.hasEntity(id);\n if (!entity || entity.type !== 'relation') return;\n if (skipMultipolgonMembers && entity.isMultipolygon()) return;\n entity.members\n .map(function(member) { return member.id; })\n .forEach(collectDeepDescendants); // recurse\n }\n}\n\n\n// Adds or removes highlight styling for the specified entities\nexport function utilHighlightEntities(ids, highlighted, context) {\n context.surface()\n .selectAll(utilEntityOrDeepMemberSelector(ids, context.graph()))\n .classed('highlighted', highlighted);\n}\n\n\n// returns an Array that is the union of:\n// - nodes for any nodeIDs passed in\n// - child nodes of any wayIDs passed in\n// - descendant member and child nodes of relationIDs passed in\nexport function utilGetAllNodes(ids, graph) {\n var seen = new Set();\n var nodes = new Set();\n\n ids.forEach(collectNodes);\n return Array.from(nodes);\n\n function collectNodes(id) {\n if (seen.has(id)) return;\n seen.add(id);\n\n var entity = graph.hasEntity(id);\n if (!entity) return;\n\n if (entity.type === 'node') {\n nodes.add(entity);\n } else if (entity.type === 'way') {\n entity.nodes.forEach(collectNodes);\n } else {\n entity.members\n .map(function(member) { return member.id; })\n .forEach(collectNodes); // recurse\n }\n }\n}\n\n\nexport function utilDisplayName(entity) {\n var localizedNameKey = 'name:' + localizer.languageCode().toLowerCase();\n var name = entity.tags[localizedNameKey] || entity.tags.name || '';\n var network = entity.tags.cycle_network || entity.tags.network;\n\n if (!name && entity.tags.ref) {\n name = entity.tags.ref;\n if (network) {\n name = network + ' ' + name;\n }\n }\n\n return name;\n}\n\n\nexport function utilDisplayNameForPath(entity) {\n var name = utilDisplayName(entity);\n var isFirefox = utilDetect().browser.toLowerCase().indexOf('firefox') > -1;\n\n if (!isFirefox && name && rtlRegex.test(name)) {\n name = fixRTLTextForSvg(name);\n }\n\n return name;\n}\n\n\nexport function utilDisplayType(id) {\n return {\n n: t('inspector.node'),\n w: t('inspector.way'),\n r: t('inspector.relation')\n }[id.charAt(0)];\n}\n\n\nexport function utilDisplayLabel(entity, graph) {\n var displayName = utilDisplayName(entity);\n if (displayName) {\n // use the display name if there is one\n return displayName;\n }\n var preset = presetManager.match(entity, graph);\n if (preset && preset.name()) {\n // use the preset name if there is a match\n return preset.name();\n }\n // fallback to the display type (node/way/relation)\n return utilDisplayType(entity.id);\n}\n\n\nexport function utilEntityRoot(entityType) {\n return {\n node: 'n',\n way: 'w',\n relation: 'r'\n }[entityType];\n}\n\n\n// Returns a single object containing the tags of all the given entities.\n// Example:\n// {\n// highway: 'service',\n// service: 'parking_aisle'\n// }\n// +\n// {\n// highway: 'service',\n// service: 'driveway',\n// width: '3'\n// }\n// =\n// {\n// highway: 'service',\n// service: [ 'driveway', 'parking_aisle' ],\n// width: [ '3', undefined ]\n// }\nexport function utilCombinedTags(entityIDs, graph) {\n\n var tags = {};\n var tagCounts = {};\n var allKeys = new Set();\n\n var entities = entityIDs.map(function(entityID) {\n return graph.hasEntity(entityID);\n }).filter(Boolean);\n\n // gather the aggregate keys\n entities.forEach(function(entity) {\n var keys = Object.keys(entity.tags).filter(Boolean);\n keys.forEach(function(key) {\n allKeys.add(key);\n });\n });\n\n entities.forEach(function(entity) {\n\n allKeys.forEach(function(key) {\n\n var value = entity.tags[key]; // purposely allow `undefined`\n\n if (!tags.hasOwnProperty(key)) {\n // first value, set as raw\n tags[key] = value;\n } else {\n if (!Array.isArray(tags[key])) {\n if (tags[key] !== value) {\n // first alternate value, replace single value with array\n tags[key] = [tags[key], value];\n }\n } else { // type is array\n if (tags[key].indexOf(value) === -1) {\n // subsequent alternate value, add to array\n tags[key].push(value);\n }\n }\n }\n\n var tagHash = key + '=' + value;\n if (!tagCounts[tagHash]) tagCounts[tagHash] = 0;\n tagCounts[tagHash] += 1;\n });\n });\n\n for (var key in tags) {\n if (!Array.isArray(tags[key])) continue;\n\n // sort values by frequency then alphabetically\n tags[key] = tags[key].sort(function(val1, val2) {\n var key = key; // capture\n var count2 = tagCounts[key + '=' + val2];\n var count1 = tagCounts[key + '=' + val1];\n if (count2 !== count1) {\n return count2 - count1;\n }\n if (val2 && val1) {\n return val1.localeCompare(val2);\n }\n return val1 ? 1 : -1;\n });\n }\n\n return tags;\n}\n\n\nexport function utilStringQs(str) {\n var i = 0; // advance past any leading '?' or '#' characters\n while (i < str.length && (str[i] === '?' || str[i] === '#')) i++;\n str = str.slice(i);\n\n return str.split('&').reduce(function(obj, pair){\n var parts = pair.split('=');\n if (parts.length === 2) {\n obj[parts[0]] = (null === parts[1]) ? '' : decodeURIComponent(parts[1]);\n }\n return obj;\n }, {});\n}\n\n\nexport function utilQsString(obj, noencode) {\n // encode everything except special characters used in certain hash parameters:\n // \"/\" in map states, \":\", \",\", {\" and \"}\" in background\n function softEncode(s) {\n return encodeURIComponent(s).replace(/(%2F|%3A|%2C|%7B|%7D)/g, decodeURIComponent);\n }\n\n return Object.keys(obj).sort().map(function(key) {\n return encodeURIComponent(key) + '=' + (\n noencode ? softEncode(obj[key]) : encodeURIComponent(obj[key]));\n }).join('&');\n}\n\n\nexport function utilPrefixDOMProperty(property) {\n var prefixes = ['webkit', 'ms', 'moz', 'o'];\n var i = -1;\n var n = prefixes.length;\n var s = document.body;\n\n if (property in s)\n return property;\n\n property = property.substr(0, 1).toUpperCase() + property.substr(1);\n\n while (++i < n) {\n if (prefixes[i] + property in s) {\n return prefixes[i] + property;\n }\n }\n\n return false;\n}\n\n\nexport function utilPrefixCSSProperty(property) {\n var prefixes = ['webkit', 'ms', 'Moz', 'O'];\n var i = -1;\n var n = prefixes.length;\n var s = document.body.style;\n\n if (property.toLowerCase() in s) {\n return property.toLowerCase();\n }\n\n while (++i < n) {\n if (prefixes[i] + property in s) {\n return '-' + prefixes[i].toLowerCase() + property.replace(/([A-Z])/g, '-$1').toLowerCase();\n }\n }\n\n return false;\n}\n\n\nvar transformProperty;\nexport function utilSetTransform(el, x, y, scale) {\n var prop = transformProperty = transformProperty || utilPrefixCSSProperty('Transform');\n var translate = utilDetect().opera ? 'translate(' + x + 'px,' + y + 'px)'\n : 'translate3d(' + x + 'px,' + y + 'px,0)';\n return el.style(prop, translate + (scale ? ' scale(' + scale + ')' : ''));\n}\n\n\n// Calculates Levenshtein distance between two strings\n// see: https://en.wikipedia.org/wiki/Levenshtein_distance\n// first converts the strings to lowercase and replaces diacritic marks with ascii equivalents.\nexport function utilEditDistance(a, b) {\n a = removeDiacritics(a.toLowerCase());\n b = removeDiacritics(b.toLowerCase());\n if (a.length === 0) return b.length;\n if (b.length === 0) return a.length;\n var matrix = [];\n for (var i = 0; i <= b.length; i++) { matrix[i] = [i]; }\n for (var j = 0; j <= a.length; j++) { matrix[0][j] = j; }\n for (i = 1; i <= b.length; i++) {\n for (j = 1; j <= a.length; j++) {\n if (b.charAt(i-1) === a.charAt(j-1)) {\n matrix[i][j] = matrix[i-1][j-1];\n } else {\n matrix[i][j] = Math.min(matrix[i-1][j-1] + 1, // substitution\n Math.min(matrix[i][j-1] + 1, // insertion\n matrix[i-1][j] + 1)); // deletion\n }\n }\n }\n return matrix[b.length][a.length];\n}\n\n\n// a d3.mouse-alike which\n// 1. Only works on HTML elements, not SVG\n// 2. Does not cause style recalculation\nexport function utilFastMouse(container) {\n var rect = container.getBoundingClientRect();\n var rectLeft = rect.left;\n var rectTop = rect.top;\n var clientLeft = +container.clientLeft;\n var clientTop = +container.clientTop;\n return function(e) {\n return [\n e.clientX - rectLeft - clientLeft,\n e.clientY - rectTop - clientTop];\n };\n}\n\n\nexport function utilAsyncMap(inputs, func, callback) {\n var remaining = inputs.length;\n var results = [];\n var errors = [];\n\n inputs.forEach(function(d, i) {\n func(d, function done(err, data) {\n errors[i] = err;\n results[i] = data;\n remaining--;\n if (!remaining) callback(errors, results);\n });\n });\n}\n\n\n// wraps an index to an interval [0..length-1]\nexport function utilWrap(index, length) {\n if (index < 0) {\n index += Math.ceil(-index/length)*length;\n }\n return index % length;\n}\n\n\n/**\n * a replacement for functor\n *\n * @param {*} value any value\n * @returns {Function} a function that returns that value or the value if it's a function\n */\nexport function utilFunctor(value) {\n if (typeof value === 'function') return value;\n return function() {\n return value;\n };\n}\n\n\nexport function utilNoAuto(selection) {\n var isText = (selection.size() && selection.node().tagName.toLowerCase() === 'textarea');\n\n return selection\n // assign 'new-password' even for non-password fields to prevent browsers (Chrome) ignoring 'off'\n .attr('autocomplete', 'new-password')\n .attr('autocorrect', 'off')\n .attr('autocapitalize', 'off')\n .attr('spellcheck', isText ? 'true' : 'false');\n}\n\n\n// https://stackoverflow.com/questions/194846/is-there-any-kind-of-hash-code-function-in-javascript\n// https://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/\nexport function utilHashcode(str) {\n var hash = 0;\n if (str.length === 0) {\n return hash;\n }\n for (var i = 0; i < str.length; i++) {\n var char = str.charCodeAt(i);\n hash = ((hash << 5) - hash) + char;\n hash = hash & hash; // Convert to 32bit integer\n }\n return hash;\n}\n\n// Returns version of `str` with all runs of special characters replaced by `_`;\n// suitable for HTML ids, classes, selectors, etc.\nexport function utilSafeClassName(str) {\n return str.toLowerCase().replace(/[^a-z0-9]+/g, '_');\n}\n\n// Returns string based on `val` that is highly unlikely to collide with an id\n// used previously or that's present elsewhere in the document. Useful for preventing\n// browser-provided autofills or when embedding iD on pages with unknown elements.\nexport function utilUniqueDomId(val) {\n return 'ideditor-' + utilSafeClassName(val.toString()) + '-' + new Date().getTime().toString();\n}\n\n// Returns the length of `str` in unicode characters. This can be less than\n// `String.length()` since a single unicode character can be composed of multiple\n// JavaScript UTF-16 code units.\nexport function utilUnicodeCharsCount(str) {\n // Native ES2015 implementations of `Array.from` split strings into unicode characters\n return Array.from(str).length;\n}\n\n// Returns a new string representing `str` cut from its start to `limit` length\n// in unicode characters. Note that this runs the risk of splitting graphemes.\nexport function utilUnicodeCharsTruncated(str, limit) {\n return Array.from(str).slice(0, limit).join('');\n}\n","import { debug } from '../index';\nimport { osmIsInterestingTag } from './tags';\nimport { utilArrayUnion } from '../util/array';\nimport { utilUnicodeCharsTruncated } from '../util/util';\n\n\nexport function osmEntity(attrs) {\n // For prototypal inheritance.\n if (this instanceof osmEntity) return;\n\n // Create the appropriate subtype.\n if (attrs && attrs.type) {\n return osmEntity[attrs.type].apply(this, arguments);\n } else if (attrs && attrs.id) {\n return osmEntity[osmEntity.id.type(attrs.id)].apply(this, arguments);\n }\n\n // Initialize a generic Entity (used only in tests).\n return (new osmEntity()).initialize(arguments);\n}\n\n\nosmEntity.id = function(type) {\n return osmEntity.id.fromOSM(type, osmEntity.id.next[type]--);\n};\n\n\nosmEntity.id.next = {\n changeset: -1, node: -1, way: -1, relation: -1\n};\n\n\nosmEntity.id.fromOSM = function(type, id) {\n return type[0] + id;\n};\n\n\nosmEntity.id.toOSM = function(id) {\n return id.slice(1);\n};\n\n\nosmEntity.id.type = function(id) {\n return { 'c': 'changeset', 'n': 'node', 'w': 'way', 'r': 'relation' }[id[0]];\n};\n\n\n// A function suitable for use as the second argument to d3.selection#data().\nosmEntity.key = function(entity) {\n return entity.id + 'v' + (entity.v || 0);\n};\n\nvar _deprecatedTagValuesByKey;\n\nosmEntity.deprecatedTagValuesByKey = function(dataDeprecated) {\n if (!_deprecatedTagValuesByKey) {\n _deprecatedTagValuesByKey = {};\n dataDeprecated.forEach(function(d) {\n var oldKeys = Object.keys(d.old);\n if (oldKeys.length === 1) {\n var oldKey = oldKeys[0];\n var oldValue = d.old[oldKey];\n if (oldValue !== '*') {\n if (!_deprecatedTagValuesByKey[oldKey]) {\n _deprecatedTagValuesByKey[oldKey] = [oldValue];\n } else {\n _deprecatedTagValuesByKey[oldKey].push(oldValue);\n }\n }\n }\n });\n }\n return _deprecatedTagValuesByKey;\n};\n\n\nosmEntity.prototype = {\n\n tags: {},\n\n\n initialize: function(sources) {\n for (var i = 0; i < sources.length; ++i) {\n var source = sources[i];\n for (var prop in source) {\n if (Object.prototype.hasOwnProperty.call(source, prop)) {\n if (source[prop] === undefined) {\n delete this[prop];\n } else {\n this[prop] = source[prop];\n }\n }\n }\n }\n\n if (!this.id && this.type) {\n this.id = osmEntity.id(this.type);\n }\n if (!this.hasOwnProperty('visible')) {\n this.visible = true;\n }\n\n if (debug) {\n Object.freeze(this);\n Object.freeze(this.tags);\n\n if (this.loc) Object.freeze(this.loc);\n if (this.nodes) Object.freeze(this.nodes);\n if (this.members) Object.freeze(this.members);\n }\n\n return this;\n },\n\n\n copy: function(resolver, copies) {\n if (copies[this.id])\n return copies[this.id];\n\n var copy = osmEntity(this, { id: undefined, user: undefined, version: undefined });\n copies[this.id] = copy;\n\n return copy;\n },\n\n\n osmId: function() {\n return osmEntity.id.toOSM(this.id);\n },\n\n\n isNew: function() {\n return this.osmId() < 0;\n },\n\n\n update: function(attrs) {\n return osmEntity(this, attrs, { v: 1 + (this.v || 0) });\n },\n\n\n mergeTags: function(tags) {\n var merged = Object.assign({}, this.tags); // shallow copy\n var changed = false;\n for (var k in tags) {\n var t1 = merged[k];\n var t2 = tags[k];\n if (!t1) {\n changed = true;\n merged[k] = t2;\n } else if (t1 !== t2) {\n changed = true;\n merged[k] = utilUnicodeCharsTruncated(\n utilArrayUnion(t1.split(/;\\s*/), t2.split(/;\\s*/)).join(';'),\n 255 // avoid exceeding character limit; see also services/osm.js -> maxCharsForTagValue()\n );\n }\n }\n return changed ? this.update({ tags: merged }) : this;\n },\n\n\n intersects: function(extent, resolver) {\n return this.extent(resolver).intersects(extent);\n },\n\n\n hasNonGeometryTags: function() {\n return Object.keys(this.tags).some(function(k) { return k !== 'area'; });\n },\n\n hasParentRelations: function(resolver) {\n return resolver.parentRelations(this).length > 0;\n },\n\n hasInterestingTags: function() {\n return Object.keys(this.tags).some(osmIsInterestingTag);\n },\n\n hasWikidata: function() {\n return !!this.tags.wikidata || !!this.tags['brand:wikidata'];\n },\n\n isHighwayIntersection: function() {\n return false;\n },\n\n isDegenerate: function() {\n return true;\n },\n\n deprecatedTags: function(dataDeprecated) {\n var tags = this.tags;\n\n // if there are no tags, none can be deprecated\n if (Object.keys(tags).length === 0) return [];\n\n var deprecated = [];\n dataDeprecated.forEach(function(d) {\n var oldKeys = Object.keys(d.old);\n var matchesDeprecatedTags = oldKeys.every(function(oldKey) {\n if (!tags[oldKey]) return false;\n if (d.old[oldKey] === '*') return true;\n\n var vals = tags[oldKey].split(';').filter(Boolean);\n if (vals.length === 0) {\n return false;\n } else if (vals.length > 1) {\n return vals.indexOf(d.old[oldKey]) !== -1;\n } else {\n if (tags[oldKey] === d.old[oldKey]) {\n if (d.replace && d.old[oldKey] === d.replace[oldKey]) {\n var replaceKeys = Object.keys(d.replace);\n return !replaceKeys.every(function(replaceKey) {\n return tags[replaceKey] === d.replace[replaceKey];\n });\n } else {\n return true;\n }\n }\n }\n return false;\n });\n if (matchesDeprecatedTags) {\n deprecated.push(d);\n }\n });\n\n return deprecated;\n }\n};\n","\nexport function osmLanes(entity) {\n if (entity.type !== 'way') return null;\n if (!entity.tags.highway) return null;\n\n var tags = entity.tags;\n var isOneWay = entity.isOneWay();\n var laneCount = getLaneCount(tags, isOneWay);\n var maxspeed = parseMaxspeed(tags);\n\n var laneDirections = parseLaneDirections(tags, isOneWay, laneCount);\n var forward = laneDirections.forward;\n var backward = laneDirections.backward;\n var bothways = laneDirections.bothways;\n\n // parse the piped string 'x|y|z' format\n var turnLanes = {};\n turnLanes.unspecified = parseTurnLanes(tags['turn:lanes']);\n turnLanes.forward = parseTurnLanes(tags['turn:lanes:forward']);\n turnLanes.backward = parseTurnLanes(tags['turn:lanes:backward']);\n\n var maxspeedLanes = {};\n maxspeedLanes.unspecified = parseMaxspeedLanes(tags['maxspeed:lanes'], maxspeed);\n maxspeedLanes.forward = parseMaxspeedLanes(tags['maxspeed:lanes:forward'], maxspeed);\n maxspeedLanes.backward = parseMaxspeedLanes(tags['maxspeed:lanes:backward'], maxspeed);\n\n var psvLanes = {};\n psvLanes.unspecified = parseMiscLanes(tags['psv:lanes']);\n psvLanes.forward = parseMiscLanes(tags['psv:lanes:forward']);\n psvLanes.backward = parseMiscLanes(tags['psv:lanes:backward']);\n\n var busLanes = {};\n busLanes.unspecified = parseMiscLanes(tags['bus:lanes']);\n busLanes.forward = parseMiscLanes(tags['bus:lanes:forward']);\n busLanes.backward = parseMiscLanes(tags['bus:lanes:backward']);\n\n var taxiLanes = {};\n taxiLanes.unspecified = parseMiscLanes(tags['taxi:lanes']);\n taxiLanes.forward = parseMiscLanes(tags['taxi:lanes:forward']);\n taxiLanes.backward = parseMiscLanes(tags['taxi:lanes:backward']);\n\n var hovLanes = {};\n hovLanes.unspecified = parseMiscLanes(tags['hov:lanes']);\n hovLanes.forward = parseMiscLanes(tags['hov:lanes:forward']);\n hovLanes.backward = parseMiscLanes(tags['hov:lanes:backward']);\n\n var hgvLanes = {};\n hgvLanes.unspecified = parseMiscLanes(tags['hgv:lanes']);\n hgvLanes.forward = parseMiscLanes(tags['hgv:lanes:forward']);\n hgvLanes.backward = parseMiscLanes(tags['hgv:lanes:backward']);\n\n var bicyclewayLanes = {};\n bicyclewayLanes.unspecified = parseBicycleWay(tags['bicycleway:lanes']);\n bicyclewayLanes.forward = parseBicycleWay(tags['bicycleway:lanes:forward']);\n bicyclewayLanes.backward = parseBicycleWay(tags['bicycleway:lanes:backward']);\n\n var lanesObj = {\n forward: [],\n backward: [],\n unspecified: []\n };\n\n // map forward/backward/unspecified of each lane type to lanesObj\n mapToLanesObj(lanesObj, turnLanes, 'turnLane');\n mapToLanesObj(lanesObj, maxspeedLanes, 'maxspeed');\n mapToLanesObj(lanesObj, psvLanes, 'psv');\n mapToLanesObj(lanesObj, busLanes, 'bus');\n mapToLanesObj(lanesObj, taxiLanes, 'taxi');\n mapToLanesObj(lanesObj, hovLanes, 'hov');\n mapToLanesObj(lanesObj, hgvLanes, 'hgv');\n mapToLanesObj(lanesObj, bicyclewayLanes, 'bicycleway');\n\n return {\n metadata: {\n count: laneCount,\n oneway: isOneWay,\n forward: forward,\n backward: backward,\n bothways: bothways,\n turnLanes: turnLanes,\n maxspeed: maxspeed,\n maxspeedLanes: maxspeedLanes,\n psvLanes: psvLanes,\n busLanes: busLanes,\n taxiLanes: taxiLanes,\n hovLanes: hovLanes,\n hgvLanes: hgvLanes,\n bicyclewayLanes: bicyclewayLanes\n },\n lanes: lanesObj\n };\n}\n\n\nfunction getLaneCount(tags, isOneWay) {\n var count;\n if (tags.lanes) {\n count = parseInt(tags.lanes, 10);\n if (count > 0) {\n return count;\n }\n }\n\n\n switch (tags.highway) {\n case 'trunk':\n case 'motorway':\n count = isOneWay ? 2 : 4;\n break;\n default:\n count = isOneWay ? 1 : 2;\n break;\n }\n\n return count;\n}\n\n\nfunction parseMaxspeed(tags) {\n var maxspeed = tags.maxspeed;\n if (!maxspeed) return;\n\n var maxspeedRegex = /^([0-9][\\.0-9]+?)(?:[ ]?(?:km\\/h|kmh|kph|mph|knots))?$/;\n if (!maxspeedRegex.test(maxspeed)) return;\n\n return parseInt(maxspeed, 10);\n}\n\n\nfunction parseLaneDirections(tags, isOneWay, laneCount) {\n var forward = parseInt(tags['lanes:forward'], 10);\n var backward = parseInt(tags['lanes:backward'], 10);\n var bothways = parseInt(tags['lanes:both_ways'], 10) > 0 ? 1 : 0;\n\n if (parseInt(tags.oneway, 10) === -1) {\n forward = 0;\n bothways = 0;\n backward = laneCount;\n }\n else if (isOneWay) {\n forward = laneCount;\n bothways = 0;\n backward = 0;\n }\n else if (isNaN(forward) && isNaN(backward)) {\n backward = Math.floor((laneCount - bothways) / 2);\n forward = laneCount - bothways - backward;\n }\n else if (isNaN(forward)) {\n if (backward > laneCount - bothways) {\n backward = laneCount - bothways;\n }\n forward = laneCount - bothways - backward;\n }\n else if (isNaN(backward)) {\n if (forward > laneCount - bothways) {\n forward = laneCount - bothways;\n }\n backward = laneCount - bothways - forward;\n }\n return {\n forward: forward,\n backward: backward,\n bothways: bothways\n };\n}\n\n\nfunction parseTurnLanes(tag){\n if (!tag) return;\n\n var validValues = [\n 'left', 'slight_left', 'sharp_left', 'through', 'right', 'slight_right',\n 'sharp_right', 'reverse', 'merge_to_left', 'merge_to_right', 'none'\n ];\n\n return tag.split('|')\n .map(function (s) {\n if (s === '') s = 'none';\n return s.split(';')\n .map(function (d) {\n return validValues.indexOf(d) === -1 ? 'unknown': d;\n });\n });\n}\n\n\nfunction parseMaxspeedLanes(tag, maxspeed) {\n if (!tag) return;\n\n return tag.split('|')\n .map(function (s) {\n if (s === 'none') return s;\n var m = parseInt(s, 10);\n if (s === '' || m === maxspeed) return null;\n return isNaN(m) ? 'unknown': m;\n });\n}\n\n\nfunction parseMiscLanes(tag) {\n if (!tag) return;\n\n var validValues = [\n 'yes', 'no', 'designated'\n ];\n\n return tag.split('|')\n .map(function (s) {\n if (s === '') s = 'no';\n return validValues.indexOf(s) === -1 ? 'unknown': s;\n });\n}\n\n\nfunction parseBicycleWay(tag) {\n if (!tag) return;\n\n var validValues = [\n 'yes', 'no', 'designated', 'lane'\n ];\n\n return tag.split('|')\n .map(function (s) {\n if (s === '') s = 'no';\n return validValues.indexOf(s) === -1 ? 'unknown': s;\n });\n}\n\n\nfunction mapToLanesObj(lanesObj, data, key) {\n if (data.forward) data.forward.forEach(function(l, i) {\n if (!lanesObj.forward[i]) lanesObj.forward[i] = {};\n lanesObj.forward[i][key] = l;\n });\n if (data.backward) data.backward.forEach(function(l, i) {\n if (!lanesObj.backward[i]) lanesObj.backward[i] = {};\n lanesObj.backward[i][key] = l;\n });\n if (data.unspecified) data.unspecified.forEach(function(l, i) {\n if (!lanesObj.unspecified[i]) lanesObj.unspecified[i] = {};\n lanesObj.unspecified[i][key] = l;\n });\n}\n","import { geoArea as d3_geoArea } from 'd3-geo';\n\nimport { geoExtent, geoVecCross } from '../geo';\nimport { osmEntity } from './entity';\nimport { osmLanes } from './lanes';\nimport { osmTagSuggestingArea, osmOneWayTags, osmRightSideIsInsideTags } from './tags';\nimport { utilArrayUniq } from '../util';\n\n\nexport function osmWay() {\n if (!(this instanceof osmWay)) {\n return (new osmWay()).initialize(arguments);\n } else if (arguments.length) {\n this.initialize(arguments);\n }\n}\n\n\nosmEntity.way = osmWay;\n\nosmWay.prototype = Object.create(osmEntity.prototype);\n\n\nObject.assign(osmWay.prototype, {\n type: 'way',\n nodes: [],\n\n\n copy: function(resolver, copies) {\n if (copies[this.id]) return copies[this.id];\n\n var copy = osmEntity.prototype.copy.call(this, resolver, copies);\n\n var nodes = this.nodes.map(function(id) {\n return resolver.entity(id).copy(resolver, copies).id;\n });\n\n copy = copy.update({ nodes: nodes });\n copies[this.id] = copy;\n\n return copy;\n },\n\n\n extent: function(resolver) {\n return resolver.transient(this, 'extent', function() {\n var extent = geoExtent();\n for (var i = 0; i < this.nodes.length; i++) {\n var node = resolver.hasEntity(this.nodes[i]);\n if (node) {\n extent._extend(node.extent());\n }\n }\n return extent;\n });\n },\n\n\n first: function() {\n return this.nodes[0];\n },\n\n\n last: function() {\n return this.nodes[this.nodes.length - 1];\n },\n\n\n contains: function(node) {\n return this.nodes.indexOf(node) >= 0;\n },\n\n\n affix: function(node) {\n if (this.nodes[0] === node) return 'prefix';\n if (this.nodes[this.nodes.length - 1] === node) return 'suffix';\n },\n\n\n layer: function() {\n // explicit layer tag, clamp between -10, 10..\n if (isFinite(this.tags.layer)) {\n return Math.max(-10, Math.min(+(this.tags.layer), 10));\n }\n\n // implied layer tag..\n if (this.tags.covered === 'yes') return -1;\n if (this.tags.location === 'overground') return 1;\n if (this.tags.location === 'underground') return -1;\n if (this.tags.location === 'underwater') return -10;\n\n if (this.tags.power === 'line') return 10;\n if (this.tags.power === 'minor_line') return 10;\n if (this.tags.aerialway) return 10;\n if (this.tags.bridge) return 1;\n if (this.tags.cutting) return -1;\n if (this.tags.tunnel) return -1;\n if (this.tags.waterway) return -1;\n if (this.tags.man_made === 'pipeline') return -10;\n if (this.tags.boundary) return -10;\n return 0;\n },\n\n\n // the approximate width of the line based on its tags except its `width` tag\n impliedLineWidthMeters: function() {\n var averageWidths = {\n highway: { // width is for single lane\n motorway: 5, motorway_link: 5, trunk: 4.5, trunk_link: 4.5,\n primary: 4, secondary: 4, tertiary: 4,\n primary_link: 4, secondary_link: 4, tertiary_link: 4,\n unclassified: 4, road: 4, living_street: 4, bus_guideway: 4, pedestrian: 4,\n residential: 3.5, service: 3.5, track: 3, cycleway: 2.5,\n bridleway: 2, corridor: 2, steps: 2, path: 1.5, footway: 1.5\n },\n railway: { // width includes ties and rail bed, not just track gauge\n rail: 2.5, light_rail: 2.5, tram: 2.5, subway: 2.5,\n monorail: 2.5, funicular: 2.5, disused: 2.5, preserved: 2.5,\n miniature: 1.5, narrow_gauge: 1.5\n },\n waterway: {\n river: 50, canal: 25, stream: 5, tidal_channel: 5, fish_pass: 2.5, drain: 2.5, ditch: 1.5\n }\n };\n for (var key in averageWidths) {\n if (this.tags[key] && averageWidths[key][this.tags[key]]) {\n var width = averageWidths[key][this.tags[key]];\n if (key === 'highway') {\n var laneCount = this.tags.lanes && parseInt(this.tags.lanes, 10);\n if (!laneCount) laneCount = this.isOneWay() ? 1 : 2;\n\n return width * laneCount;\n }\n return width;\n }\n }\n return null;\n },\n\n\n isOneWay: function() {\n // explicit oneway tag..\n var values = {\n 'yes': true,\n '1': true,\n '-1': true,\n 'reversible': true,\n 'alternating': true,\n 'no': false,\n '0': false\n };\n if (values[this.tags.oneway] !== undefined) {\n return values[this.tags.oneway];\n }\n\n // implied oneway tag..\n for (var key in this.tags) {\n if (key in osmOneWayTags && (this.tags[key] in osmOneWayTags[key]))\n return true;\n }\n return false;\n },\n\n // Some identifier for tag that implies that this way is \"sided\",\n // i.e. the right side is the 'inside' (e.g. the right side of a\n // natural=cliff is lower).\n sidednessIdentifier: function() {\n for (var key in this.tags) {\n var value = this.tags[key];\n if (key in osmRightSideIsInsideTags && (value in osmRightSideIsInsideTags[key])) {\n if (osmRightSideIsInsideTags[key][value] === true) {\n return key;\n } else {\n // if the map's value is something other than a\n // literal true, we should use it so we can\n // special case some keys (e.g. natural=coastline\n // is handled differently to other naturals).\n return osmRightSideIsInsideTags[key][value];\n }\n }\n }\n\n return null;\n },\n\n isSided: function() {\n if (this.tags.two_sided === 'yes') {\n return false;\n }\n\n return this.sidednessIdentifier() !== null;\n },\n\n lanes: function() {\n return osmLanes(this);\n },\n\n\n isClosed: function() {\n return this.nodes.length > 1 && this.first() === this.last();\n },\n\n\n isConvex: function(resolver) {\n if (!this.isClosed() || this.isDegenerate()) return null;\n\n var nodes = utilArrayUniq(resolver.childNodes(this));\n var coords = nodes.map(function(n) { return n.loc; });\n var curr = 0;\n var prev = 0;\n\n for (var i = 0; i < coords.length; i++) {\n var o = coords[(i+1) % coords.length];\n var a = coords[i];\n var b = coords[(i+2) % coords.length];\n var res = geoVecCross(a, b, o);\n\n curr = (res > 0) ? 1 : (res < 0) ? -1 : 0;\n if (curr === 0) {\n continue;\n } else if (prev && curr !== prev) {\n return false;\n }\n prev = curr;\n }\n return true;\n },\n\n // returns an object with the tag that implies this is an area, if any\n tagSuggestingArea: function() {\n return osmTagSuggestingArea(this.tags);\n },\n\n isArea: function() {\n if (this.tags.area === 'yes')\n return true;\n if (!this.isClosed() || this.tags.area === 'no')\n return false;\n return this.tagSuggestingArea() !== null;\n },\n\n\n isDegenerate: function() {\n return (new Set(this.nodes).size < (this.isArea() ? 3 : 2));\n },\n\n\n areAdjacent: function(n1, n2) {\n for (var i = 0; i < this.nodes.length; i++) {\n if (this.nodes[i] === n1) {\n if (this.nodes[i - 1] === n2) return true;\n if (this.nodes[i + 1] === n2) return true;\n }\n }\n return false;\n },\n\n\n geometry: function(graph) {\n return graph.transient(this, 'geometry', function() {\n return this.isArea() ? 'area' : 'line';\n });\n },\n\n\n // returns an array of objects representing the segments between the nodes in this way\n segments: function(graph) {\n\n function segmentExtent(graph) {\n var n1 = graph.hasEntity(this.nodes[0]);\n var n2 = graph.hasEntity(this.nodes[1]);\n return n1 && n2 && geoExtent([\n [\n Math.min(n1.loc[0], n2.loc[0]),\n Math.min(n1.loc[1], n2.loc[1])\n ],\n [\n Math.max(n1.loc[0], n2.loc[0]),\n Math.max(n1.loc[1], n2.loc[1])\n ]\n ]);\n }\n\n return graph.transient(this, 'segments', function() {\n var segments = [];\n for (var i = 0; i < this.nodes.length - 1; i++) {\n segments.push({\n id: this.id + '-' + i,\n wayId: this.id,\n index: i,\n nodes: [this.nodes[i], this.nodes[i + 1]],\n extent: segmentExtent\n });\n }\n return segments;\n });\n },\n\n\n // If this way is not closed, append the beginning node to the end of the nodelist to close it.\n close: function() {\n if (this.isClosed() || !this.nodes.length) return this;\n\n var nodes = this.nodes.slice();\n nodes = nodes.filter(noRepeatNodes);\n nodes.push(nodes[0]);\n return this.update({ nodes: nodes });\n },\n\n\n // If this way is closed, remove any connector nodes from the end of the nodelist to unclose it.\n unclose: function() {\n if (!this.isClosed()) return this;\n\n var nodes = this.nodes.slice();\n var connector = this.first();\n var i = nodes.length - 1;\n\n // remove trailing connectors..\n while (i > 0 && nodes.length > 1 && nodes[i] === connector) {\n nodes.splice(i, 1);\n i = nodes.length - 1;\n }\n\n nodes = nodes.filter(noRepeatNodes);\n return this.update({ nodes: nodes });\n },\n\n\n // Adds a node (id) in front of the node which is currently at position index.\n // If index is undefined, the node will be added to the end of the way for linear ways,\n // or just before the final connecting node for circular ways.\n // Consecutive duplicates are eliminated including existing ones.\n // Circularity is always preserved when adding a node.\n addNode: function(id, index) {\n var nodes = this.nodes.slice();\n var isClosed = this.isClosed();\n var max = isClosed ? nodes.length - 1 : nodes.length;\n\n if (index === undefined) {\n index = max;\n }\n\n if (index < 0 || index > max) {\n throw new RangeError('index ' + index + ' out of range 0..' + max);\n }\n\n // If this is a closed way, remove all connector nodes except the first one\n // (there may be duplicates) and adjust index if necessary..\n if (isClosed) {\n var connector = this.first();\n\n // leading connectors..\n var i = 1;\n while (i < nodes.length && nodes.length > 2 && nodes[i] === connector) {\n nodes.splice(i, 1);\n if (index > i) index--;\n }\n\n // trailing connectors..\n i = nodes.length - 1;\n while (i > 0 && nodes.length > 1 && nodes[i] === connector) {\n nodes.splice(i, 1);\n if (index > i) index--;\n i = nodes.length - 1;\n }\n }\n\n nodes.splice(index, 0, id);\n nodes = nodes.filter(noRepeatNodes);\n\n // If the way was closed before, append a connector node to keep it closed..\n if (isClosed && (nodes.length === 1 || nodes[0] !== nodes[nodes.length - 1])) {\n nodes.push(nodes[0]);\n }\n\n return this.update({ nodes: nodes });\n },\n\n\n // Replaces the node which is currently at position index with the given node (id).\n // Consecutive duplicates are eliminated including existing ones.\n // Circularity is preserved when updating a node.\n updateNode: function(id, index) {\n var nodes = this.nodes.slice();\n var isClosed = this.isClosed();\n var max = nodes.length - 1;\n\n if (index === undefined || index < 0 || index > max) {\n throw new RangeError('index ' + index + ' out of range 0..' + max);\n }\n\n // If this is a closed way, remove all connector nodes except the first one\n // (there may be duplicates) and adjust index if necessary..\n if (isClosed) {\n var connector = this.first();\n\n // leading connectors..\n var i = 1;\n while (i < nodes.length && nodes.length > 2 && nodes[i] === connector) {\n nodes.splice(i, 1);\n if (index > i) index--;\n }\n\n // trailing connectors..\n i = nodes.length - 1;\n while (i > 0 && nodes.length > 1 && nodes[i] === connector) {\n nodes.splice(i, 1);\n if (index === i) index = 0; // update leading connector instead\n i = nodes.length - 1;\n }\n }\n\n nodes.splice(index, 1, id);\n nodes = nodes.filter(noRepeatNodes);\n\n // If the way was closed before, append a connector node to keep it closed..\n if (isClosed && (nodes.length === 1 || nodes[0] !== nodes[nodes.length - 1])) {\n nodes.push(nodes[0]);\n }\n\n return this.update({nodes: nodes});\n },\n\n\n // Replaces each occurrence of node id needle with replacement.\n // Consecutive duplicates are eliminated including existing ones.\n // Circularity is preserved.\n replaceNode: function(needleID, replacementID) {\n var nodes = this.nodes.slice();\n var isClosed = this.isClosed();\n\n for (var i = 0; i < nodes.length; i++) {\n if (nodes[i] === needleID) {\n nodes[i] = replacementID;\n }\n }\n\n nodes = nodes.filter(noRepeatNodes);\n\n // If the way was closed before, append a connector node to keep it closed..\n if (isClosed && (nodes.length === 1 || nodes[0] !== nodes[nodes.length - 1])) {\n nodes.push(nodes[0]);\n }\n\n return this.update({nodes: nodes});\n },\n\n\n // Removes each occurrence of node id.\n // Consecutive duplicates are eliminated including existing ones.\n // Circularity is preserved.\n removeNode: function(id) {\n var nodes = this.nodes.slice();\n var isClosed = this.isClosed();\n\n nodes = nodes\n .filter(function(node) { return node !== id; })\n .filter(noRepeatNodes);\n\n // If the way was closed before, append a connector node to keep it closed..\n if (isClosed && (nodes.length === 1 || nodes[0] !== nodes[nodes.length - 1])) {\n nodes.push(nodes[0]);\n }\n\n return this.update({nodes: nodes});\n },\n\n\n asJXON: function(changeset_id) {\n var r = {\n way: {\n '@id': this.osmId(),\n '@version': this.version || 0,\n nd: this.nodes.map(function(id) {\n return { keyAttributes: { ref: osmEntity.id.toOSM(id) } };\n }, this),\n tag: Object.keys(this.tags).map(function(k) {\n return { keyAttributes: { k: k, v: this.tags[k] } };\n }, this)\n }\n };\n if (changeset_id) {\n r.way['@changeset'] = changeset_id;\n }\n return r;\n },\n\n\n asGeoJSON: function(resolver) {\n return resolver.transient(this, 'GeoJSON', function() {\n var coordinates = resolver.childNodes(this)\n .map(function(n) { return n.loc; });\n\n if (this.isArea() && this.isClosed()) {\n return {\n type: 'Polygon',\n coordinates: [coordinates]\n };\n } else {\n return {\n type: 'LineString',\n coordinates: coordinates\n };\n }\n });\n },\n\n\n area: function(resolver) {\n return resolver.transient(this, 'area', function() {\n var nodes = resolver.childNodes(this);\n\n var json = {\n type: 'Polygon',\n coordinates: [ nodes.map(function(n) { return n.loc; }) ]\n };\n\n if (!this.isClosed() && nodes.length) {\n json.coordinates[0].push(nodes[0].loc);\n }\n\n var area = d3_geoArea(json);\n\n // Heuristic for detecting counterclockwise winding order. Assumes\n // that OpenStreetMap polygons are not hemisphere-spanning.\n if (area > 2 * Math.PI) {\n json.coordinates[0] = json.coordinates[0].reverse();\n area = d3_geoArea(json);\n }\n\n return isNaN(area) ? 0 : area;\n });\n }\n});\n\n\n// Filter function to eliminate consecutive duplicates.\nfunction noRepeatNodes(node, i, arr) {\n return i === 0 || node !== arr[i - 1];\n}\n","import { actionReverse } from '../actions/reverse';\nimport { osmIsInterestingTag } from './tags';\nimport { osmWay } from './way';\n\n\n// \"Old\" multipolyons, previously known as \"simple\" multipolygons, are as follows:\n//\n// 1. Relation tagged with `type=multipolygon` and no interesting tags.\n// 2. One and only one member with the `outer` role. Must be a way with interesting tags.\n// 3. No members without a role.\n//\n// Old multipolygons are no longer recommended but are still rendered as areas by iD.\n\nexport function osmOldMultipolygonOuterMemberOfRelation(entity, graph) {\n if (entity.type !== 'relation' ||\n !entity.isMultipolygon()\n || Object.keys(entity.tags).filter(osmIsInterestingTag).length > 1) {\n return false;\n }\n\n var outerMember;\n for (var memberIndex in entity.members) {\n var member = entity.members[memberIndex];\n if (!member.role || member.role === 'outer') {\n if (outerMember) return false;\n if (member.type !== 'way') return false;\n if (!graph.hasEntity(member.id)) return false;\n\n outerMember = graph.entity(member.id);\n\n if (Object.keys(outerMember.tags).filter(osmIsInterestingTag).length === 0) {\n return false;\n }\n }\n }\n\n return outerMember;\n}\n\n// For fixing up rendering of multipolygons with tags on the outer member.\n// https://github.com/openstreetmap/iD/issues/613\nexport function osmIsOldMultipolygonOuterMember(entity, graph) {\n if (entity.type !== 'way' || Object.keys(entity.tags).filter(osmIsInterestingTag).length === 0)\n return false;\n\n var parents = graph.parentRelations(entity);\n if (parents.length !== 1)\n return false;\n\n var parent = parents[0];\n if (!parent.isMultipolygon() || Object.keys(parent.tags).filter(osmIsInterestingTag).length > 1)\n return false;\n\n var members = parent.members, member;\n for (var i = 0; i < members.length; i++) {\n member = members[i];\n if (member.id === entity.id && member.role && member.role !== 'outer')\n return false; // Not outer member\n if (member.id !== entity.id && (!member.role || member.role === 'outer'))\n return false; // Not a simple multipolygon\n }\n\n return parent;\n}\n\n\nexport function osmOldMultipolygonOuterMember(entity, graph) {\n if (entity.type !== 'way')\n return false;\n\n var parents = graph.parentRelations(entity);\n if (parents.length !== 1)\n return false;\n\n var parent = parents[0];\n if (!parent.isMultipolygon() || Object.keys(parent.tags).filter(osmIsInterestingTag).length > 1)\n return false;\n\n var members = parent.members, member, outerMember;\n for (var i = 0; i < members.length; i++) {\n member = members[i];\n if (!member.role || member.role === 'outer') {\n if (outerMember)\n return false; // Not a simple multipolygon\n outerMember = member;\n }\n }\n\n if (!outerMember)\n return false;\n\n var outerEntity = graph.hasEntity(outerMember.id);\n if (!outerEntity || !Object.keys(outerEntity.tags).filter(osmIsInterestingTag).length)\n return false;\n\n return outerEntity;\n}\n\n\n// Join `toJoin` array into sequences of connecting ways.\n\n// Segments which share identical start/end nodes will, as much as possible,\n// be connected with each other.\n//\n// The return value is a nested array. Each constituent array contains elements\n// of `toJoin` which have been determined to connect.\n//\n// Each consitituent array also has a `nodes` property whose value is an\n// ordered array of member nodes, with appropriate order reversal and\n// start/end coordinate de-duplication.\n//\n// Members of `toJoin` must have, at minimum, `type` and `id` properties.\n// Thus either an array of `osmWay`s or a relation member array may be used.\n//\n// If an member is an `osmWay`, its tags and childnodes may be reversed via\n// `actionReverse` in the output.\n//\n// The returned sequences array also has an `actions` array property, containing\n// any reversal actions that should be applied to the graph, should the calling\n// code attempt to actually join the given ways.\n//\n// Incomplete members (those for which `graph.hasEntity(element.id)` returns\n// false) and non-way members are ignored.\n//\nexport function osmJoinWays(toJoin, graph) {\n function resolve(member) {\n return graph.childNodes(graph.entity(member.id));\n }\n\n function reverse(item) {\n var action = actionReverse(item.id, { reverseOneway: true });\n sequences.actions.push(action);\n return (item instanceof osmWay) ? action(graph).entity(item.id) : item;\n }\n\n // make a copy containing only the items to join\n toJoin = toJoin.filter(function(member) {\n return member.type === 'way' && graph.hasEntity(member.id);\n });\n\n // Are the things we are joining relation members or `osmWays`?\n // If `osmWays`, skip the \"prefer a forward path\" code below (see #4872)\n var i;\n var joinAsMembers = true;\n for (i = 0; i < toJoin.length; i++) {\n if (toJoin[i] instanceof osmWay) {\n joinAsMembers = false;\n break;\n }\n }\n\n var sequences = [];\n sequences.actions = [];\n\n while (toJoin.length) {\n // start a new sequence\n var item = toJoin.shift();\n var currWays = [item];\n var currNodes = resolve(item).slice();\n var doneSequence = false;\n\n // add to it\n while (toJoin.length && !doneSequence) {\n var start = currNodes[0];\n var end = currNodes[currNodes.length - 1];\n var fn = null;\n var nodes = null;\n\n // Find the next way/member to join.\n for (i = 0; i < toJoin.length; i++) {\n item = toJoin[i];\n nodes = resolve(item);\n\n // (for member ordering only, not way ordering - see #4872)\n // Strongly prefer to generate a forward path that preserves the order\n // of the members array. For multipolygons and most relations, member\n // order does not matter - but for routes, it does. (see #4589)\n // If we started this sequence backwards (i.e. next member way attaches to\n // the start node and not the end node), reverse the initial way before continuing.\n if (joinAsMembers && currWays.length === 1 && nodes[0] !== end && nodes[nodes.length - 1] !== end &&\n (nodes[nodes.length - 1] === start || nodes[0] === start)\n ) {\n currWays[0] = reverse(currWays[0]);\n currNodes.reverse();\n start = currNodes[0];\n end = currNodes[currNodes.length - 1];\n }\n\n if (nodes[0] === end) {\n fn = currNodes.push; // join to end\n nodes = nodes.slice(1);\n break;\n } else if (nodes[nodes.length - 1] === end) {\n fn = currNodes.push; // join to end\n nodes = nodes.slice(0, -1).reverse();\n item = reverse(item);\n break;\n } else if (nodes[nodes.length - 1] === start) {\n fn = currNodes.unshift; // join to beginning\n nodes = nodes.slice(0, -1);\n break;\n } else if (nodes[0] === start) {\n fn = currNodes.unshift; // join to beginning\n nodes = nodes.slice(1).reverse();\n item = reverse(item);\n break;\n } else {\n fn = nodes = null;\n }\n }\n\n if (!nodes) { // couldn't find a joinable way/member\n doneSequence = true;\n break;\n }\n\n fn.apply(currWays, [item]);\n fn.apply(currNodes, nodes);\n\n toJoin.splice(i, 1);\n }\n\n currWays.nodes = currNodes;\n sequences.push(currWays);\n }\n\n return sequences;\n}\n","import { osmJoinWays } from '../osm/multipolygon';\nimport { osmWay } from '../osm/way';\nimport { utilArrayGroupBy, utilObjectOmit } from '../util';\n\n\nexport function actionAddMember(relationId, member, memberIndex, insertPair) {\n\n return function action(graph) {\n var relation = graph.entity(relationId);\n\n // There are some special rules for Public Transport v2 routes.\n var isPTv2 = /stop|platform/.test(member.role);\n\n if ((isNaN(memberIndex) || insertPair) && member.type === 'way' && !isPTv2) {\n // Try to perform sensible inserts based on how the ways join together\n graph = addWayMember(relation, graph);\n } else {\n // see https://wiki.openstreetmap.org/wiki/Public_transport#Service_routes\n // Stops and Platforms for PTv2 should be ordered first.\n // hack: We do not currently have the ability to place them in the exactly correct order.\n if (isPTv2 && isNaN(memberIndex)) {\n memberIndex = 0;\n }\n\n graph = graph.replace(relation.addMember(member, memberIndex));\n }\n\n return graph;\n };\n\n\n // Add a way member into the relation \"wherever it makes sense\".\n // In this situation we were not supplied a memberIndex.\n function addWayMember(relation, graph) {\n var groups, tempWay, item, i, j, k;\n\n // remove PTv2 stops and platforms before doing anything.\n var PTv2members = [];\n var members = [];\n for (i = 0; i < relation.members.length; i++) {\n var m = relation.members[i];\n if (/stop|platform/.test(m.role)) {\n PTv2members.push(m);\n } else {\n members.push(m);\n }\n }\n relation = relation.update({ members: members });\n\n\n if (insertPair) {\n // We're adding a member that must stay paired with an existing member.\n // (This feature is used by `actionSplit`)\n //\n // This is tricky because the members may exist multiple times in the\n // member list, and with different A-B/B-A ordering and different roles.\n // (e.g. a bus route that loops out and back - #4589).\n //\n // Replace the existing member with a temporary way,\n // so that `osmJoinWays` can treat the pair like a single way.\n tempWay = osmWay({ id: 'wTemp', nodes: insertPair.nodes });\n graph = graph.replace(tempWay);\n var tempMember = { id: tempWay.id, type: 'way', role: member.role };\n var tempRelation = relation.replaceMember({id: insertPair.originalID}, tempMember, true);\n groups = utilArrayGroupBy(tempRelation.members, 'type');\n groups.way = groups.way || [];\n\n } else {\n // Add the member anywhere, one time. Just push and let `osmJoinWays` decide where to put it.\n groups = utilArrayGroupBy(relation.members, 'type');\n groups.way = groups.way || [];\n groups.way.push(member);\n }\n\n members = withIndex(groups.way);\n var joined = osmJoinWays(members, graph);\n\n // `joined` might not contain all of the way members,\n // But will contain only the completed (downloaded) members\n for (i = 0; i < joined.length; i++) {\n var segment = joined[i];\n var nodes = segment.nodes.slice();\n var startIndex = segment[0].index;\n\n // j = array index in `members` where this segment starts\n for (j = 0; j < members.length; j++) {\n if (members[j].index === startIndex) {\n break;\n }\n }\n\n // k = each member in segment\n for (k = 0; k < segment.length; k++) {\n item = segment[k];\n var way = graph.entity(item.id);\n\n // If this is a paired item, generate members in correct order and role\n if (tempWay && item.id === tempWay.id) {\n if (nodes[0].id === insertPair.nodes[0]) {\n item.pair = [\n { id: insertPair.originalID, type: 'way', role: item.role },\n { id: insertPair.insertedID, type: 'way', role: item.role }\n ];\n } else {\n item.pair = [\n { id: insertPair.insertedID, type: 'way', role: item.role },\n { id: insertPair.originalID, type: 'way', role: item.role }\n ];\n }\n }\n\n // reorder `members` if necessary\n if (k > 0) {\n if (j+k >= members.length || item.index !== members[j+k].index) {\n moveMember(members, item.index, j+k);\n }\n }\n\n nodes.splice(0, way.nodes.length - 1);\n }\n }\n\n if (tempWay) {\n graph = graph.remove(tempWay);\n }\n\n // Final pass: skip dead items, split pairs, remove index properties\n var wayMembers = [];\n for (i = 0; i < members.length; i++) {\n item = members[i];\n if (item.index === -1) continue;\n\n if (item.pair) {\n wayMembers.push(item.pair[0]);\n wayMembers.push(item.pair[1]);\n } else {\n wayMembers.push(utilObjectOmit(item, ['index']));\n }\n }\n\n // Put stops and platforms first, then nodes, ways, relations\n // This is recommended for Public Transport v2 routes:\n // see https://wiki.openstreetmap.org/wiki/Public_transport#Service_routes\n var newMembers = PTv2members.concat( (groups.node || []), wayMembers, (groups.relation || []) );\n\n return graph.replace(relation.update({ members: newMembers }));\n\n\n // `moveMember()` changes the `members` array in place by splicing\n // the item with `.index = findIndex` to where it belongs,\n // and marking the old position as \"dead\" with `.index = -1`\n //\n // j=5, k=0 jk\n // segment 5 4 7 6\n // members 0 1 2 3 4 5 6 7 8 9 keep 5 in j+k\n //\n // j=5, k=1 j k\n // segment 5 4 7 6\n // members 0 1 2 3 4 5 6 7 8 9 move 4 to j+k\n // members 0 1 2 3 x 5 4 6 7 8 9 moved\n //\n // j=5, k=2 j k\n // segment 5 4 7 6\n // members 0 1 2 3 x 5 4 6 7 8 9 move 7 to j+k\n // members 0 1 2 3 x 5 4 7 6 x 8 9 moved\n //\n // j=5, k=3 j k\n // segment 5 4 7 6\n // members 0 1 2 3 x 5 4 7 6 x 8 9 keep 6 in j+k\n //\n function moveMember(arr, findIndex, toIndex) {\n for (var i = 0; i < arr.length; i++) {\n if (arr[i].index === findIndex) {\n break;\n }\n }\n\n var item = Object.assign({}, arr[i]); // shallow copy\n arr[i].index = -1; // mark as dead\n item.index = toIndex;\n arr.splice(toIndex, 0, item);\n }\n\n\n // This is the same as `Relation.indexedMembers`,\n // Except we don't want to index all the members, only the ways\n function withIndex(arr) {\n var result = new Array(arr.length);\n for (var i = 0; i < arr.length; i++) {\n result[i] = Object.assign({}, arr[i]); // shallow copy\n result[i].index = i;\n }\n return result;\n }\n }\n\n}\n","import { geoEdgeEqual } from '../geo';\nimport { utilArrayIntersection } from '../util';\n\n\nexport function actionAddMidpoint(midpoint, node) {\n return function(graph) {\n graph = graph.replace(node.move(midpoint.loc));\n\n var parents = utilArrayIntersection(\n graph.parentWays(graph.entity(midpoint.edge[0])),\n graph.parentWays(graph.entity(midpoint.edge[1]))\n );\n\n parents.forEach(function(way) {\n for (var i = 0; i < way.nodes.length - 1; i++) {\n if (geoEdgeEqual([way.nodes[i], way.nodes[i + 1]], midpoint.edge)) {\n graph = graph.replace(graph.entity(way.id).addNode(node.id, i + 1));\n\n // Add only one midpoint on doubled-back segments,\n // turning them into self-intersections.\n return;\n }\n }\n });\n\n return graph;\n };\n}\n","// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/AddNodeToWayAction.as\nexport function actionAddVertex(wayId, nodeId, index) {\n return function(graph) {\n return graph.replace(graph.entity(wayId).addNode(nodeId, index));\n };\n}\n","export function actionChangeMember(relationId, member, memberIndex) {\n return function(graph) {\n return graph.replace(graph.entity(relationId).updateMember(member, memberIndex));\n };\n}\n","export function actionChangePreset(entityID, oldPreset, newPreset, skipFieldDefaults) {\n return function action(graph) {\n var entity = graph.entity(entityID);\n var geometry = entity.geometry(graph);\n var tags = entity.tags;\n\n if (oldPreset) tags = oldPreset.unsetTags(tags, geometry);\n if (newPreset) tags = newPreset.setTags(tags, geometry, skipFieldDefaults);\n\n return graph.replace(entity.update({tags: tags}));\n };\n}\n","export function actionChangeTags(entityId, tags) {\n return function(graph) {\n var entity = graph.entity(entityId);\n return graph.replace(entity.update({tags: tags}));\n };\n}\n","import { osmEntity } from './entity';\nimport { geoAngle, geoExtent } from '../geo';\nimport { utilArrayUniq } from '../util';\n\n\nexport function osmNode() {\n if (!(this instanceof osmNode)) {\n return (new osmNode()).initialize(arguments);\n } else if (arguments.length) {\n this.initialize(arguments);\n }\n}\n\nosmEntity.node = osmNode;\n\nosmNode.prototype = Object.create(osmEntity.prototype);\n\nObject.assign(osmNode.prototype, {\n type: 'node',\n loc: [9999, 9999],\n\n extent: function() {\n return new geoExtent(this.loc);\n },\n\n\n geometry: function(graph) {\n return graph.transient(this, 'geometry', function() {\n return graph.isPoi(this) ? 'point' : 'vertex';\n });\n },\n\n\n move: function(loc) {\n return this.update({loc: loc});\n },\n\n\n isDegenerate: function() {\n return !(\n Array.isArray(this.loc) && this.loc.length === 2 &&\n this.loc[0] >= -180 && this.loc[0] <= 180 &&\n this.loc[1] >= -90 && this.loc[1] <= 90\n );\n },\n\n\n // Inspect tags and geometry to determine which direction(s) this node/vertex points\n directions: function(resolver, projection) {\n var val;\n var i;\n\n // which tag to use?\n if (this.isHighwayIntersection(resolver) && (this.tags.stop || '').toLowerCase() === 'all') {\n // all-way stop tag on a highway intersection\n val = 'all';\n } else {\n // generic direction tag\n val = (this.tags.direction || '').toLowerCase();\n\n // better suffix-style direction tag\n var re = /:direction$/i;\n var keys = Object.keys(this.tags);\n for (i = 0; i < keys.length; i++) {\n if (re.test(keys[i])) {\n val = this.tags[keys[i]].toLowerCase();\n break;\n }\n }\n }\n\n if (val === '') return [];\n\n var cardinal = {\n north: 0, n: 0,\n northnortheast: 22, nne: 22,\n northeast: 45, ne: 45,\n eastnortheast: 67, ene: 67,\n east: 90, e: 90,\n eastsoutheast: 112, ese: 112,\n southeast: 135, se: 135,\n southsoutheast: 157, sse: 157,\n south: 180, s: 180,\n southsouthwest: 202, ssw: 202,\n southwest: 225, sw: 225,\n westsouthwest: 247, wsw: 247,\n west: 270, w: 270,\n westnorthwest: 292, wnw: 292,\n northwest: 315, nw: 315,\n northnorthwest: 337, nnw: 337\n };\n\n\n var values = val.split(';');\n var results = [];\n\n values.forEach(function(v) {\n // swap cardinal for numeric directions\n if (cardinal[v] !== undefined) {\n v = cardinal[v];\n }\n\n // numeric direction - just add to results\n if (v !== '' && !isNaN(+v)) {\n results.push(+v);\n return;\n }\n\n // string direction - inspect parent ways\n var lookBackward =\n (this.tags['traffic_sign:backward'] || v === 'backward' || v === 'both' || v === 'all');\n var lookForward =\n (this.tags['traffic_sign:forward'] || v === 'forward' || v === 'both' || v === 'all');\n\n if (!lookForward && !lookBackward) return;\n\n var nodeIds = {};\n resolver.parentWays(this).forEach(function(parent) {\n var nodes = parent.nodes;\n for (i = 0; i < nodes.length; i++) {\n if (nodes[i] === this.id) { // match current entity\n if (lookForward && i > 0) {\n nodeIds[nodes[i - 1]] = true; // look back to prev node\n }\n if (lookBackward && i < nodes.length - 1) {\n nodeIds[nodes[i + 1]] = true; // look ahead to next node\n }\n }\n }\n }, this);\n\n Object.keys(nodeIds).forEach(function(nodeId) {\n // +90 because geoAngle returns angle from X axis, not Y (north)\n results.push(\n (geoAngle(this, resolver.entity(nodeId), projection) * (180 / Math.PI)) + 90\n );\n }, this);\n\n }, this);\n\n return utilArrayUniq(results);\n },\n\n\n isEndpoint: function(resolver) {\n return resolver.transient(this, 'isEndpoint', function() {\n var id = this.id;\n return resolver.parentWays(this).filter(function(parent) {\n return !parent.isClosed() && !!parent.affix(id);\n }).length > 0;\n });\n },\n\n\n isConnected: function(resolver) {\n return resolver.transient(this, 'isConnected', function() {\n var parents = resolver.parentWays(this);\n\n if (parents.length > 1) {\n // vertex is connected to multiple parent ways\n for (var i in parents) {\n if (parents[i].geometry(resolver) === 'line' &&\n parents[i].hasInterestingTags()) return true;\n }\n } else if (parents.length === 1) {\n var way = parents[0];\n var nodes = way.nodes.slice();\n if (way.isClosed()) { nodes.pop(); } // ignore connecting node if closed\n\n // return true if vertex appears multiple times (way is self intersecting)\n return nodes.indexOf(this.id) !== nodes.lastIndexOf(this.id);\n }\n\n return false;\n });\n },\n\n\n parentIntersectionWays: function(resolver) {\n return resolver.transient(this, 'parentIntersectionWays', function() {\n return resolver.parentWays(this).filter(function(parent) {\n return (parent.tags.highway ||\n parent.tags.waterway ||\n parent.tags.railway ||\n parent.tags.aeroway) &&\n parent.geometry(resolver) === 'line';\n });\n });\n },\n\n\n isIntersection: function(resolver) {\n return this.parentIntersectionWays(resolver).length > 1;\n },\n\n\n isHighwayIntersection: function(resolver) {\n return resolver.transient(this, 'isHighwayIntersection', function() {\n return resolver.parentWays(this).filter(function(parent) {\n return parent.tags.highway && parent.geometry(resolver) === 'line';\n }).length > 1;\n });\n },\n\n\n isOnAddressLine: function(resolver) {\n return resolver.transient(this, 'isOnAddressLine', function() {\n return resolver.parentWays(this).filter(function(parent) {\n return parent.tags.hasOwnProperty('addr:interpolation') &&\n parent.geometry(resolver) === 'line';\n }).length > 0;\n });\n },\n\n\n asJXON: function(changeset_id) {\n var r = {\n node: {\n '@id': this.osmId(),\n '@lon': this.loc[0],\n '@lat': this.loc[1],\n '@version': (this.version || 0),\n tag: Object.keys(this.tags).map(function(k) {\n return { keyAttributes: { k: k, v: this.tags[k] } };\n }, this)\n }\n };\n if (changeset_id) r.node['@changeset'] = changeset_id;\n return r;\n },\n\n\n asGeoJSON: function() {\n return {\n type: 'Point',\n coordinates: this.loc\n };\n }\n});\n","import { median as d3_median } from 'd3-array';\n\nimport {\n polygonArea as d3_polygonArea,\n polygonHull as d3_polygonHull,\n polygonCentroid as d3_polygonCentroid\n} from 'd3-polygon';\n\nimport { geoVecInterp, geoVecLength } from '../geo';\nimport { osmNode } from '../osm/node';\nimport { utilArrayUniq } from '../util';\nimport { geoVecLengthSquare } from '../geo/vector';\n\n\nexport function actionCircularize(wayId, projection, maxAngle) {\n maxAngle = (maxAngle || 20) * Math.PI / 180;\n\n\n var action = function(graph, t) {\n if (t === null || !isFinite(t)) t = 1;\n t = Math.min(Math.max(+t, 0), 1);\n\n var way = graph.entity(wayId);\n var origNodes = {};\n\n graph.childNodes(way).forEach(function(node) {\n if (!origNodes[node.id]) origNodes[node.id] = node;\n });\n\n if (!way.isConvex(graph)) {\n graph = action.makeConvex(graph);\n }\n\n var nodes = utilArrayUniq(graph.childNodes(way));\n var keyNodes = nodes.filter(function(n) { return graph.parentWays(n).length !== 1; });\n var points = nodes.map(function(n) { return projection(n.loc); });\n var keyPoints = keyNodes.map(function(n) { return projection(n.loc); });\n var centroid = (points.length === 2) ? geoVecInterp(points[0], points[1], 0.5) : d3_polygonCentroid(points);\n var radius = d3_median(points, function(p) { return geoVecLength(centroid, p); });\n var sign = d3_polygonArea(points) > 0 ? 1 : -1;\n var ids, i, j, k;\n\n // we need atleast two key nodes for the algorithm to work\n if (!keyNodes.length) {\n keyNodes = [nodes[0]];\n keyPoints = [points[0]];\n }\n\n if (keyNodes.length === 1) {\n var index = nodes.indexOf(keyNodes[0]);\n var oppositeIndex = Math.floor((index + nodes.length / 2) % nodes.length);\n\n keyNodes.push(nodes[oppositeIndex]);\n keyPoints.push(points[oppositeIndex]);\n }\n\n // key points and nodes are those connected to the ways,\n // they are projected onto the circle, inbetween nodes are moved\n // to constant intervals between key nodes, extra inbetween nodes are\n // added if necessary.\n for (i = 0; i < keyPoints.length; i++) {\n var nextKeyNodeIndex = (i + 1) % keyNodes.length;\n var startNode = keyNodes[i];\n var endNode = keyNodes[nextKeyNodeIndex];\n var startNodeIndex = nodes.indexOf(startNode);\n var endNodeIndex = nodes.indexOf(endNode);\n var numberNewPoints = -1;\n var indexRange = endNodeIndex - startNodeIndex;\n var nearNodes = {};\n var inBetweenNodes = [];\n var startAngle, endAngle, totalAngle, eachAngle;\n var angle, loc, node, origNode;\n\n if (indexRange < 0) {\n indexRange += nodes.length;\n }\n\n // position this key node\n var distance = geoVecLength(centroid, keyPoints[i]) || 1e-4;\n keyPoints[i] = [\n centroid[0] + (keyPoints[i][0] - centroid[0]) / distance * radius,\n centroid[1] + (keyPoints[i][1] - centroid[1]) / distance * radius\n ];\n loc = projection.invert(keyPoints[i]);\n node = keyNodes[i];\n origNode = origNodes[node.id];\n node = node.move(geoVecInterp(origNode.loc, loc, t));\n graph = graph.replace(node);\n\n // figure out the between delta angle we want to match to\n startAngle = Math.atan2(keyPoints[i][1] - centroid[1], keyPoints[i][0] - centroid[0]);\n endAngle = Math.atan2(keyPoints[nextKeyNodeIndex][1] - centroid[1], keyPoints[nextKeyNodeIndex][0] - centroid[0]);\n totalAngle = endAngle - startAngle;\n\n // detects looping around -pi/pi\n if (totalAngle * sign > 0) {\n totalAngle = -sign * (2 * Math.PI - Math.abs(totalAngle));\n }\n\n do {\n numberNewPoints++;\n eachAngle = totalAngle / (indexRange + numberNewPoints);\n } while (Math.abs(eachAngle) > maxAngle);\n\n\n // move existing nodes\n for (j = 1; j < indexRange; j++) {\n angle = startAngle + j * eachAngle;\n loc = projection.invert([\n centroid[0] + Math.cos(angle) * radius,\n centroid[1] + Math.sin(angle) * radius\n ]);\n\n node = nodes[(j + startNodeIndex) % nodes.length];\n origNode = origNodes[node.id];\n nearNodes[node.id] = angle;\n\n node = node.move(geoVecInterp(origNode.loc, loc, t));\n graph = graph.replace(node);\n }\n\n // add new inbetween nodes if necessary\n for (j = 0; j < numberNewPoints; j++) {\n angle = startAngle + (indexRange + j) * eachAngle;\n loc = projection.invert([\n centroid[0] + Math.cos(angle) * radius,\n centroid[1] + Math.sin(angle) * radius\n ]);\n\n // choose a nearnode to use as the original\n var min = Infinity;\n for (var nodeId in nearNodes) {\n var nearAngle = nearNodes[nodeId];\n var dist = Math.abs(nearAngle - angle);\n if (dist < min) {\n dist = min;\n origNode = origNodes[nodeId];\n }\n }\n\n node = osmNode({ loc: geoVecInterp(origNode.loc, loc, t) });\n graph = graph.replace(node);\n\n nodes.splice(endNodeIndex + j, 0, node);\n inBetweenNodes.push(node.id);\n }\n\n // Check for other ways that share these keyNodes..\n // If keyNodes are adjacent in both ways,\n // we can add inBetween nodes to that shared way too..\n if (indexRange === 1 && inBetweenNodes.length) {\n var startIndex1 = way.nodes.lastIndexOf(startNode.id);\n var endIndex1 = way.nodes.lastIndexOf(endNode.id);\n var wayDirection1 = (endIndex1 - startIndex1);\n if (wayDirection1 < -1) { wayDirection1 = 1; }\n\n var parentWays = graph.parentWays(keyNodes[i]);\n for (j = 0; j < parentWays.length; j++) {\n var sharedWay = parentWays[j];\n if (sharedWay === way) continue;\n\n if (sharedWay.areAdjacent(startNode.id, endNode.id)) {\n var startIndex2 = sharedWay.nodes.lastIndexOf(startNode.id);\n var endIndex2 = sharedWay.nodes.lastIndexOf(endNode.id);\n var wayDirection2 = (endIndex2 - startIndex2);\n var insertAt = endIndex2;\n if (wayDirection2 < -1) { wayDirection2 = 1; }\n\n if (wayDirection1 !== wayDirection2) {\n inBetweenNodes.reverse();\n insertAt = startIndex2;\n }\n for (k = 0; k < inBetweenNodes.length; k++) {\n sharedWay = sharedWay.addNode(inBetweenNodes[k], insertAt + k);\n }\n graph = graph.replace(sharedWay);\n }\n }\n }\n\n }\n\n // update the way to have all the new nodes\n ids = nodes.map(function(n) { return n.id; });\n ids.push(ids[0]);\n\n way = way.update({nodes: ids});\n graph = graph.replace(way);\n\n return graph;\n };\n\n\n action.makeConvex = function(graph) {\n var way = graph.entity(wayId);\n var nodes = utilArrayUniq(graph.childNodes(way));\n var points = nodes.map(function(n) { return projection(n.loc); });\n var sign = d3_polygonArea(points) > 0 ? 1 : -1;\n var hull = d3_polygonHull(points);\n var i, j;\n\n // D3 convex hulls go counterclockwise..\n if (sign === -1) {\n nodes.reverse();\n points.reverse();\n }\n\n for (i = 0; i < hull.length - 1; i++) {\n var startIndex = points.indexOf(hull[i]);\n var endIndex = points.indexOf(hull[i+1]);\n var indexRange = (endIndex - startIndex);\n\n if (indexRange < 0) {\n indexRange += nodes.length;\n }\n\n // move interior nodes to the surface of the convex hull..\n for (j = 1; j < indexRange; j++) {\n var point = geoVecInterp(hull[i], hull[i+1], j / indexRange);\n var node = nodes[(j + startIndex) % nodes.length].move(projection.invert(point));\n graph = graph.replace(node);\n }\n }\n return graph;\n };\n\n\n action.disabled = function(graph) {\n if (!graph.entity(wayId).isClosed()) {\n return 'not_closed';\n }\n\n //disable when already circular\n var way = graph.entity(wayId);\n var nodes = utilArrayUniq(graph.childNodes(way));\n var points = nodes.map(function(n) { return projection(n.loc); });\n var hull = d3_polygonHull(points);\n var epsilonAngle = Math.PI / 180;\n if (hull.length !== points.length || hull.length < 3){\n return false;\n }\n var centroid = d3_polygonCentroid(points);\n var radius = geoVecLengthSquare(centroid, points[0]);\n\n // compare distances between centroid and points\n for (var i = 0; i 0.05*radius) {\n return false;\n }\n }\n \n //check if central angles are smaller than maxAngle\n for (i = 0; i Math.PI){\n angle = (2*Math.PI - angle);\n }\n \n if (angle > maxAngle + epsilonAngle) {\n return false;\n }\n }\n return 'already_circular';\n };\n\n\n action.transitionable = true;\n\n\n return action;\n}\n","import { osmNodeGeometriesForTags } from '../osm/tags';\nimport { actionDeleteRelation } from './delete_relation';\n\n\n// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteWayAction.as\nexport function actionDeleteWay(wayID) {\n\n function canDeleteNode(node, graph) {\n // don't delete nodes still attached to ways or relations\n if (graph.parentWays(node).length ||\n graph.parentRelations(node).length) return false;\n\n var geometries = osmNodeGeometriesForTags(node.tags);\n // don't delete if this node can be a standalone point\n if (geometries.point) return false;\n // delete if this node only be a vertex\n if (geometries.vertex) return true;\n\n // iD doesn't know if this should be a point or vertex,\n // so only delete if there are no interesting tags\n return !node.hasInterestingTags();\n }\n\n\n var action = function(graph) {\n var way = graph.entity(wayID);\n\n graph.parentRelations(way).forEach(function(parent) {\n parent = parent.removeMembersWithID(wayID);\n graph = graph.replace(parent);\n\n if (parent.isDegenerate()) {\n graph = actionDeleteRelation(parent.id)(graph);\n }\n });\n\n (new Set(way.nodes)).forEach(function(nodeID) {\n graph = graph.replace(way.removeNode(nodeID));\n\n var node = graph.entity(nodeID);\n if (canDeleteNode(node, graph)) {\n graph = graph.remove(node);\n }\n });\n\n return graph.remove(way);\n };\n\n\n return action;\n}\n","import { actionDeleteNode } from './delete_node';\nimport { actionDeleteRelation } from './delete_relation';\nimport { actionDeleteWay } from './delete_way';\n\n\nexport function actionDeleteMultiple(ids) {\n var actions = {\n way: actionDeleteWay,\n node: actionDeleteNode,\n relation: actionDeleteRelation\n };\n\n\n var action = function(graph) {\n ids.forEach(function(id) {\n if (graph.hasEntity(id)) { // It may have been deleted aready.\n graph = actions[graph.entity(id).type](id)(graph);\n }\n });\n\n return graph;\n };\n\n\n return action;\n}\n","import { actionDeleteMultiple } from './delete_multiple';\nimport { utilArrayUniq } from '../util';\n\n\n// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteRelationAction.as\nexport function actionDeleteRelation(relationID, allowUntaggedMembers) {\n\n function canDeleteEntity(entity, graph) {\n return !graph.parentWays(entity).length &&\n !graph.parentRelations(entity).length &&\n (!entity.hasInterestingTags() && !allowUntaggedMembers);\n }\n\n\n var action = function(graph) {\n var relation = graph.entity(relationID);\n\n graph.parentRelations(relation)\n .forEach(function(parent) {\n parent = parent.removeMembersWithID(relationID);\n graph = graph.replace(parent);\n\n if (parent.isDegenerate()) {\n graph = actionDeleteRelation(parent.id)(graph);\n }\n });\n\n var memberIDs = utilArrayUniq(relation.members.map(function(m) { return m.id; }));\n memberIDs.forEach(function(memberID) {\n graph = graph.replace(relation.removeMembersWithID(memberID));\n\n var entity = graph.entity(memberID);\n if (canDeleteEntity(entity, graph)) {\n graph = actionDeleteMultiple([memberID])(graph);\n }\n });\n\n return graph.remove(relation);\n };\n\n\n return action;\n}\n","import { actionDeleteRelation } from './delete_relation';\nimport { actionDeleteWay } from './delete_way';\n\n\n// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteNodeAction.as\nexport function actionDeleteNode(nodeId) {\n var action = function(graph) {\n var node = graph.entity(nodeId);\n\n graph.parentWays(node)\n .forEach(function(parent) {\n parent = parent.removeNode(nodeId);\n graph = graph.replace(parent);\n\n if (parent.isDegenerate()) {\n graph = actionDeleteWay(parent.id)(graph);\n }\n });\n\n graph.parentRelations(node)\n .forEach(function(parent) {\n parent = parent.removeMembersWithID(nodeId);\n graph = graph.replace(parent);\n\n if (parent.isDegenerate()) {\n graph = actionDeleteRelation(parent.id)(graph);\n }\n });\n\n return graph.remove(node);\n };\n\n\n return action;\n}\n","import { actionDeleteNode } from './delete_node';\nimport { actionDeleteWay } from './delete_way';\nimport { utilArrayUniq } from '../util';\n\n\n// Connect the ways at the given nodes.\n//\n// First choose a node to be the survivor, with preference given\n// to an existing (not new) node.\n//\n// Tags and relation memberships of of non-surviving nodes are merged\n// to the survivor.\n//\n// This is the inverse of `iD.actionDisconnect`.\n//\n// Reference:\n// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/MergeNodesAction.as\n// https://github.com/openstreetmap/josm/blob/mirror/src/org/openstreetmap/josm/actions/MergeNodesAction.java\n//\nexport function actionConnect(nodeIDs) {\n var action = function(graph) {\n var survivor;\n var node;\n var parents;\n var i, j;\n\n // Choose a survivor node, prefer an existing (not new) node - #4974\n for (i = 0; i < nodeIDs.length; i++) {\n survivor = graph.entity(nodeIDs[i]);\n if (survivor.version) break; // found one\n }\n\n // Replace all non-surviving nodes with the survivor and merge tags.\n for (i = 0; i < nodeIDs.length; i++) {\n node = graph.entity(nodeIDs[i]);\n if (node.id === survivor.id) continue;\n\n parents = graph.parentWays(node);\n for (j = 0; j < parents.length; j++) {\n graph = graph.replace(parents[j].replaceNode(node.id, survivor.id));\n }\n\n parents = graph.parentRelations(node);\n for (j = 0; j < parents.length; j++) {\n graph = graph.replace(parents[j].replaceMember(node, survivor));\n }\n\n survivor = survivor.mergeTags(node.tags);\n graph = actionDeleteNode(node.id)(graph);\n }\n\n graph = graph.replace(survivor);\n\n // find and delete any degenerate ways created by connecting adjacent vertices\n parents = graph.parentWays(survivor);\n for (i = 0; i < parents.length; i++) {\n if (parents[i].isDegenerate()) {\n graph = actionDeleteWay(parents[i].id)(graph);\n }\n }\n\n return graph;\n };\n\n\n action.disabled = function(graph) {\n var seen = {};\n var restrictionIDs = [];\n var survivor;\n var node, way;\n var relations, relation, role;\n var i, j, k;\n\n // Choose a survivor node, prefer an existing (not new) node - #4974\n for (i = 0; i < nodeIDs.length; i++) {\n survivor = graph.entity(nodeIDs[i]);\n if (survivor.version) break; // found one\n }\n\n // 1. disable if the nodes being connected have conflicting relation roles\n for (i = 0; i < nodeIDs.length; i++) {\n node = graph.entity(nodeIDs[i]);\n relations = graph.parentRelations(node);\n\n for (j = 0; j < relations.length; j++) {\n relation = relations[j];\n role = relation.memberById(node.id).role || '';\n\n // if this node is a via node in a restriction, remember for later\n if (relation.hasFromViaTo()) {\n restrictionIDs.push(relation.id);\n }\n\n if (seen[relation.id] !== undefined && seen[relation.id] !== role) {\n return 'relation';\n } else {\n seen[relation.id] = role;\n }\n }\n }\n\n // gather restrictions for parent ways\n for (i = 0; i < nodeIDs.length; i++) {\n node = graph.entity(nodeIDs[i]);\n\n var parents = graph.parentWays(node);\n for (j = 0; j < parents.length; j++) {\n var parent = parents[j];\n relations = graph.parentRelations(parent);\n\n for (k = 0; k < relations.length; k++) {\n relation = relations[k];\n if (relation.hasFromViaTo()) {\n restrictionIDs.push(relation.id);\n }\n }\n }\n }\n\n\n // test restrictions\n restrictionIDs = utilArrayUniq(restrictionIDs);\n for (i = 0; i < restrictionIDs.length; i++) {\n relation = graph.entity(restrictionIDs[i]);\n if (!relation.isComplete(graph)) continue;\n\n var memberWays = relation.members\n .filter(function(m) { return m.type === 'way'; })\n .map(function(m) { return graph.entity(m.id); });\n\n memberWays = utilArrayUniq(memberWays);\n var f = relation.memberByRole('from');\n var t = relation.memberByRole('to');\n var isUturn = (f.id === t.id);\n\n // 2a. disable if connection would damage a restriction\n // (a key node is a node at the junction of ways)\n var nodes = { from: [], via: [], to: [], keyfrom: [], keyto: [] };\n for (j = 0; j < relation.members.length; j++) {\n collectNodes(relation.members[j], nodes);\n }\n\n nodes.keyfrom = utilArrayUniq(nodes.keyfrom.filter(hasDuplicates));\n nodes.keyto = utilArrayUniq(nodes.keyto.filter(hasDuplicates));\n\n var filter = keyNodeFilter(nodes.keyfrom, nodes.keyto);\n nodes.from = nodes.from.filter(filter);\n nodes.via = nodes.via.filter(filter);\n nodes.to = nodes.to.filter(filter);\n\n var connectFrom = false;\n var connectVia = false;\n var connectTo = false;\n var connectKeyFrom = false;\n var connectKeyTo = false;\n\n for (j = 0; j < nodeIDs.length; j++) {\n var n = nodeIDs[j];\n if (nodes.from.indexOf(n) !== -1) { connectFrom = true; }\n if (nodes.via.indexOf(n) !== -1) { connectVia = true; }\n if (nodes.to.indexOf(n) !== -1) { connectTo = true; }\n if (nodes.keyfrom.indexOf(n) !== -1) { connectKeyFrom = true; }\n if (nodes.keyto.indexOf(n) !== -1) { connectKeyTo = true; }\n }\n if (connectFrom && connectTo && !isUturn) { return 'restriction'; }\n if (connectFrom && connectVia) { return 'restriction'; }\n if (connectTo && connectVia) { return 'restriction'; }\n\n // connecting to a key node -\n // if both nodes are on a member way (i.e. part of the turn restriction),\n // the connecting node must be adjacent to the key node.\n if (connectKeyFrom || connectKeyTo) {\n if (nodeIDs.length !== 2) { return 'restriction'; }\n\n var n0 = null;\n var n1 = null;\n for (j = 0; j < memberWays.length; j++) {\n way = memberWays[j];\n if (way.contains(nodeIDs[0])) { n0 = nodeIDs[0]; }\n if (way.contains(nodeIDs[1])) { n1 = nodeIDs[1]; }\n }\n\n if (n0 && n1) { // both nodes are part of the restriction\n var ok = false;\n for (j = 0; j < memberWays.length; j++) {\n way = memberWays[j];\n if (way.areAdjacent(n0, n1)) {\n ok = true;\n break;\n }\n }\n if (!ok) {\n return 'restriction';\n }\n }\n }\n\n // 2b. disable if nodes being connected will destroy a member way in a restriction\n // (to test, make a copy and try actually connecting the nodes)\n for (j = 0; j < memberWays.length; j++) {\n way = memberWays[j].update({}); // make copy\n for (k = 0; k < nodeIDs.length; k++) {\n if (nodeIDs[k] === survivor.id) continue;\n\n if (way.areAdjacent(nodeIDs[k], survivor.id)) {\n way = way.removeNode(nodeIDs[k]);\n } else {\n way = way.replaceNode(nodeIDs[k], survivor.id);\n }\n }\n if (way.isDegenerate()) {\n return 'restriction';\n }\n }\n }\n\n return false;\n\n\n // if a key node appears multiple times (indexOf !== lastIndexOf) it's a FROM-VIA or TO-VIA junction\n function hasDuplicates(n, i, arr) {\n return arr.indexOf(n) !== arr.lastIndexOf(n);\n }\n\n function keyNodeFilter(froms, tos) {\n return function(n) {\n return froms.indexOf(n) === -1 && tos.indexOf(n) === -1;\n };\n }\n\n function collectNodes(member, collection) {\n var entity = graph.hasEntity(member.id);\n if (!entity) return;\n\n var role = member.role || '';\n if (!collection[role]) {\n collection[role] = [];\n }\n\n if (member.type === 'node') {\n collection[role].push(member.id);\n if (role === 'via') {\n collection.keyfrom.push(member.id);\n collection.keyto.push(member.id);\n }\n\n } else if (member.type === 'way') {\n collection[role].push.apply(collection[role], entity.nodes);\n if (role === 'from' || role === 'via') {\n collection.keyfrom.push(entity.first());\n collection.keyfrom.push(entity.last());\n }\n if (role === 'to' || role === 'via') {\n collection.keyto.push(entity.first());\n collection.keyto.push(entity.last());\n }\n }\n }\n };\n\n\n return action;\n}\n","export function actionCopyEntities(ids, fromGraph) {\n var _copies = {};\n\n\n var action = function(graph) {\n ids.forEach(function(id) {\n fromGraph.entity(id).copy(fromGraph, _copies);\n });\n\n for (var id in _copies) {\n graph = graph.replace(_copies[id]);\n }\n\n return graph;\n };\n\n\n action.copies = function() {\n return _copies;\n };\n\n\n return action;\n}\n","import { actionDeleteRelation } from './delete_relation';\n\n\nexport function actionDeleteMember(relationId, memberIndex) {\n return function(graph) {\n var relation = graph.entity(relationId)\n .removeMember(memberIndex);\n\n graph = graph.replace(relation);\n\n if (relation.isDegenerate())\n graph = actionDeleteRelation(relation.id)(graph);\n\n return graph;\n };\n}\n","\nexport function actionDiscardTags(difference, discardTags) {\n discardTags = discardTags || {};\n\n return (graph) => {\n difference.modified().forEach(checkTags);\n difference.created().forEach(checkTags);\n return graph;\n\n function checkTags(entity) {\n const keys = Object.keys(entity.tags);\n let didDiscard = false;\n let tags = {};\n\n for (let i = 0; i < keys.length; i++) {\n const k = keys[i];\n if (discardTags[k] || !entity.tags[k]) {\n didDiscard = true;\n } else {\n tags[k] = entity.tags[k];\n }\n }\n if (didDiscard) {\n graph = graph.replace(entity.update({ tags: tags }));\n }\n }\n\n };\n}\n","import { osmNode } from '../osm/node';\n\n\n// Disconect the ways at the given node.\n//\n// Optionally, disconnect only the given ways.\n//\n// For testing convenience, accepts an ID to assign to the (first) new node.\n// Normally, this will be undefined and the way will automatically\n// be assigned a new ID.\n//\n// This is the inverse of `iD.actionConnect`.\n//\n// Reference:\n// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/UnjoinNodeAction.as\n// https://github.com/openstreetmap/josm/blob/mirror/src/org/openstreetmap/josm/actions/UnGlueAction.java\n//\nexport function actionDisconnect(nodeId, newNodeId) {\n var wayIds;\n\n\n var action = function(graph) {\n var node = graph.entity(nodeId);\n var connections = action.connections(graph);\n\n connections.forEach(function(connection) {\n var way = graph.entity(connection.wayID);\n var newNode = osmNode({id: newNodeId, loc: node.loc, tags: node.tags});\n\n graph = graph.replace(newNode);\n if (connection.index === 0 && way.isArea()) {\n // replace shared node with shared node..\n graph = graph.replace(way.replaceNode(way.nodes[0], newNode.id));\n } else if (way.isClosed() && connection.index === way.nodes.length - 1) {\n // replace closing node with new new node..\n graph = graph.replace(way.unclose().addNode(newNode.id));\n } else {\n // replace shared node with multiple new nodes..\n graph = graph.replace(way.updateNode(newNode.id, connection.index));\n }\n });\n\n return graph;\n };\n\n\n action.connections = function(graph) {\n var candidates = [];\n var keeping = false;\n var parentWays = graph.parentWays(graph.entity(nodeId));\n var way, waynode;\n for (var i = 0; i < parentWays.length; i++) {\n way = parentWays[i];\n if (wayIds && wayIds.indexOf(way.id) === -1) {\n keeping = true;\n continue;\n }\n if (way.isArea() && (way.nodes[0] === nodeId)) {\n candidates.push({ wayID: way.id, index: 0 });\n } else {\n for (var j = 0; j < way.nodes.length; j++) {\n waynode = way.nodes[j];\n if (waynode === nodeId) {\n if (way.isClosed() &&\n parentWays.length > 1 &&\n wayIds &&\n wayIds.indexOf(way.id) !== -1 &&\n j === way.nodes.length - 1) {\n continue;\n }\n candidates.push({ wayID: way.id, index: j });\n }\n }\n }\n }\n\n if (keeping) {\n return candidates;\n } else {\n // if nodeId is positive, make sure a positive way retains it\n if (nodeId[1] !== '-' && candidates.length > 1 &&\n candidates[0].wayID[1] === '-') {\n for (var pos = 1; pos < candidates.length; pos++) {\n if (candidates[pos].wayID[1] !== '-') {\n candidates.splice(pos, 1);\n return candidates;\n }\n }\n }\n return candidates.slice(1);\n }\n };\n\n\n action.disabled = function(graph) {\n var connections = action.connections(graph);\n if (connections.length === 0)\n return 'not_connected';\n\n var parentWays = graph.parentWays(graph.entity(nodeId));\n var seenRelationIds = {};\n var sharedRelation;\n\n parentWays.forEach(function(way) {\n var relations = graph.parentRelations(way);\n relations.forEach(function(relation) {\n if (relation.id in seenRelationIds) {\n if (wayIds) {\n if (wayIds.indexOf(way.id) !== -1 ||\n wayIds.indexOf(seenRelationIds[relation.id]) !== -1) {\n sharedRelation = relation;\n }\n } else {\n sharedRelation = relation;\n }\n } else {\n seenRelationIds[relation.id] = way.id;\n }\n });\n });\n\n if (sharedRelation)\n return 'relation';\n };\n\n\n action.limitWays = function(val) {\n if (!arguments.length) return wayIds;\n wayIds = val;\n return action;\n };\n\n\n return action;\n}\n","\nimport { geoCentroid as d3_geoCentroid } from 'd3-geo';\nimport { osmNode } from '../osm/node';\n\nexport function actionExtract(entityID) {\n\n var extractedNodeID;\n\n var action = function(graph) {\n var entity = graph.entity(entityID);\n\n if (entity.type === 'node') {\n return extractFromNode(entity, graph);\n }\n\n return extractFromWayOrRelation(entity, graph);\n };\n\n function extractFromNode(node, graph) {\n\n extractedNodeID = node.id;\n\n // Create a new node to replace the one we will detach\n var replacement = osmNode({ loc: node.loc });\n graph = graph.replace(replacement);\n\n // Process each way in turn, updating the graph as we go\n graph = graph.parentWays(node)\n .reduce(function(accGraph, parentWay) {\n return accGraph.replace(parentWay.replaceNode(entityID, replacement.id));\n }, graph);\n\n // Process any relations too\n return graph.parentRelations(node)\n .reduce(function(accGraph, parentRel) {\n return accGraph.replace(parentRel.replaceMember(node, replacement));\n }, graph);\n }\n\n function extractFromWayOrRelation(entity, graph) {\n\n var fromGeometry = entity.geometry(graph);\n\n var keysToCopyAndRetain = ['source', 'wheelchair'];\n var keysToRetain = ['area'];\n var buildingKeysToRetain = ['architect', 'building', 'height', 'layer'];\n\n var extractedLoc = d3_geoCentroid(entity.asGeoJSON(graph));\n if (!extractedLoc || !isFinite(extractedLoc[0]) || !isFinite(extractedLoc[1])) {\n extractedLoc = entity.extent(graph).center();\n }\n\n var isBuilding = entity.tags.building && entity.tags.building !== 'no';\n\n var entityTags = Object.assign({}, entity.tags); // shallow copy\n var pointTags = {};\n for (var key in entityTags) {\n\n if (entity.type === 'relation' &&\n key === 'type') {\n continue;\n }\n\n if (keysToRetain.indexOf(key) !== -1) {\n continue;\n }\n\n if (isBuilding) {\n // don't transfer building-related tags\n if (buildingKeysToRetain.indexOf(key) !== -1 ||\n key.match(/^building:.{1,}/) ||\n key.match(/^roof:.{1,}/)) continue;\n }\n\n // copy the tag from the entity to the point\n pointTags[key] = entityTags[key];\n\n // leave addresses and some other tags so they're on both features\n if (keysToCopyAndRetain.indexOf(key) !== -1 ||\n key.match(/^addr:.{1,}/)) {\n continue;\n }\n\n // remove the tag from the entity\n delete entityTags[key];\n }\n\n if (!isBuilding && fromGeometry === 'area') {\n // ensure that areas keep area geometry\n entityTags.area = 'yes';\n }\n\n var replacement = osmNode({ loc: extractedLoc, tags: pointTags });\n graph = graph.replace(replacement);\n\n extractedNodeID = replacement.id;\n\n return graph.replace(entity.update({tags: entityTags}));\n }\n\n action.getExtractedNodeID = function() {\n return extractedNodeID;\n };\n\n return action;\n}\n","import { actionDeleteRelation } from './delete_relation';\nimport { actionDeleteWay } from './delete_way';\nimport { osmIsInterestingTag } from '../osm/tags';\nimport { osmJoinWays } from '../osm/multipolygon';\nimport { geoPathIntersections } from '../geo';\nimport { utilArrayGroupBy, utilArrayIntersection } from '../util';\n\n// RapiD\nimport { prefs } from '../core/preferences';\n\n\n// Join ways at the end node they share.\n//\n// This is the inverse of `iD.actionSplit`.\n//\n// Reference:\n// https://github.com/systemed/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/MergeWaysAction.as\n// https://github.com/openstreetmap/josm/blob/mirror/src/org/openstreetmap/josm/actions/CombineWayAction.java\n//\nexport function actionJoin(ids) {\n\n function groupEntitiesByGeometry(graph) {\n var entities = ids.map(function(id) { return graph.entity(id); });\n return Object.assign(\n { line: [] },\n utilArrayGroupBy(entities, function(entity) { return entity.geometry(graph); })\n );\n }\n\n\n var action = function(graph) {\n var ways = ids.map(graph.entity, graph);\n var survivorID = ways[0].id;\n\n // if any of the ways are sided (e.g. coastline, cliff, kerb)\n // sort them first so they establish the overall order - #6033\n ways.sort(function(a, b) {\n var aSided = a.isSided();\n var bSided = b.isSided();\n return (aSided && !bSided) ? -1\n : (bSided && !aSided) ? 1\n : 0;\n });\n\n // Prefer to keep an existing way.\n for (var i = 0; i < ways.length; i++) {\n if (!ways[i].isNew()) {\n survivorID = ways[i].id;\n break;\n }\n }\n\n var sequences = osmJoinWays(ways, graph);\n var joined = sequences[0];\n\n // We might need to reverse some of these ways before joining them. #4688\n // `joined.actions` property will contain any actions we need to apply.\n graph = sequences.actions.reduce(function(g, action) { return action(g); }, graph);\n\n var survivor = graph.entity(survivorID);\n survivor = survivor.update({ nodes: joined.nodes.map(function(n) { return n.id; }) });\n graph = graph.replace(survivor);\n\n joined.forEach(function(way) {\n if (way.id === survivorID) return;\n\n graph.parentRelations(way).forEach(function(parent) {\n graph = graph.replace(parent.replaceMember(way, survivor));\n });\n\n survivor = survivor.mergeTags(way.tags);\n\n graph = graph.replace(survivor);\n graph = actionDeleteWay(way.id)(graph);\n });\n\n // RapiD tagnosticRoadCombine\n var tagnosticRoadCombine = prefs('rapid-internal-feature.tagnosticRoadCombine') === 'true';\n if (tagnosticRoadCombine && ways.length && ways[0].tags.highway) {\n var newTags = Object.assign({}, survivor.tags);\n newTags.highway = ways[0].tags.highway;\n survivor = survivor.update({ tags: newTags });\n graph = graph.replace(survivor);\n }\n\n // Finds if the join created a single-member multipolygon,\n // and if so turns it into a basic area instead\n function checkForSimpleMultipolygon() {\n if (!survivor.isClosed()) return;\n\n var multipolygons = graph.parentMultipolygons(survivor).filter(function(multipolygon) {\n // find multipolygons where the survivor is the only member\n return multipolygon.members.length === 1;\n });\n\n // skip if this is the single member of multiple multipolygons\n if (multipolygons.length !== 1) return;\n\n var multipolygon = multipolygons[0];\n\n for (var key in survivor.tags) {\n if (multipolygon.tags[key] &&\n // don't collapse if tags cannot be cleanly merged\n multipolygon.tags[key] !== survivor.tags[key]) return;\n }\n\n survivor = survivor.mergeTags(multipolygon.tags);\n graph = graph.replace(survivor);\n graph = actionDeleteRelation(multipolygon.id, true /* allow untagged members */)(graph);\n\n var tags = Object.assign({}, survivor.tags);\n if (survivor.geometry(graph) !== 'area') {\n // ensure the feature persists as an area\n tags.area = 'yes';\n }\n delete tags.type; // remove type=multipolygon\n survivor = survivor.update({ tags: tags });\n graph = graph.replace(survivor);\n }\n checkForSimpleMultipolygon();\n\n return graph;\n };\n\n // Returns the number of nodes the resultant way is expected to have\n action.resultingWayNodesLength = function(graph) {\n return ids.reduce(function(count, id) {\n return count + graph.entity(id).nodes.length;\n }, 0) - ids.length - 1;\n };\n\n\n action.disabled = function(graph) {\n var geometries = groupEntitiesByGeometry(graph);\n if (ids.length < 2 || ids.length !== geometries.line.length) {\n return 'not_eligible';\n }\n\n var joined = osmJoinWays(ids.map(graph.entity, graph), graph);\n if (joined.length > 1) {\n return 'not_adjacent';\n }\n\n // Loop through all combinations of path-pairs\n // to check potential intersections between all pairs\n for (var i = 0; i < ids.length - 1; i++) {\n for (var j = i + 1; j < ids.length; j++) {\n var path1 = graph.childNodes(graph.entity(ids[i]))\n .map(function(e) { return e.loc; });\n var path2 = graph.childNodes(graph.entity(ids[j]))\n .map(function(e) { return e.loc; });\n var intersections = geoPathIntersections(path1, path2);\n\n // Check if intersections are just nodes lying on top of\n // each other/the line, as opposed to crossing it\n var common = utilArrayIntersection(\n joined[0].nodes.map(function(n) { return n.loc.toString(); }),\n intersections.map(function(n) { return n.toString(); })\n );\n if (common.length !== intersections.length) {\n return 'paths_intersect';\n }\n }\n }\n\n var nodeIds = joined[0].nodes.map(function(n) { return n.id; }).slice(1, -1);\n var relation;\n var tags = {};\n var conflicting = false;\n\n joined[0].forEach(function(way) {\n var parents = graph.parentRelations(way);\n parents.forEach(function(parent) {\n if (parent.isRestriction() && parent.members.some(function(m) { return nodeIds.indexOf(m.id) >= 0; })) {\n relation = parent;\n }\n });\n\n for (var k in way.tags) {\n if (!(k in tags)) {\n tags[k] = way.tags[k];\n } else if (tags[k] && osmIsInterestingTag(k) && tags[k] !== way.tags[k]) {\n conflicting = true;\n\n // RapiD tagnosticRoadCombine\n var tagnosticRoadCombine = prefs('rapid-internal-feature.tagnosticRoadCombine') === 'true';\n if (k === 'highway' && tagnosticRoadCombine) {\n conflicting = false;\n }\n }\n }\n });\n\n if (relation) {\n return 'restriction';\n }\n\n if (conflicting) {\n return 'conflicting_tags';\n }\n };\n\n\n return action;\n}\n","import { osmTagSuggestingArea } from '../osm/tags';\nimport { utilArrayGroupBy, utilArrayUniq } from '../util';\n\n\nexport function actionMerge(ids) {\n\n function groupEntitiesByGeometry(graph) {\n var entities = ids.map(function(id) { return graph.entity(id); });\n return Object.assign(\n { point: [], area: [], line: [], relation: [] },\n utilArrayGroupBy(entities, function(entity) { return entity.geometry(graph); })\n );\n }\n\n\n var action = function(graph) {\n var geometries = groupEntitiesByGeometry(graph);\n var target = geometries.area[0] || geometries.line[0];\n var points = geometries.point;\n\n points.forEach(function(point) {\n target = target.mergeTags(point.tags);\n graph = graph.replace(target);\n\n graph.parentRelations(point).forEach(function(parent) {\n graph = graph.replace(parent.replaceMember(point, target));\n });\n\n var nodes = utilArrayUniq(graph.childNodes(target));\n var removeNode = point;\n\n for (var i = 0; i < nodes.length; i++) {\n var node = nodes[i];\n if (graph.parentWays(node).length > 1 ||\n graph.parentRelations(node).length ||\n node.hasInterestingTags()) {\n continue;\n }\n\n // Found an uninteresting child node on the target way.\n // Move orig point into its place to preserve point's history. #3683\n graph = graph.replace(point.update({ tags: {}, loc: node.loc }));\n target = target.replaceNode(node.id, point.id);\n graph = graph.replace(target);\n removeNode = node;\n break;\n }\n\n graph = graph.remove(removeNode);\n });\n\n if (target.tags.area === 'yes') {\n var tags = Object.assign({}, target.tags); // shallow copy\n delete tags.area;\n if (osmTagSuggestingArea(tags)) {\n // remove the `area` tag if area geometry is now implied - #3851\n target = target.update({ tags: tags });\n graph = graph.replace(target);\n }\n }\n\n return graph;\n };\n\n\n action.disabled = function(graph) {\n var geometries = groupEntitiesByGeometry(graph);\n if (geometries.point.length === 0 ||\n (geometries.area.length + geometries.line.length) !== 1 ||\n geometries.relation.length !== 0) {\n return 'not_eligible';\n }\n };\n\n\n return action;\n}\n","import { actionConnect } from './connect';\nimport { geoVecAdd, geoVecScale } from '../geo';\n\n\n// `actionMergeNodes` is just a combination of:\n//\n// 1. move all the nodes to a common location\n// 2. `actionConnect` them\n\nexport function actionMergeNodes(nodeIDs, loc) {\n\n // If there is a single \"interesting\" node, use that as the location.\n // Otherwise return the average location of all the nodes.\n function chooseLoc(graph) {\n if (!nodeIDs.length) return null;\n var sum = [0,0];\n var interestingCount = 0;\n var interestingLoc;\n\n for (var i = 0; i < nodeIDs.length; i++) {\n var node = graph.entity(nodeIDs[i]);\n if (node.hasInterestingTags()) {\n interestingLoc = (++interestingCount === 1) ? node.loc : null;\n }\n sum = geoVecAdd(sum, node.loc);\n }\n\n return interestingLoc || geoVecScale(sum, 1 / nodeIDs.length);\n }\n\n\n var action = function(graph) {\n if (nodeIDs.length < 2) return graph;\n var toLoc = loc;\n if (!toLoc) {\n toLoc = chooseLoc(graph);\n }\n\n for (var i = 0; i < nodeIDs.length; i++) {\n var node = graph.entity(nodeIDs[i]);\n if (node.loc !== toLoc) {\n graph = graph.replace(node.move(toLoc));\n }\n }\n\n return actionConnect(nodeIDs)(graph);\n };\n\n\n action.disabled = function(graph) {\n if (nodeIDs.length < 2) return 'not_eligible';\n\n for (var i = 0; i < nodeIDs.length; i++) {\n var entity = graph.entity(nodeIDs[i]);\n if (entity.type !== 'node') return 'not_eligible';\n }\n\n return actionConnect(nodeIDs).disabled(graph);\n };\n\n return action;\n}\n","import { osmEntity } from './entity';\nimport { geoExtent } from '../geo';\n\n\nexport function osmChangeset() {\n if (!(this instanceof osmChangeset)) {\n return (new osmChangeset()).initialize(arguments);\n } else if (arguments.length) {\n this.initialize(arguments);\n }\n}\n\n\nosmEntity.changeset = osmChangeset;\n\nosmChangeset.prototype = Object.create(osmEntity.prototype);\n\nObject.assign(osmChangeset.prototype, {\n\n type: 'changeset',\n\n\n extent: function() {\n return new geoExtent();\n },\n\n\n geometry: function() {\n return 'changeset';\n },\n\n\n asJXON: function() {\n return {\n osm: {\n changeset: {\n tag: Object.keys(this.tags).map(function(k) {\n return { '@k': k, '@v': this.tags[k] };\n }, this),\n '@version': 0.6,\n '@generator': 'iD'\n }\n }\n };\n },\n\n\n // Generate [osmChange](http://wiki.openstreetmap.org/wiki/OsmChange)\n // XML. Returns a string.\n osmChangeJXON: function(changes) {\n var changeset_id = this.id;\n\n function nest(x, order) {\n var groups = {};\n for (var i = 0; i < x.length; i++) {\n var tagName = Object.keys(x[i])[0];\n if (!groups[tagName]) groups[tagName] = [];\n groups[tagName].push(x[i][tagName]);\n }\n var ordered = {};\n order.forEach(function(o) {\n if (groups[o]) ordered[o] = groups[o];\n });\n return ordered;\n }\n\n\n // sort relations in a changeset by dependencies\n function sort(changes) {\n\n // find a referenced relation in the current changeset\n function resolve(item) {\n return relations.find(function(relation) {\n return item.keyAttributes.type === 'relation'\n && item.keyAttributes.ref === relation['@id'];\n });\n }\n\n // a new item is an item that has not been already processed\n function isNew(item) {\n return !sorted[ item['@id'] ] && !processing.find(function(proc) {\n return proc['@id'] === item['@id'];\n });\n }\n\n var processing = [];\n var sorted = {};\n var relations = changes.relation;\n\n if (!relations) return changes;\n\n for (var i = 0; i < relations.length; i++) {\n var relation = relations[i];\n\n // skip relation if already sorted\n if (!sorted[relation['@id']]) {\n processing.push(relation);\n }\n\n while (processing.length > 0) {\n var next = processing[0],\n deps = next.member.map(resolve).filter(Boolean).filter(isNew);\n if (deps.length === 0) {\n sorted[next['@id']] = next;\n processing.shift();\n } else {\n processing = deps.concat(processing);\n }\n }\n }\n\n changes.relation = Object.values(sorted);\n return changes;\n }\n\n function rep(entity) {\n return entity.asJXON(changeset_id);\n }\n\n return {\n osmChange: {\n '@version': 0.6,\n '@generator': 'iD',\n 'create': sort(nest(changes.created.map(rep), ['node', 'way', 'relation'])),\n 'modify': nest(changes.modified.map(rep), ['node', 'way', 'relation']),\n 'delete': Object.assign(nest(changes.deleted.map(rep), ['relation', 'way', 'node']), { '@if-unused': true })\n }\n };\n },\n\n\n asGeoJSON: function() {\n return {};\n }\n\n});\n","import { geoExtent } from '../geo';\n\n\nexport function osmNote() {\n if (!(this instanceof osmNote)) {\n return (new osmNote()).initialize(arguments);\n } else if (arguments.length) {\n this.initialize(arguments);\n }\n}\n\n\nosmNote.id = function() {\n return osmNote.id.next--;\n};\n\n\nosmNote.id.next = -1;\n\n\nObject.assign(osmNote.prototype, {\n\n type: 'note',\n\n initialize: function(sources) {\n for (var i = 0; i < sources.length; ++i) {\n var source = sources[i];\n for (var prop in source) {\n if (Object.prototype.hasOwnProperty.call(source, prop)) {\n if (source[prop] === undefined) {\n delete this[prop];\n } else {\n this[prop] = source[prop];\n }\n }\n }\n }\n\n if (!this.id) {\n this.id = osmNote.id() + ''; // as string\n }\n\n return this;\n },\n\n extent: function() {\n return new geoExtent(this.loc);\n },\n\n update: function(attrs) {\n return osmNote(this, attrs); // {v: 1 + (this.v || 0)}\n },\n\n isNew: function() {\n return this.id < 0;\n },\n\n move: function(loc) {\n return this.update({ loc: loc });\n }\n\n});\n","import { geoArea as d3_geoArea } from 'd3-geo';\n\nimport { osmEntity } from './entity';\nimport { osmJoinWays } from './multipolygon';\nimport { geoExtent, geoPolygonContainsPolygon, geoPolygonIntersectsPolygon } from '../geo';\n\n\nexport function osmRelation() {\n if (!(this instanceof osmRelation)) {\n return (new osmRelation()).initialize(arguments);\n } else if (arguments.length) {\n this.initialize(arguments);\n }\n}\n\n\nosmEntity.relation = osmRelation;\n\nosmRelation.prototype = Object.create(osmEntity.prototype);\n\n\nosmRelation.creationOrder = function(a, b) {\n var aId = parseInt(osmEntity.id.toOSM(a.id), 10);\n var bId = parseInt(osmEntity.id.toOSM(b.id), 10);\n\n if (aId < 0 || bId < 0) return aId - bId;\n return bId - aId;\n};\n\n\nObject.assign(osmRelation.prototype, {\n type: 'relation',\n members: [],\n\n\n copy: function(resolver, copies) {\n if (copies[this.id]) return copies[this.id];\n\n var copy = osmEntity.prototype.copy.call(this, resolver, copies);\n\n var members = this.members.map(function(member) {\n return Object.assign({}, member, { id: resolver.entity(member.id).copy(resolver, copies).id });\n });\n\n copy = copy.update({members: members});\n copies[this.id] = copy;\n\n return copy;\n },\n\n\n extent: function(resolver, memo) {\n return resolver.transient(this, 'extent', function() {\n if (memo && memo[this.id]) return geoExtent();\n memo = memo || {};\n memo[this.id] = true;\n\n var extent = geoExtent();\n for (var i = 0; i < this.members.length; i++) {\n var member = resolver.hasEntity(this.members[i].id);\n if (member) {\n extent._extend(member.extent(resolver, memo));\n }\n }\n return extent;\n });\n },\n\n\n geometry: function(graph) {\n return graph.transient(this, 'geometry', function() {\n return this.isMultipolygon() ? 'area' : 'relation';\n });\n },\n\n\n isDegenerate: function() {\n return this.members.length === 0;\n },\n\n\n // Return an array of members, each extended with an 'index' property whose value\n // is the member index.\n indexedMembers: function() {\n var result = new Array(this.members.length);\n for (var i = 0; i < this.members.length; i++) {\n result[i] = Object.assign({}, this.members[i], {index: i});\n }\n return result;\n },\n\n\n // Return the first member with the given role. A copy of the member object\n // is returned, extended with an 'index' property whose value is the member index.\n memberByRole: function(role) {\n for (var i = 0; i < this.members.length; i++) {\n if (this.members[i].role === role) {\n return Object.assign({}, this.members[i], {index: i});\n }\n }\n },\n\n // Same as memberByRole, but returns all members with the given role\n membersByRole: function(role) {\n var result = [];\n for (var i = 0; i < this.members.length; i++) {\n if (this.members[i].role === role) {\n result.push(Object.assign({}, this.members[i], {index: i}));\n }\n }\n return result;\n },\n\n // Return the first member with the given id. A copy of the member object\n // is returned, extended with an 'index' property whose value is the member index.\n memberById: function(id) {\n for (var i = 0; i < this.members.length; i++) {\n if (this.members[i].id === id) {\n return Object.assign({}, this.members[i], {index: i});\n }\n }\n },\n\n\n // Return the first member with the given id and role. A copy of the member object\n // is returned, extended with an 'index' property whose value is the member index.\n memberByIdAndRole: function(id, role) {\n for (var i = 0; i < this.members.length; i++) {\n if (this.members[i].id === id && this.members[i].role === role) {\n return Object.assign({}, this.members[i], {index: i});\n }\n }\n },\n\n\n addMember: function(member, index) {\n var members = this.members.slice();\n members.splice(index === undefined ? members.length : index, 0, member);\n return this.update({members: members});\n },\n\n\n updateMember: function(member, index) {\n var members = this.members.slice();\n members.splice(index, 1, Object.assign({}, members[index], member));\n return this.update({members: members});\n },\n\n\n removeMember: function(index) {\n var members = this.members.slice();\n members.splice(index, 1);\n return this.update({members: members});\n },\n\n\n removeMembersWithID: function(id) {\n var members = this.members.filter(function(m) { return m.id !== id; });\n return this.update({members: members});\n },\n\n moveMember: function(fromIndex, toIndex) {\n var members = this.members.slice();\n members.splice(toIndex, 0, members.splice(fromIndex, 1)[0]);\n return this.update({members: members});\n },\n\n\n // Wherever a member appears with id `needle.id`, replace it with a member\n // with id `replacement.id`, type `replacement.type`, and the original role,\n // By default, adding a duplicate member (by id and role) is prevented.\n // Return an updated relation.\n replaceMember: function(needle, replacement, keepDuplicates) {\n if (!this.memberById(needle.id)) return this;\n\n var members = [];\n\n for (var i = 0; i < this.members.length; i++) {\n var member = this.members[i];\n if (member.id !== needle.id) {\n members.push(member);\n } else if (keepDuplicates || !this.memberByIdAndRole(replacement.id, member.role)) {\n members.push({ id: replacement.id, type: replacement.type, role: member.role });\n }\n }\n\n return this.update({ members: members });\n },\n\n\n asJXON: function(changeset_id) {\n var r = {\n relation: {\n '@id': this.osmId(),\n '@version': this.version || 0,\n member: this.members.map(function(member) {\n return {\n keyAttributes: {\n type: member.type,\n role: member.role,\n ref: osmEntity.id.toOSM(member.id)\n }\n };\n }, this),\n tag: Object.keys(this.tags).map(function(k) {\n return { keyAttributes: { k: k, v: this.tags[k] } };\n }, this)\n }\n };\n if (changeset_id) {\n r.relation['@changeset'] = changeset_id;\n }\n return r;\n },\n\n\n asGeoJSON: function(resolver) {\n return resolver.transient(this, 'GeoJSON', function () {\n if (this.isMultipolygon()) {\n return {\n type: 'MultiPolygon',\n coordinates: this.multipolygon(resolver)\n };\n } else {\n return {\n type: 'FeatureCollection',\n properties: this.tags,\n features: this.members.map(function (member) {\n return Object.assign({role: member.role}, resolver.entity(member.id).asGeoJSON(resolver));\n })\n };\n }\n });\n },\n\n\n area: function(resolver) {\n return resolver.transient(this, 'area', function() {\n return d3_geoArea(this.asGeoJSON(resolver));\n });\n },\n\n\n isMultipolygon: function() {\n return this.tags.type === 'multipolygon';\n },\n\n\n isComplete: function(resolver) {\n for (var i = 0; i < this.members.length; i++) {\n if (!resolver.hasEntity(this.members[i].id)) {\n return false;\n }\n }\n return true;\n },\n\n\n hasFromViaTo: function() {\n return (\n this.members.some(function(m) { return m.role === 'from'; }) &&\n this.members.some(function(m) { return m.role === 'via'; }) &&\n this.members.some(function(m) { return m.role === 'to'; })\n );\n },\n\n\n isRestriction: function() {\n return !!(this.tags.type && this.tags.type.match(/^restriction:?/));\n },\n\n\n isValidRestriction: function() {\n if (!this.isRestriction()) return false;\n\n var froms = this.members.filter(function(m) { return m.role === 'from'; });\n var vias = this.members.filter(function(m) { return m.role === 'via'; });\n var tos = this.members.filter(function(m) { return m.role === 'to'; });\n\n if (froms.length !== 1 && this.tags.restriction !== 'no_entry') return false;\n if (froms.some(function(m) { return m.type !== 'way'; })) return false;\n\n if (tos.length !== 1 && this.tags.restriction !== 'no_exit') return false;\n if (tos.some(function(m) { return m.type !== 'way'; })) return false;\n\n if (vias.length === 0) return false;\n if (vias.length > 1 && vias.some(function(m) { return m.type !== 'way'; })) return false;\n\n return true;\n },\n\n\n // Returns an array [A0, ... An], each Ai being an array of node arrays [Nds0, ... Ndsm],\n // where Nds0 is an outer ring and subsequent Ndsi's (if any i > 0) being inner rings.\n //\n // This corresponds to the structure needed for rendering a multipolygon path using a\n // `evenodd` fill rule, as well as the structure of a GeoJSON MultiPolygon geometry.\n //\n // In the case of invalid geometries, this function will still return a result which\n // includes the nodes of all way members, but some Nds may be unclosed and some inner\n // rings not matched with the intended outer ring.\n //\n multipolygon: function(resolver) {\n var outers = this.members.filter(function(m) { return 'outer' === (m.role || 'outer'); });\n var inners = this.members.filter(function(m) { return 'inner' === m.role; });\n\n outers = osmJoinWays(outers, resolver);\n inners = osmJoinWays(inners, resolver);\n\n var sequenceToLineString = function(sequence) {\n if (sequence.nodes.length > 2 &&\n sequence.nodes[0] !== sequence.nodes[sequence.nodes.length - 1]) {\n // close unclosed parts to ensure correct area rendering - #2945\n sequence.nodes.push(sequence.nodes[0]);\n }\n return sequence.nodes.map(function(node) { return node.loc; });\n };\n\n outers = outers.map(sequenceToLineString);\n inners = inners.map(sequenceToLineString);\n\n var result = outers.map(function(o) {\n // Heuristic for detecting counterclockwise winding order. Assumes\n // that OpenStreetMap polygons are not hemisphere-spanning.\n return [d3_geoArea({ type: 'Polygon', coordinates: [o] }) > 2 * Math.PI ? o.reverse() : o];\n });\n\n function findOuter(inner) {\n var o, outer;\n\n for (o = 0; o < outers.length; o++) {\n outer = outers[o];\n if (geoPolygonContainsPolygon(outer, inner))\n return o;\n }\n\n for (o = 0; o < outers.length; o++) {\n outer = outers[o];\n if (geoPolygonIntersectsPolygon(outer, inner, false))\n return o;\n }\n }\n\n for (var i = 0; i < inners.length; i++) {\n var inner = inners[i];\n\n if (d3_geoArea({ type: 'Polygon', coordinates: [inner] }) < 2 * Math.PI) {\n inner = inner.reverse();\n }\n\n var o = findOuter(inners[i]);\n if (o !== undefined) {\n result[o].push(inners[i]);\n } else {\n result.push([inners[i]]); // Invalid geometry\n }\n }\n\n return result;\n }\n});\n","\nexport class QAItem {\n constructor(loc, service, itemType, id, props) {\n // Store required properties\n this.loc = loc;\n this.service = service.title;\n this.itemType = itemType;\n\n // All issues must have an ID for selection, use generic if none specified\n this.id = id ? id : `${QAItem.id()}`;\n\n this.update(props);\n\n // Some QA services have marker icons to differentiate issues\n if (service && typeof service.getIcon === 'function') {\n this.icon = service.getIcon(itemType);\n }\n\n return this;\n }\n\n update(props) {\n // You can't override this inital information\n const { loc, service, itemType, id } = this;\n\n Object.keys(props).forEach(prop => this[prop] = props[prop]);\n\n this.loc = loc;\n this.service = service;\n this.itemType = itemType;\n this.id = id;\n\n return this;\n }\n\n // Generic handling for newly created QAItems\n static id() {\n return this.nextId--;\n }\n}\nQAItem.nextId = -1;\n","import { actionAddMember } from './add_member';\nimport { geoSphericalDistance } from '../geo';\nimport { osmIsOldMultipolygonOuterMember } from '../osm/multipolygon';\nimport { osmRelation } from '../osm/relation';\nimport { osmWay } from '../osm/way';\nimport { utilArrayIntersection, utilWrap } from '../util';\n\n\n// Split a way at the given node.\n//\n// Optionally, split only the given ways, if multiple ways share\n// the given node.\n//\n// This is the inverse of `iD.actionJoin`.\n//\n// For testing convenience, accepts an ID to assign to the new way.\n// Normally, this will be undefined and the way will automatically\n// be assigned a new ID.\n//\n// Reference:\n// https://github.com/systemed/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/SplitWayAction.as\n//\nexport function actionSplit(nodeId, newWayIds) {\n var _wayIDs;\n\n // The IDs of the ways actually created by running this action\n var createdWayIDs = [];\n\n // If the way is closed, we need to search for a partner node\n // to split the way at.\n //\n // The following looks for a node that is both far away from\n // the initial node in terms of way segment length and nearby\n // in terms of beeline-distance. This assures that areas get\n // split on the most \"natural\" points (independent of the number\n // of nodes).\n // For example: bone-shaped areas get split across their waist\n // line, circles across the diameter.\n function splitArea(nodes, idxA, graph) {\n var lengths = new Array(nodes.length);\n var length;\n var i;\n var best = 0;\n var idxB;\n\n function wrap(index) {\n return utilWrap(index, nodes.length);\n }\n\n function dist(nA, nB) {\n var locA = graph.entity(nA).loc;\n var locB = graph.entity(nB).loc;\n var epsilon = 1e-6;\n return (locA && locB) ? geoSphericalDistance(locA, locB) : epsilon;\n }\n\n // calculate lengths\n length = 0;\n for (i = wrap(idxA + 1); i !== idxA; i = wrap(i + 1)) {\n length += dist(nodes[i], nodes[wrap(i - 1)]);\n lengths[i] = length;\n }\n\n length = 0;\n for (i = wrap(idxA - 1); i !== idxA; i = wrap(i - 1)) {\n length += dist(nodes[i], nodes[wrap(i + 1)]);\n if (length < lengths[i]) {\n lengths[i] = length;\n }\n }\n\n // determine best opposite node to split\n for (i = 0; i < nodes.length; i++) {\n var cost = lengths[i] / dist(nodes[idxA], nodes[i]);\n if (cost > best) {\n idxB = i;\n best = cost;\n }\n }\n\n return idxB;\n }\n\n\n function split(graph, wayA, newWayId) {\n var wayB = osmWay({ id: newWayId, tags: wayA.tags }); // `wayB` is the NEW way\n var origNodes = wayA.nodes.slice();\n var nodesA;\n var nodesB;\n var isArea = wayA.isArea();\n var isOuter = osmIsOldMultipolygonOuterMember(wayA, graph);\n\n if (wayA.isClosed()) {\n var nodes = wayA.nodes.slice(0, -1);\n var idxA = nodes.indexOf(nodeId);\n var idxB = splitArea(nodes, idxA, graph);\n\n if (idxB < idxA) {\n nodesA = nodes.slice(idxA).concat(nodes.slice(0, idxB + 1));\n nodesB = nodes.slice(idxB, idxA + 1);\n } else {\n nodesA = nodes.slice(idxA, idxB + 1);\n nodesB = nodes.slice(idxB).concat(nodes.slice(0, idxA + 1));\n }\n } else {\n var idx = wayA.nodes.indexOf(nodeId, 1);\n nodesA = wayA.nodes.slice(0, idx + 1);\n nodesB = wayA.nodes.slice(idx);\n }\n\n wayA = wayA.update({ nodes: nodesA });\n wayB = wayB.update({ nodes: nodesB });\n\n graph = graph.replace(wayA);\n graph = graph.replace(wayB);\n\n graph.parentRelations(wayA).forEach(function(relation) {\n var member;\n\n // Turn restrictions - make sure:\n // 1. Splitting a FROM/TO way - only `wayA` OR `wayB` remains in relation\n // (whichever one is connected to the VIA node/ways)\n // 2. Splitting a VIA way - `wayB` remains in relation as a VIA way\n if (relation.hasFromViaTo()) {\n var f = relation.memberByRole('from');\n var v = relation.membersByRole('via');\n var t = relation.memberByRole('to');\n var i;\n\n // 1. split a FROM/TO\n if (f.id === wayA.id || t.id === wayA.id) {\n var keepB = false;\n if (v.length === 1 && v[0].type === 'node') { // check via node\n keepB = wayB.contains(v[0].id);\n } else { // check via way(s)\n for (i = 0; i < v.length; i++) {\n if (v[i].type === 'way') {\n var wayVia = graph.hasEntity(v[i].id);\n if (wayVia && utilArrayIntersection(wayB.nodes, wayVia.nodes).length) {\n keepB = true;\n break;\n }\n }\n }\n }\n\n if (keepB) {\n relation = relation.replaceMember(wayA, wayB);\n graph = graph.replace(relation);\n }\n\n // 2. split a VIA\n } else {\n for (i = 0; i < v.length; i++) {\n if (v[i].type === 'way' && v[i].id === wayA.id) {\n member = {\n id: wayB.id,\n type: 'way',\n role: 'via'\n };\n graph = actionAddMember(relation.id, member, v[i].index + 1)(graph);\n break;\n }\n }\n }\n\n // All other relations (Routes, Multipolygons, etc):\n // 1. Both `wayA` and `wayB` remain in the relation\n // 2. But must be inserted as a pair (see `actionAddMember` for details)\n } else {\n if (relation === isOuter) {\n graph = graph.replace(relation.mergeTags(wayA.tags));\n graph = graph.replace(wayA.update({ tags: {} }));\n graph = graph.replace(wayB.update({ tags: {} }));\n }\n\n member = {\n id: wayB.id,\n type: 'way',\n role: relation.memberById(wayA.id).role\n };\n\n var insertPair = {\n originalID: wayA.id,\n insertedID: wayB.id,\n nodes: origNodes\n };\n\n graph = actionAddMember(relation.id, member, undefined, insertPair)(graph);\n }\n });\n\n if (!isOuter && isArea) {\n var multipolygon = osmRelation({\n tags: Object.assign({}, wayA.tags, { type: 'multipolygon' }),\n members: [\n { id: wayA.id, role: 'outer', type: 'way' },\n { id: wayB.id, role: 'outer', type: 'way' }\n ]\n });\n\n graph = graph.replace(multipolygon);\n graph = graph.replace(wayA.update({ tags: {} }));\n graph = graph.replace(wayB.update({ tags: {} }));\n }\n\n createdWayIDs.push(wayB.id);\n\n return graph;\n }\n\n var action = function(graph) {\n var candidates = action.ways(graph);\n createdWayIDs = [];\n for (var i = 0; i < candidates.length; i++) {\n graph = split(graph, candidates[i], newWayIds && newWayIds[i]);\n }\n return graph;\n };\n\n action.getCreatedWayIDs = function() {\n return createdWayIDs;\n };\n\n action.ways = function(graph) {\n var node = graph.entity(nodeId);\n var parents = graph.parentWays(node);\n var hasLines = parents.some(function(parent) {\n return parent.geometry(graph) === 'line';\n });\n\n return parents.filter(function(parent) {\n if (_wayIDs && _wayIDs.indexOf(parent.id) === -1)\n return false;\n\n if (!_wayIDs && hasLines && parent.geometry(graph) !== 'line')\n return false;\n\n if (parent.isClosed()) {\n return true;\n }\n\n for (var i = 1; i < parent.nodes.length - 1; i++) {\n if (parent.nodes[i] === nodeId) {\n return true;\n }\n }\n\n return false;\n });\n };\n\n\n action.disabled = function(graph) {\n var candidates = action.ways(graph);\n if (candidates.length === 0 || (_wayIDs && _wayIDs.length !== candidates.length)) {\n return 'not_eligible';\n }\n };\n\n\n action.limitWays = function(val) {\n if (!arguments.length) return _wayIDs;\n _wayIDs = val;\n return action;\n };\n\n\n return action;\n}\n","import { debug } from '../index';\nimport { utilArrayDifference } from '../util';\n\n\nexport function coreGraph(other, mutable) {\n if (!(this instanceof coreGraph)) return new coreGraph(other, mutable);\n\n if (other instanceof coreGraph) {\n var base = other.base();\n this.entities = Object.assign(Object.create(base.entities), other.entities);\n this._parentWays = Object.assign(Object.create(base.parentWays), other._parentWays);\n this._parentRels = Object.assign(Object.create(base.parentRels), other._parentRels);\n\n } else {\n this.entities = Object.create({});\n this._parentWays = Object.create({});\n this._parentRels = Object.create({});\n this.rebase(other || [], [this]);\n }\n\n this.transients = {};\n this._childNodes = {};\n this.frozen = !mutable;\n}\n\n\ncoreGraph.prototype = {\n\n hasEntity: function(id) {\n return this.entities[id];\n },\n\n\n entity: function(id) {\n var entity = this.entities[id];\n\n //https://github.com/openstreetmap/iD/issues/3973#issuecomment-307052376\n if (!entity) {\n entity = this.entities.__proto__[id]; // eslint-disable-line no-proto\n }\n\n if (!entity) {\n throw new Error('entity ' + id + ' not found');\n }\n return entity;\n },\n\n\n geometry: function(id) {\n return this.entity(id).geometry(this);\n },\n\n\n transient: function(entity, key, fn) {\n var id = entity.id;\n var transients = this.transients[id] || (this.transients[id] = {});\n\n if (transients[key] !== undefined) {\n return transients[key];\n }\n\n transients[key] = fn.call(entity);\n\n return transients[key];\n },\n\n\n parentWays: function(entity) {\n var parents = this._parentWays[entity.id];\n var result = [];\n if (parents) {\n parents.forEach(function(id) {\n result.push(this.entity(id));\n }, this);\n }\n return result;\n },\n\n\n isPoi: function(entity) {\n var parents = this._parentWays[entity.id];\n return !parents || parents.size === 0;\n },\n\n\n isShared: function(entity) {\n var parents = this._parentWays[entity.id];\n return parents && parents.size > 1;\n },\n\n\n parentRelations: function(entity) {\n var parents = this._parentRels[entity.id];\n var result = [];\n if (parents) {\n parents.forEach(function(id) {\n result.push(this.entity(id));\n }, this);\n }\n return result;\n },\n\n parentMultipolygons: function(entity) {\n return this.parentRelations(entity).filter(function(relation) {\n return relation.isMultipolygon();\n });\n },\n\n\n childNodes: function(entity) {\n if (this._childNodes[entity.id]) return this._childNodes[entity.id];\n if (!entity.nodes) return [];\n\n var nodes = [];\n for (var i = 0; i < entity.nodes.length; i++) {\n nodes[i] = this.entity(entity.nodes[i]);\n }\n\n if (debug) Object.freeze(nodes);\n\n this._childNodes[entity.id] = nodes;\n return this._childNodes[entity.id];\n },\n\n\n base: function() {\n return {\n 'entities': Object.getPrototypeOf(this.entities),\n 'parentWays': Object.getPrototypeOf(this._parentWays),\n 'parentRels': Object.getPrototypeOf(this._parentRels)\n };\n },\n\n\n // Unlike other graph methods, rebase mutates in place. This is because it\n // is used only during the history operation that merges newly downloaded\n // data into each state. To external consumers, it should appear as if the\n // graph always contained the newly downloaded data.\n rebase: function(entities, stack, force) {\n var base = this.base();\n var i, j, k, id;\n\n for (i = 0; i < entities.length; i++) {\n var entity = entities[i];\n\n if (!entity.visible || (!force && base.entities[entity.id]))\n continue;\n\n // Merging data into the base graph\n base.entities[entity.id] = entity;\n this._updateCalculated(undefined, entity, base.parentWays, base.parentRels);\n\n // Restore provisionally-deleted nodes that are discovered to have an extant parent\n if (entity.type === 'way') {\n for (j = 0; j < entity.nodes.length; j++) {\n id = entity.nodes[j];\n for (k = 1; k < stack.length; k++) {\n var ents = stack[k].entities;\n if (ents.hasOwnProperty(id) && ents[id] === undefined) {\n delete ents[id];\n }\n }\n }\n }\n }\n\n for (i = 0; i < stack.length; i++) {\n stack[i]._updateRebased();\n }\n },\n\n\n _updateRebased: function() {\n var base = this.base();\n\n Object.keys(this._parentWays).forEach(function(child) {\n if (base.parentWays[child]) {\n base.parentWays[child].forEach(function(id) {\n if (!this.entities.hasOwnProperty(id)) {\n this._parentWays[child].add(id);\n }\n }, this);\n }\n }, this);\n\n Object.keys(this._parentRels).forEach(function(child) {\n if (base.parentRels[child]) {\n base.parentRels[child].forEach(function(id) {\n if (!this.entities.hasOwnProperty(id)) {\n this._parentRels[child].add(id);\n }\n }, this);\n }\n }, this);\n\n this.transients = {};\n\n // this._childNodes is not updated, under the assumption that\n // ways are always downloaded with their child nodes.\n },\n\n\n // Updates calculated properties (parentWays, parentRels) for the specified change\n _updateCalculated: function(oldentity, entity, parentWays, parentRels) {\n parentWays = parentWays || this._parentWays;\n parentRels = parentRels || this._parentRels;\n\n var type = entity && entity.type || oldentity && oldentity.type;\n var removed, added, i;\n\n if (type === 'way') { // Update parentWays\n if (oldentity && entity) {\n removed = utilArrayDifference(oldentity.nodes, entity.nodes);\n added = utilArrayDifference(entity.nodes, oldentity.nodes);\n } else if (oldentity) {\n removed = oldentity.nodes;\n added = [];\n } else if (entity) {\n removed = [];\n added = entity.nodes;\n }\n for (i = 0; i < removed.length; i++) {\n // make a copy of prototype property, store as own property, and update..\n parentWays[removed[i]] = new Set(parentWays[removed[i]]);\n parentWays[removed[i]].delete(oldentity.id);\n }\n for (i = 0; i < added.length; i++) {\n // make a copy of prototype property, store as own property, and update..\n parentWays[added[i]] = new Set(parentWays[added[i]]);\n parentWays[added[i]].add(entity.id);\n }\n\n } else if (type === 'relation') { // Update parentRels\n\n // diff only on the IDs since the same entity can be a member multiple times with different roles\n var oldentityMemberIDs = oldentity ? oldentity.members.map(function(m) { return m.id; }) : [];\n var entityMemberIDs = entity ? entity.members.map(function(m) { return m.id; }) : [];\n\n if (oldentity && entity) {\n removed = utilArrayDifference(oldentityMemberIDs, entityMemberIDs);\n added = utilArrayDifference(entityMemberIDs, oldentityMemberIDs);\n } else if (oldentity) {\n removed = oldentityMemberIDs;\n added = [];\n } else if (entity) {\n removed = [];\n added = entityMemberIDs;\n }\n for (i = 0; i < removed.length; i++) {\n // make a copy of prototype property, store as own property, and update..\n parentRels[removed[i]] = new Set(parentRels[removed[i]]);\n parentRels[removed[i]].delete(oldentity.id);\n }\n for (i = 0; i < added.length; i++) {\n // make a copy of prototype property, store as own property, and update..\n parentRels[added[i]] = new Set(parentRels[added[i]]);\n parentRels[added[i]].add(entity.id);\n }\n }\n },\n\n\n replace: function(entity) {\n if (this.entities[entity.id] === entity) return this;\n\n return this.update(function() {\n this._updateCalculated(this.entities[entity.id], entity);\n this.entities[entity.id] = entity;\n });\n },\n\n\n remove: function(entity) {\n return this.update(function() {\n this._updateCalculated(entity, undefined);\n this.entities[entity.id] = undefined;\n });\n },\n\n\n revert: function(id) {\n var baseEntity = this.base().entities[id];\n var headEntity = this.entities[id];\n if (headEntity === baseEntity) return this;\n\n return this.update(function() {\n this._updateCalculated(headEntity, baseEntity);\n delete this.entities[id];\n });\n },\n\n\n update: function() {\n var graph = this.frozen ? coreGraph(this, true) : this;\n for (var i = 0; i < arguments.length; i++) {\n arguments[i].call(graph, graph);\n }\n\n if (this.frozen) graph.frozen = true;\n\n return graph;\n },\n\n\n // Obliterates any existing entities\n load: function(entities) {\n var base = this.base();\n this.entities = Object.create(base.entities);\n\n for (var i in entities) {\n this.entities[i] = entities[i];\n this._updateCalculated(base.entities[i], this.entities[i]);\n }\n\n return this;\n }\n};\n","import { actionDeleteRelation } from '../actions/delete_relation';\nimport { actionReverse } from '../actions/reverse';\nimport { actionSplit } from '../actions/split';\nimport { coreGraph } from '../core/graph';\nimport { geoAngle, geoSphericalDistance } from '../geo';\nimport { osmEntity } from './entity';\nimport { utilArrayDifference, utilArrayUniq } from '../util';\n\n\nexport function osmTurn(turn) {\n if (!(this instanceof osmTurn)) {\n return new osmTurn(turn);\n }\n Object.assign(this, turn);\n}\n\n\nexport function osmIntersection(graph, startVertexId, maxDistance) {\n maxDistance = maxDistance || 30; // in meters\n var vgraph = coreGraph(); // virtual graph\n var i, j, k;\n\n\n function memberOfRestriction(entity) {\n return graph.parentRelations(entity)\n .some(function(r) { return r.isRestriction(); });\n }\n\n function isRoad(way) {\n if (way.isArea() || way.isDegenerate()) return false;\n var roads = {\n 'motorway': true,\n 'motorway_link': true,\n 'trunk': true,\n 'trunk_link': true,\n 'primary': true,\n 'primary_link': true,\n 'secondary': true,\n 'secondary_link': true,\n 'tertiary': true,\n 'tertiary_link': true,\n 'residential': true,\n 'unclassified': true,\n 'living_street': true,\n 'service': true,\n 'road': true,\n 'track': true\n };\n return roads[way.tags.highway];\n }\n\n\n var startNode = graph.entity(startVertexId);\n var checkVertices = [startNode];\n var checkWays;\n var vertices = [];\n var vertexIds = [];\n var vertex;\n var ways = [];\n var wayIds = [];\n var way;\n var nodes = [];\n var node;\n var parents = [];\n var parent;\n\n // `actions` will store whatever actions must be performed to satisfy\n // preconditions for adding a turn restriction to this intersection.\n // - Remove any existing degenerate turn restrictions (missing from/to, etc)\n // - Reverse oneways so that they are drawn in the forward direction\n // - Split ways on key vertices\n var actions = [];\n\n\n // STEP 1: walk the graph outwards from starting vertex to search\n // for more key vertices and ways to include in the intersection..\n\n while (checkVertices.length) {\n vertex = checkVertices.pop();\n\n // check this vertex for parent ways that are roads\n checkWays = graph.parentWays(vertex);\n var hasWays = false;\n for (i = 0; i < checkWays.length; i++) {\n way = checkWays[i];\n if (!isRoad(way) && !memberOfRestriction(way)) continue;\n\n ways.push(way); // it's a road, or it's already in a turn restriction\n hasWays = true;\n\n // check the way's children for more key vertices\n nodes = utilArrayUniq(graph.childNodes(way));\n for (j = 0; j < nodes.length; j++) {\n node = nodes[j];\n if (node === vertex) continue; // same thing\n if (vertices.indexOf(node) !== -1) continue; // seen it already\n if (geoSphericalDistance(node.loc, startNode.loc) > maxDistance) continue; // too far from start\n\n // a key vertex will have parents that are also roads\n var hasParents = false;\n parents = graph.parentWays(node);\n for (k = 0; k < parents.length; k++) {\n parent = parents[k];\n if (parent === way) continue; // same thing\n if (ways.indexOf(parent) !== -1) continue; // seen it already\n if (!isRoad(parent)) continue; // not a road\n hasParents = true;\n break;\n }\n\n if (hasParents) {\n checkVertices.push(node);\n }\n }\n }\n\n if (hasWays) {\n vertices.push(vertex);\n }\n }\n\n vertices = utilArrayUniq(vertices);\n ways = utilArrayUniq(ways);\n\n\n // STEP 2: Build a virtual graph containing only the entities in the intersection..\n // Everything done after this step should act on the virtual graph\n // Any actions that must be performed later to the main graph go in `actions` array\n ways.forEach(function(way) {\n graph.childNodes(way).forEach(function(node) {\n vgraph = vgraph.replace(node);\n });\n\n vgraph = vgraph.replace(way);\n\n graph.parentRelations(way).forEach(function(relation) {\n if (relation.isRestriction()) {\n if (relation.isValidRestriction(graph)) {\n vgraph = vgraph.replace(relation);\n } else if (relation.isComplete(graph)) {\n actions.push(actionDeleteRelation(relation.id));\n }\n }\n });\n });\n\n\n // STEP 3: Force all oneways to be drawn in the forward direction\n ways.forEach(function(w) {\n var way = vgraph.entity(w.id);\n if (way.tags.oneway === '-1') {\n var action = actionReverse(way.id, { reverseOneway: true });\n actions.push(action);\n vgraph = action(vgraph);\n }\n });\n\n\n // STEP 4: Split ways on key vertices\n var origCount = osmEntity.id.next.way;\n vertices.forEach(function(v) {\n // This is an odd way to do it, but we need to find all the ways that\n // will be split here, then split them one at a time to ensure that these\n // actions can be replayed on the main graph exactly in the same order.\n // (It is unintuitive, but the order of ways returned from graph.parentWays()\n // is arbitrary, depending on how the main graph and vgraph were built)\n var splitAll = actionSplit(v.id);\n if (!splitAll.disabled(vgraph)) {\n splitAll.ways(vgraph).forEach(function(way) {\n var splitOne = actionSplit(v.id).limitWays([way.id]);\n actions.push(splitOne);\n vgraph = splitOne(vgraph);\n });\n }\n });\n\n // In here is where we should also split the intersection at nearby junction.\n // for https://github.com/mapbox/iD-internal/issues/31\n // nearbyVertices.forEach(function(v) {\n // });\n\n // Reasons why we reset the way id count here:\n // 1. Continuity with way ids created by the splits so that we can replay\n // these actions later if the user decides to create a turn restriction\n // 2. Avoids churning way ids just by hovering over a vertex\n // and displaying the turn restriction editor\n osmEntity.id.next.way = origCount;\n\n\n // STEP 5: Update arrays to point to vgraph entities\n vertexIds = vertices.map(function(v) { return v.id; });\n vertices = [];\n ways = [];\n\n vertexIds.forEach(function(id) {\n var vertex = vgraph.entity(id);\n var parents = vgraph.parentWays(vertex);\n vertices.push(vertex);\n ways = ways.concat(parents);\n });\n\n vertices = utilArrayUniq(vertices);\n ways = utilArrayUniq(ways);\n\n vertexIds = vertices.map(function(v) { return v.id; });\n wayIds = ways.map(function(w) { return w.id; });\n\n\n // STEP 6: Update the ways with some metadata that will be useful for\n // walking the intersection graph later and rendering turn arrows.\n\n function withMetadata(way, vertexIds) {\n var __oneWay = way.isOneWay();\n\n // which affixes are key vertices?\n var __first = (vertexIds.indexOf(way.first()) !== -1);\n var __last = (vertexIds.indexOf(way.last()) !== -1);\n\n // what roles is this way eligible for?\n var __via = (__first && __last);\n var __from = ((__first && !__oneWay) || __last);\n var __to = (__first || (__last && !__oneWay));\n\n return way.update({\n __first: __first,\n __last: __last,\n __from: __from,\n __via: __via,\n __to: __to,\n __oneWay: __oneWay\n });\n }\n\n ways = [];\n wayIds.forEach(function(id) {\n var way = withMetadata(vgraph.entity(id), vertexIds);\n vgraph = vgraph.replace(way);\n ways.push(way);\n });\n\n\n // STEP 7: Simplify - This is an iterative process where we:\n // 1. Find trivial vertices with only 2 parents\n // 2. trim off the leaf way from those vertices and remove from vgraph\n\n var keepGoing;\n var removeWayIds = [];\n var removeVertexIds = [];\n\n do {\n keepGoing = false;\n checkVertices = vertexIds.slice();\n\n for (i = 0; i < checkVertices.length; i++) {\n var vertexId = checkVertices[i];\n vertex = vgraph.hasEntity(vertexId);\n\n if (!vertex) {\n if (vertexIds.indexOf(vertexId) !== -1) {\n vertexIds.splice(vertexIds.indexOf(vertexId), 1); // stop checking this one\n }\n removeVertexIds.push(vertexId);\n continue;\n }\n\n parents = vgraph.parentWays(vertex);\n if (parents.length < 3) {\n if (vertexIds.indexOf(vertexId) !== -1) {\n vertexIds.splice(vertexIds.indexOf(vertexId), 1); // stop checking this one\n }\n }\n\n if (parents.length === 2) { // vertex with 2 parents is trivial\n var a = parents[0];\n var b = parents[1];\n var aIsLeaf = a && !a.__via;\n var bIsLeaf = b && !b.__via;\n var leaf, survivor;\n\n if (aIsLeaf && !bIsLeaf) {\n leaf = a;\n survivor = b;\n } else if (!aIsLeaf && bIsLeaf) {\n leaf = b;\n survivor = a;\n }\n\n if (leaf && survivor) {\n survivor = withMetadata(survivor, vertexIds); // update survivor way\n vgraph = vgraph.replace(survivor).remove(leaf); // update graph\n removeWayIds.push(leaf.id);\n keepGoing = true;\n }\n }\n\n parents = vgraph.parentWays(vertex);\n\n if (parents.length < 2) { // vertex is no longer a key vertex\n if (vertexIds.indexOf(vertexId) !== -1) {\n vertexIds.splice(vertexIds.indexOf(vertexId), 1); // stop checking this one\n }\n removeVertexIds.push(vertexId);\n keepGoing = true;\n }\n\n if (parents.length < 1) { // vertex is no longer attached to anything\n vgraph = vgraph.remove(vertex);\n }\n\n }\n } while (keepGoing);\n\n\n vertices = vertices\n .filter(function(vertex) { return removeVertexIds.indexOf(vertex.id) === -1; })\n .map(function(vertex) { return vgraph.entity(vertex.id); });\n ways = ways\n .filter(function(way) { return removeWayIds.indexOf(way.id) === -1; })\n .map(function(way) { return vgraph.entity(way.id); });\n\n\n // OK! Here is our intersection..\n var intersection = {\n graph: vgraph,\n actions: actions,\n vertices: vertices,\n ways: ways,\n };\n\n\n\n // Get all the valid turns through this intersection given a starting way id.\n // This operates on the virtual graph for everything.\n //\n // Basically, walk through all possible paths from starting way,\n // honoring the existing turn restrictions as we go (watch out for loops!)\n //\n // For each path found, generate and return a `osmTurn` datastructure.\n //\n intersection.turns = function(fromWayId, maxViaWay) {\n if (!fromWayId) return [];\n if (!maxViaWay) maxViaWay = 0;\n\n var vgraph = intersection.graph;\n var keyVertexIds = intersection.vertices.map(function(v) { return v.id; });\n\n var start = vgraph.entity(fromWayId);\n if (!start || !(start.__from || start.__via)) return [];\n\n // maxViaWay=0 from-*-to (0 vias)\n // maxViaWay=1 from-*-via-*-to (1 via max)\n // maxViaWay=2 from-*-via-*-via-*-to (2 vias max)\n var maxPathLength = (maxViaWay * 2) + 3;\n var turns = [];\n\n step(start);\n return turns;\n\n\n // traverse the intersection graph and find all the valid paths\n function step(entity, currPath, currRestrictions, matchedRestriction) {\n currPath = (currPath || []).slice(); // shallow copy\n if (currPath.length >= maxPathLength) return;\n currPath.push(entity.id);\n currRestrictions = (currRestrictions || []).slice(); // shallow copy\n var i, j;\n\n if (entity.type === 'node') {\n var parents = vgraph.parentWays(entity);\n var nextWays = [];\n\n // which ways can we step into?\n for (i = 0; i < parents.length; i++) {\n var way = parents[i];\n\n // if next way is a oneway incoming to this vertex, skip\n if (way.__oneWay && way.nodes[0] !== entity.id) continue;\n\n // if we have seen it before (allowing for an initial u-turn), skip\n if (currPath.indexOf(way.id) !== -1 && currPath.length >= 3) continue;\n\n // Check all \"current\" restrictions (where we've already walked the `FROM`)\n var restrict = undefined;\n for (j = 0; j < currRestrictions.length; j++) {\n var restriction = currRestrictions[j];\n var f = restriction.memberByRole('from');\n var v = restriction.membersByRole('via');\n var t = restriction.memberByRole('to');\n var isOnly = /^only_/.test(restriction.tags.restriction);\n\n // Does the current path match this turn restriction?\n var matchesFrom = (f.id === fromWayId);\n var matchesViaTo = false;\n var isAlongOnlyPath = false;\n\n if (t.id === way.id) { // match TO\n\n if (v.length === 1 && v[0].type === 'node') { // match VIA node\n matchesViaTo = (v[0].id === entity.id && (\n (matchesFrom && currPath.length === 2) ||\n (!matchesFrom && currPath.length > 2)\n ));\n\n } else { // match all VIA ways\n var pathVias = [];\n for (k = 2; k < currPath.length; k +=2 ) { // k = 2 skips FROM\n pathVias.push(currPath[k]); // (path goes way-node-way...)\n }\n var restrictionVias = [];\n for (k = 0; k < v.length; k++) {\n if (v[k].type === 'way') {\n restrictionVias.push(v[k].id);\n }\n }\n var diff = utilArrayDifference(pathVias, restrictionVias);\n matchesViaTo = !diff.length;\n }\n\n } else if (isOnly) {\n for (k = 0; k < v.length; k++) {\n // way doesn't match TO, but is one of the via ways along the path of an \"only\"\n if (v[k].type === 'way' && v[k].id === way.id) {\n isAlongOnlyPath = true;\n break;\n }\n }\n }\n\n if (matchesViaTo) {\n if (isOnly) {\n restrict = { id: restriction.id, direct: matchesFrom, from: f.id, only: true, end: true };\n } else {\n restrict = { id: restriction.id, direct: matchesFrom, from: f.id, no: true, end: true };\n }\n } else { // indirect - caused by a different nearby restriction\n if (isAlongOnlyPath) {\n restrict = { id: restriction.id, direct: false, from: f.id, only: true, end: false };\n } else if (isOnly) {\n restrict = { id: restriction.id, direct: false, from: f.id, no: true, end: true };\n }\n }\n\n // stop looking if we find a \"direct\" restriction (matching FROM, VIA, TO)\n if (restrict && restrict.direct)\n break;\n }\n\n nextWays.push({ way: way, restrict: restrict });\n }\n\n nextWays.forEach(function(nextWay) {\n step(nextWay.way, currPath, currRestrictions, nextWay.restrict);\n });\n\n\n } else { // entity.type === 'way'\n if (currPath.length >= 3) { // this is a \"complete\" path..\n var turnPath = currPath.slice(); // shallow copy\n\n // an indirect restriction - only include the partial path (starting at FROM)\n if (matchedRestriction && matchedRestriction.direct === false) {\n for (i = 0; i < turnPath.length; i++) {\n if (turnPath[i] === matchedRestriction.from) {\n turnPath = turnPath.slice(i);\n break;\n }\n }\n }\n\n var turn = pathToTurn(turnPath);\n if (turn) {\n if (matchedRestriction) {\n turn.restrictionID = matchedRestriction.id;\n turn.no = matchedRestriction.no;\n turn.only = matchedRestriction.only;\n turn.direct = matchedRestriction.direct;\n }\n turns.push(osmTurn(turn));\n }\n\n if (currPath[0] === currPath[2]) return; // if we made a u-turn - stop here\n }\n\n if (matchedRestriction && matchedRestriction.end) return; // don't advance any further\n\n // which nodes can we step into?\n var n1 = vgraph.entity(entity.first());\n var n2 = vgraph.entity(entity.last());\n var dist = geoSphericalDistance(n1.loc, n2.loc);\n var nextNodes = [];\n\n if (currPath.length > 1) {\n if (dist > maxDistance) return; // the next node is too far\n if (!entity.__via) return; // this way is a leaf / can't be a via\n }\n\n if (!entity.__oneWay && // bidirectional..\n keyVertexIds.indexOf(n1.id) !== -1 && // key vertex..\n currPath.indexOf(n1.id) === -1) { // haven't seen it yet..\n nextNodes.push(n1); // can advance to first node\n }\n if (keyVertexIds.indexOf(n2.id) !== -1 && // key vertex..\n currPath.indexOf(n2.id) === -1) { // haven't seen it yet..\n nextNodes.push(n2); // can advance to last node\n }\n\n nextNodes.forEach(function(nextNode) {\n // gather restrictions FROM this way\n var fromRestrictions = vgraph.parentRelations(entity).filter(function(r) {\n if (!r.isRestriction()) return false;\n\n var f = r.memberByRole('from');\n if (!f || f.id !== entity.id) return false;\n\n var isOnly = /^only_/.test(r.tags.restriction);\n if (!isOnly) return true;\n\n // `only_` restrictions only matter along the direction of the VIA - #4849\n var isOnlyVia = false;\n var v = r.membersByRole('via');\n if (v.length === 1 && v[0].type === 'node') { // via node\n isOnlyVia = (v[0].id === nextNode.id);\n } else { // via way(s)\n for (var i = 0; i < v.length; i++) {\n if (v[i].type !== 'way') continue;\n var viaWay = vgraph.entity(v[i].id);\n if (viaWay.first() === nextNode.id || viaWay.last() === nextNode.id) {\n isOnlyVia = true;\n break;\n }\n }\n }\n return isOnlyVia;\n });\n\n step(nextNode, currPath, currRestrictions.concat(fromRestrictions), false);\n });\n }\n }\n\n\n // assumes path is alternating way-node-way of odd length\n function pathToTurn(path) {\n if (path.length < 3) return;\n var fromWayId, fromNodeId, fromVertexId;\n var toWayId, toNodeId, toVertexId;\n var viaWayIds, viaNodeId, isUturn;\n\n fromWayId = path[0];\n toWayId = path[path.length - 1];\n\n if (path.length === 3 && fromWayId === toWayId) { // u turn\n var way = vgraph.entity(fromWayId);\n if (way.__oneWay) return null;\n\n isUturn = true;\n viaNodeId = fromVertexId = toVertexId = path[1];\n fromNodeId = toNodeId = adjacentNode(fromWayId, viaNodeId);\n\n } else {\n isUturn = false;\n fromVertexId = path[1];\n fromNodeId = adjacentNode(fromWayId, fromVertexId);\n toVertexId = path[path.length - 2];\n toNodeId = adjacentNode(toWayId, toVertexId);\n\n if (path.length === 3) {\n viaNodeId = path[1];\n } else {\n viaWayIds = path.filter(function(entityId) { return entityId[0] === 'w'; });\n viaWayIds = viaWayIds.slice(1, viaWayIds.length - 1); // remove first, last\n }\n }\n\n return {\n key: path.join('_'),\n path: path,\n from: { node: fromNodeId, way: fromWayId, vertex: fromVertexId },\n via: { node: viaNodeId, ways: viaWayIds },\n to: { node: toNodeId, way: toWayId, vertex: toVertexId },\n u: isUturn\n };\n\n\n function adjacentNode(wayId, affixId) {\n var nodes = vgraph.entity(wayId).nodes;\n return affixId === nodes[0] ? nodes[1] : nodes[nodes.length - 2];\n }\n }\n\n };\n\n return intersection;\n}\n\n\nexport function osmInferRestriction(graph, turn, projection) {\n var fromWay = graph.entity(turn.from.way);\n var fromNode = graph.entity(turn.from.node);\n var fromVertex = graph.entity(turn.from.vertex);\n var toWay = graph.entity(turn.to.way);\n var toNode = graph.entity(turn.to.node);\n var toVertex = graph.entity(turn.to.vertex);\n\n var fromOneWay = (fromWay.tags.oneway === 'yes');\n var toOneWay = (toWay.tags.oneway === 'yes');\n var angle = (geoAngle(fromVertex, fromNode, projection) -\n geoAngle(toVertex, toNode, projection)) * 180 / Math.PI;\n\n while (angle < 0)\n angle += 360;\n\n if (fromNode === toNode)\n return 'no_u_turn';\n if ((angle < 23 || angle > 336) && fromOneWay && toOneWay)\n return 'no_u_turn'; // wider tolerance for u-turn if both ways are oneway\n if ((angle < 40 || angle > 319) && fromOneWay && toOneWay && turn.from.vertex !== turn.to.vertex)\n return 'no_u_turn'; // even wider tolerance for u-turn if there is a via way (from !== to)\n if (angle < 158)\n return 'no_right_turn';\n if (angle > 202)\n return 'no_left_turn';\n\n return 'no_straight_on';\n}\n","import { geoPolygonContainsPolygon } from '../geo';\nimport { osmJoinWays, osmRelation } from '../osm';\nimport { utilArrayGroupBy, utilArrayIntersection, utilObjectOmit } from '../util';\n\n\nexport function actionMergePolygon(ids, newRelationId) {\n\n function groupEntities(graph) {\n var entities = ids.map(function (id) { return graph.entity(id); });\n var geometryGroups = utilArrayGroupBy(entities, function(entity) {\n if (entity.type === 'way' && entity.isClosed()) {\n return 'closedWay';\n } else if (entity.type === 'relation' && entity.isMultipolygon()) {\n return 'multipolygon';\n } else {\n return 'other';\n }\n });\n\n return Object.assign(\n { closedWay: [], multipolygon: [], other: [] },\n geometryGroups\n );\n }\n\n\n var action = function(graph) {\n var entities = groupEntities(graph);\n\n // An array representing all the polygons that are part of the multipolygon.\n //\n // Each element is itself an array of objects with an id property, and has a\n // locs property which is an array of the locations forming the polygon.\n var polygons = entities.multipolygon.reduce(function(polygons, m) {\n return polygons.concat(osmJoinWays(m.members, graph));\n }, []).concat(entities.closedWay.map(function(d) {\n var member = [{id: d.id}];\n member.nodes = graph.childNodes(d);\n return member;\n }));\n\n // contained is an array of arrays of boolean values,\n // where contained[j][k] is true iff the jth way is\n // contained by the kth way.\n var contained = polygons.map(function(w, i) {\n return polygons.map(function(d, n) {\n if (i === n) return null;\n return geoPolygonContainsPolygon(\n d.nodes.map(function(n) { return n.loc; }),\n w.nodes.map(function(n) { return n.loc; })\n );\n });\n });\n\n // Sort all polygons as either outer or inner ways\n var members = [];\n var outer = true;\n\n while (polygons.length) {\n extractUncontained(polygons);\n polygons = polygons.filter(isContained);\n contained = contained.filter(isContained).map(filterContained);\n }\n\n function isContained(d, i) {\n return contained[i].some(function(val) { return val; });\n }\n\n function filterContained(d) {\n return d.filter(isContained);\n }\n\n function extractUncontained(polygons) {\n polygons.forEach(function(d, i) {\n if (!isContained(d, i)) {\n d.forEach(function(member) {\n members.push({\n type: 'way',\n id: member.id,\n role: outer ? 'outer' : 'inner'\n });\n });\n }\n });\n outer = !outer;\n }\n\n // Move all tags to one relation\n var relation = entities.multipolygon[0] ||\n osmRelation({ id: newRelationId, tags: { type: 'multipolygon' }});\n\n entities.multipolygon.slice(1).forEach(function(m) {\n relation = relation.mergeTags(m.tags);\n graph = graph.remove(m);\n });\n\n entities.closedWay.forEach(function(way) {\n function isThisOuter(m) {\n return m.id === way.id && m.role !== 'inner';\n }\n if (members.some(isThisOuter)) {\n relation = relation.mergeTags(way.tags);\n graph = graph.replace(way.update({ tags: {} }));\n }\n });\n\n return graph.replace(relation.update({\n members: members,\n tags: utilObjectOmit(relation.tags, ['area'])\n }));\n };\n\n\n action.disabled = function(graph) {\n var entities = groupEntities(graph);\n if (entities.other.length > 0 ||\n entities.closedWay.length + entities.multipolygon.length < 2) {\n return 'not_eligible';\n }\n if (!entities.multipolygon.every(function(r) { return r.isComplete(graph); })) {\n return 'incomplete_relation';\n }\n\n if (!entities.multipolygon.length) {\n var sharedMultipolygons = [];\n entities.closedWay.forEach(function(way, i) {\n if (i === 0) {\n sharedMultipolygons = graph.parentMultipolygons(way);\n } else {\n sharedMultipolygons = utilArrayIntersection(sharedMultipolygons, graph.parentMultipolygons(way));\n }\n });\n sharedMultipolygons = sharedMultipolygons.filter(function(relation) {\n return relation.members.length === entities.closedWay.length;\n });\n if (sharedMultipolygons.length) {\n // don't create a new multipolygon if it'd be redundant\n return 'not_eligible';\n }\n } else if (entities.closedWay.some(function(way) {\n return utilArrayIntersection(graph.parentMultipolygons(way), entities.multipolygon).length;\n })) {\n // don't add a way to a multipolygon again if it's already a member\n return 'not_eligible';\n }\n };\n\n\n return action;\n}\n","'use strict';\n\n// do not edit .js files directly - edit src/index.jst\n\n\n\nmodule.exports = function equal(a, b) {\n if (a === b) return true;\n\n if (a && b && typeof a == 'object' && typeof b == 'object') {\n if (a.constructor !== b.constructor) return false;\n\n var length, i, keys;\n if (Array.isArray(a)) {\n length = a.length;\n if (length != b.length) return false;\n for (i = length; i-- !== 0;)\n if (!equal(a[i], b[i])) return false;\n return true;\n }\n\n\n\n if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;\n if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();\n if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();\n\n keys = Object.keys(a);\n length = keys.length;\n if (length !== Object.keys(b).length) return false;\n\n for (i = length; i-- !== 0;)\n if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;\n\n for (i = length; i-- !== 0;) {\n var key = keys[i];\n\n if (!equal(a[key], b[key])) return false;\n }\n\n return true;\n }\n\n // true if both NaN, false otherwise\n return a!==a && b!==b;\n};\n","export {\n LCS,\n diffComm,\n diffIndices,\n diffPatch,\n diff3MergeRegions,\n diff3Merge,\n mergeDiff3,\n merge,\n mergeDigIn,\n patch,\n stripPatch,\n invertPatch\n};\n\n\n// Text diff algorithm following Hunt and McIlroy 1976.\n// J. W. Hunt and M. D. McIlroy, An algorithm for differential buffer\n// comparison, Bell Telephone Laboratories CSTR #41 (1976)\n// http://www.cs.dartmouth.edu/~doug/\n// https://en.wikipedia.org/wiki/Longest_common_subsequence_problem\n//\n// Expects two arrays, finds longest common sequence\nfunction LCS(buffer1, buffer2) {\n\n let equivalenceClasses = {};\n for (let j = 0; j < buffer2.length; j++) {\n const item = buffer2[j];\n if (equivalenceClasses[item]) {\n equivalenceClasses[item].push(j);\n } else {\n equivalenceClasses[item] = [j];\n }\n }\n\n const NULLRESULT = { buffer1index: -1, buffer2index: -1, chain: null };\n let candidates = [NULLRESULT];\n\n for (let i = 0; i < buffer1.length; i++) {\n const item = buffer1[i];\n const buffer2indices = equivalenceClasses[item] || [];\n let r = 0;\n let c = candidates[0];\n\n for (let jx = 0; jx < buffer2indices.length; jx++) {\n const j = buffer2indices[jx];\n\n let s;\n for (s = r; s < candidates.length; s++) {\n if ((candidates[s].buffer2index < j) && ((s === candidates.length - 1) || (candidates[s + 1].buffer2index > j))) {\n break;\n }\n }\n\n if (s < candidates.length) {\n const newCandidate = { buffer1index: i, buffer2index: j, chain: candidates[s] };\n if (r === candidates.length) {\n candidates.push(c);\n } else {\n candidates[r] = c;\n }\n r = s + 1;\n c = newCandidate;\n if (r === candidates.length) {\n break; // no point in examining further (j)s\n }\n }\n }\n\n candidates[r] = c;\n }\n\n // At this point, we know the LCS: it's in the reverse of the\n // linked-list through .chain of candidates[candidates.length - 1].\n\n return candidates[candidates.length - 1];\n}\n\n\n// We apply the LCS to build a 'comm'-style picture of the\n// differences between buffer1 and buffer2.\nfunction diffComm(buffer1, buffer2) {\n const lcs = LCS(buffer1, buffer2);\n let result = [];\n let tail1 = buffer1.length;\n let tail2 = buffer2.length;\n let common = {common: []};\n\n function processCommon() {\n if (common.common.length) {\n common.common.reverse();\n result.push(common);\n common = {common: []};\n }\n }\n\n for (let candidate = lcs; candidate !== null; candidate = candidate.chain) {\n let different = {buffer1: [], buffer2: []};\n\n while (--tail1 > candidate.buffer1index) {\n different.buffer1.push(buffer1[tail1]);\n }\n\n while (--tail2 > candidate.buffer2index) {\n different.buffer2.push(buffer2[tail2]);\n }\n\n if (different.buffer1.length || different.buffer2.length) {\n processCommon();\n different.buffer1.reverse();\n different.buffer2.reverse();\n result.push(different);\n }\n\n if (tail1 >= 0) {\n common.common.push(buffer1[tail1]);\n }\n }\n\n processCommon();\n\n result.reverse();\n return result;\n}\n\n\n// We apply the LCS to give a simple representation of the\n// offsets and lengths of mismatched chunks in the input\n// buffers. This is used by diff3MergeRegions.\nfunction diffIndices(buffer1, buffer2) {\n const lcs = LCS(buffer1, buffer2);\n let result = [];\n let tail1 = buffer1.length;\n let tail2 = buffer2.length;\n\n for (let candidate = lcs; candidate !== null; candidate = candidate.chain) {\n const mismatchLength1 = tail1 - candidate.buffer1index - 1;\n const mismatchLength2 = tail2 - candidate.buffer2index - 1;\n tail1 = candidate.buffer1index;\n tail2 = candidate.buffer2index;\n\n if (mismatchLength1 || mismatchLength2) {\n result.push({\n buffer1: [tail1 + 1, mismatchLength1],\n buffer1Content: buffer1.slice(tail1 + 1, tail1 + 1 + mismatchLength1),\n buffer2: [tail2 + 1, mismatchLength2],\n buffer2Content: buffer2.slice(tail2 + 1, tail2 + 1 + mismatchLength2)\n });\n }\n }\n\n result.reverse();\n return result;\n}\n\n\n// We apply the LCS to build a JSON representation of a\n// diff(1)-style patch.\nfunction diffPatch(buffer1, buffer2) {\n const lcs = LCS(buffer1, buffer2);\n let result = [];\n let tail1 = buffer1.length;\n let tail2 = buffer2.length;\n\n function chunkDescription(buffer, offset, length) {\n let chunk = [];\n for (let i = 0; i < length; i++) {\n chunk.push(buffer[offset + i]);\n }\n return {\n offset: offset,\n length: length,\n chunk: chunk\n };\n }\n\n for (let candidate = lcs; candidate !== null; candidate = candidate.chain) {\n const mismatchLength1 = tail1 - candidate.buffer1index - 1;\n const mismatchLength2 = tail2 - candidate.buffer2index - 1;\n tail1 = candidate.buffer1index;\n tail2 = candidate.buffer2index;\n\n if (mismatchLength1 || mismatchLength2) {\n result.push({\n buffer1: chunkDescription(buffer1, candidate.buffer1index + 1, mismatchLength1),\n buffer2: chunkDescription(buffer2, candidate.buffer2index + 1, mismatchLength2)\n });\n }\n }\n\n result.reverse();\n return result;\n}\n\n\n// Given three buffers, A, O, and B, where both A and B are\n// independently derived from O, returns a fairly complicated\n// internal representation of merge decisions it's taken. The\n// interested reader may wish to consult\n//\n// Sanjeev Khanna, Keshav Kunal, and Benjamin C. Pierce.\n// 'A Formal Investigation of ' In Arvind and Prasad,\n// editors, Foundations of Software Technology and Theoretical\n// Computer Science (FSTTCS), December 2007.\n//\n// (http://www.cis.upenn.edu/~bcpierce/papers/diff3-short.pdf)\n//\nfunction diff3MergeRegions(a, o, b) {\n\n // \"hunks\" are array subsets where `a` or `b` are different from `o`\n // https://www.gnu.org/software/diffutils/manual/html_node/diff3-Hunks.html\n let hunks = [];\n function addHunk(h, ab) {\n hunks.push({\n ab: ab,\n oStart: h.buffer1[0],\n oLength: h.buffer1[1], // length of o to remove\n abStart: h.buffer2[0],\n abLength: h.buffer2[1] // length of a/b to insert\n // abContent: (ab === 'a' ? a : b).slice(h.buffer2[0], h.buffer2[0] + h.buffer2[1])\n });\n }\n\n diffIndices(o, a).forEach(item => addHunk(item, 'a'));\n diffIndices(o, b).forEach(item => addHunk(item, 'b'));\n hunks.sort((x,y) => x.oStart - y.oStart);\n\n let results = [];\n let currOffset = 0;\n\n function advanceTo(endOffset) {\n if (endOffset > currOffset) {\n results.push({\n stable: true,\n buffer: 'o',\n bufferStart: currOffset,\n bufferLength: endOffset - currOffset,\n bufferContent: o.slice(currOffset, endOffset)\n });\n currOffset = endOffset;\n }\n }\n\n while (hunks.length) {\n let hunk = hunks.shift();\n let regionStart = hunk.oStart;\n let regionEnd = hunk.oStart + hunk.oLength;\n let regionHunks = [hunk];\n advanceTo(regionStart);\n\n // Try to pull next overlapping hunk into this region\n while (hunks.length) {\n const nextHunk = hunks[0];\n const nextHunkStart = nextHunk.oStart;\n if (nextHunkStart > regionEnd) break; // no overlap\n\n regionEnd = Math.max(regionEnd, nextHunkStart + nextHunk.oLength);\n regionHunks.push(hunks.shift());\n }\n\n if (regionHunks.length === 1) {\n // Only one hunk touches this region, meaning that there is no conflict here.\n // Either `a` or `b` is inserting into a region of `o` unchanged by the other.\n if (hunk.abLength > 0) {\n const buffer = (hunk.ab === 'a' ? a : b);\n results.push({\n stable: true,\n buffer: hunk.ab,\n bufferStart: hunk.abStart,\n bufferLength: hunk.abLength,\n bufferContent: buffer.slice(hunk.abStart, hunk.abStart + hunk.abLength)\n });\n }\n } else {\n // A true a/b conflict. Determine the bounds involved from `a`, `o`, and `b`.\n // Effectively merge all the `a` hunks into one giant hunk, then do the\n // same for the `b` hunks; then, correct for skew in the regions of `o`\n // that each side changed, and report appropriate spans for the three sides.\n let bounds = {\n a: [a.length, -1, o.length, -1],\n b: [b.length, -1, o.length, -1]\n };\n while (regionHunks.length) {\n hunk = regionHunks.shift();\n const oStart = hunk.oStart;\n const oEnd = oStart + hunk.oLength;\n const abStart = hunk.abStart;\n const abEnd = abStart + hunk.abLength;\n let b = bounds[hunk.ab];\n b[0] = Math.min(abStart, b[0]);\n b[1] = Math.max(abEnd, b[1]);\n b[2] = Math.min(oStart, b[2]);\n b[3] = Math.max(oEnd, b[3]);\n }\n\n const aStart = bounds.a[0] + (regionStart - bounds.a[2]);\n const aEnd = bounds.a[1] + (regionEnd - bounds.a[3]);\n const bStart = bounds.b[0] + (regionStart - bounds.b[2]);\n const bEnd = bounds.b[1] + (regionEnd - bounds.b[3]);\n\n let result = {\n stable: false,\n aStart: aStart,\n aLength: aEnd - aStart,\n aContent: a.slice(aStart, aEnd),\n oStart: regionStart,\n oLength: regionEnd - regionStart,\n oContent: o.slice(regionStart, regionEnd),\n bStart: bStart,\n bLength: bEnd - bStart,\n bContent: b.slice(bStart, bEnd)\n };\n results.push(result);\n }\n currOffset = regionEnd;\n }\n\n advanceTo(o.length);\n\n return results;\n}\n\n\n// Applies the output of diff3MergeRegions to actually\n// construct the merged buffer; the returned result alternates\n// between 'ok' and 'conflict' blocks.\n// A \"false conflict\" is where `a` and `b` both change the same from `o`\nfunction diff3Merge(a, o, b, options) {\n let defaults = {\n excludeFalseConflicts: true,\n stringSeparator: /\\s+/\n };\n options = Object.assign(defaults, options);\n\n const aString = (typeof a === 'string');\n const oString = (typeof o === 'string');\n const bString = (typeof b === 'string');\n\n if (aString) a = a.split(options.stringSeparator);\n if (oString) o = o.split(options.stringSeparator);\n if (bString) b = b.split(options.stringSeparator);\n\n let results = [];\n const regions = diff3MergeRegions(a, o, b);\n\n let okBuffer = [];\n function flushOk() {\n if (okBuffer.length) {\n results.push({ ok: okBuffer });\n }\n okBuffer = [];\n }\n\n function isFalseConflict(a, b) {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n }\n\n regions.forEach(region => {\n if (region.stable) {\n okBuffer.push(...region.bufferContent);\n } else {\n if (options.excludeFalseConflicts && isFalseConflict(region.aContent, region.bContent)) {\n okBuffer.push(...region.aContent);\n } else {\n flushOk();\n results.push({\n conflict: {\n a: region.aContent,\n aIndex: region.aStart,\n o: region.oContent,\n oIndex: region.oStart,\n b: region.bContent,\n bIndex: region.bStart\n }\n });\n }\n }\n });\n\n flushOk();\n return results;\n}\n\nfunction mergeDiff3(a, o, b, options) {\n let defaults = {\n excludeFalseConflicts: true,\n stringSeparator: /\\s+/,\n label: {}\n };\n options = Object.assign(defaults, options);\n\n const mergeResult = diff3Merge(a, o, b, options);\n\n let conflict = false;\n let lines = [];\n\n mergeResult.forEach(result => {\n if (result.ok) {\n lines = lines.concat(result.ok);\n } else if (result.conflict) { \n conflict = true;\n lines.push(`<<<<<<<${options.label.a ? ` ${options.label.a}` : ''}`);\n lines = lines.concat(result.conflict.a);\n lines.push(`|||||||${options.label.o ? ` ${options.label.o}` : ''}`);\n lines = lines.concat(result.conflict.o);\n lines.push('=======');\n lines = lines.concat(result.conflict.b);\n lines.push(`>>>>>>>${options.label.b ? ` ${options.label.b}` : ''}`);\n }\n });\n\n return {\n conflict: conflict,\n result: lines\n };\n}\n\nfunction merge(a, o, b, options) {\n let defaults = {\n excludeFalseConflicts: true,\n stringSeparator: /\\s+/\n };\n options = Object.assign(defaults, options);\n\n const merger = diff3Merge(a, o, b, options);\n let conflict = false;\n let lines = [];\n for (let i = 0; i < merger.length; i++) {\n const item = merger[i];\n if (item.ok) {\n lines = lines.concat(item.ok);\n } else {\n conflict = true;\n lines = lines.concat(\n ['\\n<<<<<<<<<\\n'], item.conflict.a,\n ['\\n=========\\n'], item.conflict.b,\n ['\\n>>>>>>>>>\\n']\n );\n }\n }\n return {\n conflict: conflict,\n result: lines\n };\n}\n\n\nfunction mergeDigIn(a, o, b, options) {\n let defaults = {\n excludeFalseConflicts: false,\n stringSeparator: /\\s+/\n };\n options = Object.assign(defaults, options);\n\n const merger = diff3Merge(a, o, b, options);\n let conflict = false;\n let lines = [];\n for (let i = 0; i < merger.length; i++) {\n const item = merger[i];\n if (item.ok) {\n lines = lines.concat(item.ok);\n } else {\n const c = diffComm(item.conflict.a, item.conflict.b);\n for (let j = 0; j < c.length; j++) {\n let inner = c[j];\n if (inner.common) {\n lines = lines.concat(inner.common);\n } else {\n conflict = true;\n lines = lines.concat(\n ['\\n<<<<<<<<<\\n'], inner.buffer1,\n ['\\n=========\\n'], inner.buffer2,\n ['\\n>>>>>>>>>\\n']\n );\n }\n }\n }\n }\n return {\n conflict: conflict,\n result: lines\n };\n}\n\n\n// Applies a patch to a buffer.\n// Given buffer1 and buffer2, `patch(buffer1, diffPatch(buffer1, buffer2))` should give buffer2.\nfunction patch(buffer, patch) {\n let result = [];\n let currOffset = 0;\n\n function advanceTo(targetOffset) {\n while (currOffset < targetOffset) {\n result.push(buffer[currOffset]);\n currOffset++;\n }\n }\n\n for (let chunkIndex = 0; chunkIndex < patch.length; chunkIndex++) {\n let chunk = patch[chunkIndex];\n advanceTo(chunk.buffer1.offset);\n for (let itemIndex = 0; itemIndex < chunk.buffer2.chunk.length; itemIndex++) {\n result.push(chunk.buffer2.chunk[itemIndex]);\n }\n currOffset += chunk.buffer1.length;\n }\n\n advanceTo(buffer.length);\n return result;\n}\n\n\n// Takes the output of diffPatch(), and removes extra information from it. \n// It can still be used by patch(), below, but can no longer be inverted.\nfunction stripPatch(patch) {\n return patch.map(chunk => ({\n buffer1: { offset: chunk.buffer1.offset, length: chunk.buffer1.length },\n buffer2: { chunk: chunk.buffer2.chunk }\n }));\n}\n\n\n// Takes the output of diffPatch(), and inverts the sense of it, so that it \n// can be applied to buffer2 to give buffer1 rather than the other way around.\nfunction invertPatch(patch) {\n return patch.map(chunk => ({ \n buffer1: chunk.buffer2, \n buffer2: chunk.buffer1 \n }));\n}","import deepEqual from 'fast-deep-equal';\nimport { diff3Merge } from 'node-diff3';\n\nimport { t } from '../core/localizer';\nimport { actionDeleteMultiple } from './delete_multiple';\nimport { osmEntity } from '../osm';\nimport { utilArrayUnion, utilArrayUniq } from '../util';\n\n\nexport function actionMergeRemoteChanges(id, localGraph, remoteGraph, discardTags, formatUser) {\n discardTags = discardTags || {};\n var _option = 'safe'; // 'safe', 'force_local', 'force_remote'\n var _conflicts = [];\n\n\n function user(d) {\n return (typeof formatUser === 'function') ? formatUser(d) : d;\n }\n\n\n function mergeLocation(remote, target) {\n function pointEqual(a, b) {\n var epsilon = 1e-6;\n return (Math.abs(a[0] - b[0]) < epsilon) && (Math.abs(a[1] - b[1]) < epsilon);\n }\n\n if (_option === 'force_local' || pointEqual(target.loc, remote.loc)) {\n return target;\n }\n if (_option === 'force_remote') {\n return target.update({loc: remote.loc});\n }\n\n _conflicts.push(t('merge_remote_changes.conflict.location', { user: user(remote.user) }));\n return target;\n }\n\n\n function mergeNodes(base, remote, target) {\n if (_option === 'force_local' || deepEqual(target.nodes, remote.nodes)) {\n return target;\n }\n if (_option === 'force_remote') {\n return target.update({nodes: remote.nodes});\n }\n\n var ccount = _conflicts.length;\n var o = base.nodes || [];\n var a = target.nodes || [];\n var b = remote.nodes || [];\n var nodes = [];\n var hunks = diff3Merge(a, o, b, { excludeFalseConflicts: true });\n\n for (var i = 0; i < hunks.length; i++) {\n var hunk = hunks[i];\n if (hunk.ok) {\n nodes.push.apply(nodes, hunk.ok);\n } else {\n // for all conflicts, we can assume c.a !== c.b\n // because `diff3Merge` called with `true` option to exclude false conflicts..\n var c = hunk.conflict;\n if (deepEqual(c.o, c.a)) { // only changed remotely\n nodes.push.apply(nodes, c.b);\n } else if (deepEqual(c.o, c.b)) { // only changed locally\n nodes.push.apply(nodes, c.a);\n } else { // changed both locally and remotely\n _conflicts.push(t('merge_remote_changes.conflict.nodelist', { user: user(remote.user) }));\n break;\n }\n }\n }\n\n return (_conflicts.length === ccount) ? target.update({nodes: nodes}) : target;\n }\n\n\n function mergeChildren(targetWay, children, updates, graph) {\n function isUsed(node, targetWay) {\n var hasInterestingParent = graph.parentWays(node)\n .some(function(way) { return way.id !== targetWay.id; });\n\n return node.hasInterestingTags() ||\n hasInterestingParent ||\n graph.parentRelations(node).length > 0;\n }\n\n var ccount = _conflicts.length;\n\n for (var i = 0; i < children.length; i++) {\n var id = children[i];\n var node = graph.hasEntity(id);\n\n // remove unused childNodes..\n if (targetWay.nodes.indexOf(id) === -1) {\n if (node && !isUsed(node, targetWay)) {\n updates.removeIds.push(id);\n }\n continue;\n }\n\n // restore used childNodes..\n var local = localGraph.hasEntity(id);\n var remote = remoteGraph.hasEntity(id);\n var target;\n\n if (_option === 'force_remote' && remote && remote.visible) {\n updates.replacements.push(remote);\n\n } else if (_option === 'force_local' && local) {\n target = osmEntity(local);\n if (remote) {\n target = target.update({ version: remote.version });\n }\n updates.replacements.push(target);\n\n } else if (_option === 'safe' && local && remote && local.version !== remote.version) {\n target = osmEntity(local, { version: remote.version });\n if (remote.visible) {\n target = mergeLocation(remote, target);\n } else {\n _conflicts.push(t('merge_remote_changes.conflict.deleted', { user: user(remote.user) }));\n }\n\n if (_conflicts.length !== ccount) break;\n updates.replacements.push(target);\n }\n }\n\n return targetWay;\n }\n\n\n function updateChildren(updates, graph) {\n for (var i = 0; i < updates.replacements.length; i++) {\n graph = graph.replace(updates.replacements[i]);\n }\n if (updates.removeIds.length) {\n graph = actionDeleteMultiple(updates.removeIds)(graph);\n }\n return graph;\n }\n\n\n function mergeMembers(remote, target) {\n if (_option === 'force_local' || deepEqual(target.members, remote.members)) {\n return target;\n }\n if (_option === 'force_remote') {\n return target.update({members: remote.members});\n }\n\n _conflicts.push(t('merge_remote_changes.conflict.memberlist', { user: user(remote.user) }));\n return target;\n }\n\n\n function mergeTags(base, remote, target) {\n if (_option === 'force_local' || deepEqual(target.tags, remote.tags)) {\n return target;\n }\n if (_option === 'force_remote') {\n return target.update({tags: remote.tags});\n }\n\n var ccount = _conflicts.length;\n var o = base.tags || {};\n var a = target.tags || {};\n var b = remote.tags || {};\n var keys = utilArrayUnion(utilArrayUnion(Object.keys(o), Object.keys(a)), Object.keys(b))\n .filter(function(k) { return !discardTags[k]; });\n var tags = Object.assign({}, a); // shallow copy\n var changed = false;\n\n for (var i = 0; i < keys.length; i++) {\n var k = keys[i];\n\n if (o[k] !== b[k] && a[k] !== b[k]) { // changed remotely..\n if (o[k] !== a[k]) { // changed locally..\n _conflicts.push(t('merge_remote_changes.conflict.tags',\n { tag: k, local: a[k], remote: b[k], user: user(remote.user) }));\n\n } else { // unchanged locally, accept remote change..\n if (b.hasOwnProperty(k)) {\n tags[k] = b[k];\n } else {\n delete tags[k];\n }\n changed = true;\n }\n }\n }\n\n return (changed && _conflicts.length === ccount) ? target.update({tags: tags}) : target;\n }\n\n\n // `graph.base()` is the common ancestor of the two graphs.\n // `localGraph` contains user's edits up to saving\n // `remoteGraph` contains remote edits to modified nodes\n // `graph` must be a descendent of `localGraph` and may include\n // some conflict resolution actions performed on it.\n //\n // --- ... --- `localGraph` -- ... -- `graph`\n // /\n // `graph.base()` --- ... --- `remoteGraph`\n //\n var action = function(graph) {\n var updates = { replacements: [], removeIds: [] };\n var base = graph.base().entities[id];\n var local = localGraph.entity(id);\n var remote = remoteGraph.entity(id);\n var target = osmEntity(local, { version: remote.version });\n\n // delete/undelete\n if (!remote.visible) {\n if (_option === 'force_remote') {\n return actionDeleteMultiple([id])(graph);\n\n } else if (_option === 'force_local') {\n if (target.type === 'way') {\n target = mergeChildren(target, utilArrayUniq(local.nodes), updates, graph);\n graph = updateChildren(updates, graph);\n }\n return graph.replace(target);\n\n } else {\n _conflicts.push(t('merge_remote_changes.conflict.deleted', { user: user(remote.user) }));\n return graph; // do nothing\n }\n }\n\n // merge\n if (target.type === 'node') {\n target = mergeLocation(remote, target);\n\n } else if (target.type === 'way') {\n // pull in any child nodes that may not be present locally..\n graph.rebase(remoteGraph.childNodes(remote), [graph], false);\n target = mergeNodes(base, remote, target);\n target = mergeChildren(target, utilArrayUnion(local.nodes, remote.nodes), updates, graph);\n\n } else if (target.type === 'relation') {\n target = mergeMembers(remote, target);\n }\n\n target = mergeTags(base, remote, target);\n\n if (!_conflicts.length) {\n graph = updateChildren(updates, graph).replace(target);\n }\n\n return graph;\n };\n\n\n action.withOption = function(opt) {\n _option = opt;\n return action;\n };\n\n\n action.conflicts = function() {\n return _conflicts;\n };\n\n\n return action;\n}\n","import {\n geoAngle, geoChooseEdge, geoPathIntersections, geoPathLength,\n geoVecAdd, geoVecEqual, geoVecInterp, geoVecSubtract\n} from '../geo';\n\nimport { osmNode } from '../osm/node';\nimport { utilArrayIntersection } from '../util';\n\n\n// https://github.com/openstreetmap/josm/blob/mirror/src/org/openstreetmap/josm/command/MoveCommand.java\n// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/MoveNodeAction.as\nexport function actionMove(moveIDs, tryDelta, projection, cache) {\n var _delta = tryDelta;\n\n function setupCache(graph) {\n function canMove(nodeID) {\n // Allow movement of any node that is in the selectedIDs list..\n if (moveIDs.indexOf(nodeID) !== -1) return true;\n\n // Allow movement of a vertex where 2 ways meet..\n var parents = graph.parentWays(graph.entity(nodeID));\n if (parents.length < 3) return true;\n\n // Restrict movement of a vertex where >2 ways meet, unless all parentWays are moving too..\n var parentsMoving = parents.every(function(way) { return cache.moving[way.id]; });\n if (!parentsMoving) delete cache.moving[nodeID];\n\n return parentsMoving;\n }\n\n function cacheEntities(ids) {\n for (var i = 0; i < ids.length; i++) {\n var id = ids[i];\n if (cache.moving[id]) continue;\n cache.moving[id] = true;\n\n var entity = graph.hasEntity(id);\n if (!entity) continue;\n\n if (entity.type === 'node') {\n cache.nodes.push(id);\n cache.startLoc[id] = entity.loc;\n } else if (entity.type === 'way') {\n cache.ways.push(id);\n cacheEntities(entity.nodes);\n } else {\n cacheEntities(entity.members.map(function(member) {\n return member.id;\n }));\n }\n }\n }\n\n function cacheIntersections(ids) {\n function isEndpoint(way, id) {\n return !way.isClosed() && !!way.affix(id);\n }\n\n for (var i = 0; i < ids.length; i++) {\n var id = ids[i];\n\n // consider only intersections with 1 moved and 1 unmoved way.\n var childNodes = graph.childNodes(graph.entity(id));\n for (var j = 0; j < childNodes.length; j++) {\n var node = childNodes[j];\n var parents = graph.parentWays(node);\n if (parents.length !== 2) continue;\n\n var moved = graph.entity(id);\n var unmoved = null;\n for (var k = 0; k < parents.length; k++) {\n var way = parents[k];\n if (!cache.moving[way.id]) {\n unmoved = way;\n break;\n }\n }\n if (!unmoved) continue;\n\n // exclude ways that are overly connected..\n if (utilArrayIntersection(moved.nodes, unmoved.nodes).length > 2) continue;\n if (moved.isArea() || unmoved.isArea()) continue;\n\n cache.intersections.push({\n nodeId: node.id,\n movedId: moved.id,\n unmovedId: unmoved.id,\n movedIsEP: isEndpoint(moved, node.id),\n unmovedIsEP: isEndpoint(unmoved, node.id)\n });\n }\n }\n }\n\n\n if (!cache) {\n cache = {};\n }\n if (!cache.ok) {\n cache.moving = {};\n cache.intersections = [];\n cache.replacedVertex = {};\n cache.startLoc = {};\n cache.nodes = [];\n cache.ways = [];\n\n cacheEntities(moveIDs);\n cacheIntersections(cache.ways);\n cache.nodes = cache.nodes.filter(canMove);\n\n cache.ok = true;\n }\n }\n\n\n // Place a vertex where the moved vertex used to be, to preserve way shape..\n //\n // Start:\n // b ---- e\n // / \\\n // / \\\n // / \\\n // a c\n //\n // * node '*' added to preserve shape\n // / \\\n // / b ---- e way `b,e` moved here:\n // / \\\n // a c\n //\n //\n function replaceMovedVertex(nodeId, wayId, graph, delta) {\n var way = graph.entity(wayId);\n var moved = graph.entity(nodeId);\n var movedIndex = way.nodes.indexOf(nodeId);\n var len, prevIndex, nextIndex;\n\n if (way.isClosed()) {\n len = way.nodes.length - 1;\n prevIndex = (movedIndex + len - 1) % len;\n nextIndex = (movedIndex + len + 1) % len;\n } else {\n len = way.nodes.length;\n prevIndex = movedIndex - 1;\n nextIndex = movedIndex + 1;\n }\n\n var prev = graph.hasEntity(way.nodes[prevIndex]);\n var next = graph.hasEntity(way.nodes[nextIndex]);\n\n // Don't add orig vertex at endpoint..\n if (!prev || !next) return graph;\n\n var key = wayId + '_' + nodeId;\n var orig = cache.replacedVertex[key];\n if (!orig) {\n orig = osmNode();\n cache.replacedVertex[key] = orig;\n cache.startLoc[orig.id] = cache.startLoc[nodeId];\n }\n\n var start, end;\n if (delta) {\n start = projection(cache.startLoc[nodeId]);\n end = projection.invert(geoVecAdd(start, delta));\n } else {\n end = cache.startLoc[nodeId];\n }\n orig = orig.move(end);\n\n var angle = Math.abs(geoAngle(orig, prev, projection) -\n geoAngle(orig, next, projection)) * 180 / Math.PI;\n\n // Don't add orig vertex if it would just make a straight line..\n if (angle > 175 && angle < 185) return graph;\n\n // moving forward or backward along way?\n var p1 = [prev.loc, orig.loc, moved.loc, next.loc].map(projection);\n var p2 = [prev.loc, moved.loc, orig.loc, next.loc].map(projection);\n var d1 = geoPathLength(p1);\n var d2 = geoPathLength(p2);\n var insertAt = (d1 <= d2) ? movedIndex : nextIndex;\n\n // moving around closed loop?\n if (way.isClosed() && insertAt === 0) insertAt = len;\n\n way = way.addNode(orig.id, insertAt);\n return graph.replace(orig).replace(way);\n }\n\n\n // Remove duplicate vertex that might have been added by\n // replaceMovedVertex. This is done after the unzorro checks.\n function removeDuplicateVertices(wayId, graph) {\n var way = graph.entity(wayId);\n var epsilon = 1e-6;\n var prev, curr;\n\n function isInteresting(node, graph) {\n return graph.parentWays(node).length > 1 ||\n graph.parentRelations(node).length ||\n node.hasInterestingTags();\n }\n\n for (var i = 0; i < way.nodes.length; i++) {\n curr = graph.entity(way.nodes[i]);\n\n if (prev && curr && geoVecEqual(prev.loc, curr.loc, epsilon)) {\n if (!isInteresting(prev, graph)) {\n way = way.removeNode(prev.id);\n graph = graph.replace(way).remove(prev);\n } else if (!isInteresting(curr, graph)) {\n way = way.removeNode(curr.id);\n graph = graph.replace(way).remove(curr);\n }\n }\n\n prev = curr;\n }\n\n return graph;\n }\n\n\n // Reorder nodes around intersections that have moved..\n //\n // Start: way1.nodes: b,e (moving)\n // a - b - c ----- d way2.nodes: a,b,c,d (static)\n // | vertex: b\n // e isEP1: true, isEP2, false\n //\n // way1 `b,e` moved here:\n // a ----- c = b - d\n // |\n // e\n //\n // reorder nodes way1.nodes: b,e\n // a ----- c - b - d way2.nodes: a,c,b,d\n // |\n // e\n //\n function unZorroIntersection(intersection, graph) {\n var vertex = graph.entity(intersection.nodeId);\n var way1 = graph.entity(intersection.movedId);\n var way2 = graph.entity(intersection.unmovedId);\n var isEP1 = intersection.movedIsEP;\n var isEP2 = intersection.unmovedIsEP;\n\n // don't move the vertex if it is the endpoint of both ways.\n if (isEP1 && isEP2) return graph;\n\n var nodes1 = graph.childNodes(way1).filter(function(n) { return n !== vertex; });\n var nodes2 = graph.childNodes(way2).filter(function(n) { return n !== vertex; });\n\n if (way1.isClosed() && way1.first() === vertex.id) nodes1.push(nodes1[0]);\n if (way2.isClosed() && way2.first() === vertex.id) nodes2.push(nodes2[0]);\n\n var edge1 = !isEP1 && geoChooseEdge(nodes1, projection(vertex.loc), projection);\n var edge2 = !isEP2 && geoChooseEdge(nodes2, projection(vertex.loc), projection);\n var loc;\n\n // snap vertex to nearest edge (or some point between them)..\n if (!isEP1 && !isEP2) {\n var epsilon = 1e-6, maxIter = 10;\n for (var i = 0; i < maxIter; i++) {\n loc = geoVecInterp(edge1.loc, edge2.loc, 0.5);\n edge1 = geoChooseEdge(nodes1, projection(loc), projection);\n edge2 = geoChooseEdge(nodes2, projection(loc), projection);\n if (Math.abs(edge1.distance - edge2.distance) < epsilon) break;\n }\n } else if (!isEP1) {\n loc = edge1.loc;\n } else {\n loc = edge2.loc;\n }\n\n graph = graph.replace(vertex.move(loc));\n\n // if zorro happened, reorder nodes..\n if (!isEP1 && edge1.index !== way1.nodes.indexOf(vertex.id)) {\n way1 = way1.removeNode(vertex.id).addNode(vertex.id, edge1.index);\n graph = graph.replace(way1);\n }\n if (!isEP2 && edge2.index !== way2.nodes.indexOf(vertex.id)) {\n way2 = way2.removeNode(vertex.id).addNode(vertex.id, edge2.index);\n graph = graph.replace(way2);\n }\n\n return graph;\n }\n\n\n function cleanupIntersections(graph) {\n for (var i = 0; i < cache.intersections.length; i++) {\n var obj = cache.intersections[i];\n graph = replaceMovedVertex(obj.nodeId, obj.movedId, graph, _delta);\n graph = replaceMovedVertex(obj.nodeId, obj.unmovedId, graph, null);\n graph = unZorroIntersection(obj, graph);\n graph = removeDuplicateVertices(obj.movedId, graph);\n graph = removeDuplicateVertices(obj.unmovedId, graph);\n }\n\n return graph;\n }\n\n\n // check if moving way endpoint can cross an unmoved way, if so limit delta..\n function limitDelta(graph) {\n function moveNode(loc) {\n return geoVecAdd(projection(loc), _delta);\n }\n\n for (var i = 0; i < cache.intersections.length; i++) {\n var obj = cache.intersections[i];\n\n // Don't limit movement if this is vertex joins 2 endpoints..\n if (obj.movedIsEP && obj.unmovedIsEP) continue;\n // Don't limit movement if this vertex is not an endpoint anyway..\n if (!obj.movedIsEP) continue;\n\n var node = graph.entity(obj.nodeId);\n var start = projection(node.loc);\n var end = geoVecAdd(start, _delta);\n var movedNodes = graph.childNodes(graph.entity(obj.movedId));\n var movedPath = movedNodes.map(function(n) { return moveNode(n.loc); });\n var unmovedNodes = graph.childNodes(graph.entity(obj.unmovedId));\n var unmovedPath = unmovedNodes.map(function(n) { return projection(n.loc); });\n var hits = geoPathIntersections(movedPath, unmovedPath);\n\n for (var j = 0; i < hits.length; i++) {\n if (geoVecEqual(hits[j], end)) continue;\n var edge = geoChooseEdge(unmovedNodes, end, projection);\n _delta = geoVecSubtract(projection(edge.loc), start);\n }\n }\n }\n\n\n var action = function(graph) {\n if (_delta[0] === 0 && _delta[1] === 0) return graph;\n\n setupCache(graph);\n\n if (cache.intersections.length) {\n limitDelta(graph);\n }\n\n for (var i = 0; i < cache.nodes.length; i++) {\n var node = graph.entity(cache.nodes[i]);\n var start = projection(node.loc);\n var end = geoVecAdd(start, _delta);\n graph = graph.replace(node.move(projection.invert(end)));\n }\n\n if (cache.intersections.length) {\n graph = cleanupIntersections(graph);\n }\n\n return graph;\n };\n\n\n action.delta = function() {\n return _delta;\n };\n\n\n return action;\n}\n","export function actionMoveMember(relationId, fromIndex, toIndex) {\n return function(graph) {\n return graph.replace(graph.entity(relationId).moveMember(fromIndex, toIndex));\n };\n}\n","import { geoVecInterp } from '../geo';\n\nexport function actionMoveNode(nodeID, toLoc) {\n\n var action = function(graph, t) {\n if (t === null || !isFinite(t)) t = 1;\n t = Math.min(Math.max(+t, 0), 1);\n\n var node = graph.entity(nodeID);\n return graph.replace(\n node.move(geoVecInterp(node.loc, toLoc, t))\n );\n };\n\n action.transitionable = true;\n\n return action;\n}\n","export function actionNoop() {\n return function(graph) {\n return graph;\n };\n}\n","import { actionDeleteNode } from './delete_node';\nimport {\n geoVecAdd, geoVecEqual, geoVecInterp, geoVecLength, geoVecNormalize,\n geoVecProject, geoVecScale, geoVecSubtract,\n geoOrthoNormalizedDotProduct, geoOrthoCalcScore, geoOrthoCanOrthogonalize\n} from '../geo';\n\n\nexport function actionOrthogonalize(wayID, projection, vertexID, degThresh, ep) {\n var epsilon = ep || 1e-4;\n var threshold = degThresh || 13; // degrees within right or straight to alter\n\n // We test normalized dot products so we can compare as cos(angle)\n var lowerThreshold = Math.cos((90 - threshold) * Math.PI / 180);\n var upperThreshold = Math.cos(threshold * Math.PI / 180);\n\n\n var action = function(graph, t) {\n if (t === null || !isFinite(t)) t = 1;\n t = Math.min(Math.max(+t, 0), 1);\n\n var way = graph.entity(wayID);\n way = way.removeNode(''); // sanity check - remove any consecutive duplicates\n\n if (way.tags.nonsquare) {\n var tags = Object.assign({}, way.tags);\n // since we're squaring, remove indication that this is physically unsquare\n delete tags.nonsquare;\n way = way.update({tags: tags});\n }\n\n graph = graph.replace(way);\n\n var isClosed = way.isClosed();\n var nodes = graph.childNodes(way).slice(); // shallow copy\n if (isClosed) nodes.pop();\n\n if (vertexID !== undefined) {\n nodes = nodeSubset(nodes, vertexID, isClosed);\n if (nodes.length !== 3) return graph;\n }\n\n // note: all geometry functions here use the unclosed node/point/coord list\n\n var nodeCount = {};\n var points = [];\n var corner = { i: 0, dotp: 1 };\n var node, point, loc, score, motions, i, j;\n\n for (i = 0; i < nodes.length; i++) {\n node = nodes[i];\n nodeCount[node.id] = (nodeCount[node.id] || 0) + 1;\n points.push({ id: node.id, coord: projection(node.loc) });\n }\n\n\n if (points.length === 3) { // move only one vertex for right triangle\n for (i = 0; i < 1000; i++) {\n motions = points.map(calcMotion);\n\n points[corner.i].coord = geoVecAdd(points[corner.i].coord, motions[corner.i]);\n score = corner.dotp;\n if (score < epsilon) {\n break;\n }\n }\n\n node = graph.entity(nodes[corner.i].id);\n loc = projection.invert(points[corner.i].coord);\n graph = graph.replace(node.move(geoVecInterp(node.loc, loc, t)));\n\n } else {\n var straights = [];\n var simplified = [];\n\n // Remove points from nearly straight sections..\n // This produces a simplified shape to orthogonalize\n for (i = 0; i < points.length; i++) {\n point = points[i];\n var dotp = 0;\n if (isClosed || (i > 0 && i < points.length - 1)) {\n var a = points[(i - 1 + points.length) % points.length];\n var b = points[(i + 1) % points.length];\n dotp = Math.abs(geoOrthoNormalizedDotProduct(a.coord, b.coord, point.coord));\n }\n\n if (dotp > upperThreshold) {\n straights.push(point);\n } else {\n simplified.push(point);\n }\n }\n\n // Orthogonalize the simplified shape\n var bestPoints = clonePoints(simplified);\n var originalPoints = clonePoints(simplified);\n\n score = Infinity;\n for (i = 0; i < 1000; i++) {\n motions = simplified.map(calcMotion);\n\n for (j = 0; j < motions.length; j++) {\n simplified[j].coord = geoVecAdd(simplified[j].coord, motions[j]);\n }\n var newScore = geoOrthoCalcScore(simplified, isClosed, epsilon, threshold);\n if (newScore < score) {\n bestPoints = clonePoints(simplified);\n score = newScore;\n }\n if (score < epsilon) {\n break;\n }\n }\n\n var bestCoords = bestPoints.map(function(p) { return p.coord; });\n if (isClosed) bestCoords.push(bestCoords[0]);\n\n // move the nodes that should move\n for (i = 0; i < bestPoints.length; i++) {\n point = bestPoints[i];\n if (!geoVecEqual(originalPoints[i].coord, point.coord)) {\n node = graph.entity(point.id);\n loc = projection.invert(point.coord);\n graph = graph.replace(node.move(geoVecInterp(node.loc, loc, t)));\n }\n }\n\n // move the nodes along straight segments\n for (i = 0; i < straights.length; i++) {\n point = straights[i];\n if (nodeCount[point.id] > 1) continue; // skip self-intersections\n\n node = graph.entity(point.id);\n\n if (t === 1 &&\n graph.parentWays(node).length === 1 &&\n graph.parentRelations(node).length === 0 &&\n !node.hasInterestingTags()\n ) {\n // remove uninteresting points..\n graph = actionDeleteNode(node.id)(graph);\n\n } else {\n // move interesting points to the nearest edge..\n var choice = geoVecProject(point.coord, bestCoords);\n if (choice) {\n loc = projection.invert(choice.target);\n graph = graph.replace(node.move(geoVecInterp(node.loc, loc, t)));\n }\n }\n }\n }\n\n return graph;\n\n\n function clonePoints(array) {\n return array.map(function(p) {\n return { id: p.id, coord: [p.coord[0], p.coord[1]] };\n });\n }\n\n\n function calcMotion(point, i, array) {\n // don't try to move the endpoints of a non-closed way.\n if (!isClosed && (i === 0 || i === array.length - 1)) return [0, 0];\n // don't try to move a node that appears more than once (self intersection)\n if (nodeCount[array[i].id] > 1) return [0, 0];\n\n var a = array[(i - 1 + array.length) % array.length].coord;\n var origin = point.coord;\n var b = array[(i + 1) % array.length].coord;\n var p = geoVecSubtract(a, origin);\n var q = geoVecSubtract(b, origin);\n\n var scale = 2 * Math.min(geoVecLength(p), geoVecLength(q));\n p = geoVecNormalize(p);\n q = geoVecNormalize(q);\n\n var dotp = (p[0] * q[0] + p[1] * q[1]);\n var val = Math.abs(dotp);\n\n if (val < lowerThreshold) { // nearly orthogonal\n corner.i = i;\n corner.dotp = val;\n var vec = geoVecNormalize(geoVecAdd(p, q));\n return geoVecScale(vec, 0.1 * dotp * scale);\n }\n\n return [0, 0]; // do nothing\n }\n };\n\n\n // if we are only orthogonalizing one vertex,\n // get that vertex and the previous and next\n function nodeSubset(nodes, vertexID, isClosed) {\n var first = isClosed ? 0 : 1;\n var last = isClosed ? nodes.length : nodes.length - 1;\n\n for (var i = first; i < last; i++) {\n if (nodes[i].id === vertexID) {\n return [\n nodes[(i - 1 + nodes.length) % nodes.length],\n nodes[i],\n nodes[(i + 1) % nodes.length]\n ];\n }\n }\n\n return [];\n }\n\n\n action.disabled = function(graph) {\n var way = graph.entity(wayID);\n way = way.removeNode(''); // sanity check - remove any consecutive duplicates\n graph = graph.replace(way);\n\n var isClosed = way.isClosed();\n var nodes = graph.childNodes(way).slice(); // shallow copy\n if (isClosed) nodes.pop();\n\n var allowStraightAngles = false;\n if (vertexID !== undefined) {\n allowStraightAngles = true;\n nodes = nodeSubset(nodes, vertexID, isClosed);\n if (nodes.length !== 3) return 'end_vertex';\n }\n\n var coords = nodes.map(function(n) { return projection(n.loc); });\n var score = geoOrthoCanOrthogonalize(coords, isClosed, epsilon, threshold, allowStraightAngles);\n\n if (score === null) {\n return 'not_squarish';\n } else if (score === 0) {\n return 'square_enough';\n } else {\n return false;\n }\n };\n\n\n action.transitionable = true;\n\n return action;\n}\n","import { osmRelation } from '../osm/relation';\n\n\n// `actionRestrictTurn` creates a turn restriction relation.\n//\n// `turn` must be an `osmTurn` object\n// see osm/intersection.js, pathToTurn()\n//\n// This specifies a restriction of type `restriction` when traveling from\n// `turn.from.way` toward `turn.to.way` via `turn.via.node` OR `turn.via.ways`.\n// (The action does not check that these entities form a valid intersection.)\n//\n// From, to, and via ways should be split before calling this action.\n// (old versions of the code would split the ways here, but we no longer do it)\n//\n// For testing convenience, accepts a restrictionID to assign to the new\n// relation. Normally, this will be undefined and the relation will\n// automatically be assigned a new ID.\n//\nexport function actionRestrictTurn(turn, restrictionType, restrictionID) {\n\n return function(graph) {\n var fromWay = graph.entity(turn.from.way);\n var toWay = graph.entity(turn.to.way);\n var viaNode = turn.via.node && graph.entity(turn.via.node);\n var viaWays = turn.via.ways && turn.via.ways.map(function(id) { return graph.entity(id); });\n var members = [];\n\n members.push({ id: fromWay.id, type: 'way', role: 'from' });\n\n if (viaNode) {\n members.push({ id: viaNode.id, type: 'node', role: 'via' });\n } else if (viaWays) {\n viaWays.forEach(function(viaWay) {\n members.push({ id: viaWay.id, type: 'way', role: 'via' });\n });\n }\n\n members.push({ id: toWay.id, type: 'way', role: 'to' });\n\n return graph.replace(osmRelation({\n id: restrictionID,\n tags: {\n type: 'restriction',\n restriction: restrictionType\n },\n members: members\n }));\n };\n}\n","import { actionDeleteRelation } from './delete_relation';\nimport { actionDeleteWay } from './delete_way';\n\n\nexport function actionRevert(id) {\n var action = function(graph) {\n var entity = graph.hasEntity(id),\n base = graph.base().entities[id];\n\n if (entity && !base) { // entity will be removed..\n if (entity.type === 'node') {\n graph.parentWays(entity)\n .forEach(function(parent) {\n parent = parent.removeNode(id);\n graph = graph.replace(parent);\n\n if (parent.isDegenerate()) {\n graph = actionDeleteWay(parent.id)(graph);\n }\n });\n }\n\n graph.parentRelations(entity)\n .forEach(function(parent) {\n parent = parent.removeMembersWithID(id);\n graph = graph.replace(parent);\n\n if (parent.isDegenerate()) {\n graph = actionDeleteRelation(parent.id)(graph);\n }\n });\n }\n\n return graph.revert(id);\n };\n\n return action;\n}\n","import { geoRotate } from '../geo';\nimport { utilGetAllNodes } from '../util';\n\n\nexport function actionRotate(rotateIds, pivot, angle, projection) {\n\n var action = function(graph) {\n return graph.update(function(graph) {\n utilGetAllNodes(rotateIds, graph).forEach(function(node) {\n var point = geoRotate([projection(node.loc)], angle, pivot)[0];\n graph = graph.replace(node.move(projection.invert(point)));\n });\n });\n };\n\n return action;\n}\n","import { geoGetSmallestSurroundingRectangle, geoVecDot, geoVecLength, geoVecInterp } from '../geo';\n\n\n/* Align nodes along their common axis */\nexport function actionStraightenNodes(nodeIDs, projection) {\n\n function positionAlongWay(a, o, b) {\n return geoVecDot(a, b, o) / geoVecDot(b, b, o);\n }\n\n // returns the endpoints of the long axis of symmetry of the `points` bounding rect \n function getEndpoints(points) {\n var ssr = geoGetSmallestSurroundingRectangle(points);\n\n // Choose line pq = axis of symmetry.\n // The shape's surrounding rectangle has 2 axes of symmetry.\n // Snap points to the long axis\n var p1 = [(ssr.poly[0][0] + ssr.poly[1][0]) / 2, (ssr.poly[0][1] + ssr.poly[1][1]) / 2 ];\n var q1 = [(ssr.poly[2][0] + ssr.poly[3][0]) / 2, (ssr.poly[2][1] + ssr.poly[3][1]) / 2 ];\n var p2 = [(ssr.poly[3][0] + ssr.poly[4][0]) / 2, (ssr.poly[3][1] + ssr.poly[4][1]) / 2 ];\n var q2 = [(ssr.poly[1][0] + ssr.poly[2][0]) / 2, (ssr.poly[1][1] + ssr.poly[2][1]) / 2 ];\n\n var isLong = (geoVecLength(p1, q1) > geoVecLength(p2, q2));\n if (isLong) {\n return [p1, q1];\n }\n return [p2, q2];\n }\n\n\n var action = function(graph, t) {\n if (t === null || !isFinite(t)) t = 1;\n t = Math.min(Math.max(+t, 0), 1);\n\n var nodes = nodeIDs.map(function(id) { return graph.entity(id); });\n var points = nodes.map(function(n) { return projection(n.loc); });\n var endpoints = getEndpoints(points);\n var startPoint = endpoints[0];\n var endPoint = endpoints[1];\n\n // Move points onto the line connecting the endpoints\n for (var i = 0; i < points.length; i++) {\n var node = nodes[i];\n var point = points[i];\n var u = positionAlongWay(point, startPoint, endPoint);\n var point2 = geoVecInterp(startPoint, endPoint, u);\n var loc2 = projection.invert(point2);\n graph = graph.replace(node.move(geoVecInterp(node.loc, loc2, t)));\n }\n\n return graph;\n };\n\n\n action.disabled = function(graph) {\n\n var nodes = nodeIDs.map(function(id) { return graph.entity(id); });\n var points = nodes.map(function(n) { return projection(n.loc); });\n var endpoints = getEndpoints(points);\n var startPoint = endpoints[0];\n var endPoint = endpoints[1];\n\n var maxDistance = 0;\n\n for (var i = 0; i < points.length; i++) {\n var point = points[i];\n var u = positionAlongWay(point, startPoint, endPoint);\n var p = geoVecInterp(startPoint, endPoint, u);\n var dist = geoVecLength(p, point);\n\n if (!isNaN(dist) && dist > maxDistance) {\n maxDistance = dist;\n }\n }\n\n if (maxDistance < 0.0001) {\n return 'straight_enough';\n }\n };\n\n\n action.transitionable = true;\n\n\n return action;\n}\n","import { actionDeleteNode } from './delete_node';\nimport { geoVecDot, geoVecInterp, geoVecLength } from '../geo';\nimport { utilArrayDifference } from '../util';\n\n\n/*\n * Based on https://github.com/openstreetmap/potlatch2/net/systemeD/potlatch2/tools/Straighten.as\n */\nexport function actionStraightenWay(selectedIDs, projection) {\n\n function positionAlongWay(a, o, b) {\n return geoVecDot(a, b, o) / geoVecDot(b, b, o);\n }\n\n // Return all selected ways as a continuous, ordered array of nodes\n function allNodes(graph) {\n var nodes = [];\n var startNodes = [];\n var endNodes = [];\n var remainingWays = [];\n var selectedWays = selectedIDs.filter(function(w) {\n return graph.entity(w).type === 'way';\n });\n var selectedNodes = selectedIDs.filter(function(n) {\n return graph.entity(n).type === 'node';\n });\n\n for (var i = 0; i < selectedWays.length; i++) {\n var way = graph.entity(selectedWays[i]);\n nodes = way.nodes.slice(0);\n remainingWays.push(nodes);\n startNodes.push(nodes[0]);\n endNodes.push(nodes[nodes.length-1]);\n }\n\n // Remove duplicate end/startNodes (duplicate nodes cannot be at the line end,\n // and need to be removed so currNode difference calculation below works)\n // i.e. [\"n-1\", \"n-1\", \"n-2\"] => [\"n-2\"]\n startNodes = startNodes.filter(function(n) {\n return startNodes.indexOf(n) === startNodes.lastIndexOf(n);\n });\n endNodes = endNodes.filter(function(n) {\n return endNodes.indexOf(n) === endNodes.lastIndexOf(n);\n });\n\n // Choose the initial endpoint to start from\n var currNode = utilArrayDifference(startNodes, endNodes)\n .concat(utilArrayDifference(endNodes, startNodes))[0];\n var nextWay = [];\n nodes = [];\n\n // Create nested function outside of loop to avoid \"function in loop\" lint error\n var getNextWay = function(currNode, remainingWays) {\n return remainingWays.filter(function(way) {\n return way[0] === currNode || way[way.length-1] === currNode;\n })[0];\n };\n\n // Add nodes to end of nodes array, until all ways are added\n while (remainingWays.length) {\n nextWay = getNextWay(currNode, remainingWays);\n remainingWays = utilArrayDifference(remainingWays, [nextWay]);\n\n if (nextWay[0] !== currNode) {\n nextWay.reverse();\n }\n nodes = nodes.concat(nextWay);\n currNode = nodes[nodes.length-1];\n }\n\n // If user selected 2 nodes to straighten between, then slice nodes array to those nodes\n if (selectedNodes.length === 2) {\n var startNodeIdx = nodes.indexOf(selectedNodes[0]);\n var endNodeIdx = nodes.indexOf(selectedNodes[1]);\n var sortedStartEnd = [startNodeIdx, endNodeIdx];\n\n sortedStartEnd.sort(function(a, b) { return a - b; });\n nodes = nodes.slice(sortedStartEnd[0], sortedStartEnd[1]+1);\n }\n\n return nodes.map(function(n) { return graph.entity(n); });\n }\n\n function shouldKeepNode(node, graph) {\n return graph.parentWays(node).length > 1 ||\n graph.parentRelations(node).length ||\n node.hasInterestingTags();\n }\n\n\n var action = function(graph, t) {\n if (t === null || !isFinite(t)) t = 1;\n t = Math.min(Math.max(+t, 0), 1);\n\n var nodes = allNodes(graph);\n var points = nodes.map(function(n) { return projection(n.loc); });\n var startPoint = points[0];\n var endPoint = points[points.length-1];\n var toDelete = [];\n var i;\n\n for (i = 1; i < points.length-1; i++) {\n var node = nodes[i];\n var point = points[i];\n\n if (t < 1 || shouldKeepNode(node, graph)) {\n var u = positionAlongWay(point, startPoint, endPoint);\n var p = geoVecInterp(startPoint, endPoint, u);\n var loc2 = projection.invert(p);\n graph = graph.replace(node.move(geoVecInterp(node.loc, loc2, t)));\n\n } else {\n // safe to delete\n if (toDelete.indexOf(node) === -1) {\n toDelete.push(node);\n }\n }\n }\n\n for (i = 0; i < toDelete.length; i++) {\n graph = actionDeleteNode(toDelete[i].id)(graph);\n }\n\n return graph;\n };\n\n\n action.disabled = function(graph) {\n // check way isn't too bendy\n var nodes = allNodes(graph);\n var points = nodes.map(function(n) { return projection(n.loc); });\n var startPoint = points[0];\n var endPoint = points[points.length-1];\n var threshold = 0.2 * geoVecLength(startPoint, endPoint);\n var i;\n\n if (threshold === 0) {\n return 'too_bendy';\n }\n\n var maxDistance = 0;\n\n for (i = 1; i < points.length - 1; i++) {\n var point = points[i];\n var u = positionAlongWay(point, startPoint, endPoint);\n var p = geoVecInterp(startPoint, endPoint, u);\n var dist = geoVecLength(p, point);\n\n // to bendy if point is off by 20% of total start/end distance in projected space\n if (isNaN(dist) || dist > threshold) {\n return 'too_bendy';\n } else if (dist > maxDistance) {\n maxDistance = dist;\n }\n }\n\n var keepingAllNodes = nodes.every(function(node, i) {\n return i === 0 || i === nodes.length - 1 || shouldKeepNode(node, graph);\n });\n\n if (maxDistance < 0.0001 &&\n // Allow straightening even if already straight in order to remove extraneous nodes\n keepingAllNodes) {\n return 'straight_enough';\n }\n };\n\n action.transitionable = true;\n\n\n return action;\n}\n","import { actionDeleteRelation } from './delete_relation';\n\n\n// `actionUnrestrictTurn` deletes a turn restriction relation.\n//\n// `turn` must be an `osmTurn` object with a `restrictionID` property.\n// see osm/intersection.js, pathToTurn()\n//\nexport function actionUnrestrictTurn(turn) {\n return function(graph) {\n return actionDeleteRelation(turn.restrictionID)(graph);\n };\n}\n","import { geoGetSmallestSurroundingRectangle, geoVecInterp, geoVecLength } from '../geo';\nimport { utilGetAllNodes } from '../util';\n\n\n/* Reflect the given area around its axis of symmetry */\nexport function actionReflect(reflectIds, projection) {\n var _useLongAxis = true;\n\n\n var action = function(graph, t) {\n if (t === null || !isFinite(t)) t = 1;\n t = Math.min(Math.max(+t, 0), 1);\n\n var nodes = utilGetAllNodes(reflectIds, graph);\n var points = nodes.map(function(n) { return projection(n.loc); });\n var ssr = geoGetSmallestSurroundingRectangle(points);\n\n // Choose line pq = axis of symmetry.\n // The shape's surrounding rectangle has 2 axes of symmetry.\n // Reflect across the longer axis by default.\n var p1 = [(ssr.poly[0][0] + ssr.poly[1][0]) / 2, (ssr.poly[0][1] + ssr.poly[1][1]) / 2 ];\n var q1 = [(ssr.poly[2][0] + ssr.poly[3][0]) / 2, (ssr.poly[2][1] + ssr.poly[3][1]) / 2 ];\n var p2 = [(ssr.poly[3][0] + ssr.poly[4][0]) / 2, (ssr.poly[3][1] + ssr.poly[4][1]) / 2 ];\n var q2 = [(ssr.poly[1][0] + ssr.poly[2][0]) / 2, (ssr.poly[1][1] + ssr.poly[2][1]) / 2 ];\n var p, q;\n\n var isLong = (geoVecLength(p1, q1) > geoVecLength(p2, q2));\n if ((_useLongAxis && isLong) || (!_useLongAxis && !isLong)) {\n p = p1;\n q = q1;\n } else {\n p = p2;\n q = q2;\n }\n\n // reflect c across pq\n // http://math.stackexchange.com/questions/65503/point-reflection-over-a-line\n var dx = q[0] - p[0];\n var dy = q[1] - p[1];\n var a = (dx * dx - dy * dy) / (dx * dx + dy * dy);\n var b = 2 * dx * dy / (dx * dx + dy * dy);\n for (var i = 0; i < nodes.length; i++) {\n var node = nodes[i];\n var c = projection(node.loc);\n var c2 = [\n a * (c[0] - p[0]) + b * (c[1] - p[1]) + p[0],\n b * (c[0] - p[0]) - a * (c[1] - p[1]) + p[1]\n ];\n var loc2 = projection.invert(c2);\n node = node.move(geoVecInterp(node.loc, loc2, t));\n graph = graph.replace(node);\n }\n\n return graph;\n };\n\n\n action.useLongAxis = function(val) {\n if (!arguments.length) return _useLongAxis;\n _useLongAxis = val;\n return action;\n };\n\n\n action.transitionable = true;\n\n\n return action;\n}\n","export function actionUpgradeTags(entityId, oldTags, replaceTags) {\n\n return function(graph) {\n var entity = graph.entity(entityId);\n var tags = Object.assign({}, entity.tags); // shallow copy\n var transferValue;\n var semiIndex;\n\n for (var oldTagKey in oldTags) {\n if (oldTags[oldTagKey] === '*') {\n transferValue = tags[oldTagKey];\n delete tags[oldTagKey];\n } else {\n var vals = tags[oldTagKey].split(';').filter(Boolean);\n var oldIndex = vals.indexOf(oldTags[oldTagKey]);\n if (vals.length === 1 || oldIndex === -1) {\n delete tags[oldTagKey];\n } else {\n if (replaceTags && replaceTags[oldTagKey]) {\n // replacing a value within a semicolon-delimited value, note the index\n semiIndex = oldIndex;\n }\n vals.splice(oldIndex, 1);\n tags[oldTagKey] = vals.join(';');\n }\n }\n }\n\n if (replaceTags) {\n for (var replaceKey in replaceTags) {\n var replaceValue = replaceTags[replaceKey];\n if (replaceValue === '*') {\n if (tags[replaceKey] && tags[replaceKey] !== 'no') {\n // allow any pre-existing value except `no` (troll tag)\n continue;\n } else {\n // otherwise assume `yes` is okay\n tags[replaceKey] = 'yes';\n }\n } else if (replaceValue === '$1') {\n tags[replaceKey] = transferValue;\n } else {\n if (tags[replaceKey] && oldTags[replaceKey] && semiIndex !== undefined) {\n // don't override preexisting values\n var existingVals = tags[replaceKey].split(';').filter(Boolean);\n if (existingVals.indexOf(replaceValue) === -1) {\n existingVals.splice(semiIndex, 0, replaceValue);\n tags[replaceKey] = existingVals.join(';');\n }\n } else {\n tags[replaceKey] = replaceValue;\n }\n }\n }\n }\n\n return graph.replace(entity.update({ tags: tags }));\n };\n}\n","import { geoVecInterp } from '../geo/vector';\nimport { osmNode, osmRelation, osmWay } from '../osm';\n\n\nfunction findConnectionPoint(graph, newNode, targetWay, nodeA, nodeB) {\n // Find the place to newNode on targetWay between nodeA and nodeB if it does\n // not alter the existing segment's angle much. There may be other nodes\n // between A and B from user edit or other automatic connections.\n\n var sortByLon = Math.abs(nodeA.loc[0] - nodeB.loc[0]) > Math.abs(nodeA.loc[1] - nodeB.loc[1]);\n var sortFunc = sortByLon\n ? function(n1, n2) {\n return nodeA.loc[0] < nodeB.loc[0]\n ? n1.loc[0] - n2.loc[0]\n : n2.loc[0] - n1.loc[0];\n }\n : function(n1, n2) {\n return nodeA.loc[1] < nodeB.loc[1]\n ? n1.loc[1] - n2.loc[1]\n : n2.loc[1] - n1.loc[1];\n };\n\n var nidList = targetWay.nodes;\n var idxA = nidList.indexOf(nodeA.id);\n var idxB = nidList.indexOf(nodeB.id);\n\n // Invariants for finding the insert index below: A and B must be in the\n // node list, in order, and the sort function must also order A before B\n if (idxA === -1 || idxB === -1 || idxA >= idxB || sortFunc(nodeA, nodeB) >= 0) {\n return null;\n }\n\n var insertIdx = idxA + 1; // index to insert immediately before\n while (insertIdx < idxB && sortFunc(newNode, graph.entity(nidList[insertIdx])) > 0) {\n insertIdx++;\n }\n\n // Find the interpolated point on the segment where insertion will not\n // alter the segment's angle.\n var locA = graph.entity(nidList[insertIdx - 1]).loc;\n var locB = graph.entity(nidList[insertIdx]).loc;\n var locN = newNode.loc;\n var coeff = Math.abs(locA[0] - locB[0]) > Math.abs(locA[1] - locB[1])\n ? (locN[0] - locA[0]) / (locB[0] - locA[0])\n : (locN[1] - locA[1]) / (locB[1] - locA[1]);\n var interpLoc = geoVecInterp(locA, locB, coeff);\n\n return {\n insertIdx: insertIdx,\n interpLoc: interpLoc,\n };\n}\n\n\nfunction locationChanged(loc1, loc2) {\n return Math.abs(loc1[0] - loc2[0]) > 2e-5\n || Math.abs(loc1[1] - loc2[1]) > 2e-5;\n}\n\n\nfunction removeMetadata(entity) {\n delete entity.__fbid__;\n delete entity.__origid__;\n delete entity.__service__;\n delete entity.__datasetid__;\n delete entity.tags.conn;\n delete entity.tags.dupe;\n}\n\n\nexport function actionRapidAcceptFeature(entityID, extGraph) {\n return function(graph) {\n var seenRelations = {}; // keep track of seen relations to avoid infinite recursion\n var extEntity = extGraph.entity(entityID);\n\n if (extEntity.type === 'node') {\n acceptNode(extEntity);\n } else if (extEntity.type === 'way') {\n acceptWay(extEntity);\n } else if (extEntity.type === 'relation') {\n acceptRelation(extEntity);\n }\n\n return graph;\n\n\n // These functions each accept the external entities, returning the replacement\n // NOTE - these functions will update `graph` closure variable\n\n function acceptNode(extNode) {\n // copy node before modifying\n var node = osmNode(extNode);\n node.tags = Object.assign({}, node.tags);\n removeMetadata(node);\n\n graph = graph.replace(node);\n return node;\n }\n\n\n function acceptWay(extWay) {\n // copy way before modifying\n var way = osmWay(extWay);\n way.nodes = extWay.nodes.slice();\n way.tags = Object.assign({}, way.tags);\n removeMetadata(way);\n\n var nodes = way.nodes.map(function(nodeId) {\n // copy node before modifying\n var node = osmNode(extGraph.entity(nodeId));\n node.tags = Object.assign({}, node.tags);\n\n var conn = node.tags.conn && node.tags.conn.split(',');\n var dupeId = node.tags.dupe;\n removeMetadata(node);\n\n if (dupeId && graph.hasEntity(dupeId) && !locationChanged(graph.entity(dupeId).loc, node.loc)) {\n node = graph.entity(dupeId); // keep original node with dupeId\n } else if (graph.hasEntity(node.id) && locationChanged(graph.entity(node.id).loc, node.loc)) {\n node = osmNode({ loc: node.loc }); // replace (unnecessary copy of node?)\n }\n\n if (conn && graph.hasEntity(conn[0])) {\n //conn=w316746574,n3229071295,n3229071273\n var targetWay = graph.entities[conn[0]];\n var nodeA = graph.entities[conn[1]];\n var nodeB = graph.entities[conn[2]];\n\n if (targetWay && nodeA && nodeB) {\n var result = findConnectionPoint(graph, node, targetWay, nodeA, nodeB);\n if (result && !locationChanged(result.interpLoc, node.loc)) {\n node.loc = result.interpLoc;\n graph = graph.replace(targetWay.addNode(node.id, result.insertIdx));\n }\n }\n }\n\n graph = graph.replace(node);\n return node.id;\n });\n\n way = way.update({ nodes: nodes });\n graph = graph.replace(way);\n return way;\n }\n\n\n function acceptRelation(extRelation) {\n var seen = seenRelations[extRelation.id];\n if (seen) return seen;\n\n // copy relation before modifying\n var relation = osmRelation(extRelation);\n relation.members = extRelation.members.slice();\n relation.tags = Object.assign({}, extRelation.tags);\n removeMetadata(relation);\n\n var members = relation.members.map(function(member) {\n var extEntity = extGraph.entity(member.id);\n var replacement;\n\n if (extEntity.type === 'node') {\n replacement = acceptNode(extEntity);\n } else if (extEntity.type === 'way') {\n replacement = acceptWay(extEntity);\n } else if (extEntity.type === 'relation') {\n replacement = acceptRelation(extEntity);\n }\n\n return Object.assign(member, { id: replacement.id });\n });\n\n relation = relation.update({ members: members });\n graph = graph.replace(relation);\n seenRelations[extRelation.id] = relation;\n return relation;\n }\n\n };\n}\n","export function behaviorEdit(context) {\n\n function behavior() {\n context.map()\n .minzoom(context.minEditableZoom());\n }\n\n\n behavior.off = function() {\n context.map()\n .minzoom(0);\n };\n\n return behavior;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\n\nimport {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { presetManager } from '../presets';\nimport { osmEntity, osmNote, QAItem } from '../osm';\nimport { utilKeybinding, utilRebind } from '../util';\n\n/*\n The hover behavior adds the `.hover` class on pointerover to all elements to which\n the identical datum is bound, and removes it on pointerout.\n\n The :hover pseudo-class is insufficient for iD's purposes because a datum's visual\n representation may consist of several elements scattered throughout the DOM hierarchy.\n Only one of these elements can have the :hover pseudo-class, but all of them will\n have the .hover class.\n */\nexport function behaviorHover(context) {\n var dispatch = d3_dispatch('hover');\n var _selection = d3_select(null);\n var _newNodeId = null;\n var _initialNodeID = null;\n var _altDisables;\n var _ignoreVertex;\n var _targets = [];\n\n // use pointer events on supported platforms; fallback to mouse events\n var _pointerPrefix = 'PointerEvent' in window ? 'pointer' : 'mouse';\n\n\n function keydown() {\n if (_altDisables && d3_event.keyCode === utilKeybinding.modifierCodes.alt) {\n _selection.selectAll('.hover')\n .classed('hover-suppressed', true)\n .classed('hover', false);\n\n _selection\n .classed('hover-disabled', true);\n\n dispatch.call('hover', this, null);\n }\n }\n\n\n function keyup() {\n if (_altDisables && d3_event.keyCode === utilKeybinding.modifierCodes.alt) {\n _selection.selectAll('.hover-suppressed')\n .classed('hover-suppressed', false)\n .classed('hover', true);\n\n _selection\n .classed('hover-disabled', false);\n\n dispatch.call('hover', this, _targets);\n }\n }\n\n\n function behavior(selection) {\n _selection = selection;\n\n _targets = [];\n\n if (_initialNodeID) {\n _newNodeId = _initialNodeID;\n _initialNodeID = null;\n } else {\n _newNodeId = null;\n }\n\n _selection\n .on(_pointerPrefix + 'over.hover', pointerover)\n .on(_pointerPrefix + 'out.hover', pointerout)\n // treat pointerdown as pointerover for touch devices\n .on(_pointerPrefix + 'down.hover', pointerover);\n\n d3_select(window)\n .on(_pointerPrefix + 'up.hover pointercancel.hover', pointerout, true)\n .on('keydown.hover', keydown)\n .on('keyup.hover', keyup);\n\n\n function eventTarget() {\n var datum = d3_event.target && d3_event.target.__data__;\n if (typeof datum !== 'object') return null;\n if (!(datum instanceof osmEntity) && datum.properties && (datum.properties.entity instanceof osmEntity)) {\n return datum.properties.entity;\n }\n return datum;\n }\n\n function pointerover() {\n // ignore mouse hovers with buttons pressed unless dragging\n if (context.mode().id.indexOf('drag') === -1 &&\n (!d3_event.pointerType || d3_event.pointerType === 'mouse') &&\n d3_event.buttons) return;\n\n var target = eventTarget();\n if (target && _targets.indexOf(target) === -1) {\n _targets.push(target);\n updateHover(_targets);\n }\n }\n\n function pointerout() {\n\n var target = eventTarget();\n var index = _targets.indexOf(target);\n if (index !== -1) {\n _targets.splice(index);\n updateHover(_targets);\n }\n }\n\n function allowsVertex(d) {\n return d.geometry(context.graph()) === 'vertex' || presetManager.allowsVertex(d, context.graph());\n }\n\n function modeAllowsHover(target) {\n var mode = context.mode();\n if (mode.id === 'add-point') {\n return mode.preset.matchGeometry('vertex') ||\n (target.type !== 'way' && target.geometry(context.graph()) !== 'vertex');\n }\n return true;\n }\n\n function updateHover(targets) {\n\n _selection.selectAll('.hover')\n .classed('hover', false);\n _selection.selectAll('.hover-suppressed')\n .classed('hover-suppressed', false);\n\n var mode = context.mode();\n\n if (!_newNodeId && (mode.id === 'draw-line' || mode.id === 'draw-area')) {\n var node = targets.find(function(target) {\n return target instanceof osmEntity && target.type === 'node';\n });\n _newNodeId = node && node.id;\n }\n\n targets = targets.filter(function(datum) {\n if (datum instanceof osmEntity) {\n // If drawing a way, don't hover on a node that was just placed. #3974\n return datum.id !== _newNodeId &&\n (datum.type !== 'node' || !_ignoreVertex || allowsVertex(datum)) &&\n modeAllowsHover(datum);\n }\n return true;\n });\n\n var selector = '';\n\n for (var i in targets) {\n var datum = targets[i];\n\n // What are we hovering over?\n if (datum.__fbid__) { // hovering a RapiD feature\n selector += ', .data' + datum.__fbid__;\n\n } else if (datum.__featurehash__) { // hovering custom data\n selector += ', .data' + datum.__featurehash__;\n\n } else if (datum instanceof QAItem) {\n selector += ', .' + datum.service + '.itemId-' + datum.id;\n\n } else if (datum instanceof osmNote) {\n selector += ', .note-' + datum.id;\n\n } else if (datum instanceof osmEntity) {\n selector += ', .' + datum.id;\n if (datum.type === 'relation') {\n for (var j in datum.members) {\n selector += ', .' + datum.members[j].id;\n }\n }\n }\n }\n\n var suppressed = _altDisables && d3_event && d3_event.altKey;\n\n if (selector.trim().length) {\n // remove the first comma\n selector = selector.slice(1);\n _selection.selectAll(selector)\n .classed(suppressed ? 'hover-suppressed' : 'hover', true);\n }\n\n dispatch.call('hover', this, !suppressed && targets);\n }\n }\n\n\n behavior.off = function(selection) {\n selection.selectAll('.hover')\n .classed('hover', false);\n selection.selectAll('.hover-suppressed')\n .classed('hover-suppressed', false);\n selection\n .classed('hover-disabled', false);\n\n selection\n .on(_pointerPrefix + 'over.hover', null)\n .on(_pointerPrefix + 'out.hover', null)\n .on(_pointerPrefix + 'down.hover', null);\n\n d3_select(window)\n .on(_pointerPrefix + 'up.hover pointercancel.hover', null, true)\n .on('keydown.hover', null)\n .on('keyup.hover', null);\n };\n\n\n behavior.altDisables = function(val) {\n if (!arguments.length) return _altDisables;\n _altDisables = val;\n return behavior;\n };\n\n behavior.ignoreVertex = function(val) {\n if (!arguments.length) return _ignoreVertex;\n _ignoreVertex = val;\n return behavior;\n };\n\n behavior.initialNodeID = function(nodeId) {\n _initialNodeID = nodeId;\n return behavior;\n };\n\n return utilRebind(behavior, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\n\nimport {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { presetManager } from '../presets';\nimport { behaviorEdit } from './edit';\nimport { behaviorHover } from './hover';\nimport { geoChooseEdge, geoVecLength } from '../geo';\nimport { utilFastMouse, utilKeybinding, utilRebind } from '../util';\n\nvar _disableSpace = false;\nvar _lastSpace = null;\n\n\nexport function behaviorDraw(context) {\n var dispatch = d3_dispatch(\n 'move', 'down', 'downcancel', 'click', 'clickWay', 'clickNode', 'undo', 'cancel', 'finish'\n );\n\n var keybinding = utilKeybinding('draw');\n\n var _hover = behaviorHover(context)\n .altDisables(true)\n .ignoreVertex(true)\n .on('hover', context.ui().sidebar.hover);\n var _edit = behaviorEdit(context);\n\n var _closeTolerance = 4;\n var _tolerance = 12;\n var _mouseLeave = false;\n var _lastMouse = null;\n var _lastPointerUpEvent;\n\n var _downPointer;\n\n // use pointer events on supported platforms; fallback to mouse events\n var _pointerPrefix = 'PointerEvent' in window ? 'pointer' : 'mouse';\n\n\n // related code\n // - `mode/drag_node.js` `datum()`\n function datum() {\n var mode = context.mode();\n var isNote = mode && (mode.id.indexOf('note') !== -1);\n if (d3_event.altKey || isNote) return {};\n\n var element;\n if (d3_event.type === 'keydown') {\n element = _lastMouse && _lastMouse.target;\n } else {\n element = d3_event.target;\n }\n\n // When drawing, snap only to touch targets..\n // (this excludes area fills and active drawing elements)\n var d = element.__data__;\n return (d && d.properties && d.properties.target) ? d : {};\n }\n\n function pointerdown() {\n\n if (_downPointer) return;\n\n var pointerLocGetter = utilFastMouse(this);\n _downPointer = {\n id: d3_event.pointerId || 'mouse',\n pointerLocGetter: pointerLocGetter,\n downTime: +new Date(),\n downLoc: pointerLocGetter(d3_event)\n };\n\n dispatch.call('down', this, datum());\n }\n\n function pointerup() {\n\n if (!_downPointer || _downPointer.id !== (d3_event.pointerId || 'mouse')) return;\n\n var downPointer = _downPointer;\n _downPointer = null;\n\n _lastPointerUpEvent = d3_event;\n\n if (downPointer.isCancelled) return;\n\n var t2 = +new Date();\n var p2 = downPointer.pointerLocGetter(d3_event);\n var dist = geoVecLength(downPointer.downLoc, p2);\n\n if (dist < _closeTolerance || (dist < _tolerance && (t2 - downPointer.downTime) < 500)) {\n // Prevent a quick second click\n d3_select(window).on('click.draw-block', function() {\n d3_event.stopPropagation();\n }, true);\n\n context.map().dblclickZoomEnable(false);\n\n window.setTimeout(function() {\n context.map().dblclickZoomEnable(true);\n d3_select(window).on('click.draw-block', null);\n }, 500);\n\n click(p2);\n }\n }\n\n function pointermove() {\n if (_downPointer &&\n _downPointer.id === (d3_event.pointerId || 'mouse') &&\n !_downPointer.isCancelled) {\n var p2 = _downPointer.pointerLocGetter(d3_event);\n var dist = geoVecLength(_downPointer.downLoc, p2);\n if (dist >= _closeTolerance) {\n _downPointer.isCancelled = true;\n dispatch.call('downcancel', this);\n }\n }\n\n if ((d3_event.pointerType && d3_event.pointerType !== 'mouse') ||\n d3_event.buttons ||\n _downPointer) return;\n\n // HACK: Mobile Safari likes to send one or more `mouse` type pointermove\n // events immediately after non-mouse pointerup events; detect and ignore them.\n if (_lastPointerUpEvent &&\n _lastPointerUpEvent.pointerType !== 'mouse' &&\n d3_event.timeStamp - _lastPointerUpEvent.timeStamp < 100) return;\n\n _lastMouse = d3_event;\n dispatch.call('move', this, datum());\n }\n\n function pointercancel() {\n if (_downPointer &&\n _downPointer.id === (d3_event.pointerId || 'mouse')) {\n\n if (!_downPointer.isCancelled) {\n dispatch.call('downcancel', this);\n }\n _downPointer = null;\n }\n }\n\n function mouseenter() {\n _mouseLeave = false;\n }\n\n function mouseleave() {\n _mouseLeave = true;\n }\n\n function allowsVertex(d) {\n return d.geometry(context.graph()) === 'vertex' || presetManager.allowsVertex(d, context.graph());\n }\n\n // related code\n // - `mode/drag_node.js` `doMove()`\n // - `behavior/draw.js` `click()`\n // - `behavior/draw_way.js` `move()`\n function click(loc) {\n var d = datum();\n var target = d && d.properties && d.properties.entity;\n\n var mode = context.mode();\n\n if (target && target.type === 'node' && allowsVertex(target)) { // Snap to a node\n dispatch.call('clickNode', this, target, d);\n return;\n\n } else if (target && target.type === 'way' && (mode.id !== 'add-point' || mode.preset.matchGeometry('vertex'))) { // Snap to a way\n var choice = geoChooseEdge(\n context.graph().childNodes(target), loc, context.projection, context.activeID()\n );\n if (choice) {\n var edge = [target.nodes[choice.index - 1], target.nodes[choice.index]];\n dispatch.call('clickWay', this, choice.loc, edge, d);\n return;\n }\n } else if (mode.id !== 'add-point' || mode.preset.matchGeometry('point')) {\n var locLatLng = context.projection.invert(loc);\n dispatch.call('click', this, locLatLng, d);\n }\n\n }\n\n // treat a spacebar press like a click\n function space() {\n d3_event.preventDefault();\n d3_event.stopPropagation();\n\n var currSpace = context.map().mouse();\n if (_disableSpace && _lastSpace) {\n var dist = geoVecLength(_lastSpace, currSpace);\n if (dist > _tolerance) {\n _disableSpace = false;\n }\n }\n\n if (_disableSpace || _mouseLeave || !_lastMouse) return;\n\n // user must move mouse or release space bar to allow another click\n _lastSpace = currSpace;\n _disableSpace = true;\n\n d3_select(window).on('keyup.space-block', function() {\n d3_event.preventDefault();\n d3_event.stopPropagation();\n _disableSpace = false;\n d3_select(window).on('keyup.space-block', null);\n });\n\n // get the current mouse position\n var loc = context.map().mouse() ||\n // or the map center if the mouse has never entered the map\n context.projection(context.map().center());\n click(loc);\n }\n\n\n function backspace() {\n d3_event.preventDefault();\n dispatch.call('undo');\n }\n\n\n function del() {\n d3_event.preventDefault();\n dispatch.call('cancel');\n }\n\n\n function ret() {\n d3_event.preventDefault();\n dispatch.call('finish');\n }\n\n\n function behavior(selection) {\n context.install(_hover);\n context.install(_edit);\n\n _downPointer = null;\n\n keybinding\n .on('⌫', backspace)\n .on('⌦', del)\n .on('⎋', ret)\n .on('↩', ret)\n .on('space', space)\n .on('⌥space', space);\n\n selection\n .on('mouseenter.draw', mouseenter)\n .on('mouseleave.draw', mouseleave)\n .on(_pointerPrefix + 'down.draw', pointerdown)\n .on(_pointerPrefix + 'move.draw', pointermove);\n\n d3_select(window)\n .on(_pointerPrefix + 'up.draw', pointerup, true)\n .on('pointercancel.draw', pointercancel, true);\n\n d3_select(document)\n .call(keybinding);\n\n return behavior;\n }\n\n\n behavior.off = function(selection) {\n context.ui().sidebar.hover.cancel();\n context.uninstall(_hover);\n context.uninstall(_edit);\n\n selection\n .on('mouseenter.draw', null)\n .on('mouseleave.draw', null)\n .on(_pointerPrefix + 'down.draw', null)\n .on(_pointerPrefix + 'move.draw', null);\n\n d3_select(window)\n .on(_pointerPrefix + 'up.draw', null)\n .on('pointercancel.draw', null);\n // note: keyup.space-block, click.draw-block should remain\n\n d3_select(document)\n .call(keybinding.unbind);\n };\n\n\n behavior.hover = function() {\n return _hover;\n };\n\n\n return utilRebind(behavior, dispatch, 'on');\n}\n","export function initRange(domain, range) {\n switch (arguments.length) {\n case 0: break;\n case 1: this.range(domain); break;\n default: this.range(range).domain(domain); break;\n }\n return this;\n}\n\nexport function initInterpolator(domain, interpolator) {\n switch (arguments.length) {\n case 0: break;\n case 1: this.interpolator(domain); break;\n default: this.interpolator(interpolator).domain(domain); break;\n }\n return this;\n}\n","export var prefix = \"$\";\n\nfunction Map() {}\n\nMap.prototype = map.prototype = {\n constructor: Map,\n has: function(key) {\n return (prefix + key) in this;\n },\n get: function(key) {\n return this[prefix + key];\n },\n set: function(key, value) {\n this[prefix + key] = value;\n return this;\n },\n remove: function(key) {\n var property = prefix + key;\n return property in this && delete this[property];\n },\n clear: function() {\n for (var property in this) if (property[0] === prefix) delete this[property];\n },\n keys: function() {\n var keys = [];\n for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));\n return keys;\n },\n values: function() {\n var values = [];\n for (var property in this) if (property[0] === prefix) values.push(this[property]);\n return values;\n },\n entries: function() {\n var entries = [];\n for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});\n return entries;\n },\n size: function() {\n var size = 0;\n for (var property in this) if (property[0] === prefix) ++size;\n return size;\n },\n empty: function() {\n for (var property in this) if (property[0] === prefix) return false;\n return true;\n },\n each: function(f) {\n for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);\n }\n};\n\nfunction map(object, f) {\n var map = new Map;\n\n // Copy constructor.\n if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });\n\n // Index array by numeric index or specified key function.\n else if (Array.isArray(object)) {\n var i = -1,\n n = object.length,\n o;\n\n if (f == null) while (++i < n) map.set(i, object[i]);\n else while (++i < n) map.set(f(o = object[i], i, object), o);\n }\n\n // Convert object to map.\n else if (object) for (var key in object) map.set(key, object[key]);\n\n return map;\n}\n\nexport default map;\n","import {default as map, prefix} from \"./map\";\n\nfunction Set() {}\n\nvar proto = map.prototype;\n\nSet.prototype = set.prototype = {\n constructor: Set,\n has: proto.has,\n add: function(value) {\n value += \"\";\n this[prefix + value] = value;\n return this;\n },\n remove: proto.remove,\n clear: proto.clear,\n values: proto.keys,\n size: proto.size,\n empty: proto.empty,\n each: proto.each\n};\n\nfunction set(object, f) {\n var set = new Set;\n\n // Copy constructor.\n if (object instanceof Set) object.each(function(value) { set.add(value); });\n\n // Otherwise, assume it’s an array.\n else if (object) {\n var i = -1, n = object.length;\n if (f == null) while (++i < n) set.add(object[i]);\n else while (++i < n) set.add(f(object[i], i, object));\n }\n\n return set;\n}\n\nexport default set;\n","var array = Array.prototype;\n\nexport var map = array.map;\nexport var slice = array.slice;\n","export default function(x) {\n return function() {\n return x;\n };\n}\n","export default function(x) {\n return +x;\n}\n","import {bisect} from \"d3-array\";\nimport {interpolate as interpolateValue, interpolateNumber, interpolateRound} from \"d3-interpolate\";\nimport {map, slice} from \"./array\";\nimport constant from \"./constant\";\nimport number from \"./number\";\n\nvar unit = [0, 1];\n\nexport function identity(x) {\n return x;\n}\n\nfunction normalize(a, b) {\n return (b -= (a = +a))\n ? function(x) { return (x - a) / b; }\n : constant(isNaN(b) ? NaN : 0.5);\n}\n\nfunction clamper(domain) {\n var a = domain[0], b = domain[domain.length - 1], t;\n if (a > b) t = a, a = b, b = t;\n return function(x) { return Math.max(a, Math.min(b, x)); };\n}\n\n// normalize(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].\n// interpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding range value x in [a,b].\nfunction bimap(domain, range, interpolate) {\n var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];\n if (d1 < d0) d0 = normalize(d1, d0), r0 = interpolate(r1, r0);\n else d0 = normalize(d0, d1), r0 = interpolate(r0, r1);\n return function(x) { return r0(d0(x)); };\n}\n\nfunction polymap(domain, range, interpolate) {\n var j = Math.min(domain.length, range.length) - 1,\n d = new Array(j),\n r = new Array(j),\n i = -1;\n\n // Reverse descending domains.\n if (domain[j] < domain[0]) {\n domain = domain.slice().reverse();\n range = range.slice().reverse();\n }\n\n while (++i < j) {\n d[i] = normalize(domain[i], domain[i + 1]);\n r[i] = interpolate(range[i], range[i + 1]);\n }\n\n return function(x) {\n var i = bisect(domain, x, 1, j) - 1;\n return r[i](d[i](x));\n };\n}\n\nexport function copy(source, target) {\n return target\n .domain(source.domain())\n .range(source.range())\n .interpolate(source.interpolate())\n .clamp(source.clamp())\n .unknown(source.unknown());\n}\n\nexport function transformer() {\n var domain = unit,\n range = unit,\n interpolate = interpolateValue,\n transform,\n untransform,\n unknown,\n clamp = identity,\n piecewise,\n output,\n input;\n\n function rescale() {\n piecewise = Math.min(domain.length, range.length) > 2 ? polymap : bimap;\n output = input = null;\n return scale;\n }\n\n function scale(x) {\n return isNaN(x = +x) ? unknown : (output || (output = piecewise(domain.map(transform), range, interpolate)))(transform(clamp(x)));\n }\n\n scale.invert = function(y) {\n return clamp(untransform((input || (input = piecewise(range, domain.map(transform), interpolateNumber)))(y)));\n };\n\n scale.domain = function(_) {\n return arguments.length ? (domain = map.call(_, number), clamp === identity || (clamp = clamper(domain)), rescale()) : domain.slice();\n };\n\n scale.range = function(_) {\n return arguments.length ? (range = slice.call(_), rescale()) : range.slice();\n };\n\n scale.rangeRound = function(_) {\n return range = slice.call(_), interpolate = interpolateRound, rescale();\n };\n\n scale.clamp = function(_) {\n return arguments.length ? (clamp = _ ? clamper(domain) : identity, scale) : clamp !== identity;\n };\n\n scale.interpolate = function(_) {\n return arguments.length ? (interpolate = _, rescale()) : interpolate;\n };\n\n scale.unknown = function(_) {\n return arguments.length ? (unknown = _, scale) : unknown;\n };\n\n return function(t, u) {\n transform = t, untransform = u;\n return rescale();\n };\n}\n\nexport default function continuous(transform, untransform) {\n return transformer()(transform, untransform);\n}\n","export default function(x) {\n return Math.abs(x = Math.round(x)) >= 1e21\n ? x.toLocaleString(\"en\").replace(/,/g, \"\")\n : x.toString(10);\n}\n\n// Computes the decimal coefficient and exponent of the specified number x with\n// significant digits p, where x is positive and p is in [1, 21] or undefined.\n// For example, formatDecimalParts(1.23) returns [\"123\", 0].\nexport function formatDecimalParts(x, p) {\n if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf(\"e\")) < 0) return null; // NaN, ±Infinity\n var i, coefficient = x.slice(0, i);\n\n // The string returned by toExponential either has the form \\d\\.\\d+e[-+]\\d+\n // (e.g., 1.2e+3) or the form \\de[-+]\\d+ (e.g., 1e+3).\n return [\n coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,\n +x.slice(i + 1)\n ];\n}\n","import {formatDecimalParts} from \"./formatDecimal.js\";\n\nexport default function(x) {\n return x = formatDecimalParts(Math.abs(x)), x ? x[1] : NaN;\n}\n","export default function(grouping, thousands) {\n return function(value, width) {\n var i = value.length,\n t = [],\n j = 0,\n g = grouping[0],\n length = 0;\n\n while (i > 0 && g > 0) {\n if (length + g + 1 > width) g = Math.max(1, width - length);\n t.push(value.substring(i -= g, i + g));\n if ((length += g + 1) > width) break;\n g = grouping[j = (j + 1) % grouping.length];\n }\n\n return t.reverse().join(thousands);\n };\n}\n","export default function(numerals) {\n return function(value) {\n return value.replace(/[0-9]/g, function(i) {\n return numerals[+i];\n });\n };\n}\n","// [[fill]align][sign][symbol][0][width][,][.precision][~][type]\nvar re = /^(?:(.)?([<>=^]))?([+\\-( ])?([$#])?(0)?(\\d+)?(,)?(\\.\\d+)?(~)?([a-z%])?$/i;\n\nexport default function formatSpecifier(specifier) {\n if (!(match = re.exec(specifier))) throw new Error(\"invalid format: \" + specifier);\n var match;\n return new FormatSpecifier({\n fill: match[1],\n align: match[2],\n sign: match[3],\n symbol: match[4],\n zero: match[5],\n width: match[6],\n comma: match[7],\n precision: match[8] && match[8].slice(1),\n trim: match[9],\n type: match[10]\n });\n}\n\nformatSpecifier.prototype = FormatSpecifier.prototype; // instanceof\n\nexport function FormatSpecifier(specifier) {\n this.fill = specifier.fill === undefined ? \" \" : specifier.fill + \"\";\n this.align = specifier.align === undefined ? \">\" : specifier.align + \"\";\n this.sign = specifier.sign === undefined ? \"-\" : specifier.sign + \"\";\n this.symbol = specifier.symbol === undefined ? \"\" : specifier.symbol + \"\";\n this.zero = !!specifier.zero;\n this.width = specifier.width === undefined ? undefined : +specifier.width;\n this.comma = !!specifier.comma;\n this.precision = specifier.precision === undefined ? undefined : +specifier.precision;\n this.trim = !!specifier.trim;\n this.type = specifier.type === undefined ? \"\" : specifier.type + \"\";\n}\n\nFormatSpecifier.prototype.toString = function() {\n return this.fill\n + this.align\n + this.sign\n + this.symbol\n + (this.zero ? \"0\" : \"\")\n + (this.width === undefined ? \"\" : Math.max(1, this.width | 0))\n + (this.comma ? \",\" : \"\")\n + (this.precision === undefined ? \"\" : \".\" + Math.max(0, this.precision | 0))\n + (this.trim ? \"~\" : \"\")\n + this.type;\n};\n","// Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.\nexport default function(s) {\n out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {\n switch (s[i]) {\n case \".\": i0 = i1 = i; break;\n case \"0\": if (i0 === 0) i0 = i; i1 = i; break;\n default: if (!+s[i]) break out; if (i0 > 0) i0 = 0; break;\n }\n }\n return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;\n}\n","import {formatDecimalParts} from \"./formatDecimal.js\";\n\nexport var prefixExponent;\n\nexport default function(x, p) {\n var d = formatDecimalParts(x, p);\n if (!d) return x + \"\";\n var coefficient = d[0],\n exponent = d[1],\n i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,\n n = coefficient.length;\n return i === n ? coefficient\n : i > n ? coefficient + new Array(i - n + 1).join(\"0\")\n : i > 0 ? coefficient.slice(0, i) + \".\" + coefficient.slice(i)\n : \"0.\" + new Array(1 - i).join(\"0\") + formatDecimalParts(x, Math.max(0, p + i - 1))[0]; // less than 1y!\n}\n","import {formatDecimalParts} from \"./formatDecimal.js\";\n\nexport default function(x, p) {\n var d = formatDecimalParts(x, p);\n if (!d) return x + \"\";\n var coefficient = d[0],\n exponent = d[1];\n return exponent < 0 ? \"0.\" + new Array(-exponent).join(\"0\") + coefficient\n : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + \".\" + coefficient.slice(exponent + 1)\n : coefficient + new Array(exponent - coefficient.length + 2).join(\"0\");\n}\n","import formatDecimal from \"./formatDecimal.js\";\nimport formatPrefixAuto from \"./formatPrefixAuto.js\";\nimport formatRounded from \"./formatRounded.js\";\n\nexport default {\n \"%\": function(x, p) { return (x * 100).toFixed(p); },\n \"b\": function(x) { return Math.round(x).toString(2); },\n \"c\": function(x) { return x + \"\"; },\n \"d\": formatDecimal,\n \"e\": function(x, p) { return x.toExponential(p); },\n \"f\": function(x, p) { return x.toFixed(p); },\n \"g\": function(x, p) { return x.toPrecision(p); },\n \"o\": function(x) { return Math.round(x).toString(8); },\n \"p\": function(x, p) { return formatRounded(x * 100, p); },\n \"r\": formatRounded,\n \"s\": formatPrefixAuto,\n \"X\": function(x) { return Math.round(x).toString(16).toUpperCase(); },\n \"x\": function(x) { return Math.round(x).toString(16); }\n};\n","export default function(x) {\n return x;\n}\n","import exponent from \"./exponent.js\";\nimport formatGroup from \"./formatGroup.js\";\nimport formatNumerals from \"./formatNumerals.js\";\nimport formatSpecifier from \"./formatSpecifier.js\";\nimport formatTrim from \"./formatTrim.js\";\nimport formatTypes from \"./formatTypes.js\";\nimport {prefixExponent} from \"./formatPrefixAuto.js\";\nimport identity from \"./identity.js\";\n\nvar map = Array.prototype.map,\n prefixes = [\"y\",\"z\",\"a\",\"f\",\"p\",\"n\",\"µ\",\"m\",\"\",\"k\",\"M\",\"G\",\"T\",\"P\",\"E\",\"Z\",\"Y\"];\n\nexport default function(locale) {\n var group = locale.grouping === undefined || locale.thousands === undefined ? identity : formatGroup(map.call(locale.grouping, Number), locale.thousands + \"\"),\n currencyPrefix = locale.currency === undefined ? \"\" : locale.currency[0] + \"\",\n currencySuffix = locale.currency === undefined ? \"\" : locale.currency[1] + \"\",\n decimal = locale.decimal === undefined ? \".\" : locale.decimal + \"\",\n numerals = locale.numerals === undefined ? identity : formatNumerals(map.call(locale.numerals, String)),\n percent = locale.percent === undefined ? \"%\" : locale.percent + \"\",\n minus = locale.minus === undefined ? \"-\" : locale.minus + \"\",\n nan = locale.nan === undefined ? \"NaN\" : locale.nan + \"\";\n\n function newFormat(specifier) {\n specifier = formatSpecifier(specifier);\n\n var fill = specifier.fill,\n align = specifier.align,\n sign = specifier.sign,\n symbol = specifier.symbol,\n zero = specifier.zero,\n width = specifier.width,\n comma = specifier.comma,\n precision = specifier.precision,\n trim = specifier.trim,\n type = specifier.type;\n\n // The \"n\" type is an alias for \",g\".\n if (type === \"n\") comma = true, type = \"g\";\n\n // The \"\" type, and any invalid type, is an alias for \".12~g\".\n else if (!formatTypes[type]) precision === undefined && (precision = 12), trim = true, type = \"g\";\n\n // If zero fill is specified, padding goes after sign and before digits.\n if (zero || (fill === \"0\" && align === \"=\")) zero = true, fill = \"0\", align = \"=\";\n\n // Compute the prefix and suffix.\n // For SI-prefix, the suffix is lazily computed.\n var prefix = symbol === \"$\" ? currencyPrefix : symbol === \"#\" && /[boxX]/.test(type) ? \"0\" + type.toLowerCase() : \"\",\n suffix = symbol === \"$\" ? currencySuffix : /[%p]/.test(type) ? percent : \"\";\n\n // What format function should we use?\n // Is this an integer type?\n // Can this type generate exponential notation?\n var formatType = formatTypes[type],\n maybeSuffix = /[defgprs%]/.test(type);\n\n // Set the default precision if not specified,\n // or clamp the specified precision to the supported range.\n // For significant precision, it must be in [1, 21].\n // For fixed precision, it must be in [0, 20].\n precision = precision === undefined ? 6\n : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))\n : Math.max(0, Math.min(20, precision));\n\n function format(value) {\n var valuePrefix = prefix,\n valueSuffix = suffix,\n i, n, c;\n\n if (type === \"c\") {\n valueSuffix = formatType(value) + valueSuffix;\n value = \"\";\n } else {\n value = +value;\n\n // Determine the sign. -0 is not less than 0, but 1 / -0 is!\n var valueNegative = value < 0 || 1 / value < 0;\n\n // Perform the initial formatting.\n value = isNaN(value) ? nan : formatType(Math.abs(value), precision);\n\n // Trim insignificant zeros.\n if (trim) value = formatTrim(value);\n\n // If a negative value rounds to zero after formatting, and no explicit positive sign is requested, hide the sign.\n if (valueNegative && +value === 0 && sign !== \"+\") valueNegative = false;\n\n // Compute the prefix and suffix.\n valuePrefix = (valueNegative ? (sign === \"(\" ? sign : minus) : sign === \"-\" || sign === \"(\" ? \"\" : sign) + valuePrefix;\n valueSuffix = (type === \"s\" ? prefixes[8 + prefixExponent / 3] : \"\") + valueSuffix + (valueNegative && sign === \"(\" ? \")\" : \"\");\n\n // Break the formatted value into the integer “value” part that can be\n // grouped, and fractional or exponential “suffix” part that is not.\n if (maybeSuffix) {\n i = -1, n = value.length;\n while (++i < n) {\n if (c = value.charCodeAt(i), 48 > c || c > 57) {\n valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;\n value = value.slice(0, i);\n break;\n }\n }\n }\n }\n\n // If the fill character is not \"0\", grouping is applied before padding.\n if (comma && !zero) value = group(value, Infinity);\n\n // Compute the padding.\n var length = valuePrefix.length + value.length + valueSuffix.length,\n padding = length < width ? new Array(width - length + 1).join(fill) : \"\";\n\n // If the fill character is \"0\", grouping is applied after padding.\n if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = \"\";\n\n // Reconstruct the final output based on the desired alignment.\n switch (align) {\n case \"<\": value = valuePrefix + value + valueSuffix + padding; break;\n case \"=\": value = valuePrefix + padding + value + valueSuffix; break;\n case \"^\": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;\n default: value = padding + valuePrefix + value + valueSuffix; break;\n }\n\n return numerals(value);\n }\n\n format.toString = function() {\n return specifier + \"\";\n };\n\n return format;\n }\n\n function formatPrefix(specifier, value) {\n var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = \"f\", specifier)),\n e = Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3,\n k = Math.pow(10, -e),\n prefix = prefixes[8 + e / 3];\n return function(value) {\n return f(k * value) + prefix;\n };\n }\n\n return {\n format: newFormat,\n formatPrefix: formatPrefix\n };\n}\n","import formatLocale from \"./locale.js\";\n\nvar locale;\nexport var format;\nexport var formatPrefix;\n\ndefaultLocale({\n decimal: \".\",\n thousands: \",\",\n grouping: [3],\n currency: [\"$\", \"\"],\n minus: \"-\"\n});\n\nexport default function defaultLocale(definition) {\n locale = formatLocale(definition);\n format = locale.format;\n formatPrefix = locale.formatPrefix;\n return locale;\n}\n","import exponent from \"./exponent.js\";\n\nexport default function(step) {\n return Math.max(0, -exponent(Math.abs(step)));\n}\n","import exponent from \"./exponent.js\";\n\nexport default function(step, value) {\n return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3 - exponent(Math.abs(step)));\n}\n","import exponent from \"./exponent.js\";\n\nexport default function(step, max) {\n step = Math.abs(step), max = Math.abs(max) - step;\n return Math.max(0, exponent(max) - exponent(step)) + 1;\n}\n","import {tickStep} from \"d3-array\";\nimport {format, formatPrefix, formatSpecifier, precisionFixed, precisionPrefix, precisionRound} from \"d3-format\";\n\nexport default function(start, stop, count, specifier) {\n var step = tickStep(start, stop, count),\n precision;\n specifier = formatSpecifier(specifier == null ? \",f\" : specifier);\n switch (specifier.type) {\n case \"s\": {\n var value = Math.max(Math.abs(start), Math.abs(stop));\n if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;\n return formatPrefix(specifier, value);\n }\n case \"\":\n case \"e\":\n case \"g\":\n case \"p\":\n case \"r\": {\n if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === \"e\");\n break;\n }\n case \"f\":\n case \"%\": {\n if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === \"%\") * 2;\n break;\n }\n }\n return format(specifier);\n}\n","import {ticks, tickIncrement} from \"d3-array\";\nimport continuous, {copy, identity} from \"./continuous\";\nimport {initRange} from \"./init\";\nimport tickFormat from \"./tickFormat\";\n\nexport function linearish(scale) {\n var domain = scale.domain;\n\n scale.ticks = function(count) {\n var d = domain();\n return ticks(d[0], d[d.length - 1], count == null ? 10 : count);\n };\n\n scale.tickFormat = function(count, specifier) {\n var d = domain();\n return tickFormat(d[0], d[d.length - 1], count == null ? 10 : count, specifier);\n };\n\n scale.nice = function(count) {\n if (count == null) count = 10;\n\n var d = domain(),\n i0 = 0,\n i1 = d.length - 1,\n start = d[i0],\n stop = d[i1],\n step;\n\n if (stop < start) {\n step = start, start = stop, stop = step;\n step = i0, i0 = i1, i1 = step;\n }\n\n step = tickIncrement(start, stop, count);\n\n if (step > 0) {\n start = Math.floor(start / step) * step;\n stop = Math.ceil(stop / step) * step;\n step = tickIncrement(start, stop, count);\n } else if (step < 0) {\n start = Math.ceil(start * step) / step;\n stop = Math.floor(stop * step) / step;\n step = tickIncrement(start, stop, count);\n }\n\n if (step > 0) {\n d[i0] = Math.floor(start / step) * step;\n d[i1] = Math.ceil(stop / step) * step;\n domain(d);\n } else if (step < 0) {\n d[i0] = Math.ceil(start * step) / step;\n d[i1] = Math.floor(stop * step) / step;\n domain(d);\n }\n\n return scale;\n };\n\n return scale;\n}\n\nexport default function linear() {\n var scale = continuous(identity, identity);\n\n scale.copy = function() {\n return copy(scale, linear());\n };\n\n initRange.apply(scale, arguments);\n\n return linearish(scale);\n}\n","import {bisect} from \"d3-array\";\nimport {slice} from \"./array\";\nimport {linearish} from \"./linear\";\nimport {initRange} from \"./init\";\n\nexport default function quantize() {\n var x0 = 0,\n x1 = 1,\n n = 1,\n domain = [0.5],\n range = [0, 1],\n unknown;\n\n function scale(x) {\n return x <= x ? range[bisect(domain, x, 0, n)] : unknown;\n }\n\n function rescale() {\n var i = -1;\n domain = new Array(n);\n while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);\n return scale;\n }\n\n scale.domain = function(_) {\n return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];\n };\n\n scale.range = function(_) {\n return arguments.length ? (n = (range = slice.call(_)).length - 1, rescale()) : range.slice();\n };\n\n scale.invertExtent = function(y) {\n var i = range.indexOf(y);\n return i < 0 ? [NaN, NaN]\n : i < 1 ? [x0, domain[0]]\n : i >= n ? [domain[n - 1], x1]\n : [domain[i - 1], domain[i]];\n };\n\n scale.unknown = function(_) {\n return arguments.length ? (unknown = _, scale) : scale;\n };\n\n scale.thresholds = function() {\n return domain.slice();\n };\n\n scale.copy = function() {\n return quantize()\n .domain([x0, x1])\n .range(range)\n .unknown(unknown);\n };\n\n return initRange.apply(linearish(scale), arguments);\n}\n","import deepEqual from 'fast-deep-equal';\n\nimport {\n interpolateNumber as d3_interpolateNumber,\n quantize as d3_quantize\n} from 'd3-interpolate';\n\nimport { select as d3_select } from 'd3-selection';\nimport { scaleQuantize as d3_scaleQuantize } from 'd3-scale';\nimport { timer as d3_timer } from 'd3-timer';\n\n\nexport function behaviorBreathe() {\n var duration = 800;\n var steps = 4;\n var selector = '.selected.shadow, .selected .shadow';\n var _selected = d3_select(null);\n var _classed = '';\n var _params = {};\n var _done = false;\n var _timer;\n\n\n function ratchetyInterpolator(a, b, steps, units) {\n a = parseFloat(a);\n b = parseFloat(b);\n var sample = d3_scaleQuantize()\n .domain([0, 1])\n .range(d3_quantize(d3_interpolateNumber(a, b), steps));\n\n return function(t) {\n return String(sample(t)) + (units || '');\n };\n }\n\n\n function reset(selection) {\n selection\n .style('stroke-opacity', null)\n .style('stroke-width', null)\n .style('fill-opacity', null)\n .style('r', null);\n }\n\n\n function setAnimationParams(transition, fromTo) {\n var toFrom = (fromTo === 'from' ? 'to' : 'from');\n\n transition\n .styleTween('stroke-opacity', function(d) {\n return ratchetyInterpolator(\n _params[d.id][toFrom].opacity,\n _params[d.id][fromTo].opacity,\n steps\n );\n })\n .styleTween('stroke-width', function(d) {\n return ratchetyInterpolator(\n _params[d.id][toFrom].width,\n _params[d.id][fromTo].width,\n steps,\n 'px'\n );\n })\n .styleTween('fill-opacity', function(d) {\n return ratchetyInterpolator(\n _params[d.id][toFrom].opacity,\n _params[d.id][fromTo].opacity,\n steps\n );\n })\n .styleTween('r', function(d) {\n return ratchetyInterpolator(\n _params[d.id][toFrom].width,\n _params[d.id][fromTo].width,\n steps,\n 'px'\n );\n });\n }\n\n\n function calcAnimationParams(selection) {\n selection\n .call(reset)\n .each(function(d) {\n var s = d3_select(this);\n var tag = s.node().tagName;\n var p = {'from': {}, 'to': {}};\n var opacity;\n var width;\n\n // determine base opacity and width\n if (tag === 'circle') {\n opacity = parseFloat(s.style('fill-opacity') || 0.5);\n width = parseFloat(s.style('r') || 15.5);\n } else {\n opacity = parseFloat(s.style('stroke-opacity') || 0.7);\n width = parseFloat(s.style('stroke-width') || 10);\n }\n\n // calculate from/to interpolation params..\n p.tag = tag;\n p.from.opacity = opacity * 0.6;\n p.to.opacity = opacity * 1.25;\n p.from.width = width * 0.7;\n p.to.width = width * (tag === 'circle' ? 1.5 : 1);\n _params[d.id] = p;\n });\n }\n\n\n function run(surface, fromTo) {\n var toFrom = (fromTo === 'from' ? 'to' : 'from');\n var currSelected = surface.selectAll(selector);\n var currClassed = surface.attr('class');\n\n if (_done || currSelected.empty()) {\n _selected.call(reset);\n _selected = d3_select(null);\n return;\n }\n\n if (!deepEqual(currSelected.data(), _selected.data()) || currClassed !== _classed) {\n _selected.call(reset);\n _classed = currClassed;\n _selected = currSelected.call(calcAnimationParams);\n }\n\n var didCallNextRun = false;\n\n _selected\n .transition()\n .duration(duration)\n .call(setAnimationParams, fromTo)\n .on('end', function() {\n // `end` event is called for each selected element, but we want\n // it to run only once\n if (!didCallNextRun) {\n surface.call(run, toFrom);\n didCallNextRun = true;\n }\n\n // if entity was deselected, remove breathe styling\n if (!d3_select(this).classed('selected')) {\n reset(d3_select(this));\n }\n });\n }\n\n function behavior(surface) {\n _done = false;\n _timer = d3_timer(function() {\n // wait for elements to actually become selected\n if (surface.selectAll(selector).empty()) {\n return false;\n }\n\n surface.call(run, 'from');\n _timer.stop();\n return true;\n }, 20);\n }\n\n behavior.restartIfNeeded = function(surface) {\n if (_selected.empty()) {\n surface.call(run, 'from');\n if (_timer) {\n _timer.stop();\n }\n }\n };\n\n behavior.off = function() {\n _done = true;\n if (_timer) {\n _timer.stop();\n }\n _selected\n .interrupt()\n .call(reset);\n };\n\n\n return behavior;\n}\n","import { event as d3_event } from 'd3-selection';\n\n\n/* Creates a keybinding behavior for an operation */\nexport function behaviorOperation(context) {\n var _operation;\n\n function keypress() {\n // prevent operations during low zoom selection\n if (!context.map().withinEditableZoom()) return;\n\n d3_event.preventDefault();\n var disabled = _operation.disabled();\n\n if (disabled) {\n context.ui().flash\n .duration(4000)\n .iconName('#iD-operation-' + _operation.id)\n .iconClass('operation disabled')\n .text(_operation.tooltip)();\n\n } else {\n context.ui().flash\n .duration(2000)\n .iconName('#iD-operation-' + _operation.id)\n .iconClass('operation')\n .text(_operation.annotation() || _operation.title)();\n\n if (_operation.point) _operation.point(null);\n _operation();\n }\n }\n\n\n function behavior() {\n if (_operation && _operation.available()) {\n context.keybinding()\n .on(_operation.keys, keypress);\n }\n\n return behavior;\n }\n\n\n behavior.off = function() {\n context.keybinding()\n .off(_operation.keys);\n };\n\n\n behavior.which = function (_) {\n if (!arguments.length) return _operation;\n _operation = _;\n return behavior;\n };\n\n\n return behavior;\n}\n","import { t } from '../core/localizer';\nimport { actionCircularize } from '../actions/circularize';\nimport { behaviorOperation } from '../behavior/operation';\nimport { utilGetAllNodes } from '../util';\n\n\nexport function operationCircularize(context, selectedIDs) {\n var _extent;\n var _actions = selectedIDs.map(getAction).filter(Boolean);\n var _amount = _actions.length === 1 ? 'single' : 'multiple';\n var _coords = utilGetAllNodes(selectedIDs, context.graph())\n .map(function(n) { return n.loc; });\n\n function getAction(entityID) {\n\n var entity = context.entity(entityID);\n\n if (entity.type !== 'way' || new Set(entity.nodes).size <= 1) return null;\n\n if (!_extent) {\n _extent = entity.extent(context.graph());\n } else {\n _extent = _extent.extend(entity.extent(context.graph()));\n }\n\n return actionCircularize(entityID, context.projection);\n }\n\n var operation = function() {\n if (!_actions.length) return;\n\n var combinedAction = function(graph, t) {\n _actions.forEach(function(action) {\n if (!action.disabled(graph)) {\n graph = action(graph, t);\n }\n });\n return graph;\n };\n combinedAction.transitionable = true;\n\n context.perform(combinedAction, operation.annotation());\n\n window.setTimeout(function() {\n context.validator().validate();\n }, 300); // after any transition\n };\n\n\n operation.available = function() {\n return _actions.length && selectedIDs.length === _actions.length;\n };\n\n\n // don't cache this because the visible extent could change\n operation.disabled = function() {\n if (!_actions.length) return '';\n\n var actionDisableds = _actions.map(function(action) {\n return action.disabled(context.graph());\n }).filter(Boolean);\n\n if (actionDisableds.length === _actions.length) {\n // none of the features can be circularized\n\n if (new Set(actionDisableds).size > 1) {\n return 'multiple_blockers';\n }\n return actionDisableds[0];\n } else if (_extent.percentContainedIn(context.map().extent()) < 0.8) {\n return 'too_large';\n } else if (someMissing()) {\n return 'not_downloaded';\n } else if (selectedIDs.some(context.hasHiddenConnections)) {\n return 'connected_to_hidden';\n }\n\n return false;\n\n\n function someMissing() {\n if (context.inIntro()) return false;\n var osm = context.connection();\n if (osm) {\n var missing = _coords.filter(function(loc) { return !osm.isDataLoaded(loc); });\n if (missing.length) {\n missing.forEach(function(loc) { context.loadTileAtLoc(loc); });\n return true;\n }\n }\n return false;\n }\n };\n\n\n operation.tooltip = function() {\n var disable = operation.disabled();\n return disable ?\n t('operations.circularize.' + disable + '.' + _amount) :\n t('operations.circularize.description.' + _amount);\n };\n\n\n operation.annotation = function() {\n return t('operations.circularize.annotation.' + _amount);\n };\n\n\n operation.id = 'circularize';\n operation.keys = [t('operations.circularize.key')];\n operation.title = t('operations.circularize.title');\n operation.behavior = behaviorOperation(context).which(operation);\n\n return operation;\n}\n","import { t } from '../core/localizer';\nimport { utilDetect } from '../util/detect';\n\n\n// Translate a MacOS key command into the appropriate Windows/Linux equivalent.\n// For example, ⌘Z -> Ctrl+Z\nexport var uiCmd = function (code) {\n var detected = utilDetect();\n\n if (detected.os === 'mac') {\n return code;\n }\n\n if (detected.os === 'win') {\n if (code === '⌘⇧Z') return 'Ctrl+Y';\n }\n\n var result = '',\n replacements = {\n '⌘': 'Ctrl',\n '⇧': 'Shift',\n '⌥': 'Alt',\n '⌫': 'Backspace',\n '⌦': 'Delete'\n };\n\n for (var i = 0; i < code.length; i++) {\n if (code[i] in replacements) {\n result += replacements[code[i]] + (i < code.length - 1 ? '+' : '');\n } else {\n result += code[i];\n }\n }\n\n return result;\n};\n\n\n// return a display-focused string for a given keyboard code\nuiCmd.display = function(code) {\n if (code.length !== 1) return code;\n\n var detected = utilDetect();\n var mac = (detected.os === 'mac');\n var replacements = {\n '⌘': mac ? '⌘ ' + t('shortcuts.key.cmd') : t('shortcuts.key.ctrl'),\n '⇧': mac ? '⇧ ' + t('shortcuts.key.shift') : t('shortcuts.key.shift'),\n '⌥': mac ? '⌥ ' + t('shortcuts.key.option') : t('shortcuts.key.alt'),\n '⌃': mac ? '⌃ ' + t('shortcuts.key.ctrl') : t('shortcuts.key.ctrl'),\n '⌫': mac ? '⌫ ' + t('shortcuts.key.delete') : t('shortcuts.key.backspace'),\n '⌦': mac ? '⌦ ' + t('shortcuts.key.del') : t('shortcuts.key.del'),\n '↖': mac ? '↖ ' + t('shortcuts.key.pgup') : t('shortcuts.key.pgup'),\n '↘': mac ? '↘ ' + t('shortcuts.key.pgdn') : t('shortcuts.key.pgdn'),\n '⇞': mac ? '⇞ ' + t('shortcuts.key.home') : t('shortcuts.key.home'),\n '⇟': mac ? '⇟ ' + t('shortcuts.key.end') : t('shortcuts.key.end'),\n '↵': mac ? '⏎ ' + t('shortcuts.key.return') : t('shortcuts.key.enter'),\n '⎋': mac ? '⎋ ' + t('shortcuts.key.esc') : t('shortcuts.key.esc'),\n '☰': mac ? '☰ ' + t('shortcuts.key.menu') : t('shortcuts.key.menu'),\n };\n\n return replacements[code] || code;\n};\n","import { t } from '../core/localizer';\nimport { actionDeleteMultiple } from '../actions/delete_multiple';\nimport { behaviorOperation } from '../behavior/operation';\nimport { geoSphericalDistance } from '../geo';\nimport { modeBrowse } from '../modes/browse';\nimport { modeSelect } from '../modes/select';\nimport { uiCmd } from '../ui/cmd';\nimport { utilGetAllNodes, utilTotalExtent } from '../util';\n\n\nexport function operationDelete(context, selectedIDs) {\n var multi = (selectedIDs.length === 1 ? 'single' : 'multiple');\n var action = actionDeleteMultiple(selectedIDs);\n var nodes = utilGetAllNodes(selectedIDs, context.graph());\n var coords = nodes.map(function(n) { return n.loc; });\n var extent = utilTotalExtent(selectedIDs, context.graph());\n\n\n var operation = function() {\n var nextSelectedID;\n var nextSelectedLoc;\n\n if (selectedIDs.length === 1) {\n var id = selectedIDs[0];\n var entity = context.entity(id);\n var geometry = entity.geometry(context.graph());\n var parents = context.graph().parentWays(entity);\n var parent = parents[0];\n\n // Select the next closest node in the way.\n if (geometry === 'vertex') {\n var nodes = parent.nodes;\n var i = nodes.indexOf(id);\n\n if (i === 0) {\n i++;\n } else if (i === nodes.length - 1) {\n i--;\n } else {\n var a = geoSphericalDistance(entity.loc, context.entity(nodes[i - 1]).loc);\n var b = geoSphericalDistance(entity.loc, context.entity(nodes[i + 1]).loc);\n i = a < b ? i - 1 : i + 1;\n }\n\n nextSelectedID = nodes[i];\n nextSelectedLoc = context.entity(nextSelectedID).loc;\n }\n }\n\n context.perform(action, operation.annotation());\n context.validator().validate();\n\n if (nextSelectedID && nextSelectedLoc) {\n if (context.hasEntity(nextSelectedID)) {\n context.enter(modeSelect(context, [nextSelectedID]).follow(true));\n } else {\n context.map().centerEase(nextSelectedLoc);\n context.enter(modeBrowse(context));\n }\n } else {\n context.enter(modeBrowse(context));\n }\n\n };\n\n\n operation.available = function() {\n return true;\n };\n\n\n operation.disabled = function() {\n if (extent.percentContainedIn(context.map().extent()) < 0.8) {\n return 'too_large';\n } else if (someMissing()) {\n return 'not_downloaded';\n } else if (selectedIDs.some(context.hasHiddenConnections)) {\n return 'connected_to_hidden';\n } else if (selectedIDs.some(protectedMember)) {\n return 'part_of_relation';\n } else if (selectedIDs.some(incompleteRelation)) {\n return 'incomplete_relation';\n } else if (selectedIDs.some(hasWikidataTag)) {\n return 'has_wikidata_tag';\n }\n\n return false;\n\n\n function someMissing() {\n if (context.inIntro()) return false;\n var osm = context.connection();\n if (osm) {\n var missing = coords.filter(function(loc) { return !osm.isDataLoaded(loc); });\n if (missing.length) {\n missing.forEach(function(loc) { context.loadTileAtLoc(loc); });\n return true;\n }\n }\n return false;\n }\n\n function hasWikidataTag(id) {\n var entity = context.entity(id);\n return entity.tags.wikidata && entity.tags.wikidata.trim().length > 0;\n }\n\n function incompleteRelation(id) {\n var entity = context.entity(id);\n return entity.type === 'relation' && !entity.isComplete(context.graph());\n }\n\n function protectedMember(id) {\n var entity = context.entity(id);\n if (entity.type !== 'way') return false;\n\n var parents = context.graph().parentRelations(entity);\n for (var i = 0; i < parents.length; i++) {\n var parent = parents[i];\n var type = parent.tags.type;\n var role = parent.memberById(id).role || 'outer';\n if (type === 'route' || type === 'boundary' || (type === 'multipolygon' && role === 'outer')) {\n return true;\n }\n }\n return false;\n }\n };\n\n\n operation.tooltip = function() {\n var disable = operation.disabled();\n return disable ?\n t('operations.delete.' + disable + '.' + multi) :\n t('operations.delete.description' + '.' + multi);\n };\n\n\n operation.annotation = function() {\n return selectedIDs.length === 1 ?\n t('operations.delete.annotation.' + context.graph().geometry(selectedIDs[0])) :\n t('operations.delete.annotation.multiple', { n: selectedIDs.length });\n };\n\n\n operation.id = 'delete';\n operation.keys = [uiCmd('⌘⌫'), uiCmd('⌘⌦'), uiCmd('⌦')];\n operation.title = t('operations.delete.title');\n operation.behavior = behaviorOperation(context).which(operation);\n\n return operation;\n}\n","import { t } from '../core/localizer';\nimport { actionOrthogonalize } from '../actions/orthogonalize';\nimport { behaviorOperation } from '../behavior/operation';\nimport { utilGetAllNodes } from '../util';\n\n\nexport function operationOrthogonalize(context, selectedIDs) {\n var _extent;\n var _type;\n var _actions = selectedIDs.map(chooseAction).filter(Boolean);\n var _amount = _actions.length === 1 ? 'single' : 'multiple';\n var _coords = utilGetAllNodes(selectedIDs, context.graph())\n .map(function(n) { return n.loc; });\n\n\n function chooseAction(entityID) {\n\n var entity = context.entity(entityID);\n var geometry = entity.geometry(context.graph());\n\n if (!_extent) {\n _extent = entity.extent(context.graph());\n } else {\n _extent = _extent.extend(entity.extent(context.graph()));\n }\n\n // square a line/area\n if (entity.type === 'way' && new Set(entity.nodes).size > 2 ) {\n if (_type && _type !== 'feature') return null;\n _type = 'feature';\n return actionOrthogonalize(entityID, context.projection);\n\n // square a single vertex\n } else if (geometry === 'vertex') {\n if (_type && _type !== 'corner') return null;\n _type = 'corner';\n var graph = context.graph();\n var parents = graph.parentWays(entity);\n if (parents.length === 1) {\n var way = parents[0];\n if (way.nodes.indexOf(entityID) !== -1) {\n return actionOrthogonalize(way.id, context.projection, entityID);\n }\n }\n }\n\n return null;\n }\n\n\n var operation = function() {\n if (!_actions.length) return;\n\n var combinedAction = function(graph, t) {\n _actions.forEach(function(action) {\n if (!action.disabled(graph)) {\n graph = action(graph, t);\n }\n });\n return graph;\n };\n combinedAction.transitionable = true;\n\n context.perform(combinedAction, operation.annotation());\n\n window.setTimeout(function() {\n context.validator().validate();\n }, 300); // after any transition\n };\n\n\n operation.available = function() {\n return _actions.length && selectedIDs.length === _actions.length;\n };\n\n\n // don't cache this because the visible extent could change\n operation.disabled = function() {\n if (!_actions.length) return '';\n\n var actionDisableds = _actions.map(function(action) {\n return action.disabled(context.graph());\n }).filter(Boolean);\n\n if (actionDisableds.length === _actions.length) {\n // none of the features can be squared\n\n if (new Set(actionDisableds).size > 1) {\n return 'multiple_blockers';\n }\n return actionDisableds[0];\n } else if (_extent &&\n _extent.percentContainedIn(context.map().extent()) < 0.8) {\n return 'too_large';\n } else if (someMissing()) {\n return 'not_downloaded';\n } else if (selectedIDs.some(context.hasHiddenConnections)) {\n return 'connected_to_hidden';\n }\n\n return false;\n\n\n function someMissing() {\n if (context.inIntro()) return false;\n var osm = context.connection();\n if (osm) {\n var missing = _coords.filter(function(loc) { return !osm.isDataLoaded(loc); });\n if (missing.length) {\n missing.forEach(function(loc) { context.loadTileAtLoc(loc); });\n return true;\n }\n }\n return false;\n }\n };\n\n\n operation.tooltip = function() {\n var disable = operation.disabled();\n return disable ?\n t('operations.orthogonalize.' + disable + '.' + _amount) :\n t('operations.orthogonalize.description.' + _type + '.' + _amount);\n };\n\n\n operation.annotation = function() {\n return t('operations.orthogonalize.annotation.' + _type + '.' + _amount);\n };\n\n\n operation.id = 'orthogonalize';\n operation.keys = [t('operations.orthogonalize.key')];\n operation.title = t('operations.orthogonalize.title');\n operation.behavior = behaviorOperation(context).which(operation);\n\n return operation;\n}\n","import { t } from '../core/localizer';\nimport { actionReflect } from '../actions/reflect';\nimport { behaviorOperation } from '../behavior/operation';\nimport { utilGetAllNodes, utilTotalExtent } from '../util/util';\n\n\nexport function operationReflectShort(context, selectedIDs) {\n return operationReflect(context, selectedIDs, 'short');\n}\n\n\nexport function operationReflectLong(context, selectedIDs) {\n return operationReflect(context, selectedIDs, 'long');\n}\n\n\nexport function operationReflect(context, selectedIDs, axis) {\n axis = axis || 'long';\n var multi = (selectedIDs.length === 1 ? 'single' : 'multiple');\n var nodes = utilGetAllNodes(selectedIDs, context.graph());\n var coords = nodes.map(function(n) { return n.loc; });\n var extent = utilTotalExtent(selectedIDs, context.graph());\n\n\n var operation = function() {\n var action = actionReflect(selectedIDs, context.projection)\n .useLongAxis(Boolean(axis === 'long'));\n\n context.perform(action, operation.annotation());\n\n window.setTimeout(function() {\n context.validator().validate();\n }, 300); // after any transition\n };\n\n\n operation.available = function() {\n return nodes.length >= 3;\n };\n\n\n // don't cache this because the visible extent could change\n operation.disabled = function() {\n if (extent.percentContainedIn(context.map().extent()) < 0.8) {\n return 'too_large';\n } else if (someMissing()) {\n return 'not_downloaded';\n } else if (selectedIDs.some(context.hasHiddenConnections)) {\n return 'connected_to_hidden';\n } else if (selectedIDs.some(incompleteRelation)) {\n return 'incomplete_relation';\n }\n\n return false;\n\n\n function someMissing() {\n if (context.inIntro()) return false;\n var osm = context.connection();\n if (osm) {\n var missing = coords.filter(function(loc) { return !osm.isDataLoaded(loc); });\n if (missing.length) {\n missing.forEach(function(loc) { context.loadTileAtLoc(loc); });\n return true;\n }\n }\n return false;\n }\n\n function incompleteRelation(id) {\n var entity = context.entity(id);\n return entity.type === 'relation' && !entity.isComplete(context.graph());\n }\n };\n\n\n operation.tooltip = function() {\n var disable = operation.disabled();\n return disable ?\n t('operations.reflect.' + disable + '.' + multi) :\n t('operations.reflect.description.' + axis + '.' + multi);\n };\n\n\n operation.annotation = function() {\n return t('operations.reflect.annotation.' + axis + '.' + multi);\n };\n\n\n operation.id = 'reflect-' + axis;\n operation.keys = [t('operations.reflect.key.' + axis)];\n operation.title = t('operations.reflect.title.' + axis);\n operation.behavior = behaviorOperation(context).which(operation);\n\n return operation;\n}\n","import { t } from '../core/localizer';\nimport { behaviorOperation } from '../behavior/operation';\nimport { modeMove } from '../modes/move';\nimport { utilGetAllNodes, utilTotalExtent } from '../util/util';\n\n\nexport function operationMove(context, selectedIDs) {\n var multi = (selectedIDs.length === 1 ? 'single' : 'multiple');\n var nodes = utilGetAllNodes(selectedIDs, context.graph());\n var coords = nodes.map(function(n) { return n.loc; });\n var extent = utilTotalExtent(selectedIDs, context.graph());\n\n\n var operation = function() {\n context.enter(modeMove(context, selectedIDs));\n };\n\n\n operation.available = function() {\n return selectedIDs.length > 1 ||\n context.entity(selectedIDs[0]).type !== 'node';\n };\n\n\n operation.disabled = function() {\n if (extent.percentContainedIn(context.map().extent()) < 0.8) {\n return 'too_large';\n } else if (someMissing()) {\n return 'not_downloaded';\n } else if (selectedIDs.some(context.hasHiddenConnections)) {\n return 'connected_to_hidden';\n } else if (selectedIDs.some(incompleteRelation)) {\n return 'incomplete_relation';\n }\n\n return false;\n\n\n function someMissing() {\n if (context.inIntro()) return false;\n var osm = context.connection();\n if (osm) {\n var missing = coords.filter(function(loc) { return !osm.isDataLoaded(loc); });\n if (missing.length) {\n missing.forEach(function(loc) { context.loadTileAtLoc(loc); });\n return true;\n }\n }\n return false;\n }\n\n function incompleteRelation(id) {\n var entity = context.entity(id);\n return entity.type === 'relation' && !entity.isComplete(context.graph());\n }\n };\n\n\n operation.tooltip = function() {\n var disable = operation.disabled();\n return disable ?\n t('operations.move.' + disable + '.' + multi) :\n t('operations.move.description.' + multi);\n };\n\n\n operation.annotation = function() {\n return selectedIDs.length === 1 ?\n t('operations.move.annotation.' + context.graph().geometry(selectedIDs[0])) :\n t('operations.move.annotation.multiple');\n };\n\n\n operation.id = 'move';\n operation.keys = [t('operations.move.key')];\n operation.title = t('operations.move.title');\n operation.behavior = behaviorOperation(context).which(operation);\n\n operation.mouseOnly = true;\n\n return operation;\n}\n","import {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport {\n polygonHull as d3_polygonHull,\n polygonCentroid as d3_polygonCentroid\n} from 'd3-polygon';\n\nimport { t } from '../core/localizer';\nimport { actionRotate } from '../actions/rotate';\nimport { actionNoop } from '../actions/noop';\nimport { behaviorEdit } from '../behavior/edit';\nimport { geoVecInterp } from '../geo';\nimport { modeBrowse } from './browse';\nimport { modeSelect } from './select';\n\nimport { operationCircularize } from '../operations/circularize';\nimport { operationDelete } from '../operations/delete';\nimport { operationMove } from '../operations/move';\nimport { operationOrthogonalize } from '../operations/orthogonalize';\nimport { operationReflectLong, operationReflectShort } from '../operations/reflect';\n\nimport { utilGetAllNodes, utilKeybinding } from '../util';\n\n\nexport function modeRotate(context, entityIDs) {\n var mode = {\n id: 'rotate',\n button: 'browse'\n };\n\n var keybinding = utilKeybinding('rotate');\n var behaviors = [\n behaviorEdit(context),\n operationCircularize(context, entityIDs).behavior,\n operationDelete(context, entityIDs).behavior,\n operationMove(context, entityIDs).behavior,\n operationOrthogonalize(context, entityIDs).behavior,\n operationReflectLong(context, entityIDs).behavior,\n operationReflectShort(context, entityIDs).behavior\n ];\n var annotation = entityIDs.length === 1 ?\n t('operations.rotate.annotation.' + context.graph().geometry(entityIDs[0])) :\n t('operations.rotate.annotation.multiple');\n\n var _prevGraph;\n var _prevAngle;\n var _prevTransform;\n var _pivot;\n\n\n function doRotate() {\n var fn;\n if (context.graph() !== _prevGraph) {\n fn = context.perform;\n } else {\n fn = context.replace;\n }\n\n // projection changed, recalculate _pivot\n var projection = context.projection;\n var currTransform = projection.transform();\n if (!_prevTransform ||\n currTransform.k !== _prevTransform.k ||\n currTransform.x !== _prevTransform.x ||\n currTransform.y !== _prevTransform.y) {\n\n var nodes = utilGetAllNodes(entityIDs, context.graph());\n var points = nodes.map(function(n) { return projection(n.loc); });\n _pivot = getPivot(points);\n _prevAngle = undefined;\n }\n\n\n var currMouse = context.map().mouse();\n var currAngle = Math.atan2(currMouse[1] - _pivot[1], currMouse[0] - _pivot[0]);\n\n if (typeof _prevAngle === 'undefined') _prevAngle = currAngle;\n var delta = currAngle - _prevAngle;\n\n fn(actionRotate(entityIDs, _pivot, delta, projection));\n\n _prevTransform = currTransform;\n _prevAngle = currAngle;\n _prevGraph = context.graph();\n }\n\n function getPivot(points) {\n var _pivot;\n if (points.length === 1) {\n _pivot = points[0];\n } else if (points.length === 2) {\n _pivot = geoVecInterp(points[0], points[1], 0.5);\n } else {\n var polygonHull = d3_polygonHull(points);\n if (polygonHull.length === 2) {\n _pivot = geoVecInterp(points[0], points[1], 0.5);\n } else {\n _pivot = d3_polygonCentroid(d3_polygonHull(points));\n }\n }\n return _pivot;\n }\n\n\n function finish() {\n d3_event.stopPropagation();\n context.replace(actionNoop(), annotation);\n context.enter(modeSelect(context, entityIDs));\n }\n\n\n function cancel() {\n context.pop();\n context.enter(modeSelect(context, entityIDs));\n }\n\n\n function undone() {\n context.enter(modeBrowse(context));\n }\n\n\n mode.enter = function() {\n context.features().forceVisible(entityIDs);\n\n behaviors.forEach(context.install);\n\n context.surface()\n .on('mousemove.rotate', doRotate)\n .on('click.rotate', finish);\n\n context.history()\n .on('undone.rotate', undone);\n\n keybinding\n .on('⎋', cancel)\n .on('↩', finish);\n\n d3_select(document)\n .call(keybinding);\n };\n\n\n mode.exit = function() {\n behaviors.forEach(context.uninstall);\n\n context.surface()\n .on('mousemove.rotate', null)\n .on('click.rotate', null);\n\n context.history()\n .on('undone.rotate', null);\n\n d3_select(document)\n .call(keybinding.unbind);\n\n context.features().forceVisible([]);\n };\n\n\n mode.selectedIDs = function() {\n if (!arguments.length) return entityIDs;\n // no assign\n return mode;\n };\n\n\n return mode;\n}\n","import { t } from '../core/localizer';\nimport { behaviorOperation } from '../behavior/operation';\nimport { modeRotate } from '../modes/rotate';\nimport { utilGetAllNodes, utilTotalExtent } from '../util/util';\n\n\nexport function operationRotate(context, selectedIDs) {\n var multi = (selectedIDs.length === 1 ? 'single' : 'multiple');\n var nodes = utilGetAllNodes(selectedIDs, context.graph());\n var coords = nodes.map(function(n) { return n.loc; });\n var extent = utilTotalExtent(selectedIDs, context.graph());\n\n\n var operation = function() {\n context.enter(modeRotate(context, selectedIDs));\n };\n\n\n operation.available = function() {\n return nodes.length >= 2;\n };\n\n\n operation.disabled = function() {\n\n if (extent.percentContainedIn(context.map().extent()) < 0.8) {\n return 'too_large';\n } else if (someMissing()) {\n return 'not_downloaded';\n } else if (selectedIDs.some(context.hasHiddenConnections)) {\n return 'connected_to_hidden';\n } else if (selectedIDs.some(incompleteRelation)) {\n return 'incomplete_relation';\n }\n\n return false;\n\n\n function someMissing() {\n if (context.inIntro()) return false;\n var osm = context.connection();\n if (osm) {\n var missing = coords.filter(function(loc) { return !osm.isDataLoaded(loc); });\n if (missing.length) {\n missing.forEach(function(loc) { context.loadTileAtLoc(loc); });\n return true;\n }\n }\n return false;\n }\n\n function incompleteRelation(id) {\n var entity = context.entity(id);\n return entity.type === 'relation' && !entity.isComplete(context.graph());\n }\n };\n\n\n operation.tooltip = function() {\n var disable = operation.disabled();\n return disable ?\n t('operations.rotate.' + disable + '.' + multi) :\n t('operations.rotate.description.' + multi);\n };\n\n\n operation.annotation = function() {\n return selectedIDs.length === 1 ?\n t('operations.rotate.annotation.' + context.graph().geometry(selectedIDs[0])) :\n t('operations.rotate.annotation.multiple');\n };\n\n\n operation.id = 'rotate';\n operation.keys = [t('operations.rotate.key')];\n operation.title = t('operations.rotate.title');\n operation.behavior = behaviorOperation(context).which(operation);\n\n operation.mouseOnly = true;\n\n return operation;\n}\n","import {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { t } from '../core/localizer';\n\nimport { actionMove } from '../actions/move';\nimport { actionNoop } from '../actions/noop';\nimport { behaviorEdit } from '../behavior/edit';\nimport { geoViewportEdge, geoVecSubtract } from '../geo';\nimport { modeBrowse } from './browse';\nimport { modeSelect } from './select';\nimport { utilKeybinding } from '../util';\n\n\nimport { operationCircularize } from '../operations/circularize';\nimport { operationDelete } from '../operations/delete';\nimport { operationOrthogonalize } from '../operations/orthogonalize';\nimport { operationReflectLong, operationReflectShort } from '../operations/reflect';\nimport { operationRotate } from '../operations/rotate';\n\n\nexport function modeMove(context, entityIDs, baseGraph) {\n var mode = {\n id: 'move',\n button: 'browse'\n };\n\n var keybinding = utilKeybinding('move');\n var behaviors = [\n behaviorEdit(context),\n operationCircularize(context, entityIDs).behavior,\n operationDelete(context, entityIDs).behavior,\n operationOrthogonalize(context, entityIDs).behavior,\n operationReflectLong(context, entityIDs).behavior,\n operationReflectShort(context, entityIDs).behavior,\n operationRotate(context, entityIDs).behavior\n ];\n var annotation = entityIDs.length === 1 ?\n t('operations.move.annotation.' + context.graph().geometry(entityIDs[0])) :\n t('operations.move.annotation.multiple');\n\n var _prevGraph;\n var _cache;\n var _origin;\n var _nudgeInterval;\n\n\n function doMove(nudge) {\n nudge = nudge || [0, 0];\n\n var fn;\n if (_prevGraph !== context.graph()) {\n _cache = {};\n _origin = context.map().mouseCoordinates();\n fn = context.perform;\n } else {\n fn = context.overwrite;\n }\n\n var currMouse = context.map().mouse();\n var origMouse = context.projection(_origin);\n var delta = geoVecSubtract(geoVecSubtract(currMouse, origMouse), nudge);\n\n fn(actionMove(entityIDs, delta, context.projection, _cache));\n _prevGraph = context.graph();\n }\n\n\n function startNudge(nudge) {\n if (_nudgeInterval) window.clearInterval(_nudgeInterval);\n _nudgeInterval = window.setInterval(function() {\n context.map().pan(nudge);\n doMove(nudge);\n }, 50);\n }\n\n\n function stopNudge() {\n if (_nudgeInterval) {\n window.clearInterval(_nudgeInterval);\n _nudgeInterval = null;\n }\n }\n\n\n function move() {\n doMove();\n var nudge = geoViewportEdge(context.map().mouse(), context.map().dimensions());\n if (nudge) {\n startNudge(nudge);\n } else {\n stopNudge();\n }\n }\n\n\n function finish() {\n d3_event.stopPropagation();\n context.replace(actionNoop(), annotation);\n context.enter(modeSelect(context, entityIDs));\n stopNudge();\n }\n\n\n function cancel() {\n if (baseGraph) {\n while (context.graph() !== baseGraph) context.pop();\n context.enter(modeBrowse(context));\n } else {\n context.pop();\n context.enter(modeSelect(context, entityIDs));\n }\n stopNudge();\n }\n\n\n function undone() {\n context.enter(modeBrowse(context));\n }\n\n\n mode.enter = function() {\n _origin = context.map().mouseCoordinates();\n _prevGraph = null;\n _cache = {};\n\n context.features().forceVisible(entityIDs);\n\n behaviors.forEach(context.install);\n\n context.surface()\n .on('mousemove.move', move)\n .on('click.move', finish);\n\n context.history()\n .on('undone.move', undone);\n\n keybinding\n .on('⎋', cancel)\n .on('↩', finish);\n\n d3_select(document)\n .call(keybinding);\n };\n\n\n mode.exit = function() {\n stopNudge();\n\n behaviors.forEach(function(behavior) {\n context.uninstall(behavior);\n });\n\n context.surface()\n .on('mousemove.move', null)\n .on('click.move', null);\n\n context.history()\n .on('undone.move', null);\n\n d3_select(document)\n .call(keybinding.unbind);\n\n context.features().forceVisible([]);\n };\n\n\n mode.selectedIDs = function() {\n if (!arguments.length) return entityIDs;\n // no assign\n return mode;\n };\n\n\n return mode;\n}\n","import { event as d3_event } from 'd3-selection';\n\nimport { actionCopyEntities } from '../actions/copy_entities';\nimport { actionMove } from '../actions/move';\nimport { geoExtent, geoPointInPolygon, geoVecSubtract } from '../geo';\nimport { modeMove } from '../modes/move';\nimport { uiCmd } from '../ui/cmd';\n\n// see also `operationPaste`\nexport function behaviorPaste(context) {\n\n function doPaste() {\n // prevent paste during low zoom selection\n if (!context.map().withinEditableZoom()) return;\n\n d3_event.preventDefault();\n\n var baseGraph = context.graph();\n var mouse = context.map().mouse();\n var projection = context.projection;\n var viewport = geoExtent(projection.clipExtent()).polygon();\n\n if (!geoPointInPolygon(mouse, viewport)) return;\n\n var oldIDs = context.copyIDs();\n if (!oldIDs.length) return;\n\n var extent = geoExtent();\n var oldGraph = context.copyGraph();\n var newIDs = [];\n\n var action = actionCopyEntities(oldIDs, oldGraph);\n context.perform(action);\n\n var copies = action.copies();\n var originals = new Set();\n Object.values(copies).forEach(function(entity) { originals.add(entity.id); });\n\n for (var id in copies) {\n var oldEntity = oldGraph.entity(id);\n var newEntity = copies[id];\n\n extent._extend(oldEntity.extent(oldGraph));\n\n // Exclude child nodes from newIDs if their parent way was also copied.\n var parents = context.graph().parentWays(newEntity);\n var parentCopied = parents.some(function(parent) {\n return originals.has(parent.id);\n });\n\n if (!parentCopied) {\n newIDs.push(newEntity.id);\n }\n }\n\n // Put pasted objects where mouse pointer is..\n var copyPoint = (context.copyLonLat() && projection(context.copyLonLat())) || projection(extent.center());\n var delta = geoVecSubtract(mouse, copyPoint);\n\n context.perform(actionMove(newIDs, delta, projection));\n context.enter(modeMove(context, newIDs, baseGraph));\n }\n\n\n function behavior() {\n context.keybinding().on(uiCmd('⌘V'), doPaste);\n return behavior;\n }\n\n\n behavior.off = function() {\n context.keybinding().off(uiCmd('⌘V'));\n };\n\n\n return behavior;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\n\nimport {\n customEvent as d3_customEvent,\n event as d3_event,\n select as d3_select,\n selection as d3_selection\n} from 'd3-selection';\n\nimport { geoVecLength } from '../geo';\nimport { osmNote } from '../osm';\nimport { utilRebind } from '../util/rebind';\nimport { utilFastMouse, utilPrefixCSSProperty, utilPrefixDOMProperty } from '../util';\n\n\n/*\n `behaviorDrag` is like `d3_behavior.drag`, with the following differences:\n\n * The `origin` function is expected to return an [x, y] tuple rather than an\n {x, y} object.\n * The events are `start`, `move`, and `end`.\n (https://github.com/mbostock/d3/issues/563)\n * The `start` event is not dispatched until the first cursor movement occurs.\n (https://github.com/mbostock/d3/pull/368)\n * The `move` event has a `point` and `delta` [x, y] tuple properties rather\n than `x`, `y`, `dx`, and `dy` properties.\n * The `end` event is not dispatched if no movement occurs.\n * An `off` function is available that unbinds the drag's internal event handlers.\n */\n\nexport function behaviorDrag() {\n var dispatch = d3_dispatch('start', 'move', 'end');\n\n // see also behaviorSelect\n var _tolerancePx = 1; // keep this low to facilitate pixel-perfect micromapping\n var _penTolerancePx = 4; // styluses can be touchy so require greater movement - #1981\n\n var _origin = null;\n var _selector = '';\n var _event;\n var _target;\n var _surface;\n var _pointerId;\n\n // use pointer events on supported platforms; fallback to mouse events\n var _pointerPrefix = 'PointerEvent' in window ? 'pointer' : 'mouse';\n\n var d3_event_userSelectProperty = utilPrefixCSSProperty('UserSelect');\n var d3_event_userSelectSuppress = function() {\n var selection = d3_selection();\n var select = selection.style(d3_event_userSelectProperty);\n selection.style(d3_event_userSelectProperty, 'none');\n return function() {\n selection.style(d3_event_userSelectProperty, select);\n };\n };\n\n\n function eventOf(thiz, argumentz) {\n return function(e1) {\n e1.target = behavior;\n d3_customEvent(e1, dispatch.apply, dispatch, [e1.type, thiz, argumentz]);\n };\n }\n\n\n function pointerdown() {\n\n if (_pointerId) return;\n\n _pointerId = d3_event.pointerId || 'mouse';\n\n _target = this;\n _event = eventOf(_target, arguments);\n\n // only force reflow once per drag\n var pointerLocGetter = utilFastMouse(_surface || _target.parentNode);\n\n var offset;\n var startOrigin = pointerLocGetter(d3_event);\n var started = false;\n var selectEnable = d3_event_userSelectSuppress();\n\n d3_select(window)\n .on(_pointerPrefix + 'move.drag', pointermove)\n .on(_pointerPrefix + 'up.drag pointercancel.drag', pointerup, true);\n\n if (_origin) {\n offset = _origin.apply(_target, arguments);\n offset = [offset[0] - startOrigin[0], offset[1] - startOrigin[1]];\n } else {\n offset = [0, 0];\n }\n\n d3_event.stopPropagation();\n\n\n function pointermove() {\n if (_pointerId !== (d3_event.pointerId || 'mouse')) return;\n\n var p = pointerLocGetter(d3_event);\n\n if (!started) {\n var dist = geoVecLength(startOrigin, p);\n var tolerance = d3_event.pointerType === 'pen' ? _penTolerancePx : _tolerancePx;\n // don't start until the drag has actually moved somewhat\n if (dist < tolerance) return;\n\n started = true;\n _event({ type: 'start' });\n\n // Don't send a `move` event in the same cycle as `start` since dragging\n // a midpoint will convert the target to a node.\n } else {\n\n startOrigin = p;\n d3_event.stopPropagation();\n d3_event.preventDefault();\n\n var dx = p[0] - startOrigin[0];\n var dy = p[1] - startOrigin[1];\n _event({\n type: 'move',\n point: [p[0] + offset[0], p[1] + offset[1]],\n delta: [dx, dy]\n });\n }\n }\n\n\n function pointerup() {\n if (_pointerId !== (d3_event.pointerId || 'mouse')) return;\n\n _pointerId = null;\n\n if (started) {\n _event({ type: 'end' });\n\n d3_event.preventDefault();\n }\n\n d3_select(window)\n .on(_pointerPrefix + 'move.drag', null)\n .on(_pointerPrefix + 'up.drag pointercancel.drag', null);\n\n selectEnable();\n }\n }\n\n\n function behavior(selection) {\n _pointerId = null;\n var matchesSelector = utilPrefixDOMProperty('matchesSelector');\n var delegate = pointerdown;\n\n if (_selector) {\n delegate = function() {\n var root = this;\n var target = d3_event.target;\n for (; target && target !== root; target = target.parentNode) {\n var datum = target.__data__;\n\n var entity = datum instanceof osmNote ? datum\n : datum && datum.properties && datum.properties.entity;\n\n if (entity && target[matchesSelector](_selector)) {\n return pointerdown.call(target, entity);\n }\n }\n };\n }\n\n selection\n .on(_pointerPrefix + 'down.drag' + _selector, delegate);\n }\n\n\n behavior.off = function(selection) {\n selection\n .on(_pointerPrefix + 'down.drag' + _selector, null);\n };\n\n\n behavior.selector = function(_) {\n if (!arguments.length) return _selector;\n _selector = _;\n return behavior;\n };\n\n\n behavior.origin = function(_) {\n if (!arguments.length) return _origin;\n _origin = _;\n return behavior;\n };\n\n\n behavior.cancel = function() {\n d3_select(window)\n .on(_pointerPrefix + 'move.drag', null)\n .on(_pointerPrefix + 'up.drag pointercancel.drag', null);\n return behavior;\n };\n\n\n behavior.target = function() {\n if (!arguments.length) return _target;\n _target = arguments[0];\n _event = eventOf(_target, Array.prototype.slice.call(arguments, 1));\n return behavior;\n };\n\n\n behavior.surface = function() {\n if (!arguments.length) return _surface;\n _surface = arguments[0];\n return behavior;\n };\n\n\n return utilRebind(behavior, dispatch, 'on');\n}\n","import {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { presetManager } from '../presets';\nimport { t } from '../core/localizer';\n\nimport { actionAddMidpoint } from '../actions/add_midpoint';\nimport { actionConnect } from '../actions/connect';\nimport { actionMoveNode } from '../actions/move_node';\nimport { actionNoop } from '../actions/noop';\n\nimport { behaviorDrag } from '../behavior/drag';\nimport { behaviorEdit } from '../behavior/edit';\nimport { behaviorHover } from '../behavior/hover';\n\nimport {\n geoChooseEdge,\n geoHasLineIntersections,\n geoHasSelfIntersections,\n geoVecSubtract,\n geoViewportEdge\n} from '../geo';\n\nimport { modeBrowse } from './browse';\nimport { modeSelect } from './select';\nimport { osmJoinWays, osmNode } from '../osm';\nimport { utilArrayIntersection, utilKeybinding } from '../util';\n\n\n\nexport function modeDragNode(context) {\n var mode = {\n id: 'drag-node',\n button: 'browse'\n };\n var hover = behaviorHover(context).altDisables(true)\n .on('hover', context.ui().sidebar.hover);\n var edit = behaviorEdit(context);\n\n var _nudgeInterval;\n var _restoreSelectedIDs = [];\n var _wasMidpoint = false;\n var _isCancelled = false;\n var _activeEntity;\n var _startLoc;\n var _lastLoc;\n\n\n function startNudge(entity, nudge) {\n if (_nudgeInterval) window.clearInterval(_nudgeInterval);\n _nudgeInterval = window.setInterval(function() {\n context.map().pan(nudge);\n doMove(entity, nudge);\n }, 50);\n }\n\n\n function stopNudge() {\n if (_nudgeInterval) {\n window.clearInterval(_nudgeInterval);\n _nudgeInterval = null;\n }\n }\n\n\n function moveAnnotation(entity) {\n return t('operations.move.annotation.' + entity.geometry(context.graph()));\n }\n\n\n function connectAnnotation(nodeEntity, targetEntity) {\n var nodeGeometry = nodeEntity.geometry(context.graph());\n var targetGeometry = targetEntity.geometry(context.graph());\n if (nodeGeometry === 'vertex' && targetGeometry === 'vertex') {\n var nodeParentWayIDs = context.graph().parentWays(nodeEntity);\n var targetParentWayIDs = context.graph().parentWays(targetEntity);\n var sharedParentWays = utilArrayIntersection(nodeParentWayIDs, targetParentWayIDs);\n // if both vertices are part of the same way\n if (sharedParentWays.length !== 0) {\n // if the nodes are next to each other, they are merged\n if (sharedParentWays[0].areAdjacent(nodeEntity.id, targetEntity.id)) {\n return t('operations.connect.annotation.from_vertex.to_adjacent_vertex');\n }\n return t('operations.connect.annotation.from_vertex.to_sibling_vertex');\n }\n }\n return t('operations.connect.annotation.from_' + nodeGeometry + '.to_' + targetGeometry);\n }\n\n\n function shouldSnapToNode(target) {\n if (!_activeEntity) return false;\n return _activeEntity.geometry(context.graph()) !== 'vertex' ||\n (target.geometry(context.graph()) === 'vertex' || presetManager.allowsVertex(target, context.graph()));\n }\n\n\n function origin(entity) {\n return context.projection(entity.loc);\n }\n\n\n function keydown() {\n if (d3_event.keyCode === utilKeybinding.modifierCodes.alt) {\n if (context.surface().classed('nope')) {\n context.surface()\n .classed('nope-suppressed', true);\n }\n context.surface()\n .classed('nope', false)\n .classed('nope-disabled', true);\n }\n }\n\n\n function keyup() {\n if (d3_event.keyCode === utilKeybinding.modifierCodes.alt) {\n if (context.surface().classed('nope-suppressed')) {\n context.surface()\n .classed('nope', true);\n }\n context.surface()\n .classed('nope-suppressed', false)\n .classed('nope-disabled', false);\n }\n }\n\n\n function start(entity) {\n _wasMidpoint = entity.type === 'midpoint';\n var hasHidden = context.features().hasHiddenConnections(entity, context.graph());\n _isCancelled = !context.editable() || d3_event.sourceEvent.shiftKey || hasHidden;\n\n\n if (_isCancelled) {\n if (hasHidden) {\n context.ui().flash\n .duration(4000)\n .text(t('modes.drag_node.connected_to_hidden'))();\n }\n return drag.cancel();\n }\n\n if (_wasMidpoint) {\n var midpoint = entity;\n entity = osmNode();\n context.perform(actionAddMidpoint(midpoint, entity));\n entity = context.entity(entity.id); // get post-action entity\n\n var vertex = context.surface().selectAll('.' + entity.id);\n drag.target(vertex.node(), entity);\n\n } else {\n context.perform(actionNoop());\n }\n\n _activeEntity = entity;\n _startLoc = entity.loc;\n\n hover.ignoreVertex(entity.geometry(context.graph()) === 'vertex');\n\n context.surface().selectAll('.' + _activeEntity.id)\n .classed('active', true);\n\n context.enter(mode);\n }\n\n\n // related code\n // - `behavior/draw.js` `datum()`\n function datum() {\n var event = d3_event && d3_event.sourceEvent;\n if (!event || event.altKey) {\n return {};\n } else {\n // When dragging, snap only to touch targets..\n // (this excludes area fills and active drawing elements)\n var d = event.target.__data__;\n return (d && d.properties && d.properties.target) ? d : {};\n }\n }\n\n\n function doMove(entity, nudge) {\n nudge = nudge || [0, 0];\n\n var currPoint = (d3_event && d3_event.point) || context.projection(_lastLoc);\n var currMouse = geoVecSubtract(currPoint, nudge);\n var loc = context.projection.invert(currMouse);\n\n if (!_nudgeInterval) { // If not nudging at the edge of the viewport, try to snap..\n // related code\n // - `mode/drag_node.js` `doMove()`\n // - `behavior/draw.js` `click()`\n // - `behavior/draw_way.js` `move()`\n var d = datum();\n var target = d && d.properties && d.properties.entity;\n var targetLoc = target && target.loc;\n var targetNodes = d && d.properties && d.properties.nodes;\n var edge;\n\n if (targetLoc) { // snap to node/vertex - a point target with `.loc`\n if (shouldSnapToNode(target)) {\n loc = targetLoc;\n }\n\n } else if (targetNodes) { // snap to way - a line target with `.nodes`\n edge = geoChooseEdge(targetNodes, context.map().mouse(), context.projection, end.id);\n if (edge) {\n loc = edge.loc;\n }\n }\n }\n\n context.replace(\n actionMoveNode(entity.id, loc)\n );\n\n // Below here: validations\n var isInvalid = false;\n\n // Check if this connection to `target` could cause relations to break..\n if (target) {\n isInvalid = hasRelationConflict(entity, target, edge, context.graph());\n }\n\n // Check if this drag causes the geometry to break..\n if (!isInvalid) {\n isInvalid = hasInvalidGeometry(entity, context.graph());\n }\n\n\n var nope = context.surface().classed('nope');\n if (isInvalid === 'relation' || isInvalid === 'restriction') {\n if (!nope) { // about to nope - show hint\n context.ui().flash\n .duration(4000)\n .text(t('operations.connect.' + isInvalid,\n { relation: presetManager.item('type/restriction').name() }\n ))();\n }\n } else if (isInvalid) {\n var errorID = isInvalid === 'line' ? 'lines' : 'areas';\n context.ui().flash\n .duration(3000)\n .text(t('self_intersection.error.' + errorID))();\n } else {\n if (nope) { // about to un-nope, remove hint\n context.ui().flash\n .duration(1)\n .text('')();\n }\n }\n\n\n var nopeDisabled = context.surface().classed('nope-disabled');\n if (nopeDisabled) {\n context.surface()\n .classed('nope', false)\n .classed('nope-suppressed', isInvalid);\n } else {\n context.surface()\n .classed('nope', isInvalid)\n .classed('nope-suppressed', false);\n }\n\n _lastLoc = loc;\n }\n\n\n // Uses `actionConnect.disabled()` to know whether this connection is ok..\n function hasRelationConflict(entity, target, edge, graph) {\n var testGraph = graph.update(); // copy\n\n // if snapping to way - add midpoint there and consider that the target..\n if (edge) {\n var midpoint = osmNode();\n var action = actionAddMidpoint({\n loc: edge.loc,\n edge: [target.nodes[edge.index - 1], target.nodes[edge.index]]\n }, midpoint);\n\n testGraph = action(testGraph);\n target = midpoint;\n }\n\n // can we connect to it?\n var ids = [entity.id, target.id];\n return actionConnect(ids).disabled(testGraph);\n }\n\n\n function hasInvalidGeometry(entity, graph) {\n var parents = graph.parentWays(entity);\n var i, j, k;\n\n for (i = 0; i < parents.length; i++) {\n var parent = parents[i];\n var nodes = [];\n var activeIndex = null; // which multipolygon ring contains node being dragged\n\n // test any parent multipolygons for valid geometry\n var relations = graph.parentRelations(parent);\n for (j = 0; j < relations.length; j++) {\n if (!relations[j].isMultipolygon()) continue;\n\n var rings = osmJoinWays(relations[j].members, graph);\n\n // find active ring and test it for self intersections\n for (k = 0; k < rings.length; k++) {\n nodes = rings[k].nodes;\n if (nodes.find(function(n) { return n.id === entity.id; })) {\n activeIndex = k;\n if (geoHasSelfIntersections(nodes, entity.id)) {\n return 'multipolygonMember';\n }\n }\n rings[k].coords = nodes.map(function(n) { return n.loc; });\n }\n\n // test active ring for intersections with other rings in the multipolygon\n for (k = 0; k < rings.length; k++) {\n if (k === activeIndex) continue;\n\n // make sure active ring doesnt cross passive rings\n if (geoHasLineIntersections(rings[activeIndex].nodes, rings[k].nodes, entity.id)) {\n return 'multipolygonRing';\n }\n }\n }\n\n\n // If we still haven't tested this node's parent way for self-intersections.\n // (because it's not a member of a multipolygon), test it now.\n if (activeIndex === null) {\n nodes = parent.nodes.map(function(nodeID) { return graph.entity(nodeID); });\n if (nodes.length && geoHasSelfIntersections(nodes, entity.id)) {\n return parent.geometry(graph);\n }\n }\n\n }\n\n return false;\n }\n\n\n function move(entity) {\n if (_isCancelled) return;\n d3_event.sourceEvent.stopPropagation();\n\n context.surface().classed('nope-disabled', d3_event.sourceEvent.altKey);\n\n _lastLoc = context.projection.invert(d3_event.point);\n\n doMove(entity);\n var nudge = geoViewportEdge(d3_event.point, context.map().dimensions());\n if (nudge) {\n startNudge(entity, nudge);\n } else {\n stopNudge();\n }\n }\n\n function end(entity) {\n if (_isCancelled) return;\n\n var wasPoint = entity.geometry(context.graph()) === 'point';\n\n var d = datum();\n var nope = (d && d.properties && d.properties.nope) || context.surface().classed('nope');\n var target = d && d.properties && d.properties.entity; // entity to snap to\n\n if (nope) { // bounce back\n context.perform(\n _actionBounceBack(entity.id, _startLoc)\n );\n\n } else if (target && target.type === 'way') {\n var choice = geoChooseEdge(context.graph().childNodes(target), context.map().mouse(), context.projection, entity.id);\n context.replace(\n actionAddMidpoint({\n loc: choice.loc,\n edge: [target.nodes[choice.index - 1], target.nodes[choice.index]]\n }, entity),\n connectAnnotation(entity, target)\n );\n\n } else if (target && target.type === 'node' && shouldSnapToNode(target)) {\n context.replace(\n actionConnect([target.id, entity.id]),\n connectAnnotation(entity, target)\n );\n\n } else if (_wasMidpoint) {\n context.replace(\n actionNoop(),\n t('operations.add.annotation.vertex')\n );\n\n } else {\n context.replace(\n actionNoop(),\n moveAnnotation(entity)\n );\n }\n\n if (wasPoint) {\n context.enter(modeSelect(context, [entity.id]));\n\n } else {\n var reselection = _restoreSelectedIDs.filter(function(id) {\n return context.graph().hasEntity(id);\n });\n\n if (reselection.length) {\n context.enter(modeSelect(context, reselection));\n } else {\n context.enter(modeBrowse(context));\n }\n }\n }\n\n\n function _actionBounceBack(nodeID, toLoc) {\n var moveNode = actionMoveNode(nodeID, toLoc);\n var action = function(graph, t) {\n // last time through, pop off the bounceback perform.\n // it will then overwrite the initial perform with a moveNode that does nothing\n if (t === 1) context.pop();\n return moveNode(graph, t);\n };\n action.transitionable = true;\n return action;\n }\n\n\n function cancel() {\n drag.cancel();\n context.enter(modeBrowse(context));\n }\n\n\n var drag = behaviorDrag()\n .selector('.layer-touch.points .target')\n .surface(context.container().select('.main-map').node())\n .origin(origin)\n .on('start', start)\n .on('move', move)\n .on('end', end);\n\n\n mode.enter = function() {\n context.install(hover);\n context.install(edit);\n\n d3_select(window)\n .on('keydown.dragNode', keydown)\n .on('keyup.dragNode', keyup);\n\n context.history()\n .on('undone.drag-node', cancel);\n };\n\n\n mode.exit = function() {\n context.ui().sidebar.hover.cancel();\n context.uninstall(hover);\n context.uninstall(edit);\n\n d3_select(window)\n .on('keydown.dragNode', null)\n .on('keyup.dragNode', null);\n\n context.history()\n .on('undone.drag-node', null);\n\n _activeEntity = null;\n\n context.surface()\n .classed('nope', false)\n .classed('nope-suppressed', false)\n .classed('nope-disabled', false)\n .selectAll('.active')\n .classed('active', false);\n\n stopNudge();\n };\n\n\n mode.selectedIDs = function() {\n if (!arguments.length) return _activeEntity ? [_activeEntity.id] : [];\n // no assign\n return mode;\n };\n\n\n mode.activeID = function() {\n if (!arguments.length) return _activeEntity && _activeEntity.id;\n // no assign\n return mode;\n };\n\n\n mode.restoreSelectedIDs = function(_) {\n if (!arguments.length) return _restoreSelectedIDs;\n _restoreSelectedIDs = _;\n return mode;\n };\n\n\n mode.behavior = drag;\n\n\n return mode;\n}\n","/**\n * Checks if `value` is the\n * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)\n * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is an object, else `false`.\n * @example\n *\n * _.isObject({});\n * // => true\n *\n * _.isObject([1, 2, 3]);\n * // => true\n *\n * _.isObject(_.noop);\n * // => true\n *\n * _.isObject(null);\n * // => false\n */\nfunction isObject(value) {\n var type = typeof value;\n return value != null && (type == 'object' || type == 'function');\n}\n\nexport default isObject;\n","/** Detect free variable `global` from Node.js. */\nvar freeGlobal = typeof global == 'object' && global && global.Object === Object && global;\n\nexport default freeGlobal;\n","import freeGlobal from './_freeGlobal.js';\n\n/** Detect free variable `self`. */\nvar freeSelf = typeof self == 'object' && self && self.Object === Object && self;\n\n/** Used as a reference to the global object. */\nvar root = freeGlobal || freeSelf || Function('return this')();\n\nexport default root;\n","import root from './_root.js';\n\n/**\n * Gets the timestamp of the number of milliseconds that have elapsed since\n * the Unix epoch (1 January 1970 00:00:00 UTC).\n *\n * @static\n * @memberOf _\n * @since 2.4.0\n * @category Date\n * @returns {number} Returns the timestamp.\n * @example\n *\n * _.defer(function(stamp) {\n * console.log(_.now() - stamp);\n * }, _.now());\n * // => Logs the number of milliseconds it took for the deferred invocation.\n */\nvar now = function() {\n return root.Date.now();\n};\n\nexport default now;\n","import root from './_root.js';\n\n/** Built-in value references. */\nvar Symbol = root.Symbol;\n\nexport default Symbol;\n","import Symbol from './_Symbol.js';\n\n/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/** Used to check objects for own properties. */\nvar hasOwnProperty = objectProto.hasOwnProperty;\n\n/**\n * Used to resolve the\n * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)\n * of values.\n */\nvar nativeObjectToString = objectProto.toString;\n\n/** Built-in value references. */\nvar symToStringTag = Symbol ? Symbol.toStringTag : undefined;\n\n/**\n * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.\n *\n * @private\n * @param {*} value The value to query.\n * @returns {string} Returns the raw `toStringTag`.\n */\nfunction getRawTag(value) {\n var isOwn = hasOwnProperty.call(value, symToStringTag),\n tag = value[symToStringTag];\n\n try {\n value[symToStringTag] = undefined;\n var unmasked = true;\n } catch (e) {}\n\n var result = nativeObjectToString.call(value);\n if (unmasked) {\n if (isOwn) {\n value[symToStringTag] = tag;\n } else {\n delete value[symToStringTag];\n }\n }\n return result;\n}\n\nexport default getRawTag;\n","/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/**\n * Used to resolve the\n * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)\n * of values.\n */\nvar nativeObjectToString = objectProto.toString;\n\n/**\n * Converts `value` to a string using `Object.prototype.toString`.\n *\n * @private\n * @param {*} value The value to convert.\n * @returns {string} Returns the converted string.\n */\nfunction objectToString(value) {\n return nativeObjectToString.call(value);\n}\n\nexport default objectToString;\n","import Symbol from './_Symbol.js';\nimport getRawTag from './_getRawTag.js';\nimport objectToString from './_objectToString.js';\n\n/** `Object#toString` result references. */\nvar nullTag = '[object Null]',\n undefinedTag = '[object Undefined]';\n\n/** Built-in value references. */\nvar symToStringTag = Symbol ? Symbol.toStringTag : undefined;\n\n/**\n * The base implementation of `getTag` without fallbacks for buggy environments.\n *\n * @private\n * @param {*} value The value to query.\n * @returns {string} Returns the `toStringTag`.\n */\nfunction baseGetTag(value) {\n if (value == null) {\n return value === undefined ? undefinedTag : nullTag;\n }\n return (symToStringTag && symToStringTag in Object(value))\n ? getRawTag(value)\n : objectToString(value);\n}\n\nexport default baseGetTag;\n","/**\n * Checks if `value` is object-like. A value is object-like if it's not `null`\n * and has a `typeof` result of \"object\".\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is object-like, else `false`.\n * @example\n *\n * _.isObjectLike({});\n * // => true\n *\n * _.isObjectLike([1, 2, 3]);\n * // => true\n *\n * _.isObjectLike(_.noop);\n * // => false\n *\n * _.isObjectLike(null);\n * // => false\n */\nfunction isObjectLike(value) {\n return value != null && typeof value == 'object';\n}\n\nexport default isObjectLike;\n","import baseGetTag from './_baseGetTag.js';\nimport isObjectLike from './isObjectLike.js';\n\n/** `Object#toString` result references. */\nvar symbolTag = '[object Symbol]';\n\n/**\n * Checks if `value` is classified as a `Symbol` primitive or object.\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.\n * @example\n *\n * _.isSymbol(Symbol.iterator);\n * // => true\n *\n * _.isSymbol('abc');\n * // => false\n */\nfunction isSymbol(value) {\n return typeof value == 'symbol' ||\n (isObjectLike(value) && baseGetTag(value) == symbolTag);\n}\n\nexport default isSymbol;\n","import isObject from './isObject.js';\nimport isSymbol from './isSymbol.js';\n\n/** Used as references for various `Number` constants. */\nvar NAN = 0 / 0;\n\n/** Used to match leading and trailing whitespace. */\nvar reTrim = /^\\s+|\\s+$/g;\n\n/** Used to detect bad signed hexadecimal string values. */\nvar reIsBadHex = /^[-+]0x[0-9a-f]+$/i;\n\n/** Used to detect binary string values. */\nvar reIsBinary = /^0b[01]+$/i;\n\n/** Used to detect octal string values. */\nvar reIsOctal = /^0o[0-7]+$/i;\n\n/** Built-in method references without a dependency on `root`. */\nvar freeParseInt = parseInt;\n\n/**\n * Converts `value` to a number.\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to process.\n * @returns {number} Returns the number.\n * @example\n *\n * _.toNumber(3.2);\n * // => 3.2\n *\n * _.toNumber(Number.MIN_VALUE);\n * // => 5e-324\n *\n * _.toNumber(Infinity);\n * // => Infinity\n *\n * _.toNumber('3.2');\n * // => 3.2\n */\nfunction toNumber(value) {\n if (typeof value == 'number') {\n return value;\n }\n if (isSymbol(value)) {\n return NAN;\n }\n if (isObject(value)) {\n var other = typeof value.valueOf == 'function' ? value.valueOf() : value;\n value = isObject(other) ? (other + '') : other;\n }\n if (typeof value != 'string') {\n return value === 0 ? value : +value;\n }\n value = value.replace(reTrim, '');\n var isBinary = reIsBinary.test(value);\n return (isBinary || reIsOctal.test(value))\n ? freeParseInt(value.slice(2), isBinary ? 2 : 8)\n : (reIsBadHex.test(value) ? NAN : +value);\n}\n\nexport default toNumber;\n","import isObject from './isObject.js';\nimport now from './now.js';\nimport toNumber from './toNumber.js';\n\n/** Error message constants. */\nvar FUNC_ERROR_TEXT = 'Expected a function';\n\n/* Built-in method references for those with the same name as other `lodash` methods. */\nvar nativeMax = Math.max,\n nativeMin = Math.min;\n\n/**\n * Creates a debounced function that delays invoking `func` until after `wait`\n * milliseconds have elapsed since the last time the debounced function was\n * invoked. The debounced function comes with a `cancel` method to cancel\n * delayed `func` invocations and a `flush` method to immediately invoke them.\n * Provide `options` to indicate whether `func` should be invoked on the\n * leading and/or trailing edge of the `wait` timeout. The `func` is invoked\n * with the last arguments provided to the debounced function. Subsequent\n * calls to the debounced function return the result of the last `func`\n * invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the debounced function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until to the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)\n * for details over the differences between `_.debounce` and `_.throttle`.\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Function\n * @param {Function} func The function to debounce.\n * @param {number} [wait=0] The number of milliseconds to delay.\n * @param {Object} [options={}] The options object.\n * @param {boolean} [options.leading=false]\n * Specify invoking on the leading edge of the timeout.\n * @param {number} [options.maxWait]\n * The maximum time `func` is allowed to be delayed before it's invoked.\n * @param {boolean} [options.trailing=true]\n * Specify invoking on the trailing edge of the timeout.\n * @returns {Function} Returns the new debounced function.\n * @example\n *\n * // Avoid costly calculations while the window size is in flux.\n * jQuery(window).on('resize', _.debounce(calculateLayout, 150));\n *\n * // Invoke `sendMail` when clicked, debouncing subsequent calls.\n * jQuery(element).on('click', _.debounce(sendMail, 300, {\n * 'leading': true,\n * 'trailing': false\n * }));\n *\n * // Ensure `batchLog` is invoked once after 1 second of debounced calls.\n * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });\n * var source = new EventSource('/stream');\n * jQuery(source).on('message', debounced);\n *\n * // Cancel the trailing debounced invocation.\n * jQuery(window).on('popstate', debounced.cancel);\n */\nfunction debounce(func, wait, options) {\n var lastArgs,\n lastThis,\n maxWait,\n result,\n timerId,\n lastCallTime,\n lastInvokeTime = 0,\n leading = false,\n maxing = false,\n trailing = true;\n\n if (typeof func != 'function') {\n throw new TypeError(FUNC_ERROR_TEXT);\n }\n wait = toNumber(wait) || 0;\n if (isObject(options)) {\n leading = !!options.leading;\n maxing = 'maxWait' in options;\n maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;\n trailing = 'trailing' in options ? !!options.trailing : trailing;\n }\n\n function invokeFunc(time) {\n var args = lastArgs,\n thisArg = lastThis;\n\n lastArgs = lastThis = undefined;\n lastInvokeTime = time;\n result = func.apply(thisArg, args);\n return result;\n }\n\n function leadingEdge(time) {\n // Reset any `maxWait` timer.\n lastInvokeTime = time;\n // Start the timer for the trailing edge.\n timerId = setTimeout(timerExpired, wait);\n // Invoke the leading edge.\n return leading ? invokeFunc(time) : result;\n }\n\n function remainingWait(time) {\n var timeSinceLastCall = time - lastCallTime,\n timeSinceLastInvoke = time - lastInvokeTime,\n timeWaiting = wait - timeSinceLastCall;\n\n return maxing\n ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)\n : timeWaiting;\n }\n\n function shouldInvoke(time) {\n var timeSinceLastCall = time - lastCallTime,\n timeSinceLastInvoke = time - lastInvokeTime;\n\n // Either this is the first call, activity has stopped and we're at the\n // trailing edge, the system time has gone backwards and we're treating\n // it as the trailing edge, or we've hit the `maxWait` limit.\n return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||\n (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));\n }\n\n function timerExpired() {\n var time = now();\n if (shouldInvoke(time)) {\n return trailingEdge(time);\n }\n // Restart the timer.\n timerId = setTimeout(timerExpired, remainingWait(time));\n }\n\n function trailingEdge(time) {\n timerId = undefined;\n\n // Only invoke if we have `lastArgs` which means `func` has been\n // debounced at least once.\n if (trailing && lastArgs) {\n return invokeFunc(time);\n }\n lastArgs = lastThis = undefined;\n return result;\n }\n\n function cancel() {\n if (timerId !== undefined) {\n clearTimeout(timerId);\n }\n lastInvokeTime = 0;\n lastArgs = lastCallTime = lastThis = timerId = undefined;\n }\n\n function flush() {\n return timerId === undefined ? result : trailingEdge(now());\n }\n\n function debounced() {\n var time = now(),\n isInvoking = shouldInvoke(time);\n\n lastArgs = arguments;\n lastThis = this;\n lastCallTime = time;\n\n if (isInvoking) {\n if (timerId === undefined) {\n return leadingEdge(lastCallTime);\n }\n if (maxing) {\n // Handle invocations in a tight loop.\n clearTimeout(timerId);\n timerId = setTimeout(timerExpired, wait);\n return invokeFunc(lastCallTime);\n }\n }\n if (timerId === undefined) {\n timerId = setTimeout(timerExpired, wait);\n }\n return result;\n }\n debounced.cancel = cancel;\n debounced.flush = flush;\n return debounced;\n}\n\nexport default debounce;\n","//[4] \tNameStartChar\t ::= \t\":\" | [A-Z] | \"_\" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]\r\n//[4a] \tNameChar\t ::= \tNameStartChar | \"-\" | \".\" | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]\r\n//[5] \tName\t ::= \tNameStartChar (NameChar)*\r\nvar nameStartChar = /[A-Z_a-z\\xC0-\\xD6\\xD8-\\xF6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD]///\\u10000-\\uEFFFF\r\nvar nameChar = new RegExp(\"[\\\\-\\\\.0-9\"+nameStartChar.source.slice(1,-1)+\"\\\\u00B7\\\\u0300-\\\\u036F\\\\u203F-\\\\u2040]\");\r\nvar tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\\:'+nameStartChar.source+nameChar.source+'*)?$');\r\n//var tagNamePattern = /^[a-zA-Z_][\\w\\-\\.]*(?:\\:[a-zA-Z_][\\w\\-\\.]*)?$/\r\n//var handlers = 'resolveEntity,getExternalSubset,characters,endDocument,endElement,endPrefixMapping,ignorableWhitespace,processingInstruction,setDocumentLocator,skippedEntity,startDocument,startElement,startPrefixMapping,notationDecl,unparsedEntityDecl,error,fatalError,warning,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,comment,endCDATA,endDTD,endEntity,startCDATA,startDTD,startEntity'.split(',')\r\n\r\n//S_TAG,\tS_ATTR,\tS_EQ,\tS_ATTR_NOQUOT_VALUE\r\n//S_ATTR_SPACE,\tS_ATTR_END,\tS_TAG_SPACE, S_TAG_CLOSE\r\nvar S_TAG = 0;//tag name offerring\r\nvar S_ATTR = 1;//attr name offerring \r\nvar S_ATTR_SPACE=2;//attr name end and space offer\r\nvar S_EQ = 3;//=space?\r\nvar S_ATTR_NOQUOT_VALUE = 4;//attr value(no quot value only)\r\nvar S_ATTR_END = 5;//attr value end and no space(quot end)\r\nvar S_TAG_SPACE = 6;//(attr value end || tag end ) && (space offer)\r\nvar S_TAG_CLOSE = 7;//closed el \r\n\r\nfunction XMLReader(){\r\n\t\r\n}\r\n\r\nXMLReader.prototype = {\r\n\tparse:function(source,defaultNSMap,entityMap){\r\n\t\tvar domBuilder = this.domBuilder;\r\n\t\tdomBuilder.startDocument();\r\n\t\t_copy(defaultNSMap ,defaultNSMap = {})\r\n\t\tparse(source,defaultNSMap,entityMap,\r\n\t\t\t\tdomBuilder,this.errorHandler);\r\n\t\tdomBuilder.endDocument();\r\n\t}\r\n}\r\nfunction parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){\r\n\tfunction fixedFromCharCode(code) {\r\n\t\t// String.prototype.fromCharCode does not supports\r\n\t\t// > 2 bytes unicode chars directly\r\n\t\tif (code > 0xffff) {\r\n\t\t\tcode -= 0x10000;\r\n\t\t\tvar surrogate1 = 0xd800 + (code >> 10)\r\n\t\t\t\t, surrogate2 = 0xdc00 + (code & 0x3ff);\r\n\r\n\t\t\treturn String.fromCharCode(surrogate1, surrogate2);\r\n\t\t} else {\r\n\t\t\treturn String.fromCharCode(code);\r\n\t\t}\r\n\t}\r\n\tfunction entityReplacer(a){\r\n\t\tvar k = a.slice(1,-1);\r\n\t\tif(k in entityMap){\r\n\t\t\treturn entityMap[k]; \r\n\t\t}else if(k.charAt(0) === '#'){\r\n\t\t\treturn fixedFromCharCode(parseInt(k.substr(1).replace('x','0x')))\r\n\t\t}else{\r\n\t\t\terrorHandler.error('entity not found:'+a);\r\n\t\t\treturn a;\r\n\t\t}\r\n\t}\r\n\tfunction appendText(end){//has some bugs\r\n\t\tif(end>start){\r\n\t\t\tvar xt = source.substring(start,end).replace(/?\\w+;/g,entityReplacer);\r\n\t\t\tlocator&&position(start);\r\n\t\t\tdomBuilder.characters(xt,0,end-start);\r\n\t\t\tstart = end\r\n\t\t}\r\n\t}\r\n\tfunction position(p,m){\r\n\t\twhile(p>=lineEnd && (m = linePattern.exec(source))){\r\n\t\t\tlineStart = m.index;\r\n\t\t\tlineEnd = lineStart + m[0].length;\r\n\t\t\tlocator.lineNumber++;\r\n\t\t\t//console.log('line++:',locator,startPos,endPos)\r\n\t\t}\r\n\t\tlocator.columnNumber = p-lineStart+1;\r\n\t}\r\n\tvar lineStart = 0;\r\n\tvar lineEnd = 0;\r\n\tvar linePattern = /.*(?:\\r\\n?|\\n)|.*$/g\r\n\tvar locator = domBuilder.locator;\r\n\t\r\n\tvar parseStack = [{currentNSMap:defaultNSMapCopy}]\r\n\tvar closeMap = {};\r\n\tvar start = 0;\r\n\twhile(true){\r\n\t\ttry{\r\n\t\t\tvar tagStart = source.indexOf('<',start);\r\n\t\t\tif(tagStart<0){\r\n\t\t\t\tif(!source.substr(start).match(/^\\s*$/)){\r\n\t\t\t\t\tvar doc = domBuilder.doc;\r\n\t \t\t\tvar text = doc.createTextNode(source.substr(start));\r\n\t \t\t\tdoc.appendChild(text);\r\n\t \t\t\tdomBuilder.currentElement = text;\r\n\t\t\t\t}\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tif(tagStart>start){\r\n\t\t\t\tappendText(tagStart);\r\n\t\t\t}\r\n\t\t\tswitch(source.charAt(tagStart+1)){\r\n\t\t\tcase '/':\r\n\t\t\t\tvar end = source.indexOf('>',tagStart+3);\r\n\t\t\t\tvar tagName = source.substring(tagStart+2,end);\r\n\t\t\t\tvar config = parseStack.pop();\r\n\t\t\t\tif(end<0){\r\n\t\t\t\t\t\r\n\t \t\ttagName = source.substring(tagStart+2).replace(/[\\s<].*/,'');\r\n\t \t\t//console.error('#@@@@@@'+tagName)\r\n\t \t\terrorHandler.error(\"end tag name: \"+tagName+' is not complete:'+config.tagName);\r\n\t \t\tend = tagStart+1+tagName.length;\r\n\t \t}else if(tagName.match(/\\s)){\r\n\t \t\ttagName = tagName.replace(/[\\s<].*/,'');\r\n\t \t\terrorHandler.error(\"end tag name: \"+tagName+' maybe not complete');\r\n\t \t\tend = tagStart+1+tagName.length;\r\n\t\t\t\t}\r\n\t\t\t\t//console.error(parseStack.length,parseStack)\r\n\t\t\t\t//console.error(config);\r\n\t\t\t\tvar localNSMap = config.localNSMap;\r\n\t\t\t\tvar endMatch = config.tagName == tagName;\r\n\t\t\t\tvar endIgnoreCaseMach = endMatch || config.tagName&&config.tagName.toLowerCase() == tagName.toLowerCase()\r\n\t\t if(endIgnoreCaseMach){\r\n\t\t \tdomBuilder.endElement(config.uri,config.localName,tagName);\r\n\t\t\t\t\tif(localNSMap){\r\n\t\t\t\t\t\tfor(var prefix in localNSMap){\r\n\t\t\t\t\t\t\tdomBuilder.endPrefixMapping(prefix) ;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif(!endMatch){\r\n\t\t \terrorHandler.fatalError(\"end tag name: \"+tagName+' is not match the current start tagName:'+config.tagName );\r\n\t\t\t\t\t}\r\n\t\t }else{\r\n\t\t \tparseStack.push(config)\r\n\t\t }\r\n\t\t\t\t\r\n\t\t\t\tend++;\r\n\t\t\t\tbreak;\r\n\t\t\t\t// end elment\r\n\t\t\tcase '?':// ...?>\r\n\t\t\t\tlocator&&position(tagStart);\r\n\t\t\t\tend = parseInstruction(source,tagStart,domBuilder);\r\n\t\t\t\tbreak;\r\n\t\t\tcase '!':// start){\r\n\t\t\tstart = end;\r\n\t\t}else{\r\n\t\t\t//TODO: 这里有可能sax回退,有位置错误风险\r\n\t\t\tappendText(Math.max(tagStart,start)+1);\r\n\t\t}\r\n\t}\r\n}\r\nfunction copyLocator(f,t){\r\n\tt.lineNumber = f.lineNumber;\r\n\tt.columnNumber = f.columnNumber;\r\n\treturn t;\r\n}\r\n\r\n/**\r\n * @see #appendElement(source,elStartEnd,el,selfClosed,entityReplacer,domBuilder,parseStack);\r\n * @return end of the elementStartPart(end of elementEndPart for selfClosed el)\r\n */\r\nfunction parseElementStartPart(source,start,el,currentNSMap,entityReplacer,errorHandler){\r\n\tvar attrName;\r\n\tvar value;\r\n\tvar p = ++start;\r\n\tvar s = S_TAG;//status\r\n\twhile(true){\r\n\t\tvar c = source.charAt(p);\r\n\t\tswitch(c){\r\n\t\tcase '=':\r\n\t\t\tif(s === S_ATTR){//attrName\r\n\t\t\t\tattrName = source.slice(start,p);\r\n\t\t\t\ts = S_EQ;\r\n\t\t\t}else if(s === S_ATTR_SPACE){\r\n\t\t\t\ts = S_EQ;\r\n\t\t\t}else{\r\n\t\t\t\t//fatalError: equal must after attrName or space after attrName\r\n\t\t\t\tthrow new Error('attribute equal must after attrName');\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase '\\'':\r\n\t\tcase '\"':\r\n\t\t\tif(s === S_EQ || s === S_ATTR //|| s == S_ATTR_SPACE\r\n\t\t\t\t){//equal\r\n\t\t\t\tif(s === S_ATTR){\r\n\t\t\t\t\terrorHandler.warning('attribute value must after \"=\"')\r\n\t\t\t\t\tattrName = source.slice(start,p)\r\n\t\t\t\t}\r\n\t\t\t\tstart = p+1;\r\n\t\t\t\tp = source.indexOf(c,start)\r\n\t\t\t\tif(p>0){\r\n\t\t\t\t\tvalue = source.slice(start,p).replace(/?\\w+;/g,entityReplacer);\r\n\t\t\t\t\tel.add(attrName,value,start-1);\r\n\t\t\t\t\ts = S_ATTR_END;\r\n\t\t\t\t}else{\r\n\t\t\t\t\t//fatalError: no end quot match\r\n\t\t\t\t\tthrow new Error('attribute value no end \\''+c+'\\' match');\r\n\t\t\t\t}\r\n\t\t\t}else if(s == S_ATTR_NOQUOT_VALUE){\r\n\t\t\t\tvalue = source.slice(start,p).replace(/?\\w+;/g,entityReplacer);\r\n\t\t\t\t//console.log(attrName,value,start,p)\r\n\t\t\t\tel.add(attrName,value,start);\r\n\t\t\t\t//console.dir(el)\r\n\t\t\t\terrorHandler.warning('attribute \"'+attrName+'\" missed start quot('+c+')!!');\r\n\t\t\t\tstart = p+1;\r\n\t\t\t\ts = S_ATTR_END\r\n\t\t\t}else{\r\n\t\t\t\t//fatalError: no equal before\r\n\t\t\t\tthrow new Error('attribute value must after \"=\"');\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase '/':\r\n\t\t\tswitch(s){\r\n\t\t\tcase S_TAG:\r\n\t\t\t\tel.setTagName(source.slice(start,p));\r\n\t\t\tcase S_ATTR_END:\r\n\t\t\tcase S_TAG_SPACE:\r\n\t\t\tcase S_TAG_CLOSE:\r\n\t\t\t\ts =S_TAG_CLOSE;\r\n\t\t\t\tel.closed = true;\r\n\t\t\tcase S_ATTR_NOQUOT_VALUE:\r\n\t\t\tcase S_ATTR:\r\n\t\t\tcase S_ATTR_SPACE:\r\n\t\t\t\tbreak;\r\n\t\t\t//case S_EQ:\r\n\t\t\tdefault:\r\n\t\t\t\tthrow new Error(\"attribute invalid close char('/')\")\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\tcase ''://end document\r\n\t\t\t//throw new Error('unexpected end of input')\r\n\t\t\terrorHandler.error('unexpected end of input');\r\n\t\t\tif(s == S_TAG){\r\n\t\t\t\tel.setTagName(source.slice(start,p));\r\n\t\t\t}\r\n\t\t\treturn p;\r\n\t\tcase '>':\r\n\t\t\tswitch(s){\r\n\t\t\tcase S_TAG:\r\n\t\t\t\tel.setTagName(source.slice(start,p));\r\n\t\t\tcase S_ATTR_END:\r\n\t\t\tcase S_TAG_SPACE:\r\n\t\t\tcase S_TAG_CLOSE:\r\n\t\t\t\tbreak;//normal\r\n\t\t\tcase S_ATTR_NOQUOT_VALUE://Compatible state\r\n\t\t\tcase S_ATTR:\r\n\t\t\t\tvalue = source.slice(start,p);\r\n\t\t\t\tif(value.slice(-1) === '/'){\r\n\t\t\t\t\tel.closed = true;\r\n\t\t\t\t\tvalue = value.slice(0,-1)\r\n\t\t\t\t}\r\n\t\t\tcase S_ATTR_SPACE:\r\n\t\t\t\tif(s === S_ATTR_SPACE){\r\n\t\t\t\t\tvalue = attrName;\r\n\t\t\t\t}\r\n\t\t\t\tif(s == S_ATTR_NOQUOT_VALUE){\r\n\t\t\t\t\terrorHandler.warning('attribute \"'+value+'\" missed quot(\")!!');\r\n\t\t\t\t\tel.add(attrName,value.replace(/?\\w+;/g,entityReplacer),start)\r\n\t\t\t\t}else{\r\n\t\t\t\t\tif(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !value.match(/^(?:disabled|checked|selected)$/i)){\r\n\t\t\t\t\t\terrorHandler.warning('attribute \"'+value+'\" missed value!! \"'+value+'\" instead!!')\r\n\t\t\t\t\t}\r\n\t\t\t\t\tel.add(value,value,start)\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase S_EQ:\r\n\t\t\t\tthrow new Error('attribute value missed!!');\r\n\t\t\t}\r\n//\t\t\tconsole.log(tagName,tagNamePattern,tagNamePattern.test(tagName))\r\n\t\t\treturn p;\r\n\t\t/*xml space '\\x20' | #x9 | #xD | #xA; */\r\n\t\tcase '\\u0080':\r\n\t\t\tc = ' ';\r\n\t\tdefault:\r\n\t\t\tif(c<= ' '){//space\r\n\t\t\t\tswitch(s){\r\n\t\t\t\tcase S_TAG:\r\n\t\t\t\t\tel.setTagName(source.slice(start,p));//tagName\r\n\t\t\t\t\ts = S_TAG_SPACE;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase S_ATTR:\r\n\t\t\t\t\tattrName = source.slice(start,p)\r\n\t\t\t\t\ts = S_ATTR_SPACE;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase S_ATTR_NOQUOT_VALUE:\r\n\t\t\t\t\tvar value = source.slice(start,p).replace(/?\\w+;/g,entityReplacer);\r\n\t\t\t\t\terrorHandler.warning('attribute \"'+value+'\" missed quot(\")!!');\r\n\t\t\t\t\tel.add(attrName,value,start)\r\n\t\t\t\tcase S_ATTR_END:\r\n\t\t\t\t\ts = S_TAG_SPACE;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t//case S_TAG_SPACE:\r\n\t\t\t\t//case S_EQ:\r\n\t\t\t\t//case S_ATTR_SPACE:\r\n\t\t\t\t//\tvoid();break;\r\n\t\t\t\t//case S_TAG_CLOSE:\r\n\t\t\t\t\t//ignore warning\r\n\t\t\t\t}\r\n\t\t\t}else{//not space\r\n//S_TAG,\tS_ATTR,\tS_EQ,\tS_ATTR_NOQUOT_VALUE\r\n//S_ATTR_SPACE,\tS_ATTR_END,\tS_TAG_SPACE, S_TAG_CLOSE\r\n\t\t\t\tswitch(s){\r\n\t\t\t\t//case S_TAG:void();break;\r\n\t\t\t\t//case S_ATTR:void();break;\r\n\t\t\t\t//case S_ATTR_NOQUOT_VALUE:void();break;\r\n\t\t\t\tcase S_ATTR_SPACE:\r\n\t\t\t\t\tvar tagName = el.tagName;\r\n\t\t\t\t\tif(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !attrName.match(/^(?:disabled|checked|selected)$/i)){\r\n\t\t\t\t\t\terrorHandler.warning('attribute \"'+attrName+'\" missed value!! \"'+attrName+'\" instead2!!')\r\n\t\t\t\t\t}\r\n\t\t\t\t\tel.add(attrName,attrName,start);\r\n\t\t\t\t\tstart = p;\r\n\t\t\t\t\ts = S_ATTR;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase S_ATTR_END:\r\n\t\t\t\t\terrorHandler.warning('attribute space is required\"'+attrName+'\"!!')\r\n\t\t\t\tcase S_TAG_SPACE:\r\n\t\t\t\t\ts = S_ATTR;\r\n\t\t\t\t\tstart = p;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase S_EQ:\r\n\t\t\t\t\ts = S_ATTR_NOQUOT_VALUE;\r\n\t\t\t\t\tstart = p;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase S_TAG_CLOSE:\r\n\t\t\t\t\tthrow new Error(\"elements closed character '/' and '>' must be connected to\");\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}//end outer switch\r\n\t\t//console.log('p++',p)\r\n\t\tp++;\r\n\t}\r\n}\r\n/**\r\n * @return true if has new namespace define\r\n */\r\nfunction appendElement(el,domBuilder,currentNSMap){\r\n\tvar tagName = el.tagName;\r\n\tvar localNSMap = null;\r\n\t//var currentNSMap = parseStack[parseStack.length-1].currentNSMap;\r\n\tvar i = el.length;\r\n\twhile(i--){\r\n\t\tvar a = el[i];\r\n\t\tvar qName = a.qName;\r\n\t\tvar value = a.value;\r\n\t\tvar nsp = qName.indexOf(':');\r\n\t\tif(nsp>0){\r\n\t\t\tvar prefix = a.prefix = qName.slice(0,nsp);\r\n\t\t\tvar localName = qName.slice(nsp+1);\r\n\t\t\tvar nsPrefix = prefix === 'xmlns' && localName\r\n\t\t}else{\r\n\t\t\tlocalName = qName;\r\n\t\t\tprefix = null\r\n\t\t\tnsPrefix = qName === 'xmlns' && ''\r\n\t\t}\r\n\t\t//can not set prefix,because prefix !== ''\r\n\t\ta.localName = localName ;\r\n\t\t//prefix == null for no ns prefix attribute \r\n\t\tif(nsPrefix !== false){//hack!!\r\n\t\t\tif(localNSMap == null){\r\n\t\t\t\tlocalNSMap = {}\r\n\t\t\t\t//console.log(currentNSMap,0)\r\n\t\t\t\t_copy(currentNSMap,currentNSMap={})\r\n\t\t\t\t//console.log(currentNSMap,1)\r\n\t\t\t}\r\n\t\t\tcurrentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;\r\n\t\t\ta.uri = 'http://www.w3.org/2000/xmlns/'\r\n\t\t\tdomBuilder.startPrefixMapping(nsPrefix, value) \r\n\t\t}\r\n\t}\r\n\tvar i = el.length;\r\n\twhile(i--){\r\n\t\ta = el[i];\r\n\t\tvar prefix = a.prefix;\r\n\t\tif(prefix){//no prefix attribute has no namespace\r\n\t\t\tif(prefix === 'xml'){\r\n\t\t\t\ta.uri = 'http://www.w3.org/XML/1998/namespace';\r\n\t\t\t}if(prefix !== 'xmlns'){\r\n\t\t\t\ta.uri = currentNSMap[prefix || '']\r\n\t\t\t\t\r\n\t\t\t\t//{console.log('###'+a.qName,domBuilder.locator.systemId+'',currentNSMap,a.uri)}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tvar nsp = tagName.indexOf(':');\r\n\tif(nsp>0){\r\n\t\tprefix = el.prefix = tagName.slice(0,nsp);\r\n\t\tlocalName = el.localName = tagName.slice(nsp+1);\r\n\t}else{\r\n\t\tprefix = null;//important!!\r\n\t\tlocalName = el.localName = tagName;\r\n\t}\r\n\t//no prefix element has default namespace\r\n\tvar ns = el.uri = currentNSMap[prefix || ''];\r\n\tdomBuilder.startElement(ns,localName,tagName,el);\r\n\t//endPrefixMapping and startPrefixMapping have not any help for dom builder\r\n\t//localNSMap = null\r\n\tif(el.closed){\r\n\t\tdomBuilder.endElement(ns,localName,tagName);\r\n\t\tif(localNSMap){\r\n\t\t\tfor(prefix in localNSMap){\r\n\t\t\t\tdomBuilder.endPrefixMapping(prefix) \r\n\t\t\t}\r\n\t\t}\r\n\t}else{\r\n\t\tel.currentNSMap = currentNSMap;\r\n\t\tel.localNSMap = localNSMap;\r\n\t\t//parseStack.push(el);\r\n\t\treturn true;\r\n\t}\r\n}\r\nfunction parseHtmlSpecialContent(source,elStartEnd,tagName,entityReplacer,domBuilder){\r\n\tif(/^(?:script|textarea)$/i.test(tagName)){\r\n\t\tvar elEndStart = source.indexOf(''+tagName+'>',elStartEnd);\r\n\t\tvar text = source.substring(elStartEnd+1,elEndStart);\r\n\t\tif(/[&<]/.test(text)){\r\n\t\t\tif(/^script$/i.test(tagName)){\r\n\t\t\t\t//if(!/\\]\\]>/.test(text)){\r\n\t\t\t\t\t//lexHandler.startCDATA();\r\n\t\t\t\t\tdomBuilder.characters(text,0,text.length);\r\n\t\t\t\t\t//lexHandler.endCDATA();\r\n\t\t\t\t\treturn elEndStart;\r\n\t\t\t\t//}\r\n\t\t\t}//}else{//text area\r\n\t\t\t\ttext = text.replace(/?\\w+;/g,entityReplacer);\r\n\t\t\t\tdomBuilder.characters(text,0,text.length);\r\n\t\t\t\treturn elEndStart;\r\n\t\t\t//}\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n\treturn elStartEnd+1;\r\n}\r\nfunction fixSelfClosed(source,elStartEnd,tagName,closeMap){\r\n\t//if(tagName in closeMap){\r\n\tvar pos = closeMap[tagName];\r\n\tif(pos == null){\r\n\t\t//console.log(tagName)\r\n\t\tpos = source.lastIndexOf(''+tagName+'>')\r\n\t\tif(pos',start+4);\r\n\t\t\t//append comment source.substring(4,end)//\");\n\tcase DOCUMENT_TYPE_NODE:\n\t\tvar pubid = node.publicId;\n\t\tvar sysid = node.systemId;\n\t\tbuf.push('');\n\t\t}else if(sysid && sysid!='.'){\n\t\t\tbuf.push(' SYSTEM \"',sysid,'\">');\n\t\t}else{\n\t\t\tvar sub = node.internalSubset;\n\t\t\tif(sub){\n\t\t\t\tbuf.push(\" [\",sub,\"]\");\n\t\t\t}\n\t\t\tbuf.push(\">\");\n\t\t}\n\t\treturn;\n\tcase PROCESSING_INSTRUCTION_NODE:\n\t\treturn buf.push( \"\",node.target,\" \",node.data,\"?>\");\n\tcase ENTITY_REFERENCE_NODE:\n\t\treturn buf.push( '&',node.nodeName,';');\n\t//case ENTITY_NODE:\n\t//case NOTATION_NODE:\n\tdefault:\n\t\tbuf.push('??',node.nodeName);\n\t}\n}\nfunction importNode(doc,node,deep){\n\tvar node2;\n\tswitch (node.nodeType) {\n\tcase ELEMENT_NODE:\n\t\tnode2 = node.cloneNode(false);\n\t\tnode2.ownerDocument = doc;\n\t\t//var attrs = node2.attributes;\n\t\t//var len = attrs.length;\n\t\t//for(var i=0;i','amp':'&','quot':'\"','apos':\"'\"}\r\n\tif(locator){\r\n\t\tdomBuilder.setDocumentLocator(locator)\r\n\t}\r\n\t\r\n\tsax.errorHandler = buildErrorHandler(errorHandler,domBuilder,locator);\r\n\tsax.domBuilder = options.domBuilder || domBuilder;\r\n\tif(/\\/x?html?$/.test(mimeType)){\r\n\t\tentityMap.nbsp = '\\xa0';\r\n\t\tentityMap.copy = '\\xa9';\r\n\t\tdefaultNSMap['']= 'http://www.w3.org/1999/xhtml';\r\n\t}\r\n\tdefaultNSMap.xml = defaultNSMap.xml || 'http://www.w3.org/XML/1998/namespace';\r\n\tif(source){\r\n\t\tsax.parse(source,defaultNSMap,entityMap);\r\n\t}else{\r\n\t\tsax.errorHandler.error(\"invalid doc source\");\r\n\t}\r\n\treturn domBuilder.doc;\r\n}\r\nfunction buildErrorHandler(errorImpl,domBuilder,locator){\r\n\tif(!errorImpl){\r\n\t\tif(domBuilder instanceof DOMHandler){\r\n\t\t\treturn domBuilder;\r\n\t\t}\r\n\t\terrorImpl = domBuilder ;\r\n\t}\r\n\tvar errorHandler = {}\r\n\tvar isCallback = errorImpl instanceof Function;\r\n\tlocator = locator||{}\r\n\tfunction build(key){\r\n\t\tvar fn = errorImpl[key];\r\n\t\tif(!fn && isCallback){\r\n\t\t\tfn = errorImpl.length == 2?function(msg){errorImpl(key,msg)}:errorImpl;\r\n\t\t}\r\n\t\terrorHandler[key] = fn && function(msg){\r\n\t\t\tfn('[xmldom '+key+']\\t'+msg+_locator(locator));\r\n\t\t}||function(){};\r\n\t}\r\n\tbuild('warning');\r\n\tbuild('error');\r\n\tbuild('fatalError');\r\n\treturn errorHandler;\r\n}\r\n\r\n//console.log('#\\n\\n\\n\\n\\n\\n\\n####')\r\n/**\r\n * +ContentHandler+ErrorHandler\r\n * +LexicalHandler+EntityResolver2\r\n * -DeclHandler-DTDHandler \r\n * \r\n * DefaultHandler:EntityResolver, DTDHandler, ContentHandler, ErrorHandler\r\n * DefaultHandler2:DefaultHandler,LexicalHandler, DeclHandler, EntityResolver2\r\n * @link http://www.saxproject.org/apidoc/org/xml/sax/helpers/DefaultHandler.html\r\n */\r\nfunction DOMHandler() {\r\n this.cdata = false;\r\n}\r\nfunction position(locator,node){\r\n\tnode.lineNumber = locator.lineNumber;\r\n\tnode.columnNumber = locator.columnNumber;\r\n}\r\n/**\r\n * @see org.xml.sax.ContentHandler#startDocument\r\n * @link http://www.saxproject.org/apidoc/org/xml/sax/ContentHandler.html\r\n */ \r\nDOMHandler.prototype = {\r\n\tstartDocument : function() {\r\n \tthis.doc = new DOMImplementation().createDocument(null, null, null);\r\n \tif (this.locator) {\r\n \tthis.doc.documentURI = this.locator.systemId;\r\n \t}\r\n\t},\r\n\tstartElement:function(namespaceURI, localName, qName, attrs) {\r\n\t\tvar doc = this.doc;\r\n\t var el = doc.createElementNS(namespaceURI, qName||localName);\r\n\t var len = attrs.length;\r\n\t appendElement(this, el);\r\n\t this.currentElement = el;\r\n\t \r\n\t\tthis.locator && position(this.locator,el)\r\n\t for (var i = 0 ; i < len; i++) {\r\n\t var namespaceURI = attrs.getURI(i);\r\n\t var value = attrs.getValue(i);\r\n\t var qName = attrs.getQName(i);\r\n\t\t\tvar attr = doc.createAttributeNS(namespaceURI, qName);\r\n\t\t\tthis.locator &&position(attrs.getLocator(i),attr);\r\n\t\t\tattr.value = attr.nodeValue = value;\r\n\t\t\tel.setAttributeNode(attr)\r\n\t }\r\n\t},\r\n\tendElement:function(namespaceURI, localName, qName) {\r\n\t\tvar current = this.currentElement\r\n\t\tvar tagName = current.tagName;\r\n\t\tthis.currentElement = current.parentNode;\r\n\t},\r\n\tstartPrefixMapping:function(prefix, uri) {\r\n\t},\r\n\tendPrefixMapping:function(prefix) {\r\n\t},\r\n\tprocessingInstruction:function(target, data) {\r\n\t var ins = this.doc.createProcessingInstruction(target, data);\r\n\t this.locator && position(this.locator,ins)\r\n\t appendElement(this, ins);\r\n\t},\r\n\tignorableWhitespace:function(ch, start, length) {\r\n\t},\r\n\tcharacters:function(chars, start, length) {\r\n\t\tchars = _toString.apply(this,arguments)\r\n\t\t//console.log(chars)\r\n\t\tif(chars){\r\n\t\t\tif (this.cdata) {\r\n\t\t\t\tvar charNode = this.doc.createCDATASection(chars);\r\n\t\t\t} else {\r\n\t\t\t\tvar charNode = this.doc.createTextNode(chars);\r\n\t\t\t}\r\n\t\t\tif(this.currentElement){\r\n\t\t\t\tthis.currentElement.appendChild(charNode);\r\n\t\t\t}else if(/^\\s*$/.test(chars)){\r\n\t\t\t\tthis.doc.appendChild(charNode);\r\n\t\t\t\t//process xml\r\n\t\t\t}\r\n\t\t\tthis.locator && position(this.locator,charNode)\r\n\t\t}\r\n\t},\r\n\tskippedEntity:function(name) {\r\n\t},\r\n\tendDocument:function() {\r\n\t\tthis.doc.normalize();\r\n\t},\r\n\tsetDocumentLocator:function (locator) {\r\n\t if(this.locator = locator){// && !('lineNumber' in locator)){\r\n\t \tlocator.lineNumber = 0;\r\n\t }\r\n\t},\r\n\t//LexicalHandler\r\n\tcomment:function(chars, start, length) {\r\n\t\tchars = _toString.apply(this,arguments)\r\n\t var comm = this.doc.createComment(chars);\r\n\t this.locator && position(this.locator,comm)\r\n\t appendElement(this, comm);\r\n\t},\r\n\t\r\n\tstartCDATA:function() {\r\n\t //used in characters() methods\r\n\t this.cdata = true;\r\n\t},\r\n\tendCDATA:function() {\r\n\t this.cdata = false;\r\n\t},\r\n\t\r\n\tstartDTD:function(name, publicId, systemId) {\r\n\t\tvar impl = this.doc.implementation;\r\n\t if (impl && impl.createDocumentType) {\r\n\t var dt = impl.createDocumentType(name, publicId, systemId);\r\n\t this.locator && position(this.locator,dt)\r\n\t appendElement(this, dt);\r\n\t }\r\n\t},\r\n\t/**\r\n\t * @see org.xml.sax.ErrorHandler\r\n\t * @link http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html\r\n\t */\r\n\twarning:function(error) {\r\n\t\tconsole.warn('[xmldom warning]\\t'+error,_locator(this.locator));\r\n\t},\r\n\terror:function(error) {\r\n\t\tconsole.error('[xmldom error]\\t'+error,_locator(this.locator));\r\n\t},\r\n\tfatalError:function(error) {\r\n\t\tconsole.error('[xmldom fatalError]\\t'+error,_locator(this.locator));\r\n\t throw error;\r\n\t}\r\n}\r\nfunction _locator(l){\r\n\tif(l){\r\n\t\treturn '\\n@'+(l.systemId ||'')+'#[line:'+l.lineNumber+',col:'+l.columnNumber+']'\r\n\t}\r\n}\r\nfunction _toString(chars,start,length){\r\n\tif(typeof chars == 'string'){\r\n\t\treturn chars.substr(start,length)\r\n\t}else{//java sax connect width xmldom on rhino(what about: \"? && !(chars instanceof String)\")\r\n\t\tif(chars.length >= start+length || start){\r\n\t\t\treturn new java.lang.String(chars,start,length)+'';\r\n\t\t}\r\n\t\treturn chars;\r\n\t}\r\n}\r\n\r\n/*\r\n * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/LexicalHandler.html\r\n * used method of org.xml.sax.ext.LexicalHandler:\r\n * #comment(chars, start, length)\r\n * #startCDATA()\r\n * #endCDATA()\r\n * #startDTD(name, publicId, systemId)\r\n *\r\n *\r\n * IGNORED method of org.xml.sax.ext.LexicalHandler:\r\n * #endDTD()\r\n * #startEntity(name)\r\n * #endEntity(name)\r\n *\r\n *\r\n * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/DeclHandler.html\r\n * IGNORED method of org.xml.sax.ext.DeclHandler\r\n * \t#attributeDecl(eName, aName, type, mode, value)\r\n * #elementDecl(name, model)\r\n * #externalEntityDecl(name, publicId, systemId)\r\n * #internalEntityDecl(name, value)\r\n * @link http://www.saxproject.org/apidoc/org/xml/sax/ext/EntityResolver2.html\r\n * IGNORED method of org.xml.sax.EntityResolver2\r\n * #resolveEntity(String name,String publicId,String baseURI,String systemId)\r\n * #resolveEntity(publicId, systemId)\r\n * #getExternalSubset(name, baseURI)\r\n * @link http://www.saxproject.org/apidoc/org/xml/sax/DTDHandler.html\r\n * IGNORED method of org.xml.sax.DTDHandler\r\n * #notationDecl(name, publicId, systemId) {};\r\n * #unparsedEntityDecl(name, publicId, systemId, notationName) {};\r\n */\r\n\"endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl\".replace(/\\w+/g,function(key){\r\n\tDOMHandler.prototype[key] = function(){return null}\r\n})\r\n\r\n/* Private static helpers treated below as private instance methods, so don't need to add these to the public API; we might use a Relator to also get rid of non-standard public properties */\r\nfunction appendElement (hander,node) {\r\n if (!hander.currentElement) {\r\n hander.doc.appendChild(node);\r\n } else {\r\n hander.currentElement.appendChild(node);\r\n }\r\n}//appendChild and setAttributeNS are preformance key\r\n\r\n//if(typeof require == 'function'){\r\n\tvar XMLReader = require('./sax').XMLReader;\r\n\tvar DOMImplementation = exports.DOMImplementation = require('./dom').DOMImplementation;\r\n\texports.XMLSerializer = require('./dom').XMLSerializer ;\r\n\texports.DOMParser = DOMParser;\r\n//}\r\n","var toGeoJSON = (function() {\n 'use strict';\n\n var removeSpace = /\\s*/g,\n trimSpace = /^\\s*|\\s*$/g,\n splitSpace = /\\s+/;\n // generate a short, numeric hash of a string\n function okhash(x) {\n if (!x || !x.length) return 0;\n for (var i = 0, h = 0; i < x.length; i++) {\n h = ((h << 5) - h) + x.charCodeAt(i) | 0;\n } return h;\n }\n // all Y children of X\n function get(x, y) { return x.getElementsByTagName(y); }\n function attr(x, y) { return x.getAttribute(y); }\n function attrf(x, y) { return parseFloat(attr(x, y)); }\n // one Y child of X, if any, otherwise null\n function get1(x, y) { var n = get(x, y); return n.length ? n[0] : null; }\n // https://developer.mozilla.org/en-US/docs/Web/API/Node.normalize\n function norm(el) { if (el.normalize) { el.normalize(); } return el; }\n // cast array x into numbers\n function numarray(x) {\n for (var j = 0, o = []; j < x.length; j++) { o[j] = parseFloat(x[j]); }\n return o;\n }\n // get the content of a text node, if any\n function nodeVal(x) {\n if (x) { norm(x); }\n return (x && x.textContent) || '';\n }\n // get the contents of multiple text nodes, if present\n function getMulti(x, ys) {\n var o = {}, n, k;\n for (k = 0; k < ys.length; k++) {\n n = get1(x, ys[k]);\n if (n) o[ys[k]] = nodeVal(n);\n }\n return o;\n }\n // add properties of Y to X, overwriting if present in both\n function extend(x, y) { for (var k in y) x[k] = y[k]; }\n // get one coordinate from a coordinate array, if any\n function coord1(v) { return numarray(v.replace(removeSpace, '').split(',')); }\n // get all coordinates from a coordinate array as [[],[]]\n function coord(v) {\n var coords = v.replace(trimSpace, '').split(splitSpace),\n o = [];\n for (var i = 0; i < coords.length; i++) {\n o.push(coord1(coords[i]));\n }\n return o;\n }\n function coordPair(x) {\n var ll = [attrf(x, 'lon'), attrf(x, 'lat')],\n ele = get1(x, 'ele'),\n // handle namespaced attribute in browser\n heartRate = get1(x, 'gpxtpx:hr') || get1(x, 'hr'),\n time = get1(x, 'time'),\n e;\n if (ele) {\n e = parseFloat(nodeVal(ele));\n if (!isNaN(e)) {\n ll.push(e);\n }\n }\n return {\n coordinates: ll,\n time: time ? nodeVal(time) : null,\n heartRate: heartRate ? parseFloat(nodeVal(heartRate)) : null\n };\n }\n\n // create a new feature collection parent object\n function fc() {\n return {\n type: 'FeatureCollection',\n features: []\n };\n }\n\n var serializer;\n if (typeof XMLSerializer !== 'undefined') {\n /* istanbul ignore next */\n serializer = new XMLSerializer();\n // only require xmldom in a node environment\n } else if (typeof exports === 'object' && typeof process === 'object' && !process.browser) {\n serializer = new (require('xmldom').XMLSerializer)();\n }\n function xml2str(str) {\n // IE9 will create a new XMLSerializer but it'll crash immediately.\n // This line is ignored because we don't run coverage tests in IE9\n /* istanbul ignore next */\n if (str.xml !== undefined) return str.xml;\n return serializer.serializeToString(str);\n }\n\n var t = {\n kml: function(doc) {\n\n var gj = fc(),\n // styleindex keeps track of hashed styles in order to match features\n styleIndex = {}, styleByHash = {},\n // stylemapindex keeps track of style maps to expose in properties\n styleMapIndex = {},\n // atomic geospatial types supported by KML - MultiGeometry is\n // handled separately\n geotypes = ['Polygon', 'LineString', 'Point', 'Track', 'gx:Track'],\n // all root placemarks in the file\n placemarks = get(doc, 'Placemark'),\n styles = get(doc, 'Style'),\n styleMaps = get(doc, 'StyleMap');\n\n for (var k = 0; k < styles.length; k++) {\n var hash = okhash(xml2str(styles[k])).toString(16);\n styleIndex['#' + attr(styles[k], 'id')] = hash;\n styleByHash[hash] = styles[k];\n }\n for (var l = 0; l < styleMaps.length; l++) {\n styleIndex['#' + attr(styleMaps[l], 'id')] = okhash(xml2str(styleMaps[l])).toString(16);\n var pairs = get(styleMaps[l], 'Pair');\n var pairsMap = {};\n for (var m = 0; m < pairs.length; m++) {\n pairsMap[nodeVal(get1(pairs[m], 'key'))] = nodeVal(get1(pairs[m], 'styleUrl'));\n }\n styleMapIndex['#' + attr(styleMaps[l], 'id')] = pairsMap;\n\n }\n for (var j = 0; j < placemarks.length; j++) {\n gj.features = gj.features.concat(getPlacemark(placemarks[j]));\n }\n function kmlColor(v) {\n var color, opacity;\n v = v || '';\n if (v.substr(0, 1) === '#') { v = v.substr(1); }\n if (v.length === 6 || v.length === 3) { color = v; }\n if (v.length === 8) {\n opacity = parseInt(v.substr(0, 2), 16) / 255;\n color = '#' + v.substr(6, 2) +\n v.substr(4, 2) +\n v.substr(2, 2);\n }\n return [color, isNaN(opacity) ? undefined : opacity];\n }\n function gxCoord(v) { return numarray(v.split(' ')); }\n function gxCoords(root) {\n var elems = get(root, 'coord', 'gx'), coords = [], times = [];\n if (elems.length === 0) elems = get(root, 'gx:coord');\n for (var i = 0; i < elems.length; i++) coords.push(gxCoord(nodeVal(elems[i])));\n var timeElems = get(root, 'when');\n for (var j = 0; j < timeElems.length; j++) times.push(nodeVal(timeElems[j]));\n return {\n coords: coords,\n times: times\n };\n }\n function getGeometry(root) {\n var geomNode, geomNodes, i, j, k, geoms = [], coordTimes = [];\n if (get1(root, 'MultiGeometry')) { return getGeometry(get1(root, 'MultiGeometry')); }\n if (get1(root, 'MultiTrack')) { return getGeometry(get1(root, 'MultiTrack')); }\n if (get1(root, 'gx:MultiTrack')) { return getGeometry(get1(root, 'gx:MultiTrack')); }\n for (i = 0; i < geotypes.length; i++) {\n geomNodes = get(root, geotypes[i]);\n if (geomNodes) {\n for (j = 0; j < geomNodes.length; j++) {\n geomNode = geomNodes[j];\n if (geotypes[i] === 'Point') {\n geoms.push({\n type: 'Point',\n coordinates: coord1(nodeVal(get1(geomNode, 'coordinates')))\n });\n } else if (geotypes[i] === 'LineString') {\n geoms.push({\n type: 'LineString',\n coordinates: coord(nodeVal(get1(geomNode, 'coordinates')))\n });\n } else if (geotypes[i] === 'Polygon') {\n var rings = get(geomNode, 'LinearRing'),\n coords = [];\n for (k = 0; k < rings.length; k++) {\n coords.push(coord(nodeVal(get1(rings[k], 'coordinates'))));\n }\n geoms.push({\n type: 'Polygon',\n coordinates: coords\n });\n } else if (geotypes[i] === 'Track' ||\n geotypes[i] === 'gx:Track') {\n var track = gxCoords(geomNode);\n geoms.push({\n type: 'LineString',\n coordinates: track.coords\n });\n if (track.times.length) coordTimes.push(track.times);\n }\n }\n }\n }\n return {\n geoms: geoms,\n coordTimes: coordTimes\n };\n }\n function getPlacemark(root) {\n var geomsAndTimes = getGeometry(root), i, properties = {},\n name = nodeVal(get1(root, 'name')),\n address = nodeVal(get1(root, 'address')),\n styleUrl = nodeVal(get1(root, 'styleUrl')),\n description = nodeVal(get1(root, 'description')),\n timeSpan = get1(root, 'TimeSpan'),\n timeStamp = get1(root, 'TimeStamp'),\n extendedData = get1(root, 'ExtendedData'),\n lineStyle = get1(root, 'LineStyle'),\n polyStyle = get1(root, 'PolyStyle'),\n visibility = get1(root, 'visibility');\n\n if (!geomsAndTimes.geoms.length) return [];\n if (name) properties.name = name;\n if (address) properties.address = address;\n if (styleUrl) {\n if (styleUrl[0] !== '#') {\n styleUrl = '#' + styleUrl;\n }\n\n properties.styleUrl = styleUrl;\n if (styleIndex[styleUrl]) {\n properties.styleHash = styleIndex[styleUrl];\n }\n if (styleMapIndex[styleUrl]) {\n properties.styleMapHash = styleMapIndex[styleUrl];\n properties.styleHash = styleIndex[styleMapIndex[styleUrl].normal];\n }\n // Try to populate the lineStyle or polyStyle since we got the style hash\n var style = styleByHash[properties.styleHash];\n if (style) {\n if (!lineStyle) lineStyle = get1(style, 'LineStyle');\n if (!polyStyle) polyStyle = get1(style, 'PolyStyle');\n }\n }\n if (description) properties.description = description;\n if (timeSpan) {\n var begin = nodeVal(get1(timeSpan, 'begin'));\n var end = nodeVal(get1(timeSpan, 'end'));\n properties.timespan = { begin: begin, end: end };\n }\n if (timeStamp) {\n properties.timestamp = nodeVal(get1(timeStamp, 'when'));\n }\n if (lineStyle) {\n var linestyles = kmlColor(nodeVal(get1(lineStyle, 'color'))),\n color = linestyles[0],\n opacity = linestyles[1],\n width = parseFloat(nodeVal(get1(lineStyle, 'width')));\n if (color) properties.stroke = color;\n if (!isNaN(opacity)) properties['stroke-opacity'] = opacity;\n if (!isNaN(width)) properties['stroke-width'] = width;\n }\n if (polyStyle) {\n var polystyles = kmlColor(nodeVal(get1(polyStyle, 'color'))),\n pcolor = polystyles[0],\n popacity = polystyles[1],\n fill = nodeVal(get1(polyStyle, 'fill')),\n outline = nodeVal(get1(polyStyle, 'outline'));\n if (pcolor) properties.fill = pcolor;\n if (!isNaN(popacity)) properties['fill-opacity'] = popacity;\n if (fill) properties['fill-opacity'] = fill === '1' ? properties['fill-opacity'] || 1 : 0;\n if (outline) properties['stroke-opacity'] = outline === '1' ? properties['stroke-opacity'] || 1 : 0;\n }\n if (extendedData) {\n var datas = get(extendedData, 'Data'),\n simpleDatas = get(extendedData, 'SimpleData');\n\n for (i = 0; i < datas.length; i++) {\n properties[datas[i].getAttribute('name')] = nodeVal(get1(datas[i], 'value'));\n }\n for (i = 0; i < simpleDatas.length; i++) {\n properties[simpleDatas[i].getAttribute('name')] = nodeVal(simpleDatas[i]);\n }\n }\n if (visibility) {\n properties.visibility = nodeVal(visibility);\n }\n if (geomsAndTimes.coordTimes.length) {\n properties.coordTimes = (geomsAndTimes.coordTimes.length === 1) ?\n geomsAndTimes.coordTimes[0] : geomsAndTimes.coordTimes;\n }\n var feature = {\n type: 'Feature',\n geometry: (geomsAndTimes.geoms.length === 1) ? geomsAndTimes.geoms[0] : {\n type: 'GeometryCollection',\n geometries: geomsAndTimes.geoms\n },\n properties: properties\n };\n if (attr(root, 'id')) feature.id = attr(root, 'id');\n return [feature];\n }\n return gj;\n },\n gpx: function(doc) {\n var i,\n tracks = get(doc, 'trk'),\n routes = get(doc, 'rte'),\n waypoints = get(doc, 'wpt'),\n // a feature collection\n gj = fc(),\n feature;\n for (i = 0; i < tracks.length; i++) {\n feature = getTrack(tracks[i]);\n if (feature) gj.features.push(feature);\n }\n for (i = 0; i < routes.length; i++) {\n feature = getRoute(routes[i]);\n if (feature) gj.features.push(feature);\n }\n for (i = 0; i < waypoints.length; i++) {\n gj.features.push(getPoint(waypoints[i]));\n }\n function getPoints(node, pointname) {\n var pts = get(node, pointname),\n line = [],\n times = [],\n heartRates = [],\n l = pts.length;\n if (l < 2) return {}; // Invalid line in GeoJSON\n for (var i = 0; i < l; i++) {\n var c = coordPair(pts[i]);\n line.push(c.coordinates);\n if (c.time) times.push(c.time);\n if (c.heartRate) heartRates.push(c.heartRate);\n }\n return {\n line: line,\n times: times,\n heartRates: heartRates\n };\n }\n function getTrack(node) {\n var segments = get(node, 'trkseg'),\n track = [],\n times = [],\n heartRates = [],\n line;\n for (var i = 0; i < segments.length; i++) {\n line = getPoints(segments[i], 'trkpt');\n if (line) {\n if (line.line) track.push(line.line);\n if (line.times && line.times.length) times.push(line.times);\n if (line.heartRates && line.heartRates.length) heartRates.push(line.heartRates);\n }\n }\n if (track.length === 0) return;\n var properties = getProperties(node);\n extend(properties, getLineStyle(get1(node, 'extensions')));\n if (times.length) properties.coordTimes = track.length === 1 ? times[0] : times;\n if (heartRates.length) properties.heartRates = track.length === 1 ? heartRates[0] : heartRates;\n return {\n type: 'Feature',\n properties: properties,\n geometry: {\n type: track.length === 1 ? 'LineString' : 'MultiLineString',\n coordinates: track.length === 1 ? track[0] : track\n }\n };\n }\n function getRoute(node) {\n var line = getPoints(node, 'rtept');\n if (!line.line) return;\n var prop = getProperties(node);\n extend(prop, getLineStyle(get1(node, 'extensions')));\n var routeObj = {\n type: 'Feature',\n properties: prop,\n geometry: {\n type: 'LineString',\n coordinates: line.line\n }\n };\n return routeObj;\n }\n function getPoint(node) {\n var prop = getProperties(node);\n extend(prop, getMulti(node, ['sym']));\n return {\n type: 'Feature',\n properties: prop,\n geometry: {\n type: 'Point',\n coordinates: coordPair(node).coordinates\n }\n };\n }\n function getLineStyle(extensions) {\n var style = {};\n if (extensions) {\n var lineStyle = get1(extensions, 'line');\n if (lineStyle) {\n var color = nodeVal(get1(lineStyle, 'color')),\n opacity = parseFloat(nodeVal(get1(lineStyle, 'opacity'))),\n width = parseFloat(nodeVal(get1(lineStyle, 'width')));\n if (color) style.stroke = color;\n if (!isNaN(opacity)) style['stroke-opacity'] = opacity;\n // GPX width is in mm, convert to px with 96 px per inch\n if (!isNaN(width)) style['stroke-width'] = width * 96 / 25.4;\n }\n }\n return style;\n }\n function getProperties(node) {\n var prop = getMulti(node, ['name', 'cmt', 'desc', 'type', 'time', 'keywords']),\n links = get(node, 'link');\n if (links.length) prop.links = [];\n for (var i = 0, link; i < links.length; i++) {\n link = { href: attr(links[i], 'href') };\n extend(link, getMulti(links[i], ['text', 'type']));\n prop.links.push(link);\n }\n return prop;\n }\n return gj;\n }\n };\n return t;\n})();\n\nif (typeof module !== 'undefined') module.exports = toGeoJSON;","import { geoExtent } from '../geo';\nimport { localizer, t } from '../core/localizer';\nimport toGeoJSON from '@mapbox/togeojson';\nimport { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { utilRebind } from '../util';\n\n\nexport function coreRapidContext(context) {\n const dispatch = d3_dispatch('task_extent_set');\n let _rapidContext = {};\n _rapidContext.version = '1.1.0';\n _rapidContext.showPowerUser = context.initialHashParams.poweruser === 'true';\n\n function distinct(value, index, self) {\n return self.indexOf(value) === index;\n }\n\n\n /* Task extents */\n let _taskExtent;\n let _isTaskBoundsRect = undefined;\n\n _rapidContext.setTaskExtentByGpxData = function(gpxData) {\n const dom = (new DOMParser()).parseFromString(gpxData, 'text/xml');\n const gj = toGeoJSON.gpx(dom);\n const lineStringCount = gj.features.reduce((accumulator, currentValue) => {\n return accumulator + (currentValue.geometry.type === 'LineString' ? 1 : 0);\n }, 0);\n\n if (gj.type === 'FeatureCollection') {\n let minlat, minlon, maxlat, maxlon;\n\n gj.features.forEach(f => {\n if (f.geometry.type === 'Point') {\n const lon = f.geometry.coordinates[0];\n const lat = f.geometry.coordinates[1];\n if (minlat === undefined || lat < minlat) minlat = lat;\n if (minlon === undefined || lon < minlon) minlon = lon;\n if (maxlat === undefined || lat > maxlat) maxlat = lat;\n if (maxlon === undefined || lon > maxlon) maxlon = lon;\n\n } else if (f.geometry.type === 'LineString' && lineStringCount === 1) {\n const lats = f.geometry.coordinates.map(f => f[0]);\n const lngs = f.geometry.coordinates.map(f => f[1]);\n const uniqueLats = lats.filter(distinct);\n const uniqueLngs = lngs.filter(distinct);\n let eachLatHas2Lngs = true;\n\n uniqueLats.forEach(lat => {\n const lngsForThisLat = f.geometry.coordinates\n .filter(coord => coord[0] === lat) // Filter the coords to the ones with this lat\n .map(coord => coord[1]) // Make an array of lngs that associate with that lat\n .filter(distinct); // Finally, filter for uniqueness\n\n if (lngsForThisLat.length !== 2) {\n eachLatHas2Lngs = false;\n }\n });\n // Check for exactly two unique latitudes, two unique longitudes,\n // and that each latitude was associated with exactly 2 longitudes,\n if (uniqueLats.length === 2 && uniqueLngs.length === 2 && eachLatHas2Lngs) {\n _isTaskBoundsRect = true;\n } else {\n _isTaskBoundsRect = false;\n }\n }\n });\n\n _taskExtent = new geoExtent([minlon, minlat], [maxlon, maxlat]);\n dispatch.call('task_extent_set');\n }\n };\n\n _rapidContext.getTaskExtent = () => _taskExtent;\n\n _rapidContext.isTaskRectangular = () => (!!_taskExtent && _isTaskBoundsRect);\n\n\n /* Sources */\n _rapidContext.sources = new Set();\n\n\n /* Colors */\n const RAPID_MAGENTA = '#da26d3';\n const COLORS = [\n '#ff0000', // red\n '#ffa500', // orange\n '#ffd700', // gold\n '#00ff00', // lime\n '#00ffff', // cyan\n '#1e90ff', // dodgerblue\n '#da26d3', // rapid magenta\n '#ffc0cb', // pink\n '#d3d3d3', // lightgray\n '#faf0e6' // linen\n ];\n _rapidContext.colors = () => COLORS;\n\n\n /* Available datasets */\n let _datasets = {};\n _rapidContext.datasets = () => _datasets;\n\n\n _rapidContext.init = () => {\n localizer.ensureLoaded()\n .then(() => {\n _datasets = {\n 'fbRoads': {\n id: 'fbRoads',\n beta: false,\n added: true, // whether it should appear in the list\n enabled: true, // whether the user has checked it on\n conflated: true,\n service: 'fbml',\n color: RAPID_MAGENTA,\n label: t('rapid_feature_toggle.fbRoads.label'),\n license_markdown: t('rapid_feature_toggle.fbRoads.license_markdown')\n },\n 'msBuildings': {\n id: 'msBuildings',\n beta: false,\n added: true, // whether it should appear in the list\n enabled: true, // whether the user has checked it on\n conflated: true,\n service: 'fbml',\n color: RAPID_MAGENTA,\n label: t('rapid_feature_toggle.msBuildings.label'),\n license_markdown: t('rapid_feature_toggle.msBuildings.license_markdown')\n }\n };\n });\n };\n\n /* reset any state here */\n _rapidContext.reset = () => {\n _rapidContext.sources = new Set();\n };\n\n\n return utilRebind(_rapidContext, dispatch, 'on');\n}\n","import deepEqual from 'fast-deep-equal';\n\nimport { geoVecEqual } from '../geo';\nimport { utilArrayDifference, utilArrayUnion, utilArrayUniq } from '../util/array';\n\n\n/*\n iD.coreDifference represents the difference between two graphs.\n It knows how to calculate the set of entities that were\n created, modified, or deleted, and also contains the logic\n for recursively extending a difference to the complete set\n of entities that will require a redraw, taking into account\n child and parent relationships.\n */\nexport function coreDifference(base, head) {\n var _changes = {};\n var _didChange = {}; // 'addition', 'deletion', 'geometry', 'properties'\n var _diff = {};\n\n function checkEntityID(id) {\n var h = head.entities[id];\n var b = base.entities[id];\n\n if (h === b) return;\n if (_changes[id]) return;\n\n if (!h && b) {\n _changes[id] = { base: b, head: h };\n _didChange.deletion = true;\n return;\n }\n if (h && !b) {\n _changes[id] = { base: b, head: h };\n _didChange.addition = true;\n return;\n }\n\n if (h && b) {\n if (h.members && b.members && !deepEqual(h.members, b.members)) {\n _changes[id] = { base: b, head: h };\n _didChange.geometry = true;\n _didChange.properties = true;\n return;\n }\n if (h.loc && b.loc && !geoVecEqual(h.loc, b.loc)) {\n _changes[id] = { base: b, head: h };\n _didChange.geometry = true;\n }\n if (h.nodes && b.nodes && !deepEqual(h.nodes, b.nodes)) {\n _changes[id] = { base: b, head: h };\n _didChange.geometry = true;\n }\n if (h.tags && b.tags && !deepEqual(h.tags, b.tags)) {\n _changes[id] = { base: b, head: h };\n _didChange.properties = true;\n }\n }\n }\n\n function load() {\n // HOT CODE: there can be many thousands of downloaded entities, so looping\n // through them all can become a performance bottleneck. Optimize by\n // resolving duplicates and using a basic `for` loop\n var ids = utilArrayUniq(Object.keys(head.entities).concat(Object.keys(base.entities)));\n for (var i = 0; i < ids.length; i++) {\n checkEntityID(ids[i]);\n }\n }\n load();\n\n\n _diff.length = function length() {\n return Object.keys(_changes).length;\n };\n\n\n _diff.changes = function changes() {\n return _changes;\n };\n\n _diff.didChange = _didChange;\n\n\n // pass true to include affected relation members\n _diff.extantIDs = function extantIDs(includeRelMembers) {\n var result = new Set();\n Object.keys(_changes).forEach(function(id) {\n if (_changes[id].head) {\n result.add(id);\n }\n\n var h = _changes[id].head;\n var b = _changes[id].base;\n var entity = h || b;\n\n if (includeRelMembers && entity.type === 'relation') {\n var mh = h ? h.members.map(function(m) { return m.id; }) : [];\n var mb = b ? b.members.map(function(m) { return m.id; }) : [];\n utilArrayUnion(mh, mb).forEach(function(memberID) {\n if (head.hasEntity(memberID)) {\n result.add(memberID);\n }\n });\n }\n });\n\n return Array.from(result);\n };\n\n\n _diff.modified = function modified() {\n var result = [];\n Object.values(_changes).forEach(function(change) {\n if (change.base && change.head) {\n result.push(change.head);\n }\n });\n return result;\n };\n\n\n _diff.created = function created() {\n var result = [];\n Object.values(_changes).forEach(function(change) {\n if (!change.base && change.head) {\n result.push(change.head);\n }\n });\n return result;\n };\n\n\n _diff.deleted = function deleted() {\n var result = [];\n Object.values(_changes).forEach(function(change) {\n if (change.base && !change.head) {\n result.push(change.base);\n }\n });\n return result;\n };\n\n\n _diff.summary = function summary() {\n var relevant = {};\n\n var keys = Object.keys(_changes);\n for (var i = 0; i < keys.length; i++) {\n var change = _changes[keys[i]];\n\n if (change.head && change.head.geometry(head) !== 'vertex') {\n addEntity(change.head, head, change.base ? 'modified' : 'created');\n\n } else if (change.base && change.base.geometry(base) !== 'vertex') {\n addEntity(change.base, base, 'deleted');\n\n } else if (change.base && change.head) { // modified vertex\n var moved = !deepEqual(change.base.loc, change.head.loc);\n var retagged = !deepEqual(change.base.tags, change.head.tags);\n\n if (moved) {\n addParents(change.head);\n }\n\n if (retagged || (moved && change.head.hasInterestingTags())) {\n addEntity(change.head, head, 'modified');\n }\n\n } else if (change.head && change.head.hasInterestingTags()) { // created vertex\n addEntity(change.head, head, 'created');\n\n } else if (change.base && change.base.hasInterestingTags()) { // deleted vertex\n addEntity(change.base, base, 'deleted');\n }\n }\n\n return Object.values(relevant);\n\n\n function addEntity(entity, graph, changeType) {\n relevant[entity.id] = {\n entity: entity,\n graph: graph,\n changeType: changeType\n };\n }\n\n function addParents(entity) {\n var parents = head.parentWays(entity);\n for (var j = parents.length - 1; j >= 0; j--) {\n var parent = parents[j];\n if (!(parent.id in relevant)) {\n addEntity(parent, head, 'modified');\n }\n }\n }\n };\n\n\n // returns complete set of entities that require a redraw\n // (optionally within given `extent`)\n _diff.complete = function complete(extent) {\n var result = {};\n var id, change;\n\n for (id in _changes) {\n change = _changes[id];\n\n var h = change.head;\n var b = change.base;\n var entity = h || b;\n var i;\n\n if (extent &&\n (!h || !h.intersects(extent, head)) &&\n (!b || !b.intersects(extent, base)))\n continue;\n\n result[id] = h;\n\n if (entity.type === 'way') {\n var nh = h ? h.nodes : [];\n var nb = b ? b.nodes : [];\n var diff;\n\n diff = utilArrayDifference(nh, nb);\n for (i = 0; i < diff.length; i++) {\n result[diff[i]] = head.hasEntity(diff[i]);\n }\n\n diff = utilArrayDifference(nb, nh);\n for (i = 0; i < diff.length; i++) {\n result[diff[i]] = head.hasEntity(diff[i]);\n }\n }\n\n if (entity.type === 'relation' && entity.isMultipolygon()) {\n var mh = h ? h.members.map(function(m) { return m.id; }) : [];\n var mb = b ? b.members.map(function(m) { return m.id; }) : [];\n var ids = utilArrayUnion(mh, mb);\n for (i = 0; i < ids.length; i++) {\n var member = head.hasEntity(ids[i]);\n if (!member) continue; // not downloaded\n if (extent && !member.intersects(extent, head)) continue; // not visible\n result[ids[i]] = member;\n }\n }\n\n addParents(head.parentWays(entity), result);\n addParents(head.parentRelations(entity), result);\n }\n\n return result;\n\n\n function addParents(parents, result) {\n for (var i = 0; i < parents.length; i++) {\n var parent = parents[i];\n if (parent.id in result) continue;\n\n result[parent.id] = parent;\n addParents(head.parentRelations(parent), result);\n }\n }\n };\n\n\n return _diff;\n}\n","\nexport default function quickselect(arr, k, left, right, compare) {\n quickselectStep(arr, k, left || 0, right || (arr.length - 1), compare || defaultCompare);\n}\n\nfunction quickselectStep(arr, k, left, right, compare) {\n\n while (right > left) {\n if (right - left > 600) {\n var n = right - left + 1;\n var m = k - left + 1;\n var z = Math.log(n);\n var s = 0.5 * Math.exp(2 * z / 3);\n var sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);\n var newLeft = Math.max(left, Math.floor(k - m * s / n + sd));\n var newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));\n quickselectStep(arr, k, newLeft, newRight, compare);\n }\n\n var t = arr[k];\n var i = left;\n var j = right;\n\n swap(arr, left, k);\n if (compare(arr[right], t) > 0) swap(arr, left, right);\n\n while (i < j) {\n swap(arr, i, j);\n i++;\n j--;\n while (compare(arr[i], t) < 0) i++;\n while (compare(arr[j], t) > 0) j--;\n }\n\n if (compare(arr[left], t) === 0) swap(arr, left, j);\n else {\n j++;\n swap(arr, j, right);\n }\n\n if (j <= k) left = j + 1;\n if (k <= j) right = j - 1;\n }\n}\n\nfunction swap(arr, i, j) {\n var tmp = arr[i];\n arr[i] = arr[j];\n arr[j] = tmp;\n}\n\nfunction defaultCompare(a, b) {\n return a < b ? -1 : a > b ? 1 : 0;\n}\n","import quickselect from 'quickselect';\n\nexport default class RBush {\n constructor(maxEntries = 9) {\n // max entries in a node is 9 by default; min node fill is 40% for best performance\n this._maxEntries = Math.max(4, maxEntries);\n this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4));\n this.clear();\n }\n\n all() {\n return this._all(this.data, []);\n }\n\n search(bbox) {\n let node = this.data;\n const result = [];\n\n if (!intersects(bbox, node)) return result;\n\n const toBBox = this.toBBox;\n const nodesToSearch = [];\n\n while (node) {\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n const childBBox = node.leaf ? toBBox(child) : child;\n\n if (intersects(bbox, childBBox)) {\n if (node.leaf) result.push(child);\n else if (contains(bbox, childBBox)) this._all(child, result);\n else nodesToSearch.push(child);\n }\n }\n node = nodesToSearch.pop();\n }\n\n return result;\n }\n\n collides(bbox) {\n let node = this.data;\n\n if (!intersects(bbox, node)) return false;\n\n const nodesToSearch = [];\n while (node) {\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n const childBBox = node.leaf ? this.toBBox(child) : child;\n\n if (intersects(bbox, childBBox)) {\n if (node.leaf || contains(bbox, childBBox)) return true;\n nodesToSearch.push(child);\n }\n }\n node = nodesToSearch.pop();\n }\n\n return false;\n }\n\n load(data) {\n if (!(data && data.length)) return this;\n\n if (data.length < this._minEntries) {\n for (let i = 0; i < data.length; i++) {\n this.insert(data[i]);\n }\n return this;\n }\n\n // recursively build the tree with the given data from scratch using OMT algorithm\n let node = this._build(data.slice(), 0, data.length - 1, 0);\n\n if (!this.data.children.length) {\n // save as is if tree is empty\n this.data = node;\n\n } else if (this.data.height === node.height) {\n // split root if trees have the same height\n this._splitRoot(this.data, node);\n\n } else {\n if (this.data.height < node.height) {\n // swap trees if inserted one is bigger\n const tmpNode = this.data;\n this.data = node;\n node = tmpNode;\n }\n\n // insert the small tree into the large tree at appropriate level\n this._insert(node, this.data.height - node.height - 1, true);\n }\n\n return this;\n }\n\n insert(item) {\n if (item) this._insert(item, this.data.height - 1);\n return this;\n }\n\n clear() {\n this.data = createNode([]);\n return this;\n }\n\n remove(item, equalsFn) {\n if (!item) return this;\n\n let node = this.data;\n const bbox = this.toBBox(item);\n const path = [];\n const indexes = [];\n let i, parent, goingUp;\n\n // depth-first iterative tree traversal\n while (node || path.length) {\n\n if (!node) { // go up\n node = path.pop();\n parent = path[path.length - 1];\n i = indexes.pop();\n goingUp = true;\n }\n\n if (node.leaf) { // check current node\n const index = findItem(item, node.children, equalsFn);\n\n if (index !== -1) {\n // item found, remove the item and condense tree upwards\n node.children.splice(index, 1);\n path.push(node);\n this._condense(path);\n return this;\n }\n }\n\n if (!goingUp && !node.leaf && contains(node, bbox)) { // go down\n path.push(node);\n indexes.push(i);\n i = 0;\n parent = node;\n node = node.children[0];\n\n } else if (parent) { // go right\n i++;\n node = parent.children[i];\n goingUp = false;\n\n } else node = null; // nothing found\n }\n\n return this;\n }\n\n toBBox(item) { return item; }\n\n compareMinX(a, b) { return a.minX - b.minX; }\n compareMinY(a, b) { return a.minY - b.minY; }\n\n toJSON() { return this.data; }\n\n fromJSON(data) {\n this.data = data;\n return this;\n }\n\n _all(node, result) {\n const nodesToSearch = [];\n while (node) {\n if (node.leaf) result.push(...node.children);\n else nodesToSearch.push(...node.children);\n\n node = nodesToSearch.pop();\n }\n return result;\n }\n\n _build(items, left, right, height) {\n\n const N = right - left + 1;\n let M = this._maxEntries;\n let node;\n\n if (N <= M) {\n // reached leaf level; return leaf\n node = createNode(items.slice(left, right + 1));\n calcBBox(node, this.toBBox);\n return node;\n }\n\n if (!height) {\n // target height of the bulk-loaded tree\n height = Math.ceil(Math.log(N) / Math.log(M));\n\n // target number of root entries to maximize storage utilization\n M = Math.ceil(N / Math.pow(M, height - 1));\n }\n\n node = createNode([]);\n node.leaf = false;\n node.height = height;\n\n // split the items into M mostly square tiles\n\n const N2 = Math.ceil(N / M);\n const N1 = N2 * Math.ceil(Math.sqrt(M));\n\n multiSelect(items, left, right, N1, this.compareMinX);\n\n for (let i = left; i <= right; i += N1) {\n\n const right2 = Math.min(i + N1 - 1, right);\n\n multiSelect(items, i, right2, N2, this.compareMinY);\n\n for (let j = i; j <= right2; j += N2) {\n\n const right3 = Math.min(j + N2 - 1, right2);\n\n // pack each entry recursively\n node.children.push(this._build(items, j, right3, height - 1));\n }\n }\n\n calcBBox(node, this.toBBox);\n\n return node;\n }\n\n _chooseSubtree(bbox, node, level, path) {\n while (true) {\n path.push(node);\n\n if (node.leaf || path.length - 1 === level) break;\n\n let minArea = Infinity;\n let minEnlargement = Infinity;\n let targetNode;\n\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n const area = bboxArea(child);\n const enlargement = enlargedArea(bbox, child) - area;\n\n // choose entry with the least area enlargement\n if (enlargement < minEnlargement) {\n minEnlargement = enlargement;\n minArea = area < minArea ? area : minArea;\n targetNode = child;\n\n } else if (enlargement === minEnlargement) {\n // otherwise choose one with the smallest area\n if (area < minArea) {\n minArea = area;\n targetNode = child;\n }\n }\n }\n\n node = targetNode || node.children[0];\n }\n\n return node;\n }\n\n _insert(item, level, isNode) {\n const bbox = isNode ? item : this.toBBox(item);\n const insertPath = [];\n\n // find the best node for accommodating the item, saving all nodes along the path too\n const node = this._chooseSubtree(bbox, this.data, level, insertPath);\n\n // put the item into the node\n node.children.push(item);\n extend(node, bbox);\n\n // split on node overflow; propagate upwards if necessary\n while (level >= 0) {\n if (insertPath[level].children.length > this._maxEntries) {\n this._split(insertPath, level);\n level--;\n } else break;\n }\n\n // adjust bboxes along the insertion path\n this._adjustParentBBoxes(bbox, insertPath, level);\n }\n\n // split overflowed node into two\n _split(insertPath, level) {\n const node = insertPath[level];\n const M = node.children.length;\n const m = this._minEntries;\n\n this._chooseSplitAxis(node, m, M);\n\n const splitIndex = this._chooseSplitIndex(node, m, M);\n\n const newNode = createNode(node.children.splice(splitIndex, node.children.length - splitIndex));\n newNode.height = node.height;\n newNode.leaf = node.leaf;\n\n calcBBox(node, this.toBBox);\n calcBBox(newNode, this.toBBox);\n\n if (level) insertPath[level - 1].children.push(newNode);\n else this._splitRoot(node, newNode);\n }\n\n _splitRoot(node, newNode) {\n // split root node\n this.data = createNode([node, newNode]);\n this.data.height = node.height + 1;\n this.data.leaf = false;\n calcBBox(this.data, this.toBBox);\n }\n\n _chooseSplitIndex(node, m, M) {\n let index;\n let minOverlap = Infinity;\n let minArea = Infinity;\n\n for (let i = m; i <= M - m; i++) {\n const bbox1 = distBBox(node, 0, i, this.toBBox);\n const bbox2 = distBBox(node, i, M, this.toBBox);\n\n const overlap = intersectionArea(bbox1, bbox2);\n const area = bboxArea(bbox1) + bboxArea(bbox2);\n\n // choose distribution with minimum overlap\n if (overlap < minOverlap) {\n minOverlap = overlap;\n index = i;\n\n minArea = area < minArea ? area : minArea;\n\n } else if (overlap === minOverlap) {\n // otherwise choose distribution with minimum area\n if (area < minArea) {\n minArea = area;\n index = i;\n }\n }\n }\n\n return index || M - m;\n }\n\n // sorts node children by the best axis for split\n _chooseSplitAxis(node, m, M) {\n const compareMinX = node.leaf ? this.compareMinX : compareNodeMinX;\n const compareMinY = node.leaf ? this.compareMinY : compareNodeMinY;\n const xMargin = this._allDistMargin(node, m, M, compareMinX);\n const yMargin = this._allDistMargin(node, m, M, compareMinY);\n\n // if total distributions margin value is minimal for x, sort by minX,\n // otherwise it's already sorted by minY\n if (xMargin < yMargin) node.children.sort(compareMinX);\n }\n\n // total margin of all possible split distributions where each node is at least m full\n _allDistMargin(node, m, M, compare) {\n node.children.sort(compare);\n\n const toBBox = this.toBBox;\n const leftBBox = distBBox(node, 0, m, toBBox);\n const rightBBox = distBBox(node, M - m, M, toBBox);\n let margin = bboxMargin(leftBBox) + bboxMargin(rightBBox);\n\n for (let i = m; i < M - m; i++) {\n const child = node.children[i];\n extend(leftBBox, node.leaf ? toBBox(child) : child);\n margin += bboxMargin(leftBBox);\n }\n\n for (let i = M - m - 1; i >= m; i--) {\n const child = node.children[i];\n extend(rightBBox, node.leaf ? toBBox(child) : child);\n margin += bboxMargin(rightBBox);\n }\n\n return margin;\n }\n\n _adjustParentBBoxes(bbox, path, level) {\n // adjust bboxes along the given tree path\n for (let i = level; i >= 0; i--) {\n extend(path[i], bbox);\n }\n }\n\n _condense(path) {\n // go through the path, removing empty nodes and updating bboxes\n for (let i = path.length - 1, siblings; i >= 0; i--) {\n if (path[i].children.length === 0) {\n if (i > 0) {\n siblings = path[i - 1].children;\n siblings.splice(siblings.indexOf(path[i]), 1);\n\n } else this.clear();\n\n } else calcBBox(path[i], this.toBBox);\n }\n }\n}\n\nfunction findItem(item, items, equalsFn) {\n if (!equalsFn) return items.indexOf(item);\n\n for (let i = 0; i < items.length; i++) {\n if (equalsFn(item, items[i])) return i;\n }\n return -1;\n}\n\n// calculate node's bbox from bboxes of its children\nfunction calcBBox(node, toBBox) {\n distBBox(node, 0, node.children.length, toBBox, node);\n}\n\n// min bounding rectangle of node children from k to p-1\nfunction distBBox(node, k, p, toBBox, destNode) {\n if (!destNode) destNode = createNode(null);\n destNode.minX = Infinity;\n destNode.minY = Infinity;\n destNode.maxX = -Infinity;\n destNode.maxY = -Infinity;\n\n for (let i = k; i < p; i++) {\n const child = node.children[i];\n extend(destNode, node.leaf ? toBBox(child) : child);\n }\n\n return destNode;\n}\n\nfunction extend(a, b) {\n a.minX = Math.min(a.minX, b.minX);\n a.minY = Math.min(a.minY, b.minY);\n a.maxX = Math.max(a.maxX, b.maxX);\n a.maxY = Math.max(a.maxY, b.maxY);\n return a;\n}\n\nfunction compareNodeMinX(a, b) { return a.minX - b.minX; }\nfunction compareNodeMinY(a, b) { return a.minY - b.minY; }\n\nfunction bboxArea(a) { return (a.maxX - a.minX) * (a.maxY - a.minY); }\nfunction bboxMargin(a) { return (a.maxX - a.minX) + (a.maxY - a.minY); }\n\nfunction enlargedArea(a, b) {\n return (Math.max(b.maxX, a.maxX) - Math.min(b.minX, a.minX)) *\n (Math.max(b.maxY, a.maxY) - Math.min(b.minY, a.minY));\n}\n\nfunction intersectionArea(a, b) {\n const minX = Math.max(a.minX, b.minX);\n const minY = Math.max(a.minY, b.minY);\n const maxX = Math.min(a.maxX, b.maxX);\n const maxY = Math.min(a.maxY, b.maxY);\n\n return Math.max(0, maxX - minX) *\n Math.max(0, maxY - minY);\n}\n\nfunction contains(a, b) {\n return a.minX <= b.minX &&\n a.minY <= b.minY &&\n b.maxX <= a.maxX &&\n b.maxY <= a.maxY;\n}\n\nfunction intersects(a, b) {\n return b.minX <= a.maxX &&\n b.minY <= a.maxY &&\n b.maxX >= a.minX &&\n b.maxY >= a.minY;\n}\n\nfunction createNode(children) {\n return {\n children,\n height: 1,\n leaf: true,\n minX: Infinity,\n minY: Infinity,\n maxX: -Infinity,\n maxY: -Infinity\n };\n}\n\n// sort an array so that items come in groups of n unsorted items, with groups sorted between each other;\n// combines selection algorithm with binary divide & conquer approach\n\nfunction multiSelect(arr, left, right, n, compare) {\n const stack = [left, right];\n\n while (stack.length) {\n right = stack.pop();\n left = stack.pop();\n\n if (right - left <= n) continue;\n\n const mid = left + Math.ceil((right - left) / n / 2) * n;\n quickselect(arr, mid, left, right, compare);\n\n stack.push(left, mid, mid, right);\n }\n}\n","import RBush from 'rbush';\n\nimport { coreDifference } from './difference';\n\n\nexport function coreTree(head) {\n // tree for entities\n var _rtree = new RBush();\n var _bboxes = {};\n\n // maintain a separate tree for granular way segments\n var _segmentsRTree = new RBush();\n var _segmentsBBoxes = {};\n var _segmentsByWayId = {};\n\n var tree = {};\n\n\n function entityBBox(entity) {\n var bbox = entity.extent(head).bbox();\n bbox.id = entity.id;\n _bboxes[entity.id] = bbox;\n return bbox;\n }\n\n\n function segmentBBox(segment) {\n var extent = segment.extent(head);\n // extent can be null if the node entites aren't in the graph for some reason\n if (!extent) return null;\n\n var bbox = extent.bbox();\n bbox.segment = segment;\n _segmentsBBoxes[segment.id] = bbox;\n return bbox;\n }\n\n\n function removeEntity(entity) {\n _rtree.remove(_bboxes[entity.id]);\n delete _bboxes[entity.id];\n\n if (_segmentsByWayId[entity.id]) {\n _segmentsByWayId[entity.id].forEach(function(segment) {\n _segmentsRTree.remove(_segmentsBBoxes[segment.id]);\n delete _segmentsBBoxes[segment.id];\n });\n delete _segmentsByWayId[entity.id];\n }\n }\n\n\n function loadEntities(entities) {\n _rtree.load(entities.map(entityBBox));\n\n var segments = [];\n entities.forEach(function(entity) {\n if (entity.segments) {\n var entitySegments = entity.segments(head);\n // cache these to make them easy to remove later\n _segmentsByWayId[entity.id] = entitySegments;\n segments = segments.concat(entitySegments);\n }\n });\n if (segments.length) _segmentsRTree.load(segments.map(segmentBBox).filter(Boolean));\n }\n\n\n function updateParents(entity, insertions, memo) {\n head.parentWays(entity).forEach(function(way) {\n if (_bboxes[way.id]) {\n removeEntity(way);\n insertions[way.id] = way;\n }\n updateParents(way, insertions, memo);\n });\n\n head.parentRelations(entity).forEach(function(relation) {\n if (memo[entity.id]) return;\n memo[entity.id] = true;\n if (_bboxes[relation.id]) {\n removeEntity(relation);\n insertions[relation.id] = relation;\n }\n updateParents(relation, insertions, memo);\n });\n }\n\n\n tree.rebase = function(entities, force) {\n var insertions = {};\n\n for (var i = 0; i < entities.length; i++) {\n var entity = entities[i];\n if (!entity.visible) continue;\n\n if (head.entities.hasOwnProperty(entity.id) || _bboxes[entity.id]) {\n if (!force) {\n continue;\n } else if (_bboxes[entity.id]) {\n removeEntity(entity);\n }\n }\n\n insertions[entity.id] = entity;\n updateParents(entity, insertions, {});\n }\n\n loadEntities(Object.values(insertions));\n\n return tree;\n };\n\n\n function updateToGraph(graph) {\n if (graph === head) return;\n\n var diff = coreDifference(head, graph);\n\n head = graph;\n\n var changed = diff.didChange;\n if (!changed.addition && !changed.deletion && !changed.geometry) return;\n\n var insertions = {};\n\n if (changed.deletion) {\n diff.deleted().forEach(function(entity) {\n removeEntity(entity);\n });\n }\n\n if (changed.geometry) {\n diff.modified().forEach(function(entity) {\n removeEntity(entity);\n insertions[entity.id] = entity;\n updateParents(entity, insertions, {});\n });\n }\n\n if (changed.addition) {\n diff.created().forEach(function(entity) {\n insertions[entity.id] = entity;\n });\n }\n\n loadEntities(Object.values(insertions));\n }\n\n // returns an array of entities with bounding boxes overlapping `extent` for the given `graph`\n tree.intersects = function(extent, graph) {\n updateToGraph(graph);\n return _rtree.search(extent.bbox())\n .map(function(bbox) { return graph.entity(bbox.id); });\n };\n\n // returns an array of segment objects with bounding boxes overlapping `extent` for the given `graph`\n tree.waySegments = function(extent, graph) {\n updateToGraph(graph);\n return _segmentsRTree.search(extent.bbox())\n .map(function(bbox) { return bbox.segment; });\n };\n\n\n return tree;\n}\n","export function svgIcon(name, svgklass, useklass) {\n return function drawIcon(selection) {\n selection.selectAll('svg.icon' + (svgklass ? '.' + svgklass.split(' ')[0] : ''))\n .data([0])\n .enter()\n .append('svg')\n .attr('class', 'icon ' + (svgklass || ''))\n .append('use')\n .attr('xlink:href', name)\n .attr('class', useklass);\n };\n}\n","import { event as d3_event, select as d3_select } from 'd3-selection';\n\nimport { svgIcon } from '../svg/icon';\nimport { utilKeybinding } from '../util';\n\n\nexport function uiModal(selection, blocking) {\n let keybinding = utilKeybinding('modal');\n let previous = selection.select('div.modal');\n let animate = previous.empty();\n\n previous.transition()\n .duration(200)\n .style('opacity', 0)\n .remove();\n\n let shaded = selection\n .append('div')\n .attr('class', 'shaded')\n .style('opacity', 0);\n\n shaded.close = () => {\n shaded\n .transition()\n .duration(200)\n .style('opacity',0)\n .remove();\n\n modal\n .transition()\n .duration(200)\n .style('top','0px');\n\n d3_select(document)\n .call(keybinding.unbind);\n };\n\n\n let modal = shaded\n .append('div')\n .attr('class', 'modal fillL');\n\n if (!blocking) {\n shaded.on('click.remove-modal', () => {\n if (d3_event.target === this) {\n shaded.close();\n }\n });\n\n modal\n .append('button')\n .attr('class', 'close')\n .on('click', shaded.close)\n .call(svgIcon('#iD-icon-close'));\n\n keybinding\n .on('⌫', shaded.close)\n .on('⎋', shaded.close);\n\n d3_select(document)\n .call(keybinding);\n }\n\n modal\n .append('div')\n .attr('class', 'content');\n\n if (animate) {\n shaded.transition().style('opacity', 1);\n } else {\n shaded.style('opacity', 1);\n }\n\n return shaded;\n}\n","import { select as d3_select } from 'd3-selection';\nimport { uiModal } from './modal';\n\n\nexport function uiLoading(context) {\n let _modalSelection = d3_select(null);\n let _message = '';\n let _blocking = false;\n\n\n let loading = (selection) => {\n _modalSelection = uiModal(selection, _blocking);\n\n let loadertext = _modalSelection.select('.content')\n .classed('loading-modal', true)\n .append('div')\n .attr('class', 'modal-section fillL');\n\n loadertext\n .append('img')\n .attr('class', 'loader')\n .attr('src', context.imagePath('loader-white.gif'));\n\n loadertext\n .append('h3')\n .text(_message);\n\n _modalSelection.select('button.close')\n .attr('class', 'hide');\n\n return loading;\n };\n\n\n loading.message = function(val) {\n if (!arguments.length) return _message;\n _message = val;\n return loading;\n };\n\n\n loading.blocking = function(val) {\n if (!arguments.length) return _blocking;\n _blocking = val;\n return loading;\n };\n\n\n loading.close = () => {\n _modalSelection.remove();\n };\n\n\n loading.isShown = () => {\n return _modalSelection && !_modalSelection.empty() && _modalSelection.node().parentNode;\n };\n\n\n return loading;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { easeLinear as d3_easeLinear } from 'd3-ease';\nimport { select as d3_select } from 'd3-selection';\n\nimport { prefs } from './preferences';\nimport { coreDifference } from './difference';\nimport { coreGraph } from './graph';\nimport { coreTree } from './tree';\nimport { osmEntity } from '../osm/entity';\nimport { uiLoading } from '../ui/loading';\nimport {\n utilArrayDifference, utilArrayGroupBy, utilArrayUnion,\n utilObjectOmit, utilRebind, utilSessionMutex\n} from '../util';\n\n\nexport function coreHistory(context) {\n var dispatch = d3_dispatch('change', 'merge', 'restore', 'undone', 'redone');\n var lock = utilSessionMutex('lock');\n\n // restorable if iD not open in another window/tab and a saved history exists in localStorage\n var _hasUnresolvedRestorableChanges = lock.lock() && !!prefs(getKey('saved_history'));\n\n var duration = 150;\n var _imageryUsed = [];\n var _photoOverlaysUsed = [];\n var _checkpoints = {};\n var _pausedGraph;\n var _stack;\n var _index;\n var _tree;\n\n\n // internal _act, accepts list of actions and eased time\n function _act(actions, t) {\n actions = Array.prototype.slice.call(actions);\n\n var annotation;\n if (typeof actions[actions.length - 1] !== 'function') {\n annotation = actions.pop();\n }\n\n var graph = _stack[_index].graph;\n for (var i = 0; i < actions.length; i++) {\n graph = actions[i](graph, t);\n }\n\n return {\n graph: graph,\n annotation: annotation,\n imageryUsed: _imageryUsed,\n photoOverlaysUsed: _photoOverlaysUsed,\n transform: context.projection.transform(),\n selectedIDs: context.selectedIDs()\n };\n }\n\n\n // internal _perform with eased time\n function _perform(args, t) {\n var previous = _stack[_index].graph;\n _stack = _stack.slice(0, _index + 1);\n var actionResult = _act(args, t);\n _stack.push(actionResult);\n _index++;\n return change(previous);\n }\n\n\n // internal _replace with eased time\n function _replace(args, t) {\n var previous = _stack[_index].graph;\n // assert(_index == _stack.length - 1)\n var actionResult = _act(args, t);\n _stack[_index] = actionResult;\n return change(previous);\n }\n\n\n // internal _overwrite with eased time\n function _overwrite(args, t) {\n var previous = _stack[_index].graph;\n if (_index > 0) {\n _index--;\n _stack.pop();\n }\n _stack = _stack.slice(0, _index + 1);\n var actionResult = _act(args, t);\n _stack.push(actionResult);\n _index++;\n return change(previous);\n }\n\n\n // determine difference and dispatch a change event\n function change(previous) {\n var difference = coreDifference(previous, history.graph());\n if (!_pausedGraph) {\n dispatch.call('change', this, difference);\n }\n return difference;\n }\n\n\n // iD uses namespaced keys so multiple installations do not conflict\n function getKey(n) {\n return 'iD_' + window.location.origin + '_' + n;\n }\n\n\n var history = {\n\n graph: function() {\n return _stack[_index].graph;\n },\n\n\n tree: function() {\n return _tree;\n },\n\n\n base: function() {\n return _stack[0].graph;\n },\n\n\n peekAnnotation: function() {\n return _stack[_index].annotation;\n },\n\n\n peekAllAnnotations: function() {\n var result = [];\n for (var i = 0; i <= _index; i++) {\n if (_stack[i].annotation) {\n result.push(_stack[i].annotation);\n }\n }\n return result;\n },\n\n\n merge: function(entities/*, extent*/) {\n var stack = _stack.map(function(state) { return state.graph; });\n _stack[0].graph.rebase(entities, stack, false);\n _tree.rebase(entities, false);\n\n dispatch.call('merge', this, entities);\n },\n\n\n perform: function() {\n // complete any transition already in progress\n d3_select(document).interrupt('history.perform');\n\n var transitionable = false;\n var action0 = arguments[0];\n\n if (arguments.length === 1 ||\n (arguments.length === 2 && (typeof arguments[1] !== 'function'))) {\n transitionable = !!action0.transitionable;\n }\n\n if (transitionable) {\n var origArguments = arguments;\n d3_select(document)\n .transition('history.perform')\n .duration(duration)\n .ease(d3_easeLinear)\n .tween('history.tween', function() {\n return function(t) {\n if (t < 1) _overwrite([action0], t);\n };\n })\n .on('start', function() {\n _perform([action0], 0);\n })\n .on('end interrupt', function() {\n _overwrite(origArguments, 1);\n });\n\n } else {\n return _perform(arguments);\n }\n },\n\n\n replace: function() {\n d3_select(document).interrupt('history.perform');\n return _replace(arguments, 1);\n },\n\n\n // Same as calling pop and then perform\n overwrite: function() {\n d3_select(document).interrupt('history.perform');\n return _overwrite(arguments, 1);\n },\n\n\n pop: function(n) {\n d3_select(document).interrupt('history.perform');\n\n var previous = _stack[_index].graph;\n if (isNaN(+n) || +n < 0) {\n n = 1;\n }\n while (n-- > 0 && _index > 0) {\n _index--;\n _stack.pop();\n }\n return change(previous);\n },\n\n\n // Back to the previous annotated state or _index = 0.\n undo: function() {\n d3_select(document).interrupt('history.perform');\n\n var previousStack = _stack[_index];\n var previous = previousStack.graph;\n while (_index > 0) {\n _index--;\n if (_stack[_index].annotation) break;\n }\n\n dispatch.call('undone', this, _stack[_index], previousStack);\n return change(previous);\n },\n\n\n // Forward to the next annotated state.\n redo: function() {\n d3_select(document).interrupt('history.perform');\n\n var previousStack = _stack[_index];\n var previous = previousStack.graph;\n var tryIndex = _index;\n while (tryIndex < _stack.length - 1) {\n tryIndex++;\n if (_stack[tryIndex].annotation) {\n _index = tryIndex;\n dispatch.call('redone', this, _stack[_index], previousStack);\n break;\n }\n }\n\n return change(previous);\n },\n\n\n pauseChangeDispatch: function() {\n if (!_pausedGraph) {\n _pausedGraph = _stack[_index].graph;\n }\n },\n\n\n resumeChangeDispatch: function() {\n if (_pausedGraph) {\n var previous = _pausedGraph;\n _pausedGraph = null;\n return change(previous);\n }\n },\n\n\n undoAnnotation: function() {\n var i = _index;\n while (i >= 0) {\n if (_stack[i].annotation) return _stack[i].annotation;\n i--;\n }\n },\n\n\n redoAnnotation: function() {\n var i = _index + 1;\n while (i <= _stack.length - 1) {\n if (_stack[i].annotation) return _stack[i].annotation;\n i++;\n }\n },\n\n\n // Returns the entities from the active graph with bounding boxes\n // overlapping the given `extent`.\n intersects: function(extent) {\n return _tree.intersects(extent, _stack[_index].graph);\n },\n\n\n difference: function() {\n var base = _stack[0].graph;\n var head = _stack[_index].graph;\n return coreDifference(base, head);\n },\n\n\n changes: function(action) {\n var base = _stack[0].graph;\n var head = _stack[_index].graph;\n\n if (action) {\n head = action(head);\n }\n\n var difference = coreDifference(base, head);\n\n return {\n modified: difference.modified(),\n created: difference.created(),\n deleted: difference.deleted()\n };\n },\n\n\n hasChanges: function() {\n return this.difference().length() > 0;\n },\n\n\n imageryUsed: function(sources) {\n if (sources) {\n _imageryUsed = sources;\n return history;\n } else {\n var s = new Set();\n _stack.slice(1, _index + 1).forEach(function(state) {\n state.imageryUsed.forEach(function(source) {\n if (source !== 'Custom') {\n s.add(source);\n }\n });\n });\n return Array.from(s);\n }\n },\n\n\n photoOverlaysUsed: function(sources) {\n if (sources) {\n _photoOverlaysUsed = sources;\n return history;\n } else {\n var s = new Set();\n _stack.slice(1, _index + 1).forEach(function(state) {\n if (state.photoOverlaysUsed && Array.isArray(state.photoOverlaysUsed)) {\n state.photoOverlaysUsed.forEach(function(photoOverlay) {\n s.add(photoOverlay);\n });\n }\n });\n return Array.from(s);\n }\n },\n\n\n // save the current history state\n checkpoint: function(key) {\n _checkpoints[key] = {\n stack: _stack,\n index: _index\n };\n return history;\n },\n\n\n // restore history state to a given checkpoint or reset completely\n reset: function(key) {\n if (key !== undefined && _checkpoints.hasOwnProperty(key)) {\n _stack = _checkpoints[key].stack;\n _index = _checkpoints[key].index;\n } else {\n _stack = [{graph: coreGraph()}];\n _index = 0;\n _tree = coreTree(_stack[0].graph);\n _checkpoints = {};\n }\n dispatch.call('change');\n dispatch.call('restore');\n return history;\n },\n\n\n // `toIntroGraph()` is used to export the intro graph used by the walkthrough.\n //\n // To use it:\n // 1. Start the walkthrough.\n // 2. Get to a \"free editing\" tutorial step\n // 3. Make your edits to the walkthrough map\n // 4. In your browser dev console run:\n // `id.history().toIntroGraph()`\n // 5. This outputs stringified JSON to the browser console\n // 6. Copy it to `data/intro_graph.json` and prettify it in your code editor\n toIntroGraph: function() {\n var nextID = { n: 0, r: 0, w: 0 };\n var permIDs = {};\n var graph = this.graph();\n var baseEntities = {};\n\n // clone base entities..\n Object.values(graph.base().entities).forEach(function(entity) {\n var copy = copyIntroEntity(entity);\n baseEntities[copy.id] = copy;\n });\n\n // replace base entities with head entities..\n Object.keys(graph.entities).forEach(function(id) {\n var entity = graph.entities[id];\n if (entity) {\n var copy = copyIntroEntity(entity);\n baseEntities[copy.id] = copy;\n } else {\n delete baseEntities[id];\n }\n });\n\n // swap temporary for permanent ids..\n Object.values(baseEntities).forEach(function(entity) {\n if (Array.isArray(entity.nodes)) {\n entity.nodes = entity.nodes.map(function(node) {\n return permIDs[node] || node;\n });\n }\n if (Array.isArray(entity.members)) {\n entity.members = entity.members.map(function(member) {\n member.id = permIDs[member.id] || member.id;\n return member;\n });\n }\n });\n\n return JSON.stringify({ dataIntroGraph: baseEntities });\n\n\n function copyIntroEntity(source) {\n var copy = utilObjectOmit(source, ['type', 'user', 'v', 'version', 'visible']);\n\n // Note: the copy is no longer an osmEntity, so it might not have `tags`\n if (copy.tags && !Object.keys(copy.tags)) {\n delete copy.tags;\n }\n\n if (Array.isArray(copy.loc)) {\n copy.loc[0] = +copy.loc[0].toFixed(6);\n copy.loc[1] = +copy.loc[1].toFixed(6);\n }\n\n var match = source.id.match(/([nrw])-\\d*/); // temporary id\n if (match !== null) {\n var nrw = match[1];\n var permID;\n do { permID = nrw + (++nextID[nrw]); }\n while (baseEntities.hasOwnProperty(permID));\n\n copy.id = permIDs[source.id] = permID;\n }\n return copy;\n }\n },\n\n\n toJSON: function() {\n if (!this.hasChanges()) return;\n\n var allEntities = {};\n var baseEntities = {};\n var base = _stack[0];\n\n var s = _stack.map(function(i) {\n var modified = [];\n var deleted = [];\n\n Object.keys(i.graph.entities).forEach(function(id) {\n var entity = i.graph.entities[id];\n if (entity) {\n var key = osmEntity.key(entity);\n allEntities[key] = entity;\n modified.push(key);\n } else {\n deleted.push(id);\n }\n\n // make sure that the originals of changed or deleted entities get merged\n // into the base of the _stack after restoring the data from JSON.\n if (id in base.graph.entities) {\n baseEntities[id] = base.graph.entities[id];\n }\n if (entity && entity.nodes) {\n // get originals of pre-existing child nodes\n entity.nodes.forEach(function(nodeID) {\n if (nodeID in base.graph.entities) {\n baseEntities[nodeID] = base.graph.entities[nodeID];\n }\n });\n }\n // get originals of parent entities too\n var baseParents = base.graph._parentWays[id];\n if (baseParents) {\n baseParents.forEach(function(parentID) {\n if (parentID in base.graph.entities) {\n baseEntities[parentID] = base.graph.entities[parentID];\n }\n });\n }\n });\n\n var x = {};\n\n if (modified.length) x.modified = modified;\n if (deleted.length) x.deleted = deleted;\n if (i.imageryUsed) x.imageryUsed = i.imageryUsed;\n if (i.photoOverlaysUsed) x.photoOverlaysUsed = i.photoOverlaysUsed;\n if (i.annotation) x.annotation = i.annotation;\n if (i.transform) x.transform = i.transform;\n if (i.selectedIDs) x.selectedIDs = i.selectedIDs;\n\n return x;\n });\n\n return JSON.stringify({\n version: 3,\n entities: Object.values(allEntities),\n baseEntities: Object.values(baseEntities),\n stack: s,\n nextIDs: osmEntity.id.next,\n index: _index,\n // note the time the changes were saved\n timestamp: (new Date()).getTime()\n });\n },\n\n\n fromJSON: function(json, loadChildNodes) {\n var h = JSON.parse(json);\n var loadComplete = true;\n\n osmEntity.id.next = h.nextIDs;\n _index = h.index;\n\n if (h.version === 2 || h.version === 3) {\n var allEntities = {};\n\n h.entities.forEach(function(entity) {\n allEntities[osmEntity.key(entity)] = osmEntity(entity);\n });\n\n if (h.version === 3) {\n // This merges originals for changed entities into the base of\n // the _stack even if the current _stack doesn't have them (for\n // example when iD has been restarted in a different region)\n var baseEntities = h.baseEntities.map(function(d) { return osmEntity(d); });\n var stack = _stack.map(function(state) { return state.graph; });\n _stack[0].graph.rebase(baseEntities, stack, true);\n _tree.rebase(baseEntities, true);\n\n // When we restore a modified way, we also need to fetch any missing\n // childnodes that would normally have been downloaded with it.. #2142\n if (loadChildNodes) {\n var osm = context.connection();\n var baseWays = baseEntities\n .filter(function(e) { return e.type === 'way'; });\n var nodeIDs = baseWays\n .reduce(function(acc, way) { return utilArrayUnion(acc, way.nodes); }, []);\n var missing = nodeIDs\n .filter(function(n) { return !_stack[0].graph.hasEntity(n); });\n\n if (missing.length && osm) {\n loadComplete = false;\n context.map().redrawEnable(false);\n\n var loading = uiLoading(context).blocking(true);\n context.container().call(loading);\n\n var childNodesLoaded = function(err, result) {\n if (!err) {\n var visibleGroups = utilArrayGroupBy(result.data, 'visible');\n var visibles = visibleGroups.true || []; // alive nodes\n var invisibles = visibleGroups.false || []; // deleted nodes\n\n if (visibles.length) {\n var visibleIDs = visibles.map(function(entity) { return entity.id; });\n var stack = _stack.map(function(state) { return state.graph; });\n missing = utilArrayDifference(missing, visibleIDs);\n _stack[0].graph.rebase(visibles, stack, true);\n _tree.rebase(visibles, true);\n }\n\n // fetch older versions of nodes that were deleted..\n invisibles.forEach(function(entity) {\n osm.loadEntityVersion(entity.id, +entity.version - 1, childNodesLoaded);\n });\n }\n\n if (err || !missing.length) {\n loading.close();\n context.map().redrawEnable(true);\n dispatch.call('change');\n dispatch.call('restore', this);\n }\n };\n\n osm.loadMultiple(missing, childNodesLoaded);\n }\n }\n }\n\n _stack = h.stack.map(function(d) {\n var entities = {}, entity;\n\n if (d.modified) {\n d.modified.forEach(function(key) {\n entity = allEntities[key];\n entities[entity.id] = entity;\n });\n }\n\n if (d.deleted) {\n d.deleted.forEach(function(id) {\n entities[id] = undefined;\n });\n }\n\n return {\n graph: coreGraph(_stack[0].graph).load(entities),\n annotation: d.annotation,\n imageryUsed: d.imageryUsed,\n photoOverlaysUsed: d.photoOverlaysUsed,\n transform: d.transform,\n selectedIDs: d.selectedIDs\n };\n });\n\n } else { // original version\n _stack = h.stack.map(function(d) {\n var entities = {};\n\n for (var i in d.entities) {\n var entity = d.entities[i];\n entities[i] = entity === 'undefined' ? undefined : osmEntity(entity);\n }\n\n d.graph = coreGraph(_stack[0].graph).load(entities);\n return d;\n });\n }\n\n var transform = _stack[_index].transform;\n if (transform) {\n context.map().transformEase(transform, 0); // 0 = immediate, no easing\n }\n\n if (loadComplete) {\n dispatch.call('change');\n dispatch.call('restore', this);\n }\n\n return history;\n },\n\n\n lock: function() {\n return lock.lock();\n },\n\n\n unlock: function() {\n lock.unlock();\n },\n\n\n save: function() {\n if (lock.locked() &&\n // don't overwrite existing, unresolved changes\n !_hasUnresolvedRestorableChanges) {\n\n prefs(getKey('saved_history'), history.toJSON() || null);\n }\n return history;\n },\n\n\n // delete the history version saved in localStorage\n clearSaved: function() {\n context.debouncedSave.cancel();\n if (lock.locked()) {\n _hasUnresolvedRestorableChanges = false;\n prefs(getKey('saved_history'), null);\n\n // clear the changeset metadata associated with the saved history\n prefs('comment', null);\n prefs('hashtags', null);\n prefs('source', null);\n }\n return history;\n },\n\n\n savedHistoryJSON: function() {\n return prefs(getKey('saved_history'));\n },\n\n\n hasRestorableChanges: function() {\n return _hasUnresolvedRestorableChanges;\n },\n\n\n // load history from a version stored in localStorage\n restore: function() {\n if (lock.locked()) {\n _hasUnresolvedRestorableChanges = false;\n var json = this.savedHistoryJSON();\n if (json) history.fromJSON(json, true);\n }\n },\n\n\n _getKey: getKey\n\n };\n\n\n history.reset();\n\n return utilRebind(history, dispatch, 'on');\n}\n","import { geoExtent } from '../../geo';\nimport { t } from '../../core/localizer';\n\nexport function validationIssue(attrs) {\n this.type = attrs.type; // required - name of rule that created the issue (e.g. 'missing_tag')\n this.subtype = attrs.subtype; // optional - category of the issue within the type (e.g. 'relation_type' under 'missing_tag')\n this.severity = attrs.severity; // required - 'warning' or 'error'\n this.message = attrs.message; // required - function returning localized string\n this.reference = attrs.reference; // optional - function(selection) to render reference information\n this.entityIds = attrs.entityIds; // optional - array of IDs of entities involved in the issue\n this.loc = attrs.loc; // optional - [lon, lat] to zoom in on to see the issue\n this.data = attrs.data; // optional - object containing extra data for the fixes\n this.dynamicFixes = attrs.dynamicFixes;// optional - function(context) returning fixes\n this.hash = attrs.hash; // optional - string to further differentiate the issue\n\n this.id = generateID.apply(this); // generated - see below\n// this.autoFix = null; // generated - if autofix exists, will be set below\n this.autoArgs = attrs.autoArgs; // optional - if this issue can be autofixed, supply the autofix args at issue creation\n\n // A unique, deterministic string hash.\n // Issues with identical id values are considered identical.\n function generateID() {\n var parts = [this.type];\n\n if (this.hash) { // subclasses can pass in their own differentiator\n parts.push(this.hash);\n }\n\n if (this.subtype) {\n parts.push(this.subtype);\n }\n\n // include the entities this issue is for\n // (sort them so the id is deterministic)\n if (this.entityIds) {\n var entityKeys = this.entityIds.slice().sort();\n parts.push.apply(parts, entityKeys);\n }\n\n return parts.join(':');\n }\n\n this.extent = function(resolver) {\n if (this.loc) {\n return geoExtent(this.loc);\n }\n if (this.entityIds && this.entityIds.length) {\n return this.entityIds.reduce(function(extent, entityId) {\n return extent.extend(resolver.entity(entityId).extent(resolver));\n }, geoExtent());\n }\n return null;\n };\n\n this.fixes = function(context) {\n var fixes = this.dynamicFixes ? this.dynamicFixes(context) : [];\n var issue = this;\n\n if (issue.severity === 'warning') {\n // allow ignoring any issue that's not an error\n fixes.push(new validationIssueFix({\n title: t('issues.fix.ignore_issue.title'),\n icon: 'iD-icon-close',\n onClick: function() {\n context.validator().ignoreIssue(this.issue.id);\n }\n }));\n }\n\n fixes.forEach(function(fix) {\n fix.id = fix.title;\n // add a reference to the issue for use in actions\n fix.issue = issue;\n// if (fix.autoArgs) {\n// issue.autoFix = fix;\n// }\n });\n return fixes;\n };\n\n}\n\n\nexport function validationIssueFix(attrs) {\n this.title = attrs.title; // Required\n this.onClick = attrs.onClick; // Optional - the function to run to apply the fix\n this.disabledReason = attrs.disabledReason; // Optional - a string explaining why the fix is unavailable, if any\n this.icon = attrs.icon; // Optional - shows 'iD-icon-wrench' if not set\n this.entityIds = attrs.entityIds || []; // Optional - used for hover-higlighting.\n// this.autoArgs = attrs.autoArgs; // Optional - pass [actions, annotation] arglist if this fix can automatically run\n\n this.issue = null; // Generated link - added by validationIssue\n}\n","import {\n geoExtent, geoLineIntersection, geoMetersToLat, geoMetersToLon,\n geoSphericalDistance, geoVecInterp, geoHasSelfIntersections,\n geoSphericalClosestNode, geoAngle\n} from '../geo';\n\nimport { actionAddMidpoint } from '../actions/add_midpoint';\nimport { actionChangeTags } from '../actions/change_tags';\nimport { actionMergeNodes } from '../actions/merge_nodes';\nimport { t } from '../core/localizer';\nimport { utilDisplayLabel } from '../util';\nimport { osmRoutableHighwayTagValues } from '../osm/tags';\nimport { validationIssue, validationIssueFix } from '../core/validation';\nimport { services } from '../services';\n\n\n/**\n * Look for roads that can be connected to other roads with a short extension\n */\nexport function validationAlmostJunction(context) {\n const type = 'almost_junction';\n const EXTEND_TH_METERS = 5;\n const WELD_TH_METERS = 0.75;\n // Comes from considering bounding case of parallel ways\n const CLOSE_NODE_TH = EXTEND_TH_METERS - WELD_TH_METERS;\n // Comes from considering bounding case of perpendicular ways\n const SIG_ANGLE_TH = Math.atan(WELD_TH_METERS / EXTEND_TH_METERS);\n\n function isHighway(entity) {\n return entity.type === 'way'\n && osmRoutableHighwayTagValues[entity.tags.highway];\n }\n\n function isTaggedAsNotContinuing(node) {\n return node.tags.noexit === 'yes'\n || node.tags.amenity === 'parking_entrance'\n || (node.tags.entrance && node.tags.entrance !== 'no');\n }\n\n\n const validation = function checkAlmostJunction(entity, graph) {\n if (!isHighway(entity)) return [];\n if (entity.isDegenerate()) return [];\n\n const tree = context.history().tree();\n const extendableNodeInfos = findConnectableEndNodesByExtension(entity);\n\n let issues = [];\n\n extendableNodeInfos.forEach(extendableNodeInfo => {\n issues.push(new validationIssue({\n type,\n subtype: 'highway-highway',\n severity: 'warning',\n message(context) {\n const entity1 = context.hasEntity(this.entityIds[0]);\n if (this.entityIds[0] === this.entityIds[2]) {\n return entity1 ? t('issues.almost_junction.self.message', {\n feature: utilDisplayLabel(entity1, context.graph())\n }) : '';\n } else {\n const entity2 = context.hasEntity(this.entityIds[2]);\n return (entity1 && entity2) ? t('issues.almost_junction.message', {\n feature: utilDisplayLabel(entity1, context.graph()),\n feature2: utilDisplayLabel(entity2, context.graph())\n }) : '';\n }\n },\n reference: showReference,\n entityIds: [\n entity.id,\n extendableNodeInfo.node.id,\n extendableNodeInfo.wid,\n ],\n loc: extendableNodeInfo.node.loc,\n hash: JSON.stringify(extendableNodeInfo.node.loc),\n data: {\n midId: extendableNodeInfo.mid.id,\n edge: extendableNodeInfo.edge,\n cross_loc: extendableNodeInfo.cross_loc\n },\n dynamicFixes: makeFixes\n }));\n });\n\n return issues;\n\n function makeFixes(context) {\n let fixes = [new validationIssueFix({\n icon: 'iD-icon-abutment',\n title: t('issues.fix.connect_features.title'),\n onClick(context) {\n const annotation = t('issues.fix.connect_almost_junction.annotation');\n const [, endNodeId, crossWayId] = this.issue.entityIds;\n const midNode = context.entity(this.issue.data.midId);\n const endNode = context.entity(endNodeId);\n const crossWay = context.entity(crossWayId);\n\n // When endpoints are close, just join if resulting small change in angle (#7201)\n const nearEndNodes = findNearbyEndNodes(endNode, crossWay);\n if (nearEndNodes.length > 0) {\n const collinear = findSmallJoinAngle(midNode, endNode, nearEndNodes);\n if (collinear) {\n context.perform(\n actionMergeNodes([collinear.id, endNode.id], collinear.loc),\n annotation\n );\n return;\n }\n }\n\n const targetEdge = this.issue.data.edge;\n const crossLoc = this.issue.data.cross_loc;\n const edgeNodes = [context.entity(targetEdge[0]), context.entity(targetEdge[1])];\n const closestNodeInfo = geoSphericalClosestNode(edgeNodes, crossLoc);\n\n // already a point nearby, just connect to that\n if (closestNodeInfo.distance < WELD_TH_METERS) {\n context.perform(\n actionMergeNodes([closestNodeInfo.node.id, endNode.id], closestNodeInfo.node.loc),\n annotation\n );\n // else add the end node to the edge way\n } else {\n context.perform(\n actionAddMidpoint({loc: crossLoc, edge: targetEdge}, endNode),\n annotation\n );\n }\n }\n })];\n\n const node = context.hasEntity(this.entityIds[1]);\n if (node && !node.hasInterestingTags()) {\n // node has no descriptive tags, suggest noexit fix\n fixes.push(new validationIssueFix({\n icon: 'maki-barrier',\n title: t('issues.fix.tag_as_disconnected.title'),\n onClick(context) {\n const nodeID = this.issue.entityIds[1];\n const tags = Object.assign({}, context.entity(nodeID).tags);\n tags.noexit = 'yes';\n context.perform(\n actionChangeTags(nodeID, tags),\n t('issues.fix.tag_as_disconnected.annotation')\n );\n }\n }));\n }\n\n return fixes;\n }\n\n function showReference(selection) {\n selection.selectAll('.issue-reference')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'issue-reference')\n .text(t('issues.almost_junction.highway-highway.reference'));\n }\n\n function isExtendableCandidate(node, way) {\n // can not accurately test vertices on tiles not downloaded from osm - #5938\n const osm = services.osm;\n if (osm && !osm.isDataLoaded(node.loc)) {\n return false;\n }\n if (isTaggedAsNotContinuing(node) || graph.parentWays(node).length !== 1) {\n return false;\n }\n\n let occurences = 0;\n for (const index in way.nodes) {\n if (way.nodes[index] === node.id) {\n occurences += 1;\n if (occurences > 1) {\n return false;\n }\n }\n }\n return true;\n }\n\n function findConnectableEndNodesByExtension(way) {\n let results = [];\n if (way.isClosed()) return results;\n\n let testNodes;\n const indices = [0, way.nodes.length - 1];\n indices.forEach(nodeIndex => {\n const nodeID = way.nodes[nodeIndex];\n const node = graph.entity(nodeID);\n\n if (!isExtendableCandidate(node, way)) return;\n\n const connectionInfo = canConnectByExtend(way, nodeIndex);\n if (!connectionInfo) return;\n\n testNodes = graph.childNodes(way).slice(); // shallow copy\n testNodes[nodeIndex] = testNodes[nodeIndex].move(connectionInfo.cross_loc);\n\n // don't flag issue if connecting the ways would cause self-intersection\n if (geoHasSelfIntersections(testNodes, nodeID)) return;\n\n results.push(connectionInfo);\n });\n\n return results;\n }\n\n function findNearbyEndNodes(node, way) {\n return [\n way.nodes[0],\n way.nodes[way.nodes.length - 1]\n ].map(d => graph.entity(d))\n .filter(d => {\n // Node cannot be near to itself, but other endnode of same way could be\n return d.id !== node.id\n && geoSphericalDistance(node.loc, d.loc) <= CLOSE_NODE_TH;\n });\n }\n\n function findSmallJoinAngle(midNode, tipNode, endNodes) {\n // Both nodes could be close, so want to join whichever is closest to collinear\n let joinTo;\n let minAngle = Infinity;\n\n // Checks midNode -> tipNode -> endNode for collinearity\n endNodes.forEach(endNode => {\n const a1 = geoAngle(midNode, tipNode, context.projection) + Math.PI;\n const a2 = geoAngle(midNode, endNode, context.projection) + Math.PI;\n const diff = Math.max(a1, a2) - Math.min(a1, a2);\n\n if (diff < minAngle) {\n joinTo = endNode;\n minAngle = diff;\n }\n });\n\n /* Threshold set by considering right angle triangle\n based on node joining threshold and extension distance */\n if (minAngle <= SIG_ANGLE_TH) return joinTo;\n\n return null;\n }\n\n function hasTag(tags, key) {\n return tags[key] !== undefined && tags[key] !== 'no';\n }\n\n function canConnectWays(way, way2) {\n\n // allow self-connections\n if (way.id === way2.id) return true;\n\n // if one is bridge or tunnel, both must be bridge or tunnel\n if ((hasTag(way.tags, 'bridge') || hasTag(way2.tags, 'bridge')) &&\n !(hasTag(way.tags, 'bridge') && hasTag(way2.tags, 'bridge'))) return false;\n if ((hasTag(way.tags, 'tunnel') || hasTag(way2.tags, 'tunnel')) &&\n !(hasTag(way.tags, 'tunnel') && hasTag(way2.tags, 'tunnel'))) return false;\n\n // must have equivalent layers and levels\n const layer1 = way.tags.layer || '0',\n layer2 = way2.tags.layer || '0';\n if (layer1 !== layer2) return false;\n\n const level1 = way.tags.level || '0',\n level2 = way2.tags.level || '0';\n if (level1 !== level2) return false;\n\n return true;\n }\n\n function canConnectByExtend(way, endNodeIdx) {\n const tipNid = way.nodes[endNodeIdx]; // the 'tip' node for extension point\n const midNid = endNodeIdx === 0 ? way.nodes[1] : way.nodes[way.nodes.length - 2]; // the other node of the edge\n const tipNode = graph.entity(tipNid);\n const midNode = graph.entity(midNid);\n const lon = tipNode.loc[0];\n const lat = tipNode.loc[1];\n const lon_range = geoMetersToLon(EXTEND_TH_METERS, lat) / 2;\n const lat_range = geoMetersToLat(EXTEND_TH_METERS) / 2;\n const queryExtent = geoExtent([\n [lon - lon_range, lat - lat_range],\n [lon + lon_range, lat + lat_range]\n ]);\n\n // first, extend the edge of [midNode -> tipNode] by EXTEND_TH_METERS and find the \"extended tip\" location\n const edgeLen = geoSphericalDistance(midNode.loc, tipNode.loc);\n const t = EXTEND_TH_METERS / edgeLen + 1.0;\n const extTipLoc = geoVecInterp(midNode.loc, tipNode.loc, t);\n\n // then, check if the extension part [tipNode.loc -> extTipLoc] intersects any other ways\n const segmentInfos = tree.waySegments(queryExtent, graph);\n for (let i = 0; i < segmentInfos.length; i++) {\n let segmentInfo = segmentInfos[i];\n\n let way2 = graph.entity(segmentInfo.wayId);\n\n if (!isHighway(way2)) continue;\n\n if (!canConnectWays(way, way2)) continue;\n\n let nAid = segmentInfo.nodes[0],\n nBid = segmentInfo.nodes[1];\n\n if (nAid === tipNid || nBid === tipNid) continue;\n\n let nA = graph.entity(nAid),\n nB = graph.entity(nBid);\n let crossLoc = geoLineIntersection([tipNode.loc, extTipLoc], [nA.loc, nB.loc]);\n if (crossLoc) {\n return {\n mid: midNode,\n node: tipNode,\n wid: way2.id,\n edge: [nA.id, nB.id],\n cross_loc: crossLoc\n };\n }\n }\n return null;\n }\n };\n\n validation.type = type;\n\n return validation;\n}\n","import { actionMergeNodes } from '../actions/merge_nodes';\nimport { utilDisplayLabel } from '../util';\nimport { t } from '../core/localizer';\nimport { validationIssue, validationIssueFix } from '../core/validation';\nimport { osmPathHighwayTagValues } from '../osm/tags';\nimport { geoMetersToLat, geoMetersToLon, geoSphericalDistance } from '../geo/geo';\nimport { geoExtent } from '../geo/extent';\n\nexport function validationCloseNodes(context) {\n var type = 'close_nodes';\n\n var pointThresholdMeters = 0.2;\n\n var validation = function(entity, graph) {\n if (entity.type === 'node') {\n return getIssuesForNode(entity);\n } else if (entity.type === 'way') {\n return getIssuesForWay(entity);\n }\n return [];\n\n function getIssuesForNode(node) {\n var parentWays = graph.parentWays(node);\n if (parentWays.length) {\n return getIssuesForVertex(node, parentWays);\n } else {\n return getIssuesForDetachedPoint(node);\n }\n }\n\n function wayTypeFor(way) {\n\n if (way.tags.boundary && way.tags.boundary !== 'no') return 'boundary';\n if (way.tags.indoor && way.tags.indoor !== 'no') return 'indoor';\n if ((way.tags.building && way.tags.building !== 'no') ||\n (way.tags['building:part'] && way.tags['building:part'] !== 'no')) return 'building';\n if (osmPathHighwayTagValues[way.tags.highway]) return 'path';\n\n var parentRelations = graph.parentRelations(way);\n for (var i in parentRelations) {\n var relation = parentRelations[i];\n\n if (relation.tags.type === 'boundary') return 'boundary';\n\n if (relation.isMultipolygon()) {\n if (relation.tags.indoor && relation.tags.indoor !== 'no') return 'indoor';\n if ((relation.tags.building && relation.tags.building !== 'no') ||\n (relation.tags['building:part'] && relation.tags['building:part'] !== 'no')) return 'building';\n }\n }\n\n return 'other';\n }\n\n function shouldCheckWay(way) {\n\n // don't flag issues where merging would create degenerate ways\n if (way.nodes.length <= 2 ||\n (way.isClosed() && way.nodes.length <= 4)) return false;\n\n var bbox = way.extent(graph).bbox();\n var hypotenuseMeters = geoSphericalDistance([bbox.minX, bbox.minY], [bbox.maxX, bbox.maxY]);\n // don't flag close nodes in very small ways\n if (hypotenuseMeters < 1.5) return false;\n\n return true;\n }\n\n function getIssuesForWay(way) {\n if (!shouldCheckWay(way)) return [];\n\n var issues = [],\n nodes = graph.childNodes(way);\n for (var i = 0; i < nodes.length - 1; i++) {\n var node1 = nodes[i];\n var node2 = nodes[i+1];\n\n var issue = getWayIssueIfAny(node1, node2, way);\n if (issue) issues.push(issue);\n }\n return issues;\n }\n\n function getIssuesForVertex(node, parentWays) {\n var issues = [];\n\n function checkForCloseness(node1, node2, way) {\n var issue = getWayIssueIfAny(node1, node2, way);\n if (issue) issues.push(issue);\n }\n\n for (var i = 0; i < parentWays.length; i++) {\n var parentWay = parentWays[i];\n\n if (!shouldCheckWay(parentWay)) continue;\n\n var lastIndex = parentWay.nodes.length - 1;\n for (var j = 0; j < parentWay.nodes.length; j++) {\n if (j !== 0) {\n if (parentWay.nodes[j-1] === node.id) {\n checkForCloseness(node, graph.entity(parentWay.nodes[j]), parentWay);\n }\n }\n if (j !== lastIndex) {\n if (parentWay.nodes[j+1] === node.id) {\n checkForCloseness(graph.entity(parentWay.nodes[j]), node, parentWay);\n }\n }\n }\n }\n return issues;\n }\n\n function thresholdMetersForWay(way) {\n if (!shouldCheckWay(way)) return 0;\n\n var wayType = wayTypeFor(way);\n\n // don't flag boundaries since they might be highly detailed and can't be easily verified\n if (wayType === 'boundary') return 0;\n // expect some features to be mapped with higher levels of detail\n if (wayType === 'indoor') return 0.01;\n if (wayType === 'building') return 0.05;\n if (wayType === 'path') return 0.1;\n return 0.2;\n }\n\n function getIssuesForDetachedPoint(node) {\n\n var issues = [];\n\n var lon = node.loc[0];\n var lat = node.loc[1];\n var lon_range = geoMetersToLon(pointThresholdMeters, lat) / 2;\n var lat_range = geoMetersToLat(pointThresholdMeters) / 2;\n var queryExtent = geoExtent([\n [lon - lon_range, lat - lat_range],\n [lon + lon_range, lat + lat_range]\n ]);\n\n var intersected = context.history().tree().intersects(queryExtent, graph);\n for (var j = 0; j < intersected.length; j++) {\n var nearby = intersected[j];\n\n if (nearby.id === node.id) continue;\n if (nearby.type !== 'node' || nearby.geometry(graph) !== 'point') continue;\n\n if (nearby.loc === node.loc ||\n geoSphericalDistance(node.loc, nearby.loc) < pointThresholdMeters) {\n\n // allow very close points if tags indicate the z-axis might vary\n var zAxisKeys = { layer: true, level: true, 'addr:housenumber': true, 'addr:unit': true };\n var zAxisDifferentiates = false;\n for (var key in zAxisKeys) {\n var nodeValue = node.tags[key] || '0';\n var nearbyValue = nearby.tags[key] || '0';\n if (nodeValue !== nearbyValue) {\n zAxisDifferentiates = true;\n break;\n }\n }\n if (zAxisDifferentiates) continue;\n\n issues.push(new validationIssue({\n type: type,\n subtype: 'detached',\n severity: 'warning',\n message: function(context) {\n var entity = context.hasEntity(this.entityIds[0]),\n entity2 = context.hasEntity(this.entityIds[1]);\n return (entity && entity2) ? t('issues.close_nodes.detached.message', {\n feature: utilDisplayLabel(entity, context.graph()),\n feature2: utilDisplayLabel(entity2, context.graph())\n }) : '';\n },\n reference: showReference,\n entityIds: [node.id, nearby.id],\n dynamicFixes: function() {\n return [\n new validationIssueFix({\n icon: 'iD-operation-disconnect',\n title: t('issues.fix.move_points_apart.title')\n }),\n new validationIssueFix({\n icon: 'iD-icon-layers',\n title: t('issues.fix.use_different_layers_or_levels.title')\n })\n ];\n }\n }));\n }\n }\n\n return issues;\n\n function showReference(selection) {\n var referenceText = t('issues.close_nodes.detached.reference');\n selection.selectAll('.issue-reference')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'issue-reference')\n .text(referenceText);\n }\n }\n\n function getWayIssueIfAny(node1, node2, way) {\n if (node1.id === node2.id ||\n (node1.hasInterestingTags() && node2.hasInterestingTags())) {\n return null;\n }\n\n if (node1.loc !== node2.loc) {\n var parentWays1 = graph.parentWays(node1);\n var parentWays2 = new Set(graph.parentWays(node2));\n\n var sharedWays = parentWays1.filter(function(parentWay) {\n return parentWays2.has(parentWay);\n });\n\n var thresholds = sharedWays.map(function(parentWay) {\n return thresholdMetersForWay(parentWay);\n });\n\n var threshold = Math.min(...thresholds);\n var distance = geoSphericalDistance(node1.loc, node2.loc);\n if (distance > threshold) return null;\n }\n\n return new validationIssue({\n type: type,\n subtype: 'vertices',\n severity: 'warning',\n message: function(context) {\n var entity = context.hasEntity(this.entityIds[0]);\n return entity ? t('issues.close_nodes.message', { way: utilDisplayLabel(entity, context.graph()) }) : '';\n },\n reference: showReference,\n entityIds: [way.id, node1.id, node2.id],\n loc: node1.loc,\n dynamicFixes: function() {\n return [\n new validationIssueFix({\n icon: 'iD-icon-plus',\n title: t('issues.fix.merge_points.title'),\n onClick: function(context) {\n var entityIds = this.issue.entityIds;\n var action = actionMergeNodes([entityIds[1], entityIds[2]]);\n context.perform(action, t('issues.fix.merge_close_vertices.annotation'));\n }\n }),\n new validationIssueFix({\n icon: 'iD-operation-disconnect',\n title: t('issues.fix.move_points_apart.title')\n })\n ];\n }\n });\n\n function showReference(selection) {\n var referenceText = t('issues.close_nodes.reference');\n selection.selectAll('.issue-reference')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'issue-reference')\n .text(referenceText);\n }\n }\n\n };\n\n\n validation.type = type;\n\n return validation;\n}\n","import { actionAddMidpoint } from '../actions/add_midpoint';\nimport { actionChangeTags } from '../actions/change_tags';\nimport { actionMergeNodes } from '../actions/merge_nodes';\nimport { actionSplit } from '../actions/split';\nimport { modeSelect } from '../modes/select';\nimport { geoAngle, geoExtent, geoLatToMeters, geoLonToMeters, geoLineIntersection,\n geoSphericalClosestNode, geoSphericalDistance, geoVecAngle, geoVecLength, geoMetersToLat, geoMetersToLon } from '../geo';\nimport { osmNode } from '../osm/node';\nimport { osmFlowingWaterwayTagValues, osmPathHighwayTagValues, osmRailwayTrackTagValues, osmRoutableHighwayTagValues } from '../osm/tags';\nimport { t } from '../core/localizer';\nimport { utilDisplayLabel } from '../util';\nimport { validationIssue, validationIssueFix } from '../core/validation';\n\n\nexport function validationCrossingWays(context) {\n var type = 'crossing_ways';\n\n // returns the way or its parent relation, whichever has a useful feature type\n function getFeatureWithFeatureTypeTagsForWay(way, graph) {\n if (getFeatureType(way, graph) === null) {\n // if the way doesn't match a feature type, check its parent relations\n var parentRels = graph.parentRelations(way);\n for (var i = 0; i < parentRels.length; i++) {\n var rel = parentRels[i];\n if (getFeatureType(rel, graph) !== null) {\n return rel;\n }\n }\n }\n return way;\n }\n\n\n function hasTag(tags, key) {\n return tags[key] !== undefined && tags[key] !== 'no';\n }\n\n function taggedAsIndoor(tags) {\n return hasTag(tags, 'indoor') ||\n hasTag(tags, 'level') ||\n tags.highway === 'corridor';\n }\n\n function allowsBridge(featureType) {\n return featureType === 'highway' || featureType === 'railway' || featureType === 'waterway';\n }\n function allowsTunnel(featureType) {\n return featureType === 'highway' || featureType === 'railway' || featureType === 'waterway';\n }\n\n\n function getFeatureTypeForCrossingCheck(way, graph) {\n var feature = getFeatureWithFeatureTypeTagsForWay(way, graph);\n return getFeatureType(feature, graph);\n }\n\n // discard\n var ignoredBuildings = {\n demolished: true, dismantled: true, proposed: true, razed: true\n };\n\n\n function getFeatureType(entity, graph) {\n\n var geometry = entity.geometry(graph);\n if (geometry !== 'line' && geometry !== 'area') return null;\n\n var tags = entity.tags;\n\n if (hasTag(tags, 'building') && !ignoredBuildings[tags.building]) return 'building';\n if (hasTag(tags, 'highway') && osmRoutableHighwayTagValues[tags.highway]) return 'highway';\n\n // don't check railway or waterway areas\n if (geometry !== 'line') return null;\n\n if (hasTag(tags, 'railway') && osmRailwayTrackTagValues[tags.railway]) return 'railway';\n if (hasTag(tags, 'waterway') && osmFlowingWaterwayTagValues[tags.waterway]) return 'waterway';\n\n return null;\n }\n\n\n function isLegitCrossing(way1, featureType1, way2, featureType2) {\n var tags1 = way1.tags;\n var tags2 = way2.tags;\n\n // assume 0 by default\n var level1 = tags1.level || '0';\n var level2 = tags2.level || '0';\n\n if (taggedAsIndoor(tags1) && taggedAsIndoor(tags2) && level1 !== level2) {\n // assume features don't interact if they're indoor on different levels\n return true;\n }\n\n // assume 0 by default; don't use way.layer() since we account for structures here\n var layer1 = tags1.layer || '0';\n var layer2 = tags2.layer || '0';\n\n if (allowsBridge(featureType1) && allowsBridge(featureType2)) {\n if (hasTag(tags1, 'bridge') && !hasTag(tags2, 'bridge')) return true;\n if (!hasTag(tags1, 'bridge') && hasTag(tags2, 'bridge')) return true;\n // crossing bridges must use different layers\n if (hasTag(tags1, 'bridge') && hasTag(tags2, 'bridge') && layer1 !== layer2) return true;\n } else if (allowsBridge(featureType1) && hasTag(tags1, 'bridge')) return true;\n else if (allowsBridge(featureType2) && hasTag(tags2, 'bridge')) return true;\n\n if (allowsTunnel(featureType1) && allowsTunnel(featureType2)) {\n if (hasTag(tags1, 'tunnel') && !hasTag(tags2, 'tunnel')) return true;\n if (!hasTag(tags1, 'tunnel') && hasTag(tags2, 'tunnel')) return true;\n // crossing tunnels must use different layers\n if (hasTag(tags1, 'tunnel') && hasTag(tags2, 'tunnel') && layer1 !== layer2) return true;\n } else if (allowsTunnel(featureType1) && hasTag(tags1, 'tunnel')) return true;\n else if (allowsTunnel(featureType2) && hasTag(tags2, 'tunnel')) return true;\n\n // don't flag crossing waterways and pier/highways\n if (featureType1 === 'waterway' && featureType2 === 'highway' && tags2.man_made === 'pier') return true;\n if (featureType2 === 'waterway' && featureType1 === 'highway' && tags1.man_made === 'pier') return true;\n\n if (featureType1 === 'building' || featureType2 === 'building') {\n // for building crossings, different layers are enough\n if (layer1 !== layer2) return true;\n }\n return false;\n }\n\n\n // highway values for which we shouldn't recommend connecting to waterways\n var highwaysDisallowingFords = {\n motorway: true, motorway_link: true, trunk: true, trunk_link: true,\n primary: true, primary_link: true, secondary: true, secondary_link: true\n };\n var nonCrossingHighways = { track: true };\n\n function tagsForConnectionNodeIfAllowed(entity1, entity2, graph) {\n var featureType1 = getFeatureType(entity1, graph);\n var featureType2 = getFeatureType(entity2, graph);\n\n var geometry1 = entity1.geometry(graph);\n var geometry2 = entity2.geometry(graph);\n var bothLines = geometry1 === 'line' && geometry2 === 'line';\n\n if (featureType1 === featureType2) {\n if (featureType1 === 'highway') {\n var entity1IsPath = osmPathHighwayTagValues[entity1.tags.highway];\n var entity2IsPath = osmPathHighwayTagValues[entity2.tags.highway];\n if ((entity1IsPath || entity2IsPath) && entity1IsPath !== entity2IsPath) {\n // one feature is a path but not both\n\n var roadFeature = entity1IsPath ? entity2 : entity1;\n if (nonCrossingHighways[roadFeature.tags.highway]) {\n // don't mark path connections with certain roads as crossings\n return {};\n }\n var pathFeature = entity1IsPath ? entity1 : entity2;\n if (['marked', 'unmarked'].indexOf(pathFeature.tags.crossing) !== -1) {\n // if the path is a crossing, match the crossing type\n return bothLines ? { highway: 'crossing', crossing: pathFeature.tags.crossing } : {};\n }\n // don't add a `crossing` subtag to ambiguous crossings\n return bothLines ? { highway: 'crossing' } : {};\n }\n return {};\n }\n if (featureType1 === 'waterway') return {};\n if (featureType1 === 'railway') return {};\n\n } else {\n var featureTypes = [featureType1, featureType2];\n if (featureTypes.indexOf('highway') !== -1) {\n if (featureTypes.indexOf('railway') !== -1) {\n if (osmPathHighwayTagValues[entity1.tags.highway] ||\n osmPathHighwayTagValues[entity2.tags.highway]) {\n // path-rail connections use this tag\n return bothLines ? { railway: 'crossing' } : {};\n } else {\n // road-rail connections use this tag\n return bothLines ? { railway: 'level_crossing' } : {};\n }\n }\n\n if (featureTypes.indexOf('waterway') !== -1) {\n // do not allow fords on structures\n if (hasTag(entity1.tags, 'tunnel') && hasTag(entity2.tags, 'tunnel')) return null;\n if (hasTag(entity1.tags, 'bridge') && hasTag(entity2.tags, 'bridge')) return null;\n\n if (highwaysDisallowingFords[entity1.tags.highway] ||\n highwaysDisallowingFords[entity2.tags.highway]) {\n // do not allow fords on major highways\n return null;\n }\n return bothLines ? { ford: 'yes' } : {};\n }\n }\n }\n return null;\n }\n\n\n function findCrossingsByWay(way1, graph, tree) {\n var edgeCrossInfos = [];\n if (way1.type !== 'way') return edgeCrossInfos;\n\n var way1FeatureType = getFeatureTypeForCrossingCheck(way1, graph);\n if (way1FeatureType === null) return edgeCrossInfos;\n\n var checkedSingleCrossingWays = {};\n\n // declare vars ahead of time to reduce garbage collection\n var i, j;\n var extent;\n var n1, n2, nA, nB, nAId, nBId;\n var segment1, segment2;\n var oneOnly;\n var segmentInfos, segment2Info, way2, way2FeatureType;\n var way1Nodes = graph.childNodes(way1);\n var comparedWays = {};\n for (i = 0; i < way1Nodes.length - 1; i++) {\n n1 = way1Nodes[i];\n n2 = way1Nodes[i + 1];\n extent = geoExtent([\n [\n Math.min(n1.loc[0], n2.loc[0]),\n Math.min(n1.loc[1], n2.loc[1])\n ],\n [\n Math.max(n1.loc[0], n2.loc[0]),\n Math.max(n1.loc[1], n2.loc[1])\n ]\n ]);\n\n // Optimize by only checking overlapping segments, not every segment\n // of overlapping ways\n segmentInfos = tree.waySegments(extent, graph);\n\n for (j = 0; j < segmentInfos.length; j++) {\n segment2Info = segmentInfos[j];\n\n // don't check for self-intersection in this validation\n if (segment2Info.wayId === way1.id) continue;\n\n // skip if this way was already checked and only one issue is needed\n if (checkedSingleCrossingWays[segment2Info.wayId]) continue;\n\n // mark this way as checked even if there are no crossings\n comparedWays[segment2Info.wayId] = true;\n\n way2 = graph.hasEntity(segment2Info.wayId);\n if (!way2) continue;\n\n // only check crossing highway, waterway, building, and railway\n way2FeatureType = getFeatureTypeForCrossingCheck(way2, graph);\n if (way2FeatureType === null ||\n isLegitCrossing(way1, way1FeatureType, way2, way2FeatureType)) {\n continue;\n }\n\n // create only one issue for building crossings\n oneOnly = way1FeatureType === 'building' || way2FeatureType === 'building';\n\n nAId = segment2Info.nodes[0];\n nBId = segment2Info.nodes[1];\n if (nAId === n1.id || nAId === n2.id ||\n nBId === n1.id || nBId === n2.id) {\n // n1 or n2 is a connection node; skip\n continue;\n }\n nA = graph.hasEntity(nAId);\n if (!nA) continue;\n nB = graph.hasEntity(nBId);\n if (!nB) continue;\n\n segment1 = [n1.loc, n2.loc];\n segment2 = [nA.loc, nB.loc];\n var point = geoLineIntersection(segment1, segment2);\n if (point) {\n edgeCrossInfos.push({\n wayInfos: [\n {\n way: way1,\n featureType: way1FeatureType,\n edge: [n1.id, n2.id]\n },\n {\n way: way2,\n featureType: way2FeatureType,\n edge: [nA.id, nB.id]\n }\n ],\n crossPoint: point\n });\n if (oneOnly) {\n checkedSingleCrossingWays[way2.id] = true;\n break;\n }\n }\n }\n }\n return edgeCrossInfos;\n }\n\n\n function waysToCheck(entity, graph) {\n var featureType = getFeatureType(entity, graph);\n if (!featureType) return [];\n\n if (entity.type === 'way') {\n return [entity];\n } else if (entity.type === 'relation') {\n return entity.members.reduce(function(array, member) {\n if (member.type === 'way' &&\n // only look at geometry ways\n (!member.role || member.role === 'outer' || member.role === 'inner')) {\n var entity = graph.hasEntity(member.id);\n // don't add duplicates\n if (entity && array.indexOf(entity) === -1) {\n array.push(entity);\n }\n }\n return array;\n }, []);\n }\n return [];\n }\n\n\n var validation = function checkCrossingWays(entity, graph) {\n\n var tree = context.history().tree();\n\n var ways = waysToCheck(entity, graph);\n\n var issues = [];\n // declare these here to reduce garbage collection\n var wayIndex, crossingIndex, crossings;\n for (wayIndex in ways) {\n crossings = findCrossingsByWay(ways[wayIndex], graph, tree);\n for (crossingIndex in crossings) {\n issues.push(createIssue(crossings[crossingIndex], graph));\n }\n }\n return issues;\n };\n\n\n function createIssue(crossing, graph) {\n\n // use the entities with the tags that define the feature type\n crossing.wayInfos.sort(function(way1Info, way2Info) {\n var type1 = way1Info.featureType;\n var type2 = way2Info.featureType;\n if (type1 === type2) {\n return utilDisplayLabel(way1Info.way, graph) > utilDisplayLabel(way2Info.way, graph);\n } else if (type1 === 'waterway') {\n return true;\n } else if (type2 === 'waterway') {\n return false;\n }\n return type1 < type2;\n });\n var entities = crossing.wayInfos.map(function(wayInfo) {\n return getFeatureWithFeatureTypeTagsForWay(wayInfo.way, graph);\n });\n var edges = [crossing.wayInfos[0].edge, crossing.wayInfos[1].edge];\n var featureTypes = [crossing.wayInfos[0].featureType, crossing.wayInfos[1].featureType];\n\n var connectionTags = tagsForConnectionNodeIfAllowed(entities[0], entities[1], graph);\n\n var featureType1 = crossing.wayInfos[0].featureType;\n var featureType2 = crossing.wayInfos[1].featureType;\n\n var isCrossingIndoors = taggedAsIndoor(entities[0].tags) && taggedAsIndoor(entities[1].tags);\n var isCrossingTunnels = allowsTunnel(featureType1) && hasTag(entities[0].tags, 'tunnel') &&\n allowsTunnel(featureType2) && hasTag(entities[1].tags, 'tunnel');\n var isCrossingBridges = allowsBridge(featureType1) && hasTag(entities[0].tags, 'bridge') &&\n allowsBridge(featureType2) && hasTag(entities[1].tags, 'bridge');\n\n var subtype = [featureType1, featureType2].sort().join('-');\n\n var crossingTypeID = subtype;\n\n if (isCrossingIndoors) {\n crossingTypeID = 'indoor-indoor';\n } else if (isCrossingTunnels) {\n crossingTypeID = 'tunnel-tunnel';\n } else if (isCrossingBridges) {\n crossingTypeID = 'bridge-bridge';\n }\n if (connectionTags && (isCrossingIndoors || isCrossingTunnels || isCrossingBridges)) {\n crossingTypeID += '_connectable';\n }\n\n return new validationIssue({\n type: type,\n subtype: subtype,\n severity: 'warning',\n message: function(context) {\n var graph = context.graph();\n var entity1 = graph.hasEntity(this.entityIds[0]),\n entity2 = graph.hasEntity(this.entityIds[1]);\n return (entity1 && entity2) ? t('issues.crossing_ways.message', {\n feature: utilDisplayLabel(entity1, graph),\n feature2: utilDisplayLabel(entity2, graph)\n }) : '';\n },\n reference: showReference,\n entityIds: entities.map(function(entity) {\n return entity.id;\n }),\n data: {\n edges: edges,\n featureTypes: featureTypes,\n connectionTags: connectionTags\n },\n // differentiate based on the loc since two ways can cross multiple times\n hash: crossing.crossPoint.toString() +\n // if the edges change then so does the fix\n edges.slice().sort(function(edge1, edge2) {\n // order to assure hash is deterministic\n return edge1[0] < edge2[0] ? -1 : 1;\n }).toString() +\n // ensure the correct connection tags are added in the fix\n JSON.stringify(connectionTags),\n loc: crossing.crossPoint,\n autoArgs: connectionTags && connectWaysAutoArgs(crossing.crossPoint, edges, connectionTags),\n dynamicFixes: function(context) {\n var mode = context.mode();\n if (!mode || mode.id !== 'select' || mode.selectedIDs().length !== 1) return [];\n\n var selectedIndex = this.entityIds[0] === mode.selectedIDs()[0] ? 0 : 1;\n var selectedFeatureType = this.data.featureTypes[selectedIndex];\n var otherFeatureType = this.data.featureTypes[selectedIndex === 0 ? 1 : 0];\n\n var fixes = [];\n\n if (connectionTags) {\n fixes.push(makeConnectWaysFix(this.data.connectionTags));\n }\n\n if (isCrossingIndoors) {\n fixes.push(new validationIssueFix({\n icon: 'iD-icon-layers',\n title: t('issues.fix.use_different_levels.title')\n }));\n } else if (isCrossingTunnels ||\n isCrossingBridges ||\n featureType1 === 'building' ||\n featureType2 === 'building') {\n\n fixes.push(makeChangeLayerFix('higher'));\n fixes.push(makeChangeLayerFix('lower'));\n\n // can only add bridge/tunnel if both features are lines\n } else if (context.graph().geometry(this.entityIds[0]) === 'line' &&\n context.graph().geometry(this.entityIds[1]) === 'line') {\n\n // don't recommend adding bridges to waterways since they're uncommmon\n if (allowsBridge(selectedFeatureType) && selectedFeatureType !== 'waterway') {\n fixes.push(makeAddBridgeOrTunnelFix('add_a_bridge', 'temaki-bridge', 'bridge'));\n }\n\n // don't recommend adding tunnels under waterways since they're uncommmon\n var skipTunnelFix = otherFeatureType === 'waterway' && selectedFeatureType !== 'waterway';\n if (allowsTunnel(selectedFeatureType) && !skipTunnelFix) {\n fixes.push(makeAddBridgeOrTunnelFix('add_a_tunnel', 'temaki-tunnel', 'tunnel'));\n }\n }\n\n // repositioning the features is always an option\n fixes.push(new validationIssueFix({\n icon: 'iD-operation-move',\n title: t('issues.fix.reposition_features.title')\n }));\n\n return fixes;\n }\n });\n\n function showReference(selection) {\n selection.selectAll('.issue-reference')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'issue-reference')\n .text(t('issues.crossing_ways.' + crossingTypeID + '.reference'));\n }\n }\n\n function makeAddBridgeOrTunnelFix(fixTitleID, iconName, bridgeOrTunnel){\n return new validationIssueFix({\n icon: iconName,\n title: t('issues.fix.' + fixTitleID + '.title'),\n onClick: function(context) {\n var mode = context.mode();\n if (!mode || mode.id !== 'select') return;\n\n var selectedIDs = mode.selectedIDs();\n if (selectedIDs.length !== 1) return;\n\n var selectedWayID = selectedIDs[0];\n if (!context.hasEntity(selectedWayID)) return;\n\n var resultWayIDs = [selectedWayID];\n\n var edge, crossedEdge, crossedWayID;\n if (this.issue.entityIds[0] === selectedWayID) {\n edge = this.issue.data.edges[0];\n crossedEdge = this.issue.data.edges[1];\n crossedWayID = this.issue.entityIds[1];\n } else {\n edge = this.issue.data.edges[1];\n crossedEdge = this.issue.data.edges[0];\n crossedWayID = this.issue.entityIds[0];\n }\n\n var crossingLoc = this.issue.loc;\n\n var projection = context.projection;\n\n var action = function actionAddStructure(graph) {\n\n var edgeNodes = [graph.entity(edge[0]), graph.entity(edge[1])];\n\n var crossedWay = graph.hasEntity(crossedWayID);\n // use the explicit width of the crossed feature as the structure length, if available\n var structLengthMeters = crossedWay && crossedWay.tags.width && parseFloat(crossedWay.tags.width);\n if (!structLengthMeters) {\n // if no explicit width is set, approximate the width based on the tags\n structLengthMeters = crossedWay && crossedWay.impliedLineWidthMeters();\n }\n if (structLengthMeters) {\n if (getFeatureType(crossedWay, graph) === 'railway') {\n // bridges over railways are generally much longer than the rail bed itself, compensate\n structLengthMeters *= 2;\n }\n } else {\n // should ideally never land here since all rail/water/road tags should have an implied width\n structLengthMeters = 8;\n }\n\n var a1 = geoAngle(edgeNodes[0], edgeNodes[1], projection) + Math.PI;\n var a2 = geoAngle(graph.entity(crossedEdge[0]), graph.entity(crossedEdge[1]), projection) + Math.PI;\n var crossingAngle = Math.max(a1, a2) - Math.min(a1, a2);\n if (crossingAngle > Math.PI) crossingAngle -= Math.PI;\n // lengthen the structure to account for the angle of the crossing\n structLengthMeters = ((structLengthMeters / 2) / Math.sin(crossingAngle)) * 2;\n\n // add padding since the structure must extend past the edges of the crossed feature\n structLengthMeters += 4;\n\n // clamp the length to a reasonable range\n structLengthMeters = Math.min(Math.max(structLengthMeters, 4), 50);\n\n function geomToProj(geoPoint) {\n return [\n geoLonToMeters(geoPoint[0], geoPoint[1]),\n geoLatToMeters(geoPoint[1])\n ];\n }\n function projToGeom(projPoint) {\n var lat = geoMetersToLat(projPoint[1]);\n return [\n geoMetersToLon(projPoint[0], lat),\n lat\n ];\n }\n\n var projEdgeNode1 = geomToProj(edgeNodes[0].loc);\n var projEdgeNode2 = geomToProj(edgeNodes[1].loc);\n\n var projectedAngle = geoVecAngle(projEdgeNode1, projEdgeNode2);\n\n var projectedCrossingLoc = geomToProj(crossingLoc);\n var linearToSphericalMetersRatio = geoVecLength(projEdgeNode1, projEdgeNode2) /\n geoSphericalDistance(edgeNodes[0].loc, edgeNodes[1].loc);\n\n function locSphericalDistanceFromCrossingLoc(angle, distanceMeters) {\n var lengthSphericalMeters = distanceMeters * linearToSphericalMetersRatio;\n return projToGeom([\n projectedCrossingLoc[0] + Math.cos(angle) * lengthSphericalMeters,\n projectedCrossingLoc[1] + Math.sin(angle) * lengthSphericalMeters\n ]);\n }\n\n var endpointLocGetter1 = function(lengthMeters) {\n return locSphericalDistanceFromCrossingLoc(projectedAngle, lengthMeters);\n };\n var endpointLocGetter2 = function(lengthMeters) {\n return locSphericalDistanceFromCrossingLoc(projectedAngle + Math.PI, lengthMeters);\n };\n\n // avoid creating very short edges from splitting too close to another node\n var minEdgeLengthMeters = 0.55;\n\n // decide where to bound the structure along the way, splitting as necessary\n function determineEndpoint(edge, endNode, locGetter) {\n var newNode;\n\n var idealLengthMeters = structLengthMeters / 2;\n\n // distance between the crossing location and the end of the edge,\n // the maximum length of this side of the structure\n var crossingToEdgeEndDistance = geoSphericalDistance(crossingLoc, endNode.loc);\n\n if (crossingToEdgeEndDistance - idealLengthMeters > minEdgeLengthMeters) {\n // the edge is long enough to insert a new node\n\n // the loc that would result in the full expected length\n var idealNodeLoc = locGetter(idealLengthMeters);\n\n newNode = osmNode();\n graph = actionAddMidpoint({ loc: idealNodeLoc, edge: edge }, newNode)(graph);\n\n } else {\n var edgeCount = 0;\n endNode.parentIntersectionWays(graph).forEach(function(way) {\n way.nodes.forEach(function(nodeID) {\n if (nodeID === endNode.id) {\n if ((endNode.id === way.first() && endNode.id !== way.last()) ||\n (endNode.id === way.last() && endNode.id !== way.first())) {\n edgeCount += 1;\n } else {\n edgeCount += 2;\n }\n }\n });\n });\n\n if (edgeCount >= 3) {\n // the end node is a junction, try to leave a segment\n // between it and the structure - #7202\n\n var insetLength = crossingToEdgeEndDistance - minEdgeLengthMeters;\n if (insetLength > minEdgeLengthMeters) {\n var insetNodeLoc = locGetter(insetLength);\n newNode = osmNode();\n graph = actionAddMidpoint({ loc: insetNodeLoc, edge: edge }, newNode)(graph);\n }\n }\n }\n\n // if the edge is too short to subdivide as desired, then\n // just bound the structure at the existing end node\n if (!newNode) newNode = endNode;\n\n var splitAction = actionSplit(newNode.id)\n .limitWays(resultWayIDs); // only split selected or created ways\n\n // do the split\n graph = splitAction(graph);\n if (splitAction.getCreatedWayIDs().length) {\n resultWayIDs.push(splitAction.getCreatedWayIDs()[0]);\n }\n\n return newNode;\n }\n\n var structEndNode1 = determineEndpoint(edge, edgeNodes[1], endpointLocGetter1);\n var structEndNode2 = determineEndpoint([edgeNodes[0].id, structEndNode1.id], edgeNodes[0], endpointLocGetter2);\n\n var structureWay = resultWayIDs.map(function(id) {\n return graph.entity(id);\n }).find(function(way) {\n return way.nodes.indexOf(structEndNode1.id) !== -1 &&\n way.nodes.indexOf(structEndNode2.id) !== -1;\n });\n\n var tags = Object.assign({}, structureWay.tags); // copy tags\n if (bridgeOrTunnel === 'bridge'){\n tags.bridge = 'yes';\n tags.layer = '1';\n } else {\n var tunnelValue = 'yes';\n if (getFeatureType(structureWay, graph) === 'waterway') {\n // use `tunnel=culvert` for waterways by default\n tunnelValue = 'culvert';\n }\n tags.tunnel = tunnelValue;\n tags.layer = '-1';\n }\n // apply the structure tags to the way\n graph = actionChangeTags(structureWay.id, tags)(graph);\n return graph;\n };\n\n context.perform(action, t('issues.fix.' + fixTitleID + '.annotation'));\n context.enter(modeSelect(context, resultWayIDs));\n }\n });\n }\n\n function connectWaysAutoArgs(loc, edges, connectionTags) {\n var fn = function actionConnectCrossingWays(graph) {\n // create the new node for the points\n var node = osmNode({ loc: loc, tags: connectionTags });\n graph = graph.replace(node);\n\n var nodesToMerge = [node.id];\n var mergeThresholdInMeters = 0.75;\n\n edges.forEach(function(edge) {\n var edgeNodes = [graph.entity(edge[0]), graph.entity(edge[1])];\n var closestNodeInfo = geoSphericalClosestNode(edgeNodes, loc);\n if (closestNodeInfo.distance < mergeThresholdInMeters) {\n nodesToMerge.push(closestNodeInfo.node.id); // use an existing nearby point\n } else {\n graph = actionAddMidpoint({loc: loc, edge: edge}, node)(graph);\n }\n });\n\n if (nodesToMerge.length > 1) { // if we're using nearby nodes, merge them with the new node\n graph = actionMergeNodes(nodesToMerge, loc)(graph);\n }\n\n return graph;\n };\n\n return [fn, t('issues.fix.connect_crossing_features.annotation')];\n }\n\n\n function makeConnectWaysFix(connectionTags) {\n\n var fixTitleID = 'connect_features';\n if (connectionTags.ford) {\n fixTitleID = 'connect_using_ford';\n }\n\n return new validationIssueFix({\n icon: 'iD-icon-crossing',\n title: t('issues.fix.' + fixTitleID + '.title'),\n onClick: function(context) {\n var loc = this.issue.loc;\n var connectionTags = this.issue.data.connectionTags;\n var edges = this.issue.data.edges;\n\n context.perform(\n function actionConnectCrossingWays(graph) {\n // create the new node for the points\n var node = osmNode({ loc: loc, tags: connectionTags });\n graph = graph.replace(node);\n\n var nodesToMerge = [node.id];\n var mergeThresholdInMeters = 0.75;\n\n edges.forEach(function(edge) {\n var edgeNodes = [graph.entity(edge[0]), graph.entity(edge[1])];\n var closestNodeInfo = geoSphericalClosestNode(edgeNodes, loc);\n // if there is already a point nearby, use that\n if (closestNodeInfo.distance < mergeThresholdInMeters) {\n nodesToMerge.push(closestNodeInfo.node.id);\n // else add the new node to the way\n } else {\n graph = actionAddMidpoint({loc: loc, edge: edge}, node)(graph);\n }\n });\n\n if (nodesToMerge.length > 1) {\n // if we're using nearby nodes, merge them with the new node\n graph = actionMergeNodes(nodesToMerge, loc)(graph);\n }\n\n return graph;\n },\n t('issues.fix.connect_crossing_features.annotation')\n );\n }\n });\n }\n\n function makeChangeLayerFix(higherOrLower) {\n return new validationIssueFix({\n icon: 'iD-icon-' + (higherOrLower === 'higher' ? 'up' : 'down'),\n title: t('issues.fix.tag_this_as_' + higherOrLower + '.title'),\n onClick: function(context) {\n\n var mode = context.mode();\n if (!mode || mode.id !== 'select') return;\n\n var selectedIDs = mode.selectedIDs();\n if (selectedIDs.length !== 1) return;\n\n var selectedID = selectedIDs[0];\n if (!this.issue.entityIds.some(function(entityId) {\n return entityId === selectedID;\n })) return;\n\n var entity = context.hasEntity(selectedID);\n if (!entity) return;\n\n var tags = Object.assign({}, entity.tags); // shallow copy\n var layer = tags.layer && Number(tags.layer);\n if (layer && !isNaN(layer)) {\n if (higherOrLower === 'higher') {\n layer += 1;\n } else {\n layer -= 1;\n }\n } else {\n if (higherOrLower === 'higher') {\n layer = 1;\n } else {\n layer = -1;\n }\n }\n tags.layer = layer.toString();\n context.perform(\n actionChangeTags(entity.id, tags),\n t('operations.change_tags.annotation')\n );\n }\n });\n }\n\n validation.type = type;\n\n return validation;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\n\nimport {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { presetManager } from '../presets';\nimport { t } from '../core/localizer';\nimport { actionAddMidpoint } from '../actions/add_midpoint';\nimport { actionMoveNode } from '../actions/move_node';\nimport { actionNoop } from '../actions/noop';\nimport { behaviorDraw } from './draw';\nimport { geoChooseEdge, geoHasSelfIntersections } from '../geo';\nimport { modeBrowse } from '../modes/browse';\nimport { modeSelect } from '../modes/select';\nimport { osmNode } from '../osm/node';\nimport { utilRebind } from '../util/rebind';\nimport { utilKeybinding } from '../util';\n\nexport function behaviorDrawWay(context, wayID, mode, startGraph) {\n\n var dispatch = d3_dispatch('rejectedSelfIntersection');\n\n var behavior = behaviorDraw(context);\n\n // Must be set by `drawWay.nodeIndex` before each install of this behavior.\n var _nodeIndex;\n\n var _origWay;\n var _wayGeometry;\n var _headNodeID;\n var _annotation;\n\n var _pointerHasMoved = false;\n\n // The osmNode to be placed.\n // This is temporary and just follows the mouse cursor until an \"add\" event occurs.\n var _drawNode;\n\n var _didResolveTempEdit = false;\n\n function createDrawNode(loc) {\n // don't make the draw node until we actually need it\n _drawNode = osmNode({ loc: loc });\n\n context.pauseChangeDispatch();\n context.replace(function actionAddDrawNode(graph) {\n // add the draw node to the graph and insert it into the way\n var way = graph.entity(wayID);\n return graph\n .replace(_drawNode)\n .replace(way.addNode(_drawNode.id, _nodeIndex));\n }, _annotation);\n context.resumeChangeDispatch();\n\n setActiveElements();\n }\n\n function removeDrawNode() {\n\n context.pauseChangeDispatch();\n context.replace(\n function actionDeleteDrawNode(graph) {\n var way = graph.entity(wayID);\n return graph\n .replace(way.removeNode(_drawNode.id))\n .remove(_drawNode);\n },\n _annotation\n );\n _drawNode = undefined;\n context.resumeChangeDispatch();\n }\n\n\n function keydown() {\n if (d3_event.keyCode === utilKeybinding.modifierCodes.alt) {\n if (context.surface().classed('nope')) {\n context.surface()\n .classed('nope-suppressed', true);\n }\n context.surface()\n .classed('nope', false)\n .classed('nope-disabled', true);\n }\n }\n\n\n function keyup() {\n if (d3_event.keyCode === utilKeybinding.modifierCodes.alt) {\n if (context.surface().classed('nope-suppressed')) {\n context.surface()\n .classed('nope', true);\n }\n context.surface()\n .classed('nope-suppressed', false)\n .classed('nope-disabled', false);\n }\n }\n\n\n function allowsVertex(d) {\n return d.geometry(context.graph()) === 'vertex' || presetManager.allowsVertex(d, context.graph());\n }\n\n\n // related code\n // - `mode/drag_node.js` `doMove()`\n // - `behavior/draw.js` `click()`\n // - `behavior/draw_way.js` `move()`\n function move(datum) {\n\n var loc = context.map().mouseCoordinates();\n\n if (!_drawNode) createDrawNode(loc);\n\n context.surface().classed('nope-disabled', d3_event.altKey);\n\n var targetLoc = datum && datum.properties && datum.properties.entity &&\n allowsVertex(datum.properties.entity) && datum.properties.entity.loc;\n var targetNodes = datum && datum.properties && datum.properties.nodes;\n\n if (targetLoc) { // snap to node/vertex - a point target with `.loc`\n loc = targetLoc;\n\n } else if (targetNodes) { // snap to way - a line target with `.nodes`\n var choice = geoChooseEdge(targetNodes, context.map().mouse(), context.projection, _drawNode.id);\n if (choice) {\n loc = choice.loc;\n }\n }\n\n context.replace(actionMoveNode(_drawNode.id, loc), _annotation);\n _drawNode = context.entity(_drawNode.id);\n checkGeometry(true /* includeDrawNode */);\n }\n\n\n // Check whether this edit causes the geometry to break.\n // If so, class the surface with a nope cursor.\n // `includeDrawNode` - Only check the relevant line segments if finishing drawing\n function checkGeometry(includeDrawNode) {\n var nopeDisabled = context.surface().classed('nope-disabled');\n var isInvalid = isInvalidGeometry(includeDrawNode);\n\n if (nopeDisabled) {\n context.surface()\n .classed('nope', false)\n .classed('nope-suppressed', isInvalid);\n } else {\n context.surface()\n .classed('nope', isInvalid)\n .classed('nope-suppressed', false);\n }\n }\n\n\n function isInvalidGeometry(includeDrawNode) {\n\n var testNode = _drawNode;\n\n // we only need to test the single way we're drawing\n var parentWay = context.graph().entity(wayID);\n var nodes = context.graph().childNodes(parentWay).slice(); // shallow copy\n\n if (includeDrawNode) {\n if (parentWay.isClosed()) {\n // don't test the last segment for closed ways - #4655\n // (still test the first segement)\n nodes.pop();\n }\n } else { // discount the draw node\n\n if (parentWay.isClosed()) {\n if (nodes.length < 3) return false;\n if (_drawNode) nodes.splice(-2, 1);\n testNode = nodes[nodes.length - 2];\n } else {\n // there's nothing we need to test if we ignore the draw node on open ways\n return false;\n }\n }\n\n return testNode && geoHasSelfIntersections(nodes, testNode.id);\n }\n\n\n function undone() {\n\n // undoing removed the temp edit\n _didResolveTempEdit = true;\n\n context.pauseChangeDispatch();\n\n var nextMode;\n\n if (context.graph() === startGraph) { // we've undone back to the beginning\n nextMode = modeSelect(context, [wayID]);\n } else {\n context.history()\n .on('undone.draw', null);\n // remove whatever segment was drawn previously\n context.undo();\n\n if (context.graph() === startGraph) { // we've undone back to the beginning\n nextMode = modeSelect(context, [wayID]);\n } else {\n // continue drawing\n nextMode = mode;\n }\n }\n\n // clear the redo stack by adding and removing an edit\n context.perform(actionNoop());\n context.pop(1);\n\n context.resumeChangeDispatch();\n context.enter(nextMode);\n }\n\n\n function setActiveElements() {\n if (!_drawNode) return;\n\n context.surface().selectAll('.' + _drawNode.id)\n .classed('active', true);\n }\n\n\n function resetToStartGraph() {\n while (context.graph() !== startGraph) {\n context.pop();\n }\n }\n\n\n var drawWay = function(surface) {\n _drawNode = undefined;\n _didResolveTempEdit = false;\n _origWay = context.entity(wayID);\n _headNodeID = typeof _nodeIndex === 'number' ? _origWay.nodes[_nodeIndex] :\n (_origWay.isClosed() ? _origWay.nodes[_origWay.nodes.length - 2] : _origWay.nodes[_origWay.nodes.length - 1]);\n _wayGeometry = _origWay.geometry(context.graph());\n _annotation = t((_origWay.isDegenerate() ?\n 'operations.start.annotation.' :\n 'operations.continue.annotation.') + _wayGeometry\n );\n _pointerHasMoved = false;\n\n // Push an annotated state for undo to return back to.\n // We must make sure to replace or remove it later.\n context.pauseChangeDispatch();\n context.perform(actionNoop(), _annotation);\n context.resumeChangeDispatch();\n\n behavior.hover()\n .initialNodeID(_headNodeID);\n\n behavior\n .on('move', function() {\n _pointerHasMoved = true;\n move.apply(this, arguments);\n })\n .on('down', function() {\n move.apply(this, arguments);\n })\n .on('downcancel', function() {\n if (_drawNode) removeDrawNode();\n })\n .on('click', drawWay.add)\n .on('clickWay', drawWay.addWay)\n .on('clickNode', drawWay.addNode)\n .on('undo', context.undo)\n .on('cancel', drawWay.cancel)\n .on('finish', drawWay.finish);\n\n d3_select(window)\n .on('keydown.drawWay', keydown)\n .on('keyup.drawWay', keyup);\n\n context.map()\n .dblclickZoomEnable(false)\n .on('drawn.draw', setActiveElements);\n\n setActiveElements();\n\n surface.call(behavior);\n\n context.history()\n .on('undone.draw', undone);\n };\n\n\n drawWay.off = function(surface) {\n\n if (!_didResolveTempEdit) {\n // Drawing was interrupted unexpectedly.\n // This can happen if the user changes modes,\n // clicks geolocate button, a hashchange event occurs, etc.\n\n context.pauseChangeDispatch();\n resetToStartGraph();\n context.resumeChangeDispatch();\n }\n\n _drawNode = undefined;\n _nodeIndex = undefined;\n\n context.map()\n .on('drawn.draw', null);\n\n surface.call(behavior.off)\n .selectAll('.active')\n .classed('active', false);\n\n surface\n .classed('nope', false)\n .classed('nope-suppressed', false)\n .classed('nope-disabled', false);\n\n d3_select(window)\n .on('keydown.drawWay', null)\n .on('keyup.drawWay', null);\n\n context.history()\n .on('undone.draw', null);\n };\n\n\n function attemptAdd(d, loc, doAdd) {\n\n if (_drawNode) {\n // move the node to the final loc in case move wasn't called\n // consistently (e.g. on touch devices)\n context.replace(actionMoveNode(_drawNode.id, loc), _annotation);\n _drawNode = context.entity(_drawNode.id);\n } else {\n createDrawNode(loc);\n }\n\n checkGeometry(true /* includeDrawNode */);\n if ((d && d.properties && d.properties.nope) || context.surface().classed('nope')) {\n if (!_pointerHasMoved) {\n // prevent the temporary draw node from appearing on touch devices\n removeDrawNode();\n }\n dispatch.call('rejectedSelfIntersection', this);\n return; // can't click here\n }\n\n context.pauseChangeDispatch();\n doAdd();\n // we just replaced the temporary edit with the real one\n _didResolveTempEdit = true;\n context.resumeChangeDispatch();\n\n context.enter(mode);\n }\n\n\n // Accept the current position of the drawing node\n drawWay.add = function(loc, d) {\n attemptAdd(d, loc, function() {\n // don't need to do anything extra\n });\n };\n\n\n // Connect the way to an existing way\n drawWay.addWay = function(loc, edge, d) {\n attemptAdd(d, loc, function() {\n context.replace(\n actionAddMidpoint({ loc: loc, edge: edge }, _drawNode),\n _annotation\n );\n });\n };\n\n\n // Connect the way to an existing node\n drawWay.addNode = function(node, d) {\n\n // finish drawing if the mapper targets the prior node\n if (node.id === _headNodeID ||\n // or the first node when drawing an area\n (_origWay.isClosed() && node.id === _origWay.first())) {\n drawWay.finish();\n return;\n }\n\n attemptAdd(d, node.loc, function() {\n context.replace(\n function actionReplaceDrawNode(graph) {\n // remove the temporary draw node and insert the existing node\n // at the same index\n\n graph = graph\n .replace(graph.entity(wayID).removeNode(_drawNode.id))\n .remove(_drawNode);\n return graph\n .replace(graph.entity(wayID).addNode(node.id, _nodeIndex));\n },\n _annotation\n );\n });\n };\n\n\n // Finish the draw operation, removing the temporary edit.\n // If the way has enough nodes to be valid, it's selected.\n // Otherwise, delete everything and return to browse mode.\n drawWay.finish = function() {\n checkGeometry(false /* includeDrawNode */);\n if (context.surface().classed('nope')) {\n dispatch.call('rejectedSelfIntersection', this);\n return; // can't click here\n }\n\n context.pauseChangeDispatch();\n // remove the temporary edit\n context.pop(1);\n _didResolveTempEdit = true;\n context.resumeChangeDispatch();\n\n var way = context.hasEntity(wayID);\n if (!way || way.isDegenerate()) {\n drawWay.cancel();\n return;\n }\n\n window.setTimeout(function() {\n context.map().dblclickZoomEnable(true);\n }, 1000);\n\n var isNewFeature = !mode.isContinuing;\n context.enter(modeSelect(context, [wayID]).newFeature(isNewFeature));\n };\n\n\n // Cancel the draw operation, delete everything, and return to browse mode.\n drawWay.cancel = function() {\n context.pauseChangeDispatch();\n resetToStartGraph();\n context.resumeChangeDispatch();\n\n window.setTimeout(function() {\n context.map().dblclickZoomEnable(true);\n }, 1000);\n\n context.surface()\n .classed('nope', false)\n .classed('nope-disabled', false)\n .classed('nope-suppressed', false);\n\n context.enter(modeBrowse(context));\n };\n\n\n drawWay.nodeIndex = function(val) {\n if (!arguments.length) return _nodeIndex;\n _nodeIndex = val;\n return drawWay;\n };\n\n\n drawWay.activeID = function() {\n if (!arguments.length) return _drawNode && _drawNode.id;\n // no assign\n return drawWay;\n };\n\n\n return utilRebind(drawWay, dispatch, 'on');\n}\n","import { t } from '../core/localizer';\nimport { behaviorDrawWay } from '../behavior/draw_way';\n\n\nexport function modeDrawLine(context, wayID, startGraph, button, affix, continuing) {\n var mode = {\n button: button,\n id: 'draw-line'\n };\n\n var behavior = behaviorDrawWay(context, wayID, mode, startGraph)\n .on('rejectedSelfIntersection.modeDrawLine', function() {\n context.ui().flash\n .text(t('self_intersection.error.lines'))();\n });\n\n mode.wayID = wayID;\n\n mode.isContinuing = continuing;\n\n mode.enter = function() {\n behavior\n .nodeIndex(affix === 'prefix' ? 0 : undefined);\n\n context.install(behavior);\n };\n\n mode.exit = function() {\n context.uninstall(behavior);\n };\n\n mode.selectedIDs = function() {\n return [wayID];\n };\n\n mode.activeID = function() {\n return (behavior && behavior.activeID()) || [];\n };\n\n return mode;\n}\n","import { t, localizer } from '../core/localizer';\nimport { modeDrawLine } from '../modes/draw_line';\nimport { operationDelete } from '../operations/delete';\nimport { utilDisplayLabel } from '../util';\nimport { osmRoutableHighwayTagValues } from '../osm/tags';\nimport { validationIssue, validationIssueFix } from '../core/validation';\nimport { services } from '../services';\n\nexport function validationDisconnectedWay() {\n var type = 'disconnected_way';\n\n function isTaggedAsHighway(entity) {\n return osmRoutableHighwayTagValues[entity.tags.highway];\n }\n\n\n var validation = function checkDisconnectedWay(entity, graph) {\n\n var routingIslandWays = routingIslandForEntity(entity);\n if (!routingIslandWays) return [];\n\n return [new validationIssue({\n type: type,\n subtype: 'highway',\n severity: 'warning',\n message: function(context) {\n if (this.entityIds.length === 1) {\n var entity = context.hasEntity(this.entityIds[0]);\n return entity ? t('issues.disconnected_way.highway.message', { highway: utilDisplayLabel(entity, context.graph()) }) : '';\n }\n return t('issues.disconnected_way.routable.message.multiple', { count: this.entityIds.length.toString() });\n },\n reference: showReference,\n entityIds: Array.from(routingIslandWays).map(function(way) { return way.id; }),\n dynamicFixes: makeFixes\n })];\n\n\n function makeFixes(context) {\n\n var fixes = [];\n\n var singleEntity = this.entityIds.length === 1 && context.hasEntity(this.entityIds[0]);\n\n if (singleEntity) {\n\n if (singleEntity.type === 'way' && !singleEntity.isClosed()) {\n\n var textDirection = localizer.textDirection();\n\n var startFix = makeContinueDrawingFixIfAllowed(textDirection, singleEntity.first(), 'start');\n if (startFix) fixes.push(startFix);\n\n var endFix = makeContinueDrawingFixIfAllowed(textDirection, singleEntity.last(), 'end');\n if (endFix) fixes.push(endFix);\n }\n if (!fixes.length) {\n fixes.push(new validationIssueFix({\n title: t('issues.fix.connect_feature.title')\n }));\n }\n\n fixes.push(new validationIssueFix({\n icon: 'iD-operation-delete',\n title: t('issues.fix.delete_feature.title'),\n entityIds: [singleEntity.id],\n onClick: function(context) {\n var id = this.issue.entityIds[0];\n var operation = operationDelete(context, [id]);\n if (!operation.disabled()) {\n operation();\n }\n }\n }));\n } else {\n fixes.push(new validationIssueFix({\n title: t('issues.fix.connect_features.title')\n }));\n }\n\n return fixes;\n }\n\n\n function showReference(selection) {\n selection.selectAll('.issue-reference')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'issue-reference')\n .text(t('issues.disconnected_way.routable.reference'));\n }\n\n function routingIslandForEntity(entity) {\n\n var routingIsland = new Set(); // the interconnected routable features\n var waysToCheck = []; // the queue of remaining routable ways to traverse\n\n function queueParentWays(node) {\n graph.parentWays(node).forEach(function(parentWay) {\n if (!routingIsland.has(parentWay) && // only check each feature once\n isRoutableWay(parentWay, false)) { // only check routable features\n routingIsland.add(parentWay);\n waysToCheck.push(parentWay);\n }\n });\n }\n\n if (entity.type === 'way' && isRoutableWay(entity, true)) {\n\n routingIsland.add(entity);\n waysToCheck.push(entity);\n\n } else if (entity.type === 'node' && isRoutableNode(entity)) {\n\n routingIsland.add(entity);\n queueParentWays(entity);\n\n } else {\n // this feature isn't routable, cannot be a routing island\n return null;\n }\n\n while (waysToCheck.length) {\n var wayToCheck = waysToCheck.pop();\n var childNodes = graph.childNodes(wayToCheck);\n for (var i in childNodes) {\n var vertex = childNodes[i];\n\n if (isConnectedVertex(vertex)) {\n // found a link to the wider network, not a routing island\n return null;\n }\n\n if (isRoutableNode(vertex)) {\n routingIsland.add(vertex);\n }\n\n queueParentWays(vertex);\n }\n }\n\n // no network link found, this is a routing island, return its members\n return routingIsland;\n }\n\n function isConnectedVertex(vertex) {\n // assume ways overlapping unloaded tiles are connected to the wider road network - #5938\n var osm = services.osm;\n if (osm && !osm.isDataLoaded(vertex.loc)) return true;\n\n // entrances are considered connected\n if (vertex.tags.entrance &&\n vertex.tags.entrance !== 'no') return true;\n if (vertex.tags.amenity === 'parking_entrance') return true;\n\n return false;\n }\n\n function isRoutableNode(node) {\n // treat elevators as distinct features in the highway network\n if (node.tags.highway === 'elevator') return true;\n return false;\n }\n\n function isRoutableWay(way, ignoreInnerWays) {\n if (isTaggedAsHighway(way) || way.tags.route === 'ferry') return true;\n\n return graph.parentRelations(way).some(function(parentRelation) {\n if (parentRelation.tags.type === 'route' &&\n parentRelation.tags.route === 'ferry') return true;\n\n if (parentRelation.isMultipolygon() &&\n isTaggedAsHighway(parentRelation) &&\n (!ignoreInnerWays || parentRelation.memberById(way.id).role !== 'inner')) return true;\n });\n }\n\n function makeContinueDrawingFixIfAllowed(textDirection, vertexID, whichEnd) {\n var vertex = graph.hasEntity(vertexID);\n if (!vertex || vertex.tags.noexit === 'yes') return null;\n\n var useLeftContinue = (whichEnd === 'start' && textDirection === 'ltr') ||\n (whichEnd === 'end' && textDirection === 'rtl');\n\n return new validationIssueFix({\n icon: 'iD-operation-continue' + (useLeftContinue ? '-left' : ''),\n title: t('issues.fix.continue_from_' + whichEnd + '.title'),\n entityIds: [vertexID],\n onClick: function(context) {\n var wayId = this.issue.entityIds[0];\n var way = context.hasEntity(wayId);\n var vertexId = this.entityIds[0];\n var vertex = context.hasEntity(vertexId);\n\n if (!way || !vertex) return;\n\n // make sure the vertex is actually visible and editable\n var map = context.map();\n if (!context.editable() || !map.trimmedExtent().contains(vertex.loc)) {\n map.zoomToEase(vertex);\n }\n\n context.enter(\n modeDrawLine(context, wayId, context.graph(), 'line', way.affix(vertexId), true)\n );\n }\n });\n }\n\n };\n\n validation.type = type;\n\n return validation;\n}\n","import { t } from '../core/localizer';\nimport { utilDisplayLabel } from '../util';\nimport { validationIssue } from '../core/validation';\n\nexport function validationFormatting() {\n var type = 'invalid_format';\n\n var validation = function(entity) {\n var issues = [];\n\n function isValidEmail(email) {\n // Emails in OSM are going to be official so they should be pretty simple\n // Using negated lists to better support all possible unicode characters (#6494)\n var valid_email = /^[^\\(\\)\\\\,\":;<>@\\[\\]]+@[^\\(\\)\\\\,\":;<>@\\[\\]\\.]+(?:\\.[a-z0-9-]+)*$/i;\n\n // An empty value is also acceptable\n return (!email || valid_email.test(email));\n }\n /*\n function isSchemePresent(url) {\n var valid_scheme = /^https?:\\/\\//i;\n return (!url || valid_scheme.test(url));\n }\n */\n function showReferenceEmail(selection) {\n selection.selectAll('.issue-reference')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'issue-reference')\n .text(t('issues.invalid_format.email.reference'));\n }\n /*\n function showReferenceWebsite(selection) {\n selection.selectAll('.issue-reference')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'issue-reference')\n .text(t('issues.invalid_format.website.reference'));\n }\n\n if (entity.tags.website) {\n // Multiple websites are possible\n // If ever we support ES6, arrow functions make this nicer\n var websites = entity.tags.website\n .split(';')\n .map(function(s) { return s.trim(); })\n .filter(function(x) { return !isSchemePresent(x); });\n\n if (websites.length) {\n issues.push(new validationIssue({\n type: type,\n subtype: 'website',\n severity: 'warning',\n message: function(context) {\n var entity = context.hasEntity(this.entityIds[0]);\n return entity ? t('issues.invalid_format.website.message' + this.data,\n { feature: utilDisplayLabel(entity, context.graph()), site: websites.join(', ') }) : '';\n },\n reference: showReferenceWebsite,\n entityIds: [entity.id],\n hash: websites.join(),\n data: (websites.length > 1) ? '_multi' : ''\n }));\n }\n }\n */\n if (entity.tags.email) {\n // Multiple emails are possible\n var emails = entity.tags.email\n .split(';')\n .map(function(s) { return s.trim(); })\n .filter(function(x) { return !isValidEmail(x); });\n\n if (emails.length) {\n issues.push(new validationIssue({\n type: type,\n subtype: 'email',\n severity: 'warning',\n message: function(context) {\n var entity = context.hasEntity(this.entityIds[0]);\n return entity ? t('issues.invalid_format.email.message' + this.data,\n { feature: utilDisplayLabel(entity, context.graph()), email: emails.join(', ') }) : '';\n },\n reference: showReferenceEmail,\n entityIds: [entity.id],\n hash: emails.join(),\n data: (emails.length > 1) ? '_multi' : ''\n }));\n }\n }\n\n return issues;\n };\n\n validation.type = type;\n\n return validation;\n}\n","import { t } from '../core/localizer';\nimport { utilDisplayLabel } from '../util';\nimport { validationIssue, validationIssueFix } from '../core/validation';\n\n\nexport function validationHelpRequest(context) {\n var type = 'help_request';\n\n var validation = function checkFixmeTag(entity) {\n\n if (!entity.tags.fixme) return [];\n\n // don't flag fixmes on features added by the user\n if (entity.version === undefined) return [];\n\n if (entity.v !== undefined) {\n var baseEntity = context.history().base().hasEntity(entity.id);\n // don't flag fixmes added by the user on existing features\n if (!baseEntity || !baseEntity.tags.fixme) return [];\n }\n\n return [new validationIssue({\n type: type,\n subtype: 'fixme_tag',\n severity: 'warning',\n message: function(context) {\n var entity = context.hasEntity(this.entityIds[0]);\n return entity ? t('issues.fixme_tag.message', { feature: utilDisplayLabel(entity, context.graph()) }) : '';\n },\n dynamicFixes: function() {\n return [\n new validationIssueFix({\n title: t('issues.fix.address_the_concern.title')\n })\n ];\n },\n reference: showReference,\n entityIds: [entity.id]\n })];\n\n function showReference(selection) {\n selection.selectAll('.issue-reference')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'issue-reference')\n .text(t('issues.fixme_tag.reference'));\n }\n };\n\n validation.type = type;\n\n return validation;\n}\n","import { localizer } from '../core/localizer';\nimport { t } from '../core/localizer';\nimport { modeDrawLine } from '../modes/draw_line';\nimport { actionReverse } from '../actions/reverse';\nimport { utilDisplayLabel } from '../util';\nimport { osmFlowingWaterwayTagValues, osmOneWayTags, osmRoutableHighwayTagValues } from '../osm/tags';\nimport { validationIssue, validationIssueFix } from '../core/validation';\nimport { services } from '../services';\n\nexport function validationImpossibleOneway() {\n var type = 'impossible_oneway';\n\n var validation = function checkImpossibleOneway(entity, graph) {\n\n if (entity.type !== 'way' || entity.geometry(graph) !== 'line') return [];\n\n if (entity.isClosed()) return [];\n\n if (!typeForWay(entity)) return [];\n\n if (!isOneway(entity)) return [];\n\n var firstIssues = issuesForNode(entity, entity.first());\n var lastIssues = issuesForNode(entity, entity.last());\n\n return firstIssues.concat(lastIssues);\n\n function typeForWay(way) {\n if (way.geometry(graph) !== 'line') return null;\n\n if (osmRoutableHighwayTagValues[way.tags.highway]) return 'highway';\n if (osmFlowingWaterwayTagValues[way.tags.waterway]) return 'waterway';\n return null;\n }\n\n function isOneway(way) {\n if (way.tags.oneway === 'yes') return true;\n if (way.tags.oneway) return false;\n\n for (var key in way.tags) {\n if (osmOneWayTags[key] && osmOneWayTags[key][way.tags[key]]) {\n return true;\n }\n }\n return false;\n }\n\n function nodeOccursMoreThanOnce(way, nodeID) {\n var occurences = 0;\n for (var index in way.nodes) {\n if (way.nodes[index] === nodeID) {\n occurences += 1;\n if (occurences > 1) return true;\n }\n }\n return false;\n }\n\n function isConnectedViaOtherTypes(way, node) {\n\n var wayType = typeForWay(way);\n\n if (wayType === 'highway') {\n // entrances are considered connected\n if (node.tags.entrance && node.tags.entrance !== 'no') return true;\n if (node.tags.amenity === 'parking_entrance') return true;\n } else if (wayType === 'waterway') {\n if (node.id === way.first()) {\n // multiple waterways may start at the same spring\n if (node.tags.natural === 'spring') return true;\n } else {\n // multiple waterways may end at the same drain\n if (node.tags.manhole === 'drain') return true;\n }\n }\n\n return graph.parentWays(node).some(function(parentWay) {\n if (parentWay.id === way.id) return false;\n\n if (wayType === 'highway') {\n\n // allow connections to highway areas\n if (parentWay.geometry(graph) === 'area' &&\n osmRoutableHighwayTagValues[parentWay.tags.highway]) return true;\n\n // count connections to ferry routes as connected\n if (parentWay.tags.route === 'ferry') return true;\n\n return graph.parentRelations(parentWay).some(function(parentRelation) {\n if (parentRelation.tags.type === 'route' &&\n parentRelation.tags.route === 'ferry') return true;\n\n // allow connections to highway multipolygons\n return parentRelation.isMultipolygon() && osmRoutableHighwayTagValues[parentRelation.tags.highway];\n });\n } else if (wayType === 'waterway') {\n // multiple waterways may start or end at a water body at the same node\n if (parentWay.tags.natural === 'water' ||\n parentWay.tags.natural === 'coastline') return true;\n }\n return false;\n });\n }\n\n function issuesForNode(way, nodeID) {\n\n var isFirst = nodeID === way.first();\n\n var wayType = typeForWay(way);\n\n // ignore if this way is self-connected at this node\n if (nodeOccursMoreThanOnce(way, nodeID)) return [];\n\n var osm = services.osm;\n if (!osm) return [];\n\n var node = graph.hasEntity(nodeID);\n\n // ignore if this node or its tile are unloaded\n if (!node || !osm.isDataLoaded(node.loc)) return [];\n\n if (isConnectedViaOtherTypes(way, node)) return [];\n\n var attachedWaysOfSameType = graph.parentWays(node).filter(function(parentWay) {\n if (parentWay.id === way.id) return false;\n return typeForWay(parentWay) === wayType;\n });\n\n // assume it's okay for waterways to start or end disconnected for now\n if (wayType === 'waterway' && attachedWaysOfSameType.length === 0) return [];\n\n var attachedOneways = attachedWaysOfSameType.filter(function(attachedWay) {\n return isOneway(attachedWay);\n });\n\n // ignore if the way is connected to some non-oneway features\n if (attachedOneways.length < attachedWaysOfSameType.length) return [];\n\n if (attachedOneways.length) {\n var connectedEndpointsOkay = attachedOneways.some(function(attachedOneway) {\n if ((isFirst ? attachedOneway.first() : attachedOneway.last()) !== nodeID) return true;\n if (nodeOccursMoreThanOnce(attachedOneway, nodeID)) return true;\n return false;\n });\n if (connectedEndpointsOkay) return [];\n }\n\n var placement = isFirst ? 'start' : 'end',\n messageID = wayType + '.',\n referenceID = wayType + '.';\n\n if (wayType === 'waterway') {\n messageID += 'connected.' + placement;\n referenceID += 'connected';\n } else {\n messageID += placement;\n referenceID += placement;\n }\n\n return [new validationIssue({\n type: type,\n subtype: wayType,\n severity: 'warning',\n message: function(context) {\n var entity = context.hasEntity(this.entityIds[0]);\n return entity ? t('issues.impossible_oneway.' + messageID + '.message', {\n feature: utilDisplayLabel(entity, context.graph())\n }) : '';\n },\n reference: getReference(referenceID),\n entityIds: [way.id, node.id],\n dynamicFixes: function() {\n\n var fixes = [];\n\n if (attachedOneways.length) {\n fixes.push(new validationIssueFix({\n icon: 'iD-operation-reverse',\n title: t('issues.fix.reverse_feature.title'),\n entityIds: [way.id],\n onClick: function(context) {\n var id = this.issue.entityIds[0];\n context.perform(actionReverse(id), t('operations.reverse.annotation'));\n }\n }));\n }\n if (node.tags.noexit !== 'yes') {\n var textDirection = localizer.textDirection();\n var useLeftContinue = (isFirst && textDirection === 'ltr') ||\n (!isFirst && textDirection === 'rtl');\n fixes.push(new validationIssueFix({\n icon: 'iD-operation-continue' + (useLeftContinue ? '-left' : ''),\n title: t('issues.fix.continue_from_' + (isFirst ? 'start' : 'end') + '.title'),\n onClick: function(context) {\n var entityID = this.issue.entityIds[0];\n var vertexID = this.issue.entityIds[1];\n var way = context.entity(entityID);\n var vertex = context.entity(vertexID);\n continueDrawing(way, vertex, context);\n }\n }));\n }\n\n return fixes;\n },\n loc: node.loc\n })];\n\n function getReference(referenceID) {\n return function showReference(selection) {\n selection.selectAll('.issue-reference')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'issue-reference')\n .text(t('issues.impossible_oneway.' + referenceID + '.reference'));\n };\n }\n }\n };\n\n function continueDrawing(way, vertex, context) {\n // make sure the vertex is actually visible and editable\n var map = context.map();\n if (!context.editable() || !map.trimmedExtent().contains(vertex.loc)) {\n map.zoomToEase(vertex);\n }\n\n context.enter(\n modeDrawLine(context, way.id, context.graph(), 'line', way.affix(vertex.id), true)\n );\n }\n\n validation.type = type;\n\n return validation;\n}\n","import { t } from '../core/localizer';\nimport { utilDisplayLabel } from '../util';\nimport { validationIssue, validationIssueFix } from '../core/validation';\n\n\nexport function validationIncompatibleSource() {\n var type = 'incompatible_source';\n var invalidSources = [\n {\n id:'google', regex:'google', exceptRegex: 'books.google|Google Books|drive.google|googledrive|Google Drive'\n }\n ];\n\n var validation = function checkIncompatibleSource(entity) {\n\n var entitySources = entity.tags && entity.tags.source && entity.tags.source.split(';');\n\n if (!entitySources) return [];\n\n var issues = [];\n\n invalidSources.forEach(function(invalidSource) {\n\n var hasInvalidSource = entitySources.some(function(source) {\n if (!source.match(new RegExp(invalidSource.regex, 'i'))) return false;\n if (invalidSource.exceptRegex && source.match(new RegExp(invalidSource.exceptRegex, 'i'))) return false;\n return true;\n });\n\n if (!hasInvalidSource) return;\n\n issues.push(new validationIssue({\n type: type,\n severity: 'warning',\n message: function(context) {\n var entity = context.hasEntity(this.entityIds[0]);\n return entity ? t('issues.incompatible_source.' + invalidSource.id + '.feature.message', {\n feature: utilDisplayLabel(entity, context.graph())\n }) : '';\n },\n reference: getReference(invalidSource.id),\n entityIds: [entity.id],\n dynamicFixes: function() {\n return [\n new validationIssueFix({\n title: t('issues.fix.remove_proprietary_data.title')\n })\n ];\n }\n }));\n });\n\n return issues;\n\n\n function getReference(id) {\n return function showReference(selection) {\n selection.selectAll('.issue-reference')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'issue-reference')\n .text(t('issues.incompatible_source.' + id + '.reference'));\n };\n }\n };\n\n validation.type = type;\n\n return validation;\n}\n","import { services } from '../services';\n\n\nexport function validationMaprules() {\n var type = 'maprules';\n\n var validation = function checkMaprules(entity, graph) {\n if (!services.maprules) return [];\n\n var rules = services.maprules.validationRules();\n var issues = [];\n\n for (var i = 0; i < rules.length; i++) {\n var rule = rules[i];\n rule.findIssues(entity, graph, issues);\n }\n\n return issues;\n };\n\n\n validation.type = type;\n\n return validation;\n}\n","import { actionAddVertex } from '../actions/add_vertex';\nimport { actionChangeTags } from '../actions/change_tags';\nimport { actionMergeNodes } from '../actions/merge_nodes';\nimport { actionExtract } from '../actions/extract';\nimport { modeSelect } from '../modes/select';\nimport { osmJoinWays } from '../osm/multipolygon';\nimport { osmNodeGeometriesForTags } from '../osm/tags';\nimport { presetManager } from '../presets';\nimport { geoHasSelfIntersections, geoSphericalDistance } from '../geo';\nimport { t } from '../core/localizer';\nimport { utilDisplayLabel, utilTagText } from '../util';\nimport { validationIssue, validationIssueFix } from '../core/validation';\n\n\nexport function validationMismatchedGeometry() {\n var type = 'mismatched_geometry';\n\n function tagSuggestingLineIsArea(entity) {\n if (entity.type !== 'way' || entity.isClosed()) return null;\n\n var tagSuggestingArea = entity.tagSuggestingArea();\n if (!tagSuggestingArea) {\n return null;\n }\n\n var asLine = presetManager.matchTags(tagSuggestingArea, 'line');\n var asArea = presetManager.matchTags(tagSuggestingArea, 'area');\n if (asLine && asArea && (asLine === asArea)) {\n // these tags also allow lines and making this an area wouldn't matter\n return null;\n }\n\n return tagSuggestingArea;\n }\n\n\n function makeConnectEndpointsFixOnClick(way, graph) {\n // must have at least three nodes to close this automatically\n if (way.nodes.length < 3) return null;\n\n var nodes = graph.childNodes(way), testNodes;\n var firstToLastDistanceMeters = geoSphericalDistance(nodes[0].loc, nodes[nodes.length-1].loc);\n\n // if the distance is very small, attempt to merge the endpoints\n if (firstToLastDistanceMeters < 0.75) {\n testNodes = nodes.slice(); // shallow copy\n testNodes.pop();\n testNodes.push(testNodes[0]);\n // make sure this will not create a self-intersection\n if (!geoHasSelfIntersections(testNodes, testNodes[0].id)) {\n return function(context) {\n var way = context.entity(this.issue.entityIds[0]);\n context.perform(\n actionMergeNodes([way.nodes[0], way.nodes[way.nodes.length-1]], nodes[0].loc),\n t('issues.fix.connect_endpoints.annotation')\n );\n };\n }\n }\n\n // if the points were not merged, attempt to close the way\n testNodes = nodes.slice(); // shallow copy\n testNodes.push(testNodes[0]);\n // make sure this will not create a self-intersection\n if (!geoHasSelfIntersections(testNodes, testNodes[0].id)) {\n return function(context) {\n var wayId = this.issue.entityIds[0];\n var way = context.entity(wayId);\n var nodeId = way.nodes[0];\n var index = way.nodes.length;\n context.perform(\n actionAddVertex(wayId, nodeId, index),\n t('issues.fix.connect_endpoints.annotation')\n );\n };\n }\n }\n\n function lineTaggedAsAreaIssue(entity) {\n\n var tagSuggestingArea = tagSuggestingLineIsArea(entity);\n if (!tagSuggestingArea) return null;\n\n return new validationIssue({\n type: type,\n subtype: 'area_as_line',\n severity: 'warning',\n message: function(context) {\n var entity = context.hasEntity(this.entityIds[0]);\n return entity ? t('issues.tag_suggests_area.message', {\n feature: utilDisplayLabel(entity, context.graph()),\n tag: utilTagText({ tags: tagSuggestingArea })\n }) : '';\n },\n reference: showReference,\n entityIds: [entity.id],\n hash: JSON.stringify(tagSuggestingArea),\n dynamicFixes: function(context) {\n\n var fixes = [];\n\n var entity = context.entity(this.entityIds[0]);\n var connectEndsOnClick = makeConnectEndpointsFixOnClick(entity, context.graph());\n\n fixes.push(new validationIssueFix({\n title: t('issues.fix.connect_endpoints.title'),\n onClick: connectEndsOnClick\n }));\n\n fixes.push(new validationIssueFix({\n icon: 'iD-operation-delete',\n title: t('issues.fix.remove_tag.title'),\n onClick: function(context) {\n var entityId = this.issue.entityIds[0];\n var entity = context.entity(entityId);\n var tags = Object.assign({}, entity.tags); // shallow copy\n for (var key in tagSuggestingArea) {\n delete tags[key];\n }\n context.perform(\n actionChangeTags(entityId, tags),\n t('issues.fix.remove_tag.annotation')\n );\n }\n }));\n\n return fixes;\n }\n });\n\n\n function showReference(selection) {\n selection.selectAll('.issue-reference')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'issue-reference')\n .text(t('issues.tag_suggests_area.reference'));\n }\n }\n\n function vertexTaggedAsPointIssue(entity, graph) {\n // we only care about nodes\n if (entity.type !== 'node') return null;\n\n // ignore tagless points\n if (Object.keys(entity.tags).length === 0) return null;\n\n // address lines are special so just ignore them\n if (entity.isOnAddressLine(graph)) return null;\n\n var geometry = entity.geometry(graph);\n var allowedGeometries = osmNodeGeometriesForTags(entity.tags);\n\n if (geometry === 'point' && !allowedGeometries.point && allowedGeometries.vertex) {\n\n return new validationIssue({\n type: type,\n subtype: 'vertex_as_point',\n severity: 'warning',\n message: function(context) {\n var entity = context.hasEntity(this.entityIds[0]);\n return entity ? t('issues.vertex_as_point.message', {\n feature: utilDisplayLabel(entity, context.graph())\n }) : '';\n },\n reference: function showReference(selection) {\n selection.selectAll('.issue-reference')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'issue-reference')\n .text(t('issues.vertex_as_point.reference'));\n },\n entityIds: [entity.id]\n });\n\n } else if (geometry === 'vertex' && !allowedGeometries.vertex && allowedGeometries.point) {\n\n return new validationIssue({\n type: type,\n subtype: 'point_as_vertex',\n severity: 'warning',\n message: function(context) {\n var entity = context.hasEntity(this.entityIds[0]);\n return entity ? t('issues.point_as_vertex.message', {\n feature: utilDisplayLabel(entity, context.graph())\n }) : '';\n },\n reference: function showReference(selection) {\n selection.selectAll('.issue-reference')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'issue-reference')\n .text(t('issues.point_as_vertex.reference'));\n },\n entityIds: [entity.id],\n dynamicFixes: function(context) {\n\n var entityId = this.entityIds[0];\n\n var extractOnClick = null;\n if (!context.hasHiddenConnections(entityId)) {\n\n extractOnClick = function(context) {\n var entityId = this.issue.entityIds[0];\n var action = actionExtract(entityId);\n context.perform(\n action,\n t('operations.extract.annotation.single')\n );\n // re-enter mode to trigger updates\n context.enter(modeSelect(context, [action.getExtractedNodeID()]));\n };\n }\n\n return [\n new validationIssueFix({\n icon: 'iD-operation-extract',\n title: t('issues.fix.extract_point.title'),\n onClick: extractOnClick\n })\n ];\n }\n });\n }\n\n return null;\n }\n\n function unclosedMultipolygonPartIssues(entity, graph) {\n\n if (entity.type !== 'relation' ||\n !entity.isMultipolygon() ||\n entity.isDegenerate() ||\n // cannot determine issues for incompletely-downloaded relations\n !entity.isComplete(graph)) return null;\n\n var sequences = osmJoinWays(entity.members, graph);\n\n var issues = [];\n\n for (var i in sequences) {\n var sequence = sequences[i];\n\n if (!sequence.nodes) continue;\n\n var firstNode = sequence.nodes[0];\n var lastNode = sequence.nodes[sequence.nodes.length - 1];\n\n // part is closed if the first and last nodes are the same\n if (firstNode === lastNode) continue;\n\n var issue = new validationIssue({\n type: type,\n subtype: 'unclosed_multipolygon_part',\n severity: 'warning',\n message: function(context) {\n var entity = context.hasEntity(this.entityIds[0]);\n return entity ? t('issues.unclosed_multipolygon_part.message', {\n feature: utilDisplayLabel(entity, context.graph())\n }) : '';\n },\n reference: showReference,\n loc: sequence.nodes[0].loc,\n entityIds: [entity.id],\n hash: sequence.map(function(way) {\n return way.id;\n }).join()\n });\n issues.push(issue);\n }\n\n return issues;\n\n function showReference(selection) {\n selection.selectAll('.issue-reference')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'issue-reference')\n .text(t('issues.unclosed_multipolygon_part.reference'));\n }\n }\n\n var validation = function checkMismatchedGeometry(entity, graph) {\n var issues = [\n vertexTaggedAsPointIssue(entity, graph),\n lineTaggedAsAreaIssue(entity)\n ];\n issues = issues.concat(unclosedMultipolygonPartIssues(entity, graph));\n return issues.filter(Boolean);\n };\n\n validation.type = type;\n\n return validation;\n}\n","import { actionChangeMember } from '../actions/change_member';\nimport { actionDeleteMember } from '../actions/delete_member';\nimport { t } from '../core/localizer';\nimport { utilDisplayLabel } from '../util';\nimport { validationIssue, validationIssueFix } from '../core/validation';\n\n\nexport function validationMissingRole() {\n var type = 'missing_role';\n\n var validation = function checkMissingRole(entity, graph) {\n var issues = [];\n if (entity.type === 'way') {\n graph.parentRelations(entity).forEach(function(relation) {\n if (!relation.isMultipolygon()) return;\n\n var member = relation.memberById(entity.id);\n if (member && isMissingRole(member)) {\n issues.push(makeIssue(entity, relation, member));\n }\n });\n } else if (entity.type === 'relation' && entity.isMultipolygon()) {\n entity.indexedMembers().forEach(function(member) {\n var way = graph.hasEntity(member.id);\n if (way && isMissingRole(member)) {\n issues.push(makeIssue(way, entity, member));\n }\n });\n }\n\n return issues;\n };\n\n\n function isMissingRole(member) {\n return !member.role || !member.role.trim().length;\n }\n\n\n function makeIssue(way, relation, member) {\n return new validationIssue({\n type: type,\n severity: 'warning',\n message: function(context) {\n var member = context.hasEntity(this.entityIds[1]),\n relation = context.hasEntity(this.entityIds[0]);\n return (member && relation) ? t('issues.missing_role.message', {\n member: utilDisplayLabel(member, context.graph()),\n relation: utilDisplayLabel(relation, context.graph())\n }) : '';\n },\n reference: showReference,\n entityIds: [relation.id, way.id],\n data: {\n member: member\n },\n hash: member.index.toString(),\n dynamicFixes: function() {\n return [\n makeAddRoleFix('inner'),\n makeAddRoleFix('outer'),\n new validationIssueFix({\n icon: 'iD-operation-delete',\n title: t('issues.fix.remove_from_relation.title'),\n onClick: function(context) {\n context.perform(\n actionDeleteMember(this.issue.entityIds[0], this.issue.data.member.index),\n t('operations.delete_member.annotation')\n );\n }\n })\n ];\n }\n });\n\n\n function showReference(selection) {\n selection.selectAll('.issue-reference')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'issue-reference')\n .text(t('issues.missing_role.multipolygon.reference'));\n }\n }\n\n\n function makeAddRoleFix(role) {\n return new validationIssueFix({\n title: t('issues.fix.set_as_' + role + '.title'),\n onClick: function(context) {\n var oldMember = this.issue.data.member;\n var member = { id: this.issue.entityIds[1], type: oldMember.type, role: role };\n context.perform(\n actionChangeMember(this.issue.entityIds[0], member, oldMember.index),\n t('operations.change_role.annotation')\n );\n }\n });\n }\n\n validation.type = type;\n\n return validation;\n}\n","import { operationDelete } from '../operations/delete';\nimport { osmIsInterestingTag } from '../osm/tags';\nimport { osmOldMultipolygonOuterMemberOfRelation } from '../osm/multipolygon';\nimport { t } from '../core/localizer';\nimport { utilDisplayLabel } from '../util';\nimport { validationIssue, validationIssueFix } from '../core/validation';\n\n\nexport function validationMissingTag(context) {\n var type = 'missing_tag';\n\n function hasDescriptiveTags(entity, graph) {\n var keys = Object.keys(entity.tags)\n .filter(function(k) {\n if (k === 'area' || k === 'name') {\n return false;\n } else {\n return osmIsInterestingTag(k);\n }\n });\n\n if (entity.type === 'relation' &&\n keys.length === 1 &&\n entity.tags.type === 'multipolygon') {\n // this relation's only interesting tag just says its a multipolygon,\n // which is not descriptive enough\n\n // It's okay for a simple multipolygon to have no descriptive tags\n // if its outer way has them (old model, see `outdated_tags.js`)\n return osmOldMultipolygonOuterMemberOfRelation(entity, graph);\n }\n\n return keys.length > 0;\n }\n\n function isUnknownRoad(entity) {\n return entity.type === 'way' && entity.tags.highway === 'road';\n }\n\n function isUntypedRelation(entity) {\n return entity.type === 'relation' && !entity.tags.type;\n }\n\n var validation = function checkMissingTag(entity, graph) {\n\n var subtype;\n\n var osm = context.connection();\n var isUnloadedNode = entity.type === 'node' && osm && !osm.isDataLoaded(entity.loc);\n\n // we can't know if the node is a vertex if the tile is undownloaded\n if (!isUnloadedNode &&\n // allow untagged nodes that are part of ways\n entity.geometry(graph) !== 'vertex' &&\n // allow untagged entities that are part of relations\n !entity.hasParentRelations(graph)) {\n\n if (Object.keys(entity.tags).length === 0) {\n subtype = 'any';\n } else if (!hasDescriptiveTags(entity, graph)) {\n subtype = 'descriptive';\n } else if (isUntypedRelation(entity)) {\n subtype = 'relation_type';\n }\n }\n\n // flag an unknown road even if it's a member of a relation\n if (!subtype && isUnknownRoad(entity)) {\n subtype = 'highway_classification';\n }\n\n if (!subtype) return [];\n\n var messageID = subtype === 'highway_classification' ? 'unknown_road' : 'missing_tag.' + subtype;\n var referenceID = subtype === 'highway_classification' ? 'unknown_road' : 'missing_tag';\n\n // can always delete if the user created it in the first place..\n var canDelete = (entity.version === undefined || entity.v !== undefined);\n var severity = (canDelete && subtype !== 'highway_classification') ? 'error' : 'warning';\n\n return [new validationIssue({\n type: type,\n subtype: subtype,\n severity: severity,\n message: function(context) {\n var entity = context.hasEntity(this.entityIds[0]);\n return entity ? t('issues.' + messageID + '.message', {\n feature: utilDisplayLabel(entity, context.graph())\n }) : '';\n },\n reference: showReference,\n entityIds: [entity.id],\n dynamicFixes: function(context) {\n\n var fixes = [];\n\n var selectFixType = subtype === 'highway_classification' ? 'select_road_type' : 'select_preset';\n\n fixes.push(new validationIssueFix({\n icon: 'iD-icon-search',\n title: t('issues.fix.' + selectFixType + '.title'),\n onClick: function(context) {\n context.ui().sidebar.showPresetList();\n }\n }));\n\n var deleteOnClick;\n\n var id = this.entityIds[0];\n var operation = operationDelete(context, [id]);\n var disabledReasonID = operation.disabled();\n if (!disabledReasonID) {\n deleteOnClick = function(context) {\n var id = this.issue.entityIds[0];\n var operation = operationDelete(context, [id]);\n if (!operation.disabled()) {\n operation();\n }\n };\n }\n\n fixes.push(\n new validationIssueFix({\n icon: 'iD-operation-delete',\n title: t('issues.fix.delete_feature.title'),\n disabledReason: disabledReasonID ? t('operations.delete.' + disabledReasonID + '.single') : undefined,\n onClick: deleteOnClick\n })\n );\n\n return fixes;\n }\n })];\n\n function showReference(selection) {\n selection.selectAll('.issue-reference')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'issue-reference')\n .text(t('issues.' + referenceID + '.reference'));\n }\n };\n\n validation.type = type;\n\n return validation;\n}\n","const diacritics = require('diacritics');\n\n// remove spaces, punctuation, diacritics\nmodule.exports = (str) => {\n return diacritics.remove(\n str\n .replace(/&/g, 'and')\n .replace(/[\\s\\-=_!\"#%'*{},.\\/:;?\\(\\)\\[\\]@\\\\$\\^*+<>~`’\\u00a1\\u00a7\\u00b6\\u00b7\\u00bf\\u037e\\u0387\\u055a-\\u055f\\u0589\\u05c0\\u05c3\\u05c6\\u05f3\\u05f4\\u0609\\u060a\\u060c\\u060d\\u061b\\u061e\\u061f\\u066a-\\u066d\\u06d4\\u0700-\\u070d\\u07f7-\\u07f9\\u0830-\\u083e\\u085e\\u0964\\u0965\\u0970\\u0af0\\u0df4\\u0e4f\\u0e5a\\u0e5b\\u0f04-\\u0f12\\u0f14\\u0f85\\u0fd0-\\u0fd4\\u0fd9\\u0fda\\u104a-\\u104f\\u10fb\\u1360-\\u1368\\u166d\\u166e\\u16eb-\\u16ed\\u1735\\u1736\\u17d4-\\u17d6\\u17d8-\\u17da\\u1800-\\u1805\\u1807-\\u180a\\u1944\\u1945\\u1a1e\\u1a1f\\u1aa0-\\u1aa6\\u1aa8-\\u1aad\\u1b5a-\\u1b60\\u1bfc-\\u1bff\\u1c3b-\\u1c3f\\u1c7e\\u1c7f\\u1cc0-\\u1cc7\\u1cd3\\u2016\\u2017\\u2020-\\u2027\\u2030-\\u2038\\u203b-\\u203e\\u2041-\\u2043\\u2047-\\u2051\\u2053\\u2055-\\u205e\\u2cf9-\\u2cfc\\u2cfe\\u2cff\\u2d70\\u2e00\\u2e01\\u2e06-\\u2e08\\u2e0b\\u2e0e-\\u2e16\\u2e18\\u2e19\\u2e1b\\u2e1e\\u2e1f\\u2e2a-\\u2e2e\\u2e30-\\u2e39\\u3001-\\u3003\\u303d\\u30fb\\ua4fe\\ua4ff\\ua60d-\\ua60f\\ua673\\ua67e\\ua6f2-\\ua6f7\\ua874-\\ua877\\ua8ce\\ua8cf\\ua8f8-\\ua8fa\\ua92e\\ua92f\\ua95f\\ua9c1-\\ua9cd\\ua9de\\ua9df\\uaa5c-\\uaa5f\\uaade\\uaadf\\uaaf0\\uaaf1\\uabeb\\ufe10-\\ufe16\\ufe19\\ufe30\\ufe45\\ufe46\\ufe49-\\ufe4c\\ufe50-\\ufe52\\ufe54-\\ufe57\\ufe5f-\\ufe61\\ufe68\\ufe6a\\ufe6b\\uff01-\\uff03\\uff05-\\uff07\\uff0a\\uff0c\\uff0e\\uff0f\\uff1a\\uff1b\\uff1f\\uff20\\uff3c\\uff61\\uff64\\uff65]+/g,'')\n .toLowerCase()\n );\n};\n","const simplify = require('./simplify.js');\n\n// toParts - split a name-suggestion-index key into parts\n// {\n// kvnd: \"amenity/fast_food|Thaï Express~(North America)\",\n// kvn: \"amenity/fast_food|Thaï Express\",\n// kv: \"amenity/fast_food\",\n// k: \"amenity\",\n// v: \"fast_food\",\n// n: \"Thaï Express\",\n// d: \"(North America)\",\n// nsimple: \"thaiexpress\",\n// kvnnsimple: \"amenity/fast_food|thaiexpress\"\n// }\nmodule.exports = (kvnd) => {\n const parts = {};\n parts.kvnd = kvnd;\n\n const kvndparts = kvnd.split('~', 2);\n if (kvndparts.length > 1) parts.d = kvndparts[1];\n\n parts.kvn = kvndparts[0];\n const kvnparts = parts.kvn.split('|', 2);\n if (kvnparts.length > 1) parts.n = kvnparts[1];\n\n parts.kv = kvnparts[0];\n const kvparts = parts.kv.split('/', 2);\n parts.k = kvparts[0];\n parts.v = kvparts[1];\n\n parts.nsimple = simplify(parts.n);\n parts.kvnsimple = parts.kv + '|' + parts.nsimple;\n return parts;\n};\n","const simplify = require('./simplify.js');\nconst toParts = require('./to_parts.js');\n\nconst matchGroups = require('../config/match_groups.json').matchGroups;\n\n\nmodule.exports = () => {\n let _warnings = []; // array of match conflict pairs\n let _ambiguous = {};\n let _matchIndex = {};\n let matcher = {};\n\n\n // Create an index of all the keys/simplenames for fast matching\n matcher.buildMatchIndex = (brands) => {\n // two passes - once for primary names, once for secondary/alternate names\n Object.keys(brands).forEach(kvnd => insertNames(kvnd, 'primary'));\n Object.keys(brands).forEach(kvnd => insertNames(kvnd, 'secondary'));\n\n\n function insertNames(kvnd, which) {\n const obj = brands[kvnd];\n const parts = toParts(kvnd);\n\n // Exit early for ambiguous names in the second pass.\n // They were collected in the first pass and we don't gather alt names for them.\n if (which === 'secondary' && parts.d) return;\n\n\n if (obj.countryCodes) {\n parts.countryCodes = obj.countryCodes.slice(); // copy\n }\n\n const nomatches = (obj.nomatch || []);\n if (nomatches.some(s => s === kvnd)) {\n console.log(`WARNING match/nomatch conflict for ${kvnd}`);\n return;\n }\n\n const match_kv = [parts.kv]\n .concat(obj.matchTags || [])\n .concat([`${parts.k}/yes`, `building/yes`]) // #3454 - match some generic tags\n .map(s => s.toLowerCase());\n\n let match_nsimple = [];\n if (which === 'primary') {\n match_nsimple = [parts.n]\n .concat(obj.matchNames || [])\n .concat(obj.tags.official_name || []) // #2732 - match alternate names\n .map(simplify);\n\n } else if (which === 'secondary') {\n match_nsimple = []\n .concat(obj.tags.alt_name || []) // #2732 - match alternate names\n .concat(obj.tags.short_name || []) // #2732 - match alternate names\n .map(simplify);\n }\n\n if (!match_nsimple.length) return; // nothing to do\n\n match_kv.forEach(kv => {\n match_nsimple.forEach(nsimple => {\n if (parts.d) {\n // Known ambiguous names with disambiguation string ~(USA) / ~(Canada)\n // FIXME: Name collisions will overwrite the initial entry (ok for now)\n if (!_ambiguous[kv]) _ambiguous[kv] = {};\n _ambiguous[kv][nsimple] = parts;\n\n } else {\n // Names we mostly expect to be unique..\n if (!_matchIndex[kv]) _matchIndex[kv] = {};\n\n const m = _matchIndex[kv][nsimple];\n if (m) { // There already is a match for this name, skip it\n // Warn if we detect collisions in a primary name.\n // Skip warning if a secondary name or a generic `*=yes` tag - #2972 / #3454\n if (which === 'primary' && !/\\/yes$/.test(kv)) {\n _warnings.push([m.kvnd, `${kvnd} (${kv}/${nsimple})`]);\n }\n } else {\n _matchIndex[kv][nsimple] = parts; // insert\n }\n }\n });\n });\n\n }\n };\n\n\n // pass a `key`, `value`, `name` and return the best match,\n // `countryCode` optional (if supplied, must match that too)\n matcher.matchKVN = (key, value, name, countryCode) => {\n return matcher.matchParts(toParts(`${key}/${value}|${name}`), countryCode);\n };\n\n\n // pass a parts object and return the best match,\n // `countryCode` optional (if supplied, must match that too)\n matcher.matchParts = (parts, countryCode) => {\n let match = null;\n let inGroup = false;\n\n // fixme: we currently return a single match for ambiguous\n match = _ambiguous[parts.kv] && _ambiguous[parts.kv][parts.nsimple];\n if (match && matchesCountryCode(match)) return match;\n\n // try to return an exact match\n match = _matchIndex[parts.kv] && _matchIndex[parts.kv][parts.nsimple];\n if (match && matchesCountryCode(match)) return match;\n\n // look in match groups\n for (let mg in matchGroups) {\n const matchGroup = matchGroups[mg];\n match = null;\n inGroup = false;\n\n for (let i = 0; i < matchGroup.length; i++) {\n const otherkv = matchGroup[i].toLowerCase();\n if (!inGroup) {\n inGroup = otherkv === parts.kv;\n }\n if (!match) {\n // fixme: we currently return a single match for ambiguous\n match = _ambiguous[otherkv] && _ambiguous[otherkv][parts.nsimple];\n }\n if (!match) {\n match = _matchIndex[otherkv] && _matchIndex[otherkv][parts.nsimple];\n }\n\n if (match && !matchesCountryCode(match)) {\n match = null;\n }\n\n if (inGroup && match) {\n return match;\n }\n }\n }\n\n return null;\n\n function matchesCountryCode(match) {\n if (!countryCode) return true;\n if (!match.countryCodes) return true;\n return match.countryCodes.indexOf(countryCode) !== -1;\n }\n };\n\n\n matcher.getWarnings = () => _warnings;\n\n return matcher;\n};","(function (global, factory) {\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :\n\ttypeof define === 'function' && define.amd ? define(factory) :\n\t(global.quickselect = factory());\n}(this, (function () { 'use strict';\n\nfunction quickselect(arr, k, left, right, compare) {\n quickselectStep(arr, k, left || 0, right || (arr.length - 1), compare || defaultCompare);\n}\n\nfunction quickselectStep(arr, k, left, right, compare) {\n\n while (right > left) {\n if (right - left > 600) {\n var n = right - left + 1;\n var m = k - left + 1;\n var z = Math.log(n);\n var s = 0.5 * Math.exp(2 * z / 3);\n var sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);\n var newLeft = Math.max(left, Math.floor(k - m * s / n + sd));\n var newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));\n quickselectStep(arr, k, newLeft, newRight, compare);\n }\n\n var t = arr[k];\n var i = left;\n var j = right;\n\n swap(arr, left, k);\n if (compare(arr[right], t) > 0) swap(arr, left, right);\n\n while (i < j) {\n swap(arr, i, j);\n i++;\n j--;\n while (compare(arr[i], t) < 0) i++;\n while (compare(arr[j], t) > 0) j--;\n }\n\n if (compare(arr[left], t) === 0) swap(arr, left, j);\n else {\n j++;\n swap(arr, j, right);\n }\n\n if (j <= k) left = j + 1;\n if (k <= j) right = j - 1;\n }\n}\n\nfunction swap(arr, i, j) {\n var tmp = arr[i];\n arr[i] = arr[j];\n arr[j] = tmp;\n}\n\nfunction defaultCompare(a, b) {\n return a < b ? -1 : a > b ? 1 : 0;\n}\n\nreturn quickselect;\n\n})));\n","'use strict';\n\nmodule.exports = rbush;\nmodule.exports.default = rbush;\n\nvar quickselect = require('quickselect');\n\nfunction rbush(maxEntries, format) {\n if (!(this instanceof rbush)) return new rbush(maxEntries, format);\n\n // max entries in a node is 9 by default; min node fill is 40% for best performance\n this._maxEntries = Math.max(4, maxEntries || 9);\n this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4));\n\n if (format) {\n this._initFormat(format);\n }\n\n this.clear();\n}\n\nrbush.prototype = {\n\n all: function () {\n return this._all(this.data, []);\n },\n\n search: function (bbox) {\n\n var node = this.data,\n result = [],\n toBBox = this.toBBox;\n\n if (!intersects(bbox, node)) return result;\n\n var nodesToSearch = [],\n i, len, child, childBBox;\n\n while (node) {\n for (i = 0, len = node.children.length; i < len; i++) {\n\n child = node.children[i];\n childBBox = node.leaf ? toBBox(child) : child;\n\n if (intersects(bbox, childBBox)) {\n if (node.leaf) result.push(child);\n else if (contains(bbox, childBBox)) this._all(child, result);\n else nodesToSearch.push(child);\n }\n }\n node = nodesToSearch.pop();\n }\n\n return result;\n },\n\n collides: function (bbox) {\n\n var node = this.data,\n toBBox = this.toBBox;\n\n if (!intersects(bbox, node)) return false;\n\n var nodesToSearch = [],\n i, len, child, childBBox;\n\n while (node) {\n for (i = 0, len = node.children.length; i < len; i++) {\n\n child = node.children[i];\n childBBox = node.leaf ? toBBox(child) : child;\n\n if (intersects(bbox, childBBox)) {\n if (node.leaf || contains(bbox, childBBox)) return true;\n nodesToSearch.push(child);\n }\n }\n node = nodesToSearch.pop();\n }\n\n return false;\n },\n\n load: function (data) {\n if (!(data && data.length)) return this;\n\n if (data.length < this._minEntries) {\n for (var i = 0, len = data.length; i < len; i++) {\n this.insert(data[i]);\n }\n return this;\n }\n\n // recursively build the tree with the given data from scratch using OMT algorithm\n var node = this._build(data.slice(), 0, data.length - 1, 0);\n\n if (!this.data.children.length) {\n // save as is if tree is empty\n this.data = node;\n\n } else if (this.data.height === node.height) {\n // split root if trees have the same height\n this._splitRoot(this.data, node);\n\n } else {\n if (this.data.height < node.height) {\n // swap trees if inserted one is bigger\n var tmpNode = this.data;\n this.data = node;\n node = tmpNode;\n }\n\n // insert the small tree into the large tree at appropriate level\n this._insert(node, this.data.height - node.height - 1, true);\n }\n\n return this;\n },\n\n insert: function (item) {\n if (item) this._insert(item, this.data.height - 1);\n return this;\n },\n\n clear: function () {\n this.data = createNode([]);\n return this;\n },\n\n remove: function (item, equalsFn) {\n if (!item) return this;\n\n var node = this.data,\n bbox = this.toBBox(item),\n path = [],\n indexes = [],\n i, parent, index, goingUp;\n\n // depth-first iterative tree traversal\n while (node || path.length) {\n\n if (!node) { // go up\n node = path.pop();\n parent = path[path.length - 1];\n i = indexes.pop();\n goingUp = true;\n }\n\n if (node.leaf) { // check current node\n index = findItem(item, node.children, equalsFn);\n\n if (index !== -1) {\n // item found, remove the item and condense tree upwards\n node.children.splice(index, 1);\n path.push(node);\n this._condense(path);\n return this;\n }\n }\n\n if (!goingUp && !node.leaf && contains(node, bbox)) { // go down\n path.push(node);\n indexes.push(i);\n i = 0;\n parent = node;\n node = node.children[0];\n\n } else if (parent) { // go right\n i++;\n node = parent.children[i];\n goingUp = false;\n\n } else node = null; // nothing found\n }\n\n return this;\n },\n\n toBBox: function (item) { return item; },\n\n compareMinX: compareNodeMinX,\n compareMinY: compareNodeMinY,\n\n toJSON: function () { return this.data; },\n\n fromJSON: function (data) {\n this.data = data;\n return this;\n },\n\n _all: function (node, result) {\n var nodesToSearch = [];\n while (node) {\n if (node.leaf) result.push.apply(result, node.children);\n else nodesToSearch.push.apply(nodesToSearch, node.children);\n\n node = nodesToSearch.pop();\n }\n return result;\n },\n\n _build: function (items, left, right, height) {\n\n var N = right - left + 1,\n M = this._maxEntries,\n node;\n\n if (N <= M) {\n // reached leaf level; return leaf\n node = createNode(items.slice(left, right + 1));\n calcBBox(node, this.toBBox);\n return node;\n }\n\n if (!height) {\n // target height of the bulk-loaded tree\n height = Math.ceil(Math.log(N) / Math.log(M));\n\n // target number of root entries to maximize storage utilization\n M = Math.ceil(N / Math.pow(M, height - 1));\n }\n\n node = createNode([]);\n node.leaf = false;\n node.height = height;\n\n // split the items into M mostly square tiles\n\n var N2 = Math.ceil(N / M),\n N1 = N2 * Math.ceil(Math.sqrt(M)),\n i, j, right2, right3;\n\n multiSelect(items, left, right, N1, this.compareMinX);\n\n for (i = left; i <= right; i += N1) {\n\n right2 = Math.min(i + N1 - 1, right);\n\n multiSelect(items, i, right2, N2, this.compareMinY);\n\n for (j = i; j <= right2; j += N2) {\n\n right3 = Math.min(j + N2 - 1, right2);\n\n // pack each entry recursively\n node.children.push(this._build(items, j, right3, height - 1));\n }\n }\n\n calcBBox(node, this.toBBox);\n\n return node;\n },\n\n _chooseSubtree: function (bbox, node, level, path) {\n\n var i, len, child, targetNode, area, enlargement, minArea, minEnlargement;\n\n while (true) {\n path.push(node);\n\n if (node.leaf || path.length - 1 === level) break;\n\n minArea = minEnlargement = Infinity;\n\n for (i = 0, len = node.children.length; i < len; i++) {\n child = node.children[i];\n area = bboxArea(child);\n enlargement = enlargedArea(bbox, child) - area;\n\n // choose entry with the least area enlargement\n if (enlargement < minEnlargement) {\n minEnlargement = enlargement;\n minArea = area < minArea ? area : minArea;\n targetNode = child;\n\n } else if (enlargement === minEnlargement) {\n // otherwise choose one with the smallest area\n if (area < minArea) {\n minArea = area;\n targetNode = child;\n }\n }\n }\n\n node = targetNode || node.children[0];\n }\n\n return node;\n },\n\n _insert: function (item, level, isNode) {\n\n var toBBox = this.toBBox,\n bbox = isNode ? item : toBBox(item),\n insertPath = [];\n\n // find the best node for accommodating the item, saving all nodes along the path too\n var node = this._chooseSubtree(bbox, this.data, level, insertPath);\n\n // put the item into the node\n node.children.push(item);\n extend(node, bbox);\n\n // split on node overflow; propagate upwards if necessary\n while (level >= 0) {\n if (insertPath[level].children.length > this._maxEntries) {\n this._split(insertPath, level);\n level--;\n } else break;\n }\n\n // adjust bboxes along the insertion path\n this._adjustParentBBoxes(bbox, insertPath, level);\n },\n\n // split overflowed node into two\n _split: function (insertPath, level) {\n\n var node = insertPath[level],\n M = node.children.length,\n m = this._minEntries;\n\n this._chooseSplitAxis(node, m, M);\n\n var splitIndex = this._chooseSplitIndex(node, m, M);\n\n var newNode = createNode(node.children.splice(splitIndex, node.children.length - splitIndex));\n newNode.height = node.height;\n newNode.leaf = node.leaf;\n\n calcBBox(node, this.toBBox);\n calcBBox(newNode, this.toBBox);\n\n if (level) insertPath[level - 1].children.push(newNode);\n else this._splitRoot(node, newNode);\n },\n\n _splitRoot: function (node, newNode) {\n // split root node\n this.data = createNode([node, newNode]);\n this.data.height = node.height + 1;\n this.data.leaf = false;\n calcBBox(this.data, this.toBBox);\n },\n\n _chooseSplitIndex: function (node, m, M) {\n\n var i, bbox1, bbox2, overlap, area, minOverlap, minArea, index;\n\n minOverlap = minArea = Infinity;\n\n for (i = m; i <= M - m; i++) {\n bbox1 = distBBox(node, 0, i, this.toBBox);\n bbox2 = distBBox(node, i, M, this.toBBox);\n\n overlap = intersectionArea(bbox1, bbox2);\n area = bboxArea(bbox1) + bboxArea(bbox2);\n\n // choose distribution with minimum overlap\n if (overlap < minOverlap) {\n minOverlap = overlap;\n index = i;\n\n minArea = area < minArea ? area : minArea;\n\n } else if (overlap === minOverlap) {\n // otherwise choose distribution with minimum area\n if (area < minArea) {\n minArea = area;\n index = i;\n }\n }\n }\n\n return index;\n },\n\n // sorts node children by the best axis for split\n _chooseSplitAxis: function (node, m, M) {\n\n var compareMinX = node.leaf ? this.compareMinX : compareNodeMinX,\n compareMinY = node.leaf ? this.compareMinY : compareNodeMinY,\n xMargin = this._allDistMargin(node, m, M, compareMinX),\n yMargin = this._allDistMargin(node, m, M, compareMinY);\n\n // if total distributions margin value is minimal for x, sort by minX,\n // otherwise it's already sorted by minY\n if (xMargin < yMargin) node.children.sort(compareMinX);\n },\n\n // total margin of all possible split distributions where each node is at least m full\n _allDistMargin: function (node, m, M, compare) {\n\n node.children.sort(compare);\n\n var toBBox = this.toBBox,\n leftBBox = distBBox(node, 0, m, toBBox),\n rightBBox = distBBox(node, M - m, M, toBBox),\n margin = bboxMargin(leftBBox) + bboxMargin(rightBBox),\n i, child;\n\n for (i = m; i < M - m; i++) {\n child = node.children[i];\n extend(leftBBox, node.leaf ? toBBox(child) : child);\n margin += bboxMargin(leftBBox);\n }\n\n for (i = M - m - 1; i >= m; i--) {\n child = node.children[i];\n extend(rightBBox, node.leaf ? toBBox(child) : child);\n margin += bboxMargin(rightBBox);\n }\n\n return margin;\n },\n\n _adjustParentBBoxes: function (bbox, path, level) {\n // adjust bboxes along the given tree path\n for (var i = level; i >= 0; i--) {\n extend(path[i], bbox);\n }\n },\n\n _condense: function (path) {\n // go through the path, removing empty nodes and updating bboxes\n for (var i = path.length - 1, siblings; i >= 0; i--) {\n if (path[i].children.length === 0) {\n if (i > 0) {\n siblings = path[i - 1].children;\n siblings.splice(siblings.indexOf(path[i]), 1);\n\n } else this.clear();\n\n } else calcBBox(path[i], this.toBBox);\n }\n },\n\n _initFormat: function (format) {\n // data format (minX, minY, maxX, maxY accessors)\n\n // uses eval-type function compilation instead of just accepting a toBBox function\n // because the algorithms are very sensitive to sorting functions performance,\n // so they should be dead simple and without inner calls\n\n var compareArr = ['return a', ' - b', ';'];\n\n this.compareMinX = new Function('a', 'b', compareArr.join(format[0]));\n this.compareMinY = new Function('a', 'b', compareArr.join(format[1]));\n\n this.toBBox = new Function('a',\n 'return {minX: a' + format[0] +\n ', minY: a' + format[1] +\n ', maxX: a' + format[2] +\n ', maxY: a' + format[3] + '};');\n }\n};\n\nfunction findItem(item, items, equalsFn) {\n if (!equalsFn) return items.indexOf(item);\n\n for (var i = 0; i < items.length; i++) {\n if (equalsFn(item, items[i])) return i;\n }\n return -1;\n}\n\n// calculate node's bbox from bboxes of its children\nfunction calcBBox(node, toBBox) {\n distBBox(node, 0, node.children.length, toBBox, node);\n}\n\n// min bounding rectangle of node children from k to p-1\nfunction distBBox(node, k, p, toBBox, destNode) {\n if (!destNode) destNode = createNode(null);\n destNode.minX = Infinity;\n destNode.minY = Infinity;\n destNode.maxX = -Infinity;\n destNode.maxY = -Infinity;\n\n for (var i = k, child; i < p; i++) {\n child = node.children[i];\n extend(destNode, node.leaf ? toBBox(child) : child);\n }\n\n return destNode;\n}\n\nfunction extend(a, b) {\n a.minX = Math.min(a.minX, b.minX);\n a.minY = Math.min(a.minY, b.minY);\n a.maxX = Math.max(a.maxX, b.maxX);\n a.maxY = Math.max(a.maxY, b.maxY);\n return a;\n}\n\nfunction compareNodeMinX(a, b) { return a.minX - b.minX; }\nfunction compareNodeMinY(a, b) { return a.minY - b.minY; }\n\nfunction bboxArea(a) { return (a.maxX - a.minX) * (a.maxY - a.minY); }\nfunction bboxMargin(a) { return (a.maxX - a.minX) + (a.maxY - a.minY); }\n\nfunction enlargedArea(a, b) {\n return (Math.max(b.maxX, a.maxX) - Math.min(b.minX, a.minX)) *\n (Math.max(b.maxY, a.maxY) - Math.min(b.minY, a.minY));\n}\n\nfunction intersectionArea(a, b) {\n var minX = Math.max(a.minX, b.minX),\n minY = Math.max(a.minY, b.minY),\n maxX = Math.min(a.maxX, b.maxX),\n maxY = Math.min(a.maxY, b.maxY);\n\n return Math.max(0, maxX - minX) *\n Math.max(0, maxY - minY);\n}\n\nfunction contains(a, b) {\n return a.minX <= b.minX &&\n a.minY <= b.minY &&\n b.maxX <= a.maxX &&\n b.maxY <= a.maxY;\n}\n\nfunction intersects(a, b) {\n return b.minX <= a.maxX &&\n b.minY <= a.maxY &&\n b.maxX >= a.minX &&\n b.maxY >= a.minY;\n}\n\nfunction createNode(children) {\n return {\n children: children,\n height: 1,\n leaf: true,\n minX: Infinity,\n minY: Infinity,\n maxX: -Infinity,\n maxY: -Infinity\n };\n}\n\n// sort an array so that items come in groups of n unsorted items, with groups sorted between each other;\n// combines selection algorithm with binary divide & conquer approach\n\nfunction multiSelect(arr, left, right, n, compare) {\n var stack = [left, right],\n mid;\n\n while (stack.length) {\n right = stack.pop();\n left = stack.pop();\n\n if (right - left <= n) continue;\n\n mid = left + Math.ceil((right - left) / n / 2) * n;\n quickselect(arr, mid, left, right, compare);\n\n stack.push(left, mid, mid, right);\n }\n}\n","'use strict';\n\nmodule.exports = lineclip;\n\nlineclip.polyline = lineclip;\nlineclip.polygon = polygonclip;\n\n\n// Cohen-Sutherland line clippign algorithm, adapted to efficiently\n// handle polylines rather than just segments\n\nfunction lineclip(points, bbox, result) {\n\n var len = points.length,\n codeA = bitCode(points[0], bbox),\n part = [],\n i, a, b, codeB, lastCode;\n\n if (!result) result = [];\n\n for (i = 1; i < len; i++) {\n a = points[i - 1];\n b = points[i];\n codeB = lastCode = bitCode(b, bbox);\n\n while (true) {\n\n if (!(codeA | codeB)) { // accept\n part.push(a);\n\n if (codeB !== lastCode) { // segment went outside\n part.push(b);\n\n if (i < len - 1) { // start a new line\n result.push(part);\n part = [];\n }\n } else if (i === len - 1) {\n part.push(b);\n }\n break;\n\n } else if (codeA & codeB) { // trivial reject\n break;\n\n } else if (codeA) { // a outside, intersect with clip edge\n a = intersect(a, b, codeA, bbox);\n codeA = bitCode(a, bbox);\n\n } else { // b outside\n b = intersect(a, b, codeB, bbox);\n codeB = bitCode(b, bbox);\n }\n }\n\n codeA = lastCode;\n }\n\n if (part.length) result.push(part);\n\n return result;\n}\n\n// Sutherland-Hodgeman polygon clipping algorithm\n\nfunction polygonclip(points, bbox) {\n\n var result, edge, prev, prevInside, i, p, inside;\n\n // clip against each side of the clip rectangle\n for (edge = 1; edge <= 8; edge *= 2) {\n result = [];\n prev = points[points.length - 1];\n prevInside = !(bitCode(prev, bbox) & edge);\n\n for (i = 0; i < points.length; i++) {\n p = points[i];\n inside = !(bitCode(p, bbox) & edge);\n\n // if segment goes through the clip window, add an intersection\n if (inside !== prevInside) result.push(intersect(prev, p, edge, bbox));\n\n if (inside) result.push(p); // add a point if it's inside\n\n prev = p;\n prevInside = inside;\n }\n\n points = result;\n\n if (!points.length) break;\n }\n\n return result;\n}\n\n// intersect a segment against one of the 4 lines that make up the bbox\n\nfunction intersect(a, b, edge, bbox) {\n return edge & 8 ? [a[0] + (b[0] - a[0]) * (bbox[3] - a[1]) / (b[1] - a[1]), bbox[3]] : // top\n edge & 4 ? [a[0] + (b[0] - a[0]) * (bbox[1] - a[1]) / (b[1] - a[1]), bbox[1]] : // bottom\n edge & 2 ? [bbox[2], a[1] + (b[1] - a[1]) * (bbox[2] - a[0]) / (b[0] - a[0])] : // right\n edge & 1 ? [bbox[0], a[1] + (b[1] - a[1]) * (bbox[0] - a[0]) / (b[0] - a[0])] : // left\n null;\n}\n\n// bit code reflects the point position relative to the bbox:\n\n// left mid right\n// top 1001 1000 1010\n// mid 0001 0000 0010\n// bottom 0101 0100 0110\n\nfunction bitCode(p, bbox) {\n var code = 0;\n\n if (p[0] < bbox[0]) code |= 1; // left\n else if (p[0] > bbox[2]) code |= 2; // right\n\n if (p[1] < bbox[1]) code |= 4; // bottom\n else if (p[1] > bbox[3]) code |= 8; // top\n\n return code;\n}\n","'use strict';\n\nvar rbush = require('rbush');\nvar lineclip = require('lineclip');\n\nmodule.exports = whichPolygon;\n\nfunction whichPolygon(data) {\n var bboxes = [];\n for (var i = 0; i < data.features.length; i++) {\n var feature = data.features[i];\n var coords = feature.geometry.coordinates;\n\n if (feature.geometry.type === 'Polygon') {\n bboxes.push(treeItem(coords, feature.properties));\n\n } else if (feature.geometry.type === 'MultiPolygon') {\n for (var j = 0; j < coords.length; j++) {\n bboxes.push(treeItem(coords[j], feature.properties));\n }\n }\n }\n\n var tree = rbush().load(bboxes);\n\n function query(p, multi) {\n var output = [],\n result = tree.search({\n minX: p[0],\n minY: p[1],\n maxX: p[0],\n maxY: p[1]\n });\n for (var i = 0; i < result.length; i++) {\n if (insidePolygon(result[i].coords, p)) {\n if (multi)\n output.push(result[i].props);\n else\n return result[i].props;\n }\n }\n return multi && output.length ? output : null;\n }\n\n query.tree = tree;\n query.bbox = function queryBBox(bbox) {\n var output = [];\n var result = tree.search({\n minX: bbox[0],\n minY: bbox[1],\n maxX: bbox[2],\n maxY: bbox[3]\n });\n for (var i = 0; i < result.length; i++) {\n if (polygonIntersectsBBox(result[i].coords, bbox)) {\n output.push(result[i].props);\n }\n }\n return output;\n };\n\n return query;\n}\n\nfunction polygonIntersectsBBox(polygon, bbox) {\n var bboxCenter = [\n (bbox[0] + bbox[2]) / 2,\n (bbox[1] + bbox[3]) / 2\n ];\n if (insidePolygon(polygon, bboxCenter)) return true;\n for (var i = 0; i < polygon.length; i++) {\n if (lineclip(polygon[i], bbox).length > 0) return true;\n }\n return false;\n}\n\n// ray casting algorithm for detecting if point is in polygon\nfunction insidePolygon(rings, p) {\n var inside = false;\n for (var i = 0, len = rings.length; i < len; i++) {\n var ring = rings[i];\n for (var j = 0, len2 = ring.length, k = len2 - 1; j < len2; k = j++) {\n if (rayIntersect(p, ring[j], ring[k])) inside = !inside;\n }\n }\n return inside;\n}\n\nfunction rayIntersect(p, p1, p2) {\n return ((p1[1] > p[1]) !== (p2[1] > p[1])) && (p[0] < (p2[0] - p1[0]) * (p[1] - p1[1]) / (p2[1] - p1[1]) + p1[0]);\n}\n\nfunction treeItem(coords, props) {\n var item = {\n minX: Infinity,\n minY: Infinity,\n maxX: -Infinity,\n maxY: -Infinity,\n coords: coords,\n props: props\n };\n\n for (var i = 0; i < coords[0].length; i++) {\n var p = coords[0][i];\n item.minX = Math.min(item.minX, p[0]);\n item.minY = Math.min(item.minY, p[1]);\n item.maxX = Math.max(item.maxX, p[0]);\n item.maxY = Math.max(item.maxY, p[1]);\n }\n return item;\n}\n","import whichPolygon from 'which-polygon';\nimport rawBorders from './data/borders.json';\nexport let borders = rawBorders;\nlet whichPolygonGetter = {};\nlet featuresByCode = {};\nlet idFilterRegex = /\\bThe\\b|\\bthe\\b|\\band\\b|\\bof\\b|[-_ .,()&[\\]/]/g;\nlet levels = [\n 'subterritory',\n 'territory',\n 'country',\n 'intermediateRegion',\n 'subregion',\n 'region',\n 'union',\n 'world'\n];\nloadDerivedDataAndCaches(borders);\nfunction loadDerivedDataAndCaches(borders) {\n let identifierProps = ['iso1A2', 'iso1A3', 'm49', 'wikidata', 'emojiFlag', 'nameEn'];\n let geometryFeatures = [];\n for (let i in borders.features) {\n let feature = borders.features[i];\n feature.properties.id = feature.properties.iso1A2 || feature.properties.m49;\n loadM49(feature);\n loadIsoStatus(feature);\n loadLevel(feature);\n loadGroups(feature);\n loadRoadSpeedUnit(feature);\n loadDriveSide(feature);\n loadFlag(feature);\n cacheFeatureByIDs(feature);\n if (feature.geometry) geometryFeatures.push(feature);\n }\n for (let i in borders.features) {\n let feature = borders.features[i];\n feature.properties.groups.sort(function(groupID1, groupID2) {\n return (\n levels.indexOf(featuresByCode[groupID1].properties.level) -\n levels.indexOf(featuresByCode[groupID2].properties.level)\n );\n });\n loadMembersForGroupsOf(feature);\n }\n let geometryOnlyCollection = {\n type: 'RegionFeatureCollection',\n features: geometryFeatures\n };\n whichPolygonGetter = whichPolygon(geometryOnlyCollection);\n function loadGroups(feature) {\n let props = feature.properties;\n if (!props.groups) {\n props.groups = [];\n }\n if (props.country) {\n props.groups.push(props.country);\n }\n if (props.m49 !== '001') {\n props.groups.push('001');\n }\n }\n function loadM49(feature) {\n let props = feature.properties;\n if (!props.m49 && props.iso1N3) {\n props.m49 = props.iso1N3;\n }\n }\n function loadIsoStatus(feature) {\n let props = feature.properties;\n if (!props.isoStatus && props.iso1A2) {\n props.isoStatus = 'official';\n }\n }\n function loadLevel(feature) {\n let props = feature.properties;\n if (props.level) return;\n if (!props.country) {\n props.level = 'country';\n } else if (props.isoStatus === 'official') {\n props.level = 'territory';\n } else {\n props.level = 'subterritory';\n }\n }\n function loadRoadSpeedUnit(feature) {\n let props = feature.properties;\n if (props.roadSpeedUnit === undefined && props.iso1A2 && props.iso1A2 !== 'EU') {\n props.roadSpeedUnit = 'km/h';\n }\n }\n function loadDriveSide(feature) {\n let props = feature.properties;\n if (props.driveSide === undefined && props.iso1A2 && props.iso1A2 !== 'EU') {\n props.driveSide = 'right';\n }\n }\n function loadFlag(feature) {\n if (!feature.properties.iso1A2) return;\n let flag = feature.properties.iso1A2.replace(/./g, function(char) {\n return String.fromCodePoint(char.charCodeAt(0) + 127397);\n });\n feature.properties.emojiFlag = flag;\n }\n function loadMembersForGroupsOf(feature) {\n let featureID = feature.properties.id;\n let standardizedGroupIDs = [];\n for (let j in feature.properties.groups) {\n let groupID = feature.properties.groups[j];\n let groupFeature = featuresByCode[groupID];\n standardizedGroupIDs.push(groupFeature.properties.id);\n if (groupFeature.properties.members) {\n groupFeature.properties.members.push(featureID);\n } else {\n groupFeature.properties.members = [featureID];\n }\n }\n feature.properties.groups = standardizedGroupIDs;\n }\n function cacheFeatureByIDs(feature) {\n for (let k in identifierProps) {\n let prop = identifierProps[k];\n let id = prop && feature.properties[prop];\n if (id) {\n id = id.replace(idFilterRegex, '').toUpperCase();\n featuresByCode[id] = feature;\n }\n }\n if (feature.properties.aliases) {\n for (let j in feature.properties.aliases) {\n let alias = feature.properties.aliases[j].replace(idFilterRegex, '').toUpperCase();\n featuresByCode[alias] = feature;\n }\n }\n }\n}\nfunction locArray(loc) {\n if (Array.isArray(loc)) {\n return loc;\n } else if (loc.coordinates) {\n return loc.coordinates;\n }\n return loc.geometry.coordinates;\n}\nfunction smallestFeature(loc) {\n let query = locArray(loc);\n let featureProperties = whichPolygonGetter(query);\n if (!featureProperties) return null;\n return featuresByCode[featureProperties.id];\n}\nfunction countryFeature(loc) {\n let feature = smallestFeature(loc);\n if (!feature) return null;\n let countryCode = feature.properties.country || feature.properties.iso1A2;\n return featuresByCode[countryCode];\n}\nfunction featureForLoc(loc, opts) {\n if (opts && opts.level && opts.level !== 'country') {\n let features = featuresContaining(loc);\n let targetLevel = opts.level;\n let targetLevelIndex = levels.indexOf(targetLevel);\n if (targetLevelIndex === -1) return null;\n for (let i in features) {\n let feature = features[i];\n if (\n feature.properties.level === targetLevel ||\n levels.indexOf(feature.properties.level) > targetLevelIndex\n ) {\n return feature;\n }\n }\n return null;\n }\n return countryFeature(loc);\n}\nfunction featureForID(id) {\n let stringID;\n if (typeof id === 'number') {\n stringID = id.toString();\n if (stringID.length === 1) {\n stringID = '00' + stringID;\n } else if (stringID.length === 2) {\n stringID = '0' + stringID;\n }\n } else {\n stringID = id.replace(idFilterRegex, '').toUpperCase();\n }\n return featuresByCode[stringID] || null;\n}\nfunction smallestOrMatchingFeature(query) {\n if (typeof query === 'object') {\n return smallestFeature(query);\n }\n return featureForID(query);\n}\nexport function feature(query, opts) {\n if (typeof query === 'object') {\n return featureForLoc(query, opts);\n }\n return featureForID(query);\n}\nexport function iso1A2Code(query, opts) {\n let match = feature(query, opts);\n if (!match) return null;\n return match.properties.iso1A2 || null;\n}\nexport function iso1A3Code(query, opts) {\n let match = feature(query, opts);\n if (!match) return null;\n return match.properties.iso1A3 || null;\n}\nexport function iso1N3Code(query, opts) {\n let match = feature(query, opts);\n if (!match) return null;\n return match.properties.iso1N3 || null;\n}\nexport function m49Code(query, opts) {\n let match = feature(query, opts);\n if (!match) return null;\n return match.properties.m49 || null;\n}\nexport function wikidataQID(query, opts) {\n let match = feature(query, opts);\n if (!match) return null;\n return match.properties.wikidata;\n}\nexport function emojiFlag(query, opts) {\n let match = feature(query, opts);\n if (!match) return null;\n return match.properties.emojiFlag || null;\n}\nexport function featuresContaining(query, strict) {\n let feature = smallestOrMatchingFeature(query);\n if (!feature) return [];\n let features = [];\n if (!strict || typeof query === 'object') {\n features.push(feature);\n }\n let properties = feature.properties;\n for (let i in properties.groups) {\n let groupID = properties.groups[i];\n features.push(featuresByCode[groupID]);\n }\n return features;\n}\nexport function featuresIn(id, strict) {\n let feature = featureForID(id);\n if (!feature) return [];\n let features = [];\n if (!strict) {\n features.push(feature);\n }\n let properties = feature.properties;\n if (properties.members) {\n for (let i in properties.members) {\n let memberID = properties.members[i];\n features.push(featuresByCode[memberID]);\n }\n }\n return features;\n}\nexport function aggregateFeature(id) {\n let features = featuresIn(id, false);\n if (features.length === 0) return null;\n let aggregateCoordinates = [];\n for (let i in features) {\n let feature = features[i];\n if (\n feature.geometry &&\n feature.geometry.type === 'MultiPolygon' &&\n feature.geometry.coordinates\n ) {\n aggregateCoordinates = aggregateCoordinates.concat(feature.geometry.coordinates);\n }\n }\n return {\n type: 'Feature',\n properties: features[0].properties,\n geometry: {\n type: 'MultiPolygon',\n coordinates: aggregateCoordinates\n }\n };\n}\nexport function isIn(query, bounds) {\n let queryFeature = smallestOrMatchingFeature(query);\n let boundsFeature = featureForID(bounds);\n if (!queryFeature || !boundsFeature) return false;\n if (queryFeature.properties.id === boundsFeature.properties.id) return true;\n return queryFeature.properties.groups.indexOf(boundsFeature.properties.id) !== -1;\n}\nexport function isInEuropeanUnion(query) {\n return isIn(query, 'EU');\n}\nexport function driveSide(query) {\n let feature = smallestOrMatchingFeature(query);\n return (feature && feature.properties.driveSide) || null;\n}\nexport function roadSpeedUnit(query) {\n let feature = smallestOrMatchingFeature(query);\n return (feature && feature.properties.roadSpeedUnit) || null;\n}\nexport function callingCodes(query) {\n let feature = smallestOrMatchingFeature(query);\n return (feature && feature.properties.callingCodes) || [];\n}\n","import { t } from '../core/localizer';\nimport { matcher } from 'name-suggestion-index';\nimport * as countryCoder from '@ideditor/country-coder';\n\nimport { presetManager } from '../presets';\nimport { fileFetcher } from '../core/file_fetcher';\nimport { actionChangePreset } from '../actions/change_preset';\nimport { actionChangeTags } from '../actions/change_tags';\nimport { actionUpgradeTags } from '../actions/upgrade_tags';\nimport { osmIsOldMultipolygonOuterMember, osmOldMultipolygonOuterMemberOfRelation } from '../osm/multipolygon';\nimport { utilDisplayLabel, utilTagDiff } from '../util';\nimport { validationIssue, validationIssueFix } from '../core/validation';\n\n\nlet _dataDeprecated;\nlet _nsi;\n\nexport function validationOutdatedTags() {\n const type = 'outdated_tags';\n const nsiKeys = ['amenity', 'shop', 'tourism', 'leisure', 'office'];\n\n // A concern here in switching to async data means that `_dataDeprecated`\n // and `_nsi` will not be available at first, so the data on early tiles\n // may not have tags validated fully.\n\n // initialize deprecated tags array\n fileFetcher.get('deprecated')\n .then(d => _dataDeprecated = d)\n .catch(() => { /* ignore */ });\n\n fileFetcher.get('nsi_brands')\n .then(d => {\n _nsi = {\n brands: d.brands,\n matcher: matcher(),\n wikidata: {},\n wikipedia: {}\n };\n\n // initialize name-suggestion-index matcher\n _nsi.matcher.buildMatchIndex(d.brands);\n\n // index all known wikipedia and wikidata tags\n Object.keys(d.brands).forEach(kvnd => {\n const brand = d.brands[kvnd];\n const wd = brand.tags['brand:wikidata'];\n const wp = brand.tags['brand:wikipedia'];\n if (wd) { _nsi.wikidata[wd] = kvnd; }\n if (wp) { _nsi.wikipedia[wp] = kvnd; }\n });\n\n return _nsi;\n })\n .catch(() => { /* ignore */ });\n\n\n function oldTagIssues(entity, graph) {\n const oldTags = Object.assign({}, entity.tags); // shallow copy\n let preset = presetManager.match(entity, graph);\n let subtype = 'deprecated_tags';\n if (!preset) return [];\n\n // upgrade preset..\n if (preset.replacement) {\n const newPreset = presetManager.item(preset.replacement);\n graph = actionChangePreset(entity.id, preset, newPreset, true /* skip field defaults */)(graph);\n entity = graph.entity(entity.id);\n preset = newPreset;\n }\n\n // upgrade tags..\n if (_dataDeprecated) {\n const deprecatedTags = entity.deprecatedTags(_dataDeprecated);\n if (deprecatedTags.length) {\n deprecatedTags.forEach(tag => {\n graph = actionUpgradeTags(entity.id, tag.old, tag.replace)(graph);\n });\n entity = graph.entity(entity.id);\n }\n }\n\n // add missing addTags..\n let newTags = Object.assign({}, entity.tags); // shallow copy\n if (preset.tags !== preset.addTags) {\n Object.keys(preset.addTags).forEach(k => {\n if (!newTags[k]) {\n if (preset.addTags[k] === '*') {\n newTags[k] = 'yes';\n } else {\n newTags[k] = preset.addTags[k];\n }\n }\n });\n }\n\n if (_nsi) {\n // Do `wikidata` or `wikipedia` identify this entity as a brand? #6416\n // If so, these tags can be swapped to `brand:wikidata`/`brand:wikipedia`\n let isBrand;\n if (newTags.wikidata) { // try matching `wikidata`\n isBrand = _nsi.wikidata[newTags.wikidata];\n }\n if (!isBrand && newTags.wikipedia) { // fallback to `wikipedia`\n isBrand = _nsi.wikipedia[newTags.wikipedia];\n }\n if (isBrand && !newTags.office) { // but avoid doing this for corporate offices\n if (newTags.wikidata) {\n newTags['brand:wikidata'] = newTags.wikidata;\n delete newTags.wikidata;\n }\n if (newTags.wikipedia) {\n newTags['brand:wikipedia'] = newTags.wikipedia;\n delete newTags.wikipedia;\n }\n // I considered setting `name` and other tags here, but they aren't unique per wikidata\n // (Q2759586 -> in USA \"Papa John's\", in Russia \"Папа Джонс\")\n // So users will really need to use a preset or assign `name` themselves.\n }\n\n // try key/value|name match against name-suggestion-index\n if (newTags.name) {\n for (let i = 0; i < nsiKeys.length; i++) {\n const k = nsiKeys[i];\n if (!newTags[k]) continue;\n\n const center = entity.extent(graph).center();\n const countryCode = countryCoder.iso1A2Code(center);\n const match = _nsi.matcher.matchKVN(k, newTags[k], newTags.name, countryCode && countryCode.toLowerCase());\n if (!match) continue;\n\n // for now skip ambiguous matches (like Target~(USA) vs Target~(Australia))\n if (match.d) continue;\n\n const brand = _nsi.brands[match.kvnd];\n if (brand && brand.tags['brand:wikidata'] &&\n brand.tags['brand:wikidata'] !== entity.tags['not:brand:wikidata']) {\n subtype = 'noncanonical_brand';\n\n const keepTags = ['takeaway'].reduce((acc, k) => {\n if (newTags[k]) {\n acc[k] = newTags[k];\n }\n return acc;\n }, {});\n\n nsiKeys.forEach(k => delete newTags[k]);\n Object.assign(newTags, brand.tags, keepTags);\n break;\n }\n }\n }\n }\n\n // determine diff\n const tagDiff = utilTagDiff(oldTags, newTags);\n if (!tagDiff.length) return [];\n\n const isOnlyAddingTags = tagDiff.every(d => d.type === '+');\n\n let prefix = '';\n if (subtype === 'noncanonical_brand') {\n prefix = 'noncanonical_brand.';\n } else if (subtype === 'deprecated_tags' && isOnlyAddingTags) {\n subtype = 'incomplete_tags';\n prefix = 'incomplete.';\n }\n\n let autoArgs = [doUpgrade, t('issues.fix.upgrade_tags.annotation')];\n\n return [new validationIssue({\n type: type,\n subtype: subtype,\n severity: 'warning',\n message: showMessage,\n reference: showReference,\n entityIds: [entity.id],\n hash: JSON.stringify(tagDiff),\n autoArgs: autoArgs,\n dynamicFixes: () => {\n return [\n new validationIssueFix({\n// autoArgs: autoArgs,\n title: t('issues.fix.upgrade_tags.title'),\n onClick: (context) => {\n context.perform(doUpgrade, t('issues.fix.upgrade_tags.annotation'));\n }\n })\n ];\n }\n })];\n\n\n function doUpgrade(graph) {\n const currEntity = graph.hasEntity(entity.id);\n if (!currEntity) return graph;\n\n let newTags = Object.assign({}, currEntity.tags); // shallow copy\n tagDiff.forEach(diff => {\n if (diff.type === '-') {\n delete newTags[diff.key];\n } else if (diff.type === '+') {\n newTags[diff.key] = diff.newVal;\n }\n });\n\n return actionChangeTags(currEntity.id, newTags)(graph);\n }\n\n\n function showMessage(context) {\n const currEntity = context.hasEntity(entity.id);\n if (!currEntity) return '';\n\n let messageID = `issues.outdated_tags.${prefix}message`;\n if (subtype === 'noncanonical_brand' && isOnlyAddingTags) {\n messageID += '_incomplete';\n }\n return t(messageID, { feature: utilDisplayLabel(currEntity, context.graph()) });\n }\n\n\n function showReference(selection) {\n let enter = selection.selectAll('.issue-reference')\n .data([0])\n .enter();\n\n enter\n .append('div')\n .attr('class', 'issue-reference')\n .text(t(`issues.outdated_tags.${prefix}reference`));\n\n enter\n .append('strong')\n .text(t('issues.suggested'));\n\n enter\n .append('table')\n .attr('class', 'tagDiff-table')\n .selectAll('.tagDiff-row')\n .data(tagDiff)\n .enter()\n .append('tr')\n .attr('class', 'tagDiff-row')\n .append('td')\n .attr('class', d => {\n let klass = d.type === '+' ? 'add' : 'remove';\n return `tagDiff-cell tagDiff-cell-${klass}`;\n })\n .text(d => d.display);\n }\n }\n\n\n function oldMultipolygonIssues(entity, graph) {\n let multipolygon, outerWay;\n if (entity.type === 'relation') {\n outerWay = osmOldMultipolygonOuterMemberOfRelation(entity, graph);\n multipolygon = entity;\n } else if (entity.type === 'way') {\n multipolygon = osmIsOldMultipolygonOuterMember(entity, graph);\n outerWay = entity;\n } else {\n return [];\n }\n\n if (!multipolygon || !outerWay) return [];\n\n return [new validationIssue({\n type: type,\n subtype: 'old_multipolygon',\n severity: 'warning',\n message: showMessage,\n reference: showReference,\n entityIds: [outerWay.id, multipolygon.id],\n autoArgs: [doUpgrade, t('issues.fix.move_tags.annotation')],\n dynamicFixes: () => {\n return [\n new validationIssueFix({\n // autoArgs: [doUpgrade, t('issues.fix.move_tags.annotation')],\n title: t('issues.fix.move_tags.title'),\n onClick: (context) => {\n context.perform(doUpgrade, t('issues.fix.move_tags.annotation'));\n }\n })\n ];\n }\n })];\n\n\n function doUpgrade(graph) {\n let currMultipolygon = graph.hasEntity(multipolygon.id);\n let currOuterWay = graph.hasEntity(outerWay.id);\n if (!currMultipolygon || !currOuterWay) return graph;\n\n currMultipolygon = currMultipolygon.mergeTags(currOuterWay.tags);\n graph = graph.replace(currMultipolygon);\n return actionChangeTags(currOuterWay.id, {})(graph);\n }\n\n\n function showMessage(context) {\n let currMultipolygon = context.hasEntity(multipolygon.id);\n if (!currMultipolygon) return '';\n\n return t('issues.old_multipolygon.message',\n { multipolygon: utilDisplayLabel(currMultipolygon, context.graph()) }\n );\n }\n\n\n function showReference(selection) {\n selection.selectAll('.issue-reference')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'issue-reference')\n .text(t('issues.old_multipolygon.reference'));\n }\n }\n\n\n let validation = function checkOutdatedTags(entity, graph) {\n let issues = oldMultipolygonIssues(entity, graph);\n if (!issues.length) issues = oldTagIssues(entity, graph);\n return issues;\n };\n\n\n validation.type = type;\n\n return validation;\n}\n","import { actionChangeTags } from '../actions/change_tags';\nimport { t } from '../core/localizer';\nimport { utilDisplayLabel, utilTagDiff } from '../util';\nimport { validationIssue, validationIssueFix } from '../core/validation';\n\n\nexport function validationPrivateData() {\n var type = 'private_data';\n\n // assume that some buildings are private\n var privateBuildingValues = {\n detached: true,\n farm: true,\n house: true,\n houseboat: true,\n residential: true,\n semidetached_house: true,\n static_caravan: true\n };\n\n // but they might be public if they have one of these other tags\n var publicKeys = {\n amenity: true,\n craft: true,\n historic: true,\n leisure: true,\n office: true,\n shop: true,\n tourism: true\n };\n\n // these tags may contain personally identifying info\n var personalTags = {\n 'contact:email': true,\n 'contact:fax': true,\n 'contact:phone': true,\n email: true,\n fax: true,\n phone: true\n };\n\n\n var validation = function checkPrivateData(entity) {\n var tags = entity.tags;\n if (!tags.building || !privateBuildingValues[tags.building]) return [];\n\n var keepTags = {};\n for (var k in tags) {\n if (publicKeys[k]) return []; // probably a public feature\n if (!personalTags[k]) {\n keepTags[k] = tags[k];\n }\n }\n\n var tagDiff = utilTagDiff(tags, keepTags);\n if (!tagDiff.length) return [];\n\n var fixID = tagDiff.length === 1 ? 'remove_tag' : 'remove_tags';\n\n return [new validationIssue({\n type: type,\n severity: 'warning',\n message: showMessage,\n reference: showReference,\n entityIds: [entity.id],\n dynamicFixes: function() {\n return [\n new validationIssueFix({\n icon: 'iD-operation-delete',\n title: t('issues.fix.' + fixID + '.title'),\n onClick: function(context) {\n context.perform(doUpgrade, t('issues.fix.upgrade_tags.annotation'));\n }\n })\n ];\n }\n })];\n\n\n function doUpgrade(graph) {\n var currEntity = graph.hasEntity(entity.id);\n if (!currEntity) return graph;\n\n var newTags = Object.assign({}, currEntity.tags); // shallow copy\n tagDiff.forEach(function(diff) {\n if (diff.type === '-') {\n delete newTags[diff.key];\n } else if (diff.type === '+') {\n newTags[diff.key] = diff.newVal;\n }\n });\n\n return actionChangeTags(currEntity.id, newTags)(graph);\n }\n\n\n function showMessage(context) {\n var currEntity = context.hasEntity(this.entityIds[0]);\n if (!currEntity) return '';\n\n return t('issues.private_data.contact.message',\n { feature: utilDisplayLabel(currEntity, context.graph()) }\n );\n }\n\n\n function showReference(selection) {\n var enter = selection.selectAll('.issue-reference')\n .data([0])\n .enter();\n\n enter\n .append('div')\n .attr('class', 'issue-reference')\n .text(t('issues.private_data.reference'));\n\n enter\n .append('strong')\n .text(t('issues.suggested'));\n\n enter\n .append('table')\n .attr('class', 'tagDiff-table')\n .selectAll('.tagDiff-row')\n .data(tagDiff)\n .enter()\n .append('tr')\n .attr('class', 'tagDiff-row')\n .append('td')\n .attr('class', function(d) {\n var klass = d.type === '+' ? 'add' : 'remove';\n return 'tagDiff-cell tagDiff-cell-' + klass;\n })\n .text(function(d) { return d.display; });\n }\n };\n\n\n validation.type = type;\n\n return validation;\n}\n","import { t } from '../core/localizer';\nimport { behaviorDrawWay } from '../behavior/draw_way';\n\n\nexport function modeDrawArea(context, wayID, startGraph, button) {\n var mode = {\n button: button,\n id: 'draw-area'\n };\n\n var behavior = behaviorDrawWay(context, wayID, mode, startGraph)\n .on('rejectedSelfIntersection.modeDrawArea', function() {\n context.ui().flash\n .text(t('self_intersection.error.areas'))();\n });\n\n mode.wayID = wayID;\n\n mode.enter = function() {\n context.install(behavior);\n };\n\n mode.exit = function() {\n context.uninstall(behavior);\n };\n\n mode.selectedIDs = function() {\n return [wayID];\n };\n\n mode.activeID = function() {\n return (behavior && behavior.activeID()) || [];\n };\n\n return mode;\n}\n","import { actionAddEntity } from '../actions/add_entity';\nimport { actionAddMidpoint } from '../actions/add_midpoint';\nimport { actionAddVertex } from '../actions/add_vertex';\n\nimport { behaviorAddWay } from '../behavior/add_way';\nimport { modeDrawArea } from './draw_area';\nimport { osmNode, osmWay } from '../osm';\n\n\nexport function modeAddArea(context, mode) {\n mode.id = 'add-area';\n\n var behavior = behaviorAddWay(context)\n .on('start', start)\n .on('startFromWay', startFromWay)\n .on('startFromNode', startFromNode);\n\n var defaultTags = { area: 'yes' };\n if (mode.preset) defaultTags = mode.preset.setTags(defaultTags, 'area');\n\n\n function actionClose(wayId) {\n return function (graph) {\n return graph.replace(graph.entity(wayId).close());\n };\n }\n\n\n function start(loc) {\n var startGraph = context.graph();\n var node = osmNode({ loc: loc });\n var way = osmWay({ tags: defaultTags });\n\n context.perform(\n actionAddEntity(node),\n actionAddEntity(way),\n actionAddVertex(way.id, node.id),\n actionClose(way.id)\n );\n\n context.enter(modeDrawArea(context, way.id, startGraph, mode.button));\n }\n\n\n function startFromWay(loc, edge) {\n var startGraph = context.graph();\n var node = osmNode({ loc: loc });\n var way = osmWay({ tags: defaultTags });\n\n context.perform(\n actionAddEntity(node),\n actionAddEntity(way),\n actionAddVertex(way.id, node.id),\n actionClose(way.id),\n actionAddMidpoint({ loc: loc, edge: edge }, node)\n );\n\n context.enter(modeDrawArea(context, way.id, startGraph, mode.button));\n }\n\n\n function startFromNode(node) {\n var startGraph = context.graph();\n var way = osmWay({ tags: defaultTags });\n\n context.perform(\n actionAddEntity(way),\n actionAddVertex(way.id, node.id),\n actionClose(way.id)\n );\n\n context.enter(modeDrawArea(context, way.id, startGraph, mode.button));\n }\n\n\n mode.enter = function() {\n context.install(behavior);\n };\n\n\n mode.exit = function() {\n context.uninstall(behavior);\n };\n\n\n return mode;\n}\n","import { actionAddEntity } from '../actions/add_entity';\nimport { actionAddMidpoint } from '../actions/add_midpoint';\nimport { actionAddVertex } from '../actions/add_vertex';\n\nimport { behaviorAddWay } from '../behavior/add_way';\nimport { modeDrawLine } from './draw_line';\nimport { osmNode, osmWay } from '../osm';\n\n// RapiD\nimport { prefs } from '../core/preferences';\n\n\nexport function modeAddLine(context, mode) {\n mode.id = 'add-line';\n\n var behavior = behaviorAddWay(context)\n .on('start', start)\n .on('startFromWay', startFromWay)\n .on('startFromNode', startFromNode);\n\n var defaultTags = {};\n if (mode.preset) defaultTags = mode.preset.setTags(defaultTags, 'line');\n\n // RapiD tagSources\n var tagSources = prefs('rapid-internal-feature.tagSources') === 'true';\n if (tagSources && defaultTags.highway) {\n defaultTags.source = 'maxar';\n }\n\n\n function start(loc) {\n var startGraph = context.graph();\n var node = osmNode({ loc: loc });\n var way = osmWay({ tags: defaultTags });\n\n context.perform(\n actionAddEntity(node),\n actionAddEntity(way),\n actionAddVertex(way.id, node.id)\n );\n\n context.enter(modeDrawLine(context, way.id, startGraph, mode.button));\n }\n\n\n function startFromWay(loc, edge) {\n var startGraph = context.graph();\n var node = osmNode({ loc: loc });\n var way = osmWay({ tags: defaultTags });\n\n context.perform(\n actionAddEntity(node),\n actionAddEntity(way),\n actionAddVertex(way.id, node.id),\n actionAddMidpoint({ loc: loc, edge: edge }, node)\n );\n\n context.enter(modeDrawLine(context, way.id, startGraph, mode.button));\n }\n\n\n function startFromNode(node) {\n var startGraph = context.graph();\n var way = osmWay({ tags: defaultTags });\n\n context.perform(\n actionAddEntity(way),\n actionAddVertex(way.id, node.id)\n );\n\n context.enter(modeDrawLine(context, way.id, startGraph, mode.button));\n }\n\n\n mode.enter = function() {\n context.install(behavior);\n };\n\n\n mode.exit = function() {\n context.uninstall(behavior);\n };\n\n return mode;\n}\n","import { t } from '../core/localizer';\nimport { behaviorDraw } from '../behavior/draw';\nimport { modeBrowse } from './browse';\nimport { modeSelect } from './select';\nimport { osmNode } from '../osm/node';\nimport { actionAddEntity } from '../actions/add_entity';\nimport { actionChangeTags } from '../actions/change_tags';\nimport { actionAddMidpoint } from '../actions/add_midpoint';\n\n\nexport function modeAddPoint(context, mode) {\n\n mode.id = 'add-point';\n\n var behavior = behaviorDraw(context)\n .on('click', add)\n .on('clickWay', addWay)\n .on('clickNode', addNode)\n .on('cancel', cancel)\n .on('finish', cancel);\n\n var defaultTags = {};\n if (mode.preset) defaultTags = mode.preset.setTags(defaultTags, 'point');\n\n\n function add(loc) {\n var node = osmNode({ loc: loc, tags: defaultTags });\n\n context.perform(\n actionAddEntity(node),\n t('operations.add.annotation.point')\n );\n\n enterSelectMode(node);\n }\n\n\n function addWay(loc, edge) {\n var node = osmNode({ tags: defaultTags });\n\n context.perform(\n actionAddMidpoint({loc: loc, edge: edge}, node),\n t('operations.add.annotation.vertex')\n );\n\n enterSelectMode(node);\n }\n\n function enterSelectMode(node) {\n context.enter(\n modeSelect(context, [node.id]).newFeature(true)\n );\n }\n\n\n function addNode(node) {\n if (Object.keys(defaultTags).length === 0) {\n enterSelectMode(node);\n return;\n }\n\n var tags = Object.assign({}, node.tags); // shallow copy\n for (var key in defaultTags) {\n tags[key] = defaultTags[key];\n }\n\n context.perform(\n actionChangeTags(node.id, tags),\n t('operations.add.annotation.point')\n );\n\n enterSelectMode(node);\n }\n\n\n function cancel() {\n context.enter(modeBrowse(context));\n }\n\n\n mode.enter = function() {\n context.install(behavior);\n };\n\n\n mode.exit = function() {\n context.uninstall(behavior);\n };\n\n\n return mode;\n}\n","import { select as d3_select } from 'd3-selection';\n\nimport { prefs } from '../core/preferences';\nimport { t, localizer } from '../core/localizer';\nimport { svgIcon } from '../svg/icon';\nimport { services } from '../services';\n\n\nexport function uiNoteComments() {\n var _note;\n\n\n function noteComments(selection) {\n if (_note.isNew()) return; // don't draw .comments-container\n\n var comments = selection.selectAll('.comments-container')\n .data([0]);\n\n comments = comments.enter()\n .append('div')\n .attr('class', 'comments-container')\n .merge(comments);\n\n var commentEnter = comments.selectAll('.comment')\n .data(_note.comments)\n .enter()\n .append('div')\n .attr('class', 'comment');\n\n commentEnter\n .append('div')\n .attr('class', function(d) { return 'comment-avatar user-' + d.uid; })\n .call(svgIcon('#iD-icon-avatar', 'comment-avatar-icon'));\n\n var mainEnter = commentEnter\n .append('div')\n .attr('class', 'comment-main');\n\n var metadataEnter = mainEnter\n .append('div')\n .attr('class', 'comment-metadata');\n\n metadataEnter\n .append('div')\n .attr('class', 'comment-author')\n .each(function(d) {\n var selection = d3_select(this);\n var osm = services.osm;\n if (osm && d.user) {\n selection = selection\n .append('a')\n .attr('class', 'comment-author-link')\n .attr('href', osm.userURL(d.user))\n .attr('tabindex', -1)\n .attr('target', '_blank');\n }\n selection\n .text(function(d) { return d.user || t('note.anonymous'); });\n });\n\n metadataEnter\n .append('div')\n .attr('class', 'comment-date')\n .text(function(d) {\n return t('note.status.' + d.action, { when: localeDateString(d.date) });\n });\n\n mainEnter\n .append('div')\n .attr('class', 'comment-text')\n .html(function(d) { return d.html; });\n\n comments\n .call(replaceAvatars);\n }\n\n\n function replaceAvatars(selection) {\n var showThirdPartyIcons = prefs('preferences.privacy.thirdpartyicons') || 'true';\n var osm = services.osm;\n if (showThirdPartyIcons !== 'true' || !osm) return;\n\n var uids = {}; // gather uids in the comment thread\n _note.comments.forEach(function(d) {\n if (d.uid) uids[d.uid] = true;\n });\n\n Object.keys(uids).forEach(function(uid) {\n osm.loadUser(uid, function(err, user) {\n if (!user || !user.image_url) return;\n\n selection.selectAll('.comment-avatar.user-' + uid)\n .html('')\n .append('img')\n .attr('class', 'icon comment-avatar-icon')\n .attr('src', user.image_url)\n .attr('alt', user.display_name);\n });\n });\n }\n\n\n function localeDateString(s) {\n if (!s) return null;\n var options = { day: 'numeric', month: 'short', year: 'numeric' };\n s = s.replace(/-/g, '/'); // fix browser-specific Date() issues\n var d = new Date(s);\n if (isNaN(d.getTime())) return null;\n return d.toLocaleDateString(localizer.localeCode(), options);\n }\n\n\n noteComments.note = function(val) {\n if (!arguments.length) return _note;\n _note = val;\n return noteComments;\n };\n\n\n return noteComments;\n}\n","import { t } from '../core/localizer';\nimport { svgIcon } from '../svg/icon';\n\n\nexport function uiNoteHeader() {\n var _note;\n\n\n function noteHeader(selection) {\n var header = selection.selectAll('.note-header')\n .data(\n (_note ? [_note] : []),\n function(d) { return d.status + d.id; }\n );\n\n header.exit()\n .remove();\n\n var headerEnter = header.enter()\n .append('div')\n .attr('class', 'note-header');\n\n var iconEnter = headerEnter\n .append('div')\n .attr('class', function(d) { return 'note-header-icon ' + d.status; })\n .classed('new', function(d) { return d.id < 0; });\n\n iconEnter\n .append('div')\n .attr('class', 'preset-icon-28')\n .call(svgIcon('#iD-icon-note', 'note-fill'));\n\n iconEnter.each(function(d) {\n var statusIcon = '#iD-icon-' + (d.id < 0 ? 'plus' : (d.status === 'open' ? 'close' : 'apply'));\n iconEnter\n .append('div')\n .attr('class', 'note-icon-annotation')\n .call(svgIcon(statusIcon, 'icon-annotation'));\n });\n\n headerEnter\n .append('div')\n .attr('class', 'note-header-label')\n .text(function(d) {\n if (_note.isNew()) { return t('note.new'); }\n return t('note.note') + ' ' + d.id + ' ' +\n (d.status === 'closed' ? t('note.closed') : '');\n });\n }\n\n\n noteHeader.note = function(val) {\n if (!arguments.length) return _note;\n _note = val;\n return noteHeader;\n };\n\n\n return noteHeader;\n}\n","import { t } from '../core/localizer';\nimport { osmNote } from '../osm';\nimport { services } from '../services';\nimport { svgIcon } from '../svg/icon';\n\n\nexport function uiNoteReport() {\n var _note;\n\n function noteReport(selection) {\n var url;\n if (services.osm && (_note instanceof osmNote) && (!_note.isNew())) {\n url = services.osm.noteReportURL(_note);\n }\n\n var link = selection.selectAll('.note-report')\n .data(url ? [url] : []);\n\n // exit\n link.exit()\n .remove();\n\n // enter\n var linkEnter = link.enter()\n .append('a')\n .attr('class', 'note-report')\n .attr('target', '_blank')\n .attr('href', function(d) { return d; })\n .call(svgIcon('#iD-icon-out-link', 'inline'));\n\n linkEnter\n .append('span')\n .text(t('note.report'));\n }\n\n\n noteReport.note = function(val) {\n if (!arguments.length) return _note;\n _note = val;\n return noteReport;\n };\n\n return noteReport;\n}\n","import { t } from '../core/localizer';\nimport { osmEntity, osmNote } from '../osm';\nimport { svgIcon } from '../svg/icon';\n\n\nexport function uiViewOnOSM(context) {\n var _what; // an osmEntity or osmNote\n\n\n function viewOnOSM(selection) {\n var url;\n if (_what instanceof osmEntity) {\n url = context.connection().entityURL(_what);\n } else if (_what instanceof osmNote) {\n url = context.connection().noteURL(_what);\n }\n\n var data = ((!_what || _what.isNew()) ? [] : [_what]);\n var link = selection.selectAll('.view-on-osm')\n .data(data, function(d) { return d.id; });\n\n // exit\n link.exit()\n .remove();\n\n // enter\n var linkEnter = link.enter()\n .append('a')\n .attr('class', 'view-on-osm')\n .attr('target', '_blank')\n .attr('href', url)\n .call(svgIcon('#iD-icon-out-link', 'inline'));\n\n linkEnter\n .append('span')\n .text(t('inspector.view_on_osm'));\n }\n\n\n viewOnOSM.what = function(_) {\n if (!arguments.length) return _what;\n _what = _;\n return viewOnOSM;\n };\n\n return viewOnOSM;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { t } from '../core/localizer';\nimport { services } from '../services';\nimport { modeBrowse } from '../modes/browse';\nimport { svgIcon } from '../svg/icon';\n\n// import { uiField } from './field';\n// import { uiFormFields } from './form_fields';\n\nimport { uiNoteComments } from './note_comments';\nimport { uiNoteHeader } from './note_header';\nimport { uiNoteReport } from './note_report';\nimport { uiViewOnOSM } from './view_on_osm';\n\nimport {\n utilNoAuto,\n utilRebind\n} from '../util';\n\n\nexport function uiNoteEditor(context) {\n var dispatch = d3_dispatch('change');\n var noteComments = uiNoteComments(context);\n var noteHeader = uiNoteHeader();\n\n // var formFields = uiFormFields(context);\n\n var _note;\n var _newNote;\n // var _fieldsArr;\n\n\n function noteEditor(selection) {\n\n var header = selection.selectAll('.header')\n .data([0]);\n\n var headerEnter = header.enter()\n .append('div')\n .attr('class', 'header fillL');\n\n headerEnter\n .append('button')\n .attr('class', 'close')\n .on('click', function() {\n context.enter(modeBrowse(context));\n })\n .call(svgIcon('#iD-icon-close'));\n\n headerEnter\n .append('h3')\n .text(t('note.title'));\n\n\n var body = selection.selectAll('.body')\n .data([0]);\n\n body = body.enter()\n .append('div')\n .attr('class', 'body')\n .merge(body);\n\n var editor = body.selectAll('.note-editor')\n .data([0]);\n\n editor.enter()\n .append('div')\n .attr('class', 'modal-section note-editor')\n .merge(editor)\n .call(noteHeader.note(_note))\n .call(noteComments.note(_note))\n .call(noteSaveSection);\n\n var footer = selection.selectAll('.footer')\n .data([0]);\n\n footer.enter()\n .append('div')\n .attr('class', 'footer')\n .merge(footer)\n .call(uiViewOnOSM(context).what(_note))\n .call(uiNoteReport(context).note(_note));\n\n\n // rerender the note editor on any auth change\n var osm = services.osm;\n if (osm) {\n osm.on('change.note-save', function() {\n selection.call(noteEditor);\n });\n }\n }\n\n\n function noteSaveSection(selection) {\n var isSelected = (_note && _note.id === context.selectedNoteID());\n var noteSave = selection.selectAll('.note-save')\n .data((isSelected ? [_note] : []), function(d) { return d.status + d.id; });\n\n // exit\n noteSave.exit()\n .remove();\n\n // enter\n var noteSaveEnter = noteSave.enter()\n .append('div')\n .attr('class', 'note-save save-section cf');\n\n // // if new note, show categories to pick from\n // if (_note.isNew()) {\n // var presets = presetManager;\n\n // // NOTE: this key isn't a age and therefore there is no documentation (yet)\n // _fieldsArr = [\n // uiField(context, presets.field('category'), null, { show: true, revert: false }),\n // ];\n\n // _fieldsArr.forEach(function(field) {\n // field\n // .on('change', changeCategory);\n // });\n\n // noteSaveEnter\n // .append('div')\n // .attr('class', 'note-category')\n // .call(formFields.fieldsArr(_fieldsArr));\n // }\n\n // function changeCategory() {\n // // NOTE: perhaps there is a better way to get value\n // var val = context.container().select('input[name=\\'category\\']:checked').property('__data__') || undefined;\n\n // // store the unsaved category with the note itself\n // _note = _note.update({ newCategory: val });\n // var osm = services.osm;\n // if (osm) {\n // osm.replaceNote(_note); // update note cache\n // }\n // noteSave\n // .call(noteSaveButtons);\n // }\n\n noteSaveEnter\n .append('h4')\n .attr('class', '.note-save-header')\n .text(function() {\n return _note.isNew() ? t('note.newDescription') : t('note.newComment');\n });\n\n var commentTextarea = noteSaveEnter\n .append('textarea')\n .attr('class', 'new-comment-input')\n .attr('placeholder', t('note.inputPlaceholder'))\n .attr('maxlength', 1000)\n .property('value', function(d) { return d.newComment; })\n .call(utilNoAuto)\n .on('keydown.note-input', keydown)\n .on('input.note-input', changeInput)\n .on('blur.note-input', changeInput);\n\n if (_newNote) {\n // autofocus the comment field for new notes\n commentTextarea.node().focus();\n }\n\n // update\n noteSave = noteSaveEnter\n .merge(noteSave)\n .call(userDetails)\n .call(noteSaveButtons);\n\n\n // fast submit if user presses cmd+enter\n function keydown() {\n if (!(d3_event.keyCode === 13 && d3_event.metaKey)) return;\n\n var osm = services.osm;\n if (!osm) return;\n\n var hasAuth = osm.authenticated();\n if (!hasAuth) return;\n\n if (!_note.newComment) return;\n\n d3_event.preventDefault();\n\n d3_select(this)\n .on('keydown.note-input', null);\n\n // focus on button and submit\n window.setTimeout(function() {\n if (_note.isNew()) {\n noteSave.selectAll('.save-button').node().focus();\n clickSave(_note);\n } else {\n noteSave.selectAll('.comment-button').node().focus();\n clickComment(_note);\n }\n }, 10);\n }\n\n\n function changeInput() {\n var input = d3_select(this);\n var val = input.property('value').trim() || undefined;\n\n // store the unsaved comment with the note itself\n _note = _note.update({ newComment: val });\n\n var osm = services.osm;\n if (osm) {\n osm.replaceNote(_note); // update note cache\n }\n\n noteSave\n .call(noteSaveButtons);\n }\n }\n\n\n function userDetails(selection) {\n var detailSection = selection.selectAll('.detail-section')\n .data([0]);\n\n detailSection = detailSection.enter()\n .append('div')\n .attr('class', 'detail-section')\n .merge(detailSection);\n\n var osm = services.osm;\n if (!osm) return;\n\n // Add warning if user is not logged in\n var hasAuth = osm.authenticated();\n var authWarning = detailSection.selectAll('.auth-warning')\n .data(hasAuth ? [] : [0]);\n\n authWarning.exit()\n .transition()\n .duration(200)\n .style('opacity', 0)\n .remove();\n\n var authEnter = authWarning.enter()\n .insert('div', '.tag-reference-body')\n .attr('class', 'field-warning auth-warning')\n .style('opacity', 0);\n\n authEnter\n .call(svgIcon('#iD-icon-alert', 'inline'));\n\n authEnter\n .append('span')\n .text(t('note.login'));\n\n authEnter\n .append('a')\n .attr('target', '_blank')\n .call(svgIcon('#iD-icon-out-link', 'inline'))\n .append('span')\n .text(t('login'))\n .on('click.note-login', function() {\n d3_event.preventDefault();\n osm.authenticate();\n });\n\n authEnter\n .transition()\n .duration(200)\n .style('opacity', 1);\n\n\n var prose = detailSection.selectAll('.note-save-prose')\n .data(hasAuth ? [0] : []);\n\n prose.exit()\n .remove();\n\n prose = prose.enter()\n .append('p')\n .attr('class', 'note-save-prose')\n .text(t('note.upload_explanation'))\n .merge(prose);\n\n osm.userDetails(function(err, user) {\n if (err) return;\n\n var userLink = d3_select(document.createElement('div'));\n\n if (user.image_url) {\n userLink\n .append('img')\n .attr('src', user.image_url)\n .attr('class', 'icon pre-text user-icon');\n }\n\n userLink\n .append('a')\n .attr('class', 'user-info')\n .text(user.display_name)\n .attr('href', osm.userURL(user.display_name))\n .attr('tabindex', -1)\n .attr('target', '_blank');\n\n prose\n .html(t('note.upload_explanation_with_user', { user: userLink.html() }));\n });\n }\n\n\n function noteSaveButtons(selection) {\n var osm = services.osm;\n var hasAuth = osm && osm.authenticated();\n\n var isSelected = (_note && _note.id === context.selectedNoteID());\n var buttonSection = selection.selectAll('.buttons')\n .data((isSelected ? [_note] : []), function(d) { return d.status + d.id; });\n\n // exit\n buttonSection.exit()\n .remove();\n\n // enter\n var buttonEnter = buttonSection.enter()\n .append('div')\n .attr('class', 'buttons');\n\n if (_note.isNew()) {\n buttonEnter\n .append('button')\n .attr('class', 'button cancel-button secondary-action')\n .text(t('confirm.cancel'));\n\n buttonEnter\n .append('button')\n .attr('class', 'button save-button action')\n .text(t('note.save'));\n\n } else {\n buttonEnter\n .append('button')\n .attr('class', 'button status-button action');\n\n buttonEnter\n .append('button')\n .attr('class', 'button comment-button action')\n .text(t('note.comment'));\n }\n\n\n // update\n buttonSection = buttonSection\n .merge(buttonEnter);\n\n buttonSection.select('.cancel-button') // select and propagate data\n .on('click.cancel', clickCancel);\n\n buttonSection.select('.save-button') // select and propagate data\n .attr('disabled', isSaveDisabled)\n .on('click.save', clickSave);\n\n buttonSection.select('.status-button') // select and propagate data\n .attr('disabled', (hasAuth ? null : true))\n .text(function(d) {\n var action = (d.status === 'open' ? 'close' : 'open');\n var andComment = (d.newComment ? '_comment' : '');\n return t('note.' + action + andComment);\n })\n .on('click.status', clickStatus);\n\n buttonSection.select('.comment-button') // select and propagate data\n .attr('disabled', isSaveDisabled)\n .on('click.comment', clickComment);\n\n\n function isSaveDisabled(d) {\n return (hasAuth && d.status === 'open' && d.newComment) ? null : true;\n }\n }\n\n\n\n function clickCancel(d) {\n this.blur(); // avoid keeping focus on the button - #4641\n var osm = services.osm;\n if (osm) {\n osm.removeNote(d);\n }\n context.enter(modeBrowse(context));\n dispatch.call('change');\n }\n\n\n function clickSave(d) {\n this.blur(); // avoid keeping focus on the button - #4641\n var osm = services.osm;\n if (osm) {\n osm.postNoteCreate(d, function(err, note) {\n dispatch.call('change', note);\n });\n }\n }\n\n\n function clickStatus(d) {\n this.blur(); // avoid keeping focus on the button - #4641\n var osm = services.osm;\n if (osm) {\n var setStatus = (d.status === 'open' ? 'closed' : 'open');\n osm.postNoteUpdate(d, setStatus, function(err, note) {\n dispatch.call('change', note);\n });\n }\n }\n\n function clickComment(d) {\n this.blur(); // avoid keeping focus on the button - #4641\n var osm = services.osm;\n if (osm) {\n osm.postNoteUpdate(d, d.status, function(err, note) {\n dispatch.call('change', note);\n });\n }\n }\n\n\n noteEditor.note = function(val) {\n if (!arguments.length) return _note;\n _note = val;\n return noteEditor;\n };\n\n noteEditor.newNote = function(val) {\n if (!arguments.length) return _newNote;\n _newNote = val;\n return noteEditor;\n };\n\n\n return utilRebind(noteEditor, dispatch, 'on');\n}\n","import {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { behaviorBreathe } from '../behavior/breathe';\nimport { behaviorHover } from '../behavior/hover';\nimport { behaviorLasso } from '../behavior/lasso';\nimport { behaviorSelect } from '../behavior/select';\n\nimport { t } from '../core/localizer';\n\nimport { modeBrowse } from './browse';\nimport { modeDragNode } from './drag_node';\nimport { modeDragNote } from './drag_note';\nimport { services } from '../services';\nimport { uiNoteEditor } from '../ui/note_editor';\nimport { utilKeybinding } from '../util';\n\n\nexport function modeSelectNote(context, selectedNoteID) {\n var mode = {\n id: 'select-note',\n button: 'browse'\n };\n\n var _keybinding = utilKeybinding('select-note');\n var _noteEditor = uiNoteEditor(context)\n .on('change', function() {\n context.map().pan([0,0]); // trigger a redraw\n var note = checkSelectedID();\n if (!note) return;\n context.ui().sidebar\n .show(_noteEditor.note(note));\n });\n\n var _behaviors = [\n behaviorBreathe(context),\n behaviorHover(context),\n behaviorSelect(context),\n behaviorLasso(context),\n modeDragNode(context).behavior,\n modeDragNote(context).behavior\n ];\n\n var _newFeature = false;\n\n\n function checkSelectedID() {\n if (!services.osm) return;\n var note = services.osm.getNote(selectedNoteID);\n if (!note) {\n context.enter(modeBrowse(context));\n }\n return note;\n }\n\n\n // class the note as selected, or return to browse mode if the note is gone\n function selectNote(drawn) {\n if (!checkSelectedID()) return;\n\n var selection = context.surface().selectAll('.layer-notes .note-' + selectedNoteID);\n\n if (selection.empty()) {\n // Return to browse mode if selected DOM elements have\n // disappeared because the user moved them out of view..\n var source = d3_event && d3_event.type === 'zoom' && d3_event.sourceEvent;\n if (drawn && source && (source.type === 'pointermove' || source.type === 'mousemove' || source.type === 'touchmove')) {\n context.enter(modeBrowse(context));\n }\n\n } else {\n selection\n .classed('selected', true);\n\n context.selectedNoteID(selectedNoteID);\n }\n }\n\n\n function esc() {\n if (context.container().select('.combobox').size()) return;\n context.enter(modeBrowse(context));\n }\n\n\n mode.zoomToSelected = function() {\n if (!services.osm) return;\n var note = services.osm.getNote(selectedNoteID);\n if (note) {\n context.map().centerZoomEase(note.loc, 20);\n }\n };\n\n\n mode.newFeature = function(val) {\n if (!arguments.length) return _newFeature;\n _newFeature = val;\n return mode;\n };\n\n\n mode.enter = function() {\n var note = checkSelectedID();\n if (!note) return;\n\n _behaviors.forEach(context.install);\n\n _keybinding\n .on(t('inspector.zoom_to.key'), mode.zoomToSelected)\n .on('⎋', esc, true);\n\n d3_select(document)\n .call(_keybinding);\n\n selectNote();\n\n var sidebar = context.ui().sidebar;\n sidebar.show(_noteEditor.note(note).newNote(_newFeature));\n\n // expand the sidebar, avoid obscuring the note if needed\n sidebar.expand(sidebar.intersects(note.extent()));\n\n context.map()\n .on('drawn.select', selectNote);\n };\n\n\n mode.exit = function() {\n _behaviors.forEach(context.uninstall);\n\n d3_select(document)\n .call(_keybinding.unbind);\n\n context.surface()\n .selectAll('.layer-notes .selected')\n .classed('selected hover', false);\n\n context.map()\n .on('drawn.select', null);\n\n context.ui().sidebar\n .hide();\n\n context.selectedNoteID(null);\n };\n\n\n return mode;\n}\n","import { t } from '../core/localizer';\nimport { behaviorDraw } from '../behavior/draw';\nimport { modeBrowse } from './browse';\nimport { modeSelectNote } from './select_note';\nimport { osmNote } from '../osm';\nimport { services } from '../services';\n\n\nexport function modeAddNote(context) {\n var mode = {\n id: 'add-note',\n button: 'note',\n title: t('modes.add_note.title'),\n description: t('modes.add_note.description'),\n key: t('modes.add_note.key')\n };\n\n var behavior = behaviorDraw(context)\n .on('click', add)\n .on('cancel', cancel)\n .on('finish', cancel);\n\n\n function add(loc) {\n var osm = services.osm;\n if (!osm) return;\n\n var note = osmNote({ loc: loc, status: 'open', comments: [] });\n osm.replaceNote(note);\n\n // force a reraw (there is no history change that would otherwise do this)\n context.map().pan([0,0]);\n\n context\n .selectedNoteID(note.id)\n .enter(modeSelectNote(context, note.id).newFeature(true));\n }\n\n\n function cancel() {\n context.enter(modeBrowse(context));\n }\n\n\n mode.enter = function() {\n context.install(behavior);\n };\n\n\n mode.exit = function() {\n context.uninstall(behavior);\n };\n\n\n return mode;\n}\n","export var JXON = new (function () {\n var\n sValueProp = 'keyValue', sAttributesProp = 'keyAttributes', sAttrPref = '@', /* you can customize these values */\n aCache = [], rIsNull = /^\\s*$/, rIsBool = /^(?:true|false)$/i;\n\n function parseText (sValue) {\n if (rIsNull.test(sValue)) { return null; }\n if (rIsBool.test(sValue)) { return sValue.toLowerCase() === 'true'; }\n if (isFinite(sValue)) { return parseFloat(sValue); }\n if (isFinite(Date.parse(sValue))) { return new Date(sValue); }\n return sValue;\n }\n\n function EmptyTree () { }\n EmptyTree.prototype.toString = function () { return 'null'; };\n EmptyTree.prototype.valueOf = function () { return null; };\n\n function objectify (vValue) {\n return vValue === null ? new EmptyTree() : vValue instanceof Object ? vValue : new vValue.constructor(vValue);\n }\n\n function createObjTree (oParentNode, nVerb, bFreeze, bNesteAttr) {\n var\n nLevelStart = aCache.length, bChildren = oParentNode.hasChildNodes(),\n bAttributes = oParentNode.hasAttributes(), bHighVerb = Boolean(nVerb & 2);\n\n var\n sProp, vContent, nLength = 0, sCollectedTxt = '',\n vResult = bHighVerb ? {} : /* put here the default value for empty nodes: */ true;\n\n if (bChildren) {\n for (var oNode, nItem = 0; nItem < oParentNode.childNodes.length; nItem++) {\n oNode = oParentNode.childNodes.item(nItem);\n if (oNode.nodeType === 4) { sCollectedTxt += oNode.nodeValue; } /* nodeType is 'CDATASection' (4) */\n else if (oNode.nodeType === 3) { sCollectedTxt += oNode.nodeValue.trim(); } /* nodeType is 'Text' (3) */\n else if (oNode.nodeType === 1 && !oNode.prefix) { aCache.push(oNode); } /* nodeType is 'Element' (1) */\n }\n }\n\n var nLevelEnd = aCache.length, vBuiltVal = parseText(sCollectedTxt);\n\n if (!bHighVerb && (bChildren || bAttributes)) { vResult = nVerb === 0 ? objectify(vBuiltVal) : {}; }\n\n for (var nElId = nLevelStart; nElId < nLevelEnd; nElId++) {\n sProp = aCache[nElId].nodeName.toLowerCase();\n vContent = createObjTree(aCache[nElId], nVerb, bFreeze, bNesteAttr);\n if (vResult.hasOwnProperty(sProp)) {\n if (vResult[sProp].constructor !== Array) { vResult[sProp] = [vResult[sProp]]; }\n vResult[sProp].push(vContent);\n } else {\n vResult[sProp] = vContent;\n nLength++;\n }\n }\n\n if (bAttributes) {\n var\n nAttrLen = oParentNode.attributes.length,\n sAPrefix = bNesteAttr ? '' : sAttrPref, oAttrParent = bNesteAttr ? {} : vResult;\n\n for (var oAttrib, nAttrib = 0; nAttrib < nAttrLen; nLength++, nAttrib++) {\n oAttrib = oParentNode.attributes.item(nAttrib);\n oAttrParent[sAPrefix + oAttrib.name.toLowerCase()] = parseText(oAttrib.value.trim());\n }\n\n if (bNesteAttr) {\n if (bFreeze) { Object.freeze(oAttrParent); }\n vResult[sAttributesProp] = oAttrParent;\n nLength -= nAttrLen - 1;\n }\n }\n\n if (nVerb === 3 || (nVerb === 2 || nVerb === 1 && nLength > 0) && sCollectedTxt) {\n vResult[sValueProp] = vBuiltVal;\n } else if (!bHighVerb && nLength === 0 && sCollectedTxt) {\n vResult = vBuiltVal;\n }\n\n if (bFreeze && (bHighVerb || nLength > 0)) { Object.freeze(vResult); }\n\n aCache.length = nLevelStart;\n\n return vResult;\n }\n\n function loadObjTree (oXMLDoc, oParentEl, oParentObj) {\n var vValue, oChild;\n\n if (oParentObj instanceof String || oParentObj instanceof Number || oParentObj instanceof Boolean) {\n oParentEl.appendChild(oXMLDoc.createTextNode(oParentObj.toString())); /* verbosity level is 0 */\n } else if (oParentObj.constructor === Date) {\n oParentEl.appendChild(oXMLDoc.createTextNode(oParentObj.toGMTString())); \n }\n\n for (var sName in oParentObj) {\n vValue = oParentObj[sName];\n if (isFinite(sName) || vValue instanceof Function) { continue; } /* verbosity level is 0 */\n if (sName === sValueProp) {\n if (vValue !== null && vValue !== true) { oParentEl.appendChild(oXMLDoc.createTextNode(vValue.constructor === Date ? vValue.toGMTString() : String(vValue))); }\n } else if (sName === sAttributesProp) { /* verbosity level is 3 */\n for (var sAttrib in vValue) { oParentEl.setAttribute(sAttrib, vValue[sAttrib]); }\n } else if (sName.charAt(0) === sAttrPref) {\n oParentEl.setAttribute(sName.slice(1), vValue);\n } else if (vValue.constructor === Array) {\n for (var nItem = 0; nItem < vValue.length; nItem++) {\n oChild = oXMLDoc.createElement(sName);\n loadObjTree(oXMLDoc, oChild, vValue[nItem]);\n oParentEl.appendChild(oChild);\n }\n } else {\n oChild = oXMLDoc.createElement(sName);\n if (vValue instanceof Object) {\n loadObjTree(oXMLDoc, oChild, vValue);\n } else if (vValue !== null && vValue !== true) {\n oChild.appendChild(oXMLDoc.createTextNode(vValue.toString()));\n }\n oParentEl.appendChild(oChild);\n }\n }\n }\n\n this.build = function (oXMLParent, nVerbosity /* optional */, bFreeze /* optional */, bNesteAttributes /* optional */) {\n var _nVerb = arguments.length > 1 && typeof nVerbosity === 'number' ? nVerbosity & 3 : /* put here the default verbosity level: */ 1;\n return createObjTree(oXMLParent, _nVerb, bFreeze || false, arguments.length > 3 ? bNesteAttributes : _nVerb === 3); \n };\n\n this.unbuild = function (oObjTree) { \n var oNewDoc = document.implementation.createDocument('', '', null);\n loadObjTree(oNewDoc, oNewDoc, oObjTree);\n return oNewDoc;\n };\n\n this.stringify = function (oObjTree) {\n return (new XMLSerializer()).serializeToString(JXON.unbuild(oObjTree));\n };\n})();\n\n// var myObject = JXON.build(doc);\n// we got our javascript object! try: alert(JSON.stringify(myObject));\n\n// var newDoc = JXON.unbuild(myObject);\n// we got our Document instance! try: alert((new XMLSerializer()).serializeToString(newDoc));\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\n\nimport {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { t } from '../core/localizer';\nimport { JXON } from '../util/jxon';\nimport { geoExtent } from '../geo';\nimport { osmChangeset } from '../osm';\nimport { svgIcon } from '../svg/icon';\nimport { utilDetect } from '../util/detect';\n\nimport {\n utilEntityOrMemberSelector,\n utilKeybinding,\n utilRebind,\n utilWrap\n} from '../util';\n\n\nexport function uiConflicts(context) {\n var dispatch = d3_dispatch('cancel', 'save');\n var keybinding = utilKeybinding('conflicts');\n var _origChanges;\n var _conflictList;\n var _shownConflictIndex;\n\n\n function keybindingOn() {\n d3_select(document)\n .call(keybinding.on('⎋', cancel, true));\n }\n\n function keybindingOff() {\n d3_select(document)\n .call(keybinding.unbind);\n }\n\n function tryAgain() {\n keybindingOff();\n dispatch.call('save');\n }\n\n function cancel() {\n keybindingOff();\n dispatch.call('cancel');\n }\n\n\n function conflicts(selection) {\n keybindingOn();\n\n var headerEnter = selection.selectAll('.header')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'header fillL');\n\n headerEnter\n .append('button')\n .attr('class', 'fr')\n .on('click', cancel)\n .call(svgIcon('#iD-icon-close'));\n\n headerEnter\n .append('h3')\n .text(t('save.conflict.header'));\n\n var bodyEnter = selection.selectAll('.body')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'body fillL');\n\n var conflictsHelpEnter = bodyEnter\n .append('div')\n .attr('class', 'conflicts-help')\n .text(t('save.conflict.help'));\n\n\n // Download changes link\n var detected = utilDetect();\n var changeset = new osmChangeset();\n\n delete changeset.id; // Export without changeset_id\n\n var data = JXON.stringify(changeset.osmChangeJXON(_origChanges));\n var blob = new Blob([data], { type: 'text/xml;charset=utf-8;' });\n var fileName = 'changes.osc';\n\n var linkEnter = conflictsHelpEnter.selectAll('.download-changes')\n .append('a')\n .attr('class', 'download-changes');\n\n if (detected.download) { // All except IE11 and Edge\n linkEnter // download the data as a file\n .attr('href', window.URL.createObjectURL(blob))\n .attr('download', fileName);\n\n } else { // IE11 and Edge\n linkEnter // open data uri in a new tab\n .attr('target', '_blank')\n .on('click.download', function() {\n navigator.msSaveBlob(blob, fileName);\n });\n }\n\n linkEnter\n .call(svgIcon('#iD-icon-load', 'inline'))\n .append('span')\n .text(t('save.conflict.download_changes'));\n\n\n bodyEnter\n .append('div')\n .attr('class', 'conflict-container fillL3')\n .call(showConflict, 0);\n\n bodyEnter\n .append('div')\n .attr('class', 'conflicts-done')\n .attr('opacity', 0)\n .style('display', 'none')\n .text(t('save.conflict.done'));\n\n var buttonsEnter = bodyEnter\n .append('div')\n .attr('class','buttons col12 joined conflicts-buttons');\n\n buttonsEnter\n .append('button')\n .attr('disabled', _conflictList.length > 1)\n .attr('class', 'action conflicts-button col6')\n .text(t('save.title'))\n .on('click.try_again', tryAgain);\n\n buttonsEnter\n .append('button')\n .attr('class', 'secondary-action conflicts-button col6')\n .text(t('confirm.cancel'))\n .on('click.cancel', cancel);\n }\n\n\n function showConflict(selection, index) {\n index = utilWrap(index, _conflictList.length);\n _shownConflictIndex = index;\n\n var parent = d3_select(selection.node().parentNode);\n\n // enable save button if this is the last conflict being reviewed..\n if (index === _conflictList.length - 1) {\n window.setTimeout(function() {\n parent.select('.conflicts-button')\n .attr('disabled', null);\n\n parent.select('.conflicts-done')\n .transition()\n .attr('opacity', 1)\n .style('display', 'block');\n }, 250);\n }\n\n var conflict = selection\n .selectAll('.conflict')\n .data([_conflictList[index]]);\n\n conflict.exit()\n .remove();\n\n var conflictEnter = conflict.enter()\n .append('div')\n .attr('class', 'conflict');\n\n conflictEnter\n .append('h4')\n .attr('class', 'conflict-count')\n .text(t('save.conflict.count', { num: index + 1, total: _conflictList.length }));\n\n conflictEnter\n .append('a')\n .attr('class', 'conflict-description')\n .attr('href', '#')\n .text(function(d) { return d.name; })\n .on('click', function(d) {\n d3_event.preventDefault();\n zoomToEntity(d.id);\n });\n\n var details = conflictEnter\n .append('div')\n .attr('class', 'conflict-detail-container');\n\n details\n .append('ul')\n .attr('class', 'conflict-detail-list')\n .selectAll('li')\n .data(function(d) { return d.details || []; })\n .enter()\n .append('li')\n .attr('class', 'conflict-detail-item')\n .html(function(d) { return d; });\n\n details\n .append('div')\n .attr('class', 'conflict-choices')\n .call(addChoices);\n\n details\n .append('div')\n .attr('class', 'conflict-nav-buttons joined cf')\n .selectAll('button')\n .data(['previous', 'next'])\n .enter()\n .append('button')\n .text(function(d) { return t('save.conflict.' + d); })\n .attr('class', 'conflict-nav-button action col6')\n .attr('disabled', function(d, i) {\n return (i === 0 && index === 0) ||\n (i === 1 && index === _conflictList.length - 1) || null;\n })\n .on('click', function(d, i) {\n d3_event.preventDefault();\n\n var container = parent.selectAll('.conflict-container');\n var sign = (i === 0 ? -1 : 1);\n\n container\n .selectAll('.conflict')\n .remove();\n\n container\n .call(showConflict, index + sign);\n });\n\n }\n\n\n function addChoices(selection) {\n var choices = selection\n .append('ul')\n .attr('class', 'layer-list')\n .selectAll('li')\n .data(function(d) { return d.choices || []; });\n\n // enter\n var choicesEnter = choices.enter()\n .append('li')\n .attr('class', 'layer');\n\n var labelEnter = choicesEnter\n .append('label');\n\n labelEnter\n .append('input')\n .attr('type', 'radio')\n .attr('name', function(d) { return d.id; })\n .on('change', function(d, i) {\n var ul = this.parentNode.parentNode.parentNode;\n ul.__data__.chosen = i;\n choose(ul, d);\n });\n\n labelEnter\n .append('span')\n .text(function(d) { return d.text; });\n\n // update\n choicesEnter\n .merge(choices)\n .each(function(d, i) {\n var ul = this.parentNode;\n if (ul.__data__.chosen === i) {\n choose(ul, d);\n }\n });\n }\n\n\n function choose(ul, datum) {\n if (d3_event) d3_event.preventDefault();\n\n d3_select(ul)\n .selectAll('li')\n .classed('active', function(d) { return d === datum; })\n .selectAll('input')\n .property('checked', function(d) { return d === datum; });\n\n var extent = geoExtent();\n var entity;\n\n entity = context.graph().hasEntity(datum.id);\n if (entity) extent._extend(entity.extent(context.graph()));\n\n datum.action();\n\n entity = context.graph().hasEntity(datum.id);\n if (entity) extent._extend(entity.extent(context.graph()));\n\n zoomToEntity(datum.id, extent);\n }\n\n\n function zoomToEntity(id, extent) {\n context.surface().selectAll('.hover')\n .classed('hover', false);\n\n var entity = context.graph().hasEntity(id);\n if (entity) {\n if (extent) {\n context.map().trimmedExtent(extent);\n } else {\n context.map().zoomToEase(entity);\n }\n context.surface().selectAll(utilEntityOrMemberSelector([entity.id], context.graph()))\n .classed('hover', true);\n }\n }\n\n\n // The conflict list should be an array of objects like:\n // {\n // id: id,\n // name: entityName(local),\n // details: merge.conflicts(),\n // chosen: 1,\n // choices: [\n // choice(id, keepMine, forceLocal),\n // choice(id, keepTheirs, forceRemote)\n // ]\n // }\n conflicts.conflictList = function(_) {\n if (!arguments.length) return _conflictList;\n _conflictList = _;\n return conflicts;\n };\n\n\n conflicts.origChanges = function(_) {\n if (!arguments.length) return _origChanges;\n _origChanges = _;\n return conflicts;\n };\n\n\n conflicts.shownEntityIds = function() {\n if (_conflictList && typeof _shownConflictIndex === 'number') {\n return [_conflictList[_shownConflictIndex].id];\n }\n return [];\n };\n\n\n return utilRebind(conflicts, dispatch, 'on');\n}\n","import { t } from '../core/localizer';\nimport { uiModal } from './modal';\n\n\nexport function uiConfirm(selection) {\n var modalSelection = uiModal(selection);\n\n modalSelection.select('.modal')\n .classed('modal-alert', true);\n\n var section = modalSelection.select('.content');\n\n section.append('div')\n .attr('class', 'modal-section header');\n\n section.append('div')\n .attr('class', 'modal-section message-text');\n\n var buttons = section.append('div')\n .attr('class', 'modal-section buttons cf');\n\n\n modalSelection.okButton = function() {\n buttons\n .append('button')\n .attr('class', 'button ok-button action')\n .on('click.confirm', function() {\n modalSelection.remove();\n })\n .text(t('confirm.okay'))\n .node()\n .focus();\n\n return modalSelection;\n };\n\n\n return modalSelection;\n}\n","import { event as d3_event, select as d3_select } from 'd3-selection';\nimport { utilFunctor } from '../util/util';\n\nvar _popoverID = 0;\n\nexport function uiPopover(klass) {\n var _id = _popoverID++;\n var _anchorSelection = d3_select(null);\n var popover = function(selection) {\n _anchorSelection = selection;\n selection.each(setup);\n };\n var _animation = utilFunctor(false);\n var _placement = utilFunctor('top'); // top, bottom, left, right\n var _alignment = utilFunctor('center'); // leading, center, trailing\n var _scrollContainer = utilFunctor(d3_select(null));\n var _content;\n var _displayType = utilFunctor('');\n var _hasArrow = utilFunctor(true);\n\n // use pointer events on supported platforms; fallback to mouse events\n var _pointerPrefix = 'PointerEvent' in window ? 'pointer' : 'mouse';\n\n popover.displayType = function(val) {\n if (arguments.length) {\n _displayType = utilFunctor(val);\n return popover;\n } else {\n return _displayType;\n }\n };\n\n popover.hasArrow = function(val) {\n if (arguments.length) {\n _hasArrow = utilFunctor(val);\n return popover;\n } else {\n return _hasArrow;\n }\n };\n\n popover.placement = function(val) {\n if (arguments.length) {\n _placement = utilFunctor(val);\n return popover;\n } else {\n return _placement;\n }\n };\n\n popover.alignment = function(val) {\n if (arguments.length) {\n _alignment = utilFunctor(val);\n return popover;\n } else {\n return _alignment;\n }\n };\n\n popover.scrollContainer = function(val) {\n if (arguments.length) {\n _scrollContainer = utilFunctor(val);\n return popover;\n } else {\n return _scrollContainer;\n }\n };\n\n popover.content = function(val) {\n if (arguments.length) {\n _content = val;\n return popover;\n } else {\n return _content;\n }\n };\n\n popover.isShown = function() {\n var popoverSelection = _anchorSelection.select('.popover-' + _id);\n return !popoverSelection.empty() && popoverSelection.classed('in');\n };\n\n popover.show = function() {\n _anchorSelection.each(show);\n };\n\n popover.updateContent = function() {\n _anchorSelection.each(updateContent);\n };\n\n popover.hide = function() {\n _anchorSelection.each(hide);\n };\n\n popover.toggle = function() {\n _anchorSelection.each(toggle);\n };\n\n popover.destroy = function(selection, selector) {\n // by default, just destroy the current popover\n selector = selector || '.popover-' + _id;\n\n selection\n .on(_pointerPrefix + 'enter.popover', null)\n .on(_pointerPrefix + 'leave.popover', null)\n .on(_pointerPrefix + 'up.popover', null)\n .on(_pointerPrefix + 'down.popover', null)\n .on('click.popover', null)\n .attr('title', function() {\n return this.getAttribute('data-original-title') || this.getAttribute('title');\n })\n .attr('data-original-title', null)\n .selectAll(selector)\n .remove();\n };\n\n\n popover.destroyAny = function(selection) {\n selection.call(popover.destroy, '.popover');\n };\n\n function setup() {\n var anchor = d3_select(this);\n var animate = _animation.apply(this, arguments);\n var popoverSelection = anchor.selectAll('.popover-' + _id)\n .data([0]);\n\n\n var enter = popoverSelection.enter()\n .append('div')\n .attr('class', 'popover popover-' + _id + ' ' + (klass ? klass : ''))\n .classed('arrowed', _hasArrow.apply(this, arguments));\n\n enter\n .append('div')\n .attr('class', 'popover-arrow');\n\n enter\n .append('div')\n .attr('class', 'popover-inner');\n\n popoverSelection = enter\n .merge(popoverSelection);\n\n if (animate) {\n popoverSelection.classed('fade', true);\n }\n\n var display = _displayType.apply(this, arguments);\n\n if (display === 'hover') {\n var _lastNonMouseEnterTime;\n anchor.on(_pointerPrefix + 'enter.popover', function() {\n\n if (d3_event.pointerType) {\n if (d3_event.pointerType !== 'mouse') {\n _lastNonMouseEnterTime = d3_event.timeStamp;\n // only allow hover behavior for mouse input\n return;\n } else if (_lastNonMouseEnterTime &&\n d3_event.timeStamp - _lastNonMouseEnterTime < 1500) {\n // HACK: iOS 13.4 sends an erroneous `mouse` type pointerenter\n // event for non-mouse interactions right after sending\n // the correct type pointerenter event. Workaround by discarding\n // any mouse event that occurs immediately after a non-mouse event.\n return;\n }\n }\n\n // don't show if buttons are pressed, e.g. during click and drag of map\n if (d3_event.buttons !== 0) return;\n\n show.apply(this, arguments);\n });\n anchor.on(_pointerPrefix + 'leave.popover', function() {\n hide.apply(this, arguments);\n });\n\n } else if (display === 'clickFocus') {\n anchor\n .on(_pointerPrefix + 'down.popover', function() {\n d3_event.preventDefault();\n d3_event.stopPropagation();\n })\n .on(_pointerPrefix + 'up.popover', function() {\n d3_event.preventDefault();\n d3_event.stopPropagation();\n })\n .on('click.popover', toggle);\n\n popoverSelection\n .attr('tabindex', 0)\n .on('blur.popover', function() {\n anchor.each(function() {\n hide.apply(this, arguments);\n });\n });\n }\n }\n\n\n function show() {\n var anchor = d3_select(this);\n var popoverSelection = anchor.selectAll('.popover-' + _id);\n\n if (popoverSelection.empty()) {\n // popover was removed somehow, put it back\n anchor.call(popover.destroy);\n anchor.each(setup);\n popoverSelection = anchor.selectAll('.popover-' + _id);\n }\n\n popoverSelection.classed('in', true);\n\n var displayType = _displayType.apply(this, arguments);\n if (displayType === 'clickFocus') {\n anchor.classed('active', true);\n popoverSelection.node().focus();\n }\n\n anchor.each(updateContent);\n }\n\n function updateContent() {\n var anchor = d3_select(this);\n\n if (_content) {\n anchor.selectAll('.popover-' + _id + ' > .popover-inner')\n .call(_content.apply(this, arguments));\n }\n\n updatePosition.apply(this, arguments);\n // hack: update multiple times to fix instances where the absolute offset is\n // set before the dynamic popover size is calculated by the browser\n updatePosition.apply(this, arguments);\n updatePosition.apply(this, arguments);\n }\n\n\n function updatePosition() {\n\n var anchor = d3_select(this);\n var popoverSelection = anchor.selectAll('.popover-' + _id);\n\n var scrollContainer = _scrollContainer && _scrollContainer.apply(this, arguments);\n var scrollNode = scrollContainer && !scrollContainer.empty() && scrollContainer.node();\n var scrollLeft = scrollNode ? scrollNode.scrollLeft : 0;\n var scrollTop = scrollNode ? scrollNode.scrollTop : 0;\n\n var placement = _placement.apply(this, arguments);\n popoverSelection\n .classed('left', false)\n .classed('right', false)\n .classed('top', false)\n .classed('bottom', false)\n .classed(placement, true);\n\n var alignment = _alignment.apply(this, arguments);\n var alignFactor = 0.5;\n if (alignment === 'leading') {\n alignFactor = 0;\n } else if (alignment === 'trailing') {\n alignFactor = 1;\n }\n var anchorFrame = getFrame(anchor.node());\n var popoverFrame = getFrame(popoverSelection.node());\n var position;\n\n switch (placement) {\n case 'top':\n position = {\n x: anchorFrame.x + (anchorFrame.w - popoverFrame.w) * alignFactor,\n y: anchorFrame.y - popoverFrame.h\n };\n break;\n case 'bottom':\n position = {\n x: anchorFrame.x + (anchorFrame.w - popoverFrame.w) * alignFactor,\n y: anchorFrame.y + anchorFrame.h\n };\n break;\n case 'left':\n position = {\n x: anchorFrame.x - popoverFrame.w,\n y: anchorFrame.y + (anchorFrame.h - popoverFrame.h) * alignFactor\n };\n break;\n case 'right':\n position = {\n x: anchorFrame.x + anchorFrame.w,\n y: anchorFrame.y + (anchorFrame.h - popoverFrame.h) * alignFactor\n };\n break;\n }\n\n if (position) {\n\n if (scrollNode && (placement === 'top' || placement === 'bottom')) {\n\n var initialPosX = position.x;\n\n if (position.x + popoverFrame.w > scrollNode.offsetWidth - 10) {\n position.x = scrollNode.offsetWidth - 10 - popoverFrame.w;\n } else if (position.x < 10) {\n position.x = 10;\n }\n\n var arrow = anchor.selectAll('.popover-' + _id + ' > .popover-arrow');\n // keep the arrow centered on the button, or as close as possible\n var arrowPosX = Math.min(Math.max(popoverFrame.w / 2 - (position.x - initialPosX), 10), popoverFrame.w - 10);\n arrow.style('left', ~~arrowPosX + 'px');\n }\n\n popoverSelection.style('left', ~~position.x + 'px').style('top', ~~position.y + 'px');\n } else {\n popoverSelection.style('left', null).style('top', null);\n }\n\n function getFrame(node) {\n var positionStyle = d3_select(node).style('position');\n if (positionStyle === 'absolute' || positionStyle === 'static') {\n return {\n x: node.offsetLeft - scrollLeft,\n y: node.offsetTop - scrollTop,\n w: node.offsetWidth,\n h: node.offsetHeight\n };\n } else {\n return {\n x: 0,\n y: 0,\n w: node.offsetWidth,\n h: node.offsetHeight\n };\n }\n }\n }\n\n\n function hide() {\n var anchor = d3_select(this);\n if (_displayType.apply(this, arguments) === 'clickFocus') {\n anchor.classed('active', false);\n }\n anchor.selectAll('.popover-' + _id).classed('in', false);\n }\n\n\n function toggle() {\n if (d3_select(this).select('.popover-' + _id).classed('in')) {\n hide.apply(this, arguments);\n } else {\n show.apply(this, arguments);\n }\n }\n\n\n return popover;\n}\n","import { utilFunctor } from '../util/util';\nimport { t } from '../core/localizer';\nimport { uiPopover } from './popover';\n\nexport function uiTooltip(klass) {\n\n var tooltip = uiPopover((klass || '') + ' tooltip')\n .displayType('hover');\n\n var _title = function() {\n var title = this.getAttribute('data-original-title');\n if (title) {\n return title;\n } else {\n title = this.getAttribute('title');\n this.removeAttribute('title');\n this.setAttribute('data-original-title', title);\n }\n return title;\n };\n\n var _heading = utilFunctor(null);\n var _keys = utilFunctor(null);\n\n tooltip.title = function(val) {\n if (!arguments.length) return _title;\n _title = utilFunctor(val);\n return tooltip;\n };\n\n tooltip.heading = function(val) {\n if (!arguments.length) return _heading;\n _heading = utilFunctor(val);\n return tooltip;\n };\n\n tooltip.keys = function(val) {\n if (!arguments.length) return _keys;\n _keys = utilFunctor(val);\n return tooltip;\n };\n\n tooltip.content(function() {\n var heading = _heading.apply(this, arguments);\n var text = _title.apply(this, arguments);\n var keys = _keys.apply(this, arguments);\n\n return function(selection) {\n\n var headingSelect = selection\n .selectAll('.tooltip-heading')\n .data(heading ? [heading] :[]);\n\n headingSelect.exit()\n .remove();\n\n headingSelect.enter()\n .append('div')\n .attr('class', 'tooltip-heading')\n .merge(headingSelect)\n .html(heading);\n\n var textSelect = selection\n .selectAll('.tooltip-text')\n .data(text ? [text] :[]);\n\n textSelect.exit()\n .remove();\n\n textSelect.enter()\n .append('div')\n .attr('class', 'tooltip-text')\n .merge(textSelect)\n .html(text);\n\n var keyhintWrap = selection\n .selectAll('.keyhint-wrap')\n .data(keys && keys.length ? [0] : []);\n\n keyhintWrap.exit()\n .remove();\n\n var keyhintWrapEnter = keyhintWrap.enter()\n .append('div')\n .attr('class', 'keyhint-wrap');\n\n keyhintWrapEnter\n .append('span')\n .html(t('tooltip_keyhint'));\n\n keyhintWrap = keyhintWrapEnter.merge(keyhintWrap);\n\n keyhintWrap.selectAll('kbd.shortcut')\n .data(keys && keys.length ? keys : [])\n .enter()\n .append('kbd')\n .attr('class', 'shortcut')\n .html(function(d) {\n return d;\n });\n }; \n });\n\n return tooltip;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { event as d3_event, select as d3_select } from 'd3-selection';\nimport { utilGetSetValue, utilRebind, utilTriggerEvent } from '../util';\n\n\n// This code assumes that the combobox values will not have duplicate entries.\n// It is keyed on the `value` of the entry. Data should be an array of objects like:\n// [{\n// value: 'display text', // required\n// title: 'hover text' // optional\n// }, ...]\n\nvar _comboHideTimerID;\n\nexport function uiCombobox(context, klass) {\n var dispatch = d3_dispatch('accept', 'cancel');\n var container = context.container();\n\n var _suggestions = [];\n var _data = [];\n var _fetched = {};\n var _selected = null;\n var _canAutocomplete = true;\n var _caseSensitive = false;\n var _cancelFetch = false;\n var _minItems = 2;\n var _tDown = 0;\n var _mouseEnterHandler, _mouseLeaveHandler;\n\n var _fetcher = function(val, cb) {\n cb(_data.filter(function(d) {\n var terms = d.terms || [];\n terms.push(d.value);\n return terms.some(function(term) {\n return term\n .toString()\n .toLowerCase()\n .indexOf(val.toLowerCase()) !== -1;\n });\n }));\n };\n\n var combobox = function(input, attachTo) {\n if (!input || input.empty()) return;\n\n input\n .classed('combobox-input', true)\n .on('focus.combo-input', focus)\n .on('blur.combo-input', blur)\n .on('keydown.combo-input', keydown)\n .on('keyup.combo-input', keyup)\n .on('input.combo-input', change)\n .on('mousedown.combo-input', mousedown)\n .each(function() {\n var parent = this.parentNode;\n var sibling = this.nextSibling;\n\n d3_select(parent).selectAll('.combobox-caret')\n .filter(function(d) { return d === input.node(); })\n .data([input.node()])\n .enter()\n .insert('div', function() { return sibling; })\n .attr('class', 'combobox-caret')\n .on('mousedown.combo-caret', function() {\n d3_event.preventDefault(); // don't steal focus from input\n input.node().focus(); // focus the input as if it was clicked\n mousedown();\n })\n .on('mouseup.combo-caret', function() {\n d3_event.preventDefault(); // don't steal focus from input\n mouseup();\n });\n });\n\n\n function mousedown() {\n if (d3_event.button !== 0) return; // left click only\n _tDown = +new Date();\n\n // clear selection\n var start = input.property('selectionStart');\n var end = input.property('selectionEnd');\n if (start !== end) {\n var val = utilGetSetValue(input);\n input.node().setSelectionRange(val.length, val.length);\n return;\n }\n\n input.on('mouseup.combo-input', mouseup);\n }\n\n\n function mouseup() {\n input.on('mouseup.combo-input', null);\n if (d3_event.button !== 0) return; // left click only\n if (input.node() !== document.activeElement) return; // exit if this input is not focused\n\n var start = input.property('selectionStart');\n var end = input.property('selectionEnd');\n if (start !== end) return; // exit if user is selecting\n\n // not showing or showing for a different field - try to show it.\n var combo = container.selectAll('.combobox');\n if (combo.empty() || combo.datum() !== input.node()) {\n var tOrig = _tDown;\n window.setTimeout(function() {\n if (tOrig !== _tDown) return; // exit if user double clicked\n fetchComboData('', function() {\n show();\n render();\n });\n }, 250);\n\n } else {\n hide();\n }\n }\n\n\n function focus() {\n fetchComboData(''); // prefetch values (may warm taginfo cache)\n }\n\n\n function blur() {\n _comboHideTimerID = window.setTimeout(hide, 75);\n }\n\n\n function show() {\n hide(); // remove any existing\n\n container\n .insert('div', ':first-child')\n .datum(input.node())\n .attr('class', 'combobox' + (klass ? ' combobox-' + klass : ''))\n .style('position', 'absolute')\n .style('display', 'block')\n .style('left', '0px')\n .on('mousedown.combo-container', function () {\n // prevent moving focus out of the input field\n d3_event.preventDefault();\n });\n\n container\n .on('scroll.combo-scroll', render, true);\n }\n\n\n function hide() {\n if (_comboHideTimerID) {\n window.clearTimeout(_comboHideTimerID);\n _comboHideTimerID = undefined;\n }\n\n container.selectAll('.combobox')\n .remove();\n\n container\n .on('scroll.combo-scroll', null);\n }\n\n\n function keydown() {\n var shown = !container.selectAll('.combobox').empty();\n var tagName = input.node() ? input.node().tagName.toLowerCase() : '';\n\n switch (d3_event.keyCode) {\n case 8: // ⌫ Backspace\n case 46: // ⌦ Delete\n d3_event.stopPropagation();\n _selected = null;\n render();\n input.on('input.combo-input', function() {\n var start = input.property('selectionStart');\n input.node().setSelectionRange(start, start);\n input.on('input.combo-input', change);\n });\n break;\n\n case 9: // ⇥ Tab\n accept();\n break;\n\n case 13: // ↩ Return\n d3_event.preventDefault();\n d3_event.stopPropagation();\n break;\n\n case 38: // ↑ Up arrow\n if (tagName === 'textarea' && !shown) return;\n d3_event.preventDefault();\n if (tagName === 'input' && !shown) {\n show();\n }\n nav(-1);\n break;\n\n case 40: // ↓ Down arrow\n if (tagName === 'textarea' && !shown) return;\n d3_event.preventDefault();\n if (tagName === 'input' && !shown) {\n show();\n }\n nav(+1);\n break;\n }\n }\n\n\n function keyup() {\n switch (d3_event.keyCode) {\n case 27: // ⎋ Escape\n cancel();\n break;\n\n case 13: // ↩ Return\n accept();\n break;\n }\n }\n\n\n // Called whenever the input value is changed (e.g. on typing)\n function change() {\n fetchComboData(value(), function() {\n _selected = null;\n var val = input.property('value');\n\n if (_suggestions.length) {\n if (input.property('selectionEnd') === val.length) {\n _selected = tryAutocomplete();\n }\n\n if (!_selected) {\n _selected = val;\n }\n }\n\n if (val.length) {\n var combo = container.selectAll('.combobox');\n if (combo.empty()) {\n show();\n }\n } else {\n hide();\n }\n\n render();\n });\n }\n\n\n // Called when the user presses up/down arrows to navigate the list\n function nav(dir) {\n if (_suggestions.length) {\n // try to determine previously selected index..\n var index = -1;\n for (var i = 0; i < _suggestions.length; i++) {\n if (_selected && _suggestions[i].value === _selected) {\n index = i;\n break;\n }\n }\n\n // pick new _selected\n index = Math.max(Math.min(index + dir, _suggestions.length - 1), 0);\n _selected = _suggestions[index].value;\n input.property('value', _selected);\n }\n\n render();\n ensureVisible();\n }\n\n\n function ensureVisible() {\n var combo = container.selectAll('.combobox');\n if (combo.empty()) return;\n\n var containerRect = container.node().getBoundingClientRect();\n var comboRect = combo.node().getBoundingClientRect();\n\n if (comboRect.bottom > containerRect.bottom) {\n var node = attachTo ? attachTo.node() : input.node();\n node.scrollIntoView({ behavior: 'instant', block: 'center' });\n render();\n }\n\n // https://stackoverflow.com/questions/11039885/scrollintoview-causing-the-whole-page-to-move\n var selected = combo.selectAll('.combobox-option.selected').node();\n if (selected) {\n selected.scrollIntoView({ behavior: 'smooth', block: 'nearest' });\n }\n }\n\n\n function value() {\n var value = input.property('value');\n var start = input.property('selectionStart');\n var end = input.property('selectionEnd');\n\n if (start && end) {\n value = value.substring(0, start);\n }\n\n return value;\n }\n\n\n function fetchComboData(v, cb) {\n _cancelFetch = false;\n\n _fetcher.call(input, v, function(results) {\n // already chose a value, don't overwrite or autocomplete it\n if (_cancelFetch) return;\n\n _suggestions = results;\n results.forEach(function(d) { _fetched[d.value] = d; });\n\n if (cb) {\n cb();\n }\n });\n }\n\n\n function tryAutocomplete() {\n if (!_canAutocomplete) return;\n\n var val = _caseSensitive ? value() : value().toLowerCase();\n if (!val) return;\n\n // Don't autocomplete if user is typing a number - #4935\n if (!isNaN(parseFloat(val)) && isFinite(val)) return;\n\n var bestIndex = -1;\n for (var i = 0; i < _suggestions.length; i++) {\n var suggestion = _suggestions[i].value;\n var compare = _caseSensitive ? suggestion : suggestion.toLowerCase();\n\n // if search string matches suggestion exactly, pick it..\n if (compare === val) {\n bestIndex = i;\n break;\n\n // otherwise lock in the first result that starts with the search string..\n } else if (bestIndex === -1 && compare.indexOf(val) === 0) {\n bestIndex = i;\n }\n }\n\n if (bestIndex !== -1) {\n var bestVal = _suggestions[bestIndex].value;\n input.property('value', bestVal);\n input.node().setSelectionRange(val.length, bestVal.length);\n return bestVal;\n }\n }\n\n\n function render() {\n if (_suggestions.length < _minItems || document.activeElement !== input.node()) {\n hide();\n return;\n }\n\n var shown = !container.selectAll('.combobox').empty();\n if (!shown) return;\n\n var combo = container.selectAll('.combobox');\n var options = combo.selectAll('.combobox-option')\n .data(_suggestions, function(d) { return d.value; });\n\n options.exit()\n .remove();\n\n // enter/update\n options.enter()\n .append('a')\n .attr('class', 'combobox-option')\n .attr('title', function(d) { return d.title; })\n .text(function(d) { return d.display || d.value; })\n .on('mouseenter', _mouseEnterHandler)\n .on('mouseleave', _mouseLeaveHandler)\n .merge(options)\n .classed('selected', function(d) { return d.value === _selected; })\n .on('click.combo-option', accept)\n .order();\n\n var node = attachTo ? attachTo.node() : input.node();\n var containerRect = container.node().getBoundingClientRect();\n var rect = node.getBoundingClientRect();\n\n combo\n .style('left', (rect.left + 5 - containerRect.left) + 'px')\n .style('width', (rect.width - 10) + 'px')\n .style('top', (rect.height + rect.top - containerRect.top) + 'px');\n }\n\n\n // Dispatches an 'accept' event\n // Then hides the combobox.\n function accept(d) {\n _cancelFetch = true;\n var thiz = input.node();\n\n if (d) { // user clicked on a suggestion\n utilGetSetValue(input, d.value); // replace field contents\n utilTriggerEvent(input, 'change');\n }\n\n // clear (and keep) selection\n var val = utilGetSetValue(input);\n thiz.setSelectionRange(val.length, val.length);\n\n d = _fetched[val];\n dispatch.call('accept', thiz, d, val);\n hide();\n }\n\n\n // Dispatches an 'cancel' event\n // Then hides the combobox.\n function cancel() {\n _cancelFetch = true;\n var thiz = input.node();\n\n // clear (and remove) selection, and replace field contents\n var val = utilGetSetValue(input);\n var start = input.property('selectionStart');\n var end = input.property('selectionEnd');\n val = val.slice(0, start) + val.slice(end);\n utilGetSetValue(input, val);\n thiz.setSelectionRange(val.length, val.length);\n\n dispatch.call('cancel', thiz);\n hide();\n }\n\n };\n\n\n combobox.canAutocomplete = function(val) {\n if (!arguments.length) return _canAutocomplete;\n _canAutocomplete = val;\n return combobox;\n };\n\n combobox.caseSensitive = function(val) {\n if (!arguments.length) return _caseSensitive;\n _caseSensitive = val;\n return combobox;\n };\n\n combobox.data = function(val) {\n if (!arguments.length) return _data;\n _data = val;\n return combobox;\n };\n\n combobox.fetcher = function(val) {\n if (!arguments.length) return _fetcher;\n _fetcher = val;\n return combobox;\n };\n\n combobox.minItems = function(val) {\n if (!arguments.length) return _minItems;\n _minItems = val;\n return combobox;\n };\n\n combobox.itemsMouseEnter = function(val) {\n if (!arguments.length) return _mouseEnterHandler;\n _mouseEnterHandler = val;\n return combobox;\n };\n\n combobox.itemsMouseLeave = function(val) {\n if (!arguments.length) return _mouseLeaveHandler;\n _mouseLeaveHandler = val;\n return combobox;\n };\n\n return utilRebind(combobox, dispatch, 'on');\n}\n\n\nuiCombobox.off = function(input, context) {\n input\n .on('focus.combo-input', null)\n .on('blur.combo-input', null)\n .on('keydown.combo-input', null)\n .on('keyup.combo-input', null)\n .on('input.combo-input', null)\n .on('mousedown.combo-input', null)\n .on('mouseup.combo-input', null);\n\n\n context.container()\n .on('scroll.combo-scroll', null);\n};\n","function getDefaults() {\n return {\n baseUrl: null,\n breaks: false,\n gfm: true,\n headerIds: true,\n headerPrefix: '',\n highlight: null,\n langPrefix: 'language-',\n mangle: true,\n pedantic: false,\n renderer: null,\n sanitize: false,\n sanitizer: null,\n silent: false,\n smartLists: false,\n smartypants: false,\n tokenizer: null,\n xhtml: false\n };\n}\n\nfunction changeDefaults(newDefaults) {\n module.exports.defaults = newDefaults;\n}\n\nmodule.exports = {\n defaults: getDefaults(),\n getDefaults,\n changeDefaults\n};\n","/**\n * Helpers\n */\nconst escapeTest = /[&<>\"']/;\nconst escapeReplace = /[&<>\"']/g;\nconst escapeTestNoEncode = /[<>\"']|&(?!#?\\w+;)/;\nconst escapeReplaceNoEncode = /[<>\"']|&(?!#?\\w+;)/g;\nconst escapeReplacements = {\n '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": '''\n};\nconst getEscapeReplacement = (ch) => escapeReplacements[ch];\nfunction escape(html, encode) {\n if (encode) {\n if (escapeTest.test(html)) {\n return html.replace(escapeReplace, getEscapeReplacement);\n }\n } else {\n if (escapeTestNoEncode.test(html)) {\n return html.replace(escapeReplaceNoEncode, getEscapeReplacement);\n }\n }\n\n return html;\n}\n\nconst unescapeTest = /&(#(?:\\d+)|(?:#x[0-9A-Fa-f]+)|(?:\\w+));?/ig;\n\nfunction unescape(html) {\n // explicitly match decimal, hex, and named HTML entities\n return html.replace(unescapeTest, (_, n) => {\n n = n.toLowerCase();\n if (n === 'colon') return ':';\n if (n.charAt(0) === '#') {\n return n.charAt(1) === 'x'\n ? String.fromCharCode(parseInt(n.substring(2), 16))\n : String.fromCharCode(+n.substring(1));\n }\n return '';\n });\n}\n\nconst caret = /(^|[^\\[])\\^/g;\nfunction edit(regex, opt) {\n regex = regex.source || regex;\n opt = opt || '';\n const obj = {\n replace: (name, val) => {\n val = val.source || val;\n val = val.replace(caret, '$1');\n regex = regex.replace(name, val);\n return obj;\n },\n getRegex: () => {\n return new RegExp(regex, opt);\n }\n };\n return obj;\n}\n\nconst nonWordAndColonTest = /[^\\w:]/g;\nconst originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;\nfunction cleanUrl(sanitize, base, href) {\n if (sanitize) {\n let prot;\n try {\n prot = decodeURIComponent(unescape(href))\n .replace(nonWordAndColonTest, '')\n .toLowerCase();\n } catch (e) {\n return null;\n }\n if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {\n return null;\n }\n }\n if (base && !originIndependentUrl.test(href)) {\n href = resolveUrl(base, href);\n }\n try {\n href = encodeURI(href).replace(/%25/g, '%');\n } catch (e) {\n return null;\n }\n return href;\n}\n\nconst baseUrls = {};\nconst justDomain = /^[^:]+:\\/*[^/]*$/;\nconst protocol = /^([^:]+:)[\\s\\S]*$/;\nconst domain = /^([^:]+:\\/*[^/]*)[\\s\\S]*$/;\n\nfunction resolveUrl(base, href) {\n if (!baseUrls[' ' + base]) {\n // we can ignore everything in base after the last slash of its path component,\n // but we might need to add _that_\n // https://tools.ietf.org/html/rfc3986#section-3\n if (justDomain.test(base)) {\n baseUrls[' ' + base] = base + '/';\n } else {\n baseUrls[' ' + base] = rtrim(base, '/', true);\n }\n }\n base = baseUrls[' ' + base];\n const relativeBase = base.indexOf(':') === -1;\n\n if (href.substring(0, 2) === '//') {\n if (relativeBase) {\n return href;\n }\n return base.replace(protocol, '$1') + href;\n } else if (href.charAt(0) === '/') {\n if (relativeBase) {\n return href;\n }\n return base.replace(domain, '$1') + href;\n } else {\n return base + href;\n }\n}\n\nconst noopTest = { exec: function noopTest() {} };\n\nfunction merge(obj) {\n let i = 1,\n target,\n key;\n\n for (; i < arguments.length; i++) {\n target = arguments[i];\n for (key in target) {\n if (Object.prototype.hasOwnProperty.call(target, key)) {\n obj[key] = target[key];\n }\n }\n }\n\n return obj;\n}\n\nfunction splitCells(tableRow, count) {\n // ensure that every cell-delimiting pipe has a space\n // before it to distinguish it from an escaped pipe\n const row = tableRow.replace(/\\|/g, (match, offset, str) => {\n let escaped = false,\n curr = offset;\n while (--curr >= 0 && str[curr] === '\\\\') escaped = !escaped;\n if (escaped) {\n // odd number of slashes means | is escaped\n // so we leave it alone\n return '|';\n } else {\n // add space before unescaped |\n return ' |';\n }\n }),\n cells = row.split(/ \\|/);\n let i = 0;\n\n if (cells.length > count) {\n cells.splice(count);\n } else {\n while (cells.length < count) cells.push('');\n }\n\n for (; i < cells.length; i++) {\n // leading or trailing whitespace is ignored per the gfm spec\n cells[i] = cells[i].trim().replace(/\\\\\\|/g, '|');\n }\n return cells;\n}\n\n// Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').\n// /c*$/ is vulnerable to REDOS.\n// invert: Remove suffix of non-c chars instead. Default falsey.\nfunction rtrim(str, c, invert) {\n const l = str.length;\n if (l === 0) {\n return '';\n }\n\n // Length of suffix matching the invert condition.\n let suffLen = 0;\n\n // Step left until we fail to match the invert condition.\n while (suffLen < l) {\n const currChar = str.charAt(l - suffLen - 1);\n if (currChar === c && !invert) {\n suffLen++;\n } else if (currChar !== c && invert) {\n suffLen++;\n } else {\n break;\n }\n }\n\n return str.substr(0, l - suffLen);\n}\n\nfunction findClosingBracket(str, b) {\n if (str.indexOf(b[1]) === -1) {\n return -1;\n }\n const l = str.length;\n let level = 0,\n i = 0;\n for (; i < l; i++) {\n if (str[i] === '\\\\') {\n i++;\n } else if (str[i] === b[0]) {\n level++;\n } else if (str[i] === b[1]) {\n level--;\n if (level < 0) {\n return i;\n }\n }\n }\n return -1;\n}\n\nfunction checkSanitizeDeprecation(opt) {\n if (opt && opt.sanitize && !opt.silent) {\n console.warn('marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options');\n }\n}\n\nmodule.exports = {\n escape,\n unescape,\n edit,\n cleanUrl,\n resolveUrl,\n noopTest,\n merge,\n splitCells,\n rtrim,\n findClosingBracket,\n checkSanitizeDeprecation\n};\n","const { defaults } = require('./defaults.js');\nconst {\n rtrim,\n splitCells,\n escape,\n findClosingBracket\n} = require('./helpers.js');\n\nfunction outputLink(cap, link, raw) {\n const href = link.href;\n const title = link.title ? escape(link.title) : null;\n\n if (cap[0].charAt(0) !== '!') {\n return {\n type: 'link',\n raw,\n href,\n title,\n text: cap[1]\n };\n } else {\n return {\n type: 'image',\n raw,\n text: escape(cap[1]),\n href,\n title\n };\n }\n}\n\n/**\n * Tokenizer\n */\nmodule.exports = class Tokenizer {\n constructor(options) {\n this.options = options || defaults;\n }\n\n space(src) {\n const cap = this.rules.block.newline.exec(src);\n if (cap) {\n if (cap[0].length > 1) {\n return {\n type: 'space',\n raw: cap[0]\n };\n }\n return { raw: '\\n' };\n }\n }\n\n code(src, tokens) {\n const cap = this.rules.block.code.exec(src);\n if (cap) {\n const lastToken = tokens[tokens.length - 1];\n // An indented code block cannot interrupt a paragraph.\n if (lastToken && lastToken.type === 'paragraph') {\n tokens.pop();\n lastToken.text += '\\n' + cap[0].trimRight();\n lastToken.raw += '\\n' + cap[0];\n return lastToken;\n } else {\n const text = cap[0].replace(/^ {4}/gm, '');\n return {\n type: 'code',\n raw: cap[0],\n codeBlockStyle: 'indented',\n text: !this.options.pedantic\n ? rtrim(text, '\\n')\n : text\n };\n }\n }\n }\n\n fences(src) {\n const cap = this.rules.block.fences.exec(src);\n if (cap) {\n return {\n type: 'code',\n raw: cap[0],\n lang: cap[2] ? cap[2].trim() : cap[2],\n text: cap[3] || ''\n };\n }\n }\n\n heading(src) {\n const cap = this.rules.block.heading.exec(src);\n if (cap) {\n return {\n type: 'heading',\n raw: cap[0],\n depth: cap[1].length,\n text: cap[2]\n };\n }\n }\n\n nptable(src) {\n const cap = this.rules.block.nptable.exec(src);\n if (cap) {\n const item = {\n type: 'table',\n header: splitCells(cap[1].replace(/^ *| *\\| *$/g, '')),\n align: cap[2].replace(/^ *|\\| *$/g, '').split(/ *\\| */),\n cells: cap[3] ? cap[3].replace(/\\n$/, '').split('\\n') : [],\n raw: cap[0]\n };\n\n if (item.header.length === item.align.length) {\n let l = item.align.length;\n let i;\n for (i = 0; i < l; i++) {\n if (/^ *-+: *$/.test(item.align[i])) {\n item.align[i] = 'right';\n } else if (/^ *:-+: *$/.test(item.align[i])) {\n item.align[i] = 'center';\n } else if (/^ *:-+ *$/.test(item.align[i])) {\n item.align[i] = 'left';\n } else {\n item.align[i] = null;\n }\n }\n\n l = item.cells.length;\n for (i = 0; i < l; i++) {\n item.cells[i] = splitCells(item.cells[i], item.header.length);\n }\n\n return item;\n }\n }\n }\n\n hr(src) {\n const cap = this.rules.block.hr.exec(src);\n if (cap) {\n return {\n type: 'hr',\n raw: cap[0]\n };\n }\n }\n\n blockquote(src) {\n const cap = this.rules.block.blockquote.exec(src);\n if (cap) {\n const text = cap[0].replace(/^ *> ?/gm, '');\n\n return {\n type: 'blockquote',\n raw: cap[0],\n text\n };\n }\n }\n\n list(src) {\n const cap = this.rules.block.list.exec(src);\n if (cap) {\n let raw = cap[0];\n const bull = cap[2];\n const isordered = bull.length > 1;\n\n const list = {\n type: 'list',\n raw,\n ordered: isordered,\n start: isordered ? +bull : '',\n loose: false,\n items: []\n };\n\n // Get each top-level item.\n const itemMatch = cap[0].match(this.rules.block.item);\n\n let next = false,\n item,\n space,\n b,\n addBack,\n loose,\n istask,\n ischecked;\n\n const l = itemMatch.length;\n for (let i = 0; i < l; i++) {\n item = itemMatch[i];\n raw = item;\n\n // Remove the list item's bullet\n // so it is seen as the next token.\n space = item.length;\n item = item.replace(/^ *([*+-]|\\d+\\.) */, '');\n\n // Outdent whatever the\n // list item contains. Hacky.\n if (~item.indexOf('\\n ')) {\n space -= item.length;\n item = !this.options.pedantic\n ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')\n : item.replace(/^ {1,4}/gm, '');\n }\n\n // Determine whether the next list item belongs here.\n // Backpedal if it does not belong in this list.\n if (i !== l - 1) {\n b = this.rules.block.bullet.exec(itemMatch[i + 1])[0];\n if (bull.length > 1 ? b.length === 1\n : (b.length > 1 || (this.options.smartLists && b !== bull))) {\n addBack = itemMatch.slice(i + 1).join('\\n');\n list.raw = list.raw.substring(0, list.raw.length - addBack.length);\n i = l - 1;\n }\n }\n\n // Determine whether item is loose or not.\n // Use: /(^|\\n)(?! )[^\\n]+\\n\\n(?!\\s*$)/\n // for discount behavior.\n loose = next || /\\n\\n(?!\\s*$)/.test(item);\n if (i !== l - 1) {\n next = item.charAt(item.length - 1) === '\\n';\n if (!loose) loose = next;\n }\n\n if (loose) {\n list.loose = true;\n }\n\n // Check for task list items\n istask = /^\\[[ xX]\\] /.test(item);\n ischecked = undefined;\n if (istask) {\n ischecked = item[1] !== ' ';\n item = item.replace(/^\\[[ xX]\\] +/, '');\n }\n\n list.items.push({\n raw,\n task: istask,\n checked: ischecked,\n loose: loose,\n text: item\n });\n }\n\n return list;\n }\n }\n\n html(src) {\n const cap = this.rules.block.html.exec(src);\n if (cap) {\n return {\n type: this.options.sanitize\n ? 'paragraph'\n : 'html',\n raw: cap[0],\n pre: !this.options.sanitizer\n && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),\n text: this.options.sanitize ? (this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0])) : cap[0]\n };\n }\n }\n\n def(src) {\n const cap = this.rules.block.def.exec(src);\n if (cap) {\n if (cap[3]) cap[3] = cap[3].substring(1, cap[3].length - 1);\n const tag = cap[1].toLowerCase().replace(/\\s+/g, ' ');\n return {\n tag,\n raw: cap[0],\n href: cap[2],\n title: cap[3]\n };\n }\n }\n\n table(src) {\n const cap = this.rules.block.table.exec(src);\n if (cap) {\n const item = {\n type: 'table',\n header: splitCells(cap[1].replace(/^ *| *\\| *$/g, '')),\n align: cap[2].replace(/^ *|\\| *$/g, '').split(/ *\\| */),\n cells: cap[3] ? cap[3].replace(/\\n$/, '').split('\\n') : []\n };\n\n if (item.header.length === item.align.length) {\n item.raw = cap[0];\n\n let l = item.align.length;\n let i;\n for (i = 0; i < l; i++) {\n if (/^ *-+: *$/.test(item.align[i])) {\n item.align[i] = 'right';\n } else if (/^ *:-+: *$/.test(item.align[i])) {\n item.align[i] = 'center';\n } else if (/^ *:-+ *$/.test(item.align[i])) {\n item.align[i] = 'left';\n } else {\n item.align[i] = null;\n }\n }\n\n l = item.cells.length;\n for (i = 0; i < l; i++) {\n item.cells[i] = splitCells(\n item.cells[i].replace(/^ *\\| *| *\\| *$/g, ''),\n item.header.length);\n }\n\n return item;\n }\n }\n }\n\n lheading(src) {\n const cap = this.rules.block.lheading.exec(src);\n if (cap) {\n return {\n type: 'heading',\n raw: cap[0],\n depth: cap[2].charAt(0) === '=' ? 1 : 2,\n text: cap[1]\n };\n }\n }\n\n paragraph(src) {\n const cap = this.rules.block.paragraph.exec(src);\n if (cap) {\n return {\n type: 'paragraph',\n raw: cap[0],\n text: cap[1].charAt(cap[1].length - 1) === '\\n'\n ? cap[1].slice(0, -1)\n : cap[1]\n };\n }\n }\n\n text(src) {\n const cap = this.rules.block.text.exec(src);\n if (cap) {\n return {\n type: 'text',\n raw: cap[0],\n text: cap[0]\n };\n }\n }\n\n escape(src) {\n const cap = this.rules.inline.escape.exec(src);\n if (cap) {\n return {\n type: 'escape',\n raw: cap[0],\n text: escape(cap[1])\n };\n }\n }\n\n tag(src, inLink, inRawBlock) {\n const cap = this.rules.inline.tag.exec(src);\n if (cap) {\n if (!inLink && /^/i.test(cap[0])) {\n inLink = false;\n }\n if (!inRawBlock && /^<(pre|code|kbd|script)(\\s|>)/i.test(cap[0])) {\n inRawBlock = true;\n } else if (inRawBlock && /^<\\/(pre|code|kbd|script)(\\s|>)/i.test(cap[0])) {\n inRawBlock = false;\n }\n\n return {\n type: this.options.sanitize\n ? 'text'\n : 'html',\n raw: cap[0],\n inLink,\n inRawBlock,\n text: this.options.sanitize\n ? (this.options.sanitizer\n ? this.options.sanitizer(cap[0])\n : escape(cap[0]))\n : cap[0]\n };\n }\n }\n\n link(src) {\n const cap = this.rules.inline.link.exec(src);\n if (cap) {\n const lastParenIndex = findClosingBracket(cap[2], '()');\n if (lastParenIndex > -1) {\n const start = cap[0].indexOf('!') === 0 ? 5 : 4;\n const linkLen = start + cap[1].length + lastParenIndex;\n cap[2] = cap[2].substring(0, lastParenIndex);\n cap[0] = cap[0].substring(0, linkLen).trim();\n cap[3] = '';\n }\n let href = cap[2];\n let title = '';\n if (this.options.pedantic) {\n const link = /^([^'\"]*[^\\s])\\s+(['\"])(.*)\\2/.exec(href);\n\n if (link) {\n href = link[1];\n title = link[3];\n } else {\n title = '';\n }\n } else {\n title = cap[3] ? cap[3].slice(1, -1) : '';\n }\n href = href.trim().replace(/^<([\\s\\S]*)>$/, '$1');\n const token = outputLink(cap, {\n href: href ? href.replace(this.rules.inline._escapes, '$1') : href,\n title: title ? title.replace(this.rules.inline._escapes, '$1') : title\n }, cap[0]);\n return token;\n }\n }\n\n reflink(src, links) {\n let cap;\n if ((cap = this.rules.inline.reflink.exec(src))\n || (cap = this.rules.inline.nolink.exec(src))) {\n let link = (cap[2] || cap[1]).replace(/\\s+/g, ' ');\n link = links[link.toLowerCase()];\n if (!link || !link.href) {\n const text = cap[0].charAt(0);\n return {\n type: 'text',\n raw: text,\n text\n };\n }\n const token = outputLink(cap, link, cap[0]);\n return token;\n }\n }\n\n strong(src) {\n const cap = this.rules.inline.strong.exec(src);\n if (cap) {\n return {\n type: 'strong',\n raw: cap[0],\n text: cap[4] || cap[3] || cap[2] || cap[1]\n };\n }\n }\n\n em(src) {\n const cap = this.rules.inline.em.exec(src);\n if (cap) {\n return {\n type: 'em',\n raw: cap[0],\n text: cap[6] || cap[5] || cap[4] || cap[3] || cap[2] || cap[1]\n };\n }\n }\n\n codespan(src) {\n const cap = this.rules.inline.code.exec(src);\n if (cap) {\n return {\n type: 'codespan',\n raw: cap[0],\n text: escape(cap[2].trim(), true)\n };\n }\n }\n\n br(src) {\n const cap = this.rules.inline.br.exec(src);\n if (cap) {\n return {\n type: 'br',\n raw: cap[0]\n };\n }\n }\n\n del(src) {\n const cap = this.rules.inline.del.exec(src);\n if (cap) {\n return {\n type: 'del',\n raw: cap[0],\n text: cap[1]\n };\n }\n }\n\n autolink(src, mangle) {\n const cap = this.rules.inline.autolink.exec(src);\n if (cap) {\n let text, href;\n if (cap[2] === '@') {\n text = escape(this.options.mangle ? mangle(cap[1]) : cap[1]);\n href = 'mailto:' + text;\n } else {\n text = escape(cap[1]);\n href = text;\n }\n\n return {\n type: 'link',\n raw: cap[0],\n text,\n href,\n tokens: [\n {\n type: 'text',\n raw: text,\n text\n }\n ]\n };\n }\n }\n\n url(src, mangle) {\n let cap;\n if (cap = this.rules.inline.url.exec(src)) {\n let text, href;\n if (cap[2] === '@') {\n text = escape(this.options.mangle ? mangle(cap[0]) : cap[0]);\n href = 'mailto:' + text;\n } else {\n // do extended autolink path validation\n let prevCapZero;\n do {\n prevCapZero = cap[0];\n cap[0] = this.rules.inline._backpedal.exec(cap[0])[0];\n } while (prevCapZero !== cap[0]);\n text = escape(cap[0]);\n if (cap[1] === 'www.') {\n href = 'http://' + text;\n } else {\n href = text;\n }\n }\n return {\n type: 'link',\n raw: cap[0],\n text,\n href,\n tokens: [\n {\n type: 'text',\n raw: text,\n text\n }\n ]\n };\n }\n }\n\n inlineText(src, inRawBlock, smartypants) {\n const cap = this.rules.inline.text.exec(src);\n if (cap) {\n let text;\n if (inRawBlock) {\n text = this.options.sanitize ? (this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0])) : cap[0];\n } else {\n text = escape(this.options.smartypants ? smartypants(cap[0]) : cap[0]);\n }\n return {\n type: 'text',\n raw: cap[0],\n text\n };\n }\n }\n};\n","const {\n noopTest,\n edit,\n merge\n} = require('./helpers.js');\n\n/**\n * Block-Level Grammar\n */\nconst block = {\n newline: /^\\n+/,\n code: /^( {4}[^\\n]+\\n*)+/,\n fences: /^ {0,3}(`{3,}(?=[^`\\n]*\\n)|~{3,})([^\\n]*)\\n(?:|([\\s\\S]*?)\\n)(?: {0,3}\\1[~`]* *(?:\\n+|$)|$)/,\n hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)/,\n heading: /^ {0,3}(#{1,6}) +([^\\n]*?)(?: +#+)? *(?:\\n+|$)/,\n blockquote: /^( {0,3}> ?(paragraph|[^\\n]*)(?:\\n|$))+/,\n list: /^( {0,3})(bull) [\\s\\S]+?(?:hr|def|\\n{2,}(?! )(?!\\1bull )\\n*|\\s*$)/,\n html: '^ {0,3}(?:' // optional indentation\n + '<(script|pre|style)[\\\\s>][\\\\s\\\\S]*?(?:\\\\1>[^\\\\n]*\\\\n+|$)' // (1)\n + '|comment[^\\\\n]*(\\\\n+|$)' // (2)\n + '|<\\\\?[\\\\s\\\\S]*?\\\\?>\\\\n*' // (3)\n + '|\\\\n*' // (4)\n + '|\\\\n*' // (5)\n + '|?(tag)(?: +|\\\\n|/?>)[\\\\s\\\\S]*?(?:\\\\n{2,}|$)' // (6)\n + '|<(?!script|pre|style)([a-z][\\\\w-]*)(?:attribute)*? */?>(?=[ \\\\t]*(?:\\\\n|$))[\\\\s\\\\S]*?(?:\\\\n{2,}|$)' // (7) open tag\n + '|(?!script|pre|style)[a-z][\\\\w-]*\\\\s*>(?=[ \\\\t]*(?:\\\\n|$))[\\\\s\\\\S]*?(?:\\\\n{2,}|$)' // (7) closing tag\n + ')',\n def: /^ {0,3}\\[(label)\\]: *\\n? *([^\\s>]+)>?(?:(?: +\\n? *| *\\n *)(title))? *(?:\\n+|$)/,\n nptable: noopTest,\n table: noopTest,\n lheading: /^([^\\n]+)\\n {0,3}(=+|-+) *(?:\\n+|$)/,\n // regex template, placeholders will be replaced according to different paragraph\n // interruption rules of commonmark and the original markdown spec:\n _paragraph: /^([^\\n]+(?:\\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\\n]+)*)/,\n text: /^[^\\n]+/\n};\n\nblock._label = /(?!\\s*\\])(?:\\\\[\\[\\]]|[^\\[\\]])+/;\nblock._title = /(?:\"(?:\\\\\"?|[^\"\\\\])*\"|'[^'\\n]*(?:\\n[^'\\n]+)*\\n?'|\\([^()]*\\))/;\nblock.def = edit(block.def)\n .replace('label', block._label)\n .replace('title', block._title)\n .getRegex();\n\nblock.bullet = /(?:[*+-]|\\d{1,9}\\.)/;\nblock.item = /^( *)(bull) ?[^\\n]*(?:\\n(?!\\1bull ?)[^\\n]*)*/;\nblock.item = edit(block.item, 'gm')\n .replace(/bull/g, block.bullet)\n .getRegex();\n\nblock.list = edit(block.list)\n .replace(/bull/g, block.bullet)\n .replace('hr', '\\\\n+(?=\\\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\\\* *){3,})(?:\\\\n+|$))')\n .replace('def', '\\\\n+(?=' + block.def.source + ')')\n .getRegex();\n\nblock._tag = 'address|article|aside|base|basefont|blockquote|body|caption'\n + '|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption'\n + '|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe'\n + '|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option'\n + '|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr'\n + '|track|ul';\nblock._comment = //;\nblock.html = edit(block.html, 'i')\n .replace('comment', block._comment)\n .replace('tag', block._tag)\n .replace('attribute', / +[a-zA-Z:_][\\w.:-]*(?: *= *\"[^\"\\n]*\"| *= *'[^'\\n]*'| *= *[^\\s\"'=<>`]+)?/)\n .getRegex();\n\nblock.paragraph = edit(block._paragraph)\n .replace('hr', block.hr)\n .replace('heading', ' {0,3}#{1,6} ')\n .replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs\n .replace('blockquote', ' {0,3}>')\n .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\\\n]*\\\\n)|~{3,})[^\\\\n]*\\\\n')\n .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt\n .replace('html', '?(?:tag)(?: +|\\\\n|/?>)|<(?:script|pre|style|!--)')\n .replace('tag', block._tag) // pars can be interrupted by type (6) html blocks\n .getRegex();\n\nblock.blockquote = edit(block.blockquote)\n .replace('paragraph', block.paragraph)\n .getRegex();\n\n/**\n * Normal Block Grammar\n */\n\nblock.normal = merge({}, block);\n\n/**\n * GFM Block Grammar\n */\n\nblock.gfm = merge({}, block.normal, {\n nptable: '^ *([^|\\\\n ].*\\\\|.*)\\\\n' // Header\n + ' *([-:]+ *\\\\|[-| :]*)' // Align\n + '(?:\\\\n((?:(?!\\\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\\\n|$))*)\\\\n*|$)', // Cells\n table: '^ *\\\\|(.+)\\\\n' // Header\n + ' *\\\\|?( *[-:]+[-| :]*)' // Align\n + '(?:\\\\n *((?:(?!\\\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\\\n|$))*)\\\\n*|$)' // Cells\n});\n\nblock.gfm.nptable = edit(block.gfm.nptable)\n .replace('hr', block.hr)\n .replace('heading', ' {0,3}#{1,6} ')\n .replace('blockquote', ' {0,3}>')\n .replace('code', ' {4}[^\\\\n]')\n .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\\\n]*\\\\n)|~{3,})[^\\\\n]*\\\\n')\n .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt\n .replace('html', '?(?:tag)(?: +|\\\\n|/?>)|<(?:script|pre|style|!--)')\n .replace('tag', block._tag) // tables can be interrupted by type (6) html blocks\n .getRegex();\n\nblock.gfm.table = edit(block.gfm.table)\n .replace('hr', block.hr)\n .replace('heading', ' {0,3}#{1,6} ')\n .replace('blockquote', ' {0,3}>')\n .replace('code', ' {4}[^\\\\n]')\n .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\\\n]*\\\\n)|~{3,})[^\\\\n]*\\\\n')\n .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt\n .replace('html', '?(?:tag)(?: +|\\\\n|/?>)|<(?:script|pre|style|!--)')\n .replace('tag', block._tag) // tables can be interrupted by type (6) html blocks\n .getRegex();\n\n/**\n * Pedantic grammar (original John Gruber's loose markdown specification)\n */\n\nblock.pedantic = merge({}, block.normal, {\n html: edit(\n '^ *(?:comment *(?:\\\\n|\\\\s*$)'\n + '|<(tag)[\\\\s\\\\S]+?\\\\1> *(?:\\\\n{2,}|\\\\s*$)' // closed tag\n + '| \\\\s]*)*?/?> *(?:\\\\n{2,}|\\\\s*$))')\n .replace('comment', block._comment)\n .replace(/tag/g, '(?!(?:'\n + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub'\n + '|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)'\n + '\\\\b)\\\\w+(?!:|[^\\\\w\\\\s@]*@)\\\\b')\n .getRegex(),\n def: /^ *\\[([^\\]]+)\\]: *([^\\s>]+)>?(?: +([\"(][^\\n]+[\")]))? *(?:\\n+|$)/,\n heading: /^ *(#{1,6}) *([^\\n]+?) *(?:#+ *)?(?:\\n+|$)/,\n fences: noopTest, // fences not supported\n paragraph: edit(block.normal._paragraph)\n .replace('hr', block.hr)\n .replace('heading', ' *#{1,6} *[^\\n]')\n .replace('lheading', block.lheading)\n .replace('blockquote', ' {0,3}>')\n .replace('|fences', '')\n .replace('|list', '')\n .replace('|html', '')\n .getRegex()\n});\n\n/**\n * Inline-Level Grammar\n */\nconst inline = {\n escape: /^\\\\([!\"#$%&'()*+,\\-./:;<=>?@\\[\\]\\\\^_`{|}~])/,\n autolink: /^<(scheme:[^\\s\\x00-\\x1f<>]*|email)>/,\n url: noopTest,\n tag: '^comment'\n + '|^[a-zA-Z][\\\\w:-]*\\\\s*>' // self-closing tag\n + '|^<[a-zA-Z][\\\\w-]*(?:attribute)*?\\\\s*/?>' // open tag\n + '|^<\\\\?[\\\\s\\\\S]*?\\\\?>' // processing instruction, e.g. \n + '|^' // declaration, e.g. \n + '|^', // CDATA section\n link: /^!?\\[(label)\\]\\(\\s*(href)(?:\\s+(title))?\\s*\\)/,\n reflink: /^!?\\[(label)\\]\\[(?!\\s*\\])((?:\\\\[\\[\\]]?|[^\\[\\]\\\\])+)\\]/,\n nolink: /^!?\\[(?!\\s*\\])((?:\\[[^\\[\\]]*\\]|\\\\[\\[\\]]|[^\\[\\]])*)\\](?:\\[\\])?/,\n strong: /^__([^\\s_])__(?!_)|^\\*\\*([^\\s*])\\*\\*(?!\\*)|^__([^\\s][\\s\\S]*?[^\\s])__(?!_)|^\\*\\*([^\\s][\\s\\S]*?[^\\s])\\*\\*(?!\\*)/,\n em: /^_([^\\s_])_(?!_)|^_([^\\s_<][\\s\\S]*?[^\\s_])_(?!_|[^\\spunctuation])|^_([^\\s_<][\\s\\S]*?[^\\s])_(?!_|[^\\spunctuation])|^\\*([^\\s*<\\[])\\*(?!\\*)|^\\*([^\\s<\"][\\s\\S]*?[^\\s\\[\\*])\\*(?![\\]`punctuation])|^\\*([^\\s*\"<\\[][\\s\\S]*[^\\s])\\*(?!\\*)/,\n code: /^(`+)([^`]|[^`][\\s\\S]*?[^`])\\1(?!`)/,\n br: /^( {2,}|\\\\)\\n(?!\\s*$)/,\n del: noopTest,\n text: /^(`+|[^`])(?:[\\s\\S]*?(?:(?=[\\\\?@\\\\[^_{|}~';\ninline.em = edit(inline.em).replace(/punctuation/g, inline._punctuation).getRegex();\n\ninline._escapes = /\\\\([!\"#$%&'()*+,\\-./:;<=>?@\\[\\]\\\\^_`{|}~])/g;\n\ninline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;\ninline._email = /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/;\ninline.autolink = edit(inline.autolink)\n .replace('scheme', inline._scheme)\n .replace('email', inline._email)\n .getRegex();\n\ninline._attribute = /\\s+[a-zA-Z:_][\\w.:-]*(?:\\s*=\\s*\"[^\"]*\"|\\s*=\\s*'[^']*'|\\s*=\\s*[^\\s\"'=<>`]+)?/;\n\ninline.tag = edit(inline.tag)\n .replace('comment', block._comment)\n .replace('attribute', inline._attribute)\n .getRegex();\n\ninline._label = /(?:\\[[^\\[\\]]*\\]|\\\\.|`[^`]*`|[^\\[\\]\\\\`])*?/;\ninline._href = /<(?:\\\\[<>]?|[^\\s<>\\\\])*>|[^\\s\\x00-\\x1f]*/;\ninline._title = /\"(?:\\\\\"?|[^\"\\\\])*\"|'(?:\\\\'?|[^'\\\\])*'|\\((?:\\\\\\)?|[^)\\\\])*\\)/;\n\ninline.link = edit(inline.link)\n .replace('label', inline._label)\n .replace('href', inline._href)\n .replace('title', inline._title)\n .getRegex();\n\ninline.reflink = edit(inline.reflink)\n .replace('label', inline._label)\n .getRegex();\n\n/**\n * Normal Inline Grammar\n */\n\ninline.normal = merge({}, inline);\n\n/**\n * Pedantic Inline Grammar\n */\n\ninline.pedantic = merge({}, inline.normal, {\n strong: /^__(?=\\S)([\\s\\S]*?\\S)__(?!_)|^\\*\\*(?=\\S)([\\s\\S]*?\\S)\\*\\*(?!\\*)/,\n em: /^_(?=\\S)([\\s\\S]*?\\S)_(?!_)|^\\*(?=\\S)([\\s\\S]*?\\S)\\*(?!\\*)/,\n link: edit(/^!?\\[(label)\\]\\((.*?)\\)/)\n .replace('label', inline._label)\n .getRegex(),\n reflink: edit(/^!?\\[(label)\\]\\s*\\[([^\\]]*)\\]/)\n .replace('label', inline._label)\n .getRegex()\n});\n\n/**\n * GFM Inline Grammar\n */\n\ninline.gfm = merge({}, inline.normal, {\n escape: edit(inline.escape).replace('])', '~|])').getRegex(),\n _extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,\n url: /^((?:ftp|https?):\\/\\/|www\\.)(?:[a-zA-Z0-9\\-]+\\.?)+[^\\s<]*|^email/,\n _backpedal: /(?:[^?!.,:;*_~()&]+|\\([^)]*\\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,\n del: /^~+(?=\\S)([\\s\\S]*?\\S)~+/,\n text: /^(`+|[^`])(?:[\\s\\S]*?(?:(?=[\\\\ 0.5) {\n ch = 'x' + ch.toString(16);\n }\n out += '' + ch + ';';\n }\n\n return out;\n}\n\n/**\n * Block Lexer\n */\nmodule.exports = class Lexer {\n constructor(options) {\n this.tokens = [];\n this.tokens.links = Object.create(null);\n this.options = options || defaults;\n this.options.tokenizer = this.options.tokenizer || new Tokenizer();\n this.tokenizer = this.options.tokenizer;\n this.tokenizer.options = this.options;\n\n const rules = {\n block: block.normal,\n inline: inline.normal\n };\n\n if (this.options.pedantic) {\n rules.block = block.pedantic;\n rules.inline = inline.pedantic;\n } else if (this.options.gfm) {\n rules.block = block.gfm;\n if (this.options.breaks) {\n rules.inline = inline.breaks;\n } else {\n rules.inline = inline.gfm;\n }\n }\n this.tokenizer.rules = rules;\n }\n\n /**\n * Expose Rules\n */\n static get rules() {\n return {\n block,\n inline\n };\n }\n\n /**\n * Static Lex Method\n */\n static lex(src, options) {\n const lexer = new Lexer(options);\n return lexer.lex(src);\n }\n\n /**\n * Preprocessing\n */\n lex(src) {\n src = src\n .replace(/\\r\\n|\\r/g, '\\n')\n .replace(/\\t/g, ' ');\n\n this.blockTokens(src, this.tokens, true);\n\n this.inline(this.tokens);\n\n return this.tokens;\n }\n\n /**\n * Lexing\n */\n blockTokens(src, tokens = [], top = true) {\n src = src.replace(/^ +$/gm, '');\n let token, i, l;\n\n while (src) {\n // newline\n if (token = this.tokenizer.space(src)) {\n src = src.substring(token.raw.length);\n if (token.type) {\n tokens.push(token);\n }\n continue;\n }\n\n // code\n if (token = this.tokenizer.code(src, tokens)) {\n src = src.substring(token.raw.length);\n tokens.push(token);\n continue;\n }\n\n // fences\n if (token = this.tokenizer.fences(src)) {\n src = src.substring(token.raw.length);\n tokens.push(token);\n continue;\n }\n\n // heading\n if (token = this.tokenizer.heading(src)) {\n src = src.substring(token.raw.length);\n tokens.push(token);\n continue;\n }\n\n // table no leading pipe (gfm)\n if (token = this.tokenizer.nptable(src)) {\n src = src.substring(token.raw.length);\n tokens.push(token);\n continue;\n }\n\n // hr\n if (token = this.tokenizer.hr(src)) {\n src = src.substring(token.raw.length);\n tokens.push(token);\n continue;\n }\n\n // blockquote\n if (token = this.tokenizer.blockquote(src)) {\n src = src.substring(token.raw.length);\n token.tokens = this.blockTokens(token.text, [], top);\n tokens.push(token);\n continue;\n }\n\n // list\n if (token = this.tokenizer.list(src)) {\n src = src.substring(token.raw.length);\n l = token.items.length;\n for (i = 0; i < l; i++) {\n token.items[i].tokens = this.blockTokens(token.items[i].text, [], false);\n }\n tokens.push(token);\n continue;\n }\n\n // html\n if (token = this.tokenizer.html(src)) {\n src = src.substring(token.raw.length);\n tokens.push(token);\n continue;\n }\n\n // def\n if (top && (token = this.tokenizer.def(src))) {\n src = src.substring(token.raw.length);\n if (!this.tokens.links[token.tag]) {\n this.tokens.links[token.tag] = {\n href: token.href,\n title: token.title\n };\n }\n continue;\n }\n\n // table (gfm)\n if (token = this.tokenizer.table(src)) {\n src = src.substring(token.raw.length);\n tokens.push(token);\n continue;\n }\n\n // lheading\n if (token = this.tokenizer.lheading(src)) {\n src = src.substring(token.raw.length);\n tokens.push(token);\n continue;\n }\n\n // top-level paragraph\n if (top && (token = this.tokenizer.paragraph(src))) {\n src = src.substring(token.raw.length);\n tokens.push(token);\n continue;\n }\n\n // text\n if (token = this.tokenizer.text(src)) {\n src = src.substring(token.raw.length);\n tokens.push(token);\n continue;\n }\n\n if (src) {\n const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);\n if (this.options.silent) {\n console.error(errMsg);\n break;\n } else {\n throw new Error(errMsg);\n }\n }\n }\n\n return tokens;\n }\n\n inline(tokens) {\n let i,\n j,\n k,\n l2,\n row,\n token;\n\n const l = tokens.length;\n for (i = 0; i < l; i++) {\n token = tokens[i];\n switch (token.type) {\n case 'paragraph':\n case 'text':\n case 'heading': {\n token.tokens = [];\n this.inlineTokens(token.text, token.tokens);\n break;\n }\n case 'table': {\n token.tokens = {\n header: [],\n cells: []\n };\n\n // header\n l2 = token.header.length;\n for (j = 0; j < l2; j++) {\n token.tokens.header[j] = [];\n this.inlineTokens(token.header[j], token.tokens.header[j]);\n }\n\n // cells\n l2 = token.cells.length;\n for (j = 0; j < l2; j++) {\n row = token.cells[j];\n token.tokens.cells[j] = [];\n for (k = 0; k < row.length; k++) {\n token.tokens.cells[j][k] = [];\n this.inlineTokens(row[k], token.tokens.cells[j][k]);\n }\n }\n\n break;\n }\n case 'blockquote': {\n this.inline(token.tokens);\n break;\n }\n case 'list': {\n l2 = token.items.length;\n for (j = 0; j < l2; j++) {\n this.inline(token.items[j].tokens);\n }\n break;\n }\n default: {\n // do nothing\n }\n }\n }\n\n return tokens;\n }\n\n /**\n * Lexing/Compiling\n */\n inlineTokens(src, tokens = [], inLink = false, inRawBlock = false) {\n let token;\n\n while (src) {\n // escape\n if (token = this.tokenizer.escape(src)) {\n src = src.substring(token.raw.length);\n tokens.push(token);\n continue;\n }\n\n // tag\n if (token = this.tokenizer.tag(src, inLink, inRawBlock)) {\n src = src.substring(token.raw.length);\n inLink = token.inLink;\n inRawBlock = token.inRawBlock;\n tokens.push(token);\n continue;\n }\n\n // link\n if (token = this.tokenizer.link(src)) {\n src = src.substring(token.raw.length);\n if (token.type === 'link') {\n token.tokens = this.inlineTokens(token.text, [], true, inRawBlock);\n }\n tokens.push(token);\n continue;\n }\n\n // reflink, nolink\n if (token = this.tokenizer.reflink(src, this.tokens.links)) {\n src = src.substring(token.raw.length);\n if (token.type === 'link') {\n token.tokens = this.inlineTokens(token.text, [], true, inRawBlock);\n }\n tokens.push(token);\n continue;\n }\n\n // strong\n if (token = this.tokenizer.strong(src)) {\n src = src.substring(token.raw.length);\n token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);\n tokens.push(token);\n continue;\n }\n\n // em\n if (token = this.tokenizer.em(src)) {\n src = src.substring(token.raw.length);\n token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);\n tokens.push(token);\n continue;\n }\n\n // code\n if (token = this.tokenizer.codespan(src)) {\n src = src.substring(token.raw.length);\n tokens.push(token);\n continue;\n }\n\n // br\n if (token = this.tokenizer.br(src)) {\n src = src.substring(token.raw.length);\n tokens.push(token);\n continue;\n }\n\n // del (gfm)\n if (token = this.tokenizer.del(src)) {\n src = src.substring(token.raw.length);\n token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);\n tokens.push(token);\n continue;\n }\n\n // autolink\n if (token = this.tokenizer.autolink(src, mangle)) {\n src = src.substring(token.raw.length);\n tokens.push(token);\n continue;\n }\n\n // url (gfm)\n if (!inLink && (token = this.tokenizer.url(src, mangle))) {\n src = src.substring(token.raw.length);\n tokens.push(token);\n continue;\n }\n\n // text\n if (token = this.tokenizer.inlineText(src, inRawBlock, smartypants)) {\n src = src.substring(token.raw.length);\n tokens.push(token);\n continue;\n }\n\n if (src) {\n const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);\n if (this.options.silent) {\n console.error(errMsg);\n break;\n } else {\n throw new Error(errMsg);\n }\n }\n }\n\n return tokens;\n }\n};\n","const { defaults } = require('./defaults.js');\nconst {\n cleanUrl,\n escape\n} = require('./helpers.js');\n\n/**\n * Renderer\n */\nmodule.exports = class Renderer {\n constructor(options) {\n this.options = options || defaults;\n }\n\n code(code, infostring, escaped) {\n const lang = (infostring || '').match(/\\S*/)[0];\n if (this.options.highlight) {\n const out = this.options.highlight(code, lang);\n if (out != null && out !== code) {\n escaped = true;\n code = out;\n }\n }\n\n if (!lang) {\n return ''\n + (escaped ? code : escape(code, true))\n + '
';\n }\n\n return ''\n + (escaped ? code : escape(code, true))\n + '
\\n';\n }\n\n blockquote(quote) {\n return '\\n' + quote + ' \\n';\n }\n\n html(html) {\n return html;\n }\n\n heading(text, level, raw, slugger) {\n if (this.options.headerIds) {\n return ''\n + text\n + ' \\n';\n }\n // ignore IDs\n return '' + text + ' \\n';\n }\n\n hr() {\n return this.options.xhtml ? ' \\n' : ' \\n';\n }\n\n list(body, ordered, start) {\n const type = ordered ? 'ol' : 'ul',\n startatt = (ordered && start !== 1) ? (' start=\"' + start + '\"') : '';\n return '<' + type + startatt + '>\\n' + body + '' + type + '>\\n';\n }\n\n listitem(text) {\n return '' + text + ' \\n';\n }\n\n checkbox(checked) {\n return ' ';\n }\n\n paragraph(text) {\n return '' + text + '
\\n';\n }\n\n table(header, body) {\n if (body) body = '' + body + ' ';\n\n return ' \\n'\n + '\\n'\n + header\n + ' \\n'\n + body\n + '
\\n';\n }\n\n tablerow(content) {\n return '\\n' + content + ' \\n';\n }\n\n tablecell(content, flags) {\n const type = flags.header ? 'th' : 'td';\n const tag = flags.align\n ? '<' + type + ' align=\"' + flags.align + '\">'\n : '<' + type + '>';\n return tag + content + '' + type + '>\\n';\n }\n\n // span level renderer\n strong(text) {\n return '' + text + ' ';\n }\n\n em(text) {\n return '' + text + ' ';\n }\n\n codespan(text) {\n return '' + text + '
';\n }\n\n br() {\n return this.options.xhtml ? ' ' : ' ';\n }\n\n del(text) {\n return '' + text + '';\n }\n\n link(href, title, text) {\n href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);\n if (href === null) {\n return text;\n }\n let out = '' + text + ' ';\n return out;\n }\n\n image(href, title, text) {\n href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);\n if (href === null) {\n return text;\n }\n\n let out = ' ' : '>';\n return out;\n }\n\n text(text) {\n return text;\n }\n};\n","/**\n * TextRenderer\n * returns only the textual part of the token\n */\nmodule.exports = class TextRenderer {\n // no need for block level renderers\n strong(text) {\n return text;\n }\n\n em(text) {\n return text;\n }\n\n codespan(text) {\n return text;\n }\n\n del(text) {\n return text;\n }\n\n html(text) {\n return text;\n }\n\n text(text) {\n return text;\n }\n\n link(href, title, text) {\n return '' + text;\n }\n\n image(href, title, text) {\n return '' + text;\n }\n\n br() {\n return '';\n }\n};\n","/**\n * Slugger generates header id\n */\nmodule.exports = class Slugger {\n constructor() {\n this.seen = {};\n }\n\n /**\n * Convert string to unique id\n */\n slug(value) {\n let slug = value\n .toLowerCase()\n .trim()\n // remove html tags\n .replace(/<[!\\/a-z].*?>/ig, '')\n // remove unwanted chars\n .replace(/[\\u2000-\\u206F\\u2E00-\\u2E7F\\\\'!\"#$%&()*+,./:;<=>?@[\\]^`{|}~]/g, '')\n .replace(/\\s/g, '-');\n\n if (this.seen.hasOwnProperty(slug)) {\n const originalSlug = slug;\n do {\n this.seen[originalSlug]++;\n slug = originalSlug + '-' + this.seen[originalSlug];\n } while (this.seen.hasOwnProperty(slug));\n }\n this.seen[slug] = 0;\n\n return slug;\n }\n};\n","const Renderer = require('./Renderer.js');\nconst TextRenderer = require('./TextRenderer.js');\nconst Slugger = require('./Slugger.js');\nconst { defaults } = require('./defaults.js');\nconst {\n unescape\n} = require('./helpers.js');\n\n/**\n * Parsing & Compiling\n */\nmodule.exports = class Parser {\n constructor(options) {\n this.options = options || defaults;\n this.options.renderer = this.options.renderer || new Renderer();\n this.renderer = this.options.renderer;\n this.renderer.options = this.options;\n this.textRenderer = new TextRenderer();\n this.slugger = new Slugger();\n }\n\n /**\n * Static Parse Method\n */\n static parse(tokens, options) {\n const parser = new Parser(options);\n return parser.parse(tokens);\n }\n\n /**\n * Parse Loop\n */\n parse(tokens, top = true) {\n let out = '',\n i,\n j,\n k,\n l2,\n l3,\n row,\n cell,\n header,\n body,\n token,\n ordered,\n start,\n loose,\n itemBody,\n item,\n checked,\n task,\n checkbox;\n\n const l = tokens.length;\n for (i = 0; i < l; i++) {\n token = tokens[i];\n switch (token.type) {\n case 'space': {\n continue;\n }\n case 'hr': {\n out += this.renderer.hr();\n continue;\n }\n case 'heading': {\n out += this.renderer.heading(\n this.parseInline(token.tokens),\n token.depth,\n unescape(this.parseInline(token.tokens, this.textRenderer)),\n this.slugger);\n continue;\n }\n case 'code': {\n out += this.renderer.code(token.text,\n token.lang,\n token.escaped);\n continue;\n }\n case 'table': {\n header = '';\n\n // header\n cell = '';\n l2 = token.header.length;\n for (j = 0; j < l2; j++) {\n cell += this.renderer.tablecell(\n this.parseInline(token.tokens.header[j]),\n { header: true, align: token.align[j] }\n );\n }\n header += this.renderer.tablerow(cell);\n\n body = '';\n l2 = token.cells.length;\n for (j = 0; j < l2; j++) {\n row = token.tokens.cells[j];\n\n cell = '';\n l3 = row.length;\n for (k = 0; k < l3; k++) {\n cell += this.renderer.tablecell(\n this.parseInline(row[k]),\n { header: false, align: token.align[k] }\n );\n }\n\n body += this.renderer.tablerow(cell);\n }\n out += this.renderer.table(header, body);\n continue;\n }\n case 'blockquote': {\n body = this.parse(token.tokens);\n out += this.renderer.blockquote(body);\n continue;\n }\n case 'list': {\n ordered = token.ordered;\n start = token.start;\n loose = token.loose;\n l2 = token.items.length;\n\n body = '';\n for (j = 0; j < l2; j++) {\n item = token.items[j];\n checked = item.checked;\n task = item.task;\n\n itemBody = '';\n if (item.task) {\n checkbox = this.renderer.checkbox(checked);\n if (loose) {\n if (item.tokens[0].type === 'text') {\n item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;\n if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {\n item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text;\n }\n } else {\n item.tokens.unshift({\n type: 'text',\n text: checkbox\n });\n }\n } else {\n itemBody += checkbox;\n }\n }\n\n itemBody += this.parse(item.tokens, loose);\n body += this.renderer.listitem(itemBody, task, checked);\n }\n\n out += this.renderer.list(body, ordered, start);\n continue;\n }\n case 'html': {\n // TODO parse inline content if parameter markdown=1\n out += this.renderer.html(token.text);\n continue;\n }\n case 'paragraph': {\n out += this.renderer.paragraph(this.parseInline(token.tokens));\n continue;\n }\n case 'text': {\n body = token.tokens ? this.parseInline(token.tokens) : token.text;\n while (i + 1 < l && tokens[i + 1].type === 'text') {\n token = tokens[++i];\n body += '\\n' + (token.tokens ? this.parseInline(token.tokens) : token.text);\n }\n out += top ? this.renderer.paragraph(body) : body;\n continue;\n }\n default: {\n const errMsg = 'Token with \"' + token.type + '\" type was not found.';\n if (this.options.silent) {\n console.error(errMsg);\n return;\n } else {\n throw new Error(errMsg);\n }\n }\n }\n }\n\n return out;\n }\n\n /**\n * Parse Inline Tokens\n */\n parseInline(tokens, renderer) {\n renderer = renderer || this.renderer;\n let out = '',\n i,\n token;\n\n const l = tokens.length;\n for (i = 0; i < l; i++) {\n token = tokens[i];\n switch (token.type) {\n case 'escape': {\n out += renderer.text(token.text);\n break;\n }\n case 'html': {\n out += renderer.html(token.text);\n break;\n }\n case 'link': {\n out += renderer.link(token.href, token.title, this.parseInline(token.tokens, renderer));\n break;\n }\n case 'image': {\n out += renderer.image(token.href, token.title, token.text);\n break;\n }\n case 'strong': {\n out += renderer.strong(this.parseInline(token.tokens, renderer));\n break;\n }\n case 'em': {\n out += renderer.em(this.parseInline(token.tokens, renderer));\n break;\n }\n case 'codespan': {\n out += renderer.codespan(token.text);\n break;\n }\n case 'br': {\n out += renderer.br();\n break;\n }\n case 'del': {\n out += renderer.del(this.parseInline(token.tokens, renderer));\n break;\n }\n case 'text': {\n out += renderer.text(token.text);\n break;\n }\n default: {\n const errMsg = 'Token with \"' + token.type + '\" type was not found.';\n if (this.options.silent) {\n console.error(errMsg);\n return;\n } else {\n throw new Error(errMsg);\n }\n }\n }\n }\n return out;\n }\n};\n","const Lexer = require('./Lexer.js');\nconst Parser = require('./Parser.js');\nconst Tokenizer = require('./Tokenizer.js');\nconst Renderer = require('./Renderer.js');\nconst TextRenderer = require('./TextRenderer.js');\nconst Slugger = require('./Slugger.js');\nconst {\n merge,\n checkSanitizeDeprecation,\n escape\n} = require('./helpers.js');\nconst {\n getDefaults,\n changeDefaults,\n defaults\n} = require('./defaults.js');\n\n/**\n * Marked\n */\nfunction marked(src, opt, callback) {\n // throw error in case of non string input\n if (typeof src === 'undefined' || src === null) {\n throw new Error('marked(): input parameter is undefined or null');\n }\n if (typeof src !== 'string') {\n throw new Error('marked(): input parameter is of type '\n + Object.prototype.toString.call(src) + ', string expected');\n }\n\n if (callback || typeof opt === 'function') {\n if (!callback) {\n callback = opt;\n opt = null;\n }\n\n opt = merge({}, marked.defaults, opt || {});\n checkSanitizeDeprecation(opt);\n const highlight = opt.highlight;\n let tokens,\n pending,\n i = 0;\n\n try {\n tokens = Lexer.lex(src, opt);\n } catch (e) {\n return callback(e);\n }\n\n pending = tokens.length;\n\n const done = function(err) {\n if (err) {\n opt.highlight = highlight;\n return callback(err);\n }\n\n let out;\n\n try {\n out = Parser.parse(tokens, opt);\n } catch (e) {\n err = e;\n }\n\n opt.highlight = highlight;\n\n return err\n ? callback(err)\n : callback(null, out);\n };\n\n if (!highlight || highlight.length < 3) {\n return done();\n }\n\n delete opt.highlight;\n\n if (!pending) return done();\n\n for (; i < tokens.length; i++) {\n (function(token) {\n if (token.type !== 'code') {\n return --pending || done();\n }\n return highlight(token.text, token.lang, function(err, code) {\n if (err) return done(err);\n if (code == null || code === token.text) {\n return --pending || done();\n }\n token.text = code;\n token.escaped = true;\n --pending || done();\n });\n })(tokens[i]);\n }\n\n return;\n }\n try {\n opt = merge({}, marked.defaults, opt || {});\n checkSanitizeDeprecation(opt);\n return Parser.parse(Lexer.lex(src, opt), opt);\n } catch (e) {\n e.message += '\\nPlease report this to https://github.com/markedjs/marked.';\n if ((opt || marked.defaults).silent) {\n return 'An error occurred:
'\n + escape(e.message + '', true)\n + ' ';\n }\n throw e;\n }\n}\n\n/**\n * Options\n */\n\nmarked.options =\nmarked.setOptions = function(opt) {\n merge(marked.defaults, opt);\n changeDefaults(marked.defaults);\n return marked;\n};\n\nmarked.getDefaults = getDefaults;\n\nmarked.defaults = defaults;\n\n/**\n * Use Extension\n */\n\nmarked.use = function(extension) {\n const opts = merge({}, extension);\n if (extension.renderer) {\n const renderer = marked.defaults.renderer || new Renderer();\n for (const prop in extension.renderer) {\n const prevRenderer = renderer[prop];\n renderer[prop] = (...args) => {\n let ret = extension.renderer[prop].apply(renderer, args);\n if (ret === false) {\n ret = prevRenderer.apply(renderer, args);\n }\n return ret;\n };\n }\n opts.renderer = renderer;\n }\n if (extension.tokenizer) {\n const tokenizer = marked.defaults.tokenizer || new Tokenizer();\n for (const prop in extension.tokenizer) {\n const prevTokenizer = tokenizer[prop];\n tokenizer[prop] = (...args) => {\n let ret = extension.tokenizer[prop].apply(tokenizer, args);\n if (ret === false) {\n ret = prevTokenizer.apply(tokenizer, args);\n }\n return ret;\n };\n }\n opts.tokenizer = tokenizer;\n }\n marked.setOptions(opts);\n};\n\n/**\n * Expose\n */\n\nmarked.Parser = Parser;\nmarked.parser = Parser.parse;\n\nmarked.Renderer = Renderer;\nmarked.TextRenderer = TextRenderer;\n\nmarked.Lexer = Lexer;\nmarked.lexer = Lexer.lex;\n\nmarked.Tokenizer = Tokenizer;\n\nmarked.Slugger = Slugger;\n\nmarked.parse = marked;\n\nmodule.exports = marked;\n","import { t, localizer } from '../../core/localizer';\nimport { geoSphericalDistance, geoVecNormalizedDot } from '../../geo';\nimport { uiCmd } from '../cmd';\n\nexport function pointBox(loc, context) {\n var rect = context.surfaceRect();\n var point = context.curtainProjection(loc);\n return {\n left: point[0] + rect.left - 40,\n top: point[1] + rect.top - 60,\n width: 80,\n height: 90\n };\n}\n\n\nexport function pad(locOrBox, padding, context) {\n var box;\n if (locOrBox instanceof Array) {\n var rect = context.surfaceRect();\n var point = context.curtainProjection(locOrBox);\n box = {\n left: point[0] + rect.left,\n top: point[1] + rect.top\n };\n } else {\n box = locOrBox;\n }\n\n return {\n left: box.left - padding,\n top: box.top - padding,\n width: (box.width || 0) + 2 * padding,\n height: (box.width || 0) + 2 * padding\n };\n}\n\n\nexport function icon(name, svgklass, useklass) {\n return '' +\n ' ';\n}\n\nvar helpStringReplacements;\n\n// Returns the localized string for `id` with a standardized set of icon, key, and\n// label replacements suitable for tutorials and documentation. Optionally supplemented\n// with custom `replacements`\nexport function helpString(id, replacements) {\n // only load these the first time\n if (!helpStringReplacements) helpStringReplacements = {\n // insert icons corresponding to various UI elements\n point_icon: icon('#iD-icon-point', 'pre-text'),\n line_icon: icon('#iD-icon-line', 'pre-text'),\n area_icon: icon('#iD-icon-area', 'pre-text'),\n note_icon: icon('#iD-icon-note', 'pre-text add-note'),\n plus: icon('#iD-icon-plus', 'pre-text'),\n minus: icon('#iD-icon-minus', 'pre-text'),\n move_icon: icon('#iD-operation-move', 'pre-text operation'),\n merge_icon: icon('#iD-operation-merge', 'pre-text operation'),\n delete_icon: icon('#iD-operation-delete', 'pre-text operation'),\n circularize_icon: icon('#iD-operation-circularize', 'pre-text operation'),\n split_icon: icon('#iD-operation-split', 'pre-text operation'),\n orthogonalize_icon: icon('#iD-operation-orthogonalize', 'pre-text operation'),\n disconnect_icon: icon('#iD-operation-disconnect', 'pre-text operation'),\n layers_icon: icon('#iD-icon-layers', 'pre-text'),\n data_icon: icon('#iD-icon-data', 'pre-text'),\n inspect: icon('#iD-icon-inspect', 'pre-text'),\n help_icon: icon('#iD-icon-help', 'pre-text'),\n undo_icon: icon(localizer.textDirection() === 'rtl' ? '#iD-icon-redo' : '#iD-icon-undo', 'pre-text'),\n redo_icon: icon(localizer.textDirection() === 'rtl' ? '#iD-icon-undo' : '#iD-icon-redo', 'pre-text'),\n save_icon: icon('#iD-icon-save', 'pre-text'),\n leftclick: icon('#iD-walkthrough-mouse-left', 'pre-text operation'),\n rightclick: icon('#iD-walkthrough-mouse-right', 'pre-text operation'),\n mousewheel_icon: icon('#iD-walkthrough-mousewheel', 'pre-text operation'),\n tap_icon: icon('#iD-walkthrough-tap', 'pre-text operation'),\n doubletap_icon: icon('#iD-walkthrough-doubletap', 'pre-text operation'),\n longpress_icon: icon('#iD-walkthrough-longpress', 'pre-text operation'),\n touchdrag_icon: icon('#iD-walkthrough-touchdrag', 'pre-text operation'),\n pinch_icon: icon('#iD-walkthrough-pinch-apart', 'pre-text operation'),\n\n // insert keys; may be localized and platform-dependent\n shift: uiCmd.display('⇧'),\n alt: uiCmd.display('⌥'),\n return: uiCmd.display('↵'),\n esc: t('shortcuts.key.esc'),\n space: t('shortcuts.key.space'),\n add_note_key: t('modes.add_note.key'),\n help_key: t('help.key'),\n shortcuts_key: t('shortcuts.toggle.key'),\n\n // reference localized UI labels directly so that they'll always match\n save: t('save.title'),\n undo: t('undo.title'),\n redo: t('redo.title'),\n upload: t('commit.save'),\n point: t('modes.add_point.title'),\n line: t('modes.add_line.title'),\n area: t('modes.add_area.title'),\n note: t('modes.add_note.title'),\n delete: t('operations.delete.title'),\n move: t('operations.move.title'),\n orthogonalize: t('operations.orthogonalize.title'),\n circularize: t('operations.circularize.title'),\n merge: t('operations.merge.title'),\n disconnect: t('operations.disconnect.title'),\n split: t('operations.split.title'),\n map_data: t('map_data.title'),\n osm_notes: t('map_data.layers.notes.title'),\n fields: t('inspector.fields'),\n tags: t('inspector.tags'),\n relations: t('inspector.relations'),\n new_relation: t('inspector.new_relation'),\n turn_restrictions: t('presets.fields.restrictions.label'),\n background_settings: t('background.description'),\n imagery_offset: t('background.fix_misalignment'),\n start_the_walkthrough: t('splash.walkthrough'),\n help: t('help.title'),\n ok: t('intro.ok')\n };\n\n var reps;\n if (replacements) {\n reps = Object.assign(replacements, helpStringReplacements);\n } else {\n reps = helpStringReplacements;\n }\n\n return t(id, reps)\n // use keyboard key styling for shortcuts\n .replace(/\\`(.*?)\\`/g, '$1 ');\n}\n\n\nfunction slugify(text) {\n return text.toString().toLowerCase()\n .replace(/\\s+/g, '-') // Replace spaces with -\n .replace(/[^\\w\\-]+/g, '') // Remove all non-word chars\n .replace(/\\-\\-+/g, '-') // Replace multiple - with single -\n .replace(/^-+/, '') // Trim - from start of text\n .replace(/-+$/, ''); // Trim - from end of text\n}\n\n\n// console warning for missing walkthrough names\nexport var missingStrings = {};\nfunction checkKey(key, text) {\n if (t(key, { default: undefined}) === undefined) {\n if (missingStrings.hasOwnProperty(key)) return; // warn once\n missingStrings[key] = text;\n var missing = key + ': ' + text;\n if (typeof console !== 'undefined') console.log(missing); // eslint-disable-line\n }\n}\n\n\nexport function localize(obj) {\n var key;\n\n // Assign name if entity has one..\n var name = obj.tags && obj.tags.name;\n if (name) {\n key = 'intro.graph.name.' + slugify(name);\n obj.tags.name = t(key, { default: name });\n checkKey(key, name);\n }\n\n // Assign street name if entity has one..\n var street = obj.tags && obj.tags['addr:street'];\n if (street) {\n key = 'intro.graph.name.' + slugify(street);\n obj.tags['addr:street'] = t(key, { default: street });\n checkKey(key, street);\n\n // Add address details common across walkthrough..\n var addrTags = [\n 'block_number', 'city', 'county', 'district', 'hamlet', 'neighbourhood',\n 'postcode', 'province', 'quarter', 'state', 'subdistrict', 'suburb'\n ];\n addrTags.forEach(function(k) {\n var key = 'intro.graph.' + k;\n var tag = 'addr:' + k;\n var val = obj.tags && obj.tags[tag];\n var str = t(key, { default: val });\n\n if (str) {\n if (str.match(/^<.*>$/) !== null) {\n delete obj.tags[tag];\n } else {\n obj.tags[tag] = str;\n }\n }\n });\n }\n\n return obj;\n}\n\n\n// Used to detect squareness.. some duplicataion of code from actionOrthogonalize.\nexport function isMostlySquare(points) {\n // note: uses 15 here instead of the 12 from actionOrthogonalize because\n // actionOrthogonalize can actually straighten some larger angles as it iterates\n var threshold = 15; // degrees within right or straight\n var lowerBound = Math.cos((90 - threshold) * Math.PI / 180); // near right\n var upperBound = Math.cos(threshold * Math.PI / 180); // near straight\n\n for (var i = 0; i < points.length; i++) {\n var a = points[(i - 1 + points.length) % points.length];\n var origin = points[i];\n var b = points[(i + 1) % points.length];\n\n var dotp = geoVecNormalizedDot(a, b, origin);\n var mag = Math.abs(dotp);\n if (mag > lowerBound && mag < upperBound) {\n return false;\n }\n }\n\n return true;\n}\n\n\nexport function selectMenuItem(context, operation) {\n return context.container().select('.edit-menu .edit-menu-item-' + operation);\n}\n\n\nexport function transitionTime(point1, point2) {\n var distance = geoSphericalDistance(point1, point2);\n if (distance === 0)\n return 0;\n else if (distance < 80)\n return 500;\n else\n return 1000;\n}\n","import {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport marked from 'marked';\nimport { t, localizer } from '../core/localizer';\nimport { svgIcon } from '../svg/icon';\nimport { icon } from './intro/helper';\n\n\n// This currently only works with the 'restrictions' field\n// It borrows some code from uiHelp\n\nexport function uiFieldHelp(context, fieldName) {\n var fieldHelp = {};\n var _inspector = d3_select(null);\n var _wrap = d3_select(null);\n var _body = d3_select(null);\n\n var fieldHelpKeys = {\n restrictions: [\n ['about',[\n 'about',\n 'from_via_to',\n 'maxdist',\n 'maxvia'\n ]],\n ['inspecting',[\n 'about',\n 'from_shadow',\n 'allow_shadow',\n 'restrict_shadow',\n 'only_shadow',\n 'restricted',\n 'only'\n ]],\n ['modifying',[\n 'about',\n 'indicators',\n 'allow_turn',\n 'restrict_turn',\n 'only_turn'\n ]],\n ['tips',[\n 'simple',\n 'simple_example',\n 'indirect',\n 'indirect_example',\n 'indirect_noedit'\n ]]\n ]\n };\n\n var fieldHelpHeadings = {};\n\n var replacements = {\n distField: t('restriction.controls.distance'),\n viaField: t('restriction.controls.via'),\n fromShadow: icon('#iD-turn-shadow', 'pre-text shadow from'),\n allowShadow: icon('#iD-turn-shadow', 'pre-text shadow allow'),\n restrictShadow: icon('#iD-turn-shadow', 'pre-text shadow restrict'),\n onlyShadow: icon('#iD-turn-shadow', 'pre-text shadow only'),\n allowTurn: icon('#iD-turn-yes', 'pre-text turn'),\n restrictTurn: icon('#iD-turn-no', 'pre-text turn'),\n onlyTurn: icon('#iD-turn-only', 'pre-text turn')\n };\n\n\n // For each section, squash all the texts into a single markdown document\n var docs = fieldHelpKeys[fieldName].map(function(key) {\n var helpkey = 'help.field.' + fieldName + '.' + key[0];\n var text = key[1].reduce(function(all, part) {\n var subkey = helpkey + '.' + part;\n var depth = fieldHelpHeadings[subkey]; // is this subkey a heading?\n var hhh = depth ? Array(depth + 1).join('#') + ' ' : ''; // if so, prepend with some ##'s\n return all + hhh + t(subkey, replacements) + '\\n\\n';\n }, '');\n\n return {\n key: helpkey,\n title: t(helpkey + '.title'),\n html: marked(text.trim())\n };\n });\n\n\n function show() {\n updatePosition();\n\n _body\n .classed('hide', false)\n .style('opacity', '0')\n .transition()\n .duration(200)\n .style('opacity', '1');\n }\n\n\n function hide() {\n _body\n .classed('hide', true)\n .transition()\n .duration(200)\n .style('opacity', '0')\n .on('end', function () {\n _body.classed('hide', true);\n });\n }\n\n\n function clickHelp(index) {\n var d = docs[index];\n var tkeys = fieldHelpKeys[fieldName][index][1];\n\n _body.selectAll('.field-help-nav-item')\n .classed('active', function(d, i) { return i === index; });\n\n var content = _body.selectAll('.field-help-content')\n .html(d.html);\n\n // class the paragraphs so we can find and style them\n content.selectAll('p')\n .attr('class', function(d, i) { return tkeys[i]; });\n\n // insert special content for certain help sections\n if (d.key === 'help.field.restrictions.inspecting') {\n content\n .insert('img', 'p.from_shadow')\n .attr('class', 'field-help-image cf')\n .attr('src', context.imagePath('tr_inspect.gif'));\n\n } else if (d.key === 'help.field.restrictions.modifying') {\n content\n .insert('img', 'p.allow_turn')\n .attr('class', 'field-help-image cf')\n .attr('src', context.imagePath('tr_modify.gif'));\n }\n }\n\n\n fieldHelp.button = function(selection) {\n if (_body.empty()) return;\n\n var button = selection.selectAll('.field-help-button')\n .data([0]);\n\n // enter/update\n button.enter()\n .append('button')\n .attr('class', 'field-help-button')\n .attr('tabindex', -1)\n .call(svgIcon('#iD-icon-help'))\n .merge(button)\n .on('click', function () {\n d3_event.stopPropagation();\n d3_event.preventDefault();\n if (_body.classed('hide')) {\n show();\n } else {\n hide();\n }\n });\n };\n\n\n function updatePosition() {\n var wrap = _wrap.node();\n var inspector = _inspector.node();\n var wRect = wrap.getBoundingClientRect();\n var iRect = inspector.getBoundingClientRect();\n\n _body\n .style('top', wRect.top + inspector.scrollTop - iRect.top + 'px');\n }\n\n\n fieldHelp.body = function(selection) {\n // This control expects the field to have a form-field-input-wrap div\n _wrap = selection.selectAll('.form-field-input-wrap');\n if (_wrap.empty()) return;\n\n // absolute position relative to the inspector, so it \"floats\" above the fields\n _inspector = context.container().select('.sidebar .entity-editor-pane .inspector-body');\n if (_inspector.empty()) return;\n\n _body = _inspector.selectAll('.field-help-body')\n .data([0]);\n\n var enter = _body.enter()\n .append('div')\n .attr('class', 'field-help-body hide'); // initially hidden\n\n var titleEnter = enter\n .append('div')\n .attr('class', 'field-help-title cf');\n\n titleEnter\n .append('h2')\n .attr('class', ((localizer.textDirection() === 'rtl') ? 'fr' : 'fl'))\n .text(t('help.field.' + fieldName + '.title'));\n\n titleEnter\n .append('button')\n .attr('class', 'fr close')\n .on('click', function() {\n d3_event.stopPropagation();\n d3_event.preventDefault();\n hide();\n })\n .call(svgIcon('#iD-icon-close'));\n\n var navEnter = enter\n .append('div')\n .attr('class', 'field-help-nav cf');\n\n var titles = docs.map(function(d) { return d.title; });\n navEnter.selectAll('.field-help-nav-item')\n .data(titles)\n .enter()\n .append('div')\n .attr('class', 'field-help-nav-item')\n .text(function(d) { return d; })\n .on('click', function(d, i) {\n d3_event.stopPropagation();\n d3_event.preventDefault();\n clickHelp(i);\n });\n\n enter\n .append('div')\n .attr('class', 'field-help-content');\n\n _body = _body\n .merge(enter);\n\n clickHelp(0);\n };\n\n\n return fieldHelp;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\n\nimport {\n select as d3_select,\n event as d3_event\n} from 'd3-selection';\n\nimport { utilRebind } from '../../util/rebind';\nimport { t } from '../../core/localizer';\nimport { actionReverse } from '../../actions/reverse';\nimport { osmOneWayTags } from '../../osm';\nimport { svgIcon } from '../../svg/icon';\n\nexport { uiFieldCheck as uiFieldDefaultCheck };\nexport { uiFieldCheck as uiFieldOnewayCheck };\n\n\nexport function uiFieldCheck(field, context) {\n var dispatch = d3_dispatch('change');\n var options = field.strings && field.strings.options;\n var values = [];\n var texts = [];\n\n var _tags;\n\n var input = d3_select(null);\n var text = d3_select(null);\n var label = d3_select(null);\n var reverser = d3_select(null);\n\n var _impliedYes;\n var _entityIDs = [];\n var _value;\n\n\n if (options) {\n for (var k in options) {\n values.push(k === 'undefined' ? undefined : k);\n texts.push(field.t('options.' + k, { 'default': options[k] }));\n }\n } else {\n values = [undefined, 'yes'];\n texts = [t('inspector.unknown'), t('inspector.check.yes')];\n if (field.type !== 'defaultCheck') {\n values.push('no');\n texts.push(t('inspector.check.no'));\n }\n }\n\n\n // Checks tags to see whether an undefined value is \"Assumed to be Yes\"\n function checkImpliedYes() {\n _impliedYes = (field.id === 'oneway_yes');\n\n // hack: pretend `oneway` field is a `oneway_yes` field\n // where implied oneway tag exists (e.g. `junction=roundabout`) #2220, #1841\n if (field.id === 'oneway') {\n var entity = context.entity(_entityIDs[0]);\n for (var key in entity.tags) {\n if (key in osmOneWayTags && (entity.tags[key] in osmOneWayTags[key])) {\n _impliedYes = true;\n texts[0] = t('presets.fields.oneway_yes.options.undefined');\n break;\n }\n }\n }\n }\n\n\n function reverserHidden() {\n if (!context.container().select('div.inspector-hover').empty()) return true;\n return !(_value === 'yes' || (_impliedYes && !_value));\n }\n\n\n function reverserSetText(selection) {\n var entity = _entityIDs.length && context.hasEntity(_entityIDs[0]);\n if (reverserHidden() || !entity) return selection;\n\n var first = entity.first();\n var last = entity.isClosed() ? entity.nodes[entity.nodes.length - 2] : entity.last();\n var pseudoDirection = first < last;\n var icon = pseudoDirection ? '#iD-icon-forward' : '#iD-icon-backward';\n\n selection.selectAll('.reverser-span')\n .text(t('inspector.check.reverser'))\n .call(svgIcon(icon, 'inline'));\n\n return selection;\n }\n\n\n var check = function(selection) {\n checkImpliedYes();\n\n label = selection.selectAll('.form-field-input-wrap')\n .data([0]);\n\n var enter = label.enter()\n .append('label')\n .attr('class', 'form-field-input-wrap form-field-input-check');\n\n enter\n .append('input')\n .property('indeterminate', field.type !== 'defaultCheck')\n .attr('type', 'checkbox')\n .attr('id', field.domId);\n\n enter\n .append('span')\n .text(texts[0])\n .attr('class', 'value');\n\n if (field.type === 'onewayCheck') {\n enter\n .append('a')\n .attr('class', 'reverser button' + (reverserHidden() ? ' hide' : ''))\n .attr('href', '#')\n .append('span')\n .attr('class', 'reverser-span');\n }\n\n label = label.merge(enter);\n input = label.selectAll('input');\n text = label.selectAll('span.value');\n\n input\n .on('click', function() {\n d3_event.stopPropagation();\n var t = {};\n\n if (Array.isArray(_tags[field.key])) {\n if (values.indexOf('yes') !== -1) {\n t[field.key] = 'yes';\n } else {\n t[field.key] = values[0];\n }\n } else {\n t[field.key] = values[(values.indexOf(_value) + 1) % values.length];\n }\n\n // Don't cycle through `alternating` or `reversible` states - #4970\n // (They are supported as translated strings, but should not toggle with clicks)\n if (t[field.key] === 'reversible' || t[field.key] === 'alternating') {\n t[field.key] = values[0];\n }\n\n dispatch.call('change', this, t);\n });\n\n if (field.type === 'onewayCheck') {\n reverser = label.selectAll('.reverser');\n\n reverser\n .call(reverserSetText)\n .on('click', function() {\n d3_event.preventDefault();\n d3_event.stopPropagation();\n context.perform(\n function(graph) {\n for (var i in _entityIDs) {\n graph = actionReverse(_entityIDs[i])(graph);\n }\n return graph;\n },\n t('operations.reverse.annotation')\n );\n\n // must manually revalidate since no 'change' event was called\n context.validator().validate();\n\n d3_select(this)\n .call(reverserSetText);\n });\n }\n };\n\n\n check.entityIDs = function(val) {\n if (!arguments.length) return _entityIDs;\n _entityIDs = val;\n return check;\n };\n\n\n check.tags = function(tags) {\n\n _tags = tags;\n\n function isChecked(val) {\n return val !== 'no' && val !== '' && val !== undefined && val !== null;\n }\n\n function textFor(val) {\n if (val === '') val = undefined;\n var index = values.indexOf(val);\n return (index !== -1 ? texts[index] : ('\"' + val + '\"'));\n }\n\n checkImpliedYes();\n\n var isMixed = Array.isArray(tags[field.key]);\n\n _value = !isMixed && tags[field.key] && tags[field.key].toLowerCase();\n\n if (field.type === 'onewayCheck' && (_value === '1' || _value === '-1')) {\n _value = 'yes';\n }\n\n input\n .property('indeterminate', isMixed || (field.type !== 'defaultCheck' && !_value))\n .property('checked', isChecked(_value));\n\n text\n .text(isMixed ? t('inspector.multiple_values') : textFor(_value))\n .classed('mixed', isMixed);\n\n label\n .classed('set', !!_value);\n\n if (field.type === 'onewayCheck') {\n reverser\n .classed('hide', reverserHidden())\n .call(reverserSetText);\n }\n };\n\n\n check.focus = function() {\n input.node().focus();\n };\n\n return utilRebind(check, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { event as d3_event, select as d3_select } from 'd3-selection';\nimport { drag as d3_drag } from 'd3-drag';\nimport * as countryCoder from '@ideditor/country-coder';\n\nimport { fileFetcher } from '../../core/file_fetcher';\nimport { osmEntity } from '../../osm/entity';\nimport { t } from '../../core/localizer';\nimport { services } from '../../services';\nimport { uiCombobox } from '../combobox';\nimport { utilArrayUniq, utilGetSetValue, utilNoAuto, utilRebind, utilTotalExtent, utilUnicodeCharsCount } from '../../util';\n\nexport {\n uiFieldCombo as uiFieldMultiCombo,\n uiFieldCombo as uiFieldNetworkCombo,\n uiFieldCombo as uiFieldSemiCombo,\n uiFieldCombo as uiFieldTypeCombo\n};\n\n\nexport function uiFieldCombo(field, context) {\n var dispatch = d3_dispatch('change');\n var taginfo = services.taginfo;\n var isMulti = (field.type === 'multiCombo');\n var isNetwork = (field.type === 'networkCombo');\n var isSemi = (field.type === 'semiCombo');\n var optstrings = field.strings && field.strings.options;\n var optarray = field.options;\n var snake_case = (field.snake_case || (field.snake_case === undefined));\n var caseSensitive = field.caseSensitive;\n var combobox = uiCombobox(context, 'combo-' + field.safeid)\n .caseSensitive(caseSensitive)\n .minItems(isMulti || isSemi ? 1 : 2);\n var container = d3_select(null);\n var inputWrap = d3_select(null);\n var input = d3_select(null);\n var _comboData = [];\n var _multiData = [];\n var _entityIDs = [];\n var _tags;\n var _countryCode;\n var _staticPlaceholder;\n\n // initialize deprecated tags array\n var _dataDeprecated = [];\n fileFetcher.get('deprecated')\n .then(function(d) { _dataDeprecated = d; })\n .catch(function() { /* ignore */ });\n\n\n // ensure multiCombo field.key ends with a ':'\n if (isMulti && /[^:]$/.test(field.key)) {\n field.key += ':';\n }\n\n\n function snake(s) {\n return s.replace(/\\s+/g, '_');\n }\n\n function unsnake(s) {\n return s.replace(/_+/g, ' ');\n }\n\n function clean(s) {\n return s.split(';')\n .map(function(s) { return s.trim(); })\n .join(';');\n }\n\n\n // returns the tag value for a display value\n // (for multiCombo, dval should be the key suffix, not the entire key)\n function tagValue(dval) {\n dval = clean(dval || '');\n\n if (optstrings) {\n var found = _comboData.find(function(o) {\n return o.key && clean(o.value) === dval;\n });\n if (found) {\n return found.key;\n }\n }\n\n if (field.type === 'typeCombo' && !dval) {\n return 'yes';\n }\n\n return (snake_case ? snake(dval) : dval) || undefined;\n }\n\n\n // returns the display value for a tag value\n // (for multiCombo, tval should be the key suffix, not the entire key)\n function displayValue(tval) {\n tval = tval || '';\n\n if (optstrings) {\n var found = _comboData.find(function(o) {\n return o.key === tval && o.value;\n });\n if (found) {\n return found.value;\n }\n }\n\n if (field.type === 'typeCombo' && tval.toLowerCase() === 'yes') {\n return '';\n }\n\n return snake_case ? unsnake(tval) : tval;\n }\n\n\n // Compute the difference between arrays of objects by `value` property\n //\n // objectDifference([{value:1}, {value:2}, {value:3}], [{value:2}])\n // > [{value:1}, {value:3}]\n //\n function objectDifference(a, b) {\n return a.filter(function(d1) {\n return !b.some(function(d2) {\n return !d2.isMixed && d1.value === d2.value;\n });\n });\n }\n\n\n function initCombo(selection, attachTo) {\n if (optstrings) {\n selection.attr('readonly', 'readonly');\n selection.call(combobox, attachTo);\n setStaticValues(setPlaceholder);\n\n } else if (optarray) {\n selection.call(combobox, attachTo);\n setStaticValues(setPlaceholder);\n\n } else if (taginfo) {\n selection.call(combobox.fetcher(setTaginfoValues), attachTo);\n setTaginfoValues('', setPlaceholder);\n }\n }\n\n\n function setStaticValues(callback) {\n if (!(optstrings || optarray)) return;\n\n if (optstrings) {\n _comboData = Object.keys(optstrings).map(function(k) {\n var v = field.t('options.' + k, { 'default': optstrings[k] });\n return {\n key: k,\n value: v,\n title: v\n };\n });\n\n } else if (optarray) {\n _comboData = optarray.map(function(k) {\n var v = snake_case ? unsnake(k) : k;\n return {\n key: k,\n value: v,\n title: v\n };\n });\n }\n\n combobox.data(objectDifference(_comboData, _multiData));\n if (callback) callback(_comboData);\n }\n\n\n function setTaginfoValues(q, callback) {\n var fn = isMulti ? 'multikeys' : 'values';\n var query = (isMulti ? field.key : '') + q;\n var hasCountryPrefix = isNetwork && _countryCode && _countryCode.indexOf(q.toLowerCase()) === 0;\n if (hasCountryPrefix) {\n query = _countryCode + ':';\n }\n\n var params = {\n debounce: (q !== ''),\n key: field.key,\n query: query\n };\n\n if (_entityIDs.length) {\n params.geometry = context.graph().geometry(_entityIDs[0]);\n }\n\n taginfo[fn](params, function(err, data) {\n if (err) return;\n\n data = data.filter(function(d) {\n\n if (field.type === 'typeCombo' && d.value === 'yes') {\n // don't show the fallback value\n return false;\n }\n\n // don't show values with very low usage\n return !d.count || d.count > 10;\n });\n\n var deprecatedValues = osmEntity.deprecatedTagValuesByKey(_dataDeprecated)[field.key];\n if (deprecatedValues) {\n // don't suggest deprecated tag values\n data = data.filter(function(d) {\n return deprecatedValues.indexOf(d.value) === -1;\n });\n }\n\n if (hasCountryPrefix) {\n data = data.filter(function(d) {\n return d.value.toLowerCase().indexOf(_countryCode + ':') === 0;\n });\n }\n\n // hide the caret if there are no suggestions\n container.classed('empty-combobox', data.length === 0);\n\n _comboData = data.map(function(d) {\n var k = d.value;\n if (isMulti) k = k.replace(field.key, '');\n var v = snake_case ? unsnake(k) : k;\n return {\n key: k,\n value: v,\n title: isMulti ? v : d.title\n };\n });\n\n _comboData = objectDifference(_comboData, _multiData);\n if (callback) callback(_comboData);\n });\n }\n\n\n function setPlaceholder(values) {\n\n if (isMulti || isSemi) {\n _staticPlaceholder = field.placeholder() || t('inspector.add');\n } else {\n var vals = values\n .map(function(d) { return d.value; })\n .filter(function(s) { return s.length < 20; });\n\n var placeholders = vals.length > 1 ? vals : values.map(function(d) { return d.key; });\n _staticPlaceholder = field.placeholder() || placeholders.slice(0, 3).join(', ');\n }\n\n if (!/(…|\\.\\.\\.)$/.test(_staticPlaceholder)) {\n _staticPlaceholder += '…';\n }\n\n var ph;\n if (!isMulti && !isSemi && _tags && Array.isArray(_tags[field.key])) {\n ph = t('inspector.multiple_values');\n } else {\n ph = _staticPlaceholder;\n }\n\n container.selectAll('input')\n .attr('placeholder', ph);\n }\n\n\n function change() {\n var t = {};\n var val;\n\n if (isMulti || isSemi) {\n val = tagValue(utilGetSetValue(input).replace(/,/g, ';')) || '';\n container.classed('active', false);\n utilGetSetValue(input, '');\n\n var vals = val.split(';').filter(Boolean);\n if (!vals.length) return;\n\n if (isMulti) {\n utilArrayUniq(vals).forEach(function(v) {\n var key = field.key + v;\n if (_tags) {\n // don't set a multicombo value to 'yes' if it already has a non-'no' value\n // e.g. `language:de=main`\n var old = _tags[key];\n if (typeof old === 'string' && old.toLowerCase() !== 'no') return;\n }\n key = context.cleanTagKey(key);\n field.keys.push(key);\n t[key] = 'yes';\n });\n\n } else if (isSemi) {\n var arr = _multiData.map(function(d) { return d.key; });\n arr = arr.concat(vals);\n t[field.key] = context.cleanTagValue(utilArrayUniq(arr).filter(Boolean).join(';'));\n }\n\n window.setTimeout(function() { input.node().focus(); }, 10);\n\n } else {\n var rawValue = utilGetSetValue(input);\n\n // don't override multiple values with blank string\n if (!rawValue && Array.isArray(_tags[field.key])) return;\n\n val = context.cleanTagValue(tagValue(rawValue));\n t[field.key] = val || undefined;\n }\n\n dispatch.call('change', this, t);\n }\n\n\n function isFbRoadId (entity) {\n if (entity.id) {\n return entity.id.startswith('w-');\n } else {\n return false;\n }\n }\n\n \n function removeMultikey(d) {\n d3_event.stopPropagation();\n\n // don't move source=digitalglobe or source=maxar on ML road\n // TODO: switch to check on __fbid__\n if (field.key === 'source' && _entityIDs[0] && isFbRoadId(_entityIDs[0]) && (d.value === 'digitalglobe' || d.value === 'maxar')) return;\n var t = {};\n if (isMulti) {\n t[d.key] = undefined;\n } else if (isSemi) {\n var arr = _multiData.map(function(md) {\n return md.key === d.key ? null : md.key;\n }).filter(Boolean);\n\n arr = utilArrayUniq(arr);\n t[field.key] = arr.length ? arr.join(';') : undefined;\n }\n dispatch.call('change', this, t);\n }\n\n\n function combo(selection) {\n container = selection.selectAll('.form-field-input-wrap')\n .data([0]);\n\n var type = (isMulti || isSemi) ? 'multicombo': 'combo';\n container = container.enter()\n .append('div')\n .attr('class', 'form-field-input-wrap form-field-input-' + type)\n .merge(container);\n\n if (isMulti || isSemi) {\n container = container.selectAll('.chiplist')\n .data([0]);\n\n var listClass = 'chiplist';\n\n // Use a separate line for each value in the Destinations field\n // to mimic highway exit signs\n if (field.key === 'destination') {\n listClass += ' full-line-chips';\n }\n\n container = container.enter()\n .append('ul')\n .attr('class', listClass)\n .on('click', function() {\n window.setTimeout(function() { input.node().focus(); }, 10);\n })\n .merge(container);\n\n\n inputWrap = container.selectAll('.input-wrap')\n .data([0]);\n\n inputWrap = inputWrap.enter()\n .append('li')\n .attr('class', 'input-wrap')\n .merge(inputWrap);\n\n input = inputWrap.selectAll('input')\n .data([0]);\n } else {\n input = container.selectAll('input')\n .data([0]);\n }\n\n input = input.enter()\n .append('input')\n .attr('type', 'text')\n .attr('id', field.domId)\n .call(utilNoAuto)\n .call(initCombo, selection)\n .merge(input);\n\n if (isNetwork) {\n var extent = combinedEntityExtent();\n var countryCode = extent && countryCoder.iso1A2Code(extent.center());\n _countryCode = countryCode && countryCode.toLowerCase();\n }\n\n input\n .on('change', change)\n .on('blur', change);\n\n input\n .on('keydown.field', function() {\n switch (d3_event.keyCode) {\n case 13: // ↩ Return\n input.node().blur(); // blurring also enters the value\n d3_event.stopPropagation();\n break;\n }\n });\n\n if (isMulti || isSemi) {\n combobox\n .on('accept', function() {\n input.node().blur();\n input.node().focus();\n });\n\n input\n .on('focus', function() { container.classed('active', true); });\n }\n }\n\n\n combo.tags = function(tags) {\n _tags = tags;\n\n if (isMulti || isSemi) {\n _multiData = [];\n\n var maxLength;\n\n if (isMulti) {\n // Build _multiData array containing keys already set..\n for (var k in tags) {\n if (k.indexOf(field.key) !== 0) continue;\n var v = tags[k];\n if (!v || (typeof v === 'string' && v.toLowerCase() === 'no')) continue;\n\n var suffix = k.substring(field.key.length);\n _multiData.push({\n key: k,\n value: displayValue(suffix),\n isMixed: Array.isArray(v)\n });\n }\n\n // Set keys for form-field modified (needed for undo and reset buttons)..\n field.keys = _multiData.map(function(d) { return d.key; });\n\n // limit the input length so it fits after prepending the key prefix\n maxLength = context.maxCharsForTagKey() - utilUnicodeCharsCount(field.key);\n\n } else if (isSemi) {\n\n var allValues = [];\n var commonValues;\n if (Array.isArray(tags[field.key])) {\n\n tags[field.key].forEach(function(tagVal) {\n var thisVals = utilArrayUniq((tagVal || '').split(';')).filter(Boolean);\n allValues = allValues.concat(thisVals);\n if (!commonValues) {\n commonValues = thisVals;\n } else {\n commonValues = commonValues.filter(value => thisVals.includes(value));\n }\n });\n allValues = utilArrayUniq(allValues).filter(Boolean);\n\n } else {\n allValues = utilArrayUniq((tags[field.key] || '').split(';')).filter(Boolean);\n commonValues = allValues;\n }\n\n _multiData = allValues.map(function(v) {\n return {\n key: v,\n value: displayValue(v),\n isMixed: !commonValues.includes(v)\n };\n });\n\n var currLength = utilUnicodeCharsCount(commonValues.join(';'));\n\n // limit the input length to the remaining available characters\n maxLength = context.maxCharsForTagValue() - currLength;\n\n if (currLength > 0) {\n // account for the separator if a new value will be appended to existing\n maxLength -= 1;\n }\n }\n // a negative maxlength doesn't make sense\n maxLength = Math.max(0, maxLength);\n\n var allowDragAndDrop = isSemi // only semiCombo values are ordered\n && !Array.isArray(tags[field.key]);\n\n // Exclude existing multikeys from combo options..\n var available = objectDifference(_comboData, _multiData);\n combobox.data(available);\n\n // Hide 'Add' button if this field uses fixed set of\n // translateable optstrings and they're all currently used,\n // or if the field is already at its character limit\n var hideAdd = (optstrings && !available.length) || maxLength <= 0;\n container.selectAll('.chiplist .input-wrap')\n .style('display', hideAdd ? 'none' : null);\n\n\n // Render chips\n var chips = container.selectAll('.chip')\n .data(_multiData);\n\n chips.exit()\n .remove();\n\n var enter = chips.enter()\n .insert('li', '.input-wrap')\n .attr('class', 'chip');\n\n enter.append('span');\n enter.append('a');\n\n chips = chips.merge(enter)\n .order()\n .classed('draggable', allowDragAndDrop)\n .classed('mixed', function(d) {\n return d.isMixed;\n })\n .attr('title', function(d) {\n return d.isMixed ? t('inspector.unshared_value_tooltip') : null;\n });\n\n if (allowDragAndDrop) {\n registerDragAndDrop(chips);\n }\n\n chips.select('span')\n .text(function(d) { return d.value; });\n\n chips.select('a')\n .on('click', removeMultikey)\n .attr('class', 'remove')\n .text(function(d) {\n // don't show 'x' on the digitalglobe/maxar label on ML road\n // TODO: switch to check on __fbid__\n return _entityIDs[0] && isFbRoadId(_entityIDs[0]) && field.key === 'source' && (d.value === 'digitalglobe' || d.value === 'maxar') ? '' : '×';\n });\n\n } else {\n var isMixed = Array.isArray(tags[field.key]);\n\n var mixedValues = isMixed && tags[field.key].map(function(val) {\n return displayValue(val);\n }).filter(Boolean);\n\n utilGetSetValue(input, !isMixed ? displayValue(tags[field.key]) : '')\n .attr('title', isMixed ? mixedValues.join('\\n') : undefined)\n .attr('placeholder', isMixed ? t('inspector.multiple_values') : _staticPlaceholder || '')\n .classed('mixed', isMixed);\n }\n };\n\n function registerDragAndDrop(selection) {\n\n // allow drag and drop re-ordering of chips\n var dragOrigin, targetIndex;\n selection.call(d3_drag()\n .on('start', function() {\n dragOrigin = {\n x: d3_event.x,\n y: d3_event.y\n };\n targetIndex = null;\n })\n .on('drag', function(d, index) {\n var x = d3_event.x - dragOrigin.x,\n y = d3_event.y - dragOrigin.y;\n\n if (!d3_select(this).classed('dragging') &&\n // don't display drag until dragging beyond a distance threshold\n Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)) <= 5) return;\n\n d3_select(this)\n .classed('dragging', true);\n\n targetIndex = null;\n var targetIndexOffsetTop = null;\n var draggedTagWidth = d3_select(this).node().offsetWidth;\n\n if (field.key === 'destination') { // meaning tags are full width\n container.selectAll('.chip')\n .style('transform', function(d2, index2) {\n var node = d3_select(this).node();\n\n if (index === index2) {\n return 'translate(' + x + 'px, ' + y + 'px)';\n // move the dragged tag up the order\n } else if (index2 > index && d3_event.y > node.offsetTop) {\n if (targetIndex === null || index2 > targetIndex) {\n targetIndex = index2;\n }\n return 'translateY(-100%)';\n // move the dragged tag down the order\n } else if (index2 < index && d3_event.y < node.offsetTop + node.offsetHeight) {\n if (targetIndex === null || index2 < targetIndex) {\n targetIndex = index2;\n }\n return 'translateY(100%)';\n }\n return null;\n });\n } else {\n container.selectAll('.chip')\n .each(function(d2, index2) {\n var node = d3_select(this).node();\n\n // check the cursor is in the bounding box\n if (\n index !== index2 &&\n d3_event.x < node.offsetLeft + node.offsetWidth + 5 &&\n d3_event.x > node.offsetLeft &&\n d3_event.y < node.offsetTop + node.offsetHeight &&\n d3_event.y > node.offsetTop\n ) {\n targetIndex = index2;\n targetIndexOffsetTop = node.offsetTop;\n }\n })\n .style('transform', function(d2, index2) {\n var node = d3_select(this).node();\n\n if (index === index2) {\n return 'translate(' + x + 'px, ' + y + 'px)';\n }\n\n // only translate tags in the same row\n if (node.offsetTop === targetIndexOffsetTop) {\n if (index2 < index && index2 >= targetIndex) {\n return 'translateX(' + draggedTagWidth + 'px)';\n } else if (index2 > index && index2 <= targetIndex) {\n return 'translateX(-' + draggedTagWidth + 'px)';\n }\n }\n return null;\n });\n }\n })\n .on('end', function(d, index) {\n if (!d3_select(this).classed('dragging')) {\n return;\n }\n\n d3_select(this)\n .classed('dragging', false);\n\n container.selectAll('.chip')\n .style('transform', null);\n\n if (typeof targetIndex === 'number') {\n var element = _multiData[index];\n _multiData.splice(index, 1);\n _multiData.splice(targetIndex, 0, element);\n\n var t = {};\n\n if (_multiData.length) {\n t[field.key] = _multiData.map(function(element) {\n return element.key;\n }).join(';');\n } else {\n t[field.key] = undefined;\n }\n\n dispatch.call('change', this, t);\n }\n dragOrigin = undefined;\n targetIndex = undefined;\n })\n );\n }\n\n\n combo.focus = function() {\n input.node().focus();\n };\n\n\n combo.entityIDs = function(val) {\n if (!arguments.length) return _entityIDs;\n _entityIDs = val;\n return combo;\n };\n\n\n function combinedEntityExtent() {\n return _entityIDs && _entityIDs.length && utilTotalExtent(_entityIDs, context.graph());\n }\n\n\n return utilRebind(combo, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { select as d3_select, event as d3_event } from 'd3-selection';\nimport * as countryCoder from '@ideditor/country-coder';\n\nimport { presetManager } from '../../presets';\nimport { fileFetcher } from '../../core/file_fetcher';\nimport { t, localizer } from '../../core/localizer';\nimport { utilGetSetValue, utilNoAuto, utilRebind, utilTotalExtent } from '../../util';\nimport { svgIcon } from '../../svg/icon';\n\nexport {\n uiFieldText as uiFieldUrl,\n uiFieldText as uiFieldIdentifier,\n uiFieldText as uiFieldNumber,\n uiFieldText as uiFieldTel,\n uiFieldText as uiFieldEmail\n};\n\n\nexport function uiFieldText(field, context) {\n var dispatch = d3_dispatch('change');\n var input = d3_select(null);\n var outlinkButton = d3_select(null);\n var _entityIDs = [];\n var _tags;\n var _phoneFormats = {};\n\n if (field.type === 'tel') {\n fileFetcher.get('phone_formats')\n .then(function(d) {\n _phoneFormats = d;\n updatePhonePlaceholder();\n })\n .catch(function() { /* ignore */ });\n }\n\n function i(selection) {\n var entity = _entityIDs.length && context.hasEntity(_entityIDs[0]);\n var preset = entity && presetManager.match(entity, context.graph());\n var isLocked = preset && preset.suggestion && field.id === 'brand';\n field.locked(isLocked);\n\n var wrap = selection.selectAll('.form-field-input-wrap')\n .data([0]);\n\n wrap = wrap.enter()\n .append('div')\n .attr('class', 'form-field-input-wrap form-field-input-' + field.type)\n .merge(wrap);\n\n input = wrap.selectAll('input')\n .data([0]);\n\n input = input.enter()\n .append('input')\n .attr('type', field.type === 'identifier' ? 'text' : field.type)\n .attr('id', field.domId)\n .classed(field.type, true)\n .call(utilNoAuto)\n .merge(input);\n\n input\n .classed('disabled', !!isLocked)\n .attr('readonly', isLocked || null)\n .on('input', change(true))\n .on('blur', change())\n .on('change', change());\n\n\n if (field.type === 'tel') {\n updatePhonePlaceholder();\n\n } else if (field.type === 'number') {\n var rtl = (localizer.textDirection() === 'rtl');\n\n input.attr('type', 'text');\n\n var buttons = wrap.selectAll('.increment, .decrement')\n .data(rtl ? [1, -1] : [-1, 1]);\n\n buttons.enter()\n .append('button')\n .attr('tabindex', -1)\n .attr('class', function(d) {\n var which = (d === 1 ? 'increment' : 'decrement');\n return 'form-field-button ' + which;\n })\n .merge(buttons)\n .on('click', function(d) {\n d3_event.preventDefault();\n var raw_vals = input.node().value || '0';\n var vals = raw_vals.split(';');\n vals = vals.map(function(v) {\n var num = parseFloat(v.trim(), 10);\n return isFinite(num) ? clamped(num + d) : v.trim();\n });\n input.node().value = vals.join(';');\n change()();\n });\n } else if (field.type === 'identifier' && field.urlFormat && field.pattern) {\n\n input.attr('type', 'text');\n\n outlinkButton = wrap.selectAll('.foreign-id-permalink')\n .data([0]);\n\n outlinkButton.enter()\n .append('button')\n .attr('tabindex', -1)\n .call(svgIcon('#iD-icon-out-link'))\n .attr('class', 'form-field-button foreign-id-permalink')\n .attr('title', function() {\n var domainResults = /^https?:\\/\\/(.{1,}?)\\//.exec(field.urlFormat);\n if (domainResults.length >= 2 && domainResults[1]) {\n var domain = domainResults[1];\n return t('icons.view_on', { domain: domain });\n }\n return '';\n })\n .on('click', function() {\n d3_event.preventDefault();\n\n var value = validIdentifierValueForLink();\n if (value) {\n var url = field.urlFormat.replace(/{value}/, encodeURIComponent(value));\n window.open(url, '_blank');\n }\n })\n .merge(outlinkButton);\n }\n }\n\n\n function updatePhonePlaceholder() {\n if (input.empty() || !Object.keys(_phoneFormats).length) return;\n\n var extent = combinedEntityExtent();\n var countryCode = extent && countryCoder.iso1A2Code(extent.center());\n var format = countryCode && _phoneFormats[countryCode.toLowerCase()];\n if (format) input.attr('placeholder', format);\n }\n\n\n function validIdentifierValueForLink() {\n if (field.type === 'identifier' && field.pattern) {\n var value = utilGetSetValue(input).trim().split(';')[0];\n return value && value.match(new RegExp(field.pattern));\n }\n return null;\n }\n\n\n // clamp number to min/max\n function clamped(num) {\n if (field.minValue !== undefined) {\n num = Math.max(num, field.minValue);\n }\n if (field.maxValue !== undefined) {\n num = Math.min(num, field.maxValue);\n }\n return num;\n }\n\n\n function change(onInput) {\n return function() {\n var t = {};\n var val = utilGetSetValue(input);\n if (!onInput) val = context.cleanTagValue(val);\n\n // don't override multiple values with blank string\n if (!val && Array.isArray(_tags[field.key])) return;\n\n if (!onInput) {\n if (field.type === 'number' && val) {\n var vals = val.split(';');\n vals = vals.map(function(v) {\n var num = parseFloat(v.trim(), 10);\n return isFinite(num) ? clamped(num) : v.trim();\n });\n val = vals.join(';');\n }\n utilGetSetValue(input, val);\n }\n t[field.key] = val || undefined;\n dispatch.call('change', this, t, onInput);\n };\n }\n\n\n i.entityIDs = function(val) {\n if (!arguments.length) return _entityIDs;\n _entityIDs = val;\n return i;\n };\n\n\n i.tags = function(tags) {\n _tags = tags;\n\n var isMixed = Array.isArray(tags[field.key]);\n\n utilGetSetValue(input, !isMixed && tags[field.key] ? tags[field.key] : '')\n .attr('title', isMixed ? tags[field.key].filter(Boolean).join('\\n') : undefined)\n .attr('placeholder', isMixed ? t('inspector.multiple_values') : (field.placeholder() || t('inspector.unknown')))\n .classed('mixed', isMixed);\n\n if (outlinkButton && !outlinkButton.empty()) {\n var disabled = !validIdentifierValueForLink();\n outlinkButton.classed('disabled', disabled);\n }\n };\n\n\n i.focus = function() {\n var node = input.node();\n if (node) node.focus();\n };\n\n function combinedEntityExtent() {\n return _entityIDs && _entityIDs.length && utilTotalExtent(_entityIDs, context.graph());\n }\n\n return utilRebind(i, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { select as d3_select } from 'd3-selection';\n\nimport { uiCombobox } from '../combobox';\nimport { utilGetSetValue, utilNoAuto, utilRebind } from '../../util';\nimport { t } from '../../core/localizer';\n\nexport function uiFieldAccess(field, context) {\n var dispatch = d3_dispatch('change');\n var items = d3_select(null);\n var _tags;\n\n function access(selection) {\n var wrap = selection.selectAll('.form-field-input-wrap')\n .data([0]);\n\n wrap = wrap.enter()\n .append('div')\n .attr('class', 'form-field-input-wrap form-field-input-' + field.type)\n .merge(wrap);\n\n var list = wrap.selectAll('ul')\n .data([0]);\n\n list = list.enter()\n .append('ul')\n .attr('class', 'rows')\n .merge(list);\n\n\n items = list.selectAll('li')\n .data(field.keys);\n\n // Enter\n var enter = items.enter()\n .append('li')\n .attr('class', function(d) { return 'labeled-input preset-access-' + d; });\n\n enter\n .append('span')\n .attr('class', 'label preset-label-access')\n .attr('for', function(d) { return 'preset-input-access-' + d; })\n .text(function(d) { return field.t('types.' + d); });\n\n enter\n .append('div')\n .attr('class', 'preset-input-access-wrap')\n .append('input')\n .attr('type', 'text')\n .attr('class', function(d) { return 'preset-input-access preset-input-access-' + d; })\n .call(utilNoAuto)\n .each(function(d) {\n d3_select(this)\n .call(uiCombobox(context, 'access-' + d)\n .data(access.options(d))\n );\n });\n\n\n // Update\n items = items.merge(enter);\n\n wrap.selectAll('.preset-input-access')\n .on('change', change)\n .on('blur', change);\n }\n\n\n function change(d) {\n var tag = {};\n var value = context.cleanTagValue(utilGetSetValue(d3_select(this)));\n\n // don't override multiple values with blank string\n if (!value && typeof _tags[d] !== 'string') return;\n\n tag[d] = value || undefined;\n dispatch.call('change', this, tag);\n }\n\n\n access.options = function(type) {\n var options = ['no', 'permissive', 'private', 'permit', 'destination'];\n\n if (type !== 'access') {\n options.unshift('yes');\n options.push('designated');\n\n if (type === 'bicycle') {\n options.push('dismount');\n }\n }\n\n return options.map(function(option) {\n return {\n title: field.t('options.' + option + '.description'),\n value: option\n };\n });\n };\n\n\n var placeholdersByHighway = {\n footway: {\n foot: 'designated',\n motor_vehicle: 'no'\n },\n steps: {\n foot: 'yes',\n motor_vehicle: 'no',\n bicycle: 'no',\n horse: 'no'\n },\n pedestrian: {\n foot: 'yes',\n motor_vehicle: 'no'\n },\n cycleway: {\n motor_vehicle: 'no',\n bicycle: 'designated'\n },\n bridleway: {\n motor_vehicle: 'no',\n horse: 'designated'\n },\n path: {\n foot: 'yes',\n motor_vehicle: 'no',\n bicycle: 'yes',\n horse: 'yes'\n },\n motorway: {\n foot: 'no',\n motor_vehicle: 'yes',\n bicycle: 'no',\n horse: 'no'\n },\n trunk: {\n motor_vehicle: 'yes'\n },\n primary: {\n foot: 'yes',\n motor_vehicle: 'yes',\n bicycle: 'yes',\n horse: 'yes'\n },\n secondary: {\n foot: 'yes',\n motor_vehicle: 'yes',\n bicycle: 'yes',\n horse: 'yes'\n },\n tertiary: {\n foot: 'yes',\n motor_vehicle: 'yes',\n bicycle: 'yes',\n horse: 'yes'\n },\n residential: {\n foot: 'yes',\n motor_vehicle: 'yes',\n bicycle: 'yes',\n horse: 'yes'\n },\n unclassified: {\n foot: 'yes',\n motor_vehicle: 'yes',\n bicycle: 'yes',\n horse: 'yes'\n },\n service: {\n foot: 'yes',\n motor_vehicle: 'yes',\n bicycle: 'yes',\n horse: 'yes'\n },\n motorway_link: {\n foot: 'no',\n motor_vehicle: 'yes',\n bicycle: 'no',\n horse: 'no'\n },\n trunk_link: {\n motor_vehicle: 'yes'\n },\n primary_link: {\n foot: 'yes',\n motor_vehicle: 'yes',\n bicycle: 'yes',\n horse: 'yes'\n },\n secondary_link: {\n foot: 'yes',\n motor_vehicle: 'yes',\n bicycle: 'yes',\n horse: 'yes'\n },\n tertiary_link: {\n foot: 'yes',\n motor_vehicle: 'yes',\n bicycle: 'yes',\n horse: 'yes'\n }\n };\n\n\n access.tags = function(tags) {\n _tags = tags;\n\n utilGetSetValue(items.selectAll('.preset-input-access'), function(d) {\n return typeof tags[d] === 'string' ? tags[d] : '';\n })\n .classed('mixed', function(d) {\n return tags[d] && Array.isArray(tags[d]);\n })\n .attr('title', function(d) {\n return tags[d] && Array.isArray(tags[d]) && tags[d].filter(Boolean).join('\\n');\n })\n .attr('placeholder', function(d) {\n if (tags[d] && Array.isArray(tags[d])) {\n return t('inspector.multiple_values');\n }\n if (d === 'access') {\n return 'yes';\n }\n if (tags.access && typeof tags.access === 'string') {\n return tags.access;\n }\n if (tags.highway) {\n if (typeof tags.highway === 'string') {\n if (placeholdersByHighway[tags.highway] &&\n placeholdersByHighway[tags.highway][d]) {\n\n return placeholdersByHighway[tags.highway][d];\n }\n } else {\n var impliedAccesses = tags.highway.filter(Boolean).map(function(highwayVal) {\n return placeholdersByHighway[highwayVal] && placeholdersByHighway[highwayVal][d];\n }).filter(Boolean);\n\n if (impliedAccesses.length === tags.highway.length &&\n new Set(impliedAccesses).size === 1) {\n // if all the highway values have the same implied access for this type then use that\n return impliedAccesses[0];\n }\n }\n }\n return field.placeholder();\n });\n };\n\n\n access.focus = function() {\n items.selectAll('.preset-input-access')\n .node().focus();\n };\n\n\n return utilRebind(access, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { select as d3_select } from 'd3-selection';\nimport * as countryCoder from '@ideditor/country-coder';\n\nimport { presetManager } from '../../presets';\nimport { fileFetcher } from '../../core/file_fetcher';\nimport { geoExtent, geoChooseEdge, geoSphericalDistance } from '../../geo';\nimport { uiCombobox } from '../combobox';\nimport { utilArrayUniqBy, utilGetSetValue, utilNoAuto, utilRebind, utilTotalExtent } from '../../util';\nimport { t } from '../../core/localizer';\n\n\nexport function uiFieldAddress(field, context) {\n var dispatch = d3_dispatch('change');\n var _selection = d3_select(null);\n var _wrap = d3_select(null);\n var addrField = presetManager.field('address'); // needed for placeholder strings\n\n var _entityIDs = [];\n var _tags;\n var _countryCode;\n var _addressFormats = [{\n format: [\n ['housenumber', 'street'],\n ['city', 'postcode']\n ]\n }];\n\n fileFetcher.get('address_formats')\n .then(function(d) {\n _addressFormats = d;\n if (!_selection.empty()) {\n _selection.call(address);\n }\n })\n .catch(function() { /* ignore */ });\n\n\n function getNearStreets() {\n var extent = combinedEntityExtent();\n var l = extent.center();\n var box = geoExtent(l).padByMeters(200);\n\n var streets = context.history().intersects(box)\n .filter(isAddressable)\n .map(function(d) {\n var loc = context.projection([\n (extent[0][0] + extent[1][0]) / 2,\n (extent[0][1] + extent[1][1]) / 2\n ]);\n var choice = geoChooseEdge(context.graph().childNodes(d), loc, context.projection);\n\n return {\n title: d.tags.name,\n value: d.tags.name,\n dist: choice.distance\n };\n })\n .sort(function(a, b) {\n return a.dist - b.dist;\n });\n\n return utilArrayUniqBy(streets, 'value');\n\n function isAddressable(d) {\n return d.tags.highway && d.tags.name && d.type === 'way';\n }\n }\n\n\n function getNearCities() {\n var extent = combinedEntityExtent();\n var l = extent.center();\n var box = geoExtent(l).padByMeters(200);\n\n var cities = context.history().intersects(box)\n .filter(isAddressable)\n .map(function(d) {\n return {\n title: d.tags['addr:city'] || d.tags.name,\n value: d.tags['addr:city'] || d.tags.name,\n dist: geoSphericalDistance(d.extent(context.graph()).center(), l)\n };\n })\n .sort(function(a, b) {\n return a.dist - b.dist;\n });\n\n return utilArrayUniqBy(cities, 'value');\n\n\n function isAddressable(d) {\n if (d.tags.name) {\n if (d.tags.admin_level === '8' && d.tags.boundary === 'administrative')\n return true;\n if (d.tags.border_type === 'city')\n return true;\n if (d.tags.place === 'city' || d.tags.place === 'town' || d.tags.place === 'village')\n return true;\n }\n\n if (d.tags['addr:city'])\n return true;\n\n return false;\n }\n }\n\n function getNearValues(key) {\n var extent = combinedEntityExtent();\n var l = extent.center();\n var box = geoExtent(l).padByMeters(200);\n\n var results = context.history().intersects(box)\n .filter(function hasTag(d) { return _entityIDs.indexOf(d.id) === -1 && d.tags[key]; })\n .map(function(d) {\n return {\n title: d.tags[key],\n value: d.tags[key],\n dist: geoSphericalDistance(d.extent(context.graph()).center(), l)\n };\n })\n .sort(function(a, b) {\n return a.dist - b.dist;\n });\n\n return utilArrayUniqBy(results, 'value');\n }\n\n\n function updateForCountryCode() {\n\n if (!_countryCode) return;\n\n var addressFormat;\n for (var i = 0; i < _addressFormats.length; i++) {\n var format = _addressFormats[i];\n if (!format.countryCodes) {\n addressFormat = format; // choose the default format, keep going\n } else if (format.countryCodes.indexOf(_countryCode) !== -1) {\n addressFormat = format; // choose the country format, stop here\n break;\n }\n }\n\n var dropdowns = addressFormat.dropdowns || [\n 'city', 'county', 'country', 'district', 'hamlet',\n 'neighbourhood', 'place', 'postcode', 'province',\n 'quarter', 'state', 'street', 'subdistrict', 'suburb'\n ];\n\n var widths = addressFormat.widths || {\n housenumber: 1/3, street: 2/3,\n city: 2/3, state: 1/4, postcode: 1/3\n };\n\n function row(r) {\n // Normalize widths.\n var total = r.reduce(function(sum, key) {\n return sum + (widths[key] || 0.5);\n }, 0);\n\n return r.map(function(key) {\n return {\n id: key,\n width: (widths[key] || 0.5) / total\n };\n });\n }\n\n var rows = _wrap.selectAll('.addr-row')\n .data(addressFormat.format, function(d) {\n return d.toString();\n });\n\n rows.exit()\n .remove();\n\n rows\n .enter()\n .append('div')\n .attr('class', 'addr-row')\n .selectAll('input')\n .data(row)\n .enter()\n .append('input')\n .property('type', 'text')\n .call(updatePlaceholder)\n .attr('class', function (d) { return 'addr-' + d.id; })\n .call(utilNoAuto)\n .each(addDropdown)\n .style('width', function (d) { return d.width * 100 + '%'; });\n\n\n function addDropdown(d) {\n if (dropdowns.indexOf(d.id) === -1) return; // not a dropdown\n\n var nearValues = (d.id === 'street') ? getNearStreets\n : (d.id === 'city') ? getNearCities\n : getNearValues;\n\n d3_select(this)\n .call(uiCombobox(context, 'address-' + d.id)\n .minItems(1)\n .caseSensitive(true)\n .fetcher(function(value, callback) {\n callback(nearValues('addr:' + d.id));\n })\n );\n }\n\n _wrap.selectAll('input')\n .on('blur', change())\n .on('change', change());\n\n _wrap.selectAll('input:not(.combobox-input)')\n .on('input', change(true));\n\n if (_tags) updateTags(_tags);\n }\n\n\n function address(selection) {\n _selection = selection;\n\n _wrap = selection.selectAll('.form-field-input-wrap')\n .data([0]);\n\n _wrap = _wrap.enter()\n .append('div')\n .attr('class', 'form-field-input-wrap form-field-input-' + field.type)\n .merge(_wrap);\n\n var extent = combinedEntityExtent();\n\n if (extent) {\n var countryCode;\n if (context.inIntro()) {\n // localize the address format for the walkthrough\n countryCode = t('intro.graph.countrycode');\n } else {\n var center = extent.center();\n countryCode = countryCoder.iso1A2Code(center);\n }\n if (countryCode) {\n _countryCode = countryCode.toLowerCase();\n updateForCountryCode();\n }\n }\n }\n\n\n function change(onInput) {\n return function() {\n var tags = {};\n\n _wrap.selectAll('input')\n .each(function (subfield) {\n var key = field.key + ':' + subfield.id;\n\n var value = this.value;\n if (!onInput) value = context.cleanTagValue(value);\n\n // don't override multiple values with blank string\n if (Array.isArray(_tags[key]) && !value) return;\n\n tags[key] = value || undefined;\n });\n\n dispatch.call('change', this, tags, onInput);\n };\n }\n\n function updatePlaceholder(inputSelection) {\n return inputSelection.attr('placeholder', function(subfield) {\n if (_tags && Array.isArray(_tags[field.key + ':' + subfield.id])) {\n return t('inspector.multiple_values');\n }\n if (_countryCode) {\n var localkey = subfield.id + '!' + _countryCode;\n var tkey = addrField.strings.placeholders[localkey] ? localkey : subfield.id;\n return addrField.t('placeholders.' + tkey);\n }\n });\n }\n\n\n function updateTags(tags) {\n utilGetSetValue(_wrap.selectAll('input'), function (subfield) {\n var val = tags[field.key + ':' + subfield.id];\n return typeof val === 'string' ? val : '';\n })\n .attr('title', function(subfield) {\n var val = tags[field.key + ':' + subfield.id];\n return val && Array.isArray(val) && val.filter(Boolean).join('\\n');\n })\n .classed('mixed', function(subfield) {\n return Array.isArray(tags[field.key + ':' + subfield.id]);\n })\n .call(updatePlaceholder);\n }\n\n\n function combinedEntityExtent() {\n return _entityIDs && _entityIDs.length && utilTotalExtent(_entityIDs, context.graph());\n }\n\n\n address.entityIDs = function(val) {\n if (!arguments.length) return _entityIDs;\n _entityIDs = val;\n return address;\n };\n\n\n address.tags = function(tags) {\n _tags = tags;\n updateTags(tags);\n };\n\n\n address.focus = function() {\n var node = _wrap.selectAll('input').node();\n if (node) node.focus();\n };\n\n\n return utilRebind(address, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { select as d3_select } from 'd3-selection';\n\nimport { uiCombobox } from '../combobox';\nimport { utilGetSetValue, utilNoAuto, utilRebind } from '../../util';\nimport { t } from '../../core/localizer';\n\n\nexport function uiFieldCycleway(field, context) {\n var dispatch = d3_dispatch('change');\n var items = d3_select(null);\n var wrap = d3_select(null);\n var _tags;\n\n function cycleway(selection) {\n\n function stripcolon(s) {\n return s.replace(':', '');\n }\n\n\n wrap = selection.selectAll('.form-field-input-wrap')\n .data([0]);\n\n wrap = wrap.enter()\n .append('div')\n .attr('class', 'form-field-input-wrap form-field-input-' + field.type)\n .merge(wrap);\n\n\n var div = wrap.selectAll('ul')\n .data([0]);\n\n div = div.enter()\n .append('ul')\n .attr('class', 'rows')\n .merge(div);\n\n var keys = ['cycleway:left', 'cycleway:right'];\n\n items = div.selectAll('li')\n .data(keys);\n\n var enter = items.enter()\n .append('li')\n .attr('class', function(d) { return 'labeled-input preset-cycleway-' + stripcolon(d); });\n\n enter\n .append('span')\n .attr('class', 'label preset-label-cycleway')\n .attr('for', function(d) { return 'preset-input-cycleway-' + stripcolon(d); })\n .text(function(d) { return field.t('types.' + d); });\n\n enter\n .append('div')\n .attr('class', 'preset-input-cycleway-wrap')\n .append('input')\n .attr('type', 'text')\n .attr('class', function(d) { return 'preset-input-cycleway preset-input-' + stripcolon(d); })\n .call(utilNoAuto)\n .each(function(d) {\n d3_select(this)\n .call(uiCombobox(context, 'cycleway-' + stripcolon(d))\n .data(cycleway.options(d))\n );\n });\n\n items = items.merge(enter);\n\n // Update\n wrap.selectAll('.preset-input-cycleway')\n .on('change', change)\n .on('blur', change);\n }\n\n\n function change(key) {\n\n var newValue = context.cleanTagValue(utilGetSetValue(d3_select(this)));\n\n // don't override multiple values with blank string\n if (!newValue && (Array.isArray(_tags.cycleway) || Array.isArray(_tags[key]))) return;\n\n if (newValue === 'none' || newValue === '') { newValue = undefined; }\n\n var otherKey = key === 'cycleway:left' ? 'cycleway:right' : 'cycleway:left';\n var otherValue = typeof _tags.cycleway === 'string' ? _tags.cycleway : _tags[otherKey];\n if (otherValue && Array.isArray(otherValue)) {\n // we must always have an explicit value for comparison\n otherValue = otherValue[0];\n }\n if (otherValue === 'none' || otherValue === '') { otherValue = undefined; }\n\n var tag = {};\n\n // If the left and right tags match, use the cycleway tag to tag both\n // sides the same way\n if (newValue === otherValue) {\n tag = {\n cycleway: newValue,\n 'cycleway:left': undefined,\n 'cycleway:right': undefined\n };\n } else {\n // Always set both left and right as changing one can affect the other\n tag = {\n cycleway: undefined\n };\n tag[key] = newValue;\n tag[otherKey] = otherValue;\n }\n\n dispatch.call('change', this, tag);\n }\n\n\n cycleway.options = function() {\n return Object.keys(field.strings.options).map(function(option) {\n return {\n title: field.t('options.' + option + '.description'),\n value: option\n };\n });\n };\n\n\n cycleway.tags = function(tags) {\n _tags = tags;\n\n // If cycleway is set, use that instead of individual values\n var commonValue = typeof tags.cycleway === 'string' && tags.cycleway;\n\n utilGetSetValue(items.selectAll('.preset-input-cycleway'), function(d) {\n if (commonValue) return commonValue;\n return !tags.cycleway && typeof tags[d] === 'string' ? tags[d] : '';\n })\n .attr('title', function(d) {\n if (Array.isArray(tags.cycleway) || Array.isArray(tags[d])) {\n var vals = [];\n if (Array.isArray(tags.cycleway)) {\n vals = vals.concat(tags.cycleway);\n }\n if (Array.isArray(tags[d])) {\n vals = vals.concat(tags[d]);\n }\n return vals.filter(Boolean).join('\\n');\n }\n return null;\n })\n .attr('placeholder', function(d) {\n if (Array.isArray(tags.cycleway) || Array.isArray(tags[d])) {\n return t('inspector.multiple_values');\n }\n return field.placeholder();\n })\n .classed('mixed', function(d) {\n return Array.isArray(tags.cycleway) || Array.isArray(tags[d]);\n });\n };\n\n\n cycleway.focus = function() {\n var node = wrap.selectAll('input').node();\n if (node) node.focus();\n };\n\n\n return utilRebind(cycleway, dispatch, 'on');\n}\n","function refresh(selection, node) {\n var cr = node.getBoundingClientRect();\n var prop = [cr.width, cr.height];\n selection.property('__dimensions__', prop);\n return prop;\n}\n\nexport function utilGetDimensions(selection, force) {\n if (!selection || selection.empty()) {\n return [0, 0];\n }\n var node = selection.node(),\n cached = selection.property('__dimensions__');\n return (!cached || force) ? refresh(selection, node) : cached;\n}\n\n\nexport function utilSetDimensions(selection, dimensions) {\n if (!selection || selection.empty()) {\n return selection;\n }\n var node = selection.node();\n if (dimensions === null) {\n refresh(selection, node);\n return selection;\n }\n return selection\n .property('__dimensions__', [dimensions[0], dimensions[1]])\n .attr('width', dimensions[0])\n .attr('height', dimensions[1]);\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\n\nimport { utilRebind } from '../../util/rebind';\nimport { utilGetDimensions } from '../../util/dimensions';\n\n\nexport function uiFieldLanes(field, context) {\n var dispatch = d3_dispatch('change');\n var LANE_WIDTH = 40;\n var LANE_HEIGHT = 200;\n var _entityIDs = [];\n\n function lanes(selection) {\n var lanesData = context.entity(_entityIDs[0]).lanes();\n\n if (!context.container().select('.inspector-wrap.inspector-hidden').empty() || !selection.node().parentNode) {\n selection.call(lanes.off);\n return;\n }\n\n var wrap = selection.selectAll('.form-field-input-wrap')\n .data([0]);\n\n wrap = wrap.enter()\n .append('div')\n .attr('class', 'form-field-input-wrap form-field-input-' + field.type)\n .merge(wrap);\n\n var surface = wrap.selectAll('.surface')\n .data([0]);\n\n var d = utilGetDimensions(wrap);\n var freeSpace = d[0] - lanesData.lanes.length * LANE_WIDTH * 1.5 + LANE_WIDTH * 0.5;\n\n surface = surface.enter()\n .append('svg')\n .attr('width', d[0])\n .attr('height', 300)\n .attr('class', 'surface')\n .merge(surface);\n\n\n var lanesSelection = surface.selectAll('.lanes')\n .data([0]);\n\n lanesSelection = lanesSelection.enter()\n .append('g')\n .attr('class', 'lanes')\n .merge(lanesSelection);\n\n lanesSelection\n .attr('transform', function () {\n return 'translate(' + (freeSpace / 2) + ', 0)';\n });\n\n\n var lane = lanesSelection.selectAll('.lane')\n .data(lanesData.lanes);\n\n lane.exit()\n .remove();\n\n var enter = lane.enter()\n .append('g')\n .attr('class', 'lane');\n\n enter\n .append('g')\n .append('rect')\n .attr('y', 50)\n .attr('width', LANE_WIDTH)\n .attr('height', LANE_HEIGHT);\n\n enter\n .append('g')\n .attr('class', 'forward')\n .append('text')\n .attr('y', 40)\n .attr('x', 14)\n .text('▲');\n\n enter\n .append('g')\n .attr('class', 'bothways')\n .append('text')\n .attr('y', 40)\n .attr('x', 14)\n .text('▲▼');\n\n enter\n .append('g')\n .attr('class', 'backward')\n .append('text')\n .attr('y', 40)\n .attr('x', 14)\n .text('▼');\n\n\n lane = lane\n .merge(enter);\n\n lane\n .attr('transform', function(d) {\n return 'translate(' + (LANE_WIDTH * d.index * 1.5) + ', 0)';\n });\n\n lane.select('.forward')\n .style('visibility', function(d) {\n return d.direction === 'forward' ? 'visible' : 'hidden';\n });\n\n lane.select('.bothways')\n .style('visibility', function(d) {\n return d.direction === 'bothways' ? 'visible' : 'hidden';\n });\n\n lane.select('.backward')\n .style('visibility', function(d) {\n return d.direction === 'backward' ? 'visible' : 'hidden';\n });\n }\n\n\n lanes.entityIDs = function(val) {\n _entityIDs = val;\n };\n\n lanes.tags = function() {};\n lanes.focus = function() {};\n lanes.off = function() {};\n\n return utilRebind(lanes, dispatch, 'on');\n}\n\nuiFieldLanes.supportsMultiselection = false;\n","import {\n geoIdentity as d3_geoIdentity,\n geoPath as d3_geoPath,\n geoStream as d3_geoStream\n} from 'd3-geo';\n\nimport { geoVecAdd, geoVecAngle, geoVecLength } from '../geo';\n\n\n// Touch targets control which other vertices we can drag a vertex onto.\n//\n// - the activeID - nope\n// - 1 away (adjacent) to the activeID - yes (vertices will be merged)\n// - 2 away from the activeID - nope (would create a self intersecting segment)\n// - all others on a linear way - yes\n// - all others on a closed way - nope (would create a self intersecting polygon)\n//\n// returns\n// 0 = active vertex - no touch/connect\n// 1 = passive vertex - yes touch/connect\n// 2 = adjacent vertex - yes but pay attention segmenting a line here\n//\nexport function svgPassiveVertex(node, graph, activeID) {\n if (!activeID) return 1;\n if (activeID === node.id) return 0;\n\n var parents = graph.parentWays(node);\n\n var i, j, nodes, isClosed, ix1, ix2, ix3, ix4, max;\n\n for (i = 0; i < parents.length; i++) {\n nodes = parents[i].nodes;\n isClosed = parents[i].isClosed();\n for (j = 0; j < nodes.length; j++) { // find this vertex, look nearby\n if (nodes[j] === node.id) {\n ix1 = j - 2;\n ix2 = j - 1;\n ix3 = j + 1;\n ix4 = j + 2;\n\n if (isClosed) { // wraparound if needed\n max = nodes.length - 1;\n if (ix1 < 0) ix1 = max + ix1;\n if (ix2 < 0) ix2 = max + ix2;\n if (ix3 > max) ix3 = ix3 - max;\n if (ix4 > max) ix4 = ix4 - max;\n }\n\n if (nodes[ix1] === activeID) return 0; // no - prevent self intersect\n else if (nodes[ix2] === activeID) return 2; // ok - adjacent\n else if (nodes[ix3] === activeID) return 2; // ok - adjacent\n else if (nodes[ix4] === activeID) return 0; // no - prevent self intersect\n else if (isClosed && nodes.indexOf(activeID) !== -1) return 0; // no - prevent self intersect\n }\n }\n }\n\n return 1; // ok\n}\n\n\nexport function svgMarkerSegments(projection, graph, dt,\n shouldReverse,\n bothDirections) {\n return function(entity) {\n var i = 0;\n var offset = dt;\n var segments = [];\n var clip = d3_geoIdentity().clipExtent(projection.clipExtent()).stream;\n var coordinates = graph.childNodes(entity).map(function(n) { return n.loc; });\n var a, b;\n\n if (shouldReverse(entity)) {\n coordinates.reverse();\n }\n\n d3_geoStream({\n type: 'LineString',\n coordinates: coordinates\n }, projection.stream(clip({\n lineStart: function() {},\n lineEnd: function() { a = null; },\n point: function(x, y) {\n b = [x, y];\n\n if (a) {\n var span = geoVecLength(a, b) - offset;\n\n if (span >= 0) {\n var heading = geoVecAngle(a, b);\n var dx = dt * Math.cos(heading);\n var dy = dt * Math.sin(heading);\n var p = [\n a[0] + offset * Math.cos(heading),\n a[1] + offset * Math.sin(heading)\n ];\n\n // gather coordinates\n var coord = [a, p];\n for (span -= dt; span >= 0; span -= dt) {\n p = geoVecAdd(p, [dx, dy]);\n coord.push(p);\n }\n coord.push(b);\n\n // generate svg paths\n var segment = '';\n var j;\n\n for (j = 0; j < coord.length; j++) {\n segment += (j === 0 ? 'M' : 'L') + coord[j][0] + ',' + coord[j][1];\n }\n segments.push({ id: entity.id, index: i++, d: segment });\n\n if (bothDirections(entity)) {\n segment = '';\n for (j = coord.length - 1; j >= 0; j--) {\n segment += (j === coord.length - 1 ? 'M' : 'L') + coord[j][0] + ',' + coord[j][1];\n }\n segments.push({ id: entity.id, index: i++, d: segment });\n }\n }\n\n offset = -span;\n }\n\n a = b;\n }\n })));\n\n return segments;\n };\n}\n\n\nexport function svgPath(projection, graph, isArea) {\n\n // Explanation of magic numbers:\n // \"padding\" here allows space for strokes to extend beyond the viewport,\n // so that the stroke isn't drawn along the edge of the viewport when\n // the shape is clipped.\n //\n // When drawing lines, pad viewport by 5px.\n // When drawing areas, pad viewport by 65px in each direction to allow\n // for 60px area fill stroke (see \".fill-partial path.fill\" css rule)\n\n var cache = {};\n var padding = isArea ? 65 : 5;\n var viewport = projection.clipExtent();\n var paddedExtent = [\n [viewport[0][0] - padding, viewport[0][1] - padding],\n [viewport[1][0] + padding, viewport[1][1] + padding]\n ];\n var clip = d3_geoIdentity().clipExtent(paddedExtent).stream;\n var project = projection.stream;\n var path = d3_geoPath()\n .projection({stream: function(output) { return project(clip(output)); }});\n\n var svgpath = function(entity) {\n if (entity.id in cache) {\n return cache[entity.id];\n } else {\n return cache[entity.id] = path(entity.asGeoJSON(graph));\n }\n };\n\n svgpath.geojson = function(d) {\n if (d.__featurehash__ !== undefined) {\n if (d.__featurehash__ in cache) {\n return cache[d.__featurehash__];\n } else {\n return cache[d.__featurehash__] = path(d);\n }\n } else {\n return path(d);\n }\n };\n\n return svgpath;\n}\n\n\nexport function svgPointTransform(projection) {\n var svgpoint = function(entity) {\n // http://jsperf.com/short-array-join\n var pt = projection(entity.loc);\n return 'translate(' + pt[0] + ',' + pt[1] + ')';\n };\n\n svgpoint.geojson = function(d) {\n return svgpoint(d.properties.entity);\n };\n\n return svgpoint;\n}\n\n\nexport function svgRelationMemberTags(graph) {\n return function(entity) {\n var tags = entity.tags;\n var shouldCopyMultipolygonTags = !entity.hasInterestingTags();\n graph.parentRelations(entity).forEach(function(relation) {\n var type = relation.tags.type;\n if ((type === 'multipolygon' && shouldCopyMultipolygonTags) || type === 'boundary') {\n tags = Object.assign({}, relation.tags, tags);\n }\n });\n return tags;\n };\n}\n\n\nexport function svgSegmentWay(way, graph, activeID) {\n // When there is no activeID, we can memoize this expensive computation\n if (activeID === undefined) {\n return graph.transient(way, 'waySegments', getWaySegments);\n } else {\n return getWaySegments();\n }\n\n function getWaySegments() {\n var isActiveWay = (way.nodes.indexOf(activeID) !== -1);\n var features = { passive: [], active: [] };\n var start = {};\n var end = {};\n var node, type;\n\n for (var i = 0; i < way.nodes.length; i++) {\n node = graph.entity(way.nodes[i]);\n type = svgPassiveVertex(node, graph, activeID);\n end = { node: node, type: type };\n\n if (start.type !== undefined) {\n if (start.node.id === activeID || end.node.id === activeID) {\n // push nothing\n } else if (isActiveWay && (start.type === 2 || end.type === 2)) { // one adjacent vertex\n pushActive(start, end, i);\n } else if (start.type === 0 && end.type === 0) { // both active vertices\n pushActive(start, end, i);\n } else {\n pushPassive(start, end, i);\n }\n }\n\n start = end;\n }\n\n return features;\n\n function pushActive(start, end, index) {\n features.active.push({\n type: 'Feature',\n id: way.id + '-' + index + '-nope',\n properties: {\n nope: true,\n target: true,\n entity: way,\n nodes: [start.node, end.node],\n index: index\n },\n geometry: {\n type: 'LineString',\n coordinates: [start.node.loc, end.node.loc]\n }\n });\n }\n\n function pushPassive(start, end, index) {\n features.passive.push({\n type: 'Feature',\n id: way.id + '-' + index,\n properties: {\n target: true,\n entity: way,\n nodes: [start.node, end.node],\n index: index\n },\n geometry: {\n type: 'LineString',\n coordinates: [start.node.loc, end.node.loc]\n }\n });\n }\n }\n}\n","import { select as d3_select } from 'd3-selection';\nimport { osmPathHighwayTagValues, osmPavedTags, osmSemipavedTags } from '../osm/tags';\n\n\nexport function svgTagClasses() {\n var primaries = [\n 'building', 'highway', 'railway', 'waterway', 'aeroway', 'aerialway',\n 'piste:type', 'boundary', 'power', 'amenity', 'natural', 'landuse',\n 'leisure', 'military', 'place', 'man_made', 'route', 'attraction',\n 'building:part', 'indoor'\n ];\n var statuses = [\n // nonexistent, might be built\n 'proposed', 'planned',\n // under maintentance or between groundbreaking and opening\n 'construction',\n // existent but not functional\n 'disused',\n // dilapidated to nonexistent\n 'abandoned',\n // nonexistent, still may appear in imagery\n 'dismantled', 'razed', 'demolished', 'obliterated',\n // existent occasionally, e.g. stormwater drainage basin\n 'intermittent'\n ];\n var secondaries = [\n 'oneway', 'bridge', 'tunnel', 'embankment', 'cutting', 'barrier',\n 'surface', 'tracktype', 'footway', 'crossing', 'service', 'sport',\n 'public_transport', 'location', 'parking', 'golf', 'type', 'leisure',\n 'man_made', 'indoor'\n ];\n var _tags = function(entity) { return entity.tags; };\n\n\n var tagClasses = function(selection) {\n selection.each(function tagClassesEach(entity) {\n var value = this.className;\n\n if (value.baseVal !== undefined) {\n value = value.baseVal;\n }\n\n var t = _tags(entity);\n\n var computed = tagClasses.getClassesString(t, value);\n\n if (computed !== value) {\n d3_select(this).attr('class', computed);\n }\n });\n };\n\n\n tagClasses.getClassesString = function(t, value) {\n var primary, status;\n var i, j, k, v;\n\n // in some situations we want to render perimeter strokes a certain way\n var overrideGeometry;\n if (/\\bstroke\\b/.test(value)) {\n if (!!t.barrier && t.barrier !== 'no') {\n overrideGeometry = 'line';\n }\n }\n\n // preserve base classes (nothing with `tag-`)\n var classes = value.trim().split(/\\s+/)\n .filter(function(klass) {\n return klass.length && !/^tag-/.test(klass);\n })\n .map(function(klass) { // special overrides for some perimeter strokes\n return (klass === 'line' || klass === 'area') ? (overrideGeometry || klass) : klass;\n });\n\n // pick at most one primary classification tag..\n for (i = 0; i < primaries.length; i++) {\n k = primaries[i];\n v = t[k];\n if (!v || v === 'no') continue;\n\n if (k === 'piste:type') { // avoid a ':' in the class name\n k = 'piste';\n } else if (k === 'building:part') { // avoid a ':' in the class name\n k = 'building_part';\n }\n\n primary = k;\n if (statuses.indexOf(v) !== -1) { // e.g. `railway=abandoned`\n status = v;\n classes.push('tag-' + k);\n } else {\n classes.push('tag-' + k);\n classes.push('tag-' + k + '-' + v);\n }\n\n break;\n }\n\n if (!primary) {\n for (i = 0; i < statuses.length; i++) {\n for (j = 0; j < primaries.length; j++) {\n k = statuses[i] + ':' + primaries[j]; // e.g. `demolished:building=yes`\n v = t[k];\n if (!v || v === 'no') continue;\n\n status = statuses[i];\n break;\n }\n }\n }\n\n // add at most one status tag, only if relates to primary tag..\n if (!status) {\n for (i = 0; i < statuses.length; i++) {\n k = statuses[i];\n v = t[k];\n if (!v || v === 'no') continue;\n\n if (v === 'yes') { // e.g. `railway=rail + abandoned=yes`\n status = k;\n }\n else if (primary && primary === v) { // e.g. `railway=rail + abandoned=railway`\n status = k;\n } else if (!primary && primaries.indexOf(v) !== -1) { // e.g. `abandoned=railway`\n status = k;\n primary = v;\n classes.push('tag-' + v);\n } // else ignore e.g. `highway=path + abandoned=railway`\n\n if (status) break;\n }\n }\n\n if (status) {\n classes.push('tag-status');\n classes.push('tag-status-' + status);\n }\n\n // add any secondary tags\n for (i = 0; i < secondaries.length; i++) {\n k = secondaries[i];\n v = t[k];\n if (!v || v === 'no' || k === primary) continue;\n classes.push('tag-' + k);\n classes.push('tag-' + k + '-' + v);\n }\n\n // For highways, look for surface tagging..\n if ((primary === 'highway' && !osmPathHighwayTagValues[t.highway]) || primary === 'aeroway') {\n var surface = t.highway === 'track' ? 'unpaved' : 'paved';\n for (k in t) {\n v = t[k];\n if (k in osmPavedTags) {\n surface = osmPavedTags[k][v] ? 'paved' : 'unpaved';\n }\n if (k in osmSemipavedTags && !!osmSemipavedTags[k][v]) {\n surface = 'semipaved';\n }\n }\n classes.push('tag-' + surface);\n }\n\n // If this is a wikidata-tagged item, add a class for that..\n if (t.wikidata || t['brand:wikidata']) {\n classes.push('tag-wikidata');\n }\n\n return classes.join(' ').trim();\n };\n\n\n tagClasses.tags = function(val) {\n if (!arguments.length) return _tags;\n _tags = val;\n return tagClasses;\n };\n\n return tagClasses;\n}\n","\n// Patterns only work in Firefox when set directly on element.\n// (This is not a bug: https://bugzilla.mozilla.org/show_bug.cgi?id=750632)\nvar patterns = {\n // tag - pattern name\n // -or-\n // tag - value - pattern name\n // -or-\n // tag - value - rules (optional tag-values, pattern name)\n // (matches earlier rules first, so fallback should be last entry)\n amenity: {\n grave_yard: 'cemetery',\n fountain: 'water_standing'\n },\n landuse: {\n cemetery: [\n { religion: 'christian', pattern: 'cemetery_christian' },\n { religion: 'buddhist', pattern: 'cemetery_buddhist' },\n { religion: 'muslim', pattern: 'cemetery_muslim' },\n { religion: 'jewish', pattern: 'cemetery_jewish' },\n { pattern: 'cemetery' }\n ],\n construction: 'construction',\n farmland: 'farmland',\n farmyard: 'farmyard',\n forest: [\n { leaf_type: 'broadleaved', pattern: 'forest_broadleaved' },\n { leaf_type: 'needleleaved', pattern: 'forest_needleleaved' },\n { leaf_type: 'leafless', pattern: 'forest_leafless' },\n { pattern: 'forest' } // same as 'leaf_type:mixed'\n ],\n grave_yard: 'cemetery',\n grass: [\n { golf: 'green', pattern: 'golf_green' },\n { pattern: 'grass' },\n ],\n landfill: 'landfill',\n meadow: 'meadow',\n military: 'construction',\n orchard: 'orchard',\n quarry: 'quarry',\n vineyard: 'vineyard'\n },\n natural: {\n beach: 'beach',\n grassland: 'grass',\n sand: 'beach',\n scrub: 'scrub',\n water: [\n { water: 'pond', pattern: 'pond' },\n { water: 'reservoir', pattern: 'water_standing' },\n { pattern: 'waves' }\n ],\n wetland: [\n { wetland: 'marsh', pattern: 'wetland_marsh' },\n { wetland: 'swamp', pattern: 'wetland_swamp' },\n { wetland: 'bog', pattern: 'wetland_bog' },\n { wetland: 'reedbed', pattern: 'wetland_reedbed' },\n { pattern: 'wetland' }\n ],\n wood: [\n { leaf_type: 'broadleaved', pattern: 'forest_broadleaved' },\n { leaf_type: 'needleleaved', pattern: 'forest_needleleaved' },\n { leaf_type: 'leafless', pattern: 'forest_leafless' },\n { pattern: 'forest' } // same as 'leaf_type:mixed'\n ]\n },\n traffic_calming: {\n island: [\n { surface: 'grass', pattern: 'grass' },\n ],\n chicane: [\n { surface: 'grass', pattern: 'grass' },\n ],\n choker: [\n { surface: 'grass', pattern: 'grass' },\n ]\n }\n};\n\nexport function svgTagPattern(tags) {\n // Skip pattern filling if this is a building (buildings don't get patterns applied)\n if (tags.building && tags.building !== 'no') {\n return null;\n }\n\n for (var tag in patterns) {\n var entityValue = tags[tag];\n if (!entityValue) continue;\n\n if (typeof patterns[tag] === 'string') { // extra short syntax (just tag) - pattern name\n return 'pattern-' + patterns[tag];\n } else {\n var values = patterns[tag];\n for (var value in values) {\n if (entityValue !== value) continue;\n\n var rules = values[value];\n if (typeof rules === 'string') { // short syntax - pattern name\n return 'pattern-' + rules;\n }\n\n // long syntax - rule array\n for (var ruleKey in rules) {\n var rule = rules[ruleKey];\n\n var pass = true;\n for (var criterion in rule) {\n if (criterion !== 'pattern') { // reserved for pattern name\n // The only rule is a required tag-value pair\n var v = tags[criterion];\n if (!v || v !== rule[criterion]) {\n pass = false;\n break;\n }\n }\n }\n\n if (pass) {\n return 'pattern-' + rule.pattern;\n }\n }\n }\n }\n }\n\n return null;\n}\n","import deepEqual from 'fast-deep-equal';\nimport { bisector as d3_bisector } from 'd3-array';\n\nimport { osmEntity, osmIsOldMultipolygonOuterMember } from '../osm';\nimport { svgPath, svgSegmentWay } from './helpers';\nimport { svgTagClasses } from './tag_classes';\nimport { svgTagPattern } from './tag_pattern';\n\nexport function svgAreas(projection, context) {\n\n\n function getPatternStyle(tags) {\n var imageID = svgTagPattern(tags);\n if (imageID) {\n return 'url(\"#ideditor-' + imageID + '\")';\n }\n return '';\n }\n\n\n function drawTargets(selection, graph, entities, filter) {\n var targetClass = context.getDebug('target') ? 'pink ' : 'nocolor ';\n var nopeClass = context.getDebug('target') ? 'red ' : 'nocolor ';\n var getPath = svgPath(projection).geojson;\n var activeID = context.activeID();\n var base = context.history().base();\n\n // The targets and nopes will be MultiLineString sub-segments of the ways\n var data = { targets: [], nopes: [] };\n\n entities.forEach(function(way) {\n var features = svgSegmentWay(way, graph, activeID);\n data.targets.push.apply(data.targets, features.passive);\n data.nopes.push.apply(data.nopes, features.active);\n });\n\n\n // Targets allow hover and vertex snapping\n var targetData = data.targets.filter(getPath);\n var targets = selection.selectAll('.area.target-allowed')\n .filter(function(d) { return filter(d.properties.entity); })\n .data(targetData, function key(d) { return d.id; });\n\n // exit\n targets.exit()\n .remove();\n\n var segmentWasEdited = function(d) {\n var wayID = d.properties.entity.id;\n // if the whole line was edited, don't draw segment changes\n if (!base.entities[wayID] ||\n !deepEqual(graph.entities[wayID].nodes, base.entities[wayID].nodes)) {\n return false;\n }\n return d.properties.nodes.some(function(n) {\n return !base.entities[n.id] ||\n !deepEqual(graph.entities[n.id].loc, base.entities[n.id].loc);\n });\n };\n\n // enter/update\n targets.enter()\n .append('path')\n .merge(targets)\n .attr('d', getPath)\n .attr('class', function(d) { return 'way area target target-allowed ' + targetClass + d.id; })\n .classed('segment-edited', segmentWasEdited);\n\n\n // NOPE\n var nopeData = data.nopes.filter(getPath);\n var nopes = selection.selectAll('.area.target-nope')\n .filter(function(d) { return filter(d.properties.entity); })\n .data(nopeData, function key(d) { return d.id; });\n\n // exit\n nopes.exit()\n .remove();\n\n // enter/update\n nopes.enter()\n .append('path')\n .merge(nopes)\n .attr('d', getPath)\n .attr('class', function(d) { return 'way area target target-nope ' + nopeClass + d.id; })\n .classed('segment-edited', segmentWasEdited);\n }\n\n\n function drawAreas(selection, graph, entities, filter) {\n var path = svgPath(projection, graph, true);\n var areas = {};\n var multipolygon;\n var base = context.history().base();\n\n for (var i = 0; i < entities.length; i++) {\n var entity = entities[i];\n if (entity.geometry(graph) !== 'area') continue;\n\n multipolygon = osmIsOldMultipolygonOuterMember(entity, graph);\n if (multipolygon) {\n areas[multipolygon.id] = {\n entity: multipolygon.mergeTags(entity.tags),\n area: Math.abs(entity.area(graph))\n };\n } else if (!areas[entity.id]) {\n areas[entity.id] = {\n entity: entity,\n area: Math.abs(entity.area(graph))\n };\n }\n }\n\n var fills = Object.values(areas).filter(function hasPath(a) { return path(a.entity); });\n fills.sort(function areaSort(a, b) { return b.area - a.area; });\n fills = fills.map(function(a) { return a.entity; });\n\n var strokes = fills.filter(function(area) { return area.type === 'way'; });\n\n var data = {\n clip: fills,\n shadow: strokes,\n stroke: strokes,\n fill: fills\n };\n\n var clipPaths = context.surface().selectAll('defs').selectAll('.clipPath-osm')\n .filter(filter)\n .data(data.clip, osmEntity.key);\n\n clipPaths.exit()\n .remove();\n\n var clipPathsEnter = clipPaths.enter()\n .append('clipPath')\n .attr('class', 'clipPath-osm')\n .attr('id', function(entity) { return 'ideditor-' + entity.id + '-clippath'; });\n\n clipPathsEnter\n .append('path');\n\n clipPaths.merge(clipPathsEnter)\n .selectAll('path')\n .attr('d', path);\n\n\n var drawLayer = selection.selectAll('.layer-osm.areas');\n var touchLayer = selection.selectAll('.layer-touch.areas');\n\n // Draw areas..\n var areagroup = drawLayer\n .selectAll('g.areagroup')\n .data(['fill', 'shadow', 'stroke']);\n\n areagroup = areagroup.enter()\n .append('g')\n .attr('class', function(d) { return 'areagroup area-' + d; })\n .merge(areagroup);\n\n var paths = areagroup\n .selectAll('path')\n .filter(filter)\n .data(function(layer) { return data[layer]; }, osmEntity.key);\n\n paths.exit()\n .remove();\n\n\n var fillpaths = selection.selectAll('.area-fill path.area').nodes();\n var bisect = d3_bisector(function(node) { return -node.__data__.area(graph); }).left;\n\n function sortedByArea(entity) {\n if (this._parent.__data__ === 'fill') {\n return fillpaths[bisect(fillpaths, -entity.area(graph))];\n }\n }\n\n paths = paths.enter()\n .insert('path', sortedByArea)\n .merge(paths)\n .each(function(entity) {\n var layer = this.parentNode.__data__;\n this.setAttribute('class', entity.type + ' area ' + layer + ' ' + entity.id);\n\n if (layer === 'fill') {\n this.setAttribute('clip-path', 'url(#ideditor-' + entity.id + '-clippath)');\n this.style.fill = this.style.stroke = getPatternStyle(entity.tags);\n }\n })\n .classed('added', function(d) {\n return !base.entities[d.id];\n })\n .classed('geometry-edited', function(d) {\n return graph.entities[d.id] &&\n base.entities[d.id] &&\n !deepEqual(graph.entities[d.id].nodes, base.entities[d.id].nodes);\n })\n .classed('retagged', function(d) {\n return graph.entities[d.id] &&\n base.entities[d.id] &&\n !deepEqual(graph.entities[d.id].tags, base.entities[d.id].tags);\n })\n .call(svgTagClasses())\n .attr('d', path);\n\n\n // Draw touch targets..\n touchLayer\n .call(drawTargets, graph, data.stroke, filter);\n }\n\n return drawAreas;\n}\n","import debounce from './debounce.js';\nimport isObject from './isObject.js';\n\n/** Error message constants. */\nvar FUNC_ERROR_TEXT = 'Expected a function';\n\n/**\n * Creates a throttled function that only invokes `func` at most once per\n * every `wait` milliseconds. The throttled function comes with a `cancel`\n * method to cancel delayed `func` invocations and a `flush` method to\n * immediately invoke them. Provide `options` to indicate whether `func`\n * should be invoked on the leading and/or trailing edge of the `wait`\n * timeout. The `func` is invoked with the last arguments provided to the\n * throttled function. Subsequent calls to the throttled function return the\n * result of the last `func` invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the throttled function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until to the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)\n * for details over the differences between `_.throttle` and `_.debounce`.\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Function\n * @param {Function} func The function to throttle.\n * @param {number} [wait=0] The number of milliseconds to throttle invocations to.\n * @param {Object} [options={}] The options object.\n * @param {boolean} [options.leading=true]\n * Specify invoking on the leading edge of the timeout.\n * @param {boolean} [options.trailing=true]\n * Specify invoking on the trailing edge of the timeout.\n * @returns {Function} Returns the new throttled function.\n * @example\n *\n * // Avoid excessively updating the position while scrolling.\n * jQuery(window).on('scroll', _.throttle(updatePosition, 100));\n *\n * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.\n * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });\n * jQuery(element).on('click', throttled);\n *\n * // Cancel the trailing throttled invocation.\n * jQuery(window).on('popstate', throttled.cancel);\n */\nfunction throttle(func, wait, options) {\n var leading = true,\n trailing = true;\n\n if (typeof func != 'function') {\n throw new TypeError(FUNC_ERROR_TEXT);\n }\n if (isObject(options)) {\n leading = 'leading' in options ? !!options.leading : leading;\n trailing = 'trailing' in options ? !!options.trailing : trailing;\n }\n return debounce(func, wait, {\n 'leading': leading,\n 'maxWait': wait,\n 'trailing': trailing\n });\n}\n\nexport default throttle;\n","'use strict';\n\nmodule.exports = function (data, opts) {\n if (!opts) opts = {};\n if (typeof opts === 'function') opts = { cmp: opts };\n var cycles = (typeof opts.cycles === 'boolean') ? opts.cycles : false;\n\n var cmp = opts.cmp && (function (f) {\n return function (node) {\n return function (a, b) {\n var aobj = { key: a, value: node[a] };\n var bobj = { key: b, value: node[b] };\n return f(aobj, bobj);\n };\n };\n })(opts.cmp);\n\n var seen = [];\n return (function stringify (node) {\n if (node && node.toJSON && typeof node.toJSON === 'function') {\n node = node.toJSON();\n }\n\n if (node === undefined) return;\n if (typeof node == 'number') return isFinite(node) ? '' + node : 'null';\n if (typeof node !== 'object') return JSON.stringify(node);\n\n var i, out;\n if (Array.isArray(node)) {\n out = '[';\n for (i = 0; i < node.length; i++) {\n if (i) out += ',';\n out += stringify(node[i]) || 'null';\n }\n return out + ']';\n }\n\n if (node === null) return 'null';\n\n if (seen.indexOf(node) !== -1) {\n if (cycles) return JSON.stringify('__cycle__');\n throw new TypeError('Converting circular structure to JSON');\n }\n\n var seenIndex = seen.push(node) - 1;\n var keys = Object.keys(node).sort(cmp && cmp(node));\n out = '';\n for (i = 0; i < keys.length; i++) {\n var key = keys[i];\n var value = stringify(node[key]);\n\n if (!value) continue;\n if (out) out += ',';\n out += JSON.stringify(key) + ':' + value;\n }\n seen.splice(seenIndex, 1);\n return '{' + out + '}';\n })(data);\n};\n","import _throttle from 'lodash-es/throttle';\n\nimport { geoBounds as d3_geoBounds, geoPath as d3_geoPath } from 'd3-geo';\nimport { text as d3_text } from 'd3-fetch';\nimport { event as d3_event, select as d3_select } from 'd3-selection';\n\nimport stringify from 'fast-json-stable-stringify';\nimport toGeoJSON from '@mapbox/togeojson';\n\nimport { geoExtent, geoPolygonIntersectsPolygon } from '../geo';\nimport { services } from '../services';\nimport { svgPath } from './helpers';\nimport { utilDetect } from '../util/detect';\nimport { utilArrayFlatten, utilArrayUnion, utilHashcode } from '../util';\n\n\nvar _initialized = false;\nvar _enabled = false;\nvar _geojson;\n\n\nexport function svgData(projection, context, dispatch) {\n var throttledRedraw = _throttle(function () { dispatch.call('change'); }, 1000);\n var _showLabels = true;\n var detected = utilDetect();\n var layer = d3_select(null);\n var _vtService;\n var _fileList;\n var _template;\n var _src;\n\n\n function init() {\n if (_initialized) return; // run once\n\n _geojson = {};\n _enabled = true;\n\n function over() {\n d3_event.stopPropagation();\n d3_event.preventDefault();\n d3_event.dataTransfer.dropEffect = 'copy';\n }\n\n context.container()\n .attr('dropzone', 'copy')\n .on('drop.svgData', function() {\n d3_event.stopPropagation();\n d3_event.preventDefault();\n if (!detected.filedrop) return;\n drawData.fileList(d3_event.dataTransfer.files);\n })\n .on('dragenter.svgData', over)\n .on('dragexit.svgData', over)\n .on('dragover.svgData', over);\n\n _initialized = true;\n }\n\n\n function getService() {\n if (services.vectorTile && !_vtService) {\n _vtService = services.vectorTile;\n _vtService.event.on('loadedData', throttledRedraw);\n } else if (!services.vectorTile && _vtService) {\n _vtService = null;\n }\n\n return _vtService;\n }\n\n\n function showLayer() {\n layerOn();\n\n layer\n .style('opacity', 0)\n .transition()\n .duration(250)\n .style('opacity', 1)\n .on('end', function () { dispatch.call('change'); });\n }\n\n\n function hideLayer() {\n throttledRedraw.cancel();\n\n layer\n .transition()\n .duration(250)\n .style('opacity', 0)\n .on('end', layerOff);\n }\n\n\n function layerOn() {\n layer.style('display', 'block');\n }\n\n\n function layerOff() {\n layer.selectAll('.viewfield-group').remove();\n layer.style('display', 'none');\n }\n\n\n // ensure that all geojson features in a collection have IDs\n function ensureIDs(gj) {\n if (!gj) return null;\n\n if (gj.type === 'FeatureCollection') {\n for (var i = 0; i < gj.features.length; i++) {\n ensureFeatureID(gj.features[i]);\n }\n } else {\n ensureFeatureID(gj);\n }\n return gj;\n }\n\n\n // ensure that each single Feature object has a unique ID\n function ensureFeatureID(feature) {\n if (!feature) return;\n feature.__featurehash__ = utilHashcode(stringify(feature));\n return feature;\n }\n\n\n // Prefer an array of Features instead of a FeatureCollection\n function getFeatures(gj) {\n if (!gj) return [];\n\n if (gj.type === 'FeatureCollection') {\n return gj.features;\n } else {\n return [gj];\n }\n }\n\n\n function featureKey(d) {\n return d.__featurehash__;\n }\n\n\n function isPolygon(d) {\n return d.geometry.type === 'Polygon' || d.geometry.type === 'MultiPolygon';\n }\n\n\n function clipPathID(d) {\n return 'ideditor-data-' + d.__featurehash__ + '-clippath';\n }\n\n\n function featureClasses(d) {\n return [\n 'data' + d.__featurehash__,\n d.geometry.type,\n isPolygon(d) ? 'area' : '',\n d.__layerID__ || ''\n ].filter(Boolean).join(' ');\n }\n\n\n function drawData(selection) {\n var vtService = getService();\n var getPath = svgPath(projection).geojson;\n var getAreaPath = svgPath(projection, null, true).geojson;\n var hasData = drawData.hasData();\n\n layer = selection.selectAll('.layer-mapdata')\n .data(_enabled && hasData ? [0] : []);\n\n layer.exit()\n .remove();\n\n layer = layer.enter()\n .append('g')\n .attr('class', 'layer-mapdata')\n .merge(layer);\n\n var surface = context.surface();\n if (!surface || surface.empty()) return; // not ready to draw yet, starting up\n\n\n // Gather data\n var geoData, polygonData;\n if (_template && vtService) { // fetch data from vector tile service\n var sourceID = _template;\n vtService.loadTiles(sourceID, _template, projection);\n geoData = vtService.data(sourceID, projection);\n } else {\n geoData = getFeatures(_geojson);\n }\n geoData = geoData.filter(getPath);\n polygonData = geoData.filter(isPolygon);\n\n\n // Draw clip paths for polygons\n var clipPaths = surface.selectAll('defs').selectAll('.clipPath-data')\n .data(polygonData, featureKey);\n\n clipPaths.exit()\n .remove();\n\n var clipPathsEnter = clipPaths.enter()\n .append('clipPath')\n .attr('class', 'clipPath-data')\n .attr('id', clipPathID);\n\n clipPathsEnter\n .append('path');\n\n clipPaths.merge(clipPathsEnter)\n .selectAll('path')\n .attr('d', getAreaPath);\n\n\n // Draw fill, shadow, stroke layers\n var datagroups = layer\n .selectAll('g.datagroup')\n .data(['fill', 'shadow', 'stroke']);\n\n datagroups = datagroups.enter()\n .append('g')\n .attr('class', function(d) { return 'datagroup datagroup-' + d; })\n .merge(datagroups);\n\n\n // Draw paths\n var pathData = {\n fill: polygonData,\n shadow: geoData,\n stroke: geoData\n };\n\n var paths = datagroups\n .selectAll('path')\n .data(function(layer) { return pathData[layer]; }, featureKey);\n\n // exit\n paths.exit()\n .remove();\n\n // enter/update\n paths = paths.enter()\n .append('path')\n .attr('class', function(d) {\n var datagroup = this.parentNode.__data__;\n return 'pathdata ' + datagroup + ' ' + featureClasses(d);\n })\n .attr('clip-path', function(d) {\n var datagroup = this.parentNode.__data__;\n return datagroup === 'fill' ? ('url(#' + clipPathID(d) + ')') : null;\n })\n .merge(paths)\n .attr('d', function(d) {\n var datagroup = this.parentNode.__data__;\n return datagroup === 'fill' ? getAreaPath(d) : getPath(d);\n });\n\n\n // Draw labels\n layer\n .call(drawLabels, 'label-halo', geoData)\n .call(drawLabels, 'label', geoData);\n\n\n function drawLabels(selection, textClass, data) {\n var labelPath = d3_geoPath(projection);\n var labelData = data.filter(function(d) {\n return _showLabels && d.properties && (d.properties.desc || d.properties.name);\n });\n\n var labels = selection.selectAll('text.' + textClass)\n .data(labelData, featureKey);\n\n // exit\n labels.exit()\n .remove();\n\n // enter/update\n labels = labels.enter()\n .append('text')\n .attr('class', function(d) { return textClass + ' ' + featureClasses(d); })\n .merge(labels)\n .text(function(d) {\n return d.properties.desc || d.properties.name;\n })\n .attr('x', function(d) {\n var centroid = labelPath.centroid(d);\n return centroid[0] + 11;\n })\n .attr('y', function(d) {\n var centroid = labelPath.centroid(d);\n return centroid[1];\n });\n }\n }\n\n\n function getExtension(fileName) {\n if (!fileName) return;\n\n var re = /\\.(gpx|kml|(geo)?json)$/i;\n var match = fileName.toLowerCase().match(re);\n return match && match.length && match[0];\n }\n\n\n function xmlToDom(textdata) {\n return (new DOMParser()).parseFromString(textdata, 'text/xml');\n }\n\n\n drawData.setFile = function(extension, data) {\n _template = null;\n _fileList = null;\n _geojson = null;\n _src = null;\n\n var gj;\n switch (extension) {\n case '.gpx':\n gj = toGeoJSON.gpx(xmlToDom(data));\n break;\n case '.kml':\n gj = toGeoJSON.kml(xmlToDom(data));\n break;\n case '.geojson':\n case '.json':\n gj = JSON.parse(data);\n break;\n }\n\n gj = gj || {};\n if (Object.keys(gj).length) {\n _geojson = ensureIDs(gj);\n _src = extension + ' data file';\n this.fitZoom();\n }\n\n dispatch.call('change');\n return this;\n };\n\n\n drawData.showLabels = function(val) {\n if (!arguments.length) return _showLabels;\n\n _showLabels = val;\n return this;\n };\n\n\n drawData.enabled = function(val) {\n if (!arguments.length) return _enabled;\n\n _enabled = val;\n if (_enabled) {\n showLayer();\n } else {\n hideLayer();\n }\n\n dispatch.call('change');\n return this;\n };\n\n\n drawData.hasData = function() {\n var gj = _geojson || {};\n return !!(_template || Object.keys(gj).length);\n };\n\n\n drawData.template = function(val, src) {\n if (!arguments.length) return _template;\n\n // test source against OSM imagery blacklists..\n var osm = context.connection();\n if (osm) {\n var blacklists = osm.imageryBlacklists();\n var fail = false;\n var tested = 0;\n var regex;\n\n for (var i = 0; i < blacklists.length; i++) {\n try {\n regex = new RegExp(blacklists[i]);\n fail = regex.test(val);\n tested++;\n if (fail) break;\n } catch (e) {\n /* noop */\n }\n }\n\n // ensure at least one test was run.\n if (!tested) {\n regex = new RegExp('.*\\.google(apis)?\\..*/(vt|kh)[\\?/].*([xyz]=.*){3}.*');\n fail = regex.test(val);\n }\n }\n\n _template = val;\n _fileList = null;\n _geojson = null;\n\n // strip off the querystring/hash from the template,\n // it often includes the access token\n _src = src || ('vectortile:' + val.split(/[?#]/)[0]);\n\n dispatch.call('change');\n return this;\n };\n\n\n drawData.geojson = function(gj, src) {\n if (!arguments.length) return _geojson;\n\n _template = null;\n _fileList = null;\n _geojson = null;\n _src = null;\n\n gj = gj || {};\n if (Object.keys(gj).length) {\n _geojson = ensureIDs(gj);\n _src = src || 'unknown.geojson';\n }\n\n dispatch.call('change');\n return this;\n };\n\n\n drawData.fileList = function(fileList) {\n if (!arguments.length) return _fileList;\n\n _template = null;\n _fileList = fileList;\n _geojson = null;\n _src = null;\n\n if (!fileList || !fileList.length) return this;\n var f = fileList[0];\n var extension = getExtension(f.name);\n var reader = new FileReader();\n reader.onload = (function() {\n return function(e) {\n drawData.setFile(extension, e.target.result);\n };\n })(f);\n\n reader.readAsText(f);\n\n return this;\n };\n\n\n drawData.url = function(url, defaultExtension) {\n _template = null;\n _fileList = null;\n _geojson = null;\n _src = null;\n\n // strip off any querystring/hash from the url before checking extension\n var testUrl = url.split(/[?#]/)[0];\n var extension = getExtension(testUrl) || defaultExtension;\n if (extension) {\n _template = null;\n d3_text(url)\n .then(function(data) {\n drawData.setFile(extension, data);\n var isTaskBoundsUrl = extension === '.gpx' && url.indexOf('project') > 0 && url.indexOf('task') > 0;\n if (isTaskBoundsUrl) {\n context.rapidContext().setTaskExtentByGpxData(data);\n }\n })\n .catch(function() {\n /* ignore */\n });\n } else {\n drawData.template(url);\n }\n\n return this;\n };\n\n\n drawData.getSrc = function() {\n return _src || '';\n };\n\n\n drawData.fitZoom = function() {\n var features = getFeatures(_geojson);\n if (!features.length) return;\n\n var map = context.map();\n var viewport = map.trimmedExtent().polygon();\n var coords = features.reduce(function(coords, feature) {\n var geom = feature.geometry;\n if (!geom) return coords;\n\n var c = geom.coordinates;\n\n /* eslint-disable no-fallthrough */\n switch (geom.type) {\n case 'Point':\n c = [c];\n case 'MultiPoint':\n case 'LineString':\n break;\n\n case 'MultiPolygon':\n c = utilArrayFlatten(c);\n case 'Polygon':\n case 'MultiLineString':\n c = utilArrayFlatten(c);\n break;\n }\n /* eslint-enable no-fallthrough */\n\n return utilArrayUnion(coords, c);\n }, []);\n\n if (!geoPolygonIntersectsPolygon(viewport, coords, true)) {\n var extent = geoExtent(d3_geoBounds({ type: 'LineString', coordinates: coords }));\n map.centerZoom(extent.center(), map.trimmedExtentZoom(extent));\n }\n\n return this;\n };\n\n\n init();\n return drawData;\n}\n","\nimport { fileFetcher } from '../core/file_fetcher';\nimport { svgPath } from './helpers';\n\n\nexport function svgDebug(projection, context) {\n\n function drawDebug(selection) {\n const showTile = context.getDebug('tile');\n const showCollision = context.getDebug('collision');\n const showImagery = context.getDebug('imagery');\n const showTouchTargets = context.getDebug('target');\n const showDownloaded = context.getDebug('downloaded');\n\n let debugData = [];\n if (showTile) {\n debugData.push({ class: 'red', label: 'tile' });\n }\n if (showCollision) {\n debugData.push({ class: 'yellow', label: 'collision' });\n }\n if (showImagery) {\n debugData.push({ class: 'orange', label: 'imagery' });\n }\n if (showTouchTargets) {\n debugData.push({ class: 'pink', label: 'touchTargets' });\n }\n if (showDownloaded) {\n debugData.push({ class: 'purple', label: 'downloaded' });\n }\n\n\n let legend = context.container().select('.main-content')\n .selectAll('.debug-legend')\n .data(debugData.length ? [0] : []);\n\n legend.exit()\n .remove();\n\n legend = legend.enter()\n .append('div')\n .attr('class', 'fillD debug-legend')\n .merge(legend);\n\n\n let legendItems = legend.selectAll('.debug-legend-item')\n .data(debugData, d => d.label);\n\n legendItems.exit()\n .remove();\n\n legendItems.enter()\n .append('span')\n .attr('class', d => `debug-legend-item ${d.class}`)\n .text(d => d.label);\n\n\n let layer = selection.selectAll('.layer-debug')\n .data(showImagery || showDownloaded ? [0] : []);\n\n layer.exit()\n .remove();\n\n layer = layer.enter()\n .append('g')\n .attr('class', 'layer-debug')\n .merge(layer);\n\n\n // imagery\n const extent = context.map().extent();\n fileFetcher.get('imagery')\n .then(d => {\n const hits = (showImagery && d.query.bbox(extent.rectangle(), true)) || [];\n const features = hits.map(d => d.features[d.id]);\n\n let imagery = layer.selectAll('path.debug-imagery')\n .data(features);\n\n imagery.exit()\n .remove();\n\n imagery.enter()\n .append('path')\n .attr('class', 'debug-imagery debug orange');\n })\n .catch(() => { /* ignore */ });\n\n // downloaded\n const osm = context.connection();\n let dataDownloaded = [];\n if (osm && showDownloaded) {\n const rtree = osm.caches('get').tile.rtree;\n dataDownloaded = rtree.all().map(bbox => {\n return {\n type: 'Feature',\n properties: { id: bbox.id },\n geometry: {\n type: 'Polygon',\n coordinates: [[\n [ bbox.minX, bbox.minY ],\n [ bbox.minX, bbox.maxY ],\n [ bbox.maxX, bbox.maxY ],\n [ bbox.maxX, bbox.minY ],\n [ bbox.minX, bbox.minY ]\n ]]\n }\n };\n });\n }\n\n let downloaded = layer\n .selectAll('path.debug-downloaded')\n .data(showDownloaded ? dataDownloaded : []);\n\n downloaded.exit()\n .remove();\n\n downloaded.enter()\n .append('path')\n .attr('class', 'debug-downloaded debug purple');\n\n // update\n layer.selectAll('path')\n .attr('d', svgPath(projection).geojson);\n }\n\n\n // This looks strange because `enabled` methods on other layers are\n // chainable getter/setters, and this one is just a getter.\n drawDebug.enabled = function() {\n if (!arguments.length) {\n return context.getDebug('tile') ||\n context.getDebug('collision') ||\n context.getDebug('imagery') ||\n context.getDebug('target') ||\n context.getDebug('downloaded');\n } else {\n return this;\n }\n };\n\n\n return drawDebug;\n}\n","import { svg as d3_svg } from 'd3-fetch';\nimport { select as d3_select } from 'd3-selection';\n\nimport { utilArrayUniq } from '../util';\n\n\n/*\n A standalone SVG element that contains only a `defs` sub-element. To be\n used once globally, since defs IDs must be unique within a document.\n*/\nexport function svgDefs(context) {\n\n function drawDefs(selection) {\n var defs = selection.append('defs');\n\n // add markers\n defs\n .append('marker')\n .attr('id', 'ideditor-oneway-marker')\n .attr('viewBox', '0 0 10 5')\n .attr('refX', 2.5)\n .attr('refY', 2.5)\n .attr('markerWidth', 2)\n .attr('markerHeight', 2)\n .attr('markerUnits', 'strokeWidth')\n .attr('orient', 'auto')\n .append('path')\n .attr('class', 'oneway-marker-path')\n .attr('d', 'M 5,3 L 0,3 L 0,2 L 5,2 L 5,0 L 10,2.5 L 5,5 z')\n .attr('stroke', 'none')\n .attr('fill', '#000')\n .attr('opacity', '0.75');\n\n // SVG markers have to be given a colour where they're defined\n // (they can't inherit it from the line they're attached to),\n // so we need to manually define markers for each color of tag\n // (also, it's slightly nicer if we can control the\n // positioning for different tags)\n function addSidedMarker(name, color, offset) {\n defs\n .append('marker')\n .attr('id', 'ideditor-sided-marker-' + name)\n .attr('viewBox', '0 0 2 2')\n .attr('refX', 1)\n .attr('refY', -offset)\n .attr('markerWidth', 1.5)\n .attr('markerHeight', 1.5)\n .attr('markerUnits', 'strokeWidth')\n .attr('orient', 'auto')\n .append('path')\n .attr('class', 'sided-marker-path sided-marker-' + name + '-path')\n .attr('d', 'M 0,0 L 1,1 L 2,0 z')\n .attr('stroke', 'none')\n .attr('fill', color);\n }\n addSidedMarker('natural', 'rgb(170, 170, 170)', 0);\n // for a coastline, the arrows are (somewhat unintuitively) on\n // the water side, so let's color them blue (with a gap) to\n // give a stronger indication\n addSidedMarker('coastline', '#77dede', 1);\n addSidedMarker('waterway', '#77dede', 1);\n // barriers have a dashed line, and separating the triangle\n // from the line visually suits that\n addSidedMarker('barrier', '#ddd', 1);\n addSidedMarker('man_made', '#fff', 0);\n\n defs\n .append('marker')\n .attr('id', 'ideditor-viewfield-marker')\n .attr('viewBox', '0 0 16 16')\n .attr('refX', 8)\n .attr('refY', 16)\n .attr('markerWidth', 4)\n .attr('markerHeight', 4)\n .attr('markerUnits', 'strokeWidth')\n .attr('orient', 'auto')\n .append('path')\n .attr('class', 'viewfield-marker-path')\n .attr('d', 'M 6,14 C 8,13.4 8,13.4 10,14 L 16,3 C 12,0 4,0 0,3 z')\n .attr('fill', '#333')\n .attr('fill-opacity', '0.75')\n .attr('stroke', '#fff')\n .attr('stroke-width', '0.5px')\n .attr('stroke-opacity', '0.75');\n\n defs\n .append('marker')\n .attr('id', 'ideditor-viewfield-marker-wireframe')\n .attr('viewBox', '0 0 16 16')\n .attr('refX', 8)\n .attr('refY', 16)\n .attr('markerWidth', 4)\n .attr('markerHeight', 4)\n .attr('markerUnits', 'strokeWidth')\n .attr('orient', 'auto')\n .append('path')\n .attr('class', 'viewfield-marker-path')\n .attr('d', 'M 6,14 C 8,13.4 8,13.4 10,14 L 16,3 C 12,0 4,0 0,3 z')\n .attr('fill', 'none')\n .attr('stroke', '#fff')\n .attr('stroke-width', '0.5px')\n .attr('stroke-opacity', '0.75');\n\n // add patterns\n var patterns = defs.selectAll('pattern')\n .data([\n // pattern name, pattern image name\n ['beach', 'dots'],\n ['construction', 'construction'],\n ['cemetery', 'cemetery'],\n ['cemetery_christian', 'cemetery_christian'],\n ['cemetery_buddhist', 'cemetery_buddhist'],\n ['cemetery_muslim', 'cemetery_muslim'],\n ['cemetery_jewish', 'cemetery_jewish'],\n ['farmland', 'farmland'],\n ['farmyard', 'farmyard'],\n ['forest', 'forest'],\n ['forest_broadleaved', 'forest_broadleaved'],\n ['forest_needleleaved', 'forest_needleleaved'],\n ['forest_leafless', 'forest_leafless'],\n ['golf_green', 'grass'],\n ['grass', 'grass'],\n ['landfill', 'landfill'],\n ['meadow', 'grass'],\n ['orchard', 'orchard'],\n ['pond', 'pond'],\n ['quarry', 'quarry'],\n ['scrub', 'bushes'],\n ['vineyard', 'vineyard'],\n ['water_standing', 'lines'],\n ['waves', 'waves'],\n ['wetland', 'wetland'],\n ['wetland_marsh', 'wetland_marsh'],\n ['wetland_swamp', 'wetland_swamp'],\n ['wetland_bog', 'wetland_bog'],\n ['wetland_reedbed', 'wetland_reedbed']\n ])\n .enter()\n .append('pattern')\n .attr('id', function (d) { return 'ideditor-pattern-' + d[0]; })\n .attr('width', 32)\n .attr('height', 32)\n .attr('patternUnits', 'userSpaceOnUse');\n\n patterns\n .append('rect')\n .attr('x', 0)\n .attr('y', 0)\n .attr('width', 32)\n .attr('height', 32)\n .attr('class', function (d) { return 'pattern-color-' + d[0]; });\n\n patterns\n .append('image')\n .attr('x', 0)\n .attr('y', 0)\n .attr('width', 32)\n .attr('height', 32)\n .attr('xlink:href', function (d) {\n return context.imagePath('pattern/' + d[1] + '.png');\n });\n\n // add clip paths\n defs.selectAll('clipPath')\n .data([12, 18, 20, 32, 45])\n .enter()\n .append('clipPath')\n .attr('id', function (d) { return 'ideditor-clip-square-' + d; })\n .append('rect')\n .attr('x', 0)\n .attr('y', 0)\n .attr('width', function (d) { return d; })\n .attr('height', function (d) { return d; });\n\n // add symbol spritesheets\n defs\n .call(drawDefs.addSprites, [\n 'iD-sprite', 'maki-sprite', 'temaki-sprite', 'fa-sprite', 'tnp-sprite', 'community-sprite'\n ], true);\n }\n\n\n drawDefs.addSprites = function(selection, ids, overrideColors) {\n var spritesheets = selection.selectAll('.spritesheet');\n var currData = spritesheets.data();\n var data = utilArrayUniq(currData.concat(ids));\n\n spritesheets\n .data(data)\n .enter()\n .append('g')\n .attr('class', function(d) { return 'spritesheet spritesheet-' + d; })\n .each(function(d) {\n var url = context.imagePath(d + '.svg');\n var node = d3_select(this).node();\n\n d3_svg(url)\n .then(function(svg) {\n node.appendChild(\n d3_select(svg.documentElement).attr('id', 'ideditor-' + d).node()\n );\n if (overrideColors && d !== 'iD-sprite') { // allow icon colors to be overridden..\n d3_select(node).selectAll('path')\n .attr('fill', 'currentColor');\n }\n })\n .catch(function() {\n /* ignore */\n });\n });\n };\n\n\n return drawDefs;\n}\n","import _throttle from 'lodash-es/throttle';\nimport { select as d3_select } from 'd3-selection';\n\nimport { modeBrowse } from '../modes/browse';\nimport { svgPointTransform } from './helpers';\nimport { services } from '../services';\n\nlet _layerEnabled = false;\nlet _qaService;\n\nexport function svgKeepRight(projection, context, dispatch) {\n const throttledRedraw = _throttle(() => dispatch.call('change'), 1000);\n const minZoom = 12;\n\n let touchLayer = d3_select(null);\n let drawLayer = d3_select(null);\n let layerVisible = false;\n\n function markerPath(selection, klass) {\n selection\n .attr('class', klass)\n .attr('transform', 'translate(-4, -24)')\n .attr('d', 'M11.6,6.2H7.1l1.4-5.1C8.6,0.6,8.1,0,7.5,0H2.2C1.7,0,1.3,0.3,1.3,0.8L0,10.2c-0.1,0.6,0.4,1.1,0.9,1.1h4.6l-1.8,7.6C3.6,19.4,4.1,20,4.7,20c0.3,0,0.6-0.2,0.8-0.5l6.9-11.9C12.7,7,12.3,6.2,11.6,6.2z');\n }\n\n // Loosely-coupled keepRight service for fetching issues.\n function getService() {\n if (services.keepRight && !_qaService) {\n _qaService = services.keepRight;\n _qaService.on('loaded', throttledRedraw);\n } else if (!services.keepRight && _qaService) {\n _qaService = null;\n }\n\n return _qaService;\n }\n\n // Show the markers\n function editOn() {\n if (!layerVisible) {\n layerVisible = true;\n drawLayer\n .style('display', 'block');\n }\n }\n\n // Immediately remove the markers and their touch targets\n function editOff() {\n if (layerVisible) {\n layerVisible = false;\n drawLayer\n .style('display', 'none');\n drawLayer.selectAll('.qaItem.keepRight')\n .remove();\n touchLayer.selectAll('.qaItem.keepRight')\n .remove();\n }\n }\n\n // Enable the layer. This shows the markers and transitions them to visible.\n function layerOn() {\n editOn();\n\n drawLayer\n .style('opacity', 0)\n .transition()\n .duration(250)\n .style('opacity', 1)\n .on('end interrupt', () => dispatch.call('change'));\n }\n\n // Disable the layer. This transitions the layer invisible and then hides the markers.\n function layerOff() {\n throttledRedraw.cancel();\n drawLayer.interrupt();\n touchLayer.selectAll('.qaItem.keepRight')\n .remove();\n\n drawLayer\n .transition()\n .duration(250)\n .style('opacity', 0)\n .on('end interrupt', () => {\n editOff();\n dispatch.call('change');\n });\n }\n\n // Update the issue markers\n function updateMarkers() {\n if (!layerVisible || !_layerEnabled) return;\n\n const service = getService();\n const selectedID = context.selectedErrorID();\n const data = (service ? service.getItems(projection) : []);\n const getTransform = svgPointTransform(projection);\n\n // Draw markers..\n const markers = drawLayer.selectAll('.qaItem.keepRight')\n .data(data, d => d.id);\n\n // exit\n markers.exit()\n .remove();\n\n // enter\n const markersEnter = markers.enter()\n .append('g')\n .attr('class', d => `qaItem ${d.service} itemId-${d.id} itemType-${d.parentIssueType}`);\n\n markersEnter\n .append('ellipse')\n .attr('cx', 0.5)\n .attr('cy', 1)\n .attr('rx', 6.5)\n .attr('ry', 3)\n .attr('class', 'stroke');\n\n markersEnter\n .append('path')\n .call(markerPath, 'shadow');\n\n markersEnter\n .append('use')\n .attr('class', 'qaItem-fill')\n .attr('width', '20px')\n .attr('height', '20px')\n .attr('x', '-8px')\n .attr('y', '-22px')\n .attr('xlink:href', '#iD-icon-bolt');\n\n // update\n markers\n .merge(markersEnter)\n .sort(sortY)\n .classed('selected', d => d.id === selectedID)\n .attr('transform', getTransform);\n\n\n // Draw targets..\n if (touchLayer.empty()) return;\n const fillClass = context.getDebug('target') ? 'pink ' : 'nocolor ';\n\n const targets = touchLayer.selectAll('.qaItem.keepRight')\n .data(data, d => d.id);\n\n // exit\n targets.exit()\n .remove();\n\n // enter/update\n targets.enter()\n .append('rect')\n .attr('width', '20px')\n .attr('height', '20px')\n .attr('x', '-8px')\n .attr('y', '-22px')\n .merge(targets)\n .sort(sortY)\n .attr('class', d => `qaItem ${d.service} target ${fillClass} itemId-${d.id}`)\n .attr('transform', getTransform);\n\n\n function sortY(a, b) {\n return (a.id === selectedID) ? 1\n : (b.id === selectedID) ? -1\n : (a.severity === 'error' && b.severity !== 'error') ? 1\n : (b.severity === 'error' && a.severity !== 'error') ? -1\n : b.loc[1] - a.loc[1];\n }\n }\n\n // Draw the keepRight layer and schedule loading issues and updating markers.\n function drawKeepRight(selection) {\n const service = getService();\n\n const surface = context.surface();\n if (surface && !surface.empty()) {\n touchLayer = surface.selectAll('.data-layer.touch .layer-touch.markers');\n }\n\n drawLayer = selection.selectAll('.layer-keepRight')\n .data(service ? [0] : []);\n\n drawLayer.exit()\n .remove();\n\n drawLayer = drawLayer.enter()\n .append('g')\n .attr('class', 'layer-keepRight')\n .style('display', _layerEnabled ? 'block' : 'none')\n .merge(drawLayer);\n\n if (_layerEnabled) {\n if (service && ~~context.map().zoom() >= minZoom) {\n editOn();\n service.loadIssues(projection);\n updateMarkers();\n } else {\n editOff();\n }\n }\n }\n\n // Toggles the layer on and off\n drawKeepRight.enabled = function(val) {\n if (!arguments.length) return _layerEnabled;\n\n _layerEnabled = val;\n if (_layerEnabled) {\n layerOn();\n } else {\n layerOff();\n if (context.selectedErrorID()) {\n context.enter(modeBrowse(context));\n }\n }\n\n dispatch.call('change');\n return this;\n };\n\n drawKeepRight.supported = () => !!getService();\n\n return drawKeepRight;\n}\n","import { select as d3_select } from 'd3-selection';\n\nimport { svgPointTransform } from './helpers';\nimport { geoMetersToLat } from '../geo';\n\n\nexport function svgGeolocate(projection) {\n var layer = d3_select(null);\n var _position;\n\n\n function init() {\n if (svgGeolocate.initialized) return; // run once\n svgGeolocate.enabled = false;\n svgGeolocate.initialized = true;\n }\n\n function showLayer() {\n layer.style('display', 'block');\n }\n\n\n function hideLayer() {\n layer\n .transition()\n .duration(250)\n .style('opacity', 0);\n }\n\n function layerOn() {\n layer\n .style('opacity', 0)\n .transition()\n .duration(250)\n .style('opacity', 1);\n\n }\n\n function layerOff() {\n layer.style('display', 'none');\n }\n\n function transform(d) {\n return svgPointTransform(projection)(d);\n }\n\n function accuracy(accuracy, loc) { // converts accuracy to pixels...\n var degreesRadius = geoMetersToLat(accuracy),\n tangentLoc = [loc[0], loc[1] + degreesRadius],\n projectedTangent = projection(tangentLoc),\n projectedLoc = projection([loc[0], loc[1]]);\n\n // southern most point will have higher pixel value...\n return Math.round(projectedLoc[1] - projectedTangent[1]).toString();\n }\n\n function update() {\n var geolocation = { loc: [_position.coords.longitude, _position.coords.latitude] };\n\n var groups = layer.selectAll('.geolocations').selectAll('.geolocation')\n .data([geolocation]);\n\n groups.exit()\n .remove();\n\n var pointsEnter = groups.enter()\n .append('g')\n .attr('class', 'geolocation');\n\n pointsEnter\n .append('circle')\n .attr('class', 'geolocate-radius')\n .attr('dx', '0')\n .attr('dy', '0')\n .attr('fill', 'rgb(15,128,225)')\n .attr('fill-opacity', '0.3')\n .attr('r', '0');\n\n pointsEnter\n .append('circle')\n .attr('dx', '0')\n .attr('dy', '0')\n .attr('fill', 'rgb(15,128,225)')\n .attr('stroke', 'white')\n .attr('stroke-width', '1.5')\n .attr('r', '6');\n\n groups.merge(pointsEnter)\n .attr('transform', transform);\n\n layer.select('.geolocate-radius').attr('r', accuracy(_position.coords.accuracy, geolocation.loc));\n }\n\n function drawLocation(selection) {\n var enabled = svgGeolocate.enabled;\n\n layer = selection.selectAll('.layer-geolocate')\n .data([0]);\n\n layer.exit()\n .remove();\n\n var layerEnter = layer.enter()\n .append('g')\n .attr('class', 'layer-geolocate')\n .style('display', enabled ? 'block' : 'none');\n\n layerEnter\n .append('g')\n .attr('class', 'geolocations');\n\n layer = layerEnter\n .merge(layer);\n\n if (enabled) {\n update();\n } else {\n layerOff();\n }\n }\n\n drawLocation.enabled = function (position, enabled) {\n if (!arguments.length) return svgGeolocate.enabled;\n _position = position;\n svgGeolocate.enabled = enabled;\n if (svgGeolocate.enabled) {\n showLayer();\n layerOn();\n } else {\n hideLayer();\n }\n return this;\n };\n\n init();\n return drawLocation;\n}\n","import _throttle from 'lodash-es/throttle';\n\nimport { geoPath as d3_geoPath } from 'd3-geo';\nimport RBush from 'rbush';\nimport { localizer } from '../core/localizer';\n\nimport {\n geoExtent, geoPolygonIntersectsPolygon, geoPathLength,\n geoScaleToZoom, geoVecInterp, geoVecLength\n} from '../geo';\nimport { presetManager } from '../presets';\nimport { osmEntity } from '../osm';\nimport { utilDetect } from '../util/detect';\nimport { utilDisplayName, utilDisplayNameForPath, utilEntitySelector } from '../util';\n\n\n\nexport function svgLabels(projection, context) {\n var path = d3_geoPath(projection);\n var detected = utilDetect();\n var baselineHack = (detected.ie ||\n detected.browser.toLowerCase() === 'edge' ||\n (detected.browser.toLowerCase() === 'firefox' && detected.version >= 70));\n var _rdrawn = new RBush();\n var _rskipped = new RBush();\n var _textWidthCache = {};\n var _entitybboxes = {};\n\n // Listed from highest to lowest priority\n var labelStack = [\n ['line', 'aeroway', '*', 12],\n ['line', 'highway', 'motorway', 12],\n ['line', 'highway', 'trunk', 12],\n ['line', 'highway', 'primary', 12],\n ['line', 'highway', 'secondary', 12],\n ['line', 'highway', 'tertiary', 12],\n ['line', 'highway', '*', 12],\n ['line', 'railway', '*', 12],\n ['line', 'waterway', '*', 12],\n ['area', 'aeroway', '*', 12],\n ['area', 'amenity', '*', 12],\n ['area', 'building', '*', 12],\n ['area', 'historic', '*', 12],\n ['area', 'leisure', '*', 12],\n ['area', 'man_made', '*', 12],\n ['area', 'natural', '*', 12],\n ['area', 'shop', '*', 12],\n ['area', 'tourism', '*', 12],\n ['area', 'camp_site', '*', 12],\n ['point', 'aeroway', '*', 10],\n ['point', 'amenity', '*', 10],\n ['point', 'building', '*', 10],\n ['point', 'historic', '*', 10],\n ['point', 'leisure', '*', 10],\n ['point', 'man_made', '*', 10],\n ['point', 'natural', '*', 10],\n ['point', 'shop', '*', 10],\n ['point', 'tourism', '*', 10],\n ['point', 'camp_site', '*', 10],\n ['line', 'name', '*', 12],\n ['area', 'name', '*', 12],\n ['point', 'name', '*', 10]\n ];\n\n\n function shouldSkipIcon(preset) {\n var noIcons = ['building', 'landuse', 'natural'];\n return noIcons.some(function(s) {\n return preset.id.indexOf(s) >= 0;\n });\n }\n\n\n function get(array, prop) {\n return function(d, i) { return array[i][prop]; };\n }\n\n\n function textWidth(text, size, elem) {\n var c = _textWidthCache[size];\n if (!c) c = _textWidthCache[size] = {};\n\n if (c[text]) {\n return c[text];\n\n } else if (elem) {\n c[text] = elem.getComputedTextLength();\n return c[text];\n\n } else {\n var str = encodeURIComponent(text).match(/%[CDEFcdef]/g);\n if (str === null) {\n return size / 3 * 2 * text.length;\n } else {\n return size / 3 * (2 * text.length + str.length);\n }\n }\n }\n\n\n function drawLinePaths(selection, entities, filter, classes, labels) {\n var paths = selection.selectAll('path')\n .filter(filter)\n .data(entities, osmEntity.key);\n\n // exit\n paths.exit()\n .remove();\n\n // enter/update\n paths.enter()\n .append('path')\n .style('stroke-width', get(labels, 'font-size'))\n .attr('id', function(d) { return 'ideditor-labelpath-' + d.id; })\n .attr('class', classes)\n .merge(paths)\n .attr('d', get(labels, 'lineString'));\n }\n\n\n function drawLineLabels(selection, entities, filter, classes, labels) {\n var texts = selection.selectAll('text.' + classes)\n .filter(filter)\n .data(entities, osmEntity.key);\n\n // exit\n texts.exit()\n .remove();\n\n // enter\n texts.enter()\n .append('text')\n .attr('class', function(d, i) { return classes + ' ' + labels[i].classes + ' ' + d.id; })\n .attr('dy', baselineHack ? '0.35em' : null)\n .append('textPath')\n .attr('class', 'textpath');\n\n // update\n selection.selectAll('text.' + classes).selectAll('.textpath')\n .filter(filter)\n .data(entities, osmEntity.key)\n .attr('startOffset', '50%')\n .attr('xlink:href', function(d) { return '#ideditor-labelpath-' + d.id; })\n .text(utilDisplayNameForPath);\n }\n\n\n function drawPointLabels(selection, entities, filter, classes, labels) {\n var texts = selection.selectAll('text.' + classes)\n .filter(filter)\n .data(entities, osmEntity.key);\n\n // exit\n texts.exit()\n .remove();\n\n // enter/update\n texts.enter()\n .append('text')\n .attr('class', function(d, i) {\n return classes + ' ' + labels[i].classes + ' ' + d.id;\n })\n .merge(texts)\n .attr('x', get(labels, 'x'))\n .attr('y', get(labels, 'y'))\n .style('text-anchor', get(labels, 'textAnchor'))\n .text(utilDisplayName)\n .each(function(d, i) {\n textWidth(utilDisplayName(d), labels[i].height, this);\n });\n }\n\n\n function drawAreaLabels(selection, entities, filter, classes, labels) {\n entities = entities.filter(hasText);\n labels = labels.filter(hasText);\n drawPointLabels(selection, entities, filter, classes, labels);\n\n function hasText(d, i) {\n return labels[i].hasOwnProperty('x') && labels[i].hasOwnProperty('y');\n }\n }\n\n\n function drawAreaIcons(selection, entities, filter, classes, labels) {\n var icons = selection.selectAll('use.' + classes)\n .filter(filter)\n .data(entities, osmEntity.key);\n\n // exit\n icons.exit()\n .remove();\n\n // enter/update\n icons.enter()\n .append('use')\n .attr('class', 'icon ' + classes)\n .attr('width', '17px')\n .attr('height', '17px')\n .merge(icons)\n .attr('transform', get(labels, 'transform'))\n .attr('xlink:href', function(d) {\n var preset = presetManager.match(d, context.graph());\n var picon = preset && preset.icon;\n\n if (!picon) {\n return '';\n } else {\n var isMaki = /^maki-/.test(picon);\n return '#' + picon + (isMaki ? '-15' : '');\n }\n });\n }\n\n\n function drawCollisionBoxes(selection, rtree, which) {\n var classes = 'debug ' + which + ' ' + (which === 'debug-skipped' ? 'orange' : 'yellow');\n\n var gj = [];\n if (context.getDebug('collision')) {\n gj = rtree.all().map(function(d) {\n return { type: 'Polygon', coordinates: [[\n [d.minX, d.minY],\n [d.maxX, d.minY],\n [d.maxX, d.maxY],\n [d.minX, d.maxY],\n [d.minX, d.minY]\n ]]};\n });\n }\n\n var boxes = selection.selectAll('.' + which)\n .data(gj);\n\n // exit\n boxes.exit()\n .remove();\n\n // enter/update\n boxes.enter()\n .append('path')\n .attr('class', classes)\n .merge(boxes)\n .attr('d', d3_geoPath());\n }\n\n\n function drawLabels(selection, graph, entities, filter, dimensions, fullRedraw) {\n var wireframe = context.surface().classed('fill-wireframe');\n var zoom = geoScaleToZoom(projection.scale());\n\n var labelable = [];\n var renderNodeAs = {};\n var i, j, k, entity, geometry;\n\n for (i = 0; i < labelStack.length; i++) {\n labelable.push([]);\n }\n\n if (fullRedraw) {\n _rdrawn.clear();\n _rskipped.clear();\n _entitybboxes = {};\n\n } else {\n for (i = 0; i < entities.length; i++) {\n entity = entities[i];\n var toRemove = []\n .concat(_entitybboxes[entity.id] || [])\n .concat(_entitybboxes[entity.id + 'I'] || []);\n\n for (j = 0; j < toRemove.length; j++) {\n _rdrawn.remove(toRemove[j]);\n _rskipped.remove(toRemove[j]);\n }\n }\n }\n\n // Loop through all the entities to do some preprocessing\n for (i = 0; i < entities.length; i++) {\n entity = entities[i];\n geometry = entity.geometry(graph);\n\n // Insert collision boxes around interesting points/vertices\n if (geometry === 'point' || (geometry === 'vertex' && isInterestingVertex(entity))) {\n var hasDirections = entity.directions(graph, projection).length;\n var markerPadding;\n\n if (!wireframe && geometry === 'point' && !(zoom >= 18 && hasDirections)) {\n renderNodeAs[entity.id] = 'point';\n markerPadding = 20; // extra y for marker height\n } else {\n renderNodeAs[entity.id] = 'vertex';\n markerPadding = 0;\n }\n\n var coord = projection(entity.loc);\n var nodePadding = 10;\n var bbox = {\n minX: coord[0] - nodePadding,\n minY: coord[1] - nodePadding - markerPadding,\n maxX: coord[0] + nodePadding,\n maxY: coord[1] + nodePadding\n };\n\n doInsert(bbox, entity.id + 'P');\n }\n\n // From here on, treat vertices like points\n if (geometry === 'vertex') {\n geometry = 'point';\n }\n\n // Determine which entities are label-able\n var preset = geometry === 'area' && presetManager.match(entity, graph);\n var icon = preset && !shouldSkipIcon(preset) && preset.icon;\n\n if (!icon && !utilDisplayName(entity))\n continue;\n\n for (k = 0; k < labelStack.length; k++) {\n var matchGeom = labelStack[k][0];\n var matchKey = labelStack[k][1];\n var matchVal = labelStack[k][2];\n var hasVal = entity.tags[matchKey];\n\n if (geometry === matchGeom && hasVal && (matchVal === '*' || matchVal === hasVal)) {\n labelable[k].push(entity);\n break;\n }\n }\n }\n\n var positions = {\n point: [],\n line: [],\n area: []\n };\n\n var labelled = {\n point: [],\n line: [],\n area: []\n };\n\n // Try and find a valid label for labellable entities\n for (k = 0; k < labelable.length; k++) {\n var fontSize = labelStack[k][3];\n\n for (i = 0; i < labelable[k].length; i++) {\n entity = labelable[k][i];\n geometry = entity.geometry(graph);\n\n var getName = (geometry === 'line') ? utilDisplayNameForPath : utilDisplayName;\n var name = getName(entity);\n var width = name && textWidth(name, fontSize);\n var p = null;\n\n if (geometry === 'point' || geometry === 'vertex') {\n // no point or vertex labels in wireframe mode\n // no vertex labels at low zooms (vertices have no icons)\n if (wireframe) continue;\n var renderAs = renderNodeAs[entity.id];\n if (renderAs === 'vertex' && zoom < 17) continue;\n\n p = getPointLabel(entity, width, fontSize, renderAs);\n\n } else if (geometry === 'line') {\n p = getLineLabel(entity, width, fontSize);\n\n } else if (geometry === 'area') {\n p = getAreaLabel(entity, width, fontSize);\n }\n\n if (p) {\n if (geometry === 'vertex') { geometry = 'point'; } // treat vertex like point\n p.classes = geometry + ' tag-' + labelStack[k][1];\n positions[geometry].push(p);\n labelled[geometry].push(entity);\n }\n }\n }\n\n\n function isInterestingVertex(entity) {\n var selectedIDs = context.selectedIDs();\n\n return entity.hasInterestingTags() ||\n entity.isEndpoint(graph) ||\n entity.isConnected(graph) ||\n selectedIDs.indexOf(entity.id) !== -1 ||\n graph.parentWays(entity).some(function(parent) {\n return selectedIDs.indexOf(parent.id) !== -1;\n });\n }\n\n\n function getPointLabel(entity, width, height, geometry) {\n var y = (geometry === 'point' ? -12 : 0);\n var pointOffsets = {\n ltr: [15, y, 'start'],\n rtl: [-15, y, 'end']\n };\n\n var textDirection = localizer.textDirection();\n\n var coord = projection(entity.loc);\n var textPadding = 2;\n var offset = pointOffsets[textDirection];\n var p = {\n height: height,\n width: width,\n x: coord[0] + offset[0],\n y: coord[1] + offset[1],\n textAnchor: offset[2]\n };\n\n // insert a collision box for the text label..\n var bbox;\n if (textDirection === 'rtl') {\n bbox = {\n minX: p.x - width - textPadding,\n minY: p.y - (height / 2) - textPadding,\n maxX: p.x + textPadding,\n maxY: p.y + (height / 2) + textPadding\n };\n } else {\n bbox = {\n minX: p.x - textPadding,\n minY: p.y - (height / 2) - textPadding,\n maxX: p.x + width + textPadding,\n maxY: p.y + (height / 2) + textPadding\n };\n }\n\n if (tryInsert([bbox], entity.id, true)) {\n return p;\n }\n }\n\n\n function getLineLabel(entity, width, height) {\n var viewport = geoExtent(context.projection.clipExtent()).polygon();\n var points = graph.childNodes(entity)\n .map(function(node) { return projection(node.loc); });\n var length = geoPathLength(points);\n\n if (length < width + 20) return;\n\n // % along the line to attempt to place the label\n var lineOffsets = [50, 45, 55, 40, 60, 35, 65, 30, 70,\n 25, 75, 20, 80, 15, 95, 10, 90, 5, 95];\n var padding = 3;\n\n for (var i = 0; i < lineOffsets.length; i++) {\n var offset = lineOffsets[i];\n var middle = offset / 100 * length;\n var start = middle - width / 2;\n\n if (start < 0 || start + width > length) continue;\n\n // generate subpath and ignore paths that are invalid or don't cross viewport.\n var sub = subpath(points, start, start + width);\n if (!sub || !geoPolygonIntersectsPolygon(viewport, sub, true)) {\n continue;\n }\n\n var isReverse = reverse(sub);\n if (isReverse) {\n sub = sub.reverse();\n }\n\n var bboxes = [];\n var boxsize = (height + 2) / 2;\n\n for (var j = 0; j < sub.length - 1; j++) {\n var a = sub[j];\n var b = sub[j + 1];\n\n // split up the text into small collision boxes\n var num = Math.max(1, Math.floor(geoVecLength(a, b) / boxsize / 2));\n\n for (var box = 0; box < num; box++) {\n var p = geoVecInterp(a, b, box / num);\n var x0 = p[0] - boxsize - padding;\n var y0 = p[1] - boxsize - padding;\n var x1 = p[0] + boxsize + padding;\n var y1 = p[1] + boxsize + padding;\n\n bboxes.push({\n minX: Math.min(x0, x1),\n minY: Math.min(y0, y1),\n maxX: Math.max(x0, x1),\n maxY: Math.max(y0, y1)\n });\n }\n }\n\n if (tryInsert(bboxes, entity.id, false)) { // accept this one\n return {\n 'font-size': height + 2,\n lineString: lineString(sub),\n startOffset: offset + '%'\n };\n }\n }\n\n function reverse(p) {\n var angle = Math.atan2(p[1][1] - p[0][1], p[1][0] - p[0][0]);\n return !(p[0][0] < p[p.length - 1][0] && angle < Math.PI/2 && angle > -Math.PI/2);\n }\n\n function lineString(points) {\n return 'M' + points.join('L');\n }\n\n function subpath(points, from, to) {\n var sofar = 0;\n var start, end, i0, i1;\n\n for (var i = 0; i < points.length - 1; i++) {\n var a = points[i];\n var b = points[i + 1];\n var current = geoVecLength(a, b);\n var portion;\n if (!start && sofar + current >= from) {\n portion = (from - sofar) / current;\n start = [\n a[0] + portion * (b[0] - a[0]),\n a[1] + portion * (b[1] - a[1])\n ];\n i0 = i + 1;\n }\n if (!end && sofar + current >= to) {\n portion = (to - sofar) / current;\n end = [\n a[0] + portion * (b[0] - a[0]),\n a[1] + portion * (b[1] - a[1])\n ];\n i1 = i + 1;\n }\n sofar += current;\n }\n\n var result = points.slice(i0, i1);\n result.unshift(start);\n result.push(end);\n return result;\n }\n }\n\n\n function getAreaLabel(entity, width, height) {\n var centroid = path.centroid(entity.asGeoJSON(graph, true));\n var extent = entity.extent(graph);\n var areaWidth = projection(extent[1])[0] - projection(extent[0])[0];\n\n if (isNaN(centroid[0]) || areaWidth < 20) return;\n\n var preset = presetManager.match(entity, context.graph());\n var picon = preset && preset.icon;\n var iconSize = 17;\n var padding = 2;\n var p = {};\n\n if (picon) { // icon and label..\n if (addIcon()) {\n addLabel(iconSize + padding);\n return p;\n }\n } else { // label only..\n if (addLabel(0)) {\n return p;\n }\n }\n\n\n function addIcon() {\n var iconX = centroid[0] - (iconSize / 2);\n var iconY = centroid[1] - (iconSize / 2);\n var bbox = {\n minX: iconX,\n minY: iconY,\n maxX: iconX + iconSize,\n maxY: iconY + iconSize\n };\n\n if (tryInsert([bbox], entity.id + 'I', true)) {\n p.transform = 'translate(' + iconX + ',' + iconY + ')';\n return true;\n }\n return false;\n }\n\n function addLabel(yOffset) {\n if (width && areaWidth >= width + 20) {\n var labelX = centroid[0];\n var labelY = centroid[1] + yOffset;\n var bbox = {\n minX: labelX - (width / 2) - padding,\n minY: labelY - (height / 2) - padding,\n maxX: labelX + (width / 2) + padding,\n maxY: labelY + (height / 2) + padding\n };\n\n if (tryInsert([bbox], entity.id, true)) {\n p.x = labelX;\n p.y = labelY;\n p.textAnchor = 'middle';\n p.height = height;\n return true;\n }\n }\n return false;\n }\n }\n\n\n // force insert a singular bounding box\n // singular box only, no array, id better be unique\n function doInsert(bbox, id) {\n bbox.id = id;\n\n var oldbox = _entitybboxes[id];\n if (oldbox) {\n _rdrawn.remove(oldbox);\n }\n _entitybboxes[id] = bbox;\n _rdrawn.insert(bbox);\n }\n\n\n function tryInsert(bboxes, id, saveSkipped) {\n var skipped = false;\n\n for (var i = 0; i < bboxes.length; i++) {\n var bbox = bboxes[i];\n bbox.id = id;\n\n // Check that label is visible\n if (bbox.minX < 0 || bbox.minY < 0 || bbox.maxX > dimensions[0] || bbox.maxY > dimensions[1]) {\n skipped = true;\n break;\n }\n if (_rdrawn.collides(bbox)) {\n skipped = true;\n break;\n }\n }\n\n _entitybboxes[id] = bboxes;\n\n if (skipped) {\n if (saveSkipped) {\n _rskipped.load(bboxes);\n }\n } else {\n _rdrawn.load(bboxes);\n }\n\n return !skipped;\n }\n\n\n var layer = selection.selectAll('.layer-osm.labels');\n layer.selectAll('.labels-group')\n .data(['halo', 'label', 'debug'])\n .enter()\n .append('g')\n .attr('class', function(d) { return 'labels-group ' + d; });\n\n var halo = layer.selectAll('.labels-group.halo');\n var label = layer.selectAll('.labels-group.label');\n var debug = layer.selectAll('.labels-group.debug');\n\n // points\n drawPointLabels(label, labelled.point, filter, 'pointlabel', positions.point);\n drawPointLabels(halo, labelled.point, filter, 'pointlabel-halo', positions.point);\n\n // lines\n drawLinePaths(layer, labelled.line, filter, '', positions.line);\n drawLineLabels(label, labelled.line, filter, 'linelabel', positions.line);\n drawLineLabels(halo, labelled.line, filter, 'linelabel-halo', positions.line);\n\n // areas\n drawAreaLabels(label, labelled.area, filter, 'arealabel', positions.area);\n drawAreaLabels(halo, labelled.area, filter, 'arealabel-halo', positions.area);\n drawAreaIcons(label, labelled.area, filter, 'areaicon', positions.area);\n drawAreaIcons(halo, labelled.area, filter, 'areaicon-halo', positions.area);\n\n // debug\n drawCollisionBoxes(debug, _rskipped, 'debug-skipped');\n drawCollisionBoxes(debug, _rdrawn, 'debug-drawn');\n\n layer.call(filterLabels);\n }\n\n\n function filterLabels(selection) {\n var drawLayer = selection.selectAll('.layer-osm.labels');\n var layers = drawLayer.selectAll('.labels-group.halo, .labels-group.label');\n\n layers.selectAll('.nolabel')\n .classed('nolabel', false);\n\n var mouse = context.map().mouse();\n var graph = context.graph();\n var selectedIDs = context.selectedIDs();\n var ids = [];\n var pad, bbox;\n\n // hide labels near the mouse\n if (mouse) {\n pad = 20;\n bbox = { minX: mouse[0] - pad, minY: mouse[1] - pad, maxX: mouse[0] + pad, maxY: mouse[1] + pad };\n var nearMouse = _rdrawn.search(bbox).map(function(entity) { return entity.id; });\n ids.push.apply(ids, nearMouse);\n }\n\n // hide labels on selected nodes (they look weird when dragging / haloed)\n for (var i = 0; i < selectedIDs.length; i++) {\n var entity = graph.hasEntity(selectedIDs[i]);\n if (entity && entity.type === 'node') {\n ids.push(selectedIDs[i]);\n }\n }\n\n layers.selectAll(utilEntitySelector(ids))\n .classed('nolabel', true);\n\n\n // draw the mouse bbox if debugging is on..\n var debug = selection.selectAll('.labels-group.debug');\n var gj = [];\n if (context.getDebug('collision')) {\n gj = bbox ? [{\n type: 'Polygon',\n coordinates: [[\n [bbox.minX, bbox.minY],\n [bbox.maxX, bbox.minY],\n [bbox.maxX, bbox.maxY],\n [bbox.minX, bbox.maxY],\n [bbox.minX, bbox.minY]\n ]]\n }] : [];\n }\n\n var box = debug.selectAll('.debug-mouse')\n .data(gj);\n\n // exit\n box.exit()\n .remove();\n\n // enter/update\n box.enter()\n .append('path')\n .attr('class', 'debug debug-mouse yellow')\n .merge(box)\n .attr('d', d3_geoPath());\n }\n\n\n var throttleFilterLabels = _throttle(filterLabels, 100);\n\n\n drawLabels.observe = function(selection) {\n var listener = function() { throttleFilterLabels(selection); };\n selection.on('mousemove.hidelabels', listener);\n context.on('enter.hidelabels', listener);\n };\n\n\n drawLabels.off = function(selection) {\n throttleFilterLabels.cancel();\n selection.on('mousemove.hidelabels', null);\n context.on('enter.hidelabels', null);\n };\n\n\n return drawLabels;\n}\n","import _throttle from 'lodash-es/throttle';\nimport { select as d3_select } from 'd3-selection';\n\nimport { modeBrowse } from '../modes/browse';\nimport { svgPointTransform } from './helpers';\nimport { services } from '../services';\n\nlet _layerEnabled = false;\nlet _qaService;\n\nexport function svgImproveOSM(projection, context, dispatch) {\n const throttledRedraw = _throttle(() => dispatch.call('change'), 1000);\n const minZoom = 12;\n\n let touchLayer = d3_select(null);\n let drawLayer = d3_select(null);\n let layerVisible = false;\n\n function markerPath(selection, klass) {\n selection\n .attr('class', klass)\n .attr('transform', 'translate(-10, -28)')\n .attr('points', '16,3 4,3 1,6 1,17 4,20 7,20 10,27 13,20 16,20 19,17.033 19,6');\n }\n\n // Loosely-coupled improveOSM service for fetching issues\n function getService() {\n if (services.improveOSM && !_qaService) {\n _qaService = services.improveOSM;\n _qaService.on('loaded', throttledRedraw);\n } else if (!services.improveOSM && _qaService) {\n _qaService = null;\n }\n\n return _qaService;\n }\n\n // Show the markers\n function editOn() {\n if (!layerVisible) {\n layerVisible = true;\n drawLayer\n .style('display', 'block');\n }\n }\n\n // Immediately remove the markers and their touch targets\n function editOff() {\n if (layerVisible) {\n layerVisible = false;\n drawLayer\n .style('display', 'none');\n drawLayer.selectAll('.qaItem.improveOSM')\n .remove();\n touchLayer.selectAll('.qaItem.improveOSM')\n .remove();\n }\n }\n\n // Enable the layer. This shows the markers and transitions them to visible.\n function layerOn() {\n editOn();\n\n drawLayer\n .style('opacity', 0)\n .transition()\n .duration(250)\n .style('opacity', 1)\n .on('end interrupt', () => dispatch.call('change'));\n }\n\n // Disable the layer. This transitions the layer invisible and then hides the markers.\n function layerOff() {\n throttledRedraw.cancel();\n drawLayer.interrupt();\n touchLayer.selectAll('.qaItem.improveOSM')\n .remove();\n\n drawLayer\n .transition()\n .duration(250)\n .style('opacity', 0)\n .on('end interrupt', () => {\n editOff();\n dispatch.call('change');\n });\n }\n\n // Update the issue markers\n function updateMarkers() {\n if (!layerVisible || !_layerEnabled) return;\n\n const service = getService();\n const selectedID = context.selectedErrorID();\n const data = (service ? service.getItems(projection) : []);\n const getTransform = svgPointTransform(projection);\n\n // Draw markers..\n const markers = drawLayer.selectAll('.qaItem.improveOSM')\n .data(data, d => d.id);\n\n // exit\n markers.exit()\n .remove();\n\n // enter\n const markersEnter = markers.enter()\n .append('g')\n .attr('class', d => `qaItem ${d.service} itemId-${d.id} itemType-${d.itemType}`);\n\n markersEnter\n .append('polygon')\n .call(markerPath, 'shadow');\n\n markersEnter\n .append('ellipse')\n .attr('cx', 0)\n .attr('cy', 0)\n .attr('rx', 4.5)\n .attr('ry', 2)\n .attr('class', 'stroke');\n\n markersEnter\n .append('polygon')\n .attr('fill', 'currentColor')\n .call(markerPath, 'qaItem-fill');\n\n markersEnter\n .append('use')\n .attr('transform', 'translate(-6.5, -23)')\n .attr('class', 'icon-annotation')\n .attr('width', '13px')\n .attr('height', '13px')\n .attr('xlink:href', d => {\n const picon = d.icon;\n\n if (!picon) {\n return '';\n } else {\n const isMaki = /^maki-/.test(picon);\n return `#${picon}${isMaki ? '-11' : ''}`;\n }\n });\n\n // update\n markers\n .merge(markersEnter)\n .sort(sortY)\n .classed('selected', d => d.id === selectedID)\n .attr('transform', getTransform);\n\n\n // Draw targets..\n if (touchLayer.empty()) return;\n const fillClass = context.getDebug('target') ? 'pink ' : 'nocolor ';\n\n const targets = touchLayer.selectAll('.qaItem.improveOSM')\n .data(data, d => d.id);\n\n // exit\n targets.exit()\n .remove();\n\n // enter/update\n targets.enter()\n .append('rect')\n .attr('width', '20px')\n .attr('height', '30px')\n .attr('x', '-10px')\n .attr('y', '-28px')\n .merge(targets)\n .sort(sortY)\n .attr('class', d => `qaItem ${d.service} target ${fillClass} itemId-${d.id}`)\n .attr('transform', getTransform);\n\n function sortY(a, b) {\n return (a.id === selectedID) ? 1\n : (b.id === selectedID) ? -1\n : b.loc[1] - a.loc[1];\n }\n }\n\n // Draw the ImproveOSM layer and schedule loading issues and updating markers.\n function drawImproveOSM(selection) {\n const service = getService();\n\n const surface = context.surface();\n if (surface && !surface.empty()) {\n touchLayer = surface.selectAll('.data-layer.touch .layer-touch.markers');\n }\n\n drawLayer = selection.selectAll('.layer-improveOSM')\n .data(service ? [0] : []);\n\n drawLayer.exit()\n .remove();\n\n drawLayer = drawLayer.enter()\n .append('g')\n .attr('class', 'layer-improveOSM')\n .style('display', _layerEnabled ? 'block' : 'none')\n .merge(drawLayer);\n\n if (_layerEnabled) {\n if (service && ~~context.map().zoom() >= minZoom) {\n editOn();\n service.loadIssues(projection);\n updateMarkers();\n } else {\n editOff();\n }\n }\n }\n\n // Toggles the layer on and off\n drawImproveOSM.enabled = function(val) {\n if (!arguments.length) return _layerEnabled;\n\n _layerEnabled = val;\n if (_layerEnabled) {\n layerOn();\n } else {\n layerOff();\n if (context.selectedErrorID()) {\n context.enter(modeBrowse(context));\n }\n }\n\n dispatch.call('change');\n return this;\n };\n\n drawImproveOSM.supported = () => !!getService();\n\n return drawImproveOSM;\n}\n","import _throttle from 'lodash-es/throttle';\nimport { select as d3_select } from 'd3-selection';\n\nimport { modeBrowse } from '../modes/browse';\nimport { svgPointTransform } from './helpers';\nimport { services } from '../services';\n\nlet _layerEnabled = false;\nlet _qaService;\n\nexport function svgOsmose(projection, context, dispatch) {\n const throttledRedraw = _throttle(() => dispatch.call('change'), 1000);\n const minZoom = 12;\n\n let touchLayer = d3_select(null);\n let drawLayer = d3_select(null);\n let layerVisible = false;\n\n function markerPath(selection, klass) {\n selection\n .attr('class', klass)\n .attr('transform', 'translate(-10, -28)')\n .attr('points', '16,3 4,3 1,6 1,17 4,20 7,20 10,27 13,20 16,20 19,17.033 19,6');\n }\n\n // Loosely-coupled osmose service for fetching issues\n function getService() {\n if (services.osmose && !_qaService) {\n _qaService = services.osmose;\n _qaService.on('loaded', throttledRedraw);\n } else if (!services.osmose && _qaService) {\n _qaService = null;\n }\n\n return _qaService;\n }\n\n // Show the markers\n function editOn() {\n if (!layerVisible) {\n layerVisible = true;\n drawLayer\n .style('display', 'block');\n }\n }\n\n // Immediately remove the markers and their touch targets\n function editOff() {\n if (layerVisible) {\n layerVisible = false;\n drawLayer\n .style('display', 'none');\n drawLayer.selectAll('.qaItem.osmose')\n .remove();\n touchLayer.selectAll('.qaItem.osmose')\n .remove();\n }\n }\n\n // Enable the layer. This shows the markers and transitions them to visible.\n function layerOn() {\n editOn();\n\n drawLayer\n .style('opacity', 0)\n .transition()\n .duration(250)\n .style('opacity', 1)\n .on('end interrupt', () => dispatch.call('change'));\n }\n\n // Disable the layer. This transitions the layer invisible and then hides the markers.\n function layerOff() {\n throttledRedraw.cancel();\n drawLayer.interrupt();\n touchLayer.selectAll('.qaItem.osmose')\n .remove();\n\n drawLayer\n .transition()\n .duration(250)\n .style('opacity', 0)\n .on('end interrupt', () => {\n editOff();\n dispatch.call('change');\n });\n }\n\n // Update the issue markers\n function updateMarkers() {\n if (!layerVisible || !_layerEnabled) return;\n\n const service = getService();\n const selectedID = context.selectedErrorID();\n const data = (service ? service.getItems(projection) : []);\n const getTransform = svgPointTransform(projection);\n\n // Draw markers..\n const markers = drawLayer.selectAll('.qaItem.osmose')\n .data(data, d => d.id);\n\n // exit\n markers.exit()\n .remove();\n\n // enter\n const markersEnter = markers.enter()\n .append('g')\n .attr('class', d => `qaItem ${d.service} itemId-${d.id} itemType-${d.itemType}`);\n\n markersEnter\n .append('polygon')\n .call(markerPath, 'shadow');\n\n markersEnter\n .append('ellipse')\n .attr('cx', 0)\n .attr('cy', 0)\n .attr('rx', 4.5)\n .attr('ry', 2)\n .attr('class', 'stroke');\n\n markersEnter\n .append('polygon')\n .attr('fill', d => service.getColor(d.item))\n .call(markerPath, 'qaItem-fill');\n\n markersEnter\n .append('use')\n .attr('transform', 'translate(-6.5, -23)')\n .attr('class', 'icon-annotation')\n .attr('width', '13px')\n .attr('height', '13px')\n .attr('xlink:href', d => {\n const picon = d.icon;\n\n if (!picon) {\n return '';\n } else {\n const isMaki = /^maki-/.test(picon);\n return `#${picon}${isMaki ? '-11' : ''}`;\n }\n });\n\n // update\n markers\n .merge(markersEnter)\n .sort(sortY)\n .classed('selected', d => d.id === selectedID)\n .attr('transform', getTransform);\n\n // Draw targets..\n if (touchLayer.empty()) return;\n const fillClass = context.getDebug('target') ? 'pink' : 'nocolor';\n\n const targets = touchLayer.selectAll('.qaItem.osmose')\n .data(data, d => d.id);\n\n // exit\n targets.exit()\n .remove();\n\n // enter/update\n targets.enter()\n .append('rect')\n .attr('width', '20px')\n .attr('height', '30px')\n .attr('x', '-10px')\n .attr('y', '-28px')\n .merge(targets)\n .sort(sortY)\n .attr('class', d => `qaItem ${d.service} target ${fillClass} itemId-${d.id}`)\n .attr('transform', getTransform);\n\n function sortY(a, b) {\n return (a.id === selectedID) ? 1\n : (b.id === selectedID) ? -1\n : b.loc[1] - a.loc[1];\n }\n }\n\n // Draw the Osmose layer and schedule loading issues and updating markers.\n function drawOsmose(selection) {\n const service = getService();\n\n const surface = context.surface();\n if (surface && !surface.empty()) {\n touchLayer = surface.selectAll('.data-layer.touch .layer-touch.markers');\n }\n\n drawLayer = selection.selectAll('.layer-osmose')\n .data(service ? [0] : []);\n\n drawLayer.exit()\n .remove();\n\n drawLayer = drawLayer.enter()\n .append('g')\n .attr('class', 'layer-osmose')\n .style('display', _layerEnabled ? 'block' : 'none')\n .merge(drawLayer);\n\n if (_layerEnabled) {\n if (service && ~~context.map().zoom() >= minZoom) {\n editOn();\n service.loadIssues(projection);\n updateMarkers();\n } else {\n editOff();\n }\n }\n }\n\n // Toggles the layer on and off\n drawOsmose.enabled = function(val) {\n if (!arguments.length) return _layerEnabled;\n\n _layerEnabled = val;\n if (_layerEnabled) {\n // Strings supplied by Osmose fetched before showing layer for first time\n // NOTE: Currently no way to change locale in iD at runtime, would need to re-call this method if that's ever implemented\n // Also, If layer is toggled quickly multiple requests are sent\n getService().loadStrings()\n .then(layerOn)\n .catch(err => {\n console.log(err); // eslint-disable-line no-console\n });\n } else {\n layerOff();\n if (context.selectedErrorID()) {\n context.enter(modeBrowse(context));\n }\n }\n\n dispatch.call('change');\n return this;\n };\n\n drawOsmose.supported = () => !!getService();\n\n return drawOsmose;\n}\n","import _throttle from 'lodash-es/throttle';\nimport { select as d3_select } from 'd3-selection';\nimport { svgPath, svgPointTransform } from './helpers';\nimport { services } from '../services';\n\n\nexport function svgStreetside(projection, context, dispatch) {\n var throttledRedraw = _throttle(function () { dispatch.call('change'); }, 1000);\n var minZoom = 14;\n var minMarkerZoom = 16;\n var minViewfieldZoom = 18;\n var layer = d3_select(null);\n var _viewerYaw = 0;\n var _selectedSequence = null;\n var _streetside;\n\n /**\n * init().\n */\n function init() {\n if (svgStreetside.initialized) return; // run once\n svgStreetside.enabled = false;\n svgStreetside.initialized = true;\n }\n\n /**\n * getService().\n */\n function getService() {\n if (services.streetside && !_streetside) {\n _streetside = services.streetside;\n _streetside.event\n .on('viewerChanged.svgStreetside', viewerChanged)\n .on('loadedBubbles.svgStreetside', throttledRedraw);\n } else if (!services.streetside && _streetside) {\n _streetside = null;\n }\n\n return _streetside;\n }\n\n /**\n * showLayer().\n */\n function showLayer() {\n var service = getService();\n if (!service) return;\n\n editOn();\n\n layer\n .style('opacity', 0)\n .transition()\n .duration(250)\n .style('opacity', 1)\n .on('end', function () { dispatch.call('change'); });\n }\n\n /**\n * hideLayer().\n */\n function hideLayer() {\n throttledRedraw.cancel();\n\n layer\n .transition()\n .duration(250)\n .style('opacity', 0)\n .on('end', editOff);\n }\n\n /**\n * editOn().\n */\n function editOn() {\n layer.style('display', 'block');\n }\n\n /**\n * editOff().\n */\n function editOff() {\n layer.selectAll('.viewfield-group').remove();\n layer.style('display', 'none');\n }\n\n /**\n * click() Handles 'bubble' point click event.\n */\n function click(d) {\n var service = getService();\n if (!service) return;\n\n // try to preserve the viewer rotation when staying on the same sequence\n if (d.sequenceKey !== _selectedSequence) {\n _viewerYaw = 0; // reset\n }\n _selectedSequence = d.sequenceKey;\n\n service\n .selectImage(context, d)\n .then(response => {\n if (response.status === 'ok'){\n service.showViewer(context, _viewerYaw);\n }\n });\n\n\n context.map().centerEase(d.loc);\n }\n\n /**\n * mouseover().\n */\n function mouseover(d) {\n var service = getService();\n if (service) service.setStyles(context, d);\n }\n\n /**\n * mouseout().\n */\n function mouseout() {\n var service = getService();\n if (service) service.setStyles(context, null);\n }\n\n /**\n * transform().\n */\n function transform(d) {\n var t = svgPointTransform(projection)(d);\n var rot = d.ca + _viewerYaw;\n if (rot) {\n t += ' rotate(' + Math.floor(rot) + ',0,0)';\n }\n return t;\n }\n\n\n function viewerChanged() {\n var service = getService();\n if (!service) return;\n\n var viewer = service.viewer();\n if (!viewer) return;\n\n // update viewfield rotation\n _viewerYaw = viewer.getYaw();\n\n // avoid updating if the map is currently transformed\n // e.g. during drags or easing.\n if (context.map().isTransformed()) return;\n\n layer.selectAll('.viewfield-group.currentView')\n .attr('transform', transform);\n }\n\n\n context.photos().on('change.streetside', update);\n\n /**\n * update().\n */\n function update() {\n var viewer = context.container().select('.photoviewer');\n var selected = viewer.empty() ? undefined : viewer.datum();\n var z = ~~context.map().zoom();\n var showMarkers = (z >= minMarkerZoom);\n var showViewfields = (z >= minViewfieldZoom);\n var service = getService();\n\n var sequences = [];\n var bubbles = [];\n\n if (context.photos().showsPanoramic()) {\n sequences = (service ? service.sequences(projection) : []);\n bubbles = (service && showMarkers ? service.bubbles(projection) : []);\n }\n\n var traces = layer.selectAll('.sequences').selectAll('.sequence')\n .data(sequences, function(d) { return d.properties.key; });\n\n // exit\n traces.exit()\n .remove();\n\n // enter/update\n traces = traces.enter()\n .append('path')\n .attr('class', 'sequence')\n .merge(traces)\n .attr('d', svgPath(projection).geojson);\n\n\n var groups = layer.selectAll('.markers').selectAll('.viewfield-group')\n .data(bubbles, function(d) {\n // force reenter once bubbles are attached to a sequence\n return d.key + (d.sequenceKey ? 'v1' : 'v0');\n });\n\n // exit\n groups.exit()\n .remove();\n\n // enter\n var groupsEnter = groups.enter()\n .append('g')\n .attr('class', 'viewfield-group')\n .on('mouseenter', mouseover)\n .on('mouseleave', mouseout)\n .on('click', click);\n\n groupsEnter\n .append('g')\n .attr('class', 'viewfield-scale');\n\n // update\n var markers = groups\n .merge(groupsEnter)\n .sort(function(a, b) {\n return (a === selected) ? 1\n : (b === selected) ? -1\n : b.loc[1] - a.loc[1];\n })\n .attr('transform', transform)\n .select('.viewfield-scale');\n\n\n markers.selectAll('circle')\n .data([0])\n .enter()\n .append('circle')\n .attr('dx', '0')\n .attr('dy', '0')\n .attr('r', '6');\n\n var viewfields = markers.selectAll('.viewfield')\n .data(showViewfields ? [0] : []);\n\n viewfields.exit()\n .remove();\n\n // viewfields may or may not be drawn...\n // but if they are, draw below the circles\n viewfields.enter()\n .insert('path', 'circle')\n .attr('class', 'viewfield')\n .attr('transform', 'scale(1.5,1.5),translate(-8, -13)')\n .attr('d', viewfieldPath);\n\n function viewfieldPath() {\n var d = this.parentNode.__data__;\n if (d.pano) {\n return 'M 8,13 m -10,0 a 10,10 0 1,0 20,0 a 10,10 0 1,0 -20,0';\n } else {\n return 'M 6,9 C 8,8.4 8,8.4 10,9 L 16,-2 C 12,-5 4,-5 0,-2 z';\n }\n }\n\n }\n\n /**\n * drawImages()\n * drawImages is the method that is returned (and that runs) everytime 'svgStreetside()' is called.\n * 'svgStreetside()' is called from index.js\n */\n function drawImages(selection) {\n var enabled = svgStreetside.enabled;\n var service = getService();\n\n layer = selection.selectAll('.layer-streetside-images')\n .data(service ? [0] : []);\n\n layer.exit()\n .remove();\n\n var layerEnter = layer.enter()\n .append('g')\n .attr('class', 'layer-streetside-images')\n .style('display', enabled ? 'block' : 'none');\n\n layerEnter\n .append('g')\n .attr('class', 'sequences');\n\n layerEnter\n .append('g')\n .attr('class', 'markers');\n\n layer = layerEnter\n .merge(layer);\n\n if (enabled) {\n if (service && ~~context.map().zoom() >= minZoom) {\n editOn();\n update();\n service.loadBubbles(projection);\n } else {\n editOff();\n }\n }\n }\n\n\n /**\n * drawImages.enabled().\n */\n drawImages.enabled = function(_) {\n if (!arguments.length) return svgStreetside.enabled;\n svgStreetside.enabled = _;\n if (svgStreetside.enabled) {\n showLayer();\n } else {\n hideLayer();\n }\n dispatch.call('change');\n return this;\n };\n\n /**\n * drawImages.supported().\n */\n drawImages.supported = function() {\n return !!getService();\n };\n\n init();\n\n return drawImages;\n}\n","import _throttle from 'lodash-es/throttle';\n\nimport { select as d3_select } from 'd3-selection';\nimport { svgPath, svgPointTransform } from './helpers';\nimport { services } from '../services';\n\n\nexport function svgMapillaryImages(projection, context, dispatch) {\n var throttledRedraw = _throttle(function () { dispatch.call('change'); }, 1000);\n var minZoom = 12;\n var minMarkerZoom = 16;\n var minViewfieldZoom = 18;\n var layer = d3_select(null);\n var _mapillary;\n var viewerCompassAngle;\n\n\n function init() {\n if (svgMapillaryImages.initialized) return; // run once\n svgMapillaryImages.enabled = false;\n svgMapillaryImages.initialized = true;\n }\n\n\n function getService() {\n if (services.mapillary && !_mapillary) {\n _mapillary = services.mapillary;\n _mapillary.event.on('loadedImages', throttledRedraw);\n _mapillary.event.on('bearingChanged', function(e) {\n viewerCompassAngle = e;\n\n // avoid updating if the map is currently transformed\n // e.g. during drags or easing.\n if (context.map().isTransformed()) return;\n\n layer.selectAll('.viewfield-group.currentView')\n .filter(function(d) {\n return d.pano;\n })\n .attr('transform', transform);\n });\n } else if (!services.mapillary && _mapillary) {\n _mapillary = null;\n }\n\n return _mapillary;\n }\n\n\n function showLayer() {\n var service = getService();\n if (!service) return;\n\n editOn();\n\n layer\n .style('opacity', 0)\n .transition()\n .duration(250)\n .style('opacity', 1)\n .on('end', function () { dispatch.call('change'); });\n }\n\n\n function hideLayer() {\n throttledRedraw.cancel();\n\n layer\n .transition()\n .duration(250)\n .style('opacity', 0)\n .on('end', editOff);\n }\n\n\n function editOn() {\n layer.style('display', 'block');\n }\n\n\n function editOff() {\n layer.selectAll('.viewfield-group').remove();\n layer.style('display', 'none');\n }\n\n\n function click(d) {\n var service = getService();\n if (!service) return;\n\n service\n .selectImage(context, d.key)\n .updateViewer(context, d.key)\n .showViewer(context);\n\n context.map().centerEase(d.loc);\n }\n\n\n function mouseover(d) {\n var service = getService();\n if (service) service.setStyles(context, d);\n }\n\n\n function mouseout() {\n var service = getService();\n if (service) service.setStyles(context, null);\n }\n\n\n function transform(d) {\n var t = svgPointTransform(projection)(d);\n if (d.pano && viewerCompassAngle !== null && isFinite(viewerCompassAngle)) {\n t += ' rotate(' + Math.floor(viewerCompassAngle) + ',0,0)';\n } else if (d.ca) {\n t += ' rotate(' + Math.floor(d.ca) + ',0,0)';\n }\n return t;\n }\n\n context.photos().on('change.mapillary_images', update);\n\n function filterImages(images) {\n var showsPano = context.photos().showsPanoramic();\n var showsFlat = context.photos().showsFlat();\n if (!showsPano || !showsFlat) {\n images = images.filter(function(image) {\n if (image.pano) return showsPano;\n return showsFlat;\n });\n }\n return images;\n }\n\n function filterSequences(sequences, service) {\n var showsPano = context.photos().showsPanoramic();\n var showsFlat = context.photos().showsFlat();\n if (!showsPano || !showsFlat) {\n sequences = sequences.filter(function(sequence) {\n if (sequence.properties.hasOwnProperty('pano')) {\n if (sequence.properties.pano) return showsPano;\n return showsFlat;\n } else {\n // if the sequence doesn't specify pano or not, search its images\n var cProps = sequence.properties.coordinateProperties;\n if (cProps && cProps.image_keys && cProps.image_keys.length > 0) {\n for (var index in cProps.image_keys) {\n var imageKey = cProps.image_keys[index];\n var image = service.cachedImage(imageKey);\n if (image && image.hasOwnProperty('pano')) {\n if (image.pano) return showsPano;\n return showsFlat;\n }\n }\n }\n }\n });\n }\n return sequences;\n }\n\n function update() {\n\n var z = ~~context.map().zoom();\n var showMarkers = (z >= minMarkerZoom);\n var showViewfields = (z >= minViewfieldZoom);\n\n var service = getService();\n var selectedKey = service && service.getSelectedImageKey();\n var sequences = (service ? service.sequences(projection) : []);\n var images = (service && showMarkers ? service.images(projection) : []);\n\n images = filterImages(images);\n sequences = filterSequences(sequences, service);\n\n var traces = layer.selectAll('.sequences').selectAll('.sequence')\n .data(sequences, function(d) { return d.properties.key; });\n\n // exit\n traces.exit()\n .remove();\n\n // enter/update\n traces = traces.enter()\n .append('path')\n .attr('class', 'sequence')\n .merge(traces)\n .attr('d', svgPath(projection).geojson);\n\n\n var groups = layer.selectAll('.markers').selectAll('.viewfield-group')\n .data(images, function(d) { return d.key; });\n\n // exit\n groups.exit()\n .remove();\n\n // enter\n var groupsEnter = groups.enter()\n .append('g')\n .attr('class', 'viewfield-group')\n .on('mouseenter', mouseover)\n .on('mouseleave', mouseout)\n .on('click', click);\n\n groupsEnter\n .append('g')\n .attr('class', 'viewfield-scale');\n\n // update\n var markers = groups\n .merge(groupsEnter)\n .sort(function(a, b) {\n return (a.key === selectedKey) ? 1\n : (b.key === selectedKey) ? -1\n : b.loc[1] - a.loc[1]; // sort Y\n })\n .attr('transform', transform)\n .select('.viewfield-scale');\n\n\n markers.selectAll('circle')\n .data([0])\n .enter()\n .append('circle')\n .attr('dx', '0')\n .attr('dy', '0')\n .attr('r', '6');\n\n var viewfields = markers.selectAll('.viewfield')\n .data(showViewfields ? [0] : []);\n\n viewfields.exit()\n .remove();\n\n viewfields.enter() // viewfields may or may not be drawn...\n .insert('path', 'circle') // but if they are, draw below the circles\n .attr('class', 'viewfield')\n .classed('pano', function() { return this.parentNode.__data__.pano; })\n .attr('transform', 'scale(1.5,1.5),translate(-8, -13)')\n .attr('d', viewfieldPath);\n\n function viewfieldPath() {\n var d = this.parentNode.__data__;\n if (d.pano) {\n return 'M 8,13 m -10,0 a 10,10 0 1,0 20,0 a 10,10 0 1,0 -20,0';\n } else {\n return 'M 6,9 C 8,8.4 8,8.4 10,9 L 16,-2 C 12,-5 4,-5 0,-2 z';\n }\n }\n }\n\n\n function drawImages(selection) {\n var enabled = svgMapillaryImages.enabled;\n var service = getService();\n\n layer = selection.selectAll('.layer-mapillary')\n .data(service ? [0] : []);\n\n layer.exit()\n .remove();\n\n var layerEnter = layer.enter()\n .append('g')\n .attr('class', 'layer-mapillary')\n .style('display', enabled ? 'block' : 'none');\n\n layerEnter\n .append('g')\n .attr('class', 'sequences');\n\n layerEnter\n .append('g')\n .attr('class', 'markers');\n\n layer = layerEnter\n .merge(layer);\n\n if (enabled) {\n if (service && ~~context.map().zoom() >= minZoom) {\n editOn();\n update();\n service.loadImages(projection);\n } else {\n editOff();\n }\n }\n }\n\n\n drawImages.enabled = function(_) {\n if (!arguments.length) return svgMapillaryImages.enabled;\n svgMapillaryImages.enabled = _;\n if (svgMapillaryImages.enabled) {\n showLayer();\n } else {\n hideLayer();\n }\n dispatch.call('change');\n return this;\n };\n\n\n drawImages.supported = function() {\n return !!getService();\n };\n\n\n init();\n return drawImages;\n}\n","import _throttle from 'lodash-es/throttle';\nimport { select as d3_select } from 'd3-selection';\nimport { svgPointTransform } from './helpers';\nimport { services } from '../services';\n\n\nexport function svgMapillarySigns(projection, context, dispatch) {\n var throttledRedraw = _throttle(function () { dispatch.call('change'); }, 1000);\n var minZoom = 12;\n var layer = d3_select(null);\n var _mapillary;\n\n\n function init() {\n if (svgMapillarySigns.initialized) return; // run once\n svgMapillarySigns.enabled = false;\n svgMapillarySigns.initialized = true;\n }\n\n\n function getService() {\n if (services.mapillary && !_mapillary) {\n _mapillary = services.mapillary;\n _mapillary.event.on('loadedSigns', throttledRedraw);\n } else if (!services.mapillary && _mapillary) {\n _mapillary = null;\n }\n return _mapillary;\n }\n\n\n function showLayer() {\n var service = getService();\n if (!service) return;\n\n editOn();\n }\n\n\n function hideLayer() {\n throttledRedraw.cancel();\n editOff();\n }\n\n\n function editOn() {\n layer.style('display', 'block');\n }\n\n\n function editOff() {\n layer.selectAll('.icon-sign').remove();\n layer.style('display', 'none');\n }\n\n\n function click(d) {\n var service = getService();\n if (!service) return;\n\n context.map().centerEase(d.loc);\n\n var selectedImageKey = service.getSelectedImageKey();\n var imageKey;\n\n // Pick one of the images the sign was detected in,\n // preference given to an image already selected.\n d.detections.forEach(function(detection) {\n if (!imageKey || selectedImageKey === detection.image_key) {\n imageKey = detection.image_key;\n }\n });\n\n service\n .selectImage(context, imageKey)\n .updateViewer(context, imageKey)\n .showViewer(context);\n }\n\n\n function update() {\n var service = getService();\n var data = (service ? service.signs(projection) : []);\n var selectedImageKey = service.getSelectedImageKey();\n var transform = svgPointTransform(projection);\n\n var signs = layer.selectAll('.icon-sign')\n .data(data, function(d) { return d.key; });\n\n // exit\n signs.exit()\n .remove();\n\n // enter\n var enter = signs.enter()\n .append('g')\n .attr('class', 'icon-sign icon-detected')\n .on('click', click);\n\n enter\n .append('use')\n .attr('width', '24px')\n .attr('height', '24px')\n .attr('x', '-12px')\n .attr('y', '-12px')\n .attr('xlink:href', function(d) { return '#' + d.value; });\n\n enter\n .append('rect')\n .attr('width', '24px')\n .attr('height', '24px')\n .attr('x', '-12px')\n .attr('y', '-12px');\n\n // update\n signs\n .merge(enter)\n .attr('transform', transform)\n .classed('currentView', function(d) {\n return d.detections.some(function(detection) {\n return detection.image_key === selectedImageKey;\n });\n })\n .sort(function(a, b) {\n var aSelected = a.detections.some(function(detection) {\n return detection.image_key === selectedImageKey;\n });\n var bSelected = b.detections.some(function(detection) {\n return detection.image_key === selectedImageKey;\n });\n if (aSelected === bSelected) {\n return b.loc[1] - a.loc[1]; // sort Y\n } else if (aSelected) {\n return 1;\n }\n return -1;\n });\n }\n\n\n function drawSigns(selection) {\n var enabled = svgMapillarySigns.enabled;\n var service = getService();\n\n layer = selection.selectAll('.layer-mapillary-signs')\n .data(service ? [0] : []);\n\n layer.exit()\n .remove();\n\n layer = layer.enter()\n .append('g')\n .attr('class', 'layer-mapillary-signs layer-mapillary-detections')\n .style('display', enabled ? 'block' : 'none')\n .merge(layer);\n\n if (enabled) {\n if (service && ~~context.map().zoom() >= minZoom) {\n editOn();\n update();\n service.loadSigns(projection);\n } else {\n editOff();\n }\n }\n }\n\n\n drawSigns.enabled = function(_) {\n if (!arguments.length) return svgMapillarySigns.enabled;\n svgMapillarySigns.enabled = _;\n if (svgMapillarySigns.enabled) {\n showLayer();\n } else {\n hideLayer();\n }\n dispatch.call('change');\n return this;\n };\n\n\n drawSigns.supported = function() {\n return !!getService();\n };\n\n\n init();\n return drawSigns;\n}\n","import _throttle from 'lodash-es/throttle';\nimport { select as d3_select } from 'd3-selection';\nimport { svgPointTransform } from './helpers';\nimport { services } from '../services';\nimport { t } from '../core/localizer';\n\nexport function svgMapillaryMapFeatures(projection, context, dispatch) {\n var throttledRedraw = _throttle(function () { dispatch.call('change'); }, 1000);\n var minZoom = 12;\n var layer = d3_select(null);\n var _mapillary;\n\n\n function init() {\n if (svgMapillaryMapFeatures.initialized) return; // run once\n svgMapillaryMapFeatures.enabled = false;\n svgMapillaryMapFeatures.initialized = true;\n }\n\n\n function getService() {\n if (services.mapillary && !_mapillary) {\n _mapillary = services.mapillary;\n _mapillary.event.on('loadedMapFeatures', throttledRedraw);\n } else if (!services.mapillary && _mapillary) {\n _mapillary = null;\n }\n return _mapillary;\n }\n\n\n function showLayer() {\n var service = getService();\n if (!service) return;\n\n editOn();\n }\n\n\n function hideLayer() {\n throttledRedraw.cancel();\n editOff();\n }\n\n\n function editOn() {\n layer.style('display', 'block');\n }\n\n\n function editOff() {\n layer.selectAll('.icon-map-feature').remove();\n layer.style('display', 'none');\n }\n\n\n function click(d) {\n var service = getService();\n if (!service) return;\n\n context.map().centerEase(d.loc);\n\n var selectedImageKey = service.getSelectedImageKey();\n var imageKey;\n\n // Pick one of the images the map feature was detected in,\n // preference given to an image already selected.\n d.detections.forEach(function(detection) {\n if (!imageKey || selectedImageKey === detection.image_key) {\n imageKey = detection.image_key;\n }\n });\n\n service\n .selectImage(context, imageKey)\n .updateViewer(context, imageKey)\n .showViewer(context);\n }\n\n\n function update() {\n var service = getService();\n var data = (service ? service.mapFeatures(projection) : []);\n var selectedImageKey = service && service.getSelectedImageKey();\n var transform = svgPointTransform(projection);\n\n var mapFeatures = layer.selectAll('.icon-map-feature')\n .data(data, function(d) { return d.key; });\n\n // exit\n mapFeatures.exit()\n .remove();\n\n // enter\n var enter = mapFeatures.enter()\n .append('g')\n .attr('class', 'icon-map-feature icon-detected')\n .on('click', click);\n\n enter\n .append('title')\n .text(function(d) {\n var id = d.value.replace(/--/g, '.').replace(/-/g, '_');\n return t('mapillary_map_features.' + id);\n });\n\n enter\n .append('use')\n .attr('width', '24px')\n .attr('height', '24px')\n .attr('x', '-12px')\n .attr('y', '-12px')\n .attr('xlink:href', function(d) {\n if (d.value === 'object--billboard') {\n // no billboard icon right now, so use the advertisement icon\n return '#object--sign--advertisement';\n }\n return '#' + d.value;\n });\n\n enter\n .append('rect')\n .attr('width', '24px')\n .attr('height', '24px')\n .attr('x', '-12px')\n .attr('y', '-12px');\n\n // update\n mapFeatures\n .merge(enter)\n .attr('transform', transform)\n .classed('currentView', function(d) {\n return d.detections.some(function(detection) {\n return detection.image_key === selectedImageKey;\n });\n })\n .sort(function(a, b) {\n var aSelected = a.detections.some(function(detection) {\n return detection.image_key === selectedImageKey;\n });\n var bSelected = b.detections.some(function(detection) {\n return detection.image_key === selectedImageKey;\n });\n if (aSelected === bSelected) {\n return b.loc[1] - a.loc[1]; // sort Y\n } else if (aSelected) {\n return 1;\n }\n return -1;\n });\n }\n\n\n function drawMapFeatures(selection) {\n var enabled = svgMapillaryMapFeatures.enabled;\n var service = getService();\n\n layer = selection.selectAll('.layer-mapillary-map-features')\n .data(service ? [0] : []);\n\n layer.exit()\n .remove();\n\n layer = layer.enter()\n .append('g')\n .attr('class', 'layer-mapillary-map-features layer-mapillary-detections')\n .style('display', enabled ? 'block' : 'none')\n .merge(layer);\n\n if (enabled) {\n if (service && ~~context.map().zoom() >= minZoom) {\n editOn();\n update();\n service.loadMapFeatures(projection);\n } else {\n editOff();\n }\n }\n }\n\n\n drawMapFeatures.enabled = function(_) {\n if (!arguments.length) return svgMapillaryMapFeatures.enabled;\n svgMapillaryMapFeatures.enabled = _;\n if (svgMapillaryMapFeatures.enabled) {\n showLayer();\n } else {\n hideLayer();\n }\n dispatch.call('change');\n return this;\n };\n\n\n drawMapFeatures.supported = function() {\n return !!getService();\n };\n\n\n init();\n return drawMapFeatures;\n}\n","import _throttle from 'lodash-es/throttle';\nimport { select as d3_select } from 'd3-selection';\nimport { svgPath, svgPointTransform } from './helpers';\nimport { services } from '../services';\n\n\nexport function svgOpenstreetcamImages(projection, context, dispatch) {\n var throttledRedraw = _throttle(function () { dispatch.call('change'); }, 1000);\n var minZoom = 12;\n var minMarkerZoom = 16;\n var minViewfieldZoom = 18;\n var layer = d3_select(null);\n var _openstreetcam;\n\n\n function init() {\n if (svgOpenstreetcamImages.initialized) return; // run once\n svgOpenstreetcamImages.enabled = false;\n svgOpenstreetcamImages.initialized = true;\n }\n\n\n function getService() {\n if (services.openstreetcam && !_openstreetcam) {\n _openstreetcam = services.openstreetcam;\n _openstreetcam.event.on('loadedImages', throttledRedraw);\n } else if (!services.openstreetcam && _openstreetcam) {\n _openstreetcam = null;\n }\n\n return _openstreetcam;\n }\n\n\n function showLayer() {\n var service = getService();\n if (!service) return;\n\n editOn();\n\n layer\n .style('opacity', 0)\n .transition()\n .duration(250)\n .style('opacity', 1)\n .on('end', function () { dispatch.call('change'); });\n }\n\n\n function hideLayer() {\n throttledRedraw.cancel();\n\n layer\n .transition()\n .duration(250)\n .style('opacity', 0)\n .on('end', editOff);\n }\n\n\n function editOn() {\n layer.style('display', 'block');\n }\n\n\n function editOff() {\n layer.selectAll('.viewfield-group').remove();\n layer.style('display', 'none');\n }\n\n\n function click(d) {\n var service = getService();\n if (!service) return;\n\n service\n .selectImage(context, d)\n .updateViewer(context, d)\n .showViewer(context);\n\n context.map().centerEase(d.loc);\n }\n\n\n function mouseover(d) {\n var service = getService();\n if (service) service.setStyles(context, d);\n }\n\n\n function mouseout() {\n var service = getService();\n if (service) service.setStyles(context, null);\n }\n\n\n function transform(d) {\n var t = svgPointTransform(projection)(d);\n if (d.ca) {\n t += ' rotate(' + Math.floor(d.ca) + ',0,0)';\n }\n return t;\n }\n\n\n context.photos().on('change.openstreetcam_images', update);\n\n function update() {\n var viewer = context.container().select('.photoviewer');\n var selected = viewer.empty() ? undefined : viewer.datum();\n\n var z = ~~context.map().zoom();\n var showMarkers = (z >= minMarkerZoom);\n var showViewfields = (z >= minViewfieldZoom);\n\n var service = getService();\n var sequences = [];\n var images = [];\n\n if (context.photos().showsFlat()) {\n sequences = (service ? service.sequences(projection) : []);\n images = (service && showMarkers ? service.images(projection) : []);\n }\n\n var traces = layer.selectAll('.sequences').selectAll('.sequence')\n .data(sequences, function(d) { return d.properties.key; });\n\n // exit\n traces.exit()\n .remove();\n\n // enter/update\n traces = traces.enter()\n .append('path')\n .attr('class', 'sequence')\n .merge(traces)\n .attr('d', svgPath(projection).geojson);\n\n\n var groups = layer.selectAll('.markers').selectAll('.viewfield-group')\n .data(images, function(d) { return d.key; });\n\n // exit\n groups.exit()\n .remove();\n\n // enter\n var groupsEnter = groups.enter()\n .append('g')\n .attr('class', 'viewfield-group')\n .on('mouseenter', mouseover)\n .on('mouseleave', mouseout)\n .on('click', click);\n\n groupsEnter\n .append('g')\n .attr('class', 'viewfield-scale');\n\n // update\n var markers = groups\n .merge(groupsEnter)\n .sort(function(a, b) {\n return (a === selected) ? 1\n : (b === selected) ? -1\n : b.loc[1] - a.loc[1]; // sort Y\n })\n .attr('transform', transform)\n .select('.viewfield-scale');\n\n\n markers.selectAll('circle')\n .data([0])\n .enter()\n .append('circle')\n .attr('dx', '0')\n .attr('dy', '0')\n .attr('r', '6');\n\n var viewfields = markers.selectAll('.viewfield')\n .data(showViewfields ? [0] : []);\n\n viewfields.exit()\n .remove();\n\n viewfields.enter() // viewfields may or may not be drawn...\n .insert('path', 'circle') // but if they are, draw below the circles\n .attr('class', 'viewfield')\n .attr('transform', 'scale(1.5,1.5),translate(-8, -13)')\n .attr('d', 'M 6,9 C 8,8.4 8,8.4 10,9 L 16,-2 C 12,-5 4,-5 0,-2 z');\n }\n\n\n function drawImages(selection) {\n var enabled = svgOpenstreetcamImages.enabled,\n service = getService();\n\n layer = selection.selectAll('.layer-openstreetcam')\n .data(service ? [0] : []);\n\n layer.exit()\n .remove();\n\n var layerEnter = layer.enter()\n .append('g')\n .attr('class', 'layer-openstreetcam')\n .style('display', enabled ? 'block' : 'none');\n\n layerEnter\n .append('g')\n .attr('class', 'sequences');\n\n layerEnter\n .append('g')\n .attr('class', 'markers');\n\n layer = layerEnter\n .merge(layer);\n\n if (enabled) {\n if (service && ~~context.map().zoom() >= minZoom) {\n editOn();\n update();\n service.loadImages(projection);\n } else {\n editOff();\n }\n }\n }\n\n\n drawImages.enabled = function(_) {\n if (!arguments.length) return svgOpenstreetcamImages.enabled;\n svgOpenstreetcamImages.enabled = _;\n if (svgOpenstreetcamImages.enabled) {\n showLayer();\n } else {\n hideLayer();\n }\n dispatch.call('change');\n return this;\n };\n\n\n drawImages.supported = function() {\n return !!getService();\n };\n\n\n init();\n return drawImages;\n}\n","export function svgOsm(projection, context, dispatch) {\n var enabled = true;\n\n\n function drawOsm(selection) {\n selection.selectAll('.layer-osm')\n .data(['covered', 'areas', 'lines', 'points', 'labels'])\n .enter()\n .append('g')\n .attr('class', function(d) { return 'layer-osm ' + d; });\n\n selection.selectAll('.layer-osm.points').selectAll('.points-group')\n .data(['points', 'midpoints', 'vertices', 'turns'])\n .enter()\n .append('g')\n .attr('class', function(d) { return 'points-group ' + d; });\n }\n\n\n function showLayer() {\n var layer = context.surface().selectAll('.data-layer.osm');\n layer.interrupt();\n\n layer\n .classed('disabled', false)\n .style('opacity', 0)\n .transition()\n .duration(250)\n .style('opacity', 1)\n .on('end interrupt', function () {\n dispatch.call('change');\n });\n }\n\n\n function hideLayer() {\n var layer = context.surface().selectAll('.data-layer.osm');\n layer.interrupt();\n\n layer\n .transition()\n .duration(250)\n .style('opacity', 0)\n .on('end interrupt', function () {\n layer.classed('disabled', true);\n dispatch.call('change');\n });\n }\n\n\n drawOsm.enabled = function(val) {\n if (!arguments.length) return enabled;\n enabled = val;\n\n if (enabled) {\n showLayer();\n } else {\n hideLayer();\n }\n\n dispatch.call('change');\n return this;\n };\n\n\n return drawOsm;\n}\n","import _throttle from 'lodash-es/throttle';\n\nimport { select as d3_select } from 'd3-selection';\nimport { dispatch as d3_dispatch } from 'd3-dispatch';\n\nimport { modeBrowse } from '../modes/browse';\nimport { svgPointTransform } from './helpers';\nimport { services } from '../services';\n\n\nvar _notesEnabled = false;\nvar _osmService;\n\n\nexport function svgNotes(projection, context, dispatch) {\n if (!dispatch) { dispatch = d3_dispatch('change'); }\n var throttledRedraw = _throttle(function () { dispatch.call('change'); }, 1000);\n var minZoom = 12;\n var touchLayer = d3_select(null);\n var drawLayer = d3_select(null);\n var _notesVisible = false;\n\n\n function markerPath(selection, klass) {\n selection\n .attr('class', klass)\n .attr('transform', 'translate(-8, -22)')\n .attr('d', 'm17.5,0l-15,0c-1.37,0 -2.5,1.12 -2.5,2.5l0,11.25c0,1.37 1.12,2.5 2.5,2.5l3.75,0l0,3.28c0,0.38 0.43,0.6 0.75,0.37l4.87,-3.65l5.62,0c1.37,0 2.5,-1.12 2.5,-2.5l0,-11.25c0,-1.37 -1.12,-2.5 -2.5,-2.5z');\n }\n\n\n // Loosely-coupled osm service for fetching notes.\n function getService() {\n if (services.osm && !_osmService) {\n _osmService = services.osm;\n _osmService.on('loadedNotes', throttledRedraw);\n } else if (!services.osm && _osmService) {\n _osmService = null;\n }\n\n return _osmService;\n }\n\n\n // Show the notes\n function editOn() {\n if (!_notesVisible) {\n _notesVisible = true;\n drawLayer\n .style('display', 'block');\n }\n }\n\n\n // Immediately remove the notes and their touch targets\n function editOff() {\n if (_notesVisible) {\n _notesVisible = false;\n drawLayer\n .style('display', 'none');\n drawLayer.selectAll('.note')\n .remove();\n touchLayer.selectAll('.note')\n .remove();\n }\n }\n\n\n // Enable the layer. This shows the notes and transitions them to visible.\n function layerOn() {\n editOn();\n\n drawLayer\n .style('opacity', 0)\n .transition()\n .duration(250)\n .style('opacity', 1)\n .on('end interrupt', function () {\n dispatch.call('change');\n });\n }\n\n\n // Disable the layer. This transitions the layer invisible and then hides the notes.\n function layerOff() {\n throttledRedraw.cancel();\n drawLayer.interrupt();\n touchLayer.selectAll('.note')\n .remove();\n\n drawLayer\n .transition()\n .duration(250)\n .style('opacity', 0)\n .on('end interrupt', function () {\n editOff();\n dispatch.call('change');\n });\n }\n\n\n // Update the note markers\n function updateMarkers() {\n if (!_notesVisible || !_notesEnabled) return;\n\n var service = getService();\n var selectedID = context.selectedNoteID();\n var data = (service ? service.notes(projection) : []);\n var getTransform = svgPointTransform(projection);\n\n // Draw markers..\n var notes = drawLayer.selectAll('.note')\n .data(data, function(d) { return d.status + d.id; });\n\n // exit\n notes.exit()\n .remove();\n\n // enter\n var notesEnter = notes.enter()\n .append('g')\n .attr('class', function(d) { return 'note note-' + d.id + ' ' + d.status; })\n .classed('new', function(d) { return d.id < 0; });\n\n notesEnter\n .append('ellipse')\n .attr('cx', 0.5)\n .attr('cy', 1)\n .attr('rx', 6.5)\n .attr('ry', 3)\n .attr('class', 'stroke');\n\n notesEnter\n .append('path')\n .call(markerPath, 'shadow');\n\n notesEnter\n .append('use')\n .attr('class', 'note-fill')\n .attr('width', '20px')\n .attr('height', '20px')\n .attr('x', '-8px')\n .attr('y', '-22px')\n .attr('xlink:href', '#iD-icon-note');\n\n notesEnter.selectAll('.icon-annotation')\n .data(function(d) { return [d]; })\n .enter()\n .append('use')\n .attr('class', 'icon-annotation')\n .attr('width', '10px')\n .attr('height', '10px')\n .attr('x', '-3px')\n .attr('y', '-19px')\n .attr('xlink:href', function(d) {\n return '#iD-icon-' + (d.id < 0 ? 'plus' : (d.status === 'open' ? 'close' : 'apply'));\n });\n\n // update\n notes\n .merge(notesEnter)\n .sort(sortY)\n .classed('selected', function(d) {\n var mode = context.mode();\n var isMoving = mode && mode.id === 'drag-note'; // no shadows when dragging\n return !isMoving && d.id === selectedID;\n })\n .attr('transform', getTransform);\n\n\n // Draw targets..\n if (touchLayer.empty()) return;\n var fillClass = context.getDebug('target') ? 'pink ' : 'nocolor ';\n\n var targets = touchLayer.selectAll('.note')\n .data(data, function(d) { return d.id; });\n\n // exit\n targets.exit()\n .remove();\n\n // enter/update\n targets.enter()\n .append('rect')\n .attr('width', '20px')\n .attr('height', '20px')\n .attr('x', '-8px')\n .attr('y', '-22px')\n .merge(targets)\n .sort(sortY)\n .attr('class', function(d) {\n var newClass = (d.id < 0 ? 'new' : '');\n return 'note target note-' + d.id + ' ' + fillClass + newClass;\n })\n .attr('transform', getTransform);\n\n\n function sortY(a, b) {\n return (a.id === selectedID) ? 1 : (b.id === selectedID) ? -1 : b.loc[1] - a.loc[1];\n }\n }\n\n\n // Draw the notes layer and schedule loading notes and updating markers.\n function drawNotes(selection) {\n var service = getService();\n\n var surface = context.surface();\n if (surface && !surface.empty()) {\n touchLayer = surface.selectAll('.data-layer.touch .layer-touch.markers');\n }\n\n drawLayer = selection.selectAll('.layer-notes')\n .data(service ? [0] : []);\n\n drawLayer.exit()\n .remove();\n\n drawLayer = drawLayer.enter()\n .append('g')\n .attr('class', 'layer-notes')\n .style('display', _notesEnabled ? 'block' : 'none')\n .merge(drawLayer);\n\n if (_notesEnabled) {\n if (service && ~~context.map().zoom() >= minZoom) {\n editOn();\n service.loadNotes(projection);\n updateMarkers();\n } else {\n editOff();\n }\n }\n }\n\n\n // Toggles the layer on and off\n drawNotes.enabled = function(val) {\n if (!arguments.length) return _notesEnabled;\n\n _notesEnabled = val;\n if (_notesEnabled) {\n layerOn();\n } else {\n layerOff();\n if (context.selectedNoteID()) {\n context.enter(modeBrowse(context));\n }\n }\n\n dispatch.call('change');\n return this;\n };\n\n\n return drawNotes;\n}\n","export function svgTouch() {\n\n function drawTouch(selection) {\n selection.selectAll('.layer-touch')\n .data(['areas', 'lines', 'points', 'turns', 'markers'])\n .enter()\n .append('g')\n .attr('class', function(d) { return 'layer-touch ' + d; });\n }\n\n return drawTouch;\n}\n","import _throttle from 'lodash-es/throttle';\n\nimport { select as d3_select} from 'd3-selection';\nimport { geoScaleToZoom } from '../geo';\nimport { services } from '../services';\nimport { svgPath, svgPointTransform } from './index';\nimport { utilStringQs } from '../util';\n\nlet _enabled = false;\nlet _initialized = false;\nlet _FbMlService;\nlet _EsriService;\nlet _actioned;\n\n\nexport function svgRapidFeatures(projection, context, dispatch) {\n const RAPID_MAGENTA = '#da26d3';\n const throttledRedraw = _throttle(() => dispatch.call('change'), 1000);\n const gpxInUrl = utilStringQs(window.location.hash).gpx;\n let _layer = d3_select(null);\n\n\n function init() {\n if (_initialized) return; // run once\n\n _enabled = true;\n _initialized = true;\n _actioned = new Set();\n\n // Watch history to synchronize the displayed layer with features\n // that have been accepted or rejected by the user.\n context.history().on('undone.aifeatures', onHistoryUndone);\n context.history().on('change.aifeatures', onHistoryChange);\n context.history().on('restore.aifeatures', onHistoryRestore);\n }\n\n\n // Services are loosly coupled in iD, so we use these functions\n // to gain access to them, and bind the event handlers a single time.\n function getFbMlService() {\n if (services.fbMLRoads && !_FbMlService) {\n _FbMlService = services.fbMLRoads;\n _FbMlService.event.on('loadedData', throttledRedraw);\n }\n return _FbMlService;\n }\n\n function getEsriService() {\n if (services.esriData && !_EsriService) {\n _EsriService = services.esriData;\n _EsriService.event.on('loadedData', throttledRedraw);\n }\n return _EsriService;\n }\n\n\n function wasRapidEdit(annotation) {\n return annotation && annotation.type && /^rapid/.test(annotation.type);\n }\n\n\n function onHistoryUndone(currentStack, previousStack) {\n const annotation = previousStack.annotation;\n if (!wasRapidEdit(annotation)) return;\n\n _actioned.delete(annotation.id);\n if (_enabled) { dispatch.call('change'); } // redraw\n }\n\n\n function onHistoryChange(/* difference */) {\n const annotation = context.history().peekAnnotation();\n if (!wasRapidEdit(annotation)) return;\n\n _actioned.add(annotation.id);\n if (_enabled) { dispatch.call('change'); } // redraw\n }\n\n\n function onHistoryRestore() {\n _actioned = new Set();\n context.history().peekAllAnnotations().forEach(annotation => {\n if (wasRapidEdit(annotation)) {\n _actioned.add(annotation.id);\n // origid (the original entity ID), a.k.a. datum.__origid__,\n // is a hack used to deal with non-deterministic way-splitting\n // in the roads service. Each way \"split\" will have an origid\n // attribute for the original way it was derived from. In this\n // particular case, restoring from history on page reload, we\n // prevent new splits (possibly different from before the page\n // reload) from being displayed by storing the origid and\n // checking against it in render().\n if (annotation.origid) {\n _actioned.add(annotation.origid);\n }\n }\n });\n if (_actioned.size && _enabled) {\n dispatch.call('change'); // redraw\n }\n }\n\n\n function showLayer() {\n throttledRedraw();\n layerOn();\n }\n\n\n function hideLayer() {\n throttledRedraw.cancel();\n layerOff();\n }\n\n\n function layerOn() {\n _layer.style('display', 'block');\n }\n\n\n function layerOff() {\n _layer.style('display', 'none');\n }\n\n\n function isArea(d) {\n return (d.type === 'relation' || (d.type === 'way' && d.isArea()));\n }\n\n\n function featureKey(d) {\n return d.__fbid__;\n }\n\n\n function render(selection) {\n const rapidContext = context.rapidContext();\n\n // Ensure Rapid layer and exists\n _layer = selection.selectAll('.layer-ai-features')\n .data(_enabled ? [0] : []);\n\n _layer.exit()\n .remove();\n\n let layerEnter = _layer.enter()\n .append('g')\n .attr('class', 'layer-ai-features');\n\n layerEnter\n .append('defs')\n .attr('class', 'rapid-defs');\n\n _layer = layerEnter\n .merge(_layer);\n\n const surface = context.surface();\n const waitingForTaskExtent = gpxInUrl && !rapidContext.getTaskExtent();\n if (!surface || surface.empty() || waitingForTaskExtent) return; // not ready to draw yet, starting up\n\n\n // Gather available datasets, generate a unique fill pattern\n // and a layer group for each dataset. Fill pattern styling is complicated.\n // Style needs to apply in the def, not where the pattern is used.\n const rapidDatasets = rapidContext.datasets();\n const datasets = Object.values(rapidDatasets)\n .filter(dataset => dataset.added && dataset.enabled);\n\n let defs = _layer.selectAll('.rapid-defs');\n let dsPatterns = defs.selectAll('.rapid-fill-pattern')\n .data(datasets, d => d.id);\n\n // exit\n dsPatterns.exit()\n .remove();\n\n // enter\n let dsPatternsEnter = dsPatterns.enter()\n .append('pattern')\n .attr('id', d => `fill-${d.id}`)\n .attr('class', 'rapid-fill-pattern')\n .attr('width', 5)\n .attr('height', 15)\n .attr('patternUnits', 'userSpaceOnUse')\n .attr('patternTransform', (d, i) => {\n const r = (45 + (67 * i)) % 180; // generate something different for each layer\n return `rotate(${r})`;\n });\n\n dsPatternsEnter\n .append('line')\n .attr('class', 'ai-building-line')\n .attr('stroke', 'currentColor')\n .attr('stroke-width', '2px')\n .attr('stroke-opacity', 0.6)\n .attr('y2', '15');\n\n // update\n dsPatterns = dsPatternsEnter\n .merge(dsPatterns)\n .style('color', d => d.color || RAPID_MAGENTA);\n\n\n let dsGroups = _layer.selectAll('.layer-rapid-dataset')\n .data(datasets, d => d.id);\n\n // exit\n dsGroups.exit()\n .remove();\n\n // enter/update\n dsGroups = dsGroups.enter()\n .append('g')\n .attr('class', d => `layer-rapid-dataset layer-rapid-dataset-${d.id}`)\n .merge(dsGroups)\n .style('color', d => d.color || RAPID_MAGENTA)\n .each(eachDataset);\n }\n\n\n function eachDataset(dataset, i, nodes) {\n const rapidContext = context.rapidContext();\n const selection = d3_select(nodes[i]);\n const service = dataset.service === 'fbml' ? getFbMlService(): getEsriService();\n if (!service) return;\n\n // Adjust the dataset id for whether we want the data conflated or not.\n const internalID = dataset.id + (dataset.conflated ? '-conflated' : '');\n const graph = service.graph(internalID);\n const getPath = svgPath(projection, graph);\n const getTransform = svgPointTransform(projection);\n\n // Gather data\n let geoData = {\n paths: [],\n vertices: [],\n points: []\n };\n\n if (context.map().zoom() >= context.minEditableZoom()) {\n /* Facebook AI/ML */\n if (dataset.service === 'fbml') {\n\n service.loadTiles(internalID, projection, rapidContext.getTaskExtent());\n let pathData = service\n .intersects(internalID, context.map().extent())\n .filter(d => d.type === 'way' && !_actioned.has(d.id) && !_actioned.has(d.__origid__) ) // see onHistoryRestore()\n .filter(getPath);\n\n // fb_ai service gives us roads and buildings together,\n // so filter further according to which dataset we're drawing\n if (dataset.id === 'fbRoads' || dataset.id === 'rapid_intro_graph') {\n geoData.paths = pathData.filter(d => !!d.tags.highway);\n\n let seen = {};\n geoData.paths.forEach(d => {\n const first = d.first();\n const last = d.last();\n if (!seen[first]) {\n seen[first] = true;\n geoData.vertices.push(graph.entity(first));\n }\n if (!seen[last]) {\n seen[last] = true;\n geoData.vertices.push(graph.entity(last));\n }\n });\n\n } else if (dataset.id === 'msBuildings') {\n geoData.paths = pathData.filter(isArea);\n // no vertices\n\n } else {\n // esri data via fb service\n geoData.paths = pathData.filter(isArea);\n }\n\n /* ESRI ArcGIS */\n } else if (dataset.service === 'esri') {\n service.loadTiles(internalID, projection);\n let visibleData = service\n .intersects(internalID, context.map().extent())\n .filter(d => !_actioned.has(d.id) && !_actioned.has(d.__origid__) ); // see onHistoryRestore()\n\n geoData.points = visibleData\n .filter(d => d.type === 'node' && !!d.__fbid__); // standalone only (not vertices/childnodes)\n\n geoData.paths = visibleData\n .filter(d => d.type === 'way' || d.type === 'relation')\n .filter(getPath);\n }\n }\n\n selection\n .call(drawPaths, geoData.paths, dataset, getPath)\n .call(drawVertices, geoData.vertices, getTransform)\n .call(drawPoints, geoData.points, getTransform);\n }\n\n\n function drawPaths(selection, pathData, dataset, getPath) {\n // Draw shadow, casing, stroke layers\n let linegroups = selection\n .selectAll('g.linegroup')\n .data(['shadow', 'casing', 'stroke']);\n\n linegroups = linegroups.enter()\n .append('g')\n .attr('class', d => `linegroup linegroup-${d}`)\n .merge(linegroups);\n\n // Draw paths\n let paths = linegroups\n .selectAll('path')\n .data(pathData, featureKey);\n\n // exit\n paths.exit()\n .remove();\n\n // enter/update\n paths = paths.enter()\n .append('path')\n .attr('style', d => isArea(d) ? `fill: url(#fill-${dataset.id})` : null)\n .attr('class', (d, i, nodes) => {\n const currNode = nodes[i];\n const linegroup = currNode.parentNode.__data__;\n const klass = isArea(d) ? 'building' : 'road';\n return `line ${linegroup} ${klass} data${d.__fbid__}`;\n })\n .merge(paths)\n .attr('d', getPath);\n }\n\n\n function drawVertices(selection, vertexData, getTransform) {\n const vertRadii = {\n // z16-, z17, z18+\n stroke: [3.5, 4, 4.5],\n fill: [2, 2, 2.5]\n };\n\n let vertexGroup = selection\n .selectAll('g.vertexgroup')\n .data(vertexData.length ? [0] : []);\n\n vertexGroup.exit()\n .remove();\n\n vertexGroup = vertexGroup.enter()\n .append('g')\n .attr('class', 'vertexgroup')\n .merge(vertexGroup);\n\n\n let vertices = vertexGroup\n .selectAll('g.vertex')\n .data(vertexData, d => d.id);\n\n // exit\n vertices.exit()\n .remove();\n\n // enter\n let enter = vertices.enter()\n .append('g')\n .attr('class', d => `node vertex ${d.id}`);\n\n enter\n .append('circle')\n .attr('class', 'stroke');\n\n enter\n .append('circle')\n .attr('class', 'fill');\n\n // update\n const zoom = geoScaleToZoom(projection.scale());\n const radiusIdx = (zoom < 17 ? 0 : zoom < 18 ? 1 : 2);\n vertices = vertices\n .merge(enter)\n .attr('transform', getTransform)\n .call(selection => {\n ['stroke', 'fill'].forEach(klass => {\n selection.selectAll('.' + klass)\n .attr('r', vertRadii[klass][radiusIdx]);\n });\n });\n }\n\n\n function drawPoints(selection, pointData, getTransform) {\n const pointRadii = {\n // z16-, z17, z18+\n shadow: [4.5, 7, 8],\n stroke: [4.5, 7, 8],\n fill: [2.5, 4, 5]\n };\n\n let pointGroup = selection\n .selectAll('g.pointgroup')\n .data(pointData.length ? [0] : []);\n\n pointGroup.exit()\n .remove();\n\n pointGroup = pointGroup.enter()\n .append('g')\n .attr('class', 'pointgroup')\n .merge(pointGroup);\n\n let points = pointGroup\n .selectAll('g.point')\n .data(pointData, featureKey);\n\n // exit\n points.exit()\n .remove();\n\n // enter\n let enter = points.enter()\n .append('g')\n .attr('class', d => `node point data${d.__fbid__}`);\n\n enter\n .append('circle')\n .attr('class', 'shadow');\n\n enter\n .append('circle')\n .attr('class', 'stroke');\n\n enter\n .append('circle')\n .attr('class', 'fill');\n\n // update\n const zoom = geoScaleToZoom(projection.scale());\n const radiusIdx = (zoom < 17 ? 0 : zoom < 18 ? 1 : 2);\n points = points\n .merge(enter)\n .attr('transform', getTransform)\n .call(selection => {\n ['shadow', 'stroke', 'fill'].forEach(klass => {\n selection.selectAll('.' + klass)\n .attr('r', pointRadii[klass][radiusIdx]);\n });\n });\n }\n\n\n render.showAll = function() {\n return _enabled;\n };\n\n\n render.enabled = function(val) {\n if (!arguments.length) return _enabled;\n\n _enabled = val;\n if (_enabled) {\n showLayer();\n } else {\n hideLayer();\n }\n\n dispatch.call('change');\n return render;\n };\n\n\n init();\n return render;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { select as d3_select } from 'd3-selection';\n\nimport { svgData } from './data';\nimport { svgDebug } from './debug';\nimport { svgGeolocate } from './geolocate';\nimport { svgKeepRight } from './keepRight';\nimport { svgImproveOSM } from './improveOSM';\nimport { svgOsmose } from './osmose';\nimport { svgStreetside } from './streetside';\nimport { svgMapillaryImages } from './mapillary_images';\nimport { svgMapillarySigns } from './mapillary_signs';\nimport { svgMapillaryMapFeatures } from './mapillary_map_features';\nimport { svgOpenstreetcamImages } from './openstreetcam_images';\nimport { svgOsm } from './osm';\nimport { svgNotes } from './notes';\nimport { svgTouch } from './touch';\nimport { utilArrayDifference, utilRebind } from '../util';\nimport { utilGetDimensions, utilSetDimensions } from '../util/dimensions';\n\nimport { svgRapidFeatures } from './rapid_features';\n\n\nexport function svgLayers(projection, context) {\n var dispatch = d3_dispatch('change');\n var svg = d3_select(null);\n var _layers = [\n { id: 'ai-features', layer: svgRapidFeatures(projection, context, dispatch) },\n { id: 'osm', layer: svgOsm(projection, context, dispatch) },\n { id: 'notes', layer: svgNotes(projection, context, dispatch) },\n { id: 'data', layer: svgData(projection, context, dispatch) },\n { id: 'keepRight', layer: svgKeepRight(projection, context, dispatch) },\n { id: 'improveOSM', layer: svgImproveOSM(projection, context, dispatch) },\n { id: 'osmose', layer: svgOsmose(projection, context, dispatch) },\n { id: 'streetside', layer: svgStreetside(projection, context, dispatch)},\n { id: 'mapillary', layer: svgMapillaryImages(projection, context, dispatch) },\n { id: 'mapillary-map-features', layer: svgMapillaryMapFeatures(projection, context, dispatch) },\n { id: 'mapillary-signs', layer: svgMapillarySigns(projection, context, dispatch) },\n { id: 'openstreetcam', layer: svgOpenstreetcamImages(projection, context, dispatch) },\n { id: 'debug', layer: svgDebug(projection, context, dispatch) },\n { id: 'geolocate', layer: svgGeolocate(projection, context, dispatch) },\n { id: 'touch', layer: svgTouch(projection, context, dispatch) }\n ];\n\n\n function drawLayers(selection) {\n svg = selection.selectAll('.surface')\n .data([0]);\n\n svg = svg.enter()\n .append('svg')\n .attr('class', 'surface')\n .merge(svg);\n\n var defs = svg.selectAll('.surface-defs')\n .data([0]);\n\n defs.enter()\n .append('defs')\n .attr('class', 'surface-defs');\n\n defs.enter()\n .append('svg')\n .attr('class', 'grids-svg');\n\n var groups = svg.selectAll('.data-layer')\n .data(_layers);\n\n groups.exit()\n .remove();\n\n groups.enter()\n .append('g')\n .attr('class', function(d) { return 'data-layer ' + d.id; })\n .merge(groups)\n .each(function(d) { d3_select(this).call(d.layer); });\n }\n\n\n drawLayers.all = function() {\n return _layers;\n };\n\n\n drawLayers.layer = function(id) {\n var obj = _layers.find(function(o) { return o.id === id; });\n return obj && obj.layer;\n };\n\n\n drawLayers.only = function(what) {\n var arr = [].concat(what);\n var all = _layers.map(function(layer) { return layer.id; });\n return drawLayers.remove(utilArrayDifference(all, arr));\n };\n\n\n drawLayers.remove = function(what) {\n var arr = [].concat(what);\n arr.forEach(function(id) {\n _layers = _layers.filter(function(o) { return o.id !== id; });\n });\n dispatch.call('change');\n return this;\n };\n\n\n drawLayers.add = function(what) {\n var arr = [].concat(what);\n arr.forEach(function(obj) {\n if ('id' in obj && 'layer' in obj) {\n _layers.push(obj);\n }\n });\n dispatch.call('change');\n return this;\n };\n\n\n drawLayers.dimensions = function(val) {\n if (!arguments.length) return utilGetDimensions(svg);\n utilSetDimensions(svg, val);\n return this;\n };\n\n\n return utilRebind(drawLayers, dispatch, 'on');\n}\n","/**\n * Removes all key-value entries from the list cache.\n *\n * @private\n * @name clear\n * @memberOf ListCache\n */\nfunction listCacheClear() {\n this.__data__ = [];\n this.size = 0;\n}\n\nexport default listCacheClear;\n","/**\n * Performs a\n * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)\n * comparison between two values to determine if they are equivalent.\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to compare.\n * @param {*} other The other value to compare.\n * @returns {boolean} Returns `true` if the values are equivalent, else `false`.\n * @example\n *\n * var object = { 'a': 1 };\n * var other = { 'a': 1 };\n *\n * _.eq(object, object);\n * // => true\n *\n * _.eq(object, other);\n * // => false\n *\n * _.eq('a', 'a');\n * // => true\n *\n * _.eq('a', Object('a'));\n * // => false\n *\n * _.eq(NaN, NaN);\n * // => true\n */\nfunction eq(value, other) {\n return value === other || (value !== value && other !== other);\n}\n\nexport default eq;\n","import eq from './eq.js';\n\n/**\n * Gets the index at which the `key` is found in `array` of key-value pairs.\n *\n * @private\n * @param {Array} array The array to inspect.\n * @param {*} key The key to search for.\n * @returns {number} Returns the index of the matched value, else `-1`.\n */\nfunction assocIndexOf(array, key) {\n var length = array.length;\n while (length--) {\n if (eq(array[length][0], key)) {\n return length;\n }\n }\n return -1;\n}\n\nexport default assocIndexOf;\n","import assocIndexOf from './_assocIndexOf.js';\n\n/** Used for built-in method references. */\nvar arrayProto = Array.prototype;\n\n/** Built-in value references. */\nvar splice = arrayProto.splice;\n\n/**\n * Removes `key` and its value from the list cache.\n *\n * @private\n * @name delete\n * @memberOf ListCache\n * @param {string} key The key of the value to remove.\n * @returns {boolean} Returns `true` if the entry was removed, else `false`.\n */\nfunction listCacheDelete(key) {\n var data = this.__data__,\n index = assocIndexOf(data, key);\n\n if (index < 0) {\n return false;\n }\n var lastIndex = data.length - 1;\n if (index == lastIndex) {\n data.pop();\n } else {\n splice.call(data, index, 1);\n }\n --this.size;\n return true;\n}\n\nexport default listCacheDelete;\n","import assocIndexOf from './_assocIndexOf.js';\n\n/**\n * Gets the list cache value for `key`.\n *\n * @private\n * @name get\n * @memberOf ListCache\n * @param {string} key The key of the value to get.\n * @returns {*} Returns the entry value.\n */\nfunction listCacheGet(key) {\n var data = this.__data__,\n index = assocIndexOf(data, key);\n\n return index < 0 ? undefined : data[index][1];\n}\n\nexport default listCacheGet;\n","import assocIndexOf from './_assocIndexOf.js';\n\n/**\n * Checks if a list cache value for `key` exists.\n *\n * @private\n * @name has\n * @memberOf ListCache\n * @param {string} key The key of the entry to check.\n * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.\n */\nfunction listCacheHas(key) {\n return assocIndexOf(this.__data__, key) > -1;\n}\n\nexport default listCacheHas;\n","import assocIndexOf from './_assocIndexOf.js';\n\n/**\n * Sets the list cache `key` to `value`.\n *\n * @private\n * @name set\n * @memberOf ListCache\n * @param {string} key The key of the value to set.\n * @param {*} value The value to set.\n * @returns {Object} Returns the list cache instance.\n */\nfunction listCacheSet(key, value) {\n var data = this.__data__,\n index = assocIndexOf(data, key);\n\n if (index < 0) {\n ++this.size;\n data.push([key, value]);\n } else {\n data[index][1] = value;\n }\n return this;\n}\n\nexport default listCacheSet;\n","import listCacheClear from './_listCacheClear.js';\nimport listCacheDelete from './_listCacheDelete.js';\nimport listCacheGet from './_listCacheGet.js';\nimport listCacheHas from './_listCacheHas.js';\nimport listCacheSet from './_listCacheSet.js';\n\n/**\n * Creates an list cache object.\n *\n * @private\n * @constructor\n * @param {Array} [entries] The key-value pairs to cache.\n */\nfunction ListCache(entries) {\n var index = -1,\n length = entries == null ? 0 : entries.length;\n\n this.clear();\n while (++index < length) {\n var entry = entries[index];\n this.set(entry[0], entry[1]);\n }\n}\n\n// Add methods to `ListCache`.\nListCache.prototype.clear = listCacheClear;\nListCache.prototype['delete'] = listCacheDelete;\nListCache.prototype.get = listCacheGet;\nListCache.prototype.has = listCacheHas;\nListCache.prototype.set = listCacheSet;\n\nexport default ListCache;\n","import ListCache from './_ListCache.js';\n\n/**\n * Removes all key-value entries from the stack.\n *\n * @private\n * @name clear\n * @memberOf Stack\n */\nfunction stackClear() {\n this.__data__ = new ListCache;\n this.size = 0;\n}\n\nexport default stackClear;\n","/**\n * Removes `key` and its value from the stack.\n *\n * @private\n * @name delete\n * @memberOf Stack\n * @param {string} key The key of the value to remove.\n * @returns {boolean} Returns `true` if the entry was removed, else `false`.\n */\nfunction stackDelete(key) {\n var data = this.__data__,\n result = data['delete'](key);\n\n this.size = data.size;\n return result;\n}\n\nexport default stackDelete;\n","/**\n * Gets the stack value for `key`.\n *\n * @private\n * @name get\n * @memberOf Stack\n * @param {string} key The key of the value to get.\n * @returns {*} Returns the entry value.\n */\nfunction stackGet(key) {\n return this.__data__.get(key);\n}\n\nexport default stackGet;\n","/**\n * Checks if a stack value for `key` exists.\n *\n * @private\n * @name has\n * @memberOf Stack\n * @param {string} key The key of the entry to check.\n * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.\n */\nfunction stackHas(key) {\n return this.__data__.has(key);\n}\n\nexport default stackHas;\n","import baseGetTag from './_baseGetTag.js';\nimport isObject from './isObject.js';\n\n/** `Object#toString` result references. */\nvar asyncTag = '[object AsyncFunction]',\n funcTag = '[object Function]',\n genTag = '[object GeneratorFunction]',\n proxyTag = '[object Proxy]';\n\n/**\n * Checks if `value` is classified as a `Function` object.\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a function, else `false`.\n * @example\n *\n * _.isFunction(_);\n * // => true\n *\n * _.isFunction(/abc/);\n * // => false\n */\nfunction isFunction(value) {\n if (!isObject(value)) {\n return false;\n }\n // The use of `Object#toString` avoids issues with the `typeof` operator\n // in Safari 9 which returns 'object' for typed arrays and other constructors.\n var tag = baseGetTag(value);\n return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;\n}\n\nexport default isFunction;\n","import root from './_root.js';\n\n/** Used to detect overreaching core-js shims. */\nvar coreJsData = root['__core-js_shared__'];\n\nexport default coreJsData;\n","import coreJsData from './_coreJsData.js';\n\n/** Used to detect methods masquerading as native. */\nvar maskSrcKey = (function() {\n var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');\n return uid ? ('Symbol(src)_1.' + uid) : '';\n}());\n\n/**\n * Checks if `func` has its source masked.\n *\n * @private\n * @param {Function} func The function to check.\n * @returns {boolean} Returns `true` if `func` is masked, else `false`.\n */\nfunction isMasked(func) {\n return !!maskSrcKey && (maskSrcKey in func);\n}\n\nexport default isMasked;\n","/** Used for built-in method references. */\nvar funcProto = Function.prototype;\n\n/** Used to resolve the decompiled source of functions. */\nvar funcToString = funcProto.toString;\n\n/**\n * Converts `func` to its source code.\n *\n * @private\n * @param {Function} func The function to convert.\n * @returns {string} Returns the source code.\n */\nfunction toSource(func) {\n if (func != null) {\n try {\n return funcToString.call(func);\n } catch (e) {}\n try {\n return (func + '');\n } catch (e) {}\n }\n return '';\n}\n\nexport default toSource;\n","import isFunction from './isFunction.js';\nimport isMasked from './_isMasked.js';\nimport isObject from './isObject.js';\nimport toSource from './_toSource.js';\n\n/**\n * Used to match `RegExp`\n * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).\n */\nvar reRegExpChar = /[\\\\^$.*+?()[\\]{}|]/g;\n\n/** Used to detect host constructors (Safari). */\nvar reIsHostCtor = /^\\[object .+?Constructor\\]$/;\n\n/** Used for built-in method references. */\nvar funcProto = Function.prototype,\n objectProto = Object.prototype;\n\n/** Used to resolve the decompiled source of functions. */\nvar funcToString = funcProto.toString;\n\n/** Used to check objects for own properties. */\nvar hasOwnProperty = objectProto.hasOwnProperty;\n\n/** Used to detect if a method is native. */\nvar reIsNative = RegExp('^' +\n funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\\\$&')\n .replace(/hasOwnProperty|(function).*?(?=\\\\\\()| for .+?(?=\\\\\\])/g, '$1.*?') + '$'\n);\n\n/**\n * The base implementation of `_.isNative` without bad shim checks.\n *\n * @private\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a native function,\n * else `false`.\n */\nfunction baseIsNative(value) {\n if (!isObject(value) || isMasked(value)) {\n return false;\n }\n var pattern = isFunction(value) ? reIsNative : reIsHostCtor;\n return pattern.test(toSource(value));\n}\n\nexport default baseIsNative;\n","/**\n * Gets the value at `key` of `object`.\n *\n * @private\n * @param {Object} [object] The object to query.\n * @param {string} key The key of the property to get.\n * @returns {*} Returns the property value.\n */\nfunction getValue(object, key) {\n return object == null ? undefined : object[key];\n}\n\nexport default getValue;\n","import baseIsNative from './_baseIsNative.js';\nimport getValue from './_getValue.js';\n\n/**\n * Gets the native function at `key` of `object`.\n *\n * @private\n * @param {Object} object The object to query.\n * @param {string} key The key of the method to get.\n * @returns {*} Returns the function if it's native, else `undefined`.\n */\nfunction getNative(object, key) {\n var value = getValue(object, key);\n return baseIsNative(value) ? value : undefined;\n}\n\nexport default getNative;\n","import getNative from './_getNative.js';\nimport root from './_root.js';\n\n/* Built-in method references that are verified to be native. */\nvar Map = getNative(root, 'Map');\n\nexport default Map;\n","import getNative from './_getNative.js';\n\n/* Built-in method references that are verified to be native. */\nvar nativeCreate = getNative(Object, 'create');\n\nexport default nativeCreate;\n","import nativeCreate from './_nativeCreate.js';\n\n/**\n * Removes all key-value entries from the hash.\n *\n * @private\n * @name clear\n * @memberOf Hash\n */\nfunction hashClear() {\n this.__data__ = nativeCreate ? nativeCreate(null) : {};\n this.size = 0;\n}\n\nexport default hashClear;\n","/**\n * Removes `key` and its value from the hash.\n *\n * @private\n * @name delete\n * @memberOf Hash\n * @param {Object} hash The hash to modify.\n * @param {string} key The key of the value to remove.\n * @returns {boolean} Returns `true` if the entry was removed, else `false`.\n */\nfunction hashDelete(key) {\n var result = this.has(key) && delete this.__data__[key];\n this.size -= result ? 1 : 0;\n return result;\n}\n\nexport default hashDelete;\n","import nativeCreate from './_nativeCreate.js';\n\n/** Used to stand-in for `undefined` hash values. */\nvar HASH_UNDEFINED = '__lodash_hash_undefined__';\n\n/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/** Used to check objects for own properties. */\nvar hasOwnProperty = objectProto.hasOwnProperty;\n\n/**\n * Gets the hash value for `key`.\n *\n * @private\n * @name get\n * @memberOf Hash\n * @param {string} key The key of the value to get.\n * @returns {*} Returns the entry value.\n */\nfunction hashGet(key) {\n var data = this.__data__;\n if (nativeCreate) {\n var result = data[key];\n return result === HASH_UNDEFINED ? undefined : result;\n }\n return hasOwnProperty.call(data, key) ? data[key] : undefined;\n}\n\nexport default hashGet;\n","import nativeCreate from './_nativeCreate.js';\n\n/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/** Used to check objects for own properties. */\nvar hasOwnProperty = objectProto.hasOwnProperty;\n\n/**\n * Checks if a hash value for `key` exists.\n *\n * @private\n * @name has\n * @memberOf Hash\n * @param {string} key The key of the entry to check.\n * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.\n */\nfunction hashHas(key) {\n var data = this.__data__;\n return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);\n}\n\nexport default hashHas;\n","import nativeCreate from './_nativeCreate.js';\n\n/** Used to stand-in for `undefined` hash values. */\nvar HASH_UNDEFINED = '__lodash_hash_undefined__';\n\n/**\n * Sets the hash `key` to `value`.\n *\n * @private\n * @name set\n * @memberOf Hash\n * @param {string} key The key of the value to set.\n * @param {*} value The value to set.\n * @returns {Object} Returns the hash instance.\n */\nfunction hashSet(key, value) {\n var data = this.__data__;\n this.size += this.has(key) ? 0 : 1;\n data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;\n return this;\n}\n\nexport default hashSet;\n","import hashClear from './_hashClear.js';\nimport hashDelete from './_hashDelete.js';\nimport hashGet from './_hashGet.js';\nimport hashHas from './_hashHas.js';\nimport hashSet from './_hashSet.js';\n\n/**\n * Creates a hash object.\n *\n * @private\n * @constructor\n * @param {Array} [entries] The key-value pairs to cache.\n */\nfunction Hash(entries) {\n var index = -1,\n length = entries == null ? 0 : entries.length;\n\n this.clear();\n while (++index < length) {\n var entry = entries[index];\n this.set(entry[0], entry[1]);\n }\n}\n\n// Add methods to `Hash`.\nHash.prototype.clear = hashClear;\nHash.prototype['delete'] = hashDelete;\nHash.prototype.get = hashGet;\nHash.prototype.has = hashHas;\nHash.prototype.set = hashSet;\n\nexport default Hash;\n","import Hash from './_Hash.js';\nimport ListCache from './_ListCache.js';\nimport Map from './_Map.js';\n\n/**\n * Removes all key-value entries from the map.\n *\n * @private\n * @name clear\n * @memberOf MapCache\n */\nfunction mapCacheClear() {\n this.size = 0;\n this.__data__ = {\n 'hash': new Hash,\n 'map': new (Map || ListCache),\n 'string': new Hash\n };\n}\n\nexport default mapCacheClear;\n","/**\n * Checks if `value` is suitable for use as unique object key.\n *\n * @private\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is suitable, else `false`.\n */\nfunction isKeyable(value) {\n var type = typeof value;\n return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')\n ? (value !== '__proto__')\n : (value === null);\n}\n\nexport default isKeyable;\n","import isKeyable from './_isKeyable.js';\n\n/**\n * Gets the data for `map`.\n *\n * @private\n * @param {Object} map The map to query.\n * @param {string} key The reference key.\n * @returns {*} Returns the map data.\n */\nfunction getMapData(map, key) {\n var data = map.__data__;\n return isKeyable(key)\n ? data[typeof key == 'string' ? 'string' : 'hash']\n : data.map;\n}\n\nexport default getMapData;\n","import getMapData from './_getMapData.js';\n\n/**\n * Removes `key` and its value from the map.\n *\n * @private\n * @name delete\n * @memberOf MapCache\n * @param {string} key The key of the value to remove.\n * @returns {boolean} Returns `true` if the entry was removed, else `false`.\n */\nfunction mapCacheDelete(key) {\n var result = getMapData(this, key)['delete'](key);\n this.size -= result ? 1 : 0;\n return result;\n}\n\nexport default mapCacheDelete;\n","import getMapData from './_getMapData.js';\n\n/**\n * Gets the map value for `key`.\n *\n * @private\n * @name get\n * @memberOf MapCache\n * @param {string} key The key of the value to get.\n * @returns {*} Returns the entry value.\n */\nfunction mapCacheGet(key) {\n return getMapData(this, key).get(key);\n}\n\nexport default mapCacheGet;\n","import getMapData from './_getMapData.js';\n\n/**\n * Checks if a map value for `key` exists.\n *\n * @private\n * @name has\n * @memberOf MapCache\n * @param {string} key The key of the entry to check.\n * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.\n */\nfunction mapCacheHas(key) {\n return getMapData(this, key).has(key);\n}\n\nexport default mapCacheHas;\n","import getMapData from './_getMapData.js';\n\n/**\n * Sets the map `key` to `value`.\n *\n * @private\n * @name set\n * @memberOf MapCache\n * @param {string} key The key of the value to set.\n * @param {*} value The value to set.\n * @returns {Object} Returns the map cache instance.\n */\nfunction mapCacheSet(key, value) {\n var data = getMapData(this, key),\n size = data.size;\n\n data.set(key, value);\n this.size += data.size == size ? 0 : 1;\n return this;\n}\n\nexport default mapCacheSet;\n","import mapCacheClear from './_mapCacheClear.js';\nimport mapCacheDelete from './_mapCacheDelete.js';\nimport mapCacheGet from './_mapCacheGet.js';\nimport mapCacheHas from './_mapCacheHas.js';\nimport mapCacheSet from './_mapCacheSet.js';\n\n/**\n * Creates a map cache object to store key-value pairs.\n *\n * @private\n * @constructor\n * @param {Array} [entries] The key-value pairs to cache.\n */\nfunction MapCache(entries) {\n var index = -1,\n length = entries == null ? 0 : entries.length;\n\n this.clear();\n while (++index < length) {\n var entry = entries[index];\n this.set(entry[0], entry[1]);\n }\n}\n\n// Add methods to `MapCache`.\nMapCache.prototype.clear = mapCacheClear;\nMapCache.prototype['delete'] = mapCacheDelete;\nMapCache.prototype.get = mapCacheGet;\nMapCache.prototype.has = mapCacheHas;\nMapCache.prototype.set = mapCacheSet;\n\nexport default MapCache;\n","import ListCache from './_ListCache.js';\nimport Map from './_Map.js';\nimport MapCache from './_MapCache.js';\n\n/** Used as the size to enable large array optimizations. */\nvar LARGE_ARRAY_SIZE = 200;\n\n/**\n * Sets the stack `key` to `value`.\n *\n * @private\n * @name set\n * @memberOf Stack\n * @param {string} key The key of the value to set.\n * @param {*} value The value to set.\n * @returns {Object} Returns the stack cache instance.\n */\nfunction stackSet(key, value) {\n var data = this.__data__;\n if (data instanceof ListCache) {\n var pairs = data.__data__;\n if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {\n pairs.push([key, value]);\n this.size = ++data.size;\n return this;\n }\n data = this.__data__ = new MapCache(pairs);\n }\n data.set(key, value);\n this.size = data.size;\n return this;\n}\n\nexport default stackSet;\n","import ListCache from './_ListCache.js';\nimport stackClear from './_stackClear.js';\nimport stackDelete from './_stackDelete.js';\nimport stackGet from './_stackGet.js';\nimport stackHas from './_stackHas.js';\nimport stackSet from './_stackSet.js';\n\n/**\n * Creates a stack cache object to store key-value pairs.\n *\n * @private\n * @constructor\n * @param {Array} [entries] The key-value pairs to cache.\n */\nfunction Stack(entries) {\n var data = this.__data__ = new ListCache(entries);\n this.size = data.size;\n}\n\n// Add methods to `Stack`.\nStack.prototype.clear = stackClear;\nStack.prototype['delete'] = stackDelete;\nStack.prototype.get = stackGet;\nStack.prototype.has = stackHas;\nStack.prototype.set = stackSet;\n\nexport default Stack;\n","/** Used to stand-in for `undefined` hash values. */\nvar HASH_UNDEFINED = '__lodash_hash_undefined__';\n\n/**\n * Adds `value` to the array cache.\n *\n * @private\n * @name add\n * @memberOf SetCache\n * @alias push\n * @param {*} value The value to cache.\n * @returns {Object} Returns the cache instance.\n */\nfunction setCacheAdd(value) {\n this.__data__.set(value, HASH_UNDEFINED);\n return this;\n}\n\nexport default setCacheAdd;\n","/**\n * Checks if `value` is in the array cache.\n *\n * @private\n * @name has\n * @memberOf SetCache\n * @param {*} value The value to search for.\n * @returns {number} Returns `true` if `value` is found, else `false`.\n */\nfunction setCacheHas(value) {\n return this.__data__.has(value);\n}\n\nexport default setCacheHas;\n","import MapCache from './_MapCache.js';\nimport setCacheAdd from './_setCacheAdd.js';\nimport setCacheHas from './_setCacheHas.js';\n\n/**\n *\n * Creates an array cache object to store unique values.\n *\n * @private\n * @constructor\n * @param {Array} [values] The values to cache.\n */\nfunction SetCache(values) {\n var index = -1,\n length = values == null ? 0 : values.length;\n\n this.__data__ = new MapCache;\n while (++index < length) {\n this.add(values[index]);\n }\n}\n\n// Add methods to `SetCache`.\nSetCache.prototype.add = SetCache.prototype.push = setCacheAdd;\nSetCache.prototype.has = setCacheHas;\n\nexport default SetCache;\n","/**\n * A specialized version of `_.some` for arrays without support for iteratee\n * shorthands.\n *\n * @private\n * @param {Array} [array] The array to iterate over.\n * @param {Function} predicate The function invoked per iteration.\n * @returns {boolean} Returns `true` if any element passes the predicate check,\n * else `false`.\n */\nfunction arraySome(array, predicate) {\n var index = -1,\n length = array == null ? 0 : array.length;\n\n while (++index < length) {\n if (predicate(array[index], index, array)) {\n return true;\n }\n }\n return false;\n}\n\nexport default arraySome;\n","/**\n * Checks if a `cache` value for `key` exists.\n *\n * @private\n * @param {Object} cache The cache to query.\n * @param {string} key The key of the entry to check.\n * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.\n */\nfunction cacheHas(cache, key) {\n return cache.has(key);\n}\n\nexport default cacheHas;\n","import SetCache from './_SetCache.js';\nimport arraySome from './_arraySome.js';\nimport cacheHas from './_cacheHas.js';\n\n/** Used to compose bitmasks for value comparisons. */\nvar COMPARE_PARTIAL_FLAG = 1,\n COMPARE_UNORDERED_FLAG = 2;\n\n/**\n * A specialized version of `baseIsEqualDeep` for arrays with support for\n * partial deep comparisons.\n *\n * @private\n * @param {Array} array The array to compare.\n * @param {Array} other The other array to compare.\n * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.\n * @param {Function} customizer The function to customize comparisons.\n * @param {Function} equalFunc The function to determine equivalents of values.\n * @param {Object} stack Tracks traversed `array` and `other` objects.\n * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.\n */\nfunction equalArrays(array, other, bitmask, customizer, equalFunc, stack) {\n var isPartial = bitmask & COMPARE_PARTIAL_FLAG,\n arrLength = array.length,\n othLength = other.length;\n\n if (arrLength != othLength && !(isPartial && othLength > arrLength)) {\n return false;\n }\n // Assume cyclic values are equal.\n var stacked = stack.get(array);\n if (stacked && stack.get(other)) {\n return stacked == other;\n }\n var index = -1,\n result = true,\n seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;\n\n stack.set(array, other);\n stack.set(other, array);\n\n // Ignore non-index properties.\n while (++index < arrLength) {\n var arrValue = array[index],\n othValue = other[index];\n\n if (customizer) {\n var compared = isPartial\n ? customizer(othValue, arrValue, index, other, array, stack)\n : customizer(arrValue, othValue, index, array, other, stack);\n }\n if (compared !== undefined) {\n if (compared) {\n continue;\n }\n result = false;\n break;\n }\n // Recursively compare arrays (susceptible to call stack limits).\n if (seen) {\n if (!arraySome(other, function(othValue, othIndex) {\n if (!cacheHas(seen, othIndex) &&\n (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {\n return seen.push(othIndex);\n }\n })) {\n result = false;\n break;\n }\n } else if (!(\n arrValue === othValue ||\n equalFunc(arrValue, othValue, bitmask, customizer, stack)\n )) {\n result = false;\n break;\n }\n }\n stack['delete'](array);\n stack['delete'](other);\n return result;\n}\n\nexport default equalArrays;\n","import root from './_root.js';\n\n/** Built-in value references. */\nvar Uint8Array = root.Uint8Array;\n\nexport default Uint8Array;\n","/**\n * Converts `map` to its key-value pairs.\n *\n * @private\n * @param {Object} map The map to convert.\n * @returns {Array} Returns the key-value pairs.\n */\nfunction mapToArray(map) {\n var index = -1,\n result = Array(map.size);\n\n map.forEach(function(value, key) {\n result[++index] = [key, value];\n });\n return result;\n}\n\nexport default mapToArray;\n","/**\n * Converts `set` to an array of its values.\n *\n * @private\n * @param {Object} set The set to convert.\n * @returns {Array} Returns the values.\n */\nfunction setToArray(set) {\n var index = -1,\n result = Array(set.size);\n\n set.forEach(function(value) {\n result[++index] = value;\n });\n return result;\n}\n\nexport default setToArray;\n","import Symbol from './_Symbol.js';\nimport Uint8Array from './_Uint8Array.js';\nimport eq from './eq.js';\nimport equalArrays from './_equalArrays.js';\nimport mapToArray from './_mapToArray.js';\nimport setToArray from './_setToArray.js';\n\n/** Used to compose bitmasks for value comparisons. */\nvar COMPARE_PARTIAL_FLAG = 1,\n COMPARE_UNORDERED_FLAG = 2;\n\n/** `Object#toString` result references. */\nvar boolTag = '[object Boolean]',\n dateTag = '[object Date]',\n errorTag = '[object Error]',\n mapTag = '[object Map]',\n numberTag = '[object Number]',\n regexpTag = '[object RegExp]',\n setTag = '[object Set]',\n stringTag = '[object String]',\n symbolTag = '[object Symbol]';\n\nvar arrayBufferTag = '[object ArrayBuffer]',\n dataViewTag = '[object DataView]';\n\n/** Used to convert symbols to primitives and strings. */\nvar symbolProto = Symbol ? Symbol.prototype : undefined,\n symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;\n\n/**\n * A specialized version of `baseIsEqualDeep` for comparing objects of\n * the same `toStringTag`.\n *\n * **Note:** This function only supports comparing values with tags of\n * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.\n *\n * @private\n * @param {Object} object The object to compare.\n * @param {Object} other The other object to compare.\n * @param {string} tag The `toStringTag` of the objects to compare.\n * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.\n * @param {Function} customizer The function to customize comparisons.\n * @param {Function} equalFunc The function to determine equivalents of values.\n * @param {Object} stack Tracks traversed `object` and `other` objects.\n * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.\n */\nfunction equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {\n switch (tag) {\n case dataViewTag:\n if ((object.byteLength != other.byteLength) ||\n (object.byteOffset != other.byteOffset)) {\n return false;\n }\n object = object.buffer;\n other = other.buffer;\n\n case arrayBufferTag:\n if ((object.byteLength != other.byteLength) ||\n !equalFunc(new Uint8Array(object), new Uint8Array(other))) {\n return false;\n }\n return true;\n\n case boolTag:\n case dateTag:\n case numberTag:\n // Coerce booleans to `1` or `0` and dates to milliseconds.\n // Invalid dates are coerced to `NaN`.\n return eq(+object, +other);\n\n case errorTag:\n return object.name == other.name && object.message == other.message;\n\n case regexpTag:\n case stringTag:\n // Coerce regexes to strings and treat strings, primitives and objects,\n // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring\n // for more details.\n return object == (other + '');\n\n case mapTag:\n var convert = mapToArray;\n\n case setTag:\n var isPartial = bitmask & COMPARE_PARTIAL_FLAG;\n convert || (convert = setToArray);\n\n if (object.size != other.size && !isPartial) {\n return false;\n }\n // Assume cyclic values are equal.\n var stacked = stack.get(object);\n if (stacked) {\n return stacked == other;\n }\n bitmask |= COMPARE_UNORDERED_FLAG;\n\n // Recursively compare objects (susceptible to call stack limits).\n stack.set(object, other);\n var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);\n stack['delete'](object);\n return result;\n\n case symbolTag:\n if (symbolValueOf) {\n return symbolValueOf.call(object) == symbolValueOf.call(other);\n }\n }\n return false;\n}\n\nexport default equalByTag;\n","/**\n * Appends the elements of `values` to `array`.\n *\n * @private\n * @param {Array} array The array to modify.\n * @param {Array} values The values to append.\n * @returns {Array} Returns `array`.\n */\nfunction arrayPush(array, values) {\n var index = -1,\n length = values.length,\n offset = array.length;\n\n while (++index < length) {\n array[offset + index] = values[index];\n }\n return array;\n}\n\nexport default arrayPush;\n","/**\n * Checks if `value` is classified as an `Array` object.\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is an array, else `false`.\n * @example\n *\n * _.isArray([1, 2, 3]);\n * // => true\n *\n * _.isArray(document.body.children);\n * // => false\n *\n * _.isArray('abc');\n * // => false\n *\n * _.isArray(_.noop);\n * // => false\n */\nvar isArray = Array.isArray;\n\nexport default isArray;\n","import arrayPush from './_arrayPush.js';\nimport isArray from './isArray.js';\n\n/**\n * The base implementation of `getAllKeys` and `getAllKeysIn` which uses\n * `keysFunc` and `symbolsFunc` to get the enumerable property names and\n * symbols of `object`.\n *\n * @private\n * @param {Object} object The object to query.\n * @param {Function} keysFunc The function to get the keys of `object`.\n * @param {Function} symbolsFunc The function to get the symbols of `object`.\n * @returns {Array} Returns the array of property names and symbols.\n */\nfunction baseGetAllKeys(object, keysFunc, symbolsFunc) {\n var result = keysFunc(object);\n return isArray(object) ? result : arrayPush(result, symbolsFunc(object));\n}\n\nexport default baseGetAllKeys;\n","/**\n * A specialized version of `_.filter` for arrays without support for\n * iteratee shorthands.\n *\n * @private\n * @param {Array} [array] The array to iterate over.\n * @param {Function} predicate The function invoked per iteration.\n * @returns {Array} Returns the new filtered array.\n */\nfunction arrayFilter(array, predicate) {\n var index = -1,\n length = array == null ? 0 : array.length,\n resIndex = 0,\n result = [];\n\n while (++index < length) {\n var value = array[index];\n if (predicate(value, index, array)) {\n result[resIndex++] = value;\n }\n }\n return result;\n}\n\nexport default arrayFilter;\n","/**\n * This method returns a new empty array.\n *\n * @static\n * @memberOf _\n * @since 4.13.0\n * @category Util\n * @returns {Array} Returns the new empty array.\n * @example\n *\n * var arrays = _.times(2, _.stubArray);\n *\n * console.log(arrays);\n * // => [[], []]\n *\n * console.log(arrays[0] === arrays[1]);\n * // => false\n */\nfunction stubArray() {\n return [];\n}\n\nexport default stubArray;\n","import arrayFilter from './_arrayFilter.js';\nimport stubArray from './stubArray.js';\n\n/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/** Built-in value references. */\nvar propertyIsEnumerable = objectProto.propertyIsEnumerable;\n\n/* Built-in method references for those with the same name as other `lodash` methods. */\nvar nativeGetSymbols = Object.getOwnPropertySymbols;\n\n/**\n * Creates an array of the own enumerable symbols of `object`.\n *\n * @private\n * @param {Object} object The object to query.\n * @returns {Array} Returns the array of symbols.\n */\nvar getSymbols = !nativeGetSymbols ? stubArray : function(object) {\n if (object == null) {\n return [];\n }\n object = Object(object);\n return arrayFilter(nativeGetSymbols(object), function(symbol) {\n return propertyIsEnumerable.call(object, symbol);\n });\n};\n\nexport default getSymbols;\n","/**\n * The base implementation of `_.times` without support for iteratee shorthands\n * or max array length checks.\n *\n * @private\n * @param {number} n The number of times to invoke `iteratee`.\n * @param {Function} iteratee The function invoked per iteration.\n * @returns {Array} Returns the array of results.\n */\nfunction baseTimes(n, iteratee) {\n var index = -1,\n result = Array(n);\n\n while (++index < n) {\n result[index] = iteratee(index);\n }\n return result;\n}\n\nexport default baseTimes;\n","import baseGetTag from './_baseGetTag.js';\nimport isObjectLike from './isObjectLike.js';\n\n/** `Object#toString` result references. */\nvar argsTag = '[object Arguments]';\n\n/**\n * The base implementation of `_.isArguments`.\n *\n * @private\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is an `arguments` object,\n */\nfunction baseIsArguments(value) {\n return isObjectLike(value) && baseGetTag(value) == argsTag;\n}\n\nexport default baseIsArguments;\n","import baseIsArguments from './_baseIsArguments.js';\nimport isObjectLike from './isObjectLike.js';\n\n/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/** Used to check objects for own properties. */\nvar hasOwnProperty = objectProto.hasOwnProperty;\n\n/** Built-in value references. */\nvar propertyIsEnumerable = objectProto.propertyIsEnumerable;\n\n/**\n * Checks if `value` is likely an `arguments` object.\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is an `arguments` object,\n * else `false`.\n * @example\n *\n * _.isArguments(function() { return arguments; }());\n * // => true\n *\n * _.isArguments([1, 2, 3]);\n * // => false\n */\nvar isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {\n return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&\n !propertyIsEnumerable.call(value, 'callee');\n};\n\nexport default isArguments;\n","/**\n * This method returns `false`.\n *\n * @static\n * @memberOf _\n * @since 4.13.0\n * @category Util\n * @returns {boolean} Returns `false`.\n * @example\n *\n * _.times(2, _.stubFalse);\n * // => [false, false]\n */\nfunction stubFalse() {\n return false;\n}\n\nexport default stubFalse;\n","import root from './_root.js';\nimport stubFalse from './stubFalse.js';\n\n/** Detect free variable `exports`. */\nvar freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;\n\n/** Detect free variable `module`. */\nvar freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;\n\n/** Detect the popular CommonJS extension `module.exports`. */\nvar moduleExports = freeModule && freeModule.exports === freeExports;\n\n/** Built-in value references. */\nvar Buffer = moduleExports ? root.Buffer : undefined;\n\n/* Built-in method references for those with the same name as other `lodash` methods. */\nvar nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined;\n\n/**\n * Checks if `value` is a buffer.\n *\n * @static\n * @memberOf _\n * @since 4.3.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.\n * @example\n *\n * _.isBuffer(new Buffer(2));\n * // => true\n *\n * _.isBuffer(new Uint8Array(2));\n * // => false\n */\nvar isBuffer = nativeIsBuffer || stubFalse;\n\nexport default isBuffer;\n","/** Used as references for various `Number` constants. */\nvar MAX_SAFE_INTEGER = 9007199254740991;\n\n/** Used to detect unsigned integer values. */\nvar reIsUint = /^(?:0|[1-9]\\d*)$/;\n\n/**\n * Checks if `value` is a valid array-like index.\n *\n * @private\n * @param {*} value The value to check.\n * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.\n * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.\n */\nfunction isIndex(value, length) {\n var type = typeof value;\n length = length == null ? MAX_SAFE_INTEGER : length;\n\n return !!length &&\n (type == 'number' ||\n (type != 'symbol' && reIsUint.test(value))) &&\n (value > -1 && value % 1 == 0 && value < length);\n}\n\nexport default isIndex;\n","/** Used as references for various `Number` constants. */\nvar MAX_SAFE_INTEGER = 9007199254740991;\n\n/**\n * Checks if `value` is a valid array-like length.\n *\n * **Note:** This method is loosely based on\n * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.\n * @example\n *\n * _.isLength(3);\n * // => true\n *\n * _.isLength(Number.MIN_VALUE);\n * // => false\n *\n * _.isLength(Infinity);\n * // => false\n *\n * _.isLength('3');\n * // => false\n */\nfunction isLength(value) {\n return typeof value == 'number' &&\n value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;\n}\n\nexport default isLength;\n","import baseGetTag from './_baseGetTag.js';\nimport isLength from './isLength.js';\nimport isObjectLike from './isObjectLike.js';\n\n/** `Object#toString` result references. */\nvar argsTag = '[object Arguments]',\n arrayTag = '[object Array]',\n boolTag = '[object Boolean]',\n dateTag = '[object Date]',\n errorTag = '[object Error]',\n funcTag = '[object Function]',\n mapTag = '[object Map]',\n numberTag = '[object Number]',\n objectTag = '[object Object]',\n regexpTag = '[object RegExp]',\n setTag = '[object Set]',\n stringTag = '[object String]',\n weakMapTag = '[object WeakMap]';\n\nvar arrayBufferTag = '[object ArrayBuffer]',\n dataViewTag = '[object DataView]',\n float32Tag = '[object Float32Array]',\n float64Tag = '[object Float64Array]',\n int8Tag = '[object Int8Array]',\n int16Tag = '[object Int16Array]',\n int32Tag = '[object Int32Array]',\n uint8Tag = '[object Uint8Array]',\n uint8ClampedTag = '[object Uint8ClampedArray]',\n uint16Tag = '[object Uint16Array]',\n uint32Tag = '[object Uint32Array]';\n\n/** Used to identify `toStringTag` values of typed arrays. */\nvar typedArrayTags = {};\ntypedArrayTags[float32Tag] = typedArrayTags[float64Tag] =\ntypedArrayTags[int8Tag] = typedArrayTags[int16Tag] =\ntypedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =\ntypedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =\ntypedArrayTags[uint32Tag] = true;\ntypedArrayTags[argsTag] = typedArrayTags[arrayTag] =\ntypedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =\ntypedArrayTags[dataViewTag] = typedArrayTags[dateTag] =\ntypedArrayTags[errorTag] = typedArrayTags[funcTag] =\ntypedArrayTags[mapTag] = typedArrayTags[numberTag] =\ntypedArrayTags[objectTag] = typedArrayTags[regexpTag] =\ntypedArrayTags[setTag] = typedArrayTags[stringTag] =\ntypedArrayTags[weakMapTag] = false;\n\n/**\n * The base implementation of `_.isTypedArray` without Node.js optimizations.\n *\n * @private\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.\n */\nfunction baseIsTypedArray(value) {\n return isObjectLike(value) &&\n isLength(value.length) && !!typedArrayTags[baseGetTag(value)];\n}\n\nexport default baseIsTypedArray;\n","/**\n * The base implementation of `_.unary` without support for storing metadata.\n *\n * @private\n * @param {Function} func The function to cap arguments for.\n * @returns {Function} Returns the new capped function.\n */\nfunction baseUnary(func) {\n return function(value) {\n return func(value);\n };\n}\n\nexport default baseUnary;\n","import freeGlobal from './_freeGlobal.js';\n\n/** Detect free variable `exports`. */\nvar freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;\n\n/** Detect free variable `module`. */\nvar freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;\n\n/** Detect the popular CommonJS extension `module.exports`. */\nvar moduleExports = freeModule && freeModule.exports === freeExports;\n\n/** Detect free variable `process` from Node.js. */\nvar freeProcess = moduleExports && freeGlobal.process;\n\n/** Used to access faster Node.js helpers. */\nvar nodeUtil = (function() {\n try {\n // Use `util.types` for Node.js 10+.\n var types = freeModule && freeModule.require && freeModule.require('util').types;\n\n if (types) {\n return types;\n }\n\n // Legacy `process.binding('util')` for Node.js < 10.\n return freeProcess && freeProcess.binding && freeProcess.binding('util');\n } catch (e) {}\n}());\n\nexport default nodeUtil;\n","import baseIsTypedArray from './_baseIsTypedArray.js';\nimport baseUnary from './_baseUnary.js';\nimport nodeUtil from './_nodeUtil.js';\n\n/* Node.js helper references. */\nvar nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;\n\n/**\n * Checks if `value` is classified as a typed array.\n *\n * @static\n * @memberOf _\n * @since 3.0.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.\n * @example\n *\n * _.isTypedArray(new Uint8Array);\n * // => true\n *\n * _.isTypedArray([]);\n * // => false\n */\nvar isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;\n\nexport default isTypedArray;\n","import baseTimes from './_baseTimes.js';\nimport isArguments from './isArguments.js';\nimport isArray from './isArray.js';\nimport isBuffer from './isBuffer.js';\nimport isIndex from './_isIndex.js';\nimport isTypedArray from './isTypedArray.js';\n\n/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/** Used to check objects for own properties. */\nvar hasOwnProperty = objectProto.hasOwnProperty;\n\n/**\n * Creates an array of the enumerable property names of the array-like `value`.\n *\n * @private\n * @param {*} value The value to query.\n * @param {boolean} inherited Specify returning inherited property names.\n * @returns {Array} Returns the array of property names.\n */\nfunction arrayLikeKeys(value, inherited) {\n var isArr = isArray(value),\n isArg = !isArr && isArguments(value),\n isBuff = !isArr && !isArg && isBuffer(value),\n isType = !isArr && !isArg && !isBuff && isTypedArray(value),\n skipIndexes = isArr || isArg || isBuff || isType,\n result = skipIndexes ? baseTimes(value.length, String) : [],\n length = result.length;\n\n for (var key in value) {\n if ((inherited || hasOwnProperty.call(value, key)) &&\n !(skipIndexes && (\n // Safari 9 has enumerable `arguments.length` in strict mode.\n key == 'length' ||\n // Node.js 0.10 has enumerable non-index properties on buffers.\n (isBuff && (key == 'offset' || key == 'parent')) ||\n // PhantomJS 2 has enumerable non-index properties on typed arrays.\n (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||\n // Skip index properties.\n isIndex(key, length)\n ))) {\n result.push(key);\n }\n }\n return result;\n}\n\nexport default arrayLikeKeys;\n","/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/**\n * Checks if `value` is likely a prototype object.\n *\n * @private\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.\n */\nfunction isPrototype(value) {\n var Ctor = value && value.constructor,\n proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;\n\n return value === proto;\n}\n\nexport default isPrototype;\n","/**\n * Creates a unary function that invokes `func` with its argument transformed.\n *\n * @private\n * @param {Function} func The function to wrap.\n * @param {Function} transform The argument transform.\n * @returns {Function} Returns the new function.\n */\nfunction overArg(func, transform) {\n return function(arg) {\n return func(transform(arg));\n };\n}\n\nexport default overArg;\n","import overArg from './_overArg.js';\n\n/* Built-in method references for those with the same name as other `lodash` methods. */\nvar nativeKeys = overArg(Object.keys, Object);\n\nexport default nativeKeys;\n","import isPrototype from './_isPrototype.js';\nimport nativeKeys from './_nativeKeys.js';\n\n/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/** Used to check objects for own properties. */\nvar hasOwnProperty = objectProto.hasOwnProperty;\n\n/**\n * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.\n *\n * @private\n * @param {Object} object The object to query.\n * @returns {Array} Returns the array of property names.\n */\nfunction baseKeys(object) {\n if (!isPrototype(object)) {\n return nativeKeys(object);\n }\n var result = [];\n for (var key in Object(object)) {\n if (hasOwnProperty.call(object, key) && key != 'constructor') {\n result.push(key);\n }\n }\n return result;\n}\n\nexport default baseKeys;\n","import isFunction from './isFunction.js';\nimport isLength from './isLength.js';\n\n/**\n * Checks if `value` is array-like. A value is considered array-like if it's\n * not a function and has a `value.length` that's an integer greater than or\n * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is array-like, else `false`.\n * @example\n *\n * _.isArrayLike([1, 2, 3]);\n * // => true\n *\n * _.isArrayLike(document.body.children);\n * // => true\n *\n * _.isArrayLike('abc');\n * // => true\n *\n * _.isArrayLike(_.noop);\n * // => false\n */\nfunction isArrayLike(value) {\n return value != null && isLength(value.length) && !isFunction(value);\n}\n\nexport default isArrayLike;\n","import arrayLikeKeys from './_arrayLikeKeys.js';\nimport baseKeys from './_baseKeys.js';\nimport isArrayLike from './isArrayLike.js';\n\n/**\n * Creates an array of the own enumerable property names of `object`.\n *\n * **Note:** Non-object values are coerced to objects. See the\n * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)\n * for more details.\n *\n * @static\n * @since 0.1.0\n * @memberOf _\n * @category Object\n * @param {Object} object The object to query.\n * @returns {Array} Returns the array of property names.\n * @example\n *\n * function Foo() {\n * this.a = 1;\n * this.b = 2;\n * }\n *\n * Foo.prototype.c = 3;\n *\n * _.keys(new Foo);\n * // => ['a', 'b'] (iteration order is not guaranteed)\n *\n * _.keys('hi');\n * // => ['0', '1']\n */\nfunction keys(object) {\n return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);\n}\n\nexport default keys;\n","import baseGetAllKeys from './_baseGetAllKeys.js';\nimport getSymbols from './_getSymbols.js';\nimport keys from './keys.js';\n\n/**\n * Creates an array of own enumerable property names and symbols of `object`.\n *\n * @private\n * @param {Object} object The object to query.\n * @returns {Array} Returns the array of property names and symbols.\n */\nfunction getAllKeys(object) {\n return baseGetAllKeys(object, keys, getSymbols);\n}\n\nexport default getAllKeys;\n","import getAllKeys from './_getAllKeys.js';\n\n/** Used to compose bitmasks for value comparisons. */\nvar COMPARE_PARTIAL_FLAG = 1;\n\n/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/** Used to check objects for own properties. */\nvar hasOwnProperty = objectProto.hasOwnProperty;\n\n/**\n * A specialized version of `baseIsEqualDeep` for objects with support for\n * partial deep comparisons.\n *\n * @private\n * @param {Object} object The object to compare.\n * @param {Object} other The other object to compare.\n * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.\n * @param {Function} customizer The function to customize comparisons.\n * @param {Function} equalFunc The function to determine equivalents of values.\n * @param {Object} stack Tracks traversed `object` and `other` objects.\n * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.\n */\nfunction equalObjects(object, other, bitmask, customizer, equalFunc, stack) {\n var isPartial = bitmask & COMPARE_PARTIAL_FLAG,\n objProps = getAllKeys(object),\n objLength = objProps.length,\n othProps = getAllKeys(other),\n othLength = othProps.length;\n\n if (objLength != othLength && !isPartial) {\n return false;\n }\n var index = objLength;\n while (index--) {\n var key = objProps[index];\n if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {\n return false;\n }\n }\n // Assume cyclic values are equal.\n var stacked = stack.get(object);\n if (stacked && stack.get(other)) {\n return stacked == other;\n }\n var result = true;\n stack.set(object, other);\n stack.set(other, object);\n\n var skipCtor = isPartial;\n while (++index < objLength) {\n key = objProps[index];\n var objValue = object[key],\n othValue = other[key];\n\n if (customizer) {\n var compared = isPartial\n ? customizer(othValue, objValue, key, other, object, stack)\n : customizer(objValue, othValue, key, object, other, stack);\n }\n // Recursively compare objects (susceptible to call stack limits).\n if (!(compared === undefined\n ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))\n : compared\n )) {\n result = false;\n break;\n }\n skipCtor || (skipCtor = key == 'constructor');\n }\n if (result && !skipCtor) {\n var objCtor = object.constructor,\n othCtor = other.constructor;\n\n // Non `Object` object instances with different constructors are not equal.\n if (objCtor != othCtor &&\n ('constructor' in object && 'constructor' in other) &&\n !(typeof objCtor == 'function' && objCtor instanceof objCtor &&\n typeof othCtor == 'function' && othCtor instanceof othCtor)) {\n result = false;\n }\n }\n stack['delete'](object);\n stack['delete'](other);\n return result;\n}\n\nexport default equalObjects;\n","import getNative from './_getNative.js';\nimport root from './_root.js';\n\n/* Built-in method references that are verified to be native. */\nvar DataView = getNative(root, 'DataView');\n\nexport default DataView;\n","import getNative from './_getNative.js';\nimport root from './_root.js';\n\n/* Built-in method references that are verified to be native. */\nvar Promise = getNative(root, 'Promise');\n\nexport default Promise;\n","import getNative from './_getNative.js';\nimport root from './_root.js';\n\n/* Built-in method references that are verified to be native. */\nvar Set = getNative(root, 'Set');\n\nexport default Set;\n","import getNative from './_getNative.js';\nimport root from './_root.js';\n\n/* Built-in method references that are verified to be native. */\nvar WeakMap = getNative(root, 'WeakMap');\n\nexport default WeakMap;\n","import DataView from './_DataView.js';\nimport Map from './_Map.js';\nimport Promise from './_Promise.js';\nimport Set from './_Set.js';\nimport WeakMap from './_WeakMap.js';\nimport baseGetTag from './_baseGetTag.js';\nimport toSource from './_toSource.js';\n\n/** `Object#toString` result references. */\nvar mapTag = '[object Map]',\n objectTag = '[object Object]',\n promiseTag = '[object Promise]',\n setTag = '[object Set]',\n weakMapTag = '[object WeakMap]';\n\nvar dataViewTag = '[object DataView]';\n\n/** Used to detect maps, sets, and weakmaps. */\nvar dataViewCtorString = toSource(DataView),\n mapCtorString = toSource(Map),\n promiseCtorString = toSource(Promise),\n setCtorString = toSource(Set),\n weakMapCtorString = toSource(WeakMap);\n\n/**\n * Gets the `toStringTag` of `value`.\n *\n * @private\n * @param {*} value The value to query.\n * @returns {string} Returns the `toStringTag`.\n */\nvar getTag = baseGetTag;\n\n// Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.\nif ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||\n (Map && getTag(new Map) != mapTag) ||\n (Promise && getTag(Promise.resolve()) != promiseTag) ||\n (Set && getTag(new Set) != setTag) ||\n (WeakMap && getTag(new WeakMap) != weakMapTag)) {\n getTag = function(value) {\n var result = baseGetTag(value),\n Ctor = result == objectTag ? value.constructor : undefined,\n ctorString = Ctor ? toSource(Ctor) : '';\n\n if (ctorString) {\n switch (ctorString) {\n case dataViewCtorString: return dataViewTag;\n case mapCtorString: return mapTag;\n case promiseCtorString: return promiseTag;\n case setCtorString: return setTag;\n case weakMapCtorString: return weakMapTag;\n }\n }\n return result;\n };\n}\n\nexport default getTag;\n","import Stack from './_Stack.js';\nimport equalArrays from './_equalArrays.js';\nimport equalByTag from './_equalByTag.js';\nimport equalObjects from './_equalObjects.js';\nimport getTag from './_getTag.js';\nimport isArray from './isArray.js';\nimport isBuffer from './isBuffer.js';\nimport isTypedArray from './isTypedArray.js';\n\n/** Used to compose bitmasks for value comparisons. */\nvar COMPARE_PARTIAL_FLAG = 1;\n\n/** `Object#toString` result references. */\nvar argsTag = '[object Arguments]',\n arrayTag = '[object Array]',\n objectTag = '[object Object]';\n\n/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/** Used to check objects for own properties. */\nvar hasOwnProperty = objectProto.hasOwnProperty;\n\n/**\n * A specialized version of `baseIsEqual` for arrays and objects which performs\n * deep comparisons and tracks traversed objects enabling objects with circular\n * references to be compared.\n *\n * @private\n * @param {Object} object The object to compare.\n * @param {Object} other The other object to compare.\n * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.\n * @param {Function} customizer The function to customize comparisons.\n * @param {Function} equalFunc The function to determine equivalents of values.\n * @param {Object} [stack] Tracks traversed `object` and `other` objects.\n * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.\n */\nfunction baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {\n var objIsArr = isArray(object),\n othIsArr = isArray(other),\n objTag = objIsArr ? arrayTag : getTag(object),\n othTag = othIsArr ? arrayTag : getTag(other);\n\n objTag = objTag == argsTag ? objectTag : objTag;\n othTag = othTag == argsTag ? objectTag : othTag;\n\n var objIsObj = objTag == objectTag,\n othIsObj = othTag == objectTag,\n isSameTag = objTag == othTag;\n\n if (isSameTag && isBuffer(object)) {\n if (!isBuffer(other)) {\n return false;\n }\n objIsArr = true;\n objIsObj = false;\n }\n if (isSameTag && !objIsObj) {\n stack || (stack = new Stack);\n return (objIsArr || isTypedArray(object))\n ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)\n : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);\n }\n if (!(bitmask & COMPARE_PARTIAL_FLAG)) {\n var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),\n othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');\n\n if (objIsWrapped || othIsWrapped) {\n var objUnwrapped = objIsWrapped ? object.value() : object,\n othUnwrapped = othIsWrapped ? other.value() : other;\n\n stack || (stack = new Stack);\n return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);\n }\n }\n if (!isSameTag) {\n return false;\n }\n stack || (stack = new Stack);\n return equalObjects(object, other, bitmask, customizer, equalFunc, stack);\n}\n\nexport default baseIsEqualDeep;\n","import baseIsEqualDeep from './_baseIsEqualDeep.js';\nimport isObjectLike from './isObjectLike.js';\n\n/**\n * The base implementation of `_.isEqual` which supports partial comparisons\n * and tracks traversed objects.\n *\n * @private\n * @param {*} value The value to compare.\n * @param {*} other The other value to compare.\n * @param {boolean} bitmask The bitmask flags.\n * 1 - Unordered comparison\n * 2 - Partial comparison\n * @param {Function} [customizer] The function to customize comparisons.\n * @param {Object} [stack] Tracks traversed `value` and `other` objects.\n * @returns {boolean} Returns `true` if the values are equivalent, else `false`.\n */\nfunction baseIsEqual(value, other, bitmask, customizer, stack) {\n if (value === other) {\n return true;\n }\n if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {\n return value !== value && other !== other;\n }\n return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);\n}\n\nexport default baseIsEqual;\n","import baseIsEqual from './_baseIsEqual.js';\n\n/**\n * Performs a deep comparison between two values to determine if they are\n * equivalent.\n *\n * **Note:** This method supports comparing arrays, array buffers, booleans,\n * date objects, error objects, maps, numbers, `Object` objects, regexes,\n * sets, strings, symbols, and typed arrays. `Object` objects are compared\n * by their own, not inherited, enumerable properties. Functions and DOM\n * nodes are compared by strict equality, i.e. `===`.\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Lang\n * @param {*} value The value to compare.\n * @param {*} other The other value to compare.\n * @returns {boolean} Returns `true` if the values are equivalent, else `false`.\n * @example\n *\n * var object = { 'a': 1 };\n * var other = { 'a': 1 };\n *\n * _.isEqual(object, other);\n * // => true\n *\n * object === other;\n * // => false\n */\nfunction isEqual(value, other) {\n return baseIsEqual(value, other);\n}\n\nexport default isEqual;\n","/**\n * A specialized version of `_.map` for arrays without support for iteratee\n * shorthands.\n *\n * @private\n * @param {Array} [array] The array to iterate over.\n * @param {Function} iteratee The function invoked per iteration.\n * @returns {Array} Returns the new mapped array.\n */\nfunction arrayMap(array, iteratee) {\n var index = -1,\n length = array == null ? 0 : array.length,\n result = Array(length);\n\n while (++index < length) {\n result[index] = iteratee(array[index], index, array);\n }\n return result;\n}\n\nexport default arrayMap;\n","/**\n * A specialized version of `_.forEach` for arrays without support for\n * iteratee shorthands.\n *\n * @private\n * @param {Array} [array] The array to iterate over.\n * @param {Function} iteratee The function invoked per iteration.\n * @returns {Array} Returns `array`.\n */\nfunction arrayEach(array, iteratee) {\n var index = -1,\n length = array == null ? 0 : array.length;\n\n while (++index < length) {\n if (iteratee(array[index], index, array) === false) {\n break;\n }\n }\n return array;\n}\n\nexport default arrayEach;\n","import getNative from './_getNative.js';\n\nvar defineProperty = (function() {\n try {\n var func = getNative(Object, 'defineProperty');\n func({}, '', {});\n return func;\n } catch (e) {}\n}());\n\nexport default defineProperty;\n","import defineProperty from './_defineProperty.js';\n\n/**\n * The base implementation of `assignValue` and `assignMergeValue` without\n * value checks.\n *\n * @private\n * @param {Object} object The object to modify.\n * @param {string} key The key of the property to assign.\n * @param {*} value The value to assign.\n */\nfunction baseAssignValue(object, key, value) {\n if (key == '__proto__' && defineProperty) {\n defineProperty(object, key, {\n 'configurable': true,\n 'enumerable': true,\n 'value': value,\n 'writable': true\n });\n } else {\n object[key] = value;\n }\n}\n\nexport default baseAssignValue;\n","import baseAssignValue from './_baseAssignValue.js';\nimport eq from './eq.js';\n\n/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/** Used to check objects for own properties. */\nvar hasOwnProperty = objectProto.hasOwnProperty;\n\n/**\n * Assigns `value` to `key` of `object` if the existing value is not equivalent\n * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)\n * for equality comparisons.\n *\n * @private\n * @param {Object} object The object to modify.\n * @param {string} key The key of the property to assign.\n * @param {*} value The value to assign.\n */\nfunction assignValue(object, key, value) {\n var objValue = object[key];\n if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||\n (value === undefined && !(key in object))) {\n baseAssignValue(object, key, value);\n }\n}\n\nexport default assignValue;\n","import assignValue from './_assignValue.js';\nimport baseAssignValue from './_baseAssignValue.js';\n\n/**\n * Copies properties of `source` to `object`.\n *\n * @private\n * @param {Object} source The object to copy properties from.\n * @param {Array} props The property identifiers to copy.\n * @param {Object} [object={}] The object to copy properties to.\n * @param {Function} [customizer] The function to customize copied values.\n * @returns {Object} Returns `object`.\n */\nfunction copyObject(source, props, object, customizer) {\n var isNew = !object;\n object || (object = {});\n\n var index = -1,\n length = props.length;\n\n while (++index < length) {\n var key = props[index];\n\n var newValue = customizer\n ? customizer(object[key], source[key], key, object, source)\n : undefined;\n\n if (newValue === undefined) {\n newValue = source[key];\n }\n if (isNew) {\n baseAssignValue(object, key, newValue);\n } else {\n assignValue(object, key, newValue);\n }\n }\n return object;\n}\n\nexport default copyObject;\n","import copyObject from './_copyObject.js';\nimport keys from './keys.js';\n\n/**\n * The base implementation of `_.assign` without support for multiple sources\n * or `customizer` functions.\n *\n * @private\n * @param {Object} object The destination object.\n * @param {Object} source The source object.\n * @returns {Object} Returns `object`.\n */\nfunction baseAssign(object, source) {\n return object && copyObject(source, keys(source), object);\n}\n\nexport default baseAssign;\n","/**\n * This function is like\n * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)\n * except that it includes inherited enumerable properties.\n *\n * @private\n * @param {Object} object The object to query.\n * @returns {Array} Returns the array of property names.\n */\nfunction nativeKeysIn(object) {\n var result = [];\n if (object != null) {\n for (var key in Object(object)) {\n result.push(key);\n }\n }\n return result;\n}\n\nexport default nativeKeysIn;\n","import isObject from './isObject.js';\nimport isPrototype from './_isPrototype.js';\nimport nativeKeysIn from './_nativeKeysIn.js';\n\n/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/** Used to check objects for own properties. */\nvar hasOwnProperty = objectProto.hasOwnProperty;\n\n/**\n * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.\n *\n * @private\n * @param {Object} object The object to query.\n * @returns {Array} Returns the array of property names.\n */\nfunction baseKeysIn(object) {\n if (!isObject(object)) {\n return nativeKeysIn(object);\n }\n var isProto = isPrototype(object),\n result = [];\n\n for (var key in object) {\n if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {\n result.push(key);\n }\n }\n return result;\n}\n\nexport default baseKeysIn;\n","import arrayLikeKeys from './_arrayLikeKeys.js';\nimport baseKeysIn from './_baseKeysIn.js';\nimport isArrayLike from './isArrayLike.js';\n\n/**\n * Creates an array of the own and inherited enumerable property names of `object`.\n *\n * **Note:** Non-object values are coerced to objects.\n *\n * @static\n * @memberOf _\n * @since 3.0.0\n * @category Object\n * @param {Object} object The object to query.\n * @returns {Array} Returns the array of property names.\n * @example\n *\n * function Foo() {\n * this.a = 1;\n * this.b = 2;\n * }\n *\n * Foo.prototype.c = 3;\n *\n * _.keysIn(new Foo);\n * // => ['a', 'b', 'c'] (iteration order is not guaranteed)\n */\nfunction keysIn(object) {\n return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);\n}\n\nexport default keysIn;\n","import copyObject from './_copyObject.js';\nimport keysIn from './keysIn.js';\n\n/**\n * The base implementation of `_.assignIn` without support for multiple sources\n * or `customizer` functions.\n *\n * @private\n * @param {Object} object The destination object.\n * @param {Object} source The source object.\n * @returns {Object} Returns `object`.\n */\nfunction baseAssignIn(object, source) {\n return object && copyObject(source, keysIn(source), object);\n}\n\nexport default baseAssignIn;\n","import root from './_root.js';\n\n/** Detect free variable `exports`. */\nvar freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;\n\n/** Detect free variable `module`. */\nvar freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;\n\n/** Detect the popular CommonJS extension `module.exports`. */\nvar moduleExports = freeModule && freeModule.exports === freeExports;\n\n/** Built-in value references. */\nvar Buffer = moduleExports ? root.Buffer : undefined,\n allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined;\n\n/**\n * Creates a clone of `buffer`.\n *\n * @private\n * @param {Buffer} buffer The buffer to clone.\n * @param {boolean} [isDeep] Specify a deep clone.\n * @returns {Buffer} Returns the cloned buffer.\n */\nfunction cloneBuffer(buffer, isDeep) {\n if (isDeep) {\n return buffer.slice();\n }\n var length = buffer.length,\n result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);\n\n buffer.copy(result);\n return result;\n}\n\nexport default cloneBuffer;\n","/**\n * Copies the values of `source` to `array`.\n *\n * @private\n * @param {Array} source The array to copy values from.\n * @param {Array} [array=[]] The array to copy values to.\n * @returns {Array} Returns `array`.\n */\nfunction copyArray(source, array) {\n var index = -1,\n length = source.length;\n\n array || (array = Array(length));\n while (++index < length) {\n array[index] = source[index];\n }\n return array;\n}\n\nexport default copyArray;\n","import copyObject from './_copyObject.js';\nimport getSymbols from './_getSymbols.js';\n\n/**\n * Copies own symbols of `source` to `object`.\n *\n * @private\n * @param {Object} source The object to copy symbols from.\n * @param {Object} [object={}] The object to copy symbols to.\n * @returns {Object} Returns `object`.\n */\nfunction copySymbols(source, object) {\n return copyObject(source, getSymbols(source), object);\n}\n\nexport default copySymbols;\n","import overArg from './_overArg.js';\n\n/** Built-in value references. */\nvar getPrototype = overArg(Object.getPrototypeOf, Object);\n\nexport default getPrototype;\n","import arrayPush from './_arrayPush.js';\nimport getPrototype from './_getPrototype.js';\nimport getSymbols from './_getSymbols.js';\nimport stubArray from './stubArray.js';\n\n/* Built-in method references for those with the same name as other `lodash` methods. */\nvar nativeGetSymbols = Object.getOwnPropertySymbols;\n\n/**\n * Creates an array of the own and inherited enumerable symbols of `object`.\n *\n * @private\n * @param {Object} object The object to query.\n * @returns {Array} Returns the array of symbols.\n */\nvar getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {\n var result = [];\n while (object) {\n arrayPush(result, getSymbols(object));\n object = getPrototype(object);\n }\n return result;\n};\n\nexport default getSymbolsIn;\n","import copyObject from './_copyObject.js';\nimport getSymbolsIn from './_getSymbolsIn.js';\n\n/**\n * Copies own and inherited symbols of `source` to `object`.\n *\n * @private\n * @param {Object} source The object to copy symbols from.\n * @param {Object} [object={}] The object to copy symbols to.\n * @returns {Object} Returns `object`.\n */\nfunction copySymbolsIn(source, object) {\n return copyObject(source, getSymbolsIn(source), object);\n}\n\nexport default copySymbolsIn;\n","import baseGetAllKeys from './_baseGetAllKeys.js';\nimport getSymbolsIn from './_getSymbolsIn.js';\nimport keysIn from './keysIn.js';\n\n/**\n * Creates an array of own and inherited enumerable property names and\n * symbols of `object`.\n *\n * @private\n * @param {Object} object The object to query.\n * @returns {Array} Returns the array of property names and symbols.\n */\nfunction getAllKeysIn(object) {\n return baseGetAllKeys(object, keysIn, getSymbolsIn);\n}\n\nexport default getAllKeysIn;\n","/** Used for built-in method references. */\nvar objectProto = Object.prototype;\n\n/** Used to check objects for own properties. */\nvar hasOwnProperty = objectProto.hasOwnProperty;\n\n/**\n * Initializes an array clone.\n *\n * @private\n * @param {Array} array The array to clone.\n * @returns {Array} Returns the initialized clone.\n */\nfunction initCloneArray(array) {\n var length = array.length,\n result = new array.constructor(length);\n\n // Add properties assigned by `RegExp#exec`.\n if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {\n result.index = array.index;\n result.input = array.input;\n }\n return result;\n}\n\nexport default initCloneArray;\n","import Uint8Array from './_Uint8Array.js';\n\n/**\n * Creates a clone of `arrayBuffer`.\n *\n * @private\n * @param {ArrayBuffer} arrayBuffer The array buffer to clone.\n * @returns {ArrayBuffer} Returns the cloned array buffer.\n */\nfunction cloneArrayBuffer(arrayBuffer) {\n var result = new arrayBuffer.constructor(arrayBuffer.byteLength);\n new Uint8Array(result).set(new Uint8Array(arrayBuffer));\n return result;\n}\n\nexport default cloneArrayBuffer;\n","import cloneArrayBuffer from './_cloneArrayBuffer.js';\n\n/**\n * Creates a clone of `dataView`.\n *\n * @private\n * @param {Object} dataView The data view to clone.\n * @param {boolean} [isDeep] Specify a deep clone.\n * @returns {Object} Returns the cloned data view.\n */\nfunction cloneDataView(dataView, isDeep) {\n var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;\n return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);\n}\n\nexport default cloneDataView;\n","/** Used to match `RegExp` flags from their coerced string values. */\nvar reFlags = /\\w*$/;\n\n/**\n * Creates a clone of `regexp`.\n *\n * @private\n * @param {Object} regexp The regexp to clone.\n * @returns {Object} Returns the cloned regexp.\n */\nfunction cloneRegExp(regexp) {\n var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));\n result.lastIndex = regexp.lastIndex;\n return result;\n}\n\nexport default cloneRegExp;\n","import Symbol from './_Symbol.js';\n\n/** Used to convert symbols to primitives and strings. */\nvar symbolProto = Symbol ? Symbol.prototype : undefined,\n symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;\n\n/**\n * Creates a clone of the `symbol` object.\n *\n * @private\n * @param {Object} symbol The symbol object to clone.\n * @returns {Object} Returns the cloned symbol object.\n */\nfunction cloneSymbol(symbol) {\n return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};\n}\n\nexport default cloneSymbol;\n","import cloneArrayBuffer from './_cloneArrayBuffer.js';\n\n/**\n * Creates a clone of `typedArray`.\n *\n * @private\n * @param {Object} typedArray The typed array to clone.\n * @param {boolean} [isDeep] Specify a deep clone.\n * @returns {Object} Returns the cloned typed array.\n */\nfunction cloneTypedArray(typedArray, isDeep) {\n var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;\n return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);\n}\n\nexport default cloneTypedArray;\n","import cloneArrayBuffer from './_cloneArrayBuffer.js';\nimport cloneDataView from './_cloneDataView.js';\nimport cloneRegExp from './_cloneRegExp.js';\nimport cloneSymbol from './_cloneSymbol.js';\nimport cloneTypedArray from './_cloneTypedArray.js';\n\n/** `Object#toString` result references. */\nvar boolTag = '[object Boolean]',\n dateTag = '[object Date]',\n mapTag = '[object Map]',\n numberTag = '[object Number]',\n regexpTag = '[object RegExp]',\n setTag = '[object Set]',\n stringTag = '[object String]',\n symbolTag = '[object Symbol]';\n\nvar arrayBufferTag = '[object ArrayBuffer]',\n dataViewTag = '[object DataView]',\n float32Tag = '[object Float32Array]',\n float64Tag = '[object Float64Array]',\n int8Tag = '[object Int8Array]',\n int16Tag = '[object Int16Array]',\n int32Tag = '[object Int32Array]',\n uint8Tag = '[object Uint8Array]',\n uint8ClampedTag = '[object Uint8ClampedArray]',\n uint16Tag = '[object Uint16Array]',\n uint32Tag = '[object Uint32Array]';\n\n/**\n * Initializes an object clone based on its `toStringTag`.\n *\n * **Note:** This function only supports cloning values with tags of\n * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.\n *\n * @private\n * @param {Object} object The object to clone.\n * @param {string} tag The `toStringTag` of the object to clone.\n * @param {boolean} [isDeep] Specify a deep clone.\n * @returns {Object} Returns the initialized clone.\n */\nfunction initCloneByTag(object, tag, isDeep) {\n var Ctor = object.constructor;\n switch (tag) {\n case arrayBufferTag:\n return cloneArrayBuffer(object);\n\n case boolTag:\n case dateTag:\n return new Ctor(+object);\n\n case dataViewTag:\n return cloneDataView(object, isDeep);\n\n case float32Tag: case float64Tag:\n case int8Tag: case int16Tag: case int32Tag:\n case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:\n return cloneTypedArray(object, isDeep);\n\n case mapTag:\n return new Ctor;\n\n case numberTag:\n case stringTag:\n return new Ctor(object);\n\n case regexpTag:\n return cloneRegExp(object);\n\n case setTag:\n return new Ctor;\n\n case symbolTag:\n return cloneSymbol(object);\n }\n}\n\nexport default initCloneByTag;\n","import isObject from './isObject.js';\n\n/** Built-in value references. */\nvar objectCreate = Object.create;\n\n/**\n * The base implementation of `_.create` without support for assigning\n * properties to the created object.\n *\n * @private\n * @param {Object} proto The object to inherit from.\n * @returns {Object} Returns the new object.\n */\nvar baseCreate = (function() {\n function object() {}\n return function(proto) {\n if (!isObject(proto)) {\n return {};\n }\n if (objectCreate) {\n return objectCreate(proto);\n }\n object.prototype = proto;\n var result = new object;\n object.prototype = undefined;\n return result;\n };\n}());\n\nexport default baseCreate;\n","import baseCreate from './_baseCreate.js';\nimport getPrototype from './_getPrototype.js';\nimport isPrototype from './_isPrototype.js';\n\n/**\n * Initializes an object clone.\n *\n * @private\n * @param {Object} object The object to clone.\n * @returns {Object} Returns the initialized clone.\n */\nfunction initCloneObject(object) {\n return (typeof object.constructor == 'function' && !isPrototype(object))\n ? baseCreate(getPrototype(object))\n : {};\n}\n\nexport default initCloneObject;\n","import getTag from './_getTag.js';\nimport isObjectLike from './isObjectLike.js';\n\n/** `Object#toString` result references. */\nvar mapTag = '[object Map]';\n\n/**\n * The base implementation of `_.isMap` without Node.js optimizations.\n *\n * @private\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a map, else `false`.\n */\nfunction baseIsMap(value) {\n return isObjectLike(value) && getTag(value) == mapTag;\n}\n\nexport default baseIsMap;\n","import baseIsMap from './_baseIsMap.js';\nimport baseUnary from './_baseUnary.js';\nimport nodeUtil from './_nodeUtil.js';\n\n/* Node.js helper references. */\nvar nodeIsMap = nodeUtil && nodeUtil.isMap;\n\n/**\n * Checks if `value` is classified as a `Map` object.\n *\n * @static\n * @memberOf _\n * @since 4.3.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a map, else `false`.\n * @example\n *\n * _.isMap(new Map);\n * // => true\n *\n * _.isMap(new WeakMap);\n * // => false\n */\nvar isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;\n\nexport default isMap;\n","import getTag from './_getTag.js';\nimport isObjectLike from './isObjectLike.js';\n\n/** `Object#toString` result references. */\nvar setTag = '[object Set]';\n\n/**\n * The base implementation of `_.isSet` without Node.js optimizations.\n *\n * @private\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a set, else `false`.\n */\nfunction baseIsSet(value) {\n return isObjectLike(value) && getTag(value) == setTag;\n}\n\nexport default baseIsSet;\n","import baseIsSet from './_baseIsSet.js';\nimport baseUnary from './_baseUnary.js';\nimport nodeUtil from './_nodeUtil.js';\n\n/* Node.js helper references. */\nvar nodeIsSet = nodeUtil && nodeUtil.isSet;\n\n/**\n * Checks if `value` is classified as a `Set` object.\n *\n * @static\n * @memberOf _\n * @since 4.3.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a set, else `false`.\n * @example\n *\n * _.isSet(new Set);\n * // => true\n *\n * _.isSet(new WeakSet);\n * // => false\n */\nvar isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;\n\nexport default isSet;\n","import Stack from './_Stack.js';\nimport arrayEach from './_arrayEach.js';\nimport assignValue from './_assignValue.js';\nimport baseAssign from './_baseAssign.js';\nimport baseAssignIn from './_baseAssignIn.js';\nimport cloneBuffer from './_cloneBuffer.js';\nimport copyArray from './_copyArray.js';\nimport copySymbols from './_copySymbols.js';\nimport copySymbolsIn from './_copySymbolsIn.js';\nimport getAllKeys from './_getAllKeys.js';\nimport getAllKeysIn from './_getAllKeysIn.js';\nimport getTag from './_getTag.js';\nimport initCloneArray from './_initCloneArray.js';\nimport initCloneByTag from './_initCloneByTag.js';\nimport initCloneObject from './_initCloneObject.js';\nimport isArray from './isArray.js';\nimport isBuffer from './isBuffer.js';\nimport isMap from './isMap.js';\nimport isObject from './isObject.js';\nimport isSet from './isSet.js';\nimport keys from './keys.js';\n\n/** Used to compose bitmasks for cloning. */\nvar CLONE_DEEP_FLAG = 1,\n CLONE_FLAT_FLAG = 2,\n CLONE_SYMBOLS_FLAG = 4;\n\n/** `Object#toString` result references. */\nvar argsTag = '[object Arguments]',\n arrayTag = '[object Array]',\n boolTag = '[object Boolean]',\n dateTag = '[object Date]',\n errorTag = '[object Error]',\n funcTag = '[object Function]',\n genTag = '[object GeneratorFunction]',\n mapTag = '[object Map]',\n numberTag = '[object Number]',\n objectTag = '[object Object]',\n regexpTag = '[object RegExp]',\n setTag = '[object Set]',\n stringTag = '[object String]',\n symbolTag = '[object Symbol]',\n weakMapTag = '[object WeakMap]';\n\nvar arrayBufferTag = '[object ArrayBuffer]',\n dataViewTag = '[object DataView]',\n float32Tag = '[object Float32Array]',\n float64Tag = '[object Float64Array]',\n int8Tag = '[object Int8Array]',\n int16Tag = '[object Int16Array]',\n int32Tag = '[object Int32Array]',\n uint8Tag = '[object Uint8Array]',\n uint8ClampedTag = '[object Uint8ClampedArray]',\n uint16Tag = '[object Uint16Array]',\n uint32Tag = '[object Uint32Array]';\n\n/** Used to identify `toStringTag` values supported by `_.clone`. */\nvar cloneableTags = {};\ncloneableTags[argsTag] = cloneableTags[arrayTag] =\ncloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =\ncloneableTags[boolTag] = cloneableTags[dateTag] =\ncloneableTags[float32Tag] = cloneableTags[float64Tag] =\ncloneableTags[int8Tag] = cloneableTags[int16Tag] =\ncloneableTags[int32Tag] = cloneableTags[mapTag] =\ncloneableTags[numberTag] = cloneableTags[objectTag] =\ncloneableTags[regexpTag] = cloneableTags[setTag] =\ncloneableTags[stringTag] = cloneableTags[symbolTag] =\ncloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =\ncloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;\ncloneableTags[errorTag] = cloneableTags[funcTag] =\ncloneableTags[weakMapTag] = false;\n\n/**\n * The base implementation of `_.clone` and `_.cloneDeep` which tracks\n * traversed objects.\n *\n * @private\n * @param {*} value The value to clone.\n * @param {boolean} bitmask The bitmask flags.\n * 1 - Deep clone\n * 2 - Flatten inherited properties\n * 4 - Clone symbols\n * @param {Function} [customizer] The function to customize cloning.\n * @param {string} [key] The key of `value`.\n * @param {Object} [object] The parent object of `value`.\n * @param {Object} [stack] Tracks traversed objects and their clone counterparts.\n * @returns {*} Returns the cloned value.\n */\nfunction baseClone(value, bitmask, customizer, key, object, stack) {\n var result,\n isDeep = bitmask & CLONE_DEEP_FLAG,\n isFlat = bitmask & CLONE_FLAT_FLAG,\n isFull = bitmask & CLONE_SYMBOLS_FLAG;\n\n if (customizer) {\n result = object ? customizer(value, key, object, stack) : customizer(value);\n }\n if (result !== undefined) {\n return result;\n }\n if (!isObject(value)) {\n return value;\n }\n var isArr = isArray(value);\n if (isArr) {\n result = initCloneArray(value);\n if (!isDeep) {\n return copyArray(value, result);\n }\n } else {\n var tag = getTag(value),\n isFunc = tag == funcTag || tag == genTag;\n\n if (isBuffer(value)) {\n return cloneBuffer(value, isDeep);\n }\n if (tag == objectTag || tag == argsTag || (isFunc && !object)) {\n result = (isFlat || isFunc) ? {} : initCloneObject(value);\n if (!isDeep) {\n return isFlat\n ? copySymbolsIn(value, baseAssignIn(result, value))\n : copySymbols(value, baseAssign(result, value));\n }\n } else {\n if (!cloneableTags[tag]) {\n return object ? value : {};\n }\n result = initCloneByTag(value, tag, isDeep);\n }\n }\n // Check for circular references and return its corresponding clone.\n stack || (stack = new Stack);\n var stacked = stack.get(value);\n if (stacked) {\n return stacked;\n }\n stack.set(value, result);\n\n if (isSet(value)) {\n value.forEach(function(subValue) {\n result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));\n });\n } else if (isMap(value)) {\n value.forEach(function(subValue, key) {\n result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));\n });\n }\n\n var keysFunc = isFull\n ? (isFlat ? getAllKeysIn : getAllKeys)\n : (isFlat ? keysIn : keys);\n\n var props = isArr ? undefined : keysFunc(value);\n arrayEach(props || value, function(subValue, key) {\n if (props) {\n key = subValue;\n subValue = value[key];\n }\n // Recursively populate clone (susceptible to call stack limits).\n assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));\n });\n return result;\n}\n\nexport default baseClone;\n","import isArray from './isArray.js';\nimport isSymbol from './isSymbol.js';\n\n/** Used to match property names within property paths. */\nvar reIsDeepProp = /\\.|\\[(?:[^[\\]]*|([\"'])(?:(?!\\1)[^\\\\]|\\\\.)*?\\1)\\]/,\n reIsPlainProp = /^\\w*$/;\n\n/**\n * Checks if `value` is a property name and not a property path.\n *\n * @private\n * @param {*} value The value to check.\n * @param {Object} [object] The object to query keys on.\n * @returns {boolean} Returns `true` if `value` is a property name, else `false`.\n */\nfunction isKey(value, object) {\n if (isArray(value)) {\n return false;\n }\n var type = typeof value;\n if (type == 'number' || type == 'symbol' || type == 'boolean' ||\n value == null || isSymbol(value)) {\n return true;\n }\n return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||\n (object != null && value in Object(object));\n}\n\nexport default isKey;\n","import MapCache from './_MapCache.js';\n\n/** Error message constants. */\nvar FUNC_ERROR_TEXT = 'Expected a function';\n\n/**\n * Creates a function that memoizes the result of `func`. If `resolver` is\n * provided, it determines the cache key for storing the result based on the\n * arguments provided to the memoized function. By default, the first argument\n * provided to the memoized function is used as the map cache key. The `func`\n * is invoked with the `this` binding of the memoized function.\n *\n * **Note:** The cache is exposed as the `cache` property on the memoized\n * function. Its creation may be customized by replacing the `_.memoize.Cache`\n * constructor with one whose instances implement the\n * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)\n * method interface of `clear`, `delete`, `get`, `has`, and `set`.\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Function\n * @param {Function} func The function to have its output memoized.\n * @param {Function} [resolver] The function to resolve the cache key.\n * @returns {Function} Returns the new memoized function.\n * @example\n *\n * var object = { 'a': 1, 'b': 2 };\n * var other = { 'c': 3, 'd': 4 };\n *\n * var values = _.memoize(_.values);\n * values(object);\n * // => [1, 2]\n *\n * values(other);\n * // => [3, 4]\n *\n * object.a = 2;\n * values(object);\n * // => [1, 2]\n *\n * // Modify the result cache.\n * values.cache.set(object, ['a', 'b']);\n * values(object);\n * // => ['a', 'b']\n *\n * // Replace `_.memoize.Cache`.\n * _.memoize.Cache = WeakMap;\n */\nfunction memoize(func, resolver) {\n if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {\n throw new TypeError(FUNC_ERROR_TEXT);\n }\n var memoized = function() {\n var args = arguments,\n key = resolver ? resolver.apply(this, args) : args[0],\n cache = memoized.cache;\n\n if (cache.has(key)) {\n return cache.get(key);\n }\n var result = func.apply(this, args);\n memoized.cache = cache.set(key, result) || cache;\n return result;\n };\n memoized.cache = new (memoize.Cache || MapCache);\n return memoized;\n}\n\n// Expose `MapCache`.\nmemoize.Cache = MapCache;\n\nexport default memoize;\n","import memoize from './memoize.js';\n\n/** Used as the maximum memoize cache size. */\nvar MAX_MEMOIZE_SIZE = 500;\n\n/**\n * A specialized version of `_.memoize` which clears the memoized function's\n * cache when it exceeds `MAX_MEMOIZE_SIZE`.\n *\n * @private\n * @param {Function} func The function to have its output memoized.\n * @returns {Function} Returns the new memoized function.\n */\nfunction memoizeCapped(func) {\n var result = memoize(func, function(key) {\n if (cache.size === MAX_MEMOIZE_SIZE) {\n cache.clear();\n }\n return key;\n });\n\n var cache = result.cache;\n return result;\n}\n\nexport default memoizeCapped;\n","import memoizeCapped from './_memoizeCapped.js';\n\n/** Used to match property names within property paths. */\nvar rePropName = /[^.[\\]]+|\\[(?:(-?\\d+(?:\\.\\d+)?)|([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))/g;\n\n/** Used to match backslashes in property paths. */\nvar reEscapeChar = /\\\\(\\\\)?/g;\n\n/**\n * Converts `string` to a property path array.\n *\n * @private\n * @param {string} string The string to convert.\n * @returns {Array} Returns the property path array.\n */\nvar stringToPath = memoizeCapped(function(string) {\n var result = [];\n if (string.charCodeAt(0) === 46 /* . */) {\n result.push('');\n }\n string.replace(rePropName, function(match, number, quote, subString) {\n result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));\n });\n return result;\n});\n\nexport default stringToPath;\n","import Symbol from './_Symbol.js';\nimport arrayMap from './_arrayMap.js';\nimport isArray from './isArray.js';\nimport isSymbol from './isSymbol.js';\n\n/** Used as references for various `Number` constants. */\nvar INFINITY = 1 / 0;\n\n/** Used to convert symbols to primitives and strings. */\nvar symbolProto = Symbol ? Symbol.prototype : undefined,\n symbolToString = symbolProto ? symbolProto.toString : undefined;\n\n/**\n * The base implementation of `_.toString` which doesn't convert nullish\n * values to empty strings.\n *\n * @private\n * @param {*} value The value to process.\n * @returns {string} Returns the string.\n */\nfunction baseToString(value) {\n // Exit early for strings to avoid a performance hit in some environments.\n if (typeof value == 'string') {\n return value;\n }\n if (isArray(value)) {\n // Recursively convert values (susceptible to call stack limits).\n return arrayMap(value, baseToString) + '';\n }\n if (isSymbol(value)) {\n return symbolToString ? symbolToString.call(value) : '';\n }\n var result = (value + '');\n return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;\n}\n\nexport default baseToString;\n","import baseToString from './_baseToString.js';\n\n/**\n * Converts `value` to a string. An empty string is returned for `null`\n * and `undefined` values. The sign of `-0` is preserved.\n *\n * @static\n * @memberOf _\n * @since 4.0.0\n * @category Lang\n * @param {*} value The value to convert.\n * @returns {string} Returns the converted string.\n * @example\n *\n * _.toString(null);\n * // => ''\n *\n * _.toString(-0);\n * // => '-0'\n *\n * _.toString([1, 2, 3]);\n * // => '1,2,3'\n */\nfunction toString(value) {\n return value == null ? '' : baseToString(value);\n}\n\nexport default toString;\n","import isArray from './isArray.js';\nimport isKey from './_isKey.js';\nimport stringToPath from './_stringToPath.js';\nimport toString from './toString.js';\n\n/**\n * Casts `value` to a path array if it's not one.\n *\n * @private\n * @param {*} value The value to inspect.\n * @param {Object} [object] The object to query keys on.\n * @returns {Array} Returns the cast property path array.\n */\nfunction castPath(value, object) {\n if (isArray(value)) {\n return value;\n }\n return isKey(value, object) ? [value] : stringToPath(toString(value));\n}\n\nexport default castPath;\n","/**\n * Gets the last element of `array`.\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Array\n * @param {Array} array The array to query.\n * @returns {*} Returns the last element of `array`.\n * @example\n *\n * _.last([1, 2, 3]);\n * // => 3\n */\nfunction last(array) {\n var length = array == null ? 0 : array.length;\n return length ? array[length - 1] : undefined;\n}\n\nexport default last;\n","import isSymbol from './isSymbol.js';\n\n/** Used as references for various `Number` constants. */\nvar INFINITY = 1 / 0;\n\n/**\n * Converts `value` to a string key if it's not a string or symbol.\n *\n * @private\n * @param {*} value The value to inspect.\n * @returns {string|symbol} Returns the key.\n */\nfunction toKey(value) {\n if (typeof value == 'string' || isSymbol(value)) {\n return value;\n }\n var result = (value + '');\n return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;\n}\n\nexport default toKey;\n","import castPath from './_castPath.js';\nimport toKey from './_toKey.js';\n\n/**\n * The base implementation of `_.get` without support for default values.\n *\n * @private\n * @param {Object} object The object to query.\n * @param {Array|string} path The path of the property to get.\n * @returns {*} Returns the resolved value.\n */\nfunction baseGet(object, path) {\n path = castPath(path, object);\n\n var index = 0,\n length = path.length;\n\n while (object != null && index < length) {\n object = object[toKey(path[index++])];\n }\n return (index && index == length) ? object : undefined;\n}\n\nexport default baseGet;\n","/**\n * The base implementation of `_.slice` without an iteratee call guard.\n *\n * @private\n * @param {Array} array The array to slice.\n * @param {number} [start=0] The start position.\n * @param {number} [end=array.length] The end position.\n * @returns {Array} Returns the slice of `array`.\n */\nfunction baseSlice(array, start, end) {\n var index = -1,\n length = array.length;\n\n if (start < 0) {\n start = -start > length ? 0 : (length + start);\n }\n end = end > length ? length : end;\n if (end < 0) {\n end += length;\n }\n length = start > end ? 0 : ((end - start) >>> 0);\n start >>>= 0;\n\n var result = Array(length);\n while (++index < length) {\n result[index] = array[index + start];\n }\n return result;\n}\n\nexport default baseSlice;\n","import baseGet from './_baseGet.js';\nimport baseSlice from './_baseSlice.js';\n\n/**\n * Gets the parent value at `path` of `object`.\n *\n * @private\n * @param {Object} object The object to query.\n * @param {Array} path The path to get the parent value of.\n * @returns {*} Returns the parent value.\n */\nfunction parent(object, path) {\n return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));\n}\n\nexport default parent;\n","import castPath from './_castPath.js';\nimport last from './last.js';\nimport parent from './_parent.js';\nimport toKey from './_toKey.js';\n\n/**\n * The base implementation of `_.unset`.\n *\n * @private\n * @param {Object} object The object to modify.\n * @param {Array|string} path The property path to unset.\n * @returns {boolean} Returns `true` if the property is deleted, else `false`.\n */\nfunction baseUnset(object, path) {\n path = castPath(path, object);\n object = parent(object, path);\n return object == null || delete object[toKey(last(path))];\n}\n\nexport default baseUnset;\n","import baseGetTag from './_baseGetTag.js';\nimport getPrototype from './_getPrototype.js';\nimport isObjectLike from './isObjectLike.js';\n\n/** `Object#toString` result references. */\nvar objectTag = '[object Object]';\n\n/** Used for built-in method references. */\nvar funcProto = Function.prototype,\n objectProto = Object.prototype;\n\n/** Used to resolve the decompiled source of functions. */\nvar funcToString = funcProto.toString;\n\n/** Used to check objects for own properties. */\nvar hasOwnProperty = objectProto.hasOwnProperty;\n\n/** Used to infer the `Object` constructor. */\nvar objectCtorString = funcToString.call(Object);\n\n/**\n * Checks if `value` is a plain object, that is, an object created by the\n * `Object` constructor or one with a `[[Prototype]]` of `null`.\n *\n * @static\n * @memberOf _\n * @since 0.8.0\n * @category Lang\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.\n * @example\n *\n * function Foo() {\n * this.a = 1;\n * }\n *\n * _.isPlainObject(new Foo);\n * // => false\n *\n * _.isPlainObject([1, 2, 3]);\n * // => false\n *\n * _.isPlainObject({ 'x': 0, 'y': 0 });\n * // => true\n *\n * _.isPlainObject(Object.create(null));\n * // => true\n */\nfunction isPlainObject(value) {\n if (!isObjectLike(value) || baseGetTag(value) != objectTag) {\n return false;\n }\n var proto = getPrototype(value);\n if (proto === null) {\n return true;\n }\n var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;\n return typeof Ctor == 'function' && Ctor instanceof Ctor &&\n funcToString.call(Ctor) == objectCtorString;\n}\n\nexport default isPlainObject;\n","import isPlainObject from './isPlainObject.js';\n\n/**\n * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain\n * objects.\n *\n * @private\n * @param {*} value The value to inspect.\n * @param {string} key The key of the property to inspect.\n * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.\n */\nfunction customOmitClone(value) {\n return isPlainObject(value) ? undefined : value;\n}\n\nexport default customOmitClone;\n","import Symbol from './_Symbol.js';\nimport isArguments from './isArguments.js';\nimport isArray from './isArray.js';\n\n/** Built-in value references. */\nvar spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined;\n\n/**\n * Checks if `value` is a flattenable `arguments` object or array.\n *\n * @private\n * @param {*} value The value to check.\n * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.\n */\nfunction isFlattenable(value) {\n return isArray(value) || isArguments(value) ||\n !!(spreadableSymbol && value && value[spreadableSymbol]);\n}\n\nexport default isFlattenable;\n","import arrayPush from './_arrayPush.js';\nimport isFlattenable from './_isFlattenable.js';\n\n/**\n * The base implementation of `_.flatten` with support for restricting flattening.\n *\n * @private\n * @param {Array} array The array to flatten.\n * @param {number} depth The maximum recursion depth.\n * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.\n * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.\n * @param {Array} [result=[]] The initial result value.\n * @returns {Array} Returns the new flattened array.\n */\nfunction baseFlatten(array, depth, predicate, isStrict, result) {\n var index = -1,\n length = array.length;\n\n predicate || (predicate = isFlattenable);\n result || (result = []);\n\n while (++index < length) {\n var value = array[index];\n if (depth > 0 && predicate(value)) {\n if (depth > 1) {\n // Recursively flatten arrays (susceptible to call stack limits).\n baseFlatten(value, depth - 1, predicate, isStrict, result);\n } else {\n arrayPush(result, value);\n }\n } else if (!isStrict) {\n result[result.length] = value;\n }\n }\n return result;\n}\n\nexport default baseFlatten;\n","import baseFlatten from './_baseFlatten.js';\n\n/**\n * Flattens `array` a single level deep.\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @category Array\n * @param {Array} array The array to flatten.\n * @returns {Array} Returns the new flattened array.\n * @example\n *\n * _.flatten([1, [2, [3, [4]], 5]]);\n * // => [1, 2, [3, [4]], 5]\n */\nfunction flatten(array) {\n var length = array == null ? 0 : array.length;\n return length ? baseFlatten(array, 1) : [];\n}\n\nexport default flatten;\n","/**\n * A faster alternative to `Function#apply`, this function invokes `func`\n * with the `this` binding of `thisArg` and the arguments of `args`.\n *\n * @private\n * @param {Function} func The function to invoke.\n * @param {*} thisArg The `this` binding of `func`.\n * @param {Array} args The arguments to invoke `func` with.\n * @returns {*} Returns the result of `func`.\n */\nfunction apply(func, thisArg, args) {\n switch (args.length) {\n case 0: return func.call(thisArg);\n case 1: return func.call(thisArg, args[0]);\n case 2: return func.call(thisArg, args[0], args[1]);\n case 3: return func.call(thisArg, args[0], args[1], args[2]);\n }\n return func.apply(thisArg, args);\n}\n\nexport default apply;\n","import apply from './_apply.js';\n\n/* Built-in method references for those with the same name as other `lodash` methods. */\nvar nativeMax = Math.max;\n\n/**\n * A specialized version of `baseRest` which transforms the rest array.\n *\n * @private\n * @param {Function} func The function to apply a rest parameter to.\n * @param {number} [start=func.length-1] The start position of the rest parameter.\n * @param {Function} transform The rest array transform.\n * @returns {Function} Returns the new function.\n */\nfunction overRest(func, start, transform) {\n start = nativeMax(start === undefined ? (func.length - 1) : start, 0);\n return function() {\n var args = arguments,\n index = -1,\n length = nativeMax(args.length - start, 0),\n array = Array(length);\n\n while (++index < length) {\n array[index] = args[start + index];\n }\n index = -1;\n var otherArgs = Array(start + 1);\n while (++index < start) {\n otherArgs[index] = args[index];\n }\n otherArgs[start] = transform(array);\n return apply(func, this, otherArgs);\n };\n}\n\nexport default overRest;\n","/**\n * Creates a function that returns `value`.\n *\n * @static\n * @memberOf _\n * @since 2.4.0\n * @category Util\n * @param {*} value The value to return from the new function.\n * @returns {Function} Returns the new constant function.\n * @example\n *\n * var objects = _.times(2, _.constant({ 'a': 1 }));\n *\n * console.log(objects);\n * // => [{ 'a': 1 }, { 'a': 1 }]\n *\n * console.log(objects[0] === objects[1]);\n * // => true\n */\nfunction constant(value) {\n return function() {\n return value;\n };\n}\n\nexport default constant;\n","/**\n * This method returns the first argument it receives.\n *\n * @static\n * @since 0.1.0\n * @memberOf _\n * @category Util\n * @param {*} value Any value.\n * @returns {*} Returns `value`.\n * @example\n *\n * var object = { 'a': 1 };\n *\n * console.log(_.identity(object) === object);\n * // => true\n */\nfunction identity(value) {\n return value;\n}\n\nexport default identity;\n","import constant from './constant.js';\nimport defineProperty from './_defineProperty.js';\nimport identity from './identity.js';\n\n/**\n * The base implementation of `setToString` without support for hot loop shorting.\n *\n * @private\n * @param {Function} func The function to modify.\n * @param {Function} string The `toString` result.\n * @returns {Function} Returns `func`.\n */\nvar baseSetToString = !defineProperty ? identity : function(func, string) {\n return defineProperty(func, 'toString', {\n 'configurable': true,\n 'enumerable': false,\n 'value': constant(string),\n 'writable': true\n });\n};\n\nexport default baseSetToString;\n","/** Used to detect hot functions by number of calls within a span of milliseconds. */\nvar HOT_COUNT = 800,\n HOT_SPAN = 16;\n\n/* Built-in method references for those with the same name as other `lodash` methods. */\nvar nativeNow = Date.now;\n\n/**\n * Creates a function that'll short out and invoke `identity` instead\n * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`\n * milliseconds.\n *\n * @private\n * @param {Function} func The function to restrict.\n * @returns {Function} Returns the new shortable function.\n */\nfunction shortOut(func) {\n var count = 0,\n lastCalled = 0;\n\n return function() {\n var stamp = nativeNow(),\n remaining = HOT_SPAN - (stamp - lastCalled);\n\n lastCalled = stamp;\n if (remaining > 0) {\n if (++count >= HOT_COUNT) {\n return arguments[0];\n }\n } else {\n count = 0;\n }\n return func.apply(undefined, arguments);\n };\n}\n\nexport default shortOut;\n","import baseSetToString from './_baseSetToString.js';\nimport shortOut from './_shortOut.js';\n\n/**\n * Sets the `toString` method of `func` to return `string`.\n *\n * @private\n * @param {Function} func The function to modify.\n * @param {Function} string The `toString` result.\n * @returns {Function} Returns `func`.\n */\nvar setToString = shortOut(baseSetToString);\n\nexport default setToString;\n","import flatten from './flatten.js';\nimport overRest from './_overRest.js';\nimport setToString from './_setToString.js';\n\n/**\n * A specialized version of `baseRest` which flattens the rest array.\n *\n * @private\n * @param {Function} func The function to apply a rest parameter to.\n * @returns {Function} Returns the new function.\n */\nfunction flatRest(func) {\n return setToString(overRest(func, undefined, flatten), func + '');\n}\n\nexport default flatRest;\n","import arrayMap from './_arrayMap.js';\nimport baseClone from './_baseClone.js';\nimport baseUnset from './_baseUnset.js';\nimport castPath from './_castPath.js';\nimport copyObject from './_copyObject.js';\nimport customOmitClone from './_customOmitClone.js';\nimport flatRest from './_flatRest.js';\nimport getAllKeysIn from './_getAllKeysIn.js';\n\n/** Used to compose bitmasks for cloning. */\nvar CLONE_DEEP_FLAG = 1,\n CLONE_FLAT_FLAG = 2,\n CLONE_SYMBOLS_FLAG = 4;\n\n/**\n * The opposite of `_.pick`; this method creates an object composed of the\n * own and inherited enumerable property paths of `object` that are not omitted.\n *\n * **Note:** This method is considerably slower than `_.pick`.\n *\n * @static\n * @since 0.1.0\n * @memberOf _\n * @category Object\n * @param {Object} object The source object.\n * @param {...(string|string[])} [paths] The property paths to omit.\n * @returns {Object} Returns the new object.\n * @example\n *\n * var object = { 'a': 1, 'b': '2', 'c': 3 };\n *\n * _.omit(object, ['a', 'c']);\n * // => { 'b': '2' }\n */\nvar omit = flatRest(function(object, paths) {\n var result = {};\n if (object == null) {\n return result;\n }\n var isDeep = false;\n paths = arrayMap(paths, function(path) {\n path = castPath(path, object);\n isDeep || (isDeep = path.length > 1);\n return path;\n });\n copyObject(object, getAllKeysIn(object), result);\n if (isDeep) {\n result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);\n }\n var length = paths.length;\n while (length--) {\n baseUnset(result, paths[length]);\n }\n return result;\n});\n\nexport default omit;\n","import deepEqual from 'fast-deep-equal';\nimport { range as d3_range } from 'd3-array';\n\nimport {\n svgMarkerSegments, svgPath, svgRelationMemberTags, svgSegmentWay\n} from './helpers';\nimport { svgTagClasses } from './tag_classes';\n\nimport { osmEntity, osmOldMultipolygonOuterMember } from '../osm';\nimport { utilArrayFlatten, utilArrayGroupBy } from '../util';\nimport { utilDetect } from '../util/detect';\nimport _isEqual from 'lodash-es/isEqual';\nimport _omit from 'lodash-es/omit';\nimport { rapid_config } from '../../data/rapid_config.json';\n\nexport function svgLines(projection, context) {\n var detected = utilDetect();\n\n var highway_stack = {\n motorway: 0,\n motorway_link: 1,\n trunk: 2,\n trunk_link: 3,\n primary: 4,\n primary_link: 5,\n secondary: 6,\n tertiary: 7,\n unclassified: 8,\n residential: 9,\n service: 10,\n footway: 11\n };\n\n function drawTargets(selection, graph, entities, filter) {\n var targetClass = context.getDebug('target') ? 'pink ' : 'nocolor ';\n var nopeClass = context.getDebug('target') ? 'red ' : 'nocolor ';\n var getPath = svgPath(projection).geojson;\n var activeID = context.activeID();\n var base = context.history().base();\n\n // The targets and nopes will be MultiLineString sub-segments of the ways\n var data = { targets: [], nopes: [] };\n\n entities.forEach(function(way) {\n var features = svgSegmentWay(way, graph, activeID);\n data.targets.push.apply(data.targets, features.passive);\n data.nopes.push.apply(data.nopes, features.active);\n });\n\n\n // Targets allow hover and vertex snapping\n var targetData = data.targets.filter(getPath);\n var targets = selection.selectAll('.line.target-allowed')\n .filter(function(d) { return filter(d.properties.entity); })\n .data(targetData, function key(d) { return d.id; });\n\n // exit\n targets.exit()\n .remove();\n\n var segmentWasEdited = function(d) {\n var wayID = d.properties.entity.id;\n // if the whole line was edited, don't draw segment changes\n if (!base.entities[wayID] ||\n !deepEqual(graph.entities[wayID].nodes, base.entities[wayID].nodes)) {\n return false;\n }\n return d.properties.nodes.some(function(n) {\n return !base.entities[n.id] ||\n !deepEqual(graph.entities[n.id].loc, base.entities[n.id].loc);\n });\n };\n\n // enter/update\n targets.enter()\n .append('path')\n .merge(targets)\n .attr('d', getPath)\n .attr('class', function(d) {\n return 'way line target target-allowed ' + targetClass + d.id;\n })\n .classed('segment-edited', segmentWasEdited);\n\n // NOPE\n var nopeData = data.nopes.filter(getPath);\n var nopes = selection.selectAll('.line.target-nope')\n .filter(function(d) { return filter(d.properties.entity); })\n .data(nopeData, function key(d) { return d.id; });\n\n // exit\n nopes.exit()\n .remove();\n\n // enter/update\n nopes.enter()\n .append('path')\n .merge(nopes)\n .attr('d', getPath)\n .attr('class', function(d) {\n return 'way line target target-nope ' + nopeClass + d.id;\n })\n .classed('segment-edited', segmentWasEdited);\n }\n\n\n function drawLines(selection, graph, entities, filter) {\n var base = context.history().base();\n\n function waystack(a, b) {\n var selected = context.selectedIDs();\n var scoreA = selected.indexOf(a.id) !== -1 ? 20 : 0;\n var scoreB = selected.indexOf(b.id) !== -1 ? 20 : 0;\n\n if (a.tags.highway) { scoreA -= highway_stack[a.tags.highway]; }\n if (b.tags.highway) { scoreB -= highway_stack[b.tags.highway]; }\n return scoreA - scoreB;\n }\n\n var getAIRoadStylingClass = function(d){\n if (!rapid_config.style_fb_ai_roads.enabled) return '';\n\n return (d.tags.source === 'digitalglobe' || d.tags.source === 'maxar') ? ' airoad ' : '';\n };\n\n // Class for styling currently edited lines\n var tagEditClass = function(d) {\n var result = graph.entities[d.id] && base.entities[d.id] && !_isEqual(graph.entities[d.id].tags, base.entities[d.id].tags);\n\n return result ?\n ' tagedited ' : '';\n };\n\n // Class for styling currently edited lines\n var graphEditClass = function(d) {\n if (!base.entities[d.id]) {\n return ' graphedited ';\n }\n\n var result = graph.entities[d.id] && base.entities[d.id] && !_isEqual(_omit(graph.entities[d.id], ['tags', 'v']), _omit(base.entities[d.id], ['tags', 'v']));\n\n return result ? ' graphedited ' : '';\n };\n\n function drawLineGroup(selection, klass, isSelected) {\n // Note: Don't add `.selected` class in draw modes\n var mode = context.mode();\n var isDrawing = mode && /^draw/.test(mode.id);\n var selectedClass = (!isDrawing && isSelected) ? 'selected ' : '';\n\n var lines = selection\n .selectAll('path')\n .filter(filter)\n .data(getPathData(isSelected), osmEntity.key);\n\n lines.exit()\n .remove();\n\n // Optimization: Call expensive TagClasses only on enter selection. This\n // works because osmEntity.key is defined to include the entity v attribute.\n lines.enter()\n .append('path')\n .attr('class', function(d) {\n\n var prefix = 'way line';\n\n // if this line isn't styled by its own tags\n if (!d.hasInterestingTags()) {\n\n var parentRelations = graph.parentRelations(d);\n var parentMultipolygons = parentRelations.filter(function(relation) {\n return relation.isMultipolygon();\n });\n\n // and if it's a member of at least one multipolygon relation\n if (parentMultipolygons.length > 0 &&\n // and only multipolygon relations\n parentRelations.length === parentMultipolygons.length) {\n // then fudge the classes to style this as an area edge\n prefix = 'relation area';\n }\n }\n\n var oldMPClass = oldMultiPolygonOuters[d.id] ? 'old-multipolygon ' : '';\n return prefix + ' ' + klass + ' ' + selectedClass + oldMPClass + graphEditClass(d) + tagEditClass(d) + getAIRoadStylingClass(d) + d.id;\n })\n .classed('added', function(d) {\n return !base.entities[d.id];\n })\n .classed('geometry-edited', function(d) {\n return graph.entities[d.id] &&\n base.entities[d.id] &&\n !deepEqual(graph.entities[d.id].nodes, base.entities[d.id].nodes);\n })\n .classed('retagged', function(d) {\n return graph.entities[d.id] &&\n base.entities[d.id] &&\n !deepEqual(graph.entities[d.id].tags, base.entities[d.id].tags);\n })\n .call(svgTagClasses())\n .merge(lines)\n .sort(waystack)\n .attr('d', getPath)\n .call(svgTagClasses().tags(svgRelationMemberTags(graph)));\n\n return selection;\n }\n\n\n function getPathData(isSelected) {\n return function() {\n var layer = this.parentNode.__data__;\n var data = pathdata[layer] || [];\n return data.filter(function(d) {\n if (isSelected)\n return context.selectedIDs().indexOf(d.id) !== -1;\n else\n return context.selectedIDs().indexOf(d.id) === -1;\n });\n };\n }\n\n function addMarkers(layergroup, pathclass, groupclass, groupdata, marker) {\n var markergroup = layergroup\n .selectAll('g.' + groupclass)\n .data([pathclass]);\n\n markergroup = markergroup.enter()\n .append('g')\n .attr('class', groupclass)\n .merge(markergroup);\n\n var markers = markergroup\n .selectAll('path')\n .filter(filter)\n .data(\n function data() { return groupdata[this.parentNode.__data__] || []; },\n function key(d) { return [d.id, d.index]; }\n );\n\n markers.exit()\n .remove();\n\n markers = markers.enter()\n .append('path')\n .attr('class', pathclass)\n .merge(markers)\n .attr('marker-mid', marker)\n .attr('d', function(d) { return d.d; });\n\n if (detected.ie) {\n markers.each(function() { this.parentNode.insertBefore(this, this); });\n }\n }\n\n\n var getPath = svgPath(projection, graph);\n var ways = [];\n var onewaydata = {};\n var sideddata = {};\n var oldMultiPolygonOuters = {};\n\n for (var i = 0; i < entities.length; i++) {\n var entity = entities[i];\n var outer = osmOldMultipolygonOuterMember(entity, graph);\n if (outer) {\n ways.push(entity.mergeTags(outer.tags));\n oldMultiPolygonOuters[outer.id] = true;\n } else if (entity.geometry(graph) === 'line') {\n ways.push(entity);\n }\n }\n\n ways = ways.filter(getPath);\n var pathdata = utilArrayGroupBy(ways, function(way) { return way.layer(); });\n\n Object.keys(pathdata).forEach(function(k) {\n var v = pathdata[k];\n var onewayArr = v.filter(function(d) { return d.isOneWay(); });\n var onewaySegments = svgMarkerSegments(\n projection, graph, 35,\n function shouldReverse(entity) { return entity.tags.oneway === '-1'; },\n function bothDirections(entity) {\n return entity.tags.oneway === 'reversible' || entity.tags.oneway === 'alternating';\n }\n );\n onewaydata[k] = utilArrayFlatten(onewayArr.map(onewaySegments));\n\n var sidedArr = v.filter(function(d) { return d.isSided(); });\n var sidedSegments = svgMarkerSegments(\n projection, graph, 30,\n function shouldReverse() { return false; },\n function bothDirections() { return false; }\n );\n sideddata[k] = utilArrayFlatten(sidedArr.map(sidedSegments));\n });\n\n\n var covered = selection.selectAll('.layer-osm.covered'); // under areas\n var uncovered = selection.selectAll('.layer-osm.lines'); // over areas\n var touchLayer = selection.selectAll('.layer-touch.lines');\n\n // Draw lines..\n [covered, uncovered].forEach(function(selection) {\n var range = (selection === covered ? d3_range(-10,0) : d3_range(0,11));\n var layergroup = selection\n .selectAll('g.layergroup')\n .data(range);\n\n layergroup = layergroup.enter()\n .append('g')\n .attr('class', function(d) { return 'layergroup layer' + String(d); })\n .merge(layergroup);\n\n layergroup\n .selectAll('g.linegroup')\n .data(['shadow', 'casing', 'stroke', 'shadow-highlighted', 'casing-highlighted', 'stroke-highlighted'])\n .enter()\n .append('g')\n .attr('class', function(d) { return 'linegroup line-' + d; });\n\n layergroup.selectAll('g.line-shadow')\n .call(drawLineGroup, 'shadow', false);\n layergroup.selectAll('g.line-casing')\n .call(drawLineGroup, 'casing', false);\n layergroup.selectAll('g.line-stroke')\n .call(drawLineGroup, 'stroke', false);\n\n layergroup.selectAll('g.line-shadow-highlighted')\n .call(drawLineGroup, 'shadow', true);\n layergroup.selectAll('g.line-casing-highlighted')\n .call(drawLineGroup, 'casing', true);\n layergroup.selectAll('g.line-stroke-highlighted')\n .call(drawLineGroup, 'stroke', true);\n\n addMarkers(layergroup, 'oneway', 'onewaygroup', onewaydata, 'url(#ideditor-oneway-marker)');\n addMarkers(layergroup, 'sided', 'sidedgroup', sideddata,\n function marker(d) {\n var category = graph.entity(d.id).sidednessIdentifier();\n return 'url(#ideditor-sided-marker-' + category + ')';\n }\n );\n });\n\n // Draw touch targets..\n touchLayer\n .call(drawTargets, graph, ways, filter);\n }\n\n\n return drawLines;\n}\n","import { svgPointTransform } from './helpers';\nimport { svgTagClasses } from './tag_classes';\nimport { geoAngle, geoLineIntersection, geoVecInterp, geoVecLength } from '../geo';\n\n\nexport function svgMidpoints(projection, context) {\n var targetRadius = 8;\n\n function drawTargets(selection, graph, entities, filter) {\n var fillClass = context.getDebug('target') ? 'pink ' : 'nocolor ';\n var getTransform = svgPointTransform(projection).geojson;\n\n var data = entities.map(function(midpoint) {\n return {\n type: 'Feature',\n id: midpoint.id,\n properties: {\n target: true,\n entity: midpoint\n },\n geometry: {\n type: 'Point',\n coordinates: midpoint.loc\n }\n };\n });\n\n var targets = selection.selectAll('.midpoint.target')\n .filter(function(d) { return filter(d.properties.entity); })\n .data(data, function key(d) { return d.id; });\n\n // exit\n targets.exit()\n .remove();\n\n // enter/update\n targets.enter()\n .append('circle')\n .attr('r', targetRadius)\n .merge(targets)\n .attr('class', function(d) { return 'node midpoint target ' + fillClass + d.id; })\n .attr('transform', getTransform);\n }\n\n\n function drawMidpoints(selection, graph, entities, filter, extent) {\n var drawLayer = selection.selectAll('.layer-osm.points .points-group.midpoints');\n var touchLayer = selection.selectAll('.layer-touch.points');\n\n var mode = context.mode();\n if ((mode && mode.id !== 'select') || !context.map().withinEditableZoom()) {\n drawLayer.selectAll('.midpoint').remove();\n touchLayer.selectAll('.midpoint.target').remove();\n return;\n }\n\n var poly = extent.polygon();\n var midpoints = {};\n\n for (var i = 0; i < entities.length; i++) {\n var entity = entities[i];\n\n if (entity.type !== 'way') continue;\n if (!filter(entity)) continue;\n if (context.selectedIDs().indexOf(entity.id) < 0) continue;\n\n var nodes = graph.childNodes(entity);\n for (var j = 0; j < nodes.length - 1; j++) {\n var a = nodes[j];\n var b = nodes[j + 1];\n var id = [a.id, b.id].sort().join('-');\n\n if (midpoints[id]) {\n midpoints[id].parents.push(entity);\n } else if (geoVecLength(projection(a.loc), projection(b.loc)) > 40) {\n var point = geoVecInterp(a.loc, b.loc, 0.5);\n var loc = null;\n\n if (extent.intersects(point)) {\n loc = point;\n } else {\n for (var k = 0; k < 4; k++) {\n point = geoLineIntersection([a.loc, b.loc], [poly[k], poly[k + 1]]);\n if (point &&\n geoVecLength(projection(a.loc), projection(point)) > 20 &&\n geoVecLength(projection(b.loc), projection(point)) > 20)\n {\n loc = point;\n break;\n }\n }\n }\n\n if (loc) {\n midpoints[id] = {\n type: 'midpoint',\n id: id,\n loc: loc,\n edge: [a.id, b.id],\n parents: [entity]\n };\n }\n }\n }\n }\n\n\n function midpointFilter(d) {\n if (midpoints[d.id])\n return true;\n\n for (var i = 0; i < d.parents.length; i++) {\n if (filter(d.parents[i])) {\n return true;\n }\n }\n\n return false;\n }\n\n\n var groups = drawLayer.selectAll('.midpoint')\n .filter(midpointFilter)\n .data(Object.values(midpoints), function(d) { return d.id; });\n\n groups.exit()\n .remove();\n\n var enter = groups.enter()\n .insert('g', ':first-child')\n .attr('class', 'midpoint');\n\n enter\n .append('polygon')\n .attr('points', '-6,8 10,0 -6,-8')\n .attr('class', 'shadow');\n\n enter\n .append('polygon')\n .attr('points', '-3,4 5,0 -3,-4')\n .attr('class', 'fill');\n\n groups = groups\n .merge(enter)\n .attr('transform', function(d) {\n var translate = svgPointTransform(projection);\n var a = graph.entity(d.edge[0]);\n var b = graph.entity(d.edge[1]);\n var angle = geoAngle(a, b, projection) * (180 / Math.PI);\n return translate(d) + ' rotate(' + angle + ')';\n })\n .call(svgTagClasses().tags(\n function(d) { return d.parents[0].tags; }\n ));\n\n // Propagate data bindings.\n groups.select('polygon.shadow');\n groups.select('polygon.fill');\n\n\n // Draw touch targets..\n touchLayer\n .call(drawTargets, graph, Object.values(midpoints), midpointFilter);\n }\n\n return drawMidpoints;\n}\n","import deepEqual from 'fast-deep-equal';\nimport { geoScaleToZoom } from '../geo';\nimport { osmEntity } from '../osm';\nimport { svgPointTransform } from './helpers';\nimport { svgTagClasses } from './tag_classes';\nimport { presetManager } from '../presets';\n\nexport function svgPoints(projection, context) {\n\n function markerPath(selection, klass) {\n selection\n .attr('class', klass)\n .attr('transform', 'translate(-8, -23)')\n .attr('d', 'M 17,8 C 17,13 11,21 8.5,23.5 C 6,21 0,13 0,8 C 0,4 4,-0.5 8.5,-0.5 C 13,-0.5 17,4 17,8 z');\n }\n\n function sortY(a, b) {\n return b.loc[1] - a.loc[1];\n }\n\n\n // Avoid exit/enter if we're just moving stuff around.\n // The node will get a new version but we only need to run the update selection.\n function fastEntityKey(d) {\n var mode = context.mode();\n var isMoving = mode && /^(add|draw|drag|move|rotate)/.test(mode.id);\n return isMoving ? d.id : osmEntity.key(d);\n }\n\n\n function drawTargets(selection, graph, entities, filter) {\n var fillClass = context.getDebug('target') ? 'pink ' : 'nocolor ';\n var getTransform = svgPointTransform(projection).geojson;\n var activeID = context.activeID();\n var data = [];\n\n entities.forEach(function(node) {\n if (activeID === node.id) return; // draw no target on the activeID\n\n data.push({\n type: 'Feature',\n id: node.id,\n properties: {\n target: true,\n entity: node\n },\n geometry: node.asGeoJSON()\n });\n });\n\n var targets = selection.selectAll('.point.target')\n .filter(function(d) { return filter(d.properties.entity); })\n .data(data, function key(d) { return d.id; });\n\n // exit\n targets.exit()\n .remove();\n\n // enter/update\n targets.enter()\n .append('rect')\n .attr('x', -10)\n .attr('y', -26)\n .attr('width', 20)\n .attr('height', 30)\n .merge(targets)\n .attr('class', function(d) { return 'node point target ' + fillClass + d.id; })\n .attr('transform', getTransform);\n }\n\n\n function drawPoints(selection, graph, entities, filter) {\n var wireframe = context.surface().classed('fill-wireframe');\n var zoom = geoScaleToZoom(projection.scale());\n var base = context.history().base();\n\n // Points with a direction will render as vertices at higher zooms..\n function renderAsPoint(entity) {\n return entity.geometry(graph) === 'point' &&\n !(zoom >= 18 && entity.directions(graph, projection).length);\n }\n\n // All points will render as vertices in wireframe mode too..\n var points = wireframe ? [] : entities.filter(renderAsPoint);\n points.sort(sortY);\n\n\n var drawLayer = selection.selectAll('.layer-osm.points .points-group.points');\n var touchLayer = selection.selectAll('.layer-touch.points');\n\n // Draw points..\n var groups = drawLayer.selectAll('g.point')\n .filter(filter)\n .data(points, fastEntityKey);\n\n groups.exit()\n .remove();\n\n var enter = groups.enter()\n .append('g')\n .attr('class', function(d) { return 'node point ' + d.id; })\n .order();\n\n enter\n .append('path')\n .call(markerPath, 'shadow');\n\n enter\n .append('ellipse')\n .attr('cx', 0.5)\n .attr('cy', 1)\n .attr('rx', 6.5)\n .attr('ry', 3)\n .attr('class', 'stroke');\n\n enter\n .append('path')\n .call(markerPath, 'stroke');\n\n enter\n .append('use')\n .attr('transform', 'translate(-5, -19)')\n .attr('class', 'icon')\n .attr('width', '11px')\n .attr('height', '11px');\n\n groups = groups\n .merge(enter)\n .attr('transform', svgPointTransform(projection))\n .classed('added', function(d) {\n return !base.entities[d.id]; // if it doesn't exist in the base graph, it's new\n })\n .classed('moved', function(d) {\n return base.entities[d.id] && !deepEqual(graph.entities[d.id].loc, base.entities[d.id].loc);\n })\n .classed('retagged', function(d) {\n return base.entities[d.id] && !deepEqual(graph.entities[d.id].tags, base.entities[d.id].tags);\n })\n .call(svgTagClasses());\n\n groups.select('.shadow'); // propagate bound data\n groups.select('.stroke'); // propagate bound data\n groups.select('.icon') // propagate bound data\n .attr('xlink:href', function(entity) {\n var preset = presetManager.match(entity, graph);\n var picon = preset && preset.icon;\n\n if (!picon) {\n return '';\n } else {\n var isMaki = /^maki-/.test(picon);\n return '#' + picon + (isMaki ? '-11' : '');\n }\n });\n\n\n // Draw touch targets..\n touchLayer\n .call(drawTargets, graph, points, filter);\n }\n\n\n return drawPoints;\n}\n","import { geoAngle, geoPathLength } from '../geo';\n\n\nexport function svgTurns(projection, context) {\n\n function icon(turn) {\n var u = turn.u ? '-u' : '';\n if (turn.no) return '#iD-turn-no' + u;\n if (turn.only) return '#iD-turn-only' + u;\n return '#iD-turn-yes' + u;\n }\n\n function drawTurns(selection, graph, turns) {\n\n function turnTransform(d) {\n var pxRadius = 50;\n var toWay = graph.entity(d.to.way);\n var toPoints = graph.childNodes(toWay)\n .map(function (n) { return n.loc; })\n .map(projection);\n var toLength = geoPathLength(toPoints);\n var mid = toLength / 2; // midpoint of destination way\n\n var toNode = graph.entity(d.to.node);\n var toVertex = graph.entity(d.to.vertex);\n var a = geoAngle(toVertex, toNode, projection);\n var o = projection(toVertex.loc);\n var r = d.u ? 0 // u-turn: no radius\n : !toWay.__via ? pxRadius // leaf way: put marker at pxRadius\n : Math.min(mid, pxRadius); // via way: prefer pxRadius, fallback to mid for very short ways\n\n return 'translate(' + (r * Math.cos(a) + o[0]) + ',' + (r * Math.sin(a) + o[1]) + ') ' +\n 'rotate(' + a * 180 / Math.PI + ')';\n }\n\n\n var drawLayer = selection.selectAll('.layer-osm.points .points-group.turns');\n var touchLayer = selection.selectAll('.layer-touch.turns');\n\n // Draw turns..\n var groups = drawLayer.selectAll('g.turn')\n .data(turns, function(d) { return d.key; });\n\n // exit\n groups.exit()\n .remove();\n\n // enter\n var groupsEnter = groups.enter()\n .append('g')\n .attr('class', function(d) { return 'turn ' + d.key; });\n\n var turnsEnter = groupsEnter\n .filter(function(d) { return !d.u; });\n\n turnsEnter.append('rect')\n .attr('transform', 'translate(-22, -12)')\n .attr('width', '44')\n .attr('height', '24');\n\n turnsEnter.append('use')\n .attr('transform', 'translate(-22, -12)')\n .attr('width', '44')\n .attr('height', '24');\n\n var uEnter = groupsEnter\n .filter(function(d) { return d.u; });\n\n uEnter.append('circle')\n .attr('r', '16');\n\n uEnter.append('use')\n .attr('transform', 'translate(-16, -16)')\n .attr('width', '32')\n .attr('height', '32');\n\n // update\n groups = groups\n .merge(groupsEnter)\n .attr('opacity', function(d) { return d.direct === false ? '0.7' : null; })\n .attr('transform', turnTransform);\n\n groups.select('use')\n .attr('xlink:href', icon);\n\n groups.select('rect'); // propagate bound data\n groups.select('circle'); // propagate bound data\n\n\n // Draw touch targets..\n var fillClass = context.getDebug('target') ? 'pink ' : 'nocolor ';\n groups = touchLayer.selectAll('g.turn')\n .data(turns, function(d) { return d.key; });\n\n // exit\n groups.exit()\n .remove();\n\n // enter\n groupsEnter = groups.enter()\n .append('g')\n .attr('class', function(d) { return 'turn ' + d.key; });\n\n turnsEnter = groupsEnter\n .filter(function(d) { return !d.u; });\n\n turnsEnter.append('rect')\n .attr('class', 'target ' + fillClass)\n .attr('transform', 'translate(-22, -12)')\n .attr('width', '44')\n .attr('height', '24');\n\n uEnter = groupsEnter\n .filter(function(d) { return d.u; });\n\n uEnter.append('circle')\n .attr('class', 'target ' + fillClass)\n .attr('r', '16');\n\n // update\n groups = groups\n .merge(groupsEnter)\n .attr('transform', turnTransform);\n\n groups.select('rect'); // propagate bound data\n groups.select('circle'); // propagate bound data\n\n\n return this;\n }\n\n return drawTurns;\n}\n","import deepEqual from 'fast-deep-equal';\nimport { select as d3_select } from 'd3-selection';\n\nimport { presetManager } from '../presets';\nimport { geoScaleToZoom } from '../geo';\nimport { osmEntity } from '../osm';\nimport { svgPassiveVertex, svgPointTransform } from './helpers';\n\nexport function svgVertices(projection, context) {\n var radiuses = {\n // z16-, z17, z18+, w/icon\n shadow: [6, 7.5, 7.5, 12],\n stroke: [2.5, 3.5, 3.5, 8],\n fill: [1, 1.5, 1.5, 1.5]\n };\n\n var _currHoverTarget;\n var _currPersistent = {};\n var _currHover = {};\n var _prevHover = {};\n var _currSelected = {};\n var _prevSelected = {};\n var _radii = {};\n\n\n function sortY(a, b) {\n return b.loc[1] - a.loc[1];\n }\n\n // Avoid exit/enter if we're just moving stuff around.\n // The node will get a new version but we only need to run the update selection.\n function fastEntityKey(d) {\n var mode = context.mode();\n var isMoving = mode && /^(add|draw|drag|move|rotate)/.test(mode.id);\n return isMoving ? d.id : osmEntity.key(d);\n }\n\n\n function draw(selection, graph, vertices, sets, filter) {\n sets = sets || { selected: {}, important: {}, hovered: {} };\n\n var icons = {};\n var directions = {};\n var wireframe = context.surface().classed('fill-wireframe');\n var zoom = geoScaleToZoom(projection.scale());\n var z = (zoom < 17 ? 0 : zoom < 18 ? 1 : 2);\n var activeID = context.activeID();\n var base = context.history().base();\n\n\n function getIcon(d) {\n // always check latest entity, as fastEntityKey avoids enter/exit now\n var entity = graph.entity(d.id);\n if (entity.id in icons) return icons[entity.id];\n\n icons[entity.id] =\n entity.hasInterestingTags() &&\n presetManager.match(entity, graph).icon;\n\n return icons[entity.id];\n }\n\n\n // memoize directions results, return false for empty arrays (for use in filter)\n function getDirections(entity) {\n if (entity.id in directions) return directions[entity.id];\n\n var angles = entity.directions(graph, projection);\n directions[entity.id] = angles.length ? angles : false;\n return angles;\n }\n\n\n function updateAttributes(selection) {\n ['shadow', 'stroke', 'fill'].forEach(function(klass) {\n var rads = radiuses[klass];\n selection.selectAll('.' + klass)\n .each(function(entity) {\n var i = z && getIcon(entity);\n var r = rads[i ? 3 : z];\n\n // slightly increase the size of unconnected endpoints #3775\n if (entity.id !== activeID && entity.isEndpoint(graph) && !entity.isConnected(graph)) {\n r += 1.5;\n }\n\n if (klass === 'shadow') { // remember this value, so we don't need to\n _radii[entity.id] = r; // recompute it when we draw the touch targets\n }\n\n d3_select(this)\n .attr('r', r)\n .attr('visibility', (i && klass === 'fill') ? 'hidden' : null);\n });\n });\n }\n\n vertices.sort(sortY);\n\n var groups = selection.selectAll('g.vertex')\n .filter(filter)\n .data(vertices, fastEntityKey);\n\n // exit\n groups.exit()\n .remove();\n\n // enter\n var enter = groups.enter()\n .append('g')\n .attr('class', function(d) { return 'node vertex ' + d.id; })\n .order();\n\n enter\n .append('circle')\n .attr('class', 'shadow');\n\n enter\n .append('circle')\n .attr('class', 'stroke');\n\n // Vertices with tags get a fill.\n enter.filter(function(d) { return d.hasInterestingTags(); })\n .append('circle')\n .attr('class', 'fill');\n\n // update\n groups = groups\n .merge(enter)\n .attr('transform', svgPointTransform(projection))\n .classed('sibling', function(d) { return d.id in sets.selected; })\n .classed('shared', function(d) { return graph.isShared(d); })\n .classed('endpoint', function(d) { return d.isEndpoint(graph); })\n .classed('added', function(d) {\n return !base.entities[d.id]; // if it doesn't exist in the base graph, it's new\n })\n .classed('moved', function(d) {\n return base.entities[d.id] && !deepEqual(graph.entities[d.id].loc, base.entities[d.id].loc);\n })\n .classed('retagged', function(d) {\n return base.entities[d.id] && !deepEqual(graph.entities[d.id].tags, base.entities[d.id].tags);\n })\n .call(updateAttributes);\n\n // Vertices with icons get a `use`.\n var iconUse = groups\n .selectAll('.icon')\n .data(function data(d) { return zoom >= 17 && getIcon(d) ? [d] : []; }, fastEntityKey);\n\n // exit\n iconUse.exit()\n .remove();\n\n // enter\n iconUse.enter()\n .append('use')\n .attr('class', 'icon')\n .attr('width', '11px')\n .attr('height', '11px')\n .attr('transform', 'translate(-5.5, -5.5)')\n .attr('xlink:href', function(d) {\n var picon = getIcon(d);\n var isMaki = /^maki-/.test(picon);\n return '#' + picon + (isMaki ? '-11' : '');\n });\n\n\n // Vertices with directions get viewfields\n var dgroups = groups\n .selectAll('.viewfieldgroup')\n .data(function data(d) { return zoom >= 18 && getDirections(d) ? [d] : []; }, fastEntityKey);\n\n // exit\n dgroups.exit()\n .remove();\n\n // enter/update\n dgroups = dgroups.enter()\n .insert('g', '.shadow')\n .attr('class', 'viewfieldgroup')\n .merge(dgroups);\n\n var viewfields = dgroups.selectAll('.viewfield')\n .data(getDirections, function key(d) { return osmEntity.key(d); });\n\n // exit\n viewfields.exit()\n .remove();\n\n // enter/update\n viewfields.enter()\n .append('path')\n .attr('class', 'viewfield')\n .attr('d', 'M0,0H0')\n .merge(viewfields)\n .attr('marker-start', 'url(#ideditor-viewfield-marker' + (wireframe ? '-wireframe' : '') + ')')\n .attr('transform', function(d) { return 'rotate(' + d + ')'; });\n }\n\n\n function drawTargets(selection, graph, entities, filter) {\n var targetClass = context.getDebug('target') ? 'pink ' : 'nocolor ';\n var nopeClass = context.getDebug('target') ? 'red ' : 'nocolor ';\n var getTransform = svgPointTransform(projection).geojson;\n var activeID = context.activeID();\n var data = { targets: [], nopes: [] };\n var base = context.history().base();\n\n entities.forEach(function(node) {\n if (activeID === node.id) return; // draw no target on the activeID\n\n var vertexType = svgPassiveVertex(node, graph, activeID);\n if (vertexType !== 0) { // passive or adjacent - allow to connect\n data.targets.push({\n type: 'Feature',\n id: node.id,\n properties: {\n target: true,\n entity: node\n },\n geometry: node.asGeoJSON()\n });\n } else {\n data.nopes.push({\n type: 'Feature',\n id: node.id + '-nope',\n properties: {\n nope: true,\n target: true,\n entity: node\n },\n geometry: node.asGeoJSON()\n });\n }\n });\n\n // Targets allow hover and vertex snapping\n var targets = selection.selectAll('.vertex.target-allowed')\n .filter(function(d) { return filter(d.properties.entity); })\n .data(data.targets, function key(d) { return d.id; });\n\n // exit\n targets.exit()\n .remove();\n\n var threeFourths = function (num) {\n return (Math.round(3 * num) / 4).toFixed(2);\n };\n\n // enter/update\n targets.enter()\n .append('circle')\n .attr('r', function(d) {\n return _radii[d.id]\n || radiuses.shadow[3];\n })\n .merge(targets)\n .attr('class', function(d) {\n return 'node vertex target target-allowed '\n + targetClass + d.id;\n })\n .attr('transform', getTransform);\n\n\n // NOPE\n var nopes = selection.selectAll('.vertex.target-nope')\n .filter(function(d) { return filter(d.properties.entity); })\n .data(data.nopes, function key(d) { return d.id; });\n\n // exit\n nopes.exit()\n .remove();\n\n // enter/update\n nopes.enter()\n .append('circle')\n .attr('r', function(d) { return (_radii[d.properties.entity.id] || radiuses.shadow[3]); })\n .merge(nopes)\n .attr('class', function(d) { return 'node vertex target target-nope ' + nopeClass + d.id; })\n .attr('transform', getTransform);\n }\n\n\n // Points can also render as vertices:\n // 1. in wireframe mode or\n // 2. at higher zooms if they have a direction\n function renderAsVertex(entity, graph, wireframe, zoom) {\n var geometry = entity.geometry(graph);\n return geometry === 'vertex' || (geometry === 'point' && (\n wireframe || (zoom >= 18 && entity.directions(graph, projection).length)\n ));\n }\n\n\n function isEditedNode(node, base, head) {\n var baseNode = base.entities[node.id];\n var headNode = head.entities[node.id];\n return !headNode ||\n !baseNode ||\n !deepEqual(headNode.tags, baseNode.tags) ||\n !deepEqual(headNode.loc, baseNode.loc);\n }\n\n\n function getSiblingAndChildVertices(ids, graph, wireframe, zoom) {\n var results = {};\n\n var seenIds = {};\n\n function addChildVertices(entity) {\n\n // avoid redunant work and infinite recursion of circular relations\n if (seenIds[entity.id]) return;\n seenIds[entity.id] = true;\n\n var geometry = entity.geometry(graph);\n if (!context.features().isHiddenFeature(entity, graph, geometry)) {\n var i;\n if (entity.type === 'way') {\n for (i = 0; i < entity.nodes.length; i++) {\n var child = graph.hasEntity(entity.nodes[i]);\n if (child) {\n addChildVertices(child);\n }\n }\n } else if (entity.type === 'relation') {\n for (i = 0; i < entity.members.length; i++) {\n var member = graph.hasEntity(entity.members[i].id);\n if (member) {\n addChildVertices(member);\n }\n }\n } else if (renderAsVertex(entity, graph, wireframe, zoom)) {\n results[entity.id] = entity;\n }\n }\n }\n\n ids.forEach(function(id) {\n var entity = graph.hasEntity(id);\n if (!entity) return;\n\n if (entity.type === 'node') {\n if (renderAsVertex(entity, graph, wireframe, zoom)) {\n results[entity.id] = entity;\n graph.parentWays(entity).forEach(function(entity) {\n addChildVertices(entity);\n });\n }\n } else { // way, relation\n addChildVertices(entity);\n }\n });\n\n return results;\n }\n\n\n function drawVertices(selection, graph, entities, filter, extent, fullRedraw) {\n var wireframe = context.surface().classed('fill-wireframe');\n var visualDiff = context.surface().classed('highlight-edited');\n var zoom = geoScaleToZoom(projection.scale());\n var mode = context.mode();\n var isMoving = mode && /^(add|draw|drag|move|rotate)/.test(mode.id);\n var base = context.history().base();\n\n var drawLayer = selection.selectAll('.layer-osm.points .points-group.vertices');\n var touchLayer = selection.selectAll('.layer-touch.points');\n\n if (fullRedraw) {\n _currPersistent = {};\n _radii = {};\n }\n\n // Collect important vertices from the `entities` list..\n // (during a paritial redraw, it will not contain everything)\n for (var i = 0; i < entities.length; i++) {\n var entity = entities[i];\n var geometry = entity.geometry(graph);\n var keep = false;\n\n // a point that looks like a vertex..\n if ((geometry === 'point') && renderAsVertex(entity, graph, wireframe, zoom)) {\n _currPersistent[entity.id] = entity;\n keep = true;\n\n // a vertex of some importance..\n } else if (geometry === 'vertex' &&\n (entity.hasInterestingTags() || entity.isEndpoint(graph) || entity.isConnected(graph)\n || (visualDiff && isEditedNode(entity, base, graph)))) {\n _currPersistent[entity.id] = entity;\n keep = true;\n }\n\n // whatever this is, it's not a persistent vertex..\n if (!keep && !fullRedraw) {\n delete _currPersistent[entity.id];\n }\n }\n\n // 3 sets of vertices to consider:\n var sets = {\n persistent: _currPersistent, // persistent = important vertices (render always)\n selected: _currSelected, // selected + siblings of selected (render always)\n hovered: _currHover // hovered + siblings of hovered (render only in draw modes)\n };\n\n var all = Object.assign({}, (isMoving ? _currHover : {}), _currSelected, _currPersistent);\n\n // Draw the vertices..\n // The filter function controls the scope of what objects d3 will touch (exit/enter/update)\n // Adjust the filter function to expand the scope beyond whatever entities were passed in.\n var filterRendered = function(d) {\n return d.id in _currPersistent || d.id in _currSelected || d.id in _currHover || filter(d);\n };\n drawLayer\n .call(draw, graph, currentVisible(all), sets, filterRendered);\n\n // Draw touch targets..\n // When drawing, render all targets (not just those affected by a partial redraw)\n var filterTouch = function(d) {\n return isMoving ? true : filterRendered(d);\n };\n touchLayer\n .call(drawTargets, graph, currentVisible(all), filterTouch);\n\n\n function currentVisible(which) {\n return Object.keys(which)\n .map(graph.hasEntity, graph) // the current version of this entity\n .filter(function (entity) { return entity && entity.intersects(extent, graph); });\n }\n }\n\n\n // partial redraw - only update the selected items..\n drawVertices.drawSelected = function(selection, graph, extent) {\n var wireframe = context.surface().classed('fill-wireframe');\n var zoom = geoScaleToZoom(projection.scale());\n\n _prevSelected = _currSelected || {};\n if (context.map().isInWideSelection()) {\n _currSelected = {};\n context.selectedIDs().forEach(function(id) {\n var entity = graph.hasEntity(id);\n if (!entity) return;\n\n if (entity.type === 'node') {\n if (renderAsVertex(entity, graph, wireframe, zoom)) {\n _currSelected[entity.id] = entity;\n }\n }\n });\n\n } else {\n _currSelected = getSiblingAndChildVertices(context.selectedIDs(), graph, wireframe, zoom);\n }\n\n // note that drawVertices will add `_currSelected` automatically if needed..\n var filter = function(d) { return d.id in _prevSelected; };\n drawVertices(selection, graph, Object.values(_prevSelected), filter, extent, false);\n };\n\n\n // partial redraw - only update the hovered items..\n drawVertices.drawHover = function(selection, graph, target, extent) {\n if (target === _currHoverTarget) return; // continue only if something changed\n\n var wireframe = context.surface().classed('fill-wireframe');\n var zoom = geoScaleToZoom(projection.scale());\n\n _prevHover = _currHover || {};\n _currHoverTarget = target;\n var entity = target && target.properties && target.properties.entity;\n\n if (entity) {\n _currHover = getSiblingAndChildVertices([entity.id], graph, wireframe, zoom);\n } else {\n _currHover = {};\n }\n\n // note that drawVertices will add `_currHover` automatically if needed..\n var filter = function(d) { return d.id in _prevHover; };\n drawVertices(selection, graph, Object.values(_prevHover), filter, extent, false);\n };\n\n return drawVertices;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { select as d3_select, event as d3_event } from 'd3-selection';\nimport * as countryCoder from '@ideditor/country-coder';\n\nimport { presetManager } from '../../presets';\nimport { fileFetcher } from '../../core/file_fetcher';\nimport { t, localizer } from '../../core/localizer';\nimport { services } from '../../services';\nimport { svgIcon } from '../../svg';\nimport { uiTooltip } from '../tooltip';\nimport { uiCombobox } from '../combobox';\nimport { utilArrayUniq, utilEditDistance, utilGetSetValue, utilNoAuto, utilRebind, utilTotalExtent, utilUniqueDomId } from '../../util';\n\nvar _languagesArray = [];\n\n\nexport function uiFieldLocalized(field, context) {\n var dispatch = d3_dispatch('change', 'input');\n var wikipedia = services.wikipedia;\n var input = d3_select(null);\n var localizedInputs = d3_select(null);\n var _countryCode;\n var _tags;\n\n\n // A concern here in switching to async data means that _languagesArray will not\n // be available the first time through, so things like the fetchers and\n // the language() function will not work immediately.\n fileFetcher.get('languages')\n .then(loadLanguagesArray)\n .catch(function() { /* ignore */ });\n\n var _territoryLanguages = {};\n fileFetcher.get('territory_languages')\n .then(function(d) { _territoryLanguages = d; })\n .catch(function() { /* ignore */ });\n\n\n var allSuggestions = presetManager.collection.filter(function(p) {\n return p.suggestion === true;\n });\n\n // reuse these combos\n var langCombo = uiCombobox(context, 'localized-lang')\n .fetcher(fetchLanguages)\n .minItems(0);\n\n var brandCombo = uiCombobox(context, 'localized-brand')\n .canAutocomplete(false)\n .minItems(1);\n\n var _selection = d3_select(null);\n var _multilingual = [];\n var _buttonTip = uiTooltip()\n .title(t('translate.translate'))\n .placement('left');\n var _wikiTitles;\n var _entityIDs = [];\n\n\n function loadLanguagesArray(dataLanguages) {\n if (_languagesArray.length !== 0) return;\n\n // some conversion is needed to ensure correct OSM tags are used\n var replacements = {\n sr: 'sr-Cyrl', // in OSM, `sr` implies Cyrillic\n 'sr-Cyrl': false // `sr-Cyrl` isn't used in OSM\n };\n\n for (var code in dataLanguages) {\n if (replacements[code] === false) continue;\n var metaCode = code;\n if (replacements[code]) metaCode = replacements[code];\n\n _languagesArray.push({\n localName: localizer.languageName(metaCode, { localOnly: true }),\n nativeName: dataLanguages[metaCode].nativeName,\n code: code,\n label: localizer.languageName(metaCode)\n });\n }\n }\n\n\n function calcLocked() {\n\n // only lock the Name field\n var isLocked = field.id === 'name' &&\n _entityIDs.length &&\n // lock the field if any feature needs it\n _entityIDs.some(function(entityID) {\n\n var entity = context.graph().hasEntity(entityID);\n if (!entity) return false;\n\n var original = context.graph().base().entities[_entityIDs[0]];\n var hasOriginalName = original && entity.tags.name && entity.tags.name === original.tags.name;\n // if the name was already edited manually then allow further editing\n if (!hasOriginalName) return false;\n\n // features linked to Wikidata are likely important and should be protected\n if (entity.tags.wikidata) return true;\n\n // assume the name has already been confirmed if its source has been researched\n if (entity.tags['name:etymology:wikidata']) return true;\n\n var preset = presetManager.match(entity, context.graph());\n var isSuggestion = preset && preset.suggestion;\n var showsBrand = preset && preset.originalFields.filter(function(d) {\n return d.id === 'brand';\n }).length;\n // protect standardized brand names\n return isSuggestion && !showsBrand;\n });\n\n field.locked(isLocked);\n }\n\n\n // update _multilingual, maintaining the existing order\n function calcMultilingual(tags) {\n var existingLangsOrdered = _multilingual.map(function(item) {\n return item.lang;\n });\n var existingLangs = new Set(existingLangsOrdered.filter(Boolean));\n\n for (var k in tags) {\n var m = k.match(/^(.*):([a-zA-Z_-]+)$/);\n if (m && m[1] === field.key && m[2]) {\n var item = { lang: m[2], value: tags[k] };\n if (existingLangs.has(item.lang)) {\n // update the value\n _multilingual[existingLangsOrdered.indexOf(item.lang)].value = item.value;\n existingLangs.delete(item.lang);\n } else {\n _multilingual.push(item);\n }\n }\n }\n\n _multilingual = _multilingual.filter(function(item) {\n return !item.lang || !existingLangs.has(item.lang);\n });\n }\n\n\n function localized(selection) {\n _selection = selection;\n calcLocked();\n var isLocked = field.locked();\n var singularEntity = _entityIDs.length === 1 && context.hasEntity(_entityIDs[0]);\n var preset = singularEntity && presetManager.match(singularEntity, context.graph());\n\n var wrap = selection.selectAll('.form-field-input-wrap')\n .data([0]);\n\n // enter/update\n wrap = wrap.enter()\n .append('div')\n .attr('class', 'form-field-input-wrap form-field-input-' + field.type)\n .merge(wrap);\n\n input = wrap.selectAll('.localized-main')\n .data([0]);\n\n // enter/update\n input = input.enter()\n .append('input')\n .attr('type', 'text')\n .attr('id', field.domId)\n .attr('class', 'localized-main')\n .call(utilNoAuto)\n .merge(input);\n\n if (preset && field.id === 'name') {\n var pTag = preset.id.split('/', 2);\n var pKey = pTag[0];\n var pValue = pTag[1];\n\n if (!preset.suggestion) {\n // Not a suggestion preset - Add a suggestions dropdown if it makes sense to.\n // This code attempts to determine if the matched preset is the\n // kind of preset that even can benefit from name suggestions..\n // - true = shops, cafes, hotels, etc. (also generic and fallback presets)\n // - false = churches, parks, hospitals, etc. (things not in the index)\n var isFallback = preset.isFallback();\n var goodSuggestions = allSuggestions.filter(function(s) {\n if (isFallback) return true;\n var sTag = s.id.split('/', 2);\n var sKey = sTag[0];\n var sValue = sTag[1];\n return pKey === sKey && (!pValue || pValue === sValue);\n });\n\n // Show the suggestions.. If the user picks one, change the tags..\n if (allSuggestions.length && goodSuggestions.length) {\n input\n .on('blur.localized', checkBrandOnBlur)\n .call(brandCombo\n .fetcher(fetchBrandNames(preset, allSuggestions))\n .on('accept', acceptBrand)\n .on('cancel', cancelBrand)\n );\n }\n }\n }\n\n input\n .classed('disabled', !!isLocked)\n .attr('readonly', isLocked || null)\n .on('input', change(true))\n .on('blur', change())\n .on('change', change());\n\n\n var translateButton = wrap.selectAll('.localized-add')\n .data([0]);\n\n translateButton = translateButton.enter()\n .append('button')\n .attr('class', 'localized-add form-field-button')\n .attr('tabindex', -1)\n .call(svgIcon('#iD-icon-plus'))\n .merge(translateButton);\n\n translateButton\n .classed('disabled', !!isLocked)\n .call(isLocked ? _buttonTip.destroy : _buttonTip)\n .on('click', addNew);\n\n\n if (_tags && !_multilingual.length) {\n calcMultilingual(_tags);\n }\n\n localizedInputs = selection.selectAll('.localized-multilingual')\n .data([0]);\n\n localizedInputs = localizedInputs.enter()\n .append('div')\n .attr('class', 'localized-multilingual')\n .merge(localizedInputs);\n\n localizedInputs\n .call(renderMultilingual);\n\n localizedInputs.selectAll('button, input')\n .classed('disabled', !!isLocked)\n .attr('readonly', isLocked || null);\n\n\n\n // We are not guaranteed to get an `accept` or `cancel` when blurring the field.\n // (This can happen if the user actives the combo, arrows down, and then clicks off to blur)\n // So compare the current field value against the suggestions one last time.\n function checkBrandOnBlur() {\n var latest = _entityIDs.length === 1 && context.hasEntity(_entityIDs[0]);\n if (!latest) return; // deleting the entity blurred the field?\n\n var preset = presetManager.match(latest, context.graph());\n if (preset && preset.suggestion) return; // already accepted\n\n // note: here we are testing against \"decorated\" names, i.e. 'Starbucks – Cafe'\n var name = utilGetSetValue(input).trim();\n var matched = allSuggestions.filter(function(s) { return name === s.name(); });\n\n if (matched.length === 1) {\n acceptBrand({ suggestion: matched[0] });\n } else {\n cancelBrand();\n }\n }\n\n\n function acceptBrand(d) {\n\n var entity = _entityIDs.length === 1 && context.hasEntity(_entityIDs[0]);\n\n if (!d || !entity) {\n cancelBrand();\n return;\n }\n\n var tags = entity.tags;\n var geometry = entity.geometry(context.graph());\n var removed = preset.unsetTags(tags, geometry);\n for (var k in tags) {\n tags[k] = removed[k]; // set removed tags to `undefined`\n }\n tags = d.suggestion.setTags(tags, geometry);\n utilGetSetValue(input, tags.name);\n dispatch.call('change', this, tags);\n }\n\n\n // user hit escape, clean whatever preset name appears after the last ' – '\n function cancelBrand() {\n var name = utilGetSetValue(input);\n var clean = cleanName(name);\n if (clean !== name) {\n utilGetSetValue(input, clean);\n dispatch.call('change', this, { name: clean });\n }\n }\n\n // Remove whatever is after the last ' – '\n // NOTE: split/join on en-dash, not a hypen (to avoid conflict with fr - nl names in Brussels etc)\n function cleanName(name) {\n var parts = name.split(' – ');\n if (parts.length > 1) {\n parts.pop();\n name = parts.join(' – ');\n }\n return name;\n }\n\n\n function fetchBrandNames(preset, suggestions) {\n var pTag = preset.id.split('/', 2);\n var pKey = pTag[0];\n var pValue = pTag[1];\n\n return function(value, callback) {\n var results = [];\n if (value && value.length > 2) {\n for (var i = 0; i < suggestions.length; i++) {\n var s = suggestions[i];\n\n // don't suggest brands from incompatible countries\n if (_countryCode && s.countryCodes &&\n s.countryCodes.indexOf(_countryCode) === -1) continue;\n\n var sTag = s.id.split('/', 2);\n var sKey = sTag[0];\n var sValue = sTag[1];\n var name = s.name();\n var dist = utilEditDistance(value, name.substring(0, value.length));\n var matchesPreset = (pKey === sKey && (!pValue || pValue === sValue));\n\n if (dist < 1 || (matchesPreset && dist < 3)) {\n var obj = {\n title: name,\n value: name,\n suggestion: s,\n dist: dist + (matchesPreset ? 0 : 1) // penalize if not matched preset\n };\n results.push(obj);\n }\n }\n results.sort(function(a, b) { return a.dist - b.dist; });\n }\n results = results.slice(0, 10);\n callback(results);\n };\n }\n\n\n function addNew() {\n d3_event.preventDefault();\n if (field.locked()) return;\n\n var defaultLang = localizer.languageCode().toLowerCase();\n var langExists = _multilingual.find(function(datum) { return datum.lang === defaultLang; });\n var isLangEn = defaultLang.indexOf('en') > -1;\n if (isLangEn || langExists) {\n defaultLang = '';\n langExists = _multilingual.find(function(datum) { return datum.lang === defaultLang; });\n }\n\n if (!langExists) {\n // prepend the value so it appears at the top\n _multilingual.unshift({ lang: defaultLang, value: '' });\n\n localizedInputs\n .call(renderMultilingual);\n }\n }\n\n\n function change(onInput) {\n return function() {\n if (field.locked()) {\n d3_event.preventDefault();\n return;\n }\n\n var val = utilGetSetValue(d3_select(this));\n if (!onInput) val = context.cleanTagValue(val);\n\n // don't override multiple values with blank string\n if (!val && Array.isArray(_tags[field.key])) return;\n\n var t = {};\n\n t[field.key] = val || undefined;\n dispatch.call('change', this, t, onInput);\n };\n }\n }\n\n\n function key(lang) {\n return field.key + ':' + lang;\n }\n\n\n function changeLang(d) {\n var tags = {};\n\n // make sure unrecognized suffixes are lowercase - #7156\n var lang = utilGetSetValue(d3_select(this)).toLowerCase();\n\n var language = _languagesArray.find(function(d) {\n return d.label.toLowerCase() === lang ||\n (d.localName && d.localName.toLowerCase() === lang) ||\n (d.nativeName && d.nativeName.toLowerCase() === lang);\n });\n if (language) lang = language.code;\n\n if (d.lang && d.lang !== lang) {\n tags[key(d.lang)] = undefined;\n }\n\n var newKey = lang && context.cleanTagKey(key(lang));\n\n var value = utilGetSetValue(d3_select(this.parentNode).selectAll('.localized-value'));\n\n if (newKey && value) {\n tags[newKey] = value;\n } else if (newKey && _wikiTitles && _wikiTitles[d.lang]) {\n tags[newKey] = _wikiTitles[d.lang];\n }\n\n d.lang = lang;\n dispatch.call('change', this, tags);\n }\n\n\n function changeValue(d) {\n if (!d.lang) return;\n var value = context.cleanTagValue(utilGetSetValue(d3_select(this))) || undefined;\n\n // don't override multiple values with blank string\n if (!value && Array.isArray(d.value)) return;\n\n var t = {};\n t[key(d.lang)] = value;\n d.value = value;\n dispatch.call('change', this, t);\n }\n\n\n function fetchLanguages(value, cb) {\n var v = value.toLowerCase();\n\n // show the user's language first\n var langCodes = [localizer.localeCode(), localizer.languageCode()];\n\n if (_countryCode && _territoryLanguages[_countryCode]) {\n langCodes = langCodes.concat(_territoryLanguages[_countryCode]);\n }\n\n var langItems = [];\n langCodes.forEach(function(code) {\n var langItem = _languagesArray.find(function(item) {\n return item.code === code;\n });\n if (langItem) langItems.push(langItem);\n });\n langItems = utilArrayUniq(langItems.concat(_languagesArray));\n\n cb(langItems.filter(function(d) {\n return d.label.toLowerCase().indexOf(v) >= 0 ||\n (d.localName && d.localName.toLowerCase().indexOf(v) >= 0) ||\n (d.nativeName && d.nativeName.toLowerCase().indexOf(v) >= 0) ||\n d.code.toLowerCase().indexOf(v) >= 0;\n }).map(function(d) {\n return { value: d.label };\n }));\n }\n\n\n function renderMultilingual(selection) {\n var entries = selection.selectAll('div.entry')\n .data(_multilingual, function(d) { return d.lang; });\n\n entries.exit()\n .style('top', '0')\n .style('max-height', '240px')\n .transition()\n .duration(200)\n .style('opacity', '0')\n .style('max-height', '0px')\n .remove();\n\n var entriesEnter = entries.enter()\n .append('div')\n .attr('class', 'entry')\n .each(function(_, index) {\n var wrap = d3_select(this);\n\n var domId = utilUniqueDomId(index);\n\n var label = wrap\n .append('label')\n .attr('class', 'field-label')\n .attr('for', domId);\n\n var text = label\n .append('span')\n .attr('class', 'label-text');\n\n text\n .append('span')\n .attr('class', 'label-textvalue')\n .text(t('translate.localized_translation_label'));\n\n text\n .append('span')\n .attr('class', 'label-textannotation');\n\n label\n .append('button')\n .attr('class', 'remove-icon-multilingual')\n .on('click', function(d, index) {\n if (field.locked()) return;\n d3_event.preventDefault();\n\n if (!d.lang || !d.value) {\n _multilingual.splice(index, 1);\n renderMultilingual(selection);\n } else {\n // remove from entity tags\n var t = {};\n t[key(d.lang)] = undefined;\n dispatch.call('change', this, t);\n }\n\n })\n .call(svgIcon('#iD-operation-delete'));\n\n wrap\n .append('input')\n .attr('class', 'localized-lang')\n .attr('id', domId)\n .attr('type', 'text')\n .attr('placeholder', t('translate.localized_translation_language'))\n .on('blur', changeLang)\n .on('change', changeLang)\n .call(langCombo);\n\n wrap\n .append('input')\n .attr('type', 'text')\n .attr('class', 'localized-value')\n .on('blur', changeValue)\n .on('change', changeValue);\n });\n\n entriesEnter\n .style('margin-top', '0px')\n .style('max-height', '0px')\n .style('opacity', '0')\n .transition()\n .duration(200)\n .style('margin-top', '10px')\n .style('max-height', '240px')\n .style('opacity', '1')\n .on('end', function() {\n d3_select(this)\n .style('max-height', '')\n .style('overflow', 'visible');\n });\n\n entries = entries.merge(entriesEnter);\n\n entries.order();\n\n entries.classed('present', function(d) {\n return d.lang && d.value;\n });\n\n utilGetSetValue(entries.select('.localized-lang'), function(d) {\n return localizer.languageName(d.lang);\n });\n\n utilGetSetValue(entries.select('.localized-value'), function(d) {\n return typeof d.value === 'string' ? d.value : '';\n })\n .attr('title', function(d) {\n return Array.isArray(d.value) ? d.value.filter(Boolean).join('\\n') : null;\n })\n .attr('placeholder', function(d) {\n return Array.isArray(d.value) ? t('inspector.multiple_values') : t('translate.localized_translation_name');\n })\n .classed('mixed', function(d) {\n return Array.isArray(d.value);\n });\n }\n\n\n localized.tags = function(tags) {\n _tags = tags;\n\n // Fetch translations from wikipedia\n if (typeof tags.wikipedia === 'string' && !_wikiTitles) {\n _wikiTitles = {};\n var wm = tags.wikipedia.match(/([^:]+):(.+)/);\n if (wm && wm[0] && wm[1]) {\n wikipedia.translations(wm[1], wm[2], function(err, d) {\n if (err || !d) return;\n _wikiTitles = d;\n });\n }\n }\n\n var isMixed = Array.isArray(tags[field.key]);\n\n utilGetSetValue(input, typeof tags[field.key] === 'string' ? tags[field.key] : '')\n .attr('title', isMixed ? tags[field.key].filter(Boolean).join('\\n') : undefined)\n .attr('placeholder', isMixed ? t('inspector.multiple_values') : field.placeholder())\n .classed('mixed', isMixed);\n\n calcMultilingual(tags);\n\n _selection\n .call(localized);\n };\n\n\n localized.focus = function() {\n input.node().focus();\n };\n\n\n localized.entityIDs = function(val) {\n if (!arguments.length) return _entityIDs;\n _entityIDs = val;\n _multilingual = [];\n loadCountryCode();\n return localized;\n };\n\n function loadCountryCode() {\n var extent = combinedEntityExtent();\n var countryCode = extent && countryCoder.iso1A2Code(extent.center());\n _countryCode = countryCode && countryCode.toLowerCase();\n }\n\n function combinedEntityExtent() {\n return _entityIDs && _entityIDs.length && utilTotalExtent(_entityIDs, context.graph());\n }\n\n return utilRebind(localized, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { select as d3_select } from 'd3-selection';\nimport * as countryCoder from '@ideditor/country-coder';\n\nimport { uiCombobox } from '../combobox';\nimport { t } from '../../core/localizer';\nimport { utilGetSetValue, utilNoAuto, utilRebind, utilTotalExtent } from '../../util';\n\n\nexport function uiFieldMaxspeed(field, context) {\n var dispatch = d3_dispatch('change');\n var unitInput = d3_select(null);\n var input = d3_select(null);\n var _entityIDs = [];\n var _tags;\n var _isImperial;\n\n var speedCombo = uiCombobox(context, 'maxspeed');\n var unitCombo = uiCombobox(context, 'maxspeed-unit')\n .data(['km/h', 'mph'].map(comboValues));\n\n var metricValues = [20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120];\n var imperialValues = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80];\n\n\n function maxspeed(selection) {\n\n var wrap = selection.selectAll('.form-field-input-wrap')\n .data([0]);\n\n wrap = wrap.enter()\n .append('div')\n .attr('class', 'form-field-input-wrap form-field-input-' + field.type)\n .merge(wrap);\n\n\n input = wrap.selectAll('input.maxspeed-number')\n .data([0]);\n\n input = input.enter()\n .append('input')\n .attr('type', 'text')\n .attr('class', 'maxspeed-number')\n .attr('id', field.domId)\n .call(utilNoAuto)\n .call(speedCombo)\n .merge(input);\n\n input\n .on('change', change)\n .on('blur', change);\n\n var loc = combinedEntityExtent().center();\n _isImperial = countryCoder.roadSpeedUnit(loc) === 'mph';\n\n unitInput = wrap.selectAll('input.maxspeed-unit')\n .data([0]);\n\n unitInput = unitInput.enter()\n .append('input')\n .attr('type', 'text')\n .attr('class', 'maxspeed-unit')\n .call(unitCombo)\n .merge(unitInput);\n\n unitInput\n .on('blur', changeUnits)\n .on('change', changeUnits);\n\n\n function changeUnits() {\n _isImperial = utilGetSetValue(unitInput) === 'mph';\n utilGetSetValue(unitInput, _isImperial ? 'mph' : 'km/h');\n setUnitSuggestions();\n change();\n }\n }\n\n\n function setUnitSuggestions() {\n speedCombo.data((_isImperial ? imperialValues : metricValues).map(comboValues));\n utilGetSetValue(unitInput, _isImperial ? 'mph' : 'km/h');\n }\n\n\n function comboValues(d) {\n return {\n value: d.toString(),\n title: d.toString()\n };\n }\n\n\n function change() {\n var tag = {};\n var value = utilGetSetValue(input).trim();\n\n // don't override multiple values with blank string\n if (!value && Array.isArray(_tags[field.key])) return;\n\n if (!value) {\n tag[field.key] = undefined;\n } else if (isNaN(value) || !_isImperial) {\n tag[field.key] = context.cleanTagValue(value);\n } else {\n tag[field.key] = context.cleanTagValue(value + ' mph');\n }\n\n dispatch.call('change', this, tag);\n }\n\n\n maxspeed.tags = function(tags) {\n _tags = tags;\n\n var value = tags[field.key];\n var isMixed = Array.isArray(value);\n\n if (!isMixed) {\n if (value && value.indexOf('mph') >= 0) {\n value = parseInt(value, 10).toString();\n _isImperial = true;\n } else if (value) {\n _isImperial = false;\n }\n }\n\n setUnitSuggestions();\n\n utilGetSetValue(input, typeof value === 'string' ? value : '')\n .attr('title', isMixed ? value.filter(Boolean).join('\\n') : null)\n .attr('placeholder', isMixed ? t('inspector.multiple_values') : field.placeholder())\n .classed('mixed', isMixed);\n };\n\n\n maxspeed.focus = function() {\n input.node().focus();\n };\n\n\n maxspeed.entityIDs = function(val) {\n _entityIDs = val;\n };\n\n\n function combinedEntityExtent() {\n return _entityIDs && _entityIDs.length && utilTotalExtent(_entityIDs, context.graph());\n }\n\n\n return utilRebind(maxspeed, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { select as d3_select } from 'd3-selection';\n\nimport { presetManager } from '../../presets';\nimport { t } from '../../core/localizer';\nimport { uiField } from '../field';\nimport { utilArrayUnion, utilRebind } from '../../util';\n\n\nexport { uiFieldRadio as uiFieldStructureRadio };\n\n\nexport function uiFieldRadio(field, context) {\n var dispatch = d3_dispatch('change');\n var placeholder = d3_select(null);\n var wrap = d3_select(null);\n var labels = d3_select(null);\n var radios = d3_select(null);\n var radioData = (field.options || (field.strings && field.strings.options && Object.keys(field.strings.options)) || field.keys).slice(); // shallow copy\n var typeField;\n var layerField;\n var _oldType = {};\n var _entityIDs = [];\n\n\n function selectedKey() {\n var node = wrap.selectAll('.form-field-input-radio label.active input');\n return !node.empty() && node.datum();\n }\n\n\n function radio(selection) {\n selection.classed('preset-radio', true);\n\n wrap = selection.selectAll('.form-field-input-wrap')\n .data([0]);\n\n var enter = wrap.enter()\n .append('div')\n .attr('class', 'form-field-input-wrap form-field-input-radio');\n\n enter\n .append('span')\n .attr('class', 'placeholder');\n\n wrap = wrap\n .merge(enter);\n\n\n placeholder = wrap.selectAll('.placeholder');\n\n labels = wrap.selectAll('label')\n .data(radioData);\n\n enter = labels.enter()\n .append('label');\n\n enter\n .append('input')\n .attr('type', 'radio')\n .attr('name', field.id)\n .attr('value', function(d) { return field.t('options.' + d, { 'default': d }); })\n .attr('checked', false);\n\n enter\n .append('span')\n .text(function(d) { return field.t('options.' + d, { 'default': d }); });\n\n labels = labels\n .merge(enter);\n\n radios = labels.selectAll('input')\n .on('change', changeRadio);\n\n }\n\n\n function structureExtras(selection, tags) {\n var selected = selectedKey() || tags.layer !== undefined;\n var type = presetManager.field(selected);\n var layer = presetManager.field('layer');\n var showLayer = (selected === 'bridge' || selected === 'tunnel' || tags.layer !== undefined);\n\n\n var extrasWrap = selection.selectAll('.structure-extras-wrap')\n .data(selected ? [0] : []);\n\n extrasWrap.exit()\n .remove();\n\n extrasWrap = extrasWrap.enter()\n .append('div')\n .attr('class', 'structure-extras-wrap')\n .merge(extrasWrap);\n\n var list = extrasWrap.selectAll('ul')\n .data([0]);\n\n list = list.enter()\n .append('ul')\n .attr('class', 'rows')\n .merge(list);\n\n\n // Type\n if (type) {\n if (!typeField || typeField.id !== selected) {\n typeField = uiField(context, type, _entityIDs, { wrap: false })\n .on('change', changeType);\n }\n typeField.tags(tags);\n } else {\n typeField = null;\n }\n\n var typeItem = list.selectAll('.structure-type-item')\n .data(typeField ? [typeField] : [], function(d) { return d.id; });\n\n // Exit\n typeItem.exit()\n .remove();\n\n // Enter\n var typeEnter = typeItem.enter()\n .insert('li', ':first-child')\n .attr('class', 'labeled-input structure-type-item');\n\n typeEnter\n .append('span')\n .attr('class', 'label structure-label-type')\n .attr('for', 'preset-input-' + selected)\n .text(t('inspector.radio.structure.type'));\n\n typeEnter\n .append('div')\n .attr('class', 'structure-input-type-wrap');\n\n // Update\n typeItem = typeItem\n .merge(typeEnter);\n\n if (typeField) {\n typeItem.selectAll('.structure-input-type-wrap')\n .call(typeField.render);\n }\n\n\n // Layer\n if (layer && showLayer) {\n if (!layerField) {\n layerField = uiField(context, layer, _entityIDs, { wrap: false })\n .on('change', changeLayer);\n }\n layerField.tags(tags);\n field.keys = utilArrayUnion(field.keys, ['layer']);\n } else {\n layerField = null;\n field.keys = field.keys.filter(function(k) { return k !== 'layer'; });\n }\n\n var layerItem = list.selectAll('.structure-layer-item')\n .data(layerField ? [layerField] : []);\n\n // Exit\n layerItem.exit()\n .remove();\n\n // Enter\n var layerEnter = layerItem.enter()\n .append('li')\n .attr('class', 'labeled-input structure-layer-item');\n\n layerEnter\n .append('span')\n .attr('class', 'label structure-label-layer')\n .attr('for', 'preset-input-layer')\n .text(t('inspector.radio.structure.layer'));\n\n layerEnter\n .append('div')\n .attr('class', 'structure-input-layer-wrap');\n\n // Update\n layerItem = layerItem\n .merge(layerEnter);\n\n if (layerField) {\n layerItem.selectAll('.structure-input-layer-wrap')\n .call(layerField.render);\n }\n }\n\n\n function changeType(t, onInput) {\n var key = selectedKey();\n if (!key) return;\n\n var val = t[key];\n if (val !== 'no') {\n _oldType[key] = val;\n }\n\n if (field.type === 'structureRadio') {\n // remove layer if it should not be set\n if (val === 'no' ||\n (key !== 'bridge' && key !== 'tunnel') ||\n (key === 'tunnel' && val === 'building_passage')) {\n t.layer = undefined;\n }\n // add layer if it should be set\n if (t.layer === undefined) {\n if (key === 'bridge' && val !== 'no') {\n t.layer = '1';\n }\n if (key === 'tunnel' && val !== 'no' && val !== 'building_passage') {\n t.layer = '-1';\n }\n }\n }\n\n dispatch.call('change', this, t, onInput);\n }\n\n\n function changeLayer(t, onInput) {\n if (t.layer === '0') {\n t.layer = undefined;\n }\n dispatch.call('change', this, t, onInput);\n }\n\n\n function changeRadio() {\n var t = {};\n var activeKey;\n\n if (field.key) {\n t[field.key] = undefined;\n }\n\n radios.each(function(d) {\n var active = d3_select(this).property('checked');\n if (active) activeKey = d;\n\n if (field.key) {\n if (active) t[field.key] = d;\n } else {\n var val = _oldType[activeKey] || 'yes';\n t[d] = active ? val : undefined;\n }\n });\n\n if (field.type === 'structureRadio') {\n if (activeKey === 'bridge') {\n t.layer = '1';\n } else if (activeKey === 'tunnel' && t.tunnel !== 'building_passage') {\n t.layer = '-1';\n } else {\n t.layer = undefined;\n }\n }\n\n dispatch.call('change', this, t);\n }\n\n\n radio.tags = function(tags) {\n\n radios.property('checked', function(d) {\n if (field.key) {\n return tags[field.key] === d;\n }\n return !!(typeof tags[d] === 'string' && tags[d].toLowerCase() !== 'no');\n });\n\n function isMixed(d) {\n if (field.key) {\n return Array.isArray(tags[field.key]) && tags[field.key].includes(d);\n }\n return Array.isArray(tags[d]);\n }\n\n labels\n .classed('active', function(d) {\n if (field.key) {\n return (Array.isArray(tags[field.key]) && tags[field.key].includes(d))\n || tags[field.key] === d;\n }\n return Array.isArray(tags[d]) || !!(tags[d] && tags[d].toLowerCase() !== 'no');\n })\n .classed('mixed', isMixed)\n .attr('title', function(d) {\n return isMixed(d) ? t('inspector.unshared_value_tooltip') : null;\n });\n\n\n var selection = radios.filter(function() { return this.checked; });\n\n if (selection.empty()) {\n placeholder.text(t('inspector.none'));\n } else {\n placeholder.text(selection.attr('value'));\n _oldType[selection.datum()] = tags[selection.datum()];\n }\n\n if (field.type === 'structureRadio') {\n // For waterways without a tunnel tag, set 'culvert' as\n // the _oldType to default to if the user picks 'tunnel'\n if (!!tags.waterway && !_oldType.tunnel) {\n _oldType.tunnel = 'culvert';\n }\n\n wrap.call(structureExtras, tags);\n }\n };\n\n\n radio.focus = function() {\n radios.node().focus();\n };\n\n\n radio.entityIDs = function(val) {\n if (!arguments.length) return _entityIDs;\n _entityIDs = val;\n _oldType = {};\n return radio;\n };\n\n\n radio.isAllowed = function() {\n return _entityIDs.length === 1;\n };\n\n\n return utilRebind(radio, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { select as d3_select, event as d3_event } from 'd3-selection';\n\nimport { presetManager } from '../../presets';\nimport { prefs } from '../../core/preferences';\nimport { t, localizer } from '../../core/localizer';\nimport { actionRestrictTurn } from '../../actions/restrict_turn';\nimport { actionUnrestrictTurn } from '../../actions/unrestrict_turn';\nimport { behaviorBreathe } from '../../behavior/breathe';\nimport { geoExtent, geoRawMercator, geoVecScale, geoVecSubtract, geoZoomToScale } from '../../geo';\nimport { osmIntersection, osmInferRestriction, osmTurn, osmWay } from '../../osm';\nimport { svgLayers, svgLines, svgTurns, svgVertices } from '../../svg';\nimport { utilDisplayName, utilDisplayType, utilEntitySelector, utilFunctor, utilRebind } from '../../util';\nimport { utilGetDimensions, utilSetDimensions } from '../../util/dimensions';\n\n\nexport function uiFieldRestrictions(field, context) {\n var dispatch = d3_dispatch('change');\n var breathe = behaviorBreathe(context);\n\n prefs('turn-restriction-via-way', null); // remove old key\n var storedViaWay = prefs('turn-restriction-via-way0'); // use new key #6922\n var storedDistance = prefs('turn-restriction-distance');\n\n var _maxViaWay = storedViaWay !== null ? (+storedViaWay) : 0;\n var _maxDistance = storedDistance ? (+storedDistance) : 30;\n var _initialized = false;\n var _parent = d3_select(null); // the entire field\n var _container = d3_select(null); // just the map\n var _oldTurns;\n var _graph;\n var _vertexID;\n var _intersection;\n var _fromWayID;\n\n var _lastXPos;\n\n\n function restrictions(selection) {\n _parent = selection;\n\n // try to reuse the intersection, but always rebuild it if the graph has changed\n if (_vertexID && (context.graph() !== _graph || !_intersection)) {\n _graph = context.graph();\n _intersection = osmIntersection(_graph, _vertexID, _maxDistance);\n }\n\n // It's possible for there to be no actual intersection here.\n // for example, a vertex of two `highway=path`\n // In this case, hide the field.\n var isOK = (\n _intersection &&\n _intersection.vertices.length && // has vertices\n _intersection.vertices // has the vertex that the user selected\n .filter(function(vertex) { return vertex.id === _vertexID; }).length &&\n _intersection.ways.length > 2 && // has more than 2 ways\n _intersection.ways // has more than 1 TO way\n .filter(function(way) { return way.__to; }).length > 1\n );\n\n // Also hide in the case where\n d3_select(selection.node().parentNode).classed('hide', !isOK);\n\n // if form field is hidden or has detached from dom, clean up.\n if (!isOK ||\n !context.container().select('.inspector-wrap.inspector-hidden').empty() ||\n !selection.node().parentNode ||\n !selection.node().parentNode.parentNode) {\n selection.call(restrictions.off);\n return;\n }\n\n\n var wrap = selection.selectAll('.form-field-input-wrap')\n .data([0]);\n\n wrap = wrap.enter()\n .append('div')\n .attr('class', 'form-field-input-wrap form-field-input-' + field.type)\n .merge(wrap);\n\n var container = wrap.selectAll('.restriction-container')\n .data([0]);\n\n // enter\n var containerEnter = container.enter()\n .append('div')\n .attr('class', 'restriction-container');\n\n containerEnter\n .append('div')\n .attr('class', 'restriction-help');\n\n // update\n _container = containerEnter\n .merge(container)\n .call(renderViewer);\n\n var controls = wrap.selectAll('.restriction-controls')\n .data([0]);\n\n // enter/update\n controls.enter()\n .append('div')\n .attr('class', 'restriction-controls-container')\n .append('div')\n .attr('class', 'restriction-controls')\n .merge(controls)\n .call(renderControls);\n }\n\n\n function renderControls(selection) {\n var distControl = selection.selectAll('.restriction-distance')\n .data([0]);\n\n distControl.exit()\n .remove();\n\n var distControlEnter = distControl.enter()\n .append('div')\n .attr('class', 'restriction-control restriction-distance');\n\n distControlEnter\n .append('span')\n .attr('class', 'restriction-control-label restriction-distance-label')\n .text(t('restriction.controls.distance') + ':');\n\n distControlEnter\n .append('input')\n .attr('class', 'restriction-distance-input')\n .attr('type', 'range')\n .attr('min', '20')\n .attr('max', '50')\n .attr('step', '5');\n\n distControlEnter\n .append('span')\n .attr('class', 'restriction-distance-text');\n\n // update\n selection.selectAll('.restriction-distance-input')\n .property('value', _maxDistance)\n .on('input', function() {\n var val = d3_select(this).property('value');\n _maxDistance = +val;\n _intersection = null;\n _container.selectAll('.layer-osm .layer-turns *').remove();\n prefs('turn-restriction-distance', _maxDistance);\n _parent.call(restrictions);\n });\n\n selection.selectAll('.restriction-distance-text')\n .text(displayMaxDistance(_maxDistance));\n\n\n var viaControl = selection.selectAll('.restriction-via-way')\n .data([0]);\n\n viaControl.exit()\n .remove();\n\n var viaControlEnter = viaControl.enter()\n .append('div')\n .attr('class', 'restriction-control restriction-via-way');\n\n viaControlEnter\n .append('span')\n .attr('class', 'restriction-control-label restriction-via-way-label')\n .text(t('restriction.controls.via') + ':');\n\n viaControlEnter\n .append('input')\n .attr('class', 'restriction-via-way-input')\n .attr('type', 'range')\n .attr('min', '0')\n .attr('max', '2')\n .attr('step', '1');\n\n viaControlEnter\n .append('span')\n .attr('class', 'restriction-via-way-text');\n\n // update\n selection.selectAll('.restriction-via-way-input')\n .property('value', _maxViaWay)\n .on('input', function() {\n var val = d3_select(this).property('value');\n _maxViaWay = +val;\n _container.selectAll('.layer-osm .layer-turns *').remove();\n prefs('turn-restriction-via-way0', _maxViaWay);\n _parent.call(restrictions);\n });\n\n selection.selectAll('.restriction-via-way-text')\n .text(displayMaxVia(_maxViaWay));\n }\n\n\n function renderViewer(selection) {\n if (!_intersection) return;\n\n var vgraph = _intersection.graph;\n var filter = utilFunctor(true);\n var projection = geoRawMercator();\n\n // Reflow warning: `utilGetDimensions` calls `getBoundingClientRect`\n // Instead of asking the restriction-container for its dimensions,\n // we can ask the .sidebar, which can have its dimensions cached.\n // width: calc as sidebar - padding\n // height: hardcoded (from `80_app.css`)\n // var d = utilGetDimensions(selection);\n var sdims = utilGetDimensions(context.container().select('.sidebar'));\n var d = [ sdims[0] - 50, 370 ];\n var c = geoVecScale(d, 0.5);\n var z = 22;\n\n projection.scale(geoZoomToScale(z));\n\n // Calculate extent of all key vertices\n var extent = geoExtent();\n for (var i = 0; i < _intersection.vertices.length; i++) {\n extent._extend(_intersection.vertices[i].extent());\n }\n\n // If this is a large intersection, adjust zoom to fit extent\n if (_intersection.vertices.length > 1) {\n var padding = 180; // in z22 pixels\n var tl = projection([extent[0][0], extent[1][1]]);\n var br = projection([extent[1][0], extent[0][1]]);\n var hFactor = (br[0] - tl[0]) / (d[0] - padding);\n var vFactor = (br[1] - tl[1]) / (d[1] - padding);\n var hZoomDiff = Math.log(Math.abs(hFactor)) / Math.LN2;\n var vZoomDiff = Math.log(Math.abs(vFactor)) / Math.LN2;\n z = z - Math.max(hZoomDiff, vZoomDiff);\n projection.scale(geoZoomToScale(z));\n }\n\n var padTop = 35; // reserve top space for hint text\n var extentCenter = projection(extent.center());\n extentCenter[1] = extentCenter[1] - padTop;\n\n projection\n .translate(geoVecSubtract(c, extentCenter))\n .clipExtent([[0, 0], d]);\n\n var drawLayers = svgLayers(projection, context).only(['osm','touch']).dimensions(d);\n var drawVertices = svgVertices(projection, context);\n var drawLines = svgLines(projection, context);\n var drawTurns = svgTurns(projection, context);\n\n var firstTime = selection.selectAll('.surface').empty();\n\n selection\n .call(drawLayers);\n\n var surface = selection.selectAll('.surface')\n .classed('tr', true);\n\n if (firstTime) {\n _initialized = true;\n\n surface\n .call(breathe);\n }\n\n // This can happen if we've lowered the detail while a FROM way\n // is selected, and that way is no longer part of the intersection.\n if (_fromWayID && !vgraph.hasEntity(_fromWayID)) {\n _fromWayID = null;\n _oldTurns = null;\n }\n\n surface\n .call(utilSetDimensions, d)\n .call(drawVertices, vgraph, _intersection.vertices, filter, extent, z)\n .call(drawLines, vgraph, _intersection.ways, filter)\n .call(drawTurns, vgraph, _intersection.turns(_fromWayID, _maxViaWay));\n\n surface\n .on('click.restrictions', click)\n .on('mouseover.restrictions', mouseover);\n\n surface\n .selectAll('.selected')\n .classed('selected', false);\n\n surface\n .selectAll('.related')\n .classed('related', false);\n\n if (_fromWayID) {\n var way = vgraph.entity(_fromWayID);\n surface\n .selectAll('.' + _fromWayID)\n .classed('selected', true)\n .classed('related', true);\n }\n\n document.addEventListener('resizeWindow', function () {\n utilSetDimensions(_container, null);\n redraw(1);\n }, false);\n\n updateHints(null);\n\n\n function click() {\n surface\n .call(breathe.off)\n .call(breathe);\n\n var datum = d3_event.target.__data__;\n var entity = datum && datum.properties && datum.properties.entity;\n if (entity) {\n datum = entity;\n }\n\n if (datum instanceof osmWay && (datum.__from || datum.__via)) {\n _fromWayID = datum.id;\n _oldTurns = null;\n redraw();\n\n } else if (datum instanceof osmTurn) {\n var actions, extraActions, turns, i;\n var restrictionType = osmInferRestriction(vgraph, datum, projection);\n\n if (datum.restrictionID && !datum.direct) {\n return;\n\n } else if (datum.restrictionID && !datum.only) { // NO -> ONLY\n var seen = {};\n var datumOnly = JSON.parse(JSON.stringify(datum)); // deep clone the datum\n datumOnly.only = true; // but change this property\n restrictionType = restrictionType.replace(/^no/, 'only');\n\n // Adding an ONLY restriction should destroy all other direct restrictions from the FROM towards the VIA.\n // We will remember them in _oldTurns, and restore them if the user clicks again.\n turns = _intersection.turns(_fromWayID, 2);\n extraActions = [];\n _oldTurns = [];\n for (i = 0; i < turns.length; i++) {\n var turn = turns[i];\n if (seen[turn.restrictionID]) continue; // avoid deleting the turn twice (#4968, #4928)\n\n if (turn.direct && turn.path[1] === datum.path[1]) {\n seen[turns[i].restrictionID] = true;\n turn.restrictionType = osmInferRestriction(vgraph, turn, projection);\n _oldTurns.push(turn);\n extraActions.push(actionUnrestrictTurn(turn));\n }\n }\n\n actions = _intersection.actions.concat(extraActions, [\n actionRestrictTurn(datumOnly, restrictionType),\n t('operations.restriction.annotation.create')\n ]);\n\n } else if (datum.restrictionID) { // ONLY -> Allowed\n // Restore whatever restrictions we might have destroyed by cycling thru the ONLY state.\n // This relies on the assumption that the intersection was already split up when we\n // performed the previous action (NO -> ONLY), so the IDs in _oldTurns shouldn't have changed.\n turns = _oldTurns || [];\n extraActions = [];\n for (i = 0; i < turns.length; i++) {\n if (turns[i].key !== datum.key) {\n extraActions.push(actionRestrictTurn(turns[i], turns[i].restrictionType));\n }\n }\n _oldTurns = null;\n\n actions = _intersection.actions.concat(extraActions, [\n actionUnrestrictTurn(datum),\n t('operations.restriction.annotation.delete')\n ]);\n\n } else { // Allowed -> NO\n actions = _intersection.actions.concat([\n actionRestrictTurn(datum, restrictionType),\n t('operations.restriction.annotation.create')\n ]);\n }\n\n context.perform.apply(context, actions);\n\n // At this point the datum will be changed, but will have same key..\n // Refresh it and update the help..\n var s = surface.selectAll('.' + datum.key);\n datum = s.empty() ? null : s.datum();\n updateHints(datum);\n\n } else {\n _fromWayID = null;\n _oldTurns = null;\n redraw();\n }\n }\n\n\n function mouseover() {\n var datum = d3_event.target.__data__;\n updateHints(datum);\n }\n\n _lastXPos = _lastXPos || sdims[0];\n\n function redraw(minChange) {\n var xPos = -1;\n\n if (minChange) {\n xPos = utilGetDimensions(context.container().select('.sidebar'))[0];\n }\n\n if (!minChange || (minChange && Math.abs(xPos - _lastXPos) >= minChange)) {\n if (context.hasEntity(_vertexID)) {\n _lastXPos = xPos;\n _container.call(renderViewer);\n }\n }\n }\n\n\n function highlightPathsFrom(wayID) {\n surface.selectAll('.related')\n .classed('related', false)\n .classed('allow', false)\n .classed('restrict', false)\n .classed('only', false);\n\n surface.selectAll('.' + wayID)\n .classed('related', true);\n\n if (wayID) {\n var turns = _intersection.turns(wayID, _maxViaWay);\n for (var i = 0; i < turns.length; i++) {\n var turn = turns[i];\n var ids = [turn.to.way];\n var klass = (turn.no ? 'restrict' : (turn.only ? 'only' : 'allow'));\n\n if (turn.only || turns.length === 1) {\n if (turn.via.ways) {\n ids = ids.concat(turn.via.ways);\n }\n } else if (turn.to.way === wayID) {\n continue;\n }\n\n surface.selectAll(utilEntitySelector(ids))\n .classed('related', true)\n .classed('allow', (klass === 'allow'))\n .classed('restrict', (klass === 'restrict'))\n .classed('only', (klass === 'only'));\n }\n }\n }\n\n\n function updateHints(datum) {\n var help = _container.selectAll('.restriction-help').html('');\n\n var placeholders = {};\n ['from', 'via', 'to'].forEach(function(k) {\n placeholders[k] = '' + t('restriction.help.' + k) + ' ';\n });\n\n var entity = datum && datum.properties && datum.properties.entity;\n if (entity) {\n datum = entity;\n }\n\n if (_fromWayID) {\n way = vgraph.entity(_fromWayID);\n surface\n .selectAll('.' + _fromWayID)\n .classed('selected', true)\n .classed('related', true);\n }\n\n // Hovering a way\n if (datum instanceof osmWay && datum.__from) {\n way = datum;\n\n highlightPathsFrom(_fromWayID ? null : way.id);\n surface.selectAll('.' + way.id)\n .classed('related', true);\n\n var clickSelect = (!_fromWayID || _fromWayID !== way.id);\n help\n .append('div') // \"Click to select FROM {fromName}.\" / \"FROM {fromName}\"\n .html(t('restriction.help.' + (clickSelect ? 'select_from_name' : 'from_name'), {\n from: placeholders.from,\n fromName: displayName(way.id, vgraph)\n }));\n\n\n // Hovering a turn arrow\n } else if (datum instanceof osmTurn) {\n var restrictionType = osmInferRestriction(vgraph, datum, projection);\n var turnType = restrictionType.replace(/^(only|no)\\_/, '');\n var indirect = (datum.direct === false ? t('restriction.help.indirect') : '');\n var klass, turnText, nextText;\n\n if (datum.no) {\n klass = 'restrict';\n turnText = t('restriction.help.turn.no_' + turnType, { indirect: indirect });\n nextText = t('restriction.help.turn.only_' + turnType, { indirect: '' });\n } else if (datum.only) {\n klass = 'only';\n turnText = t('restriction.help.turn.only_' + turnType, { indirect: indirect });\n nextText = t('restriction.help.turn.allowed_' + turnType, { indirect: '' });\n } else {\n klass = 'allow';\n turnText = t('restriction.help.turn.allowed_' + turnType, { indirect: indirect });\n nextText = t('restriction.help.turn.no_' + turnType, { indirect: '' });\n }\n\n help\n .append('div') // \"NO Right Turn (indirect)\"\n .attr('class', 'qualifier ' + klass)\n .text(turnText);\n\n help\n .append('div') // \"FROM {fromName} TO {toName}\"\n .html(t('restriction.help.from_name_to_name', {\n from: placeholders.from,\n fromName: displayName(datum.from.way, vgraph),\n to: placeholders.to,\n toName: displayName(datum.to.way, vgraph)\n }));\n\n if (datum.via.ways && datum.via.ways.length) {\n var names = [];\n for (var i = 0; i < datum.via.ways.length; i++) {\n var prev = names[names.length - 1];\n var curr = displayName(datum.via.ways[i], vgraph);\n if (!prev || curr !== prev) // collapse identical names\n names.push(curr);\n }\n\n help\n .append('div') // \"VIA {viaNames}\"\n .html(t('restriction.help.via_names', {\n via: placeholders.via,\n viaNames: names.join(', ')\n }));\n }\n\n if (!indirect) {\n help\n .append('div') // Click for \"No Right Turn\"\n .text(t('restriction.help.toggle', { turn: nextText.trim() }));\n }\n\n highlightPathsFrom(null);\n var alongIDs = datum.path.slice();\n surface.selectAll(utilEntitySelector(alongIDs))\n .classed('related', true)\n .classed('allow', (klass === 'allow'))\n .classed('restrict', (klass === 'restrict'))\n .classed('only', (klass === 'only'));\n\n\n // Hovering empty surface\n } else {\n highlightPathsFrom(null);\n if (_fromWayID) {\n help\n .append('div') // \"FROM {fromName}\"\n .html(t('restriction.help.from_name', {\n from: placeholders.from,\n fromName: displayName(_fromWayID, vgraph)\n }));\n\n } else {\n help\n .append('div') // \"Click to select a FROM segment.\"\n .html(t('restriction.help.select_from', {\n from: placeholders.from\n }));\n }\n }\n }\n }\n\n\n function displayMaxDistance(maxDist) {\n var isImperial = !localizer.usesMetric();\n var opts;\n\n if (isImperial) {\n var distToFeet = { // imprecise conversion for prettier display\n 20: 70, 25: 85, 30: 100, 35: 115, 40: 130, 45: 145, 50: 160\n }[maxDist];\n opts = { distance: t('units.feet', { quantity: distToFeet }) };\n } else {\n opts = { distance: t('units.meters', { quantity: maxDist }) };\n }\n\n return t('restriction.controls.distance_up_to', opts);\n }\n\n\n function displayMaxVia(maxVia) {\n return maxVia === 0 ? t('restriction.controls.via_node_only')\n : maxVia === 1 ? t('restriction.controls.via_up_to_one')\n : t('restriction.controls.via_up_to_two');\n }\n\n\n function displayName(entityID, graph) {\n var entity = graph.entity(entityID);\n var name = utilDisplayName(entity) || '';\n var matched = presetManager.match(entity, graph);\n var type = (matched && matched.name()) || utilDisplayType(entity.id);\n return name || type;\n }\n\n\n restrictions.entityIDs = function(val) {\n _intersection = null;\n _fromWayID = null;\n _oldTurns = null;\n _vertexID = val[0];\n };\n\n\n restrictions.tags = function() {};\n restrictions.focus = function() {};\n\n\n restrictions.off = function(selection) {\n if (!_initialized) return;\n\n selection.selectAll('.surface')\n .call(breathe.off)\n .on('click.restrictions', null)\n .on('mouseover.restrictions', null);\n\n d3_select(window)\n .on('resize.restrictions', null);\n };\n\n\n return utilRebind(restrictions, dispatch, 'on');\n}\n\nuiFieldRestrictions.supportsMultiselection = false;\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { select as d3_select } from 'd3-selection';\n\nimport { t } from '../../core/localizer';\nimport {\n utilGetSetValue,\n utilNoAuto,\n utilRebind\n} from '../../util';\n\n\nexport function uiFieldTextarea(field, context) {\n var dispatch = d3_dispatch('change');\n var input = d3_select(null);\n var _tags;\n\n\n function textarea(selection) {\n var wrap = selection.selectAll('.form-field-input-wrap')\n .data([0]);\n\n wrap = wrap.enter()\n .append('div')\n .attr('class', 'form-field-input-wrap form-field-input-' + field.type)\n .merge(wrap);\n\n input = wrap.selectAll('textarea')\n .data([0]);\n\n input = input.enter()\n .append('textarea')\n .attr('id', field.domId)\n .call(utilNoAuto)\n .on('input', change(true))\n .on('blur', change())\n .on('change', change())\n .merge(input);\n }\n\n\n function change(onInput) {\n return function() {\n\n var val = utilGetSetValue(input);\n if (!onInput) val = context.cleanTagValue(val);\n\n // don't override multiple values with blank string\n if (!val && Array.isArray(_tags[field.key])) return;\n\n var t = {};\n t[field.key] = val || undefined;\n dispatch.call('change', this, t, onInput);\n };\n }\n\n\n textarea.tags = function(tags) {\n _tags = tags;\n\n var isMixed = Array.isArray(tags[field.key]);\n\n utilGetSetValue(input, !isMixed && tags[field.key] ? tags[field.key] : '')\n .attr('title', isMixed ? tags[field.key].filter(Boolean).join('\\n') : undefined)\n .attr('placeholder', isMixed ? t('inspector.multiple_values') : (field.placeholder() || t('inspector.unknown')))\n .classed('mixed', isMixed);\n };\n\n\n textarea.focus = function() {\n input.node().focus();\n };\n\n\n return utilRebind(textarea, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\n\nimport {\n select as d3_select,\n event as d3_event\n} from 'd3-selection';\n\nimport { uiCombobox } from '../combobox';\n\nimport { actionChangeTags } from '../../actions/change_tags';\nimport { services } from '../../services/index';\n\nimport { svgIcon } from '../../svg/icon';\nimport {\n utilGetSetValue,\n utilNoAuto,\n utilRebind\n} from '../../util';\n\nimport { t } from '../../core/localizer';\n\n\nexport function uiFieldWikidata(field, context) {\n var wikidata = services.wikidata;\n var dispatch = d3_dispatch('change');\n\n var _selection = d3_select(null);\n var _searchInput = d3_select(null);\n var _qid = null;\n var _wikidataEntity = null;\n var _wikiURL = '';\n var _entityIDs = [];\n\n var _wikipediaKey = field.keys && field.keys.find(function(key) {\n return key.includes('wikipedia');\n }),\n _hintKey = field.key === 'wikidata' ? 'name' : field.key.split(':')[0];\n\n var combobox = uiCombobox(context, 'combo-' + field.safeid)\n .caseSensitive(true)\n .minItems(1);\n\n function wiki(selection) {\n\n _selection = selection;\n\n var wrap = selection.selectAll('.form-field-input-wrap')\n .data([0]);\n\n wrap = wrap.enter()\n .append('div')\n .attr('class', 'form-field-input-wrap form-field-input-' + field.type)\n .merge(wrap);\n\n\n var list = wrap.selectAll('ul')\n .data([0]);\n\n list = list.enter()\n .append('ul')\n .attr('class', 'rows')\n .merge(list);\n\n var searchRow = list.selectAll('li.wikidata-search')\n .data([0]);\n\n var searchRowEnter = searchRow.enter()\n .append('li')\n .attr('class', 'wikidata-search');\n\n searchRowEnter\n .append('input')\n .attr('type', 'text')\n .attr('id', field.domId)\n .style('flex', '1')\n .call(utilNoAuto)\n .on('focus', function() {\n var node = d3_select(this).node();\n node.setSelectionRange(0, node.value.length);\n })\n .on('blur', function() {\n setLabelForEntity();\n })\n .call(combobox.fetcher(fetchWikidataItems));\n\n combobox.on('accept', function(d) {\n _qid = d.id;\n change();\n }).on('cancel', function() {\n setLabelForEntity();\n });\n\n searchRowEnter\n .append('button')\n .attr('class', 'form-field-button wiki-link')\n .attr('title', t('icons.view_on', { domain: 'wikidata.org' }))\n .attr('tabindex', -1)\n .call(svgIcon('#iD-icon-out-link'))\n .on('click', function() {\n d3_event.preventDefault();\n if (_wikiURL) window.open(_wikiURL, '_blank');\n });\n\n searchRow = searchRow.merge(searchRowEnter);\n\n _searchInput = searchRow.select('input');\n\n var wikidataProperties = ['description', 'identifier'];\n\n var items = list.selectAll('li.labeled-input')\n .data(wikidataProperties);\n\n // Enter\n var enter = items.enter()\n .append('li')\n .attr('class', function(d) { return 'labeled-input preset-wikidata-' + d; });\n\n enter\n .append('span')\n .attr('class', 'label')\n .text(function(d) { return t('wikidata.' + d); });\n\n enter\n .append('input')\n .attr('type', 'text')\n .call(utilNoAuto)\n .classed('disabled', 'true')\n .attr('readonly', 'true');\n\n enter\n .append('button')\n .attr('class', 'form-field-button')\n .attr('title', t('icons.copy'))\n .attr('tabindex', -1)\n .call(svgIcon('#iD-operation-copy'))\n .on('click', function() {\n d3_event.preventDefault();\n d3_select(this.parentNode)\n .select('input')\n .node()\n .select();\n document.execCommand('copy');\n });\n\n }\n\n function fetchWikidataItems(q, callback) {\n\n if (!q && _hintKey) {\n // other tags may be good search terms\n for (var i in _entityIDs) {\n var entity = context.hasEntity(_entityIDs[i]);\n if (entity.tags[_hintKey]) {\n q = entity.tags[_hintKey];\n break;\n }\n }\n }\n\n wikidata.itemsForSearchQuery(q, function(err, data) {\n if (err) return;\n\n for (var i in data) {\n data[i].value = data[i].label + ' (' + data[i].id + ')';\n data[i].title = data[i].description;\n }\n\n if (callback) callback(data);\n });\n }\n\n\n function change() {\n var syncTags = {};\n syncTags[field.key] = _qid;\n dispatch.call('change', this, syncTags);\n\n // attempt asynchronous update of wikidata tag..\n var initGraph = context.graph();\n var initEntityIDs = _entityIDs;\n\n wikidata.entityByQID(_qid, function(err, entity) {\n if (err) return;\n\n // If graph has changed, we can't apply this update.\n if (context.graph() !== initGraph) return;\n\n if (!entity.sitelinks) return;\n\n var langs = wikidata.languagesToQuery();\n // use the label and description languages as fallbacks\n ['labels', 'descriptions'].forEach(function(key) {\n if (!entity[key]) return;\n\n var valueLangs = Object.keys(entity[key]);\n if (valueLangs.length === 0) return;\n var valueLang = valueLangs[0];\n\n if (langs.indexOf(valueLang) === -1) {\n langs.push(valueLang);\n }\n });\n\n var newWikipediaValue;\n\n if (_wikipediaKey) {\n var foundPreferred;\n for (var i in langs) {\n var lang = langs[i];\n var siteID = lang.replace('-', '_') + 'wiki';\n if (entity.sitelinks[siteID]) {\n foundPreferred = true;\n newWikipediaValue = lang + ':' + entity.sitelinks[siteID].title;\n // use the first match\n break;\n }\n }\n\n if (!foundPreferred) {\n // No wikipedia sites available in the user's language or the fallback languages,\n // default to any wikipedia sitelink\n\n var wikiSiteKeys = Object.keys(entity.sitelinks).filter(function(site) {\n return site.endsWith('wiki');\n });\n\n if (wikiSiteKeys.length === 0) {\n // if no wikipedia pages are linked to this wikidata entity, delete that tag\n newWikipediaValue = null;\n } else {\n var wikiLang = wikiSiteKeys[0].slice(0, -4).replace('_', '-');\n var wikiTitle = entity.sitelinks[wikiSiteKeys[0]].title;\n newWikipediaValue = wikiLang + ':' + wikiTitle;\n }\n }\n }\n\n if (newWikipediaValue) {\n newWikipediaValue = context.cleanTagValue(newWikipediaValue);\n }\n\n if (typeof newWikipediaValue === 'undefined') return;\n\n var actions = initEntityIDs.map(function(entityID) {\n var entity = context.hasEntity(entityID);\n if (!entity) return;\n\n var currTags = Object.assign({}, entity.tags); // shallow copy\n if (newWikipediaValue === null) {\n if (!currTags[_wikipediaKey]) return;\n\n delete currTags[_wikipediaKey];\n } else {\n currTags[_wikipediaKey] = newWikipediaValue;\n }\n\n return actionChangeTags(entityID, currTags);\n }).filter(Boolean);\n\n if (!actions.length) return;\n\n // Coalesce the update of wikidata tag into the previous tag change\n context.overwrite(\n function actionUpdateWikipediaTags(graph) {\n actions.forEach(function(action) {\n graph = action(graph);\n });\n return graph;\n },\n context.history().undoAnnotation()\n );\n\n // do not dispatch.call('change') here, because entity_editor\n // changeTags() is not intended to be called asynchronously\n });\n }\n\n function setLabelForEntity() {\n var label = '';\n if (_wikidataEntity) {\n label = entityPropertyForDisplay(_wikidataEntity, 'labels');\n if (label.length === 0) {\n label = _wikidataEntity.id.toString();\n }\n }\n utilGetSetValue(_searchInput, label);\n }\n\n\n wiki.tags = function(tags) {\n\n var isMixed = Array.isArray(tags[field.key]);\n _searchInput\n .attr('title', isMixed ? tags[field.key].filter(Boolean).join('\\n') : null)\n .attr('placeholder', isMixed ? t('inspector.multiple_values') : '')\n .classed('mixed', isMixed);\n\n _qid = typeof tags[field.key] === 'string' && tags[field.key] || '';\n\n if (!/^Q[0-9]*$/.test(_qid)) { // not a proper QID\n unrecognized();\n return;\n }\n\n // QID value in correct format\n _wikiURL = 'https://wikidata.org/wiki/' + _qid;\n wikidata.entityByQID(_qid, function(err, entity) {\n if (err) {\n unrecognized();\n return;\n }\n _wikidataEntity = entity;\n\n setLabelForEntity();\n\n var description = entityPropertyForDisplay(entity, 'descriptions');\n\n _selection.select('button.wiki-link')\n .classed('disabled', false);\n\n _selection.select('.preset-wikidata-description')\n .style('display', function(){\n return description.length > 0 ? 'flex' : 'none';\n })\n .select('input')\n .attr('value', description);\n\n _selection.select('.preset-wikidata-identifier')\n .style('display', function(){\n return entity.id ? 'flex' : 'none';\n })\n .select('input')\n .attr('value', entity.id);\n });\n\n\n // not a proper QID\n function unrecognized() {\n _wikidataEntity = null;\n setLabelForEntity();\n\n _selection.select('.preset-wikidata-description')\n .style('display', 'none');\n _selection.select('.preset-wikidata-identifier')\n .style('display', 'none');\n\n _selection.select('button.wiki-link')\n .classed('disabled', true);\n\n if (_qid && _qid !== '') {\n _wikiURL = 'https://wikidata.org/wiki/Special:Search?search=' + _qid;\n } else {\n _wikiURL = '';\n }\n }\n };\n\n function entityPropertyForDisplay(wikidataEntity, propKey) {\n if (!wikidataEntity[propKey]) return '';\n var propObj = wikidataEntity[propKey];\n var langKeys = Object.keys(propObj);\n if (langKeys.length === 0) return '';\n // sorted by priority, since we want to show the user's language first if possible\n var langs = wikidata.languagesToQuery();\n for (var i in langs) {\n var lang = langs[i];\n var valueObj = propObj[lang];\n if (valueObj && valueObj.value && valueObj.value.length > 0) return valueObj.value;\n }\n // default to any available value\n return propObj[langKeys[0]].value;\n }\n\n\n wiki.entityIDs = function(val) {\n if (!arguments.length) return _entityIDs;\n _entityIDs = val;\n return wiki;\n };\n\n\n wiki.focus = function() {\n _searchInput.node().focus();\n };\n\n\n return utilRebind(wiki, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { select as d3_select, event as d3_event } from 'd3-selection';\n\nimport { fileFetcher } from '../../core/file_fetcher';\nimport { t, localizer } from '../../core/localizer';\nimport { actionChangeTags } from '../../actions/change_tags';\nimport { services } from '../../services/index';\nimport { svgIcon } from '../../svg/icon';\nimport { uiCombobox } from '../combobox';\nimport { utilGetSetValue, utilNoAuto, utilRebind } from '../../util';\n\n\nexport function uiFieldWikipedia(field, context) {\n const dispatch = d3_dispatch('change');\n const wikipedia = services.wikipedia;\n const wikidata = services.wikidata;\n let _langInput = d3_select(null);\n let _titleInput = d3_select(null);\n let _wikiURL = '';\n let _entityIDs;\n let _tags;\n\n let _dataWikipedia = [];\n fileFetcher.get('wmf_sitematrix')\n .then(d => {\n _dataWikipedia = d;\n if (_tags) updateForTags(_tags);\n })\n .catch(() => { /* ignore */ });\n\n\n const langCombo = uiCombobox(context, 'wikipedia-lang')\n .fetcher((value, callback) => {\n const v = value.toLowerCase();\n callback(_dataWikipedia\n .filter(d => {\n return d[0].toLowerCase().indexOf(v) >= 0 ||\n d[1].toLowerCase().indexOf(v) >= 0 ||\n d[2].toLowerCase().indexOf(v) >= 0;\n })\n .map(d => ({ value: d[1] }))\n );\n });\n\n const titleCombo = uiCombobox(context, 'wikipedia-title')\n .fetcher((value, callback) => {\n if (!value) {\n value = '';\n for (let i in _entityIDs) {\n let entity = context.hasEntity(_entityIDs[i]);\n if (entity.tags.name) {\n value = entity.tags.name;\n break;\n }\n }\n }\n const searchfn = value.length > 7 ? wikipedia.search : wikipedia.suggestions;\n searchfn(language()[2], value, (query, data) => {\n callback( data.map(d => ({ value: d })) );\n });\n });\n\n\n function wiki(selection) {\n let wrap = selection.selectAll('.form-field-input-wrap')\n .data([0]);\n\n wrap = wrap.enter()\n .append('div')\n .attr('class', `form-field-input-wrap form-field-input-${field.type}`)\n .merge(wrap);\n\n\n let langContainer = wrap.selectAll('.wiki-lang-container')\n .data([0]);\n\n langContainer = langContainer.enter()\n .append('div')\n .attr('class', 'wiki-lang-container')\n .merge(langContainer);\n\n\n _langInput = langContainer.selectAll('input.wiki-lang')\n .data([0]);\n\n _langInput = _langInput.enter()\n .append('input')\n .attr('type', 'text')\n .attr('class', 'wiki-lang')\n .attr('placeholder', t('translate.localized_translation_language'))\n .call(utilNoAuto)\n .call(langCombo)\n .merge(_langInput);\n\n utilGetSetValue(_langInput, language()[1]);\n\n _langInput\n .on('blur', changeLang)\n .on('change', changeLang);\n\n\n let titleContainer = wrap.selectAll('.wiki-title-container')\n .data([0]);\n\n titleContainer = titleContainer.enter()\n .append('div')\n .attr('class', 'wiki-title-container')\n .merge(titleContainer);\n\n _titleInput = titleContainer.selectAll('input.wiki-title')\n .data([0]);\n\n _titleInput = _titleInput.enter()\n .append('input')\n .attr('type', 'text')\n .attr('class', 'wiki-title')\n .attr('id', field.domId)\n .call(utilNoAuto)\n .call(titleCombo)\n .merge(_titleInput);\n\n _titleInput\n .on('blur', blur)\n .on('change', change);\n\n\n let link = titleContainer.selectAll('.wiki-link')\n .data([0]);\n\n link = link.enter()\n .append('button')\n .attr('class', 'form-field-button wiki-link')\n .attr('tabindex', -1)\n .attr('title', t('icons.view_on', { domain: 'wikipedia.org' }))\n .call(svgIcon('#iD-icon-out-link'))\n .merge(link);\n\n link\n .on('click', () => {\n d3_event.preventDefault();\n if (_wikiURL) window.open(_wikiURL, '_blank');\n });\n }\n\n\n function language() {\n const value = utilGetSetValue(_langInput).toLowerCase();\n const locale = localizer.localeCode().toLowerCase();\n let localeLanguage;\n return _dataWikipedia.find(d => {\n if (d[2] === locale) localeLanguage = d;\n return d[0].toLowerCase() === value || d[1].toLowerCase() === value || d[2] === value;\n }) || localeLanguage || ['English', 'English', 'en'];\n }\n\n\n function changeLang() {\n utilGetSetValue(_langInput, language()[1]);\n change(true);\n }\n\n\n function blur() {\n change(true);\n }\n\n\n function change(skipWikidata) {\n let value = utilGetSetValue(_titleInput);\n const m = value.match(/https?:\\/\\/([-a-z]+)\\.wikipedia\\.org\\/(?:wiki|\\1-[-a-z]+)\\/([^#]+)(?:#(.+))?/);\n const l = m && _dataWikipedia.find(d => m[1] === d[2]);\n let syncTags = {};\n\n if (l) {\n // Normalize title http://www.mediawiki.org/wiki/API:Query#Title_normalization\n value = decodeURIComponent(m[2]).replace(/_/g, ' ');\n if (m[3]) {\n let anchor;\n // try {\n // leave this out for now - #6232\n // Best-effort `anchordecode:` implementation\n // anchor = decodeURIComponent(m[3].replace(/\\.([0-9A-F]{2})/g, '%$1'));\n // } catch (e) {\n anchor = decodeURIComponent(m[3]);\n // }\n value += '#' + anchor.replace(/_/g, ' ');\n }\n value = value.slice(0, 1).toUpperCase() + value.slice(1);\n utilGetSetValue(_langInput, l[1]);\n utilGetSetValue(_titleInput, value);\n }\n\n if (value) {\n syncTags.wikipedia = context.cleanTagValue(language()[2] + ':' + value);\n } else {\n syncTags.wikipedia = undefined;\n }\n\n dispatch.call('change', this, syncTags);\n\n\n if (skipWikidata || !value || !language()[2]) return;\n\n // attempt asynchronous update of wikidata tag..\n const initGraph = context.graph();\n const initEntityIDs = _entityIDs;\n\n wikidata.itemsByTitle(language()[2], value, (err, data) => {\n if (err || !data || !Object.keys(data).length) return;\n\n // If graph has changed, we can't apply this update.\n if (context.graph() !== initGraph) return;\n\n const qids = Object.keys(data);\n const value = qids && qids.find(id => id.match(/^Q\\d+$/));\n\n let actions = initEntityIDs.map((entityID) => {\n let entity = context.entity(entityID).tags;\n let currTags = Object.assign({}, entity); // shallow copy\n if (currTags.wikidata !== value) {\n currTags.wikidata = value;\n return actionChangeTags(entityID, currTags);\n }\n }).filter(Boolean);\n\n if (!actions.length) return;\n\n // Coalesce the update of wikidata tag into the previous tag change\n context.overwrite(\n function actionUpdateWikidataTags(graph) {\n actions.forEach(function(action) {\n graph = action(graph);\n });\n return graph;\n },\n context.history().undoAnnotation()\n );\n\n // do not dispatch.call('change') here, because entity_editor\n // changeTags() is not intended to be called asynchronously\n });\n }\n\n\n wiki.tags = (tags) => {\n _tags = tags;\n updateForTags(tags);\n };\n\n function updateForTags(tags) {\n\n const value = typeof tags[field.key] === 'string' ? tags[field.key] : '';\n const m = value.match(/([^:]+):([^#]+)(?:#(.+))?/);\n const l = m && _dataWikipedia.find(d => m[1] === d[2]);\n let anchor = m && m[3];\n\n // value in correct format\n if (l) {\n utilGetSetValue(_langInput, l[1]);\n utilGetSetValue(_titleInput, m[2] + (anchor ? ('#' + anchor) : ''));\n if (anchor) {\n try {\n // Best-effort `anchorencode:` implementation\n anchor = encodeURIComponent(anchor.replace(/ /g, '_')).replace(/%/g, '.');\n } catch (e) {\n anchor = anchor.replace(/ /g, '_');\n }\n }\n _wikiURL = 'https://' + m[1] + '.wikipedia.org/wiki/' +\n m[2].replace(/ /g, '_') + (anchor ? ('#' + anchor) : '');\n\n // unrecognized value format\n } else {\n utilGetSetValue(_titleInput, value);\n if (value && value !== '') {\n utilGetSetValue(_langInput, '');\n _wikiURL = `https://en.wikipedia.org/wiki/Special:Search?search=${value}`;\n } else {\n _wikiURL = '';\n }\n }\n }\n\n\n wiki.entityIDs = (val) => {\n if (!arguments.length) return _entityIDs;\n _entityIDs = val;\n return wiki;\n };\n\n\n wiki.focus = () => {\n _titleInput.node().focus();\n };\n\n\n return utilRebind(wiki, dispatch, 'on');\n}\n\nuiFieldWikipedia.supportsMultiselection = false;\n","export * from './check';\nexport * from './combo';\nexport * from './input';\nexport * from './access';\nexport * from './address';\nexport * from './cycleway';\nexport * from './lanes';\nexport * from './localized';\nexport * from './maxspeed';\nexport * from './radio';\nexport * from './restrictions';\nexport * from './textarea';\nexport * from './wikidata';\nexport * from './wikipedia';\n\nimport {\n uiFieldCheck,\n uiFieldDefaultCheck,\n uiFieldOnewayCheck\n} from './check';\n\nimport {\n uiFieldCombo,\n uiFieldMultiCombo,\n uiFieldNetworkCombo,\n uiFieldSemiCombo,\n uiFieldTypeCombo\n} from './combo';\n\nimport {\n uiFieldEmail,\n uiFieldIdentifier,\n uiFieldNumber,\n uiFieldTel,\n uiFieldText,\n uiFieldUrl\n} from './input';\n\nimport {\n uiFieldRadio,\n uiFieldStructureRadio\n} from './radio';\n\nimport { uiFieldAccess } from './access';\nimport { uiFieldAddress } from './address';\nimport { uiFieldCycleway } from './cycleway';\nimport { uiFieldLanes } from './lanes';\nimport { uiFieldLocalized } from './localized';\nimport { uiFieldMaxspeed } from './maxspeed';\nimport { uiFieldRestrictions } from './restrictions';\nimport { uiFieldTextarea } from './textarea';\nimport { uiFieldWikidata } from './wikidata';\nimport { uiFieldWikipedia } from './wikipedia';\n\nexport var uiFields = {\n access: uiFieldAccess,\n address: uiFieldAddress,\n check: uiFieldCheck,\n combo: uiFieldCombo,\n cycleway: uiFieldCycleway,\n defaultCheck: uiFieldDefaultCheck,\n email: uiFieldEmail,\n identifier: uiFieldIdentifier,\n lanes: uiFieldLanes,\n localized: uiFieldLocalized,\n maxspeed: uiFieldMaxspeed,\n multiCombo: uiFieldMultiCombo,\n networkCombo: uiFieldNetworkCombo,\n number: uiFieldNumber,\n onewayCheck: uiFieldOnewayCheck,\n radio: uiFieldRadio,\n restrictions: uiFieldRestrictions,\n semiCombo: uiFieldSemiCombo,\n structureRadio: uiFieldStructureRadio,\n tel: uiFieldTel,\n text: uiFieldText,\n textarea: uiFieldTextarea,\n typeCombo: uiFieldTypeCombo,\n url: uiFieldUrl,\n wikidata: uiFieldWikidata,\n wikipedia: uiFieldWikipedia\n};\n","import {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { t } from '../core/localizer';\nimport { services } from '../services';\nimport { svgIcon } from '../svg/icon';\n\n\n// Pass `which` object of the form:\n// {\n// key: 'string', // required\n// value: 'string' // optional\n// }\n// -or-\n// {\n// rtype: 'string' // relation type (e.g. 'multipolygon')\n// }\n// -or-\n// {\n// qid: 'string' // brand wikidata (e.g. 'Q37158')\n// }\n//\nexport function uiTagReference(what) {\n var wikibase = what.qid ? services.wikidata : services.osmWikibase;\n var tagReference = {};\n\n var _button = d3_select(null);\n var _body = d3_select(null);\n var _loaded;\n var _showing;\n\n\n function load() {\n if (!wikibase) return;\n\n _button\n .classed('tag-reference-loading', true);\n\n wikibase.getDocs(what, gotDocs);\n }\n\n\n function gotDocs(err, docs) {\n _body.html('');\n\n if (!docs || !docs.title) {\n _body\n .append('p')\n .attr('class', 'tag-reference-description')\n .text(t('inspector.no_documentation_key'));\n done();\n return;\n }\n\n if (docs.imageURL) {\n _body\n .append('img')\n .attr('class', 'tag-reference-wiki-image')\n .attr('src', docs.imageURL)\n .on('load', function() { done(); })\n .on('error', function() { d3_select(this).remove(); done(); });\n } else {\n done();\n }\n\n _body\n .append('p')\n .attr('class', 'tag-reference-description')\n .text(docs.description || t('inspector.no_documentation_key'))\n .append('a')\n .attr('class', 'tag-reference-edit')\n .attr('target', '_blank')\n .attr('tabindex', -1)\n .attr('title', t('inspector.edit_reference'))\n .attr('href', docs.editURL)\n .call(svgIcon('#iD-icon-edit', 'inline'));\n\n if (docs.wiki) {\n _body\n .append('a')\n .attr('class', 'tag-reference-link')\n .attr('target', '_blank')\n .attr('tabindex', -1)\n .attr('href', docs.wiki.url)\n .call(svgIcon('#iD-icon-out-link', 'inline'))\n .append('span')\n .text(t(docs.wiki.text));\n }\n\n // Add link to info about \"good changeset comments\" - #2923\n if (what.key === 'comment') {\n _body\n .append('a')\n .attr('class', 'tag-reference-comment-link')\n .attr('target', '_blank')\n .attr('tabindex', -1)\n .call(svgIcon('#iD-icon-out-link', 'inline'))\n .attr('href', t('commit.about_changeset_comments_link'))\n .append('span')\n .text(t('commit.about_changeset_comments'));\n }\n }\n\n\n function done() {\n _loaded = true;\n\n _button\n .classed('tag-reference-loading', false);\n\n _body\n .classed('expanded', true)\n .transition()\n .duration(200)\n .style('max-height', '200px')\n .style('opacity', '1');\n\n _showing = true;\n\n _button.selectAll('svg.icon use').each(function() {\n var iconUse = d3_select(this);\n if (iconUse.attr('href') === '#iD-icon-info') {\n iconUse.attr('href', '#iD-icon-info-filled');\n }\n });\n }\n\n\n function hide() {\n _body\n .transition()\n .duration(200)\n .style('max-height', '0px')\n .style('opacity', '0')\n .on('end', function () {\n _body.classed('expanded', false);\n });\n\n _showing = false;\n\n _button.selectAll('svg.icon use').each(function() {\n var iconUse = d3_select(this);\n if (iconUse.attr('href') === '#iD-icon-info-filled') {\n iconUse.attr('href', '#iD-icon-info');\n }\n });\n\n }\n\n\n tagReference.button = function(selection, klass, iconName) {\n _button = selection.selectAll('.tag-reference-button')\n .data([0]);\n\n _button = _button.enter()\n .append('button')\n .attr('class', 'tag-reference-button ' + klass)\n .attr('title', t('icons.information'))\n .attr('tabindex', -1)\n .call(svgIcon('#iD-icon-' + (iconName || 'inspect')))\n .merge(_button);\n\n _button\n .on('click', function () {\n d3_event.stopPropagation();\n d3_event.preventDefault();\n this.blur(); // avoid keeping focus on the button - #4641\n if (_showing) {\n hide();\n } else if (_loaded) {\n done();\n } else {\n load();\n }\n });\n };\n\n\n tagReference.body = function(selection) {\n var itemID = what.qid || what.rtype || (what.key + '-' + what.value);\n _body = selection.selectAll('.tag-reference-body')\n .data([itemID], function(d) { return d; });\n\n _body.exit()\n .remove();\n\n _body = _body.enter()\n .append('div')\n .attr('class', 'tag-reference-body')\n .style('max-height', '0')\n .style('opacity', '0')\n .merge(_body);\n\n if (_showing === false) {\n hide();\n }\n };\n\n\n tagReference.showing = function(val) {\n if (!arguments.length) return _showing;\n _showing = val;\n return tagReference;\n };\n\n\n return tagReference;\n}\n","import * as countryCoder from '@ideditor/country-coder';\nimport { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { event as d3_event, select as d3_select } from 'd3-selection';\n\nimport { t, localizer } from '../core/localizer';\nimport { svgIcon } from '../svg/icon';\nimport { uiTooltip } from './tooltip';\nimport { geoExtent } from '../geo/extent';\nimport { uiFieldHelp } from './field_help';\nimport { uiFields } from './fields';\nimport { uiTagReference } from './tag_reference';\nimport { utilRebind, utilUniqueDomId } from '../util';\n\n\nexport function uiField(context, presetField, entityIDs, options) {\n options = Object.assign({\n show: true,\n wrap: true,\n remove: true,\n revert: true,\n info: true\n }, options);\n\n // Don't show the remove and revert buttons if any of the entity IDs are FB features\n // with source=digitalglobe or source=maxar\n var someFbRoadsSelected = entityIDs ? entityIDs.some(function(entity) {\n return entity.__fbid__ && (entity.tags.source === 'maxar' || entity.tags.source === 'digitalglobe');\n }) : false;\n\n\n if ( someFbRoadsSelected ) {\n options.remove = false;\n options.revert = false;\n }\n\n var dispatch = d3_dispatch('change', 'revert');\n var field = Object.assign({}, presetField); // shallow copy\n field.domId = utilUniqueDomId('form-field-' + field.safeid);\n var _show = options.show;\n var _state = '';\n var _tags = {};\n\n var _locked = false;\n var _lockedTip = uiTooltip()\n .title(t('inspector.lock.suggestion', { label: field.label }))\n .placement('bottom');\n\n\n field.keys = field.keys || [field.key];\n\n // only create the fields that are actually being shown\n if (_show && !field.impl) {\n createField();\n }\n\n // Creates the field.. This is done lazily,\n // once we know that the field will be shown.\n function createField() {\n field.impl = uiFields[field.type](field, context)\n .on('change', function(t, onInput) {\n dispatch.call('change', field, t, onInput);\n });\n\n if (entityIDs) {\n field.entityIDs = entityIDs;\n // if this field cares about the entities, pass them along\n if (field.impl.entityIDs) {\n field.impl.entityIDs(entityIDs);\n }\n }\n }\n\n\n function isModified() {\n if (!entityIDs || !entityIDs.length) return false;\n return entityIDs.some(function(entityID) {\n var original = context.graph().base().entities[entityID];\n var latest = context.graph().entity(entityID);\n return field.keys.some(function(key) {\n return original ? latest.tags[key] !== original.tags[key] : latest.tags[key];\n });\n });\n }\n\n\n function tagsContainFieldKey() {\n return field.keys.some(function(key) {\n if (field.type === 'multiCombo') {\n for (var tagKey in _tags) {\n if (tagKey.indexOf(key) === 0) {\n return true;\n }\n }\n return false;\n }\n return _tags[key] !== undefined;\n });\n }\n\n\n function revert(d) {\n d3_event.stopPropagation();\n d3_event.preventDefault();\n if (!entityIDs || _locked) return;\n\n dispatch.call('revert', d, d.keys);\n }\n\n\n function remove(d) {\n d3_event.stopPropagation();\n d3_event.preventDefault();\n if (_locked) return;\n\n var t = {};\n d.keys.forEach(function(key) {\n t[key] = undefined;\n });\n\n dispatch.call('change', d, t);\n }\n\n\n field.render = function(selection) {\n var container = selection.selectAll('.form-field')\n .data([field]);\n\n // Enter\n var enter = container.enter()\n .append('div')\n .attr('class', function(d) { return 'form-field form-field-' + d.safeid; })\n .classed('nowrap', !options.wrap);\n\n if (options.wrap) {\n var labelEnter = enter\n .append('label')\n .attr('class', 'field-label')\n .attr('for', function(d) { return d.domId; });\n\n var textEnter = labelEnter\n .append('span')\n .attr('class', 'label-text');\n\n textEnter\n .append('span')\n .attr('class', 'label-textvalue')\n .text(function(d) { return d.label(); });\n\n textEnter\n .append('span')\n .attr('class', 'label-textannotation');\n\n if (options.remove) {\n labelEnter\n .append('button')\n .attr('class', 'remove-icon')\n .attr('title', t('icons.remove'))\n .attr('tabindex', -1)\n .call(svgIcon('#iD-operation-delete'));\n }\n\n if (options.revert) {\n labelEnter\n .append('button')\n .attr('class', 'modified-icon')\n .attr('title', t('icons.undo'))\n .attr('tabindex', -1)\n .call(svgIcon((localizer.textDirection() === 'rtl') ? '#iD-icon-redo' : '#iD-icon-undo'));\n }\n }\n\n\n // Update\n container = container\n .merge(enter);\n\n container.select('.field-label > .remove-icon') // propagate bound data\n .on('click', remove);\n\n container.select('.field-label > .modified-icon') // propagate bound data\n .on('click', revert);\n\n container\n .each(function(d) {\n var selection = d3_select(this);\n\n if (!d.impl) {\n createField();\n }\n\n var reference, help;\n\n // instantiate field help\n if (options.wrap && field.type === 'restrictions') {\n help = uiFieldHelp(context, 'restrictions');\n }\n\n // instantiate tag reference\n if (options.wrap && options.info) {\n var referenceKey = d.key;\n if (d.type === 'multiCombo') { // lookup key without the trailing ':'\n referenceKey = referenceKey.replace(/:$/, '');\n }\n\n reference = uiTagReference(d.reference || { key: referenceKey }, context);\n if (_state === 'hover') {\n reference.showing(false);\n }\n }\n\n selection\n .call(d.impl);\n\n // add field help components\n if (help) {\n selection\n .call(help.body)\n .select('.field-label')\n .call(help.button);\n }\n\n // add tag reference components\n if (reference) {\n selection\n .call(reference.body)\n .select('.field-label')\n .call(reference.button);\n }\n\n d.impl.tags(_tags);\n });\n\n\n container\n .classed('locked', _locked)\n .classed('modified', isModified())\n .classed('present', tagsContainFieldKey());\n\n\n // show a tip and lock icon if the field is locked\n var annotation = container.selectAll('.field-label .label-textannotation');\n var icon = annotation.selectAll('.icon')\n .data(_locked ? [0]: []);\n\n icon.exit()\n .remove();\n\n icon.enter()\n .append('svg')\n .attr('class', 'icon')\n .append('use')\n .attr('xlink:href', '#fas-lock');\n\n container.call(_locked ? _lockedTip : _lockedTip.destroy);\n };\n\n\n field.state = function(val) {\n if (!arguments.length) return _state;\n _state = val;\n return field;\n };\n\n\n field.tags = function(val) {\n if (!arguments.length) return _tags;\n _tags = val;\n\n if (tagsContainFieldKey() && !_show) {\n // always show a field if it has a value to display\n _show = true;\n if (!field.impl) {\n createField();\n }\n }\n\n return field;\n };\n\n\n field.locked = function(val) {\n if (!arguments.length) return _locked;\n _locked = val;\n return field;\n };\n\n\n field.show = function() {\n _show = true;\n if (!field.impl) {\n createField();\n }\n if (field.default && field.key && _tags[field.key] !== field.default) {\n var t = {};\n t[field.key] = field.default;\n dispatch.call('change', this, t);\n }\n };\n\n // A shown field has a visible UI, a non-shown field is in the 'Add field' dropdown\n field.isShown = function() {\n return _show;\n };\n\n\n // An allowed field can appear in the UI or in the 'Add field' dropdown.\n // A non-allowed field is hidden from the user altogether\n field.isAllowed = function() {\n\n if (entityIDs &&\n entityIDs.length > 1 &&\n uiFields[field.type].supportsMultiselection === false) return false;\n\n if (field.geometry && !entityIDs.every(function(entityID) {\n return field.matchGeometry(context.graph().geometry(entityID));\n })) return false;\n\n if (field.countryCodes || field.notCountryCodes) {\n var extent = combinedEntityExtent();\n if (!extent) return true;\n\n var center = extent.center();\n var countryCode = countryCoder.iso1A2Code(center);\n\n if (!countryCode) return false;\n\n countryCode = countryCode.toLowerCase();\n\n if (field.countryCodes && field.countryCodes.indexOf(countryCode) === -1) {\n return false;\n }\n if (field.notCountryCodes && field.notCountryCodes.indexOf(countryCode) !== -1) {\n return false;\n }\n }\n\n var prerequisiteTag = field.prerequisiteTag;\n\n if (entityIDs &&\n !tagsContainFieldKey() && // ignore tagging prerequisites if a value is already present\n prerequisiteTag) {\n\n if (!entityIDs.every(function(entityID) {\n var entity = context.graph().entity(entityID);\n if (prerequisiteTag.key) {\n var value = entity.tags[prerequisiteTag.key];\n if (!value) return false;\n\n if (prerequisiteTag.valueNot) {\n return prerequisiteTag.valueNot !== value;\n }\n if (prerequisiteTag.value) {\n return prerequisiteTag.value === value;\n }\n } else if (prerequisiteTag.keyNot) {\n if (entity.tags[prerequisiteTag.keyNot]) return false;\n }\n return true;\n })) return false;\n }\n\n return true;\n };\n\n\n field.focus = function() {\n if (field.impl) {\n field.impl.focus();\n }\n };\n\n\n function combinedEntityExtent() {\n return entityIDs && entityIDs.length && entityIDs.reduce(function(extent, entityID) {\n var entity = context.graph().entity(entityID);\n return extent.extend(entity.extent(context.graph()));\n }, geoExtent());\n }\n\n\n return utilRebind(field, dispatch, 'on');\n}\n","import { select as d3_select } from 'd3-selection';\n\nimport { t } from '../core/localizer';\nimport { uiCombobox } from './combobox';\nimport { utilGetSetValue, utilNoAuto } from '../util';\n\n\nexport function uiFormFields(context) {\n var moreCombo = uiCombobox(context, 'more-fields').minItems(1);\n var _fieldsArr = [];\n var _lastPlaceholder = '';\n var _state = '';\n var _klass = '';\n\n\n function formFields(selection) {\n var allowedFields = _fieldsArr.filter(function(field) { return field.isAllowed(); });\n var shown = allowedFields.filter(function(field) { return field.isShown(); });\n var notShown = allowedFields.filter(function(field) { return !field.isShown(); });\n\n var container = selection.selectAll('.form-fields-container')\n .data([0]);\n\n container = container.enter()\n .append('div')\n .attr('class', 'form-fields-container ' + (_klass || ''))\n .merge(container);\n\n\n var fields = container.selectAll('.wrap-form-field')\n .data(shown, function(d) { return d.id + (d.entityIDs ? d.entityIDs.join() : ''); });\n\n fields.exit()\n .remove();\n\n // Enter\n var enter = fields.enter()\n .append('div')\n .attr('class', function(d) { return 'wrap-form-field wrap-form-field-' + d.safeid; });\n\n // Update\n fields = fields\n .merge(enter);\n\n fields\n .order()\n .each(function(d) {\n d3_select(this)\n .call(d.render);\n });\n\n\n var titles = [];\n var moreFields = notShown.map(function(field) {\n var label = field.label();\n titles.push(label);\n\n var terms = field.terms();\n if (field.key) terms.push(field.key);\n if (field.keys) terms = terms.concat(field.keys);\n\n return {\n title: label,\n value: label,\n field: field,\n terms: terms\n };\n });\n\n var placeholder = titles.slice(0,3).join(', ') + ((titles.length > 3) ? '…' : '');\n\n\n var more = selection.selectAll('.more-fields')\n .data((_state === 'hover' || moreFields.length === 0) ? [] : [0]);\n\n more.exit()\n .remove();\n\n var moreEnter = more.enter()\n .append('div')\n .attr('class', 'more-fields')\n .append('label');\n\n moreEnter\n .append('span')\n .text(t('inspector.add_fields'));\n\n more = moreEnter\n .merge(more);\n\n\n var input = more.selectAll('.value')\n .data([0]);\n\n input.exit()\n .remove();\n\n input = input.enter()\n .append('input')\n .attr('class', 'value')\n .attr('type', 'text')\n .attr('placeholder', placeholder)\n .call(utilNoAuto)\n .merge(input);\n\n input\n .call(utilGetSetValue, '')\n .call(moreCombo\n .data(moreFields)\n .on('accept', function (d) {\n if (!d) return; // user entered something that was not matched\n var field = d.field;\n field.show();\n selection.call(formFields); // rerender\n if (field.type !== 'semiCombo' && field.type !== 'multiCombo') {\n field.focus();\n }\n })\n );\n\n // avoid updating placeholder excessively (triggers style recalc)\n if (_lastPlaceholder !== placeholder) {\n input.attr('placeholder', placeholder);\n _lastPlaceholder = placeholder;\n }\n }\n\n\n formFields.fieldsArr = function(val) {\n if (!arguments.length) return _fieldsArr;\n _fieldsArr = val || [];\n return formFields;\n };\n\n formFields.state = function(val) {\n if (!arguments.length) return _state;\n _state = val;\n return formFields;\n };\n\n formFields.klass = function(val) {\n if (!arguments.length) return _klass;\n _klass = val;\n return formFields;\n };\n\n\n return formFields;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\n\nimport { presetManager } from '../presets';\nimport { t } from '../core/localizer';\nimport { svgIcon } from '../svg/icon';\nimport { uiCombobox} from './combobox';\nimport { uiField } from './field';\nimport { uiFormFields } from './form_fields';\nimport { utilArrayUniqBy, utilRebind, utilTriggerEvent } from '../util';\n\n\nexport function uiChangesetEditor(context) {\n var dispatch = d3_dispatch('change');\n var formFields = uiFormFields(context);\n var commentCombo = uiCombobox(context, 'comment').caseSensitive(true);\n var _fieldsArr;\n var _tags;\n var _changesetID;\n\n\n function changesetEditor(selection) {\n render(selection);\n }\n\n\n function render(selection) {\n var initial = false;\n\n if (!_fieldsArr) {\n initial = true;\n var presets = presetManager;\n\n _fieldsArr = [\n uiField(context, presets.field('comment'), null, { show: true, revert: false }),\n uiField(context, presets.field('source'), null, { show: false, revert: false }),\n uiField(context, presets.field('hashtags'), null, { show: false, revert: false }),\n ];\n\n _fieldsArr.forEach(function(field) {\n field\n .on('change', function(t, onInput) {\n dispatch.call('change', field, undefined, t, onInput);\n });\n });\n }\n\n _fieldsArr.forEach(function(field) {\n field\n .tags(_tags);\n });\n\n\n selection\n .call(formFields.fieldsArr(_fieldsArr));\n\n\n if (initial) {\n var commentField = selection.select('.form-field-comment textarea');\n var commentNode = commentField.node();\n\n if (commentNode) {\n commentNode.focus();\n commentNode.select();\n }\n\n // trigger a 'blur' event so that comment field can be cleaned\n // and checked for hashtags, even if retrieved from localstorage\n utilTriggerEvent(commentField, 'blur');\n\n var osm = context.connection();\n if (osm) {\n osm.userChangesets(function (err, changesets) {\n if (err) return;\n\n var comments = changesets.map(function(changeset) {\n var comment = changeset.tags.comment;\n return comment ? { title: comment, value: comment } : null;\n }).filter(Boolean);\n\n commentField\n .call(commentCombo\n .data(utilArrayUniqBy(comments, 'title'))\n );\n });\n }\n }\n\n // Add warning if comment mentions Google\n var hasGoogle = _tags.comment.match(/google/i);\n var commentWarning = selection.select('.form-field-comment').selectAll('.comment-warning')\n .data(hasGoogle ? [0] : []);\n\n commentWarning.exit()\n .transition()\n .duration(200)\n .style('opacity', 0)\n .remove();\n\n var commentEnter = commentWarning.enter()\n .insert('div', '.tag-reference-body')\n .attr('class', 'field-warning comment-warning')\n .style('opacity', 0);\n\n commentEnter\n .append('a')\n .attr('target', '_blank')\n .attr('tabindex', -1)\n .call(svgIcon('#iD-icon-alert', 'inline'))\n .attr('href', t('commit.google_warning_link'))\n .append('span')\n .text(t('commit.google_warning'));\n\n commentEnter\n .transition()\n .duration(200)\n .style('opacity', 1);\n }\n\n\n changesetEditor.tags = function(_) {\n if (!arguments.length) return _tags;\n _tags = _;\n // Don't reset _fieldsArr here.\n return changesetEditor;\n };\n\n\n changesetEditor.changesetID = function(_) {\n if (!arguments.length) return _changesetID;\n if (_changesetID === _) return changesetEditor;\n _changesetID = _;\n _fieldsArr = null;\n return changesetEditor;\n };\n\n\n return utilRebind(changesetEditor, dispatch, 'on');\n}\n","import { select as d3_select } from 'd3-selection';\n\n\n// toggles the visibility of ui elements, using a combination of the\n// hide class, which sets display=none, and a d3 transition for opacity.\n// this will cause blinking when called repeatedly, so check that the\n// value actually changes between calls.\nexport function uiToggle(show, callback) {\n return function(selection) {\n selection\n .style('opacity', show ? 0 : 1)\n .classed('hide', false)\n .transition()\n .style('opacity', show ? 1 : 0)\n .on('end', function() {\n d3_select(this)\n .classed('hide', !show)\n .style('opacity', null);\n if (callback) callback.apply(this);\n });\n };\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { event as d3_event } from 'd3-selection';\n\nimport { prefs } from '../core/preferences';\nimport { svgIcon } from '../svg/icon';\nimport { utilFunctor } from '../util';\nimport { utilRebind } from '../util/rebind';\nimport { uiToggle } from './toggle';\nimport { localizer } from '../core/localizer';\n\n\nexport function uiDisclosure(context, key, expandedDefault) {\n var dispatch = d3_dispatch('toggled');\n var _expanded;\n var _title = utilFunctor('');\n var _updatePreference = true;\n var _content = function () {};\n\n\n var disclosure = function(selection) {\n\n if (_expanded === undefined || _expanded === null) {\n // loading _expanded here allows it to be reset by calling `disclosure.expanded(null)`\n\n var preference = prefs('disclosure.' + key + '.expanded');\n _expanded = preference === null ? !!expandedDefault : (preference === 'true');\n }\n\n var hideToggle = selection.selectAll('.hide-toggle-' + key)\n .data([0]);\n\n // enter\n var hideToggleEnter = hideToggle.enter()\n .append('a')\n .attr('href', '#')\n .attr('class', 'hide-toggle hide-toggle-' + key)\n .call(svgIcon('', 'pre-text', 'hide-toggle-icon'));\n\n hideToggleEnter\n .append('span')\n .attr('class', 'hide-toggle-text');\n\n // update\n hideToggle = hideToggleEnter\n .merge(hideToggle);\n\n hideToggle\n .on('click', toggle)\n .classed('expanded', _expanded);\n\n hideToggle.selectAll('.hide-toggle-text')\n .text(_title());\n\n hideToggle.selectAll('.hide-toggle-icon')\n .attr('xlink:href', _expanded ? '#iD-icon-down'\n : (localizer.textDirection() === 'rtl') ? '#iD-icon-backward' : '#iD-icon-forward'\n );\n\n\n var wrap = selection.selectAll('.disclosure-wrap')\n .data([0]);\n\n // enter/update\n wrap = wrap.enter()\n .append('div')\n .attr('class', 'disclosure-wrap disclosure-wrap-' + key)\n .merge(wrap)\n .classed('hide', !_expanded);\n\n if (_expanded) {\n wrap\n .call(_content);\n }\n\n\n function toggle() {\n d3_event.preventDefault();\n\n _expanded = !_expanded;\n\n if (_updatePreference) {\n prefs('disclosure.' + key + '.expanded', _expanded);\n }\n\n hideToggle\n .classed('expanded', _expanded);\n\n hideToggle.selectAll('.hide-toggle-icon')\n .attr('xlink:href', _expanded ? '#iD-icon-down'\n : (localizer.textDirection() === 'rtl') ? '#iD-icon-backward' : '#iD-icon-forward'\n );\n\n wrap\n .call(uiToggle(_expanded));\n\n if (_expanded) {\n wrap\n .call(_content);\n }\n\n dispatch.call('toggled', this, _expanded);\n }\n };\n\n\n disclosure.title = function(val) {\n if (!arguments.length) return _title;\n _title = utilFunctor(val);\n return disclosure;\n };\n\n\n disclosure.expanded = function(val) {\n if (!arguments.length) return _expanded;\n _expanded = val;\n return disclosure;\n };\n\n\n disclosure.updatePreference = function(val) {\n if (!arguments.length) return _updatePreference;\n _updatePreference = val;\n return disclosure;\n };\n\n\n disclosure.content = function(val) {\n if (!arguments.length) return _content;\n _content = val;\n return disclosure;\n };\n\n\n return utilRebind(disclosure, dispatch, 'on');\n}\n","import {\n select as d3_select\n} from 'd3-selection';\n\nimport { uiDisclosure } from './disclosure';\nimport { utilFunctor } from '../util';\n\n// A unit of controls or info to be used in a layout, such as within a pane.\n// Can be labeled and collapsible.\nexport function uiSection(id, context) {\n\n var _classes = utilFunctor('');\n var _shouldDisplay;\n var _content;\n\n var _disclosure;\n var _title;\n var _expandedByDefault = utilFunctor(true);\n var _disclosureContent;\n var _disclosureExpanded;\n\n var _containerSelection = d3_select(null);\n\n var section = {\n id: id\n };\n\n section.classes = function(val) {\n if (!arguments.length) return _classes;\n _classes = utilFunctor(val);\n return section;\n };\n\n section.title = function(val) {\n if (!arguments.length) return _title;\n _title = utilFunctor(val);\n return section;\n };\n\n section.expandedByDefault = function(val) {\n if (!arguments.length) return _expandedByDefault;\n _expandedByDefault = utilFunctor(val);\n return section;\n };\n\n section.shouldDisplay = function(val) {\n if (!arguments.length) return _shouldDisplay;\n _shouldDisplay = utilFunctor(val);\n return section;\n };\n\n section.content = function(val) {\n if (!arguments.length) return _content;\n _content = val;\n return section;\n };\n\n section.disclosureContent = function(val) {\n if (!arguments.length) return _disclosureContent;\n _disclosureContent = val;\n return section;\n };\n\n section.disclosureExpanded = function(val) {\n if (!arguments.length) return _disclosureExpanded;\n _disclosureExpanded = val;\n return section;\n };\n\n // may be called multiple times\n section.render = function(selection) {\n\n _containerSelection = selection\n .selectAll('.section-' + id)\n .data([0]);\n\n var sectionEnter = _containerSelection\n .enter()\n .append('div')\n .attr('class', 'section section-' + id + ' ' + (_classes && _classes() || ''));\n\n _containerSelection = sectionEnter\n .merge(_containerSelection);\n\n _containerSelection\n .call(renderContent);\n };\n\n section.reRender = function() {\n _containerSelection\n .call(renderContent);\n };\n\n section.selection = function() {\n return _containerSelection;\n };\n\n section.disclosure = function() {\n return _disclosure;\n };\n\n // may be called multiple times\n function renderContent(selection) {\n if (_shouldDisplay) {\n var shouldDisplay = _shouldDisplay();\n selection.classed('hide', !shouldDisplay);\n if (!shouldDisplay) {\n selection.html('');\n return;\n }\n }\n\n if (_disclosureContent) {\n if (!_disclosure) {\n _disclosure = uiDisclosure(context, id.replace(/-/g, '_'), _expandedByDefault())\n .title(_title || '')\n /*.on('toggled', function(expanded) {\n if (expanded) { selection.node().parentNode.scrollTop += 200; }\n })*/\n .content(_disclosureContent);\n }\n if (_disclosureExpanded !== undefined) {\n _disclosure.expanded(_disclosureExpanded);\n _disclosureExpanded = undefined;\n }\n selection\n .call(_disclosure);\n\n return;\n }\n\n if (_content) {\n selection\n .call(_content);\n }\n }\n\n return section;\n}\n","import { select as d3_select } from 'd3-selection';\n\nimport { presetManager } from '../../presets';\nimport { fileFetcher } from '../../core/file_fetcher';\nimport { t } from '../../core/localizer';\nimport { JXON } from '../../util/jxon';\nimport { actionDiscardTags } from '../../actions/discard_tags';\nimport { osmChangeset } from '../../osm';\nimport { svgIcon } from '../../svg/icon';\nimport { utilDetect } from '../../util/detect';\nimport { uiSection } from '../section';\n\nimport {\n utilDisplayName,\n utilDisplayType,\n utilEntityOrMemberSelector\n} from '../../util';\n\n\nexport function uiSectionChanges(context) {\n var detected = utilDetect();\n\n var _discardTags = {};\n fileFetcher.get('discarded')\n .then(function(d) { _discardTags = d; })\n .catch(function() { /* ignore */ });\n\n var section = uiSection('changes-list', context)\n .title(function() {\n var history = context.history();\n var summary = history.difference().summary();\n return t('commit.changes', { count: summary.length });\n })\n .disclosureContent(renderDisclosureContent);\n\n function renderDisclosureContent(selection) {\n var history = context.history();\n var summary = history.difference().summary();\n\n var container = selection.selectAll('.commit-section')\n .data([0]);\n\n var containerEnter = container.enter()\n .append('div')\n .attr('class', 'commit-section');\n\n containerEnter\n .append('ul')\n .attr('class', 'changeset-list');\n\n container = containerEnter\n .merge(container);\n\n\n var items = container.select('ul').selectAll('li')\n .data(summary);\n\n var itemsEnter = items.enter()\n .append('li')\n .attr('class', 'change-item');\n\n itemsEnter\n .each(function(d) {\n d3_select(this)\n .call(svgIcon('#iD-icon-' + d.entity.geometry(d.graph), 'pre-text ' + d.changeType));\n });\n\n itemsEnter\n .append('span')\n .attr('class', 'change-type')\n .text(function(d) { return t('commit.' + d.changeType) + ' '; });\n\n itemsEnter\n .append('strong')\n .attr('class', 'entity-type')\n .text(function(d) {\n var matched = presetManager.match(d.entity, d.graph);\n return (matched && matched.name()) || utilDisplayType(d.entity.id);\n });\n\n itemsEnter\n .append('span')\n .attr('class', 'entity-name')\n .text(function(d) {\n var name = utilDisplayName(d.entity) || '',\n string = '';\n if (name !== '') {\n string += ':';\n }\n return string += ' ' + name;\n });\n\n itemsEnter\n .style('opacity', 0)\n .transition()\n .style('opacity', 1);\n\n items = itemsEnter\n .merge(items);\n\n items\n .on('mouseover', mouseover)\n .on('mouseout', mouseout)\n .on('click', click);\n\n\n // Download changeset link\n var changeset = new osmChangeset().update({ id: undefined });\n var changes = history.changes(actionDiscardTags(history.difference(), _discardTags));\n\n delete changeset.id; // Export without chnageset_id\n\n var data = JXON.stringify(changeset.osmChangeJXON(changes));\n var blob = new Blob([data], {type: 'text/xml;charset=utf-8;'});\n var fileName = 'changes.osc';\n\n var linkEnter = container.selectAll('.download-changes')\n .data([0])\n .enter()\n .append('a')\n .attr('class', 'download-changes');\n\n if (detected.download) { // All except IE11 and Edge\n linkEnter // download the data as a file\n .attr('href', window.URL.createObjectURL(blob))\n .attr('download', fileName);\n\n } else { // IE11 and Edge\n linkEnter // open data uri in a new tab\n .attr('target', '_blank')\n .on('click.download', function() {\n navigator.msSaveBlob(blob, fileName);\n });\n }\n\n linkEnter\n .call(svgIcon('#iD-icon-load', 'inline'))\n .append('span')\n .text(t('commit.download_changes'));\n\n\n function mouseover(d) {\n if (d.entity) {\n context.surface().selectAll(\n utilEntityOrMemberSelector([d.entity.id], context.graph())\n ).classed('hover', true);\n }\n }\n\n\n function mouseout() {\n context.surface().selectAll('.hover')\n .classed('hover', false);\n }\n\n\n function click(change) {\n if (change.changeType !== 'deleted') {\n var entity = change.entity;\n context.map().zoomToEase(entity);\n context.surface().selectAll(utilEntityOrMemberSelector([entity.id], context.graph()))\n .classed('hover', true);\n }\n }\n }\n\n return section;\n}\n","import { t } from '../core/localizer';\nimport { svgIcon } from '../svg/icon';\nimport { uiTooltip } from './tooltip';\nimport { utilEntityOrMemberSelector } from '../util';\n\n\nexport function uiCommitWarnings(context) {\n\n function commitWarnings(selection) {\n var issuesBySeverity = context.validator()\n .getIssuesBySeverity({ what: 'edited', where: 'all', includeDisabledRules: true });\n\n for (var severity in issuesBySeverity) {\n var issues = issuesBySeverity[severity];\n var section = severity + '-section';\n var issueItem = severity + '-item';\n\n var container = selection.selectAll('.' + section)\n .data(issues.length ? [0] : []);\n\n container.exit()\n .remove();\n\n var containerEnter = container.enter()\n .append('div')\n .attr('class', 'modal-section ' + section + ' fillL2');\n\n containerEnter\n .append('h3')\n .text(severity === 'warning' ? t('commit.warnings') : t('commit.errors'));\n\n containerEnter\n .append('ul')\n .attr('class', 'changeset-list');\n\n container = containerEnter\n .merge(container);\n\n\n var items = container.select('ul').selectAll('li')\n .data(issues, function(d) { return d.id; });\n\n items.exit()\n .remove();\n\n var itemsEnter = items.enter()\n .append('li')\n .attr('class', issueItem);\n\n itemsEnter\n .call(svgIcon('#iD-icon-alert', 'pre-text'));\n\n itemsEnter\n .append('strong')\n .attr('class', 'issue-message');\n\n itemsEnter.filter(function(d) { return d.tooltip; })\n .call(uiTooltip()\n .title(function(d) { return d.tooltip; })\n .placement('top')\n );\n\n items = itemsEnter\n .merge(items);\n\n items.selectAll('.issue-message')\n .text(function(d) {\n return d.message(context);\n });\n\n items\n .on('mouseover', function(d) {\n if (d.entityIds) {\n context.surface().selectAll(\n utilEntityOrMemberSelector(\n d.entityIds,\n context.graph()\n )\n ).classed('hover', true);\n }\n })\n .on('mouseout', function() {\n context.surface().selectAll('.hover')\n .classed('hover', false);\n })\n .on('click', function(d) {\n context.validator().focusIssue(d);\n });\n }\n }\n\n\n return commitWarnings;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { event as d3_event, select as d3_select } from 'd3-selection';\n\nimport { services } from '../../services';\nimport { svgIcon } from '../../svg/icon';\nimport { uiCombobox } from '../combobox';\nimport { uiSection } from '../section';\nimport { uiTagReference } from '../tag_reference';\nimport { prefs } from '../../core/preferences';\nimport { t } from '../../core/localizer';\nimport { utilArrayDifference, utilArrayIdentical } from '../../util/array';\nimport { utilGetSetValue, utilNoAuto, utilRebind, utilTagDiff } from '../../util';\n\nexport function uiSectionRawTagEditor(id, context) {\n\n var section = uiSection(id, context)\n .classes('raw-tag-editor')\n .title(function() {\n var count = Object.keys(_tags).filter(function(d) { return d; }).length;\n return t('inspector.title_count', { title: t('inspector.tags'), count: count });\n })\n .expandedByDefault(false)\n .disclosureContent(renderDisclosureContent);\n\n var taginfo = services.taginfo;\n var dispatch = d3_dispatch('change');\n var availableViews = [\n { id: 'text', icon: '#fas-i-cursor' },\n { id: 'list', icon: '#fas-th-list' }\n ];\n\n var _tagView = (prefs('raw-tag-editor-view') || 'list'); // 'list, 'text'\n var _readOnlyTags = [];\n // the keys in the order we want them to display\n var _orderedKeys = [];\n var _showBlank = false;\n var _pendingChange = null;\n var _state;\n var _presets;\n var _tags;\n var _entityIDs;\n\n function renderDisclosureContent(wrap) {\n\n // remove deleted keys\n _orderedKeys = _orderedKeys.filter(function(key) {\n return _tags[key] !== undefined;\n });\n\n // When switching to a different entity or changing the state (hover/select)\n // reorder the keys alphabetically.\n // We trigger this by emptying the `_orderedKeys` array, then it will be rebuilt here.\n // Otherwise leave their order alone - #5857, #5927\n var all = Object.keys(_tags).sort();\n var missingKeys = utilArrayDifference(all, _orderedKeys);\n for (var i in missingKeys) {\n _orderedKeys.push(missingKeys[i]);\n }\n\n // assemble row data\n var rowData = _orderedKeys.map(function(key, i) {\n return { index: i, key: key, value: _tags[key] };\n });\n\n // append blank row last, if necessary\n if (!rowData.length || _showBlank) {\n _showBlank = false;\n rowData.push({ index: rowData.length, key: '', value: '' });\n }\n\n\n // View Options\n var options = wrap.selectAll('.raw-tag-options')\n .data([0]);\n\n options.exit()\n .remove();\n\n var optionsEnter = options.enter()\n .insert('div', ':first-child')\n .attr('class', 'raw-tag-options');\n\n var optionEnter = optionsEnter.selectAll('.raw-tag-option')\n .data(availableViews, function(d) { return d.id; })\n .enter();\n\n optionEnter\n .append('button')\n .attr('class', function(d) {\n return 'raw-tag-option raw-tag-option-' + d.id + (_tagView === d.id ? ' selected' : '');\n })\n .attr('title', function(d) { return t('icons.' + d.id); })\n .on('click', function(d) {\n _tagView = d.id;\n prefs('raw-tag-editor-view', d.id);\n\n wrap.selectAll('.raw-tag-option')\n .classed('selected', function(datum) { return datum === d; });\n\n wrap.selectAll('.tag-text')\n .classed('hide', (d.id !== 'text'))\n .each(setTextareaHeight);\n\n wrap.selectAll('.tag-list, .add-row')\n .classed('hide', (d.id !== 'list'));\n })\n .each(function(d) {\n d3_select(this)\n .call(svgIcon(d.icon));\n });\n\n\n // View as Text\n var textData = rowsToText(rowData);\n var textarea = wrap.selectAll('.tag-text')\n .data([0]);\n\n textarea = textarea.enter()\n .append('textarea')\n .attr('class', 'tag-text' + (_tagView !== 'text' ? ' hide' : ''))\n .call(utilNoAuto)\n .attr('placeholder', t('inspector.key_value'))\n .attr('spellcheck', 'false')\n .merge(textarea);\n\n textarea\n .call(utilGetSetValue, textData)\n .each(setTextareaHeight)\n .on('input', setTextareaHeight)\n .on('blur', textChanged)\n .on('change', textChanged);\n\n\n // View as List\n var list = wrap.selectAll('.tag-list')\n .data([0]);\n\n list = list.enter()\n .append('ul')\n .attr('class', 'tag-list' + (_tagView !== 'list' ? ' hide' : ''))\n .merge(list);\n\n\n // Container for the Add button\n var addRowEnter = wrap.selectAll('.add-row')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'add-row' + (_tagView !== 'list' ? ' hide' : ''));\n\n addRowEnter\n .append('button')\n .attr('class', 'add-tag')\n .call(svgIcon('#iD-icon-plus', 'light'))\n .on('click', addTag);\n\n addRowEnter\n .append('div')\n .attr('class', 'space-value'); // preserve space\n\n addRowEnter\n .append('div')\n .attr('class', 'space-buttons'); // preserve space\n\n\n // Tag list items\n var items = list.selectAll('.tag-row')\n .data(rowData, function(d) { return d.key; });\n\n items.exit()\n .each(unbind)\n .remove();\n\n\n // Enter\n var itemsEnter = items.enter()\n .append('li')\n .attr('class', 'tag-row')\n .classed('readonly', isReadOnly);\n\n var innerWrap = itemsEnter.append('div')\n .attr('class', 'inner-wrap');\n\n innerWrap\n .append('div')\n .attr('class', 'key-wrap')\n .append('input')\n .property('type', 'text')\n .attr('class', 'key')\n .call(utilNoAuto)\n .on('blur', keyChange)\n .on('change', keyChange);\n\n innerWrap\n .append('div')\n .attr('class', 'value-wrap')\n .append('input')\n .property('type', 'text')\n .attr('class', 'value')\n .call(utilNoAuto)\n .on('blur', valueChange)\n .on('change', valueChange)\n .on('keydown.push-more', pushMore);\n\n innerWrap\n .append('button')\n .attr('tabindex', -1)\n .attr('class', 'form-field-button remove')\n .attr('title', t('icons.remove'))\n .call(svgIcon('#iD-operation-delete'));\n\n\n // Update\n items = items\n .merge(itemsEnter)\n .sort(function(a, b) { return a.index - b.index; });\n\n items\n .each(function(d) {\n var row = d3_select(this);\n var key = row.select('input.key'); // propagate bound data\n var value = row.select('input.value'); // propagate bound data\n\n if (_entityIDs && taginfo && _state !== 'hover') {\n bindTypeahead(key, value);\n }\n\n var reference;\n\n if (typeof d.value !== 'string') {\n reference = uiTagReference({ key: d.key }, context);\n } else {\n var isRelation = _entityIDs && _entityIDs.some(function(entityID) {\n return context.entity(entityID).type === 'relation';\n });\n if (isRelation && d.key === 'type') {\n reference = uiTagReference({ rtype: d.value }, context);\n } else {\n reference = uiTagReference({ key: d.key, value: d.value }, context);\n }\n }\n\n if (_state === 'hover') {\n reference.showing(false);\n }\n\n row.select('.inner-wrap') // propagate bound data\n .call(reference.button);\n\n row.call(reference.body);\n\n row.select('button.remove'); // propagate bound data\n });\n\n items.selectAll('input.key')\n .attr('title', function(d) { return d.key; })\n .call(utilGetSetValue, function(d) { return d.key; })\n .attr('readonly', function(d) {\n return (isReadOnly(d) || (typeof d.value !== 'string')) || null;\n });\n\n items.selectAll('input.value')\n .attr('title', function(d) {\n return Array.isArray(d.value) ? d.value.filter(Boolean).join('\\n') : d.value;\n })\n .classed('mixed', function(d) {\n return Array.isArray(d.value);\n })\n .attr('placeholder', function(d) {\n return typeof d.value === 'string' ? null : t('inspector.multiple_values');\n })\n .call(utilGetSetValue, function(d) {\n return typeof d.value === 'string' ? d.value : '';\n })\n .attr('readonly', function(d) {\n return isReadOnly(d) || null;\n });\n\n items.selectAll('button.remove')\n .on(('PointerEvent' in window ? 'pointer' : 'mouse') + 'down', removeTag); // 'click' fires too late - #5878\n\n }\n\n function isReadOnly(d) {\n for (var i = 0; i < _readOnlyTags.length; i++) {\n if (d.key.match(_readOnlyTags[i]) !== null) {\n return true;\n }\n }\n return false;\n }\n\n function setTextareaHeight() {\n if (_tagView !== 'text') return;\n\n var selection = d3_select(this);\n selection.style('height', null);\n selection.style('height', selection.node().scrollHeight + 5 + 'px');\n }\n\n function stringify(s) {\n return JSON.stringify(s).slice(1, -1); // without leading/trailing \"\n }\n\n function unstringify(s) {\n var leading = '';\n var trailing = '';\n if (s.length < 1 || s.charAt(0) !== '\"') {\n leading = '\"';\n }\n if (s.length < 2 || s.charAt(s.length - 1) !== '\"' ||\n (s.charAt(s.length - 1) === '\"' && s.charAt(s.length - 2) === '\\\\')\n ) {\n trailing = '\"';\n }\n return JSON.parse(leading + s + trailing);\n }\n\n function rowsToText(rows) {\n var str = rows\n .filter(function(row) { return row.key && row.key.trim() !== ''; })\n .map(function(row) {\n var rawVal = row.value;\n if (typeof rawVal !== 'string') rawVal = '*';\n var val = rawVal ? stringify(rawVal) : '';\n return stringify(row.key) + '=' + val;\n })\n .join('\\n');\n\n if (_state !== 'hover' && str.length) {\n return str + '\\n';\n }\n return str;\n }\n\n function textChanged() {\n var newText = this.value.trim();\n var newTags = {};\n newText.split('\\n').forEach(function(row) {\n var m = row.match(/^\\s*([^=]+)=(.*)$/);\n if (m !== null) {\n var k = context.cleanTagKey(unstringify(m[1].trim()));\n var v = context.cleanTagValue(unstringify(m[2].trim()));\n newTags[k] = v;\n }\n });\n\n var tagDiff = utilTagDiff(_tags, newTags);\n if (!tagDiff.length) return;\n\n _pendingChange = _pendingChange || {};\n\n tagDiff.forEach(function(change) {\n if (isReadOnly({ key: change.key })) return;\n\n // skip unchanged multiselection placeholders\n if (change.newVal === '*' && typeof change.oldVal !== 'string') return;\n\n if (change.type === '-') {\n _pendingChange[change.key] = undefined;\n } else if (change.type === '+') {\n _pendingChange[change.key] = change.newVal || '';\n }\n });\n\n if (Object.keys(_pendingChange).length === 0) {\n _pendingChange = null;\n return;\n }\n\n scheduleChange();\n }\n\n function pushMore() {\n // if pressing Tab on the last value field with content, add a blank row\n if (d3_event.keyCode === 9 && !d3_event.shiftKey &&\n section.selection().selectAll('.tag-list li:last-child input.value').node() === this &&\n utilGetSetValue(d3_select(this))) {\n addTag();\n }\n }\n\n function bindTypeahead(key, value) {\n if (isReadOnly(key.datum())) return;\n\n if (Array.isArray(value.datum().value)) {\n value.call(uiCombobox(context, 'tag-value')\n .minItems(1)\n .fetcher(function(value, callback) {\n var keyString = utilGetSetValue(key);\n if (!_tags[keyString]) return;\n var data = _tags[keyString].filter(Boolean).map(function(tagValue) {\n return {\n value: tagValue,\n title: tagValue\n };\n });\n callback(data);\n }));\n return;\n }\n\n var geometry = context.graph().geometry(_entityIDs[0]);\n\n key.call(uiCombobox(context, 'tag-key')\n .fetcher(function(value, callback) {\n taginfo.keys({\n debounce: true,\n geometry: geometry,\n query: value\n }, function(err, data) {\n if (!err) {\n var filtered = data.filter(function(d) { return _tags[d.value] === undefined; });\n callback(sort(value, filtered));\n }\n });\n }));\n\n value.call(uiCombobox(context, 'tag-value')\n .fetcher(function(value, callback) {\n taginfo.values({\n debounce: true,\n key: utilGetSetValue(key),\n geometry: geometry,\n query: value\n }, function(err, data) {\n if (!err) callback(sort(value, data));\n });\n }));\n\n\n function sort(value, data) {\n var sameletter = [];\n var other = [];\n for (var i = 0; i < data.length; i++) {\n if (data[i].value.substring(0, value.length) === value) {\n sameletter.push(data[i]);\n } else {\n other.push(data[i]);\n }\n }\n return sameletter.concat(other);\n }\n }\n\n function unbind() {\n var row = d3_select(this);\n\n row.selectAll('input.key')\n .call(uiCombobox.off, context);\n\n row.selectAll('input.value')\n .call(uiCombobox.off, context);\n }\n\n function keyChange(d) {\n if (d3_select(this).attr('readonly')) return;\n\n var kOld = d.key;\n\n // exit if we are currently about to delete this row anyway - #6366\n if (_pendingChange && _pendingChange.hasOwnProperty(kOld) && _pendingChange[kOld] === undefined) return;\n\n var kNew = context.cleanTagKey(this.value.trim());\n\n // allow no change if the key should be readonly\n if (isReadOnly({ key: kNew })) {\n this.value = kOld;\n return;\n }\n\n if (kNew &&\n kNew !== kOld &&\n _tags[kNew] !== undefined) {\n // new key is already in use, switch focus to the existing row\n\n this.value = kOld; // reset the key\n section.selection().selectAll('.tag-list input.value')\n .each(function(d) {\n if (d.key === kNew) { // send focus to that other value combo instead\n var input = d3_select(this).node();\n input.focus();\n input.select();\n }\n });\n return;\n }\n\n\n var row = this.parentNode.parentNode;\n var inputVal = d3_select(row).selectAll('input.value');\n var vNew = context.cleanTagValue(utilGetSetValue(inputVal));\n\n _pendingChange = _pendingChange || {};\n\n if (kOld) {\n _pendingChange[kOld] = undefined;\n }\n\n _pendingChange[kNew] = vNew;\n\n // update the ordered key index so this row doesn't change position\n var existingKeyIndex = _orderedKeys.indexOf(kOld);\n if (existingKeyIndex !== -1) _orderedKeys[existingKeyIndex] = kNew;\n\n d.key = kNew; // update datum to avoid exit/enter on tag update\n d.value = vNew;\n\n this.value = kNew;\n utilGetSetValue(inputVal, vNew);\n scheduleChange();\n }\n\n function valueChange(d) {\n if (isReadOnly(d)) return;\n\n // exit if this is a multiselection and no value was entered\n if (typeof d.value !== 'string' && !this.value) return;\n\n // exit if we are currently about to delete this row anyway - #6366\n if (_pendingChange && _pendingChange.hasOwnProperty(d.key) && _pendingChange[d.key] === undefined) return;\n\n _pendingChange = _pendingChange || {};\n\n _pendingChange[d.key] = context.cleanTagValue(this.value);\n scheduleChange();\n }\n\n function removeTag(d) {\n if (isReadOnly(d)) return;\n\n if (d.key === '') { // removing the blank row\n _showBlank = false;\n section.reRender();\n\n } else {\n // remove the key from the ordered key index\n _orderedKeys = _orderedKeys.filter(function(key) { return key !== d.key; });\n\n _pendingChange = _pendingChange || {};\n _pendingChange[d.key] = undefined;\n scheduleChange();\n }\n }\n\n function addTag() {\n // Delay render in case this click is blurring an edited combo.\n // Without the setTimeout, the `content` render would wipe out the pending tag change.\n window.setTimeout(function() {\n _showBlank = true;\n section.reRender();\n section.selection().selectAll('.tag-list li:last-child input.key').node().focus();\n }, 20);\n }\n\n function scheduleChange() {\n // Cache IDs in case the editor is reloaded before the change event is called. - #6028\n var entityIDs = _entityIDs;\n\n // Delay change in case this change is blurring an edited combo. - #5878\n window.setTimeout(function() {\n if (!_pendingChange) return;\n\n dispatch.call('change', this, entityIDs, _pendingChange);\n _pendingChange = null;\n }, 10);\n }\n\n\n section.state = function(val) {\n if (!arguments.length) return _state;\n if (_state !== val) {\n _orderedKeys = [];\n _state = val;\n }\n return section;\n };\n\n\n section.presets = function(val) {\n if (!arguments.length) return _presets;\n _presets = val;\n if (_presets && _presets.length && _presets[0].isFallback()) {\n section.disclosureExpanded(true);\n } else {\n section.disclosureExpanded(null);\n }\n return section;\n };\n\n\n section.tags = function(val) {\n if (!arguments.length) return _tags;\n _tags = val;\n return section;\n };\n\n\n section.entityIDs = function(val) {\n if (!arguments.length) return _entityIDs;\n if (!_entityIDs || !val || !utilArrayIdentical(_entityIDs, val)) {\n _entityIDs = val;\n _orderedKeys = [];\n }\n return section;\n };\n\n\n // pass an array of regular expressions to test against the tag key\n section.readOnlyTags = function(val) {\n if (!arguments.length) return _readOnlyTags;\n _readOnlyTags = val;\n return section;\n };\n\n\n return utilRebind(section, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { select as d3_select } from 'd3-selection';\nimport deepEqual from 'fast-deep-equal';\n\nimport { prefs } from '../core/preferences';\nimport { t, localizer } from '../core/localizer';\nimport { osmChangeset } from '../osm';\nimport { svgIcon } from '../svg/icon';\nimport { services } from '../services';\nimport { uiTooltip } from './tooltip';\nimport { uiChangesetEditor } from './changeset_editor';\nimport { uiSectionChanges } from './sections/changes';\nimport { uiCommitWarnings } from './commit_warnings';\nimport { uiSectionRawTagEditor } from './sections/raw_tag_editor';\nimport { utilArrayGroupBy, utilRebind, utilUniqueDomId } from '../util';\nimport { utilDetect } from '../util/detect';\n\n\nvar readOnlyTags = [\n /^changesets_count$/,\n /^created_by$/,\n /^ideditor:/,\n /^imagery_used$/,\n /^host$/,\n /^locale$/,\n /^warnings:/,\n /^resolved:/,\n /^closed:note$/,\n /^closed:keepright$/,\n /^closed:improveosm:/,\n /^closed:osmose:/\n];\n\n// treat most punctuation (except -, _, +, &) as hashtag delimiters - #4398\n// from https://stackoverflow.com/a/25575009\nvar hashtagRegex = /(#[^\\u2000-\\u206F\\u2E00-\\u2E7F\\s\\\\'!\"#$%()*,.\\/:;<=>?@\\[\\]^`{|}~]+)/g;\n\n\nexport function uiCommit(context) {\n var dispatch = d3_dispatch('cancel');\n var _userDetails;\n var _selection;\n\n var changesetEditor = uiChangesetEditor(context)\n .on('change', changeTags);\n var rawTagEditor = uiSectionRawTagEditor('changeset-tag-editor', context)\n .on('change', changeTags)\n .readOnlyTags(readOnlyTags);\n var commitChanges = uiSectionChanges(context);\n var commitWarnings = uiCommitWarnings(context);\n\n\n function commit(selection) {\n _selection = selection;\n\n // Initialize changeset if one does not exist yet.\n if (!context.changeset) initChangeset();\n\n loadDerivedChangesetTags();\n\n selection.call(render);\n }\n\n function initChangeset() {\n\n // expire stored comment, hashtags, source after cutoff datetime - #3947 #4899\n var commentDate = +prefs('commentDate') || 0;\n var currDate = Date.now();\n var cutoff = 2 * 86400 * 1000; // 2 days\n if (commentDate > currDate || currDate - commentDate > cutoff) {\n prefs('comment', null);\n prefs('hashtags', null);\n prefs('source', null);\n }\n\n // load in explicitly-set values, if any\n if (context.defaultChangesetComment()) {\n prefs('comment', context.defaultChangesetComment());\n prefs('commentDate', Date.now());\n }\n if (context.defaultChangesetSource()) {\n prefs('source', context.defaultChangesetSource());\n prefs('commentDate', Date.now());\n }\n if (context.defaultChangesetHashtags()) {\n prefs('hashtags', context.defaultChangesetHashtags());\n prefs('commentDate', Date.now());\n }\n\n var detected = utilDetect();\n var tags = {\n comment: prefs('comment') || '',\n created_by: context.cleanTagValue('RapiD ' + context.rapidContext().version),\n host: context.cleanTagValue(detected.host),\n locale: context.cleanTagValue(localizer.localeCode())\n };\n\n // call findHashtags initially - this will remove stored\n // hashtags if any hashtags are found in the comment - #4304\n findHashtags(tags, true);\n\n var hashtags = prefs('hashtags');\n if (hashtags) {\n tags.hashtags = hashtags;\n }\n\n var source = prefs('source');\n if (source) {\n tags.source = source;\n }\n var photoOverlaysUsed = context.history().photoOverlaysUsed();\n if (photoOverlaysUsed.length) {\n var sources = (tags.source || '').split(';');\n\n // include this tag for any photo layer\n if (sources.indexOf('streetlevel imagery') === -1) {\n sources.push('streetlevel imagery');\n }\n\n // add the photo overlays used during editing as sources\n photoOverlaysUsed.forEach(function(photoOverlay) {\n if (sources.indexOf(photoOverlay) === -1) {\n sources.push(photoOverlay);\n }\n });\n\n tags.source = context.cleanTagValue(sources.join(';'));\n }\n\n context.changeset = new osmChangeset({ tags: tags });\n }\n\n // Calculates read-only metadata tags based on the user's editing session and applies\n // them to the changeset.\n function loadDerivedChangesetTags() {\n\n var osm = context.connection();\n if (!osm) return;\n\n var tags = Object.assign({}, context.changeset.tags); // shallow copy\n\n // assign tags for imagery used\n var imageryUsed = context.cleanTagValue(context.history().imageryUsed().join(';'));\n tags.imagery_used = imageryUsed || 'None';\n\n // assign tags for closed issues and notes\n var osmClosed = osm.getClosedIDs();\n var itemType;\n if (osmClosed.length) {\n tags['closed:note'] = context.cleanTagValue(osmClosed.join(';'));\n }\n if (services.keepRight) {\n var krClosed = services.keepRight.getClosedIDs();\n if (krClosed.length) {\n tags['closed:keepright'] = context.cleanTagValue(krClosed.join(';'));\n }\n }\n if (services.improveOSM) {\n var iOsmClosed = services.improveOSM.getClosedCounts();\n for (itemType in iOsmClosed) {\n tags['closed:improveosm:' + itemType] = context.cleanTagValue(iOsmClosed[itemType].toString());\n }\n }\n if (services.osmose) {\n var osmoseClosed = services.osmose.getClosedCounts();\n for (itemType in osmoseClosed) {\n tags['closed:osmose:' + itemType] = context.cleanTagValue(osmoseClosed[itemType].toString());\n }\n }\n\n // remove existing issue counts\n for (var key in tags) {\n if (key.match(/(^warnings:)|(^resolved:)/)) {\n delete tags[key];\n }\n }\n\n function addIssueCounts(issues, prefix) {\n var issuesByType = utilArrayGroupBy(issues, 'type');\n for (var issueType in issuesByType) {\n var issuesOfType = issuesByType[issueType];\n if (issuesOfType[0].subtype) {\n var issuesBySubtype = utilArrayGroupBy(issuesOfType, 'subtype');\n for (var issueSubtype in issuesBySubtype) {\n var issuesOfSubtype = issuesBySubtype[issueSubtype];\n tags[prefix + ':' + issueType + ':' + issueSubtype] = context.cleanTagValue(issuesOfSubtype.length.toString());\n }\n } else {\n tags[prefix + ':' + issueType] = context.cleanTagValue(issuesOfType.length.toString());\n }\n }\n }\n\n // add counts of warnings generated by the user's edits\n var warnings = context.validator()\n .getIssuesBySeverity({ what: 'edited', where: 'all', includeIgnored: true, includeDisabledRules: true }).warning;\n addIssueCounts(warnings, 'warnings');\n\n // add counts of issues resolved by the user's edits\n var resolvedIssues = context.validator().getResolvedIssues();\n addIssueCounts(resolvedIssues, 'resolved');\n\n context.changeset = context.changeset.update({ tags: tags });\n }\n\n function render(selection) {\n\n var osm = context.connection();\n if (!osm) return;\n\n var header = selection.selectAll('.header')\n .data([0]);\n\n var headerTitle = header.enter()\n .append('div')\n .attr('class', 'header fillL header-container');\n\n headerTitle\n .append('div')\n .attr('class', 'header-block header-block-outer');\n\n headerTitle\n .append('div')\n .attr('class', 'header-block')\n .append('h3')\n .text(t('commit.title'));\n\n headerTitle\n .append('div')\n .attr('class', 'header-block header-block-outer header-block-close')\n .append('button')\n .attr('class', 'close')\n .on('click', function() {\n dispatch.call('cancel', this);\n })\n .call(svgIcon('#iD-icon-close'));\n\n var body = selection.selectAll('.body')\n .data([0]);\n\n body = body.enter()\n .append('div')\n .attr('class', 'body')\n .merge(body);\n\n\n // Changeset Section\n var changesetSection = body.selectAll('.changeset-editor')\n .data([0]);\n\n changesetSection = changesetSection.enter()\n .append('div')\n .attr('class', 'modal-section changeset-editor')\n .merge(changesetSection);\n\n changesetSection\n .call(changesetEditor\n .changesetID(context.changeset.id)\n .tags(context.changeset.tags)\n );\n\n\n // Warnings\n body.call(commitWarnings);\n\n\n // Upload Explanation\n var saveSection = body.selectAll('.save-section')\n .data([0]);\n\n saveSection = saveSection.enter()\n .append('div')\n .attr('class','modal-section save-section fillL')\n .merge(saveSection);\n\n var prose = saveSection.selectAll('.commit-info')\n .data([0]);\n\n if (prose.enter().size()) { // first time, make sure to update user details in prose\n _userDetails = null;\n }\n\n prose = prose.enter()\n .append('p')\n .attr('class', 'commit-info')\n .text(t('commit.upload_explanation'))\n .merge(prose);\n\n // always check if this has changed, but only update prose.html()\n // if needed, because it can trigger a style recalculation\n osm.userDetails(function(err, user) {\n if (err) return;\n\n if (_userDetails === user) return; // no change\n _userDetails = user;\n\n var userLink = d3_select(document.createElement('div'));\n\n if (user.image_url) {\n userLink\n .append('img')\n .attr('src', user.image_url)\n .attr('class', 'icon pre-text user-icon');\n }\n\n userLink\n .append('a')\n .attr('class', 'user-info')\n .text(user.display_name)\n .attr('href', osm.userURL(user.display_name))\n .attr('target', '_blank');\n\n prose\n .html(t('commit.upload_explanation_with_user', { user: userLink.html() }));\n });\n\n\n // Request Review\n var requestReview = saveSection.selectAll('.request-review')\n .data([0]);\n\n // Enter\n var requestReviewEnter = requestReview.enter()\n .append('div')\n .attr('class', 'request-review');\n\n var requestReviewDomId = utilUniqueDomId('commit-input-request-review');\n\n var labelEnter = requestReviewEnter\n .append('label')\n .attr('for', requestReviewDomId);\n\n labelEnter\n .append('input')\n .attr('type', 'checkbox')\n .attr('id', requestReviewDomId);\n\n labelEnter\n .append('span')\n .text(t('commit.request_review'));\n\n // Update\n requestReview = requestReview\n .merge(requestReviewEnter);\n\n var requestReviewInput = requestReview.selectAll('input')\n .property('checked', isReviewRequested(context.changeset.tags))\n .on('change', toggleRequestReview);\n\n\n // Buttons\n var buttonSection = saveSection.selectAll('.buttons')\n .data([0]);\n\n // enter\n var buttonEnter = buttonSection.enter()\n .append('div')\n .attr('class', 'buttons fillL');\n\n buttonEnter\n .append('button')\n .attr('class', 'secondary-action button cancel-button')\n .append('span')\n .attr('class', 'label')\n .text(t('commit.cancel'));\n\n var uploadButton = buttonEnter\n .append('button')\n .attr('class', 'action button save-button');\n\n uploadButton.append('span')\n .attr('class', 'label')\n .text(t('commit.save'));\n\n var uploadBlockerTooltipText = getUploadBlockerMessage();\n\n // update\n buttonSection = buttonSection\n .merge(buttonEnter);\n\n buttonSection.selectAll('.cancel-button')\n .on('click.cancel', function() {\n dispatch.call('cancel', this);\n });\n\n buttonSection.selectAll('.save-button')\n .classed('disabled', uploadBlockerTooltipText !== null)\n .on('click.save', function() {\n if (!d3_select(this).classed('disabled')) {\n this.blur(); // avoid keeping focus on the button - #4641\n context.uploader().save(context.changeset);\n }\n });\n\n // remove any existing tooltip\n uiTooltip().destroyAny(buttonSection.selectAll('.save-button'));\n\n if (uploadBlockerTooltipText) {\n buttonSection.selectAll('.save-button')\n .call(uiTooltip().title(uploadBlockerTooltipText).placement('top'));\n }\n\n // Raw Tag Editor\n var tagSection = body.selectAll('.tag-section.raw-tag-editor')\n .data([0]);\n\n tagSection = tagSection.enter()\n .append('div')\n .attr('class', 'modal-section tag-section raw-tag-editor')\n .merge(tagSection);\n\n tagSection\n .call(rawTagEditor\n .tags(Object.assign({}, context.changeset.tags)) // shallow copy\n .render\n );\n\n var changesSection = body.selectAll('.commit-changes-section')\n .data([0]);\n\n changesSection = changesSection.enter()\n .append('div')\n .attr('class', 'modal-section commit-changes-section')\n .merge(changesSection);\n\n // Change summary\n changesSection.call(commitChanges.render);\n\n\n function toggleRequestReview() {\n var rr = requestReviewInput.property('checked');\n updateChangeset({ review_requested: (rr ? 'yes' : undefined) });\n\n tagSection\n .call(rawTagEditor\n .tags(Object.assign({}, context.changeset.tags)) // shallow copy\n .render\n );\n }\n }\n\n\n function getUploadBlockerMessage() {\n var errors = context.validator()\n .getIssuesBySeverity({ what: 'edited', where: 'all' }).error;\n\n if (errors.length) {\n return t('commit.outstanding_errors_message', { count: errors.length });\n\n } else {\n var hasChangesetComment = context.changeset && context.changeset.tags.comment && context.changeset.tags.comment.trim().length;\n if (!hasChangesetComment) {\n return t('commit.comment_needed_message');\n }\n }\n return null;\n }\n\n\n function changeTags(_, changed, onInput) {\n if (changed.hasOwnProperty('comment')) {\n if (changed.comment === undefined) {\n changed.comment = '';\n }\n if (!onInput) {\n prefs('comment', changed.comment);\n prefs('commentDate', Date.now());\n }\n }\n if (changed.hasOwnProperty('source')) {\n if (changed.source === undefined) {\n prefs('source', null);\n } else if (!onInput) {\n prefs('source', changed.source);\n prefs('commentDate', Date.now());\n }\n }\n // no need to update `prefs` for `hashtags` here since it's done in `updateChangeset`\n\n updateChangeset(changed, onInput);\n\n if (_selection) {\n _selection.call(render);\n }\n }\n\n\n function findHashtags(tags, commentOnly) {\n var detectedHashtags = commentHashtags();\n\n if (detectedHashtags.length) {\n // always remove stored hashtags if there are hashtags in the comment - #4304\n prefs('hashtags', null);\n }\n if (!detectedHashtags.length || !commentOnly) {\n detectedHashtags = detectedHashtags.concat(hashtagHashtags());\n }\n\n var allLowerCase = new Set();\n return detectedHashtags.filter(function(hashtag) {\n // Compare tags as lowercase strings, but keep original case tags\n var lowerCase = hashtag.toLowerCase();\n if (!allLowerCase.has(lowerCase)) {\n allLowerCase.add(lowerCase);\n return true;\n }\n return false;\n });\n\n // Extract hashtags from `comment`\n function commentHashtags() {\n var matches = (tags.comment || '')\n .replace(/http\\S*/g, '') // drop anything that looks like a URL - #4289\n .match(hashtagRegex);\n\n return matches || [];\n }\n\n // Extract and clean hashtags from `hashtags`\n function hashtagHashtags() {\n var matches = (tags.hashtags || '')\n .split(/[,;\\s]+/)\n .map(function (s) {\n if (s[0] !== '#') { s = '#' + s; } // prepend '#'\n var matched = s.match(hashtagRegex);\n return matched && matched[0];\n }).filter(Boolean); // exclude falsy\n\n return matches || [];\n }\n }\n\n\n function isReviewRequested(tags) {\n var rr = tags.review_requested;\n if (rr === undefined) return false;\n rr = rr.trim().toLowerCase();\n return !(rr === '' || rr === 'no');\n }\n\n\n function updateChangeset(changed, onInput) {\n var tags = Object.assign({}, context.changeset.tags); // shallow copy\n\n Object.keys(changed).forEach(function(k) {\n var v = changed[k];\n k = context.cleanTagKey(k);\n if (readOnlyTags.indexOf(k) !== -1) return;\n\n if (k !== '' && v !== undefined) {\n if (onInput) {\n tags[k] = v;\n } else {\n tags[k] = context.cleanTagValue(v);\n }\n } else {\n delete tags[k];\n }\n });\n\n if (!onInput) {\n // when changing the comment, override hashtags with any found in comment.\n var commentOnly = changed.hasOwnProperty('comment') && (changed.comment !== '');\n var arr = findHashtags(tags, commentOnly);\n if (arr.length) {\n tags.hashtags = context.cleanTagValue(arr.join(';'));\n prefs('hashtags', tags.hashtags);\n } else {\n delete tags.hashtags;\n prefs('hashtags', null);\n }\n }\n\n // always update userdetails, just in case user reauthenticates as someone else\n if (_userDetails && _userDetails.changesets_count !== undefined) {\n var changesetsCount = parseInt(_userDetails.changesets_count, 10) + 1; // #4283\n tags.changesets_count = String(changesetsCount);\n\n // first 100 edits - new user\n if (changesetsCount <= 100) {\n var s;\n s = prefs('walkthrough_completed');\n if (s) {\n tags['ideditor:walkthrough_completed'] = s;\n }\n\n s = prefs('walkthrough_progress');\n if (s) {\n tags['ideditor:walkthrough_progress'] = s;\n }\n\n s = prefs('walkthrough_started');\n if (s) {\n tags['ideditor:walkthrough_started'] = s;\n }\n }\n } else {\n delete tags.changesets_count;\n }\n\n if (!deepEqual(context.changeset.tags, tags)) {\n context.changeset = context.changeset.update({ tags: tags });\n }\n }\n\n\n commit.reset = function() {\n context.changeset = null;\n };\n\n\n return utilRebind(commit, dispatch, 'on');\n}\n","module.exports.RADIUS = 6378137;\nmodule.exports.FLATTENING = 1/298.257223563;\nmodule.exports.POLAR_RADIUS = 6356752.3142;\n","var wgs84 = require('wgs84');\n\nmodule.exports.geometry = geometry;\nmodule.exports.ring = ringArea;\n\nfunction geometry(_) {\n var area = 0, i;\n switch (_.type) {\n case 'Polygon':\n return polygonArea(_.coordinates);\n case 'MultiPolygon':\n for (i = 0; i < _.coordinates.length; i++) {\n area += polygonArea(_.coordinates[i]);\n }\n return area;\n case 'Point':\n case 'MultiPoint':\n case 'LineString':\n case 'MultiLineString':\n return 0;\n case 'GeometryCollection':\n for (i = 0; i < _.geometries.length; i++) {\n area += geometry(_.geometries[i]);\n }\n return area;\n }\n}\n\nfunction polygonArea(coords) {\n var area = 0;\n if (coords && coords.length > 0) {\n area += Math.abs(ringArea(coords[0]));\n for (var i = 1; i < coords.length; i++) {\n area -= Math.abs(ringArea(coords[i]));\n }\n }\n return area;\n}\n\n/**\n * Calculate the approximate area of the polygon were it projected onto\n * the earth. Note that this area will be positive if ring is oriented\n * clockwise, otherwise it will be negative.\n *\n * Reference:\n * Robert. G. Chamberlain and William H. Duquette, \"Some Algorithms for\n * Polygons on a Sphere\", JPL Publication 07-03, Jet Propulsion\n * Laboratory, Pasadena, CA, June 2007 http://trs-new.jpl.nasa.gov/dspace/handle/2014/40409\n *\n * Returns:\n * {float} The approximate signed geodesic area of the polygon in square\n * meters.\n */\n\nfunction ringArea(coords) {\n var p1, p2, p3, lowerIndex, middleIndex, upperIndex, i,\n area = 0,\n coordsLength = coords.length;\n\n if (coordsLength > 2) {\n for (i = 0; i < coordsLength; i++) {\n if (i === coordsLength - 2) {// i = N-2\n lowerIndex = coordsLength - 2;\n middleIndex = coordsLength -1;\n upperIndex = 0;\n } else if (i === coordsLength - 1) {// i = N-1\n lowerIndex = coordsLength - 1;\n middleIndex = 0;\n upperIndex = 1;\n } else { // i = 0 to N-3\n lowerIndex = i;\n middleIndex = i+1;\n upperIndex = i+2;\n }\n p1 = coords[lowerIndex];\n p2 = coords[middleIndex];\n p3 = coords[upperIndex];\n area += ( rad(p3[0]) - rad(p1[0]) ) * Math.sin( rad(p2[1]));\n }\n\n area = area * wgs84.RADIUS * wgs84.RADIUS / 2;\n }\n\n return area;\n}\n\nfunction rad(_) {\n return _ * Math.PI / 180;\n}","\"use strict\";\nfunction toRadians(angleInDegrees) {\n return (angleInDegrees * Math.PI) / 180;\n}\n\nfunction toDegrees(angleInRadians) {\n return (angleInRadians * 180) / Math.PI;\n}\n\nfunction offset(c1, distance, bearing) {\n var lat1 = toRadians(c1[1]);\n var lon1 = toRadians(c1[0]);\n var dByR = distance / 6378137; // distance divided by 6378137 (radius of the earth) wgs84\n var lat = Math.asin(\n Math.sin(lat1) * Math.cos(dByR) +\n Math.cos(lat1) * Math.sin(dByR) * Math.cos(bearing)\n );\n var lon =\n lon1 +\n Math.atan2(\n Math.sin(bearing) * Math.sin(dByR) * Math.cos(lat1),\n Math.cos(dByR) - Math.sin(lat1) * Math.sin(lat)\n );\n return [toDegrees(lon), toDegrees(lat)];\n}\n\nfunction validateCenter(center) {\n const validCenterLengths = [2, 3];\n if (!Array.isArray(center) || !validCenterLengths.includes(center.length)) {\n throw new Error(\"ERROR! Center has to be an array of length two or three\");\n }\n const [lng, lat] = center;\n if (typeof lng !== \"number\" || typeof lat !== \"number\") {\n throw new Error(\n `ERROR! Longitude and Latitude has to be numbers but where ${typeof lng} and ${typeof lat}`\n );\n }\n if (lng > 180 || lng < -180) {\n throw new Error(\n `ERROR! Longitude has to be between -180 and 180 but was ${lng}`\n );\n }\n\n if (lat > 90 || lat < -90) {\n throw new Error(\n `ERROR! Latitude has to be between -90 and 90 but was ${lat}`\n );\n }\n}\n\nfunction validateRadius(radius) {\n if (typeof radius !== \"number\") {\n throw new Error(\n `ERROR! Radius has to be a positive number but was: ${typeof radius}`\n );\n }\n\n if (radius <= 0) {\n throw new Error(\n `ERROR! Radius has to be a positive number but was: ${radius}`\n );\n }\n}\n\nfunction validateNumberOfSegments(numberOfSegments) {\n if (typeof numberOfSegments !== \"number\" && numberOfSegments !== undefined) {\n throw new Error(\n `ERROR! Number of segments has to be a number but was: ${typeof numberOfSegments}`\n );\n }\n\n if (numberOfSegments < 3) {\n throw new Error(\n `ERROR! Number of segments has to be at least 3 but was: ${numberOfSegments}`\n );\n }\n}\n\nfunction validateInput({ center, radius, numberOfSegments }) {\n validateCenter(center);\n validateRadius(radius);\n validateNumberOfSegments(numberOfSegments);\n}\n\nmodule.exports = function circleToPolygon(center, radius, numberOfSegments) {\n var n = numberOfSegments ? numberOfSegments : 32;\n\n // validateInput() throws error on invalid input and do nothing on valid input\n validateInput({ center, radius, numberOfSegments });\n\n var coordinates = [];\n for (var i = 0; i < n; ++i) {\n coordinates.push(offset(center, radius, (2 * Math.PI * -i) / n));\n }\n coordinates.push(coordinates[0]);\n\n return {\n type: \"Polygon\",\n coordinates: [coordinates]\n };\n};\n","(function() {\n\n function parse(t, coordinatePrecision, extrasPrecision) {\n\n function point(p) {\n return p.map(function(e, index) {\n if (index < 2) {\n return 1 * e.toFixed(coordinatePrecision);\n } else {\n return 1 * e.toFixed(extrasPrecision);\n }\n });\n }\n\n function multi(l) {\n return l.map(point);\n }\n\n function poly(p) {\n return p.map(multi);\n }\n\n function multiPoly(m) {\n return m.map(poly);\n }\n\n function geometry(obj) {\n if (!obj) {\n return {};\n }\n \n switch (obj.type) {\n case \"Point\":\n obj.coordinates = point(obj.coordinates);\n return obj;\n case \"LineString\":\n case \"MultiPoint\":\n obj.coordinates = multi(obj.coordinates);\n return obj;\n case \"Polygon\":\n case \"MultiLineString\":\n obj.coordinates = poly(obj.coordinates);\n return obj;\n case \"MultiPolygon\":\n obj.coordinates = multiPoly(obj.coordinates);\n return obj;\n case \"GeometryCollection\":\n obj.geometries = obj.geometries.map(geometry);\n return obj;\n default :\n return {};\n }\n }\n\n function feature(obj) {\n obj.geometry = geometry(obj.geometry);\n return obj\n }\n\n function featureCollection(f) {\n f.features = f.features.map(feature);\n return f;\n }\n\n function geometryCollection(g) {\n g.geometries = g.geometries.map(geometry);\n return g;\n }\n\n if (!t) {\n return t;\n }\n\n switch (t.type) {\n case \"Feature\":\n return feature(t);\n case \"GeometryCollection\" :\n return geometryCollection(t);\n case \"FeatureCollection\" :\n return featureCollection(t);\n case \"Point\":\n case \"LineString\":\n case \"Polygon\":\n case \"MultiPoint\":\n case \"MultiPolygon\":\n case \"MultiLineString\":\n return geometry(t);\n default :\n return t;\n }\n \n }\n\n module.exports = parse;\n module.exports.parse = parse;\n\n}());\n \n","/* Polyfill service v3.13.0\n * For detailed credits and licence information see http://github.com/financial-times/polyfill-service\n *\n * - Array.prototype.fill, License: CC0 */\n\nif (!('fill' in Array.prototype)) {\n Object.defineProperty(Array.prototype, 'fill', {\n configurable: true,\n value: function fill (value) {\n if (this === undefined || this === null) {\n throw new TypeError(this + ' is not an object')\n }\n\n var arrayLike = Object(this);\n\n var length = Math.max(Math.min(arrayLike.length, 9007199254740991), 0) || 0;\n\n var relativeStart = 1 in arguments ? parseInt(Number(arguments[1]), 10) || 0 : 0;\n\n relativeStart = relativeStart < 0 ? Math.max(length + relativeStart, 0) : Math.min(relativeStart, length);\n\n var relativeEnd = 2 in arguments && arguments[2] !== undefined ? parseInt(Number(arguments[2]), 10) || 0 : length;\n\n relativeEnd = relativeEnd < 0 ? Math.max(length + arguments[2], 0) : Math.min(relativeEnd, length);\n\n while (relativeStart < relativeEnd) {\n arrayLike[relativeStart] = value;\n\n ++relativeStart;\n }\n\n return arrayLike\n },\n writable: true\n });\n}\n\n/**\n * Polyfill for IE support\n */\nNumber.isFinite = Number.isFinite || function (value) {\n return typeof value === 'number' && isFinite(value)\n};\n\nNumber.isInteger = Number.isInteger || function (val) {\n return typeof val === 'number' &&\n isFinite(val) &&\n Math.floor(val) === val\n};\n\nNumber.parseFloat = Number.parseFloat || parseFloat;\n\nNumber.isNaN = Number.isNaN || function (value) {\n return value !== value // eslint-disable-line\n};\n\n/**\n * Polyfill for IE support\n */\nMath.trunc = Math.trunc || function (x) {\n return x < 0 ? Math.ceil(x) : Math.floor(x)\n};\n\nvar NumberUtil = function NumberUtil () {};\n\nNumberUtil.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nNumberUtil.prototype.getClass = function getClass () {\n return NumberUtil\n};\nNumberUtil.prototype.equalsWithTolerance = function equalsWithTolerance (x1, x2, tolerance) {\n return Math.abs(x1 - x2) <= tolerance\n};\n\nvar IllegalArgumentException = (function (Error) {\n\tfunction IllegalArgumentException (message) {\n\t\tError.call(this, message);\n\t\tthis.name = 'IllegalArgumentException';\n\t\tthis.message = message;\n\t\tthis.stack = (new Error()).stack;\n\t}\n\n\tif ( Error ) IllegalArgumentException.__proto__ = Error;\n\tIllegalArgumentException.prototype = Object.create( Error && Error.prototype );\n\tIllegalArgumentException.prototype.constructor = IllegalArgumentException;\n\n\treturn IllegalArgumentException;\n}(Error));\n\nvar Double = function Double () {};\n\nvar staticAccessors$1 = { MAX_VALUE: { configurable: true } };\n\nDouble.isNaN = function isNaN (n) { return Number.isNaN(n) };\nDouble.doubleToLongBits = function doubleToLongBits (n) { return n };\nDouble.longBitsToDouble = function longBitsToDouble (n) { return n };\nDouble.isInfinite = function isInfinite (n) { return !Number.isFinite(n) };\nstaticAccessors$1.MAX_VALUE.get = function () { return Number.MAX_VALUE };\n\nObject.defineProperties( Double, staticAccessors$1 );\n\nvar Comparable = function Comparable () {};\n\nvar Clonable = function Clonable () {};\n\nvar Comparator = function Comparator () {};\n\nfunction Serializable () {}\n\n// import Assert from '../util/Assert'\n\nvar Coordinate = function Coordinate () {\n this.x = null;\n this.y = null;\n this.z = null;\n if (arguments.length === 0) {\n this.x = 0.0;\n this.y = 0.0;\n this.z = Coordinate.NULL_ORDINATE;\n } else if (arguments.length === 1) {\n var c = arguments[0];\n this.x = c.x;\n this.y = c.y;\n this.z = c.z;\n } else if (arguments.length === 2) {\n this.x = arguments[0];\n this.y = arguments[1];\n this.z = Coordinate.NULL_ORDINATE;\n } else if (arguments.length === 3) {\n this.x = arguments[0];\n this.y = arguments[1];\n this.z = arguments[2];\n }\n};\n\nvar staticAccessors = { DimensionalComparator: { configurable: true },serialVersionUID: { configurable: true },NULL_ORDINATE: { configurable: true },X: { configurable: true },Y: { configurable: true },Z: { configurable: true } };\nCoordinate.prototype.setOrdinate = function setOrdinate (ordinateIndex, value) {\n switch (ordinateIndex) {\n case Coordinate.X:\n this.x = value;\n break\n case Coordinate.Y:\n this.y = value;\n break\n case Coordinate.Z:\n this.z = value;\n break\n default:\n throw new IllegalArgumentException('Invalid ordinate index: ' + ordinateIndex)\n }\n};\nCoordinate.prototype.equals2D = function equals2D () {\n if (arguments.length === 1) {\n var other = arguments[0];\n if (this.x !== other.x) {\n return false\n }\n if (this.y !== other.y) {\n return false\n }\n return true\n } else if (arguments.length === 2) {\n var c = arguments[0];\n var tolerance = arguments[1];\n if (!NumberUtil.equalsWithTolerance(this.x, c.x, tolerance)) {\n return false\n }\n if (!NumberUtil.equalsWithTolerance(this.y, c.y, tolerance)) {\n return false\n }\n return true\n }\n};\nCoordinate.prototype.getOrdinate = function getOrdinate (ordinateIndex) {\n switch (ordinateIndex) {\n case Coordinate.X:\n return this.x\n case Coordinate.Y:\n return this.y\n case Coordinate.Z:\n return this.z\n default:\n }\n throw new IllegalArgumentException('Invalid ordinate index: ' + ordinateIndex)\n};\nCoordinate.prototype.equals3D = function equals3D (other) {\n return this.x === other.x &&\n this.y === other.y &&\n ((this.z === other.z || Double.isNaN(this.z)) &&\n Double.isNaN(other.z))\n};\nCoordinate.prototype.equals = function equals (other) {\n if (!(other instanceof Coordinate)) {\n return false\n }\n return this.equals2D(other)\n};\nCoordinate.prototype.equalInZ = function equalInZ (c, tolerance) {\n return NumberUtil.equalsWithTolerance(this.z, c.z, tolerance)\n};\nCoordinate.prototype.compareTo = function compareTo (o) {\n var other = o;\n if (this.x < other.x) { return -1 }\n if (this.x > other.x) { return 1 }\n if (this.y < other.y) { return -1 }\n if (this.y > other.y) { return 1 }\n return 0\n};\nCoordinate.prototype.clone = function clone () {\n // try {\n // var coord = null\n // return coord\n // } catch (e) {\n // if (e instanceof CloneNotSupportedException) {\n // Assert.shouldNeverReachHere(\"this shouldn't happen because this class is Cloneable\")\n // return null\n // } else throw e\n // } finally {}\n};\nCoordinate.prototype.copy = function copy () {\n return new Coordinate(this)\n};\nCoordinate.prototype.toString = function toString () {\n return '(' + this.x + ', ' + this.y + ', ' + this.z + ')'\n};\nCoordinate.prototype.distance3D = function distance3D (c) {\n var dx = this.x - c.x;\n var dy = this.y - c.y;\n var dz = this.z - c.z;\n return Math.sqrt(dx * dx + dy * dy + dz * dz)\n};\nCoordinate.prototype.distance = function distance (c) {\n var dx = this.x - c.x;\n var dy = this.y - c.y;\n return Math.sqrt(dx * dx + dy * dy)\n};\nCoordinate.prototype.hashCode = function hashCode () {\n var result = 17;\n result = 37 * result + Coordinate.hashCode(this.x);\n result = 37 * result + Coordinate.hashCode(this.y);\n return result\n};\nCoordinate.prototype.setCoordinate = function setCoordinate (other) {\n this.x = other.x;\n this.y = other.y;\n this.z = other.z;\n};\nCoordinate.prototype.interfaces_ = function interfaces_ () {\n return [Comparable, Clonable, Serializable]\n};\nCoordinate.prototype.getClass = function getClass () {\n return Coordinate\n};\nCoordinate.hashCode = function hashCode () {\n if (arguments.length === 1) {\n var x = arguments[0];\n var f = Double.doubleToLongBits(x);\n return Math.trunc((f ^ f) >>> 32)\n }\n};\nstaticAccessors.DimensionalComparator.get = function () { return DimensionalComparator };\nstaticAccessors.serialVersionUID.get = function () { return 6683108902428366910 };\nstaticAccessors.NULL_ORDINATE.get = function () { return Double.NaN };\nstaticAccessors.X.get = function () { return 0 };\nstaticAccessors.Y.get = function () { return 1 };\nstaticAccessors.Z.get = function () { return 2 };\n\nObject.defineProperties( Coordinate, staticAccessors );\n\nvar DimensionalComparator = function DimensionalComparator (dimensionsToTest) {\n this._dimensionsToTest = 2;\n if (arguments.length === 0) {} else if (arguments.length === 1) {\n var dimensionsToTest$1 = arguments[0];\n if (dimensionsToTest$1 !== 2 && dimensionsToTest$1 !== 3) { throw new IllegalArgumentException('only 2 or 3 dimensions may be specified') }\n this._dimensionsToTest = dimensionsToTest$1;\n }\n};\nDimensionalComparator.prototype.compare = function compare (o1, o2) {\n var c1 = o1;\n var c2 = o2;\n var compX = DimensionalComparator.compare(c1.x, c2.x);\n if (compX !== 0) { return compX }\n var compY = DimensionalComparator.compare(c1.y, c2.y);\n if (compY !== 0) { return compY }\n if (this._dimensionsToTest <= 2) { return 0 }\n var compZ = DimensionalComparator.compare(c1.z, c2.z);\n return compZ\n};\nDimensionalComparator.prototype.interfaces_ = function interfaces_ () {\n return [Comparator]\n};\nDimensionalComparator.prototype.getClass = function getClass () {\n return DimensionalComparator\n};\nDimensionalComparator.compare = function compare (a, b) {\n if (a < b) { return -1 }\n if (a > b) { return 1 }\n if (Double.isNaN(a)) {\n if (Double.isNaN(b)) { return 0 }\n return -1\n }\n if (Double.isNaN(b)) { return 1 }\n return 0\n};\n\n// import hasInterface from '../../../../hasInterface'\n// import CoordinateSequence from './CoordinateSequence'\n\nvar CoordinateSequenceFactory = function CoordinateSequenceFactory () {};\n\nCoordinateSequenceFactory.prototype.create = function create () {\n // if (arguments.length === 1) {\n // if (arguments[0] instanceof Array) {\n // let coordinates = arguments[0]\n // } else if (hasInterface(arguments[0], CoordinateSequence)) {\n // let coordSeq = arguments[0]\n // }\n // } else if (arguments.length === 2) {\n // let size = arguments[0]\n // let dimension = arguments[1]\n // }\n};\nCoordinateSequenceFactory.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nCoordinateSequenceFactory.prototype.getClass = function getClass () {\n return CoordinateSequenceFactory\n};\n\nvar Location = function Location () {};\n\nvar staticAccessors$4 = { INTERIOR: { configurable: true },BOUNDARY: { configurable: true },EXTERIOR: { configurable: true },NONE: { configurable: true } };\n\nLocation.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nLocation.prototype.getClass = function getClass () {\n return Location\n};\nLocation.toLocationSymbol = function toLocationSymbol (locationValue) {\n switch (locationValue) {\n case Location.EXTERIOR:\n return 'e'\n case Location.BOUNDARY:\n return 'b'\n case Location.INTERIOR:\n return 'i'\n case Location.NONE:\n return '-'\n default:\n }\n throw new IllegalArgumentException('Unknown location value: ' + locationValue)\n};\nstaticAccessors$4.INTERIOR.get = function () { return 0 };\nstaticAccessors$4.BOUNDARY.get = function () { return 1 };\nstaticAccessors$4.EXTERIOR.get = function () { return 2 };\nstaticAccessors$4.NONE.get = function () { return -1 };\n\nObject.defineProperties( Location, staticAccessors$4 );\n\nvar hasInterface = function (o, i) {\n return o.interfaces_ && o.interfaces_().indexOf(i) > -1\n};\n\nvar MathUtil = function MathUtil () {};\n\nvar staticAccessors$5 = { LOG_10: { configurable: true } };\n\nMathUtil.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nMathUtil.prototype.getClass = function getClass () {\n return MathUtil\n};\nMathUtil.log10 = function log10 (x) {\n var ln = Math.log(x);\n if (Double.isInfinite(ln)) { return ln }\n if (Double.isNaN(ln)) { return ln }\n return ln / MathUtil.LOG_10\n};\nMathUtil.min = function min (v1, v2, v3, v4) {\n var min = v1;\n if (v2 < min) { min = v2; }\n if (v3 < min) { min = v3; }\n if (v4 < min) { min = v4; }\n return min\n};\nMathUtil.clamp = function clamp () {\n if (typeof arguments[2] === 'number' && (typeof arguments[0] === 'number' && typeof arguments[1] === 'number')) {\n var x = arguments[0];\n var min = arguments[1];\n var max = arguments[2];\n if (x < min) { return min }\n if (x > max) { return max }\n return x\n } else if (Number.isInteger(arguments[2]) && (Number.isInteger(arguments[0]) && Number.isInteger(arguments[1]))) {\n var x$1 = arguments[0];\n var min$1 = arguments[1];\n var max$1 = arguments[2];\n if (x$1 < min$1) { return min$1 }\n if (x$1 > max$1) { return max$1 }\n return x$1\n }\n};\nMathUtil.wrap = function wrap (index, max) {\n if (index < 0) {\n return max - -index % max\n }\n return index % max\n};\nMathUtil.max = function max () {\n if (arguments.length === 3) {\n var v1 = arguments[0];\n var v2 = arguments[1];\n var v3 = arguments[2];\n var max = v1;\n if (v2 > max) { max = v2; }\n if (v3 > max) { max = v3; }\n return max\n } else if (arguments.length === 4) {\n var v1$1 = arguments[0];\n var v2$1 = arguments[1];\n var v3$1 = arguments[2];\n var v4 = arguments[3];\n var max$1 = v1$1;\n if (v2$1 > max$1) { max$1 = v2$1; }\n if (v3$1 > max$1) { max$1 = v3$1; }\n if (v4 > max$1) { max$1 = v4; }\n return max$1\n }\n};\nMathUtil.average = function average (x1, x2) {\n return (x1 + x2) / 2.0\n};\nstaticAccessors$5.LOG_10.get = function () { return Math.log(10) };\n\nObject.defineProperties( MathUtil, staticAccessors$5 );\n\nvar StringBuffer = function StringBuffer (str) {\n this.str = str;\n};\nStringBuffer.prototype.append = function append (e) {\n this.str += e;\n};\n\nStringBuffer.prototype.setCharAt = function setCharAt (i, c) {\n this.str = this.str.substr(0, i) + c + this.str.substr(i + 1);\n};\n\nStringBuffer.prototype.toString = function toString (e) {\n return this.str\n};\n\nvar Integer = function Integer (value) {\n this.value = value;\n};\nInteger.prototype.intValue = function intValue () {\n return this.value\n};\nInteger.prototype.compareTo = function compareTo (o) {\n if (this.value < o) { return -1 }\n if (this.value > o) { return 1 }\n return 0\n};\nInteger.isNaN = function isNaN (n) { return Number.isNaN(n) };\n\nvar Character = function Character () {};\n\nCharacter.isWhitespace = function isWhitespace (c) { return ((c <= 32 && c >= 0) || c === 127) };\nCharacter.toUpperCase = function toUpperCase (c) { return c.toUpperCase() };\n\nvar DD = function DD () {\n this._hi = 0.0;\n this._lo = 0.0;\n if (arguments.length === 0) {\n this.init(0.0);\n } else if (arguments.length === 1) {\n if (typeof arguments[0] === 'number') {\n var x = arguments[0];\n this.init(x);\n } else if (arguments[0] instanceof DD) {\n var dd = arguments[0];\n this.init(dd);\n } else if (typeof arguments[0] === 'string') {\n var str = arguments[0];\n DD.call(this, DD.parse(str));\n }\n } else if (arguments.length === 2) {\n var hi = arguments[0];\n var lo = arguments[1];\n this.init(hi, lo);\n }\n};\n\nvar staticAccessors$7 = { PI: { configurable: true },TWO_PI: { configurable: true },PI_2: { configurable: true },E: { configurable: true },NaN: { configurable: true },EPS: { configurable: true },SPLIT: { configurable: true },MAX_PRINT_DIGITS: { configurable: true },TEN: { configurable: true },ONE: { configurable: true },SCI_NOT_EXPONENT_CHAR: { configurable: true },SCI_NOT_ZERO: { configurable: true } };\nDD.prototype.le = function le (y) {\n return (this._hi < y._hi || this._hi === y._hi) && this._lo <= y._lo\n};\nDD.prototype.extractSignificantDigits = function extractSignificantDigits (insertDecimalPoint, magnitude) {\n var y = this.abs();\n var mag = DD.magnitude(y._hi);\n var scale = DD.TEN.pow(mag);\n y = y.divide(scale);\n if (y.gt(DD.TEN)) {\n y = y.divide(DD.TEN);\n mag += 1;\n } else if (y.lt(DD.ONE)) {\n y = y.multiply(DD.TEN);\n mag -= 1;\n }\n var decimalPointPos = mag + 1;\n var buf = new StringBuffer();\n var numDigits = DD.MAX_PRINT_DIGITS - 1;\n for (var i = 0; i <= numDigits; i++) {\n if (insertDecimalPoint && i === decimalPointPos) {\n buf.append('.');\n }\n var digit = Math.trunc(y._hi);\n if (digit < 0) {\n break\n }\n var rebiasBy10 = false;\n var digitChar = 0;\n if (digit > 9) {\n rebiasBy10 = true;\n digitChar = '9';\n } else {\n digitChar = '0' + digit;\n }\n buf.append(digitChar);\n y = y.subtract(DD.valueOf(digit)).multiply(DD.TEN);\n if (rebiasBy10) { y.selfAdd(DD.TEN); }\n var continueExtractingDigits = true;\n var remMag = DD.magnitude(y._hi);\n if (remMag < 0 && Math.abs(remMag) >= numDigits - i) { continueExtractingDigits = false; }\n if (!continueExtractingDigits) { break }\n }\n magnitude[0] = mag;\n return buf.toString()\n};\nDD.prototype.sqr = function sqr () {\n return this.multiply(this)\n};\nDD.prototype.doubleValue = function doubleValue () {\n return this._hi + this._lo\n};\nDD.prototype.subtract = function subtract () {\n if (arguments[0] instanceof DD) {\n var y = arguments[0];\n return this.add(y.negate())\n } else if (typeof arguments[0] === 'number') {\n var y$1 = arguments[0];\n return this.add(-y$1)\n }\n};\nDD.prototype.equals = function equals () {\n if (arguments.length === 1) {\n var y = arguments[0];\n return this._hi === y._hi && this._lo === y._lo\n }\n};\nDD.prototype.isZero = function isZero () {\n return this._hi === 0.0 && this._lo === 0.0\n};\nDD.prototype.selfSubtract = function selfSubtract () {\n if (arguments[0] instanceof DD) {\n var y = arguments[0];\n if (this.isNaN()) { return this }\n return this.selfAdd(-y._hi, -y._lo)\n } else if (typeof arguments[0] === 'number') {\n var y$1 = arguments[0];\n if (this.isNaN()) { return this }\n return this.selfAdd(-y$1, 0.0)\n }\n};\nDD.prototype.getSpecialNumberString = function getSpecialNumberString () {\n if (this.isZero()) { return '0.0' }\n if (this.isNaN()) { return 'NaN ' }\n return null\n};\nDD.prototype.min = function min (x) {\n if (this.le(x)) {\n return this\n } else {\n return x\n }\n};\nDD.prototype.selfDivide = function selfDivide () {\n if (arguments.length === 1) {\n if (arguments[0] instanceof DD) {\n var y = arguments[0];\n return this.selfDivide(y._hi, y._lo)\n } else if (typeof arguments[0] === 'number') {\n var y$1 = arguments[0];\n return this.selfDivide(y$1, 0.0)\n }\n } else if (arguments.length === 2) {\n var yhi = arguments[0];\n var ylo = arguments[1];\n var hc = null;\n var tc = null;\n var hy = null;\n var ty = null;\n var C = null;\n var c = null;\n var U = null;\n var u = null;\n C = this._hi / yhi;\n c = DD.SPLIT * C;\n hc = c - C;\n u = DD.SPLIT * yhi;\n hc = c - hc;\n tc = C - hc;\n hy = u - yhi;\n U = C * yhi;\n hy = u - hy;\n ty = yhi - hy;\n u = hc * hy - U + hc * ty + tc * hy + tc * ty;\n c = (this._hi - U - u + this._lo - C * ylo) / yhi;\n u = C + c;\n this._hi = u;\n this._lo = C - u + c;\n return this\n }\n};\nDD.prototype.dump = function dump () {\n return 'DD<' + this._hi + ', ' + this._lo + '>'\n};\nDD.prototype.divide = function divide () {\n if (arguments[0] instanceof DD) {\n var y = arguments[0];\n var hc = null;\n var tc = null;\n var hy = null;\n var ty = null;\n var C = null;\n var c = null;\n var U = null;\n var u = null;\n C = this._hi / y._hi;\n c = DD.SPLIT * C;\n hc = c - C;\n u = DD.SPLIT * y._hi;\n hc = c - hc;\n tc = C - hc;\n hy = u - y._hi;\n U = C * y._hi;\n hy = u - hy;\n ty = y._hi - hy;\n u = hc * hy - U + hc * ty + tc * hy + tc * ty;\n c = (this._hi - U - u + this._lo - C * y._lo) / y._hi;\n u = C + c;\n var zhi = u;\n var zlo = C - u + c;\n return new DD(zhi, zlo)\n } else if (typeof arguments[0] === 'number') {\n var y$1 = arguments[0];\n if (Double.isNaN(y$1)) { return DD.createNaN() }\n return DD.copy(this).selfDivide(y$1, 0.0)\n }\n};\nDD.prototype.ge = function ge (y) {\n return (this._hi > y._hi || this._hi === y._hi) && this._lo >= y._lo\n};\nDD.prototype.pow = function pow (exp) {\n if (exp === 0.0) { return DD.valueOf(1.0) }\n var r = new DD(this);\n var s = DD.valueOf(1.0);\n var n = Math.abs(exp);\n if (n > 1) {\n while (n > 0) {\n if (n % 2 === 1) {\n s.selfMultiply(r);\n }\n n /= 2;\n if (n > 0) { r = r.sqr(); }\n }\n } else {\n s = r;\n }\n if (exp < 0) { return s.reciprocal() }\n return s\n};\nDD.prototype.ceil = function ceil () {\n if (this.isNaN()) { return DD.NaN }\n var fhi = Math.ceil(this._hi);\n var flo = 0.0;\n if (fhi === this._hi) {\n flo = Math.ceil(this._lo);\n }\n return new DD(fhi, flo)\n};\nDD.prototype.compareTo = function compareTo (o) {\n var other = o;\n if (this._hi < other._hi) { return -1 }\n if (this._hi > other._hi) { return 1 }\n if (this._lo < other._lo) { return -1 }\n if (this._lo > other._lo) { return 1 }\n return 0\n};\nDD.prototype.rint = function rint () {\n if (this.isNaN()) { return this }\n var plus5 = this.add(0.5);\n return plus5.floor()\n};\nDD.prototype.setValue = function setValue () {\n if (arguments[0] instanceof DD) {\n var value = arguments[0];\n this.init(value);\n return this\n } else if (typeof arguments[0] === 'number') {\n var value$1 = arguments[0];\n this.init(value$1);\n return this\n }\n};\nDD.prototype.max = function max (x) {\n if (this.ge(x)) {\n return this\n } else {\n return x\n }\n};\nDD.prototype.sqrt = function sqrt () {\n if (this.isZero()) { return DD.valueOf(0.0) }\n if (this.isNegative()) {\n return DD.NaN\n }\n var x = 1.0 / Math.sqrt(this._hi);\n var ax = this._hi * x;\n var axdd = DD.valueOf(ax);\n var diffSq = this.subtract(axdd.sqr());\n var d2 = diffSq._hi * (x * 0.5);\n return axdd.add(d2)\n};\nDD.prototype.selfAdd = function selfAdd () {\n if (arguments.length === 1) {\n if (arguments[0] instanceof DD) {\n var y = arguments[0];\n return this.selfAdd(y._hi, y._lo)\n } else if (typeof arguments[0] === 'number') {\n var y$1 = arguments[0];\n var H = null;\n var h = null;\n var S = null;\n var s = null;\n var e = null;\n var f = null;\n S = this._hi + y$1;\n e = S - this._hi;\n s = S - e;\n s = y$1 - e + (this._hi - s);\n f = s + this._lo;\n H = S + f;\n h = f + (S - H);\n this._hi = H + h;\n this._lo = h + (H - this._hi);\n return this\n }\n } else if (arguments.length === 2) {\n var yhi = arguments[0];\n var ylo = arguments[1];\n var H$1 = null;\n var h$1 = null;\n var T = null;\n var t = null;\n var S$1 = null;\n var s$1 = null;\n var e$1 = null;\n var f$1 = null;\n S$1 = this._hi + yhi;\n T = this._lo + ylo;\n e$1 = S$1 - this._hi;\n f$1 = T - this._lo;\n s$1 = S$1 - e$1;\n t = T - f$1;\n s$1 = yhi - e$1 + (this._hi - s$1);\n t = ylo - f$1 + (this._lo - t);\n e$1 = s$1 + T;\n H$1 = S$1 + e$1;\n h$1 = e$1 + (S$1 - H$1);\n e$1 = t + h$1;\n var zhi = H$1 + e$1;\n var zlo = e$1 + (H$1 - zhi);\n this._hi = zhi;\n this._lo = zlo;\n return this\n }\n};\nDD.prototype.selfMultiply = function selfMultiply () {\n if (arguments.length === 1) {\n if (arguments[0] instanceof DD) {\n var y = arguments[0];\n return this.selfMultiply(y._hi, y._lo)\n } else if (typeof arguments[0] === 'number') {\n var y$1 = arguments[0];\n return this.selfMultiply(y$1, 0.0)\n }\n } else if (arguments.length === 2) {\n var yhi = arguments[0];\n var ylo = arguments[1];\n var hx = null;\n var tx = null;\n var hy = null;\n var ty = null;\n var C = null;\n var c = null;\n C = DD.SPLIT * this._hi;\n hx = C - this._hi;\n c = DD.SPLIT * yhi;\n hx = C - hx;\n tx = this._hi - hx;\n hy = c - yhi;\n C = this._hi * yhi;\n hy = c - hy;\n ty = yhi - hy;\n c = hx * hy - C + hx * ty + tx * hy + tx * ty + (this._hi * ylo + this._lo * yhi);\n var zhi = C + c;\n hx = C - zhi;\n var zlo = c + hx;\n this._hi = zhi;\n this._lo = zlo;\n return this\n }\n};\nDD.prototype.selfSqr = function selfSqr () {\n return this.selfMultiply(this)\n};\nDD.prototype.floor = function floor () {\n if (this.isNaN()) { return DD.NaN }\n var fhi = Math.floor(this._hi);\n var flo = 0.0;\n if (fhi === this._hi) {\n flo = Math.floor(this._lo);\n }\n return new DD(fhi, flo)\n};\nDD.prototype.negate = function negate () {\n if (this.isNaN()) { return this }\n return new DD(-this._hi, -this._lo)\n};\nDD.prototype.clone = function clone () {\n // try {\n // return null\n // } catch (ex) {\n // if (ex instanceof CloneNotSupportedException) {\n // return null\n // } else throw ex\n // } finally {}\n};\nDD.prototype.multiply = function multiply () {\n if (arguments[0] instanceof DD) {\n var y = arguments[0];\n if (y.isNaN()) { return DD.createNaN() }\n return DD.copy(this).selfMultiply(y)\n } else if (typeof arguments[0] === 'number') {\n var y$1 = arguments[0];\n if (Double.isNaN(y$1)) { return DD.createNaN() }\n return DD.copy(this).selfMultiply(y$1, 0.0)\n }\n};\nDD.prototype.isNaN = function isNaN () {\n return Double.isNaN(this._hi)\n};\nDD.prototype.intValue = function intValue () {\n return Math.trunc(this._hi)\n};\nDD.prototype.toString = function toString () {\n var mag = DD.magnitude(this._hi);\n if (mag >= -3 && mag <= 20) { return this.toStandardNotation() }\n return this.toSciNotation()\n};\nDD.prototype.toStandardNotation = function toStandardNotation () {\n var specialStr = this.getSpecialNumberString();\n if (specialStr !== null) { return specialStr }\n var magnitude = new Array(1).fill(null);\n var sigDigits = this.extractSignificantDigits(true, magnitude);\n var decimalPointPos = magnitude[0] + 1;\n var num = sigDigits;\n if (sigDigits.charAt(0) === '.') {\n num = '0' + sigDigits;\n } else if (decimalPointPos < 0) {\n num = '0.' + DD.stringOfChar('0', -decimalPointPos) + sigDigits;\n } else if (sigDigits.indexOf('.') === -1) {\n var numZeroes = decimalPointPos - sigDigits.length;\n var zeroes = DD.stringOfChar('0', numZeroes);\n num = sigDigits + zeroes + '.0';\n }\n if (this.isNegative()) { return '-' + num }\n return num\n};\nDD.prototype.reciprocal = function reciprocal () {\n var hc = null;\n var tc = null;\n var hy = null;\n var ty = null;\n var C = null;\n var c = null;\n var U = null;\n var u = null;\n C = 1.0 / this._hi;\n c = DD.SPLIT * C;\n hc = c - C;\n u = DD.SPLIT * this._hi;\n hc = c - hc;\n tc = C - hc;\n hy = u - this._hi;\n U = C * this._hi;\n hy = u - hy;\n ty = this._hi - hy;\n u = hc * hy - U + hc * ty + tc * hy + tc * ty;\n c = (1.0 - U - u - C * this._lo) / this._hi;\n var zhi = C + c;\n var zlo = C - zhi + c;\n return new DD(zhi, zlo)\n};\nDD.prototype.toSciNotation = function toSciNotation () {\n if (this.isZero()) { return DD.SCI_NOT_ZERO }\n var specialStr = this.getSpecialNumberString();\n if (specialStr !== null) { return specialStr }\n var magnitude = new Array(1).fill(null);\n var digits = this.extractSignificantDigits(false, magnitude);\n var expStr = DD.SCI_NOT_EXPONENT_CHAR + magnitude[0];\n if (digits.charAt(0) === '0') {\n throw new Error('Found leading zero: ' + digits)\n }\n var trailingDigits = '';\n if (digits.length > 1) { trailingDigits = digits.substring(1); }\n var digitsWithDecimal = digits.charAt(0) + '.' + trailingDigits;\n if (this.isNegative()) { return '-' + digitsWithDecimal + expStr }\n return digitsWithDecimal + expStr\n};\nDD.prototype.abs = function abs () {\n if (this.isNaN()) { return DD.NaN }\n if (this.isNegative()) { return this.negate() }\n return new DD(this)\n};\nDD.prototype.isPositive = function isPositive () {\n return (this._hi > 0.0 || this._hi === 0.0) && this._lo > 0.0\n};\nDD.prototype.lt = function lt (y) {\n return (this._hi < y._hi || this._hi === y._hi) && this._lo < y._lo\n};\nDD.prototype.add = function add () {\n if (arguments[0] instanceof DD) {\n var y = arguments[0];\n return DD.copy(this).selfAdd(y)\n } else if (typeof arguments[0] === 'number') {\n var y$1 = arguments[0];\n return DD.copy(this).selfAdd(y$1)\n }\n};\nDD.prototype.init = function init () {\n if (arguments.length === 1) {\n if (typeof arguments[0] === 'number') {\n var x = arguments[0];\n this._hi = x;\n this._lo = 0.0;\n } else if (arguments[0] instanceof DD) {\n var dd = arguments[0];\n this._hi = dd._hi;\n this._lo = dd._lo;\n }\n } else if (arguments.length === 2) {\n var hi = arguments[0];\n var lo = arguments[1];\n this._hi = hi;\n this._lo = lo;\n }\n};\nDD.prototype.gt = function gt (y) {\n return (this._hi > y._hi || this._hi === y._hi) && this._lo > y._lo\n};\nDD.prototype.isNegative = function isNegative () {\n return (this._hi < 0.0 || this._hi === 0.0) && this._lo < 0.0\n};\nDD.prototype.trunc = function trunc () {\n if (this.isNaN()) { return DD.NaN }\n if (this.isPositive()) { return this.floor(); } else { return this.ceil() }\n};\nDD.prototype.signum = function signum () {\n if (this._hi > 0) { return 1 }\n if (this._hi < 0) { return -1 }\n if (this._lo > 0) { return 1 }\n if (this._lo < 0) { return -1 }\n return 0\n};\nDD.prototype.interfaces_ = function interfaces_ () {\n return [Serializable, Comparable, Clonable]\n};\nDD.prototype.getClass = function getClass () {\n return DD\n};\nDD.sqr = function sqr (x) {\n return DD.valueOf(x).selfMultiply(x)\n};\nDD.valueOf = function valueOf () {\n if (typeof arguments[0] === 'string') {\n var str = arguments[0];\n return DD.parse(str)\n } else if (typeof arguments[0] === 'number') {\n var x = arguments[0];\n return new DD(x)\n }\n};\nDD.sqrt = function sqrt (x) {\n return DD.valueOf(x).sqrt()\n};\nDD.parse = function parse (str) {\n var i = 0;\n var strlen = str.length;\n while (Character.isWhitespace(str.charAt(i))) { i++; }\n var isNegative = false;\n if (i < strlen) {\n var signCh = str.charAt(i);\n if (signCh === '-' || signCh === '+') {\n i++;\n if (signCh === '-') { isNegative = true; }\n }\n }\n var val = new DD();\n var numDigits = 0;\n var numBeforeDec = 0;\n var exp = 0;\n while (true) {\n if (i >= strlen) { break }\n var ch = str.charAt(i);\n i++;\n if (Character.isDigit(ch)) {\n var d = ch - '0';\n val.selfMultiply(DD.TEN);\n val.selfAdd(d);\n numDigits++;\n continue\n }\n if (ch === '.') {\n numBeforeDec = numDigits;\n continue\n }\n if (ch === 'e' || ch === 'E') {\n var expStr = str.substring(i);\n try {\n exp = Integer.parseInt(expStr);\n } catch (ex) {\n if (ex instanceof Error) {\n throw new Error('Invalid exponent ' + expStr + ' in string ' + str)\n } else { throw ex }\n } finally {}\n break\n }\n throw new Error(\"Unexpected character '\" + ch + \"' at position \" + i + ' in string ' + str)\n }\n var val2 = val;\n var numDecPlaces = numDigits - numBeforeDec - exp;\n if (numDecPlaces === 0) {\n val2 = val;\n } else if (numDecPlaces > 0) {\n var scale = DD.TEN.pow(numDecPlaces);\n val2 = val.divide(scale);\n } else if (numDecPlaces < 0) {\n var scale$1 = DD.TEN.pow(-numDecPlaces);\n val2 = val.multiply(scale$1);\n }\n if (isNegative) {\n return val2.negate()\n }\n return val2\n};\nDD.createNaN = function createNaN () {\n return new DD(Double.NaN, Double.NaN)\n};\nDD.copy = function copy (dd) {\n return new DD(dd)\n};\nDD.magnitude = function magnitude (x) {\n var xAbs = Math.abs(x);\n var xLog10 = Math.log(xAbs) / Math.log(10);\n var xMag = Math.trunc(Math.floor(xLog10));\n var xApprox = Math.pow(10, xMag);\n if (xApprox * 10 <= xAbs) { xMag += 1; }\n return xMag\n};\nDD.stringOfChar = function stringOfChar (ch, len) {\n var buf = new StringBuffer();\n for (var i = 0; i < len; i++) {\n buf.append(ch);\n }\n return buf.toString()\n};\nstaticAccessors$7.PI.get = function () { return new DD(3.141592653589793116e+00, 1.224646799147353207e-16) };\nstaticAccessors$7.TWO_PI.get = function () { return new DD(6.283185307179586232e+00, 2.449293598294706414e-16) };\nstaticAccessors$7.PI_2.get = function () { return new DD(1.570796326794896558e+00, 6.123233995736766036e-17) };\nstaticAccessors$7.E.get = function () { return new DD(2.718281828459045091e+00, 1.445646891729250158e-16) };\nstaticAccessors$7.NaN.get = function () { return new DD(Double.NaN, Double.NaN) };\nstaticAccessors$7.EPS.get = function () { return 1.23259516440783e-32 };\nstaticAccessors$7.SPLIT.get = function () { return 134217729.0 };\nstaticAccessors$7.MAX_PRINT_DIGITS.get = function () { return 32 };\nstaticAccessors$7.TEN.get = function () { return DD.valueOf(10.0) };\nstaticAccessors$7.ONE.get = function () { return DD.valueOf(1.0) };\nstaticAccessors$7.SCI_NOT_EXPONENT_CHAR.get = function () { return 'E' };\nstaticAccessors$7.SCI_NOT_ZERO.get = function () { return '0.0E0' };\n\nObject.defineProperties( DD, staticAccessors$7 );\n\nvar CGAlgorithmsDD = function CGAlgorithmsDD () {};\n\nvar staticAccessors$6 = { DP_SAFE_EPSILON: { configurable: true } };\n\nCGAlgorithmsDD.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nCGAlgorithmsDD.prototype.getClass = function getClass () {\n return CGAlgorithmsDD\n};\nCGAlgorithmsDD.orientationIndex = function orientationIndex (p1, p2, q) {\n var index = CGAlgorithmsDD.orientationIndexFilter(p1, p2, q);\n if (index <= 1) { return index }\n var dx1 = DD.valueOf(p2.x).selfAdd(-p1.x);\n var dy1 = DD.valueOf(p2.y).selfAdd(-p1.y);\n var dx2 = DD.valueOf(q.x).selfAdd(-p2.x);\n var dy2 = DD.valueOf(q.y).selfAdd(-p2.y);\n return dx1.selfMultiply(dy2).selfSubtract(dy1.selfMultiply(dx2)).signum()\n};\nCGAlgorithmsDD.signOfDet2x2 = function signOfDet2x2 (x1, y1, x2, y2) {\n var det = x1.multiply(y2).selfSubtract(y1.multiply(x2));\n return det.signum()\n};\nCGAlgorithmsDD.intersection = function intersection (p1, p2, q1, q2) {\n var denom1 = DD.valueOf(q2.y).selfSubtract(q1.y).selfMultiply(DD.valueOf(p2.x).selfSubtract(p1.x));\n var denom2 = DD.valueOf(q2.x).selfSubtract(q1.x).selfMultiply(DD.valueOf(p2.y).selfSubtract(p1.y));\n var denom = denom1.subtract(denom2);\n var numx1 = DD.valueOf(q2.x).selfSubtract(q1.x).selfMultiply(DD.valueOf(p1.y).selfSubtract(q1.y));\n var numx2 = DD.valueOf(q2.y).selfSubtract(q1.y).selfMultiply(DD.valueOf(p1.x).selfSubtract(q1.x));\n var numx = numx1.subtract(numx2);\n var fracP = numx.selfDivide(denom).doubleValue();\n var x = DD.valueOf(p1.x).selfAdd(DD.valueOf(p2.x).selfSubtract(p1.x).selfMultiply(fracP)).doubleValue();\n var numy1 = DD.valueOf(p2.x).selfSubtract(p1.x).selfMultiply(DD.valueOf(p1.y).selfSubtract(q1.y));\n var numy2 = DD.valueOf(p2.y).selfSubtract(p1.y).selfMultiply(DD.valueOf(p1.x).selfSubtract(q1.x));\n var numy = numy1.subtract(numy2);\n var fracQ = numy.selfDivide(denom).doubleValue();\n var y = DD.valueOf(q1.y).selfAdd(DD.valueOf(q2.y).selfSubtract(q1.y).selfMultiply(fracQ)).doubleValue();\n return new Coordinate(x, y)\n};\nCGAlgorithmsDD.orientationIndexFilter = function orientationIndexFilter (pa, pb, pc) {\n var detsum = null;\n var detleft = (pa.x - pc.x) * (pb.y - pc.y);\n var detright = (pa.y - pc.y) * (pb.x - pc.x);\n var det = detleft - detright;\n if (detleft > 0.0) {\n if (detright <= 0.0) {\n return CGAlgorithmsDD.signum(det)\n } else {\n detsum = detleft + detright;\n }\n } else if (detleft < 0.0) {\n if (detright >= 0.0) {\n return CGAlgorithmsDD.signum(det)\n } else {\n detsum = -detleft - detright;\n }\n } else {\n return CGAlgorithmsDD.signum(det)\n }\n var errbound = CGAlgorithmsDD.DP_SAFE_EPSILON * detsum;\n if (det >= errbound || -det >= errbound) {\n return CGAlgorithmsDD.signum(det)\n }\n return 2\n};\nCGAlgorithmsDD.signum = function signum (x) {\n if (x > 0) { return 1 }\n if (x < 0) { return -1 }\n return 0\n};\nstaticAccessors$6.DP_SAFE_EPSILON.get = function () { return 1e-15 };\n\nObject.defineProperties( CGAlgorithmsDD, staticAccessors$6 );\n\nvar CoordinateSequence = function CoordinateSequence () {};\n\nvar staticAccessors$8 = { X: { configurable: true },Y: { configurable: true },Z: { configurable: true },M: { configurable: true } };\n\nstaticAccessors$8.X.get = function () { return 0 };\nstaticAccessors$8.Y.get = function () { return 1 };\nstaticAccessors$8.Z.get = function () { return 2 };\nstaticAccessors$8.M.get = function () { return 3 };\nCoordinateSequence.prototype.setOrdinate = function setOrdinate (index, ordinateIndex, value) {};\nCoordinateSequence.prototype.size = function size () {};\nCoordinateSequence.prototype.getOrdinate = function getOrdinate (index, ordinateIndex) {};\nCoordinateSequence.prototype.getCoordinate = function getCoordinate () {};\nCoordinateSequence.prototype.getCoordinateCopy = function getCoordinateCopy (i) {};\nCoordinateSequence.prototype.getDimension = function getDimension () {};\nCoordinateSequence.prototype.getX = function getX (index) {};\nCoordinateSequence.prototype.clone = function clone () {};\nCoordinateSequence.prototype.expandEnvelope = function expandEnvelope (env) {};\nCoordinateSequence.prototype.copy = function copy () {};\nCoordinateSequence.prototype.getY = function getY (index) {};\nCoordinateSequence.prototype.toCoordinateArray = function toCoordinateArray () {};\nCoordinateSequence.prototype.interfaces_ = function interfaces_ () {\n return [Clonable]\n};\nCoordinateSequence.prototype.getClass = function getClass () {\n return CoordinateSequence\n};\n\nObject.defineProperties( CoordinateSequence, staticAccessors$8 );\n\nvar Exception = function Exception () {};\n\nvar NotRepresentableException = (function (Exception$$1) {\n function NotRepresentableException () {\n Exception$$1.call(this, 'Projective point not representable on the Cartesian plane.');\n }\n\n if ( Exception$$1 ) NotRepresentableException.__proto__ = Exception$$1;\n NotRepresentableException.prototype = Object.create( Exception$$1 && Exception$$1.prototype );\n NotRepresentableException.prototype.constructor = NotRepresentableException;\n NotRepresentableException.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n NotRepresentableException.prototype.getClass = function getClass () {\n return NotRepresentableException\n };\n\n return NotRepresentableException;\n}(Exception));\n\nvar System = function System () {};\n\nSystem.arraycopy = function arraycopy (src, srcPos, dest, destPos, len) {\n var c = 0;\n for (var i = srcPos; i < srcPos + len; i++) {\n dest[destPos + c] = src[i];\n c++;\n }\n};\n\nSystem.getProperty = function getProperty (name) {\n return {\n 'line.separator': '\\n'\n }[name]\n};\n\nvar HCoordinate = function HCoordinate () {\n this.x = null;\n this.y = null;\n this.w = null;\n if (arguments.length === 0) {\n this.x = 0.0;\n this.y = 0.0;\n this.w = 1.0;\n } else if (arguments.length === 1) {\n var p = arguments[0];\n this.x = p.x;\n this.y = p.y;\n this.w = 1.0;\n } else if (arguments.length === 2) {\n if (typeof arguments[0] === 'number' && typeof arguments[1] === 'number') {\n var _x = arguments[0];\n var _y = arguments[1];\n this.x = _x;\n this.y = _y;\n this.w = 1.0;\n } else if (arguments[0] instanceof HCoordinate && arguments[1] instanceof HCoordinate) {\n var p1 = arguments[0];\n var p2 = arguments[1];\n this.x = p1.y * p2.w - p2.y * p1.w;\n this.y = p2.x * p1.w - p1.x * p2.w;\n this.w = p1.x * p2.y - p2.x * p1.y;\n } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Coordinate) {\n var p1$1 = arguments[0];\n var p2$1 = arguments[1];\n this.x = p1$1.y - p2$1.y;\n this.y = p2$1.x - p1$1.x;\n this.w = p1$1.x * p2$1.y - p2$1.x * p1$1.y;\n }\n } else if (arguments.length === 3) {\n var _x$1 = arguments[0];\n var _y$1 = arguments[1];\n var _w = arguments[2];\n this.x = _x$1;\n this.y = _y$1;\n this.w = _w;\n } else if (arguments.length === 4) {\n var p1$2 = arguments[0];\n var p2$2 = arguments[1];\n var q1 = arguments[2];\n var q2 = arguments[3];\n var px = p1$2.y - p2$2.y;\n var py = p2$2.x - p1$2.x;\n var pw = p1$2.x * p2$2.y - p2$2.x * p1$2.y;\n var qx = q1.y - q2.y;\n var qy = q2.x - q1.x;\n var qw = q1.x * q2.y - q2.x * q1.y;\n this.x = py * qw - qy * pw;\n this.y = qx * pw - px * qw;\n this.w = px * qy - qx * py;\n }\n};\nHCoordinate.prototype.getY = function getY () {\n var a = this.y / this.w;\n if (Double.isNaN(a) || Double.isInfinite(a)) {\n throw new NotRepresentableException()\n }\n return a\n};\nHCoordinate.prototype.getX = function getX () {\n var a = this.x / this.w;\n if (Double.isNaN(a) || Double.isInfinite(a)) {\n throw new NotRepresentableException()\n }\n return a\n};\nHCoordinate.prototype.getCoordinate = function getCoordinate () {\n var p = new Coordinate();\n p.x = this.getX();\n p.y = this.getY();\n return p\n};\nHCoordinate.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nHCoordinate.prototype.getClass = function getClass () {\n return HCoordinate\n};\nHCoordinate.intersection = function intersection (p1, p2, q1, q2) {\n var px = p1.y - p2.y;\n var py = p2.x - p1.x;\n var pw = p1.x * p2.y - p2.x * p1.y;\n var qx = q1.y - q2.y;\n var qy = q2.x - q1.x;\n var qw = q1.x * q2.y - q2.x * q1.y;\n var x = py * qw - qy * pw;\n var y = qx * pw - px * qw;\n var w = px * qy - qx * py;\n var xInt = x / w;\n var yInt = y / w;\n if (Double.isNaN(xInt) || (Double.isInfinite(xInt) || Double.isNaN(yInt)) || Double.isInfinite(yInt)) {\n throw new NotRepresentableException()\n }\n return new Coordinate(xInt, yInt)\n};\n\nvar Envelope = function Envelope () {\n this._minx = null;\n this._maxx = null;\n this._miny = null;\n this._maxy = null;\n if (arguments.length === 0) {\n this.init();\n } else if (arguments.length === 1) {\n if (arguments[0] instanceof Coordinate) {\n var p = arguments[0];\n this.init(p.x, p.x, p.y, p.y);\n } else if (arguments[0] instanceof Envelope) {\n var env = arguments[0];\n this.init(env);\n }\n } else if (arguments.length === 2) {\n var p1 = arguments[0];\n var p2 = arguments[1];\n this.init(p1.x, p2.x, p1.y, p2.y);\n } else if (arguments.length === 4) {\n var x1 = arguments[0];\n var x2 = arguments[1];\n var y1 = arguments[2];\n var y2 = arguments[3];\n this.init(x1, x2, y1, y2);\n }\n};\n\nvar staticAccessors$9 = { serialVersionUID: { configurable: true } };\nEnvelope.prototype.getArea = function getArea () {\n return this.getWidth() * this.getHeight()\n};\nEnvelope.prototype.equals = function equals (other) {\n if (!(other instanceof Envelope)) {\n return false\n }\n var otherEnvelope = other;\n if (this.isNull()) {\n return otherEnvelope.isNull()\n }\n return this._maxx === otherEnvelope.getMaxX() && this._maxy === otherEnvelope.getMaxY() && this._minx === otherEnvelope.getMinX() && this._miny === otherEnvelope.getMinY()\n};\nEnvelope.prototype.intersection = function intersection (env) {\n if (this.isNull() || env.isNull() || !this.intersects(env)) { return new Envelope() }\n var intMinX = this._minx > env._minx ? this._minx : env._minx;\n var intMinY = this._miny > env._miny ? this._miny : env._miny;\n var intMaxX = this._maxx < env._maxx ? this._maxx : env._maxx;\n var intMaxY = this._maxy < env._maxy ? this._maxy : env._maxy;\n return new Envelope(intMinX, intMaxX, intMinY, intMaxY)\n};\nEnvelope.prototype.isNull = function isNull () {\n return this._maxx < this._minx\n};\nEnvelope.prototype.getMaxX = function getMaxX () {\n return this._maxx\n};\nEnvelope.prototype.covers = function covers () {\n if (arguments.length === 1) {\n if (arguments[0] instanceof Coordinate) {\n var p = arguments[0];\n return this.covers(p.x, p.y)\n } else if (arguments[0] instanceof Envelope) {\n var other = arguments[0];\n if (this.isNull() || other.isNull()) {\n return false\n }\n return other.getMinX() >= this._minx && other.getMaxX() <= this._maxx && other.getMinY() >= this._miny && other.getMaxY() <= this._maxy\n }\n } else if (arguments.length === 2) {\n var x = arguments[0];\n var y = arguments[1];\n if (this.isNull()) { return false }\n return x >= this._minx && x <= this._maxx && y >= this._miny && y <= this._maxy\n }\n};\nEnvelope.prototype.intersects = function intersects () {\n if (arguments.length === 1) {\n if (arguments[0] instanceof Envelope) {\n var other = arguments[0];\n if (this.isNull() || other.isNull()) {\n return false\n }\n return !(other._minx > this._maxx || other._maxx < this._minx || other._miny > this._maxy || other._maxy < this._miny)\n } else if (arguments[0] instanceof Coordinate) {\n var p = arguments[0];\n return this.intersects(p.x, p.y)\n }\n } else if (arguments.length === 2) {\n var x = arguments[0];\n var y = arguments[1];\n if (this.isNull()) { return false }\n return !(x > this._maxx || x < this._minx || y > this._maxy || y < this._miny)\n }\n};\nEnvelope.prototype.getMinY = function getMinY () {\n return this._miny\n};\nEnvelope.prototype.getMinX = function getMinX () {\n return this._minx\n};\nEnvelope.prototype.expandToInclude = function expandToInclude () {\n if (arguments.length === 1) {\n if (arguments[0] instanceof Coordinate) {\n var p = arguments[0];\n this.expandToInclude(p.x, p.y);\n } else if (arguments[0] instanceof Envelope) {\n var other = arguments[0];\n if (other.isNull()) {\n return null\n }\n if (this.isNull()) {\n this._minx = other.getMinX();\n this._maxx = other.getMaxX();\n this._miny = other.getMinY();\n this._maxy = other.getMaxY();\n } else {\n if (other._minx < this._minx) {\n this._minx = other._minx;\n }\n if (other._maxx > this._maxx) {\n this._maxx = other._maxx;\n }\n if (other._miny < this._miny) {\n this._miny = other._miny;\n }\n if (other._maxy > this._maxy) {\n this._maxy = other._maxy;\n }\n }\n }\n } else if (arguments.length === 2) {\n var x = arguments[0];\n var y = arguments[1];\n if (this.isNull()) {\n this._minx = x;\n this._maxx = x;\n this._miny = y;\n this._maxy = y;\n } else {\n if (x < this._minx) {\n this._minx = x;\n }\n if (x > this._maxx) {\n this._maxx = x;\n }\n if (y < this._miny) {\n this._miny = y;\n }\n if (y > this._maxy) {\n this._maxy = y;\n }\n }\n }\n};\nEnvelope.prototype.minExtent = function minExtent () {\n if (this.isNull()) { return 0.0 }\n var w = this.getWidth();\n var h = this.getHeight();\n if (w < h) { return w }\n return h\n};\nEnvelope.prototype.getWidth = function getWidth () {\n if (this.isNull()) {\n return 0\n }\n return this._maxx - this._minx\n};\nEnvelope.prototype.compareTo = function compareTo (o) {\n var env = o;\n if (this.isNull()) {\n if (env.isNull()) { return 0 }\n return -1\n } else {\n if (env.isNull()) { return 1 }\n }\n if (this._minx < env._minx) { return -1 }\n if (this._minx > env._minx) { return 1 }\n if (this._miny < env._miny) { return -1 }\n if (this._miny > env._miny) { return 1 }\n if (this._maxx < env._maxx) { return -1 }\n if (this._maxx > env._maxx) { return 1 }\n if (this._maxy < env._maxy) { return -1 }\n if (this._maxy > env._maxy) { return 1 }\n return 0\n};\nEnvelope.prototype.translate = function translate (transX, transY) {\n if (this.isNull()) {\n return null\n }\n this.init(this.getMinX() + transX, this.getMaxX() + transX, this.getMinY() + transY, this.getMaxY() + transY);\n};\nEnvelope.prototype.toString = function toString () {\n return 'Env[' + this._minx + ' : ' + this._maxx + ', ' + this._miny + ' : ' + this._maxy + ']'\n};\nEnvelope.prototype.setToNull = function setToNull () {\n this._minx = 0;\n this._maxx = -1;\n this._miny = 0;\n this._maxy = -1;\n};\nEnvelope.prototype.getHeight = function getHeight () {\n if (this.isNull()) {\n return 0\n }\n return this._maxy - this._miny\n};\nEnvelope.prototype.maxExtent = function maxExtent () {\n if (this.isNull()) { return 0.0 }\n var w = this.getWidth();\n var h = this.getHeight();\n if (w > h) { return w }\n return h\n};\nEnvelope.prototype.expandBy = function expandBy () {\n if (arguments.length === 1) {\n var distance = arguments[0];\n this.expandBy(distance, distance);\n } else if (arguments.length === 2) {\n var deltaX = arguments[0];\n var deltaY = arguments[1];\n if (this.isNull()) { return null }\n this._minx -= deltaX;\n this._maxx += deltaX;\n this._miny -= deltaY;\n this._maxy += deltaY;\n if (this._minx > this._maxx || this._miny > this._maxy) { this.setToNull(); }\n }\n};\nEnvelope.prototype.contains = function contains () {\n if (arguments.length === 1) {\n if (arguments[0] instanceof Envelope) {\n var other = arguments[0];\n return this.covers(other)\n } else if (arguments[0] instanceof Coordinate) {\n var p = arguments[0];\n return this.covers(p)\n }\n } else if (arguments.length === 2) {\n var x = arguments[0];\n var y = arguments[1];\n return this.covers(x, y)\n }\n};\nEnvelope.prototype.centre = function centre () {\n if (this.isNull()) { return null }\n return new Coordinate((this.getMinX() + this.getMaxX()) / 2.0, (this.getMinY() + this.getMaxY()) / 2.0)\n};\nEnvelope.prototype.init = function init () {\n if (arguments.length === 0) {\n this.setToNull();\n } else if (arguments.length === 1) {\n if (arguments[0] instanceof Coordinate) {\n var p = arguments[0];\n this.init(p.x, p.x, p.y, p.y);\n } else if (arguments[0] instanceof Envelope) {\n var env = arguments[0];\n this._minx = env._minx;\n this._maxx = env._maxx;\n this._miny = env._miny;\n this._maxy = env._maxy;\n }\n } else if (arguments.length === 2) {\n var p1 = arguments[0];\n var p2 = arguments[1];\n this.init(p1.x, p2.x, p1.y, p2.y);\n } else if (arguments.length === 4) {\n var x1 = arguments[0];\n var x2 = arguments[1];\n var y1 = arguments[2];\n var y2 = arguments[3];\n if (x1 < x2) {\n this._minx = x1;\n this._maxx = x2;\n } else {\n this._minx = x2;\n this._maxx = x1;\n }\n if (y1 < y2) {\n this._miny = y1;\n this._maxy = y2;\n } else {\n this._miny = y2;\n this._maxy = y1;\n }\n }\n};\nEnvelope.prototype.getMaxY = function getMaxY () {\n return this._maxy\n};\nEnvelope.prototype.distance = function distance (env) {\n if (this.intersects(env)) { return 0 }\n var dx = 0.0;\n if (this._maxx < env._minx) { dx = env._minx - this._maxx; } else if (this._minx > env._maxx) { dx = this._minx - env._maxx; }\n var dy = 0.0;\n if (this._maxy < env._miny) { dy = env._miny - this._maxy; } else if (this._miny > env._maxy) { dy = this._miny - env._maxy; }\n if (dx === 0.0) { return dy }\n if (dy === 0.0) { return dx }\n return Math.sqrt(dx * dx + dy * dy)\n};\nEnvelope.prototype.hashCode = function hashCode () {\n var result = 17;\n result = 37 * result + Coordinate.hashCode(this._minx);\n result = 37 * result + Coordinate.hashCode(this._maxx);\n result = 37 * result + Coordinate.hashCode(this._miny);\n result = 37 * result + Coordinate.hashCode(this._maxy);\n return result\n};\nEnvelope.prototype.interfaces_ = function interfaces_ () {\n return [Comparable, Serializable]\n};\nEnvelope.prototype.getClass = function getClass () {\n return Envelope\n};\nEnvelope.intersects = function intersects () {\n if (arguments.length === 3) {\n var p1 = arguments[0];\n var p2 = arguments[1];\n var q = arguments[2];\n if (q.x >= (p1.x < p2.x ? p1.x : p2.x) && q.x <= (p1.x > p2.x ? p1.x : p2.x) && (q.y >= (p1.y < p2.y ? p1.y : p2.y) && q.y <= (p1.y > p2.y ? p1.y : p2.y))) {\n return true\n }\n return false\n } else if (arguments.length === 4) {\n var p1$1 = arguments[0];\n var p2$1 = arguments[1];\n var q1 = arguments[2];\n var q2 = arguments[3];\n var minq = Math.min(q1.x, q2.x);\n var maxq = Math.max(q1.x, q2.x);\n var minp = Math.min(p1$1.x, p2$1.x);\n var maxp = Math.max(p1$1.x, p2$1.x);\n if (minp > maxq) { return false }\n if (maxp < minq) { return false }\n minq = Math.min(q1.y, q2.y);\n maxq = Math.max(q1.y, q2.y);\n minp = Math.min(p1$1.y, p2$1.y);\n maxp = Math.max(p1$1.y, p2$1.y);\n if (minp > maxq) { return false }\n if (maxp < minq) { return false }\n return true\n }\n};\nstaticAccessors$9.serialVersionUID.get = function () { return 5873921885273102420 };\n\nObject.defineProperties( Envelope, staticAccessors$9 );\n\nvar regExes = {\n 'typeStr': /^\\s*(\\w+)\\s*\\(\\s*(.*)\\s*\\)\\s*$/,\n 'emptyTypeStr': /^\\s*(\\w+)\\s*EMPTY\\s*$/,\n 'spaces': /\\s+/,\n 'parenComma': /\\)\\s*,\\s*\\(/,\n 'doubleParenComma': /\\)\\s*\\)\\s*,\\s*\\(\\s*\\(/, // can't use {2} here\n 'trimParens': /^\\s*\\(?(.*?)\\)?\\s*$/\n};\n\n/**\n * Class for reading and writing Well-Known Text.\n *\n * NOTE: Adapted from OpenLayers 2.11 implementation.\n */\n\n/** Create a new parser for WKT\n *\n * @param {GeometryFactory} geometryFactory\n * @return An instance of WKTParser.\n * @constructor\n * @private\n */\nvar WKTParser = function WKTParser (geometryFactory) {\n this.geometryFactory = geometryFactory || new GeometryFactory();\n};\n/**\n * Deserialize a WKT string and return a geometry. Supports WKT for POINT,\n * MULTIPOINT, LINESTRING, LINEARRING, MULTILINESTRING, POLYGON, MULTIPOLYGON,\n * and GEOMETRYCOLLECTION.\n *\n * @param {String} wkt A WKT string.\n * @return {Geometry} A geometry instance.\n * @private\n */\nWKTParser.prototype.read = function read (wkt) {\n var geometry, type, str;\n wkt = wkt.replace(/[\\n\\r]/g, ' ');\n var matches = regExes.typeStr.exec(wkt);\n if (wkt.search('EMPTY') !== -1) {\n matches = regExes.emptyTypeStr.exec(wkt);\n matches[2] = undefined;\n }\n if (matches) {\n type = matches[1].toLowerCase();\n str = matches[2];\n if (parse$1[type]) {\n geometry = parse$1[type].apply(this, [str]);\n }\n }\n\n if (geometry === undefined) { throw new Error('Could not parse WKT ' + wkt) }\n\n return geometry\n};\n\n/**\n * Serialize a geometry into a WKT string.\n *\n * @param {Geometry} geometry A feature or array of features.\n * @return {String} The WKT string representation of the input geometries.\n * @private\n */\nWKTParser.prototype.write = function write (geometry) {\n return this.extractGeometry(geometry)\n};\n\n/**\n * Entry point to construct the WKT for a single Geometry object.\n *\n * @param {Geometry} geometry\n * @return {String} A WKT string of representing the geometry.\n * @private\n */\nWKTParser.prototype.extractGeometry = function extractGeometry (geometry) {\n var type = geometry.getGeometryType().toLowerCase();\n if (!extract$1[type]) {\n return null\n }\n var wktType = type.toUpperCase();\n var data;\n if (geometry.isEmpty()) {\n data = wktType + ' EMPTY';\n } else {\n data = wktType + '(' + extract$1[type].apply(this, [geometry]) + ')';\n }\n return data\n};\n\n/**\n * Object with properties corresponding to the geometry types. Property values\n * are functions that do the actual data extraction.\n * @private\n */\nvar extract$1 = {\n coordinate: function coordinate (coordinate$1) {\n return coordinate$1.x + ' ' + coordinate$1.y\n },\n\n /**\n * Return a space delimited string of point coordinates.\n *\n * @param {Point}\n * point\n * @return {String} A string of coordinates representing the point.\n */\n point: function point (point$1) {\n return extract$1.coordinate.call(this, point$1._coordinates._coordinates[0])\n },\n\n /**\n * Return a comma delimited string of point coordinates from a multipoint.\n *\n * @param {MultiPoint}\n * multipoint\n * @return {String} A string of point coordinate strings representing the\n * multipoint.\n */\n multipoint: function multipoint (multipoint$1) {\n var this$1 = this;\n\n var array = [];\n for (var i = 0, len = multipoint$1._geometries.length; i < len; ++i) {\n array.push('(' + extract$1.point.apply(this$1, [multipoint$1._geometries[i]]) + ')');\n }\n return array.join(',')\n },\n\n /**\n * Return a comma delimited string of point coordinates from a line.\n *\n * @param {LineString} linestring\n * @return {String} A string of point coordinate strings representing the linestring.\n */\n linestring: function linestring (linestring$1) {\n var this$1 = this;\n\n var array = [];\n for (var i = 0, len = linestring$1._points._coordinates.length; i < len; ++i) {\n array.push(extract$1.coordinate.apply(this$1, [linestring$1._points._coordinates[i]]));\n }\n return array.join(',')\n },\n\n linearring: function linearring (linearring$1) {\n var this$1 = this;\n\n var array = [];\n for (var i = 0, len = linearring$1._points._coordinates.length; i < len; ++i) {\n array.push(extract$1.coordinate.apply(this$1, [linearring$1._points._coordinates[i]]));\n }\n return array.join(',')\n },\n\n /**\n * Return a comma delimited string of linestring strings from a\n * multilinestring.\n *\n * @param {MultiLineString} multilinestring\n * @return {String} A string of of linestring strings representing the multilinestring.\n */\n multilinestring: function multilinestring (multilinestring$1) {\n var this$1 = this;\n\n var array = [];\n for (var i = 0, len = multilinestring$1._geometries.length; i < len; ++i) {\n array.push('(' +\n extract$1.linestring.apply(this$1, [multilinestring$1._geometries[i]]) +\n ')');\n }\n return array.join(',')\n },\n\n /**\n * Return a comma delimited string of linear ring arrays from a polygon.\n *\n * @param {Polygon} polygon\n * @return {String} An array of linear ring arrays representing the polygon.\n */\n polygon: function polygon (polygon$1) {\n var this$1 = this;\n\n var array = [];\n array.push('(' + extract$1.linestring.apply(this, [polygon$1._shell]) + ')');\n for (var i = 0, len = polygon$1._holes.length; i < len; ++i) {\n array.push('(' + extract$1.linestring.apply(this$1, [polygon$1._holes[i]]) + ')');\n }\n return array.join(',')\n },\n\n /**\n * Return an array of polygon arrays from a multipolygon.\n *\n * @param {MultiPolygon} multipolygon\n * @return {String} An array of polygon arrays representing the multipolygon.\n */\n multipolygon: function multipolygon (multipolygon$1) {\n var this$1 = this;\n\n var array = [];\n for (var i = 0, len = multipolygon$1._geometries.length; i < len; ++i) {\n array.push('(' + extract$1.polygon.apply(this$1, [multipolygon$1._geometries[i]]) + ')');\n }\n return array.join(',')\n },\n\n /**\n * Return the WKT portion between 'GEOMETRYCOLLECTION(' and ')' for an\n * geometrycollection.\n *\n * @param {GeometryCollection} collection\n * @return {String} internal WKT representation of the collection.\n */\n geometrycollection: function geometrycollection (collection) {\n var this$1 = this;\n\n var array = [];\n for (var i = 0, len = collection._geometries.length; i < len; ++i) {\n array.push(this$1.extractGeometry(collection._geometries[i]));\n }\n return array.join(',')\n }\n};\n\n/**\n * Object with properties corresponding to the geometry types. Property values\n * are functions that do the actual parsing.\n * @private\n */\nvar parse$1 = {\n /**\n * Return point geometry given a point WKT fragment.\n *\n * @param {String} str A WKT fragment representing the point.\n * @return {Point} A point geometry.\n * @private\n */\n point: function point (str) {\n if (str === undefined) {\n return this.geometryFactory.createPoint()\n }\n\n var coords = str.trim().split(regExes.spaces);\n return this.geometryFactory.createPoint(new Coordinate(Number.parseFloat(coords[0]),\n Number.parseFloat(coords[1])))\n },\n\n /**\n * Return a multipoint geometry given a multipoint WKT fragment.\n *\n * @param {String} str A WKT fragment representing the multipoint.\n * @return {Point} A multipoint feature.\n * @private\n */\n multipoint: function multipoint (str) {\n var this$1 = this;\n\n if (str === undefined) {\n return this.geometryFactory.createMultiPoint()\n }\n\n var point;\n var points = str.trim().split(',');\n var components = [];\n for (var i = 0, len = points.length; i < len; ++i) {\n point = points[i].replace(regExes.trimParens, '$1');\n components.push(parse$1.point.apply(this$1, [point]));\n }\n return this.geometryFactory.createMultiPoint(components)\n },\n\n /**\n * Return a linestring geometry given a linestring WKT fragment.\n *\n * @param {String} str A WKT fragment representing the linestring.\n * @return {LineString} A linestring geometry.\n * @private\n */\n linestring: function linestring (str) {\n if (str === undefined) {\n return this.geometryFactory.createLineString()\n }\n\n var points = str.trim().split(',');\n var components = [];\n var coords;\n for (var i = 0, len = points.length; i < len; ++i) {\n coords = points[i].trim().split(regExes.spaces);\n components.push(new Coordinate(Number.parseFloat(coords[0]), Number.parseFloat(coords[1])));\n }\n return this.geometryFactory.createLineString(components)\n },\n\n /**\n * Return a linearring geometry given a linearring WKT fragment.\n *\n * @param {String} str A WKT fragment representing the linearring.\n * @return {LinearRing} A linearring geometry.\n * @private\n */\n linearring: function linearring (str) {\n if (str === undefined) {\n return this.geometryFactory.createLinearRing()\n }\n\n var points = str.trim().split(',');\n var components = [];\n var coords;\n for (var i = 0, len = points.length; i < len; ++i) {\n coords = points[i].trim().split(regExes.spaces);\n components.push(new Coordinate(Number.parseFloat(coords[0]), Number.parseFloat(coords[1])));\n }\n return this.geometryFactory.createLinearRing(components)\n },\n\n /**\n * Return a multilinestring geometry given a multilinestring WKT fragment.\n *\n * @param {String} str A WKT fragment representing the multilinestring.\n * @return {MultiLineString} A multilinestring geometry.\n * @private\n */\n multilinestring: function multilinestring (str) {\n var this$1 = this;\n\n if (str === undefined) {\n return this.geometryFactory.createMultiLineString()\n }\n\n var line;\n var lines = str.trim().split(regExes.parenComma);\n var components = [];\n for (var i = 0, len = lines.length; i < len; ++i) {\n line = lines[i].replace(regExes.trimParens, '$1');\n components.push(parse$1.linestring.apply(this$1, [line]));\n }\n return this.geometryFactory.createMultiLineString(components)\n },\n\n /**\n * Return a polygon geometry given a polygon WKT fragment.\n *\n * @param {String} str A WKT fragment representing the polygon.\n * @return {Polygon} A polygon geometry.\n * @private\n */\n polygon: function polygon (str) {\n var this$1 = this;\n\n if (str === undefined) {\n return this.geometryFactory.createPolygon()\n }\n\n var ring, linestring, linearring;\n var rings = str.trim().split(regExes.parenComma);\n var shell;\n var holes = [];\n for (var i = 0, len = rings.length; i < len; ++i) {\n ring = rings[i].replace(regExes.trimParens, '$1');\n linestring = parse$1.linestring.apply(this$1, [ring]);\n linearring = this$1.geometryFactory.createLinearRing(linestring._points);\n if (i === 0) {\n shell = linearring;\n } else {\n holes.push(linearring);\n }\n }\n return this.geometryFactory.createPolygon(shell, holes)\n },\n\n /**\n * Return a multipolygon geometry given a multipolygon WKT fragment.\n *\n * @param {String} str A WKT fragment representing the multipolygon.\n * @return {MultiPolygon} A multipolygon geometry.\n * @private\n */\n multipolygon: function multipolygon (str) {\n var this$1 = this;\n\n if (str === undefined) {\n return this.geometryFactory.createMultiPolygon()\n }\n\n var polygon;\n var polygons = str.trim().split(regExes.doubleParenComma);\n var components = [];\n for (var i = 0, len = polygons.length; i < len; ++i) {\n polygon = polygons[i].replace(regExes.trimParens, '$1');\n components.push(parse$1.polygon.apply(this$1, [polygon]));\n }\n return this.geometryFactory.createMultiPolygon(components)\n },\n\n /**\n * Return a geometrycollection given a geometrycollection WKT fragment.\n *\n * @param {String} str A WKT fragment representing the geometrycollection.\n * @return {GeometryCollection}\n * @private\n */\n geometrycollection: function geometrycollection (str) {\n var this$1 = this;\n\n if (str === undefined) {\n return this.geometryFactory.createGeometryCollection()\n }\n\n // separate components of the collection with |\n str = str.replace(/,\\s*([A-Za-z])/g, '|$1');\n var wktArray = str.trim().split('|');\n var components = [];\n for (var i = 0, len = wktArray.length; i < len; ++i) {\n components.push(this$1.read(wktArray[i]));\n }\n return this.geometryFactory.createGeometryCollection(components)\n }\n};\n\n/**\n * Writes the Well-Known Text representation of a {@link Geometry}. The\n * Well-Known Text format is defined in the OGC Simple Features\n * Specification for SQL .\n * \n * The WKTWriter
outputs coordinates rounded to the precision\n * model. Only the maximum number of decimal places necessary to represent the\n * ordinates to the required precision will be output.\n *
\n * The SFS WKT spec does not define a special tag for {@link LinearRing}s.\n * Under the spec, rings are output as LINESTRING
s.\n */\n\n/**\n * @param {GeometryFactory} geometryFactory\n * @constructor\n */\nvar WKTWriter = function WKTWriter (geometryFactory) {\n this.parser = new WKTParser(geometryFactory);\n};\n\n/**\n * Converts a Geometry
to its Well-known Text representation.\n *\n * @param {Geometry} geometry a Geometry
to process.\n * @return {string} a string (see the OpenGIS Simple\n * Features Specification).\n * @memberof WKTWriter\n */\nWKTWriter.prototype.write = function write (geometry) {\n return this.parser.write(geometry)\n};\n/**\n * Generates the WKT for a LINESTRING specified by two\n * {@link Coordinate}s.\n *\n * @param p0 the first coordinate.\n * @param p1 the second coordinate.\n *\n * @return the WKT.\n * @private\n */\nWKTWriter.toLineString = function toLineString (p0, p1) {\n if (arguments.length !== 2) {\n throw new Error('Not implemented')\n }\n return 'LINESTRING ( ' + p0.x + ' ' + p0.y + ', ' + p1.x + ' ' + p1.y + ' )'\n};\n\nvar RuntimeException = (function (Error) {\n function RuntimeException (message) {\n Error.call(this, message);\n this.name = 'RuntimeException';\n this.message = message;\n this.stack = (new Error()).stack;\n }\n\n if ( Error ) RuntimeException.__proto__ = Error;\n RuntimeException.prototype = Object.create( Error && Error.prototype );\n RuntimeException.prototype.constructor = RuntimeException;\n\n return RuntimeException;\n}(Error));\n\nvar AssertionFailedException = (function (RuntimeException$$1) {\n function AssertionFailedException () {\n RuntimeException$$1.call(this);\n if (arguments.length === 0) {\n RuntimeException$$1.call(this);\n } else if (arguments.length === 1) {\n var message = arguments[0];\n RuntimeException$$1.call(this, message);\n }\n }\n\n if ( RuntimeException$$1 ) AssertionFailedException.__proto__ = RuntimeException$$1;\n AssertionFailedException.prototype = Object.create( RuntimeException$$1 && RuntimeException$$1.prototype );\n AssertionFailedException.prototype.constructor = AssertionFailedException;\n AssertionFailedException.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n AssertionFailedException.prototype.getClass = function getClass () {\n return AssertionFailedException\n };\n\n return AssertionFailedException;\n}(RuntimeException));\n\nvar Assert = function Assert () {};\n\nAssert.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nAssert.prototype.getClass = function getClass () {\n return Assert\n};\nAssert.shouldNeverReachHere = function shouldNeverReachHere () {\n if (arguments.length === 0) {\n Assert.shouldNeverReachHere(null);\n } else if (arguments.length === 1) {\n var message = arguments[0];\n throw new AssertionFailedException('Should never reach here' + (message !== null ? ': ' + message : ''))\n }\n};\nAssert.isTrue = function isTrue () {\n var assertion;\n var message;\n if (arguments.length === 1) {\n assertion = arguments[0];\n Assert.isTrue(assertion, null);\n } else if (arguments.length === 2) {\n assertion = arguments[0];\n message = arguments[1];\n if (!assertion) {\n if (message === null) {\n throw new AssertionFailedException()\n } else {\n throw new AssertionFailedException(message)\n }\n }\n }\n};\nAssert.equals = function equals () {\n var expectedValue;\n var actualValue;\n var message;\n if (arguments.length === 2) {\n expectedValue = arguments[0];\n actualValue = arguments[1];\n Assert.equals(expectedValue, actualValue, null);\n } else if (arguments.length === 3) {\n expectedValue = arguments[0];\n actualValue = arguments[1];\n message = arguments[2];\n if (!actualValue.equals(expectedValue)) {\n throw new AssertionFailedException('Expected ' + expectedValue + ' but encountered ' + actualValue + (message !== null ? ': ' + message : ''))\n }\n }\n};\n\nvar LineIntersector = function LineIntersector () {\n this._result = null;\n this._inputLines = Array(2).fill().map(function () { return Array(2); });\n this._intPt = new Array(2).fill(null);\n this._intLineIndex = null;\n this._isProper = null;\n this._pa = null;\n this._pb = null;\n this._precisionModel = null;\n this._intPt[0] = new Coordinate();\n this._intPt[1] = new Coordinate();\n this._pa = this._intPt[0];\n this._pb = this._intPt[1];\n this._result = 0;\n};\n\nvar staticAccessors$10 = { DONT_INTERSECT: { configurable: true },DO_INTERSECT: { configurable: true },COLLINEAR: { configurable: true },NO_INTERSECTION: { configurable: true },POINT_INTERSECTION: { configurable: true },COLLINEAR_INTERSECTION: { configurable: true } };\nLineIntersector.prototype.getIndexAlongSegment = function getIndexAlongSegment (segmentIndex, intIndex) {\n this.computeIntLineIndex();\n return this._intLineIndex[segmentIndex][intIndex]\n};\nLineIntersector.prototype.getTopologySummary = function getTopologySummary () {\n var catBuf = new StringBuffer();\n if (this.isEndPoint()) { catBuf.append(' endpoint'); }\n if (this._isProper) { catBuf.append(' proper'); }\n if (this.isCollinear()) { catBuf.append(' collinear'); }\n return catBuf.toString()\n};\nLineIntersector.prototype.computeIntersection = function computeIntersection (p1, p2, p3, p4) {\n this._inputLines[0][0] = p1;\n this._inputLines[0][1] = p2;\n this._inputLines[1][0] = p3;\n this._inputLines[1][1] = p4;\n this._result = this.computeIntersect(p1, p2, p3, p4);\n};\nLineIntersector.prototype.getIntersectionNum = function getIntersectionNum () {\n return this._result\n};\nLineIntersector.prototype.computeIntLineIndex = function computeIntLineIndex () {\n if (arguments.length === 0) {\n if (this._intLineIndex === null) {\n this._intLineIndex = Array(2).fill().map(function () { return Array(2); });\n this.computeIntLineIndex(0);\n this.computeIntLineIndex(1);\n }\n } else if (arguments.length === 1) {\n var segmentIndex = arguments[0];\n var dist0 = this.getEdgeDistance(segmentIndex, 0);\n var dist1 = this.getEdgeDistance(segmentIndex, 1);\n if (dist0 > dist1) {\n this._intLineIndex[segmentIndex][0] = 0;\n this._intLineIndex[segmentIndex][1] = 1;\n } else {\n this._intLineIndex[segmentIndex][0] = 1;\n this._intLineIndex[segmentIndex][1] = 0;\n }\n }\n};\nLineIntersector.prototype.isProper = function isProper () {\n return this.hasIntersection() && this._isProper\n};\nLineIntersector.prototype.setPrecisionModel = function setPrecisionModel (precisionModel) {\n this._precisionModel = precisionModel;\n};\nLineIntersector.prototype.isInteriorIntersection = function isInteriorIntersection () {\n var this$1 = this;\n\n if (arguments.length === 0) {\n if (this.isInteriorIntersection(0)) { return true }\n if (this.isInteriorIntersection(1)) { return true }\n return false\n } else if (arguments.length === 1) {\n var inputLineIndex = arguments[0];\n for (var i = 0; i < this._result; i++) {\n if (!(this$1._intPt[i].equals2D(this$1._inputLines[inputLineIndex][0]) || this$1._intPt[i].equals2D(this$1._inputLines[inputLineIndex][1]))) {\n return true\n }\n }\n return false\n }\n};\nLineIntersector.prototype.getIntersection = function getIntersection (intIndex) {\n return this._intPt[intIndex]\n};\nLineIntersector.prototype.isEndPoint = function isEndPoint () {\n return this.hasIntersection() && !this._isProper\n};\nLineIntersector.prototype.hasIntersection = function hasIntersection () {\n return this._result !== LineIntersector.NO_INTERSECTION\n};\nLineIntersector.prototype.getEdgeDistance = function getEdgeDistance (segmentIndex, intIndex) {\n var dist = LineIntersector.computeEdgeDistance(this._intPt[intIndex], this._inputLines[segmentIndex][0], this._inputLines[segmentIndex][1]);\n return dist\n};\nLineIntersector.prototype.isCollinear = function isCollinear () {\n return this._result === LineIntersector.COLLINEAR_INTERSECTION\n};\nLineIntersector.prototype.toString = function toString () {\n return WKTWriter.toLineString(this._inputLines[0][0], this._inputLines[0][1]) + ' - ' + WKTWriter.toLineString(this._inputLines[1][0], this._inputLines[1][1]) + this.getTopologySummary()\n};\nLineIntersector.prototype.getEndpoint = function getEndpoint (segmentIndex, ptIndex) {\n return this._inputLines[segmentIndex][ptIndex]\n};\nLineIntersector.prototype.isIntersection = function isIntersection (pt) {\n var this$1 = this;\n\n for (var i = 0; i < this._result; i++) {\n if (this$1._intPt[i].equals2D(pt)) {\n return true\n }\n }\n return false\n};\nLineIntersector.prototype.getIntersectionAlongSegment = function getIntersectionAlongSegment (segmentIndex, intIndex) {\n this.computeIntLineIndex();\n return this._intPt[this._intLineIndex[segmentIndex][intIndex]]\n};\nLineIntersector.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nLineIntersector.prototype.getClass = function getClass () {\n return LineIntersector\n};\nLineIntersector.computeEdgeDistance = function computeEdgeDistance (p, p0, p1) {\n var dx = Math.abs(p1.x - p0.x);\n var dy = Math.abs(p1.y - p0.y);\n var dist = -1.0;\n if (p.equals(p0)) {\n dist = 0.0;\n } else if (p.equals(p1)) {\n if (dx > dy) { dist = dx; } else { dist = dy; }\n } else {\n var pdx = Math.abs(p.x - p0.x);\n var pdy = Math.abs(p.y - p0.y);\n if (dx > dy) { dist = pdx; } else { dist = pdy; }\n if (dist === 0.0 && !p.equals(p0)) {\n dist = Math.max(pdx, pdy);\n }\n }\n Assert.isTrue(!(dist === 0.0 && !p.equals(p0)), 'Bad distance calculation');\n return dist\n};\nLineIntersector.nonRobustComputeEdgeDistance = function nonRobustComputeEdgeDistance (p, p1, p2) {\n var dx = p.x - p1.x;\n var dy = p.y - p1.y;\n var dist = Math.sqrt(dx * dx + dy * dy);\n Assert.isTrue(!(dist === 0.0 && !p.equals(p1)), 'Invalid distance calculation');\n return dist\n};\nstaticAccessors$10.DONT_INTERSECT.get = function () { return 0 };\nstaticAccessors$10.DO_INTERSECT.get = function () { return 1 };\nstaticAccessors$10.COLLINEAR.get = function () { return 2 };\nstaticAccessors$10.NO_INTERSECTION.get = function () { return 0 };\nstaticAccessors$10.POINT_INTERSECTION.get = function () { return 1 };\nstaticAccessors$10.COLLINEAR_INTERSECTION.get = function () { return 2 };\n\nObject.defineProperties( LineIntersector, staticAccessors$10 );\n\nvar RobustLineIntersector = (function (LineIntersector$$1) {\n function RobustLineIntersector () {\n LineIntersector$$1.apply(this, arguments);\n }\n\n if ( LineIntersector$$1 ) RobustLineIntersector.__proto__ = LineIntersector$$1;\n RobustLineIntersector.prototype = Object.create( LineIntersector$$1 && LineIntersector$$1.prototype );\n RobustLineIntersector.prototype.constructor = RobustLineIntersector;\n\n RobustLineIntersector.prototype.isInSegmentEnvelopes = function isInSegmentEnvelopes (intPt) {\n var env0 = new Envelope(this._inputLines[0][0], this._inputLines[0][1]);\n var env1 = new Envelope(this._inputLines[1][0], this._inputLines[1][1]);\n return env0.contains(intPt) && env1.contains(intPt)\n };\n RobustLineIntersector.prototype.computeIntersection = function computeIntersection () {\n if (arguments.length === 3) {\n var p = arguments[0];\n var p1 = arguments[1];\n var p2 = arguments[2];\n this._isProper = false;\n if (Envelope.intersects(p1, p2, p)) {\n if (CGAlgorithms.orientationIndex(p1, p2, p) === 0 && CGAlgorithms.orientationIndex(p2, p1, p) === 0) {\n this._isProper = true;\n if (p.equals(p1) || p.equals(p2)) {\n this._isProper = false;\n }\n this._result = LineIntersector$$1.POINT_INTERSECTION;\n return null\n }\n }\n this._result = LineIntersector$$1.NO_INTERSECTION;\n } else { return LineIntersector$$1.prototype.computeIntersection.apply(this, arguments) }\n };\n RobustLineIntersector.prototype.normalizeToMinimum = function normalizeToMinimum (n1, n2, n3, n4, normPt) {\n normPt.x = this.smallestInAbsValue(n1.x, n2.x, n3.x, n4.x);\n normPt.y = this.smallestInAbsValue(n1.y, n2.y, n3.y, n4.y);\n n1.x -= normPt.x;\n n1.y -= normPt.y;\n n2.x -= normPt.x;\n n2.y -= normPt.y;\n n3.x -= normPt.x;\n n3.y -= normPt.y;\n n4.x -= normPt.x;\n n4.y -= normPt.y;\n };\n RobustLineIntersector.prototype.safeHCoordinateIntersection = function safeHCoordinateIntersection (p1, p2, q1, q2) {\n var intPt = null;\n try {\n intPt = HCoordinate.intersection(p1, p2, q1, q2);\n } catch (e) {\n if (e instanceof NotRepresentableException) {\n intPt = RobustLineIntersector.nearestEndpoint(p1, p2, q1, q2);\n } else { throw e }\n } finally {}\n return intPt\n };\n RobustLineIntersector.prototype.intersection = function intersection (p1, p2, q1, q2) {\n var intPt = this.intersectionWithNormalization(p1, p2, q1, q2);\n if (!this.isInSegmentEnvelopes(intPt)) {\n intPt = new Coordinate(RobustLineIntersector.nearestEndpoint(p1, p2, q1, q2));\n }\n if (this._precisionModel !== null) {\n this._precisionModel.makePrecise(intPt);\n }\n return intPt\n };\n RobustLineIntersector.prototype.smallestInAbsValue = function smallestInAbsValue (x1, x2, x3, x4) {\n var x = x1;\n var xabs = Math.abs(x);\n if (Math.abs(x2) < xabs) {\n x = x2;\n xabs = Math.abs(x2);\n }\n if (Math.abs(x3) < xabs) {\n x = x3;\n xabs = Math.abs(x3);\n }\n if (Math.abs(x4) < xabs) {\n x = x4;\n }\n return x\n };\n RobustLineIntersector.prototype.checkDD = function checkDD (p1, p2, q1, q2, intPt) {\n var intPtDD = CGAlgorithmsDD.intersection(p1, p2, q1, q2);\n var isIn = this.isInSegmentEnvelopes(intPtDD);\n System.out.println('DD in env = ' + isIn + ' --------------------- ' + intPtDD);\n if (intPt.distance(intPtDD) > 0.0001) {\n System.out.println('Distance = ' + intPt.distance(intPtDD));\n }\n };\n RobustLineIntersector.prototype.intersectionWithNormalization = function intersectionWithNormalization (p1, p2, q1, q2) {\n var n1 = new Coordinate(p1);\n var n2 = new Coordinate(p2);\n var n3 = new Coordinate(q1);\n var n4 = new Coordinate(q2);\n var normPt = new Coordinate();\n this.normalizeToEnvCentre(n1, n2, n3, n4, normPt);\n var intPt = this.safeHCoordinateIntersection(n1, n2, n3, n4);\n intPt.x += normPt.x;\n intPt.y += normPt.y;\n return intPt\n };\n RobustLineIntersector.prototype.computeCollinearIntersection = function computeCollinearIntersection (p1, p2, q1, q2) {\n var p1q1p2 = Envelope.intersects(p1, p2, q1);\n var p1q2p2 = Envelope.intersects(p1, p2, q2);\n var q1p1q2 = Envelope.intersects(q1, q2, p1);\n var q1p2q2 = Envelope.intersects(q1, q2, p2);\n if (p1q1p2 && p1q2p2) {\n this._intPt[0] = q1;\n this._intPt[1] = q2;\n return LineIntersector$$1.COLLINEAR_INTERSECTION\n }\n if (q1p1q2 && q1p2q2) {\n this._intPt[0] = p1;\n this._intPt[1] = p2;\n return LineIntersector$$1.COLLINEAR_INTERSECTION\n }\n if (p1q1p2 && q1p1q2) {\n this._intPt[0] = q1;\n this._intPt[1] = p1;\n return q1.equals(p1) && !p1q2p2 && !q1p2q2 ? LineIntersector$$1.POINT_INTERSECTION : LineIntersector$$1.COLLINEAR_INTERSECTION\n }\n if (p1q1p2 && q1p2q2) {\n this._intPt[0] = q1;\n this._intPt[1] = p2;\n return q1.equals(p2) && !p1q2p2 && !q1p1q2 ? LineIntersector$$1.POINT_INTERSECTION : LineIntersector$$1.COLLINEAR_INTERSECTION\n }\n if (p1q2p2 && q1p1q2) {\n this._intPt[0] = q2;\n this._intPt[1] = p1;\n return q2.equals(p1) && !p1q1p2 && !q1p2q2 ? LineIntersector$$1.POINT_INTERSECTION : LineIntersector$$1.COLLINEAR_INTERSECTION\n }\n if (p1q2p2 && q1p2q2) {\n this._intPt[0] = q2;\n this._intPt[1] = p2;\n return q2.equals(p2) && !p1q1p2 && !q1p1q2 ? LineIntersector$$1.POINT_INTERSECTION : LineIntersector$$1.COLLINEAR_INTERSECTION\n }\n return LineIntersector$$1.NO_INTERSECTION\n };\n RobustLineIntersector.prototype.normalizeToEnvCentre = function normalizeToEnvCentre (n00, n01, n10, n11, normPt) {\n var minX0 = n00.x < n01.x ? n00.x : n01.x;\n var minY0 = n00.y < n01.y ? n00.y : n01.y;\n var maxX0 = n00.x > n01.x ? n00.x : n01.x;\n var maxY0 = n00.y > n01.y ? n00.y : n01.y;\n var minX1 = n10.x < n11.x ? n10.x : n11.x;\n var minY1 = n10.y < n11.y ? n10.y : n11.y;\n var maxX1 = n10.x > n11.x ? n10.x : n11.x;\n var maxY1 = n10.y > n11.y ? n10.y : n11.y;\n var intMinX = minX0 > minX1 ? minX0 : minX1;\n var intMaxX = maxX0 < maxX1 ? maxX0 : maxX1;\n var intMinY = minY0 > minY1 ? minY0 : minY1;\n var intMaxY = maxY0 < maxY1 ? maxY0 : maxY1;\n var intMidX = (intMinX + intMaxX) / 2.0;\n var intMidY = (intMinY + intMaxY) / 2.0;\n normPt.x = intMidX;\n normPt.y = intMidY;\n n00.x -= normPt.x;\n n00.y -= normPt.y;\n n01.x -= normPt.x;\n n01.y -= normPt.y;\n n10.x -= normPt.x;\n n10.y -= normPt.y;\n n11.x -= normPt.x;\n n11.y -= normPt.y;\n };\n RobustLineIntersector.prototype.computeIntersect = function computeIntersect (p1, p2, q1, q2) {\n this._isProper = false;\n if (!Envelope.intersects(p1, p2, q1, q2)) { return LineIntersector$$1.NO_INTERSECTION }\n var Pq1 = CGAlgorithms.orientationIndex(p1, p2, q1);\n var Pq2 = CGAlgorithms.orientationIndex(p1, p2, q2);\n if ((Pq1 > 0 && Pq2 > 0) || (Pq1 < 0 && Pq2 < 0)) {\n return LineIntersector$$1.NO_INTERSECTION\n }\n var Qp1 = CGAlgorithms.orientationIndex(q1, q2, p1);\n var Qp2 = CGAlgorithms.orientationIndex(q1, q2, p2);\n if ((Qp1 > 0 && Qp2 > 0) || (Qp1 < 0 && Qp2 < 0)) {\n return LineIntersector$$1.NO_INTERSECTION\n }\n var collinear = Pq1 === 0 && Pq2 === 0 && Qp1 === 0 && Qp2 === 0;\n if (collinear) {\n return this.computeCollinearIntersection(p1, p2, q1, q2)\n }\n if (Pq1 === 0 || Pq2 === 0 || Qp1 === 0 || Qp2 === 0) {\n this._isProper = false;\n if (p1.equals2D(q1) || p1.equals2D(q2)) {\n this._intPt[0] = p1;\n } else if (p2.equals2D(q1) || p2.equals2D(q2)) {\n this._intPt[0] = p2;\n } else if (Pq1 === 0) {\n this._intPt[0] = new Coordinate(q1);\n } else if (Pq2 === 0) {\n this._intPt[0] = new Coordinate(q2);\n } else if (Qp1 === 0) {\n this._intPt[0] = new Coordinate(p1);\n } else if (Qp2 === 0) {\n this._intPt[0] = new Coordinate(p2);\n }\n } else {\n this._isProper = true;\n this._intPt[0] = this.intersection(p1, p2, q1, q2);\n }\n return LineIntersector$$1.POINT_INTERSECTION\n };\n RobustLineIntersector.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n RobustLineIntersector.prototype.getClass = function getClass () {\n return RobustLineIntersector\n };\n RobustLineIntersector.nearestEndpoint = function nearestEndpoint (p1, p2, q1, q2) {\n var nearestPt = p1;\n var minDist = CGAlgorithms.distancePointLine(p1, q1, q2);\n var dist = CGAlgorithms.distancePointLine(p2, q1, q2);\n if (dist < minDist) {\n minDist = dist;\n nearestPt = p2;\n }\n dist = CGAlgorithms.distancePointLine(q1, p1, p2);\n if (dist < minDist) {\n minDist = dist;\n nearestPt = q1;\n }\n dist = CGAlgorithms.distancePointLine(q2, p1, p2);\n if (dist < minDist) {\n minDist = dist;\n nearestPt = q2;\n }\n return nearestPt\n };\n\n return RobustLineIntersector;\n}(LineIntersector));\n\nvar RobustDeterminant = function RobustDeterminant () {};\n\nRobustDeterminant.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nRobustDeterminant.prototype.getClass = function getClass () {\n return RobustDeterminant\n};\nRobustDeterminant.orientationIndex = function orientationIndex (p1, p2, q) {\n var dx1 = p2.x - p1.x;\n var dy1 = p2.y - p1.y;\n var dx2 = q.x - p2.x;\n var dy2 = q.y - p2.y;\n return RobustDeterminant.signOfDet2x2(dx1, dy1, dx2, dy2)\n};\nRobustDeterminant.signOfDet2x2 = function signOfDet2x2 (x1, y1, x2, y2) {\n var sign = null;\n var swap = null;\n var k = null;\n sign = 1;\n if (x1 === 0.0 || y2 === 0.0) {\n if (y1 === 0.0 || x2 === 0.0) {\n return 0\n } else if (y1 > 0) {\n if (x2 > 0) {\n return -sign\n } else {\n return sign\n }\n } else {\n if (x2 > 0) {\n return sign\n } else {\n return -sign\n }\n }\n }\n if (y1 === 0.0 || x2 === 0.0) {\n if (y2 > 0) {\n if (x1 > 0) {\n return sign\n } else {\n return -sign\n }\n } else {\n if (x1 > 0) {\n return -sign\n } else {\n return sign\n }\n }\n }\n if (y1 > 0.0) {\n if (y2 > 0.0) {\n if (y1 <= y2) {\n \n } else {\n sign = -sign;\n swap = x1;\n x1 = x2;\n x2 = swap;\n swap = y1;\n y1 = y2;\n y2 = swap;\n }\n } else {\n if (y1 <= -y2) {\n sign = -sign;\n x2 = -x2;\n y2 = -y2;\n } else {\n swap = x1;\n x1 = -x2;\n x2 = swap;\n swap = y1;\n y1 = -y2;\n y2 = swap;\n }\n }\n } else {\n if (y2 > 0.0) {\n if (-y1 <= y2) {\n sign = -sign;\n x1 = -x1;\n y1 = -y1;\n } else {\n swap = -x1;\n x1 = x2;\n x2 = swap;\n swap = -y1;\n y1 = y2;\n y2 = swap;\n }\n } else {\n if (y1 >= y2) {\n x1 = -x1;\n y1 = -y1;\n x2 = -x2;\n y2 = -y2;\n } else {\n sign = -sign;\n swap = -x1;\n x1 = -x2;\n x2 = swap;\n swap = -y1;\n y1 = -y2;\n y2 = swap;\n }\n }\n }\n if (x1 > 0.0) {\n if (x2 > 0.0) {\n if (x1 <= x2) {\n \n } else {\n return sign\n }\n } else {\n return sign\n }\n } else {\n if (x2 > 0.0) {\n return -sign\n } else {\n if (x1 >= x2) {\n sign = -sign;\n x1 = -x1;\n x2 = -x2;\n } else {\n return -sign\n }\n }\n }\n while (true) {\n k = Math.floor(x2 / x1);\n x2 = x2 - k * x1;\n y2 = y2 - k * y1;\n if (y2 < 0.0) {\n return -sign\n }\n if (y2 > y1) {\n return sign\n }\n if (x1 > x2 + x2) {\n if (y1 < y2 + y2) {\n return sign\n }\n } else {\n if (y1 > y2 + y2) {\n return -sign\n } else {\n x2 = x1 - x2;\n y2 = y1 - y2;\n sign = -sign;\n }\n }\n if (y2 === 0.0) {\n if (x2 === 0.0) {\n return 0\n } else {\n return -sign\n }\n }\n if (x2 === 0.0) {\n return sign\n }\n k = Math.floor(x1 / x2);\n x1 = x1 - k * x2;\n y1 = y1 - k * y2;\n if (y1 < 0.0) {\n return sign\n }\n if (y1 > y2) {\n return -sign\n }\n if (x2 > x1 + x1) {\n if (y2 < y1 + y1) {\n return -sign\n }\n } else {\n if (y2 > y1 + y1) {\n return sign\n } else {\n x1 = x2 - x1;\n y1 = y2 - y1;\n sign = -sign;\n }\n }\n if (y1 === 0.0) {\n if (x1 === 0.0) {\n return 0\n } else {\n return sign\n }\n }\n if (x1 === 0.0) {\n return -sign\n }\n }\n};\n\nvar RayCrossingCounter = function RayCrossingCounter () {\n this._p = null;\n this._crossingCount = 0;\n this._isPointOnSegment = false;\n var p = arguments[0];\n this._p = p;\n};\nRayCrossingCounter.prototype.countSegment = function countSegment (p1, p2) {\n if (p1.x < this._p.x && p2.x < this._p.x) { return null }\n if (this._p.x === p2.x && this._p.y === p2.y) {\n this._isPointOnSegment = true;\n return null\n }\n if (p1.y === this._p.y && p2.y === this._p.y) {\n var minx = p1.x;\n var maxx = p2.x;\n if (minx > maxx) {\n minx = p2.x;\n maxx = p1.x;\n }\n if (this._p.x >= minx && this._p.x <= maxx) {\n this._isPointOnSegment = true;\n }\n return null\n }\n if ((p1.y > this._p.y && p2.y <= this._p.y) || (p2.y > this._p.y && p1.y <= this._p.y)) {\n var x1 = p1.x - this._p.x;\n var y1 = p1.y - this._p.y;\n var x2 = p2.x - this._p.x;\n var y2 = p2.y - this._p.y;\n var xIntSign = RobustDeterminant.signOfDet2x2(x1, y1, x2, y2);\n if (xIntSign === 0.0) {\n this._isPointOnSegment = true;\n return null\n }\n if (y2 < y1) { xIntSign = -xIntSign; }\n if (xIntSign > 0.0) {\n this._crossingCount++;\n }\n }\n};\nRayCrossingCounter.prototype.isPointInPolygon = function isPointInPolygon () {\n return this.getLocation() !== Location.EXTERIOR\n};\nRayCrossingCounter.prototype.getLocation = function getLocation () {\n if (this._isPointOnSegment) { return Location.BOUNDARY }\n if (this._crossingCount % 2 === 1) {\n return Location.INTERIOR\n }\n return Location.EXTERIOR\n};\nRayCrossingCounter.prototype.isOnSegment = function isOnSegment () {\n return this._isPointOnSegment\n};\nRayCrossingCounter.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nRayCrossingCounter.prototype.getClass = function getClass () {\n return RayCrossingCounter\n};\nRayCrossingCounter.locatePointInRing = function locatePointInRing () {\n if (arguments[0] instanceof Coordinate && hasInterface(arguments[1], CoordinateSequence)) {\n var p = arguments[0];\n var ring = arguments[1];\n var counter = new RayCrossingCounter(p);\n var p1 = new Coordinate();\n var p2 = new Coordinate();\n for (var i = 1; i < ring.size(); i++) {\n ring.getCoordinate(i, p1);\n ring.getCoordinate(i - 1, p2);\n counter.countSegment(p1, p2);\n if (counter.isOnSegment()) { return counter.getLocation() }\n }\n return counter.getLocation()\n } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Array) {\n var p$1 = arguments[0];\n var ring$1 = arguments[1];\n var counter$1 = new RayCrossingCounter(p$1);\n for (var i$1 = 1; i$1 < ring$1.length; i$1++) {\n var p1$1 = ring$1[i$1];\n var p2$1 = ring$1[i$1 - 1];\n counter$1.countSegment(p1$1, p2$1);\n if (counter$1.isOnSegment()) { return counter$1.getLocation() }\n }\n return counter$1.getLocation()\n }\n};\n\nvar CGAlgorithms = function CGAlgorithms () {};\n\nvar staticAccessors$3 = { CLOCKWISE: { configurable: true },RIGHT: { configurable: true },COUNTERCLOCKWISE: { configurable: true },LEFT: { configurable: true },COLLINEAR: { configurable: true },STRAIGHT: { configurable: true } };\n\nCGAlgorithms.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nCGAlgorithms.prototype.getClass = function getClass () {\n return CGAlgorithms\n};\nCGAlgorithms.orientationIndex = function orientationIndex (p1, p2, q) {\n return CGAlgorithmsDD.orientationIndex(p1, p2, q)\n};\nCGAlgorithms.signedArea = function signedArea () {\n if (arguments[0] instanceof Array) {\n var ring = arguments[0];\n if (ring.length < 3) { return 0.0 }\n var sum = 0.0;\n var x0 = ring[0].x;\n for (var i = 1; i < ring.length - 1; i++) {\n var x = ring[i].x - x0;\n var y1 = ring[i + 1].y;\n var y2 = ring[i - 1].y;\n sum += x * (y2 - y1);\n }\n return sum / 2.0\n } else if (hasInterface(arguments[0], CoordinateSequence)) {\n var ring$1 = arguments[0];\n var n = ring$1.size();\n if (n < 3) { return 0.0 }\n var p0 = new Coordinate();\n var p1 = new Coordinate();\n var p2 = new Coordinate();\n ring$1.getCoordinate(0, p1);\n ring$1.getCoordinate(1, p2);\n var x0$1 = p1.x;\n p2.x -= x0$1;\n var sum$1 = 0.0;\n for (var i$1 = 1; i$1 < n - 1; i$1++) {\n p0.y = p1.y;\n p1.x = p2.x;\n p1.y = p2.y;\n ring$1.getCoordinate(i$1 + 1, p2);\n p2.x -= x0$1;\n sum$1 += p1.x * (p0.y - p2.y);\n }\n return sum$1 / 2.0\n }\n};\nCGAlgorithms.distanceLineLine = function distanceLineLine (A, B, C, D) {\n if (A.equals(B)) { return CGAlgorithms.distancePointLine(A, C, D) }\n if (C.equals(D)) { return CGAlgorithms.distancePointLine(D, A, B) }\n var noIntersection = false;\n if (!Envelope.intersects(A, B, C, D)) {\n noIntersection = true;\n } else {\n var denom = (B.x - A.x) * (D.y - C.y) - (B.y - A.y) * (D.x - C.x);\n if (denom === 0) {\n noIntersection = true;\n } else {\n var rNumb = (A.y - C.y) * (D.x - C.x) - (A.x - C.x) * (D.y - C.y);\n var sNum = (A.y - C.y) * (B.x - A.x) - (A.x - C.x) * (B.y - A.y);\n var s = sNum / denom;\n var r = rNumb / denom;\n if (r < 0 || r > 1 || s < 0 || s > 1) {\n noIntersection = true;\n }\n }\n }\n if (noIntersection) {\n return MathUtil.min(CGAlgorithms.distancePointLine(A, C, D), CGAlgorithms.distancePointLine(B, C, D), CGAlgorithms.distancePointLine(C, A, B), CGAlgorithms.distancePointLine(D, A, B))\n }\n return 0.0\n};\nCGAlgorithms.isPointInRing = function isPointInRing (p, ring) {\n return CGAlgorithms.locatePointInRing(p, ring) !== Location.EXTERIOR\n};\nCGAlgorithms.computeLength = function computeLength (pts) {\n var n = pts.size();\n if (n <= 1) { return 0.0 }\n var len = 0.0;\n var p = new Coordinate();\n pts.getCoordinate(0, p);\n var x0 = p.x;\n var y0 = p.y;\n for (var i = 1; i < n; i++) {\n pts.getCoordinate(i, p);\n var x1 = p.x;\n var y1 = p.y;\n var dx = x1 - x0;\n var dy = y1 - y0;\n len += Math.sqrt(dx * dx + dy * dy);\n x0 = x1;\n y0 = y1;\n }\n return len\n};\nCGAlgorithms.isCCW = function isCCW (ring) {\n var nPts = ring.length - 1;\n if (nPts < 3) { throw new IllegalArgumentException('Ring has fewer than 4 points, so orientation cannot be determined') }\n var hiPt = ring[0];\n var hiIndex = 0;\n for (var i = 1; i <= nPts; i++) {\n var p = ring[i];\n if (p.y > hiPt.y) {\n hiPt = p;\n hiIndex = i;\n }\n }\n var iPrev = hiIndex;\n do {\n iPrev = iPrev - 1;\n if (iPrev < 0) { iPrev = nPts; }\n } while (ring[iPrev].equals2D(hiPt) && iPrev !== hiIndex)\n var iNext = hiIndex;\n do {\n iNext = (iNext + 1) % nPts;\n } while (ring[iNext].equals2D(hiPt) && iNext !== hiIndex)\n var prev = ring[iPrev];\n var next = ring[iNext];\n if (prev.equals2D(hiPt) || next.equals2D(hiPt) || prev.equals2D(next)) { return false }\n var disc = CGAlgorithms.computeOrientation(prev, hiPt, next);\n var isCCW = false;\n if (disc === 0) {\n isCCW = prev.x > next.x;\n } else {\n isCCW = disc > 0;\n }\n return isCCW\n};\nCGAlgorithms.locatePointInRing = function locatePointInRing (p, ring) {\n return RayCrossingCounter.locatePointInRing(p, ring)\n};\nCGAlgorithms.distancePointLinePerpendicular = function distancePointLinePerpendicular (p, A, B) {\n var len2 = (B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y);\n var s = ((A.y - p.y) * (B.x - A.x) - (A.x - p.x) * (B.y - A.y)) / len2;\n return Math.abs(s) * Math.sqrt(len2)\n};\nCGAlgorithms.computeOrientation = function computeOrientation (p1, p2, q) {\n return CGAlgorithms.orientationIndex(p1, p2, q)\n};\nCGAlgorithms.distancePointLine = function distancePointLine () {\n if (arguments.length === 2) {\n var p = arguments[0];\n var line = arguments[1];\n if (line.length === 0) { throw new IllegalArgumentException('Line array must contain at least one vertex') }\n var minDistance = p.distance(line[0]);\n for (var i = 0; i < line.length - 1; i++) {\n var dist = CGAlgorithms.distancePointLine(p, line[i], line[i + 1]);\n if (dist < minDistance) {\n minDistance = dist;\n }\n }\n return minDistance\n } else if (arguments.length === 3) {\n var p$1 = arguments[0];\n var A = arguments[1];\n var B = arguments[2];\n if (A.x === B.x && A.y === B.y) { return p$1.distance(A) }\n var len2 = (B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y);\n var r = ((p$1.x - A.x) * (B.x - A.x) + (p$1.y - A.y) * (B.y - A.y)) / len2;\n if (r <= 0.0) { return p$1.distance(A) }\n if (r >= 1.0) { return p$1.distance(B) }\n var s = ((A.y - p$1.y) * (B.x - A.x) - (A.x - p$1.x) * (B.y - A.y)) / len2;\n return Math.abs(s) * Math.sqrt(len2)\n }\n};\nCGAlgorithms.isOnLine = function isOnLine (p, pt) {\n var lineIntersector = new RobustLineIntersector();\n for (var i = 1; i < pt.length; i++) {\n var p0 = pt[i - 1];\n var p1 = pt[i];\n lineIntersector.computeIntersection(p, p0, p1);\n if (lineIntersector.hasIntersection()) {\n return true\n }\n }\n return false\n};\nstaticAccessors$3.CLOCKWISE.get = function () { return -1 };\nstaticAccessors$3.RIGHT.get = function () { return CGAlgorithms.CLOCKWISE };\nstaticAccessors$3.COUNTERCLOCKWISE.get = function () { return 1 };\nstaticAccessors$3.LEFT.get = function () { return CGAlgorithms.COUNTERCLOCKWISE };\nstaticAccessors$3.COLLINEAR.get = function () { return 0 };\nstaticAccessors$3.STRAIGHT.get = function () { return CGAlgorithms.COLLINEAR };\n\nObject.defineProperties( CGAlgorithms, staticAccessors$3 );\n\nvar GeometryComponentFilter = function GeometryComponentFilter () {};\n\nGeometryComponentFilter.prototype.filter = function filter (geom) {};\nGeometryComponentFilter.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nGeometryComponentFilter.prototype.getClass = function getClass () {\n return GeometryComponentFilter\n};\n\nvar Geometry = function Geometry () {\n var factory = arguments[0];\n\n this._envelope = null;\n this._factory = null;\n this._SRID = null;\n this._userData = null;\n this._factory = factory;\n this._SRID = factory.getSRID();\n};\n\nvar staticAccessors$11 = { serialVersionUID: { configurable: true },SORTINDEX_POINT: { configurable: true },SORTINDEX_MULTIPOINT: { configurable: true },SORTINDEX_LINESTRING: { configurable: true },SORTINDEX_LINEARRING: { configurable: true },SORTINDEX_MULTILINESTRING: { configurable: true },SORTINDEX_POLYGON: { configurable: true },SORTINDEX_MULTIPOLYGON: { configurable: true },SORTINDEX_GEOMETRYCOLLECTION: { configurable: true },geometryChangedFilter: { configurable: true } };\nGeometry.prototype.isGeometryCollection = function isGeometryCollection () {\n return this.getSortIndex() === Geometry.SORTINDEX_GEOMETRYCOLLECTION\n};\nGeometry.prototype.getFactory = function getFactory () {\n return this._factory\n};\nGeometry.prototype.getGeometryN = function getGeometryN (n) {\n return this\n};\nGeometry.prototype.getArea = function getArea () {\n return 0.0\n};\nGeometry.prototype.isRectangle = function isRectangle () {\n return false\n};\nGeometry.prototype.equals = function equals () {\n if (arguments[0] instanceof Geometry) {\n var g$1 = arguments[0];\n if (g$1 === null) { return false }\n return this.equalsTopo(g$1)\n } else if (arguments[0] instanceof Object) {\n var o = arguments[0];\n if (!(o instanceof Geometry)) { return false }\n var g = o;\n return this.equalsExact(g)\n }\n};\nGeometry.prototype.equalsExact = function equalsExact (other) {\n return this === other || this.equalsExact(other, 0)\n};\nGeometry.prototype.geometryChanged = function geometryChanged () {\n this.apply(Geometry.geometryChangedFilter);\n};\nGeometry.prototype.geometryChangedAction = function geometryChangedAction () {\n this._envelope = null;\n};\nGeometry.prototype.equalsNorm = function equalsNorm (g) {\n if (g === null) { return false }\n return this.norm().equalsExact(g.norm())\n};\nGeometry.prototype.getLength = function getLength () {\n return 0.0\n};\nGeometry.prototype.getNumGeometries = function getNumGeometries () {\n return 1\n};\nGeometry.prototype.compareTo = function compareTo () {\n if (arguments.length === 1) {\n var o = arguments[0];\n var other = o;\n if (this.getSortIndex() !== other.getSortIndex()) {\n return this.getSortIndex() - other.getSortIndex()\n }\n if (this.isEmpty() && other.isEmpty()) {\n return 0\n }\n if (this.isEmpty()) {\n return -1\n }\n if (other.isEmpty()) {\n return 1\n }\n return this.compareToSameClass(o)\n } else if (arguments.length === 2) {\n var other$1 = arguments[0];\n var comp = arguments[1];\n if (this.getSortIndex() !== other$1.getSortIndex()) {\n return this.getSortIndex() - other$1.getSortIndex()\n }\n if (this.isEmpty() && other$1.isEmpty()) {\n return 0\n }\n if (this.isEmpty()) {\n return -1\n }\n if (other$1.isEmpty()) {\n return 1\n }\n return this.compareToSameClass(other$1, comp)\n }\n};\nGeometry.prototype.getUserData = function getUserData () {\n return this._userData\n};\nGeometry.prototype.getSRID = function getSRID () {\n return this._SRID\n};\nGeometry.prototype.getEnvelope = function getEnvelope () {\n return this.getFactory().toGeometry(this.getEnvelopeInternal())\n};\nGeometry.prototype.checkNotGeometryCollection = function checkNotGeometryCollection (g) {\n if (g.getSortIndex() === Geometry.SORTINDEX_GEOMETRYCOLLECTION) {\n throw new IllegalArgumentException('This method does not support GeometryCollection arguments')\n }\n};\nGeometry.prototype.equal = function equal (a, b, tolerance) {\n if (tolerance === 0) {\n return a.equals(b)\n }\n return a.distance(b) <= tolerance\n};\nGeometry.prototype.norm = function norm () {\n var copy = this.copy();\n copy.normalize();\n return copy\n};\nGeometry.prototype.getPrecisionModel = function getPrecisionModel () {\n return this._factory.getPrecisionModel()\n};\nGeometry.prototype.getEnvelopeInternal = function getEnvelopeInternal () {\n if (this._envelope === null) {\n this._envelope = this.computeEnvelopeInternal();\n }\n return new Envelope(this._envelope)\n};\nGeometry.prototype.setSRID = function setSRID (SRID) {\n this._SRID = SRID;\n};\nGeometry.prototype.setUserData = function setUserData (userData) {\n this._userData = userData;\n};\nGeometry.prototype.compare = function compare (a, b) {\n var i = a.iterator();\n var j = b.iterator();\n while (i.hasNext() && j.hasNext()) {\n var aElement = i.next();\n var bElement = j.next();\n var comparison = aElement.compareTo(bElement);\n if (comparison !== 0) {\n return comparison\n }\n }\n if (i.hasNext()) {\n return 1\n }\n if (j.hasNext()) {\n return -1\n }\n return 0\n};\nGeometry.prototype.hashCode = function hashCode () {\n return this.getEnvelopeInternal().hashCode()\n};\nGeometry.prototype.isGeometryCollectionOrDerived = function isGeometryCollectionOrDerived () {\n if (this.getSortIndex() === Geometry.SORTINDEX_GEOMETRYCOLLECTION || this.getSortIndex() === Geometry.SORTINDEX_MULTIPOINT || this.getSortIndex() === Geometry.SORTINDEX_MULTILINESTRING || this.getSortIndex() === Geometry.SORTINDEX_MULTIPOLYGON) {\n return true\n }\n return false\n};\nGeometry.prototype.interfaces_ = function interfaces_ () {\n return [Clonable, Comparable, Serializable]\n};\nGeometry.prototype.getClass = function getClass () {\n return Geometry\n};\nGeometry.hasNonEmptyElements = function hasNonEmptyElements (geometries) {\n for (var i = 0; i < geometries.length; i++) {\n if (!geometries[i].isEmpty()) {\n return true\n }\n }\n return false\n};\nGeometry.hasNullElements = function hasNullElements (array) {\n for (var i = 0; i < array.length; i++) {\n if (array[i] === null) {\n return true\n }\n }\n return false\n};\nstaticAccessors$11.serialVersionUID.get = function () { return 8763622679187376702 };\nstaticAccessors$11.SORTINDEX_POINT.get = function () { return 0 };\nstaticAccessors$11.SORTINDEX_MULTIPOINT.get = function () { return 1 };\nstaticAccessors$11.SORTINDEX_LINESTRING.get = function () { return 2 };\nstaticAccessors$11.SORTINDEX_LINEARRING.get = function () { return 3 };\nstaticAccessors$11.SORTINDEX_MULTILINESTRING.get = function () { return 4 };\nstaticAccessors$11.SORTINDEX_POLYGON.get = function () { return 5 };\nstaticAccessors$11.SORTINDEX_MULTIPOLYGON.get = function () { return 6 };\nstaticAccessors$11.SORTINDEX_GEOMETRYCOLLECTION.get = function () { return 7 };\nstaticAccessors$11.geometryChangedFilter.get = function () { return geometryChangedFilter };\n\nObject.defineProperties( Geometry, staticAccessors$11 );\n\nvar geometryChangedFilter = function geometryChangedFilter () {};\n\ngeometryChangedFilter.interfaces_ = function interfaces_ () {\n return [GeometryComponentFilter]\n};\ngeometryChangedFilter.filter = function filter (geom) {\n geom.geometryChangedAction();\n};\n\nvar CoordinateFilter = function CoordinateFilter () {};\n\nCoordinateFilter.prototype.filter = function filter (coord) {};\nCoordinateFilter.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nCoordinateFilter.prototype.getClass = function getClass () {\n return CoordinateFilter\n};\n\nvar BoundaryNodeRule = function BoundaryNodeRule () {};\n\nvar staticAccessors$12 = { Mod2BoundaryNodeRule: { configurable: true },EndPointBoundaryNodeRule: { configurable: true },MultiValentEndPointBoundaryNodeRule: { configurable: true },MonoValentEndPointBoundaryNodeRule: { configurable: true },MOD2_BOUNDARY_RULE: { configurable: true },ENDPOINT_BOUNDARY_RULE: { configurable: true },MULTIVALENT_ENDPOINT_BOUNDARY_RULE: { configurable: true },MONOVALENT_ENDPOINT_BOUNDARY_RULE: { configurable: true },OGC_SFS_BOUNDARY_RULE: { configurable: true } };\n\nBoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {};\nBoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nBoundaryNodeRule.prototype.getClass = function getClass () {\n return BoundaryNodeRule\n};\nstaticAccessors$12.Mod2BoundaryNodeRule.get = function () { return Mod2BoundaryNodeRule };\nstaticAccessors$12.EndPointBoundaryNodeRule.get = function () { return EndPointBoundaryNodeRule };\nstaticAccessors$12.MultiValentEndPointBoundaryNodeRule.get = function () { return MultiValentEndPointBoundaryNodeRule };\nstaticAccessors$12.MonoValentEndPointBoundaryNodeRule.get = function () { return MonoValentEndPointBoundaryNodeRule };\nstaticAccessors$12.MOD2_BOUNDARY_RULE.get = function () { return new Mod2BoundaryNodeRule() };\nstaticAccessors$12.ENDPOINT_BOUNDARY_RULE.get = function () { return new EndPointBoundaryNodeRule() };\nstaticAccessors$12.MULTIVALENT_ENDPOINT_BOUNDARY_RULE.get = function () { return new MultiValentEndPointBoundaryNodeRule() };\nstaticAccessors$12.MONOVALENT_ENDPOINT_BOUNDARY_RULE.get = function () { return new MonoValentEndPointBoundaryNodeRule() };\nstaticAccessors$12.OGC_SFS_BOUNDARY_RULE.get = function () { return BoundaryNodeRule.MOD2_BOUNDARY_RULE };\n\nObject.defineProperties( BoundaryNodeRule, staticAccessors$12 );\n\nvar Mod2BoundaryNodeRule = function Mod2BoundaryNodeRule () {};\n\nMod2BoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {\n return boundaryCount % 2 === 1\n};\nMod2BoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {\n return [BoundaryNodeRule]\n};\nMod2BoundaryNodeRule.prototype.getClass = function getClass () {\n return Mod2BoundaryNodeRule\n};\n\nvar EndPointBoundaryNodeRule = function EndPointBoundaryNodeRule () {};\n\nEndPointBoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {\n return boundaryCount > 0\n};\nEndPointBoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {\n return [BoundaryNodeRule]\n};\nEndPointBoundaryNodeRule.prototype.getClass = function getClass () {\n return EndPointBoundaryNodeRule\n};\n\nvar MultiValentEndPointBoundaryNodeRule = function MultiValentEndPointBoundaryNodeRule () {};\n\nMultiValentEndPointBoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {\n return boundaryCount > 1\n};\nMultiValentEndPointBoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {\n return [BoundaryNodeRule]\n};\nMultiValentEndPointBoundaryNodeRule.prototype.getClass = function getClass () {\n return MultiValentEndPointBoundaryNodeRule\n};\n\nvar MonoValentEndPointBoundaryNodeRule = function MonoValentEndPointBoundaryNodeRule () {};\n\nMonoValentEndPointBoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {\n return boundaryCount === 1\n};\nMonoValentEndPointBoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {\n return [BoundaryNodeRule]\n};\nMonoValentEndPointBoundaryNodeRule.prototype.getClass = function getClass () {\n return MonoValentEndPointBoundaryNodeRule\n};\n\n// import Iterator from './Iterator'\n\n/**\n * @see http://download.oracle.com/javase/6/docs/api/java/util/Collection.html\n *\n * @constructor\n * @private\n */\nvar Collection = function Collection () {};\n\nCollection.prototype.add = function add () {};\n\n/**\n * Appends all of the elements in the specified collection to the end of this\n * list, in the order that they are returned by the specified collection's\n * iterator (optional operation).\n * @param {javascript.util.Collection} c\n * @return {boolean}\n */\nCollection.prototype.addAll = function addAll () {};\n\n/**\n * Returns true if this collection contains no elements.\n * @return {boolean}\n */\nCollection.prototype.isEmpty = function isEmpty () {};\n\n/**\n * Returns an iterator over the elements in this collection.\n * @return {javascript.util.Iterator}\n */\nCollection.prototype.iterator = function iterator () {};\n\n/**\n * Returns an iterator over the elements in this collection.\n * @return {number}\n */\nCollection.prototype.size = function size () {};\n\n/**\n * Returns an array containing all of the elements in this collection.\n * @return {Array}\n */\nCollection.prototype.toArray = function toArray () {};\n\n/**\n * Removes a single instance of the specified element from this collection if it\n * is present. (optional)\n * @param {Object} e\n * @return {boolean}\n */\nCollection.prototype.remove = function remove () {};\n\n/**\n * @param {string=} message Optional message\n * @extends {Error}\n * @constructor\n * @private\n */\nfunction IndexOutOfBoundsException (message) {\n this.message = message || '';\n}\nIndexOutOfBoundsException.prototype = new Error();\n\n/**\n * @type {string}\n */\nIndexOutOfBoundsException.prototype.name = 'IndexOutOfBoundsException';\n\n/**\n * @see http://download.oracle.com/javase/6/docs/api/java/util/Iterator.html\n * @constructor\n * @private\n */\nvar Iterator = function Iterator () {};\n\nIterator.prototype.hasNext = function hasNext () {};\n\n/**\n * Returns the next element in the iteration.\n * @return {Object}\n */\nIterator.prototype.next = function next () {};\n\n/**\n * Removes from the underlying collection the last element returned by the\n * iterator (optional operation).\n */\nIterator.prototype.remove = function remove () {};\n\n/**\n * @see http://download.oracle.com/javase/6/docs/api/java/util/List.html\n *\n * @extends {javascript.util.Collection}\n * @constructor\n * @private\n */\nvar List = (function (Collection$$1) {\n function List () {\n Collection$$1.apply(this, arguments);\n }\n\n if ( Collection$$1 ) List.__proto__ = Collection$$1;\n List.prototype = Object.create( Collection$$1 && Collection$$1.prototype );\n List.prototype.constructor = List;\n\n List.prototype.get = function get () { };\n\n /**\n * Replaces the element at the specified position in this list with the\n * specified element (optional operation).\n * @param {number} index\n * @param {Object} e\n * @return {Object}\n */\n List.prototype.set = function set () { };\n\n /**\n * Returns true if this collection contains no elements.\n * @return {boolean}\n */\n List.prototype.isEmpty = function isEmpty () { };\n\n return List;\n}(Collection));\n\n/**\n * @param {string=} message Optional message\n * @extends {Error}\n * @constructor\n * @private\n */\nfunction NoSuchElementException (message) {\n this.message = message || '';\n}\nNoSuchElementException.prototype = new Error();\n\n/**\n * @type {string}\n */\nNoSuchElementException.prototype.name = 'NoSuchElementException';\n\n// import OperationNotSupported from './OperationNotSupported'\n\n/**\n * @see http://download.oracle.com/javase/6/docs/api/java/util/ArrayList.html\n *\n * @extends List\n * @private\n */\nvar ArrayList = (function (List$$1) {\n function ArrayList () {\n List$$1.call(this);\n this.array_ = [];\n\n if (arguments[0] instanceof Collection) {\n this.addAll(arguments[0]);\n }\n }\n\n if ( List$$1 ) ArrayList.__proto__ = List$$1;\n ArrayList.prototype = Object.create( List$$1 && List$$1.prototype );\n ArrayList.prototype.constructor = ArrayList;\n\n ArrayList.prototype.ensureCapacity = function ensureCapacity () {};\n ArrayList.prototype.interfaces_ = function interfaces_ () { return [List$$1, Collection] };\n\n /**\n * @override\n */\n ArrayList.prototype.add = function add (e) {\n if (arguments.length === 1) {\n this.array_.push(e);\n } else {\n this.array_.splice(arguments[0], arguments[1]);\n }\n return true\n };\n\n ArrayList.prototype.clear = function clear () {\n this.array_ = [];\n };\n\n /**\n * @override\n */\n ArrayList.prototype.addAll = function addAll (c) {\n var this$1 = this;\n\n for (var i = c.iterator(); i.hasNext();) {\n this$1.add(i.next());\n }\n return true\n };\n\n /**\n * @override\n */\n ArrayList.prototype.set = function set (index, element) {\n var oldElement = this.array_[index];\n this.array_[index] = element;\n return oldElement\n };\n\n /**\n * @override\n */\n ArrayList.prototype.iterator = function iterator () {\n return new Iterator_(this)\n };\n\n /**\n * @override\n */\n ArrayList.prototype.get = function get (index) {\n if (index < 0 || index >= this.size()) {\n throw new IndexOutOfBoundsException()\n }\n\n return this.array_[index]\n };\n\n /**\n * @override\n */\n ArrayList.prototype.isEmpty = function isEmpty () {\n return this.array_.length === 0\n };\n\n /**\n * @override\n */\n ArrayList.prototype.size = function size () {\n return this.array_.length\n };\n\n /**\n * @override\n */\n ArrayList.prototype.toArray = function toArray () {\n var this$1 = this;\n\n var array = [];\n\n for (var i = 0, len = this.array_.length; i < len; i++) {\n array.push(this$1.array_[i]);\n }\n\n return array\n };\n\n /**\n * @override\n */\n ArrayList.prototype.remove = function remove (o) {\n var this$1 = this;\n\n var found = false;\n\n for (var i = 0, len = this.array_.length; i < len; i++) {\n if (this$1.array_[i] === o) {\n this$1.array_.splice(i, 1);\n found = true;\n break\n }\n }\n\n return found\n };\n\n return ArrayList;\n}(List));\n\n/**\n * @extends {Iterator}\n * @param {ArrayList} arrayList\n * @constructor\n * @private\n */\nvar Iterator_ = (function (Iterator$$1) {\n function Iterator_ (arrayList) {\n Iterator$$1.call(this);\n /**\n * @type {ArrayList}\n * @private\n */\n this.arrayList_ = arrayList;\n /**\n * @type {number}\n * @private\n */\n this.position_ = 0;\n }\n\n if ( Iterator$$1 ) Iterator_.__proto__ = Iterator$$1;\n Iterator_.prototype = Object.create( Iterator$$1 && Iterator$$1.prototype );\n Iterator_.prototype.constructor = Iterator_;\n\n /**\n * @override\n */\n Iterator_.prototype.next = function next () {\n if (this.position_ === this.arrayList_.size()) {\n throw new NoSuchElementException()\n }\n return this.arrayList_.get(this.position_++)\n };\n\n /**\n * @override\n */\n Iterator_.prototype.hasNext = function hasNext () {\n if (this.position_ < this.arrayList_.size()) {\n return true\n } else {\n return false\n }\n };\n\n /**\n * TODO: should be in ListIterator\n * @override\n */\n Iterator_.prototype.set = function set (element) {\n return this.arrayList_.set(this.position_ - 1, element)\n };\n\n /**\n * @override\n */\n Iterator_.prototype.remove = function remove () {\n this.arrayList_.remove(this.arrayList_.get(this.position_));\n };\n\n return Iterator_;\n}(Iterator));\n\nvar CoordinateList = (function (ArrayList$$1) {\n function CoordinateList () {\n ArrayList$$1.call(this);\n if (arguments.length === 0) {\n } else if (arguments.length === 1) {\n var coord = arguments[0];\n this.ensureCapacity(coord.length);\n this.add(coord, true);\n } else if (arguments.length === 2) {\n var coord$1 = arguments[0];\n var allowRepeated = arguments[1];\n this.ensureCapacity(coord$1.length);\n this.add(coord$1, allowRepeated);\n }\n }\n\n if ( ArrayList$$1 ) CoordinateList.__proto__ = ArrayList$$1;\n CoordinateList.prototype = Object.create( ArrayList$$1 && ArrayList$$1.prototype );\n CoordinateList.prototype.constructor = CoordinateList;\n\n var staticAccessors = { coordArrayType: { configurable: true } };\n staticAccessors.coordArrayType.get = function () { return new Array(0).fill(null) };\n CoordinateList.prototype.getCoordinate = function getCoordinate (i) {\n return this.get(i)\n };\n CoordinateList.prototype.addAll = function addAll () {\n var this$1 = this;\n\n if (arguments.length === 2) {\n var coll = arguments[0];\n var allowRepeated = arguments[1];\n var isChanged = false;\n for (var i = coll.iterator(); i.hasNext();) {\n this$1.add(i.next(), allowRepeated);\n isChanged = true;\n }\n return isChanged\n } else { return ArrayList$$1.prototype.addAll.apply(this, arguments) }\n };\n CoordinateList.prototype.clone = function clone () {\n var this$1 = this;\n\n var clone = ArrayList$$1.prototype.clone.call(this);\n for (var i = 0; i < this.size(); i++) {\n clone.add(i, this$1.get(i).copy());\n }\n return clone\n };\n CoordinateList.prototype.toCoordinateArray = function toCoordinateArray () {\n return this.toArray(CoordinateList.coordArrayType)\n };\n CoordinateList.prototype.add = function add () {\n var this$1 = this;\n\n if (arguments.length === 1) {\n var coord = arguments[0];\n ArrayList$$1.prototype.add.call(this, coord);\n } else if (arguments.length === 2) {\n if (arguments[0] instanceof Array && typeof arguments[1] === 'boolean') {\n var coord$1 = arguments[0];\n var allowRepeated = arguments[1];\n this.add(coord$1, allowRepeated, true);\n return true\n } else if (arguments[0] instanceof Coordinate && typeof arguments[1] === 'boolean') {\n var coord$2 = arguments[0];\n var allowRepeated$1 = arguments[1];\n if (!allowRepeated$1) {\n if (this.size() >= 1) {\n var last = this.get(this.size() - 1);\n if (last.equals2D(coord$2)) { return null }\n }\n }\n ArrayList$$1.prototype.add.call(this, coord$2);\n } else if (arguments[0] instanceof Object && typeof arguments[1] === 'boolean') {\n var obj = arguments[0];\n var allowRepeated$2 = arguments[1];\n this.add(obj, allowRepeated$2);\n return true\n }\n } else if (arguments.length === 3) {\n if (typeof arguments[2] === 'boolean' && (arguments[0] instanceof Array && typeof arguments[1] === 'boolean')) {\n var coord$3 = arguments[0];\n var allowRepeated$3 = arguments[1];\n var direction = arguments[2];\n if (direction) {\n for (var i$1 = 0; i$1 < coord$3.length; i$1++) {\n this$1.add(coord$3[i$1], allowRepeated$3);\n }\n } else {\n for (var i$2 = coord$3.length - 1; i$2 >= 0; i$2--) {\n this$1.add(coord$3[i$2], allowRepeated$3);\n }\n }\n return true\n } else if (typeof arguments[2] === 'boolean' && (Number.isInteger(arguments[0]) && arguments[1] instanceof Coordinate)) {\n var i$3 = arguments[0];\n var coord$4 = arguments[1];\n var allowRepeated$4 = arguments[2];\n if (!allowRepeated$4) {\n var size = this.size();\n if (size > 0) {\n if (i$3 > 0) {\n var prev = this.get(i$3 - 1);\n if (prev.equals2D(coord$4)) { return null }\n }\n if (i$3 < size) {\n var next = this.get(i$3);\n if (next.equals2D(coord$4)) { return null }\n }\n }\n }\n ArrayList$$1.prototype.add.call(this, i$3, coord$4);\n }\n } else if (arguments.length === 4) {\n var coord$5 = arguments[0];\n var allowRepeated$5 = arguments[1];\n var start = arguments[2];\n var end = arguments[3];\n var inc = 1;\n if (start > end) { inc = -1; }\n for (var i = start; i !== end; i += inc) {\n this$1.add(coord$5[i], allowRepeated$5);\n }\n return true\n }\n };\n CoordinateList.prototype.closeRing = function closeRing () {\n if (this.size() > 0) { this.add(new Coordinate(this.get(0)), false); }\n };\n CoordinateList.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n CoordinateList.prototype.getClass = function getClass () {\n return CoordinateList\n };\n\n Object.defineProperties( CoordinateList, staticAccessors );\n\n return CoordinateList;\n}(ArrayList));\n\nvar CoordinateArrays = function CoordinateArrays () {};\n\nvar staticAccessors$13 = { ForwardComparator: { configurable: true },BidirectionalComparator: { configurable: true },coordArrayType: { configurable: true } };\n\nstaticAccessors$13.ForwardComparator.get = function () { return ForwardComparator };\nstaticAccessors$13.BidirectionalComparator.get = function () { return BidirectionalComparator };\nstaticAccessors$13.coordArrayType.get = function () { return new Array(0).fill(null) };\n\nCoordinateArrays.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nCoordinateArrays.prototype.getClass = function getClass () {\n return CoordinateArrays\n};\nCoordinateArrays.isRing = function isRing (pts) {\n if (pts.length < 4) { return false }\n if (!pts[0].equals2D(pts[pts.length - 1])) { return false }\n return true\n};\nCoordinateArrays.ptNotInList = function ptNotInList (testPts, pts) {\n for (var i = 0; i < testPts.length; i++) {\n var testPt = testPts[i];\n if (CoordinateArrays.indexOf(testPt, pts) < 0) { return testPt }\n }\n return null\n};\nCoordinateArrays.scroll = function scroll (coordinates, firstCoordinate) {\n var i = CoordinateArrays.indexOf(firstCoordinate, coordinates);\n if (i < 0) { return null }\n var newCoordinates = new Array(coordinates.length).fill(null);\n System.arraycopy(coordinates, i, newCoordinates, 0, coordinates.length - i);\n System.arraycopy(coordinates, 0, newCoordinates, coordinates.length - i, i);\n System.arraycopy(newCoordinates, 0, coordinates, 0, coordinates.length);\n};\nCoordinateArrays.equals = function equals () {\n if (arguments.length === 2) {\n var coord1 = arguments[0];\n var coord2 = arguments[1];\n if (coord1 === coord2) { return true }\n if (coord1 === null || coord2 === null) { return false }\n if (coord1.length !== coord2.length) { return false }\n for (var i = 0; i < coord1.length; i++) {\n if (!coord1[i].equals(coord2[i])) { return false }\n }\n return true\n } else if (arguments.length === 3) {\n var coord1$1 = arguments[0];\n var coord2$1 = arguments[1];\n var coordinateComparator = arguments[2];\n if (coord1$1 === coord2$1) { return true }\n if (coord1$1 === null || coord2$1 === null) { return false }\n if (coord1$1.length !== coord2$1.length) { return false }\n for (var i$1 = 0; i$1 < coord1$1.length; i$1++) {\n if (coordinateComparator.compare(coord1$1[i$1], coord2$1[i$1]) !== 0) { return false }\n }\n return true\n }\n};\nCoordinateArrays.intersection = function intersection (coordinates, env) {\n var coordList = new CoordinateList();\n for (var i = 0; i < coordinates.length; i++) {\n if (env.intersects(coordinates[i])) { coordList.add(coordinates[i], true); }\n }\n return coordList.toCoordinateArray()\n};\nCoordinateArrays.hasRepeatedPoints = function hasRepeatedPoints (coord) {\n for (var i = 1; i < coord.length; i++) {\n if (coord[i - 1].equals(coord[i])) {\n return true\n }\n }\n return false\n};\nCoordinateArrays.removeRepeatedPoints = function removeRepeatedPoints (coord) {\n if (!CoordinateArrays.hasRepeatedPoints(coord)) { return coord }\n var coordList = new CoordinateList(coord, false);\n return coordList.toCoordinateArray()\n};\nCoordinateArrays.reverse = function reverse (coord) {\n var last = coord.length - 1;\n var mid = Math.trunc(last / 2);\n for (var i = 0; i <= mid; i++) {\n var tmp = coord[i];\n coord[i] = coord[last - i];\n coord[last - i] = tmp;\n }\n};\nCoordinateArrays.removeNull = function removeNull (coord) {\n var nonNull = 0;\n for (var i = 0; i < coord.length; i++) {\n if (coord[i] !== null) { nonNull++; }\n }\n var newCoord = new Array(nonNull).fill(null);\n if (nonNull === 0) { return newCoord }\n var j = 0;\n for (var i$1 = 0; i$1 < coord.length; i$1++) {\n if (coord[i$1] !== null) { newCoord[j++] = coord[i$1]; }\n }\n return newCoord\n};\nCoordinateArrays.copyDeep = function copyDeep () {\n if (arguments.length === 1) {\n var coordinates = arguments[0];\n var copy = new Array(coordinates.length).fill(null);\n for (var i = 0; i < coordinates.length; i++) {\n copy[i] = new Coordinate(coordinates[i]);\n }\n return copy\n } else if (arguments.length === 5) {\n var src = arguments[0];\n var srcStart = arguments[1];\n var dest = arguments[2];\n var destStart = arguments[3];\n var length = arguments[4];\n for (var i$1 = 0; i$1 < length; i$1++) {\n dest[destStart + i$1] = new Coordinate(src[srcStart + i$1]);\n }\n }\n};\nCoordinateArrays.isEqualReversed = function isEqualReversed (pts1, pts2) {\n for (var i = 0; i < pts1.length; i++) {\n var p1 = pts1[i];\n var p2 = pts2[pts1.length - i - 1];\n if (p1.compareTo(p2) !== 0) { return false }\n }\n return true\n};\nCoordinateArrays.envelope = function envelope (coordinates) {\n var env = new Envelope();\n for (var i = 0; i < coordinates.length; i++) {\n env.expandToInclude(coordinates[i]);\n }\n return env\n};\nCoordinateArrays.toCoordinateArray = function toCoordinateArray (coordList) {\n return coordList.toArray(CoordinateArrays.coordArrayType)\n};\nCoordinateArrays.atLeastNCoordinatesOrNothing = function atLeastNCoordinatesOrNothing (n, c) {\n return c.length >= n ? c : []\n};\nCoordinateArrays.indexOf = function indexOf (coordinate, coordinates) {\n for (var i = 0; i < coordinates.length; i++) {\n if (coordinate.equals(coordinates[i])) {\n return i\n }\n }\n return -1\n};\nCoordinateArrays.increasingDirection = function increasingDirection (pts) {\n for (var i = 0; i < Math.trunc(pts.length / 2); i++) {\n var j = pts.length - 1 - i;\n var comp = pts[i].compareTo(pts[j]);\n if (comp !== 0) { return comp }\n }\n return 1\n};\nCoordinateArrays.compare = function compare (pts1, pts2) {\n var i = 0;\n while (i < pts1.length && i < pts2.length) {\n var compare = pts1[i].compareTo(pts2[i]);\n if (compare !== 0) { return compare }\n i++;\n }\n if (i < pts2.length) { return -1 }\n if (i < pts1.length) { return 1 }\n return 0\n};\nCoordinateArrays.minCoordinate = function minCoordinate (coordinates) {\n var minCoord = null;\n for (var i = 0; i < coordinates.length; i++) {\n if (minCoord === null || minCoord.compareTo(coordinates[i]) > 0) {\n minCoord = coordinates[i];\n }\n }\n return minCoord\n};\nCoordinateArrays.extract = function extract (pts, start, end) {\n start = MathUtil.clamp(start, 0, pts.length);\n end = MathUtil.clamp(end, -1, pts.length);\n var npts = end - start + 1;\n if (end < 0) { npts = 0; }\n if (start >= pts.length) { npts = 0; }\n if (end < start) { npts = 0; }\n var extractPts = new Array(npts).fill(null);\n if (npts === 0) { return extractPts }\n var iPts = 0;\n for (var i = start; i <= end; i++) {\n extractPts[iPts++] = pts[i];\n }\n return extractPts\n};\n\nObject.defineProperties( CoordinateArrays, staticAccessors$13 );\n\nvar ForwardComparator = function ForwardComparator () {};\n\nForwardComparator.prototype.compare = function compare (o1, o2) {\n var pts1 = o1;\n var pts2 = o2;\n return CoordinateArrays.compare(pts1, pts2)\n};\nForwardComparator.prototype.interfaces_ = function interfaces_ () {\n return [Comparator]\n};\nForwardComparator.prototype.getClass = function getClass () {\n return ForwardComparator\n};\n\nvar BidirectionalComparator = function BidirectionalComparator () {};\n\nBidirectionalComparator.prototype.compare = function compare (o1, o2) {\n var pts1 = o1;\n var pts2 = o2;\n if (pts1.length < pts2.length) { return -1 }\n if (pts1.length > pts2.length) { return 1 }\n if (pts1.length === 0) { return 0 }\n var forwardComp = CoordinateArrays.compare(pts1, pts2);\n var isEqualRev = CoordinateArrays.isEqualReversed(pts1, pts2);\n if (isEqualRev) { return 0 }\n return forwardComp\n};\nBidirectionalComparator.prototype.OLDcompare = function OLDcompare (o1, o2) {\n var pts1 = o1;\n var pts2 = o2;\n if (pts1.length < pts2.length) { return -1 }\n if (pts1.length > pts2.length) { return 1 }\n if (pts1.length === 0) { return 0 }\n var dir1 = CoordinateArrays.increasingDirection(pts1);\n var dir2 = CoordinateArrays.increasingDirection(pts2);\n var i1 = dir1 > 0 ? 0 : pts1.length - 1;\n var i2 = dir2 > 0 ? 0 : pts1.length - 1;\n for (var i = 0; i < pts1.length; i++) {\n var comparePt = pts1[i1].compareTo(pts2[i2]);\n if (comparePt !== 0) { return comparePt }\n i1 += dir1;\n i2 += dir2;\n }\n return 0\n};\nBidirectionalComparator.prototype.interfaces_ = function interfaces_ () {\n return [Comparator]\n};\nBidirectionalComparator.prototype.getClass = function getClass () {\n return BidirectionalComparator\n};\n\n/**\n * @see http://download.oracle.com/javase/6/docs/api/java/util/Map.html\n *\n * @constructor\n * @private\n */\nvar Map$1 = function Map () {};\n\nMap$1.prototype.get = function get () {};\n/**\n * Associates the specified value with the specified key in this map (optional\n * operation).\n * @param {Object} key\n * @param {Object} value\n * @return {Object}\n */\nMap$1.prototype.put = function put () {};\n\n/**\n * Returns the number of key-value mappings in this map.\n * @return {number}\n */\nMap$1.prototype.size = function size () {};\n\n/**\n * Returns a Collection view of the values contained in this map.\n * @return {javascript.util.Collection}\n */\nMap$1.prototype.values = function values () {};\n\n/**\n * Returns a {@link Set} view of the mappings contained in this map.\n * The set is backed by the map, so changes to the map are\n * reflected in the set, and vice-versa.If the map is modified\n * while an iteration over the set is in progress (except through\n * the iterator's own remove operation, or through the\n * setValue operation on a map entry returned by the\n * iterator) the results of the iteration are undefined.The set\n * supports element removal, which removes the corresponding\n * mapping from the map, via the Iterator.remove ,\n * Set.remove , removeAll , retainAll and\n * clear operations.It does not support the\n * add or addAll operations.\n *\n * @return {Set} a set view of the mappings contained in this map\n */\nMap$1.prototype.entrySet = function entrySet () {};\n\n/**\n * @see http://download.oracle.com/javase/6/docs/api/java/util/SortedMap.html\n *\n * @extends {Map}\n * @constructor\n * @private\n */\nvar SortedMap = (function (Map) {\n\tfunction SortedMap () {\n\t\tMap.apply(this, arguments);\n\t}if ( Map ) SortedMap.__proto__ = Map;\n\tSortedMap.prototype = Object.create( Map && Map.prototype );\n\tSortedMap.prototype.constructor = SortedMap;\n\n\t\n\n\treturn SortedMap;\n}(Map$1));\n\n/**\n * @param {string=} message Optional message\n * @extends {Error}\n * @constructor\n * @private\n */\nfunction OperationNotSupported (message) {\n this.message = message || '';\n}\nOperationNotSupported.prototype = new Error();\n\n/**\n * @type {string}\n */\nOperationNotSupported.prototype.name = 'OperationNotSupported';\n\n/**\n * @see http://download.oracle.com/javase/6/docs/api/java/util/Set.html\n *\n * @extends {Collection}\n * @constructor\n * @private\n */\nfunction Set() {}\nSet.prototype = new Collection();\n\n\n/**\n * Returns true if this set contains the specified element. More formally,\n * returns true if and only if this set contains an element e such that (o==null ?\n * e==null : o.equals(e)).\n * @param {Object} e\n * @return {boolean}\n */\nSet.prototype.contains = function() {};\n\n/**\n * @see http://docs.oracle.com/javase/6/docs/api/java/util/HashSet.html\n *\n * @extends {javascript.util.Set}\n * @constructor\n * @private\n */\nvar HashSet = (function (Set$$1) {\n function HashSet () {\n Set$$1.call(this);\n this.array_ = [];\n\n if (arguments[0] instanceof Collection) {\n this.addAll(arguments[0]);\n }\n }\n\n if ( Set$$1 ) HashSet.__proto__ = Set$$1;\n HashSet.prototype = Object.create( Set$$1 && Set$$1.prototype );\n HashSet.prototype.constructor = HashSet;\n\n /**\n * @override\n */\n HashSet.prototype.contains = function contains (o) {\n var this$1 = this;\n\n for (var i = 0, len = this.array_.length; i < len; i++) {\n var e = this$1.array_[i];\n if (e === o) {\n return true\n }\n }\n return false\n };\n\n /**\n * @override\n */\n HashSet.prototype.add = function add (o) {\n if (this.contains(o)) {\n return false\n }\n\n this.array_.push(o);\n\n return true\n };\n\n /**\n * @override\n */\n HashSet.prototype.addAll = function addAll (c) {\n var this$1 = this;\n\n for (var i = c.iterator(); i.hasNext();) {\n this$1.add(i.next());\n }\n return true\n };\n\n /**\n * @override\n */\n HashSet.prototype.remove = function remove (o) {\n // throw new javascript.util.OperationNotSupported()\n throw new Error()\n };\n\n /**\n * @override\n */\n HashSet.prototype.size = function size () {\n return this.array_.length\n };\n\n /**\n * @override\n */\n HashSet.prototype.isEmpty = function isEmpty () {\n return this.array_.length === 0\n };\n\n /**\n * @override\n */\n HashSet.prototype.toArray = function toArray () {\n var this$1 = this;\n\n var array = [];\n\n for (var i = 0, len = this.array_.length; i < len; i++) {\n array.push(this$1.array_[i]);\n }\n\n return array\n };\n\n /**\n * @override\n */\n HashSet.prototype.iterator = function iterator () {\n return new Iterator_$1(this)\n };\n\n return HashSet;\n}(Set));\n\n/**\n * @extends {Iterator}\n * @param {HashSet} hashSet\n * @constructor\n * @private\n */\nvar Iterator_$1 = (function (Iterator$$1) {\n function Iterator_ (hashSet) {\n Iterator$$1.call(this);\n /**\n * @type {HashSet}\n * @private\n */\n this.hashSet_ = hashSet;\n /**\n * @type {number}\n * @private\n */\n this.position_ = 0;\n }\n\n if ( Iterator$$1 ) Iterator_.__proto__ = Iterator$$1;\n Iterator_.prototype = Object.create( Iterator$$1 && Iterator$$1.prototype );\n Iterator_.prototype.constructor = Iterator_;\n\n /**\n * @override\n */\n Iterator_.prototype.next = function next () {\n if (this.position_ === this.hashSet_.size()) {\n throw new NoSuchElementException()\n }\n return this.hashSet_.array_[this.position_++]\n };\n\n /**\n * @override\n */\n Iterator_.prototype.hasNext = function hasNext () {\n if (this.position_ < this.hashSet_.size()) {\n return true\n } else {\n return false\n }\n };\n\n /**\n * @override\n */\n Iterator_.prototype.remove = function remove () {\n throw new OperationNotSupported()\n };\n\n return Iterator_;\n}(Iterator));\n\nvar BLACK = 0;\nvar RED = 1;\nfunction colorOf (p) { return (p === null ? BLACK : p.color) }\nfunction parentOf (p) { return (p === null ? null : p.parent) }\nfunction setColor (p, c) { if (p !== null) { p.color = c; } }\nfunction leftOf (p) { return (p === null ? null : p.left) }\nfunction rightOf (p) { return (p === null ? null : p.right) }\n\n/**\n * @see http://download.oracle.com/javase/6/docs/api/java/util/TreeMap.html\n *\n * @extends {SortedMap}\n * @constructor\n * @private\n */\nfunction TreeMap () {\n /**\n * @type {Object}\n * @private\n */\n this.root_ = null;\n /**\n * @type {number}\n * @private\n */\n this.size_ = 0;\n}\nTreeMap.prototype = new SortedMap();\n\n/**\n * @override\n */\nTreeMap.prototype.get = function (key) {\n var p = this.root_;\n while (p !== null) {\n var cmp = key['compareTo'](p.key);\n if (cmp < 0) { p = p.left; }\n else if (cmp > 0) { p = p.right; }\n else { return p.value }\n }\n return null\n};\n\n/**\n * @override\n */\nTreeMap.prototype.put = function (key, value) {\n if (this.root_ === null) {\n this.root_ = {\n key: key,\n value: value,\n left: null,\n right: null,\n parent: null,\n color: BLACK,\n getValue: function getValue () { return this.value },\n getKey: function getKey () { return this.key }\n };\n this.size_ = 1;\n return null\n }\n var t = this.root_;\n var parent;\n var cmp;\n do {\n parent = t;\n cmp = key['compareTo'](t.key);\n if (cmp < 0) {\n t = t.left;\n } else if (cmp > 0) {\n t = t.right;\n } else {\n var oldValue = t.value;\n t.value = value;\n return oldValue\n }\n } while (t !== null)\n var e = {\n key: key,\n left: null,\n right: null,\n value: value,\n parent: parent,\n color: BLACK,\n getValue: function getValue () { return this.value },\n getKey: function getKey () { return this.key }\n };\n if (cmp < 0) {\n parent.left = e;\n } else {\n parent.right = e;\n }\n this.fixAfterInsertion(e);\n this.size_++;\n return null\n};\n\n/**\n * @param {Object} x\n */\nTreeMap.prototype.fixAfterInsertion = function (x) {\n var this$1 = this;\n\n x.color = RED;\n while (x != null && x !== this.root_ && x.parent.color === RED) {\n if (parentOf(x) === leftOf(parentOf(parentOf(x)))) {\n var y = rightOf(parentOf(parentOf(x)));\n if (colorOf(y) === RED) {\n setColor(parentOf(x), BLACK);\n setColor(y, BLACK);\n setColor(parentOf(parentOf(x)), RED);\n x = parentOf(parentOf(x));\n } else {\n if (x === rightOf(parentOf(x))) {\n x = parentOf(x);\n this$1.rotateLeft(x);\n }\n setColor(parentOf(x), BLACK);\n setColor(parentOf(parentOf(x)), RED);\n this$1.rotateRight(parentOf(parentOf(x)));\n }\n } else {\n var y$1 = leftOf(parentOf(parentOf(x)));\n if (colorOf(y$1) === RED) {\n setColor(parentOf(x), BLACK);\n setColor(y$1, BLACK);\n setColor(parentOf(parentOf(x)), RED);\n x = parentOf(parentOf(x));\n } else {\n if (x === leftOf(parentOf(x))) {\n x = parentOf(x);\n this$1.rotateRight(x);\n }\n setColor(parentOf(x), BLACK);\n setColor(parentOf(parentOf(x)), RED);\n this$1.rotateLeft(parentOf(parentOf(x)));\n }\n }\n }\n this.root_.color = BLACK;\n};\n\n/**\n * @override\n */\nTreeMap.prototype.values = function () {\n var arrayList = new ArrayList();\n var p = this.getFirstEntry();\n if (p !== null) {\n arrayList.add(p.value);\n while ((p = TreeMap.successor(p)) !== null) {\n arrayList.add(p.value);\n }\n }\n return arrayList\n};\n\n/**\n * @override\n */\nTreeMap.prototype.entrySet = function () {\n var hashSet = new HashSet();\n var p = this.getFirstEntry();\n if (p !== null) {\n hashSet.add(p);\n while ((p = TreeMap.successor(p)) !== null) {\n hashSet.add(p);\n }\n }\n return hashSet\n};\n\n/**\n * @param {Object} p\n */\nTreeMap.prototype.rotateLeft = function (p) {\n if (p != null) {\n var r = p.right;\n p.right = r.left;\n if (r.left != null) { r.left.parent = p; }\n r.parent = p.parent;\n if (p.parent === null) { this.root_ = r; } else if (p.parent.left === p) { p.parent.left = r; } else { p.parent.right = r; }\n r.left = p;\n p.parent = r;\n }\n};\n\n/**\n * @param {Object} p\n */\nTreeMap.prototype.rotateRight = function (p) {\n if (p != null) {\n var l = p.left;\n p.left = l.right;\n if (l.right != null) { l.right.parent = p; }\n l.parent = p.parent;\n if (p.parent === null) { this.root_ = l; } else if (p.parent.right === p) { p.parent.right = l; } else { p.parent.left = l; }\n l.right = p;\n p.parent = l;\n }\n};\n\n/**\n * @return {Object}\n */\nTreeMap.prototype.getFirstEntry = function () {\n var p = this.root_;\n if (p != null) {\n while (p.left != null) {\n p = p.left;\n }\n }\n return p\n};\n\n/**\n * @param {Object} t\n * @return {Object}\n * @private\n */\nTreeMap.successor = function (t) {\n if (t === null) { return null } else if (t.right !== null) {\n var p = t.right;\n while (p.left !== null) {\n p = p.left;\n }\n return p\n } else {\n var p$1 = t.parent;\n var ch = t;\n while (p$1 !== null && ch === p$1.right) {\n ch = p$1;\n p$1 = p$1.parent;\n }\n return p$1\n }\n};\n\n/**\n * @override\n */\nTreeMap.prototype.size = function () {\n return this.size_\n};\n\nvar Lineal = function Lineal () {};\n\nLineal.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nLineal.prototype.getClass = function getClass () {\n return Lineal\n};\n\n/**\n * @see http://download.oracle.com/javase/6/docs/api/java/util/SortedSet.html\n *\n * @extends {Set}\n * @constructor\n * @private\n */\nfunction SortedSet () {}\nSortedSet.prototype = new Set();\n\n// import Iterator from './Iterator'\n/**\n * @see http://download.oracle.com/javase/6/docs/api/java/util/TreeSet.html\n *\n * @extends {SortedSet}\n * @constructor\n * @private\n */\nfunction TreeSet () {\n /**\n * @type {Array}\n * @private\n */\n this.array_ = [];\n\n if (arguments[0] instanceof Collection) {\n this.addAll(arguments[0]);\n }\n}\nTreeSet.prototype = new SortedSet();\n\n/**\n * @override\n */\nTreeSet.prototype.contains = function (o) {\n var this$1 = this;\n\n for (var i = 0, len = this.array_.length; i < len; i++) {\n var e = this$1.array_[i];\n if (e['compareTo'](o) === 0) {\n return true\n }\n }\n return false\n};\n\n/**\n * @override\n */\nTreeSet.prototype.add = function (o) {\n var this$1 = this;\n\n if (this.contains(o)) {\n return false\n }\n\n for (var i = 0, len = this.array_.length; i < len; i++) {\n var e = this$1.array_[i];\n if (e['compareTo'](o) === 1) {\n this$1.array_.splice(i, 0, o);\n return true\n }\n }\n\n this.array_.push(o);\n\n return true\n};\n\n/**\n * @override\n */\nTreeSet.prototype.addAll = function (c) {\n var this$1 = this;\n\n for (var i = c.iterator(); i.hasNext();) {\n this$1.add(i.next());\n }\n return true\n};\n\n/**\n * @override\n */\nTreeSet.prototype.remove = function (e) {\n throw new OperationNotSupported()\n};\n\n/**\n * @override\n */\nTreeSet.prototype.size = function () {\n return this.array_.length\n};\n\n/**\n * @override\n */\nTreeSet.prototype.isEmpty = function () {\n return this.array_.length === 0\n};\n\n/**\n * @override\n */\nTreeSet.prototype.toArray = function () {\n var this$1 = this;\n\n var array = [];\n\n for (var i = 0, len = this.array_.length; i < len; i++) {\n array.push(this$1.array_[i]);\n }\n\n return array\n};\n\n/**\n * @override\n */\nTreeSet.prototype.iterator = function () {\n return new Iterator_$2(this)\n};\n\n/**\n * @extends {javascript.util.Iterator}\n * @param {javascript.util.TreeSet} treeSet\n * @constructor\n * @private\n */\nvar Iterator_$2 = function (treeSet) {\n /**\n * @type {javascript.util.TreeSet}\n * @private\n */\n this.treeSet_ = treeSet;\n /**\n * @type {number}\n * @private\n */\n this.position_ = 0;\n};\n\n/**\n * @override\n */\nIterator_$2.prototype.next = function () {\n if (this.position_ === this.treeSet_.size()) {\n throw new NoSuchElementException()\n }\n return this.treeSet_.array_[this.position_++]\n};\n\n/**\n * @override\n */\nIterator_$2.prototype.hasNext = function () {\n if (this.position_ < this.treeSet_.size()) {\n return true\n } else {\n return false\n }\n};\n\n/**\n * @override\n */\nIterator_$2.prototype.remove = function () {\n throw new OperationNotSupported()\n};\n\n/**\n * @see http://download.oracle.com/javase/6/docs/api/java/util/Arrays.html\n *\n * @constructor\n * @private\n */\nvar Arrays = function Arrays () {};\n\nArrays.sort = function sort () {\n var a = arguments[0];\n var i;\n var t;\n var comparator;\n var compare;\n if (arguments.length === 1) {\n compare = function (a, b) {\n return a.compareTo(b)\n };\n a.sort(compare);\n } else if (arguments.length === 2) {\n comparator = arguments[1];\n compare = function (a, b) {\n return comparator['compare'](a, b)\n };\n a.sort(compare);\n } else if (arguments.length === 3) {\n t = a.slice(arguments[1], arguments[2]);\n t.sort();\n var r = a.slice(0, arguments[1]).concat(t, a.slice(arguments[2], a.length));\n a.splice(0, a.length);\n for (i = 0; i < r.length; i++) {\n a.push(r[i]);\n }\n } else if (arguments.length === 4) {\n t = a.slice(arguments[1], arguments[2]);\n comparator = arguments[3];\n compare = function (a, b) {\n return comparator['compare'](a, b)\n };\n t.sort(compare);\n r = a.slice(0, arguments[1]).concat(t, a.slice(arguments[2], a.length));\n a.splice(0, a.length);\n for (i = 0; i < r.length; i++) {\n a.push(r[i]);\n }\n }\n};\n/**\n * @param {Array} array\n * @return {ArrayList}\n */\nArrays.asList = function asList (array) {\n var arrayList = new ArrayList();\n for (var i = 0, len = array.length; i < len; i++) {\n arrayList.add(array[i]);\n }\n return arrayList\n};\n\nvar Dimension = function Dimension () {};\n\nvar staticAccessors$14 = { P: { configurable: true },L: { configurable: true },A: { configurable: true },FALSE: { configurable: true },TRUE: { configurable: true },DONTCARE: { configurable: true },SYM_FALSE: { configurable: true },SYM_TRUE: { configurable: true },SYM_DONTCARE: { configurable: true },SYM_P: { configurable: true },SYM_L: { configurable: true },SYM_A: { configurable: true } };\n\nstaticAccessors$14.P.get = function () { return 0 };\nstaticAccessors$14.L.get = function () { return 1 };\nstaticAccessors$14.A.get = function () { return 2 };\nstaticAccessors$14.FALSE.get = function () { return -1 };\nstaticAccessors$14.TRUE.get = function () { return -2 };\nstaticAccessors$14.DONTCARE.get = function () { return -3 };\nstaticAccessors$14.SYM_FALSE.get = function () { return 'F' };\nstaticAccessors$14.SYM_TRUE.get = function () { return 'T' };\nstaticAccessors$14.SYM_DONTCARE.get = function () { return '*' };\nstaticAccessors$14.SYM_P.get = function () { return '0' };\nstaticAccessors$14.SYM_L.get = function () { return '1' };\nstaticAccessors$14.SYM_A.get = function () { return '2' };\n\nDimension.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nDimension.prototype.getClass = function getClass () {\n return Dimension\n};\nDimension.toDimensionSymbol = function toDimensionSymbol (dimensionValue) {\n switch (dimensionValue) {\n case Dimension.FALSE:\n return Dimension.SYM_FALSE\n case Dimension.TRUE:\n return Dimension.SYM_TRUE\n case Dimension.DONTCARE:\n return Dimension.SYM_DONTCARE\n case Dimension.P:\n return Dimension.SYM_P\n case Dimension.L:\n return Dimension.SYM_L\n case Dimension.A:\n return Dimension.SYM_A\n default:\n }\n throw new IllegalArgumentException('Unknown dimension value: ' + dimensionValue)\n};\nDimension.toDimensionValue = function toDimensionValue (dimensionSymbol) {\n switch (Character.toUpperCase(dimensionSymbol)) {\n case Dimension.SYM_FALSE:\n return Dimension.FALSE\n case Dimension.SYM_TRUE:\n return Dimension.TRUE\n case Dimension.SYM_DONTCARE:\n return Dimension.DONTCARE\n case Dimension.SYM_P:\n return Dimension.P\n case Dimension.SYM_L:\n return Dimension.L\n case Dimension.SYM_A:\n return Dimension.A\n default:\n }\n throw new IllegalArgumentException('Unknown dimension symbol: ' + dimensionSymbol)\n};\n\nObject.defineProperties( Dimension, staticAccessors$14 );\n\nvar GeometryFilter = function GeometryFilter () {};\n\nGeometryFilter.prototype.filter = function filter (geom) {};\nGeometryFilter.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nGeometryFilter.prototype.getClass = function getClass () {\n return GeometryFilter\n};\n\nvar CoordinateSequenceFilter = function CoordinateSequenceFilter () {};\n\nCoordinateSequenceFilter.prototype.filter = function filter (seq, i) {};\nCoordinateSequenceFilter.prototype.isDone = function isDone () {};\nCoordinateSequenceFilter.prototype.isGeometryChanged = function isGeometryChanged () {};\nCoordinateSequenceFilter.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nCoordinateSequenceFilter.prototype.getClass = function getClass () {\n return CoordinateSequenceFilter\n};\n\nvar GeometryCollection = (function (Geometry$$1) {\n function GeometryCollection (geometries, factory) {\n Geometry$$1.call(this, factory);\n this._geometries = geometries || [];\n\n if (Geometry$$1.hasNullElements(this._geometries)) {\n throw new IllegalArgumentException('geometries must not contain null elements')\n }\n }\n\n if ( Geometry$$1 ) GeometryCollection.__proto__ = Geometry$$1;\n GeometryCollection.prototype = Object.create( Geometry$$1 && Geometry$$1.prototype );\n GeometryCollection.prototype.constructor = GeometryCollection;\n\n var staticAccessors = { serialVersionUID: { configurable: true } };\n GeometryCollection.prototype.computeEnvelopeInternal = function computeEnvelopeInternal () {\n var this$1 = this;\n\n var envelope = new Envelope();\n for (var i = 0; i < this._geometries.length; i++) {\n envelope.expandToInclude(this$1._geometries[i].getEnvelopeInternal());\n }\n return envelope\n };\n GeometryCollection.prototype.getGeometryN = function getGeometryN (n) {\n return this._geometries[n]\n };\n GeometryCollection.prototype.getSortIndex = function getSortIndex () {\n return Geometry$$1.SORTINDEX_GEOMETRYCOLLECTION\n };\n GeometryCollection.prototype.getCoordinates = function getCoordinates () {\n var this$1 = this;\n\n var coordinates = new Array(this.getNumPoints()).fill(null);\n var k = -1;\n for (var i = 0; i < this._geometries.length; i++) {\n var childCoordinates = this$1._geometries[i].getCoordinates();\n for (var j = 0; j < childCoordinates.length; j++) {\n k++;\n coordinates[k] = childCoordinates[j];\n }\n }\n return coordinates\n };\n GeometryCollection.prototype.getArea = function getArea () {\n var this$1 = this;\n\n var area = 0.0;\n for (var i = 0; i < this._geometries.length; i++) {\n area += this$1._geometries[i].getArea();\n }\n return area\n };\n GeometryCollection.prototype.equalsExact = function equalsExact () {\n var this$1 = this;\n\n if (arguments.length === 2) {\n var other = arguments[0];\n var tolerance = arguments[1];\n if (!this.isEquivalentClass(other)) {\n return false\n }\n var otherCollection = other;\n if (this._geometries.length !== otherCollection._geometries.length) {\n return false\n }\n for (var i = 0; i < this._geometries.length; i++) {\n if (!this$1._geometries[i].equalsExact(otherCollection._geometries[i], tolerance)) {\n return false\n }\n }\n return true\n } else { return Geometry$$1.prototype.equalsExact.apply(this, arguments) }\n };\n GeometryCollection.prototype.normalize = function normalize () {\n var this$1 = this;\n\n for (var i = 0; i < this._geometries.length; i++) {\n this$1._geometries[i].normalize();\n }\n Arrays.sort(this._geometries);\n };\n GeometryCollection.prototype.getCoordinate = function getCoordinate () {\n if (this.isEmpty()) { return null }\n return this._geometries[0].getCoordinate()\n };\n GeometryCollection.prototype.getBoundaryDimension = function getBoundaryDimension () {\n var this$1 = this;\n\n var dimension = Dimension.FALSE;\n for (var i = 0; i < this._geometries.length; i++) {\n dimension = Math.max(dimension, this$1._geometries[i].getBoundaryDimension());\n }\n return dimension\n };\n GeometryCollection.prototype.getDimension = function getDimension () {\n var this$1 = this;\n\n var dimension = Dimension.FALSE;\n for (var i = 0; i < this._geometries.length; i++) {\n dimension = Math.max(dimension, this$1._geometries[i].getDimension());\n }\n return dimension\n };\n GeometryCollection.prototype.getLength = function getLength () {\n var this$1 = this;\n\n var sum = 0.0;\n for (var i = 0; i < this._geometries.length; i++) {\n sum += this$1._geometries[i].getLength();\n }\n return sum\n };\n GeometryCollection.prototype.getNumPoints = function getNumPoints () {\n var this$1 = this;\n\n var numPoints = 0;\n for (var i = 0; i < this._geometries.length; i++) {\n numPoints += this$1._geometries[i].getNumPoints();\n }\n return numPoints\n };\n GeometryCollection.prototype.getNumGeometries = function getNumGeometries () {\n return this._geometries.length\n };\n GeometryCollection.prototype.reverse = function reverse () {\n var this$1 = this;\n\n var n = this._geometries.length;\n var revGeoms = new Array(n).fill(null);\n for (var i = 0; i < this._geometries.length; i++) {\n revGeoms[i] = this$1._geometries[i].reverse();\n }\n return this.getFactory().createGeometryCollection(revGeoms)\n };\n GeometryCollection.prototype.compareToSameClass = function compareToSameClass () {\n var this$1 = this;\n\n if (arguments.length === 1) {\n var o = arguments[0];\n var theseElements = new TreeSet(Arrays.asList(this._geometries));\n var otherElements = new TreeSet(Arrays.asList(o._geometries));\n return this.compare(theseElements, otherElements)\n } else if (arguments.length === 2) {\n var o$1 = arguments[0];\n var comp = arguments[1];\n var gc = o$1;\n var n1 = this.getNumGeometries();\n var n2 = gc.getNumGeometries();\n var i = 0;\n while (i < n1 && i < n2) {\n var thisGeom = this$1.getGeometryN(i);\n var otherGeom = gc.getGeometryN(i);\n var holeComp = thisGeom.compareToSameClass(otherGeom, comp);\n if (holeComp !== 0) { return holeComp }\n i++;\n }\n if (i < n1) { return 1 }\n if (i < n2) { return -1 }\n return 0\n }\n };\n GeometryCollection.prototype.apply = function apply () {\n var this$1 = this;\n\n if (hasInterface(arguments[0], CoordinateFilter)) {\n var filter = arguments[0];\n for (var i = 0; i < this._geometries.length; i++) {\n this$1._geometries[i].apply(filter);\n }\n } else if (hasInterface(arguments[0], CoordinateSequenceFilter)) {\n var filter$1 = arguments[0];\n if (this._geometries.length === 0) { return null }\n for (var i$1 = 0; i$1 < this._geometries.length; i$1++) {\n this$1._geometries[i$1].apply(filter$1);\n if (filter$1.isDone()) {\n break\n }\n }\n if (filter$1.isGeometryChanged()) { this.geometryChanged(); }\n } else if (hasInterface(arguments[0], GeometryFilter)) {\n var filter$2 = arguments[0];\n filter$2.filter(this);\n for (var i$2 = 0; i$2 < this._geometries.length; i$2++) {\n this$1._geometries[i$2].apply(filter$2);\n }\n } else if (hasInterface(arguments[0], GeometryComponentFilter)) {\n var filter$3 = arguments[0];\n filter$3.filter(this);\n for (var i$3 = 0; i$3 < this._geometries.length; i$3++) {\n this$1._geometries[i$3].apply(filter$3);\n }\n }\n };\n GeometryCollection.prototype.getBoundary = function getBoundary () {\n this.checkNotGeometryCollection(this);\n Assert.shouldNeverReachHere();\n return null\n };\n GeometryCollection.prototype.clone = function clone () {\n var this$1 = this;\n\n var gc = Geometry$$1.prototype.clone.call(this);\n gc._geometries = new Array(this._geometries.length).fill(null);\n for (var i = 0; i < this._geometries.length; i++) {\n gc._geometries[i] = this$1._geometries[i].clone();\n }\n return gc\n };\n GeometryCollection.prototype.getGeometryType = function getGeometryType () {\n return 'GeometryCollection'\n };\n GeometryCollection.prototype.copy = function copy () {\n var this$1 = this;\n\n var geometries = new Array(this._geometries.length).fill(null);\n for (var i = 0; i < geometries.length; i++) {\n geometries[i] = this$1._geometries[i].copy();\n }\n return new GeometryCollection(geometries, this._factory)\n };\n GeometryCollection.prototype.isEmpty = function isEmpty () {\n var this$1 = this;\n\n for (var i = 0; i < this._geometries.length; i++) {\n if (!this$1._geometries[i].isEmpty()) {\n return false\n }\n }\n return true\n };\n GeometryCollection.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n GeometryCollection.prototype.getClass = function getClass () {\n return GeometryCollection\n };\n staticAccessors.serialVersionUID.get = function () { return -5694727726395021467 };\n\n Object.defineProperties( GeometryCollection, staticAccessors );\n\n return GeometryCollection;\n}(Geometry));\n\nvar MultiLineString = (function (GeometryCollection$$1) {\n function MultiLineString () {\n GeometryCollection$$1.apply(this, arguments);\n }\n\n if ( GeometryCollection$$1 ) MultiLineString.__proto__ = GeometryCollection$$1;\n MultiLineString.prototype = Object.create( GeometryCollection$$1 && GeometryCollection$$1.prototype );\n MultiLineString.prototype.constructor = MultiLineString;\n\n var staticAccessors = { serialVersionUID: { configurable: true } };\n\n MultiLineString.prototype.getSortIndex = function getSortIndex () {\n return Geometry.SORTINDEX_MULTILINESTRING\n };\n MultiLineString.prototype.equalsExact = function equalsExact () {\n if (arguments.length === 2) {\n var other = arguments[0];\n var tolerance = arguments[1];\n if (!this.isEquivalentClass(other)) {\n return false\n }\n return GeometryCollection$$1.prototype.equalsExact.call(this, other, tolerance)\n } else { return GeometryCollection$$1.prototype.equalsExact.apply(this, arguments) }\n };\n MultiLineString.prototype.getBoundaryDimension = function getBoundaryDimension () {\n if (this.isClosed()) {\n return Dimension.FALSE\n }\n return 0\n };\n MultiLineString.prototype.isClosed = function isClosed () {\n var this$1 = this;\n\n if (this.isEmpty()) {\n return false\n }\n for (var i = 0; i < this._geometries.length; i++) {\n if (!this$1._geometries[i].isClosed()) {\n return false\n }\n }\n return true\n };\n MultiLineString.prototype.getDimension = function getDimension () {\n return 1\n };\n MultiLineString.prototype.reverse = function reverse () {\n var this$1 = this;\n\n var nLines = this._geometries.length;\n var revLines = new Array(nLines).fill(null);\n for (var i = 0; i < this._geometries.length; i++) {\n revLines[nLines - 1 - i] = this$1._geometries[i].reverse();\n }\n return this.getFactory().createMultiLineString(revLines)\n };\n MultiLineString.prototype.getBoundary = function getBoundary () {\n return new BoundaryOp(this).getBoundary()\n };\n MultiLineString.prototype.getGeometryType = function getGeometryType () {\n return 'MultiLineString'\n };\n MultiLineString.prototype.copy = function copy () {\n var this$1 = this;\n\n var lineStrings = new Array(this._geometries.length).fill(null);\n for (var i = 0; i < lineStrings.length; i++) {\n lineStrings[i] = this$1._geometries[i].copy();\n }\n return new MultiLineString(lineStrings, this._factory)\n };\n MultiLineString.prototype.interfaces_ = function interfaces_ () {\n return [Lineal]\n };\n MultiLineString.prototype.getClass = function getClass () {\n return MultiLineString\n };\n staticAccessors.serialVersionUID.get = function () { return 8166665132445433741 };\n\n Object.defineProperties( MultiLineString, staticAccessors );\n\n return MultiLineString;\n}(GeometryCollection));\n\nvar BoundaryOp = function BoundaryOp () {\n this._geom = null;\n this._geomFact = null;\n this._bnRule = null;\n this._endpointMap = null;\n if (arguments.length === 1) {\n var geom = arguments[0];\n var bnRule = BoundaryNodeRule.MOD2_BOUNDARY_RULE;\n this._geom = geom;\n this._geomFact = geom.getFactory();\n this._bnRule = bnRule;\n } else if (arguments.length === 2) {\n var geom$1 = arguments[0];\n var bnRule$1 = arguments[1];\n this._geom = geom$1;\n this._geomFact = geom$1.getFactory();\n this._bnRule = bnRule$1;\n }\n};\nBoundaryOp.prototype.boundaryMultiLineString = function boundaryMultiLineString (mLine) {\n if (this._geom.isEmpty()) {\n return this.getEmptyMultiPoint()\n }\n var bdyPts = this.computeBoundaryCoordinates(mLine);\n if (bdyPts.length === 1) {\n return this._geomFact.createPoint(bdyPts[0])\n }\n return this._geomFact.createMultiPointFromCoords(bdyPts)\n};\nBoundaryOp.prototype.getBoundary = function getBoundary () {\n if (this._geom instanceof LineString) { return this.boundaryLineString(this._geom) }\n if (this._geom instanceof MultiLineString) { return this.boundaryMultiLineString(this._geom) }\n return this._geom.getBoundary()\n};\nBoundaryOp.prototype.boundaryLineString = function boundaryLineString (line) {\n if (this._geom.isEmpty()) {\n return this.getEmptyMultiPoint()\n }\n if (line.isClosed()) {\n var closedEndpointOnBoundary = this._bnRule.isInBoundary(2);\n if (closedEndpointOnBoundary) {\n return line.getStartPoint()\n } else {\n return this._geomFact.createMultiPoint()\n }\n }\n return this._geomFact.createMultiPoint([line.getStartPoint(), line.getEndPoint()])\n};\nBoundaryOp.prototype.getEmptyMultiPoint = function getEmptyMultiPoint () {\n return this._geomFact.createMultiPoint()\n};\nBoundaryOp.prototype.computeBoundaryCoordinates = function computeBoundaryCoordinates (mLine) {\n var this$1 = this;\n\n var bdyPts = new ArrayList();\n this._endpointMap = new TreeMap();\n for (var i = 0; i < mLine.getNumGeometries(); i++) {\n var line = mLine.getGeometryN(i);\n if (line.getNumPoints() === 0) { continue }\n this$1.addEndpoint(line.getCoordinateN(0));\n this$1.addEndpoint(line.getCoordinateN(line.getNumPoints() - 1));\n }\n for (var it = this._endpointMap.entrySet().iterator(); it.hasNext();) {\n var entry = it.next();\n var counter = entry.getValue();\n var valence = counter.count;\n if (this$1._bnRule.isInBoundary(valence)) {\n bdyPts.add(entry.getKey());\n }\n }\n return CoordinateArrays.toCoordinateArray(bdyPts)\n};\nBoundaryOp.prototype.addEndpoint = function addEndpoint (pt) {\n var counter = this._endpointMap.get(pt);\n if (counter === null) {\n counter = new Counter();\n this._endpointMap.put(pt, counter);\n }\n counter.count++;\n};\nBoundaryOp.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nBoundaryOp.prototype.getClass = function getClass () {\n return BoundaryOp\n};\nBoundaryOp.getBoundary = function getBoundary () {\n if (arguments.length === 1) {\n var g = arguments[0];\n var bop = new BoundaryOp(g);\n return bop.getBoundary()\n } else if (arguments.length === 2) {\n var g$1 = arguments[0];\n var bnRule = arguments[1];\n var bop$1 = new BoundaryOp(g$1, bnRule);\n return bop$1.getBoundary()\n }\n};\n\nvar Counter = function Counter () {\n this.count = null;\n};\nCounter.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nCounter.prototype.getClass = function getClass () {\n return Counter\n};\n\n// boundary\n\nfunction PrintStream () {}\n\nfunction StringReader () {}\n\nvar DecimalFormat = function DecimalFormat () {};\n\nfunction ByteArrayOutputStream () {}\n\nfunction IOException () {}\n\nfunction LineNumberReader () {}\n\nvar StringUtil = function StringUtil () {};\n\nvar staticAccessors$15 = { NEWLINE: { configurable: true },SIMPLE_ORDINATE_FORMAT: { configurable: true } };\n\nStringUtil.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nStringUtil.prototype.getClass = function getClass () {\n return StringUtil\n};\nStringUtil.chars = function chars (c, n) {\n var ch = new Array(n).fill(null);\n for (var i = 0; i < n; i++) {\n ch[i] = c;\n }\n return String(ch)\n};\nStringUtil.getStackTrace = function getStackTrace () {\n if (arguments.length === 1) {\n var t = arguments[0];\n var os = new ByteArrayOutputStream();\n var ps = new PrintStream(os);\n t.printStackTrace(ps);\n return os.toString()\n } else if (arguments.length === 2) {\n var t$1 = arguments[0];\n var depth = arguments[1];\n var stackTrace = '';\n var stringReader = new StringReader(StringUtil.getStackTrace(t$1));\n var lineNumberReader = new LineNumberReader(stringReader);\n for (var i = 0; i < depth; i++) {\n try {\n stackTrace += lineNumberReader.readLine() + StringUtil.NEWLINE;\n } catch (e) {\n if (e instanceof IOException) {\n Assert.shouldNeverReachHere();\n } else { throw e }\n } finally {}\n }\n return stackTrace\n }\n};\nStringUtil.split = function split (s, separator) {\n var separatorlen = separator.length;\n var tokenList = new ArrayList();\n var tmpString = '' + s;\n var pos = tmpString.indexOf(separator);\n while (pos >= 0) {\n var token = tmpString.substring(0, pos);\n tokenList.add(token);\n tmpString = tmpString.substring(pos + separatorlen);\n pos = tmpString.indexOf(separator);\n }\n if (tmpString.length > 0) { tokenList.add(tmpString); }\n var res = new Array(tokenList.size()).fill(null);\n for (var i = 0; i < res.length; i++) {\n res[i] = tokenList.get(i);\n }\n return res\n};\nStringUtil.toString = function toString () {\n if (arguments.length === 1) {\n var d = arguments[0];\n return StringUtil.SIMPLE_ORDINATE_FORMAT.format(d)\n }\n};\nStringUtil.spaces = function spaces (n) {\n return StringUtil.chars(' ', n)\n};\nstaticAccessors$15.NEWLINE.get = function () { return System.getProperty('line.separator') };\nstaticAccessors$15.SIMPLE_ORDINATE_FORMAT.get = function () { return new DecimalFormat('0.#') };\n\nObject.defineProperties( StringUtil, staticAccessors$15 );\n\nvar CoordinateSequences = function CoordinateSequences () {};\n\nCoordinateSequences.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nCoordinateSequences.prototype.getClass = function getClass () {\n return CoordinateSequences\n};\nCoordinateSequences.copyCoord = function copyCoord (src, srcPos, dest, destPos) {\n var minDim = Math.min(src.getDimension(), dest.getDimension());\n for (var dim = 0; dim < minDim; dim++) {\n dest.setOrdinate(destPos, dim, src.getOrdinate(srcPos, dim));\n }\n};\nCoordinateSequences.isRing = function isRing (seq) {\n var n = seq.size();\n if (n === 0) { return true }\n if (n <= 3) { return false }\n return seq.getOrdinate(0, CoordinateSequence.X) === seq.getOrdinate(n - 1, CoordinateSequence.X) && seq.getOrdinate(0, CoordinateSequence.Y) === seq.getOrdinate(n - 1, CoordinateSequence.Y)\n};\nCoordinateSequences.isEqual = function isEqual (cs1, cs2) {\n var cs1Size = cs1.size();\n var cs2Size = cs2.size();\n if (cs1Size !== cs2Size) { return false }\n var dim = Math.min(cs1.getDimension(), cs2.getDimension());\n for (var i = 0; i < cs1Size; i++) {\n for (var d = 0; d < dim; d++) {\n var v1 = cs1.getOrdinate(i, d);\n var v2 = cs2.getOrdinate(i, d);\n if (cs1.getOrdinate(i, d) === cs2.getOrdinate(i, d)) { continue }\n if (Double.isNaN(v1) && Double.isNaN(v2)) { continue }\n return false\n }\n }\n return true\n};\nCoordinateSequences.extend = function extend (fact, seq, size) {\n var newseq = fact.create(size, seq.getDimension());\n var n = seq.size();\n CoordinateSequences.copy(seq, 0, newseq, 0, n);\n if (n > 0) {\n for (var i = n; i < size; i++) { CoordinateSequences.copy(seq, n - 1, newseq, i, 1); }\n }\n return newseq\n};\nCoordinateSequences.reverse = function reverse (seq) {\n var last = seq.size() - 1;\n var mid = Math.trunc(last / 2);\n for (var i = 0; i <= mid; i++) {\n CoordinateSequences.swap(seq, i, last - i);\n }\n};\nCoordinateSequences.swap = function swap (seq, i, j) {\n if (i === j) { return null }\n for (var dim = 0; dim < seq.getDimension(); dim++) {\n var tmp = seq.getOrdinate(i, dim);\n seq.setOrdinate(i, dim, seq.getOrdinate(j, dim));\n seq.setOrdinate(j, dim, tmp);\n }\n};\nCoordinateSequences.copy = function copy (src, srcPos, dest, destPos, length) {\n for (var i = 0; i < length; i++) {\n CoordinateSequences.copyCoord(src, srcPos + i, dest, destPos + i);\n }\n};\nCoordinateSequences.toString = function toString () {\n if (arguments.length === 1) {\n var cs = arguments[0];\n var size = cs.size();\n if (size === 0) { return '()' }\n var dim = cs.getDimension();\n var buf = new StringBuffer();\n buf.append('(');\n for (var i = 0; i < size; i++) {\n if (i > 0) { buf.append(' '); }\n for (var d = 0; d < dim; d++) {\n if (d > 0) { buf.append(','); }\n buf.append(StringUtil.toString(cs.getOrdinate(i, d)));\n }\n }\n buf.append(')');\n return buf.toString()\n }\n};\nCoordinateSequences.ensureValidRing = function ensureValidRing (fact, seq) {\n var n = seq.size();\n if (n === 0) { return seq }\n if (n <= 3) { return CoordinateSequences.createClosedRing(fact, seq, 4) }\n var isClosed = seq.getOrdinate(0, CoordinateSequence.X) === seq.getOrdinate(n - 1, CoordinateSequence.X) && seq.getOrdinate(0, CoordinateSequence.Y) === seq.getOrdinate(n - 1, CoordinateSequence.Y);\n if (isClosed) { return seq }\n return CoordinateSequences.createClosedRing(fact, seq, n + 1)\n};\nCoordinateSequences.createClosedRing = function createClosedRing (fact, seq, size) {\n var newseq = fact.create(size, seq.getDimension());\n var n = seq.size();\n CoordinateSequences.copy(seq, 0, newseq, 0, n);\n for (var i = n; i < size; i++) { CoordinateSequences.copy(seq, 0, newseq, i, 1); }\n return newseq\n};\n\nvar LineString = (function (Geometry$$1) {\n function LineString (points, factory) {\n Geometry$$1.call(this, factory);\n this._points = null;\n this.init(points);\n }\n\n if ( Geometry$$1 ) LineString.__proto__ = Geometry$$1;\n LineString.prototype = Object.create( Geometry$$1 && Geometry$$1.prototype );\n LineString.prototype.constructor = LineString;\n\n var staticAccessors = { serialVersionUID: { configurable: true } };\n LineString.prototype.computeEnvelopeInternal = function computeEnvelopeInternal () {\n if (this.isEmpty()) {\n return new Envelope()\n }\n return this._points.expandEnvelope(new Envelope())\n };\n LineString.prototype.isRing = function isRing () {\n return this.isClosed() && this.isSimple()\n };\n LineString.prototype.getSortIndex = function getSortIndex () {\n return Geometry$$1.SORTINDEX_LINESTRING\n };\n LineString.prototype.getCoordinates = function getCoordinates () {\n return this._points.toCoordinateArray()\n };\n LineString.prototype.equalsExact = function equalsExact () {\n var this$1 = this;\n\n if (arguments.length === 2) {\n var other = arguments[0];\n var tolerance = arguments[1];\n if (!this.isEquivalentClass(other)) {\n return false\n }\n var otherLineString = other;\n if (this._points.size() !== otherLineString._points.size()) {\n return false\n }\n for (var i = 0; i < this._points.size(); i++) {\n if (!this$1.equal(this$1._points.getCoordinate(i), otherLineString._points.getCoordinate(i), tolerance)) {\n return false\n }\n }\n return true\n } else { return Geometry$$1.prototype.equalsExact.apply(this, arguments) }\n };\n LineString.prototype.normalize = function normalize () {\n var this$1 = this;\n\n for (var i = 0; i < Math.trunc(this._points.size() / 2); i++) {\n var j = this$1._points.size() - 1 - i;\n if (!this$1._points.getCoordinate(i).equals(this$1._points.getCoordinate(j))) {\n if (this$1._points.getCoordinate(i).compareTo(this$1._points.getCoordinate(j)) > 0) {\n CoordinateSequences.reverse(this$1._points);\n }\n return null\n }\n }\n };\n LineString.prototype.getCoordinate = function getCoordinate () {\n if (this.isEmpty()) { return null }\n return this._points.getCoordinate(0)\n };\n LineString.prototype.getBoundaryDimension = function getBoundaryDimension () {\n if (this.isClosed()) {\n return Dimension.FALSE\n }\n return 0\n };\n LineString.prototype.isClosed = function isClosed () {\n if (this.isEmpty()) {\n return false\n }\n return this.getCoordinateN(0).equals2D(this.getCoordinateN(this.getNumPoints() - 1))\n };\n LineString.prototype.getEndPoint = function getEndPoint () {\n if (this.isEmpty()) {\n return null\n }\n return this.getPointN(this.getNumPoints() - 1)\n };\n LineString.prototype.getDimension = function getDimension () {\n return 1\n };\n LineString.prototype.getLength = function getLength () {\n return CGAlgorithms.computeLength(this._points)\n };\n LineString.prototype.getNumPoints = function getNumPoints () {\n return this._points.size()\n };\n LineString.prototype.reverse = function reverse () {\n var seq = this._points.copy();\n CoordinateSequences.reverse(seq);\n var revLine = this.getFactory().createLineString(seq);\n return revLine\n };\n LineString.prototype.compareToSameClass = function compareToSameClass () {\n var this$1 = this;\n\n if (arguments.length === 1) {\n var o = arguments[0];\n var line = o;\n var i = 0;\n var j = 0;\n while (i < this._points.size() && j < line._points.size()) {\n var comparison = this$1._points.getCoordinate(i).compareTo(line._points.getCoordinate(j));\n if (comparison !== 0) {\n return comparison\n }\n i++;\n j++;\n }\n if (i < this._points.size()) {\n return 1\n }\n if (j < line._points.size()) {\n return -1\n }\n return 0\n } else if (arguments.length === 2) {\n var o$1 = arguments[0];\n var comp = arguments[1];\n var line$1 = o$1;\n return comp.compare(this._points, line$1._points)\n }\n };\n LineString.prototype.apply = function apply () {\n var this$1 = this;\n\n if (hasInterface(arguments[0], CoordinateFilter)) {\n var filter = arguments[0];\n for (var i = 0; i < this._points.size(); i++) {\n filter.filter(this$1._points.getCoordinate(i));\n }\n } else if (hasInterface(arguments[0], CoordinateSequenceFilter)) {\n var filter$1 = arguments[0];\n if (this._points.size() === 0) { return null }\n for (var i$1 = 0; i$1 < this._points.size(); i$1++) {\n filter$1.filter(this$1._points, i$1);\n if (filter$1.isDone()) { break }\n }\n if (filter$1.isGeometryChanged()) { this.geometryChanged(); }\n } else if (hasInterface(arguments[0], GeometryFilter)) {\n var filter$2 = arguments[0];\n filter$2.filter(this);\n } else if (hasInterface(arguments[0], GeometryComponentFilter)) {\n var filter$3 = arguments[0];\n filter$3.filter(this);\n }\n };\n LineString.prototype.getBoundary = function getBoundary () {\n return new BoundaryOp(this).getBoundary()\n };\n LineString.prototype.isEquivalentClass = function isEquivalentClass (other) {\n return other instanceof LineString\n };\n LineString.prototype.clone = function clone () {\n var ls = Geometry$$1.prototype.clone.call(this);\n ls._points = this._points.clone();\n return ls\n };\n LineString.prototype.getCoordinateN = function getCoordinateN (n) {\n return this._points.getCoordinate(n)\n };\n LineString.prototype.getGeometryType = function getGeometryType () {\n return 'LineString'\n };\n LineString.prototype.copy = function copy () {\n return new LineString(this._points.copy(), this._factory)\n };\n LineString.prototype.getCoordinateSequence = function getCoordinateSequence () {\n return this._points\n };\n LineString.prototype.isEmpty = function isEmpty () {\n return this._points.size() === 0\n };\n LineString.prototype.init = function init (points) {\n if (points === null) {\n points = this.getFactory().getCoordinateSequenceFactory().create([]);\n }\n if (points.size() === 1) {\n throw new IllegalArgumentException('Invalid number of points in LineString (found ' + points.size() + ' - must be 0 or >= 2)')\n }\n this._points = points;\n };\n LineString.prototype.isCoordinate = function isCoordinate (pt) {\n var this$1 = this;\n\n for (var i = 0; i < this._points.size(); i++) {\n if (this$1._points.getCoordinate(i).equals(pt)) {\n return true\n }\n }\n return false\n };\n LineString.prototype.getStartPoint = function getStartPoint () {\n if (this.isEmpty()) {\n return null\n }\n return this.getPointN(0)\n };\n LineString.prototype.getPointN = function getPointN (n) {\n return this.getFactory().createPoint(this._points.getCoordinate(n))\n };\n LineString.prototype.interfaces_ = function interfaces_ () {\n return [Lineal]\n };\n LineString.prototype.getClass = function getClass () {\n return LineString\n };\n staticAccessors.serialVersionUID.get = function () { return 3110669828065365560 };\n\n Object.defineProperties( LineString, staticAccessors );\n\n return LineString;\n}(Geometry));\n\nvar Puntal = function Puntal () {};\n\nPuntal.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nPuntal.prototype.getClass = function getClass () {\n return Puntal\n};\n\nvar Point = (function (Geometry$$1) {\n function Point (coordinates, factory) {\n Geometry$$1.call(this, factory);\n this._coordinates = coordinates || null;\n this.init(this._coordinates);\n }\n\n if ( Geometry$$1 ) Point.__proto__ = Geometry$$1;\n Point.prototype = Object.create( Geometry$$1 && Geometry$$1.prototype );\n Point.prototype.constructor = Point;\n\n var staticAccessors = { serialVersionUID: { configurable: true } };\n Point.prototype.computeEnvelopeInternal = function computeEnvelopeInternal () {\n if (this.isEmpty()) {\n return new Envelope()\n }\n var env = new Envelope();\n env.expandToInclude(this._coordinates.getX(0), this._coordinates.getY(0));\n return env\n };\n Point.prototype.getSortIndex = function getSortIndex () {\n return Geometry$$1.SORTINDEX_POINT\n };\n Point.prototype.getCoordinates = function getCoordinates () {\n return this.isEmpty() ? [] : [this.getCoordinate()]\n };\n Point.prototype.equalsExact = function equalsExact () {\n if (arguments.length === 2) {\n var other = arguments[0];\n var tolerance = arguments[1];\n if (!this.isEquivalentClass(other)) {\n return false\n }\n if (this.isEmpty() && other.isEmpty()) {\n return true\n }\n if (this.isEmpty() !== other.isEmpty()) {\n return false\n }\n return this.equal(other.getCoordinate(), this.getCoordinate(), tolerance)\n } else { return Geometry$$1.prototype.equalsExact.apply(this, arguments) }\n };\n Point.prototype.normalize = function normalize () {};\n Point.prototype.getCoordinate = function getCoordinate () {\n return this._coordinates.size() !== 0 ? this._coordinates.getCoordinate(0) : null\n };\n Point.prototype.getBoundaryDimension = function getBoundaryDimension () {\n return Dimension.FALSE\n };\n Point.prototype.getDimension = function getDimension () {\n return 0\n };\n Point.prototype.getNumPoints = function getNumPoints () {\n return this.isEmpty() ? 0 : 1\n };\n Point.prototype.reverse = function reverse () {\n return this.copy()\n };\n Point.prototype.getX = function getX () {\n if (this.getCoordinate() === null) {\n throw new Error('getX called on empty Point')\n }\n return this.getCoordinate().x\n };\n Point.prototype.compareToSameClass = function compareToSameClass () {\n if (arguments.length === 1) {\n var other = arguments[0];\n var point$1 = other;\n return this.getCoordinate().compareTo(point$1.getCoordinate())\n } else if (arguments.length === 2) {\n var other$1 = arguments[0];\n var comp = arguments[1];\n var point = other$1;\n return comp.compare(this._coordinates, point._coordinates)\n }\n };\n Point.prototype.apply = function apply () {\n if (hasInterface(arguments[0], CoordinateFilter)) {\n var filter = arguments[0];\n if (this.isEmpty()) {\n return null\n }\n filter.filter(this.getCoordinate());\n } else if (hasInterface(arguments[0], CoordinateSequenceFilter)) {\n var filter$1 = arguments[0];\n if (this.isEmpty()) { return null }\n filter$1.filter(this._coordinates, 0);\n if (filter$1.isGeometryChanged()) { this.geometryChanged(); }\n } else if (hasInterface(arguments[0], GeometryFilter)) {\n var filter$2 = arguments[0];\n filter$2.filter(this);\n } else if (hasInterface(arguments[0], GeometryComponentFilter)) {\n var filter$3 = arguments[0];\n filter$3.filter(this);\n }\n };\n Point.prototype.getBoundary = function getBoundary () {\n return this.getFactory().createGeometryCollection(null)\n };\n Point.prototype.clone = function clone () {\n var p = Geometry$$1.prototype.clone.call(this);\n p._coordinates = this._coordinates.clone();\n return p\n };\n Point.prototype.getGeometryType = function getGeometryType () {\n return 'Point'\n };\n Point.prototype.copy = function copy () {\n return new Point(this._coordinates.copy(), this._factory)\n };\n Point.prototype.getCoordinateSequence = function getCoordinateSequence () {\n return this._coordinates\n };\n Point.prototype.getY = function getY () {\n if (this.getCoordinate() === null) {\n throw new Error('getY called on empty Point')\n }\n return this.getCoordinate().y\n };\n Point.prototype.isEmpty = function isEmpty () {\n return this._coordinates.size() === 0\n };\n Point.prototype.init = function init (coordinates) {\n if (coordinates === null) {\n coordinates = this.getFactory().getCoordinateSequenceFactory().create([]);\n }\n Assert.isTrue(coordinates.size() <= 1);\n this._coordinates = coordinates;\n };\n Point.prototype.isSimple = function isSimple () {\n return true\n };\n Point.prototype.interfaces_ = function interfaces_ () {\n return [Puntal]\n };\n Point.prototype.getClass = function getClass () {\n return Point\n };\n staticAccessors.serialVersionUID.get = function () { return 4902022702746614570 };\n\n Object.defineProperties( Point, staticAccessors );\n\n return Point;\n}(Geometry));\n\nvar Polygonal = function Polygonal () {};\n\nPolygonal.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nPolygonal.prototype.getClass = function getClass () {\n return Polygonal\n};\n\nvar Polygon = (function (Geometry$$1) {\n function Polygon (shell, holes, factory) {\n Geometry$$1.call(this, factory);\n this._shell = null;\n this._holes = null;\n if (shell === null) {\n shell = this.getFactory().createLinearRing();\n }\n if (holes === null) {\n holes = [];\n }\n if (Geometry$$1.hasNullElements(holes)) {\n throw new IllegalArgumentException('holes must not contain null elements')\n }\n if (shell.isEmpty() && Geometry$$1.hasNonEmptyElements(holes)) {\n throw new IllegalArgumentException('shell is empty but holes are not')\n }\n this._shell = shell;\n this._holes = holes;\n }\n\n if ( Geometry$$1 ) Polygon.__proto__ = Geometry$$1;\n Polygon.prototype = Object.create( Geometry$$1 && Geometry$$1.prototype );\n Polygon.prototype.constructor = Polygon;\n\n var staticAccessors = { serialVersionUID: { configurable: true } };\n Polygon.prototype.computeEnvelopeInternal = function computeEnvelopeInternal () {\n return this._shell.getEnvelopeInternal()\n };\n Polygon.prototype.getSortIndex = function getSortIndex () {\n return Geometry$$1.SORTINDEX_POLYGON\n };\n Polygon.prototype.getCoordinates = function getCoordinates () {\n var this$1 = this;\n\n if (this.isEmpty()) {\n return []\n }\n var coordinates = new Array(this.getNumPoints()).fill(null);\n var k = -1;\n var shellCoordinates = this._shell.getCoordinates();\n for (var x = 0; x < shellCoordinates.length; x++) {\n k++;\n coordinates[k] = shellCoordinates[x];\n }\n for (var i = 0; i < this._holes.length; i++) {\n var childCoordinates = this$1._holes[i].getCoordinates();\n for (var j = 0; j < childCoordinates.length; j++) {\n k++;\n coordinates[k] = childCoordinates[j];\n }\n }\n return coordinates\n };\n Polygon.prototype.getArea = function getArea () {\n var this$1 = this;\n\n var area = 0.0;\n area += Math.abs(CGAlgorithms.signedArea(this._shell.getCoordinateSequence()));\n for (var i = 0; i < this._holes.length; i++) {\n area -= Math.abs(CGAlgorithms.signedArea(this$1._holes[i].getCoordinateSequence()));\n }\n return area\n };\n Polygon.prototype.isRectangle = function isRectangle () {\n if (this.getNumInteriorRing() !== 0) { return false }\n if (this._shell === null) { return false }\n if (this._shell.getNumPoints() !== 5) { return false }\n var seq = this._shell.getCoordinateSequence();\n var env = this.getEnvelopeInternal();\n for (var i = 0; i < 5; i++) {\n var x = seq.getX(i);\n if (!(x === env.getMinX() || x === env.getMaxX())) { return false }\n var y = seq.getY(i);\n if (!(y === env.getMinY() || y === env.getMaxY())) { return false }\n }\n var prevX = seq.getX(0);\n var prevY = seq.getY(0);\n for (var i$1 = 1; i$1 <= 4; i$1++) {\n var x$1 = seq.getX(i$1);\n var y$1 = seq.getY(i$1);\n var xChanged = x$1 !== prevX;\n var yChanged = y$1 !== prevY;\n if (xChanged === yChanged) { return false }\n prevX = x$1;\n prevY = y$1;\n }\n return true\n };\n Polygon.prototype.equalsExact = function equalsExact () {\n var this$1 = this;\n\n if (arguments.length === 2) {\n var other = arguments[0];\n var tolerance = arguments[1];\n if (!this.isEquivalentClass(other)) {\n return false\n }\n var otherPolygon = other;\n var thisShell = this._shell;\n var otherPolygonShell = otherPolygon._shell;\n if (!thisShell.equalsExact(otherPolygonShell, tolerance)) {\n return false\n }\n if (this._holes.length !== otherPolygon._holes.length) {\n return false\n }\n for (var i = 0; i < this._holes.length; i++) {\n if (!this$1._holes[i].equalsExact(otherPolygon._holes[i], tolerance)) {\n return false\n }\n }\n return true\n } else { return Geometry$$1.prototype.equalsExact.apply(this, arguments) }\n };\n Polygon.prototype.normalize = function normalize () {\n var this$1 = this;\n\n if (arguments.length === 0) {\n this.normalize(this._shell, true);\n for (var i = 0; i < this._holes.length; i++) {\n this$1.normalize(this$1._holes[i], false);\n }\n Arrays.sort(this._holes);\n } else if (arguments.length === 2) {\n var ring = arguments[0];\n var clockwise = arguments[1];\n if (ring.isEmpty()) {\n return null\n }\n var uniqueCoordinates = new Array(ring.getCoordinates().length - 1).fill(null);\n System.arraycopy(ring.getCoordinates(), 0, uniqueCoordinates, 0, uniqueCoordinates.length);\n var minCoordinate = CoordinateArrays.minCoordinate(ring.getCoordinates());\n CoordinateArrays.scroll(uniqueCoordinates, minCoordinate);\n System.arraycopy(uniqueCoordinates, 0, ring.getCoordinates(), 0, uniqueCoordinates.length);\n ring.getCoordinates()[uniqueCoordinates.length] = uniqueCoordinates[0];\n if (CGAlgorithms.isCCW(ring.getCoordinates()) === clockwise) {\n CoordinateArrays.reverse(ring.getCoordinates());\n }\n }\n };\n Polygon.prototype.getCoordinate = function getCoordinate () {\n return this._shell.getCoordinate()\n };\n Polygon.prototype.getNumInteriorRing = function getNumInteriorRing () {\n return this._holes.length\n };\n Polygon.prototype.getBoundaryDimension = function getBoundaryDimension () {\n return 1\n };\n Polygon.prototype.getDimension = function getDimension () {\n return 2\n };\n Polygon.prototype.getLength = function getLength () {\n var this$1 = this;\n\n var len = 0.0;\n len += this._shell.getLength();\n for (var i = 0; i < this._holes.length; i++) {\n len += this$1._holes[i].getLength();\n }\n return len\n };\n Polygon.prototype.getNumPoints = function getNumPoints () {\n var this$1 = this;\n\n var numPoints = this._shell.getNumPoints();\n for (var i = 0; i < this._holes.length; i++) {\n numPoints += this$1._holes[i].getNumPoints();\n }\n return numPoints\n };\n Polygon.prototype.reverse = function reverse () {\n var this$1 = this;\n\n var poly = this.copy();\n poly._shell = this._shell.copy().reverse();\n poly._holes = new Array(this._holes.length).fill(null);\n for (var i = 0; i < this._holes.length; i++) {\n poly._holes[i] = this$1._holes[i].copy().reverse();\n }\n return poly\n };\n Polygon.prototype.convexHull = function convexHull () {\n return this.getExteriorRing().convexHull()\n };\n Polygon.prototype.compareToSameClass = function compareToSameClass () {\n var this$1 = this;\n\n if (arguments.length === 1) {\n var o = arguments[0];\n var thisShell = this._shell;\n var otherShell = o._shell;\n return thisShell.compareToSameClass(otherShell)\n } else if (arguments.length === 2) {\n var o$1 = arguments[0];\n var comp = arguments[1];\n var poly = o$1;\n var thisShell$1 = this._shell;\n var otherShell$1 = poly._shell;\n var shellComp = thisShell$1.compareToSameClass(otherShell$1, comp);\n if (shellComp !== 0) { return shellComp }\n var nHole1 = this.getNumInteriorRing();\n var nHole2 = poly.getNumInteriorRing();\n var i = 0;\n while (i < nHole1 && i < nHole2) {\n var thisHole = this$1.getInteriorRingN(i);\n var otherHole = poly.getInteriorRingN(i);\n var holeComp = thisHole.compareToSameClass(otherHole, comp);\n if (holeComp !== 0) { return holeComp }\n i++;\n }\n if (i < nHole1) { return 1 }\n if (i < nHole2) { return -1 }\n return 0\n }\n };\n Polygon.prototype.apply = function apply (filter) {\n var this$1 = this;\n\n if (hasInterface(filter, CoordinateFilter)) {\n this._shell.apply(filter);\n for (var i$1 = 0; i$1 < this._holes.length; i$1++) {\n this$1._holes[i$1].apply(filter);\n }\n } else if (hasInterface(filter, CoordinateSequenceFilter)) {\n this._shell.apply(filter);\n if (!filter.isDone()) {\n for (var i$2 = 0; i$2 < this._holes.length; i$2++) {\n this$1._holes[i$2].apply(filter);\n if (filter.isDone()) { break }\n }\n }\n if (filter.isGeometryChanged()) { this.geometryChanged(); }\n } else if (hasInterface(filter, GeometryFilter)) {\n filter.filter(this);\n } else if (hasInterface(filter, GeometryComponentFilter)) {\n filter.filter(this);\n this._shell.apply(filter);\n for (var i = 0; i < this._holes.length; i++) {\n this$1._holes[i].apply(filter);\n }\n }\n };\n Polygon.prototype.getBoundary = function getBoundary () {\n var this$1 = this;\n\n if (this.isEmpty()) {\n return this.getFactory().createMultiLineString()\n }\n var rings = new Array(this._holes.length + 1).fill(null);\n rings[0] = this._shell;\n for (var i = 0; i < this._holes.length; i++) {\n rings[i + 1] = this$1._holes[i];\n }\n if (rings.length <= 1) { return this.getFactory().createLinearRing(rings[0].getCoordinateSequence()) }\n return this.getFactory().createMultiLineString(rings)\n };\n Polygon.prototype.clone = function clone () {\n var this$1 = this;\n\n var poly = Geometry$$1.prototype.clone.call(this);\n poly._shell = this._shell.clone();\n poly._holes = new Array(this._holes.length).fill(null);\n for (var i = 0; i < this._holes.length; i++) {\n poly._holes[i] = this$1._holes[i].clone();\n }\n return poly\n };\n Polygon.prototype.getGeometryType = function getGeometryType () {\n return 'Polygon'\n };\n Polygon.prototype.copy = function copy () {\n var this$1 = this;\n\n var shell = this._shell.copy();\n var holes = new Array(this._holes.length).fill(null);\n for (var i = 0; i < holes.length; i++) {\n holes[i] = this$1._holes[i].copy();\n }\n return new Polygon(shell, holes, this._factory)\n };\n Polygon.prototype.getExteriorRing = function getExteriorRing () {\n return this._shell\n };\n Polygon.prototype.isEmpty = function isEmpty () {\n return this._shell.isEmpty()\n };\n Polygon.prototype.getInteriorRingN = function getInteriorRingN (n) {\n return this._holes[n]\n };\n Polygon.prototype.interfaces_ = function interfaces_ () {\n return [Polygonal]\n };\n Polygon.prototype.getClass = function getClass () {\n return Polygon\n };\n staticAccessors.serialVersionUID.get = function () { return -3494792200821764533 };\n\n Object.defineProperties( Polygon, staticAccessors );\n\n return Polygon;\n}(Geometry));\n\nvar MultiPoint = (function (GeometryCollection$$1) {\n function MultiPoint () {\n GeometryCollection$$1.apply(this, arguments);\n }\n\n if ( GeometryCollection$$1 ) MultiPoint.__proto__ = GeometryCollection$$1;\n MultiPoint.prototype = Object.create( GeometryCollection$$1 && GeometryCollection$$1.prototype );\n MultiPoint.prototype.constructor = MultiPoint;\n\n var staticAccessors = { serialVersionUID: { configurable: true } };\n\n MultiPoint.prototype.getSortIndex = function getSortIndex () {\n return Geometry.SORTINDEX_MULTIPOINT\n };\n MultiPoint.prototype.isValid = function isValid () {\n return true\n };\n MultiPoint.prototype.equalsExact = function equalsExact () {\n if (arguments.length === 2) {\n var other = arguments[0];\n var tolerance = arguments[1];\n if (!this.isEquivalentClass(other)) {\n return false\n }\n return GeometryCollection$$1.prototype.equalsExact.call(this, other, tolerance)\n } else { return GeometryCollection$$1.prototype.equalsExact.apply(this, arguments) }\n };\n MultiPoint.prototype.getCoordinate = function getCoordinate () {\n if (arguments.length === 1) {\n var n = arguments[0];\n return this._geometries[n].getCoordinate()\n } else { return GeometryCollection$$1.prototype.getCoordinate.apply(this, arguments) }\n };\n MultiPoint.prototype.getBoundaryDimension = function getBoundaryDimension () {\n return Dimension.FALSE\n };\n MultiPoint.prototype.getDimension = function getDimension () {\n return 0\n };\n MultiPoint.prototype.getBoundary = function getBoundary () {\n return this.getFactory().createGeometryCollection(null)\n };\n MultiPoint.prototype.getGeometryType = function getGeometryType () {\n return 'MultiPoint'\n };\n MultiPoint.prototype.copy = function copy () {\n var this$1 = this;\n\n var points = new Array(this._geometries.length).fill(null);\n for (var i = 0; i < points.length; i++) {\n points[i] = this$1._geometries[i].copy();\n }\n return new MultiPoint(points, this._factory)\n };\n MultiPoint.prototype.interfaces_ = function interfaces_ () {\n return [Puntal]\n };\n MultiPoint.prototype.getClass = function getClass () {\n return MultiPoint\n };\n staticAccessors.serialVersionUID.get = function () { return -8048474874175355449 };\n\n Object.defineProperties( MultiPoint, staticAccessors );\n\n return MultiPoint;\n}(GeometryCollection));\n\nvar LinearRing = (function (LineString$$1) {\n function LinearRing (points, factory) {\n if (points instanceof Coordinate && factory instanceof GeometryFactory) {\n points = factory.getCoordinateSequenceFactory().create(points);\n }\n LineString$$1.call(this, points, factory);\n this.validateConstruction();\n }\n\n if ( LineString$$1 ) LinearRing.__proto__ = LineString$$1;\n LinearRing.prototype = Object.create( LineString$$1 && LineString$$1.prototype );\n LinearRing.prototype.constructor = LinearRing;\n\n var staticAccessors = { MINIMUM_VALID_SIZE: { configurable: true },serialVersionUID: { configurable: true } };\n LinearRing.prototype.getSortIndex = function getSortIndex () {\n return Geometry.SORTINDEX_LINEARRING\n };\n LinearRing.prototype.getBoundaryDimension = function getBoundaryDimension () {\n return Dimension.FALSE\n };\n LinearRing.prototype.isClosed = function isClosed () {\n if (this.isEmpty()) {\n return true\n }\n return LineString$$1.prototype.isClosed.call(this)\n };\n LinearRing.prototype.reverse = function reverse () {\n var seq = this._points.copy();\n CoordinateSequences.reverse(seq);\n var rev = this.getFactory().createLinearRing(seq);\n return rev\n };\n LinearRing.prototype.validateConstruction = function validateConstruction () {\n if (!this.isEmpty() && !LineString$$1.prototype.isClosed.call(this)) {\n throw new IllegalArgumentException('Points of LinearRing do not form a closed linestring')\n }\n if (this.getCoordinateSequence().size() >= 1 && this.getCoordinateSequence().size() < LinearRing.MINIMUM_VALID_SIZE) {\n throw new IllegalArgumentException('Invalid number of points in LinearRing (found ' + this.getCoordinateSequence().size() + ' - must be 0 or >= 4)')\n }\n };\n LinearRing.prototype.getGeometryType = function getGeometryType () {\n return 'LinearRing'\n };\n LinearRing.prototype.copy = function copy () {\n return new LinearRing(this._points.copy(), this._factory)\n };\n LinearRing.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n LinearRing.prototype.getClass = function getClass () {\n return LinearRing\n };\n staticAccessors.MINIMUM_VALID_SIZE.get = function () { return 4 };\n staticAccessors.serialVersionUID.get = function () { return -4261142084085851829 };\n\n Object.defineProperties( LinearRing, staticAccessors );\n\n return LinearRing;\n}(LineString));\n\nvar MultiPolygon = (function (GeometryCollection$$1) {\n function MultiPolygon () {\n GeometryCollection$$1.apply(this, arguments);\n }\n\n if ( GeometryCollection$$1 ) MultiPolygon.__proto__ = GeometryCollection$$1;\n MultiPolygon.prototype = Object.create( GeometryCollection$$1 && GeometryCollection$$1.prototype );\n MultiPolygon.prototype.constructor = MultiPolygon;\n\n var staticAccessors = { serialVersionUID: { configurable: true } };\n\n MultiPolygon.prototype.getSortIndex = function getSortIndex () {\n return Geometry.SORTINDEX_MULTIPOLYGON\n };\n MultiPolygon.prototype.equalsExact = function equalsExact () {\n if (arguments.length === 2) {\n var other = arguments[0];\n var tolerance = arguments[1];\n if (!this.isEquivalentClass(other)) {\n return false\n }\n return GeometryCollection$$1.prototype.equalsExact.call(this, other, tolerance)\n } else { return GeometryCollection$$1.prototype.equalsExact.apply(this, arguments) }\n };\n MultiPolygon.prototype.getBoundaryDimension = function getBoundaryDimension () {\n return 1\n };\n MultiPolygon.prototype.getDimension = function getDimension () {\n return 2\n };\n MultiPolygon.prototype.reverse = function reverse () {\n var this$1 = this;\n\n var n = this._geometries.length;\n var revGeoms = new Array(n).fill(null);\n for (var i = 0; i < this._geometries.length; i++) {\n revGeoms[i] = this$1._geometries[i].reverse();\n }\n return this.getFactory().createMultiPolygon(revGeoms)\n };\n MultiPolygon.prototype.getBoundary = function getBoundary () {\n var this$1 = this;\n\n if (this.isEmpty()) {\n return this.getFactory().createMultiLineString()\n }\n var allRings = new ArrayList();\n for (var i = 0; i < this._geometries.length; i++) {\n var polygon = this$1._geometries[i];\n var rings = polygon.getBoundary();\n for (var j = 0; j < rings.getNumGeometries(); j++) {\n allRings.add(rings.getGeometryN(j));\n }\n }\n var allRingsArray = new Array(allRings.size()).fill(null);\n return this.getFactory().createMultiLineString(allRings.toArray(allRingsArray))\n };\n MultiPolygon.prototype.getGeometryType = function getGeometryType () {\n return 'MultiPolygon'\n };\n MultiPolygon.prototype.copy = function copy () {\n var this$1 = this;\n\n var polygons = new Array(this._geometries.length).fill(null);\n for (var i = 0; i < polygons.length; i++) {\n polygons[i] = this$1._geometries[i].copy();\n }\n return new MultiPolygon(polygons, this._factory)\n };\n MultiPolygon.prototype.interfaces_ = function interfaces_ () {\n return [Polygonal]\n };\n MultiPolygon.prototype.getClass = function getClass () {\n return MultiPolygon\n };\n staticAccessors.serialVersionUID.get = function () { return -551033529766975875 };\n\n Object.defineProperties( MultiPolygon, staticAccessors );\n\n return MultiPolygon;\n}(GeometryCollection));\n\nvar GeometryEditor = function GeometryEditor (factory) {\n this._factory = factory || null;\n this._isUserDataCopied = false;\n};\n\nvar staticAccessors$16 = { NoOpGeometryOperation: { configurable: true },CoordinateOperation: { configurable: true },CoordinateSequenceOperation: { configurable: true } };\nGeometryEditor.prototype.setCopyUserData = function setCopyUserData (isUserDataCopied) {\n this._isUserDataCopied = isUserDataCopied;\n};\nGeometryEditor.prototype.edit = function edit (geometry, operation) {\n if (geometry === null) { return null }\n var result = this.editInternal(geometry, operation);\n if (this._isUserDataCopied) {\n result.setUserData(geometry.getUserData());\n }\n return result\n};\nGeometryEditor.prototype.editInternal = function editInternal (geometry, operation) {\n if (this._factory === null) { this._factory = geometry.getFactory(); }\n if (geometry instanceof GeometryCollection) {\n return this.editGeometryCollection(geometry, operation)\n }\n if (geometry instanceof Polygon) {\n return this.editPolygon(geometry, operation)\n }\n if (geometry instanceof Point) {\n return operation.edit(geometry, this._factory)\n }\n if (geometry instanceof LineString) {\n return operation.edit(geometry, this._factory)\n }\n Assert.shouldNeverReachHere('Unsupported Geometry class: ' + geometry.getClass().getName());\n return null\n};\nGeometryEditor.prototype.editGeometryCollection = function editGeometryCollection (collection, operation) {\n var this$1 = this;\n\n var collectionForType = operation.edit(collection, this._factory);\n var geometries = new ArrayList();\n for (var i = 0; i < collectionForType.getNumGeometries(); i++) {\n var geometry = this$1.edit(collectionForType.getGeometryN(i), operation);\n if (geometry === null || geometry.isEmpty()) {\n continue\n }\n geometries.add(geometry);\n }\n if (collectionForType.getClass() === MultiPoint) {\n return this._factory.createMultiPoint(geometries.toArray([]))\n }\n if (collectionForType.getClass() === MultiLineString) {\n return this._factory.createMultiLineString(geometries.toArray([]))\n }\n if (collectionForType.getClass() === MultiPolygon) {\n return this._factory.createMultiPolygon(geometries.toArray([]))\n }\n return this._factory.createGeometryCollection(geometries.toArray([]))\n};\nGeometryEditor.prototype.editPolygon = function editPolygon (polygon, operation) {\n var this$1 = this;\n\n var newPolygon = operation.edit(polygon, this._factory);\n if (newPolygon === null) { newPolygon = this._factory.createPolygon(null); }\n if (newPolygon.isEmpty()) {\n return newPolygon\n }\n var shell = this.edit(newPolygon.getExteriorRing(), operation);\n if (shell === null || shell.isEmpty()) {\n return this._factory.createPolygon()\n }\n var holes = new ArrayList();\n for (var i = 0; i < newPolygon.getNumInteriorRing(); i++) {\n var hole = this$1.edit(newPolygon.getInteriorRingN(i), operation);\n if (hole === null || hole.isEmpty()) {\n continue\n }\n holes.add(hole);\n }\n return this._factory.createPolygon(shell, holes.toArray([]))\n};\nGeometryEditor.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nGeometryEditor.prototype.getClass = function getClass () {\n return GeometryEditor\n};\nGeometryEditor.GeometryEditorOperation = function GeometryEditorOperation () {};\nstaticAccessors$16.NoOpGeometryOperation.get = function () { return NoOpGeometryOperation };\nstaticAccessors$16.CoordinateOperation.get = function () { return CoordinateOperation };\nstaticAccessors$16.CoordinateSequenceOperation.get = function () { return CoordinateSequenceOperation };\n\nObject.defineProperties( GeometryEditor, staticAccessors$16 );\n\nvar NoOpGeometryOperation = function NoOpGeometryOperation () {};\n\nNoOpGeometryOperation.prototype.edit = function edit (geometry, factory) {\n return geometry\n};\nNoOpGeometryOperation.prototype.interfaces_ = function interfaces_ () {\n return [GeometryEditor.GeometryEditorOperation]\n};\nNoOpGeometryOperation.prototype.getClass = function getClass () {\n return NoOpGeometryOperation\n};\n\nvar CoordinateOperation = function CoordinateOperation () {};\n\nCoordinateOperation.prototype.edit = function edit (geometry, factory) {\n var coords = this.editCoordinates(geometry.getCoordinates(), geometry);\n if (coords === null) { return geometry }\n if (geometry instanceof LinearRing) {\n return factory.createLinearRing(coords)\n }\n if (geometry instanceof LineString) {\n return factory.createLineString(coords)\n }\n if (geometry instanceof Point) {\n if (coords.length > 0) {\n return factory.createPoint(coords[0])\n } else {\n return factory.createPoint()\n }\n }\n return geometry\n};\nCoordinateOperation.prototype.interfaces_ = function interfaces_ () {\n return [GeometryEditor.GeometryEditorOperation]\n};\nCoordinateOperation.prototype.getClass = function getClass () {\n return CoordinateOperation\n};\n\nvar CoordinateSequenceOperation = function CoordinateSequenceOperation () {};\n\nCoordinateSequenceOperation.prototype.edit = function edit (geometry, factory) {\n if (geometry instanceof LinearRing) {\n return factory.createLinearRing(this.edit(geometry.getCoordinateSequence(), geometry))\n }\n if (geometry instanceof LineString) {\n return factory.createLineString(this.edit(geometry.getCoordinateSequence(), geometry))\n }\n if (geometry instanceof Point) {\n return factory.createPoint(this.edit(geometry.getCoordinateSequence(), geometry))\n }\n return geometry\n};\nCoordinateSequenceOperation.prototype.interfaces_ = function interfaces_ () {\n return [GeometryEditor.GeometryEditorOperation]\n};\nCoordinateSequenceOperation.prototype.getClass = function getClass () {\n return CoordinateSequenceOperation\n};\n\nvar CoordinateArraySequence = function CoordinateArraySequence () {\n var this$1 = this;\n\n this._dimension = 3;\n this._coordinates = null;\n if (arguments.length === 1) {\n if (arguments[0] instanceof Array) {\n this._coordinates = arguments[0];\n this._dimension = 3;\n } else if (Number.isInteger(arguments[0])) {\n var size = arguments[0];\n this._coordinates = new Array(size).fill(null);\n for (var i = 0; i < size; i++) {\n this$1._coordinates[i] = new Coordinate();\n }\n } else if (hasInterface(arguments[0], CoordinateSequence)) {\n var coordSeq = arguments[0];\n if (coordSeq === null) {\n this._coordinates = new Array(0).fill(null);\n return null\n }\n this._dimension = coordSeq.getDimension();\n this._coordinates = new Array(coordSeq.size()).fill(null);\n for (var i$1 = 0; i$1 < this._coordinates.length; i$1++) {\n this$1._coordinates[i$1] = coordSeq.getCoordinateCopy(i$1);\n }\n }\n } else if (arguments.length === 2) {\n if (arguments[0] instanceof Array && Number.isInteger(arguments[1])) {\n var coordinates = arguments[0];\n var dimension = arguments[1];\n this._coordinates = coordinates;\n this._dimension = dimension;\n if (coordinates === null) { this._coordinates = new Array(0).fill(null); }\n } else if (Number.isInteger(arguments[0]) && Number.isInteger(arguments[1])) {\n var size$1 = arguments[0];\n var dimension$1 = arguments[1];\n this._coordinates = new Array(size$1).fill(null);\n this._dimension = dimension$1;\n for (var i$2 = 0; i$2 < size$1; i$2++) {\n this$1._coordinates[i$2] = new Coordinate();\n }\n }\n }\n};\n\nvar staticAccessors$18 = { serialVersionUID: { configurable: true } };\nCoordinateArraySequence.prototype.setOrdinate = function setOrdinate (index, ordinateIndex, value) {\n switch (ordinateIndex) {\n case CoordinateSequence.X:\n this._coordinates[index].x = value;\n break\n case CoordinateSequence.Y:\n this._coordinates[index].y = value;\n break\n case CoordinateSequence.Z:\n this._coordinates[index].z = value;\n break\n default:\n throw new IllegalArgumentException('invalid ordinateIndex')\n }\n};\nCoordinateArraySequence.prototype.size = function size () {\n return this._coordinates.length\n};\nCoordinateArraySequence.prototype.getOrdinate = function getOrdinate (index, ordinateIndex) {\n switch (ordinateIndex) {\n case CoordinateSequence.X:\n return this._coordinates[index].x\n case CoordinateSequence.Y:\n return this._coordinates[index].y\n case CoordinateSequence.Z:\n return this._coordinates[index].z\n default:\n }\n return Double.NaN\n};\nCoordinateArraySequence.prototype.getCoordinate = function getCoordinate () {\n if (arguments.length === 1) {\n var i = arguments[0];\n return this._coordinates[i]\n } else if (arguments.length === 2) {\n var index = arguments[0];\n var coord = arguments[1];\n coord.x = this._coordinates[index].x;\n coord.y = this._coordinates[index].y;\n coord.z = this._coordinates[index].z;\n }\n};\nCoordinateArraySequence.prototype.getCoordinateCopy = function getCoordinateCopy (i) {\n return new Coordinate(this._coordinates[i])\n};\nCoordinateArraySequence.prototype.getDimension = function getDimension () {\n return this._dimension\n};\nCoordinateArraySequence.prototype.getX = function getX (index) {\n return this._coordinates[index].x\n};\nCoordinateArraySequence.prototype.clone = function clone () {\n var this$1 = this;\n\n var cloneCoordinates = new Array(this.size()).fill(null);\n for (var i = 0; i < this._coordinates.length; i++) {\n cloneCoordinates[i] = this$1._coordinates[i].clone();\n }\n return new CoordinateArraySequence(cloneCoordinates, this._dimension)\n};\nCoordinateArraySequence.prototype.expandEnvelope = function expandEnvelope (env) {\n var this$1 = this;\n\n for (var i = 0; i < this._coordinates.length; i++) {\n env.expandToInclude(this$1._coordinates[i]);\n }\n return env\n};\nCoordinateArraySequence.prototype.copy = function copy () {\n var this$1 = this;\n\n var cloneCoordinates = new Array(this.size()).fill(null);\n for (var i = 0; i < this._coordinates.length; i++) {\n cloneCoordinates[i] = this$1._coordinates[i].copy();\n }\n return new CoordinateArraySequence(cloneCoordinates, this._dimension)\n};\nCoordinateArraySequence.prototype.toString = function toString () {\n var this$1 = this;\n\n if (this._coordinates.length > 0) {\n var strBuf = new StringBuffer(17 * this._coordinates.length);\n strBuf.append('(');\n strBuf.append(this._coordinates[0]);\n for (var i = 1; i < this._coordinates.length; i++) {\n strBuf.append(', ');\n strBuf.append(this$1._coordinates[i]);\n }\n strBuf.append(')');\n return strBuf.toString()\n } else {\n return '()'\n }\n};\nCoordinateArraySequence.prototype.getY = function getY (index) {\n return this._coordinates[index].y\n};\nCoordinateArraySequence.prototype.toCoordinateArray = function toCoordinateArray () {\n return this._coordinates\n};\nCoordinateArraySequence.prototype.interfaces_ = function interfaces_ () {\n return [CoordinateSequence, Serializable]\n};\nCoordinateArraySequence.prototype.getClass = function getClass () {\n return CoordinateArraySequence\n};\nstaticAccessors$18.serialVersionUID.get = function () { return -915438501601840650 };\n\nObject.defineProperties( CoordinateArraySequence, staticAccessors$18 );\n\nvar CoordinateArraySequenceFactory = function CoordinateArraySequenceFactory () {};\n\nvar staticAccessors$17 = { serialVersionUID: { configurable: true },instanceObject: { configurable: true } };\n\nCoordinateArraySequenceFactory.prototype.readResolve = function readResolve () {\n return CoordinateArraySequenceFactory.instance()\n};\nCoordinateArraySequenceFactory.prototype.create = function create () {\n if (arguments.length === 1) {\n if (arguments[0] instanceof Array) {\n var coordinates = arguments[0];\n return new CoordinateArraySequence(coordinates)\n } else if (hasInterface(arguments[0], CoordinateSequence)) {\n var coordSeq = arguments[0];\n return new CoordinateArraySequence(coordSeq)\n }\n } else if (arguments.length === 2) {\n var size = arguments[0];\n var dimension = arguments[1];\n if (dimension > 3) { dimension = 3; }\n if (dimension < 2) { return new CoordinateArraySequence(size) }\n return new CoordinateArraySequence(size, dimension)\n }\n};\nCoordinateArraySequenceFactory.prototype.interfaces_ = function interfaces_ () {\n return [CoordinateSequenceFactory, Serializable]\n};\nCoordinateArraySequenceFactory.prototype.getClass = function getClass () {\n return CoordinateArraySequenceFactory\n};\nCoordinateArraySequenceFactory.instance = function instance () {\n return CoordinateArraySequenceFactory.instanceObject\n};\n\nstaticAccessors$17.serialVersionUID.get = function () { return -4099577099607551657 };\nstaticAccessors$17.instanceObject.get = function () { return new CoordinateArraySequenceFactory() };\n\nObject.defineProperties( CoordinateArraySequenceFactory, staticAccessors$17 );\n\n/**\n * @see http://download.oracle.com/javase/6/docs/api/java/util/HashMap.html\n *\n * @extends {javascript.util.Map}\n * @constructor\n * @private\n */\nvar HashMap = (function (MapInterface) {\n function HashMap () {\n MapInterface.call(this);\n this.map_ = new Map();\n }\n\n if ( MapInterface ) HashMap.__proto__ = MapInterface;\n HashMap.prototype = Object.create( MapInterface && MapInterface.prototype );\n HashMap.prototype.constructor = HashMap;\n /**\n * @override\n */\n HashMap.prototype.get = function get (key) {\n return this.map_.get(key) || null\n };\n\n /**\n * @override\n */\n HashMap.prototype.put = function put (key, value) {\n this.map_.set(key, value);\n return value\n };\n\n /**\n * @override\n */\n HashMap.prototype.values = function values () {\n var arrayList = new ArrayList();\n var it = this.map_.values();\n var o = it.next();\n while (!o.done) {\n arrayList.add(o.value);\n o = it.next();\n }\n return arrayList\n };\n\n /**\n * @override\n */\n HashMap.prototype.entrySet = function entrySet () {\n var hashSet = new HashSet();\n this.map_.entries().forEach(function (entry) { return hashSet.add(entry); });\n return hashSet\n };\n\n /**\n * @override\n */\n HashMap.prototype.size = function size () {\n return this.map_.size()\n };\n\n return HashMap;\n}(Map$1));\n\nvar PrecisionModel = function PrecisionModel () {\n this._modelType = null;\n this._scale = null;\n if (arguments.length === 0) {\n this._modelType = PrecisionModel.FLOATING;\n } else if (arguments.length === 1) {\n if (arguments[0] instanceof Type) {\n var modelType = arguments[0];\n this._modelType = modelType;\n if (modelType === PrecisionModel.FIXED) {\n this.setScale(1.0);\n }\n } else if (typeof arguments[0] === 'number') {\n var scale = arguments[0];\n this._modelType = PrecisionModel.FIXED;\n this.setScale(scale);\n } else if (arguments[0] instanceof PrecisionModel) {\n var pm = arguments[0];\n this._modelType = pm._modelType;\n this._scale = pm._scale;\n }\n }\n};\n\nvar staticAccessors$19 = { serialVersionUID: { configurable: true },maximumPreciseValue: { configurable: true } };\nPrecisionModel.prototype.equals = function equals (other) {\n if (!(other instanceof PrecisionModel)) {\n return false\n }\n var otherPrecisionModel = other;\n return this._modelType === otherPrecisionModel._modelType && this._scale === otherPrecisionModel._scale\n};\nPrecisionModel.prototype.compareTo = function compareTo (o) {\n var other = o;\n var sigDigits = this.getMaximumSignificantDigits();\n var otherSigDigits = other.getMaximumSignificantDigits();\n return new Integer(sigDigits).compareTo(new Integer(otherSigDigits))\n};\nPrecisionModel.prototype.getScale = function getScale () {\n return this._scale\n};\nPrecisionModel.prototype.isFloating = function isFloating () {\n return this._modelType === PrecisionModel.FLOATING || this._modelType === PrecisionModel.FLOATING_SINGLE\n};\nPrecisionModel.prototype.getType = function getType () {\n return this._modelType\n};\nPrecisionModel.prototype.toString = function toString () {\n var description = 'UNKNOWN';\n if (this._modelType === PrecisionModel.FLOATING) {\n description = 'Floating';\n } else if (this._modelType === PrecisionModel.FLOATING_SINGLE) {\n description = 'Floating-Single';\n } else if (this._modelType === PrecisionModel.FIXED) {\n description = 'Fixed (Scale=' + this.getScale() + ')';\n }\n return description\n};\nPrecisionModel.prototype.makePrecise = function makePrecise () {\n if (typeof arguments[0] === 'number') {\n var val = arguments[0];\n if (Double.isNaN(val)) { return val }\n if (this._modelType === PrecisionModel.FLOATING_SINGLE) {\n var floatSingleVal = val;\n return floatSingleVal\n }\n if (this._modelType === PrecisionModel.FIXED) {\n return Math.round(val * this._scale) / this._scale\n }\n return val\n } else if (arguments[0] instanceof Coordinate) {\n var coord = arguments[0];\n if (this._modelType === PrecisionModel.FLOATING) { return null }\n coord.x = this.makePrecise(coord.x);\n coord.y = this.makePrecise(coord.y);\n }\n};\nPrecisionModel.prototype.getMaximumSignificantDigits = function getMaximumSignificantDigits () {\n var maxSigDigits = 16;\n if (this._modelType === PrecisionModel.FLOATING) {\n maxSigDigits = 16;\n } else if (this._modelType === PrecisionModel.FLOATING_SINGLE) {\n maxSigDigits = 6;\n } else if (this._modelType === PrecisionModel.FIXED) {\n maxSigDigits = 1 + Math.trunc(Math.ceil(Math.log(this.getScale()) / Math.log(10)));\n }\n return maxSigDigits\n};\nPrecisionModel.prototype.setScale = function setScale (scale) {\n this._scale = Math.abs(scale);\n};\nPrecisionModel.prototype.interfaces_ = function interfaces_ () {\n return [Serializable, Comparable]\n};\nPrecisionModel.prototype.getClass = function getClass () {\n return PrecisionModel\n};\nPrecisionModel.mostPrecise = function mostPrecise (pm1, pm2) {\n if (pm1.compareTo(pm2) >= 0) { return pm1 }\n return pm2\n};\nstaticAccessors$19.serialVersionUID.get = function () { return 7777263578777803835 };\nstaticAccessors$19.maximumPreciseValue.get = function () { return 9007199254740992.0 };\n\nObject.defineProperties( PrecisionModel, staticAccessors$19 );\n\nvar Type = function Type (name) {\n this._name = name || null;\n Type.nameToTypeMap.put(name, this);\n};\n\nvar staticAccessors$1$1 = { serialVersionUID: { configurable: true },nameToTypeMap: { configurable: true } };\nType.prototype.readResolve = function readResolve () {\n return Type.nameToTypeMap.get(this._name)\n};\nType.prototype.toString = function toString () {\n return this._name\n};\nType.prototype.interfaces_ = function interfaces_ () {\n return [Serializable]\n};\nType.prototype.getClass = function getClass () {\n return Type\n};\nstaticAccessors$1$1.serialVersionUID.get = function () { return -5528602631731589822 };\nstaticAccessors$1$1.nameToTypeMap.get = function () { return new HashMap() };\n\nObject.defineProperties( Type, staticAccessors$1$1 );\n\nPrecisionModel.Type = Type;\nPrecisionModel.FIXED = new Type('FIXED');\nPrecisionModel.FLOATING = new Type('FLOATING');\nPrecisionModel.FLOATING_SINGLE = new Type('FLOATING SINGLE');\n\nvar GeometryFactory = function GeometryFactory () {\n this._precisionModel = new PrecisionModel();\n this._SRID = 0;\n this._coordinateSequenceFactory = GeometryFactory.getDefaultCoordinateSequenceFactory();\n\n if (arguments.length === 0) {\n } else if (arguments.length === 1) {\n if (hasInterface(arguments[0], CoordinateSequenceFactory)) {\n this._coordinateSequenceFactory = arguments[0];\n } else if (arguments[0] instanceof PrecisionModel) {\n this._precisionModel = arguments[0];\n }\n } else if (arguments.length === 2) {\n this._precisionModel = arguments[0];\n this._SRID = arguments[1];\n } else if (arguments.length === 3) {\n this._precisionModel = arguments[0];\n this._SRID = arguments[1];\n this._coordinateSequenceFactory = arguments[2];\n }\n};\n\nvar staticAccessors$2 = { serialVersionUID: { configurable: true } };\nGeometryFactory.prototype.toGeometry = function toGeometry (envelope) {\n if (envelope.isNull()) {\n return this.createPoint(null)\n }\n if (envelope.getMinX() === envelope.getMaxX() && envelope.getMinY() === envelope.getMaxY()) {\n return this.createPoint(new Coordinate(envelope.getMinX(), envelope.getMinY()))\n }\n if (envelope.getMinX() === envelope.getMaxX() || envelope.getMinY() === envelope.getMaxY()) {\n return this.createLineString([new Coordinate(envelope.getMinX(), envelope.getMinY()), new Coordinate(envelope.getMaxX(), envelope.getMaxY())])\n }\n return this.createPolygon(this.createLinearRing([new Coordinate(envelope.getMinX(), envelope.getMinY()), new Coordinate(envelope.getMinX(), envelope.getMaxY()), new Coordinate(envelope.getMaxX(), envelope.getMaxY()), new Coordinate(envelope.getMaxX(), envelope.getMinY()), new Coordinate(envelope.getMinX(), envelope.getMinY())]), null)\n};\nGeometryFactory.prototype.createLineString = function createLineString (coordinates) {\n if (!coordinates) { return new LineString(this.getCoordinateSequenceFactory().create([]), this) }\n else if (coordinates instanceof Array) { return new LineString(this.getCoordinateSequenceFactory().create(coordinates), this) }\n else if (hasInterface(coordinates, CoordinateSequence)) { return new LineString(coordinates, this) }\n};\nGeometryFactory.prototype.createMultiLineString = function createMultiLineString () {\n if (arguments.length === 0) {\n return new MultiLineString(null, this)\n } else if (arguments.length === 1) {\n var lineStrings = arguments[0];\n return new MultiLineString(lineStrings, this)\n }\n};\nGeometryFactory.prototype.buildGeometry = function buildGeometry (geomList) {\n var geomClass = null;\n var isHeterogeneous = false;\n var hasGeometryCollection = false;\n for (var i = geomList.iterator(); i.hasNext();) {\n var geom = i.next();\n var partClass = geom.getClass();\n if (geomClass === null) {\n geomClass = partClass;\n }\n if (partClass !== geomClass) {\n isHeterogeneous = true;\n }\n if (geom.isGeometryCollectionOrDerived()) { hasGeometryCollection = true; }\n }\n if (geomClass === null) {\n return this.createGeometryCollection()\n }\n if (isHeterogeneous || hasGeometryCollection) {\n return this.createGeometryCollection(GeometryFactory.toGeometryArray(geomList))\n }\n var geom0 = geomList.iterator().next();\n var isCollection = geomList.size() > 1;\n if (isCollection) {\n if (geom0 instanceof Polygon) {\n return this.createMultiPolygon(GeometryFactory.toPolygonArray(geomList))\n } else if (geom0 instanceof LineString) {\n return this.createMultiLineString(GeometryFactory.toLineStringArray(geomList))\n } else if (geom0 instanceof Point) {\n return this.createMultiPoint(GeometryFactory.toPointArray(geomList))\n }\n Assert.shouldNeverReachHere('Unhandled class: ' + geom0.getClass().getName());\n }\n return geom0\n};\nGeometryFactory.prototype.createMultiPointFromCoords = function createMultiPointFromCoords (coordinates) {\n return this.createMultiPoint(coordinates !== null ? this.getCoordinateSequenceFactory().create(coordinates) : null)\n};\nGeometryFactory.prototype.createPoint = function createPoint () {\n if (arguments.length === 0) {\n return this.createPoint(this.getCoordinateSequenceFactory().create([]))\n } else if (arguments.length === 1) {\n if (arguments[0] instanceof Coordinate) {\n var coordinate = arguments[0];\n return this.createPoint(coordinate !== null ? this.getCoordinateSequenceFactory().create([coordinate]) : null)\n } else if (hasInterface(arguments[0], CoordinateSequence)) {\n var coordinates = arguments[0];\n return new Point(coordinates, this)\n }\n }\n};\nGeometryFactory.prototype.getCoordinateSequenceFactory = function getCoordinateSequenceFactory () {\n return this._coordinateSequenceFactory\n};\nGeometryFactory.prototype.createPolygon = function createPolygon () {\n if (arguments.length === 0) {\n return new Polygon(null, null, this)\n } else if (arguments.length === 1) {\n if (hasInterface(arguments[0], CoordinateSequence)) {\n var coordinates = arguments[0];\n return this.createPolygon(this.createLinearRing(coordinates))\n } else if (arguments[0] instanceof Array) {\n var coordinates$1 = arguments[0];\n return this.createPolygon(this.createLinearRing(coordinates$1))\n } else if (arguments[0] instanceof LinearRing) {\n var shell = arguments[0];\n return this.createPolygon(shell, null)\n }\n } else if (arguments.length === 2) {\n var shell$1 = arguments[0];\n var holes = arguments[1];\n return new Polygon(shell$1, holes, this)\n }\n};\nGeometryFactory.prototype.getSRID = function getSRID () {\n return this._SRID\n};\nGeometryFactory.prototype.createGeometryCollection = function createGeometryCollection () {\n if (arguments.length === 0) {\n return new GeometryCollection(null, this)\n } else if (arguments.length === 1) {\n var geometries = arguments[0];\n return new GeometryCollection(geometries, this)\n }\n};\nGeometryFactory.prototype.createGeometry = function createGeometry (g) {\n var editor = new GeometryEditor(this);\n return editor.edit(g, {\n edit: function () {\n if (arguments.length === 2) {\n var coordSeq = arguments[0];\n // const geometry = arguments[1]\n return this._coordinateSequenceFactory.create(coordSeq)\n }\n }\n })\n};\nGeometryFactory.prototype.getPrecisionModel = function getPrecisionModel () {\n return this._precisionModel\n};\nGeometryFactory.prototype.createLinearRing = function createLinearRing () {\n if (arguments.length === 0) {\n return this.createLinearRing(this.getCoordinateSequenceFactory().create([]))\n } else if (arguments.length === 1) {\n if (arguments[0] instanceof Array) {\n var coordinates = arguments[0];\n return this.createLinearRing(coordinates !== null ? this.getCoordinateSequenceFactory().create(coordinates) : null)\n } else if (hasInterface(arguments[0], CoordinateSequence)) {\n var coordinates$1 = arguments[0];\n return new LinearRing(coordinates$1, this)\n }\n }\n};\nGeometryFactory.prototype.createMultiPolygon = function createMultiPolygon () {\n if (arguments.length === 0) {\n return new MultiPolygon(null, this)\n } else if (arguments.length === 1) {\n var polygons = arguments[0];\n return new MultiPolygon(polygons, this)\n }\n};\nGeometryFactory.prototype.createMultiPoint = function createMultiPoint () {\n var this$1 = this;\n\n if (arguments.length === 0) {\n return new MultiPoint(null, this)\n } else if (arguments.length === 1) {\n if (arguments[0] instanceof Array) {\n var point = arguments[0];\n return new MultiPoint(point, this)\n } else if (arguments[0] instanceof Array) {\n var coordinates = arguments[0];\n return this.createMultiPoint(coordinates !== null ? this.getCoordinateSequenceFactory().create(coordinates) : null)\n } else if (hasInterface(arguments[0], CoordinateSequence)) {\n var coordinates$1 = arguments[0];\n if (coordinates$1 === null) {\n return this.createMultiPoint(new Array(0).fill(null))\n }\n var points = new Array(coordinates$1.size()).fill(null);\n for (var i = 0; i < coordinates$1.size(); i++) {\n var ptSeq = this$1.getCoordinateSequenceFactory().create(1, coordinates$1.getDimension());\n CoordinateSequences.copy(coordinates$1, i, ptSeq, 0, 1);\n points[i] = this$1.createPoint(ptSeq);\n }\n return this.createMultiPoint(points)\n }\n }\n};\nGeometryFactory.prototype.interfaces_ = function interfaces_ () {\n return [Serializable]\n};\nGeometryFactory.prototype.getClass = function getClass () {\n return GeometryFactory\n};\nGeometryFactory.toMultiPolygonArray = function toMultiPolygonArray (multiPolygons) {\n var multiPolygonArray = new Array(multiPolygons.size()).fill(null);\n return multiPolygons.toArray(multiPolygonArray)\n};\nGeometryFactory.toGeometryArray = function toGeometryArray (geometries) {\n if (geometries === null) { return null }\n var geometryArray = new Array(geometries.size()).fill(null);\n return geometries.toArray(geometryArray)\n};\nGeometryFactory.getDefaultCoordinateSequenceFactory = function getDefaultCoordinateSequenceFactory () {\n return CoordinateArraySequenceFactory.instance()\n};\nGeometryFactory.toMultiLineStringArray = function toMultiLineStringArray (multiLineStrings) {\n var multiLineStringArray = new Array(multiLineStrings.size()).fill(null);\n return multiLineStrings.toArray(multiLineStringArray)\n};\nGeometryFactory.toLineStringArray = function toLineStringArray (lineStrings) {\n var lineStringArray = new Array(lineStrings.size()).fill(null);\n return lineStrings.toArray(lineStringArray)\n};\nGeometryFactory.toMultiPointArray = function toMultiPointArray (multiPoints) {\n var multiPointArray = new Array(multiPoints.size()).fill(null);\n return multiPoints.toArray(multiPointArray)\n};\nGeometryFactory.toLinearRingArray = function toLinearRingArray (linearRings) {\n var linearRingArray = new Array(linearRings.size()).fill(null);\n return linearRings.toArray(linearRingArray)\n};\nGeometryFactory.toPointArray = function toPointArray (points) {\n var pointArray = new Array(points.size()).fill(null);\n return points.toArray(pointArray)\n};\nGeometryFactory.toPolygonArray = function toPolygonArray (polygons) {\n var polygonArray = new Array(polygons.size()).fill(null);\n return polygons.toArray(polygonArray)\n};\nGeometryFactory.createPointFromInternalCoord = function createPointFromInternalCoord (coord, exemplar) {\n exemplar.getPrecisionModel().makePrecise(coord);\n return exemplar.getFactory().createPoint(coord)\n};\nstaticAccessors$2.serialVersionUID.get = function () { return -6820524753094095635 };\n\nObject.defineProperties( GeometryFactory, staticAccessors$2 );\n\nvar geometryTypes = ['Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon'];\n\n/**\n * Class for reading and writing Well-Known Text.Create a new parser for GeoJSON\n * NOTE: Adapted from OpenLayers 2.11 implementation.\n */\n\n/**\n * Create a new parser for GeoJSON\n *\n * @param {GeometryFactory} geometryFactory\n * @return An instance of GeoJsonParser.\n * @constructor\n * @private\n */\nvar GeoJSONParser = function GeoJSONParser (geometryFactory) {\n this.geometryFactory = geometryFactory || new GeometryFactory();\n};\n/**\n * Deserialize a GeoJSON object and return the Geometry or Feature(Collection) with JSTS Geometries\n *\n * @param {}\n * A GeoJSON object.\n * @return {} A Geometry instance or object representing a Feature(Collection) with Geometry instances.\n * @private\n */\nGeoJSONParser.prototype.read = function read (json) {\n var obj;\n if (typeof json === 'string') {\n obj = JSON.parse(json);\n } else {\n obj = json;\n }\n\n var type = obj.type;\n\n if (!parse[type]) {\n throw new Error('Unknown GeoJSON type: ' + obj.type)\n }\n\n if (geometryTypes.indexOf(type) !== -1) {\n return parse[type].apply(this, [obj.coordinates])\n } else if (type === 'GeometryCollection') {\n return parse[type].apply(this, [obj.geometries])\n }\n\n // feature or feature collection\n return parse[type].apply(this, [obj])\n};\n\n/**\n * Serialize a Geometry object into GeoJSON\n *\n * @param {Geometry}\n * geometry A Geometry or array of Geometries.\n * @return {Object} A GeoJSON object represting the input Geometry/Geometries.\n * @private\n */\nGeoJSONParser.prototype.write = function write (geometry) {\n var type = geometry.getGeometryType();\n\n if (!extract[type]) {\n throw new Error('Geometry is not supported')\n }\n\n return extract[type].apply(this, [geometry])\n};\n\nvar parse = {\n /**\n * Parse a GeoJSON Feature object\n *\n * @param {Object}\n * obj Object to parse.\n *\n * @return {Object} Feature with geometry/bbox converted to JSTS Geometries.\n */\n Feature: function (obj) {\n var feature = {};\n\n // copy features\n for (var key in obj) {\n feature[key] = obj[key];\n }\n\n // parse geometry\n if (obj.geometry) {\n var type = obj.geometry.type;\n if (!parse[type]) {\n throw new Error('Unknown GeoJSON type: ' + obj.type)\n }\n feature.geometry = this.read(obj.geometry);\n }\n\n // bbox\n if (obj.bbox) {\n feature.bbox = parse.bbox.apply(this, [obj.bbox]);\n }\n\n return feature\n },\n\n /**\n * Parse a GeoJSON FeatureCollection object\n *\n * @param {Object}\n * obj Object to parse.\n *\n * @return {Object} FeatureCollection with geometry/bbox converted to JSTS Geometries.\n */\n FeatureCollection: function (obj) {\n var this$1 = this;\n\n var featureCollection = {};\n\n if (obj.features) {\n featureCollection.features = [];\n\n for (var i = 0; i < obj.features.length; ++i) {\n featureCollection.features.push(this$1.read(obj.features[i]));\n }\n }\n\n if (obj.bbox) {\n featureCollection.bbox = this.parse.bbox.apply(this, [obj.bbox]);\n }\n\n return featureCollection\n },\n\n /**\n * Convert the ordinates in an array to an array of Coordinates\n *\n * @param {Array}\n * array Array with {Number}s.\n *\n * @return {Array} Array with Coordinates.\n */\n coordinates: function (array) {\n var coordinates = [];\n for (var i = 0; i < array.length; ++i) {\n var sub = array[i];\n coordinates.push(new Coordinate(sub[0], sub[1]));\n }\n return coordinates\n },\n\n /**\n * Convert the bbox to a LinearRing\n *\n * @param {Array}\n * array Array with [xMin, yMin, xMax, yMax].\n *\n * @return {Array} Array with Coordinates.\n */\n bbox: function (array) {\n return this.geometryFactory.createLinearRing([\n new Coordinate(array[0], array[1]),\n new Coordinate(array[2], array[1]),\n new Coordinate(array[2], array[3]),\n new Coordinate(array[0], array[3]),\n new Coordinate(array[0], array[1])\n ])\n },\n\n /**\n * Convert an Array with ordinates to a Point\n *\n * @param {Array}\n * array Array with ordinates.\n *\n * @return {Point} Point.\n */\n Point: function (array) {\n var coordinate = new Coordinate(array[0], array[1]);\n return this.geometryFactory.createPoint(coordinate)\n },\n\n /**\n * Convert an Array with coordinates to a MultiPoint\n *\n * @param {Array}\n * array Array with coordinates.\n *\n * @return {MultiPoint} MultiPoint.\n */\n MultiPoint: function (array) {\n var this$1 = this;\n\n var points = [];\n for (var i = 0; i < array.length; ++i) {\n points.push(parse.Point.apply(this$1, [array[i]]));\n }\n return this.geometryFactory.createMultiPoint(points)\n },\n\n /**\n * Convert an Array with coordinates to a LineString\n *\n * @param {Array}\n * array Array with coordinates.\n *\n * @return {LineString} LineString.\n */\n LineString: function (array) {\n var coordinates = parse.coordinates.apply(this, [array]);\n return this.geometryFactory.createLineString(coordinates)\n },\n\n /**\n * Convert an Array with coordinates to a MultiLineString\n *\n * @param {Array}\n * array Array with coordinates.\n *\n * @return {MultiLineString} MultiLineString.\n */\n MultiLineString: function (array) {\n var this$1 = this;\n\n var lineStrings = [];\n for (var i = 0; i < array.length; ++i) {\n lineStrings.push(parse.LineString.apply(this$1, [array[i]]));\n }\n return this.geometryFactory.createMultiLineString(lineStrings)\n },\n\n /**\n * Convert an Array to a Polygon\n *\n * @param {Array}\n * array Array with shell and holes.\n *\n * @return {Polygon} Polygon.\n */\n Polygon: function (array) {\n var this$1 = this;\n\n var shellCoordinates = parse.coordinates.apply(this, [array[0]]);\n var shell = this.geometryFactory.createLinearRing(shellCoordinates);\n var holes = [];\n for (var i = 1; i < array.length; ++i) {\n var hole = array[i];\n var coordinates = parse.coordinates.apply(this$1, [hole]);\n var linearRing = this$1.geometryFactory.createLinearRing(coordinates);\n holes.push(linearRing);\n }\n return this.geometryFactory.createPolygon(shell, holes)\n },\n\n /**\n * Convert an Array to a MultiPolygon\n *\n * @param {Array}\n * array Array of arrays with shell and rings.\n *\n * @return {MultiPolygon} MultiPolygon.\n */\n MultiPolygon: function (array) {\n var this$1 = this;\n\n var polygons = [];\n for (var i = 0; i < array.length; ++i) {\n var polygon = array[i];\n polygons.push(parse.Polygon.apply(this$1, [polygon]));\n }\n return this.geometryFactory.createMultiPolygon(polygons)\n },\n\n /**\n * Convert an Array to a GeometryCollection\n *\n * @param {Array}\n * array Array of GeoJSON geometries.\n *\n * @return {GeometryCollection} GeometryCollection.\n */\n GeometryCollection: function (array) {\n var this$1 = this;\n\n var geometries = [];\n for (var i = 0; i < array.length; ++i) {\n var geometry = array[i];\n geometries.push(this$1.read(geometry));\n }\n return this.geometryFactory.createGeometryCollection(geometries)\n }\n};\n\nvar extract = {\n /**\n * Convert a Coordinate to an Array\n *\n * @param {Coordinate}\n * coordinate Coordinate to convert.\n *\n * @return {Array} Array of ordinates.\n */\n coordinate: function (coordinate) {\n return [coordinate.x, coordinate.y]\n },\n\n /**\n * Convert a Point to a GeoJSON object\n *\n * @param {Point}\n * point Point to convert.\n *\n * @return {Array} Array of 2 ordinates (paired to a coordinate).\n */\n Point: function (point) {\n var array = extract.coordinate.apply(this, [point.getCoordinate()]);\n return {\n type: 'Point',\n coordinates: array\n }\n },\n\n /**\n * Convert a MultiPoint to a GeoJSON object\n *\n * @param {MultiPoint}\n * multipoint MultiPoint to convert.\n *\n * @return {Array} Array of coordinates.\n */\n MultiPoint: function (multipoint) {\n var this$1 = this;\n\n var array = [];\n for (var i = 0; i < multipoint._geometries.length; ++i) {\n var point = multipoint._geometries[i];\n var geoJson = extract.Point.apply(this$1, [point]);\n array.push(geoJson.coordinates);\n }\n return {\n type: 'MultiPoint',\n coordinates: array\n }\n },\n\n /**\n * Convert a LineString to a GeoJSON object\n *\n * @param {LineString}\n * linestring LineString to convert.\n *\n * @return {Array} Array of coordinates.\n */\n LineString: function (linestring) {\n var this$1 = this;\n\n var array = [];\n var coordinates = linestring.getCoordinates();\n for (var i = 0; i < coordinates.length; ++i) {\n var coordinate = coordinates[i];\n array.push(extract.coordinate.apply(this$1, [coordinate]));\n }\n return {\n type: 'LineString',\n coordinates: array\n }\n },\n\n /**\n * Convert a MultiLineString to a GeoJSON object\n *\n * @param {MultiLineString}\n * multilinestring MultiLineString to convert.\n *\n * @return {Array} Array of Array of coordinates.\n */\n MultiLineString: function (multilinestring) {\n var this$1 = this;\n\n var array = [];\n for (var i = 0; i < multilinestring._geometries.length; ++i) {\n var linestring = multilinestring._geometries[i];\n var geoJson = extract.LineString.apply(this$1, [linestring]);\n array.push(geoJson.coordinates);\n }\n return {\n type: 'MultiLineString',\n coordinates: array\n }\n },\n\n /**\n * Convert a Polygon to a GeoJSON object\n *\n * @param {Polygon}\n * polygon Polygon to convert.\n *\n * @return {Array} Array with shell, holes.\n */\n Polygon: function (polygon) {\n var this$1 = this;\n\n var array = [];\n var shellGeoJson = extract.LineString.apply(this, [polygon._shell]);\n array.push(shellGeoJson.coordinates);\n for (var i = 0; i < polygon._holes.length; ++i) {\n var hole = polygon._holes[i];\n var holeGeoJson = extract.LineString.apply(this$1, [hole]);\n array.push(holeGeoJson.coordinates);\n }\n return {\n type: 'Polygon',\n coordinates: array\n }\n },\n\n /**\n * Convert a MultiPolygon to a GeoJSON object\n *\n * @param {MultiPolygon}\n * multipolygon MultiPolygon to convert.\n *\n * @return {Array} Array of polygons.\n */\n MultiPolygon: function (multipolygon) {\n var this$1 = this;\n\n var array = [];\n for (var i = 0; i < multipolygon._geometries.length; ++i) {\n var polygon = multipolygon._geometries[i];\n var geoJson = extract.Polygon.apply(this$1, [polygon]);\n array.push(geoJson.coordinates);\n }\n return {\n type: 'MultiPolygon',\n coordinates: array\n }\n },\n\n /**\n * Convert a GeometryCollection to a GeoJSON object\n *\n * @param {GeometryCollection}\n * collection GeometryCollection to convert.\n *\n * @return {Array} Array of geometries.\n */\n GeometryCollection: function (collection) {\n var this$1 = this;\n\n var array = [];\n for (var i = 0; i < collection._geometries.length; ++i) {\n var geometry = collection._geometries[i];\n var type = geometry.getGeometryType();\n array.push(extract[type].apply(this$1, [geometry]));\n }\n return {\n type: 'GeometryCollection',\n geometries: array\n }\n }\n};\n\n/**\n * Converts a geometry in GeoJSON to a {@link Geometry}.\n */\n\n/**\n * A GeoJSONReader
is parameterized by a GeometryFactory
,\n * to allow it to create Geometry
objects of the appropriate\n * implementation. In particular, the GeometryFactory
determines\n * the PrecisionModel
and SRID
that is used.\n *\n * @param {GeometryFactory} geometryFactory\n * @constructor\n */\nvar GeoJSONReader = function GeoJSONReader (geometryFactory) {\n this.geometryFactory = geometryFactory || new GeometryFactory();\n this.precisionModel = this.geometryFactory.getPrecisionModel();\n this.parser = new GeoJSONParser(this.geometryFactory);\n};\n/**\n * Reads a GeoJSON representation of a {@link Geometry}\n *\n * Will also parse GeoJSON Features/FeatureCollections as custom objects.\n *\n * @param {Object|String} geoJson a GeoJSON Object or String.\n * @return {Geometry|Object} a Geometry or Feature/FeatureCollection representation.
\n * @memberof GeoJSONReader\n */\nGeoJSONReader.prototype.read = function read (geoJson) {\n var geometry = this.parser.read(geoJson);\n\n if (this.precisionModel.getType() === PrecisionModel.FIXED) {\n this.reducePrecision(geometry);\n }\n\n return geometry\n};\n\n// NOTE: this is a hack\nGeoJSONReader.prototype.reducePrecision = function reducePrecision (geometry) {\n var this$1 = this;\n\n var i, len;\n\n if (geometry.coordinate) {\n this.precisionModel.makePrecise(geometry.coordinate);\n } else if (geometry.points) {\n for (i = 0, len = geometry.points.length; i < len; i++) {\n this$1.precisionModel.makePrecise(geometry.points[i]);\n }\n } else if (geometry.geometries) {\n for (i = 0, len = geometry.geometries.length; i < len; i++) {\n this$1.reducePrecision(geometry.geometries[i]);\n }\n }\n};\n\n/**\n * @module GeoJSONWriter\n */\n\n/**\n * Writes the GeoJSON representation of a {@link Geometry}. The\n * The GeoJSON format is defined here .\n */\n\n/**\n * The GeoJSONWriter
outputs coordinates rounded to the precision\n * model. Only the maximum number of decimal places necessary to represent the\n * ordinates to the required precision will be output.\n *\n * @param {GeometryFactory} geometryFactory\n * @constructor\n */\nvar GeoJSONWriter = function GeoJSONWriter () {\n this.parser = new GeoJSONParser(this.geometryFactory);\n};\n/**\n * Converts a Geometry
to its GeoJSON representation.\n *\n * @param {Geometry}\n * geometry a Geometry
to process.\n * @return {Object} The GeoJSON representation of the Geometry.\n * @memberof GeoJSONWriter\n */\nGeoJSONWriter.prototype.write = function write (geometry) {\n return this.parser.write(geometry)\n};\n\n/* eslint-disable no-undef */\n\n// io\n\nvar Position = function Position () {};\n\nvar staticAccessors$20 = { ON: { configurable: true },LEFT: { configurable: true },RIGHT: { configurable: true } };\n\nPosition.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nPosition.prototype.getClass = function getClass () {\n return Position\n};\nPosition.opposite = function opposite (position) {\n if (position === Position.LEFT) { return Position.RIGHT }\n if (position === Position.RIGHT) { return Position.LEFT }\n return position\n};\nstaticAccessors$20.ON.get = function () { return 0 };\nstaticAccessors$20.LEFT.get = function () { return 1 };\nstaticAccessors$20.RIGHT.get = function () { return 2 };\n\nObject.defineProperties( Position, staticAccessors$20 );\n\n/**\n * @param {string=} message Optional message\n * @extends {Error}\n * @constructor\n * @private\n */\nfunction EmptyStackException (message) {\n this.message = message || '';\n}\nEmptyStackException.prototype = new Error();\n\n/**\n * @type {string}\n */\nEmptyStackException.prototype.name = 'EmptyStackException';\n\n/**\n * @see http://download.oracle.com/javase/6/docs/api/java/util/Stack.html\n *\n * @extends {List}\n * @constructor\n * @private\n */\nfunction Stack () {\n /**\n * @type {Array}\n * @private\n */\n this.array_ = [];\n}\nStack.prototype = new List();\n\n/**\n * @override\n */\nStack.prototype.add = function (e) {\n this.array_.push(e);\n return true\n};\n\n/**\n * @override\n */\nStack.prototype.get = function (index) {\n if (index < 0 || index >= this.size()) {\n throw new Error()\n }\n\n return this.array_[index]\n};\n\n/**\n * Pushes an item onto the top of this stack.\n * @param {Object} e\n * @return {Object}\n */\nStack.prototype.push = function (e) {\n this.array_.push(e);\n return e\n};\n\n/**\n * Pushes an item onto the top of this stack.\n * @param {Object} e\n * @return {Object}\n */\nStack.prototype.pop = function (e) {\n if (this.array_.length === 0) {\n throw new EmptyStackException()\n }\n\n return this.array_.pop()\n};\n\n/**\n * Looks at the object at the top of this stack without removing it from the\n * stack.\n * @return {Object}\n */\nStack.prototype.peek = function () {\n if (this.array_.length === 0) {\n throw new EmptyStackException()\n }\n\n return this.array_[this.array_.length - 1]\n};\n\n/**\n * Tests if this stack is empty.\n * @return {boolean} true if and only if this stack contains no items; false\n * otherwise.\n */\nStack.prototype.empty = function () {\n if (this.array_.length === 0) {\n return true\n } else {\n return false\n }\n};\n\n/**\n * @return {boolean}\n */\nStack.prototype.isEmpty = function () {\n return this.empty()\n};\n\n/**\n * Returns the 1-based position where an object is on this stack. If the object\n * o occurs as an item in this stack, this method returns the distance from the\n * top of the stack of the occurrence nearest the top of the stack; the topmost\n * item on the stack is considered to be at distance 1. The equals method is\n * used to compare o to the items in this stack.\n *\n * NOTE: does not currently actually use equals. (=== is used)\n *\n * @param {Object} o\n * @return {number} the 1-based position from the top of the stack where the\n * object is located; the return value -1 indicates that the object is\n * not on the stack.\n */\nStack.prototype.search = function (o) {\n return this.array_.indexOf(o)\n};\n\n/**\n * @return {number}\n * @export\n */\nStack.prototype.size = function () {\n return this.array_.length\n};\n\n/**\n * @return {Array}\n */\nStack.prototype.toArray = function () {\n var this$1 = this;\n\n var array = [];\n\n for (var i = 0, len = this.array_.length; i < len; i++) {\n array.push(this$1.array_[i]);\n }\n\n return array\n};\n\nvar RightmostEdgeFinder = function RightmostEdgeFinder () {\n this._minIndex = -1;\n this._minCoord = null;\n this._minDe = null;\n this._orientedDe = null;\n};\nRightmostEdgeFinder.prototype.getCoordinate = function getCoordinate () {\n return this._minCoord\n};\nRightmostEdgeFinder.prototype.getRightmostSide = function getRightmostSide (de, index) {\n var side = this.getRightmostSideOfSegment(de, index);\n if (side < 0) { side = this.getRightmostSideOfSegment(de, index - 1); }\n if (side < 0) {\n this._minCoord = null;\n this.checkForRightmostCoordinate(de);\n }\n return side\n};\nRightmostEdgeFinder.prototype.findRightmostEdgeAtVertex = function findRightmostEdgeAtVertex () {\n var pts = this._minDe.getEdge().getCoordinates();\n Assert.isTrue(this._minIndex > 0 && this._minIndex < pts.length, 'rightmost point expected to be interior vertex of edge');\n var pPrev = pts[this._minIndex - 1];\n var pNext = pts[this._minIndex + 1];\n var orientation = CGAlgorithms.computeOrientation(this._minCoord, pNext, pPrev);\n var usePrev = false;\n if (pPrev.y < this._minCoord.y && pNext.y < this._minCoord.y && orientation === CGAlgorithms.COUNTERCLOCKWISE) {\n usePrev = true;\n } else if (pPrev.y > this._minCoord.y && pNext.y > this._minCoord.y && orientation === CGAlgorithms.CLOCKWISE) {\n usePrev = true;\n }\n if (usePrev) {\n this._minIndex = this._minIndex - 1;\n }\n};\nRightmostEdgeFinder.prototype.getRightmostSideOfSegment = function getRightmostSideOfSegment (de, i) {\n var e = de.getEdge();\n var coord = e.getCoordinates();\n if (i < 0 || i + 1 >= coord.length) { return -1 }\n if (coord[i].y === coord[i + 1].y) { return -1 }\n var pos = Position.LEFT;\n if (coord[i].y < coord[i + 1].y) { pos = Position.RIGHT; }\n return pos\n};\nRightmostEdgeFinder.prototype.getEdge = function getEdge () {\n return this._orientedDe\n};\nRightmostEdgeFinder.prototype.checkForRightmostCoordinate = function checkForRightmostCoordinate (de) {\n var this$1 = this;\n\n var coord = de.getEdge().getCoordinates();\n for (var i = 0; i < coord.length - 1; i++) {\n if (this$1._minCoord === null || coord[i].x > this$1._minCoord.x) {\n this$1._minDe = de;\n this$1._minIndex = i;\n this$1._minCoord = coord[i];\n }\n }\n};\nRightmostEdgeFinder.prototype.findRightmostEdgeAtNode = function findRightmostEdgeAtNode () {\n var node = this._minDe.getNode();\n var star = node.getEdges();\n this._minDe = star.getRightmostEdge();\n if (!this._minDe.isForward()) {\n this._minDe = this._minDe.getSym();\n this._minIndex = this._minDe.getEdge().getCoordinates().length - 1;\n }\n};\nRightmostEdgeFinder.prototype.findEdge = function findEdge (dirEdgeList) {\n var this$1 = this;\n\n for (var i = dirEdgeList.iterator(); i.hasNext();) {\n var de = i.next();\n if (!de.isForward()) { continue }\n this$1.checkForRightmostCoordinate(de);\n }\n Assert.isTrue(this._minIndex !== 0 || this._minCoord.equals(this._minDe.getCoordinate()), 'inconsistency in rightmost processing');\n if (this._minIndex === 0) {\n this.findRightmostEdgeAtNode();\n } else {\n this.findRightmostEdgeAtVertex();\n }\n this._orientedDe = this._minDe;\n var rightmostSide = this.getRightmostSide(this._minDe, this._minIndex);\n if (rightmostSide === Position.LEFT) {\n this._orientedDe = this._minDe.getSym();\n }\n};\nRightmostEdgeFinder.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nRightmostEdgeFinder.prototype.getClass = function getClass () {\n return RightmostEdgeFinder\n};\n\nvar TopologyException = (function (RuntimeException$$1) {\n function TopologyException (msg, pt) {\n RuntimeException$$1.call(this, TopologyException.msgWithCoord(msg, pt));\n this.pt = pt ? new Coordinate(pt) : null;\n this.name = 'TopologyException';\n }\n\n if ( RuntimeException$$1 ) TopologyException.__proto__ = RuntimeException$$1;\n TopologyException.prototype = Object.create( RuntimeException$$1 && RuntimeException$$1.prototype );\n TopologyException.prototype.constructor = TopologyException;\n TopologyException.prototype.getCoordinate = function getCoordinate () {\n return this.pt\n };\n TopologyException.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n TopologyException.prototype.getClass = function getClass () {\n return TopologyException\n };\n TopologyException.msgWithCoord = function msgWithCoord (msg, pt) {\n if (!pt) { return msg + ' [ ' + pt + ' ]' }\n return msg\n };\n\n return TopologyException;\n}(RuntimeException));\n\nvar LinkedList = function LinkedList () {\n this.array_ = [];\n};\nLinkedList.prototype.addLast = function addLast (e) {\n this.array_.push(e);\n};\nLinkedList.prototype.removeFirst = function removeFirst () {\n return this.array_.shift()\n};\nLinkedList.prototype.isEmpty = function isEmpty () {\n return this.array_.length === 0\n};\n\nvar BufferSubgraph = function BufferSubgraph () {\n this._finder = null;\n this._dirEdgeList = new ArrayList();\n this._nodes = new ArrayList();\n this._rightMostCoord = null;\n this._env = null;\n this._finder = new RightmostEdgeFinder();\n};\nBufferSubgraph.prototype.clearVisitedEdges = function clearVisitedEdges () {\n for (var it = this._dirEdgeList.iterator(); it.hasNext();) {\n var de = it.next();\n de.setVisited(false);\n }\n};\nBufferSubgraph.prototype.getRightmostCoordinate = function getRightmostCoordinate () {\n return this._rightMostCoord\n};\nBufferSubgraph.prototype.computeNodeDepth = function computeNodeDepth (n) {\n var this$1 = this;\n\n var startEdge = null;\n for (var i = n.getEdges().iterator(); i.hasNext();) {\n var de = i.next();\n if (de.isVisited() || de.getSym().isVisited()) {\n startEdge = de;\n break\n }\n }\n if (startEdge === null) { throw new TopologyException('unable to find edge to compute depths at ' + n.getCoordinate()) }\n n.getEdges().computeDepths(startEdge);\n for (var i$1 = n.getEdges().iterator(); i$1.hasNext();) {\n var de$1 = i$1.next();\n de$1.setVisited(true);\n this$1.copySymDepths(de$1);\n }\n};\nBufferSubgraph.prototype.computeDepth = function computeDepth (outsideDepth) {\n this.clearVisitedEdges();\n var de = this._finder.getEdge();\n // const n = de.getNode()\n // const label = de.getLabel()\n de.setEdgeDepths(Position.RIGHT, outsideDepth);\n this.copySymDepths(de);\n this.computeDepths(de);\n};\nBufferSubgraph.prototype.create = function create (node) {\n this.addReachable(node);\n this._finder.findEdge(this._dirEdgeList);\n this._rightMostCoord = this._finder.getCoordinate();\n};\nBufferSubgraph.prototype.findResultEdges = function findResultEdges () {\n for (var it = this._dirEdgeList.iterator(); it.hasNext();) {\n var de = it.next();\n if (de.getDepth(Position.RIGHT) >= 1 && de.getDepth(Position.LEFT) <= 0 && !de.isInteriorAreaEdge()) {\n de.setInResult(true);\n }\n }\n};\nBufferSubgraph.prototype.computeDepths = function computeDepths (startEdge) {\n var this$1 = this;\n\n var nodesVisited = new HashSet();\n var nodeQueue = new LinkedList();\n var startNode = startEdge.getNode();\n nodeQueue.addLast(startNode);\n nodesVisited.add(startNode);\n startEdge.setVisited(true);\n while (!nodeQueue.isEmpty()) {\n var n = nodeQueue.removeFirst();\n nodesVisited.add(n);\n this$1.computeNodeDepth(n);\n for (var i = n.getEdges().iterator(); i.hasNext();) {\n var de = i.next();\n var sym = de.getSym();\n if (sym.isVisited()) { continue }\n var adjNode = sym.getNode();\n if (!nodesVisited.contains(adjNode)) {\n nodeQueue.addLast(adjNode);\n nodesVisited.add(adjNode);\n }\n }\n }\n};\nBufferSubgraph.prototype.compareTo = function compareTo (o) {\n var graph = o;\n if (this._rightMostCoord.x < graph._rightMostCoord.x) {\n return -1\n }\n if (this._rightMostCoord.x > graph._rightMostCoord.x) {\n return 1\n }\n return 0\n};\nBufferSubgraph.prototype.getEnvelope = function getEnvelope () {\n if (this._env === null) {\n var edgeEnv = new Envelope();\n for (var it = this._dirEdgeList.iterator(); it.hasNext();) {\n var dirEdge = it.next();\n var pts = dirEdge.getEdge().getCoordinates();\n for (var i = 0; i < pts.length - 1; i++) {\n edgeEnv.expandToInclude(pts[i]);\n }\n }\n this._env = edgeEnv;\n }\n return this._env\n};\nBufferSubgraph.prototype.addReachable = function addReachable (startNode) {\n var this$1 = this;\n\n var nodeStack = new Stack();\n nodeStack.add(startNode);\n while (!nodeStack.empty()) {\n var node = nodeStack.pop();\n this$1.add(node, nodeStack);\n }\n};\nBufferSubgraph.prototype.copySymDepths = function copySymDepths (de) {\n var sym = de.getSym();\n sym.setDepth(Position.LEFT, de.getDepth(Position.RIGHT));\n sym.setDepth(Position.RIGHT, de.getDepth(Position.LEFT));\n};\nBufferSubgraph.prototype.add = function add (node, nodeStack) {\n var this$1 = this;\n\n node.setVisited(true);\n this._nodes.add(node);\n for (var i = node.getEdges().iterator(); i.hasNext();) {\n var de = i.next();\n this$1._dirEdgeList.add(de);\n var sym = de.getSym();\n var symNode = sym.getNode();\n if (!symNode.isVisited()) { nodeStack.push(symNode); }\n }\n};\nBufferSubgraph.prototype.getNodes = function getNodes () {\n return this._nodes\n};\nBufferSubgraph.prototype.getDirectedEdges = function getDirectedEdges () {\n return this._dirEdgeList\n};\nBufferSubgraph.prototype.interfaces_ = function interfaces_ () {\n return [Comparable]\n};\nBufferSubgraph.prototype.getClass = function getClass () {\n return BufferSubgraph\n};\n\nvar TopologyLocation = function TopologyLocation () {\n var this$1 = this;\n\n this.location = null;\n if (arguments.length === 1) {\n if (arguments[0] instanceof Array) {\n var location = arguments[0];\n this.init(location.length);\n } else if (Number.isInteger(arguments[0])) {\n var on = arguments[0];\n this.init(1);\n this.location[Position.ON] = on;\n } else if (arguments[0] instanceof TopologyLocation) {\n var gl = arguments[0];\n this.init(gl.location.length);\n if (gl !== null) {\n for (var i = 0; i < this.location.length; i++) {\n this$1.location[i] = gl.location[i];\n }\n }\n }\n } else if (arguments.length === 3) {\n var on$1 = arguments[0];\n var left = arguments[1];\n var right = arguments[2];\n this.init(3);\n this.location[Position.ON] = on$1;\n this.location[Position.LEFT] = left;\n this.location[Position.RIGHT] = right;\n }\n};\nTopologyLocation.prototype.setAllLocations = function setAllLocations (locValue) {\n var this$1 = this;\n\n for (var i = 0; i < this.location.length; i++) {\n this$1.location[i] = locValue;\n }\n};\nTopologyLocation.prototype.isNull = function isNull () {\n var this$1 = this;\n\n for (var i = 0; i < this.location.length; i++) {\n if (this$1.location[i] !== Location.NONE) { return false }\n }\n return true\n};\nTopologyLocation.prototype.setAllLocationsIfNull = function setAllLocationsIfNull (locValue) {\n var this$1 = this;\n\n for (var i = 0; i < this.location.length; i++) {\n if (this$1.location[i] === Location.NONE) { this$1.location[i] = locValue; }\n }\n};\nTopologyLocation.prototype.isLine = function isLine () {\n return this.location.length === 1\n};\nTopologyLocation.prototype.merge = function merge (gl) {\n var this$1 = this;\n\n if (gl.location.length > this.location.length) {\n var newLoc = new Array(3).fill(null);\n newLoc[Position.ON] = this.location[Position.ON];\n newLoc[Position.LEFT] = Location.NONE;\n newLoc[Position.RIGHT] = Location.NONE;\n this.location = newLoc;\n }\n for (var i = 0; i < this.location.length; i++) {\n if (this$1.location[i] === Location.NONE && i < gl.location.length) { this$1.location[i] = gl.location[i]; }\n }\n};\nTopologyLocation.prototype.getLocations = function getLocations () {\n return this.location\n};\nTopologyLocation.prototype.flip = function flip () {\n if (this.location.length <= 1) { return null }\n var temp = this.location[Position.LEFT];\n this.location[Position.LEFT] = this.location[Position.RIGHT];\n this.location[Position.RIGHT] = temp;\n};\nTopologyLocation.prototype.toString = function toString () {\n var buf = new StringBuffer();\n if (this.location.length > 1) { buf.append(Location.toLocationSymbol(this.location[Position.LEFT])); }\n buf.append(Location.toLocationSymbol(this.location[Position.ON]));\n if (this.location.length > 1) { buf.append(Location.toLocationSymbol(this.location[Position.RIGHT])); }\n return buf.toString()\n};\nTopologyLocation.prototype.setLocations = function setLocations (on, left, right) {\n this.location[Position.ON] = on;\n this.location[Position.LEFT] = left;\n this.location[Position.RIGHT] = right;\n};\nTopologyLocation.prototype.get = function get (posIndex) {\n if (posIndex < this.location.length) { return this.location[posIndex] }\n return Location.NONE\n};\nTopologyLocation.prototype.isArea = function isArea () {\n return this.location.length > 1\n};\nTopologyLocation.prototype.isAnyNull = function isAnyNull () {\n var this$1 = this;\n\n for (var i = 0; i < this.location.length; i++) {\n if (this$1.location[i] === Location.NONE) { return true }\n }\n return false\n};\nTopologyLocation.prototype.setLocation = function setLocation () {\n if (arguments.length === 1) {\n var locValue = arguments[0];\n this.setLocation(Position.ON, locValue);\n } else if (arguments.length === 2) {\n var locIndex = arguments[0];\n var locValue$1 = arguments[1];\n this.location[locIndex] = locValue$1;\n }\n};\nTopologyLocation.prototype.init = function init (size) {\n this.location = new Array(size).fill(null);\n this.setAllLocations(Location.NONE);\n};\nTopologyLocation.prototype.isEqualOnSide = function isEqualOnSide (le, locIndex) {\n return this.location[locIndex] === le.location[locIndex]\n};\nTopologyLocation.prototype.allPositionsEqual = function allPositionsEqual (loc) {\n var this$1 = this;\n\n for (var i = 0; i < this.location.length; i++) {\n if (this$1.location[i] !== loc) { return false }\n }\n return true\n};\nTopologyLocation.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nTopologyLocation.prototype.getClass = function getClass () {\n return TopologyLocation\n};\n\nvar Label = function Label () {\n this.elt = new Array(2).fill(null);\n if (arguments.length === 1) {\n if (Number.isInteger(arguments[0])) {\n var onLoc = arguments[0];\n this.elt[0] = new TopologyLocation(onLoc);\n this.elt[1] = new TopologyLocation(onLoc);\n } else if (arguments[0] instanceof Label) {\n var lbl = arguments[0];\n this.elt[0] = new TopologyLocation(lbl.elt[0]);\n this.elt[1] = new TopologyLocation(lbl.elt[1]);\n }\n } else if (arguments.length === 2) {\n var geomIndex = arguments[0];\n var onLoc$1 = arguments[1];\n this.elt[0] = new TopologyLocation(Location.NONE);\n this.elt[1] = new TopologyLocation(Location.NONE);\n this.elt[geomIndex].setLocation(onLoc$1);\n } else if (arguments.length === 3) {\n var onLoc$2 = arguments[0];\n var leftLoc = arguments[1];\n var rightLoc = arguments[2];\n this.elt[0] = new TopologyLocation(onLoc$2, leftLoc, rightLoc);\n this.elt[1] = new TopologyLocation(onLoc$2, leftLoc, rightLoc);\n } else if (arguments.length === 4) {\n var geomIndex$1 = arguments[0];\n var onLoc$3 = arguments[1];\n var leftLoc$1 = arguments[2];\n var rightLoc$1 = arguments[3];\n this.elt[0] = new TopologyLocation(Location.NONE, Location.NONE, Location.NONE);\n this.elt[1] = new TopologyLocation(Location.NONE, Location.NONE, Location.NONE);\n this.elt[geomIndex$1].setLocations(onLoc$3, leftLoc$1, rightLoc$1);\n }\n};\nLabel.prototype.getGeometryCount = function getGeometryCount () {\n var count = 0;\n if (!this.elt[0].isNull()) { count++; }\n if (!this.elt[1].isNull()) { count++; }\n return count\n};\nLabel.prototype.setAllLocations = function setAllLocations (geomIndex, location) {\n this.elt[geomIndex].setAllLocations(location);\n};\nLabel.prototype.isNull = function isNull (geomIndex) {\n return this.elt[geomIndex].isNull()\n};\nLabel.prototype.setAllLocationsIfNull = function setAllLocationsIfNull () {\n if (arguments.length === 1) {\n var location = arguments[0];\n this.setAllLocationsIfNull(0, location);\n this.setAllLocationsIfNull(1, location);\n } else if (arguments.length === 2) {\n var geomIndex = arguments[0];\n var location$1 = arguments[1];\n this.elt[geomIndex].setAllLocationsIfNull(location$1);\n }\n};\nLabel.prototype.isLine = function isLine (geomIndex) {\n return this.elt[geomIndex].isLine()\n};\nLabel.prototype.merge = function merge (lbl) {\n var this$1 = this;\n\n for (var i = 0; i < 2; i++) {\n if (this$1.elt[i] === null && lbl.elt[i] !== null) {\n this$1.elt[i] = new TopologyLocation(lbl.elt[i]);\n } else {\n this$1.elt[i].merge(lbl.elt[i]);\n }\n }\n};\nLabel.prototype.flip = function flip () {\n this.elt[0].flip();\n this.elt[1].flip();\n};\nLabel.prototype.getLocation = function getLocation () {\n if (arguments.length === 1) {\n var geomIndex = arguments[0];\n return this.elt[geomIndex].get(Position.ON)\n } else if (arguments.length === 2) {\n var geomIndex$1 = arguments[0];\n var posIndex = arguments[1];\n return this.elt[geomIndex$1].get(posIndex)\n }\n};\nLabel.prototype.toString = function toString () {\n var buf = new StringBuffer();\n if (this.elt[0] !== null) {\n buf.append('A:');\n buf.append(this.elt[0].toString());\n }\n if (this.elt[1] !== null) {\n buf.append(' B:');\n buf.append(this.elt[1].toString());\n }\n return buf.toString()\n};\nLabel.prototype.isArea = function isArea () {\n if (arguments.length === 0) {\n return this.elt[0].isArea() || this.elt[1].isArea()\n } else if (arguments.length === 1) {\n var geomIndex = arguments[0];\n return this.elt[geomIndex].isArea()\n }\n};\nLabel.prototype.isAnyNull = function isAnyNull (geomIndex) {\n return this.elt[geomIndex].isAnyNull()\n};\nLabel.prototype.setLocation = function setLocation () {\n if (arguments.length === 2) {\n var geomIndex = arguments[0];\n var location = arguments[1];\n this.elt[geomIndex].setLocation(Position.ON, location);\n } else if (arguments.length === 3) {\n var geomIndex$1 = arguments[0];\n var posIndex = arguments[1];\n var location$1 = arguments[2];\n this.elt[geomIndex$1].setLocation(posIndex, location$1);\n }\n};\nLabel.prototype.isEqualOnSide = function isEqualOnSide (lbl, side) {\n return this.elt[0].isEqualOnSide(lbl.elt[0], side) && this.elt[1].isEqualOnSide(lbl.elt[1], side)\n};\nLabel.prototype.allPositionsEqual = function allPositionsEqual (geomIndex, loc) {\n return this.elt[geomIndex].allPositionsEqual(loc)\n};\nLabel.prototype.toLine = function toLine (geomIndex) {\n if (this.elt[geomIndex].isArea()) { this.elt[geomIndex] = new TopologyLocation(this.elt[geomIndex].location[0]); }\n};\nLabel.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nLabel.prototype.getClass = function getClass () {\n return Label\n};\nLabel.toLineLabel = function toLineLabel (label) {\n var lineLabel = new Label(Location.NONE);\n for (var i = 0; i < 2; i++) {\n lineLabel.setLocation(i, label.getLocation(i));\n }\n return lineLabel\n};\n\nvar EdgeRing = function EdgeRing () {\n this._startDe = null;\n this._maxNodeDegree = -1;\n this._edges = new ArrayList();\n this._pts = new ArrayList();\n this._label = new Label(Location.NONE);\n this._ring = null;\n this._isHole = null;\n this._shell = null;\n this._holes = new ArrayList();\n this._geometryFactory = null;\n var start = arguments[0];\n var geometryFactory = arguments[1];\n this._geometryFactory = geometryFactory;\n this.computePoints(start);\n this.computeRing();\n};\nEdgeRing.prototype.computeRing = function computeRing () {\n var this$1 = this;\n\n if (this._ring !== null) { return null }\n var coord = new Array(this._pts.size()).fill(null);\n for (var i = 0; i < this._pts.size(); i++) {\n coord[i] = this$1._pts.get(i);\n }\n this._ring = this._geometryFactory.createLinearRing(coord);\n this._isHole = CGAlgorithms.isCCW(this._ring.getCoordinates());\n};\nEdgeRing.prototype.isIsolated = function isIsolated () {\n return this._label.getGeometryCount() === 1\n};\nEdgeRing.prototype.computePoints = function computePoints (start) {\n var this$1 = this;\n\n this._startDe = start;\n var de = start;\n var isFirstEdge = true;\n do {\n if (de === null) { throw new TopologyException('Found null DirectedEdge') }\n if (de.getEdgeRing() === this$1) { throw new TopologyException('Directed Edge visited twice during ring-building at ' + de.getCoordinate()) }\n this$1._edges.add(de);\n var label = de.getLabel();\n Assert.isTrue(label.isArea());\n this$1.mergeLabel(label);\n this$1.addPoints(de.getEdge(), de.isForward(), isFirstEdge);\n isFirstEdge = false;\n this$1.setEdgeRing(de, this$1);\n de = this$1.getNext(de);\n } while (de !== this._startDe)\n};\nEdgeRing.prototype.getLinearRing = function getLinearRing () {\n return this._ring\n};\nEdgeRing.prototype.getCoordinate = function getCoordinate (i) {\n return this._pts.get(i)\n};\nEdgeRing.prototype.computeMaxNodeDegree = function computeMaxNodeDegree () {\n var this$1 = this;\n\n this._maxNodeDegree = 0;\n var de = this._startDe;\n do {\n var node = de.getNode();\n var degree = node.getEdges().getOutgoingDegree(this$1);\n if (degree > this$1._maxNodeDegree) { this$1._maxNodeDegree = degree; }\n de = this$1.getNext(de);\n } while (de !== this._startDe)\n this._maxNodeDegree *= 2;\n};\nEdgeRing.prototype.addPoints = function addPoints (edge, isForward, isFirstEdge) {\n var this$1 = this;\n\n var edgePts = edge.getCoordinates();\n if (isForward) {\n var startIndex = 1;\n if (isFirstEdge) { startIndex = 0; }\n for (var i = startIndex; i < edgePts.length; i++) {\n this$1._pts.add(edgePts[i]);\n }\n } else {\n var startIndex$1 = edgePts.length - 2;\n if (isFirstEdge) { startIndex$1 = edgePts.length - 1; }\n for (var i$1 = startIndex$1; i$1 >= 0; i$1--) {\n this$1._pts.add(edgePts[i$1]);\n }\n }\n};\nEdgeRing.prototype.isHole = function isHole () {\n return this._isHole\n};\nEdgeRing.prototype.setInResult = function setInResult () {\n var de = this._startDe;\n do {\n de.getEdge().setInResult(true);\n de = de.getNext();\n } while (de !== this._startDe)\n};\nEdgeRing.prototype.containsPoint = function containsPoint (p) {\n var shell = this.getLinearRing();\n var env = shell.getEnvelopeInternal();\n if (!env.contains(p)) { return false }\n if (!CGAlgorithms.isPointInRing(p, shell.getCoordinates())) { return false }\n for (var i = this._holes.iterator(); i.hasNext();) {\n var hole = i.next();\n if (hole.containsPoint(p)) { return false }\n }\n return true\n};\nEdgeRing.prototype.addHole = function addHole (ring) {\n this._holes.add(ring);\n};\nEdgeRing.prototype.isShell = function isShell () {\n return this._shell === null\n};\nEdgeRing.prototype.getLabel = function getLabel () {\n return this._label\n};\nEdgeRing.prototype.getEdges = function getEdges () {\n return this._edges\n};\nEdgeRing.prototype.getMaxNodeDegree = function getMaxNodeDegree () {\n if (this._maxNodeDegree < 0) { this.computeMaxNodeDegree(); }\n return this._maxNodeDegree\n};\nEdgeRing.prototype.getShell = function getShell () {\n return this._shell\n};\nEdgeRing.prototype.mergeLabel = function mergeLabel () {\n if (arguments.length === 1) {\n var deLabel = arguments[0];\n this.mergeLabel(deLabel, 0);\n this.mergeLabel(deLabel, 1);\n } else if (arguments.length === 2) {\n var deLabel$1 = arguments[0];\n var geomIndex = arguments[1];\n var loc = deLabel$1.getLocation(geomIndex, Position.RIGHT);\n if (loc === Location.NONE) { return null }\n if (this._label.getLocation(geomIndex) === Location.NONE) {\n this._label.setLocation(geomIndex, loc);\n return null\n }\n }\n};\nEdgeRing.prototype.setShell = function setShell (shell) {\n this._shell = shell;\n if (shell !== null) { shell.addHole(this); }\n};\nEdgeRing.prototype.toPolygon = function toPolygon (geometryFactory) {\n var this$1 = this;\n\n var holeLR = new Array(this._holes.size()).fill(null);\n for (var i = 0; i < this._holes.size(); i++) {\n holeLR[i] = this$1._holes.get(i).getLinearRing();\n }\n var poly = geometryFactory.createPolygon(this.getLinearRing(), holeLR);\n return poly\n};\nEdgeRing.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nEdgeRing.prototype.getClass = function getClass () {\n return EdgeRing\n};\n\nvar MinimalEdgeRing = (function (EdgeRing$$1) {\n function MinimalEdgeRing () {\n var start = arguments[0];\n var geometryFactory = arguments[1];\n EdgeRing$$1.call(this, start, geometryFactory);\n }\n\n if ( EdgeRing$$1 ) MinimalEdgeRing.__proto__ = EdgeRing$$1;\n MinimalEdgeRing.prototype = Object.create( EdgeRing$$1 && EdgeRing$$1.prototype );\n MinimalEdgeRing.prototype.constructor = MinimalEdgeRing;\n MinimalEdgeRing.prototype.setEdgeRing = function setEdgeRing (de, er) {\n de.setMinEdgeRing(er);\n };\n MinimalEdgeRing.prototype.getNext = function getNext (de) {\n return de.getNextMin()\n };\n MinimalEdgeRing.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n MinimalEdgeRing.prototype.getClass = function getClass () {\n return MinimalEdgeRing\n };\n\n return MinimalEdgeRing;\n}(EdgeRing));\n\nvar MaximalEdgeRing = (function (EdgeRing$$1) {\n function MaximalEdgeRing () {\n var start = arguments[0];\n var geometryFactory = arguments[1];\n EdgeRing$$1.call(this, start, geometryFactory);\n }\n\n if ( EdgeRing$$1 ) MaximalEdgeRing.__proto__ = EdgeRing$$1;\n MaximalEdgeRing.prototype = Object.create( EdgeRing$$1 && EdgeRing$$1.prototype );\n MaximalEdgeRing.prototype.constructor = MaximalEdgeRing;\n MaximalEdgeRing.prototype.buildMinimalRings = function buildMinimalRings () {\n var this$1 = this;\n\n var minEdgeRings = new ArrayList();\n var de = this._startDe;\n do {\n if (de.getMinEdgeRing() === null) {\n var minEr = new MinimalEdgeRing(de, this$1._geometryFactory);\n minEdgeRings.add(minEr);\n }\n de = de.getNext();\n } while (de !== this._startDe)\n return minEdgeRings\n };\n MaximalEdgeRing.prototype.setEdgeRing = function setEdgeRing (de, er) {\n de.setEdgeRing(er);\n };\n MaximalEdgeRing.prototype.linkDirectedEdgesForMinimalEdgeRings = function linkDirectedEdgesForMinimalEdgeRings () {\n var this$1 = this;\n\n var de = this._startDe;\n do {\n var node = de.getNode();\n node.getEdges().linkMinimalDirectedEdges(this$1);\n de = de.getNext();\n } while (de !== this._startDe)\n };\n MaximalEdgeRing.prototype.getNext = function getNext (de) {\n return de.getNext()\n };\n MaximalEdgeRing.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n MaximalEdgeRing.prototype.getClass = function getClass () {\n return MaximalEdgeRing\n };\n\n return MaximalEdgeRing;\n}(EdgeRing));\n\nvar GraphComponent = function GraphComponent () {\n this._label = null;\n this._isInResult = false;\n this._isCovered = false;\n this._isCoveredSet = false;\n this._isVisited = false;\n if (arguments.length === 0) {} else if (arguments.length === 1) {\n var label = arguments[0];\n this._label = label;\n }\n};\nGraphComponent.prototype.setVisited = function setVisited (isVisited) {\n this._isVisited = isVisited;\n};\nGraphComponent.prototype.setInResult = function setInResult (isInResult) {\n this._isInResult = isInResult;\n};\nGraphComponent.prototype.isCovered = function isCovered () {\n return this._isCovered\n};\nGraphComponent.prototype.isCoveredSet = function isCoveredSet () {\n return this._isCoveredSet\n};\nGraphComponent.prototype.setLabel = function setLabel (label) {\n this._label = label;\n};\nGraphComponent.prototype.getLabel = function getLabel () {\n return this._label\n};\nGraphComponent.prototype.setCovered = function setCovered (isCovered) {\n this._isCovered = isCovered;\n this._isCoveredSet = true;\n};\nGraphComponent.prototype.updateIM = function updateIM (im) {\n Assert.isTrue(this._label.getGeometryCount() >= 2, 'found partial label');\n this.computeIM(im);\n};\nGraphComponent.prototype.isInResult = function isInResult () {\n return this._isInResult\n};\nGraphComponent.prototype.isVisited = function isVisited () {\n return this._isVisited\n};\nGraphComponent.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nGraphComponent.prototype.getClass = function getClass () {\n return GraphComponent\n};\n\nvar Node = (function (GraphComponent$$1) {\n function Node () {\n GraphComponent$$1.call(this);\n this._coord = null;\n this._edges = null;\n var coord = arguments[0];\n var edges = arguments[1];\n this._coord = coord;\n this._edges = edges;\n this._label = new Label(0, Location.NONE);\n }\n\n if ( GraphComponent$$1 ) Node.__proto__ = GraphComponent$$1;\n Node.prototype = Object.create( GraphComponent$$1 && GraphComponent$$1.prototype );\n Node.prototype.constructor = Node;\n Node.prototype.isIncidentEdgeInResult = function isIncidentEdgeInResult () {\n for (var it = this.getEdges().getEdges().iterator(); it.hasNext();) {\n var de = it.next();\n if (de.getEdge().isInResult()) { return true }\n }\n return false\n };\n Node.prototype.isIsolated = function isIsolated () {\n return this._label.getGeometryCount() === 1\n };\n Node.prototype.getCoordinate = function getCoordinate () {\n return this._coord\n };\n Node.prototype.print = function print (out) {\n out.println('node ' + this._coord + ' lbl: ' + this._label);\n };\n Node.prototype.computeIM = function computeIM (im) {};\n Node.prototype.computeMergedLocation = function computeMergedLocation (label2, eltIndex) {\n var loc = Location.NONE;\n loc = this._label.getLocation(eltIndex);\n if (!label2.isNull(eltIndex)) {\n var nLoc = label2.getLocation(eltIndex);\n if (loc !== Location.BOUNDARY) { loc = nLoc; }\n }\n return loc\n };\n Node.prototype.setLabel = function setLabel () {\n if (arguments.length === 2) {\n var argIndex = arguments[0];\n var onLocation = arguments[1];\n if (this._label === null) {\n this._label = new Label(argIndex, onLocation);\n } else { this._label.setLocation(argIndex, onLocation); }\n } else { return GraphComponent$$1.prototype.setLabel.apply(this, arguments) }\n };\n Node.prototype.getEdges = function getEdges () {\n return this._edges\n };\n Node.prototype.mergeLabel = function mergeLabel () {\n var this$1 = this;\n\n if (arguments[0] instanceof Node) {\n var n = arguments[0];\n this.mergeLabel(n._label);\n } else if (arguments[0] instanceof Label) {\n var label2 = arguments[0];\n for (var i = 0; i < 2; i++) {\n var loc = this$1.computeMergedLocation(label2, i);\n var thisLoc = this$1._label.getLocation(i);\n if (thisLoc === Location.NONE) { this$1._label.setLocation(i, loc); }\n }\n }\n };\n Node.prototype.add = function add (e) {\n this._edges.insert(e);\n e.setNode(this);\n };\n Node.prototype.setLabelBoundary = function setLabelBoundary (argIndex) {\n if (this._label === null) { return null }\n var loc = Location.NONE;\n if (this._label !== null) { loc = this._label.getLocation(argIndex); }\n var newLoc = null;\n switch (loc) {\n case Location.BOUNDARY:\n newLoc = Location.INTERIOR;\n break\n case Location.INTERIOR:\n newLoc = Location.BOUNDARY;\n break\n default:\n newLoc = Location.BOUNDARY;\n break\n }\n this._label.setLocation(argIndex, newLoc);\n };\n Node.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n Node.prototype.getClass = function getClass () {\n return Node\n };\n\n return Node;\n}(GraphComponent));\n\nvar NodeMap = function NodeMap () {\n this.nodeMap = new TreeMap();\n this.nodeFact = null;\n var nodeFact = arguments[0];\n this.nodeFact = nodeFact;\n};\nNodeMap.prototype.find = function find (coord) {\n return this.nodeMap.get(coord)\n};\nNodeMap.prototype.addNode = function addNode () {\n if (arguments[0] instanceof Coordinate) {\n var coord = arguments[0];\n var node = this.nodeMap.get(coord);\n if (node === null) {\n node = this.nodeFact.createNode(coord);\n this.nodeMap.put(coord, node);\n }\n return node\n } else if (arguments[0] instanceof Node) {\n var n = arguments[0];\n var node$1 = this.nodeMap.get(n.getCoordinate());\n if (node$1 === null) {\n this.nodeMap.put(n.getCoordinate(), n);\n return n\n }\n node$1.mergeLabel(n);\n return node$1\n }\n};\nNodeMap.prototype.print = function print (out) {\n for (var it = this.iterator(); it.hasNext();) {\n var n = it.next();\n n.print(out);\n }\n};\nNodeMap.prototype.iterator = function iterator () {\n return this.nodeMap.values().iterator()\n};\nNodeMap.prototype.values = function values () {\n return this.nodeMap.values()\n};\nNodeMap.prototype.getBoundaryNodes = function getBoundaryNodes (geomIndex) {\n var bdyNodes = new ArrayList();\n for (var i = this.iterator(); i.hasNext();) {\n var node = i.next();\n if (node.getLabel().getLocation(geomIndex) === Location.BOUNDARY) { bdyNodes.add(node); }\n }\n return bdyNodes\n};\nNodeMap.prototype.add = function add (e) {\n var p = e.getCoordinate();\n var n = this.addNode(p);\n n.add(e);\n};\nNodeMap.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nNodeMap.prototype.getClass = function getClass () {\n return NodeMap\n};\n\nvar Quadrant = function Quadrant () {};\n\nvar staticAccessors$21 = { NE: { configurable: true },NW: { configurable: true },SW: { configurable: true },SE: { configurable: true } };\n\nQuadrant.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nQuadrant.prototype.getClass = function getClass () {\n return Quadrant\n};\nQuadrant.isNorthern = function isNorthern (quad) {\n return quad === Quadrant.NE || quad === Quadrant.NW\n};\nQuadrant.isOpposite = function isOpposite (quad1, quad2) {\n if (quad1 === quad2) { return false }\n var diff = (quad1 - quad2 + 4) % 4;\n if (diff === 2) { return true }\n return false\n};\nQuadrant.commonHalfPlane = function commonHalfPlane (quad1, quad2) {\n if (quad1 === quad2) { return quad1 }\n var diff = (quad1 - quad2 + 4) % 4;\n if (diff === 2) { return -1 }\n var min = quad1 < quad2 ? quad1 : quad2;\n var max = quad1 > quad2 ? quad1 : quad2;\n if (min === 0 && max === 3) { return 3 }\n return min\n};\nQuadrant.isInHalfPlane = function isInHalfPlane (quad, halfPlane) {\n if (halfPlane === Quadrant.SE) {\n return quad === Quadrant.SE || quad === Quadrant.SW\n }\n return quad === halfPlane || quad === halfPlane + 1\n};\nQuadrant.quadrant = function quadrant () {\n if (typeof arguments[0] === 'number' && typeof arguments[1] === 'number') {\n var dx = arguments[0];\n var dy = arguments[1];\n if (dx === 0.0 && dy === 0.0) { throw new IllegalArgumentException('Cannot compute the quadrant for point ( ' + dx + ', ' + dy + ' )') }\n if (dx >= 0.0) {\n if (dy >= 0.0) { return Quadrant.NE; } else { return Quadrant.SE }\n } else {\n if (dy >= 0.0) { return Quadrant.NW; } else { return Quadrant.SW }\n }\n } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Coordinate) {\n var p0 = arguments[0];\n var p1 = arguments[1];\n if (p1.x === p0.x && p1.y === p0.y) { throw new IllegalArgumentException('Cannot compute the quadrant for two identical points ' + p0) }\n if (p1.x >= p0.x) {\n if (p1.y >= p0.y) { return Quadrant.NE; } else { return Quadrant.SE }\n } else {\n if (p1.y >= p0.y) { return Quadrant.NW; } else { return Quadrant.SW }\n }\n }\n};\nstaticAccessors$21.NE.get = function () { return 0 };\nstaticAccessors$21.NW.get = function () { return 1 };\nstaticAccessors$21.SW.get = function () { return 2 };\nstaticAccessors$21.SE.get = function () { return 3 };\n\nObject.defineProperties( Quadrant, staticAccessors$21 );\n\nvar EdgeEnd = function EdgeEnd () {\n this._edge = null;\n this._label = null;\n this._node = null;\n this._p0 = null;\n this._p1 = null;\n this._dx = null;\n this._dy = null;\n this._quadrant = null;\n if (arguments.length === 1) {\n var edge = arguments[0];\n this._edge = edge;\n } else if (arguments.length === 3) {\n var edge$1 = arguments[0];\n var p0 = arguments[1];\n var p1 = arguments[2];\n var label = null;\n this._edge = edge$1;\n this.init(p0, p1);\n this._label = label;\n } else if (arguments.length === 4) {\n var edge$2 = arguments[0];\n var p0$1 = arguments[1];\n var p1$1 = arguments[2];\n var label$1 = arguments[3];\n this._edge = edge$2;\n this.init(p0$1, p1$1);\n this._label = label$1;\n }\n};\nEdgeEnd.prototype.compareDirection = function compareDirection (e) {\n if (this._dx === e._dx && this._dy === e._dy) { return 0 }\n if (this._quadrant > e._quadrant) { return 1 }\n if (this._quadrant < e._quadrant) { return -1 }\n return CGAlgorithms.computeOrientation(e._p0, e._p1, this._p1)\n};\nEdgeEnd.prototype.getDy = function getDy () {\n return this._dy\n};\nEdgeEnd.prototype.getCoordinate = function getCoordinate () {\n return this._p0\n};\nEdgeEnd.prototype.setNode = function setNode (node) {\n this._node = node;\n};\nEdgeEnd.prototype.print = function print (out) {\n var angle = Math.atan2(this._dy, this._dx);\n var className = this.getClass().getName();\n var lastDotPos = className.lastIndexOf('.');\n var name = className.substring(lastDotPos + 1);\n out.print(' ' + name + ': ' + this._p0 + ' - ' + this._p1 + ' ' + this._quadrant + ':' + angle + ' ' + this._label);\n};\nEdgeEnd.prototype.compareTo = function compareTo (obj) {\n var e = obj;\n return this.compareDirection(e)\n};\nEdgeEnd.prototype.getDirectedCoordinate = function getDirectedCoordinate () {\n return this._p1\n};\nEdgeEnd.prototype.getDx = function getDx () {\n return this._dx\n};\nEdgeEnd.prototype.getLabel = function getLabel () {\n return this._label\n};\nEdgeEnd.prototype.getEdge = function getEdge () {\n return this._edge\n};\nEdgeEnd.prototype.getQuadrant = function getQuadrant () {\n return this._quadrant\n};\nEdgeEnd.prototype.getNode = function getNode () {\n return this._node\n};\nEdgeEnd.prototype.toString = function toString () {\n var angle = Math.atan2(this._dy, this._dx);\n var className = this.getClass().getName();\n var lastDotPos = className.lastIndexOf('.');\n var name = className.substring(lastDotPos + 1);\n return ' ' + name + ': ' + this._p0 + ' - ' + this._p1 + ' ' + this._quadrant + ':' + angle + ' ' + this._label\n};\nEdgeEnd.prototype.computeLabel = function computeLabel (boundaryNodeRule) {};\nEdgeEnd.prototype.init = function init (p0, p1) {\n this._p0 = p0;\n this._p1 = p1;\n this._dx = p1.x - p0.x;\n this._dy = p1.y - p0.y;\n this._quadrant = Quadrant.quadrant(this._dx, this._dy);\n Assert.isTrue(!(this._dx === 0 && this._dy === 0), 'EdgeEnd with identical endpoints found');\n};\nEdgeEnd.prototype.interfaces_ = function interfaces_ () {\n return [Comparable]\n};\nEdgeEnd.prototype.getClass = function getClass () {\n return EdgeEnd\n};\n\nvar DirectedEdge = (function (EdgeEnd$$1) {\n function DirectedEdge () {\n var edge = arguments[0];\n var isForward = arguments[1];\n EdgeEnd$$1.call(this, edge);\n this._isForward = null;\n this._isInResult = false;\n this._isVisited = false;\n this._sym = null;\n this._next = null;\n this._nextMin = null;\n this._edgeRing = null;\n this._minEdgeRing = null;\n this._depth = [0, -999, -999];\n this._isForward = isForward;\n if (isForward) {\n this.init(edge.getCoordinate(0), edge.getCoordinate(1));\n } else {\n var n = edge.getNumPoints() - 1;\n this.init(edge.getCoordinate(n), edge.getCoordinate(n - 1));\n }\n this.computeDirectedLabel();\n }\n\n if ( EdgeEnd$$1 ) DirectedEdge.__proto__ = EdgeEnd$$1;\n DirectedEdge.prototype = Object.create( EdgeEnd$$1 && EdgeEnd$$1.prototype );\n DirectedEdge.prototype.constructor = DirectedEdge;\n DirectedEdge.prototype.getNextMin = function getNextMin () {\n return this._nextMin\n };\n DirectedEdge.prototype.getDepth = function getDepth (position) {\n return this._depth[position]\n };\n DirectedEdge.prototype.setVisited = function setVisited (isVisited) {\n this._isVisited = isVisited;\n };\n DirectedEdge.prototype.computeDirectedLabel = function computeDirectedLabel () {\n this._label = new Label(this._edge.getLabel());\n if (!this._isForward) { this._label.flip(); }\n };\n DirectedEdge.prototype.getNext = function getNext () {\n return this._next\n };\n DirectedEdge.prototype.setDepth = function setDepth (position, depthVal) {\n if (this._depth[position] !== -999) {\n if (this._depth[position] !== depthVal) { throw new TopologyException('assigned depths do not match', this.getCoordinate()) }\n }\n this._depth[position] = depthVal;\n };\n DirectedEdge.prototype.isInteriorAreaEdge = function isInteriorAreaEdge () {\n var this$1 = this;\n\n var isInteriorAreaEdge = true;\n for (var i = 0; i < 2; i++) {\n if (!(this$1._label.isArea(i) && this$1._label.getLocation(i, Position.LEFT) === Location.INTERIOR && this$1._label.getLocation(i, Position.RIGHT) === Location.INTERIOR)) {\n isInteriorAreaEdge = false;\n }\n }\n return isInteriorAreaEdge\n };\n DirectedEdge.prototype.setNextMin = function setNextMin (nextMin) {\n this._nextMin = nextMin;\n };\n DirectedEdge.prototype.print = function print (out) {\n EdgeEnd$$1.prototype.print.call(this, out);\n out.print(' ' + this._depth[Position.LEFT] + '/' + this._depth[Position.RIGHT]);\n out.print(' (' + this.getDepthDelta() + ')');\n if (this._isInResult) { out.print(' inResult'); }\n };\n DirectedEdge.prototype.setMinEdgeRing = function setMinEdgeRing (minEdgeRing) {\n this._minEdgeRing = minEdgeRing;\n };\n DirectedEdge.prototype.isLineEdge = function isLineEdge () {\n var isLine = this._label.isLine(0) || this._label.isLine(1);\n var isExteriorIfArea0 = !this._label.isArea(0) || this._label.allPositionsEqual(0, Location.EXTERIOR);\n var isExteriorIfArea1 = !this._label.isArea(1) || this._label.allPositionsEqual(1, Location.EXTERIOR);\n return isLine && isExteriorIfArea0 && isExteriorIfArea1\n };\n DirectedEdge.prototype.setEdgeRing = function setEdgeRing (edgeRing) {\n this._edgeRing = edgeRing;\n };\n DirectedEdge.prototype.getMinEdgeRing = function getMinEdgeRing () {\n return this._minEdgeRing\n };\n DirectedEdge.prototype.getDepthDelta = function getDepthDelta () {\n var depthDelta = this._edge.getDepthDelta();\n if (!this._isForward) { depthDelta = -depthDelta; }\n return depthDelta\n };\n DirectedEdge.prototype.setInResult = function setInResult (isInResult) {\n this._isInResult = isInResult;\n };\n DirectedEdge.prototype.getSym = function getSym () {\n return this._sym\n };\n DirectedEdge.prototype.isForward = function isForward () {\n return this._isForward\n };\n DirectedEdge.prototype.getEdge = function getEdge () {\n return this._edge\n };\n DirectedEdge.prototype.printEdge = function printEdge (out) {\n this.print(out);\n out.print(' ');\n if (this._isForward) { this._edge.print(out); } else { this._edge.printReverse(out); }\n };\n DirectedEdge.prototype.setSym = function setSym (de) {\n this._sym = de;\n };\n DirectedEdge.prototype.setVisitedEdge = function setVisitedEdge (isVisited) {\n this.setVisited(isVisited);\n this._sym.setVisited(isVisited);\n };\n DirectedEdge.prototype.setEdgeDepths = function setEdgeDepths (position, depth) {\n var depthDelta = this.getEdge().getDepthDelta();\n if (!this._isForward) { depthDelta = -depthDelta; }\n var directionFactor = 1;\n if (position === Position.LEFT) { directionFactor = -1; }\n var oppositePos = Position.opposite(position);\n var delta = depthDelta * directionFactor;\n var oppositeDepth = depth + delta;\n this.setDepth(position, depth);\n this.setDepth(oppositePos, oppositeDepth);\n };\n DirectedEdge.prototype.getEdgeRing = function getEdgeRing () {\n return this._edgeRing\n };\n DirectedEdge.prototype.isInResult = function isInResult () {\n return this._isInResult\n };\n DirectedEdge.prototype.setNext = function setNext (next) {\n this._next = next;\n };\n DirectedEdge.prototype.isVisited = function isVisited () {\n return this._isVisited\n };\n DirectedEdge.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n DirectedEdge.prototype.getClass = function getClass () {\n return DirectedEdge\n };\n DirectedEdge.depthFactor = function depthFactor (currLocation, nextLocation) {\n if (currLocation === Location.EXTERIOR && nextLocation === Location.INTERIOR) { return 1; } else if (currLocation === Location.INTERIOR && nextLocation === Location.EXTERIOR) { return -1 }\n return 0\n };\n\n return DirectedEdge;\n}(EdgeEnd));\n\nvar NodeFactory = function NodeFactory () {};\n\nNodeFactory.prototype.createNode = function createNode (coord) {\n return new Node(coord, null)\n};\nNodeFactory.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nNodeFactory.prototype.getClass = function getClass () {\n return NodeFactory\n};\n\nvar PlanarGraph = function PlanarGraph () {\n this._edges = new ArrayList();\n this._nodes = null;\n this._edgeEndList = new ArrayList();\n if (arguments.length === 0) {\n this._nodes = new NodeMap(new NodeFactory());\n } else if (arguments.length === 1) {\n var nodeFact = arguments[0];\n this._nodes = new NodeMap(nodeFact);\n }\n};\nPlanarGraph.prototype.printEdges = function printEdges (out) {\n var this$1 = this;\n\n out.println('Edges:');\n for (var i = 0; i < this._edges.size(); i++) {\n out.println('edge ' + i + ':');\n var e = this$1._edges.get(i);\n e.print(out);\n e.eiList.print(out);\n }\n};\nPlanarGraph.prototype.find = function find (coord) {\n return this._nodes.find(coord)\n};\nPlanarGraph.prototype.addNode = function addNode () {\n if (arguments[0] instanceof Node) {\n var node = arguments[0];\n return this._nodes.addNode(node)\n } else if (arguments[0] instanceof Coordinate) {\n var coord = arguments[0];\n return this._nodes.addNode(coord)\n }\n};\nPlanarGraph.prototype.getNodeIterator = function getNodeIterator () {\n return this._nodes.iterator()\n};\nPlanarGraph.prototype.linkResultDirectedEdges = function linkResultDirectedEdges () {\n for (var nodeit = this._nodes.iterator(); nodeit.hasNext();) {\n var node = nodeit.next();\n node.getEdges().linkResultDirectedEdges();\n }\n};\nPlanarGraph.prototype.debugPrintln = function debugPrintln (o) {\n System.out.println(o);\n};\nPlanarGraph.prototype.isBoundaryNode = function isBoundaryNode (geomIndex, coord) {\n var node = this._nodes.find(coord);\n if (node === null) { return false }\n var label = node.getLabel();\n if (label !== null && label.getLocation(geomIndex) === Location.BOUNDARY) { return true }\n return false\n};\nPlanarGraph.prototype.linkAllDirectedEdges = function linkAllDirectedEdges () {\n for (var nodeit = this._nodes.iterator(); nodeit.hasNext();) {\n var node = nodeit.next();\n node.getEdges().linkAllDirectedEdges();\n }\n};\nPlanarGraph.prototype.matchInSameDirection = function matchInSameDirection (p0, p1, ep0, ep1) {\n if (!p0.equals(ep0)) { return false }\n if (CGAlgorithms.computeOrientation(p0, p1, ep1) === CGAlgorithms.COLLINEAR && Quadrant.quadrant(p0, p1) === Quadrant.quadrant(ep0, ep1)) { return true }\n return false\n};\nPlanarGraph.prototype.getEdgeEnds = function getEdgeEnds () {\n return this._edgeEndList\n};\nPlanarGraph.prototype.debugPrint = function debugPrint (o) {\n System.out.print(o);\n};\nPlanarGraph.prototype.getEdgeIterator = function getEdgeIterator () {\n return this._edges.iterator()\n};\nPlanarGraph.prototype.findEdgeInSameDirection = function findEdgeInSameDirection (p0, p1) {\n var this$1 = this;\n\n for (var i = 0; i < this._edges.size(); i++) {\n var e = this$1._edges.get(i);\n var eCoord = e.getCoordinates();\n if (this$1.matchInSameDirection(p0, p1, eCoord[0], eCoord[1])) { return e }\n if (this$1.matchInSameDirection(p0, p1, eCoord[eCoord.length - 1], eCoord[eCoord.length - 2])) { return e }\n }\n return null\n};\nPlanarGraph.prototype.insertEdge = function insertEdge (e) {\n this._edges.add(e);\n};\nPlanarGraph.prototype.findEdgeEnd = function findEdgeEnd (e) {\n for (var i = this.getEdgeEnds().iterator(); i.hasNext();) {\n var ee = i.next();\n if (ee.getEdge() === e) { return ee }\n }\n return null\n};\nPlanarGraph.prototype.addEdges = function addEdges (edgesToAdd) {\n var this$1 = this;\n\n for (var it = edgesToAdd.iterator(); it.hasNext();) {\n var e = it.next();\n this$1._edges.add(e);\n var de1 = new DirectedEdge(e, true);\n var de2 = new DirectedEdge(e, false);\n de1.setSym(de2);\n de2.setSym(de1);\n this$1.add(de1);\n this$1.add(de2);\n }\n};\nPlanarGraph.prototype.add = function add (e) {\n this._nodes.add(e);\n this._edgeEndList.add(e);\n};\nPlanarGraph.prototype.getNodes = function getNodes () {\n return this._nodes.values()\n};\nPlanarGraph.prototype.findEdge = function findEdge (p0, p1) {\n var this$1 = this;\n\n for (var i = 0; i < this._edges.size(); i++) {\n var e = this$1._edges.get(i);\n var eCoord = e.getCoordinates();\n if (p0.equals(eCoord[0]) && p1.equals(eCoord[1])) { return e }\n }\n return null\n};\nPlanarGraph.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nPlanarGraph.prototype.getClass = function getClass () {\n return PlanarGraph\n};\nPlanarGraph.linkResultDirectedEdges = function linkResultDirectedEdges (nodes) {\n for (var nodeit = nodes.iterator(); nodeit.hasNext();) {\n var node = nodeit.next();\n node.getEdges().linkResultDirectedEdges();\n }\n};\n\nvar PolygonBuilder = function PolygonBuilder () {\n this._geometryFactory = null;\n this._shellList = new ArrayList();\n var geometryFactory = arguments[0];\n this._geometryFactory = geometryFactory;\n};\nPolygonBuilder.prototype.sortShellsAndHoles = function sortShellsAndHoles (edgeRings, shellList, freeHoleList) {\n for (var it = edgeRings.iterator(); it.hasNext();) {\n var er = it.next();\n if (er.isHole()) {\n freeHoleList.add(er);\n } else {\n shellList.add(er);\n }\n }\n};\nPolygonBuilder.prototype.computePolygons = function computePolygons (shellList) {\n var this$1 = this;\n\n var resultPolyList = new ArrayList();\n for (var it = shellList.iterator(); it.hasNext();) {\n var er = it.next();\n var poly = er.toPolygon(this$1._geometryFactory);\n resultPolyList.add(poly);\n }\n return resultPolyList\n};\nPolygonBuilder.prototype.placeFreeHoles = function placeFreeHoles (shellList, freeHoleList) {\n var this$1 = this;\n\n for (var it = freeHoleList.iterator(); it.hasNext();) {\n var hole = it.next();\n if (hole.getShell() === null) {\n var shell = this$1.findEdgeRingContaining(hole, shellList);\n if (shell === null) { throw new TopologyException('unable to assign hole to a shell', hole.getCoordinate(0)) }\n hole.setShell(shell);\n }\n }\n};\nPolygonBuilder.prototype.buildMinimalEdgeRings = function buildMinimalEdgeRings (maxEdgeRings, shellList, freeHoleList) {\n var this$1 = this;\n\n var edgeRings = new ArrayList();\n for (var it = maxEdgeRings.iterator(); it.hasNext();) {\n var er = it.next();\n if (er.getMaxNodeDegree() > 2) {\n er.linkDirectedEdgesForMinimalEdgeRings();\n var minEdgeRings = er.buildMinimalRings();\n var shell = this$1.findShell(minEdgeRings);\n if (shell !== null) {\n this$1.placePolygonHoles(shell, minEdgeRings);\n shellList.add(shell);\n } else {\n freeHoleList.addAll(minEdgeRings);\n }\n } else {\n edgeRings.add(er);\n }\n }\n return edgeRings\n};\nPolygonBuilder.prototype.containsPoint = function containsPoint (p) {\n for (var it = this._shellList.iterator(); it.hasNext();) {\n var er = it.next();\n if (er.containsPoint(p)) { return true }\n }\n return false\n};\nPolygonBuilder.prototype.buildMaximalEdgeRings = function buildMaximalEdgeRings (dirEdges) {\n var this$1 = this;\n\n var maxEdgeRings = new ArrayList();\n for (var it = dirEdges.iterator(); it.hasNext();) {\n var de = it.next();\n if (de.isInResult() && de.getLabel().isArea()) {\n if (de.getEdgeRing() === null) {\n var er = new MaximalEdgeRing(de, this$1._geometryFactory);\n maxEdgeRings.add(er);\n er.setInResult();\n }\n }\n }\n return maxEdgeRings\n};\nPolygonBuilder.prototype.placePolygonHoles = function placePolygonHoles (shell, minEdgeRings) {\n for (var it = minEdgeRings.iterator(); it.hasNext();) {\n var er = it.next();\n if (er.isHole()) {\n er.setShell(shell);\n }\n }\n};\nPolygonBuilder.prototype.getPolygons = function getPolygons () {\n var resultPolyList = this.computePolygons(this._shellList);\n return resultPolyList\n};\nPolygonBuilder.prototype.findEdgeRingContaining = function findEdgeRingContaining (testEr, shellList) {\n var testRing = testEr.getLinearRing();\n var testEnv = testRing.getEnvelopeInternal();\n var testPt = testRing.getCoordinateN(0);\n var minShell = null;\n var minEnv = null;\n for (var it = shellList.iterator(); it.hasNext();) {\n var tryShell = it.next();\n var tryRing = tryShell.getLinearRing();\n var tryEnv = tryRing.getEnvelopeInternal();\n if (minShell !== null) { minEnv = minShell.getLinearRing().getEnvelopeInternal(); }\n var isContained = false;\n if (tryEnv.contains(testEnv) && CGAlgorithms.isPointInRing(testPt, tryRing.getCoordinates())) { isContained = true; }\n if (isContained) {\n if (minShell === null || minEnv.contains(tryEnv)) {\n minShell = tryShell;\n }\n }\n }\n return minShell\n};\nPolygonBuilder.prototype.findShell = function findShell (minEdgeRings) {\n var shellCount = 0;\n var shell = null;\n for (var it = minEdgeRings.iterator(); it.hasNext();) {\n var er = it.next();\n if (!er.isHole()) {\n shell = er;\n shellCount++;\n }\n }\n Assert.isTrue(shellCount <= 1, 'found two shells in MinimalEdgeRing list');\n return shell\n};\nPolygonBuilder.prototype.add = function add () {\n if (arguments.length === 1) {\n var graph = arguments[0];\n this.add(graph.getEdgeEnds(), graph.getNodes());\n } else if (arguments.length === 2) {\n var dirEdges = arguments[0];\n var nodes = arguments[1];\n PlanarGraph.linkResultDirectedEdges(nodes);\n var maxEdgeRings = this.buildMaximalEdgeRings(dirEdges);\n var freeHoleList = new ArrayList();\n var edgeRings = this.buildMinimalEdgeRings(maxEdgeRings, this._shellList, freeHoleList);\n this.sortShellsAndHoles(edgeRings, this._shellList, freeHoleList);\n this.placeFreeHoles(this._shellList, freeHoleList);\n }\n};\nPolygonBuilder.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nPolygonBuilder.prototype.getClass = function getClass () {\n return PolygonBuilder\n};\n\nvar Boundable = function Boundable () {};\n\nBoundable.prototype.getBounds = function getBounds () {};\nBoundable.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nBoundable.prototype.getClass = function getClass () {\n return Boundable\n};\n\nvar ItemBoundable = function ItemBoundable () {\n this._bounds = null;\n this._item = null;\n var bounds = arguments[0];\n var item = arguments[1];\n this._bounds = bounds;\n this._item = item;\n};\nItemBoundable.prototype.getItem = function getItem () {\n return this._item\n};\nItemBoundable.prototype.getBounds = function getBounds () {\n return this._bounds\n};\nItemBoundable.prototype.interfaces_ = function interfaces_ () {\n return [Boundable, Serializable]\n};\nItemBoundable.prototype.getClass = function getClass () {\n return ItemBoundable\n};\n\nvar PriorityQueue = function PriorityQueue () {\n this._size = null;\n this._items = null;\n this._size = 0;\n this._items = new ArrayList();\n this._items.add(null);\n};\nPriorityQueue.prototype.poll = function poll () {\n if (this.isEmpty()) { return null }\n var minItem = this._items.get(1);\n this._items.set(1, this._items.get(this._size));\n this._size -= 1;\n this.reorder(1);\n return minItem\n};\nPriorityQueue.prototype.size = function size () {\n return this._size\n};\nPriorityQueue.prototype.reorder = function reorder (hole) {\n var this$1 = this;\n\n var child = null;\n var tmp = this._items.get(hole);\n for (; hole * 2 <= this._size; hole = child) {\n child = hole * 2;\n if (child !== this$1._size && this$1._items.get(child + 1).compareTo(this$1._items.get(child)) < 0) { child++; }\n if (this$1._items.get(child).compareTo(tmp) < 0) { this$1._items.set(hole, this$1._items.get(child)); } else { break }\n }\n this._items.set(hole, tmp);\n};\nPriorityQueue.prototype.clear = function clear () {\n this._size = 0;\n this._items.clear();\n};\nPriorityQueue.prototype.isEmpty = function isEmpty () {\n return this._size === 0\n};\nPriorityQueue.prototype.add = function add (x) {\n var this$1 = this;\n\n this._items.add(null);\n this._size += 1;\n var hole = this._size;\n this._items.set(0, x);\n for (; x.compareTo(this._items.get(Math.trunc(hole / 2))) < 0; hole /= 2) {\n this$1._items.set(hole, this$1._items.get(Math.trunc(hole / 2)));\n }\n this._items.set(hole, x);\n};\nPriorityQueue.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nPriorityQueue.prototype.getClass = function getClass () {\n return PriorityQueue\n};\n\nvar ItemVisitor = function ItemVisitor () {};\n\nItemVisitor.prototype.visitItem = function visitItem (item) {};\nItemVisitor.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nItemVisitor.prototype.getClass = function getClass () {\n return ItemVisitor\n};\n\nvar SpatialIndex = function SpatialIndex () {};\n\nSpatialIndex.prototype.insert = function insert (itemEnv, item) {};\nSpatialIndex.prototype.remove = function remove (itemEnv, item) {};\nSpatialIndex.prototype.query = function query () {\n // if (arguments.length === 1) {\n // const searchEnv = arguments[0]\n // } else if (arguments.length === 2) {\n // const searchEnv = arguments[0]\n // const visitor = arguments[1]\n // }\n};\nSpatialIndex.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nSpatialIndex.prototype.getClass = function getClass () {\n return SpatialIndex\n};\n\nvar AbstractNode = function AbstractNode () {\n this._childBoundables = new ArrayList();\n this._bounds = null;\n this._level = null;\n if (arguments.length === 0) {} else if (arguments.length === 1) {\n var level = arguments[0];\n this._level = level;\n }\n};\n\nvar staticAccessors$22 = { serialVersionUID: { configurable: true } };\nAbstractNode.prototype.getLevel = function getLevel () {\n return this._level\n};\nAbstractNode.prototype.size = function size () {\n return this._childBoundables.size()\n};\nAbstractNode.prototype.getChildBoundables = function getChildBoundables () {\n return this._childBoundables\n};\nAbstractNode.prototype.addChildBoundable = function addChildBoundable (childBoundable) {\n Assert.isTrue(this._bounds === null);\n this._childBoundables.add(childBoundable);\n};\nAbstractNode.prototype.isEmpty = function isEmpty () {\n return this._childBoundables.isEmpty()\n};\nAbstractNode.prototype.getBounds = function getBounds () {\n if (this._bounds === null) {\n this._bounds = this.computeBounds();\n }\n return this._bounds\n};\nAbstractNode.prototype.interfaces_ = function interfaces_ () {\n return [Boundable, Serializable]\n};\nAbstractNode.prototype.getClass = function getClass () {\n return AbstractNode\n};\nstaticAccessors$22.serialVersionUID.get = function () { return 6493722185909573708 };\n\nObject.defineProperties( AbstractNode, staticAccessors$22 );\n\nvar Collections = function Collections () {};\n\nCollections.reverseOrder = function reverseOrder () {\n return {\n compare: function compare (a, b) {\n return b.compareTo(a)\n }\n }\n};\nCollections.min = function min (l) {\n Collections.sort(l);\n return l.get(0)\n};\nCollections.sort = function sort (l, c) {\n var a = l.toArray();\n if (c) {\n Arrays.sort(a, c);\n } else {\n Arrays.sort(a);\n }\n var i = l.iterator();\n for (var pos = 0, alen = a.length; pos < alen; pos++) {\n i.next();\n i.set(a[pos]);\n }\n};\nCollections.singletonList = function singletonList (o) {\n var arrayList = new ArrayList();\n arrayList.add(o);\n return arrayList\n};\n\nvar BoundablePair = function BoundablePair () {\n this._boundable1 = null;\n this._boundable2 = null;\n this._distance = null;\n this._itemDistance = null;\n var boundable1 = arguments[0];\n var boundable2 = arguments[1];\n var itemDistance = arguments[2];\n this._boundable1 = boundable1;\n this._boundable2 = boundable2;\n this._itemDistance = itemDistance;\n this._distance = this.distance();\n};\nBoundablePair.prototype.expandToQueue = function expandToQueue (priQ, minDistance) {\n var isComp1 = BoundablePair.isComposite(this._boundable1);\n var isComp2 = BoundablePair.isComposite(this._boundable2);\n if (isComp1 && isComp2) {\n if (BoundablePair.area(this._boundable1) > BoundablePair.area(this._boundable2)) {\n this.expand(this._boundable1, this._boundable2, priQ, minDistance);\n return null\n } else {\n this.expand(this._boundable2, this._boundable1, priQ, minDistance);\n return null\n }\n } else if (isComp1) {\n this.expand(this._boundable1, this._boundable2, priQ, minDistance);\n return null\n } else if (isComp2) {\n this.expand(this._boundable2, this._boundable1, priQ, minDistance);\n return null\n }\n throw new IllegalArgumentException('neither boundable is composite')\n};\nBoundablePair.prototype.isLeaves = function isLeaves () {\n return !(BoundablePair.isComposite(this._boundable1) || BoundablePair.isComposite(this._boundable2))\n};\nBoundablePair.prototype.compareTo = function compareTo (o) {\n var nd = o;\n if (this._distance < nd._distance) { return -1 }\n if (this._distance > nd._distance) { return 1 }\n return 0\n};\nBoundablePair.prototype.expand = function expand (bndComposite, bndOther, priQ, minDistance) {\n var this$1 = this;\n\n var children = bndComposite.getChildBoundables();\n for (var i = children.iterator(); i.hasNext();) {\n var child = i.next();\n var bp = new BoundablePair(child, bndOther, this$1._itemDistance);\n if (bp.getDistance() < minDistance) {\n priQ.add(bp);\n }\n }\n};\nBoundablePair.prototype.getBoundable = function getBoundable (i) {\n if (i === 0) { return this._boundable1 }\n return this._boundable2\n};\nBoundablePair.prototype.getDistance = function getDistance () {\n return this._distance\n};\nBoundablePair.prototype.distance = function distance () {\n if (this.isLeaves()) {\n return this._itemDistance.distance(this._boundable1, this._boundable2)\n }\n return this._boundable1.getBounds().distance(this._boundable2.getBounds())\n};\nBoundablePair.prototype.interfaces_ = function interfaces_ () {\n return [Comparable]\n};\nBoundablePair.prototype.getClass = function getClass () {\n return BoundablePair\n};\nBoundablePair.area = function area (b) {\n return b.getBounds().getArea()\n};\nBoundablePair.isComposite = function isComposite (item) {\n return item instanceof AbstractNode\n};\n\nvar AbstractSTRtree = function AbstractSTRtree () {\n this._root = null;\n this._built = false;\n this._itemBoundables = new ArrayList();\n this._nodeCapacity = null;\n if (arguments.length === 0) {\n var nodeCapacity = AbstractSTRtree.DEFAULT_NODE_CAPACITY;\n this._nodeCapacity = nodeCapacity;\n } else if (arguments.length === 1) {\n var nodeCapacity$1 = arguments[0];\n Assert.isTrue(nodeCapacity$1 > 1, 'Node capacity must be greater than 1');\n this._nodeCapacity = nodeCapacity$1;\n }\n};\n\nvar staticAccessors$23 = { IntersectsOp: { configurable: true },serialVersionUID: { configurable: true },DEFAULT_NODE_CAPACITY: { configurable: true } };\nAbstractSTRtree.prototype.getNodeCapacity = function getNodeCapacity () {\n return this._nodeCapacity\n};\nAbstractSTRtree.prototype.lastNode = function lastNode (nodes) {\n return nodes.get(nodes.size() - 1)\n};\nAbstractSTRtree.prototype.size = function size () {\n var this$1 = this;\n\n if (arguments.length === 0) {\n if (this.isEmpty()) {\n return 0\n }\n this.build();\n return this.size(this._root)\n } else if (arguments.length === 1) {\n var node = arguments[0];\n var size = 0;\n for (var i = node.getChildBoundables().iterator(); i.hasNext();) {\n var childBoundable = i.next();\n if (childBoundable instanceof AbstractNode) {\n size += this$1.size(childBoundable);\n } else if (childBoundable instanceof ItemBoundable) {\n size += 1;\n }\n }\n return size\n }\n};\nAbstractSTRtree.prototype.removeItem = function removeItem (node, item) {\n var childToRemove = null;\n for (var i = node.getChildBoundables().iterator(); i.hasNext();) {\n var childBoundable = i.next();\n if (childBoundable instanceof ItemBoundable) {\n if (childBoundable.getItem() === item) { childToRemove = childBoundable; }\n }\n }\n if (childToRemove !== null) {\n node.getChildBoundables().remove(childToRemove);\n return true\n }\n return false\n};\nAbstractSTRtree.prototype.itemsTree = function itemsTree () {\n var this$1 = this;\n\n if (arguments.length === 0) {\n this.build();\n var valuesTree = this.itemsTree(this._root);\n if (valuesTree === null) { return new ArrayList() }\n return valuesTree\n } else if (arguments.length === 1) {\n var node = arguments[0];\n var valuesTreeForNode = new ArrayList();\n for (var i = node.getChildBoundables().iterator(); i.hasNext();) {\n var childBoundable = i.next();\n if (childBoundable instanceof AbstractNode) {\n var valuesTreeForChild = this$1.itemsTree(childBoundable);\n if (valuesTreeForChild !== null) { valuesTreeForNode.add(valuesTreeForChild); }\n } else if (childBoundable instanceof ItemBoundable) {\n valuesTreeForNode.add(childBoundable.getItem());\n } else {\n Assert.shouldNeverReachHere();\n }\n }\n if (valuesTreeForNode.size() <= 0) { return null }\n return valuesTreeForNode\n }\n};\nAbstractSTRtree.prototype.insert = function insert (bounds, item) {\n Assert.isTrue(!this._built, 'Cannot insert items into an STR packed R-tree after it has been built.');\n this._itemBoundables.add(new ItemBoundable(bounds, item));\n};\nAbstractSTRtree.prototype.boundablesAtLevel = function boundablesAtLevel () {\n var this$1 = this;\n\n if (arguments.length === 1) {\n var level = arguments[0];\n var boundables = new ArrayList();\n this.boundablesAtLevel(level, this._root, boundables);\n return boundables\n } else if (arguments.length === 3) {\n var level$1 = arguments[0];\n var top = arguments[1];\n var boundables$1 = arguments[2];\n Assert.isTrue(level$1 > -2);\n if (top.getLevel() === level$1) {\n boundables$1.add(top);\n return null\n }\n for (var i = top.getChildBoundables().iterator(); i.hasNext();) {\n var boundable = i.next();\n if (boundable instanceof AbstractNode) {\n this$1.boundablesAtLevel(level$1, boundable, boundables$1);\n } else {\n Assert.isTrue(boundable instanceof ItemBoundable);\n if (level$1 === -1) {\n boundables$1.add(boundable);\n }\n }\n }\n return null\n }\n};\nAbstractSTRtree.prototype.query = function query () {\n var this$1 = this;\n\n if (arguments.length === 1) {\n var searchBounds = arguments[0];\n this.build();\n var matches = new ArrayList();\n if (this.isEmpty()) {\n return matches\n }\n if (this.getIntersectsOp().intersects(this._root.getBounds(), searchBounds)) {\n this.query(searchBounds, this._root, matches);\n }\n return matches\n } else if (arguments.length === 2) {\n var searchBounds$1 = arguments[0];\n var visitor = arguments[1];\n this.build();\n if (this.isEmpty()) {\n return null\n }\n if (this.getIntersectsOp().intersects(this._root.getBounds(), searchBounds$1)) {\n this.query(searchBounds$1, this._root, visitor);\n }\n } else if (arguments.length === 3) {\n if (hasInterface(arguments[2], ItemVisitor) && (arguments[0] instanceof Object && arguments[1] instanceof AbstractNode)) {\n var searchBounds$2 = arguments[0];\n var node = arguments[1];\n var visitor$1 = arguments[2];\n var childBoundables = node.getChildBoundables();\n for (var i = 0; i < childBoundables.size(); i++) {\n var childBoundable = childBoundables.get(i);\n if (!this$1.getIntersectsOp().intersects(childBoundable.getBounds(), searchBounds$2)) {\n continue\n }\n if (childBoundable instanceof AbstractNode) {\n this$1.query(searchBounds$2, childBoundable, visitor$1);\n } else if (childBoundable instanceof ItemBoundable) {\n visitor$1.visitItem(childBoundable.getItem());\n } else {\n Assert.shouldNeverReachHere();\n }\n }\n } else if (hasInterface(arguments[2], List) && (arguments[0] instanceof Object && arguments[1] instanceof AbstractNode)) {\n var searchBounds$3 = arguments[0];\n var node$1 = arguments[1];\n var matches$1 = arguments[2];\n var childBoundables$1 = node$1.getChildBoundables();\n for (var i$1 = 0; i$1 < childBoundables$1.size(); i$1++) {\n var childBoundable$1 = childBoundables$1.get(i$1);\n if (!this$1.getIntersectsOp().intersects(childBoundable$1.getBounds(), searchBounds$3)) {\n continue\n }\n if (childBoundable$1 instanceof AbstractNode) {\n this$1.query(searchBounds$3, childBoundable$1, matches$1);\n } else if (childBoundable$1 instanceof ItemBoundable) {\n matches$1.add(childBoundable$1.getItem());\n } else {\n Assert.shouldNeverReachHere();\n }\n }\n }\n }\n};\nAbstractSTRtree.prototype.build = function build () {\n if (this._built) { return null }\n this._root = this._itemBoundables.isEmpty() ? this.createNode(0) : this.createHigherLevels(this._itemBoundables, -1);\n this._itemBoundables = null;\n this._built = true;\n};\nAbstractSTRtree.prototype.getRoot = function getRoot () {\n this.build();\n return this._root\n};\nAbstractSTRtree.prototype.remove = function remove () {\n var this$1 = this;\n\n if (arguments.length === 2) {\n var searchBounds = arguments[0];\n var item = arguments[1];\n this.build();\n if (this.getIntersectsOp().intersects(this._root.getBounds(), searchBounds)) {\n return this.remove(searchBounds, this._root, item)\n }\n return false\n } else if (arguments.length === 3) {\n var searchBounds$1 = arguments[0];\n var node = arguments[1];\n var item$1 = arguments[2];\n var found = this.removeItem(node, item$1);\n if (found) { return true }\n var childToPrune = null;\n for (var i = node.getChildBoundables().iterator(); i.hasNext();) {\n var childBoundable = i.next();\n if (!this$1.getIntersectsOp().intersects(childBoundable.getBounds(), searchBounds$1)) {\n continue\n }\n if (childBoundable instanceof AbstractNode) {\n found = this$1.remove(searchBounds$1, childBoundable, item$1);\n if (found) {\n childToPrune = childBoundable;\n break\n }\n }\n }\n if (childToPrune !== null) {\n if (childToPrune.getChildBoundables().isEmpty()) {\n node.getChildBoundables().remove(childToPrune);\n }\n }\n return found\n }\n};\nAbstractSTRtree.prototype.createHigherLevels = function createHigherLevels (boundablesOfALevel, level) {\n Assert.isTrue(!boundablesOfALevel.isEmpty());\n var parentBoundables = this.createParentBoundables(boundablesOfALevel, level + 1);\n if (parentBoundables.size() === 1) {\n return parentBoundables.get(0)\n }\n return this.createHigherLevels(parentBoundables, level + 1)\n};\nAbstractSTRtree.prototype.depth = function depth () {\n var this$1 = this;\n\n if (arguments.length === 0) {\n if (this.isEmpty()) {\n return 0\n }\n this.build();\n return this.depth(this._root)\n } else if (arguments.length === 1) {\n var node = arguments[0];\n var maxChildDepth = 0;\n for (var i = node.getChildBoundables().iterator(); i.hasNext();) {\n var childBoundable = i.next();\n if (childBoundable instanceof AbstractNode) {\n var childDepth = this$1.depth(childBoundable);\n if (childDepth > maxChildDepth) { maxChildDepth = childDepth; }\n }\n }\n return maxChildDepth + 1\n }\n};\nAbstractSTRtree.prototype.createParentBoundables = function createParentBoundables (childBoundables, newLevel) {\n var this$1 = this;\n\n Assert.isTrue(!childBoundables.isEmpty());\n var parentBoundables = new ArrayList();\n parentBoundables.add(this.createNode(newLevel));\n var sortedChildBoundables = new ArrayList(childBoundables);\n Collections.sort(sortedChildBoundables, this.getComparator());\n for (var i = sortedChildBoundables.iterator(); i.hasNext();) {\n var childBoundable = i.next();\n if (this$1.lastNode(parentBoundables).getChildBoundables().size() === this$1.getNodeCapacity()) {\n parentBoundables.add(this$1.createNode(newLevel));\n }\n this$1.lastNode(parentBoundables).addChildBoundable(childBoundable);\n }\n return parentBoundables\n};\nAbstractSTRtree.prototype.isEmpty = function isEmpty () {\n if (!this._built) { return this._itemBoundables.isEmpty() }\n return this._root.isEmpty()\n};\nAbstractSTRtree.prototype.interfaces_ = function interfaces_ () {\n return [Serializable]\n};\nAbstractSTRtree.prototype.getClass = function getClass () {\n return AbstractSTRtree\n};\nAbstractSTRtree.compareDoubles = function compareDoubles (a, b) {\n return a > b ? 1 : a < b ? -1 : 0\n};\nstaticAccessors$23.IntersectsOp.get = function () { return IntersectsOp };\nstaticAccessors$23.serialVersionUID.get = function () { return -3886435814360241337 };\nstaticAccessors$23.DEFAULT_NODE_CAPACITY.get = function () { return 10 };\n\nObject.defineProperties( AbstractSTRtree, staticAccessors$23 );\n\nvar IntersectsOp = function IntersectsOp () {};\n\nvar ItemDistance = function ItemDistance () {};\n\nItemDistance.prototype.distance = function distance (item1, item2) {};\nItemDistance.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nItemDistance.prototype.getClass = function getClass () {\n return ItemDistance\n};\n\nvar STRtree = (function (AbstractSTRtree$$1) {\n function STRtree (nodeCapacity) {\n nodeCapacity = nodeCapacity || STRtree.DEFAULT_NODE_CAPACITY;\n AbstractSTRtree$$1.call(this, nodeCapacity);\n }\n\n if ( AbstractSTRtree$$1 ) STRtree.__proto__ = AbstractSTRtree$$1;\n STRtree.prototype = Object.create( AbstractSTRtree$$1 && AbstractSTRtree$$1.prototype );\n STRtree.prototype.constructor = STRtree;\n\n var staticAccessors = { STRtreeNode: { configurable: true },serialVersionUID: { configurable: true },xComparator: { configurable: true },yComparator: { configurable: true },intersectsOp: { configurable: true },DEFAULT_NODE_CAPACITY: { configurable: true } };\n STRtree.prototype.createParentBoundablesFromVerticalSlices = function createParentBoundablesFromVerticalSlices (verticalSlices, newLevel) {\n var this$1 = this;\n\n Assert.isTrue(verticalSlices.length > 0);\n var parentBoundables = new ArrayList();\n for (var i = 0; i < verticalSlices.length; i++) {\n parentBoundables.addAll(this$1.createParentBoundablesFromVerticalSlice(verticalSlices[i], newLevel));\n }\n return parentBoundables\n };\n STRtree.prototype.createNode = function createNode (level) {\n return new STRtreeNode(level)\n };\n STRtree.prototype.size = function size () {\n if (arguments.length === 0) {\n return AbstractSTRtree$$1.prototype.size.call(this)\n } else { return AbstractSTRtree$$1.prototype.size.apply(this, arguments) }\n };\n STRtree.prototype.insert = function insert () {\n if (arguments.length === 2) {\n var itemEnv = arguments[0];\n var item = arguments[1];\n if (itemEnv.isNull()) {\n return null\n }\n AbstractSTRtree$$1.prototype.insert.call(this, itemEnv, item);\n } else { return AbstractSTRtree$$1.prototype.insert.apply(this, arguments) }\n };\n STRtree.prototype.getIntersectsOp = function getIntersectsOp () {\n return STRtree.intersectsOp\n };\n STRtree.prototype.verticalSlices = function verticalSlices (childBoundables, sliceCount) {\n var sliceCapacity = Math.trunc(Math.ceil(childBoundables.size() / sliceCount));\n var slices = new Array(sliceCount).fill(null);\n var i = childBoundables.iterator();\n for (var j = 0; j < sliceCount; j++) {\n slices[j] = new ArrayList();\n var boundablesAddedToSlice = 0;\n while (i.hasNext() && boundablesAddedToSlice < sliceCapacity) {\n var childBoundable = i.next();\n slices[j].add(childBoundable);\n boundablesAddedToSlice++;\n }\n }\n return slices\n };\n STRtree.prototype.query = function query () {\n if (arguments.length === 1) {\n var searchEnv = arguments[0];\n return AbstractSTRtree$$1.prototype.query.call(this, searchEnv)\n } else if (arguments.length === 2) {\n var searchEnv$1 = arguments[0];\n var visitor = arguments[1];\n AbstractSTRtree$$1.prototype.query.call(this, searchEnv$1, visitor);\n } else if (arguments.length === 3) {\n if (hasInterface(arguments[2], ItemVisitor) && (arguments[0] instanceof Object && arguments[1] instanceof AbstractNode)) {\n var searchBounds = arguments[0];\n var node = arguments[1];\n var visitor$1 = arguments[2];\n AbstractSTRtree$$1.prototype.query.call(this, searchBounds, node, visitor$1);\n } else if (hasInterface(arguments[2], List) && (arguments[0] instanceof Object && arguments[1] instanceof AbstractNode)) {\n var searchBounds$1 = arguments[0];\n var node$1 = arguments[1];\n var matches = arguments[2];\n AbstractSTRtree$$1.prototype.query.call(this, searchBounds$1, node$1, matches);\n }\n }\n };\n STRtree.prototype.getComparator = function getComparator () {\n return STRtree.yComparator\n };\n STRtree.prototype.createParentBoundablesFromVerticalSlice = function createParentBoundablesFromVerticalSlice (childBoundables, newLevel) {\n return AbstractSTRtree$$1.prototype.createParentBoundables.call(this, childBoundables, newLevel)\n };\n STRtree.prototype.remove = function remove () {\n if (arguments.length === 2) {\n var itemEnv = arguments[0];\n var item = arguments[1];\n return AbstractSTRtree$$1.prototype.remove.call(this, itemEnv, item)\n } else { return AbstractSTRtree$$1.prototype.remove.apply(this, arguments) }\n };\n STRtree.prototype.depth = function depth () {\n if (arguments.length === 0) {\n return AbstractSTRtree$$1.prototype.depth.call(this)\n } else { return AbstractSTRtree$$1.prototype.depth.apply(this, arguments) }\n };\n STRtree.prototype.createParentBoundables = function createParentBoundables (childBoundables, newLevel) {\n Assert.isTrue(!childBoundables.isEmpty());\n var minLeafCount = Math.trunc(Math.ceil(childBoundables.size() / this.getNodeCapacity()));\n var sortedChildBoundables = new ArrayList(childBoundables);\n Collections.sort(sortedChildBoundables, STRtree.xComparator);\n var verticalSlices = this.verticalSlices(sortedChildBoundables, Math.trunc(Math.ceil(Math.sqrt(minLeafCount))));\n return this.createParentBoundablesFromVerticalSlices(verticalSlices, newLevel)\n };\n STRtree.prototype.nearestNeighbour = function nearestNeighbour () {\n if (arguments.length === 1) {\n if (hasInterface(arguments[0], ItemDistance)) {\n var itemDist = arguments[0];\n var bp = new BoundablePair(this.getRoot(), this.getRoot(), itemDist);\n return this.nearestNeighbour(bp)\n } else if (arguments[0] instanceof BoundablePair) {\n var initBndPair = arguments[0];\n return this.nearestNeighbour(initBndPair, Double.POSITIVE_INFINITY)\n }\n } else if (arguments.length === 2) {\n if (arguments[0] instanceof STRtree && hasInterface(arguments[1], ItemDistance)) {\n var tree = arguments[0];\n var itemDist$1 = arguments[1];\n var bp$1 = new BoundablePair(this.getRoot(), tree.getRoot(), itemDist$1);\n return this.nearestNeighbour(bp$1)\n } else if (arguments[0] instanceof BoundablePair && typeof arguments[1] === 'number') {\n var initBndPair$1 = arguments[0];\n var maxDistance = arguments[1];\n var distanceLowerBound = maxDistance;\n var minPair = null;\n var priQ = new PriorityQueue();\n priQ.add(initBndPair$1);\n while (!priQ.isEmpty() && distanceLowerBound > 0.0) {\n var bndPair = priQ.poll();\n var currentDistance = bndPair.getDistance();\n if (currentDistance >= distanceLowerBound) { break }\n if (bndPair.isLeaves()) {\n distanceLowerBound = currentDistance;\n minPair = bndPair;\n } else {\n bndPair.expandToQueue(priQ, distanceLowerBound);\n }\n }\n return [minPair.getBoundable(0).getItem(), minPair.getBoundable(1).getItem()]\n }\n } else if (arguments.length === 3) {\n var env = arguments[0];\n var item = arguments[1];\n var itemDist$2 = arguments[2];\n var bnd = new ItemBoundable(env, item);\n var bp$2 = new BoundablePair(this.getRoot(), bnd, itemDist$2);\n return this.nearestNeighbour(bp$2)[0]\n }\n };\n STRtree.prototype.interfaces_ = function interfaces_ () {\n return [SpatialIndex, Serializable]\n };\n STRtree.prototype.getClass = function getClass () {\n return STRtree\n };\n STRtree.centreX = function centreX (e) {\n return STRtree.avg(e.getMinX(), e.getMaxX())\n };\n STRtree.avg = function avg (a, b) {\n return (a + b) / 2\n };\n STRtree.centreY = function centreY (e) {\n return STRtree.avg(e.getMinY(), e.getMaxY())\n };\n staticAccessors.STRtreeNode.get = function () { return STRtreeNode };\n staticAccessors.serialVersionUID.get = function () { return 259274702368956900 };\n staticAccessors.xComparator.get = function () {\n return {\n interfaces_: function () {\n return [Comparator]\n },\n compare: function (o1, o2) {\n return AbstractSTRtree$$1.compareDoubles(STRtree.centreX(o1.getBounds()), STRtree.centreX(o2.getBounds()))\n }\n }\n };\n staticAccessors.yComparator.get = function () {\n return {\n interfaces_: function () {\n return [Comparator]\n },\n compare: function (o1, o2) {\n return AbstractSTRtree$$1.compareDoubles(STRtree.centreY(o1.getBounds()), STRtree.centreY(o2.getBounds()))\n }\n }\n };\n staticAccessors.intersectsOp.get = function () {\n return {\n interfaces_: function () {\n return [AbstractSTRtree$$1.IntersectsOp]\n },\n intersects: function (aBounds, bBounds) {\n return aBounds.intersects(bBounds)\n }\n }\n };\n staticAccessors.DEFAULT_NODE_CAPACITY.get = function () { return 10 };\n\n Object.defineProperties( STRtree, staticAccessors );\n\n return STRtree;\n}(AbstractSTRtree));\n\nvar STRtreeNode = (function (AbstractNode$$1) {\n function STRtreeNode () {\n var level = arguments[0];\n AbstractNode$$1.call(this, level);\n }\n\n if ( AbstractNode$$1 ) STRtreeNode.__proto__ = AbstractNode$$1;\n STRtreeNode.prototype = Object.create( AbstractNode$$1 && AbstractNode$$1.prototype );\n STRtreeNode.prototype.constructor = STRtreeNode;\n STRtreeNode.prototype.computeBounds = function computeBounds () {\n var bounds = null;\n for (var i = this.getChildBoundables().iterator(); i.hasNext();) {\n var childBoundable = i.next();\n if (bounds === null) {\n bounds = new Envelope(childBoundable.getBounds());\n } else {\n bounds.expandToInclude(childBoundable.getBounds());\n }\n }\n return bounds\n };\n STRtreeNode.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n STRtreeNode.prototype.getClass = function getClass () {\n return STRtreeNode\n };\n\n return STRtreeNode;\n}(AbstractNode));\n\nvar SegmentPointComparator = function SegmentPointComparator () {};\n\nSegmentPointComparator.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nSegmentPointComparator.prototype.getClass = function getClass () {\n return SegmentPointComparator\n};\nSegmentPointComparator.relativeSign = function relativeSign (x0, x1) {\n if (x0 < x1) { return -1 }\n if (x0 > x1) { return 1 }\n return 0\n};\nSegmentPointComparator.compare = function compare (octant, p0, p1) {\n if (p0.equals2D(p1)) { return 0 }\n var xSign = SegmentPointComparator.relativeSign(p0.x, p1.x);\n var ySign = SegmentPointComparator.relativeSign(p0.y, p1.y);\n switch (octant) {\n case 0:\n return SegmentPointComparator.compareValue(xSign, ySign)\n case 1:\n return SegmentPointComparator.compareValue(ySign, xSign)\n case 2:\n return SegmentPointComparator.compareValue(ySign, -xSign)\n case 3:\n return SegmentPointComparator.compareValue(-xSign, ySign)\n case 4:\n return SegmentPointComparator.compareValue(-xSign, -ySign)\n case 5:\n return SegmentPointComparator.compareValue(-ySign, -xSign)\n case 6:\n return SegmentPointComparator.compareValue(-ySign, xSign)\n case 7:\n return SegmentPointComparator.compareValue(xSign, -ySign)\n default:\n }\n Assert.shouldNeverReachHere('invalid octant value');\n return 0\n};\nSegmentPointComparator.compareValue = function compareValue (compareSign0, compareSign1) {\n if (compareSign0 < 0) { return -1 }\n if (compareSign0 > 0) { return 1 }\n if (compareSign1 < 0) { return -1 }\n if (compareSign1 > 0) { return 1 }\n return 0\n};\n\nvar SegmentNode = function SegmentNode () {\n this._segString = null;\n this.coord = null;\n this.segmentIndex = null;\n this._segmentOctant = null;\n this._isInterior = null;\n var segString = arguments[0];\n var coord = arguments[1];\n var segmentIndex = arguments[2];\n var segmentOctant = arguments[3];\n this._segString = segString;\n this.coord = new Coordinate(coord);\n this.segmentIndex = segmentIndex;\n this._segmentOctant = segmentOctant;\n this._isInterior = !coord.equals2D(segString.getCoordinate(segmentIndex));\n};\nSegmentNode.prototype.getCoordinate = function getCoordinate () {\n return this.coord\n};\nSegmentNode.prototype.print = function print (out) {\n out.print(this.coord);\n out.print(' seg # = ' + this.segmentIndex);\n};\nSegmentNode.prototype.compareTo = function compareTo (obj) {\n var other = obj;\n if (this.segmentIndex < other.segmentIndex) { return -1 }\n if (this.segmentIndex > other.segmentIndex) { return 1 }\n if (this.coord.equals2D(other.coord)) { return 0 }\n return SegmentPointComparator.compare(this._segmentOctant, this.coord, other.coord)\n};\nSegmentNode.prototype.isEndPoint = function isEndPoint (maxSegmentIndex) {\n if (this.segmentIndex === 0 && !this._isInterior) { return true }\n if (this.segmentIndex === maxSegmentIndex) { return true }\n return false\n};\nSegmentNode.prototype.isInterior = function isInterior () {\n return this._isInterior\n};\nSegmentNode.prototype.interfaces_ = function interfaces_ () {\n return [Comparable]\n};\nSegmentNode.prototype.getClass = function getClass () {\n return SegmentNode\n};\n\n// import Iterator from '../../../../java/util/Iterator'\nvar SegmentNodeList = function SegmentNodeList () {\n this._nodeMap = new TreeMap();\n this._edge = null;\n var edge = arguments[0];\n this._edge = edge;\n};\nSegmentNodeList.prototype.getSplitCoordinates = function getSplitCoordinates () {\n var this$1 = this;\n\n var coordList = new CoordinateList();\n this.addEndpoints();\n var it = this.iterator();\n var eiPrev = it.next();\n while (it.hasNext()) {\n var ei = it.next();\n this$1.addEdgeCoordinates(eiPrev, ei, coordList);\n eiPrev = ei;\n }\n return coordList.toCoordinateArray()\n};\nSegmentNodeList.prototype.addCollapsedNodes = function addCollapsedNodes () {\n var this$1 = this;\n\n var collapsedVertexIndexes = new ArrayList();\n this.findCollapsesFromInsertedNodes(collapsedVertexIndexes);\n this.findCollapsesFromExistingVertices(collapsedVertexIndexes);\n for (var it = collapsedVertexIndexes.iterator(); it.hasNext();) {\n var vertexIndex = it.next().intValue();\n this$1.add(this$1._edge.getCoordinate(vertexIndex), vertexIndex);\n }\n};\nSegmentNodeList.prototype.print = function print (out) {\n out.println('Intersections:');\n for (var it = this.iterator(); it.hasNext();) {\n var ei = it.next();\n ei.print(out);\n }\n};\nSegmentNodeList.prototype.findCollapsesFromExistingVertices = function findCollapsesFromExistingVertices (collapsedVertexIndexes) {\n var this$1 = this;\n\n for (var i = 0; i < this._edge.size() - 2; i++) {\n var p0 = this$1._edge.getCoordinate(i);\n // const p1 = this._edge.getCoordinate(i + 1)\n var p2 = this$1._edge.getCoordinate(i + 2);\n if (p0.equals2D(p2)) {\n collapsedVertexIndexes.add(new Integer(i + 1));\n }\n }\n};\nSegmentNodeList.prototype.addEdgeCoordinates = function addEdgeCoordinates (ei0, ei1, coordList) {\n var this$1 = this;\n\n // let npts = ei1.segmentIndex - ei0.segmentIndex + 2\n var lastSegStartPt = this._edge.getCoordinate(ei1.segmentIndex);\n var useIntPt1 = ei1.isInterior() || !ei1.coord.equals2D(lastSegStartPt);\n // if (!useIntPt1) {\n // npts--\n // }\n // const ipt = 0\n coordList.add(new Coordinate(ei0.coord), false);\n for (var i = ei0.segmentIndex + 1; i <= ei1.segmentIndex; i++) {\n coordList.add(this$1._edge.getCoordinate(i));\n }\n if (useIntPt1) {\n coordList.add(new Coordinate(ei1.coord));\n }\n};\nSegmentNodeList.prototype.iterator = function iterator () {\n return this._nodeMap.values().iterator()\n};\nSegmentNodeList.prototype.addSplitEdges = function addSplitEdges (edgeList) {\n var this$1 = this;\n\n this.addEndpoints();\n this.addCollapsedNodes();\n var it = this.iterator();\n var eiPrev = it.next();\n while (it.hasNext()) {\n var ei = it.next();\n var newEdge = this$1.createSplitEdge(eiPrev, ei);\n edgeList.add(newEdge);\n eiPrev = ei;\n }\n};\nSegmentNodeList.prototype.findCollapseIndex = function findCollapseIndex (ei0, ei1, collapsedVertexIndex) {\n if (!ei0.coord.equals2D(ei1.coord)) { return false }\n var numVerticesBetween = ei1.segmentIndex - ei0.segmentIndex;\n if (!ei1.isInterior()) {\n numVerticesBetween--;\n }\n if (numVerticesBetween === 1) {\n collapsedVertexIndex[0] = ei0.segmentIndex + 1;\n return true\n }\n return false\n};\nSegmentNodeList.prototype.findCollapsesFromInsertedNodes = function findCollapsesFromInsertedNodes (collapsedVertexIndexes) {\n var this$1 = this;\n\n var collapsedVertexIndex = new Array(1).fill(null);\n var it = this.iterator();\n var eiPrev = it.next();\n while (it.hasNext()) {\n var ei = it.next();\n var isCollapsed = this$1.findCollapseIndex(eiPrev, ei, collapsedVertexIndex);\n if (isCollapsed) { collapsedVertexIndexes.add(new Integer(collapsedVertexIndex[0])); }\n eiPrev = ei;\n }\n};\nSegmentNodeList.prototype.getEdge = function getEdge () {\n return this._edge\n};\nSegmentNodeList.prototype.addEndpoints = function addEndpoints () {\n var maxSegIndex = this._edge.size() - 1;\n this.add(this._edge.getCoordinate(0), 0);\n this.add(this._edge.getCoordinate(maxSegIndex), maxSegIndex);\n};\nSegmentNodeList.prototype.createSplitEdge = function createSplitEdge (ei0, ei1) {\n var this$1 = this;\n\n var npts = ei1.segmentIndex - ei0.segmentIndex + 2;\n var lastSegStartPt = this._edge.getCoordinate(ei1.segmentIndex);\n var useIntPt1 = ei1.isInterior() || !ei1.coord.equals2D(lastSegStartPt);\n if (!useIntPt1) {\n npts--;\n }\n var pts = new Array(npts).fill(null);\n var ipt = 0;\n pts[ipt++] = new Coordinate(ei0.coord);\n for (var i = ei0.segmentIndex + 1; i <= ei1.segmentIndex; i++) {\n pts[ipt++] = this$1._edge.getCoordinate(i);\n }\n if (useIntPt1) { pts[ipt] = new Coordinate(ei1.coord); }\n return new NodedSegmentString(pts, this._edge.getData())\n};\nSegmentNodeList.prototype.add = function add (intPt, segmentIndex) {\n var eiNew = new SegmentNode(this._edge, intPt, segmentIndex, this._edge.getSegmentOctant(segmentIndex));\n var ei = this._nodeMap.get(eiNew);\n if (ei !== null) {\n Assert.isTrue(ei.coord.equals2D(intPt), 'Found equal nodes with different coordinates');\n return ei\n }\n this._nodeMap.put(eiNew, eiNew);\n return eiNew\n};\nSegmentNodeList.prototype.checkSplitEdgesCorrectness = function checkSplitEdgesCorrectness (splitEdges) {\n var edgePts = this._edge.getCoordinates();\n var split0 = splitEdges.get(0);\n var pt0 = split0.getCoordinate(0);\n if (!pt0.equals2D(edgePts[0])) { throw new RuntimeException('bad split edge start point at ' + pt0) }\n var splitn = splitEdges.get(splitEdges.size() - 1);\n var splitnPts = splitn.getCoordinates();\n var ptn = splitnPts[splitnPts.length - 1];\n if (!ptn.equals2D(edgePts[edgePts.length - 1])) { throw new RuntimeException('bad split edge end point at ' + ptn) }\n};\nSegmentNodeList.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nSegmentNodeList.prototype.getClass = function getClass () {\n return SegmentNodeList\n};\n\n\n\n// class NodeVertexIterator {\n// constructor () {\n// this._nodeList = null\n// this._edge = null\n// this._nodeIt = null\n// this._currNode = null\n// this._nextNode = null\n// this._currSegIndex = 0\n// let nodeList = arguments[0]\n// this._nodeList = nodeList\n// this._edge = nodeList.getEdge()\n// this._nodeIt = nodeList.iterator()\n// this.readNextNode()\n// }\n// next () {\n// if (this._currNode === null) {\n// this._currNode = this._nextNode\n// this._currSegIndex = this._currNode.segmentIndex\n// this.readNextNode()\n// return this._currNode\n// }\n// if (this._nextNode === null) return null\n// if (this._nextNode.segmentIndex === this._currNode.segmentIndex) {\n// this._currNode = this._nextNode\n// this._currSegIndex = this._currNode.segmentIndex\n// this.readNextNode()\n// return this._currNode\n// }\n// if (this._nextNode.segmentIndex > this._currNode.segmentIndex) {}\n// return null\n// }\n// remove () {\n// // throw new UnsupportedOperationException(this.getClass().getName())\n// }\n// hasNext () {\n// if (this._nextNode === null) return false\n// return true\n// }\n// readNextNode () {\n// if (this._nodeIt.hasNext()) this._nextNode = this._nodeIt.next(); else this._nextNode = null\n// }\n// interfaces_ () {\n// return [Iterator]\n// }\n// getClass () {\n// return NodeVertexIterator\n// }\n// }\n\nvar Octant = function Octant () {};\n\nOctant.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nOctant.prototype.getClass = function getClass () {\n return Octant\n};\nOctant.octant = function octant () {\n if (typeof arguments[0] === 'number' && typeof arguments[1] === 'number') {\n var dx = arguments[0];\n var dy = arguments[1];\n if (dx === 0.0 && dy === 0.0) { throw new IllegalArgumentException('Cannot compute the octant for point ( ' + dx + ', ' + dy + ' )') }\n var adx = Math.abs(dx);\n var ady = Math.abs(dy);\n if (dx >= 0) {\n if (dy >= 0) {\n if (adx >= ady) { return 0; } else { return 1 }\n } else {\n if (adx >= ady) { return 7; } else { return 6 }\n }\n } else {\n if (dy >= 0) {\n if (adx >= ady) { return 3; } else { return 2 }\n } else {\n if (adx >= ady) { return 4; } else { return 5 }\n }\n }\n } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Coordinate) {\n var p0 = arguments[0];\n var p1 = arguments[1];\n var dx$1 = p1.x - p0.x;\n var dy$1 = p1.y - p0.y;\n if (dx$1 === 0.0 && dy$1 === 0.0) { throw new IllegalArgumentException('Cannot compute the octant for two identical points ' + p0) }\n return Octant.octant(dx$1, dy$1)\n }\n};\n\nvar SegmentString = function SegmentString () {};\n\nSegmentString.prototype.getCoordinates = function getCoordinates () {};\nSegmentString.prototype.size = function size () {};\nSegmentString.prototype.getCoordinate = function getCoordinate (i) {};\nSegmentString.prototype.isClosed = function isClosed () {};\nSegmentString.prototype.setData = function setData (data) {};\nSegmentString.prototype.getData = function getData () {};\nSegmentString.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nSegmentString.prototype.getClass = function getClass () {\n return SegmentString\n};\n\nvar NodableSegmentString = function NodableSegmentString () {};\n\nNodableSegmentString.prototype.addIntersection = function addIntersection (intPt, segmentIndex) {};\nNodableSegmentString.prototype.interfaces_ = function interfaces_ () {\n return [SegmentString]\n};\nNodableSegmentString.prototype.getClass = function getClass () {\n return NodableSegmentString\n};\n\nvar NodedSegmentString = function NodedSegmentString () {\n this._nodeList = new SegmentNodeList(this);\n this._pts = null;\n this._data = null;\n var pts = arguments[0];\n var data = arguments[1];\n this._pts = pts;\n this._data = data;\n};\nNodedSegmentString.prototype.getCoordinates = function getCoordinates () {\n return this._pts\n};\nNodedSegmentString.prototype.size = function size () {\n return this._pts.length\n};\nNodedSegmentString.prototype.getCoordinate = function getCoordinate (i) {\n return this._pts[i]\n};\nNodedSegmentString.prototype.isClosed = function isClosed () {\n return this._pts[0].equals(this._pts[this._pts.length - 1])\n};\nNodedSegmentString.prototype.getSegmentOctant = function getSegmentOctant (index) {\n if (index === this._pts.length - 1) { return -1 }\n return this.safeOctant(this.getCoordinate(index), this.getCoordinate(index + 1))\n};\nNodedSegmentString.prototype.setData = function setData (data) {\n this._data = data;\n};\nNodedSegmentString.prototype.safeOctant = function safeOctant (p0, p1) {\n if (p0.equals2D(p1)) { return 0 }\n return Octant.octant(p0, p1)\n};\nNodedSegmentString.prototype.getData = function getData () {\n return this._data\n};\nNodedSegmentString.prototype.addIntersection = function addIntersection () {\n if (arguments.length === 2) {\n var intPt$1 = arguments[0];\n var segmentIndex = arguments[1];\n this.addIntersectionNode(intPt$1, segmentIndex);\n } else if (arguments.length === 4) {\n var li = arguments[0];\n var segmentIndex$1 = arguments[1];\n // const geomIndex = arguments[2]\n var intIndex = arguments[3];\n var intPt = new Coordinate(li.getIntersection(intIndex));\n this.addIntersection(intPt, segmentIndex$1);\n }\n};\nNodedSegmentString.prototype.toString = function toString () {\n return WKTWriter.toLineString(new CoordinateArraySequence(this._pts))\n};\nNodedSegmentString.prototype.getNodeList = function getNodeList () {\n return this._nodeList\n};\nNodedSegmentString.prototype.addIntersectionNode = function addIntersectionNode (intPt, segmentIndex) {\n var normalizedSegmentIndex = segmentIndex;\n var nextSegIndex = normalizedSegmentIndex + 1;\n if (nextSegIndex < this._pts.length) {\n var nextPt = this._pts[nextSegIndex];\n if (intPt.equals2D(nextPt)) {\n normalizedSegmentIndex = nextSegIndex;\n }\n }\n var ei = this._nodeList.add(intPt, normalizedSegmentIndex);\n return ei\n};\nNodedSegmentString.prototype.addIntersections = function addIntersections (li, segmentIndex, geomIndex) {\n var this$1 = this;\n\n for (var i = 0; i < li.getIntersectionNum(); i++) {\n this$1.addIntersection(li, segmentIndex, geomIndex, i);\n }\n};\nNodedSegmentString.prototype.interfaces_ = function interfaces_ () {\n return [NodableSegmentString]\n};\nNodedSegmentString.prototype.getClass = function getClass () {\n return NodedSegmentString\n};\nNodedSegmentString.getNodedSubstrings = function getNodedSubstrings () {\n if (arguments.length === 1) {\n var segStrings = arguments[0];\n var resultEdgelist = new ArrayList();\n NodedSegmentString.getNodedSubstrings(segStrings, resultEdgelist);\n return resultEdgelist\n } else if (arguments.length === 2) {\n var segStrings$1 = arguments[0];\n var resultEdgelist$1 = arguments[1];\n for (var i = segStrings$1.iterator(); i.hasNext();) {\n var ss = i.next();\n ss.getNodeList().addSplitEdges(resultEdgelist$1);\n }\n }\n};\n\nvar LineSegment = function LineSegment () {\n this.p0 = null;\n this.p1 = null;\n if (arguments.length === 0) {\n this.p0 = new Coordinate();\n this.p1 = new Coordinate();\n } else if (arguments.length === 1) {\n var ls = arguments[0];\n this.p0 = new Coordinate(ls.p0);\n this.p1 = new Coordinate(ls.p1);\n } else if (arguments.length === 2) {\n this.p0 = arguments[0];\n this.p1 = arguments[1];\n } else if (arguments.length === 4) {\n var x0 = arguments[0];\n var y0 = arguments[1];\n var x1 = arguments[2];\n var y1 = arguments[3];\n this.p0 = new Coordinate(x0, y0);\n this.p1 = new Coordinate(x1, y1);\n }\n};\n\nvar staticAccessors$24 = { serialVersionUID: { configurable: true } };\nLineSegment.prototype.minX = function minX () {\n return Math.min(this.p0.x, this.p1.x)\n};\nLineSegment.prototype.orientationIndex = function orientationIndex () {\n if (arguments[0] instanceof LineSegment) {\n var seg = arguments[0];\n var orient0 = CGAlgorithms.orientationIndex(this.p0, this.p1, seg.p0);\n var orient1 = CGAlgorithms.orientationIndex(this.p0, this.p1, seg.p1);\n if (orient0 >= 0 && orient1 >= 0) { return Math.max(orient0, orient1) }\n if (orient0 <= 0 && orient1 <= 0) { return Math.max(orient0, orient1) }\n return 0\n } else if (arguments[0] instanceof Coordinate) {\n var p = arguments[0];\n return CGAlgorithms.orientationIndex(this.p0, this.p1, p)\n }\n};\nLineSegment.prototype.toGeometry = function toGeometry (geomFactory) {\n return geomFactory.createLineString([this.p0, this.p1])\n};\nLineSegment.prototype.isVertical = function isVertical () {\n return this.p0.x === this.p1.x\n};\nLineSegment.prototype.equals = function equals (o) {\n if (!(o instanceof LineSegment)) {\n return false\n }\n var other = o;\n return this.p0.equals(other.p0) && this.p1.equals(other.p1)\n};\nLineSegment.prototype.intersection = function intersection (line) {\n var li = new RobustLineIntersector();\n li.computeIntersection(this.p0, this.p1, line.p0, line.p1);\n if (li.hasIntersection()) { return li.getIntersection(0) }\n return null\n};\nLineSegment.prototype.project = function project () {\n if (arguments[0] instanceof Coordinate) {\n var p = arguments[0];\n if (p.equals(this.p0) || p.equals(this.p1)) { return new Coordinate(p) }\n var r = this.projectionFactor(p);\n var coord = new Coordinate();\n coord.x = this.p0.x + r * (this.p1.x - this.p0.x);\n coord.y = this.p0.y + r * (this.p1.y - this.p0.y);\n return coord\n } else if (arguments[0] instanceof LineSegment) {\n var seg = arguments[0];\n var pf0 = this.projectionFactor(seg.p0);\n var pf1 = this.projectionFactor(seg.p1);\n if (pf0 >= 1.0 && pf1 >= 1.0) { return null }\n if (pf0 <= 0.0 && pf1 <= 0.0) { return null }\n var newp0 = this.project(seg.p0);\n if (pf0 < 0.0) { newp0 = this.p0; }\n if (pf0 > 1.0) { newp0 = this.p1; }\n var newp1 = this.project(seg.p1);\n if (pf1 < 0.0) { newp1 = this.p0; }\n if (pf1 > 1.0) { newp1 = this.p1; }\n return new LineSegment(newp0, newp1)\n }\n};\nLineSegment.prototype.normalize = function normalize () {\n if (this.p1.compareTo(this.p0) < 0) { this.reverse(); }\n};\nLineSegment.prototype.angle = function angle () {\n return Math.atan2(this.p1.y - this.p0.y, this.p1.x - this.p0.x)\n};\nLineSegment.prototype.getCoordinate = function getCoordinate (i) {\n if (i === 0) { return this.p0 }\n return this.p1\n};\nLineSegment.prototype.distancePerpendicular = function distancePerpendicular (p) {\n return CGAlgorithms.distancePointLinePerpendicular(p, this.p0, this.p1)\n};\nLineSegment.prototype.minY = function minY () {\n return Math.min(this.p0.y, this.p1.y)\n};\nLineSegment.prototype.midPoint = function midPoint () {\n return LineSegment.midPoint(this.p0, this.p1)\n};\nLineSegment.prototype.projectionFactor = function projectionFactor (p) {\n if (p.equals(this.p0)) { return 0.0 }\n if (p.equals(this.p1)) { return 1.0 }\n var dx = this.p1.x - this.p0.x;\n var dy = this.p1.y - this.p0.y;\n var len = dx * dx + dy * dy;\n if (len <= 0.0) { return Double.NaN }\n var r = ((p.x - this.p0.x) * dx + (p.y - this.p0.y) * dy) / len;\n return r\n};\nLineSegment.prototype.closestPoints = function closestPoints (line) {\n var intPt = this.intersection(line);\n if (intPt !== null) {\n return [intPt, intPt]\n }\n var closestPt = new Array(2).fill(null);\n var minDistance = Double.MAX_VALUE;\n var dist = null;\n var close00 = this.closestPoint(line.p0);\n minDistance = close00.distance(line.p0);\n closestPt[0] = close00;\n closestPt[1] = line.p0;\n var close01 = this.closestPoint(line.p1);\n dist = close01.distance(line.p1);\n if (dist < minDistance) {\n minDistance = dist;\n closestPt[0] = close01;\n closestPt[1] = line.p1;\n }\n var close10 = line.closestPoint(this.p0);\n dist = close10.distance(this.p0);\n if (dist < minDistance) {\n minDistance = dist;\n closestPt[0] = this.p0;\n closestPt[1] = close10;\n }\n var close11 = line.closestPoint(this.p1);\n dist = close11.distance(this.p1);\n if (dist < minDistance) {\n minDistance = dist;\n closestPt[0] = this.p1;\n closestPt[1] = close11;\n }\n return closestPt\n};\nLineSegment.prototype.closestPoint = function closestPoint (p) {\n var factor = this.projectionFactor(p);\n if (factor > 0 && factor < 1) {\n return this.project(p)\n }\n var dist0 = this.p0.distance(p);\n var dist1 = this.p1.distance(p);\n if (dist0 < dist1) { return this.p0 }\n return this.p1\n};\nLineSegment.prototype.maxX = function maxX () {\n return Math.max(this.p0.x, this.p1.x)\n};\nLineSegment.prototype.getLength = function getLength () {\n return this.p0.distance(this.p1)\n};\nLineSegment.prototype.compareTo = function compareTo (o) {\n var other = o;\n var comp0 = this.p0.compareTo(other.p0);\n if (comp0 !== 0) { return comp0 }\n return this.p1.compareTo(other.p1)\n};\nLineSegment.prototype.reverse = function reverse () {\n var temp = this.p0;\n this.p0 = this.p1;\n this.p1 = temp;\n};\nLineSegment.prototype.equalsTopo = function equalsTopo (other) {\n return this.p0.equals(other.p0) &&\n (this.p1.equals(other.p1) || this.p0.equals(other.p1)) &&\n this.p1.equals(other.p0)\n};\nLineSegment.prototype.lineIntersection = function lineIntersection (line) {\n try {\n var intPt = HCoordinate.intersection(this.p0, this.p1, line.p0, line.p1);\n return intPt\n } catch (ex) {\n if (ex instanceof NotRepresentableException) {} else { throw ex }\n } finally {}\n return null\n};\nLineSegment.prototype.maxY = function maxY () {\n return Math.max(this.p0.y, this.p1.y)\n};\nLineSegment.prototype.pointAlongOffset = function pointAlongOffset (segmentLengthFraction, offsetDistance) {\n var segx = this.p0.x + segmentLengthFraction * (this.p1.x - this.p0.x);\n var segy = this.p0.y + segmentLengthFraction * (this.p1.y - this.p0.y);\n var dx = this.p1.x - this.p0.x;\n var dy = this.p1.y - this.p0.y;\n var len = Math.sqrt(dx * dx + dy * dy);\n var ux = 0.0;\n var uy = 0.0;\n if (offsetDistance !== 0.0) {\n if (len <= 0.0) { throw new Error('Cannot compute offset from zero-length line segment') }\n ux = offsetDistance * dx / len;\n uy = offsetDistance * dy / len;\n }\n var offsetx = segx - uy;\n var offsety = segy + ux;\n var coord = new Coordinate(offsetx, offsety);\n return coord\n};\nLineSegment.prototype.setCoordinates = function setCoordinates () {\n if (arguments.length === 1) {\n var ls = arguments[0];\n this.setCoordinates(ls.p0, ls.p1);\n } else if (arguments.length === 2) {\n var p0 = arguments[0];\n var p1 = arguments[1];\n this.p0.x = p0.x;\n this.p0.y = p0.y;\n this.p1.x = p1.x;\n this.p1.y = p1.y;\n }\n};\nLineSegment.prototype.segmentFraction = function segmentFraction (inputPt) {\n var segFrac = this.projectionFactor(inputPt);\n if (segFrac < 0.0) { segFrac = 0.0; } else if (segFrac > 1.0 || Double.isNaN(segFrac)) { segFrac = 1.0; }\n return segFrac\n};\nLineSegment.prototype.toString = function toString () {\n return 'LINESTRING( ' + this.p0.x + ' ' + this.p0.y + ', ' + this.p1.x + ' ' + this.p1.y + ')'\n};\nLineSegment.prototype.isHorizontal = function isHorizontal () {\n return this.p0.y === this.p1.y\n};\nLineSegment.prototype.distance = function distance () {\n if (arguments[0] instanceof LineSegment) {\n var ls = arguments[0];\n return CGAlgorithms.distanceLineLine(this.p0, this.p1, ls.p0, ls.p1)\n } else if (arguments[0] instanceof Coordinate) {\n var p = arguments[0];\n return CGAlgorithms.distancePointLine(p, this.p0, this.p1)\n }\n};\nLineSegment.prototype.pointAlong = function pointAlong (segmentLengthFraction) {\n var coord = new Coordinate();\n coord.x = this.p0.x + segmentLengthFraction * (this.p1.x - this.p0.x);\n coord.y = this.p0.y + segmentLengthFraction * (this.p1.y - this.p0.y);\n return coord\n};\nLineSegment.prototype.hashCode = function hashCode () {\n var bits0 = Double.doubleToLongBits(this.p0.x);\n bits0 ^= Double.doubleToLongBits(this.p0.y) * 31;\n var hash0 = Math.trunc(bits0) ^ Math.trunc(bits0 >> 32);\n var bits1 = Double.doubleToLongBits(this.p1.x);\n bits1 ^= Double.doubleToLongBits(this.p1.y) * 31;\n var hash1 = Math.trunc(bits1) ^ Math.trunc(bits1 >> 32);\n return hash0 ^ hash1\n};\nLineSegment.prototype.interfaces_ = function interfaces_ () {\n return [Comparable, Serializable]\n};\nLineSegment.prototype.getClass = function getClass () {\n return LineSegment\n};\nLineSegment.midPoint = function midPoint (p0, p1) {\n return new Coordinate((p0.x + p1.x) / 2, (p0.y + p1.y) / 2)\n};\nstaticAccessors$24.serialVersionUID.get = function () { return 3252005833466256227 };\n\nObject.defineProperties( LineSegment, staticAccessors$24 );\n\nvar MonotoneChainOverlapAction = function MonotoneChainOverlapAction () {\n this.tempEnv1 = new Envelope();\n this.tempEnv2 = new Envelope();\n this._overlapSeg1 = new LineSegment();\n this._overlapSeg2 = new LineSegment();\n};\nMonotoneChainOverlapAction.prototype.overlap = function overlap () {\n if (arguments.length === 2) {\n // const seg1 = arguments[0]\n // const seg2 = arguments[1]\n } else if (arguments.length === 4) {\n var mc1 = arguments[0];\n var start1 = arguments[1];\n var mc2 = arguments[2];\n var start2 = arguments[3];\n mc1.getLineSegment(start1, this._overlapSeg1);\n mc2.getLineSegment(start2, this._overlapSeg2);\n this.overlap(this._overlapSeg1, this._overlapSeg2);\n }\n};\nMonotoneChainOverlapAction.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nMonotoneChainOverlapAction.prototype.getClass = function getClass () {\n return MonotoneChainOverlapAction\n};\n\nvar MonotoneChain = function MonotoneChain () {\n this._pts = null;\n this._start = null;\n this._end = null;\n this._env = null;\n this._context = null;\n this._id = null;\n var pts = arguments[0];\n var start = arguments[1];\n var end = arguments[2];\n var context = arguments[3];\n this._pts = pts;\n this._start = start;\n this._end = end;\n this._context = context;\n};\nMonotoneChain.prototype.getLineSegment = function getLineSegment (index, ls) {\n ls.p0 = this._pts[index];\n ls.p1 = this._pts[index + 1];\n};\nMonotoneChain.prototype.computeSelect = function computeSelect (searchEnv, start0, end0, mcs) {\n var p0 = this._pts[start0];\n var p1 = this._pts[end0];\n mcs.tempEnv1.init(p0, p1);\n if (end0 - start0 === 1) {\n mcs.select(this, start0);\n return null\n }\n if (!searchEnv.intersects(mcs.tempEnv1)) { return null }\n var mid = Math.trunc((start0 + end0) / 2);\n if (start0 < mid) {\n this.computeSelect(searchEnv, start0, mid, mcs);\n }\n if (mid < end0) {\n this.computeSelect(searchEnv, mid, end0, mcs);\n }\n};\nMonotoneChain.prototype.getCoordinates = function getCoordinates () {\n var this$1 = this;\n\n var coord = new Array(this._end - this._start + 1).fill(null);\n var index = 0;\n for (var i = this._start; i <= this._end; i++) {\n coord[index++] = this$1._pts[i];\n }\n return coord\n};\nMonotoneChain.prototype.computeOverlaps = function computeOverlaps (mc, mco) {\n this.computeOverlapsInternal(this._start, this._end, mc, mc._start, mc._end, mco);\n};\nMonotoneChain.prototype.setId = function setId (id) {\n this._id = id;\n};\nMonotoneChain.prototype.select = function select (searchEnv, mcs) {\n this.computeSelect(searchEnv, this._start, this._end, mcs);\n};\nMonotoneChain.prototype.getEnvelope = function getEnvelope () {\n if (this._env === null) {\n var p0 = this._pts[this._start];\n var p1 = this._pts[this._end];\n this._env = new Envelope(p0, p1);\n }\n return this._env\n};\nMonotoneChain.prototype.getEndIndex = function getEndIndex () {\n return this._end\n};\nMonotoneChain.prototype.getStartIndex = function getStartIndex () {\n return this._start\n};\nMonotoneChain.prototype.getContext = function getContext () {\n return this._context\n};\nMonotoneChain.prototype.getId = function getId () {\n return this._id\n};\nMonotoneChain.prototype.computeOverlapsInternal = function computeOverlapsInternal (start0, end0, mc, start1, end1, mco) {\n var p00 = this._pts[start0];\n var p01 = this._pts[end0];\n var p10 = mc._pts[start1];\n var p11 = mc._pts[end1];\n if (end0 - start0 === 1 && end1 - start1 === 1) {\n mco.overlap(this, start0, mc, start1);\n return null\n }\n mco.tempEnv1.init(p00, p01);\n mco.tempEnv2.init(p10, p11);\n if (!mco.tempEnv1.intersects(mco.tempEnv2)) { return null }\n var mid0 = Math.trunc((start0 + end0) / 2);\n var mid1 = Math.trunc((start1 + end1) / 2);\n if (start0 < mid0) {\n if (start1 < mid1) { this.computeOverlapsInternal(start0, mid0, mc, start1, mid1, mco); }\n if (mid1 < end1) { this.computeOverlapsInternal(start0, mid0, mc, mid1, end1, mco); }\n }\n if (mid0 < end0) {\n if (start1 < mid1) { this.computeOverlapsInternal(mid0, end0, mc, start1, mid1, mco); }\n if (mid1 < end1) { this.computeOverlapsInternal(mid0, end0, mc, mid1, end1, mco); }\n }\n};\nMonotoneChain.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nMonotoneChain.prototype.getClass = function getClass () {\n return MonotoneChain\n};\n\nvar MonotoneChainBuilder = function MonotoneChainBuilder () {};\n\nMonotoneChainBuilder.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nMonotoneChainBuilder.prototype.getClass = function getClass () {\n return MonotoneChainBuilder\n};\nMonotoneChainBuilder.getChainStartIndices = function getChainStartIndices (pts) {\n var start = 0;\n var startIndexList = new ArrayList();\n startIndexList.add(new Integer(start));\n do {\n var last = MonotoneChainBuilder.findChainEnd(pts, start);\n startIndexList.add(new Integer(last));\n start = last;\n } while (start < pts.length - 1)\n var startIndex = MonotoneChainBuilder.toIntArray(startIndexList);\n return startIndex\n};\nMonotoneChainBuilder.findChainEnd = function findChainEnd (pts, start) {\n var safeStart = start;\n while (safeStart < pts.length - 1 && pts[safeStart].equals2D(pts[safeStart + 1])) {\n safeStart++;\n }\n if (safeStart >= pts.length - 1) {\n return pts.length - 1\n }\n var chainQuad = Quadrant.quadrant(pts[safeStart], pts[safeStart + 1]);\n var last = start + 1;\n while (last < pts.length) {\n if (!pts[last - 1].equals2D(pts[last])) {\n var quad = Quadrant.quadrant(pts[last - 1], pts[last]);\n if (quad !== chainQuad) { break }\n }\n last++;\n }\n return last - 1\n};\nMonotoneChainBuilder.getChains = function getChains () {\n if (arguments.length === 1) {\n var pts = arguments[0];\n return MonotoneChainBuilder.getChains(pts, null)\n } else if (arguments.length === 2) {\n var pts$1 = arguments[0];\n var context = arguments[1];\n var mcList = new ArrayList();\n var startIndex = MonotoneChainBuilder.getChainStartIndices(pts$1);\n for (var i = 0; i < startIndex.length - 1; i++) {\n var mc = new MonotoneChain(pts$1, startIndex[i], startIndex[i + 1], context);\n mcList.add(mc);\n }\n return mcList\n }\n};\nMonotoneChainBuilder.toIntArray = function toIntArray (list) {\n var array = new Array(list.size()).fill(null);\n for (var i = 0; i < array.length; i++) {\n array[i] = list.get(i).intValue();\n }\n return array\n};\n\nvar Noder = function Noder () {};\n\nNoder.prototype.computeNodes = function computeNodes (segStrings) {};\nNoder.prototype.getNodedSubstrings = function getNodedSubstrings () {};\nNoder.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nNoder.prototype.getClass = function getClass () {\n return Noder\n};\n\nvar SinglePassNoder = function SinglePassNoder () {\n this._segInt = null;\n if (arguments.length === 0) {} else if (arguments.length === 1) {\n var segInt = arguments[0];\n this.setSegmentIntersector(segInt);\n }\n};\nSinglePassNoder.prototype.setSegmentIntersector = function setSegmentIntersector (segInt) {\n this._segInt = segInt;\n};\nSinglePassNoder.prototype.interfaces_ = function interfaces_ () {\n return [Noder]\n};\nSinglePassNoder.prototype.getClass = function getClass () {\n return SinglePassNoder\n};\n\nvar MCIndexNoder = (function (SinglePassNoder$$1) {\n function MCIndexNoder (si) {\n if (si) { SinglePassNoder$$1.call(this, si); }\n else { SinglePassNoder$$1.call(this); }\n this._monoChains = new ArrayList();\n this._index = new STRtree();\n this._idCounter = 0;\n this._nodedSegStrings = null;\n this._nOverlaps = 0;\n }\n\n if ( SinglePassNoder$$1 ) MCIndexNoder.__proto__ = SinglePassNoder$$1;\n MCIndexNoder.prototype = Object.create( SinglePassNoder$$1 && SinglePassNoder$$1.prototype );\n MCIndexNoder.prototype.constructor = MCIndexNoder;\n\n var staticAccessors = { SegmentOverlapAction: { configurable: true } };\n MCIndexNoder.prototype.getMonotoneChains = function getMonotoneChains () {\n return this._monoChains\n };\n MCIndexNoder.prototype.getNodedSubstrings = function getNodedSubstrings () {\n return NodedSegmentString.getNodedSubstrings(this._nodedSegStrings)\n };\n MCIndexNoder.prototype.getIndex = function getIndex () {\n return this._index\n };\n MCIndexNoder.prototype.add = function add (segStr) {\n var this$1 = this;\n\n var segChains = MonotoneChainBuilder.getChains(segStr.getCoordinates(), segStr);\n for (var i = segChains.iterator(); i.hasNext();) {\n var mc = i.next();\n mc.setId(this$1._idCounter++);\n this$1._index.insert(mc.getEnvelope(), mc);\n this$1._monoChains.add(mc);\n }\n };\n MCIndexNoder.prototype.computeNodes = function computeNodes (inputSegStrings) {\n var this$1 = this;\n\n this._nodedSegStrings = inputSegStrings;\n for (var i = inputSegStrings.iterator(); i.hasNext();) {\n this$1.add(i.next());\n }\n this.intersectChains();\n };\n MCIndexNoder.prototype.intersectChains = function intersectChains () {\n var this$1 = this;\n\n var overlapAction = new SegmentOverlapAction(this._segInt);\n for (var i = this._monoChains.iterator(); i.hasNext();) {\n var queryChain = i.next();\n var overlapChains = this$1._index.query(queryChain.getEnvelope());\n for (var j = overlapChains.iterator(); j.hasNext();) {\n var testChain = j.next();\n if (testChain.getId() > queryChain.getId()) {\n queryChain.computeOverlaps(testChain, overlapAction);\n this$1._nOverlaps++;\n }\n if (this$1._segInt.isDone()) { return null }\n }\n }\n };\n MCIndexNoder.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n MCIndexNoder.prototype.getClass = function getClass () {\n return MCIndexNoder\n };\n staticAccessors.SegmentOverlapAction.get = function () { return SegmentOverlapAction };\n\n Object.defineProperties( MCIndexNoder, staticAccessors );\n\n return MCIndexNoder;\n}(SinglePassNoder));\n\nvar SegmentOverlapAction = (function (MonotoneChainOverlapAction$$1) {\n function SegmentOverlapAction () {\n MonotoneChainOverlapAction$$1.call(this);\n this._si = null;\n var si = arguments[0];\n this._si = si;\n }\n\n if ( MonotoneChainOverlapAction$$1 ) SegmentOverlapAction.__proto__ = MonotoneChainOverlapAction$$1;\n SegmentOverlapAction.prototype = Object.create( MonotoneChainOverlapAction$$1 && MonotoneChainOverlapAction$$1.prototype );\n SegmentOverlapAction.prototype.constructor = SegmentOverlapAction;\n SegmentOverlapAction.prototype.overlap = function overlap () {\n if (arguments.length === 4) {\n var mc1 = arguments[0];\n var start1 = arguments[1];\n var mc2 = arguments[2];\n var start2 = arguments[3];\n var ss1 = mc1.getContext();\n var ss2 = mc2.getContext();\n this._si.processIntersections(ss1, start1, ss2, start2);\n } else { return MonotoneChainOverlapAction$$1.prototype.overlap.apply(this, arguments) }\n };\n SegmentOverlapAction.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n SegmentOverlapAction.prototype.getClass = function getClass () {\n return SegmentOverlapAction\n };\n\n return SegmentOverlapAction;\n}(MonotoneChainOverlapAction));\n\nvar BufferParameters = function BufferParameters () {\n this._quadrantSegments = BufferParameters.DEFAULT_QUADRANT_SEGMENTS;\n this._endCapStyle = BufferParameters.CAP_ROUND;\n this._joinStyle = BufferParameters.JOIN_ROUND;\n this._mitreLimit = BufferParameters.DEFAULT_MITRE_LIMIT;\n this._isSingleSided = false;\n this._simplifyFactor = BufferParameters.DEFAULT_SIMPLIFY_FACTOR;\n\n if (arguments.length === 0) {} else if (arguments.length === 1) {\n var quadrantSegments = arguments[0];\n this.setQuadrantSegments(quadrantSegments);\n } else if (arguments.length === 2) {\n var quadrantSegments$1 = arguments[0];\n var endCapStyle = arguments[1];\n this.setQuadrantSegments(quadrantSegments$1);\n this.setEndCapStyle(endCapStyle);\n } else if (arguments.length === 4) {\n var quadrantSegments$2 = arguments[0];\n var endCapStyle$1 = arguments[1];\n var joinStyle = arguments[2];\n var mitreLimit = arguments[3];\n this.setQuadrantSegments(quadrantSegments$2);\n this.setEndCapStyle(endCapStyle$1);\n this.setJoinStyle(joinStyle);\n this.setMitreLimit(mitreLimit);\n }\n};\n\nvar staticAccessors$25 = { CAP_ROUND: { configurable: true },CAP_FLAT: { configurable: true },CAP_SQUARE: { configurable: true },JOIN_ROUND: { configurable: true },JOIN_MITRE: { configurable: true },JOIN_BEVEL: { configurable: true },DEFAULT_QUADRANT_SEGMENTS: { configurable: true },DEFAULT_MITRE_LIMIT: { configurable: true },DEFAULT_SIMPLIFY_FACTOR: { configurable: true } };\nBufferParameters.prototype.getEndCapStyle = function getEndCapStyle () {\n return this._endCapStyle\n};\nBufferParameters.prototype.isSingleSided = function isSingleSided () {\n return this._isSingleSided\n};\nBufferParameters.prototype.setQuadrantSegments = function setQuadrantSegments (quadSegs) {\n this._quadrantSegments = quadSegs;\n if (this._quadrantSegments === 0) { this._joinStyle = BufferParameters.JOIN_BEVEL; }\n if (this._quadrantSegments < 0) {\n this._joinStyle = BufferParameters.JOIN_MITRE;\n this._mitreLimit = Math.abs(this._quadrantSegments);\n }\n if (quadSegs <= 0) {\n this._quadrantSegments = 1;\n }\n if (this._joinStyle !== BufferParameters.JOIN_ROUND) {\n this._quadrantSegments = BufferParameters.DEFAULT_QUADRANT_SEGMENTS;\n }\n};\nBufferParameters.prototype.getJoinStyle = function getJoinStyle () {\n return this._joinStyle\n};\nBufferParameters.prototype.setJoinStyle = function setJoinStyle (joinStyle) {\n this._joinStyle = joinStyle;\n};\nBufferParameters.prototype.setSimplifyFactor = function setSimplifyFactor (simplifyFactor) {\n this._simplifyFactor = simplifyFactor < 0 ? 0 : simplifyFactor;\n};\nBufferParameters.prototype.getSimplifyFactor = function getSimplifyFactor () {\n return this._simplifyFactor\n};\nBufferParameters.prototype.getQuadrantSegments = function getQuadrantSegments () {\n return this._quadrantSegments\n};\nBufferParameters.prototype.setEndCapStyle = function setEndCapStyle (endCapStyle) {\n this._endCapStyle = endCapStyle;\n};\nBufferParameters.prototype.getMitreLimit = function getMitreLimit () {\n return this._mitreLimit\n};\nBufferParameters.prototype.setMitreLimit = function setMitreLimit (mitreLimit) {\n this._mitreLimit = mitreLimit;\n};\nBufferParameters.prototype.setSingleSided = function setSingleSided (isSingleSided) {\n this._isSingleSided = isSingleSided;\n};\nBufferParameters.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nBufferParameters.prototype.getClass = function getClass () {\n return BufferParameters\n};\nBufferParameters.bufferDistanceError = function bufferDistanceError (quadSegs) {\n var alpha = Math.PI / 2.0 / quadSegs;\n return 1 - Math.cos(alpha / 2.0)\n};\nstaticAccessors$25.CAP_ROUND.get = function () { return 1 };\nstaticAccessors$25.CAP_FLAT.get = function () { return 2 };\nstaticAccessors$25.CAP_SQUARE.get = function () { return 3 };\nstaticAccessors$25.JOIN_ROUND.get = function () { return 1 };\nstaticAccessors$25.JOIN_MITRE.get = function () { return 2 };\nstaticAccessors$25.JOIN_BEVEL.get = function () { return 3 };\nstaticAccessors$25.DEFAULT_QUADRANT_SEGMENTS.get = function () { return 8 };\nstaticAccessors$25.DEFAULT_MITRE_LIMIT.get = function () { return 5.0 };\nstaticAccessors$25.DEFAULT_SIMPLIFY_FACTOR.get = function () { return 0.01 };\n\nObject.defineProperties( BufferParameters, staticAccessors$25 );\n\nvar BufferInputLineSimplifier = function BufferInputLineSimplifier (inputLine) {\n this._distanceTol = null;\n this._isDeleted = null;\n this._angleOrientation = CGAlgorithms.COUNTERCLOCKWISE;\n this._inputLine = inputLine || null;\n};\n\nvar staticAccessors$26 = { INIT: { configurable: true },DELETE: { configurable: true },KEEP: { configurable: true },NUM_PTS_TO_CHECK: { configurable: true } };\nBufferInputLineSimplifier.prototype.isDeletable = function isDeletable (i0, i1, i2, distanceTol) {\n var p0 = this._inputLine[i0];\n var p1 = this._inputLine[i1];\n var p2 = this._inputLine[i2];\n if (!this.isConcave(p0, p1, p2)) { return false }\n if (!this.isShallow(p0, p1, p2, distanceTol)) { return false }\n return this.isShallowSampled(p0, p1, i0, i2, distanceTol)\n};\nBufferInputLineSimplifier.prototype.deleteShallowConcavities = function deleteShallowConcavities () {\n var this$1 = this;\n\n var index = 1;\n // const maxIndex = this._inputLine.length - 1\n var midIndex = this.findNextNonDeletedIndex(index);\n var lastIndex = this.findNextNonDeletedIndex(midIndex);\n var isChanged = false;\n while (lastIndex < this._inputLine.length) {\n var isMiddleVertexDeleted = false;\n if (this$1.isDeletable(index, midIndex, lastIndex, this$1._distanceTol)) {\n this$1._isDeleted[midIndex] = BufferInputLineSimplifier.DELETE;\n isMiddleVertexDeleted = true;\n isChanged = true;\n }\n if (isMiddleVertexDeleted) { index = lastIndex; } else { index = midIndex; }\n midIndex = this$1.findNextNonDeletedIndex(index);\n lastIndex = this$1.findNextNonDeletedIndex(midIndex);\n }\n return isChanged\n};\nBufferInputLineSimplifier.prototype.isShallowConcavity = function isShallowConcavity (p0, p1, p2, distanceTol) {\n var orientation = CGAlgorithms.computeOrientation(p0, p1, p2);\n var isAngleToSimplify = orientation === this._angleOrientation;\n if (!isAngleToSimplify) { return false }\n var dist = CGAlgorithms.distancePointLine(p1, p0, p2);\n return dist < distanceTol\n};\nBufferInputLineSimplifier.prototype.isShallowSampled = function isShallowSampled (p0, p2, i0, i2, distanceTol) {\n var this$1 = this;\n\n var inc = Math.trunc((i2 - i0) / BufferInputLineSimplifier.NUM_PTS_TO_CHECK);\n if (inc <= 0) { inc = 1; }\n for (var i = i0; i < i2; i += inc) {\n if (!this$1.isShallow(p0, p2, this$1._inputLine[i], distanceTol)) { return false }\n }\n return true\n};\nBufferInputLineSimplifier.prototype.isConcave = function isConcave (p0, p1, p2) {\n var orientation = CGAlgorithms.computeOrientation(p0, p1, p2);\n var isConcave = orientation === this._angleOrientation;\n return isConcave\n};\nBufferInputLineSimplifier.prototype.simplify = function simplify (distanceTol) {\n var this$1 = this;\n\n this._distanceTol = Math.abs(distanceTol);\n if (distanceTol < 0) { this._angleOrientation = CGAlgorithms.CLOCKWISE; }\n this._isDeleted = new Array(this._inputLine.length).fill(null);\n var isChanged = false;\n do {\n isChanged = this$1.deleteShallowConcavities();\n } while (isChanged)\n return this.collapseLine()\n};\nBufferInputLineSimplifier.prototype.findNextNonDeletedIndex = function findNextNonDeletedIndex (index) {\n var next = index + 1;\n while (next < this._inputLine.length && this._isDeleted[next] === BufferInputLineSimplifier.DELETE) { next++; }\n return next\n};\nBufferInputLineSimplifier.prototype.isShallow = function isShallow (p0, p1, p2, distanceTol) {\n var dist = CGAlgorithms.distancePointLine(p1, p0, p2);\n return dist < distanceTol\n};\nBufferInputLineSimplifier.prototype.collapseLine = function collapseLine () {\n var this$1 = this;\n\n var coordList = new CoordinateList();\n for (var i = 0; i < this._inputLine.length; i++) {\n if (this$1._isDeleted[i] !== BufferInputLineSimplifier.DELETE) { coordList.add(this$1._inputLine[i]); }\n }\n return coordList.toCoordinateArray()\n};\nBufferInputLineSimplifier.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nBufferInputLineSimplifier.prototype.getClass = function getClass () {\n return BufferInputLineSimplifier\n};\nBufferInputLineSimplifier.simplify = function simplify (inputLine, distanceTol) {\n var simp = new BufferInputLineSimplifier(inputLine);\n return simp.simplify(distanceTol)\n};\nstaticAccessors$26.INIT.get = function () { return 0 };\nstaticAccessors$26.DELETE.get = function () { return 1 };\nstaticAccessors$26.KEEP.get = function () { return 1 };\nstaticAccessors$26.NUM_PTS_TO_CHECK.get = function () { return 10 };\n\nObject.defineProperties( BufferInputLineSimplifier, staticAccessors$26 );\n\nvar OffsetSegmentString = function OffsetSegmentString () {\n this._ptList = null;\n this._precisionModel = null;\n this._minimimVertexDistance = 0.0;\n this._ptList = new ArrayList();\n};\n\nvar staticAccessors$28 = { COORDINATE_ARRAY_TYPE: { configurable: true } };\nOffsetSegmentString.prototype.getCoordinates = function getCoordinates () {\n var coord = this._ptList.toArray(OffsetSegmentString.COORDINATE_ARRAY_TYPE);\n return coord\n};\nOffsetSegmentString.prototype.setPrecisionModel = function setPrecisionModel (precisionModel) {\n this._precisionModel = precisionModel;\n};\nOffsetSegmentString.prototype.addPt = function addPt (pt) {\n var bufPt = new Coordinate(pt);\n this._precisionModel.makePrecise(bufPt);\n if (this.isRedundant(bufPt)) { return null }\n this._ptList.add(bufPt);\n};\nOffsetSegmentString.prototype.revere = function revere () {};\nOffsetSegmentString.prototype.addPts = function addPts (pt, isForward) {\n var this$1 = this;\n\n if (isForward) {\n for (var i = 0; i < pt.length; i++) {\n this$1.addPt(pt[i]);\n }\n } else {\n for (var i$1 = pt.length - 1; i$1 >= 0; i$1--) {\n this$1.addPt(pt[i$1]);\n }\n }\n};\nOffsetSegmentString.prototype.isRedundant = function isRedundant (pt) {\n if (this._ptList.size() < 1) { return false }\n var lastPt = this._ptList.get(this._ptList.size() - 1);\n var ptDist = pt.distance(lastPt);\n if (ptDist < this._minimimVertexDistance) { return true }\n return false\n};\nOffsetSegmentString.prototype.toString = function toString () {\n var fact = new GeometryFactory();\n var line = fact.createLineString(this.getCoordinates());\n return line.toString()\n};\nOffsetSegmentString.prototype.closeRing = function closeRing () {\n if (this._ptList.size() < 1) { return null }\n var startPt = new Coordinate(this._ptList.get(0));\n var lastPt = this._ptList.get(this._ptList.size() - 1);\n // const last2Pt = null\n // if (this._ptList.size() >= 2) last2Pt = this._ptList.get(this._ptList.size() - 2)\n if (startPt.equals(lastPt)) { return null }\n this._ptList.add(startPt);\n};\nOffsetSegmentString.prototype.setMinimumVertexDistance = function setMinimumVertexDistance (minimimVertexDistance) {\n this._minimimVertexDistance = minimimVertexDistance;\n};\nOffsetSegmentString.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nOffsetSegmentString.prototype.getClass = function getClass () {\n return OffsetSegmentString\n};\nstaticAccessors$28.COORDINATE_ARRAY_TYPE.get = function () { return new Array(0).fill(null) };\n\nObject.defineProperties( OffsetSegmentString, staticAccessors$28 );\n\nvar Angle = function Angle () {};\n\nvar staticAccessors$29 = { PI_TIMES_2: { configurable: true },PI_OVER_2: { configurable: true },PI_OVER_4: { configurable: true },COUNTERCLOCKWISE: { configurable: true },CLOCKWISE: { configurable: true },NONE: { configurable: true } };\n\nAngle.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nAngle.prototype.getClass = function getClass () {\n return Angle\n};\nAngle.toDegrees = function toDegrees (radians) {\n return radians * 180 / Math.PI\n};\nAngle.normalize = function normalize (angle) {\n while (angle > Math.PI) { angle -= Angle.PI_TIMES_2; }\n while (angle <= -Math.PI) { angle += Angle.PI_TIMES_2; }\n return angle\n};\nAngle.angle = function angle () {\n if (arguments.length === 1) {\n var p = arguments[0];\n return Math.atan2(p.y, p.x)\n } else if (arguments.length === 2) {\n var p0 = arguments[0];\n var p1 = arguments[1];\n var dx = p1.x - p0.x;\n var dy = p1.y - p0.y;\n return Math.atan2(dy, dx)\n }\n};\nAngle.isAcute = function isAcute (p0, p1, p2) {\n var dx0 = p0.x - p1.x;\n var dy0 = p0.y - p1.y;\n var dx1 = p2.x - p1.x;\n var dy1 = p2.y - p1.y;\n var dotprod = dx0 * dx1 + dy0 * dy1;\n return dotprod > 0\n};\nAngle.isObtuse = function isObtuse (p0, p1, p2) {\n var dx0 = p0.x - p1.x;\n var dy0 = p0.y - p1.y;\n var dx1 = p2.x - p1.x;\n var dy1 = p2.y - p1.y;\n var dotprod = dx0 * dx1 + dy0 * dy1;\n return dotprod < 0\n};\nAngle.interiorAngle = function interiorAngle (p0, p1, p2) {\n var anglePrev = Angle.angle(p1, p0);\n var angleNext = Angle.angle(p1, p2);\n return Math.abs(angleNext - anglePrev)\n};\nAngle.normalizePositive = function normalizePositive (angle) {\n if (angle < 0.0) {\n while (angle < 0.0) { angle += Angle.PI_TIMES_2; }\n if (angle >= Angle.PI_TIMES_2) { angle = 0.0; }\n } else {\n while (angle >= Angle.PI_TIMES_2) { angle -= Angle.PI_TIMES_2; }\n if (angle < 0.0) { angle = 0.0; }\n }\n return angle\n};\nAngle.angleBetween = function angleBetween (tip1, tail, tip2) {\n var a1 = Angle.angle(tail, tip1);\n var a2 = Angle.angle(tail, tip2);\n return Angle.diff(a1, a2)\n};\nAngle.diff = function diff (ang1, ang2) {\n var delAngle = null;\n if (ang1 < ang2) {\n delAngle = ang2 - ang1;\n } else {\n delAngle = ang1 - ang2;\n }\n if (delAngle > Math.PI) {\n delAngle = 2 * Math.PI - delAngle;\n }\n return delAngle\n};\nAngle.toRadians = function toRadians (angleDegrees) {\n return angleDegrees * Math.PI / 180.0\n};\nAngle.getTurn = function getTurn (ang1, ang2) {\n var crossproduct = Math.sin(ang2 - ang1);\n if (crossproduct > 0) {\n return Angle.COUNTERCLOCKWISE\n }\n if (crossproduct < 0) {\n return Angle.CLOCKWISE\n }\n return Angle.NONE\n};\nAngle.angleBetweenOriented = function angleBetweenOriented (tip1, tail, tip2) {\n var a1 = Angle.angle(tail, tip1);\n var a2 = Angle.angle(tail, tip2);\n var angDel = a2 - a1;\n if (angDel <= -Math.PI) { return angDel + Angle.PI_TIMES_2 }\n if (angDel > Math.PI) { return angDel - Angle.PI_TIMES_2 }\n return angDel\n};\nstaticAccessors$29.PI_TIMES_2.get = function () { return 2.0 * Math.PI };\nstaticAccessors$29.PI_OVER_2.get = function () { return Math.PI / 2.0 };\nstaticAccessors$29.PI_OVER_4.get = function () { return Math.PI / 4.0 };\nstaticAccessors$29.COUNTERCLOCKWISE.get = function () { return CGAlgorithms.COUNTERCLOCKWISE };\nstaticAccessors$29.CLOCKWISE.get = function () { return CGAlgorithms.CLOCKWISE };\nstaticAccessors$29.NONE.get = function () { return CGAlgorithms.COLLINEAR };\n\nObject.defineProperties( Angle, staticAccessors$29 );\n\nvar OffsetSegmentGenerator = function OffsetSegmentGenerator () {\n this._maxCurveSegmentError = 0.0;\n this._filletAngleQuantum = null;\n this._closingSegLengthFactor = 1;\n this._segList = null;\n this._distance = 0.0;\n this._precisionModel = null;\n this._bufParams = null;\n this._li = null;\n this._s0 = null;\n this._s1 = null;\n this._s2 = null;\n this._seg0 = new LineSegment();\n this._seg1 = new LineSegment();\n this._offset0 = new LineSegment();\n this._offset1 = new LineSegment();\n this._side = 0;\n this._hasNarrowConcaveAngle = false;\n var precisionModel = arguments[0];\n var bufParams = arguments[1];\n var distance = arguments[2];\n this._precisionModel = precisionModel;\n this._bufParams = bufParams;\n this._li = new RobustLineIntersector();\n this._filletAngleQuantum = Math.PI / 2.0 / bufParams.getQuadrantSegments();\n if (bufParams.getQuadrantSegments() >= 8 && bufParams.getJoinStyle() === BufferParameters.JOIN_ROUND) { this._closingSegLengthFactor = OffsetSegmentGenerator.MAX_CLOSING_SEG_LEN_FACTOR; }\n this.init(distance);\n};\n\nvar staticAccessors$27 = { OFFSET_SEGMENT_SEPARATION_FACTOR: { configurable: true },INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR: { configurable: true },CURVE_VERTEX_SNAP_DISTANCE_FACTOR: { configurable: true },MAX_CLOSING_SEG_LEN_FACTOR: { configurable: true } };\nOffsetSegmentGenerator.prototype.addNextSegment = function addNextSegment (p, addStartPoint) {\n this._s0 = this._s1;\n this._s1 = this._s2;\n this._s2 = p;\n this._seg0.setCoordinates(this._s0, this._s1);\n this.computeOffsetSegment(this._seg0, this._side, this._distance, this._offset0);\n this._seg1.setCoordinates(this._s1, this._s2);\n this.computeOffsetSegment(this._seg1, this._side, this._distance, this._offset1);\n if (this._s1.equals(this._s2)) { return null }\n var orientation = CGAlgorithms.computeOrientation(this._s0, this._s1, this._s2);\n var outsideTurn = (orientation === CGAlgorithms.CLOCKWISE && this._side === Position.LEFT) || (orientation === CGAlgorithms.COUNTERCLOCKWISE && this._side === Position.RIGHT);\n if (orientation === 0) {\n this.addCollinear(addStartPoint);\n } else if (outsideTurn) {\n this.addOutsideTurn(orientation, addStartPoint);\n } else {\n this.addInsideTurn(orientation, addStartPoint);\n }\n};\nOffsetSegmentGenerator.prototype.addLineEndCap = function addLineEndCap (p0, p1) {\n var seg = new LineSegment(p0, p1);\n var offsetL = new LineSegment();\n this.computeOffsetSegment(seg, Position.LEFT, this._distance, offsetL);\n var offsetR = new LineSegment();\n this.computeOffsetSegment(seg, Position.RIGHT, this._distance, offsetR);\n var dx = p1.x - p0.x;\n var dy = p1.y - p0.y;\n var angle = Math.atan2(dy, dx);\n switch (this._bufParams.getEndCapStyle()) {\n case BufferParameters.CAP_ROUND:\n this._segList.addPt(offsetL.p1);\n this.addFilletArc(p1, angle + Math.PI / 2, angle - Math.PI / 2, CGAlgorithms.CLOCKWISE, this._distance);\n this._segList.addPt(offsetR.p1);\n break\n case BufferParameters.CAP_FLAT:\n this._segList.addPt(offsetL.p1);\n this._segList.addPt(offsetR.p1);\n break\n case BufferParameters.CAP_SQUARE:\n var squareCapSideOffset = new Coordinate();\n squareCapSideOffset.x = Math.abs(this._distance) * Math.cos(angle);\n squareCapSideOffset.y = Math.abs(this._distance) * Math.sin(angle);\n var squareCapLOffset = new Coordinate(offsetL.p1.x + squareCapSideOffset.x, offsetL.p1.y + squareCapSideOffset.y);\n var squareCapROffset = new Coordinate(offsetR.p1.x + squareCapSideOffset.x, offsetR.p1.y + squareCapSideOffset.y);\n this._segList.addPt(squareCapLOffset);\n this._segList.addPt(squareCapROffset);\n break\n default:\n }\n};\nOffsetSegmentGenerator.prototype.getCoordinates = function getCoordinates () {\n var pts = this._segList.getCoordinates();\n return pts\n};\nOffsetSegmentGenerator.prototype.addMitreJoin = function addMitreJoin (p, offset0, offset1, distance) {\n var isMitreWithinLimit = true;\n var intPt = null;\n try {\n intPt = HCoordinate.intersection(offset0.p0, offset0.p1, offset1.p0, offset1.p1);\n var mitreRatio = distance <= 0.0 ? 1.0 : intPt.distance(p) / Math.abs(distance);\n if (mitreRatio > this._bufParams.getMitreLimit()) { isMitreWithinLimit = false; }\n } catch (ex) {\n if (ex instanceof NotRepresentableException) {\n intPt = new Coordinate(0, 0);\n isMitreWithinLimit = false;\n } else { throw ex }\n } finally {}\n if (isMitreWithinLimit) {\n this._segList.addPt(intPt);\n } else {\n this.addLimitedMitreJoin(offset0, offset1, distance, this._bufParams.getMitreLimit());\n }\n};\nOffsetSegmentGenerator.prototype.addFilletCorner = function addFilletCorner (p, p0, p1, direction, radius) {\n var dx0 = p0.x - p.x;\n var dy0 = p0.y - p.y;\n var startAngle = Math.atan2(dy0, dx0);\n var dx1 = p1.x - p.x;\n var dy1 = p1.y - p.y;\n var endAngle = Math.atan2(dy1, dx1);\n if (direction === CGAlgorithms.CLOCKWISE) {\n if (startAngle <= endAngle) { startAngle += 2.0 * Math.PI; }\n } else {\n if (startAngle >= endAngle) { startAngle -= 2.0 * Math.PI; }\n }\n this._segList.addPt(p0);\n this.addFilletArc(p, startAngle, endAngle, direction, radius);\n this._segList.addPt(p1);\n};\nOffsetSegmentGenerator.prototype.addOutsideTurn = function addOutsideTurn (orientation, addStartPoint) {\n if (this._offset0.p1.distance(this._offset1.p0) < this._distance * OffsetSegmentGenerator.OFFSET_SEGMENT_SEPARATION_FACTOR) {\n this._segList.addPt(this._offset0.p1);\n return null\n }\n if (this._bufParams.getJoinStyle() === BufferParameters.JOIN_MITRE) {\n this.addMitreJoin(this._s1, this._offset0, this._offset1, this._distance);\n } else if (this._bufParams.getJoinStyle() === BufferParameters.JOIN_BEVEL) {\n this.addBevelJoin(this._offset0, this._offset1);\n } else {\n if (addStartPoint) { this._segList.addPt(this._offset0.p1); }\n this.addFilletCorner(this._s1, this._offset0.p1, this._offset1.p0, orientation, this._distance);\n this._segList.addPt(this._offset1.p0);\n }\n};\nOffsetSegmentGenerator.prototype.createSquare = function createSquare (p) {\n this._segList.addPt(new Coordinate(p.x + this._distance, p.y + this._distance));\n this._segList.addPt(new Coordinate(p.x + this._distance, p.y - this._distance));\n this._segList.addPt(new Coordinate(p.x - this._distance, p.y - this._distance));\n this._segList.addPt(new Coordinate(p.x - this._distance, p.y + this._distance));\n this._segList.closeRing();\n};\nOffsetSegmentGenerator.prototype.addSegments = function addSegments (pt, isForward) {\n this._segList.addPts(pt, isForward);\n};\nOffsetSegmentGenerator.prototype.addFirstSegment = function addFirstSegment () {\n this._segList.addPt(this._offset1.p0);\n};\nOffsetSegmentGenerator.prototype.addLastSegment = function addLastSegment () {\n this._segList.addPt(this._offset1.p1);\n};\nOffsetSegmentGenerator.prototype.initSideSegments = function initSideSegments (s1, s2, side) {\n this._s1 = s1;\n this._s2 = s2;\n this._side = side;\n this._seg1.setCoordinates(s1, s2);\n this.computeOffsetSegment(this._seg1, side, this._distance, this._offset1);\n};\nOffsetSegmentGenerator.prototype.addLimitedMitreJoin = function addLimitedMitreJoin (offset0, offset1, distance, mitreLimit) {\n var basePt = this._seg0.p1;\n var ang0 = Angle.angle(basePt, this._seg0.p0);\n // const ang1 = Angle.angle(basePt, this._seg1.p1)\n var angDiff = Angle.angleBetweenOriented(this._seg0.p0, basePt, this._seg1.p1);\n var angDiffHalf = angDiff / 2;\n var midAng = Angle.normalize(ang0 + angDiffHalf);\n var mitreMidAng = Angle.normalize(midAng + Math.PI);\n var mitreDist = mitreLimit * distance;\n var bevelDelta = mitreDist * Math.abs(Math.sin(angDiffHalf));\n var bevelHalfLen = distance - bevelDelta;\n var bevelMidX = basePt.x + mitreDist * Math.cos(mitreMidAng);\n var bevelMidY = basePt.y + mitreDist * Math.sin(mitreMidAng);\n var bevelMidPt = new Coordinate(bevelMidX, bevelMidY);\n var mitreMidLine = new LineSegment(basePt, bevelMidPt);\n var bevelEndLeft = mitreMidLine.pointAlongOffset(1.0, bevelHalfLen);\n var bevelEndRight = mitreMidLine.pointAlongOffset(1.0, -bevelHalfLen);\n if (this._side === Position.LEFT) {\n this._segList.addPt(bevelEndLeft);\n this._segList.addPt(bevelEndRight);\n } else {\n this._segList.addPt(bevelEndRight);\n this._segList.addPt(bevelEndLeft);\n }\n};\nOffsetSegmentGenerator.prototype.computeOffsetSegment = function computeOffsetSegment (seg, side, distance, offset) {\n var sideSign = side === Position.LEFT ? 1 : -1;\n var dx = seg.p1.x - seg.p0.x;\n var dy = seg.p1.y - seg.p0.y;\n var len = Math.sqrt(dx * dx + dy * dy);\n var ux = sideSign * distance * dx / len;\n var uy = sideSign * distance * dy / len;\n offset.p0.x = seg.p0.x - uy;\n offset.p0.y = seg.p0.y + ux;\n offset.p1.x = seg.p1.x - uy;\n offset.p1.y = seg.p1.y + ux;\n};\nOffsetSegmentGenerator.prototype.addFilletArc = function addFilletArc (p, startAngle, endAngle, direction, radius) {\n var this$1 = this;\n\n var directionFactor = direction === CGAlgorithms.CLOCKWISE ? -1 : 1;\n var totalAngle = Math.abs(startAngle - endAngle);\n var nSegs = Math.trunc(totalAngle / this._filletAngleQuantum + 0.5);\n if (nSegs < 1) { return null }\n var initAngle = 0.0;\n var currAngleInc = totalAngle / nSegs;\n var currAngle = initAngle;\n var pt = new Coordinate();\n while (currAngle < totalAngle) {\n var angle = startAngle + directionFactor * currAngle;\n pt.x = p.x + radius * Math.cos(angle);\n pt.y = p.y + radius * Math.sin(angle);\n this$1._segList.addPt(pt);\n currAngle += currAngleInc;\n }\n};\nOffsetSegmentGenerator.prototype.addInsideTurn = function addInsideTurn (orientation, addStartPoint) {\n this._li.computeIntersection(this._offset0.p0, this._offset0.p1, this._offset1.p0, this._offset1.p1);\n if (this._li.hasIntersection()) {\n this._segList.addPt(this._li.getIntersection(0));\n } else {\n this._hasNarrowConcaveAngle = true;\n if (this._offset0.p1.distance(this._offset1.p0) < this._distance * OffsetSegmentGenerator.INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR) {\n this._segList.addPt(this._offset0.p1);\n } else {\n this._segList.addPt(this._offset0.p1);\n if (this._closingSegLengthFactor > 0) {\n var mid0 = new Coordinate((this._closingSegLengthFactor * this._offset0.p1.x + this._s1.x) / (this._closingSegLengthFactor + 1), (this._closingSegLengthFactor * this._offset0.p1.y + this._s1.y) / (this._closingSegLengthFactor + 1));\n this._segList.addPt(mid0);\n var mid1 = new Coordinate((this._closingSegLengthFactor * this._offset1.p0.x + this._s1.x) / (this._closingSegLengthFactor + 1), (this._closingSegLengthFactor * this._offset1.p0.y + this._s1.y) / (this._closingSegLengthFactor + 1));\n this._segList.addPt(mid1);\n } else {\n this._segList.addPt(this._s1);\n }\n this._segList.addPt(this._offset1.p0);\n }\n }\n};\nOffsetSegmentGenerator.prototype.createCircle = function createCircle (p) {\n var pt = new Coordinate(p.x + this._distance, p.y);\n this._segList.addPt(pt);\n this.addFilletArc(p, 0.0, 2.0 * Math.PI, -1, this._distance);\n this._segList.closeRing();\n};\nOffsetSegmentGenerator.prototype.addBevelJoin = function addBevelJoin (offset0, offset1) {\n this._segList.addPt(offset0.p1);\n this._segList.addPt(offset1.p0);\n};\nOffsetSegmentGenerator.prototype.init = function init (distance) {\n this._distance = distance;\n this._maxCurveSegmentError = distance * (1 - Math.cos(this._filletAngleQuantum / 2.0));\n this._segList = new OffsetSegmentString();\n this._segList.setPrecisionModel(this._precisionModel);\n this._segList.setMinimumVertexDistance(distance * OffsetSegmentGenerator.CURVE_VERTEX_SNAP_DISTANCE_FACTOR);\n};\nOffsetSegmentGenerator.prototype.addCollinear = function addCollinear (addStartPoint) {\n this._li.computeIntersection(this._s0, this._s1, this._s1, this._s2);\n var numInt = this._li.getIntersectionNum();\n if (numInt >= 2) {\n if (this._bufParams.getJoinStyle() === BufferParameters.JOIN_BEVEL || this._bufParams.getJoinStyle() === BufferParameters.JOIN_MITRE) {\n if (addStartPoint) { this._segList.addPt(this._offset0.p1); }\n this._segList.addPt(this._offset1.p0);\n } else {\n this.addFilletCorner(this._s1, this._offset0.p1, this._offset1.p0, CGAlgorithms.CLOCKWISE, this._distance);\n }\n }\n};\nOffsetSegmentGenerator.prototype.closeRing = function closeRing () {\n this._segList.closeRing();\n};\nOffsetSegmentGenerator.prototype.hasNarrowConcaveAngle = function hasNarrowConcaveAngle () {\n return this._hasNarrowConcaveAngle\n};\nOffsetSegmentGenerator.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nOffsetSegmentGenerator.prototype.getClass = function getClass () {\n return OffsetSegmentGenerator\n};\nstaticAccessors$27.OFFSET_SEGMENT_SEPARATION_FACTOR.get = function () { return 1.0E-3 };\nstaticAccessors$27.INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR.get = function () { return 1.0E-3 };\nstaticAccessors$27.CURVE_VERTEX_SNAP_DISTANCE_FACTOR.get = function () { return 1.0E-6 };\nstaticAccessors$27.MAX_CLOSING_SEG_LEN_FACTOR.get = function () { return 80 };\n\nObject.defineProperties( OffsetSegmentGenerator, staticAccessors$27 );\n\nvar OffsetCurveBuilder = function OffsetCurveBuilder () {\n this._distance = 0.0;\n this._precisionModel = null;\n this._bufParams = null;\n var precisionModel = arguments[0];\n var bufParams = arguments[1];\n this._precisionModel = precisionModel;\n this._bufParams = bufParams;\n};\nOffsetCurveBuilder.prototype.getOffsetCurve = function getOffsetCurve (inputPts, distance) {\n this._distance = distance;\n if (distance === 0.0) { return null }\n var isRightSide = distance < 0.0;\n var posDistance = Math.abs(distance);\n var segGen = this.getSegGen(posDistance);\n if (inputPts.length <= 1) {\n this.computePointCurve(inputPts[0], segGen);\n } else {\n this.computeOffsetCurve(inputPts, isRightSide, segGen);\n }\n var curvePts = segGen.getCoordinates();\n if (isRightSide) { CoordinateArrays.reverse(curvePts); }\n return curvePts\n};\nOffsetCurveBuilder.prototype.computeSingleSidedBufferCurve = function computeSingleSidedBufferCurve (inputPts, isRightSide, segGen) {\n var distTol = this.simplifyTolerance(this._distance);\n if (isRightSide) {\n segGen.addSegments(inputPts, true);\n var simp2 = BufferInputLineSimplifier.simplify(inputPts, -distTol);\n var n2 = simp2.length - 1;\n segGen.initSideSegments(simp2[n2], simp2[n2 - 1], Position.LEFT);\n segGen.addFirstSegment();\n for (var i = n2 - 2; i >= 0; i--) {\n segGen.addNextSegment(simp2[i], true);\n }\n } else {\n segGen.addSegments(inputPts, false);\n var simp1 = BufferInputLineSimplifier.simplify(inputPts, distTol);\n var n1 = simp1.length - 1;\n segGen.initSideSegments(simp1[0], simp1[1], Position.LEFT);\n segGen.addFirstSegment();\n for (var i$1 = 2; i$1 <= n1; i$1++) {\n segGen.addNextSegment(simp1[i$1], true);\n }\n }\n segGen.addLastSegment();\n segGen.closeRing();\n};\nOffsetCurveBuilder.prototype.computeRingBufferCurve = function computeRingBufferCurve (inputPts, side, segGen) {\n var distTol = this.simplifyTolerance(this._distance);\n if (side === Position.RIGHT) { distTol = -distTol; }\n var simp = BufferInputLineSimplifier.simplify(inputPts, distTol);\n var n = simp.length - 1;\n segGen.initSideSegments(simp[n - 1], simp[0], side);\n for (var i = 1; i <= n; i++) {\n var addStartPoint = i !== 1;\n segGen.addNextSegment(simp[i], addStartPoint);\n }\n segGen.closeRing();\n};\nOffsetCurveBuilder.prototype.computeLineBufferCurve = function computeLineBufferCurve (inputPts, segGen) {\n var distTol = this.simplifyTolerance(this._distance);\n var simp1 = BufferInputLineSimplifier.simplify(inputPts, distTol);\n var n1 = simp1.length - 1;\n segGen.initSideSegments(simp1[0], simp1[1], Position.LEFT);\n for (var i = 2; i <= n1; i++) {\n segGen.addNextSegment(simp1[i], true);\n }\n segGen.addLastSegment();\n segGen.addLineEndCap(simp1[n1 - 1], simp1[n1]);\n var simp2 = BufferInputLineSimplifier.simplify(inputPts, -distTol);\n var n2 = simp2.length - 1;\n segGen.initSideSegments(simp2[n2], simp2[n2 - 1], Position.LEFT);\n for (var i$1 = n2 - 2; i$1 >= 0; i$1--) {\n segGen.addNextSegment(simp2[i$1], true);\n }\n segGen.addLastSegment();\n segGen.addLineEndCap(simp2[1], simp2[0]);\n segGen.closeRing();\n};\nOffsetCurveBuilder.prototype.computePointCurve = function computePointCurve (pt, segGen) {\n switch (this._bufParams.getEndCapStyle()) {\n case BufferParameters.CAP_ROUND:\n segGen.createCircle(pt);\n break\n case BufferParameters.CAP_SQUARE:\n segGen.createSquare(pt);\n break\n default:\n }\n};\nOffsetCurveBuilder.prototype.getLineCurve = function getLineCurve (inputPts, distance) {\n this._distance = distance;\n if (distance < 0.0 && !this._bufParams.isSingleSided()) { return null }\n if (distance === 0.0) { return null }\n var posDistance = Math.abs(distance);\n var segGen = this.getSegGen(posDistance);\n if (inputPts.length <= 1) {\n this.computePointCurve(inputPts[0], segGen);\n } else {\n if (this._bufParams.isSingleSided()) {\n var isRightSide = distance < 0.0;\n this.computeSingleSidedBufferCurve(inputPts, isRightSide, segGen);\n } else { this.computeLineBufferCurve(inputPts, segGen); }\n }\n var lineCoord = segGen.getCoordinates();\n return lineCoord\n};\nOffsetCurveBuilder.prototype.getBufferParameters = function getBufferParameters () {\n return this._bufParams\n};\nOffsetCurveBuilder.prototype.simplifyTolerance = function simplifyTolerance (bufDistance) {\n return bufDistance * this._bufParams.getSimplifyFactor()\n};\nOffsetCurveBuilder.prototype.getRingCurve = function getRingCurve (inputPts, side, distance) {\n this._distance = distance;\n if (inputPts.length <= 2) { return this.getLineCurve(inputPts, distance) }\n if (distance === 0.0) {\n return OffsetCurveBuilder.copyCoordinates(inputPts)\n }\n var segGen = this.getSegGen(distance);\n this.computeRingBufferCurve(inputPts, side, segGen);\n return segGen.getCoordinates()\n};\nOffsetCurveBuilder.prototype.computeOffsetCurve = function computeOffsetCurve (inputPts, isRightSide, segGen) {\n var distTol = this.simplifyTolerance(this._distance);\n if (isRightSide) {\n var simp2 = BufferInputLineSimplifier.simplify(inputPts, -distTol);\n var n2 = simp2.length - 1;\n segGen.initSideSegments(simp2[n2], simp2[n2 - 1], Position.LEFT);\n segGen.addFirstSegment();\n for (var i = n2 - 2; i >= 0; i--) {\n segGen.addNextSegment(simp2[i], true);\n }\n } else {\n var simp1 = BufferInputLineSimplifier.simplify(inputPts, distTol);\n var n1 = simp1.length - 1;\n segGen.initSideSegments(simp1[0], simp1[1], Position.LEFT);\n segGen.addFirstSegment();\n for (var i$1 = 2; i$1 <= n1; i$1++) {\n segGen.addNextSegment(simp1[i$1], true);\n }\n }\n segGen.addLastSegment();\n};\nOffsetCurveBuilder.prototype.getSegGen = function getSegGen (distance) {\n return new OffsetSegmentGenerator(this._precisionModel, this._bufParams, distance)\n};\nOffsetCurveBuilder.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nOffsetCurveBuilder.prototype.getClass = function getClass () {\n return OffsetCurveBuilder\n};\nOffsetCurveBuilder.copyCoordinates = function copyCoordinates (pts) {\n var copy = new Array(pts.length).fill(null);\n for (var i = 0; i < copy.length; i++) {\n copy[i] = new Coordinate(pts[i]);\n }\n return copy\n};\n\nvar SubgraphDepthLocater = function SubgraphDepthLocater () {\n this._subgraphs = null;\n this._seg = new LineSegment();\n this._cga = new CGAlgorithms();\n var subgraphs = arguments[0];\n this._subgraphs = subgraphs;\n};\n\nvar staticAccessors$30 = { DepthSegment: { configurable: true } };\nSubgraphDepthLocater.prototype.findStabbedSegments = function findStabbedSegments () {\n var this$1 = this;\n\n if (arguments.length === 1) {\n var stabbingRayLeftPt = arguments[0];\n var stabbedSegments = new ArrayList();\n for (var i = this._subgraphs.iterator(); i.hasNext();) {\n var bsg = i.next();\n var env = bsg.getEnvelope();\n if (stabbingRayLeftPt.y < env.getMinY() || stabbingRayLeftPt.y > env.getMaxY()) { continue }\n this$1.findStabbedSegments(stabbingRayLeftPt, bsg.getDirectedEdges(), stabbedSegments);\n }\n return stabbedSegments\n } else if (arguments.length === 3) {\n if (hasInterface(arguments[2], List) && (arguments[0] instanceof Coordinate && arguments[1] instanceof DirectedEdge)) {\n var stabbingRayLeftPt$1 = arguments[0];\n var dirEdge = arguments[1];\n var stabbedSegments$1 = arguments[2];\n var pts = dirEdge.getEdge().getCoordinates();\n for (var i$1 = 0; i$1 < pts.length - 1; i$1++) {\n this$1._seg.p0 = pts[i$1];\n this$1._seg.p1 = pts[i$1 + 1];\n if (this$1._seg.p0.y > this$1._seg.p1.y) { this$1._seg.reverse(); }\n var maxx = Math.max(this$1._seg.p0.x, this$1._seg.p1.x);\n if (maxx < stabbingRayLeftPt$1.x) { continue }\n if (this$1._seg.isHorizontal()) { continue }\n if (stabbingRayLeftPt$1.y < this$1._seg.p0.y || stabbingRayLeftPt$1.y > this$1._seg.p1.y) { continue }\n if (CGAlgorithms.computeOrientation(this$1._seg.p0, this$1._seg.p1, stabbingRayLeftPt$1) === CGAlgorithms.RIGHT) { continue }\n var depth = dirEdge.getDepth(Position.LEFT);\n if (!this$1._seg.p0.equals(pts[i$1])) { depth = dirEdge.getDepth(Position.RIGHT); }\n var ds = new DepthSegment(this$1._seg, depth);\n stabbedSegments$1.add(ds);\n }\n } else if (hasInterface(arguments[2], List) && (arguments[0] instanceof Coordinate && hasInterface(arguments[1], List))) {\n var stabbingRayLeftPt$2 = arguments[0];\n var dirEdges = arguments[1];\n var stabbedSegments$2 = arguments[2];\n for (var i$2 = dirEdges.iterator(); i$2.hasNext();) {\n var de = i$2.next();\n if (!de.isForward()) { continue }\n this$1.findStabbedSegments(stabbingRayLeftPt$2, de, stabbedSegments$2);\n }\n }\n }\n};\nSubgraphDepthLocater.prototype.getDepth = function getDepth (p) {\n var stabbedSegments = this.findStabbedSegments(p);\n if (stabbedSegments.size() === 0) { return 0 }\n var ds = Collections.min(stabbedSegments);\n return ds._leftDepth\n};\nSubgraphDepthLocater.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nSubgraphDepthLocater.prototype.getClass = function getClass () {\n return SubgraphDepthLocater\n};\nstaticAccessors$30.DepthSegment.get = function () { return DepthSegment };\n\nObject.defineProperties( SubgraphDepthLocater, staticAccessors$30 );\n\nvar DepthSegment = function DepthSegment () {\n this._upwardSeg = null;\n this._leftDepth = null;\n var seg = arguments[0];\n var depth = arguments[1];\n this._upwardSeg = new LineSegment(seg);\n this._leftDepth = depth;\n};\nDepthSegment.prototype.compareTo = function compareTo (obj) {\n var other = obj;\n if (this._upwardSeg.minX() >= other._upwardSeg.maxX()) { return 1 }\n if (this._upwardSeg.maxX() <= other._upwardSeg.minX()) { return -1 }\n var orientIndex = this._upwardSeg.orientationIndex(other._upwardSeg);\n if (orientIndex !== 0) { return orientIndex }\n orientIndex = -1 * other._upwardSeg.orientationIndex(this._upwardSeg);\n if (orientIndex !== 0) { return orientIndex }\n return this._upwardSeg.compareTo(other._upwardSeg)\n};\nDepthSegment.prototype.compareX = function compareX (seg0, seg1) {\n var compare0 = seg0.p0.compareTo(seg1.p0);\n if (compare0 !== 0) { return compare0 }\n return seg0.p1.compareTo(seg1.p1)\n};\nDepthSegment.prototype.toString = function toString () {\n return this._upwardSeg.toString()\n};\nDepthSegment.prototype.interfaces_ = function interfaces_ () {\n return [Comparable]\n};\nDepthSegment.prototype.getClass = function getClass () {\n return DepthSegment\n};\n\nvar Triangle = function Triangle (p0, p1, p2) {\n this.p0 = p0 || null;\n this.p1 = p1 || null;\n this.p2 = p2 || null;\n};\nTriangle.prototype.area = function area () {\n return Triangle.area(this.p0, this.p1, this.p2)\n};\nTriangle.prototype.signedArea = function signedArea () {\n return Triangle.signedArea(this.p0, this.p1, this.p2)\n};\nTriangle.prototype.interpolateZ = function interpolateZ (p) {\n if (p === null) { throw new IllegalArgumentException('Supplied point is null.') }\n return Triangle.interpolateZ(p, this.p0, this.p1, this.p2)\n};\nTriangle.prototype.longestSideLength = function longestSideLength () {\n return Triangle.longestSideLength(this.p0, this.p1, this.p2)\n};\nTriangle.prototype.isAcute = function isAcute () {\n return Triangle.isAcute(this.p0, this.p1, this.p2)\n};\nTriangle.prototype.circumcentre = function circumcentre () {\n return Triangle.circumcentre(this.p0, this.p1, this.p2)\n};\nTriangle.prototype.area3D = function area3D () {\n return Triangle.area3D(this.p0, this.p1, this.p2)\n};\nTriangle.prototype.centroid = function centroid () {\n return Triangle.centroid(this.p0, this.p1, this.p2)\n};\nTriangle.prototype.inCentre = function inCentre () {\n return Triangle.inCentre(this.p0, this.p1, this.p2)\n};\nTriangle.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nTriangle.prototype.getClass = function getClass () {\n return Triangle\n};\nTriangle.area = function area (a, b, c) {\n return Math.abs(((c.x - a.x) * (b.y - a.y) - (b.x - a.x) * (c.y - a.y)) / 2)\n};\nTriangle.signedArea = function signedArea (a, b, c) {\n return ((c.x - a.x) * (b.y - a.y) - (b.x - a.x) * (c.y - a.y)) / 2\n};\nTriangle.det = function det (m00, m01, m10, m11) {\n return m00 * m11 - m01 * m10\n};\nTriangle.interpolateZ = function interpolateZ (p, v0, v1, v2) {\n var x0 = v0.x;\n var y0 = v0.y;\n var a = v1.x - x0;\n var b = v2.x - x0;\n var c = v1.y - y0;\n var d = v2.y - y0;\n var det = a * d - b * c;\n var dx = p.x - x0;\n var dy = p.y - y0;\n var t = (d * dx - b * dy) / det;\n var u = (-c * dx + a * dy) / det;\n var z = v0.z + t * (v1.z - v0.z) + u * (v2.z - v0.z);\n return z\n};\nTriangle.longestSideLength = function longestSideLength (a, b, c) {\n var lenAB = a.distance(b);\n var lenBC = b.distance(c);\n var lenCA = c.distance(a);\n var maxLen = lenAB;\n if (lenBC > maxLen) { maxLen = lenBC; }\n if (lenCA > maxLen) { maxLen = lenCA; }\n return maxLen\n};\nTriangle.isAcute = function isAcute (a, b, c) {\n if (!Angle.isAcute(a, b, c)) { return false }\n if (!Angle.isAcute(b, c, a)) { return false }\n if (!Angle.isAcute(c, a, b)) { return false }\n return true\n};\nTriangle.circumcentre = function circumcentre (a, b, c) {\n var cx = c.x;\n var cy = c.y;\n var ax = a.x - cx;\n var ay = a.y - cy;\n var bx = b.x - cx;\n var by = b.y - cy;\n var denom = 2 * Triangle.det(ax, ay, bx, by);\n var numx = Triangle.det(ay, ax * ax + ay * ay, by, bx * bx + by * by);\n var numy = Triangle.det(ax, ax * ax + ay * ay, bx, bx * bx + by * by);\n var ccx = cx - numx / denom;\n var ccy = cy + numy / denom;\n return new Coordinate(ccx, ccy)\n};\nTriangle.perpendicularBisector = function perpendicularBisector (a, b) {\n var dx = b.x - a.x;\n var dy = b.y - a.y;\n var l1 = new HCoordinate(a.x + dx / 2.0, a.y + dy / 2.0, 1.0);\n var l2 = new HCoordinate(a.x - dy + dx / 2.0, a.y + dx + dy / 2.0, 1.0);\n return new HCoordinate(l1, l2)\n};\nTriangle.angleBisector = function angleBisector (a, b, c) {\n var len0 = b.distance(a);\n var len2 = b.distance(c);\n var frac = len0 / (len0 + len2);\n var dx = c.x - a.x;\n var dy = c.y - a.y;\n var splitPt = new Coordinate(a.x + frac * dx, a.y + frac * dy);\n return splitPt\n};\nTriangle.area3D = function area3D (a, b, c) {\n var ux = b.x - a.x;\n var uy = b.y - a.y;\n var uz = b.z - a.z;\n var vx = c.x - a.x;\n var vy = c.y - a.y;\n var vz = c.z - a.z;\n var crossx = uy * vz - uz * vy;\n var crossy = uz * vx - ux * vz;\n var crossz = ux * vy - uy * vx;\n var absSq = crossx * crossx + crossy * crossy + crossz * crossz;\n var area3D = Math.sqrt(absSq) / 2;\n return area3D\n};\nTriangle.centroid = function centroid (a, b, c) {\n var x = (a.x + b.x + c.x) / 3;\n var y = (a.y + b.y + c.y) / 3;\n return new Coordinate(x, y)\n};\nTriangle.inCentre = function inCentre (a, b, c) {\n var len0 = b.distance(c);\n var len1 = a.distance(c);\n var len2 = a.distance(b);\n var circum = len0 + len1 + len2;\n var inCentreX = (len0 * a.x + len1 * b.x + len2 * c.x) / circum;\n var inCentreY = (len0 * a.y + len1 * b.y + len2 * c.y) / circum;\n return new Coordinate(inCentreX, inCentreY)\n};\n\nvar OffsetCurveSetBuilder = function OffsetCurveSetBuilder () {\n this._inputGeom = null;\n this._distance = null;\n this._curveBuilder = null;\n this._curveList = new ArrayList();\n var inputGeom = arguments[0];\n var distance = arguments[1];\n var curveBuilder = arguments[2];\n this._inputGeom = inputGeom;\n this._distance = distance;\n this._curveBuilder = curveBuilder;\n};\nOffsetCurveSetBuilder.prototype.addPoint = function addPoint (p) {\n if (this._distance <= 0.0) { return null }\n var coord = p.getCoordinates();\n var curve = this._curveBuilder.getLineCurve(coord, this._distance);\n this.addCurve(curve, Location.EXTERIOR, Location.INTERIOR);\n};\nOffsetCurveSetBuilder.prototype.addPolygon = function addPolygon (p) {\n var this$1 = this;\n\n var offsetDistance = this._distance;\n var offsetSide = Position.LEFT;\n if (this._distance < 0.0) {\n offsetDistance = -this._distance;\n offsetSide = Position.RIGHT;\n }\n var shell = p.getExteriorRing();\n var shellCoord = CoordinateArrays.removeRepeatedPoints(shell.getCoordinates());\n if (this._distance < 0.0 && this.isErodedCompletely(shell, this._distance)) { return null }\n if (this._distance <= 0.0 && shellCoord.length < 3) { return null }\n this.addPolygonRing(shellCoord, offsetDistance, offsetSide, Location.EXTERIOR, Location.INTERIOR);\n for (var i = 0; i < p.getNumInteriorRing(); i++) {\n var hole = p.getInteriorRingN(i);\n var holeCoord = CoordinateArrays.removeRepeatedPoints(hole.getCoordinates());\n if (this$1._distance > 0.0 && this$1.isErodedCompletely(hole, -this$1._distance)) { continue }\n this$1.addPolygonRing(holeCoord, offsetDistance, Position.opposite(offsetSide), Location.INTERIOR, Location.EXTERIOR);\n }\n};\nOffsetCurveSetBuilder.prototype.isTriangleErodedCompletely = function isTriangleErodedCompletely (triangleCoord, bufferDistance) {\n var tri = new Triangle(triangleCoord[0], triangleCoord[1], triangleCoord[2]);\n var inCentre = tri.inCentre();\n var distToCentre = CGAlgorithms.distancePointLine(inCentre, tri.p0, tri.p1);\n return distToCentre < Math.abs(bufferDistance)\n};\nOffsetCurveSetBuilder.prototype.addLineString = function addLineString (line) {\n if (this._distance <= 0.0 && !this._curveBuilder.getBufferParameters().isSingleSided()) { return null }\n var coord = CoordinateArrays.removeRepeatedPoints(line.getCoordinates());\n var curve = this._curveBuilder.getLineCurve(coord, this._distance);\n this.addCurve(curve, Location.EXTERIOR, Location.INTERIOR);\n};\nOffsetCurveSetBuilder.prototype.addCurve = function addCurve (coord, leftLoc, rightLoc) {\n if (coord === null || coord.length < 2) { return null }\n var e = new NodedSegmentString(coord, new Label(0, Location.BOUNDARY, leftLoc, rightLoc));\n this._curveList.add(e);\n};\nOffsetCurveSetBuilder.prototype.getCurves = function getCurves () {\n this.add(this._inputGeom);\n return this._curveList\n};\nOffsetCurveSetBuilder.prototype.addPolygonRing = function addPolygonRing (coord, offsetDistance, side, cwLeftLoc, cwRightLoc) {\n if (offsetDistance === 0.0 && coord.length < LinearRing.MINIMUM_VALID_SIZE) { return null }\n var leftLoc = cwLeftLoc;\n var rightLoc = cwRightLoc;\n if (coord.length >= LinearRing.MINIMUM_VALID_SIZE && CGAlgorithms.isCCW(coord)) {\n leftLoc = cwRightLoc;\n rightLoc = cwLeftLoc;\n side = Position.opposite(side);\n }\n var curve = this._curveBuilder.getRingCurve(coord, side, offsetDistance);\n this.addCurve(curve, leftLoc, rightLoc);\n};\nOffsetCurveSetBuilder.prototype.add = function add (g) {\n if (g.isEmpty()) { return null }\n if (g instanceof Polygon) { this.addPolygon(g); }\n else if (g instanceof LineString) { this.addLineString(g); }\n else if (g instanceof Point) { this.addPoint(g); }\n else if (g instanceof MultiPoint) { this.addCollection(g); }\n else if (g instanceof MultiLineString) { this.addCollection(g); }\n else if (g instanceof MultiPolygon) { this.addCollection(g); }\n else if (g instanceof GeometryCollection) { this.addCollection(g); }\n // else throw new UnsupportedOperationException(g.getClass().getName())\n};\nOffsetCurveSetBuilder.prototype.isErodedCompletely = function isErodedCompletely (ring, bufferDistance) {\n var ringCoord = ring.getCoordinates();\n // const minDiam = 0.0\n if (ringCoord.length < 4) { return bufferDistance < 0 }\n if (ringCoord.length === 4) { return this.isTriangleErodedCompletely(ringCoord, bufferDistance) }\n var env = ring.getEnvelopeInternal();\n var envMinDimension = Math.min(env.getHeight(), env.getWidth());\n if (bufferDistance < 0.0 && 2 * Math.abs(bufferDistance) > envMinDimension) { return true }\n return false\n};\nOffsetCurveSetBuilder.prototype.addCollection = function addCollection (gc) {\n var this$1 = this;\n\n for (var i = 0; i < gc.getNumGeometries(); i++) {\n var g = gc.getGeometryN(i);\n this$1.add(g);\n }\n};\nOffsetCurveSetBuilder.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nOffsetCurveSetBuilder.prototype.getClass = function getClass () {\n return OffsetCurveSetBuilder\n};\n\nvar PointOnGeometryLocator = function PointOnGeometryLocator () {};\n\nPointOnGeometryLocator.prototype.locate = function locate (p) {};\nPointOnGeometryLocator.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nPointOnGeometryLocator.prototype.getClass = function getClass () {\n return PointOnGeometryLocator\n};\n\nvar GeometryCollectionIterator = function GeometryCollectionIterator () {\n this._parent = null;\n this._atStart = null;\n this._max = null;\n this._index = null;\n this._subcollectionIterator = null;\n var parent = arguments[0];\n this._parent = parent;\n this._atStart = true;\n this._index = 0;\n this._max = parent.getNumGeometries();\n};\nGeometryCollectionIterator.prototype.next = function next () {\n if (this._atStart) {\n this._atStart = false;\n if (GeometryCollectionIterator.isAtomic(this._parent)) { this._index++; }\n return this._parent\n }\n if (this._subcollectionIterator !== null) {\n if (this._subcollectionIterator.hasNext()) {\n return this._subcollectionIterator.next()\n } else {\n this._subcollectionIterator = null;\n }\n }\n if (this._index >= this._max) {\n throw new NoSuchElementException()\n }\n var obj = this._parent.getGeometryN(this._index++);\n if (obj instanceof GeometryCollection) {\n this._subcollectionIterator = new GeometryCollectionIterator(obj);\n return this._subcollectionIterator.next()\n }\n return obj\n};\nGeometryCollectionIterator.prototype.remove = function remove () {\n throw new Error(this.getClass().getName())\n};\nGeometryCollectionIterator.prototype.hasNext = function hasNext () {\n if (this._atStart) {\n return true\n }\n if (this._subcollectionIterator !== null) {\n if (this._subcollectionIterator.hasNext()) {\n return true\n }\n this._subcollectionIterator = null;\n }\n if (this._index >= this._max) {\n return false\n }\n return true\n};\nGeometryCollectionIterator.prototype.interfaces_ = function interfaces_ () {\n return [Iterator]\n};\nGeometryCollectionIterator.prototype.getClass = function getClass () {\n return GeometryCollectionIterator\n};\nGeometryCollectionIterator.isAtomic = function isAtomic (geom) {\n return !(geom instanceof GeometryCollection)\n};\n\nvar SimplePointInAreaLocator = function SimplePointInAreaLocator () {\n this._geom = null;\n var geom = arguments[0];\n this._geom = geom;\n};\nSimplePointInAreaLocator.prototype.locate = function locate (p) {\n return SimplePointInAreaLocator.locate(p, this._geom)\n};\nSimplePointInAreaLocator.prototype.interfaces_ = function interfaces_ () {\n return [PointOnGeometryLocator]\n};\nSimplePointInAreaLocator.prototype.getClass = function getClass () {\n return SimplePointInAreaLocator\n};\nSimplePointInAreaLocator.isPointInRing = function isPointInRing (p, ring) {\n if (!ring.getEnvelopeInternal().intersects(p)) { return false }\n return CGAlgorithms.isPointInRing(p, ring.getCoordinates())\n};\nSimplePointInAreaLocator.containsPointInPolygon = function containsPointInPolygon (p, poly) {\n if (poly.isEmpty()) { return false }\n var shell = poly.getExteriorRing();\n if (!SimplePointInAreaLocator.isPointInRing(p, shell)) { return false }\n for (var i = 0; i < poly.getNumInteriorRing(); i++) {\n var hole = poly.getInteriorRingN(i);\n if (SimplePointInAreaLocator.isPointInRing(p, hole)) { return false }\n }\n return true\n};\nSimplePointInAreaLocator.containsPoint = function containsPoint (p, geom) {\n if (geom instanceof Polygon) {\n return SimplePointInAreaLocator.containsPointInPolygon(p, geom)\n } else if (geom instanceof GeometryCollection) {\n var geomi = new GeometryCollectionIterator(geom);\n while (geomi.hasNext()) {\n var g2 = geomi.next();\n if (g2 !== geom) { if (SimplePointInAreaLocator.containsPoint(p, g2)) { return true } }\n }\n }\n return false\n};\nSimplePointInAreaLocator.locate = function locate (p, geom) {\n if (geom.isEmpty()) { return Location.EXTERIOR }\n if (SimplePointInAreaLocator.containsPoint(p, geom)) { return Location.INTERIOR }\n return Location.EXTERIOR\n};\n\nvar EdgeEndStar = function EdgeEndStar () {\n this._edgeMap = new TreeMap();\n this._edgeList = null;\n this._ptInAreaLocation = [Location.NONE, Location.NONE];\n};\nEdgeEndStar.prototype.getNextCW = function getNextCW (ee) {\n this.getEdges();\n var i = this._edgeList.indexOf(ee);\n var iNextCW = i - 1;\n if (i === 0) { iNextCW = this._edgeList.size() - 1; }\n return this._edgeList.get(iNextCW)\n};\nEdgeEndStar.prototype.propagateSideLabels = function propagateSideLabels (geomIndex) {\n var startLoc = Location.NONE;\n for (var it = this.iterator(); it.hasNext();) {\n var e = it.next();\n var label = e.getLabel();\n if (label.isArea(geomIndex) && label.getLocation(geomIndex, Position.LEFT) !== Location.NONE) { startLoc = label.getLocation(geomIndex, Position.LEFT); }\n }\n if (startLoc === Location.NONE) { return null }\n var currLoc = startLoc;\n for (var it$1 = this.iterator(); it$1.hasNext();) {\n var e$1 = it$1.next();\n var label$1 = e$1.getLabel();\n if (label$1.getLocation(geomIndex, Position.ON) === Location.NONE) { label$1.setLocation(geomIndex, Position.ON, currLoc); }\n if (label$1.isArea(geomIndex)) {\n var leftLoc = label$1.getLocation(geomIndex, Position.LEFT);\n var rightLoc = label$1.getLocation(geomIndex, Position.RIGHT);\n if (rightLoc !== Location.NONE) {\n if (rightLoc !== currLoc) { throw new TopologyException('side location conflict', e$1.getCoordinate()) }\n if (leftLoc === Location.NONE) {\n Assert.shouldNeverReachHere('found single null side (at ' + e$1.getCoordinate() + ')');\n }\n currLoc = leftLoc;\n } else {\n Assert.isTrue(label$1.getLocation(geomIndex, Position.LEFT) === Location.NONE, 'found single null side');\n label$1.setLocation(geomIndex, Position.RIGHT, currLoc);\n label$1.setLocation(geomIndex, Position.LEFT, currLoc);\n }\n }\n }\n};\nEdgeEndStar.prototype.getCoordinate = function getCoordinate () {\n var it = this.iterator();\n if (!it.hasNext()) { return null }\n var e = it.next();\n return e.getCoordinate()\n};\nEdgeEndStar.prototype.print = function print (out) {\n System.out.println('EdgeEndStar: ' + this.getCoordinate());\n for (var it = this.iterator(); it.hasNext();) {\n var e = it.next();\n e.print(out);\n }\n};\nEdgeEndStar.prototype.isAreaLabelsConsistent = function isAreaLabelsConsistent (geomGraph) {\n this.computeEdgeEndLabels(geomGraph.getBoundaryNodeRule());\n return this.checkAreaLabelsConsistent(0)\n};\nEdgeEndStar.prototype.checkAreaLabelsConsistent = function checkAreaLabelsConsistent (geomIndex) {\n var edges = this.getEdges();\n if (edges.size() <= 0) { return true }\n var lastEdgeIndex = edges.size() - 1;\n var startLabel = edges.get(lastEdgeIndex).getLabel();\n var startLoc = startLabel.getLocation(geomIndex, Position.LEFT);\n Assert.isTrue(startLoc !== Location.NONE, 'Found unlabelled area edge');\n var currLoc = startLoc;\n for (var it = this.iterator(); it.hasNext();) {\n var e = it.next();\n var label = e.getLabel();\n Assert.isTrue(label.isArea(geomIndex), 'Found non-area edge');\n var leftLoc = label.getLocation(geomIndex, Position.LEFT);\n var rightLoc = label.getLocation(geomIndex, Position.RIGHT);\n if (leftLoc === rightLoc) {\n return false\n }\n if (rightLoc !== currLoc) {\n return false\n }\n currLoc = leftLoc;\n }\n return true\n};\nEdgeEndStar.prototype.findIndex = function findIndex (eSearch) {\n var this$1 = this;\n\n this.iterator();\n for (var i = 0; i < this._edgeList.size(); i++) {\n var e = this$1._edgeList.get(i);\n if (e === eSearch) { return i }\n }\n return -1\n};\nEdgeEndStar.prototype.iterator = function iterator () {\n return this.getEdges().iterator()\n};\nEdgeEndStar.prototype.getEdges = function getEdges () {\n if (this._edgeList === null) {\n this._edgeList = new ArrayList(this._edgeMap.values());\n }\n return this._edgeList\n};\nEdgeEndStar.prototype.getLocation = function getLocation (geomIndex, p, geom) {\n if (this._ptInAreaLocation[geomIndex] === Location.NONE) {\n this._ptInAreaLocation[geomIndex] = SimplePointInAreaLocator.locate(p, geom[geomIndex].getGeometry());\n }\n return this._ptInAreaLocation[geomIndex]\n};\nEdgeEndStar.prototype.toString = function toString () {\n var buf = new StringBuffer();\n buf.append('EdgeEndStar: ' + this.getCoordinate());\n buf.append('\\n');\n for (var it = this.iterator(); it.hasNext();) {\n var e = it.next();\n buf.append(e);\n buf.append('\\n');\n }\n return buf.toString()\n};\nEdgeEndStar.prototype.computeEdgeEndLabels = function computeEdgeEndLabels (boundaryNodeRule) {\n for (var it = this.iterator(); it.hasNext();) {\n var ee = it.next();\n ee.computeLabel(boundaryNodeRule);\n }\n};\nEdgeEndStar.prototype.computeLabelling = function computeLabelling (geomGraph) {\n var this$1 = this;\n\n this.computeEdgeEndLabels(geomGraph[0].getBoundaryNodeRule());\n this.propagateSideLabels(0);\n this.propagateSideLabels(1);\n var hasDimensionalCollapseEdge = [false, false];\n for (var it = this.iterator(); it.hasNext();) {\n var e = it.next();\n var label = e.getLabel();\n for (var geomi = 0; geomi < 2; geomi++) {\n if (label.isLine(geomi) && label.getLocation(geomi) === Location.BOUNDARY) { hasDimensionalCollapseEdge[geomi] = true; }\n }\n }\n for (var it$1 = this.iterator(); it$1.hasNext();) {\n var e$1 = it$1.next();\n var label$1 = e$1.getLabel();\n for (var geomi$1 = 0; geomi$1 < 2; geomi$1++) {\n if (label$1.isAnyNull(geomi$1)) {\n var loc = Location.NONE;\n if (hasDimensionalCollapseEdge[geomi$1]) {\n loc = Location.EXTERIOR;\n } else {\n var p = e$1.getCoordinate();\n loc = this$1.getLocation(geomi$1, p, geomGraph);\n }\n label$1.setAllLocationsIfNull(geomi$1, loc);\n }\n }\n }\n};\nEdgeEndStar.prototype.getDegree = function getDegree () {\n return this._edgeMap.size()\n};\nEdgeEndStar.prototype.insertEdgeEnd = function insertEdgeEnd (e, obj) {\n this._edgeMap.put(e, obj);\n this._edgeList = null;\n};\nEdgeEndStar.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nEdgeEndStar.prototype.getClass = function getClass () {\n return EdgeEndStar\n};\n\nvar DirectedEdgeStar = (function (EdgeEndStar$$1) {\n function DirectedEdgeStar () {\n EdgeEndStar$$1.call(this);\n this._resultAreaEdgeList = null;\n this._label = null;\n this._SCANNING_FOR_INCOMING = 1;\n this._LINKING_TO_OUTGOING = 2;\n }\n\n if ( EdgeEndStar$$1 ) DirectedEdgeStar.__proto__ = EdgeEndStar$$1;\n DirectedEdgeStar.prototype = Object.create( EdgeEndStar$$1 && EdgeEndStar$$1.prototype );\n DirectedEdgeStar.prototype.constructor = DirectedEdgeStar;\n DirectedEdgeStar.prototype.linkResultDirectedEdges = function linkResultDirectedEdges () {\n var this$1 = this;\n\n this.getResultAreaEdges();\n var firstOut = null;\n var incoming = null;\n var state = this._SCANNING_FOR_INCOMING;\n for (var i = 0; i < this._resultAreaEdgeList.size(); i++) {\n var nextOut = this$1._resultAreaEdgeList.get(i);\n var nextIn = nextOut.getSym();\n if (!nextOut.getLabel().isArea()) { continue }\n if (firstOut === null && nextOut.isInResult()) { firstOut = nextOut; }\n switch (state) {\n case this$1._SCANNING_FOR_INCOMING:\n if (!nextIn.isInResult()) { continue }\n incoming = nextIn;\n state = this$1._LINKING_TO_OUTGOING;\n break\n case this$1._LINKING_TO_OUTGOING:\n if (!nextOut.isInResult()) { continue }\n incoming.setNext(nextOut);\n state = this$1._SCANNING_FOR_INCOMING;\n break\n default:\n }\n }\n if (state === this._LINKING_TO_OUTGOING) {\n if (firstOut === null) { throw new TopologyException('no outgoing dirEdge found', this.getCoordinate()) }\n Assert.isTrue(firstOut.isInResult(), 'unable to link last incoming dirEdge');\n incoming.setNext(firstOut);\n }\n };\n DirectedEdgeStar.prototype.insert = function insert (ee) {\n var de = ee;\n this.insertEdgeEnd(de, de);\n };\n DirectedEdgeStar.prototype.getRightmostEdge = function getRightmostEdge () {\n var edges = this.getEdges();\n var size = edges.size();\n if (size < 1) { return null }\n var de0 = edges.get(0);\n if (size === 1) { return de0 }\n var deLast = edges.get(size - 1);\n var quad0 = de0.getQuadrant();\n var quad1 = deLast.getQuadrant();\n if (Quadrant.isNorthern(quad0) && Quadrant.isNorthern(quad1)) { return de0; } else if (!Quadrant.isNorthern(quad0) && !Quadrant.isNorthern(quad1)) { return deLast; } else {\n // const nonHorizontalEdge = null\n if (de0.getDy() !== 0) { return de0; } else if (deLast.getDy() !== 0) { return deLast }\n }\n Assert.shouldNeverReachHere('found two horizontal edges incident on node');\n return null\n };\n DirectedEdgeStar.prototype.print = function print (out) {\n System.out.println('DirectedEdgeStar: ' + this.getCoordinate());\n for (var it = this.iterator(); it.hasNext();) {\n var de = it.next();\n out.print('out ');\n de.print(out);\n out.println();\n out.print('in ');\n de.getSym().print(out);\n out.println();\n }\n };\n DirectedEdgeStar.prototype.getResultAreaEdges = function getResultAreaEdges () {\n var this$1 = this;\n\n if (this._resultAreaEdgeList !== null) { return this._resultAreaEdgeList }\n this._resultAreaEdgeList = new ArrayList();\n for (var it = this.iterator(); it.hasNext();) {\n var de = it.next();\n if (de.isInResult() || de.getSym().isInResult()) { this$1._resultAreaEdgeList.add(de); }\n }\n return this._resultAreaEdgeList\n };\n DirectedEdgeStar.prototype.updateLabelling = function updateLabelling (nodeLabel) {\n for (var it = this.iterator(); it.hasNext();) {\n var de = it.next();\n var label = de.getLabel();\n label.setAllLocationsIfNull(0, nodeLabel.getLocation(0));\n label.setAllLocationsIfNull(1, nodeLabel.getLocation(1));\n }\n };\n DirectedEdgeStar.prototype.linkAllDirectedEdges = function linkAllDirectedEdges () {\n var this$1 = this;\n\n this.getEdges();\n var prevOut = null;\n var firstIn = null;\n for (var i = this._edgeList.size() - 1; i >= 0; i--) {\n var nextOut = this$1._edgeList.get(i);\n var nextIn = nextOut.getSym();\n if (firstIn === null) { firstIn = nextIn; }\n if (prevOut !== null) { nextIn.setNext(prevOut); }\n prevOut = nextOut;\n }\n firstIn.setNext(prevOut);\n };\n DirectedEdgeStar.prototype.computeDepths = function computeDepths () {\n var this$1 = this;\n\n if (arguments.length === 1) {\n var de = arguments[0];\n var edgeIndex = this.findIndex(de);\n // const label = de.getLabel()\n var startDepth = de.getDepth(Position.LEFT);\n var targetLastDepth = de.getDepth(Position.RIGHT);\n var nextDepth = this.computeDepths(edgeIndex + 1, this._edgeList.size(), startDepth);\n var lastDepth = this.computeDepths(0, edgeIndex, nextDepth);\n if (lastDepth !== targetLastDepth) { throw new TopologyException('depth mismatch at ' + de.getCoordinate()) }\n } else if (arguments.length === 3) {\n var startIndex = arguments[0];\n var endIndex = arguments[1];\n var startDepth$1 = arguments[2];\n var currDepth = startDepth$1;\n for (var i = startIndex; i < endIndex; i++) {\n var nextDe = this$1._edgeList.get(i);\n // const label = nextDe.getLabel()\n nextDe.setEdgeDepths(Position.RIGHT, currDepth);\n currDepth = nextDe.getDepth(Position.LEFT);\n }\n return currDepth\n }\n };\n DirectedEdgeStar.prototype.mergeSymLabels = function mergeSymLabels () {\n for (var it = this.iterator(); it.hasNext();) {\n var de = it.next();\n var label = de.getLabel();\n label.merge(de.getSym().getLabel());\n }\n };\n DirectedEdgeStar.prototype.linkMinimalDirectedEdges = function linkMinimalDirectedEdges (er) {\n var this$1 = this;\n\n var firstOut = null;\n var incoming = null;\n var state = this._SCANNING_FOR_INCOMING;\n for (var i = this._resultAreaEdgeList.size() - 1; i >= 0; i--) {\n var nextOut = this$1._resultAreaEdgeList.get(i);\n var nextIn = nextOut.getSym();\n if (firstOut === null && nextOut.getEdgeRing() === er) { firstOut = nextOut; }\n switch (state) {\n case this$1._SCANNING_FOR_INCOMING:\n if (nextIn.getEdgeRing() !== er) { continue }\n incoming = nextIn;\n state = this$1._LINKING_TO_OUTGOING;\n break\n case this$1._LINKING_TO_OUTGOING:\n if (nextOut.getEdgeRing() !== er) { continue }\n incoming.setNextMin(nextOut);\n state = this$1._SCANNING_FOR_INCOMING;\n break\n default:\n }\n }\n if (state === this._LINKING_TO_OUTGOING) {\n Assert.isTrue(firstOut !== null, 'found null for first outgoing dirEdge');\n Assert.isTrue(firstOut.getEdgeRing() === er, 'unable to link last incoming dirEdge');\n incoming.setNextMin(firstOut);\n }\n };\n DirectedEdgeStar.prototype.getOutgoingDegree = function getOutgoingDegree () {\n if (arguments.length === 0) {\n var degree = 0;\n for (var it = this.iterator(); it.hasNext();) {\n var de = it.next();\n if (de.isInResult()) { degree++; }\n }\n return degree\n } else if (arguments.length === 1) {\n var er = arguments[0];\n var degree$1 = 0;\n for (var it$1 = this.iterator(); it$1.hasNext();) {\n var de$1 = it$1.next();\n if (de$1.getEdgeRing() === er) { degree$1++; }\n }\n return degree$1\n }\n };\n DirectedEdgeStar.prototype.getLabel = function getLabel () {\n return this._label\n };\n DirectedEdgeStar.prototype.findCoveredLineEdges = function findCoveredLineEdges () {\n var startLoc = Location.NONE;\n for (var it = this.iterator(); it.hasNext();) {\n var nextOut = it.next();\n var nextIn = nextOut.getSym();\n if (!nextOut.isLineEdge()) {\n if (nextOut.isInResult()) {\n startLoc = Location.INTERIOR;\n break\n }\n if (nextIn.isInResult()) {\n startLoc = Location.EXTERIOR;\n break\n }\n }\n }\n if (startLoc === Location.NONE) { return null }\n var currLoc = startLoc;\n for (var it$1 = this.iterator(); it$1.hasNext();) {\n var nextOut$1 = it$1.next();\n var nextIn$1 = nextOut$1.getSym();\n if (nextOut$1.isLineEdge()) {\n nextOut$1.getEdge().setCovered(currLoc === Location.INTERIOR);\n } else {\n if (nextOut$1.isInResult()) { currLoc = Location.EXTERIOR; }\n if (nextIn$1.isInResult()) { currLoc = Location.INTERIOR; }\n }\n }\n };\n DirectedEdgeStar.prototype.computeLabelling = function computeLabelling (geom) {\n var this$1 = this;\n\n EdgeEndStar$$1.prototype.computeLabelling.call(this, geom);\n this._label = new Label(Location.NONE);\n for (var it = this.iterator(); it.hasNext();) {\n var ee = it.next();\n var e = ee.getEdge();\n var eLabel = e.getLabel();\n for (var i = 0; i < 2; i++) {\n var eLoc = eLabel.getLocation(i);\n if (eLoc === Location.INTERIOR || eLoc === Location.BOUNDARY) { this$1._label.setLocation(i, Location.INTERIOR); }\n }\n }\n };\n DirectedEdgeStar.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n DirectedEdgeStar.prototype.getClass = function getClass () {\n return DirectedEdgeStar\n };\n\n return DirectedEdgeStar;\n}(EdgeEndStar));\n\nvar OverlayNodeFactory = (function (NodeFactory$$1) {\n function OverlayNodeFactory () {\n NodeFactory$$1.apply(this, arguments);\n }\n\n if ( NodeFactory$$1 ) OverlayNodeFactory.__proto__ = NodeFactory$$1;\n OverlayNodeFactory.prototype = Object.create( NodeFactory$$1 && NodeFactory$$1.prototype );\n OverlayNodeFactory.prototype.constructor = OverlayNodeFactory;\n\n OverlayNodeFactory.prototype.createNode = function createNode (coord) {\n return new Node(coord, new DirectedEdgeStar())\n };\n OverlayNodeFactory.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n OverlayNodeFactory.prototype.getClass = function getClass () {\n return OverlayNodeFactory\n };\n\n return OverlayNodeFactory;\n}(NodeFactory));\n\nvar OrientedCoordinateArray = function OrientedCoordinateArray () {\n this._pts = null;\n this._orientation = null;\n var pts = arguments[0];\n this._pts = pts;\n this._orientation = OrientedCoordinateArray.orientation(pts);\n};\nOrientedCoordinateArray.prototype.compareTo = function compareTo (o1) {\n var oca = o1;\n var comp = OrientedCoordinateArray.compareOriented(this._pts, this._orientation, oca._pts, oca._orientation);\n return comp\n};\nOrientedCoordinateArray.prototype.interfaces_ = function interfaces_ () {\n return [Comparable]\n};\nOrientedCoordinateArray.prototype.getClass = function getClass () {\n return OrientedCoordinateArray\n};\nOrientedCoordinateArray.orientation = function orientation (pts) {\n return CoordinateArrays.increasingDirection(pts) === 1\n};\nOrientedCoordinateArray.compareOriented = function compareOriented (pts1, orientation1, pts2, orientation2) {\n var dir1 = orientation1 ? 1 : -1;\n var dir2 = orientation2 ? 1 : -1;\n var limit1 = orientation1 ? pts1.length : -1;\n var limit2 = orientation2 ? pts2.length : -1;\n var i1 = orientation1 ? 0 : pts1.length - 1;\n var i2 = orientation2 ? 0 : pts2.length - 1;\n // const comp = 0\n while (true) {\n var compPt = pts1[i1].compareTo(pts2[i2]);\n if (compPt !== 0) { return compPt }\n i1 += dir1;\n i2 += dir2;\n var done1 = i1 === limit1;\n var done2 = i2 === limit2;\n if (done1 && !done2) { return -1 }\n if (!done1 && done2) { return 1 }\n if (done1 && done2) { return 0 }\n }\n};\n\nvar EdgeList = function EdgeList () {\n this._edges = new ArrayList();\n this._ocaMap = new TreeMap();\n};\nEdgeList.prototype.print = function print (out) {\n var this$1 = this;\n\n out.print('MULTILINESTRING ( ');\n for (var j = 0; j < this._edges.size(); j++) {\n var e = this$1._edges.get(j);\n if (j > 0) { out.print(','); }\n out.print('(');\n var pts = e.getCoordinates();\n for (var i = 0; i < pts.length; i++) {\n if (i > 0) { out.print(','); }\n out.print(pts[i].x + ' ' + pts[i].y);\n }\n out.println(')');\n }\n out.print(') ');\n};\nEdgeList.prototype.addAll = function addAll (edgeColl) {\n var this$1 = this;\n\n for (var i = edgeColl.iterator(); i.hasNext();) {\n this$1.add(i.next());\n }\n};\nEdgeList.prototype.findEdgeIndex = function findEdgeIndex (e) {\n var this$1 = this;\n\n for (var i = 0; i < this._edges.size(); i++) {\n if (this$1._edges.get(i).equals(e)) { return i }\n }\n return -1\n};\nEdgeList.prototype.iterator = function iterator () {\n return this._edges.iterator()\n};\nEdgeList.prototype.getEdges = function getEdges () {\n return this._edges\n};\nEdgeList.prototype.get = function get (i) {\n return this._edges.get(i)\n};\nEdgeList.prototype.findEqualEdge = function findEqualEdge (e) {\n var oca = new OrientedCoordinateArray(e.getCoordinates());\n var matchEdge = this._ocaMap.get(oca);\n return matchEdge\n};\nEdgeList.prototype.add = function add (e) {\n this._edges.add(e);\n var oca = new OrientedCoordinateArray(e.getCoordinates());\n this._ocaMap.put(oca, e);\n};\nEdgeList.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nEdgeList.prototype.getClass = function getClass () {\n return EdgeList\n};\n\nvar SegmentIntersector = function SegmentIntersector () {};\n\nSegmentIntersector.prototype.processIntersections = function processIntersections (e0, segIndex0, e1, segIndex1) {};\nSegmentIntersector.prototype.isDone = function isDone () {};\nSegmentIntersector.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nSegmentIntersector.prototype.getClass = function getClass () {\n return SegmentIntersector\n};\n\nvar IntersectionAdder = function IntersectionAdder () {\n this._hasIntersection = false;\n this._hasProper = false;\n this._hasProperInterior = false;\n this._hasInterior = false;\n this._properIntersectionPoint = null;\n this._li = null;\n this._isSelfIntersection = null;\n this.numIntersections = 0;\n this.numInteriorIntersections = 0;\n this.numProperIntersections = 0;\n this.numTests = 0;\n var li = arguments[0];\n this._li = li;\n};\nIntersectionAdder.prototype.isTrivialIntersection = function isTrivialIntersection (e0, segIndex0, e1, segIndex1) {\n if (e0 === e1) {\n if (this._li.getIntersectionNum() === 1) {\n if (IntersectionAdder.isAdjacentSegments(segIndex0, segIndex1)) { return true }\n if (e0.isClosed()) {\n var maxSegIndex = e0.size() - 1;\n if ((segIndex0 === 0 && segIndex1 === maxSegIndex) ||\n (segIndex1 === 0 && segIndex0 === maxSegIndex)) {\n return true\n }\n }\n }\n }\n return false\n};\nIntersectionAdder.prototype.getProperIntersectionPoint = function getProperIntersectionPoint () {\n return this._properIntersectionPoint\n};\nIntersectionAdder.prototype.hasProperInteriorIntersection = function hasProperInteriorIntersection () {\n return this._hasProperInterior\n};\nIntersectionAdder.prototype.getLineIntersector = function getLineIntersector () {\n return this._li\n};\nIntersectionAdder.prototype.hasProperIntersection = function hasProperIntersection () {\n return this._hasProper\n};\nIntersectionAdder.prototype.processIntersections = function processIntersections (e0, segIndex0, e1, segIndex1) {\n if (e0 === e1 && segIndex0 === segIndex1) { return null }\n this.numTests++;\n var p00 = e0.getCoordinates()[segIndex0];\n var p01 = e0.getCoordinates()[segIndex0 + 1];\n var p10 = e1.getCoordinates()[segIndex1];\n var p11 = e1.getCoordinates()[segIndex1 + 1];\n this._li.computeIntersection(p00, p01, p10, p11);\n if (this._li.hasIntersection()) {\n this.numIntersections++;\n if (this._li.isInteriorIntersection()) {\n this.numInteriorIntersections++;\n this._hasInterior = true;\n }\n if (!this.isTrivialIntersection(e0, segIndex0, e1, segIndex1)) {\n this._hasIntersection = true;\n e0.addIntersections(this._li, segIndex0, 0);\n e1.addIntersections(this._li, segIndex1, 1);\n if (this._li.isProper()) {\n this.numProperIntersections++;\n this._hasProper = true;\n this._hasProperInterior = true;\n }\n }\n }\n};\nIntersectionAdder.prototype.hasIntersection = function hasIntersection () {\n return this._hasIntersection\n};\nIntersectionAdder.prototype.isDone = function isDone () {\n return false\n};\nIntersectionAdder.prototype.hasInteriorIntersection = function hasInteriorIntersection () {\n return this._hasInterior\n};\nIntersectionAdder.prototype.interfaces_ = function interfaces_ () {\n return [SegmentIntersector]\n};\nIntersectionAdder.prototype.getClass = function getClass () {\n return IntersectionAdder\n};\nIntersectionAdder.isAdjacentSegments = function isAdjacentSegments (i1, i2) {\n return Math.abs(i1 - i2) === 1\n};\n\nvar EdgeIntersection = function EdgeIntersection () {\n this.coord = null;\n this.segmentIndex = null;\n this.dist = null;\n var coord = arguments[0];\n var segmentIndex = arguments[1];\n var dist = arguments[2];\n this.coord = new Coordinate(coord);\n this.segmentIndex = segmentIndex;\n this.dist = dist;\n};\nEdgeIntersection.prototype.getSegmentIndex = function getSegmentIndex () {\n return this.segmentIndex\n};\nEdgeIntersection.prototype.getCoordinate = function getCoordinate () {\n return this.coord\n};\nEdgeIntersection.prototype.print = function print (out) {\n out.print(this.coord);\n out.print(' seg # = ' + this.segmentIndex);\n out.println(' dist = ' + this.dist);\n};\nEdgeIntersection.prototype.compareTo = function compareTo (obj) {\n var other = obj;\n return this.compare(other.segmentIndex, other.dist)\n};\nEdgeIntersection.prototype.isEndPoint = function isEndPoint (maxSegmentIndex) {\n if (this.segmentIndex === 0 && this.dist === 0.0) { return true }\n if (this.segmentIndex === maxSegmentIndex) { return true }\n return false\n};\nEdgeIntersection.prototype.toString = function toString () {\n return this.coord + ' seg # = ' + this.segmentIndex + ' dist = ' + this.dist\n};\nEdgeIntersection.prototype.getDistance = function getDistance () {\n return this.dist\n};\nEdgeIntersection.prototype.compare = function compare (segmentIndex, dist) {\n if (this.segmentIndex < segmentIndex) { return -1 }\n if (this.segmentIndex > segmentIndex) { return 1 }\n if (this.dist < dist) { return -1 }\n if (this.dist > dist) { return 1 }\n return 0\n};\nEdgeIntersection.prototype.interfaces_ = function interfaces_ () {\n return [Comparable]\n};\nEdgeIntersection.prototype.getClass = function getClass () {\n return EdgeIntersection\n};\n\nvar EdgeIntersectionList = function EdgeIntersectionList () {\n this._nodeMap = new TreeMap();\n this.edge = null;\n var edge = arguments[0];\n this.edge = edge;\n};\nEdgeIntersectionList.prototype.print = function print (out) {\n out.println('Intersections:');\n for (var it = this.iterator(); it.hasNext();) {\n var ei = it.next();\n ei.print(out);\n }\n};\nEdgeIntersectionList.prototype.iterator = function iterator () {\n return this._nodeMap.values().iterator()\n};\nEdgeIntersectionList.prototype.addSplitEdges = function addSplitEdges (edgeList) {\n var this$1 = this;\n\n this.addEndpoints();\n var it = this.iterator();\n var eiPrev = it.next();\n while (it.hasNext()) {\n var ei = it.next();\n var newEdge = this$1.createSplitEdge(eiPrev, ei);\n edgeList.add(newEdge);\n eiPrev = ei;\n }\n};\nEdgeIntersectionList.prototype.addEndpoints = function addEndpoints () {\n var maxSegIndex = this.edge.pts.length - 1;\n this.add(this.edge.pts[0], 0, 0.0);\n this.add(this.edge.pts[maxSegIndex], maxSegIndex, 0.0);\n};\nEdgeIntersectionList.prototype.createSplitEdge = function createSplitEdge (ei0, ei1) {\n var this$1 = this;\n\n var npts = ei1.segmentIndex - ei0.segmentIndex + 2;\n var lastSegStartPt = this.edge.pts[ei1.segmentIndex];\n var useIntPt1 = ei1.dist > 0.0 || !ei1.coord.equals2D(lastSegStartPt);\n if (!useIntPt1) {\n npts--;\n }\n var pts = new Array(npts).fill(null);\n var ipt = 0;\n pts[ipt++] = new Coordinate(ei0.coord);\n for (var i = ei0.segmentIndex + 1; i <= ei1.segmentIndex; i++) {\n pts[ipt++] = this$1.edge.pts[i];\n }\n if (useIntPt1) { pts[ipt] = ei1.coord; }\n return new Edge(pts, new Label(this.edge._label))\n};\nEdgeIntersectionList.prototype.add = function add (intPt, segmentIndex, dist) {\n var eiNew = new EdgeIntersection(intPt, segmentIndex, dist);\n var ei = this._nodeMap.get(eiNew);\n if (ei !== null) {\n return ei\n }\n this._nodeMap.put(eiNew, eiNew);\n return eiNew\n};\nEdgeIntersectionList.prototype.isIntersection = function isIntersection (pt) {\n for (var it = this.iterator(); it.hasNext();) {\n var ei = it.next();\n if (ei.coord.equals(pt)) { return true }\n }\n return false\n};\nEdgeIntersectionList.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nEdgeIntersectionList.prototype.getClass = function getClass () {\n return EdgeIntersectionList\n};\n\nvar MonotoneChainIndexer = function MonotoneChainIndexer () {};\n\nMonotoneChainIndexer.prototype.getChainStartIndices = function getChainStartIndices (pts) {\n var this$1 = this;\n\n var start = 0;\n var startIndexList = new ArrayList();\n startIndexList.add(new Integer(start));\n do {\n var last = this$1.findChainEnd(pts, start);\n startIndexList.add(new Integer(last));\n start = last;\n } while (start < pts.length - 1)\n var startIndex = MonotoneChainIndexer.toIntArray(startIndexList);\n return startIndex\n};\nMonotoneChainIndexer.prototype.findChainEnd = function findChainEnd (pts, start) {\n var chainQuad = Quadrant.quadrant(pts[start], pts[start + 1]);\n var last = start + 1;\n while (last < pts.length) {\n var quad = Quadrant.quadrant(pts[last - 1], pts[last]);\n if (quad !== chainQuad) { break }\n last++;\n }\n return last - 1\n};\nMonotoneChainIndexer.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nMonotoneChainIndexer.prototype.getClass = function getClass () {\n return MonotoneChainIndexer\n};\nMonotoneChainIndexer.toIntArray = function toIntArray (list) {\n var array = new Array(list.size()).fill(null);\n for (var i = 0; i < array.length; i++) {\n array[i] = list.get(i).intValue();\n }\n return array\n};\n\nvar MonotoneChainEdge = function MonotoneChainEdge () {\n this.e = null;\n this.pts = null;\n this.startIndex = null;\n this.env1 = new Envelope();\n this.env2 = new Envelope();\n var e = arguments[0];\n this.e = e;\n this.pts = e.getCoordinates();\n var mcb = new MonotoneChainIndexer();\n this.startIndex = mcb.getChainStartIndices(this.pts);\n};\nMonotoneChainEdge.prototype.getCoordinates = function getCoordinates () {\n return this.pts\n};\nMonotoneChainEdge.prototype.getMaxX = function getMaxX (chainIndex) {\n var x1 = this.pts[this.startIndex[chainIndex]].x;\n var x2 = this.pts[this.startIndex[chainIndex + 1]].x;\n return x1 > x2 ? x1 : x2\n};\nMonotoneChainEdge.prototype.getMinX = function getMinX (chainIndex) {\n var x1 = this.pts[this.startIndex[chainIndex]].x;\n var x2 = this.pts[this.startIndex[chainIndex + 1]].x;\n return x1 < x2 ? x1 : x2\n};\nMonotoneChainEdge.prototype.computeIntersectsForChain = function computeIntersectsForChain () {\n if (arguments.length === 4) {\n var chainIndex0 = arguments[0];\n var mce = arguments[1];\n var chainIndex1 = arguments[2];\n var si = arguments[3];\n this.computeIntersectsForChain(this.startIndex[chainIndex0], this.startIndex[chainIndex0 + 1], mce, mce.startIndex[chainIndex1], mce.startIndex[chainIndex1 + 1], si);\n } else if (arguments.length === 6) {\n var start0 = arguments[0];\n var end0 = arguments[1];\n var mce$1 = arguments[2];\n var start1 = arguments[3];\n var end1 = arguments[4];\n var ei = arguments[5];\n var p00 = this.pts[start0];\n var p01 = this.pts[end0];\n var p10 = mce$1.pts[start1];\n var p11 = mce$1.pts[end1];\n if (end0 - start0 === 1 && end1 - start1 === 1) {\n ei.addIntersections(this.e, start0, mce$1.e, start1);\n return null\n }\n this.env1.init(p00, p01);\n this.env2.init(p10, p11);\n if (!this.env1.intersects(this.env2)) { return null }\n var mid0 = Math.trunc((start0 + end0) / 2);\n var mid1 = Math.trunc((start1 + end1) / 2);\n if (start0 < mid0) {\n if (start1 < mid1) { this.computeIntersectsForChain(start0, mid0, mce$1, start1, mid1, ei); }\n if (mid1 < end1) { this.computeIntersectsForChain(start0, mid0, mce$1, mid1, end1, ei); }\n }\n if (mid0 < end0) {\n if (start1 < mid1) { this.computeIntersectsForChain(mid0, end0, mce$1, start1, mid1, ei); }\n if (mid1 < end1) { this.computeIntersectsForChain(mid0, end0, mce$1, mid1, end1, ei); }\n }\n }\n};\nMonotoneChainEdge.prototype.getStartIndexes = function getStartIndexes () {\n return this.startIndex\n};\nMonotoneChainEdge.prototype.computeIntersects = function computeIntersects (mce, si) {\n var this$1 = this;\n\n for (var i = 0; i < this.startIndex.length - 1; i++) {\n for (var j = 0; j < mce.startIndex.length - 1; j++) {\n this$1.computeIntersectsForChain(i, mce, j, si);\n }\n }\n};\nMonotoneChainEdge.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nMonotoneChainEdge.prototype.getClass = function getClass () {\n return MonotoneChainEdge\n};\n\nvar Depth = function Depth () {\n var this$1 = this;\n\n this._depth = Array(2).fill().map(function () { return Array(3); });\n for (var i = 0; i < 2; i++) {\n for (var j = 0; j < 3; j++) {\n this$1._depth[i][j] = Depth.NULL_VALUE;\n }\n }\n};\n\nvar staticAccessors$31 = { NULL_VALUE: { configurable: true } };\nDepth.prototype.getDepth = function getDepth (geomIndex, posIndex) {\n return this._depth[geomIndex][posIndex]\n};\nDepth.prototype.setDepth = function setDepth (geomIndex, posIndex, depthValue) {\n this._depth[geomIndex][posIndex] = depthValue;\n};\nDepth.prototype.isNull = function isNull () {\n var this$1 = this;\n\n if (arguments.length === 0) {\n for (var i = 0; i < 2; i++) {\n for (var j = 0; j < 3; j++) {\n if (this$1._depth[i][j] !== Depth.NULL_VALUE) { return false }\n }\n }\n return true\n } else if (arguments.length === 1) {\n var geomIndex = arguments[0];\n return this._depth[geomIndex][1] === Depth.NULL_VALUE\n } else if (arguments.length === 2) {\n var geomIndex$1 = arguments[0];\n var posIndex = arguments[1];\n return this._depth[geomIndex$1][posIndex] === Depth.NULL_VALUE\n }\n};\nDepth.prototype.normalize = function normalize () {\n var this$1 = this;\n\n for (var i = 0; i < 2; i++) {\n if (!this$1.isNull(i)) {\n var minDepth = this$1._depth[i][1];\n if (this$1._depth[i][2] < minDepth) { minDepth = this$1._depth[i][2]; }\n if (minDepth < 0) { minDepth = 0; }\n for (var j = 1; j < 3; j++) {\n var newValue = 0;\n if (this$1._depth[i][j] > minDepth) { newValue = 1; }\n this$1._depth[i][j] = newValue;\n }\n }\n }\n};\nDepth.prototype.getDelta = function getDelta (geomIndex) {\n return this._depth[geomIndex][Position.RIGHT] - this._depth[geomIndex][Position.LEFT]\n};\nDepth.prototype.getLocation = function getLocation (geomIndex, posIndex) {\n if (this._depth[geomIndex][posIndex] <= 0) { return Location.EXTERIOR }\n return Location.INTERIOR\n};\nDepth.prototype.toString = function toString () {\n return 'A: ' + this._depth[0][1] + ',' + this._depth[0][2] + ' B: ' + this._depth[1][1] + ',' + this._depth[1][2]\n};\nDepth.prototype.add = function add () {\n var this$1 = this;\n\n if (arguments.length === 1) {\n var lbl = arguments[0];\n for (var i = 0; i < 2; i++) {\n for (var j = 1; j < 3; j++) {\n var loc = lbl.getLocation(i, j);\n if (loc === Location.EXTERIOR || loc === Location.INTERIOR) {\n if (this$1.isNull(i, j)) {\n this$1._depth[i][j] = Depth.depthAtLocation(loc);\n } else { this$1._depth[i][j] += Depth.depthAtLocation(loc); }\n }\n }\n }\n } else if (arguments.length === 3) {\n var geomIndex = arguments[0];\n var posIndex = arguments[1];\n var location = arguments[2];\n if (location === Location.INTERIOR) { this._depth[geomIndex][posIndex]++; }\n }\n};\nDepth.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nDepth.prototype.getClass = function getClass () {\n return Depth\n};\nDepth.depthAtLocation = function depthAtLocation (location) {\n if (location === Location.EXTERIOR) { return 0 }\n if (location === Location.INTERIOR) { return 1 }\n return Depth.NULL_VALUE\n};\nstaticAccessors$31.NULL_VALUE.get = function () { return -1 };\n\nObject.defineProperties( Depth, staticAccessors$31 );\n\nvar Edge = (function (GraphComponent$$1) {\n function Edge () {\n GraphComponent$$1.call(this);\n this.pts = null;\n this._env = null;\n this.eiList = new EdgeIntersectionList(this);\n this._name = null;\n this._mce = null;\n this._isIsolated = true;\n this._depth = new Depth();\n this._depthDelta = 0;\n if (arguments.length === 1) {\n var pts = arguments[0];\n Edge.call(this, pts, null);\n } else if (arguments.length === 2) {\n var pts$1 = arguments[0];\n var label = arguments[1];\n this.pts = pts$1;\n this._label = label;\n }\n }\n\n if ( GraphComponent$$1 ) Edge.__proto__ = GraphComponent$$1;\n Edge.prototype = Object.create( GraphComponent$$1 && GraphComponent$$1.prototype );\n Edge.prototype.constructor = Edge;\n Edge.prototype.getDepth = function getDepth () {\n return this._depth\n };\n Edge.prototype.getCollapsedEdge = function getCollapsedEdge () {\n var newPts = new Array(2).fill(null);\n newPts[0] = this.pts[0];\n newPts[1] = this.pts[1];\n var newe = new Edge(newPts, Label.toLineLabel(this._label));\n return newe\n };\n Edge.prototype.isIsolated = function isIsolated () {\n return this._isIsolated\n };\n Edge.prototype.getCoordinates = function getCoordinates () {\n return this.pts\n };\n Edge.prototype.setIsolated = function setIsolated (isIsolated) {\n this._isIsolated = isIsolated;\n };\n Edge.prototype.setName = function setName (name) {\n this._name = name;\n };\n Edge.prototype.equals = function equals (o) {\n var this$1 = this;\n\n if (!(o instanceof Edge)) { return false }\n var e = o;\n if (this.pts.length !== e.pts.length) { return false }\n var isEqualForward = true;\n var isEqualReverse = true;\n var iRev = this.pts.length;\n for (var i = 0; i < this.pts.length; i++) {\n if (!this$1.pts[i].equals2D(e.pts[i])) {\n isEqualForward = false;\n }\n if (!this$1.pts[i].equals2D(e.pts[--iRev])) {\n isEqualReverse = false;\n }\n if (!isEqualForward && !isEqualReverse) { return false }\n }\n return true\n };\n Edge.prototype.getCoordinate = function getCoordinate () {\n if (arguments.length === 0) {\n if (this.pts.length > 0) { return this.pts[0] }\n return null\n } else if (arguments.length === 1) {\n var i = arguments[0];\n return this.pts[i]\n }\n };\n Edge.prototype.print = function print (out) {\n var this$1 = this;\n\n out.print('edge ' + this._name + ': ');\n out.print('LINESTRING (');\n for (var i = 0; i < this.pts.length; i++) {\n if (i > 0) { out.print(','); }\n out.print(this$1.pts[i].x + ' ' + this$1.pts[i].y);\n }\n out.print(') ' + this._label + ' ' + this._depthDelta);\n };\n Edge.prototype.computeIM = function computeIM (im) {\n Edge.updateIM(this._label, im);\n };\n Edge.prototype.isCollapsed = function isCollapsed () {\n if (!this._label.isArea()) { return false }\n if (this.pts.length !== 3) { return false }\n if (this.pts[0].equals(this.pts[2])) { return true }\n return false\n };\n Edge.prototype.isClosed = function isClosed () {\n return this.pts[0].equals(this.pts[this.pts.length - 1])\n };\n Edge.prototype.getMaximumSegmentIndex = function getMaximumSegmentIndex () {\n return this.pts.length - 1\n };\n Edge.prototype.getDepthDelta = function getDepthDelta () {\n return this._depthDelta\n };\n Edge.prototype.getNumPoints = function getNumPoints () {\n return this.pts.length\n };\n Edge.prototype.printReverse = function printReverse (out) {\n var this$1 = this;\n\n out.print('edge ' + this._name + ': ');\n for (var i = this.pts.length - 1; i >= 0; i--) {\n out.print(this$1.pts[i] + ' ');\n }\n out.println('');\n };\n Edge.prototype.getMonotoneChainEdge = function getMonotoneChainEdge () {\n if (this._mce === null) { this._mce = new MonotoneChainEdge(this); }\n return this._mce\n };\n Edge.prototype.getEnvelope = function getEnvelope () {\n var this$1 = this;\n\n if (this._env === null) {\n this._env = new Envelope();\n for (var i = 0; i < this.pts.length; i++) {\n this$1._env.expandToInclude(this$1.pts[i]);\n }\n }\n return this._env\n };\n Edge.prototype.addIntersection = function addIntersection (li, segmentIndex, geomIndex, intIndex) {\n var intPt = new Coordinate(li.getIntersection(intIndex));\n var normalizedSegmentIndex = segmentIndex;\n var dist = li.getEdgeDistance(geomIndex, intIndex);\n var nextSegIndex = normalizedSegmentIndex + 1;\n if (nextSegIndex < this.pts.length) {\n var nextPt = this.pts[nextSegIndex];\n if (intPt.equals2D(nextPt)) {\n normalizedSegmentIndex = nextSegIndex;\n dist = 0.0;\n }\n }\n this.eiList.add(intPt, normalizedSegmentIndex, dist);\n };\n Edge.prototype.toString = function toString () {\n var this$1 = this;\n\n var buf = new StringBuffer();\n buf.append('edge ' + this._name + ': ');\n buf.append('LINESTRING (');\n for (var i = 0; i < this.pts.length; i++) {\n if (i > 0) { buf.append(','); }\n buf.append(this$1.pts[i].x + ' ' + this$1.pts[i].y);\n }\n buf.append(') ' + this._label + ' ' + this._depthDelta);\n return buf.toString()\n };\n Edge.prototype.isPointwiseEqual = function isPointwiseEqual (e) {\n var this$1 = this;\n\n if (this.pts.length !== e.pts.length) { return false }\n for (var i = 0; i < this.pts.length; i++) {\n if (!this$1.pts[i].equals2D(e.pts[i])) {\n return false\n }\n }\n return true\n };\n Edge.prototype.setDepthDelta = function setDepthDelta (depthDelta) {\n this._depthDelta = depthDelta;\n };\n Edge.prototype.getEdgeIntersectionList = function getEdgeIntersectionList () {\n return this.eiList\n };\n Edge.prototype.addIntersections = function addIntersections (li, segmentIndex, geomIndex) {\n var this$1 = this;\n\n for (var i = 0; i < li.getIntersectionNum(); i++) {\n this$1.addIntersection(li, segmentIndex, geomIndex, i);\n }\n };\n Edge.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n Edge.prototype.getClass = function getClass () {\n return Edge\n };\n Edge.updateIM = function updateIM () {\n if (arguments.length === 2) {\n var label = arguments[0];\n var im = arguments[1];\n im.setAtLeastIfValid(label.getLocation(0, Position.ON), label.getLocation(1, Position.ON), 1);\n if (label.isArea()) {\n im.setAtLeastIfValid(label.getLocation(0, Position.LEFT), label.getLocation(1, Position.LEFT), 2);\n im.setAtLeastIfValid(label.getLocation(0, Position.RIGHT), label.getLocation(1, Position.RIGHT), 2);\n }\n } else { return GraphComponent$$1.prototype.updateIM.apply(this, arguments) }\n };\n\n return Edge;\n}(GraphComponent));\n\nvar BufferBuilder = function BufferBuilder (bufParams) {\n this._workingPrecisionModel = null;\n this._workingNoder = null;\n this._geomFact = null;\n this._graph = null;\n this._edgeList = new EdgeList();\n this._bufParams = bufParams || null;\n};\nBufferBuilder.prototype.setWorkingPrecisionModel = function setWorkingPrecisionModel (pm) {\n this._workingPrecisionModel = pm;\n};\nBufferBuilder.prototype.insertUniqueEdge = function insertUniqueEdge (e) {\n var existingEdge = this._edgeList.findEqualEdge(e);\n if (existingEdge !== null) {\n var existingLabel = existingEdge.getLabel();\n var labelToMerge = e.getLabel();\n if (!existingEdge.isPointwiseEqual(e)) {\n labelToMerge = new Label(e.getLabel());\n labelToMerge.flip();\n }\n existingLabel.merge(labelToMerge);\n var mergeDelta = BufferBuilder.depthDelta(labelToMerge);\n var existingDelta = existingEdge.getDepthDelta();\n var newDelta = existingDelta + mergeDelta;\n existingEdge.setDepthDelta(newDelta);\n } else {\n this._edgeList.add(e);\n e.setDepthDelta(BufferBuilder.depthDelta(e.getLabel()));\n }\n};\nBufferBuilder.prototype.buildSubgraphs = function buildSubgraphs (subgraphList, polyBuilder) {\n var processedGraphs = new ArrayList();\n for (var i = subgraphList.iterator(); i.hasNext();) {\n var subgraph = i.next();\n var p = subgraph.getRightmostCoordinate();\n var locater = new SubgraphDepthLocater(processedGraphs);\n var outsideDepth = locater.getDepth(p);\n subgraph.computeDepth(outsideDepth);\n subgraph.findResultEdges();\n processedGraphs.add(subgraph);\n polyBuilder.add(subgraph.getDirectedEdges(), subgraph.getNodes());\n }\n};\nBufferBuilder.prototype.createSubgraphs = function createSubgraphs (graph) {\n var subgraphList = new ArrayList();\n for (var i = graph.getNodes().iterator(); i.hasNext();) {\n var node = i.next();\n if (!node.isVisited()) {\n var subgraph = new BufferSubgraph();\n subgraph.create(node);\n subgraphList.add(subgraph);\n }\n }\n Collections.sort(subgraphList, Collections.reverseOrder());\n return subgraphList\n};\nBufferBuilder.prototype.createEmptyResultGeometry = function createEmptyResultGeometry () {\n var emptyGeom = this._geomFact.createPolygon();\n return emptyGeom\n};\nBufferBuilder.prototype.getNoder = function getNoder (precisionModel) {\n if (this._workingNoder !== null) { return this._workingNoder }\n var noder = new MCIndexNoder();\n var li = new RobustLineIntersector();\n li.setPrecisionModel(precisionModel);\n noder.setSegmentIntersector(new IntersectionAdder(li));\n return noder\n};\nBufferBuilder.prototype.buffer = function buffer (g, distance) {\n var precisionModel = this._workingPrecisionModel;\n if (precisionModel === null) { precisionModel = g.getPrecisionModel(); }\n this._geomFact = g.getFactory();\n var curveBuilder = new OffsetCurveBuilder(precisionModel, this._bufParams);\n var curveSetBuilder = new OffsetCurveSetBuilder(g, distance, curveBuilder);\n var bufferSegStrList = curveSetBuilder.getCurves();\n if (bufferSegStrList.size() <= 0) {\n return this.createEmptyResultGeometry()\n }\n this.computeNodedEdges(bufferSegStrList, precisionModel);\n this._graph = new PlanarGraph(new OverlayNodeFactory());\n this._graph.addEdges(this._edgeList.getEdges());\n var subgraphList = this.createSubgraphs(this._graph);\n var polyBuilder = new PolygonBuilder(this._geomFact);\n this.buildSubgraphs(subgraphList, polyBuilder);\n var resultPolyList = polyBuilder.getPolygons();\n if (resultPolyList.size() <= 0) {\n return this.createEmptyResultGeometry()\n }\n var resultGeom = this._geomFact.buildGeometry(resultPolyList);\n return resultGeom\n};\nBufferBuilder.prototype.computeNodedEdges = function computeNodedEdges (bufferSegStrList, precisionModel) {\n var this$1 = this;\n\n var noder = this.getNoder(precisionModel);\n noder.computeNodes(bufferSegStrList);\n var nodedSegStrings = noder.getNodedSubstrings();\n for (var i = nodedSegStrings.iterator(); i.hasNext();) {\n var segStr = i.next();\n var pts = segStr.getCoordinates();\n if (pts.length === 2 && pts[0].equals2D(pts[1])) { continue }\n var oldLabel = segStr.getData();\n var edge = new Edge(segStr.getCoordinates(), new Label(oldLabel));\n this$1.insertUniqueEdge(edge);\n }\n};\nBufferBuilder.prototype.setNoder = function setNoder (noder) {\n this._workingNoder = noder;\n};\nBufferBuilder.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nBufferBuilder.prototype.getClass = function getClass () {\n return BufferBuilder\n};\nBufferBuilder.depthDelta = function depthDelta (label) {\n var lLoc = label.getLocation(0, Position.LEFT);\n var rLoc = label.getLocation(0, Position.RIGHT);\n if (lLoc === Location.INTERIOR && rLoc === Location.EXTERIOR) { return 1; } else if (lLoc === Location.EXTERIOR && rLoc === Location.INTERIOR) { return -1 }\n return 0\n};\nBufferBuilder.convertSegStrings = function convertSegStrings (it) {\n var fact = new GeometryFactory();\n var lines = new ArrayList();\n while (it.hasNext()) {\n var ss = it.next();\n var line = fact.createLineString(ss.getCoordinates());\n lines.add(line);\n }\n return fact.buildGeometry(lines)\n};\n\nvar ScaledNoder = function ScaledNoder () {\n this._noder = null;\n this._scaleFactor = null;\n this._offsetX = null;\n this._offsetY = null;\n this._isScaled = false;\n if (arguments.length === 2) {\n var noder = arguments[0];\n var scaleFactor = arguments[1];\n this._noder = noder;\n this._scaleFactor = scaleFactor;\n this._offsetX = 0.0;\n this._offsetY = 0.0;\n this._isScaled = !this.isIntegerPrecision();\n } else if (arguments.length === 4) {\n var noder$1 = arguments[0];\n var scaleFactor$1 = arguments[1];\n var offsetX = arguments[2];\n var offsetY = arguments[3];\n this._noder = noder$1;\n this._scaleFactor = scaleFactor$1;\n this._offsetX = offsetX;\n this._offsetY = offsetY;\n this._isScaled = !this.isIntegerPrecision();\n }\n};\nScaledNoder.prototype.rescale = function rescale () {\n var this$1 = this;\n\n if (hasInterface(arguments[0], Collection)) {\n var segStrings = arguments[0];\n for (var i = segStrings.iterator(); i.hasNext();) {\n var ss = i.next();\n this$1.rescale(ss.getCoordinates());\n }\n } else if (arguments[0] instanceof Array) {\n var pts = arguments[0];\n // let p0 = null\n // let p1 = null\n // if (pts.length === 2) {\n // p0 = new Coordinate(pts[0])\n // p1 = new Coordinate(pts[1])\n // }\n for (var i$1 = 0; i$1 < pts.length; i$1++) {\n pts[i$1].x = pts[i$1].x / this$1._scaleFactor + this$1._offsetX;\n pts[i$1].y = pts[i$1].y / this$1._scaleFactor + this$1._offsetY;\n }\n if (pts.length === 2 && pts[0].equals2D(pts[1])) {\n System.out.println(pts);\n }\n }\n};\nScaledNoder.prototype.scale = function scale () {\n var this$1 = this;\n\n if (hasInterface(arguments[0], Collection)) {\n var segStrings = arguments[0];\n var nodedSegmentStrings = new ArrayList();\n for (var i = segStrings.iterator(); i.hasNext();) {\n var ss = i.next();\n nodedSegmentStrings.add(new NodedSegmentString(this$1.scale(ss.getCoordinates()), ss.getData()));\n }\n return nodedSegmentStrings\n } else if (arguments[0] instanceof Array) {\n var pts = arguments[0];\n var roundPts = new Array(pts.length).fill(null);\n for (var i$1 = 0; i$1 < pts.length; i$1++) {\n roundPts[i$1] = new Coordinate(Math.round((pts[i$1].x - this$1._offsetX) * this$1._scaleFactor), Math.round((pts[i$1].y - this$1._offsetY) * this$1._scaleFactor), pts[i$1].z);\n }\n var roundPtsNoDup = CoordinateArrays.removeRepeatedPoints(roundPts);\n return roundPtsNoDup\n }\n};\nScaledNoder.prototype.isIntegerPrecision = function isIntegerPrecision () {\n return this._scaleFactor === 1.0\n};\nScaledNoder.prototype.getNodedSubstrings = function getNodedSubstrings () {\n var splitSS = this._noder.getNodedSubstrings();\n if (this._isScaled) { this.rescale(splitSS); }\n return splitSS\n};\nScaledNoder.prototype.computeNodes = function computeNodes (inputSegStrings) {\n var intSegStrings = inputSegStrings;\n if (this._isScaled) { intSegStrings = this.scale(inputSegStrings); }\n this._noder.computeNodes(intSegStrings);\n};\nScaledNoder.prototype.interfaces_ = function interfaces_ () {\n return [Noder]\n};\nScaledNoder.prototype.getClass = function getClass () {\n return ScaledNoder\n};\n\nvar NodingValidator = function NodingValidator () {\n this._li = new RobustLineIntersector();\n this._segStrings = null;\n var segStrings = arguments[0];\n this._segStrings = segStrings;\n};\n\nvar staticAccessors$33 = { fact: { configurable: true } };\nNodingValidator.prototype.checkEndPtVertexIntersections = function checkEndPtVertexIntersections () {\n var this$1 = this;\n\n if (arguments.length === 0) {\n for (var i = this._segStrings.iterator(); i.hasNext();) {\n var ss = i.next();\n var pts = ss.getCoordinates();\n this$1.checkEndPtVertexIntersections(pts[0], this$1._segStrings);\n this$1.checkEndPtVertexIntersections(pts[pts.length - 1], this$1._segStrings);\n }\n } else if (arguments.length === 2) {\n var testPt = arguments[0];\n var segStrings = arguments[1];\n for (var i$1 = segStrings.iterator(); i$1.hasNext();) {\n var ss$1 = i$1.next();\n var pts$1 = ss$1.getCoordinates();\n for (var j = 1; j < pts$1.length - 1; j++) {\n if (pts$1[j].equals(testPt)) { throw new RuntimeException('found endpt/interior pt intersection at index ' + j + ' :pt ' + testPt) }\n }\n }\n }\n};\nNodingValidator.prototype.checkInteriorIntersections = function checkInteriorIntersections () {\n var this$1 = this;\n\n if (arguments.length === 0) {\n for (var i = this._segStrings.iterator(); i.hasNext();) {\n var ss0 = i.next();\n for (var j = this._segStrings.iterator(); j.hasNext();) {\n var ss1 = j.next();\n this$1.checkInteriorIntersections(ss0, ss1);\n }\n }\n } else if (arguments.length === 2) {\n var ss0$1 = arguments[0];\n var ss1$1 = arguments[1];\n var pts0 = ss0$1.getCoordinates();\n var pts1 = ss1$1.getCoordinates();\n for (var i0 = 0; i0 < pts0.length - 1; i0++) {\n for (var i1 = 0; i1 < pts1.length - 1; i1++) {\n this$1.checkInteriorIntersections(ss0$1, i0, ss1$1, i1);\n }\n }\n } else if (arguments.length === 4) {\n var e0 = arguments[0];\n var segIndex0 = arguments[1];\n var e1 = arguments[2];\n var segIndex1 = arguments[3];\n if (e0 === e1 && segIndex0 === segIndex1) { return null }\n var p00 = e0.getCoordinates()[segIndex0];\n var p01 = e0.getCoordinates()[segIndex0 + 1];\n var p10 = e1.getCoordinates()[segIndex1];\n var p11 = e1.getCoordinates()[segIndex1 + 1];\n this._li.computeIntersection(p00, p01, p10, p11);\n if (this._li.hasIntersection()) {\n if (this._li.isProper() || this.hasInteriorIntersection(this._li, p00, p01) || this.hasInteriorIntersection(this._li, p10, p11)) {\n throw new RuntimeException('found non-noded intersection at ' + p00 + '-' + p01 + ' and ' + p10 + '-' + p11)\n }\n }\n }\n};\nNodingValidator.prototype.checkValid = function checkValid () {\n this.checkEndPtVertexIntersections();\n this.checkInteriorIntersections();\n this.checkCollapses();\n};\nNodingValidator.prototype.checkCollapses = function checkCollapses () {\n var this$1 = this;\n\n if (arguments.length === 0) {\n for (var i = this._segStrings.iterator(); i.hasNext();) {\n var ss = i.next();\n this$1.checkCollapses(ss);\n }\n } else if (arguments.length === 1) {\n var ss$1 = arguments[0];\n var pts = ss$1.getCoordinates();\n for (var i$1 = 0; i$1 < pts.length - 2; i$1++) {\n this$1.checkCollapse(pts[i$1], pts[i$1 + 1], pts[i$1 + 2]);\n }\n }\n};\nNodingValidator.prototype.hasInteriorIntersection = function hasInteriorIntersection (li, p0, p1) {\n for (var i = 0; i < li.getIntersectionNum(); i++) {\n var intPt = li.getIntersection(i);\n if (!(intPt.equals(p0) || intPt.equals(p1))) { return true }\n }\n return false\n};\nNodingValidator.prototype.checkCollapse = function checkCollapse (p0, p1, p2) {\n if (p0.equals(p2)) { throw new RuntimeException('found non-noded collapse at ' + NodingValidator.fact.createLineString([p0, p1, p2])) }\n};\nNodingValidator.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nNodingValidator.prototype.getClass = function getClass () {\n return NodingValidator\n};\nstaticAccessors$33.fact.get = function () { return new GeometryFactory() };\n\nObject.defineProperties( NodingValidator, staticAccessors$33 );\n\nvar HotPixel = function HotPixel () {\n this._li = null;\n this._pt = null;\n this._originalPt = null;\n this._ptScaled = null;\n this._p0Scaled = null;\n this._p1Scaled = null;\n this._scaleFactor = null;\n this._minx = null;\n this._maxx = null;\n this._miny = null;\n this._maxy = null;\n this._corner = new Array(4).fill(null);\n this._safeEnv = null;\n var pt = arguments[0];\n var scaleFactor = arguments[1];\n var li = arguments[2];\n this._originalPt = pt;\n this._pt = pt;\n this._scaleFactor = scaleFactor;\n this._li = li;\n if (scaleFactor <= 0) { throw new IllegalArgumentException('Scale factor must be non-zero') }\n if (scaleFactor !== 1.0) {\n this._pt = new Coordinate(this.scale(pt.x), this.scale(pt.y));\n this._p0Scaled = new Coordinate();\n this._p1Scaled = new Coordinate();\n }\n this.initCorners(this._pt);\n};\n\nvar staticAccessors$34 = { SAFE_ENV_EXPANSION_FACTOR: { configurable: true } };\nHotPixel.prototype.intersectsScaled = function intersectsScaled (p0, p1) {\n var segMinx = Math.min(p0.x, p1.x);\n var segMaxx = Math.max(p0.x, p1.x);\n var segMiny = Math.min(p0.y, p1.y);\n var segMaxy = Math.max(p0.y, p1.y);\n var isOutsidePixelEnv = this._maxx < segMinx || this._minx > segMaxx || this._maxy < segMiny || this._miny > segMaxy;\n if (isOutsidePixelEnv) { return false }\n var intersects = this.intersectsToleranceSquare(p0, p1);\n Assert.isTrue(!(isOutsidePixelEnv && intersects), 'Found bad envelope test');\n return intersects\n};\nHotPixel.prototype.initCorners = function initCorners (pt) {\n var tolerance = 0.5;\n this._minx = pt.x - tolerance;\n this._maxx = pt.x + tolerance;\n this._miny = pt.y - tolerance;\n this._maxy = pt.y + tolerance;\n this._corner[0] = new Coordinate(this._maxx, this._maxy);\n this._corner[1] = new Coordinate(this._minx, this._maxy);\n this._corner[2] = new Coordinate(this._minx, this._miny);\n this._corner[3] = new Coordinate(this._maxx, this._miny);\n};\nHotPixel.prototype.intersects = function intersects (p0, p1) {\n if (this._scaleFactor === 1.0) { return this.intersectsScaled(p0, p1) }\n this.copyScaled(p0, this._p0Scaled);\n this.copyScaled(p1, this._p1Scaled);\n return this.intersectsScaled(this._p0Scaled, this._p1Scaled)\n};\nHotPixel.prototype.scale = function scale (val) {\n return Math.round(val * this._scaleFactor)\n};\nHotPixel.prototype.getCoordinate = function getCoordinate () {\n return this._originalPt\n};\nHotPixel.prototype.copyScaled = function copyScaled (p, pScaled) {\n pScaled.x = this.scale(p.x);\n pScaled.y = this.scale(p.y);\n};\nHotPixel.prototype.getSafeEnvelope = function getSafeEnvelope () {\n if (this._safeEnv === null) {\n var safeTolerance = HotPixel.SAFE_ENV_EXPANSION_FACTOR / this._scaleFactor;\n this._safeEnv = new Envelope(this._originalPt.x - safeTolerance, this._originalPt.x + safeTolerance, this._originalPt.y - safeTolerance, this._originalPt.y + safeTolerance);\n }\n return this._safeEnv\n};\nHotPixel.prototype.intersectsPixelClosure = function intersectsPixelClosure (p0, p1) {\n this._li.computeIntersection(p0, p1, this._corner[0], this._corner[1]);\n if (this._li.hasIntersection()) { return true }\n this._li.computeIntersection(p0, p1, this._corner[1], this._corner[2]);\n if (this._li.hasIntersection()) { return true }\n this._li.computeIntersection(p0, p1, this._corner[2], this._corner[3]);\n if (this._li.hasIntersection()) { return true }\n this._li.computeIntersection(p0, p1, this._corner[3], this._corner[0]);\n if (this._li.hasIntersection()) { return true }\n return false\n};\nHotPixel.prototype.intersectsToleranceSquare = function intersectsToleranceSquare (p0, p1) {\n var intersectsLeft = false;\n var intersectsBottom = false;\n this._li.computeIntersection(p0, p1, this._corner[0], this._corner[1]);\n if (this._li.isProper()) { return true }\n this._li.computeIntersection(p0, p1, this._corner[1], this._corner[2]);\n if (this._li.isProper()) { return true }\n if (this._li.hasIntersection()) { intersectsLeft = true; }\n this._li.computeIntersection(p0, p1, this._corner[2], this._corner[3]);\n if (this._li.isProper()) { return true }\n if (this._li.hasIntersection()) { intersectsBottom = true; }\n this._li.computeIntersection(p0, p1, this._corner[3], this._corner[0]);\n if (this._li.isProper()) { return true }\n if (intersectsLeft && intersectsBottom) { return true }\n if (p0.equals(this._pt)) { return true }\n if (p1.equals(this._pt)) { return true }\n return false\n};\nHotPixel.prototype.addSnappedNode = function addSnappedNode (segStr, segIndex) {\n var p0 = segStr.getCoordinate(segIndex);\n var p1 = segStr.getCoordinate(segIndex + 1);\n if (this.intersects(p0, p1)) {\n segStr.addIntersection(this.getCoordinate(), segIndex);\n return true\n }\n return false\n};\nHotPixel.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nHotPixel.prototype.getClass = function getClass () {\n return HotPixel\n};\nstaticAccessors$34.SAFE_ENV_EXPANSION_FACTOR.get = function () { return 0.75 };\n\nObject.defineProperties( HotPixel, staticAccessors$34 );\n\nvar MonotoneChainSelectAction = function MonotoneChainSelectAction () {\n this.tempEnv1 = new Envelope();\n this.selectedSegment = new LineSegment();\n};\nMonotoneChainSelectAction.prototype.select = function select () {\n if (arguments.length === 1) {\n // const seg = arguments[0]\n } else if (arguments.length === 2) {\n var mc = arguments[0];\n var startIndex = arguments[1];\n mc.getLineSegment(startIndex, this.selectedSegment);\n this.select(this.selectedSegment);\n }\n};\nMonotoneChainSelectAction.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nMonotoneChainSelectAction.prototype.getClass = function getClass () {\n return MonotoneChainSelectAction\n};\n\nvar MCIndexPointSnapper = function MCIndexPointSnapper () {\n this._index = null;\n var index = arguments[0];\n this._index = index;\n};\n\nvar staticAccessors$35 = { HotPixelSnapAction: { configurable: true } };\nMCIndexPointSnapper.prototype.snap = function snap () {\n if (arguments.length === 1) {\n var hotPixel = arguments[0];\n return this.snap(hotPixel, null, -1)\n } else if (arguments.length === 3) {\n var hotPixel$1 = arguments[0];\n var parentEdge = arguments[1];\n var hotPixelVertexIndex = arguments[2];\n var pixelEnv = hotPixel$1.getSafeEnvelope();\n var hotPixelSnapAction = new HotPixelSnapAction(hotPixel$1, parentEdge, hotPixelVertexIndex);\n this._index.query(pixelEnv, {\n interfaces_: function () {\n return [ItemVisitor]\n },\n visitItem: function (item) {\n var testChain = item;\n testChain.select(pixelEnv, hotPixelSnapAction);\n }\n });\n return hotPixelSnapAction.isNodeAdded()\n }\n};\nMCIndexPointSnapper.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nMCIndexPointSnapper.prototype.getClass = function getClass () {\n return MCIndexPointSnapper\n};\nstaticAccessors$35.HotPixelSnapAction.get = function () { return HotPixelSnapAction };\n\nObject.defineProperties( MCIndexPointSnapper, staticAccessors$35 );\n\nvar HotPixelSnapAction = (function (MonotoneChainSelectAction$$1) {\n function HotPixelSnapAction () {\n MonotoneChainSelectAction$$1.call(this);\n this._hotPixel = null;\n this._parentEdge = null;\n this._hotPixelVertexIndex = null;\n this._isNodeAdded = false;\n var hotPixel = arguments[0];\n var parentEdge = arguments[1];\n var hotPixelVertexIndex = arguments[2];\n this._hotPixel = hotPixel;\n this._parentEdge = parentEdge;\n this._hotPixelVertexIndex = hotPixelVertexIndex;\n }\n\n if ( MonotoneChainSelectAction$$1 ) HotPixelSnapAction.__proto__ = MonotoneChainSelectAction$$1;\n HotPixelSnapAction.prototype = Object.create( MonotoneChainSelectAction$$1 && MonotoneChainSelectAction$$1.prototype );\n HotPixelSnapAction.prototype.constructor = HotPixelSnapAction;\n HotPixelSnapAction.prototype.isNodeAdded = function isNodeAdded () {\n return this._isNodeAdded\n };\n HotPixelSnapAction.prototype.select = function select () {\n if (arguments.length === 2) {\n var mc = arguments[0];\n var startIndex = arguments[1];\n var ss = mc.getContext();\n if (this._parentEdge !== null) {\n if (ss === this._parentEdge && startIndex === this._hotPixelVertexIndex) { return null }\n }\n this._isNodeAdded = this._hotPixel.addSnappedNode(ss, startIndex);\n } else { return MonotoneChainSelectAction$$1.prototype.select.apply(this, arguments) }\n };\n HotPixelSnapAction.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n HotPixelSnapAction.prototype.getClass = function getClass () {\n return HotPixelSnapAction\n };\n\n return HotPixelSnapAction;\n}(MonotoneChainSelectAction));\n\nvar InteriorIntersectionFinderAdder = function InteriorIntersectionFinderAdder () {\n this._li = null;\n this._interiorIntersections = null;\n var li = arguments[0];\n this._li = li;\n this._interiorIntersections = new ArrayList();\n};\nInteriorIntersectionFinderAdder.prototype.processIntersections = function processIntersections (e0, segIndex0, e1, segIndex1) {\n var this$1 = this;\n\n if (e0 === e1 && segIndex0 === segIndex1) { return null }\n var p00 = e0.getCoordinates()[segIndex0];\n var p01 = e0.getCoordinates()[segIndex0 + 1];\n var p10 = e1.getCoordinates()[segIndex1];\n var p11 = e1.getCoordinates()[segIndex1 + 1];\n this._li.computeIntersection(p00, p01, p10, p11);\n if (this._li.hasIntersection()) {\n if (this._li.isInteriorIntersection()) {\n for (var intIndex = 0; intIndex < this._li.getIntersectionNum(); intIndex++) {\n this$1._interiorIntersections.add(this$1._li.getIntersection(intIndex));\n }\n e0.addIntersections(this._li, segIndex0, 0);\n e1.addIntersections(this._li, segIndex1, 1);\n }\n }\n};\nInteriorIntersectionFinderAdder.prototype.isDone = function isDone () {\n return false\n};\nInteriorIntersectionFinderAdder.prototype.getInteriorIntersections = function getInteriorIntersections () {\n return this._interiorIntersections\n};\nInteriorIntersectionFinderAdder.prototype.interfaces_ = function interfaces_ () {\n return [SegmentIntersector]\n};\nInteriorIntersectionFinderAdder.prototype.getClass = function getClass () {\n return InteriorIntersectionFinderAdder\n};\n\nvar MCIndexSnapRounder = function MCIndexSnapRounder () {\n this._pm = null;\n this._li = null;\n this._scaleFactor = null;\n this._noder = null;\n this._pointSnapper = null;\n this._nodedSegStrings = null;\n var pm = arguments[0];\n this._pm = pm;\n this._li = new RobustLineIntersector();\n this._li.setPrecisionModel(pm);\n this._scaleFactor = pm.getScale();\n};\nMCIndexSnapRounder.prototype.checkCorrectness = function checkCorrectness (inputSegmentStrings) {\n var resultSegStrings = NodedSegmentString.getNodedSubstrings(inputSegmentStrings);\n var nv = new NodingValidator(resultSegStrings);\n try {\n nv.checkValid();\n } catch (ex) {\n if (ex instanceof Exception) {\n ex.printStackTrace();\n } else { throw ex }\n } finally {}\n};\nMCIndexSnapRounder.prototype.getNodedSubstrings = function getNodedSubstrings () {\n return NodedSegmentString.getNodedSubstrings(this._nodedSegStrings)\n};\nMCIndexSnapRounder.prototype.snapRound = function snapRound (segStrings, li) {\n var intersections = this.findInteriorIntersections(segStrings, li);\n this.computeIntersectionSnaps(intersections);\n this.computeVertexSnaps(segStrings);\n};\nMCIndexSnapRounder.prototype.findInteriorIntersections = function findInteriorIntersections (segStrings, li) {\n var intFinderAdder = new InteriorIntersectionFinderAdder(li);\n this._noder.setSegmentIntersector(intFinderAdder);\n this._noder.computeNodes(segStrings);\n return intFinderAdder.getInteriorIntersections()\n};\nMCIndexSnapRounder.prototype.computeVertexSnaps = function computeVertexSnaps () {\n var this$1 = this;\n\n if (hasInterface(arguments[0], Collection)) {\n var edges = arguments[0];\n for (var i0 = edges.iterator(); i0.hasNext();) {\n var edge0 = i0.next();\n this$1.computeVertexSnaps(edge0);\n }\n } else if (arguments[0] instanceof NodedSegmentString) {\n var e = arguments[0];\n var pts0 = e.getCoordinates();\n for (var i = 0; i < pts0.length; i++) {\n var hotPixel = new HotPixel(pts0[i], this$1._scaleFactor, this$1._li);\n var isNodeAdded = this$1._pointSnapper.snap(hotPixel, e, i);\n if (isNodeAdded) {\n e.addIntersection(pts0[i], i);\n }\n }\n }\n};\nMCIndexSnapRounder.prototype.computeNodes = function computeNodes (inputSegmentStrings) {\n this._nodedSegStrings = inputSegmentStrings;\n this._noder = new MCIndexNoder();\n this._pointSnapper = new MCIndexPointSnapper(this._noder.getIndex());\n this.snapRound(inputSegmentStrings, this._li);\n};\nMCIndexSnapRounder.prototype.computeIntersectionSnaps = function computeIntersectionSnaps (snapPts) {\n var this$1 = this;\n\n for (var it = snapPts.iterator(); it.hasNext();) {\n var snapPt = it.next();\n var hotPixel = new HotPixel(snapPt, this$1._scaleFactor, this$1._li);\n this$1._pointSnapper.snap(hotPixel);\n }\n};\nMCIndexSnapRounder.prototype.interfaces_ = function interfaces_ () {\n return [Noder]\n};\nMCIndexSnapRounder.prototype.getClass = function getClass () {\n return MCIndexSnapRounder\n};\n\nvar BufferOp = function BufferOp () {\n this._argGeom = null;\n this._distance = null;\n this._bufParams = new BufferParameters();\n this._resultGeometry = null;\n this._saveException = null;\n if (arguments.length === 1) {\n var g = arguments[0];\n this._argGeom = g;\n } else if (arguments.length === 2) {\n var g$1 = arguments[0];\n var bufParams = arguments[1];\n this._argGeom = g$1;\n this._bufParams = bufParams;\n }\n};\n\nvar staticAccessors$32 = { CAP_ROUND: { configurable: true },CAP_BUTT: { configurable: true },CAP_FLAT: { configurable: true },CAP_SQUARE: { configurable: true },MAX_PRECISION_DIGITS: { configurable: true } };\nBufferOp.prototype.bufferFixedPrecision = function bufferFixedPrecision (fixedPM) {\n var noder = new ScaledNoder(new MCIndexSnapRounder(new PrecisionModel(1.0)), fixedPM.getScale());\n var bufBuilder = new BufferBuilder(this._bufParams);\n bufBuilder.setWorkingPrecisionModel(fixedPM);\n bufBuilder.setNoder(noder);\n this._resultGeometry = bufBuilder.buffer(this._argGeom, this._distance);\n};\nBufferOp.prototype.bufferReducedPrecision = function bufferReducedPrecision () {\n var this$1 = this;\n\n if (arguments.length === 0) {\n for (var precDigits = BufferOp.MAX_PRECISION_DIGITS; precDigits >= 0; precDigits--) {\n try {\n this$1.bufferReducedPrecision(precDigits);\n } catch (ex) {\n if (ex instanceof TopologyException) {\n this$1._saveException = ex;\n } else { throw ex }\n } finally {}\n if (this$1._resultGeometry !== null) { return null }\n }\n throw this._saveException\n } else if (arguments.length === 1) {\n var precisionDigits = arguments[0];\n var sizeBasedScaleFactor = BufferOp.precisionScaleFactor(this._argGeom, this._distance, precisionDigits);\n var fixedPM = new PrecisionModel(sizeBasedScaleFactor);\n this.bufferFixedPrecision(fixedPM);\n }\n};\nBufferOp.prototype.computeGeometry = function computeGeometry () {\n this.bufferOriginalPrecision();\n if (this._resultGeometry !== null) { return null }\n var argPM = this._argGeom.getFactory().getPrecisionModel();\n if (argPM.getType() === PrecisionModel.FIXED) { this.bufferFixedPrecision(argPM); } else { this.bufferReducedPrecision(); }\n};\nBufferOp.prototype.setQuadrantSegments = function setQuadrantSegments (quadrantSegments) {\n this._bufParams.setQuadrantSegments(quadrantSegments);\n};\nBufferOp.prototype.bufferOriginalPrecision = function bufferOriginalPrecision () {\n try {\n var bufBuilder = new BufferBuilder(this._bufParams);\n this._resultGeometry = bufBuilder.buffer(this._argGeom, this._distance);\n } catch (ex) {\n if (ex instanceof RuntimeException) {\n this._saveException = ex;\n } else { throw ex }\n } finally {}\n};\nBufferOp.prototype.getResultGeometry = function getResultGeometry (distance) {\n this._distance = distance;\n this.computeGeometry();\n return this._resultGeometry\n};\nBufferOp.prototype.setEndCapStyle = function setEndCapStyle (endCapStyle) {\n this._bufParams.setEndCapStyle(endCapStyle);\n};\nBufferOp.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nBufferOp.prototype.getClass = function getClass () {\n return BufferOp\n};\nBufferOp.bufferOp = function bufferOp () {\n if (arguments.length === 2) {\n var g = arguments[0];\n var distance = arguments[1];\n var gBuf = new BufferOp(g);\n var geomBuf = gBuf.getResultGeometry(distance);\n return geomBuf\n } else if (arguments.length === 3) {\n if (Number.isInteger(arguments[2]) && (arguments[0] instanceof Geometry && typeof arguments[1] === 'number')) {\n var g$1 = arguments[0];\n var distance$1 = arguments[1];\n var quadrantSegments = arguments[2];\n var bufOp = new BufferOp(g$1);\n bufOp.setQuadrantSegments(quadrantSegments);\n var geomBuf$1 = bufOp.getResultGeometry(distance$1);\n return geomBuf$1\n } else if (arguments[2] instanceof BufferParameters && (arguments[0] instanceof Geometry && typeof arguments[1] === 'number')) {\n var g$2 = arguments[0];\n var distance$2 = arguments[1];\n var params = arguments[2];\n var bufOp$1 = new BufferOp(g$2, params);\n var geomBuf$2 = bufOp$1.getResultGeometry(distance$2);\n return geomBuf$2\n }\n } else if (arguments.length === 4) {\n var g$3 = arguments[0];\n var distance$3 = arguments[1];\n var quadrantSegments$1 = arguments[2];\n var endCapStyle = arguments[3];\n var bufOp$2 = new BufferOp(g$3);\n bufOp$2.setQuadrantSegments(quadrantSegments$1);\n bufOp$2.setEndCapStyle(endCapStyle);\n var geomBuf$3 = bufOp$2.getResultGeometry(distance$3);\n return geomBuf$3\n }\n};\nBufferOp.precisionScaleFactor = function precisionScaleFactor (g, distance, maxPrecisionDigits) {\n var env = g.getEnvelopeInternal();\n var envMax = MathUtil.max(Math.abs(env.getMaxX()), Math.abs(env.getMaxY()), Math.abs(env.getMinX()), Math.abs(env.getMinY()));\n var expandByDistance = distance > 0.0 ? distance : 0.0;\n var bufEnvMax = envMax + 2 * expandByDistance;\n var bufEnvPrecisionDigits = Math.trunc(Math.log(bufEnvMax) / Math.log(10) + 1.0);\n var minUnitLog10 = maxPrecisionDigits - bufEnvPrecisionDigits;\n var scaleFactor = Math.pow(10.0, minUnitLog10);\n return scaleFactor\n};\nstaticAccessors$32.CAP_ROUND.get = function () { return BufferParameters.CAP_ROUND };\nstaticAccessors$32.CAP_BUTT.get = function () { return BufferParameters.CAP_FLAT };\nstaticAccessors$32.CAP_FLAT.get = function () { return BufferParameters.CAP_FLAT };\nstaticAccessors$32.CAP_SQUARE.get = function () { return BufferParameters.CAP_SQUARE };\nstaticAccessors$32.MAX_PRECISION_DIGITS.get = function () { return 12 };\n\nObject.defineProperties( BufferOp, staticAccessors$32 );\n\nvar PointPairDistance = function PointPairDistance () {\n this._pt = [new Coordinate(), new Coordinate()];\n this._distance = Double.NaN;\n this._isNull = true;\n};\nPointPairDistance.prototype.getCoordinates = function getCoordinates () {\n return this._pt\n};\nPointPairDistance.prototype.getCoordinate = function getCoordinate (i) {\n return this._pt[i]\n};\nPointPairDistance.prototype.setMinimum = function setMinimum () {\n if (arguments.length === 1) {\n var ptDist = arguments[0];\n this.setMinimum(ptDist._pt[0], ptDist._pt[1]);\n } else if (arguments.length === 2) {\n var p0 = arguments[0];\n var p1 = arguments[1];\n if (this._isNull) {\n this.initialize(p0, p1);\n return null\n }\n var dist = p0.distance(p1);\n if (dist < this._distance) { this.initialize(p0, p1, dist); }\n }\n};\nPointPairDistance.prototype.initialize = function initialize () {\n if (arguments.length === 0) {\n this._isNull = true;\n } else if (arguments.length === 2) {\n var p0 = arguments[0];\n var p1 = arguments[1];\n this._pt[0].setCoordinate(p0);\n this._pt[1].setCoordinate(p1);\n this._distance = p0.distance(p1);\n this._isNull = false;\n } else if (arguments.length === 3) {\n var p0$1 = arguments[0];\n var p1$1 = arguments[1];\n var distance = arguments[2];\n this._pt[0].setCoordinate(p0$1);\n this._pt[1].setCoordinate(p1$1);\n this._distance = distance;\n this._isNull = false;\n }\n};\nPointPairDistance.prototype.getDistance = function getDistance () {\n return this._distance\n};\nPointPairDistance.prototype.setMaximum = function setMaximum () {\n if (arguments.length === 1) {\n var ptDist = arguments[0];\n this.setMaximum(ptDist._pt[0], ptDist._pt[1]);\n } else if (arguments.length === 2) {\n var p0 = arguments[0];\n var p1 = arguments[1];\n if (this._isNull) {\n this.initialize(p0, p1);\n return null\n }\n var dist = p0.distance(p1);\n if (dist > this._distance) { this.initialize(p0, p1, dist); }\n }\n};\nPointPairDistance.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nPointPairDistance.prototype.getClass = function getClass () {\n return PointPairDistance\n};\n\nvar DistanceToPointFinder = function DistanceToPointFinder () {};\n\nDistanceToPointFinder.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nDistanceToPointFinder.prototype.getClass = function getClass () {\n return DistanceToPointFinder\n};\nDistanceToPointFinder.computeDistance = function computeDistance () {\n if (arguments[2] instanceof PointPairDistance && (arguments[0] instanceof LineString && arguments[1] instanceof Coordinate)) {\n var line = arguments[0];\n var pt = arguments[1];\n var ptDist = arguments[2];\n var coords = line.getCoordinates();\n var tempSegment = new LineSegment();\n for (var i = 0; i < coords.length - 1; i++) {\n tempSegment.setCoordinates(coords[i], coords[i + 1]);\n var closestPt = tempSegment.closestPoint(pt);\n ptDist.setMinimum(closestPt, pt);\n }\n } else if (arguments[2] instanceof PointPairDistance && (arguments[0] instanceof Polygon && arguments[1] instanceof Coordinate)) {\n var poly = arguments[0];\n var pt$1 = arguments[1];\n var ptDist$1 = arguments[2];\n DistanceToPointFinder.computeDistance(poly.getExteriorRing(), pt$1, ptDist$1);\n for (var i$1 = 0; i$1 < poly.getNumInteriorRing(); i$1++) {\n DistanceToPointFinder.computeDistance(poly.getInteriorRingN(i$1), pt$1, ptDist$1);\n }\n } else if (arguments[2] instanceof PointPairDistance && (arguments[0] instanceof Geometry && arguments[1] instanceof Coordinate)) {\n var geom = arguments[0];\n var pt$2 = arguments[1];\n var ptDist$2 = arguments[2];\n if (geom instanceof LineString) {\n DistanceToPointFinder.computeDistance(geom, pt$2, ptDist$2);\n } else if (geom instanceof Polygon) {\n DistanceToPointFinder.computeDistance(geom, pt$2, ptDist$2);\n } else if (geom instanceof GeometryCollection) {\n var gc = geom;\n for (var i$2 = 0; i$2 < gc.getNumGeometries(); i$2++) {\n var g = gc.getGeometryN(i$2);\n DistanceToPointFinder.computeDistance(g, pt$2, ptDist$2);\n }\n } else {\n ptDist$2.setMinimum(geom.getCoordinate(), pt$2);\n }\n } else if (arguments[2] instanceof PointPairDistance && (arguments[0] instanceof LineSegment && arguments[1] instanceof Coordinate)) {\n var segment = arguments[0];\n var pt$3 = arguments[1];\n var ptDist$3 = arguments[2];\n var closestPt$1 = segment.closestPoint(pt$3);\n ptDist$3.setMinimum(closestPt$1, pt$3);\n }\n};\n\nvar BufferCurveMaximumDistanceFinder = function BufferCurveMaximumDistanceFinder (inputGeom) {\n this._maxPtDist = new PointPairDistance();\n this._inputGeom = inputGeom || null;\n};\n\nvar staticAccessors$36 = { MaxPointDistanceFilter: { configurable: true },MaxMidpointDistanceFilter: { configurable: true } };\nBufferCurveMaximumDistanceFinder.prototype.computeMaxMidpointDistance = function computeMaxMidpointDistance (curve) {\n var distFilter = new MaxMidpointDistanceFilter(this._inputGeom);\n curve.apply(distFilter);\n this._maxPtDist.setMaximum(distFilter.getMaxPointDistance());\n};\nBufferCurveMaximumDistanceFinder.prototype.computeMaxVertexDistance = function computeMaxVertexDistance (curve) {\n var distFilter = new MaxPointDistanceFilter(this._inputGeom);\n curve.apply(distFilter);\n this._maxPtDist.setMaximum(distFilter.getMaxPointDistance());\n};\nBufferCurveMaximumDistanceFinder.prototype.findDistance = function findDistance (bufferCurve) {\n this.computeMaxVertexDistance(bufferCurve);\n this.computeMaxMidpointDistance(bufferCurve);\n return this._maxPtDist.getDistance()\n};\nBufferCurveMaximumDistanceFinder.prototype.getDistancePoints = function getDistancePoints () {\n return this._maxPtDist\n};\nBufferCurveMaximumDistanceFinder.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nBufferCurveMaximumDistanceFinder.prototype.getClass = function getClass () {\n return BufferCurveMaximumDistanceFinder\n};\nstaticAccessors$36.MaxPointDistanceFilter.get = function () { return MaxPointDistanceFilter };\nstaticAccessors$36.MaxMidpointDistanceFilter.get = function () { return MaxMidpointDistanceFilter };\n\nObject.defineProperties( BufferCurveMaximumDistanceFinder, staticAccessors$36 );\n\nvar MaxPointDistanceFilter = function MaxPointDistanceFilter (geom) {\n this._maxPtDist = new PointPairDistance();\n this._minPtDist = new PointPairDistance();\n this._geom = geom || null;\n};\nMaxPointDistanceFilter.prototype.filter = function filter (pt) {\n this._minPtDist.initialize();\n DistanceToPointFinder.computeDistance(this._geom, pt, this._minPtDist);\n this._maxPtDist.setMaximum(this._minPtDist);\n};\nMaxPointDistanceFilter.prototype.getMaxPointDistance = function getMaxPointDistance () {\n return this._maxPtDist\n};\nMaxPointDistanceFilter.prototype.interfaces_ = function interfaces_ () {\n return [CoordinateFilter]\n};\nMaxPointDistanceFilter.prototype.getClass = function getClass () {\n return MaxPointDistanceFilter\n};\n\nvar MaxMidpointDistanceFilter = function MaxMidpointDistanceFilter (geom) {\n this._maxPtDist = new PointPairDistance();\n this._minPtDist = new PointPairDistance();\n this._geom = geom || null;\n};\nMaxMidpointDistanceFilter.prototype.filter = function filter (seq, index) {\n if (index === 0) { return null }\n var p0 = seq.getCoordinate(index - 1);\n var p1 = seq.getCoordinate(index);\n var midPt = new Coordinate((p0.x + p1.x) / 2, (p0.y + p1.y) / 2);\n this._minPtDist.initialize();\n DistanceToPointFinder.computeDistance(this._geom, midPt, this._minPtDist);\n this._maxPtDist.setMaximum(this._minPtDist);\n};\nMaxMidpointDistanceFilter.prototype.isDone = function isDone () {\n return false\n};\nMaxMidpointDistanceFilter.prototype.isGeometryChanged = function isGeometryChanged () {\n return false\n};\nMaxMidpointDistanceFilter.prototype.getMaxPointDistance = function getMaxPointDistance () {\n return this._maxPtDist\n};\nMaxMidpointDistanceFilter.prototype.interfaces_ = function interfaces_ () {\n return [CoordinateSequenceFilter]\n};\nMaxMidpointDistanceFilter.prototype.getClass = function getClass () {\n return MaxMidpointDistanceFilter\n};\n\nvar PolygonExtracter = function PolygonExtracter (comps) {\n this._comps = comps || null;\n};\nPolygonExtracter.prototype.filter = function filter (geom) {\n if (geom instanceof Polygon) { this._comps.add(geom); }\n};\nPolygonExtracter.prototype.interfaces_ = function interfaces_ () {\n return [GeometryFilter]\n};\nPolygonExtracter.prototype.getClass = function getClass () {\n return PolygonExtracter\n};\nPolygonExtracter.getPolygons = function getPolygons () {\n if (arguments.length === 1) {\n var geom = arguments[0];\n return PolygonExtracter.getPolygons(geom, new ArrayList())\n } else if (arguments.length === 2) {\n var geom$1 = arguments[0];\n var list = arguments[1];\n if (geom$1 instanceof Polygon) {\n list.add(geom$1);\n } else if (geom$1 instanceof GeometryCollection) {\n geom$1.apply(new PolygonExtracter(list));\n }\n return list\n }\n};\n\nvar LinearComponentExtracter = function LinearComponentExtracter () {\n this._lines = null;\n this._isForcedToLineString = false;\n if (arguments.length === 1) {\n var lines = arguments[0];\n this._lines = lines;\n } else if (arguments.length === 2) {\n var lines$1 = arguments[0];\n var isForcedToLineString = arguments[1];\n this._lines = lines$1;\n this._isForcedToLineString = isForcedToLineString;\n }\n};\nLinearComponentExtracter.prototype.filter = function filter (geom) {\n if (this._isForcedToLineString && geom instanceof LinearRing) {\n var line = geom.getFactory().createLineString(geom.getCoordinateSequence());\n this._lines.add(line);\n return null\n }\n if (geom instanceof LineString) { this._lines.add(geom); }\n};\nLinearComponentExtracter.prototype.setForceToLineString = function setForceToLineString (isForcedToLineString) {\n this._isForcedToLineString = isForcedToLineString;\n};\nLinearComponentExtracter.prototype.interfaces_ = function interfaces_ () {\n return [GeometryComponentFilter]\n};\nLinearComponentExtracter.prototype.getClass = function getClass () {\n return LinearComponentExtracter\n};\nLinearComponentExtracter.getGeometry = function getGeometry () {\n if (arguments.length === 1) {\n var geom = arguments[0];\n return geom.getFactory().buildGeometry(LinearComponentExtracter.getLines(geom))\n } else if (arguments.length === 2) {\n var geom$1 = arguments[0];\n var forceToLineString = arguments[1];\n return geom$1.getFactory().buildGeometry(LinearComponentExtracter.getLines(geom$1, forceToLineString))\n }\n};\nLinearComponentExtracter.getLines = function getLines () {\n if (arguments.length === 1) {\n var geom = arguments[0];\n return LinearComponentExtracter.getLines(geom, false)\n } else if (arguments.length === 2) {\n if (hasInterface(arguments[0], Collection) && hasInterface(arguments[1], Collection)) {\n var geoms = arguments[0];\n var lines$1 = arguments[1];\n for (var i = geoms.iterator(); i.hasNext();) {\n var g = i.next();\n LinearComponentExtracter.getLines(g, lines$1);\n }\n return lines$1\n } else if (arguments[0] instanceof Geometry && typeof arguments[1] === 'boolean') {\n var geom$1 = arguments[0];\n var forceToLineString = arguments[1];\n var lines = new ArrayList();\n geom$1.apply(new LinearComponentExtracter(lines, forceToLineString));\n return lines\n } else if (arguments[0] instanceof Geometry && hasInterface(arguments[1], Collection)) {\n var geom$2 = arguments[0];\n var lines$2 = arguments[1];\n if (geom$2 instanceof LineString) {\n lines$2.add(geom$2);\n } else {\n geom$2.apply(new LinearComponentExtracter(lines$2));\n }\n return lines$2\n }\n } else if (arguments.length === 3) {\n if (typeof arguments[2] === 'boolean' && (hasInterface(arguments[0], Collection) && hasInterface(arguments[1], Collection))) {\n var geoms$1 = arguments[0];\n var lines$3 = arguments[1];\n var forceToLineString$1 = arguments[2];\n for (var i$1 = geoms$1.iterator(); i$1.hasNext();) {\n var g$1 = i$1.next();\n LinearComponentExtracter.getLines(g$1, lines$3, forceToLineString$1);\n }\n return lines$3\n } else if (typeof arguments[2] === 'boolean' && (arguments[0] instanceof Geometry && hasInterface(arguments[1], Collection))) {\n var geom$3 = arguments[0];\n var lines$4 = arguments[1];\n var forceToLineString$2 = arguments[2];\n geom$3.apply(new LinearComponentExtracter(lines$4, forceToLineString$2));\n return lines$4\n }\n }\n};\n\nvar PointLocator = function PointLocator () {\n this._boundaryRule = BoundaryNodeRule.OGC_SFS_BOUNDARY_RULE;\n this._isIn = null;\n this._numBoundaries = null;\n if (arguments.length === 0) {} else if (arguments.length === 1) {\n var boundaryRule = arguments[0];\n if (boundaryRule === null) { throw new IllegalArgumentException('Rule must be non-null') }\n this._boundaryRule = boundaryRule;\n }\n};\nPointLocator.prototype.locateInternal = function locateInternal () {\n var this$1 = this;\n\n if (arguments[0] instanceof Coordinate && arguments[1] instanceof Polygon) {\n var p = arguments[0];\n var poly = arguments[1];\n if (poly.isEmpty()) { return Location.EXTERIOR }\n var shell = poly.getExteriorRing();\n var shellLoc = this.locateInPolygonRing(p, shell);\n if (shellLoc === Location.EXTERIOR) { return Location.EXTERIOR }\n if (shellLoc === Location.BOUNDARY) { return Location.BOUNDARY }\n for (var i = 0; i < poly.getNumInteriorRing(); i++) {\n var hole = poly.getInteriorRingN(i);\n var holeLoc = this$1.locateInPolygonRing(p, hole);\n if (holeLoc === Location.INTERIOR) { return Location.EXTERIOR }\n if (holeLoc === Location.BOUNDARY) { return Location.BOUNDARY }\n }\n return Location.INTERIOR\n } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof LineString) {\n var p$1 = arguments[0];\n var l = arguments[1];\n if (!l.getEnvelopeInternal().intersects(p$1)) { return Location.EXTERIOR }\n var pt = l.getCoordinates();\n if (!l.isClosed()) {\n if (p$1.equals(pt[0]) || p$1.equals(pt[pt.length - 1])) {\n return Location.BOUNDARY\n }\n }\n if (CGAlgorithms.isOnLine(p$1, pt)) { return Location.INTERIOR }\n return Location.EXTERIOR\n } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Point) {\n var p$2 = arguments[0];\n var pt$1 = arguments[1];\n var ptCoord = pt$1.getCoordinate();\n if (ptCoord.equals2D(p$2)) { return Location.INTERIOR }\n return Location.EXTERIOR\n }\n};\nPointLocator.prototype.locateInPolygonRing = function locateInPolygonRing (p, ring) {\n if (!ring.getEnvelopeInternal().intersects(p)) { return Location.EXTERIOR }\n return CGAlgorithms.locatePointInRing(p, ring.getCoordinates())\n};\nPointLocator.prototype.intersects = function intersects (p, geom) {\n return this.locate(p, geom) !== Location.EXTERIOR\n};\nPointLocator.prototype.updateLocationInfo = function updateLocationInfo (loc) {\n if (loc === Location.INTERIOR) { this._isIn = true; }\n if (loc === Location.BOUNDARY) { this._numBoundaries++; }\n};\nPointLocator.prototype.computeLocation = function computeLocation (p, geom) {\n var this$1 = this;\n\n if (geom instanceof Point) {\n this.updateLocationInfo(this.locateInternal(p, geom));\n }\n if (geom instanceof LineString) {\n this.updateLocationInfo(this.locateInternal(p, geom));\n } else if (geom instanceof Polygon) {\n this.updateLocationInfo(this.locateInternal(p, geom));\n } else if (geom instanceof MultiLineString) {\n var ml = geom;\n for (var i = 0; i < ml.getNumGeometries(); i++) {\n var l = ml.getGeometryN(i);\n this$1.updateLocationInfo(this$1.locateInternal(p, l));\n }\n } else if (geom instanceof MultiPolygon) {\n var mpoly = geom;\n for (var i$1 = 0; i$1 < mpoly.getNumGeometries(); i$1++) {\n var poly = mpoly.getGeometryN(i$1);\n this$1.updateLocationInfo(this$1.locateInternal(p, poly));\n }\n } else if (geom instanceof GeometryCollection) {\n var geomi = new GeometryCollectionIterator(geom);\n while (geomi.hasNext()) {\n var g2 = geomi.next();\n if (g2 !== geom) { this$1.computeLocation(p, g2); }\n }\n }\n};\nPointLocator.prototype.locate = function locate (p, geom) {\n if (geom.isEmpty()) { return Location.EXTERIOR }\n if (geom instanceof LineString) {\n return this.locateInternal(p, geom)\n } else if (geom instanceof Polygon) {\n return this.locateInternal(p, geom)\n }\n this._isIn = false;\n this._numBoundaries = 0;\n this.computeLocation(p, geom);\n if (this._boundaryRule.isInBoundary(this._numBoundaries)) { return Location.BOUNDARY }\n if (this._numBoundaries > 0 || this._isIn) { return Location.INTERIOR }\n return Location.EXTERIOR\n};\nPointLocator.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nPointLocator.prototype.getClass = function getClass () {\n return PointLocator\n};\n\nvar GeometryLocation = function GeometryLocation () {\n this._component = null;\n this._segIndex = null;\n this._pt = null;\n if (arguments.length === 2) {\n var component = arguments[0];\n var pt = arguments[1];\n GeometryLocation.call(this, component, GeometryLocation.INSIDE_AREA, pt);\n } else if (arguments.length === 3) {\n var component$1 = arguments[0];\n var segIndex = arguments[1];\n var pt$1 = arguments[2];\n this._component = component$1;\n this._segIndex = segIndex;\n this._pt = pt$1;\n }\n};\n\nvar staticAccessors$38 = { INSIDE_AREA: { configurable: true } };\nGeometryLocation.prototype.isInsideArea = function isInsideArea () {\n return this._segIndex === GeometryLocation.INSIDE_AREA\n};\nGeometryLocation.prototype.getCoordinate = function getCoordinate () {\n return this._pt\n};\nGeometryLocation.prototype.getGeometryComponent = function getGeometryComponent () {\n return this._component\n};\nGeometryLocation.prototype.getSegmentIndex = function getSegmentIndex () {\n return this._segIndex\n};\nGeometryLocation.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nGeometryLocation.prototype.getClass = function getClass () {\n return GeometryLocation\n};\nstaticAccessors$38.INSIDE_AREA.get = function () { return -1 };\n\nObject.defineProperties( GeometryLocation, staticAccessors$38 );\n\nvar PointExtracter = function PointExtracter (pts) {\n this._pts = pts || null;\n};\nPointExtracter.prototype.filter = function filter (geom) {\n if (geom instanceof Point) { this._pts.add(geom); }\n};\nPointExtracter.prototype.interfaces_ = function interfaces_ () {\n return [GeometryFilter]\n};\nPointExtracter.prototype.getClass = function getClass () {\n return PointExtracter\n};\nPointExtracter.getPoints = function getPoints () {\n if (arguments.length === 1) {\n var geom = arguments[0];\n if (geom instanceof Point) {\n return Collections.singletonList(geom)\n }\n return PointExtracter.getPoints(geom, new ArrayList())\n } else if (arguments.length === 2) {\n var geom$1 = arguments[0];\n var list = arguments[1];\n if (geom$1 instanceof Point) {\n list.add(geom$1);\n } else if (geom$1 instanceof GeometryCollection) {\n geom$1.apply(new PointExtracter(list));\n }\n return list\n }\n};\n\nvar ConnectedElementLocationFilter = function ConnectedElementLocationFilter () {\n this._locations = null;\n var locations = arguments[0];\n this._locations = locations;\n};\nConnectedElementLocationFilter.prototype.filter = function filter (geom) {\n if (geom instanceof Point || geom instanceof LineString || geom instanceof Polygon) { this._locations.add(new GeometryLocation(geom, 0, geom.getCoordinate())); }\n};\nConnectedElementLocationFilter.prototype.interfaces_ = function interfaces_ () {\n return [GeometryFilter]\n};\nConnectedElementLocationFilter.prototype.getClass = function getClass () {\n return ConnectedElementLocationFilter\n};\nConnectedElementLocationFilter.getLocations = function getLocations (geom) {\n var locations = new ArrayList();\n geom.apply(new ConnectedElementLocationFilter(locations));\n return locations\n};\n\nvar DistanceOp = function DistanceOp () {\n this._geom = null;\n this._terminateDistance = 0.0;\n this._ptLocator = new PointLocator();\n this._minDistanceLocation = null;\n this._minDistance = Double.MAX_VALUE;\n if (arguments.length === 2) {\n var g0 = arguments[0];\n var g1 = arguments[1];\n this._geom = [g0, g1];\n this._terminateDistance = 0.0;\n } else if (arguments.length === 3) {\n var g0$1 = arguments[0];\n var g1$1 = arguments[1];\n var terminateDistance = arguments[2];\n this._geom = new Array(2).fill(null);\n this._geom[0] = g0$1;\n this._geom[1] = g1$1;\n this._terminateDistance = terminateDistance;\n }\n};\nDistanceOp.prototype.computeContainmentDistance = function computeContainmentDistance () {\n var this$1 = this;\n\n if (arguments.length === 0) {\n var locPtPoly = new Array(2).fill(null);\n this.computeContainmentDistance(0, locPtPoly);\n if (this._minDistance <= this._terminateDistance) { return null }\n this.computeContainmentDistance(1, locPtPoly);\n } else if (arguments.length === 2) {\n var polyGeomIndex = arguments[0];\n var locPtPoly$1 = arguments[1];\n var locationsIndex = 1 - polyGeomIndex;\n var polys = PolygonExtracter.getPolygons(this._geom[polyGeomIndex]);\n if (polys.size() > 0) {\n var insideLocs = ConnectedElementLocationFilter.getLocations(this._geom[locationsIndex]);\n this.computeContainmentDistance(insideLocs, polys, locPtPoly$1);\n if (this._minDistance <= this._terminateDistance) {\n this._minDistanceLocation[locationsIndex] = locPtPoly$1[0];\n this._minDistanceLocation[polyGeomIndex] = locPtPoly$1[1];\n return null\n }\n }\n } else if (arguments.length === 3) {\n if (arguments[2] instanceof Array && (hasInterface(arguments[0], List) && hasInterface(arguments[1], List))) {\n var locs = arguments[0];\n var polys$1 = arguments[1];\n var locPtPoly$2 = arguments[2];\n for (var i = 0; i < locs.size(); i++) {\n var loc = locs.get(i);\n for (var j = 0; j < polys$1.size(); j++) {\n this$1.computeContainmentDistance(loc, polys$1.get(j), locPtPoly$2);\n if (this$1._minDistance <= this$1._terminateDistance) { return null }\n }\n }\n } else if (arguments[2] instanceof Array && (arguments[0] instanceof GeometryLocation && arguments[1] instanceof Polygon)) {\n var ptLoc = arguments[0];\n var poly = arguments[1];\n var locPtPoly$3 = arguments[2];\n var pt = ptLoc.getCoordinate();\n if (Location.EXTERIOR !== this._ptLocator.locate(pt, poly)) {\n this._minDistance = 0.0;\n locPtPoly$3[0] = ptLoc;\n locPtPoly$3[1] = new GeometryLocation(poly, pt);\n\n return null\n }\n }\n }\n};\nDistanceOp.prototype.computeMinDistanceLinesPoints = function computeMinDistanceLinesPoints (lines, points, locGeom) {\n var this$1 = this;\n\n for (var i = 0; i < lines.size(); i++) {\n var line = lines.get(i);\n for (var j = 0; j < points.size(); j++) {\n var pt = points.get(j);\n this$1.computeMinDistance(line, pt, locGeom);\n if (this$1._minDistance <= this$1._terminateDistance) { return null }\n }\n }\n};\nDistanceOp.prototype.computeFacetDistance = function computeFacetDistance () {\n var locGeom = new Array(2).fill(null);\n var lines0 = LinearComponentExtracter.getLines(this._geom[0]);\n var lines1 = LinearComponentExtracter.getLines(this._geom[1]);\n var pts0 = PointExtracter.getPoints(this._geom[0]);\n var pts1 = PointExtracter.getPoints(this._geom[1]);\n this.computeMinDistanceLines(lines0, lines1, locGeom);\n this.updateMinDistance(locGeom, false);\n if (this._minDistance <= this._terminateDistance) { return null }\n locGeom[0] = null;\n locGeom[1] = null;\n this.computeMinDistanceLinesPoints(lines0, pts1, locGeom);\n this.updateMinDistance(locGeom, false);\n if (this._minDistance <= this._terminateDistance) { return null }\n locGeom[0] = null;\n locGeom[1] = null;\n this.computeMinDistanceLinesPoints(lines1, pts0, locGeom);\n this.updateMinDistance(locGeom, true);\n if (this._minDistance <= this._terminateDistance) { return null }\n locGeom[0] = null;\n locGeom[1] = null;\n this.computeMinDistancePoints(pts0, pts1, locGeom);\n this.updateMinDistance(locGeom, false);\n};\nDistanceOp.prototype.nearestLocations = function nearestLocations () {\n this.computeMinDistance();\n return this._minDistanceLocation\n};\nDistanceOp.prototype.updateMinDistance = function updateMinDistance (locGeom, flip) {\n if (locGeom[0] === null) { return null }\n if (flip) {\n this._minDistanceLocation[0] = locGeom[1];\n this._minDistanceLocation[1] = locGeom[0];\n } else {\n this._minDistanceLocation[0] = locGeom[0];\n this._minDistanceLocation[1] = locGeom[1];\n }\n};\nDistanceOp.prototype.nearestPoints = function nearestPoints () {\n this.computeMinDistance();\n var nearestPts = [this._minDistanceLocation[0].getCoordinate(), this._minDistanceLocation[1].getCoordinate()];\n return nearestPts\n};\nDistanceOp.prototype.computeMinDistance = function computeMinDistance () {\n var this$1 = this;\n\n if (arguments.length === 0) {\n if (this._minDistanceLocation !== null) { return null }\n this._minDistanceLocation = new Array(2).fill(null);\n this.computeContainmentDistance();\n if (this._minDistance <= this._terminateDistance) { return null }\n this.computeFacetDistance();\n } else if (arguments.length === 3) {\n if (arguments[2] instanceof Array && (arguments[0] instanceof LineString && arguments[1] instanceof Point)) {\n var line = arguments[0];\n var pt = arguments[1];\n var locGeom = arguments[2];\n if (line.getEnvelopeInternal().distance(pt.getEnvelopeInternal()) > this._minDistance) { return null }\n var coord0 = line.getCoordinates();\n var coord = pt.getCoordinate();\n for (var i = 0; i < coord0.length - 1; i++) {\n var dist = CGAlgorithms.distancePointLine(coord, coord0[i], coord0[i + 1]);\n if (dist < this$1._minDistance) {\n this$1._minDistance = dist;\n var seg = new LineSegment(coord0[i], coord0[i + 1]);\n var segClosestPoint = seg.closestPoint(coord);\n locGeom[0] = new GeometryLocation(line, i, segClosestPoint);\n locGeom[1] = new GeometryLocation(pt, 0, coord);\n }\n if (this$1._minDistance <= this$1._terminateDistance) { return null }\n }\n } else if (arguments[2] instanceof Array && (arguments[0] instanceof LineString && arguments[1] instanceof LineString)) {\n var line0 = arguments[0];\n var line1 = arguments[1];\n var locGeom$1 = arguments[2];\n if (line0.getEnvelopeInternal().distance(line1.getEnvelopeInternal()) > this._minDistance) { return null }\n var coord0$1 = line0.getCoordinates();\n var coord1 = line1.getCoordinates();\n for (var i$1 = 0; i$1 < coord0$1.length - 1; i$1++) {\n for (var j = 0; j < coord1.length - 1; j++) {\n var dist$1 = CGAlgorithms.distanceLineLine(coord0$1[i$1], coord0$1[i$1 + 1], coord1[j], coord1[j + 1]);\n if (dist$1 < this$1._minDistance) {\n this$1._minDistance = dist$1;\n var seg0 = new LineSegment(coord0$1[i$1], coord0$1[i$1 + 1]);\n var seg1 = new LineSegment(coord1[j], coord1[j + 1]);\n var closestPt = seg0.closestPoints(seg1);\n locGeom$1[0] = new GeometryLocation(line0, i$1, closestPt[0]);\n locGeom$1[1] = new GeometryLocation(line1, j, closestPt[1]);\n }\n if (this$1._minDistance <= this$1._terminateDistance) { return null }\n }\n }\n }\n }\n};\nDistanceOp.prototype.computeMinDistancePoints = function computeMinDistancePoints (points0, points1, locGeom) {\n var this$1 = this;\n\n for (var i = 0; i < points0.size(); i++) {\n var pt0 = points0.get(i);\n for (var j = 0; j < points1.size(); j++) {\n var pt1 = points1.get(j);\n var dist = pt0.getCoordinate().distance(pt1.getCoordinate());\n if (dist < this$1._minDistance) {\n this$1._minDistance = dist;\n locGeom[0] = new GeometryLocation(pt0, 0, pt0.getCoordinate());\n locGeom[1] = new GeometryLocation(pt1, 0, pt1.getCoordinate());\n }\n if (this$1._minDistance <= this$1._terminateDistance) { return null }\n }\n }\n};\nDistanceOp.prototype.distance = function distance () {\n if (this._geom[0] === null || this._geom[1] === null) { throw new IllegalArgumentException('null geometries are not supported') }\n if (this._geom[0].isEmpty() || this._geom[1].isEmpty()) { return 0.0 }\n this.computeMinDistance();\n return this._minDistance\n};\nDistanceOp.prototype.computeMinDistanceLines = function computeMinDistanceLines (lines0, lines1, locGeom) {\n var this$1 = this;\n\n for (var i = 0; i < lines0.size(); i++) {\n var line0 = lines0.get(i);\n for (var j = 0; j < lines1.size(); j++) {\n var line1 = lines1.get(j);\n this$1.computeMinDistance(line0, line1, locGeom);\n if (this$1._minDistance <= this$1._terminateDistance) { return null }\n }\n }\n};\nDistanceOp.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nDistanceOp.prototype.getClass = function getClass () {\n return DistanceOp\n};\nDistanceOp.distance = function distance (g0, g1) {\n var distOp = new DistanceOp(g0, g1);\n return distOp.distance()\n};\nDistanceOp.isWithinDistance = function isWithinDistance (g0, g1, distance) {\n var distOp = new DistanceOp(g0, g1, distance);\n return distOp.distance() <= distance\n};\nDistanceOp.nearestPoints = function nearestPoints (g0, g1) {\n var distOp = new DistanceOp(g0, g1);\n return distOp.nearestPoints()\n};\n\nvar PointPairDistance$2 = function PointPairDistance () {\n this._pt = [new Coordinate(), new Coordinate()];\n this._distance = Double.NaN;\n this._isNull = true;\n};\nPointPairDistance$2.prototype.getCoordinates = function getCoordinates () {\n return this._pt\n};\nPointPairDistance$2.prototype.getCoordinate = function getCoordinate (i) {\n return this._pt[i]\n};\nPointPairDistance$2.prototype.setMinimum = function setMinimum () {\n if (arguments.length === 1) {\n var ptDist = arguments[0];\n this.setMinimum(ptDist._pt[0], ptDist._pt[1]);\n } else if (arguments.length === 2) {\n var p0 = arguments[0];\n var p1 = arguments[1];\n if (this._isNull) {\n this.initialize(p0, p1);\n return null\n }\n var dist = p0.distance(p1);\n if (dist < this._distance) { this.initialize(p0, p1, dist); }\n }\n};\nPointPairDistance$2.prototype.initialize = function initialize () {\n if (arguments.length === 0) {\n this._isNull = true;\n } else if (arguments.length === 2) {\n var p0 = arguments[0];\n var p1 = arguments[1];\n this._pt[0].setCoordinate(p0);\n this._pt[1].setCoordinate(p1);\n this._distance = p0.distance(p1);\n this._isNull = false;\n } else if (arguments.length === 3) {\n var p0$1 = arguments[0];\n var p1$1 = arguments[1];\n var distance = arguments[2];\n this._pt[0].setCoordinate(p0$1);\n this._pt[1].setCoordinate(p1$1);\n this._distance = distance;\n this._isNull = false;\n }\n};\nPointPairDistance$2.prototype.toString = function toString () {\n return WKTWriter.toLineString(this._pt[0], this._pt[1])\n};\nPointPairDistance$2.prototype.getDistance = function getDistance () {\n return this._distance\n};\nPointPairDistance$2.prototype.setMaximum = function setMaximum () {\n if (arguments.length === 1) {\n var ptDist = arguments[0];\n this.setMaximum(ptDist._pt[0], ptDist._pt[1]);\n } else if (arguments.length === 2) {\n var p0 = arguments[0];\n var p1 = arguments[1];\n if (this._isNull) {\n this.initialize(p0, p1);\n return null\n }\n var dist = p0.distance(p1);\n if (dist > this._distance) { this.initialize(p0, p1, dist); }\n }\n};\nPointPairDistance$2.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nPointPairDistance$2.prototype.getClass = function getClass () {\n return PointPairDistance$2\n};\n\nvar DistanceToPoint = function DistanceToPoint () {};\n\nDistanceToPoint.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nDistanceToPoint.prototype.getClass = function getClass () {\n return DistanceToPoint\n};\nDistanceToPoint.computeDistance = function computeDistance () {\n if (arguments[2] instanceof PointPairDistance$2 && (arguments[0] instanceof LineString && arguments[1] instanceof Coordinate)) {\n var line = arguments[0];\n var pt = arguments[1];\n var ptDist = arguments[2];\n var tempSegment = new LineSegment();\n var coords = line.getCoordinates();\n for (var i = 0; i < coords.length - 1; i++) {\n tempSegment.setCoordinates(coords[i], coords[i + 1]);\n var closestPt = tempSegment.closestPoint(pt);\n ptDist.setMinimum(closestPt, pt);\n }\n } else if (arguments[2] instanceof PointPairDistance$2 && (arguments[0] instanceof Polygon && arguments[1] instanceof Coordinate)) {\n var poly = arguments[0];\n var pt$1 = arguments[1];\n var ptDist$1 = arguments[2];\n DistanceToPoint.computeDistance(poly.getExteriorRing(), pt$1, ptDist$1);\n for (var i$1 = 0; i$1 < poly.getNumInteriorRing(); i$1++) {\n DistanceToPoint.computeDistance(poly.getInteriorRingN(i$1), pt$1, ptDist$1);\n }\n } else if (arguments[2] instanceof PointPairDistance$2 && (arguments[0] instanceof Geometry && arguments[1] instanceof Coordinate)) {\n var geom = arguments[0];\n var pt$2 = arguments[1];\n var ptDist$2 = arguments[2];\n if (geom instanceof LineString) {\n DistanceToPoint.computeDistance(geom, pt$2, ptDist$2);\n } else if (geom instanceof Polygon) {\n DistanceToPoint.computeDistance(geom, pt$2, ptDist$2);\n } else if (geom instanceof GeometryCollection) {\n var gc = geom;\n for (var i$2 = 0; i$2 < gc.getNumGeometries(); i$2++) {\n var g = gc.getGeometryN(i$2);\n DistanceToPoint.computeDistance(g, pt$2, ptDist$2);\n }\n } else {\n ptDist$2.setMinimum(geom.getCoordinate(), pt$2);\n }\n } else if (arguments[2] instanceof PointPairDistance$2 && (arguments[0] instanceof LineSegment && arguments[1] instanceof Coordinate)) {\n var segment = arguments[0];\n var pt$3 = arguments[1];\n var ptDist$3 = arguments[2];\n var closestPt$1 = segment.closestPoint(pt$3);\n ptDist$3.setMinimum(closestPt$1, pt$3);\n }\n};\n\nvar DiscreteHausdorffDistance = function DiscreteHausdorffDistance () {\n this._g0 = null;\n this._g1 = null;\n this._ptDist = new PointPairDistance$2();\n this._densifyFrac = 0.0;\n var g0 = arguments[0];\n var g1 = arguments[1];\n this._g0 = g0;\n this._g1 = g1;\n};\n\nvar staticAccessors$39 = { MaxPointDistanceFilter: { configurable: true },MaxDensifiedByFractionDistanceFilter: { configurable: true } };\nDiscreteHausdorffDistance.prototype.getCoordinates = function getCoordinates () {\n return this._ptDist.getCoordinates()\n};\nDiscreteHausdorffDistance.prototype.setDensifyFraction = function setDensifyFraction (densifyFrac) {\n if (densifyFrac > 1.0 || densifyFrac <= 0.0) { throw new IllegalArgumentException('Fraction is not in range (0.0 - 1.0]') }\n this._densifyFrac = densifyFrac;\n};\nDiscreteHausdorffDistance.prototype.compute = function compute (g0, g1) {\n this.computeOrientedDistance(g0, g1, this._ptDist);\n this.computeOrientedDistance(g1, g0, this._ptDist);\n};\nDiscreteHausdorffDistance.prototype.distance = function distance () {\n this.compute(this._g0, this._g1);\n return this._ptDist.getDistance()\n};\nDiscreteHausdorffDistance.prototype.computeOrientedDistance = function computeOrientedDistance (discreteGeom, geom, ptDist) {\n var distFilter = new MaxPointDistanceFilter$1(geom);\n discreteGeom.apply(distFilter);\n ptDist.setMaximum(distFilter.getMaxPointDistance());\n if (this._densifyFrac > 0) {\n var fracFilter = new MaxDensifiedByFractionDistanceFilter(geom, this._densifyFrac);\n discreteGeom.apply(fracFilter);\n ptDist.setMaximum(fracFilter.getMaxPointDistance());\n }\n};\nDiscreteHausdorffDistance.prototype.orientedDistance = function orientedDistance () {\n this.computeOrientedDistance(this._g0, this._g1, this._ptDist);\n return this._ptDist.getDistance()\n};\nDiscreteHausdorffDistance.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nDiscreteHausdorffDistance.prototype.getClass = function getClass () {\n return DiscreteHausdorffDistance\n};\nDiscreteHausdorffDistance.distance = function distance () {\n if (arguments.length === 2) {\n var g0 = arguments[0];\n var g1 = arguments[1];\n var dist = new DiscreteHausdorffDistance(g0, g1);\n return dist.distance()\n } else if (arguments.length === 3) {\n var g0$1 = arguments[0];\n var g1$1 = arguments[1];\n var densifyFrac = arguments[2];\n var dist$1 = new DiscreteHausdorffDistance(g0$1, g1$1);\n dist$1.setDensifyFraction(densifyFrac);\n return dist$1.distance()\n }\n};\nstaticAccessors$39.MaxPointDistanceFilter.get = function () { return MaxPointDistanceFilter$1 };\nstaticAccessors$39.MaxDensifiedByFractionDistanceFilter.get = function () { return MaxDensifiedByFractionDistanceFilter };\n\nObject.defineProperties( DiscreteHausdorffDistance, staticAccessors$39 );\n\nvar MaxPointDistanceFilter$1 = function MaxPointDistanceFilter () {\n this._maxPtDist = new PointPairDistance$2();\n this._minPtDist = new PointPairDistance$2();\n this._euclideanDist = new DistanceToPoint();\n this._geom = null;\n var geom = arguments[0];\n this._geom = geom;\n};\nMaxPointDistanceFilter$1.prototype.filter = function filter (pt) {\n this._minPtDist.initialize();\n DistanceToPoint.computeDistance(this._geom, pt, this._minPtDist);\n this._maxPtDist.setMaximum(this._minPtDist);\n};\nMaxPointDistanceFilter$1.prototype.getMaxPointDistance = function getMaxPointDistance () {\n return this._maxPtDist\n};\nMaxPointDistanceFilter$1.prototype.interfaces_ = function interfaces_ () {\n return [CoordinateFilter]\n};\nMaxPointDistanceFilter$1.prototype.getClass = function getClass () {\n return MaxPointDistanceFilter$1\n};\n\nvar MaxDensifiedByFractionDistanceFilter = function MaxDensifiedByFractionDistanceFilter () {\n this._maxPtDist = new PointPairDistance$2();\n this._minPtDist = new PointPairDistance$2();\n this._geom = null;\n this._numSubSegs = 0;\n var geom = arguments[0];\n var fraction = arguments[1];\n this._geom = geom;\n this._numSubSegs = Math.trunc(Math.round(1.0 / fraction));\n};\nMaxDensifiedByFractionDistanceFilter.prototype.filter = function filter (seq, index) {\n var this$1 = this;\n\n if (index === 0) { return null }\n var p0 = seq.getCoordinate(index - 1);\n var p1 = seq.getCoordinate(index);\n var delx = (p1.x - p0.x) / this._numSubSegs;\n var dely = (p1.y - p0.y) / this._numSubSegs;\n for (var i = 0; i < this._numSubSegs; i++) {\n var x = p0.x + i * delx;\n var y = p0.y + i * dely;\n var pt = new Coordinate(x, y);\n this$1._minPtDist.initialize();\n DistanceToPoint.computeDistance(this$1._geom, pt, this$1._minPtDist);\n this$1._maxPtDist.setMaximum(this$1._minPtDist);\n }\n};\nMaxDensifiedByFractionDistanceFilter.prototype.isDone = function isDone () {\n return false\n};\nMaxDensifiedByFractionDistanceFilter.prototype.isGeometryChanged = function isGeometryChanged () {\n return false\n};\nMaxDensifiedByFractionDistanceFilter.prototype.getMaxPointDistance = function getMaxPointDistance () {\n return this._maxPtDist\n};\nMaxDensifiedByFractionDistanceFilter.prototype.interfaces_ = function interfaces_ () {\n return [CoordinateSequenceFilter]\n};\nMaxDensifiedByFractionDistanceFilter.prototype.getClass = function getClass () {\n return MaxDensifiedByFractionDistanceFilter\n};\n\nvar BufferDistanceValidator = function BufferDistanceValidator (input, bufDistance, result) {\n this._minValidDistance = null;\n this._maxValidDistance = null;\n this._minDistanceFound = null;\n this._maxDistanceFound = null;\n this._isValid = true;\n this._errMsg = null;\n this._errorLocation = null;\n this._errorIndicator = null;\n this._input = input || null;\n this._bufDistance = bufDistance || null;\n this._result = result || null;\n};\n\nvar staticAccessors$37 = { VERBOSE: { configurable: true },MAX_DISTANCE_DIFF_FRAC: { configurable: true } };\nBufferDistanceValidator.prototype.checkMaximumDistance = function checkMaximumDistance (input, bufCurve, maxDist) {\n var haus = new DiscreteHausdorffDistance(bufCurve, input);\n haus.setDensifyFraction(0.25);\n this._maxDistanceFound = haus.orientedDistance();\n if (this._maxDistanceFound > maxDist) {\n this._isValid = false;\n var pts = haus.getCoordinates();\n this._errorLocation = pts[1];\n this._errorIndicator = input.getFactory().createLineString(pts);\n this._errMsg = 'Distance between buffer curve and input is too large (' + this._maxDistanceFound + ' at ' + WKTWriter.toLineString(pts[0], pts[1]) + ')';\n }\n};\nBufferDistanceValidator.prototype.isValid = function isValid () {\n var posDistance = Math.abs(this._bufDistance);\n var distDelta = BufferDistanceValidator.MAX_DISTANCE_DIFF_FRAC * posDistance;\n this._minValidDistance = posDistance - distDelta;\n this._maxValidDistance = posDistance + distDelta;\n if (this._input.isEmpty() || this._result.isEmpty()) { return true }\n if (this._bufDistance > 0.0) {\n this.checkPositiveValid();\n } else {\n this.checkNegativeValid();\n }\n if (BufferDistanceValidator.VERBOSE) {\n System.out.println('Min Dist= ' + this._minDistanceFound + ' err= ' + (1.0 - this._minDistanceFound / this._bufDistance) + ' Max Dist= ' + this._maxDistanceFound + ' err= ' + (this._maxDistanceFound / this._bufDistance - 1.0));\n }\n return this._isValid\n};\nBufferDistanceValidator.prototype.checkNegativeValid = function checkNegativeValid () {\n if (!(this._input instanceof Polygon || this._input instanceof MultiPolygon || this._input instanceof GeometryCollection)) {\n return null\n }\n var inputCurve = this.getPolygonLines(this._input);\n this.checkMinimumDistance(inputCurve, this._result, this._minValidDistance);\n if (!this._isValid) { return null }\n this.checkMaximumDistance(inputCurve, this._result, this._maxValidDistance);\n};\nBufferDistanceValidator.prototype.getErrorIndicator = function getErrorIndicator () {\n return this._errorIndicator\n};\nBufferDistanceValidator.prototype.checkMinimumDistance = function checkMinimumDistance (g1, g2, minDist) {\n var distOp = new DistanceOp(g1, g2, minDist);\n this._minDistanceFound = distOp.distance();\n if (this._minDistanceFound < minDist) {\n this._isValid = false;\n var pts = distOp.nearestPoints();\n this._errorLocation = distOp.nearestPoints()[1];\n this._errorIndicator = g1.getFactory().createLineString(pts);\n this._errMsg = 'Distance between buffer curve and input is too small (' + this._minDistanceFound + ' at ' + WKTWriter.toLineString(pts[0], pts[1]) + ' )';\n }\n};\nBufferDistanceValidator.prototype.checkPositiveValid = function checkPositiveValid () {\n var bufCurve = this._result.getBoundary();\n this.checkMinimumDistance(this._input, bufCurve, this._minValidDistance);\n if (!this._isValid) { return null }\n this.checkMaximumDistance(this._input, bufCurve, this._maxValidDistance);\n};\nBufferDistanceValidator.prototype.getErrorLocation = function getErrorLocation () {\n return this._errorLocation\n};\nBufferDistanceValidator.prototype.getPolygonLines = function getPolygonLines (g) {\n var lines = new ArrayList();\n var lineExtracter = new LinearComponentExtracter(lines);\n var polys = PolygonExtracter.getPolygons(g);\n for (var i = polys.iterator(); i.hasNext();) {\n var poly = i.next();\n poly.apply(lineExtracter);\n }\n return g.getFactory().buildGeometry(lines)\n};\nBufferDistanceValidator.prototype.getErrorMessage = function getErrorMessage () {\n return this._errMsg\n};\nBufferDistanceValidator.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nBufferDistanceValidator.prototype.getClass = function getClass () {\n return BufferDistanceValidator\n};\nstaticAccessors$37.VERBOSE.get = function () { return false };\nstaticAccessors$37.MAX_DISTANCE_DIFF_FRAC.get = function () { return 0.012 };\n\nObject.defineProperties( BufferDistanceValidator, staticAccessors$37 );\n\nvar BufferResultValidator = function BufferResultValidator (input, distance, result) {\n this._isValid = true;\n this._errorMsg = null;\n this._errorLocation = null;\n this._errorIndicator = null;\n this._input = input || null;\n this._distance = distance || null;\n this._result = result || null;\n};\n\nvar staticAccessors$40 = { VERBOSE: { configurable: true },MAX_ENV_DIFF_FRAC: { configurable: true } };\nBufferResultValidator.prototype.isValid = function isValid () {\n this.checkPolygonal();\n if (!this._isValid) { return this._isValid }\n this.checkExpectedEmpty();\n if (!this._isValid) { return this._isValid }\n this.checkEnvelope();\n if (!this._isValid) { return this._isValid }\n this.checkArea();\n if (!this._isValid) { return this._isValid }\n this.checkDistance();\n return this._isValid\n};\nBufferResultValidator.prototype.checkEnvelope = function checkEnvelope () {\n if (this._distance < 0.0) { return null }\n var padding = this._distance * BufferResultValidator.MAX_ENV_DIFF_FRAC;\n if (padding === 0.0) { padding = 0.001; }\n var expectedEnv = new Envelope(this._input.getEnvelopeInternal());\n expectedEnv.expandBy(this._distance);\n var bufEnv = new Envelope(this._result.getEnvelopeInternal());\n bufEnv.expandBy(padding);\n if (!bufEnv.contains(expectedEnv)) {\n this._isValid = false;\n this._errorMsg = 'Buffer envelope is incorrect';\n this._errorIndicator = this._input.getFactory().toGeometry(bufEnv);\n }\n this.report('Envelope');\n};\nBufferResultValidator.prototype.checkDistance = function checkDistance () {\n var distValid = new BufferDistanceValidator(this._input, this._distance, this._result);\n if (!distValid.isValid()) {\n this._isValid = false;\n this._errorMsg = distValid.getErrorMessage();\n this._errorLocation = distValid.getErrorLocation();\n this._errorIndicator = distValid.getErrorIndicator();\n }\n this.report('Distance');\n};\nBufferResultValidator.prototype.checkArea = function checkArea () {\n var inputArea = this._input.getArea();\n var resultArea = this._result.getArea();\n if (this._distance > 0.0 && inputArea > resultArea) {\n this._isValid = false;\n this._errorMsg = 'Area of positive buffer is smaller than input';\n this._errorIndicator = this._result;\n }\n if (this._distance < 0.0 && inputArea < resultArea) {\n this._isValid = false;\n this._errorMsg = 'Area of negative buffer is larger than input';\n this._errorIndicator = this._result;\n }\n this.report('Area');\n};\nBufferResultValidator.prototype.checkPolygonal = function checkPolygonal () {\n if (!(this._result instanceof Polygon || this._result instanceof MultiPolygon)) { this._isValid = false; }\n this._errorMsg = 'Result is not polygonal';\n this._errorIndicator = this._result;\n this.report('Polygonal');\n};\nBufferResultValidator.prototype.getErrorIndicator = function getErrorIndicator () {\n return this._errorIndicator\n};\nBufferResultValidator.prototype.getErrorLocation = function getErrorLocation () {\n return this._errorLocation\n};\nBufferResultValidator.prototype.checkExpectedEmpty = function checkExpectedEmpty () {\n if (this._input.getDimension() >= 2) { return null }\n if (this._distance > 0.0) { return null }\n if (!this._result.isEmpty()) {\n this._isValid = false;\n this._errorMsg = 'Result is non-empty';\n this._errorIndicator = this._result;\n }\n this.report('ExpectedEmpty');\n};\nBufferResultValidator.prototype.report = function report (checkName) {\n if (!BufferResultValidator.VERBOSE) { return null }\n System.out.println('Check ' + checkName + ': ' + (this._isValid ? 'passed' : 'FAILED'));\n};\nBufferResultValidator.prototype.getErrorMessage = function getErrorMessage () {\n return this._errorMsg\n};\nBufferResultValidator.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nBufferResultValidator.prototype.getClass = function getClass () {\n return BufferResultValidator\n};\nBufferResultValidator.isValidMsg = function isValidMsg (g, distance, result) {\n var validator = new BufferResultValidator(g, distance, result);\n if (!validator.isValid()) { return validator.getErrorMessage() }\n return null\n};\nBufferResultValidator.isValid = function isValid (g, distance, result) {\n var validator = new BufferResultValidator(g, distance, result);\n if (validator.isValid()) { return true }\n return false\n};\nstaticAccessors$40.VERBOSE.get = function () { return false };\nstaticAccessors$40.MAX_ENV_DIFF_FRAC.get = function () { return 0.012 };\n\nObject.defineProperties( BufferResultValidator, staticAccessors$40 );\n\n// operation.buffer\n\nvar BasicSegmentString = function BasicSegmentString () {\n this._pts = null;\n this._data = null;\n var pts = arguments[0];\n var data = arguments[1];\n this._pts = pts;\n this._data = data;\n};\nBasicSegmentString.prototype.getCoordinates = function getCoordinates () {\n return this._pts\n};\nBasicSegmentString.prototype.size = function size () {\n return this._pts.length\n};\nBasicSegmentString.prototype.getCoordinate = function getCoordinate (i) {\n return this._pts[i]\n};\nBasicSegmentString.prototype.isClosed = function isClosed () {\n return this._pts[0].equals(this._pts[this._pts.length - 1])\n};\nBasicSegmentString.prototype.getSegmentOctant = function getSegmentOctant (index) {\n if (index === this._pts.length - 1) { return -1 }\n return Octant.octant(this.getCoordinate(index), this.getCoordinate(index + 1))\n};\nBasicSegmentString.prototype.setData = function setData (data) {\n this._data = data;\n};\nBasicSegmentString.prototype.getData = function getData () {\n return this._data\n};\nBasicSegmentString.prototype.toString = function toString () {\n return WKTWriter.toLineString(new CoordinateArraySequence(this._pts))\n};\nBasicSegmentString.prototype.interfaces_ = function interfaces_ () {\n return [SegmentString]\n};\nBasicSegmentString.prototype.getClass = function getClass () {\n return BasicSegmentString\n};\n\nvar InteriorIntersectionFinder = function InteriorIntersectionFinder () {\n this._findAllIntersections = false;\n this._isCheckEndSegmentsOnly = false;\n this._li = null;\n this._interiorIntersection = null;\n this._intSegments = null;\n this._intersections = new ArrayList();\n this._intersectionCount = 0;\n this._keepIntersections = true;\n var li = arguments[0];\n this._li = li;\n this._interiorIntersection = null;\n};\nInteriorIntersectionFinder.prototype.getInteriorIntersection = function getInteriorIntersection () {\n return this._interiorIntersection\n};\nInteriorIntersectionFinder.prototype.setCheckEndSegmentsOnly = function setCheckEndSegmentsOnly (isCheckEndSegmentsOnly) {\n this._isCheckEndSegmentsOnly = isCheckEndSegmentsOnly;\n};\nInteriorIntersectionFinder.prototype.getIntersectionSegments = function getIntersectionSegments () {\n return this._intSegments\n};\nInteriorIntersectionFinder.prototype.count = function count () {\n return this._intersectionCount\n};\nInteriorIntersectionFinder.prototype.getIntersections = function getIntersections () {\n return this._intersections\n};\nInteriorIntersectionFinder.prototype.setFindAllIntersections = function setFindAllIntersections (findAllIntersections) {\n this._findAllIntersections = findAllIntersections;\n};\nInteriorIntersectionFinder.prototype.setKeepIntersections = function setKeepIntersections (keepIntersections) {\n this._keepIntersections = keepIntersections;\n};\nInteriorIntersectionFinder.prototype.processIntersections = function processIntersections (e0, segIndex0, e1, segIndex1) {\n if (!this._findAllIntersections && this.hasIntersection()) { return null }\n if (e0 === e1 && segIndex0 === segIndex1) { return null }\n if (this._isCheckEndSegmentsOnly) {\n var isEndSegPresent = this.isEndSegment(e0, segIndex0) || this.isEndSegment(e1, segIndex1);\n if (!isEndSegPresent) { return null }\n }\n var p00 = e0.getCoordinates()[segIndex0];\n var p01 = e0.getCoordinates()[segIndex0 + 1];\n var p10 = e1.getCoordinates()[segIndex1];\n var p11 = e1.getCoordinates()[segIndex1 + 1];\n this._li.computeIntersection(p00, p01, p10, p11);\n if (this._li.hasIntersection()) {\n if (this._li.isInteriorIntersection()) {\n this._intSegments = new Array(4).fill(null);\n this._intSegments[0] = p00;\n this._intSegments[1] = p01;\n this._intSegments[2] = p10;\n this._intSegments[3] = p11;\n this._interiorIntersection = this._li.getIntersection(0);\n if (this._keepIntersections) { this._intersections.add(this._interiorIntersection); }\n this._intersectionCount++;\n }\n }\n};\nInteriorIntersectionFinder.prototype.isEndSegment = function isEndSegment (segStr, index) {\n if (index === 0) { return true }\n if (index >= segStr.size() - 2) { return true }\n return false\n};\nInteriorIntersectionFinder.prototype.hasIntersection = function hasIntersection () {\n return this._interiorIntersection !== null\n};\nInteriorIntersectionFinder.prototype.isDone = function isDone () {\n if (this._findAllIntersections) { return false }\n return this._interiorIntersection !== null\n};\nInteriorIntersectionFinder.prototype.interfaces_ = function interfaces_ () {\n return [SegmentIntersector]\n};\nInteriorIntersectionFinder.prototype.getClass = function getClass () {\n return InteriorIntersectionFinder\n};\nInteriorIntersectionFinder.createAllIntersectionsFinder = function createAllIntersectionsFinder (li) {\n var finder = new InteriorIntersectionFinder(li);\n finder.setFindAllIntersections(true);\n return finder\n};\nInteriorIntersectionFinder.createAnyIntersectionFinder = function createAnyIntersectionFinder (li) {\n return new InteriorIntersectionFinder(li)\n};\nInteriorIntersectionFinder.createIntersectionCounter = function createIntersectionCounter (li) {\n var finder = new InteriorIntersectionFinder(li);\n finder.setFindAllIntersections(true);\n finder.setKeepIntersections(false);\n return finder\n};\n\nvar FastNodingValidator = function FastNodingValidator () {\n this._li = new RobustLineIntersector();\n this._segStrings = null;\n this._findAllIntersections = false;\n this._segInt = null;\n this._isValid = true;\n var segStrings = arguments[0];\n this._segStrings = segStrings;\n};\nFastNodingValidator.prototype.execute = function execute () {\n if (this._segInt !== null) { return null }\n this.checkInteriorIntersections();\n};\nFastNodingValidator.prototype.getIntersections = function getIntersections () {\n return this._segInt.getIntersections()\n};\nFastNodingValidator.prototype.isValid = function isValid () {\n this.execute();\n return this._isValid\n};\nFastNodingValidator.prototype.setFindAllIntersections = function setFindAllIntersections (findAllIntersections) {\n this._findAllIntersections = findAllIntersections;\n};\nFastNodingValidator.prototype.checkInteriorIntersections = function checkInteriorIntersections () {\n this._isValid = true;\n this._segInt = new InteriorIntersectionFinder(this._li);\n this._segInt.setFindAllIntersections(this._findAllIntersections);\n var noder = new MCIndexNoder();\n noder.setSegmentIntersector(this._segInt);\n noder.computeNodes(this._segStrings);\n if (this._segInt.hasIntersection()) {\n this._isValid = false;\n return null\n }\n};\nFastNodingValidator.prototype.checkValid = function checkValid () {\n this.execute();\n if (!this._isValid) { throw new TopologyException(this.getErrorMessage(), this._segInt.getInteriorIntersection()) }\n};\nFastNodingValidator.prototype.getErrorMessage = function getErrorMessage () {\n if (this._isValid) { return 'no intersections found' }\n var intSegs = this._segInt.getIntersectionSegments();\n return 'found non-noded intersection between ' + WKTWriter.toLineString(intSegs[0], intSegs[1]) + ' and ' + WKTWriter.toLineString(intSegs[2], intSegs[3])\n};\nFastNodingValidator.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nFastNodingValidator.prototype.getClass = function getClass () {\n return FastNodingValidator\n};\nFastNodingValidator.computeIntersections = function computeIntersections (segStrings) {\n var nv = new FastNodingValidator(segStrings);\n nv.setFindAllIntersections(true);\n nv.isValid();\n return nv.getIntersections()\n};\n\nvar EdgeNodingValidator = function EdgeNodingValidator () {\n this._nv = null;\n var edges = arguments[0];\n this._nv = new FastNodingValidator(EdgeNodingValidator.toSegmentStrings(edges));\n};\nEdgeNodingValidator.prototype.checkValid = function checkValid () {\n this._nv.checkValid();\n};\nEdgeNodingValidator.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nEdgeNodingValidator.prototype.getClass = function getClass () {\n return EdgeNodingValidator\n};\nEdgeNodingValidator.toSegmentStrings = function toSegmentStrings (edges) {\n var segStrings = new ArrayList();\n for (var i = edges.iterator(); i.hasNext();) {\n var e = i.next();\n segStrings.add(new BasicSegmentString(e.getCoordinates(), e));\n }\n return segStrings\n};\nEdgeNodingValidator.checkValid = function checkValid (edges) {\n var validator = new EdgeNodingValidator(edges);\n validator.checkValid();\n};\n\nvar GeometryCollectionMapper = function GeometryCollectionMapper (mapOp) {\n this._mapOp = mapOp;\n};\nGeometryCollectionMapper.prototype.map = function map (gc) {\n var this$1 = this;\n\n var mapped = new ArrayList();\n for (var i = 0; i < gc.getNumGeometries(); i++) {\n var g = this$1._mapOp.map(gc.getGeometryN(i));\n if (!g.isEmpty()) { mapped.add(g); }\n }\n return gc.getFactory().createGeometryCollection(GeometryFactory.toGeometryArray(mapped))\n};\nGeometryCollectionMapper.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nGeometryCollectionMapper.prototype.getClass = function getClass () {\n return GeometryCollectionMapper\n};\nGeometryCollectionMapper.map = function map (gc, op) {\n var mapper = new GeometryCollectionMapper(op);\n return mapper.map(gc)\n};\n\nvar LineBuilder = function LineBuilder () {\n this._op = null;\n this._geometryFactory = null;\n this._ptLocator = null;\n this._lineEdgesList = new ArrayList();\n this._resultLineList = new ArrayList();\n var op = arguments[0];\n var geometryFactory = arguments[1];\n var ptLocator = arguments[2];\n this._op = op;\n this._geometryFactory = geometryFactory;\n this._ptLocator = ptLocator;\n};\nLineBuilder.prototype.collectLines = function collectLines (opCode) {\n var this$1 = this;\n\n for (var it = this._op.getGraph().getEdgeEnds().iterator(); it.hasNext();) {\n var de = it.next();\n this$1.collectLineEdge(de, opCode, this$1._lineEdgesList);\n this$1.collectBoundaryTouchEdge(de, opCode, this$1._lineEdgesList);\n }\n};\nLineBuilder.prototype.labelIsolatedLine = function labelIsolatedLine (e, targetIndex) {\n var loc = this._ptLocator.locate(e.getCoordinate(), this._op.getArgGeometry(targetIndex));\n e.getLabel().setLocation(targetIndex, loc);\n};\nLineBuilder.prototype.build = function build (opCode) {\n this.findCoveredLineEdges();\n this.collectLines(opCode);\n this.buildLines(opCode);\n return this._resultLineList\n};\nLineBuilder.prototype.collectLineEdge = function collectLineEdge (de, opCode, edges) {\n var label = de.getLabel();\n var e = de.getEdge();\n if (de.isLineEdge()) {\n if (!de.isVisited() && OverlayOp.isResultOfOp(label, opCode) && !e.isCovered()) {\n edges.add(e);\n de.setVisitedEdge(true);\n }\n }\n};\nLineBuilder.prototype.findCoveredLineEdges = function findCoveredLineEdges () {\n var this$1 = this;\n\n for (var nodeit = this._op.getGraph().getNodes().iterator(); nodeit.hasNext();) {\n var node = nodeit.next();\n node.getEdges().findCoveredLineEdges();\n }\n for (var it = this._op.getGraph().getEdgeEnds().iterator(); it.hasNext();) {\n var de = it.next();\n var e = de.getEdge();\n if (de.isLineEdge() && !e.isCoveredSet()) {\n var isCovered = this$1._op.isCoveredByA(de.getCoordinate());\n e.setCovered(isCovered);\n }\n }\n};\nLineBuilder.prototype.labelIsolatedLines = function labelIsolatedLines (edgesList) {\n var this$1 = this;\n\n for (var it = edgesList.iterator(); it.hasNext();) {\n var e = it.next();\n var label = e.getLabel();\n if (e.isIsolated()) {\n if (label.isNull(0)) { this$1.labelIsolatedLine(e, 0); } else { this$1.labelIsolatedLine(e, 1); }\n }\n }\n};\nLineBuilder.prototype.buildLines = function buildLines (opCode) {\n var this$1 = this;\n\n for (var it = this._lineEdgesList.iterator(); it.hasNext();) {\n var e = it.next();\n // const label = e.getLabel()\n var line = this$1._geometryFactory.createLineString(e.getCoordinates());\n this$1._resultLineList.add(line);\n e.setInResult(true);\n }\n};\nLineBuilder.prototype.collectBoundaryTouchEdge = function collectBoundaryTouchEdge (de, opCode, edges) {\n var label = de.getLabel();\n if (de.isLineEdge()) { return null }\n if (de.isVisited()) { return null }\n if (de.isInteriorAreaEdge()) { return null }\n if (de.getEdge().isInResult()) { return null }\n Assert.isTrue(!(de.isInResult() || de.getSym().isInResult()) || !de.getEdge().isInResult());\n if (OverlayOp.isResultOfOp(label, opCode) && opCode === OverlayOp.INTERSECTION) {\n edges.add(de.getEdge());\n de.setVisitedEdge(true);\n }\n};\nLineBuilder.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nLineBuilder.prototype.getClass = function getClass () {\n return LineBuilder\n};\n\nvar PointBuilder = function PointBuilder () {\n this._op = null;\n this._geometryFactory = null;\n this._resultPointList = new ArrayList();\n var op = arguments[0];\n var geometryFactory = arguments[1];\n // const ptLocator = arguments[2]\n this._op = op;\n this._geometryFactory = geometryFactory;\n};\nPointBuilder.prototype.filterCoveredNodeToPoint = function filterCoveredNodeToPoint (n) {\n var coord = n.getCoordinate();\n if (!this._op.isCoveredByLA(coord)) {\n var pt = this._geometryFactory.createPoint(coord);\n this._resultPointList.add(pt);\n }\n};\nPointBuilder.prototype.extractNonCoveredResultNodes = function extractNonCoveredResultNodes (opCode) {\n var this$1 = this;\n\n for (var nodeit = this._op.getGraph().getNodes().iterator(); nodeit.hasNext();) {\n var n = nodeit.next();\n if (n.isInResult()) { continue }\n if (n.isIncidentEdgeInResult()) { continue }\n if (n.getEdges().getDegree() === 0 || opCode === OverlayOp.INTERSECTION) {\n var label = n.getLabel();\n if (OverlayOp.isResultOfOp(label, opCode)) {\n this$1.filterCoveredNodeToPoint(n);\n }\n }\n }\n};\nPointBuilder.prototype.build = function build (opCode) {\n this.extractNonCoveredResultNodes(opCode);\n return this._resultPointList\n};\nPointBuilder.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nPointBuilder.prototype.getClass = function getClass () {\n return PointBuilder\n};\n\nvar GeometryTransformer = function GeometryTransformer () {\n this._inputGeom = null;\n this._factory = null;\n this._pruneEmptyGeometry = true;\n this._preserveGeometryCollectionType = true;\n this._preserveCollections = false;\n this._preserveType = false;\n};\nGeometryTransformer.prototype.transformPoint = function transformPoint (geom, parent) {\n return this._factory.createPoint(this.transformCoordinates(geom.getCoordinateSequence(), geom))\n};\nGeometryTransformer.prototype.transformPolygon = function transformPolygon (geom, parent) {\n var this$1 = this;\n\n var isAllValidLinearRings = true;\n var shell = this.transformLinearRing(geom.getExteriorRing(), geom);\n if (shell === null || !(shell instanceof LinearRing) || shell.isEmpty()) { isAllValidLinearRings = false; }\n var holes = new ArrayList();\n for (var i = 0; i < geom.getNumInteriorRing(); i++) {\n var hole = this$1.transformLinearRing(geom.getInteriorRingN(i), geom);\n if (hole === null || hole.isEmpty()) {\n continue\n }\n if (!(hole instanceof LinearRing)) { isAllValidLinearRings = false; }\n holes.add(hole);\n }\n if (isAllValidLinearRings) { return this._factory.createPolygon(shell, holes.toArray([])); } else {\n var components = new ArrayList();\n if (shell !== null) { components.add(shell); }\n components.addAll(holes);\n return this._factory.buildGeometry(components)\n }\n};\nGeometryTransformer.prototype.createCoordinateSequence = function createCoordinateSequence (coords) {\n return this._factory.getCoordinateSequenceFactory().create(coords)\n};\nGeometryTransformer.prototype.getInputGeometry = function getInputGeometry () {\n return this._inputGeom\n};\nGeometryTransformer.prototype.transformMultiLineString = function transformMultiLineString (geom, parent) {\n var this$1 = this;\n\n var transGeomList = new ArrayList();\n for (var i = 0; i < geom.getNumGeometries(); i++) {\n var transformGeom = this$1.transformLineString(geom.getGeometryN(i), geom);\n if (transformGeom === null) { continue }\n if (transformGeom.isEmpty()) { continue }\n transGeomList.add(transformGeom);\n }\n return this._factory.buildGeometry(transGeomList)\n};\nGeometryTransformer.prototype.transformCoordinates = function transformCoordinates (coords, parent) {\n return this.copy(coords)\n};\nGeometryTransformer.prototype.transformLineString = function transformLineString (geom, parent) {\n return this._factory.createLineString(this.transformCoordinates(geom.getCoordinateSequence(), geom))\n};\nGeometryTransformer.prototype.transformMultiPoint = function transformMultiPoint (geom, parent) {\n var this$1 = this;\n\n var transGeomList = new ArrayList();\n for (var i = 0; i < geom.getNumGeometries(); i++) {\n var transformGeom = this$1.transformPoint(geom.getGeometryN(i), geom);\n if (transformGeom === null) { continue }\n if (transformGeom.isEmpty()) { continue }\n transGeomList.add(transformGeom);\n }\n return this._factory.buildGeometry(transGeomList)\n};\nGeometryTransformer.prototype.transformMultiPolygon = function transformMultiPolygon (geom, parent) {\n var this$1 = this;\n\n var transGeomList = new ArrayList();\n for (var i = 0; i < geom.getNumGeometries(); i++) {\n var transformGeom = this$1.transformPolygon(geom.getGeometryN(i), geom);\n if (transformGeom === null) { continue }\n if (transformGeom.isEmpty()) { continue }\n transGeomList.add(transformGeom);\n }\n return this._factory.buildGeometry(transGeomList)\n};\nGeometryTransformer.prototype.copy = function copy (seq) {\n return seq.copy()\n};\nGeometryTransformer.prototype.transformGeometryCollection = function transformGeometryCollection (geom, parent) {\n var this$1 = this;\n\n var transGeomList = new ArrayList();\n for (var i = 0; i < geom.getNumGeometries(); i++) {\n var transformGeom = this$1.transform(geom.getGeometryN(i));\n if (transformGeom === null) { continue }\n if (this$1._pruneEmptyGeometry && transformGeom.isEmpty()) { continue }\n transGeomList.add(transformGeom);\n }\n if (this._preserveGeometryCollectionType) { return this._factory.createGeometryCollection(GeometryFactory.toGeometryArray(transGeomList)) }\n return this._factory.buildGeometry(transGeomList)\n};\nGeometryTransformer.prototype.transform = function transform (inputGeom) {\n this._inputGeom = inputGeom;\n this._factory = inputGeom.getFactory();\n if (inputGeom instanceof Point) { return this.transformPoint(inputGeom, null) }\n if (inputGeom instanceof MultiPoint) { return this.transformMultiPoint(inputGeom, null) }\n if (inputGeom instanceof LinearRing) { return this.transformLinearRing(inputGeom, null) }\n if (inputGeom instanceof LineString) { return this.transformLineString(inputGeom, null) }\n if (inputGeom instanceof MultiLineString) { return this.transformMultiLineString(inputGeom, null) }\n if (inputGeom instanceof Polygon) { return this.transformPolygon(inputGeom, null) }\n if (inputGeom instanceof MultiPolygon) { return this.transformMultiPolygon(inputGeom, null) }\n if (inputGeom instanceof GeometryCollection) { return this.transformGeometryCollection(inputGeom, null) }\n throw new IllegalArgumentException('Unknown Geometry subtype: ' + inputGeom.getClass().getName())\n};\nGeometryTransformer.prototype.transformLinearRing = function transformLinearRing (geom, parent) {\n var seq = this.transformCoordinates(geom.getCoordinateSequence(), geom);\n if (seq === null) { return this._factory.createLinearRing(null) }\n var seqSize = seq.size();\n if (seqSize > 0 && seqSize < 4 && !this._preserveType) { return this._factory.createLineString(seq) }\n return this._factory.createLinearRing(seq)\n};\nGeometryTransformer.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nGeometryTransformer.prototype.getClass = function getClass () {\n return GeometryTransformer\n};\n\nvar LineStringSnapper = function LineStringSnapper () {\n this._snapTolerance = 0.0;\n this._srcPts = null;\n this._seg = new LineSegment();\n this._allowSnappingToSourceVertices = false;\n this._isClosed = false;\n if (arguments[0] instanceof LineString && typeof arguments[1] === 'number') {\n var srcLine = arguments[0];\n var snapTolerance = arguments[1];\n LineStringSnapper.call(this, srcLine.getCoordinates(), snapTolerance);\n } else if (arguments[0] instanceof Array && typeof arguments[1] === 'number') {\n var srcPts = arguments[0];\n var snapTolerance$1 = arguments[1];\n this._srcPts = srcPts;\n this._isClosed = LineStringSnapper.isClosed(srcPts);\n this._snapTolerance = snapTolerance$1;\n }\n};\nLineStringSnapper.prototype.snapVertices = function snapVertices (srcCoords, snapPts) {\n var this$1 = this;\n\n var end = this._isClosed ? srcCoords.size() - 1 : srcCoords.size();\n for (var i = 0; i < end; i++) {\n var srcPt = srcCoords.get(i);\n var snapVert = this$1.findSnapForVertex(srcPt, snapPts);\n if (snapVert !== null) {\n srcCoords.set(i, new Coordinate(snapVert));\n if (i === 0 && this$1._isClosed) { srcCoords.set(srcCoords.size() - 1, new Coordinate(snapVert)); }\n }\n }\n};\nLineStringSnapper.prototype.findSnapForVertex = function findSnapForVertex (pt, snapPts) {\n var this$1 = this;\n\n for (var i = 0; i < snapPts.length; i++) {\n if (pt.equals2D(snapPts[i])) { return null }\n if (pt.distance(snapPts[i]) < this$1._snapTolerance) { return snapPts[i] }\n }\n return null\n};\nLineStringSnapper.prototype.snapTo = function snapTo (snapPts) {\n var coordList = new CoordinateList(this._srcPts);\n this.snapVertices(coordList, snapPts);\n this.snapSegments(coordList, snapPts);\n var newPts = coordList.toCoordinateArray();\n return newPts\n};\nLineStringSnapper.prototype.snapSegments = function snapSegments (srcCoords, snapPts) {\n var this$1 = this;\n\n if (snapPts.length === 0) { return null }\n var distinctPtCount = snapPts.length;\n if (snapPts[0].equals2D(snapPts[snapPts.length - 1])) { distinctPtCount = snapPts.length - 1; }\n for (var i = 0; i < distinctPtCount; i++) {\n var snapPt = snapPts[i];\n var index = this$1.findSegmentIndexToSnap(snapPt, srcCoords);\n if (index >= 0) {\n srcCoords.add(index + 1, new Coordinate(snapPt), false);\n }\n }\n};\nLineStringSnapper.prototype.findSegmentIndexToSnap = function findSegmentIndexToSnap (snapPt, srcCoords) {\n var this$1 = this;\n\n var minDist = Double.MAX_VALUE;\n var snapIndex = -1;\n for (var i = 0; i < srcCoords.size() - 1; i++) {\n this$1._seg.p0 = srcCoords.get(i);\n this$1._seg.p1 = srcCoords.get(i + 1);\n if (this$1._seg.p0.equals2D(snapPt) || this$1._seg.p1.equals2D(snapPt)) {\n if (this$1._allowSnappingToSourceVertices) { continue; } else { return -1 }\n }\n var dist = this$1._seg.distance(snapPt);\n if (dist < this$1._snapTolerance && dist < minDist) {\n minDist = dist;\n snapIndex = i;\n }\n }\n return snapIndex\n};\nLineStringSnapper.prototype.setAllowSnappingToSourceVertices = function setAllowSnappingToSourceVertices (allowSnappingToSourceVertices) {\n this._allowSnappingToSourceVertices = allowSnappingToSourceVertices;\n};\nLineStringSnapper.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nLineStringSnapper.prototype.getClass = function getClass () {\n return LineStringSnapper\n};\nLineStringSnapper.isClosed = function isClosed (pts) {\n if (pts.length <= 1) { return false }\n return pts[0].equals2D(pts[pts.length - 1])\n};\n\nvar GeometrySnapper = function GeometrySnapper (srcGeom) {\n this._srcGeom = srcGeom || null;\n};\n\nvar staticAccessors$41 = { SNAP_PRECISION_FACTOR: { configurable: true } };\nGeometrySnapper.prototype.snapTo = function snapTo (snapGeom, snapTolerance) {\n var snapPts = this.extractTargetCoordinates(snapGeom);\n var snapTrans = new SnapTransformer(snapTolerance, snapPts);\n return snapTrans.transform(this._srcGeom)\n};\nGeometrySnapper.prototype.snapToSelf = function snapToSelf (snapTolerance, cleanResult) {\n var snapPts = this.extractTargetCoordinates(this._srcGeom);\n var snapTrans = new SnapTransformer(snapTolerance, snapPts, true);\n var snappedGeom = snapTrans.transform(this._srcGeom);\n var result = snappedGeom;\n if (cleanResult && hasInterface(result, Polygonal)) {\n result = snappedGeom.buffer(0);\n }\n return result\n};\nGeometrySnapper.prototype.computeSnapTolerance = function computeSnapTolerance (ringPts) {\n var minSegLen = this.computeMinimumSegmentLength(ringPts);\n var snapTol = minSegLen / 10;\n return snapTol\n};\nGeometrySnapper.prototype.extractTargetCoordinates = function extractTargetCoordinates (g) {\n var ptSet = new TreeSet();\n var pts = g.getCoordinates();\n for (var i = 0; i < pts.length; i++) {\n ptSet.add(pts[i]);\n }\n return ptSet.toArray(new Array(0).fill(null))\n};\nGeometrySnapper.prototype.computeMinimumSegmentLength = function computeMinimumSegmentLength (pts) {\n var minSegLen = Double.MAX_VALUE;\n for (var i = 0; i < pts.length - 1; i++) {\n var segLen = pts[i].distance(pts[i + 1]);\n if (segLen < minSegLen) { minSegLen = segLen; }\n }\n return minSegLen\n};\nGeometrySnapper.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nGeometrySnapper.prototype.getClass = function getClass () {\n return GeometrySnapper\n};\nGeometrySnapper.snap = function snap (g0, g1, snapTolerance) {\n var snapGeom = new Array(2).fill(null);\n var snapper0 = new GeometrySnapper(g0);\n snapGeom[0] = snapper0.snapTo(g1, snapTolerance);\n var snapper1 = new GeometrySnapper(g1);\n snapGeom[1] = snapper1.snapTo(snapGeom[0], snapTolerance);\n return snapGeom\n};\nGeometrySnapper.computeOverlaySnapTolerance = function computeOverlaySnapTolerance () {\n if (arguments.length === 1) {\n var g = arguments[0];\n var snapTolerance = GeometrySnapper.computeSizeBasedSnapTolerance(g);\n var pm = g.getPrecisionModel();\n if (pm.getType() === PrecisionModel.FIXED) {\n var fixedSnapTol = 1 / pm.getScale() * 2 / 1.415;\n if (fixedSnapTol > snapTolerance) { snapTolerance = fixedSnapTol; }\n }\n return snapTolerance\n } else if (arguments.length === 2) {\n var g0 = arguments[0];\n var g1 = arguments[1];\n return Math.min(GeometrySnapper.computeOverlaySnapTolerance(g0), GeometrySnapper.computeOverlaySnapTolerance(g1))\n }\n};\nGeometrySnapper.computeSizeBasedSnapTolerance = function computeSizeBasedSnapTolerance (g) {\n var env = g.getEnvelopeInternal();\n var minDimension = Math.min(env.getHeight(), env.getWidth());\n var snapTol = minDimension * GeometrySnapper.SNAP_PRECISION_FACTOR;\n return snapTol\n};\nGeometrySnapper.snapToSelf = function snapToSelf (geom, snapTolerance, cleanResult) {\n var snapper0 = new GeometrySnapper(geom);\n return snapper0.snapToSelf(snapTolerance, cleanResult)\n};\nstaticAccessors$41.SNAP_PRECISION_FACTOR.get = function () { return 1e-9 };\n\nObject.defineProperties( GeometrySnapper, staticAccessors$41 );\n\nvar SnapTransformer = (function (GeometryTransformer$$1) {\n function SnapTransformer (snapTolerance, snapPts, isSelfSnap) {\n GeometryTransformer$$1.call(this);\n this._snapTolerance = snapTolerance || null;\n this._snapPts = snapPts || null;\n this._isSelfSnap = (isSelfSnap !== undefined) ? isSelfSnap : false;\n }\n\n if ( GeometryTransformer$$1 ) SnapTransformer.__proto__ = GeometryTransformer$$1;\n SnapTransformer.prototype = Object.create( GeometryTransformer$$1 && GeometryTransformer$$1.prototype );\n SnapTransformer.prototype.constructor = SnapTransformer;\n SnapTransformer.prototype.snapLine = function snapLine (srcPts, snapPts) {\n var snapper = new LineStringSnapper(srcPts, this._snapTolerance);\n snapper.setAllowSnappingToSourceVertices(this._isSelfSnap);\n return snapper.snapTo(snapPts)\n };\n SnapTransformer.prototype.transformCoordinates = function transformCoordinates (coords, parent) {\n var srcPts = coords.toCoordinateArray();\n var newPts = this.snapLine(srcPts, this._snapPts);\n return this._factory.getCoordinateSequenceFactory().create(newPts)\n };\n SnapTransformer.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n SnapTransformer.prototype.getClass = function getClass () {\n return SnapTransformer\n };\n\n return SnapTransformer;\n}(GeometryTransformer));\n\nvar CommonBits = function CommonBits () {\n this._isFirst = true;\n this._commonMantissaBitsCount = 53;\n this._commonBits = 0;\n this._commonSignExp = null;\n};\nCommonBits.prototype.getCommon = function getCommon () {\n return Double.longBitsToDouble(this._commonBits)\n};\nCommonBits.prototype.add = function add (num) {\n var numBits = Double.doubleToLongBits(num);\n if (this._isFirst) {\n this._commonBits = numBits;\n this._commonSignExp = CommonBits.signExpBits(this._commonBits);\n this._isFirst = false;\n return null\n }\n var numSignExp = CommonBits.signExpBits(numBits);\n if (numSignExp !== this._commonSignExp) {\n this._commonBits = 0;\n return null\n }\n this._commonMantissaBitsCount = CommonBits.numCommonMostSigMantissaBits(this._commonBits, numBits);\n this._commonBits = CommonBits.zeroLowerBits(this._commonBits, 64 - (12 + this._commonMantissaBitsCount));\n};\nCommonBits.prototype.toString = function toString () {\n if (arguments.length === 1) {\n var bits = arguments[0];\n var x = Double.longBitsToDouble(bits);\n var numStr = Double.toBinaryString(bits);\n var padStr = '0000000000000000000000000000000000000000000000000000000000000000' + numStr;\n var bitStr = padStr.substring(padStr.length - 64);\n var str = bitStr.substring(0, 1) + ' ' + bitStr.substring(1, 12) + '(exp) ' + bitStr.substring(12) + ' [ ' + x + ' ]';\n return str\n }\n};\nCommonBits.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nCommonBits.prototype.getClass = function getClass () {\n return CommonBits\n};\nCommonBits.getBit = function getBit (bits, i) {\n var mask = 1 << i;\n return (bits & mask) !== 0 ? 1 : 0\n};\nCommonBits.signExpBits = function signExpBits (num) {\n return num >> 52\n};\nCommonBits.zeroLowerBits = function zeroLowerBits (bits, nBits) {\n var invMask = (1 << nBits) - 1;\n var mask = ~invMask;\n var zeroed = bits & mask;\n return zeroed\n};\nCommonBits.numCommonMostSigMantissaBits = function numCommonMostSigMantissaBits (num1, num2) {\n var count = 0;\n for (var i = 52; i >= 0; i--) {\n if (CommonBits.getBit(num1, i) !== CommonBits.getBit(num2, i)) { return count }\n count++;\n }\n return 52\n};\n\nvar CommonBitsRemover = function CommonBitsRemover () {\n this._commonCoord = null;\n this._ccFilter = new CommonCoordinateFilter();\n};\n\nvar staticAccessors$42 = { CommonCoordinateFilter: { configurable: true },Translater: { configurable: true } };\nCommonBitsRemover.prototype.addCommonBits = function addCommonBits (geom) {\n var trans = new Translater(this._commonCoord);\n geom.apply(trans);\n geom.geometryChanged();\n};\nCommonBitsRemover.prototype.removeCommonBits = function removeCommonBits (geom) {\n if (this._commonCoord.x === 0.0 && this._commonCoord.y === 0.0) { return geom }\n var invCoord = new Coordinate(this._commonCoord);\n invCoord.x = -invCoord.x;\n invCoord.y = -invCoord.y;\n var trans = new Translater(invCoord);\n geom.apply(trans);\n geom.geometryChanged();\n return geom\n};\nCommonBitsRemover.prototype.getCommonCoordinate = function getCommonCoordinate () {\n return this._commonCoord\n};\nCommonBitsRemover.prototype.add = function add (geom) {\n geom.apply(this._ccFilter);\n this._commonCoord = this._ccFilter.getCommonCoordinate();\n};\nCommonBitsRemover.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nCommonBitsRemover.prototype.getClass = function getClass () {\n return CommonBitsRemover\n};\nstaticAccessors$42.CommonCoordinateFilter.get = function () { return CommonCoordinateFilter };\nstaticAccessors$42.Translater.get = function () { return Translater };\n\nObject.defineProperties( CommonBitsRemover, staticAccessors$42 );\n\nvar CommonCoordinateFilter = function CommonCoordinateFilter () {\n this._commonBitsX = new CommonBits();\n this._commonBitsY = new CommonBits();\n};\nCommonCoordinateFilter.prototype.filter = function filter (coord) {\n this._commonBitsX.add(coord.x);\n this._commonBitsY.add(coord.y);\n};\nCommonCoordinateFilter.prototype.getCommonCoordinate = function getCommonCoordinate () {\n return new Coordinate(this._commonBitsX.getCommon(), this._commonBitsY.getCommon())\n};\nCommonCoordinateFilter.prototype.interfaces_ = function interfaces_ () {\n return [CoordinateFilter]\n};\nCommonCoordinateFilter.prototype.getClass = function getClass () {\n return CommonCoordinateFilter\n};\n\nvar Translater = function Translater () {\n this.trans = null;\n var trans = arguments[0];\n this.trans = trans;\n};\nTranslater.prototype.filter = function filter (seq, i) {\n var xp = seq.getOrdinate(i, 0) + this.trans.x;\n var yp = seq.getOrdinate(i, 1) + this.trans.y;\n seq.setOrdinate(i, 0, xp);\n seq.setOrdinate(i, 1, yp);\n};\nTranslater.prototype.isDone = function isDone () {\n return false\n};\nTranslater.prototype.isGeometryChanged = function isGeometryChanged () {\n return true\n};\nTranslater.prototype.interfaces_ = function interfaces_ () {\n return [CoordinateSequenceFilter]\n};\nTranslater.prototype.getClass = function getClass () {\n return Translater\n};\n\nvar SnapOverlayOp = function SnapOverlayOp (g1, g2) {\n this._geom = new Array(2).fill(null);\n this._snapTolerance = null;\n this._cbr = null;\n this._geom[0] = g1;\n this._geom[1] = g2;\n this.computeSnapTolerance();\n};\nSnapOverlayOp.prototype.selfSnap = function selfSnap (geom) {\n var snapper0 = new GeometrySnapper(geom);\n var snapGeom = snapper0.snapTo(geom, this._snapTolerance);\n return snapGeom\n};\nSnapOverlayOp.prototype.removeCommonBits = function removeCommonBits (geom) {\n this._cbr = new CommonBitsRemover();\n this._cbr.add(geom[0]);\n this._cbr.add(geom[1]);\n var remGeom = new Array(2).fill(null);\n remGeom[0] = this._cbr.removeCommonBits(geom[0].copy());\n remGeom[1] = this._cbr.removeCommonBits(geom[1].copy());\n return remGeom\n};\nSnapOverlayOp.prototype.prepareResult = function prepareResult (geom) {\n this._cbr.addCommonBits(geom);\n return geom\n};\nSnapOverlayOp.prototype.getResultGeometry = function getResultGeometry (opCode) {\n var prepGeom = this.snap(this._geom);\n var result = OverlayOp.overlayOp(prepGeom[0], prepGeom[1], opCode);\n return this.prepareResult(result)\n};\nSnapOverlayOp.prototype.checkValid = function checkValid (g) {\n if (!g.isValid()) {\n System.out.println('Snapped geometry is invalid');\n }\n};\nSnapOverlayOp.prototype.computeSnapTolerance = function computeSnapTolerance () {\n this._snapTolerance = GeometrySnapper.computeOverlaySnapTolerance(this._geom[0], this._geom[1]);\n};\nSnapOverlayOp.prototype.snap = function snap (geom) {\n var remGeom = this.removeCommonBits(geom);\n var snapGeom = GeometrySnapper.snap(remGeom[0], remGeom[1], this._snapTolerance);\n return snapGeom\n};\nSnapOverlayOp.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nSnapOverlayOp.prototype.getClass = function getClass () {\n return SnapOverlayOp\n};\nSnapOverlayOp.overlayOp = function overlayOp (g0, g1, opCode) {\n var op = new SnapOverlayOp(g0, g1);\n return op.getResultGeometry(opCode)\n};\nSnapOverlayOp.union = function union (g0, g1) {\n return SnapOverlayOp.overlayOp(g0, g1, OverlayOp.UNION)\n};\nSnapOverlayOp.intersection = function intersection (g0, g1) {\n return SnapOverlayOp.overlayOp(g0, g1, OverlayOp.INTERSECTION)\n};\nSnapOverlayOp.symDifference = function symDifference (g0, g1) {\n return SnapOverlayOp.overlayOp(g0, g1, OverlayOp.SYMDIFFERENCE)\n};\nSnapOverlayOp.difference = function difference (g0, g1) {\n return SnapOverlayOp.overlayOp(g0, g1, OverlayOp.DIFFERENCE)\n};\n\nvar SnapIfNeededOverlayOp = function SnapIfNeededOverlayOp (g1, g2) {\n this._geom = new Array(2).fill(null);\n this._geom[0] = g1;\n this._geom[1] = g2;\n};\nSnapIfNeededOverlayOp.prototype.getResultGeometry = function getResultGeometry (opCode) {\n var result = null;\n var isSuccess = false;\n var savedException = null;\n try {\n result = OverlayOp.overlayOp(this._geom[0], this._geom[1], opCode);\n var isValid = true;\n if (isValid) { isSuccess = true; }\n } catch (ex) {\n if (ex instanceof RuntimeException) {\n savedException = ex;\n } else { throw ex }\n } finally {}\n if (!isSuccess) {\n try {\n result = SnapOverlayOp.overlayOp(this._geom[0], this._geom[1], opCode);\n } catch (ex) {\n if (ex instanceof RuntimeException) {\n throw savedException\n } else { throw ex }\n } finally {}\n }\n return result\n};\nSnapIfNeededOverlayOp.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nSnapIfNeededOverlayOp.prototype.getClass = function getClass () {\n return SnapIfNeededOverlayOp\n};\nSnapIfNeededOverlayOp.overlayOp = function overlayOp (g0, g1, opCode) {\n var op = new SnapIfNeededOverlayOp(g0, g1);\n return op.getResultGeometry(opCode)\n};\nSnapIfNeededOverlayOp.union = function union (g0, g1) {\n return SnapIfNeededOverlayOp.overlayOp(g0, g1, OverlayOp.UNION)\n};\nSnapIfNeededOverlayOp.intersection = function intersection (g0, g1) {\n return SnapIfNeededOverlayOp.overlayOp(g0, g1, OverlayOp.INTERSECTION)\n};\nSnapIfNeededOverlayOp.symDifference = function symDifference (g0, g1) {\n return SnapIfNeededOverlayOp.overlayOp(g0, g1, OverlayOp.SYMDIFFERENCE)\n};\nSnapIfNeededOverlayOp.difference = function difference (g0, g1) {\n return SnapIfNeededOverlayOp.overlayOp(g0, g1, OverlayOp.DIFFERENCE)\n};\n\nvar MonotoneChain$2 = function MonotoneChain () {\n this.mce = null;\n this.chainIndex = null;\n var mce = arguments[0];\n var chainIndex = arguments[1];\n this.mce = mce;\n this.chainIndex = chainIndex;\n};\nMonotoneChain$2.prototype.computeIntersections = function computeIntersections (mc, si) {\n this.mce.computeIntersectsForChain(this.chainIndex, mc.mce, mc.chainIndex, si);\n};\nMonotoneChain$2.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nMonotoneChain$2.prototype.getClass = function getClass () {\n return MonotoneChain$2\n};\n\nvar SweepLineEvent = function SweepLineEvent () {\n this._label = null;\n this._xValue = null;\n this._eventType = null;\n this._insertEvent = null;\n this._deleteEventIndex = null;\n this._obj = null;\n if (arguments.length === 2) {\n var x = arguments[0];\n var insertEvent = arguments[1];\n this._eventType = SweepLineEvent.DELETE;\n this._xValue = x;\n this._insertEvent = insertEvent;\n } else if (arguments.length === 3) {\n var label = arguments[0];\n var x$1 = arguments[1];\n var obj = arguments[2];\n this._eventType = SweepLineEvent.INSERT;\n this._label = label;\n this._xValue = x$1;\n this._obj = obj;\n }\n};\n\nvar staticAccessors$43 = { INSERT: { configurable: true },DELETE: { configurable: true } };\nSweepLineEvent.prototype.isDelete = function isDelete () {\n return this._eventType === SweepLineEvent.DELETE\n};\nSweepLineEvent.prototype.setDeleteEventIndex = function setDeleteEventIndex (deleteEventIndex) {\n this._deleteEventIndex = deleteEventIndex;\n};\nSweepLineEvent.prototype.getObject = function getObject () {\n return this._obj\n};\nSweepLineEvent.prototype.compareTo = function compareTo (o) {\n var pe = o;\n if (this._xValue < pe._xValue) { return -1 }\n if (this._xValue > pe._xValue) { return 1 }\n if (this._eventType < pe._eventType) { return -1 }\n if (this._eventType > pe._eventType) { return 1 }\n return 0\n};\nSweepLineEvent.prototype.getInsertEvent = function getInsertEvent () {\n return this._insertEvent\n};\nSweepLineEvent.prototype.isInsert = function isInsert () {\n return this._eventType === SweepLineEvent.INSERT\n};\nSweepLineEvent.prototype.isSameLabel = function isSameLabel (ev) {\n if (this._label === null) { return false }\n return this._label === ev._label\n};\nSweepLineEvent.prototype.getDeleteEventIndex = function getDeleteEventIndex () {\n return this._deleteEventIndex\n};\nSweepLineEvent.prototype.interfaces_ = function interfaces_ () {\n return [Comparable]\n};\nSweepLineEvent.prototype.getClass = function getClass () {\n return SweepLineEvent\n};\nstaticAccessors$43.INSERT.get = function () { return 1 };\nstaticAccessors$43.DELETE.get = function () { return 2 };\n\nObject.defineProperties( SweepLineEvent, staticAccessors$43 );\n\nvar EdgeSetIntersector = function EdgeSetIntersector () {};\n\nEdgeSetIntersector.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nEdgeSetIntersector.prototype.getClass = function getClass () {\n return EdgeSetIntersector\n};\n\nvar SegmentIntersector$2 = function SegmentIntersector () {\n this._hasIntersection = false;\n this._hasProper = false;\n this._hasProperInterior = false;\n this._properIntersectionPoint = null;\n this._li = null;\n this._includeProper = null;\n this._recordIsolated = null;\n this._isSelfIntersection = null;\n this._numIntersections = 0;\n this.numTests = 0;\n this._bdyNodes = null;\n this._isDone = false;\n this._isDoneWhenProperInt = false;\n var li = arguments[0];\n var includeProper = arguments[1];\n var recordIsolated = arguments[2];\n this._li = li;\n this._includeProper = includeProper;\n this._recordIsolated = recordIsolated;\n};\nSegmentIntersector$2.prototype.isTrivialIntersection = function isTrivialIntersection (e0, segIndex0, e1, segIndex1) {\n if (e0 === e1) {\n if (this._li.getIntersectionNum() === 1) {\n if (SegmentIntersector$2.isAdjacentSegments(segIndex0, segIndex1)) { return true }\n if (e0.isClosed()) {\n var maxSegIndex = e0.getNumPoints() - 1;\n if ((segIndex0 === 0 && segIndex1 === maxSegIndex) ||\n (segIndex1 === 0 && segIndex0 === maxSegIndex)) {\n return true\n }\n }\n }\n }\n return false\n};\nSegmentIntersector$2.prototype.getProperIntersectionPoint = function getProperIntersectionPoint () {\n return this._properIntersectionPoint\n};\nSegmentIntersector$2.prototype.setIsDoneIfProperInt = function setIsDoneIfProperInt (isDoneWhenProperInt) {\n this._isDoneWhenProperInt = isDoneWhenProperInt;\n};\nSegmentIntersector$2.prototype.hasProperInteriorIntersection = function hasProperInteriorIntersection () {\n return this._hasProperInterior\n};\nSegmentIntersector$2.prototype.isBoundaryPointInternal = function isBoundaryPointInternal (li, bdyNodes) {\n for (var i = bdyNodes.iterator(); i.hasNext();) {\n var node = i.next();\n var pt = node.getCoordinate();\n if (li.isIntersection(pt)) { return true }\n }\n return false\n};\nSegmentIntersector$2.prototype.hasProperIntersection = function hasProperIntersection () {\n return this._hasProper\n};\nSegmentIntersector$2.prototype.hasIntersection = function hasIntersection () {\n return this._hasIntersection\n};\nSegmentIntersector$2.prototype.isDone = function isDone () {\n return this._isDone\n};\nSegmentIntersector$2.prototype.isBoundaryPoint = function isBoundaryPoint (li, bdyNodes) {\n if (bdyNodes === null) { return false }\n if (this.isBoundaryPointInternal(li, bdyNodes[0])) { return true }\n if (this.isBoundaryPointInternal(li, bdyNodes[1])) { return true }\n return false\n};\nSegmentIntersector$2.prototype.setBoundaryNodes = function setBoundaryNodes (bdyNodes0, bdyNodes1) {\n this._bdyNodes = new Array(2).fill(null);\n this._bdyNodes[0] = bdyNodes0;\n this._bdyNodes[1] = bdyNodes1;\n};\nSegmentIntersector$2.prototype.addIntersections = function addIntersections (e0, segIndex0, e1, segIndex1) {\n if (e0 === e1 && segIndex0 === segIndex1) { return null }\n this.numTests++;\n var p00 = e0.getCoordinates()[segIndex0];\n var p01 = e0.getCoordinates()[segIndex0 + 1];\n var p10 = e1.getCoordinates()[segIndex1];\n var p11 = e1.getCoordinates()[segIndex1 + 1];\n this._li.computeIntersection(p00, p01, p10, p11);\n if (this._li.hasIntersection()) {\n if (this._recordIsolated) {\n e0.setIsolated(false);\n e1.setIsolated(false);\n }\n this._numIntersections++;\n if (!this.isTrivialIntersection(e0, segIndex0, e1, segIndex1)) {\n this._hasIntersection = true;\n if (this._includeProper || !this._li.isProper()) {\n e0.addIntersections(this._li, segIndex0, 0);\n e1.addIntersections(this._li, segIndex1, 1);\n }\n if (this._li.isProper()) {\n this._properIntersectionPoint = this._li.getIntersection(0).copy();\n this._hasProper = true;\n if (this._isDoneWhenProperInt) {\n this._isDone = true;\n }\n if (!this.isBoundaryPoint(this._li, this._bdyNodes)) { this._hasProperInterior = true; }\n }\n }\n }\n};\nSegmentIntersector$2.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nSegmentIntersector$2.prototype.getClass = function getClass () {\n return SegmentIntersector$2\n};\nSegmentIntersector$2.isAdjacentSegments = function isAdjacentSegments (i1, i2) {\n return Math.abs(i1 - i2) === 1\n};\n\nvar SimpleMCSweepLineIntersector = (function (EdgeSetIntersector$$1) {\n function SimpleMCSweepLineIntersector () {\n EdgeSetIntersector$$1.call(this);\n this.events = new ArrayList();\n this.nOverlaps = null;\n }\n\n if ( EdgeSetIntersector$$1 ) SimpleMCSweepLineIntersector.__proto__ = EdgeSetIntersector$$1;\n SimpleMCSweepLineIntersector.prototype = Object.create( EdgeSetIntersector$$1 && EdgeSetIntersector$$1.prototype );\n SimpleMCSweepLineIntersector.prototype.constructor = SimpleMCSweepLineIntersector;\n SimpleMCSweepLineIntersector.prototype.prepareEvents = function prepareEvents () {\n var this$1 = this;\n\n Collections.sort(this.events);\n for (var i = 0; i < this.events.size(); i++) {\n var ev = this$1.events.get(i);\n if (ev.isDelete()) {\n ev.getInsertEvent().setDeleteEventIndex(i);\n }\n }\n };\n SimpleMCSweepLineIntersector.prototype.computeIntersections = function computeIntersections () {\n var this$1 = this;\n\n if (arguments.length === 1) {\n var si = arguments[0];\n this.nOverlaps = 0;\n this.prepareEvents();\n for (var i = 0; i < this.events.size(); i++) {\n var ev = this$1.events.get(i);\n if (ev.isInsert()) {\n this$1.processOverlaps(i, ev.getDeleteEventIndex(), ev, si);\n }\n if (si.isDone()) {\n break\n }\n }\n } else if (arguments.length === 3) {\n if (arguments[2] instanceof SegmentIntersector$2 && (hasInterface(arguments[0], List) && hasInterface(arguments[1], List))) {\n var edges0 = arguments[0];\n var edges1 = arguments[1];\n var si$1 = arguments[2];\n this.addEdges(edges0, edges0);\n this.addEdges(edges1, edges1);\n this.computeIntersections(si$1);\n } else if (typeof arguments[2] === 'boolean' && (hasInterface(arguments[0], List) && arguments[1] instanceof SegmentIntersector$2)) {\n var edges = arguments[0];\n var si$2 = arguments[1];\n var testAllSegments = arguments[2];\n if (testAllSegments) { this.addEdges(edges, null); } else { this.addEdges(edges); }\n this.computeIntersections(si$2);\n }\n }\n };\n SimpleMCSweepLineIntersector.prototype.addEdge = function addEdge (edge, edgeSet) {\n var this$1 = this;\n\n var mce = edge.getMonotoneChainEdge();\n var startIndex = mce.getStartIndexes();\n for (var i = 0; i < startIndex.length - 1; i++) {\n var mc = new MonotoneChain$2(mce, i);\n var insertEvent = new SweepLineEvent(edgeSet, mce.getMinX(i), mc);\n this$1.events.add(insertEvent);\n this$1.events.add(new SweepLineEvent(mce.getMaxX(i), insertEvent));\n }\n };\n SimpleMCSweepLineIntersector.prototype.processOverlaps = function processOverlaps (start, end, ev0, si) {\n var this$1 = this;\n\n var mc0 = ev0.getObject();\n for (var i = start; i < end; i++) {\n var ev1 = this$1.events.get(i);\n if (ev1.isInsert()) {\n var mc1 = ev1.getObject();\n if (!ev0.isSameLabel(ev1)) {\n mc0.computeIntersections(mc1, si);\n this$1.nOverlaps++;\n }\n }\n }\n };\n SimpleMCSweepLineIntersector.prototype.addEdges = function addEdges () {\n var this$1 = this;\n\n if (arguments.length === 1) {\n var edges = arguments[0];\n for (var i = edges.iterator(); i.hasNext();) {\n var edge = i.next();\n this$1.addEdge(edge, edge);\n }\n } else if (arguments.length === 2) {\n var edges$1 = arguments[0];\n var edgeSet = arguments[1];\n for (var i$1 = edges$1.iterator(); i$1.hasNext();) {\n var edge$1 = i$1.next();\n this$1.addEdge(edge$1, edgeSet);\n }\n }\n };\n SimpleMCSweepLineIntersector.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n SimpleMCSweepLineIntersector.prototype.getClass = function getClass () {\n return SimpleMCSweepLineIntersector\n };\n\n return SimpleMCSweepLineIntersector;\n}(EdgeSetIntersector));\n\nvar IntervalRTreeNode = function IntervalRTreeNode () {\n this._min = Double.POSITIVE_INFINITY;\n this._max = Double.NEGATIVE_INFINITY;\n};\n\nvar staticAccessors$45 = { NodeComparator: { configurable: true } };\nIntervalRTreeNode.prototype.getMin = function getMin () {\n return this._min\n};\nIntervalRTreeNode.prototype.intersects = function intersects (queryMin, queryMax) {\n if (this._min > queryMax || this._max < queryMin) { return false }\n return true\n};\nIntervalRTreeNode.prototype.getMax = function getMax () {\n return this._max\n};\nIntervalRTreeNode.prototype.toString = function toString () {\n return WKTWriter.toLineString(new Coordinate(this._min, 0), new Coordinate(this._max, 0))\n};\nIntervalRTreeNode.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nIntervalRTreeNode.prototype.getClass = function getClass () {\n return IntervalRTreeNode\n};\nstaticAccessors$45.NodeComparator.get = function () { return NodeComparator };\n\nObject.defineProperties( IntervalRTreeNode, staticAccessors$45 );\n\nvar NodeComparator = function NodeComparator () {};\n\nNodeComparator.prototype.compare = function compare (o1, o2) {\n var n1 = o1;\n var n2 = o2;\n var mid1 = (n1._min + n1._max) / 2;\n var mid2 = (n2._min + n2._max) / 2;\n if (mid1 < mid2) { return -1 }\n if (mid1 > mid2) { return 1 }\n return 0\n};\nNodeComparator.prototype.interfaces_ = function interfaces_ () {\n return [Comparator]\n};\nNodeComparator.prototype.getClass = function getClass () {\n return NodeComparator\n};\n\nvar IntervalRTreeLeafNode = (function (IntervalRTreeNode$$1) {\n function IntervalRTreeLeafNode () {\n IntervalRTreeNode$$1.call(this);\n this._item = null;\n var min = arguments[0];\n var max = arguments[1];\n var item = arguments[2];\n this._min = min;\n this._max = max;\n this._item = item;\n }\n\n if ( IntervalRTreeNode$$1 ) IntervalRTreeLeafNode.__proto__ = IntervalRTreeNode$$1;\n IntervalRTreeLeafNode.prototype = Object.create( IntervalRTreeNode$$1 && IntervalRTreeNode$$1.prototype );\n IntervalRTreeLeafNode.prototype.constructor = IntervalRTreeLeafNode;\n IntervalRTreeLeafNode.prototype.query = function query (queryMin, queryMax, visitor) {\n if (!this.intersects(queryMin, queryMax)) { return null }\n visitor.visitItem(this._item);\n };\n IntervalRTreeLeafNode.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n IntervalRTreeLeafNode.prototype.getClass = function getClass () {\n return IntervalRTreeLeafNode\n };\n\n return IntervalRTreeLeafNode;\n}(IntervalRTreeNode));\n\nvar IntervalRTreeBranchNode = (function (IntervalRTreeNode$$1) {\n function IntervalRTreeBranchNode () {\n IntervalRTreeNode$$1.call(this);\n this._node1 = null;\n this._node2 = null;\n var n1 = arguments[0];\n var n2 = arguments[1];\n this._node1 = n1;\n this._node2 = n2;\n this.buildExtent(this._node1, this._node2);\n }\n\n if ( IntervalRTreeNode$$1 ) IntervalRTreeBranchNode.__proto__ = IntervalRTreeNode$$1;\n IntervalRTreeBranchNode.prototype = Object.create( IntervalRTreeNode$$1 && IntervalRTreeNode$$1.prototype );\n IntervalRTreeBranchNode.prototype.constructor = IntervalRTreeBranchNode;\n IntervalRTreeBranchNode.prototype.buildExtent = function buildExtent (n1, n2) {\n this._min = Math.min(n1._min, n2._min);\n this._max = Math.max(n1._max, n2._max);\n };\n IntervalRTreeBranchNode.prototype.query = function query (queryMin, queryMax, visitor) {\n if (!this.intersects(queryMin, queryMax)) {\n return null\n }\n if (this._node1 !== null) { this._node1.query(queryMin, queryMax, visitor); }\n if (this._node2 !== null) { this._node2.query(queryMin, queryMax, visitor); }\n };\n IntervalRTreeBranchNode.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n IntervalRTreeBranchNode.prototype.getClass = function getClass () {\n return IntervalRTreeBranchNode\n };\n\n return IntervalRTreeBranchNode;\n}(IntervalRTreeNode));\n\nvar SortedPackedIntervalRTree = function SortedPackedIntervalRTree () {\n this._leaves = new ArrayList();\n this._root = null;\n this._level = 0;\n};\nSortedPackedIntervalRTree.prototype.buildTree = function buildTree () {\n var this$1 = this;\n\n Collections.sort(this._leaves, new IntervalRTreeNode.NodeComparator());\n var src = this._leaves;\n var temp = null;\n var dest = new ArrayList();\n while (true) {\n this$1.buildLevel(src, dest);\n if (dest.size() === 1) { return dest.get(0) }\n temp = src;\n src = dest;\n dest = temp;\n }\n};\nSortedPackedIntervalRTree.prototype.insert = function insert (min, max, item) {\n if (this._root !== null) { throw new Error('Index cannot be added to once it has been queried') }\n this._leaves.add(new IntervalRTreeLeafNode(min, max, item));\n};\nSortedPackedIntervalRTree.prototype.query = function query (min, max, visitor) {\n this.init();\n this._root.query(min, max, visitor);\n};\nSortedPackedIntervalRTree.prototype.buildRoot = function buildRoot () {\n if (this._root !== null) { return null }\n this._root = this.buildTree();\n};\nSortedPackedIntervalRTree.prototype.printNode = function printNode (node) {\n System.out.println(WKTWriter.toLineString(new Coordinate(node._min, this._level), new Coordinate(node._max, this._level)));\n};\nSortedPackedIntervalRTree.prototype.init = function init () {\n if (this._root !== null) { return null }\n this.buildRoot();\n};\nSortedPackedIntervalRTree.prototype.buildLevel = function buildLevel (src, dest) {\n this._level++;\n dest.clear();\n for (var i = 0; i < src.size(); i += 2) {\n var n1 = src.get(i);\n var n2 = i + 1 < src.size() ? src.get(i) : null;\n if (n2 === null) {\n dest.add(n1);\n } else {\n var node = new IntervalRTreeBranchNode(src.get(i), src.get(i + 1));\n dest.add(node);\n }\n }\n};\nSortedPackedIntervalRTree.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nSortedPackedIntervalRTree.prototype.getClass = function getClass () {\n return SortedPackedIntervalRTree\n};\n\nvar ArrayListVisitor = function ArrayListVisitor () {\n this._items = new ArrayList();\n};\nArrayListVisitor.prototype.visitItem = function visitItem (item) {\n this._items.add(item);\n};\nArrayListVisitor.prototype.getItems = function getItems () {\n return this._items\n};\nArrayListVisitor.prototype.interfaces_ = function interfaces_ () {\n return [ItemVisitor]\n};\nArrayListVisitor.prototype.getClass = function getClass () {\n return ArrayListVisitor\n};\n\nvar IndexedPointInAreaLocator = function IndexedPointInAreaLocator () {\n this._index = null;\n var g = arguments[0];\n if (!hasInterface(g, Polygonal)) { throw new IllegalArgumentException('Argument must be Polygonal') }\n this._index = new IntervalIndexedGeometry(g);\n};\n\nvar staticAccessors$44 = { SegmentVisitor: { configurable: true },IntervalIndexedGeometry: { configurable: true } };\nIndexedPointInAreaLocator.prototype.locate = function locate (p) {\n var rcc = new RayCrossingCounter(p);\n var visitor = new SegmentVisitor(rcc);\n this._index.query(p.y, p.y, visitor);\n return rcc.getLocation()\n};\nIndexedPointInAreaLocator.prototype.interfaces_ = function interfaces_ () {\n return [PointOnGeometryLocator]\n};\nIndexedPointInAreaLocator.prototype.getClass = function getClass () {\n return IndexedPointInAreaLocator\n};\nstaticAccessors$44.SegmentVisitor.get = function () { return SegmentVisitor };\nstaticAccessors$44.IntervalIndexedGeometry.get = function () { return IntervalIndexedGeometry };\n\nObject.defineProperties( IndexedPointInAreaLocator, staticAccessors$44 );\n\nvar SegmentVisitor = function SegmentVisitor () {\n this._counter = null;\n var counter = arguments[0];\n this._counter = counter;\n};\nSegmentVisitor.prototype.visitItem = function visitItem (item) {\n var seg = item;\n this._counter.countSegment(seg.getCoordinate(0), seg.getCoordinate(1));\n};\nSegmentVisitor.prototype.interfaces_ = function interfaces_ () {\n return [ItemVisitor]\n};\nSegmentVisitor.prototype.getClass = function getClass () {\n return SegmentVisitor\n};\n\nvar IntervalIndexedGeometry = function IntervalIndexedGeometry () {\n this._index = new SortedPackedIntervalRTree();\n var geom = arguments[0];\n this.init(geom);\n};\nIntervalIndexedGeometry.prototype.init = function init (geom) {\n var this$1 = this;\n\n var lines = LinearComponentExtracter.getLines(geom);\n for (var i = lines.iterator(); i.hasNext();) {\n var line = i.next();\n var pts = line.getCoordinates();\n this$1.addLine(pts);\n }\n};\nIntervalIndexedGeometry.prototype.addLine = function addLine (pts) {\n var this$1 = this;\n\n for (var i = 1; i < pts.length; i++) {\n var seg = new LineSegment(pts[i - 1], pts[i]);\n var min = Math.min(seg.p0.y, seg.p1.y);\n var max = Math.max(seg.p0.y, seg.p1.y);\n this$1._index.insert(min, max, seg);\n }\n};\nIntervalIndexedGeometry.prototype.query = function query () {\n if (arguments.length === 2) {\n var min = arguments[0];\n var max = arguments[1];\n var visitor = new ArrayListVisitor();\n this._index.query(min, max, visitor);\n return visitor.getItems()\n } else if (arguments.length === 3) {\n var min$1 = arguments[0];\n var max$1 = arguments[1];\n var visitor$1 = arguments[2];\n this._index.query(min$1, max$1, visitor$1);\n }\n};\nIntervalIndexedGeometry.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nIntervalIndexedGeometry.prototype.getClass = function getClass () {\n return IntervalIndexedGeometry\n};\n\nvar GeometryGraph = (function (PlanarGraph$$1) {\n function GeometryGraph () {\n PlanarGraph$$1.call(this);\n this._parentGeom = null;\n this._lineEdgeMap = new HashMap();\n this._boundaryNodeRule = null;\n this._useBoundaryDeterminationRule = true;\n this._argIndex = null;\n this._boundaryNodes = null;\n this._hasTooFewPoints = false;\n this._invalidPoint = null;\n this._areaPtLocator = null;\n this._ptLocator = new PointLocator();\n if (arguments.length === 2) {\n var argIndex = arguments[0];\n var parentGeom = arguments[1];\n var boundaryNodeRule = BoundaryNodeRule.OGC_SFS_BOUNDARY_RULE;\n this._argIndex = argIndex;\n this._parentGeom = parentGeom;\n this._boundaryNodeRule = boundaryNodeRule;\n if (parentGeom !== null) {\n this.add(parentGeom);\n }\n } else if (arguments.length === 3) {\n var argIndex$1 = arguments[0];\n var parentGeom$1 = arguments[1];\n var boundaryNodeRule$1 = arguments[2];\n this._argIndex = argIndex$1;\n this._parentGeom = parentGeom$1;\n this._boundaryNodeRule = boundaryNodeRule$1;\n if (parentGeom$1 !== null) {\n this.add(parentGeom$1);\n }\n }\n }\n\n if ( PlanarGraph$$1 ) GeometryGraph.__proto__ = PlanarGraph$$1;\n GeometryGraph.prototype = Object.create( PlanarGraph$$1 && PlanarGraph$$1.prototype );\n GeometryGraph.prototype.constructor = GeometryGraph;\n GeometryGraph.prototype.insertBoundaryPoint = function insertBoundaryPoint (argIndex, coord) {\n var n = this._nodes.addNode(coord);\n var lbl = n.getLabel();\n var boundaryCount = 1;\n var loc = Location.NONE;\n loc = lbl.getLocation(argIndex, Position.ON);\n if (loc === Location.BOUNDARY) { boundaryCount++; }\n var newLoc = GeometryGraph.determineBoundary(this._boundaryNodeRule, boundaryCount);\n lbl.setLocation(argIndex, newLoc);\n };\n GeometryGraph.prototype.computeSelfNodes = function computeSelfNodes () {\n if (arguments.length === 2) {\n var li = arguments[0];\n var computeRingSelfNodes = arguments[1];\n return this.computeSelfNodes(li, computeRingSelfNodes, false)\n } else if (arguments.length === 3) {\n var li$1 = arguments[0];\n var computeRingSelfNodes$1 = arguments[1];\n var isDoneIfProperInt = arguments[2];\n var si = new SegmentIntersector$2(li$1, true, false);\n si.setIsDoneIfProperInt(isDoneIfProperInt);\n var esi = this.createEdgeSetIntersector();\n var isRings = this._parentGeom instanceof LinearRing || this._parentGeom instanceof Polygon || this._parentGeom instanceof MultiPolygon;\n var computeAllSegments = computeRingSelfNodes$1 || !isRings;\n esi.computeIntersections(this._edges, si, computeAllSegments);\n this.addSelfIntersectionNodes(this._argIndex);\n return si\n }\n };\n GeometryGraph.prototype.computeSplitEdges = function computeSplitEdges (edgelist) {\n for (var i = this._edges.iterator(); i.hasNext();) {\n var e = i.next();\n e.eiList.addSplitEdges(edgelist);\n }\n };\n GeometryGraph.prototype.computeEdgeIntersections = function computeEdgeIntersections (g, li, includeProper) {\n var si = new SegmentIntersector$2(li, includeProper, true);\n si.setBoundaryNodes(this.getBoundaryNodes(), g.getBoundaryNodes());\n var esi = this.createEdgeSetIntersector();\n esi.computeIntersections(this._edges, g._edges, si);\n return si\n };\n GeometryGraph.prototype.getGeometry = function getGeometry () {\n return this._parentGeom\n };\n GeometryGraph.prototype.getBoundaryNodeRule = function getBoundaryNodeRule () {\n return this._boundaryNodeRule\n };\n GeometryGraph.prototype.hasTooFewPoints = function hasTooFewPoints () {\n return this._hasTooFewPoints\n };\n GeometryGraph.prototype.addPoint = function addPoint () {\n if (arguments[0] instanceof Point) {\n var p = arguments[0];\n var coord = p.getCoordinate();\n this.insertPoint(this._argIndex, coord, Location.INTERIOR);\n } else if (arguments[0] instanceof Coordinate) {\n var pt = arguments[0];\n this.insertPoint(this._argIndex, pt, Location.INTERIOR);\n }\n };\n GeometryGraph.prototype.addPolygon = function addPolygon (p) {\n var this$1 = this;\n\n this.addPolygonRing(p.getExteriorRing(), Location.EXTERIOR, Location.INTERIOR);\n for (var i = 0; i < p.getNumInteriorRing(); i++) {\n var hole = p.getInteriorRingN(i);\n this$1.addPolygonRing(hole, Location.INTERIOR, Location.EXTERIOR);\n }\n };\n GeometryGraph.prototype.addEdge = function addEdge (e) {\n this.insertEdge(e);\n var coord = e.getCoordinates();\n this.insertPoint(this._argIndex, coord[0], Location.BOUNDARY);\n this.insertPoint(this._argIndex, coord[coord.length - 1], Location.BOUNDARY);\n };\n GeometryGraph.prototype.addLineString = function addLineString (line) {\n var coord = CoordinateArrays.removeRepeatedPoints(line.getCoordinates());\n if (coord.length < 2) {\n this._hasTooFewPoints = true;\n this._invalidPoint = coord[0];\n return null\n }\n var e = new Edge(coord, new Label(this._argIndex, Location.INTERIOR));\n this._lineEdgeMap.put(line, e);\n this.insertEdge(e);\n Assert.isTrue(coord.length >= 2, 'found LineString with single point');\n this.insertBoundaryPoint(this._argIndex, coord[0]);\n this.insertBoundaryPoint(this._argIndex, coord[coord.length - 1]);\n };\n GeometryGraph.prototype.getInvalidPoint = function getInvalidPoint () {\n return this._invalidPoint\n };\n GeometryGraph.prototype.getBoundaryPoints = function getBoundaryPoints () {\n var coll = this.getBoundaryNodes();\n var pts = new Array(coll.size()).fill(null);\n var i = 0;\n for (var it = coll.iterator(); it.hasNext();) {\n var node = it.next();\n pts[i++] = node.getCoordinate().copy();\n }\n return pts\n };\n GeometryGraph.prototype.getBoundaryNodes = function getBoundaryNodes () {\n if (this._boundaryNodes === null) { this._boundaryNodes = this._nodes.getBoundaryNodes(this._argIndex); }\n return this._boundaryNodes\n };\n GeometryGraph.prototype.addSelfIntersectionNode = function addSelfIntersectionNode (argIndex, coord, loc) {\n if (this.isBoundaryNode(argIndex, coord)) { return null }\n if (loc === Location.BOUNDARY && this._useBoundaryDeterminationRule) { this.insertBoundaryPoint(argIndex, coord); } else { this.insertPoint(argIndex, coord, loc); }\n };\n GeometryGraph.prototype.addPolygonRing = function addPolygonRing (lr, cwLeft, cwRight) {\n if (lr.isEmpty()) { return null }\n var coord = CoordinateArrays.removeRepeatedPoints(lr.getCoordinates());\n if (coord.length < 4) {\n this._hasTooFewPoints = true;\n this._invalidPoint = coord[0];\n return null\n }\n var left = cwLeft;\n var right = cwRight;\n if (CGAlgorithms.isCCW(coord)) {\n left = cwRight;\n right = cwLeft;\n }\n var e = new Edge(coord, new Label(this._argIndex, Location.BOUNDARY, left, right));\n this._lineEdgeMap.put(lr, e);\n this.insertEdge(e);\n this.insertPoint(this._argIndex, coord[0], Location.BOUNDARY);\n };\n GeometryGraph.prototype.insertPoint = function insertPoint (argIndex, coord, onLocation) {\n var n = this._nodes.addNode(coord);\n var lbl = n.getLabel();\n if (lbl === null) {\n n._label = new Label(argIndex, onLocation);\n } else { lbl.setLocation(argIndex, onLocation); }\n };\n GeometryGraph.prototype.createEdgeSetIntersector = function createEdgeSetIntersector () {\n return new SimpleMCSweepLineIntersector()\n };\n GeometryGraph.prototype.addSelfIntersectionNodes = function addSelfIntersectionNodes (argIndex) {\n var this$1 = this;\n\n for (var i = this._edges.iterator(); i.hasNext();) {\n var e = i.next();\n var eLoc = e.getLabel().getLocation(argIndex);\n for (var eiIt = e.eiList.iterator(); eiIt.hasNext();) {\n var ei = eiIt.next();\n this$1.addSelfIntersectionNode(argIndex, ei.coord, eLoc);\n }\n }\n };\n GeometryGraph.prototype.add = function add () {\n if (arguments.length === 1) {\n var g = arguments[0];\n if (g.isEmpty()) { return null }\n if (g instanceof MultiPolygon) { this._useBoundaryDeterminationRule = false; }\n if (g instanceof Polygon) { this.addPolygon(g); }\n else if (g instanceof LineString) { this.addLineString(g); }\n else if (g instanceof Point) { this.addPoint(g); }\n else if (g instanceof MultiPoint) { this.addCollection(g); }\n else if (g instanceof MultiLineString) { this.addCollection(g); }\n else if (g instanceof MultiPolygon) { this.addCollection(g); }\n else if (g instanceof GeometryCollection) { this.addCollection(g); }\n else { throw new Error(g.getClass().getName()) }\n } else { return PlanarGraph$$1.prototype.add.apply(this, arguments) }\n };\n GeometryGraph.prototype.addCollection = function addCollection (gc) {\n var this$1 = this;\n\n for (var i = 0; i < gc.getNumGeometries(); i++) {\n var g = gc.getGeometryN(i);\n this$1.add(g);\n }\n };\n GeometryGraph.prototype.locate = function locate (pt) {\n if (hasInterface(this._parentGeom, Polygonal) && this._parentGeom.getNumGeometries() > 50) {\n if (this._areaPtLocator === null) {\n this._areaPtLocator = new IndexedPointInAreaLocator(this._parentGeom);\n }\n return this._areaPtLocator.locate(pt)\n }\n return this._ptLocator.locate(pt, this._parentGeom)\n };\n GeometryGraph.prototype.findEdge = function findEdge () {\n if (arguments.length === 1) {\n var line = arguments[0];\n return this._lineEdgeMap.get(line)\n } else { return PlanarGraph$$1.prototype.findEdge.apply(this, arguments) }\n };\n GeometryGraph.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n GeometryGraph.prototype.getClass = function getClass () {\n return GeometryGraph\n };\n GeometryGraph.determineBoundary = function determineBoundary (boundaryNodeRule, boundaryCount) {\n return boundaryNodeRule.isInBoundary(boundaryCount) ? Location.BOUNDARY : Location.INTERIOR\n };\n\n return GeometryGraph;\n}(PlanarGraph));\n\nvar GeometryGraphOp = function GeometryGraphOp () {\n this._li = new RobustLineIntersector();\n this._resultPrecisionModel = null;\n this._arg = null;\n if (arguments.length === 1) {\n var g0 = arguments[0];\n this.setComputationPrecision(g0.getPrecisionModel());\n this._arg = new Array(1).fill(null);\n this._arg[0] = new GeometryGraph(0, g0);\n } else if (arguments.length === 2) {\n var g0$1 = arguments[0];\n var g1 = arguments[1];\n var boundaryNodeRule = BoundaryNodeRule.OGC_SFS_BOUNDARY_RULE;\n if (g0$1.getPrecisionModel().compareTo(g1.getPrecisionModel()) >= 0) { this.setComputationPrecision(g0$1.getPrecisionModel()); } else { this.setComputationPrecision(g1.getPrecisionModel()); }\n this._arg = new Array(2).fill(null);\n this._arg[0] = new GeometryGraph(0, g0$1, boundaryNodeRule);\n this._arg[1] = new GeometryGraph(1, g1, boundaryNodeRule);\n } else if (arguments.length === 3) {\n var g0$2 = arguments[0];\n var g1$1 = arguments[1];\n var boundaryNodeRule$1 = arguments[2];\n if (g0$2.getPrecisionModel().compareTo(g1$1.getPrecisionModel()) >= 0) { this.setComputationPrecision(g0$2.getPrecisionModel()); } else { this.setComputationPrecision(g1$1.getPrecisionModel()); }\n this._arg = new Array(2).fill(null);\n this._arg[0] = new GeometryGraph(0, g0$2, boundaryNodeRule$1);\n this._arg[1] = new GeometryGraph(1, g1$1, boundaryNodeRule$1);\n }\n};\nGeometryGraphOp.prototype.getArgGeometry = function getArgGeometry (i) {\n return this._arg[i].getGeometry()\n};\nGeometryGraphOp.prototype.setComputationPrecision = function setComputationPrecision (pm) {\n this._resultPrecisionModel = pm;\n this._li.setPrecisionModel(this._resultPrecisionModel);\n};\nGeometryGraphOp.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nGeometryGraphOp.prototype.getClass = function getClass () {\n return GeometryGraphOp\n};\n\n// operation.geometrygraph\n\nvar GeometryMapper = function GeometryMapper () {};\n\nGeometryMapper.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nGeometryMapper.prototype.getClass = function getClass () {\n return GeometryMapper\n};\nGeometryMapper.map = function map () {\n if (arguments[0] instanceof Geometry && hasInterface(arguments[1], GeometryMapper.MapOp)) {\n var geom = arguments[0];\n var op = arguments[1];\n var mapped = new ArrayList();\n for (var i = 0; i < geom.getNumGeometries(); i++) {\n var g = op.map(geom.getGeometryN(i));\n if (g !== null) { mapped.add(g); }\n }\n return geom.getFactory().buildGeometry(mapped)\n } else if (hasInterface(arguments[0], Collection) && hasInterface(arguments[1], GeometryMapper.MapOp)) {\n var geoms = arguments[0];\n var op$1 = arguments[1];\n var mapped$1 = new ArrayList();\n for (var i$1 = geoms.iterator(); i$1.hasNext();) {\n var g$1 = i$1.next();\n var gr = op$1.map(g$1);\n if (gr !== null) { mapped$1.add(gr); }\n }\n return mapped$1\n }\n};\nGeometryMapper.MapOp = function MapOp () {};\n\nvar OverlayOp = (function (GeometryGraphOp) {\n function OverlayOp () {\n var g0 = arguments[0];\n var g1 = arguments[1];\n GeometryGraphOp.call(this, g0, g1);\n this._ptLocator = new PointLocator();\n this._geomFact = null;\n this._resultGeom = null;\n this._graph = null;\n this._edgeList = new EdgeList();\n this._resultPolyList = new ArrayList();\n this._resultLineList = new ArrayList();\n this._resultPointList = new ArrayList();\n this._graph = new PlanarGraph(new OverlayNodeFactory());\n this._geomFact = g0.getFactory();\n }\n\n if ( GeometryGraphOp ) OverlayOp.__proto__ = GeometryGraphOp;\n OverlayOp.prototype = Object.create( GeometryGraphOp && GeometryGraphOp.prototype );\n OverlayOp.prototype.constructor = OverlayOp;\n OverlayOp.prototype.insertUniqueEdge = function insertUniqueEdge (e) {\n var existingEdge = this._edgeList.findEqualEdge(e);\n if (existingEdge !== null) {\n var existingLabel = existingEdge.getLabel();\n var labelToMerge = e.getLabel();\n if (!existingEdge.isPointwiseEqual(e)) {\n labelToMerge = new Label(e.getLabel());\n labelToMerge.flip();\n }\n var depth = existingEdge.getDepth();\n if (depth.isNull()) {\n depth.add(existingLabel);\n }\n depth.add(labelToMerge);\n existingLabel.merge(labelToMerge);\n } else {\n this._edgeList.add(e);\n }\n };\n OverlayOp.prototype.getGraph = function getGraph () {\n return this._graph\n };\n OverlayOp.prototype.cancelDuplicateResultEdges = function cancelDuplicateResultEdges () {\n for (var it = this._graph.getEdgeEnds().iterator(); it.hasNext();) {\n var de = it.next();\n var sym = de.getSym();\n if (de.isInResult() && sym.isInResult()) {\n de.setInResult(false);\n sym.setInResult(false);\n }\n }\n };\n OverlayOp.prototype.isCoveredByLA = function isCoveredByLA (coord) {\n if (this.isCovered(coord, this._resultLineList)) { return true }\n if (this.isCovered(coord, this._resultPolyList)) { return true }\n return false\n };\n OverlayOp.prototype.computeGeometry = function computeGeometry (resultPointList, resultLineList, resultPolyList, opcode) {\n var geomList = new ArrayList();\n geomList.addAll(resultPointList);\n geomList.addAll(resultLineList);\n geomList.addAll(resultPolyList);\n if (geomList.isEmpty()) { return OverlayOp.createEmptyResult(opcode, this._arg[0].getGeometry(), this._arg[1].getGeometry(), this._geomFact) }\n return this._geomFact.buildGeometry(geomList)\n };\n OverlayOp.prototype.mergeSymLabels = function mergeSymLabels () {\n for (var nodeit = this._graph.getNodes().iterator(); nodeit.hasNext();) {\n var node = nodeit.next();\n node.getEdges().mergeSymLabels();\n }\n };\n OverlayOp.prototype.isCovered = function isCovered (coord, geomList) {\n var this$1 = this;\n\n for (var it = geomList.iterator(); it.hasNext();) {\n var geom = it.next();\n var loc = this$1._ptLocator.locate(coord, geom);\n if (loc !== Location.EXTERIOR) { return true }\n }\n return false\n };\n OverlayOp.prototype.replaceCollapsedEdges = function replaceCollapsedEdges () {\n var newEdges = new ArrayList();\n for (var it = this._edgeList.iterator(); it.hasNext();) {\n var e = it.next();\n if (e.isCollapsed()) {\n it.remove();\n newEdges.add(e.getCollapsedEdge());\n }\n }\n this._edgeList.addAll(newEdges);\n };\n OverlayOp.prototype.updateNodeLabelling = function updateNodeLabelling () {\n for (var nodeit = this._graph.getNodes().iterator(); nodeit.hasNext();) {\n var node = nodeit.next();\n var lbl = node.getEdges().getLabel();\n node.getLabel().merge(lbl);\n }\n };\n OverlayOp.prototype.getResultGeometry = function getResultGeometry (overlayOpCode) {\n this.computeOverlay(overlayOpCode);\n return this._resultGeom\n };\n OverlayOp.prototype.insertUniqueEdges = function insertUniqueEdges (edges) {\n var this$1 = this;\n\n for (var i = edges.iterator(); i.hasNext();) {\n var e = i.next();\n this$1.insertUniqueEdge(e);\n }\n };\n OverlayOp.prototype.computeOverlay = function computeOverlay (opCode) {\n this.copyPoints(0);\n this.copyPoints(1);\n this._arg[0].computeSelfNodes(this._li, false);\n this._arg[1].computeSelfNodes(this._li, false);\n this._arg[0].computeEdgeIntersections(this._arg[1], this._li, true);\n var baseSplitEdges = new ArrayList();\n this._arg[0].computeSplitEdges(baseSplitEdges);\n this._arg[1].computeSplitEdges(baseSplitEdges);\n // const splitEdges = baseSplitEdges\n this.insertUniqueEdges(baseSplitEdges);\n this.computeLabelsFromDepths();\n this.replaceCollapsedEdges();\n EdgeNodingValidator.checkValid(this._edgeList.getEdges());\n this._graph.addEdges(this._edgeList.getEdges());\n this.computeLabelling();\n this.labelIncompleteNodes();\n this.findResultAreaEdges(opCode);\n this.cancelDuplicateResultEdges();\n var polyBuilder = new PolygonBuilder(this._geomFact);\n polyBuilder.add(this._graph);\n this._resultPolyList = polyBuilder.getPolygons();\n var lineBuilder = new LineBuilder(this, this._geomFact, this._ptLocator);\n this._resultLineList = lineBuilder.build(opCode);\n var pointBuilder = new PointBuilder(this, this._geomFact, this._ptLocator);\n this._resultPointList = pointBuilder.build(opCode);\n this._resultGeom = this.computeGeometry(this._resultPointList, this._resultLineList, this._resultPolyList, opCode);\n };\n OverlayOp.prototype.labelIncompleteNode = function labelIncompleteNode (n, targetIndex) {\n var loc = this._ptLocator.locate(n.getCoordinate(), this._arg[targetIndex].getGeometry());\n n.getLabel().setLocation(targetIndex, loc);\n };\n OverlayOp.prototype.copyPoints = function copyPoints (argIndex) {\n var this$1 = this;\n\n for (var i = this._arg[argIndex].getNodeIterator(); i.hasNext();) {\n var graphNode = i.next();\n var newNode = this$1._graph.addNode(graphNode.getCoordinate());\n newNode.setLabel(argIndex, graphNode.getLabel().getLocation(argIndex));\n }\n };\n OverlayOp.prototype.findResultAreaEdges = function findResultAreaEdges (opCode) {\n for (var it = this._graph.getEdgeEnds().iterator(); it.hasNext();) {\n var de = it.next();\n var label = de.getLabel();\n if (label.isArea() && !de.isInteriorAreaEdge() && OverlayOp.isResultOfOp(label.getLocation(0, Position.RIGHT), label.getLocation(1, Position.RIGHT), opCode)) {\n de.setInResult(true);\n }\n }\n };\n OverlayOp.prototype.computeLabelsFromDepths = function computeLabelsFromDepths () {\n for (var it = this._edgeList.iterator(); it.hasNext();) {\n var e = it.next();\n var lbl = e.getLabel();\n var depth = e.getDepth();\n if (!depth.isNull()) {\n depth.normalize();\n for (var i = 0; i < 2; i++) {\n if (!lbl.isNull(i) && lbl.isArea() && !depth.isNull(i)) {\n if (depth.getDelta(i) === 0) {\n lbl.toLine(i);\n } else {\n Assert.isTrue(!depth.isNull(i, Position.LEFT), 'depth of LEFT side has not been initialized');\n lbl.setLocation(i, Position.LEFT, depth.getLocation(i, Position.LEFT));\n Assert.isTrue(!depth.isNull(i, Position.RIGHT), 'depth of RIGHT side has not been initialized');\n lbl.setLocation(i, Position.RIGHT, depth.getLocation(i, Position.RIGHT));\n }\n }\n }\n }\n }\n };\n OverlayOp.prototype.computeLabelling = function computeLabelling () {\n var this$1 = this;\n\n for (var nodeit = this._graph.getNodes().iterator(); nodeit.hasNext();) {\n var node = nodeit.next();\n node.getEdges().computeLabelling(this$1._arg);\n }\n this.mergeSymLabels();\n this.updateNodeLabelling();\n };\n OverlayOp.prototype.labelIncompleteNodes = function labelIncompleteNodes () {\n var this$1 = this;\n\n // let nodeCount = 0\n for (var ni = this._graph.getNodes().iterator(); ni.hasNext();) {\n var n = ni.next();\n var label = n.getLabel();\n if (n.isIsolated()) {\n // nodeCount++\n if (label.isNull(0)) { this$1.labelIncompleteNode(n, 0); } else { this$1.labelIncompleteNode(n, 1); }\n }\n n.getEdges().updateLabelling(label);\n }\n };\n OverlayOp.prototype.isCoveredByA = function isCoveredByA (coord) {\n if (this.isCovered(coord, this._resultPolyList)) { return true }\n return false\n };\n OverlayOp.prototype.interfaces_ = function interfaces_ () {\n return []\n };\n OverlayOp.prototype.getClass = function getClass () {\n return OverlayOp\n };\n\n return OverlayOp;\n}(GeometryGraphOp));\n\nOverlayOp.overlayOp = function (geom0, geom1, opCode) {\n var gov = new OverlayOp(geom0, geom1);\n var geomOv = gov.getResultGeometry(opCode);\n return geomOv\n};\nOverlayOp.intersection = function (g, other) {\n if (g.isEmpty() || other.isEmpty()) { return OverlayOp.createEmptyResult(OverlayOp.INTERSECTION, g, other, g.getFactory()) }\n if (g.isGeometryCollection()) {\n var g2 = other;\n return GeometryCollectionMapper.map(g, {\n interfaces_: function () {\n return [GeometryMapper.MapOp]\n },\n map: function (g) {\n return g.intersection(g2)\n }\n })\n }\n g.checkNotGeometryCollection(g);\n g.checkNotGeometryCollection(other);\n return SnapIfNeededOverlayOp.overlayOp(g, other, OverlayOp.INTERSECTION)\n};\nOverlayOp.symDifference = function (g, other) {\n if (g.isEmpty() || other.isEmpty()) {\n if (g.isEmpty() && other.isEmpty()) { return OverlayOp.createEmptyResult(OverlayOp.SYMDIFFERENCE, g, other, g.getFactory()) }\n if (g.isEmpty()) { return other.copy() }\n if (other.isEmpty()) { return g.copy() }\n }\n g.checkNotGeometryCollection(g);\n g.checkNotGeometryCollection(other);\n return SnapIfNeededOverlayOp.overlayOp(g, other, OverlayOp.SYMDIFFERENCE)\n};\nOverlayOp.resultDimension = function (opCode, g0, g1) {\n var dim0 = g0.getDimension();\n var dim1 = g1.getDimension();\n var resultDimension = -1;\n switch (opCode) {\n case OverlayOp.INTERSECTION:\n resultDimension = Math.min(dim0, dim1);\n break\n case OverlayOp.UNION:\n resultDimension = Math.max(dim0, dim1);\n break\n case OverlayOp.DIFFERENCE:\n resultDimension = dim0;\n break\n case OverlayOp.SYMDIFFERENCE:\n resultDimension = Math.max(dim0, dim1);\n break\n default:\n }\n return resultDimension\n};\nOverlayOp.createEmptyResult = function (overlayOpCode, a, b, geomFact) {\n var result = null;\n switch (OverlayOp.resultDimension(overlayOpCode, a, b)) {\n case -1:\n result = geomFact.createGeometryCollection(new Array(0).fill(null));\n break\n case 0:\n result = geomFact.createPoint();\n break\n case 1:\n result = geomFact.createLineString();\n break\n case 2:\n result = geomFact.createPolygon();\n break\n default:\n }\n return result\n};\nOverlayOp.difference = function (g, other) {\n if (g.isEmpty()) { return OverlayOp.createEmptyResult(OverlayOp.DIFFERENCE, g, other, g.getFactory()) }\n if (other.isEmpty()) { return g.copy() }\n g.checkNotGeometryCollection(g);\n g.checkNotGeometryCollection(other);\n return SnapIfNeededOverlayOp.overlayOp(g, other, OverlayOp.DIFFERENCE)\n};\nOverlayOp.isResultOfOp = function () {\n if (arguments.length === 2) {\n var label = arguments[0];\n var opCode = arguments[1];\n var loc0 = label.getLocation(0);\n var loc1 = label.getLocation(1);\n return OverlayOp.isResultOfOp(loc0, loc1, opCode)\n } else if (arguments.length === 3) {\n var loc0$1 = arguments[0];\n var loc1$1 = arguments[1];\n var overlayOpCode = arguments[2];\n if (loc0$1 === Location.BOUNDARY) { loc0$1 = Location.INTERIOR; }\n if (loc1$1 === Location.BOUNDARY) { loc1$1 = Location.INTERIOR; }\n switch (overlayOpCode) {\n case OverlayOp.INTERSECTION:\n return loc0$1 === Location.INTERIOR && loc1$1 === Location.INTERIOR\n case OverlayOp.UNION:\n return loc0$1 === Location.INTERIOR || loc1$1 === Location.INTERIOR\n case OverlayOp.DIFFERENCE:\n return loc0$1 === Location.INTERIOR && loc1$1 !== Location.INTERIOR\n case OverlayOp.SYMDIFFERENCE:\n return (loc0$1 === Location.INTERIOR && loc1$1 !== Location.INTERIOR) || (loc0$1 !== Location.INTERIOR && loc1$1 === Location.INTERIOR)\n default:\n }\n return false\n }\n};\nOverlayOp.INTERSECTION = 1;\nOverlayOp.UNION = 2;\nOverlayOp.DIFFERENCE = 3;\nOverlayOp.SYMDIFFERENCE = 4;\n\nvar FuzzyPointLocator = function FuzzyPointLocator () {\n this._g = null;\n this._boundaryDistanceTolerance = null;\n this._linework = null;\n this._ptLocator = new PointLocator();\n this._seg = new LineSegment();\n var g = arguments[0];\n var boundaryDistanceTolerance = arguments[1];\n this._g = g;\n this._boundaryDistanceTolerance = boundaryDistanceTolerance;\n this._linework = this.extractLinework(g);\n};\nFuzzyPointLocator.prototype.isWithinToleranceOfBoundary = function isWithinToleranceOfBoundary (pt) {\n var this$1 = this;\n\n for (var i = 0; i < this._linework.getNumGeometries(); i++) {\n var line = this$1._linework.getGeometryN(i);\n var seq = line.getCoordinateSequence();\n for (var j = 0; j < seq.size() - 1; j++) {\n seq.getCoordinate(j, this$1._seg.p0);\n seq.getCoordinate(j + 1, this$1._seg.p1);\n var dist = this$1._seg.distance(pt);\n if (dist <= this$1._boundaryDistanceTolerance) { return true }\n }\n }\n return false\n};\nFuzzyPointLocator.prototype.getLocation = function getLocation (pt) {\n if (this.isWithinToleranceOfBoundary(pt)) { return Location.BOUNDARY }\n return this._ptLocator.locate(pt, this._g)\n};\nFuzzyPointLocator.prototype.extractLinework = function extractLinework (g) {\n var extracter = new PolygonalLineworkExtracter();\n g.apply(extracter);\n var linework = extracter.getLinework();\n var lines = GeometryFactory.toLineStringArray(linework);\n return g.getFactory().createMultiLineString(lines)\n};\nFuzzyPointLocator.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nFuzzyPointLocator.prototype.getClass = function getClass () {\n return FuzzyPointLocator\n};\n\nvar PolygonalLineworkExtracter = function PolygonalLineworkExtracter () {\n this._linework = null;\n this._linework = new ArrayList();\n};\nPolygonalLineworkExtracter.prototype.getLinework = function getLinework () {\n return this._linework\n};\nPolygonalLineworkExtracter.prototype.filter = function filter (g) {\n var this$1 = this;\n\n if (g instanceof Polygon) {\n var poly = g;\n this._linework.add(poly.getExteriorRing());\n for (var i = 0; i < poly.getNumInteriorRing(); i++) {\n this$1._linework.add(poly.getInteriorRingN(i));\n }\n }\n};\nPolygonalLineworkExtracter.prototype.interfaces_ = function interfaces_ () {\n return [GeometryFilter]\n};\nPolygonalLineworkExtracter.prototype.getClass = function getClass () {\n return PolygonalLineworkExtracter\n};\n\nvar OffsetPointGenerator = function OffsetPointGenerator () {\n this._g = null;\n this._doLeft = true;\n this._doRight = true;\n var g = arguments[0];\n this._g = g;\n};\nOffsetPointGenerator.prototype.extractPoints = function extractPoints (line, offsetDistance, offsetPts) {\n var this$1 = this;\n\n var pts = line.getCoordinates();\n for (var i = 0; i < pts.length - 1; i++) {\n this$1.computeOffsetPoints(pts[i], pts[i + 1], offsetDistance, offsetPts);\n }\n};\nOffsetPointGenerator.prototype.setSidesToGenerate = function setSidesToGenerate (doLeft, doRight) {\n this._doLeft = doLeft;\n this._doRight = doRight;\n};\nOffsetPointGenerator.prototype.getPoints = function getPoints (offsetDistance) {\n var this$1 = this;\n\n var offsetPts = new ArrayList();\n var lines = LinearComponentExtracter.getLines(this._g);\n for (var i = lines.iterator(); i.hasNext();) {\n var line = i.next();\n this$1.extractPoints(line, offsetDistance, offsetPts);\n }\n return offsetPts\n};\nOffsetPointGenerator.prototype.computeOffsetPoints = function computeOffsetPoints (p0, p1, offsetDistance, offsetPts) {\n var dx = p1.x - p0.x;\n var dy = p1.y - p0.y;\n var len = Math.sqrt(dx * dx + dy * dy);\n var ux = offsetDistance * dx / len;\n var uy = offsetDistance * dy / len;\n var midX = (p1.x + p0.x) / 2;\n var midY = (p1.y + p0.y) / 2;\n if (this._doLeft) {\n var offsetLeft = new Coordinate(midX - uy, midY + ux);\n offsetPts.add(offsetLeft);\n }\n if (this._doRight) {\n var offsetRight = new Coordinate(midX + uy, midY - ux);\n offsetPts.add(offsetRight);\n }\n};\nOffsetPointGenerator.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nOffsetPointGenerator.prototype.getClass = function getClass () {\n return OffsetPointGenerator\n};\n\nvar OverlayResultValidator = function OverlayResultValidator () {\n this._geom = null;\n this._locFinder = null;\n this._location = new Array(3).fill(null);\n this._invalidLocation = null;\n this._boundaryDistanceTolerance = OverlayResultValidator.TOLERANCE;\n this._testCoords = new ArrayList();\n var a = arguments[0];\n var b = arguments[1];\n var result = arguments[2];\n this._boundaryDistanceTolerance = OverlayResultValidator.computeBoundaryDistanceTolerance(a, b);\n this._geom = [a, b, result];\n this._locFinder = [new FuzzyPointLocator(this._geom[0], this._boundaryDistanceTolerance), new FuzzyPointLocator(this._geom[1], this._boundaryDistanceTolerance), new FuzzyPointLocator(this._geom[2], this._boundaryDistanceTolerance)];\n};\n\nvar staticAccessors$46 = { TOLERANCE: { configurable: true } };\nOverlayResultValidator.prototype.reportResult = function reportResult (overlayOp, location, expectedInterior) {\n System.out.println('Overlay result invalid - A:' + Location.toLocationSymbol(location[0]) + ' B:' + Location.toLocationSymbol(location[1]) + ' expected:' + (expectedInterior ? 'i' : 'e') + ' actual:' + Location.toLocationSymbol(location[2]));\n};\nOverlayResultValidator.prototype.isValid = function isValid (overlayOp) {\n this.addTestPts(this._geom[0]);\n this.addTestPts(this._geom[1]);\n var isValid = this.checkValid(overlayOp);\n return isValid\n};\nOverlayResultValidator.prototype.checkValid = function checkValid () {\n var this$1 = this;\n\n if (arguments.length === 1) {\n var overlayOp = arguments[0];\n for (var i = 0; i < this._testCoords.size(); i++) {\n var pt = this$1._testCoords.get(i);\n if (!this$1.checkValid(overlayOp, pt)) {\n this$1._invalidLocation = pt;\n return false\n }\n }\n return true\n } else if (arguments.length === 2) {\n var overlayOp$1 = arguments[0];\n var pt$1 = arguments[1];\n this._location[0] = this._locFinder[0].getLocation(pt$1);\n this._location[1] = this._locFinder[1].getLocation(pt$1);\n this._location[2] = this._locFinder[2].getLocation(pt$1);\n if (OverlayResultValidator.hasLocation(this._location, Location.BOUNDARY)) { return true }\n return this.isValidResult(overlayOp$1, this._location)\n }\n};\nOverlayResultValidator.prototype.addTestPts = function addTestPts (g) {\n var ptGen = new OffsetPointGenerator(g);\n this._testCoords.addAll(ptGen.getPoints(5 * this._boundaryDistanceTolerance));\n};\nOverlayResultValidator.prototype.isValidResult = function isValidResult (overlayOp, location) {\n var expectedInterior = OverlayOp.isResultOfOp(location[0], location[1], overlayOp);\n var resultInInterior = location[2] === Location.INTERIOR;\n var isValid = !(expectedInterior ^ resultInInterior);\n if (!isValid) { this.reportResult(overlayOp, location, expectedInterior); }\n return isValid\n};\nOverlayResultValidator.prototype.getInvalidLocation = function getInvalidLocation () {\n return this._invalidLocation\n};\nOverlayResultValidator.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nOverlayResultValidator.prototype.getClass = function getClass () {\n return OverlayResultValidator\n};\nOverlayResultValidator.hasLocation = function hasLocation (location, loc) {\n for (var i = 0; i < 3; i++) {\n if (location[i] === loc) { return true }\n }\n return false\n};\nOverlayResultValidator.computeBoundaryDistanceTolerance = function computeBoundaryDistanceTolerance (g0, g1) {\n return Math.min(GeometrySnapper.computeSizeBasedSnapTolerance(g0), GeometrySnapper.computeSizeBasedSnapTolerance(g1))\n};\nOverlayResultValidator.isValid = function isValid (a, b, overlayOp, result) {\n var validator = new OverlayResultValidator(a, b, result);\n return validator.isValid(overlayOp)\n};\nstaticAccessors$46.TOLERANCE.get = function () { return 0.000001 };\n\nObject.defineProperties( OverlayResultValidator, staticAccessors$46 );\n\n// operation.overlay\n\nvar GeometryCombiner = function GeometryCombiner (geoms) {\n this._geomFactory = null;\n this._skipEmpty = false;\n this._inputGeoms = null;\n this._geomFactory = GeometryCombiner.extractFactory(geoms);\n this._inputGeoms = geoms;\n};\nGeometryCombiner.prototype.extractElements = function extractElements (geom, elems) {\n var this$1 = this;\n\n if (geom === null) { return null }\n for (var i = 0; i < geom.getNumGeometries(); i++) {\n var elemGeom = geom.getGeometryN(i);\n if (this$1._skipEmpty && elemGeom.isEmpty()) { continue }\n elems.add(elemGeom);\n }\n};\nGeometryCombiner.prototype.combine = function combine () {\n var this$1 = this;\n\n var elems = new ArrayList();\n for (var i = this._inputGeoms.iterator(); i.hasNext();) {\n var g = i.next();\n this$1.extractElements(g, elems);\n }\n if (elems.size() === 0) {\n if (this._geomFactory !== null) {\n return this._geomFactory.createGeometryCollection(null)\n }\n return null\n }\n return this._geomFactory.buildGeometry(elems)\n};\nGeometryCombiner.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nGeometryCombiner.prototype.getClass = function getClass () {\n return GeometryCombiner\n};\nGeometryCombiner.combine = function combine () {\n if (arguments.length === 1) {\n var geoms = arguments[0];\n var combiner = new GeometryCombiner(geoms);\n return combiner.combine()\n } else if (arguments.length === 2) {\n var g0 = arguments[0];\n var g1 = arguments[1];\n var combiner$1 = new GeometryCombiner(GeometryCombiner.createList(g0, g1));\n return combiner$1.combine()\n } else if (arguments.length === 3) {\n var g0$1 = arguments[0];\n var g1$1 = arguments[1];\n var g2 = arguments[2];\n var combiner$2 = new GeometryCombiner(GeometryCombiner.createList(g0$1, g1$1, g2));\n return combiner$2.combine()\n }\n};\nGeometryCombiner.extractFactory = function extractFactory (geoms) {\n if (geoms.isEmpty()) { return null }\n return geoms.iterator().next().getFactory()\n};\nGeometryCombiner.createList = function createList () {\n if (arguments.length === 2) {\n var obj0 = arguments[0];\n var obj1 = arguments[1];\n var list = new ArrayList();\n list.add(obj0);\n list.add(obj1);\n return list\n } else if (arguments.length === 3) {\n var obj0$1 = arguments[0];\n var obj1$1 = arguments[1];\n var obj2 = arguments[2];\n var list$1 = new ArrayList();\n list$1.add(obj0$1);\n list$1.add(obj1$1);\n list$1.add(obj2);\n return list$1\n }\n};\n\nvar CascadedPolygonUnion = function CascadedPolygonUnion () {\n this._inputPolys = null;\n this._geomFactory = null;\n var polys = arguments[0];\n this._inputPolys = polys;\n if (this._inputPolys === null) { this._inputPolys = new ArrayList(); }\n};\n\nvar staticAccessors$47 = { STRTREE_NODE_CAPACITY: { configurable: true } };\nCascadedPolygonUnion.prototype.reduceToGeometries = function reduceToGeometries (geomTree) {\n var this$1 = this;\n\n var geoms = new ArrayList();\n for (var i = geomTree.iterator(); i.hasNext();) {\n var o = i.next();\n var geom = null;\n if (hasInterface(o, List)) {\n geom = this$1.unionTree(o);\n } else if (o instanceof Geometry) {\n geom = o;\n }\n geoms.add(geom);\n }\n return geoms\n};\nCascadedPolygonUnion.prototype.extractByEnvelope = function extractByEnvelope (env, geom, disjointGeoms) {\n var intersectingGeoms = new ArrayList();\n for (var i = 0; i < geom.getNumGeometries(); i++) {\n var elem = geom.getGeometryN(i);\n if (elem.getEnvelopeInternal().intersects(env)) { intersectingGeoms.add(elem); } else { disjointGeoms.add(elem); }\n }\n return this._geomFactory.buildGeometry(intersectingGeoms)\n};\nCascadedPolygonUnion.prototype.unionOptimized = function unionOptimized (g0, g1) {\n var g0Env = g0.getEnvelopeInternal();\n var g1Env = g1.getEnvelopeInternal();\n if (!g0Env.intersects(g1Env)) {\n var combo = GeometryCombiner.combine(g0, g1);\n return combo\n }\n if (g0.getNumGeometries() <= 1 && g1.getNumGeometries() <= 1) { return this.unionActual(g0, g1) }\n var commonEnv = g0Env.intersection(g1Env);\n return this.unionUsingEnvelopeIntersection(g0, g1, commonEnv)\n};\nCascadedPolygonUnion.prototype.union = function union () {\n if (this._inputPolys === null) { throw new Error('union() method cannot be called twice') }\n if (this._inputPolys.isEmpty()) { return null }\n this._geomFactory = this._inputPolys.iterator().next().getFactory();\n var index = new STRtree(CascadedPolygonUnion.STRTREE_NODE_CAPACITY);\n for (var i = this._inputPolys.iterator(); i.hasNext();) {\n var item = i.next();\n index.insert(item.getEnvelopeInternal(), item);\n }\n this._inputPolys = null;\n var itemTree = index.itemsTree();\n var unionAll = this.unionTree(itemTree);\n return unionAll\n};\nCascadedPolygonUnion.prototype.binaryUnion = function binaryUnion () {\n if (arguments.length === 1) {\n var geoms = arguments[0];\n return this.binaryUnion(geoms, 0, geoms.size())\n } else if (arguments.length === 3) {\n var geoms$1 = arguments[0];\n var start = arguments[1];\n var end = arguments[2];\n if (end - start <= 1) {\n var g0 = CascadedPolygonUnion.getGeometry(geoms$1, start);\n return this.unionSafe(g0, null)\n } else if (end - start === 2) {\n return this.unionSafe(CascadedPolygonUnion.getGeometry(geoms$1, start), CascadedPolygonUnion.getGeometry(geoms$1, start + 1))\n } else {\n var mid = Math.trunc((end + start) / 2);\n var g0$1 = this.binaryUnion(geoms$1, start, mid);\n var g1 = this.binaryUnion(geoms$1, mid, end);\n return this.unionSafe(g0$1, g1)\n }\n }\n};\nCascadedPolygonUnion.prototype.repeatedUnion = function repeatedUnion (geoms) {\n var union = null;\n for (var i = geoms.iterator(); i.hasNext();) {\n var g = i.next();\n if (union === null) { union = g.copy(); } else { union = union.union(g); }\n }\n return union\n};\nCascadedPolygonUnion.prototype.unionSafe = function unionSafe (g0, g1) {\n if (g0 === null && g1 === null) { return null }\n if (g0 === null) { return g1.copy() }\n if (g1 === null) { return g0.copy() }\n return this.unionOptimized(g0, g1)\n};\nCascadedPolygonUnion.prototype.unionActual = function unionActual (g0, g1) {\n return CascadedPolygonUnion.restrictToPolygons(g0.union(g1))\n};\nCascadedPolygonUnion.prototype.unionTree = function unionTree (geomTree) {\n var geoms = this.reduceToGeometries(geomTree);\n var union = this.binaryUnion(geoms);\n return union\n};\nCascadedPolygonUnion.prototype.unionUsingEnvelopeIntersection = function unionUsingEnvelopeIntersection (g0, g1, common) {\n var disjointPolys = new ArrayList();\n var g0Int = this.extractByEnvelope(common, g0, disjointPolys);\n var g1Int = this.extractByEnvelope(common, g1, disjointPolys);\n var union = this.unionActual(g0Int, g1Int);\n disjointPolys.add(union);\n var overallUnion = GeometryCombiner.combine(disjointPolys);\n return overallUnion\n};\nCascadedPolygonUnion.prototype.bufferUnion = function bufferUnion () {\n if (arguments.length === 1) {\n var geoms = arguments[0];\n var factory = geoms.get(0).getFactory();\n var gColl = factory.buildGeometry(geoms);\n var unionAll = gColl.buffer(0.0);\n return unionAll\n } else if (arguments.length === 2) {\n var g0 = arguments[0];\n var g1 = arguments[1];\n var factory$1 = g0.getFactory();\n var gColl$1 = factory$1.createGeometryCollection([g0, g1]);\n var unionAll$1 = gColl$1.buffer(0.0);\n return unionAll$1\n }\n};\nCascadedPolygonUnion.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nCascadedPolygonUnion.prototype.getClass = function getClass () {\n return CascadedPolygonUnion\n};\nCascadedPolygonUnion.restrictToPolygons = function restrictToPolygons (g) {\n if (hasInterface(g, Polygonal)) {\n return g\n }\n var polygons = PolygonExtracter.getPolygons(g);\n if (polygons.size() === 1) { return polygons.get(0) }\n return g.getFactory().createMultiPolygon(GeometryFactory.toPolygonArray(polygons))\n};\nCascadedPolygonUnion.getGeometry = function getGeometry (list, index) {\n if (index >= list.size()) { return null }\n return list.get(index)\n};\nCascadedPolygonUnion.union = function union (polys) {\n var op = new CascadedPolygonUnion(polys);\n return op.union()\n};\nstaticAccessors$47.STRTREE_NODE_CAPACITY.get = function () { return 4 };\n\nObject.defineProperties( CascadedPolygonUnion, staticAccessors$47 );\n\nvar UnionOp = function UnionOp () {};\n\nUnionOp.prototype.interfaces_ = function interfaces_ () {\n return []\n};\nUnionOp.prototype.getClass = function getClass () {\n return UnionOp\n};\nUnionOp.union = function union (g, other) {\n if (g.isEmpty() || other.isEmpty()) {\n if (g.isEmpty() && other.isEmpty()) { return OverlayOp.createEmptyResult(OverlayOp.UNION, g, other, g.getFactory()) }\n if (g.isEmpty()) { return other.copy() }\n if (other.isEmpty()) { return g.copy() }\n }\n g.checkNotGeometryCollection(g);\n g.checkNotGeometryCollection(other);\n return SnapIfNeededOverlayOp.overlayOp(g, other, OverlayOp.UNION)\n};\n\n// operation.union\n\n// operation\n\n/**\n * Polyfill for IE support\n */\n\nexport { GeoJSONReader, GeoJSONWriter, OverlayOp, UnionOp, BufferOp };\n","/**\n * Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth.\n */\nvar earthRadius = 6371008.8;\n\n/**\n * Unit of measurement factors using a spherical (non-ellipsoid) earth radius.\n */\nvar factors = {\n meters: earthRadius,\n metres: earthRadius,\n millimeters: earthRadius * 1000,\n millimetres: earthRadius * 1000,\n centimeters: earthRadius * 100,\n centimetres: earthRadius * 100,\n kilometers: earthRadius / 1000,\n kilometres: earthRadius / 1000,\n miles: earthRadius / 1609.344,\n nauticalmiles: earthRadius / 1852,\n inches: earthRadius * 39.370,\n yards: earthRadius / 1.0936,\n feet: earthRadius * 3.28084,\n radians: 1,\n degrees: earthRadius / 111325,\n};\n\n/**\n * Units of measurement factors based on 1 meter.\n */\nvar unitsFactors = {\n meters: 1,\n metres: 1,\n millimeters: 1000,\n millimetres: 1000,\n centimeters: 100,\n centimetres: 100,\n kilometers: 1 / 1000,\n kilometres: 1 / 1000,\n miles: 1 / 1609.344,\n nauticalmiles: 1 / 1852,\n inches: 39.370,\n yards: 1 / 1.0936,\n feet: 3.28084,\n radians: 1 / earthRadius,\n degrees: 1 / 111325,\n};\n\n/**\n * Area of measurement factors based on 1 square meter.\n */\nvar areaFactors = {\n meters: 1,\n metres: 1,\n millimeters: 1000000,\n millimetres: 1000000,\n centimeters: 10000,\n centimetres: 10000,\n kilometers: 0.000001,\n kilometres: 0.000001,\n acres: 0.000247105,\n miles: 3.86e-7,\n yards: 1.195990046,\n feet: 10.763910417,\n inches: 1550.003100006\n};\n\n/**\n * Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}.\n *\n * @name feature\n * @param {Geometry} geometry input geometry\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature} a GeoJSON Feature\n * @example\n * var geometry = {\n * \"type\": \"Point\",\n * \"coordinates\": [110, 50]\n * };\n *\n * var feature = turf.feature(geometry);\n *\n * //=feature\n */\nfunction feature(geometry, properties, options) {\n // Optional Parameters\n options = options || {};\n if (!isObject(options)) throw new Error('options is invalid');\n var bbox = options.bbox;\n var id = options.id;\n\n // Validation\n if (geometry === undefined) throw new Error('geometry is required');\n if (properties && properties.constructor !== Object) throw new Error('properties must be an Object');\n if (bbox) validateBBox(bbox);\n if (id) validateId(id);\n\n // Main\n var feat = {type: 'Feature'};\n if (id) feat.id = id;\n if (bbox) feat.bbox = bbox;\n feat.properties = properties || {};\n feat.geometry = geometry;\n return feat;\n}\n\n/**\n * Creates a GeoJSON {@link Geometry} from a Geometry string type & coordinates.\n * For GeometryCollection type use `helpers.geometryCollection`\n *\n * @name geometry\n * @param {string} type Geometry Type\n * @param {Array} coordinates Coordinates\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Geometry\n * @returns {Geometry} a GeoJSON Geometry\n * @example\n * var type = 'Point';\n * var coordinates = [110, 50];\n *\n * var geometry = turf.geometry(type, coordinates);\n *\n * //=geometry\n */\nfunction geometry(type, coordinates, options) {\n // Optional Parameters\n options = options || {};\n if (!isObject(options)) throw new Error('options is invalid');\n var bbox = options.bbox;\n\n // Validation\n if (!type) throw new Error('type is required');\n if (!coordinates) throw new Error('coordinates is required');\n if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');\n if (bbox) validateBBox(bbox);\n\n // Main\n var geom;\n switch (type) {\n case 'Point': geom = point(coordinates).geometry; break;\n case 'LineString': geom = lineString(coordinates).geometry; break;\n case 'Polygon': geom = polygon(coordinates).geometry; break;\n case 'MultiPoint': geom = multiPoint(coordinates).geometry; break;\n case 'MultiLineString': geom = multiLineString(coordinates).geometry; break;\n case 'MultiPolygon': geom = multiPolygon(coordinates).geometry; break;\n default: throw new Error(type + ' is invalid');\n }\n if (bbox) geom.bbox = bbox;\n return geom;\n}\n\n/**\n * Creates a {@link Point} {@link Feature} from a Position.\n *\n * @name point\n * @param {Array} coordinates longitude, latitude position (each in decimal degrees)\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature} a Point feature\n * @example\n * var point = turf.point([-75.343, 39.984]);\n *\n * //=point\n */\nfunction point(coordinates, properties, options) {\n if (!coordinates) throw new Error('coordinates is required');\n if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');\n if (coordinates.length < 2) throw new Error('coordinates must be at least 2 numbers long');\n if (!isNumber(coordinates[0]) || !isNumber(coordinates[1])) throw new Error('coordinates must contain numbers');\n\n return feature({\n type: 'Point',\n coordinates: coordinates\n }, properties, options);\n}\n\n/**\n * Creates a {@link Point} {@link FeatureCollection} from an Array of Point coordinates.\n *\n * @name points\n * @param {Array>} coordinates an array of Points\n * @param {Object} [properties={}] Translate these properties to each Feature\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the FeatureCollection\n * @param {string|number} [options.id] Identifier associated with the FeatureCollection\n * @returns {FeatureCollection} Point Feature\n * @example\n * var points = turf.points([\n * [-75, 39],\n * [-80, 45],\n * [-78, 50]\n * ]);\n *\n * //=points\n */\nfunction points(coordinates, properties, options) {\n if (!coordinates) throw new Error('coordinates is required');\n if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');\n\n return featureCollection(coordinates.map(function (coords) {\n return point(coords, properties);\n }), options);\n}\n\n/**\n * Creates a {@link Polygon} {@link Feature} from an Array of LinearRings.\n *\n * @name polygon\n * @param {Array>>} coordinates an array of LinearRings\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature} Polygon Feature\n * @example\n * var polygon = turf.polygon([[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]], { name: 'poly1' });\n *\n * //=polygon\n */\nfunction polygon(coordinates, properties, options) {\n if (!coordinates) throw new Error('coordinates is required');\n\n for (var i = 0; i < coordinates.length; i++) {\n var ring = coordinates[i];\n if (ring.length < 4) {\n throw new Error('Each LinearRing of a Polygon must have 4 or more Positions.');\n }\n for (var j = 0; j < ring[ring.length - 1].length; j++) {\n // Check if first point of Polygon contains two numbers\n if (i === 0 && j === 0 && !isNumber(ring[0][0]) || !isNumber(ring[0][1])) throw new Error('coordinates must contain numbers');\n if (ring[ring.length - 1][j] !== ring[0][j]) {\n throw new Error('First and last Position are not equivalent.');\n }\n }\n }\n\n return feature({\n type: 'Polygon',\n coordinates: coordinates\n }, properties, options);\n}\n\n/**\n * Creates a {@link Polygon} {@link FeatureCollection} from an Array of Polygon coordinates.\n *\n * @name polygons\n * @param {Array>>>} coordinates an array of Polygon coordinates\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the FeatureCollection\n * @returns {FeatureCollection} Polygon FeatureCollection\n * @example\n * var polygons = turf.polygons([\n * [[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]],\n * [[[-15, 42], [-14, 46], [-12, 41], [-17, 44], [-15, 42]]],\n * ]);\n *\n * //=polygons\n */\nfunction polygons(coordinates, properties, options) {\n if (!coordinates) throw new Error('coordinates is required');\n if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');\n\n return featureCollection(coordinates.map(function (coords) {\n return polygon(coords, properties);\n }), options);\n}\n\n/**\n * Creates a {@link LineString} {@link Feature} from an Array of Positions.\n *\n * @name lineString\n * @param {Array>} coordinates an array of Positions\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature} LineString Feature\n * @example\n * var linestring1 = turf.lineString([[-24, 63], [-23, 60], [-25, 65], [-20, 69]], {name: 'line 1'});\n * var linestring2 = turf.lineString([[-14, 43], [-13, 40], [-15, 45], [-10, 49]], {name: 'line 2'});\n *\n * //=linestring1\n * //=linestring2\n */\nfunction lineString(coordinates, properties, options) {\n if (!coordinates) throw new Error('coordinates is required');\n if (coordinates.length < 2) throw new Error('coordinates must be an array of two or more positions');\n // Check if first point of LineString contains two numbers\n if (!isNumber(coordinates[0][1]) || !isNumber(coordinates[0][1])) throw new Error('coordinates must contain numbers');\n\n return feature({\n type: 'LineString',\n coordinates: coordinates\n }, properties, options);\n}\n\n/**\n * Creates a {@link LineString} {@link FeatureCollection} from an Array of LineString coordinates.\n *\n * @name lineStrings\n * @param {Array>} coordinates an array of LinearRings\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the FeatureCollection\n * @param {string|number} [options.id] Identifier associated with the FeatureCollection\n * @returns {FeatureCollection} LineString FeatureCollection\n * @example\n * var linestrings = turf.lineStrings([\n * [[-24, 63], [-23, 60], [-25, 65], [-20, 69]],\n * [[-14, 43], [-13, 40], [-15, 45], [-10, 49]]\n * ]);\n *\n * //=linestrings\n */\nfunction lineStrings(coordinates, properties, options) {\n if (!coordinates) throw new Error('coordinates is required');\n if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');\n\n return featureCollection(coordinates.map(function (coords) {\n return lineString(coords, properties);\n }), options);\n}\n\n/**\n * Takes one or more {@link Feature|Features} and creates a {@link FeatureCollection}.\n *\n * @name featureCollection\n * @param {Feature[]} features input features\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {FeatureCollection} FeatureCollection of Features\n * @example\n * var locationA = turf.point([-75.343, 39.984], {name: 'Location A'});\n * var locationB = turf.point([-75.833, 39.284], {name: 'Location B'});\n * var locationC = turf.point([-75.534, 39.123], {name: 'Location C'});\n *\n * var collection = turf.featureCollection([\n * locationA,\n * locationB,\n * locationC\n * ]);\n *\n * //=collection\n */\nfunction featureCollection(features, options) {\n // Optional Parameters\n options = options || {};\n if (!isObject(options)) throw new Error('options is invalid');\n var bbox = options.bbox;\n var id = options.id;\n\n // Validation\n if (!features) throw new Error('No features passed');\n if (!Array.isArray(features)) throw new Error('features must be an Array');\n if (bbox) validateBBox(bbox);\n if (id) validateId(id);\n\n // Main\n var fc = {type: 'FeatureCollection'};\n if (id) fc.id = id;\n if (bbox) fc.bbox = bbox;\n fc.features = features;\n return fc;\n}\n\n/**\n * Creates a {@link Feature} based on a\n * coordinate array. Properties can be added optionally.\n *\n * @name multiLineString\n * @param {Array>>} coordinates an array of LineStrings\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature} a MultiLineString feature\n * @throws {Error} if no coordinates are passed\n * @example\n * var multiLine = turf.multiLineString([[[0,0],[10,10]]]);\n *\n * //=multiLine\n */\nfunction multiLineString(coordinates, properties, options) {\n if (!coordinates) throw new Error('coordinates is required');\n\n return feature({\n type: 'MultiLineString',\n coordinates: coordinates\n }, properties, options);\n}\n\n/**\n * Creates a {@link Feature} based on a\n * coordinate array. Properties can be added optionally.\n *\n * @name multiPoint\n * @param {Array>} coordinates an array of Positions\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature} a MultiPoint feature\n * @throws {Error} if no coordinates are passed\n * @example\n * var multiPt = turf.multiPoint([[0,0],[10,10]]);\n *\n * //=multiPt\n */\nfunction multiPoint(coordinates, properties, options) {\n if (!coordinates) throw new Error('coordinates is required');\n\n return feature({\n type: 'MultiPoint',\n coordinates: coordinates\n }, properties, options);\n}\n\n/**\n * Creates a {@link Feature} based on a\n * coordinate array. Properties can be added optionally.\n *\n * @name multiPolygon\n * @param {Array>>>} coordinates an array of Polygons\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature} a multipolygon feature\n * @throws {Error} if no coordinates are passed\n * @example\n * var multiPoly = turf.multiPolygon([[[[0,0],[0,10],[10,10],[10,0],[0,0]]]]);\n *\n * //=multiPoly\n *\n */\nfunction multiPolygon(coordinates, properties, options) {\n if (!coordinates) throw new Error('coordinates is required');\n\n return feature({\n type: 'MultiPolygon',\n coordinates: coordinates\n }, properties, options);\n}\n\n/**\n * Creates a {@link Feature} based on a\n * coordinate array. Properties can be added optionally.\n *\n * @name geometryCollection\n * @param {Array} geometries an array of GeoJSON Geometries\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature} a GeoJSON GeometryCollection Feature\n * @example\n * var pt = {\n * \"type\": \"Point\",\n * \"coordinates\": [100, 0]\n * };\n * var line = {\n * \"type\": \"LineString\",\n * \"coordinates\": [ [101, 0], [102, 1] ]\n * };\n * var collection = turf.geometryCollection([pt, line]);\n *\n * //=collection\n */\nfunction geometryCollection(geometries, properties, options) {\n if (!geometries) throw new Error('geometries is required');\n if (!Array.isArray(geometries)) throw new Error('geometries must be an Array');\n\n return feature({\n type: 'GeometryCollection',\n geometries: geometries\n }, properties, options);\n}\n\n/**\n * Round number to precision\n *\n * @param {number} num Number\n * @param {number} [precision=0] Precision\n * @returns {number} rounded number\n * @example\n * turf.round(120.4321)\n * //=120\n *\n * turf.round(120.4321, 2)\n * //=120.43\n */\nfunction round(num, precision) {\n if (num === undefined || num === null || isNaN(num)) throw new Error('num is required');\n if (precision && !(precision >= 0)) throw new Error('precision must be a positive number');\n var multiplier = Math.pow(10, precision || 0);\n return Math.round(num * multiplier) / multiplier;\n}\n\n/**\n * Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.\n * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet\n *\n * @name radiansToLength\n * @param {number} radians in radians across the sphere\n * @param {string} [units='kilometers'] can be degrees, radians, miles, or kilometers inches, yards, metres, meters, kilometres, kilometers.\n * @returns {number} distance\n */\nfunction radiansToLength(radians, units) {\n if (radians === undefined || radians === null) throw new Error('radians is required');\n\n if (units && typeof units !== 'string') throw new Error('units must be a string');\n var factor = factors[units || 'kilometers'];\n if (!factor) throw new Error(units + ' units is invalid');\n return radians * factor;\n}\n\n/**\n * Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians\n * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet\n *\n * @name lengthToRadians\n * @param {number} distance in real units\n * @param {string} [units='kilometers'] can be degrees, radians, miles, or kilometers inches, yards, metres, meters, kilometres, kilometers.\n * @returns {number} radians\n */\nfunction lengthToRadians(distance, units) {\n if (distance === undefined || distance === null) throw new Error('distance is required');\n\n if (units && typeof units !== 'string') throw new Error('units must be a string');\n var factor = factors[units || 'kilometers'];\n if (!factor) throw new Error(units + ' units is invalid');\n return distance / factor;\n}\n\n/**\n * Convert a distance measurement (assuming a spherical Earth) from a real-world unit into degrees\n * Valid units: miles, nauticalmiles, inches, yards, meters, metres, centimeters, kilometres, feet\n *\n * @name lengthToDegrees\n * @param {number} distance in real units\n * @param {string} [units='kilometers'] can be degrees, radians, miles, or kilometers inches, yards, metres, meters, kilometres, kilometers.\n * @returns {number} degrees\n */\nfunction lengthToDegrees(distance, units) {\n return radiansToDegrees(lengthToRadians(distance, units));\n}\n\n/**\n * Converts any bearing angle from the north line direction (positive clockwise)\n * and returns an angle between 0-360 degrees (positive clockwise), 0 being the north line\n *\n * @name bearingToAzimuth\n * @param {number} bearing angle, between -180 and +180 degrees\n * @returns {number} angle between 0 and 360 degrees\n */\nfunction bearingToAzimuth(bearing) {\n if (bearing === null || bearing === undefined) throw new Error('bearing is required');\n\n var angle = bearing % 360;\n if (angle < 0) angle += 360;\n return angle;\n}\n\n/**\n * Converts an angle in radians to degrees\n *\n * @name radiansToDegrees\n * @param {number} radians angle in radians\n * @returns {number} degrees between 0 and 360 degrees\n */\nfunction radiansToDegrees(radians) {\n if (radians === null || radians === undefined) throw new Error('radians is required');\n\n var degrees = radians % (2 * Math.PI);\n return degrees * 180 / Math.PI;\n}\n\n/**\n * Converts an angle in degrees to radians\n *\n * @name degreesToRadians\n * @param {number} degrees angle between 0 and 360 degrees\n * @returns {number} angle in radians\n */\nfunction degreesToRadians(degrees) {\n if (degrees === null || degrees === undefined) throw new Error('degrees is required');\n\n var radians = degrees % 360;\n return radians * Math.PI / 180;\n}\n\n/**\n * Converts a length to the requested unit.\n * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet\n *\n * @param {number} length to be converted\n * @param {string} originalUnit of the length\n * @param {string} [finalUnit='kilometers'] returned unit\n * @returns {number} the converted length\n */\nfunction convertLength(length, originalUnit, finalUnit) {\n if (length === null || length === undefined) throw new Error('length is required');\n if (!(length >= 0)) throw new Error('length must be a positive number');\n\n return radiansToLength(lengthToRadians(length, originalUnit), finalUnit || 'kilometers');\n}\n\n/**\n * Converts a area to the requested unit.\n * Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches\n * @param {number} area to be converted\n * @param {string} [originalUnit='meters'] of the distance\n * @param {string} [finalUnit='kilometers'] returned unit\n * @returns {number} the converted distance\n */\nfunction convertArea(area, originalUnit, finalUnit) {\n if (area === null || area === undefined) throw new Error('area is required');\n if (!(area >= 0)) throw new Error('area must be a positive number');\n\n var startFactor = areaFactors[originalUnit || 'meters'];\n if (!startFactor) throw new Error('invalid original units');\n\n var finalFactor = areaFactors[finalUnit || 'kilometers'];\n if (!finalFactor) throw new Error('invalid final units');\n\n return (area / startFactor) * finalFactor;\n}\n\n/**\n * isNumber\n *\n * @param {*} num Number to validate\n * @returns {boolean} true/false\n * @example\n * turf.isNumber(123)\n * //=true\n * turf.isNumber('foo')\n * //=false\n */\nfunction isNumber(num) {\n return !isNaN(num) && num !== null && !Array.isArray(num);\n}\n\n/**\n * isObject\n *\n * @param {*} input variable to validate\n * @returns {boolean} true/false\n * @example\n * turf.isObject({elevation: 10})\n * //=true\n * turf.isObject('foo')\n * //=false\n */\nfunction isObject(input) {\n return (!!input) && (input.constructor === Object);\n}\n\n/**\n * Validate BBox\n *\n * @private\n * @param {Array} bbox BBox to validate\n * @returns {void}\n * @throws Error if BBox is not valid\n * @example\n * validateBBox([-180, -40, 110, 50])\n * //=OK\n * validateBBox([-180, -40])\n * //=Error\n * validateBBox('Foo')\n * //=Error\n * validateBBox(5)\n * //=Error\n * validateBBox(null)\n * //=Error\n * validateBBox(undefined)\n * //=Error\n */\nfunction validateBBox(bbox) {\n if (!bbox) throw new Error('bbox is required');\n if (!Array.isArray(bbox)) throw new Error('bbox must be an Array');\n if (bbox.length !== 4 && bbox.length !== 6) throw new Error('bbox must be an Array of 4 or 6 numbers');\n bbox.forEach(function (num) {\n if (!isNumber(num)) throw new Error('bbox must only contain numbers');\n });\n}\n\n/**\n * Validate Id\n *\n * @private\n * @param {string|number} id Id to validate\n * @returns {void}\n * @throws Error if Id is not valid\n * @example\n * validateId([-180, -40, 110, 50])\n * //=Error\n * validateId([-180, -40])\n * //=Error\n * validateId('Foo')\n * //=OK\n * validateId(5)\n * //=OK\n * validateId(null)\n * //=Error\n * validateId(undefined)\n * //=Error\n */\nfunction validateId(id) {\n if (!id) throw new Error('id is required');\n if (['string', 'number'].indexOf(typeof id) === -1) throw new Error('id must be a number or a string');\n}\n\n// Deprecated methods\nfunction radians2degrees() {\n throw new Error('method has been renamed to `radiansToDegrees`');\n}\n\nfunction degrees2radians() {\n throw new Error('method has been renamed to `degreesToRadians`');\n}\n\nfunction distanceToDegrees() {\n throw new Error('method has been renamed to `lengthToDegrees`');\n}\n\nfunction distanceToRadians() {\n throw new Error('method has been renamed to `lengthToRadians`');\n}\n\nfunction radiansToDistance() {\n throw new Error('method has been renamed to `radiansToLength`');\n}\n\nfunction bearingToAngle() {\n throw new Error('method has been renamed to `bearingToAzimuth`');\n}\n\nfunction convertDistance() {\n throw new Error('method has been renamed to `convertLength`');\n}\n\nexport { earthRadius, factors, unitsFactors, areaFactors, feature, geometry, point, points, polygon, polygons, lineString, lineStrings, featureCollection, multiLineString, multiPoint, multiPolygon, geometryCollection, round, radiansToLength, lengthToRadians, lengthToDegrees, bearingToAzimuth, radiansToDegrees, degreesToRadians, convertLength, convertArea, isNumber, isObject, validateBBox, validateId, radians2degrees, degrees2radians, distanceToDegrees, distanceToRadians, radiansToDistance, bearingToAngle, convertDistance };\n","import { feature, isObject, lineString, point } from '@turf/helpers';\n\n/**\n * Callback for coordEach\n *\n * @callback coordEachCallback\n * @param {Array} currentCoord The current coordinate being processed.\n * @param {number} coordIndex The current index of the coordinate being processed.\n * @param {number} featureIndex The current index of the Feature being processed.\n * @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.\n * @param {number} geometryIndex The current index of the Geometry being processed.\n */\n\n/**\n * Iterate over coordinates in any GeoJSON object, similar to Array.forEach()\n *\n * @name coordEach\n * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object\n * @param {Function} callback a method that takes (currentCoord, coordIndex, featureIndex, multiFeatureIndex)\n * @param {boolean} [excludeWrapCoord=false] whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration.\n * @returns {void}\n * @example\n * var features = turf.featureCollection([\n * turf.point([26, 37], {\"foo\": \"bar\"}),\n * turf.point([36, 53], {\"hello\": \"world\"})\n * ]);\n *\n * turf.coordEach(features, function (currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {\n * //=currentCoord\n * //=coordIndex\n * //=featureIndex\n * //=multiFeatureIndex\n * //=geometryIndex\n * });\n */\nfunction coordEach(geojson, callback, excludeWrapCoord) {\n // Handles null Geometry -- Skips this GeoJSON\n if (geojson === null) return;\n var j, k, l, geometry, stopG, coords,\n geometryMaybeCollection,\n wrapShrink = 0,\n coordIndex = 0,\n isGeometryCollection,\n type = geojson.type,\n isFeatureCollection = type === 'FeatureCollection',\n isFeature = type === 'Feature',\n stop = isFeatureCollection ? geojson.features.length : 1;\n\n // This logic may look a little weird. The reason why it is that way\n // is because it's trying to be fast. GeoJSON supports multiple kinds\n // of objects at its root: FeatureCollection, Features, Geometries.\n // This function has the responsibility of handling all of them, and that\n // means that some of the `for` loops you see below actually just don't apply\n // to certain inputs. For instance, if you give this just a\n // Point geometry, then both loops are short-circuited and all we do\n // is gradually rename the input until it's called 'geometry'.\n //\n // This also aims to allocate as few resources as possible: just a\n // few numbers and booleans, rather than any temporary arrays as would\n // be required with the normalization approach.\n for (var featureIndex = 0; featureIndex < stop; featureIndex++) {\n geometryMaybeCollection = (isFeatureCollection ? geojson.features[featureIndex].geometry :\n (isFeature ? geojson.geometry : geojson));\n isGeometryCollection = (geometryMaybeCollection) ? geometryMaybeCollection.type === 'GeometryCollection' : false;\n stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;\n\n for (var geomIndex = 0; geomIndex < stopG; geomIndex++) {\n var multiFeatureIndex = 0;\n var geometryIndex = 0;\n geometry = isGeometryCollection ?\n geometryMaybeCollection.geometries[geomIndex] : geometryMaybeCollection;\n\n // Handles null Geometry -- Skips this geometry\n if (geometry === null) continue;\n coords = geometry.coordinates;\n var geomType = geometry.type;\n\n wrapShrink = (excludeWrapCoord && (geomType === 'Polygon' || geomType === 'MultiPolygon')) ? 1 : 0;\n\n switch (geomType) {\n case null:\n break;\n case 'Point':\n if (callback(coords, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;\n coordIndex++;\n multiFeatureIndex++;\n break;\n case 'LineString':\n case 'MultiPoint':\n for (j = 0; j < coords.length; j++) {\n if (callback(coords[j], coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;\n coordIndex++;\n if (geomType === 'MultiPoint') multiFeatureIndex++;\n }\n if (geomType === 'LineString') multiFeatureIndex++;\n break;\n case 'Polygon':\n case 'MultiLineString':\n for (j = 0; j < coords.length; j++) {\n for (k = 0; k < coords[j].length - wrapShrink; k++) {\n if (callback(coords[j][k], coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;\n coordIndex++;\n }\n if (geomType === 'MultiLineString') multiFeatureIndex++;\n if (geomType === 'Polygon') geometryIndex++;\n }\n if (geomType === 'Polygon') multiFeatureIndex++;\n break;\n case 'MultiPolygon':\n for (j = 0; j < coords.length; j++) {\n if (geomType === 'MultiPolygon') geometryIndex = 0;\n for (k = 0; k < coords[j].length; k++) {\n for (l = 0; l < coords[j][k].length - wrapShrink; l++) {\n if (callback(coords[j][k][l], coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;\n coordIndex++;\n }\n geometryIndex++;\n }\n multiFeatureIndex++;\n }\n break;\n case 'GeometryCollection':\n for (j = 0; j < geometry.geometries.length; j++)\n if (coordEach(geometry.geometries[j], callback, excludeWrapCoord) === false) return false;\n break;\n default:\n throw new Error('Unknown Geometry Type');\n }\n }\n }\n}\n\n/**\n * Callback for coordReduce\n *\n * The first time the callback function is called, the values provided as arguments depend\n * on whether the reduce method has an initialValue argument.\n *\n * If an initialValue is provided to the reduce method:\n * - The previousValue argument is initialValue.\n * - The currentValue argument is the value of the first element present in the array.\n *\n * If an initialValue is not provided:\n * - The previousValue argument is the value of the first element present in the array.\n * - The currentValue argument is the value of the second element present in the array.\n *\n * @callback coordReduceCallback\n * @param {*} previousValue The accumulated value previously returned in the last invocation\n * of the callback, or initialValue, if supplied.\n * @param {Array} currentCoord The current coordinate being processed.\n * @param {number} coordIndex The current index of the coordinate being processed.\n * Starts at index 0, if an initialValue is provided, and at index 1 otherwise.\n * @param {number} featureIndex The current index of the Feature being processed.\n * @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.\n * @param {number} geometryIndex The current index of the Geometry being processed.\n */\n\n/**\n * Reduce coordinates in any GeoJSON object, similar to Array.reduce()\n *\n * @name coordReduce\n * @param {FeatureCollection|Geometry|Feature} geojson any GeoJSON object\n * @param {Function} callback a method that takes (previousValue, currentCoord, coordIndex)\n * @param {*} [initialValue] Value to use as the first argument to the first call of the callback.\n * @param {boolean} [excludeWrapCoord=false] whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration.\n * @returns {*} The value that results from the reduction.\n * @example\n * var features = turf.featureCollection([\n * turf.point([26, 37], {\"foo\": \"bar\"}),\n * turf.point([36, 53], {\"hello\": \"world\"})\n * ]);\n *\n * turf.coordReduce(features, function (previousValue, currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {\n * //=previousValue\n * //=currentCoord\n * //=coordIndex\n * //=featureIndex\n * //=multiFeatureIndex\n * //=geometryIndex\n * return currentCoord;\n * });\n */\nfunction coordReduce(geojson, callback, initialValue, excludeWrapCoord) {\n var previousValue = initialValue;\n coordEach(geojson, function (currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {\n if (coordIndex === 0 && initialValue === undefined) previousValue = currentCoord;\n else previousValue = callback(previousValue, currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex);\n }, excludeWrapCoord);\n return previousValue;\n}\n\n/**\n * Callback for propEach\n *\n * @callback propEachCallback\n * @param {Object} currentProperties The current Properties being processed.\n * @param {number} featureIndex The current index of the Feature being processed.\n */\n\n/**\n * Iterate over properties in any GeoJSON object, similar to Array.forEach()\n *\n * @name propEach\n * @param {FeatureCollection|Feature} geojson any GeoJSON object\n * @param {Function} callback a method that takes (currentProperties, featureIndex)\n * @returns {void}\n * @example\n * var features = turf.featureCollection([\n * turf.point([26, 37], {foo: 'bar'}),\n * turf.point([36, 53], {hello: 'world'})\n * ]);\n *\n * turf.propEach(features, function (currentProperties, featureIndex) {\n * //=currentProperties\n * //=featureIndex\n * });\n */\nfunction propEach(geojson, callback) {\n var i;\n switch (geojson.type) {\n case 'FeatureCollection':\n for (i = 0; i < geojson.features.length; i++) {\n if (callback(geojson.features[i].properties, i) === false) break;\n }\n break;\n case 'Feature':\n callback(geojson.properties, 0);\n break;\n }\n}\n\n\n/**\n * Callback for propReduce\n *\n * The first time the callback function is called, the values provided as arguments depend\n * on whether the reduce method has an initialValue argument.\n *\n * If an initialValue is provided to the reduce method:\n * - The previousValue argument is initialValue.\n * - The currentValue argument is the value of the first element present in the array.\n *\n * If an initialValue is not provided:\n * - The previousValue argument is the value of the first element present in the array.\n * - The currentValue argument is the value of the second element present in the array.\n *\n * @callback propReduceCallback\n * @param {*} previousValue The accumulated value previously returned in the last invocation\n * of the callback, or initialValue, if supplied.\n * @param {*} currentProperties The current Properties being processed.\n * @param {number} featureIndex The current index of the Feature being processed.\n */\n\n/**\n * Reduce properties in any GeoJSON object into a single value,\n * similar to how Array.reduce works. However, in this case we lazily run\n * the reduction, so an array of all properties is unnecessary.\n *\n * @name propReduce\n * @param {FeatureCollection|Feature} geojson any GeoJSON object\n * @param {Function} callback a method that takes (previousValue, currentProperties, featureIndex)\n * @param {*} [initialValue] Value to use as the first argument to the first call of the callback.\n * @returns {*} The value that results from the reduction.\n * @example\n * var features = turf.featureCollection([\n * turf.point([26, 37], {foo: 'bar'}),\n * turf.point([36, 53], {hello: 'world'})\n * ]);\n *\n * turf.propReduce(features, function (previousValue, currentProperties, featureIndex) {\n * //=previousValue\n * //=currentProperties\n * //=featureIndex\n * return currentProperties\n * });\n */\nfunction propReduce(geojson, callback, initialValue) {\n var previousValue = initialValue;\n propEach(geojson, function (currentProperties, featureIndex) {\n if (featureIndex === 0 && initialValue === undefined) previousValue = currentProperties;\n else previousValue = callback(previousValue, currentProperties, featureIndex);\n });\n return previousValue;\n}\n\n/**\n * Callback for featureEach\n *\n * @callback featureEachCallback\n * @param {Feature} currentFeature The current Feature being processed.\n * @param {number} featureIndex The current index of the Feature being processed.\n */\n\n/**\n * Iterate over features in any GeoJSON object, similar to\n * Array.forEach.\n *\n * @name featureEach\n * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object\n * @param {Function} callback a method that takes (currentFeature, featureIndex)\n * @returns {void}\n * @example\n * var features = turf.featureCollection([\n * turf.point([26, 37], {foo: 'bar'}),\n * turf.point([36, 53], {hello: 'world'})\n * ]);\n *\n * turf.featureEach(features, function (currentFeature, featureIndex) {\n * //=currentFeature\n * //=featureIndex\n * });\n */\nfunction featureEach(geojson, callback) {\n if (geojson.type === 'Feature') {\n callback(geojson, 0);\n } else if (geojson.type === 'FeatureCollection') {\n for (var i = 0; i < geojson.features.length; i++) {\n if (callback(geojson.features[i], i) === false) break;\n }\n }\n}\n\n/**\n * Callback for featureReduce\n *\n * The first time the callback function is called, the values provided as arguments depend\n * on whether the reduce method has an initialValue argument.\n *\n * If an initialValue is provided to the reduce method:\n * - The previousValue argument is initialValue.\n * - The currentValue argument is the value of the first element present in the array.\n *\n * If an initialValue is not provided:\n * - The previousValue argument is the value of the first element present in the array.\n * - The currentValue argument is the value of the second element present in the array.\n *\n * @callback featureReduceCallback\n * @param {*} previousValue The accumulated value previously returned in the last invocation\n * of the callback, or initialValue, if supplied.\n * @param {Feature} currentFeature The current Feature being processed.\n * @param {number} featureIndex The current index of the Feature being processed.\n */\n\n/**\n * Reduce features in any GeoJSON object, similar to Array.reduce().\n *\n * @name featureReduce\n * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object\n * @param {Function} callback a method that takes (previousValue, currentFeature, featureIndex)\n * @param {*} [initialValue] Value to use as the first argument to the first call of the callback.\n * @returns {*} The value that results from the reduction.\n * @example\n * var features = turf.featureCollection([\n * turf.point([26, 37], {\"foo\": \"bar\"}),\n * turf.point([36, 53], {\"hello\": \"world\"})\n * ]);\n *\n * turf.featureReduce(features, function (previousValue, currentFeature, featureIndex) {\n * //=previousValue\n * //=currentFeature\n * //=featureIndex\n * return currentFeature\n * });\n */\nfunction featureReduce(geojson, callback, initialValue) {\n var previousValue = initialValue;\n featureEach(geojson, function (currentFeature, featureIndex) {\n if (featureIndex === 0 && initialValue === undefined) previousValue = currentFeature;\n else previousValue = callback(previousValue, currentFeature, featureIndex);\n });\n return previousValue;\n}\n\n/**\n * Get all coordinates from any GeoJSON object.\n *\n * @name coordAll\n * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object\n * @returns {Array>} coordinate position array\n * @example\n * var features = turf.featureCollection([\n * turf.point([26, 37], {foo: 'bar'}),\n * turf.point([36, 53], {hello: 'world'})\n * ]);\n *\n * var coords = turf.coordAll(features);\n * //= [[26, 37], [36, 53]]\n */\nfunction coordAll(geojson) {\n var coords = [];\n coordEach(geojson, function (coord) {\n coords.push(coord);\n });\n return coords;\n}\n\n/**\n * Callback for geomEach\n *\n * @callback geomEachCallback\n * @param {Geometry} currentGeometry The current Geometry being processed.\n * @param {number} featureIndex The current index of the Feature being processed.\n * @param {Object} featureProperties The current Feature Properties being processed.\n * @param {Array} featureBBox The current Feature BBox being processed.\n * @param {number|string} featureId The current Feature Id being processed.\n */\n\n/**\n * Iterate over each geometry in any GeoJSON object, similar to Array.forEach()\n *\n * @name geomEach\n * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object\n * @param {Function} callback a method that takes (currentGeometry, featureIndex, featureProperties, featureBBox, featureId)\n * @returns {void}\n * @example\n * var features = turf.featureCollection([\n * turf.point([26, 37], {foo: 'bar'}),\n * turf.point([36, 53], {hello: 'world'})\n * ]);\n *\n * turf.geomEach(features, function (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {\n * //=currentGeometry\n * //=featureIndex\n * //=featureProperties\n * //=featureBBox\n * //=featureId\n * });\n */\nfunction geomEach(geojson, callback) {\n var i, j, g, geometry, stopG,\n geometryMaybeCollection,\n isGeometryCollection,\n featureProperties,\n featureBBox,\n featureId,\n featureIndex = 0,\n isFeatureCollection = geojson.type === 'FeatureCollection',\n isFeature = geojson.type === 'Feature',\n stop = isFeatureCollection ? geojson.features.length : 1;\n\n // This logic may look a little weird. The reason why it is that way\n // is because it's trying to be fast. GeoJSON supports multiple kinds\n // of objects at its root: FeatureCollection, Features, Geometries.\n // This function has the responsibility of handling all of them, and that\n // means that some of the `for` loops you see below actually just don't apply\n // to certain inputs. For instance, if you give this just a\n // Point geometry, then both loops are short-circuited and all we do\n // is gradually rename the input until it's called 'geometry'.\n //\n // This also aims to allocate as few resources as possible: just a\n // few numbers and booleans, rather than any temporary arrays as would\n // be required with the normalization approach.\n for (i = 0; i < stop; i++) {\n\n geometryMaybeCollection = (isFeatureCollection ? geojson.features[i].geometry :\n (isFeature ? geojson.geometry : geojson));\n featureProperties = (isFeatureCollection ? geojson.features[i].properties :\n (isFeature ? geojson.properties : {}));\n featureBBox = (isFeatureCollection ? geojson.features[i].bbox :\n (isFeature ? geojson.bbox : undefined));\n featureId = (isFeatureCollection ? geojson.features[i].id :\n (isFeature ? geojson.id : undefined));\n isGeometryCollection = (geometryMaybeCollection) ? geometryMaybeCollection.type === 'GeometryCollection' : false;\n stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;\n\n for (g = 0; g < stopG; g++) {\n geometry = isGeometryCollection ?\n geometryMaybeCollection.geometries[g] : geometryMaybeCollection;\n\n // Handle null Geometry\n if (geometry === null) {\n if (callback(null, featureIndex, featureProperties, featureBBox, featureId) === false) return false;\n continue;\n }\n switch (geometry.type) {\n case 'Point':\n case 'LineString':\n case 'MultiPoint':\n case 'Polygon':\n case 'MultiLineString':\n case 'MultiPolygon': {\n if (callback(geometry, featureIndex, featureProperties, featureBBox, featureId) === false) return false;\n break;\n }\n case 'GeometryCollection': {\n for (j = 0; j < geometry.geometries.length; j++) {\n if (callback(geometry.geometries[j], featureIndex, featureProperties, featureBBox, featureId) === false) return false;\n }\n break;\n }\n default:\n throw new Error('Unknown Geometry Type');\n }\n }\n // Only increase `featureIndex` per each feature\n featureIndex++;\n }\n}\n\n/**\n * Callback for geomReduce\n *\n * The first time the callback function is called, the values provided as arguments depend\n * on whether the reduce method has an initialValue argument.\n *\n * If an initialValue is provided to the reduce method:\n * - The previousValue argument is initialValue.\n * - The currentValue argument is the value of the first element present in the array.\n *\n * If an initialValue is not provided:\n * - The previousValue argument is the value of the first element present in the array.\n * - The currentValue argument is the value of the second element present in the array.\n *\n * @callback geomReduceCallback\n * @param {*} previousValue The accumulated value previously returned in the last invocation\n * of the callback, or initialValue, if supplied.\n * @param {Geometry} currentGeometry The current Geometry being processed.\n * @param {number} featureIndex The current index of the Feature being processed.\n * @param {Object} featureProperties The current Feature Properties being processed.\n * @param {Array} featureBBox The current Feature BBox being processed.\n * @param {number|string} featureId The current Feature Id being processed.\n */\n\n/**\n * Reduce geometry in any GeoJSON object, similar to Array.reduce().\n *\n * @name geomReduce\n * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object\n * @param {Function} callback a method that takes (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId)\n * @param {*} [initialValue] Value to use as the first argument to the first call of the callback.\n * @returns {*} The value that results from the reduction.\n * @example\n * var features = turf.featureCollection([\n * turf.point([26, 37], {foo: 'bar'}),\n * turf.point([36, 53], {hello: 'world'})\n * ]);\n *\n * turf.geomReduce(features, function (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {\n * //=previousValue\n * //=currentGeometry\n * //=featureIndex\n * //=featureProperties\n * //=featureBBox\n * //=featureId\n * return currentGeometry\n * });\n */\nfunction geomReduce(geojson, callback, initialValue) {\n var previousValue = initialValue;\n geomEach(geojson, function (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {\n if (featureIndex === 0 && initialValue === undefined) previousValue = currentGeometry;\n else previousValue = callback(previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId);\n });\n return previousValue;\n}\n\n/**\n * Callback for flattenEach\n *\n * @callback flattenEachCallback\n * @param {Feature} currentFeature The current flattened feature being processed.\n * @param {number} featureIndex The current index of the Feature being processed.\n * @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.\n */\n\n/**\n * Iterate over flattened features in any GeoJSON object, similar to\n * Array.forEach.\n *\n * @name flattenEach\n * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object\n * @param {Function} callback a method that takes (currentFeature, featureIndex, multiFeatureIndex)\n * @example\n * var features = turf.featureCollection([\n * turf.point([26, 37], {foo: 'bar'}),\n * turf.multiPoint([[40, 30], [36, 53]], {hello: 'world'})\n * ]);\n *\n * turf.flattenEach(features, function (currentFeature, featureIndex, multiFeatureIndex) {\n * //=currentFeature\n * //=featureIndex\n * //=multiFeatureIndex\n * });\n */\nfunction flattenEach(geojson, callback) {\n geomEach(geojson, function (geometry, featureIndex, properties, bbox, id) {\n // Callback for single geometry\n var type = (geometry === null) ? null : geometry.type;\n switch (type) {\n case null:\n case 'Point':\n case 'LineString':\n case 'Polygon':\n if (callback(feature(geometry, properties, {bbox: bbox, id: id}), featureIndex, 0) === false) return false;\n return;\n }\n\n var geomType;\n\n // Callback for multi-geometry\n switch (type) {\n case 'MultiPoint':\n geomType = 'Point';\n break;\n case 'MultiLineString':\n geomType = 'LineString';\n break;\n case 'MultiPolygon':\n geomType = 'Polygon';\n break;\n }\n\n for (var multiFeatureIndex = 0; multiFeatureIndex < geometry.coordinates.length; multiFeatureIndex++) {\n var coordinate = geometry.coordinates[multiFeatureIndex];\n var geom = {\n type: geomType,\n coordinates: coordinate\n };\n if (callback(feature(geom, properties), featureIndex, multiFeatureIndex) === false) return false;\n }\n });\n}\n\n/**\n * Callback for flattenReduce\n *\n * The first time the callback function is called, the values provided as arguments depend\n * on whether the reduce method has an initialValue argument.\n *\n * If an initialValue is provided to the reduce method:\n * - The previousValue argument is initialValue.\n * - The currentValue argument is the value of the first element present in the array.\n *\n * If an initialValue is not provided:\n * - The previousValue argument is the value of the first element present in the array.\n * - The currentValue argument is the value of the second element present in the array.\n *\n * @callback flattenReduceCallback\n * @param {*} previousValue The accumulated value previously returned in the last invocation\n * of the callback, or initialValue, if supplied.\n * @param {Feature} currentFeature The current Feature being processed.\n * @param {number} featureIndex The current index of the Feature being processed.\n * @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.\n */\n\n/**\n * Reduce flattened features in any GeoJSON object, similar to Array.reduce().\n *\n * @name flattenReduce\n * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object\n * @param {Function} callback a method that takes (previousValue, currentFeature, featureIndex, multiFeatureIndex)\n * @param {*} [initialValue] Value to use as the first argument to the first call of the callback.\n * @returns {*} The value that results from the reduction.\n * @example\n * var features = turf.featureCollection([\n * turf.point([26, 37], {foo: 'bar'}),\n * turf.multiPoint([[40, 30], [36, 53]], {hello: 'world'})\n * ]);\n *\n * turf.flattenReduce(features, function (previousValue, currentFeature, featureIndex, multiFeatureIndex) {\n * //=previousValue\n * //=currentFeature\n * //=featureIndex\n * //=multiFeatureIndex\n * return currentFeature\n * });\n */\nfunction flattenReduce(geojson, callback, initialValue) {\n var previousValue = initialValue;\n flattenEach(geojson, function (currentFeature, featureIndex, multiFeatureIndex) {\n if (featureIndex === 0 && multiFeatureIndex === 0 && initialValue === undefined) previousValue = currentFeature;\n else previousValue = callback(previousValue, currentFeature, featureIndex, multiFeatureIndex);\n });\n return previousValue;\n}\n\n/**\n * Callback for segmentEach\n *\n * @callback segmentEachCallback\n * @param {Feature} currentSegment The current Segment being processed.\n * @param {number} featureIndex The current index of the Feature being processed.\n * @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.\n * @param {number} geometryIndex The current index of the Geometry being processed.\n * @param {number} segmentIndex The current index of the Segment being processed.\n * @returns {void}\n */\n\n/**\n * Iterate over 2-vertex line segment in any GeoJSON object, similar to Array.forEach()\n * (Multi)Point geometries do not contain segments therefore they are ignored during this operation.\n *\n * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON\n * @param {Function} callback a method that takes (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex)\n * @returns {void}\n * @example\n * var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);\n *\n * // Iterate over GeoJSON by 2-vertex segments\n * turf.segmentEach(polygon, function (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) {\n * //=currentSegment\n * //=featureIndex\n * //=multiFeatureIndex\n * //=geometryIndex\n * //=segmentIndex\n * });\n *\n * // Calculate the total number of segments\n * var total = 0;\n * turf.segmentEach(polygon, function () {\n * total++;\n * });\n */\nfunction segmentEach(geojson, callback) {\n flattenEach(geojson, function (feature$$1, featureIndex, multiFeatureIndex) {\n var segmentIndex = 0;\n\n // Exclude null Geometries\n if (!feature$$1.geometry) return;\n // (Multi)Point geometries do not contain segments therefore they are ignored during this operation.\n var type = feature$$1.geometry.type;\n if (type === 'Point' || type === 'MultiPoint') return;\n\n // Generate 2-vertex line segments\n var previousCoords;\n if (coordEach(feature$$1, function (currentCoord, coordIndex, featureIndexCoord, mutliPartIndexCoord, geometryIndex) {\n // Simulating a meta.coordReduce() since `reduce` operations cannot be stopped by returning `false`\n if (previousCoords === undefined) {\n previousCoords = currentCoord;\n return;\n }\n var currentSegment = lineString([previousCoords, currentCoord], feature$$1.properties);\n if (callback(currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) === false) return false;\n segmentIndex++;\n previousCoords = currentCoord;\n }) === false) return false;\n });\n}\n\n/**\n * Callback for segmentReduce\n *\n * The first time the callback function is called, the values provided as arguments depend\n * on whether the reduce method has an initialValue argument.\n *\n * If an initialValue is provided to the reduce method:\n * - The previousValue argument is initialValue.\n * - The currentValue argument is the value of the first element present in the array.\n *\n * If an initialValue is not provided:\n * - The previousValue argument is the value of the first element present in the array.\n * - The currentValue argument is the value of the second element present in the array.\n *\n * @callback segmentReduceCallback\n * @param {*} previousValue The accumulated value previously returned in the last invocation\n * of the callback, or initialValue, if supplied.\n * @param {Feature} currentSegment The current Segment being processed.\n * @param {number} featureIndex The current index of the Feature being processed.\n * @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.\n * @param {number} geometryIndex The current index of the Geometry being processed.\n * @param {number} segmentIndex The current index of the Segment being processed.\n */\n\n/**\n * Reduce 2-vertex line segment in any GeoJSON object, similar to Array.reduce()\n * (Multi)Point geometries do not contain segments therefore they are ignored during this operation.\n *\n * @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON\n * @param {Function} callback a method that takes (previousValue, currentSegment, currentIndex)\n * @param {*} [initialValue] Value to use as the first argument to the first call of the callback.\n * @returns {void}\n * @example\n * var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);\n *\n * // Iterate over GeoJSON by 2-vertex segments\n * turf.segmentReduce(polygon, function (previousSegment, currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) {\n * //= previousSegment\n * //= currentSegment\n * //= featureIndex\n * //= multiFeatureIndex\n * //= geometryIndex\n * //= segmentInex\n * return currentSegment\n * });\n *\n * // Calculate the total number of segments\n * var initialValue = 0\n * var total = turf.segmentReduce(polygon, function (previousValue) {\n * previousValue++;\n * return previousValue;\n * }, initialValue);\n */\nfunction segmentReduce(geojson, callback, initialValue) {\n var previousValue = initialValue;\n var started = false;\n segmentEach(geojson, function (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) {\n if (started === false && initialValue === undefined) previousValue = currentSegment;\n else previousValue = callback(previousValue, currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex);\n started = true;\n });\n return previousValue;\n}\n\n/**\n * Callback for lineEach\n *\n * @callback lineEachCallback\n * @param {Feature} currentLine The current LineString|LinearRing being processed\n * @param {number} featureIndex The current index of the Feature being processed\n * @param {number} multiFeatureIndex The current index of the Multi-Feature being processed\n * @param {number} geometryIndex The current index of the Geometry being processed\n */\n\n/**\n * Iterate over line or ring coordinates in LineString, Polygon, MultiLineString, MultiPolygon Features or Geometries,\n * similar to Array.forEach.\n *\n * @name lineEach\n * @param {Geometry|Feature} geojson object\n * @param {Function} callback a method that takes (currentLine, featureIndex, multiFeatureIndex, geometryIndex)\n * @example\n * var multiLine = turf.multiLineString([\n * [[26, 37], [35, 45]],\n * [[36, 53], [38, 50], [41, 55]]\n * ]);\n *\n * turf.lineEach(multiLine, function (currentLine, featureIndex, multiFeatureIndex, geometryIndex) {\n * //=currentLine\n * //=featureIndex\n * //=multiFeatureIndex\n * //=geometryIndex\n * });\n */\nfunction lineEach(geojson, callback) {\n // validation\n if (!geojson) throw new Error('geojson is required');\n\n flattenEach(geojson, function (feature$$1, featureIndex, multiFeatureIndex) {\n if (feature$$1.geometry === null) return;\n var type = feature$$1.geometry.type;\n var coords = feature$$1.geometry.coordinates;\n switch (type) {\n case 'LineString':\n if (callback(feature$$1, featureIndex, multiFeatureIndex, 0, 0) === false) return false;\n break;\n case 'Polygon':\n for (var geometryIndex = 0; geometryIndex < coords.length; geometryIndex++) {\n if (callback(lineString(coords[geometryIndex], feature$$1.properties), featureIndex, multiFeatureIndex, geometryIndex) === false) return false;\n }\n break;\n }\n });\n}\n\n/**\n * Callback for lineReduce\n *\n * The first time the callback function is called, the values provided as arguments depend\n * on whether the reduce method has an initialValue argument.\n *\n * If an initialValue is provided to the reduce method:\n * - The previousValue argument is initialValue.\n * - The currentValue argument is the value of the first element present in the array.\n *\n * If an initialValue is not provided:\n * - The previousValue argument is the value of the first element present in the array.\n * - The currentValue argument is the value of the second element present in the array.\n *\n * @callback lineReduceCallback\n * @param {*} previousValue The accumulated value previously returned in the last invocation\n * of the callback, or initialValue, if supplied.\n * @param {Feature} currentLine The current LineString|LinearRing being processed.\n * @param {number} featureIndex The current index of the Feature being processed\n * @param {number} multiFeatureIndex The current index of the Multi-Feature being processed\n * @param {number} geometryIndex The current index of the Geometry being processed\n */\n\n/**\n * Reduce features in any GeoJSON object, similar to Array.reduce().\n *\n * @name lineReduce\n * @param {Geometry|Feature} geojson object\n * @param {Function} callback a method that takes (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex)\n * @param {*} [initialValue] Value to use as the first argument to the first call of the callback.\n * @returns {*} The value that results from the reduction.\n * @example\n * var multiPoly = turf.multiPolygon([\n * turf.polygon([[[12,48],[2,41],[24,38],[12,48]], [[9,44],[13,41],[13,45],[9,44]]]),\n * turf.polygon([[[5, 5], [0, 0], [2, 2], [4, 4], [5, 5]]])\n * ]);\n *\n * turf.lineReduce(multiPoly, function (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex) {\n * //=previousValue\n * //=currentLine\n * //=featureIndex\n * //=multiFeatureIndex\n * //=geometryIndex\n * return currentLine\n * });\n */\nfunction lineReduce(geojson, callback, initialValue) {\n var previousValue = initialValue;\n lineEach(geojson, function (currentLine, featureIndex, multiFeatureIndex, geometryIndex) {\n if (featureIndex === 0 && initialValue === undefined) previousValue = currentLine;\n else previousValue = callback(previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex);\n });\n return previousValue;\n}\n\n/**\n * Finds a particular 2-vertex LineString Segment from a GeoJSON using `@turf/meta` indexes.\n *\n * Negative indexes are permitted.\n * Point & MultiPoint will always return null.\n *\n * @param {FeatureCollection|Feature|Geometry} geojson Any GeoJSON Feature or Geometry\n * @param {Object} [options={}] Optional parameters\n * @param {number} [options.featureIndex=0] Feature Index\n * @param {number} [options.multiFeatureIndex=0] Multi-Feature Index\n * @param {number} [options.geometryIndex=0] Geometry Index\n * @param {number} [options.segmentIndex=0] Segment Index\n * @param {Object} [options.properties={}] Translate Properties to output LineString\n * @param {BBox} [options.bbox={}] Translate BBox to output LineString\n * @param {number|string} [options.id={}] Translate Id to output LineString\n * @returns {Feature} 2-vertex GeoJSON Feature LineString\n * @example\n * var multiLine = turf.multiLineString([\n * [[10, 10], [50, 30], [30, 40]],\n * [[-10, -10], [-50, -30], [-30, -40]]\n * ]);\n *\n * // First Segment (defaults are 0)\n * turf.findSegment(multiLine);\n * // => Feature>\n *\n * // First Segment of 2nd Multi Feature\n * turf.findSegment(multiLine, {multiFeatureIndex: 1});\n * // => Feature>\n *\n * // Last Segment of Last Multi Feature\n * turf.findSegment(multiLine, {multiFeatureIndex: -1, segmentIndex: -1});\n * // => Feature>\n */\nfunction findSegment(geojson, options) {\n // Optional Parameters\n options = options || {};\n if (!isObject(options)) throw new Error('options is invalid');\n var featureIndex = options.featureIndex || 0;\n var multiFeatureIndex = options.multiFeatureIndex || 0;\n var geometryIndex = options.geometryIndex || 0;\n var segmentIndex = options.segmentIndex || 0;\n\n // Find FeatureIndex\n var properties = options.properties;\n var geometry;\n\n switch (geojson.type) {\n case 'FeatureCollection':\n if (featureIndex < 0) featureIndex = geojson.features.length + featureIndex;\n properties = properties || geojson.features[featureIndex].properties;\n geometry = geojson.features[featureIndex].geometry;\n break;\n case 'Feature':\n properties = properties || geojson.properties;\n geometry = geojson.geometry;\n break;\n case 'Point':\n case 'MultiPoint':\n return null;\n case 'LineString':\n case 'Polygon':\n case 'MultiLineString':\n case 'MultiPolygon':\n geometry = geojson;\n break;\n default:\n throw new Error('geojson is invalid');\n }\n\n // Find SegmentIndex\n if (geometry === null) return null;\n var coords = geometry.coordinates;\n switch (geometry.type) {\n case 'Point':\n case 'MultiPoint':\n return null;\n case 'LineString':\n if (segmentIndex < 0) segmentIndex = coords.length + segmentIndex - 1;\n return lineString([coords[segmentIndex], coords[segmentIndex + 1]], properties, options);\n case 'Polygon':\n if (geometryIndex < 0) geometryIndex = coords.length + geometryIndex;\n if (segmentIndex < 0) segmentIndex = coords[geometryIndex].length + segmentIndex - 1;\n return lineString([coords[geometryIndex][segmentIndex], coords[geometryIndex][segmentIndex + 1]], properties, options);\n case 'MultiLineString':\n if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;\n if (segmentIndex < 0) segmentIndex = coords[multiFeatureIndex].length + segmentIndex - 1;\n return lineString([coords[multiFeatureIndex][segmentIndex], coords[multiFeatureIndex][segmentIndex + 1]], properties, options);\n case 'MultiPolygon':\n if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;\n if (geometryIndex < 0) geometryIndex = coords[multiFeatureIndex].length + geometryIndex;\n if (segmentIndex < 0) segmentIndex = coords[multiFeatureIndex][geometryIndex].length - segmentIndex - 1;\n return lineString([coords[multiFeatureIndex][geometryIndex][segmentIndex], coords[multiFeatureIndex][geometryIndex][segmentIndex + 1]], properties, options);\n }\n throw new Error('geojson is invalid');\n}\n\n/**\n * Finds a particular Point from a GeoJSON using `@turf/meta` indexes.\n *\n * Negative indexes are permitted.\n *\n * @param {FeatureCollection|Feature|Geometry} geojson Any GeoJSON Feature or Geometry\n * @param {Object} [options={}] Optional parameters\n * @param {number} [options.featureIndex=0] Feature Index\n * @param {number} [options.multiFeatureIndex=0] Multi-Feature Index\n * @param {number} [options.geometryIndex=0] Geometry Index\n * @param {number} [options.coordIndex=0] Coord Index\n * @param {Object} [options.properties={}] Translate Properties to output Point\n * @param {BBox} [options.bbox={}] Translate BBox to output Point\n * @param {number|string} [options.id={}] Translate Id to output Point\n * @returns {Feature} 2-vertex GeoJSON Feature Point\n * @example\n * var multiLine = turf.multiLineString([\n * [[10, 10], [50, 30], [30, 40]],\n * [[-10, -10], [-50, -30], [-30, -40]]\n * ]);\n *\n * // First Segment (defaults are 0)\n * turf.findPoint(multiLine);\n * // => Feature>\n *\n * // First Segment of the 2nd Multi-Feature\n * turf.findPoint(multiLine, {multiFeatureIndex: 1});\n * // => Feature>\n *\n * // Last Segment of last Multi-Feature\n * turf.findPoint(multiLine, {multiFeatureIndex: -1, coordIndex: -1});\n * // => Feature>\n */\nfunction findPoint(geojson, options) {\n // Optional Parameters\n options = options || {};\n if (!isObject(options)) throw new Error('options is invalid');\n var featureIndex = options.featureIndex || 0;\n var multiFeatureIndex = options.multiFeatureIndex || 0;\n var geometryIndex = options.geometryIndex || 0;\n var coordIndex = options.coordIndex || 0;\n\n // Find FeatureIndex\n var properties = options.properties;\n var geometry;\n\n switch (geojson.type) {\n case 'FeatureCollection':\n if (featureIndex < 0) featureIndex = geojson.features.length + featureIndex;\n properties = properties || geojson.features[featureIndex].properties;\n geometry = geojson.features[featureIndex].geometry;\n break;\n case 'Feature':\n properties = properties || geojson.properties;\n geometry = geojson.geometry;\n break;\n case 'Point':\n case 'MultiPoint':\n return null;\n case 'LineString':\n case 'Polygon':\n case 'MultiLineString':\n case 'MultiPolygon':\n geometry = geojson;\n break;\n default:\n throw new Error('geojson is invalid');\n }\n\n // Find Coord Index\n if (geometry === null) return null;\n var coords = geometry.coordinates;\n switch (geometry.type) {\n case 'Point':\n return point(coords, properties, options);\n case 'MultiPoint':\n if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;\n return point(coords[multiFeatureIndex], properties, options);\n case 'LineString':\n if (coordIndex < 0) coordIndex = coords.length + coordIndex;\n return point(coords[coordIndex], properties, options);\n case 'Polygon':\n if (geometryIndex < 0) geometryIndex = coords.length + geometryIndex;\n if (coordIndex < 0) coordIndex = coords[geometryIndex].length + coordIndex;\n return point(coords[geometryIndex][coordIndex], properties, options);\n case 'MultiLineString':\n if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;\n if (coordIndex < 0) coordIndex = coords[multiFeatureIndex].length + coordIndex;\n return point(coords[multiFeatureIndex][coordIndex], properties, options);\n case 'MultiPolygon':\n if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;\n if (geometryIndex < 0) geometryIndex = coords[multiFeatureIndex].length + geometryIndex;\n if (coordIndex < 0) coordIndex = coords[multiFeatureIndex][geometryIndex].length - coordIndex;\n return point(coords[multiFeatureIndex][geometryIndex][coordIndex], properties, options);\n }\n throw new Error('geojson is invalid');\n}\n\nexport { coordEach, coordReduce, propEach, propReduce, featureEach, featureReduce, coordAll, geomEach, geomReduce, flattenEach, flattenReduce, segmentEach, segmentReduce, lineEach, lineReduce, findSegment, findPoint };\n","import { geomReduce } from '@turf/meta';\n\n/**\n * Takes one or more features and returns their area in square meters.\n *\n * @name area\n * @param {GeoJSON} geojson input GeoJSON feature(s)\n * @returns {number} area in square meters\n * @example\n * var polygon = turf.polygon([[[125, -15], [113, -22], [154, -27], [144, -15], [125, -15]]]);\n *\n * var area = turf.area(polygon);\n *\n * //addToMap\n * var addToMap = [polygon]\n * polygon.properties.area = area\n */\nfunction area(geojson) {\n return geomReduce(geojson, function (value, geom) {\n return value + calculateArea(geom);\n }, 0);\n}\n\nvar RADIUS = 6378137;\n// var FLATTENING_DENOM = 298.257223563;\n// var FLATTENING = 1 / FLATTENING_DENOM;\n// var POLAR_RADIUS = RADIUS * (1 - FLATTENING);\n\n/**\n * Calculate Area\n *\n * @private\n * @param {GeoJSON} geojson GeoJSON\n * @returns {number} area\n */\nfunction calculateArea(geojson) {\n var area = 0, i;\n switch (geojson.type) {\n case 'Polygon':\n return polygonArea(geojson.coordinates);\n case 'MultiPolygon':\n for (i = 0; i < geojson.coordinates.length; i++) {\n area += polygonArea(geojson.coordinates[i]);\n }\n return area;\n case 'Point':\n case 'MultiPoint':\n case 'LineString':\n case 'MultiLineString':\n return 0;\n case 'GeometryCollection':\n for (i = 0; i < geojson.geometries.length; i++) {\n area += calculateArea(geojson.geometries[i]);\n }\n return area;\n }\n}\n\nfunction polygonArea(coords) {\n var area = 0;\n if (coords && coords.length > 0) {\n area += Math.abs(ringArea(coords[0]));\n for (var i = 1; i < coords.length; i++) {\n area -= Math.abs(ringArea(coords[i]));\n }\n }\n return area;\n}\n\n/**\n * @private\n * Calculate the approximate area of the polygon were it projected onto the earth.\n * Note that this area will be positive if ring is oriented clockwise, otherwise it will be negative.\n *\n * Reference:\n * Robert. G. Chamberlain and William H. Duquette, \"Some Algorithms for Polygons on a Sphere\", JPL Publication 07-03, Jet Propulsion\n * Laboratory, Pasadena, CA, June 2007 http://trs-new.jpl.nasa.gov/dspace/handle/2014/40409\n *\n * @param {Array>} coords Ring Coordinates\n * @returns {number} The approximate signed geodesic area of the polygon in square meters.\n */\nfunction ringArea(coords) {\n var p1;\n var p2;\n var p3;\n var lowerIndex;\n var middleIndex;\n var upperIndex;\n var i;\n var area = 0;\n var coordsLength = coords.length;\n\n if (coordsLength > 2) {\n for (i = 0; i < coordsLength; i++) {\n if (i === coordsLength - 2) { // i = N-2\n lowerIndex = coordsLength - 2;\n middleIndex = coordsLength - 1;\n upperIndex = 0;\n } else if (i === coordsLength - 1) { // i = N-1\n lowerIndex = coordsLength - 1;\n middleIndex = 0;\n upperIndex = 1;\n } else { // i = 0 to N-3\n lowerIndex = i;\n middleIndex = i + 1;\n upperIndex = i + 2;\n }\n p1 = coords[lowerIndex];\n p2 = coords[middleIndex];\n p3 = coords[upperIndex];\n area += (rad(p3[0]) - rad(p1[0])) * Math.sin(rad(p2[1]));\n }\n\n area = area * RADIUS * RADIUS / 2;\n }\n\n return area;\n}\n\nfunction rad(_) {\n return _ * Math.PI / 180;\n}\n\nexport default area;\n","/**\n * Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth.\n */\nvar earthRadius = 6371008.8;\n\n/**\n * Unit of measurement factors using a spherical (non-ellipsoid) earth radius.\n */\nvar factors = {\n meters: earthRadius,\n metres: earthRadius,\n millimeters: earthRadius * 1000,\n millimetres: earthRadius * 1000,\n centimeters: earthRadius * 100,\n centimetres: earthRadius * 100,\n kilometers: earthRadius / 1000,\n kilometres: earthRadius / 1000,\n miles: earthRadius / 1609.344,\n nauticalmiles: earthRadius / 1852,\n inches: earthRadius * 39.370,\n yards: earthRadius / 1.0936,\n feet: earthRadius * 3.28084,\n radians: 1,\n degrees: earthRadius / 111325,\n};\n\n/**\n * Units of measurement factors based on 1 meter.\n */\nvar unitsFactors = {\n meters: 1,\n metres: 1,\n millimeters: 1000,\n millimetres: 1000,\n centimeters: 100,\n centimetres: 100,\n kilometers: 1 / 1000,\n kilometres: 1 / 1000,\n miles: 1 / 1609.344,\n nauticalmiles: 1 / 1852,\n inches: 39.370,\n yards: 1 / 1.0936,\n feet: 3.28084,\n radians: 1 / earthRadius,\n degrees: 1 / 111325,\n};\n\n/**\n * Area of measurement factors based on 1 square meter.\n */\nvar areaFactors = {\n meters: 1,\n metres: 1,\n millimeters: 1000000,\n millimetres: 1000000,\n centimeters: 10000,\n centimetres: 10000,\n kilometers: 0.000001,\n kilometres: 0.000001,\n acres: 0.000247105,\n miles: 3.86e-7,\n yards: 1.195990046,\n feet: 10.763910417,\n inches: 1550.003100006\n};\n\n/**\n * Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}.\n *\n * @name feature\n * @param {Geometry} geometry input geometry\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature} a GeoJSON Feature\n * @example\n * var geometry = {\n * \"type\": \"Point\",\n * \"coordinates\": [110, 50]\n * };\n *\n * var feature = turf.feature(geometry);\n *\n * //=feature\n */\nfunction feature(geometry, properties, options) {\n // Optional Parameters\n options = options || {};\n if (!isObject(options)) throw new Error('options is invalid');\n var bbox = options.bbox;\n var id = options.id;\n\n // Validation\n if (geometry === undefined) throw new Error('geometry is required');\n if (properties && properties.constructor !== Object) throw new Error('properties must be an Object');\n if (bbox) validateBBox(bbox);\n if (id) validateId(id);\n\n // Main\n var feat = {type: 'Feature'};\n if (id) feat.id = id;\n if (bbox) feat.bbox = bbox;\n feat.properties = properties || {};\n feat.geometry = geometry;\n return feat;\n}\n\n/**\n * Creates a GeoJSON {@link Geometry} from a Geometry string type & coordinates.\n * For GeometryCollection type use `helpers.geometryCollection`\n *\n * @name geometry\n * @param {string} type Geometry Type\n * @param {Array} coordinates Coordinates\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Geometry\n * @returns {Geometry} a GeoJSON Geometry\n * @example\n * var type = 'Point';\n * var coordinates = [110, 50];\n *\n * var geometry = turf.geometry(type, coordinates);\n *\n * //=geometry\n */\nfunction geometry(type, coordinates, options) {\n // Optional Parameters\n options = options || {};\n if (!isObject(options)) throw new Error('options is invalid');\n var bbox = options.bbox;\n\n // Validation\n if (!type) throw new Error('type is required');\n if (!coordinates) throw new Error('coordinates is required');\n if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');\n if (bbox) validateBBox(bbox);\n\n // Main\n var geom;\n switch (type) {\n case 'Point': geom = point(coordinates).geometry; break;\n case 'LineString': geom = lineString(coordinates).geometry; break;\n case 'Polygon': geom = polygon(coordinates).geometry; break;\n case 'MultiPoint': geom = multiPoint(coordinates).geometry; break;\n case 'MultiLineString': geom = multiLineString(coordinates).geometry; break;\n case 'MultiPolygon': geom = multiPolygon(coordinates).geometry; break;\n default: throw new Error(type + ' is invalid');\n }\n if (bbox) geom.bbox = bbox;\n return geom;\n}\n\n/**\n * Creates a {@link Point} {@link Feature} from a Position.\n *\n * @name point\n * @param {Array} coordinates longitude, latitude position (each in decimal degrees)\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature} a Point feature\n * @example\n * var point = turf.point([-75.343, 39.984]);\n *\n * //=point\n */\nfunction point(coordinates, properties, options) {\n if (!coordinates) throw new Error('coordinates is required');\n if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');\n if (coordinates.length < 2) throw new Error('coordinates must be at least 2 numbers long');\n if (!isNumber(coordinates[0]) || !isNumber(coordinates[1])) throw new Error('coordinates must contain numbers');\n\n return feature({\n type: 'Point',\n coordinates: coordinates\n }, properties, options);\n}\n\n/**\n * Creates a {@link Point} {@link FeatureCollection} from an Array of Point coordinates.\n *\n * @name points\n * @param {Array>} coordinates an array of Points\n * @param {Object} [properties={}] Translate these properties to each Feature\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the FeatureCollection\n * @param {string|number} [options.id] Identifier associated with the FeatureCollection\n * @returns {FeatureCollection} Point Feature\n * @example\n * var points = turf.points([\n * [-75, 39],\n * [-80, 45],\n * [-78, 50]\n * ]);\n *\n * //=points\n */\nfunction points(coordinates, properties, options) {\n if (!coordinates) throw new Error('coordinates is required');\n if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');\n\n return featureCollection(coordinates.map(function (coords) {\n return point(coords, properties);\n }), options);\n}\n\n/**\n * Creates a {@link Polygon} {@link Feature} from an Array of LinearRings.\n *\n * @name polygon\n * @param {Array>>} coordinates an array of LinearRings\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature} Polygon Feature\n * @example\n * var polygon = turf.polygon([[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]], { name: 'poly1' });\n *\n * //=polygon\n */\nfunction polygon(coordinates, properties, options) {\n if (!coordinates) throw new Error('coordinates is required');\n\n for (var i = 0; i < coordinates.length; i++) {\n var ring = coordinates[i];\n if (ring.length < 4) {\n throw new Error('Each LinearRing of a Polygon must have 4 or more Positions.');\n }\n for (var j = 0; j < ring[ring.length - 1].length; j++) {\n // Check if first point of Polygon contains two numbers\n if (i === 0 && j === 0 && !isNumber(ring[0][0]) || !isNumber(ring[0][1])) throw new Error('coordinates must contain numbers');\n if (ring[ring.length - 1][j] !== ring[0][j]) {\n throw new Error('First and last Position are not equivalent.');\n }\n }\n }\n\n return feature({\n type: 'Polygon',\n coordinates: coordinates\n }, properties, options);\n}\n\n/**\n * Creates a {@link Polygon} {@link FeatureCollection} from an Array of Polygon coordinates.\n *\n * @name polygons\n * @param {Array>>>} coordinates an array of Polygon coordinates\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the FeatureCollection\n * @returns {FeatureCollection} Polygon FeatureCollection\n * @example\n * var polygons = turf.polygons([\n * [[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]],\n * [[[-15, 42], [-14, 46], [-12, 41], [-17, 44], [-15, 42]]],\n * ]);\n *\n * //=polygons\n */\nfunction polygons(coordinates, properties, options) {\n if (!coordinates) throw new Error('coordinates is required');\n if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');\n\n return featureCollection(coordinates.map(function (coords) {\n return polygon(coords, properties);\n }), options);\n}\n\n/**\n * Creates a {@link LineString} {@link Feature} from an Array of Positions.\n *\n * @name lineString\n * @param {Array>} coordinates an array of Positions\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature} LineString Feature\n * @example\n * var linestring1 = turf.lineString([[-24, 63], [-23, 60], [-25, 65], [-20, 69]], {name: 'line 1'});\n * var linestring2 = turf.lineString([[-14, 43], [-13, 40], [-15, 45], [-10, 49]], {name: 'line 2'});\n *\n * //=linestring1\n * //=linestring2\n */\nfunction lineString(coordinates, properties, options) {\n if (!coordinates) throw new Error('coordinates is required');\n if (coordinates.length < 2) throw new Error('coordinates must be an array of two or more positions');\n // Check if first point of LineString contains two numbers\n if (!isNumber(coordinates[0][1]) || !isNumber(coordinates[0][1])) throw new Error('coordinates must contain numbers');\n\n return feature({\n type: 'LineString',\n coordinates: coordinates\n }, properties, options);\n}\n\n/**\n * Creates a {@link LineString} {@link FeatureCollection} from an Array of LineString coordinates.\n *\n * @name lineStrings\n * @param {Array>} coordinates an array of LinearRings\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the FeatureCollection\n * @param {string|number} [options.id] Identifier associated with the FeatureCollection\n * @returns {FeatureCollection} LineString FeatureCollection\n * @example\n * var linestrings = turf.lineStrings([\n * [[-24, 63], [-23, 60], [-25, 65], [-20, 69]],\n * [[-14, 43], [-13, 40], [-15, 45], [-10, 49]]\n * ]);\n *\n * //=linestrings\n */\nfunction lineStrings(coordinates, properties, options) {\n if (!coordinates) throw new Error('coordinates is required');\n if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');\n\n return featureCollection(coordinates.map(function (coords) {\n return lineString(coords, properties);\n }), options);\n}\n\n/**\n * Takes one or more {@link Feature|Features} and creates a {@link FeatureCollection}.\n *\n * @name featureCollection\n * @param {Feature[]} features input features\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {FeatureCollection} FeatureCollection of Features\n * @example\n * var locationA = turf.point([-75.343, 39.984], {name: 'Location A'});\n * var locationB = turf.point([-75.833, 39.284], {name: 'Location B'});\n * var locationC = turf.point([-75.534, 39.123], {name: 'Location C'});\n *\n * var collection = turf.featureCollection([\n * locationA,\n * locationB,\n * locationC\n * ]);\n *\n * //=collection\n */\nfunction featureCollection(features, options) {\n // Optional Parameters\n options = options || {};\n if (!isObject(options)) throw new Error('options is invalid');\n var bbox = options.bbox;\n var id = options.id;\n\n // Validation\n if (!features) throw new Error('No features passed');\n if (!Array.isArray(features)) throw new Error('features must be an Array');\n if (bbox) validateBBox(bbox);\n if (id) validateId(id);\n\n // Main\n var fc = {type: 'FeatureCollection'};\n if (id) fc.id = id;\n if (bbox) fc.bbox = bbox;\n fc.features = features;\n return fc;\n}\n\n/**\n * Creates a {@link Feature} based on a\n * coordinate array. Properties can be added optionally.\n *\n * @name multiLineString\n * @param {Array>>} coordinates an array of LineStrings\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature} a MultiLineString feature\n * @throws {Error} if no coordinates are passed\n * @example\n * var multiLine = turf.multiLineString([[[0,0],[10,10]]]);\n *\n * //=multiLine\n */\nfunction multiLineString(coordinates, properties, options) {\n if (!coordinates) throw new Error('coordinates is required');\n\n return feature({\n type: 'MultiLineString',\n coordinates: coordinates\n }, properties, options);\n}\n\n/**\n * Creates a {@link Feature} based on a\n * coordinate array. Properties can be added optionally.\n *\n * @name multiPoint\n * @param {Array>} coordinates an array of Positions\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature} a MultiPoint feature\n * @throws {Error} if no coordinates are passed\n * @example\n * var multiPt = turf.multiPoint([[0,0],[10,10]]);\n *\n * //=multiPt\n */\nfunction multiPoint(coordinates, properties, options) {\n if (!coordinates) throw new Error('coordinates is required');\n\n return feature({\n type: 'MultiPoint',\n coordinates: coordinates\n }, properties, options);\n}\n\n/**\n * Creates a {@link Feature} based on a\n * coordinate array. Properties can be added optionally.\n *\n * @name multiPolygon\n * @param {Array>>>} coordinates an array of Polygons\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature} a multipolygon feature\n * @throws {Error} if no coordinates are passed\n * @example\n * var multiPoly = turf.multiPolygon([[[[0,0],[0,10],[10,10],[10,0],[0,0]]]]);\n *\n * //=multiPoly\n *\n */\nfunction multiPolygon(coordinates, properties, options) {\n if (!coordinates) throw new Error('coordinates is required');\n\n return feature({\n type: 'MultiPolygon',\n coordinates: coordinates\n }, properties, options);\n}\n\n/**\n * Creates a {@link Feature} based on a\n * coordinate array. Properties can be added optionally.\n *\n * @name geometryCollection\n * @param {Array} geometries an array of GeoJSON Geometries\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature} a GeoJSON GeometryCollection Feature\n * @example\n * var pt = {\n * \"type\": \"Point\",\n * \"coordinates\": [100, 0]\n * };\n * var line = {\n * \"type\": \"LineString\",\n * \"coordinates\": [ [101, 0], [102, 1] ]\n * };\n * var collection = turf.geometryCollection([pt, line]);\n *\n * //=collection\n */\nfunction geometryCollection(geometries, properties, options) {\n if (!geometries) throw new Error('geometries is required');\n if (!Array.isArray(geometries)) throw new Error('geometries must be an Array');\n\n return feature({\n type: 'GeometryCollection',\n geometries: geometries\n }, properties, options);\n}\n\n/**\n * Round number to precision\n *\n * @param {number} num Number\n * @param {number} [precision=0] Precision\n * @returns {number} rounded number\n * @example\n * turf.round(120.4321)\n * //=120\n *\n * turf.round(120.4321, 2)\n * //=120.43\n */\nfunction round(num, precision) {\n if (num === undefined || num === null || isNaN(num)) throw new Error('num is required');\n if (precision && !(precision >= 0)) throw new Error('precision must be a positive number');\n var multiplier = Math.pow(10, precision || 0);\n return Math.round(num * multiplier) / multiplier;\n}\n\n/**\n * Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.\n * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet\n *\n * @name radiansToLength\n * @param {number} radians in radians across the sphere\n * @param {string} [units='kilometers'] can be degrees, radians, miles, or kilometers inches, yards, metres, meters, kilometres, kilometers.\n * @returns {number} distance\n */\nfunction radiansToLength(radians, units) {\n if (radians === undefined || radians === null) throw new Error('radians is required');\n\n if (units && typeof units !== 'string') throw new Error('units must be a string');\n var factor = factors[units || 'kilometers'];\n if (!factor) throw new Error(units + ' units is invalid');\n return radians * factor;\n}\n\n/**\n * Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians\n * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet\n *\n * @name lengthToRadians\n * @param {number} distance in real units\n * @param {string} [units='kilometers'] can be degrees, radians, miles, or kilometers inches, yards, metres, meters, kilometres, kilometers.\n * @returns {number} radians\n */\nfunction lengthToRadians(distance, units) {\n if (distance === undefined || distance === null) throw new Error('distance is required');\n\n if (units && typeof units !== 'string') throw new Error('units must be a string');\n var factor = factors[units || 'kilometers'];\n if (!factor) throw new Error(units + ' units is invalid');\n return distance / factor;\n}\n\n/**\n * Convert a distance measurement (assuming a spherical Earth) from a real-world unit into degrees\n * Valid units: miles, nauticalmiles, inches, yards, meters, metres, centimeters, kilometres, feet\n *\n * @name lengthToDegrees\n * @param {number} distance in real units\n * @param {string} [units='kilometers'] can be degrees, radians, miles, or kilometers inches, yards, metres, meters, kilometres, kilometers.\n * @returns {number} degrees\n */\nfunction lengthToDegrees(distance, units) {\n return radiansToDegrees(lengthToRadians(distance, units));\n}\n\n/**\n * Converts any bearing angle from the north line direction (positive clockwise)\n * and returns an angle between 0-360 degrees (positive clockwise), 0 being the north line\n *\n * @name bearingToAzimuth\n * @param {number} bearing angle, between -180 and +180 degrees\n * @returns {number} angle between 0 and 360 degrees\n */\nfunction bearingToAzimuth(bearing) {\n if (bearing === null || bearing === undefined) throw new Error('bearing is required');\n\n var angle = bearing % 360;\n if (angle < 0) angle += 360;\n return angle;\n}\n\n/**\n * Converts an angle in radians to degrees\n *\n * @name radiansToDegrees\n * @param {number} radians angle in radians\n * @returns {number} degrees between 0 and 360 degrees\n */\nfunction radiansToDegrees(radians) {\n if (radians === null || radians === undefined) throw new Error('radians is required');\n\n var degrees = radians % (2 * Math.PI);\n return degrees * 180 / Math.PI;\n}\n\n/**\n * Converts an angle in degrees to radians\n *\n * @name degreesToRadians\n * @param {number} degrees angle between 0 and 360 degrees\n * @returns {number} angle in radians\n */\nfunction degreesToRadians(degrees) {\n if (degrees === null || degrees === undefined) throw new Error('degrees is required');\n\n var radians = degrees % 360;\n return radians * Math.PI / 180;\n}\n\n/**\n * Converts a length to the requested unit.\n * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet\n *\n * @param {number} length to be converted\n * @param {string} originalUnit of the length\n * @param {string} [finalUnit='kilometers'] returned unit\n * @returns {number} the converted length\n */\nfunction convertLength(length, originalUnit, finalUnit) {\n if (length === null || length === undefined) throw new Error('length is required');\n if (!(length >= 0)) throw new Error('length must be a positive number');\n\n return radiansToLength(lengthToRadians(length, originalUnit), finalUnit || 'kilometers');\n}\n\n/**\n * Converts a area to the requested unit.\n * Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches\n * @param {number} area to be converted\n * @param {string} [originalUnit='meters'] of the distance\n * @param {string} [finalUnit='kilometers'] returned unit\n * @returns {number} the converted distance\n */\nfunction convertArea(area, originalUnit, finalUnit) {\n if (area === null || area === undefined) throw new Error('area is required');\n if (!(area >= 0)) throw new Error('area must be a positive number');\n\n var startFactor = areaFactors[originalUnit || 'meters'];\n if (!startFactor) throw new Error('invalid original units');\n\n var finalFactor = areaFactors[finalUnit || 'kilometers'];\n if (!finalFactor) throw new Error('invalid final units');\n\n return (area / startFactor) * finalFactor;\n}\n\n/**\n * isNumber\n *\n * @param {*} num Number to validate\n * @returns {boolean} true/false\n * @example\n * turf.isNumber(123)\n * //=true\n * turf.isNumber('foo')\n * //=false\n */\nfunction isNumber(num) {\n return !isNaN(num) && num !== null && !Array.isArray(num);\n}\n\n/**\n * isObject\n *\n * @param {*} input variable to validate\n * @returns {boolean} true/false\n * @example\n * turf.isObject({elevation: 10})\n * //=true\n * turf.isObject('foo')\n * //=false\n */\nfunction isObject(input) {\n return (!!input) && (input.constructor === Object);\n}\n\n/**\n * Validate BBox\n *\n * @private\n * @param {Array} bbox BBox to validate\n * @returns {void}\n * @throws Error if BBox is not valid\n * @example\n * validateBBox([-180, -40, 110, 50])\n * //=OK\n * validateBBox([-180, -40])\n * //=Error\n * validateBBox('Foo')\n * //=Error\n * validateBBox(5)\n * //=Error\n * validateBBox(null)\n * //=Error\n * validateBBox(undefined)\n * //=Error\n */\nfunction validateBBox(bbox) {\n if (!bbox) throw new Error('bbox is required');\n if (!Array.isArray(bbox)) throw new Error('bbox must be an Array');\n if (bbox.length !== 4 && bbox.length !== 6) throw new Error('bbox must be an Array of 4 or 6 numbers');\n bbox.forEach(function (num) {\n if (!isNumber(num)) throw new Error('bbox must only contain numbers');\n });\n}\n\n/**\n * Validate Id\n *\n * @private\n * @param {string|number} id Id to validate\n * @returns {void}\n * @throws Error if Id is not valid\n * @example\n * validateId([-180, -40, 110, 50])\n * //=Error\n * validateId([-180, -40])\n * //=Error\n * validateId('Foo')\n * //=OK\n * validateId(5)\n * //=OK\n * validateId(null)\n * //=Error\n * validateId(undefined)\n * //=Error\n */\nfunction validateId(id) {\n if (!id) throw new Error('id is required');\n if (['string', 'number'].indexOf(typeof id) === -1) throw new Error('id must be a number or a string');\n}\n\n// Deprecated methods\nfunction radians2degrees() {\n throw new Error('method has been renamed to `radiansToDegrees`');\n}\n\nfunction degrees2radians() {\n throw new Error('method has been renamed to `degreesToRadians`');\n}\n\nfunction distanceToDegrees() {\n throw new Error('method has been renamed to `lengthToDegrees`');\n}\n\nfunction distanceToRadians() {\n throw new Error('method has been renamed to `lengthToRadians`');\n}\n\nfunction radiansToDistance() {\n throw new Error('method has been renamed to `radiansToLength`');\n}\n\nfunction bearingToAngle() {\n throw new Error('method has been renamed to `bearingToAzimuth`');\n}\n\nfunction convertDistance() {\n throw new Error('method has been renamed to `convertLength`');\n}\n\nexport { earthRadius, factors, unitsFactors, areaFactors, feature, geometry, point, points, polygon, polygons, lineString, lineStrings, featureCollection, multiLineString, multiPoint, multiPolygon, geometryCollection, round, radiansToLength, lengthToRadians, lengthToDegrees, bearingToAzimuth, radiansToDegrees, degreesToRadians, convertLength, convertArea, isNumber, isObject, validateBBox, validateId, radians2degrees, degrees2radians, distanceToDegrees, distanceToRadians, radiansToDistance, bearingToAngle, convertDistance };\n","import { isNumber } from '@turf/helpers';\n\n/**\n * Unwrap a coordinate from a Point Feature, Geometry or a single coordinate.\n *\n * @name getCoord\n * @param {Array|Geometry|Feature} coord GeoJSON Point or an Array of numbers\n * @returns {Array} coordinates\n * @example\n * var pt = turf.point([10, 10]);\n *\n * var coord = turf.getCoord(pt);\n * //= [10, 10]\n */\nfunction getCoord(coord) {\n if (!coord) throw new Error('coord is required');\n if (coord.type === 'Feature' && coord.geometry !== null && coord.geometry.type === 'Point') return coord.geometry.coordinates;\n if (coord.type === 'Point') return coord.coordinates;\n if (Array.isArray(coord) && coord.length >= 2 && coord[0].length === undefined && coord[1].length === undefined) return coord;\n\n throw new Error('coord must be GeoJSON Point or an Array of numbers');\n}\n\n/**\n * Unwrap coordinates from a Feature, Geometry Object or an Array\n *\n * @name getCoords\n * @param {Array|Geometry|Feature} coords Feature, Geometry Object or an Array\n * @returns {Array} coordinates\n * @example\n * var poly = turf.polygon([[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]);\n *\n * var coords = turf.getCoords(poly);\n * //= [[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]\n */\nfunction getCoords(coords) {\n if (!coords) throw new Error('coords is required');\n\n // Feature\n if (coords.type === 'Feature' && coords.geometry !== null) return coords.geometry.coordinates;\n\n // Geometry\n if (coords.coordinates) return coords.coordinates;\n\n // Array of numbers\n if (Array.isArray(coords)) return coords;\n\n throw new Error('coords must be GeoJSON Feature, Geometry Object or an Array');\n}\n\n/**\n * Checks if coordinates contains a number\n *\n * @name containsNumber\n * @param {Array} coordinates GeoJSON Coordinates\n * @returns {boolean} true if Array contains a number\n */\nfunction containsNumber(coordinates) {\n if (coordinates.length > 1 && isNumber(coordinates[0]) && isNumber(coordinates[1])) {\n return true;\n }\n\n if (Array.isArray(coordinates[0]) && coordinates[0].length) {\n return containsNumber(coordinates[0]);\n }\n throw new Error('coordinates must only contain numbers');\n}\n\n/**\n * Enforce expectations about types of GeoJSON objects for Turf.\n *\n * @name geojsonType\n * @param {GeoJSON} value any GeoJSON object\n * @param {string} type expected GeoJSON type\n * @param {string} name name of calling function\n * @throws {Error} if value is not the expected type.\n */\nfunction geojsonType(value, type, name) {\n if (!type || !name) throw new Error('type and name required');\n\n if (!value || value.type !== type) {\n throw new Error('Invalid input to ' + name + ': must be a ' + type + ', given ' + value.type);\n }\n}\n\n/**\n * Enforce expectations about types of {@link Feature} inputs for Turf.\n * Internally this uses {@link geojsonType} to judge geometry types.\n *\n * @name featureOf\n * @param {Feature} feature a feature with an expected geometry type\n * @param {string} type expected GeoJSON type\n * @param {string} name name of calling function\n * @throws {Error} error if value is not the expected type.\n */\nfunction featureOf(feature, type, name) {\n if (!feature) throw new Error('No feature passed');\n if (!name) throw new Error('.featureOf() requires a name');\n if (!feature || feature.type !== 'Feature' || !feature.geometry) {\n throw new Error('Invalid input to ' + name + ', Feature with geometry required');\n }\n if (!feature.geometry || feature.geometry.type !== type) {\n throw new Error('Invalid input to ' + name + ': must be a ' + type + ', given ' + feature.geometry.type);\n }\n}\n\n/**\n * Enforce expectations about types of {@link FeatureCollection} inputs for Turf.\n * Internally this uses {@link geojsonType} to judge geometry types.\n *\n * @name collectionOf\n * @param {FeatureCollection} featureCollection a FeatureCollection for which features will be judged\n * @param {string} type expected GeoJSON type\n * @param {string} name name of calling function\n * @throws {Error} if value is not the expected type.\n */\nfunction collectionOf(featureCollection, type, name) {\n if (!featureCollection) throw new Error('No featureCollection passed');\n if (!name) throw new Error('.collectionOf() requires a name');\n if (!featureCollection || featureCollection.type !== 'FeatureCollection') {\n throw new Error('Invalid input to ' + name + ', FeatureCollection required');\n }\n for (var i = 0; i < featureCollection.features.length; i++) {\n var feature = featureCollection.features[i];\n if (!feature || feature.type !== 'Feature' || !feature.geometry) {\n throw new Error('Invalid input to ' + name + ', Feature with geometry required');\n }\n if (!feature.geometry || feature.geometry.type !== type) {\n throw new Error('Invalid input to ' + name + ': must be a ' + type + ', given ' + feature.geometry.type);\n }\n }\n}\n\n/**\n * Get Geometry from Feature or Geometry Object\n *\n * @param {Feature|Geometry} geojson GeoJSON Feature or Geometry Object\n * @returns {Geometry|null} GeoJSON Geometry Object\n * @throws {Error} if geojson is not a Feature or Geometry Object\n * @example\n * var point = {\n * \"type\": \"Feature\",\n * \"properties\": {},\n * \"geometry\": {\n * \"type\": \"Point\",\n * \"coordinates\": [110, 40]\n * }\n * }\n * var geom = turf.getGeom(point)\n * //={\"type\": \"Point\", \"coordinates\": [110, 40]}\n */\nfunction getGeom(geojson) {\n if (!geojson) throw new Error('geojson is required');\n if (geojson.geometry !== undefined) return geojson.geometry;\n if (geojson.coordinates || geojson.geometries) return geojson;\n throw new Error('geojson must be a valid Feature or Geometry Object');\n}\n\n/**\n * Get Geometry Type from Feature or Geometry Object\n *\n * @throws {Error} **DEPRECATED** in v5.0.0 in favor of getType\n */\nfunction getGeomType() {\n throw new Error('invariant.getGeomType has been deprecated in v5.0 in favor of invariant.getType');\n}\n\n/**\n * Get GeoJSON object's type, Geometry type is prioritize.\n *\n * @param {GeoJSON} geojson GeoJSON object\n * @param {string} [name=\"geojson\"] name of the variable to display in error message\n * @returns {string} GeoJSON type\n * @example\n * var point = {\n * \"type\": \"Feature\",\n * \"properties\": {},\n * \"geometry\": {\n * \"type\": \"Point\",\n * \"coordinates\": [110, 40]\n * }\n * }\n * var geom = turf.getType(point)\n * //=\"Point\"\n */\nfunction getType(geojson, name) {\n if (!geojson) throw new Error((name || 'geojson') + ' is required');\n // GeoJSON Feature & GeometryCollection\n if (geojson.geometry && geojson.geometry.type) return geojson.geometry.type;\n // GeoJSON Geometry & FeatureCollection\n if (geojson.type) return geojson.type;\n throw new Error((name || 'geojson') + ' is invalid');\n}\n\nexport { getCoord, getCoords, containsNumber, geojsonType, featureOf, collectionOf, getGeom, getGeomType, getType };\n","import { GeoJSONReader, GeoJSONWriter, OverlayOp } from 'turf-jsts';\nimport area from '@turf/area';\nimport { feature } from '@turf/helpers';\nimport { getGeom } from '@turf/invariant';\nimport { flattenEach } from '@turf/meta';\n\n/**\n * Finds the difference between two {@link Polygon|polygons} by clipping the second polygon from the first.\n *\n * @name difference\n * @param {Feature} polygon1 input Polygon feature\n * @param {Feature} polygon2 Polygon feature to difference from polygon1\n * @returns {Feature|null} a Polygon or MultiPolygon feature showing the area of `polygon1` excluding the area of `polygon2` (if empty returns `null`)\n * @example\n * var polygon1 = turf.polygon([[\n * [128, -26],\n * [141, -26],\n * [141, -21],\n * [128, -21],\n * [128, -26]\n * ]], {\n * \"fill\": \"#F00\",\n * \"fill-opacity\": 0.1\n * });\n * var polygon2 = turf.polygon([[\n * [126, -28],\n * [140, -28],\n * [140, -20],\n * [126, -20],\n * [126, -28]\n * ]], {\n * \"fill\": \"#00F\",\n * \"fill-opacity\": 0.1\n * });\n *\n * var difference = turf.difference(polygon1, polygon2);\n *\n * //addToMap\n * var addToMap = [polygon1, polygon2, difference];\n */\nfunction difference(polygon1, polygon2) {\n var geom1 = getGeom(polygon1);\n var geom2 = getGeom(polygon2);\n var properties = polygon1.properties || {};\n\n // Issue #721 - JSTS can't handle empty polygons\n geom1 = removeEmptyPolygon(geom1);\n geom2 = removeEmptyPolygon(geom2);\n if (!geom1) return null;\n if (!geom2) return feature(geom1, properties);\n\n // JSTS difference operation\n var reader = new GeoJSONReader();\n var a = reader.read(geom1);\n var b = reader.read(geom2);\n var differenced = OverlayOp.difference(a, b);\n if (differenced.isEmpty()) return null;\n var writer = new GeoJSONWriter();\n var geom = writer.write(differenced);\n\n return feature(geom, properties);\n}\n\n/**\n * Detect Empty Polygon\n *\n * @private\n * @param {Geometry} geom Geometry Object\n * @returns {Geometry|null} removed any polygons with no areas\n */\nfunction removeEmptyPolygon(geom) {\n switch (geom.type) {\n case 'Polygon':\n if (area(geom) > 1) return geom;\n return null;\n case 'MultiPolygon':\n var coordinates = [];\n flattenEach(geom, function (feature$$1) {\n if (area(feature$$1) > 1) coordinates.push(feature$$1.geometry.coordinates);\n });\n if (coordinates.length) return {type: 'MultiPolygon', coordinates: coordinates};\n }\n}\n\nexport default difference;\n","import { GeoJSONReader, GeoJSONWriter, UnionOp } from 'turf-jsts';\n\n/**\n * Takes two or more {@link Polygon|polygons} and returns a combined polygon. If the input polygons are not contiguous, this function returns a {@link MultiPolygon} feature.\n *\n * @name union\n * @param {...Feature} A polygon to combine\n * @returns {Feature<(Polygon|MultiPolygon)>} a combined {@link Polygon} or {@link MultiPolygon} feature\n * @example\n * var poly1 = turf.polygon([[\n * [-82.574787, 35.594087],\n * [-82.574787, 35.615581],\n * [-82.545261, 35.615581],\n * [-82.545261, 35.594087],\n * [-82.574787, 35.594087]\n * ]], {\"fill\": \"#0f0\"});\n * var poly2 = turf.polygon([[\n * [-82.560024, 35.585153],\n * [-82.560024, 35.602602],\n * [-82.52964, 35.602602],\n * [-82.52964, 35.585153],\n * [-82.560024, 35.585153]\n * ]], {\"fill\": \"#00f\"});\n *\n * var union = turf.union(poly1, poly2);\n *\n * //addToMap\n * var addToMap = [poly1, poly2, union];\n */\nfunction union() {\n var reader = new GeoJSONReader();\n var result = reader.read(JSON.stringify(arguments[0].geometry));\n\n for (var i = 1; i < arguments.length; i++) {\n result = UnionOp.union(result, reader.read(JSON.stringify(arguments[i].geometry)));\n }\n\n var writer = new GeoJSONWriter();\n result = writer.write(result);\n\n return {\n type: 'Feature',\n geometry: result,\n properties: arguments[0].properties\n };\n}\n\nexport default union;\n","import * as CountryCoder from '@ideditor/country-coder';\n\nimport calcArea from '@mapbox/geojson-area';\nimport circleToPolygon from 'circle-to-polygon';\nimport precision from 'geojson-precision';\n\nimport difference from '@turf/difference';\nimport { default as union } from '@turf/union';\n\n\n\n// Reduce an array of locations into a single GeoJSON feature\nfunction _locationReducer(accumulator, location) {\n /* eslint-disable no-console, no-invalid-this */\n let result;\n try {\n let resolved = this.resolveLocation(location);\n if (!resolved || !resolved.feature) {\n console.warn(`Warning: Couldn't resolve location \"${location}\"`);\n return accumulator;\n }\n result = !accumulator ? resolved.feature : union(accumulator, resolved.feature);\n } catch (e) {\n console.warn(`Warning: Error resolving location \"${location}\"`);\n console.warn(e);\n result = accumulator;\n }\n\n return result;\n /* eslint-enable no-console, no-invalid-this */\n}\n\n\n\nfunction _cloneDeep(obj) {\n return JSON.parse(JSON.stringify(obj));\n}\n\n\nexport default class {\n\n // constructor\n //\n // Optionally pass a GeoJSON FeatureCollection of known features which we can refer to later.\n // Each feature must have a filename-like `id`, for example: `something.geojson`\n //\n // {\n // \"type\": \"FeatureCollection\"\n // \"features\": [\n // {\n // \"type\": \"Feature\",\n // \"id\": \"philly_metro.geojson\",\n // \"properties\": { … },\n // \"geometry\": { … }\n // }\n // ]\n // }\n constructor(fc) {\n this._cache = {};\n\n // process input FeatureCollection\n if (fc && fc.type === 'FeatureCollection' && Array.isArray(fc.features)) {\n fc.features.forEach(feature => {\n feature.properties = feature.properties || {};\n let props = feature.properties;\n\n // get `id` from either `id` or `properties`\n let id = feature.id || props.id;\n if (!id || !/^\\S+\\.geojson$/i.test(id)) return;\n\n // ensure id exists and is lowercase\n id = id.toLowerCase();\n feature.id = id;\n props.id = id;\n\n // ensure area property exists\n if (!props.area) {\n const area = calcArea.geometry(feature.geometry) / 1e6; // m² to km²\n props.area = Number(area.toFixed(2));\n }\n\n this._cache[id] = feature;\n });\n }\n\n // Replace CountryCoder world geometry to have a polygon covering the world.\n let world = _cloneDeep(CountryCoder.feature('Q2'));\n world.geometry = {\n type: 'Polygon',\n coordinates: [[[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]]]\n };\n world.id = 'Q2';\n world.properties.id = 'Q2';\n world.properties.area = calcArea.geometry(world.geometry) / 1e6; // m² to km²\n this._cache.Q2 = world;\n }\n\n\n // validateLocation\n //\n // Pass a `location` identifier\n // Returns a result like\n // {\n // type: 'point', 'geojson', or 'countrycoder'\n // location: the queried location\n // id: a unique identifier\n // }\n // or `null` if the location is invalid\n //\n validateLocation(location) {\n if (Array.isArray(location)) { // a [lon,lat] coordinate pair?\n if (location.length === 2 && Number.isFinite(location[0]) && Number.isFinite(location[1]) &&\n location[0] >= -180 && location[0] <= 180 && location[1] >= -90 && location[1] <= 90\n ) {\n const id = '[' + location.toString() + ']';\n return { type: 'point', location: location, id: id };\n }\n\n } else if (typeof location === 'string' && /^\\S+\\.geojson$/i.test(location)) { // a .geojson filename?\n const id = location.toLowerCase();\n if (this._cache[id]) {\n return { type: 'geojson', location: location, id: id };\n }\n\n } else if (typeof location === 'string' || typeof location === 'number') { // a country-coder value?\n const feature = CountryCoder.feature(location);\n if (feature) {\n // Use wikidata QID as the identifier, since that seems to be the only\n // property that everything in CountryCoder is guaranteed to have.\n const id = feature.properties.wikidata;\n return { type: 'countrycoder', location: location, id: id };\n }\n }\n\n return null;\n }\n\n\n // resolveLocation\n //\n // Pass a `location` identifier\n // Returns a result like\n // {\n // type: 'point', 'geojson', or 'countrycoder'\n // location: the queried location\n // id: a unique identifier\n // feature: the geojson feature\n // }\n // or `null` if the location is invalid\n //\n resolveLocation(location) {\n const valid = this.validateLocation(location);\n if (!valid) return null;\n\n // return a result from cache if we can\n if (this._cache[valid.id]) {\n return Object.assign(valid, { feature: this._cache[valid.id] });\n }\n\n // a [lon,lat] coordinate pair?\n if (valid.type === 'point') {\n const RADIUS = 25000; // meters\n const EDGES = 10;\n const PRECISION = 3;\n const area = Math.PI * RADIUS * RADIUS / 1e6; // m² to km²\n const feature = this._cache[valid.id] = precision({\n type: 'Feature',\n id: valid.id,\n properties: { id: valid.id, area: Number(area.toFixed(2)) },\n geometry: circleToPolygon(location, RADIUS, EDGES)\n }, PRECISION);\n return Object.assign(valid, { feature: feature });\n\n // a .geojson filename?\n } else if (valid.type === 'geojson') {\n // nothing to do here - these are all in _cache and would have returned already\n\n // a country-coder identifier?\n } else if (valid.type === 'countrycoder') {\n let feature = _cloneDeep(CountryCoder.feature(valid.id));\n let props = feature.properties;\n\n // -> This block of code is weird and requires some explanation. <-\n // CountryCoder includes higher level features which are made up of members.\n // These features don't have their own geometry, but CountryCoder provides an\n // `aggregateFeature` method to combine these members into a MultiPolygon.\n // BUT, when we try to actually work with these aggregated MultiPolygons,\n // Turf/JSTS gets crashy because of topography bugs.\n // SO, we'll aggregate the features ourselves by unioning them together.\n // This approach also has the benefit of removing all the internal boaders and\n // simplifying the regional polygons a lot.\n if (Array.isArray(props.members)) {\n let seed = feature.geometry ? feature : null;\n let aggregate = props.members.reduce(_locationReducer.bind(this), seed);\n feature.geometry = aggregate.geometry;\n }\n\n // ensure area property exists\n if (!props.area) {\n const area = calcArea.geometry(feature.geometry) / 1e6; // m² to km²\n props.area = Number(area.toFixed(2));\n }\n\n // ensure id property exists\n feature.id = valid.id;\n props.id = valid.id;\n\n this._cache[valid.id] = feature;\n return Object.assign(valid, { feature: feature });\n }\n\n return null;\n }\n\n\n // resolveLocationSet\n //\n // Pass a `locationSet` Object like:\n // `{ include: [ Array ], exclude: [ Array ] }`\n // Returns a stable identifier string of the form:\n // \"+[included]-[excluded]\"\n //\n resolveLocationSet(locationSet) {\n locationSet = locationSet || {};\n const resolve = this.resolveLocation.bind(this);\n let include = (locationSet.include || []).map(resolve).filter(Boolean);\n let exclude = (locationSet.exclude || []).map(resolve).filter(Boolean);\n\n if (!include.length) {\n include = [resolve('Q2')]; // default to 'the world'\n }\n\n // return quickly if it's a single included location..\n if (include.length === 1 && exclude.length === 0) {\n return include[0].feature;\n }\n\n // generate stable identifier\n include.sort(sortFeatures);\n let id = '+[' + include.map(d => d.id).join(',') + ']';\n if (exclude.length) {\n exclude.sort(sortFeatures);\n id += '-[' + exclude.map(d => d.id).join(',') + ']';\n }\n\n // return cached?\n if (this._cache[id]) {\n return this._cache[id];\n }\n\n // calculate unions\n let includeGeoJSON = include.map(d => d.location).reduce(_locationReducer.bind(this), null);\n let excludeGeoJSON = exclude.map(d => d.location).reduce(_locationReducer.bind(this), null);\n\n // calculate difference, update area and return result\n let resultGeoJSON = excludeGeoJSON ? difference(includeGeoJSON, excludeGeoJSON) : includeGeoJSON;\n const area = calcArea.geometry(resultGeoJSON.geometry) / 1e6; // m² to km²\n resultGeoJSON.id = id;\n resultGeoJSON.properties = { id: id, area: Number(area.toFixed(2)) };\n\n return this._cache[id] = resultGeoJSON;\n\n\n // Sorting the location lists is ok because they end up unioned together.\n // This sorting makes it possible to generate a deterministic id.\n function sortFeatures(a, b) {\n const rank = { countrycoder: 1, geojson: 2, point: 3 };\n const aRank = rank[a.type];\n const bRank = rank[b.type];\n\n return (aRank > bRank) ? 1\n : (aRank < bRank) ? -1\n : a.id.localeCompare(b.id);\n }\n }\n\n\n cache() {\n return this._cache;\n }\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { select as d3_select } from 'd3-selection';\n\nimport LocationConflation from '@ideditor/location-conflation';\nimport whichPolygon from 'which-polygon';\n\nimport { fileFetcher } from '../core/file_fetcher';\nimport { t, localizer } from '../core/localizer';\nimport { svgIcon } from '../svg/icon';\nimport { uiDisclosure } from '../ui/disclosure';\nimport { utilRebind } from '../util/rebind';\n\n\nlet _oci = null;\n\nexport function uiSuccess(context) {\n const MAXEVENTS = 2;\n const dispatch = d3_dispatch('cancel');\n let _changeset;\n let _location;\n ensureOSMCommunityIndex(); // start fetching the data\n\n\n function ensureOSMCommunityIndex() {\n const data = fileFetcher;\n return Promise.all([ data.get('oci_resources'), data.get('oci_features') ])\n .then(vals => {\n if (_oci) return _oci;\n\n const ociResources = vals[0].resources;\n const loco = new LocationConflation(vals[1]);\n let ociFeatures = {};\n\n Object.values(ociResources).forEach(resource => {\n const feature = loco.resolveLocationSet(resource.locationSet);\n let ociFeature = ociFeatures[feature.id];\n if (!ociFeature) {\n ociFeature = JSON.parse(JSON.stringify(feature)); // deep clone\n ociFeature.properties.resourceIDs = new Set();\n ociFeatures[feature.id] = ociFeature;\n }\n ociFeature.properties.resourceIDs.add(resource.id);\n });\n\n return _oci = {\n features: ociFeatures,\n resources: ociResources,\n query: whichPolygon({ type: 'FeatureCollection', features: Object.values(ociFeatures) })\n };\n });\n }\n\n\n // string-to-date parsing in JavaScript is weird\n function parseEventDate(when) {\n if (!when) return;\n\n let raw = when.trim();\n if (!raw) return;\n\n if (!/Z$/.test(raw)) { // if no trailing 'Z', add one\n raw += 'Z'; // this forces date to be parsed as a UTC date\n }\n\n const parsed = new Date(raw);\n return new Date(parsed.toUTCString().substr(0, 25)); // convert to local timezone\n }\n\n\n function success(selection) {\n let header = selection\n .append('div')\n .attr('class', 'header fillL');\n\n header\n .append('h3')\n .text(t('success.just_edited'));\n\n header\n .append('button')\n .attr('class', 'close')\n .on('click', () => dispatch.call('cancel'))\n .call(svgIcon('#iD-icon-close'));\n\n let body = selection\n .append('div')\n .attr('class', 'body save-success fillL');\n\n let summary = body\n .append('div')\n .attr('class', 'save-summary');\n\n summary\n .append('h3')\n .text(t('success.thank_you' + (_location ? '_location' : ''), { where: _location }));\n\n summary\n .append('p')\n .text(t('success.help_html'))\n .append('a')\n .attr('class', 'link-out')\n .attr('target', '_blank')\n .attr('tabindex', -1)\n .attr('href', t('success.help_link_url'))\n .call(svgIcon('#iD-icon-out-link', 'inline'))\n .append('span')\n .text(t('success.help_link_text'));\n\n let osm = context.connection();\n if (!osm) return;\n\n let changesetURL = osm.changesetURL(_changeset.id);\n\n let table = summary\n .append('table')\n .attr('class', 'summary-table');\n\n let row = table\n .append('tr')\n .attr('class', 'summary-row');\n\n row\n .append('td')\n .attr('class', 'cell-icon summary-icon')\n .append('a')\n .attr('target', '_blank')\n .attr('href', changesetURL)\n .append('svg')\n .attr('class', 'logo-small')\n .append('use')\n .attr('xlink:href', '#iD-logo-osm');\n\n let summaryDetail = row\n .append('td')\n .attr('class', 'cell-detail summary-detail');\n\n summaryDetail\n .append('a')\n .attr('class', 'cell-detail summary-view-on-osm')\n .attr('target', '_blank')\n .attr('href', changesetURL)\n .text(t('success.view_on_osm'));\n\n summaryDetail\n .append('div')\n .html(t('success.changeset_id', {\n changeset_id: `${_changeset.id} `\n }));\n\n\n // Get OSM community index features intersecting the map..\n ensureOSMCommunityIndex()\n .then(oci => {\n let communities = [];\n const properties = oci.query(context.map().center(), true) || [];\n\n // Gather the communities from the result\n properties.forEach(props => {\n const resourceIDs = Array.from(props.resourceIDs);\n resourceIDs.forEach(resourceID => {\n const resource = oci.resources[resourceID];\n communities.push({\n area: props.area || Infinity,\n order: resource.order || 0,\n resource: resource\n });\n });\n });\n\n // sort communities by feature area ascending, community order descending\n communities.sort((a, b) => a.area - b.area || b.order - a.order);\n\n body\n .call(showCommunityLinks, communities.map(c => c.resource));\n });\n }\n\n\n function showCommunityLinks(selection, resources) {\n let communityLinks = selection\n .append('div')\n .attr('class', 'save-communityLinks');\n\n communityLinks\n .append('h3')\n .text(t('success.like_osm'));\n\n let table = communityLinks\n .append('table')\n .attr('class', 'community-table');\n\n let row = table.selectAll('.community-row')\n .data(resources);\n\n let rowEnter = row.enter()\n .append('tr')\n .attr('class', 'community-row');\n\n rowEnter\n .append('td')\n .attr('class', 'cell-icon community-icon')\n .append('a')\n .attr('target', '_blank')\n .attr('href', d => d.url)\n .append('svg')\n .attr('class', 'logo-small')\n .append('use')\n .attr('xlink:href', d => `#community-${d.type}`);\n\n let communityDetail = rowEnter\n .append('td')\n .attr('class', 'cell-detail community-detail');\n\n communityDetail\n .each(showCommunityDetails);\n\n communityLinks\n .append('div')\n .attr('class', 'community-missing')\n .text(t('success.missing'))\n .append('a')\n .attr('class', 'link-out')\n .attr('target', '_blank')\n .attr('tabindex', -1)\n .call(svgIcon('#iD-icon-out-link', 'inline'))\n .attr('href', 'https://github.com/osmlab/osm-community-index/issues')\n .append('span')\n .text(t('success.tell_us'));\n }\n\n\n function showCommunityDetails(d) {\n let selection = d3_select(this);\n let communityID = d.id;\n let replacements = {\n url: linkify(d.url),\n signupUrl: linkify(d.signupUrl || d.url)\n };\n\n selection\n .append('div')\n .attr('class', 'community-name')\n .append('a')\n .attr('target', '_blank')\n .attr('href', d.url)\n .text(t(`community.${d.id}.name`));\n\n let descriptionHTML = t(`community.${d.id}.description`, replacements);\n\n if (d.type === 'reddit') { // linkify subreddits #4997\n descriptionHTML = descriptionHTML\n .replace(/(\\/r\\/\\w*\\/*)/i, match => linkify(d.url, match));\n }\n\n selection\n .append('div')\n .attr('class', 'community-description')\n .html(descriptionHTML);\n\n if (d.extendedDescription || (d.languageCodes && d.languageCodes.length)) {\n selection\n .append('div')\n .call(uiDisclosure(context, `community-more-${d.id}`, false)\n .expanded(false)\n .updatePreference(false)\n .title(t('success.more'))\n .content(showMore)\n );\n }\n\n let nextEvents = (d.events || [])\n .map(event => {\n event.date = parseEventDate(event.when);\n return event;\n })\n .filter(event => { // date is valid and future (or today)\n const t = event.date.getTime();\n const now = (new Date()).setHours(0,0,0,0);\n return !isNaN(t) && t >= now;\n })\n .sort((a, b) => { // sort by date ascending\n return a.date < b.date ? -1 : a.date > b.date ? 1 : 0;\n })\n .slice(0, MAXEVENTS); // limit number of events shown\n\n if (nextEvents.length) {\n selection\n .append('div')\n .call(uiDisclosure(context, `community-events-${d.id}`, false)\n .expanded(false)\n .updatePreference(false)\n .title(t('success.events'))\n .content(showNextEvents)\n )\n .select('.hide-toggle')\n .append('span')\n .attr('class', 'badge-text')\n .text(nextEvents.length);\n }\n\n\n function showMore(selection) {\n let more = selection.selectAll('.community-more')\n .data([0]);\n\n let moreEnter = more.enter()\n .append('div')\n .attr('class', 'community-more');\n\n if (d.extendedDescription) {\n moreEnter\n .append('div')\n .attr('class', 'community-extended-description')\n .html(t(`community.${d.id}.extendedDescription`, replacements));\n }\n\n if (d.languageCodes && d.languageCodes.length) {\n const languageList = d.languageCodes\n .map(code => localizer.languageName(code))\n .join(', ');\n\n moreEnter\n .append('div')\n .attr('class', 'community-languages')\n .text(t('success.languages', { languages: languageList }));\n }\n }\n\n\n function showNextEvents(selection) {\n let events = selection\n .append('div')\n .attr('class', 'community-events');\n\n let item = events.selectAll('.community-event')\n .data(nextEvents);\n\n let itemEnter = item.enter()\n .append('div')\n .attr('class', 'community-event');\n\n itemEnter\n .append('div')\n .attr('class', 'community-event-name')\n .append('a')\n .attr('target', '_blank')\n .attr('href', d => d.url)\n .text(d => {\n let name = d.name;\n if (d.i18n && d.id) {\n name = t(`community.${communityID}.events.${d.id}.name`, { default: name });\n }\n return name;\n });\n\n itemEnter\n .append('div')\n .attr('class', 'community-event-when')\n .text(d => {\n let options = { weekday: 'short', day: 'numeric', month: 'short', year: 'numeric' };\n if (d.date.getHours() || d.date.getMinutes()) { // include time if it has one\n options.hour = 'numeric';\n options.minute = 'numeric';\n }\n return d.date.toLocaleString(localizer.localeCode(), options);\n });\n\n itemEnter\n .append('div')\n .attr('class', 'community-event-where')\n .text(d => {\n let where = d.where;\n if (d.i18n && d.id) {\n where = t(`community.${communityID}.events.${d.id}.where`, { default: where });\n }\n return where;\n });\n\n itemEnter\n .append('div')\n .attr('class', 'community-event-description')\n .text(d => {\n let description = d.description;\n if (d.i18n && d.id) {\n description = t(`community.${communityID}.events.${d.id}.description`, { default: description });\n }\n return description;\n });\n }\n\n\n function linkify(url, text) {\n text = text || url;\n return `${text} `;\n }\n }\n\n\n success.changeset = function(val) {\n if (!arguments.length) return _changeset;\n _changeset = val;\n return success;\n };\n\n\n success.location = function(val) {\n if (!arguments.length) return _location;\n _location = val;\n return success;\n };\n\n\n return utilRebind(success, dispatch, 'on');\n}\n","import { event as d3_event, select as d3_select } from 'd3-selection';\nimport { t } from '../core/localizer';\n\nimport { modeBrowse } from './browse';\nimport { services } from '../services';\nimport { uiConflicts } from '../ui/conflicts';\nimport { uiConfirm } from '../ui/confirm';\nimport { uiCommit } from '../ui/commit';\nimport { uiSuccess } from '../ui/success';\nimport { utilKeybinding } from '../util';\n\n\nexport function modeSave(context) {\n var mode = { id: 'save' };\n var keybinding = utilKeybinding('modeSave');\n\n var commit = uiCommit(context)\n .on('cancel', cancel);\n var _conflictsUi; // uiConflicts\n\n var _location;\n var _success;\n\n var uploader = context.uploader()\n .on('saveStarted.modeSave', function() {\n keybindingOff();\n })\n // fire off some async work that we want to be ready later\n .on('willAttemptUpload.modeSave', prepareForSuccess)\n .on('progressChanged.modeSave', showProgress)\n .on('resultNoChanges.modeSave', function() {\n cancel();\n })\n .on('resultErrors.modeSave', showErrors)\n .on('resultConflicts.modeSave', showConflicts)\n .on('resultSuccess.modeSave', showSuccess);\n\n\n function cancel() {\n context.enter(modeBrowse(context));\n }\n\n\n function showProgress(num, total) {\n var modal = context.container().select('.loading-modal .modal-section');\n var progress = modal.selectAll('.progress')\n .data([0]);\n\n // enter/update\n progress.enter()\n .append('div')\n .attr('class', 'progress')\n .merge(progress)\n .text(t('save.conflict_progress', { num: num, total: total }));\n }\n\n\n function showConflicts(changeset, conflicts, origChanges) {\n\n var selection = context.container()\n .select('.sidebar')\n .append('div')\n .attr('class','sidebar-component');\n\n context.container().selectAll('.main-content')\n .classed('active', true)\n .classed('inactive', false);\n\n _conflictsUi = uiConflicts(context)\n .conflictList(conflicts)\n .origChanges(origChanges)\n .on('cancel', function() {\n context.container().selectAll('.main-content')\n .classed('active', false)\n .classed('inactive', true);\n selection.remove();\n keybindingOn();\n\n uploader.cancelConflictResolution();\n })\n .on('save', function() {\n context.container().selectAll('.main-content')\n .classed('active', false)\n .classed('inactive', true);\n selection.remove();\n\n uploader.processResolvedConflicts(changeset);\n });\n\n selection.call(_conflictsUi);\n }\n\n\n function showErrors(errors) {\n keybindingOn();\n\n var selection = uiConfirm(context.container());\n selection\n .select('.modal-section.header')\n .append('h3')\n .text(t('save.error'));\n\n addErrors(selection, errors);\n selection.okButton();\n }\n\n\n function addErrors(selection, data) {\n var message = selection\n .select('.modal-section.message-text');\n\n var items = message\n .selectAll('.error-container')\n .data(data);\n\n var enter = items.enter()\n .append('div')\n .attr('class', 'error-container');\n\n enter\n .append('a')\n .attr('class', 'error-description')\n .attr('href', '#')\n .classed('hide-toggle', true)\n .text(function(d) { return d.msg || t('save.unknown_error_details'); })\n .on('click', function() {\n d3_event.preventDefault();\n\n var error = d3_select(this);\n var detail = d3_select(this.nextElementSibling);\n var exp = error.classed('expanded');\n\n detail.style('display', exp ? 'none' : 'block');\n error.classed('expanded', !exp);\n });\n\n var details = enter\n .append('div')\n .attr('class', 'error-detail-container')\n .style('display', 'none');\n\n details\n .append('ul')\n .attr('class', 'error-detail-list')\n .selectAll('li')\n .data(function(d) { return d.details || []; })\n .enter()\n .append('li')\n .attr('class', 'error-detail-item')\n .text(function(d) { return d; });\n\n items.exit()\n .remove();\n }\n\n\n function showSuccess(changeset) {\n commit.reset();\n\n var ui = _success\n .changeset(changeset)\n .location(_location)\n .on('cancel', function() { context.ui().sidebar.hide(); });\n\n context.enter(modeBrowse(context).sidebar(ui));\n }\n\n\n function keybindingOn() {\n d3_select(document)\n .call(keybinding.on('⎋', cancel, true));\n }\n\n\n function keybindingOff() {\n d3_select(document)\n .call(keybinding.unbind);\n }\n\n\n // Reverse geocode current map location so we can display a message on\n // the success screen like \"Thank you for editing around place, region.\"\n function prepareForSuccess() {\n _success = uiSuccess(context);\n _location = null;\n if (!services.geocoder) return;\n\n services.geocoder.reverse(context.map().center(), function(err, result) {\n if (err || !result || !result.address) return;\n\n var addr = result.address;\n var place = (addr && (addr.town || addr.city || addr.county)) || '';\n var region = (addr && (addr.state || addr.country)) || '';\n var separator = (place && region) ? t('success.thank_you_where.separator') : '';\n\n _location = t('success.thank_you_where.format',\n { place: place, separator: separator, region: region }\n );\n });\n }\n\n\n mode.selectedIDs = function() {\n return _conflictsUi ? _conflictsUi.shownEntityIds() : [];\n };\n\n\n mode.enter = function() {\n // Show sidebar\n context.ui().sidebar.expand();\n\n function done() {\n context.ui().sidebar.show(commit);\n }\n\n keybindingOn();\n\n context.container().selectAll('.main-content')\n .classed('active', false)\n .classed('inactive', true);\n\n var osm = context.connection();\n if (!osm) {\n cancel();\n return;\n }\n\n if (osm.authenticated()) {\n done();\n } else {\n osm.authenticate(function(err) {\n if (err) {\n cancel();\n } else {\n done();\n }\n });\n }\n };\n\n\n mode.exit = function() {\n\n keybindingOff();\n\n context.container().selectAll('.main-content')\n .classed('active', true)\n .classed('inactive', false);\n\n context.ui().sidebar.hide();\n };\n\n return mode;\n}\n","import { select as d3_select } from 'd3-selection';\n\nimport { t, localizer } from '../core/localizer';\nimport { svgIcon } from '../svg/icon';\nimport { services } from '../services';\n\nexport function uiImproveOsmComments() {\n let _qaItem;\n\n function issueComments(selection) {\n // make the div immediately so it appears above the buttons\n let comments = selection.selectAll('.comments-container')\n .data([0]);\n\n comments = comments.enter()\n .append('div')\n .attr('class', 'comments-container')\n .merge(comments);\n\n // must retrieve comments from API before they can be displayed\n services.improveOSM.getComments(_qaItem)\n .then(d => {\n if (!d.comments) return; // nothing to do here\n\n const commentEnter = comments.selectAll('.comment')\n .data(d.comments)\n .enter()\n .append('div')\n .attr('class', 'comment');\n\n commentEnter\n .append('div')\n .attr('class', 'comment-avatar')\n .call(svgIcon('#iD-icon-avatar', 'comment-avatar-icon'));\n\n const mainEnter = commentEnter\n .append('div')\n .attr('class', 'comment-main');\n\n const metadataEnter = mainEnter\n .append('div')\n .attr('class', 'comment-metadata');\n\n metadataEnter\n .append('div')\n .attr('class', 'comment-author')\n .each(function(d) {\n const osm = services.osm;\n let selection = d3_select(this);\n if (osm && d.username) {\n selection = selection\n .append('a')\n .attr('class', 'comment-author-link')\n .attr('href', osm.userURL(d.username))\n .attr('tabindex', -1)\n .attr('target', '_blank');\n }\n selection\n .text(d => d.username);\n });\n\n metadataEnter\n .append('div')\n .attr('class', 'comment-date')\n .text(d => t('note.status.commented', { when: localeDateString(d.timestamp) }));\n\n mainEnter\n .append('div')\n .attr('class', 'comment-text')\n .append('p')\n .text(d => d.text);\n })\n .catch(err => {\n console.log(err); // eslint-disable-line no-console\n });\n }\n\n function localeDateString(s) {\n if (!s) return null;\n const options = { day: 'numeric', month: 'short', year: 'numeric' };\n const d = new Date(s * 1000); // timestamp is served in seconds, date takes ms\n if (isNaN(d.getTime())) return null;\n return d.toLocaleDateString(localizer.localeCode(), options);\n }\n\n issueComments.issue = function(val) {\n if (!arguments.length) return _qaItem;\n _qaItem = val;\n return issueComments;\n };\n\n return issueComments;\n}\n","import {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { presetManager } from '../presets';\nimport { modeSelect } from '../modes/select';\nimport { t } from '../core/localizer';\nimport { utilDisplayName, utilHighlightEntities, utilEntityRoot } from '../util';\n\nexport function uiImproveOsmDetails(context) {\n let _qaItem;\n\n\n function issueDetail(d) {\n if (d.desc) return d.desc;\n const issueKey = d.issueKey;\n d.replacements = d.replacements || {};\n d.replacements.default = t('inspector.unknown'); // special key `default` works as a fallback string\n return t(`QA.improveOSM.error_types.${issueKey}.description`, d.replacements);\n }\n\n\n function improveOsmDetails(selection) {\n const details = selection.selectAll('.error-details')\n .data(\n (_qaItem ? [_qaItem] : []),\n d => `${d.id}-${d.status || 0}`\n );\n\n details.exit()\n .remove();\n\n const detailsEnter = details.enter()\n .append('div')\n .attr('class', 'error-details qa-details-container');\n\n\n // description\n const descriptionEnter = detailsEnter\n .append('div')\n .attr('class', 'qa-details-subsection');\n\n descriptionEnter\n .append('h4')\n .text(() => t('QA.keepRight.detail_description'));\n\n descriptionEnter\n .append('div')\n .attr('class', 'qa-details-description-text')\n .html(issueDetail);\n\n // If there are entity links in the error message..\n let relatedEntities = [];\n descriptionEnter.selectAll('.error_entity_link, .error_object_link')\n .each(function() {\n const link = d3_select(this);\n const isObjectLink = link.classed('error_object_link');\n const entityID = isObjectLink ?\n (utilEntityRoot(_qaItem.objectType) + _qaItem.objectId)\n : this.textContent;\n const entity = context.hasEntity(entityID);\n\n relatedEntities.push(entityID);\n\n // Add click handler\n link\n .on('mouseenter', () => {\n utilHighlightEntities([entityID], true, context);\n })\n .on('mouseleave', () => {\n utilHighlightEntities([entityID], false, context);\n })\n .on('click', () => {\n d3_event.preventDefault();\n\n utilHighlightEntities([entityID], false, context);\n\n const osmlayer = context.layers().layer('osm');\n if (!osmlayer.enabled()) {\n osmlayer.enabled(true);\n }\n\n context.map().centerZoom(_qaItem.loc, 20);\n\n if (entity) {\n context.enter(modeSelect(context, [entityID]));\n } else {\n context.loadEntity(entityID, () => {\n context.enter(modeSelect(context, [entityID]));\n });\n }\n });\n\n // Replace with friendly name if possible\n // (The entity may not yet be loaded into the graph)\n if (entity) {\n let name = utilDisplayName(entity); // try to use common name\n\n if (!name && !isObjectLink) {\n const preset = presetManager.match(entity, context.graph());\n name = preset && !preset.isFallback() && preset.name(); // fallback to preset name\n }\n\n if (name) {\n this.innerText = name;\n }\n }\n });\n\n // Don't hide entities related to this error - #5880\n context.features().forceVisible(relatedEntities);\n context.map().pan([0,0]); // trigger a redraw\n }\n\n improveOsmDetails.issue = function(val) {\n if (!arguments.length) return _qaItem;\n _qaItem = val;\n return improveOsmDetails;\n };\n\n return improveOsmDetails;\n}\n","import { t } from '../core/localizer';\n\n\nexport function uiImproveOsmHeader() {\n let _qaItem;\n\n\n function issueTitle(d) {\n const issueKey = d.issueKey;\n d.replacements = d.replacements || {};\n d.replacements.default = t('inspector.unknown'); // special key `default` works as a fallback string\n return t(`QA.improveOSM.error_types.${issueKey}.title`, d.replacements);\n }\n\n\n function improveOsmHeader(selection) {\n const header = selection.selectAll('.qa-header')\n .data(\n (_qaItem ? [_qaItem] : []),\n d => `${d.id}-${d.status || 0}`\n );\n\n header.exit()\n .remove();\n\n const headerEnter = header.enter()\n .append('div')\n .attr('class', 'qa-header');\n\n const svgEnter = headerEnter\n .append('div')\n .attr('class', 'qa-header-icon')\n .classed('new', d => d.id < 0)\n .append('svg')\n .attr('width', '20px')\n .attr('height', '30px')\n .attr('viewbox', '0 0 20 30')\n .attr('class', d => `preset-icon-28 qaItem ${d.service} itemId-${d.id} itemType-${d.itemType}`);\n\n svgEnter\n .append('polygon')\n .attr('fill', 'currentColor')\n .attr('class', 'qaItem-fill')\n .attr('points', '16,3 4,3 1,6 1,17 4,20 7,20 10,27 13,20 16,20 19,17.033 19,6');\n\n svgEnter\n .append('use')\n .attr('class', 'icon-annotation')\n .attr('width', '13px')\n .attr('height', '13px')\n .attr('transform', 'translate(3.5, 5)')\n .attr('xlink:href', d => {\n const picon = d.icon;\n if (!picon) {\n return '';\n } else {\n const isMaki = /^maki-/.test(picon);\n return `#${picon}${isMaki ? '-11' : ''}`;\n }\n });\n\n headerEnter\n .append('div')\n .attr('class', 'qa-header-label')\n .text(issueTitle);\n }\n\n improveOsmHeader.issue = function(val) {\n if (!arguments.length) return _qaItem;\n _qaItem = val;\n return improveOsmHeader;\n };\n\n return improveOsmHeader;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { select as d3_select } from 'd3-selection';\n\nimport { t } from '../core/localizer';\nimport { services } from '../services';\nimport { modeBrowse } from '../modes/browse';\nimport { svgIcon } from '../svg/icon';\n\nimport { uiImproveOsmComments } from './improveOSM_comments';\nimport { uiImproveOsmDetails } from './improveOSM_details';\nimport { uiImproveOsmHeader } from './improveOSM_header';\n\nimport { utilNoAuto, utilRebind } from '../util';\n\nexport function uiImproveOsmEditor(context) {\n const dispatch = d3_dispatch('change');\n const qaDetails = uiImproveOsmDetails(context);\n const qaComments = uiImproveOsmComments(context);\n const qaHeader = uiImproveOsmHeader(context);\n\n let _qaItem;\n\n function improveOsmEditor(selection) {\n\n const headerEnter = selection.selectAll('.header')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'header fillL');\n\n headerEnter\n .append('button')\n .attr('class', 'close')\n .on('click', () => context.enter(modeBrowse(context)))\n .call(svgIcon('#iD-icon-close'));\n\n headerEnter\n .append('h3')\n .text(t('QA.improveOSM.title'));\n\n let body = selection.selectAll('.body')\n .data([0]);\n\n body = body.enter()\n .append('div')\n .attr('class', 'body')\n .merge(body);\n\n const editor = body.selectAll('.qa-editor')\n .data([0]);\n\n editor.enter()\n .append('div')\n .attr('class', 'modal-section qa-editor')\n .merge(editor)\n .call(qaHeader.issue(_qaItem))\n .call(qaDetails.issue(_qaItem))\n .call(qaComments.issue(_qaItem))\n .call(improveOsmSaveSection);\n }\n\n function improveOsmSaveSection(selection) {\n const isSelected = (_qaItem && _qaItem.id === context.selectedErrorID());\n const isShown = (_qaItem && (isSelected || _qaItem.newComment || _qaItem.comment));\n let saveSection = selection.selectAll('.qa-save')\n .data(\n (isShown ? [_qaItem] : []),\n d => `${d.id}-${d.status || 0}`\n );\n\n // exit\n saveSection.exit()\n .remove();\n\n // enter\n const saveSectionEnter = saveSection.enter()\n .append('div')\n .attr('class', 'qa-save save-section cf');\n\n saveSectionEnter\n .append('h4')\n .attr('class', '.qa-save-header')\n .text(t('note.newComment'));\n\n saveSectionEnter\n .append('textarea')\n .attr('class', 'new-comment-input')\n .attr('placeholder', t('QA.keepRight.comment_placeholder'))\n .attr('maxlength', 1000)\n .property('value', d => d.newComment)\n .call(utilNoAuto)\n .on('input', changeInput)\n .on('blur', changeInput);\n\n // update\n saveSection = saveSectionEnter\n .merge(saveSection)\n .call(qaSaveButtons);\n\n function changeInput() {\n const input = d3_select(this);\n let val = input.property('value').trim();\n\n if (val === '') {\n val = undefined;\n }\n\n // store the unsaved comment with the issue itself\n _qaItem = _qaItem.update({ newComment: val });\n\n const qaService = services.improveOSM;\n if (qaService) {\n qaService.replaceItem(_qaItem);\n }\n\n saveSection\n .call(qaSaveButtons);\n }\n }\n\n function qaSaveButtons(selection) {\n const isSelected = (_qaItem && _qaItem.id === context.selectedErrorID());\n let buttonSection = selection.selectAll('.buttons')\n .data((isSelected ? [_qaItem] : []), d => d.status + d.id);\n\n // exit\n buttonSection.exit()\n .remove();\n\n // enter\n const buttonEnter = buttonSection.enter()\n .append('div')\n .attr('class', 'buttons');\n\n buttonEnter\n .append('button')\n .attr('class', 'button comment-button action')\n .text(t('QA.keepRight.save_comment'));\n\n buttonEnter\n .append('button')\n .attr('class', 'button close-button action');\n\n buttonEnter\n .append('button')\n .attr('class', 'button ignore-button action');\n\n // update\n buttonSection = buttonSection\n .merge(buttonEnter);\n\n buttonSection.select('.comment-button')\n .attr('disabled', d => d.newComment ? null : true)\n .on('click.comment', function(d) {\n this.blur(); // avoid keeping focus on the button - #4641\n const qaService = services.improveOSM;\n if (qaService) {\n qaService.postUpdate(d, (err, item) => dispatch.call('change', item));\n }\n });\n\n buttonSection.select('.close-button')\n .text(d => {\n const andComment = (d.newComment ? '_comment' : '');\n return t(`QA.keepRight.close${andComment}`);\n })\n .on('click.close', function(d) {\n this.blur(); // avoid keeping focus on the button - #4641\n const qaService = services.improveOSM;\n if (qaService) {\n d.newStatus = 'SOLVED';\n qaService.postUpdate(d, (err, item) => dispatch.call('change', item));\n }\n });\n\n buttonSection.select('.ignore-button')\n .text(d => {\n const andComment = (d.newComment ? '_comment' : '');\n return t(`QA.keepRight.ignore${andComment}`);\n })\n .on('click.ignore', function(d) {\n this.blur(); // avoid keeping focus on the button - #4641\n const qaService = services.improveOSM;\n if (qaService) {\n d.newStatus = 'INVALID';\n qaService.postUpdate(d, (err, item) => dispatch.call('change', item));\n }\n });\n }\n\n // NOTE: Don't change method name until UI v3 is merged\n improveOsmEditor.error = function(val) {\n if (!arguments.length) return _qaItem;\n _qaItem = val;\n return improveOsmEditor;\n };\n\n return utilRebind(improveOsmEditor, dispatch, 'on');\n}\n","import {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { presetManager } from '../presets';\nimport { modeSelect } from '../modes/select';\nimport { t } from '../core/localizer';\nimport { utilDisplayName, utilHighlightEntities, utilEntityRoot } from '../util';\n\n\nexport function uiKeepRightDetails(context) {\n let _qaItem;\n\n\n function issueDetail(d) {\n const { itemType, parentIssueType } = d;\n const unknown = t('inspector.unknown');\n let replacements = d.replacements || {};\n replacements.default = unknown; // special key `default` works as a fallback string\n\n let detail = t(`QA.keepRight.errorTypes.${itemType}.description`, replacements);\n if (detail === unknown) {\n detail = t(`QA.keepRight.errorTypes.${parentIssueType}.description`, replacements);\n }\n return detail;\n }\n\n\n function keepRightDetails(selection) {\n const details = selection.selectAll('.error-details')\n .data(\n (_qaItem ? [_qaItem] : []),\n d => `${d.id}-${d.status || 0}`\n );\n\n details.exit()\n .remove();\n\n const detailsEnter = details.enter()\n .append('div')\n .attr('class', 'error-details qa-details-container');\n\n // description\n const descriptionEnter = detailsEnter\n .append('div')\n .attr('class', 'qa-details-subsection');\n\n descriptionEnter\n .append('h4')\n .text(() => t('QA.keepRight.detail_description'));\n\n descriptionEnter\n .append('div')\n .attr('class', 'qa-details-description-text')\n .html(issueDetail);\n\n // If there are entity links in the error message..\n let relatedEntities = [];\n descriptionEnter.selectAll('.error_entity_link, .error_object_link')\n .each(function() {\n const link = d3_select(this);\n const isObjectLink = link.classed('error_object_link');\n const entityID = isObjectLink ?\n (utilEntityRoot(_qaItem.objectType) + _qaItem.objectId)\n : this.textContent;\n const entity = context.hasEntity(entityID);\n\n relatedEntities.push(entityID);\n\n // Add click handler\n link\n .on('mouseenter', () => {\n utilHighlightEntities([entityID], true, context);\n })\n .on('mouseleave', () => {\n utilHighlightEntities([entityID], false, context);\n })\n .on('click', () => {\n d3_event.preventDefault();\n\n utilHighlightEntities([entityID], false, context);\n\n const osmlayer = context.layers().layer('osm');\n if (!osmlayer.enabled()) {\n osmlayer.enabled(true);\n }\n\n context.map().centerZoomEase(_qaItem.loc, 20);\n\n if (entity) {\n context.enter(modeSelect(context, [entityID]));\n } else {\n context.loadEntity(entityID, () => {\n context.enter(modeSelect(context, [entityID]));\n });\n }\n });\n\n // Replace with friendly name if possible\n // (The entity may not yet be loaded into the graph)\n if (entity) {\n let name = utilDisplayName(entity); // try to use common name\n\n if (!name && !isObjectLink) {\n const preset = presetManager.match(entity, context.graph());\n name = preset && !preset.isFallback() && preset.name(); // fallback to preset name\n }\n\n if (name) {\n this.innerText = name;\n }\n }\n });\n\n // Don't hide entities related to this issue - #5880\n context.features().forceVisible(relatedEntities);\n context.map().pan([0,0]); // trigger a redraw\n }\n\n keepRightDetails.issue = function(val) {\n if (!arguments.length) return _qaItem;\n _qaItem = val;\n return keepRightDetails;\n };\n\n return keepRightDetails;\n}\n","import { svgIcon } from '../svg/icon';\nimport { t } from '../core/localizer';\n\n\nexport function uiKeepRightHeader() {\n let _qaItem;\n\n\n function issueTitle(d) {\n const { itemType, parentIssueType } = d;\n const unknown = t('inspector.unknown');\n let replacements = d.replacements || {};\n replacements.default = unknown; // special key `default` works as a fallback string\n\n let title = t(`QA.keepRight.errorTypes.${itemType}.title`, replacements);\n if (title === unknown) {\n title = t(`QA.keepRight.errorTypes.${parentIssueType}.title`, replacements);\n }\n return title;\n }\n\n\n function keepRightHeader(selection) {\n const header = selection.selectAll('.qa-header')\n .data(\n (_qaItem ? [_qaItem] : []),\n d => `${d.id}-${d.status || 0}`\n );\n\n header.exit()\n .remove();\n\n const headerEnter = header.enter()\n .append('div')\n .attr('class', 'qa-header');\n\n const iconEnter = headerEnter\n .append('div')\n .attr('class', 'qa-header-icon')\n .classed('new', d => d.id < 0);\n\n iconEnter\n .append('div')\n .attr('class', d => `preset-icon-28 qaItem ${d.service} itemId-${d.id} itemType-${d.parentIssueType}`)\n .call(svgIcon('#iD-icon-bolt', 'qaItem-fill'));\n\n headerEnter\n .append('div')\n .attr('class', 'qa-header-label')\n .text(issueTitle);\n }\n\n\n keepRightHeader.issue = function(val) {\n if (!arguments.length) return _qaItem;\n _qaItem = val;\n return keepRightHeader;\n };\n\n return keepRightHeader;\n}\n","import { t } from '../core/localizer';\nimport { services } from '../services';\nimport { svgIcon } from '../svg/icon';\nimport { QAItem } from '../osm';\n\nexport function uiViewOnKeepRight() {\n let _qaItem;\n\n function viewOnKeepRight(selection) {\n let url;\n if (services.keepRight && (_qaItem instanceof QAItem)) {\n url = services.keepRight.issueURL(_qaItem);\n }\n\n const link = selection.selectAll('.view-on-keepRight')\n .data(url ? [url] : []);\n\n // exit\n link.exit()\n .remove();\n\n // enter\n const linkEnter = link.enter()\n .append('a')\n .attr('class', 'view-on-keepRight')\n .attr('target', '_blank')\n .attr('rel', 'noopener') // security measure\n .attr('href', d => d)\n .call(svgIcon('#iD-icon-out-link', 'inline'));\n\n linkEnter\n .append('span')\n .text(t('inspector.view_on_keepRight'));\n }\n\n viewOnKeepRight.what = function(val) {\n if (!arguments.length) return _qaItem;\n _qaItem = val;\n return viewOnKeepRight;\n };\n\n return viewOnKeepRight;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { select as d3_select } from 'd3-selection';\n\nimport { t } from '../core/localizer';\nimport { services } from '../services';\nimport { modeBrowse } from '../modes/browse';\nimport { svgIcon } from '../svg/icon';\n\nimport { uiKeepRightDetails } from './keepRight_details';\nimport { uiKeepRightHeader } from './keepRight_header';\nimport { uiViewOnKeepRight } from './view_on_keepRight';\n\nimport { utilNoAuto, utilRebind } from '../util';\n\nexport function uiKeepRightEditor(context) {\n const dispatch = d3_dispatch('change');\n const qaDetails = uiKeepRightDetails(context);\n const qaHeader = uiKeepRightHeader(context);\n\n let _qaItem;\n\n function keepRightEditor(selection) {\n\n const headerEnter = selection.selectAll('.header')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'header fillL');\n\n headerEnter\n .append('button')\n .attr('class', 'close')\n .on('click', () => context.enter(modeBrowse(context)))\n .call(svgIcon('#iD-icon-close'));\n\n headerEnter\n .append('h3')\n .text(t('QA.keepRight.title'));\n\n\n let body = selection.selectAll('.body')\n .data([0]);\n\n body = body.enter()\n .append('div')\n .attr('class', 'body')\n .merge(body);\n\n const editor = body.selectAll('.qa-editor')\n .data([0]);\n\n editor.enter()\n .append('div')\n .attr('class', 'modal-section qa-editor')\n .merge(editor)\n .call(qaHeader.issue(_qaItem))\n .call(qaDetails.issue(_qaItem))\n .call(keepRightSaveSection);\n\n\n const footer = selection.selectAll('.footer')\n .data([0]);\n\n footer.enter()\n .append('div')\n .attr('class', 'footer')\n .merge(footer)\n .call(uiViewOnKeepRight(context).what(_qaItem));\n }\n\n\n function keepRightSaveSection(selection) {\n const isSelected = (_qaItem && _qaItem.id === context.selectedErrorID());\n const isShown = (_qaItem && (isSelected || _qaItem.newComment || _qaItem.comment));\n let saveSection = selection.selectAll('.qa-save')\n .data(\n (isShown ? [_qaItem] : []),\n d => `${d.id}-${d.status || 0}`\n );\n\n // exit\n saveSection.exit()\n .remove();\n\n // enter\n const saveSectionEnter = saveSection.enter()\n .append('div')\n .attr('class', 'qa-save save-section cf');\n\n saveSectionEnter\n .append('h4')\n .attr('class', '.qa-save-header')\n .text(t('QA.keepRight.comment'));\n\n saveSectionEnter\n .append('textarea')\n .attr('class', 'new-comment-input')\n .attr('placeholder', t('QA.keepRight.comment_placeholder'))\n .attr('maxlength', 1000)\n .property('value', d => d.newComment || d.comment)\n .call(utilNoAuto)\n .on('input', changeInput)\n .on('blur', changeInput);\n\n // update\n saveSection = saveSectionEnter\n .merge(saveSection)\n .call(qaSaveButtons);\n\n function changeInput() {\n const input = d3_select(this);\n let val = input.property('value').trim();\n\n if (val === _qaItem.comment) {\n val = undefined;\n }\n\n // store the unsaved comment with the issue itself\n _qaItem = _qaItem.update({ newComment: val });\n\n const qaService = services.keepRight;\n if (qaService) {\n qaService.replaceItem(_qaItem); // update keepright cache\n }\n\n saveSection\n .call(qaSaveButtons);\n }\n }\n\n\n function qaSaveButtons(selection) {\n const isSelected = (_qaItem && _qaItem.id === context.selectedErrorID());\n let buttonSection = selection.selectAll('.buttons')\n .data((isSelected ? [_qaItem] : []), d => d.status + d.id);\n\n // exit\n buttonSection.exit()\n .remove();\n\n // enter\n const buttonEnter = buttonSection.enter()\n .append('div')\n .attr('class', 'buttons');\n\n buttonEnter\n .append('button')\n .attr('class', 'button comment-button action')\n .text(t('QA.keepRight.save_comment'));\n\n buttonEnter\n .append('button')\n .attr('class', 'button close-button action');\n\n buttonEnter\n .append('button')\n .attr('class', 'button ignore-button action');\n\n // update\n buttonSection = buttonSection\n .merge(buttonEnter);\n\n buttonSection.select('.comment-button') // select and propagate data\n .attr('disabled', d => d.newComment ? null : true)\n .on('click.comment', function(d) {\n this.blur(); // avoid keeping focus on the button - #4641\n const qaService = services.keepRight;\n if (qaService) {\n qaService.postUpdate(d, (err, item) => dispatch.call('change', item));\n }\n });\n\n buttonSection.select('.close-button') // select and propagate data\n .text(d => {\n const andComment = (d.newComment ? '_comment' : '');\n return t(`QA.keepRight.close${andComment}`);\n })\n .on('click.close', function(d) {\n this.blur(); // avoid keeping focus on the button - #4641\n const qaService = services.keepRight;\n if (qaService) {\n d.newStatus = 'ignore_t'; // ignore temporarily (item fixed)\n qaService.postUpdate(d, (err, item) => dispatch.call('change', item));\n }\n });\n\n buttonSection.select('.ignore-button') // select and propagate data\n .text(d => {\n const andComment = (d.newComment ? '_comment' : '');\n return t(`QA.keepRight.ignore${andComment}`);\n })\n .on('click.ignore', function(d) {\n this.blur(); // avoid keeping focus on the button - #4641\n const qaService = services.keepRight;\n if (qaService) {\n d.newStatus = 'ignore'; // ignore permanently (false positive)\n qaService.postUpdate(d, (err, item) => dispatch.call('change', item));\n }\n });\n }\n\n // NOTE: Don't change method name until UI v3 is merged\n keepRightEditor.error = function(val) {\n if (!arguments.length) return _qaItem;\n _qaItem = val;\n return keepRightEditor;\n };\n\n return utilRebind(keepRightEditor, dispatch, 'on');\n}\n","import {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { presetManager } from '../presets';\nimport { modeSelect } from '../modes/select';\nimport { t } from '../core/localizer';\nimport { services } from '../services';\nimport { utilDisplayName, utilHighlightEntities } from '../util';\n\n\nexport function uiOsmoseDetails(context) {\n let _qaItem;\n\n function issueString(d, type) {\n if (!d) return '';\n\n // Issue strings are cached from Osmose API\n const s = services.osmose.getStrings(d.itemType);\n return (type in s) ? s[type] : '';\n }\n\n\n function osmoseDetails(selection) {\n const details = selection.selectAll('.error-details')\n .data(\n _qaItem ? [_qaItem] : [],\n d => `${d.id}-${d.status || 0}`\n );\n\n details.exit()\n .remove();\n\n const detailsEnter = details.enter()\n .append('div')\n .attr('class', 'error-details qa-details-container');\n\n\n // Description\n if (issueString(_qaItem, 'detail')) {\n const div = detailsEnter\n .append('div')\n .attr('class', 'qa-details-subsection');\n\n div\n .append('h4')\n .text(() => t('QA.keepRight.detail_description'));\n\n div\n .append('p')\n .attr('class', 'qa-details-description-text')\n .html(d => issueString(d, 'detail'))\n .selectAll('a')\n .attr('rel', 'noopener')\n .attr('target', '_blank');\n }\n\n // Elements (populated later as data is requested)\n const detailsDiv = detailsEnter\n .append('div')\n .attr('class', 'qa-details-subsection');\n\n const elemsDiv = detailsEnter\n .append('div')\n .attr('class', 'qa-details-subsection');\n\n // Suggested Fix (musn't exist for every issue type)\n if (issueString(_qaItem, 'fix')) {\n const div = detailsEnter\n .append('div')\n .attr('class', 'qa-details-subsection');\n\n div\n .append('h4')\n .text(() => t('QA.osmose.fix_title'));\n\n div\n .append('p')\n .html(d => issueString(d, 'fix'))\n .selectAll('a')\n .attr('rel', 'noopener')\n .attr('target', '_blank');\n }\n\n // Common Pitfalls (musn't exist for every issue type)\n if (issueString(_qaItem, 'trap')) {\n const div = detailsEnter\n .append('div')\n .attr('class', 'qa-details-subsection');\n\n div\n .append('h4')\n .text(() => t('QA.osmose.trap_title'));\n\n div\n .append('p')\n .html(d => issueString(d, 'trap'))\n .selectAll('a')\n .attr('rel', 'noopener')\n .attr('target', '_blank');\n }\n\n // Save current item to check if UI changed by time request resolves\n const thisItem = _qaItem;\n services.osmose.loadIssueDetail(_qaItem)\n .then(d => {\n // No details to add if there are no associated issue elements\n if (!d.elems || d.elems.length === 0) return;\n\n // Do nothing if UI has moved on by the time this resolves\n if (\n context.selectedErrorID() !== thisItem.id\n && context.container().selectAll(`.qaItem.osmose.hover.itemId-${thisItem.id}`).empty()\n ) return;\n\n // Things like keys and values are dynamically added to a subtitle string\n if (d.detail) {\n detailsDiv\n .append('h4')\n .text(() => t('QA.osmose.detail_title'));\n\n detailsDiv\n .append('p')\n .html(d => d.detail)\n .selectAll('a')\n .attr('rel', 'noopener')\n .attr('target', '_blank');\n }\n\n // Create list of linked issue elements\n elemsDiv\n .append('h4')\n .text(() => t('QA.osmose.elems_title'));\n\n elemsDiv\n .append('ul').selectAll('li')\n .data(d.elems)\n .enter()\n .append('li')\n .append('a')\n .attr('class', 'error_entity_link')\n .text(d => d)\n .each(function() {\n const link = d3_select(this);\n const entityID = this.textContent;\n const entity = context.hasEntity(entityID);\n\n // Add click handler\n link\n .on('mouseenter', () => {\n utilHighlightEntities([entityID], true, context);\n })\n .on('mouseleave', () => {\n utilHighlightEntities([entityID], false, context);\n })\n .on('click', () => {\n d3_event.preventDefault();\n\n utilHighlightEntities([entityID], false, context);\n\n const osmlayer = context.layers().layer('osm');\n if (!osmlayer.enabled()) {\n osmlayer.enabled(true);\n }\n\n context.map().centerZoom(d.loc, 20);\n\n if (entity) {\n context.enter(modeSelect(context, [entityID]));\n } else {\n context.loadEntity(entityID, () => {\n context.enter(modeSelect(context, [entityID]));\n });\n }\n });\n\n // Replace with friendly name if possible\n // (The entity may not yet be loaded into the graph)\n if (entity) {\n let name = utilDisplayName(entity); // try to use common name\n\n if (!name) {\n const preset = presetManager.match(entity, context.graph());\n name = preset && !preset.isFallback() && preset.name(); // fallback to preset name\n }\n\n if (name) {\n this.innerText = name;\n }\n }\n });\n\n // Don't hide entities related to this issue - #5880\n context.features().forceVisible(d.elems);\n context.map().pan([0,0]); // trigger a redraw\n })\n .catch(err => {\n console.log(err); // eslint-disable-line no-console\n });\n }\n\n\n osmoseDetails.issue = function(val) {\n if (!arguments.length) return _qaItem;\n _qaItem = val;\n return osmoseDetails;\n };\n\n\n return osmoseDetails;\n}\n","import { services } from '../services';\nimport { t } from '../core/localizer';\n\n\nexport function uiOsmoseHeader() {\n let _qaItem;\n\n function issueTitle(d) {\n const unknown = t('inspector.unknown');\n\n if (!d) return unknown;\n\n // Issue titles supplied by Osmose\n const s = services.osmose.getStrings(d.itemType);\n return ('title' in s) ? s.title : unknown;\n }\n\n function osmoseHeader(selection) {\n const header = selection.selectAll('.qa-header')\n .data(\n (_qaItem ? [_qaItem] : []),\n d => `${d.id}-${d.status || 0}`\n );\n\n header.exit()\n .remove();\n\n const headerEnter = header.enter()\n .append('div')\n .attr('class', 'qa-header');\n\n const svgEnter = headerEnter\n .append('div')\n .attr('class', 'qa-header-icon')\n .classed('new', d => d.id < 0)\n .append('svg')\n .attr('width', '20px')\n .attr('height', '30px')\n .attr('viewbox', '0 0 20 30')\n .attr('class', d => `preset-icon-28 qaItem ${d.service} itemId-${d.id} itemType-${d.itemType}`);\n\n svgEnter\n .append('polygon')\n .attr('fill', d => services.osmose.getColor(d.item))\n .attr('class', 'qaItem-fill')\n .attr('points', '16,3 4,3 1,6 1,17 4,20 7,20 10,27 13,20 16,20 19,17.033 19,6');\n\n svgEnter\n .append('use')\n .attr('class', 'icon-annotation')\n .attr('width', '13px')\n .attr('height', '13px')\n .attr('transform', 'translate(3.5, 5)')\n .attr('xlink:href', d => {\n const picon = d.icon;\n\n if (!picon) {\n return '';\n } else {\n const isMaki = /^maki-/.test(picon);\n return `#${picon}${isMaki ? '-11' : ''}`;\n }\n });\n\n headerEnter\n .append('div')\n .attr('class', 'qa-header-label')\n .text(issueTitle);\n }\n\n osmoseHeader.issue = function(val) {\n if (!arguments.length) return _qaItem;\n _qaItem = val;\n return osmoseHeader;\n };\n\n return osmoseHeader;\n}\n","import { t } from '../core/localizer';\nimport { services } from '../services';\nimport { svgIcon } from '../svg/icon';\nimport { QAItem } from '../osm';\n\nexport function uiViewOnOsmose() {\n let _qaItem;\n\n function viewOnOsmose(selection) {\n let url;\n if (services.osmose && (_qaItem instanceof QAItem)) {\n url = services.osmose.itemURL(_qaItem);\n }\n\n const link = selection.selectAll('.view-on-osmose')\n .data(url ? [url] : []);\n\n // exit\n link.exit()\n .remove();\n\n // enter\n const linkEnter = link.enter()\n .append('a')\n .attr('class', 'view-on-osmose')\n .attr('target', '_blank')\n .attr('rel', 'noopener') // security measure\n .attr('href', d => d)\n .call(svgIcon('#iD-icon-out-link', 'inline'));\n\n linkEnter\n .append('span')\n .text(t('inspector.view_on_osmose'));\n }\n\n viewOnOsmose.what = function(val) {\n if (!arguments.length) return _qaItem;\n _qaItem = val;\n return viewOnOsmose;\n };\n\n return viewOnOsmose;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\n\nimport { t } from '../core/localizer';\nimport { services } from '../services';\nimport { modeBrowse } from '../modes/browse';\nimport { svgIcon } from '../svg/icon';\n\nimport { uiOsmoseDetails } from './osmose_details';\nimport { uiOsmoseHeader } from './osmose_header';\nimport { uiViewOnOsmose } from './view_on_osmose';\n\nimport { utilRebind } from '../util';\n\nexport function uiOsmoseEditor(context) {\n const dispatch = d3_dispatch('change');\n const qaDetails = uiOsmoseDetails(context);\n const qaHeader = uiOsmoseHeader(context);\n\n let _qaItem;\n\n function osmoseEditor(selection) {\n\n const header = selection.selectAll('.header')\n .data([0]);\n\n const headerEnter = header.enter()\n .append('div')\n .attr('class', 'header fillL');\n\n headerEnter\n .append('button')\n .attr('class', 'close')\n .on('click', () => context.enter(modeBrowse(context)))\n .call(svgIcon('#iD-icon-close'));\n\n headerEnter\n .append('h3')\n .text(t('QA.osmose.title'));\n\n let body = selection.selectAll('.body')\n .data([0]);\n\n body = body.enter()\n .append('div')\n .attr('class', 'body')\n .merge(body);\n\n let editor = body.selectAll('.qa-editor')\n .data([0]);\n\n editor.enter()\n .append('div')\n .attr('class', 'modal-section qa-editor')\n .merge(editor)\n .call(qaHeader.issue(_qaItem))\n .call(qaDetails.issue(_qaItem))\n .call(osmoseSaveSection);\n\n const footer = selection.selectAll('.footer')\n .data([0]);\n\n footer.enter()\n .append('div')\n .attr('class', 'footer')\n .merge(footer)\n .call(uiViewOnOsmose(context).what(_qaItem));\n }\n\n function osmoseSaveSection(selection) {\n const isSelected = (_qaItem && _qaItem.id === context.selectedErrorID());\n const isShown = (_qaItem && isSelected);\n let saveSection = selection.selectAll('.qa-save')\n .data(\n (isShown ? [_qaItem] : []),\n d => `${d.id}-${d.status || 0}`\n );\n\n // exit\n saveSection.exit()\n .remove();\n\n // enter\n const saveSectionEnter = saveSection.enter()\n .append('div')\n .attr('class', 'qa-save save-section cf');\n\n // update\n saveSection = saveSectionEnter\n .merge(saveSection)\n .call(qaSaveButtons);\n }\n\n function qaSaveButtons(selection) {\n const isSelected = (_qaItem && _qaItem.id === context.selectedErrorID());\n let buttonSection = selection.selectAll('.buttons')\n .data((isSelected ? [_qaItem] : []), d => d.status + d.id);\n\n // exit\n buttonSection.exit()\n .remove();\n\n // enter\n const buttonEnter = buttonSection.enter()\n .append('div')\n .attr('class', 'buttons');\n\n buttonEnter\n .append('button')\n .attr('class', 'button close-button action');\n\n buttonEnter\n .append('button')\n .attr('class', 'button ignore-button action');\n\n // update\n buttonSection = buttonSection\n .merge(buttonEnter);\n\n buttonSection.select('.close-button')\n .text(() => t('QA.keepRight.close'))\n .on('click.close', function(d) {\n this.blur(); // avoid keeping focus on the button - #4641\n const qaService = services.osmose;\n if (qaService) {\n d.newStatus = 'done';\n qaService.postUpdate(d, (err, item) => dispatch.call('change', item));\n }\n });\n\n buttonSection.select('.ignore-button')\n .text(() => t('QA.keepRight.ignore'))\n .on('click.ignore', function(d) {\n this.blur(); // avoid keeping focus on the button - #4641\n const qaService = services.osmose;\n if (qaService) {\n d.newStatus = 'false';\n qaService.postUpdate(d, (err, item) => dispatch.call('change', item));\n }\n });\n }\n\n // NOTE: Don't change method name until UI v3 is merged\n osmoseEditor.error = function(val) {\n if (!arguments.length) return _qaItem;\n _qaItem = val;\n return osmoseEditor;\n };\n\n return utilRebind(osmoseEditor, dispatch, 'on');\n}\n","import {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { behaviorBreathe } from '../behavior/breathe';\nimport { behaviorHover } from '../behavior/hover';\nimport { behaviorLasso } from '../behavior/lasso';\nimport { behaviorSelect } from '../behavior/select';\n\nimport { t } from '../core/localizer';\nimport { services } from '../services';\nimport { modeBrowse } from './browse';\nimport { modeDragNode } from './drag_node';\nimport { modeDragNote } from './drag_note';\nimport { uiImproveOsmEditor } from '../ui/improveOSM_editor';\nimport { uiKeepRightEditor } from '../ui/keepRight_editor';\nimport { uiOsmoseEditor } from '../ui/osmose_editor';\nimport { utilKeybinding } from '../util';\n\n// NOTE: Don't change name of this until UI v3 is merged\nexport function modeSelectError(context, selectedErrorID, selectedErrorService) {\n var mode = {\n id: 'select-error',\n button: 'browse'\n };\n\n var keybinding = utilKeybinding('select-error');\n\n var errorService = services[selectedErrorService];\n var errorEditor;\n switch (selectedErrorService) {\n case 'improveOSM':\n errorEditor = uiImproveOsmEditor(context)\n .on('change', function() {\n context.map().pan([0,0]); // trigger a redraw\n var error = checkSelectedID();\n if (!error) return;\n context.ui().sidebar\n .show(errorEditor.error(error));\n });\n break;\n case 'keepRight':\n errorEditor = uiKeepRightEditor(context)\n .on('change', function() {\n context.map().pan([0,0]); // trigger a redraw\n var error = checkSelectedID();\n if (!error) return;\n context.ui().sidebar\n .show(errorEditor.error(error));\n });\n break;\n case 'osmose':\n errorEditor = uiOsmoseEditor(context)\n .on('change', function() {\n context.map().pan([0,0]); // trigger a redraw\n var error = checkSelectedID();\n if (!error) return;\n context.ui().sidebar\n .show(errorEditor.error(error));\n });\n break;\n }\n\n\n var behaviors = [\n behaviorBreathe(context),\n behaviorHover(context),\n behaviorSelect(context),\n behaviorLasso(context),\n modeDragNode(context).behavior,\n modeDragNote(context).behavior\n ];\n\n\n function checkSelectedID() {\n if (!errorService) return;\n var error = errorService.getError(selectedErrorID);\n if (!error) {\n context.enter(modeBrowse(context));\n }\n return error;\n }\n\n\n mode.zoomToSelected = function() {\n if (!errorService) return;\n var error = errorService.getError(selectedErrorID);\n if (error) {\n context.map().centerZoomEase(error.loc, 20);\n }\n };\n\n\n mode.enter = function() {\n var error = checkSelectedID();\n if (!error) return;\n\n behaviors.forEach(context.install);\n keybinding\n .on(t('inspector.zoom_to.key'), mode.zoomToSelected)\n .on('⎋', esc, true);\n\n d3_select(document)\n .call(keybinding);\n\n selectError();\n\n var sidebar = context.ui().sidebar;\n sidebar.show(errorEditor.error(error));\n\n context.map()\n .on('drawn.select-error', selectError);\n\n\n // class the error as selected, or return to browse mode if the error is gone\n function selectError(drawn) {\n if (!checkSelectedID()) return;\n\n var selection = context.surface()\n .selectAll('.itemId-' + selectedErrorID + '.' + selectedErrorService);\n\n if (selection.empty()) {\n // Return to browse mode if selected DOM elements have\n // disappeared because the user moved them out of view..\n var source = d3_event && d3_event.type === 'zoom' && d3_event.sourceEvent;\n if (drawn && source && (source.type === 'pointermove' || source.type === 'mousemove' || source.type === 'touchmove')) {\n context.enter(modeBrowse(context));\n }\n\n } else {\n selection\n .classed('selected', true);\n\n context.selectedErrorID(selectedErrorID);\n }\n }\n\n function esc() {\n if (context.container().select('.combobox').size()) return;\n context.enter(modeBrowse(context));\n }\n };\n\n\n mode.exit = function() {\n behaviors.forEach(context.uninstall);\n\n d3_select(document)\n .call(keybinding.unbind);\n\n context.surface()\n .selectAll('.qaItem.selected')\n .classed('selected hover', false);\n\n context.map()\n .on('drawn.select-error', null);\n\n context.ui().sidebar\n .hide();\n\n context.selectedErrorID(null);\n context.features().forceVisible([]);\n };\n\n\n return mode;\n}\n","import { event as d3_event } from 'd3-selection';\n\nimport { t } from '../core/localizer';\nimport { svgIcon } from '../svg/icon';\n\n\nexport function uiAccount(context) {\n var osm = context.connection();\n\n\n function update(selection) {\n if (!osm) return;\n\n if (!osm.authenticated()) {\n selection.selectAll('.userLink, .logoutLink')\n .classed('hide', true);\n return;\n }\n\n osm.userDetails(function(err, details) {\n var userLink = selection.select('.userLink'),\n logoutLink = selection.select('.logoutLink');\n\n userLink.html('');\n logoutLink.html('');\n\n if (err || !details) return;\n\n selection.selectAll('.userLink, .logoutLink')\n .classed('hide', false);\n\n // Link\n userLink.append('a')\n .attr('href', osm.userURL(details.display_name))\n .attr('target', '_blank');\n\n // Add thumbnail or dont\n if (details.image_url) {\n userLink.append('img')\n .attr('class', 'icon pre-text user-icon')\n .attr('src', details.image_url);\n } else {\n userLink\n .call(svgIcon('#iD-icon-avatar', 'pre-text light'));\n }\n\n // Add user name\n userLink.append('span')\n .attr('class', 'label')\n .text(details.display_name);\n\n logoutLink.append('a')\n .attr('class', 'logout')\n .attr('href', '#')\n .text(t('logout'))\n .on('click.logout', function() {\n d3_event.preventDefault();\n osm.logout();\n });\n });\n }\n\n\n return function(selection) {\n selection.append('li')\n .attr('class', 'logoutLink')\n .classed('hide', true);\n\n selection.append('li')\n .attr('class', 'userLink')\n .classed('hide', true);\n\n if (osm) {\n osm.on('change.account', function() { update(selection); });\n update(selection);\n }\n };\n}\n","import _throttle from 'lodash-es/throttle';\nimport { select as d3_select } from 'd3-selection';\nimport { t } from '../core/localizer';\n\n\nexport function uiAttribution(context) {\n let _selection = d3_select(null);\n\n\n function render(selection, data, klass) {\n let div = selection.selectAll(`.${klass}`)\n .data([0]);\n\n div = div.enter()\n .append('div')\n .attr('class', klass)\n .merge(div);\n\n\n let attributions = div.selectAll('.attribution')\n .data(data, d => d.id);\n\n attributions.exit()\n .remove();\n\n attributions = attributions.enter()\n .append('span')\n .attr('class', 'attribution')\n .each((d, i, nodes) => {\n let attribution = d3_select(nodes[i]);\n\n if (d.terms_html) {\n attribution.html(d.terms_html);\n return;\n }\n\n if (d.terms_url) {\n attribution = attribution\n .append('a')\n .attr('href', d.terms_url)\n .attr('target', '_blank');\n }\n\n const sourceID = d.id.replace(/\\./g, '');\n const terms_text = t(`imagery.${sourceID}.attribution.text`,\n { default: d.terms_text || d.id || d.name() }\n );\n\n if (d.icon && !d.overlay) {\n attribution\n .append('img')\n .attr('class', 'source-image')\n .attr('src', d.icon);\n }\n\n attribution\n .append('span')\n .attr('class', 'attribution-text')\n .text(terms_text);\n })\n .merge(attributions);\n\n\n let copyright = attributions.selectAll('.copyright-notice')\n .data(d => {\n let notice = d.copyrightNotices(context.map().zoom(), context.map().extent());\n return notice ? [notice] : [];\n });\n\n copyright.exit()\n .remove();\n\n copyright = copyright.enter()\n .append('span')\n .attr('class', 'copyright-notice')\n .merge(copyright);\n\n copyright\n .text(String);\n }\n\n\n function update() {\n let baselayer = context.background().baseLayerSource();\n _selection\n .call(render, (baselayer ? [baselayer] : []), 'base-layer-attribution');\n\n const z = context.map().zoom();\n let overlays = context.background().overlayLayerSources() || [];\n _selection\n .call(render, overlays.filter(s => s.validZoom(z)), 'overlay-layer-attribution');\n }\n\n\n return function(selection) {\n _selection = selection;\n\n context.background()\n .on('change.attribution', update);\n\n context.map()\n .on('move.attribution', _throttle(update, 400, { leading: false }));\n\n update();\n };\n}\n","import _debounce from 'lodash-es/debounce';\n\nimport { select as d3_select } from 'd3-selection';\n\nimport { t } from '../core/localizer';\nimport { svgIcon } from '../svg/index';\n\n\nexport function uiContributors(context) {\n var osm = context.connection(),\n debouncedUpdate = _debounce(function() { update(); }, 1000),\n limit = 4,\n hidden = false,\n wrap = d3_select(null);\n\n\n function update() {\n if (!osm) return;\n\n var users = {},\n entities = context.history().intersects(context.map().extent());\n\n entities.forEach(function(entity) {\n if (entity && entity.user) users[entity.user] = true;\n });\n\n var u = Object.keys(users),\n subset = u.slice(0, u.length > limit ? limit - 1 : limit);\n\n wrap.html('')\n .call(svgIcon('#iD-icon-nearby', 'pre-text light'));\n\n var userList = d3_select(document.createElement('span'));\n\n userList.selectAll()\n .data(subset)\n .enter()\n .append('a')\n .attr('class', 'user-link')\n .attr('href', function(d) { return osm.userURL(d); })\n .attr('target', '_blank')\n .text(String);\n\n if (u.length > limit) {\n var count = d3_select(document.createElement('span'));\n\n count.append('a')\n .attr('target', '_blank')\n .attr('href', function() {\n return osm.changesetsURL(context.map().center(), context.map().zoom());\n })\n .text(u.length - limit + 1);\n\n wrap.append('span')\n .html(t('contributors.truncated_list', { users: userList.html(), count: count.html() }));\n\n } else {\n wrap.append('span')\n .html(t('contributors.list', { users: userList.html() }));\n }\n\n if (!u.length) {\n hidden = true;\n wrap\n .transition()\n .style('opacity', 0);\n\n } else if (hidden) {\n wrap\n .transition()\n .style('opacity', 1);\n }\n }\n\n\n return function(selection) {\n if (!osm) return;\n wrap = selection;\n update();\n\n osm.on('loaded.contributors', debouncedUpdate);\n context.map().on('move.contributors', debouncedUpdate);\n };\n}\n","import { event as d3_event, select as d3_select } from 'd3-selection';\nimport { dispatch as d3_dispatch } from 'd3-dispatch';\n\nimport { geoVecAdd } from '../geo';\nimport { localizer } from '../core/localizer';\nimport { uiTooltip } from './tooltip';\nimport { utilRebind } from '../util/rebind';\nimport { svgIcon } from '../svg/icon';\n\n\nexport function uiEditMenu(context) {\n var dispatch = d3_dispatch('toggled');\n\n var _menu = d3_select(null);\n var _operations = [];\n // the position the menu should be displayed relative to\n var _anchorLoc = [0, 0];\n var _anchorLocLonLat = [0, 0];\n // a string indicating how the menu was opened\n var _triggerType = '';\n\n var _vpTopMargin = 85; // viewport top margin\n var _vpBottomMargin = 45; // viewport bottom margin\n var _vpSideMargin = 35; // viewport side margin\n\n var _menuTop = false;\n var _menuHeight;\n var _menuWidth;\n\n // hardcode these values to make menu positioning easier\n var _verticalPadding = 4;\n\n // see also `.edit-menu .tooltip` CSS; include margin\n var _tooltipWidth = 210;\n\n // offset the menu slightly from the target location\n var _menuSideMargin = 10;\n\n var _tooltips = [];\n\n var editMenu = function(selection) {\n\n var isTouchMenu = _triggerType.includes('touch') || _triggerType.includes('pen');\n\n var ops = _operations.filter(function(op) {\n return !isTouchMenu || !op.mouseOnly;\n });\n\n if (!ops.length) return;\n\n _tooltips = [];\n\n // Position the menu above the anchor for stylus and finger input\n // since the mapper's hand likely obscures the screen below the anchor\n _menuTop = isTouchMenu;\n\n // Show labels for touch input since there aren't hover tooltips\n var showLabels = isTouchMenu;\n\n var buttonHeight = showLabels ? 32 : 34;\n if (showLabels) {\n // Get a general idea of the width based on the length of the label\n _menuWidth = 52 + Math.min(120, 6 * Math.max.apply(Math, ops.map(function(op) {\n return op.title.length;\n })));\n } else {\n _menuWidth = 44;\n }\n\n _menuHeight = _verticalPadding * 2 + ops.length * buttonHeight;\n\n _menu = selection\n .append('div')\n .attr('class', 'edit-menu')\n .classed('touch-menu', isTouchMenu)\n .style('padding', _verticalPadding + 'px 0');\n\n var buttons = _menu.selectAll('.edit-menu-item')\n .data(ops);\n\n // enter\n var buttonsEnter = buttons.enter()\n .append('button')\n .attr('class', function (d) { return 'edit-menu-item edit-menu-item-' + d.id; })\n .style('height', buttonHeight + 'px')\n .on('click', click)\n // don't listen for `mouseup` because we only care about non-mouse pointer types\n .on('pointerup', pointerup)\n .on('pointerdown mousedown', function pointerdown() {\n // don't let button presses also act as map input - #1869\n d3_event.stopPropagation();\n });\n\n buttonsEnter.each(function(d) {\n var tooltip = uiTooltip()\n .heading(d.title)\n .title(d.tooltip())\n .keys([d.keys[0]]);\n\n _tooltips.push(tooltip);\n\n d3_select(this)\n .call(tooltip)\n .append('div')\n .attr('class', 'icon-wrap')\n .call(svgIcon('#iD-operation-' + d.id, 'operation'));\n });\n\n if (showLabels) {\n buttonsEnter.append('span')\n .attr('class', 'label')\n .text(function(d) {\n return d.title;\n });\n }\n\n // update\n buttons = buttonsEnter\n .merge(buttons)\n .classed('disabled', function(d) { return d.disabled(); });\n\n updatePosition();\n\n var initialScale = context.projection.scale();\n context.map()\n .on('move.edit-menu', function() {\n if (initialScale !== context.projection.scale()) {\n editMenu.close();\n }\n })\n .on('drawn.edit-menu', function(info) {\n if (info.full) updatePosition();\n });\n\n var lastPointerUpType;\n // `pointerup` is always called before `click`\n function pointerup() {\n lastPointerUpType = d3_event.pointerType;\n }\n\n function click(operation) {\n d3_event.stopPropagation();\n if (operation.disabled()) {\n if (lastPointerUpType === 'touch' ||\n lastPointerUpType === 'pen') {\n // there are no tooltips for touch interactions so flash feedback instead\n context.ui().flash\n .duration(4000)\n .iconName('#iD-operation-' + operation.id)\n .iconClass('operation disabled')\n .text(operation.tooltip)();\n }\n } else {\n if (lastPointerUpType === 'touch' ||\n lastPointerUpType === 'pen') {\n context.ui().flash\n .duration(2000)\n .iconName('#iD-operation-' + operation.id)\n .iconClass('operation')\n .text(operation.annotation() || operation.title)();\n }\n\n operation();\n editMenu.close();\n }\n lastPointerUpType = null;\n }\n\n dispatch.call('toggled', this, true);\n };\n\n function updatePosition() {\n\n if (!_menu || _menu.empty()) return;\n\n var anchorLoc = context.projection(_anchorLocLonLat);\n\n var viewport = context.surfaceRect();\n\n if (anchorLoc[0] < 0 ||\n anchorLoc[0] > viewport.width ||\n anchorLoc[1] < 0 ||\n anchorLoc[1] > viewport.height) {\n // close the menu if it's gone offscreen\n\n editMenu.close();\n return;\n }\n\n var menuLeft = displayOnLeft(viewport);\n\n var offset = [0, 0];\n\n offset[0] = menuLeft ? -1 * (_menuSideMargin + _menuWidth) : _menuSideMargin;\n\n if (_menuTop) {\n if (anchorLoc[1] - _menuHeight < _vpTopMargin) {\n // menu is near top viewport edge, shift downward\n offset[1] = -anchorLoc[1] + _vpTopMargin;\n } else {\n offset[1] = -_menuHeight;\n }\n } else {\n if (anchorLoc[1] + _menuHeight > (viewport.height - _vpBottomMargin)) {\n // menu is near bottom viewport edge, shift upwards\n offset[1] = -anchorLoc[1] - _menuHeight + viewport.height - _vpBottomMargin;\n } else {\n offset[1] = 0;\n }\n }\n\n var origin = geoVecAdd(anchorLoc, offset);\n\n _menu\n .style('left', origin[0] + 'px')\n .style('top', origin[1] + 'px');\n\n var tooltipSide = tooltipPosition(viewport, menuLeft);\n _tooltips.forEach(function(tooltip) {\n tooltip.placement(tooltipSide);\n });\n\n function displayOnLeft(viewport) {\n if (localizer.textDirection() === 'ltr') {\n if ((anchorLoc[0] + _menuSideMargin + _menuWidth) > (viewport.width - _vpSideMargin)) {\n // right menu would be too close to the right viewport edge, go left\n return true;\n }\n // prefer right menu\n return false;\n\n } else { // rtl\n if ((anchorLoc[0] - _menuSideMargin - _menuWidth) < _vpSideMargin) {\n // left menu would be too close to the left viewport edge, go right\n return false;\n }\n // prefer left menu\n return true;\n }\n }\n\n function tooltipPosition(viewport, menuLeft) {\n if (localizer.textDirection() === 'ltr') {\n if (menuLeft) {\n // if there's not room for a right-side menu then there definitely\n // isn't room for right-side tooltips\n return 'left';\n }\n if ((anchorLoc[0] + _menuSideMargin + _menuWidth + _tooltipWidth) > (viewport.width - _vpSideMargin)) {\n // right tooltips would be too close to the right viewport edge, go left\n return 'left';\n }\n // prefer right tooltips\n return 'right';\n\n } else { // rtl\n if (!menuLeft) {\n return 'right';\n }\n if ((anchorLoc[0] - _menuSideMargin - _menuWidth - _tooltipWidth) < _vpSideMargin) {\n // left tooltips would be too close to the left viewport edge, go right\n return 'right';\n }\n // prefer left tooltips\n return 'left';\n }\n }\n }\n\n editMenu.close = function () {\n\n context.map()\n .on('move.edit-menu', null)\n .on('drawn.edit-menu', null);\n\n _menu.remove();\n _tooltips = [];\n\n dispatch.call('toggled', this, false);\n };\n\n editMenu.anchorLoc = function(val) {\n if (!arguments.length) return _anchorLoc;\n _anchorLoc = val;\n _anchorLocLonLat = context.projection.invert(_anchorLoc);\n return editMenu;\n };\n\n editMenu.triggerType = function(val) {\n if (!arguments.length) return _triggerType;\n _triggerType = val;\n return editMenu;\n };\n\n editMenu.operations = function(val) {\n if (!arguments.length) return _operations;\n _operations = val;\n return editMenu;\n };\n\n return utilRebind(editMenu, dispatch, 'on');\n}\n","import { event as d3_event } from 'd3-selection';\n\nimport { t } from '../core/localizer';\nimport { uiTooltip } from './tooltip';\n\n\nexport function uiFeatureInfo(context) {\n function update(selection) {\n var features = context.features();\n var stats = features.stats();\n var count = 0;\n var hiddenList = features.hidden().map(function(k) {\n if (stats[k]) {\n count += stats[k];\n return String(stats[k]) + ' ' + t('feature.' + k + '.description');\n }\n }).filter(Boolean);\n\n selection.html('');\n\n if (hiddenList.length) {\n var tooltipBehavior = uiTooltip()\n .placement('top')\n .title(function() {\n return hiddenList.join(' ');\n });\n\n selection.append('a')\n .attr('class', 'chip')\n .attr('href', '#')\n .attr('tabindex', -1)\n .html(t('feature_info.hidden_warning', { count: count }))\n .call(tooltipBehavior)\n .on('click', function() {\n tooltipBehavior.hide();\n d3_event.preventDefault();\n // open the Map Data pane\n context.ui().togglePanes(context.container().select('.map-panes .map-data-pane'));\n });\n }\n\n selection\n .classed('hide', !hiddenList.length);\n }\n\n\n return function(selection) {\n update(selection);\n\n context.features().on('change.feature_info', function() {\n update(selection);\n });\n };\n}\n","import { timeout as d3_timeout } from 'd3-timer';\n\nexport function uiFlash(context) {\n var _flashTimer;\n\n var _duration = 2000;\n var _iconName = '#iD-icon-no';\n var _iconClass = 'disabled';\n var _text = '';\n var _textClass;\n\n function flash() {\n if (_flashTimer) {\n _flashTimer.stop();\n }\n\n context.container().select('.main-footer-wrap')\n .classed('footer-hide', true)\n .classed('footer-show', false);\n context.container().select('.flash-wrap')\n .classed('footer-hide', false)\n .classed('footer-show', true);\n\n var content = context.container().select('.flash-wrap').selectAll('.flash-content')\n .data([0]);\n\n // Enter\n var contentEnter = content.enter()\n .append('div')\n .attr('class', 'flash-content');\n\n var iconEnter = contentEnter\n .append('svg')\n .attr('class', 'flash-icon icon')\n .append('g')\n .attr('transform', 'translate(10,10)');\n\n iconEnter\n .append('circle')\n .attr('r', 9);\n\n iconEnter\n .append('use')\n .attr('transform', 'translate(-7,-7)')\n .attr('width', '14')\n .attr('height', '14');\n\n contentEnter\n .append('div')\n .attr('class', 'flash-text');\n\n\n // Update\n content = content\n .merge(contentEnter);\n\n content\n .selectAll('.flash-icon')\n .attr('class', 'icon flash-icon ' + (_iconClass || ''));\n\n content\n .selectAll('.flash-icon use')\n .attr('xlink:href', _iconName);\n\n content\n .selectAll('.flash-text')\n .attr('class', 'flash-text ' + (_textClass || ''))\n .text(_text);\n\n\n _flashTimer = d3_timeout(function() {\n _flashTimer = null;\n context.container().select('.main-footer-wrap')\n .classed('footer-hide', false)\n .classed('footer-show', true);\n context.container().select('.flash-wrap')\n .classed('footer-hide', true)\n .classed('footer-show', false);\n }, _duration);\n\n return content;\n }\n\n\n flash.duration = function(_) {\n if (!arguments.length) return _duration;\n _duration = _;\n return flash;\n };\n\n flash.text = function(_) {\n if (!arguments.length) return _text;\n _text = _;\n return flash;\n };\n\n flash.textClass = function(_) {\n if (!arguments.length) return _textClass;\n _textClass = _;\n return flash;\n };\n\n flash.iconName = function(_) {\n if (!arguments.length) return _iconName;\n _iconName = _;\n return flash;\n };\n\n flash.iconClass = function(_) {\n if (!arguments.length) return _iconClass;\n _iconClass = _;\n return flash;\n };\n\n return flash;\n}\n","import { event as d3_event } from 'd3-selection';\n\nimport { uiCmd } from './cmd';\nimport { utilDetect } from '../util/detect';\n\n\nexport function uiFullScreen(context) {\n var element = context.container().node();\n // var button = d3_select(null);\n\n\n function getFullScreenFn() {\n if (element.requestFullscreen) {\n return element.requestFullscreen;\n } else if (element.msRequestFullscreen) {\n return element.msRequestFullscreen;\n } else if (element.mozRequestFullScreen) {\n return element.mozRequestFullScreen;\n } else if (element.webkitRequestFullscreen) {\n return element.webkitRequestFullscreen;\n }\n }\n\n\n function getExitFullScreenFn() {\n if (document.exitFullscreen) {\n return document.exitFullscreen;\n } else if (document.msExitFullscreen) {\n return document.msExitFullscreen;\n } else if (document.mozCancelFullScreen) {\n return document.mozCancelFullScreen;\n } else if (document.webkitExitFullscreen) {\n return document.webkitExitFullscreen;\n }\n }\n\n\n function isFullScreen() {\n return document.fullscreenElement ||\n document.mozFullScreenElement ||\n document.webkitFullscreenElement ||\n document.msFullscreenElement;\n }\n\n\n function isSupported() {\n return !!getFullScreenFn();\n }\n\n\n function fullScreen() {\n d3_event.preventDefault();\n if (!isFullScreen()) {\n // button.classed('active', true);\n getFullScreenFn().apply(element);\n } else {\n // button.classed('active', false);\n getExitFullScreenFn().apply(document);\n }\n }\n\n\n return function() { // selection) {\n if (!isSupported()) return;\n\n // button = selection.append('button')\n // .attr('title', t('full_screen'))\n // .attr('tabindex', -1)\n // .on('click', fullScreen)\n // .call(tooltip);\n\n // button.append('span')\n // .attr('class', 'icon full-screen');\n\n var detected = utilDetect();\n var keys = (detected.os === 'mac' ? [uiCmd('⌃⌘F'), 'f11'] : ['f11']);\n context.keybinding().on(keys, fullScreen);\n };\n}\n","import { select as d3_select } from 'd3-selection';\n\nimport { t, localizer } from '../core/localizer';\nimport { uiTooltip } from './tooltip';\nimport { geoExtent } from '../geo';\nimport { modeBrowse } from '../modes/browse';\nimport { svgIcon } from '../svg/icon';\nimport { uiLoading } from './loading';\n\nexport function uiGeolocate(context) {\n var _geolocationOptions = {\n // prioritize speed and power usage over precision\n enableHighAccuracy: false,\n // don't hang indefinitely getting the location\n timeout: 6000 // 6sec\n };\n var _locating = uiLoading(context).message(t('geolocate.locating')).blocking(true);\n var _layer = context.layers().layer('geolocate');\n var _position;\n var _extent;\n var _timeoutID;\n var _button = d3_select(null);\n\n function click() {\n if (context.inIntro()) return;\n if (!_layer.enabled() && !_locating.isShown()) {\n\n // This timeout ensures that we still call finish() even if\n // the user declines to share their location in Firefox\n _timeoutID = setTimeout(error, 10000 /* 10sec */ );\n\n context.container().call(_locating);\n // get the latest position even if we already have one\n navigator.geolocation.getCurrentPosition(success, error, _geolocationOptions);\n } else {\n _locating.close();\n _layer.enabled(null, false);\n updateButtonState();\n }\n }\n\n function zoomTo() {\n context.enter(modeBrowse(context));\n\n var map = context.map();\n _layer.enabled(_position, true);\n updateButtonState();\n map.centerZoomEase(_extent.center(), Math.min(20, map.extentZoom(_extent)));\n }\n\n function success(geolocation) {\n _position = geolocation;\n var coords = _position.coords;\n _extent = geoExtent([coords.longitude, coords.latitude]).padByMeters(coords.accuracy);\n zoomTo();\n finish();\n }\n\n function error() {\n if (_position) {\n // use the position from a previous call if we have one\n zoomTo();\n } else {\n context.ui().flash\n .text(t('geolocate.location_unavailable'))\n .iconName('#iD-icon-geolocate')();\n }\n\n finish();\n }\n\n function finish() {\n _locating.close(); // unblock ui\n if (_timeoutID) { clearTimeout(_timeoutID); }\n _timeoutID = undefined;\n }\n\n function updateButtonState() {\n _button.classed('active', _layer.enabled());\n }\n\n return function(selection) {\n if (!navigator.geolocation || !navigator.geolocation.getCurrentPosition) return;\n\n _button = selection\n .append('button')\n .on('click', click)\n .call(svgIcon('#iD-icon-geolocate', 'light'))\n .call(uiTooltip()\n .placement((localizer.textDirection() === 'rtl') ? 'right' : 'left')\n .title(t('geolocate.title'))\n .keys([t('geolocate.key')])\n );\n\n context.keybinding().on(t('geolocate.key'), click);\n };\n}\n","import _debounce from 'lodash-es/debounce';\n\nimport {\n event as d3_event\n} from 'd3-selection';\n\nimport { t } from '../../core/localizer';\n\n\nexport function uiPanelBackground(context) {\n var background = context.background();\n var currSourceName = null;\n var metadata = {};\n var metadataKeys = [\n 'zoom', 'vintage', 'source', 'description', 'resolution', 'accuracy'\n ];\n\n var debouncedRedraw = _debounce(redraw, 250);\n\n function redraw(selection) {\n var source = background.baseLayerSource();\n if (!source) return;\n\n var isDG = (source.id.match(/^DigitalGlobe/i) !== null);\n\n if (currSourceName !== source.name()) {\n currSourceName = source.name();\n metadata = {};\n }\n\n selection.html('');\n\n var list = selection\n .append('ul')\n .attr('class', 'background-info');\n\n list\n .append('li')\n .text(currSourceName);\n\n metadataKeys.forEach(function(k) {\n // DigitalGlobe vintage is available in raster layers for now.\n if (isDG && k === 'vintage') return;\n\n list\n .append('li')\n .attr('class', 'background-info-list-' + k)\n .classed('hide', !metadata[k])\n .text(t('info_panels.background.' + k) + ':')\n .append('span')\n .attr('class', 'background-info-span-' + k)\n .text(metadata[k]);\n });\n\n debouncedGetMetadata(selection);\n\n var toggleTiles = context.getDebug('tile') ? 'hide_tiles' : 'show_tiles';\n\n selection\n .append('a')\n .text(t('info_panels.background.' + toggleTiles))\n .attr('href', '#')\n .attr('class', 'button button-toggle-tiles')\n .on('click', function() {\n d3_event.preventDefault();\n context.setDebug('tile', !context.getDebug('tile'));\n selection.call(redraw);\n });\n\n if (isDG) {\n var key = source.id + '-vintage';\n var sourceVintage = context.background().findSource(key);\n var showsVintage = context.background().showsLayer(sourceVintage);\n var toggleVintage = showsVintage ? 'hide_vintage' : 'show_vintage';\n selection\n .append('a')\n .text(t('info_panels.background.' + toggleVintage))\n .attr('href', '#')\n .attr('class', 'button button-toggle-vintage')\n .on('click', function() {\n d3_event.preventDefault();\n context.background().toggleOverlayLayer(sourceVintage);\n selection.call(redraw);\n });\n }\n\n // disable if necessary\n ['DigitalGlobe-Premium', 'DigitalGlobe-Standard'].forEach(function(layerId) {\n if (source.id !== layerId) {\n var key = layerId + '-vintage';\n var sourceVintage = context.background().findSource(key);\n if (context.background().showsLayer(sourceVintage)) {\n context.background().toggleOverlayLayer(sourceVintage);\n }\n }\n });\n }\n\n\n var debouncedGetMetadata = _debounce(getMetadata, 250);\n\n function getMetadata(selection) {\n var tile = context.container().select('.layer-background img.tile-center'); // tile near viewport center\n if (tile.empty()) return;\n\n var sourceName = currSourceName;\n var d = tile.datum();\n var zoom = (d && d.length >= 3 && d[2]) || Math.floor(context.map().zoom());\n var center = context.map().center();\n\n // update zoom\n metadata.zoom = String(zoom);\n selection.selectAll('.background-info-list-zoom')\n .classed('hide', false)\n .selectAll('.background-info-span-zoom')\n .text(metadata.zoom);\n\n if (!d || !d.length >= 3) return;\n\n background.baseLayerSource().getMetadata(center, d, function(err, result) {\n if (err || currSourceName !== sourceName) return;\n\n // update vintage\n var vintage = result.vintage;\n metadata.vintage = (vintage && vintage.range) || t('info_panels.background.unknown');\n selection.selectAll('.background-info-list-vintage')\n .classed('hide', false)\n .selectAll('.background-info-span-vintage')\n .text(metadata.vintage);\n\n // update other metdata\n metadataKeys.forEach(function(k) {\n if (k === 'zoom' || k === 'vintage') return; // done already\n var val = result[k];\n metadata[k] = val;\n selection.selectAll('.background-info-list-' + k)\n .classed('hide', !val)\n .selectAll('.background-info-span-' + k)\n .text(val);\n });\n });\n }\n\n\n var panel = function(selection) {\n selection.call(redraw);\n\n context.map()\n .on('drawn.info-background', function() {\n selection.call(debouncedRedraw);\n })\n .on('move.info-background', function() {\n selection.call(debouncedGetMetadata);\n });\n\n };\n\n panel.off = function() {\n context.map()\n .on('drawn.info-background', null)\n .on('move.info-background', null);\n };\n\n panel.id = 'background';\n panel.title = t('info_panels.background.title');\n panel.key = t('info_panels.background.key');\n\n\n return panel;\n}\n","import { t, localizer } from '../../core/localizer';\nimport { svgIcon } from '../../svg';\n\n\nexport function uiPanelHistory(context) {\n var osm;\n\n function displayTimestamp(timestamp) {\n if (!timestamp) return t('info_panels.history.unknown');\n var options = {\n day: 'numeric', month: 'short', year: 'numeric',\n hour: 'numeric', minute: 'numeric', second: 'numeric'\n };\n var d = new Date(timestamp);\n if (isNaN(d.getTime())) return t('info_panels.history.unknown');\n return d.toLocaleString(localizer.localeCode(), options);\n }\n\n\n function displayUser(selection, userName) {\n if (!userName) {\n selection\n .append('span')\n .text(t('info_panels.history.unknown'));\n return;\n }\n\n selection\n .append('span')\n .attr('class', 'user-name')\n .text(userName);\n\n var links = selection\n .append('div')\n .attr('class', 'links');\n\n if (osm) {\n links\n .append('a')\n .attr('class', 'user-osm-link')\n .attr('href', osm.userURL(userName))\n .attr('target', '_blank')\n .attr('tabindex', -1)\n .text('OSM');\n }\n\n links\n .append('a')\n .attr('class', 'user-hdyc-link')\n .attr('href', 'https://hdyc.neis-one.org/?' + userName)\n .attr('target', '_blank')\n .attr('tabindex', -1)\n .text('HDYC');\n }\n\n\n function displayChangeset(selection, changeset) {\n if (!changeset) {\n selection\n .append('span')\n .text(t('info_panels.history.unknown'));\n return;\n }\n\n selection\n .append('span')\n .attr('class', 'changeset-id')\n .text(changeset);\n\n var links = selection\n .append('div')\n .attr('class', 'links');\n\n if (osm) {\n links\n .append('a')\n .attr('class', 'changeset-osm-link')\n .attr('href', osm.changesetURL(changeset))\n .attr('target', '_blank')\n .attr('tabindex', -1)\n .text('OSM');\n }\n\n links\n .append('a')\n .attr('class', 'changeset-osmcha-link')\n .attr('href', 'https://osmcha.org/changesets/' + changeset)\n .attr('target', '_blank')\n .attr('tabindex', -1)\n .text('OSMCha');\n\n links\n .append('a')\n .attr('class', 'changeset-achavi-link')\n .attr('href', 'https://overpass-api.de/achavi/?changeset=' + changeset)\n .attr('target', '_blank')\n .attr('tabindex', -1)\n .text('Achavi');\n }\n\n\n function redraw(selection) {\n var selectedNoteID = context.selectedNoteID();\n osm = context.connection();\n\n var selected, note, entity;\n if (selectedNoteID && osm) { // selected 1 note\n selected = [ t('note.note') + ' ' + selectedNoteID ];\n note = osm.getNote(selectedNoteID);\n } else { // selected 1..n entities\n selected = context.selectedIDs()\n .filter(function(e) { return context.hasEntity(e); });\n if (selected.length) {\n entity = context.entity(selected[0]);\n }\n }\n\n var singular = selected.length === 1 ? selected[0] : null;\n\n selection.html('');\n\n selection\n .append('h4')\n .attr('class', 'history-heading')\n .text(singular || t('info_panels.history.selected', { n: selected.length }));\n\n if (!singular) return;\n\n if (entity) {\n selection.call(redrawEntity, entity);\n } else if (note) {\n selection.call(redrawNote, note);\n }\n }\n\n\n function redrawNote(selection, note) {\n if (!note || note.isNew()) {\n selection\n .append('div')\n .text(t('info_panels.history.note_no_history'));\n return;\n }\n\n var list = selection\n .append('ul');\n\n list\n .append('li')\n .text(t('info_panels.history.note_comments') + ':')\n .append('span')\n .text(note.comments.length);\n\n if (note.comments.length) {\n list\n .append('li')\n .text(t('info_panels.history.note_created_date') + ':')\n .append('span')\n .text(displayTimestamp(note.comments[0].date));\n\n list\n .append('li')\n .text(t('info_panels.history.note_created_user') + ':')\n .call(displayUser, note.comments[0].user);\n }\n\n if (osm) {\n selection\n .append('a')\n .attr('class', 'view-history-on-osm')\n .attr('target', '_blank')\n .attr('tabindex', -1)\n .attr('href', osm.noteURL(note))\n .call(svgIcon('#iD-icon-out-link', 'inline'))\n .append('span')\n .text(t('info_panels.history.note_link_text'));\n }\n }\n\n\n function redrawEntity(selection, entity) {\n if (!entity || entity.isNew()) {\n selection\n .append('div')\n .text(t('info_panels.history.no_history'));\n return;\n }\n\n var links = selection\n .append('div')\n .attr('class', 'links');\n\n if (osm) {\n links\n .append('a')\n .attr('class', 'view-history-on-osm')\n .attr('href', osm.historyURL(entity))\n .attr('target', '_blank')\n .attr('tabindex', -1)\n .attr('title', t('info_panels.history.link_text'))\n .text('OSM');\n }\n links\n .append('a')\n .attr('class', 'pewu-history-viewer-link')\n .attr('href', 'https://pewu.github.io/osm-history/#/' + entity.type + '/' + entity.osmId())\n .attr('target', '_blank')\n .attr('tabindex', -1)\n .text('PeWu');\n\n var list = selection\n .append('ul');\n\n list\n .append('li')\n .text(t('info_panels.history.version') + ':')\n .append('span')\n .text(entity.version);\n\n list\n .append('li')\n .text(t('info_panels.history.last_edit') + ':')\n .append('span')\n .text(displayTimestamp(entity.timestamp));\n\n list\n .append('li')\n .text(t('info_panels.history.edited_by') + ':')\n .call(displayUser, entity.user);\n\n list\n .append('li')\n .text(t('info_panels.history.changeset') + ':')\n .call(displayChangeset, entity.changeset);\n }\n\n\n var panel = function(selection) {\n selection.call(redraw);\n\n context.map()\n .on('drawn.info-history', function() {\n selection.call(redraw);\n });\n\n context\n .on('enter.info-history', function() {\n selection.call(redraw);\n });\n };\n\n panel.off = function() {\n context.map().on('drawn.info-history', null);\n context.on('enter.info-history', null);\n };\n\n panel.id = 'history';\n panel.title = t('info_panels.history.title');\n panel.key = t('info_panels.history.key');\n\n\n return panel;\n}\n","import { t, localizer } from '../core/localizer';\n\nvar OSM_PRECISION = 7;\n\n/**\n * Returns a localized representation of the given length measurement.\n *\n * @param {Number} m area in meters\n * @param {Boolean} isImperial true for U.S. customary units; false for metric\n */\nexport function displayLength(m, isImperial) {\n var d = m * (isImperial ? 3.28084 : 1);\n var unit;\n\n if (isImperial) {\n if (d >= 5280) {\n d /= 5280;\n unit = 'miles';\n } else {\n unit = 'feet';\n }\n } else {\n if (d >= 1000) {\n d /= 1000;\n unit = 'kilometers';\n } else {\n unit = 'meters';\n }\n }\n\n return t('units.' + unit, {\n quantity: d.toLocaleString(localizer.localeCode(), {\n maximumSignificantDigits: 4\n })\n });\n}\n\n/**\n * Returns a localized representation of the given area measurement.\n *\n * @param {Number} m2 area in square meters\n * @param {Boolean} isImperial true for U.S. customary units; false for metric\n */\nexport function displayArea(m2, isImperial) {\n var locale = localizer.localeCode();\n var d = m2 * (isImperial ? 10.7639111056 : 1);\n var d1, d2, area;\n var unit1 = '';\n var unit2 = '';\n\n if (isImperial) {\n if (d >= 6969600) { // > 0.25mi² show mi²\n d1 = d / 27878400;\n unit1 = 'square_miles';\n } else {\n d1 = d;\n unit1 = 'square_feet';\n }\n\n if (d > 4356 && d < 43560000) { // 0.1 - 1000 acres\n d2 = d / 43560;\n unit2 = 'acres';\n }\n\n } else {\n if (d >= 250000) { // > 0.25km² show km²\n d1 = d / 1000000;\n unit1 = 'square_kilometers';\n } else {\n d1 = d;\n unit1 = 'square_meters';\n }\n\n if (d > 1000 && d < 10000000) { // 0.1 - 1000 hectares\n d2 = d / 10000;\n unit2 = 'hectares';\n }\n }\n\n area = t('units.' + unit1, {\n quantity: d1.toLocaleString(locale, {\n maximumSignificantDigits: 4\n })\n });\n\n if (d2) {\n return t('units.area_pair', {\n area1: area,\n area2: t('units.' + unit2, {\n quantity: d2.toLocaleString(locale, {\n maximumSignificantDigits: 2\n })\n })\n });\n } else {\n return area;\n }\n}\n\nfunction wrap(x, min, max) {\n var d = max - min;\n return ((x - min) % d + d) % d + min;\n}\n\nfunction clamp(x, min, max) {\n return Math.max(min, Math.min(x, max));\n}\n\nfunction displayCoordinate(deg, pos, neg) {\n var locale = localizer.localeCode();\n var min = (Math.abs(deg) - Math.floor(Math.abs(deg))) * 60;\n var sec = (min - Math.floor(min)) * 60;\n var displayDegrees = t('units.arcdegrees', {\n quantity: Math.floor(Math.abs(deg)).toLocaleString(locale)\n });\n var displayCoordinate;\n\n if (Math.floor(sec) > 0) {\n displayCoordinate = displayDegrees +\n t('units.arcminutes', {\n quantity: Math.floor(min).toLocaleString(locale)\n }) +\n t('units.arcseconds', {\n quantity: Math.round(sec).toLocaleString(locale)\n });\n } else if (Math.floor(min) > 0) {\n displayCoordinate = displayDegrees +\n t('units.arcminutes', {\n quantity: Math.round(min).toLocaleString(locale)\n });\n } else {\n displayCoordinate = t('units.arcdegrees', {\n quantity: Math.round(Math.abs(deg)).toLocaleString(locale)\n });\n }\n\n if (deg === 0) {\n return displayCoordinate;\n } else {\n return t('units.coordinate', {\n coordinate: displayCoordinate,\n direction: t('units.' + (deg > 0 ? pos : neg))\n });\n }\n}\n\n/**\n * Returns given coordinate pair in degree-minute-second format.\n *\n * @param {Array} coord longitude and latitude\n */\nexport function dmsCoordinatePair(coord) {\n return t('units.coordinate_pair', {\n latitude: displayCoordinate(clamp(coord[1], -90, 90), 'north', 'south'),\n longitude: displayCoordinate(wrap(coord[0], -180, 180), 'east', 'west')\n });\n}\n\n/**\n * Returns the given coordinate pair in decimal format.\n * note: unlocalized to avoid comma ambiguity - see #4765\n *\n * @param {Array} coord longitude and latitude\n */\nexport function decimalCoordinatePair(coord) {\n return t('units.coordinate_pair', {\n latitude: clamp(coord[1], -90, 90).toFixed(OSM_PRECISION),\n longitude: wrap(coord[0], -180, 180).toFixed(OSM_PRECISION)\n });\n}\n","import _debounce from 'lodash-es/debounce';\n\nimport { decimalCoordinatePair, dmsCoordinatePair } from '../../util/units';\nimport { t } from '../../core/localizer';\nimport { services } from '../../services';\n\n\nexport function uiPanelLocation(context) {\n var currLocation = '';\n\n\n function redraw(selection) {\n selection.html('');\n\n var list = selection\n .append('ul');\n\n // Mouse coordinates\n var coord = context.map().mouseCoordinates();\n if (coord.some(isNaN)) {\n coord = context.map().center();\n }\n\n list\n .append('li')\n .text(dmsCoordinatePair(coord))\n .append('li')\n .text(decimalCoordinatePair(coord));\n\n // Location Info\n selection\n .append('div')\n .attr('class', 'location-info')\n .text(currLocation || ' ');\n\n debouncedGetLocation(selection, coord);\n }\n\n\n var debouncedGetLocation = _debounce(getLocation, 250);\n function getLocation(selection, coord) {\n if (!services.geocoder) {\n currLocation = t('info_panels.location.unknown_location');\n selection.selectAll('.location-info')\n .text(currLocation);\n } else {\n services.geocoder.reverse(coord, function(err, result) {\n currLocation = result ? result.display_name : t('info_panels.location.unknown_location');\n selection.selectAll('.location-info')\n .text(currLocation);\n });\n }\n }\n\n\n var panel = function(selection) {\n selection.call(redraw);\n\n context.surface()\n .on(('PointerEvent' in window ? 'pointer' : 'mouse') + 'move.info-location', function() {\n selection.call(redraw);\n });\n };\n\n panel.off = function() {\n context.surface()\n .on('.info-location', null);\n };\n\n panel.id = 'location';\n panel.title = t('info_panels.location.title');\n panel.key = t('info_panels.location.key');\n\n\n return panel;\n}\n","import { event as d3_event } from 'd3-selection';\n\nimport {\n geoLength as d3_geoLength,\n geoCentroid as d3_geoCentroid\n} from 'd3-geo';\n\nimport { t, localizer } from '../../core/localizer';\nimport { displayArea, displayLength, decimalCoordinatePair, dmsCoordinatePair } from '../../util/units';\nimport { geoExtent } from '../../geo';\nimport { services } from '../../services';\nimport { utilGetAllNodes } from '../../util';\n\nexport function uiPanelMeasurement(context) {\n var locale = localizer.localeCode();\n var isImperial = !localizer.usesMetric();\n\n\n function radiansToMeters(r) {\n // using WGS84 authalic radius (6371007.1809 m)\n return r * 6371007.1809;\n }\n\n function steradiansToSqmeters(r) {\n // http://gis.stackexchange.com/a/124857/40446\n return r / (4 * Math.PI) * 510065621724000;\n }\n\n\n function toLineString(feature) {\n if (feature.type === 'LineString') return feature;\n\n var result = { type: 'LineString', coordinates: [] };\n if (feature.type === 'Polygon') {\n result.coordinates = feature.coordinates[0];\n } else if (feature.type === 'MultiPolygon') {\n result.coordinates = feature.coordinates[0][0];\n }\n\n return result;\n }\n\n\n function redraw(selection) {\n var graph = context.graph();\n var selectedNoteID = context.selectedNoteID();\n var osm = services.osm;\n\n var heading;\n var center, location, centroid;\n var closed, geometry;\n var totalNodeCount, length = 0, area = 0;\n\n if (selectedNoteID && osm) { // selected 1 note\n\n var note = osm.getNote(selectedNoteID);\n heading = t('note.note') + ' ' + selectedNoteID;\n location = note.loc;\n geometry = 'note';\n\n } else { // selected 1..n entities\n var selectedIDs = context.selectedIDs().filter(function(id) {\n return context.hasEntity(id);\n });\n var selected = selectedIDs.map(function(id) {\n return context.entity(id);\n });\n\n heading = selected.length === 1 ? selected[0].id :\n t('info_panels.measurement.selected', { n: selected.length.toLocaleString(locale) });\n\n if (selected.length) {\n var extent = geoExtent();\n for (var i in selected) {\n var entity = selected[i];\n extent._extend(entity.extent(graph));\n\n geometry = entity.geometry(graph);\n if (geometry === 'line' || geometry === 'area') {\n closed = (entity.type === 'relation') || (entity.isClosed() && !entity.isDegenerate());\n var feature = entity.asGeoJSON(graph);\n length += radiansToMeters(d3_geoLength(toLineString(feature)));\n centroid = d3_geoCentroid(feature);\n if (closed) {\n area += steradiansToSqmeters(entity.area(graph));\n }\n }\n }\n\n if (selected.length > 1) {\n geometry = null;\n closed = null;\n centroid = null;\n }\n\n if (selected.length === 1 && selected[0].type === 'node') {\n location = selected[0].loc;\n } else {\n totalNodeCount = utilGetAllNodes(selectedIDs, context.graph()).length;\n }\n\n if (!location && !centroid) {\n center = extent.center();\n }\n }\n }\n\n selection.html('');\n\n if (heading) {\n selection\n .append('h4')\n .attr('class', 'measurement-heading')\n .text(heading);\n }\n\n var list = selection\n .append('ul');\n var coordItem;\n\n if (geometry) {\n list\n .append('li')\n .text(t('info_panels.measurement.geometry') + ':')\n .append('span')\n .text(\n closed ? t('info_panels.measurement.closed_' + geometry) : t('geometry.' + geometry)\n );\n }\n\n if (totalNodeCount) {\n list\n .append('li')\n .text(t('info_panels.measurement.node_count') + ':')\n .append('span')\n .text(totalNodeCount.toLocaleString(locale));\n }\n\n if (area) {\n list\n .append('li')\n .text(t('info_panels.measurement.area') + ':')\n .append('span')\n .text(displayArea(area, isImperial));\n }\n\n if (length) {\n var lengthLabel = t('info_panels.measurement.' + (closed ? 'perimeter' : 'length'));\n list\n .append('li')\n .text(lengthLabel + ':')\n .append('span')\n .text(displayLength(length, isImperial));\n }\n\n if (location) {\n coordItem = list\n .append('li')\n .text(t('info_panels.measurement.location') + ':');\n coordItem.append('span')\n .text(dmsCoordinatePair(location));\n coordItem.append('span')\n .text(decimalCoordinatePair(location));\n }\n\n if (centroid) {\n coordItem = list\n .append('li')\n .text(t('info_panels.measurement.centroid') + ':');\n coordItem.append('span')\n .text(dmsCoordinatePair(centroid));\n coordItem.append('span')\n .text(decimalCoordinatePair(centroid));\n }\n\n if (center) {\n coordItem = list\n .append('li')\n .text(t('info_panels.measurement.center') + ':');\n coordItem.append('span')\n .text(dmsCoordinatePair(center));\n coordItem.append('span')\n .text(decimalCoordinatePair(center));\n }\n\n if (length || area) {\n var toggle = isImperial ? 'imperial' : 'metric';\n selection\n .append('a')\n .text(t('info_panels.measurement.' + toggle))\n .attr('href', '#')\n .attr('class', 'button button-toggle-units')\n .on('click', function() {\n d3_event.preventDefault();\n isImperial = !isImperial;\n selection.call(redraw);\n });\n }\n }\n\n\n var panel = function(selection) {\n selection.call(redraw);\n\n context.map()\n .on('drawn.info-measurement', function() {\n selection.call(redraw);\n });\n\n context\n .on('enter.info-measurement', function() {\n selection.call(redraw);\n });\n };\n\n panel.off = function() {\n context.map().on('drawn.info-measurement', null);\n context.on('enter.info-measurement', null);\n };\n\n panel.id = 'measurement';\n panel.title = t('info_panels.measurement.title');\n panel.key = t('info_panels.measurement.key');\n\n\n return panel;\n}\n","export * from './background';\nexport * from './history';\nexport * from './location';\nexport * from './measurement';\n\nimport { uiPanelBackground } from './background';\nimport { uiPanelHistory } from './history';\nimport { uiPanelLocation } from './location';\nimport { uiPanelMeasurement } from './measurement';\n\nexport var uiInfoPanels = {\n background: uiPanelBackground,\n history: uiPanelHistory,\n location: uiPanelLocation,\n measurement: uiPanelMeasurement,\n};\n","import {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { t } from '../core/localizer';\nimport { svgIcon } from '../svg/icon';\nimport { uiCmd } from './cmd';\nimport { uiInfoPanels } from './panels';\n\n\nexport function uiInfo(context) {\n var ids = Object.keys(uiInfoPanels);\n var wasActive = ['measurement'];\n var panels = {};\n var active = {};\n\n // create panels\n ids.forEach(function(k) {\n if (!panels[k]) {\n panels[k] = uiInfoPanels[k](context);\n active[k] = false;\n }\n });\n\n\n function info(selection) {\n\n function redraw() {\n var activeids = ids.filter(function(k) { return active[k]; }).sort();\n\n var containers = infoPanels.selectAll('.panel-container')\n .data(activeids, function(k) { return k; });\n\n containers.exit()\n .style('opacity', 1)\n .transition()\n .duration(200)\n .style('opacity', 0)\n .on('end', function(d) {\n d3_select(this)\n .call(panels[d].off)\n .remove();\n });\n\n var enter = containers.enter()\n .append('div')\n .attr('class', function(d) { return 'fillD2 panel-container panel-container-' + d; });\n\n enter\n .style('opacity', 0)\n .transition()\n .duration(200)\n .style('opacity', 1);\n\n var title = enter\n .append('div')\n .attr('class', 'panel-title fillD2');\n\n title\n .append('h3')\n .text(function(d) { return panels[d].title; });\n\n title\n .append('button')\n .attr('class', 'close')\n .on('click', function (d) { info.toggle(d); })\n .call(svgIcon('#iD-icon-close'));\n\n enter\n .append('div')\n .attr('class', function(d) { return 'panel-content panel-content-' + d; });\n\n\n // redraw the panels\n infoPanels.selectAll('.panel-content')\n .each(function(d) {\n d3_select(this).call(panels[d]);\n });\n }\n\n\n info.toggle = function(which) {\n if (d3_event) {\n d3_event.stopImmediatePropagation();\n d3_event.preventDefault();\n }\n\n var activeids = ids.filter(function(k) { return active[k]; });\n\n if (which) { // toggle one\n active[which] = !active[which];\n if (activeids.length === 1 && activeids[0] === which) { // none active anymore\n wasActive = [which];\n }\n\n context.container().select('.' + which + '-panel-toggle-item')\n .classed('active', active[which])\n .select('input')\n .property('checked', active[which]);\n\n } else { // toggle all\n if (activeids.length) {\n wasActive = activeids;\n activeids.forEach(function(k) { active[k] = false; });\n } else {\n wasActive.forEach(function(k) { active[k] = true; });\n }\n }\n\n redraw();\n };\n\n\n var infoPanels = selection.selectAll('.info-panels')\n .data([0]);\n\n infoPanels = infoPanels.enter()\n .append('div')\n .attr('class', 'info-panels')\n .merge(infoPanels);\n\n redraw();\n\n context.keybinding()\n .on(uiCmd('⌘' + t('info_panels.key')), info.toggle);\n\n ids.forEach(function(k) {\n var key = t('info_panels.' + k + '.key', { default: null });\n if (!key) return;\n context.keybinding()\n .on(uiCmd('⌘⇧' + key), function() { info.toggle(k); });\n });\n }\n\n return info;\n}\n","import { easeLinear as d3_easeLinear } from 'd3-ease';\n\nimport {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { localizer } from '../core/localizer';\nimport { uiToggle } from './toggle';\n\n\n// Tooltips and svg mask used to highlight certain features\nexport function uiCurtain(containerNode) {\n\n var surface = d3_select(null),\n tooltip = d3_select(null),\n darkness = d3_select(null);\n\n function curtain(selection) {\n surface = selection\n .append('svg')\n .attr('class', 'curtain')\n .style('top', 0)\n .style('left', 0);\n\n darkness = surface.append('path')\n .attr('x', 0)\n .attr('y', 0)\n .attr('class', 'curtain-darkness');\n\n d3_select(window).on('resize.curtain', resize);\n\n tooltip = selection.append('div')\n .attr('class', 'tooltip');\n\n tooltip\n .append('div')\n .attr('class', 'popover-arrow');\n\n tooltip\n .append('div')\n .attr('class', 'popover-inner');\n\n resize();\n\n\n function resize() {\n surface\n .attr('width', containerNode.clientWidth)\n .attr('height', containerNode.clientHeight);\n curtain.cut(darkness.datum());\n }\n }\n\n\n /**\n * Reveal cuts the curtain to highlight the given box,\n * and shows a tooltip with instructions next to the box.\n *\n * @param {String|ClientRect} [box] box used to cut the curtain\n * @param {String} [text] text for a tooltip\n * @param {Object} [options]\n * @param {string} [options.tooltipClass] optional class to add to the tooltip\n * @param {integer} [options.duration] transition time in milliseconds\n * @param {string} [options.buttonText] if set, create a button with this text label\n * @param {function} [options.buttonCallback] if set, the callback for the button\n * @param {function} [options.padding] extra margin in px to put around bbox\n * @param {String|ClientRect} [options.tooltipBox] box for tooltip position, if different from box for the curtain\n */\n curtain.reveal = function(box, text, options) {\n options = options || {};\n\n if (typeof box === 'string') {\n box = d3_select(box).node();\n }\n if (box && box.getBoundingClientRect) {\n box = copyBox(box.getBoundingClientRect());\n var containerRect = containerNode.getBoundingClientRect();\n box.top -= containerRect.top;\n box.left -= containerRect.left;\n }\n if (box && options.padding) {\n box.top -= options.padding;\n box.left -= options.padding;\n box.bottom += options.padding;\n box.right += options.padding;\n box.height += options.padding * 2;\n box.width += options.padding * 2;\n }\n\n var tooltipBox;\n if (options.tooltipBox) {\n tooltipBox = options.tooltipBox;\n if (typeof tooltipBox === 'string') {\n tooltipBox = d3_select(tooltipBox).node();\n }\n if (tooltipBox && tooltipBox.getBoundingClientRect) {\n tooltipBox = copyBox(tooltipBox.getBoundingClientRect());\n }\n } else {\n tooltipBox = box;\n }\n\n if (tooltipBox && text) {\n // pseudo markdown bold text for the instruction section..\n var parts = text.split('**');\n var html = parts[0] ? '' + parts[0] + ' ' : '';\n if (parts[1]) {\n html += '' + parts[1] + ' ';\n }\n\n html = html.replace(/\\*(.*?)\\*/g, '$1 '); // emphasis\n html = html.replace(/\\{br\\}/g, ' '); // linebreak\n\n if (options.buttonText && options.buttonCallback) {\n html += '' +\n '' + options.buttonText + '
';\n }\n\n var classes = 'curtain-tooltip popover tooltip arrowed in ' + (options.tooltipClass || '');\n tooltip\n .classed(classes, true)\n .selectAll('.popover-inner')\n .html(html);\n\n if (options.buttonText && options.buttonCallback) {\n var button = tooltip.selectAll('.button-section .button.action');\n button\n .on('click', function() {\n d3_event.preventDefault();\n options.buttonCallback();\n });\n }\n\n var tip = copyBox(tooltip.node().getBoundingClientRect()),\n w = containerNode.clientWidth,\n h = containerNode.clientHeight,\n tooltipWidth = 200,\n tooltipArrow = 5,\n side, pos;\n\n\n // hack: this will have bottom placement,\n // so need to reserve extra space for the tooltip illustration.\n if (options.tooltipClass === 'intro-mouse') {\n tip.height += 80;\n }\n\n // trim box dimensions to just the portion that fits in the container..\n if (tooltipBox.top + tooltipBox.height > h) {\n tooltipBox.height -= (tooltipBox.top + tooltipBox.height - h);\n }\n if (tooltipBox.left + tooltipBox.width > w) {\n tooltipBox.width -= (tooltipBox.left + tooltipBox.width - w);\n }\n\n // determine tooltip placement..\n\n if (tooltipBox.top + tooltipBox.height < 100) {\n // tooltip below box..\n side = 'bottom';\n pos = [\n tooltipBox.left + tooltipBox.width / 2 - tip.width / 2,\n tooltipBox.top + tooltipBox.height\n ];\n\n } else if (tooltipBox.top > h - 140) {\n // tooltip above box..\n side = 'top';\n pos = [\n tooltipBox.left + tooltipBox.width / 2 - tip.width / 2,\n tooltipBox.top - tip.height\n ];\n\n } else {\n // tooltip to the side of the tooltipBox..\n var tipY = tooltipBox.top + tooltipBox.height / 2 - tip.height / 2;\n\n if (localizer.textDirection() === 'rtl') {\n if (tooltipBox.left - tooltipWidth - tooltipArrow < 70) {\n side = 'right';\n pos = [tooltipBox.left + tooltipBox.width + tooltipArrow, tipY];\n\n } else {\n side = 'left';\n pos = [tooltipBox.left - tooltipWidth - tooltipArrow, tipY];\n }\n\n } else {\n if (tooltipBox.left + tooltipBox.width + tooltipArrow + tooltipWidth > w - 70) {\n side = 'left';\n pos = [tooltipBox.left - tooltipWidth - tooltipArrow, tipY];\n }\n else {\n side = 'right';\n pos = [tooltipBox.left + tooltipBox.width + tooltipArrow, tipY];\n }\n }\n }\n\n if (options.duration !== 0 || !tooltip.classed(side)) {\n tooltip.call(uiToggle(true));\n }\n\n tooltip\n .style('top', pos[1] + 'px')\n .style('left', pos[0] + 'px')\n .attr('class', classes + ' ' + side);\n\n\n // shift popover-inner if it is very close to the top or bottom edge\n // (doesn't affect the placement of the popover-arrow)\n var shiftY = 0;\n if (side === 'left' || side === 'right') {\n if (pos[1] < 60) {\n shiftY = 60 - pos[1];\n }\n else if (pos[1] + tip.height > h - 100) {\n shiftY = h - pos[1] - tip.height - 100;\n }\n }\n tooltip.selectAll('.popover-inner')\n .style('top', shiftY + 'px');\n\n } else {\n tooltip\n .classed('in', false)\n .call(uiToggle(false));\n }\n\n curtain.cut(box, options.duration);\n\n return tooltip;\n };\n\n\n curtain.cut = function(datum, duration) {\n darkness.datum(datum)\n .interrupt();\n\n var selection;\n if (duration === 0) {\n selection = darkness;\n } else {\n selection = darkness\n .transition()\n .duration(duration || 600)\n .ease(d3_easeLinear);\n }\n\n selection\n .attr('d', function(d) {\n var containerWidth = containerNode.clientWidth;\n var containerHeight = containerNode.clientHeight;\n var string = 'M 0,0 L 0,' + containerHeight + ' L ' +\n containerWidth + ',' + containerHeight + 'L' +\n containerWidth + ',0 Z';\n\n if (!d) return string;\n return string + 'M' +\n d.left + ',' + d.top + 'L' +\n d.left + ',' + (d.top + d.height) + 'L' +\n (d.left + d.width) + ',' + (d.top + d.height) + 'L' +\n (d.left + d.width) + ',' + (d.top) + 'Z';\n\n });\n };\n\n\n curtain.remove = function() {\n surface.remove();\n tooltip.remove();\n d3_select(window).on('resize.curtain', null);\n };\n\n\n // ClientRects are immutable, so copy them to an object,\n // in case we need to trim the height/width.\n function copyBox(src) {\n return {\n top: src.top,\n right: src.right,\n bottom: src.bottom,\n left: src.left,\n width: src.width,\n height: src.height\n };\n }\n\n\n return curtain;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\n\nimport { helpString } from './helper';\nimport { t } from '../../core/localizer';\nimport { utilRebind } from '../../util/rebind';\n\n\nexport function uiIntroWelcome(context, reveal) {\n var dispatch = d3_dispatch('done');\n\n var chapter = {\n title: 'intro.welcome.title'\n };\n\n\n function welcome() {\n context.map().centerZoom([-85.63591, 41.94285], 19);\n reveal('.intro-nav-wrap .chapter-welcome',\n helpString('intro.welcome.welcome'),\n { buttonText: t('intro.ok'), buttonCallback: practice }\n );\n }\n\n function practice() {\n reveal('.intro-nav-wrap .chapter-welcome',\n helpString('intro.welcome.practice'),\n { buttonText: t('intro.ok'), buttonCallback: words }\n );\n }\n\n function words() {\n reveal('.intro-nav-wrap .chapter-welcome',\n helpString('intro.welcome.words'),\n { buttonText: t('intro.ok'), buttonCallback: chapters }\n );\n }\n\n\n function chapters() {\n dispatch.call('done');\n reveal('.intro-nav-wrap .chapter-navigation',\n helpString('intro.welcome.chapters', { next: t('intro.navigation.title') })\n );\n }\n\n\n chapter.enter = function() {\n welcome();\n };\n\n\n chapter.exit = function() {\n context.container().select('.curtain-tooltip.intro-mouse')\n .selectAll('.counter')\n .remove();\n };\n\n\n chapter.restart = function() {\n chapter.exit();\n chapter.enter();\n };\n\n\n return utilRebind(chapter, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\n\nimport {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { presetManager } from '../../presets';\nimport { t } from '../../core/localizer';\nimport { modeBrowse } from '../../modes/browse';\nimport { modeSelect } from '../../modes/select';\nimport { utilRebind } from '../../util/rebind';\nimport { helpString, icon, pointBox, transitionTime } from './helper';\n\n\nexport function uiIntroNavigation(context, reveal) {\n var dispatch = d3_dispatch('done');\n var timeouts = [];\n var hallId = 'n2061';\n var townHall = [-85.63591, 41.94285];\n var springStreetId = 'w397';\n var springStreetEndId = 'n1834';\n var springStreet = [-85.63582, 41.94255];\n var onewayField = presetManager.field('oneway');\n var maxspeedField = presetManager.field('maxspeed');\n\n\n var chapter = {\n title: 'intro.navigation.title'\n };\n\n\n function timeout(f, t) {\n timeouts.push(window.setTimeout(f, t));\n }\n\n\n function eventCancel() {\n d3_event.stopPropagation();\n d3_event.preventDefault();\n }\n\n\n function isTownHallSelected() {\n var ids = context.selectedIDs();\n return ids.length === 1 && ids[0] === hallId;\n }\n\n\n function dragMap() {\n context.enter(modeBrowse(context));\n context.history().reset('initial');\n\n var msec = transitionTime(townHall, context.map().center());\n if (msec) { reveal(null, null, { duration: 0 }); }\n context.map().centerZoomEase(townHall, 19, msec);\n\n timeout(function() {\n var centerStart = context.map().center();\n\n var textId = context.lastPointerType() === 'mouse' ? 'drag' : 'drag_touch';\n var dragString = helpString('intro.navigation.map_info') + '{br}' + helpString('intro.navigation.' + textId);\n reveal('.surface', dragString);\n context.map().on('drawn.intro', function() {\n reveal('.surface', dragString, { duration: 0 });\n });\n\n context.map().on('move.intro', function() {\n var centerNow = context.map().center();\n if (centerStart[0] !== centerNow[0] || centerStart[1] !== centerNow[1]) {\n context.map().on('move.intro', null);\n timeout(function() { continueTo(zoomMap); }, 3000);\n }\n });\n\n }, msec + 100);\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n nextStep();\n }\n }\n\n\n function zoomMap() {\n var zoomStart = context.map().zoom();\n\n var textId = context.lastPointerType() === 'mouse' ? 'zoom' : 'zoom_touch';\n var zoomString = helpString('intro.navigation.' + textId);\n\n reveal('.surface', zoomString);\n\n context.map().on('drawn.intro', function() {\n reveal('.surface', zoomString, { duration: 0 });\n });\n\n context.map().on('move.intro', function() {\n if (context.map().zoom() !== zoomStart) {\n context.map().on('move.intro', null);\n timeout(function() { continueTo(features); }, 3000);\n }\n });\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n nextStep();\n }\n }\n\n\n function features() {\n var onClick = function() { continueTo(pointsLinesAreas); };\n\n reveal('.surface', helpString('intro.navigation.features'),\n { buttonText: t('intro.ok'), buttonCallback: onClick }\n );\n\n context.map().on('drawn.intro', function() {\n reveal('.surface', helpString('intro.navigation.features'),\n { duration: 0, buttonText: t('intro.ok'), buttonCallback: onClick }\n );\n });\n\n function continueTo(nextStep) {\n context.map().on('drawn.intro', null);\n nextStep();\n }\n }\n\n function pointsLinesAreas() {\n var onClick = function() { continueTo(nodesWays); };\n\n reveal('.surface', helpString('intro.navigation.points_lines_areas'),\n { buttonText: t('intro.ok'), buttonCallback: onClick }\n );\n\n context.map().on('drawn.intro', function() {\n reveal('.surface', helpString('intro.navigation.points_lines_areas'),\n { duration: 0, buttonText: t('intro.ok'), buttonCallback: onClick }\n );\n });\n\n function continueTo(nextStep) {\n context.map().on('drawn.intro', null);\n nextStep();\n }\n }\n\n function nodesWays() {\n var onClick = function() { continueTo(clickTownHall); };\n\n reveal('.surface', helpString('intro.navigation.nodes_ways'),\n { buttonText: t('intro.ok'), buttonCallback: onClick }\n );\n\n context.map().on('drawn.intro', function() {\n reveal('.surface', helpString('intro.navigation.nodes_ways'),\n { duration: 0, buttonText: t('intro.ok'), buttonCallback: onClick }\n );\n });\n\n function continueTo(nextStep) {\n context.map().on('drawn.intro', null);\n nextStep();\n }\n }\n\n function clickTownHall() {\n context.enter(modeBrowse(context));\n context.history().reset('initial');\n\n var entity = context.hasEntity(hallId);\n if (!entity) return;\n reveal(null, null, { duration: 0 });\n context.map().centerZoomEase(entity.loc, 19, 500);\n\n timeout(function() {\n var entity = context.hasEntity(hallId);\n if (!entity) return;\n var box = pointBox(entity.loc, context);\n var textId = context.lastPointerType() === 'mouse' ? 'click_townhall' : 'tap_townhall';\n reveal(box, helpString('intro.navigation.' + textId));\n\n context.map().on('move.intro drawn.intro', function() {\n var entity = context.hasEntity(hallId);\n if (!entity) return;\n var box = pointBox(entity.loc, context);\n reveal(box, helpString('intro.navigation.' + textId), { duration: 0 });\n });\n\n context.on('enter.intro', function() {\n if (isTownHallSelected()) continueTo(selectedTownHall);\n });\n\n }, 550); // after centerZoomEase\n\n context.history().on('change.intro', function() {\n if (!context.hasEntity(hallId)) {\n continueTo(clickTownHall);\n }\n });\n\n function continueTo(nextStep) {\n context.on('enter.intro', null);\n context.map().on('move.intro drawn.intro', null);\n context.history().on('change.intro', null);\n nextStep();\n }\n }\n\n\n function selectedTownHall() {\n if (!isTownHallSelected()) return clickTownHall();\n\n var entity = context.hasEntity(hallId);\n if (!entity) return clickTownHall();\n\n var box = pointBox(entity.loc, context);\n var onClick = function() { continueTo(editorTownHall); };\n\n reveal(box, helpString('intro.navigation.selected_townhall'),\n { buttonText: t('intro.ok'), buttonCallback: onClick }\n );\n\n context.map().on('move.intro drawn.intro', function() {\n var entity = context.hasEntity(hallId);\n if (!entity) return;\n var box = pointBox(entity.loc, context);\n reveal(box, helpString('intro.navigation.selected_townhall'),\n { duration: 0, buttonText: t('intro.ok'), buttonCallback: onClick }\n );\n });\n\n context.history().on('change.intro', function() {\n if (!context.hasEntity(hallId)) {\n continueTo(clickTownHall);\n }\n });\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.history().on('change.intro', null);\n nextStep();\n }\n }\n\n\n function editorTownHall() {\n if (!isTownHallSelected()) return clickTownHall();\n\n // disallow scrolling\n context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);\n\n var onClick = function() { continueTo(presetTownHall); };\n\n reveal('.entity-editor-pane',\n helpString('intro.navigation.editor_townhall'),\n { buttonText: t('intro.ok'), buttonCallback: onClick }\n );\n\n context.on('exit.intro', function() {\n continueTo(clickTownHall);\n });\n\n context.history().on('change.intro', function() {\n if (!context.hasEntity(hallId)) {\n continueTo(clickTownHall);\n }\n });\n\n function continueTo(nextStep) {\n context.on('exit.intro', null);\n context.history().on('change.intro', null);\n context.container().select('.inspector-wrap').on('wheel.intro', null);\n nextStep();\n }\n }\n\n\n function presetTownHall() {\n if (!isTownHallSelected()) return clickTownHall();\n\n // reset pane, in case user happened to change it..\n context.container().select('.inspector-wrap .panewrap').style('right', '0%');\n // disallow scrolling\n context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);\n\n // preset match, in case the user happened to change it.\n var entity = context.entity(context.selectedIDs()[0]);\n var preset = presetManager.match(entity, context.graph());\n\n var onClick = function() { continueTo(fieldsTownHall); };\n\n reveal('.entity-editor-pane .section-feature-type',\n helpString('intro.navigation.preset_townhall', { preset: preset.name() }),\n { buttonText: t('intro.ok'), buttonCallback: onClick }\n );\n\n context.on('exit.intro', function() {\n continueTo(clickTownHall);\n });\n\n context.history().on('change.intro', function() {\n if (!context.hasEntity(hallId)) {\n continueTo(clickTownHall);\n }\n });\n\n function continueTo(nextStep) {\n context.on('exit.intro', null);\n context.history().on('change.intro', null);\n context.container().select('.inspector-wrap').on('wheel.intro', null);\n nextStep();\n }\n }\n\n\n function fieldsTownHall() {\n if (!isTownHallSelected()) return clickTownHall();\n\n // reset pane, in case user happened to change it..\n context.container().select('.inspector-wrap .panewrap').style('right', '0%');\n // disallow scrolling\n context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);\n\n var onClick = function() { continueTo(closeTownHall); };\n\n reveal('.entity-editor-pane .section-preset-fields',\n helpString('intro.navigation.fields_townhall'),\n { buttonText: t('intro.ok'), buttonCallback: onClick }\n );\n\n context.on('exit.intro', function() {\n continueTo(clickTownHall);\n });\n\n context.history().on('change.intro', function() {\n if (!context.hasEntity(hallId)) {\n continueTo(clickTownHall);\n }\n });\n\n function continueTo(nextStep) {\n context.on('exit.intro', null);\n context.history().on('change.intro', null);\n context.container().select('.inspector-wrap').on('wheel.intro', null);\n nextStep();\n }\n }\n\n\n function closeTownHall() {\n if (!isTownHallSelected()) return clickTownHall();\n\n var selector = '.entity-editor-pane button.close svg use';\n var href = d3_select(selector).attr('href') || '#iD-icon-close';\n\n reveal('.entity-editor-pane',\n helpString('intro.navigation.close_townhall', { button: icon(href, 'pre-text') })\n );\n\n context.on('exit.intro', function() {\n continueTo(searchStreet);\n });\n\n context.history().on('change.intro', function() {\n // update the close icon in the tooltip if the user edits something.\n var selector = '.entity-editor-pane button.close svg use';\n var href = d3_select(selector).attr('href') || '#iD-icon-close';\n\n reveal('.entity-editor-pane',\n helpString('intro.navigation.close_townhall', { button: icon(href, 'pre-text') }),\n { duration: 0 }\n );\n });\n\n function continueTo(nextStep) {\n context.on('exit.intro', null);\n context.history().on('change.intro', null);\n nextStep();\n }\n }\n\n\n function searchStreet() {\n context.enter(modeBrowse(context));\n context.history().reset('initial'); // ensure spring street exists\n\n var msec = transitionTime(springStreet, context.map().center());\n if (msec) { reveal(null, null, { duration: 0 }); }\n context.map().centerZoomEase(springStreet, 19, msec); // ..and user can see it\n\n timeout(function() {\n reveal('.search-header input',\n helpString('intro.navigation.search_street', { name: t('intro.graph.name.spring-street') })\n );\n\n context.container().select('.search-header input')\n .on('keyup.intro', checkSearchResult);\n }, msec + 100);\n }\n\n\n function checkSearchResult() {\n var first = context.container().select('.feature-list-item:nth-child(0n+2)'); // skip \"No Results\" item\n var firstName = first.select('.entity-name');\n var name = t('intro.graph.name.spring-street');\n\n if (!firstName.empty() && firstName.text() === name) {\n reveal(first.node(),\n helpString('intro.navigation.choose_street', { name: name }),\n { duration: 300 }\n );\n\n context.on('exit.intro', function() {\n continueTo(selectedStreet);\n });\n\n context.container().select('.search-header input')\n .on('keydown.intro', eventCancel, true)\n .on('keyup.intro', null);\n }\n\n function continueTo(nextStep) {\n context.on('exit.intro', null);\n context.container().select('.search-header input')\n .on('keydown.intro', null)\n .on('keyup.intro', null);\n nextStep();\n }\n }\n\n\n function selectedStreet() {\n if (!context.hasEntity(springStreetEndId) || !context.hasEntity(springStreetId)) {\n return searchStreet();\n }\n\n var onClick = function() { continueTo(editorStreet); };\n var entity = context.entity(springStreetEndId);\n var box = pointBox(entity.loc, context);\n box.height = 500;\n\n reveal(box,\n helpString('intro.navigation.selected_street', { name: t('intro.graph.name.spring-street') }),\n { duration: 600, buttonText: t('intro.ok'), buttonCallback: onClick }\n );\n\n timeout(function() {\n context.map().on('move.intro drawn.intro', function() {\n var entity = context.hasEntity(springStreetEndId);\n if (!entity) return;\n var box = pointBox(entity.loc, context);\n box.height = 500;\n reveal(box,\n helpString('intro.navigation.selected_street', { name: t('intro.graph.name.spring-street') }),\n { duration: 0, buttonText: t('intro.ok'), buttonCallback: onClick }\n );\n });\n }, 600); // after reveal.\n\n context.on('enter.intro', function(mode) {\n if (!context.hasEntity(springStreetId)) {\n return continueTo(searchStreet);\n }\n var ids = context.selectedIDs();\n if (mode.id !== 'select' || !ids.length || ids[0] !== springStreetId) {\n // keep Spring Street selected..\n context.enter(modeSelect(context, [springStreetId]));\n }\n });\n\n context.history().on('change.intro', function() {\n if (!context.hasEntity(springStreetEndId) || !context.hasEntity(springStreetId)) {\n timeout(function() {\n continueTo(searchStreet);\n }, 300); // after any transition (e.g. if user deleted intersection)\n }\n });\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.on('enter.intro', null);\n context.history().on('change.intro', null);\n nextStep();\n }\n }\n\n\n function editorStreet() {\n var selector = '.entity-editor-pane button.close svg use';\n var href = d3_select(selector).attr('href') || '#iD-icon-close';\n\n reveal('.entity-editor-pane', helpString('intro.navigation.street_different_fields') + '{br}' +\n helpString('intro.navigation.editor_street', {\n button: icon(href, 'pre-text'),\n field1: onewayField.label(),\n field2: maxspeedField.label()\n }));\n\n context.on('exit.intro', function() {\n continueTo(play);\n });\n\n context.history().on('change.intro', function() {\n // update the close icon in the tooltip if the user edits something.\n var selector = '.entity-editor-pane button.close svg use';\n var href = d3_select(selector).attr('href') || '#iD-icon-close';\n\n reveal('.entity-editor-pane', helpString('intro.navigation.street_different_fields') + '{br}' +\n helpString('intro.navigation.editor_street', {\n button: icon(href, 'pre-text'),\n field1: onewayField.label(),\n field2: maxspeedField.label()\n }), { duration: 0 }\n );\n });\n\n function continueTo(nextStep) {\n context.on('exit.intro', null);\n context.history().on('change.intro', null);\n nextStep();\n }\n }\n\n\n function play() {\n dispatch.call('done');\n reveal('.ideditor',\n helpString('intro.navigation.play', { next: t('intro.points.title') }), {\n tooltipBox: '.intro-nav-wrap .chapter-point',\n buttonText: t('intro.ok'),\n buttonCallback: function() { reveal('.ideditor'); }\n }\n );\n }\n\n\n chapter.enter = function() {\n dragMap();\n };\n\n\n chapter.exit = function() {\n timeouts.forEach(window.clearTimeout);\n context.on('enter.intro exit.intro', null);\n context.map().on('move.intro drawn.intro', null);\n context.history().on('change.intro', null);\n context.container().select('.inspector-wrap').on('wheel.intro', null);\n context.container().select('.search-header input').on('keydown.intro keyup.intro', null);\n };\n\n\n chapter.restart = function() {\n chapter.exit();\n chapter.enter();\n };\n\n\n return utilRebind(chapter, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { presetManager } from '../../presets';\nimport { t } from '../../core/localizer';\nimport { actionChangePreset } from '../../actions/change_preset';\nimport { modeBrowse } from '../../modes/browse';\nimport { modeSelect } from '../../modes/select';\nimport { utilRebind } from '../../util/rebind';\nimport { helpString, icon, pointBox, pad, selectMenuItem, transitionTime } from './helper';\n\n\nexport function uiIntroPoint(context, reveal) {\n var dispatch = d3_dispatch('done');\n var timeouts = [];\n var intersection = [-85.63279, 41.94394];\n var building = [-85.632422, 41.944045];\n var cafePreset = presetManager.item('amenity/cafe');\n var _pointID = null;\n\n\n var chapter = {\n title: 'intro.points.title'\n };\n\n\n function timeout(f, t) {\n timeouts.push(window.setTimeout(f, t));\n }\n\n\n function eventCancel() {\n d3_event.stopPropagation();\n d3_event.preventDefault();\n }\n\n\n function addPoint() {\n context.enter(modeBrowse(context));\n context.history().reset('initial');\n\n var msec = transitionTime(intersection, context.map().center());\n if (msec) { reveal(null, null, { duration: 0 }); }\n context.map().centerZoomEase(intersection, 19, msec);\n\n timeout(function() {\n var tooltip = reveal('button.add-point',\n helpString('intro.points.points_info') + '{br}' + helpString('intro.points.add_point'));\n\n _pointID = null;\n\n tooltip.selectAll('.popover-inner')\n .insert('svg', 'span')\n .attr('class', 'tooltip-illustration')\n .append('use')\n .attr('xlink:href', '#iD-graphic-points');\n\n context.on('enter.intro', function(mode) {\n if (mode.id !== 'add-point') return;\n continueTo(placePoint);\n });\n }, msec + 100);\n\n function continueTo(nextStep) {\n context.on('enter.intro', null);\n nextStep();\n }\n }\n\n\n function placePoint() {\n if (context.mode().id !== 'add-point') {\n return chapter.restart();\n }\n\n var pointBox = pad(building, 150, context);\n var textId = context.lastPointerType() === 'mouse' ? 'place_point' : 'place_point_touch';\n reveal(pointBox, helpString('intro.points.' + textId));\n\n context.map().on('move.intro drawn.intro', function() {\n pointBox = pad(building, 150, context);\n reveal(pointBox, helpString('intro.points.' + textId), { duration: 0 });\n });\n\n context.on('enter.intro', function(mode) {\n if (mode.id !== 'select') return chapter.restart();\n _pointID = context.mode().selectedIDs()[0];\n continueTo(searchPreset);\n });\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.on('enter.intro', null);\n nextStep();\n }\n }\n\n\n function searchPreset() {\n if (context.mode().id !== 'select' || !_pointID || !context.hasEntity(_pointID)) {\n return addPoint();\n }\n\n // disallow scrolling\n context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);\n\n context.container().select('.preset-search-input')\n .on('keydown.intro', null)\n .on('keyup.intro', checkPresetSearch);\n\n reveal('.preset-search-input',\n helpString('intro.points.search_cafe', { preset: cafePreset.name() })\n );\n\n context.on('enter.intro', function(mode) {\n if (!_pointID || !context.hasEntity(_pointID)) {\n return continueTo(addPoint);\n }\n\n var ids = context.selectedIDs();\n if (mode.id !== 'select' || !ids.length || ids[0] !== _pointID) {\n // keep the user's point selected..\n context.enter(modeSelect(context, [_pointID]));\n\n // disallow scrolling\n context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);\n\n context.container().select('.preset-search-input')\n .on('keydown.intro', null)\n .on('keyup.intro', checkPresetSearch);\n\n reveal('.preset-search-input',\n helpString('intro.points.search_cafe', { preset: cafePreset.name() })\n );\n\n context.history().on('change.intro', null);\n }\n });\n\n\n function checkPresetSearch() {\n var first = context.container().select('.preset-list-item:first-child');\n\n if (first.classed('preset-amenity-cafe')) {\n context.container().select('.preset-search-input')\n .on('keydown.intro', eventCancel, true)\n .on('keyup.intro', null);\n\n reveal(first.select('.preset-list-button').node(),\n helpString('intro.points.choose_cafe', { preset: cafePreset.name() }),\n { duration: 300 }\n );\n\n context.history().on('change.intro', function() {\n continueTo(aboutFeatureEditor);\n });\n }\n }\n\n function continueTo(nextStep) {\n context.on('enter.intro', null);\n context.history().on('change.intro', null);\n context.container().select('.inspector-wrap').on('wheel.intro', null);\n context.container().select('.preset-search-input').on('keydown.intro keyup.intro', null);\n nextStep();\n }\n }\n\n\n function aboutFeatureEditor() {\n if (context.mode().id !== 'select' || !_pointID || !context.hasEntity(_pointID)) {\n return addPoint();\n }\n\n timeout(function() {\n reveal('.entity-editor-pane', helpString('intro.points.feature_editor'), {\n tooltipClass: 'intro-points-describe',\n buttonText: t('intro.ok'),\n buttonCallback: function() { continueTo(addName); }\n });\n }, 400);\n\n context.on('exit.intro', function() {\n // if user leaves select mode here, just continue with the tutorial.\n continueTo(reselectPoint);\n });\n\n function continueTo(nextStep) {\n context.on('exit.intro', null);\n nextStep();\n }\n }\n\n\n function addName() {\n if (context.mode().id !== 'select' || !_pointID || !context.hasEntity(_pointID)) {\n return addPoint();\n }\n\n // reset pane, in case user happened to change it..\n context.container().select('.inspector-wrap .panewrap').style('right', '0%');\n\n var addNameString = helpString('intro.points.fields_info') + '{br}' + helpString('intro.points.add_name');\n\n timeout(function() {\n // It's possible for the user to add a name in a previous step..\n // If so, don't tell them to add the name in this step.\n // Give them an OK button instead.\n var entity = context.entity(_pointID);\n if (entity.tags.name) {\n var tooltip = reveal('.entity-editor-pane', addNameString, {\n tooltipClass: 'intro-points-describe',\n buttonText: t('intro.ok'),\n buttonCallback: function() { continueTo(addCloseEditor); }\n });\n tooltip.select('.instruction').style('display', 'none');\n\n } else {\n reveal('.entity-editor-pane', addNameString,\n { tooltipClass: 'intro-points-describe' }\n );\n }\n }, 400);\n\n context.history().on('change.intro', function() {\n continueTo(addCloseEditor);\n });\n\n context.on('exit.intro', function() {\n // if user leaves select mode here, just continue with the tutorial.\n continueTo(reselectPoint);\n });\n\n function continueTo(nextStep) {\n context.on('exit.intro', null);\n context.history().on('change.intro', null);\n nextStep();\n }\n }\n\n\n function addCloseEditor() {\n // reset pane, in case user happened to change it..\n context.container().select('.inspector-wrap .panewrap').style('right', '0%');\n\n var selector = '.entity-editor-pane button.close svg use';\n var href = d3_select(selector).attr('href') || '#iD-icon-close';\n\n context.on('exit.intro', function() {\n continueTo(reselectPoint);\n });\n\n reveal('.entity-editor-pane',\n helpString('intro.points.add_close', { button: icon(href, 'pre-text') })\n );\n\n function continueTo(nextStep) {\n context.on('exit.intro', null);\n nextStep();\n }\n }\n\n\n function reselectPoint() {\n if (!_pointID) return chapter.restart();\n var entity = context.hasEntity(_pointID);\n if (!entity) return chapter.restart();\n\n // make sure it's still a cafe, in case user somehow changed it..\n var oldPreset = presetManager.match(entity, context.graph());\n context.replace(actionChangePreset(_pointID, oldPreset, cafePreset));\n\n context.enter(modeBrowse(context));\n\n var msec = transitionTime(entity.loc, context.map().center());\n if (msec) { reveal(null, null, { duration: 0 }); }\n context.map().centerEase(entity.loc, msec);\n\n timeout(function() {\n var box = pointBox(entity.loc, context);\n reveal(box, helpString('intro.points.reselect'), { duration: 600 });\n\n timeout(function() {\n context.map().on('move.intro drawn.intro', function() {\n var entity = context.hasEntity(_pointID);\n if (!entity) return chapter.restart();\n var box = pointBox(entity.loc, context);\n reveal(box, helpString('intro.points.reselect'), { duration: 0 });\n });\n }, 600); // after reveal..\n\n context.on('enter.intro', function(mode) {\n if (mode.id !== 'select') return;\n continueTo(updatePoint);\n });\n\n }, msec + 100);\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.on('enter.intro', null);\n nextStep();\n }\n }\n\n\n function updatePoint() {\n if (context.mode().id !== 'select' || !_pointID || !context.hasEntity(_pointID)) {\n return continueTo(reselectPoint);\n }\n\n // reset pane, in case user happened to untag the point..\n context.container().select('.inspector-wrap .panewrap').style('right', '0%');\n\n context.on('exit.intro', function() {\n continueTo(reselectPoint);\n });\n\n context.history().on('change.intro', function() {\n continueTo(updateCloseEditor);\n });\n\n timeout(function() {\n reveal('.entity-editor-pane', helpString('intro.points.update'),\n { tooltipClass: 'intro-points-describe' }\n );\n }, 400);\n\n function continueTo(nextStep) {\n context.on('exit.intro', null);\n context.history().on('change.intro', null);\n nextStep();\n }\n }\n\n\n function updateCloseEditor() {\n if (context.mode().id !== 'select' || !_pointID || !context.hasEntity(_pointID)) {\n return continueTo(reselectPoint);\n }\n\n // reset pane, in case user happened to change it..\n context.container().select('.inspector-wrap .panewrap').style('right', '0%');\n\n context.on('exit.intro', function() {\n continueTo(rightClickPoint);\n });\n\n timeout(function() {\n reveal('.entity-editor-pane',\n helpString('intro.points.update_close', { button: icon('#iD-icon-close', 'pre-text') })\n );\n }, 500);\n\n function continueTo(nextStep) {\n context.on('exit.intro', null);\n nextStep();\n }\n }\n\n\n function rightClickPoint() {\n if (!_pointID) return chapter.restart();\n var entity = context.hasEntity(_pointID);\n if (!entity) return chapter.restart();\n\n context.enter(modeBrowse(context));\n\n var box = pointBox(entity.loc, context);\n var textId = context.lastPointerType() === 'mouse' ? 'rightclick' : 'edit_menu_touch';\n reveal(box, helpString('intro.points.' + textId), { duration: 600 });\n\n timeout(function() {\n context.map().on('move.intro', function() {\n var entity = context.hasEntity(_pointID);\n if (!entity) return chapter.restart();\n var box = pointBox(entity.loc, context);\n reveal(box, helpString('intro.points.' + textId), { duration: 0 });\n });\n }, 600); // after reveal\n\n context.on('enter.intro', function(mode) {\n if (mode.id !== 'select') return;\n var ids = context.selectedIDs();\n if (ids.length !== 1 || ids[0] !== _pointID) return;\n\n timeout(function() {\n var node = selectMenuItem(context, 'delete').node();\n if (!node) return;\n continueTo(enterDelete);\n }, 50); // after menu visible\n });\n\n function continueTo(nextStep) {\n context.on('enter.intro', null);\n context.map().on('move.intro', null);\n nextStep();\n }\n }\n\n\n function enterDelete() {\n if (!_pointID) return chapter.restart();\n var entity = context.hasEntity(_pointID);\n if (!entity) return chapter.restart();\n\n var node = selectMenuItem(context, 'delete').node();\n if (!node) { return continueTo(rightClickPoint); }\n\n reveal('.edit-menu',\n helpString('intro.points.delete'),\n { padding: 50 }\n );\n\n timeout(function() {\n context.map().on('move.intro', function() {\n reveal('.edit-menu',\n helpString('intro.points.delete'),\n { duration: 0, padding: 50 }\n );\n });\n }, 300); // after menu visible\n\n context.on('exit.intro', function() {\n if (!_pointID) return chapter.restart();\n var entity = context.hasEntity(_pointID);\n if (entity) return continueTo(rightClickPoint); // point still exists\n });\n\n context.history().on('change.intro', function(changed) {\n if (changed.deleted().length) {\n continueTo(undo);\n }\n });\n\n function continueTo(nextStep) {\n context.map().on('move.intro', null);\n context.history().on('change.intro', null);\n context.on('exit.intro', null);\n nextStep();\n }\n }\n\n\n function undo() {\n context.history().on('change.intro', function() {\n continueTo(play);\n });\n\n reveal('.top-toolbar button.undo-button',\n helpString('intro.points.undo')\n );\n\n function continueTo(nextStep) {\n context.history().on('change.intro', null);\n nextStep();\n }\n }\n\n\n function play() {\n dispatch.call('done');\n reveal('.ideditor',\n helpString('intro.points.play', { next: t('intro.areas.title') }), {\n tooltipBox: '.intro-nav-wrap .chapter-area',\n buttonText: t('intro.ok'),\n buttonCallback: function() { reveal('.ideditor'); }\n }\n );\n }\n\n\n chapter.enter = function() {\n addPoint();\n };\n\n\n chapter.exit = function() {\n timeouts.forEach(window.clearTimeout);\n context.on('enter.intro exit.intro', null);\n context.map().on('move.intro drawn.intro', null);\n context.history().on('change.intro', null);\n context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);\n context.container().select('.preset-search-input').on('keydown.intro keyup.intro', null);\n };\n\n\n chapter.restart = function() {\n chapter.exit();\n chapter.enter();\n };\n\n\n return utilRebind(chapter, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\n\nimport {\n event as d3_event\n} from 'd3-selection';\n\nimport {\n interpolateNumber as d3_interpolateNumber\n} from 'd3-interpolate';\n\nimport { presetManager } from '../../presets';\nimport { t } from '../../core/localizer';\nimport { modeBrowse } from '../../modes/browse';\nimport { modeSelect } from '../../modes/select';\nimport { utilRebind } from '../../util/rebind';\nimport { helpString, icon, pad, transitionTime } from './helper';\n\n\nexport function uiIntroArea(context, reveal) {\n var dispatch = d3_dispatch('done');\n var playground = [-85.63552, 41.94159];\n var playgroundPreset = presetManager.item('leisure/playground');\n var nameField = presetManager.field('name');\n var descriptionField = presetManager.field('description');\n var timeouts = [];\n var _areaID;\n\n\n var chapter = {\n title: 'intro.areas.title'\n };\n\n\n function timeout(f, t) {\n timeouts.push(window.setTimeout(f, t));\n }\n\n\n function eventCancel() {\n d3_event.stopPropagation();\n d3_event.preventDefault();\n }\n\n\n function revealPlayground(center, text, options) {\n var padding = 180 * Math.pow(2, context.map().zoom() - 19.5);\n var box = pad(center, padding, context);\n reveal(box, text, options);\n }\n\n\n function addArea() {\n context.enter(modeBrowse(context));\n context.history().reset('initial');\n _areaID = null;\n\n var msec = transitionTime(playground, context.map().center());\n if (msec) { reveal(null, null, { duration: 0 }); }\n context.map().centerZoomEase(playground, 19, msec);\n\n timeout(function() {\n var tooltip = reveal('button.add-area',\n helpString('intro.areas.add_playground'));\n\n tooltip.selectAll('.popover-inner')\n .insert('svg', 'span')\n .attr('class', 'tooltip-illustration')\n .append('use')\n .attr('xlink:href', '#iD-graphic-areas');\n\n context.on('enter.intro', function(mode) {\n if (mode.id !== 'add-area') return;\n continueTo(startPlayground);\n });\n }, msec + 100);\n\n function continueTo(nextStep) {\n context.on('enter.intro', null);\n nextStep();\n }\n }\n\n\n function startPlayground() {\n if (context.mode().id !== 'add-area') {\n return chapter.restart();\n }\n\n _areaID = null;\n context.map().zoomEase(19.5, 500);\n\n timeout(function() {\n var textId = context.lastPointerType() === 'mouse' ? 'starting_node_click' : 'starting_node_tap';\n var startDrawString = helpString('intro.areas.start_playground') + helpString('intro.areas.' + textId);\n revealPlayground(playground,\n startDrawString, { duration: 250 }\n );\n\n timeout(function() {\n context.map().on('move.intro drawn.intro', function() {\n revealPlayground(playground,\n startDrawString, { duration: 0 }\n );\n });\n context.on('enter.intro', function(mode) {\n if (mode.id !== 'draw-area') return chapter.restart();\n continueTo(continuePlayground);\n });\n }, 250); // after reveal\n\n }, 550); // after easing\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.on('enter.intro', null);\n nextStep();\n }\n }\n\n\n function continuePlayground() {\n if (context.mode().id !== 'draw-area') {\n return chapter.restart();\n }\n\n _areaID = null;\n revealPlayground(playground,\n helpString('intro.areas.continue_playground'),\n { duration: 250 }\n );\n\n timeout(function() {\n context.map().on('move.intro drawn.intro', function() {\n revealPlayground(playground,\n helpString('intro.areas.continue_playground'),\n { duration: 0 }\n );\n });\n }, 250); // after reveal\n\n context.on('enter.intro', function(mode) {\n if (mode.id === 'draw-area') {\n var entity = context.hasEntity(context.selectedIDs()[0]);\n if (entity && entity.nodes.length >= 6) {\n return continueTo(finishPlayground);\n } else {\n return;\n }\n } else if (mode.id === 'select') {\n _areaID = context.selectedIDs()[0];\n return continueTo(searchPresets);\n } else {\n return chapter.restart();\n }\n });\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.on('enter.intro', null);\n nextStep();\n }\n }\n\n\n function finishPlayground() {\n if (context.mode().id !== 'draw-area') {\n return chapter.restart();\n }\n\n _areaID = null;\n\n var finishString = helpString('intro.areas.finish_area_' + (context.lastPointerType() === 'mouse' ? 'click' : 'tap')) +\n helpString('intro.areas.finish_playground');\n revealPlayground(playground,\n finishString, { duration: 250 }\n );\n\n timeout(function() {\n context.map().on('move.intro drawn.intro', function() {\n revealPlayground(playground,\n finishString, { duration: 0 }\n );\n });\n }, 250); // after reveal\n\n context.on('enter.intro', function(mode) {\n if (mode.id === 'draw-area') {\n return;\n } else if (mode.id === 'select') {\n _areaID = context.selectedIDs()[0];\n return continueTo(searchPresets);\n } else {\n return chapter.restart();\n }\n });\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.on('enter.intro', null);\n nextStep();\n }\n }\n\n\n function searchPresets() {\n if (!_areaID || !context.hasEntity(_areaID)) {\n return addArea();\n }\n var ids = context.selectedIDs();\n if (context.mode().id !== 'select' || !ids.length || ids[0] !== _areaID) {\n context.enter(modeSelect(context, [_areaID]));\n }\n\n // disallow scrolling\n context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);\n\n timeout(function() {\n // reset pane, in case user somehow happened to change it..\n context.container().select('.inspector-wrap .panewrap').style('right', '-100%');\n\n context.container().select('.preset-search-input')\n .on('keydown.intro', null)\n .on('keyup.intro', checkPresetSearch);\n\n reveal('.preset-search-input',\n helpString('intro.areas.search_playground', { preset: playgroundPreset.name() })\n );\n }, 400); // after preset list pane visible..\n\n context.on('enter.intro', function(mode) {\n if (!_areaID || !context.hasEntity(_areaID)) {\n return continueTo(addArea);\n }\n\n var ids = context.selectedIDs();\n if (mode.id !== 'select' || !ids.length || ids[0] !== _areaID) {\n // keep the user's area selected..\n context.enter(modeSelect(context, [_areaID]));\n\n // reset pane, in case user somehow happened to change it..\n context.container().select('.inspector-wrap .panewrap').style('right', '-100%');\n // disallow scrolling\n context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);\n\n context.container().select('.preset-search-input')\n .on('keydown.intro', null)\n .on('keyup.intro', checkPresetSearch);\n\n reveal('.preset-search-input',\n helpString('intro.areas.search_playground', { preset: playgroundPreset.name() })\n );\n\n context.history().on('change.intro', null);\n }\n });\n\n function checkPresetSearch() {\n var first = context.container().select('.preset-list-item:first-child');\n\n if (first.classed('preset-leisure-playground')) {\n reveal(first.select('.preset-list-button').node(),\n helpString('intro.areas.choose_playground', { preset: playgroundPreset.name() }),\n { duration: 300 }\n );\n\n context.container().select('.preset-search-input')\n .on('keydown.intro', eventCancel, true)\n .on('keyup.intro', null);\n\n context.history().on('change.intro', function() {\n continueTo(clickAddField);\n });\n }\n }\n\n function continueTo(nextStep) {\n context.container().select('.inspector-wrap').on('wheel.intro', null);\n context.on('enter.intro', null);\n context.history().on('change.intro', null);\n context.container().select('.preset-search-input').on('keydown.intro keyup.intro', null);\n nextStep();\n }\n }\n\n\n function clickAddField() {\n if (!_areaID || !context.hasEntity(_areaID)) {\n return addArea();\n }\n var ids = context.selectedIDs();\n if (context.mode().id !== 'select' || !ids.length || ids[0] !== _areaID) {\n return searchPresets();\n }\n\n if (!context.container().select('.form-field-description').empty()) {\n return continueTo(describePlayground);\n }\n\n // disallow scrolling\n context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);\n\n timeout(function() {\n // reset pane, in case user somehow happened to change it..\n context.container().select('.inspector-wrap .panewrap').style('right', '0%');\n\n // It's possible for the user to add a description in a previous step..\n // If they did this already, just continue to next step.\n var entity = context.entity(_areaID);\n if (entity.tags.description) {\n return continueTo(play);\n }\n\n // scroll \"Add field\" into view\n var box = context.container().select('.more-fields').node().getBoundingClientRect();\n if (box.top > 300) {\n var pane = context.container().select('.entity-editor-pane .inspector-body');\n var start = pane.node().scrollTop;\n var end = start + (box.top - 300);\n\n pane\n .transition()\n .duration(250)\n .tween('scroll.inspector', function() {\n var node = this;\n var i = d3_interpolateNumber(start, end);\n return function(t) {\n node.scrollTop = i(t);\n };\n });\n }\n\n timeout(function() {\n reveal('.more-fields .combobox-input',\n helpString('intro.areas.add_field', {\n name: nameField.label(),\n description: descriptionField.label()\n }),\n { duration: 300 }\n );\n\n context.container().select('.more-fields .combobox-input')\n .on('click.intro', function() {\n // Watch for the combobox to appear...\n var watcher;\n watcher = window.setInterval(function() {\n if (!context.container().select('div.combobox').empty()) {\n window.clearInterval(watcher);\n continueTo(chooseDescriptionField);\n }\n }, 300);\n });\n }, 300); // after \"Add Field\" visible\n\n }, 400); // after editor pane visible\n\n context.on('exit.intro', function() {\n return continueTo(searchPresets);\n });\n\n function continueTo(nextStep) {\n context.container().select('.inspector-wrap').on('wheel.intro', null);\n context.container().select('.more-fields .combobox-input').on('click.intro', null);\n context.on('exit.intro', null);\n nextStep();\n }\n }\n\n\n function chooseDescriptionField() {\n if (!_areaID || !context.hasEntity(_areaID)) {\n return addArea();\n }\n var ids = context.selectedIDs();\n if (context.mode().id !== 'select' || !ids.length || ids[0] !== _areaID) {\n return searchPresets();\n }\n\n if (!context.container().select('.form-field-description').empty()) {\n return continueTo(describePlayground);\n }\n\n // Make sure combobox is ready..\n if (context.container().select('div.combobox').empty()) {\n return continueTo(clickAddField);\n }\n // Watch for the combobox to go away..\n var watcher;\n watcher = window.setInterval(function() {\n if (context.container().select('div.combobox').empty()) {\n window.clearInterval(watcher);\n timeout(function() {\n if (context.container().select('.form-field-description').empty()) {\n continueTo(retryChooseDescription);\n } else {\n continueTo(describePlayground);\n }\n }, 300); // after description field added.\n }\n }, 300);\n\n reveal('div.combobox',\n helpString('intro.areas.choose_field', { field: descriptionField.label() }),\n { duration: 300 }\n );\n\n context.on('exit.intro', function() {\n return continueTo(searchPresets);\n });\n\n function continueTo(nextStep) {\n if (watcher) window.clearInterval(watcher);\n context.on('exit.intro', null);\n nextStep();\n }\n }\n\n\n function describePlayground() {\n if (!_areaID || !context.hasEntity(_areaID)) {\n return addArea();\n }\n var ids = context.selectedIDs();\n if (context.mode().id !== 'select' || !ids.length || ids[0] !== _areaID) {\n return searchPresets();\n }\n\n // reset pane, in case user happened to change it..\n context.container().select('.inspector-wrap .panewrap').style('right', '0%');\n\n if (context.container().select('.form-field-description').empty()) {\n return continueTo(retryChooseDescription);\n }\n\n context.on('exit.intro', function() {\n continueTo(play);\n });\n\n reveal('.entity-editor-pane',\n helpString('intro.areas.describe_playground', { button: icon('#iD-icon-close', 'pre-text') }),\n { duration: 300 }\n );\n\n function continueTo(nextStep) {\n context.on('exit.intro', null);\n nextStep();\n }\n }\n\n\n function retryChooseDescription() {\n if (!_areaID || !context.hasEntity(_areaID)) {\n return addArea();\n }\n var ids = context.selectedIDs();\n if (context.mode().id !== 'select' || !ids.length || ids[0] !== _areaID) {\n return searchPresets();\n }\n\n // reset pane, in case user happened to change it..\n context.container().select('.inspector-wrap .panewrap').style('right', '0%');\n\n reveal('.entity-editor-pane',\n helpString('intro.areas.retry_add_field', { field: descriptionField.label() }), {\n buttonText: t('intro.ok'),\n buttonCallback: function() { continueTo(clickAddField); }\n });\n\n context.on('exit.intro', function() {\n return continueTo(searchPresets);\n });\n\n function continueTo(nextStep) {\n context.on('exit.intro', null);\n nextStep();\n }\n }\n\n\n function play() {\n dispatch.call('done');\n reveal('.ideditor',\n helpString('intro.areas.play', { next: t('intro.lines.title') }), {\n tooltipBox: '.intro-nav-wrap .chapter-line',\n buttonText: t('intro.ok'),\n buttonCallback: function() { reveal('.ideditor'); }\n }\n );\n }\n\n\n chapter.enter = function() {\n addArea();\n };\n\n\n chapter.exit = function() {\n timeouts.forEach(window.clearTimeout);\n context.on('enter.intro exit.intro', null);\n context.map().on('move.intro drawn.intro', null);\n context.history().on('change.intro', null);\n context.container().select('.inspector-wrap').on('wheel.intro', null);\n context.container().select('.preset-search-input').on('keydown.intro keyup.intro', null);\n context.container().select('.more-fields .combobox-input').on('click.intro', null);\n };\n\n\n chapter.restart = function() {\n chapter.exit();\n chapter.enter();\n };\n\n\n return utilRebind(chapter, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\n\nimport {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { presetManager } from '../../presets';\nimport { t } from '../../core/localizer';\nimport { geoSphericalDistance } from '../../geo';\nimport { modeBrowse } from '../../modes/browse';\nimport { modeSelect } from '../../modes/select';\nimport { utilRebind } from '../../util/rebind';\nimport { helpString, icon, pad, selectMenuItem, transitionTime } from './helper';\n\n\nexport function uiIntroLine(context, reveal) {\n var dispatch = d3_dispatch('done');\n var timeouts = [];\n var _tulipRoadID = null;\n var flowerRoadID = 'w646';\n var tulipRoadStart = [-85.6297754121684, 41.95805253325314];\n var tulipRoadMidpoint = [-85.62975395449628, 41.95787501510204];\n var tulipRoadIntersection = [-85.62974496187628, 41.95742515554585];\n var roadCategory = presetManager.item('category-road_minor');\n var residentialPreset = presetManager.item('highway/residential');\n var woodRoadID = 'w525';\n var woodRoadEndID = 'n2862';\n var woodRoadAddNode = [-85.62390110349587, 41.95397111462291];\n var woodRoadDragEndpoint = [-85.623867390213, 41.95466987786487];\n var woodRoadDragMidpoint = [-85.62386254803509, 41.95430395953872];\n var washingtonStreetID = 'w522';\n var twelfthAvenueID = 'w1';\n var eleventhAvenueEndID = 'n3550';\n var twelfthAvenueEndID = 'n5';\n var _washingtonSegmentID = null;\n var eleventhAvenueEnd = context.entity(eleventhAvenueEndID).loc;\n var twelfthAvenueEnd = context.entity(twelfthAvenueEndID).loc;\n var deleteLinesLoc = [-85.6219395542764, 41.95228033922477];\n var twelfthAvenue = [-85.62219310052491, 41.952505413152956];\n\n\n var chapter = {\n title: 'intro.lines.title'\n };\n\n\n function timeout(f, t) {\n timeouts.push(window.setTimeout(f, t));\n }\n\n\n function eventCancel() {\n d3_event.stopPropagation();\n d3_event.preventDefault();\n }\n\n\n function addLine() {\n context.enter(modeBrowse(context));\n context.history().reset('initial');\n\n var msec = transitionTime(tulipRoadStart, context.map().center());\n if (msec) { reveal(null, null, { duration: 0 }); }\n context.map().centerZoomEase(tulipRoadStart, 18.5, msec);\n\n timeout(function() {\n var tooltip = reveal('button.add-line',\n helpString('intro.lines.add_line'));\n\n tooltip.selectAll('.popover-inner')\n .insert('svg', 'span')\n .attr('class', 'tooltip-illustration')\n .append('use')\n .attr('xlink:href', '#iD-graphic-lines');\n\n context.on('enter.intro', function(mode) {\n if (mode.id !== 'add-line') return;\n continueTo(startLine);\n });\n }, msec + 100);\n\n function continueTo(nextStep) {\n context.on('enter.intro', null);\n nextStep();\n }\n }\n\n\n function startLine() {\n if (context.mode().id !== 'add-line') return chapter.restart();\n\n _tulipRoadID = null;\n\n var padding = 70 * Math.pow(2, context.map().zoom() - 18);\n var box = pad(tulipRoadStart, padding, context);\n box.height = box.height + 100;\n\n var textId = context.lastPointerType() === 'mouse' ? 'start_line' : 'start_line_tap';\n var startLineString = helpString('intro.lines.missing_road') + '{br}' +\n helpString('intro.lines.line_draw_info') +\n helpString('intro.lines.' + textId);\n reveal(box, startLineString);\n\n context.map().on('move.intro drawn.intro', function() {\n padding = 70 * Math.pow(2, context.map().zoom() - 18);\n box = pad(tulipRoadStart, padding, context);\n box.height = box.height + 100;\n reveal(box, startLineString, { duration: 0 });\n });\n\n context.on('enter.intro', function(mode) {\n if (mode.id !== 'draw-line') return chapter.restart();\n continueTo(drawLine);\n });\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.on('enter.intro', null);\n nextStep();\n }\n }\n\n\n function drawLine() {\n if (context.mode().id !== 'draw-line') return chapter.restart();\n\n _tulipRoadID = context.mode().selectedIDs()[0];\n context.map().centerEase(tulipRoadMidpoint, 500);\n\n timeout(function() {\n var padding = 200 * Math.pow(2, context.map().zoom() - 18.5);\n var box = pad(tulipRoadMidpoint, padding, context);\n box.height = box.height * 2;\n reveal(box,\n helpString('intro.lines.intersect', { name: t('intro.graph.name.flower-street') })\n );\n\n context.map().on('move.intro drawn.intro', function() {\n padding = 200 * Math.pow(2, context.map().zoom() - 18.5);\n box = pad(tulipRoadMidpoint, padding, context);\n box.height = box.height * 2;\n reveal(box,\n helpString('intro.lines.intersect', { name: t('intro.graph.name.flower-street') }),\n { duration: 0 }\n );\n });\n }, 550); // after easing..\n\n context.history().on('change.intro', function() {\n if (isLineConnected()) {\n continueTo(continueLine);\n }\n });\n\n context.on('enter.intro', function(mode) {\n if (mode.id === 'draw-line') {\n return;\n } else if (mode.id === 'select') {\n continueTo(retryIntersect);\n return;\n } else {\n return chapter.restart();\n }\n });\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.history().on('change.intro', null);\n context.on('enter.intro', null);\n nextStep();\n }\n }\n\n\n function isLineConnected() {\n var entity = _tulipRoadID && context.hasEntity(_tulipRoadID);\n if (!entity) return false;\n\n var drawNodes = context.graph().childNodes(entity);\n return drawNodes.some(function(node) {\n return context.graph().parentWays(node).some(function(parent) {\n return parent.id === flowerRoadID;\n });\n });\n }\n\n\n function retryIntersect() {\n d3_select(window).on('pointerdown.intro mousedown.intro', eventCancel, true);\n\n var box = pad(tulipRoadIntersection, 80, context);\n reveal(box,\n helpString('intro.lines.retry_intersect', { name: t('intro.graph.name.flower-street') })\n );\n\n timeout(chapter.restart, 3000);\n }\n\n\n function continueLine() {\n if (context.mode().id !== 'draw-line') return chapter.restart();\n var entity = _tulipRoadID && context.hasEntity(_tulipRoadID);\n if (!entity) return chapter.restart();\n\n context.map().centerEase(tulipRoadIntersection, 500);\n\n var continueLineText = helpString('intro.lines.continue_line') + '{br}' +\n helpString('intro.lines.finish_line_' + (context.lastPointerType() === 'mouse' ? 'click' : 'tap')) +\n helpString('intro.lines.finish_road');\n\n reveal('.surface', continueLineText);\n\n context.on('enter.intro', function(mode) {\n if (mode.id === 'draw-line')\n return;\n else if (mode.id === 'select')\n return continueTo(chooseCategoryRoad);\n else\n return chapter.restart();\n });\n\n function continueTo(nextStep) {\n context.on('enter.intro', null);\n nextStep();\n }\n }\n\n\n function chooseCategoryRoad() {\n if (context.mode().id !== 'select') return chapter.restart();\n\n context.on('exit.intro', function() {\n return chapter.restart();\n });\n\n var button = context.container().select('.preset-category-road_minor .preset-list-button');\n if (button.empty()) return chapter.restart();\n\n // disallow scrolling\n context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);\n\n timeout(function() {\n // reset pane, in case user somehow happened to change it..\n context.container().select('.inspector-wrap .panewrap').style('right', '-100%');\n\n reveal(button.node(),\n helpString('intro.lines.choose_category_road', { category: roadCategory.name() })\n );\n\n button.on('click.intro', function() {\n continueTo(choosePresetResidential);\n });\n\n }, 400); // after editor pane visible\n\n function continueTo(nextStep) {\n context.container().select('.inspector-wrap').on('wheel.intro', null);\n context.container().select('.preset-list-button').on('click.intro', null);\n context.on('exit.intro', null);\n nextStep();\n }\n }\n\n\n function choosePresetResidential() {\n if (context.mode().id !== 'select') return chapter.restart();\n\n context.on('exit.intro', function() {\n return chapter.restart();\n });\n\n var subgrid = context.container().select('.preset-category-road_minor .subgrid');\n if (subgrid.empty()) return chapter.restart();\n\n subgrid.selectAll(':not(.preset-highway-residential) .preset-list-button')\n .on('click.intro', function() {\n continueTo(retryPresetResidential);\n });\n\n subgrid.selectAll('.preset-highway-residential .preset-list-button')\n .on('click.intro', function() {\n continueTo(nameRoad);\n });\n\n timeout(function() {\n reveal(subgrid.node(),\n helpString('intro.lines.choose_preset_residential', { preset: residentialPreset.name() }),\n { tooltipBox: '.preset-highway-residential .preset-list-button', duration: 300 }\n );\n }, 300);\n\n function continueTo(nextStep) {\n context.container().select('.preset-list-button').on('click.intro', null);\n context.on('exit.intro', null);\n nextStep();\n }\n }\n\n\n // selected wrong road type\n function retryPresetResidential() {\n if (context.mode().id !== 'select') return chapter.restart();\n\n context.on('exit.intro', function() {\n return chapter.restart();\n });\n\n // disallow scrolling\n context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);\n\n timeout(function() {\n var button = context.container().select('.entity-editor-pane .preset-list-button');\n\n reveal(button.node(),\n helpString('intro.lines.retry_preset_residential', { preset: residentialPreset.name() })\n );\n\n button.on('click.intro', function() {\n continueTo(chooseCategoryRoad);\n });\n\n }, 500);\n\n function continueTo(nextStep) {\n context.container().select('.inspector-wrap').on('wheel.intro', null);\n context.container().select('.preset-list-button').on('click.intro', null);\n context.on('exit.intro', null);\n nextStep();\n }\n }\n\n\n function nameRoad() {\n context.on('exit.intro', function() {\n continueTo(didNameRoad);\n });\n\n timeout(function() {\n reveal('.entity-editor-pane',\n helpString('intro.lines.name_road', { button: icon('#iD-icon-close', 'pre-text') }),\n { tooltipClass: 'intro-lines-name_road' }\n );\n }, 500);\n\n function continueTo(nextStep) {\n context.on('exit.intro', null);\n nextStep();\n }\n }\n\n\n function didNameRoad() {\n context.history().checkpoint('doneAddLine');\n\n timeout(function() {\n reveal('.surface', helpString('intro.lines.did_name_road'), {\n buttonText: t('intro.ok'),\n buttonCallback: function() { continueTo(updateLine); }\n });\n }, 500);\n\n function continueTo(nextStep) {\n nextStep();\n }\n }\n\n\n function updateLine() {\n context.history().reset('doneAddLine');\n if (!context.hasEntity(woodRoadID) || !context.hasEntity(woodRoadEndID)) {\n return chapter.restart();\n }\n\n var msec = transitionTime(woodRoadDragMidpoint, context.map().center());\n if (msec) { reveal(null, null, { duration: 0 }); }\n context.map().centerZoomEase(woodRoadDragMidpoint, 19, msec);\n\n timeout(function() {\n var padding = 250 * Math.pow(2, context.map().zoom() - 19);\n var box = pad(woodRoadDragMidpoint, padding, context);\n var advance = function() { continueTo(addNode); };\n\n reveal(box, helpString('intro.lines.update_line'),\n { buttonText: t('intro.ok'), buttonCallback: advance }\n );\n\n context.map().on('move.intro drawn.intro', function() {\n var padding = 250 * Math.pow(2, context.map().zoom() - 19);\n var box = pad(woodRoadDragMidpoint, padding, context);\n reveal(box, helpString('intro.lines.update_line'),\n { duration: 0, buttonText: t('intro.ok'), buttonCallback: advance }\n );\n });\n }, msec + 100);\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n nextStep();\n }\n }\n\n\n function addNode() {\n context.history().reset('doneAddLine');\n if (!context.hasEntity(woodRoadID) || !context.hasEntity(woodRoadEndID)) {\n return chapter.restart();\n }\n\n var padding = 40 * Math.pow(2, context.map().zoom() - 19);\n var box = pad(woodRoadAddNode, padding, context);\n var addNodeString = helpString('intro.lines.add_node' + (context.lastPointerType() === 'mouse' ? '' : '_touch'));\n reveal(box, addNodeString);\n\n context.map().on('move.intro drawn.intro', function() {\n var padding = 40 * Math.pow(2, context.map().zoom() - 19);\n var box = pad(woodRoadAddNode, padding, context);\n reveal(box, addNodeString, { duration: 0 });\n });\n\n context.history().on('change.intro', function(changed) {\n if (!context.hasEntity(woodRoadID) || !context.hasEntity(woodRoadEndID)) {\n return continueTo(updateLine);\n }\n if (changed.created().length === 1) {\n timeout(function() { continueTo(startDragEndpoint); }, 500);\n }\n });\n\n context.on('enter.intro', function(mode) {\n if (mode.id !== 'select') {\n continueTo(updateLine);\n }\n });\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.history().on('change.intro', null);\n context.on('enter.intro', null);\n nextStep();\n }\n }\n\n\n function startDragEndpoint() {\n if (!context.hasEntity(woodRoadID) || !context.hasEntity(woodRoadEndID)) {\n return continueTo(updateLine);\n }\n var padding = 100 * Math.pow(2, context.map().zoom() - 19);\n var box = pad(woodRoadDragEndpoint, padding, context);\n var startDragString = helpString('intro.lines.start_drag_endpoint' + (context.lastPointerType() === 'mouse' ? '' : '_touch')) +\n helpString('intro.lines.drag_to_intersection');\n reveal(box, startDragString);\n\n context.map().on('move.intro drawn.intro', function() {\n if (!context.hasEntity(woodRoadID) || !context.hasEntity(woodRoadEndID)) {\n return continueTo(updateLine);\n }\n var padding = 100 * Math.pow(2, context.map().zoom() - 19);\n var box = pad(woodRoadDragEndpoint, padding, context);\n reveal(box, startDragString, { duration: 0 });\n\n var entity = context.entity(woodRoadEndID);\n if (geoSphericalDistance(entity.loc, woodRoadDragEndpoint) <= 4) {\n continueTo(finishDragEndpoint);\n }\n });\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n nextStep();\n }\n }\n\n\n function finishDragEndpoint() {\n if (!context.hasEntity(woodRoadID) || !context.hasEntity(woodRoadEndID)) {\n return continueTo(updateLine);\n }\n\n var padding = 100 * Math.pow(2, context.map().zoom() - 19);\n var box = pad(woodRoadDragEndpoint, padding, context);\n var finishDragString = helpString('intro.lines.spot_looks_good') +\n helpString('intro.lines.finish_drag_endpoint' + (context.lastPointerType() === 'mouse' ? '' : '_touch'));\n reveal(box, finishDragString);\n\n context.map().on('move.intro drawn.intro', function() {\n if (!context.hasEntity(woodRoadID) || !context.hasEntity(woodRoadEndID)) {\n return continueTo(updateLine);\n }\n var padding = 100 * Math.pow(2, context.map().zoom() - 19);\n var box = pad(woodRoadDragEndpoint, padding, context);\n reveal(box, finishDragString, { duration: 0 });\n\n var entity = context.entity(woodRoadEndID);\n if (geoSphericalDistance(entity.loc, woodRoadDragEndpoint) > 4) {\n continueTo(startDragEndpoint);\n }\n });\n\n context.on('enter.intro', function() {\n continueTo(startDragMidpoint);\n });\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.on('enter.intro', null);\n nextStep();\n }\n }\n\n\n function startDragMidpoint() {\n if (!context.hasEntity(woodRoadID) || !context.hasEntity(woodRoadEndID)) {\n return continueTo(updateLine);\n }\n if (context.selectedIDs().indexOf(woodRoadID) === -1) {\n context.enter(modeSelect(context, [woodRoadID]));\n }\n\n var padding = 80 * Math.pow(2, context.map().zoom() - 19);\n var box = pad(woodRoadDragMidpoint, padding, context);\n reveal(box, helpString('intro.lines.start_drag_midpoint'));\n\n context.map().on('move.intro drawn.intro', function() {\n if (!context.hasEntity(woodRoadID) || !context.hasEntity(woodRoadEndID)) {\n return continueTo(updateLine);\n }\n var padding = 80 * Math.pow(2, context.map().zoom() - 19);\n var box = pad(woodRoadDragMidpoint, padding, context);\n reveal(box, helpString('intro.lines.start_drag_midpoint'), { duration: 0 });\n });\n\n context.history().on('change.intro', function(changed) {\n if (changed.created().length === 1) {\n continueTo(continueDragMidpoint);\n }\n });\n\n context.on('enter.intro', function(mode) {\n if (mode.id !== 'select') {\n // keep Wood Road selected so midpoint triangles are drawn..\n context.enter(modeSelect(context, [woodRoadID]));\n }\n });\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.history().on('change.intro', null);\n context.on('enter.intro', null);\n nextStep();\n }\n }\n\n\n function continueDragMidpoint() {\n if (!context.hasEntity(woodRoadID) || !context.hasEntity(woodRoadEndID)) {\n return continueTo(updateLine);\n }\n\n var padding = 100 * Math.pow(2, context.map().zoom() - 19);\n var box = pad(woodRoadDragEndpoint, padding, context);\n box.height += 400;\n\n var advance = function() {\n context.history().checkpoint('doneUpdateLine');\n continueTo(deleteLines);\n };\n\n reveal(box, helpString('intro.lines.continue_drag_midpoint'),\n { buttonText: t('intro.ok'), buttonCallback: advance }\n );\n\n context.map().on('move.intro drawn.intro', function() {\n if (!context.hasEntity(woodRoadID) || !context.hasEntity(woodRoadEndID)) {\n return continueTo(updateLine);\n }\n var padding = 100 * Math.pow(2, context.map().zoom() - 19);\n var box = pad(woodRoadDragEndpoint, padding, context);\n box.height += 400;\n reveal(box, helpString('intro.lines.continue_drag_midpoint'),\n { duration: 0, buttonText: t('intro.ok'), buttonCallback: advance }\n );\n });\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n nextStep();\n }\n }\n\n\n function deleteLines() {\n context.history().reset('doneUpdateLine');\n context.enter(modeBrowse(context));\n\n if (!context.hasEntity(washingtonStreetID) ||\n !context.hasEntity(twelfthAvenueID) ||\n !context.hasEntity(eleventhAvenueEndID)) {\n return chapter.restart();\n }\n\n var msec = transitionTime(deleteLinesLoc, context.map().center());\n if (msec) { reveal(null, null, { duration: 0 }); }\n context.map().centerZoomEase(deleteLinesLoc, 18, msec);\n\n timeout(function() {\n var padding = 200 * Math.pow(2, context.map().zoom() - 18);\n var box = pad(deleteLinesLoc, padding, context);\n box.top -= 200;\n box.height += 400;\n var advance = function() { continueTo(rightClickIntersection); };\n\n reveal(box, helpString('intro.lines.delete_lines', { street: t('intro.graph.name.12th-avenue') }),\n { buttonText: t('intro.ok'), buttonCallback: advance }\n );\n\n context.map().on('move.intro drawn.intro', function() {\n var padding = 200 * Math.pow(2, context.map().zoom() - 18);\n var box = pad(deleteLinesLoc, padding, context);\n box.top -= 200;\n box.height += 400;\n reveal(box, helpString('intro.lines.delete_lines', { street: t('intro.graph.name.12th-avenue') }),\n { duration: 0, buttonText: t('intro.ok'), buttonCallback: advance }\n );\n });\n\n context.history().on('change.intro', function() {\n timeout(function() {\n continueTo(deleteLines);\n }, 500); // after any transition (e.g. if user deleted intersection)\n });\n\n }, msec + 100);\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.history().on('change.intro', null);\n nextStep();\n }\n }\n\n\n function rightClickIntersection() {\n context.history().reset('doneUpdateLine');\n context.enter(modeBrowse(context));\n\n context.map().centerZoomEase(eleventhAvenueEnd, 18, 500);\n\n var rightClickString = helpString('intro.lines.split_street', {\n street1: t('intro.graph.name.11th-avenue'),\n street2: t('intro.graph.name.washington-street')\n }) +\n helpString('intro.lines.' + (context.lastPointerType() === 'mouse' ? 'rightclick_intersection' : 'edit_menu_intersection_touch'));\n\n timeout(function() {\n var padding = 60 * Math.pow(2, context.map().zoom() - 18);\n var box = pad(eleventhAvenueEnd, padding, context);\n reveal(box, rightClickString);\n\n context.map().on('move.intro drawn.intro', function() {\n var padding = 60 * Math.pow(2, context.map().zoom() - 18);\n var box = pad(eleventhAvenueEnd, padding, context);\n reveal(box, rightClickString,\n { duration: 0 }\n );\n });\n\n context.on('enter.intro', function(mode) {\n if (mode.id !== 'select') return;\n var ids = context.selectedIDs();\n if (ids.length !== 1 || ids[0] !== eleventhAvenueEndID) return;\n\n timeout(function() {\n var node = selectMenuItem(context, 'split').node();\n if (!node) return;\n continueTo(splitIntersection);\n }, 50); // after menu visible\n });\n\n context.history().on('change.intro', function() {\n timeout(function() {\n continueTo(deleteLines);\n }, 300); // after any transition (e.g. if user deleted intersection)\n });\n\n }, 600);\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.on('enter.intro', null);\n context.history().on('change.intro', null);\n nextStep();\n }\n }\n\n\n function splitIntersection() {\n if (!context.hasEntity(washingtonStreetID) ||\n !context.hasEntity(twelfthAvenueID) ||\n !context.hasEntity(eleventhAvenueEndID)) {\n return continueTo(deleteLines);\n }\n\n var node = selectMenuItem(context, 'split').node();\n if (!node) { return continueTo(rightClickIntersection); }\n\n var wasChanged = false;\n _washingtonSegmentID = null;\n\n reveal('.edit-menu', helpString('intro.lines.split_intersection',\n { street: t('intro.graph.name.washington-street') }),\n { padding: 50 }\n );\n\n context.map().on('move.intro drawn.intro', function() {\n var node = selectMenuItem(context, 'split').node();\n if (!wasChanged && !node) { return continueTo(rightClickIntersection); }\n\n reveal('.edit-menu', helpString('intro.lines.split_intersection',\n { street: t('intro.graph.name.washington-street') }),\n { duration: 0, padding: 50 }\n );\n });\n\n context.history().on('change.intro', function(changed) {\n wasChanged = true;\n timeout(function() {\n if (context.history().undoAnnotation() === t('operations.split.annotation.line')) {\n _washingtonSegmentID = changed.created()[0].id;\n continueTo(didSplit);\n } else {\n _washingtonSegmentID = null;\n continueTo(retrySplit);\n }\n }, 300); // after any transition (e.g. if user deleted intersection)\n });\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.history().on('change.intro', null);\n nextStep();\n }\n }\n\n\n function retrySplit() {\n context.enter(modeBrowse(context));\n context.map().centerZoomEase(eleventhAvenueEnd, 18, 500);\n var advance = function() { continueTo(rightClickIntersection); };\n\n var padding = 60 * Math.pow(2, context.map().zoom() - 18);\n var box = pad(eleventhAvenueEnd, padding, context);\n reveal(box, helpString('intro.lines.retry_split'),\n { buttonText: t('intro.ok'), buttonCallback: advance }\n );\n\n context.map().on('move.intro drawn.intro', function() {\n var padding = 60 * Math.pow(2, context.map().zoom() - 18);\n var box = pad(eleventhAvenueEnd, padding, context);\n reveal(box, helpString('intro.lines.retry_split'),\n { duration: 0, buttonText: t('intro.ok'), buttonCallback: advance }\n );\n });\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n nextStep();\n }\n }\n\n\n function didSplit() {\n if (!_washingtonSegmentID ||\n !context.hasEntity(_washingtonSegmentID) ||\n !context.hasEntity(washingtonStreetID) ||\n !context.hasEntity(twelfthAvenueID) ||\n !context.hasEntity(eleventhAvenueEndID)) {\n return continueTo(rightClickIntersection);\n }\n\n var ids = context.selectedIDs();\n var string = 'intro.lines.did_split_' + (ids.length > 1 ? 'multi' : 'single');\n var street = t('intro.graph.name.washington-street');\n\n var padding = 200 * Math.pow(2, context.map().zoom() - 18);\n var box = pad(twelfthAvenue, padding, context);\n box.width = box.width / 2;\n reveal(box, helpString(string, { street1: street, street2: street }),\n { duration: 500 }\n );\n\n timeout(function() {\n context.map().centerZoomEase(twelfthAvenue, 18, 500);\n\n context.map().on('move.intro drawn.intro', function() {\n var padding = 200 * Math.pow(2, context.map().zoom() - 18);\n var box = pad(twelfthAvenue, padding, context);\n box.width = box.width / 2;\n reveal(box, helpString(string, { street1: street, street2: street }),\n { duration: 0 }\n );\n });\n }, 600); // after initial reveal and curtain cut\n\n context.on('enter.intro', function() {\n var ids = context.selectedIDs();\n if (ids.length === 1 && ids[0] === _washingtonSegmentID) {\n continueTo(multiSelect);\n }\n });\n\n context.history().on('change.intro', function() {\n if (!_washingtonSegmentID ||\n !context.hasEntity(_washingtonSegmentID) ||\n !context.hasEntity(washingtonStreetID) ||\n !context.hasEntity(twelfthAvenueID) ||\n !context.hasEntity(eleventhAvenueEndID)) {\n return continueTo(rightClickIntersection);\n }\n });\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.on('enter.intro', null);\n context.history().on('change.intro', null);\n nextStep();\n }\n }\n\n\n function multiSelect() {\n if (!_washingtonSegmentID ||\n !context.hasEntity(_washingtonSegmentID) ||\n !context.hasEntity(washingtonStreetID) ||\n !context.hasEntity(twelfthAvenueID) ||\n !context.hasEntity(eleventhAvenueEndID)) {\n return continueTo(rightClickIntersection);\n }\n\n var ids = context.selectedIDs();\n var hasWashington = ids.indexOf(_washingtonSegmentID) !== -1;\n var hasTwelfth = ids.indexOf(twelfthAvenueID) !== -1;\n\n if (hasWashington && hasTwelfth) {\n return continueTo(multiRightClick);\n } else if (!hasWashington && !hasTwelfth) {\n return continueTo(didSplit);\n }\n\n context.map().centerZoomEase(twelfthAvenue, 18, 500);\n\n timeout(function() {\n var selected, other, padding, box;\n if (hasWashington) {\n selected = t('intro.graph.name.washington-street');\n other = t('intro.graph.name.12th-avenue');\n padding = 60 * Math.pow(2, context.map().zoom() - 18);\n box = pad(twelfthAvenueEnd, padding, context);\n box.width *= 3;\n } else {\n selected = t('intro.graph.name.12th-avenue');\n other = t('intro.graph.name.washington-street');\n padding = 200 * Math.pow(2, context.map().zoom() - 18);\n box = pad(twelfthAvenue, padding, context);\n box.width /= 2;\n }\n\n reveal(box,\n helpString('intro.lines.multi_select',\n { selected: selected, other1: other }) + ' ' +\n helpString('intro.lines.add_to_selection_' + (context.lastPointerType() === 'mouse' ? 'click' : 'touch'),\n { selected: selected, other2: other })\n );\n\n context.map().on('move.intro drawn.intro', function() {\n if (hasWashington) {\n selected = t('intro.graph.name.washington-street');\n other = t('intro.graph.name.12th-avenue');\n padding = 60 * Math.pow(2, context.map().zoom() - 18);\n box = pad(twelfthAvenueEnd, padding, context);\n box.width *= 3;\n } else {\n selected = t('intro.graph.name.12th-avenue');\n other = t('intro.graph.name.washington-street');\n padding = 200 * Math.pow(2, context.map().zoom() - 18);\n box = pad(twelfthAvenue, padding, context);\n box.width /= 2;\n }\n\n reveal(box,\n helpString('intro.lines.multi_select',\n { selected: selected, other1: other }) + ' ' +\n helpString('intro.lines.add_to_selection_' + (context.lastPointerType() === 'mouse' ? 'click' : 'touch'),\n { selected: selected, other2: other }),\n { duration: 0 }\n );\n });\n\n context.on('enter.intro', function() {\n continueTo(multiSelect);\n });\n\n context.history().on('change.intro', function() {\n if (!_washingtonSegmentID ||\n !context.hasEntity(_washingtonSegmentID) ||\n !context.hasEntity(washingtonStreetID) ||\n !context.hasEntity(twelfthAvenueID) ||\n !context.hasEntity(eleventhAvenueEndID)) {\n return continueTo(rightClickIntersection);\n }\n });\n }, 600);\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.on('enter.intro', null);\n context.history().on('change.intro', null);\n nextStep();\n }\n }\n\n\n function multiRightClick() {\n if (!_washingtonSegmentID ||\n !context.hasEntity(_washingtonSegmentID) ||\n !context.hasEntity(washingtonStreetID) ||\n !context.hasEntity(twelfthAvenueID) ||\n !context.hasEntity(eleventhAvenueEndID)) {\n return continueTo(rightClickIntersection);\n }\n\n var padding = 200 * Math.pow(2, context.map().zoom() - 18);\n var box = pad(twelfthAvenue, padding, context);\n\n var rightClickString = helpString('intro.lines.multi_select_success') +\n helpString('intro.lines.multi_' + (context.lastPointerType() === 'mouse' ? 'rightclick' : 'edit_menu_touch'));\n reveal(box, rightClickString);\n\n context.map().on('move.intro drawn.intro', function() {\n var padding = 200 * Math.pow(2, context.map().zoom() - 18);\n var box = pad(twelfthAvenue, padding, context);\n reveal(box, rightClickString, { duration: 0 });\n });\n\n context.ui().editMenu().on('toggled.intro', function(open) {\n if (!open) return;\n\n timeout(function() {\n var ids = context.selectedIDs();\n if (ids.length === 2 &&\n ids.indexOf(twelfthAvenueID) !== -1 &&\n ids.indexOf(_washingtonSegmentID) !== -1) {\n var node = selectMenuItem(context, 'delete').node();\n if (!node) return;\n continueTo(multiDelete);\n } else if (ids.length === 1 &&\n ids.indexOf(_washingtonSegmentID) !== -1) {\n return continueTo(multiSelect);\n } else {\n return continueTo(didSplit);\n }\n }, 300); // after edit menu visible\n });\n\n context.history().on('change.intro', function() {\n if (!_washingtonSegmentID ||\n !context.hasEntity(_washingtonSegmentID) ||\n !context.hasEntity(washingtonStreetID) ||\n !context.hasEntity(twelfthAvenueID) ||\n !context.hasEntity(eleventhAvenueEndID)) {\n return continueTo(rightClickIntersection);\n }\n });\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.ui().editMenu().on('toggled.intro', null);\n context.history().on('change.intro', null);\n nextStep();\n }\n }\n\n\n function multiDelete() {\n if (!_washingtonSegmentID ||\n !context.hasEntity(_washingtonSegmentID) ||\n !context.hasEntity(washingtonStreetID) ||\n !context.hasEntity(twelfthAvenueID) ||\n !context.hasEntity(eleventhAvenueEndID)) {\n return continueTo(rightClickIntersection);\n }\n\n var node = selectMenuItem(context, 'delete').node();\n if (!node) return continueTo(multiRightClick);\n\n reveal('.edit-menu',\n helpString('intro.lines.multi_delete'),\n { padding: 50 }\n );\n\n context.map().on('move.intro drawn.intro', function() {\n reveal('.edit-menu',\n helpString('intro.lines.multi_delete'),\n { duration: 0, padding: 50 }\n );\n });\n\n context.on('exit.intro', function() {\n if (context.hasEntity(_washingtonSegmentID) || context.hasEntity(twelfthAvenueID)) {\n return continueTo(multiSelect); // left select mode but roads still exist\n }\n });\n\n context.history().on('change.intro', function() {\n if (context.hasEntity(_washingtonSegmentID) || context.hasEntity(twelfthAvenueID)) {\n continueTo(retryDelete); // changed something but roads still exist\n } else {\n continueTo(play);\n }\n });\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.on('exit.intro', null);\n context.history().on('change.intro', null);\n nextStep();\n }\n }\n\n\n function retryDelete() {\n context.enter(modeBrowse(context));\n\n var padding = 200 * Math.pow(2, context.map().zoom() - 18);\n var box = pad(twelfthAvenue, padding, context);\n reveal(box, helpString('intro.lines.retry_delete'), {\n buttonText: t('intro.ok'),\n buttonCallback: function() { continueTo(multiSelect); }\n });\n\n function continueTo(nextStep) {\n nextStep();\n }\n }\n\n\n function play() {\n dispatch.call('done');\n reveal('.ideditor',\n helpString('intro.lines.play', { next: t('intro.buildings.title') }), {\n tooltipBox: '.intro-nav-wrap .chapter-building',\n buttonText: t('intro.ok'),\n buttonCallback: function() { reveal('.ideditor'); }\n }\n );\n }\n\n\n chapter.enter = function() {\n addLine();\n };\n\n\n chapter.exit = function() {\n timeouts.forEach(window.clearTimeout);\n d3_select(window).on('pointerdown.intro mousedown.intro', null, true);\n context.on('enter.intro exit.intro', null);\n context.map().on('move.intro drawn.intro', null);\n context.history().on('change.intro', null);\n context.container().select('.inspector-wrap').on('wheel.intro', null);\n context.container().select('.preset-list-button').on('click.intro', null);\n };\n\n\n chapter.restart = function() {\n chapter.exit();\n chapter.enter();\n };\n\n\n return utilRebind(chapter, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\n\nimport {\n event as d3_event\n} from 'd3-selection';\n\nimport { presetManager } from '../../presets';\nimport { t } from '../../core/localizer';\nimport { modeBrowse } from '../../modes/browse';\nimport { modeSelect } from '../../modes/select';\nimport { utilArrayUniq, utilRebind } from '../../util';\nimport { helpString, icon, pad, isMostlySquare, selectMenuItem, transitionTime } from './helper';\n\n\nexport function uiIntroBuilding(context, reveal) {\n var dispatch = d3_dispatch('done');\n var house = [-85.62815, 41.95638];\n var tank = [-85.62732, 41.95347];\n var buildingCatetory = presetManager.item('category-building');\n var housePreset = presetManager.item('building/house');\n var tankPreset = presetManager.item('man_made/storage_tank');\n var timeouts = [];\n var _houseID = null;\n var _tankID = null;\n\n\n var chapter = {\n title: 'intro.buildings.title'\n };\n\n\n function timeout(f, t) {\n timeouts.push(window.setTimeout(f, t));\n }\n\n\n function eventCancel() {\n d3_event.stopPropagation();\n d3_event.preventDefault();\n }\n\n\n function revealHouse(center, text, options) {\n var padding = 160 * Math.pow(2, context.map().zoom() - 20);\n var box = pad(center, padding, context);\n reveal(box, text, options);\n }\n\n\n function revealTank(center, text, options) {\n var padding = 190 * Math.pow(2, context.map().zoom() - 19.5);\n var box = pad(center, padding, context);\n reveal(box, text, options);\n }\n\n\n function addHouse() {\n context.enter(modeBrowse(context));\n context.history().reset('initial');\n _houseID = null;\n\n var msec = transitionTime(house, context.map().center());\n if (msec) { reveal(null, null, { duration: 0 }); }\n context.map().centerZoomEase(house, 19, msec);\n\n timeout(function() {\n var tooltip = reveal('button.add-area',\n helpString('intro.buildings.add_building'));\n\n tooltip.selectAll('.popover-inner')\n .insert('svg', 'span')\n .attr('class', 'tooltip-illustration')\n .append('use')\n .attr('xlink:href', '#iD-graphic-buildings');\n\n context.on('enter.intro', function(mode) {\n if (mode.id !== 'add-area') return;\n continueTo(startHouse);\n });\n }, msec + 100);\n\n function continueTo(nextStep) {\n context.on('enter.intro', null);\n nextStep();\n }\n }\n\n\n function startHouse() {\n if (context.mode().id !== 'add-area') {\n return continueTo(addHouse);\n }\n\n _houseID = null;\n context.map().zoomEase(20, 500);\n\n timeout(function() {\n var startString = helpString('intro.buildings.start_building') +\n helpString('intro.buildings.building_corner_' + (context.lastPointerType() === 'mouse' ? 'click' : 'tap'));\n revealHouse(house, startString);\n\n context.map().on('move.intro drawn.intro', function() {\n revealHouse(house, startString, { duration: 0 });\n });\n\n context.on('enter.intro', function(mode) {\n if (mode.id !== 'draw-area') return chapter.restart();\n continueTo(continueHouse);\n });\n\n }, 550); // after easing\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.on('enter.intro', null);\n nextStep();\n }\n }\n\n\n function continueHouse() {\n if (context.mode().id !== 'draw-area') {\n return continueTo(addHouse);\n }\n\n _houseID = null;\n\n var continueString = helpString('intro.buildings.continue_building') + '{br}' +\n helpString('intro.areas.finish_area_' + (context.lastPointerType() === 'mouse' ? 'click' : 'tap')) +\n helpString('intro.buildings.finish_building');\n\n revealHouse(house, continueString);\n\n context.map().on('move.intro drawn.intro', function() {\n revealHouse(house, continueString, { duration: 0 });\n });\n\n context.on('enter.intro', function(mode) {\n if (mode.id === 'draw-area') {\n return;\n } else if (mode.id === 'select') {\n var graph = context.graph();\n var way = context.entity(context.selectedIDs()[0]);\n var nodes = graph.childNodes(way);\n var points = utilArrayUniq(nodes)\n .map(function(n) { return context.projection(n.loc); });\n\n if (isMostlySquare(points)) {\n _houseID = way.id;\n return continueTo(chooseCategoryBuilding);\n } else {\n return continueTo(retryHouse);\n }\n\n } else {\n return chapter.restart();\n }\n });\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.on('enter.intro', null);\n nextStep();\n }\n }\n\n\n function retryHouse() {\n var onClick = function() { continueTo(addHouse); };\n\n revealHouse(house, helpString('intro.buildings.retry_building'),\n { buttonText: t('intro.ok'), buttonCallback: onClick }\n );\n\n context.map().on('move.intro drawn.intro', function() {\n revealHouse(house, helpString('intro.buildings.retry_building'),\n { duration: 0, buttonText: t('intro.ok'), buttonCallback: onClick }\n );\n });\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n nextStep();\n }\n }\n\n\n function chooseCategoryBuilding() {\n if (!_houseID || !context.hasEntity(_houseID)) {\n return addHouse();\n }\n var ids = context.selectedIDs();\n if (context.mode().id !== 'select' || !ids.length || ids[0] !== _houseID) {\n context.enter(modeSelect(context, [_houseID]));\n }\n\n // disallow scrolling\n context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);\n\n timeout(function() {\n // reset pane, in case user somehow happened to change it..\n context.container().select('.inspector-wrap .panewrap').style('right', '-100%');\n\n var button = context.container().select('.preset-category-building .preset-list-button');\n\n reveal(button.node(),\n helpString('intro.buildings.choose_category_building', { category: buildingCatetory.name() })\n );\n\n button.on('click.intro', function() {\n button.on('click.intro', null);\n continueTo(choosePresetHouse);\n });\n\n }, 400); // after preset list pane visible..\n\n\n context.on('enter.intro', function(mode) {\n if (!_houseID || !context.hasEntity(_houseID)) {\n return continueTo(addHouse);\n }\n var ids = context.selectedIDs();\n if (mode.id !== 'select' || !ids.length || ids[0] !== _houseID) {\n return continueTo(chooseCategoryBuilding);\n }\n });\n\n function continueTo(nextStep) {\n context.container().select('.inspector-wrap').on('wheel.intro', null);\n context.container().select('.preset-list-button').on('click.intro', null);\n context.on('enter.intro', null);\n nextStep();\n }\n }\n\n\n function choosePresetHouse() {\n if (!_houseID || !context.hasEntity(_houseID)) {\n return addHouse();\n }\n var ids = context.selectedIDs();\n if (context.mode().id !== 'select' || !ids.length || ids[0] !== _houseID) {\n context.enter(modeSelect(context, [_houseID]));\n }\n\n // disallow scrolling\n context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);\n\n timeout(function() {\n // reset pane, in case user somehow happened to change it..\n context.container().select('.inspector-wrap .panewrap').style('right', '-100%');\n\n var button = context.container().select('.preset-building-house .preset-list-button');\n\n reveal(button.node(),\n helpString('intro.buildings.choose_preset_house', { preset: housePreset.name() }),\n { duration: 300 }\n );\n\n button.on('click.intro', function() {\n button.on('click.intro', null);\n continueTo(closeEditorHouse);\n });\n\n }, 400); // after preset list pane visible..\n\n context.on('enter.intro', function(mode) {\n if (!_houseID || !context.hasEntity(_houseID)) {\n return continueTo(addHouse);\n }\n var ids = context.selectedIDs();\n if (mode.id !== 'select' || !ids.length || ids[0] !== _houseID) {\n return continueTo(chooseCategoryBuilding);\n }\n });\n\n function continueTo(nextStep) {\n context.container().select('.inspector-wrap').on('wheel.intro', null);\n context.container().select('.preset-list-button').on('click.intro', null);\n context.on('enter.intro', null);\n nextStep();\n }\n }\n\n\n function closeEditorHouse() {\n if (!_houseID || !context.hasEntity(_houseID)) {\n return addHouse();\n }\n var ids = context.selectedIDs();\n if (context.mode().id !== 'select' || !ids.length || ids[0] !== _houseID) {\n context.enter(modeSelect(context, [_houseID]));\n }\n\n context.history().checkpoint('hasHouse');\n\n context.on('exit.intro', function() {\n continueTo(rightClickHouse);\n });\n\n timeout(function() {\n reveal('.entity-editor-pane',\n helpString('intro.buildings.close', { button: icon('#iD-icon-close', 'pre-text') })\n );\n }, 500);\n\n function continueTo(nextStep) {\n context.on('exit.intro', null);\n nextStep();\n }\n }\n\n\n function rightClickHouse() {\n if (!_houseID) return chapter.restart();\n\n context.enter(modeBrowse(context));\n context.history().reset('hasHouse');\n var zoom = context.map().zoom();\n if (zoom < 20) {\n zoom = 20;\n }\n context.map().centerZoomEase(house, zoom, 500);\n\n context.on('enter.intro', function(mode) {\n if (mode.id !== 'select') return;\n var ids = context.selectedIDs();\n if (ids.length !== 1 || ids[0] !== _houseID) return;\n\n timeout(function() {\n var node = selectMenuItem(context, 'orthogonalize').node();\n if (!node) return;\n continueTo(clickSquare);\n }, 50); // after menu visible\n });\n\n context.map().on('move.intro drawn.intro', function() {\n var rightclickString = helpString('intro.buildings.' + (context.lastPointerType() === 'mouse' ? 'rightclick_building' : 'edit_menu_building_touch'));\n revealHouse(house, rightclickString, { duration: 0 });\n });\n\n context.history().on('change.intro', function() {\n continueTo(rightClickHouse);\n });\n\n function continueTo(nextStep) {\n context.on('enter.intro', null);\n context.map().on('move.intro drawn.intro', null);\n context.history().on('change.intro', null);\n nextStep();\n }\n }\n\n\n function clickSquare() {\n if (!_houseID) return chapter.restart();\n var entity = context.hasEntity(_houseID);\n if (!entity) return continueTo(rightClickHouse);\n\n var node = selectMenuItem(context, 'orthogonalize').node();\n if (!node) { return continueTo(rightClickHouse); }\n\n var wasChanged = false;\n\n reveal('.edit-menu',\n helpString('intro.buildings.square_building'),\n { padding: 50 }\n );\n\n context.on('enter.intro', function(mode) {\n if (mode.id === 'browse') {\n continueTo(rightClickHouse);\n } else if (mode.id === 'move' || mode.id === 'rotate') {\n continueTo(retryClickSquare);\n }\n });\n\n context.map().on('move.intro', function() {\n var node = selectMenuItem(context, 'orthogonalize').node();\n if (!wasChanged && !node) { return continueTo(rightClickHouse); }\n\n reveal('.edit-menu',\n helpString('intro.buildings.square_building'),\n { duration: 0, padding: 50 }\n );\n });\n\n context.history().on('change.intro', function() {\n wasChanged = true;\n context.history().on('change.intro', null);\n\n // Something changed. Wait for transition to complete and check undo annotation.\n timeout(function() {\n if (context.history().undoAnnotation() === t('operations.orthogonalize.annotation.feature.single')) {\n continueTo(doneSquare);\n } else {\n continueTo(retryClickSquare);\n }\n }, 500); // after transitioned actions\n });\n\n function continueTo(nextStep) {\n context.on('enter.intro', null);\n context.map().on('move.intro', null);\n context.history().on('change.intro', null);\n nextStep();\n }\n }\n\n\n function retryClickSquare() {\n context.enter(modeBrowse(context));\n\n revealHouse(house, helpString('intro.buildings.retry_square'), {\n buttonText: t('intro.ok'),\n buttonCallback: function() { continueTo(rightClickHouse); }\n });\n\n function continueTo(nextStep) {\n nextStep();\n }\n }\n\n\n function doneSquare() {\n context.history().checkpoint('doneSquare');\n\n revealHouse(house, helpString('intro.buildings.done_square'), {\n buttonText: t('intro.ok'),\n buttonCallback: function() { continueTo(addTank); }\n });\n\n function continueTo(nextStep) {\n nextStep();\n }\n }\n\n\n function addTank() {\n context.enter(modeBrowse(context));\n context.history().reset('doneSquare');\n _tankID = null;\n\n var msec = transitionTime(tank, context.map().center());\n if (msec) { reveal(null, null, { duration: 0 }); }\n context.map().centerZoomEase(tank, 19.5, msec);\n\n timeout(function() {\n reveal('button.add-area',\n helpString('intro.buildings.add_tank')\n );\n\n context.on('enter.intro', function(mode) {\n if (mode.id !== 'add-area') return;\n continueTo(startTank);\n });\n }, msec + 100);\n\n function continueTo(nextStep) {\n context.on('enter.intro', null);\n nextStep();\n }\n }\n\n\n function startTank() {\n if (context.mode().id !== 'add-area') {\n return continueTo(addTank);\n }\n\n _tankID = null;\n\n timeout(function() {\n var startString = helpString('intro.buildings.start_tank') +\n helpString('intro.buildings.tank_edge_' + (context.lastPointerType() === 'mouse' ? 'click' : 'tap'));\n revealTank(tank, startString);\n\n context.map().on('move.intro drawn.intro', function() {\n revealTank(tank, startString, { duration: 0 });\n });\n\n context.on('enter.intro', function(mode) {\n if (mode.id !== 'draw-area') return chapter.restart();\n continueTo(continueTank);\n });\n\n }, 550); // after easing\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.on('enter.intro', null);\n nextStep();\n }\n }\n\n\n function continueTank() {\n if (context.mode().id !== 'draw-area') {\n return continueTo(addTank);\n }\n\n _tankID = null;\n\n var continueString = helpString('intro.buildings.continue_tank') + '{br}' +\n helpString('intro.areas.finish_area_' + (context.lastPointerType() === 'mouse' ? 'click' : 'tap')) +\n helpString('intro.buildings.finish_tank');\n\n revealTank(tank, continueString);\n\n context.map().on('move.intro drawn.intro', function() {\n revealTank(tank, continueString, { duration: 0 });\n });\n\n context.on('enter.intro', function(mode) {\n if (mode.id === 'draw-area') {\n return;\n } else if (mode.id === 'select') {\n _tankID = context.selectedIDs()[0];\n return continueTo(searchPresetTank);\n } else {\n return continueTo(addTank);\n }\n });\n\n function continueTo(nextStep) {\n context.map().on('move.intro drawn.intro', null);\n context.on('enter.intro', null);\n nextStep();\n }\n }\n\n\n function searchPresetTank() {\n if (!_tankID || !context.hasEntity(_tankID)) {\n return addTank();\n }\n var ids = context.selectedIDs();\n if (context.mode().id !== 'select' || !ids.length || ids[0] !== _tankID) {\n context.enter(modeSelect(context, [_tankID]));\n }\n\n // disallow scrolling\n context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);\n\n timeout(function() {\n // reset pane, in case user somehow happened to change it..\n context.container().select('.inspector-wrap .panewrap').style('right', '-100%');\n\n context.container().select('.preset-search-input')\n .on('keydown.intro', null)\n .on('keyup.intro', checkPresetSearch);\n\n reveal('.preset-search-input',\n helpString('intro.buildings.search_tank', { preset: tankPreset.name() })\n );\n }, 400); // after preset list pane visible..\n\n context.on('enter.intro', function(mode) {\n if (!_tankID || !context.hasEntity(_tankID)) {\n return continueTo(addTank);\n }\n\n var ids = context.selectedIDs();\n if (mode.id !== 'select' || !ids.length || ids[0] !== _tankID) {\n // keep the user's area selected..\n context.enter(modeSelect(context, [_tankID]));\n\n // reset pane, in case user somehow happened to change it..\n context.container().select('.inspector-wrap .panewrap').style('right', '-100%');\n // disallow scrolling\n context.container().select('.inspector-wrap').on('wheel.intro', eventCancel);\n\n context.container().select('.preset-search-input')\n .on('keydown.intro', null)\n .on('keyup.intro', checkPresetSearch);\n\n reveal('.preset-search-input',\n helpString('intro.buildings.search_tank', { preset: tankPreset.name() })\n );\n\n context.history().on('change.intro', null);\n }\n });\n\n function checkPresetSearch() {\n var first = context.container().select('.preset-list-item:first-child');\n\n if (first.classed('preset-man_made-storage_tank')) {\n reveal(first.select('.preset-list-button').node(),\n helpString('intro.buildings.choose_tank', { preset: tankPreset.name() }),\n { duration: 300 }\n );\n\n context.container().select('.preset-search-input')\n .on('keydown.intro', eventCancel, true)\n .on('keyup.intro', null);\n\n context.history().on('change.intro', function() {\n continueTo(closeEditorTank);\n });\n }\n }\n\n function continueTo(nextStep) {\n context.container().select('.inspector-wrap').on('wheel.intro', null);\n context.on('enter.intro', null);\n context.history().on('change.intro', null);\n context.container().select('.preset-search-input').on('keydown.intro keyup.intro', null);\n nextStep();\n }\n }\n\n\n function closeEditorTank() {\n if (!_tankID || !context.hasEntity(_tankID)) {\n return addTank();\n }\n var ids = context.selectedIDs();\n if (context.mode().id !== 'select' || !ids.length || ids[0] !== _tankID) {\n context.enter(modeSelect(context, [_tankID]));\n }\n\n context.history().checkpoint('hasTank');\n\n context.on('exit.intro', function() {\n continueTo(rightClickTank);\n });\n\n timeout(function() {\n reveal('.entity-editor-pane',\n helpString('intro.buildings.close', { button: icon('#iD-icon-close', 'pre-text') })\n );\n }, 500);\n\n function continueTo(nextStep) {\n context.on('exit.intro', null);\n nextStep();\n }\n }\n\n\n function rightClickTank() {\n if (!_tankID) return continueTo(addTank);\n\n context.enter(modeBrowse(context));\n context.history().reset('hasTank');\n context.map().centerEase(tank, 500);\n\n timeout(function() {\n context.on('enter.intro', function(mode) {\n if (mode.id !== 'select') return;\n var ids = context.selectedIDs();\n if (ids.length !== 1 || ids[0] !== _tankID) return;\n\n timeout(function() {\n var node = selectMenuItem(context, 'circularize').node();\n if (!node) return;\n continueTo(clickCircle);\n }, 50); // after menu visible\n });\n\n var rightclickString = helpString('intro.buildings.' + (context.lastPointerType() === 'mouse' ? 'rightclick_tank' : 'edit_menu_tank_touch'));\n\n revealTank(tank, rightclickString);\n\n context.map().on('move.intro drawn.intro', function() {\n revealTank(tank, rightclickString, { duration: 0 });\n });\n\n context.history().on('change.intro', function() {\n continueTo(rightClickTank);\n });\n\n }, 600);\n\n function continueTo(nextStep) {\n context.on('enter.intro', null);\n context.map().on('move.intro drawn.intro', null);\n context.history().on('change.intro', null);\n nextStep();\n }\n }\n\n\n function clickCircle() {\n if (!_tankID) return chapter.restart();\n var entity = context.hasEntity(_tankID);\n if (!entity) return continueTo(rightClickTank);\n\n var node = selectMenuItem(context, 'circularize').node();\n if (!node) { return continueTo(rightClickTank); }\n\n var wasChanged = false;\n\n reveal('.edit-menu',\n helpString('intro.buildings.circle_tank'),\n { padding: 50 }\n );\n\n context.on('enter.intro', function(mode) {\n if (mode.id === 'browse') {\n continueTo(rightClickTank);\n } else if (mode.id === 'move' || mode.id === 'rotate') {\n continueTo(retryClickCircle);\n }\n });\n\n context.map().on('move.intro', function() {\n var node = selectMenuItem(context, 'circularize').node();\n if (!wasChanged && !node) { return continueTo(rightClickTank); }\n\n reveal('.edit-menu',\n helpString('intro.buildings.circle_tank'),\n { duration: 0, padding: 50 }\n );\n });\n\n context.history().on('change.intro', function() {\n wasChanged = true;\n context.history().on('change.intro', null);\n\n // Something changed. Wait for transition to complete and check undo annotation.\n timeout(function() {\n if (context.history().undoAnnotation() === t('operations.circularize.annotation.single')) {\n continueTo(play);\n } else {\n continueTo(retryClickCircle);\n }\n }, 500); // after transitioned actions\n });\n\n function continueTo(nextStep) {\n context.on('enter.intro', null);\n context.map().on('move.intro', null);\n context.history().on('change.intro', null);\n nextStep();\n }\n }\n\n\n function retryClickCircle() {\n context.enter(modeBrowse(context));\n\n revealTank(tank, helpString('intro.buildings.retry_circle'), {\n buttonText: t('intro.ok'),\n buttonCallback: function() { continueTo(rightClickTank); }\n });\n\n function continueTo(nextStep) {\n nextStep();\n }\n }\n\n\n function play() {\n dispatch.call('done');\n reveal('#id-container',\n t('intro.buildings.play', { next: t('intro.rapid.title') }), {\n tooltipBox: '.intro-nav-wrap .chapter-rapid',\n buttonText: t('intro.ok'),\n buttonCallback: function() { reveal('.ideditor'); }\n }\n );\n }\n\n\n chapter.enter = function() {\n addHouse();\n };\n\n\n chapter.exit = function() {\n timeouts.forEach(window.clearTimeout);\n context.on('enter.intro exit.intro', null);\n context.map().on('move.intro drawn.intro', null);\n context.history().on('change.intro', null);\n context.container().select('.inspector-wrap').on('wheel.intro', null);\n context.container().select('.preset-search-input').on('keydown.intro keyup.intro', null);\n context.container().select('.more-fields .combobox-input').on('click.intro', null);\n };\n\n\n chapter.restart = function() {\n chapter.exit();\n chapter.enter();\n };\n\n\n return utilRebind(chapter, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport {\n select as d3_select\n} from 'd3-selection';\n\nimport { t } from '../../core/localizer';\nimport { helpString } from './helper';\nimport { uiModal } from '../modal';\nimport { utilRebind } from '../../util/rebind';\n\n\nexport function uiIntroStartEditing(context, reveal) {\n var dispatch = d3_dispatch('done', 'startEditing');\n var modalSelection = d3_select(null);\n\n\n var chapter = {\n title: 'intro.startediting.title'\n };\n\n function showHelp() {\n reveal('.map-control.help-control',\n helpString('intro.startediting.help'), {\n buttonText: t('intro.ok'),\n buttonCallback: function() { shortcuts(); }\n }\n );\n }\n\n function shortcuts() {\n reveal('.map-control.help-control',\n helpString('intro.startediting.shortcuts'), {\n buttonText: t('intro.ok'),\n buttonCallback: function() { showSave(); }\n }\n );\n }\n\n function showSave() {\n context.container().selectAll('.shaded').remove(); // in case user opened keyboard shortcuts\n reveal('.top-toolbar button.save',\n helpString('intro.startediting.save'), {\n buttonText: t('intro.ok'),\n buttonCallback: function() { showStart(); }\n }\n );\n }\n\n function showStart() {\n context.container().selectAll('.shaded').remove(); // in case user opened keyboard shortcuts\n\n modalSelection = uiModal(context.container());\n\n modalSelection.select('.modal')\n .attr('class', 'modal-splash modal');\n\n modalSelection.selectAll('.close').remove();\n\n var startbutton = modalSelection.select('.content')\n .attr('class', 'fillL')\n .append('button')\n .attr('class', 'modal-section huge-modal-button')\n .on('click', function() {\n modalSelection.remove();\n });\n\n startbutton\n .append('svg')\n .attr('class', 'illustration')\n .append('use')\n .attr('xlink:href', '#iD-logo-walkthrough');\n\n startbutton\n .append('h2')\n .text(t('intro.startediting.start'));\n\n dispatch.call('startEditing');\n }\n\n\n chapter.enter = function() {\n showHelp();\n };\n\n\n chapter.exit = function() {\n modalSelection.remove();\n context.container().selectAll('.shaded').remove(); // in case user opened keyboard shortcuts\n };\n\n\n return utilRebind(chapter, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { event as d3_event, select as d3_select } from 'd3-selection';\n\nimport marked from 'marked';\nimport { t } from '../../core/localizer';\nimport { modeBrowse} from '../../modes';\nimport { utilRebind } from '../../util/rebind';\nimport { icon, pad, transitionTime } from './helper';\n\n\nexport function uiIntroRapid(context, reveal) {\n const dispatch = d3_dispatch('done');\n let chapter = { title: 'intro.rapid.title' };\n let timeouts = [];\n\n const tulipLaneStart = [-85.6297512, 41.9561476];\n const tulipLaneMid = [-85.6281089, 41.9561288];\n const tulipLaneEnd = [-85.6272670, 41.9558780];\n\n\n function timeout(f, t) {\n timeouts.push(window.setTimeout(f, t));\n }\n\n\n function tulipLaneEndBoundingBox(){\n const padding = 70 * Math.pow(2, context.map().zoom() - 18);\n let box = pad(tulipLaneEnd, padding, context);\n box.height = box.height + 65;\n box.width = box.width + 65;\n return box;\n }\n\n function tulipLaneBoundingBox(){\n const padding = 70 * Math.pow(2, context.map().zoom() - 18);\n let box = pad(tulipLaneStart, padding, context);\n box.height = box.height + 65;\n box.width = box.width + 600;\n return box;\n }\n\n\n function eventCancel() {\n d3_event.stopPropagation();\n d3_event.preventDefault();\n }\n\n\n function welcome() {\n context.layers().layer('ai-features').enabled(true);\n context.enter(modeBrowse(context));\n context.history().reset('initial');\n reveal('.intro-nav-wrap .chapter-rapid',\n t('intro.rapid.start', { rapid: icon('#iD-logo-rapid', 'pre-text') }),\n { buttonText: t('intro.ok'), buttonCallback: showHideRoads }\n );\n }\n\n\n function showHideRoads() {\n const msec = transitionTime(tulipLaneMid, context.map().center());\n if (msec) { reveal(null, null, { duration: 0 }); }\n context.map().centerZoomEase(tulipLaneMid, 18.5, msec);\n\n reveal(\n 'button.rapid-features',\n t('intro.rapid.ai_roads', { rapid: icon('#iD-logo-rapid', 'pre-text') }),\n { buttonText: t('intro.ok'), buttonCallback: selectRoad }\n );\n }\n\n\n function selectRoad() {\n context.layers().layer('ai-features').enabled(true);\n\n // disallow scrolling\n d3_select('.inspector-wrap').on('wheel.intro', eventCancel);\n reveal(tulipLaneBoundingBox(), t('intro.rapid.select_road'));\n\n timeout(() => {\n let fbRoad = d3_select('.data-layer.ai-features');\n fbRoad.on('click.intro', addRoad);\n }, 250);\n }\n\n\n function addRoad() {\n timeout(() => {\n reveal('.rapid-inspector-choice-accept', t('intro.rapid.add_road'));\n let button = d3_select('.choice-button-accept');\n button.on('click.intro', roadAdded);\n }, 250);\n }\n\n\n function roadAdded() {\n if (context.mode().id !== 'select') return chapter.restart();\n\n timeout(() => {\n reveal(tulipLaneBoundingBox(),\n t('intro.rapid.add_road_not_saved_yet', { rapid: icon('#iD-logo-rapid', 'pre-text') }),\n { buttonText: t('intro.ok'), buttonCallback: showLint }\n );\n }, 250);\n }\n\n\n function showLint() {\n if (context.mode().id !== 'select') return chapter.restart();\n\n let button = d3_select('li.issue-list-item.actionable > button');\n button.on('click.intro', () => continueTo(fixLint));\n\n timeout(() => {\n reveal('div.issue.severity-warning',\n t('intro.rapid.new_lints'),\n { buttonText: t('intro.ok'), buttonCallback: fixLint }\n );\n }, 250);\n\n function continueTo(nextStep) {\n button.on('click.intro', null);\n nextStep();\n }\n }\n\n\n function fixLint() {\n if (context.mode().id !== 'select') return chapter.restart();\n\n let button = d3_select('li.issue-fix-item.actionable');\n button.on('click.intro', () => continueTo(showFixedRoad));\n\n timeout(() => {\n reveal('li.issue-fix-item.actionable',\n t('intro.rapid.fix_lint', {connect: icon('#iD-icon-crossing', 'pre-text') })\n );\n }, 250);\n\n function continueTo(nextStep) {\n button.on('click.intro', null);\n nextStep();\n }\n }\n\n\n function showFixedRoad() {\n if (context.mode().id !== 'select') return chapter.restart();\n\n timeout(() => {\n reveal(\n tulipLaneEndBoundingBox(),\n t('intro.rapid.fixed_lint'),\n { buttonText: t('intro.ok'), buttonCallback: undoFixLint }\n );\n }, 250);\n }\n\n\n function undoFixLint() {\n if (context.mode().id !== 'select') return chapter.restart();\n\n timeout(() => {\n let button = d3_select('.top-toolbar button.undo-button');\n let iconName = '#iD-icon-undo';\n reveal('.top-toolbar button.undo-button',\n t('intro.rapid.undo_fix_lint', { button: icon(iconName, 'pre-text') })\n );\n button.on('click.intro', undoRoadAdd);\n }, 250);\n }\n\n\n function undoRoadAdd() {\n if (context.mode().id !== 'select') return chapter.restart();\n\n timeout(() => {\n let button = d3_select('.top-toolbar button.undo-button');\n const iconName = '#iD-icon-undo';\n reveal('.top-toolbar button.undo-button',\n t('intro.rapid.undo_road_add', { button: icon(iconName, 'pre-text') })\n );\n button.on('click.intro', afterUndoRoadAdd);\n }, 250);\n }\n\n\n function afterUndoRoadAdd() {\n timeout(() => {\n reveal(\n tulipLaneBoundingBox(),\n t('intro.rapid.undo_road_add_aftermath'),\n { buttonText: t('intro.ok'), buttonCallback: selectRoadAgain }\n );\n }, 250);\n }\n\n\n function selectRoadAgain() {\n timeout(() => {\n reveal(tulipLaneBoundingBox(), t('intro.rapid.select_road_again'));\n let fbRoad = d3_select('.data-layer.ai-features');\n fbRoad.on('click.intro', ignoreRoad);\n }, 250);\n }\n\n\n function ignoreRoad() {\n timeout(() => {\n reveal('.rapid-inspector-choice-ignore', t('intro.rapid.ignore_road'));\n let button = d3_select('.choice-button-ignore');\n button.on('click.intro', showHelp);\n }, 250);\n }\n\n\n function showHelp() {\n reveal(\n '.map-control.help-control',\n t('intro.rapid.help', {\n rapid: icon('#iD-logo-rapid', 'pre-text'),\n button: icon('#iD-icon-help', 'pre-text'),\n key: t('help.key')\n }),\n { buttonText: t('intro.ok'), buttonCallback: allDone }\n );\n }\n\n\n function allDone() {\n if (context.mode().id !== 'browse') return chapter.restart();\n\n dispatch.call('done');\n reveal('.intro-nav-wrap .chapter-startEditing',\n marked(t('intro.rapid.done', { next: t('intro.startediting.title') }))\n );\n }\n\n\n chapter.enter = () => {\n welcome();\n };\n\n\n chapter.exit = () => {\n timeouts.forEach(window.clearTimeout);\n d3_select(window).on('mousedown.intro-rapid', null, true);\n context.on('enter.intro-rapid exit.intro-rapid', null);\n context.map().on('move.intro-rapid drawn.intro-rapid', null);\n context.history().on('change.intro-rapid', null);\n d3_select('.inspector-wrap').on('wheel.intro-rapid', null);\n d3_select('.preset-list-button').on('click.intro-rapid', null);\n };\n\n\n chapter.restart = () => {\n chapter.exit();\n chapter.enter();\n };\n\n\n return utilRebind(chapter, dispatch, 'on');\n}\n","import { t, localizer } from '../../core/localizer';\nimport { localize } from './helper';\n\nimport { prefs } from '../../core/preferences';\nimport { fileFetcher } from '../../core/file_fetcher';\nimport { coreGraph } from '../../core/graph';\nimport { modeBrowse } from '../../modes/browse';\nimport { osmEntity } from '../../osm/entity';\nimport { services } from '../../services';\nimport { svgIcon } from '../../svg/icon';\nimport { uiCurtain } from '../curtain';\nimport { utilArrayDifference, utilArrayUniq } from '../../util';\n\nimport { uiIntroWelcome } from './welcome';\nimport { uiIntroNavigation } from './navigation';\nimport { uiIntroPoint } from './point';\nimport { uiIntroArea } from './area';\nimport { uiIntroLine } from './line';\nimport { uiIntroBuilding } from './building';\nimport { uiIntroStartEditing } from './start_editing';\nimport { uiIntroRapid } from './rapid';\n\nconst chapterUi = {\n welcome: uiIntroWelcome,\n navigation: uiIntroNavigation,\n point: uiIntroPoint,\n area: uiIntroArea,\n line: uiIntroLine,\n building: uiIntroBuilding,\n rapid: uiIntroRapid,\n startEditing: uiIntroStartEditing\n};\n\nconst chapterFlow = [\n 'welcome',\n 'navigation',\n 'point',\n 'area',\n 'line',\n 'building',\n 'rapid',\n 'startEditing'\n];\n\n\nexport function uiIntro(context, skipToRapid) {\n const INTRO_IMAGERY = 'EsriWorldImageryClarity';\n let _introGraph = {};\n let _rapidGraph = {};\n let _currChapter;\n\n\n function intro(selection) {\n Promise.all([\n fileFetcher.get('intro_rapid_graph'),\n fileFetcher.get('intro_graph')\n ])\n .then(values => {\n const rapidData = values[0];\n const introData = values[1];\n\n for (const id in rapidData) {\n if (!_rapidGraph[id]) {\n _rapidGraph[id] = osmEntity(localize(rapidData[id]));\n }\n }\n for (const id in introData) {\n if (!_introGraph[id]) {\n _introGraph[id] = osmEntity(localize(introData[id]));\n }\n }\n\n selection.call(startIntro);\n });\n }\n\n\n function startIntro(selection) {\n context.enter(modeBrowse(context));\n\n // Save current map state\n let osm = context.connection();\n let history = context.history().toJSON();\n let hash = window.location.hash;\n let center = context.map().center();\n let zoom = context.map().zoom();\n let background = context.background().baseLayerSource();\n let overlays = context.background().overlayLayerSources();\n let opacity = context.container().selectAll('.main-map .layer-background').style('opacity');\n let caches = osm && osm.caches();\n let baseEntities = context.history().graph().base().entities;\n\n // Show sidebar and disable the sidebar resizing button\n // (this needs to be before `context.inIntro(true)`)\n context.ui().sidebar.expand();\n context.container().selectAll('button.sidebar-toggle').classed('disabled', true);\n\n // Block saving\n context.inIntro(true);\n\n // Load semi-real data used in intro\n if (osm) { osm.toggle(false).reset(); }\n context.history().reset();\n context.history().merge(Object.values(coreGraph().load(_introGraph).entities));\n context.history().checkpoint('initial');\n\n // Setup imagery\n let imagery = context.background().findSource(INTRO_IMAGERY);\n if (imagery) {\n context.background().baseLayerSource(imagery);\n } else {\n context.background().bing();\n }\n overlays.forEach(d => context.background().toggleOverlayLayer(d));\n\n // Setup data layers (only OSM & ai-features)\n let layers = context.layers();\n layers.all().forEach(item => {\n // if the layer has the function `enabled`\n if (typeof item.layer.enabled === 'function') {\n item.layer.enabled(item.id === 'osm' || item.id === 'ai-features');\n }\n });\n\n // Setup RapiD Walkthrough dataset and disable service\n let rapidDatasets = context.rapidContext().datasets();\n const rapidDatasetsCopy = JSON.parse(JSON.stringify(rapidDatasets)); // deep copy\n Object.keys(rapidDatasets).forEach(id => rapidDatasets[id].enabled = false);\n\n rapidDatasets.rapid_intro_graph = {\n id: 'rapid_intro_graph',\n beta: false,\n added: true,\n enabled: true,\n conflated: false,\n service: 'fbml',\n color: '#da26d3',\n label: 'RapiD Walkthrough'\n };\n\n if (services.fbMLRoads) {\n services.fbMLRoads.toggle(false); // disable network\n const entities = Object.values(coreGraph().load(_rapidGraph).entities);\n services.fbMLRoads.merge('rapid_intro_graph', entities);\n }\n\n context.container().selectAll('.main-map .layer-background').style('opacity', 1);\n\n let curtain = uiCurtain(context.container().node());\n selection.call(curtain);\n\n // Store that the user started the walkthrough..\n prefs('walkthrough_started', 'yes');\n\n // Restore previous walkthrough progress..\n let storedProgress = prefs('walkthrough_progress') || '';\n let progress = storedProgress.split(';').filter(Boolean);\n\n let chapters = chapterFlow.map((chapter, i) => {\n let s = chapterUi[chapter](context, curtain.reveal)\n .on('done', () => {\n\n buttons\n .filter(d => d.title === s.title)\n .classed('finished', true);\n\n if (i < chapterFlow.length - 1) {\n const next = chapterFlow[i + 1];\n context.container().select(`button.chapter-${next}`)\n .classed('next', true);\n }\n\n // Store walkthrough progress..\n progress.push(chapter);\n prefs('walkthrough_progress', utilArrayUniq(progress).join(';'));\n });\n return s;\n });\n\n chapters[chapters.length - 1].on('startEditing', () => {\n // Store walkthrough progress..\n progress.push('startEditing');\n prefs('walkthrough_progress', utilArrayUniq(progress).join(';'));\n\n // Store if walkthrough is completed..\n let incomplete = utilArrayDifference(chapterFlow, progress);\n if (!incomplete.length) {\n prefs('walkthrough_completed', 'yes');\n }\n\n // Restore RapiD datasets and service\n let rapidDatasets = context.rapidContext().datasets();\n delete rapidDatasets.rapid_intro_graph;\n Object.keys(rapidDatasetsCopy).forEach(id => rapidDatasets[id].enabled = rapidDatasetsCopy[id].enabled);\n Object.assign(rapidDatasets, rapidDatasetsCopy);\n if (services.fbMLRoads) {\n services.fbMLRoads.toggle(true);\n }\n\n curtain.remove();\n navwrap.remove();\n context.container().selectAll('.main-map .layer-background').style('opacity', opacity);\n context.container().selectAll('button.sidebar-toggle').classed('disabled', false);\n if (osm) { osm.toggle(true).reset().caches(caches); }\n context.history().reset().merge(Object.values(baseEntities));\n context.background().baseLayerSource(background);\n overlays.forEach(d => context.background().toggleOverlayLayer(d));\n if (history) { context.history().fromJSON(history, false); }\n context.map().centerZoom(center, zoom);\n window.location.replace(hash);\n context.inIntro(false);\n });\n\n let navwrap = selection\n .append('div')\n .attr('class', 'intro-nav-wrap fillD');\n\n navwrap\n .append('svg')\n .attr('class', 'intro-nav-wrap-logo')\n .append('use')\n .attr('xlink:href', '#iD-logo-walkthrough');\n\n let buttonwrap = navwrap\n .append('div')\n .attr('class', 'joined')\n .selectAll('button.chapter');\n\n let buttons = buttonwrap\n .data(chapters)\n .enter()\n .append('button')\n .attr('class', (d, i) => `chapter chapter-${chapterFlow[i]}`)\n .on('click', enterChapter);\n\n buttons\n .append('span')\n .text(d => t(d.title));\n\n buttons\n .append('span')\n .attr('class', 'status')\n .call(svgIcon((localizer.textDirection() === 'rtl' ? '#iD-icon-backward' : '#iD-icon-forward'), 'inline'));\n\n enterChapter(chapters[skipToRapid ? 6 : 0]);\n\n function enterChapter(newChapter) {\n if (_currChapter) { _currChapter.exit(); }\n context.enter(modeBrowse(context));\n\n _currChapter = newChapter;\n _currChapter.enter();\n\n buttons\n .classed('next', false)\n .classed('active', d => d.title === _currChapter.title);\n }\n }\n\n\n return intro;\n}\n","import { event as d3_event, select as d3_select } from 'd3-selection';\n\nimport { prefs } from '../core/preferences';\nimport { svgIcon } from '../svg/icon';\nimport { t } from '../core/localizer';\nimport { uiTooltip } from './tooltip';\n\n\nexport function uiIssuesInfo(context) {\n\n var warningsItem = {\n id: 'warnings',\n count: 0,\n iconID: 'iD-icon-alert',\n descriptionID: 'issues.warnings_and_errors'\n };\n\n var resolvedItem = {\n id: 'resolved',\n count: 0,\n iconID: 'iD-icon-apply',\n descriptionID: 'issues.user_resolved_issues'\n };\n\n function update(selection) {\n\n var shownItems = [];\n\n var liveIssues = context.validator().getIssues({\n what: prefs('validate-what') || 'edited',\n where: prefs('validate-where') || 'all'\n });\n if (liveIssues.length) {\n warningsItem.count = liveIssues.length;\n shownItems.push(warningsItem);\n }\n\n if (prefs('validate-what') === 'all') {\n var resolvedIssues = context.validator().getResolvedIssues();\n if (resolvedIssues.length) {\n resolvedItem.count = resolvedIssues.length;\n shownItems.push(resolvedItem);\n }\n }\n\n var chips = selection.selectAll('.chip')\n .data(shownItems, function(d) {\n return d.id;\n });\n\n chips.exit().remove();\n\n var enter = chips.enter()\n .append('a')\n .attr('class', function(d) {\n return 'chip ' + d.id + '-count';\n })\n .attr('href', '#')\n .attr('tabindex', -1)\n .each(function(d) {\n\n var chipSelection = d3_select(this);\n\n var tooltipBehavior = uiTooltip()\n .placement('top')\n .title(t(d.descriptionID));\n\n chipSelection\n .call(tooltipBehavior)\n .on('click', function() {\n d3_event.preventDefault();\n\n tooltipBehavior.hide(d3_select(this));\n // open the Issues pane\n context.ui().togglePanes(context.container().select('.map-panes .issues-pane'));\n });\n\n chipSelection.call(svgIcon('#' + d.iconID));\n\n });\n\n enter.append('span')\n .attr('class', 'count');\n\n enter.merge(chips)\n .selectAll('span.count')\n .text(function(d) {\n return d.count.toString();\n });\n }\n\n\n return function(selection) {\n update(selection);\n\n context.validator().on('validated.infobox', function() {\n update(selection);\n });\n };\n}\n","import { geoArea as d3_geoArea, geoMercatorRaw as d3_geoMercatorRaw } from 'd3-geo';\nimport { json as d3_json } from 'd3-fetch';\n\nimport { t, localizer } from '../core/localizer';\nimport { geoExtent, geoSphericalDistance } from '../geo';\nimport { utilQsString, utilStringQs } from '../util';\nimport { utilAesDecrypt } from '../util/aes';\n\n\nvar isRetina = window.devicePixelRatio && window.devicePixelRatio >= 2;\n\n// listen for DPI change, e.g. when dragging a browser window from a retina to non-retina screen\nwindow.matchMedia(`\n (-webkit-min-device-pixel-ratio: 2), /* Safari */\n (min-resolution: 2dppx), /* standard */\n (min-resolution: 192dpi) /* fallback */\n `).addListener(function() {\n\n isRetina = window.devicePixelRatio && window.devicePixelRatio >= 2;\n});\n\n\nfunction localeDateString(s) {\n if (!s) return null;\n var options = { day: 'numeric', month: 'short', year: 'numeric' };\n var d = new Date(s);\n if (isNaN(d.getTime())) return null;\n return d.toLocaleDateString(localizer.localeCode(), options);\n}\n\nfunction vintageRange(vintage) {\n var s;\n if (vintage.start || vintage.end) {\n s = (vintage.start || '?');\n if (vintage.start !== vintage.end) {\n s += ' - ' + (vintage.end || '?');\n }\n }\n return s;\n}\n\n\nexport function rendererBackgroundSource(data) {\n var source = Object.assign({}, data); // shallow copy\n var _offset = [0, 0];\n var _name = source.name;\n var _description = source.description;\n var _best = !!source.best;\n var _template = source.encrypted ? utilAesDecrypt(source.template) : source.template;\n\n source.tileSize = data.tileSize || 256;\n source.zoomExtent = data.zoomExtent || [0, 22];\n source.overzoom = data.overzoom !== false;\n\n source.offset = function(val) {\n if (!arguments.length) return _offset;\n _offset = val;\n return source;\n };\n\n\n source.nudge = function(val, zoomlevel) {\n _offset[0] += val[0] / Math.pow(2, zoomlevel);\n _offset[1] += val[1] / Math.pow(2, zoomlevel);\n return source;\n };\n\n\n source.name = function() {\n var id_safe = source.id.replace(/\\./g, '');\n return t('imagery.' + id_safe + '.name', { default: _name });\n };\n\n\n source.description = function() {\n var id_safe = source.id.replace(/\\./g, '');\n return t('imagery.' + id_safe + '.description', { default: _description });\n };\n\n\n source.best = function() {\n return _best;\n };\n\n\n source.area = function() {\n if (!data.polygon) return Number.MAX_VALUE; // worldwide\n var area = d3_geoArea({ type: 'MultiPolygon', coordinates: [ data.polygon ] });\n return isNaN(area) ? 0 : area;\n };\n\n\n source.imageryUsed = function() {\n return name || source.id;\n };\n\n\n source.template = function(val) {\n if (!arguments.length) return _template;\n if (source.id === 'custom') {\n _template = val;\n }\n return source;\n };\n\n\n source.url = function(coord) {\n var result = _template;\n if (result === '') return result; // source 'none'\n\n\n // Guess a type based on the tokens present in the template\n // (This is for 'custom' source, where we don't know)\n if (!source.type) {\n if (/\\{(proj|wkid|bbox)\\}/.test(_template)) {\n source.type = 'wms';\n source.projection = 'EPSG:3857'; // guess\n } else if (/\\{(x|y)\\}/.test(_template)) {\n source.type = 'tms';\n } else if (/\\{u\\}/.test(_template)) {\n source.type = 'bing';\n }\n }\n\n\n if (source.type === 'wms') {\n var tileToProjectedCoords = (function(x, y, z) {\n //polyfill for IE11, PhantomJS\n var sinh = Math.sinh || function(x) {\n var y = Math.exp(x);\n return (y - 1 / y) / 2;\n };\n\n var zoomSize = Math.pow(2, z);\n var lon = x / zoomSize * Math.PI * 2 - Math.PI;\n var lat = Math.atan(sinh(Math.PI * (1 - 2 * y / zoomSize)));\n\n switch (source.projection) {\n case 'EPSG:4326':\n return {\n x: lon * 180 / Math.PI,\n y: lat * 180 / Math.PI\n };\n default: // EPSG:3857 and synonyms\n var mercCoords = d3_geoMercatorRaw(lon, lat);\n return {\n x: 20037508.34 / Math.PI * mercCoords[0],\n y: 20037508.34 / Math.PI * mercCoords[1]\n };\n }\n });\n\n var tileSize = source.tileSize;\n var projection = source.projection;\n var minXmaxY = tileToProjectedCoords(coord[0], coord[1], coord[2]);\n var maxXminY = tileToProjectedCoords(coord[0]+1, coord[1]+1, coord[2]);\n\n result = result.replace(/\\{(\\w+)\\}/g, function (token, key) {\n switch (key) {\n case 'width':\n case 'height':\n return tileSize;\n case 'proj':\n return projection;\n case 'wkid':\n return projection.replace(/^EPSG:/, '');\n case 'bbox':\n return minXmaxY.x + ',' + maxXminY.y + ',' + maxXminY.x + ',' + minXmaxY.y;\n case 'w':\n return minXmaxY.x;\n case 's':\n return maxXminY.y;\n case 'n':\n return maxXminY.x;\n case 'e':\n return minXmaxY.y;\n default:\n return token;\n }\n });\n\n } else if (source.type === 'tms') {\n result = result\n .replace('{x}', coord[0])\n .replace('{y}', coord[1])\n // TMS-flipped y coordinate\n .replace(/\\{[t-]y\\}/, Math.pow(2, coord[2]) - coord[1] - 1)\n .replace(/\\{z(oom)?\\}/, coord[2])\n // only fetch retina tiles for retina screens\n .replace(/\\{@2x\\}|\\{r\\}/, isRetina ? '@2x' : '');\n\n } else if (source.type === 'bing') {\n result = result\n .replace('{u}', function() {\n var u = '';\n for (var zoom = coord[2]; zoom > 0; zoom--) {\n var b = 0;\n var mask = 1 << (zoom - 1);\n if ((coord[0] & mask) !== 0) b++;\n if ((coord[1] & mask) !== 0) b += 2;\n u += b.toString();\n }\n return u;\n });\n }\n\n // these apply to any type..\n result = result.replace(/\\{switch:([^}]+)\\}/, function(s, r) {\n var subdomains = r.split(',');\n return subdomains[(coord[0] + coord[1]) % subdomains.length];\n });\n\n\n return result;\n };\n\n\n source.validZoom = function(z) {\n return source.zoomExtent[0] <= z &&\n (source.overzoom || source.zoomExtent[1] > z);\n };\n\n\n source.isLocatorOverlay = function() {\n return source.id === 'mapbox_locator_overlay';\n };\n\n\n /* hides a source from the list, but leaves it available for use */\n source.isHidden = function() {\n return source.id === 'DigitalGlobe-Premium-vintage' ||\n source.id === 'DigitalGlobe-Standard-vintage';\n };\n\n\n source.copyrightNotices = function() {};\n\n\n source.getMetadata = function(center, tileCoord, callback) {\n var vintage = {\n start: localeDateString(source.startDate),\n end: localeDateString(source.endDate)\n };\n vintage.range = vintageRange(vintage);\n\n var metadata = { vintage: vintage };\n callback(null, metadata);\n };\n\n\n return source;\n}\n\n\nrendererBackgroundSource.Bing = function(data, dispatch) {\n // http://msdn.microsoft.com/en-us/library/ff701716.aspx\n // http://msdn.microsoft.com/en-us/library/ff701701.aspx\n\n data.template = 'https://ecn.t{switch:0,1,2,3}.tiles.virtualearth.net/tiles/a{u}.jpeg?g=587&mkt=en-gb&n=z';\n\n var bing = rendererBackgroundSource(data);\n // var key = 'Arzdiw4nlOJzRwOz__qailc8NiR31Tt51dN2D7cm57NrnceZnCpgOkmJhNpGoppU'; // P2, JOSM, etc\n var key = 'Ak5oTE46TUbjRp08OFVcGpkARErDobfpuyNKa-W2mQ8wbt1K1KL8p1bIRwWwcF-Q'; // iD\n\n\n var url = 'https://dev.virtualearth.net/REST/v1/Imagery/Metadata/Aerial?include=ImageryProviders&key=' + key;\n var cache = {};\n var inflight = {};\n var providers = [];\n\n d3_json(url)\n .then(function(json) {\n providers = json.resourceSets[0].resources[0].imageryProviders.map(function(provider) {\n return {\n attribution: provider.attribution,\n areas: provider.coverageAreas.map(function(area) {\n return {\n zoom: [area.zoomMin, area.zoomMax],\n extent: geoExtent([area.bbox[1], area.bbox[0]], [area.bbox[3], area.bbox[2]])\n };\n })\n };\n });\n dispatch.call('change');\n })\n .catch(function() {\n /* ignore */\n });\n\n\n bing.copyrightNotices = function(zoom, extent) {\n zoom = Math.min(zoom, 21);\n return providers.filter(function(provider) {\n return provider.areas.some(function(area) {\n return extent.intersects(area.extent) &&\n area.zoom[0] <= zoom &&\n area.zoom[1] >= zoom;\n });\n }).map(function(provider) {\n return provider.attribution;\n }).join(', ');\n };\n\n\n bing.getMetadata = function(center, tileCoord, callback) {\n var tileID = tileCoord.slice(0, 3).join('/');\n var zoom = Math.min(tileCoord[2], 21);\n var centerPoint = center[1] + ',' + center[0]; // lat,lng\n var url = 'https://dev.virtualearth.net/REST/v1/Imagery/Metadata/Aerial/' + centerPoint +\n '?zl=' + zoom + '&key=' + key;\n\n if (inflight[tileID]) return;\n\n if (!cache[tileID]) {\n cache[tileID] = {};\n }\n if (cache[tileID] && cache[tileID].metadata) {\n return callback(null, cache[tileID].metadata);\n }\n\n inflight[tileID] = true;\n d3_json(url)\n .then(function(result) {\n delete inflight[tileID];\n if (!result) {\n throw new Error('Unknown Error');\n }\n var vintage = {\n start: localeDateString(result.resourceSets[0].resources[0].vintageStart),\n end: localeDateString(result.resourceSets[0].resources[0].vintageEnd)\n };\n vintage.range = vintageRange(vintage);\n\n var metadata = { vintage: vintage };\n cache[tileID].metadata = metadata;\n if (callback) callback(null, metadata);\n })\n .catch(function(err) {\n delete inflight[tileID];\n if (callback) callback(err.message);\n });\n };\n\n\n bing.terms_url = 'https://blog.openstreetmap.org/2010/11/30/microsoft-imagery-details';\n\n\n return bing;\n};\n\n\n\nrendererBackgroundSource.Esri = function(data) {\n // in addition to using the tilemap at zoom level 20, overzoom real tiles - #4327 (deprecated technique, but it works)\n if (data.template.match(/blankTile/) === null) {\n data.template = data.template + '?blankTile=false';\n }\n\n var esri = rendererBackgroundSource(data);\n var cache = {};\n var inflight = {};\n var _prevCenter;\n\n // use a tilemap service to set maximum zoom for esri tiles dynamically\n // https://developers.arcgis.com/documentation/tiled-elevation-service/\n esri.fetchTilemap = function(center) {\n // skip if we have already fetched a tilemap within 5km\n if (_prevCenter && geoSphericalDistance(center, _prevCenter) < 5000) return;\n _prevCenter = center;\n\n // tiles are available globally to zoom level 19, afterward they may or may not be present\n var z = 20;\n\n // first generate a random url using the template\n var dummyUrl = esri.url([1,2,3]);\n\n // calculate url z/y/x from the lat/long of the center of the map\n var x = (Math.floor((center[0] + 180) / 360 * Math.pow(2, z)));\n var y = (Math.floor((1 - Math.log(Math.tan(center[1] * Math.PI / 180) + 1 / Math.cos(center[1] * Math.PI / 180)) / Math.PI) / 2 * Math.pow(2, z)));\n\n // fetch an 8x8 grid to leverage cache\n var tilemapUrl = dummyUrl.replace(/tile\\/[0-9]+\\/[0-9]+\\/[0-9]+\\?blankTile=false/, 'tilemap') + '/' + z + '/' + y + '/' + x + '/8/8';\n\n // make the request and introspect the response from the tilemap server\n d3_json(tilemapUrl)\n .then(function(tilemap) {\n if (!tilemap) {\n throw new Error('Unknown Error');\n }\n var hasTiles = true;\n for (var i = 0; i < tilemap.data.length; i++) {\n // 0 means an individual tile in the grid doesn't exist\n if (!tilemap.data[i]) {\n hasTiles = false;\n break;\n }\n }\n\n // if any tiles are missing at level 20 we restrict maxZoom to 19\n esri.zoomExtent[1] = (hasTiles ? 22 : 19);\n })\n .catch(function() {\n /* ignore */\n });\n };\n\n\n esri.getMetadata = function(center, tileCoord, callback) {\n var tileID = tileCoord.slice(0, 3).join('/');\n var zoom = Math.min(tileCoord[2], esri.zoomExtent[1]);\n var centerPoint = center[0] + ',' + center[1]; // long, lat (as it should be)\n var unknown = t('info_panels.background.unknown');\n var metadataLayer;\n var vintage = {};\n var metadata = {};\n\n if (inflight[tileID]) return;\n\n switch (true) {\n case (zoom >= 20 && esri.id === 'EsriWorldImageryClarity'):\n metadataLayer = 4;\n break;\n case zoom >= 19:\n metadataLayer = 3;\n break;\n case zoom >= 17:\n metadataLayer = 2;\n break;\n case zoom >= 13:\n metadataLayer = 0;\n break;\n default:\n metadataLayer = 99;\n }\n\n var url;\n // build up query using the layer appropriate to the current zoom\n if (esri.id === 'EsriWorldImagery') {\n url = 'https://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/';\n } else if (esri.id === 'EsriWorldImageryClarity') {\n url = 'https://serviceslab.arcgisonline.com/arcgis/rest/services/Clarity_World_Imagery/MapServer/';\n }\n\n url += metadataLayer + '/query?returnGeometry=false&geometry=' + centerPoint + '&inSR=4326&geometryType=esriGeometryPoint&outFields=*&f=json';\n\n if (!cache[tileID]) {\n cache[tileID] = {};\n }\n if (cache[tileID] && cache[tileID].metadata) {\n return callback(null, cache[tileID].metadata);\n }\n\n // accurate metadata is only available >= 13\n if (metadataLayer === 99) {\n vintage = {\n start: null,\n end: null,\n range: null\n };\n metadata = {\n vintage: null,\n source: unknown,\n description: unknown,\n resolution: unknown,\n accuracy: unknown\n };\n\n callback(null, metadata);\n\n } else {\n inflight[tileID] = true;\n d3_json(url)\n .then(function(result) {\n delete inflight[tileID];\n if (!result) {\n throw new Error('Unknown Error');\n } else if (result.features && result.features.length < 1) {\n throw new Error('No Results');\n } else if (result.error && result.error.message) {\n throw new Error(result.error.message);\n }\n\n // pass through the discrete capture date from metadata\n var captureDate = localeDateString(result.features[0].attributes.SRC_DATE2);\n vintage = {\n start: captureDate,\n end: captureDate,\n range: captureDate\n };\n metadata = {\n vintage: vintage,\n source: clean(result.features[0].attributes.NICE_NAME),\n description: clean(result.features[0].attributes.NICE_DESC),\n resolution: clean(+parseFloat(result.features[0].attributes.SRC_RES).toFixed(4)),\n accuracy: clean(+parseFloat(result.features[0].attributes.SRC_ACC).toFixed(4))\n };\n\n // append units - meters\n if (isFinite(metadata.resolution)) {\n metadata.resolution += ' m';\n }\n if (isFinite(metadata.accuracy)) {\n metadata.accuracy += ' m';\n }\n\n cache[tileID].metadata = metadata;\n if (callback) callback(null, metadata);\n })\n .catch(function(err) {\n delete inflight[tileID];\n if (callback) callback(err.message);\n });\n }\n\n\n function clean(val) {\n return String(val).trim() || unknown;\n }\n };\n\n return esri;\n};\n\n\nrendererBackgroundSource.None = function() {\n var source = rendererBackgroundSource({ id: 'none', template: '' });\n\n\n source.name = function() {\n return t('background.none');\n };\n\n\n source.imageryUsed = function() {\n return null;\n };\n\n\n source.area = function() {\n return -1; // sources in background pane are sorted by area\n };\n\n\n return source;\n};\n\n\nrendererBackgroundSource.Custom = function(template) {\n var source = rendererBackgroundSource({ id: 'custom', template: template });\n\n\n source.name = function() {\n return t('background.custom');\n };\n\n\n source.imageryUsed = function() {\n // sanitize personal connection tokens - #6801\n var cleaned = source.template();\n\n // from query string parameters\n if (cleaned.indexOf('?') !== -1) {\n var parts = cleaned.split('?', 2);\n var qs = utilStringQs(parts[1]);\n\n ['access_token', 'connectId', 'token'].forEach(function(param) {\n if (qs[param]) {\n qs[param] = '{apikey}';\n }\n });\n cleaned = parts[0] + '?' + utilQsString(qs, true); // true = soft encode\n }\n\n // from wms/wmts api path parameters\n cleaned = cleaned.replace(/token\\/(\\w+)/, 'token/{apikey}');\n\n return 'Custom (' + cleaned + ' )';\n };\n\n\n source.area = function() {\n return -2; // sources in background pane are sorted by area\n };\n\n\n return source;\n};\n","import { select as d3_select } from 'd3-selection';\nimport { t } from '../core/localizer';\n\nimport { geoScaleToZoom, geoVecLength } from '../geo';\nimport { utilPrefixCSSProperty, utilTiler } from '../util';\n\n\nexport function rendererTileLayer(context) {\n var transformProp = utilPrefixCSSProperty('Transform');\n var tiler = utilTiler();\n\n var _tileSize = 256;\n var _projection;\n var _cache = {};\n var _tileOrigin;\n var _zoom;\n var _source;\n\n\n function tileSizeAtZoom(d, z) {\n var EPSILON = 0.002; // close seams\n return ((_tileSize * Math.pow(2, z - d[2])) / _tileSize) + EPSILON;\n }\n\n\n function atZoom(t, distance) {\n var power = Math.pow(2, distance);\n return [\n Math.floor(t[0] * power),\n Math.floor(t[1] * power),\n t[2] + distance\n ];\n }\n\n\n function lookUp(d) {\n for (var up = -1; up > -d[2]; up--) {\n var tile = atZoom(d, up);\n if (_cache[_source.url(tile)] !== false) {\n return tile;\n }\n }\n }\n\n\n function uniqueBy(a, n) {\n var o = [];\n var seen = {};\n for (var i = 0; i < a.length; i++) {\n if (seen[a[i][n]] === undefined) {\n o.push(a[i]);\n seen[a[i][n]] = true;\n }\n }\n return o;\n }\n\n\n function addSource(d) {\n d.push(_source.url(d));\n return d;\n }\n\n\n // Update tiles based on current state of `projection`.\n function background(selection) {\n _zoom = geoScaleToZoom(_projection.scale(), _tileSize);\n\n var pixelOffset;\n if (_source) {\n pixelOffset = [\n _source.offset()[0] * Math.pow(2, _zoom),\n _source.offset()[1] * Math.pow(2, _zoom)\n ];\n } else {\n pixelOffset = [0, 0];\n }\n\n var translate = [\n _projection.translate()[0] + pixelOffset[0],\n _projection.translate()[1] + pixelOffset[1]\n ];\n\n tiler\n .scale(_projection.scale() * 2 * Math.PI)\n .translate(translate);\n\n _tileOrigin = [\n _projection.scale() * Math.PI - translate[0],\n _projection.scale() * Math.PI - translate[1]\n ];\n\n render(selection);\n }\n\n\n // Derive the tiles onscreen, remove those offscreen and position them.\n // Important that this part not depend on `_projection` because it's\n // rentered when tiles load/error (see #644).\n function render(selection) {\n if (!_source) return;\n var requests = [];\n var showDebug = context.getDebug('tile') && !_source.overlay;\n\n if (_source.validZoom(_zoom)) {\n tiler.skipNullIsland(!!_source.overlay);\n\n tiler().forEach(function(d) {\n addSource(d);\n if (d[3] === '') return;\n if (typeof d[3] !== 'string') return; // Workaround for #2295\n requests.push(d);\n if (_cache[d[3]] === false && lookUp(d)) {\n requests.push(addSource(lookUp(d)));\n }\n });\n\n requests = uniqueBy(requests, 3).filter(function(r) {\n // don't re-request tiles which have failed in the past\n return _cache[r[3]] !== false;\n });\n }\n\n function load(d) {\n _cache[d[3]] = true;\n d3_select(this)\n .on('error', null)\n .on('load', null)\n .classed('tile-loaded', true);\n render(selection);\n }\n\n function error(d) {\n _cache[d[3]] = false;\n d3_select(this)\n .on('error', null)\n .on('load', null)\n .remove();\n render(selection);\n }\n\n function imageTransform(d) {\n var ts = _tileSize * Math.pow(2, _zoom - d[2]);\n var scale = tileSizeAtZoom(d, _zoom);\n return 'translate(' +\n ((d[0] * ts) - _tileOrigin[0]) + 'px,' +\n ((d[1] * ts) - _tileOrigin[1]) + 'px) ' +\n 'scale(' + scale + ',' + scale + ')';\n }\n\n function tileCenter(d) {\n var ts = _tileSize * Math.pow(2, _zoom - d[2]);\n return [\n ((d[0] * ts) - _tileOrigin[0] + (ts / 2)),\n ((d[1] * ts) - _tileOrigin[1] + (ts / 2))\n ];\n }\n\n function debugTransform(d) {\n var coord = tileCenter(d);\n return 'translate(' + coord[0] + 'px,' + coord[1] + 'px)';\n }\n\n\n // Pick a representative tile near the center of the viewport\n // (This is useful for sampling the imagery vintage)\n var dims = tiler.size();\n var mapCenter = [dims[0] / 2, dims[1] / 2];\n var minDist = Math.max(dims[0], dims[1]);\n var nearCenter;\n\n requests.forEach(function(d) {\n var c = tileCenter(d);\n var dist = geoVecLength(c, mapCenter);\n if (dist < minDist) {\n minDist = dist;\n nearCenter = d;\n }\n });\n\n\n var image = selection.selectAll('img')\n .data(requests, function(d) { return d[3]; });\n\n image.exit()\n .style(transformProp, imageTransform)\n .classed('tile-removing', true)\n .classed('tile-center', false)\n .each(function() {\n var tile = d3_select(this);\n window.setTimeout(function() {\n if (tile.classed('tile-removing')) {\n tile.remove();\n }\n }, 300);\n });\n\n image.enter()\n .append('img')\n .attr('class', 'tile')\n .attr('draggable', 'false')\n .style('width', _tileSize + 'px')\n .style('height', _tileSize + 'px')\n .attr('src', function(d) { return d[3]; })\n .on('error', error)\n .on('load', load)\n .merge(image)\n .style(transformProp, imageTransform)\n .classed('tile-debug', showDebug)\n .classed('tile-removing', false)\n .classed('tile-center', function(d) { return d === nearCenter; });\n\n\n\n var debug = selection.selectAll('.tile-label-debug')\n .data(showDebug ? requests : [], function(d) { return d[3]; });\n\n debug.exit()\n .remove();\n\n if (showDebug) {\n var debugEnter = debug.enter()\n .append('div')\n .attr('class', 'tile-label-debug');\n\n debugEnter\n .append('div')\n .attr('class', 'tile-label-debug-coord');\n\n debugEnter\n .append('div')\n .attr('class', 'tile-label-debug-vintage');\n\n debug = debug.merge(debugEnter);\n\n debug\n .style(transformProp, debugTransform);\n\n debug\n .selectAll('.tile-label-debug-coord')\n .text(function(d) { return d[2] + ' / ' + d[0] + ' / ' + d[1]; });\n\n debug\n .selectAll('.tile-label-debug-vintage')\n .each(function(d) {\n var span = d3_select(this);\n var center = context.projection.invert(tileCenter(d));\n _source.getMetadata(center, d, function(err, result) {\n span.text((result && result.vintage && result.vintage.range) ||\n t('info_panels.background.vintage') + ': ' + t('info_panels.background.unknown')\n );\n });\n });\n }\n\n }\n\n\n background.projection = function(val) {\n if (!arguments.length) return _projection;\n _projection = val;\n return background;\n };\n\n\n background.dimensions = function(val) {\n if (!arguments.length) return tiler.size();\n tiler.size(val);\n return background;\n };\n\n\n background.source = function(val) {\n if (!arguments.length) return _source;\n _source = val;\n _tileSize = _source.tileSize;\n _cache = {};\n tiler.tileSize(_source.tileSize).zoomExtent(_source.zoomExtent);\n return background;\n };\n\n\n return background;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { interpolateNumber as d3_interpolateNumber } from 'd3-interpolate';\nimport { select as d3_select } from 'd3-selection';\n\nimport whichPolygon from 'which-polygon';\n\nimport { prefs } from '../core/preferences';\nimport { fileFetcher } from '../core/file_fetcher';\nimport { geoExtent, geoMetersToOffset, geoOffsetToMeters} from '../geo';\nimport { rendererBackgroundSource } from './background_source';\nimport { rendererTileLayer } from './tile_layer';\nimport { utilQsString, utilStringQs } from '../util';\nimport { utilDetect } from '../util/detect';\nimport { utilRebind } from '../util/rebind';\n\n\nlet _imageryIndex = null;\n\nexport function rendererBackground(context) {\n const dispatch = d3_dispatch('change');\n const detected = utilDetect();\n const baseLayer = rendererTileLayer(context).projection(context.projection);\n let _isValid = true;\n let _overlayLayers = [];\n let _brightness = 1;\n let _contrast = 1;\n let _saturation = 1;\n let _sharpness = 1;\n var _numGridSplits = 0; // No grid by default.\n\n\n function ensureImageryIndex() {\n return fileFetcher.get('imagery')\n .then(sources => {\n if (_imageryIndex) return _imageryIndex;\n\n _imageryIndex = {\n imagery: sources,\n features: {}\n };\n\n // use which-polygon to support efficient index and querying for imagery\n const features = sources.map(source => {\n if (!source.polygon) return null;\n // workaround for editor-layer-index weirdness..\n // Add an extra array nest to each element in `source.polygon`\n // so the rings are not treated as a bunch of holes:\n // what we have: [ [[outer],[hole],[hole]] ]\n // what we want: [ [[outer]],[[outer]],[[outer]] ]\n const rings = source.polygon.map(ring => [ring]);\n\n const feature = {\n type: 'Feature',\n properties: { id: source.id },\n geometry: { type: 'MultiPolygon', coordinates: rings }\n };\n\n _imageryIndex.features[source.id] = feature;\n return feature;\n\n }).filter(Boolean);\n\n _imageryIndex.query = whichPolygon({ type: 'FeatureCollection', features: features });\n\n\n // Instantiate `rendererBackgroundSource` objects for each source\n _imageryIndex.backgrounds = sources.map(source => {\n if (source.type === 'bing') {\n return rendererBackgroundSource.Bing(source, dispatch);\n } else if (/^EsriWorldImagery/.test(source.id)) {\n return rendererBackgroundSource.Esri(source);\n } else {\n return rendererBackgroundSource(source);\n }\n });\n\n // Add 'None'\n _imageryIndex.backgrounds.unshift(rendererBackgroundSource.None());\n\n // Add 'Custom'\n let template = prefs('background-custom-template') || '';\n const custom = rendererBackgroundSource.Custom(template);\n _imageryIndex.backgrounds.unshift(custom);\n\n return _imageryIndex;\n });\n }\n\n\n function background(selection) {\n const currSource = baseLayer.source();\n\n // If we are displaying an Esri basemap at high zoom,\n // check its tilemap to see how high the zoom can go\n if (context.map().zoom() > 18) {\n if (currSource && /^EsriWorldImagery/.test(currSource.id)) {\n const center = context.map().center();\n currSource.fetchTilemap(center);\n }\n }\n\n // Is the imagery valid here? - #4827\n const sources = background.sources(context.map().extent());\n const wasValid = _isValid;\n _isValid = !!sources.filter(d => d === currSource).length;\n\n if (wasValid !== _isValid) { // change in valid status\n background.updateImagery();\n }\n\n\n let baseFilter = '';\n if (detected.cssfilters) {\n if (_brightness !== 1) {\n baseFilter += ` brightness(${_brightness})`;\n }\n if (_contrast !== 1) {\n baseFilter += ` contrast(${_contrast})`;\n }\n if (_saturation !== 1) {\n baseFilter += ` saturate(${_saturation})`;\n }\n if (_sharpness < 1) { // gaussian blur\n const blur = d3_interpolateNumber(0.5, 5)(1 - _sharpness);\n baseFilter += ` blur(${blur}px)`;\n }\n }\n\n let base = selection.selectAll('.layer-background')\n .data([0]);\n\n base = base.enter()\n .insert('div', '.layer-data')\n .attr('class', 'layer layer-background')\n .merge(base);\n\n if (detected.cssfilters) {\n base.style('filter', baseFilter || null);\n } else {\n base.style('opacity', _brightness);\n }\n\n\n let imagery = base.selectAll('.layer-imagery')\n .data([0]);\n\n imagery.enter()\n .append('div')\n .attr('class', 'layer layer-imagery')\n .merge(imagery)\n .call(baseLayer);\n\n\n let maskFilter = '';\n let mixBlendMode = '';\n if (detected.cssfilters && _sharpness > 1) { // apply unsharp mask\n mixBlendMode = 'overlay';\n maskFilter = 'saturate(0) blur(3px) invert(1)';\n\n let contrast = _sharpness - 1;\n maskFilter += ` contrast(${contrast})`;\n\n let brightness = d3_interpolateNumber(1, 0.85)(_sharpness - 1);\n maskFilter += ` brightness(${brightness})`;\n }\n\n let mask = base.selectAll('.layer-unsharp-mask')\n .data(detected.cssfilters && _sharpness > 1 ? [0] : []);\n\n mask.exit()\n .remove();\n\n mask.enter()\n .append('div')\n .attr('class', 'layer layer-mask layer-unsharp-mask')\n .merge(mask)\n .call(baseLayer)\n .style('filter', maskFilter || null)\n .style('mix-blend-mode', mixBlendMode || null);\n\n\n let overlays = selection.selectAll('.layer-overlay')\n .data(_overlayLayers, d => d.source().name());\n\n overlays.exit()\n .remove();\n\n overlays.enter()\n .insert('div', '.layer-data')\n .attr('class', 'layer layer-overlay')\n .merge(overlays)\n .each((layer, i, nodes) => d3_select(nodes[i]).call(layer));\n }\n\n background.numGridSplits = function(_) {\n if (!arguments.length) return _numGridSplits;\n _numGridSplits = _;\n dispatch.call('change');\n return background;\n };\n\n background.updateImagery = function() {\n let currSource = baseLayer.source();\n if (context.inIntro() || !currSource) return;\n\n let o = _overlayLayers\n .filter(d => !d.source().isLocatorOverlay() && !d.source().isHidden())\n .map(d => d.source().id)\n .join(',');\n\n const meters = geoOffsetToMeters(currSource.offset());\n const EPSILON = 0.01;\n const x = +meters[0].toFixed(2);\n const y = +meters[1].toFixed(2);\n let hash = utilStringQs(window.location.hash);\n\n let id = currSource.id;\n if (id === 'custom') {\n id = `custom:${currSource.template()}`;\n }\n\n if (id) {\n hash.background = id;\n } else {\n delete hash.background;\n }\n\n if (o) {\n hash.overlays = o;\n } else {\n delete hash.overlays;\n }\n\n if (Math.abs(x) > EPSILON || Math.abs(y) > EPSILON) {\n hash.offset = `${x},${y}`;\n } else {\n delete hash.offset;\n }\n\n if (!window.mocha) {\n window.location.replace('#' + utilQsString(hash, true));\n }\n\n let imageryUsed = [];\n let photoOverlaysUsed = [];\n\n const currUsed = currSource.imageryUsed();\n if (currUsed && _isValid) {\n imageryUsed.push(currUsed);\n }\n\n _overlayLayers\n .filter(d => !d.source().isLocatorOverlay() && !d.source().isHidden())\n .forEach(d => imageryUsed.push(d.source().imageryUsed()));\n\n const dataLayer = context.layers().layer('data');\n if (dataLayer && dataLayer.enabled() && dataLayer.hasData()) {\n imageryUsed.push(dataLayer.getSrc());\n }\n\n const photoOverlayLayers = {\n streetside: 'Bing Streetside',\n mapillary: 'Mapillary Images',\n 'mapillary-map-features': 'Mapillary Map Features',\n 'mapillary-signs': 'Mapillary Signs',\n openstreetcam: 'OpenStreetCam Images'\n };\n\n for (let layerID in photoOverlayLayers) {\n const layer = context.layers().layer(layerID);\n if (layer && layer.enabled()) {\n photoOverlaysUsed.push(layerID);\n imageryUsed.push(photoOverlayLayers[layerID]);\n }\n }\n\n context.history().imageryUsed(imageryUsed);\n context.history().photoOverlaysUsed(photoOverlaysUsed);\n };\n\n\n background.sources = (extent, zoom, includeCurrent) => {\n if (!_imageryIndex) return []; // called before init()?\n\n let visible = {};\n (_imageryIndex.query.bbox(extent.rectangle(), true) || [])\n .forEach(d => visible[d.id] = true);\n\n const currSource = baseLayer.source();\n\n return _imageryIndex.backgrounds.filter(source => {\n if (!source.polygon) return true; // always include imagery with worldwide coverage\n if (includeCurrent && currSource === source) return true; // optionally include the current imagery\n if (zoom && zoom < 6) return false; // optionally exclude local imagery at low zooms\n return visible[source.id]; // include imagery visible in given extent\n });\n };\n\n\n background.dimensions = (val) => {\n if (!val) return;\n baseLayer.dimensions(val);\n _overlayLayers.forEach(layer => layer.dimensions(val));\n };\n\n\n background.baseLayerSource = function(d) {\n if (!arguments.length) return baseLayer.source();\n\n // test source against OSM imagery blacklists..\n const osm = context.connection();\n if (!osm) return background;\n\n const blacklists = osm.imageryBlacklists();\n const template = d.template();\n let fail = false;\n let tested = 0;\n let regex;\n\n for (let i = 0; i < blacklists.length; i++) {\n try {\n regex = new RegExp(blacklists[i]);\n fail = regex.test(template);\n tested++;\n if (fail) break;\n } catch (e) {\n /* noop */\n }\n }\n\n // ensure at least one test was run.\n if (!tested) {\n regex = new RegExp('.*\\.google(apis)?\\..*/(vt|kh)[\\?/].*([xyz]=.*){3}.*');\n fail = regex.test(template);\n }\n\n baseLayer.source(!fail ? d : background.findSource('none'));\n dispatch.call('change');\n background.updateImagery();\n return background;\n };\n\n\n background.findSource = (id) => {\n if (!id || !_imageryIndex) return null; // called before init()?\n return _imageryIndex.backgrounds.find(d => d.id && d.id === id);\n };\n\n\n background.bing = () => {\n background.baseLayerSource(background.findSource('Bing'));\n };\n\n\n background.showsLayer = (d) => {\n const currSource = baseLayer.source();\n if (!d || !currSource) return false;\n return d.id === currSource.id || _overlayLayers.some(layer => d.id === layer.source().id);\n };\n\n\n background.overlayLayerSources = () => {\n return _overlayLayers.map(layer => layer.source());\n };\n\n\n background.toggleOverlayLayer = (d) => {\n let layer;\n for (let i = 0; i < _overlayLayers.length; i++) {\n layer = _overlayLayers[i];\n if (layer.source() === d) {\n _overlayLayers.splice(i, 1);\n dispatch.call('change');\n background.updateImagery();\n return;\n }\n }\n\n layer = rendererTileLayer(context)\n .source(d)\n .projection(context.projection)\n .dimensions(baseLayer.dimensions()\n );\n\n _overlayLayers.push(layer);\n dispatch.call('change');\n background.updateImagery();\n };\n\n\n background.nudge = (d, zoom) => {\n const currSource = baseLayer.source();\n if (currSource) {\n currSource.nudge(d, zoom);\n dispatch.call('change');\n background.updateImagery();\n }\n return background;\n };\n\n\n background.offset = function(d) {\n const currSource = baseLayer.source();\n if (!arguments.length) {\n return (currSource && currSource.offset()) || [0, 0];\n }\n if (currSource) {\n currSource.offset(d);\n dispatch.call('change');\n background.updateImagery();\n }\n return background;\n };\n\n\n background.brightness = function(d) {\n if (!arguments.length) return _brightness;\n _brightness = d;\n if (context.mode()) dispatch.call('change');\n return background;\n };\n\n\n background.contrast = function(d) {\n if (!arguments.length) return _contrast;\n _contrast = d;\n if (context.mode()) dispatch.call('change');\n return background;\n };\n\n\n background.saturation = function(d) {\n if (!arguments.length) return _saturation;\n _saturation = d;\n if (context.mode()) dispatch.call('change');\n return background;\n };\n\n\n background.sharpness = function(d) {\n if (!arguments.length) return _sharpness;\n _sharpness = d;\n if (context.mode()) dispatch.call('change');\n return background;\n };\n\n let _loadPromise;\n\n background.ensureLoaded = () => {\n\n if (_loadPromise) return _loadPromise;\n\n function parseMapParams(qmap) {\n if (!qmap) return false;\n const params = qmap.split('/').map(Number);\n if (params.length < 3 || params.some(isNaN)) return false;\n return geoExtent([params[2], params[1]]); // lon,lat\n }\n\n const hash = utilStringQs(window.location.hash);\n const requested = hash.background || hash.layer;\n let extent = parseMapParams(hash.map);\n\n return _loadPromise = ensureImageryIndex()\n .then(imageryIndex => {\n const first = imageryIndex.backgrounds.length && imageryIndex.backgrounds[0];\n\n let best;\n if (!requested && extent) {\n best = background.sources(extent).find(s => s.best());\n }\n\n // Decide which background layer to display\n if (requested && requested.indexOf('custom:') === 0) {\n const template = requested.replace(/^custom:/, '');\n const custom = background.findSource('custom');\n background.baseLayerSource(custom.template(template));\n prefs('background-custom-template', template);\n } else {\n background.baseLayerSource(\n background.findSource(requested) ||\n best ||\n background.findSource(prefs('background-last-used')) ||\n background.findSource('Maxar-Premium') ||\n background.findSource('Bing') ||\n first ||\n background.findSource('none')\n );\n }\n\n const locator = imageryIndex.backgrounds.find(d => d.overlay && d.default);\n if (locator) {\n background.toggleOverlayLayer(locator);\n }\n\n const overlays = (hash.overlays || '').split(',');\n overlays.forEach(overlay => {\n overlay = background.findSource(overlay);\n if (overlay) {\n background.toggleOverlayLayer(overlay);\n }\n });\n\n if (hash.gpx) {\n const gpx = context.layers().layer('data');\n if (gpx) {\n gpx.url(hash.gpx, '.gpx');\n }\n }\n\n if (hash.offset) {\n const offset = hash.offset\n .replace(/;/g, ',')\n .split(',')\n .map(n => !isNaN(n) && n);\n\n if (offset.length === 2) {\n background.offset(geoMetersToOffset(offset));\n }\n }\n })\n .catch(() => { /* ignore */ });\n };\n\n\n return utilRebind(background, dispatch, 'on');\n }\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\n\nimport { prefs } from '../core/preferences';\nimport { osmEntity } from '../osm';\nimport { utilRebind } from '../util/rebind';\nimport { utilArrayGroupBy, utilArrayUnion, utilQsString, utilStringQs } from '../util';\n\n\nexport function rendererFeatures(context) {\n var dispatch = d3_dispatch('change', 'redraw');\n var features = utilRebind({}, dispatch, 'on');\n var _deferred = new Set();\n\n var traffic_roads = {\n 'motorway': true,\n 'motorway_link': true,\n 'trunk': true,\n 'trunk_link': true,\n 'primary': true,\n 'primary_link': true,\n 'secondary': true,\n 'secondary_link': true,\n 'tertiary': true,\n 'tertiary_link': true,\n 'residential': true,\n 'unclassified': true,\n 'living_street': true\n };\n\n var service_roads = {\n 'service': true,\n 'road': true,\n 'track': true\n };\n\n var paths = {\n 'path': true,\n 'footway': true,\n 'cycleway': true,\n 'bridleway': true,\n 'steps': true,\n 'pedestrian': true\n };\n\n var past_futures = {\n 'proposed': true,\n 'construction': true,\n 'abandoned': true,\n 'dismantled': true,\n 'disused': true,\n 'razed': true,\n 'demolished': true,\n 'obliterated': true\n };\n\n var _cullFactor = 1;\n var _cache = {};\n var _rules = {};\n var _stats = {};\n var _keys = [];\n var _hidden = [];\n var _forceVisible = {};\n\n\n function update() {\n if (!window.mocha) {\n var hash = utilStringQs(window.location.hash);\n var disabled = features.disabled();\n if (disabled.length) {\n hash.disable_features = disabled.join(',');\n } else {\n delete hash.disable_features;\n }\n window.location.replace('#' + utilQsString(hash, true));\n prefs('disabled-features', disabled.join(','));\n }\n _hidden = features.hidden();\n dispatch.call('change');\n dispatch.call('redraw');\n }\n\n\n function defineRule(k, filter, max) {\n var isEnabled = true;\n\n _keys.push(k);\n _rules[k] = {\n filter: filter,\n enabled: isEnabled, // whether the user wants it enabled..\n count: 0,\n currentMax: (max || Infinity),\n defaultMax: (max || Infinity),\n enable: function() { this.enabled = true; this.currentMax = this.defaultMax; },\n disable: function() { this.enabled = false; this.currentMax = 0; },\n hidden: function() {\n return (this.count === 0 && !this.enabled) ||\n this.count > this.currentMax * _cullFactor;\n },\n autoHidden: function() { return this.hidden() && this.currentMax > 0; }\n };\n }\n\n\n defineRule('points', function isPoint(tags, geometry) {\n return geometry === 'point';\n }, 200);\n\n defineRule('traffic_roads', function isTrafficRoad(tags) {\n return traffic_roads[tags.highway];\n });\n\n defineRule('service_roads', function isServiceRoad(tags) {\n return service_roads[tags.highway];\n });\n\n defineRule('paths', function isPath(tags) {\n return paths[tags.highway];\n });\n\n defineRule('buildings', function isBuilding(tags) {\n return (\n (!!tags.building && tags.building !== 'no') ||\n tags.parking === 'multi-storey' ||\n tags.parking === 'sheds' ||\n tags.parking === 'carports' ||\n tags.parking === 'garage_boxes'\n );\n }, 250);\n\n defineRule('building_parts', function isBuildingPart(tags) {\n return tags['building:part'];\n });\n\n defineRule('indoor', function isIndoor(tags) {\n return tags.indoor;\n });\n\n defineRule('landuse', function isLanduse(tags, geometry) {\n return geometry === 'area' &&\n !_rules.buildings.filter(tags) &&\n !_rules.building_parts.filter(tags) &&\n !_rules.indoor.filter(tags) &&\n !_rules.water.filter(tags) &&\n !_rules.pistes.filter(tags);\n });\n\n defineRule('boundaries', function isBoundary(tags) {\n return (\n !!tags.boundary\n ) && !(\n traffic_roads[tags.highway] ||\n service_roads[tags.highway] ||\n paths[tags.highway] ||\n tags.waterway ||\n tags.railway ||\n tags.landuse ||\n tags.natural ||\n tags.building ||\n tags.power\n );\n });\n\n defineRule('water', function isWater(tags) {\n return (\n !!tags.waterway ||\n tags.natural === 'water' ||\n tags.natural === 'coastline' ||\n tags.natural === 'bay' ||\n tags.landuse === 'pond' ||\n tags.landuse === 'basin' ||\n tags.landuse === 'reservoir' ||\n tags.landuse === 'salt_pond'\n );\n });\n\n defineRule('rail', function isRail(tags) {\n return (\n !!tags.railway ||\n tags.landuse === 'railway'\n ) && !(\n traffic_roads[tags.highway] ||\n service_roads[tags.highway] ||\n paths[tags.highway]\n );\n });\n\n defineRule('pistes', function isPiste(tags) {\n return tags['piste:type'];\n });\n\n defineRule('aerialways', function isPiste(tags) {\n return tags.aerialway &&\n tags.aerialway !== 'yes' &&\n tags.aerialway !== 'station';\n });\n\n defineRule('power', function isPower(tags) {\n return !!tags.power;\n });\n\n // contains a past/future tag, but not in active use as a road/path/cycleway/etc..\n defineRule('past_future', function isPastFuture(tags) {\n if (\n traffic_roads[tags.highway] ||\n service_roads[tags.highway] ||\n paths[tags.highway]\n ) { return false; }\n\n var strings = Object.keys(tags);\n\n for (var i = 0; i < strings.length; i++) {\n var s = strings[i];\n if (past_futures[s] || past_futures[tags[s]]) { return true; }\n }\n return false;\n });\n\n // Lines or areas that don't match another feature filter.\n // IMPORTANT: The 'others' feature must be the last one defined,\n // so that code in getMatches can skip this test if `hasMatch = true`\n defineRule('others', function isOther(tags, geometry) {\n return (geometry === 'line' || geometry === 'area');\n });\n\n\n\n features.features = function() {\n return _rules;\n };\n\n\n features.keys = function() {\n return _keys;\n };\n\n\n features.enabled = function(k) {\n if (!arguments.length) {\n return _keys.filter(function(k) { return _rules[k].enabled; });\n }\n return _rules[k] && _rules[k].enabled;\n };\n\n\n features.disabled = function(k) {\n if (!arguments.length) {\n return _keys.filter(function(k) { return !_rules[k].enabled; });\n }\n return _rules[k] && !_rules[k].enabled;\n };\n\n\n features.hidden = function(k) {\n if (!arguments.length) {\n return _keys.filter(function(k) { return _rules[k].hidden(); });\n }\n return _rules[k] && _rules[k].hidden();\n };\n\n\n features.autoHidden = function(k) {\n if (!arguments.length) {\n return _keys.filter(function(k) { return _rules[k].autoHidden(); });\n }\n return _rules[k] && _rules[k].autoHidden();\n };\n\n\n features.enable = function(k) {\n if (_rules[k] && !_rules[k].enabled) {\n _rules[k].enable();\n update();\n }\n };\n\n features.enableAll = function() {\n var didEnable = false;\n for (var k in _rules) {\n if (!_rules[k].enabled) {\n didEnable = true;\n _rules[k].enable();\n }\n }\n if (didEnable) update();\n };\n\n\n features.disable = function(k) {\n if (_rules[k] && _rules[k].enabled) {\n _rules[k].disable();\n update();\n }\n };\n\n features.disableAll = function() {\n var didDisable = false;\n for (var k in _rules) {\n if (_rules[k].enabled) {\n didDisable = true;\n _rules[k].disable();\n }\n }\n if (didDisable) update();\n };\n\n\n features.toggle = function(k) {\n if (_rules[k]) {\n (function(f) { return f.enabled ? f.disable() : f.enable(); }(_rules[k]));\n update();\n }\n };\n\n\n features.resetStats = function() {\n for (var i = 0; i < _keys.length; i++) {\n _rules[_keys[i]].count = 0;\n }\n dispatch.call('change');\n };\n\n\n features.gatherStats = function(d, resolver, dimensions) {\n var needsRedraw = false;\n var types = utilArrayGroupBy(d, 'type');\n var entities = [].concat(types.relation || [], types.way || [], types.node || []);\n var currHidden, geometry, matches, i, j;\n\n for (i = 0; i < _keys.length; i++) {\n _rules[_keys[i]].count = 0;\n }\n\n // adjust the threshold for point/building culling based on viewport size..\n // a _cullFactor of 1 corresponds to a 1000x1000px viewport..\n _cullFactor = dimensions[0] * dimensions[1] / 1000000;\n\n for (i = 0; i < entities.length; i++) {\n geometry = entities[i].geometry(resolver);\n matches = Object.keys(features.getMatches(entities[i], resolver, geometry));\n for (j = 0; j < matches.length; j++) {\n _rules[matches[j]].count++;\n }\n }\n\n currHidden = features.hidden();\n if (currHidden !== _hidden) {\n _hidden = currHidden;\n needsRedraw = true;\n dispatch.call('change');\n }\n\n return needsRedraw;\n };\n\n\n features.stats = function() {\n for (var i = 0; i < _keys.length; i++) {\n _stats[_keys[i]] = _rules[_keys[i]].count;\n }\n\n return _stats;\n };\n\n\n features.clear = function(d) {\n for (var i = 0; i < d.length; i++) {\n features.clearEntity(d[i]);\n }\n };\n\n\n features.clearEntity = function(entity) {\n delete _cache[osmEntity.key(entity)];\n };\n\n\n features.reset = function() {\n Array.from(_deferred).forEach(function(handle) {\n window.cancelIdleCallback(handle);\n _deferred.delete(handle);\n });\n\n _cache = {};\n };\n\n // only certain relations are worth checking\n function relationShouldBeChecked(relation) {\n // multipolygon features have `area` geometry and aren't checked here\n return relation.tags.type === 'boundary';\n }\n\n features.getMatches = function(entity, resolver, geometry) {\n if (geometry === 'vertex' ||\n (geometry === 'relation' && !relationShouldBeChecked(entity))) return {};\n\n var ent = osmEntity.key(entity);\n if (!_cache[ent]) {\n _cache[ent] = {};\n }\n\n if (!_cache[ent].matches) {\n var matches = {};\n var hasMatch = false;\n\n for (var i = 0; i < _keys.length; i++) {\n if (_keys[i] === 'others') {\n if (hasMatch) continue;\n\n // If an entity...\n // 1. is a way that hasn't matched other 'interesting' feature rules,\n if (entity.type === 'way') {\n var parents = features.getParents(entity, resolver, geometry);\n\n // 2a. belongs only to a single multipolygon relation\n if ((parents.length === 1 && parents[0].isMultipolygon()) ||\n // 2b. or belongs only to boundary relations\n (parents.length > 0 && parents.every(function(parent) { return parent.tags.type === 'boundary'; }))) {\n\n // ...then match whatever feature rules the parent relation has matched.\n // see #2548, #2887\n //\n // IMPORTANT:\n // For this to work, getMatches must be called on relations before ways.\n //\n var pkey = osmEntity.key(parents[0]);\n if (_cache[pkey] && _cache[pkey].matches) {\n matches = Object.assign({}, _cache[pkey].matches); // shallow copy\n continue;\n }\n }\n }\n }\n\n if (_rules[_keys[i]].filter(entity.tags, geometry)) {\n matches[_keys[i]] = hasMatch = true;\n }\n }\n _cache[ent].matches = matches;\n }\n\n return _cache[ent].matches;\n };\n\n\n features.getParents = function(entity, resolver, geometry) {\n if (geometry === 'point') return [];\n\n var ent = osmEntity.key(entity);\n if (!_cache[ent]) {\n _cache[ent] = {};\n }\n\n if (!_cache[ent].parents) {\n var parents = [];\n if (geometry === 'vertex') {\n parents = resolver.parentWays(entity);\n } else { // 'line', 'area', 'relation'\n parents = resolver.parentRelations(entity);\n }\n _cache[ent].parents = parents;\n }\n return _cache[ent].parents;\n };\n\n\n features.isHiddenPreset = function(preset, geometry) {\n if (!_hidden.length) return false;\n if (!preset.tags) return false;\n\n var test = preset.setTags({}, geometry);\n for (var key in _rules) {\n if (_rules[key].filter(test, geometry)) {\n if (_hidden.indexOf(key) !== -1) {\n return key;\n }\n return false;\n }\n }\n return false;\n };\n\n\n features.isHiddenFeature = function(entity, resolver, geometry) {\n if (!_hidden.length) return false;\n if (!entity.version) return false;\n if (_forceVisible[entity.id]) return false;\n\n var matches = Object.keys(features.getMatches(entity, resolver, geometry));\n return matches.length && matches.every(function(k) { return features.hidden(k); });\n };\n\n\n features.isHiddenChild = function(entity, resolver, geometry) {\n if (!_hidden.length) return false;\n if (!entity.version || geometry === 'point') return false;\n if (_forceVisible[entity.id]) return false;\n\n var parents = features.getParents(entity, resolver, geometry);\n if (!parents.length) return false;\n\n for (var i = 0; i < parents.length; i++) {\n if (!features.isHidden(parents[i], resolver, parents[i].geometry(resolver))) {\n return false;\n }\n }\n return true;\n };\n\n\n features.hasHiddenConnections = function(entity, resolver) {\n if (!_hidden.length) return false;\n\n var childNodes, connections;\n if (entity.type === 'midpoint') {\n childNodes = [resolver.entity(entity.edge[0]), resolver.entity(entity.edge[1])];\n connections = [];\n } else {\n childNodes = entity.nodes ? resolver.childNodes(entity) : [];\n connections = features.getParents(entity, resolver, entity.geometry(resolver));\n }\n\n // gather ways connected to child nodes..\n connections = childNodes.reduce(function(result, e) {\n return resolver.isShared(e) ? utilArrayUnion(result, resolver.parentWays(e)) : result;\n }, connections);\n\n return connections.some(function(e) {\n return features.isHidden(e, resolver, e.geometry(resolver));\n });\n };\n\n\n features.isHidden = function(entity, resolver, geometry) {\n if (!_hidden.length) return false;\n if (!entity.version) return false;\n\n var fn = (geometry === 'vertex' ? features.isHiddenChild : features.isHiddenFeature);\n return fn(entity, resolver, geometry);\n };\n\n\n features.filter = function(d, resolver) {\n if (!_hidden.length) return d;\n\n var result = [];\n for (var i = 0; i < d.length; i++) {\n var entity = d[i];\n if (!features.isHidden(entity, resolver, entity.geometry(resolver))) {\n result.push(entity);\n }\n }\n return result;\n };\n\n\n features.forceVisible = function(entityIDs) {\n if (!arguments.length) return Object.keys(_forceVisible);\n\n _forceVisible = {};\n for (var i = 0; i < entityIDs.length; i++) {\n _forceVisible[entityIDs[i]] = true;\n var entity = context.hasEntity(entityIDs[i]);\n if (entity && entity.type === 'relation') {\n // also show relation members (one level deep)\n for (var j in entity.members) {\n _forceVisible[entity.members[j].id] = true;\n }\n }\n }\n return features;\n };\n\n\n features.init = function() {\n var storage = prefs('disabled-features');\n if (storage) {\n var storageDisabled = storage.replace(/;/g, ',').split(',');\n storageDisabled.forEach(features.disable);\n }\n\n var hash = utilStringQs(window.location.hash);\n if (hash.disable_features) {\n var hashDisabled = hash.disable_features.replace(/;/g, ',').split(',');\n hashDisabled.forEach(features.disable);\n }\n };\n\n\n // warm up the feature matching cache upon merging fetched data\n context.history().on('merge.features', function(newEntities) {\n if (!newEntities) return;\n var handle = window.requestIdleCallback(function() {\n var graph = context.graph();\n var types = utilArrayGroupBy(newEntities, 'type');\n // ensure that getMatches is called on relations before ways\n var entities = [].concat(types.relation || [], types.way || [], types.node || []);\n for (var i = 0; i < entities.length; i++) {\n var geometry = entities[i].geometry(graph);\n features.getMatches(entities[i], graph, geometry);\n }\n });\n _deferred.add(handle);\n });\n\n\n return features;\n}\n","export function utilBindOnce(target, type, listener, capture) {\n var typeOnce = type + '.once';\n function one() {\n target.on(typeOnce, null);\n listener.apply(this, arguments);\n }\n target.on(typeOnce, one, capture);\n return this;\n}\n","// Adapted from d3-zoom to handle pointer events.\n// https://github.com/d3/d3-zoom/blob/523ccff340187a3e3c044eaa4d4a7391ea97272b/src/zoom.js\n\nimport { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { interpolateZoom } from 'd3-interpolate';\nimport { event as d3_event, customEvent as d3_customEvent, select as d3_select } from 'd3-selection';\nimport { interrupt as d3_interrupt } from 'd3-transition';\nimport { zoomIdentity as d3_zoomIdentity } from 'd3-zoom';\nimport ZoomEvent from '../../node_modules/d3-zoom/src/event.js';\nimport { Transform } from '../../node_modules/d3-zoom/src/transform.js';\n\nimport { utilFastMouse, utilFunctor } from './util';\n\n// Ignore right-click, since that should open the context menu.\nfunction defaultFilter() {\n return !d3_event.ctrlKey && !d3_event.button;\n}\n\nfunction defaultExtent() {\n var e = this;\n if (e instanceof SVGElement) {\n e = e.ownerSVGElement || e;\n if (e.hasAttribute('viewBox')) {\n e = e.viewBox.baseVal;\n return [[e.x, e.y], [e.x + e.width, e.y + e.height]];\n }\n return [[0, 0], [e.width.baseVal.value, e.height.baseVal.value]];\n }\n return [[0, 0], [e.clientWidth, e.clientHeight]];\n}\n\nfunction defaultWheelDelta() {\n return -d3_event.deltaY * (d3_event.deltaMode === 1 ? 0.05 : d3_event.deltaMode ? 1 : 0.002);\n}\n\nfunction defaultConstrain(transform, extent, translateExtent) {\n var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],\n dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],\n dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],\n dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];\n return transform.translate(\n dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),\n dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)\n );\n}\n\nexport function utilZoomPan() {\n var filter = defaultFilter,\n extent = defaultExtent,\n constrain = defaultConstrain,\n wheelDelta = defaultWheelDelta,\n scaleExtent = [0, Infinity],\n translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],\n interpolate = interpolateZoom,\n listeners = d3_dispatch('start', 'zoom', 'end'),\n _wheelDelay = 150,\n _transform = d3_zoomIdentity,\n _activeGesture;\n\n function zoom(selection) {\n selection\n .on('pointerdown.zoom', pointerdown)\n .on('wheel.zoom', wheeled)\n .style('touch-action', 'none')\n .style('-webkit-tap-highlight-color', 'rgba(0,0,0,0)');\n\n d3_select(window)\n .on('pointermove.zoompan', pointermove)\n .on('pointerup.zoompan pointercancel.zoompan', pointerup);\n }\n\n zoom.transform = function(collection, transform, point) {\n var selection = collection.selection ? collection.selection() : collection;\n if (collection !== selection) {\n schedule(collection, transform, point);\n } else {\n selection.interrupt().each(function() {\n gesture(this, arguments)\n .start()\n .zoom(null, typeof transform === 'function' ? transform.apply(this, arguments) : transform)\n .end();\n });\n }\n };\n\n zoom.scaleBy = function(selection, k, p) {\n zoom.scaleTo(selection, function() {\n var k0 = _transform.k,\n k1 = typeof k === 'function' ? k.apply(this, arguments) : k;\n return k0 * k1;\n }, p);\n };\n\n zoom.scaleTo = function(selection, k, p) {\n zoom.transform(selection, function() {\n var e = extent.apply(this, arguments),\n t0 = _transform,\n p0 = p == null ? centroid(e) : typeof p === 'function' ? p.apply(this, arguments) : p,\n p1 = t0.invert(p0),\n k1 = typeof k === 'function' ? k.apply(this, arguments) : k;\n return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);\n }, p);\n };\n\n zoom.translateBy = function(selection, x, y) {\n zoom.transform(selection, function() {\n return constrain(_transform.translate(\n typeof x === 'function' ? x.apply(this, arguments) : x,\n typeof y === 'function' ? y.apply(this, arguments) : y\n ), extent.apply(this, arguments), translateExtent);\n });\n };\n\n zoom.translateTo = function(selection, x, y, p) {\n zoom.transform(selection, function() {\n var e = extent.apply(this, arguments),\n t = _transform,\n p0 = p == null ? centroid(e) : typeof p === 'function' ? p.apply(this, arguments) : p;\n return constrain(d3_zoomIdentity.translate(p0[0], p0[1]).scale(t.k).translate(\n typeof x === 'function' ? -x.apply(this, arguments) : -x,\n typeof y === 'function' ? -y.apply(this, arguments) : -y\n ), e, translateExtent);\n }, p);\n };\n\n function scale(transform, k) {\n k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));\n return k === transform.k ? transform : new Transform(k, transform.x, transform.y);\n }\n\n function translate(transform, p0, p1) {\n var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;\n return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);\n }\n\n function centroid(extent) {\n return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];\n }\n\n function schedule(transition, transform, point) {\n transition\n .on('start.zoom', function() { gesture(this, arguments).start(); })\n .on('interrupt.zoom end.zoom', function() { gesture(this, arguments).end(); })\n .tween('zoom', function() {\n var that = this,\n args = arguments,\n g = gesture(that, args),\n e = extent.apply(that, args),\n p = point == null ? centroid(e) : typeof point === 'function' ? point.apply(that, args) : point,\n w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),\n a = _transform,\n b = typeof transform === 'function' ? transform.apply(that, args) : transform,\n i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));\n return function(t) {\n if (t === 1) t = b; // Avoid rounding error on end.\n else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }\n g.zoom(null, t);\n };\n });\n }\n\n function gesture(that, args, clean) {\n return (!clean && _activeGesture) || new Gesture(that, args);\n }\n\n function Gesture(that, args) {\n this.that = that;\n this.args = args;\n this.active = 0;\n this.extent = extent.apply(that, args);\n }\n\n Gesture.prototype = {\n start: function() {\n if (++this.active === 1) {\n _activeGesture = this;\n this.emit('start');\n }\n return this;\n },\n zoom: function(key, transform) {\n if (this.mouse && key !== 'mouse') this.mouse[1] = transform.invert(this.mouse[0]);\n if (this.pointer0 && key !== 'touch') this.pointer0[1] = transform.invert(this.pointer0[0]);\n if (this.pointer1 && key !== 'touch') this.pointer1[1] = transform.invert(this.pointer1[0]);\n _transform = transform;\n this.emit('zoom');\n return this;\n },\n end: function() {\n if (--this.active === 0) {\n _activeGesture = null;\n this.emit('end');\n }\n return this;\n },\n emit: function(type) {\n d3_customEvent(new ZoomEvent(zoom, type, _transform), listeners.apply, listeners, [type, this.that, this.args]);\n }\n };\n\n function wheeled() {\n if (!filter.apply(this, arguments)) return;\n var g = gesture(this, arguments),\n t = _transform,\n k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),\n p = utilFastMouse(this)(d3_event);\n\n // If the mouse is in the same location as before, reuse it.\n // If there were recent wheel events, reset the wheel idle timeout.\n if (g.wheel) {\n if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {\n g.mouse[1] = t.invert(g.mouse[0] = p);\n }\n clearTimeout(g.wheel);\n\n // Otherwise, capture the mouse point and location at the start.\n } else {\n g.mouse = [p, t.invert(p)];\n d3_interrupt(this);\n g.start();\n }\n\n d3_event.preventDefault();\n d3_event.stopImmediatePropagation();\n g.wheel = setTimeout(wheelidled, _wheelDelay);\n g.zoom('mouse', constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));\n\n function wheelidled() {\n g.wheel = null;\n g.end();\n }\n }\n\n var _downPointerIDs = new Set();\n var _pointerLocGetter;\n\n function pointerdown() {\n _downPointerIDs.add(d3_event.pointerId);\n\n if (!filter.apply(this, arguments)) return;\n\n var g = gesture(this, arguments, _downPointerIDs.size === 1);\n var started;\n\n d3_event.stopImmediatePropagation();\n _pointerLocGetter = utilFastMouse(this);\n var loc = _pointerLocGetter(d3_event);\n var p = [loc, _transform.invert(loc), d3_event.pointerId];\n if (!g.pointer0) {\n g.pointer0 = p;\n started = true;\n\n } else if (!g.pointer1 && g.pointer0[2] !== p[2]) {\n g.pointer1 = p;\n }\n\n if (started) {\n d3_interrupt(this);\n g.start();\n }\n }\n\n function pointermove() {\n if (!_downPointerIDs.has(d3_event.pointerId)) return;\n\n if (!_activeGesture || !_pointerLocGetter) return;\n\n var g = gesture(this, arguments);\n\n var isPointer0 = g.pointer0 && g.pointer0[2] === d3_event.pointerId;\n var isPointer1 = !isPointer0 && g.pointer1 && g.pointer1[2] === d3_event.pointerId;\n\n if ((isPointer0 || isPointer1) && 'buttons' in d3_event && !d3_event.buttons) {\n // The pointer went up without ending the gesture somehow, e.g.\n // a down mouse was moved off the map and released. End it here.\n if (g.pointer0) _downPointerIDs.delete(g.pointer0[2]);\n if (g.pointer1) _downPointerIDs.delete(g.pointer1[2]);\n g.end();\n return;\n }\n\n d3_event.preventDefault();\n d3_event.stopImmediatePropagation();\n\n var loc = _pointerLocGetter(d3_event);\n var t, p, l;\n\n if (isPointer0) g.pointer0[0] = loc;\n else if (isPointer1) g.pointer1[0] = loc;\n\n t = _transform;\n if (g.pointer1) {\n var p0 = g.pointer0[0], l0 = g.pointer0[1],\n p1 = g.pointer1[0], l1 = g.pointer1[1],\n dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,\n dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;\n t = scale(t, Math.sqrt(dp / dl));\n p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];\n l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];\n } else if (g.pointer0) {\n p = g.pointer0[0];\n l = g.pointer0[1];\n }\n else return;\n g.zoom('touch', constrain(translate(t, p, l), g.extent, translateExtent));\n }\n\n function pointerup() {\n if (!_downPointerIDs.has(d3_event.pointerId)) return;\n\n _downPointerIDs.delete(d3_event.pointerId);\n\n if (!_activeGesture) return;\n\n var g = gesture(this, arguments);\n\n d3_event.stopImmediatePropagation();\n\n if (g.pointer0 && g.pointer0[2] === d3_event.pointerId) delete g.pointer0;\n else if (g.pointer1 && g.pointer1[2] === d3_event.pointerId) delete g.pointer1;\n\n if (g.pointer1 && !g.pointer0) {\n g.pointer0 = g.pointer1;\n delete g.pointer1;\n }\n if (g.pointer0) g.pointer0[1] = _transform.invert(g.pointer0[0]);\n else {\n g.end();\n }\n }\n\n zoom.wheelDelta = function(_) {\n return arguments.length ? (wheelDelta = utilFunctor(+_), zoom) : wheelDelta;\n };\n\n zoom.filter = function(_) {\n return arguments.length ? (filter = utilFunctor(!!_), zoom) : filter;\n };\n\n zoom.extent = function(_) {\n return arguments.length ? (extent = utilFunctor([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;\n };\n\n zoom.scaleExtent = function(_) {\n return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];\n };\n\n zoom.translateExtent = function(_) {\n return arguments.length ? (translateExtent[0][0] = +_[0][0], translateExtent[1][0] = +_[1][0], translateExtent[0][1] = +_[0][1], translateExtent[1][1] = +_[1][1], zoom) : [[translateExtent[0][0], translateExtent[0][1]], [translateExtent[1][0], translateExtent[1][1]]];\n };\n\n zoom.constrain = function(_) {\n return arguments.length ? (constrain = _, zoom) : constrain;\n };\n\n zoom.interpolate = function(_) {\n return arguments.length ? (interpolate = _, zoom) : interpolate;\n };\n\n zoom._transform = function(_) {\n return arguments.length ? (_transform = _, zoom) : _transform;\n };\n\n zoom.on = function() {\n var value = listeners.on.apply(listeners, arguments);\n return value === listeners ? zoom : value;\n };\n\n return zoom;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { event as d3_event } from 'd3-selection';\n\nimport { utilFastMouse } from './util';\nimport { utilRebind } from './rebind';\nimport { geoVecLength } from '../geo/vector';\n\n// A custom double-click / double-tap event detector that works on touch devices\n// if pointer events are supported. Falls back to default `dblclick` event.\nexport function utilDoubleUp() {\n\n var dispatch = d3_dispatch('doubleUp');\n\n var _maxTimespan = 500; // milliseconds\n var _maxDistance = 20; // web pixels; be somewhat generous to account for touch devices\n var _pointer; // object representing the pointer that could trigger double up\n\n function pointerIsValidFor(loc) {\n // second pointerup must occur within a small timeframe after the first pointerdown\n return new Date().getTime() - _pointer.startTime <= _maxTimespan &&\n // all pointer events must occur within a small distance of the first pointerdown\n geoVecLength(_pointer.startLoc, loc) <= _maxDistance;\n }\n\n function pointerdown() {\n\n // ignore right-click\n if (d3_event.ctrlKey || d3_event.button === 2) return;\n\n var loc = [d3_event.clientX, d3_event.clientY];\n\n // Don't rely on pointerId here since it can change between pointerdown\n // events on touch devices\n if (_pointer && !pointerIsValidFor(loc)) {\n // if this pointer is no longer valid, clear it so another can be started\n _pointer = undefined;\n }\n\n if (!_pointer) {\n _pointer = {\n startLoc: loc,\n startTime: new Date().getTime(),\n upCount: 0,\n pointerId: d3_event.pointerId\n };\n } else { // double down\n _pointer.pointerId = d3_event.pointerId;\n }\n }\n\n function pointerup() {\n\n // ignore right-click\n if (d3_event.ctrlKey || d3_event.button === 2) return;\n\n if (!_pointer || _pointer.pointerId !== d3_event.pointerId) return;\n\n _pointer.upCount += 1;\n\n if (_pointer.upCount === 2) { // double up!\n var loc = [d3_event.clientX, d3_event.clientY];\n if (pointerIsValidFor(loc)) {\n var locInThis = utilFastMouse(this)(d3_event);\n dispatch.call('doubleUp', this, locInThis);\n }\n // clear the pointer info in any case\n _pointer = undefined;\n }\n }\n\n function doubleUp(selection) {\n if ('PointerEvent' in window) {\n // dblclick isn't well supported on touch devices so manually use\n // pointer events if they're available\n selection\n .on('pointerdown.doubleUp', pointerdown)\n .on('pointerup.doubleUp', pointerup);\n } else {\n // fallback to dblclick\n selection\n .on('dblclick.doubleUp', function() {\n dispatch.call('doubleUp', this, utilFastMouse(this)(d3_event));\n });\n }\n }\n\n doubleUp.off = function(selection) {\n selection\n .on('pointerdown.doubleUp', null)\n .on('pointerup.doubleUp', null)\n .on('dblclick.doubleUp', null);\n };\n\n return utilRebind(doubleUp, dispatch, 'on');\n}\n","import _throttle from 'lodash-es/throttle';\n\nimport { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { interpolate as d3_interpolate } from 'd3-interpolate';\nimport { scaleLinear as d3_scaleLinear } from 'd3-scale';\nimport { event as d3_event, select as d3_select } from 'd3-selection';\nimport { zoom as d3_zoom, zoomIdentity as d3_zoomIdentity } from 'd3-zoom';\nimport { geoPath as d3_geoPath } from 'd3-geo';\n\nimport { prefs } from '../core/preferences';\nimport { geoExtent, geoRawMercator, geoScaleToZoom, geoZoomToScale } from '../geo';\nimport { modeBrowse } from '../modes/browse';\nimport { svgAreas, svgLabels, svgLayers, svgLines, svgMidpoints, svgPoints, svgVertices } from '../svg';\nimport { utilFastMouse, utilFunctor, utilSetTransform, utilEntityAndDeepMemberIDs } from '../util/util';\nimport { utilBindOnce } from '../util/bind_once';\nimport { utilDetect } from '../util/detect';\nimport { utilGetDimensions } from '../util/dimensions';\nimport { utilRebind } from '../util/rebind';\nimport { utilZoomPan } from '../util/zoom_pan';\nimport { utilDoubleUp } from '../util/double_up';\n\n// constants\nvar TILESIZE = 256;\nvar minZoom = 2;\nvar maxZoom = 24;\nvar kMin = geoZoomToScale(minZoom, TILESIZE);\nvar kMax = geoZoomToScale(maxZoom, TILESIZE);\n\nfunction clamp(num, min, max) {\n return Math.max(min, Math.min(num, max));\n}\n\n\nexport function rendererMap(context) {\n var dispatch = d3_dispatch(\n 'move', 'drawn',\n 'crossEditableZoom', 'hitMinZoom',\n 'changeHighlighting', 'changeAreaFill'\n );\n var projection = context.projection;\n var curtainProjection = context.curtainProjection;\n var drawLayers;\n var drawPoints;\n var drawVertices;\n var drawLines;\n var drawAreas;\n var drawMidpoints;\n var drawLabels;\n\n var _selection = d3_select(null);\n var supersurface = d3_select(null);\n var wrapper = d3_select(null);\n var surface = d3_select(null);\n\n var _dimensions = [1, 1];\n var _dblClickZoomEnabled = true;\n var _redrawEnabled = true;\n var _gestureTransformStart;\n var _transformStart = projection.transform();\n var _transformLast;\n var _isTransformed = false;\n var _minzoom = 0;\n var _getMouseCoords;\n var _lastPointerEvent;\n var _lastWithinEditableZoom;\n\n // whether a pointerdown event started the zoom\n var _pointerDown = false;\n\n // use pointer events on supported platforms; fallback to mouse events\n var _pointerPrefix = 'PointerEvent' in window ? 'pointer' : 'mouse';\n\n // use pointer event interaction if supported; fallback to touch/mouse events in d3-zoom\n var _zoomerPannerFunction = 'PointerEvent' in window ? utilZoomPan : d3_zoom;\n\n var _zoomerPanner = _zoomerPannerFunction()\n .scaleExtent([kMin, kMax])\n .interpolate(d3_interpolate)\n .filter(zoomEventFilter)\n .on('zoom.map', zoomPan)\n .on('start.map', function() {\n _pointerDown = d3_event.sourceEvent && d3_event.sourceEvent.type === 'pointerdown';\n })\n .on('end.map', function() {\n _pointerDown = false;\n });\n var _doubleUpHandler = utilDoubleUp();\n\n var scheduleRedraw = _throttle(redraw, 750);\n // var isRedrawScheduled = false;\n // var pendingRedrawCall;\n // function scheduleRedraw() {\n // // Only schedule the redraw if one has not already been set.\n // if (isRedrawScheduled) return;\n // isRedrawScheduled = true;\n // var that = this;\n // var args = arguments;\n // pendingRedrawCall = window.requestIdleCallback(function () {\n // // Reset the boolean so future redraws can be set.\n // isRedrawScheduled = false;\n // redraw.apply(that, args);\n // }, { timeout: 1400 });\n // }\n\n function cancelPendingRedraw() {\n scheduleRedraw.cancel();\n // isRedrawScheduled = false;\n // window.cancelIdleCallback(pendingRedrawCall);\n }\n\n\n function map(selection) {\n _selection = selection;\n\n context\n .on('change.map', immediateRedraw);\n\n var osm = context.connection();\n if (osm) {\n osm.on('change.map', immediateRedraw);\n }\n\n function didUndoOrRedo(targetTransform) {\n var mode = context.mode().id;\n if (mode !== 'browse' && mode !== 'select') return;\n if (targetTransform) {\n map.transformEase(targetTransform);\n }\n }\n\n context.history()\n .on('merge.map', function() { scheduleRedraw(); })\n .on('change.map', immediateRedraw)\n .on('undone.map', function(stack, fromStack) {\n didUndoOrRedo(fromStack.transform);\n })\n .on('redone.map', function(stack) {\n didUndoOrRedo(stack.transform);\n });\n\n context.background()\n .on('change.map', immediateRedraw);\n\n context.features()\n .on('redraw.map', immediateRedraw);\n\n drawLayers\n .on('change.map', function() {\n context.background().updateImagery();\n immediateRedraw();\n });\n\n selection\n .on('wheel.map mousewheel.map', function() {\n // disable swipe-to-navigate browser pages on trackpad/magic mouse – #5552\n d3_event.preventDefault();\n })\n .call(_zoomerPanner)\n .call(_zoomerPanner.transform, projection.transform())\n .on('dblclick.zoom', null); // override d3-zoom dblclick handling\n\n map.supersurface = supersurface = selection.append('div')\n .attr('class', 'supersurface')\n .call(utilSetTransform, 0, 0);\n\n // Need a wrapper div because Opera can't cope with an absolutely positioned\n // SVG element: http://bl.ocks.org/jfirebaugh/6fbfbd922552bf776c16\n wrapper = supersurface\n .append('div')\n .attr('class', 'layer layer-data');\n\n map.surface = surface = wrapper\n .call(drawLayers)\n .selectAll('.surface');\n\n surface\n .call(drawLabels.observe)\n .call(_doubleUpHandler)\n .on(_pointerPrefix + 'down.zoom', function() {\n _lastPointerEvent = d3_event;\n if (d3_event.button === 2) {\n d3_event.stopPropagation();\n }\n }, true)\n .on(_pointerPrefix + 'up.zoom', function() {\n _lastPointerEvent = d3_event;\n if (resetTransform()) {\n immediateRedraw();\n }\n })\n .on(_pointerPrefix + 'move.map', function() {\n _lastPointerEvent = d3_event;\n })\n .on(_pointerPrefix + 'over.vertices', function() {\n if (map.editableDataEnabled() && !_isTransformed) {\n var hover = d3_event.target.__data__;\n surface.call(drawVertices.drawHover, context.graph(), hover, map.extent());\n dispatch.call('drawn', this, { full: false });\n }\n })\n .on(_pointerPrefix + 'out.vertices', function() {\n if (map.editableDataEnabled() && !_isTransformed) {\n var hover = d3_event.relatedTarget && d3_event.relatedTarget.__data__;\n surface.call(drawVertices.drawHover, context.graph(), hover, map.extent());\n dispatch.call('drawn', this, { full: false });\n }\n });\n\n var detected = utilDetect();\n\n // only WebKit supports gesture events\n if ('GestureEvent' in window &&\n // Listening for gesture events on iOS 13.4+ breaks double-tapping,\n // but we only need to do this on desktop Safari anyway. – #7694\n !detected.isMobileWebKit) {\n\n // Desktop Safari sends gesture events for multitouch trackpad pinches.\n // We can listen for these and translate them into map zooms.\n surface\n .on('gesturestart.surface', function() {\n d3_event.preventDefault();\n _gestureTransformStart = projection.transform();\n })\n .on('gesturechange.surface', gestureChange);\n }\n\n // must call after surface init\n updateAreaFill();\n\n _doubleUpHandler.on('doubleUp.map', function(p0) {\n if (!_dblClickZoomEnabled) return;\n\n // don't zoom if targeting something other than the map itself\n if (typeof d3_event.target.__data__ === 'object' &&\n // or area fills\n !d3_select(d3_event.target).classed('fill')) return;\n\n var zoomOut = d3_event.shiftKey;\n\n var t = projection.transform();\n\n var p1 = t.invert(p0);\n\n t = t.scale(zoomOut ? 0.5 : 2);\n\n t.x = p0[0] - p1[0] * t.k;\n t.y = p0[1] - p1[1] * t.k;\n\n map.transformEase(t);\n });\n\n context.on('enter.map', function() {\n if (!map.editableDataEnabled(true /* skip zoom check */)) return;\n\n // redraw immediately any objects affected by a change in selectedIDs.\n var graph = context.graph();\n var selectedAndParents = {};\n context.selectedIDs().forEach(function(id) {\n var entity = graph.hasEntity(id);\n if (entity) {\n selectedAndParents[entity.id] = entity;\n if (entity.type === 'node') {\n graph.parentWays(entity).forEach(function(parent) {\n selectedAndParents[parent.id] = parent;\n });\n }\n }\n });\n var data = Object.values(selectedAndParents);\n var filter = function(d) { return d.id in selectedAndParents; };\n\n data = context.features().filter(data, graph);\n\n surface\n .call(drawVertices.drawSelected, graph, map.extent())\n .call(drawLines, graph, data, filter)\n .call(drawAreas, graph, data, filter)\n .call(drawMidpoints, graph, data, filter, map.trimmedExtent());\n\n dispatch.call('drawn', this, { full: false });\n\n // redraw everything else later\n scheduleRedraw();\n });\n\n map.dimensions(utilGetDimensions(selection));\n }\n\n\n function zoomEventFilter() {\n // Fix for #2151, (see also d3/d3-zoom#60, d3/d3-brush#18)\n // Intercept `mousedown` and check if there is an orphaned zoom gesture.\n // This can happen if a previous `mousedown` occurred without a `mouseup`.\n // If we detect this, dispatch `mouseup` to complete the orphaned gesture,\n // so that d3-zoom won't stop propagation of new `mousedown` events.\n if (d3_event.type === 'mousedown') {\n var hasOrphan = false;\n var listeners = window.__on;\n for (var i = 0; i < listeners.length; i++) {\n var listener = listeners[i];\n if (listener.name === 'zoom' && listener.type === 'mouseup') {\n hasOrphan = true;\n break;\n }\n }\n if (hasOrphan) {\n var event = window.CustomEvent;\n if (event) {\n event = new event('mouseup');\n } else {\n event = window.document.createEvent('Event');\n event.initEvent('mouseup', false, false);\n }\n // Event needs to be dispatched with an event.view property.\n event.view = window;\n window.dispatchEvent(event);\n }\n }\n\n return d3_event.button !== 2; // ignore right clicks\n }\n\n\n function pxCenter() {\n return [_dimensions[0] / 2, _dimensions[1] / 2];\n }\n\n\n function drawEditable(difference, extent) {\n var mode = context.mode();\n var graph = context.graph();\n var features = context.features();\n var all = context.history().intersects(map.extent());\n var fullRedraw = false;\n var data;\n var set;\n var filter;\n var applyFeatureLayerFilters = true;\n\n if (map.isInWideSelection()) {\n data = [];\n utilEntityAndDeepMemberIDs(mode.selectedIDs(), context.graph()).forEach(function(id) {\n var entity = context.hasEntity(id);\n if (entity) data.push(entity);\n });\n fullRedraw = true;\n filter = utilFunctor(true);\n // selected features should always be visible, so we can skip filtering\n applyFeatureLayerFilters = false;\n\n } else if (difference) {\n var complete = difference.complete(map.extent());\n data = Object.values(complete).filter(Boolean);\n set = new Set(Object.keys(complete));\n filter = function(d) { return set.has(d.id); };\n features.clear(data);\n\n } else {\n // force a full redraw if gatherStats detects that a feature\n // should be auto-hidden (e.g. points or buildings)..\n if (features.gatherStats(all, graph, _dimensions)) {\n extent = undefined;\n }\n\n if (extent) {\n data = context.history().intersects(map.extent().intersection(extent));\n set = new Set(data.map(function(entity) { return entity.id; }));\n filter = function(d) { return set.has(d.id); };\n\n } else {\n data = all;\n fullRedraw = true;\n filter = utilFunctor(true);\n }\n }\n\n if (applyFeatureLayerFilters) {\n data = features.filter(data, graph);\n } else {\n context.features().resetStats();\n }\n\n if (mode && mode.id === 'select') {\n // update selected vertices - the user might have just double-clicked a way,\n // creating a new vertex, triggering a partial redraw without a mode change\n surface.call(drawVertices.drawSelected, graph, map.extent());\n }\n\n surface\n .call(drawVertices, graph, data, filter, map.extent(), fullRedraw)\n .call(drawLines, graph, data, filter)\n .call(drawAreas, graph, data, filter)\n .call(drawMidpoints, graph, data, filter, map.trimmedExtent())\n .call(drawLabels, graph, data, filter, _dimensions, fullRedraw)\n .call(drawPoints, graph, data, filter);\n\n dispatch.call('drawn', this, {full: true});\n }\n\n map.init = function() {\n drawLayers = svgLayers(projection, context);\n drawPoints = svgPoints(projection, context);\n drawVertices = svgVertices(projection, context);\n drawLines = svgLines(projection, context);\n drawAreas = svgAreas(projection, context);\n drawMidpoints = svgMidpoints(projection, context);\n drawLabels = svgLabels(projection, context);\n };\n\n function editOff() {\n context.features().resetStats();\n surface.selectAll('.layer-osm *').remove();\n surface.selectAll('.layer-touch:not(.markers) *').remove();\n\n var allowed = {\n 'browse': true,\n 'save': true,\n 'select-note': true,\n 'select-data': true,\n 'select-error': true\n };\n\n var mode = context.mode();\n if (mode && !allowed[mode.id]) {\n context.enter(modeBrowse(context));\n }\n\n dispatch.call('drawn', this, {full: true});\n }\n\n\n\n\n\n function gestureChange() {\n // Remap Safari gesture events to wheel events - #5492\n // We want these disabled most places, but enabled for zoom/unzoom on map surface\n // https://developer.mozilla.org/en-US/docs/Web/API/GestureEvent\n var e = d3_event;\n e.preventDefault();\n\n var props = {\n deltaMode: 0, // dummy values to ignore in zoomPan\n deltaY: 1, // dummy values to ignore in zoomPan\n clientX: e.clientX,\n clientY: e.clientY,\n screenX: e.screenX,\n screenY: e.screenY,\n x: e.x,\n y: e.y\n };\n\n var e2 = new WheelEvent('wheel', props);\n e2._scale = e.scale; // preserve the original scale\n e2._rotation = e.rotation; // preserve the original rotation\n\n _selection.node().dispatchEvent(e2);\n }\n\n\n function zoomPan(manualEvent) {\n var event = (manualEvent || d3_event);\n var source = event.sourceEvent;\n var eventTransform = event.transform;\n var x = eventTransform.x;\n var y = eventTransform.y;\n var k = eventTransform.k;\n\n // Special handling of 'wheel' events:\n // They might be triggered by the user scrolling the mouse wheel,\n // or 2-finger pinch/zoom gestures, the transform may need adjustment.\n if (source && source.type === 'wheel') {\n\n // assume that the gesture is already handled by pointer events\n if (_pointerDown) return;\n\n var detected = utilDetect();\n var dX = source.deltaX;\n var dY = source.deltaY;\n var x2 = x;\n var y2 = y;\n var k2 = k;\n var t0, p0, p1;\n\n // Normalize mousewheel scroll speed (Firefox) - #3029\n // If wheel delta is provided in LINE units, recalculate it in PIXEL units\n // We are essentially redoing the calculations that occur here:\n // https://github.com/d3/d3-zoom/blob/78563a8348aa4133b07cac92e2595c2227ca7cd7/src/zoom.js#L203\n // See this for more info:\n // https://github.com/basilfx/normalize-wheel/blob/master/src/normalizeWheel.js\n if (source.deltaMode === 1 /* LINE */) {\n // Convert from lines to pixels, more if the user is scrolling fast.\n // (I made up the exp function to roughly match Firefox to what Chrome does)\n // These numbers should be floats, because integers are treated as pan gesture below.\n var lines = Math.abs(source.deltaY);\n var sign = (source.deltaY > 0) ? 1 : -1;\n dY = sign * clamp(\n Math.exp((lines - 1) * 0.75) * 4.000244140625,\n 4.000244140625, // min\n 350.000244140625 // max\n );\n\n // On Firefox Windows and Linux we always get +/- the scroll line amount (default 3)\n // There doesn't seem to be any scroll accelleration.\n // This multiplier increases the speed a little bit - #5512\n if (detected.os !== 'mac') {\n dY *= 5;\n }\n\n // recalculate x2,y2,k2\n t0 = _isTransformed ? _transformLast : _transformStart;\n p0 = _getMouseCoords(source);\n p1 = t0.invert(p0);\n k2 = t0.k * Math.pow(2, -dY / 500);\n k2 = clamp(k2, kMin, kMax);\n x2 = p0[0] - p1[0] * k2;\n y2 = p0[1] - p1[1] * k2;\n\n // 2 finger map pinch zooming (Safari) - #5492\n // These are fake `wheel` events we made from Safari `gesturechange` events..\n } else if (source._scale) {\n // recalculate x2,y2,k2\n t0 = _gestureTransformStart;\n p0 = _getMouseCoords(source);\n p1 = t0.invert(p0);\n k2 = t0.k * source._scale;\n k2 = clamp(k2, kMin, kMax);\n x2 = p0[0] - p1[0] * k2;\n y2 = p0[1] - p1[1] * k2;\n\n // 2 finger map pinch zooming (all browsers except Safari) - #5492\n // Pinch zooming via the `wheel` event will always have:\n // - `ctrlKey = true`\n // - `deltaY` is not round integer pixels (ignore `deltaX`)\n } else if (source.ctrlKey && !isInteger(dY)) {\n dY *= 6; // slightly scale up whatever the browser gave us\n\n // recalculate x2,y2,k2\n t0 = _isTransformed ? _transformLast : _transformStart;\n p0 = _getMouseCoords(source);\n p1 = t0.invert(p0);\n k2 = t0.k * Math.pow(2, -dY / 500);\n k2 = clamp(k2, kMin, kMax);\n x2 = p0[0] - p1[0] * k2;\n y2 = p0[1] - p1[1] * k2;\n\n // Trackpad scroll zooming with shift or alt/option key down\n } else if ((source.altKey || source.shiftKey) && isInteger(dY)) {\n // recalculate x2,y2,k2\n t0 = _isTransformed ? _transformLast : _transformStart;\n p0 = _getMouseCoords(source);\n p1 = t0.invert(p0);\n k2 = t0.k * Math.pow(2, -dY / 500);\n k2 = clamp(k2, kMin, kMax);\n x2 = p0[0] - p1[0] * k2;\n y2 = p0[1] - p1[1] * k2;\n\n // 2 finger map panning (Mac only, all browsers) - #5492, #5512\n // Panning via the `wheel` event will always have:\n // - `ctrlKey = false`\n // - `deltaX`,`deltaY` are round integer pixels\n } else if (detected.os === 'mac' && !source.ctrlKey && isInteger(dX) && isInteger(dY)) {\n p1 = projection.translate();\n x2 = p1[0] - dX;\n y2 = p1[1] - dY;\n k2 = projection.scale();\n k2 = clamp(k2, kMin, kMax);\n }\n\n // something changed - replace the event transform\n if (x2 !== x || y2 !== y || k2 !== k) {\n x = x2;\n y = y2;\n k = k2;\n eventTransform = d3_zoomIdentity.translate(x2, y2).scale(k2);\n if (_zoomerPanner._transform) {\n // utilZoomPan interface\n _zoomerPanner._transform(eventTransform);\n } else {\n // d3_zoom interface\n _selection.node().__zoom = eventTransform;\n }\n }\n\n }\n\n if (_transformStart.x === x &&\n _transformStart.y === y &&\n _transformStart.k === k) {\n return; // no change\n }\n\n var withinEditableZoom = map.withinEditableZoom();\n if (_lastWithinEditableZoom !== withinEditableZoom) {\n if (_lastWithinEditableZoom !== undefined) {\n // notify that the map zoomed in or out over the editable zoom threshold\n dispatch.call('crossEditableZoom', this, withinEditableZoom);\n }\n _lastWithinEditableZoom = withinEditableZoom;\n }\n\n if (geoScaleToZoom(k, TILESIZE) < _minzoom) {\n surface.interrupt();\n dispatch.call('hitMinZoom', this, map);\n setCenterZoom(map.center(), context.minEditableZoom(), 0, true);\n scheduleRedraw();\n dispatch.call('move', this, map);\n return;\n }\n\n projection.transform(eventTransform);\n\n var scale = k / _transformStart.k;\n var tX = (x / scale - _transformStart.x) * scale;\n var tY = (y / scale - _transformStart.y) * scale;\n\n if (context.inIntro()) {\n curtainProjection.transform({\n x: x - tX,\n y: y - tY,\n k: k\n });\n }\n\n if (source) {\n _lastPointerEvent = event;\n }\n _isTransformed = true;\n _transformLast = eventTransform;\n utilSetTransform(supersurface, tX, tY, scale);\n scheduleRedraw();\n\n dispatch.call('move', this, map);\n\n\n function isInteger(val) {\n return typeof val === 'number' && isFinite(val) && Math.floor(val) === val;\n }\n }\n\n\n function resetTransform() {\n if (!_isTransformed) return false;\n\n utilSetTransform(supersurface, 0, 0);\n _isTransformed = false;\n if (context.inIntro()) {\n curtainProjection.transform(projection.transform());\n }\n return true;\n }\n\n\n function drawMapGrid() {\n // Add bounding box to imported OSM file layer\n var d3Path = d3_geoPath(projection),\n mapBoundsExtent = context.rapidContext().getTaskExtent(); \n var minlat = mapBoundsExtent[0][1],\n minlon = mapBoundsExtent[0][0],\n maxlat = mapBoundsExtent[1][1],\n maxlon = mapBoundsExtent[1][0],\n numGridSplits = context.background().numGridSplits();\n\n var gridsSvg = surface.selectAll('.grids-svg')\n .data([0]);\n\n // Since there is no z-order within an svg, \n // and we want the grid to appear on top of everything else, \n // insert(), not append(), it at the start of the data layer. \n gridsSvg.enter()\n .insert('svg', ':first-child')\n .attr('class', 'grids-svg');\n \n gridsSvg.exit()\n .remove();\n\n var gridsData = [];\n\n for (var i = 1; i < numGridSplits; i++) {\n var midlon = minlon + (maxlon - minlon) * i / numGridSplits,\n midlat = minlat + (maxlat - minlat) * i / numGridSplits;\n gridsData.push({\n type: 'LineString',\n coordinates:[[midlon, minlat], [midlon, maxlat]]\n });\n gridsData.push({\n type: 'LineString',\n coordinates:[[minlon, midlat], [maxlon, midlat]]\n });\n }\n\n var gridsPath = gridsSvg.selectAll('.map-grids')\n .data(gridsData); \n\n gridsPath.attr('d', d3Path);\n\n gridsPath.enter()\n .append('path')\n .attr('class', 'map-grids')\n .attr('d', d3Path); \n \n gridsPath.exit()\n .remove();\n }\n\n\n function redraw(difference, extent) {\n if (surface.empty() || !_redrawEnabled) return;\n\n // If we are in the middle of a zoom/pan, we can't do differenced redraws.\n // It would result in artifacts where differenced entities are redrawn with\n // one transform and unchanged entities with another.\n if (resetTransform()) {\n difference = extent = undefined;\n }\n\n var zoom = map.zoom();\n var z = String(~~zoom);\n\n if (surface.attr('data-zoom') !== z) {\n surface.attr('data-zoom', z);\n }\n\n // class surface as `lowzoom` around z17-z18.5 (based on latitude)\n var lat = map.center()[1];\n var lowzoom = d3_scaleLinear()\n .domain([-60, 0, 60])\n .range([17, 18.5, 17])\n .clamp(true);\n\n surface\n .classed('low-zoom', zoom <= lowzoom(lat));\n\n if (context.rapidContext().isTaskRectangular()) {\n drawMapGrid();\n }\n\n if (!difference) {\n supersurface.call(context.background());\n wrapper.call(drawLayers);\n }\n\n // OSM\n if (map.editableDataEnabled() || map.isInWideSelection()) {\n context.loadTiles(projection);\n drawEditable(difference, extent);\n } else {\n editOff();\n }\n\n _transformStart = projection.transform();\n\n return map;\n }\n\n\n\n var immediateRedraw = function(difference, extent) {\n if (!difference && !extent) cancelPendingRedraw();\n redraw(difference, extent);\n };\n\n\n map.lastPointerEvent = function() {\n return _lastPointerEvent;\n };\n\n\n map.mouse = function() {\n var event = _lastPointerEvent || d3_event;\n if (event) {\n var s;\n while ((s = event.sourceEvent)) { event = s; }\n return _getMouseCoords(event);\n }\n return null;\n };\n\n\n // returns Lng/Lat\n map.mouseCoordinates = function() {\n var coord = map.mouse() || pxCenter();\n return projection.invert(coord);\n };\n\n\n map.dblclickZoomEnable = function(val) {\n if (!arguments.length) return _dblClickZoomEnabled;\n _dblClickZoomEnabled = val;\n return map;\n };\n\n\n map.redrawEnable = function(val) {\n if (!arguments.length) return _redrawEnabled;\n _redrawEnabled = val;\n return map;\n };\n\n\n map.isTransformed = function() {\n return _isTransformed;\n };\n\n\n function setTransform(t2, duration, force) {\n var t = projection.transform();\n if (!force && t2.k === t.k && t2.x === t.x && t2.y === t.y) return false;\n\n if (duration) {\n _selection\n .transition()\n .duration(duration)\n .on('start', function() { map.startEase(); })\n .call(_zoomerPanner.transform, d3_zoomIdentity.translate(t2.x, t2.y).scale(t2.k));\n } else {\n projection.transform(t2);\n _transformStart = t2;\n _selection.call(_zoomerPanner.transform, _transformStart);\n }\n\n return true;\n }\n\n\n function setCenterZoom(loc2, z2, duration, force) {\n var c = map.center();\n var z = map.zoom();\n if (loc2[0] === c[0] && loc2[1] === c[1] && z2 === z && !force) return false;\n\n var proj = geoRawMercator().transform(projection.transform()); // copy projection\n\n var k2 = clamp(geoZoomToScale(z2, TILESIZE), kMin, kMax);\n proj.scale(k2);\n\n var t = proj.translate();\n var point = proj(loc2);\n\n var center = pxCenter();\n t[0] += center[0] - point[0];\n t[1] += center[1] - point[1];\n\n return setTransform(d3_zoomIdentity.translate(t[0], t[1]).scale(k2), duration, force);\n }\n\n\n map.pan = function(delta, duration) {\n var t = projection.translate();\n var k = projection.scale();\n\n t[0] += delta[0];\n t[1] += delta[1];\n\n if (duration) {\n _selection\n .transition()\n .duration(duration)\n .on('start', function() { map.startEase(); })\n .call(_zoomerPanner.transform, d3_zoomIdentity.translate(t[0], t[1]).scale(k));\n } else {\n projection.translate(t);\n _transformStart = projection.transform();\n _selection.call(_zoomerPanner.transform, _transformStart);\n dispatch.call('move', this, map);\n immediateRedraw();\n }\n\n return map;\n };\n\n\n map.dimensions = function(val) {\n if (!arguments.length) return _dimensions;\n\n _dimensions = val;\n drawLayers.dimensions(_dimensions);\n context.background().dimensions(_dimensions);\n projection.clipExtent([[0, 0], _dimensions]);\n _getMouseCoords = utilFastMouse(supersurface.node());\n\n scheduleRedraw();\n return map;\n };\n\n\n function zoomIn(delta) {\n setCenterZoom(map.center(), ~~map.zoom() + delta, 250, true);\n }\n\n function zoomOut(delta) {\n setCenterZoom(map.center(), ~~map.zoom() - delta, 250, true);\n }\n\n map.zoomIn = function() { zoomIn(1); };\n map.zoomInFurther = function() { zoomIn(4); };\n map.canZoomIn = function() { return map.zoom() < maxZoom; };\n\n map.zoomOut = function() { zoomOut(1); };\n map.zoomOutFurther = function() { zoomOut(4); };\n map.canZoomOut = function() { return map.zoom() > minZoom; };\n\n map.center = function(loc2) {\n if (!arguments.length) {\n return projection.invert(pxCenter());\n }\n\n if (setCenterZoom(loc2, map.zoom())) {\n dispatch.call('move', this, map);\n }\n\n scheduleRedraw();\n return map;\n };\n\n map.unobscuredCenterZoomEase = function(loc, zoom) {\n var offset = map.unobscuredOffsetPx();\n\n var proj = geoRawMercator().transform(projection.transform()); // copy projection\n // use the target zoom to calculate the offset center\n proj.scale(geoZoomToScale(zoom, TILESIZE));\n\n var locPx = proj(loc);\n var offsetLocPx = [locPx[0] + offset[0], locPx[1] + offset[1]];\n var offsetLoc = proj.invert(offsetLocPx);\n\n map.centerZoomEase(offsetLoc, zoom);\n };\n\n map.unobscuredOffsetPx = function() {\n var openPane = context.container().select('.map-panes .map-pane.shown');\n if (!openPane.empty()) {\n return [openPane.node().offsetWidth/2, 0];\n }\n return [0, 0];\n };\n\n map.zoom = function(z2) {\n if (!arguments.length) {\n return Math.max(geoScaleToZoom(projection.scale(), TILESIZE), 0);\n }\n\n if (z2 < _minzoom) {\n surface.interrupt();\n dispatch.call('hitMinZoom', this, map);\n z2 = context.minEditableZoom();\n }\n\n if (setCenterZoom(map.center(), z2)) {\n dispatch.call('move', this, map);\n }\n\n scheduleRedraw();\n return map;\n };\n\n\n map.centerZoom = function(loc2, z2) {\n if (setCenterZoom(loc2, z2)) {\n dispatch.call('move', this, map);\n }\n\n scheduleRedraw();\n return map;\n };\n\n\n map.zoomTo = function(entity) {\n var extent = entity.extent(context.graph());\n if (!isFinite(extent.area())) return map;\n\n var z2 = clamp(map.trimmedExtentZoom(extent), 0, 20);\n return map.centerZoom(extent.center(), z2);\n };\n\n\n map.centerEase = function(loc2, duration) {\n duration = duration || 250;\n setCenterZoom(loc2, map.zoom(), duration);\n return map;\n };\n\n\n map.zoomEase = function(z2, duration) {\n duration = duration || 250;\n setCenterZoom(map.center(), z2, duration, false);\n return map;\n };\n\n\n map.centerZoomEase = function(loc2, z2, duration) {\n duration = duration || 250;\n setCenterZoom(loc2, z2, duration, false);\n return map;\n };\n\n\n map.transformEase = function(t2, duration) {\n duration = duration || 250;\n setTransform(t2, duration, false /* don't force */);\n return map;\n };\n\n\n map.zoomToEase = function(obj, duration) {\n var extent;\n if (Array.isArray(obj)) {\n obj.forEach(function(entity) {\n var entityExtent = entity.extent(context.graph());\n if (!extent) {\n extent = entityExtent;\n } else {\n extent = extent.extend(entityExtent);\n }\n });\n } else {\n extent = obj.extent(context.graph());\n }\n if (!isFinite(extent.area())) return map;\n\n var z2 = clamp(map.trimmedExtentZoom(extent), 0, 20);\n return map.centerZoomEase(extent.center(), z2, duration);\n };\n\n\n map.startEase = function() {\n utilBindOnce(surface, _pointerPrefix + 'down.ease', function() {\n map.cancelEase();\n });\n return map;\n };\n\n\n map.cancelEase = function() {\n _selection.interrupt();\n return map;\n };\n\n\n map.extent = function(val) {\n if (!arguments.length) {\n return new geoExtent(\n projection.invert([0, _dimensions[1]]),\n projection.invert([_dimensions[0], 0])\n );\n } else {\n var extent = geoExtent(val);\n map.centerZoom(extent.center(), map.extentZoom(extent));\n }\n };\n\n\n map.trimmedExtent = function(val) {\n if (!arguments.length) {\n var headerY = 71;\n var footerY = 30;\n var pad = 10;\n return new geoExtent(\n projection.invert([pad, _dimensions[1] - footerY - pad]),\n projection.invert([_dimensions[0] - pad, headerY + pad])\n );\n } else {\n var extent = geoExtent(val);\n map.centerZoom(extent.center(), map.trimmedExtentZoom(extent));\n }\n };\n\n\n function calcExtentZoom(extent, dim) {\n var tl = projection([extent[0][0], extent[1][1]]);\n var br = projection([extent[1][0], extent[0][1]]);\n\n // Calculate maximum zoom that fits extent\n var hFactor = (br[0] - tl[0]) / dim[0];\n var vFactor = (br[1] - tl[1]) / dim[1];\n var hZoomDiff = Math.log(Math.abs(hFactor)) / Math.LN2;\n var vZoomDiff = Math.log(Math.abs(vFactor)) / Math.LN2;\n var newZoom = map.zoom() - Math.max(hZoomDiff, vZoomDiff);\n\n return newZoom;\n }\n\n\n map.extentZoom = function(val) {\n return calcExtentZoom(geoExtent(val), _dimensions);\n };\n\n\n map.trimmedExtentZoom = function(val) {\n var trimY = 120;\n var trimX = 40;\n var trimmed = [_dimensions[0] - trimX, _dimensions[1] - trimY];\n return calcExtentZoom(geoExtent(val), trimmed);\n };\n\n\n map.withinEditableZoom = function() {\n return map.zoom() >= context.minEditableZoom();\n };\n\n\n map.isInWideSelection = function() {\n return !map.withinEditableZoom() && context.selectedIDs().length;\n };\n\n\n map.editableDataEnabled = function(skipZoomCheck) {\n\n var layer = context.layers().layer('osm');\n if (!layer || !layer.enabled()) return false;\n\n return skipZoomCheck || map.withinEditableZoom();\n };\n\n\n map.notesEditable = function() {\n var layer = context.layers().layer('notes');\n if (!layer || !layer.enabled()) return false;\n\n return map.withinEditableZoom();\n };\n\n\n map.minzoom = function(val) {\n if (!arguments.length) return _minzoom;\n _minzoom = val;\n return map;\n };\n\n\n map.toggleHighlightEdited = function() {\n surface.classed('highlight-edited', !surface.classed('highlight-edited'));\n map.pan([0,0]); // trigger a redraw\n dispatch.call('changeHighlighting', this);\n };\n\n\n map.areaFillOptions = ['wireframe', 'partial', 'full'];\n\n map.activeAreaFill = function(val) {\n if (!arguments.length) return prefs('area-fill') || 'partial';\n\n prefs('area-fill', val);\n if (val !== 'wireframe') {\n prefs('area-fill-toggle', val);\n }\n updateAreaFill();\n map.pan([0,0]); // trigger a redraw\n dispatch.call('changeAreaFill', this);\n return map;\n };\n\n map.toggleWireframe = function() {\n\n var activeFill = map.activeAreaFill();\n\n if (activeFill === 'wireframe') {\n activeFill = prefs('area-fill-toggle') || 'partial';\n } else {\n activeFill = 'wireframe';\n }\n\n map.activeAreaFill(activeFill);\n };\n\n function updateAreaFill() {\n var activeFill = map.activeAreaFill();\n map.areaFillOptions.forEach(function(opt) {\n surface.classed('fill-' + opt, Boolean(opt === activeFill));\n });\n }\n\n\n map.layers = () => drawLayers;\n\n\n map.doubleUpHandler = function() {\n return _doubleUpHandler;\n };\n\n\n return utilRebind(map, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\n\nimport { utilRebind } from '../util/rebind';\nimport { utilQsString, utilStringQs } from '../util';\n\n\nexport function rendererPhotos(context) {\n var dispatch = d3_dispatch('change');\n var _layerIDs = ['streetside', 'mapillary', 'mapillary-map-features', 'mapillary-signs', 'openstreetcam'];\n var _allPhotoTypes = ['flat', 'panoramic'];\n var _shownPhotoTypes = _allPhotoTypes.slice(); // shallow copy\n\n function photos() {}\n\n function updateStorage() {\n if (window.mocha) return;\n\n var hash = utilStringQs(window.location.hash);\n var enabled = context.layers().all().filter(function(d) {\n return _layerIDs.indexOf(d.id) !== -1 && d.layer && d.layer.supported() && d.layer.enabled();\n }).map(function(d) {\n return d.id;\n });\n if (enabled.length) {\n hash.photo_overlay = enabled.join(',');\n } else {\n delete hash.photo_overlay;\n }\n window.location.replace('#' + utilQsString(hash, true));\n }\n\n photos.overlayLayerIDs = function() {\n return _layerIDs;\n };\n\n photos.allPhotoTypes = function() {\n return _allPhotoTypes;\n };\n\n function showsLayer(id) {\n var layer = context.layers().layer(id);\n return layer && layer.supported() && layer.enabled();\n }\n\n photos.shouldFilterByPhotoType = function() {\n return showsLayer('mapillary') ||\n (showsLayer('streetside') && showsLayer('openstreetcam'));\n };\n\n photos.showsPhotoType = function(val) {\n if (!photos.shouldFilterByPhotoType()) return true;\n\n return _shownPhotoTypes.indexOf(val) !== -1;\n };\n\n photos.showsFlat = function() {\n return photos.showsPhotoType('flat');\n };\n\n photos.showsPanoramic = function() {\n return photos.showsPhotoType('panoramic');\n };\n\n photos.togglePhotoType = function(val) {\n var index = _shownPhotoTypes.indexOf(val);\n if (index !== -1) {\n _shownPhotoTypes.splice(index, 1);\n } else {\n _shownPhotoTypes.push(val);\n }\n dispatch.call('change', this);\n return photos;\n };\n\n photos.init = function() {\n var hash = utilStringQs(window.location.hash);\n if (hash.photo_overlay) {\n var hashOverlayIDs = hash.photo_overlay.replace(/;/g, ',').split(',');\n hashOverlayIDs.forEach(function(id) {\n var layer = context.layers().layer(id);\n if (layer) layer.enabled(true);\n });\n }\n\n context.layers().on('change.rendererPhotos', updateStorage);\n };\n\n return utilRebind(photos, dispatch, 'on');\n}\n","import { geoPath as d3_geoPath } from 'd3-geo';\nimport { event as d3_event, select as d3_select } from 'd3-selection';\nimport { zoom as d3_zoom, zoomIdentity as d3_zoomIdentity } from 'd3-zoom';\n\nimport { t } from '../core/localizer';\nimport { geoRawMercator, geoScaleToZoom, geoVecSubtract, geoVecScale, geoZoomToScale } from '../geo';\nimport { rendererTileLayer } from '../renderer';\nimport { svgDebug, svgData } from '../svg';\nimport { utilSetTransform } from '../util';\n// import { utilGetDimensions } from '../util/dimensions';\n\n\nexport function uiMapInMap(context) {\n\n function mapInMap(selection) {\n var backgroundLayer = rendererTileLayer(context);\n var overlayLayers = {};\n var projection = geoRawMercator();\n var dataLayer = svgData(projection, context).showLabels(false);\n var debugLayer = svgDebug(projection, context);\n var zoom = d3_zoom()\n .scaleExtent([geoZoomToScale(0.5), geoZoomToScale(24)])\n .on('start', zoomStarted)\n .on('zoom', zoomed)\n .on('end', zoomEnded);\n\n var wrap = d3_select(null);\n var tiles = d3_select(null);\n var viewport = d3_select(null);\n\n var _isTransformed = false;\n var _isHidden = true;\n var _skipEvents = false;\n var _gesture = null;\n var _zDiff = 6; // by default, minimap renders at (main zoom - 6)\n var _dMini; // dimensions of minimap\n var _cMini; // center pixel of minimap\n var _tStart; // transform at start of gesture\n var _tCurr; // transform at most recent event\n var _timeoutID;\n\n\n function zoomStarted() {\n if (_skipEvents) return;\n _tStart = _tCurr = projection.transform();\n _gesture = null;\n }\n\n\n function zoomed() {\n if (_skipEvents) return;\n\n var x = d3_event.transform.x;\n var y = d3_event.transform.y;\n var k = d3_event.transform.k;\n var isZooming = (k !== _tStart.k);\n var isPanning = (x !== _tStart.x || y !== _tStart.y);\n\n if (!isZooming && !isPanning) {\n return; // no change\n }\n\n // lock in either zooming or panning, don't allow both in minimap.\n if (!_gesture) {\n _gesture = isZooming ? 'zoom' : 'pan';\n }\n\n var tMini = projection.transform();\n var tX, tY, scale;\n\n if (_gesture === 'zoom') {\n scale = k / tMini.k;\n tX = (_cMini[0] / scale - _cMini[0]) * scale;\n tY = (_cMini[1] / scale - _cMini[1]) * scale;\n } else {\n k = tMini.k;\n scale = 1;\n tX = x - tMini.x;\n tY = y - tMini.y;\n }\n\n utilSetTransform(tiles, tX, tY, scale);\n utilSetTransform(viewport, 0, 0, scale);\n _isTransformed = true;\n _tCurr = d3_zoomIdentity.translate(x, y).scale(k);\n\n var zMain = geoScaleToZoom(context.projection.scale());\n var zMini = geoScaleToZoom(k);\n\n _zDiff = zMain - zMini;\n\n queueRedraw();\n }\n\n\n function zoomEnded() {\n if (_skipEvents) return;\n if (_gesture !== 'pan') return;\n\n updateProjection();\n _gesture = null;\n context.map().center(projection.invert(_cMini)); // recenter main map..\n }\n\n\n function updateProjection() {\n var loc = context.map().center();\n var tMain = context.projection.transform();\n var zMain = geoScaleToZoom(tMain.k);\n var zMini = Math.max(zMain - _zDiff, 0.5);\n var kMini = geoZoomToScale(zMini);\n\n projection\n .translate([tMain.x, tMain.y])\n .scale(kMini);\n\n var point = projection(loc);\n var mouse = (_gesture === 'pan') ? geoVecSubtract([_tCurr.x, _tCurr.y], [_tStart.x, _tStart.y]) : [0, 0];\n var xMini = _cMini[0] - point[0] + tMain.x + mouse[0];\n var yMini = _cMini[1] - point[1] + tMain.y + mouse[1];\n\n projection\n .translate([xMini, yMini])\n .clipExtent([[0, 0], _dMini]);\n\n _tCurr = projection.transform();\n\n if (_isTransformed) {\n utilSetTransform(tiles, 0, 0);\n utilSetTransform(viewport, 0, 0);\n _isTransformed = false;\n }\n\n zoom\n .scaleExtent([geoZoomToScale(0.5), geoZoomToScale(zMain - 3)]);\n\n _skipEvents = true;\n wrap.call(zoom.transform, _tCurr);\n _skipEvents = false;\n }\n\n\n function redraw() {\n clearTimeout(_timeoutID);\n if (_isHidden) return;\n\n updateProjection();\n var zMini = geoScaleToZoom(projection.scale());\n\n // setup tile container\n tiles = wrap\n .selectAll('.map-in-map-tiles')\n .data([0]);\n\n tiles = tiles.enter()\n .append('div')\n .attr('class', 'map-in-map-tiles')\n .merge(tiles);\n\n // redraw background\n backgroundLayer\n .source(context.background().baseLayerSource())\n .projection(projection)\n .dimensions(_dMini);\n\n var background = tiles\n .selectAll('.map-in-map-background')\n .data([0]);\n\n background.enter()\n .append('div')\n .attr('class', 'map-in-map-background')\n .merge(background)\n .call(backgroundLayer);\n\n\n // redraw overlay\n var overlaySources = context.background().overlayLayerSources();\n var activeOverlayLayers = [];\n for (var i = 0; i < overlaySources.length; i++) {\n if (overlaySources[i].validZoom(zMini)) {\n if (!overlayLayers[i]) overlayLayers[i] = rendererTileLayer(context);\n activeOverlayLayers.push(overlayLayers[i]\n .source(overlaySources[i])\n .projection(projection)\n .dimensions(_dMini));\n }\n }\n\n var overlay = tiles\n .selectAll('.map-in-map-overlay')\n .data([0]);\n\n overlay = overlay.enter()\n .append('div')\n .attr('class', 'map-in-map-overlay')\n .merge(overlay);\n\n\n var overlays = overlay\n .selectAll('div')\n .data(activeOverlayLayers, function(d) { return d.source().name(); });\n\n overlays.exit()\n .remove();\n\n overlays = overlays.enter()\n .append('div')\n .merge(overlays)\n .each(function(layer) { d3_select(this).call(layer); });\n\n\n var dataLayers = tiles\n .selectAll('.map-in-map-data')\n .data([0]);\n\n dataLayers.exit()\n .remove();\n\n dataLayers = dataLayers.enter()\n .append('svg')\n .attr('class', 'map-in-map-data')\n .merge(dataLayers)\n .call(dataLayer)\n .call(debugLayer);\n\n\n // redraw viewport bounding box\n if (_gesture !== 'pan') {\n var getPath = d3_geoPath(projection);\n var bbox = { type: 'Polygon', coordinates: [context.map().extent().polygon()] };\n\n viewport = wrap.selectAll('.map-in-map-viewport')\n .data([0]);\n\n viewport = viewport.enter()\n .append('svg')\n .attr('class', 'map-in-map-viewport')\n .merge(viewport);\n\n\n var path = viewport.selectAll('.map-in-map-bbox')\n .data([bbox]);\n\n path.enter()\n .append('path')\n .attr('class', 'map-in-map-bbox')\n .merge(path)\n .attr('d', getPath)\n .classed('thick', function(d) { return getPath.area(d) < 30; });\n }\n }\n\n\n function queueRedraw() {\n clearTimeout(_timeoutID);\n _timeoutID = setTimeout(function() { redraw(); }, 750);\n }\n\n\n function toggle() {\n if (d3_event) d3_event.preventDefault();\n\n _isHidden = !_isHidden;\n\n context.container().select('.minimap-toggle-item')\n .classed('active', !_isHidden)\n .select('input')\n .property('checked', !_isHidden);\n\n if (_isHidden) {\n wrap\n .style('display', 'block')\n .style('opacity', '1')\n .transition()\n .duration(200)\n .style('opacity', '0')\n .on('end', function() {\n selection.selectAll('.map-in-map')\n .style('display', 'none');\n });\n } else {\n wrap\n .style('display', 'block')\n .style('opacity', '0')\n .transition()\n .duration(200)\n .style('opacity', '1')\n .on('end', function() {\n redraw();\n });\n }\n }\n\n\n uiMapInMap.toggle = toggle;\n\n wrap = selection.selectAll('.map-in-map')\n .data([0]);\n\n wrap = wrap.enter()\n .append('div')\n .attr('class', 'map-in-map')\n .style('display', (_isHidden ? 'none' : 'block'))\n .call(zoom)\n .on('dblclick.zoom', null)\n .merge(wrap);\n\n // reflow warning: Hardcode dimensions - currently can't resize it anyway..\n _dMini = [200,150]; //utilGetDimensions(wrap);\n _cMini = geoVecScale(_dMini, 0.5);\n\n context.map()\n .on('drawn.map-in-map', function(drawn) {\n if (drawn.full === true) {\n redraw();\n }\n });\n\n redraw();\n\n context.keybinding()\n .on(t('background.minimap.key'), toggle);\n }\n\n return mapInMap;\n}\n","import _debounce from 'lodash-es/debounce';\n\nimport { event as d3_event } from 'd3-selection';\n\nimport { t } from '../core/localizer';\nimport { svgIcon } from '../svg/index';\n\n\nexport function uiNotice(context) {\n\n return function(selection) {\n var div = selection\n .append('div')\n .attr('class', 'notice');\n\n var button = div\n .append('button')\n .attr('class', 'zoom-to notice fillD')\n .on('click', function() {\n context.map().zoomEase(context.minEditableZoom());\n })\n .on('wheel', function() { // let wheel events pass through #4482\n var e2 = new WheelEvent(d3_event.type, d3_event);\n context.surface().node().dispatchEvent(e2);\n });\n\n button\n .call(svgIcon('#iD-icon-plus', 'pre-text'))\n .append('span')\n .attr('class', 'label')\n .text(t('zoom_in_edit'));\n\n\n function disableTooHigh() {\n var canEdit = context.map().zoom() >= context.minEditableZoom();\n div.style('display', canEdit ? 'none' : 'block');\n }\n\n context.map()\n .on('move.notice', _debounce(disableTooHigh, 500));\n\n disableTooHigh();\n };\n}\n","import {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { svgIcon } from '../svg/icon';\nimport { utilGetDimensions } from '../util/dimensions';\nimport { utilRebind } from '../util';\nimport { services } from '../services';\n\nexport function uiPhotoviewer(context) {\n\n var dispatch = d3_dispatch('resize');\n\n var _pointerPrefix = 'PointerEvent' in window ? 'pointer' : 'mouse';\n\n function photoviewer(selection) {\n selection\n .append('button')\n .attr('class', 'thumb-hide')\n .on('click', function () {\n if (services.streetside) { services.streetside.hideViewer(context); }\n if (services.mapillary) { services.mapillary.hideViewer(context); }\n if (services.openstreetcam) { services.openstreetcam.hideViewer(context); }\n })\n .append('div')\n .call(svgIcon('#iD-icon-close'));\n\n function preventDefault() {\n d3_event.preventDefault();\n }\n\n selection\n .append('button')\n .attr('class', 'resize-handle-xy')\n .on('touchstart touchdown touchend', preventDefault)\n .on(\n _pointerPrefix + 'down',\n buildResizeListener(selection, 'resize', dispatch, { resizeOnX: true, resizeOnY: true })\n );\n\n selection\n .append('button')\n .attr('class', 'resize-handle-x')\n .on('touchstart touchdown touchend', preventDefault)\n .on(\n _pointerPrefix + 'down',\n buildResizeListener(selection, 'resize', dispatch, { resizeOnX: true })\n );\n\n selection\n .append('button')\n .attr('class', 'resize-handle-y')\n .on('touchstart touchdown touchend', preventDefault)\n .on(\n _pointerPrefix + 'down',\n buildResizeListener(selection, 'resize', dispatch, { resizeOnY: true })\n );\n\n services.streetside.loadViewer(context);\n services.mapillary.loadViewer(context);\n services.openstreetcam.loadViewer(context);\n\n function buildResizeListener(target, eventName, dispatch, options) {\n\n var resizeOnX = !!options.resizeOnX;\n var resizeOnY = !!options.resizeOnY;\n var minHeight = options.minHeight || 240;\n var minWidth = options.minWidth || 320;\n var pointerId;\n var startX;\n var startY;\n var startWidth;\n var startHeight;\n\n function startResize() {\n if (pointerId !== (d3_event.pointerId || 'mouse')) return;\n\n d3_event.preventDefault();\n d3_event.stopPropagation();\n\n var mapSize = context.map().dimensions();\n\n if (resizeOnX) {\n var maxWidth = mapSize[0];\n var newWidth = clamp((startWidth + d3_event.clientX - startX), minWidth, maxWidth);\n target.style('width', newWidth + 'px');\n }\n\n if (resizeOnY) {\n var maxHeight = mapSize[1] - 90; // preserve space at top/bottom of map\n var newHeight = clamp((startHeight + startY - d3_event.clientY), minHeight, maxHeight);\n target.style('height', newHeight + 'px');\n }\n\n dispatch.call(eventName, target, utilGetDimensions(target, true));\n }\n\n function clamp(num, min, max) {\n return Math.max(min, Math.min(num, max));\n }\n\n function stopResize() {\n if (pointerId !== (d3_event.pointerId || 'mouse')) return;\n\n d3_event.preventDefault();\n d3_event.stopPropagation();\n\n // remove all the listeners we added\n d3_select(window)\n .on('.' + eventName, null);\n }\n\n return function initResize() {\n d3_event.preventDefault();\n d3_event.stopPropagation();\n\n pointerId = d3_event.pointerId || 'mouse';\n\n startX = d3_event.clientX;\n startY = d3_event.clientY;\n var targetRect = target.node().getBoundingClientRect();\n startWidth = targetRect.width;\n startHeight = targetRect.height;\n\n d3_select(window)\n .on(_pointerPrefix + 'move.' + eventName, startResize, false)\n .on(_pointerPrefix + 'up.' + eventName, stopResize, false);\n\n if (_pointerPrefix === 'pointer') {\n d3_select(window)\n .on('pointercancel.' + eventName, stopResize, false);\n }\n };\n }\n }\n\n photoviewer.onMapResize = function() {\n var photoviewer = context.container().select('.photoviewer');\n var content = context.container().select('.main-content');\n var mapDimensions = utilGetDimensions(content, true);\n // shrink photo viewer if it is too big\n // (-90 preserves space at top and bottom of map used by menus)\n var photoDimensions = utilGetDimensions(photoviewer, true);\n if (photoDimensions[0] > mapDimensions[0] || photoDimensions[1] > (mapDimensions[1] - 90)) {\n var setPhotoDimensions = [\n Math.min(photoDimensions[0], mapDimensions[0]),\n Math.min(photoDimensions[1], mapDimensions[1] - 90),\n ];\n\n photoviewer\n .style('width', setPhotoDimensions[0] + 'px')\n .style('height', setPhotoDimensions[1] + 'px');\n\n dispatch.call('resize', photoviewer, setPhotoDimensions);\n }\n };\n\n return utilRebind(photoviewer, dispatch, 'on');\n}\n","import { t } from '../core/localizer';\nimport { uiModal } from './modal';\n\n\nexport function uiRestore(context) {\n return function(selection) {\n if (!context.history().hasRestorableChanges()) return;\n\n let modalSelection = uiModal(selection, true);\n\n modalSelection.select('.modal')\n .attr('class', 'modal fillL');\n\n let introModal = modalSelection.select('.content');\n\n introModal\n .append('div')\n .attr('class', 'modal-section')\n .append('h3')\n .text(t('restore.heading'));\n\n introModal\n .append('div')\n .attr('class','modal-section')\n .append('p')\n .text(t('restore.description'));\n\n let buttonWrap = introModal\n .append('div')\n .attr('class', 'modal-actions');\n\n let restore = buttonWrap\n .append('button')\n .attr('class', 'restore')\n .on('click', () => {\n context.history().restore();\n modalSelection.remove();\n });\n\n restore\n .append('svg')\n .attr('class', 'logo logo-restore')\n .append('use')\n .attr('xlink:href', '#iD-logo-restore');\n\n restore\n .append('div')\n .text(t('restore.restore'));\n\n let reset = buttonWrap\n .append('button')\n .attr('class', 'reset')\n .on('click', () => {\n context.history().clearSaved();\n modalSelection.remove();\n });\n\n reset\n .append('svg')\n .attr('class', 'logo logo-reset')\n .append('use')\n .attr('xlink:href', '#iD-logo-reset');\n\n reset\n .append('div')\n .text(t('restore.reset'));\n\n restore.node().focus();\n };\n}\n","import { displayLength } from '../util/units';\nimport { geoLonToMeters, geoMetersToLon } from '../geo';\nimport { localizer } from '../core/localizer';\n\n\nexport function uiScale(context) {\n var projection = context.projection,\n isImperial = !localizer.usesMetric(),\n maxLength = 180,\n tickHeight = 8;\n\n\n function scaleDefs(loc1, loc2) {\n var lat = (loc2[1] + loc1[1]) / 2,\n conversion = (isImperial ? 3.28084 : 1),\n dist = geoLonToMeters(loc2[0] - loc1[0], lat) * conversion,\n scale = { dist: 0, px: 0, text: '' },\n buckets, i, val, dLon;\n\n if (isImperial) {\n buckets = [5280000, 528000, 52800, 5280, 500, 50, 5, 1];\n } else {\n buckets = [5000000, 500000, 50000, 5000, 500, 50, 5, 1];\n }\n\n // determine a user-friendly endpoint for the scale\n for (i = 0; i < buckets.length; i++) {\n val = buckets[i];\n if (dist >= val) {\n scale.dist = Math.floor(dist / val) * val;\n break;\n } else {\n scale.dist = +dist.toFixed(2);\n }\n }\n\n dLon = geoMetersToLon(scale.dist / conversion, lat);\n scale.px = Math.round(projection([loc1[0] + dLon, loc1[1]])[0]);\n\n scale.text = displayLength(scale.dist / conversion, isImperial);\n\n return scale;\n }\n\n\n function update(selection) {\n // choose loc1, loc2 along bottom of viewport (near where the scale will be drawn)\n var dims = context.map().dimensions(),\n loc1 = projection.invert([0, dims[1]]),\n loc2 = projection.invert([maxLength, dims[1]]),\n scale = scaleDefs(loc1, loc2);\n\n selection.select('.scale-path')\n .attr('d', 'M0.5,0.5v' + tickHeight + 'h' + scale.px + 'v-' + tickHeight);\n\n selection.select('.scale-textgroup')\n .attr('transform', 'translate(' + (scale.px + 8) + ',' + tickHeight + ')');\n\n selection.select('.scale-text')\n .text(scale.text);\n }\n\n\n return function(selection) {\n function switchUnits() {\n isImperial = !isImperial;\n selection.call(update);\n }\n\n var scalegroup = selection.append('svg')\n .attr('class', 'scale')\n .on('click', switchUnits)\n .append('g')\n .attr('transform', 'translate(10,11)');\n\n scalegroup\n .append('path')\n .attr('class', 'scale-path');\n\n scalegroup\n .append('g')\n .attr('class', 'scale-textgroup')\n .append('text')\n .attr('class', 'scale-text');\n\n selection.call(update);\n\n context.map().on('move.scale', function() {\n update(selection);\n });\n };\n}\n","import { select as d3_select } from 'd3-selection';\n\nimport { fileFetcher } from '../core/file_fetcher';\nimport { t } from '../core/localizer';\nimport { svgIcon } from '../svg/icon';\nimport { uiCmd } from './cmd';\nimport { uiModal } from './modal';\nimport { utilArrayUniq } from '../util';\nimport { utilDetect } from '../util/detect';\n\n\nexport function uiShortcuts(context) {\n var detected = utilDetect();\n var _activeTab = 0;\n var _modalSelection;\n var _selection = d3_select(null);\n\n\n context.keybinding()\n .on([t('shortcuts.toggle.key'), '?'], function () {\n if (context.container().selectAll('.modal-shortcuts').size()) { // already showing\n if (_modalSelection) {\n _modalSelection.close();\n _modalSelection = null;\n }\n } else {\n _modalSelection = uiModal(_selection);\n _modalSelection.call(shortcutsModal);\n }\n });\n\n\n function shortcutsModal(_modalSelection) {\n _modalSelection.select('.modal')\n .classed('modal-shortcuts', true);\n\n var content = _modalSelection.select('.content');\n\n content\n .append('div')\n .attr('class', 'modal-section')\n .append('h3')\n .text(t('shortcuts.title'));\n\n fileFetcher.get('shortcuts')\n .then(function(data) { content.call(render, data); })\n .catch(function() { /* ignore */ });\n }\n\n\n function render(selection, dataShortcuts) {\n var wrapper = selection\n .selectAll('.wrapper')\n .data([0]);\n\n var wrapperEnter = wrapper\n .enter()\n .append('div')\n .attr('class', 'wrapper modal-section');\n\n var tabsBar = wrapperEnter\n .append('div')\n .attr('class', 'tabs-bar');\n\n var shortcutsList = wrapperEnter\n .append('div')\n .attr('class', 'shortcuts-list');\n\n wrapper = wrapper.merge(wrapperEnter);\n\n var tabs = tabsBar\n .selectAll('.tab')\n .data(dataShortcuts);\n\n var tabsEnter = tabs\n .enter()\n .append('div')\n .attr('class', 'tab')\n .on('click', function (d, i) {\n _activeTab = i;\n render(selection, dataShortcuts);\n });\n\n tabsEnter\n .append('span')\n .text(function (d) { return t(d.text); });\n\n tabs = tabs\n .merge(tabsEnter);\n\n // Update\n wrapper.selectAll('.tab')\n .classed('active', function (d, i) {\n return i === _activeTab;\n });\n\n\n var shortcuts = shortcutsList\n .selectAll('.shortcut-tab')\n .data(dataShortcuts);\n\n var shortcutsEnter = shortcuts\n .enter()\n .append('div')\n .attr('class', function(d) { return 'shortcut-tab shortcut-tab-' + d.tab; });\n\n var columnsEnter = shortcutsEnter\n .selectAll('.shortcut-column')\n .data(function (d) { return d.columns; })\n .enter()\n .append('table')\n .attr('class', 'shortcut-column');\n\n var rowsEnter = columnsEnter\n .selectAll('.shortcut-row')\n .data(function (d) { return d.rows; })\n .enter()\n .append('tr')\n .attr('class', 'shortcut-row');\n\n\n var sectionRows = rowsEnter\n .filter(function (d) { return !d.shortcuts; });\n\n sectionRows\n .append('td');\n\n sectionRows\n .append('td')\n .attr('class', 'shortcut-section')\n .append('h3')\n .text(function (d) { return t(d.text); });\n\n\n var shortcutRows = rowsEnter\n .filter(function (d) { return d.shortcuts; });\n\n var shortcutKeys = shortcutRows\n .append('td')\n .attr('class', 'shortcut-keys');\n\n var modifierKeys = shortcutKeys\n .filter(function (d) { return d.modifiers; });\n\n modifierKeys\n .selectAll('kbd.modifier')\n .data(function (d) {\n if (detected.os === 'win' && d.text === 'shortcuts.editing.commands.redo') {\n return ['⌘'];\n } else if (detected.os !== 'mac' && d.text === 'shortcuts.browsing.display_options.fullscreen') {\n return [];\n } else {\n return d.modifiers;\n }\n })\n .enter()\n .each(function () {\n var selection = d3_select(this);\n\n selection\n .append('kbd')\n .attr('class', 'modifier')\n .text(function (d) { return uiCmd.display(d); });\n\n selection\n .append('span')\n .text('+');\n });\n\n\n shortcutKeys\n .selectAll('kbd.shortcut')\n .data(function (d) {\n var arr = d.shortcuts;\n if (detected.os === 'win' && d.text === 'shortcuts.editing.commands.redo') {\n arr = ['Y'];\n } else if (detected.os !== 'mac' && d.text === 'shortcuts.browsing.display_options.fullscreen') {\n arr = ['F11'];\n }\n\n // replace translations\n arr = arr.map(function(s) {\n return uiCmd.display(s.indexOf('.') !== -1 ? t(s) : s);\n });\n\n return utilArrayUniq(arr).map(function(s) {\n return {\n shortcut: s,\n separator: d.separator,\n suffix: d.suffix,\n rapid: d.rapid\n };\n });\n })\n .enter()\n .each(function (d, i, nodes) {\n var selection = d3_select(this);\n var click = d.shortcut.toLowerCase().match(/(.*).click/);\n\n if (click && click[1]) { // replace \"left_click\", \"right_click\" with mouse icon\n selection\n .call(svgIcon('#iD-walkthrough-mouse-' + click[1], 'operation'));\n } else if (d.shortcut.toLowerCase() === 'long-press') {\n selection\n .call(svgIcon('#iD-walkthrough-longpress', 'longpress operation'));\n } else if (d.shortcut.toLowerCase() === 'tap') {\n selection\n .call(svgIcon('#iD-walkthrough-tap', 'tap operation'));\n } else {\n selection\n .append('kbd')\n .attr('class', 'shortcut')\n .text(function (d) { return d.shortcut; });\n }\n\n if (i < nodes.length - 1) {\n selection\n .append('span')\n .text(d.separator || '\\u00a0' + t('shortcuts.or') + '\\u00a0');\n } else if (i === nodes.length - 1 && d.suffix) {\n selection\n .append('span')\n .text(d.suffix);\n }\n\n if (d.rapid){\n selection\n .append('svg')\n .lower()\n .attr('class', 'icon logo-rapid')\n .append('use')\n .attr('xlink:href', '#iD-logo-rapid')\n .attr('class', '#iD-logo-rapid'); \n }\n });\n\n shortcutKeys\n .filter(function(d) { return d.gesture; })\n .each(function () {\n var selection = d3_select(this);\n\n selection\n .append('span')\n .text('+');\n\n selection\n .append('span')\n .attr('class', 'gesture')\n .text(function (d) { return t(d.gesture); });\n });\n\n\n shortcutRows\n .append('td')\n .attr('class', 'shortcut-desc')\n .text(function (d) { return d.text ? t(d.text) : '\\u00a0'; });\n\n\n shortcuts = shortcuts\n .merge(shortcutsEnter);\n\n // Update\n wrapper.selectAll('.shortcut-tab')\n .style('display', function (d, i) {\n return i === _activeTab ? 'flex' : 'none';\n });\n }\n\n\n return function(selection, show) {\n _selection = selection;\n if (show) {\n _modalSelection = uiModal(selection);\n _modalSelection.call(shortcutsModal);\n }\n };\n}\n","import { t } from '../core/localizer';\nimport { svgIcon } from '../svg/icon';\n\n\nexport function uiDataHeader() {\n var _datum;\n\n\n function dataHeader(selection) {\n var header = selection.selectAll('.data-header')\n .data(\n (_datum ? [_datum] : []),\n function(d) { return d.__featurehash__; }\n );\n\n header.exit()\n .remove();\n\n var headerEnter = header.enter()\n .append('div')\n .attr('class', 'data-header');\n\n var iconEnter = headerEnter\n .append('div')\n .attr('class', 'data-header-icon');\n\n iconEnter\n .append('div')\n .attr('class', 'preset-icon-28')\n .call(svgIcon('#iD-icon-data', 'note-fill'));\n\n headerEnter\n .append('div')\n .attr('class', 'data-header-label')\n .text(t('map_data.layers.custom.title'));\n }\n\n\n dataHeader.datum = function(val) {\n if (!arguments.length) return _datum;\n _datum = val;\n return this;\n };\n\n\n return dataHeader;\n}\n","import { t } from '../core/localizer';\nimport { modeBrowse } from '../modes/browse';\nimport { svgIcon } from '../svg/icon';\n\nimport { uiDataHeader } from './data_header';\nimport { uiSectionRawTagEditor } from './sections/raw_tag_editor';\n\n\nexport function uiDataEditor(context) {\n var dataHeader = uiDataHeader();\n var rawTagEditor = uiSectionRawTagEditor('custom-data-tag-editor', context)\n .expandedByDefault(true)\n .readOnlyTags([/./]);\n var _datum;\n\n\n function dataEditor(selection) {\n\n var header = selection.selectAll('.header')\n .data([0]);\n\n var headerEnter = header.enter()\n .append('div')\n .attr('class', 'header fillL');\n\n headerEnter\n .append('button')\n .attr('class', 'close')\n .on('click', function() {\n context.enter(modeBrowse(context));\n })\n .call(svgIcon('#iD-icon-close'));\n\n headerEnter\n .append('h3')\n .text(t('map_data.title'));\n\n\n var body = selection.selectAll('.body')\n .data([0]);\n\n body = body.enter()\n .append('div')\n .attr('class', 'body')\n .merge(body);\n\n var editor = body.selectAll('.data-editor')\n .data([0]);\n\n // enter/update\n editor.enter()\n .append('div')\n .attr('class', 'modal-section data-editor')\n .merge(editor)\n .call(dataHeader.datum(_datum));\n\n var rte = body.selectAll('.raw-tag-editor')\n .data([0]);\n\n // enter/update\n rte.enter()\n .append('div')\n .attr('class', 'raw-tag-editor data-editor')\n .merge(rte)\n .call(rawTagEditor\n .tags((_datum && _datum.properties) || {})\n .state('hover')\n .render\n )\n .selectAll('textarea.tag-text')\n .attr('readonly', true)\n .classed('readonly', true);\n }\n\n\n dataEditor.datum = function(val) {\n if (!arguments.length) return _datum;\n _datum = val;\n return this;\n };\n\n\n return dataEditor;\n}\n","module.exports = element;\nmodule.exports.pair = pair;\nmodule.exports.format = format;\nmodule.exports.formatPair = formatPair;\nmodule.exports.coordToDMS = coordToDMS;\n\n\nfunction element(input, dims) {\n var result = search(input, dims);\n return (result === null) ? null : result.val;\n}\n\n\nfunction formatPair(input) {\n return format(input.lat, 'lat') + ' ' + format(input.lon, 'lon');\n}\n\n\n// Is 0 North or South?\nfunction format(input, dim) {\n var dms = coordToDMS(input, dim);\n return dms.whole + '° ' +\n (dms.minutes ? dms.minutes + '\\' ' : '') +\n (dms.seconds ? dms.seconds + '\" ' : '') + dms.dir;\n}\n\n\nfunction coordToDMS(input, dim) {\n var dirs = { lat: ['N', 'S'], lon: ['E', 'W'] }[dim] || '';\n var dir = dirs[input >= 0 ? 0 : 1];\n var abs = Math.abs(input);\n var whole = Math.floor(abs);\n var fraction = abs - whole;\n var fractionMinutes = fraction * 60;\n var minutes = Math.floor(fractionMinutes);\n var seconds = Math.floor((fractionMinutes - minutes) * 60);\n\n return {\n whole: whole,\n minutes: minutes,\n seconds: seconds,\n dir: dir\n };\n}\n\n\nfunction search(input, dims) {\n if (!dims) dims = 'NSEW';\n if (typeof input !== 'string') return null;\n\n input = input.toUpperCase();\n var regex = /^[\\s\\,]*([NSEW])?\\s*([\\-|\\—|\\―]?[0-9.]+)[°º˚]?\\s*(?:([0-9.]+)['’′‘]\\s*)?(?:([0-9.]+)(?:''|\"|”|″)\\s*)?([NSEW])?/;\n\n var m = input.match(regex);\n if (!m) return null; // no match\n\n var matched = m[0];\n\n // extract dimension.. m[1] = leading, m[5] = trailing\n var dim;\n if (m[1] && m[5]) { // if matched both..\n dim = m[1]; // keep leading\n matched = matched.slice(0, -1); // remove trailing dimension from match\n } else {\n dim = m[1] || m[5];\n }\n\n // if unrecognized dimension\n if (dim && dims.indexOf(dim) === -1) return null;\n\n // extract DMS\n var deg = m[2] ? parseFloat(m[2]) : 0;\n var min = m[3] ? parseFloat(m[3]) / 60 : 0;\n var sec = m[4] ? parseFloat(m[4]) / 3600 : 0;\n var sign = (deg < 0) ? -1 : 1;\n if (dim === 'S' || dim === 'W') sign *= -1;\n\n return {\n val: (Math.abs(deg) + min + sec) * sign,\n dim: dim,\n matched: matched,\n remain: input.slice(matched.length)\n };\n}\n\n\nfunction pair(input, dims) {\n input = input.trim();\n var one = search(input, dims);\n if (!one) return null;\n\n input = one.remain.trim();\n var two = search(input, dims);\n if (!two || two.remain) return null;\n\n if (one.dim) {\n return swapdim(one.val, two.val, one.dim);\n } else {\n return [one.val, two.val];\n }\n}\n\n\nfunction swapdim(a, b, dim) {\n if (dim === 'N' || dim === 'S') return [a, b];\n if (dim === 'W' || dim === 'E') return [b, a];\n}\n","import {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\nimport * as sexagesimal from '@mapbox/sexagesimal';\n\nimport { presetManager } from '../presets';\nimport { t } from '../core/localizer';\nimport { dmsCoordinatePair } from '../util/units';\nimport { coreGraph } from '../core/graph';\nimport { geoSphericalDistance } from '../geo/geo';\nimport { geoExtent } from '../geo';\nimport { modeSelect } from '../modes/select';\nimport { osmEntity } from '../osm/entity';\nimport { services } from '../services';\nimport { svgIcon } from '../svg/icon';\nimport { uiCmd } from './cmd';\n\nimport {\n utilDisplayName,\n utilDisplayType,\n utilHighlightEntities,\n utilNoAuto\n} from '../util';\n\n\nexport function uiFeatureList(context) {\n var _geocodeResults;\n\n\n function featureList(selection) {\n var header = selection\n .append('div')\n .attr('class', 'header fillL cf');\n\n header\n .append('h3')\n .text(t('inspector.feature_list'));\n\n var searchWrap = selection\n .append('div')\n .attr('class', 'search-header');\n\n var search = searchWrap\n .append('input')\n .attr('placeholder', t('inspector.search'))\n .attr('type', 'search')\n .call(utilNoAuto)\n .on('keypress', keypress)\n .on('keydown', keydown)\n .on('input', inputevent);\n\n searchWrap\n .call(svgIcon('#iD-icon-search', 'pre-text'));\n\n var listWrap = selection\n .append('div')\n .attr('class', 'inspector-body');\n\n var list = listWrap\n .append('div')\n .attr('class', 'feature-list cf');\n\n context\n .on('exit.feature-list', clearSearch);\n context.map()\n .on('drawn.feature-list', mapDrawn);\n\n context.keybinding()\n .on(uiCmd('⌘F'), focusSearch);\n\n\n function focusSearch() {\n var mode = context.mode() && context.mode().id;\n if (mode !== 'browse') return;\n\n d3_event.preventDefault();\n search.node().focus();\n }\n\n\n function keydown() {\n if (d3_event.keyCode === 27) { // escape\n search.node().blur();\n }\n }\n\n\n function keypress() {\n var q = search.property('value'),\n items = list.selectAll('.feature-list-item');\n if (d3_event.keyCode === 13 && q.length && items.size()) { // return\n click(items.datum());\n }\n }\n\n\n function inputevent() {\n _geocodeResults = undefined;\n drawList();\n }\n\n\n function clearSearch() {\n search.property('value', '');\n drawList();\n }\n\n\n function mapDrawn(e) {\n if (e.full) {\n drawList();\n }\n }\n\n\n function features() {\n var result = [];\n var graph = context.graph();\n var visibleCenter = context.map().extent().center();\n var q = search.property('value').toLowerCase();\n\n if (!q) return result;\n\n var idMatch = q.match(/(?:^|\\W)(node|way|relation|[nwr])\\W?0*([1-9]\\d*)(?:\\W|$)/i);\n\n if (idMatch) {\n var elemType = idMatch[1].charAt(0);\n var elemId = idMatch[2];\n result.push({\n id: elemType + elemId,\n geometry: elemType === 'n' ? 'point' : elemType === 'w' ? 'line' : 'relation',\n type: elemType === 'n' ? t('inspector.node') : elemType === 'w' ? t('inspector.way') : t('inspector.relation'),\n name: elemId\n });\n }\n\n var locationMatch = sexagesimal.pair(q.toUpperCase()) || q.match(/^(-?\\d+\\.?\\d*)\\s+(-?\\d+\\.?\\d*)$/);\n\n if (locationMatch) {\n var loc = [parseFloat(locationMatch[0]), parseFloat(locationMatch[1])];\n result.push({\n id: -1,\n geometry: 'point',\n type: t('inspector.location'),\n name: dmsCoordinatePair([loc[1], loc[0]]),\n location: loc\n });\n }\n\n var allEntities = graph.entities;\n var localResults = [];\n for (var id in allEntities) {\n var entity = allEntities[id];\n if (!entity) continue;\n\n var name = utilDisplayName(entity) || '';\n if (name.toLowerCase().indexOf(q) < 0) continue;\n\n var matched = presetManager.match(entity, graph);\n var type = (matched && matched.name()) || utilDisplayType(entity.id);\n var extent = entity.extent(graph);\n var distance = extent ? geoSphericalDistance(visibleCenter, extent.center()) : 0;\n\n localResults.push({\n id: entity.id,\n entity: entity,\n geometry: entity.geometry(graph),\n type: type,\n name: name,\n distance: distance\n });\n\n if (localResults.length > 100) break;\n }\n localResults = localResults.sort(function byDistance(a, b) {\n return a.distance - b.distance;\n });\n result = result.concat(localResults);\n\n (_geocodeResults || []).forEach(function(d) {\n if (d.osm_type && d.osm_id) { // some results may be missing these - #1890\n\n // Make a temporary osmEntity so we can preset match\n // and better localize the search result - #4725\n var id = osmEntity.id.fromOSM(d.osm_type, d.osm_id);\n var tags = {};\n tags[d.class] = d.type;\n\n var attrs = { id: id, type: d.osm_type, tags: tags };\n if (d.osm_type === 'way') { // for ways, add some fake closed nodes\n attrs.nodes = ['a','a']; // so that geometry area is possible\n }\n\n var tempEntity = osmEntity(attrs);\n var tempGraph = coreGraph([tempEntity]);\n var matched = presetManager.match(tempEntity, tempGraph);\n var type = (matched && matched.name()) || utilDisplayType(id);\n\n result.push({\n id: tempEntity.id,\n geometry: tempEntity.geometry(tempGraph),\n type: type,\n name: d.display_name,\n extent: new geoExtent(\n [parseFloat(d.boundingbox[3]), parseFloat(d.boundingbox[0])],\n [parseFloat(d.boundingbox[2]), parseFloat(d.boundingbox[1])])\n });\n }\n });\n\n if (q.match(/^[0-9]+$/)) {\n // if query is just a number, possibly an OSM ID without a prefix\n result.push({\n id: 'n' + q,\n geometry: 'point',\n type: t('inspector.node'),\n name: q\n });\n result.push({\n id: 'w' + q,\n geometry: 'line',\n type: t('inspector.way'),\n name: q\n });\n result.push({\n id: 'r' + q,\n geometry: 'relation',\n type: t('inspector.relation'),\n name: q\n });\n }\n\n return result;\n }\n\n\n function drawList() {\n var value = search.property('value');\n var results = features();\n\n list.classed('filtered', value.length);\n\n var resultsIndicator = list.selectAll('.no-results-item')\n .data([0])\n .enter()\n .append('button')\n .property('disabled', true)\n .attr('class', 'no-results-item')\n .call(svgIcon('#iD-icon-alert', 'pre-text'));\n\n resultsIndicator.append('span')\n .attr('class', 'entity-name');\n\n list.selectAll('.no-results-item .entity-name')\n .text(t('geocoder.no_results_worldwide'));\n\n if (services.geocoder) {\n list.selectAll('.geocode-item')\n .data([0])\n .enter()\n .append('button')\n .attr('class', 'geocode-item')\n .on('click', geocoderSearch)\n .append('div')\n .attr('class', 'label')\n .append('span')\n .attr('class', 'entity-name')\n .text(t('geocoder.search'));\n }\n\n list.selectAll('.no-results-item')\n .style('display', (value.length && !results.length) ? 'block' : 'none');\n\n list.selectAll('.geocode-item')\n .style('display', (value && _geocodeResults === undefined) ? 'block' : 'none');\n\n list.selectAll('.feature-list-item')\n .data([-1])\n .remove();\n\n var items = list.selectAll('.feature-list-item')\n .data(results, function(d) { return d.id; });\n\n var enter = items.enter()\n .insert('button', '.geocode-item')\n .attr('class', 'feature-list-item')\n .on('mouseover', mouseover)\n .on('mouseout', mouseout)\n .on('click', click);\n\n var label = enter\n .append('div')\n .attr('class', 'label');\n\n label\n .each(function(d) {\n d3_select(this)\n .call(svgIcon('#iD-icon-' + d.geometry, 'pre-text'));\n });\n\n label\n .append('span')\n .attr('class', 'entity-type')\n .text(function(d) { return d.type; });\n\n label\n .append('span')\n .attr('class', 'entity-name')\n .text(function(d) { return d.name; });\n\n enter\n .style('opacity', 0)\n .transition()\n .style('opacity', 1);\n\n items.order();\n\n items.exit()\n .remove();\n }\n\n\n function mouseover(d) {\n if (d.id === -1) return;\n\n utilHighlightEntities([d.id], true, context);\n }\n\n\n function mouseout(d) {\n if (d.id === -1) return;\n\n utilHighlightEntities([d.id], false, context);\n }\n\n\n function click(d) {\n d3_event.preventDefault();\n\n if (d.location) {\n context.map().centerZoomEase([d.location[1], d.location[0]], 19);\n\n } else if (d.entity) {\n utilHighlightEntities([d.id], false, context);\n\n context.enter(modeSelect(context, [d.entity.id]));\n context.map().zoomToEase(d.entity);\n\n } else {\n // download, zoom to, and select the entity with the given ID\n context.zoomToEntity(d.id);\n }\n }\n\n\n function geocoderSearch() {\n services.geocoder.search(search.property('value'), function (err, resp) {\n _geocodeResults = resp || [];\n drawList();\n });\n }\n }\n\n\n return featureList;\n}\n","import { event as d3_event, select as d3_select } from 'd3-selection';\n\nimport { svgIcon } from '../../svg/icon';\nimport { utilArrayIdentical } from '../../util/array';\nimport { t } from '../../core/localizer';\nimport { utilHighlightEntities } from '../../util';\nimport { uiSection } from '../section';\n\nexport function uiSectionEntityIssues(context) {\n\n var _entityIDs = [];\n var _issues = [];\n var _activeIssueID;\n\n var section = uiSection('entity-issues', context)\n .shouldDisplay(function() {\n return _issues.length > 0;\n })\n .title(function() {\n return t('issues.list_title', { count: _issues.length });\n })\n .disclosureContent(renderDisclosureContent);\n\n context.validator()\n .on('validated.entity_issues', function() {\n // Refresh on validated events\n reloadIssues();\n section.reRender();\n })\n .on('focusedIssue.entity_issues', function(issue) {\n makeActiveIssue(issue.id);\n });\n\n function reloadIssues() {\n _issues = context.validator().getSharedEntityIssues(_entityIDs, { includeDisabledRules: true });\n }\n\n function makeActiveIssue(issueID) {\n _activeIssueID = issueID;\n section.selection().selectAll('.issue-container')\n .classed('active', function(d) { return d.id === _activeIssueID; });\n }\n\n function renderDisclosureContent(selection) {\n\n selection.classed('grouped-items-area', true);\n\n _activeIssueID = _issues.length > 0 ? _issues[0].id : null;\n\n var containers = selection.selectAll('.issue-container')\n .data(_issues, function(d) { return d.id; });\n\n // Exit\n containers.exit()\n .remove();\n\n // Enter\n var containersEnter = containers.enter()\n .append('div')\n .attr('class', 'issue-container');\n\n\n var itemsEnter = containersEnter\n .append('div')\n .attr('class', function(d) { return 'issue severity-' + d.severity; })\n .on('mouseover.highlight', function(d) {\n // don't hover-highlight the selected entity\n var ids = d.entityIds\n .filter(function(e) { return _entityIDs.indexOf(e) === -1; });\n\n utilHighlightEntities(ids, true, context);\n })\n .on('mouseout.highlight', function(d) {\n var ids = d.entityIds\n .filter(function(e) { return _entityIDs.indexOf(e) === -1; });\n\n utilHighlightEntities(ids, false, context);\n });\n\n var labelsEnter = itemsEnter\n .append('div')\n .attr('class', 'issue-label')\n .on('click', function(d) {\n\n makeActiveIssue(d.id); // expand only the clicked item\n\n var extent = d.extent(context.graph());\n if (extent) {\n var setZoom = Math.max(context.map().zoom(), 19);\n context.map().unobscuredCenterZoomEase(extent.center(), setZoom);\n }\n });\n\n var textEnter = labelsEnter\n .append('span')\n .attr('class', 'issue-text');\n\n textEnter\n .append('span')\n .attr('class', 'issue-icon')\n .each(function(d) {\n var iconName = '#iD-icon-' + (d.severity === 'warning' ? 'alert' : 'error');\n d3_select(this)\n .call(svgIcon(iconName));\n });\n\n textEnter\n .append('span')\n .attr('class', 'issue-message');\n\n\n var infoButton = labelsEnter\n .append('button')\n .attr('class', 'issue-info-button')\n .attr('title', t('icons.information'))\n .attr('tabindex', -1)\n .call(svgIcon('#iD-icon-inspect'));\n\n infoButton\n .on('click', function () {\n d3_event.stopPropagation();\n d3_event.preventDefault();\n this.blur(); // avoid keeping focus on the button - #4641\n\n var container = d3_select(this.parentNode.parentNode.parentNode);\n var info = container.selectAll('.issue-info');\n var isExpanded = info.classed('expanded');\n\n if (isExpanded) {\n info\n .transition()\n .duration(200)\n .style('max-height', '0px')\n .style('opacity', '0')\n .on('end', function () {\n info.classed('expanded', false);\n });\n } else {\n info\n .classed('expanded', true)\n .transition()\n .duration(200)\n .style('max-height', '200px')\n .style('opacity', '1')\n .on('end', function () {\n info.style('max-height', null);\n });\n }\n });\n\n itemsEnter\n .append('ul')\n .attr('class', 'issue-fix-list');\n\n containersEnter\n .append('div')\n .attr('class', 'issue-info')\n .style('max-height', '0')\n .style('opacity', '0')\n .each(function(d) {\n if (typeof d.reference === 'function') {\n d3_select(this)\n .call(d.reference);\n } else {\n d3_select(this)\n .text(t('inspector.no_documentation_key'));\n }\n });\n\n\n // Update\n containers = containers\n .merge(containersEnter)\n .classed('active', function(d) { return d.id === _activeIssueID; });\n\n containers.selectAll('.issue-message')\n .text(function(d) {\n return d.message(context);\n });\n\n // fixes\n var fixLists = containers.selectAll('.issue-fix-list');\n\n var fixes = fixLists.selectAll('.issue-fix-item')\n .data(function(d) { return d.fixes ? d.fixes(context) : []; }, function(fix) { return fix.id; });\n\n fixes.exit()\n .remove();\n\n var fixesEnter = fixes.enter()\n .append('li')\n .attr('class', 'issue-fix-item')\n .on('click', function(d) {\n // not all fixes are actionable\n if (!d3_select(this).classed('actionable') || !d.onClick) return;\n\n // Don't run another fix for this issue within a second of running one\n // (Necessary for \"Select a feature type\" fix. Most fixes should only ever run once)\n if (d.issue.dateLastRanFix && new Date() - d.issue.dateLastRanFix < 1000) return;\n d.issue.dateLastRanFix = new Date();\n\n // remove hover-highlighting\n utilHighlightEntities(d.issue.entityIds.concat(d.entityIds), false, context);\n\n new Promise(function(resolve, reject) {\n d.onClick(context, resolve, reject);\n if (d.onClick.length <= 1) {\n // if the fix doesn't take any completion parameters then consider it resolved\n resolve();\n }\n })\n .then(function() {\n // revalidate whenever the fix has finished running successfully\n context.validator().validate();\n });\n })\n .on('mouseover.highlight', function(d) {\n utilHighlightEntities(d.entityIds, true, context);\n })\n .on('mouseout.highlight', function(d) {\n utilHighlightEntities(d.entityIds, false, context);\n });\n\n fixesEnter\n .append('span')\n .attr('class', 'fix-icon')\n .each(function(d) {\n var iconName = d.icon || 'iD-icon-wrench';\n if (iconName.startsWith('maki')) {\n iconName += '-15';\n }\n d3_select(this).call(svgIcon('#' + iconName));\n });\n\n fixesEnter\n .append('span')\n .attr('class', 'fix-message')\n .text(function(d) { return d.title; });\n\n fixesEnter.merge(fixes)\n .classed('actionable', function(d) {\n return d.onClick;\n })\n .attr('title', function(d) {\n if (d.disabledReason) {\n return d.disabledReason;\n }\n return null;\n });\n }\n\n section.entityIDs = function(val) {\n if (!arguments.length) return _entityIDs;\n if (!_entityIDs || !val || !utilArrayIdentical(_entityIDs, val)) {\n _entityIDs = val;\n _activeIssueID = null;\n reloadIssues();\n }\n return section;\n };\n\n return section;\n}\n","import { select as d3_select } from 'd3-selection';\n\nimport { presetManager } from '../presets';\nimport { prefs } from '../core/preferences';\nimport { svgIcon, svgTagClasses } from '../svg';\nimport { utilFunctor } from '../util';\n\n\nexport function uiPresetIcon() {\n let _preset;\n let _geometry;\n let _sizeClass = 'medium';\n\n\n function isSmall() {\n return _sizeClass === 'small';\n }\n\n\n function presetIcon(selection) {\n selection.each(render);\n }\n\n\n function getIcon(p, geom) {\n if (isSmall() && p.isFallback && p.isFallback())\n return 'iD-icon-' + p.id;\n else if (p.icon)\n return p.icon;\n else if (geom === 'line')\n return 'iD-other-line';\n else if (geom === 'vertex')\n return p.isFallback() ? '' : 'temaki-vertex';\n else if (isSmall() && geom === 'point')\n return '';\n else\n return 'maki-marker-stroked';\n }\n\n\n function renderPointBorder(enter) {\n const w = 40;\n const h = 40;\n\n enter\n .append('svg')\n .attr('class', 'preset-icon-fill preset-icon-point-border')\n .attr('width', w)\n .attr('height', h)\n .attr('viewBox', `0 0 ${w} ${h}`)\n .append('path')\n .attr('transform', 'translate(11.5, 8)')\n .attr('d', 'M 17,8 C 17,13 11,21 8.5,23.5 C 6,21 0,13 0,8 C 0,4 4,-0.5 8.5,-0.5 C 13,-0.5 17,4 17,8 z');\n }\n\n\n function renderCircleFill(fillEnter) {\n const w = 60;\n const h = 60;\n const d = 40;\n\n fillEnter\n .append('svg')\n .attr('class', 'preset-icon-fill preset-icon-fill-vertex')\n .attr('width', w)\n .attr('height', h)\n .attr('viewBox', `0 0 ${w} ${h}`)\n .append('circle')\n .attr('cx', w / 2)\n .attr('cy', h / 2)\n .attr('r', d / 2);\n }\n\n\n function renderSquareFill(fillEnter) {\n const d = isSmall() ? 40 : 60;\n const w = d;\n const h = d;\n const l = d * 2/3;\n const c1 = (w-l) / 2;\n const c2 = c1 + l;\n\n fillEnter = fillEnter\n .append('svg')\n .attr('class', 'preset-icon-fill preset-icon-fill-area')\n .attr('width', w)\n .attr('height', h)\n .attr('viewBox', `0 0 ${w} ${h}`);\n\n ['fill', 'stroke'].forEach(klass => {\n fillEnter\n .append('path')\n .attr('d', `M${c1} ${c1} L${c1} ${c2} L${c2} ${c2} L${c2} ${c1} Z`)\n .attr('class', `line area ${klass}`);\n });\n\n const rVertex = 2.5;\n [[c1, c1], [c1, c2], [c2, c2], [c2, c1]].forEach(point => {\n fillEnter\n .append('circle')\n .attr('class', 'vertex')\n .attr('cx', point[0])\n .attr('cy', point[1])\n .attr('r', rVertex);\n });\n\n if (!isSmall()) {\n const rMidpoint = 1.25;\n [[c1, w/2], [c2, w/2], [h/2, c1], [h/2, c2]].forEach(point => {\n fillEnter\n .append('circle')\n .attr('class', 'midpoint')\n .attr('cx', point[0])\n .attr('cy', point[1])\n .attr('r', rMidpoint);\n });\n }\n }\n\n\n function renderLine(lineEnter) {\n const d = isSmall() ? 40 : 60;\n // draw the line parametrically\n const w = d;\n const h = d;\n const y = Math.round(d * 0.72);\n const l = Math.round(d * 0.6);\n const r = 2.5;\n const x1 = (w - l) / 2;\n const x2 = x1 + l;\n\n lineEnter = lineEnter\n .append('svg')\n .attr('class', 'preset-icon-line')\n .attr('width', w)\n .attr('height', h)\n .attr('viewBox', `0 0 ${w} ${h}`);\n\n ['casing', 'stroke'].forEach(klass => {\n lineEnter\n .append('path')\n .attr('d', `M${x1} ${y} L${x2} ${y}`)\n .attr('class', `line ${klass}`);\n });\n\n [[x1-1, y], [x2+1, y]].forEach(point => {\n lineEnter\n .append('circle')\n .attr('class', 'vertex')\n .attr('cx', point[0])\n .attr('cy', point[1])\n .attr('r', r);\n });\n }\n\n\n function renderRoute(routeEnter) {\n const d = isSmall() ? 40 : 60;\n // draw the route parametrically\n const w = d;\n const h = d;\n const y1 = Math.round(d * 0.80);\n const y2 = Math.round(d * 0.68);\n const l = Math.round(d * 0.6);\n const r = 2;\n const x1 = (w - l) / 2;\n const x2 = x1 + l / 3;\n const x3 = x2 + l / 3;\n const x4 = x3 + l / 3;\n\n routeEnter = routeEnter\n .append('svg')\n .attr('class', 'preset-icon-route')\n .attr('width', w)\n .attr('height', h)\n .attr('viewBox', `0 0 ${w} ${h}`);\n\n ['casing', 'stroke'].forEach(klass => {\n routeEnter\n .append('path')\n .attr('d', `M${x1} ${y1} L${x2} ${y2}`)\n .attr('class', `segment0 line ${klass}`);\n routeEnter\n .append('path')\n .attr('d', `M${x2} ${y2} L${x3} ${y1}`)\n .attr('class', `segment1 line ${klass}`);\n routeEnter\n .append('path')\n .attr('d', `M${x3} ${y1} L${x4} ${y2}`)\n .attr('class', `segment2 line ${klass}`);\n });\n\n [[x1, y1], [x2, y2], [x3, y1], [x4, y2]].forEach(point => {\n routeEnter\n .append('circle')\n .attr('class', 'vertex')\n .attr('cx', point[0])\n .attr('cy', point[1])\n .attr('r', r);\n });\n }\n\n\n // Route icons are drawn with a zigzag annotation underneath:\n // o o\n // / \\ /\n // o o\n // This dataset defines the styles that are used to draw the zigzag segments.\n const routeSegments = {\n bicycle: ['highway/cycleway', 'highway/cycleway', 'highway/cycleway'],\n bus: ['highway/unclassified', 'highway/secondary', 'highway/primary'],\n trolleybus: ['highway/unclassified', 'highway/secondary', 'highway/primary'],\n detour: ['highway/tertiary', 'highway/residential', 'highway/unclassified'],\n ferry: ['route/ferry', 'route/ferry', 'route/ferry'],\n foot: ['highway/footway', 'highway/footway', 'highway/footway'],\n hiking: ['highway/path', 'highway/path', 'highway/path'],\n horse: ['highway/bridleway', 'highway/bridleway', 'highway/bridleway'],\n light_rail: ['railway/light_rail', 'railway/light_rail', 'railway/light_rail'],\n monorail: ['railway/monorail', 'railway/monorail', 'railway/monorail'],\n pipeline: ['man_made/pipeline', 'man_made/pipeline', 'man_made/pipeline'],\n piste: ['piste/downhill', 'piste/hike', 'piste/nordic'],\n power: ['power/line', 'power/line', 'power/line'],\n road: ['highway/secondary', 'highway/primary', 'highway/trunk'],\n subway: ['railway/subway', 'railway/subway', 'railway/subway'],\n train: ['railway/rail', 'railway/rail', 'railway/rail'],\n tram: ['railway/tram', 'railway/tram', 'railway/tram'],\n waterway: ['waterway/stream', 'waterway/stream', 'waterway/stream']\n };\n\n\n function render() {\n let p = _preset.apply(this, arguments);\n let geom = _geometry ? _geometry.apply(this, arguments) : null;\n if (geom === 'relation' && p.tags && ((p.tags.type === 'route' && p.tags.route && routeSegments[p.tags.route]) || p.tags.type === 'waterway')) {\n geom = 'route';\n }\n\n const showThirdPartyIcons = prefs('preferences.privacy.thirdpartyicons') || 'true';\n const isFallback = isSmall() && p.isFallback && p.isFallback();\n const imageURL = (showThirdPartyIcons === 'true') && p.imageURL;\n const picon = getIcon(p, geom);\n const isMaki = picon && /^maki-/.test(picon);\n const isTemaki = picon && /^temaki-/.test(picon);\n const isFa = picon && /^fa[srb]-/.test(picon);\n const isTnp = picon && /^tnp-/.test(picon);\n const isiDIcon = picon && !(isMaki || isTemaki || isFa || isTnp);\n const isCategory = !p.setTags;\n const drawPoint = picon && geom === 'point' && isSmall() && !isFallback;\n const drawVertex = picon !== null && geom === 'vertex' && (!isSmall() || !isFallback);\n const drawLine = picon && geom === 'line' && !isFallback && !isCategory;\n const drawArea = picon && geom === 'area' && !isFallback;\n const drawRoute = picon && geom === 'route';\n const isFramed = (drawVertex || drawArea || drawLine || drawRoute);\n\n let tags = !isCategory ? p.setTags({}, geom) : {};\n for (let k in tags) {\n if (tags[k] === '*') {\n tags[k] = 'yes';\n }\n }\n\n let tagClasses = svgTagClasses().getClassesString(tags, '');\n let selection = d3_select(this);\n\n let container = selection.selectAll('.preset-icon-container')\n .data([0]);\n\n container = container.enter()\n .append('div')\n .attr('class', `preset-icon-container ${_sizeClass}`)\n .merge(container);\n\n container\n .classed('showing-img', !!imageURL)\n .classed('fallback', isFallback);\n\n\n let pointBorder = container.selectAll('.preset-icon-point-border')\n .data(drawPoint ? [0] : []);\n\n pointBorder.exit()\n .remove();\n\n let pointBorderEnter = pointBorder.enter();\n renderPointBorder(pointBorderEnter);\n pointBorder = pointBorderEnter.merge(pointBorder);\n\n\n let vertexFill = container.selectAll('.preset-icon-fill-vertex')\n .data(drawVertex ? [0] : []);\n\n vertexFill.exit()\n .remove();\n\n let vertexFillEnter = vertexFill.enter();\n renderCircleFill(vertexFillEnter);\n vertexFill = vertexFillEnter.merge(vertexFill);\n\n\n let fill = container.selectAll('.preset-icon-fill-area')\n .data(drawArea ? [0] : []);\n\n fill.exit()\n .remove();\n\n let fillEnter = fill.enter();\n renderSquareFill(fillEnter);\n fill = fillEnter.merge(fill);\n\n fill.selectAll('path.stroke')\n .attr('class', `area stroke ${tagClasses}`);\n fill.selectAll('path.fill')\n .attr('class', `area fill ${tagClasses}`);\n\n\n let line = container.selectAll('.preset-icon-line')\n .data(drawLine ? [0] : []);\n\n line.exit()\n .remove();\n\n let lineEnter = line.enter();\n renderLine(lineEnter);\n line = lineEnter.merge(line);\n\n line.selectAll('path.stroke')\n .attr('class', `line stroke ${tagClasses}`);\n line.selectAll('path.casing')\n .attr('class', `line casing ${tagClasses}`);\n\n\n let route = container.selectAll('.preset-icon-route')\n .data(drawRoute ? [0] : []);\n\n route.exit()\n .remove();\n\n let routeEnter = route.enter();\n renderRoute(routeEnter);\n route = routeEnter.merge(route);\n\n if (drawRoute) {\n let routeType = p.tags.type === 'waterway' ? 'waterway' : p.tags.route;\n const segmentPresetIDs = routeSegments[routeType];\n for (let i in segmentPresetIDs) {\n const segmentPreset = presetManager.item(segmentPresetIDs[i]);\n const segmentTagClasses = svgTagClasses().getClassesString(segmentPreset.tags, '');\n route.selectAll(`path.stroke.segment${i}`)\n .attr('class', `segment${i} line stroke ${segmentTagClasses}`);\n route.selectAll(`path.casing.segment${i}`)\n .attr('class', `segment${i} line casing ${segmentTagClasses}`);\n }\n }\n\n\n let icon = container.selectAll('.preset-icon')\n .data(picon ? [0] : []);\n\n icon.exit()\n .remove();\n\n icon = icon.enter()\n .append('div')\n .attr('class', 'preset-icon')\n .call(svgIcon(''))\n .merge(icon);\n\n icon\n .attr('class', 'preset-icon ' + (geom ? geom + '-geom' : ''))\n .classed('framed', isFramed)\n .classed('preset-icon-iD', isiDIcon);\n\n icon.selectAll('svg')\n .attr('class', 'icon ' + picon + ' ' + (!isiDIcon && geom !== 'line' ? '' : tagClasses));\n\n icon.selectAll('use')\n .attr('href', '#' + picon + (isMaki ? (isSmall() && geom === 'point' ? '-11' : '-15') : ''));\n\n let imageIcon = container.selectAll('img.image-icon')\n .data(imageURL ? [0] : []);\n\n imageIcon.exit()\n .remove();\n\n imageIcon = imageIcon.enter()\n .append('img')\n .attr('class', 'image-icon')\n .on('load', () => container.classed('showing-img', true) )\n .on('error', () => container.classed('showing-img', false) )\n .merge(imageIcon);\n\n imageIcon\n .attr('src', imageURL);\n }\n\n\n presetIcon.preset = function(val) {\n if (!arguments.length) return _preset;\n _preset = utilFunctor(val);\n return presetIcon;\n };\n\n\n presetIcon.geometry = function(val) {\n if (!arguments.length) return _geometry;\n _geometry = utilFunctor(val);\n return presetIcon;\n };\n\n\n presetIcon.sizeClass = function(val) {\n if (!arguments.length) return _sizeClass;\n _sizeClass = val;\n return presetIcon;\n };\n\n return presetIcon;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport {\n event as d3_event\n} from 'd3-selection';\n\nimport { presetManager } from '../../presets';\nimport { utilArrayIdentical } from '../../util/array';\nimport { t } from '../../core/localizer';\nimport { uiTooltip } from '../tooltip';\nimport { utilRebind } from '../../util';\nimport { uiPresetIcon } from '../preset_icon';\nimport { uiSection } from '../section';\nimport { uiTagReference } from '../tag_reference';\n\n\nexport function uiSectionFeatureType(context) {\n\n var dispatch = d3_dispatch('choose');\n\n var _entityIDs = [];\n var _presets = [];\n\n var _tagReference;\n\n var section = uiSection('feature-type', context)\n .title(t('inspector.feature_type'))\n .disclosureContent(renderDisclosureContent);\n\n function renderDisclosureContent(selection) {\n\n selection.classed('preset-list-item', true);\n selection.classed('mixed-types', _presets.length > 1);\n\n var presetButtonWrap = selection\n .selectAll('.preset-list-button-wrap')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'preset-list-button-wrap');\n\n var presetButton = presetButtonWrap\n .append('button')\n .attr('class', 'preset-list-button preset-reset')\n .call(uiTooltip()\n .title(t('inspector.back_tooltip'))\n .placement('bottom')\n );\n\n presetButton.append('div')\n .attr('class', 'preset-icon-container');\n\n presetButton\n .append('div')\n .attr('class', 'label')\n .append('div')\n .attr('class', 'label-inner');\n\n presetButtonWrap.append('div')\n .attr('class', 'accessory-buttons');\n\n var tagReferenceBodyWrap = selection\n .selectAll('.tag-reference-body-wrap')\n .data([0]);\n\n tagReferenceBodyWrap = tagReferenceBodyWrap\n .enter()\n .append('div')\n .attr('class', 'tag-reference-body-wrap')\n .merge(tagReferenceBodyWrap);\n\n // update header\n if (_tagReference) {\n selection.selectAll('.preset-list-button-wrap .accessory-buttons')\n .style('display', _presets.length === 1 ? null : 'none')\n .call(_tagReference.button);\n\n tagReferenceBodyWrap\n .style('display', _presets.length === 1 ? null : 'none')\n .call(_tagReference.body);\n }\n\n selection.selectAll('.preset-reset')\n .on('click', function() {\n dispatch.call('choose', this, _presets);\n })\n .on('pointerdown pointerup mousedown mouseup', function() {\n d3_event.preventDefault();\n d3_event.stopPropagation();\n });\n\n var geometries = entityGeometries();\n selection.select('.preset-list-item button')\n .call(uiPresetIcon()\n .geometry(_presets.length === 1 ? (geometries.length === 1 && geometries[0]) : null)\n .preset(_presets.length === 1 ? _presets[0] : presetManager.item('point'))\n );\n\n // NOTE: split on en-dash, not a hypen (to avoid conflict with hyphenated names)\n var names = _presets.length === 1 ? _presets[0].name().split(' – ') : [t('inspector.multiple_types')];\n\n var label = selection.select('.label-inner');\n var nameparts = label.selectAll('.namepart')\n .data(names, function(d) { return d; });\n\n nameparts.exit()\n .remove();\n\n nameparts\n .enter()\n .append('div')\n .attr('class', 'namepart')\n .text(function(d) { return d; });\n }\n\n section.entityIDs = function(val) {\n if (!arguments.length) return _entityIDs;\n _entityIDs = val;\n return section;\n };\n\n section.presets = function(val) {\n if (!arguments.length) return _presets;\n\n // don't reload the same preset\n if (!utilArrayIdentical(val, _presets)) {\n _presets = val;\n\n var geometries = entityGeometries();\n if (_presets.length === 1 && geometries.length) {\n _tagReference = uiTagReference(_presets[0].reference(geometries[0]), context)\n .showing(false);\n }\n }\n\n return section;\n };\n\n function entityGeometries() {\n\n var counts = {};\n\n for (var i in _entityIDs) {\n var geometry = context.graph().geometry(_entityIDs[i]);\n if (!counts[geometry]) counts[geometry] = 0;\n counts[geometry] += 1;\n }\n\n return Object.keys(counts).sort(function(geom1, geom2) {\n return counts[geom2] - counts[geom1];\n });\n }\n\n return utilRebind(section, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport {\n event as d3_event\n} from 'd3-selection';\n\nimport { presetManager } from '../../presets';\nimport { t, localizer } from '../../core/localizer';\nimport { utilArrayIdentical } from '../../util/array';\nimport { utilArrayUnion, utilRebind } from '../../util';\nimport { modeBrowse } from '../../modes/browse';\nimport { uiField } from '../field';\nimport { uiFormFields } from '../form_fields';\nimport { uiSection } from '../section';\n\nexport function uiSectionPresetFields(context) {\n\n var section = uiSection('preset-fields', context)\n .title(function() {\n return t('inspector.fields');\n })\n .disclosureContent(renderDisclosureContent);\n\n var dispatch = d3_dispatch('change', 'revert');\n var formFields = uiFormFields(context);\n var _state;\n var _fieldsArr;\n var _presets = [];\n var _tags;\n var _entityIDs;\n\n function renderDisclosureContent(selection) {\n if (!_fieldsArr) {\n\n var graph = context.graph();\n\n var geometries = Object.keys(_entityIDs.reduce(function(geoms, entityID) {\n return geoms[graph.entity(entityID).geometry(graph)] = true;\n }, {}));\n\n var presetsManager = presetManager;\n\n var allFields = [];\n var allMoreFields = [];\n var sharedTotalFields;\n\n _presets.forEach(function(preset) {\n var fields = preset.fields();\n var moreFields = preset.moreFields();\n\n allFields = utilArrayUnion(allFields, fields);\n allMoreFields = utilArrayUnion(allMoreFields, moreFields);\n\n if (!sharedTotalFields) {\n sharedTotalFields = utilArrayUnion(fields, moreFields);\n } else {\n sharedTotalFields = sharedTotalFields.filter(function(field) {\n return fields.indexOf(field) !== -1 || moreFields.indexOf(field) !== -1;\n });\n }\n });\n\n var sharedFields = allFields.filter(function(field) {\n return sharedTotalFields.indexOf(field) !== -1;\n });\n var sharedMoreFields = allMoreFields.filter(function(field) {\n return sharedTotalFields.indexOf(field) !== -1;\n });\n\n _fieldsArr = [];\n\n sharedFields.forEach(function(field) {\n if (field.matchAllGeometry(geometries)) {\n _fieldsArr.push(\n uiField(context, field, _entityIDs)\n );\n }\n });\n\n var singularEntity = _entityIDs.length === 1 && graph.hasEntity(_entityIDs[0]);\n if (singularEntity && singularEntity.isHighwayIntersection(graph) && presetsManager.field('restrictions')) {\n _fieldsArr.push(\n uiField(context, presetsManager.field('restrictions'), _entityIDs)\n );\n }\n\n var additionalFields = utilArrayUnion(sharedMoreFields, presetsManager.universal());\n additionalFields.sort(function(field1, field2) {\n return field1.label().localeCompare(field2.label(), localizer.localeCode());\n });\n\n additionalFields.forEach(function(field) {\n if (sharedFields.indexOf(field) === -1 &&\n field.matchAllGeometry(geometries)) {\n _fieldsArr.push(\n uiField(context, field, _entityIDs, { show: false })\n );\n }\n });\n\n _fieldsArr.forEach(function(field) {\n field\n .on('change', function(t, onInput) {\n dispatch.call('change', field, _entityIDs, t, onInput);\n })\n .on('revert', function(keys) {\n dispatch.call('revert', field, keys);\n });\n });\n }\n\n _fieldsArr.forEach(function(field) {\n field\n .state(_state)\n .tags(_tags);\n });\n\n\n selection\n .call(formFields\n .fieldsArr(_fieldsArr)\n .state(_state)\n .klass('grouped-items-area')\n );\n\n\n selection.selectAll('.wrap-form-field input')\n .on('keydown', function() {\n // if user presses enter, and combobox is not active, accept edits..\n if (d3_event.keyCode === 13 && context.container().select('.combobox').empty()) {\n context.enter(modeBrowse(context));\n }\n });\n }\n\n section.presets = function(val) {\n if (!arguments.length) return _presets;\n if (!_presets || !val || !utilArrayIdentical(_presets, val)) {\n _presets = val;\n _fieldsArr = null;\n }\n return section;\n };\n\n section.state = function(val) {\n if (!arguments.length) return _state;\n _state = val;\n return section;\n };\n\n section.tags = function(val) {\n if (!arguments.length) return _tags;\n _tags = val;\n // Don't reset _fieldsArr here.\n return section;\n };\n\n section.entityIDs = function(val) {\n if (!arguments.length) return _entityIDs;\n if (!val || !_entityIDs || !utilArrayIdentical(_entityIDs, val)) {\n _entityIDs = val;\n _fieldsArr = null;\n }\n return section;\n };\n\n return utilRebind(section, dispatch, 'on');\n}\n","import { drag as d3_drag } from 'd3-drag';\nimport {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { presetManager } from '../../presets';\nimport { t } from '../../core/localizer';\nimport { actionChangeMember } from '../../actions/change_member';\nimport { actionDeleteMember } from '../../actions/delete_member';\nimport { actionMoveMember } from '../../actions/move_member';\nimport { modeBrowse } from '../../modes/browse';\nimport { modeSelect } from '../../modes/select';\nimport { osmEntity } from '../../osm';\nimport { svgIcon } from '../../svg/icon';\nimport { services } from '../../services';\nimport { uiCombobox } from '../combobox';\nimport { uiSection } from '../section';\nimport { utilDisplayName, utilDisplayType, utilHighlightEntities, utilNoAuto, utilUniqueDomId } from '../../util';\n\n\nexport function uiSectionRawMemberEditor(context) {\n\n var section = uiSection('raw-member-editor', context)\n .shouldDisplay(function() {\n if (!_entityIDs || _entityIDs.length !== 1) return false;\n\n var entity = context.hasEntity(_entityIDs[0]);\n return entity && entity.type === 'relation';\n })\n .title(function() {\n var entity = context.hasEntity(_entityIDs[0]);\n if (!entity) return '';\n\n var gt = entity.members.length > _maxMembers ? '>' : '';\n var count = gt + entity.members.slice(0, _maxMembers).length;\n return t('inspector.title_count', { title: t('inspector.members'), count: count });\n })\n .disclosureContent(renderDisclosureContent);\n\n var taginfo = services.taginfo;\n var _entityIDs;\n var _maxMembers = 1000;\n\n function downloadMember(d) {\n d3_event.preventDefault();\n\n // display the loading indicator\n d3_select(this.parentNode).classed('tag-reference-loading', true);\n context.loadEntity(d.id, function() {\n section.reRender();\n });\n }\n\n function zoomToMember(d) {\n d3_event.preventDefault();\n\n var entity = context.entity(d.id);\n context.map().zoomToEase(entity);\n\n // highlight the feature in case it wasn't previously on-screen\n utilHighlightEntities([d.id], true, context);\n }\n\n\n function selectMember(d) {\n d3_event.preventDefault();\n\n // remove the hover-highlight styling\n utilHighlightEntities([d.id], false, context);\n\n var entity = context.entity(d.id);\n var mapExtent = context.map().extent();\n if (!entity.intersects(mapExtent, context.graph())) {\n // zoom to the entity if its extent is not visible now\n context.map().zoomToEase(entity);\n }\n\n context.enter(modeSelect(context, [d.id]));\n }\n\n\n function changeRole(d) {\n var oldRole = d.role;\n var newRole = context.cleanRelationRole(d3_select(this).property('value'));\n\n if (oldRole !== newRole) {\n var member = { id: d.id, type: d.type, role: newRole };\n context.perform(\n actionChangeMember(d.relation.id, member, d.index),\n t('operations.change_role.annotation')\n );\n }\n }\n\n\n function deleteMember(d) {\n\n // remove the hover-highlight styling\n utilHighlightEntities([d.id], false, context);\n\n context.perform(\n actionDeleteMember(d.relation.id, d.index),\n t('operations.delete_member.annotation')\n );\n\n if (!context.hasEntity(d.relation.id)) {\n context.enter(modeBrowse(context));\n }\n }\n\n function renderDisclosureContent(selection) {\n\n var entityID = _entityIDs[0];\n\n var memberships = [];\n var entity = context.entity(entityID);\n entity.members.slice(0, _maxMembers).forEach(function(member, index) {\n memberships.push({\n index: index,\n id: member.id,\n type: member.type,\n role: member.role,\n relation: entity,\n member: context.hasEntity(member.id),\n domId: utilUniqueDomId(entityID + '-member-' + index)\n });\n });\n\n var list = selection.selectAll('.member-list')\n .data([0]);\n\n list = list.enter()\n .append('ul')\n .attr('class', 'member-list')\n .merge(list);\n\n\n var items = list.selectAll('li')\n .data(memberships, function(d) {\n return osmEntity.key(d.relation) + ',' + d.index + ',' +\n (d.member ? osmEntity.key(d.member) : 'incomplete');\n });\n\n items.exit()\n .each(unbind)\n .remove();\n\n var itemsEnter = items.enter()\n .append('li')\n .attr('class', 'member-row form-field')\n .classed('member-incomplete', function(d) { return !d.member; });\n\n itemsEnter\n .each(function(d) {\n var item = d3_select(this);\n\n var label = item\n .append('label')\n .attr('class', 'field-label')\n .attr('for', d.domId);\n\n if (d.member) {\n // highlight the member feature in the map while hovering on the list item\n item\n .on('mouseover', function() {\n utilHighlightEntities([d.id], true, context);\n })\n .on('mouseout', function() {\n utilHighlightEntities([d.id], false, context);\n });\n\n var labelLink = label\n .append('span')\n .attr('class', 'label-text')\n .append('a')\n .attr('href', '#')\n .on('click', selectMember);\n\n labelLink\n .append('span')\n .attr('class', 'member-entity-type')\n .text(function(d) {\n var matched = presetManager.match(d.member, context.graph());\n return (matched && matched.name()) || utilDisplayType(d.member.id);\n });\n\n labelLink\n .append('span')\n .attr('class', 'member-entity-name')\n .text(function(d) { return utilDisplayName(d.member); });\n\n label\n .append('button')\n .attr('tabindex', -1)\n .attr('title', t('icons.remove'))\n .attr('class', 'remove member-delete')\n .call(svgIcon('#iD-operation-delete'));\n\n label\n .append('button')\n .attr('class', 'member-zoom')\n .attr('title', t('icons.zoom_to'))\n .call(svgIcon('#iD-icon-framed-dot', 'monochrome'))\n .on('click', zoomToMember);\n\n } else {\n var labelText = label\n .append('span')\n .attr('class', 'label-text');\n\n labelText\n .append('span')\n .attr('class', 'member-entity-type')\n .text(t('inspector.' + d.type, { id: d.id }));\n\n labelText\n .append('span')\n .attr('class', 'member-entity-name')\n .text(t('inspector.incomplete', { id: d.id }));\n\n label\n .append('button')\n .attr('class', 'member-download')\n .attr('title', t('icons.download'))\n .attr('tabindex', -1)\n .call(svgIcon('#iD-icon-load'))\n .on('click', downloadMember);\n }\n });\n\n var wrapEnter = itemsEnter\n .append('div')\n .attr('class', 'form-field-input-wrap form-field-input-member');\n\n wrapEnter\n .append('input')\n .attr('class', 'member-role')\n .attr('id', function(d) {\n return d.domId;\n })\n .property('type', 'text')\n .attr('placeholder', t('inspector.role'))\n .call(utilNoAuto);\n\n if (taginfo) {\n wrapEnter.each(bindTypeahead);\n }\n\n // update\n items = items\n .merge(itemsEnter)\n .order();\n\n items.select('input.member-role')\n .property('value', function(d) { return d.role; })\n .on('blur', changeRole)\n .on('change', changeRole);\n\n items.select('button.member-delete')\n .on('click', deleteMember);\n\n var dragOrigin, targetIndex;\n\n items.call(d3_drag()\n .on('start', function() {\n dragOrigin = {\n x: d3_event.x,\n y: d3_event.y\n };\n targetIndex = null;\n })\n .on('drag', function(d, index) {\n var x = d3_event.x - dragOrigin.x,\n y = d3_event.y - dragOrigin.y;\n\n if (!d3_select(this).classed('dragging') &&\n // don't display drag until dragging beyond a distance threshold\n Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)) <= 5) return;\n\n d3_select(this)\n .classed('dragging', true);\n\n targetIndex = null;\n\n selection.selectAll('li.member-row')\n .style('transform', function(d2, index2) {\n var node = d3_select(this).node();\n if (index === index2) {\n return 'translate(' + x + 'px, ' + y + 'px)';\n } else if (index2 > index && d3_event.y > node.offsetTop) {\n if (targetIndex === null || index2 > targetIndex) {\n targetIndex = index2;\n }\n return 'translateY(-100%)';\n } else if (index2 < index && d3_event.y < node.offsetTop + node.offsetHeight) {\n if (targetIndex === null || index2 < targetIndex) {\n targetIndex = index2;\n }\n return 'translateY(100%)';\n }\n return null;\n });\n })\n .on('end', function(d, index) {\n\n if (!d3_select(this).classed('dragging')) {\n return;\n }\n\n d3_select(this)\n .classed('dragging', false);\n\n selection.selectAll('li.member-row')\n .style('transform', null);\n\n if (targetIndex !== null) {\n // dragged to a new position, reorder\n context.perform(\n actionMoveMember(d.relation.id, index, targetIndex),\n t('operations.reorder_members.annotation')\n );\n }\n })\n );\n\n\n\n function bindTypeahead(d) {\n var row = d3_select(this);\n var role = row.selectAll('input.member-role');\n var origValue = role.property('value');\n\n function sort(value, data) {\n var sameletter = [];\n var other = [];\n for (var i = 0; i < data.length; i++) {\n if (data[i].value.substring(0, value.length) === value) {\n sameletter.push(data[i]);\n } else {\n other.push(data[i]);\n }\n }\n return sameletter.concat(other);\n }\n\n role.call(uiCombobox(context, 'member-role')\n .fetcher(function(role, callback) {\n // The `geometry` param is used in the `taginfo.js` interface for\n // filtering results, as a key into the `tag_members_fractions`\n // object. If we don't know the geometry because the member is\n // not yet downloaded, it's ok to guess based on type.\n var geometry;\n if (d.member) {\n geometry = context.graph().geometry(d.member.id);\n } else if (d.type === 'relation') {\n geometry = 'relation';\n } else if (d.type === 'way') {\n geometry = 'line';\n } else {\n geometry = 'point';\n }\n\n var rtype = entity.tags.type;\n taginfo.roles({\n debounce: true,\n rtype: rtype || '',\n geometry: geometry,\n query: role\n }, function(err, data) {\n if (!err) callback(sort(role, data));\n });\n })\n .on('cancel', function() {\n role.property('value', origValue);\n })\n );\n }\n\n\n function unbind() {\n var row = d3_select(this);\n\n row.selectAll('input.member-role')\n .call(uiCombobox.off, context);\n }\n }\n\n section.entityIDs = function(val) {\n if (!arguments.length) return _entityIDs;\n _entityIDs = val;\n return section;\n };\n\n\n return section;\n}\n","import {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { presetManager } from '../../presets';\nimport { t, localizer } from '../../core/localizer';\n\nimport { actionAddEntity } from '../../actions/add_entity';\nimport { actionAddMember } from '../../actions/add_member';\nimport { actionChangeMember } from '../../actions/change_member';\nimport { actionDeleteMember } from '../../actions/delete_member';\n\nimport { modeSelect } from '../../modes/select';\nimport { osmEntity, osmRelation } from '../../osm';\nimport { services } from '../../services';\nimport { svgIcon } from '../../svg/icon';\nimport { uiCombobox } from '../combobox';\nimport { uiSection } from '../section';\nimport { uiTooltip } from '../tooltip';\nimport { utilArrayGroupBy, utilDisplayName, utilNoAuto, utilHighlightEntities, utilUniqueDomId } from '../../util';\n\n\nexport function uiSectionRawMembershipEditor(context) {\n\n var section = uiSection('raw-membership-editor', context)\n .shouldDisplay(function() {\n return _entityIDs && _entityIDs.length === 1;\n })\n .title(function() {\n var entity = context.hasEntity(_entityIDs[0]);\n if (!entity) return '';\n\n var parents = context.graph().parentRelations(entity);\n var gt = parents.length > _maxMemberships ? '>' : '';\n var count = gt + parents.slice(0, _maxMemberships).length;\n return t('inspector.title_count', { title: t('inspector.relations'), count: count });\n })\n .disclosureContent(renderDisclosureContent);\n\n var taginfo = services.taginfo;\n var nearbyCombo = uiCombobox(context, 'parent-relation')\n .minItems(1)\n .fetcher(fetchNearbyRelations)\n .itemsMouseEnter(function(d) {\n if (d.relation) utilHighlightEntities([d.relation.id], true, context);\n })\n .itemsMouseLeave(function(d) {\n if (d.relation) utilHighlightEntities([d.relation.id], false, context);\n });\n var _inChange = false;\n var _entityIDs = [];\n var _showBlank;\n var _maxMemberships = 1000;\n\n function selectRelation(d) {\n d3_event.preventDefault();\n\n // remove the hover-highlight styling\n utilHighlightEntities([d.relation.id], false, context);\n\n context.enter(modeSelect(context, [d.relation.id]));\n }\n\n function zoomToRelation(d) {\n d3_event.preventDefault();\n\n var entity = context.entity(d.relation.id);\n context.map().zoomToEase(entity);\n\n // highlight the relation in case it wasn't previously on-screen\n utilHighlightEntities([d.relation.id], true, context);\n }\n\n\n function changeRole(d) {\n if (d === 0) return; // called on newrow (shoudn't happen)\n if (_inChange) return; // avoid accidental recursive call #5731\n\n var oldRole = d.member.role;\n var newRole = context.cleanRelationRole(d3_select(this).property('value'));\n\n if (oldRole !== newRole) {\n _inChange = true;\n context.perform(\n actionChangeMember(d.relation.id, Object.assign({}, d.member, { role: newRole }), d.index),\n t('operations.change_role.annotation')\n );\n }\n _inChange = false;\n }\n\n\n function addMembership(d, role) {\n this.blur(); // avoid keeping focus on the button\n _showBlank = false;\n\n var member = { id: _entityIDs[0], type: context.entity(_entityIDs[0]).type, role: role };\n\n if (d.relation) {\n context.perform(\n actionAddMember(d.relation.id, member),\n t('operations.add_member.annotation')\n );\n\n } else {\n var relation = osmRelation();\n context.perform(\n actionAddEntity(relation),\n actionAddMember(relation.id, member),\n t('operations.add.annotation.relation')\n );\n\n context.enter(modeSelect(context, [relation.id]).newFeature(true));\n }\n }\n\n\n function deleteMembership(d) {\n this.blur(); // avoid keeping focus on the button\n if (d === 0) return; // called on newrow (shoudn't happen)\n\n // remove the hover-highlight styling\n utilHighlightEntities([d.relation.id], false, context);\n\n context.perform(\n actionDeleteMember(d.relation.id, d.index),\n t('operations.delete_member.annotation')\n );\n }\n\n\n function fetchNearbyRelations(q, callback) {\n var newRelation = { relation: null, value: t('inspector.new_relation') };\n\n var entityID = _entityIDs[0];\n\n var result = [];\n\n var graph = context.graph();\n\n function baseDisplayLabel(entity) {\n var matched = presetManager.match(entity, graph);\n var presetName = (matched && matched.name()) || t('inspector.relation');\n var entityName = utilDisplayName(entity) || '';\n\n return presetName + ' ' + entityName;\n }\n\n var explicitRelation = q && context.hasEntity(q.toLowerCase());\n if (explicitRelation && explicitRelation.type === 'relation' && explicitRelation.id !== entityID) {\n // loaded relation is specified explicitly, only show that\n\n result.push({\n relation: explicitRelation,\n value: baseDisplayLabel(explicitRelation) + ' ' + explicitRelation.id\n });\n } else {\n\n context.history().intersects(context.map().extent()).forEach(function(entity) {\n if (entity.type !== 'relation' || entity.id === entityID) return;\n\n var value = baseDisplayLabel(entity);\n if (q && (value + ' ' + entity.id).toLowerCase().indexOf(q.toLowerCase()) === -1) return;\n\n result.push({ relation: entity, value: value });\n });\n\n result.sort(function(a, b) {\n return osmRelation.creationOrder(a.relation, b.relation);\n });\n\n // Dedupe identical names by appending relation id - see #2891\n var dupeGroups = Object.values(utilArrayGroupBy(result, 'value'))\n .filter(function(v) { return v.length > 1; });\n\n dupeGroups.forEach(function(group) {\n group.forEach(function(obj) {\n obj.value += ' ' + obj.relation.id;\n });\n });\n }\n\n result.forEach(function(obj) {\n obj.title = obj.value;\n });\n\n result.unshift(newRelation);\n callback(result);\n }\n\n function renderDisclosureContent(selection) {\n\n var entityID = _entityIDs[0];\n\n var entity = context.entity(entityID);\n var parents = context.graph().parentRelations(entity);\n\n var memberships = [];\n\n parents.slice(0, _maxMemberships).forEach(function(relation) {\n relation.members.forEach(function(member, index) {\n if (member.id === entity.id) {\n memberships.push({\n relation: relation,\n member: member,\n index: index,\n domId: utilUniqueDomId(entityID + '-membership-' + relation.id + '-' + index)\n });\n }\n });\n });\n\n var list = selection.selectAll('.member-list')\n .data([0]);\n\n list = list.enter()\n .append('ul')\n .attr('class', 'member-list')\n .merge(list);\n\n\n var items = list.selectAll('li.member-row-normal')\n .data(memberships, function(d) {\n return osmEntity.key(d.relation) + ',' + d.index;\n });\n\n items.exit()\n .each(unbind)\n .remove();\n\n // Enter\n var itemsEnter = items.enter()\n .append('li')\n .attr('class', 'member-row member-row-normal form-field');\n\n // highlight the relation in the map while hovering on the list item\n itemsEnter.on('mouseover', function(d) {\n utilHighlightEntities([d.relation.id], true, context);\n })\n .on('mouseout', function(d) {\n utilHighlightEntities([d.relation.id], false, context);\n });\n\n var labelEnter = itemsEnter\n .append('label')\n .attr('class', 'field-label')\n .attr('for', function(d) {\n return d.domId;\n });\n\n var labelLink = labelEnter\n .append('span')\n .attr('class', 'label-text')\n .append('a')\n .attr('href', '#')\n .on('click', selectRelation);\n\n labelLink\n .append('span')\n .attr('class', 'member-entity-type')\n .text(function(d) {\n var matched = presetManager.match(d.relation, context.graph());\n return (matched && matched.name()) || t('inspector.relation');\n });\n\n labelLink\n .append('span')\n .attr('class', 'member-entity-name')\n .text(function(d) { return utilDisplayName(d.relation); });\n\n labelEnter\n .append('button')\n .attr('tabindex', -1)\n .attr('class', 'remove member-delete')\n .call(svgIcon('#iD-operation-delete'))\n .on('click', deleteMembership);\n\n labelEnter\n .append('button')\n .attr('class', 'member-zoom')\n .attr('title', t('icons.zoom_to'))\n .call(svgIcon('#iD-icon-framed-dot', 'monochrome'))\n .on('click', zoomToRelation);\n\n var wrapEnter = itemsEnter\n .append('div')\n .attr('class', 'form-field-input-wrap form-field-input-member');\n\n wrapEnter\n .append('input')\n .attr('class', 'member-role')\n .attr('id', function(d) {\n return d.domId;\n })\n .property('type', 'text')\n .attr('placeholder', t('inspector.role'))\n .call(utilNoAuto)\n .property('value', function(d) { return d.member.role; })\n .on('blur', changeRole)\n .on('change', changeRole);\n\n if (taginfo) {\n wrapEnter.each(bindTypeahead);\n }\n\n\n var newMembership = list.selectAll('.member-row-new')\n .data(_showBlank ? [0] : []);\n\n // Exit\n newMembership.exit()\n .remove();\n\n // Enter\n var newMembershipEnter = newMembership.enter()\n .append('li')\n .attr('class', 'member-row member-row-new form-field');\n\n var newLabelEnter = newMembershipEnter\n .append('label')\n .attr('class', 'field-label');\n\n newLabelEnter\n .append('input')\n .attr('placeholder', t('inspector.choose_relation'))\n .attr('type', 'text')\n .attr('class', 'member-entity-input')\n .call(utilNoAuto);\n\n newLabelEnter\n .append('button')\n .attr('tabindex', -1)\n .attr('class', 'remove member-delete')\n .call(svgIcon('#iD-operation-delete'))\n .on('click', function() {\n list.selectAll('.member-row-new')\n .remove();\n });\n\n var newWrapEnter = newMembershipEnter\n .append('div')\n .attr('class', 'form-field-input-wrap form-field-input-member');\n\n newWrapEnter\n .append('input')\n .attr('class', 'member-role')\n .property('type', 'text')\n .attr('placeholder', t('inspector.role'))\n .call(utilNoAuto);\n\n // Update\n newMembership = newMembership\n .merge(newMembershipEnter);\n\n newMembership.selectAll('.member-entity-input')\n .on('blur', cancelEntity) // if it wasn't accepted normally, cancel it\n .call(nearbyCombo\n .on('accept', acceptEntity)\n .on('cancel', cancelEntity)\n );\n\n\n // Container for the Add button\n var addRow = selection.selectAll('.add-row')\n .data([0]);\n\n // enter\n var addRowEnter = addRow.enter()\n .append('div')\n .attr('class', 'add-row');\n\n var addRelationButton = addRowEnter\n .append('button')\n .attr('class', 'add-relation');\n\n addRelationButton\n .call(svgIcon('#iD-icon-plus', 'light'));\n addRelationButton\n .call(uiTooltip().title(t('inspector.add_to_relation')).placement(localizer.textDirection() === 'ltr' ? 'right' : 'left'));\n\n addRowEnter\n .append('div')\n .attr('class', 'space-value'); // preserve space\n\n addRowEnter\n .append('div')\n .attr('class', 'space-buttons'); // preserve space\n\n // update\n addRow = addRow\n .merge(addRowEnter);\n\n addRow.select('.add-relation')\n .on('click', function() {\n _showBlank = true;\n section.reRender();\n list.selectAll('.member-entity-input').node().focus();\n });\n\n\n function acceptEntity(d) {\n if (!d) {\n cancelEntity();\n return;\n }\n // remove hover-higlighting\n if (d.relation) utilHighlightEntities([d.relation.id], false, context);\n\n var role = context.cleanRelationRole(list.selectAll('.member-row-new .member-role').property('value'));\n addMembership(d, role);\n }\n\n\n function cancelEntity() {\n var input = newMembership.selectAll('.member-entity-input');\n input.property('value', '');\n\n // remove hover-higlighting\n context.surface().selectAll('.highlighted')\n .classed('highlighted', false);\n }\n\n\n function bindTypeahead(d) {\n var row = d3_select(this);\n var role = row.selectAll('input.member-role');\n var origValue = role.property('value');\n\n function sort(value, data) {\n var sameletter = [];\n var other = [];\n for (var i = 0; i < data.length; i++) {\n if (data[i].value.substring(0, value.length) === value) {\n sameletter.push(data[i]);\n } else {\n other.push(data[i]);\n }\n }\n return sameletter.concat(other);\n }\n\n role.call(uiCombobox(context, 'member-role')\n .fetcher(function(role, callback) {\n var rtype = d.relation.tags.type;\n taginfo.roles({\n debounce: true,\n rtype: rtype || '',\n geometry: context.graph().geometry(entityID),\n query: role\n }, function(err, data) {\n if (!err) callback(sort(role, data));\n });\n })\n .on('cancel', function() {\n role.property('value', origValue);\n })\n );\n }\n\n\n function unbind() {\n var row = d3_select(this);\n\n row.selectAll('input.member-role')\n .call(uiCombobox.off, context);\n }\n }\n\n\n section.entityIDs = function(val) {\n if (!arguments.length) return _entityIDs;\n _entityIDs = val;\n _showBlank = false;\n return section;\n };\n\n\n return section;\n}\n","import { event as d3_event, select as d3_select } from 'd3-selection';\n\nimport { presetManager } from '../../presets';\nimport { modeSelect } from '../../modes/select';\nimport { osmEntity } from '../../osm';\nimport { svgIcon } from '../../svg/icon';\nimport { uiSection } from '../section';\nimport { t } from '../../core/localizer';\nimport { utilDisplayName, utilHighlightEntities } from '../../util';\n\nexport function uiSectionSelectionList(context) {\n\n var _selectedIDs = [];\n\n var section = uiSection('selected-features', context)\n .shouldDisplay(function() {\n return _selectedIDs.length > 1;\n })\n .title(function() {\n return t('inspector.title_count', { title: t('inspector.features'), count: _selectedIDs.length });\n })\n .disclosureContent(renderDisclosureContent);\n\n context.history()\n .on('change.selectionList', function(difference) {\n if (difference) {\n section.reRender();\n }\n });\n\n section.entityIDs = function(val) {\n if (!arguments.length) return _selectedIDs;\n _selectedIDs = val;\n return section;\n };\n\n function selectEntity(entity) {\n context.enter(modeSelect(context, [entity.id]));\n }\n\n function deselectEntity(entity) {\n d3_event.stopPropagation();\n\n var selectedIDs = _selectedIDs.slice();\n var index = selectedIDs.indexOf(entity.id);\n if (index > -1) {\n selectedIDs.splice(index, 1);\n context.enter(modeSelect(context, selectedIDs));\n }\n }\n\n function renderDisclosureContent(selection) {\n\n var list = selection.selectAll('.feature-list')\n .data([0]);\n\n list = list.enter()\n .append('div')\n .attr('class', 'feature-list')\n .merge(list);\n\n var entities = _selectedIDs\n .map(function(id) { return context.hasEntity(id); })\n .filter(Boolean);\n\n var items = list.selectAll('.feature-list-item')\n .data(entities, osmEntity.key);\n\n items.exit()\n .remove();\n\n // Enter\n var enter = items.enter()\n .append('div')\n .attr('class', 'feature-list-item')\n .on('click', selectEntity);\n\n enter\n .each(function(d) {\n d3_select(this).on('mouseover', function() {\n utilHighlightEntities([d.id], true, context);\n });\n d3_select(this).on('mouseout', function() {\n utilHighlightEntities([d.id], false, context);\n });\n });\n\n var label = enter\n .append('button')\n .attr('class', 'label');\n\n enter\n .append('button')\n .attr('class', 'close')\n .attr('title', t('icons.deselect'))\n .on('click', deselectEntity)\n .call(svgIcon('#iD-icon-close'));\n\n label\n .append('span')\n .attr('class', 'entity-geom-icon')\n .call(svgIcon('', 'pre-text'));\n\n label\n .append('span')\n .attr('class', 'entity-type');\n\n label\n .append('span')\n .attr('class', 'entity-name');\n\n // Update\n items = items.merge(enter);\n\n items.selectAll('.entity-geom-icon use')\n .attr('href', function() {\n var entity = this.parentNode.parentNode.__data__;\n return '#iD-icon-' + entity.geometry(context.graph());\n });\n\n items.selectAll('.entity-type')\n .text(function(entity) { return presetManager.match(entity, context.graph()).name(); });\n\n items.selectAll('.entity-name')\n .text(function(d) {\n // fetch latest entity\n var entity = context.entity(d.id);\n return utilDisplayName(entity);\n });\n }\n\n return section;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { event as d3_event } from 'd3-selection';\nimport deepEqual from 'fast-deep-equal';\n\nimport { presetManager } from '../presets';\nimport { t, localizer } from '../core/localizer';\nimport { actionChangeTags } from '../actions/change_tags';\nimport { modeBrowse } from '../modes/browse';\nimport { svgIcon } from '../svg/icon';\nimport { utilArrayIdentical } from '../util/array';\nimport { utilCleanTags, utilCombinedTags, utilRebind } from '../util';\n\nimport { uiSectionEntityIssues } from './sections/entity_issues';\nimport { uiSectionFeatureType } from './sections/feature_type';\nimport { uiSectionPresetFields } from './sections/preset_fields';\nimport { uiSectionRawMemberEditor } from './sections/raw_member_editor';\nimport { uiSectionRawMembershipEditor } from './sections/raw_membership_editor';\nimport { uiSectionRawTagEditor } from './sections/raw_tag_editor';\nimport { uiSectionSelectionList } from './sections/selection_list';\n\nexport function uiEntityEditor(context) {\n var dispatch = d3_dispatch('choose');\n var _state = 'select';\n var _coalesceChanges = false;\n var _modified = false;\n var _base;\n var _entityIDs;\n var _activePresets = [];\n var _newFeature;\n\n var _sections;\n\n function entityEditor(selection) {\n\n var combinedTags = utilCombinedTags(_entityIDs, context.graph());\n\n // Header\n var header = selection.selectAll('.header')\n .data([0]);\n\n // Enter\n var headerEnter = header.enter()\n .append('div')\n .attr('class', 'header fillL cf');\n\n headerEnter\n .append('button')\n .attr('class', 'preset-reset preset-choose')\n .call(svgIcon((localizer.textDirection() === 'rtl') ? '#iD-icon-forward' : '#iD-icon-backward'));\n\n headerEnter\n .append('button')\n .attr('class', 'close')\n .on('click', function() { context.enter(modeBrowse(context)); })\n .call(svgIcon(_modified ? '#iD-icon-apply' : '#iD-icon-close'));\n\n headerEnter\n .append('h3');\n\n // Update\n header = header\n .merge(headerEnter);\n\n header.selectAll('h3')\n .text(_entityIDs.length === 1 ? t('inspector.edit') : t('inspector.edit_features'));\n\n header.selectAll('.preset-reset')\n .on('click', function() {\n dispatch.call('choose', this, _activePresets);\n });\n\n // Body\n var body = selection.selectAll('.inspector-body')\n .data([0]);\n\n // Enter\n var bodyEnter = body.enter()\n .append('div')\n .attr('class', 'entity-editor inspector-body sep-top');\n\n // Update\n body = body\n .merge(bodyEnter);\n\n if (!_sections) {\n _sections = [\n uiSectionSelectionList(context),\n uiSectionFeatureType(context).on('choose', function(presets) {\n dispatch.call('choose', this, presets);\n }),\n uiSectionEntityIssues(context),\n uiSectionPresetFields(context).on('change', changeTags).on('revert', revertTags),\n uiSectionRawTagEditor('raw-tag-editor', context).on('change', changeTags),\n uiSectionRawMemberEditor(context),\n uiSectionRawMembershipEditor(context)\n ];\n }\n\n _sections.forEach(function(section) {\n if (section.entityIDs) {\n section.entityIDs(_entityIDs);\n }\n if (section.presets) {\n section.presets(_activePresets);\n }\n if (section.tags) {\n section.tags(combinedTags);\n }\n if (section.state) {\n section.state(_state);\n }\n body.call(section.render);\n });\n\n body\n .selectAll('.key-trap-wrap')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'key-trap-wrap')\n .append('input')\n .attr('type', 'text')\n .attr('class', 'key-trap')\n .on('keydown.key-trap', function() {\n // On tabbing, send focus back to the first field on the inspector-body\n // (probably the `name` field) #4159\n if (d3_event.keyCode === 9 && !d3_event.shiftKey) {\n d3_event.preventDefault();\n body.select('input').node().focus();\n }\n });\n\n context.history()\n .on('change.entity-editor', historyChanged);\n\n function historyChanged(difference) {\n if (selection.selectAll('.entity-editor').empty()) return;\n if (_state === 'hide') return;\n var significant = !difference ||\n difference.didChange.properties ||\n difference.didChange.addition ||\n difference.didChange.deletion;\n if (!significant) return;\n\n _entityIDs = _entityIDs.filter(context.hasEntity);\n if (!_entityIDs.length) return;\n\n var priorActivePreset = _activePresets.length === 1 && _activePresets[0];\n\n loadActivePresets();\n\n var graph = context.graph();\n entityEditor.modified(_base !== graph);\n entityEditor(selection);\n\n if (priorActivePreset && _activePresets.length === 1 && priorActivePreset !== _activePresets[0]) {\n // flash the button to indicate the preset changed\n context.container().selectAll('.entity-editor button.preset-reset .label')\n .style('background-color', '#fff')\n .transition()\n .duration(750)\n .style('background-color', null);\n }\n }\n }\n\n\n // Tag changes that fire on input can all get coalesced into a single\n // history operation when the user leaves the field. #2342\n // Use explicit entityIDs in case the selection changes before the event is fired.\n function changeTags(entityIDs, changed, onInput) {\n\n var actions = [];\n for (var i in entityIDs) {\n var entityID = entityIDs[i];\n var entity = context.entity(entityID);\n\n var tags = Object.assign({}, entity.tags); // shallow copy\n\n for (var k in changed) {\n if (!k) continue;\n // No op for source=digitalglobe or source=maxar on ML roads. TODO: switch to check on __fbid__\n if (entity.__fbid__ && k === 'source' &&\n (entity.tags.source === 'digitalglobe' || entity.tags.source === 'maxar')) continue;\n var v = changed[k];\n if (v !== undefined || tags.hasOwnProperty(k)) {\n tags[k] = v;\n }\n }\n\n if (!onInput) {\n tags = utilCleanTags(tags);\n }\n\n if (!deepEqual(entity.tags, tags)) {\n actions.push(actionChangeTags(entityID, tags));\n }\n }\n\n if (actions.length) {\n var combinedAction = function(graph) {\n actions.forEach(function(action) {\n graph = action(graph);\n });\n return graph;\n };\n\n var annotation = t('operations.change_tags.annotation');\n\n if (_coalesceChanges) {\n context.overwrite(combinedAction, annotation);\n } else {\n context.perform(combinedAction, annotation);\n _coalesceChanges = !!onInput;\n }\n }\n\n // if leaving field (blur event), rerun validation\n if (!onInput) {\n context.validator().validate();\n }\n }\n\n function revertTags(keys) {\n\n var actions = [];\n for (var i in _entityIDs) {\n var entityID = _entityIDs[i];\n\n var original = context.graph().base().entities[entityID];\n var changed = {};\n for (var j in keys) {\n var key = keys[j];\n changed[key] = original ? original.tags[key] : undefined;\n }\n\n var entity = context.entity(entityID);\n var tags = Object.assign({}, entity.tags); // shallow copy\n\n for (var k in changed) {\n if (!k) continue;\n var v = changed[k];\n if (v !== undefined || tags.hasOwnProperty(k)) {\n tags[k] = v;\n }\n }\n\n\n tags = utilCleanTags(tags);\n\n if (!deepEqual(entity.tags, tags)) {\n actions.push(actionChangeTags(entityID, tags));\n }\n\n }\n\n if (actions.length) {\n var combinedAction = function(graph) {\n actions.forEach(function(action) {\n graph = action(graph);\n });\n return graph;\n };\n\n var annotation = t('operations.change_tags.annotation');\n\n if (_coalesceChanges) {\n context.overwrite(combinedAction, annotation);\n } else {\n context.perform(combinedAction, annotation);\n _coalesceChanges = false;\n }\n }\n\n context.validator().validate();\n }\n\n\n entityEditor.modified = function(val) {\n if (!arguments.length) return _modified;\n _modified = val;\n return entityEditor;\n };\n\n\n entityEditor.state = function(val) {\n if (!arguments.length) return _state;\n _state = val;\n return entityEditor;\n };\n\n\n entityEditor.entityIDs = function(val) {\n if (!arguments.length) return _entityIDs;\n if (val && _entityIDs && utilArrayIdentical(_entityIDs, val)) return entityEditor; // exit early if no change\n\n _entityIDs = val;\n _base = context.graph();\n _coalesceChanges = false;\n\n loadActivePresets(true);\n\n return entityEditor\n .modified(false);\n };\n\n\n entityEditor.newFeature = function(val) {\n if (!arguments.length) return _newFeature;\n _newFeature = val;\n return entityEditor;\n };\n\n\n function loadActivePresets(isForNewSelection) {\n\n var graph = context.graph();\n\n var counts = {};\n\n for (var i in _entityIDs) {\n var entity = graph.hasEntity(_entityIDs[i]);\n if (!entity) return;\n\n var match = presetManager.match(entity, graph);\n\n if (!counts[match.id]) counts[match.id] = 0;\n counts[match.id] += 1;\n }\n\n var matches = Object.keys(counts).sort(function(p1, p2) {\n return counts[p2] - counts[p1];\n }).map(function(pID) {\n return presetManager.item(pID);\n });\n\n if (!isForNewSelection) {\n // A \"weak\" preset doesn't set any tags. (e.g. \"Address\")\n var weakPreset = _activePresets.length === 1 &&\n !_activePresets[0].isFallback() &&\n Object.keys(_activePresets[0].addTags || {}).length === 0;\n // Don't replace a weak preset with a fallback preset (e.g. \"Point\")\n if (weakPreset && matches.length === 1 && matches[0].isFallback()) return;\n }\n\n entityEditor.presets(matches);\n }\n\n entityEditor.presets = function(val) {\n if (!arguments.length) return _activePresets;\n\n // don't reload the same preset\n if (!utilArrayIdentical(val, _activePresets)) {\n _activePresets = val;\n }\n return entityEditor;\n };\n\n return utilRebind(entityEditor, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport * as countryCoder from '@ideditor/country-coder';\n\nimport {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { presetManager } from '../presets';\nimport { t, localizer } from '../core/localizer';\nimport { actionChangePreset } from '../actions/change_preset';\nimport { operationDelete } from '../operations/delete';\nimport { svgIcon } from '../svg/index';\nimport { uiTooltip } from './tooltip';\nimport { geoExtent } from '../geo/extent';\nimport { uiPresetIcon } from './preset_icon';\nimport { uiTagReference } from './tag_reference';\nimport { utilKeybinding, utilNoAuto, utilRebind } from '../util';\n\n\nexport function uiPresetList(context) {\n var dispatch = d3_dispatch('cancel', 'choose');\n var _entityIDs;\n var _currentPresets;\n var _autofocus = false;\n\n\n function presetList(selection) {\n if (!_entityIDs) return;\n\n var presets = presetManager.matchAllGeometry(entityGeometries());\n\n selection.html('');\n\n var messagewrap = selection\n .append('div')\n .attr('class', 'header fillL');\n\n var message = messagewrap\n .append('h3')\n .text(t('inspector.choose'));\n\n messagewrap\n .append('button')\n .attr('class', 'preset-choose')\n .on('click', function() { dispatch.call('cancel', this); })\n .call(svgIcon((localizer.textDirection() === 'rtl') ? '#iD-icon-backward' : '#iD-icon-forward'));\n\n function initialKeydown() {\n // hack to let delete shortcut work when search is autofocused\n if (search.property('value').length === 0 &&\n (d3_event.keyCode === utilKeybinding.keyCodes['⌫'] ||\n d3_event.keyCode === utilKeybinding.keyCodes['⌦'])) {\n d3_event.preventDefault();\n d3_event.stopPropagation();\n operationDelete(context, _entityIDs)();\n\n // hack to let undo work when search is autofocused\n } else if (search.property('value').length === 0 &&\n (d3_event.ctrlKey || d3_event.metaKey) &&\n d3_event.keyCode === utilKeybinding.keyCodes.z) {\n d3_event.preventDefault();\n d3_event.stopPropagation();\n context.undo();\n } else if (!d3_event.ctrlKey && !d3_event.metaKey) {\n // don't check for delete/undo hack on future keydown events\n d3_select(this).on('keydown', keydown);\n keydown.call(this);\n }\n }\n\n function keydown() {\n // down arrow\n if (d3_event.keyCode === utilKeybinding.keyCodes['↓'] &&\n // if insertion point is at the end of the string\n search.node().selectionStart === search.property('value').length) {\n d3_event.preventDefault();\n d3_event.stopPropagation();\n // move focus to the first item in the preset list\n var buttons = list.selectAll('.preset-list-button');\n if (!buttons.empty()) buttons.nodes()[0].focus();\n }\n }\n\n function keypress() {\n // enter\n var value = search.property('value');\n if (d3_event.keyCode === 13 && value.length) {\n list.selectAll('.preset-list-item:first-child')\n .each(function(d) { d.choose.call(this); });\n }\n }\n\n function inputevent() {\n var value = search.property('value');\n list.classed('filtered', value.length);\n var extent = combinedEntityExtent();\n var results, messageText;\n if (value.length && extent) {\n var center = extent.center();\n var countryCode = countryCoder.iso1A2Code(center);\n\n results = presets.search(value, entityGeometries()[0], countryCode && countryCode.toLowerCase());\n messageText = t('inspector.results', {\n n: results.collection.length,\n search: value\n });\n } else {\n results = presetManager.defaults(entityGeometries()[0], 36, !context.inIntro());\n messageText = t('inspector.choose');\n }\n list.call(drawList, results);\n message.text(messageText);\n }\n\n var searchWrap = selection\n .append('div')\n .attr('class', 'search-header');\n\n var search = searchWrap\n .append('input')\n .attr('class', 'preset-search-input')\n .attr('placeholder', t('inspector.search'))\n .attr('type', 'search')\n .call(utilNoAuto)\n .on('keydown', initialKeydown)\n .on('keypress', keypress)\n .on('input', inputevent);\n\n searchWrap\n .call(svgIcon('#iD-icon-search', 'pre-text'));\n\n if (_autofocus) {\n search.node().focus();\n }\n\n var listWrap = selection\n .append('div')\n .attr('class', 'inspector-body');\n\n var list = listWrap\n .append('div')\n .attr('class', 'preset-list')\n .call(drawList, presetManager.defaults(entityGeometries()[0], 36, !context.inIntro()));\n\n context.features().on('change.preset-list', updateForFeatureHiddenState);\n }\n\n\n function drawList(list, presets) {\n presets = presets.matchAllGeometry(entityGeometries());\n var collection = presets.collection.reduce(function(collection, preset) {\n if (!preset) return collection;\n\n if (preset.members) {\n if (preset.members.collection.filter(function(preset) {\n return preset.addable();\n }).length > 1) {\n collection.push(CategoryItem(preset));\n }\n } else if (preset.addable()) {\n collection.push(PresetItem(preset));\n }\n return collection;\n }, []);\n\n var items = list.selectAll('.preset-list-item')\n .data(collection, function(d) { return d.preset.id; });\n\n items.order();\n\n items.exit()\n .remove();\n\n items.enter()\n .append('div')\n .attr('class', function(item) { return 'preset-list-item preset-' + item.preset.id.replace('/', '-'); })\n .classed('current', function(item) { return _currentPresets.indexOf(item.preset) !== -1; })\n .each(function(item) { d3_select(this).call(item); })\n .style('opacity', 0)\n .transition()\n .style('opacity', 1);\n\n updateForFeatureHiddenState();\n }\n\n function itemKeydown(){\n // the actively focused item\n var item = d3_select(this.closest('.preset-list-item'));\n var parentItem = d3_select(item.node().parentNode.closest('.preset-list-item'));\n\n // arrow down, move focus to the next, lower item\n if (d3_event.keyCode === utilKeybinding.keyCodes['↓']) {\n d3_event.preventDefault();\n d3_event.stopPropagation();\n // the next item in the list at the same level\n var nextItem = d3_select(item.node().nextElementSibling);\n // if there is no next item in this list\n if (nextItem.empty()) {\n // if there is a parent item\n if (!parentItem.empty()) {\n // the item is the last item of a sublist,\n // select the next item at the parent level\n nextItem = d3_select(parentItem.node().nextElementSibling);\n }\n // if the focused item is expanded\n } else if (d3_select(this).classed('expanded')) {\n // select the first subitem instead\n nextItem = item.select('.subgrid .preset-list-item:first-child');\n }\n if (!nextItem.empty()) {\n // focus on the next item\n nextItem.select('.preset-list-button').node().focus();\n }\n\n // arrow up, move focus to the previous, higher item\n } else if (d3_event.keyCode === utilKeybinding.keyCodes['↑']) {\n d3_event.preventDefault();\n d3_event.stopPropagation();\n // the previous item in the list at the same level\n var previousItem = d3_select(item.node().previousElementSibling);\n\n // if there is no previous item in this list\n if (previousItem.empty()) {\n // if there is a parent item\n if (!parentItem.empty()) {\n // the item is the first subitem of a sublist select the parent item\n previousItem = parentItem;\n }\n // if the previous item is expanded\n } else if (previousItem.select('.preset-list-button').classed('expanded')) {\n // select the last subitem of the sublist of the previous item\n previousItem = previousItem.select('.subgrid .preset-list-item:last-child');\n }\n\n if (!previousItem.empty()) {\n // focus on the previous item\n previousItem.select('.preset-list-button').node().focus();\n } else {\n // the focus is at the top of the list, move focus back to the search field\n var search = d3_select(this.closest('.preset-list-pane')).select('.preset-search-input');\n search.node().focus();\n }\n\n // arrow left, move focus to the parent item if there is one\n } else if (d3_event.keyCode === utilKeybinding.keyCodes[(localizer.textDirection() === 'rtl') ? '→' : '←']) {\n d3_event.preventDefault();\n d3_event.stopPropagation();\n // if there is a parent item, focus on the parent item\n if (!parentItem.empty()) {\n parentItem.select('.preset-list-button').node().focus();\n }\n\n // arrow right, choose this item\n } else if (d3_event.keyCode === utilKeybinding.keyCodes[(localizer.textDirection() === 'rtl') ? '←' : '→']) {\n d3_event.preventDefault();\n d3_event.stopPropagation();\n item.datum().choose.call(d3_select(this).node());\n }\n }\n\n\n function CategoryItem(preset) {\n var box, sublist, shown = false;\n\n function item(selection) {\n var wrap = selection.append('div')\n .attr('class', 'preset-list-button-wrap category');\n\n function click() {\n var isExpanded = d3_select(this).classed('expanded');\n var iconName = isExpanded ?\n (localizer.textDirection() === 'rtl' ? '#iD-icon-backward' : '#iD-icon-forward') : '#iD-icon-down';\n d3_select(this)\n .classed('expanded', !isExpanded);\n d3_select(this).selectAll('div.label-inner svg.icon use')\n .attr('href', iconName);\n item.choose();\n }\n\n var geometries = entityGeometries();\n\n var button = wrap\n .append('button')\n .attr('class', 'preset-list-button')\n .classed('expanded', false)\n .call(uiPresetIcon()\n .geometry(geometries.length === 1 && geometries[0])\n .preset(preset))\n .on('click', click)\n .on('keydown', function() {\n // right arrow, expand the focused item\n if (d3_event.keyCode === utilKeybinding.keyCodes[(localizer.textDirection() === 'rtl') ? '←' : '→']) {\n d3_event.preventDefault();\n d3_event.stopPropagation();\n // if the item isn't expanded\n if (!d3_select(this).classed('expanded')) {\n // toggle expansion (expand the item)\n click.call(this);\n }\n // left arrow, collapse the focused item\n } else if (d3_event.keyCode === utilKeybinding.keyCodes[(localizer.textDirection() === 'rtl') ? '→' : '←']) {\n d3_event.preventDefault();\n d3_event.stopPropagation();\n // if the item is expanded\n if (d3_select(this).classed('expanded')) {\n // toggle expansion (collapse the item)\n click.call(this);\n }\n } else {\n itemKeydown.call(this);\n }\n });\n\n var label = button\n .append('div')\n .attr('class', 'label')\n .append('div')\n .attr('class', 'label-inner');\n\n label\n .append('div')\n .attr('class', 'namepart')\n .call(svgIcon((localizer.textDirection() === 'rtl' ? '#iD-icon-backward' : '#iD-icon-forward'), 'inline'))\n .append('span')\n .html(function() { return preset.name() + '…'; });\n\n box = selection.append('div')\n .attr('class', 'subgrid')\n .style('max-height', '0px')\n .style('opacity', 0);\n\n box.append('div')\n .attr('class', 'arrow');\n\n sublist = box.append('div')\n .attr('class', 'preset-list fillL3');\n }\n\n\n item.choose = function() {\n if (!box || !sublist) return;\n\n if (shown) {\n shown = false;\n box.transition()\n .duration(200)\n .style('opacity', '0')\n .style('max-height', '0px')\n .style('padding-bottom', '0px');\n } else {\n shown = true;\n var members = preset.members.matchAllGeometry(entityGeometries());\n sublist.call(drawList, members);\n box.transition()\n .duration(200)\n .style('opacity', '1')\n .style('max-height', 200 + members.collection.length * 190 + 'px')\n .style('padding-bottom', '10px');\n }\n };\n\n item.preset = preset;\n return item;\n }\n\n\n function PresetItem(preset) {\n function item(selection) {\n var wrap = selection.append('div')\n .attr('class', 'preset-list-button-wrap');\n\n var geometries = entityGeometries();\n\n var button = wrap.append('button')\n .attr('class', 'preset-list-button')\n .call(uiPresetIcon()\n .geometry(geometries.length === 1 && geometries[0])\n .preset(preset))\n .on('click', item.choose)\n .on('keydown', itemKeydown);\n\n var label = button\n .append('div')\n .attr('class', 'label')\n .append('div')\n .attr('class', 'label-inner');\n\n // NOTE: split/join on en-dash, not a hypen (to avoid conflict with fr - nl names in Brussels etc)\n label.selectAll('.namepart')\n .data(preset.name().split(' – '))\n .enter()\n .append('div')\n .attr('class', 'namepart')\n .text(function(d) { return d; });\n\n wrap.call(item.reference.button);\n selection.call(item.reference.body);\n }\n\n item.choose = function() {\n if (d3_select(this).classed('disabled')) return;\n if (!context.inIntro()) {\n presetManager.setMostRecent(preset, entityGeometries()[0]);\n }\n context.perform(\n function(graph) {\n for (var i in _entityIDs) {\n var entityID = _entityIDs[i];\n var oldPreset = presetManager.match(graph.entity(entityID), graph);\n graph = actionChangePreset(entityID, oldPreset, preset)(graph);\n }\n return graph;\n },\n t('operations.change_tags.annotation')\n );\n\n context.validator().validate(); // rerun validation\n dispatch.call('choose', this, preset);\n };\n\n item.help = function() {\n d3_event.stopPropagation();\n item.reference.toggle();\n };\n\n item.preset = preset;\n item.reference = uiTagReference(preset.reference(entityGeometries()[0]), context);\n\n return item;\n }\n\n\n function updateForFeatureHiddenState() {\n if (!_entityIDs.every(context.hasEntity)) return;\n\n var geometries = entityGeometries();\n var button = context.container().selectAll('.preset-list .preset-list-button');\n\n // remove existing tooltips\n button.call(uiTooltip().destroyAny);\n\n button.each(function(item, index) {\n var hiddenPresetFeaturesId;\n for (var i in geometries) {\n hiddenPresetFeaturesId = context.features().isHiddenPreset(item.preset, geometries[i]);\n if (hiddenPresetFeaturesId) break;\n }\n var isHiddenPreset = !context.inIntro() &&\n !!hiddenPresetFeaturesId &&\n (_currentPresets.length !== 1 || item.preset !== _currentPresets[0]);\n\n d3_select(this)\n .classed('disabled', isHiddenPreset);\n\n if (isHiddenPreset) {\n var isAutoHidden = context.features().autoHidden(hiddenPresetFeaturesId);\n var tooltipIdSuffix = isAutoHidden ? 'zoom' : 'manual';\n var tooltipObj = { features: t('feature.' + hiddenPresetFeaturesId + '.description') };\n d3_select(this).call(uiTooltip()\n .title(t('inspector.hidden_preset.' + tooltipIdSuffix, tooltipObj))\n .placement(index < 2 ? 'bottom' : 'top')\n );\n }\n });\n }\n\n presetList.autofocus = function(val) {\n if (!arguments.length) return _autofocus;\n _autofocus = val;\n return presetList;\n };\n\n presetList.entityIDs = function(val) {\n if (!arguments.length) return _entityIDs;\n _entityIDs = val;\n if (_entityIDs && _entityIDs.length) {\n var presets = _entityIDs.map(function(entityID) {\n return presetManager.match(context.entity(entityID), context.graph());\n });\n presetList.presets(presets);\n }\n return presetList;\n };\n\n presetList.presets = function(val) {\n if (!arguments.length) return _currentPresets;\n _currentPresets = val;\n return presetList;\n };\n\n function entityGeometries() {\n\n var counts = {};\n\n for (var i in _entityIDs) {\n var entityID = _entityIDs[i];\n var entity = context.entity(entityID);\n var geometry = entity.geometry(context.graph());\n\n // Treat entities on addr:interpolation lines as points, not vertices (#3241)\n if (geometry === 'vertex' && entity.isOnAddressLine(context.graph())) {\n geometry = 'point';\n }\n\n if (!counts[geometry]) counts[geometry] = 0;\n counts[geometry] += 1;\n }\n\n return Object.keys(counts).sort(function(geom1, geom2) {\n return counts[geom2] - counts[geom1];\n });\n }\n\n function combinedEntityExtent() {\n return _entityIDs.reduce(function(extent, entityID) {\n var entity = context.graph().entity(entityID);\n return extent.extend(entity.extent(context.graph()));\n }, geoExtent());\n }\n\n return utilRebind(presetList, dispatch, 'on');\n}\n","import { interpolate as d3_interpolate } from 'd3-interpolate';\nimport { select as d3_select } from 'd3-selection';\n\nimport { uiEntityEditor } from './entity_editor';\nimport { uiPresetList } from './preset_list';\nimport { uiViewOnOSM } from './view_on_osm';\n\n\nexport function uiInspector(context) {\n var presetList = uiPresetList(context);\n var entityEditor = uiEntityEditor(context);\n var wrap = d3_select(null),\n presetPane = d3_select(null),\n editorPane = d3_select(null);\n var _state = 'select';\n var _entityIDs;\n var _newFeature = false;\n\n\n function inspector(selection) {\n presetList\n .entityIDs(_entityIDs)\n .autofocus(_newFeature)\n .on('choose', inspector.setPreset)\n .on('cancel', function() {\n wrap.transition()\n .styleTween('right', function() { return d3_interpolate('-100%', '0%'); });\n editorPane.call(entityEditor);\n });\n\n entityEditor\n .state(_state)\n .entityIDs(_entityIDs)\n .on('choose', inspector.showList);\n\n wrap = selection.selectAll('.panewrap')\n .data([0]);\n\n var enter = wrap.enter()\n .append('div')\n .attr('class', 'panewrap');\n\n enter\n .append('div')\n .attr('class', 'preset-list-pane pane');\n\n enter\n .append('div')\n .attr('class', 'entity-editor-pane pane');\n\n wrap = wrap.merge(enter);\n presetPane = wrap.selectAll('.preset-list-pane');\n editorPane = wrap.selectAll('.entity-editor-pane');\n\n function shouldDefaultToPresetList() {\n // always show the inspector on hover\n if (_state !== 'select') return false;\n\n // can only change preset on single selection\n if (_entityIDs.length !== 1) return false;\n\n var entityID = _entityIDs[0];\n var entity = context.hasEntity(entityID);\n if (!entity) return false;\n\n // default to inspector if there are already tags\n if (entity.hasNonGeometryTags()) return false;\n\n // prompt to select preset if feature is new and untagged\n if (_newFeature) return true;\n\n // all existing features except vertices should default to inspector\n if (entity.geometry(context.graph()) !== 'vertex') return false;\n\n // show vertex relations if any\n if (context.graph().parentRelations(entity).length) return false;\n\n // show vertex issues if there are any\n if (context.validator().getEntityIssues(entityID).length) return false;\n\n // show turn retriction editor for junction vertices\n if (entity.isHighwayIntersection(context.graph())) return false;\n\n // otherwise show preset list for uninteresting vertices\n return true;\n }\n\n if (shouldDefaultToPresetList()) {\n wrap.style('right', '-100%');\n presetPane.call(presetList);\n } else {\n wrap.style('right', '0%');\n editorPane.call(entityEditor);\n }\n\n var footer = selection.selectAll('.footer')\n .data([0]);\n\n footer = footer.enter()\n .append('div')\n .attr('class', 'footer')\n .merge(footer);\n\n footer\n .call(uiViewOnOSM(context)\n .what(context.hasEntity(_entityIDs.length === 1 && _entityIDs[0]))\n );\n }\n\n inspector.showList = function(presets) {\n\n wrap.transition()\n .styleTween('right', function() { return d3_interpolate('0%', '-100%'); });\n\n if (presets) {\n presetList.presets(presets);\n }\n\n presetPane\n .call(presetList.autofocus(true));\n };\n\n inspector.setPreset = function(preset) {\n\n // upon setting multipolygon, go to the area preset list instead of the editor\n if (preset.id === 'type/multipolygon') {\n presetPane\n .call(presetList.autofocus(true));\n\n } else {\n wrap.transition()\n .styleTween('right', function() { return d3_interpolate('-100%', '0%'); });\n\n editorPane\n .call(entityEditor.presets([preset]));\n }\n\n };\n\n inspector.state = function(val) {\n if (!arguments.length) return _state;\n _state = val;\n entityEditor.state(_state);\n\n // remove any old field help overlay that might have gotten attached to the inspector\n context.container().selectAll('.field-help-body').remove();\n\n return inspector;\n };\n\n\n inspector.entityIDs = function(val) {\n if (!arguments.length) return _entityIDs;\n _entityIDs = val;\n return inspector;\n };\n\n\n inspector.newFeature = function(val) {\n if (!arguments.length) return _newFeature;\n _newFeature = val;\n return inspector;\n };\n\n\n return inspector;\n}\n","import { select as d3_select } from 'd3-selection';\nimport { t } from '../core/localizer';\nimport { uiIntro } from './intro';\nimport { icon } from './intro/helper';\nimport { uiModal } from './modal';\nimport { prefs } from '../core/preferences';\n\n\nexport function uiRapidSplash(context) {\n\n return function(selection) {\n if (prefs('sawRapidSplash')) return;\n prefs('sawRapidSplash', true);\n\n const modalSelection = uiModal(selection);\n\n modalSelection.select('.modal')\n .attr('class', 'modal rapid-modal modal-splash'); // RapiD styling\n\n let introModal = modalSelection.select('.content');\n\n introModal\n .append('div')\n .attr('class','modal-section')\n .append('h3').text(t('rapid_splash.welcome'));\n\n introModal\n .append('div')\n .attr('class','modal-section')\n .append('p')\n .html(t('rapid_splash.text', {\n rapidicon: icon('#iD-logo-rapid', 'logo-rapid'),\n walkthrough: icon('#iD-logo-walkthrough', 'logo-walkthrough'),\n edit: icon('#iD-logo-features', 'logo-features')\n }));\n\n let buttonWrap = introModal\n .append('div')\n .attr('class', 'modal-actions');\n\n let walkthrough = buttonWrap\n .append('button')\n .attr('class', 'walkthrough')\n .on('click', (d, i, nodes) => {\n d3_select(nodes[i]).node().blur();\n context.container().call(uiIntro(context, false));\n modalSelection.close();\n });\n\n walkthrough\n .append('svg')\n .attr('class', 'logo logo-features')\n .append('use')\n .attr('xlink:href', '#iD-logo-walkthrough');\n\n walkthrough\n .append('div')\n .text(t('rapid_splash.walkthrough'));\n\n let rapidWalkthrough = buttonWrap\n .append('button')\n .attr('class', 'rapid-walkthrough')\n .on('click', (d, i, nodes) => {\n d3_select(nodes[i]).node().blur();\n context.container().call(uiIntro(context, true));\n modalSelection.close();\n });\n\n rapidWalkthrough\n .append('svg')\n .attr('class', 'logo logo-rapid')\n .append('use')\n .attr('xlink:href', '#iD-logo-rapid');\n\n rapidWalkthrough\n .append('div')\n .text(t('rapid_splash.skip_to_rapid'));\n\n let startEditing = buttonWrap\n .append('button')\n .attr('class', 'start-editing')\n .on('click', (d, i, nodes) => {\n d3_select(nodes[i]).node().blur();\n modalSelection.close();\n });\n\n startEditing\n .append('svg')\n .attr('class', 'logo logo-features')\n .append('use')\n .attr('xlink:href', '#iD-logo-features');\n\n startEditing\n .append('div')\n .text(t('rapid_splash.start'));\n\n modalSelection.select('button.close')\n .attr('class', 'hide');\n };\n}\n","import { select as d3_select } from 'd3-selection';\nimport { t } from '../core/localizer';\nimport { icon } from './intro/helper';\nimport { uiModal } from './modal';\nimport { uiRapidSplash } from './rapid_splash';\n\n\nexport function uiRapidFirstEditDialog(context) {\n\n return function(selection) {\n let modalSelection = uiModal(selection);\n\n modalSelection.select('.modal')\n .attr('class', 'modal rapid-modal'); // RapiD styling\n\n let firstEditModal = modalSelection.select('.content');\n\n firstEditModal\n .append('div')\n .attr('class', 'modal-section')\n .append('h3')\n .html(t('rapid_first_edit.nice', { rapidicon: icon('#iD-logo-rapid', 'logo-rapid') }));\n\n firstEditModal\n .append('div')\n .attr('class', 'modal-section')\n .append('p')\n .text(t('rapid_first_edit.text'));\n\n let buttonWrap = firstEditModal\n .append('div')\n .attr('class', 'modal-actions');\n\n let exploring = buttonWrap\n .append('button')\n .attr('class', 'rapid-explore')\n .on('click', (d, i, nodes) => {\n d3_select(nodes[i]).node().blur();\n modalSelection.close();\n });\n\n exploring\n .append('div')\n .text(t('rapid_first_edit.exploring'));\n\n let loginToOsm = buttonWrap\n .append('button')\n .attr('class', 'rapid-login-to-osm')\n .on('click', (d, i, nodes) => {\n d3_select(nodes[i]).node().blur();\n modalSelection.close();\n const osm = context.connection();\n if (!osm) return;\n osm.authenticate(() => context.container().call(uiRapidSplash(context)) );\n });\n\n loginToOsm\n .append('div')\n .text(t('rapid_first_edit.login_with_osm'));\n\n modalSelection.select('button.close')\n .attr('class', 'hide');\n };\n}\n","import { select as d3_select } from 'd3-selection';\nimport { t } from '../core/localizer';\n\nimport { actionNoop, actionRapidAcceptFeature } from '../actions';\nimport { modeBrowse, modeSelect } from '../modes';\nimport { services } from '../services';\nimport { svgIcon } from '../svg';\nimport { uiFlash } from './flash';\nimport { uiTooltip } from './tooltip';\nimport { utilStringQs } from '../util';\nimport { uiRapidFirstEditDialog } from './rapid_first_edit_dialog';\n\n\nexport function uiRapidFeatureInspector(context, keybinding) {\n const rapidContext = context.rapidContext();\n const showPowerUser = rapidContext.showPowerUser;\n const ACCEPT_FEATURES_LIMIT = showPowerUser ? Infinity : 50;\n let _datum;\n\n\n function isAddFeatureDisabled() {\n // when task GPX is set in URL (TM mode), \"add roads\" is always enabled\n const gpxInUrl = utilStringQs(window.location.hash).gpx;\n if (gpxInUrl) return false;\n\n const annotations = context.history().peekAllAnnotations();\n const aiFeatureAccepts = annotations.filter(a => a.type === 'rapid_accept_feature');\n return aiFeatureAccepts.length >= ACCEPT_FEATURES_LIMIT;\n }\n\n\n function onAcceptFeature() {\n if (!_datum) return;\n\n if (isAddFeatureDisabled()) {\n const flash = uiFlash(context)\n .duration(5000)\n .text(t(\n 'rapid_feature_inspector.option_accept.disabled_flash',\n { n: ACCEPT_FEATURES_LIMIT }\n ));\n flash();\n return;\n }\n\n // In place of a string annotation, this introduces an \"object-style\"\n // annotation, where \"type\" and \"description\" are standard keys,\n // and there may be additional properties. Note that this will be\n // serialized to JSON while saving undo/redo state in history.save().\n const annotation = {\n type: 'rapid_accept_feature',\n description: t('rapid_feature_inspector.option_accept.annotation'),\n id: _datum.id,\n origid: _datum.__origid__,\n };\n\n const service = _datum.__service__ === 'esri' ? services.esriData : services.fbMLRoads;\n const graph = service.graph(_datum.__datasetid__);\n context.perform(actionRapidAcceptFeature(_datum.id, graph), annotation);\n context.enter(modeSelect(context, [_datum.id]));\n\n if (context.inIntro()) return;\n\n // remember sources for later when we prepare the changeset\n const source = _datum.tags && _datum.tags.source;\n if (source) {\n rapidContext.sources.add(source);\n }\n\n if (window.sessionStorage.getItem('acknowledgedLogin') === 'true') return;\n window.sessionStorage.setItem('acknowledgedLogin', 'true');\n\n const osm = context.connection();\n if (!osm.authenticated()) {\n context.container()\n .call(uiRapidFirstEditDialog(context));\n }\n }\n\n\n function onIgnoreFeature() {\n if (!_datum) return;\n\n const annotation = {\n type: 'rapid_ignore_feature',\n description: t('rapid_feature_inspector.option_ignore.annotation'),\n id: _datum.id,\n origid: _datum.__origid__\n };\n context.perform(actionNoop(), annotation);\n context.enter(modeBrowse(context));\n }\n\n\n // https://www.w3.org/TR/AERT#color-contrast\n // https://trendct.org/2016/01/22/how-to-choose-a-label-color-to-contrast-with-background/\n // pass color as a hexstring like '#rgb', '#rgba', '#rrggbb', '#rrggbbaa' (alpha values are ignored)\n function getBrightness(color) {\n const short = (color.length < 6);\n const r = parseInt(short ? color[1] + color[1] : color[1] + color[2], 16);\n const g = parseInt(short ? color[2] + color[2] : color[3] + color[4], 16);\n const b = parseInt(short ? color[3] + color[3] : color[5] + color[6], 16);\n return ((r * 299) + (g * 587) + (b * 114)) / 1000;\n }\n\n\n function featureInfo(selection) {\n if (!_datum) return;\n\n const datasetID = _datum.__datasetid__.replace('-conflated', '');\n const dataset = rapidContext.datasets()[datasetID];\n const color = dataset.color;\n\n let featureInfo = selection.selectAll('.feature-info')\n .data([color]);\n\n // enter\n let featureInfoEnter = featureInfo\n .enter()\n .append('div')\n .attr('class', 'feature-info');\n\n featureInfoEnter\n .append('div')\n .attr('class', 'dataset-label')\n .text(dataset.label || dataset.id); // fallback to dataset ID\n\n if (dataset.beta) {\n featureInfoEnter\n .append('div')\n .attr('class', 'dataset-beta beta')\n .attr('title', t('rapid_poweruser_features.beta'));\n }\n\n // update\n featureInfo = featureInfo\n .merge(featureInfoEnter)\n .style('background', d => d)\n .style('color', d => getBrightness(d) > 140.5 ? '#333' : '#fff');\n }\n\n\n function tagInfo(selection) {\n const tags = _datum && _datum.tags;\n if (!tags) return;\n\n let tagInfoEnter = selection.selectAll('.tag-info')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'tag-info');\n\n let tagBagEnter = tagInfoEnter\n .append('div')\n .attr('class', 'tag-bag');\n\n tagBagEnter\n .append('div')\n .attr('class', 'tag-heading')\n .text(t('rapid_feature_inspector.tags'));\n\n const tagEntries = Object.keys(tags).map(k => ({ key: k, value: tags[k] }) );\n\n tagEntries.forEach(e => {\n let entryDiv = tagBagEnter.append('div')\n .attr('class', 'tag-entry');\n\n entryDiv.append('div').attr('class', 'tag-key').text(e.key);\n entryDiv.append('div').attr('class', 'tag-value').text(e.value);\n });\n }\n\n\n function rapidInspector(selection) {\n let inspector = selection.selectAll('.rapid-inspector')\n .data([0]);\n\n let inspectorEnter = inspector\n .enter()\n .append('div')\n .attr('class', 'rapid-inspector');\n\n inspector = inspector\n .merge(inspectorEnter);\n\n\n // Header\n let headerEnter = inspector.selectAll('.header')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'header');\n\n headerEnter\n .append('h3')\n .append('svg')\n .attr('class', 'logo-rapid dark')\n .append('use')\n .attr('xlink:href', '#iD-logo-rapid');\n\n headerEnter\n .append('button')\n .attr('class', 'fr rapid-inspector-close')\n .on('click', (d, i, nodes) => {\n d3_select(nodes[i]).node().blur();\n context.enter(modeBrowse(context));\n })\n .call(svgIcon('#iD-icon-close'));\n\n\n // Body\n let body = inspector.selectAll('.body')\n .data([0]);\n\n let bodyEnter = body\n .enter()\n .append('div')\n .attr('class', 'body');\n\n body = body\n .merge(bodyEnter)\n .call(featureInfo)\n .call(tagInfo);\n\n\n // Choices\n const choiceData = [\n {\n key: 'accept',\n iconName: '#iD-icon-rapid-plus-circle',\n label: t('rapid_feature_inspector.option_accept.label'),\n description: t('rapid_feature_inspector.option_accept.description'),\n onClick: onAcceptFeature\n }, {\n key: 'ignore',\n iconName: '#iD-icon-rapid-minus-circle',\n label: t('rapid_feature_inspector.option_ignore.label'),\n description: t('rapid_feature_inspector.option_ignore.description'),\n onClick: onIgnoreFeature\n }\n ];\n\n let choices = body.selectAll('.rapid-inspector-choices')\n .data([0]);\n\n let choicesEnter = choices\n .enter()\n .append('div')\n .attr('class', 'rapid-inspector-choices');\n\n choicesEnter\n .append('p')\n .text(t('rapid_feature_inspector.prompt'));\n\n choicesEnter.selectAll('.rapid-inspector-choice')\n .data(choiceData, d => d.key)\n .enter()\n .append('div')\n .attr('class', d => `rapid-inspector-choice rapid-inspector-choice-${d.key}`)\n .each(showChoice);\n }\n\n\n function showChoice(d, i, nodes) {\n let selection = d3_select(nodes[i]);\n const disableClass = (d.key === 'accept' && isAddFeatureDisabled()) ? 'secondary disabled': '';\n\n let choiceWrap = selection\n .append('div')\n .attr('class', `choice-wrap choice-wrap-${d.key}`);\n\n let choiceReference = selection\n .append('div')\n .attr('class', 'tag-reference-body');\n\n choiceReference\n .text(d.description);\n\n const onClick = d.onClick;\n let choiceButton = choiceWrap\n .append('button')\n .attr('class', `choice-button choice-button-${d.key} ${disableClass}`)\n .on('click', (d, i, nodes) => {\n d3_select(nodes[i]).node().blur();\n onClick();\n });\n\n // build tooltips\n let title, keys;\n if (d.key === 'accept') {\n if (isAddFeatureDisabled()) {\n title = t('rapid_feature_inspector.option_accept.disabled', { n: ACCEPT_FEATURES_LIMIT } );\n keys = [];\n } else {\n title = t('rapid_feature_inspector.option_accept.tooltip');\n keys = [t('rapid_feature_inspector.option_accept.key')];\n }\n } else if (d.key === 'ignore') {\n title = t('rapid_feature_inspector.option_ignore.tooltip');\n keys = [t('rapid_feature_inspector.option_ignore.key')];\n }\n\n if (title && keys) {\n choiceButton = choiceButton\n .call(uiTooltip().placement('bottom').title(title).keys(keys));\n }\n\n choiceButton\n .append('svg')\n .attr('class', 'choice-icon icon')\n .append('use')\n .attr('xlink:href', d.iconName);\n\n choiceButton\n .append('div')\n .attr('class', 'choice-label')\n .text(d.label);\n\n choiceWrap\n .append('button')\n .attr('class', `tag-reference-button ${disableClass}`)\n .attr('title', 'info')\n .attr('tabindex', '-1')\n .on('click', (d, i, nodes) => {\n d3_select(nodes[i]).node().blur();\n choiceReference.classed('expanded', !choiceReference.classed('expanded'));\n })\n .call(svgIcon('#iD-icon-inspect'));\n }\n\n\n rapidInspector.datum = function(val) {\n if (!arguments.length) return _datum;\n _datum = val;\n return this;\n };\n\n if (keybinding) {\n keybinding()\n .on(t('rapid_feature_inspector.option_accept.key'), onAcceptFeature)\n .on(t('rapid_feature_inspector.option_ignore.key'), onIgnoreFeature);\n }\n\n return rapidInspector;\n}\n","import _throttle from 'lodash-es/throttle';\n\nimport { interpolateNumber as d3_interpolateNumber } from 'd3-interpolate';\nimport {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { utilArrayIdentical } from '../util/array';\nimport { utilFastMouse } from '../util';\nimport { osmEntity, osmNote, QAItem } from '../osm';\nimport { services } from '../services';\nimport { uiDataEditor } from './data_editor';\nimport { uiFeatureList } from './feature_list';\nimport { uiInspector } from './inspector';\nimport { uiImproveOsmEditor } from './improveOSM_editor';\nimport { uiKeepRightEditor } from './keepRight_editor';\nimport { uiOsmoseEditor } from './osmose_editor';\nimport { uiNoteEditor } from './note_editor';\nimport { localizer } from '../core/localizer';\n\nimport { uiRapidFeatureInspector } from './rapid_feature_inspector';\n\n\nexport function uiSidebar(context) {\n var inspector = uiInspector(context);\n var rapidInspector = uiRapidFeatureInspector(context);\n var dataEditor = uiDataEditor(context);\n var noteEditor = uiNoteEditor(context);\n var improveOsmEditor = uiImproveOsmEditor(context);\n var keepRightEditor = uiKeepRightEditor(context);\n var osmoseEditor = uiOsmoseEditor(context);\n var _current;\n var _wasRapiD = false;\n var _wasData = false;\n var _wasNote = false;\n var _wasQaItem = false;\n\n // use pointer events on supported platforms; fallback to mouse events\n var _pointerPrefix = 'PointerEvent' in window ? 'pointer' : 'mouse';\n\n\n function sidebar(selection) {\n var container = context.container();\n var minWidth = 240;\n var sidebarWidth;\n var containerWidth;\n var dragOffset;\n\n // Set the initial width constraints\n selection\n .style('min-width', minWidth + 'px')\n .style('max-width', '400px')\n .style('width', '33.3333%');\n\n var resizer = selection\n .append('div')\n .attr('class', 'sidebar-resizer')\n .on(_pointerPrefix + 'down.sidebar-resizer', pointerdown);\n\n var downPointerId, lastClientX, containerLocGetter;\n\n function pointerdown() {\n if (downPointerId) return;\n\n if ('button' in d3_event && d3_event.button !== 0) return;\n\n downPointerId = d3_event.pointerId || 'mouse';\n\n lastClientX = d3_event.clientX;\n\n containerLocGetter = utilFastMouse(container.node());\n\n // offset from edge of sidebar-resizer\n dragOffset = utilFastMouse(resizer.node())(d3_event)[0] - 1;\n\n sidebarWidth = selection.node().getBoundingClientRect().width;\n containerWidth = container.node().getBoundingClientRect().width;\n var widthPct = (sidebarWidth / containerWidth) * 100;\n selection\n .style('width', widthPct + '%') // lock in current width\n .style('max-width', '85%'); // but allow larger widths\n\n resizer.classed('dragging', true);\n\n d3_select(window)\n .on('touchmove.sidebar-resizer', function() {\n // disable page scrolling while resizing on touch input\n d3_event.preventDefault();\n }, { passive: false })\n .on(_pointerPrefix + 'move.sidebar-resizer', pointermove)\n .on(_pointerPrefix + 'up.sidebar-resizer pointercancel.sidebar-resizer', pointerup);\n }\n\n function pointermove() {\n\n if (downPointerId !== (d3_event.pointerId || 'mouse')) return;\n\n d3_event.preventDefault();\n\n var dx = d3_event.clientX - lastClientX;\n\n lastClientX = d3_event.clientX;\n\n var isRTL = (localizer.textDirection() === 'rtl');\n var scaleX = isRTL ? 0 : 1;\n var xMarginProperty = isRTL ? 'margin-right' : 'margin-left';\n\n var x = containerLocGetter(d3_event)[0] - dragOffset;\n sidebarWidth = isRTL ? containerWidth - x : x;\n\n var isCollapsed = selection.classed('collapsed');\n var shouldCollapse = sidebarWidth < minWidth;\n\n selection.classed('collapsed', shouldCollapse);\n\n if (shouldCollapse) {\n if (!isCollapsed) {\n selection\n .style(xMarginProperty, '-400px')\n .style('width', '400px');\n\n context.ui().onResize([(sidebarWidth - dx) * scaleX, 0]);\n }\n\n } else {\n var widthPct = (sidebarWidth / containerWidth) * 100;\n selection\n .style(xMarginProperty, null)\n .style('width', widthPct + '%');\n\n if (isCollapsed) {\n context.ui().onResize([-sidebarWidth * scaleX, 0]);\n } else {\n context.ui().onResize([-dx * scaleX, 0]);\n }\n }\n }\n\n function pointerup() {\n if (downPointerId !== (d3_event.pointerId || 'mouse')) return;\n\n downPointerId = null;\n\n resizer.classed('dragging', false);\n\n d3_select(window)\n .on('touchmove.sidebar-resizer', null)\n .on(_pointerPrefix + 'move.sidebar-resizer', null)\n .on(_pointerPrefix + 'up.sidebar-resizer pointercancel.sidebar-resizer', null);\n }\n\n var featureListWrap = selection\n .append('div')\n .attr('class', 'feature-list-pane')\n .call(uiFeatureList(context));\n\n var inspectorWrap = selection\n .append('div')\n .attr('class', 'inspector-hidden inspector-wrap');\n\n var hoverModeSelect = function(targets) {\n context.container().selectAll('.feature-list-item').classed('hover', false);\n\n if (context.selectedIDs().length > 1 &&\n targets && targets.length) {\n\n var elements = context.container().selectAll('.feature-list-item')\n .filter(function (node) {\n return targets.indexOf(node) !== -1;\n });\n\n if (!elements.empty()) {\n elements.classed('hover', true);\n }\n }\n };\n\n sidebar.hoverModeSelect = _throttle(hoverModeSelect, 200);\n\n function hover(targets) {\n var datum = targets && targets.length && targets[0];\n if (datum && datum.__featurehash__) { // hovering on data\n _wasData = true;\n sidebar\n .show(dataEditor.datum(datum));\n\n selection.selectAll('.sidebar-component')\n .classed('inspector-hover', true);\n\n } else if (datum && datum.__fbid__) { // hovering on RapiD data\n _wasRapiD = true;\n sidebar\n .show(rapidInspector.datum(datum));\n\n selection.selectAll('.sidebar-component')\n .classed('inspector-hover', true);\n\n } else if (datum instanceof osmNote) {\n if (context.mode().id === 'drag-note') return;\n _wasNote = true;\n\n var osm = services.osm;\n if (osm) {\n datum = osm.getNote(datum.id); // marker may contain stale data - get latest\n }\n\n sidebar\n .show(noteEditor.note(datum));\n\n selection.selectAll('.sidebar-component')\n .classed('inspector-hover', true);\n\n } else if (datum instanceof QAItem) {\n _wasQaItem = true;\n\n var errService = services[datum.service];\n if (errService) {\n // marker may contain stale data - get latest\n datum = errService.getError(datum.id);\n }\n\n // Currently only three possible services\n var errEditor;\n if (datum.service === 'keepRight') {\n errEditor = keepRightEditor;\n } else if (datum.service === 'osmose') {\n errEditor = osmoseEditor;\n } else {\n errEditor = improveOsmEditor;\n }\n\n context.container().selectAll('.qaItem.' + datum.service)\n .classed('hover', function(d) { return d.id === datum.id; });\n\n sidebar\n .show(errEditor.error(datum));\n\n selection.selectAll('.sidebar-component')\n .classed('inspector-hover', true);\n\n } else if (!_current && (datum instanceof osmEntity)) {\n featureListWrap\n .classed('inspector-hidden', true);\n\n inspectorWrap\n .classed('inspector-hidden', false)\n .classed('inspector-hover', true);\n\n if (!inspector.entityIDs() || !utilArrayIdentical(inspector.entityIDs(), [datum.id]) || inspector.state() !== 'hover') {\n inspector\n .state('hover')\n .entityIDs([datum.id])\n .newFeature(false);\n\n inspectorWrap\n .call(inspector);\n }\n\n } else if (!_current) {\n featureListWrap\n .classed('inspector-hidden', false);\n inspectorWrap\n .classed('inspector-hidden', true);\n inspector\n .state('hide');\n\n } else if (_wasRapiD || _wasData || _wasNote || _wasQaItem) {\n _wasRapiD = false;\n _wasNote = false;\n _wasData = false;\n _wasQaItem = false;\n context.container().selectAll('.layer-ai-features .hover').classed('hover', false);\n context.container().selectAll('.note').classed('hover', false);\n context.container().selectAll('.qaItem').classed('hover', false);\n sidebar.hide();\n }\n }\n\n sidebar.hover = _throttle(hover, 200);\n\n\n sidebar.intersects = function(extent) {\n var rect = selection.node().getBoundingClientRect();\n return extent.intersects([\n context.projection.invert([0, rect.height]),\n context.projection.invert([rect.width, 0])\n ]);\n };\n\n\n sidebar.select = function(ids, newFeature) {\n sidebar.hide();\n\n if (ids && ids.length) {\n\n var entity = ids.length === 1 && context.entity(ids[0]);\n if (entity && newFeature && selection.classed('collapsed')) {\n // uncollapse the sidebar\n var extent = entity.extent(context.graph());\n sidebar.expand(sidebar.intersects(extent));\n }\n\n featureListWrap\n .classed('inspector-hidden', true);\n\n inspectorWrap\n .classed('inspector-hidden', false)\n .classed('inspector-hover', false);\n\n if (!inspector.entityIDs() || !utilArrayIdentical(inspector.entityIDs(), ids) || inspector.state() !== 'select') {\n inspector\n .state('select')\n .entityIDs(ids)\n .newFeature(newFeature);\n\n inspectorWrap\n .call(inspector);\n }\n\n } else {\n inspector\n .state('hide');\n }\n };\n\n\n sidebar.showPresetList = function() {\n inspector.showList();\n };\n\n\n sidebar.show = function(component, element) {\n featureListWrap\n .classed('inspector-hidden', true);\n inspectorWrap\n .classed('inspector-hidden', true);\n\n if (_current) _current.remove();\n _current = selection\n .append('div')\n .attr('class', 'sidebar-component')\n .call(component, element);\n };\n\n\n sidebar.hide = function() {\n featureListWrap\n .classed('inspector-hidden', false);\n inspectorWrap\n .classed('inspector-hidden', true);\n\n if (_current) _current.remove();\n _current = null;\n };\n\n\n sidebar.expand = function(moveMap) {\n if (selection.classed('collapsed')) {\n sidebar.toggle(moveMap);\n }\n };\n\n\n sidebar.collapse = function(moveMap) {\n if (!selection.classed('collapsed')) {\n sidebar.toggle(moveMap);\n }\n };\n\n\n sidebar.toggle = function(moveMap) {\n var e = d3_event;\n if (e && e.sourceEvent) {\n e.sourceEvent.preventDefault();\n } else if (e) {\n e.preventDefault();\n }\n\n // Don't allow sidebar to toggle when the user is in the walkthrough.\n if (context.inIntro()) return;\n\n var isCollapsed = selection.classed('collapsed');\n var isCollapsing = !isCollapsed;\n var isRTL = (localizer.textDirection() === 'rtl');\n var scaleX = isRTL ? 0 : 1;\n var xMarginProperty = isRTL ? 'margin-right' : 'margin-left';\n\n sidebarWidth = selection.node().getBoundingClientRect().width;\n\n // switch from % to px\n selection.style('width', sidebarWidth + 'px');\n\n var startMargin, endMargin, lastMargin;\n if (isCollapsing) {\n startMargin = lastMargin = 0;\n endMargin = -sidebarWidth;\n } else {\n startMargin = lastMargin = -sidebarWidth;\n endMargin = 0;\n }\n\n selection.transition()\n .style(xMarginProperty, endMargin + 'px')\n .tween('panner', function() {\n var i = d3_interpolateNumber(startMargin, endMargin);\n return function(t) {\n var dx = lastMargin - Math.round(i(t));\n lastMargin = lastMargin - dx;\n context.ui().onResize(moveMap ? undefined : [dx * scaleX, 0]);\n };\n })\n .on('end', function() {\n selection.classed('collapsed', isCollapsing);\n\n // switch back from px to %\n if (!isCollapsing) {\n var containerWidth = container.node().getBoundingClientRect().width;\n var widthPct = (sidebarWidth / containerWidth) * 100;\n selection\n .style(xMarginProperty, null)\n .style('width', widthPct + '%');\n }\n });\n };\n\n // toggle the sidebar collapse when double-clicking the resizer\n resizer.on('dblclick', sidebar.toggle);\n\n // ensure hover sidebar is closed when zooming out beyond editable zoom\n context.map().on('crossEditableZoom.sidebar', function(within) {\n if (!within && !selection.select('.inspector-hover').empty()) {\n hover([]);\n }\n });\n }\n\n sidebar.showPresetList = function() {};\n sidebar.hover = function() {};\n sidebar.hover.cancel = function() {};\n sidebar.intersects = function() {};\n sidebar.select = function() {};\n sidebar.show = function() {};\n sidebar.hide = function() {};\n sidebar.expand = function() {};\n sidebar.collapse = function() {};\n sidebar.toggle = function() {};\n\n return sidebar;\n}\n","import {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { t } from '../core/localizer';\nimport { modeBrowse } from '../modes/browse';\n\n\nexport function uiSourceSwitch(context) {\n var keys;\n\n\n function click() {\n d3_event.preventDefault();\n\n var osm = context.connection();\n if (!osm) return;\n\n if (context.inIntro()) return;\n\n if (context.history().hasChanges() &&\n !window.confirm(t('source_switch.lose_changes'))) return;\n\n var isLive = d3_select(this)\n .classed('live');\n\n isLive = !isLive;\n context.enter(modeBrowse(context));\n context.history().clearSaved(); // remove saved history\n context.flush(); // remove stored data\n\n d3_select(this)\n .text(isLive ? t('source_switch.live') : t('source_switch.dev'))\n .classed('live', isLive)\n .classed('chip', isLive);\n\n osm.switch(isLive ? keys[0] : keys[1]); // switch connection (warning: dispatches 'change' event)\n }\n\n var sourceSwitch = function(selection) {\n selection\n .append('a')\n .attr('href', '#')\n .text(t('source_switch.live'))\n .attr('class', 'live chip')\n .on('click', click);\n };\n\n\n sourceSwitch.keys = function(_) {\n if (!arguments.length) return keys;\n keys = _;\n return sourceSwitch;\n };\n\n\n return sourceSwitch;\n}\n","export function uiSpinner(context) {\n var osm = context.connection();\n\n\n return function(selection) {\n var img = selection\n .append('img')\n .attr('src', context.imagePath('loader-black.gif'))\n .style('opacity', 0);\n\n if (osm) {\n osm\n .on('loading.spinner', function() {\n img.transition()\n .style('opacity', 1);\n })\n .on('loaded.spinner', function() {\n img.transition()\n .style('opacity', 0);\n });\n }\n };\n}\n","import _throttle from 'lodash-es/throttle';\nimport { event as d3_event } from 'd3-selection';\n\nimport { t } from '../core/localizer';\nimport { svgIcon } from '../svg/icon';\n\n\nexport function uiStatus(context) {\n var osm = context.connection();\n\n\n return function(selection) {\n if (!osm) return;\n\n function update(err, apiStatus) {\n selection.html('');\n\n if (err) {\n if (apiStatus === 'connectionSwitched') {\n // if the connection was just switched, we can't rely on\n // the status (we're getting the status of the previous api)\n return;\n\n } else if (apiStatus === 'rateLimited') {\n selection\n .text(t('osm_api_status.message.rateLimit'))\n .append('a')\n .attr('class', 'api-status-login')\n .attr('target', '_blank')\n .call(svgIcon('#iD-icon-out-link', 'inline'))\n .append('span')\n .text(t('login'))\n .on('click.login', function() {\n d3_event.preventDefault();\n osm.authenticate();\n });\n } else {\n\n // don't allow retrying too rapidly\n var throttledRetry = _throttle(function() {\n // try loading the visible tiles\n context.loadTiles(context.projection);\n // manually reload the status too in case all visible tiles were already loaded\n osm.reloadApiStatus();\n }, 2000);\n\n // eslint-disable-next-line no-warning-comments\n // TODO: nice messages for different error types\n selection\n .text(t('osm_api_status.message.error') + ' ')\n .append('a')\n // let the user manually retry their connection directly\n .text(t('osm_api_status.retry'))\n .on('click.retry', function() {\n d3_event.preventDefault();\n throttledRetry();\n });\n }\n\n } else if (apiStatus === 'readonly') {\n selection.text(t('osm_api_status.message.readonly'));\n } else if (apiStatus === 'offline') {\n selection.text(t('osm_api_status.message.offline'));\n }\n\n selection.attr('class', 'api-status ' + (err ? 'error' : apiStatus));\n }\n\n osm.on('apiStatusChange.uiStatus', update);\n\n // reload the status periodically regardless of other factors\n window.setInterval(function() {\n osm.reloadApiStatus();\n }, 90000);\n\n // load the initial status in case no OSM data was loaded yet\n osm.reloadApiStatus();\n };\n}\n","import { event as d3_event } from 'd3-selection';\nimport { t } from '../../core/localizer';\nimport { JXON } from '../../util/jxon';\nimport { osmChangeset } from '../../osm';\nimport { actionDiscardTags } from '../../actions';\nimport { svgIcon } from '../../svg';\nimport { uiTooltip } from '../tooltip';\n\n\nexport function uiToolDownloadOsc(context) {\n\n var tool = {\n id: 'download_osc',\n label: t('download_osc.title')\n };\n\n var button = null;\n var tooltipBehavior = null;\n var history = context.history();\n var _numChanges = 0;\n\n function isDisabled() {\n return _numChanges === 0;\n }\n\n function downloadOsc() {\n d3_event.preventDefault();\n if (!context.inIntro() && history.hasChanges()) {\n var _changeset = new osmChangeset();\n var changes = history.changes(actionDiscardTags(history.difference()));\n var osc = JXON.stringify(_changeset.osmChangeJXON(changes));\n downloadFile(osc,'change.osc');\n }\n }\n\n function updateCount() {\n var val = history.difference().summary().length;\n if (val === _numChanges) return;\n _numChanges = val;\n\n if (tooltipBehavior) {\n tooltipBehavior\n .title(\n t(_numChanges > 0 ? 'download_osc.help' : 'download_osc.no_changes')\n );\n }\n\n if (button) {\n button.classed('disabled', isDisabled());\n }\n }\n\n function downloadFile(data, fileName) {\n // Create an invisible A element\n var a = document.createElement('a');\n a.style.display = 'none';\n document.body.appendChild(a);\n\n // Set the HREF to a Blob representation of the data to be downloaded\n a.href = window.URL.createObjectURL(\n new Blob([data])\n );\n\n // Use download attribute to set set desired file name\n a.setAttribute('download', fileName);\n\n // Trigger the download by simulating click\n a.click();\n\n // Cleanup\n window.URL.revokeObjectURL(a.href);\n document.body.removeChild(a);\n }\n\n\n tool.render = function(selection) {\n\n tooltipBehavior = uiTooltip()\n .placement('bottom')\n .title(t('download_osc.no_changes'));\n\n button = selection\n .append('button')\n .attr('class', 'downloadOsc disabled bar-button')\n .on('click', downloadOsc)\n .call(tooltipBehavior);\n\n button\n .call(svgIcon('#iD-icon-download-osc'));\n\n\n updateCount();\n\n\n context.history()\n .on('change.download_osc', updateCount);\n\n context\n .on('enter.download_osc', function() {\n if (button) {\n button\n .classed('disabled', isDisabled());\n }\n });\n };\n\n tool.uninstall = function() {\n\n context.history()\n .on('change.download', null);\n\n context\n .on('enter.download', null);\n\n button = null;\n tooltipBehavior = null;\n };\n\n return tool;\n}\n","import _debounce from 'lodash-es/debounce';\n\nimport { select as d3_select } from 'd3-selection';\n\nimport {\n modeAddArea,\n modeAddLine,\n modeAddPoint,\n modeBrowse\n} from '../../modes';\n\nimport { presetManager } from '../../presets';\nimport { t } from '../../core/localizer';\nimport { svgIcon } from '../../svg';\nimport { uiTooltip } from '../tooltip';\n\nexport function uiToolOldDrawModes(context) {\n\n var tool = {\n id: 'old_modes',\n label: t('toolbar.add_feature')\n };\n\n var modes = [\n modeAddPoint(context, {\n title: t('modes.add_point.title'),\n button: 'point',\n description: t('modes.add_point.description'),\n preset: presetManager.item('point'),\n key: '1'\n }),\n modeAddLine(context, {\n title: t('modes.add_line.title'),\n button: 'line',\n description: t('modes.add_line.description'),\n preset: presetManager.item('line'),\n key: '2'\n }),\n modeAddArea(context, {\n title: t('modes.add_area.title'),\n button: 'area',\n description: t('modes.add_area.description'),\n preset: presetManager.item('area'),\n key: '3'\n })\n ];\n\n\n function enabled() {\n return osmEditable();\n }\n\n function osmEditable() {\n return context.editable();\n }\n\n modes.forEach(function(mode) {\n context.keybinding().on(mode.key, function() {\n if (!enabled(mode)) return;\n\n if (mode.id === context.mode().id) {\n context.enter(modeBrowse(context));\n } else {\n context.enter(mode);\n }\n });\n });\n\n tool.render = function(selection) {\n\n var wrap = selection\n .append('div')\n .attr('class', 'joined')\n .style('display', 'flex');\n\n var debouncedUpdate = _debounce(update, 500, { leading: true, trailing: true });\n\n context.map()\n .on('move.modes', debouncedUpdate)\n .on('drawn.modes', debouncedUpdate);\n\n context\n .on('enter.modes', update);\n\n update();\n\n\n function update() {\n\n var buttons = wrap.selectAll('button.add-button')\n .data(modes, function(d) { return d.id; });\n\n // exit\n buttons.exit()\n .remove();\n\n // enter\n var buttonsEnter = buttons.enter()\n .append('button')\n .attr('class', function(d) { return d.id + ' add-button bar-button'; })\n .on('click.mode-buttons', function(d) {\n if (!enabled(d)) return;\n\n // When drawing, ignore accidental clicks on mode buttons - #4042\n var currMode = context.mode().id;\n if (/^draw/.test(currMode)) return;\n\n if (d.id === currMode) {\n context.enter(modeBrowse(context));\n } else {\n context.enter(d);\n }\n })\n .call(uiTooltip()\n .placement('bottom')\n .title(function(d) { return d.description; })\n .keys(function(d) { return [d.key]; })\n .scrollContainer(context.container().select('.top-toolbar'))\n );\n\n buttonsEnter\n .each(function(d) {\n d3_select(this)\n .call(svgIcon('#iD-icon-' + d.button));\n });\n\n buttonsEnter\n .append('span')\n .attr('class', 'label')\n .text(function(mode) { return mode.title; });\n\n // if we are adding/removing the buttons, check if toolbar has overflowed\n if (buttons.enter().size() || buttons.exit().size()) {\n context.ui().checkOverflow('.top-toolbar', true);\n }\n\n // update\n buttons = buttons\n .merge(buttonsEnter)\n .classed('disabled', function(d) { return !enabled(d); })\n .classed('active', function(d) { return context.mode() && context.mode().button === d.button; });\n }\n };\n\n return tool;\n}\n","import _debounce from 'lodash-es/debounce';\n\nimport { select as d3_select } from 'd3-selection';\n\nimport {\n modeAddNote,\n modeBrowse\n} from '../../modes';\n\nimport { t } from '../../core/localizer';\nimport { svgIcon } from '../../svg';\nimport { uiTooltip } from '../tooltip';\n\nexport function uiToolNotes(context) {\n\n var tool = {\n id: 'notes',\n label: t('modes.add_note.label')\n };\n\n var mode = modeAddNote(context);\n\n function enabled() {\n return notesEnabled() && notesEditable();\n }\n\n function notesEnabled() {\n var noteLayer = context.layers().layer('notes');\n return noteLayer && noteLayer.enabled();\n }\n\n function notesEditable() {\n var mode = context.mode();\n return context.map().notesEditable() && mode && mode.id !== 'save';\n }\n\n context.keybinding().on(mode.key, function() {\n if (!enabled(mode)) return;\n\n if (mode.id === context.mode().id) {\n context.enter(modeBrowse(context));\n } else {\n context.enter(mode);\n }\n });\n\n tool.render = function(selection) {\n\n\n var debouncedUpdate = _debounce(update, 500, { leading: true, trailing: true });\n\n context.map()\n .on('move.notes', debouncedUpdate)\n .on('drawn.notes', debouncedUpdate);\n\n context\n .on('enter.notes', update);\n\n update();\n\n\n function update() {\n var showNotes = notesEnabled();\n var data = showNotes ? [mode] : [];\n\n var buttons = selection.selectAll('button.add-button')\n .data(data, function(d) { return d.id; });\n\n // exit\n buttons.exit()\n .remove();\n\n // enter\n var buttonsEnter = buttons.enter()\n .append('button')\n .attr('tabindex', -1)\n .attr('class', function(d) { return d.id + ' add-button bar-button'; })\n .on('click.notes', function(d) {\n if (!enabled(d)) return;\n\n // When drawing, ignore accidental clicks on mode buttons - #4042\n var currMode = context.mode().id;\n if (/^draw/.test(currMode)) return;\n\n if (d.id === currMode) {\n context.enter(modeBrowse(context));\n } else {\n context.enter(d);\n }\n })\n .call(uiTooltip()\n .placement('bottom')\n .title(function(d) { return d.description; })\n .keys(function(d) { return [d.key]; })\n .scrollContainer(context.container().select('.top-toolbar'))\n );\n\n buttonsEnter\n .each(function(d) {\n d3_select(this)\n .call(svgIcon(d.icon || '#iD-icon-' + d.button));\n });\n\n // if we are adding/removing the buttons, check if toolbar has overflowed\n if (buttons.enter().size() || buttons.exit().size()) {\n context.ui().checkOverflow('.top-toolbar', true);\n }\n\n // update\n buttons = buttons\n .merge(buttonsEnter)\n .classed('disabled', function(d) { return !enabled(d); })\n .classed('active', function(d) { return context.mode() && context.mode().button === d.button; });\n }\n };\n\n tool.uninstall = function() {\n context\n .on('enter.editor.notes', null)\n .on('exit.editor.notes', null)\n .on('enter.notes', null);\n\n context.map()\n .on('move.notes', null)\n .on('drawn.notes', null);\n };\n\n return tool;\n}\n","import { interpolateRgb as d3_interpolateRgb } from 'd3-interpolate';\nimport { event as d3_event } from 'd3-selection';\n\nimport { t } from '../../core/localizer';\nimport { modeSave } from '../../modes';\nimport { svgIcon } from '../../svg';\nimport { uiCmd } from '../cmd';\nimport { uiTooltip } from '../tooltip';\n\n\nexport function uiToolSave(context) {\n\n var tool = {\n id: 'save',\n label: t('save.title')\n };\n\n var button = null;\n var tooltipBehavior = null;\n var history = context.history();\n var key = uiCmd('⌘S');\n var _numChanges = 0;\n\n function isSaving() {\n var mode = context.mode();\n return mode && mode.id === 'save';\n }\n\n function isDisabled() {\n return _numChanges === 0 || isSaving();\n }\n\n function save() {\n d3_event.preventDefault();\n if (!context.inIntro() && !isSaving() && history.hasChanges()) {\n context.enter(modeSave(context));\n }\n }\n\n function bgColor() {\n var step;\n if (_numChanges === 0) {\n return null;\n } else if (_numChanges <= 50) {\n step = _numChanges / 50;\n return d3_interpolateRgb('#fff', '#ff8')(step); // white -> yellow\n } else {\n step = Math.min((_numChanges - 50) / 50, 1.0);\n return d3_interpolateRgb('#ff8', '#f88')(step); // yellow -> red\n }\n }\n\n function updateCount() {\n var val = history.difference().summary().length;\n if (val === _numChanges) return;\n\n _numChanges = val;\n\n if (tooltipBehavior) {\n tooltipBehavior\n .title(t(_numChanges > 0 ? 'save.help' : 'save.no_changes'))\n .keys([key]);\n }\n\n if (button) {\n button\n .classed('disabled', isDisabled())\n .style('background', bgColor(_numChanges));\n\n button.select('span.count')\n .text(_numChanges);\n }\n }\n\n\n tool.render = function(selection) {\n tooltipBehavior = uiTooltip()\n .placement('bottom')\n .title(t('save.no_changes'))\n .keys([key])\n .scrollContainer(context.container().select('.top-toolbar'));\n\n var lastPointerUpType;\n\n button = selection\n .append('button')\n .attr('class', 'save disabled bar-button')\n .on('pointerup', function() {\n lastPointerUpType = d3_event.pointerType;\n })\n .on('click', function() {\n d3_event.preventDefault();\n\n save();\n\n if (_numChanges === 0 && (\n lastPointerUpType === 'touch' ||\n lastPointerUpType === 'pen')\n ) {\n // there are no tooltips for touch interactions so flash feedback instead\n context.ui().flash\n .duration(2000)\n .iconName('#iD-icon-save')\n .iconClass('disabled')\n .text(t('save.no_changes'))();\n }\n lastPointerUpType = null;\n })\n .call(tooltipBehavior);\n\n button\n .call(svgIcon('#iD-icon-save'));\n\n button\n .append('span')\n .attr('class', 'count')\n .attr('aria-hidden', 'true')\n .text('0');\n\n updateCount();\n\n\n context.keybinding()\n .on(key, save, true);\n\n\n context.history()\n .on('change.save', updateCount);\n\n context\n .on('enter.save', function() {\n if (button) {\n button\n .classed('disabled', isDisabled());\n\n if (isSaving()) {\n button.call(tooltipBehavior.hide);\n }\n }\n });\n };\n\n\n tool.uninstall = function() {\n context.keybinding()\n .off(key, true);\n\n context.history()\n .on('change.save', null);\n\n context\n .on('enter.save', null);\n\n button = null;\n tooltipBehavior = null;\n };\n\n return tool;\n}\n","import { t, localizer } from '../../core/localizer';\nimport { svgIcon } from '../../svg';\nimport { uiTooltip } from '../tooltip';\n\nexport function uiToolSidebarToggle(context) {\n\n var tool = {\n id: 'sidebar_toggle',\n label: t('toolbar.inspect')\n };\n\n tool.render = function(selection) {\n selection\n .append('button')\n .attr('class', 'bar-button')\n .on('click', function() {\n context.ui().sidebar.toggle();\n })\n .call(uiTooltip()\n .placement('bottom')\n .title(t('sidebar.tooltip'))\n .keys([t('sidebar.key')])\n .scrollContainer(context.container().select('.top-toolbar'))\n )\n .call(svgIcon('#iD-icon-sidebar-' + (localizer.textDirection() === 'rtl' ? 'right' : 'left')));\n };\n\n return tool;\n}\n","import _debounce from 'lodash-es/debounce';\n\nimport {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { t, localizer } from '../../core/localizer';\nimport { svgIcon } from '../../svg';\nimport { uiCmd } from '../cmd';\nimport { uiTooltip } from '../tooltip';\n\nexport function uiToolUndoRedo(context) {\n\n var tool = {\n id: 'undo_redo',\n label: t('toolbar.undo_redo')\n };\n\n var commands = [{\n id: 'undo',\n cmd: uiCmd('⌘Z'),\n action: function() {\n context.undo();\n },\n annotation: function() {\n return context.history().undoAnnotation();\n },\n icon: 'iD-icon-' + (localizer.textDirection() === 'rtl' ? 'redo' : 'undo')\n }, {\n id: 'redo',\n cmd: uiCmd('⌘⇧Z'),\n action: function() {\n context.redo();\n },\n annotation: function() {\n return context.history().redoAnnotation();\n },\n icon: 'iD-icon-' + (localizer.textDirection() === 'rtl' ? 'undo' : 'redo')\n }];\n\n\n function editable() {\n return context.mode() && context.mode().id !== 'save' && context.map().editableDataEnabled(true /* ignore min zoom */);\n }\n\n\n tool.render = function(selection) {\n var tooltipBehavior = uiTooltip()\n .placement('bottom')\n .title(function (d) {\n // Handle string- or object-style annotations. Object-style\n // should include \"type\" and \"description\" keys, where\n // \"description\" is used in place of a string-style annotation.\n // See ui/rapid_feature_inspector.js for the motivating use case.\n return (d.annotation() ?\n t(d.id + '.tooltip', {\n action: d.annotation().description\n ? d.annotation().description\n : d.annotation(),\n }) :\n t(d.id + '.nothing'), d.cmd);\n })\n .keys(function(d) {\n return [d.cmd];\n })\n .scrollContainer(context.container().select('.top-toolbar'));\n\n var lastPointerUpType;\n\n var buttons = selection.selectAll('button')\n .data(commands)\n .enter()\n .append('button')\n .attr('class', function(d) { return 'disabled ' + d.id + '-button bar-button'; })\n .on('pointerup', function() {\n // `pointerup` is always called before `click`\n lastPointerUpType = d3_event.pointerType;\n })\n .on('click', function(d) {\n d3_event.preventDefault();\n\n var annotation = d.annotation();\n\n if (editable() && annotation) {\n d.action();\n }\n\n if (editable() && (\n lastPointerUpType === 'touch' ||\n lastPointerUpType === 'pen')\n ) {\n // there are no tooltips for touch interactions so flash feedback instead\n\n var text = annotation ?\n t(d.id + '.tooltip', { action: annotation }) :\n t(d.id + '.nothing');\n context.ui().flash\n .duration(2000)\n .iconName('#' + d.icon)\n .iconClass(annotation ? '' : 'disabled')\n .text(text)();\n }\n lastPointerUpType = null;\n })\n .call(tooltipBehavior);\n\n buttons.each(function(d) {\n d3_select(this)\n .call(svgIcon('#' + d.icon));\n });\n\n context.keybinding()\n .on(commands[0].cmd, function() {\n d3_event.preventDefault();\n if (editable()) commands[0].action();\n })\n .on(commands[1].cmd, function() {\n d3_event.preventDefault();\n if (editable()) commands[1].action();\n });\n\n\n var debouncedUpdate = _debounce(update, 500, { leading: true, trailing: true });\n\n context.map()\n .on('move.undo_redo', debouncedUpdate)\n .on('drawn.undo_redo', debouncedUpdate);\n\n context.history()\n .on('change.undo_redo', function(difference) {\n if (difference) update();\n });\n\n context\n .on('enter.undo_redo', update);\n\n\n function update() {\n buttons\n .classed('disabled', function(d) {\n return !editable() || !d.annotation();\n })\n .each(function() {\n var selection = d3_select(this);\n if (!selection.select('.tooltip.in').empty()) {\n selection.call(tooltipBehavior.updateContent);\n }\n });\n }\n };\n\n tool.uninstall = function() {\n context.keybinding()\n .off(commands[0].cmd)\n .off(commands[1].cmd);\n\n context.map()\n .on('move.undo_redo', null)\n .on('drawn.undo_redo', null);\n\n context.history()\n .on('change.undo_redo', null);\n\n context\n .on('enter.undo_redo', null);\n };\n\n return tool;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { select as d3_select, event as d3_event } from 'd3-selection';\n\nimport { localizer } from '../core/localizer';\nimport { svgIcon } from '../svg/icon';\nimport { utilKeybinding, utilRebind } from '../util';\n\n\nexport function uiRapidColorpicker(context, parentModal) {\n const rapidContext = context.rapidContext();\n const dispatch = d3_dispatch('change', 'done');\n\n let _close = () => {};\n\n\n function togglePopup(d, i, nodes) {\n const shaded = context.container().selectAll('.shaded'); // container for the existing modal\n if (shaded.empty()) return;\n\n if (shaded.selectAll('.colorpicker-popup').size()) {\n _close();\n } else {\n renderPopup(shaded, nodes[i]);\n }\n }\n\n\n // if user clicks outside the colorpicker, dismiss\n function handleClick() {\n const target = d3_event.target;\n const className = (target && target.className) || '';\n if (!/colorpicker/i.test(className)) {\n d3_event.stopPropagation();\n d3_event.preventDefault();\n _close();\n }\n }\n\n // https://www.w3.org/TR/AERT#color-contrast\n // https://trendct.org/2016/01/22/how-to-choose-a-label-color-to-contrast-with-background/\n // pass color as a hexstring like '#rgb', '#rgba', '#rrggbb', '#rrggbbaa' (alpha values are ignored)\n function getBrightness(color) {\n const short = (color.length < 6);\n const r = parseInt(short ? color[1] + color[1] : color[1] + color[2], 16);\n const g = parseInt(short ? color[2] + color[2] : color[3] + color[4], 16);\n const b = parseInt(short ? color[3] + color[3] : color[5] + color[6], 16);\n return ((r * 299) + (g * 587) + (b * 114)) / 1000;\n }\n\n\n function render(selection) {\n let colorpicker = selection.selectAll('.rapid-colorpicker')\n .data(d => [d], d => d.id); // retain data from parent\n\n // enter\n let colorpickerEnter = colorpicker.enter()\n .append('div')\n .attr('class', 'rapid-colorpicker')\n .on('click', togglePopup);\n\n colorpickerEnter\n .append('div')\n .attr('class', 'rapid-colorpicker-fill')\n .call(svgIcon('#fas-palette'));\n\n // update\n colorpicker\n .merge(colorpickerEnter)\n .selectAll('.rapid-colorpicker-fill')\n .style('background', d => d.color)\n .select('.icon') // propagate bound data\n .style('color', d => getBrightness(d.color) > 140.5 ? '#333' : '#fff');\n }\n\n\n function renderPopup(selection, forNode) {\n const dataset = forNode.__data__;\n const rect = forNode.getBoundingClientRect();\n const popWidth = 180;\n const popTop = rect.bottom + 15;\n const popLeft = localizer.textDirection() === 'rtl'\n ? rect.right - (0.3333 * popWidth)\n : rect.left - (0.6666 * popWidth);\n const arrowLeft = localizer.textDirection() === 'rtl'\n ? (0.3333 * popWidth) - rect.width + 10\n : (0.6666 * popWidth) + 10;\n\n const origClose = parentModal.close;\n parentModal.close = () => { /* ignore */ };\n\n _close = () => {\n popup\n .transition()\n .duration(200)\n .style('opacity', 0)\n .remove();\n\n parentModal.close = origClose; // restore close handler\n\n let keybinding = utilKeybinding('modal');\n keybinding.on(['⌫', '⎋'], origClose);\n d3_select(document).call(keybinding);\n d3_select(document).on('click.colorpicker', null);\n _close = () => {};\n dispatch.call('done');\n };\n\n let keybinding = utilKeybinding('modal');\n keybinding.on(['⌫', '⎋'], _close);\n d3_select(document).call(keybinding);\n d3_select(document).on('click.colorpicker', handleClick);\n\n let popup = selection\n .append('div')\n .attr('class', 'colorpicker-popup')\n .style('opacity', 0)\n .style('width', popWidth + 'px')\n .style('top', popTop + 'px')\n .style('left', popLeft + 'px');\n\n popup\n .append('div')\n .attr('class', 'colorpicker-arrow')\n .style('left', arrowLeft + 'px');\n\n let content = popup\n .append('div')\n .attr('class', 'colorpicker-content');\n\n let colorlist = content.selectAll('.colorpicker-colors')\n .data([0]);\n\n colorlist = colorlist.enter()\n .append('div')\n .attr('class', 'colorpicker-colors')\n .merge(colorlist);\n\n let colorItems = colorlist.selectAll('.colorpicker-option')\n .data(rapidContext.colors());\n\n // enter\n let colorItemsEnter = colorItems.enter()\n .append('div')\n .attr('class', 'colorpicker-option')\n .style('color', d => d)\n .on('click', selectedColor => {\n dispatch.call('change', this, dataset.id, selectedColor);\n colorItems.classed('selected', d => d === selectedColor);\n });\n\n colorItemsEnter\n .append('div')\n .attr('class', 'colorpicker-option-fill');\n\n // update\n colorItems = colorItems\n .merge(colorItemsEnter);\n\n colorItems\n .classed('selected', d => d === dataset.color);\n\n popup\n .transition()\n .style('opacity', 1);\n }\n\n return utilRebind(render, dispatch, 'on');\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { select as d3_select } from 'd3-selection';\n\nimport marked from 'marked';\nimport { t, localizer } from '../core/localizer';\nimport { prefs } from '../core/preferences';\nimport { geoExtent } from '../geo';\nimport { modeBrowse } from '../modes';\nimport { services } from '../services';\nimport { svgIcon } from '../svg/icon';\nimport { utilKeybinding, utilRebind, utilWrap } from '../util';\n\n\nexport function uiRapidViewManageDatasets(context, parentModal) {\n const rapidContext = context.rapidContext();\n const dispatch = d3_dispatch('done');\n const PERPAGE = 4;\n\n let _content = d3_select(null);\n let _datasetInfo;\n let _datasetStart = 0;\n let _myClose = () => true; // custom close handler\n\n\n function clamp(num, min, max) {\n return Math.max(min, Math.min(num, max));\n }\n\n\n function clickPage(d) {\n if (!Array.isArray(_datasetInfo)) return;\n\n const pages = Math.ceil(_datasetInfo.length / PERPAGE);\n _datasetStart = clamp(d, 0, pages - 1) * PERPAGE;\n\n _content\n .call(renderModalContent);\n }\n\n\n function nextPreviousPage(d) {\n if (!Array.isArray(_datasetInfo)) return;\n\n const pages = Math.ceil(_datasetInfo.length / PERPAGE);\n const currPage = Math.floor(_datasetStart / PERPAGE);\n const nextPage = utilWrap(currPage + d, pages);\n _datasetStart = nextPage * PERPAGE;\n\n _content\n .call(renderModalContent);\n }\n\n\n function render() {\n // Unfortunately `uiModal` is written in a way that there can be only one at a time.\n // So we have to roll our own modal here instead of just creating a second `uiModal`.\n let shaded = context.container().selectAll('.shaded'); // container for the existing modal\n if (shaded.empty()) return;\n if (shaded.selectAll('.modal-view-manage').size()) return; // view/manage modal exists already\n\n const origClose = parentModal.close;\n parentModal.close = () => { /* ignore */ };\n\n // override the close handler\n _myClose = () => {\n myModal\n .transition()\n .duration(200)\n .style('top', '0px')\n .on('end', () => myShaded.remove());\n\n parentModal.close = origClose; // restore close handler\n\n let keybinding = utilKeybinding('modal');\n keybinding.on(['⌫', '⎋'], origClose);\n d3_select(document).call(keybinding);\n dispatch.call('done');\n };\n\n\n let keybinding = utilKeybinding('modal');\n keybinding.on(['⌫', '⎋'], _myClose);\n d3_select(document).call(keybinding);\n\n let myShaded = shaded\n .append('div')\n .attr('class', 'view-manage-wrap'); // need absolutely positioned div here for new stacking context\n\n let myModal = myShaded\n .append('div')\n .attr('class', 'modal rapid-modal modal-view-manage') // RapiD styling\n .style('opacity', 0);\n\n myModal\n .append('button')\n .attr('class', 'close')\n .on('click', _myClose)\n .call(svgIcon('#iD-icon-close'));\n\n _content = myModal\n .append('div')\n .attr('class', 'rapid-stack content');\n\n _content\n .call(renderModalContent);\n\n _content.selectAll('.ok-button')\n .node()\n .focus();\n\n myModal\n .transition()\n .style('opacity', 1);\n }\n\n\n function renderModalContent(selection) {\n const isRTL = localizer.textDirection() === 'rtl';\n\n /* Header section */\n let headerEnter = selection.selectAll('.rapid-view-manage-header')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'modal-section rapid-view-manage-header');\n\n let line1 = headerEnter\n .append('div');\n\n line1\n .append('div')\n .attr('class', 'rapid-view-manage-header-icon')\n .call(svgIcon('#iD-icon-data', 'icon-30'));\n\n line1\n .append('div')\n .attr('class', 'rapid-view-manage-header-text')\n .text(t('rapid_feature_toggle.esri.title'));\n\n line1\n .append('div')\n .attr('class', 'rapid-view-manage-header-inputs');\n // .text('Home / Search');\n\n let line2 = headerEnter\n .append('div');\n\n line2\n .append('div')\n .attr('class', 'rapid-view-manage-header-about')\n .html(marked(t('rapid_feature_toggle.esri.about')));\n\n line2.selectAll('a')\n .attr('target', '_blank');\n\n\n /* Pages section */\n let pagesSection = selection.selectAll('.rapid-view-manage-pages')\n .data([0]);\n\n let pagesSectionEnter = pagesSection.enter()\n .append('div')\n .attr('class', 'modal-section rapid-view-manage-pages');\n\n pagesSection = pagesSection\n .merge(pagesSectionEnter)\n .call(renderPages);\n\n\n /* Dataset section */\n let dsSection = selection.selectAll('.rapid-view-manage-datasets-section')\n .data([0]);\n\n // enter\n let dsSectionEnter = dsSection.enter()\n .append('div')\n .attr('class', 'modal-section rapid-view-manage-datasets-section');\n\n dsSectionEnter\n .append('div')\n .attr('class', 'rapid-view-manage-pageleft')\n .call(svgIcon(isRTL ? '#iD-icon-forward' : '#iD-icon-backward'))\n .on('click', () => nextPreviousPage(isRTL ? 1 : -1) );\n\n dsSectionEnter\n .append('div')\n .attr('class', 'rapid-view-manage-datasets');\n\n dsSectionEnter\n .append('div')\n .attr('class', 'rapid-view-manage-pageright')\n .call(svgIcon(isRTL ? '#iD-icon-backward' : '#iD-icon-forward'))\n .on('click', () => nextPreviousPage(isRTL ? -1 : 1) );\n\n // update\n dsSection = dsSection\n .merge(dsSectionEnter);\n\n dsSection.selectAll('.rapid-view-manage-datasets')\n .call(renderDatasets);\n\n\n /* OK Button */\n let buttonsEnter = selection.selectAll('.modal-section.buttons')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'modal-section buttons');\n\n buttonsEnter\n .append('button')\n .attr('class', 'button ok-button action')\n .on('click', _myClose)\n .text(t('confirm.okay'));\n }\n\n\n function renderDatasets(selection) {\n const showPreview = prefs('rapid-internal-feature.previewDatasets') === 'true';\n const service = services.esriData;\n if (!service || (Array.isArray(_datasetInfo) && !_datasetInfo.length)) {\n selection.text(t('rapid_feature_toggle.esri.no_datasets'));\n return;\n }\n\n if (!_datasetInfo) {\n selection.text(t('rapid_feature_toggle.esri.fetching_datasets'));\n service.loadDatasets()\n .then(results => {\n // exclude preview datasets unless user has opted into them\n return _datasetInfo = Object.values(results)\n .filter(d => showPreview || !d.groupCategories.some(category => category === '/Categories/Preview'));\n })\n .then(() => _content.call(renderModalContent));\n return;\n }\n\n selection.text('');\n\n let page = _datasetInfo.slice(_datasetStart, _datasetStart + PERPAGE);\n let datasets = selection.selectAll('.rapid-view-manage-dataset')\n .data(page, d => d.id);\n\n // exit\n datasets.exit()\n .remove();\n\n // enter\n let datasetsEnter = datasets.enter()\n .append('div')\n .attr('class', 'rapid-view-manage-dataset');\n\n let labelsEnter = datasetsEnter\n .append('div')\n .attr('class', 'rapid-view-manage-dataset-label');\n\n labelsEnter\n .append('div')\n .attr('class', 'rapid-view-manage-dataset-name')\n .text(d => d.title);\n\n labelsEnter\n .append('div')\n .attr('class', 'rapid-view-manage-dataset-license')\n .append('a')\n .attr('class', 'rapid-view-manage-dataset-link')\n .attr('target', '_blank')\n .attr('href', d => d.itemURL)\n .text(t('rapid_feature_toggle.esri.more_info'))\n .call(svgIcon('#iD-icon-out-link', 'inline'));\n\n labelsEnter.selectAll('.rapid-view-manage-dataset-beta')\n .data(d => d.groupCategories.filter(d => d === '/Categories/Preview'))\n .enter()\n .append('div')\n .attr('class', 'rapid-view-manage-dataset-beta beta')\n .attr('title', t('rapid_poweruser_features.beta'));\n\n labelsEnter\n .append('div')\n .text(d => d.snippet);\n\n labelsEnter\n .append('button')\n .attr('class', 'rapid-view-manage-dataset-action')\n .on('click', toggleDataset);\n\n let thumbsEnter = datasetsEnter\n .append('div')\n .attr('class', 'rapid-view-manage-dataset-thumb');\n\n thumbsEnter\n .append('img')\n .attr('class', 'rapid-view-manage-dataset-thumbnail')\n .attr('src', d => `https://openstreetmap.maps.arcgis.com/sharing/rest/content/items/${d.id}/info/${d.thumbnail}?w=400`);\n\n // update\n datasets = datasets\n .merge(datasetsEnter);\n\n datasets.selectAll('.rapid-view-manage-dataset-action')\n .classed('secondary', d => datasetAdded(d))\n .text(d => datasetAdded(d) ? t('rapid_feature_toggle.esri.remove') : t('rapid_feature_toggle.esri.add_to_map'));\n }\n\n\n function renderPages(selection) {\n if (!_datasetInfo) return;\n\n const total = _datasetInfo.length;\n const numPages = Math.ceil(total / PERPAGE);\n const currPage = Math.floor(_datasetStart / PERPAGE);\n const pages = Array.from(Array(numPages).keys());\n\n let dots = selection.selectAll('.rapid-view-manage-page')\n .data(pages);\n\n // exit\n dots.exit()\n .remove();\n\n // enter/update\n dots.enter()\n .append('span')\n .attr('class', 'rapid-view-manage-page')\n .html('⬤')\n .on('click', clickPage)\n .merge(dots)\n .classed('current', d => d === currPage);\n }\n\n\n function toggleDataset(d, i, nodes) {\n const datasets = rapidContext.datasets();\n const ds = datasets[d.id];\n\n if (ds) {\n ds.added = !ds.added;\n\n } else { // hasn't been added yet\n const isBeta = d.groupCategories.some(d => d === '/Categories/Preview');\n const isBuildings = d.groupCategories.some(d => d === '/Categories/Buildings');\n\n // pick a new color\n const colors = rapidContext.colors();\n const colorIndex = Object.keys(datasets).length % colors.length;\n\n let dataset = {\n id: d.id,\n beta: isBeta,\n added: true, // whether it should appear in the list\n enabled: true, // whether the user has checked it on\n conflated: false,\n service: 'esri',\n color: colors[colorIndex],\n label: d.title,\n license_markdown: t('rapid_feature_toggle.esri.license_markdown')\n };\n\n if (d.extent) {\n dataset.extent = geoExtent(d.extent);\n }\n\n // Test running building layers only through conflation service\n if (isBuildings) {\n dataset.conflated = true;\n dataset.service = 'fbml';\n }\n\n datasets[d.id] = dataset;\n }\n\n nodes[i].blur();\n _content.call(renderModalContent);\n\n context.enter(modeBrowse(context)); // return to browse mode (in case something was selected)\n context.map().pan([0,0]); // trigger a map redraw\n }\n\n\n function datasetAdded(d) {\n const datasets = rapidContext.datasets();\n return datasets[d.id] && datasets[d.id].added;\n }\n\n\n return utilRebind(render, dispatch, 'on');\n}\n","import { event as d3_event, select as d3_select } from 'd3-selection';\n\nimport marked from 'marked';\nimport { t, localizer } from '../core/localizer';\nimport { prefs } from '../core/preferences';\nimport { icon } from './intro/helper';\nimport { modeBrowse } from '../modes';\nimport { svgIcon } from '../svg/icon';\nimport { uiModal } from './modal';\nimport { uiRapidColorpicker } from './rapid_colorpicker';\nimport { uiRapidViewManageDatasets } from './rapid_view_manage_datasets';\n\nexport function uiRapidFeatureToggleDialog(context, AIFeatureToggleKey, featureToggleKeyDispatcher) {\n const rapidContext = context.rapidContext();\n\n let _modalSelection = d3_select(null);\n let _content = d3_select(null);\n let _viewManageModal;\n let _colorpicker;\n\n\n function datasetEnabled(d) {\n const dataset = rapidContext.datasets()[d.id];\n return dataset && dataset.enabled;\n }\n\n function toggleDataset(d) {\n const dataset = rapidContext.datasets()[d.id];\n if (dataset) {\n dataset.enabled = !dataset.enabled;\n context.enter(modeBrowse(context)); // return to browse mode (in case something was selected)\n context.map().pan([0,0]); // trigger a map redraw\n }\n }\n\n function changeColor(datasetID, color) {\n const dataset = rapidContext.datasets()[datasetID];\n if (dataset) {\n dataset.color = color;\n context.map().pan([0,0]); // trigger a map redraw\n _content.call(renderModalContent);\n\n // if a RapiD feature is selected, reselect it to update sidebar too\n const mode = context.mode();\n if (mode && mode.id === 'select-ai-features')\n context.enter(mode, mode.selectedDatum());\n }\n }\n\n function toggleRapid() {\n const rapidLayer = context.layers().layer('ai-features');\n rapidLayer.enabled(!rapidLayer.enabled()); // toggling the layer will trigger a map redraw\n _content.call(renderModalContent);\n }\n\n\n function keyPressHandler() {\n if (d3_event.shiftKey && d3_event.key === t('map_data.layers.ai-features.key')) {\n toggleRapid();\n }\n }\n\n\n return function render(selection) {\n _modalSelection = uiModal(selection);\n\n _modalSelection.select('.modal')\n .attr('class', 'modal rapid-modal'); // RapiD styling\n\n _viewManageModal = uiRapidViewManageDatasets(context, _modalSelection)\n .on('done', () => _content.call(renderModalContent));\n\n _colorpicker = uiRapidColorpicker(context, _modalSelection)\n .on('change', changeColor);\n\n _content = _modalSelection.select('.content')\n .append('div')\n .attr('class', 'rapid-stack')\n .on('keypress', keyPressHandler);\n\n _content\n .call(renderModalContent);\n\n _content.selectAll('.ok-button')\n .node()\n .focus();\n\n featureToggleKeyDispatcher\n .on('ai_feature_toggle', () => _content.call(renderModalContent) );\n };\n\n\n function renderModalContent(selection) {\n const rapidLayer = context.layers().layer('ai-features');\n\n /* Toggle All */\n let toggleAll = selection.selectAll('.rapid-toggle-all')\n .data([0]);\n\n // enter\n let toggleAllEnter = toggleAll\n .enter()\n .append('div')\n .attr('class', 'modal-section rapid-checkbox rapid-toggle-all');\n\n let toggleAllTextEnter = toggleAllEnter\n .append('div')\n .attr('class', 'rapid-feature-label-container');\n\n toggleAllTextEnter\n .append('div')\n .attr('class', 'rapid-feature-label')\n .html(t('rapid_feature_toggle.toggle_all', { rapidicon: icon('#iD-logo-rapid', 'logo-rapid') }));\n\n toggleAllTextEnter\n .append('span')\n .attr('class', 'rapid-feature-hotkey')\n .html('(' + AIFeatureToggleKey + ')');\n\n let toggleAllCheckboxEnter = toggleAllEnter\n .append('div')\n .attr('class', 'rapid-checkbox-inputs')\n .append('label')\n .attr('class', 'rapid-checkbox-label');\n\n toggleAllCheckboxEnter\n .append('input')\n .attr('type', 'checkbox')\n .attr('class', 'rapid-feature-checkbox')\n .on('click', toggleRapid);\n\n toggleAllCheckboxEnter\n .append('div')\n .attr('class', 'rapid-checkbox-custom');\n\n // update\n toggleAll = toggleAll\n .merge(toggleAllEnter);\n\n toggleAll.selectAll('.rapid-feature-checkbox')\n .property('checked', rapidLayer.showAll());\n\n\n /* Dataset List */\n let datasets = selection.selectAll('.rapid-datasets-container')\n .data([0]);\n\n let datasetsEnter = datasets.enter()\n .append('div')\n .attr('class', 'rapid-datasets-container');\n\n datasets\n .merge(datasetsEnter)\n .call(renderDatasets);\n\n\n /* View/Manage Datasets */\n let manageDatasetsEnter = selection.selectAll('.rapid-manage-datasets')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'modal-section rapid-checkbox rapid-manage-datasets')\n .on('click', () => context.container().call(_viewManageModal));\n\n manageDatasetsEnter\n .append('div')\n .attr('class', 'rapid-feature-label-container')\n .append('div')\n .attr('class', 'rapid-feature-label')\n .text(t('rapid_feature_toggle.view_manage_datasets'));\n\n manageDatasetsEnter\n .append('div')\n .attr('class', 'rapid-checkbox-inputs')\n .append('div')\n .attr('class', 'rapid-checkbox-label')\n .call(svgIcon(localizer.textDirection() === 'rtl' ? '#iD-icon-backward' : '#iD-icon-forward', 'icon-30'));\n\n\n /* OK Button */\n let buttonsEnter = selection.selectAll('.modal-section.buttons')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'modal-section buttons');\n\n buttonsEnter\n .append('button')\n .attr('class', 'button ok-button action')\n .on('click', () => _modalSelection.remove())\n .text(t('confirm.okay'));\n }\n\n\n function renderDatasets(selection) {\n const showPreview = prefs('rapid-internal-feature.previewDatasets') === 'true';\n const datasets = Object.values(rapidContext.datasets())\n .filter(d => d.added && (showPreview || !d.beta)); // exclude preview datasets unless user has opted into them\n\n const rapidLayer = context.layers().layer('ai-features');\n\n let rows = selection.selectAll('.rapid-checkbox-dataset')\n .data(datasets, d => d.id);\n\n // exit\n rows.exit()\n .remove();\n\n // enter\n let rowsEnter = rows.enter()\n .append('div')\n .attr('class', 'modal-section rapid-checkbox rapid-checkbox-dataset');\n\n rowsEnter\n .append('div')\n .attr('class', 'rapid-feature')\n .each((d, i, nodes) => {\n let selection = d3_select(nodes[i]);\n\n // line1: name and details\n let labelEnter = selection\n .append('div')\n .attr('class', 'rapid-feature-label-container');\n\n labelEnter\n .append('div')\n .attr('class', 'rapid-feature-label')\n .text(d.label || d.id); // fallback to dataset ID\n\n if (d.beta) {\n labelEnter\n .append('div')\n .attr('class', 'rapid-feature-label-beta beta')\n .attr('title', t('rapid_poweruser_features.beta'));\n }\n\n if (d.description) {\n labelEnter\n .append('div')\n .attr('class', 'rapid-feature-label-divider');\n\n labelEnter\n .append('div')\n .attr('class', 'rapid-feature-description')\n .text(d.description);\n }\n\n if (d.license_markdown) {\n labelEnter\n .append('div')\n .attr('class', 'rapid-feature-label-divider');\n\n labelEnter\n .append('div')\n .attr('class', 'rapid-feature-license')\n .html(marked(d.license_markdown));\n\n labelEnter.select('p a')\n .attr('target', '_blank');\n }\n\n // line2: dataset extent\n selection\n .append('div')\n .attr('class', 'rapid-feature-extent-container')\n .each((d, i, nodes) => {\n let selection = d3_select(nodes[i]);\n\n // if the data spans more than 100°*100°, it might as well be worldwide\n if (d.extent && d.extent.area() < 10000) {\n selection\n .append('a')\n .attr('href', '#')\n .text(t('rapid_feature_toggle.center_map'))\n .on('click', () => {\n d3_event.preventDefault();\n context.map().extent(d.extent);\n });\n } else {\n selection\n .text(t('rapid_feature_toggle.worldwide'));\n }\n });\n });\n\n let inputsEnter = rowsEnter\n .append('div')\n .attr('class', 'rapid-checkbox-inputs');\n\n inputsEnter\n .append('label')\n .attr('class', 'rapid-colorpicker-label');\n\n let checkboxEnter = inputsEnter\n .append('label')\n .attr('class', 'rapid-checkbox-label');\n\n checkboxEnter\n .append('input')\n .attr('type', 'checkbox')\n .attr('class', 'rapid-feature-checkbox')\n .on('click', toggleDataset);\n\n checkboxEnter\n .append('div')\n .attr('class', 'rapid-checkbox-custom');\n\n\n // update\n rows = rows\n .merge(rowsEnter)\n .classed('disabled', !rapidLayer.showAll());\n\n rows.selectAll('.rapid-colorpicker-label')\n .attr('disabled', rapidLayer.showAll() ? null : true)\n .call(_colorpicker);\n\n rows.selectAll('.rapid-checkbox-label')\n .classed('disabled', !rapidLayer.showAll());\n\n rows.selectAll('.rapid-feature-checkbox')\n .property('checked', datasetEnabled)\n .attr('disabled', rapidLayer.showAll() ? null : true);\n }\n}\n","import { select as d3_select } from 'd3-selection';\n\nimport { t } from '../core/localizer';\nimport { prefs } from '../core/preferences';\nimport { modeBrowse } from '../modes';\nimport { uiModal } from './modal';\n\n\nexport function uiRapidPowerUserFeaturesDialog(context) {\n const featureFlags = ['previewDatasets', 'tagnosticRoadCombine', 'tagSources', 'showAutoFix'];\n const rapidContext = context.rapidContext();\n const showPowerUser = rapidContext.showPowerUser;\n let _modalSelection = d3_select(null);\n let _content = d3_select(null);\n\n // if we are not currently showing poweruser features, move all the feature flags to a different keyspace\n if (!showPowerUser) {\n featureFlags.forEach(featureFlag => {\n const val = prefs(`rapid-internal-feature.${featureFlag}`);\n if (val) {\n prefs(`rapid-internal-feature.was.${featureFlag}`, val);\n prefs(`rapid-internal-feature.${featureFlag}`, null);\n }\n });\n } else {\n featureFlags.forEach(featureFlag => {\n const val = prefs(`rapid-internal-feature.was.${featureFlag}`);\n if (val) {\n prefs(`rapid-internal-feature.${featureFlag}`, val);\n prefs(`rapid-internal-feature.was.${featureFlag}`, null);\n }\n });\n }\n\n\n function isEnabled(featureFlag) {\n return prefs(`rapid-internal-feature.${featureFlag}`) === 'true';\n }\n\n function toggleFeature(featureFlag) {\n let enabled = prefs(`rapid-internal-feature.${featureFlag}`) === 'true';\n enabled = !enabled;\n prefs(`rapid-internal-feature.${featureFlag}`, enabled);\n\n // custom on-toggle behaviors can go here\n if (featureFlag === 'previewDatasets' && !enabled) { // user unchecked previewDatasets feature\n const datasets = rapidContext.datasets();\n Object.values(datasets).forEach(ds => {\n if (ds.beta) {\n ds.added = false;\n ds.enabled = false;\n }\n });\n context.enter(modeBrowse(context)); // return to browse mode (in case something was selected)\n context.map().pan([0,0]); // trigger a map redraw\n }\n }\n\n\n return (selection) => {\n _modalSelection = uiModal(selection);\n\n _modalSelection.select('.modal')\n .attr('class', 'modal rapid-modal'); // RapiD styling\n\n _content = _modalSelection.select('.content')\n .append('div')\n .attr('class', 'rapid-stack poweruser');\n\n _content\n .call(renderModalContent);\n\n _content.selectAll('.ok-button')\n .node()\n .focus();\n };\n\n\n function renderModalContent(selection) {\n /* Header */\n let headerEnter = selection.selectAll('.modal-section-heading')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'modal-section-heading');\n\n headerEnter\n .append('h3')\n .attr('class', 'modal-heading')\n .html(t('rapid_poweruser_features.heading.label'));\n\n headerEnter\n .append('div')\n .attr('class', 'modal-heading-desc')\n .text(t('rapid_poweruser_features.heading.description'))\n .append('span')\n .attr('class', 'smile')\n .text('😎');\n\n\n /* Features */\n let features = selection.selectAll('.rapid-features-container')\n .data([0]);\n\n let featuresEnter = features.enter()\n .append('div')\n .attr('class', 'rapid-features-container');\n\n features\n .merge(featuresEnter)\n .call(renderFeatures);\n\n\n /* OK Button */\n let buttonsEnter = selection.selectAll('.modal-section.buttons')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'modal-section buttons');\n\n buttonsEnter\n .append('button')\n .attr('class', 'button ok-button action')\n .on('click', () => _modalSelection.remove())\n .text(t('confirm.okay'));\n }\n\n\n function renderFeatures(selection) {\n let rows = selection.selectAll('.rapid-checkbox-feature')\n .data(featureFlags, d => d);\n\n // enter\n let rowsEnter = rows.enter()\n .append('div')\n .attr('class', 'modal-section rapid-checkbox rapid-checkbox-feature');\n\n rowsEnter\n .append('div')\n .attr('class', 'rapid-feature')\n .each((d, i, nodes) => {\n let selection = d3_select(nodes[i]);\n\n // line1: Label\n selection\n .append('div')\n .attr('class', 'rapid-feature-label')\n .text(d => t(`rapid_poweruser_features.${d}.label`));\n\n // line2: description\n selection\n .append('div')\n .attr('class', 'rapid-feature-description')\n .text(d => t(`rapid_poweruser_features.${d}.description`));\n });\n\n let inputsEnter = rowsEnter\n .append('div')\n .attr('class', 'rapid-checkbox-inputs');\n\n let checkboxEnter = inputsEnter\n .append('label')\n .attr('class', 'rapid-checkbox-label');\n\n checkboxEnter\n .append('input')\n .attr('type', 'checkbox')\n .attr('class', 'rapid-feature-checkbox')\n .on('click', toggleFeature);\n\n checkboxEnter\n .append('div')\n .attr('class', 'rapid-checkbox-custom');\n\n\n // update\n rows = rows\n .merge(rowsEnter);\n\n rows.selectAll('.rapid-feature-checkbox')\n .property('checked', isEnabled);\n }\n\n}\n","import _debounce from 'lodash-es/debounce';\n\nimport { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { select as d3_select, event as d3_event } from 'd3-selection';\nimport { t } from '../../core/localizer';\nimport { uiTooltip } from '../tooltip';\nimport { uiCmd } from '../cmd';\nimport { uiRapidFeatureToggleDialog } from '../rapid_feature_toggle_dialog';\nimport { uiRapidPowerUserFeaturesDialog } from '../rapid_poweruser_features_dialog';\n\n\nexport function uiToolRapidFeatures(context) {\n const toggleKeyDispatcher = d3_dispatch('ai_feature_toggle');\n const rapidFeaturesToggleKey = uiCmd('⇧' + t('map_data.layers.ai-features.key'));\n const datasetDialog = uiRapidFeatureToggleDialog(context, rapidFeaturesToggleKey, toggleKeyDispatcher);\n const powerUserDialog = uiRapidPowerUserFeaturesDialog(context);\n const showPowerUser = context.rapidContext().showPowerUser;\n\n let tool = {\n id: 'rapid_features',\n label: t('toolbar.rapid_features')\n };\n\n context.keybinding()\n .on(rapidFeaturesToggleKey, () => {\n d3_event.preventDefault();\n d3_event.stopPropagation();\n toggleFeatures();\n });\n\n\n function layerEnabled() {\n return context.layers().layer('ai-features').enabled();\n }\n\n\n function toggleFeatures() {\n let layer = context.layers().layer('ai-features');\n layer.enabled(!layer.enabled());\n toggleKeyDispatcher.call('ai_feature_toggle');\n }\n\n\n function showFeatureToggleDialog(d, i, nodes) {\n d3_select(nodes[i]).node().blur();\n context.container().call(datasetDialog);\n }\n\n function showPowerUserFeaturesDialog(d, i, nodes) {\n d3_select(nodes[i]).node().blur();\n context.container().call(powerUserDialog);\n }\n\n\n tool.render = (selection) => {\n const debouncedUpdate = _debounce(update, 100, { leading: true, trailing: true });\n let wrap = selection\n .append('div')\n .attr('class', showPowerUser ? 'joined' : null)\n .style('display', 'flex');\n\n context.map()\n .on('move.rapid_features', debouncedUpdate)\n .on('drawn.rapid_features', debouncedUpdate);\n\n context\n .on('enter.rapid_features', update);\n\n update();\n\n\n function update() {\n let rapidButton = wrap.selectAll('.rapid-features')\n .data([0]);\n\n // enter\n let rapidButtonEnter = rapidButton.enter()\n .append('button')\n .attr('class', 'bar-button rapid-features')\n .attr('tabindex', -1)\n .on('click', showFeatureToggleDialog)\n .call(uiTooltip()\n .placement('bottom')\n .title(t('shortcuts.browsing.display_options.rapid_features_data'))\n .keys(rapidFeaturesToggleKey)\n );\n\n rapidButtonEnter\n .append('svg')\n .attr('class', 'logo-rapid')\n .append('use')\n .attr('xlink:href', '#iD-logo-rapid');\n\n // update\n rapidButton.merge(rapidButtonEnter)\n .classed('layer-off', !layerEnabled());\n\n\n let powerUserButton = wrap.selectAll('.rapid-poweruser-features')\n .data(showPowerUser ? [0] : []);\n\n powerUserButton.enter()\n .append('button')\n .attr('class', 'bar-button rapid-poweruser-features')\n .attr('tabindex', -1)\n .on('click', showPowerUserFeaturesDialog)\n .call(uiTooltip()\n .placement('bottom')\n .title(t('rapid_poweruser_features.heading.label'))\n )\n .append('div')\n .attr('class', 'beta');\n }\n };\n\n return tool;\n}\n","\nimport {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport _debounce from 'lodash-es/debounce';\nimport { utilStringQs } from '../util';\nimport { uiToolRapidFeatures, uiToolOldDrawModes, uiToolNotes, uiToolSave, uiToolSidebarToggle, uiToolUndoRedo, uiToolDownloadOsc } from './tools';\n\n\nexport function uiTopToolbar(context) {\n\n var sidebarToggle = uiToolSidebarToggle(context),\n rapidFeatures = uiToolRapidFeatures(context),\n modes = uiToolOldDrawModes(context),\n notes = uiToolNotes(context),\n undoRedo = uiToolUndoRedo(context),\n save = uiToolSave(context),\n downloadOsc = uiToolDownloadOsc(context);\n\n function notesEnabled() {\n var noteLayer = context.layers().layer('notes');\n return noteLayer && noteLayer.enabled();\n }\n\n function topToolbar(bar) {\n\n bar.on('wheel.topToolbar', function() {\n if (!d3_event.deltaX) {\n // translate vertical scrolling into horizontal scrolling in case\n // the user doesn't have an input device that can scroll horizontally\n bar.node().scrollLeft += d3_event.deltaY;\n }\n });\n\n var debouncedUpdate = _debounce(update, 500, { leading: true, trailing: true });\n context.layers()\n .on('change.topToolbar', debouncedUpdate);\n\n update();\n\n function update() {\n\n var tools = [\n sidebarToggle,\n 'spacer',\n modes,\n rapidFeatures\n // searchAdd\n ];\n\n tools.push('spacer');\n\n if (notesEnabled()) {\n tools = tools.concat([notes, 'spacer']);\n }\n\n var q = utilStringQs(window.location.hash.substring(1));\n if (q.support_download_osc === 'true') {\n tools.push(downloadOsc);\n }\n tools = tools.concat([undoRedo, save]);\n\n var toolbarItems = bar.selectAll('.toolbar-item')\n .data(tools, function(d) {\n return d.id || d;\n });\n\n toolbarItems.exit()\n .each(function(d) {\n if (d.uninstall) {\n d.uninstall();\n }\n })\n .remove();\n\n var itemsEnter = toolbarItems\n .enter()\n .append('div')\n .attr('class', function(d) {\n var classes = 'toolbar-item ' + (d.id || d).replace('_', '-');\n if (d.klass) classes += ' ' + d.klass;\n return classes;\n });\n\n var actionableItems = itemsEnter.filter(function(d) { return d !== 'spacer'; });\n\n actionableItems\n .append('div')\n .attr('class', 'item-content')\n .each(function(d) {\n d3_select(this).call(d.render, bar);\n });\n\n actionableItems\n .append('div')\n .attr('class', 'item-label')\n .text(function(d) {\n return d.label;\n });\n }\n\n }\n\n return topToolbar;\n}\n","import { prefs } from '../core/preferences';\nimport { t } from '../core/localizer';\nimport { svgIcon } from '../svg/icon';\nimport { uiTooltip } from './tooltip';\n\n\n// these are module variables so they are preserved through a ui.restart()\nvar sawVersion = null;\nvar isNewVersion = false;\nvar isNewUser = false;\n\n\nexport function uiVersion(context) {\n\n var currVersion = context.rapidContext().version;\n var matchedVersion = currVersion.match(/\\d+\\.\\d+\\.\\d+.*/);\n\n if (sawVersion === null && matchedVersion !== null) {\n if (prefs('sawVersion')) {\n isNewUser = false;\n isNewVersion = prefs('sawVersion') !== currVersion && currVersion.indexOf('-') === -1;\n } else {\n isNewUser = true;\n isNewVersion = true;\n }\n prefs('sawVersion', currVersion);\n sawVersion = currVersion;\n }\n\n return function(selection) {\n selection\n .append('a')\n .attr('target', '_blank')\n .attr('tabindex', -1)\n .attr('href', 'https://github.com/facebookincubator/RapiD')\n .text(currVersion);\n\n // only show new version indicator to users that have used iD before\n if (isNewVersion && !isNewUser) {\n selection\n .append('div')\n .attr('class', 'badge')\n .append('a')\n .attr('target', '_blank')\n .attr('tabindex', -1)\n .attr('href', 'https://github.com/facebookincubator/RapiD/blob/master/CHANGELOG.md')\n .call(svgIcon('#maki-gift-11'))\n .call(uiTooltip()\n .title(t('version.whats_new', { version: currVersion }))\n .placement('top')\n );\n }\n };\n}\n","import {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { t, localizer } from '../core/localizer';\nimport { svgIcon } from '../svg/icon';\nimport { uiCmd } from './cmd';\nimport { uiTooltip } from './tooltip';\n\n\nexport function uiZoom(context) {\n\n var zooms = [{\n id: 'zoom-in',\n icon: 'iD-icon-plus',\n title: t('zoom.in'),\n action: zoomIn,\n disabled: function() {\n return !context.map().canZoomIn();\n },\n disabledTitle: t('zoom.disabled.in'),\n key: '+'\n }, {\n id: 'zoom-out',\n icon: 'iD-icon-minus',\n title: t('zoom.out'),\n action: zoomOut,\n disabled: function() {\n return !context.map().canZoomOut();\n },\n disabledTitle: t('zoom.disabled.out'),\n key: '-'\n }];\n\n function zoomIn() {\n d3_event.preventDefault();\n context.map().zoomIn();\n }\n\n function zoomOut() {\n d3_event.preventDefault();\n context.map().zoomOut();\n }\n\n function zoomInFurther() {\n d3_event.preventDefault();\n context.map().zoomInFurther();\n }\n\n function zoomOutFurther() {\n d3_event.preventDefault();\n context.map().zoomOutFurther();\n }\n\n return function(selection) {\n var tooltipBehavior = uiTooltip()\n .placement((localizer.textDirection() === 'rtl') ? 'right' : 'left')\n .title(function(d) {\n if (d.disabled()) {\n return d.disabledTitle;\n }\n return d.title;\n })\n .keys(function(d) {\n return [d.key];\n });\n\n var lastPointerUpType;\n\n var buttons = selection.selectAll('button')\n .data(zooms)\n .enter()\n .append('button')\n .attr('class', function(d) { return d.id; })\n .on('pointerup.editor', function() {\n lastPointerUpType = d3_event.pointerType;\n })\n .on('click.editor', function(d) {\n if (!d.disabled()) {\n d.action();\n } else if (lastPointerUpType === 'touch' || lastPointerUpType === 'pen') {\n context.ui().flash\n .duration(2000)\n .iconName('#' + d.icon)\n .iconClass('disabled')\n .text(d.disabledTitle)();\n }\n lastPointerUpType = null;\n })\n .call(tooltipBehavior);\n\n buttons.each(function(d) {\n d3_select(this)\n .call(svgIcon('#' + d.icon, 'light'));\n });\n\n ['plus', 'ffplus', '=', 'ffequals'].forEach(function(key) {\n context.keybinding().on([key], zoomIn);\n context.keybinding().on([uiCmd('⌘' + key)], zoomInFurther);\n });\n\n ['_', '-', 'ffminus', 'dash'].forEach(function(key) {\n context.keybinding().on([key], zoomOut);\n context.keybinding().on([uiCmd('⌘' + key)], zoomOutFurther);\n });\n\n function updateButtonStates() {\n buttons\n .classed('disabled', function(d) {\n return d.disabled();\n })\n .each(function() {\n var selection = d3_select(this);\n if (!selection.select('.tooltip.in').empty()) {\n selection.call(tooltipBehavior.updateContent);\n }\n });\n }\n\n updateButtonStates();\n\n context.map().on('move.uiZoom', updateButtonStates);\n };\n}\n","import { event as d3_event } from 'd3-selection';\n\nimport { t, localizer } from '../core/localizer';\nimport { uiTooltip } from './tooltip';\nimport { svgIcon } from '../svg/icon';\n\nexport function uiZoomToSelection(context) {\n\n function isDisabled() {\n var mode = context.mode();\n return !mode || !mode.zoomToSelected;\n }\n\n var _lastPointerUpType;\n\n function pointerup() {\n _lastPointerUpType = d3_event.pointerType;\n }\n\n function click() {\n d3_event.preventDefault();\n\n if (isDisabled()) {\n if (_lastPointerUpType === 'touch' || _lastPointerUpType === 'pen') {\n context.ui().flash\n .duration(2000)\n .iconName('#iD-icon-framed-dot')\n .iconClass('disabled')\n .text(t('inspector.zoom_to.no_selection'))();\n }\n } else {\n var mode = context.mode();\n if (mode && mode.zoomToSelected) {\n mode.zoomToSelected();\n }\n }\n\n _lastPointerUpType = null;\n }\n\n return function(selection) {\n\n var tooltipBehavior = uiTooltip()\n .placement((localizer.textDirection() === 'rtl') ? 'right' : 'left')\n .title(function() {\n if (isDisabled()) {\n return t('inspector.zoom_to.no_selection');\n }\n return t('inspector.zoom_to.title');\n })\n .keys([t('inspector.zoom_to.key')]);\n\n var button = selection\n .append('button')\n .on('pointerup', pointerup)\n .on('click', click)\n .call(svgIcon('#iD-icon-framed-dot', 'light'))\n .call(tooltipBehavior);\n\n function setEnabledState() {\n button.classed('disabled', isDisabled());\n if (!button.select('.tooltip.in').empty()) {\n button.call(tooltipBehavior.updateContent);\n }\n }\n\n context.on('enter.uiZoomToSelection', setEnabledState);\n\n setEnabledState();\n };\n}\n","import {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { svgIcon } from '../svg/icon';\nimport { localizer } from '../core/localizer';\nimport { uiTooltip } from './tooltip';\n\n\nexport function uiPane(id, context) {\n\n var _key;\n var _title = '';\n var _description = '';\n var _iconName = '';\n var _sections; // array of uiSection objects\n\n var _paneSelection = d3_select(null);\n\n var _paneTooltip;\n\n var pane = {\n id: id\n };\n\n pane.title = function(val) {\n if (!arguments.length) return _title;\n _title = val;\n return pane;\n };\n\n pane.key = function(val) {\n if (!arguments.length) return _key;\n _key = val;\n return pane;\n };\n\n pane.description = function(val) {\n if (!arguments.length) return _description;\n _description = val;\n return pane;\n };\n\n pane.iconName = function(val) {\n if (!arguments.length) return _iconName;\n _iconName = val;\n return pane;\n };\n\n pane.sections = function(val) {\n if (!arguments.length) return _sections;\n _sections = val;\n return pane;\n };\n\n pane.selection = function() {\n return _paneSelection;\n };\n\n function hidePane() {\n context.ui().togglePanes();\n }\n\n pane.togglePane = function() {\n if (d3_event) d3_event.preventDefault();\n _paneTooltip.hide();\n context.ui().togglePanes(!_paneSelection.classed('shown') ? _paneSelection : undefined);\n };\n\n pane.renderToggleButton = function(selection) {\n\n if (!_paneTooltip) {\n _paneTooltip = uiTooltip()\n .placement((localizer.textDirection() === 'rtl') ? 'right' : 'left')\n .title(_description)\n .keys([_key]);\n }\n\n selection\n .append('button')\n .on('click', pane.togglePane)\n .call(svgIcon('#' + _iconName, 'light'))\n .call(_paneTooltip);\n };\n\n pane.renderContent = function(selection) {\n // override to fully customize content\n\n if (_sections) {\n _sections.forEach(function(section) {\n selection.call(section.render);\n });\n }\n };\n\n pane.renderPane = function(selection) {\n\n _paneSelection = selection\n .append('div')\n .attr('class', 'fillL map-pane hide ' + id + '-pane')\n .attr('pane', id);\n\n var heading = _paneSelection\n .append('div')\n .attr('class', 'pane-heading');\n\n heading\n .append('h2')\n .text(_title);\n\n heading\n .append('button')\n .on('click', hidePane)\n .call(svgIcon('#iD-icon-close'));\n\n\n _paneSelection\n .append('div')\n .attr('class', 'pane-content')\n .call(pane.renderContent);\n\n if (_key) {\n context.keybinding()\n .on(_key, pane.togglePane);\n }\n };\n\n return pane;\n}\n","import {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { prefs } from '../../core/preferences';\nimport { t, localizer } from '../../core/localizer';\nimport { svgIcon } from '../../svg/icon';\nimport { uiSection } from '../section';\nimport { utilDetect } from '../../util/detect';\n\n\nexport function uiSectionBackgroundDisplayOptions(context) {\n\n var section = uiSection('background-display-options', context)\n .title(t('background.display_options'))\n .disclosureContent(renderDisclosureContent);\n\n var _detected = utilDetect();\n var _storedOpacity = prefs('background-opacity');\n var _minVal = 0.25;\n var _maxVal = _detected.cssfilters ? 2 : 1;\n\n var _sliders = _detected.cssfilters\n ? ['brightness', 'contrast', 'saturation', 'sharpness']\n : ['brightness'];\n\n var _options = {\n brightness: (_storedOpacity !== null ? (+_storedOpacity) : 1),\n contrast: 1,\n saturation: 1,\n sharpness: 1\n };\n\n function clamp(x, min, max) {\n return Math.max(min, Math.min(x, max));\n }\n\n function updateValue(d, val) {\n if (!val && d3_event && d3_event.target) {\n val = d3_event.target.value;\n }\n\n val = clamp(val, _minVal, _maxVal);\n\n _options[d] = val;\n context.background()[d](val);\n\n if (d === 'brightness') {\n prefs('background-opacity', val);\n }\n\n section.reRender();\n }\n\n function renderDisclosureContent(selection) {\n var container = selection.selectAll('.display-options-container')\n .data([0]);\n\n var containerEnter = container.enter()\n .append('div')\n .attr('class', 'display-options-container controls-list');\n\n // add slider controls\n var slidersEnter = containerEnter.selectAll('.display-control')\n .data(_sliders)\n .enter()\n .append('div')\n .attr('class', function(d) { return 'display-control display-control-' + d; });\n\n slidersEnter\n .append('h5')\n .text(function(d) { return t('background.' + d); })\n .append('span')\n .attr('class', function(d) { return 'display-option-value display-option-value-' + d; });\n\n slidersEnter\n .append('input')\n .attr('class', function(d) { return 'display-option-input display-option-input-' + d; })\n .attr('type', 'range')\n .attr('min', _minVal)\n .attr('max', _maxVal)\n .attr('step', '0.05')\n .on('input', function(d) {\n var val = d3_select(this).property('value');\n updateValue(d, val);\n });\n\n slidersEnter\n .append('button')\n .attr('title', t('background.reset'))\n .attr('class', function(d) { return 'display-option-reset display-option-reset-' + d; })\n .on('click', function(d) {\n if (d3_event.button !== 0) return;\n updateValue(d, 1);\n })\n .call(svgIcon('#iD-icon-' + (localizer.textDirection() === 'rtl' ? 'redo' : 'undo')));\n\n // reset all button\n containerEnter\n .append('a')\n .attr('class', 'display-option-resetlink')\n .attr('href', '#')\n .text(t('background.reset_all'))\n .on('click', function() {\n for (var i = 0; i < _sliders.length; i++) {\n updateValue(_sliders[i],1);\n }\n });\n\n // update\n container = containerEnter\n .merge(container);\n\n container.selectAll('.display-option-input')\n .property('value', function(d) { return _options[d]; });\n\n container.selectAll('.display-option-value')\n .text(function(d) { return Math.floor(_options[d] * 100) + '%'; });\n\n container.selectAll('.display-option-reset')\n .classed('disabled', function(d) { return _options[d] === 1; });\n\n // first time only, set brightness if needed\n if (containerEnter.size() && _options.brightness !== 1) {\n context.background().brightness(_options.brightness);\n }\n }\n\n return section;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport marked from 'marked';\n\nimport { prefs } from '../../core/preferences';\nimport { t } from '../../core/localizer';\nimport { uiConfirm } from '../confirm';\nimport { utilNoAuto, utilRebind } from '../../util';\n\n\nexport function uiSettingsCustomBackground() {\n var dispatch = d3_dispatch('change');\n\n function render(selection) {\n // keep separate copies of original and current settings\n var _origSettings = {\n template: prefs('background-custom-template')\n };\n var _currSettings = {\n template: prefs('background-custom-template')\n };\n\n var example = 'https://{switch:a,b,c}.tile.openstreetmap.org/{zoom}/{x}/{y}.png';\n var modal = uiConfirm(selection).okButton();\n\n modal\n .classed('settings-modal settings-custom-background', true);\n\n modal.select('.modal-section.header')\n .append('h3')\n .text(t('settings.custom_background.header'));\n\n\n var textSection = modal.select('.modal-section.message-text');\n\n var instructions =\n `${t('settings.custom_background.instructions.info')}\\n` +\n '\\n' +\n `#### ${t('settings.custom_background.instructions.wms.tokens_label')}\\n` +\n `* ${t('settings.custom_background.instructions.wms.tokens.proj')}\\n` +\n `* ${t('settings.custom_background.instructions.wms.tokens.wkid')}\\n` +\n `* ${t('settings.custom_background.instructions.wms.tokens.dimensions')}\\n` +\n `* ${t('settings.custom_background.instructions.wms.tokens.bbox')}\\n` +\n '\\n' +\n `#### ${t('settings.custom_background.instructions.tms.tokens_label')}\\n` +\n `* ${t('settings.custom_background.instructions.tms.tokens.xyz')}\\n` +\n `* ${t('settings.custom_background.instructions.tms.tokens.flipped_y')}\\n` +\n `* ${t('settings.custom_background.instructions.tms.tokens.switch')}\\n` +\n `* ${t('settings.custom_background.instructions.tms.tokens.quadtile')}\\n` +\n `* ${t('settings.custom_background.instructions.tms.tokens.scale_factor')}\\n` +\n '\\n' +\n `#### ${t('settings.custom_background.instructions.example')}\\n` +\n `\\`${example}\\``;\n\n textSection\n .append('div')\n .attr('class', 'instructions-template')\n .html(marked(instructions));\n\n textSection\n .append('textarea')\n .attr('class', 'field-template')\n .attr('placeholder', t('settings.custom_background.template.placeholder'))\n .call(utilNoAuto)\n .property('value', _currSettings.template);\n\n\n // insert a cancel button\n var buttonSection = modal.select('.modal-section.buttons');\n\n buttonSection\n .insert('button', '.ok-button')\n .attr('class', 'button cancel-button secondary-action')\n .text(t('confirm.cancel'));\n\n\n buttonSection.select('.cancel-button')\n .on('click.cancel', clickCancel);\n\n buttonSection.select('.ok-button')\n .attr('disabled', isSaveDisabled)\n .on('click.save', clickSave);\n\n\n function isSaveDisabled() {\n return null;\n }\n\n\n // restore the original template\n function clickCancel() {\n textSection.select('.field-template').property('value', _origSettings.template);\n prefs('background-custom-template', _origSettings.template);\n this.blur();\n modal.close();\n }\n\n // accept the current template\n function clickSave() {\n _currSettings.template = textSection.select('.field-template').property('value');\n prefs('background-custom-template', _currSettings.template);\n this.blur();\n modal.close();\n dispatch.call('change', this, _currSettings);\n }\n }\n\n return utilRebind(render, dispatch, 'on');\n}\n","import _debounce from 'lodash-es/debounce';\nimport { descending as d3_descending, ascending as d3_ascending } from 'd3-array';\nimport {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\nimport { easeCubicInOut as d3_easeCubicInOut } from 'd3-ease';\nimport { prefs } from '../../core/preferences';\nimport { t, localizer } from '../../core/localizer';\nimport { uiTooltip } from '../tooltip';\nimport { svgIcon } from '../../svg/icon';\nimport { uiCmd } from '../cmd';\nimport { uiSettingsCustomBackground } from '../settings/custom_background';\nimport { uiMapInMap } from '../map_in_map';\nimport { uiSection } from '../section';\n\nexport function uiSectionBackgroundList(context) {\n\n let _backgroundList = d3_select(null);\n\n const _customSource = context.background().findSource('custom');\n\n const _settingsCustomBackground = uiSettingsCustomBackground(context)\n .on('change', customChanged);\n\n const section = uiSection('background-list', context)\n .title(t('background.backgrounds'))\n .disclosureContent(renderDisclosureContent);\n\n const favoriteBackgroundsJSON = prefs('background-favorites');\n const _favoriteBackgrounds = favoriteBackgroundsJSON ? JSON.parse(favoriteBackgroundsJSON) : {};\n\n function previousBackgroundID() {\n return prefs('background-last-used-toggle');\n }\n\n function renderDisclosureContent(selection) {\n\n // the background list\n const container = selection.selectAll('.layer-background-list')\n .data([0]);\n\n _backgroundList = container.enter()\n .append('ul')\n .attr('class', 'layer-list layer-background-list')\n .attr('dir', 'auto')\n .merge(container);\n\n\n // add minimap toggle below list\n const bgExtrasListEnter = selection.selectAll('.bg-extras-list')\n .data([0])\n .enter()\n .append('ul')\n .attr('class', 'layer-list bg-extras-list');\n\n const minimapLabelEnter = bgExtrasListEnter\n .append('li')\n .attr('class', 'minimap-toggle-item')\n .append('label')\n .call(uiTooltip()\n .title(t('background.minimap.tooltip'))\n .keys([t('background.minimap.key')])\n .placement('top')\n );\n\n minimapLabelEnter\n .append('input')\n .attr('type', 'checkbox')\n .on('change', () => {\n d3_event.preventDefault();\n uiMapInMap.toggle();\n });\n\n minimapLabelEnter\n .append('span')\n .text(t('background.minimap.description'));\n\n\n const panelLabelEnter = bgExtrasListEnter\n .append('li')\n .attr('class', 'background-panel-toggle-item')\n .append('label')\n .call(uiTooltip()\n .title(t('background.panel.tooltip'))\n .keys([uiCmd('⌘⇧' + t('info_panels.background.key'))])\n .placement('top')\n );\n\n panelLabelEnter\n .append('input')\n .attr('type', 'checkbox')\n .on('change', () => {\n d3_event.preventDefault();\n context.ui().info.toggle('background');\n });\n\n panelLabelEnter\n .append('span')\n .text(t('background.panel.description'));\n\n const locPanelLabelEnter = bgExtrasListEnter\n .append('li')\n .attr('class', 'location-panel-toggle-item')\n .append('label')\n .call(uiTooltip()\n .title(t('background.location_panel.tooltip'))\n .keys([uiCmd('⌘⇧' + t('info_panels.location.key'))])\n .placement('top')\n );\n\n locPanelLabelEnter\n .append('input')\n .attr('type', 'checkbox')\n .on('change', () => {\n d3_event.preventDefault();\n context.ui().info.toggle('location');\n });\n\n locPanelLabelEnter\n .append('span')\n .text(t('background.location_panel.description'));\n\n\n // \"Info / Report a Problem\" link\n selection.selectAll('.imagery-faq')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'imagery-faq')\n .append('a')\n .attr('target', '_blank')\n .call(svgIcon('#iD-icon-out-link', 'inline'))\n .attr('href', 'https://github.com/openstreetmap/iD/blob/develop/FAQ.md#how-can-i-report-an-issue-with-background-imagery')\n .append('span')\n .text(t('background.imagery_problem_faq'));\n\n _backgroundList\n .call(drawListItems, 'radio', chooseBackground, (d) => { return !d.isHidden() && !d.overlay; });\n }\n\n function setTooltips(selection) {\n selection.each((d, i, nodes) => {\n const item = d3_select(nodes[i]).select('label');\n const span = item.select('span');\n const placement = (i < nodes.length / 2) ? 'bottom' : 'top';\n const description = d.description();\n const isOverflowing = (span.property('clientWidth') !== span.property('scrollWidth'));\n\n item.call(uiTooltip().destroyAny);\n\n if (d.id === previousBackgroundID()) {\n item.call(uiTooltip()\n .placement(placement)\n .title('' + t('background.switch') + '
')\n .keys([uiCmd('⌘' + t('background.key'))])\n );\n } else if (description || isOverflowing) {\n item.call(uiTooltip()\n .placement(placement)\n .title(description || d.name())\n );\n }\n });\n }\n\n function sortSources(a, b) {\n return _favoriteBackgrounds[a.id] && !_favoriteBackgrounds[b.id] ? -1\n : _favoriteBackgrounds[b.id] && !_favoriteBackgrounds[a.id] ? 1\n : a.best() && !b.best() ? -1 : b.best() && !a.best() ? 1\n : d3_descending(a.area(), b.area()) || d3_ascending(a.name(), b.name()) || 0;\n }\n\n function drawListItems(layerList, type, change, filter) {\n const sources = context.background()\n .sources(context.map().extent(), context.map().zoom(), true)\n .filter(filter);\n\n const layerLinks = layerList.selectAll('li')\n .data(sources, (d) => { return d.id; });\n\n layerLinks.exit()\n .remove();\n\n const layerLinksEnter = layerLinks.enter()\n .append('li')\n .classed('layer-custom', (d) => { return d.id === 'custom'; })\n .classed('best', (d) =>{ return d.best(); });\n\n const label = layerLinksEnter\n .append('label');\n\n label\n .append('input')\n .attr('type', type)\n .attr('name', 'layers')\n .on('change', change);\n\n label\n .append('span')\n .attr('class', 'background-name')\n .text((d) => { return d.name(); });\n\n layerLinksEnter\n .append('button')\n .attr('class', 'background-favorite-button')\n .classed('active', (d) => { return !!_favoriteBackgrounds[d.id]; })\n .attr('tabindex', -1)\n .call(svgIcon('#iD-icon-favorite'))\n .on('click', (d, i, nodes) => {\n if (_favoriteBackgrounds[d.id]) {\n d3_select(nodes[i]).classed('active', false);\n delete _favoriteBackgrounds[d.id];\n } else {\n d3_select(nodes[i]).classed('active', true);\n _favoriteBackgrounds[d.id] = true;\n }\n prefs('background-favorites', JSON.stringify(_favoriteBackgrounds));\n\n d3_select(nodes[i].parentElement)\n .transition()\n .duration(300)\n .ease(d3_easeCubicInOut)\n .style('background-color', 'orange')\n .transition()\n .duration(300)\n .ease(d3_easeCubicInOut)\n .style('background-color', null);\n\n layerList.selectAll('li')\n .sort(sortSources);\n layerList\n .call(updateLayerSelections);\n nodes[i].blur(); // Stop old de-stars from having grey background\n });\n\n layerLinksEnter.filter((d) => { return d.id === 'custom'; })\n .append('button')\n .attr('class', 'layer-browse')\n .call(uiTooltip()\n .title(t('settings.custom_background.tooltip'))\n .placement((localizer.textDirection() === 'rtl') ? 'right' : 'left')\n )\n .on('click', editCustom)\n .call(svgIcon('#iD-icon-more'));\n\n layerLinksEnter.filter((d) => { return d.best(); })\n .selectAll('label')\n .append('span')\n .attr('class', 'best')\n .call(uiTooltip()\n .title(t('background.best_imagery'))\n .placement('bottom')\n )\n .call(svgIcon('#iD-icon-best-background'));\n\n layerList.selectAll('li')\n .sort(sortSources);\n\n layerList\n .call(updateLayerSelections);\n\n }\n\n function updateLayerSelections(selection) {\n function active(d) {\n return context.background().showsLayer(d);\n }\n\n selection.selectAll('li')\n .classed('active', active)\n .classed('switch', (d) => { return d.id === previousBackgroundID(); })\n .call(setTooltips)\n .selectAll('input')\n .property('checked', active);\n }\n\n\n function chooseBackground(d) {\n if (d.id === 'custom' && !d.template()) {\n return editCustom();\n }\n\n d3_event.preventDefault();\n const previousBackground = context.background().baseLayerSource();\n prefs('background-last-used-toggle', previousBackground.id);\n prefs('background-last-used', d.id);\n context.background().baseLayerSource(d);\n document.activeElement.blur();\n }\n\n\n function customChanged(d) {\n if (d && d.template) {\n _customSource.template(d.template);\n chooseBackground(_customSource);\n } else {\n _customSource.template('');\n chooseBackground(context.background().findSource('none'));\n }\n }\n\n\n function editCustom() {\n d3_event.preventDefault();\n context.container()\n .call(_settingsCustomBackground);\n }\n\n\n context.background()\n .on('change.background_list', () => {\n _backgroundList.call(updateLayerSelections);\n });\n\n context.map()\n .on('move.background_list',\n _debounce(() => {\n // layers in-view may have changed due to map move\n window.requestIdleCallback(section.reRender);\n }, 1000)\n );\n\n function getBackgrounds(filter) {\n return context.background()\n .sources(context.map().extent(), context.map().zoom(), true)\n .filter(filter);\n }\n\n function chooseBackgroundAtOffset(offset) {\n const backgrounds = getBackgrounds((d) => { return !d.isHidden() && !d.overlay; });\n backgrounds.sort(sortSources);\n const currentBackground = context.background().baseLayerSource();\n const foundIndex = backgrounds.indexOf(currentBackground);\n if (foundIndex === -1) {\n // Can't find the current background, so just do nothing\n return;\n }\n\n let nextBackgroundIndex = (foundIndex + offset + backgrounds.length) % backgrounds.length;\n let nextBackground = backgrounds[nextBackgroundIndex];\n if (nextBackground.id === 'custom' && !nextBackground.template()) {\n nextBackgroundIndex = (nextBackgroundIndex + offset + backgrounds.length) % backgrounds.length;\n nextBackground = backgrounds[nextBackgroundIndex];\n }\n chooseBackground(nextBackground);\n }\n\n function nextBackground() {\n chooseBackgroundAtOffset(1);\n }\n\n function previousBackground() {\n chooseBackgroundAtOffset(-1);\n }\n\n context.keybinding()\n .on(t('background.next_background.key'), nextBackground)\n .on(t('background.previous_background.key'), previousBackground);\n\n return section;\n}\n","import {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { t, localizer } from '../../core/localizer';\nimport { geoMetersToOffset, geoOffsetToMeters } from '../../geo';\nimport { svgIcon } from '../../svg/icon';\nimport { uiSection } from '../section';\n\n\nexport function uiSectionBackgroundOffset(context) {\n\n var section = uiSection('background-offset', context)\n .title(t('background.fix_misalignment'))\n .disclosureContent(renderDisclosureContent)\n .expandedByDefault(false);\n\n var _pointerPrefix = 'PointerEvent' in window ? 'pointer' : 'mouse';\n\n var _directions = [\n ['right', [0.5, 0]],\n ['top', [0, -0.5]],\n ['left', [-0.5, 0]],\n ['bottom', [0, 0.5]]\n ];\n\n\n function cancelEvent() {\n d3_event.stopPropagation();\n d3_event.preventDefault();\n }\n\n\n function updateValue() {\n var meters = geoOffsetToMeters(context.background().offset());\n var x = +meters[0].toFixed(2);\n var y = +meters[1].toFixed(2);\n\n context.container().selectAll('.nudge-inner-rect')\n .select('input')\n .classed('error', false)\n .property('value', x + ', ' + y);\n\n context.container().selectAll('.nudge-reset')\n .classed('disabled', function() {\n return (x === 0 && y === 0);\n });\n }\n\n\n function resetOffset() {\n context.background().offset([0, 0]);\n updateValue();\n }\n\n\n function nudge(d) {\n context.background().nudge(d, context.map().zoom());\n updateValue();\n }\n\n\n function pointerdownNudgeButton(d) {\n var interval;\n var timeout = window.setTimeout(function() {\n interval = window.setInterval(nudge.bind(null, d), 100);\n }, 500);\n\n function doneNudge() {\n window.clearTimeout(timeout);\n window.clearInterval(interval);\n d3_select(window)\n .on(_pointerPrefix + 'up.buttonoffset', null, true)\n .on(_pointerPrefix + 'down.buttonoffset', null, true);\n }\n\n d3_select(window)\n .on(_pointerPrefix + 'up.buttonoffset', doneNudge, true)\n .on(_pointerPrefix + 'down.buttonoffset', doneNudge, true);\n\n nudge(d);\n }\n\n\n function inputOffset() {\n var input = d3_select(this);\n var d = input.node().value;\n\n if (d === '') return resetOffset();\n\n d = d.replace(/;/g, ',').split(',').map(function(n) {\n // if n is NaN, it will always get mapped to false.\n return !isNaN(n) && n;\n });\n\n if (d.length !== 2 || !d[0] || !d[1]) {\n input.classed('error', true);\n return;\n }\n\n context.background().offset(geoMetersToOffset(d));\n updateValue();\n }\n\n\n function dragOffset() {\n if (d3_event.button !== 0) return;\n\n var origin = [d3_event.clientX, d3_event.clientY];\n\n var pointerId = d3_event.pointerId || 'mouse';\n\n context.container()\n .append('div')\n .attr('class', 'nudge-surface');\n\n d3_select(window)\n .on(_pointerPrefix + 'move.drag-bg-offset', pointermove)\n .on(_pointerPrefix + 'up.drag-bg-offset', pointerup);\n\n if (_pointerPrefix === 'pointer') {\n d3_select(window)\n .on('pointercancel.drag-bg-offset', pointerup);\n }\n\n function pointermove() {\n if (pointerId !== (d3_event.pointerId || 'mouse')) return;\n\n var latest = [d3_event.clientX, d3_event.clientY];\n var d = [\n -(origin[0] - latest[0]) / 4,\n -(origin[1] - latest[1]) / 4\n ];\n\n origin = latest;\n nudge(d);\n }\n\n function pointerup() {\n if (pointerId !== (d3_event.pointerId || 'mouse')) return;\n if (d3_event.button !== 0) return;\n\n context.container().selectAll('.nudge-surface')\n .remove();\n\n d3_select(window)\n .on('.drag-bg-offset', null);\n }\n }\n\n\n function renderDisclosureContent(selection) {\n var container = selection.selectAll('.nudge-container')\n .data([0]);\n\n var containerEnter = container.enter()\n .append('div')\n .attr('class', 'nudge-container cf');\n\n containerEnter\n .append('div')\n .attr('class', 'nudge-instructions')\n .text(t('background.offset'));\n\n var nudgeEnter = containerEnter\n .append('div')\n .attr('class', 'nudge-outer-rect')\n .on(_pointerPrefix + 'down', dragOffset);\n\n nudgeEnter\n .append('div')\n .attr('class', 'nudge-inner-rect')\n .append('input')\n .on('change', inputOffset);\n\n containerEnter\n .append('div')\n .selectAll('button')\n .data(_directions).enter()\n .append('button')\n .attr('class', function(d) { return d[0] + ' nudge'; })\n .on('contextmenu', cancelEvent)\n .on(_pointerPrefix + 'down', function(d) {\n if (d3_event.button !== 0) return;\n pointerdownNudgeButton(d[1]);\n });\n\n containerEnter\n .append('button')\n .attr('title', t('background.reset'))\n .attr('class', 'nudge-reset disabled')\n .on('contextmenu', cancelEvent)\n .on('click', function() {\n d3_event.preventDefault();\n if (d3_event.button !== 0) return;\n resetOffset();\n })\n .call(svgIcon('#iD-icon-' + (localizer.textDirection() === 'rtl' ? 'redo' : 'undo')));\n\n updateValue();\n }\n\n context.background()\n .on('change.backgroundOffset-update', updateValue);\n\n return section;\n}\n","import _debounce from 'lodash-es/debounce';\nimport { descending as d3_descending, ascending as d3_ascending } from 'd3-array';\nimport {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { t } from '../../core/localizer';\nimport { uiTooltip } from '../tooltip';\nimport { uiSection } from '../section';\n\nexport function uiSectionOverlayList(context) {\n\n var section = uiSection('overlay-list', context)\n .title(t('background.overlays'))\n .disclosureContent(renderDisclosureContent);\n\n var _overlayList = d3_select(null);\n\n function setTooltips(selection) {\n selection.each(function(d, i, nodes) {\n var item = d3_select(this).select('label');\n var span = item.select('span');\n var placement = (i < nodes.length / 2) ? 'bottom' : 'top';\n var description = d.description();\n var isOverflowing = (span.property('clientWidth') !== span.property('scrollWidth'));\n\n item.call(uiTooltip().destroyAny);\n\n if (description || isOverflowing) {\n item.call(uiTooltip()\n .placement(placement)\n .title(description || d.name())\n );\n }\n });\n }\n\n function updateLayerSelections(selection) {\n function active(d) {\n return context.background().showsLayer(d);\n }\n\n selection.selectAll('li')\n .classed('active', active)\n .call(setTooltips)\n .selectAll('input')\n .property('checked', active);\n }\n\n\n function chooseOverlay(d) {\n d3_event.preventDefault();\n context.background().toggleOverlayLayer(d);\n _overlayList.call(updateLayerSelections);\n document.activeElement.blur();\n }\n\n function drawListItems(layerList, type, change, filter) {\n var sources = context.background()\n .sources(context.map().extent(), context.map().zoom(), true)\n .filter(filter);\n\n var layerLinks = layerList.selectAll('li')\n .data(sources, function(d) { return d.name(); });\n\n layerLinks.exit()\n .remove();\n\n var enter = layerLinks.enter()\n .append('li');\n\n var label = enter\n .append('label');\n\n label\n .append('input')\n .attr('type', type)\n .attr('name', 'layers')\n .on('change', change);\n\n label\n .append('span')\n .text(function(d) { return d.name(); });\n\n\n layerList.selectAll('li')\n .sort(sortSources);\n\n layerList\n .call(updateLayerSelections);\n\n\n function sortSources(a, b) {\n return a.best() && !b.best() ? -1\n : b.best() && !a.best() ? 1\n : d3_descending(a.area(), b.area()) || d3_ascending(a.name(), b.name()) || 0;\n }\n }\n\n function renderDisclosureContent(selection) {\n\n var container = selection.selectAll('.layer-overlay-list')\n .data([0]);\n\n _overlayList = container.enter()\n .append('ul')\n .attr('class', 'layer-list layer-overlay-list')\n .attr('dir', 'auto')\n .merge(container);\n\n _overlayList\n .call(drawListItems, 'checkbox', chooseOverlay, function(d) { return !d.isHidden() && d.overlay; });\n }\n\n context.map()\n .on('move.overlay_list',\n _debounce(function() {\n // layers in-view may have changed due to map move\n window.requestIdleCallback(section.reRender);\n }, 1000)\n );\n\n return section;\n}\n","import { event as d3_event } from 'd3-selection';\nimport { select as d3_select } from 'd3-selection';\n\nimport { t } from '../../core/localizer';\nimport { uiSection } from '../section';\n\nexport function uiSectionGridDisplayOptions(context) {\n\n\n var section = uiSection('grid-display-options', context)\n .title(t('background.grid.grids'))\n .disclosureContent(gridDisplayOptions);\n\n\n function chooseGrid(d) {\n d3_event.preventDefault();\n context.background().numGridSplits(d.numSplit);\n }\n\n\n function render(selection) {\n // the grid list\n var container = selection.selectAll('.layer-grid-list')\n .data([0]);\n\n var gridList = container.enter()\n .append('ul')\n .attr('class', 'layer-list layer-grid-list')\n .attr('dir', 'auto')\n .merge(container);\n\n var gridItems = gridList.selectAll('li')\n .data(\n [{numSplit: 0, name: t('background.grid.no_grid')},\n {numSplit: 2, name: t('background.grid.n_by_n', {num: 2})},\n {numSplit: 3, name: t('background.grid.n_by_n', {num: 3})},\n {numSplit: 4, name: t('background.grid.n_by_n', {num: 4})},\n {numSplit: 5, name: t('background.grid.n_by_n', {num: 5})},\n {numSplit: 6, name: t('background.grid.n_by_n', {num: 6})}],\n function(d) { return d.name; }\n );\n\n var enter = gridItems.enter()\n .insert('li', '.custom-gridsopt')\n .attr('class', 'gridsopt');\n\n var label = enter.append('label');\n label.append('input')\n .attr('type', 'radio')\n .attr('name', 'grids')\n .property('checked', function(d){\n return (d.numSplit === context.background().numGridSplits());\n })\n .on('change', chooseGrid);\n\n label.append('span')\n .text(function(d) {return d.name;});\n\n gridItems.exit()\n .remove();\n }\n\n\n function gridDisplayOptions(selection) {\n var gridOptionsSection = d3_select('.section-grid-display-options');\n\n context.rapidContext().on('task_extent_set.grid_display_options', function() {\n if (context.rapidContext().isTaskRectangular()) {\n gridOptionsSection.classed('hide', false);\n selection.call(render);\n }\n });\n\n if (!context.rapidContext().isTaskRectangular()){\n gridOptionsSection.classed('hide', true);\n return;\n }\n }\n\n\n return section;\n}\n","\nimport { t } from '../../core/localizer';\nimport { uiPane } from '../pane';\n\nimport { uiSectionBackgroundDisplayOptions } from '../sections/background_display_options';\nimport { uiSectionBackgroundList } from '../sections/background_list';\nimport { uiSectionBackgroundOffset } from '../sections/background_offset';\nimport { uiSectionOverlayList } from '../sections/overlay_list';\nimport { uiSectionGridDisplayOptions } from '../sections/grid_display_options';\nexport function uiPaneBackground(context) {\n\n var backgroundPane = uiPane('background', context)\n .key(t('background.key'))\n .title(t('background.title'))\n .description(t('background.description'))\n .iconName('iD-icon-layers')\n .sections([\n uiSectionBackgroundList(context),\n uiSectionOverlayList(context),\n uiSectionGridDisplayOptions(context),\n uiSectionBackgroundDisplayOptions(context),\n uiSectionBackgroundOffset(context)\n ]);\n\n return backgroundPane;\n}\n","\nimport marked from 'marked';\nimport { svgIcon } from '../../svg/icon';\nimport { uiIntro } from '../intro/intro';\nimport { uiShortcuts } from '../shortcuts';\nimport { uiPane } from '../pane';\n\nimport { t, localizer } from '../../core/localizer';\nimport { uiTooltip } from '../tooltip';\nimport { helpString } from '../intro/helper';\n\nexport function uiPaneHelp(context) {\n\n var docKeys = [\n ['help', [\n 'welcome',\n 'open_data_h',\n 'open_data',\n 'before_start_h',\n 'before_start',\n 'open_source_h',\n 'open_source',\n 'open_source_help'\n ]],\n ['overview', [\n 'navigation_h',\n 'navigation_drag',\n 'navigation_zoom',\n 'features_h',\n 'features',\n 'nodes_ways'\n ]],\n ['editing', [\n 'select_h',\n 'select_left_click',\n 'select_right_click',\n 'select_space',\n 'multiselect_h',\n 'multiselect',\n 'multiselect_shift_click',\n 'multiselect_lasso',\n 'undo_redo_h',\n 'undo_redo',\n 'save_h',\n 'save',\n 'save_validation',\n 'upload_h',\n 'upload',\n 'backups_h',\n 'backups',\n 'keyboard_h',\n 'keyboard'\n ]],\n ['feature_editor', [\n 'intro',\n 'definitions',\n 'type_h',\n 'type',\n 'type_picker',\n 'fields_h',\n 'fields_all_fields',\n 'fields_example',\n 'fields_add_field',\n 'tags_h',\n 'tags_all_tags',\n 'tags_resources'\n ]],\n ['points', [\n 'intro',\n 'add_point_h',\n 'add_point',\n 'add_point_finish',\n 'move_point_h',\n 'move_point',\n 'delete_point_h',\n 'delete_point',\n 'delete_point_command'\n ]],\n ['lines', [\n 'intro',\n 'add_line_h',\n 'add_line',\n 'add_line_draw',\n 'add_line_continue',\n 'add_line_finish',\n 'modify_line_h',\n 'modify_line_dragnode',\n 'modify_line_addnode',\n 'connect_line_h',\n 'connect_line',\n 'connect_line_display',\n 'connect_line_drag',\n 'connect_line_tag',\n 'disconnect_line_h',\n 'disconnect_line_command',\n 'move_line_h',\n 'move_line_command',\n 'move_line_connected',\n 'delete_line_h',\n 'delete_line',\n 'delete_line_command'\n ]],\n ['areas', [\n 'intro',\n 'point_or_area_h',\n 'point_or_area',\n 'add_area_h',\n 'add_area_command',\n 'add_area_draw',\n 'add_area_continue',\n 'add_area_finish',\n 'square_area_h',\n 'square_area_command',\n 'modify_area_h',\n 'modify_area_dragnode',\n 'modify_area_addnode',\n 'delete_area_h',\n 'delete_area',\n 'delete_area_command'\n ]],\n ['relations', [\n 'intro',\n 'edit_relation_h',\n 'edit_relation',\n 'edit_relation_add',\n 'edit_relation_delete',\n 'maintain_relation_h',\n 'maintain_relation',\n 'relation_types_h',\n 'multipolygon_h',\n 'multipolygon',\n 'multipolygon_create',\n 'multipolygon_merge',\n 'turn_restriction_h',\n 'turn_restriction',\n 'turn_restriction_field',\n 'turn_restriction_editing',\n 'route_h',\n 'route',\n 'route_add',\n 'boundary_h',\n 'boundary',\n 'boundary_add'\n ]],\n ['notes', [\n 'intro',\n 'add_note_h',\n 'add_note',\n 'place_note',\n 'move_note',\n 'update_note_h',\n 'update_note',\n 'save_note_h',\n 'save_note'\n ]],\n ['imagery', [\n 'intro',\n 'sources_h',\n 'choosing',\n 'sources',\n 'offsets_h',\n 'offset',\n 'offset_change'\n ]],\n ['streetlevel', [\n 'intro',\n 'using_h',\n 'using',\n 'photos',\n 'viewer'\n ]],\n ['gps', [\n 'intro',\n 'survey',\n 'using_h',\n 'using',\n 'tracing',\n 'upload'\n ]],\n ['qa', [\n 'intro',\n 'tools_h',\n 'tools',\n 'issues_h',\n 'issues'\n ]]\n ];\n\n var headings = {\n 'help.help.open_data_h': 3,\n 'help.help.before_start_h': 3,\n 'help.help.open_source_h': 3,\n 'help.overview.navigation_h': 3,\n 'help.overview.features_h': 3,\n 'help.editing.select_h': 3,\n 'help.editing.multiselect_h': 3,\n 'help.editing.undo_redo_h': 3,\n 'help.editing.save_h': 3,\n 'help.editing.upload_h': 3,\n 'help.editing.backups_h': 3,\n 'help.editing.keyboard_h': 3,\n 'help.feature_editor.type_h': 3,\n 'help.feature_editor.fields_h': 3,\n 'help.feature_editor.tags_h': 3,\n 'help.points.add_point_h': 3,\n 'help.points.move_point_h': 3,\n 'help.points.delete_point_h': 3,\n 'help.lines.add_line_h': 3,\n 'help.lines.modify_line_h': 3,\n 'help.lines.connect_line_h': 3,\n 'help.lines.disconnect_line_h': 3,\n 'help.lines.move_line_h': 3,\n 'help.lines.delete_line_h': 3,\n 'help.areas.point_or_area_h': 3,\n 'help.areas.add_area_h': 3,\n 'help.areas.square_area_h': 3,\n 'help.areas.modify_area_h': 3,\n 'help.areas.delete_area_h': 3,\n 'help.relations.edit_relation_h': 3,\n 'help.relations.maintain_relation_h': 3,\n 'help.relations.relation_types_h': 2,\n 'help.relations.multipolygon_h': 3,\n 'help.relations.turn_restriction_h': 3,\n 'help.relations.route_h': 3,\n 'help.relations.boundary_h': 3,\n 'help.notes.add_note_h': 3,\n 'help.notes.update_note_h': 3,\n 'help.notes.save_note_h': 3,\n 'help.imagery.sources_h': 3,\n 'help.imagery.offsets_h': 3,\n 'help.streetlevel.using_h': 3,\n 'help.gps.using_h': 3,\n 'help.qa.tools_h': 3,\n 'help.qa.issues_h': 3\n };\n\n // For each section, squash all the texts into a single markdown document\n var docs = docKeys.map(function(key) {\n var helpkey = 'help.' + key[0];\n var helpPaneReplacements = { version: context.rapidContext().version };\n var text = key[1].reduce(function(all, part) {\n var subkey = helpkey + '.' + part;\n var depth = headings[subkey]; // is this subkey a heading?\n var hhh = depth ? Array(depth + 1).join('#') + ' ' : ''; // if so, prepend with some ##'s\n return all + hhh + helpString(subkey, helpPaneReplacements) + '\\n\\n';\n }, '');\n\n return {\n title: t(helpkey + '.title'),\n html: marked(text.trim())\n // use keyboard key styling for shortcuts\n .replace(//g, '')\n .replace(/<\\/code>/g, '<\\/kbd>')\n };\n });\n\n var helpPane = uiPane('help', context)\n .key(t('help.key'))\n .title(t('help.title'))\n .description(t('help.title'))\n .iconName('iD-icon-help');\n\n helpPane.renderContent = function(content) {\n\n function clickHelp(d, i) {\n var rtl = (localizer.textDirection() === 'rtl');\n content.property('scrollTop', 0);\n helpPane.selection().select('.pane-heading h2').html(d.title);\n\n body.html(d.html);\n body.selectAll('a')\n .attr('target', '_blank');\n menuItems.classed('selected', function(m) {\n return m.title === d.title;\n });\n\n nav.html('');\n if (rtl) {\n nav.call(drawNext).call(drawPrevious);\n } else {\n nav.call(drawPrevious).call(drawNext);\n }\n\n\n function drawNext(selection) {\n if (i < docs.length - 1) {\n var nextLink = selection\n .append('a')\n .attr('class', 'next')\n .on('click', function() {\n clickHelp(docs[i + 1], i + 1);\n });\n\n nextLink\n .append('span')\n .text(docs[i + 1].title)\n .call(svgIcon((rtl ? '#iD-icon-backward' : '#iD-icon-forward'), 'inline'));\n }\n }\n\n\n function drawPrevious(selection) {\n if (i > 0) {\n var prevLink = selection\n .append('a')\n .attr('class', 'previous')\n .on('click', function() {\n clickHelp(docs[i - 1], i - 1);\n });\n\n prevLink\n .call(svgIcon((rtl ? '#iD-icon-forward' : '#iD-icon-backward'), 'inline'))\n .append('span')\n .text(docs[i - 1].title);\n }\n }\n }\n\n\n function clickWalkthrough() {\n if (context.inIntro()) return;\n context.container().call(uiIntro(context));\n context.ui().togglePanes();\n }\n\n\n function clickShortcuts() {\n context.container().call(uiShortcuts(context), true);\n }\n\n var toc = content\n .append('ul')\n .attr('class', 'toc');\n\n var menuItems = toc.selectAll('li')\n .data(docs)\n .enter()\n .append('li')\n .append('a')\n .html(function(d) { return d.title; })\n .on('click', clickHelp);\n\n var shortcuts = toc\n .append('li')\n .attr('class', 'shortcuts')\n .call(uiTooltip()\n .title(t('shortcuts.tooltip'))\n .keys(['?'])\n .placement('top')\n )\n .append('a')\n .on('click', clickShortcuts);\n\n shortcuts\n .append('div')\n .text(t('shortcuts.title'));\n\n var walkthrough = toc\n .append('li')\n .attr('class', 'walkthrough')\n .append('a')\n .on('click', clickWalkthrough);\n\n walkthrough\n .append('svg')\n .attr('class', 'logo logo-walkthrough')\n .append('use')\n .attr('xlink:href', '#iD-logo-walkthrough');\n\n walkthrough\n .append('div')\n .text(t('splash.walkthrough'));\n\n\n var helpContent = content\n .append('div')\n .attr('class', 'left-content');\n\n var body = helpContent\n .append('div')\n .attr('class', 'body');\n\n var nav = helpContent\n .append('div')\n .attr('class', 'nav');\n\n clickHelp(docs[0], 0);\n\n };\n\n return helpPane;\n}\n","import _debounce from 'lodash-es/debounce';\nimport { event as d3_event, select as d3_select } from 'd3-selection';\n\nimport { actionNoop } from '../../actions/noop';\nimport { geoSphericalDistance } from '../../geo';\nimport { svgIcon } from '../../svg/icon';\nimport { prefs } from '../../core/preferences';\nimport { t } from '../../core/localizer';\nimport { utilHighlightEntities } from '../../util';\nimport { uiSection } from '../section';\n\nexport function uiSectionValidationIssues(id, severity, context) {\n\n var _issues = [];\n\n var section = uiSection(id, context)\n .title(function() {\n if (!_issues) return '';\n var issueCountText = _issues.length > 1000 ? '1000+' : String(_issues.length);\n return t('issues.' + severity + 's.list_title', { count: issueCountText });\n })\n .disclosureContent(renderDisclosureContent)\n .shouldDisplay(function() {\n return _issues && _issues.length;\n });\n\n function getOptions() {\n return {\n what: prefs('validate-what') || 'edited',\n where: prefs('validate-where') || 'all'\n };\n }\n\n // get and cache the issues to display, unordered\n function reloadIssues() {\n _issues = context.validator().getIssuesBySeverity(getOptions())[severity];\n }\n\n function renderDisclosureContent(selection) {\n\n var center = context.map().center();\n var graph = context.graph();\n\n // sort issues by distance away from the center of the map\n var issues = _issues.map(function withDistance(issue) {\n var extent = issue.extent(graph);\n var dist = extent ? geoSphericalDistance(center, extent.center()) : 0;\n return Object.assign(issue, { dist: dist });\n })\n .sort(function byDistance(a, b) {\n return a.dist - b.dist;\n });\n\n // cut off at 1000\n issues = issues.slice(0, 1000);\n\n //renderIgnoredIssuesReset(_warningsSelection);\n\n selection\n .call(drawIssuesList, issues);\n }\n\n function drawIssuesList(selection, issues) {\n const showAutoFix = prefs('rapid-internal-feature.showAutoFix') === 'true';\n\n var list = selection.selectAll('.issues-list')\n .data([0]);\n\n list = list.enter()\n .append('ul')\n .attr('class', 'layer-list issues-list ' + severity + 's-list')\n .merge(list);\n\n\n var items = list.selectAll('li')\n .data(issues, function(d) { return d.id; });\n\n // Exit\n items.exit()\n .remove();\n\n // Enter\n var itemsEnter = items.enter()\n .append('li')\n .attr('class', function (d) { return 'issue severity-' + d.severity; })\n .on('click', function(d) {\n context.validator().focusIssue(d);\n })\n .on('mouseover', function(d) {\n utilHighlightEntities(d.entityIds, true, context);\n })\n .on('mouseout', function(d) {\n utilHighlightEntities(d.entityIds, false, context);\n });\n\n\n var labelsEnter = itemsEnter\n .append('div')\n .attr('class', 'issue-label');\n\n var textEnter = labelsEnter\n .append('span')\n .attr('class', 'issue-text');\n\n textEnter\n .append('span')\n .attr('class', 'issue-icon')\n .each(function(d) {\n var iconName = '#iD-icon-' + (d.severity === 'warning' ? 'alert' : 'error');\n d3_select(this)\n .call(svgIcon(iconName));\n });\n\n textEnter\n .append('span')\n .attr('class', 'issue-message');\n\n if (showAutoFix) {\n labelsEnter\n .append('span')\n .attr('class', 'issue-autofix')\n .each(function(d) {\n if (!d.autoArgs) return;\n\n d3_select(this)\n .append('button')\n .attr('title', t('issues.fix_one.title'))\n .datum(d) // set button datum to the issue\n .attr('class', 'autofix action')\n .on('click', function(d) {\n d3_event.preventDefault();\n d3_event.stopPropagation();\n\n utilHighlightEntities(d.entityIds, false, context); // unhighlight\n context.perform.apply(context, d.autoArgs);\n context.validator().validate();\n })\n .call(svgIcon('#iD-icon-wrench'));\n });\n } /* show autoFix */\n\n // Update\n items = items\n .merge(itemsEnter)\n .order();\n\n items.selectAll('.issue-message')\n .text(function(d) {\n return d.message(context);\n });\n\n var canAutoFix = issues.filter(function(issue) { return issue.autoArgs; });\n var autoFixAll = selection.selectAll('.autofix-all')\n .data(showAutoFix && canAutoFix.length ? [0] : []);\n\n // exit\n autoFixAll.exit()\n .remove();\n\n // enter\n var autoFixAllEnter = autoFixAll.enter()\n .insert('div', '.issues-list')\n .attr('class', 'autofix-all');\n\n var linkEnter = autoFixAllEnter\n .append('a')\n .attr('class', 'autofix-all-link')\n .attr('href', '#');\n\n linkEnter\n .append('span')\n .attr('class', 'autofix-all-link-text')\n .text(t('issues.fix_all.title'));\n\n linkEnter\n .append('span')\n .attr('class', 'autofix-all-link-icon')\n .call(svgIcon('#iD-icon-wrench'));\n\n // if (severity === 'warning') {\n // renderIgnoredIssuesReset(selection);\n // }\n\n // update\n autoFixAll = autoFixAll\n .merge(autoFixAllEnter);\n\n autoFixAll.selectAll('.autofix-all-link')\n .on('click', function() {\n context.pauseChangeDispatch();\n context.perform(actionNoop());\n canAutoFix.forEach(function(issue) {\n var args = issue.autoArgs.slice(); // copy\n if (typeof args[args.length - 1] !== 'function') {\n args.pop();\n }\n args.push(t('issues.fix_all.annotation'));\n context.replace.apply(context, args);\n });\n context.resumeChangeDispatch();\n context.validator().validate();\n });\n }\n\n context.validator().on('validated.uiSectionValidationIssues' + id, function() {\n window.requestIdleCallback(function() {\n reloadIssues();\n section.reRender();\n });\n });\n\n context.map().on('move.uiSectionValidationIssues' + id,\n _debounce(function() {\n window.requestIdleCallback(function() {\n if (getOptions().where === 'visible') {\n // must refetch issues if they are viewport-dependent\n reloadIssues();\n }\n // always reload list to re-sort-by-distance\n section.reRender();\n });\n }, 1000)\n );\n\n return section;\n}\n","import {\n event as d3_event\n} from 'd3-selection';\n\nimport { prefs } from '../../core/preferences';\nimport { t } from '../../core/localizer';\nimport { uiSection } from '../section';\n\nexport function uiSectionValidationOptions(context) {\n\n var section = uiSection('issues-options', context)\n .content(renderContent);\n\n function renderContent(selection) {\n\n var container = selection.selectAll('.issues-options-container')\n .data([0]);\n\n container = container.enter()\n .append('div')\n .attr('class', 'issues-options-container')\n .merge(container);\n\n var data = [\n { key: 'what', values: ['edited', 'all'] },\n { key: 'where', values: ['visible', 'all'] }\n ];\n\n var options = container.selectAll('.issues-option')\n .data(data, function(d) { return d.key; });\n\n var optionsEnter = options.enter()\n .append('div')\n .attr('class', function(d) { return 'issues-option issues-option-' + d.key; });\n\n optionsEnter\n .append('div')\n .attr('class', 'issues-option-title')\n .text(function(d) { return t('issues.options.' + d.key + '.title'); });\n\n var valuesEnter = optionsEnter.selectAll('label')\n .data(function(d) {\n return d.values.map(function(val) { return { value: val, key: d.key }; });\n })\n .enter()\n .append('label');\n\n valuesEnter\n .append('input')\n .attr('type', 'radio')\n .attr('name', function(d) { return 'issues-option-' + d.key; })\n .attr('value', function(d) { return d.value; })\n .property('checked', function(d) { return getOptions()[d.key] === d.value; })\n .on('change', function(d) { updateOptionValue(d.key, d.value); });\n\n valuesEnter\n .append('span')\n .text(function(d) { return t('issues.options.' + d.key + '.' + d.value); });\n }\n\n function getOptions() {\n return {\n what: prefs('validate-what') || 'edited', // 'all', 'edited'\n where: prefs('validate-where') || 'all' // 'all', 'visible'\n };\n }\n\n function updateOptionValue(d, val) {\n if (!val && d3_event && d3_event.target) {\n val = d3_event.target.value;\n }\n\n prefs('validate-' + d, val);\n context.validator().validate();\n }\n\n return section;\n}\n","import {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { prefs } from '../../core/preferences';\nimport { t } from '../../core/localizer';\nimport { utilGetSetValue, utilNoAuto } from '../../util';\nimport { uiTooltip } from '../tooltip';\nimport { uiSection } from '../section';\n\nexport function uiSectionValidationRules(context) {\n\n var MINSQUARE = 0;\n var MAXSQUARE = 20;\n var DEFAULTSQUARE = 5; // see also unsquare_way.js\n\n var section = uiSection('issues-rules', context)\n .disclosureContent(renderDisclosureContent)\n .title(t('issues.rules.title'));\n\n var _ruleKeys = context.validator().getRuleKeys()\n .filter(function(key) { return key !== 'maprules'; })\n .sort(function(key1, key2) {\n // alphabetize by localized title\n return t('issues.' + key1 + '.title') < t('issues.' + key2 + '.title') ? -1 : 1;\n });\n\n function renderDisclosureContent(selection) {\n var container = selection.selectAll('.issues-rulelist-container')\n .data([0]);\n\n var containerEnter = container.enter()\n .append('div')\n .attr('class', 'issues-rulelist-container');\n\n containerEnter\n .append('ul')\n .attr('class', 'layer-list issue-rules-list');\n\n var ruleLinks = containerEnter\n .append('div')\n .attr('class', 'issue-rules-links section-footer');\n\n ruleLinks\n .append('a')\n .attr('class', 'issue-rules-link')\n .attr('href', '#')\n .text(t('issues.enable_all'))\n .on('click', function() {\n context.validator().disableRules([]);\n });\n\n ruleLinks\n .append('a')\n .attr('class', 'issue-rules-link')\n .attr('href', '#')\n .text(t('issues.disable_all'))\n .on('click', function() {\n context.validator().disableRules(_ruleKeys);\n });\n\n\n // Update\n container = container\n .merge(containerEnter);\n\n container.selectAll('.issue-rules-list')\n .call(drawListItems, _ruleKeys, 'checkbox', 'rule', toggleRule, isRuleEnabled);\n }\n\n function drawListItems(selection, data, type, name, change, active) {\n var items = selection.selectAll('li')\n .data(data);\n\n // Exit\n items.exit()\n .remove();\n\n // Enter\n var enter = items.enter()\n .append('li');\n\n if (name === 'rule') {\n enter\n .call(uiTooltip()\n .title(function(d) { return t('issues.' + d + '.tip'); })\n .placement('top')\n );\n }\n\n var label = enter\n .append('label');\n\n label\n .append('input')\n .attr('type', type)\n .attr('name', name)\n .on('change', change);\n\n label\n .append('span')\n .html(function(d) {\n var params = {};\n if (d === 'unsquare_way') {\n params.val = ' ';\n }\n return t('issues.' + d + '.title', params);\n });\n\n // Update\n items = items\n .merge(enter);\n\n items\n .classed('active', active)\n .selectAll('input')\n .property('checked', active)\n .property('indeterminate', false);\n\n\n // user-configurable square threshold\n var degStr = prefs('validate-square-degrees');\n if (degStr === null) {\n degStr = '' + DEFAULTSQUARE;\n }\n\n var span = items.selectAll('.square-degrees');\n var input = span.selectAll('.square-degrees-input')\n .data([0]);\n\n // enter / update\n input.enter()\n .append('input')\n .attr('type', 'number')\n .attr('min', '' + MINSQUARE)\n .attr('max', '' + MAXSQUARE)\n .attr('step', '0.5')\n .attr('class', 'square-degrees-input')\n .call(utilNoAuto)\n .on('click', function () {\n d3_event.preventDefault();\n d3_event.stopPropagation();\n this.select();\n })\n .on('keyup', function () {\n if (d3_event.keyCode === 13) { // enter\n this.blur();\n this.select();\n }\n })\n .on('blur', changeSquare)\n .merge(input)\n .property('value', degStr);\n }\n\n function changeSquare() {\n var input = d3_select(this);\n var degStr = utilGetSetValue(input).trim();\n var degNum = parseFloat(degStr, 10);\n\n if (!isFinite(degNum)) {\n degNum = DEFAULTSQUARE;\n } else if (degNum > MAXSQUARE) {\n degNum = MAXSQUARE;\n } else if (degNum < MINSQUARE) {\n degNum = MINSQUARE;\n }\n\n degNum = Math.round(degNum * 10 ) / 10; // round to 1 decimal\n degStr = '' + degNum;\n\n input\n .property('value', degStr);\n\n prefs('validate-square-degrees', degStr);\n context.validator().reloadUnsquareIssues();\n }\n\n function isRuleEnabled(d) {\n return context.validator().isRuleEnabled(d);\n }\n\n function toggleRule(d) {\n context.validator().toggleRule(d);\n }\n\n context.validator().on('validated.uiSectionValidationRules', function() {\n window.requestIdleCallback(section.reRender);\n });\n\n return section;\n}\n","import _debounce from 'lodash-es/debounce';\n\nimport { svgIcon } from '../../svg/icon';\nimport { prefs } from '../../core/preferences';\nimport { t } from '../../core/localizer';\nimport { uiSection } from '../section';\n\nexport function uiSectionValidationStatus(context) {\n\n var section = uiSection('issues-status', context)\n .content(renderContent)\n .shouldDisplay(function() {\n var issues = context.validator().getIssues(getOptions());\n return issues.length === 0;\n });\n\n function getOptions() {\n return {\n what: prefs('validate-what') || 'edited',\n where: prefs('validate-where') || 'all'\n };\n }\n\n function renderContent(selection) {\n\n var box = selection.selectAll('.box')\n .data([0]);\n\n var boxEnter = box.enter()\n .append('div')\n .attr('class', 'box');\n\n boxEnter\n .append('div')\n .call(svgIcon('#iD-icon-apply', 'pre-text'));\n\n var noIssuesMessage = boxEnter\n .append('span');\n\n noIssuesMessage\n .append('strong')\n .attr('class', 'message');\n\n noIssuesMessage\n .append('br');\n\n noIssuesMessage\n .append('span')\n .attr('class', 'details');\n\n renderIgnoredIssuesReset(selection);\n setNoIssuesText(selection);\n }\n\n function renderIgnoredIssuesReset(selection) {\n\n var ignoredIssues = context.validator()\n .getIssues({ what: 'all', where: 'all', includeDisabledRules: true, includeIgnored: 'only' });\n\n var resetIgnored = selection.selectAll('.reset-ignored')\n .data(ignoredIssues.length ? [0] : []);\n\n // exit\n resetIgnored.exit()\n .remove();\n\n // enter\n var resetIgnoredEnter = resetIgnored.enter()\n .append('div')\n .attr('class', 'reset-ignored section-footer');\n\n resetIgnoredEnter\n .append('a')\n .attr('href', '#');\n\n // update\n resetIgnored = resetIgnored\n .merge(resetIgnoredEnter);\n\n resetIgnored.select('a')\n .text(t('issues.reset_ignored', { count: ignoredIssues.length.toString() }));\n\n resetIgnored.on('click', function() {\n context.validator().resetIgnoredIssues();\n });\n }\n\n function setNoIssuesText(selection) {\n\n var opts = getOptions();\n\n function checkForHiddenIssues(cases) {\n for (var type in cases) {\n var hiddenOpts = cases[type];\n var hiddenIssues = context.validator().getIssues(hiddenOpts);\n if (hiddenIssues.length) {\n selection.select('.box .details')\n .text(t(\n 'issues.no_issues.hidden_issues.' + type,\n { count: hiddenIssues.length.toString() }\n ));\n return;\n }\n }\n selection.select('.box .details')\n .text(t('issues.no_issues.hidden_issues.none'));\n }\n\n var messageType;\n\n if (opts.what === 'edited' && opts.where === 'visible') {\n\n messageType = 'edits_in_view';\n\n checkForHiddenIssues({\n elsewhere: { what: 'edited', where: 'all' },\n everything_else: { what: 'all', where: 'visible' },\n disabled_rules: { what: 'edited', where: 'visible', includeDisabledRules: 'only' },\n everything_else_elsewhere: { what: 'all', where: 'all' },\n disabled_rules_elsewhere: { what: 'edited', where: 'all', includeDisabledRules: 'only' },\n ignored_issues: { what: 'edited', where: 'visible', includeIgnored: 'only' },\n ignored_issues_elsewhere: { what: 'edited', where: 'all', includeIgnored: 'only' }\n });\n\n } else if (opts.what === 'edited' && opts.where === 'all') {\n\n messageType = 'edits';\n\n checkForHiddenIssues({\n everything_else: { what: 'all', where: 'all' },\n disabled_rules: { what: 'edited', where: 'all', includeDisabledRules: 'only' },\n ignored_issues: { what: 'edited', where: 'all', includeIgnored: 'only' }\n });\n\n } else if (opts.what === 'all' && opts.where === 'visible') {\n\n messageType = 'everything_in_view';\n\n checkForHiddenIssues({\n elsewhere: { what: 'all', where: 'all' },\n disabled_rules: { what: 'all', where: 'visible', includeDisabledRules: 'only' },\n disabled_rules_elsewhere: { what: 'all', where: 'all', includeDisabledRules: 'only' },\n ignored_issues: { what: 'all', where: 'visible', includeIgnored: 'only' },\n ignored_issues_elsewhere: { what: 'all', where: 'all', includeIgnored: 'only' }\n });\n } else if (opts.what === 'all' && opts.where === 'all') {\n\n messageType = 'everything';\n\n checkForHiddenIssues({\n disabled_rules: { what: 'all', where: 'all', includeDisabledRules: 'only' },\n ignored_issues: { what: 'all', where: 'all', includeIgnored: 'only' }\n });\n }\n\n if (opts.what === 'edited' && context.history().difference().summary().length === 0) {\n messageType = 'no_edits';\n }\n\n selection.select('.box .message')\n .text(t('issues.no_issues.message.' + messageType));\n\n }\n\n context.validator().on('validated.uiSectionValidationStatus', function() {\n window.requestIdleCallback(section.reRender);\n });\n\n context.map().on('move.uiSectionValidationStatus',\n _debounce(function() {\n window.requestIdleCallback(section.reRender);\n }, 1000)\n );\n\n return section;\n}\n","\nimport { t } from '../../core/localizer';\nimport { uiPane } from '../pane';\n\nimport { uiSectionValidationIssues } from '../sections/validation_issues';\nimport { uiSectionValidationOptions } from '../sections/validation_options';\nimport { uiSectionValidationRules } from '../sections/validation_rules';\nimport { uiSectionValidationStatus } from '../sections/validation_status';\n\nexport function uiPaneIssues(context) {\n\n var issuesPane = uiPane('issues', context)\n .key(t('issues.key'))\n .title(t('issues.title'))\n .description(t('issues.title'))\n .iconName('iD-icon-alert')\n .sections([\n uiSectionValidationOptions(context),\n uiSectionValidationStatus(context),\n uiSectionValidationIssues('issues-errors', 'error', context),\n uiSectionValidationIssues('issues-warnings', 'warning', context),\n uiSectionValidationRules(context)\n ]);\n\n return issuesPane;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { event as d3_event } from 'd3-selection';\n\nimport { prefs } from '../../core/preferences';\nimport { t } from '../../core/localizer';\nimport { uiConfirm } from '../confirm';\nimport { utilNoAuto, utilRebind } from '../../util';\n\n\nexport function uiSettingsCustomData(context) {\n var dispatch = d3_dispatch('change');\n\n function render(selection) {\n var dataLayer = context.layers().layer('data');\n\n // keep separate copies of original and current settings\n var _origSettings = {\n fileList: (dataLayer && dataLayer.fileList()) || null,\n url: prefs('settings-custom-data-url')\n };\n var _currSettings = {\n fileList: (dataLayer && dataLayer.fileList()) || null,\n url: prefs('settings-custom-data-url')\n };\n\n // var example = 'https://{switch:a,b,c}.tile.openstreetmap.org/{zoom}/{x}/{y}.png';\n var modal = uiConfirm(selection).okButton();\n\n modal\n .classed('settings-modal settings-custom-data', true);\n\n modal.select('.modal-section.header')\n .append('h3')\n .text(t('settings.custom_data.header'));\n\n\n var textSection = modal.select('.modal-section.message-text');\n\n textSection\n .append('pre')\n .attr('class', 'instructions-file')\n .text(t('settings.custom_data.file.instructions'));\n\n textSection\n .append('input')\n .attr('class', 'field-file')\n .attr('type', 'file')\n .property('files', _currSettings.fileList) // works for all except IE11\n .on('change', function() {\n var files = d3_event.target.files;\n if (files && files.length) {\n _currSettings.url = '';\n textSection.select('.field-url').property('value', '');\n _currSettings.fileList = files;\n } else {\n _currSettings.fileList = null;\n }\n });\n\n textSection\n .append('h4')\n .text(t('settings.custom_data.or'));\n\n textSection\n .append('pre')\n .attr('class', 'instructions-url')\n .text(t('settings.custom_data.url.instructions'));\n\n textSection\n .append('textarea')\n .attr('class', 'field-url')\n .attr('placeholder', t('settings.custom_data.url.placeholder'))\n .call(utilNoAuto)\n .property('value', _currSettings.url);\n\n\n // insert a cancel button\n var buttonSection = modal.select('.modal-section.buttons');\n\n buttonSection\n .insert('button', '.ok-button')\n .attr('class', 'button cancel-button secondary-action')\n .text(t('confirm.cancel'));\n\n\n buttonSection.select('.cancel-button')\n .on('click.cancel', clickCancel);\n\n buttonSection.select('.ok-button')\n .attr('disabled', isSaveDisabled)\n .on('click.save', clickSave);\n\n\n function isSaveDisabled() {\n return null;\n }\n\n\n // restore the original url\n function clickCancel() {\n textSection.select('.field-url').property('value', _origSettings.url);\n prefs('settings-custom-data-url', _origSettings.url);\n this.blur();\n modal.close();\n }\n\n // accept the current url\n function clickSave() {\n _currSettings.url = textSection.select('.field-url').property('value').trim();\n\n // one or the other but not both\n if (_currSettings.url) { _currSettings.fileList = null; }\n if (_currSettings.fileList) { _currSettings.url = ''; }\n\n prefs('settings-custom-data-url', _currSettings.url);\n this.blur();\n modal.close();\n dispatch.call('change', this, _currSettings);\n }\n }\n\n return utilRebind(render, dispatch, 'on');\n}\n","import _debounce from 'lodash-es/debounce';\nimport {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport { prefs } from '../../core/preferences';\nimport { t, localizer } from '../../core/localizer';\nimport { uiTooltip } from '../tooltip';\nimport { svgIcon } from '../../svg/icon';\nimport { geoExtent } from '../../geo';\nimport { modeBrowse } from '../../modes/browse';\nimport { uiCmd } from '../cmd';\nimport { uiSection } from '../section';\nimport { uiSettingsCustomData } from '../settings/custom_data';\n\nexport function uiSectionDataLayers(context) {\n\n var settingsCustomData = uiSettingsCustomData(context)\n .on('change', customChanged);\n\n var layers = context.layers();\n\n var section = uiSection('data-layers', context)\n .title(t('map_data.data_layers'))\n .disclosureContent(renderDisclosureContent);\n\n function renderDisclosureContent(selection) {\n var container = selection.selectAll('.data-layer-container')\n .data([0]);\n\n container.enter()\n .append('div')\n .attr('class', 'data-layer-container')\n .merge(container)\n .call(drawOsmItems)\n .call(drawQAItems)\n .call(drawCustomDataItems)\n .call(drawVectorItems) // Beta - Detroit mapping challenge\n .call(drawPanelItems);\n }\n\n function showsLayer(which) {\n var layer = layers.layer(which);\n if (layer) {\n return layer.enabled();\n }\n return false;\n }\n\n function setLayer(which, enabled) {\n // Don't allow layer changes while drawing - #6584\n var mode = context.mode();\n if (mode && /^draw/.test(mode.id)) return;\n\n var layer = layers.layer(which);\n if (layer) {\n layer.enabled(enabled);\n\n if (!enabled && (which === 'osm' || which === 'notes')) {\n context.enter(modeBrowse(context));\n }\n }\n }\n\n function toggleLayer(which) {\n setLayer(which, !showsLayer(which));\n }\n\n function drawOsmItems(selection) {\n var osmKeys = ['osm', 'notes'];\n var osmLayers = layers.all().filter(function(obj) { return osmKeys.indexOf(obj.id) !== -1; });\n\n var ul = selection\n .selectAll('.layer-list-osm')\n .data([0]);\n\n ul = ul.enter()\n .append('ul')\n .attr('class', 'layer-list layer-list-osm')\n .merge(ul);\n\n var li = ul.selectAll('.list-item')\n .data(osmLayers);\n\n li.exit()\n .remove();\n\n var liEnter = li.enter()\n .append('li')\n .attr('class', function(d) { return 'list-item list-item-' + d.id; });\n\n var labelEnter = liEnter\n .append('label')\n .each(function(d) {\n if (d.id === 'osm') {\n d3_select(this)\n .call(uiTooltip()\n .title(t('map_data.layers.' + d.id + '.tooltip'))\n .keys([uiCmd('⌥' + t('area_fill.wireframe.key'))])\n .placement('bottom')\n );\n } else {\n d3_select(this)\n .call(uiTooltip()\n .title(t('map_data.layers.' + d.id + '.tooltip'))\n .placement('bottom')\n );\n }\n });\n\n labelEnter\n .append('input')\n .attr('type', 'checkbox')\n .on('change', function(d) { toggleLayer(d.id); });\n\n labelEnter\n .append('span')\n .text(function(d) { return t('map_data.layers.' + d.id + '.title'); });\n\n\n // Update\n li\n .merge(liEnter)\n .classed('active', function (d) { return d.layer.enabled(); })\n .selectAll('input')\n .property('checked', function (d) { return d.layer.enabled(); });\n }\n\n function drawQAItems(selection) {\n var qaKeys = ['keepRight', 'improveOSM', 'osmose'];\n var qaLayers = layers.all().filter(function(obj) { return qaKeys.indexOf(obj.id) !== -1; });\n\n var ul = selection\n .selectAll('.layer-list-qa')\n .data([0]);\n\n ul = ul.enter()\n .append('ul')\n .attr('class', 'layer-list layer-list-qa')\n .merge(ul);\n\n var li = ul.selectAll('.list-item')\n .data(qaLayers);\n\n li.exit()\n .remove();\n\n var liEnter = li.enter()\n .append('li')\n .attr('class', function(d) { return 'list-item list-item-' + d.id; });\n\n var labelEnter = liEnter\n .append('label')\n .each(function(d) {\n d3_select(this)\n .call(uiTooltip()\n .title(t('map_data.layers.' + d.id + '.tooltip'))\n .placement('bottom')\n );\n });\n\n labelEnter\n .append('input')\n .attr('type', 'checkbox')\n .on('change', function(d) { toggleLayer(d.id); });\n\n labelEnter\n .append('span')\n .text(function(d) { return t('map_data.layers.' + d.id + '.title'); });\n\n\n // Update\n li\n .merge(liEnter)\n .classed('active', function (d) { return d.layer.enabled(); })\n .selectAll('input')\n .property('checked', function (d) { return d.layer.enabled(); });\n }\n\n // Beta feature - sample vector layers to support Detroit Mapping Challenge\n // https://github.com/osmus/detroit-mapping-challenge\n function drawVectorItems(selection) {\n var dataLayer = layers.layer('data');\n var vtData = [\n {\n name: 'Detroit Neighborhoods/Parks',\n src: 'neighborhoods-parks',\n tooltip: 'Neighborhood boundaries and parks as compiled by City of Detroit in concert with community groups.',\n template: 'https://{switch:a,b,c,d}.tiles.mapbox.com/v4/jonahadkins.cjksmur6x34562qp9iv1u3ksf-54hev,jonahadkins.cjksmqxdx33jj2wp90xd9x2md-4e5y2/{z}/{x}/{y}.vector.pbf?access_token=pk.eyJ1Ijoiam9uYWhhZGtpbnMiLCJhIjoiRlVVVkx3VSJ9.9sdVEK_B_VkEXPjssU5MqA'\n }, {\n name: 'Detroit Composite POIs',\n src: 'composite-poi',\n tooltip: 'Fire Inspections, Business Licenses, and other public location data collated from the City of Detroit.',\n template: 'https://{switch:a,b,c,d}.tiles.mapbox.com/v4/jonahadkins.cjksmm6a02sli31myxhsr7zf3-2sw8h/{z}/{x}/{y}.vector.pbf?access_token=pk.eyJ1Ijoiam9uYWhhZGtpbnMiLCJhIjoiRlVVVkx3VSJ9.9sdVEK_B_VkEXPjssU5MqA'\n }, {\n name: 'Detroit All-The-Places POIs',\n src: 'alltheplaces-poi',\n tooltip: 'Public domain business location data created by web scrapers.',\n template: 'https://{switch:a,b,c,d}.tiles.mapbox.com/v4/jonahadkins.cjksmswgk340g2vo06p1w9w0j-8fjjc/{z}/{x}/{y}.vector.pbf?access_token=pk.eyJ1Ijoiam9uYWhhZGtpbnMiLCJhIjoiRlVVVkx3VSJ9.9sdVEK_B_VkEXPjssU5MqA'\n }\n ];\n\n // Only show this if the map is around Detroit..\n var detroit = geoExtent([-83.5, 42.1], [-82.8, 42.5]);\n var showVectorItems = (context.map().zoom() > 9 && detroit.contains(context.map().center()));\n\n var container = selection.selectAll('.vectortile-container')\n .data(showVectorItems ? [0] : []);\n\n container.exit()\n .remove();\n\n var containerEnter = container.enter()\n .append('div')\n .attr('class', 'vectortile-container');\n\n containerEnter\n .append('h4')\n .attr('class', 'vectortile-header')\n .text('Detroit Vector Tiles (Beta)');\n\n containerEnter\n .append('ul')\n .attr('class', 'layer-list layer-list-vectortile');\n\n containerEnter\n .append('div')\n .attr('class', 'vectortile-footer')\n .append('a')\n .attr('target', '_blank')\n .attr('tabindex', -1)\n .call(svgIcon('#iD-icon-out-link', 'inline'))\n .attr('href', 'https://github.com/osmus/detroit-mapping-challenge')\n .append('span')\n .text('About these layers');\n\n container = container\n .merge(containerEnter);\n\n\n var ul = container.selectAll('.layer-list-vectortile');\n\n var li = ul.selectAll('.list-item')\n .data(vtData);\n\n li.exit()\n .remove();\n\n var liEnter = li.enter()\n .append('li')\n .attr('class', function(d) { return 'list-item list-item-' + d.src; });\n\n var labelEnter = liEnter\n .append('label')\n .each(function(d) {\n d3_select(this).call(\n uiTooltip().title(d.tooltip).placement('top')\n );\n });\n\n labelEnter\n .append('input')\n .attr('type', 'radio')\n .attr('name', 'vectortile')\n .on('change', selectVTLayer);\n\n labelEnter\n .append('span')\n .text(function(d) { return d.name; });\n\n // Update\n li\n .merge(liEnter)\n .classed('active', isVTLayerSelected)\n .selectAll('input')\n .property('checked', isVTLayerSelected);\n\n\n function isVTLayerSelected(d) {\n return dataLayer && dataLayer.template() === d.template;\n }\n\n function selectVTLayer(d) {\n prefs('settings-custom-data-url', d.template);\n if (dataLayer) {\n dataLayer.template(d.template, d.src);\n dataLayer.enabled(true);\n }\n }\n }\n\n function drawCustomDataItems(selection) {\n var dataLayer = layers.layer('data');\n var hasData = dataLayer && dataLayer.hasData();\n var showsData = hasData && dataLayer.enabled();\n\n var ul = selection\n .selectAll('.layer-list-data')\n .data(dataLayer ? [0] : []);\n\n // Exit\n ul.exit()\n .remove();\n\n // Enter\n var ulEnter = ul.enter()\n .append('ul')\n .attr('class', 'layer-list layer-list-data');\n\n var liEnter = ulEnter\n .append('li')\n .attr('class', 'list-item-data');\n\n var labelEnter = liEnter\n .append('label')\n .call(uiTooltip()\n .title(t('map_data.layers.custom.tooltip'))\n .placement('top')\n );\n\n labelEnter\n .append('input')\n .attr('type', 'checkbox')\n .on('change', function() { toggleLayer('data'); });\n\n labelEnter\n .append('span')\n .text(t('map_data.layers.custom.title'));\n\n liEnter\n .append('button')\n .call(uiTooltip()\n .title(t('settings.custom_data.tooltip'))\n .placement((localizer.textDirection() === 'rtl') ? 'right' : 'left')\n )\n .on('click', editCustom)\n .call(svgIcon('#iD-icon-more'));\n\n liEnter\n .append('button')\n .call(uiTooltip()\n .title(t('map_data.layers.custom.zoom'))\n .placement((localizer.textDirection() === 'rtl') ? 'right' : 'left')\n )\n .on('click', function() {\n d3_event.preventDefault();\n d3_event.stopPropagation();\n dataLayer.fitZoom();\n })\n .call(svgIcon('#iD-icon-framed-dot'));\n\n // Update\n ul = ul\n .merge(ulEnter);\n\n ul.selectAll('.list-item-data')\n .classed('active', showsData)\n .selectAll('label')\n .classed('deemphasize', !hasData)\n .selectAll('input')\n .property('disabled', !hasData)\n .property('checked', showsData);\n }\n\n function editCustom() {\n d3_event.preventDefault();\n context.container()\n .call(settingsCustomData);\n }\n\n function customChanged(d) {\n var dataLayer = layers.layer('data');\n\n if (d && d.url) {\n dataLayer.url(d.url);\n } else if (d && d.fileList) {\n dataLayer.fileList(d.fileList);\n }\n }\n\n\n function drawPanelItems(selection) {\n\n var panelsListEnter = selection.selectAll('.md-extras-list')\n .data([0])\n .enter()\n .append('ul')\n .attr('class', 'layer-list md-extras-list');\n\n var historyPanelLabelEnter = panelsListEnter\n .append('li')\n .attr('class', 'history-panel-toggle-item')\n .append('label')\n .call(uiTooltip()\n .title(t('map_data.history_panel.tooltip'))\n .keys([uiCmd('⌘⇧' + t('info_panels.history.key'))])\n .placement('top')\n );\n\n historyPanelLabelEnter\n .append('input')\n .attr('type', 'checkbox')\n .on('change', function() {\n d3_event.preventDefault();\n context.ui().info.toggle('history');\n });\n\n historyPanelLabelEnter\n .append('span')\n .text(t('map_data.history_panel.title'));\n\n var measurementPanelLabelEnter = panelsListEnter\n .append('li')\n .attr('class', 'measurement-panel-toggle-item')\n .append('label')\n .call(uiTooltip()\n .title(t('map_data.measurement_panel.tooltip'))\n .keys([uiCmd('⌘⇧' + t('info_panels.measurement.key'))])\n .placement('top')\n );\n\n measurementPanelLabelEnter\n .append('input')\n .attr('type', 'checkbox')\n .on('change', function() {\n d3_event.preventDefault();\n context.ui().info.toggle('measurement');\n });\n\n measurementPanelLabelEnter\n .append('span')\n .text(t('map_data.measurement_panel.title'));\n }\n\n context.layers().on('change.uiSectionDataLayers', section.reRender);\n\n context.map()\n .on('move.uiSectionDataLayers',\n _debounce(function() {\n // Detroit layers may have moved in or out of view\n window.requestIdleCallback(section.reRender);\n }, 1000)\n );\n\n return section;\n}\n","import { t } from '../../core/localizer';\nimport { uiTooltip } from '../tooltip';\nimport { uiSection } from '../section';\n\nexport function uiSectionMapFeatures(context) {\n\n var _features = context.features().keys();\n\n var section = uiSection('map-features', context)\n .title(t('map_data.map_features'))\n .disclosureContent(renderDisclosureContent)\n .expandedByDefault(false);\n\n function renderDisclosureContent(selection) {\n\n var container = selection.selectAll('.layer-feature-list-container')\n .data([0]);\n\n var containerEnter = container.enter()\n .append('div')\n .attr('class', 'layer-feature-list-container');\n\n containerEnter\n .append('ul')\n .attr('class', 'layer-list layer-feature-list');\n\n var footer = containerEnter\n .append('div')\n .attr('class', 'feature-list-links section-footer');\n\n footer\n .append('a')\n .attr('class', 'feature-list-link')\n .attr('href', '#')\n .text(t('issues.enable_all'))\n .on('click', function() {\n context.features().enableAll();\n });\n\n footer\n .append('a')\n .attr('class', 'feature-list-link')\n .attr('href', '#')\n .text(t('issues.disable_all'))\n .on('click', function() {\n context.features().disableAll();\n });\n\n // Update\n container = container\n .merge(containerEnter);\n\n container.selectAll('.layer-feature-list')\n .call(drawListItems, _features, 'checkbox', 'feature', clickFeature, showsFeature);\n }\n\n function drawListItems(selection, data, type, name, change, active) {\n var items = selection.selectAll('li')\n .data(data);\n\n // Exit\n items.exit()\n .remove();\n\n // Enter\n var enter = items.enter()\n .append('li')\n .call(uiTooltip()\n .title(function(d) {\n var tip = t(name + '.' + d + '.tooltip');\n if (autoHiddenFeature(d)) {\n var msg = showsLayer('osm') ? t('map_data.autohidden') : t('map_data.osmhidden');\n tip += '' + msg + '
';\n }\n return tip;\n })\n .placement('top')\n );\n\n var label = enter\n .append('label');\n\n label\n .append('input')\n .attr('type', type)\n .attr('name', name)\n .on('change', change);\n\n label\n .append('span')\n .text(function(d) { return t(name + '.' + d + '.description'); });\n\n // Update\n items = items\n .merge(enter);\n\n items\n .classed('active', active)\n .selectAll('input')\n .property('checked', active)\n .property('indeterminate', autoHiddenFeature);\n }\n\n function autoHiddenFeature(d) {\n return context.features().autoHidden(d);\n }\n\n function showsFeature(d) {\n return context.features().enabled(d);\n }\n\n function clickFeature(d) {\n context.features().toggle(d);\n }\n\n function showsLayer(id) {\n var layer = context.layers().layer(id);\n return layer && layer.enabled();\n }\n\n // add listeners\n context.features()\n .on('change.map_features', section.reRender);\n\n return section;\n}\n","import {\n event as d3_event\n} from 'd3-selection';\n\nimport { t } from '../../core/localizer';\nimport { uiTooltip } from '../tooltip';\nimport { uiSection } from '../section';\n\nexport function uiSectionMapStyleOptions(context) {\n\n var section = uiSection('fill-area', context)\n .title(t('map_data.style_options'))\n .disclosureContent(renderDisclosureContent)\n .expandedByDefault(false);\n\n function renderDisclosureContent(selection) {\n var container = selection.selectAll('.layer-fill-list')\n .data([0]);\n\n container.enter()\n .append('ul')\n .attr('class', 'layer-list layer-fill-list')\n .merge(container)\n .call(drawListItems, context.map().areaFillOptions, 'radio', 'area_fill', setFill, isActiveFill);\n\n var container2 = selection.selectAll('.layer-visual-diff-list')\n .data([0]);\n\n container2.enter()\n .append('ul')\n .attr('class', 'layer-list layer-visual-diff-list')\n .merge(container2)\n .call(drawListItems, ['highlight_edits'], 'checkbox', 'visual_diff', toggleHighlightEdited, function() {\n return context.surface().classed('highlight-edited');\n });\n }\n\n function drawListItems(selection, data, type, name, change, active) {\n var items = selection.selectAll('li')\n .data(data);\n\n // Exit\n items.exit()\n .remove();\n\n // Enter\n var enter = items.enter()\n .append('li')\n .call(uiTooltip()\n .title(function(d) {\n return t(name + '.' + d + '.tooltip');\n })\n .keys(function(d) {\n var key = (d === 'wireframe' ? t('area_fill.wireframe.key') : null);\n if (d === 'highlight_edits') key = t('map_data.highlight_edits.key');\n return key ? [key] : null;\n })\n .placement('top')\n );\n\n var label = enter\n .append('label');\n\n label\n .append('input')\n .attr('type', type)\n .attr('name', name)\n .on('change', change);\n\n label\n .append('span')\n .text(function(d) { return t(name + '.' + d + '.description'); });\n\n // Update\n items = items\n .merge(enter);\n\n items\n .classed('active', active)\n .selectAll('input')\n .property('checked', active)\n .property('indeterminate', false);\n }\n\n function isActiveFill(d) {\n return context.map().activeAreaFill() === d;\n }\n\n function toggleHighlightEdited() {\n d3_event.preventDefault();\n context.map().toggleHighlightEdited();\n }\n\n function setFill(d) {\n context.map().activeAreaFill(d);\n }\n\n context.map()\n .on('changeHighlighting.ui_style, changeAreaFill.ui_style', section.reRender);\n\n return section;\n}\n","import {\n select as d3_select\n} from 'd3-selection';\n\nimport { t } from '../../core/localizer';\nimport { uiTooltip } from '../tooltip';\nimport { uiSection } from '../section';\n\nexport function uiSectionPhotoOverlays(context) {\n\n var layers = context.layers();\n\n var section = uiSection('photo-overlays', context)\n .title(t('photo_overlays.title'))\n .disclosureContent(renderDisclosureContent)\n .expandedByDefault(false);\n\n function renderDisclosureContent(selection) {\n var container = selection.selectAll('.photo-overlay-container')\n .data([0]);\n\n container.enter()\n .append('div')\n .attr('class', 'photo-overlay-container')\n .merge(container)\n .call(drawPhotoItems)\n .call(drawPhotoTypeItems);\n }\n\n function drawPhotoItems(selection) {\n var photoKeys = context.photos().overlayLayerIDs();\n var photoLayers = layers.all().filter(function(obj) { return photoKeys.indexOf(obj.id) !== -1; });\n var data = photoLayers.filter(function(obj) { return obj.layer.supported(); });\n\n function layerSupported(d) {\n return d.layer && d.layer.supported();\n }\n function layerEnabled(d) {\n return layerSupported(d) && d.layer.enabled();\n }\n\n var ul = selection\n .selectAll('.layer-list-photos')\n .data([0]);\n\n ul = ul.enter()\n .append('ul')\n .attr('class', 'layer-list layer-list-photos')\n .merge(ul);\n\n var li = ul.selectAll('.list-item-photos')\n .data(data);\n\n li.exit()\n .remove();\n\n var liEnter = li.enter()\n .append('li')\n .attr('class', function(d) {\n var classes = 'list-item-photos list-item-' + d.id;\n if (d.id === 'mapillary-signs' || d.id === 'mapillary-map-features') {\n classes += ' indented';\n }\n return classes;\n });\n\n var labelEnter = liEnter\n .append('label')\n .each(function(d) {\n var titleID;\n if (d.id === 'mapillary-signs') titleID = 'mapillary.signs.tooltip';\n else if (d.id === 'mapillary') titleID = 'mapillary_images.tooltip';\n else if (d.id === 'openstreetcam') titleID = 'openstreetcam_images.tooltip';\n else titleID = d.id.replace(/-/g, '_') + '.tooltip';\n d3_select(this)\n .call(uiTooltip()\n .title(t(titleID))\n .placement('top')\n );\n });\n\n labelEnter\n .append('input')\n .attr('type', 'checkbox')\n .on('change', function(d) { toggleLayer(d.id); });\n\n labelEnter\n .append('span')\n .text(function(d) {\n var id = d.id;\n if (id === 'mapillary-signs') id = 'photo_overlays.traffic_signs';\n return t(id.replace(/-/g, '_') + '.title');\n });\n\n\n // Update\n li\n .merge(liEnter)\n .classed('active', layerEnabled)\n .selectAll('input')\n .property('checked', layerEnabled);\n }\n\n function drawPhotoTypeItems(selection) {\n var data = context.photos().allPhotoTypes();\n\n function typeEnabled(d) {\n return context.photos().showsPhotoType(d);\n }\n\n var ul = selection\n .selectAll('.layer-list-photo-types')\n .data(context.photos().shouldFilterByPhotoType() ? [0] : []);\n\n ul.exit()\n .remove();\n\n ul = ul.enter()\n .append('ul')\n .attr('class', 'layer-list layer-list-photo-types')\n .merge(ul);\n\n var li = ul.selectAll('.list-item-photo-types')\n .data(data);\n\n li.exit()\n .remove();\n\n var liEnter = li.enter()\n .append('li')\n .attr('class', function(d) {\n return 'list-item-photo-types list-item-' + d;\n });\n\n var labelEnter = liEnter\n .append('label')\n .each(function(d) {\n d3_select(this)\n .call(uiTooltip()\n .title(t('photo_overlays.photo_type.' + d + '.tooltip'))\n .placement('top')\n );\n });\n\n labelEnter\n .append('input')\n .attr('type', 'checkbox')\n .on('change', function(d) {\n context.photos().togglePhotoType(d);\n });\n\n labelEnter\n .append('span')\n .text(function(d) {\n return t('photo_overlays.photo_type.' + d + '.title');\n });\n\n\n // Update\n li\n .merge(liEnter)\n .classed('active', typeEnabled)\n .selectAll('input')\n .property('checked', typeEnabled);\n }\n\n function toggleLayer(which) {\n setLayer(which, !showsLayer(which));\n }\n\n function showsLayer(which) {\n var layer = layers.layer(which);\n if (layer) {\n return layer.enabled();\n }\n return false;\n }\n\n function setLayer(which, enabled) {\n var layer = layers.layer(which);\n if (layer) {\n layer.enabled(enabled);\n }\n }\n\n context.layers().on('change.uiSectionPhotoOverlays', section.reRender);\n context.photos().on('change.uiSectionPhotoOverlays', section.reRender);\n\n return section;\n}\n","\nimport { t } from '../../core/localizer';\nimport { uiPane } from '../pane';\n\nimport { uiSectionDataLayers } from '../sections/data_layers';\nimport { uiSectionMapFeatures } from '../sections/map_features';\nimport { uiSectionMapStyleOptions } from '../sections/map_style_options';\nimport { uiSectionPhotoOverlays } from '../sections/photo_overlays';\n\nexport function uiPaneMapData(context) {\n\n var mapDataPane = uiPane('map-data', context)\n .key(t('map_data.key'))\n .title(t('map_data.title'))\n .description(t('map_data.description'))\n .iconName('iD-icon-data')\n .sections([\n uiSectionDataLayers(context),\n uiSectionPhotoOverlays(context),\n uiSectionMapStyleOptions(context),\n uiSectionMapFeatures(context)\n ]);\n\n return mapDataPane;\n}\n","import {\n event as d3_event\n} from 'd3-selection';\n\nimport { prefs } from '../../core/preferences';\nimport { t } from '../../core/localizer';\nimport { uiTooltip } from '../tooltip';\nimport { svgIcon } from '../../svg/icon';\nimport { uiSection } from '../section';\n\nexport function uiSectionPrivacy(context) {\n\n let section = uiSection('preferences-third-party', context)\n .title(t('preferences.privacy.title'))\n .disclosureContent(renderDisclosureContent);\n\n let _showThirdPartyIcons = prefs('preferences.privacy.thirdpartyicons') || 'true';\n\n function renderDisclosureContent(selection) {\n // enter\n let privacyOptionsListEnter = selection.selectAll('.privacy-options-list')\n .data([0])\n .enter()\n .append('ul')\n .attr('class', 'layer-list privacy-options-list');\n\n let thirdPartyIconsEnter = privacyOptionsListEnter\n .append('li')\n .attr('class', 'privacy-third-party-icons-item')\n .append('label')\n .call(uiTooltip()\n .title(t('preferences.privacy.third_party_icons.tooltip'))\n .placement('bottom')\n );\n\n thirdPartyIconsEnter\n .append('input')\n .attr('type', 'checkbox')\n .on('change', () => {\n d3_event.preventDefault();\n _showThirdPartyIcons = (_showThirdPartyIcons === 'true') ? 'false' : 'true';\n prefs('preferences.privacy.thirdpartyicons', _showThirdPartyIcons);\n update();\n });\n\n thirdPartyIconsEnter\n .append('span')\n .text(t('preferences.privacy.third_party_icons.description'));\n\n\n // Privacy Policy link\n selection.selectAll('.privacy-link')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'privacy-link')\n .append('a')\n .attr('target', '_blank')\n .call(svgIcon('#iD-icon-out-link', 'inline'))\n .attr('href', 'https://github.com/openstreetmap/iD/blob/release/PRIVACY.md')\n .append('span')\n .text(t('preferences.privacy.privacy_link'));\n\n update();\n\n\n function update() {\n selection.selectAll('.privacy-third-party-icons-item')\n .classed('active', (_showThirdPartyIcons === 'true'))\n .select('input')\n .property('checked', (_showThirdPartyIcons === 'true'));\n }\n }\n\n return section;\n}\n","\nimport { t } from '../../core/localizer';\nimport { uiPane } from '../pane';\nimport { uiSectionPrivacy } from '../sections/privacy';\n\nexport function uiPanePreferences(context) {\n\n let preferencesPane = uiPane('preferences', context)\n .key(t('preferences.key'))\n .title(t('preferences.title'))\n .description(t('preferences.description'))\n .iconName('fas-user-cog')\n .sections([\n uiSectionPrivacy(context)\n ]);\n\n return preferencesPane;\n}\n","import { t } from '../core/localizer';\n\n\nexport function uiRapidServiceLicense() {\n return function(selection) {\n selection.append('a')\n .attr('href', 'https://mapwith.ai/doc/license/MapWithAILicense.pdf')\n .attr('target', '_blank')\n .text(t('rapid_feature_license'));\n };\n}\n","import { event as d3_event, select as d3_select } from 'd3-selection';\n\nimport { prefs } from '../core/preferences';\nimport { t, localizer } from '../core/localizer';\nimport { presetManager } from '../presets';\nimport { behaviorHash } from '../behavior';\nimport { modeBrowse } from '../modes/browse';\nimport { svgDefs, svgIcon } from '../svg';\nimport { utilDetect } from '../util/detect';\nimport { utilGetDimensions } from '../util/dimensions';\n\nimport { uiAccount } from './account';\nimport { uiAttribution } from './attribution';\nimport { uiContributors } from './contributors';\nimport { uiEditMenu } from './edit_menu';\nimport { uiFeatureInfo } from './feature_info';\nimport { uiFlash } from './flash';\nimport { uiFullScreen } from './full_screen';\nimport { uiGeolocate } from './geolocate';\nimport { uiInfo } from './info';\nimport { uiIntro } from './intro';\nimport { uiIssuesInfo } from './issues_info';\nimport { uiLoading } from './loading';\nimport { uiMapInMap } from './map_in_map';\nimport { uiNotice } from './notice';\nimport { uiPhotoviewer } from './photoviewer';\nimport { uiRestore } from './restore';\nimport { uiScale } from './scale';\nimport { uiShortcuts } from './shortcuts';\nimport { uiSidebar } from './sidebar';\nimport { uiSourceSwitch } from './source_switch';\nimport { uiSpinner } from './spinner';\nimport { uiStatus } from './status';\nimport { uiTooltip } from './tooltip';\nimport { uiTopToolbar } from './top_toolbar';\nimport { uiVersion } from './version';\nimport { uiZoom } from './zoom';\nimport { uiZoomToSelection } from './zoom_to_selection';\nimport { uiCmd } from './cmd';\n\nimport { uiPaneBackground } from './panes/background';\nimport { uiPaneHelp } from './panes/help';\nimport { uiPaneIssues } from './panes/issues';\nimport { uiPaneMapData } from './panes/map_data';\nimport { uiPanePreferences } from './panes/preferences';\n\nimport { uiRapidServiceLicense } from './rapid_service_license';\n// import { uiRapidWhatsNew } from './rapid_whatsnew';\nimport { uiRapidSplash } from './rapid_splash';\n\n\nexport function uiInit(context) {\n var _initCounter = 0;\n var _needWidth = {};\n\n var _lastPointerType;\n\n\n function render(container) {\n\n container\n .on('click.ui', function() {\n // we're only concerned with the primary mouse button\n if (d3_event.button !== 0) return;\n\n if (!d3_event.composedPath) return;\n\n // some targets have default click events we don't want to override\n var isOkayTarget = d3_event.composedPath().some(function(node) {\n // we only care about element nodes\n return node.nodeType === 1 &&\n // clicking focuses it and/or changes a value\n (node.nodeName === 'INPUT' ||\n // clicking affects its by default\n node.nodeName === 'LABEL' ||\n // clicking opens a hyperlink by default\n node.nodeName === 'A');\n });\n if (isOkayTarget) return;\n\n // disable double-tap-to-zoom on touchscreens\n d3_event.preventDefault();\n });\n\n var detected = utilDetect();\n\n // only WebKit supports gesture events\n if ('GestureEvent' in window &&\n // Listening for gesture events on iOS 13.4+ breaks double-tapping,\n // but we only need to do this on desktop Safari anyway. – #7694\n !detected.isMobileWebKit) {\n\n // On iOS we disable pinch-to-zoom of the UI via the `touch-action`\n // CSS property, but on desktop Safari we need to manually cancel the\n // default gesture events.\n container.on('gesturestart.ui gesturechange.ui gestureend.ui', function() {\n // disable pinch-to-zoom of the UI via multitouch trackpads on macOS Safari\n d3_event.preventDefault();\n });\n }\n\n if ('PointerEvent' in window) {\n d3_select(window)\n .on('pointerdown.ui pointerup.ui', function() {\n var pointerType = d3_event.pointerType || 'mouse';\n if (_lastPointerType !== pointerType) {\n _lastPointerType = pointerType;\n container\n .attr('pointer', pointerType);\n }\n }, true);\n } else {\n _lastPointerType = 'mouse';\n container\n .attr('pointer', 'mouse');\n }\n\n container\n .attr('dir', localizer.textDirection());\n\n // setup fullscreen keybindings (no button shown at this time)\n container\n .call(uiFullScreen(context));\n\n var map = context.map();\n map.redrawEnable(false); // don't draw until we've set zoom/lat/long\n\n map\n .on('hitMinZoom.ui', function() {\n ui.flash.text(t('cannot_zoom'))();\n });\n\n container\n .append('svg')\n .attr('id', 'ideditor-defs')\n .call(svgDefs(context));\n\n container\n .append('div')\n .attr('class', 'sidebar')\n .call(ui.sidebar);\n\n var content = container\n .append('div')\n .attr('class', 'main-content active');\n\n // Top toolbar\n content\n .append('div')\n .attr('class', 'top-toolbar-wrap')\n .append('div')\n .attr('class', 'top-toolbar fillD')\n .call(uiTopToolbar(context));\n\n content\n .append('div')\n .attr('class', 'main-map')\n .attr('dir', 'ltr')\n .call(map);\n\n content\n .append('div')\n .attr('class', 'spinner')\n .call(uiSpinner(context));\n\n // Add attribution and footer\n var about = content\n .append('div')\n .attr('class', 'map-footer');\n\n about\n .append('div')\n .attr('class', 'attribution-wrap')\n .attr('dir', 'ltr')\n .call(uiAttribution(context));\n\n about\n .append('div')\n .attr('class', 'api-status')\n .call(uiStatus(context));\n\n\n var footer = about\n .append('div')\n .attr('class', 'map-footer-bar fillD');\n\n footer\n .append('div')\n .attr('class', 'flash-wrap footer-hide');\n\n var footerWrap = footer\n .append('div')\n .attr('class', 'main-footer-wrap footer-show');\n\n footerWrap\n .append('div')\n .attr('class', 'scale-block')\n .call(uiScale(context));\n\n var aboutList = footerWrap\n .append('div')\n .attr('class', 'info-block')\n .append('ul')\n .attr('class', 'map-footer-list');\n\n if (!context.embed()) {\n aboutList\n .call(uiAccount(context));\n }\n\n aboutList\n .append('li')\n .attr('class', 'version')\n .call(uiVersion(context));\n\n var issueLinks = aboutList\n .append('li');\n\n issueLinks\n .append('a')\n .attr('target', '_blank')\n .attr('tabindex', -1)\n .attr('href', 'https://github.com/facebookincubator/RapiD/issues')\n .call(svgIcon('#iD-icon-bug', 'light'))\n .call(uiTooltip().title(t('report_a_bug')).placement('top'));\n\n issueLinks\n .append('a')\n .attr('target', '_blank')\n .attr('href', 'https://github.com/openstreetmap/iD/blob/develop/CONTRIBUTING.md#translating')\n .call(svgIcon('#iD-icon-translate', 'light'))\n .call(uiTooltip().title(t('help_translate')).placement('top'));\n\n aboutList\n .append('li')\n .attr('class', 'feature-warning')\n .attr('tabindex', -1)\n .call(uiFeatureInfo(context));\n\n aboutList\n .append('li')\n .attr('class', 'issues-info')\n .attr('tabindex', -1)\n .call(uiIssuesInfo(context));\n\n var apiConnections = context.apiConnections();\n if (apiConnections && apiConnections.length > 1) {\n aboutList\n .append('li')\n .attr('class', 'source-switch')\n .attr('tabindex', -1)\n .call(uiSourceSwitch(context)\n .keys(apiConnections)\n );\n }\n\n aboutList\n .append('li')\n .attr('class', 'user-list')\n .attr('tabindex', -1)\n .call(uiContributors(context));\n\n aboutList\n .append('li')\n .attr('class', 'fb-road-license')\n .attr('tabindex', -1)\n .call(uiRapidServiceLicense());\n\n\n // Setup map dimensions and move map to initial center/zoom.\n // This should happen after .main-content and toolbars exist.\n ui.onResize();\n map.redrawEnable(true);\n\n ui.hash = behaviorHash(context);\n ui.hash();\n if (!ui.hash.hadHash) {\n map.centerZoom([0, 0], 2);\n }\n\n\n var overMap = content\n .append('div')\n .attr('class', 'over-map');\n\n // Map controls\n var controls = overMap\n .append('div')\n .attr('class', 'map-controls');\n\n controls\n .append('div')\n .attr('class', 'map-control zoombuttons')\n .call(uiZoom(context));\n\n controls\n .append('div')\n .attr('class', 'map-control zoom-to-selection-control')\n .call(uiZoomToSelection(context));\n\n controls\n .append('div')\n .attr('class', 'map-control geolocate-control')\n .call(uiGeolocate(context));\n\n // Add panes\n // This should happen after map is initialized, as some require surface()\n var panes = overMap\n .append('div')\n .attr('class', 'map-panes');\n\n var uiPanes = [\n uiPaneBackground(context),\n uiPaneMapData(context),\n uiPaneIssues(context),\n uiPanePreferences(context),\n uiPaneHelp(context)\n ];\n\n uiPanes.forEach(function(pane) {\n controls\n .append('div')\n .attr('class', 'map-control map-pane-control ' + pane.id + '-control')\n .call(pane.renderToggleButton);\n\n panes\n .call(pane.renderPane);\n });\n\n ui.info = uiInfo(context);\n\n // Add absolutely-positioned elements that sit on top of the map\n // This should happen after the map is ready (center/zoom)\n overMap\n .call(uiMapInMap(context))\n .call(ui.info)\n .call(uiNotice(context));\n\n\n overMap\n .append('div')\n .attr('class', 'photoviewer')\n .classed('al', true) // 'al'=left, 'ar'=right\n .classed('hide', true)\n .call(ui.photoviewer);\n\n\n // Bind events\n window.onbeforeunload = function() {\n return context.save();\n };\n window.onunload = function() {\n context.history().unlock();\n };\n\n d3_select(window)\n .on('resize.editor', ui.onResize);\n\n\n var panPixels = 80;\n context.keybinding()\n .on('⌫', function() { d3_event.preventDefault(); })\n .on([t('sidebar.key'), '`', '²', '@'], ui.sidebar.toggle) // #5663, #6864 - common QWERTY, AZERTY\n .on('←', pan([panPixels, 0]))\n .on('↑', pan([0, panPixels]))\n .on('→', pan([-panPixels, 0]))\n .on('↓', pan([0, -panPixels]))\n .on(uiCmd('⌘←'), pan([map.dimensions()[0], 0]))\n .on(uiCmd('⌘↑'), pan([0, map.dimensions()[1]]))\n .on(uiCmd('⌘→'), pan([-map.dimensions()[0], 0]))\n .on(uiCmd('⌘↓'), pan([0, -map.dimensions()[1]]))\n .on(uiCmd('⌘' + t('background.key')), function quickSwitch() {\n if (d3_event) {\n d3_event.stopImmediatePropagation();\n d3_event.preventDefault();\n }\n var previousBackground = context.background().findSource(prefs('background-last-used-toggle'));\n if (previousBackground) {\n var currentBackground = context.background().baseLayerSource();\n prefs('background-last-used-toggle', currentBackground.id);\n prefs('background-last-used', previousBackground.id);\n context.background().baseLayerSource(previousBackground);\n }\n })\n .on(t('area_fill.wireframe.key'), function toggleWireframe() {\n d3_event.preventDefault();\n d3_event.stopPropagation();\n context.map().toggleWireframe();\n })\n .on(uiCmd('⌥' + t('area_fill.wireframe.key')), function toggleOsmData() {\n d3_event.preventDefault();\n d3_event.stopPropagation();\n\n // Don't allow layer changes while drawing - #6584\n var mode = context.mode();\n if (mode && /^draw/.test(mode.id)) return;\n\n var layer = context.layers().layer('osm');\n if (layer) {\n layer.enabled(!layer.enabled());\n if (!layer.enabled()) {\n context.enter(modeBrowse(context));\n }\n }\n })\n .on(t('map_data.highlight_edits.key'), function toggleHighlightEdited() {\n d3_event.preventDefault();\n context.map().toggleHighlightEdited();\n });\n\n context\n .on('enter.editor', function(entered) {\n container\n .classed('mode-' + entered.id, true);\n })\n .on('exit.editor', function(exited) {\n container\n .classed('mode-' + exited.id, false);\n });\n\n context.enter(modeBrowse(context));\n\n var osm = context.connection();\n\n if (!_initCounter++) {\n if (!ui.hash.startWalkthrough) {\n if (context.history().lock() && context.history().hasRestorableChanges()) {\n context.container()\n .call(uiRestore(context));\n\n// // If users have already seen the 'welcome to RapiD' splash screen, don't also\n// // show them the what's new screen\n// } else if (prefs('sawRapidSplash')) {\n// context.container()\n// .call(uiRapidWhatsNew(context));\n } else if (osm.authenticated()) {\n context.container()\n .call(uiRapidSplash(context));\n }\n }\n\n context.container()\n .call(uiShortcuts(context));\n }\n\n var auth = uiLoading(context).message(t('loading_auth')).blocking(true);\n\n if (osm && auth) {\n osm\n .on('authLoading.ui', function() {\n context.container()\n .call(auth);\n })\n .on('authDone.ui', function() {\n auth.close();\n });\n }\n\n _initCounter++;\n\n if (ui.hash.startWalkthrough) {\n ui.hash.startWalkthrough = false;\n context.container().call(uiIntro(context));\n }\n\n\n function pan(d) {\n return function() {\n if (d3_event.shiftKey) return;\n if (context.container().select('.combobox').size()) return;\n d3_event.preventDefault();\n context.map().pan(d, 100);\n };\n }\n\n }\n\n\n let ui = {};\n\n let _loadPromise;\n // renders the iD interface into the container node\n ui.ensureLoaded = () => {\n\n if (_loadPromise) return _loadPromise;\n\n return _loadPromise = Promise.all([\n // must have strings and presets before loading the UI\n localizer.ensureLoaded(),\n presetManager.ensureLoaded()\n ])\n .then(() => {\n if (!context.container().empty()) render(context.container());\n })\n .catch(err => console.error(err)); // eslint-disable-line\n };\n\n\n // `ui.restart()` will destroy and rebuild the entire iD interface,\n // for example to switch the locale while iD is running.\n ui.restart = function() {\n context.keybinding().clear();\n\n _loadPromise = null;\n\n context.container().selectAll('*').remove();\n\n ui.ensureLoaded();\n };\n\n ui.lastPointerType = function() {\n return _lastPointerType;\n };\n\n ui.flash = uiFlash(context);\n\n ui.sidebar = uiSidebar(context);\n\n ui.photoviewer = uiPhotoviewer(context);\n\n ui.onResize = function(withPan) {\n var map = context.map();\n\n // Recalc dimensions of map and sidebar.. (`true` = force recalc)\n // This will call `getBoundingClientRect` and trigger reflow,\n // but the values will be cached for later use.\n var mapDimensions = utilGetDimensions(context.container().select('.main-content'), true);\n utilGetDimensions(context.container().select('.sidebar'), true);\n\n if (withPan !== undefined) {\n map.redrawEnable(false);\n map.pan(withPan);\n map.redrawEnable(true);\n }\n map.dimensions(mapDimensions);\n\n ui.photoviewer.onMapResize();\n\n // check if header or footer have overflowed\n ui.checkOverflow('.top-toolbar');\n ui.checkOverflow('.map-footer-bar');\n\n // Use outdated code so it works on Explorer\n var resizeWindowEvent = document.createEvent('Event');\n\n resizeWindowEvent.initEvent('resizeWindow', true, true);\n\n document.dispatchEvent(resizeWindowEvent);\n };\n\n\n // Call checkOverflow when resizing or whenever the contents change.\n ui.checkOverflow = function(selector, reset) {\n if (reset) {\n delete _needWidth[selector];\n }\n\n var element = d3_select(selector);\n var scrollWidth = element.property('scrollWidth');\n var clientWidth = element.property('clientWidth');\n var needed = _needWidth[selector] || scrollWidth;\n\n if (scrollWidth > clientWidth) { // overflow happening\n element.classed('narrow', true);\n if (!_needWidth[selector]) {\n _needWidth[selector] = scrollWidth;\n }\n\n } else if (scrollWidth >= needed) {\n element.classed('narrow', false);\n }\n };\n\n ui.togglePanes = function(showPane) {\n var shownPanes = context.container().selectAll('.map-pane.shown');\n\n var side = localizer.textDirection() === 'ltr' ? 'right' : 'left';\n\n shownPanes\n .classed('shown', false);\n\n context.container().selectAll('.map-pane-control button')\n .classed('active', false);\n\n if (showPane) {\n shownPanes\n .style('display', 'none')\n .style(side, '-500px');\n\n context.container().selectAll('.' + showPane.attr('pane') + '-control button')\n .classed('active', true);\n\n showPane\n .classed('shown', true)\n .style('display', 'block');\n if (shownPanes.empty()) {\n showPane\n .style('display', 'block')\n .style(side, '-500px')\n .transition()\n .duration(200)\n .style(side, '0px');\n } else {\n showPane\n .style(side, '0px');\n }\n } else {\n shownPanes\n .style('display', 'block')\n .style(side, '0px')\n .transition()\n .duration(200)\n .style(side, '-500px')\n .on('end', function() {\n d3_select(this).style('display', 'none');\n });\n }\n };\n\n\n var _editMenu = uiEditMenu(context);\n\n ui.editMenu = function() {\n return _editMenu;\n };\n\n ui.showEditMenu = function(anchorPoint, triggerType, operations) {\n\n // remove any displayed menu\n ui.closeEditMenu();\n\n if (!operations && context.mode().operations) operations = context.mode().operations();\n if (!operations || !operations.length) return;\n\n // disable menu if in wide selection, for example\n if (!context.map().editableDataEnabled()) return;\n\n var surfaceNode = context.surface().node();\n if (surfaceNode.focus) { // FF doesn't support it\n // focus the surface or else clicking off the menu may not trigger modeBrowse\n surfaceNode.focus();\n }\n\n operations.forEach(function(operation) {\n if (operation.point) operation.point(anchorPoint);\n });\n\n _editMenu\n .anchorLoc(anchorPoint)\n .triggerType(triggerType)\n .operations(operations);\n\n // render the menu\n context.map().supersurface.call(_editMenu);\n };\n\n ui.closeEditMenu = function() {\n // remove any existing menu no matter how it was added\n context.map().supersurface\n .select('.edit-menu').remove();\n };\n\n\n var _saveLoading = d3_select(null);\n\n context.uploader()\n .on('saveStarted.ui', function() {\n _saveLoading = uiLoading(context)\n .message(t('save.uploading'))\n .blocking(true);\n context.container().call(_saveLoading); // block input during upload\n })\n .on('saveEnded.ui', function() {\n _saveLoading.close();\n _saveLoading = d3_select(null);\n });\n\n return ui;\n}\n","import { select as d3_select } from 'd3-selection';\nimport { geoExtent } from '../geo';\nimport { uiToggle } from './toggle';\n\n\nexport function uiLasso(context) {\n var group, polygon;\n\n lasso.coordinates = [];\n\n function lasso(selection) {\n context.container()\n .classed('lasso', true);\n\n group = selection\n .append('g')\n .attr('class', 'lasso hide');\n\n polygon = group\n .append('path')\n .attr('class', 'lasso-path');\n\n group\n .call(uiToggle(true));\n }\n\n\n function draw() {\n if (polygon) {\n polygon.data([lasso.coordinates])\n .attr('d', function(d) { return 'M' + d.join(' L') + ' Z'; });\n }\n }\n\n\n lasso.extent = function () {\n return lasso.coordinates.reduce(function(extent, point) {\n return extent.extend(geoExtent(point));\n }, geoExtent());\n };\n\n\n lasso.p = function(_) {\n if (!arguments.length) return lasso;\n lasso.coordinates.push(_);\n draw();\n return lasso;\n };\n\n\n lasso.close = function() {\n if (group) {\n group.call(uiToggle(false, function() {\n d3_select(this).remove();\n }));\n }\n context.container().classed('lasso', false);\n };\n\n\n return lasso;\n}\n","import { prefs } from '../core/preferences';\nimport { fileFetcher } from '../core/file_fetcher';\nimport { t } from '../core/localizer';\nimport { uiIntro } from './intro';\nimport { uiModal } from './modal';\n\n\nexport function uiSplash(context) {\n return (selection) => {\n // Exception - if there are restorable changes, skip this splash screen.\n // This is because we currently only support one `uiModal` at a time\n // and we need to show them `uiRestore`` instead of this one.\n if (context.history().hasRestorableChanges()) return;\n\n // If user has not seen this version of the privacy policy, show the splash again.\n let updateMessage = '';\n const sawPrivacyVersion = prefs('sawPrivacyVersion');\n let showSplash = !prefs('sawSplash');\n if (sawPrivacyVersion !== context.privacyVersion) {\n updateMessage = t('splash.privacy_update');\n showSplash = true;\n }\n\n if (!showSplash) return;\n\n prefs('sawSplash', true);\n prefs('sawPrivacyVersion', context.privacyVersion);\n\n // fetch intro graph data now, while user is looking at the splash screen\n fileFetcher.get('intro_graph');\n\n let modalSelection = uiModal(selection);\n\n modalSelection.select('.modal')\n .attr('class', 'modal-splash modal');\n\n let introModal = modalSelection.select('.content')\n .append('div')\n .attr('class', 'fillL');\n\n introModal\n .append('div')\n .attr('class','modal-section')\n .append('h3')\n .text(t('splash.welcome'));\n\n let modalSection = introModal\n .append('div')\n .attr('class','modal-section');\n\n modalSection\n .append('p')\n .html(t('splash.text', {\n version: context.version,\n website: ' ideditor.blog ',\n github: 'github.com '\n }));\n\n modalSection\n .append('p')\n .html(t('splash.privacy', {\n updateMessage: updateMessage,\n privacyLink: '' +\n t('splash.privacy_policy') + ' '\n }));\n\n let buttonWrap = introModal\n .append('div')\n .attr('class', 'modal-actions');\n\n let walkthrough = buttonWrap\n .append('button')\n .attr('class', 'walkthrough')\n .on('click', () => {\n context.container().call(uiIntro(context));\n modalSelection.close();\n });\n\n walkthrough\n .append('svg')\n .attr('class', 'logo logo-walkthrough')\n .append('use')\n .attr('xlink:href', '#iD-logo-walkthrough');\n\n walkthrough\n .append('div')\n .text(t('splash.walkthrough'));\n\n let startEditing = buttonWrap\n .append('button')\n .attr('class', 'start-editing')\n .on('click', modalSelection.close);\n\n startEditing\n .append('svg')\n .attr('class', 'logo logo-features')\n .append('use')\n .attr('xlink:href', '#iD-logo-features');\n\n startEditing\n .append('div')\n .text(t('splash.start'));\n\n modalSelection.select('button.close')\n .attr('class','hide');\n };\n}\n","import { select as d3_select } from 'd3-selection';\nimport { t } from '../core/localizer';\nimport { icon } from './intro/helper';\nimport { uiModal } from './modal';\nimport { prefs } from '../core/preferences';\nimport marked from 'marked';\n\n\nexport function uiRapidWhatsNew(context) {\n let _dontShowAgain = false;\n\n\n return function(selection) {\n if (prefs('sawWhatsNew') === 'true') return;\n\n const modalSelection = uiModal(selection);\n\n modalSelection.select('.modal')\n .attr('class', 'modal rapid-modal modal-splash modal-whatsnew'); // RapiD styling\n\n let whatsNewModal = modalSelection.select('.content');\n\n whatsNewModal\n .append('div')\n .attr('class','modal-section')\n .append('h3')\n .html(t('rapid_whats_new.welcome', { rapidicon: icon('#iD-logo-rapid', 'logo-rapid') }));\n\n\n let body = whatsNewModal\n .append('div')\n .attr('class','modal-section body')\n .html(marked(t('rapid_whats_new.text', {rapidicon: icon('#iD-logo-rapid', 'logo-rapid') })));\n\n\n body\n .append('img')\n .attr('class', 'whatsnew-image')\n .attr('src', context.asset('img/rapid-esri-splash.jpg'));\n\n body.select('p a')\n .attr('target', '_blank');\n\n\n let checkboxContainer = whatsNewModal\n .append('div')\n .attr('class', 'modal-section rapid-checkbox dontshow')\n .attr('id', 'dontshowagain');\n\n let checkbox = checkboxContainer\n .append('label')\n .attr('class', 'rapid-checkbox-label dontshow');\n\n checkbox\n .append('span')\n .attr('class', 'rapid-checkbox-text')\n .text(t('rapid_whats_new.dontshowagain'));\n\n checkbox\n .append('input')\n .attr('type', 'checkbox')\n .attr('class', 'rapid-feature-checkbox')\n .property('checked', false)\n .on('click', (d, i, nodes) => {\n d3_select(nodes[i]).node().blur();\n _dontShowAgain = !_dontShowAgain;\n });\n\n checkbox\n .append('div')\n .attr('class', 'rapid-checkbox-custom');\n\n let buttonWrap = whatsNewModal\n .append('div')\n .attr('class', 'modal-actions');\n\n let nothanks = buttonWrap\n .append('button')\n .attr('class', 'whats-new-nothanks')\n .on('click', (d, i, nodes) => {\n d3_select(nodes[i]).node().blur();\n prefs('sawWhatsNew', _dontShowAgain);\n modalSelection.close();\n });\n\n nothanks\n .append('div')\n .text(t('rapid_whats_new.nope'));\n\n let okayButton = buttonWrap\n .append('button')\n .attr('class', 'whats-new-okay');\n\n okayButton\n .append('div')\n .text(t('rapid_whats_new.ok'))\n .on('click', (d, i, nodes) => {\n d3_select(nodes[i]).node().blur();\n prefs('sawWhatsNew', _dontShowAgain);\n modalSelection.close();\n window.open('https://mapwith.ai/rapid-esri', '_blank');\n });\n\n modalSelection.select('button.close')\n .attr('class','hide');\n };\n}\n","import { event as d3_event, select as d3_select } from 'd3-selection';\n\nimport { t } from '../core/localizer';\nimport { behaviorBreathe, behaviorHover, behaviorLasso, behaviorSelect } from '../behavior';\nimport { modeBrowse, modeDragNode, modeDragNote } from '../modes';\nimport { services } from '../services';\nimport { uiRapidFeatureInspector } from '../ui';\nimport { utilKeybinding } from '../util';\n\nlet _expandedOnce = false;\n\n\nexport function modeRapidSelectFeatures(context, selectedDatum) {\n let mode = {\n id: 'select-ai-features',\n button: 'browse'\n };\n\n const keybinding = utilKeybinding('select-ai-features');\n const rapidInspector = uiRapidFeatureInspector(context, keybinding);\n const service = selectedDatum.__service__ === 'esri' ? services.esriData : services.fbMLRoads;\n const rapidGraph = service.graph(selectedDatum.__datasetid__);\n\n let behaviors = [\n behaviorBreathe(context),\n behaviorHover(context),\n behaviorSelect(context),\n behaviorLasso(context),\n modeDragNode(context).behavior,\n modeDragNote(context).behavior\n ];\n\n\n // class the data as selected, or return to browse mode if the data is gone\n function selectData(drawn) {\n let selection = context.surface().selectAll('.layer-ai-features .data' + selectedDatum.__fbid__);\n\n if (selection.empty()) {\n // Return to browse mode if selected DOM elements have\n // disappeared because the user moved them out of view..\n const source = d3_event && d3_event.type === 'zoom' && d3_event.sourceEvent;\n if (drawn && source && (source.type === 'mousemove' || source.type === 'touchmove')) {\n context.enter(modeBrowse(context));\n }\n } else {\n selection.classed('selected', true);\n }\n }\n\n\n function esc() {\n if (d3_select('.combobox').size()) return;\n context.enter(modeBrowse(context));\n }\n\n\n mode.selectedIDs = function() {\n return [selectedDatum.id];\n };\n\n\n mode.selectedDatum = function() {\n return selectedDatum;\n };\n\n\n mode.zoomToSelected = function() {\n const extent = selectedDatum.extent(rapidGraph);\n context.map().centerZoomEase(extent.center(), context.map().trimmedExtentZoom(extent));\n };\n\n\n mode.enter = function() {\n behaviors.forEach(context.install);\n\n keybinding\n .on(t('inspector.zoom_to.key'), mode.zoomToSelected)\n .on('⎋', esc, true);\n\n d3_select(document)\n .call(keybinding);\n\n selectData();\n\n const sidebar = context.ui().sidebar;\n sidebar.show(rapidInspector.datum(selectedDatum));\n\n if (!_expandedOnce) {\n // Expand sidebar at least once per session to inform user how to\n // accept and reject proposed roads.\n _expandedOnce = true;\n // expand the sidebar, avoid obscuring the data if needed\n const extent = selectedDatum.extent(rapidGraph);\n sidebar.expand(sidebar.intersects(extent));\n }\n\n context.map()\n .on('drawn.select-ai-features', selectData);\n };\n\n\n mode.exit = function() {\n behaviors.forEach(context.uninstall);\n\n d3_select(document)\n .call(keybinding.unbind);\n\n context.surface()\n .selectAll('.layer-ai-features .selected')\n .classed('selected hover', false);\n\n context.map()\n .on('drawn.select-ai-features', null);\n\n context.ui().sidebar\n .hide();\n };\n\n\n return mode;\n}\n","import { t } from '../core/localizer';\nimport { modeDrawLine } from '../modes/draw_line';\nimport { behaviorOperation } from '../behavior/operation';\nimport { utilArrayGroupBy } from '../util';\n\n\nexport function operationContinue(context, selectedIDs) {\n var graph = context.graph();\n var entities = selectedIDs.map(function(id) { return graph.entity(id); });\n var geometries = Object.assign(\n { line: [], vertex: [] },\n utilArrayGroupBy(entities, function(entity) { return entity.geometry(graph); })\n );\n var vertex = geometries.vertex[0];\n\n\n function candidateWays() {\n return graph.parentWays(vertex).filter(function(parent) {\n return parent.geometry(graph) === 'line' &&\n !parent.isClosed() &&\n parent.affix(vertex.id) &&\n (geometries.line.length === 0 || geometries.line[0] === parent);\n });\n }\n\n\n var operation = function() {\n var candidate = candidateWays()[0];\n context.enter(\n modeDrawLine(context, candidate.id, context.graph(), 'line', candidate.affix(vertex.id), true)\n );\n };\n\n\n operation.available = function() {\n return geometries.vertex.length === 1 &&\n geometries.line.length <= 1 &&\n !context.features().hasHiddenConnections(vertex, context.graph());\n };\n\n\n operation.disabled = function() {\n var candidates = candidateWays();\n if (candidates.length === 0) {\n return 'not_eligible';\n } else if (candidates.length > 1) {\n return 'multiple';\n }\n\n return false;\n };\n\n\n operation.tooltip = function() {\n var disable = operation.disabled();\n return disable ?\n t('operations.continue.' + disable) :\n t('operations.continue.description');\n };\n\n\n operation.annotation = function() {\n return t('operations.continue.annotation.line');\n };\n\n\n operation.id = 'continue';\n operation.keys = [t('operations.continue.key')];\n operation.title = t('operations.continue.title');\n operation.behavior = behaviorOperation(context).which(operation);\n\n return operation;\n}\n","import { t } from '../core/localizer';\nimport { actionChangeTags } from '../actions/index';\nimport { behaviorOperation } from '../behavior/index';\n\n\nexport function operationCycleHighwayTag(context, selectedIDs) {\n var _entityID = selectedIDs[0];\n var _entity = context.entity(_entityID);\n var _prevSelectedIDs;\n var ROAD_TYPES = ['residential', 'service', 'track', 'unclassified', 'tertiary'];\n\n\n var updateHighwayTag = function (tags) {\n var idx = tags.highway ? ROAD_TYPES.indexOf(tags.highway) : -1;\n tags.highway = ROAD_TYPES[(idx + 1) % ROAD_TYPES.length];\n\n if (tags.highway === 'track') {\n tags.surface = 'unpaved';\n }\n else {\n delete tags.surface;\n }\n };\n\n\n var operation = function() {\n _entity = context.entity(_entityID);\n // Calculate whether the changes since the last time this action ran\n // are only to highway tags.\n if (_prevSelectedIDs) {\n var sameSelection = _prevSelectedIDs ? _prevSelectedIDs[0] === selectedIDs[0] : false;\n }\n\n var tags = Object.assign({}, _entity.tags);\n updateHighwayTag(tags);\n\n _prevSelectedIDs = selectedIDs;\n\n // context peeking tells us the last operation performed. Was it cycle road tags?\n if (sameSelection && context.history().peekAnnotation() === operation.annotation()) {\n // Coalesce the update of Highway type tags into the previous tag change\n context.replace(actionChangeTags(_entityID, tags), operation.annotation());\n } else {\n context.perform(actionChangeTags(_entityID, tags), operation.annotation());\n }\n };\n\n\n operation.available = function() {\n return selectedIDs.length === 1 &&\n _entity.type === 'way' &&\n new Set(_entity.nodes).size > 1;\n };\n\n\n operation.disabled = function() {\n if ( Object.keys(_entity.tags).length > 0 && !_entity.tags.highway) {\n return 'restriction';\n }\n };\n\n\n operation.tooltip = function() {\n var disable = operation.disabled();\n return disable ?\n t('operations.cycle_highway_tag.' + disable) :\n t('operations.cycle_highway_tag.description');\n };\n\n\n operation.annotation = function() {\n return t('operations.cycle_highway_tag.annotation');\n };\n\n\n operation.id = 'cycle_highway_tag';\n operation.keys = ['⇧' + t('operations.cycle_highway_tag.key')];\n operation.title = t('operations.cycle_highway_tag.title');\n operation.behavior = behaviorOperation(context).which(operation);\n\n return operation;\n}\n","import { event as d3_event } from 'd3-selection';\n\nimport { t } from '../core/localizer';\nimport { behaviorOperation } from '../behavior/operation';\nimport { uiCmd } from '../ui/cmd';\nimport { utilArrayGroupBy, utilTotalExtent } from '../util';\n\nexport function operationCopy(context, selectedIDs) {\n\n var _multi = selectedIDs.length === 1 ? 'single' : 'multiple';\n\n function getFilteredIdsToCopy() {\n return selectedIDs.filter(function(selectedID) {\n var entity = context.graph().hasEntity(selectedID);\n // don't copy untagged vertices separately from ways\n return entity.hasInterestingTags() || entity.geometry(context.graph()) !== 'vertex';\n });\n }\n\n var operation = function() {\n\n if (!getSelectionText()) {\n d3_event.preventDefault();\n }\n\n var graph = context.graph();\n var selected = groupEntities(getFilteredIdsToCopy(), graph);\n var canCopy = [];\n var skip = {};\n var entity;\n var i;\n\n for (i = 0; i < selected.relation.length; i++) {\n entity = selected.relation[i];\n if (!skip[entity.id] && entity.isComplete(graph)) {\n canCopy.push(entity.id);\n skip = getDescendants(entity.id, graph, skip);\n }\n }\n for (i = 0; i < selected.way.length; i++) {\n entity = selected.way[i];\n if (!skip[entity.id]) {\n canCopy.push(entity.id);\n skip = getDescendants(entity.id, graph, skip);\n }\n }\n for (i = 0; i < selected.node.length; i++) {\n entity = selected.node[i];\n if (!skip[entity.id]) {\n canCopy.push(entity.id);\n }\n }\n\n context.copyIDs(canCopy);\n if (_point &&\n (canCopy.length !== 1 || graph.entity(canCopy[0]).type !== 'node')) {\n // store the anchor coordinates if copying more than a single node\n context.copyLonLat(context.projection.invert(_point));\n } else {\n context.copyLonLat(null);\n }\n\n };\n\n\n function groupEntities(ids, graph) {\n var entities = ids.map(function (id) { return graph.entity(id); });\n return Object.assign(\n { relation: [], way: [], node: [] },\n utilArrayGroupBy(entities, 'type')\n );\n }\n\n\n function getDescendants(id, graph, descendants) {\n var entity = graph.entity(id);\n var children;\n\n descendants = descendants || {};\n\n if (entity.type === 'relation') {\n children = entity.members.map(function(m) { return m.id; });\n } else if (entity.type === 'way') {\n children = entity.nodes;\n } else {\n children = [];\n }\n\n for (var i = 0; i < children.length; i++) {\n if (!descendants[children[i]]) {\n descendants[children[i]] = true;\n descendants = getDescendants(children[i], graph, descendants);\n }\n }\n\n return descendants;\n }\n\n\n function getSelectionText() {\n return window.getSelection().toString();\n }\n\n\n operation.available = function() {\n return getFilteredIdsToCopy().length > 0;\n };\n\n\n operation.disabled = function() {\n var extent = utilTotalExtent(getFilteredIdsToCopy(), context.graph());\n if (extent.percentContainedIn(context.map().extent()) < 0.8) {\n return 'too_large';\n }\n return false;\n };\n\n\n operation.tooltip = function() {\n var disable = operation.disabled();\n return disable ?\n t('operations.copy.' + disable + '.' + _multi) :\n t('operations.copy.description' + '.' + _multi);\n };\n\n\n operation.annotation = function() {\n return selectedIDs.length === 1 ?\n t('operations.copy.annotation.single') :\n t('operations.copy.annotation.multiple', { n: selectedIDs.length.toString() });\n };\n\n\n var _point;\n operation.point = function(val) {\n _point = val;\n return operation;\n };\n\n\n operation.id = 'copy';\n operation.keys = [uiCmd('⌘C')];\n operation.title = t('operations.copy.title');\n operation.behavior = behaviorOperation(context).which(operation);\n\n return operation;\n}\n","import { t } from '../core/localizer';\nimport { actionDisconnect } from '../actions/disconnect';\nimport { behaviorOperation } from '../behavior/operation';\nimport { utilGetAllNodes, utilTotalExtent } from '../util/util';\n\n\nexport function operationDisconnect(context, selectedIDs) {\n var _vertexIDs = [];\n var _wayIDs = [];\n var _otherIDs = [];\n var _actions = [];\n\n selectedIDs.forEach(function(id) {\n var entity = context.entity(id);\n if (entity.type === 'way'){\n _wayIDs.push(id);\n } else if (entity.geometry(context.graph()) === 'vertex') {\n _vertexIDs.push(id);\n } else {\n _otherIDs.push(id);\n }\n });\n\n var _extent, _nodes, _coords, _descriptionID = '', _annotationID = 'features';\n\n if (_vertexIDs.length > 0) {\n // At the selected vertices, disconnect the selected ways, if any, else\n // disconnect all connected ways\n\n _extent = utilTotalExtent(_vertexIDs, context.graph());\n\n _vertexIDs.forEach(function(vertexID) {\n var action = actionDisconnect(vertexID);\n\n if (_wayIDs.length > 0) {\n var waysIDsForVertex = _wayIDs.filter(function(wayID) {\n var way = context.entity(wayID);\n return way.nodes.indexOf(vertexID) !== -1;\n });\n action.limitWays(waysIDsForVertex);\n }\n _actions.push(action);\n });\n\n _descriptionID += _actions.length === 1 ? 'single_point.' : 'multiple_points.';\n if (_wayIDs.length === 1) {\n _descriptionID += 'single_way.' + context.graph().geometry(_wayIDs[0]);\n } else {\n _descriptionID += _wayIDs.length === 0 ? 'no_ways' : 'multiple_ways';\n }\n\n } else if (_wayIDs.length > 0) {\n // Disconnect the selected ways from each other, if they're connected,\n // else disconnect them from all connected ways\n\n var ways = _wayIDs.map(function(id) {\n return context.entity(id);\n });\n _nodes = utilGetAllNodes(_wayIDs, context.graph());\n _coords = _nodes.map(function(n) { return n.loc; });\n _extent = utilTotalExtent(ways, context.graph());\n\n // actions for connected nodes shared by at least two selected ways\n var sharedActions = [];\n // actions for connected nodes\n var unsharedActions = [];\n\n _nodes.forEach(function(node) {\n var action = actionDisconnect(node.id).limitWays(_wayIDs);\n if (action.disabled(context.graph()) !== 'not_connected') {\n\n var count = 0;\n for (var i in ways) {\n var way = ways[i];\n if (way.nodes.indexOf(node.id) !== -1) {\n count += 1;\n }\n if (count > 1) break;\n }\n\n if (count > 1) {\n sharedActions.push(action);\n } else {\n unsharedActions.push(action);\n }\n }\n });\n\n _descriptionID += 'no_points.';\n _descriptionID += _wayIDs.length === 1 ? 'single_way.' : 'multiple_ways.';\n\n if (sharedActions.length) {\n // if any nodes are shared, only disconnect the selected ways from each other\n _actions = sharedActions;\n _descriptionID += 'conjoined';\n _annotationID = 'from_each_other';\n } else {\n // if no nodes are shared, disconnect the selected ways from all connected ways\n _actions = unsharedActions;\n if (_wayIDs.length === 1) {\n _descriptionID += context.graph().geometry(_wayIDs[0]);\n } else {\n _descriptionID += 'separate';\n }\n }\n }\n\n\n var operation = function() {\n context.perform(function(graph) {\n return _actions.reduce(function(graph, action) { return action(graph); }, graph);\n }, operation.annotation());\n\n context.validator().validate();\n };\n\n\n operation.available = function() {\n if (_actions.length === 0) return false;\n if (_otherIDs.length !== 0) return false;\n\n if (_vertexIDs.length !== 0 && _wayIDs.length !== 0 && !_wayIDs.every(function(wayID) {\n return _vertexIDs.some(function(vertexID) {\n var way = context.entity(wayID);\n return way.nodes.indexOf(vertexID) !== -1;\n });\n })) return false;\n\n return true;\n };\n\n\n operation.disabled = function() {\n var reason;\n for (var actionIndex in _actions) {\n reason = _actions[actionIndex].disabled(context.graph());\n if (reason) return reason;\n }\n\n if (_extent && _extent.percentContainedIn(context.map().extent()) < 0.8) {\n return 'too_large.' + ((_vertexIDs.length ? _vertexIDs : _wayIDs).length === 1 ? 'single' : 'multiple');\n } else if (_coords && someMissing()) {\n return 'not_downloaded';\n } else if (selectedIDs.some(context.hasHiddenConnections)) {\n return 'connected_to_hidden';\n }\n\n return false;\n\n\n function someMissing() {\n if (context.inIntro()) return false;\n var osm = context.connection();\n if (osm) {\n var missing = _coords.filter(function(loc) { return !osm.isDataLoaded(loc); });\n if (missing.length) {\n missing.forEach(function(loc) { context.loadTileAtLoc(loc); });\n return true;\n }\n }\n return false;\n }\n };\n\n\n operation.tooltip = function() {\n var disable = operation.disabled();\n if (disable) {\n return t('operations.disconnect.' + disable);\n }\n return t('operations.disconnect.description.' + _descriptionID);\n };\n\n\n operation.annotation = function() {\n return t('operations.disconnect.annotation.' + _annotationID);\n };\n\n\n operation.id = 'disconnect';\n operation.keys = [t('operations.disconnect.key')];\n operation.title = t('operations.disconnect.title');\n operation.behavior = behaviorOperation(context).which(operation);\n\n return operation;\n}\n","import { actionChangeTags } from '../actions/change_tags';\nimport { behaviorOperation } from '../behavior/operation';\nimport { modeSelect } from '../modes/select';\nimport { t } from '../core/localizer';\nimport { uiCmd } from '../ui/cmd';\nimport { presetManager } from '../presets';\n\nexport function operationDowngrade(context, selectedIDs) {\n var affectedFeatureCount = 0;\n var downgradeType;\n\n setDowngradeTypeForEntityIDs();\n\n var multi = affectedFeatureCount === 1 ? 'single' : 'multiple';\n\n function setDowngradeTypeForEntityIDs() {\n for (var i in selectedIDs) {\n var entityID = selectedIDs[i];\n var type = downgradeTypeForEntityID(entityID);\n if (type) {\n affectedFeatureCount += 1;\n if (downgradeType && type !== downgradeType) {\n downgradeType = 'building_address';\n } else {\n downgradeType = type;\n }\n }\n }\n }\n\n function downgradeTypeForEntityID(entityID) {\n var graph = context.graph();\n var entity = graph.entity(entityID);\n var preset = presetManager.match(entity, graph);\n\n if (!preset || preset.isFallback()) return null;\n\n if (entity.type === 'node' &&\n preset.id !== 'address' &&\n Object.keys(entity.tags).some(function(key) {\n return key.match(/^addr:.{1,}/);\n })) {\n\n return 'address';\n }\n if (entity.geometry(graph) === 'area' &&\n entity.tags.building &&\n !preset.tags.building) {\n\n return 'building';\n }\n\n return null;\n }\n\n var buildingKeysToKeep = ['architect', 'building', 'height', 'layer', 'source', 'type', 'wheelchair'];\n var addressKeysToKeep = ['source'];\n\n var operation = function () {\n context.perform(function(graph) {\n\n for (var i in selectedIDs) {\n var entityID = selectedIDs[i];\n var type = downgradeTypeForEntityID(entityID);\n if (!type) continue;\n\n var tags = Object.assign({}, graph.entity(entityID).tags); // shallow copy\n for (var key in tags) {\n if (type === 'address' && addressKeysToKeep.indexOf(key) !== -1) continue;\n if (type === 'building') {\n if (buildingKeysToKeep.indexOf(key) !== -1 ||\n key.match(/^building:.{1,}/) ||\n key.match(/^roof:.{1,}/)) continue;\n }\n // keep address tags for buildings too\n if (key.match(/^addr:.{1,}/)) continue;\n\n delete tags[key];\n }\n graph = actionChangeTags(entityID, tags)(graph);\n }\n return graph;\n }, operation.annotation());\n\n context.validator().validate();\n\n // refresh the select mode to enable the delete operation\n context.enter(modeSelect(context, selectedIDs));\n };\n\n\n operation.available = function () {\n return downgradeType;\n };\n\n\n operation.disabled = function () {\n if (selectedIDs.some(hasWikidataTag)) {\n return 'has_wikidata_tag';\n }\n return false;\n\n function hasWikidataTag(id) {\n var entity = context.entity(id);\n return entity.tags.wikidata && entity.tags.wikidata.trim().length > 0;\n }\n };\n\n\n operation.tooltip = function () {\n var disable = operation.disabled();\n return disable ?\n t('operations.downgrade.' + disable + '.' + multi) :\n t('operations.downgrade.description.' + downgradeType);\n };\n\n\n operation.annotation = function () {\n var suffix;\n if (downgradeType === 'building_address') {\n suffix = 'multiple';\n } else {\n suffix = downgradeType + '.' + multi;\n }\n return t('operations.downgrade.annotation.' + suffix, { n: affectedFeatureCount});\n };\n\n\n operation.id = 'downgrade';\n operation.keys = [uiCmd('⌘⌫'), uiCmd('⌘⌦'), uiCmd('⌦')];\n operation.title = t('operations.downgrade.title');\n operation.behavior = behaviorOperation(context).which(operation);\n\n\n return operation;\n}\n","import { actionExtract } from '../actions/extract';\nimport { behaviorOperation } from '../behavior/operation';\nimport { modeSelect } from '../modes/select';\nimport { t } from '../core/localizer';\nimport { presetManager } from '../presets';\nimport { utilArrayUniq } from '../util/array';\n\nexport function operationExtract(context, selectedIDs) {\n\n var _amount = selectedIDs.length === 1 ? 'single' : 'multiple';\n var _geometries = utilArrayUniq(selectedIDs.map(function(entityID) {\n return context.graph().hasEntity(entityID) && context.graph().geometry(entityID);\n }).filter(Boolean));\n var _geometryID = _geometries.length === 1 ? _geometries[0] : 'feature';\n\n var _extent;\n var _actions = selectedIDs.map(function(entityID) {\n var graph = context.graph();\n var entity = graph.hasEntity(entityID);\n if (!entity || !entity.hasInterestingTags()) return;\n\n if (entity.type === 'node' && graph.parentWays(entity).length === 0) return;\n\n if (entity.type !== 'node') {\n var preset = presetManager.match(entity, graph);\n // only allow extraction from ways/relations if the preset supports points\n if (preset.geometry.indexOf('point') === -1) return;\n }\n\n _extent = _extent ? _extent.extend(entity.extent(graph)) : entity.extent(graph);\n\n return actionExtract(entityID);\n }).filter(Boolean);\n\n\n var operation = function () {\n var combinedAction = function(graph) {\n _actions.forEach(function(action) {\n graph = action(graph);\n });\n return graph;\n };\n context.perform(combinedAction, operation.annotation()); // do the extract\n\n var extractedNodeIDs = _actions.map(function(action) {\n return action.getExtractedNodeID();\n });\n context.enter(modeSelect(context, extractedNodeIDs));\n };\n\n\n operation.available = function () {\n return _actions.length && selectedIDs.length === _actions.length;\n };\n\n\n operation.disabled = function () {\n\n if (_extent && _extent.percentContainedIn(context.map().extent()) < 0.8) {\n return 'too_large';\n } else if (selectedIDs.some(function(entityID) {\n return context.graph().geometry(entityID) === 'vertex' && context.hasHiddenConnections(entityID);\n })) {\n return 'connected_to_hidden';\n }\n\n return false;\n };\n\n\n operation.tooltip = function () {\n var disableReason = operation.disabled();\n if (disableReason) {\n return t('operations.extract.' + disableReason + '.' + _amount);\n } else {\n return t('operations.extract.description.' + _geometryID + '.' + _amount);\n }\n };\n\n\n operation.annotation = function () {\n return t('operations.extract.annotation.' + _amount, { n: selectedIDs.length });\n };\n\n\n operation.id = 'extract';\n operation.keys = [t('operations.extract.key')];\n operation.title = t('operations.extract.title');\n operation.behavior = behaviorOperation(context).which(operation);\n\n\n return operation;\n}\n","import { t } from '../core/localizer';\n\nimport { actionJoin } from '../actions/join';\nimport { actionMerge } from '../actions/merge';\nimport { actionMergeNodes } from '../actions/merge_nodes';\nimport { actionMergePolygon } from '../actions/merge_polygon';\n\nimport { behaviorOperation } from '../behavior/operation';\nimport { modeSelect } from '../modes/select';\nimport { presetManager } from '../presets';\n\nexport function operationMerge(context, selectedIDs) {\n\n var _action = getAction();\n\n function getAction() {\n // prefer a non-disabled action first\n var join = actionJoin(selectedIDs);\n if (!join.disabled(context.graph())) return join;\n\n var merge = actionMerge(selectedIDs);\n if (!merge.disabled(context.graph())) return merge;\n\n var mergePolygon = actionMergePolygon(selectedIDs);\n if (!mergePolygon.disabled(context.graph())) return mergePolygon;\n\n var mergeNodes = actionMergeNodes(selectedIDs);\n if (!mergeNodes.disabled(context.graph())) return mergeNodes;\n\n // otherwise prefer an action with an interesting disabled reason\n if (join.disabled(context.graph()) !== 'not_eligible') return join;\n if (merge.disabled(context.graph()) !== 'not_eligible') return merge;\n if (mergePolygon.disabled(context.graph()) !== 'not_eligible') return mergePolygon;\n\n return mergeNodes;\n }\n\n var operation = function() {\n\n if (operation.disabled()) return;\n\n context.perform(_action, operation.annotation());\n\n context.validator().validate();\n\n var resultIDs = selectedIDs.filter(context.hasEntity);\n if (resultIDs.length > 1) {\n var interestingIDs = resultIDs.filter(function(id) {\n return context.entity(id).hasInterestingTags();\n });\n if (interestingIDs.length) resultIDs = interestingIDs;\n }\n context.enter(modeSelect(context, resultIDs));\n };\n\n operation.available = function() {\n return selectedIDs.length >= 2;\n };\n\n operation.disabled = function() {\n var actionDisabled = _action.disabled(context.graph());\n if (actionDisabled) return actionDisabled;\n\n var osm = context.connection();\n if (osm &&\n _action.resultingWayNodesLength &&\n _action.resultingWayNodesLength(context.graph()) > osm.maxWayNodes()) {\n return 'too_many_vertices';\n }\n\n return false;\n };\n\n operation.tooltip = function() {\n var disabled = operation.disabled();\n if (disabled) {\n if (disabled === 'restriction') {\n return t('operations.merge.restriction',\n { relation: presetManager.item('type/restriction').name() });\n }\n return t('operations.merge.' + disabled);\n }\n return t('operations.merge.description');\n };\n\n operation.annotation = function() {\n return t('operations.merge.annotation', { n: selectedIDs.length });\n };\n\n operation.id = 'merge';\n operation.keys = [t('operations.merge.key')];\n operation.title = t('operations.merge.title');\n operation.behavior = behaviorOperation(context).which(operation);\n\n return operation;\n}\n","\nimport { actionCopyEntities } from '../actions/copy_entities';\nimport { actionMove } from '../actions/move';\nimport { modeSelect } from '../modes/select';\nimport { geoExtent, geoVecSubtract } from '../geo';\nimport { t } from '../core/localizer';\nimport { uiCmd } from '../ui/cmd';\nimport { utilDisplayLabel } from '../util/util';\n\n// see also `behaviorPaste`\nexport function operationPaste(context) {\n\n var _pastePoint;\n\n var operation = function() {\n\n if (!_pastePoint) return;\n\n var oldIDs = context.copyIDs();\n if (!oldIDs.length) return;\n\n var projection = context.projection;\n var extent = geoExtent();\n var oldGraph = context.copyGraph();\n var newIDs = [];\n\n var action = actionCopyEntities(oldIDs, oldGraph);\n context.perform(action);\n\n var copies = action.copies();\n var originals = new Set();\n Object.values(copies).forEach(function(entity) { originals.add(entity.id); });\n\n for (var id in copies) {\n var oldEntity = oldGraph.entity(id);\n var newEntity = copies[id];\n\n extent._extend(oldEntity.extent(oldGraph));\n\n // Exclude child nodes from newIDs if their parent way was also copied.\n var parents = context.graph().parentWays(newEntity);\n var parentCopied = parents.some(function(parent) {\n return originals.has(parent.id);\n });\n\n if (!parentCopied) {\n newIDs.push(newEntity.id);\n }\n }\n\n // Use the location of the copy operation to offset the paste location,\n // or else use the center of the pasted extent\n var copyPoint = (context.copyLonLat() && projection(context.copyLonLat())) ||\n projection(extent.center());\n var delta = geoVecSubtract(_pastePoint, copyPoint);\n\n // Move the pasted objects to be anchored at the paste location\n context.replace(actionMove(newIDs, delta, projection), operation.annotation());\n context.enter(modeSelect(context, newIDs));\n };\n\n operation.point = function(val) {\n _pastePoint = val;\n return operation;\n };\n\n operation.available = function() {\n return context.mode().id === 'browse';\n };\n\n operation.disabled = function() {\n return !context.copyIDs().length;\n };\n\n operation.tooltip = function() {\n var oldGraph = context.copyGraph();\n var ids = context.copyIDs();\n if (!ids.length) {\n return t('operations.paste.nothing_copied');\n }\n return ids.length === 1 ?\n t('operations.paste.description.single', { feature: utilDisplayLabel(oldGraph.entity(ids[0]), oldGraph) }) :\n t('operations.paste.description.multiple', { n: ids.length.toString() });\n };\n\n operation.annotation = function() {\n var ids = context.copyIDs();\n return ids.length === 1 ?\n t('operations.paste.annotation.single') :\n t('operations.paste.annotation.multiple', { n: ids.length.toString() });\n };\n\n operation.id = 'paste';\n operation.keys = [uiCmd('⌘V')];\n operation.title = t('operations.paste.title');\n\n return operation;\n}\n","import { t } from '../core/localizer';\nimport { actionReverse } from '../actions/reverse';\nimport { behaviorOperation } from '../behavior/operation';\n\n\nexport function operationReverse(context, selectedIDs) {\n\n var operation = function() {\n context.perform(function combinedReverseAction(graph) {\n actions().forEach(function(action) {\n graph = action(graph);\n });\n return graph;\n }, operation.annotation());\n context.validator().validate();\n };\n\n function actions(situation) {\n return selectedIDs.map(function(entityID) {\n var entity = context.hasEntity(entityID);\n if (!entity) return;\n\n if (situation === 'toolbar') {\n if (entity.type === 'way' &&\n (!entity.isOneWay() && !entity.isSided())) return;\n }\n\n var geometry = entity.geometry(context.graph());\n if (entity.type !== 'node' && geometry !== 'line') return;\n\n var action = actionReverse(entityID);\n if (action.disabled(context.graph())) return;\n\n return action;\n }).filter(Boolean);\n }\n\n function reverseTypeID() {\n var acts = actions();\n var nodeActionCount = acts.filter(function(act) {\n var entity = context.hasEntity(act.entityID());\n return entity && entity.type === 'node';\n }).length;\n var typeID = nodeActionCount === 0 ? 'line' : (nodeActionCount === acts.length ? 'point' : 'features');\n if (typeID !== 'features' && acts.length > 1) typeID += 's';\n return typeID;\n }\n\n\n operation.available = function(situation) {\n return actions(situation).length > 0;\n };\n\n\n operation.disabled = function() {\n return false;\n };\n\n\n operation.tooltip = function() {\n return t('operations.reverse.description.' + reverseTypeID());\n };\n\n\n operation.annotation = function() {\n return t('operations.reverse.annotation.' + reverseTypeID());\n };\n\n\n operation.id = 'reverse';\n operation.keys = [t('operations.reverse.key')];\n operation.title = t('operations.reverse.title');\n operation.behavior = behaviorOperation(context).which(operation);\n\n return operation;\n}\n","import { t } from '../core/localizer';\nimport { actionSplit } from '../actions/split';\nimport { behaviorOperation } from '../behavior/operation';\nimport { modeSelect } from '../modes/select';\n\n\nexport function operationSplit(context, selectedIDs) {\n var vertices = selectedIDs\n .filter(function(id) { return context.graph().geometry(id) === 'vertex'; });\n var entityID = vertices[0];\n var action = actionSplit(entityID);\n var ways = [];\n\n if (vertices.length === 1) {\n if (entityID && selectedIDs.length > 1) {\n var ids = selectedIDs.filter(function(id) { return id !== entityID; });\n action.limitWays(ids);\n }\n ways = action.ways(context.graph());\n }\n\n\n var operation = function() {\n var difference = context.perform(action, operation.annotation());\n context.enter(modeSelect(context, difference.extantIDs()));\n };\n\n\n operation.available = function() {\n return vertices.length === 1;\n };\n\n\n operation.disabled = function() {\n var reason = action.disabled(context.graph());\n if (reason) {\n return reason;\n } else if (selectedIDs.some(context.hasHiddenConnections)) {\n return 'connected_to_hidden';\n }\n\n return false;\n };\n\n\n operation.tooltip = function() {\n var disable = operation.disabled();\n if (disable) {\n return t('operations.split.' + disable);\n } else if (ways.length === 1) {\n return t('operations.split.description.' + context.graph().geometry(ways[0].id));\n } else {\n return t('operations.split.description.multiple');\n }\n };\n\n\n operation.annotation = function() {\n return ways.length === 1 ?\n t('operations.split.annotation.' + context.graph().geometry(ways[0].id)) :\n t('operations.split.annotation.multiple', { n: ways.length });\n };\n\n\n operation.id = 'split';\n operation.keys = [t('operations.split.key')];\n operation.title = t('operations.split.title');\n operation.behavior = behaviorOperation(context).which(operation);\n\n return operation;\n}\n","import { t } from '../core/localizer';\nimport { actionStraightenNodes } from '../actions/straighten_nodes';\nimport { actionStraightenWay } from '../actions/straighten_way';\nimport { behaviorOperation } from '../behavior/operation';\nimport { utilArrayDifference, utilGetAllNodes, utilTotalExtent } from '../util/index';\n\n\nexport function operationStraighten(context, selectedIDs) {\n var _wayIDs = selectedIDs.filter(function(id) { return id.charAt(0) === 'w'; });\n var _nodeIDs = selectedIDs.filter(function(id) { return id.charAt(0) === 'n'; });\n var _amount = ((_wayIDs.length ? _wayIDs : _nodeIDs).length === 1 ? 'single' : 'multiple');\n\n var _nodes = utilGetAllNodes(selectedIDs, context.graph());\n var _coords = _nodes.map(function(n) { return n.loc; });\n var _extent = utilTotalExtent(selectedIDs, context.graph());\n var _action = chooseAction();\n var _geometry;\n\n\n function chooseAction() {\n // straighten selected nodes\n if (_wayIDs.length === 0 && _nodeIDs.length > 2) {\n _geometry = 'points';\n return actionStraightenNodes(_nodeIDs, context.projection);\n\n // straighten selected ways (possibly between range of 2 selected nodes)\n } else if (_wayIDs.length > 0 && (_nodeIDs.length === 0 || _nodeIDs.length === 2)) {\n var startNodeIDs = [];\n var endNodeIDs = [];\n\n for (var i = 0; i < selectedIDs.length; i++) {\n var entity = context.entity(selectedIDs[i]);\n if (entity.type === 'node') {\n continue;\n } else if (entity.type !== 'way' || entity.isClosed()) {\n return null; // exit early, can't straighten these\n }\n\n startNodeIDs.push(entity.first());\n endNodeIDs.push(entity.last());\n }\n\n // Remove duplicate end/startNodeIDs (duplicate nodes cannot be at the line end)\n startNodeIDs = startNodeIDs.filter(function(n) {\n return startNodeIDs.indexOf(n) === startNodeIDs.lastIndexOf(n);\n });\n endNodeIDs = endNodeIDs.filter(function(n) {\n return endNodeIDs.indexOf(n) === endNodeIDs.lastIndexOf(n);\n });\n\n // Ensure all ways are connected (i.e. only 2 unique endpoints/startpoints)\n if (utilArrayDifference(startNodeIDs, endNodeIDs).length +\n utilArrayDifference(endNodeIDs, startNodeIDs).length !== 2) return null;\n\n // Ensure path contains at least 3 unique nodes\n var wayNodeIDs = utilGetAllNodes(_wayIDs, context.graph())\n .map(function(node) { return node.id; });\n if (wayNodeIDs.length <= 2) return null;\n\n // If range of 2 selected nodes is supplied, ensure nodes lie on the selected path\n if (_nodeIDs.length === 2 && (\n wayNodeIDs.indexOf(_nodeIDs[0]) === -1 || wayNodeIDs.indexOf(_nodeIDs[1]) === -1\n )) return null;\n\n if (_nodeIDs.length) {\n // If we're only straightenting between two points, we only need that extent visible\n _extent = utilTotalExtent(_nodeIDs, context.graph());\n }\n\n _geometry = _wayIDs.length === 1 ? 'line' : 'lines';\n return actionStraightenWay(selectedIDs, context.projection);\n }\n\n return null;\n }\n\n\n function operation() {\n if (!_action) return;\n\n context.perform(_action, operation.annotation());\n\n window.setTimeout(function() {\n context.validator().validate();\n }, 300); // after any transition\n }\n\n\n operation.available = function() {\n return Boolean(_action);\n };\n\n\n operation.disabled = function() {\n var reason = _action.disabled(context.graph());\n if (reason) {\n return reason;\n } else if (_extent.percentContainedIn(context.map().extent()) < 0.8) {\n return 'too_large';\n } else if (someMissing()) {\n return 'not_downloaded';\n } else if (selectedIDs.some(context.hasHiddenConnections)) {\n return 'connected_to_hidden';\n }\n\n return false;\n\n\n function someMissing() {\n if (context.inIntro()) return false;\n var osm = context.connection();\n if (osm) {\n var missing = _coords.filter(function(loc) { return !osm.isDataLoaded(loc); });\n if (missing.length) {\n missing.forEach(function(loc) { context.loadTileAtLoc(loc); });\n return true;\n }\n }\n return false;\n }\n };\n\n\n operation.tooltip = function() {\n var disable = operation.disabled();\n return disable ?\n t('operations.straighten.' + disable + '.' + _amount) :\n t('operations.straighten.description.' + _geometry);\n };\n\n\n operation.annotation = function() {\n return t('operations.straighten.annotation.' + _geometry);\n };\n\n\n operation.id = 'straighten';\n operation.keys = [t('operations.straighten.key')];\n operation.title = t('operations.straighten.title');\n operation.behavior = behaviorOperation(context).which(operation);\n\n return operation;\n}\n","import { geoSphericalDistance } from '../geo';\nimport { modeDrawLine } from '../modes';\nimport { operationDelete } from '../operations/index';\nimport { t } from '../core/localizer';\nimport { utilDisplayLabel } from '../util';\nimport { validationIssue, validationIssueFix } from '../core/validation';\n\n\nexport function validationShortRoad(context) {\n var type = 'short_road';\n\n // Thresholds for number of nodes and total length for a short road. A road\n // is considered as \"short\" only if it has less than 7 nodes and is shorter\n // than 20 meters.\n var SHORT_WAY_NODES_THD = 7;\n var SHORT_WAY_LENGTH_THD_METERS = 20;\n\n\n function wayLength(way, graph) {\n var length = 0;\n for (var i = 0; i < way.nodes.length - 1; i++) {\n var n1 = graph.entity(way.nodes[i]),\n n2 = graph.entity(way.nodes[i + 1]);\n length += geoSphericalDistance(n1.loc, n2.loc);\n }\n return length;\n }\n\n function continueDrawing(way, vertex, context) {\n // make sure the vertex is actually visible and editable\n var map = context.map();\n if (!map.editable() || !map.trimmedExtent().contains(vertex.loc)) {\n map.zoomToEase(vertex);\n }\n\n context.enter(\n modeDrawLine(context, way.id, context.graph(), context.graph(), '', way.affix(vertex.id), true)\n );\n }\n\n\n var validation = function(entity, graph) {\n if (entity.type !== 'way' || !entity.tags.highway || entity.isClosed() || entity.nodes.length >= SHORT_WAY_NODES_THD) return [];\n\n var firstNode = graph.entity(entity.first()),\n lastNode = graph.entity(entity.last()),\n pwaysStart = graph.parentWays(firstNode),\n pwaysEnd = graph.parentWays(lastNode),\n firstNodeOK = pwaysStart.length > 1 || firstNode.tags.noexit === 'yes',\n lastNodeOK = pwaysEnd.length > 1 || lastNode.tags.noexit === 'yes';\n // only do check on roads with open ends\n if ((firstNodeOK && lastNodeOK) || wayLength(entity, graph) >= SHORT_WAY_LENGTH_THD_METERS) return [];\n\n var fixes = [];\n if (!firstNodeOK) {\n fixes.push(new validationIssueFix({\n icon: 'iD-operation-continue-left',\n title: t('issues.fix.continue_from_start.title'),\n entityIds: [entity.first()],\n onClick: function() {\n var vertex = context.entity(entity.first());\n continueDrawing(entity, vertex, context);\n }\n }));\n }\n if (!lastNodeOK) {\n fixes.push(new validationIssueFix({\n icon: 'iD-operation-continue',\n title: t('issues.fix.continue_from_end.title'),\n entityIds: [entity.last()],\n onClick: function() {\n var vertex = context.entity(entity.last());\n continueDrawing(entity, vertex, context);\n }\n }));\n }\n if (!operationDelete(context, [entity.id]).disabled()) {\n fixes.push(new validationIssueFix({\n icon: 'iD-operation-delete',\n title: t('issues.fix.delete_feature.title'),\n entityIds: [entity.id],\n onClick: function() {\n var id = this.issue.entityIds[0];\n var operation = operationDelete(context, [id]);\n if (!operation.disabled()) {\n operation();\n }\n }\n }));\n }\n\n return [new validationIssue({\n type: type,\n severity: 'warning',\n message: function(context) {\n var entity = context.hasEntity(this.entityIds[0]);\n if (!entity) return '';\n var entityLabel = utilDisplayLabel(entity, context.graph());\n return t('issues.short_road.message', { highway: entityLabel });\n },\n reference: function(selection) {\n selection.selectAll('.issue-reference')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'issue-reference')\n .text(t('issues.short_road.reference'));\n },\n entityIds: [entity.id],\n fixes: fixes\n })];\n };\n\n\n validation.type = type;\n\n return validation;\n}\n","import { geoAngle, geoSphericalDistance } from '../geo';\nimport { operationDelete } from '../operations/index';\nimport { t } from '../core/localizer';\nimport { validationIssue, validationIssueFix } from '../core/validation';\n\n\nexport function validationYShapedConnection(context) {\n /* We want to catch and warn about the following \"shapes of connections\"\n * that may appear in ML-generated roads:\n * (1) Two short edges around a connection node, causing a \"Y-shaped\" connection\n * ________ _______\n * V\n * |\n * |\n * |\n * (2) One short edges around a connection node. The connection is not exactly\n * \"Y-shaped\", but still a little too detailed.\n * _______\n * ___________ /\n * |\n * |\n * |\n * The potential fix is to remove the non-connection nodes causing the short edges,\n * so that the shape of the connection becomes more like a \"T\".\n *\n * This validation will flag issues on those excessive non-connection nodes around\n * Y-shaped connections and suggest deletion or move as possible fixes.\n */\n\n var type = 'y_shaped_connection';\n // THD means \"threshold\"\n var SHORT_EDGE_THD_METERS = 12;\n var NON_FLAT_ANGLE_THD_DEGREES = 5;\n\n var relatedHighways = {\n residential: true, service: true, track: true, unclassified: true,\n tertiary: true, secondary: true, primary: true, living_street: true,\n cycleway: true, trunk: true, motorway: true, road: true, raceway: true\n };\n\n\n function isTaggedAsRelatedHighway(entity) {\n return relatedHighways[entity.tags.highway];\n }\n\n function getRelatedHighwayParents(node, graph) {\n var parentWays = graph.parentWays(node);\n return parentWays.filter(function (way) {\n return isTaggedAsRelatedHighway(way);\n });\n }\n\n function createIssueAndFixForNode(node, context) {\n var deletable = !operationDelete(context, [node.id]).disabled();\n var fix = undefined;\n if (deletable) {\n fix = new validationIssueFix({\n icon: 'iD-operation-delete',\n title: t('issues.fix.delete_node_around_conn.title'),\n entityIds: [node.id],\n onClick: function() {\n var id = this.entityIds[0];\n var operation = operationDelete(context, [id]);\n if (!operation.disabled()) {\n operation();\n }\n }\n });\n } else {\n fix = new validationIssueFix({\n icon: 'iD-operation-move',\n title: t('issues.fix.move_node_around_conn.title'),\n entityIds: [node.id]\n });\n }\n\n return new validationIssue({\n type: type,\n severity: 'warning',\n message: function() {\n return t('issues.y_shaped_connection.message');\n },\n reference: function(selection) {\n selection.selectAll('.issue-reference')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'issue-reference')\n .text(t('issues.y_shaped_connection.reference'));\n },\n entityIds: [node.id],\n fixes: [fix]\n });\n }\n\n // Check\n // (1) if the edge between connNodeIdx and edgeNodeIdx is a short edge\n // (2) if the node at connNodeIdx is a Y-shaped connection\n // return true only if both (1) and (2) hold.\n function isShortEdgeAndYShapedConnection(graph, way, connNodeIdx, edgeNodeIdx) {\n // conditions for connNode to be a possible Y-shaped connection:\n // (1) it is a connection node with edges on both side\n // (2) at least one edge is short\n // (3) the angle between the two edges are not close to 180 degrees\n\n if (connNodeIdx <= 0 || connNodeIdx >= way.nodes.length - 1) return false;\n\n // make sure the node at connNodeIdx is really a connection node\n var connNid = way.nodes[connNodeIdx];\n var connNode = graph.entity(connNid);\n var pways = getRelatedHighwayParents(connNode, graph);\n if (pways.length < 2) return false;\n\n // check if the edge between connNode and edgeNode is short\n var edgeNid = way.nodes[edgeNodeIdx];\n var edgeNode = graph.entity(edgeNid);\n var edgeLen = geoSphericalDistance(connNode.loc, edgeNode.loc);\n if (edgeLen > SHORT_EDGE_THD_METERS) return false;\n\n // check if connNode is a Y-shaped connection\n var prevEdgeGeoAngle = 0;\n var nextEdgeGeoAngle = 0;\n var angleBetweenEdges = 0;\n var otherNodeIdx = connNodeIdx < edgeNodeIdx ? connNodeIdx - 1 : connNodeIdx + 1;\n var otherNid = way.nodes[otherNodeIdx];\n var otherNode = graph.entity(otherNid);\n if (otherNodeIdx < edgeNodeIdx) {\n // node order along way: otherNode -> connNode -> edgeNode\n prevEdgeGeoAngle = geoAngle(otherNode, connNode, context.projection);\n nextEdgeGeoAngle = geoAngle(connNode, edgeNode, context.projection);\n angleBetweenEdges = Math.abs(nextEdgeGeoAngle - prevEdgeGeoAngle) / Math.PI * 180.0;\n } else {\n // node order along way: edgeNode -> connNode -> otherNode\n prevEdgeGeoAngle = geoAngle(edgeNode, connNode, context.projection);\n nextEdgeGeoAngle = geoAngle(connNode, otherNode, context.projection);\n angleBetweenEdges = Math.abs(nextEdgeGeoAngle - prevEdgeGeoAngle) / Math.PI * 180.0;\n }\n\n return angleBetweenEdges > NON_FLAT_ANGLE_THD_DEGREES;\n }\n\n\n var validation = function(entity, graph) {\n // Only flag issue on non-connection nodes on negative ways\n if (entity.type !== 'node') return [];\n var pways = getRelatedHighwayParents(entity, graph);\n if (pways.length !== 1 || !pways[0].id.startsWith('w-')) return [];\n\n // check if either neighbor node on its parent way is a connection node\n var issues = [];\n var way = pways[0];\n var idx = way.nodes.indexOf(entity.id);\n if (idx <= 0) return issues;\n if (isShortEdgeAndYShapedConnection(graph, way, idx - 1, idx) ||\n isShortEdgeAndYShapedConnection(graph, way, idx + 1, idx)) {\n issues.push(createIssueAndFixForNode(entity, context));\n }\n return issues;\n };\n\n\n validation.type = type;\n\n return validation;\n}\n","import { fileFetcher } from '../core/file_fetcher';\nimport { localizer } from '../core/localizer';\nimport { t } from '../core/localizer';\nimport { presetManager } from '../presets';\nimport { validationIssue, validationIssueFix } from '../core/validation';\nimport { actionChangeTags } from '../actions/change_tags';\n\n\nlet _discardNameRegexes = [];\n\nexport function validationSuspiciousName() {\n const type = 'suspicious_name';\n const keysToTestForGenericValues = [\n 'aerialway', 'aeroway', 'amenity', 'building', 'craft', 'highway',\n 'leisure', 'railway', 'man_made', 'office', 'shop', 'tourism', 'waterway'\n ];\n\n // A concern here in switching to async data means that `_nsiFilters` will not\n // be available at first, so the data on early tiles may not have tags validated fully.\n\n fileFetcher.get('nsi_filters')\n .then(filters => {\n // known list of generic names (e.g. \"bar\")\n _discardNameRegexes = filters.discardNames\n .map(discardName => new RegExp(discardName, 'i'));\n })\n .catch(() => { /* ignore */ });\n\n\n function isDiscardedSuggestionName(lowercaseName) {\n return _discardNameRegexes.some(regex => regex.test(lowercaseName));\n }\n\n // test if the name is just the key or tag value (e.g. \"park\")\n function nameMatchesRawTag(lowercaseName, tags) {\n for (let i = 0; i < keysToTestForGenericValues.length; i++) {\n let key = keysToTestForGenericValues[i];\n let val = tags[key];\n if (val) {\n val = val.toLowerCase();\n if (key === lowercaseName ||\n val === lowercaseName ||\n key.replace(/\\_/g, ' ') === lowercaseName ||\n val.replace(/\\_/g, ' ') === lowercaseName) {\n return true;\n }\n }\n }\n return false;\n }\n\n function isGenericName(name, tags) {\n name = name.toLowerCase();\n return nameMatchesRawTag(name, tags) || isDiscardedSuggestionName(name);\n }\n\n function makeGenericNameIssue(entityId, nameKey, genericName, langCode) {\n return new validationIssue({\n type: type,\n subtype: 'generic_name',\n severity: 'warning',\n message: function(context) {\n let entity = context.hasEntity(this.entityIds[0]);\n if (!entity) return '';\n let preset = presetManager.match(entity, context.graph());\n let langName = langCode && localizer.languageName(langCode);\n return t('issues.generic_name.message' + (langName ? '_language' : ''),\n { feature: preset.name(), name: genericName, language: langName }\n );\n },\n reference: showReference,\n entityIds: [entityId],\n hash: nameKey + '=' + genericName,\n dynamicFixes: function() {\n return [\n new validationIssueFix({\n icon: 'iD-operation-delete',\n title: t('issues.fix.remove_the_name.title'),\n onClick: function(context) {\n let entityId = this.issue.entityIds[0];\n let entity = context.entity(entityId);\n let tags = Object.assign({}, entity.tags); // shallow copy\n delete tags[nameKey];\n context.perform(\n actionChangeTags(entityId, tags), t('issues.fix.remove_generic_name.annotation')\n );\n }\n })\n ];\n }\n });\n\n function showReference(selection) {\n selection.selectAll('.issue-reference')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'issue-reference')\n .text(t('issues.generic_name.reference'));\n }\n }\n\n function makeIncorrectNameIssue(entityId, nameKey, incorrectName, langCode) {\n return new validationIssue({\n type: type,\n subtype: 'not_name',\n severity: 'warning',\n message: function(context) {\n const entity = context.hasEntity(this.entityIds[0]);\n if (!entity) return '';\n const preset = presetManager.match(entity, context.graph());\n const langName = langCode && localizer.languageName(langCode);\n return t('issues.incorrect_name.message' + (langName ? '_language' : ''),\n { feature: preset.name(), name: incorrectName, language: langName }\n );\n },\n reference: showReference,\n entityIds: [entityId],\n hash: nameKey + '=' + incorrectName,\n dynamicFixes: function() {\n return [\n new validationIssueFix({\n icon: 'iD-operation-delete',\n title: t('issues.fix.remove_the_name.title'),\n onClick: function(context) {\n const entityId = this.issue.entityIds[0];\n const entity = context.entity(entityId);\n let tags = Object.assign({}, entity.tags); // shallow copy\n delete tags[nameKey];\n context.perform(\n actionChangeTags(entityId, tags), t('issues.fix.remove_mistaken_name.annotation')\n );\n }\n })\n ];\n }\n });\n\n function showReference(selection) {\n selection.selectAll('.issue-reference')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'issue-reference')\n .text(t('issues.generic_name.reference'));\n }\n }\n\n\n let validation = function checkGenericName(entity) {\n // a generic name is okay if it's a known brand or entity\n if (entity.hasWikidata()) return [];\n\n let issues = [];\n const notNames = (entity.tags['not:name'] || '').split(';');\n\n for (let key in entity.tags) {\n const m = key.match(/^name(?:(?::)([a-zA-Z_-]+))?$/);\n if (!m) continue;\n\n const langCode = m.length >= 2 ? m[1] : null;\n const value = entity.tags[key];\n if (notNames.length) {\n for (let i in notNames) {\n const notName = notNames[i];\n if (notName && value === notName) {\n issues.push(makeIncorrectNameIssue(entity.id, key, value, langCode));\n continue;\n }\n }\n }\n if (isGenericName(value, entity.tags)) {\n issues.push(makeGenericNameIssue(entity.id, key, value, langCode));\n }\n }\n\n return issues;\n };\n\n\n validation.type = type;\n\n return validation;\n}\n","import { prefs } from '../core/preferences';\nimport { t } from '../core/localizer';\n//import { actionChangeTags } from '../actions/change_tags';\nimport { actionOrthogonalize } from '../actions/orthogonalize';\nimport { geoOrthoCanOrthogonalize } from '../geo/ortho';\nimport { utilDisplayLabel } from '../util';\nimport { validationIssue, validationIssueFix } from '../core/validation';\nimport { services } from '../services';\n\nexport function validationUnsquareWay(context) {\n var type = 'unsquare_way';\n var DEFAULT_DEG_THRESHOLD = 5; // see also issues.js\n\n // use looser epsilon for detection to reduce warnings of buildings that are essentially square already\n var epsilon = 0.05;\n var nodeThreshold = 10;\n\n function isBuilding(entity, graph) {\n if (entity.type !== 'way' || entity.geometry(graph) !== 'area') return false;\n return entity.tags.building && entity.tags.building !== 'no';\n }\n\n\n var validation = function checkUnsquareWay(entity, graph) {\n\n if (!isBuilding(entity, graph)) return [];\n\n // don't flag ways marked as physically unsquare\n if (entity.tags.nonsquare === 'yes') return [];\n\n var isClosed = entity.isClosed();\n if (!isClosed) return []; // this building has bigger problems\n\n // don't flag ways with lots of nodes since they are likely detail-mapped\n var nodes = graph.childNodes(entity).slice(); // shallow copy\n if (nodes.length > nodeThreshold + 1) return []; // +1 because closing node appears twice\n\n // ignore if not all nodes are fully downloaded\n var osm = services.osm;\n if (!osm || nodes.some(function(node) { return !osm.isDataLoaded(node.loc); })) return [];\n\n // don't flag connected ways to avoid unresolvable unsquare loops\n var hasConnectedSquarableWays = nodes.some(function(node) {\n return graph.parentWays(node).some(function(way) {\n if (way.id === entity.id) return false;\n if (isBuilding(way, graph)) return true;\n return graph.parentRelations(way).some(function(parentRelation) {\n return parentRelation.isMultipolygon() &&\n parentRelation.tags.building &&\n parentRelation.tags.building !== 'no';\n });\n });\n });\n if (hasConnectedSquarableWays) return [];\n\n\n // user-configurable square threshold\n var storedDegreeThreshold = prefs('validate-square-degrees');\n var degreeThreshold = isNaN(storedDegreeThreshold) ? DEFAULT_DEG_THRESHOLD : parseFloat(storedDegreeThreshold);\n\n var points = nodes.map(function(node) { return context.projection(node.loc); });\n if (!geoOrthoCanOrthogonalize(points, isClosed, epsilon, degreeThreshold, true)) return [];\n\n var autoArgs;\n // don't allow autosquaring features linked to wikidata\n if (!entity.tags.wikidata) {\n // use same degree threshold as for detection\n var autoAction = actionOrthogonalize(entity.id, context.projection, undefined, degreeThreshold);\n autoAction.transitionable = false; // when autofixing, do it instantly\n autoArgs = [autoAction, t('operations.orthogonalize.annotation.feature.single')];\n }\n\n return [new validationIssue({\n type: type,\n subtype: 'building',\n severity: 'warning',\n message: function(context) {\n var entity = context.hasEntity(this.entityIds[0]);\n return entity ? t('issues.unsquare_way.message', { feature: utilDisplayLabel(entity, context.graph()) }) : '';\n },\n reference: showReference,\n entityIds: [entity.id],\n hash: JSON.stringify(autoArgs !== undefined) + degreeThreshold,\n autoArgs: autoArgs,\n dynamicFixes: function() {\n return [\n new validationIssueFix({\n icon: 'iD-operation-orthogonalize',\n title: t('issues.fix.square_feature.title'),\n// autoArgs: autoArgs,\n onClick: function(context, completionHandler) {\n var entityId = this.issue.entityIds[0];\n // use same degree threshold as for detection\n context.perform(\n actionOrthogonalize(entityId, context.projection, undefined, degreeThreshold),\n t('operations.orthogonalize.annotation.feature.single')\n );\n // run after the squaring transition (currently 150ms)\n window.setTimeout(function() { completionHandler(); }, 175);\n }\n }),\n /*\n new validationIssueFix({\n title: t('issues.fix.tag_as_unsquare.title'),\n onClick: function(context) {\n var entityId = this.issue.entityIds[0];\n var entity = context.entity(entityId);\n var tags = Object.assign({}, entity.tags); // shallow copy\n tags.nonsquare = 'yes';\n context.perform(\n actionChangeTags(entityId, tags),\n t('issues.fix.tag_as_unsquare.annotation')\n );\n }\n })\n */\n ];\n }\n })];\n\n function showReference(selection) {\n selection.selectAll('.issue-reference')\n .data([0])\n .enter()\n .append('div')\n .attr('class', 'issue-reference')\n .text(t('issues.unsquare_way.buildings.reference'));\n }\n };\n\n validation.type = type;\n\n return validation;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\n\nimport { prefs } from './preferences';\nimport { coreDifference } from './difference';\nimport { geoExtent } from '../geo/extent';\nimport { modeSelect } from '../modes/select';\nimport { utilArrayGroupBy, utilRebind } from '../util';\nimport * as Validations from '../validations/index';\n\n\nexport function coreValidator(context) {\n var dispatch = d3_dispatch('validated', 'focusedIssue');\n var validator = utilRebind({}, dispatch, 'on');\n\n var _rules = {};\n var _disabledRules = {};\n\n var _ignoredIssueIDs = {}; // issue.id -> true\n var _baseCache = validationCache(); // issues before any user edits\n var _headCache = validationCache(); // issues after all user edits\n var _validatedGraph = null;\n var _deferred = new Set();\n\n //\n // initialize the validator rulesets\n //\n validator.init = function() {\n Object.values(Validations).forEach(function(validation) {\n if (typeof validation !== 'function') return;\n\n var fn = validation(context);\n var key = fn.type;\n _rules[key] = fn;\n });\n\n var disabledRules = prefs('validate-disabledRules');\n if (disabledRules) {\n disabledRules.split(',')\n .forEach(function(key) { _disabledRules[key] = true; });\n }\n };\n\n\n //\n // clear caches, called whenever iD resets after a save\n //\n validator.reset = function() {\n Array.from(_deferred).forEach(function(handle) {\n window.cancelIdleCallback(handle);\n _deferred.delete(handle);\n });\n\n // clear caches\n _ignoredIssueIDs = {};\n _baseCache = validationCache();\n _headCache = validationCache();\n _validatedGraph = null;\n };\n\n validator.resetIgnoredIssues = function() {\n _ignoredIssueIDs = {};\n // reload UI\n dispatch.call('validated');\n };\n\n\n // must update issues when the user changes the unsquare thereshold\n validator.reloadUnsquareIssues = function() {\n\n reloadUnsquareIssues(_headCache, context.graph());\n reloadUnsquareIssues(_baseCache, context.history().base());\n\n dispatch.call('validated');\n };\n\n function reloadUnsquareIssues(cache, graph) {\n\n var checkUnsquareWay = _rules.unsquare_way;\n if (typeof checkUnsquareWay !== 'function') return;\n\n // uncache existing\n cache.uncacheIssuesOfType('unsquare_way');\n\n var buildings = context.history().tree().intersects(geoExtent([-180,-90],[180, 90]), graph) // everywhere\n .filter(function(entity) {\n return entity.type === 'way' && entity.tags.building && entity.tags.building !== 'no';\n });\n\n // rerun for all buildings\n buildings.forEach(function(entity) {\n var detected = checkUnsquareWay(entity, graph);\n if (detected.length !== 1) return;\n var issue = detected[0];\n if (!cache.issuesByEntityID[entity.id]) {\n cache.issuesByEntityID[entity.id] = new Set();\n }\n cache.issuesByEntityID[entity.id].add(issue.id);\n cache.issuesByIssueID[issue.id] = issue;\n });\n }\n\n // options = {\n // what: 'all', // 'all' or 'edited'\n // where: 'all', // 'all' or 'visible'\n // includeIgnored: false // true, false, or 'only'\n // includeDisabledRules: false // true, false, or 'only'\n // };\n validator.getIssues = function(options) {\n var opts = Object.assign({ what: 'all', where: 'all', includeIgnored: false, includeDisabledRules: false }, options);\n var issues = Object.values(_headCache.issuesByIssueID);\n var view = context.map().extent();\n\n return issues.filter(function(issue) {\n if (!issue) return false;\n if (opts.includeDisabledRules === 'only' && !_disabledRules[issue.type]) return false;\n if (!opts.includeDisabledRules && _disabledRules[issue.type]) return false;\n\n if (opts.includeIgnored === 'only' && !_ignoredIssueIDs[issue.id]) return false;\n if (!opts.includeIgnored && _ignoredIssueIDs[issue.id]) return false;\n\n // Sanity check: This issue may be for an entity that not longer exists.\n // If we detect this, uncache and return false so it is not included..\n var entityIds = issue.entityIds || [];\n for (var i = 0; i < entityIds.length; i++) {\n var entityId = entityIds[i];\n if (!context.hasEntity(entityId)) {\n delete _headCache.issuesByEntityID[entityId];\n delete _headCache.issuesByIssueID[issue.id];\n return false;\n }\n }\n\n if (opts.what === 'edited' && _baseCache.issuesByIssueID[issue.id]) return false;\n\n if (opts.where === 'visible') {\n var extent = issue.extent(context.graph());\n if (!view.intersects(extent)) return false;\n }\n\n return true;\n });\n };\n\n validator.getResolvedIssues = function() {\n var baseIssues = Object.values(_baseCache.issuesByIssueID);\n return baseIssues.filter(function(issue) {\n return !_headCache.issuesByIssueID[issue.id];\n });\n };\n\n validator.focusIssue = function(issue) {\n var extent = issue.extent(context.graph());\n\n if (extent) {\n var setZoom = Math.max(context.map().zoom(), 19);\n context.map().unobscuredCenterZoomEase(extent.center(), setZoom);\n\n // select the first entity\n if (issue.entityIds && issue.entityIds.length) {\n window.setTimeout(function() {\n var ids = issue.entityIds;\n context.enter(modeSelect(context, [ids[0]]));\n dispatch.call('focusedIssue', this, issue);\n }, 250); // after ease\n }\n }\n };\n\n\n validator.getIssuesBySeverity = function(options) {\n var groups = utilArrayGroupBy(validator.getIssues(options), 'severity');\n groups.error = groups.error || [];\n groups.warning = groups.warning || [];\n return groups;\n };\n\n // show some issue types in a particular order\n var orderedIssueTypes = [\n // flag missing data first\n 'missing_tag', 'missing_role',\n // then flag identity issues\n 'outdated_tags', 'mismatched_geometry',\n // flag geometry issues where fixing them might solve connectivity issues\n 'crossing_ways', 'almost_junction',\n // then flag connectivity issues\n 'disconnected_way', 'impossible_oneway'\n ];\n\n // returns the issues that the given entity IDs have in common, matching the given options\n validator.getSharedEntityIssues = function(entityIDs, options) {\n var cache = _headCache;\n\n // gather the issues that are common to all the entities\n var issueIDs = entityIDs.reduce(function(acc, entityID) {\n var entityIssueIDs = cache.issuesByEntityID[entityID] || new Set();\n if (!acc) {\n return new Set(entityIssueIDs);\n }\n return new Set([...acc].filter(function(elem) {\n return entityIssueIDs.has(elem);\n }));\n }, null) || [];\n\n var opts = options || {};\n\n return Array.from(issueIDs)\n .map(function(id) { return cache.issuesByIssueID[id]; })\n .filter(function(issue) {\n if (!issue) return false;\n if (opts.includeDisabledRules === 'only' && !_disabledRules[issue.type]) return false;\n if (!opts.includeDisabledRules && _disabledRules[issue.type]) return false;\n\n if (opts.includeIgnored === 'only' && !_ignoredIssueIDs[issue.id]) return false;\n if (!opts.includeIgnored && _ignoredIssueIDs[issue.id]) return false;\n\n return true;\n }).sort(function(issue1, issue2) {\n if (issue1.type === issue2.type) {\n // issues of the same type, sort deterministically\n return issue1.id < issue2.id ? -1 : 1;\n }\n var index1 = orderedIssueTypes.indexOf(issue1.type);\n var index2 = orderedIssueTypes.indexOf(issue2.type);\n if (index1 !== -1 && index2 !== -1) {\n // both issue types have explicit sort orders\n return index1 - index2;\n } else if (index1 === -1 && index2 === -1) {\n // neither issue type has an explicit sort order, sort by type\n return issue1.type < issue2.type ? -1 : 1;\n } else {\n // order explicit types before everything else\n return index1 !== -1 ? -1 : 1;\n }\n });\n };\n\n\n validator.getEntityIssues = function(entityID, options) {\n return validator.getSharedEntityIssues([entityID], options);\n };\n\n\n validator.getRuleKeys = function() {\n return Object.keys(_rules);\n };\n\n\n validator.isRuleEnabled = function(key) {\n return !_disabledRules[key];\n };\n\n\n validator.toggleRule = function(key) {\n if (_disabledRules[key]) {\n delete _disabledRules[key];\n } else {\n _disabledRules[key] = true;\n }\n\n prefs('validate-disabledRules', Object.keys(_disabledRules).join(','));\n validator.validate();\n };\n\n\n validator.disableRules = function(keys) {\n _disabledRules = {};\n keys.forEach(function(k) {\n _disabledRules[k] = true;\n });\n\n prefs('validate-disabledRules', Object.keys(_disabledRules).join(','));\n validator.validate();\n };\n\n\n validator.ignoreIssue = function(id) {\n _ignoredIssueIDs[id] = true;\n };\n\n\n //\n // Run validation on a single entity for the given graph\n //\n function validateEntity(entity, graph) {\n var entityIssues = [];\n\n // runs validation and appends resulting issues\n function runValidation(key) {\n\n var fn = _rules[key];\n if (typeof fn !== 'function') {\n console.error('no such validation rule = ' + key); // eslint-disable-line no-console\n return;\n }\n\n var detected = fn(entity, graph);\n entityIssues = entityIssues.concat(detected);\n }\n\n // run all rules\n Object.keys(_rules).forEach(runValidation);\n\n return entityIssues;\n }\n\n function entityIDsToValidate(entityIDs, graph) {\n var processedIDs = new Set();\n return entityIDs.reduce(function(acc, entityID) {\n // keep redundancy check separate from `acc` because an `entityID`\n // could have been added to `acc` as a related entity through an earlier pass\n if (processedIDs.has(entityID)) return acc;\n processedIDs.add(entityID);\n\n var entity = graph.hasEntity(entityID);\n if (!entity) return acc;\n\n acc.add(entityID);\n\n var checkParentRels = [entity];\n\n if (entity.type === 'node') {\n graph.parentWays(entity).forEach(function(parentWay) {\n acc.add(parentWay.id); // include parent ways\n checkParentRels.push(parentWay);\n });\n } else if (entity.type === 'relation') {\n entity.members.forEach(function(member) {\n acc.add(member.id); // include members\n });\n } else if (entity.type === 'way') {\n entity.nodes.forEach(function(nodeID) {\n acc.add(nodeID); // include child nodes\n graph._parentWays[nodeID].forEach(function(wayID) {\n acc.add(wayID); // include connected ways\n });\n });\n }\n\n checkParentRels.forEach(function(entity) { // include parent relations\n if (entity.type !== 'relation') { // but not super-relations\n graph.parentRelations(entity).forEach(function(parentRelation) {\n acc.add(parentRelation.id);\n });\n }\n });\n\n return acc;\n\n }, new Set());\n }\n\n //\n // Run validation for several entities, supplied `entityIDs`,\n // against `graph` for the given `cache`\n //\n function validateEntities(entityIDs, graph, cache) {\n\n // clear caches for existing issues related to these entities\n entityIDs.forEach(cache.uncacheEntityID);\n\n // detect new issues and update caches\n entityIDs.forEach(function(entityID) {\n var entity = graph.hasEntity(entityID);\n // don't validate deleted entities\n if (!entity) return;\n\n var issues = validateEntity(entity, graph);\n cache.cacheIssues(issues);\n });\n }\n\n\n //\n // Validates anything that has changed since the last time it was run.\n // Also updates the \"validatedGraph\" to be the current graph\n // and dispatches a `validated` event when finished.\n //\n validator.validate = function() {\n\n var currGraph = context.graph();\n _validatedGraph = _validatedGraph || context.history().base();\n if (currGraph === _validatedGraph) {\n dispatch.call('validated');\n return;\n }\n var oldGraph = _validatedGraph;\n var difference = coreDifference(oldGraph, currGraph);\n _validatedGraph = currGraph;\n\n var createdAndModifiedEntityIDs = difference.extantIDs(true); // created/modified (true = w/relation members)\n var entityIDsToCheck = entityIDsToValidate(createdAndModifiedEntityIDs, currGraph);\n\n // check modified and deleted entities against the old graph in order to update their related entities\n // (e.g. deleting the only highway connected to a road should create a disconnected highway issue)\n var modifiedAndDeletedEntityIDs = difference.deleted().concat(difference.modified())\n .map(function(entity) { return entity.id; });\n var entityIDsToCheckForOldGraph = entityIDsToValidate(modifiedAndDeletedEntityIDs, oldGraph);\n\n // concat the sets\n entityIDsToCheckForOldGraph.forEach(entityIDsToCheck.add, entityIDsToCheck);\n\n validateEntities(entityIDsToCheck, context.graph(), _headCache);\n\n dispatch.call('validated');\n };\n\n\n // WHEN TO RUN VALIDATION:\n // When graph changes:\n context.history()\n .on('restore.validator', validator.validate) // restore saved history\n .on('undone.validator', validator.validate) // undo\n .on('redone.validator', validator.validate); // redo\n // but not on 'change' (e.g. while drawing)\n\n // When user chages editing modes:\n context\n .on('exit.validator', validator.validate);\n\n // When merging fetched data:\n context.history()\n .on('merge.validator', function(entities) {\n if (!entities) return;\n var handle = window.requestIdleCallback(function() {\n var entityIDs = entities.map(function(entity) { return entity.id; });\n var headGraph = context.graph();\n validateEntities(entityIDsToValidate(entityIDs, headGraph), headGraph, _headCache);\n\n var baseGraph = context.history().base();\n validateEntities(entityIDsToValidate(entityIDs, baseGraph), baseGraph, _baseCache);\n\n dispatch.call('validated');\n });\n _deferred.add(handle);\n });\n\n\n return validator;\n}\n\n\nfunction validationCache() {\n\n var cache = {\n issuesByIssueID: {}, // issue.id -> issue\n issuesByEntityID: {} // entity.id -> set(issue.id)\n };\n\n cache.cacheIssues = function(issues) {\n issues.forEach(function(issue) {\n var entityIds = issue.entityIds || [];\n entityIds.forEach(function(entityId) {\n if (!cache.issuesByEntityID[entityId]) {\n cache.issuesByEntityID[entityId] = new Set();\n }\n cache.issuesByEntityID[entityId].add(issue.id);\n });\n cache.issuesByIssueID[issue.id] = issue;\n });\n };\n\n cache.uncacheIssue = function(issue) {\n // When multiple entities are involved (e.g. crossing_ways),\n // remove this issue from the other entity caches too..\n var entityIds = issue.entityIds || [];\n entityIds.forEach(function(entityId) {\n if (cache.issuesByEntityID[entityId]) {\n cache.issuesByEntityID[entityId].delete(issue.id);\n }\n });\n delete cache.issuesByIssueID[issue.id];\n };\n\n cache.uncacheIssues = function(issues) {\n issues.forEach(cache.uncacheIssue);\n };\n\n cache.uncacheIssuesOfType = function(type) {\n var issuesOfType = Object.values(cache.issuesByIssueID)\n .filter(function(issue) { return issue.type === type; });\n cache.uncacheIssues(issuesOfType);\n };\n\n //\n // Remove a single entity and all its related issues from the caches\n //\n cache.uncacheEntityID = function(entityID) {\n var issueIDs = cache.issuesByEntityID[entityID];\n if (!issueIDs) return;\n\n issueIDs.forEach(function(issueID) {\n var issue = cache.issuesByIssueID[issueID];\n if (issue) {\n cache.uncacheIssue(issue);\n } else {\n delete cache.issuesByIssueID[issueID];\n }\n });\n\n delete cache.issuesByEntityID[entityID];\n };\n\n return cache;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\n\nimport { fileFetcher } from './file_fetcher';\nimport { actionDiscardTags } from '../actions/discard_tags';\nimport { actionMergeRemoteChanges } from '../actions/merge_remote_changes';\nimport { actionNoop } from '../actions/noop';\nimport { actionRevert } from '../actions/revert';\nimport { coreGraph } from '../core/graph';\nimport { t } from '../core/localizer';\nimport { utilArrayUnion, utilArrayUniq, utilDisplayName, utilDisplayType, utilRebind } from '../util';\n\n\nexport function coreUploader(context) {\n\n var dispatch = d3_dispatch(\n // Start and end events are dispatched exactly once each per legitimate outside call to `save`\n 'saveStarted', // dispatched as soon as a call to `save` has been deemed legitimate\n 'saveEnded', // dispatched after the result event has been dispatched\n\n 'willAttemptUpload', // dispatched before the actual upload call occurs, if it will\n 'progressChanged',\n\n // Each save results in one of these outcomes:\n 'resultNoChanges', // upload wasn't attempted since there were no edits\n 'resultErrors', // upload failed due to errors\n 'resultConflicts', // upload failed due to data conflicts\n 'resultSuccess' // upload completed without errors\n );\n\n var _isSaving = false;\n\n var _conflicts = [];\n var _errors = [];\n var _origChanges;\n\n var _discardTags = {};\n fileFetcher.get('discarded')\n .then(function(d) { _discardTags = d; })\n .catch(function() { /* ignore */ });\n\n var uploader = utilRebind({}, dispatch, 'on');\n\n uploader.isSaving = function() {\n return _isSaving;\n };\n\n uploader.save = function(changeset, tryAgain, checkConflicts) {\n // Guard against accidentally entering save code twice - #4641\n if (_isSaving && !tryAgain) {\n return;\n }\n\n var osm = context.connection();\n if (!osm) return;\n\n // If user somehow got logged out mid-save, try to reauthenticate..\n // This can happen if they were logged in from before, but the tokens are no longer valid.\n if (!osm.authenticated()) {\n osm.authenticate(function(err) {\n if (!err) {\n uploader.save(changeset, tryAgain, checkConflicts); // continue where we left off..\n }\n });\n return;\n }\n\n if (!_isSaving) {\n _isSaving = true;\n dispatch.call('saveStarted', this);\n }\n\n var history = context.history();\n\n _conflicts = [];\n _errors = [];\n\n // Store original changes, in case user wants to download them as an .osc file\n _origChanges = history.changes(actionDiscardTags(history.difference(), _discardTags));\n\n // First time, `history.perform` a no-op action.\n // Any conflict resolutions will be done as `history.replace`\n // Remember to pop this later if needed\n if (!tryAgain) {\n history.perform(actionNoop());\n }\n\n // Attempt a fast upload.. If there are conflicts, re-enter with `checkConflicts = true`\n if (!checkConflicts) {\n upload(changeset);\n\n // Do the full (slow) conflict check..\n } else {\n performFullConflictCheck(changeset);\n }\n\n };\n\n\n function performFullConflictCheck(changeset) {\n\n var osm = context.connection();\n if (!osm) return;\n\n var history = context.history();\n\n var localGraph = context.graph();\n var remoteGraph = coreGraph(history.base(), true);\n\n var summary = history.difference().summary();\n var _toCheck = [];\n for (var i = 0; i < summary.length; i++) {\n var item = summary[i];\n if (item.changeType === 'modified') {\n _toCheck.push(item.entity.id);\n }\n }\n\n var _toLoad = withChildNodes(_toCheck, localGraph);\n var _loaded = {};\n var _toLoadCount = 0;\n var _toLoadTotal = _toLoad.length;\n\n if (_toCheck.length) {\n dispatch.call('progressChanged', this, _toLoadCount, _toLoadTotal);\n _toLoad.forEach(function(id) { _loaded[id] = false; });\n osm.loadMultiple(_toLoad, loaded);\n } else {\n upload(changeset);\n }\n\n return;\n\n function withChildNodes(ids, graph) {\n var s = new Set(ids);\n ids.forEach(function(id) {\n var entity = graph.entity(id);\n if (entity.type !== 'way') return;\n\n graph.childNodes(entity).forEach(function(child) {\n if (child.version !== undefined) {\n s.add(child.id);\n }\n });\n });\n\n return Array.from(s);\n }\n\n\n // Reload modified entities into an alternate graph and check for conflicts..\n function loaded(err, result) {\n if (_errors.length) return;\n\n if (err) {\n _errors.push({\n msg: err.message || err.responseText,\n details: [ t('save.status_code', { code: err.status }) ]\n });\n didResultInErrors();\n\n } else {\n var loadMore = [];\n\n result.data.forEach(function(entity) {\n remoteGraph.replace(entity);\n _loaded[entity.id] = true;\n _toLoad = _toLoad.filter(function(val) { return val !== entity.id; });\n\n if (!entity.visible) return;\n\n // Because loadMultiple doesn't download /full like loadEntity,\n // need to also load children that aren't already being checked..\n var i, id;\n if (entity.type === 'way') {\n for (i = 0; i < entity.nodes.length; i++) {\n id = entity.nodes[i];\n if (_loaded[id] === undefined) {\n _loaded[id] = false;\n loadMore.push(id);\n }\n }\n } else if (entity.type === 'relation' && entity.isMultipolygon()) {\n for (i = 0; i < entity.members.length; i++) {\n id = entity.members[i].id;\n if (_loaded[id] === undefined) {\n _loaded[id] = false;\n loadMore.push(id);\n }\n }\n }\n });\n\n _toLoadCount += result.data.length;\n _toLoadTotal += loadMore.length;\n dispatch.call('progressChanged', this, _toLoadCount, _toLoadTotal);\n\n if (loadMore.length) {\n _toLoad.push.apply(_toLoad, loadMore);\n osm.loadMultiple(loadMore, loaded);\n }\n\n if (!_toLoad.length) {\n detectConflicts();\n upload(changeset);\n }\n }\n }\n\n\n function detectConflicts() {\n function choice(id, text, action) {\n return {\n id: id,\n text: text,\n action: function() {\n history.replace(action);\n }\n };\n }\n function formatUser(d) {\n return '' + d + ' ';\n }\n function entityName(entity) {\n return utilDisplayName(entity) || (utilDisplayType(entity.id) + ' ' + entity.id);\n }\n\n function sameVersions(local, remote) {\n if (local.version !== remote.version) return false;\n\n if (local.type === 'way') {\n var children = utilArrayUnion(local.nodes, remote.nodes);\n for (var i = 0; i < children.length; i++) {\n var a = localGraph.hasEntity(children[i]);\n var b = remoteGraph.hasEntity(children[i]);\n if (a && b && a.version !== b.version) return false;\n }\n }\n\n return true;\n }\n\n _toCheck.forEach(function(id) {\n var local = localGraph.entity(id);\n var remote = remoteGraph.entity(id);\n\n if (sameVersions(local, remote)) return;\n\n var merge = actionMergeRemoteChanges(id, localGraph, remoteGraph, _discardTags, formatUser);\n\n history.replace(merge);\n\n var mergeConflicts = merge.conflicts();\n if (!mergeConflicts.length) return; // merged safely\n\n var forceLocal = actionMergeRemoteChanges(id, localGraph, remoteGraph, _discardTags).withOption('force_local');\n var forceRemote = actionMergeRemoteChanges(id, localGraph, remoteGraph, _discardTags).withOption('force_remote');\n var keepMine = t('save.conflict.' + (remote.visible ? 'keep_local' : 'restore'));\n var keepTheirs = t('save.conflict.' + (remote.visible ? 'keep_remote' : 'delete'));\n\n _conflicts.push({\n id: id,\n name: entityName(local),\n details: mergeConflicts,\n chosen: 1,\n choices: [\n choice(id, keepMine, forceLocal),\n choice(id, keepTheirs, forceRemote)\n ]\n });\n });\n }\n }\n\n\n function upload(changeset) {\n var osm = context.connection();\n if (!osm) {\n _errors.push({ msg: 'No OSM Service' });\n }\n\n if (_conflicts.length) {\n didResultInConflicts(changeset);\n\n } else if (_errors.length) {\n didResultInErrors();\n\n } else {\n var history = context.history();\n var changes = history.changes(actionDiscardTags(history.difference(), _discardTags));\n if (changes.modified.length || changes.created.length || changes.deleted.length) {\n\n dispatch.call('willAttemptUpload', this);\n\n osm.putChangeset(changeset, changes, uploadCallback);\n\n } else {\n // changes were insignificant or reverted by user\n didResultInNoChanges();\n }\n }\n }\n\n\n function uploadCallback(err, changeset) {\n if (err) {\n if (err.status === 409) { // 409 Conflict\n uploader.save(changeset, true, true); // tryAgain = true, checkConflicts = true\n } else {\n _errors.push({\n msg: err.message || err.responseText,\n details: [ t('save.status_code', { code: err.status }) ]\n });\n didResultInErrors();\n }\n\n } else {\n didResultInSuccess(changeset);\n }\n }\n\n function didResultInNoChanges() {\n\n dispatch.call('resultNoChanges', this);\n\n endSave();\n\n context.flush(); // reset iD\n }\n\n function didResultInErrors() {\n\n context.history().pop();\n\n dispatch.call('resultErrors', this, _errors);\n\n endSave();\n }\n\n\n function didResultInConflicts(changeset) {\n\n _conflicts.sort(function(a, b) { return b.id.localeCompare(a.id); });\n\n dispatch.call('resultConflicts', this, changeset, _conflicts, _origChanges);\n\n endSave();\n }\n\n\n function didResultInSuccess(changeset) {\n\n // delete the edit stack cached to local storage\n context.history().clearSaved();\n\n dispatch.call('resultSuccess', this, changeset);\n\n // Add delay to allow for postgres replication #1646 #2678\n window.setTimeout(function() {\n\n endSave();\n\n context.flush(); // reset iD\n }, 2500);\n }\n\n\n function endSave() {\n _isSaving = false;\n\n dispatch.call('saveEnded', this);\n }\n\n\n uploader.cancelConflictResolution = function() {\n context.history().pop();\n };\n\n\n uploader.processResolvedConflicts = function(changeset) {\n var history = context.history();\n\n for (var i = 0; i < _conflicts.length; i++) {\n if (_conflicts[i].chosen === 1) { // user chose \"use theirs\"\n var entity = context.hasEntity(_conflicts[i].id);\n if (entity && entity.type === 'way') {\n var children = utilArrayUniq(entity.nodes);\n for (var j = 0; j < children.length; j++) {\n history.replace(actionRevert(children[j]));\n }\n }\n history.replace(actionRevert(_conflicts[i].id));\n }\n }\n\n uploader.save(changeset, true, false); // tryAgain = true, checkConflicts = false\n };\n\n\n uploader.reset = function() {\n\n };\n\n\n return uploader;\n}\n","import _debounce from 'lodash-es/debounce';\n\nimport { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { json as d3_json } from 'd3-fetch';\nimport { select as d3_select } from 'd3-selection';\n\nimport { t } from '../core/localizer';\n\nimport { coreRapidContext } from './rapid_context';\nimport { fileFetcher as data } from './file_fetcher';\nimport { localizer } from './localizer';\nimport { prefs } from './preferences';\nimport { coreHistory } from './history';\nimport { coreValidator } from './validator';\nimport { coreUploader } from './uploader';\nimport { geoRawMercator } from '../geo/raw_mercator';\nimport { modeSelect } from '../modes/select';\nimport { presetManager } from '../presets';\nimport { rendererBackground, rendererFeatures, rendererMap, rendererPhotos } from '../renderer';\nimport { services } from '../services';\nimport { uiInit } from '../ui/init';\nimport { utilKeybinding, utilRebind, utilStringQs, utilUnicodeCharsTruncated } from '../util';\n\n\nexport function coreContext() {\n const dispatch = d3_dispatch('enter', 'exit', 'change');\n let context = utilRebind({}, dispatch, 'on');\n let _deferred = new Set();\n\n context.version = '2.18.3';\n context.privacyVersion = '20200407';\n\n // iD will alter the hash so cache the parameters intended to setup the session\n context.initialHashParams = window.location.hash ? utilStringQs(window.location.hash) : {};\n\n context.isFirstSession = !prefs('sawSplash') && !prefs('sawPrivacyVersion');\n\n /* Changeset */\n // An osmChangeset object. Not loaded until needed.\n context.changeset = null;\n\n let _defaultChangesetComment = context.initialHashParams.comment;\n let _defaultChangesetSource = context.initialHashParams.source;\n let _defaultChangesetHashtags = context.initialHashParams.hashtags;\n context.defaultChangesetComment = function(val) {\n if (!arguments.length) return _defaultChangesetComment;\n _defaultChangesetComment = val;\n return context;\n };\n context.defaultChangesetSource = function(val) {\n if (!arguments.length) return _defaultChangesetSource;\n _defaultChangesetSource = val;\n return context;\n };\n context.defaultChangesetHashtags = function(val) {\n if (!arguments.length) return _defaultChangesetHashtags;\n _defaultChangesetHashtags = val;\n return context;\n };\n\n /* Document title */\n /* (typically shown as the label for the browser window/tab) */\n\n // If true, iD will update the title based on what the user is doing\n let _setsDocumentTitle = true;\n context.setsDocumentTitle = function(val) {\n if (!arguments.length) return _setsDocumentTitle;\n _setsDocumentTitle = val;\n return context;\n };\n // The part of the title that is always the same\n let _documentTitleBase = document.title;\n context.documentTitleBase = function(val) {\n if (!arguments.length) return _documentTitleBase;\n _documentTitleBase = val;\n return context;\n };\n\n\n /* User interface and keybinding */\n let _ui;\n context.ui = () => _ui;\n context.lastPointerType = () => _ui.lastPointerType();\n\n let _keybinding = utilKeybinding('context');\n context.keybinding = () => _keybinding;\n d3_select(document).call(_keybinding);\n\n\n /* Straight accessors. Avoid using these if you can. */\n // Instantiate the connection here because it doesn't require passing in\n // `context` and it's needed for pre-init calls like `preauth`\n let _connection = services.osm;\n let _history;\n let _validator;\n let _uploader;\n context.connection = () => _connection;\n context.history = () => _history;\n context.validator = () => _validator;\n context.uploader = () => _uploader;\n\n /* Connection */\n context.preauth = (options) => {\n if (_connection) {\n _connection.switch(options);\n }\n return context;\n };\n\n /* connection options for source switcher (optional) */\n let _apiConnections;\n context.apiConnections = function(val) {\n if (!arguments.length) return _apiConnections;\n _apiConnections = val;\n return context;\n };\n\n\n // A string or array or locale codes to prefer over the browser's settings\n context.locale = function(locale) {\n if (!arguments.length) return localizer.localeCode();\n localizer.preferredLocaleCodes(locale);\n return context;\n };\n\n\n function afterLoad(cid, callback) {\n return (err, result) => {\n if (err) {\n // 400 Bad Request, 401 Unauthorized, 403 Forbidden..\n if (err.status === 400 || err.status === 401 || err.status === 403) {\n if (_connection) {\n _connection.logout();\n }\n }\n if (typeof callback === 'function') {\n callback(err);\n }\n return;\n\n } else if (_connection && _connection.getConnectionId() !== cid) {\n if (typeof callback === 'function') {\n callback({ message: 'Connection Switched', status: -1 });\n }\n return;\n\n } else {\n _history.merge(result.data, result.extent);\n if (typeof callback === 'function') {\n callback(err, result);\n }\n return;\n }\n };\n }\n\n\n context.loadTiles = (projection, callback) => {\n const handle = window.requestIdleCallback(() => {\n _deferred.delete(handle);\n if (_connection && context.editableDataEnabled()) {\n const cid = _connection.getConnectionId();\n _connection.loadTiles(projection, afterLoad(cid, callback));\n }\n });\n _deferred.add(handle);\n };\n\n context.loadTileAtLoc = (loc, callback) => {\n const handle = window.requestIdleCallback(() => {\n _deferred.delete(handle);\n if (_connection && context.editableDataEnabled()) {\n const cid = _connection.getConnectionId();\n _connection.loadTileAtLoc(loc, afterLoad(cid, callback));\n }\n });\n _deferred.add(handle);\n };\n\n context.loadEntity = (entityID, callback) => {\n if (_connection) {\n const cid = _connection.getConnectionId();\n _connection.loadEntity(entityID, afterLoad(cid, callback));\n }\n };\n\n context.zoomToEntity = (entityID, zoomTo) => {\n if (zoomTo !== false) {\n context.loadEntity(entityID, (err, result) => {\n if (err) return;\n const entity = result.data.find(e => e.id === entityID);\n if (entity) {\n _map.zoomTo(entity);\n }\n });\n }\n\n _map.on('drawn.zoomToEntity', () => {\n if (!context.hasEntity(entityID)) return;\n _map.on('drawn.zoomToEntity', null);\n context.on('enter.zoomToEntity', null);\n context.enter(modeSelect(context, [entityID]));\n });\n\n context.on('enter.zoomToEntity', () => {\n if (_mode.id !== 'browse') {\n _map.on('drawn.zoomToEntity', null);\n context.on('enter.zoomToEntity', null);\n }\n });\n };\n\n let _minEditableZoom = 16;\n context.minEditableZoom = function(val) {\n if (!arguments.length) return _minEditableZoom;\n _minEditableZoom = val;\n if (_connection) {\n _connection.tileZoom(val);\n }\n return context;\n };\n\n // String length limits in Unicode characters, not JavaScript UTF-16 code units\n context.maxCharsForTagKey = () => 255;\n context.maxCharsForTagValue = () => 255;\n context.maxCharsForRelationRole = () => 255;\n\n function cleanOsmString(val, maxChars) {\n // be lenient with input\n if (val === undefined || val === null) {\n val = '';\n } else {\n val = val.toString();\n }\n\n // remove whitespace\n val = val.trim();\n\n // use the canonical form of the string\n if (val.normalize) val = val.normalize('NFC');\n\n // trim to the number of allowed characters\n return utilUnicodeCharsTruncated(val, maxChars);\n }\n context.cleanTagKey = (val) => cleanOsmString(val, context.maxCharsForTagKey());\n context.cleanTagValue = (val) => cleanOsmString(val, context.maxCharsForTagValue());\n context.cleanRelationRole = (val) => cleanOsmString(val, context.maxCharsForRelationRole());\n\n\n /* History */\n let _inIntro = false;\n context.inIntro = function(val) {\n if (!arguments.length) return _inIntro;\n _inIntro = val;\n return context;\n };\n\n // Immediately save the user's history to localstorage, if possible\n // This is called someteimes, but also on the `window.onbeforeunload` handler\n context.save = () => {\n // no history save, no message onbeforeunload\n if (_inIntro || context.container().select('.modal').size()) return;\n\n let canSave;\n if (_mode && _mode.id === 'save') {\n canSave = false;\n\n // Attempt to prevent user from creating duplicate changes - see #5200\n if (services.osm && services.osm.isChangesetInflight()) {\n _history.clearSaved();\n return;\n }\n\n } else {\n canSave = context.selectedIDs().every(id => {\n const entity = context.hasEntity(id);\n return entity && !entity.isDegenerate();\n });\n }\n\n if (canSave) {\n _history.save();\n }\n if (_history.hasChanges()) {\n return t('save.unsaved_changes');\n }\n };\n\n // Debounce save, since it's a synchronous localStorage write,\n // and history changes can happen frequently (e.g. when dragging).\n context.debouncedSave = _debounce(context.save, 350);\n\n function withDebouncedSave(fn) {\n return function() {\n const result = fn.apply(_history, arguments);\n context.debouncedSave();\n return result;\n };\n }\n\n\n /* Graph */\n context.hasEntity = (id) => _history.graph().hasEntity(id);\n context.entity = (id) => _history.graph().entity(id);\n\n\n /* Modes */\n let _mode;\n context.mode = () => _mode;\n context.enter = (newMode) => {\n if (_mode) {\n _mode.exit();\n dispatch.call('exit', this, _mode);\n }\n\n _mode = newMode;\n _mode.enter();\n dispatch.call('enter', this, _mode);\n };\n\n context.selectedIDs = () => (_mode && _mode.selectedIDs && _mode.selectedIDs()) || [];\n context.activeID = () => _mode && _mode.activeID && _mode.activeID();\n\n let _selectedNoteID;\n context.selectedNoteID = function(noteID) {\n if (!arguments.length) return _selectedNoteID;\n _selectedNoteID = noteID;\n return context;\n };\n\n // NOTE: Don't change the name of this until UI v3 is merged\n let _selectedErrorID;\n context.selectedErrorID = function(errorID) {\n if (!arguments.length) return _selectedErrorID;\n _selectedErrorID = errorID;\n return context;\n };\n\n\n /* Behaviors */\n context.install = (behavior) => context.surface().call(behavior);\n context.uninstall = (behavior) => context.surface().call(behavior.off);\n\n\n /* Copy/Paste */\n let _copyGraph;\n context.copyGraph = () => _copyGraph;\n\n let _copyIDs = [];\n context.copyIDs = function(val) {\n if (!arguments.length) return _copyIDs;\n _copyIDs = val;\n _copyGraph = _history.graph();\n return context;\n };\n\n let _copyLonLat;\n context.copyLonLat = function(val) {\n if (!arguments.length) return _copyLonLat;\n _copyLonLat = val;\n return context;\n };\n\n\n /* Background */\n let _background;\n context.background = () => _background;\n\n\n /* Features */\n let _features;\n context.features = () => _features;\n context.hasHiddenConnections = (id) => {\n const graph = _history.graph();\n const entity = graph.entity(id);\n return _features.hasHiddenConnections(entity, graph);\n };\n\n\n /* Photos */\n let _photos;\n context.photos = () => _photos;\n\n\n /* Map */\n let _map;\n context.map = () => _map;\n context.layers = () => _map.layers();\n context.surface = () => _map.surface;\n context.editableDataEnabled = () => _map.editableDataEnabled();\n context.surfaceRect = () => _map.surface.node().getBoundingClientRect();\n context.editable = () => {\n // don't allow editing during save\n const mode = context.mode();\n if (!mode || mode.id === 'save') return false;\n return _map.editableDataEnabled();\n };\n\n\n /* Debug */\n let _debugFlags = {\n tile: false, // tile boundaries\n collision: false, // label collision bounding boxes\n imagery: false, // imagery bounding polygons\n target: false, // touch targets\n downloaded: false // downloaded data from osm\n };\n context.debugFlags = () => _debugFlags;\n context.getDebug = (flag) => flag && _debugFlags[flag];\n context.setDebug = function(flag, val) {\n if (arguments.length === 1) val = true;\n _debugFlags[flag] = val;\n dispatch.call('change');\n return context;\n };\n\n\n /* Container */\n let _container = d3_select(null);\n context.container = function(val) {\n if (!arguments.length) return _container;\n _container = val;\n _container.classed('ideditor', true);\n return context;\n };\n context.containerNode = function(val) {\n if (!arguments.length) return context.container().node();\n context.container(d3_select(val));\n return context;\n };\n\n let _embed;\n context.embed = function(val) {\n if (!arguments.length) return _embed;\n _embed = val;\n return context;\n };\n\n\n /* Assets */\n let _assetPath = '';\n context.assetPath = function(val) {\n if (!arguments.length) return _assetPath;\n _assetPath = val;\n data.assetPath(val);\n return context;\n };\n\n let _assetMap = {};\n context.assetMap = function(val) {\n if (!arguments.length) return _assetMap;\n _assetMap = val;\n data.assetMap(val);\n return context;\n };\n\n context.asset = (val) => {\n if (/^http(s)?:\\/\\//i.test(val)) return val;\n const filename = _assetPath + val;\n return _assetMap[filename] || filename;\n };\n\n context.imagePath = (val) => context.asset(`img/${val}`);\n\n\n /* reset (aka flush) */\n context.reset = context.flush = () => {\n context.debouncedSave.cancel();\n\n Array.from(_deferred).forEach(handle => {\n window.cancelIdleCallback(handle);\n _deferred.delete(handle);\n });\n\n Object.values(services).forEach(service => {\n if (service && typeof service.reset === 'function') {\n service.reset(context);\n }\n });\n\n context.changeset = null;\n\n _validator.reset();\n _features.reset();\n _history.reset();\n _uploader.reset();\n\n // don't leave stale state in the inspector\n context.container().select('.inspector-wrap *').remove();\n\n return context;\n };\n\n\n /* Projections */\n context.projection = geoRawMercator();\n context.curtainProjection = geoRawMercator();\n\n /* RapiD */\n let _rapidContext;\n context.rapidContext = () => _rapidContext;\n\n\n /* Init */\n context.init = () => {\n\n instantiateInternal();\n\n initializeDependents();\n\n return context;\n\n // Load variables and properties. No property of `context` should be accessed\n // until this is complete since load statuses are indeterminate. The order\n // of instantiation shouldn't matter.\n function instantiateInternal() {\n\n _history = coreHistory(context);\n context.graph = _history.graph;\n context.pauseChangeDispatch = _history.pauseChangeDispatch;\n context.resumeChangeDispatch = _history.resumeChangeDispatch;\n context.perform = withDebouncedSave(_history.perform);\n context.replace = withDebouncedSave(_history.replace);\n context.pop = withDebouncedSave(_history.pop);\n context.overwrite = withDebouncedSave(_history.overwrite);\n context.undo = withDebouncedSave(_history.undo);\n context.redo = withDebouncedSave(_history.redo);\n\n _rapidContext = coreRapidContext(context);\n _validator = coreValidator(context);\n _uploader = coreUploader(context);\n\n _background = rendererBackground(context);\n _features = rendererFeatures(context);\n _map = rendererMap(context);\n _photos = rendererPhotos(context);\n\n _ui = uiInit(context);\n }\n\n // Set up objects that might need to access properties of `context`. The order\n // might matter if dependents make calls to each other. Be wary of async calls.\n function initializeDependents() {\n\n if (context.initialHashParams.presets) {\n presetManager.addablePresetIDs(new Set(context.initialHashParams.presets.split(',')));\n }\n\n if (context.initialHashParams.locale) {\n localizer.preferredLocaleCodes(context.initialHashParams.locale);\n }\n\n // kick off some async work\n localizer.ensureLoaded();\n _background.ensureLoaded();\n presetManager.ensureLoaded();\n\n Object.values(services).forEach(service => {\n if (service && typeof service.init === 'function') {\n service.init();\n }\n });\n\n _map.init();\n _validator.init();\n _features.init();\n _photos.init();\n _rapidContext.init();\n\n if (services.maprules && context.initialHashParams.maprules) {\n d3_json(context.initialHashParams.maprules)\n .then(mapcss => {\n services.maprules.init();\n mapcss.forEach(mapcssSelector => services.maprules.addRule(mapcssSelector));\n })\n .catch(() => { /* ignore */ });\n }\n\n // if the container isn't available, e.g. when testing, don't load the UI\n if (!context.container().empty()) _ui.ensureLoaded();\n }\n };\n\n\n return context;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { json as d3_json } from 'd3-fetch';\nimport { select as d3_select } from 'd3-selection';\n\nimport { coreGraph, coreTree } from '../core';\nimport { osmNode, osmRelation, osmWay } from '../osm';\nimport { utilRebind, utilTiler } from '../util';\n\n\nconst GROUPID = 'bdf6c800b3ae453b9db239e03d7c1727';\nconst APIROOT = 'https://openstreetmap.maps.arcgis.com/sharing/rest/content';\nconst HOMEROOT = 'https://openstreetmap.maps.arcgis.com/home';\nconst TILEZOOM = 14;\nconst tiler = utilTiler().zoomExtent([TILEZOOM, TILEZOOM]);\nconst dispatch = d3_dispatch('loadedData');\n\nlet _datasets = {};\nlet _off;\n\n\nfunction abortRequest(controller) {\n controller.abort();\n}\n\n\n// API\nfunction searchURL() {\n return `${APIROOT}/groups/${GROUPID}/search?num=20&start=1&sortField=title&sortOrder=asc&f=json`;\n // use to get\n // .results[]\n // .extent\n // .id\n // .thumbnail\n // .title\n // .snippet\n // .url (featureServer)\n}\n\nfunction layerURL(featureServerURL) {\n return `${featureServerURL}/layers?f=json`;\n // should return single layer(?)\n // .layers[0]\n // .copyrightText\n // .fields\n // .geometryType \"esriGeometryPoint\" or \"esriGeometryPolygon\" ?\n}\n\nfunction itemURL(itemID) {\n return `${HOMEROOT}/item.html?id=${itemID}`;\n}\n\nfunction tileURL(dataset, extent) {\n const layerId = dataset.layer.id;\n const bbox = extent.toParam();\n return `${dataset.url}/${layerId}/query?f=geojson&outfields=*&outSR=4326&geometryType=esriGeometryEnvelope&geometry=${bbox}`;\n}\n\n\nfunction parseTile(dataset, tile, geojson, callback) {\n if (!geojson) return callback({ message: 'No GeoJSON', status: -1 });\n\n // expect a FeatureCollection with `features` array\n let results = [];\n (geojson.features || []).forEach(f => {\n let entities = parseFeature(f, dataset);\n if (entities) results.push.apply(results, entities);\n });\n\n callback(null, results);\n}\n\n\nfunction parseFeature(feature, dataset) {\n const geom = feature.geometry;\n const props = feature.properties;\n if (!geom || !props) return null;\n\n const featureID = props[dataset.layer.idfield] || props.OBJECTID || props.FID || props.id;\n if (!featureID) return null;\n\n // skip if we've seen this feature already on another tile\n if (dataset.cache.seen[featureID]) return null;\n dataset.cache.seen[featureID] = true;\n\n const id = `${dataset.id}-${featureID}`;\n const meta = { __fbid__: id, __origid__: id, __service__: 'esri', __datasetid__: dataset.id };\n let entities = [];\n let nodemap = new Map();\n\n // Point: make a single node\n if (geom.type === 'Point') {\n return [ new osmNode({ loc: geom.coordinates, tags: parseTags(props) }, meta) ];\n\n // LineString: make nodes, single way\n } else if (geom.type === 'LineString') {\n const nodelist = parseCoordinates(geom.coordinates);\n if (nodelist.length < 2) return null;\n\n const w = new osmWay({ nodes: nodelist, tags: parseTags(props) }, meta);\n entities.push(w);\n return entities;\n\n // Polygon: make nodes, way(s), possibly a relation\n } else if (geom.type === 'Polygon') {\n let ways = [];\n geom.coordinates.forEach(ring => {\n const nodelist = parseCoordinates(ring);\n if (nodelist.length < 3) return null;\n\n const first = nodelist[0];\n const last = nodelist[nodelist.length - 1];\n if (first !== last) nodelist.push(first); // sanity check, ensure rings are closed\n\n const w = new osmWay({ nodes: nodelist });\n ways.push(w);\n });\n\n if (ways.length === 1) { // single ring, assign tags and return\n entities.push(\n ways[0].update( Object.assign({ tags: parseTags(props) }, meta) )\n );\n } else { // multiple rings, make a multipolygon relation with inner/outer members\n const members = ways.map((w, i) => {\n entities.push(w);\n return { id: w.id, role: (i === 0 ? 'outer' : 'inner'), type: 'way' };\n });\n const tags = Object.assign(parseTags(props), { type: 'multipolygon' });\n const r = new osmRelation({ members: members, tags: tags }, meta);\n entities.push(r);\n }\n\n return entities;\n }\n // no Multitypes for now (maybe not needed)\n\n function parseCoordinates(coords) {\n let nodelist = [];\n coords.forEach(coord => {\n const key = coord.toString();\n let n = nodemap.get(key);\n if (!n) {\n n = new osmNode({ loc: coord });\n entities.push(n);\n nodemap.set(key, n);\n }\n nodelist.push(n.id);\n });\n return nodelist;\n }\n\n function parseTags(props) {\n let tags = {};\n Object.keys(props).forEach(prop => {\n const k = clean(dataset.layer.tagmap[prop]);\n const v = clean(props[prop]);\n if (k && v) {\n tags[k] = v;\n }\n });\n\n tags.source = `esri/${dataset.name}`;\n return tags;\n }\n\n function clean(val) {\n return val ? val.toString().trim() : null;\n }\n}\n\n\nexport default {\n\n init: function () {\n this.event = utilRebind(this, dispatch, 'on');\n },\n\n\n reset: function () {\n Object.values(_datasets).forEach(ds => {\n if (ds.cache.inflight) {\n Object.values(ds.cache.inflight).forEach(abortRequest);\n }\n ds.graph = coreGraph();\n ds.tree = coreTree(ds.graph);\n ds.cache = { inflight: {}, loaded: {}, seen: {}, origIdTile: {} };\n });\n\n return this;\n },\n\n\n graph: function (datasetID) {\n const ds = _datasets[datasetID];\n return ds && ds.graph;\n },\n\n\n intersects: function (datasetID, extent) {\n const ds = _datasets[datasetID];\n if (!ds || !ds.tree || !ds.graph) return [];\n return ds.tree.intersects(extent, ds.graph);\n },\n\n\n toggle: function (val) {\n _off = !val;\n return this;\n },\n\n\n loadTiles: function (datasetID, projection) {\n if (_off) return;\n\n // `loadDatasets` and `loadLayer` are asynchronous,\n // so ensure both have completed before we start requesting tiles.\n const ds = _datasets[datasetID];\n if (!ds || !ds.layer) return;\n\n const cache = ds.cache;\n const tree = ds.tree;\n const graph = ds.graph;\n const tiles = tiler.getTiles(projection);\n\n // abort inflight requests that are no longer needed\n Object.keys(cache.inflight).forEach(k => {\n const wanted = tiles.find(tile => tile.id === k);\n if (!wanted) {\n abortRequest(cache.inflight[k]);\n delete cache.inflight[k];\n }\n });\n\n tiles.forEach(tile => {\n if (cache.loaded[tile.id] || cache.inflight[tile.id]) return;\n\n const controller = new AbortController();\n const url = tileURL(ds, tile.extent);\n\n d3_json(url, { signal: controller.signal })\n .then(geojson => {\n delete cache.inflight[tile.id];\n if (!geojson) throw new Error('no geojson');\n parseTile(ds, tile, geojson, (err, results) => {\n if (err) throw new Error(err);\n graph.rebase(results, [graph], true);\n tree.rebase(results, true);\n cache.loaded[tile.id] = true;\n dispatch.call('loadedData');\n });\n })\n .catch(() => { /* ignore */ });\n\n cache.inflight[tile.id] = controller;\n });\n },\n\n\n loadDatasets: function () { // eventually pass search params?\n if (Object.keys(_datasets).length) { // for now, if we have fetched datasets, return them\n return Promise.resolve(_datasets);\n }\n\n const that = this;\n return d3_json(searchURL())\n .then(json => {\n (json.results || []).forEach(ds => { // add each one to _datasets, create internal state\n if (_datasets[ds.id]) return; // unless we've seen it already\n _datasets[ds.id] = ds;\n ds.graph = coreGraph();\n ds.tree = coreTree(ds.graph);\n ds.cache = { inflight: {}, loaded: {}, seen: {}, origIdTile: {} };\n\n // cleanup the `licenseInfo` field by removing styles (not used currently)\n let license = d3_select(document.createElement('div'));\n license.html(ds.licenseInfo); // set innerHtml\n license.selectAll('*')\n .attr('style', null)\n .attr('size', null);\n ds.license_html = license.html(); // get innerHtml\n\n // generate public link to this item\n ds.itemURL = itemURL(ds.id);\n\n // preload the layer info (or we could wait do this once the user actually clicks 'add to map')\n that.loadLayer(ds.id);\n });\n return _datasets;\n })\n .catch(() => { /* ignore */ });\n },\n\n\n loadLayer: function (datasetID) {\n let ds = _datasets[datasetID];\n if (!ds || !ds.url) {\n return Promise.reject(`Unknown datasetID: ${datasetID}`);\n } else if (ds.layer) {\n return Promise.resolve(ds.layer);\n }\n\n return d3_json(layerURL(ds.url))\n .then(json => {\n if (!json.layers || !json.layers.length) {\n throw new Error(`Missing layer info for datasetID: ${datasetID}`);\n }\n\n ds.layer = json.layers[0]; // should return a single layer\n\n // Use the field metadata to map to OSM tags\n let tagmap = {};\n ds.layer.fields.forEach(f => {\n if (f.type === 'esriFieldTypeOID') { // this is an id field, remember it\n ds.layer.idfield = f.name;\n }\n if (!f.editable) return; // 1. keep \"editable\" fields only\n tagmap[f.name] = f.alias; // 2. field `name` -> OSM tag (stored in `alias`)\n });\n ds.layer.tagmap = tagmap;\n\n return ds.layer;\n })\n .catch(() => { /* ignore */ });\n }\n};\n","/**\n * Creates a base function for methods like `_.forIn` and `_.forOwn`.\n *\n * @private\n * @param {boolean} [fromRight] Specify iterating from right to left.\n * @returns {Function} Returns the new base function.\n */\nfunction createBaseFor(fromRight) {\n return function(object, iteratee, keysFunc) {\n var index = -1,\n iterable = Object(object),\n props = keysFunc(object),\n length = props.length;\n\n while (length--) {\n var key = props[fromRight ? length : ++index];\n if (iteratee(iterable[key], key, iterable) === false) {\n break;\n }\n }\n return object;\n };\n}\n\nexport default createBaseFor;\n","import createBaseFor from './_createBaseFor.js';\n\n/**\n * The base implementation of `baseForOwn` which iterates over `object`\n * properties returned by `keysFunc` and invokes `iteratee` for each property.\n * Iteratee functions may exit iteration early by explicitly returning `false`.\n *\n * @private\n * @param {Object} object The object to iterate over.\n * @param {Function} iteratee The function invoked per iteration.\n * @param {Function} keysFunc The function to get the keys of `object`.\n * @returns {Object} Returns `object`.\n */\nvar baseFor = createBaseFor();\n\nexport default baseFor;\n","import baseFor from './_baseFor.js';\nimport keys from './keys.js';\n\n/**\n * The base implementation of `_.forOwn` without support for iteratee shorthands.\n *\n * @private\n * @param {Object} object The object to iterate over.\n * @param {Function} iteratee The function invoked per iteration.\n * @returns {Object} Returns `object`.\n */\nfunction baseForOwn(object, iteratee) {\n return object && baseFor(object, iteratee, keys);\n}\n\nexport default baseForOwn;\n","import isArrayLike from './isArrayLike.js';\n\n/**\n * Creates a `baseEach` or `baseEachRight` function.\n *\n * @private\n * @param {Function} eachFunc The function to iterate over a collection.\n * @param {boolean} [fromRight] Specify iterating from right to left.\n * @returns {Function} Returns the new base function.\n */\nfunction createBaseEach(eachFunc, fromRight) {\n return function(collection, iteratee) {\n if (collection == null) {\n return collection;\n }\n if (!isArrayLike(collection)) {\n return eachFunc(collection, iteratee);\n }\n var length = collection.length,\n index = fromRight ? length : -1,\n iterable = Object(collection);\n\n while ((fromRight ? index-- : ++index < length)) {\n if (iteratee(iterable[index], index, iterable) === false) {\n break;\n }\n }\n return collection;\n };\n}\n\nexport default createBaseEach;\n","import baseForOwn from './_baseForOwn.js';\nimport createBaseEach from './_createBaseEach.js';\n\n/**\n * The base implementation of `_.forEach` without support for iteratee shorthands.\n *\n * @private\n * @param {Array|Object} collection The collection to iterate over.\n * @param {Function} iteratee The function invoked per iteration.\n * @returns {Array|Object} Returns `collection`.\n */\nvar baseEach = createBaseEach(baseForOwn);\n\nexport default baseEach;\n","import identity from './identity.js';\n\n/**\n * Casts `value` to `identity` if it's not a function.\n *\n * @private\n * @param {*} value The value to inspect.\n * @returns {Function} Returns cast function.\n */\nfunction castFunction(value) {\n return typeof value == 'function' ? value : identity;\n}\n\nexport default castFunction;\n","import arrayEach from './_arrayEach.js';\nimport baseEach from './_baseEach.js';\nimport castFunction from './_castFunction.js';\nimport isArray from './isArray.js';\n\n/**\n * Iterates over elements of `collection` and invokes `iteratee` for each element.\n * The iteratee is invoked with three arguments: (value, index|key, collection).\n * Iteratee functions may exit iteration early by explicitly returning `false`.\n *\n * **Note:** As with other \"Collections\" methods, objects with a \"length\"\n * property are iterated like arrays. To avoid this behavior use `_.forIn`\n * or `_.forOwn` for object iteration.\n *\n * @static\n * @memberOf _\n * @since 0.1.0\n * @alias each\n * @category Collection\n * @param {Array|Object} collection The collection to iterate over.\n * @param {Function} [iteratee=_.identity] The function invoked per iteration.\n * @returns {Array|Object} Returns `collection`.\n * @see _.forEachRight\n * @example\n *\n * _.forEach([1, 2], function(value) {\n * console.log(value);\n * });\n * // => Logs `1` then `2`.\n *\n * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {\n * console.log(key);\n * });\n * // => Logs 'a' then 'b' (iteration order is not guaranteed).\n */\nfunction forEach(collection, iteratee) {\n var func = isArray(collection) ? arrayEach : baseEach;\n return func(collection, castFunction(iteratee));\n}\n\nexport default forEach;\n","import _forEach from 'lodash-es/forEach';\n\nimport { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { xml as d3_xml } from 'd3-fetch';\n\nimport { coreGraph, coreTree } from '../core';\nimport { osmEntity, osmNode, osmWay } from '../osm';\nimport { utilRebind, utilStringQs, utilTiler } from '../util';\n\n// constants\nvar APIROOT = 'https://mapwith.ai/maps/ml_roads';\nvar TILEZOOM = 16;\nvar tiler = utilTiler().zoomExtent([TILEZOOM, TILEZOOM]);\nvar dispatch = d3_dispatch('loadedData');\n\nvar _datasets = {};\nvar _deferredAiFeaturesParsing = new Set();\nvar _off;\n\n\nfunction abortRequest(i) {\n i.abort();\n}\n\n\nfunction tileURL(dataset, extent, taskExtent) {\n // Conflated datasets have a different ID, so they get stored in their own graph/tree\n var isConflated = /-conflated$/.test(dataset.id);\n var datasetID = dataset.id.replace('-conflated', '');\n\n var qs = {\n conflate_with_osm: isConflated,\n theme: 'ml_road_vector',\n collaborator: 'fbid',\n token: 'ASZUVdYpCkd3M6ZrzjXdQzHulqRMnxdlkeBJWEKOeTUoY_Gwm9fuEd2YObLrClgDB_xfavizBsh0oDfTWTF7Zb4C',\n hash: 'ASYM8LPNy8k1XoJiI7A'\n };\n\n if (datasetID === 'fbRoads') {\n qs.result_type = 'road_vector_xml';\n\n } else if (datasetID === 'msBuildings') {\n qs.result_type = 'road_building_vector_xml';\n qs.building_source = 'microsoft';\n\n } else {\n qs.result_type = 'osm_xml';\n qs.sources = `esri_building.${datasetID}`;\n }\n\n qs.bbox = extent.toParam();\n\n if (taskExtent) qs.crop_bbox = taskExtent.toParam();\n\n // Note: we are not sure whether the `fb_ml_road_url` and `fb_ml_road_tags` query params are used anymore.\n var customUrlRoot = utilStringQs(window.location.hash).fb_ml_road_url;\n var customRoadTags = utilStringQs(window.location.hash).fb_ml_road_tags;\n\n var urlRoot = customUrlRoot || APIROOT;\n var url = urlRoot + '?' + utilQsString(qs, true); // true = noencode\n\n if (customRoadTags) {\n customRoadTags.split(',').forEach(function (tag) {\n url += '&allow_tags[]=' + tag;\n });\n }\n\n return url;\n\n\n // This utilQsString does not sort the keys, because the fbml service needs them to be ordered a certain way.\n function utilQsString(obj, noencode) {\n // encode everything except special characters used in certain hash parameters:\n // \"/\" in map states, \":\", \",\", {\" and \"}\" in background\n function softEncode(s) {\n return encodeURIComponent(s).replace(/(%2F|%3A|%2C|%7B|%7D)/g, decodeURIComponent);\n }\n\n return Object.keys(obj).map(function(key) { // NO SORT\n return encodeURIComponent(key) + '=' + (\n noencode ? softEncode(obj[key]) : encodeURIComponent(obj[key]));\n }).join('&');\n }\n\n}\n\n\nfunction getLoc(attrs) {\n var lon = attrs.lon && attrs.lon.value;\n var lat = attrs.lat && attrs.lat.value;\n return [parseFloat(lon), parseFloat(lat)];\n}\n\n\nfunction getNodes(obj) {\n var elems = obj.getElementsByTagName('nd');\n var nodes = new Array(elems.length);\n for (var i = 0, l = elems.length; i < l; i++) {\n nodes[i] = 'n' + elems[i].attributes.ref.value;\n }\n return nodes;\n}\n\n\nfunction getTags(obj) {\n var elems = obj.getElementsByTagName('tag');\n var tags = {};\n for (var i = 0, l = elems.length; i < l; i++) {\n var attrs = elems[i].attributes;\n var k = (attrs.k.value || '').trim();\n var v = (attrs.v.value || '').trim();\n if (k && v) {\n tags[k] = v;\n }\n }\n\n return tags;\n}\n\n\nfunction getVisible(attrs) {\n return (!attrs.visible || attrs.visible.value !== 'false');\n}\n\n\nvar parsers = {\n node: function nodeData(obj, uid) {\n var attrs = obj.attributes;\n return new osmNode({\n id: uid,\n visible: getVisible(attrs),\n loc: getLoc(attrs),\n tags: getTags(obj)\n });\n },\n\n way: function wayData(obj, uid) {\n var attrs = obj.attributes;\n return new osmWay({\n id: uid,\n visible: getVisible(attrs),\n tags: getTags(obj),\n nodes: getNodes(obj),\n });\n }\n};\n\n\nfunction parseXML(dataset, xml, tile, callback, options) {\n options = Object.assign({ skipSeen: true }, options);\n if (!xml || !xml.childNodes) {\n return callback({ message: 'No XML', status: -1 });\n }\n\n var graph = dataset.graph;\n var cache = dataset.cache;\n\n var root = xml.childNodes[0];\n var children = root.childNodes;\n var handle = window.requestIdleCallback(function() {\n _deferredAiFeaturesParsing.delete(handle);\n var results = [];\n for (var i = 0; i < children.length; i++) {\n var result = parseChild(children[i]);\n if (result) results.push(result);\n }\n callback(null, results);\n });\n _deferredAiFeaturesParsing.add(handle);\n\n\n function parseChild(child) {\n var parser = parsers[child.nodeName];\n if (!parser) return null;\n\n var uid = osmEntity.id.fromOSM(child.nodeName, child.attributes.id.value);\n if (options.skipSeen) {\n if (cache.seen[uid]) return null; // avoid reparsing a \"seen\" entity\n if (cache.origIdTile[uid]) return null; // avoid double-parsing a split way\n cache.seen[uid] = true;\n }\n\n // Handle non-deterministic way splitting from Roads Service. Splits\n // are consistent within a single request.\n var origUid;\n if (child.attributes.orig_id) {\n origUid = osmEntity.id.fromOSM(child.nodeName, child.attributes.orig_id.value);\n if (graph.entities[origUid] ||\n (cache.origIdTile[origUid] && cache.origIdTile[origUid] !== tile.id)) {\n return null;\n }\n cache.origIdTile[origUid] = tile.id;\n }\n\n var entity = parser(child, uid);\n var meta = {\n __fbid__: child.attributes.id.value,\n __origid__: origUid,\n __service__: 'fbml',\n __datasetid__: dataset.id\n };\n return Object.assign(entity, meta);\n }\n}\n\n\nexport default {\n\n init: function() {\n this.event = utilRebind(this, dispatch, 'on');\n\n // allocate a special dataset for the rapid intro graph.\n var datasetID = 'rapid_intro_graph';\n var graph = coreGraph();\n var tree = coreTree(graph);\n var cache = { inflight: {}, loaded: {}, seen: {}, origIdTile: {} };\n var ds = { id: datasetID, graph: graph, tree: tree, cache: cache };\n _datasets[datasetID] = ds;\n },\n\n reset: function() {\n Array.from(_deferredAiFeaturesParsing).forEach(function(handle) {\n window.cancelIdleCallback(handle);\n _deferredAiFeaturesParsing.delete(handle);\n });\n\n Object.values(_datasets).forEach(function(ds) {\n if (ds.cache.inflight) {\n Object.values(ds.cache.inflight).forEach(abortRequest);\n }\n ds.graph = coreGraph();\n ds.tree = coreTree(ds.graph);\n ds.cache = { inflight: {}, loaded: {}, seen: {}, origIdTile: {} };\n });\n\n return this;\n },\n\n\n graph: function (datasetID) {\n var ds = _datasets[datasetID];\n return ds && ds.graph;\n },\n\n\n intersects: function (datasetID, extent) {\n var ds = _datasets[datasetID];\n if (!ds || !ds.tree || !ds.graph) return [];\n return ds.tree.intersects(extent, ds.graph);\n },\n\n\n merge: function(datasetID, entities) {\n var ds = _datasets[datasetID];\n if (!ds || !ds.tree || !ds.graph) return;\n ds.graph.rebase(entities, [ds.graph], false);\n ds.tree.rebase(entities, false);\n },\n\n\n cache: function (datasetID, obj) {\n var ds = _datasets[datasetID];\n if (!ds || !ds.cache) return;\n\n function cloneDeep(source) {\n return JSON.parse(JSON.stringify(source));\n }\n\n if (!arguments.length) {\n return {\n tile: cloneDeep(ds.cache)\n };\n }\n\n // access cache directly for testing\n if (obj === 'get') {\n return ds.cache;\n }\n\n ds.cache = obj;\n },\n\n\n toggle: function(val) {\n _off = !val;\n return this;\n },\n\n\n loadTiles: function(datasetID, projection, taskExtent) {\n if (_off) return;\n\n var ds = _datasets[datasetID];\n var graph, tree, cache;\n if (ds) {\n graph = ds.graph;\n tree = ds.tree;\n cache = ds.cache;\n } else {\n // as tile requests arrive, setup the resources needed to hold the results\n graph = coreGraph();\n tree = coreTree(graph);\n cache = { inflight: {}, loaded: {}, seen: {}, origIdTile: {} };\n ds = { id: datasetID, graph: graph, tree: tree, cache: cache };\n _datasets[datasetID] = ds;\n }\n\n\n var tiles = tiler.getTiles(projection);\n\n // abort inflight requests that are no longer needed\n _forEach(cache.inflight, function(v, k) {\n var wanted = tiles.find(function(tile) { return k === tile.id; });\n if (!wanted) {\n abortRequest(v);\n delete cache.inflight[k];\n }\n });\n\n tiles.forEach(function(tile) {\n if (cache.loaded[tile.id] || cache.inflight[tile.id]) return;\n\n var controller = new AbortController();\n d3_xml(tileURL(ds, tile.extent, taskExtent), { signal: controller.signal })\n .then(function (dom) {\n delete cache.inflight[tile.id];\n if (!dom) return;\n parseXML(ds, dom, tile, function(err, results) {\n if (err) return;\n graph.rebase(results, [graph], true);\n tree.rebase(results, true);\n cache.loaded[tile.id] = true;\n dispatch.call('loadedData');\n });\n })\n .catch(function() {});\n\n cache.inflight[tile.id] = controller;\n });\n }\n};\n","import RBush from 'rbush';\n\nimport { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { json as d3_json } from 'd3-fetch';\n\nimport { fileFetcher } from '../core/file_fetcher';\nimport { geoExtent, geoVecAdd } from '../geo';\nimport { QAItem } from '../osm';\nimport { t } from '../core/localizer';\nimport { utilRebind, utilTiler, utilQsString } from '../util';\n\n\nconst tiler = utilTiler();\nconst dispatch = d3_dispatch('loaded');\nconst _tileZoom = 14;\nconst _krUrlRoot = 'https://www.keepright.at';\nlet _krData = { errorTypes: {}, localizeStrings: {} };\n\n// This gets reassigned if reset\nlet _cache;\n\nconst _krRuleset = [\n // no 20 - multiple node on same spot - these are mostly boundaries overlapping roads\n 30, 40, 50, 60, 70, 90, 100, 110, 120, 130, 150, 160, 170, 180,\n 190, 191, 192, 193, 194, 195, 196, 197, 198,\n 200, 201, 202, 203, 204, 205, 206, 207, 208, 210, 220,\n 230, 231, 232, 270, 280, 281, 282, 283, 284, 285,\n 290, 291, 292, 293, 294, 295, 296, 297, 298, 300, 310, 311, 312, 313,\n 320, 350, 360, 370, 380, 390, 400, 401, 402, 410, 411, 412, 413\n];\n\n\nfunction abortRequest(controller) {\n if (controller) {\n controller.abort();\n }\n}\n\nfunction abortUnwantedRequests(cache, tiles) {\n Object.keys(cache.inflightTile).forEach(k => {\n const wanted = tiles.find(tile => k === tile.id);\n if (!wanted) {\n abortRequest(cache.inflightTile[k]);\n delete cache.inflightTile[k];\n }\n });\n}\n\n\nfunction encodeIssueRtree(d) {\n return { minX: d.loc[0], minY: d.loc[1], maxX: d.loc[0], maxY: d.loc[1], data: d };\n}\n\n\n// Replace or remove QAItem from rtree\nfunction updateRtree(item, replace) {\n _cache.rtree.remove(item, (a, b) => a.data.id === b.data.id);\n\n if (replace) {\n _cache.rtree.insert(item);\n }\n}\n\n\nfunction tokenReplacements(d) {\n if (!(d instanceof QAItem)) return;\n\n const htmlRegex = new RegExp(/<\\/[a-z][\\s\\S]*>/);\n const replacements = {};\n\n const issueTemplate = _krData.errorTypes[d.whichType];\n if (!issueTemplate) {\n /* eslint-disable no-console */\n console.log('No Template: ', d.whichType);\n console.log(' ', d.description);\n /* eslint-enable no-console */\n return;\n }\n\n // some descriptions are just fixed text\n if (!issueTemplate.regex) return;\n\n // regex pattern should match description with variable details captured\n const errorRegex = new RegExp(issueTemplate.regex, 'i');\n const errorMatch = errorRegex.exec(d.description);\n if (!errorMatch) {\n /* eslint-disable no-console */\n console.log('Unmatched: ', d.whichType);\n console.log(' ', d.description);\n console.log(' ', errorRegex);\n /* eslint-enable no-console */\n return;\n }\n\n for (let i = 1; i < errorMatch.length; i++) { // skip first\n let capture = errorMatch[i];\n let idType;\n\n idType = 'IDs' in issueTemplate ? issueTemplate.IDs[i-1] : '';\n if (idType && capture) { // link IDs if present in the capture\n capture = parseError(capture, idType);\n } else if (htmlRegex.test(capture)) { // escape any html in non-IDs\n capture = '\\\\' + capture + '\\\\';\n } else {\n const compare = capture.toLowerCase();\n if (_krData.localizeStrings[compare]) { // some replacement strings can be localized\n capture = t('QA.keepRight.error_parts.' + _krData.localizeStrings[compare]);\n }\n }\n\n replacements['var' + i] = capture;\n }\n\n return replacements;\n}\n\n\nfunction parseError(capture, idType) {\n const compare = capture.toLowerCase();\n if (_krData.localizeStrings[compare]) { // some replacement strings can be localized\n capture = t('QA.keepRight.error_parts.' + _krData.localizeStrings[compare]);\n }\n\n switch (idType) {\n // link a string like \"this node\"\n case 'this':\n capture = linkErrorObject(capture);\n break;\n\n case 'url':\n capture = linkURL(capture);\n break;\n\n // link an entity ID\n case 'n':\n case 'w':\n case 'r':\n capture = linkEntity(idType + capture);\n break;\n\n // some errors have more complex ID lists/variance\n case '20':\n capture = parse20(capture);\n break;\n case '211':\n capture = parse211(capture);\n break;\n case '231':\n capture = parse231(capture);\n break;\n case '294':\n capture = parse294(capture);\n break;\n case '370':\n capture = parse370(capture);\n break;\n }\n\n return capture;\n\n\n function linkErrorObject(d) {\n return `${d} `;\n }\n\n function linkEntity(d) {\n return `${d} `;\n }\n\n function linkURL(d) {\n return `${d} `;\n }\n\n // arbitrary node list of form: #ID, #ID, #ID...\n function parse211(capture) {\n let newList = [];\n const items = capture.split(', ');\n\n items.forEach(item => {\n // ID has # at the front\n let id = linkEntity('n' + item.slice(1));\n newList.push(id);\n });\n\n return newList.join(', ');\n }\n\n // arbitrary way list of form: #ID(layer),#ID(layer),#ID(layer)...\n function parse231(capture) {\n let newList = [];\n // unfortunately 'layer' can itself contain commas, so we split on '),'\n const items = capture.split('),');\n\n items.forEach(item => {\n const match = item.match(/\\#(\\d+)\\((.+)\\)?/);\n if (match !== null && match.length > 2) {\n newList.push(linkEntity('w' + match[1]) + ' ' +\n t('QA.keepRight.errorTypes.231.layer', { layer: match[2] })\n );\n }\n });\n\n return newList.join(', ');\n }\n\n // arbitrary node/relation list of form: from node #ID,to relation #ID,to node #ID...\n function parse294(capture) {\n let newList = [];\n const items = capture.split(',');\n\n items.forEach(item => {\n // item of form \"from/to node/relation #ID\"\n item = item.split(' ');\n\n // to/from role is more clear in quotes\n const role = `\"${item[0]}\"`;\n\n // first letter of node/relation provides the type\n const idType = item[1].slice(0,1);\n\n // ID has # at the front\n let id = item[2].slice(1);\n id = linkEntity(idType + id);\n\n newList.push(`${role} ${item[1]} ${id}`);\n });\n\n return newList.join(', ');\n }\n\n // may or may not include the string \"(including the name 'name')\"\n function parse370(capture) {\n if (!capture) return '';\n\n const match = capture.match(/\\(including the name (\\'.+\\')\\)/);\n if (match && match.length) {\n return t('QA.keepRight.errorTypes.370.including_the_name', { name: match[1] });\n }\n return '';\n }\n\n // arbitrary node list of form: #ID,#ID,#ID...\n function parse20(capture) {\n let newList = [];\n const items = capture.split(',');\n\n items.forEach(item => {\n // ID has # at the front\n const id = linkEntity('n' + item.slice(1));\n newList.push(id);\n });\n\n return newList.join(', ');\n }\n}\n\n\nexport default {\n title: 'keepRight',\n\n init() {\n fileFetcher.get('keepRight')\n .then(d => _krData = d);\n\n if (!_cache) {\n this.reset();\n }\n\n this.event = utilRebind(this, dispatch, 'on');\n },\n\n reset() {\n if (_cache) {\n Object.values(_cache.inflightTile).forEach(abortRequest);\n }\n\n _cache = {\n data: {},\n loadedTile: {},\n inflightTile: {},\n inflightPost: {},\n closed: {},\n rtree: new RBush()\n };\n },\n\n\n // KeepRight API: http://osm.mueschelsoft.de/keepright/interfacing.php\n loadIssues(projection) {\n const options = {\n format: 'geojson',\n ch: _krRuleset\n };\n\n // determine the needed tiles to cover the view\n const tiles = tiler\n .zoomExtent([_tileZoom, _tileZoom])\n .getTiles(projection);\n\n // abort inflight requests that are no longer needed\n abortUnwantedRequests(_cache, tiles);\n\n // issue new requests..\n tiles.forEach(tile => {\n if (_cache.loadedTile[tile.id] || _cache.inflightTile[tile.id]) return;\n\n const [ left, top, right, bottom ] = tile.extent.rectangle();\n const params = Object.assign({}, options, { left, bottom, right, top });\n const url = `${_krUrlRoot}/export.php?` + utilQsString(params);\n const controller = new AbortController();\n\n _cache.inflightTile[tile.id] = controller;\n\n d3_json(url, { signal: controller.signal })\n .then(data => {\n delete _cache.inflightTile[tile.id];\n _cache.loadedTile[tile.id] = true;\n if (!data || !data.features || !data.features.length) {\n throw new Error('No Data');\n }\n\n data.features.forEach(feature => {\n const {\n properties: {\n error_type: itemType,\n error_id: id,\n comment = null,\n object_id: objectId,\n object_type: objectType,\n schema,\n title\n }\n } = feature;\n let {\n geometry: { coordinates: loc },\n properties: { description = '' }\n } = feature;\n\n // if there is a parent, save its error type e.g.:\n // Error 191 = \"highway-highway\"\n // Error 190 = \"intersections without junctions\" (parent)\n const issueTemplate = _krData.errorTypes[itemType];\n const parentIssueType = (Math.floor(itemType / 10) * 10).toString();\n\n // try to handle error type directly, fallback to parent error type.\n const whichType = issueTemplate ? itemType : parentIssueType;\n const whichTemplate = _krData.errorTypes[whichType];\n\n // Rewrite a few of the errors at this point..\n // This is done to make them easier to linkify and translate.\n switch (whichType) {\n case '170':\n description = `This feature has a FIXME tag: ${description}`;\n break;\n case '292':\n case '293':\n description = description.replace('A turn-', 'This turn-');\n break;\n case '294':\n case '295':\n case '296':\n case '297':\n case '298':\n description = `This turn-restriction~${description}`;\n break;\n case '300':\n description = 'This highway is missing a maxspeed tag';\n break;\n case '411':\n case '412':\n case '413':\n description = `This feature~${description}`;\n break;\n }\n\n // move markers slightly so it doesn't obscure the geometry,\n // then move markers away from other coincident markers\n let coincident = false;\n do {\n // first time, move marker up. after that, move marker right.\n let delta = coincident ? [0.00001, 0] : [0, 0.00001];\n loc = geoVecAdd(loc, delta);\n let bbox = geoExtent(loc).bbox();\n coincident = _cache.rtree.search(bbox).length;\n } while (coincident);\n\n let d = new QAItem(loc, this, itemType, id, {\n comment,\n description,\n whichType,\n parentIssueType,\n severity: whichTemplate.severity || 'error',\n objectId,\n objectType,\n schema,\n title\n });\n\n d.replacements = tokenReplacements(d);\n\n _cache.data[id] = d;\n _cache.rtree.insert(encodeIssueRtree(d));\n });\n\n dispatch.call('loaded');\n })\n .catch(() => {\n delete _cache.inflightTile[tile.id];\n _cache.loadedTile[tile.id] = true;\n });\n\n });\n },\n\n\n postUpdate(d, callback) {\n if (_cache.inflightPost[d.id]) {\n return callback({ message: 'Error update already inflight', status: -2 }, d);\n }\n\n const params = { schema: d.schema, id: d.id };\n\n if (d.newStatus) {\n params.st = d.newStatus;\n }\n if (d.newComment !== undefined) {\n params.co = d.newComment;\n }\n\n // NOTE: This throws a CORS err, but it seems successful.\n // We don't care too much about the response, so this is fine.\n const url = `${_krUrlRoot}/comment.php?` + utilQsString(params);\n const controller = new AbortController();\n\n _cache.inflightPost[d.id] = controller;\n\n // Since this is expected to throw an error just continue as if it worked\n // (worst case scenario the request truly fails and issue will show up if iD restarts)\n d3_json(url, { signal: controller.signal })\n .finally(() => {\n delete _cache.inflightPost[d.id];\n\n if (d.newStatus === 'ignore') {\n // ignore permanently (false positive)\n this.removeItem(d);\n } else if (d.newStatus === 'ignore_t') {\n // ignore temporarily (error fixed)\n this.removeItem(d);\n _cache.closed[`${d.schema}:${d.id}`] = true;\n } else {\n d = this.replaceItem(d.update({\n comment: d.newComment,\n newComment: undefined,\n newState: undefined\n }));\n }\n\n if (callback) callback(null, d);\n });\n },\n\n // Get all cached QAItems covering the viewport\n getItems(projection) {\n const viewport = projection.clipExtent();\n const min = [viewport[0][0], viewport[1][1]];\n const max = [viewport[1][0], viewport[0][1]];\n const bbox = geoExtent(projection.invert(min), projection.invert(max)).bbox();\n\n return _cache.rtree.search(bbox).map(d => d.data);\n },\n\n // Get a QAItem from cache\n // NOTE: Don't change method name until UI v3 is merged\n getError(id) {\n return _cache.data[id];\n },\n\n // Replace a single QAItem in the cache\n replaceItem(item) {\n if (!(item instanceof QAItem) || !item.id) return;\n\n _cache.data[item.id] = item;\n updateRtree(encodeIssueRtree(item), true); // true = replace\n return item;\n },\n\n // Remove a single QAItem from the cache\n removeItem(item) {\n if (!(item instanceof QAItem) || !item.id) return;\n\n delete _cache.data[item.id];\n updateRtree(encodeIssueRtree(item), false); // false = remove\n },\n\n issueURL(item) {\n return `${_krUrlRoot}/report_map.php?schema=${item.schema}&error=${item.id}`;\n },\n\n // Get an array of issues closed during this session.\n // Used to populate `closed:keepright` changeset tag\n getClosedIDs() {\n return Object.keys(_cache.closed).sort();\n }\n\n};\n","import RBush from 'rbush';\n\nimport { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { json as d3_json } from 'd3-fetch';\n\nimport { fileFetcher } from '../core/file_fetcher';\nimport { geoExtent, geoVecAdd, geoVecScale } from '../geo';\nimport { QAItem } from '../osm';\nimport { serviceOsm } from './index';\nimport { t } from '../core/localizer';\nimport { utilRebind, utilTiler, utilQsString } from '../util';\n\n\nconst tiler = utilTiler();\nconst dispatch = d3_dispatch('loaded');\nconst _tileZoom = 14;\nconst _impOsmUrls = {\n ow: 'https://grab.community.improve-osm.org/directionOfFlowService',\n mr: 'https://grab.community.improve-osm.org/missingGeoService',\n tr: 'https://grab.community.improve-osm.org/turnRestrictionService'\n};\nlet _impOsmData = { icons: {} };\n\n\n// This gets reassigned if reset\nlet _cache;\n\nfunction abortRequest(i) {\n Object.values(i).forEach(controller => {\n if (controller) {\n controller.abort();\n }\n });\n}\n\nfunction abortUnwantedRequests(cache, tiles) {\n Object.keys(cache.inflightTile).forEach(k => {\n const wanted = tiles.find(tile => k === tile.id);\n if (!wanted) {\n abortRequest(cache.inflightTile[k]);\n delete cache.inflightTile[k];\n }\n });\n}\n\nfunction encodeIssueRtree(d) {\n return { minX: d.loc[0], minY: d.loc[1], maxX: d.loc[0], maxY: d.loc[1], data: d };\n}\n\n// Replace or remove QAItem from rtree\nfunction updateRtree(item, replace) {\n _cache.rtree.remove(item, (a, b) => a.data.id === b.data.id);\n\n if (replace) {\n _cache.rtree.insert(item);\n }\n}\n\nfunction linkErrorObject(d) {\n return `${d} `;\n}\n\nfunction linkEntity(d) {\n return `${d} `;\n}\n\nfunction pointAverage(points) {\n if (points.length) {\n const sum = points.reduce(\n (acc, point) => geoVecAdd(acc, [point.lon, point.lat]),\n [0,0]\n );\n return geoVecScale(sum, 1 / points.length);\n } else {\n return [0,0];\n }\n}\n\nfunction relativeBearing(p1, p2) {\n let angle = Math.atan2(p2.lon - p1.lon, p2.lat - p1.lat);\n if (angle < 0) {\n angle += 2 * Math.PI;\n }\n\n // Return degrees\n return angle * 180 / Math.PI;\n}\n\n// Assuming range [0,360)\nfunction cardinalDirection(bearing) {\n const dir = 45 * Math.round(bearing / 45);\n const compass = {\n 0: 'north',\n 45: 'northeast',\n 90: 'east',\n 135: 'southeast',\n 180: 'south',\n 225: 'southwest',\n 270: 'west',\n 315: 'northwest',\n 360: 'north'\n };\n\n return t(`QA.improveOSM.directions.${compass[dir]}`);\n}\n\n// Errors shouldn't obscure eachother\nfunction preventCoincident(loc, bumpUp) {\n let coincident = false;\n do {\n // first time, move marker up. after that, move marker right.\n let delta = coincident ? [0.00001, 0] : (bumpUp ? [0, 0.00001] : [0, 0]);\n loc = geoVecAdd(loc, delta);\n let bbox = geoExtent(loc).bbox();\n coincident = _cache.rtree.search(bbox).length;\n } while (coincident);\n\n return loc;\n}\n\nexport default {\n title: 'improveOSM',\n\n init() {\n fileFetcher.get('qa_data')\n .then(d => _impOsmData = d.improveOSM);\n\n if (!_cache) {\n this.reset();\n }\n\n this.event = utilRebind(this, dispatch, 'on');\n },\n\n reset() {\n if (_cache) {\n Object.values(_cache.inflightTile).forEach(abortRequest);\n }\n _cache = {\n data: {},\n loadedTile: {},\n inflightTile: {},\n inflightPost: {},\n closed: {},\n rtree: new RBush()\n };\n },\n\n loadIssues(projection) {\n const options = {\n client: 'iD',\n status: 'OPEN',\n zoom: '19' // Use a high zoom so that clusters aren't returned\n };\n\n // determine the needed tiles to cover the view\n const tiles = tiler\n .zoomExtent([_tileZoom, _tileZoom])\n .getTiles(projection);\n\n // abort inflight requests that are no longer needed\n abortUnwantedRequests(_cache, tiles);\n\n // issue new requests..\n tiles.forEach(tile => {\n if (_cache.loadedTile[tile.id] || _cache.inflightTile[tile.id]) return;\n\n const [ east, north, west, south ] = tile.extent.rectangle();\n const params = Object.assign({}, options, { east, south, west, north });\n\n // 3 separate requests to store for each tile\n const requests = {};\n\n Object.keys(_impOsmUrls).forEach(k => {\n // We exclude WATER from missing geometry as it doesn't seem useful\n // We use most confident one-way and turn restrictions only, still have false positives\n const kParams = Object.assign({},\n params,\n (k === 'mr') ? { type: 'PARKING,ROAD,BOTH,PATH' } : { confidenceLevel: 'C1' }\n );\n const url = `${_impOsmUrls[k]}/search?` + utilQsString(kParams);\n const controller = new AbortController();\n\n requests[k] = controller;\n\n d3_json(url, { signal: controller.signal })\n .then(data => {\n delete _cache.inflightTile[tile.id][k];\n if (!Object.keys(_cache.inflightTile[tile.id]).length) {\n delete _cache.inflightTile[tile.id];\n _cache.loadedTile[tile.id] = true;\n }\n\n // Road segments at high zoom == oneways\n if (data.roadSegments) {\n data.roadSegments.forEach(feature => {\n // Position error at the approximate middle of the segment\n const { points, wayId, fromNodeId, toNodeId } = feature;\n const itemId = `${wayId}${fromNodeId}${toNodeId}`;\n let mid = points.length / 2;\n let loc;\n\n // Even number of points, find midpoint of the middle two\n // Odd number of points, use position of very middle point\n if (mid % 1 === 0) {\n loc = pointAverage([points[mid - 1], points[mid]]);\n } else {\n mid = points[Math.floor(mid)];\n loc = [mid.lon, mid.lat];\n }\n\n // One-ways can land on same segment in opposite direction\n loc = preventCoincident(loc, false);\n\n let d = new QAItem(loc, this, k, itemId, {\n issueKey: k, // used as a category\n identifier: { // used to post changes\n wayId,\n fromNodeId,\n toNodeId\n },\n objectId: wayId,\n objectType: 'way'\n });\n\n // Variables used in the description\n d.replacements = {\n percentage: feature.percentOfTrips,\n num_trips: feature.numberOfTrips,\n highway: linkErrorObject(t('QA.keepRight.error_parts.highway')),\n from_node: linkEntity('n' + feature.fromNodeId),\n to_node: linkEntity('n' + feature.toNodeId)\n };\n\n _cache.data[d.id] = d;\n _cache.rtree.insert(encodeIssueRtree(d));\n });\n }\n\n // Tiles at high zoom == missing roads\n if (data.tiles) {\n data.tiles.forEach(feature => {\n const { type, x, y, numberOfTrips } = feature;\n const geoType = type.toLowerCase();\n const itemId = `${geoType}${x}${y}${numberOfTrips}`;\n\n // Average of recorded points should land on the missing geometry\n // Missing geometry could happen to land on another error\n let loc = pointAverage(feature.points);\n loc = preventCoincident(loc, false);\n\n let d = new QAItem(loc, this, `${k}-${geoType}`, itemId, {\n issueKey: k,\n identifier: { x, y }\n });\n\n d.replacements = {\n num_trips: numberOfTrips,\n geometry_type: t(`QA.improveOSM.geometry_types.${geoType}`)\n };\n\n // -1 trips indicates data came from a 3rd party\n if (numberOfTrips === -1) {\n d.desc = t('QA.improveOSM.error_types.mr.description_alt', d.replacements);\n }\n\n _cache.data[d.id] = d;\n _cache.rtree.insert(encodeIssueRtree(d));\n });\n }\n\n // Entities at high zoom == turn restrictions\n if (data.entities) {\n data.entities.forEach(feature => {\n const { point, id, segments, numberOfPasses, turnType } = feature;\n const itemId = `${id.replace(/[,:+#]/g, '_')}`;\n\n // Turn restrictions could be missing at same junction\n // We also want to bump the error up so node is accessible\n const loc = preventCoincident([point.lon, point.lat], true);\n\n // Elements are presented in a strange way\n const ids = id.split(',');\n const from_way = ids[0];\n const via_node = ids[3];\n const to_way = ids[2].split(':')[1];\n\n let d = new QAItem(loc, this, k, itemId, {\n issueKey: k,\n identifier: id,\n objectId: via_node,\n objectType: 'node'\n });\n\n // Travel direction along from_way clarifies the turn restriction\n const [ p1, p2 ] = segments[0].points;\n const dir_of_travel = cardinalDirection(relativeBearing(p1, p2));\n\n // Variables used in the description\n d.replacements = {\n num_passed: numberOfPasses,\n num_trips: segments[0].numberOfTrips,\n turn_restriction: turnType.toLowerCase(),\n from_way: linkEntity('w' + from_way),\n to_way: linkEntity('w' + to_way),\n travel_direction: dir_of_travel,\n junction: linkErrorObject(t('QA.keepRight.error_parts.this_node'))\n };\n\n _cache.data[d.id] = d;\n _cache.rtree.insert(encodeIssueRtree(d));\n dispatch.call('loaded');\n });\n }\n })\n .catch(() => {\n delete _cache.inflightTile[tile.id][k];\n if (!Object.keys(_cache.inflightTile[tile.id]).length) {\n delete _cache.inflightTile[tile.id];\n _cache.loadedTile[tile.id] = true;\n }\n });\n });\n\n _cache.inflightTile[tile.id] = requests;\n });\n },\n\n getComments(item) {\n // If comments already retrieved no need to do so again\n if (item.comments) {\n return Promise.resolve(item);\n }\n\n const key = item.issueKey;\n let qParams = {};\n\n if (key === 'ow') {\n qParams = item.identifier;\n } else if (key === 'mr') {\n qParams.tileX = item.identifier.x;\n qParams.tileY = item.identifier.y;\n } else if (key === 'tr') {\n qParams.targetId = item.identifier;\n }\n\n const url = `${_impOsmUrls[key]}/retrieveComments?` + utilQsString(qParams);\n const cacheComments = data => {\n // Assign directly for immediate use afterwards\n // comments are served newest to oldest\n item.comments = data.comments ? data.comments.reverse() : [];\n this.replaceItem(item);\n };\n\n return d3_json(url).then(cacheComments).then(() => item);\n },\n\n postUpdate(d, callback) {\n if (!serviceOsm.authenticated()) { // Username required in payload\n return callback({ message: 'Not Authenticated', status: -3}, d);\n }\n if (_cache.inflightPost[d.id]) {\n return callback({ message: 'Error update already inflight', status: -2 }, d);\n }\n\n // Payload can only be sent once username is established\n serviceOsm.userDetails(sendPayload.bind(this));\n\n function sendPayload(err, user) {\n if (err) { return callback(err, d); }\n\n const key = d.issueKey;\n const url = `${_impOsmUrls[key]}/comment`;\n const payload = {\n username: user.display_name,\n targetIds: [ d.identifier ]\n };\n\n if (d.newStatus) {\n payload.status = d.newStatus;\n payload.text = 'status changed';\n }\n\n // Comment take place of default text\n if (d.newComment) {\n payload.text = d.newComment;\n }\n\n const controller = new AbortController();\n _cache.inflightPost[d.id] = controller;\n\n const options = {\n method: 'POST',\n signal: controller.signal,\n body: JSON.stringify(payload)\n };\n\n d3_json(url, options)\n .then(() => {\n delete _cache.inflightPost[d.id];\n\n // Just a comment, update error in cache\n if (!d.newStatus) {\n const now = new Date();\n let comments = d.comments ? d.comments : [];\n\n comments.push({\n username: payload.username,\n text: payload.text,\n timestamp: now.getTime() / 1000\n });\n\n this.replaceItem(d.update({\n comments: comments,\n newComment: undefined\n }));\n } else {\n this.removeItem(d);\n if (d.newStatus === 'SOLVED') {\n // Keep track of the number of issues closed per type to tag the changeset\n if (!(d.issueKey in _cache.closed)) {\n _cache.closed[d.issueKey] = 0;\n }\n _cache.closed[d.issueKey] += 1;\n }\n }\n if (callback) callback(null, d);\n })\n .catch(err => {\n delete _cache.inflightPost[d.id];\n if (callback) callback(err.message);\n });\n }\n },\n\n\n // Get all cached QAItems covering the viewport\n getItems(projection) {\n const viewport = projection.clipExtent();\n const min = [viewport[0][0], viewport[1][1]];\n const max = [viewport[1][0], viewport[0][1]];\n const bbox = geoExtent(projection.invert(min), projection.invert(max)).bbox();\n\n return _cache.rtree.search(bbox).map(d => d.data);\n },\n\n // Get a QAItem from cache\n // NOTE: Don't change method name until UI v3 is merged\n getError(id) {\n return _cache.data[id];\n },\n\n // get the name of the icon to display for this item\n getIcon(itemType) {\n return _impOsmData.icons[itemType];\n },\n\n // Replace a single QAItem in the cache\n replaceItem(issue) {\n if (!(issue instanceof QAItem) || !issue.id) return;\n\n _cache.data[issue.id] = issue;\n updateRtree(encodeIssueRtree(issue), true); // true = replace\n return issue;\n },\n\n // Remove a single QAItem from the cache\n removeItem(issue) {\n if (!(issue instanceof QAItem) || !issue.id) return;\n\n delete _cache.data[issue.id];\n updateRtree(encodeIssueRtree(issue), false); // false = remove\n },\n\n // Used to populate `closed:improveosm:*` changeset tags\n getClosedCounts() {\n return _cache.closed;\n }\n};\n","import RBush from 'rbush';\n\nimport { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { json as d3_json } from 'd3-fetch';\n\nimport marked from 'marked';\n\nimport { fileFetcher } from '../core/file_fetcher';\nimport { localizer } from '../core/localizer';\nimport { geoExtent, geoVecAdd } from '../geo';\nimport { QAItem } from '../osm';\nimport { utilRebind, utilTiler, utilQsString } from '../util';\n\nconst tiler = utilTiler();\nconst dispatch = d3_dispatch('loaded');\nconst _tileZoom = 14;\nconst _osmoseUrlRoot = 'https://osmose.openstreetmap.fr/api/0.3';\nlet _osmoseData = { icons: {}, items: [] };\n\n// This gets reassigned if reset\nlet _cache;\n\nfunction abortRequest(controller) {\n if (controller) {\n controller.abort();\n }\n}\n\nfunction abortUnwantedRequests(cache, tiles) {\n Object.keys(cache.inflightTile).forEach(k => {\n let wanted = tiles.find(tile => k === tile.id);\n if (!wanted) {\n abortRequest(cache.inflightTile[k]);\n delete cache.inflightTile[k];\n }\n });\n}\n\nfunction encodeIssueRtree(d) {\n return { minX: d.loc[0], minY: d.loc[1], maxX: d.loc[0], maxY: d.loc[1], data: d };\n}\n\n// Replace or remove QAItem from rtree\nfunction updateRtree(item, replace) {\n _cache.rtree.remove(item, (a, b) => a.data.id === b.data.id);\n\n if (replace) {\n _cache.rtree.insert(item);\n }\n}\n\n// Issues shouldn't obscure eachother\nfunction preventCoincident(loc) {\n let coincident = false;\n do {\n // first time, move marker up. after that, move marker right.\n let delta = coincident ? [0.00001, 0] : [0, 0.00001];\n loc = geoVecAdd(loc, delta);\n let bbox = geoExtent(loc).bbox();\n coincident = _cache.rtree.search(bbox).length;\n } while (coincident);\n\n return loc;\n}\n\nexport default {\n title: 'osmose',\n\n init() {\n fileFetcher.get('qa_data')\n .then(d => {\n _osmoseData = d.osmose;\n _osmoseData.items = Object.keys(d.osmose.icons)\n .map(s => s.split('-')[0])\n .reduce((unique, item) => unique.indexOf(item) !== -1 ? unique : [...unique, item], []);\n });\n\n if (!_cache) {\n this.reset();\n }\n\n this.event = utilRebind(this, dispatch, 'on');\n },\n\n reset() {\n let _strings = {};\n let _colors = {};\n if (_cache) {\n Object.values(_cache.inflightTile).forEach(abortRequest);\n // Strings and colors are static and should not be re-populated\n _strings = _cache.strings;\n _colors = _cache.colors;\n }\n _cache = {\n data: {},\n loadedTile: {},\n inflightTile: {},\n inflightPost: {},\n closed: {},\n rtree: new RBush(),\n strings: _strings,\n colors: _colors\n };\n },\n\n loadIssues(projection) {\n let params = {\n // Tiles return a maximum # of issues\n // So we want to filter our request for only types iD supports\n item: _osmoseData.items\n };\n\n // determine the needed tiles to cover the view\n let tiles = tiler\n .zoomExtent([_tileZoom, _tileZoom])\n .getTiles(projection);\n\n // abort inflight requests that are no longer needed\n abortUnwantedRequests(_cache, tiles);\n\n // issue new requests..\n tiles.forEach(tile => {\n if (_cache.loadedTile[tile.id] || _cache.inflightTile[tile.id]) return;\n\n let [ x, y, z ] = tile.xyz;\n let url = `${_osmoseUrlRoot}/issues/${z}/${x}/${y}.json?` + utilQsString(params);\n\n let controller = new AbortController();\n _cache.inflightTile[tile.id] = controller;\n\n d3_json(url, { signal: controller.signal })\n .then(data => {\n delete _cache.inflightTile[tile.id];\n _cache.loadedTile[tile.id] = true;\n\n if (data.features) {\n data.features.forEach(issue => {\n const { item, class: cl, uuid: id } = issue.properties;\n /* Osmose issues are uniquely identified by a unique\n `item` and `class` combination (both integer values) */\n const itemType = `${item}-${cl}`;\n\n // Filter out unsupported issue types (some are too specific or advanced)\n if (itemType in _osmoseData.icons) {\n let loc = issue.geometry.coordinates; // lon, lat\n loc = preventCoincident(loc);\n\n let d = new QAItem(loc, this, itemType, id, { item });\n\n // Setting elems here prevents UI detail requests\n if (item === 8300 || item === 8360) {\n d.elems = [];\n }\n\n _cache.data[d.id] = d;\n _cache.rtree.insert(encodeIssueRtree(d));\n }\n });\n }\n\n dispatch.call('loaded');\n })\n .catch(() => {\n delete _cache.inflightTile[tile.id];\n _cache.loadedTile[tile.id] = true;\n });\n });\n },\n\n loadIssueDetail(issue) {\n // Issue details only need to be fetched once\n if (issue.elems !== undefined) {\n return Promise.resolve(issue);\n }\n\n const url = `${_osmoseUrlRoot}/issue/${issue.id}?langs=${localizer.localeCode()}`;\n const cacheDetails = data => {\n // Associated elements used for highlighting\n // Assign directly for immediate use in the callback\n issue.elems = data.elems.map(e => e.type.substring(0,1) + e.id);\n\n // Some issues have instance specific detail in a subtitle\n issue.detail = data.subtitle ? marked(data.subtitle.auto) : '';\n\n this.replaceItem(issue);\n };\n\n return d3_json(url).then(cacheDetails).then(() => issue);\n },\n\n loadStrings(locale=localizer.localeCode()) {\n const items = Object.keys(_osmoseData.icons);\n\n if (\n locale in _cache.strings\n && Object.keys(_cache.strings[locale]).length === items.length\n ) {\n return Promise.resolve(_cache.strings[locale]);\n }\n\n // May be partially populated already if some requests were successful\n if (!(locale in _cache.strings)) {\n _cache.strings[locale] = {};\n }\n\n // Only need to cache strings for supported issue types\n // Using multiple individual item + class requests to reduce fetched data size\n const allRequests = items.map(itemType => {\n // No need to request data we already have\n if (itemType in _cache.strings[locale]) return;\n\n const cacheData = data => {\n // Bunch of nested single value arrays of objects\n const [ cat = {items:[]} ] = data.categories;\n const [ item = {class:[]} ] = cat.items;\n const [ cl = null ] = item.class;\n\n // If null default value is reached, data wasn't as expected (or was empty)\n if (!cl) {\n /* eslint-disable no-console */\n console.log(`Osmose strings request (${itemType}) had unexpected data`);\n /* eslint-enable no-console */\n return;\n }\n\n // Cache served item colors to automatically style issue markers later\n const { item: itemInt, color } = item;\n if (/^#[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}/.test(color)) {\n _cache.colors[itemInt] = color;\n }\n\n // Value of root key will be null if no string exists\n // If string exists, value is an object with key 'auto' for string\n const { title, detail, fix, trap } = cl;\n\n // Osmose titles shouldn't contain markdown\n let issueStrings = {};\n if (title) issueStrings.title = title.auto;\n if (detail) issueStrings.detail = marked(detail.auto);\n if (trap) issueStrings.trap = marked(trap.auto);\n if (fix) issueStrings.fix = marked(fix.auto);\n\n _cache.strings[locale][itemType] = issueStrings;\n };\n\n const [ item, cl ] = itemType.split('-');\n\n // Osmose API falls back to English strings where untranslated or if locale doesn't exist\n const url = `${_osmoseUrlRoot}/items/${item}/class/${cl}?langs=${locale}`;\n\n return d3_json(url).then(cacheData);\n });\n\n return Promise.all(allRequests).then(() => _cache.strings[locale]);\n },\n\n getStrings(itemType, locale=localizer.localeCode()) {\n // No need to fallback to English, Osmose API handles this for us\n return (locale in _cache.strings) ? _cache.strings[locale][itemType] : {};\n },\n\n getColor(itemType) {\n return (itemType in _cache.colors) ? _cache.colors[itemType] : '#FFFFFF';\n },\n\n postUpdate(issue, callback) {\n if (_cache.inflightPost[issue.id]) {\n return callback({ message: 'Issue update already inflight', status: -2 }, issue);\n }\n\n // UI sets the status to either 'done' or 'false'\n const url = `${_osmoseUrlRoot}/issue/${issue.id}/${issue.newStatus}`;\n const controller = new AbortController();\n const after = () => {\n delete _cache.inflightPost[issue.id];\n\n this.removeItem(issue);\n if (issue.newStatus === 'done') {\n // Keep track of the number of issues closed per `item` to tag the changeset\n if (!(issue.item in _cache.closed)) {\n _cache.closed[issue.item] = 0;\n }\n _cache.closed[issue.item] += 1;\n }\n if (callback) callback(null, issue);\n };\n\n _cache.inflightPost[issue.id] = controller;\n\n fetch(url, { signal: controller.signal })\n .then(after)\n .catch(err => {\n delete _cache.inflightPost[issue.id];\n if (callback) callback(err.message);\n });\n },\n\n // Get all cached QAItems covering the viewport\n getItems(projection) {\n const viewport = projection.clipExtent();\n const min = [viewport[0][0], viewport[1][1]];\n const max = [viewport[1][0], viewport[0][1]];\n const bbox = geoExtent(projection.invert(min), projection.invert(max)).bbox();\n\n return _cache.rtree.search(bbox).map(d => d.data);\n },\n\n // Get a QAItem from cache\n // NOTE: Don't change method name until UI v3 is merged\n getError(id) {\n return _cache.data[id];\n },\n\n // get the name of the icon to display for this item\n getIcon(itemType) {\n return _osmoseData.icons[itemType];\n },\n\n // Replace a single QAItem in the cache\n replaceItem(item) {\n if (!(item instanceof QAItem) || !item.id) return;\n\n _cache.data[item.id] = item;\n updateRtree(encodeIssueRtree(item), true); // true = replace\n return item;\n },\n\n // Remove a single QAItem from the cache\n removeItem(item) {\n if (!(item instanceof QAItem) || !item.id) return;\n\n delete _cache.data[item.id];\n updateRtree(encodeIssueRtree(item), false); // false = remove\n },\n\n // Used to populate `closed:osmose:*` changeset tags\n getClosedCounts() {\n return _cache.closed;\n },\n\n itemURL(item) {\n return `https://osmose.openstreetmap.fr/en/error/${item.id}`;\n }\n};\n","/* global Mapillary:false */\nimport { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { select as d3_select } from 'd3-selection';\n\nimport RBush from 'rbush';\n\nimport { geoExtent, geoScaleToZoom } from '../geo';\nimport { svgDefs } from '../svg/defs';\nimport { utilArrayUnion, utilQsString, utilRebind, utilTiler } from '../util';\n\n\nvar apibase = 'https://a.mapillary.com/v3/';\nvar viewercss = 'mapillary-js/mapillary.min.css';\nvar viewerjs = 'mapillary-js/mapillary.min.js';\nvar clientId = 'NzNRM2otQkR2SHJzaXJmNmdQWVQ0dzo1ZWYyMmYwNjdmNDdlNmVi';\nvar mapFeatureConfig = {\n values: [\n 'construction--flat--crosswalk-plain',\n 'marking--discrete--crosswalk-zebra',\n 'object--banner',\n 'object--bench',\n 'object--bike-rack',\n 'object--billboard',\n 'object--catch-basin',\n 'object--cctv-camera',\n 'object--fire-hydrant',\n 'object--mailbox',\n 'object--manhole',\n 'object--phone-booth',\n 'object--sign--advertisement',\n 'object--sign--information',\n 'object--sign--store',\n 'object--street-light',\n 'object--support--utility-pole',\n 'object--traffic-light--*',\n 'object--traffic-light--pedestrians',\n 'object--trash-can'\n ].join(',')\n};\nvar maxResults = 1000;\nvar tileZoom = 14;\nvar tiler = utilTiler().zoomExtent([tileZoom, tileZoom]).skipNullIsland(true);\nvar dispatch = d3_dispatch('loadedImages', 'loadedSigns', 'loadedMapFeatures', 'bearingChanged');\nvar _mlyFallback = false;\nvar _mlyCache;\nvar _mlyClicks;\nvar _mlySelectedImageKey;\nvar _mlyViewer;\n\n\nfunction abortRequest(controller) {\n controller.abort();\n}\n\n\nfunction maxPageAtZoom(z) {\n if (z < 15) return 2;\n if (z === 15) return 5;\n if (z === 16) return 10;\n if (z === 17) return 20;\n if (z === 18) return 40;\n if (z > 18) return 80;\n}\n\n\nfunction loadTiles(which, url, projection) {\n var currZoom = Math.floor(geoScaleToZoom(projection.scale()));\n var tiles = tiler.getTiles(projection);\n\n // abort inflight requests that are no longer needed\n var cache = _mlyCache[which];\n Object.keys(cache.inflight).forEach(function(k) {\n var wanted = tiles.find(function(tile) { return k.indexOf(tile.id + ',') === 0; });\n if (!wanted) {\n abortRequest(cache.inflight[k]);\n delete cache.inflight[k];\n }\n });\n\n tiles.forEach(function(tile) {\n loadNextTilePage(which, currZoom, url, tile);\n });\n}\n\n\nfunction loadNextTilePage(which, currZoom, url, tile) {\n var cache = _mlyCache[which];\n var rect = tile.extent.rectangle();\n var maxPages = maxPageAtZoom(currZoom);\n var nextPage = cache.nextPage[tile.id] || 0;\n var nextURL = cache.nextURL[tile.id] || url +\n utilQsString({\n per_page: maxResults,\n page: nextPage,\n client_id: clientId,\n bbox: [rect[0], rect[1], rect[2], rect[3]].join(','),\n });\n\n if (nextPage > maxPages) return;\n\n var id = tile.id + ',' + String(nextPage);\n if (cache.loaded[id] || cache.inflight[id]) return;\n\n var controller = new AbortController();\n cache.inflight[id] = controller;\n\n var options = {\n method: 'GET',\n signal: controller.signal,\n headers: { 'Content-Type': 'application/json' }\n };\n\n fetch(nextURL, options)\n .then(function(response) {\n if (!response.ok) {\n throw new Error(response.status + ' ' + response.statusText);\n }\n var linkHeader = response.headers.get('Link');\n if (linkHeader) {\n var pagination = parsePagination(linkHeader);\n if (pagination.next) {\n cache.nextURL[tile.id] = pagination.next;\n }\n }\n return response.json();\n })\n .then(function(data) {\n cache.loaded[id] = true;\n delete cache.inflight[id];\n if (!data || !data.features || !data.features.length) {\n throw new Error('No Data');\n }\n\n var features = data.features.map(function(feature) {\n var loc = feature.geometry.coordinates;\n var d;\n\n // An image (shown as a green dot on the map) is a single street photo with extra\n // information such as location, camera angle (CA), camera model, and so on.\n // Each image feature is a GeoJSON Point\n if (which === 'images') {\n d = {\n loc: loc,\n key: feature.properties.key,\n ca: feature.properties.ca,\n captured_at: feature.properties.captured_at,\n captured_by: feature.properties.username,\n pano: feature.properties.pano\n };\n\n cache.forImageKey[d.key] = d; // cache imageKey -> image\n\n // Mapillary organizes images as sequences. A sequence of images are continuously captured\n // by a user at a give time. Sequences are shown on the map as green lines.\n // Each sequence feature is a GeoJSON LineString\n } else if (which === 'sequences') {\n var sequenceKey = feature.properties.key;\n cache.lineString[sequenceKey] = feature; // cache sequenceKey -> lineString\n feature.properties.coordinateProperties.image_keys.forEach(function(imageKey) {\n cache.forImageKey[imageKey] = sequenceKey; // cache imageKey -> sequenceKey\n });\n return false; // because no `d` data worth loading into an rbush\n\n // An image detection is a semantic pixel area on an image. The area could indicate\n // sky, trees, sidewalk in the image. A detection can be a polygon, a bounding box, or a point.\n // Each image_detection feature is a GeoJSON Point (located where the image was taken)\n } else if (which === 'image_detections') {\n d = {\n key: feature.properties.key,\n image_key: feature.properties.image_key,\n value: feature.properties.value,\n package: feature.properties.package,\n shape: feature.properties.shape\n };\n\n // cache imageKey -> image_detections\n if (!cache.forImageKey[d.image_key]) {\n cache.forImageKey[d.image_key] = [];\n }\n cache.forImageKey[d.image_key].push(d);\n return false; // because no `d` data worth loading into an rbush\n\n\n // A map feature is a real world object that can be shown on a map. It could be any object\n // recognized from images, manually added in images, or added on the map.\n // Each map feature is a GeoJSON Point (located where the feature is)\n } else if (which === 'map_features' || which === 'points') {\n d = {\n loc: loc,\n key: feature.properties.key,\n value: feature.properties.value,\n package: feature.properties.package,\n detections: feature.properties.detections\n };\n }\n\n return {\n minX: loc[0], minY: loc[1], maxX: loc[0], maxY: loc[1], data: d\n };\n\n }).filter(Boolean);\n\n if (cache.rtree && features) {\n cache.rtree.load(features);\n }\n\n if (data.features.length === maxResults) { // more pages to load\n cache.nextPage[tile.id] = nextPage + 1;\n loadNextTilePage(which, currZoom, url, tile);\n } else {\n cache.nextPage[tile.id] = Infinity; // no more pages to load\n }\n\n if (which === 'images' || which === 'sequences') {\n dispatch.call('loadedImages');\n } else if (which === 'map_features') {\n dispatch.call('loadedSigns');\n } else if (which === 'points') {\n dispatch.call('loadedMapFeatures');\n }\n })\n .catch(function() {\n cache.loaded[id] = true;\n delete cache.inflight[id];\n });\n}\n\n// extract links to pages of API results\nfunction parsePagination(links) {\n return links.split(',').map(function(rel) {\n var elements = rel.split(';');\n if (elements.length === 2) {\n return [\n /<(.+)>/.exec(elements[0])[1],\n /rel=\"(.+)\"/.exec(elements[1])[1]\n ];\n } else {\n return ['',''];\n }\n }).reduce(function(pagination, val) {\n pagination[val[1]] = val[0];\n return pagination;\n }, {});\n}\n\n\n// partition viewport into higher zoom tiles\nfunction partitionViewport(projection) {\n var z = geoScaleToZoom(projection.scale());\n var z2 = (Math.ceil(z * 2) / 2) + 2.5; // round to next 0.5 and add 2.5\n var tiler = utilTiler().zoomExtent([z2, z2]);\n\n return tiler.getTiles(projection)\n .map(function(tile) { return tile.extent; });\n}\n\n\n// no more than `limit` results per partition.\nfunction searchLimited(limit, projection, rtree) {\n limit = limit || 5;\n\n return partitionViewport(projection)\n .reduce(function(result, extent) {\n var found = rtree.search(extent.bbox())\n .slice(0, limit)\n .map(function(d) { return d.data; });\n\n return (found.length ? result.concat(found) : result);\n }, []);\n}\n\n\n\nexport default {\n\n init: function() {\n if (!_mlyCache) {\n this.reset();\n }\n\n this.event = utilRebind(this, dispatch, 'on');\n },\n\n reset: function() {\n if (_mlyCache) {\n Object.values(_mlyCache.images.inflight).forEach(abortRequest);\n Object.values(_mlyCache.image_detections.inflight).forEach(abortRequest);\n Object.values(_mlyCache.map_features.inflight).forEach(abortRequest);\n Object.values(_mlyCache.points.inflight).forEach(abortRequest);\n Object.values(_mlyCache.sequences.inflight).forEach(abortRequest);\n }\n\n _mlyCache = {\n images: { inflight: {}, loaded: {}, nextPage: {}, nextURL: {}, rtree: new RBush(), forImageKey: {} },\n image_detections: { inflight: {}, loaded: {}, nextPage: {}, nextURL: {}, forImageKey: {} },\n map_features: { inflight: {}, loaded: {}, nextPage: {}, nextURL: {}, rtree: new RBush() },\n points: { inflight: {}, loaded: {}, nextPage: {}, nextURL: {}, rtree: new RBush() },\n sequences: { inflight: {}, loaded: {}, nextPage: {}, nextURL: {}, rtree: new RBush(), forImageKey: {}, lineString: {} }\n };\n\n _mlySelectedImageKey = null;\n _mlyClicks = [];\n },\n\n\n images: function(projection) {\n var limit = 5;\n return searchLimited(limit, projection, _mlyCache.images.rtree);\n },\n\n\n signs: function(projection) {\n var limit = 5;\n return searchLimited(limit, projection, _mlyCache.map_features.rtree);\n },\n\n\n mapFeatures: function(projection) {\n var limit = 5;\n return searchLimited(limit, projection, _mlyCache.points.rtree);\n },\n\n\n cachedImage: function(imageKey) {\n return _mlyCache.images.forImageKey[imageKey];\n },\n\n\n sequences: function(projection) {\n var viewport = projection.clipExtent();\n var min = [viewport[0][0], viewport[1][1]];\n var max = [viewport[1][0], viewport[0][1]];\n var bbox = geoExtent(projection.invert(min), projection.invert(max)).bbox();\n var sequenceKeys = {};\n\n // all sequences for images in viewport\n _mlyCache.images.rtree.search(bbox)\n .forEach(function(d) {\n var sequenceKey = _mlyCache.sequences.forImageKey[d.data.key];\n if (sequenceKey) {\n sequenceKeys[sequenceKey] = true;\n }\n });\n\n // Return lineStrings for the sequences\n return Object.keys(sequenceKeys).map(function(sequenceKey) {\n return _mlyCache.sequences.lineString[sequenceKey];\n });\n },\n\n\n signsSupported: function() {\n return true;\n },\n\n\n loadImages: function(projection) {\n loadTiles('images', apibase + 'images?sort_by=key&', projection);\n loadTiles('sequences', apibase + 'sequences?sort_by=key&', projection);\n },\n\n\n loadSigns: function(projection) {\n // if we are looking at signs, we'll actually need to fetch images too\n loadTiles('images', apibase + 'images?sort_by=key&', projection);\n loadTiles('map_features', apibase + 'map_features?layers=trafficsigns&min_nbr_image_detections=2&sort_by=key&', projection);\n loadTiles('image_detections', apibase + 'image_detections?layers=trafficsigns&sort_by=key&', projection);\n },\n\n\n loadMapFeatures: function(projection) {\n // if we are looking at signs, we'll actually need to fetch images too\n loadTiles('images', apibase + 'images?sort_by=key', projection);\n loadTiles('points', apibase + 'map_features?layers=points&min_nbr_image_detections=2&sort_by=key&values=' + mapFeatureConfig.values + '&', projection);\n loadTiles('image_detections', apibase + 'image_detections?layers=points&sort_by=key&values=' + mapFeatureConfig.values + '&', projection);\n },\n\n\n loadViewer: function(context) {\n // add mly-wrapper\n var wrap = context.container().select('.photoviewer')\n .selectAll('.mly-wrapper')\n .data([0]);\n\n wrap.enter()\n .append('div')\n .attr('id', 'ideditor-mly')\n .attr('class', 'photo-wrapper mly-wrapper')\n .classed('hide', true);\n\n // load mapillary-viewercss\n d3_select('head').selectAll('#ideditor-mapillary-viewercss')\n .data([0])\n .enter()\n .append('link')\n .attr('id', 'ideditor-mapillary-viewercss')\n .attr('rel', 'stylesheet')\n .attr('href', context.asset(viewercss));\n\n // load mapillary-viewerjs\n d3_select('head').selectAll('#ideditor-mapillary-viewerjs')\n .data([0])\n .enter()\n .append('script')\n .attr('id', 'ideditor-mapillary-viewerjs')\n .attr('src', context.asset(viewerjs));\n\n // load mapillary signs sprite\n var defs = context.container().select('defs');\n defs.call(svgDefs(context).addSprites, ['mapillary-sprite', 'mapillary-object-sprite'], false /* don't override colors */ );\n\n // Register viewer resize handler\n context.ui().photoviewer.on('resize.mapillary', function() {\n if (_mlyViewer) {\n _mlyViewer.resize();\n }\n });\n },\n\n\n showViewer: function(context) {\n var wrap = context.container().select('.photoviewer')\n .classed('hide', false);\n\n var isHidden = wrap.selectAll('.photo-wrapper.mly-wrapper.hide').size();\n\n if (isHidden && _mlyViewer) {\n wrap\n .selectAll('.photo-wrapper:not(.mly-wrapper)')\n .classed('hide', true);\n\n wrap\n .selectAll('.photo-wrapper.mly-wrapper')\n .classed('hide', false);\n\n _mlyViewer.resize();\n }\n\n return this;\n },\n\n\n hideViewer: function(context) {\n _mlySelectedImageKey = null;\n\n if (!_mlyFallback && _mlyViewer) {\n _mlyViewer.getComponent('sequence').stop();\n }\n\n var viewer = context.container().select('.photoviewer');\n if (!viewer.empty()) viewer.datum(null);\n\n viewer\n .classed('hide', true)\n .selectAll('.photo-wrapper')\n .classed('hide', true);\n\n context.container().selectAll('.viewfield-group, .sequence, .icon-detected')\n .classed('currentView', false);\n\n return this.setStyles(context, null, true);\n },\n\n\n parsePagination: parsePagination,\n\n\n updateViewer: function(context, imageKey) {\n if (!imageKey) return this;\n\n if (!_mlyViewer) {\n this.initViewer(context, imageKey);\n } else {\n _mlyViewer.moveToKey(imageKey)\n .catch(function(e) { console.error('mly3', e); }); // eslint-disable-line no-console\n }\n\n return this;\n },\n\n\n initViewer: function(context, imageKey) {\n var that = this;\n if (window.Mapillary && imageKey) {\n var opts = {\n baseImageSize: 320,\n component: {\n cover: false,\n keyboard: false,\n tag: true\n }\n };\n\n // Disable components requiring WebGL support\n if (!Mapillary.isSupported() && Mapillary.isFallbackSupported()) {\n _mlyFallback = true;\n opts.component = {\n cover: false,\n direction: false,\n imagePlane: false,\n keyboard: false,\n mouse: false,\n sequence: false,\n tag: false,\n image: true, // fallback\n navigation: true // fallback\n };\n }\n\n _mlyViewer = new Mapillary.Viewer('ideditor-mly', clientId, null, opts);\n _mlyViewer.on('nodechanged', nodeChanged);\n _mlyViewer.on('bearingchanged', bearingChanged);\n _mlyViewer.moveToKey(imageKey)\n .catch(function(e) { console.error('mly3', e); }); // eslint-disable-line no-console\n }\n\n // nodeChanged: called after the viewer has changed images and is ready.\n //\n // There is some logic here to batch up clicks into a _mlyClicks array\n // because the user might click on a lot of markers quickly and nodechanged\n // may be called out of order asychronously.\n //\n // Clicks are added to the array in `selectedImage` and removed here.\n //\n function nodeChanged(node) {\n if (!_mlyFallback) {\n _mlyViewer.getComponent('tag').removeAll(); // remove previous detections\n }\n\n var clicks = _mlyClicks;\n var index = clicks.indexOf(node.key);\n var selectedKey = _mlySelectedImageKey;\n\n if (index > -1) { // `nodechanged` initiated from clicking on a marker..\n clicks.splice(index, 1); // remove the click\n // If `node.key` matches the current _mlySelectedImageKey, call `selectImage()`\n // one more time to update the detections and attribution..\n if (node.key === selectedKey) {\n that.selectImage(context, _mlySelectedImageKey, true);\n }\n } else { // `nodechanged` initiated from the Mapillary viewer controls..\n var loc = node.computedLatLon ? [node.computedLatLon.lon, node.computedLatLon.lat] : [node.latLon.lon, node.latLon.lat];\n context.map().centerEase(loc);\n that.selectImage(context, node.key, true);\n }\n }\n\n function bearingChanged(e) {\n dispatch.call('bearingChanged', undefined, e);\n }\n },\n\n\n // Pass in the image key string as `imageKey`.\n // This allows images to be selected from places that dont have access\n // to the full image datum (like the street signs layer or the js viewer)\n selectImage: function(context, imageKey, fromViewer) {\n\n _mlySelectedImageKey = imageKey;\n\n // Note the datum could be missing, but we'll try to carry on anyway.\n // There just might be a delay before user sees detections, captured_at, etc.\n var d = _mlyCache.images.forImageKey[imageKey];\n\n var viewer = context.container().select('.photoviewer');\n if (!viewer.empty()) viewer.datum(d);\n\n imageKey = (d && d.key) || imageKey;\n if (!fromViewer && imageKey) {\n _mlyClicks.push(imageKey);\n }\n\n this.setStyles(context, null, true);\n\n // if signs signs are shown, highlight the ones that appear in this image\n context.container().selectAll('.layer-mapillary-signs .icon-detected')\n .classed('currentView', function(d) {\n return d.detections.some(function(detection) {\n return detection.image_key === imageKey;\n });\n });\n\n if (d) {\n this.updateDetections(d);\n }\n\n return this;\n },\n\n\n getSelectedImageKey: function() {\n return _mlySelectedImageKey;\n },\n\n\n getSequenceKeyForImageKey: function(imageKey) {\n return _mlyCache.sequences.forImageKey[imageKey];\n },\n\n\n // Updates the currently highlighted sequence and selected bubble.\n // Reset is only necessary when interacting with the viewport because\n // this implicitly changes the currently selected bubble/sequence\n setStyles: function(context, hovered, reset) {\n if (reset) { // reset all layers\n context.container().selectAll('.viewfield-group')\n .classed('highlighted', false)\n .classed('hovered', false)\n .classed('currentView', false);\n\n context.container().selectAll('.sequence')\n .classed('highlighted', false)\n .classed('currentView', false);\n }\n\n var hoveredImageKey = hovered && hovered.key;\n var hoveredSequenceKey = hoveredImageKey && this.getSequenceKeyForImageKey(hoveredImageKey);\n var hoveredLineString = hoveredSequenceKey && _mlyCache.sequences.lineString[hoveredSequenceKey];\n var hoveredImageKeys = (hoveredLineString && hoveredLineString.properties.coordinateProperties.image_keys) || [];\n\n var selectedImageKey = _mlySelectedImageKey;\n var selectedSequenceKey = selectedImageKey && this.getSequenceKeyForImageKey(selectedImageKey);\n var selectedLineString = selectedSequenceKey && _mlyCache.sequences.lineString[selectedSequenceKey];\n var selectedImageKeys = (selectedLineString && selectedLineString.properties.coordinateProperties.image_keys) || [];\n\n // highlight sibling viewfields on either the selected or the hovered sequences\n var highlightedImageKeys = utilArrayUnion(hoveredImageKeys, selectedImageKeys);\n\n context.container().selectAll('.layer-mapillary .viewfield-group')\n .classed('highlighted', function(d) { return highlightedImageKeys.indexOf(d.key) !== -1; })\n .classed('hovered', function(d) { return d.key === hoveredImageKey; })\n .classed('currentView', function(d) { return d.key === selectedImageKey; });\n\n context.container().selectAll('.layer-mapillary .sequence')\n .classed('highlighted', function(d) { return d.properties.key === hoveredSequenceKey; })\n .classed('currentView', function(d) { return d.properties.key === selectedSequenceKey; });\n\n // update viewfields if needed\n context.container().selectAll('.viewfield-group .viewfield')\n .attr('d', viewfieldPath);\n\n function viewfieldPath() {\n var d = this.parentNode.__data__;\n if (d.pano && d.key !== selectedImageKey) {\n return 'M 8,13 m -10,0 a 10,10 0 1,0 20,0 a 10,10 0 1,0 -20,0';\n } else {\n return 'M 6,9 C 8,8.4 8,8.4 10,9 L 16,-2 C 12,-5 4,-5 0,-2 z';\n }\n }\n\n return this;\n },\n\n\n updateDetections: function(d) {\n if (!_mlyViewer || _mlyFallback) return;\n\n var imageKey = d && d.key;\n if (!imageKey) return;\n\n var detections = _mlyCache.image_detections.forImageKey[imageKey] || [];\n detections.forEach(function(data) {\n var tag = makeTag(data);\n if (tag) {\n var tagComponent = _mlyViewer.getComponent('tag');\n tagComponent.add([tag]);\n }\n });\n\n function makeTag(data) {\n var valueParts = data.value.split('--');\n if (valueParts.length !== 3) return;\n\n var text = valueParts[1].replace(/-/g, ' ');\n var tag;\n\n // Currently only two shapes \n if (data.shape.type === 'Polygon') {\n var polygonGeometry = new Mapillary\n .TagComponent\n .PolygonGeometry(data.shape.coordinates[0]);\n\n tag = new Mapillary.TagComponent.OutlineTag(\n data.key,\n polygonGeometry,\n {\n text: text,\n textColor: 0xffff00,\n lineColor: 0xffff00,\n lineWidth: 2,\n fillColor: 0xffff00,\n fillOpacity: 0.3,\n }\n );\n\n } else if (data.shape.type === 'Point') {\n var pointGeometry = new Mapillary\n .TagComponent\n .PointGeometry(data.shape.coordinates[0]);\n\n tag = new Mapillary.TagComponent.SpotTag(\n data.key,\n pointGeometry,\n {\n text: text,\n color: 0xffff00,\n textColor: 0xffff00\n }\n );\n }\n\n return tag;\n }\n },\n\n\n cache: function() {\n return _mlyCache;\n }\n\n};\n","import { osmAreaKeys as areaKeys } from '../osm/tags';\nimport { utilArrayIntersection } from '../util';\nimport { validationIssue } from '../core/validation';\n\n\nvar buildRuleChecks = function() {\n return {\n equals: function (equals) {\n return function(tags) {\n return Object.keys(equals).every(function(k) {\n return equals[k] === tags[k];\n });\n };\n },\n notEquals: function (notEquals) {\n return function(tags) {\n return Object.keys(notEquals).some(function(k) {\n return notEquals[k] !== tags[k];\n });\n };\n },\n absence: function(absence) {\n return function(tags) {\n return Object.keys(tags).indexOf(absence) === -1;\n };\n },\n presence: function(presence) {\n return function(tags) {\n return Object.keys(tags).indexOf(presence) > -1;\n };\n },\n greaterThan: function(greaterThan) {\n var key = Object.keys(greaterThan)[0];\n var value = greaterThan[key];\n\n return function(tags) {\n return tags[key] > value;\n };\n },\n greaterThanEqual: function(greaterThanEqual) {\n var key = Object.keys(greaterThanEqual)[0];\n var value = greaterThanEqual[key];\n\n return function(tags) {\n return tags[key] >= value;\n };\n },\n lessThan: function(lessThan) {\n var key = Object.keys(lessThan)[0];\n var value = lessThan[key];\n\n return function(tags) {\n return tags[key] < value;\n };\n },\n lessThanEqual: function(lessThanEqual) {\n var key = Object.keys(lessThanEqual)[0];\n var value = lessThanEqual[key];\n\n return function(tags) {\n return tags[key] <= value;\n };\n },\n positiveRegex: function(positiveRegex) {\n var tagKey = Object.keys(positiveRegex)[0];\n var expression = positiveRegex[tagKey].join('|');\n var regex = new RegExp(expression);\n\n return function(tags) {\n return regex.test(tags[tagKey]);\n };\n },\n negativeRegex: function(negativeRegex) {\n var tagKey = Object.keys(negativeRegex)[0];\n var expression = negativeRegex[tagKey].join('|');\n var regex = new RegExp(expression);\n\n return function(tags) {\n return !regex.test(tags[tagKey]);\n };\n }\n };\n};\n\nvar buildLineKeys = function() {\n return {\n highway: {\n rest_area: true,\n services: true\n },\n railway: {\n roundhouse: true,\n station: true,\n traverser: true,\n turntable: true,\n wash: true\n }\n };\n};\n\nexport default {\n init: function() {\n this._ruleChecks = buildRuleChecks();\n this._validationRules = [];\n this._areaKeys = areaKeys;\n this._lineKeys = buildLineKeys();\n },\n\n // list of rules only relevant to tag checks...\n filterRuleChecks: function(selector) {\n var _ruleChecks = this._ruleChecks;\n return Object.keys(selector).reduce(function(rules, key) {\n if (['geometry', 'error', 'warning'].indexOf(key) === -1) {\n rules.push(_ruleChecks[key](selector[key]));\n }\n return rules;\n }, []);\n },\n\n // builds tagMap from mapcss-parse selector object...\n buildTagMap: function(selector) {\n var getRegexValues = function(regexes) {\n return regexes.map(function(regex) {\n return regex.replace(/\\$|\\^/g, '');\n });\n };\n\n var tagMap = Object.keys(selector).reduce(function (expectedTags, key) {\n var values;\n var isRegex = /regex/gi.test(key);\n var isEqual = /equals/gi.test(key);\n\n if (isRegex || isEqual) {\n Object.keys(selector[key]).forEach(function(selectorKey) {\n values = isEqual ? [selector[key][selectorKey]] : getRegexValues(selector[key][selectorKey]);\n\n if (expectedTags.hasOwnProperty(selectorKey)) {\n values = values.concat(expectedTags[selectorKey]);\n }\n\n expectedTags[selectorKey] = values;\n });\n\n } else if (/(greater|less)Than(Equal)?|presence/g.test(key)) {\n var tagKey = /presence/.test(key) ? selector[key] : Object.keys(selector[key])[0];\n\n values = [selector[key][tagKey]];\n\n if (expectedTags.hasOwnProperty(tagKey)) {\n values = values.concat(expectedTags[tagKey]);\n }\n\n expectedTags[tagKey] = values;\n }\n\n return expectedTags;\n }, {});\n\n return tagMap;\n },\n\n // inspired by osmWay#isArea()\n inferGeometry: function(tagMap) {\n var _lineKeys = this._lineKeys;\n var _areaKeys = this._areaKeys;\n\n var keyValueDoesNotImplyArea = function(key) {\n return utilArrayIntersection(tagMap[key], Object.keys(_areaKeys[key])).length > 0;\n };\n var keyValueImpliesLine = function(key) {\n return utilArrayIntersection(tagMap[key], Object.keys(_lineKeys[key])).length > 0;\n };\n\n if (tagMap.hasOwnProperty('area')) {\n if (tagMap.area.indexOf('yes') > -1) {\n return 'area';\n }\n if (tagMap.area.indexOf('no') > -1) {\n return 'line';\n }\n }\n\n for (var key in tagMap) {\n if (key in _areaKeys && !keyValueDoesNotImplyArea(key)) {\n return 'area';\n }\n if (key in _lineKeys && keyValueImpliesLine(key)) {\n return 'area';\n }\n }\n\n return 'line';\n },\n\n // adds from mapcss-parse selector check...\n addRule: function(selector) {\n var rule = {\n // checks relevant to mapcss-selector\n checks: this.filterRuleChecks(selector),\n // true if all conditions for a tag error are true..\n matches: function(entity) {\n return this.checks.every(function(check) {\n return check(entity.tags);\n });\n },\n // borrowed from Way#isArea()\n inferredGeometry: this.inferGeometry(this.buildTagMap(selector), this._areaKeys),\n geometryMatches: function(entity, graph) {\n if (entity.type === 'node' || entity.type === 'relation') {\n return selector.geometry === entity.type;\n } else if (entity.type === 'way') {\n return this.inferredGeometry === entity.geometry(graph);\n }\n },\n // when geometries match and tag matches are present, return a warning...\n findIssues: function (entity, graph, issues) {\n if (this.geometryMatches(entity, graph) && this.matches(entity)) {\n var severity = Object.keys(selector).indexOf('error') > -1\n ? 'error'\n : 'warning';\n var message = selector[severity];\n issues.push(new validationIssue({\n type: 'maprules',\n severity: severity,\n message: function() {\n return message;\n },\n entityIds: [entity.id]\n }));\n }\n }\n };\n this._validationRules.push(rule);\n },\n\n clearRules: function() { this._validationRules = []; },\n\n // returns validationRules...\n validationRules: function() { return this._validationRules; },\n\n // returns ruleChecks\n ruleChecks: function() { return this._ruleChecks; }\n};\n","import { json as d3_json } from 'd3-fetch';\n\nimport RBush from 'rbush';\nimport { geoExtent } from '../geo';\nimport { utilQsString } from '../util';\n\n\nvar apibase = 'https://nominatim.openstreetmap.org/';\nvar _inflight = {};\nvar _nominatimCache;\n\n\nexport default {\n\n init: function() {\n _inflight = {};\n _nominatimCache = new RBush();\n },\n\n reset: function() {\n Object.values(_inflight).forEach(function(controller) { controller.abort(); });\n _inflight = {};\n _nominatimCache = new RBush();\n },\n\n\n countryCode: function (location, callback) {\n this.reverse(location, function(err, result) {\n if (err) {\n return callback(err);\n } else if (result.address) {\n return callback(null, result.address.country_code);\n } else {\n return callback('Unable to geocode', null);\n }\n });\n },\n\n\n reverse: function (loc, callback) {\n var cached = _nominatimCache.search(\n { minX: loc[0], minY: loc[1], maxX: loc[0], maxY: loc[1] }\n );\n\n if (cached.length > 0) {\n if (callback) callback(null, cached[0].data);\n return;\n }\n\n var params = { zoom: 13, format: 'json', addressdetails: 1, lat: loc[1], lon: loc[0] };\n var url = apibase + 'reverse?' + utilQsString(params);\n\n if (_inflight[url]) return;\n var controller = new AbortController();\n _inflight[url] = controller;\n\n d3_json(url, { signal: controller.signal })\n .then(function(result) {\n delete _inflight[url];\n if (result && result.error) {\n throw new Error(result.error);\n }\n var extent = geoExtent(loc).padByMeters(200);\n _nominatimCache.insert(Object.assign(extent.bbox(), {data: result}));\n if (callback) callback(null, result);\n })\n .catch(function(err) {\n delete _inflight[url];\n if (err.name === 'AbortError') return;\n if (callback) callback(err.message);\n });\n },\n\n\n search: function (val, callback) {\n var searchVal = encodeURIComponent(val);\n var url = apibase + 'search/' + searchVal + '?limit=10&format=json';\n\n if (_inflight[url]) return;\n var controller = new AbortController();\n _inflight[url] = controller;\n\n d3_json(url, { signal: controller.signal })\n .then(function(result) {\n delete _inflight[url];\n if (result && result.error) {\n throw new Error(result.error);\n }\n if (callback) callback(null, result);\n })\n .catch(function(err) {\n delete _inflight[url];\n if (err.name === 'AbortError') return;\n if (callback) callback(err.message);\n });\n }\n\n};\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { json as d3_json } from 'd3-fetch';\nimport { event as d3_event } from 'd3-selection';\nimport { zoom as d3_zoom, zoomIdentity as d3_zoomIdentity } from 'd3-zoom';\n\nimport RBush from 'rbush';\n\nimport { localizer } from '../core/localizer';\nimport { geoExtent, geoScaleToZoom } from '../geo';\nimport { utilArrayUnion, utilQsString, utilRebind, utilSetTransform, utilTiler } from '../util';\n\n\nvar apibase = 'https://openstreetcam.org';\nvar maxResults = 1000;\nvar tileZoom = 14;\nvar tiler = utilTiler().zoomExtent([tileZoom, tileZoom]).skipNullIsland(true);\nvar dispatch = d3_dispatch('loadedImages');\nvar imgZoom = d3_zoom()\n .extent([[0, 0], [320, 240]])\n .translateExtent([[0, 0], [320, 240]])\n .scaleExtent([1, 15]);\nvar _oscCache;\nvar _oscSelectedImage;\n\n\nfunction abortRequest(controller) {\n controller.abort();\n}\n\n\nfunction maxPageAtZoom(z) {\n if (z < 15) return 2;\n if (z === 15) return 5;\n if (z === 16) return 10;\n if (z === 17) return 20;\n if (z === 18) return 40;\n if (z > 18) return 80;\n}\n\n\nfunction loadTiles(which, url, projection) {\n var currZoom = Math.floor(geoScaleToZoom(projection.scale()));\n var tiles = tiler.getTiles(projection);\n\n // abort inflight requests that are no longer needed\n var cache = _oscCache[which];\n Object.keys(cache.inflight).forEach(function(k) {\n var wanted = tiles.find(function(tile) { return k.indexOf(tile.id + ',') === 0; });\n if (!wanted) {\n abortRequest(cache.inflight[k]);\n delete cache.inflight[k];\n }\n });\n\n tiles.forEach(function(tile) {\n loadNextTilePage(which, currZoom, url, tile);\n });\n}\n\n\nfunction loadNextTilePage(which, currZoom, url, tile) {\n var cache = _oscCache[which];\n var bbox = tile.extent.bbox();\n var maxPages = maxPageAtZoom(currZoom);\n var nextPage = cache.nextPage[tile.id] || 1;\n var params = utilQsString({\n ipp: maxResults,\n page: nextPage,\n // client_id: clientId,\n bbTopLeft: [bbox.maxY, bbox.minX].join(','),\n bbBottomRight: [bbox.minY, bbox.maxX].join(',')\n }, true);\n\n if (nextPage > maxPages) return;\n\n var id = tile.id + ',' + String(nextPage);\n if (cache.loaded[id] || cache.inflight[id]) return;\n\n var controller = new AbortController();\n cache.inflight[id] = controller;\n\n var options = {\n method: 'POST',\n signal: controller.signal,\n body: params,\n headers: { 'Content-Type': 'application/x-www-form-urlencoded' }\n };\n\n d3_json(url, options)\n .then(function(data) {\n cache.loaded[id] = true;\n delete cache.inflight[id];\n if (!data || !data.currentPageItems || !data.currentPageItems.length) {\n throw new Error('No Data');\n }\n\n var features = data.currentPageItems.map(function(item) {\n var loc = [+item.lng, +item.lat];\n var d;\n\n if (which === 'images') {\n d = {\n loc: loc,\n key: item.id,\n ca: +item.heading,\n captured_at: (item.shot_date || item.date_added),\n captured_by: item.username,\n imagePath: item.lth_name,\n sequence_id: item.sequence_id,\n sequence_index: +item.sequence_index\n };\n\n // cache sequence info\n var seq = _oscCache.sequences[d.sequence_id];\n if (!seq) {\n seq = { rotation: 0, images: [] };\n _oscCache.sequences[d.sequence_id] = seq;\n }\n seq.images[d.sequence_index] = d;\n }\n\n return {\n minX: loc[0], minY: loc[1], maxX: loc[0], maxY: loc[1], data: d\n };\n });\n\n cache.rtree.load(features);\n\n if (data.currentPageItems.length === maxResults) { // more pages to load\n cache.nextPage[tile.id] = nextPage + 1;\n loadNextTilePage(which, currZoom, url, tile);\n } else {\n cache.nextPage[tile.id] = Infinity; // no more pages to load\n }\n\n if (which === 'images') {\n dispatch.call('loadedImages');\n }\n })\n .catch(function() {\n cache.loaded[id] = true;\n delete cache.inflight[id];\n });\n}\n\n\n// partition viewport into higher zoom tiles\nfunction partitionViewport(projection) {\n var z = geoScaleToZoom(projection.scale());\n var z2 = (Math.ceil(z * 2) / 2) + 2.5; // round to next 0.5 and add 2.5\n var tiler = utilTiler().zoomExtent([z2, z2]);\n\n return tiler.getTiles(projection)\n .map(function(tile) { return tile.extent; });\n}\n\n\n// no more than `limit` results per partition.\nfunction searchLimited(limit, projection, rtree) {\n limit = limit || 5;\n\n return partitionViewport(projection)\n .reduce(function(result, extent) {\n var found = rtree.search(extent.bbox())\n .slice(0, limit)\n .map(function(d) { return d.data; });\n\n return (found.length ? result.concat(found) : result);\n }, []);\n}\n\n\nexport default {\n\n init: function() {\n if (!_oscCache) {\n this.reset();\n }\n\n this.event = utilRebind(this, dispatch, 'on');\n },\n\n reset: function() {\n if (_oscCache) {\n Object.values(_oscCache.images.inflight).forEach(abortRequest);\n }\n\n _oscCache = {\n images: { inflight: {}, loaded: {}, nextPage: {}, rtree: new RBush() },\n sequences: {}\n };\n\n _oscSelectedImage = null;\n },\n\n\n images: function(projection) {\n var limit = 5;\n return searchLimited(limit, projection, _oscCache.images.rtree);\n },\n\n\n sequences: function(projection) {\n var viewport = projection.clipExtent();\n var min = [viewport[0][0], viewport[1][1]];\n var max = [viewport[1][0], viewport[0][1]];\n var bbox = geoExtent(projection.invert(min), projection.invert(max)).bbox();\n var sequenceKeys = {};\n\n // all sequences for images in viewport\n _oscCache.images.rtree.search(bbox)\n .forEach(function(d) { sequenceKeys[d.data.sequence_id] = true; });\n\n // make linestrings from those sequences\n var lineStrings = [];\n Object.keys(sequenceKeys)\n .forEach(function(sequenceKey) {\n var seq = _oscCache.sequences[sequenceKey];\n var images = seq && seq.images;\n if (images) {\n lineStrings.push({\n type: 'LineString',\n coordinates: images.map(function (d) { return d.loc; }).filter(Boolean),\n properties: { key: sequenceKey }\n });\n }\n });\n return lineStrings;\n },\n\n\n loadImages: function(projection) {\n var url = apibase + '/1.0/list/nearby-photos/';\n loadTiles('images', url, projection);\n },\n\n\n loadViewer: function(context) {\n var that = this;\n\n // add osc-wrapper\n var wrap = context.container().select('.photoviewer').selectAll('.osc-wrapper')\n .data([0]);\n\n var wrapEnter = wrap.enter()\n .append('div')\n .attr('class', 'photo-wrapper osc-wrapper')\n .classed('hide', true)\n .call(imgZoom.on('zoom', zoomPan))\n .on('dblclick.zoom', null);\n\n wrapEnter\n .append('div')\n .attr('class', 'photo-attribution fillD');\n\n var controlsEnter = wrapEnter\n .append('div')\n .attr('class', 'photo-controls-wrap')\n .append('div')\n .attr('class', 'photo-controls');\n\n controlsEnter\n .append('button')\n .on('click.back', step(-1))\n .text('◄');\n\n controlsEnter\n .append('button')\n .on('click.rotate-ccw', rotate(-90))\n .text('⤿');\n\n controlsEnter\n .append('button')\n .on('click.rotate-cw', rotate(90))\n .text('⤾');\n\n controlsEnter\n .append('button')\n .on('click.forward', step(1))\n .text('►');\n\n wrapEnter\n .append('div')\n .attr('class', 'osc-image-wrap');\n\n\n // Register viewer resize handler\n context.ui().photoviewer.on('resize.openstreetcam', function(dimensions) {\n imgZoom = d3_zoom()\n .extent([[0, 0], dimensions])\n .translateExtent([[0, 0], dimensions])\n .scaleExtent([1, 15])\n .on('zoom', zoomPan);\n });\n\n\n function zoomPan() {\n var t = d3_event.transform;\n context.container().select('.photoviewer .osc-image-wrap')\n .call(utilSetTransform, t.x, t.y, t.k);\n }\n\n\n function rotate(deg) {\n return function() {\n if (!_oscSelectedImage) return;\n var sequenceKey = _oscSelectedImage.sequence_id;\n var sequence = _oscCache.sequences[sequenceKey];\n if (!sequence) return;\n\n var r = sequence.rotation || 0;\n r += deg;\n\n if (r > 180) r -= 360;\n if (r < -180) r += 360;\n sequence.rotation = r;\n\n var wrap = context.container().select('.photoviewer .osc-wrapper');\n\n wrap\n .transition()\n .duration(100)\n .call(imgZoom.transform, d3_zoomIdentity);\n\n wrap.selectAll('.osc-image')\n .transition()\n .duration(100)\n .style('transform', 'rotate(' + r + 'deg)');\n };\n }\n\n function step(stepBy) {\n return function() {\n if (!_oscSelectedImage) return;\n var sequenceKey = _oscSelectedImage.sequence_id;\n var sequence = _oscCache.sequences[sequenceKey];\n if (!sequence) return;\n\n var nextIndex = _oscSelectedImage.sequence_index + stepBy;\n var nextImage = sequence.images[nextIndex];\n if (!nextImage) return;\n\n context.map().centerEase(nextImage.loc);\n\n that\n .selectImage(context, nextImage)\n .updateViewer(context, nextImage);\n };\n }\n },\n\n\n showViewer: function(context) {\n var viewer = context.container().select('.photoviewer')\n .classed('hide', false);\n\n var isHidden = viewer.selectAll('.photo-wrapper.osc-wrapper.hide').size();\n\n if (isHidden) {\n viewer\n .selectAll('.photo-wrapper:not(.osc-wrapper)')\n .classed('hide', true);\n\n viewer\n .selectAll('.photo-wrapper.osc-wrapper')\n .classed('hide', false);\n }\n\n return this;\n },\n\n\n hideViewer: function(context) {\n _oscSelectedImage = null;\n\n var viewer = context.container().select('.photoviewer');\n if (!viewer.empty()) viewer.datum(null);\n\n viewer\n .classed('hide', true)\n .selectAll('.photo-wrapper')\n .classed('hide', true);\n\n context.container().selectAll('.viewfield-group, .sequence, .icon-sign')\n .classed('currentView', false);\n\n return this.setStyles(context, null, true);\n },\n\n\n updateViewer: function(context, d) {\n var wrap = context.container().select('.photoviewer .osc-wrapper');\n var imageWrap = wrap.selectAll('.osc-image-wrap');\n var attribution = wrap.selectAll('.photo-attribution').html('');\n\n wrap\n .transition()\n .duration(100)\n .call(imgZoom.transform, d3_zoomIdentity);\n\n imageWrap\n .selectAll('.osc-image')\n .remove();\n\n if (d) {\n var sequence = _oscCache.sequences[d.sequence_id];\n var r = (sequence && sequence.rotation) || 0;\n\n imageWrap\n .append('img')\n .attr('class', 'osc-image')\n .attr('src', apibase + '/' + d.imagePath)\n .style('transform', 'rotate(' + r + 'deg)');\n\n if (d.captured_by) {\n attribution\n .append('a')\n .attr('class', 'captured_by')\n .attr('target', '_blank')\n .attr('href', 'https://openstreetcam.org/user/' + encodeURIComponent(d.captured_by))\n .text('@' + d.captured_by);\n\n attribution\n .append('span')\n .text('|');\n }\n\n if (d.captured_at) {\n attribution\n .append('span')\n .attr('class', 'captured_at')\n .text(localeDateString(d.captured_at));\n\n attribution\n .append('span')\n .text('|');\n }\n\n attribution\n .append('a')\n .attr('class', 'image-link')\n .attr('target', '_blank')\n .attr('href', 'https://openstreetcam.org/details/' + d.sequence_id + '/' + d.sequence_index)\n .text('openstreetcam.org');\n }\n\n return this;\n\n\n function localeDateString(s) {\n if (!s) return null;\n var options = { day: 'numeric', month: 'short', year: 'numeric' };\n var d = new Date(s);\n if (isNaN(d.getTime())) return null;\n return d.toLocaleDateString(localizer.localeCode(), options);\n }\n },\n\n\n selectImage: function(context, d) {\n _oscSelectedImage = d;\n var viewer = context.container().select('.photoviewer');\n if (!viewer.empty()) viewer.datum(d);\n\n this.setStyles(context, null, true);\n\n context.container().selectAll('.icon-sign')\n .classed('currentView', false);\n\n return this;\n },\n\n\n getSelectedImage: function() {\n return _oscSelectedImage;\n },\n\n\n getSequenceKeyForImage: function(d) {\n return d && d.sequence_id;\n },\n\n\n // Updates the currently highlighted sequence and selected bubble.\n // Reset is only necessary when interacting with the viewport because\n // this implicitly changes the currently selected bubble/sequence\n setStyles: function(context, hovered, reset) {\n if (reset) { // reset all layers\n context.container().selectAll('.viewfield-group')\n .classed('highlighted', false)\n .classed('hovered', false)\n .classed('currentView', false);\n\n context.container().selectAll('.sequence')\n .classed('highlighted', false)\n .classed('currentView', false);\n }\n\n var hoveredImageKey = hovered && hovered.key;\n var hoveredSequenceKey = this.getSequenceKeyForImage(hovered);\n var hoveredSequence = hoveredSequenceKey && _oscCache.sequences[hoveredSequenceKey];\n var hoveredImageKeys = (hoveredSequence && hoveredSequence.images.map(function (d) { return d.key; })) || [];\n\n var viewer = context.container().select('.photoviewer');\n var selected = viewer.empty() ? undefined : viewer.datum();\n var selectedImageKey = selected && selected.key;\n var selectedSequenceKey = this.getSequenceKeyForImage(selected);\n var selectedSequence = selectedSequenceKey && _oscCache.sequences[selectedSequenceKey];\n var selectedImageKeys = (selectedSequence && selectedSequence.images.map(function (d) { return d.key; })) || [];\n\n // highlight sibling viewfields on either the selected or the hovered sequences\n var highlightedImageKeys = utilArrayUnion(hoveredImageKeys, selectedImageKeys);\n\n context.container().selectAll('.layer-openstreetcam .viewfield-group')\n .classed('highlighted', function(d) { return highlightedImageKeys.indexOf(d.key) !== -1; })\n .classed('hovered', function(d) { return d.key === hoveredImageKey; })\n .classed('currentView', function(d) { return d.key === selectedImageKey; });\n\n context.container().selectAll('.layer-openstreetcam .sequence')\n .classed('highlighted', function(d) { return d.properties.key === hoveredSequenceKey; })\n .classed('currentView', function(d) { return d.properties.key === selectedSequenceKey; });\n\n // update viewfields if needed\n context.container().selectAll('.viewfield-group .viewfield')\n .attr('d', viewfieldPath);\n\n function viewfieldPath() {\n var d = this.parentNode.__data__;\n if (d.pano && d.key !== selectedImageKey) {\n return 'M 8,13 m -10,0 a 10,10 0 1,0 20,0 a 10,10 0 1,0 -20,0';\n } else {\n return 'M 6,9 C 8,8.4 8,8.4 10,9 L 16,-2 C 12,-5 4,-5 0,-2 z';\n }\n }\n\n return this;\n },\n\n\n cache: function() {\n return _oscCache;\n }\n\n};\n","/**\n * jshashes - https://github.com/h2non/jshashes\n * Released under the \"New BSD\" license\n *\n * Algorithms specification:\n *\n * MD5 - http://www.ietf.org/rfc/rfc1321.txt\n * RIPEMD-160 - http://homes.esat.kuleuven.be/~bosselae/ripemd160.html\n * SHA1 - http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf\n * SHA256 - http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf\n * SHA512 - http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf\n * HMAC - http://www.ietf.org/rfc/rfc2104.txt\n */\n(function() {\n var Hashes;\n\n function utf8Encode(str) {\n var x, y, output = '',\n i = -1,\n l;\n\n if (str && str.length) {\n l = str.length;\n while ((i += 1) < l) {\n /* Decode utf-16 surrogate pairs */\n x = str.charCodeAt(i);\n y = i + 1 < l ? str.charCodeAt(i + 1) : 0;\n if (0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) {\n x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);\n i += 1;\n }\n /* Encode output as utf-8 */\n if (x <= 0x7F) {\n output += String.fromCharCode(x);\n } else if (x <= 0x7FF) {\n output += String.fromCharCode(0xC0 | ((x >>> 6) & 0x1F),\n 0x80 | (x & 0x3F));\n } else if (x <= 0xFFFF) {\n output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),\n 0x80 | ((x >>> 6) & 0x3F),\n 0x80 | (x & 0x3F));\n } else if (x <= 0x1FFFFF) {\n output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),\n 0x80 | ((x >>> 12) & 0x3F),\n 0x80 | ((x >>> 6) & 0x3F),\n 0x80 | (x & 0x3F));\n }\n }\n }\n return output;\n }\n\n function utf8Decode(str) {\n var i, ac, c1, c2, c3, arr = [],\n l;\n i = ac = c1 = c2 = c3 = 0;\n\n if (str && str.length) {\n l = str.length;\n str += '';\n\n while (i < l) {\n c1 = str.charCodeAt(i);\n ac += 1;\n if (c1 < 128) {\n arr[ac] = String.fromCharCode(c1);\n i += 1;\n } else if (c1 > 191 && c1 < 224) {\n c2 = str.charCodeAt(i + 1);\n arr[ac] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));\n i += 2;\n } else {\n c2 = str.charCodeAt(i + 1);\n c3 = str.charCodeAt(i + 2);\n arr[ac] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));\n i += 3;\n }\n }\n }\n return arr.join('');\n }\n\n /**\n * Add integers, wrapping at 2^32. This uses 16-bit operations internally\n * to work around bugs in some JS interpreters.\n */\n\n function safe_add(x, y) {\n var lsw = (x & 0xFFFF) + (y & 0xFFFF),\n msw = (x >> 16) + (y >> 16) + (lsw >> 16);\n return (msw << 16) | (lsw & 0xFFFF);\n }\n\n /**\n * Bitwise rotate a 32-bit number to the left.\n */\n\n function bit_rol(num, cnt) {\n return (num << cnt) | (num >>> (32 - cnt));\n }\n\n /**\n * Convert a raw string to a hex string\n */\n\n function rstr2hex(input, hexcase) {\n var hex_tab = hexcase ? '0123456789ABCDEF' : '0123456789abcdef',\n output = '',\n x, i = 0,\n l = input.length;\n for (; i < l; i += 1) {\n x = input.charCodeAt(i);\n output += hex_tab.charAt((x >>> 4) & 0x0F) + hex_tab.charAt(x & 0x0F);\n }\n return output;\n }\n\n /**\n * Encode a string as utf-16\n */\n\n function str2rstr_utf16le(input) {\n var i, l = input.length,\n output = '';\n for (i = 0; i < l; i += 1) {\n output += String.fromCharCode(input.charCodeAt(i) & 0xFF, (input.charCodeAt(i) >>> 8) & 0xFF);\n }\n return output;\n }\n\n function str2rstr_utf16be(input) {\n var i, l = input.length,\n output = '';\n for (i = 0; i < l; i += 1) {\n output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF, input.charCodeAt(i) & 0xFF);\n }\n return output;\n }\n\n /**\n * Convert an array of big-endian words to a string\n */\n\n function binb2rstr(input) {\n var i, l = input.length * 32,\n output = '';\n for (i = 0; i < l; i += 8) {\n output += String.fromCharCode((input[i >> 5] >>> (24 - i % 32)) & 0xFF);\n }\n return output;\n }\n\n /**\n * Convert an array of little-endian words to a string\n */\n\n function binl2rstr(input) {\n var i, l = input.length * 32,\n output = '';\n for (i = 0; i < l; i += 8) {\n output += String.fromCharCode((input[i >> 5] >>> (i % 32)) & 0xFF);\n }\n return output;\n }\n\n /**\n * Convert a raw string to an array of little-endian words\n * Characters >255 have their high-byte silently ignored.\n */\n\n function rstr2binl(input) {\n var i, l = input.length * 8,\n output = Array(input.length >> 2),\n lo = output.length;\n for (i = 0; i < lo; i += 1) {\n output[i] = 0;\n }\n for (i = 0; i < l; i += 8) {\n output[i >> 5] |= (input.charCodeAt(i / 8) & 0xFF) << (i % 32);\n }\n return output;\n }\n\n /**\n * Convert a raw string to an array of big-endian words\n * Characters >255 have their high-byte silently ignored.\n */\n\n function rstr2binb(input) {\n var i, l = input.length * 8,\n output = Array(input.length >> 2),\n lo = output.length;\n for (i = 0; i < lo; i += 1) {\n output[i] = 0;\n }\n for (i = 0; i < l; i += 8) {\n output[i >> 5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);\n }\n return output;\n }\n\n /**\n * Convert a raw string to an arbitrary string encoding\n */\n\n function rstr2any(input, encoding) {\n var divisor = encoding.length,\n remainders = Array(),\n i, q, x, ld, quotient, dividend, output, full_length;\n\n /* Convert to an array of 16-bit big-endian values, forming the dividend */\n dividend = Array(Math.ceil(input.length / 2));\n ld = dividend.length;\n for (i = 0; i < ld; i += 1) {\n dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);\n }\n\n /**\n * Repeatedly perform a long division. The binary array forms the dividend,\n * the length of the encoding is the divisor. Once computed, the quotient\n * forms the dividend for the next step. We stop when the dividend is zerHashes.\n * All remainders are stored for later use.\n */\n while (dividend.length > 0) {\n quotient = Array();\n x = 0;\n for (i = 0; i < dividend.length; i += 1) {\n x = (x << 16) + dividend[i];\n q = Math.floor(x / divisor);\n x -= q * divisor;\n if (quotient.length > 0 || q > 0) {\n quotient[quotient.length] = q;\n }\n }\n remainders[remainders.length] = x;\n dividend = quotient;\n }\n\n /* Convert the remainders to the output string */\n output = '';\n for (i = remainders.length - 1; i >= 0; i--) {\n output += encoding.charAt(remainders[i]);\n }\n\n /* Append leading zero equivalents */\n full_length = Math.ceil(input.length * 8 / (Math.log(encoding.length) / Math.log(2)));\n for (i = output.length; i < full_length; i += 1) {\n output = encoding[0] + output;\n }\n return output;\n }\n\n /**\n * Convert a raw string to a base-64 string\n */\n\n function rstr2b64(input, b64pad) {\n var tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',\n output = '',\n len = input.length,\n i, j, triplet;\n b64pad = b64pad || '=';\n for (i = 0; i < len; i += 3) {\n triplet = (input.charCodeAt(i) << 16) | (i + 1 < len ? input.charCodeAt(i + 1) << 8 : 0) | (i + 2 < len ? input.charCodeAt(i + 2) : 0);\n for (j = 0; j < 4; j += 1) {\n if (i * 8 + j * 6 > input.length * 8) {\n output += b64pad;\n } else {\n output += tab.charAt((triplet >>> 6 * (3 - j)) & 0x3F);\n }\n }\n }\n return output;\n }\n\n Hashes = {\n /**\n * @property {String} version\n * @readonly\n */\n VERSION: '1.0.6',\n /**\n * @member Hashes\n * @class Base64\n * @constructor\n */\n Base64: function() {\n // private properties\n var tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',\n pad = '=', // default pad according with the RFC standard\n url = false, // URL encoding support @todo\n utf8 = true; // by default enable UTF-8 support encoding\n\n // public method for encoding\n this.encode = function(input) {\n var i, j, triplet,\n output = '',\n len = input.length;\n\n pad = pad || '=';\n input = (utf8) ? utf8Encode(input) : input;\n\n for (i = 0; i < len; i += 3) {\n triplet = (input.charCodeAt(i) << 16) | (i + 1 < len ? input.charCodeAt(i + 1) << 8 : 0) | (i + 2 < len ? input.charCodeAt(i + 2) : 0);\n for (j = 0; j < 4; j += 1) {\n if (i * 8 + j * 6 > len * 8) {\n output += pad;\n } else {\n output += tab.charAt((triplet >>> 6 * (3 - j)) & 0x3F);\n }\n }\n }\n return output;\n };\n\n // public method for decoding\n this.decode = function(input) {\n // var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';\n var i, o1, o2, o3, h1, h2, h3, h4, bits, ac,\n dec = '',\n arr = [];\n if (!input) {\n return input;\n }\n\n i = ac = 0;\n input = input.replace(new RegExp('\\\\' + pad, 'gi'), ''); // use '='\n //input += '';\n\n do { // unpack four hexets into three octets using index points in b64\n h1 = tab.indexOf(input.charAt(i += 1));\n h2 = tab.indexOf(input.charAt(i += 1));\n h3 = tab.indexOf(input.charAt(i += 1));\n h4 = tab.indexOf(input.charAt(i += 1));\n\n bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;\n\n o1 = bits >> 16 & 0xff;\n o2 = bits >> 8 & 0xff;\n o3 = bits & 0xff;\n ac += 1;\n\n if (h3 === 64) {\n arr[ac] = String.fromCharCode(o1);\n } else if (h4 === 64) {\n arr[ac] = String.fromCharCode(o1, o2);\n } else {\n arr[ac] = String.fromCharCode(o1, o2, o3);\n }\n } while (i < input.length);\n\n dec = arr.join('');\n dec = (utf8) ? utf8Decode(dec) : dec;\n\n return dec;\n };\n\n // set custom pad string\n this.setPad = function(str) {\n pad = str || pad;\n return this;\n };\n // set custom tab string characters\n this.setTab = function(str) {\n tab = str || tab;\n return this;\n };\n this.setUTF8 = function(bool) {\n if (typeof bool === 'boolean') {\n utf8 = bool;\n }\n return this;\n };\n },\n\n /**\n * CRC-32 calculation\n * @member Hashes\n * @method CRC32\n * @static\n * @param {String} str Input String\n * @return {String}\n */\n CRC32: function(str) {\n var crc = 0,\n x = 0,\n y = 0,\n table, i, iTop;\n str = utf8Encode(str);\n\n table = [\n '00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 ',\n '79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 ',\n '84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F ',\n '63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD ',\n 'A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC ',\n '51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 ',\n 'B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 ',\n '06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 ',\n 'E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 ',\n '12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 ',\n 'D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 ',\n '33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 ',\n 'CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 ',\n '9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E ',\n '7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D ',\n '806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 ',\n '60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA ',\n 'AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 ',\n '5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 ',\n 'B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 ',\n '05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 ',\n 'F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA ',\n '11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 ',\n 'D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F ',\n '30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E ',\n 'C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D'\n ].join('');\n\n crc = crc ^ (-1);\n for (i = 0, iTop = str.length; i < iTop; i += 1) {\n y = (crc ^ str.charCodeAt(i)) & 0xFF;\n x = '0x' + table.substr(y * 9, 8);\n crc = (crc >>> 8) ^ x;\n }\n // always return a positive number (that's what >>> 0 does)\n return (crc ^ (-1)) >>> 0;\n },\n /**\n * @member Hashes\n * @class MD5\n * @constructor\n * @param {Object} [config]\n *\n * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message\n * Digest Algorithm, as defined in RFC 1321.\n * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009\n * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet\n * See for more infHashes.\n */\n MD5: function(options) {\n /**\n * Private config properties. You may need to tweak these to be compatible with\n * the server-side, but the defaults work in most cases.\n * See {@link Hashes.MD5#method-setUpperCase} and {@link Hashes.SHA1#method-setUpperCase}\n */\n var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false, // hexadecimal output case format. false - lowercase; true - uppercase\n b64pad = (options && typeof options.pad === 'string') ? options.pad : '=', // base-64 pad character. Defaults to '=' for strict RFC compliance\n utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true; // enable/disable utf8 encoding\n\n // privileged (public) methods\n this.hex = function(s) {\n return rstr2hex(rstr(s, utf8), hexcase);\n };\n this.b64 = function(s) {\n return rstr2b64(rstr(s), b64pad);\n };\n this.any = function(s, e) {\n return rstr2any(rstr(s, utf8), e);\n };\n this.raw = function(s) {\n return rstr(s, utf8);\n };\n this.hex_hmac = function(k, d) {\n return rstr2hex(rstr_hmac(k, d), hexcase);\n };\n this.b64_hmac = function(k, d) {\n return rstr2b64(rstr_hmac(k, d), b64pad);\n };\n this.any_hmac = function(k, d, e) {\n return rstr2any(rstr_hmac(k, d), e);\n };\n /**\n * Perform a simple self-test to see if the VM is working\n * @return {String} Hexadecimal hash sample\n */\n this.vm_test = function() {\n return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';\n };\n /**\n * Enable/disable uppercase hexadecimal returned string\n * @param {Boolean}\n * @return {Object} this\n */\n this.setUpperCase = function(a) {\n if (typeof a === 'boolean') {\n hexcase = a;\n }\n return this;\n };\n /**\n * Defines a base64 pad string\n * @param {String} Pad\n * @return {Object} this\n */\n this.setPad = function(a) {\n b64pad = a || b64pad;\n return this;\n };\n /**\n * Defines a base64 pad string\n * @param {Boolean}\n * @return {Object} [this]\n */\n this.setUTF8 = function(a) {\n if (typeof a === 'boolean') {\n utf8 = a;\n }\n return this;\n };\n\n // private methods\n\n /**\n * Calculate the MD5 of a raw string\n */\n\n function rstr(s) {\n s = (utf8) ? utf8Encode(s) : s;\n return binl2rstr(binl(rstr2binl(s), s.length * 8));\n }\n\n /**\n * Calculate the HMAC-MD5, of a key and some data (raw strings)\n */\n\n function rstr_hmac(key, data) {\n var bkey, ipad, opad, hash, i;\n\n key = (utf8) ? utf8Encode(key) : key;\n data = (utf8) ? utf8Encode(data) : data;\n bkey = rstr2binl(key);\n if (bkey.length > 16) {\n bkey = binl(bkey, key.length * 8);\n }\n\n ipad = Array(16), opad = Array(16);\n for (i = 0; i < 16; i += 1) {\n ipad[i] = bkey[i] ^ 0x36363636;\n opad[i] = bkey[i] ^ 0x5C5C5C5C;\n }\n hash = binl(ipad.concat(rstr2binl(data)), 512 + data.length * 8);\n return binl2rstr(binl(opad.concat(hash), 512 + 128));\n }\n\n /**\n * Calculate the MD5 of an array of little-endian words, and a bit length.\n */\n\n function binl(x, len) {\n var i, olda, oldb, oldc, oldd,\n a = 1732584193,\n b = -271733879,\n c = -1732584194,\n d = 271733878;\n\n /* append padding */\n x[len >> 5] |= 0x80 << ((len) % 32);\n x[(((len + 64) >>> 9) << 4) + 14] = len;\n\n for (i = 0; i < x.length; i += 16) {\n olda = a;\n oldb = b;\n oldc = c;\n oldd = d;\n\n a = md5_ff(a, b, c, d, x[i + 0], 7, -680876936);\n d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586);\n c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819);\n b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330);\n a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897);\n d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);\n c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341);\n b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983);\n a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);\n d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417);\n c = md5_ff(c, d, a, b, x[i + 10], 17, -42063);\n b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162);\n a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);\n d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101);\n c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290);\n b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);\n\n a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510);\n d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632);\n c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713);\n b = md5_gg(b, c, d, a, x[i + 0], 20, -373897302);\n a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691);\n d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083);\n c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335);\n b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848);\n a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438);\n d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690);\n c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961);\n b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);\n a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467);\n d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784);\n c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);\n b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734);\n\n a = md5_hh(a, b, c, d, x[i + 5], 4, -378558);\n d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463);\n c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);\n b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556);\n a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060);\n d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);\n c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632);\n b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640);\n a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174);\n d = md5_hh(d, a, b, c, x[i + 0], 11, -358537222);\n c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979);\n b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189);\n a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487);\n d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835);\n c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520);\n b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651);\n\n a = md5_ii(a, b, c, d, x[i + 0], 6, -198630844);\n d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);\n c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905);\n b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055);\n a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);\n d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606);\n c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523);\n b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799);\n a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);\n d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744);\n c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380);\n b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);\n a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070);\n d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379);\n c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259);\n b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551);\n\n a = safe_add(a, olda);\n b = safe_add(b, oldb);\n c = safe_add(c, oldc);\n d = safe_add(d, oldd);\n }\n return Array(a, b, c, d);\n }\n\n /**\n * These functions implement the four basic operations the algorithm uses.\n */\n\n function md5_cmn(q, a, b, x, s, t) {\n return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b);\n }\n\n function md5_ff(a, b, c, d, x, s, t) {\n return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);\n }\n\n function md5_gg(a, b, c, d, x, s, t) {\n return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);\n }\n\n function md5_hh(a, b, c, d, x, s, t) {\n return md5_cmn(b ^ c ^ d, a, b, x, s, t);\n }\n\n function md5_ii(a, b, c, d, x, s, t) {\n return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);\n }\n },\n /**\n * @member Hashes\n * @class Hashes.SHA1\n * @param {Object} [config]\n * @constructor\n *\n * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined in FIPS 180-1\n * Version 2.2 Copyright Paul Johnston 2000 - 2009.\n * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet\n * See http://pajhome.org.uk/crypt/md5 for details.\n */\n SHA1: function(options) {\n /**\n * Private config properties. You may need to tweak these to be compatible with\n * the server-side, but the defaults work in most cases.\n * See {@link Hashes.MD5#method-setUpperCase} and {@link Hashes.SHA1#method-setUpperCase}\n */\n var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false, // hexadecimal output case format. false - lowercase; true - uppercase\n b64pad = (options && typeof options.pad === 'string') ? options.pad : '=', // base-64 pad character. Defaults to '=' for strict RFC compliance\n utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true; // enable/disable utf8 encoding\n\n // public methods\n this.hex = function(s) {\n return rstr2hex(rstr(s, utf8), hexcase);\n };\n this.b64 = function(s) {\n return rstr2b64(rstr(s, utf8), b64pad);\n };\n this.any = function(s, e) {\n return rstr2any(rstr(s, utf8), e);\n };\n this.raw = function(s) {\n return rstr(s, utf8);\n };\n this.hex_hmac = function(k, d) {\n return rstr2hex(rstr_hmac(k, d));\n };\n this.b64_hmac = function(k, d) {\n return rstr2b64(rstr_hmac(k, d), b64pad);\n };\n this.any_hmac = function(k, d, e) {\n return rstr2any(rstr_hmac(k, d), e);\n };\n /**\n * Perform a simple self-test to see if the VM is working\n * @return {String} Hexadecimal hash sample\n * @public\n */\n this.vm_test = function() {\n return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';\n };\n /**\n * @description Enable/disable uppercase hexadecimal returned string\n * @param {boolean}\n * @return {Object} this\n * @public\n */\n this.setUpperCase = function(a) {\n if (typeof a === 'boolean') {\n hexcase = a;\n }\n return this;\n };\n /**\n * @description Defines a base64 pad string\n * @param {string} Pad\n * @return {Object} this\n * @public\n */\n this.setPad = function(a) {\n b64pad = a || b64pad;\n return this;\n };\n /**\n * @description Defines a base64 pad string\n * @param {boolean}\n * @return {Object} this\n * @public\n */\n this.setUTF8 = function(a) {\n if (typeof a === 'boolean') {\n utf8 = a;\n }\n return this;\n };\n\n // private methods\n\n /**\n * Calculate the SHA-512 of a raw string\n */\n\n function rstr(s) {\n s = (utf8) ? utf8Encode(s) : s;\n return binb2rstr(binb(rstr2binb(s), s.length * 8));\n }\n\n /**\n * Calculate the HMAC-SHA1 of a key and some data (raw strings)\n */\n\n function rstr_hmac(key, data) {\n var bkey, ipad, opad, i, hash;\n key = (utf8) ? utf8Encode(key) : key;\n data = (utf8) ? utf8Encode(data) : data;\n bkey = rstr2binb(key);\n\n if (bkey.length > 16) {\n bkey = binb(bkey, key.length * 8);\n }\n ipad = Array(16), opad = Array(16);\n for (i = 0; i < 16; i += 1) {\n ipad[i] = bkey[i] ^ 0x36363636;\n opad[i] = bkey[i] ^ 0x5C5C5C5C;\n }\n hash = binb(ipad.concat(rstr2binb(data)), 512 + data.length * 8);\n return binb2rstr(binb(opad.concat(hash), 512 + 160));\n }\n\n /**\n * Calculate the SHA-1 of an array of big-endian words, and a bit length\n */\n\n function binb(x, len) {\n var i, j, t, olda, oldb, oldc, oldd, olde,\n w = Array(80),\n a = 1732584193,\n b = -271733879,\n c = -1732584194,\n d = 271733878,\n e = -1009589776;\n\n /* append padding */\n x[len >> 5] |= 0x80 << (24 - len % 32);\n x[((len + 64 >> 9) << 4) + 15] = len;\n\n for (i = 0; i < x.length; i += 16) {\n olda = a;\n oldb = b;\n oldc = c;\n oldd = d;\n olde = e;\n\n for (j = 0; j < 80; j += 1) {\n if (j < 16) {\n w[j] = x[i + j];\n } else {\n w[j] = bit_rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1);\n }\n t = safe_add(safe_add(bit_rol(a, 5), sha1_ft(j, b, c, d)),\n safe_add(safe_add(e, w[j]), sha1_kt(j)));\n e = d;\n d = c;\n c = bit_rol(b, 30);\n b = a;\n a = t;\n }\n\n a = safe_add(a, olda);\n b = safe_add(b, oldb);\n c = safe_add(c, oldc);\n d = safe_add(d, oldd);\n e = safe_add(e, olde);\n }\n return Array(a, b, c, d, e);\n }\n\n /**\n * Perform the appropriate triplet combination function for the current\n * iteration\n */\n\n function sha1_ft(t, b, c, d) {\n if (t < 20) {\n return (b & c) | ((~b) & d);\n }\n if (t < 40) {\n return b ^ c ^ d;\n }\n if (t < 60) {\n return (b & c) | (b & d) | (c & d);\n }\n return b ^ c ^ d;\n }\n\n /**\n * Determine the appropriate additive constant for the current iteration\n */\n\n function sha1_kt(t) {\n return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :\n (t < 60) ? -1894007588 : -899497514;\n }\n },\n /**\n * @class Hashes.SHA256\n * @param {config}\n *\n * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined in FIPS 180-2\n * Version 2.2 Copyright Angel Marin, Paul Johnston 2000 - 2009.\n * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet\n * See http://pajhome.org.uk/crypt/md5 for details.\n * Also http://anmar.eu.org/projects/jssha2/\n */\n SHA256: function(options) {\n /**\n * Private properties configuration variables. You may need to tweak these to be compatible with\n * the server-side, but the defaults work in most cases.\n * @see this.setUpperCase() method\n * @see this.setPad() method\n */\n var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false, // hexadecimal output case format. false - lowercase; true - uppercase */\n b64pad = (options && typeof options.pad === 'string') ? options.pad : '=',\n /* base-64 pad character. Default '=' for strict RFC compliance */\n utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true,\n /* enable/disable utf8 encoding */\n sha256_K;\n\n /* privileged (public) methods */\n this.hex = function(s) {\n return rstr2hex(rstr(s, utf8));\n };\n this.b64 = function(s) {\n return rstr2b64(rstr(s, utf8), b64pad);\n };\n this.any = function(s, e) {\n return rstr2any(rstr(s, utf8), e);\n };\n this.raw = function(s) {\n return rstr(s, utf8);\n };\n this.hex_hmac = function(k, d) {\n return rstr2hex(rstr_hmac(k, d));\n };\n this.b64_hmac = function(k, d) {\n return rstr2b64(rstr_hmac(k, d), b64pad);\n };\n this.any_hmac = function(k, d, e) {\n return rstr2any(rstr_hmac(k, d), e);\n };\n /**\n * Perform a simple self-test to see if the VM is working\n * @return {String} Hexadecimal hash sample\n * @public\n */\n this.vm_test = function() {\n return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';\n };\n /**\n * Enable/disable uppercase hexadecimal returned string\n * @param {boolean}\n * @return {Object} this\n * @public\n */\n this.setUpperCase = function(a) {\n if (typeof a === 'boolean') {\n hexcase = a;\n }\n return this;\n };\n /**\n * @description Defines a base64 pad string\n * @param {string} Pad\n * @return {Object} this\n * @public\n */\n this.setPad = function(a) {\n b64pad = a || b64pad;\n return this;\n };\n /**\n * Defines a base64 pad string\n * @param {boolean}\n * @return {Object} this\n * @public\n */\n this.setUTF8 = function(a) {\n if (typeof a === 'boolean') {\n utf8 = a;\n }\n return this;\n };\n\n // private methods\n\n /**\n * Calculate the SHA-512 of a raw string\n */\n\n function rstr(s, utf8) {\n s = (utf8) ? utf8Encode(s) : s;\n return binb2rstr(binb(rstr2binb(s), s.length * 8));\n }\n\n /**\n * Calculate the HMAC-sha256 of a key and some data (raw strings)\n */\n\n function rstr_hmac(key, data) {\n key = (utf8) ? utf8Encode(key) : key;\n data = (utf8) ? utf8Encode(data) : data;\n var hash, i = 0,\n bkey = rstr2binb(key),\n ipad = Array(16),\n opad = Array(16);\n\n if (bkey.length > 16) {\n bkey = binb(bkey, key.length * 8);\n }\n\n for (; i < 16; i += 1) {\n ipad[i] = bkey[i] ^ 0x36363636;\n opad[i] = bkey[i] ^ 0x5C5C5C5C;\n }\n\n hash = binb(ipad.concat(rstr2binb(data)), 512 + data.length * 8);\n return binb2rstr(binb(opad.concat(hash), 512 + 256));\n }\n\n /*\n * Main sha256 function, with its support functions\n */\n\n function sha256_S(X, n) {\n return (X >>> n) | (X << (32 - n));\n }\n\n function sha256_R(X, n) {\n return (X >>> n);\n }\n\n function sha256_Ch(x, y, z) {\n return ((x & y) ^ ((~x) & z));\n }\n\n function sha256_Maj(x, y, z) {\n return ((x & y) ^ (x & z) ^ (y & z));\n }\n\n function sha256_Sigma0256(x) {\n return (sha256_S(x, 2) ^ sha256_S(x, 13) ^ sha256_S(x, 22));\n }\n\n function sha256_Sigma1256(x) {\n return (sha256_S(x, 6) ^ sha256_S(x, 11) ^ sha256_S(x, 25));\n }\n\n function sha256_Gamma0256(x) {\n return (sha256_S(x, 7) ^ sha256_S(x, 18) ^ sha256_R(x, 3));\n }\n\n function sha256_Gamma1256(x) {\n return (sha256_S(x, 17) ^ sha256_S(x, 19) ^ sha256_R(x, 10));\n }\n\n function sha256_Sigma0512(x) {\n return (sha256_S(x, 28) ^ sha256_S(x, 34) ^ sha256_S(x, 39));\n }\n\n function sha256_Sigma1512(x) {\n return (sha256_S(x, 14) ^ sha256_S(x, 18) ^ sha256_S(x, 41));\n }\n\n function sha256_Gamma0512(x) {\n return (sha256_S(x, 1) ^ sha256_S(x, 8) ^ sha256_R(x, 7));\n }\n\n function sha256_Gamma1512(x) {\n return (sha256_S(x, 19) ^ sha256_S(x, 61) ^ sha256_R(x, 6));\n }\n\n sha256_K = [\n 1116352408, 1899447441, -1245643825, -373957723, 961987163, 1508970993, -1841331548, -1424204075, -670586216, 310598401, 607225278, 1426881987,\n 1925078388, -2132889090, -1680079193, -1046744716, -459576895, -272742522,\n 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, -1740746414, -1473132947, -1341970488, -1084653625, -958395405, -710438585,\n 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291,\n 1695183700, 1986661051, -2117940946, -1838011259, -1564481375, -1474664885, -1035236496, -949202525, -778901479, -694614492, -200395387, 275423344,\n 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218,\n 1537002063, 1747873779, 1955562222, 2024104815, -2067236844, -1933114872, -1866530822, -1538233109, -1090935817, -965641998\n ];\n\n function binb(m, l) {\n var HASH = [1779033703, -1150833019, 1013904242, -1521486534,\n 1359893119, -1694144372, 528734635, 1541459225\n ];\n var W = new Array(64);\n var a, b, c, d, e, f, g, h;\n var i, j, T1, T2;\n\n /* append padding */\n m[l >> 5] |= 0x80 << (24 - l % 32);\n m[((l + 64 >> 9) << 4) + 15] = l;\n\n for (i = 0; i < m.length; i += 16) {\n a = HASH[0];\n b = HASH[1];\n c = HASH[2];\n d = HASH[3];\n e = HASH[4];\n f = HASH[5];\n g = HASH[6];\n h = HASH[7];\n\n for (j = 0; j < 64; j += 1) {\n if (j < 16) {\n W[j] = m[j + i];\n } else {\n W[j] = safe_add(safe_add(safe_add(sha256_Gamma1256(W[j - 2]), W[j - 7]),\n sha256_Gamma0256(W[j - 15])), W[j - 16]);\n }\n\n T1 = safe_add(safe_add(safe_add(safe_add(h, sha256_Sigma1256(e)), sha256_Ch(e, f, g)),\n sha256_K[j]), W[j]);\n T2 = safe_add(sha256_Sigma0256(a), sha256_Maj(a, b, c));\n h = g;\n g = f;\n f = e;\n e = safe_add(d, T1);\n d = c;\n c = b;\n b = a;\n a = safe_add(T1, T2);\n }\n\n HASH[0] = safe_add(a, HASH[0]);\n HASH[1] = safe_add(b, HASH[1]);\n HASH[2] = safe_add(c, HASH[2]);\n HASH[3] = safe_add(d, HASH[3]);\n HASH[4] = safe_add(e, HASH[4]);\n HASH[5] = safe_add(f, HASH[5]);\n HASH[6] = safe_add(g, HASH[6]);\n HASH[7] = safe_add(h, HASH[7]);\n }\n return HASH;\n }\n\n },\n\n /**\n * @class Hashes.SHA512\n * @param {config}\n *\n * A JavaScript implementation of the Secure Hash Algorithm, SHA-512, as defined in FIPS 180-2\n * Version 2.2 Copyright Anonymous Contributor, Paul Johnston 2000 - 2009.\n * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet\n * See http://pajhome.org.uk/crypt/md5 for details.\n */\n SHA512: function(options) {\n /**\n * Private properties configuration variables. You may need to tweak these to be compatible with\n * the server-side, but the defaults work in most cases.\n * @see this.setUpperCase() method\n * @see this.setPad() method\n */\n var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false,\n /* hexadecimal output case format. false - lowercase; true - uppercase */\n b64pad = (options && typeof options.pad === 'string') ? options.pad : '=',\n /* base-64 pad character. Default '=' for strict RFC compliance */\n utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true,\n /* enable/disable utf8 encoding */\n sha512_k;\n\n /* privileged (public) methods */\n this.hex = function(s) {\n return rstr2hex(rstr(s));\n };\n this.b64 = function(s) {\n return rstr2b64(rstr(s), b64pad);\n };\n this.any = function(s, e) {\n return rstr2any(rstr(s), e);\n };\n this.raw = function(s) {\n return rstr(s, utf8);\n };\n this.hex_hmac = function(k, d) {\n return rstr2hex(rstr_hmac(k, d));\n };\n this.b64_hmac = function(k, d) {\n return rstr2b64(rstr_hmac(k, d), b64pad);\n };\n this.any_hmac = function(k, d, e) {\n return rstr2any(rstr_hmac(k, d), e);\n };\n /**\n * Perform a simple self-test to see if the VM is working\n * @return {String} Hexadecimal hash sample\n * @public\n */\n this.vm_test = function() {\n return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';\n };\n /**\n * @description Enable/disable uppercase hexadecimal returned string\n * @param {boolean}\n * @return {Object} this\n * @public\n */\n this.setUpperCase = function(a) {\n if (typeof a === 'boolean') {\n hexcase = a;\n }\n return this;\n };\n /**\n * @description Defines a base64 pad string\n * @param {string} Pad\n * @return {Object} this\n * @public\n */\n this.setPad = function(a) {\n b64pad = a || b64pad;\n return this;\n };\n /**\n * @description Defines a base64 pad string\n * @param {boolean}\n * @return {Object} this\n * @public\n */\n this.setUTF8 = function(a) {\n if (typeof a === 'boolean') {\n utf8 = a;\n }\n return this;\n };\n\n /* private methods */\n\n /**\n * Calculate the SHA-512 of a raw string\n */\n\n function rstr(s) {\n s = (utf8) ? utf8Encode(s) : s;\n return binb2rstr(binb(rstr2binb(s), s.length * 8));\n }\n /*\n * Calculate the HMAC-SHA-512 of a key and some data (raw strings)\n */\n\n function rstr_hmac(key, data) {\n key = (utf8) ? utf8Encode(key) : key;\n data = (utf8) ? utf8Encode(data) : data;\n\n var hash, i = 0,\n bkey = rstr2binb(key),\n ipad = Array(32),\n opad = Array(32);\n\n if (bkey.length > 32) {\n bkey = binb(bkey, key.length * 8);\n }\n\n for (; i < 32; i += 1) {\n ipad[i] = bkey[i] ^ 0x36363636;\n opad[i] = bkey[i] ^ 0x5C5C5C5C;\n }\n\n hash = binb(ipad.concat(rstr2binb(data)), 1024 + data.length * 8);\n return binb2rstr(binb(opad.concat(hash), 1024 + 512));\n }\n\n /**\n * Calculate the SHA-512 of an array of big-endian dwords, and a bit length\n */\n\n function binb(x, len) {\n var j, i, l,\n W = new Array(80),\n hash = new Array(16),\n //Initial hash values\n H = [\n new int64(0x6a09e667, -205731576),\n new int64(-1150833019, -2067093701),\n new int64(0x3c6ef372, -23791573),\n new int64(-1521486534, 0x5f1d36f1),\n new int64(0x510e527f, -1377402159),\n new int64(-1694144372, 0x2b3e6c1f),\n new int64(0x1f83d9ab, -79577749),\n new int64(0x5be0cd19, 0x137e2179)\n ],\n T1 = new int64(0, 0),\n T2 = new int64(0, 0),\n a = new int64(0, 0),\n b = new int64(0, 0),\n c = new int64(0, 0),\n d = new int64(0, 0),\n e = new int64(0, 0),\n f = new int64(0, 0),\n g = new int64(0, 0),\n h = new int64(0, 0),\n //Temporary variables not specified by the document\n s0 = new int64(0, 0),\n s1 = new int64(0, 0),\n Ch = new int64(0, 0),\n Maj = new int64(0, 0),\n r1 = new int64(0, 0),\n r2 = new int64(0, 0),\n r3 = new int64(0, 0);\n\n if (sha512_k === undefined) {\n //SHA512 constants\n sha512_k = [\n new int64(0x428a2f98, -685199838), new int64(0x71374491, 0x23ef65cd),\n new int64(-1245643825, -330482897), new int64(-373957723, -2121671748),\n new int64(0x3956c25b, -213338824), new int64(0x59f111f1, -1241133031),\n new int64(-1841331548, -1357295717), new int64(-1424204075, -630357736),\n new int64(-670586216, -1560083902), new int64(0x12835b01, 0x45706fbe),\n new int64(0x243185be, 0x4ee4b28c), new int64(0x550c7dc3, -704662302),\n new int64(0x72be5d74, -226784913), new int64(-2132889090, 0x3b1696b1),\n new int64(-1680079193, 0x25c71235), new int64(-1046744716, -815192428),\n new int64(-459576895, -1628353838), new int64(-272742522, 0x384f25e3),\n new int64(0xfc19dc6, -1953704523), new int64(0x240ca1cc, 0x77ac9c65),\n new int64(0x2de92c6f, 0x592b0275), new int64(0x4a7484aa, 0x6ea6e483),\n new int64(0x5cb0a9dc, -1119749164), new int64(0x76f988da, -2096016459),\n new int64(-1740746414, -295247957), new int64(-1473132947, 0x2db43210),\n new int64(-1341970488, -1728372417), new int64(-1084653625, -1091629340),\n new int64(-958395405, 0x3da88fc2), new int64(-710438585, -1828018395),\n new int64(0x6ca6351, -536640913), new int64(0x14292967, 0xa0e6e70),\n new int64(0x27b70a85, 0x46d22ffc), new int64(0x2e1b2138, 0x5c26c926),\n new int64(0x4d2c6dfc, 0x5ac42aed), new int64(0x53380d13, -1651133473),\n new int64(0x650a7354, -1951439906), new int64(0x766a0abb, 0x3c77b2a8),\n new int64(-2117940946, 0x47edaee6), new int64(-1838011259, 0x1482353b),\n new int64(-1564481375, 0x4cf10364), new int64(-1474664885, -1136513023),\n new int64(-1035236496, -789014639), new int64(-949202525, 0x654be30),\n new int64(-778901479, -688958952), new int64(-694614492, 0x5565a910),\n new int64(-200395387, 0x5771202a), new int64(0x106aa070, 0x32bbd1b8),\n new int64(0x19a4c116, -1194143544), new int64(0x1e376c08, 0x5141ab53),\n new int64(0x2748774c, -544281703), new int64(0x34b0bcb5, -509917016),\n new int64(0x391c0cb3, -976659869), new int64(0x4ed8aa4a, -482243893),\n new int64(0x5b9cca4f, 0x7763e373), new int64(0x682e6ff3, -692930397),\n new int64(0x748f82ee, 0x5defb2fc), new int64(0x78a5636f, 0x43172f60),\n new int64(-2067236844, -1578062990), new int64(-1933114872, 0x1a6439ec),\n new int64(-1866530822, 0x23631e28), new int64(-1538233109, -561857047),\n new int64(-1090935817, -1295615723), new int64(-965641998, -479046869),\n new int64(-903397682, -366583396), new int64(-779700025, 0x21c0c207),\n new int64(-354779690, -840897762), new int64(-176337025, -294727304),\n new int64(0x6f067aa, 0x72176fba), new int64(0xa637dc5, -1563912026),\n new int64(0x113f9804, -1090974290), new int64(0x1b710b35, 0x131c471b),\n new int64(0x28db77f5, 0x23047d84), new int64(0x32caab7b, 0x40c72493),\n new int64(0x3c9ebe0a, 0x15c9bebc), new int64(0x431d67c4, -1676669620),\n new int64(0x4cc5d4be, -885112138), new int64(0x597f299c, -60457430),\n new int64(0x5fcb6fab, 0x3ad6faec), new int64(0x6c44198c, 0x4a475817)\n ];\n }\n\n for (i = 0; i < 80; i += 1) {\n W[i] = new int64(0, 0);\n }\n\n // append padding to the source string. The format is described in the FIPS.\n x[len >> 5] |= 0x80 << (24 - (len & 0x1f));\n x[((len + 128 >> 10) << 5) + 31] = len;\n l = x.length;\n for (i = 0; i < l; i += 32) { //32 dwords is the block size\n int64copy(a, H[0]);\n int64copy(b, H[1]);\n int64copy(c, H[2]);\n int64copy(d, H[3]);\n int64copy(e, H[4]);\n int64copy(f, H[5]);\n int64copy(g, H[6]);\n int64copy(h, H[7]);\n\n for (j = 0; j < 16; j += 1) {\n W[j].h = x[i + 2 * j];\n W[j].l = x[i + 2 * j + 1];\n }\n\n for (j = 16; j < 80; j += 1) {\n //sigma1\n int64rrot(r1, W[j - 2], 19);\n int64revrrot(r2, W[j - 2], 29);\n int64shr(r3, W[j - 2], 6);\n s1.l = r1.l ^ r2.l ^ r3.l;\n s1.h = r1.h ^ r2.h ^ r3.h;\n //sigma0\n int64rrot(r1, W[j - 15], 1);\n int64rrot(r2, W[j - 15], 8);\n int64shr(r3, W[j - 15], 7);\n s0.l = r1.l ^ r2.l ^ r3.l;\n s0.h = r1.h ^ r2.h ^ r3.h;\n\n int64add4(W[j], s1, W[j - 7], s0, W[j - 16]);\n }\n\n for (j = 0; j < 80; j += 1) {\n //Ch\n Ch.l = (e.l & f.l) ^ (~e.l & g.l);\n Ch.h = (e.h & f.h) ^ (~e.h & g.h);\n\n //Sigma1\n int64rrot(r1, e, 14);\n int64rrot(r2, e, 18);\n int64revrrot(r3, e, 9);\n s1.l = r1.l ^ r2.l ^ r3.l;\n s1.h = r1.h ^ r2.h ^ r3.h;\n\n //Sigma0\n int64rrot(r1, a, 28);\n int64revrrot(r2, a, 2);\n int64revrrot(r3, a, 7);\n s0.l = r1.l ^ r2.l ^ r3.l;\n s0.h = r1.h ^ r2.h ^ r3.h;\n\n //Maj\n Maj.l = (a.l & b.l) ^ (a.l & c.l) ^ (b.l & c.l);\n Maj.h = (a.h & b.h) ^ (a.h & c.h) ^ (b.h & c.h);\n\n int64add5(T1, h, s1, Ch, sha512_k[j], W[j]);\n int64add(T2, s0, Maj);\n\n int64copy(h, g);\n int64copy(g, f);\n int64copy(f, e);\n int64add(e, d, T1);\n int64copy(d, c);\n int64copy(c, b);\n int64copy(b, a);\n int64add(a, T1, T2);\n }\n int64add(H[0], H[0], a);\n int64add(H[1], H[1], b);\n int64add(H[2], H[2], c);\n int64add(H[3], H[3], d);\n int64add(H[4], H[4], e);\n int64add(H[5], H[5], f);\n int64add(H[6], H[6], g);\n int64add(H[7], H[7], h);\n }\n\n //represent the hash as an array of 32-bit dwords\n for (i = 0; i < 8; i += 1) {\n hash[2 * i] = H[i].h;\n hash[2 * i + 1] = H[i].l;\n }\n return hash;\n }\n\n //A constructor for 64-bit numbers\n\n function int64(h, l) {\n this.h = h;\n this.l = l;\n //this.toString = int64toString;\n }\n\n //Copies src into dst, assuming both are 64-bit numbers\n\n function int64copy(dst, src) {\n dst.h = src.h;\n dst.l = src.l;\n }\n\n //Right-rotates a 64-bit number by shift\n //Won't handle cases of shift>=32\n //The function revrrot() is for that\n\n function int64rrot(dst, x, shift) {\n dst.l = (x.l >>> shift) | (x.h << (32 - shift));\n dst.h = (x.h >>> shift) | (x.l << (32 - shift));\n }\n\n //Reverses the dwords of the source and then rotates right by shift.\n //This is equivalent to rotation by 32+shift\n\n function int64revrrot(dst, x, shift) {\n dst.l = (x.h >>> shift) | (x.l << (32 - shift));\n dst.h = (x.l >>> shift) | (x.h << (32 - shift));\n }\n\n //Bitwise-shifts right a 64-bit number by shift\n //Won't handle shift>=32, but it's never needed in SHA512\n\n function int64shr(dst, x, shift) {\n dst.l = (x.l >>> shift) | (x.h << (32 - shift));\n dst.h = (x.h >>> shift);\n }\n\n //Adds two 64-bit numbers\n //Like the original implementation, does not rely on 32-bit operations\n\n function int64add(dst, x, y) {\n var w0 = (x.l & 0xffff) + (y.l & 0xffff);\n var w1 = (x.l >>> 16) + (y.l >>> 16) + (w0 >>> 16);\n var w2 = (x.h & 0xffff) + (y.h & 0xffff) + (w1 >>> 16);\n var w3 = (x.h >>> 16) + (y.h >>> 16) + (w2 >>> 16);\n dst.l = (w0 & 0xffff) | (w1 << 16);\n dst.h = (w2 & 0xffff) | (w3 << 16);\n }\n\n //Same, except with 4 addends. Works faster than adding them one by one.\n\n function int64add4(dst, a, b, c, d) {\n var w0 = (a.l & 0xffff) + (b.l & 0xffff) + (c.l & 0xffff) + (d.l & 0xffff);\n var w1 = (a.l >>> 16) + (b.l >>> 16) + (c.l >>> 16) + (d.l >>> 16) + (w0 >>> 16);\n var w2 = (a.h & 0xffff) + (b.h & 0xffff) + (c.h & 0xffff) + (d.h & 0xffff) + (w1 >>> 16);\n var w3 = (a.h >>> 16) + (b.h >>> 16) + (c.h >>> 16) + (d.h >>> 16) + (w2 >>> 16);\n dst.l = (w0 & 0xffff) | (w1 << 16);\n dst.h = (w2 & 0xffff) | (w3 << 16);\n }\n\n //Same, except with 5 addends\n\n function int64add5(dst, a, b, c, d, e) {\n var w0 = (a.l & 0xffff) + (b.l & 0xffff) + (c.l & 0xffff) + (d.l & 0xffff) + (e.l & 0xffff),\n w1 = (a.l >>> 16) + (b.l >>> 16) + (c.l >>> 16) + (d.l >>> 16) + (e.l >>> 16) + (w0 >>> 16),\n w2 = (a.h & 0xffff) + (b.h & 0xffff) + (c.h & 0xffff) + (d.h & 0xffff) + (e.h & 0xffff) + (w1 >>> 16),\n w3 = (a.h >>> 16) + (b.h >>> 16) + (c.h >>> 16) + (d.h >>> 16) + (e.h >>> 16) + (w2 >>> 16);\n dst.l = (w0 & 0xffff) | (w1 << 16);\n dst.h = (w2 & 0xffff) | (w3 << 16);\n }\n },\n /**\n * @class Hashes.RMD160\n * @constructor\n * @param {Object} [config]\n *\n * A JavaScript implementation of the RIPEMD-160 Algorithm\n * Version 2.2 Copyright Jeremy Lin, Paul Johnston 2000 - 2009.\n * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet\n * See http://pajhome.org.uk/crypt/md5 for details.\n * Also http://www.ocf.berkeley.edu/~jjlin/jsotp/\n */\n RMD160: function(options) {\n /**\n * Private properties configuration variables. You may need to tweak these to be compatible with\n * the server-side, but the defaults work in most cases.\n * @see this.setUpperCase() method\n * @see this.setPad() method\n */\n var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false,\n /* hexadecimal output case format. false - lowercase; true - uppercase */\n b64pad = (options && typeof options.pad === 'string') ? options.pa : '=',\n /* base-64 pad character. Default '=' for strict RFC compliance */\n utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true,\n /* enable/disable utf8 encoding */\n rmd160_r1 = [\n 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,\n 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,\n 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,\n 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,\n 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13\n ],\n rmd160_r2 = [\n 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,\n 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,\n 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,\n 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,\n 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11\n ],\n rmd160_s1 = [\n 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,\n 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,\n 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,\n 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,\n 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6\n ],\n rmd160_s2 = [\n 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,\n 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,\n 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,\n 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,\n 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11\n ];\n\n /* privileged (public) methods */\n this.hex = function(s) {\n return rstr2hex(rstr(s, utf8));\n };\n this.b64 = function(s) {\n return rstr2b64(rstr(s, utf8), b64pad);\n };\n this.any = function(s, e) {\n return rstr2any(rstr(s, utf8), e);\n };\n this.raw = function(s) {\n return rstr(s, utf8);\n };\n this.hex_hmac = function(k, d) {\n return rstr2hex(rstr_hmac(k, d));\n };\n this.b64_hmac = function(k, d) {\n return rstr2b64(rstr_hmac(k, d), b64pad);\n };\n this.any_hmac = function(k, d, e) {\n return rstr2any(rstr_hmac(k, d), e);\n };\n /**\n * Perform a simple self-test to see if the VM is working\n * @return {String} Hexadecimal hash sample\n * @public\n */\n this.vm_test = function() {\n return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';\n };\n /**\n * @description Enable/disable uppercase hexadecimal returned string\n * @param {boolean}\n * @return {Object} this\n * @public\n */\n this.setUpperCase = function(a) {\n if (typeof a === 'boolean') {\n hexcase = a;\n }\n return this;\n };\n /**\n * @description Defines a base64 pad string\n * @param {string} Pad\n * @return {Object} this\n * @public\n */\n this.setPad = function(a) {\n if (typeof a !== 'undefined') {\n b64pad = a;\n }\n return this;\n };\n /**\n * @description Defines a base64 pad string\n * @param {boolean}\n * @return {Object} this\n * @public\n */\n this.setUTF8 = function(a) {\n if (typeof a === 'boolean') {\n utf8 = a;\n }\n return this;\n };\n\n /* private methods */\n\n /**\n * Calculate the rmd160 of a raw string\n */\n\n function rstr(s) {\n s = (utf8) ? utf8Encode(s) : s;\n return binl2rstr(binl(rstr2binl(s), s.length * 8));\n }\n\n /**\n * Calculate the HMAC-rmd160 of a key and some data (raw strings)\n */\n\n function rstr_hmac(key, data) {\n key = (utf8) ? utf8Encode(key) : key;\n data = (utf8) ? utf8Encode(data) : data;\n var i, hash,\n bkey = rstr2binl(key),\n ipad = Array(16),\n opad = Array(16);\n\n if (bkey.length > 16) {\n bkey = binl(bkey, key.length * 8);\n }\n\n for (i = 0; i < 16; i += 1) {\n ipad[i] = bkey[i] ^ 0x36363636;\n opad[i] = bkey[i] ^ 0x5C5C5C5C;\n }\n hash = binl(ipad.concat(rstr2binl(data)), 512 + data.length * 8);\n return binl2rstr(binl(opad.concat(hash), 512 + 160));\n }\n\n /**\n * Convert an array of little-endian words to a string\n */\n\n function binl2rstr(input) {\n var i, output = '',\n l = input.length * 32;\n for (i = 0; i < l; i += 8) {\n output += String.fromCharCode((input[i >> 5] >>> (i % 32)) & 0xFF);\n }\n return output;\n }\n\n /**\n * Calculate the RIPE-MD160 of an array of little-endian words, and a bit length.\n */\n\n function binl(x, len) {\n var T, j, i, l,\n h0 = 0x67452301,\n h1 = 0xefcdab89,\n h2 = 0x98badcfe,\n h3 = 0x10325476,\n h4 = 0xc3d2e1f0,\n A1, B1, C1, D1, E1,\n A2, B2, C2, D2, E2;\n\n /* append padding */\n x[len >> 5] |= 0x80 << (len % 32);\n x[(((len + 64) >>> 9) << 4) + 14] = len;\n l = x.length;\n\n for (i = 0; i < l; i += 16) {\n A1 = A2 = h0;\n B1 = B2 = h1;\n C1 = C2 = h2;\n D1 = D2 = h3;\n E1 = E2 = h4;\n for (j = 0; j <= 79; j += 1) {\n T = safe_add(A1, rmd160_f(j, B1, C1, D1));\n T = safe_add(T, x[i + rmd160_r1[j]]);\n T = safe_add(T, rmd160_K1(j));\n T = safe_add(bit_rol(T, rmd160_s1[j]), E1);\n A1 = E1;\n E1 = D1;\n D1 = bit_rol(C1, 10);\n C1 = B1;\n B1 = T;\n T = safe_add(A2, rmd160_f(79 - j, B2, C2, D2));\n T = safe_add(T, x[i + rmd160_r2[j]]);\n T = safe_add(T, rmd160_K2(j));\n T = safe_add(bit_rol(T, rmd160_s2[j]), E2);\n A2 = E2;\n E2 = D2;\n D2 = bit_rol(C2, 10);\n C2 = B2;\n B2 = T;\n }\n\n T = safe_add(h1, safe_add(C1, D2));\n h1 = safe_add(h2, safe_add(D1, E2));\n h2 = safe_add(h3, safe_add(E1, A2));\n h3 = safe_add(h4, safe_add(A1, B2));\n h4 = safe_add(h0, safe_add(B1, C2));\n h0 = T;\n }\n return [h0, h1, h2, h3, h4];\n }\n\n // specific algorithm methods\n\n function rmd160_f(j, x, y, z) {\n return (0 <= j && j <= 15) ? (x ^ y ^ z) :\n (16 <= j && j <= 31) ? (x & y) | (~x & z) :\n (32 <= j && j <= 47) ? (x | ~y) ^ z :\n (48 <= j && j <= 63) ? (x & z) | (y & ~z) :\n (64 <= j && j <= 79) ? x ^ (y | ~z) :\n 'rmd160_f: j out of range';\n }\n\n function rmd160_K1(j) {\n return (0 <= j && j <= 15) ? 0x00000000 :\n (16 <= j && j <= 31) ? 0x5a827999 :\n (32 <= j && j <= 47) ? 0x6ed9eba1 :\n (48 <= j && j <= 63) ? 0x8f1bbcdc :\n (64 <= j && j <= 79) ? 0xa953fd4e :\n 'rmd160_K1: j out of range';\n }\n\n function rmd160_K2(j) {\n return (0 <= j && j <= 15) ? 0x50a28be6 :\n (16 <= j && j <= 31) ? 0x5c4dd124 :\n (32 <= j && j <= 47) ? 0x6d703ef3 :\n (48 <= j && j <= 63) ? 0x7a6d76e9 :\n (64 <= j && j <= 79) ? 0x00000000 :\n 'rmd160_K2: j out of range';\n }\n }\n };\n\n // exposes Hashes\n (function(window, undefined) {\n var freeExports = false;\n if (typeof exports === 'object') {\n freeExports = exports;\n if (exports && typeof global === 'object' && global && global === global.global) {\n window = global;\n }\n }\n\n if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {\n // define as an anonymous module, so, through path mapping, it can be aliased\n define(function() {\n return Hashes;\n });\n } else if (freeExports) {\n // in Node.js or RingoJS v0.8.0+\n if (typeof module === 'object' && module && module.exports === freeExports) {\n module.exports = Hashes;\n }\n // in Narwhal or RingoJS v0.7.0-\n else {\n freeExports.Hashes = Hashes;\n }\n } else {\n // in a browser or Rhino\n window.Hashes = Hashes;\n }\n }(this));\n}()); // IIFE\n","module.exports = extend\n\nvar hasOwnProperty = Object.prototype.hasOwnProperty;\n\nfunction extend() {\n var target = {}\n\n for (var i = 0; i < arguments.length; i++) {\n var source = arguments[i]\n\n for (var key in source) {\n if (hasOwnProperty.call(source, key)) {\n target[key] = source[key]\n }\n }\n }\n\n return target\n}\n","'use strict';\n\nvar hashes = require('jshashes'),\n xtend = require('xtend'),\n sha1 = new hashes.SHA1();\n\nvar ohauth = {};\n\nohauth.qsString = function(obj) {\n return Object.keys(obj).sort().map(function(key) {\n return ohauth.percentEncode(key) + '=' +\n ohauth.percentEncode(obj[key]);\n }).join('&');\n};\n\nohauth.stringQs = function(str) {\n return str.split('&').filter(function (pair) {\n return pair !== '';\n }).reduce(function(obj, pair){\n var parts = pair.split('=');\n obj[decodeURIComponent(parts[0])] = (null === parts[1]) ?\n '' : decodeURIComponent(parts[1]);\n return obj;\n }, {});\n};\n\nohauth.rawxhr = function(method, url, data, headers, callback) {\n var xhr = new XMLHttpRequest(),\n twoHundred = /^20\\d$/;\n xhr.onreadystatechange = function() {\n if (4 === xhr.readyState && 0 !== xhr.status) {\n if (twoHundred.test(xhr.status)) callback(null, xhr);\n else return callback(xhr, null);\n }\n };\n xhr.onerror = function(e) { return callback(e, null); };\n xhr.open(method, url, true);\n for (var h in headers) xhr.setRequestHeader(h, headers[h]);\n xhr.send(data);\n return xhr;\n};\n\nohauth.xhr = function(method, url, auth, data, options, callback) {\n var headers = (options && options.header) || {\n 'Content-Type': 'application/x-www-form-urlencoded'\n };\n headers.Authorization = 'OAuth ' + ohauth.authHeader(auth);\n return ohauth.rawxhr(method, url, data, headers, callback);\n};\n\nohauth.nonce = function() {\n for (var o = ''; o.length < 6;) {\n o += '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'[Math.floor(Math.random() * 61)];\n }\n return o;\n};\n\nohauth.authHeader = function(obj) {\n return Object.keys(obj).sort().map(function(key) {\n return encodeURIComponent(key) + '=\"' + encodeURIComponent(obj[key]) + '\"';\n }).join(', ');\n};\n\nohauth.timestamp = function() { return ~~((+new Date()) / 1000); };\n\nohauth.percentEncode = function(s) {\n return encodeURIComponent(s)\n .replace(/\\!/g, '%21').replace(/\\'/g, '%27')\n .replace(/\\*/g, '%2A').replace(/\\(/g, '%28').replace(/\\)/g, '%29');\n};\n\nohauth.baseString = function(method, url, params) {\n if (params.oauth_signature) delete params.oauth_signature;\n return [\n method,\n ohauth.percentEncode(url),\n ohauth.percentEncode(ohauth.qsString(params))].join('&');\n};\n\nohauth.signature = function(oauth_secret, token_secret, baseString) {\n return sha1.b64_hmac(\n ohauth.percentEncode(oauth_secret) + '&' +\n ohauth.percentEncode(token_secret),\n baseString);\n};\n\n/**\n * Takes an options object for configuration (consumer_key,\n * consumer_secret, version, signature_method, token, token_secret)\n * and returns a function that generates the Authorization header\n * for given data.\n *\n * The returned function takes these parameters:\n * - method: GET/POST/...\n * - uri: full URI with protocol, port, path and query string\n * - extra_params: any extra parameters (that are passed in the POST data),\n * can be an object or a from-urlencoded string.\n *\n * Returned function returns full OAuth header with \"OAuth\" string in it.\n */\n\nohauth.headerGenerator = function(options) {\n options = options || {};\n var consumer_key = options.consumer_key || '',\n consumer_secret = options.consumer_secret || '',\n signature_method = options.signature_method || 'HMAC-SHA1',\n version = options.version || '1.0',\n token = options.token || '',\n token_secret = options.token_secret || '';\n\n return function(method, uri, extra_params) {\n method = method.toUpperCase();\n if (typeof extra_params === 'string' && extra_params.length > 0) {\n extra_params = ohauth.stringQs(extra_params);\n }\n\n var uri_parts = uri.split('?', 2),\n base_uri = uri_parts[0];\n\n var query_params = uri_parts.length === 2 ?\n ohauth.stringQs(uri_parts[1]) : {};\n\n var oauth_params = {\n oauth_consumer_key: consumer_key,\n oauth_signature_method: signature_method,\n oauth_version: version,\n oauth_timestamp: ohauth.timestamp(),\n oauth_nonce: ohauth.nonce()\n };\n\n if (token) oauth_params.oauth_token = token;\n\n var all_params = xtend({}, oauth_params, query_params, extra_params),\n base_str = ohauth.baseString(method, base_uri, all_params);\n\n oauth_params.oauth_signature = ohauth.signature(consumer_secret, token_secret, base_str);\n\n return 'OAuth ' + ohauth.authHeader(oauth_params);\n };\n};\n\nmodule.exports = ohauth;\n","// Copyright 2014 Simon Lydell\r\n// X11 (“MIT”) Licensed. (See LICENSE.)\r\n\r\nvoid (function(root, factory) {\r\n if (typeof define === \"function\" && define.amd) {\r\n define(factory)\r\n } else if (typeof exports === \"object\") {\r\n module.exports = factory()\r\n } else {\r\n root.resolveUrl = factory()\r\n }\r\n}(this, function() {\r\n\r\n function resolveUrl(/* ...urls */) {\r\n var numUrls = arguments.length\r\n\r\n if (numUrls === 0) {\r\n throw new Error(\"resolveUrl requires at least one argument; got none.\")\r\n }\r\n\r\n var base = document.createElement(\"base\")\r\n base.href = arguments[0]\r\n\r\n if (numUrls === 1) {\r\n return base.href\r\n }\r\n\r\n var head = document.getElementsByTagName(\"head\")[0]\r\n head.insertBefore(base, head.firstChild)\r\n\r\n var a = document.createElement(\"a\")\r\n var resolved\r\n\r\n for (var index = 1; index < numUrls; index++) {\r\n a.href = arguments[index]\r\n resolved = a.href\r\n base.href = resolved\r\n }\r\n\r\n head.removeChild(base)\r\n\r\n return resolved\r\n }\r\n\r\n return resolveUrl\r\n\r\n}));\r\n","var assign = make_assign()\nvar create = make_create()\nvar trim = make_trim()\nvar Global = (typeof window !== 'undefined' ? window : global)\n\nmodule.exports = {\n\tassign: assign,\n\tcreate: create,\n\ttrim: trim,\n\tbind: bind,\n\tslice: slice,\n\teach: each,\n\tmap: map,\n\tpluck: pluck,\n\tisList: isList,\n\tisFunction: isFunction,\n\tisObject: isObject,\n\tGlobal: Global\n}\n\nfunction make_assign() {\n\tif (Object.assign) {\n\t\treturn Object.assign\n\t} else {\n\t\treturn function shimAssign(obj, props1, props2, etc) {\n\t\t\tfor (var i = 1; i < arguments.length; i++) {\n\t\t\t\teach(Object(arguments[i]), function(val, key) {\n\t\t\t\t\tobj[key] = val\n\t\t\t\t})\n\t\t\t}\t\t\t\n\t\t\treturn obj\n\t\t}\n\t}\n}\n\nfunction make_create() {\n\tif (Object.create) {\n\t\treturn function create(obj, assignProps1, assignProps2, etc) {\n\t\t\tvar assignArgsList = slice(arguments, 1)\n\t\t\treturn assign.apply(this, [Object.create(obj)].concat(assignArgsList))\n\t\t}\n\t} else {\n\t\tfunction F() {} // eslint-disable-line no-inner-declarations\n\t\treturn function create(obj, assignProps1, assignProps2, etc) {\n\t\t\tvar assignArgsList = slice(arguments, 1)\n\t\t\tF.prototype = obj\n\t\t\treturn assign.apply(this, [new F()].concat(assignArgsList))\n\t\t}\n\t}\n}\n\nfunction make_trim() {\n\tif (String.prototype.trim) {\n\t\treturn function trim(str) {\n\t\t\treturn String.prototype.trim.call(str)\n\t\t}\n\t} else {\n\t\treturn function trim(str) {\n\t\t\treturn str.replace(/^[\\s\\uFEFF\\xA0]+|[\\s\\uFEFF\\xA0]+$/g, '')\n\t\t}\n\t}\n}\n\nfunction bind(obj, fn) {\n\treturn function() {\n\t\treturn fn.apply(obj, Array.prototype.slice.call(arguments, 0))\n\t}\n}\n\nfunction slice(arr, index) {\n\treturn Array.prototype.slice.call(arr, index || 0)\n}\n\nfunction each(obj, fn) {\n\tpluck(obj, function(val, key) {\n\t\tfn(val, key)\n\t\treturn false\n\t})\n}\n\nfunction map(obj, fn) {\n\tvar res = (isList(obj) ? [] : {})\n\tpluck(obj, function(v, k) {\n\t\tres[k] = fn(v, k)\n\t\treturn false\n\t})\n\treturn res\n}\n\nfunction pluck(obj, fn) {\n\tif (isList(obj)) {\n\t\tfor (var i=0; i= 0; i--) {\n\t\tvar key = localStorage().key(i)\n\t\tfn(read(key), key)\n\t}\n}\n\nfunction remove(key) {\n\treturn localStorage().removeItem(key)\n}\n\nfunction clearAll() {\n\treturn localStorage().clear()\n}\n","// oldFF-globalStorage provides storage for Firefox\n// versions 6 and 7, where no localStorage, etc\n// is available.\n\nvar util = require('../src/util')\nvar Global = util.Global\n\nmodule.exports = {\n\tname: 'oldFF-globalStorage',\n\tread: read,\n\twrite: write,\n\teach: each,\n\tremove: remove,\n\tclearAll: clearAll,\n}\n\nvar globalStorage = Global.globalStorage\n\nfunction read(key) {\n\treturn globalStorage[key]\n}\n\nfunction write(key, data) {\n\tglobalStorage[key] = data\n}\n\nfunction each(fn) {\n\tfor (var i = globalStorage.length - 1; i >= 0; i--) {\n\t\tvar key = globalStorage.key(i)\n\t\tfn(globalStorage[key], key)\n\t}\n}\n\nfunction remove(key) {\n\treturn globalStorage.removeItem(key)\n}\n\nfunction clearAll() {\n\teach(function(key, _) {\n\t\tdelete globalStorage[key]\n\t})\n}\n","// oldIE-userDataStorage provides storage for Internet Explorer\n// versions 6 and 7, where no localStorage, sessionStorage, etc\n// is available.\n\nvar util = require('../src/util')\nvar Global = util.Global\n\nmodule.exports = {\n\tname: 'oldIE-userDataStorage',\n\twrite: write,\n\tread: read,\n\teach: each,\n\tremove: remove,\n\tclearAll: clearAll,\n}\n\nvar storageName = 'storejs'\nvar doc = Global.document\nvar _withStorageEl = _makeIEStorageElFunction()\nvar disable = (Global.navigator ? Global.navigator.userAgent : '').match(/ (MSIE 8|MSIE 9|MSIE 10)\\./) // MSIE 9.x, MSIE 10.x\n\nfunction write(unfixedKey, data) {\n\tif (disable) { return }\n\tvar fixedKey = fixKey(unfixedKey)\n\t_withStorageEl(function(storageEl) {\n\t\tstorageEl.setAttribute(fixedKey, data)\n\t\tstorageEl.save(storageName)\n\t})\n}\n\nfunction read(unfixedKey) {\n\tif (disable) { return }\n\tvar fixedKey = fixKey(unfixedKey)\n\tvar res = null\n\t_withStorageEl(function(storageEl) {\n\t\tres = storageEl.getAttribute(fixedKey)\n\t})\n\treturn res\n}\n\nfunction each(callback) {\n\t_withStorageEl(function(storageEl) {\n\t\tvar attributes = storageEl.XMLDocument.documentElement.attributes\n\t\tfor (var i=attributes.length-1; i>=0; i--) {\n\t\t\tvar attr = attributes[i]\n\t\t\tcallback(storageEl.getAttribute(attr.name), attr.name)\n\t\t}\n\t})\n}\n\nfunction remove(unfixedKey) {\n\tvar fixedKey = fixKey(unfixedKey)\n\t_withStorageEl(function(storageEl) {\n\t\tstorageEl.removeAttribute(fixedKey)\n\t\tstorageEl.save(storageName)\n\t})\n}\n\nfunction clearAll() {\n\t_withStorageEl(function(storageEl) {\n\t\tvar attributes = storageEl.XMLDocument.documentElement.attributes\n\t\tstorageEl.load(storageName)\n\t\tfor (var i=attributes.length-1; i>=0; i--) {\n\t\t\tstorageEl.removeAttribute(attributes[i].name)\n\t\t}\n\t\tstorageEl.save(storageName)\n\t})\n}\n\n// Helpers\n//////////\n\n// In IE7, keys cannot start with a digit or contain certain chars.\n// See https://github.com/marcuswestin/store.js/issues/40\n// See https://github.com/marcuswestin/store.js/issues/83\nvar forbiddenCharsRegex = new RegExp(\"[!\\\"#$%&'()*+,/\\\\\\\\:;<=>?@[\\\\]^`{|}~]\", \"g\")\nfunction fixKey(key) {\n\treturn key.replace(/^\\d/, '___$&').replace(forbiddenCharsRegex, '___')\n}\n\nfunction _makeIEStorageElFunction() {\n\tif (!doc || !doc.documentElement || !doc.documentElement.addBehavior) {\n\t\treturn null\n\t}\n\tvar scriptTag = 'script',\n\t\tstorageOwner,\n\t\tstorageContainer,\n\t\tstorageEl\n\n\t// Since #userData storage applies only to specific paths, we need to\n\t// somehow link our data to a specific path. We choose /favicon.ico\n\t// as a pretty safe option, since all browsers already make a request to\n\t// this URL anyway and being a 404 will not hurt us here. We wrap an\n\t// iframe pointing to the favicon in an ActiveXObject(htmlfile) object\n\t// (see: http://msdn.microsoft.com/en-us/library/aa752574(v=VS.85).aspx)\n\t// since the iframe access rules appear to allow direct access and\n\t// manipulation of the document element, even for a 404 page. This\n\t// document can be used instead of the current document (which would\n\t// have been limited to the current path) to perform #userData storage.\n\ttry {\n\t\t/* global ActiveXObject */\n\t\tstorageContainer = new ActiveXObject('htmlfile')\n\t\tstorageContainer.open()\n\t\tstorageContainer.write('<'+scriptTag+'>document.w=window'+scriptTag+'>')\n\t\tstorageContainer.close()\n\t\tstorageOwner = storageContainer.w.frames[0].document\n\t\tstorageEl = storageOwner.createElement('div')\n\t} catch(e) {\n\t\t// somehow ActiveXObject instantiation failed (perhaps some special\n\t\t// security settings or otherwse), fall back to per-path storage\n\t\tstorageEl = doc.createElement('div')\n\t\tstorageOwner = doc.body\n\t}\n\n\treturn function(storeFunction) {\n\t\tvar args = [].slice.call(arguments, 0)\n\t\targs.unshift(storageEl)\n\t\t// See http://msdn.microsoft.com/en-us/library/ms531081(v=VS.85).aspx\n\t\t// and http://msdn.microsoft.com/en-us/library/ms531424(v=VS.85).aspx\n\t\tstorageOwner.appendChild(storageEl)\n\t\tstorageEl.addBehavior('#default#userData')\n\t\tstorageEl.load(storageName)\n\t\tstoreFunction.apply(this, args)\n\t\tstorageOwner.removeChild(storageEl)\n\t\treturn\n\t}\n}\n","// cookieStorage is useful Safari private browser mode, where localStorage\n// doesn't work but cookies do. This implementation is adopted from\n// https://developer.mozilla.org/en-US/docs/Web/API/Storage/LocalStorage\n\nvar util = require('../src/util')\nvar Global = util.Global\nvar trim = util.trim\n\nmodule.exports = {\n\tname: 'cookieStorage',\n\tread: read,\n\twrite: write,\n\teach: each,\n\tremove: remove,\n\tclearAll: clearAll,\n}\n\nvar doc = Global.document\n\nfunction read(key) {\n\tif (!key || !_has(key)) { return null }\n\tvar regexpStr = \"(?:^|.*;\\\\s*)\" +\n\t\tescape(key).replace(/[\\-\\.\\+\\*]/g, \"\\\\$&\") +\n\t\t\"\\\\s*\\\\=\\\\s*((?:[^;](?!;))*[^;]?).*\"\n\treturn unescape(doc.cookie.replace(new RegExp(regexpStr), \"$1\"))\n}\n\nfunction each(callback) {\n\tvar cookies = doc.cookie.split(/; ?/g)\n\tfor (var i = cookies.length - 1; i >= 0; i--) {\n\t\tif (!trim(cookies[i])) {\n\t\t\tcontinue\n\t\t}\n\t\tvar kvp = cookies[i].split('=')\n\t\tvar key = unescape(kvp[0])\n\t\tvar val = unescape(kvp[1])\n\t\tcallback(val, key)\n\t}\n}\n\nfunction write(key, data) {\n\tif(!key) { return }\n\tdoc.cookie = escape(key) + \"=\" + escape(data) + \"; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/\"\n}\n\nfunction remove(key) {\n\tif (!key || !_has(key)) {\n\t\treturn\n\t}\n\tdoc.cookie = escape(key) + \"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/\"\n}\n\nfunction clearAll() {\n\teach(function(_, key) {\n\t\tremove(key)\n\t})\n}\n\nfunction _has(key) {\n\treturn (new RegExp(\"(?:^|;\\\\s*)\" + escape(key).replace(/[\\-\\.\\+\\*]/g, \"\\\\$&\") + \"\\\\s*\\\\=\")).test(doc.cookie)\n}\n","var util = require('../src/util')\nvar Global = util.Global\n\nmodule.exports = {\n\tname: 'sessionStorage',\n\tread: read,\n\twrite: write,\n\teach: each,\n\tremove: remove,\n\tclearAll: clearAll\n}\n\nfunction sessionStorage() {\n\treturn Global.sessionStorage\n}\n\nfunction read(key) {\n\treturn sessionStorage().getItem(key)\n}\n\nfunction write(key, data) {\n\treturn sessionStorage().setItem(key, data)\n}\n\nfunction each(fn) {\n\tfor (var i = sessionStorage().length - 1; i >= 0; i--) {\n\t\tvar key = sessionStorage().key(i)\n\t\tfn(read(key), key)\n\t}\n}\n\nfunction remove(key) {\n\treturn sessionStorage().removeItem(key)\n}\n\nfunction clearAll() {\n\treturn sessionStorage().clear()\n}\n","// memoryStorage is a useful last fallback to ensure that the store\n// is functions (meaning store.get(), store.set(), etc will all function).\n// However, stored values will not persist when the browser navigates to\n// a new page or reloads the current page.\n\nmodule.exports = {\n\tname: 'memoryStorage',\n\tread: read,\n\twrite: write,\n\teach: each,\n\tremove: remove,\n\tclearAll: clearAll,\n}\n\nvar memoryStorage = {}\n\nfunction read(key) {\n\treturn memoryStorage[key]\n}\n\nfunction write(key, data) {\n\tmemoryStorage[key] = data\n}\n\nfunction each(callback) {\n\tfor (var key in memoryStorage) {\n\t\tif (memoryStorage.hasOwnProperty(key)) {\n\t\t\tcallback(memoryStorage[key], key)\n\t\t}\n\t}\n}\n\nfunction remove(key) {\n\tdelete memoryStorage[key]\n}\n\nfunction clearAll(key) {\n\tmemoryStorage = {}\n}\n","module.exports = [\n\t// Listed in order of usage preference\n\trequire('./localStorage'),\n\trequire('./oldFF-globalStorage'),\n\trequire('./oldIE-userDataStorage'),\n\trequire('./cookieStorage'),\n\trequire('./sessionStorage'),\n\trequire('./memoryStorage')\n]\n","/* eslint-disable */\n\n// json2.js\n// 2016-10-28\n// Public Domain.\n// NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n// See http://www.JSON.org/js.html\n// This code should be minified before deployment.\n// See http://javascript.crockford.com/jsmin.html\n\n// USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO\n// NOT CONTROL.\n\n// This file creates a global JSON object containing two methods: stringify\n// and parse. This file provides the ES5 JSON capability to ES3 systems.\n// If a project might run on IE8 or earlier, then this file should be included.\n// This file does nothing on ES5 systems.\n\n// JSON.stringify(value, replacer, space)\n// value any JavaScript value, usually an object or array.\n// replacer an optional parameter that determines how object\n// values are stringified for objects. It can be a\n// function or an array of strings.\n// space an optional parameter that specifies the indentation\n// of nested structures. If it is omitted, the text will\n// be packed without extra whitespace. If it is a number,\n// it will specify the number of spaces to indent at each\n// level. If it is a string (such as \"\\t\" or \" \"),\n// it contains the characters used to indent at each level.\n// This method produces a JSON text from a JavaScript value.\n// When an object value is found, if the object contains a toJSON\n// method, its toJSON method will be called and the result will be\n// stringified. A toJSON method does not serialize: it returns the\n// value represented by the name/value pair that should be serialized,\n// or undefined if nothing should be serialized. The toJSON method\n// will be passed the key associated with the value, and this will be\n// bound to the value.\n\n// For example, this would serialize Dates as ISO strings.\n\n// Date.prototype.toJSON = function (key) {\n// function f(n) {\n// // Format integers to have at least two digits.\n// return (n < 10)\n// ? \"0\" + n\n// : n;\n// }\n// return this.getUTCFullYear() + \"-\" +\n// f(this.getUTCMonth() + 1) + \"-\" +\n// f(this.getUTCDate()) + \"T\" +\n// f(this.getUTCHours()) + \":\" +\n// f(this.getUTCMinutes()) + \":\" +\n// f(this.getUTCSeconds()) + \"Z\";\n// };\n\n// You can provide an optional replacer method. It will be passed the\n// key and value of each member, with this bound to the containing\n// object. The value that is returned from your method will be\n// serialized. If your method returns undefined, then the member will\n// be excluded from the serialization.\n\n// If the replacer parameter is an array of strings, then it will be\n// used to select the members to be serialized. It filters the results\n// such that only members with keys listed in the replacer array are\n// stringified.\n\n// Values that do not have JSON representations, such as undefined or\n// functions, will not be serialized. Such values in objects will be\n// dropped; in arrays they will be replaced with null. You can use\n// a replacer function to replace those with JSON values.\n\n// JSON.stringify(undefined) returns undefined.\n\n// The optional space parameter produces a stringification of the\n// value that is filled with line breaks and indentation to make it\n// easier to read.\n\n// If the space parameter is a non-empty string, then that string will\n// be used for indentation. If the space parameter is a number, then\n// the indentation will be that many spaces.\n\n// Example:\n\n// text = JSON.stringify([\"e\", {pluribus: \"unum\"}]);\n// // text is '[\"e\",{\"pluribus\":\"unum\"}]'\n\n// text = JSON.stringify([\"e\", {pluribus: \"unum\"}], null, \"\\t\");\n// // text is '[\\n\\t\"e\",\\n\\t{\\n\\t\\t\"pluribus\": \"unum\"\\n\\t}\\n]'\n\n// text = JSON.stringify([new Date()], function (key, value) {\n// return this[key] instanceof Date\n// ? \"Date(\" + this[key] + \")\"\n// : value;\n// });\n// // text is '[\"Date(---current time---)\"]'\n\n// JSON.parse(text, reviver)\n// This method parses a JSON text to produce an object or array.\n// It can throw a SyntaxError exception.\n\n// The optional reviver parameter is a function that can filter and\n// transform the results. It receives each of the keys and values,\n// and its return value is used instead of the original value.\n// If it returns what it received, then the structure is not modified.\n// If it returns undefined then the member is deleted.\n\n// Example:\n\n// // Parse the text. Values that look like ISO date strings will\n// // be converted to Date objects.\n\n// myData = JSON.parse(text, function (key, value) {\n// var a;\n// if (typeof value === \"string\") {\n// a =\n// /^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2}(?:\\.\\d*)?)Z$/.exec(value);\n// if (a) {\n// return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],\n// +a[5], +a[6]));\n// }\n// }\n// return value;\n// });\n\n// myData = JSON.parse('[\"Date(09/09/2001)\"]', function (key, value) {\n// var d;\n// if (typeof value === \"string\" &&\n// value.slice(0, 5) === \"Date(\" &&\n// value.slice(-1) === \")\") {\n// d = new Date(value.slice(5, -1));\n// if (d) {\n// return d;\n// }\n// }\n// return value;\n// });\n\n// This is a reference implementation. You are free to copy, modify, or\n// redistribute.\n\n/*jslint\n eval, for, this\n*/\n\n/*property\n JSON, apply, call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,\n getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,\n lastIndex, length, parse, prototype, push, replace, slice, stringify,\n test, toJSON, toString, valueOf\n*/\n\n\n// Create a JSON object only if one does not already exist. We create the\n// methods in a closure to avoid creating global variables.\n\nif (typeof JSON !== \"object\") {\n JSON = {};\n}\n\n(function () {\n \"use strict\";\n\n var rx_one = /^[\\],:{}\\s]*$/;\n var rx_two = /\\\\(?:[\"\\\\\\/bfnrt]|u[0-9a-fA-F]{4})/g;\n var rx_three = /\"[^\"\\\\\\n\\r]*\"|true|false|null|-?\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d+)?/g;\n var rx_four = /(?:^|:|,)(?:\\s*\\[)+/g;\n var rx_escapable = /[\\\\\"\\u0000-\\u001f\\u007f-\\u009f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g;\n var rx_dangerous = /[\\u0000\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g;\n\n function f(n) {\n // Format integers to have at least two digits.\n return n < 10\n ? \"0\" + n\n : n;\n }\n\n function this_value() {\n return this.valueOf();\n }\n\n if (typeof Date.prototype.toJSON !== \"function\") {\n\n Date.prototype.toJSON = function () {\n\n return isFinite(this.valueOf())\n ? this.getUTCFullYear() + \"-\" +\n f(this.getUTCMonth() + 1) + \"-\" +\n f(this.getUTCDate()) + \"T\" +\n f(this.getUTCHours()) + \":\" +\n f(this.getUTCMinutes()) + \":\" +\n f(this.getUTCSeconds()) + \"Z\"\n : null;\n };\n\n Boolean.prototype.toJSON = this_value;\n Number.prototype.toJSON = this_value;\n String.prototype.toJSON = this_value;\n }\n\n var gap;\n var indent;\n var meta;\n var rep;\n\n\n function quote(string) {\n\n// If the string contains no control characters, no quote characters, and no\n// backslash characters, then we can safely slap some quotes around it.\n// Otherwise we must also replace the offending characters with safe escape\n// sequences.\n\n rx_escapable.lastIndex = 0;\n return rx_escapable.test(string)\n ? \"\\\"\" + string.replace(rx_escapable, function (a) {\n var c = meta[a];\n return typeof c === \"string\"\n ? c\n : \"\\\\u\" + (\"0000\" + a.charCodeAt(0).toString(16)).slice(-4);\n }) + \"\\\"\"\n : \"\\\"\" + string + \"\\\"\";\n }\n\n\n function str(key, holder) {\n\n// Produce a string from holder[key].\n\n var i; // The loop counter.\n var k; // The member key.\n var v; // The member value.\n var length;\n var mind = gap;\n var partial;\n var value = holder[key];\n\n// If the value has a toJSON method, call it to obtain a replacement value.\n\n if (value && typeof value === \"object\" &&\n typeof value.toJSON === \"function\") {\n value = value.toJSON(key);\n }\n\n// If we were called with a replacer function, then call the replacer to\n// obtain a replacement value.\n\n if (typeof rep === \"function\") {\n value = rep.call(holder, key, value);\n }\n\n// What happens next depends on the value's type.\n\n switch (typeof value) {\n case \"string\":\n return quote(value);\n\n case \"number\":\n\n// JSON numbers must be finite. Encode non-finite numbers as null.\n\n return isFinite(value)\n ? String(value)\n : \"null\";\n\n case \"boolean\":\n case \"null\":\n\n// If the value is a boolean or null, convert it to a string. Note:\n// typeof null does not produce \"null\". The case is included here in\n// the remote chance that this gets fixed someday.\n\n return String(value);\n\n// If the type is \"object\", we might be dealing with an object or an array or\n// null.\n\n case \"object\":\n\n// Due to a specification blunder in ECMAScript, typeof null is \"object\",\n// so watch out for that case.\n\n if (!value) {\n return \"null\";\n }\n\n// Make an array to hold the partial results of stringifying this object value.\n\n gap += indent;\n partial = [];\n\n// Is the value an array?\n\n if (Object.prototype.toString.apply(value) === \"[object Array]\") {\n\n// The value is an array. Stringify every element. Use null as a placeholder\n// for non-JSON values.\n\n length = value.length;\n for (i = 0; i < length; i += 1) {\n partial[i] = str(i, value) || \"null\";\n }\n\n// Join all of the elements together, separated with commas, and wrap them in\n// brackets.\n\n v = partial.length === 0\n ? \"[]\"\n : gap\n ? \"[\\n\" + gap + partial.join(\",\\n\" + gap) + \"\\n\" + mind + \"]\"\n : \"[\" + partial.join(\",\") + \"]\";\n gap = mind;\n return v;\n }\n\n// If the replacer is an array, use it to select the members to be stringified.\n\n if (rep && typeof rep === \"object\") {\n length = rep.length;\n for (i = 0; i < length; i += 1) {\n if (typeof rep[i] === \"string\") {\n k = rep[i];\n v = str(k, value);\n if (v) {\n partial.push(quote(k) + (\n gap\n ? \": \"\n : \":\"\n ) + v);\n }\n }\n }\n } else {\n\n// Otherwise, iterate through all of the keys in the object.\n\n for (k in value) {\n if (Object.prototype.hasOwnProperty.call(value, k)) {\n v = str(k, value);\n if (v) {\n partial.push(quote(k) + (\n gap\n ? \": \"\n : \":\"\n ) + v);\n }\n }\n }\n }\n\n// Join all of the member texts together, separated with commas,\n// and wrap them in braces.\n\n v = partial.length === 0\n ? \"{}\"\n : gap\n ? \"{\\n\" + gap + partial.join(\",\\n\" + gap) + \"\\n\" + mind + \"}\"\n : \"{\" + partial.join(\",\") + \"}\";\n gap = mind;\n return v;\n }\n }\n\n// If the JSON object does not yet have a stringify method, give it one.\n\n if (typeof JSON.stringify !== \"function\") {\n meta = { // table of character substitutions\n \"\\b\": \"\\\\b\",\n \"\\t\": \"\\\\t\",\n \"\\n\": \"\\\\n\",\n \"\\f\": \"\\\\f\",\n \"\\r\": \"\\\\r\",\n \"\\\"\": \"\\\\\\\"\",\n \"\\\\\": \"\\\\\\\\\"\n };\n JSON.stringify = function (value, replacer, space) {\n\n// The stringify method takes a value and an optional replacer, and an optional\n// space parameter, and returns a JSON text. The replacer can be a function\n// that can replace values, or an array of strings that will select the keys.\n// A default replacer method can be provided. Use of the space parameter can\n// produce text that is more easily readable.\n\n var i;\n gap = \"\";\n indent = \"\";\n\n// If the space parameter is a number, make an indent string containing that\n// many spaces.\n\n if (typeof space === \"number\") {\n for (i = 0; i < space; i += 1) {\n indent += \" \";\n }\n\n// If the space parameter is a string, it will be used as the indent string.\n\n } else if (typeof space === \"string\") {\n indent = space;\n }\n\n// If there is a replacer, it must be a function or an array.\n// Otherwise, throw an error.\n\n rep = replacer;\n if (replacer && typeof replacer !== \"function\" &&\n (typeof replacer !== \"object\" ||\n typeof replacer.length !== \"number\")) {\n throw new Error(\"JSON.stringify\");\n }\n\n// Make a fake root object containing our value under the key of \"\".\n// Return the result of stringifying the value.\n\n return str(\"\", {\"\": value});\n };\n }\n\n\n// If the JSON object does not yet have a parse method, give it one.\n\n if (typeof JSON.parse !== \"function\") {\n JSON.parse = function (text, reviver) {\n\n// The parse method takes a text and an optional reviver function, and returns\n// a JavaScript value if the text is a valid JSON text.\n\n var j;\n\n function walk(holder, key) {\n\n// The walk method is used to recursively walk the resulting structure so\n// that modifications can be made.\n\n var k;\n var v;\n var value = holder[key];\n if (value && typeof value === \"object\") {\n for (k in value) {\n if (Object.prototype.hasOwnProperty.call(value, k)) {\n v = walk(value, k);\n if (v !== undefined) {\n value[k] = v;\n } else {\n delete value[k];\n }\n }\n }\n }\n return reviver.call(holder, key, value);\n }\n\n\n// Parsing happens in four stages. In the first stage, we replace certain\n// Unicode characters with escape sequences. JavaScript handles many characters\n// incorrectly, either silently deleting them, or treating them as line endings.\n\n text = String(text);\n rx_dangerous.lastIndex = 0;\n if (rx_dangerous.test(text)) {\n text = text.replace(rx_dangerous, function (a) {\n return \"\\\\u\" +\n (\"0000\" + a.charCodeAt(0).toString(16)).slice(-4);\n });\n }\n\n// In the second stage, we run the text against regular expressions that look\n// for non-JSON patterns. We are especially concerned with \"()\" and \"new\"\n// because they can cause invocation, and \"=\" because it can cause mutation.\n// But just to be safe, we want to reject all unexpected forms.\n\n// We split the second stage into 4 regexp operations in order to work around\n// crippling inefficiencies in IE's and Safari's regexp engines. First we\n// replace the JSON backslash pairs with \"@\" (a non-JSON character). Second, we\n// replace all simple value tokens with \"]\" characters. Third, we delete all\n// open brackets that follow a colon or comma or that begin the text. Finally,\n// we look to see that the remaining characters are only whitespace or \"]\" or\n// \",\" or \":\" or \"{\" or \"}\". If that is so, then the text is safe for eval.\n\n if (\n rx_one.test(\n text\n .replace(rx_two, \"@\")\n .replace(rx_three, \"]\")\n .replace(rx_four, \"\")\n )\n ) {\n\n// In the third stage we use the eval function to compile the text into a\n// JavaScript structure. The \"{\" operator is subject to a syntactic ambiguity\n// in JavaScript: it can begin a block or an object literal. We wrap the text\n// in parens to eliminate the ambiguity.\n\n j = eval(\"(\" + text + \")\");\n\n// In the optional fourth stage, we recursively walk the new structure, passing\n// each name/value pair to a reviver function for possible transformation.\n\n return (typeof reviver === \"function\")\n ? walk({\"\": j}, \"\")\n : j;\n }\n\n// If the text is not JSON parseable, then a SyntaxError is thrown.\n\n throw new SyntaxError(\"JSON.parse\");\n };\n }\n}());","module.exports = json2Plugin\n\nfunction json2Plugin() {\n\trequire('./lib/json2')\n\treturn {}\n}\n","var engine = require('../src/store-engine')\n\nvar storages = require('../storages/all')\nvar plugins = [require('../plugins/json2')]\n\nmodule.exports = engine.createStore(storages, plugins)\n","'use strict';\n\nvar ohauth = require('ohauth');\nvar resolveUrl = require('resolve-url');\nvar store = require('store');\nvar xtend = require('xtend');\n\n\n// # osm-auth\n//\n// This code is only compatible with IE10+ because the [XDomainRequest](http://bit.ly/LfO7xo)\n// object, IE<10's idea of [CORS](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing),\n// does not support custom headers, which this uses everywhere.\nmodule.exports = function(o) {\n\n var oauth = {};\n\n // authenticated users will also have a request token secret, but it's\n // not used in transactions with the server\n oauth.authenticated = function() {\n return !!(token('oauth_token') && token('oauth_token_secret'));\n };\n\n oauth.logout = function() {\n token('oauth_token', '');\n token('oauth_token_secret', '');\n token('oauth_request_token_secret', '');\n return oauth;\n };\n\n // TODO: detect lack of click event\n oauth.authenticate = function(callback) {\n if (oauth.authenticated()) return callback();\n\n oauth.logout();\n\n // ## Getting a request token\n var params = timenonce(getAuth(o)),\n url = o.url + '/oauth/request_token';\n\n params.oauth_signature = ohauth.signature(\n o.oauth_secret, '',\n ohauth.baseString('POST', url, params));\n\n if (!o.singlepage) {\n // Create a 600x550 popup window in the center of the screen\n var w = 600, h = 550,\n settings = [\n ['width', w], ['height', h],\n ['left', screen.width / 2 - w / 2],\n ['top', screen.height / 2 - h / 2]].map(function(x) {\n return x.join('=');\n }).join(','),\n popup = window.open('about:blank', 'oauth_window', settings);\n }\n\n // Request a request token. When this is complete, the popup\n // window is redirected to OSM's authorization page.\n ohauth.xhr('POST', url, params, null, {}, reqTokenDone);\n o.loading();\n\n function reqTokenDone(err, xhr) {\n o.done();\n if (err) return callback(err);\n var resp = ohauth.stringQs(xhr.response);\n token('oauth_request_token_secret', resp.oauth_token_secret);\n var authorize_url = o.url + '/oauth/authorize?' + ohauth.qsString({\n oauth_token: resp.oauth_token,\n oauth_callback: resolveUrl(o.landing)\n });\n\n if (o.singlepage) {\n location.href = authorize_url;\n } else {\n popup.location = authorize_url;\n }\n }\n\n // Called by a function in a landing page, in the popup window. The\n // window closes itself.\n window.authComplete = function(token) {\n var oauth_token = ohauth.stringQs(token.split('?')[1]);\n get_access_token(oauth_token.oauth_token);\n delete window.authComplete;\n };\n\n // ## Getting an request token\n //\n // At this point we have an `oauth_token`, brought in from a function\n // call on a landing page popup.\n function get_access_token(oauth_token) {\n var url = o.url + '/oauth/access_token',\n params = timenonce(getAuth(o)),\n request_token_secret = token('oauth_request_token_secret');\n params.oauth_token = oauth_token;\n params.oauth_signature = ohauth.signature(\n o.oauth_secret,\n request_token_secret,\n ohauth.baseString('POST', url, params));\n\n // ## Getting an access token\n //\n // The final token required for authentication. At this point\n // we have a `request token secret`\n ohauth.xhr('POST', url, params, null, {}, accessTokenDone);\n o.loading();\n }\n\n function accessTokenDone(err, xhr) {\n o.done();\n if (err) return callback(err);\n var access_token = ohauth.stringQs(xhr.response);\n token('oauth_token', access_token.oauth_token);\n token('oauth_token_secret', access_token.oauth_token_secret);\n callback(null, oauth);\n }\n };\n\n oauth.bootstrapToken = function(oauth_token, callback) {\n // ## Getting an request token\n // At this point we have an `oauth_token`, brought in from a function\n // call on a landing page popup.\n function get_access_token(oauth_token) {\n var url = o.url + '/oauth/access_token',\n params = timenonce(getAuth(o)),\n request_token_secret = token('oauth_request_token_secret');\n params.oauth_token = oauth_token;\n params.oauth_signature = ohauth.signature(\n o.oauth_secret,\n request_token_secret,\n ohauth.baseString('POST', url, params));\n\n // ## Getting an access token\n // The final token required for authentication. At this point\n // we have a `request token secret`\n ohauth.xhr('POST', url, params, null, {}, accessTokenDone);\n o.loading();\n }\n\n function accessTokenDone(err, xhr) {\n o.done();\n if (err) return callback(err);\n var access_token = ohauth.stringQs(xhr.response);\n token('oauth_token', access_token.oauth_token);\n token('oauth_token_secret', access_token.oauth_token_secret);\n callback(null, oauth);\n }\n\n get_access_token(oauth_token);\n };\n\n // # xhr\n //\n // A single XMLHttpRequest wrapper that does authenticated calls if the\n // user has logged in.\n oauth.xhr = function(options, callback) {\n if (!oauth.authenticated()) {\n if (o.auto) {\n return oauth.authenticate(run);\n } else {\n callback('not authenticated', null);\n return;\n }\n } else {\n return run();\n }\n\n function run() {\n var params = timenonce(getAuth(o)),\n oauth_token_secret = token('oauth_token_secret'),\n url = (options.prefix !== false) ? o.url + options.path : options.path,\n url_parts = url.replace(/#.*$/, '').split('?', 2),\n base_url = url_parts[0],\n query = (url_parts.length === 2) ? url_parts[1] : '';\n\n // https://tools.ietf.org/html/rfc5849#section-3.4.1.3.1\n if ((!options.options || !options.options.header ||\n options.options.header['Content-Type'] === 'application/x-www-form-urlencoded') &&\n options.content) {\n params = xtend(params, ohauth.stringQs(options.content));\n }\n\n params.oauth_token = token('oauth_token');\n params.oauth_signature = ohauth.signature(\n o.oauth_secret,\n oauth_token_secret,\n ohauth.baseString(options.method, base_url, xtend(params, ohauth.stringQs(query)))\n );\n\n return ohauth.xhr(options.method, url, params, options.content, options.options, done);\n }\n\n function done(err, xhr) {\n if (err) return callback(err);\n else if (xhr.responseXML) return callback(err, xhr.responseXML);\n else return callback(err, xhr.response);\n }\n };\n\n // pre-authorize this object, if we can just get a token and token_secret\n // from the start\n oauth.preauth = function(c) {\n if (!c) return;\n if (c.oauth_token) token('oauth_token', c.oauth_token);\n if (c.oauth_token_secret) token('oauth_token_secret', c.oauth_token_secret);\n return oauth;\n };\n\n oauth.options = function(_) {\n if (!arguments.length) return o;\n\n o = _;\n o.url = o.url || 'https://www.openstreetmap.org';\n o.landing = o.landing || 'land.html';\n o.singlepage = o.singlepage || false;\n\n // Optional loading and loading-done functions for nice UI feedback.\n // by default, no-ops\n o.loading = o.loading || function() {};\n o.done = o.done || function() {};\n\n return oauth.preauth(o);\n };\n\n // 'stamp' an authentication object from `getAuth()`\n // with a [nonce](http://en.wikipedia.org/wiki/Cryptographic_nonce)\n // and timestamp\n function timenonce(o) {\n o.oauth_timestamp = ohauth.timestamp();\n o.oauth_nonce = ohauth.nonce();\n return o;\n }\n\n // get/set tokens. These are prefixed with the base URL so that `osm-auth`\n // can be used with multiple APIs and the keys in `localStorage`\n // will not clash\n var token;\n\n if (store.enabled) {\n token = function (x, y) {\n if (arguments.length === 1) return store.get(o.url + x);\n else if (arguments.length === 2) return store.set(o.url + x, y);\n };\n } else {\n var storage = {};\n token = function (x, y) {\n if (arguments.length === 1) return storage[o.url + x];\n else if (arguments.length === 2) return storage[o.url + x] = y;\n };\n }\n\n // Get an authentication object. If you just add and remove properties\n // from a single object, you'll need to use `delete` to make sure that\n // it doesn't contain undesired properties for authentication\n function getAuth(o) {\n return {\n oauth_consumer_key: o.oauth_consumer_key,\n oauth_signature_method: 'HMAC-SHA1'\n };\n }\n\n // potentially pre-authorize\n oauth.options(o);\n\n return oauth;\n};\n","import _throttle from 'lodash-es/throttle';\n\nimport { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { xml as d3_xml } from 'd3-fetch';\nimport { json as d3_json } from 'd3-fetch';\n\nimport osmAuth from 'osm-auth';\nimport RBush from 'rbush';\n\nimport { JXON } from '../util/jxon';\nimport { geoExtent, geoRawMercator, geoVecAdd, geoZoomToScale } from '../geo';\nimport { osmEntity, osmNode, osmNote, osmRelation, osmWay } from '../osm';\nimport { utilArrayChunk, utilArrayGroupBy, utilArrayUniq, utilRebind, utilTiler, utilQsString, utilStringQs } from '../util';\n\n\nvar tiler = utilTiler();\nvar dispatch = d3_dispatch('apiStatusChange', 'authLoading', 'authDone', 'change', 'loading', 'loaded', 'loadedNotes');\nvar urlroot = 'https://www.openstreetmap.org';\nvar q = utilStringQs(window.location.hash.substring(1));\nvar credentialsMode = 'omit';\nif (q.hasOwnProperty('osm_api_url')) {\n urlroot = q.osm_api_url;\n credentialsMode = 'include';\n}\nvar oauth = osmAuth({\n url: urlroot,\n oauth_consumer_key: 'MlAcABGGdqadlgrjpmG6qSQu3bwbAgxC7hW0vRwm',\n oauth_secret: 'M0g3lCJTvpnwMic0HYYwwTMpVvugNRlkycQL7so5',\n loading: authLoading,\n done: authDone\n});\n\nvar _blacklists = ['.*\\.google(apis)?\\..*/(vt|kh)[\\?/].*([xyz]=.*){3}.*'];\nvar _tileCache = { toLoad: {}, loaded: {}, inflight: {}, seen: {}, rtree: new RBush() };\nvar _noteCache = { toLoad: {}, loaded: {}, inflight: {}, inflightPost: {}, note: {}, closed: {}, rtree: new RBush() };\nvar _userCache = { toLoad: {}, user: {} };\nvar _cachedApiStatus;\nvar _changeset = {};\n\nvar _deferred = new Set();\nvar _connectionID = 1;\nvar _tileZoom = 16;\nvar _noteZoom = 12;\nvar _rateLimitError;\nvar _userChangesets;\nvar _userDetails;\nvar _off;\n\n// set a default but also load this from the API status\nvar _maxWayNodes = 2000;\n\n\nfunction authLoading() {\n dispatch.call('authLoading');\n}\n\n\nfunction authDone() {\n dispatch.call('authDone');\n}\n\n\nfunction abortRequest(controllerOrXHR) {\n if (controllerOrXHR) {\n controllerOrXHR.abort();\n }\n}\n\n\nfunction hasInflightRequests(cache) {\n return Object.keys(cache.inflight).length;\n}\n\n\nfunction abortUnwantedRequests(cache, visibleTiles) {\n Object.keys(cache.inflight).forEach(function(k) {\n if (cache.toLoad[k]) return;\n if (visibleTiles.find(function(tile) { return k === tile.id; })) return;\n\n abortRequest(cache.inflight[k]);\n delete cache.inflight[k];\n });\n}\n\n\nfunction getLoc(attrs) {\n var lon = attrs.lon && attrs.lon.value;\n var lat = attrs.lat && attrs.lat.value;\n return [parseFloat(lon), parseFloat(lat)];\n}\n\n\nfunction getNodes(obj) {\n var elems = obj.getElementsByTagName('nd');\n var nodes = new Array(elems.length);\n for (var i = 0, l = elems.length; i < l; i++) {\n nodes[i] = 'n' + elems[i].attributes.ref.value;\n }\n return nodes;\n}\n\nfunction getNodesJSON(obj) {\n var elems = obj.nodes;\n var nodes = new Array(elems.length);\n for (var i = 0, l = elems.length; i < l; i++) {\n nodes[i] = 'n' + elems[i];\n }\n return nodes;\n}\n\nfunction getTags(obj) {\n var elems = obj.getElementsByTagName('tag');\n var tags = {};\n for (var i = 0, l = elems.length; i < l; i++) {\n var attrs = elems[i].attributes;\n tags[attrs.k.value] = attrs.v.value;\n }\n\n return tags;\n}\n\n\nfunction getMembers(obj) {\n var elems = obj.getElementsByTagName('member');\n var members = new Array(elems.length);\n for (var i = 0, l = elems.length; i < l; i++) {\n var attrs = elems[i].attributes;\n members[i] = {\n id: attrs.type.value[0] + attrs.ref.value,\n type: attrs.type.value,\n role: attrs.role.value\n };\n }\n return members;\n}\n\nfunction getMembersJSON(obj) {\n var elems = obj.members;\n var members = new Array(elems.length);\n for (var i = 0, l = elems.length; i < l; i++) {\n var attrs = elems[i];\n members[i] = {\n id: attrs.type[0] + attrs.ref,\n type: attrs.type,\n role: attrs.role\n };\n }\n return members;\n}\n\nfunction getVisible(attrs) {\n return (!attrs.visible || attrs.visible.value !== 'false');\n}\n\n\nfunction parseComments(comments) {\n var parsedComments = [];\n\n // for each comment\n for (var i = 0; i < comments.length; i++) {\n var comment = comments[i];\n if (comment.nodeName === 'comment') {\n var childNodes = comment.childNodes;\n var parsedComment = {};\n\n for (var j = 0; j < childNodes.length; j++) {\n var node = childNodes[j];\n var nodeName = node.nodeName;\n if (nodeName === '#text') continue;\n parsedComment[nodeName] = node.textContent;\n\n if (nodeName === 'uid') {\n var uid = node.textContent;\n if (uid && !_userCache.user[uid]) {\n _userCache.toLoad[uid] = true;\n }\n }\n }\n\n if (parsedComment) {\n parsedComments.push(parsedComment);\n }\n }\n }\n return parsedComments;\n}\n\n\nfunction encodeNoteRtree(note) {\n return {\n minX: note.loc[0],\n minY: note.loc[1],\n maxX: note.loc[0],\n maxY: note.loc[1],\n data: note\n };\n}\n\n\nvar jsonparsers = {\n\n node: function nodeData(obj, uid) {\n return new osmNode({\n id: uid,\n visible: typeof obj.visible === 'boolean' ? obj.visible : true,\n version: obj.version && obj.version.toString(),\n changeset: obj.changeset && obj.changeset.toString(),\n timestamp: obj.timestamp,\n user: obj.user,\n uid: obj.uid && obj.uid.toString(),\n loc: [parseFloat(obj.lon), parseFloat(obj.lat)],\n tags: obj.tags\n });\n },\n\n way: function wayData(obj, uid) {\n return new osmWay({\n id: uid,\n visible: typeof obj.visible === 'boolean' ? obj.visible : true,\n version: obj.version && obj.version.toString(),\n changeset: obj.changeset && obj.changeset.toString(),\n timestamp: obj.timestamp,\n user: obj.user,\n uid: obj.uid && obj.uid.toString(),\n tags: obj.tags,\n nodes: getNodesJSON(obj)\n });\n },\n\n relation: function relationData(obj, uid) {\n return new osmRelation({\n id: uid,\n visible: typeof obj.visible === 'boolean' ? obj.visible : true,\n version: obj.version && obj.version.toString(),\n changeset: obj.changeset && obj.changeset.toString(),\n timestamp: obj.timestamp,\n user: obj.user,\n uid: obj.uid && obj.uid.toString(),\n tags: obj.tags,\n members: getMembersJSON(obj)\n });\n }\n};\n\nfunction parseJSON(payload, callback, options) {\n options = Object.assign({ skipSeen: true }, options);\n if (!payload) {\n return callback({ message: 'No JSON', status: -1 });\n }\n\n var json = payload;\n if (typeof json !== 'object')\n json = JSON.parse(payload);\n\n if (!json.elements)\n return callback({ message: 'No JSON', status: -1 });\n\n var children = json.elements;\n\n var handle = window.requestIdleCallback(function() {\n var results = [];\n var result;\n for (var i = 0; i < children.length; i++) {\n result = parseChild(children[i]);\n if (result) results.push(result);\n }\n callback(null, results);\n });\n\n _deferred.add(handle);\n\n function parseChild(child) {\n var parser = jsonparsers[child.type];\n if (!parser) return null;\n\n var uid;\n\n uid = osmEntity.id.fromOSM(child.type, child.id);\n if (options.skipSeen) {\n if (_tileCache.seen[uid]) return null; // avoid reparsing a \"seen\" entity\n _tileCache.seen[uid] = true;\n }\n\n return parser(child, uid);\n }\n}\n\nvar parsers = {\n node: function nodeData(obj, uid) {\n var attrs = obj.attributes;\n return new osmNode({\n id: uid,\n visible: getVisible(attrs),\n version: attrs.version.value,\n changeset: attrs.changeset && attrs.changeset.value,\n timestamp: attrs.timestamp && attrs.timestamp.value,\n user: attrs.user && attrs.user.value,\n uid: attrs.uid && attrs.uid.value,\n loc: getLoc(attrs),\n tags: getTags(obj)\n });\n },\n\n way: function wayData(obj, uid) {\n var attrs = obj.attributes;\n return new osmWay({\n id: uid,\n visible: getVisible(attrs),\n version: attrs.version.value,\n changeset: attrs.changeset && attrs.changeset.value,\n timestamp: attrs.timestamp && attrs.timestamp.value,\n user: attrs.user && attrs.user.value,\n uid: attrs.uid && attrs.uid.value,\n tags: getTags(obj),\n nodes: getNodes(obj),\n });\n },\n\n relation: function relationData(obj, uid) {\n var attrs = obj.attributes;\n return new osmRelation({\n id: uid,\n visible: getVisible(attrs),\n version: attrs.version.value,\n changeset: attrs.changeset && attrs.changeset.value,\n timestamp: attrs.timestamp && attrs.timestamp.value,\n user: attrs.user && attrs.user.value,\n uid: attrs.uid && attrs.uid.value,\n tags: getTags(obj),\n members: getMembers(obj)\n });\n },\n\n note: function parseNote(obj, uid) {\n var attrs = obj.attributes;\n var childNodes = obj.childNodes;\n var props = {};\n\n props.id = uid;\n props.loc = getLoc(attrs);\n\n // if notes are coincident, move them apart slightly\n var coincident = false;\n var epsilon = 0.00001;\n do {\n if (coincident) {\n props.loc = geoVecAdd(props.loc, [epsilon, epsilon]);\n }\n var bbox = geoExtent(props.loc).bbox();\n coincident = _noteCache.rtree.search(bbox).length;\n } while (coincident);\n\n // parse note contents\n for (var i = 0; i < childNodes.length; i++) {\n var node = childNodes[i];\n var nodeName = node.nodeName;\n if (nodeName === '#text') continue;\n\n // if the element is comments, parse the comments\n if (nodeName === 'comments') {\n props[nodeName] = parseComments(node.childNodes);\n } else {\n props[nodeName] = node.textContent;\n }\n }\n\n var note = new osmNote(props);\n var item = encodeNoteRtree(note);\n _noteCache.note[note.id] = note;\n _noteCache.rtree.insert(item);\n\n return note;\n },\n\n user: function parseUser(obj, uid) {\n var attrs = obj.attributes;\n var user = {\n id: uid,\n display_name: attrs.display_name && attrs.display_name.value,\n account_created: attrs.account_created && attrs.account_created.value,\n changesets_count: '0',\n active_blocks: '0'\n };\n\n var img = obj.getElementsByTagName('img');\n if (img && img[0] && img[0].getAttribute('href')) {\n user.image_url = img[0].getAttribute('href');\n }\n\n var changesets = obj.getElementsByTagName('changesets');\n if (changesets && changesets[0] && changesets[0].getAttribute('count')) {\n user.changesets_count = changesets[0].getAttribute('count');\n }\n\n var blocks = obj.getElementsByTagName('blocks');\n if (blocks && blocks[0]) {\n var received = blocks[0].getElementsByTagName('received');\n if (received && received[0] && received[0].getAttribute('active')) {\n user.active_blocks = received[0].getAttribute('active');\n }\n }\n\n _userCache.user[uid] = user;\n delete _userCache.toLoad[uid];\n return user;\n }\n};\n\n\nfunction parseXML(xml, callback, options) {\n options = Object.assign({ skipSeen: true }, options);\n if (!xml || !xml.childNodes) {\n return callback({ message: 'No XML', status: -1 });\n }\n\n var root = xml.childNodes[0];\n var children = root.childNodes;\n\n var handle = window.requestIdleCallback(function() {\n var results = [];\n var result;\n for (var i = 0; i < children.length; i++) {\n result = parseChild(children[i]);\n if (result) results.push(result);\n }\n callback(null, results);\n });\n\n _deferred.add(handle);\n\n\n function parseChild(child) {\n var parser = parsers[child.nodeName];\n if (!parser) return null;\n\n var uid;\n if (child.nodeName === 'user') {\n uid = child.attributes.id.value;\n if (options.skipSeen && _userCache.user[uid]) {\n delete _userCache.toLoad[uid];\n return null;\n }\n\n } else if (child.nodeName === 'note') {\n uid = child.getElementsByTagName('id')[0].textContent;\n\n } else {\n uid = osmEntity.id.fromOSM(child.nodeName, child.attributes.id.value);\n if (options.skipSeen) {\n if (_tileCache.seen[uid]) return null; // avoid reparsing a \"seen\" entity\n _tileCache.seen[uid] = true;\n }\n }\n\n return parser(child, uid);\n }\n}\n\n\n// replace or remove note from rtree\nfunction updateRtree(item, replace) {\n _noteCache.rtree.remove(item, function isEql(a, b) { return a.data.id === b.data.id; });\n\n if (replace) {\n _noteCache.rtree.insert(item);\n }\n}\n\n\nfunction wrapcb(thisArg, callback, cid) {\n return function(err, result) {\n if (err) {\n // 400 Bad Request, 401 Unauthorized, 403 Forbidden..\n if (err.status === 400 || err.status === 401 || err.status === 403) {\n thisArg.logout();\n }\n return callback.call(thisArg, err);\n\n } else if (thisArg.getConnectionId() !== cid) {\n return callback.call(thisArg, { message: 'Connection Switched', status: -1 });\n\n } else {\n return callback.call(thisArg, err, result);\n }\n };\n}\n\n\nexport default {\n\n init: function() {\n utilRebind(this, dispatch, 'on');\n },\n\n\n reset: function() {\n Array.from(_deferred).forEach(function(handle) {\n window.cancelIdleCallback(handle);\n _deferred.delete(handle);\n });\n\n _connectionID++;\n _userChangesets = undefined;\n _userDetails = undefined;\n _rateLimitError = undefined;\n\n Object.values(_tileCache.inflight).forEach(abortRequest);\n Object.values(_noteCache.inflight).forEach(abortRequest);\n Object.values(_noteCache.inflightPost).forEach(abortRequest);\n if (_changeset.inflight) abortRequest(_changeset.inflight);\n\n _tileCache = { toLoad: {}, loaded: {}, inflight: {}, seen: {}, rtree: new RBush() };\n _noteCache = { toLoad: {}, loaded: {}, inflight: {}, inflightPost: {}, note: {}, closed: {}, rtree: new RBush() };\n _userCache = { toLoad: {}, user: {} };\n _cachedApiStatus = undefined;\n _changeset = {};\n\n return this;\n },\n\n\n getConnectionId: function() {\n return _connectionID;\n },\n\n\n changesetURL: function(changesetID) {\n return urlroot + '/changeset/' + changesetID;\n },\n\n\n changesetsURL: function(center, zoom) {\n var precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));\n return urlroot + '/history#map=' +\n Math.floor(zoom) + '/' +\n center[1].toFixed(precision) + '/' +\n center[0].toFixed(precision);\n },\n\n\n entityURL: function(entity) {\n return urlroot + '/' + entity.type + '/' + entity.osmId();\n },\n\n\n historyURL: function(entity) {\n return urlroot + '/' + entity.type + '/' + entity.osmId() + '/history';\n },\n\n\n userURL: function(username) {\n return urlroot + '/user/' + username;\n },\n\n\n noteURL: function(note) {\n return urlroot + '/note/' + note.id;\n },\n\n\n noteReportURL: function(note) {\n return urlroot + '/reports/new?reportable_type=Note&reportable_id=' + note.id;\n },\n\n\n // Generic method to load data from the OSM API\n // Can handle either auth or unauth calls.\n loadFromAPI: function(path, callback, options) {\n options = Object.assign({ skipSeen: true }, options);\n var that = this;\n var cid = _connectionID;\n\n function done(err, payload) {\n if (that.getConnectionId() !== cid) {\n if (callback) callback({ message: 'Connection Switched', status: -1 });\n return;\n }\n\n var isAuthenticated = that.authenticated();\n\n // 400 Bad Request, 401 Unauthorized, 403 Forbidden\n // Logout and retry the request..\n if (isAuthenticated && err && err.status &&\n (err.status === 400 || err.status === 401 || err.status === 403)) {\n that.logout();\n that.loadFromAPI(path, callback, options);\n\n // else, no retry..\n } else {\n // 509 Bandwidth Limit Exceeded, 429 Too Many Requests\n // Set the rateLimitError flag and trigger a warning..\n if (!isAuthenticated && !_rateLimitError && err && err.status &&\n (err.status === 509 || err.status === 429)) {\n _rateLimitError = err;\n dispatch.call('change');\n that.reloadApiStatus();\n\n } else if ((err && _cachedApiStatus === 'online') ||\n (!err && _cachedApiStatus !== 'online')) {\n // If the response's error state doesn't match the status,\n // it's likely we lost or gained the connection so reload the status\n that.reloadApiStatus();\n }\n\n if (callback) {\n if (err) {\n return callback(err);\n } else {\n if (path.indexOf('.json') !== -1) {\n return parseJSON(payload, callback, options);\n } else {\n return parseXML(payload, callback, options);\n }\n }\n }\n }\n }\n\n if (this.authenticated()) {\n return oauth.xhr({ method: 'GET', path: path }, done);\n } else {\n var url = urlroot + path;\n var controller = new AbortController();\n d3_json(url, { signal: controller.signal })\n .then(function(data) {\n done(null, data);\n })\n .catch(function(err) {\n if (err.name === 'AbortError') return;\n // d3-fetch includes status in the error message,\n // but we can't access the response itself\n // https://github.com/d3/d3-fetch/issues/27\n var match = err.message.match(/^\\d{3}/);\n if (match) {\n done({ status: +match[0], statusText: err.message });\n } else {\n done(err.message);\n }\n });\n return controller;\n }\n },\n\n\n // Load a single entity by id (ways and relations use the `/full` call)\n // GET /api/0.6/node/#id\n // GET /api/0.6/[way|relation]/#id/full\n loadEntity: function(id, callback) {\n var type = osmEntity.id.type(id);\n var osmID = osmEntity.id.toOSM(id);\n var options = { skipSeen: false };\n\n this.loadFromAPI(\n '/api/0.6/' + type + '/' + osmID + (type !== 'node' ? '/full' : '') + '.json',\n function(err, entities) {\n if (callback) callback(err, { data: entities });\n },\n options\n );\n },\n\n\n // Load a single entity with a specific version\n // GET /api/0.6/[node|way|relation]/#id/#version\n loadEntityVersion: function(id, version, callback) {\n var type = osmEntity.id.type(id);\n var osmID = osmEntity.id.toOSM(id);\n var options = { skipSeen: false };\n\n this.loadFromAPI(\n '/api/0.6/' + type + '/' + osmID + '/' + version + '.json',\n function(err, entities) {\n if (callback) callback(err, { data: entities });\n },\n options\n );\n },\n\n\n // Load multiple entities in chunks\n // (note: callback may be called multiple times)\n // Unlike `loadEntity`, child nodes and members are not fetched\n // GET /api/0.6/[nodes|ways|relations]?#parameters\n loadMultiple: function(ids, callback) {\n var that = this;\n var groups = utilArrayGroupBy(utilArrayUniq(ids), osmEntity.id.type);\n\n Object.keys(groups).forEach(function(k) {\n var type = k + 's'; // nodes, ways, relations\n var osmIDs = groups[k].map(function(id) { return osmEntity.id.toOSM(id); });\n var options = { skipSeen: false };\n\n utilArrayChunk(osmIDs, 150).forEach(function(arr) {\n that.loadFromAPI(\n '/api/0.6/' + type + '.json?' + type + '=' + arr.join(),\n function(err, entities) {\n if (callback) callback(err, { data: entities });\n },\n options\n );\n });\n });\n },\n\n\n // Create, upload, and close a changeset\n // PUT /api/0.6/changeset/create\n // POST /api/0.6/changeset/#id/upload\n // PUT /api/0.6/changeset/#id/close\n putChangeset: function(changeset, changes, callback) {\n var cid = _connectionID;\n\n if (_changeset.inflight) {\n return callback({ message: 'Changeset already inflight', status: -2 }, changeset);\n\n } else if (_changeset.open) { // reuse existing open changeset..\n return createdChangeset.call(this, null, _changeset.open);\n\n } else { // Open a new changeset..\n var options = {\n method: 'PUT',\n path: '/api/0.6/changeset/create',\n options: { header: { 'Content-Type': 'text/xml' } },\n content: JXON.stringify(changeset.asJXON())\n };\n _changeset.inflight = oauth.xhr(\n options,\n wrapcb(this, createdChangeset, cid)\n );\n }\n\n\n function createdChangeset(err, changesetID) {\n _changeset.inflight = null;\n if (err) { return callback(err, changeset); }\n\n _changeset.open = changesetID;\n changeset = changeset.update({ id: changesetID });\n\n // Upload the changeset..\n var options = {\n method: 'POST',\n path: '/api/0.6/changeset/' + changesetID + '/upload',\n options: { header: { 'Content-Type': 'text/xml' } },\n content: JXON.stringify(changeset.osmChangeJXON(changes))\n };\n _changeset.inflight = oauth.xhr(\n options,\n wrapcb(this, uploadedChangeset, cid)\n );\n }\n\n\n function uploadedChangeset(err) {\n _changeset.inflight = null;\n if (err) return callback(err, changeset);\n\n // Upload was successful, safe to call the callback.\n // Add delay to allow for postgres replication #1646 #2678\n window.setTimeout(function() { callback(null, changeset); }, 2500);\n _changeset.open = null;\n\n // At this point, we don't really care if the connection was switched..\n // Only try to close the changeset if we're still talking to the same server.\n if (this.getConnectionId() === cid) {\n // Still attempt to close changeset, but ignore response because #2667\n oauth.xhr({\n method: 'PUT',\n path: '/api/0.6/changeset/' + changeset.id + '/close',\n options: { header: { 'Content-Type': 'text/xml' } }\n }, function() { return true; });\n }\n }\n },\n\n\n // Load multiple users in chunks\n // (note: callback may be called multiple times)\n // GET /api/0.6/users?users=#id1,#id2,...,#idn\n loadUsers: function(uids, callback) {\n var toLoad = [];\n var cached = [];\n\n utilArrayUniq(uids).forEach(function(uid) {\n if (_userCache.user[uid]) {\n delete _userCache.toLoad[uid];\n cached.push(_userCache.user[uid]);\n } else {\n toLoad.push(uid);\n }\n });\n\n if (cached.length || !this.authenticated()) {\n callback(undefined, cached);\n if (!this.authenticated()) return; // require auth\n }\n\n utilArrayChunk(toLoad, 150).forEach(function(arr) {\n oauth.xhr(\n { method: 'GET', path: '/api/0.6/users?users=' + arr.join() },\n wrapcb(this, done, _connectionID)\n );\n }.bind(this));\n\n function done(err, xml) {\n if (err) { return callback(err); }\n\n var options = { skipSeen: true };\n return parseXML(xml, function(err, results) {\n if (err) {\n return callback(err);\n } else {\n return callback(undefined, results);\n }\n }, options);\n }\n },\n\n\n // Load a given user by id\n // GET /api/0.6/user/#id\n loadUser: function(uid, callback) {\n if (_userCache.user[uid] || !this.authenticated()) { // require auth\n delete _userCache.toLoad[uid];\n return callback(undefined, _userCache.user[uid]);\n }\n\n oauth.xhr(\n { method: 'GET', path: '/api/0.6/user/' + uid },\n wrapcb(this, done, _connectionID)\n );\n\n function done(err, xml) {\n if (err) { return callback(err); }\n\n var options = { skipSeen: true };\n return parseXML(xml, function(err, results) {\n if (err) {\n return callback(err);\n } else {\n return callback(undefined, results[0]);\n }\n }, options);\n }\n },\n\n\n // Load the details of the logged-in user\n // GET /api/0.6/user/details\n userDetails: function(callback) {\n if (_userDetails) { // retrieve cached\n return callback(undefined, _userDetails);\n }\n\n oauth.xhr(\n { method: 'GET', path: '/api/0.6/user/details' },\n wrapcb(this, done, _connectionID)\n );\n\n function done(err, xml) {\n if (err) { return callback(err); }\n\n var options = { skipSeen: false };\n return parseXML(xml, function(err, results) {\n if (err) {\n return callback(err);\n } else {\n _userDetails = results[0];\n return callback(undefined, _userDetails);\n }\n }, options);\n }\n },\n\n\n // Load previous changesets for the logged in user\n // GET /api/0.6/changesets?user=#id\n userChangesets: function(callback) {\n if (_userChangesets) { // retrieve cached\n return callback(undefined, _userChangesets);\n }\n\n this.userDetails(\n wrapcb(this, gotDetails, _connectionID)\n );\n\n\n function gotDetails(err, user) {\n if (err) { return callback(err); }\n\n oauth.xhr(\n { method: 'GET', path: '/api/0.6/changesets?user=' + user.id },\n wrapcb(this, done, _connectionID)\n );\n }\n\n function done(err, xml) {\n if (err) { return callback(err); }\n\n _userChangesets = Array.prototype.map.call(\n xml.getElementsByTagName('changeset'),\n function (changeset) { return { tags: getTags(changeset) }; }\n ).filter(function (changeset) {\n var comment = changeset.tags.comment;\n return comment && comment !== '';\n });\n\n return callback(undefined, _userChangesets);\n }\n },\n\n\n // Fetch the status of the OSM API\n // GET /api/capabilities\n status: function(callback) {\n var url = urlroot + '/api/capabilities';\n var errback = wrapcb(this, done, _connectionID);\n d3_xml(url, { credentials: credentialsMode })\n .then(function(data) { errback(null, data); })\n .catch(function(err) { errback(err.message); });\n\n function done(err, xml) {\n if (err) {\n // the status is null if no response could be retrieved\n return callback(err, null);\n }\n\n // update blacklists\n var elements = xml.getElementsByTagName('blacklist');\n var regexes = [];\n for (var i = 0; i < elements.length; i++) {\n var regex = elements[i].getAttribute('regex'); // needs unencode?\n if (regex) {\n regexes.push(regex);\n }\n }\n if (regexes.length) {\n _blacklists = regexes;\n }\n\n if (_rateLimitError) {\n return callback(_rateLimitError, 'rateLimited');\n } else {\n var waynodes = xml.getElementsByTagName('waynodes');\n var maxWayNodes = waynodes.length && parseInt(waynodes[0].getAttribute('maximum'), 10);\n if (maxWayNodes && isFinite(maxWayNodes)) _maxWayNodes = maxWayNodes;\n\n var apiStatus = xml.getElementsByTagName('status');\n var val = apiStatus[0].getAttribute('api');\n return callback(undefined, val);\n }\n }\n },\n\n // Calls `status` and dispatches an `apiStatusChange` event if the returned\n // status differs from the cached status.\n reloadApiStatus: function() {\n // throttle to avoid unncessary API calls\n if (!this.throttledReloadApiStatus) {\n var that = this;\n this.throttledReloadApiStatus = _throttle(function() {\n that.status(function(err, status) {\n if (status !== _cachedApiStatus) {\n _cachedApiStatus = status;\n dispatch.call('apiStatusChange', that, err, status);\n }\n });\n }, 500);\n }\n this.throttledReloadApiStatus();\n },\n\n\n // Returns the maximum number of nodes a single way can have\n maxWayNodes: function() {\n return _maxWayNodes;\n },\n\n\n // Load data (entities) from the API in tiles\n // GET /api/0.6/map?bbox=\n loadTiles: function(projection, callback) {\n if (_off) return;\n\n // determine the needed tiles to cover the view\n var tiles = tiler.zoomExtent([_tileZoom, _tileZoom]).getTiles(projection);\n\n // abort inflight requests that are no longer needed\n var hadRequests = hasInflightRequests(_tileCache);\n abortUnwantedRequests(_tileCache, tiles);\n if (hadRequests && !hasInflightRequests(_tileCache)) {\n dispatch.call('loaded'); // stop the spinner\n }\n\n // issue new requests..\n tiles.forEach(function(tile) {\n this.loadTile(tile, callback);\n }, this);\n },\n\n\n // Load a single data tile\n // GET /api/0.6/map?bbox=\n loadTile: function(tile, callback) {\n if (_off) return;\n if (_tileCache.loaded[tile.id] || _tileCache.inflight[tile.id]) return;\n\n if (!hasInflightRequests(_tileCache)) {\n dispatch.call('loading'); // start the spinner\n }\n\n var path = '/api/0.6/map.json?bbox=';\n var options = { skipSeen: true };\n\n _tileCache.inflight[tile.id] = this.loadFromAPI(\n path + tile.extent.toParam(),\n tileCallback,\n options\n );\n\n function tileCallback(err, parsed) {\n delete _tileCache.inflight[tile.id];\n if (!err) {\n delete _tileCache.toLoad[tile.id];\n _tileCache.loaded[tile.id] = true;\n var bbox = tile.extent.bbox();\n bbox.id = tile.id;\n _tileCache.rtree.insert(bbox);\n }\n if (callback) {\n callback(err, Object.assign({ data: parsed }, tile));\n }\n if (!hasInflightRequests(_tileCache)) {\n dispatch.call('loaded'); // stop the spinner\n }\n }\n },\n\n\n isDataLoaded: function(loc) {\n var bbox = { minX: loc[0], minY: loc[1], maxX: loc[0], maxY: loc[1] };\n return _tileCache.rtree.collides(bbox);\n },\n\n\n // load the tile that covers the given `loc`\n loadTileAtLoc: function(loc, callback) {\n // Back off if the toLoad queue is filling up.. re #6417\n // (Currently `loadTileAtLoc` requests are considered low priority - used by operations to\n // let users safely edit geometries which extend to unloaded tiles. We can drop some.)\n if (Object.keys(_tileCache.toLoad).length > 50) return;\n\n var k = geoZoomToScale(_tileZoom + 1);\n var offset = geoRawMercator().scale(k)(loc);\n var projection = geoRawMercator().transform({ k: k, x: -offset[0], y: -offset[1] });\n var tiles = tiler.zoomExtent([_tileZoom, _tileZoom]).getTiles(projection);\n\n tiles.forEach(function(tile) {\n if (_tileCache.toLoad[tile.id] || _tileCache.loaded[tile.id] || _tileCache.inflight[tile.id]) return;\n\n _tileCache.toLoad[tile.id] = true;\n this.loadTile(tile, callback);\n }, this);\n },\n\n\n // Load notes from the API in tiles\n // GET /api/0.6/notes?bbox=\n loadNotes: function(projection, noteOptions) {\n noteOptions = Object.assign({ limit: 10000, closed: 7 }, noteOptions);\n if (_off) return;\n\n var that = this;\n var path = '/api/0.6/notes?limit=' + noteOptions.limit + '&closed=' + noteOptions.closed + '&bbox=';\n var throttleLoadUsers = _throttle(function() {\n var uids = Object.keys(_userCache.toLoad);\n if (!uids.length) return;\n that.loadUsers(uids, function() {}); // eagerly load user details\n }, 750);\n\n // determine the needed tiles to cover the view\n var tiles = tiler.zoomExtent([_noteZoom, _noteZoom]).getTiles(projection);\n\n // abort inflight requests that are no longer needed\n abortUnwantedRequests(_noteCache, tiles);\n\n // issue new requests..\n tiles.forEach(function(tile) {\n if (_noteCache.loaded[tile.id] || _noteCache.inflight[tile.id]) return;\n\n var options = { skipSeen: false };\n _noteCache.inflight[tile.id] = that.loadFromAPI(\n path + tile.extent.toParam(),\n function(err) {\n delete _noteCache.inflight[tile.id];\n if (!err) {\n _noteCache.loaded[tile.id] = true;\n }\n throttleLoadUsers();\n dispatch.call('loadedNotes');\n },\n options\n );\n });\n },\n\n\n // Create a note\n // POST /api/0.6/notes?params\n postNoteCreate: function(note, callback) {\n if (!this.authenticated()) {\n return callback({ message: 'Not Authenticated', status: -3 }, note);\n }\n if (_noteCache.inflightPost[note.id]) {\n return callback({ message: 'Note update already inflight', status: -2 }, note);\n }\n\n if (!note.loc[0] || !note.loc[1] || !note.newComment) return; // location & description required\n\n var comment = note.newComment;\n if (note.newCategory && note.newCategory !== 'None') { comment += ' #' + note.newCategory; }\n\n var path = '/api/0.6/notes?' + utilQsString({ lon: note.loc[0], lat: note.loc[1], text: comment });\n\n _noteCache.inflightPost[note.id] = oauth.xhr(\n { method: 'POST', path: path },\n wrapcb(this, done, _connectionID)\n );\n\n\n function done(err, xml) {\n delete _noteCache.inflightPost[note.id];\n if (err) { return callback(err); }\n\n // we get the updated note back, remove from caches and reparse..\n this.removeNote(note);\n\n var options = { skipSeen: false };\n return parseXML(xml, function(err, results) {\n if (err) {\n return callback(err);\n } else {\n return callback(undefined, results[0]);\n }\n }, options);\n }\n },\n\n\n // Update a note\n // POST /api/0.6/notes/#id/comment?text=comment\n // POST /api/0.6/notes/#id/close?text=comment\n // POST /api/0.6/notes/#id/reopen?text=comment\n postNoteUpdate: function(note, newStatus, callback) {\n if (!this.authenticated()) {\n return callback({ message: 'Not Authenticated', status: -3 }, note);\n }\n if (_noteCache.inflightPost[note.id]) {\n return callback({ message: 'Note update already inflight', status: -2 }, note);\n }\n\n var action;\n if (note.status !== 'closed' && newStatus === 'closed') {\n action = 'close';\n } else if (note.status !== 'open' && newStatus === 'open') {\n action = 'reopen';\n } else {\n action = 'comment';\n if (!note.newComment) return; // when commenting, comment required\n }\n\n var path = '/api/0.6/notes/' + note.id + '/' + action;\n if (note.newComment) {\n path += '?' + utilQsString({ text: note.newComment });\n }\n\n _noteCache.inflightPost[note.id] = oauth.xhr(\n { method: 'POST', path: path },\n wrapcb(this, done, _connectionID)\n );\n\n\n function done(err, xml) {\n delete _noteCache.inflightPost[note.id];\n if (err) { return callback(err); }\n\n // we get the updated note back, remove from caches and reparse..\n this.removeNote(note);\n\n // update closed note cache - used to populate `closed:note` changeset tag\n if (action === 'close') {\n _noteCache.closed[note.id] = true;\n } else if (action === 'reopen') {\n delete _noteCache.closed[note.id];\n }\n\n var options = { skipSeen: false };\n return parseXML(xml, function(err, results) {\n if (err) {\n return callback(err);\n } else {\n return callback(undefined, results[0]);\n }\n }, options);\n }\n },\n\n\n switch: function(options) {\n urlroot = options.urlroot;\n\n oauth.options(Object.assign({\n url: urlroot,\n loading: authLoading,\n done: authDone\n }, options));\n\n this.reset();\n this.userChangesets(function() {}); // eagerly load user details/changesets\n dispatch.call('change');\n return this;\n },\n\n\n toggle: function(val) {\n _off = !val;\n return this;\n },\n\n\n isChangesetInflight: function() {\n return !!_changeset.inflight;\n },\n\n\n // get/set cached data\n // This is used to save/restore the state when entering/exiting the walkthrough\n // Also used for testing purposes.\n caches: function(obj) {\n function cloneCache(source) {\n var target = {};\n Object.keys(source).forEach(function(k) {\n if (k === 'rtree') {\n target.rtree = new RBush().fromJSON(source.rtree.toJSON()); // clone rbush\n } else if (k === 'note') {\n target.note = {};\n Object.keys(source.note).forEach(function(id) {\n target.note[id] = osmNote(source.note[id]); // copy notes\n });\n } else {\n target[k] = JSON.parse(JSON.stringify(source[k])); // clone deep\n }\n });\n return target;\n }\n\n if (!arguments.length) {\n return {\n tile: cloneCache(_tileCache),\n note: cloneCache(_noteCache),\n user: cloneCache(_userCache)\n };\n }\n\n // access caches directly for testing (e.g., loading notes rtree)\n if (obj === 'get') {\n return {\n tile: _tileCache,\n note: _noteCache,\n user: _userCache\n };\n }\n\n if (obj.tile) {\n _tileCache = obj.tile;\n _tileCache.inflight = {};\n }\n if (obj.note) {\n _noteCache = obj.note;\n _noteCache.inflight = {};\n _noteCache.inflightPost = {};\n }\n if (obj.user) {\n _userCache = obj.user;\n }\n\n return this;\n },\n\n\n logout: function() {\n _userChangesets = undefined;\n _userDetails = undefined;\n oauth.logout();\n dispatch.call('change');\n return this;\n },\n\n\n authenticated: function() {\n return oauth.authenticated();\n },\n\n\n authenticate: function(callback) {\n var that = this;\n var cid = _connectionID;\n _userChangesets = undefined;\n _userDetails = undefined;\n\n function done(err, res) {\n if (err) {\n if (callback) callback(err);\n return;\n }\n if (that.getConnectionId() !== cid) {\n if (callback) callback({ message: 'Connection Switched', status: -1 });\n return;\n }\n _rateLimitError = undefined;\n dispatch.call('change');\n if (callback) callback(err, res);\n that.userChangesets(function() {}); // eagerly load user details/changesets\n }\n\n return oauth.authenticate(done);\n },\n\n\n imageryBlacklists: function() {\n return _blacklists;\n },\n\n\n tileZoom: function(val) {\n if (!arguments.length) return _tileZoom;\n _tileZoom = val;\n return this;\n },\n\n\n // get all cached notes covering the viewport\n notes: function(projection) {\n var viewport = projection.clipExtent();\n var min = [viewport[0][0], viewport[1][1]];\n var max = [viewport[1][0], viewport[0][1]];\n var bbox = geoExtent(projection.invert(min), projection.invert(max)).bbox();\n\n return _noteCache.rtree.search(bbox)\n .map(function(d) { return d.data; });\n },\n\n\n // get a single note from the cache\n getNote: function(id) {\n return _noteCache.note[id];\n },\n\n\n // remove a single note from the cache\n removeNote: function(note) {\n if (!(note instanceof osmNote) || !note.id) return;\n\n delete _noteCache.note[note.id];\n updateRtree(encodeNoteRtree(note), false); // false = remove\n },\n\n\n // replace a single note in the cache\n replaceNote: function(note) {\n if (!(note instanceof osmNote) || !note.id) return;\n\n _noteCache.note[note.id] = note;\n updateRtree(encodeNoteRtree(note), true); // true = replace\n return note;\n },\n\n\n // Get an array of note IDs closed during this session.\n // Used to populate `closed:note` changeset tag\n getClosedIDs: function() {\n return Object.keys(_noteCache.closed).sort();\n }\n\n};\n","import _debounce from 'lodash-es/debounce';\n\nimport { json as d3_json } from 'd3-fetch';\n\nimport { localizer } from '../core/localizer';\nimport { utilQsString } from '../util';\n\n\nvar apibase = 'https://wiki.openstreetmap.org/w/api.php';\nvar _inflight = {};\nvar _wikibaseCache = {};\nvar _localeIDs = { en: false };\n\n\nvar debouncedRequest = _debounce(request, 500, { leading: false });\n\nfunction request(url, callback) {\n if (_inflight[url]) return;\n var controller = new AbortController();\n _inflight[url] = controller;\n\n d3_json(url, { signal: controller.signal })\n .then(function(result) {\n delete _inflight[url];\n if (callback) callback(null, result);\n })\n .catch(function(err) {\n delete _inflight[url];\n if (err.name === 'AbortError') return;\n if (callback) callback(err.message);\n });\n}\n\n\n/**\n * Get the best string value from the descriptions/labels result\n * Note that if mediawiki doesn't recognize language code, it will return all values.\n * In that case, fallback to use English.\n * @param values object - either descriptions or labels\n * @param langCode String\n * @returns localized string\n */\nfunction localizedToString(values, langCode) {\n if (values) {\n values = values[langCode] || values.en;\n }\n return values ? values.value : '';\n}\n\n\nexport default {\n\n init: function() {\n _inflight = {};\n _wikibaseCache = {};\n _localeIDs = {};\n },\n\n\n reset: function() {\n Object.values(_inflight).forEach(function(controller) { controller.abort(); });\n _inflight = {};\n },\n\n\n /**\n * Get the best value for the property, or undefined if not found\n * @param entity object from wikibase\n * @param property string e.g. 'P4' for image\n * @param langCode string e.g. 'fr' for French\n */\n claimToValue: function(entity, property, langCode) {\n if (!entity.claims[property]) return undefined;\n var locale = _localeIDs[langCode];\n var preferredPick, localePick;\n\n entity.claims[property].forEach(function(stmt) {\n // If exists, use value limited to the needed language (has a qualifier P26 = locale)\n // Or if not found, use the first value with the \"preferred\" rank\n if (!preferredPick && stmt.rank === 'preferred') {\n preferredPick = stmt;\n }\n if (locale && stmt.qualifiers && stmt.qualifiers.P26 &&\n stmt.qualifiers.P26[0].datavalue.value.id === locale\n ) {\n localePick = stmt;\n }\n });\n\n var result = localePick || preferredPick;\n if (result) {\n var datavalue = result.mainsnak.datavalue;\n return datavalue.type === 'wikibase-entityid' ? datavalue.value.id : datavalue.value;\n } else {\n return undefined;\n }\n },\n\n\n /**\n * Convert monolingual property into a key-value object (language -> value)\n * @param entity object from wikibase\n * @param property string e.g. 'P31' for monolingual wiki page title\n */\n monolingualClaimToValueObj: function(entity, property) {\n if (!entity || !entity.claims[property]) return undefined;\n\n return entity.claims[property].reduce(function(acc, obj) {\n var value = obj.mainsnak.datavalue.value;\n acc[value.language] = value.text;\n return acc;\n }, {});\n },\n\n\n toSitelink: function(key, value) {\n var result = value ? ('Tag:' + key + '=' + value) : 'Key:' + key;\n return result.replace(/_/g, ' ').trim();\n },\n\n\n //\n // Pass params object of the form:\n // {\n // key: 'string',\n // value: 'string',\n // rtype: 'string',\n // langCode: 'string'\n // }\n //\n getEntity: function(params, callback) {\n var doRequest = params.debounce ? debouncedRequest : request;\n var that = this;\n var titles = [];\n var result = {};\n var rtypeSitelink = params.rtype ? ('Relation:' + params.rtype).replace(/_/g, ' ').trim() : false;\n var keySitelink = params.key ? this.toSitelink(params.key) : false;\n var tagSitelink = (params.key && params.value) ? this.toSitelink(params.key, params.value) : false;\n var localeSitelink;\n\n if (params.langCode && _localeIDs[params.langCode] === undefined) {\n // If this is the first time we are asking about this locale,\n // fetch corresponding entity (if it exists), and cache it.\n // If there is no such entry, cache `false` value to avoid re-requesting it.\n localeSitelink = ('Locale:' + params.langCode).replace(/_/g, ' ').trim();\n titles.push(localeSitelink);\n }\n\n if (rtypeSitelink) {\n if (_wikibaseCache[rtypeSitelink]) {\n result.rtype = _wikibaseCache[rtypeSitelink];\n } else {\n titles.push(rtypeSitelink);\n }\n }\n\n if (keySitelink) {\n if (_wikibaseCache[keySitelink]) {\n result.key = _wikibaseCache[keySitelink];\n } else {\n titles.push(keySitelink);\n }\n }\n\n if (tagSitelink) {\n if (_wikibaseCache[tagSitelink]) {\n result.tag = _wikibaseCache[tagSitelink];\n } else {\n titles.push(tagSitelink);\n }\n }\n\n if (!titles.length) {\n // Nothing to do, we already had everything in the cache\n return callback(null, result);\n }\n\n // Requesting just the user language code\n // If backend recognizes the code, it will perform proper fallbacks,\n // and the result will contain the requested code. If not, all values are returned:\n // {\"zh-tw\":{\"value\":\"...\",\"language\":\"zh-tw\",\"source-language\":\"zh-hant\"}\n // {\"pt-br\":{\"value\":\"...\",\"language\":\"pt\",\"for-language\":\"pt-br\"}}\n var obj = {\n action: 'wbgetentities',\n sites: 'wiki',\n titles: titles.join('|'),\n languages: params.langCode,\n languagefallback: 1,\n origin: '*',\n format: 'json',\n // There is an MW Wikibase API bug https://phabricator.wikimedia.org/T212069\n // We shouldn't use v1 until it gets fixed, but should switch to it afterwards\n // formatversion: 2,\n };\n\n var url = apibase + '?' + utilQsString(obj);\n doRequest(url, function(err, d) {\n if (err) {\n callback(err);\n } else if (!d.success || d.error) {\n callback(d.error.messages.map(function(v) { return v.html['*']; }).join(' '));\n } else {\n var localeID = false;\n Object.values(d.entities).forEach(function(res) {\n if (res.missing !== '') {\n // Simplify access to the localized values\n res.description = localizedToString(res.descriptions, params.langCode);\n res.label = localizedToString(res.labels, params.langCode);\n\n var title = res.sitelinks.wiki.title;\n if (title === rtypeSitelink) {\n _wikibaseCache[rtypeSitelink] = res;\n result.rtype = res;\n } else if (title === keySitelink) {\n _wikibaseCache[keySitelink] = res;\n result.key = res;\n } else if (title === tagSitelink) {\n _wikibaseCache[tagSitelink] = res;\n result.tag = res;\n } else if (title === localeSitelink) {\n localeID = res.id;\n } else {\n console.log('Unexpected title ' + title); // eslint-disable-line no-console\n }\n }\n });\n\n if (localeSitelink) {\n // If locale ID is not found, store false to prevent repeated queries\n that.addLocale(params.langCode, localeID);\n }\n\n callback(null, result);\n }\n });\n },\n\n\n //\n // Pass params object of the form:\n // {\n // key: 'string', // required\n // value: 'string' // optional\n // }\n // -or-\n // {\n // rtype: 'rtype' // relation type (e.g. 'multipolygon')\n // }\n //\n // Get an result object used to display tag documentation\n // {\n // title: 'string',\n // description: 'string',\n // editURL: 'string',\n // imageURL: 'string',\n // wiki: { title: 'string', text: 'string', url: 'string' }\n // }\n //\n getDocs: function(params, callback) {\n var that = this;\n var langCode = localizer.localeCode().toLowerCase();\n params.langCode = langCode;\n\n this.getEntity(params, function(err, data) {\n if (err) {\n callback(err);\n return;\n }\n\n var entity = data.rtype || data.tag || data.key;\n if (!entity) {\n callback('No entity');\n return;\n }\n\n // prepare result\n var result = {\n title: entity.title,\n description: entity.description,\n editURL: 'https://wiki.openstreetmap.org/wiki/' + entity.title\n };\n\n // add image\n if (entity.claims) {\n var imageroot;\n var image = that.claimToValue(entity, 'P4', langCode);\n if (image) {\n imageroot = 'https://commons.wikimedia.org/w/index.php';\n } else {\n image = that.claimToValue(entity, 'P28', langCode);\n if (image) {\n imageroot = 'https://wiki.openstreetmap.org/w/index.php';\n }\n }\n if (imageroot && image) {\n result.imageURL = imageroot + '?' + utilQsString({\n title: 'Special:Redirect/file/' + image,\n width: 400\n });\n }\n }\n\n // Try to get a wiki page from tag data item first, followed by the corresponding key data item.\n // If neither tag nor key data item contain a wiki page in the needed language nor English,\n // get the first found wiki page from either the tag or the key item.\n var rtypeWiki = that.monolingualClaimToValueObj(data.rtype, 'P31');\n var tagWiki = that.monolingualClaimToValueObj(data.tag, 'P31');\n var keyWiki = that.monolingualClaimToValueObj(data.key, 'P31');\n\n // If exact language code does not exist, try to find the first part before the '-'\n // BUG: in some cases, a more elaborate fallback logic might be needed\n var langPrefix = langCode.split('-', 2)[0];\n\n // use the first acceptable wiki page\n result.wiki =\n getWikiInfo(rtypeWiki, langCode, 'inspector.wiki_reference') ||\n getWikiInfo(rtypeWiki, langPrefix, 'inspector.wiki_reference') ||\n getWikiInfo(rtypeWiki, 'en', 'inspector.wiki_en_reference') ||\n getWikiInfo(tagWiki, langCode, 'inspector.wiki_reference') ||\n getWikiInfo(tagWiki, langPrefix, 'inspector.wiki_reference') ||\n getWikiInfo(tagWiki, 'en', 'inspector.wiki_en_reference') ||\n getWikiInfo(keyWiki, langCode, 'inspector.wiki_reference') ||\n getWikiInfo(keyWiki, langPrefix, 'inspector.wiki_reference') ||\n getWikiInfo(keyWiki, 'en', 'inspector.wiki_en_reference');\n\n callback(null, result);\n\n\n // Helper method to get wiki info if a given language exists\n function getWikiInfo(wiki, langCode, tKey) {\n if (wiki && wiki[langCode]) {\n return {\n title: wiki[langCode],\n text: tKey,\n url: 'https://wiki.openstreetmap.org/wiki/' + wiki[langCode]\n };\n }\n }\n });\n },\n\n\n addLocale: function(langCode, qid) {\n // Makes it easier to unit test\n _localeIDs[langCode] = qid;\n },\n\n\n apibase: function(val) {\n if (!arguments.length) return apibase;\n apibase = val;\n return this;\n }\n\n};\n","import { select as d3_select } from 'd3-selection';\n\nvar jsonpCache = {};\nwindow.jsonpCache = jsonpCache;\n\nexport function jsonpRequest(url, callback) {\n var request = {\n abort: function() {}\n };\n\n if (window.JSONP_FIX) {\n if (window.JSONP_DELAY === 0) {\n callback(window.JSONP_FIX);\n } else {\n var t = window.setTimeout(function() {\n callback(window.JSONP_FIX);\n }, window.JSONP_DELAY || 0);\n\n request.abort = function() { window.clearTimeout(t); };\n }\n\n return request;\n }\n\n function rand() {\n var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n var c = '';\n var i = -1;\n while (++i < 15) c += chars.charAt(Math.floor(Math.random() * 52));\n return c;\n }\n\n function create(url) {\n var e = url.match(/callback=(\\w+)/);\n var c = e ? e[1] : rand();\n\n jsonpCache[c] = function(data) {\n if (jsonpCache[c]) {\n callback(data);\n }\n finalize();\n };\n\n function finalize() {\n delete jsonpCache[c];\n script.remove();\n }\n\n request.abort = finalize;\n return 'jsonpCache.' + c;\n }\n\n var cb = create(url);\n\n var script = d3_select('head')\n .append('script')\n .attr('type', 'text/javascript')\n .attr('src', url.replace(/(\\{|%7B)callback(\\}|%7D)/, cb));\n\n return request;\n}\n","import { dispatch as d3_dispatch } from 'd3-dispatch';\nimport { timer as d3_timer } from 'd3-timer';\n\nimport {\n event as d3_event,\n select as d3_select\n} from 'd3-selection';\n\nimport RBush from 'rbush';\nimport { t, localizer } from '../core/localizer';\nimport { jsonpRequest } from '../util/jsonp_request';\n\nimport {\n geoExtent, geoMetersToLat, geoMetersToLon, geoPointInPolygon,\n geoRotate, geoScaleToZoom, geoVecLength\n} from '../geo';\n\nimport { utilArrayUnion, utilQsString, utilRebind, utilTiler, utilUniqueDomId } from '../util';\n\n\nconst bubbleApi = 'https://dev.virtualearth.net/mapcontrol/HumanScaleServices/GetBubbles.ashx?';\nconst streetsideImagesApi = 'https://t.ssl.ak.tiles.virtualearth.net/tiles/';\nconst bubbleAppKey = 'AuftgJsO0Xs8Ts4M1xZUQJQXJNsvmh3IV8DkNieCiy3tCwCUMq76-WpkrBtNAuEm';\nconst pannellumViewerCSS = 'pannellum-streetside/pannellum.css';\nconst pannellumViewerJS = 'pannellum-streetside/pannellum.js';\nconst maxResults = 2000;\nconst tileZoom = 16.5;\nconst tiler = utilTiler().zoomExtent([tileZoom, tileZoom]).skipNullIsland(true);\nconst dispatch = d3_dispatch('loadedBubbles', 'viewerChanged');\nconst minHfov = 10; // zoom in degrees: 20, 10, 5\nconst maxHfov = 90; // zoom out degrees\nconst defaultHfov = 45;\n\nlet _hires = false;\nlet _resolution = 512; // higher numbers are slower - 512, 1024, 2048, 4096\nlet _currScene = 0;\nlet _ssCache;\nlet _pannellumViewer;\nlet _sceneOptions;\nlet _dataUrlArray = [];\n\n\n/**\n * abortRequest().\n */\nfunction abortRequest(i) {\n i.abort();\n}\n\n\n/**\n * localeTimeStamp().\n */\nfunction localeTimestamp(s) {\n if (!s) return null;\n const options = { day: 'numeric', month: 'short', year: 'numeric' };\n const d = new Date(s);\n if (isNaN(d.getTime())) return null;\n return d.toLocaleString(localizer.localeCode(), options);\n}\n\n\n/**\n * loadTiles() wraps the process of generating tiles and then fetching image points for each tile.\n */\nfunction loadTiles(which, url, projection, margin) {\n const tiles = tiler.margin(margin).getTiles(projection);\n\n // abort inflight requests that are no longer needed\n const cache = _ssCache[which];\n Object.keys(cache.inflight).forEach(k => {\n const wanted = tiles.find(tile => k.indexOf(tile.id + ',') === 0);\n if (!wanted) {\n abortRequest(cache.inflight[k]);\n delete cache.inflight[k];\n }\n });\n\n tiles.forEach(tile => loadNextTilePage(which, url, tile));\n}\n\n\n/**\n * loadNextTilePage() load data for the next tile page in line.\n */\nfunction loadNextTilePage(which, url, tile) {\n const cache = _ssCache[which];\n const nextPage = cache.nextPage[tile.id] || 0;\n const id = tile.id + ',' + String(nextPage);\n if (cache.loaded[id] || cache.inflight[id]) return;\n\n cache.inflight[id] = getBubbles(url, tile, (bubbles) => {\n cache.loaded[id] = true;\n delete cache.inflight[id];\n if (!bubbles) return;\n\n // [].shift() removes the first element, some statistics info, not a bubble point\n bubbles.shift();\n\n const features = bubbles.map(bubble => {\n if (cache.points[bubble.id]) return null; // skip duplicates\n\n const loc = [bubble.lo, bubble.la];\n const d = {\n loc: loc,\n key: bubble.id,\n ca: bubble.he,\n captured_at: bubble.cd,\n captured_by: 'microsoft',\n // nbn: bubble.nbn,\n // pbn: bubble.pbn,\n // ad: bubble.ad,\n // rn: bubble.rn,\n pr: bubble.pr, // previous\n ne: bubble.ne, // next\n pano: true,\n sequenceKey: null\n };\n\n cache.points[bubble.id] = d;\n\n // a sequence starts here\n if (bubble.pr === undefined) {\n cache.leaders.push(bubble.id);\n }\n\n return {\n minX: loc[0], minY: loc[1], maxX: loc[0], maxY: loc[1], data: d\n };\n\n }).filter(Boolean);\n\n cache.rtree.load(features);\n\n connectSequences();\n\n if (which === 'bubbles') {\n dispatch.call('loadedBubbles');\n }\n });\n}\n\n\n// call this sometimes to connect the bubbles into sequences\nfunction connectSequences() {\n let cache = _ssCache.bubbles;\n let keepLeaders = [];\n\n for (let i = 0; i < cache.leaders.length; i++) {\n let bubble = cache.points[cache.leaders[i]];\n let seen = {};\n\n // try to make a sequence.. use the key of the leader bubble.\n let sequence = { key: bubble.key, bubbles: [] };\n let complete = false;\n\n do {\n sequence.bubbles.push(bubble);\n seen[bubble.key] = true;\n\n if (bubble.ne === undefined) {\n complete = true;\n } else {\n bubble = cache.points[bubble.ne]; // advance to next\n }\n } while (bubble && !seen[bubble.key] && !complete);\n\n\n if (complete) {\n _ssCache.sequences[sequence.key] = sequence;\n\n // assign bubbles to the sequence\n for (let j = 0; j < sequence.bubbles.length; j++) {\n sequence.bubbles[j].sequenceKey = sequence.key;\n }\n\n // create a GeoJSON LineString\n sequence.geojson = {\n type: 'LineString',\n properties: { key: sequence.key },\n coordinates: sequence.bubbles.map(d => d.loc)\n };\n\n } else {\n keepLeaders.push(cache.leaders[i]);\n }\n }\n\n // couldn't complete these, save for later\n cache.leaders = keepLeaders;\n}\n\n\n/**\n * getBubbles() handles the request to the server for a tile extent of 'bubbles' (streetside image locations).\n */\nfunction getBubbles(url, tile, callback) {\n let rect = tile.extent.rectangle();\n let urlForRequest = url + utilQsString({\n n: rect[3],\n s: rect[1],\n e: rect[2],\n w: rect[0],\n c: maxResults,\n appkey: bubbleAppKey,\n jsCallback: '{callback}'\n });\n\n return jsonpRequest(urlForRequest, (data) => {\n if (!data || data.error) {\n callback(null);\n } else {\n callback(data);\n }\n });\n}\n\n\n// partition viewport into higher zoom tiles\nfunction partitionViewport(projection) {\n let z = geoScaleToZoom(projection.scale());\n let z2 = (Math.ceil(z * 2) / 2) + 2.5; // round to next 0.5 and add 2.5\n let tiler = utilTiler().zoomExtent([z2, z2]);\n\n return tiler.getTiles(projection)\n .map(tile => tile.extent);\n}\n\n\n// no more than `limit` results per partition.\nfunction searchLimited(limit, projection, rtree) {\n limit = limit || 5;\n\n return partitionViewport(projection)\n .reduce((result, extent) => {\n let found = rtree.search(extent.bbox())\n .slice(0, limit)\n .map(d => d.data);\n\n return (found.length ? result.concat(found) : result);\n }, []);\n}\n\n\n/**\n * loadImage()\n */\nfunction loadImage(imgInfo) {\n return new Promise(resolve => {\n let img = new Image();\n img.onload = () => {\n let canvas = document.getElementById('ideditor-canvas' + imgInfo.face);\n let ctx = canvas.getContext('2d');\n ctx.drawImage(img, imgInfo.x, imgInfo.y);\n resolve({ imgInfo: imgInfo, status: 'ok' });\n };\n img.onerror = () => {\n resolve({ data: imgInfo, status: 'error' });\n };\n img.setAttribute('crossorigin', '');\n img.src = imgInfo.url;\n });\n}\n\n\n/**\n * loadCanvas()\n */\nfunction loadCanvas(imageGroup) {\n return Promise.all(imageGroup.map(loadImage))\n .then((data) => {\n let canvas = document.getElementById('ideditor-canvas' + data[0].imgInfo.face);\n const which = { '01': 0, '02': 1, '03': 2, '10': 3, '11': 4, '12': 5 };\n let face = data[0].imgInfo.face;\n _dataUrlArray[which[face]] = canvas.toDataURL('image/jpeg', 1.0);\n return { status: 'loadCanvas for face ' + data[0].imgInfo.face + 'ok'};\n });\n}\n\n\n/**\n * loadFaces()\n */\nfunction loadFaces(faceGroup) {\n return Promise.all(faceGroup.map(loadCanvas))\n .then(() => { return { status: 'loadFaces done' }; });\n}\n\n\nfunction setupCanvas(selection, reset) {\n if (reset) {\n selection.selectAll('#ideditor-stitcher-canvases')\n .remove();\n }\n\n // Add the Streetside working canvases. These are used for 'stitching', or combining,\n // multiple images for each of the six faces, before passing to the Pannellum control as DataUrls\n selection.selectAll('#ideditor-stitcher-canvases')\n .data([0])\n .enter()\n .append('div')\n .attr('id', 'ideditor-stitcher-canvases')\n .attr('display', 'none')\n .selectAll('canvas')\n .data(['canvas01', 'canvas02', 'canvas03', 'canvas10', 'canvas11', 'canvas12'])\n .enter()\n .append('canvas')\n .attr('id', d => 'ideditor-' + d)\n .attr('width', _resolution)\n .attr('height', _resolution);\n}\n\n\nfunction qkToXY(qk) {\n let x = 0;\n let y = 0;\n let scale = 256;\n for (let i = qk.length; i > 0; i--) {\n const key = qk[i-1];\n x += (+(key === '1' || key === '3')) * scale;\n y += (+(key === '2' || key === '3')) * scale;\n scale *= 2;\n }\n return [x, y];\n}\n\n\nfunction getQuadKeys() {\n let dim = _resolution / 256;\n let quadKeys;\n\n if (dim === 16) {\n quadKeys = [\n '0000','0001','0010','0011','0100','0101','0110','0111', '1000','1001','1010','1011','1100','1101','1110','1111',\n '0002','0003','0012','0013','0102','0103','0112','0113', '1002','1003','1012','1013','1102','1103','1112','1113',\n '0020','0021','0030','0031','0120','0121','0130','0131', '1020','1021','1030','1031','1120','1121','1130','1131',\n '0022','0023','0032','0033','0122','0123','0132','0133', '1022','1023','1032','1033','1122','1123','1132','1133',\n '0200','0201','0210','0211','0300','0301','0310','0311', '1200','1201','1210','1211','1300','1301','1310','1311',\n '0202','0203','0212','0213','0302','0303','0312','0313', '1202','1203','1212','1213','1302','1303','1312','1313',\n '0220','0221','0230','0231','0320','0321','0330','0331', '1220','1221','1230','1231','1320','1321','1330','1331',\n '0222','0223','0232','0233','0322','0323','0332','0333', '1222','1223','1232','1233','1322','1323','1332','1333',\n\n '2000','2001','2010','2011','2100','2101','2110','2111', '3000','3001','3010','3011','3100','3101','3110','3111',\n '2002','2003','2012','2013','2102','2103','2112','2113', '3002','3003','3012','3013','3102','3103','3112','3113',\n '2020','2021','2030','2031','2120','2121','2130','2131', '3020','3021','3030','3031','3120','3121','3130','3131',\n '2022','2023','2032','2033','2122','2123','2132','2133', '3022','3023','3032','3033','3122','3123','3132','3133',\n '2200','2201','2210','2211','2300','2301','2310','2311', '3200','3201','3210','3211','3300','3301','3310','3311',\n '2202','2203','2212','2213','2302','2303','2312','2313', '3202','3203','3212','3213','3302','3303','3312','3313',\n '2220','2221','2230','2231','2320','2321','2330','2331', '3220','3221','3230','3231','3320','3321','3330','3331',\n '2222','2223','2232','2233','2322','2323','2332','2333', '3222','3223','3232','3233','3322','3323','3332','3333'\n ];\n\n } else if (dim === 8) {\n quadKeys = [\n '000','001','010','011', '100','101','110','111',\n '002','003','012','013', '102','103','112','113',\n '020','021','030','031', '120','121','130','131',\n '022','023','032','033', '122','123','132','133',\n\n '200','201','210','211', '300','301','310','311',\n '202','203','212','213', '302','303','312','313',\n '220','221','230','231', '320','321','330','331',\n '222','223','232','233', '322','323','332','333'\n ];\n\n } else if (dim === 4) {\n quadKeys = [\n '00','01', '10','11',\n '02','03', '12','13',\n\n '20','21', '30','31',\n '22','23', '32','33'\n ];\n\n } else { // dim === 2\n quadKeys = [\n '0', '1',\n '2', '3'\n ];\n }\n\n return quadKeys;\n}\n\n\n\nexport default {\n /**\n * init() initialize streetside.\n */\n init: function() {\n if (!_ssCache) {\n this.reset();\n }\n\n this.event = utilRebind(this, dispatch, 'on');\n },\n\n /**\n * reset() reset the cache.\n */\n reset: function() {\n if (_ssCache) {\n Object.values(_ssCache.bubbles.inflight).forEach(abortRequest);\n }\n\n _ssCache = {\n bubbles: { inflight: {}, loaded: {}, nextPage: {}, rtree: new RBush(), points: {}, leaders: [] },\n sequences: {}\n };\n },\n\n /**\n * bubbles()\n */\n bubbles: function(projection) {\n const limit = 5;\n return searchLimited(limit, projection, _ssCache.bubbles.rtree);\n },\n\n\n sequences: function(projection) {\n const viewport = projection.clipExtent();\n const min = [viewport[0][0], viewport[1][1]];\n const max = [viewport[1][0], viewport[0][1]];\n const bbox = geoExtent(projection.invert(min), projection.invert(max)).bbox();\n let seen = {};\n let results = [];\n\n // all sequences for bubbles in viewport\n _ssCache.bubbles.rtree.search(bbox)\n .forEach(d => {\n const key = d.data.sequenceKey;\n if (key && !seen[key]) {\n seen[key] = true;\n results.push(_ssCache.sequences[key].geojson);\n }\n });\n\n return results;\n },\n\n\n /**\n * loadBubbles()\n */\n loadBubbles: function(projection, margin) {\n // by default: request 2 nearby tiles so we can connect sequences.\n if (margin === undefined) margin = 2;\n\n loadTiles('bubbles', bubbleApi, projection, margin);\n },\n\n\n viewer: function() {\n return _pannellumViewer;\n },\n\n\n initViewer: function () {\n if (!window.pannellum) return;\n if (_pannellumViewer) return;\n\n const sceneID = ++_currScene + '';\n const options = {\n 'default': { firstScene: sceneID },\n scenes: {}\n };\n options.scenes[sceneID] = _sceneOptions;\n\n _pannellumViewer = window.pannellum.viewer('ideditor-viewer-streetside', options);\n },\n\n\n /**\n * loadViewer() create the streeside viewer.\n */\n loadViewer: function(context) {\n let that = this;\n\n let pointerPrefix = 'PointerEvent' in window ? 'pointer' : 'mouse';\n\n // create ms-wrapper, a photo wrapper class\n let wrap = context.container().select('.photoviewer').selectAll('.ms-wrapper')\n .data([0]);\n\n // inject ms-wrapper into the photoviewer div\n // (used by all to house each custom photo viewer)\n let wrapEnter = wrap.enter()\n .append('div')\n .attr('class', 'photo-wrapper ms-wrapper')\n .classed('hide', true);\n\n // inject div to support streetside viewer (pannellum) and attribution line\n wrapEnter\n .append('div')\n .attr('id', 'ideditor-viewer-streetside')\n .on(pointerPrefix + 'down.streetside', () => {\n d3_select(window)\n .on(pointerPrefix + 'move.streetside', () => {\n dispatch.call('viewerChanged');\n }, true);\n })\n .on(pointerPrefix + 'up.streetside pointercancel.streetside', () => {\n d3_select(window)\n .on(pointerPrefix + 'move.streetside', null);\n\n // continue dispatching events for a few seconds, in case viewer has inertia.\n let t = d3_timer(elapsed => {\n dispatch.call('viewerChanged');\n if (elapsed > 2000) {\n t.stop();\n }\n });\n })\n .append('div')\n .attr('class', 'photo-attribution fillD');\n\n let controlsEnter = wrapEnter\n .append('div')\n .attr('class', 'photo-controls-wrap')\n .append('div')\n .attr('class', 'photo-controls');\n\n controlsEnter\n .append('button')\n .on('click.back', step(-1))\n .text('◄');\n\n controlsEnter\n .append('button')\n .on('click.forward', step(1))\n .text('►');\n\n\n // create working canvas for stitching together images\n wrap = wrap\n .merge(wrapEnter)\n .call(setupCanvas, true);\n\n // load streetside pannellum viewer css\n d3_select('head').selectAll('#ideditor-streetside-viewercss')\n .data([0])\n .enter()\n .append('link')\n .attr('id', 'ideditor-streetside-viewercss')\n .attr('rel', 'stylesheet')\n .attr('href', context.asset(pannellumViewerCSS));\n\n // load streetside pannellum viewer js\n d3_select('head').selectAll('#ideditor-streetside-viewerjs')\n .data([0])\n .enter()\n .append('script')\n .attr('id', 'ideditor-streetside-viewerjs')\n .attr('src', context.asset(pannellumViewerJS));\n\n\n // Register viewer resize handler\n context.ui().photoviewer.on('resize.streetside', () => {\n if (_pannellumViewer) {\n _pannellumViewer.resize();\n }\n });\n\n\n function step(stepBy) {\n return () => {\n let viewer = context.container().select('.photoviewer');\n let selected = viewer.empty() ? undefined : viewer.datum();\n if (!selected) return;\n\n let nextID = (stepBy === 1 ? selected.ne : selected.pr);\n let yaw = _pannellumViewer.getYaw();\n let ca = selected.ca + yaw;\n let origin = selected.loc;\n\n // construct a search trapezoid pointing out from current bubble\n const meters = 35;\n let p1 = [\n origin[0] + geoMetersToLon(meters / 5, origin[1]),\n origin[1]\n ];\n let p2 = [\n origin[0] + geoMetersToLon(meters / 2, origin[1]),\n origin[1] + geoMetersToLat(meters)\n ];\n let p3 = [\n origin[0] - geoMetersToLon(meters / 2, origin[1]),\n origin[1] + geoMetersToLat(meters)\n ];\n let p4 = [\n origin[0] - geoMetersToLon(meters / 5, origin[1]),\n origin[1]\n ];\n\n let poly = [p1, p2, p3, p4, p1];\n\n // rotate it to face forward/backward\n let angle = (stepBy === 1 ? ca : ca + 180) * (Math.PI / 180);\n poly = geoRotate(poly, -angle, origin);\n\n let extent = poly.reduce((extent, point) => {\n return extent.extend(geoExtent(point));\n }, geoExtent());\n\n // find nearest other bubble in the search polygon\n let minDist = Infinity;\n _ssCache.bubbles.rtree.search(extent.bbox())\n .forEach(d => {\n if (d.data.key === selected.key) return;\n if (!geoPointInPolygon(d.data.loc, poly)) return;\n\n let dist = geoVecLength(d.data.loc, selected.loc);\n let theta = selected.ca - d.data.ca;\n let minTheta = Math.min(Math.abs(theta), 360 - Math.abs(theta));\n if (minTheta > 20) {\n dist += 5; // penalize distance if camera angles don't match\n }\n\n if (dist < minDist) {\n nextID = d.data.key;\n minDist = dist;\n }\n });\n\n let nextBubble = nextID && _ssCache.bubbles.points[nextID];\n if (!nextBubble) return;\n\n context.map().centerEase(nextBubble.loc);\n\n that.selectImage(context, nextBubble)\n .then(response => {\n if (response.status === 'ok') {\n _sceneOptions.yaw = yaw;\n that.showViewer(context);\n }\n });\n };\n }\n },\n\n\n /**\n * showViewer()\n */\n showViewer: function(context, yaw) {\n if (!_sceneOptions) return;\n\n if (yaw !== undefined) {\n _sceneOptions.yaw = yaw;\n }\n\n if (!_pannellumViewer) {\n this.initViewer();\n } else {\n // make a new scene\n let sceneID = ++_currScene + '';\n _pannellumViewer\n .addScene(sceneID, _sceneOptions)\n .loadScene(sceneID);\n\n // remove previous scene\n if (_currScene > 2) {\n sceneID = (_currScene - 1) + '';\n _pannellumViewer\n .removeScene(sceneID);\n }\n }\n\n let wrap = context.container().select('.photoviewer')\n .classed('hide', false);\n\n let isHidden = wrap.selectAll('.photo-wrapper.ms-wrapper.hide').size();\n\n if (isHidden) {\n wrap\n .selectAll('.photo-wrapper:not(.ms-wrapper)')\n .classed('hide', true);\n\n wrap\n .selectAll('.photo-wrapper.ms-wrapper')\n .classed('hide', false);\n }\n\n return this;\n },\n\n\n /**\n * hideViewer()\n */\n hideViewer: function (context) {\n let viewer = context.container().select('.photoviewer');\n if (!viewer.empty()) viewer.datum(null);\n\n viewer\n .classed('hide', true)\n .selectAll('.photo-wrapper')\n .classed('hide', true);\n\n context.container().selectAll('.viewfield-group, .sequence, .icon-sign')\n .classed('currentView', false);\n\n return this.setStyles(context, null, true);\n },\n\n\n /**\n * selectImage().\n */\n selectImage: function (context, d) {\n let that = this;\n let viewer = context.container().select('.photoviewer');\n if (!viewer.empty()) viewer.datum(d);\n\n this.setStyles(context, null, true);\n\n let wrap = context.container().select('.photoviewer .ms-wrapper');\n let attribution = wrap.selectAll('.photo-attribution').html('');\n\n wrap.selectAll('.pnlm-load-box') // display \"loading..\"\n .style('display', 'block');\n\n if (!d) {\n return Promise.resolve({ status: 'ok' });\n }\n\n let line1 = attribution\n .append('div')\n .attr('class', 'attribution-row');\n\n const hiresDomId = utilUniqueDomId('streetside-hires');\n\n // Add hires checkbox\n let label = line1\n .append('label')\n .attr('for', hiresDomId)\n .attr('class', 'streetside-hires');\n\n label\n .append('input')\n .attr('type', 'checkbox')\n .attr('id', hiresDomId)\n .property('checked', _hires)\n .on('click', () => {\n d3_event.stopPropagation();\n\n _hires = !_hires;\n _resolution = _hires ? 1024 : 512;\n wrap.call(setupCanvas, true);\n\n let viewstate = {\n yaw: _pannellumViewer.getYaw(),\n pitch: _pannellumViewer.getPitch(),\n hfov: _pannellumViewer.getHfov()\n };\n\n that.selectImage(context, d)\n .then(response => {\n if (response.status === 'ok') {\n _sceneOptions = Object.assign(_sceneOptions, viewstate);\n that.showViewer(context);\n }\n });\n });\n\n label\n .append('span')\n .text(t('streetside.hires'));\n\n\n let captureInfo = line1\n .append('div')\n .attr('class', 'attribution-capture-info');\n\n // Add capture date\n if (d.captured_by) {\n const yyyy = (new Date()).getFullYear();\n\n captureInfo\n .append('a')\n .attr('class', 'captured_by')\n .attr('target', '_blank')\n .attr('href', 'https://www.microsoft.com/en-us/maps/streetside')\n .text('©' + yyyy + ' Microsoft');\n\n captureInfo\n .append('span')\n .text('|');\n }\n\n if (d.captured_at) {\n captureInfo\n .append('span')\n .attr('class', 'captured_at')\n .text(localeTimestamp(d.captured_at));\n }\n\n // Add image links\n let line2 = attribution\n .append('div')\n .attr('class', 'attribution-row');\n\n line2\n .append('a')\n .attr('class', 'image-view-link')\n .attr('target', '_blank')\n .attr('href', 'https://www.bing.com/maps?cp=' + d.loc[1] + '~' + d.loc[0] +\n '&lvl=17&dir=' + d.ca + '&style=x&v=2&sV=1')\n .text(t('streetside.view_on_bing'));\n\n line2\n .append('a')\n .attr('class', 'image-report-link')\n .attr('target', '_blank')\n .attr('href', 'https://www.bing.com/maps/privacyreport/streetsideprivacyreport?bubbleid=' +\n encodeURIComponent(d.key) + '&focus=photo&lat=' + d.loc[1] + '&lng=' + d.loc[0] + '&z=17')\n .text(t('streetside.report'));\n\n\n let bubbleIdQuadKey = d.key.toString(4);\n const paddingNeeded = 16 - bubbleIdQuadKey.length;\n for (let i = 0; i < paddingNeeded; i++) {\n bubbleIdQuadKey = '0' + bubbleIdQuadKey;\n }\n const imgUrlPrefix = streetsideImagesApi + 'hs' + bubbleIdQuadKey;\n const imgUrlSuffix = '.jpg?g=6338&n=z';\n\n // Cubemap face code order matters here: front=01, right=02, back=03, left=10, up=11, down=12\n const faceKeys = ['01','02','03','10','11','12'];\n\n // Map images to cube faces\n let quadKeys = getQuadKeys();\n let faces = faceKeys.map((faceKey) => {\n return quadKeys.map((quadKey) =>{\n const xy = qkToXY(quadKey);\n return {\n face: faceKey,\n url: imgUrlPrefix + faceKey + quadKey + imgUrlSuffix,\n x: xy[0],\n y: xy[1]\n };\n });\n });\n\n return loadFaces(faces)\n .then(() => {\n _sceneOptions = {\n showFullscreenCtrl: false,\n autoLoad: true,\n compass: true,\n northOffset: d.ca,\n yaw: 0,\n minHfov: minHfov,\n maxHfov: maxHfov,\n hfov: defaultHfov,\n type: 'cubemap',\n cubeMap: [\n _dataUrlArray[0],\n _dataUrlArray[1],\n _dataUrlArray[2],\n _dataUrlArray[3],\n _dataUrlArray[4],\n _dataUrlArray[5]\n ]\n };\n return { status: 'ok' };\n });\n },\n\n\n getSequenceKeyForBubble: function(d) {\n return d && d.sequenceKey;\n },\n\n\n // Updates the currently highlighted sequence and selected bubble.\n // Reset is only necessary when interacting with the viewport because\n // this implicitly changes the currently selected bubble/sequence\n setStyles: function (context, hovered, reset) {\n if (reset) { // reset all layers\n context.container().selectAll('.viewfield-group')\n .classed('highlighted', false)\n .classed('hovered', false)\n .classed('currentView', false);\n\n context.container().selectAll('.sequence')\n .classed('highlighted', false)\n .classed('currentView', false);\n }\n\n let hoveredBubbleKey = hovered && hovered.key;\n let hoveredSequenceKey = this.getSequenceKeyForBubble(hovered);\n let hoveredSequence = hoveredSequenceKey && _ssCache.sequences[hoveredSequenceKey];\n let hoveredBubbleKeys = (hoveredSequence && hoveredSequence.bubbles.map(d => d.key)) || [];\n\n let viewer = context.container().select('.photoviewer');\n let selected = viewer.empty() ? undefined : viewer.datum();\n let selectedBubbleKey = selected && selected.key;\n let selectedSequenceKey = this.getSequenceKeyForBubble(selected);\n let selectedSequence = selectedSequenceKey && _ssCache.sequences[selectedSequenceKey];\n let selectedBubbleKeys = (selectedSequence && selectedSequence.bubbles.map(d => d.key)) || [];\n\n // highlight sibling viewfields on either the selected or the hovered sequences\n let highlightedBubbleKeys = utilArrayUnion(hoveredBubbleKeys, selectedBubbleKeys);\n\n context.container().selectAll('.layer-streetside-images .viewfield-group')\n .classed('highlighted', d => highlightedBubbleKeys.indexOf(d.key) !== -1)\n .classed('hovered', d => d.key === hoveredBubbleKey)\n .classed('currentView', d => d.key === selectedBubbleKey);\n\n context.container().selectAll('.layer-streetside-images .sequence')\n .classed('highlighted', d => d.properties.key === hoveredSequenceKey)\n .classed('currentView', d => d.properties.key === selectedSequenceKey);\n\n // update viewfields if needed\n context.container().selectAll('.viewfield-group .viewfield')\n .attr('d', viewfieldPath);\n\n function viewfieldPath() {\n let d = this.parentNode.__data__;\n if (d.pano && d.key !== selectedBubbleKey) {\n return 'M 8,13 m -10,0 a 10,10 0 1,0 20,0 a 10,10 0 1,0 -20,0';\n } else {\n return 'M 6,9 C 8,8.4 8,8.4 10,9 L 16,-2 C 12,-5 4,-5 0,-2 z';\n }\n }\n\n return this;\n },\n\n\n /**\n * cache().\n */\n cache: function () {\n return _ssCache;\n }\n};\n","import _debounce from 'lodash-es/debounce';\n\nimport { json as d3_json } from 'd3-fetch';\n\nimport { utilObjectOmit, utilQsString } from '../util';\nimport { localizer } from '../core/localizer';\n\n\nvar apibase = 'https://taginfo.openstreetmap.org/api/4/';\nvar _inflight = {};\nvar _popularKeys = {};\nvar _taginfoCache = {};\n\nvar tag_sorts = {\n point: 'count_nodes',\n vertex: 'count_nodes',\n area: 'count_ways',\n line: 'count_ways'\n};\nvar tag_sort_members = {\n point: 'count_node_members',\n vertex: 'count_node_members',\n area: 'count_way_members',\n line: 'count_way_members',\n relation: 'count_relation_members'\n};\nvar tag_filters = {\n point: 'nodes',\n vertex: 'nodes',\n area: 'ways',\n line: 'ways'\n};\nvar tag_members_fractions = {\n point: 'count_node_members_fraction',\n vertex: 'count_node_members_fraction',\n area: 'count_way_members_fraction',\n line: 'count_way_members_fraction',\n relation: 'count_relation_members_fraction'\n};\n\n\nfunction sets(params, n, o) {\n if (params.geometry && o[params.geometry]) {\n params[n] = o[params.geometry];\n }\n return params;\n}\n\n\nfunction setFilter(params) {\n return sets(params, 'filter', tag_filters);\n}\n\n\nfunction setSort(params) {\n return sets(params, 'sortname', tag_sorts);\n}\n\n\nfunction setSortMembers(params) {\n return sets(params, 'sortname', tag_sort_members);\n}\n\n\nfunction clean(params) {\n return utilObjectOmit(params, ['geometry', 'debounce']);\n}\n\n\nfunction filterKeys(type) {\n var count_type = type ? 'count_' + type : 'count_all';\n return function(d) {\n return parseFloat(d[count_type]) > 2500 || d.in_wiki;\n };\n}\n\n\nfunction filterMultikeys(prefix) {\n return function(d) {\n // d.key begins with prefix, and d.key contains no additional ':'s\n var re = new RegExp('^' + prefix + '(.*)$');\n var matches = d.key.match(re) || [];\n return (matches.length === 2 && matches[1].indexOf(':') === -1);\n };\n}\n\n\nfunction filterValues(allowUpperCase) {\n return function(d) {\n if (d.value.match(/[;,]/) !== null) return false; // exclude some punctuation\n if (!allowUpperCase && d.value.match(/[A-Z*]/) !== null) return false; // exclude uppercase letters\n return parseFloat(d.fraction) > 0.0;\n };\n}\n\n\nfunction filterRoles(geometry) {\n return function(d) {\n if (d.role === '') return false; // exclude empty role\n if (d.role.match(/[A-Z*;,]/) !== null) return false; // exclude uppercase letters and some punctuation\n return parseFloat(d[tag_members_fractions[geometry]]) > 0.0;\n };\n}\n\n\nfunction valKey(d) {\n return {\n value: d.key,\n title: d.key\n };\n}\n\n\nfunction valKeyDescription(d) {\n var obj = {\n value: d.value,\n title: d.description || d.value\n };\n if (d.count) {\n obj.count = d.count;\n }\n return obj;\n}\n\n\nfunction roleKey(d) {\n return {\n value: d.role,\n title: d.role\n };\n}\n\n\n// sort keys with ':' lower than keys without ':'\nfunction sortKeys(a, b) {\n return (a.key.indexOf(':') === -1 && b.key.indexOf(':') !== -1) ? -1\n : (a.key.indexOf(':') !== -1 && b.key.indexOf(':') === -1) ? 1\n : 0;\n}\n\n\nvar debouncedRequest = _debounce(request, 300, { leading: false });\n\nfunction request(url, params, exactMatch, callback, loaded) {\n if (_inflight[url]) return;\n\n if (checkCache(url, params, exactMatch, callback)) return;\n\n var controller = new AbortController();\n _inflight[url] = controller;\n\n d3_json(url, { signal: controller.signal })\n .then(function(result) {\n delete _inflight[url];\n if (loaded) loaded(null, result);\n })\n .catch(function(err) {\n delete _inflight[url];\n if (err.name === 'AbortError') return;\n if (loaded) loaded(err.message);\n });\n}\n\n\nfunction checkCache(url, params, exactMatch, callback) {\n var rp = params.rp || 25;\n var testQuery = params.query || '';\n var testUrl = url;\n\n do {\n var hit = _taginfoCache[testUrl];\n\n // exact match, or shorter match yielding fewer than max results (rp)\n if (hit && (url === testUrl || hit.length < rp)) {\n callback(null, hit);\n return true;\n }\n\n // don't try to shorten the query\n if (exactMatch || !testQuery.length) return false;\n\n // do shorten the query to see if we already have a cached result\n // that has returned fewer than max results (rp)\n testQuery = testQuery.slice(0, -1);\n testUrl = url.replace(/&query=(.*?)&/, '&query=' + testQuery + '&');\n } while (testQuery.length >= 0);\n\n return false;\n}\n\n\nexport default {\n\n init: function() {\n _inflight = {};\n _taginfoCache = {};\n _popularKeys = {\n // manually exclude some keys – #5377, #7485\n postal_code: true,\n full_name: true,\n loc_name: true,\n reg_name: true,\n short_name: true,\n sorting_name: true,\n artist_name: true,\n nat_name: true,\n long_name: true,\n 'bridge:name': true\n };\n\n // Fetch popular keys. We'll exclude these from `values`\n // lookups because they stress taginfo, and they aren't likely\n // to yield meaningful autocomplete results.. see #3955\n var params = {\n rp: 100,\n sortname: 'values_all',\n sortorder: 'desc',\n page: 1,\n debounce: false,\n lang: localizer.languageCode()\n };\n this.keys(params, function(err, data) {\n if (err) return;\n data.forEach(function(d) {\n if (d.value === 'opening_hours') return; // exception\n _popularKeys[d.value] = true;\n });\n });\n },\n\n\n reset: function() {\n Object.values(_inflight).forEach(function(controller) { controller.abort(); });\n _inflight = {};\n },\n\n\n keys: function(params, callback) {\n var doRequest = params.debounce ? debouncedRequest : request;\n params = clean(setSort(params));\n params = Object.assign({\n rp: 10,\n sortname: 'count_all',\n sortorder: 'desc',\n page: 1,\n lang: localizer.languageCode()\n }, params);\n\n var url = apibase + 'keys/all?' + utilQsString(params);\n doRequest(url, params, false, callback, function(err, d) {\n if (err) {\n callback(err);\n } else {\n var f = filterKeys(params.filter);\n var result = d.data.filter(f).sort(sortKeys).map(valKey);\n _taginfoCache[url] = result;\n callback(null, result);\n }\n });\n },\n\n\n multikeys: function(params, callback) {\n var doRequest = params.debounce ? debouncedRequest : request;\n params = clean(setSort(params));\n params = Object.assign({\n rp: 25,\n sortname: 'count_all',\n sortorder: 'desc',\n page: 1,\n lang: localizer.languageCode()\n }, params);\n\n var prefix = params.query;\n var url = apibase + 'keys/all?' + utilQsString(params);\n doRequest(url, params, true, callback, function(err, d) {\n if (err) {\n callback(err);\n } else {\n var f = filterMultikeys(prefix);\n var result = d.data.filter(f).map(valKey);\n _taginfoCache[url] = result;\n callback(null, result);\n }\n });\n },\n\n\n values: function(params, callback) {\n // Exclude popular keys from values lookups.. see #3955\n var key = params.key;\n if (key && _popularKeys[key]) {\n callback(null, []);\n return;\n }\n\n var doRequest = params.debounce ? debouncedRequest : request;\n params = clean(setSort(setFilter(params)));\n params = Object.assign({\n rp: 25,\n sortname: 'count_all',\n sortorder: 'desc',\n page: 1,\n lang: localizer.languageCode()\n }, params);\n\n var url = apibase + 'key/values?' + utilQsString(params);\n doRequest(url, params, false, callback, function(err, d) {\n if (err) {\n callback(err);\n } else {\n // In most cases we prefer taginfo value results with lowercase letters.\n // A few OSM keys expect values to contain uppercase values (see #3377).\n // This is not an exhaustive list (e.g. `name` also has uppercase values)\n // but these are the fields where taginfo value lookup is most useful.\n var re = /network|taxon|genus|species|brand|grape_variety|royal_cypher|listed_status|booth|rating|stars|:output|_hours|_times|_ref|manufacturer|country|target|brewery/;\n var allowUpperCase = re.test(params.key);\n var f = filterValues(allowUpperCase);\n\n var result = d.data.filter(f).map(valKeyDescription);\n _taginfoCache[url] = result;\n callback(null, result);\n }\n });\n },\n\n\n roles: function(params, callback) {\n var doRequest = params.debounce ? debouncedRequest : request;\n var geometry = params.geometry;\n params = clean(setSortMembers(params));\n params = Object.assign({\n rp: 25,\n sortname: 'count_all_members',\n sortorder: 'desc',\n page: 1,\n lang: localizer.languageCode()\n }, params);\n\n var url = apibase + 'relation/roles?' + utilQsString(params);\n doRequest(url, params, true, callback, function(err, d) {\n if (err) {\n callback(err);\n } else {\n var f = filterRoles(geometry);\n var result = d.data.filter(f).map(roleKey);\n _taginfoCache[url] = result;\n callback(null, result);\n }\n });\n },\n\n\n docs: function(params, callback) {\n var doRequest = params.debounce ? debouncedRequest : request;\n params = clean(setSort(params));\n\n var path = 'key/wiki_pages?';\n if (params.value) {\n path = 'tag/wiki_pages?';\n } else if (params.rtype) {\n path = 'relation/wiki_pages?';\n }\n\n var url = apibase + path + utilQsString(params);\n doRequest(url, params, true, callback, function(err, d) {\n if (err) {\n callback(err);\n } else {\n _taginfoCache[url] = d.data;\n callback(null, d.data);\n }\n });\n },\n\n\n apibase: function(_) {\n if (!arguments.length) return apibase;\n apibase = _;\n return this;\n }\n\n};\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\n/**\n * @module helpers\n */\n/**\n * Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth.\n *\n * @memberof helpers\n * @type {number}\n */\nexports.earthRadius = 6371008.8;\n/**\n * Unit of measurement factors using a spherical (non-ellipsoid) earth radius.\n *\n * @memberof helpers\n * @type {Object}\n */\nexports.factors = {\n centimeters: exports.earthRadius * 100,\n centimetres: exports.earthRadius * 100,\n degrees: exports.earthRadius / 111325,\n feet: exports.earthRadius * 3.28084,\n inches: exports.earthRadius * 39.370,\n kilometers: exports.earthRadius / 1000,\n kilometres: exports.earthRadius / 1000,\n meters: exports.earthRadius,\n metres: exports.earthRadius,\n miles: exports.earthRadius / 1609.344,\n millimeters: exports.earthRadius * 1000,\n millimetres: exports.earthRadius * 1000,\n nauticalmiles: exports.earthRadius / 1852,\n radians: 1,\n yards: exports.earthRadius / 1.0936,\n};\n/**\n * Units of measurement factors based on 1 meter.\n *\n * @memberof helpers\n * @type {Object}\n */\nexports.unitsFactors = {\n centimeters: 100,\n centimetres: 100,\n degrees: 1 / 111325,\n feet: 3.28084,\n inches: 39.370,\n kilometers: 1 / 1000,\n kilometres: 1 / 1000,\n meters: 1,\n metres: 1,\n miles: 1 / 1609.344,\n millimeters: 1000,\n millimetres: 1000,\n nauticalmiles: 1 / 1852,\n radians: 1 / exports.earthRadius,\n yards: 1 / 1.0936,\n};\n/**\n * Area of measurement factors based on 1 square meter.\n *\n * @memberof helpers\n * @type {Object}\n */\nexports.areaFactors = {\n acres: 0.000247105,\n centimeters: 10000,\n centimetres: 10000,\n feet: 10.763910417,\n inches: 1550.003100006,\n kilometers: 0.000001,\n kilometres: 0.000001,\n meters: 1,\n metres: 1,\n miles: 3.86e-7,\n millimeters: 1000000,\n millimetres: 1000000,\n yards: 1.195990046,\n};\n/**\n * Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}.\n *\n * @name feature\n * @param {Geometry} geometry input geometry\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature} a GeoJSON Feature\n * @example\n * var geometry = {\n * \"type\": \"Point\",\n * \"coordinates\": [110, 50]\n * };\n *\n * var feature = turf.feature(geometry);\n *\n * //=feature\n */\nfunction feature(geom, properties, options) {\n if (options === void 0) { options = {}; }\n var feat = { type: \"Feature\" };\n if (options.id === 0 || options.id) {\n feat.id = options.id;\n }\n if (options.bbox) {\n feat.bbox = options.bbox;\n }\n feat.properties = properties || {};\n feat.geometry = geom;\n return feat;\n}\nexports.feature = feature;\n/**\n * Creates a GeoJSON {@link Geometry} from a Geometry string type & coordinates.\n * For GeometryCollection type use `helpers.geometryCollection`\n *\n * @name geometry\n * @param {string} type Geometry Type\n * @param {Array} coordinates Coordinates\n * @param {Object} [options={}] Optional Parameters\n * @returns {Geometry} a GeoJSON Geometry\n * @example\n * var type = \"Point\";\n * var coordinates = [110, 50];\n * var geometry = turf.geometry(type, coordinates);\n * // => geometry\n */\nfunction geometry(type, coordinates, options) {\n if (options === void 0) { options = {}; }\n switch (type) {\n case \"Point\": return point(coordinates).geometry;\n case \"LineString\": return lineString(coordinates).geometry;\n case \"Polygon\": return polygon(coordinates).geometry;\n case \"MultiPoint\": return multiPoint(coordinates).geometry;\n case \"MultiLineString\": return multiLineString(coordinates).geometry;\n case \"MultiPolygon\": return multiPolygon(coordinates).geometry;\n default: throw new Error(type + \" is invalid\");\n }\n}\nexports.geometry = geometry;\n/**\n * Creates a {@link Point} {@link Feature} from a Position.\n *\n * @name point\n * @param {Array} coordinates longitude, latitude position (each in decimal degrees)\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature} a Point feature\n * @example\n * var point = turf.point([-75.343, 39.984]);\n *\n * //=point\n */\nfunction point(coordinates, properties, options) {\n if (options === void 0) { options = {}; }\n var geom = {\n type: \"Point\",\n coordinates: coordinates,\n };\n return feature(geom, properties, options);\n}\nexports.point = point;\n/**\n * Creates a {@link Point} {@link FeatureCollection} from an Array of Point coordinates.\n *\n * @name points\n * @param {Array>} coordinates an array of Points\n * @param {Object} [properties={}] Translate these properties to each Feature\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north]\n * associated with the FeatureCollection\n * @param {string|number} [options.id] Identifier associated with the FeatureCollection\n * @returns {FeatureCollection} Point Feature\n * @example\n * var points = turf.points([\n * [-75, 39],\n * [-80, 45],\n * [-78, 50]\n * ]);\n *\n * //=points\n */\nfunction points(coordinates, properties, options) {\n if (options === void 0) { options = {}; }\n return featureCollection(coordinates.map(function (coords) {\n return point(coords, properties);\n }), options);\n}\nexports.points = points;\n/**\n * Creates a {@link Polygon} {@link Feature} from an Array of LinearRings.\n *\n * @name polygon\n * @param {Array>>} coordinates an array of LinearRings\n * @param {Object} [properties={}] an Object of key-value pairs to add as properties\n * @param {Object} [options={}] Optional Parameters\n * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature\n * @param {string|number} [options.id] Identifier associated with the Feature\n * @returns {Feature} Polygon Feature\n * @example\n * var polygon = turf.polygon([[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]], { name: 'poly1' });\n *\n * //=polygon\n */\nfunction polygon(coordinates, properties, options) {\n if (options === void 0) { options = {}; }\n for (var _i = 0, coordinates_1 = coordinates; _i < coordinates_1.length; _i++) {\n var ring = coordinates_1[_i];\n if (ring.length < 4) {\n throw new Error(\"Each LinearRing of a Polygon must have 4 or more Positions.\");\n }\n for (var j = 0; j < ring[ring.length - 1].length; j++) {\n // Check if first point of Polygon contains two numbers\n if (ring[ring.length - 1][j] !== ring[0][j]) {\n throw new Error(\"First and last Position are not equivalent.\");\n }\n }\n }\n var geom = {\n type: \"Polygon\",\n coordinates: coordinates,\n };\n return feature(geom, properties, options);\n}\nexports.polygon = polygon;\n/**\n * Creates a {@link Polygon} {@link FeatureCollection} from an Array of Polygon coordinates.\n *\n * @name polygons\n * @param {Array