diff --git a/cmd/example/index.html b/cmd/example/index.html index 6b3e72b..2758566 100644 --- a/cmd/example/index.html +++ b/cmd/example/index.html @@ -15,17 +15,12 @@ var tile_url = document.body.getAttribute("data-protomaps-tile-url"); const map = L.map('map'); + map.setView([37.61799, -122.370943], 14); - const p = new protomaps.PMTiles(tile_url); - - p.metadata().then(m => { - let bounds_str = m.bounds.split(',') - let bounds = [[+bounds_str[1],+bounds_str[0]],[+bounds_str[3],+bounds_str[2]]] - - var layer = protomaps.leafletLayer({url: tile_url, bounds:bounds}); - layer.addTo(map); - map.fitBounds(bounds) - }); + console.log(tile_url); + + var layer = protomaps.leafletLayer({url:tile_url}) + layer.addTo(map); new L.Hash(map); diff --git a/cmd/example/sfo.pmtiles b/cmd/example/sfo.pmtiles index cdfba04..b3f6303 100644 Binary files a/cmd/example/sfo.pmtiles and b/cmd/example/sfo.pmtiles differ diff --git a/static/javascript/protomaps.js b/static/javascript/protomaps.js index 53d5552..f7b3f23 100644 --- a/static/javascript/protomaps.js +++ b/static/javascript/protomaps.js @@ -39,28 +39,24 @@ var protomaps = (() => { var __toModule = (module) => { return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", module && module.__esModule && "default" in module ? { get: () => module.default, enumerable: true } : { value: module, enumerable: true })), module); }; - var __publicField = (obj, key, value) => { - __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); - return value; - }; var __async = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { - step(generator.next(value)); + step2(generator.next(value)); } catch (e2) { reject(e2); } }; var rejected = (value) => { try { - step(generator.throw(value)); + step2(generator.throw(value)); } catch (e2) { reject(e2); } }; - var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); - step((generator = generator.apply(__this, __arguments)).next()); + var step2 = (x2) => x2.done ? resolve(x2.value) : Promise.resolve(x2.value).then(fulfilled, rejected); + step2((generator = generator.apply(__this, __arguments)).next()); }); }; @@ -68,14 +64,14 @@ var protomaps = (() => { var require_point_geometry = __commonJS({ "node_modules/@mapbox/point-geometry/index.js"(exports, module) { "use strict"; - module.exports = Point7; - function Point7(x, y) { - this.x = x; + module.exports = Point9; + function Point9(x2, y) { + this.x = x2; this.y = y; } - Point7.prototype = { + Point9.prototype = { clone: function() { - return new Point7(this.x, this.y); + return new Point9(this.x, this.y); }, add: function(p2) { return this.clone()._add(p2); @@ -135,12 +131,12 @@ var protomaps = (() => { angleWith: function(b) { return this.angleWithSep(b.x, b.y); }, - angleWithSep: function(x, y) { - return Math.atan2(this.x * y - this.y * x, this.x * x + this.y * y); + angleWithSep: function(x2, y) { + return Math.atan2(this.x * y - this.y * x2, this.x * x2 + 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; + var x2 = m[0] * this.x + m[1] * this.y, y = m[2] * this.x + m[3] * this.y; + this.x = x2; this.y = y; return this; }, @@ -185,14 +181,14 @@ var protomaps = (() => { 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; + var cos = Math.cos(angle), sin = Math.sin(angle), x2 = cos * this.x - sin * this.y, y = sin * this.x + cos * this.y; + this.x = x2; this.y = y; return this; }, _rotateAround: function(angle, p2) { - var cos = Math.cos(angle), sin = Math.sin(angle), x = p2.x + cos * (this.x - p2.x) - sin * (this.y - p2.y), y = p2.y + sin * (this.x - p2.x) + cos * (this.y - p2.y); - this.x = x; + var cos = Math.cos(angle), sin = Math.sin(angle), x2 = p2.x + cos * (this.x - p2.x) - sin * (this.y - p2.y), y = p2.y + sin * (this.x - p2.x) + cos * (this.y - p2.y); + this.x = x2; this.y = y; return this; }, @@ -202,12 +198,12 @@ var protomaps = (() => { return this; } }; - Point7.convert = function(a2) { - if (a2 instanceof Point7) { + Point9.convert = function(a2) { + if (a2 instanceof Point9) { return a2; } if (Array.isArray(a2)) { - return new Point7(a2[0], a2[1]); + return new Point9(a2[0], a2[1]); } return a2; }; @@ -218,7 +214,7 @@ var protomaps = (() => { var require_vectortilefeature = __commonJS({ "node_modules/@mapbox/vector-tile/lib/vectortilefeature.js"(exports, module) { "use strict"; - var Point7 = require_point_geometry(); + var Point9 = require_point_geometry(); module.exports = VectorTileFeature; function VectorTileFeature(pbf, end, extent, keys, values) { this.properties = {}; @@ -251,7 +247,7 @@ var protomaps = (() => { 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; + var end = pbf.readVarint() + pbf.pos, cmd = 1, length = 0, x2 = 0, y = 0, lines = [], line; while (pbf.pos < end) { if (length <= 0) { var cmdLen = pbf.readVarint(); @@ -260,14 +256,14 @@ var protomaps = (() => { } length--; if (cmd === 1 || cmd === 2) { - x += pbf.readSVarint(); + x2 += pbf.readSVarint(); y += pbf.readSVarint(); if (cmd === 1) { if (line) lines.push(line); line = []; } - line.push(new Point7(x, y)); + line.push(new Point9(x2, y)); } else if (cmd === 7) { if (line) { line.push(line[0].clone()); @@ -283,7 +279,7 @@ var protomaps = (() => { 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; + var end = pbf.readVarint() + pbf.pos, cmd = 1, length = 0, x2 = 0, y = 0, x1 = Infinity, x22 = -Infinity, y1 = Infinity, y2 = -Infinity; while (pbf.pos < end) { if (length <= 0) { var cmdLen = pbf.readVarint(); @@ -292,12 +288,12 @@ var protomaps = (() => { } length--; if (cmd === 1 || cmd === 2) { - x += pbf.readSVarint(); + x2 += pbf.readSVarint(); y += pbf.readSVarint(); - if (x < x1) - x1 = x; - if (x > x2) - x2 = x; + if (x2 < x1) + x1 = x2; + if (x2 > x22) + x22 = x2; if (y < y1) y1 = y; if (y > y2) @@ -306,10 +302,10 @@ var protomaps = (() => { throw new Error("unknown command " + cmd); } } - return [x1, y1, x2, y2]; + return [x1, y1, x22, y2]; }; - VectorTileFeature.prototype.toGeoJSON = function(x, y, z2) { - var size = this.extent * Math.pow(2, z2), x0 = this.extent * x, y0 = this.extent * y, coords = this.loadGeometry(), type = VectorTileFeature.types[this.type], i2, j; + VectorTileFeature.prototype.toGeoJSON = function(x2, y, z2) { + var size = this.extent * Math.pow(2, z2), x0 = this.extent * x2, y0 = this.extent * y, coords = this.loadGeometry(), type = VectorTileFeature.types[this.type], i2, j; function project3(line) { for (var j2 = 0; j2 < line.length; j2++) { var p2 = line[j2], y2 = 180 - (p2.y + y0) * 360 / size; @@ -644,7 +640,7 @@ var protomaps = (() => { return val; b = buf[this.pos]; val |= (b & 15) << 28; - return readVarintRemainder(val, isSigned, this); + return readVarintRemainder2(val, isSigned, this); }, readVarint64: function() { return this.readVarint(true); @@ -955,38 +951,38 @@ var protomaps = (() => { this.writeVarintField(tag, Boolean(val)); } }; - function readVarintRemainder(l2, s2, p2) { + function readVarintRemainder2(l2, s2, p2) { var buf = p2.buf, h, b; b = buf[p2.pos++]; h = (b & 112) >> 4; if (b < 128) - return toNum(l2, h, s2); + return toNum2(l2, h, s2); b = buf[p2.pos++]; h |= (b & 127) << 3; if (b < 128) - return toNum(l2, h, s2); + return toNum2(l2, h, s2); b = buf[p2.pos++]; h |= (b & 127) << 10; if (b < 128) - return toNum(l2, h, s2); + return toNum2(l2, h, s2); b = buf[p2.pos++]; h |= (b & 127) << 17; if (b < 128) - return toNum(l2, h, s2); + return toNum2(l2, h, s2); b = buf[p2.pos++]; h |= (b & 127) << 24; if (b < 128) - return toNum(l2, h, s2); + return toNum2(l2, h, s2); b = buf[p2.pos++]; h |= (b & 1) << 31; if (b < 128) - return toNum(l2, h, s2); + return toNum2(l2, h, s2); 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) { + function toNum2(low, high, isSigned) { if (isSigned) { return high * 4294967296 + (low >>> 0); } @@ -1223,14 +1219,14 @@ var protomaps = (() => { var o3 = a4 - e4 + 1, s3 = r4 - e4 + 1, l3 = Math.log(o3), f3 = 0.5 * Math.exp(2 * l3 / 3), u3 = 0.5 * Math.sqrt(l3 * f3 * (o3 - f3) / o3) * (s3 - o3 / 2 < 0 ? -1 : 1), m2 = Math.max(e4, Math.floor(r4 - s3 * f3 / o3 + u3)), c3 = Math.min(a4, Math.floor(r4 + (o3 - s3) * f3 / o3 + u3)); t4(n3, r4, m2, c3, h3); } - var p3 = n3[r4], d2 = e4, x = a4; - for (i2(n3, e4, r4), h3(n3[a4], p3) > 0 && i2(n3, e4, a4); d2 < x; ) { - for (i2(n3, d2, x), d2++, x--; h3(n3[d2], p3) < 0; ) + var p3 = n3[r4], d2 = e4, x2 = a4; + for (i2(n3, e4, r4), h3(n3[a4], p3) > 0 && i2(n3, e4, a4); d2 < x2; ) { + for (i2(n3, d2, x2), d2++, x2--; h3(n3[d2], p3) < 0; ) d2++; - for (; h3(n3[x], p3) > 0; ) - x--; + for (; h3(n3[x2], p3) > 0; ) + x2--; } - h3(n3[e4], p3) === 0 ? i2(n3, e4, x) : i2(n3, ++x, a4), x <= r4 && (e4 = x + 1), r4 <= x && (a4 = x - 1); + h3(n3[e4], p3) === 0 ? i2(n3, e4, x2) : i2(n3, ++x2, a4), x2 <= r4 && (e4 = x2 + 1), r4 <= x2 && (a4 = x2 - 1); } }(t3, r3, e3 || 0, a3 || t3.length - 1, h2 || n2); } @@ -1416,7 +1412,7 @@ var protomaps = (() => { this.data = p2([t3, i3]), this.data.height = t3.height + 1, this.data.leaf = false, a2(this.data, this.toBBox); }, r2.prototype._chooseSplitIndex = function(t3, i3, n3) { for (var r3, e3, a3, o3, s3, l3, u3, m2 = 1 / 0, c3 = 1 / 0, p3 = i3; p3 <= n3 - i3; p3++) { - var d2 = h(t3, 0, p3, this.toBBox), x = h(t3, p3, n3, this.toBBox), v = (e3 = d2, a3 = x, o3 = void 0, s3 = void 0, l3 = void 0, u3 = void 0, o3 = Math.max(e3.minX, a3.minX), s3 = Math.max(e3.minY, a3.minY), l3 = Math.min(e3.maxX, a3.maxX), u3 = Math.min(e3.maxY, a3.maxY), Math.max(0, l3 - o3) * Math.max(0, u3 - s3)), M = f2(d2) + f2(x); + var d2 = h(t3, 0, p3, this.toBBox), x2 = h(t3, p3, n3, this.toBBox), v = (e3 = d2, a3 = x2, o3 = void 0, s3 = void 0, l3 = void 0, u3 = void 0, o3 = Math.max(e3.minX, a3.minX), s3 = Math.max(e3.minY, a3.minY), l3 = Math.min(e3.maxX, a3.maxX), u3 = Math.min(e3.maxY, a3.maxY), Math.max(0, l3 - o3) * Math.max(0, u3 - s3)), M = f2(d2) + f2(x2); v < m2 ? (m2 = v, r3 = p3, c3 = M < c3 ? M : c3) : v === m2 && M < c3 && (c3 = M, r3 = p3); } return r3 || n3 - i3; @@ -1445,6 +1441,12 @@ var protomaps = (() => { } }); + // src/types/unitbezier.d.ts + var require_unitbezier_d = __commonJS({ + "src/types/unitbezier.d.ts"() { + } + }); + // node_modules/tinyqueue/tinyqueue.js var require_tinyqueue = __commonJS({ "node_modules/tinyqueue/tinyqueue.js"(exports, module) { @@ -1452,14 +1454,14 @@ var protomaps = (() => { typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (global = global || self, global.TinyQueue = factory()); })(exports, function() { "use strict"; - var TinyQueue = function TinyQueue2(data, compare) { + var TinyQueue = function TinyQueue2(data, compare2) { if (data === void 0) data = []; - if (compare === void 0) - compare = defaultCompare; + if (compare2 === void 0) + compare2 = defaultCompare; this.data = data; this.length = this.data.length; - this.compare = compare; + this.compare = compare2; if (this.length > 0) { for (var i2 = (this.length >> 1) - 1; i2 >= 0; i2--) { this._down(i2); @@ -1490,12 +1492,12 @@ var protomaps = (() => { TinyQueue.prototype._up = function _up(pos) { var ref = this; var data = ref.data; - var compare = ref.compare; + var compare2 = ref.compare; var item = data[pos]; while (pos > 0) { var parent = pos - 1 >> 1; var current = data[parent]; - if (compare(item, current) >= 0) { + if (compare2(item, current) >= 0) { break; } data[pos] = current; @@ -1506,18 +1508,18 @@ var protomaps = (() => { TinyQueue.prototype._down = function _down(pos) { var ref = this; var data = ref.data; - var compare = ref.compare; + var compare2 = ref.compare; var halfLength = this.length >> 1; var item = data[pos]; while (pos < halfLength) { var left = (pos << 1) + 1; var best = data[left]; var right = left + 1; - if (right < this.length && compare(data[right], best) < 0) { + if (right < this.length && compare2(data[right], best) < 0) { left = right; best = data[right]; } - if (compare(best, item) >= 0) { + if (compare2(best, item) >= 0) { break; } data[pos] = best; @@ -1566,9 +1568,9 @@ var protomaps = (() => { return degeneratePoleOfInaccessibility; } var cellQueue = new Queue(void 0, compareMax); - for (var x = minX; x < maxX; x += cellSize) { + for (var x2 = minX; x2 < maxX; x2 += cellSize) { for (var y = minY; y < maxY; y += cellSize) { - cellQueue.push(new Cell(x + h, y + h, h, polygon)); + cellQueue.push(new Cell(x2 + h, y + h, h, polygon)); } } var bestCell = getCentroidCell(polygon); @@ -1603,14 +1605,14 @@ var protomaps = (() => { function compareMax(a2, b) { return b.max - a2.max; } - function Cell(x, y, h, polygon) { - this.x = x; + function Cell(x2, y, h, polygon) { + this.x = x2; this.y = y; this.h = h; - this.d = pointToPolygonDist(x, y, polygon); + this.d = pointToPolygonDist(x2, y, polygon); this.max = this.d + this.h * Math.SQRT2; } - function pointToPolygonDist(x, y, polygon) { + function pointToPolygonDist(x2, y, polygon) { var inside = false; var minDistSq = Infinity; for (var k = 0; k < polygon.length; k++) { @@ -1618,459 +1620,1354 @@ var protomaps = (() => { for (var i2 = 0, len = ring.length, j = len - 1; i2 < len; j = i2++) { var a2 = ring[i2]; var b = ring[j]; - if (a2[1] > y !== b[1] > y && x < (b[0] - a2[0]) * (y - a2[1]) / (b[1] - a2[1]) + a2[0]) + if (a2[1] > y !== b[1] > y && x2 < (b[0] - a2[0]) * (y - a2[1]) / (b[1] - a2[1]) + a2[0]) inside = !inside; - minDistSq = Math.min(minDistSq, getSegDistSq(x, y, a2, b)); + minDistSq = Math.min(minDistSq, getSegDistSq(x2, y, a2, b)); } } return minDistSq === 0 ? 0 : (inside ? 1 : -1) * Math.sqrt(minDistSq); } function getCentroidCell(polygon) { var area = 0; - var x = 0; + var x2 = 0; var y = 0; var points = polygon[0]; for (var i2 = 0, len = points.length, j = len - 1; i2 < len; j = i2++) { var a2 = points[i2]; var b = points[j]; var f2 = a2[0] * b[1] - b[0] * a2[1]; - x += (a2[0] + b[0]) * f2; + x2 += (a2[0] + b[0]) * f2; y += (a2[1] + b[1]) * f2; area += f2 * 3; } if (area === 0) return new Cell(points[0][0], points[0][1], 0, polygon); - return new Cell(x / area, y / area, 0, polygon); + return new Cell(x2 / area, y / area, 0, polygon); } function getSegDistSq(px, py, a2, b) { - var x = a2[0]; + var x2 = a2[0]; var y = a2[1]; - var dx = b[0] - x; + var dx = b[0] - x2; var dy = b[1] - y; if (dx !== 0 || dy !== 0) { - var t2 = ((px - x) * dx + (py - y) * dy) / (dx * dx + dy * dy); + var t2 = ((px - x2) * dx + (py - y) * dy) / (dx * dx + dy * dy); if (t2 > 1) { - x = b[0]; + x2 = b[0]; y = b[1]; } else if (t2 > 0) { - x += dx * t2; + x2 += dx * t2; y += dy * t2; } } - dx = px - x; + dx = px - x2; dy = py - y; return dx * dx + dy * dy; } } }); - // node_modules/linelabel/xy.js - var require_xy = __commonJS({ - "node_modules/linelabel/xy.js"(exports, module) { - module.exports = function(pts, max_angle_delta) { - var chunks = []; - var cur_angles = [null]; - var a2, b, c2, i2 = 0, n2 = 0, d = 0; - var abmag = 0, bcmag = 0; - var abx = 0, aby = 0; - var bcx = 0, bcy = 0; - var dt = 0; - var i_start = 0; - var d_start = 0; - if (pts.length < 2) - return []; - if (pts.length === 2) { - d = Math.sqrt(Math.pow(pts[1].x - pts[0].x, 2) + Math.pow(pts[1].y - pts[0].y, 2)); - return [{ - length: d, - beginIndex: 0, - beginDistance: 0, - endIndex: 2, - endDistance: d, - angles: [null, null] - }]; - } - abmag = Math.sqrt(Math.pow(pts[1].x - pts[0].x, 2) + Math.pow(pts[1].y - pts[0].y, 2)); - for (i2 = 1, n2 = pts.length - 1; i2 < n2; i2++) { - a2 = pts[i2 - 1]; - b = pts[i2]; - c2 = pts[i2 + 1]; - abx = b.x - a2.x; - aby = b.y - a2.y; - bcx = c2.x - b.x; - bcy = c2.y - b.y; - bcmag = Math.sqrt(bcx * bcx + bcy * bcy); - d += abmag; - dt = Math.acos((abx * bcx + aby * bcy) / (abmag * bcmag)); - cur_angles.push(dt); - if (dt > max_angle_delta) { - chunks.push({ - length: d - d_start, - beginDistance: d_start, - beginIndex: i_start, - endIndex: i2 + 1, - endDistance: d, - angles: cur_angles - }); - i_start = i2; - d_start = d; - cur_angles = [dt]; - } - abmag = bcmag; - } - cur_angles.push(null); - if (i2 - i_start > 0) { - chunks.push({ - length: d - d_start + bcmag, - beginIndex: i_start, - beginDistance: d_start, - endIndex: i2 + 1, - endDistance: d + bcmag, - angles: cur_angles - }); - } - return chunks; - }; - } - }); - // src/index.ts var src_exports = {}; __export(src_exports, { + CenteredSymbolizer: () => CenteredSymbolizer, CenteredTextSymbolizer: () => CenteredTextSymbolizer, CircleSymbolizer: () => CircleSymbolizer, FlexSymbolizer: () => FlexSymbolizer, Font: () => Font, + GeomType: () => GeomType, GroupSymbolizer: () => GroupSymbolizer, IconSymbolizer: () => IconSymbolizer, + Index: () => Index, + Justify: () => Justify, + Labeler: () => Labeler, + Labelers: () => Labelers, + LineLabelPlacement: () => LineLabelPlacement, LineLabelSymbolizer: () => LineLabelSymbolizer, LineSymbolizer: () => LineSymbolizer, + OffsetSymbolizer: () => OffsetSymbolizer, OffsetTextSymbolizer: () => OffsetTextSymbolizer, PMTiles: () => PMTiles, + Padding: () => Padding, + PmtilesSource: () => PmtilesSource, PolygonLabelSymbolizer: () => PolygonLabelSymbolizer, PolygonSymbolizer: () => PolygonSymbolizer, + Sheet: () => Sheet, ShieldSymbolizer: () => ShieldSymbolizer, - Sprites: () => Sprites, Static: () => Static, + TextPlacements: () => TextPlacements, + TextSymbolizer: () => TextSymbolizer, + TileCache: () => TileCache, + View: () => View, + ZxySource: () => ZxySource, arr: () => arr, + covering: () => covering, createPattern: () => createPattern, + cubicBezier: () => cubicBezier, dark: () => dark, exp: () => exp, filterFn: () => filterFn, getFont: () => getFont, + getZoom: () => getZoom, + isCCW: () => isCCW, + isInRing: () => isInRing, json_style: () => json_style, labelRules: () => labelRules, leafletLayer: () => leafletLayer, light: () => light, + linear: () => linear, numberFn: () => numberFn, numberOrFn: () => numberOrFn, paintRules: () => paintRules, - widthFn: () => widthFn + painter: () => painter, + pointInPolygon: () => pointInPolygon, + pointMinDistToLines: () => pointMinDistToLines, + pointMinDistToPoints: () => pointMinDistToPoints, + sourcesToViews: () => sourcesToViews, + step: () => step, + toIndex: () => toIndex, + transformGeom: () => transformGeom, + widthFn: () => widthFn, + wrap: () => wrap }); // src/frontends/static.ts - var import_point_geometry5 = __toModule(require_point_geometry()); + var import_point_geometry7 = __toModule(require_point_geometry()); + + // src/view.ts + var import_point_geometry2 = __toModule(require_point_geometry()); // src/tilecache.ts var import_point_geometry = __toModule(require_point_geometry()); var import_vector_tile = __toModule(require_vector_tile()); var import_pbf = __toModule(require_pbf()); - // node_modules/pmtiles/index.mjs - var shift = (number, shift2) => { - return number * Math.pow(2, shift2); - }; - var getUint24 = (dataview, pos) => { - return shift(dataview.getUint16(pos + 1, true), 8) + dataview.getUint8(pos, true); + // node_modules/pmtiles/dist/index.mjs + var __async2 = (__this, __arguments, generator) => { + return new Promise((resolve, reject) => { + var fulfilled = (value) => { + try { + step2(generator.next(value)); + } catch (e2) { + reject(e2); + } + }; + var rejected = (value) => { + try { + step2(generator.throw(value)); + } catch (e2) { + reject(e2); + } + }; + var step2 = (x2) => x2.done ? resolve(x2.value) : Promise.resolve(x2.value).then(fulfilled, rejected); + step2((generator = generator.apply(__this, __arguments)).next()); + }); }; - var getUint48 = (dataview, pos) => { - return shift(dataview.getUint32(pos + 2, true), 16) + dataview.getUint16(pos, true); + var u8 = Uint8Array; + var u16 = Uint16Array; + var u32 = Uint32Array; + var fleb = new u8([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0, 0]); + var fdeb = new u8([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 0, 0]); + var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); + var freb = function(eb, start) { + var b = new u16(31); + for (var i2 = 0; i2 < 31; ++i2) { + b[i2] = start += 1 << eb[i2 - 1]; + } + var r2 = new u32(b[30]); + for (var i2 = 1; i2 < 30; ++i2) { + for (var j = b[i2]; j < b[i2 + 1]; ++j) { + r2[j] = j - b[i2] << 5 | i2; + } + } + return [b, r2]; }; - var parseHeader = (dataview) => { - var magic = dataview.getUint16(0, true); - var version = dataview.getUint16(2, true); - var json_size = dataview.getUint32(4, true); - var root_entries = dataview.getUint16(8, true); - return { version, json_size, root_entries }; + var _a = freb(fleb, 2); + var fl = _a[0]; + var revfl = _a[1]; + fl[28] = 258, revfl[258] = 28; + var _b = freb(fdeb, 0); + var fd = _b[0]; + var revfd = _b[1]; + var rev = new u16(32768); + for (var i2 = 0; i2 < 32768; ++i2) { + x = (i2 & 43690) >>> 1 | (i2 & 21845) << 1; + x = (x & 52428) >>> 2 | (x & 13107) << 2; + x = (x & 61680) >>> 4 | (x & 3855) << 4; + rev[i2] = ((x & 65280) >>> 8 | (x & 255) << 8) >>> 1; + } + var x; + var hMap = function(cd, mb, r2) { + var s2 = cd.length; + var i2 = 0; + var l2 = new u16(mb); + for (; i2 < s2; ++i2) { + if (cd[i2]) + ++l2[cd[i2] - 1]; + } + var le = new u16(mb); + for (i2 = 0; i2 < mb; ++i2) { + le[i2] = le[i2 - 1] + l2[i2 - 1] << 1; + } + var co; + if (r2) { + co = new u16(1 << mb); + var rvb = 15 - mb; + for (i2 = 0; i2 < s2; ++i2) { + if (cd[i2]) { + var sv = i2 << 4 | cd[i2]; + var r_1 = mb - cd[i2]; + var v = le[cd[i2] - 1]++ << r_1; + for (var m = v | (1 << r_1) - 1; v <= m; ++v) { + co[rev[v] >>> rvb] = sv; + } + } + } + } else { + co = new u16(s2); + for (i2 = 0; i2 < s2; ++i2) { + if (cd[i2]) { + co[i2] = rev[le[cd[i2] - 1]++] >>> 15 - cd[i2]; + } + } + } + return co; }; - var bytesToMap = (dataview) => { - let m = new Map(); - for (var i2 = 0; i2 < dataview.byteLength; i2 += 17) { - var z_raw = dataview.getUint8(i2, true); - var z2 = z_raw & 127; - var is_dir = z_raw >> 7; - var x = getUint24(dataview, i2 + 1); - var y = getUint24(dataview, i2 + 4); - var offset = getUint48(dataview, i2 + 7); - var length = dataview.getUint32(i2 + 13, true); - m.set(z2 + "_" + x + "_" + y, [offset, length, is_dir]); + var flt = new u8(288); + for (var i2 = 0; i2 < 144; ++i2) + flt[i2] = 8; + for (var i2 = 144; i2 < 256; ++i2) + flt[i2] = 9; + for (var i2 = 256; i2 < 280; ++i2) + flt[i2] = 7; + for (var i2 = 280; i2 < 288; ++i2) + flt[i2] = 8; + var fdt = new u8(32); + for (var i2 = 0; i2 < 32; ++i2) + fdt[i2] = 5; + var flrm = /* @__PURE__ */ hMap(flt, 9, 1); + var fdrm = /* @__PURE__ */ hMap(fdt, 5, 1); + var max = function(a2) { + var m = a2[0]; + for (var i2 = 1; i2 < a2.length; ++i2) { + if (a2[i2] > m) + m = a2[i2]; } return m; }; - var PMTiles = class { - constructor(url) { - __publicField(this, "metadata", (func) => { - return new Promise((resolve, reject) => { - this.root.then((root) => { - resolve(root.metadata); - }); - }); - }); - __publicField(this, "getLeaf", (offset, len) => { - return new Promise((resolve, reject) => { - if (this.leaves.has(offset)) { - this.leaves.get(offset)[0]++; - resolve(this.leaves.get(offset)[1]); - } else if (this.outstanding_requests.has(offset)) { - this.outstanding_requests.get(offset).push(resolve); - } else { - this.outstanding_requests.set(offset, []); - fetch(this.url, { headers: { Range: "bytes=" + offset + "-" + (offset + len - 1) } }).then((resp) => { - return resp.arrayBuffer(); - }).then((buf) => { - var map = bytesToMap(new DataView(buf), len / 17); - if (this.leaves.size > 32) { - var minStep = Infinity; - var minKey = void 0; - this.leaves.forEach((val, key) => { - if (val[0] < minStep) { - minStep = val[0]; - minKey = key; - } - }); - this.leaves.delete(minKey); - } - this.leaves.set(offset, [this.step++, map]); - resolve(map); - this.outstanding_requests.get(offset).forEach((f2) => f2(map)); - this.outstanding_requests.delete(offset); - }); + var bits = function(d, p2, m) { + var o2 = p2 / 8 | 0; + return (d[o2] | d[o2 + 1] << 8) >> (p2 & 7) & m; + }; + var bits16 = function(d, p2) { + var o2 = p2 / 8 | 0; + return (d[o2] | d[o2 + 1] << 8 | d[o2 + 2] << 16) >> (p2 & 7); + }; + var shft = function(p2) { + return (p2 + 7) / 8 | 0; + }; + var slc = function(v, s2, e2) { + if (s2 == null || s2 < 0) + s2 = 0; + if (e2 == null || e2 > v.length) + e2 = v.length; + var n2 = new (v.BYTES_PER_ELEMENT == 2 ? u16 : v.BYTES_PER_ELEMENT == 4 ? u32 : u8)(e2 - s2); + n2.set(v.subarray(s2, e2)); + return n2; + }; + var ec = [ + "unexpected EOF", + "invalid block type", + "invalid length/literal", + "invalid distance", + "stream finished", + "no stream handler", + , + "no callback", + "invalid UTF-8 data", + "extra field too long", + "date not in range 1980-2099", + "filename too long", + "stream finishing", + "invalid zip data" + ]; + var err = function(ind, msg, nt) { + var e2 = new Error(msg || ec[ind]); + e2.code = ind; + if (Error.captureStackTrace) + Error.captureStackTrace(e2, err); + if (!nt) + throw e2; + return e2; + }; + var inflt = function(dat, buf, st) { + var sl = dat.length; + if (!sl || st && st.f && !st.l) + return buf || new u8(0); + var noBuf = !buf || st; + var noSt = !st || st.i; + if (!st) + st = {}; + if (!buf) + buf = new u8(sl * 3); + var cbuf = function(l22) { + var bl = buf.length; + if (l22 > bl) { + var nbuf = new u8(Math.max(bl * 2, l22)); + nbuf.set(buf); + buf = nbuf; + } + }; + var final = st.f || 0, pos = st.p || 0, bt = st.b || 0, lm = st.l, dm = st.d, lbt = st.m, dbt = st.n; + var tbts = sl * 8; + do { + if (!lm) { + final = bits(dat, pos, 1); + var type = bits(dat, pos + 1, 3); + pos += 3; + if (!type) { + var s2 = shft(pos) + 4, l2 = dat[s2 - 4] | dat[s2 - 3] << 8, t2 = s2 + l2; + if (t2 > sl) { + if (noSt) + err(0); + break; } - }); - }); - __publicField(this, "getZxy", (z2, x, y) => { - var strid = z2 + "_" + x + "_" + y; - return this.root.then((root) => { - if (root.dir.has(strid) && root.dir.get(strid)[2] == 0) { - return root.dir.get(strid); - } else { - if (z2 >= 7) { - var z7_tile_diff = z2 - 7; - var z7_tile = [7, Math.trunc(x / (1 << z7_tile_diff)), Math.trunc(y / (1 << z7_tile_diff))]; - var z7_tile_str = z7_tile[0] + "_" + z7_tile[1] + "_" + z7_tile[2]; - if (root.dir.has(z7_tile_str) && root.dir.get(z7_tile_str)[2] == 1) { - const val = root.dir.get(z7_tile_str); - return this.getLeaf(val[0], val[1]).then((leafdir) => { - if (leafdir.has(strid)) { - return leafdir.get(strid); - } - return null; - }); - } - } + if (noBuf) + cbuf(bt + l2); + buf.set(dat.subarray(s2, t2), bt); + st.b = bt += l2, st.p = pos = t2 * 8, st.f = final; + continue; + } else if (type == 1) + lm = flrm, dm = fdrm, lbt = 9, dbt = 5; + else if (type == 2) { + var hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4; + var tl = hLit + bits(dat, pos + 5, 31) + 1; + pos += 14; + var ldt = new u8(tl); + var clt = new u8(19); + for (var i2 = 0; i2 < hcLen; ++i2) { + clt[clim[i2]] = bits(dat, pos + i2 * 3, 7); } - return null; - }); - }); - __publicField(this, "transformRequest", (u2, t2, tile, done) => { - if (u2.endsWith(".pmtiles") && done) { - var tid = tile.tileID.canonical; - var strid = tid.z + "_" + tid.x + "_" + tid.y; - this.getZxy(tid.z, tid.x, tid.y).then((val) => { - if (val) { - done({ url: this.url, headers: { "Range": "bytes=" + val[0] + "-" + (val[0] + val[1] - 1) } }); + pos += hcLen * 3; + var clb = max(clt), clbmsk = (1 << clb) - 1; + var clm = hMap(clt, clb, 1); + for (var i2 = 0; i2 < tl; ) { + var r2 = clm[bits(dat, pos, clbmsk)]; + pos += r2 & 15; + var s2 = r2 >>> 4; + if (s2 < 16) { + ldt[i2++] = s2; + } else { + var c2 = 0, n2 = 0; + if (s2 == 16) + n2 = 3 + bits(dat, pos, 3), pos += 2, c2 = ldt[i2 - 1]; + else if (s2 == 17) + n2 = 3 + bits(dat, pos, 7), pos += 3; + else if (s2 == 18) + n2 = 11 + bits(dat, pos, 127), pos += 7; + while (n2--) + ldt[i2++] = c2; } - }); + } + var lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit); + lbt = max(lt); + dbt = max(dt); + lm = hMap(lt, lbt, 1); + dm = hMap(dt, dbt, 1); + } else + err(1); + if (pos > tbts) { + if (noSt) + err(0); + break; } - return { url: u2 }; - }); - __publicField(this, "leafletLayer", (options) => { - const self2 = this; - var cls = L.GridLayer.extend({ - createTile: function(coord, done) { - var tile = document.createElement("img"); - var error; - self2.getZxy(coord.z, coord.x, coord.y).then((result) => { - if (result === null) - return; - fetch(self2.url, { headers: { Range: "bytes=" + result[0] + "-" + (result[0] + result[1] - 1) } }).then((resp) => { - return resp.arrayBuffer(); - }).then((buf) => { - var blob = new Blob([buf], { type: "image/png" }); - var imageUrl = window.URL.createObjectURL(blob); - tile.src = imageUrl; - done(error, tile); - }); - }); - return tile; - }, - _removeTile: function(key) { - var tile = this._tiles[key]; - if (!tile) { - return; - } - tile.el.width = 0; - tile.el.height = 0; - tile.el.deleted = true; - L.DomUtil.remove(tile.el); - delete this._tiles[key]; - this.fire("tileunload", { - tile: tile.el, - coords: this._keyToTileCoords(key) - }); + } + if (noBuf) + cbuf(bt + 131072); + var lms = (1 << lbt) - 1, dms = (1 << dbt) - 1; + var lpos = pos; + for (; ; lpos = pos) { + var c2 = lm[bits16(dat, pos) & lms], sym = c2 >>> 4; + pos += c2 & 15; + if (pos > tbts) { + if (noSt) + err(0); + break; + } + if (!c2) + err(2); + if (sym < 256) + buf[bt++] = sym; + else if (sym == 256) { + lpos = pos, lm = null; + break; + } else { + var add = sym - 254; + if (sym > 264) { + var i2 = sym - 257, b = fleb[i2]; + add = bits(dat, pos, (1 << b) - 1) + fl[i2]; + pos += b; } - }); - return new cls(options); - }); - this.url = url; - const controller = new AbortController(); - const signal = controller.signal; - this.root = fetch(this.url, { signal, headers: { Range: "bytes=0-511999" } }).then((resp) => { - if (resp.headers.get("Content-Length") != 512e3) { - console.error("Content-Length mismatch indicates byte serving not supported; aborting."); - controller.abort(); + var d = dm[bits16(dat, pos) & dms], dsym = d >>> 4; + if (!d) + err(3); + pos += d & 15; + var dt = fd[dsym]; + if (dsym > 3) { + var b = fdeb[dsym]; + dt += bits16(dat, pos) & (1 << b) - 1, pos += b; + } + if (pos > tbts) { + if (noSt) + err(0); + break; + } + if (noBuf) + cbuf(bt + 131072); + var end = bt + add; + for (; bt < end; bt += 4) { + buf[bt] = buf[bt - dt]; + buf[bt + 1] = buf[bt + 1 - dt]; + buf[bt + 2] = buf[bt + 2 - dt]; + buf[bt + 3] = buf[bt + 3 - dt]; + } + bt = end; } - return resp.arrayBuffer(); - }).then((buf) => { - const header = parseHeader(new DataView(buf, 0, 10)); - var dec = new TextDecoder("utf-8"); - return { - metadata: JSON.parse(dec.decode(new DataView(buf, 10, header.json_size))), - dir: bytesToMap(new DataView(buf, 10 + header.json_size, 17 * header.root_entries)) - }; - }); - this.step = 0; - this.leaves = new Map(); - this.outstanding_requests = new Map(); + } + st.l = lm, st.p = lpos, st.b = bt, st.f = final; + if (lm) + final = 1, st.m = lbt, st.d = dm, st.n = dbt; + } while (!final); + return bt == buf.length ? buf : slc(buf, 0, bt); + }; + var et = /* @__PURE__ */ new u8(0); + var gzs = function(d) { + if (d[0] != 31 || d[1] != 139 || d[2] != 8) + err(6, "invalid gzip data"); + var flg = d[3]; + var st = 10; + if (flg & 4) + st += d[10] | (d[11] << 8) + 2; + for (var zs = (flg >> 3 & 1) + (flg >> 4 & 1); zs > 0; zs -= !d[st++]) + ; + return st + (flg & 2); + }; + var gzl = function(d) { + var l2 = d.length; + return (d[l2 - 4] | d[l2 - 3] << 8 | d[l2 - 2] << 16 | d[l2 - 1] << 24) >>> 0; + }; + var zlv = function(d) { + if ((d[0] & 15) != 8 || d[0] >>> 4 > 7 || (d[0] << 8 | d[1]) % 31) + err(6, "invalid zlib data"); + if (d[1] & 32) + err(6, "invalid zlib data: preset dictionaries not supported"); + }; + function inflateSync(data, out) { + return inflt(data, out); + } + function gunzipSync(data, out) { + return inflt(data.subarray(gzs(data), -8), out || new u8(gzl(data))); + } + function unzlibSync(data, out) { + return inflt((zlv(data), data.subarray(2, -4)), out); + } + function decompressSync(data, out) { + return data[0] == 31 && data[1] == 139 && data[2] == 8 ? gunzipSync(data, out) : (data[0] & 15) != 8 || data[0] >> 4 > 7 || (data[0] << 8 | data[1]) % 31 ? inflateSync(data, out) : unzlibSync(data, out); + } + var te = typeof TextEncoder != "undefined" && /* @__PURE__ */ new TextEncoder(); + var td = typeof TextDecoder != "undefined" && /* @__PURE__ */ new TextDecoder(); + var tds = 0; + try { + td.decode(et, { stream: true }); + tds = 1; + } catch (e2) { + } + var mt = typeof queueMicrotask == "function" ? queueMicrotask : typeof setTimeout == "function" ? setTimeout : function(fn) { + fn(); + }; + var shift = (n2, shift2) => { + return n2 * Math.pow(2, shift2); + }; + var unshift = (n2, shift2) => { + return Math.floor(n2 / Math.pow(2, shift2)); + }; + var getUint24 = (view, pos) => { + return shift(view.getUint16(pos + 1, true), 8) + view.getUint8(pos); + }; + var getUint48 = (view, pos) => { + return shift(view.getUint32(pos + 2, true), 16) + view.getUint16(pos, true); + }; + var compare = (tz, tx, ty, view, i2) => { + if (tz != view.getUint8(i2)) + return tz - view.getUint8(i2); + const x2 = getUint24(view, i2 + 1); + if (tx != x2) + return tx - x2; + const y = getUint24(view, i2 + 4); + if (ty != y) + return ty - y; + return 0; + }; + var queryLeafdir = (view, z2, x2, y) => { + const offset_len = queryView(view, z2 | 128, x2, y); + if (offset_len) { + return { + z: z2, + x: x2, + y, + offset: offset_len[0], + length: offset_len[1], + is_dir: true + }; } + return null; }; - - // src/tilecache.ts - var GeomType; - (function(GeomType2) { - GeomType2[GeomType2["Point"] = 1] = "Point"; - GeomType2[GeomType2["Line"] = 2] = "Line"; - GeomType2[GeomType2["Polygon"] = 3] = "Polygon"; - })(GeomType || (GeomType = {})); - function toIndex(c2) { - return c2.x + ":" + c2.y + ":" + c2.z; + var queryTile = (view, z2, x2, y) => { + const offset_len = queryView(view, z2, x2, y); + if (offset_len) { + return { + z: z2, + x: x2, + y, + offset: offset_len[0], + length: offset_len[1], + is_dir: false + }; + } + return null; + }; + var queryView = (view, z2, x2, y) => { + let m = 0; + let n2 = view.byteLength / 17 - 1; + while (m <= n2) { + const k = n2 + m >> 1; + const cmp = compare(z2, x2, y, view, k * 17); + if (cmp > 0) { + m = k + 1; + } else if (cmp < 0) { + n2 = k - 1; + } else { + return [getUint48(view, k * 17 + 7), view.getUint32(k * 17 + 13, true)]; + } + } + return null; + }; + var entrySort = (a2, b) => { + if (a2.is_dir && !b.is_dir) { + return 1; + } + if (!a2.is_dir && b.is_dir) { + return -1; + } + if (a2.z !== b.z) { + return a2.z - b.z; + } + if (a2.x !== b.x) { + return a2.x - b.x; + } + return a2.y - b.y; + }; + var parseEntry = (dataview, i2) => { + const z_raw = dataview.getUint8(i2 * 17); + const z2 = z_raw & 127; + return { + z: z2, + x: getUint24(dataview, i2 * 17 + 1), + y: getUint24(dataview, i2 * 17 + 4), + offset: getUint48(dataview, i2 * 17 + 7), + length: dataview.getUint32(i2 * 17 + 13, true), + is_dir: z_raw >> 7 === 1 + }; + }; + var sortDir = (a2) => { + const entries = []; + const view = new DataView(a2); + for (let i2 = 0; i2 < view.byteLength / 17; i2++) { + entries.push(parseEntry(view, i2)); + } + return createDirectory(entries); + }; + var createDirectory = (entries) => { + entries.sort(entrySort); + const buffer = new ArrayBuffer(17 * entries.length); + const arr2 = new Uint8Array(buffer); + for (let i2 = 0; i2 < entries.length; i2++) { + const entry = entries[i2]; + let z2 = entry.z; + if (entry.is_dir) + z2 = z2 | 128; + arr2[i2 * 17] = z2; + arr2[i2 * 17 + 1] = entry.x & 255; + arr2[i2 * 17 + 2] = entry.x >> 8 & 255; + arr2[i2 * 17 + 3] = entry.x >> 16 & 255; + arr2[i2 * 17 + 4] = entry.y & 255; + arr2[i2 * 17 + 5] = entry.y >> 8 & 255; + arr2[i2 * 17 + 6] = entry.y >> 16 & 255; + arr2[i2 * 17 + 7] = entry.offset & 255; + arr2[i2 * 17 + 8] = unshift(entry.offset, 8) & 255; + arr2[i2 * 17 + 9] = unshift(entry.offset, 16) & 255; + arr2[i2 * 17 + 10] = unshift(entry.offset, 24) & 255; + arr2[i2 * 17 + 11] = unshift(entry.offset, 32) & 255; + arr2[i2 * 17 + 12] = unshift(entry.offset, 48) & 255; + arr2[i2 * 17 + 13] = entry.length & 255; + arr2[i2 * 17 + 14] = entry.length >> 8 & 255; + arr2[i2 * 17 + 15] = entry.length >> 16 & 255; + arr2[i2 * 17 + 16] = entry.length >> 24 & 255; + } + return buffer; + }; + var deriveLeaf = (view, tile) => { + if (view.byteLength < 17) + return null; + const numEntries = view.byteLength / 17; + const entry = parseEntry(view, numEntries - 1); + if (entry.is_dir) { + let leaf_level = entry.z; + const level_diff = tile.z - leaf_level; + const leaf_x = Math.trunc(tile.x / (1 << level_diff)); + const leaf_y = Math.trunc(tile.y / (1 << level_diff)); + return { z: leaf_level, x: leaf_x, y: leaf_y }; + } + return null; + }; + function getHeader(source) { + return __async2(this, null, function* () { + let resp = yield source.getBytes(0, 512e3); + const dataview = new DataView(resp.data); + const json_size = dataview.getUint32(4, true); + const root_entries = dataview.getUint16(8, true); + const dec = new TextDecoder("utf-8"); + const json_metadata = JSON.parse(dec.decode(new DataView(resp.data, 10, json_size))); + let tile_compression = Compression.Unknown; + if (json_metadata.compression === "gzip") { + tile_compression = Compression.Gzip; + } + let minzoom = 0; + if ("minzoom" in json_metadata) { + minzoom = +json_metadata.minzoom; + } + let maxzoom = 0; + if ("maxzoom" in json_metadata) { + maxzoom = +json_metadata.maxzoom; + } + let center_lon = 0; + let center_lat = 0; + let center_zoom = 0; + let min_lon = -180; + let min_lat = -85; + let max_lon = 180; + let max_lat = 85; + if (json_metadata.bounds) { + let split = json_metadata.bounds.split(","); + min_lon = +split[0]; + min_lat = +split[1]; + max_lon = +split[2]; + max_lat = +split[3]; + } + if (json_metadata.center) { + let split = json_metadata.center.split(","); + center_lon = +split[0]; + center_lat = +split[1]; + center_zoom = +split[2]; + } + const header = { + specVersion: dataview.getUint16(2, true), + rootDirectoryOffset: 10 + json_size, + rootDirectoryLength: root_entries * 17, + jsonMetadataOffset: 10, + jsonMetadataLength: json_size, + leafDirectoryOffset: 0, + leafDirectoryLength: void 0, + tileDataOffset: 0, + tileDataLength: void 0, + numAddressedTiles: 0, + numTileEntries: 0, + numTileContents: 0, + clustered: false, + internalCompression: Compression.None, + tileCompression: tile_compression, + tileType: TileType.Mvt, + minZoom: minzoom, + maxZoom: maxzoom, + minLon: min_lon, + minLat: min_lat, + maxLon: max_lon, + maxLat: max_lat, + centerZoom: center_zoom, + centerLon: center_lon, + centerLat: center_lat, + etag: resp.etag + }; + return header; + }); } - var loadGeomAndBbox = (pbf, geometry, scale) => { - pbf.pos = geometry; - var end = pbf.readVarint() + pbf.pos, cmd = 1, length = 0, x = 0, y = 0, x1 = Infinity, x2 = -Infinity, y1 = Infinity, y2 = -Infinity; - var lines = []; - var line; - while (pbf.pos < end) { - if (length <= 0) { - var cmdLen = pbf.readVarint(); - cmd = cmdLen & 7; - length = cmdLen >> 3; + function getZxy(header, source, cache, z2, x2, y, signal) { + return __async2(this, null, function* () { + let root_dir = yield cache.getArrayBuffer(source, header.rootDirectoryOffset, header.rootDirectoryLength, header); + if (header.specVersion === 1) { + root_dir = sortDir(root_dir); } - length--; - if (cmd === 1 || cmd === 2) { - x += pbf.readSVarint() * scale; - y += pbf.readSVarint() * scale; - if (x < x1) - x1 = x; - if (x > x2) - x2 = x; - if (y < y1) - y1 = y; - if (y > y2) - y2 = y; - if (cmd === 1) { - if (line) - lines.push(line); - line = []; + const entry = queryTile(new DataView(root_dir), z2, x2, y); + if (entry) { + let resp = yield source.getBytes(entry.offset, entry.length, signal); + let tile_data = resp.data; + let view = new DataView(tile_data); + if (view.getUint8(0) == 31 && view.getUint8(1) == 139) { + tile_data = decompressSync(new Uint8Array(tile_data)); } - line.push(new import_point_geometry.default(x, y)); - } else if (cmd === 7) { - if (line) - line.push(line[0].clone()); - } else - throw new Error("unknown command " + cmd); - } - if (line) - lines.push(line); - return { geom: lines, bbox: { minX: x1, minY: y1, maxX: x2, maxY: y2 } }; + return { + data: tile_data + }; + } + const leafcoords = deriveLeaf(new DataView(root_dir), { z: z2, x: x2, y }); + if (leafcoords) { + const leafdir_entry = queryLeafdir(new DataView(root_dir), leafcoords.z, leafcoords.x, leafcoords.y); + if (leafdir_entry) { + let leaf_dir = yield cache.getArrayBuffer(source, leafdir_entry.offset, leafdir_entry.length, header); + if (header.specVersion === 1) { + leaf_dir = sortDir(leaf_dir); + } + let tile_entry = queryTile(new DataView(leaf_dir), z2, x2, y); + if (tile_entry) { + let resp = yield source.getBytes(tile_entry.offset, tile_entry.length, signal); + let tile_data = resp.data; + let view = new DataView(tile_data); + if (view.getUint8(0) == 31 && view.getUint8(1) == 139) { + tile_data = decompressSync(new Uint8Array(tile_data)); + } + return { + data: tile_data + }; + } + } + } + return void 0; + }); + } + var v2_default = { + getHeader, + getZxy }; - function parseTile(buffer, tileSize) { - let v = new import_vector_tile.VectorTile(new import_pbf.default(buffer)); - let result = new Map(); - for (let [key, value] of Object.entries(v.layers)) { - let features = []; - let layer = value; - for (let i2 = 0; i2 < layer.length; i2++) { - let result2 = loadGeomAndBbox(layer.feature(i2)._pbf, layer.feature(i2)._geometry, tileSize / layer.extent); - let numVertices = 0; - for (let part of result2.geom) - numVertices += part.length; - features.push({ - id: layer.feature(i2).id, - geomType: layer.feature(i2).type, - geom: result2.geom, - numVertices, - bbox: result2.bbox, - properties: layer.feature(i2).properties - }); + function toNum(low, high) { + return (high >>> 0) * 4294967296 + (low >>> 0); + } + function readVarintRemainder(l2, p2) { + const buf = p2.buf; + let h, b; + b = buf[p2.pos++]; + h = (b & 112) >> 4; + if (b < 128) + return toNum(l2, h); + b = buf[p2.pos++]; + h |= (b & 127) << 3; + if (b < 128) + return toNum(l2, h); + b = buf[p2.pos++]; + h |= (b & 127) << 10; + if (b < 128) + return toNum(l2, h); + b = buf[p2.pos++]; + h |= (b & 127) << 17; + if (b < 128) + return toNum(l2, h); + b = buf[p2.pos++]; + h |= (b & 127) << 24; + if (b < 128) + return toNum(l2, h); + b = buf[p2.pos++]; + h |= (b & 1) << 31; + if (b < 128) + return toNum(l2, h); + throw new Error("Expected varint not more than 10 bytes"); + } + function readVarint(p2) { + const buf = p2.buf; + let val, b; + b = buf[p2.pos++]; + val = b & 127; + if (b < 128) + return val; + b = buf[p2.pos++]; + val |= (b & 127) << 7; + if (b < 128) + return val; + b = buf[p2.pos++]; + val |= (b & 127) << 14; + if (b < 128) + return val; + b = buf[p2.pos++]; + val |= (b & 127) << 21; + if (b < 128) + return val; + b = buf[p2.pos]; + val |= (b & 15) << 28; + return readVarintRemainder(val, p2); + } + function rotate(n2, xy, rx, ry) { + if (ry == 0) { + if (rx == 1) { + xy[0] = n2 - 1 - xy[0]; + xy[1] = n2 - 1 - xy[1]; } - result.set(key, features); + const t2 = xy[0]; + xy[0] = xy[1]; + xy[1] = t2; } - return result; } - var PmtilesSource = class { - constructor(url) { - if (url.url) { - this.p = url; + function zxyToTileId(z2, x2, y) { + let acc = 0; + let tz = 0; + while (tz < z2) { + acc += (1 << tz) * (1 << tz); + tz++; + } + const n2 = 1 << z2; + let rx = 0; + let ry = 0; + let d = 0; + const xy = [x2, y]; + let s2 = n2 / 2 >> 0; + while (s2 > 0) { + rx = (xy[0] & s2) > 0 ? 1 : 0; + ry = (xy[1] & s2) > 0 ? 1 : 0; + d += s2 * s2 * (3 * rx ^ ry); + rotate(s2, xy, rx, ry); + s2 = s2 / 2 >> 0; + } + return acc + d; + } + var ENTRY_SIZE_BYTES = 32; + var Compression; + (function(Compression2) { + Compression2[Compression2["Unknown"] = 0] = "Unknown"; + Compression2[Compression2["None"] = 1] = "None"; + Compression2[Compression2["Gzip"] = 2] = "Gzip"; + Compression2[Compression2["Brotli"] = 3] = "Brotli"; + Compression2[Compression2["Zstd"] = 4] = "Zstd"; + })(Compression || (Compression = {})); + function tryDecompress(buf, compression) { + if (compression === 1 || compression === 0) { + return buf; + } else if (compression === 2) { + return decompressSync(new Uint8Array(buf)); + } else { + throw Error("Compression method not supported"); + } + } + var TileType; + (function(TileType2) { + TileType2[TileType2["Unknown"] = 0] = "Unknown"; + TileType2[TileType2["Mvt"] = 1] = "Mvt"; + TileType2[TileType2["Png"] = 2] = "Png"; + TileType2[TileType2["Jpeg"] = 3] = "Jpeg"; + TileType2[TileType2["Webp"] = 4] = "Webp"; + })(TileType || (TileType = {})); + var HEADER_SIZE_BYTES = 127; + function findTile(entries, tileId) { + let m = 0; + let n2 = entries.length - 1; + while (m <= n2) { + const k = n2 + m >> 1; + const cmp = tileId - entries[k].tileId; + if (cmp > 0) { + m = k + 1; + } else if (cmp < 0) { + n2 = k - 1; } else { - this.p = new PMTiles(url); + return entries[k]; } - this.controllers = []; } - get(c2, tileSize) { - return __async(this, null, function* () { - this.controllers = this.controllers.filter((cont) => { - if (cont[0] != c2.z) { - cont[1].abort(); - return false; - } - return true; - }); - let result = yield this.p.getZxy(c2.z, c2.x, c2.y); - if (!result) - throw new Error(`Tile ${c2.z} ${c2.x} ${c2.y} not found in archive`); - const controller = new AbortController(); - this.controllers.push([c2.z, controller]); - const signal = controller.signal; - return new Promise((resolve, reject) => { - fetch(this.p.url, { headers: { Range: "bytes=" + result[0] + "-" + (result[0] + result[1] - 1) }, signal }).then((resp) => { - return resp.arrayBuffer(); - }).then((buffer) => { - let result2 = parseTile(buffer, tileSize); - resolve(result2); - }).catch((e2) => { - reject(e2); - }); - }); - }); + if (n2 >= 0) { + if (entries[n2].runLength === 0) { + return entries[n2]; + } + if (tileId - entries[n2].tileId < entries[n2].runLength) { + return entries[n2]; + } } - }; - var ZxySource = class { + return null; + } + var FetchSource = class { constructor(url) { this.url = url; - this.controllers = []; } - get(c2, tileSize) { - return __async(this, null, function* () { - this.controllers = this.controllers.filter((cont) => { - if (cont[0] != c2.z) { - cont[1].abort(); - return false; - } - return true; + getKey() { + return this.url; + } + getBytes(offset, length, signal) { + return __async2(this, null, function* () { + let controller; + if (!signal) { + controller = new AbortController(); + signal = controller.signal; + } + const resp = yield fetch(this.url, { + signal, + headers: { Range: "bytes=" + offset + "-" + (offset + length - 1) } }); - let url = this.url.replace("{z}", c2.z.toString()).replace("{x}", c2.x.toString()).replace("{y}", c2.y.toString()); - const controller = new AbortController(); + const contentLength = resp.headers.get("Content-Length"); + if (!contentLength || +contentLength !== length) { + console.error("Content-Length mismatch indicates byte serving not supported; aborting."); + if (controller) + controller.abort(); + } + const a2 = yield resp.arrayBuffer(); + return { + data: a2, + etag: resp.headers.get("ETag") || void 0, + cacheControl: resp.headers.get("Cache-Control") || void 0, + expires: resp.headers.get("Expires") || void 0 + }; + }); + } + }; + function bytesToHeader(bytes, etag) { + const v = new DataView(bytes); + return { + specVersion: 3, + rootDirectoryOffset: Number(v.getBigUint64(8, true)), + rootDirectoryLength: Number(v.getBigUint64(16, true)), + jsonMetadataOffset: Number(v.getBigUint64(24, true)), + jsonMetadataLength: Number(v.getBigUint64(32, true)), + leafDirectoryOffset: Number(v.getBigUint64(40, true)), + leafDirectoryLength: Number(v.getBigUint64(48, true)), + tileDataOffset: Number(v.getBigUint64(56, true)), + tileDataLength: Number(v.getBigUint64(64, true)), + numAddressedTiles: Number(v.getBigUint64(72, true)), + numTileEntries: Number(v.getBigUint64(80, true)), + numTileContents: Number(v.getBigUint64(88, true)), + clustered: v.getUint8(96) === 1, + internalCompression: v.getUint8(97), + tileCompression: v.getUint8(98), + tileType: v.getUint8(99), + minZoom: v.getUint8(100), + maxZoom: v.getUint8(101), + minLon: v.getInt32(102, true) / 1e7, + minLat: v.getInt32(106, true) / 1e7, + maxLon: v.getInt32(110, true) / 1e7, + maxLat: v.getInt32(114, true) / 1e7, + centerZoom: v.getUint8(118), + centerLon: v.getInt32(119, true) / 1e7, + centerLat: v.getInt32(123, true) / 1e7, + etag + }; + } + function deserializeIndex(buffer) { + const p2 = { buf: new Uint8Array(buffer), pos: 0 }; + const numEntries = readVarint(p2); + const entries = []; + let lastId = 0; + for (let i2 = 0; i2 < numEntries; i2++) { + const v = readVarint(p2); + entries.push({ tileId: lastId + v, offset: 0, length: 0, runLength: 1 }); + lastId += v; + } + for (let i2 = 0; i2 < numEntries; i2++) { + entries[i2].runLength = readVarint(p2); + } + for (let i2 = 0; i2 < numEntries; i2++) { + entries[i2].length = readVarint(p2); + } + for (let i2 = 0; i2 < numEntries; i2++) { + const v = readVarint(p2); + if (v === 0 && i2 > 0) { + entries[i2].offset = entries[i2 - 1].offset + entries[i2 - 1].length; + } else { + entries[i2].offset = v - 1; + } + } + return entries; + } + function detectVersion(a2) { + const v = new DataView(a2); + if (v.getUint16(2, true) === 2) { + console.warn("PMTiles spec version 2 has been deprecated; please see github.com/protomaps/PMTiles for tools to upgrade"); + return 2; + } else if (v.getUint16(2, true) === 1) { + console.warn("PMTiles spec version 1 has been deprecated; please see github.com/protomaps/PMTiles for tools to upgrade"); + return 1; + } + return 3; + } + var VersionMismatch = class extends Error { + }; + function getHeaderAndRoot(source, prefetch) { + return __async2(this, null, function* () { + let resp = yield source.getBytes(0, 16384); + const v = new DataView(resp.data); + if (v.getUint16(0, true) !== 19792) { + throw new Error("Wrong magic number for PMTiles archive"); + } + if (detectVersion(resp.data) < 3) { + return [yield v2_default.getHeader(source)]; + } + const headerData = resp.data.slice(0, HEADER_SIZE_BYTES); + const header = bytesToHeader(headerData, resp.etag); + if (prefetch) { + const rootDirData = resp.data.slice(header.rootDirectoryOffset, header.rootDirectoryOffset + header.rootDirectoryLength); + const dirKey = source.getKey() + "|" + (header.etag || "") + "|" + header.rootDirectoryOffset + "|" + header.rootDirectoryLength; + const rootDir = deserializeIndex(tryDecompress(rootDirData, header.internalCompression)); + return [header, [dirKey, ENTRY_SIZE_BYTES * rootDir.length, rootDir]]; + } + return [header, void 0]; + }); + } + function getDirectory(source, offset, length, header) { + return __async2(this, null, function* () { + let resp = yield source.getBytes(offset, length); + if (header.etag && header.etag !== resp.etag) { + throw new VersionMismatch("ETag mismatch: " + header.etag); + } + const data = tryDecompress(resp.data, header.internalCompression); + const directory = deserializeIndex(data); + if (directory.length === 0) { + throw new Error("Empty directory is invalid"); + } + return directory; + }); + } + var SharedPromiseCache = class { + constructor(maxSizeBytes = 64e6, prefetch = true) { + this.cache = new Map(); + this.sizeBytes = 0; + this.maxSizeBytes = maxSizeBytes; + this.counter = 1; + this.prefetch = prefetch; + } + getHeader(source) { + return __async2(this, null, function* () { + const cacheKey = source.getKey(); + if (this.cache.has(cacheKey)) { + this.cache.get(cacheKey).lastUsed = this.counter++; + const data = yield this.cache.get(cacheKey).data; + return data; + } + const p2 = new Promise((resolve, reject) => { + getHeaderAndRoot(source, this.prefetch).then((res) => { + if (this.cache.has(cacheKey)) { + this.cache.get(cacheKey).size = HEADER_SIZE_BYTES; + this.sizeBytes += HEADER_SIZE_BYTES; + } + if (res[1]) { + this.cache.set(res[1][0], { + lastUsed: this.counter++, + size: res[1][1], + data: Promise.resolve(res[1][2]) + }); + } + resolve(res[0]); + this.prune(); + }).catch((e2) => { + reject(e2); + }); + }); + this.cache.set(cacheKey, { lastUsed: this.counter++, data: p2, size: 0 }); + return p2; + }); + } + getDirectory(source, offset, length, header) { + return __async2(this, null, function* () { + const cacheKey = source.getKey() + "|" + (header.etag || "") + "|" + offset + "|" + length; + if (this.cache.has(cacheKey)) { + this.cache.get(cacheKey).lastUsed = this.counter++; + const data = yield this.cache.get(cacheKey).data; + return data; + } + const p2 = new Promise((resolve, reject) => { + getDirectory(source, offset, length, header).then((directory) => { + resolve(directory); + if (this.cache.has(cacheKey)) { + this.cache.get(cacheKey).size = ENTRY_SIZE_BYTES * directory.length; + this.sizeBytes += ENTRY_SIZE_BYTES * directory.length; + } + this.prune(); + }).catch((e2) => { + reject(e2); + }); + }); + this.cache.set(cacheKey, { lastUsed: this.counter++, data: p2, size: 0 }); + return p2; + }); + } + getArrayBuffer(source, offset, length, header) { + return __async2(this, null, function* () { + const cacheKey = source.getKey() + "|" + (header.etag || "") + "|" + offset + "|" + length; + if (this.cache.has(cacheKey)) { + this.cache.get(cacheKey).lastUsed = this.counter++; + const data = yield this.cache.get(cacheKey).data; + return data; + } + const p2 = new Promise((resolve, reject) => { + source.getBytes(offset, length).then((resp) => { + if (header.etag && header.etag !== resp.etag) { + throw new VersionMismatch("ETag mismatch: " + header.etag); + } + resolve(resp.data); + if (this.cache.has(cacheKey)) { + this.cache.get(cacheKey).size = resp.data.byteLength; + this.sizeBytes += resp.data.byteLength; + } + this.prune(); + }).catch((e2) => { + reject(e2); + }); + }); + this.cache.set(cacheKey, { lastUsed: this.counter++, data: p2, size: 0 }); + return p2; + }); + } + prune() { + while (this.sizeBytes > this.maxSizeBytes) { + let minUsed = Infinity; + let minKey = void 0; + this.cache.forEach((cache_value, key) => { + if (cache_value.lastUsed < minUsed) { + minUsed = cache_value.lastUsed; + minKey = key; + } + }); + if (minKey) { + this.sizeBytes -= this.cache.get(minKey).size; + this.cache.delete(minKey); + } + } + } + invalidate(source) { + this.cache.delete(source.getKey()); + } + }; + var PMTiles = class { + constructor(source, cache) { + if (typeof source === "string") { + this.source = new FetchSource(source); + } else { + this.source = source; + } + if (cache) { + this.cache = cache; + } else { + this.cache = new SharedPromiseCache(); + } + } + root_entries() { + return __async2(this, null, function* () { + const header = yield this.cache.getHeader(this.source); + if (header.specVersion < 3) { + return []; + } + let d_o = header.rootDirectoryOffset; + let d_l = header.rootDirectoryLength; + return yield this.cache.getDirectory(this.source, d_o, d_l, header); + }); + } + getHeader() { + return __async2(this, null, function* () { + return yield this.cache.getHeader(this.source); + }); + } + getZxyAttempt(z2, x2, y, signal) { + return __async2(this, null, function* () { + const tile_id = zxyToTileId(z2, x2, y); + const header = yield this.cache.getHeader(this.source); + if (header.specVersion < 3) { + return v2_default.getZxy(header, this.source, this.cache, z2, x2, y, signal); + } + if (z2 < header.minZoom || z2 > header.maxZoom) { + return void 0; + } + let d_o = header.rootDirectoryOffset; + let d_l = header.rootDirectoryLength; + for (let depth = 0; depth < 5; depth++) { + const directory = yield this.cache.getDirectory(this.source, d_o, d_l, header); + const entry = findTile(directory, tile_id); + if (entry) { + if (entry.runLength > 0) { + const resp = yield this.source.getBytes(header.tileDataOffset + entry.offset, entry.length, signal); + if (header.etag && header.etag !== resp.etag) { + throw new VersionMismatch("ETag mismatch: " + header.etag); + } + return { + data: tryDecompress(resp.data, header.tileCompression), + cacheControl: resp.cacheControl, + expires: resp.expires + }; + } else { + d_o = header.leafDirectoryOffset + entry.offset; + d_l = entry.length; + } + } else { + return void 0; + } + } + throw Error("Maximum directory depth exceeded"); + }); + } + getZxy(z2, x2, y, signal) { + return __async2(this, null, function* () { + try { + return yield this.getZxyAttempt(z2, x2, y, signal); + } catch (e2) { + if (e2 instanceof VersionMismatch) { + this.cache.invalidate(this.source); + return yield this.getZxyAttempt(z2, x2, y, signal); + } else { + throw e2; + } + } + }); + } + getMetadataAttempt() { + return __async2(this, null, function* () { + const header = yield this.cache.getHeader(this.source); + const resp = yield this.source.getBytes(header.jsonMetadataOffset, header.jsonMetadataLength); + if (header.etag && header.etag !== resp.etag) { + throw new VersionMismatch("Etag mismatch: " + header.etag); + } + const decompressed = tryDecompress(resp.data, header.internalCompression); + const dec = new TextDecoder("utf-8"); + return JSON.parse(dec.decode(decompressed)); + }); + } + getMetadata() { + return __async2(this, null, function* () { + try { + return yield this.getMetadataAttempt(); + } catch (e2) { + if (e2 instanceof VersionMismatch) { + this.cache.invalidate(this.source); + return yield this.getMetadataAttempt(); + } else { + throw e2; + } + } + }); + } + }; + + // src/tilecache.ts + var GeomType; + (function(GeomType2) { + GeomType2[GeomType2["Point"] = 1] = "Point"; + GeomType2[GeomType2["Line"] = 2] = "Line"; + GeomType2[GeomType2["Polygon"] = 3] = "Polygon"; + })(GeomType || (GeomType = {})); + function toIndex(c2) { + return c2.x + ":" + c2.y + ":" + c2.z; + } + var loadGeomAndBbox = (pbf, geometry, scale) => { + pbf.pos = geometry; + var end = pbf.readVarint() + pbf.pos, cmd = 1, length = 0, x2 = 0, y = 0, x1 = Infinity, x22 = -Infinity, y1 = Infinity, y2 = -Infinity; + var lines = []; + var line = []; + while (pbf.pos < end) { + if (length <= 0) { + var cmdLen = pbf.readVarint(); + cmd = cmdLen & 7; + length = cmdLen >> 3; + } + length--; + if (cmd === 1 || cmd === 2) { + x2 += pbf.readSVarint() * scale; + y += pbf.readSVarint() * scale; + if (x2 < x1) + x1 = x2; + if (x2 > x22) + x22 = x2; + if (y < y1) + y1 = y; + if (y > y2) + y2 = y; + if (cmd === 1) { + if (line.length > 0) + lines.push(line); + line = []; + } + line.push(new import_point_geometry.default(x2, y)); + } else if (cmd === 7) { + if (line) + line.push(line[0].clone()); + } else + throw new Error("unknown command " + cmd); + } + if (line) + lines.push(line); + return { geom: lines, bbox: { minX: x1, minY: y1, maxX: x22, maxY: y2 } }; + }; + function parseTile(buffer, tileSize) { + let v = new import_vector_tile.VectorTile(new import_pbf.default(buffer)); + let result = new Map(); + for (let [key, value] of Object.entries(v.layers)) { + let features = []; + let layer = value; + for (let i2 = 0; i2 < layer.length; i2++) { + let loaded = loadGeomAndBbox(layer.feature(i2)._pbf, layer.feature(i2)._geometry, tileSize / layer.extent); + let numVertices = 0; + for (let part of loaded.geom) + numVertices += part.length; + features.push({ + id: layer.feature(i2).id, + geomType: layer.feature(i2).type, + geom: loaded.geom, + numVertices, + bbox: loaded.bbox, + props: layer.feature(i2).properties + }); + } + result.set(key, features); + } + return result; + } + var PmtilesSource = class { + constructor(url, shouldCancelZooms) { + if (typeof url == "string") { + this.p = new PMTiles(url); + } else { + this.p = url; + } + this.controllers = []; + this.shouldCancelZooms = shouldCancelZooms; + } + get(c2, tileSize) { + return __async(this, null, function* () { + if (this.shouldCancelZooms) { + this.controllers = this.controllers.filter((cont) => { + if (cont[0] != c2.z) { + cont[1].abort(); + return false; + } + return true; + }); + } + const controller = new AbortController(); + this.controllers.push([c2.z, controller]); + const signal = controller.signal; + let result = yield this.p.getZxy(c2.z, c2.x, c2.y, signal); + if (result) { + return parseTile(result.data, tileSize); + } else { + return new Map(); + } + }); + } + }; + var ZxySource = class { + constructor(url, shouldCancelZooms) { + this.url = url; + this.controllers = []; + this.shouldCancelZooms = shouldCancelZooms; + } + get(c2, tileSize) { + return __async(this, null, function* () { + if (this.shouldCancelZooms) { + this.controllers = this.controllers.filter((cont) => { + if (cont[0] != c2.z) { + cont[1].abort(); + return false; + } + return true; + }); + } + let url = this.url.replace("{z}", c2.z.toString()).replace("{x}", c2.x.toString()).replace("{y}", c2.y.toString()); + const controller = new AbortController(); this.controllers.push([c2.z, controller]); const signal = controller.signal; return new Promise((resolve, reject) => { @@ -2095,6 +2992,75 @@ var protomaps = (() => { let sin = Math.sin(constrained_lat * d); return new import_point_geometry.default(R * latlng[1] * d, R * Math.log((1 + sin) / (1 - sin)) / 2); }; + function sqr(x2) { + return x2 * x2; + } + function dist2(v, w) { + return sqr(v.x - w.x) + sqr(v.y - w.y); + } + function distToSegmentSquared(p2, v, w) { + var l2 = dist2(v, w); + if (l2 === 0) + return dist2(p2, v); + var t2 = ((p2.x - v.x) * (w.x - v.x) + (p2.y - v.y) * (w.y - v.y)) / l2; + t2 = Math.max(0, Math.min(1, t2)); + return dist2(p2, new import_point_geometry.default(v.x + t2 * (w.x - v.x), v.y + t2 * (w.y - v.y))); + } + function isInRing(point, ring) { + var inside = false; + for (var i2 = 0, j = ring.length - 1; i2 < ring.length; j = i2++) { + var xi = ring[i2].x, yi = ring[i2].y; + var xj = ring[j].x, yj = ring[j].y; + var intersect = yi > point.y != yj > point.y && point.x < (xj - xi) * (point.y - yi) / (yj - yi) + xi; + if (intersect) + inside = !inside; + } + return inside; + } + function isCCW(ring) { + var area = 0; + for (var i2 = 0; i2 < ring.length; i2++) { + let j = (i2 + 1) % ring.length; + area += ring[i2].x * ring[j].y; + area -= ring[j].x * ring[i2].y; + } + return area < 0; + } + function pointInPolygon(point, geom) { + var isInCurrentExterior = false; + for (let ring of geom) { + if (isCCW(ring)) { + if (isInRing(point, ring)) + isInCurrentExterior = false; + } else { + if (isInCurrentExterior) + return true; + if (isInRing(point, ring)) + isInCurrentExterior = true; + } + } + return isInCurrentExterior; + } + function pointMinDistToPoints(point, geom) { + let min = Infinity; + for (let l2 of geom) { + let dist = Math.sqrt(dist2(point, l2[0])); + if (dist < min) + min = dist; + } + return min; + } + function pointMinDistToLines(point, geom) { + let min = Infinity; + for (let l2 of geom) { + for (var i2 = 0; i2 < l2.length - 1; i2++) { + let dist = Math.sqrt(distToSegmentSquared(point, l2[i2], l2[i2 + 1])); + if (dist < min) + min = dist; + } + } + return min; + } var TileCache = class { constructor(source, tileSize) { this.source = source; @@ -2102,7 +3068,7 @@ var protomaps = (() => { this.inflight = new Map(); this.tileSize = tileSize; } - queryFeatures(lng, lat, zoom) { + queryFeatures(lng, lat, zoom, brushSize) { let projected = project([lat, lng]); var normalized = new import_point_geometry.default((projected.x + MAXCOORD) / (MAXCOORD * 2), 1 - (projected.y + MAXCOORD) / (MAXCOORD * 2)); if (normalized.x > 1) @@ -2114,13 +3080,21 @@ var protomaps = (() => { let retval = []; let entry = this.cache.get(idx); if (entry) { - const center_bbox_x = (on_zoom.x - tile_x) * this.tileSize; - const center_bbox_y = (on_zoom.y - tile_y) * this.tileSize; - let query_bbox = { minX: center_bbox_x - 8, minY: center_bbox_y - 8, maxX: center_bbox_x + 8, maxY: center_bbox_y + 8 }; + const center = new import_point_geometry.default((on_zoom.x - tile_x) * this.tileSize, (on_zoom.y - tile_y) * this.tileSize); for (let [layer_name, layer_arr] of entry.data.entries()) { for (let feature of layer_arr) { - if (query_bbox.maxX >= feature.bbox.minX && feature.bbox.maxX >= query_bbox.minX && (query_bbox.maxY >= feature.bbox.minY && feature.bbox.maxY >= query_bbox.minY)) { - retval.push(feature); + if (feature.geomType == 1) { + if (pointMinDistToPoints(center, feature.geom) < brushSize) { + retval.push({ feature, layerName: layer_name }); + } + } else if (feature.geomType == 2) { + if (pointMinDistToLines(center, feature.geom) < brushSize) { + retval.push({ feature, layerName: layer_name }); + } + } else { + if (pointInPolygon(center, feature.geom)) { + retval.push({ feature, layerName: layer_name }); + } } } } @@ -2152,8 +3126,10 @@ var protomaps = (() => { let min_used = Infinity; let min_key = void 0; this.cache.forEach((value, key) => { - if (value.used < min_used) + if (value.used < min_used) { + min_used = value.used; min_key = key; + } }); if (min_key) this.cache.delete(min_key); @@ -2173,7 +3149,6 @@ var protomaps = (() => { }; // src/view.ts - var import_point_geometry2 = __toModule(require_point_geometry()); var transformGeom = (geom, scale, translate) => { let retval = []; for (let arr2 of geom) { @@ -2185,6 +3160,14 @@ var protomaps = (() => { } return retval; }; + var wrap = (val, z2) => { + let dim = 1 << z2; + if (val < 0) + val = dim + val; + if (val >= dim) + val = val % dim; + return val; + }; var View = class { constructor(tileCache, maxDataLevel, levelDiff) { this.tileCache = tileCache; @@ -2192,11 +3175,12 @@ var protomaps = (() => { this.levelDiff = levelDiff; } dataTilesForBounds(display_zoom, bounds) { + let fractional = Math.pow(2, display_zoom) / Math.pow(2, Math.ceil(display_zoom)); let needed = []; var scale = 1; var dim = this.tileCache.tileSize; if (display_zoom < this.levelDiff) { - scale = 1 / (1 << this.levelDiff - display_zoom); + scale = 1 / (1 << this.levelDiff - display_zoom) * fractional; needed.push({ data_tile: { z: 0, x: 0, y: 0 }, origin: new import_point_geometry2.default(0, 0), @@ -2205,24 +3189,30 @@ var protomaps = (() => { }); } else if (display_zoom <= this.levelDiff + this.maxDataLevel) { let f2 = 1 << this.levelDiff; - let mintile_x = Math.floor(bounds.minX / f2 / 256); - let mintile_y = Math.floor(bounds.minY / f2 / 256); - let maxtile_x = Math.floor(bounds.maxX / f2 / 256); - let maxtile_y = Math.floor(bounds.maxY / f2 / 256); + let basetile_size = 256 * fractional; + let data_zoom = Math.ceil(display_zoom) - this.levelDiff; + let mintile_x = Math.floor(bounds.minX / f2 / basetile_size); + let mintile_y = Math.floor(bounds.minY / f2 / basetile_size); + let maxtile_x = Math.floor(bounds.maxX / f2 / basetile_size); + let maxtile_y = Math.floor(bounds.maxY / f2 / basetile_size); for (var tx = mintile_x; tx <= maxtile_x; tx++) { for (var ty = mintile_y; ty <= maxtile_y; ty++) { - let origin = new import_point_geometry2.default(tx * f2 * 256, ty * f2 * 256); + let origin = new import_point_geometry2.default(tx * f2 * basetile_size, ty * f2 * basetile_size); needed.push({ - data_tile: { z: display_zoom - this.levelDiff, x: tx, y: ty }, + data_tile: { + z: data_zoom, + x: wrap(tx, data_zoom), + y: wrap(ty, data_zoom) + }, origin, - scale: 1, - dim + scale: fractional, + dim: dim * fractional }); } } } else { let f2 = 1 << this.levelDiff; - scale = 1 << display_zoom - this.maxDataLevel - this.levelDiff; + scale = (1 << Math.ceil(display_zoom) - this.maxDataLevel - this.levelDiff) * fractional; let mintile_x = Math.floor(bounds.minX / f2 / 256 / scale); let mintile_y = Math.floor(bounds.minY / f2 / 256 / scale); let maxtile_x = Math.floor(bounds.maxX / f2 / 256 / scale); @@ -2231,7 +3221,11 @@ var protomaps = (() => { for (var ty = mintile_y; ty <= maxtile_y; ty++) { let origin = new import_point_geometry2.default(tx * f2 * 256 * scale, ty * f2 * 256 * scale); needed.push({ - data_tile: { z: this.maxDataLevel, x: tx, y: ty }, + data_tile: { + z: this.maxDataLevel, + x: wrap(tx, this.maxDataLevel), + y: wrap(ty, this.maxDataLevel) + }, origin, scale, dim: dim * scale @@ -2304,66 +3298,111 @@ var protomaps = (() => { }); } queryFeatures(lng, lat, display_zoom) { - return this.tileCache.queryFeatures(lng, lat, Math.min(display_zoom - this.levelDiff, this.maxDataLevel)); + let rounded_zoom = Math.round(display_zoom); + let data_zoom = Math.min(rounded_zoom - this.levelDiff, this.maxDataLevel); + let brush_size = 16 / (1 << rounded_zoom - data_zoom); + return this.tileCache.queryFeatures(lng, lat, data_zoom, brush_size); } }; + var sourcesToViews = (options) => { + let sourceToViews = (o2) => { + let level_diff = o2.levelDiff === void 0 ? 2 : o2.levelDiff; + let maxDataZoom = o2.maxDataZoom || 14; + let source; + if (typeof o2.url === "string") { + if (o2.url.endsWith(".pmtiles")) { + source = new PmtilesSource(o2.url, true); + } else { + source = new ZxySource(o2.url, true); + } + } else { + source = new PmtilesSource(o2.url, true); + } + let cache = new TileCache(source, 256 * 1 << level_diff); + return new View(cache, maxDataZoom, level_diff); + }; + let sources = new Map(); + if (options.sources) { + for (const key in options.sources) { + sources.set(key, sourceToViews(options.sources[key])); + } + } else { + sources.set("", sourceToViews(options)); + } + return sources; + }; // src/painter.ts var import_point_geometry3 = __toModule(require_point_geometry()); - function painter(ctx, prepared_tiles, label_data, rules, bbox, origin, clip, debug) { + function painter(ctx, z2, prepared_tilemap, label_data, rules, bbox, origin, clip, debug) { let start = performance.now(); ctx.save(); ctx.miterLimit = 2; - for (var prepared_tile of prepared_tiles) { - let po = prepared_tile.origin; - let ps = prepared_tile.scale; - ctx.save(); - if (clip) { - ctx.beginPath(); - ctx.rect(po.x - origin.x, po.y - origin.y, prepared_tile.dim, prepared_tile.dim); - ctx.clip(); - } - ctx.translate(po.x - origin.x, po.y - origin.y); - for (var rule of rules) { - if (rule.minzoom && prepared_tile.z < rule.minzoom) - continue; - if (rule.maxzoom && prepared_tile.z > rule.maxzoom) - continue; + for (var rule of rules) { + if (rule.minzoom && z2 < rule.minzoom) + continue; + if (rule.maxzoom && z2 > rule.maxzoom) + continue; + let prepared_tiles = prepared_tilemap.get(rule.dataSource || ""); + if (!prepared_tiles) + continue; + for (let prepared_tile of prepared_tiles) { var layer = prepared_tile.data.get(rule.dataLayer); if (layer === void 0) continue; - rule.symbolizer.before(ctx, prepared_tile.z); + if (rule.symbolizer.before) + rule.symbolizer.before(ctx, prepared_tile.z); + let po = prepared_tile.origin; + let dim = prepared_tile.dim; + let ps = prepared_tile.scale; + ctx.save(); + if (clip) { + ctx.beginPath(); + let minX = Math.max(po.x - origin.x, bbox.minX - origin.x); + let minY = Math.max(po.y - origin.y, bbox.minY - origin.y); + let maxX = Math.min(po.x - origin.x + dim, bbox.maxX - origin.x); + let maxY = Math.min(po.y - origin.y + dim, bbox.maxY - origin.y); + ctx.rect(minX, minY, maxX - minX, maxY - minY); + ctx.clip(); + } + ctx.translate(po.x - origin.x, po.y - origin.y); for (var feature of layer) { let geom = feature.geom; let fbox = feature.bbox; if (fbox.maxX * ps + po.x < bbox.minX || fbox.minX * ps + po.x > bbox.maxX || fbox.minY * ps + po.y > bbox.maxY || fbox.maxY * ps + po.y < bbox.minY) { continue; } - let properties = feature.properties; - if (rule.filter && !rule.filter(properties)) + if (rule.filter && !rule.filter(prepared_tile.z, feature)) continue; if (ps != 1) { geom = transformGeom(geom, ps, new import_point_geometry3.default(0, 0)); } - rule.symbolizer.draw(ctx, geom, properties); + rule.symbolizer.draw(ctx, geom, prepared_tile.z, feature); } + ctx.restore(); } - ctx.restore(); } - let matches = label_data.searchBbox(bbox, Infinity); - for (var label of matches) { - ctx.save(); - ctx.translate(label.anchor.x - origin.x, label.anchor.y - origin.y); - label.draw(ctx); - ctx.restore(); - if (debug) { - ctx.lineWidth = 0.5; - ctx.strokeStyle = debug; - ctx.fillStyle = debug; - ctx.globalAlpha = 1; - ctx.fillRect(label.anchor.x - origin.x - 2, label.anchor.y - origin.y - 2, 4, 4); - for (let bbox2 of label.bboxes) { - ctx.strokeRect(bbox2.minX - origin.x, bbox2.minY - origin.y, bbox2.maxX - bbox2.minX, bbox2.maxY - bbox2.minY); + if (clip) { + ctx.beginPath(); + ctx.rect(bbox.minX - origin.x, bbox.minY - origin.y, bbox.maxX - bbox.minX, bbox.maxY - bbox.minY); + ctx.clip(); + } + if (label_data) { + let matches = label_data.searchBbox(bbox, Infinity); + for (var label of matches) { + ctx.save(); + ctx.translate(label.anchor.x - origin.x, label.anchor.y - origin.y); + label.draw(ctx); + ctx.restore(); + if (debug) { + ctx.lineWidth = 0.5; + ctx.strokeStyle = debug; + ctx.fillStyle = debug; + ctx.globalAlpha = 1; + ctx.fillRect(label.anchor.x - origin.x - 2, label.anchor.y - origin.y - 2, 4, 4); + for (let bbox2 of label.bboxes) { + ctx.strokeRect(bbox2.minX - origin.x, bbox2.minY - origin.y, bbox2.maxX - bbox2.minX, bbox2.maxY - bbox2.minY); + } } } } @@ -2372,6 +3411,7 @@ var protomaps = (() => { } // src/labeler.ts + var import_point_geometry4 = __toModule(require_point_geometry()); var import_rbush = __toModule(require_rbush_min()); var covering = (display_zoom, tile_width, bbox) => { let res = 256; @@ -2382,20 +3422,34 @@ var protomaps = (() => { let maxy = Math.floor(bbox.maxY / res); let leveldiff = Math.log2(f2); let retval = []; - for (let x = minx; x <= maxx; x++) { + for (let x2 = minx; x2 <= maxx; x2++) { + let wrapped_x = x2 % (1 << display_zoom); for (let y = miny; y <= maxy; y++) { retval.push({ - display: toIndex({ z: display_zoom, x, y }), - key: toIndex({ z: display_zoom - leveldiff, x: Math.floor(x / f2), y: Math.floor(y / f2) }) + display: toIndex({ z: display_zoom, x: wrapped_x, y }), + key: toIndex({ + z: display_zoom - leveldiff, + x: Math.floor(wrapped_x / f2), + y: Math.floor(y / f2) + }) }); } } return retval; }; var Index = class { - constructor() { + constructor(dim, maxLabeledTiles) { this.tree = new import_rbush.default(); this.current = new Map(); + this.dim = dim; + this.maxLabeledTiles = maxLabeledTiles; + } + hasPrefix(tileKey) { + for (let key of this.current.keys()) { + if (key.startsWith(tileKey)) + return true; + } + return false; } has(tileKey) { return this.current.has(tileKey); @@ -2442,29 +3496,109 @@ var protomaps = (() => { } return false; } + deduplicationCollides(label) { + if (!label.deduplicationKey || !label.deduplicationDistance) + return false; + let dist = label.deduplicationDistance; + let test_bbox = { + minX: label.anchor.x - dist, + minY: label.anchor.y - dist, + maxX: label.anchor.x + dist, + maxY: label.anchor.y + dist + }; + for (let collision of this.tree.search(test_bbox)) { + if (collision.indexed_label.deduplicationKey === label.deduplicationKey) { + if (collision.indexed_label.anchor.dist(label.anchor) < dist) { + return true; + } + } + } + return false; + } + makeEntry(tileKey) { + if (this.current.get(tileKey)) { + console.log("consistency error 1"); + } + let newSet = new Set(); + this.current.set(tileKey, newSet); + } insert(label, order, tileKey) { let indexed_label = { anchor: label.anchor, bboxes: label.bboxes, draw: label.draw, order, - tileKey + tileKey, + deduplicationKey: label.deduplicationKey, + deduplicationDistance: label.deduplicationDistance }; let entry = this.current.get(tileKey); - if (entry) { - entry.add(indexed_label); - } else { + if (!entry) { let newSet = new Set(); - newSet.add(indexed_label); this.current.set(tileKey, newSet); + entry = newSet; } + entry.add(indexed_label); + var wrapsLeft = false; + var wrapsRight = false; for (let bbox of label.bboxes) { var b = bbox; b.indexed_label = indexed_label; this.tree.insert(b); + if (bbox.minX < 0) + wrapsLeft = true; + if (bbox.maxX > this.dim) + wrapsRight = true; + } + if (wrapsLeft || wrapsRight) { + var shift2 = wrapsLeft ? this.dim : -this.dim; + var new_bboxes = []; + for (let bbox of label.bboxes) { + new_bboxes.push({ + minX: bbox.minX + shift2, + minY: bbox.minY, + maxX: bbox.maxX + shift2, + maxY: bbox.maxY + }); + } + let duplicate_label = { + anchor: new import_point_geometry4.default(label.anchor.x + shift2, label.anchor.y), + bboxes: new_bboxes, + draw: label.draw, + order, + tileKey + }; + let entry2 = this.current.get(tileKey); + if (entry2) + entry2.add(duplicate_label); + for (let bbox of new_bboxes) { + var b = bbox; + b.indexed_label = duplicate_label; + this.tree.insert(b); + } + } + } + pruneOrNoop(key_added) { + let added = key_added.split(":"); + let max_key = void 0; + let max_dist = 0; + let keys_for_ds = 0; + for (var existing_key of this.current.keys()) { + let existing = existing_key.split(":"); + if (existing[3] === added[3]) { + keys_for_ds++; + let dist = Math.sqrt(Math.pow(+existing[0] - +added[0], 2) + Math.pow(+existing[1] - +added[1], 2)); + if (dist > max_dist) { + max_dist = dist; + max_key = existing_key; + } + } + if (max_key && keys_for_ds > this.maxLabeledTiles) { + this.pruneKey(max_key); + } } } - prune(keyToRemove) { + pruneKey(keyToRemove) { let indexed_labels = this.current.get(keyToRemove); if (!indexed_labels) return; @@ -2495,16 +3629,25 @@ var protomaps = (() => { } }; var Labeler = class { - constructor(z2, scratch, labelRules2, callback) { - this.index = new Index(); + constructor(z2, scratch, labelRules2, maxLabeledTiles, callback) { + this.index = new Index(256 * 1 << z2, maxLabeledTiles); this.z = z2; this.scratch = scratch; this.labelRules = labelRules2; this.callback = callback; } - layout(pt) { + layout(prepared_tilemap) { let start = performance.now(); - let key = toIndex(pt.data_tile); + let keys_adding = new Set(); + for (let [k, prepared_tiles] of prepared_tilemap) { + for (let prepared_tile of prepared_tiles) { + let key2 = toIndex(prepared_tile.data_tile) + ":" + k; + if (!this.index.has(key2)) { + this.index.makeEntry(key2); + keys_adding.add(key2); + } + } + } let tiles_invalidated = new Set(); for (let [order, rule] of this.labelRules.entries()) { if (rule.visible == false) @@ -2513,58 +3656,74 @@ var protomaps = (() => { continue; if (rule.maxzoom && this.z > rule.maxzoom) continue; - let layer = pt.data.get(rule.dataLayer); - if (layer === void 0) + let dsName = rule.dataSource || ""; + let prepared_tiles = prepared_tilemap.get(dsName); + if (!prepared_tiles) continue; - let feats = layer; - if (rule.sort) - feats.sort((a2, b) => { - if (rule.sort) { - return rule.sort(a2.properties, b.properties); - } - return 0; - }); - let layout = { - index: this.index, - zoom: this.z, - scratch: this.scratch, - order - }; - for (let feature of feats) { - if (rule.filter && !rule.filter(feature.properties)) + for (let prepared_tile of prepared_tiles) { + let key2 = toIndex(prepared_tile.data_tile) + ":" + dsName; + if (!keys_adding.has(key2)) continue; - let transformed = transformGeom(feature.geom, pt.scale, pt.origin); - let labels = rule.symbolizer.place(layout, transformed, feature); - if (!labels) + let layer = prepared_tile.data.get(rule.dataLayer); + if (layer === void 0) continue; - for (let label of labels) { - var label_added = false; - if (this.index.labelCollides(label, Infinity)) { - if (!this.index.labelCollides(label, order)) { - let conflicts = this.index.searchLabel(label, Infinity); - for (let conflict of conflicts) { - this.index.removeLabel(conflict); - for (let bbox of conflict.bboxes) { - this.findInvalidatedTiles(tiles_invalidated, pt.dim, bbox, key); + let feats = layer; + if (rule.sort) + feats.sort((a2, b) => { + if (rule.sort) { + return rule.sort(a2.props, b.props); + } + return 0; + }); + let layout = { + index: this.index, + zoom: this.z, + scratch: this.scratch, + order, + overzoom: this.z - prepared_tile.data_tile.z + }; + for (let feature of feats) { + if (rule.filter && !rule.filter(this.z, feature)) + continue; + let transformed = transformGeom(feature.geom, prepared_tile.scale, prepared_tile.origin); + let labels = rule.symbolizer.place(layout, transformed, feature); + if (!labels) + continue; + for (let label of labels) { + var label_added = false; + if (label.deduplicationKey && this.index.deduplicationCollides(label)) { + continue; + } + if (this.index.labelCollides(label, Infinity)) { + if (!this.index.labelCollides(label, order)) { + let conflicts = this.index.searchLabel(label, Infinity); + for (let conflict of conflicts) { + this.index.removeLabel(conflict); + for (let bbox of conflict.bboxes) { + this.findInvalidatedTiles(tiles_invalidated, prepared_tile.dim, bbox, key2); + } } + this.index.insert(label, order, key2); + label_added = true; } - this.index.insert(label, order, key); + } else { + this.index.insert(label, order, key2); label_added = true; } - } else { - this.index.insert(label, order, key); - label_added = true; - } - if (label_added) { - for (let bbox of label.bboxes) { - if (bbox.maxX > pt.origin.x + pt.dim || bbox.minX < pt.origin.x || bbox.minY < pt.origin.y || bbox.maxY > pt.origin.y + pt.dim) { - this.findInvalidatedTiles(tiles_invalidated, pt.dim, bbox, key); + if (label_added) { + for (let bbox of label.bboxes) { + if (bbox.maxX > prepared_tile.origin.x + prepared_tile.dim || bbox.minX < prepared_tile.origin.x || bbox.minY < prepared_tile.origin.y || bbox.maxY > prepared_tile.origin.y + prepared_tile.dim) { + this.findInvalidatedTiles(tiles_invalidated, prepared_tile.dim, bbox, key2); + } } } } } } } + for (var key of keys_adding) { + this.index.pruneOrNoop(key); + } if (tiles_invalidated.size > 0 && this.callback) { this.callback(tiles_invalidated); } @@ -2573,53 +3732,43 @@ var protomaps = (() => { findInvalidatedTiles(tiles_invalidated, dim, bbox, key) { let touched = covering(this.z, dim, bbox); for (let s2 of touched) { - if (s2.key != key && this.index.has(s2.key)) { + if (s2.key != key && this.index.hasPrefix(s2.key)) { tiles_invalidated.add(s2.display); } } } - pruneCache(added) { - if (this.index.size() > 16) { - let max_key = void 0; - let max_dist = 0; - for (let key of this.index.keys()) { - let split = key.split(":"); - let dist = Math.sqrt(Math.pow(+split[0] - added.data_tile.x, 2) + Math.pow(+split[1] - added.data_tile.y, 2)); - if (dist > max_dist) { - max_dist = dist; - max_key = key; - } + add(prepared_tilemap) { + var all_added = true; + for (let [k, prepared_tiles] of prepared_tilemap) { + for (let prepared_tile of prepared_tiles) { + if (!this.index.has(toIndex(prepared_tile.data_tile) + ":" + k)) + all_added = false; } - if (max_key) - this.index.prune(max_key); } - } - add(prepared_tile) { - let idx = toIndex(prepared_tile.data_tile); - if (this.index.has(idx)) { + if (all_added) { return 0; } else { - let timing = this.layout(prepared_tile); - this.pruneCache(prepared_tile); + let timing = this.layout(prepared_tilemap); return timing; } } }; var Labelers = class { - constructor(scratch, labelRules2, callback) { + constructor(scratch, labelRules2, maxLabeledTiles, callback) { this.labelers = new Map(); this.scratch = scratch; this.labelRules = labelRules2; + this.maxLabeledTiles = maxLabeledTiles; this.callback = callback; } - add(prepared_tile) { - var labeler = this.labelers.get(prepared_tile.z); + add(z2, prepared_tilemap) { + var labeler = this.labelers.get(z2); if (labeler) { - return labeler.add(prepared_tile); + return labeler.add(prepared_tilemap); } else { - labeler = new Labeler(prepared_tile.z, this.scratch, this.labelRules, this.callback); - this.labelers.set(prepared_tile.z, labeler); - return labeler.add(prepared_tile); + labeler = new Labeler(z2, this.scratch, this.labelRules, this.maxLabeledTiles, this.callback); + this.labelers.set(z2, labeler); + return labeler.add(prepared_tilemap); } } getIndex(z2) { @@ -2701,62 +3850,179 @@ var protomaps = (() => { poisLabel: "#959393" }; + // node_modules/color2k/dist/index.module.js + function t(t2, n2, r2) { + return Math.min(Math.max(t2, r2), n2); + } + var n = class extends Error { + constructor(t2) { + super(`Failed to parse color: "${t2}"`); + } + }; + function r(r2) { + if (typeof r2 != "string") + throw new n(r2); + if (r2.trim().toLowerCase() === "transparent") + return [0, 0, 0, 0]; + let e2 = r2.trim(); + e2 = u.test(r2) ? function(t2) { + const r3 = t2.toLowerCase().trim(), e3 = o[function(t3) { + let n2 = 5381, r4 = t3.length; + for (; r4; ) + n2 = 33 * n2 ^ t3.charCodeAt(--r4); + return (n2 >>> 0) % 2341; + }(r3)]; + if (!e3) + throw new n(t2); + return `#${e3}`; + }(r2) : r2; + const f2 = s.exec(e2); + if (f2) { + const t2 = Array.from(f2).slice(1); + return [...t2.slice(0, 3).map((t3) => parseInt(_(t3, 2), 16)), parseInt(_(t2[3] || "f", 2), 16) / 255]; + } + const p2 = i.exec(e2); + if (p2) { + const t2 = Array.from(p2).slice(1); + return [...t2.slice(0, 3).map((t3) => parseInt(t3, 16)), parseInt(t2[3] || "ff", 16) / 255]; + } + const z2 = a.exec(e2); + if (z2) { + const t2 = Array.from(z2).slice(1); + return [...t2.slice(0, 3).map((t3) => parseInt(t3, 10)), parseFloat(t2[3] || "1")]; + } + const h = c.exec(e2); + if (h) { + const [e3, o2, _2, s2] = Array.from(h).slice(1).map(parseFloat); + if (t(0, 100, o2) !== o2) + throw new n(r2); + if (t(0, 100, _2) !== _2) + throw new n(r2); + return [...l(e3, o2, _2), s2 || 1]; + } + throw new n(r2); + } + var e = (t2) => parseInt(t2.replace(/_/g, ""), 36); + var o = "1q29ehhb 1n09sgk7 1kl1ekf_ _yl4zsno 16z9eiv3 1p29lhp8 _bd9zg04 17u0____ _iw9zhe5 _to73___ _r45e31e _7l6g016 _jh8ouiv _zn3qba8 1jy4zshs 11u87k0u 1ro9yvyo 1aj3xael 1gz9zjz0 _3w8l4xo 1bf1ekf_ _ke3v___ _4rrkb__ 13j776yz _646mbhl _nrjr4__ _le6mbhl 1n37ehkb _m75f91n _qj3bzfz 1939yygw 11i5z6x8 _1k5f8xs 1509441m 15t5lwgf _ae2th1n _tg1ugcv 1lp1ugcv 16e14up_ _h55rw7n _ny9yavn _7a11xb_ 1ih442g9 _pv442g9 1mv16xof 14e6y7tu 1oo9zkds 17d1cisi _4v9y70f _y98m8kc 1019pq0v 12o9zda8 _348j4f4 1et50i2o _8epa8__ _ts6senj 1o350i2o 1mi9eiuo 1259yrp0 1ln80gnw _632xcoy 1cn9zldc _f29edu4 1n490c8q _9f9ziet 1b94vk74 _m49zkct 1kz6s73a 1eu9dtog _q58s1rz 1dy9sjiq __u89jo3 _aj5nkwg _ld89jo3 13h9z6wx _qa9z2ii _l119xgq _bs5arju 1hj4nwk9 1qt4nwk9 1ge6wau6 14j9zlcw 11p1edc_ _ms1zcxe _439shk6 _jt9y70f _754zsow 1la40eju _oq5p___ _x279qkz 1fa5r3rv _yd2d9ip _424tcku _8y1di2_ _zi2uabw _yy7rn9h 12yz980_ __39ljp6 1b59zg0x _n39zfzp 1fy9zest _b33k___ _hp9wq92 1il50hz4 _io472ub _lj9z3eo 19z9ykg0 _8t8iu3a 12b9bl4a 1ak5yw0o _896v4ku _tb8k8lv _s59zi6t _c09ze0p 1lg80oqn 1id9z8wb _238nba5 1kq6wgdi _154zssg _tn3zk49 _da9y6tc 1sg7cv4f _r12jvtt 1gq5fmkz 1cs9rvci _lp9jn1c _xw1tdnb 13f9zje6 16f6973h _vo7ir40 _bt5arjf _rc45e4t _hr4e100 10v4e100 _hc9zke2 _w91egv_ _sj2r1kk 13c87yx8 _vqpds__ _ni8ggk8 _tj9yqfb 1ia2j4r4 _7x9b10u 1fc9ld4j 1eq9zldr _5j9lhpx _ez9zl6o _md61fzm".split(" ").reduce((t2, n2) => { + const r2 = e(n2.substring(0, 3)), o2 = e(n2.substring(3)).toString(16); + let _2 = ""; + for (let t3 = 0; t3 < 6 - o2.length; t3++) + _2 += "0"; + return t2[r2] = `${_2}${o2}`, t2; + }, {}); + var _ = (t2, n2) => Array.from(Array(n2)).map(() => t2).join(""); + var s = new RegExp(`^#${_("([a-f0-9])", 3)}([a-f0-9])?$`, "i"); + var i = new RegExp(`^#${_("([a-f0-9]{2})", 3)}([a-f0-9]{2})?$`, "i"); + var a = new RegExp(`^rgba?\\(\\s*(\\d+)\\s*${_(",\\s*(\\d+)\\s*", 2)}(?:,\\s*([\\d.]+))?\\s*\\)$`, "i"); + var c = /^hsla?\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%(?:\s*,\s*([\d.]+))?\s*\)$/i; + var u = /^[a-z]+$/i; + var f = (t2) => Math.round(255 * t2); + var l = (t2, n2, r2) => { + let e2 = r2 / 100; + if (n2 === 0) + return [e2, e2, e2].map(f); + const o2 = (t2 % 360 + 360) % 360 / 60, _2 = (1 - Math.abs(2 * e2 - 1)) * (n2 / 100), s2 = _2 * (1 - Math.abs(o2 % 2 - 1)); + let i2 = 0, a2 = 0, c2 = 0; + o2 >= 0 && o2 < 1 ? (i2 = _2, a2 = s2) : o2 >= 1 && o2 < 2 ? (i2 = s2, a2 = _2) : o2 >= 2 && o2 < 3 ? (a2 = _2, c2 = s2) : o2 >= 3 && o2 < 4 ? (a2 = s2, c2 = _2) : o2 >= 4 && o2 < 5 ? (i2 = s2, c2 = _2) : o2 >= 5 && o2 < 6 && (i2 = _2, c2 = s2); + const u2 = e2 - _2 / 2; + return [i2 + u2, a2 + u2, c2 + u2].map(f); + }; + function p(t2) { + const [n2, e2, o2, _2] = r(t2).map((t3, n3) => n3 === 3 ? t3 : t3 / 255), s2 = Math.max(n2, e2, o2), i2 = Math.min(n2, e2, o2), a2 = (s2 + i2) / 2; + if (s2 === i2) + return [0, 0, a2, _2]; + const c2 = s2 - i2; + return [60 * (n2 === s2 ? (e2 - o2) / c2 + (e2 < o2 ? 6 : 0) : e2 === s2 ? (o2 - n2) / c2 + 2 : (n2 - e2) / c2 + 4), a2 > 0.5 ? c2 / (2 - s2 - i2) : c2 / (s2 + i2), a2, _2]; + } + function z(n2, r2, e2, o2) { + return `hsla(${(n2 % 360).toFixed()}, ${t(0, 100, 100 * r2).toFixed()}%, ${t(0, 100, 100 * e2).toFixed()}%, ${parseFloat(t(0, 1, o2).toFixed(3))})`; + } + // src/symbolizer.ts - var import_point_geometry4 = __toModule(require_point_geometry()); + var import_point_geometry6 = __toModule(require_point_geometry()); + var import_unitbezier = __toModule(require_unitbezier_d()); var import_polylabel = __toModule(require_polylabel()); - // src/text.ts - function linebreak(str) { - if (str.length <= 15) - return [str]; - let space_before = str.lastIndexOf(" ", 14); - let space_after = str.indexOf(" ", 14); - if (space_before == -1 && space_after == -1) { - return [str]; + // src/attribute.ts + var StringAttr = class { + constructor(c2, defaultValue) { + this.str = c2 != null ? c2 : defaultValue; + this.per_feature = typeof this.str == "function" && this.str.length == 2; } - let first; - let after; - if (space_after == -1 || space_before >= 0 && 14 - space_before < space_after - 14) { - first = str.substring(0, space_before); - after = str.substring(space_before + 1, str.length); - } else { - first = str.substring(0, space_after); - after = str.substring(space_after + 1, str.length); + get(z2, f2) { + if (typeof this.str === "function") { + return this.str(z2, f2); + } else { + return this.str; + } } - return [first, ...linebreak(after)]; - } - var CJK_CHARS = "\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3220-\u3229\u3248-\u324F\u3251-\u325F\u3280-\u3289\u32B1-\u32BF\u3400-\u4DB5\u4E00-\u9FEA\uF900-\uFA6D\uFA70-\uFAD9\u2000"; - var cjk_test = new RegExp("^[" + CJK_CHARS + "]+$"); - var TextSpec = class { - constructor(options = {}) { - this.properties = options.properties || ["name"]; - this.textTransform = options.textTransform; - } - str(z2, f2) { - var retval; - for (let property of this.properties) { - if (f2.hasOwnProperty(property)) { - retval = f2[property]; + }; + var NumberAttr = class { + constructor(c2, defaultValue = 1) { + this.value = c2 != null ? c2 : defaultValue; + this.per_feature = typeof this.value == "function" && this.value.length == 2; + } + get(z2, f2) { + if (typeof this.value == "function") { + return this.value(z2, f2); + } else { + return this.value; + } + } + }; + var TextAttr = class { + constructor(options) { + var _a2; + this.label_props = (_a2 = options == null ? void 0 : options.label_props) != null ? _a2 : ["name"]; + this.textTransform = options == null ? void 0 : options.textTransform; + } + get(z2, f2) { + let retval; + let label_props; + if (typeof this.label_props == "function") { + label_props = this.label_props(z2, f2); + } else { + label_props = this.label_props; + } + for (let property of label_props) { + if (f2.props.hasOwnProperty(property) && typeof f2.props[property] === "string") { + retval = f2.props[property]; break; } } - if (retval && this.textTransform === "uppercase") + let transform; + if (typeof this.textTransform === "function") { + transform = this.textTransform(z2, f2); + } else { + transform = this.textTransform; + } + if (retval && transform === "uppercase") retval = retval.toUpperCase(); + else if (retval && transform === "lowercase") + retval = retval.toLowerCase(); + else if (retval && transform === "capitalize") { + const wordsArray = retval.toLowerCase().split(" "); + const capsArray = wordsArray.map((word) => { + return word[0].toUpperCase() + word.slice(1); + }); + retval = capsArray.join(" "); + } return retval; } }; - var FontSpec = class { + var FontAttr = class { constructor(options) { - if (options.font) { + var _a2, _b2; + if (options == null ? void 0 : options.font) { this.font = options.font; } else { - this.family = options.fontFamily || "sans-serif"; - this.size = options.fontSize || 12; - this.weight = options.fontWeight; - this.style = options.fontStyle; + this.family = (_a2 = options == null ? void 0 : options.fontFamily) != null ? _a2 : "sans-serif"; + this.size = (_b2 = options == null ? void 0 : options.fontSize) != null ? _b2 : 12; + this.weight = options == null ? void 0 : options.fontWeight; + this.style = options == null ? void 0 : options.fontStyle; } } - str(z2, f2) { + get(z2, f2) { if (this.font) { if (typeof this.font === "function") { return this.font(z2, f2); @@ -2796,77 +4062,233 @@ var protomaps = (() => { } } }; + var ArrayAttr = class { + constructor(c2, defaultValue = []) { + this.value = c2 != null ? c2 : defaultValue; + this.per_feature = typeof this.value == "function" && this.value.length == 2; + } + get(z2, f2) { + if (typeof this.value == "function") { + return this.value(z2, f2); + } else { + return this.value; + } + } + }; // src/line.ts - var import_xy = __toModule(require_xy()); - function simpleLabel(mls, minimum) { + var import_point_geometry5 = __toModule(require_point_geometry()); + var linelabel = (pts, max_angle_delta, targetLen) => { + var chunks = []; + var a2, b, c2, i2 = 0, n2 = 0, d = 0; + var abmag = 0, bcmag = 0; + var abx = 0, aby = 0; + var bcx = 0, bcy = 0; + var dt = 0; + var i_start = 0; + var d_start = 0; + if (pts.length < 2) + return []; + if (pts.length === 2) { + d = Math.sqrt(Math.pow(pts[1].x - pts[0].x, 2) + Math.pow(pts[1].y - pts[0].y, 2)); + return [ + { + length: d, + beginIndex: 0, + beginDistance: 0, + endIndex: 2, + endDistance: d + } + ]; + } + abmag = Math.sqrt(Math.pow(pts[1].x - pts[0].x, 2) + Math.pow(pts[1].y - pts[0].y, 2)); + for (i2 = 1, n2 = pts.length - 1; i2 < n2; i2++) { + a2 = pts[i2 - 1]; + b = pts[i2]; + c2 = pts[i2 + 1]; + abx = b.x - a2.x; + aby = b.y - a2.y; + bcx = c2.x - b.x; + bcy = c2.y - b.y; + bcmag = Math.sqrt(bcx * bcx + bcy * bcy); + d += abmag; + dt = Math.acos((abx * bcx + aby * bcy) / (abmag * bcmag)); + if (dt > max_angle_delta || d - d_start > targetLen) { + chunks.push({ + length: d - d_start, + beginDistance: d_start, + beginIndex: i_start, + endIndex: i2 + 1, + endDistance: d + }); + i_start = i2; + d_start = d; + } + abmag = bcmag; + } + if (i2 - i_start > 0) { + chunks.push({ + length: d - d_start + bcmag, + beginIndex: i_start, + beginDistance: d_start, + endIndex: i2 + 1, + endDistance: d + bcmag + }); + } + return chunks; + }; + function simpleLabel(mls, minimum, repeatDistance, cellSize) { let longestStart; let longestEnd; let longestLength = 0; + let candidates = []; + var lastLabeledDistance = -Infinity; for (let ls of mls) { - let segments = (0, import_xy.default)(ls, Math.PI / 2 / 18); + let segments = linelabel(ls, Math.PI / 45, minimum); for (let segment of segments) { - if (segment.length >= minimum && segment.length > longestLength) { - longestLength = segment.length; - longestStart = ls[segment.beginIndex]; - longestEnd = ls[segment.endIndex - 1]; + if (segment.length >= minimum + cellSize) { + let start = new import_point_geometry5.default(ls[segment.beginIndex].x, ls[segment.beginIndex].y); + let end = ls[segment.endIndex - 1]; + let normalized = new import_point_geometry5.default((end.x - start.x) / segment.length, (end.y - start.y) / segment.length); + for (var i2 = cellSize; i2 < segment.length - minimum; i2 += repeatDistance) { + candidates.push({ + start: start.add(normalized.mult(i2)), + end: start.add(normalized.mult(i2 + minimum)) + }); + } } } } - if (!longestStart) - return void 0; - if (longestStart.x == longestEnd.x && longestStart.y == longestEnd.y) { - return void 0; - } - return { start: longestStart, end: longestEnd }; + return candidates; } function lineCells(a2, b, length, spacing) { let dx = b.x - a2.x; let dy = b.y - a2.y; let dist = Math.sqrt(Math.pow(b.x - a2.x, 2) + Math.pow(b.y - a2.y, 2)); let retval = []; - for (var i2 = spacing; i2 < length; i2 += 2 * spacing) { + for (var i2 = 0; i2 < length + spacing; i2 += 2 * spacing) { let factor = i2 * 1 / dist; retval.push({ x: a2.x + factor * dx, y: a2.y + factor * dy }); } return retval; } + // src/text.ts + function linebreak(str, maxUnits) { + if (str.length <= maxUnits) + return [str]; + let endIndex = maxUnits - 1; + let space_before = str.lastIndexOf(" ", endIndex); + let space_after = str.indexOf(" ", endIndex); + if (space_before == -1 && space_after == -1) { + return [str]; + } + let first; + let after; + if (space_after == -1 || space_before >= 0 && endIndex - space_before < space_after - endIndex) { + first = str.substring(0, space_before); + after = str.substring(space_before + 1, str.length); + } else { + first = str.substring(0, space_after); + after = str.substring(space_after + 1, str.length); + } + return [first, ...linebreak(after, maxUnits)]; + } + var CJK_CHARS = "\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3220-\u3229\u3248-\u324F\u3251-\u325F\u3280-\u3289\u32B1-\u32BF\u3400-\u4DB5\u4E00-\u9FEA\uF900-\uFA6D\uFA70-\uFAD9\u2000"; + var cjk_test = new RegExp("^[" + CJK_CHARS + "]+$"); + // src/symbolizer.ts + var MAX_VERTICES_PER_DRAW_CALL = 5400; + var Justify; + (function(Justify2) { + Justify2[Justify2["Left"] = 1] = "Left"; + Justify2[Justify2["Center"] = 2] = "Center"; + Justify2[Justify2["Right"] = 3] = "Right"; + })(Justify || (Justify = {})); + var TextPlacements; + (function(TextPlacements2) { + TextPlacements2[TextPlacements2["N"] = 1] = "N"; + TextPlacements2[TextPlacements2["NE"] = 2] = "NE"; + TextPlacements2[TextPlacements2["E"] = 3] = "E"; + TextPlacements2[TextPlacements2["SE"] = 4] = "SE"; + TextPlacements2[TextPlacements2["S"] = 5] = "S"; + TextPlacements2[TextPlacements2["SW"] = 6] = "SW"; + TextPlacements2[TextPlacements2["W"] = 7] = "W"; + TextPlacements2[TextPlacements2["NW"] = 8] = "NW"; + })(TextPlacements || (TextPlacements = {})); var createPattern = (width, height, fn) => { const canvas = document.createElement("canvas"); const ctx = canvas.getContext("2d"); canvas.width = width; canvas.height = height; - fn(canvas, ctx); + if (ctx !== null) + fn(canvas, ctx); return canvas; }; var PolygonSymbolizer = class { constructor(options) { - this.fill = options.fill || "#000000"; - this.opacity = options.opacity || 1; + var _a2; this.pattern = options.pattern; + this.fill = new StringAttr(options.fill, "black"); + this.opacity = new NumberAttr(options.opacity, 1); + this.stroke = new StringAttr(options.stroke, "black"); + this.width = new NumberAttr(options.width, 0); + this.per_feature = (_a2 = this.fill.per_feature || this.opacity.per_feature || this.stroke.per_feature || this.width.per_feature || options.per_feature) != null ? _a2 : false; + this.do_stroke = false; } - before(ctx) { + before(ctx, z2) { + if (!this.per_feature) { + ctx.globalAlpha = this.opacity.get(z2); + ctx.fillStyle = this.fill.get(z2); + ctx.strokeStyle = this.stroke.get(z2); + let width = this.width.get(z2); + if (width > 0) + this.do_stroke = true; + ctx.lineWidth = width; + } if (this.pattern) { - ctx.fillStyle = ctx.createPattern(this.pattern, "repeat"); - } else { - ctx.fillStyle = this.fill; + const patten = ctx.createPattern(this.pattern, "repeat"); + if (patten) + ctx.fillStyle = patten; } - ctx.globalAlpha = this.opacity; } - draw(ctx, geom, properties) { + draw(ctx, geom, z2, f2) { + var do_stroke = false; + if (this.per_feature) { + ctx.globalAlpha = this.opacity.get(z2, f2); + ctx.fillStyle = this.fill.get(z2, f2); + var width = this.width.get(z2, f2); + if (width) { + do_stroke = true; + ctx.strokeStyle = this.stroke.get(z2, f2); + ctx.lineWidth = width; + } + } + let drawPath = () => { + ctx.fill(); + if (do_stroke || this.do_stroke) { + ctx.stroke(); + } + }; + var vertices_in_path = 0; ctx.beginPath(); for (var poly of geom) { - for (var p2 = 0; p2 < poly.length - 1; p2++) { + if (vertices_in_path + poly.length > MAX_VERTICES_PER_DRAW_CALL) { + drawPath(); + vertices_in_path = 0; + ctx.beginPath(); + } + for (var p2 = 0; p2 < poly.length; p2++) { let pt = poly[p2]; if (p2 == 0) ctx.moveTo(pt.x, pt.y); else ctx.lineTo(pt.x, pt.y); } + vertices_in_path += poly.length; } - ctx.fill(); + if (vertices_in_path > 0) + drawPath(); } }; function arr(base, a2) { @@ -2878,56 +4300,124 @@ var protomaps = (() => { return 0; }; } + function getStopIndex(input, stops) { + let idx = 0; + while (stops[idx + 1][0] < input) + idx++; + return idx; + } + function interpolate(factor, start, end) { + return factor * (end - start) + start; + } + function computeInterpolationFactor(z2, idx, base, stops) { + const difference = stops[idx + 1][0] - stops[idx][0]; + const progress = z2 - stops[idx][0]; + if (difference === 0) + return 0; + else if (base === 1) + return progress / difference; + else + return (Math.pow(base, progress) - 1) / (Math.pow(base, difference) - 1); + } function exp(base, stops) { return (z2) => { + if (stops.length < 1) + return 0; if (z2 <= stops[0][0]) return stops[0][1]; if (z2 >= stops[stops.length - 1][0]) return stops[stops.length - 1][1]; - let idx = 0; - while (stops[idx + 1][0] < z2) - idx++; - let difference = stops[idx + 1][0] - stops[idx][0]; - let progress = z2 - stops[idx][0]; - var factor; - if (difference === 0) - factor = 0; - else if (base === 1) - factor = progress / difference; - else - factor = (Math.pow(base, progress) - 1) / (Math.pow(base, difference) - 1); - return factor * (stops[idx + 1][1] - stops[idx][1]) + stops[idx][1]; + const idx = getStopIndex(z2, stops); + const factor = computeInterpolationFactor(z2, idx, base, stops); + return interpolate(factor, stops[idx][1], stops[idx + 1][1]); + }; + } + function step(output0, stops) { + return (z2) => { + if (stops.length < 1) + return 0; + let retval = output0; + for (let i2 = 0; i2 < stops.length; i2++) { + if (z2 >= stops[i2][0]) + retval = stops[i2][1]; + } + return retval; }; } - function isFunction(obj) { - return !!(obj && obj.constructor && obj.call && obj.apply); + function linear(stops) { + return exp(1, stops); + } + function cubicBezier(x1, y1, x2, y2, stops) { + return (z2) => { + if (stops.length < 1) + return 0; + const bezier = new import_unitbezier.default(x1, y1, x2, y2); + const idx = getStopIndex(z2, stops); + const factor = bezier.solve(computeInterpolationFactor(z2, idx, 1, stops)); + return interpolate(factor, stops[idx][1], stops[idx + 1][1]); + }; } var LineSymbolizer = class { constructor(options) { - this.color = options.color || "#000000"; - this.width = options.width || 1; - this.opacity = options.opacity || 1; + var _a2; + this.color = new StringAttr(options.color, "black"); + this.width = new NumberAttr(options.width); + this.opacity = new NumberAttr(options.opacity); + this.dash = options.dash ? new ArrayAttr(options.dash) : null; + this.dashColor = new StringAttr(options.dashColor, "black"); + this.dashWidth = new NumberAttr(options.dashWidth, 1); + this.lineCap = new StringAttr(options.lineCap, "butt"); + this.lineJoin = new StringAttr(options.lineJoin, "miter"); this.skip = false; - this.dash = options.dash; - this.dashColor = options.dashColor || "black"; - this.dashWidth = options.dashWidth || 1; + this.per_feature = !!(((_a2 = this.dash) == null ? void 0 : _a2.per_feature) || this.color.per_feature || this.opacity.per_feature || this.width.per_feature || this.lineCap.per_feature || this.lineJoin.per_feature || options.per_feature); } before(ctx, z2) { - ctx.strokeStyle = this.color; - ctx.globalAlpha = this.opacity; - if (isFunction(this.width) && this.width.length == 1) { - let width = this.width(z2); - this.skip = width === 0; - ctx.lineWidth = width; - } else { - ctx.lineWidth = this.width; + if (!this.per_feature) { + ctx.strokeStyle = this.color.get(z2); + ctx.lineWidth = this.width.get(z2); + ctx.globalAlpha = this.opacity.get(z2); + ctx.lineCap = this.lineCap.get(z2); + ctx.lineJoin = this.lineJoin.get(z2); } } - draw(ctx, geom, properties) { + draw(ctx, geom, z2, f2) { if (this.skip) return; + let strokePath = () => { + if (this.per_feature) { + ctx.globalAlpha = this.opacity.get(z2, f2); + ctx.lineCap = this.lineCap.get(z2, f2); + ctx.lineJoin = this.lineJoin.get(z2, f2); + } + if (this.dash) { + ctx.save(); + if (this.per_feature) { + ctx.lineWidth = this.dashWidth.get(z2, f2); + ctx.strokeStyle = this.dashColor.get(z2, f2); + ctx.setLineDash(this.dash.get(z2, f2)); + } else { + ctx.setLineDash(this.dash.get(z2)); + } + ctx.stroke(); + ctx.restore(); + } else { + ctx.save(); + if (this.per_feature) { + ctx.lineWidth = this.width.get(z2, f2); + ctx.strokeStyle = this.color.get(z2, f2); + } + ctx.stroke(); + ctx.restore(); + } + }; + var vertices_in_path = 0; ctx.beginPath(); for (var ls of geom) { + if (vertices_in_path + ls.length > MAX_VERTICES_PER_DRAW_CALL) { + strokePath(); + vertices_in_path = 0; + ctx.beginPath(); + } for (var p2 = 0; p2 < ls.length; p2++) { let pt = ls[p2]; if (p2 == 0) @@ -2935,95 +4425,98 @@ var protomaps = (() => { else ctx.lineTo(pt.x, pt.y); } + vertices_in_path += ls.length; } - if (this.dash) { - ctx.save(); - ctx.lineWidth = this.dashWidth; - ctx.strokeStyle = this.dashColor; - ctx.setLineDash(this.dash); - ctx.stroke(); - ctx.restore(); - } else { - ctx.stroke(); - } + if (vertices_in_path > 0) + strokePath(); } }; var IconSymbolizer = class { constructor(options) { - this.sprites = options.sprites; this.name = options.name; + this.sheet = options.sheet; + this.dpr = window.devicePixelRatio; } place(layout, geom, feature) { let pt = geom[0]; - let a2 = new import_point_geometry4.default(geom[0][0].x, geom[0][0].y); + let a2 = new import_point_geometry6.default(geom[0][0].x, geom[0][0].y); + let loc = this.sheet.get(this.name); + let width = loc.w / this.dpr; + let height = loc.h / this.dpr; let bbox = { - minX: a2.x - 32, - minY: a2.y - 32, - maxX: a2.x + 32, - maxY: a2.y + 32 + minX: a2.x - width / 2, + minY: a2.y - height / 2, + maxX: a2.x + width / 2, + maxY: a2.y + height / 2 }; let draw = (ctx) => { ctx.globalAlpha = 1; - let r2 = this.sprites.get(this.name); - ctx.drawImage(r2.canvas, r2.x, r2.y, r2.w, r2.h, -8, -8, r2.w, r2.h); + ctx.drawImage(this.sheet.canvas, loc.x, loc.y, loc.w, loc.h, -loc.w / 2 / this.dpr, -loc.h / 2 / this.dpr, loc.w / 2, loc.h / 2); }; return [{ anchor: a2, bboxes: [bbox], draw }]; } }; var CircleSymbolizer = class { constructor(options) { - this.radius = options.radius || 3; - this.fill = options.fill || "black"; - this.stroke = options.stroke || "white"; - this.width = options.width || 0; + this.radius = new NumberAttr(options.radius, 3); + this.fill = new StringAttr(options.fill, "black"); + this.stroke = new StringAttr(options.stroke, "white"); + this.width = new NumberAttr(options.width, 0); + this.opacity = new NumberAttr(options.opacity); + } + draw(ctx, geom, z2, f2) { + ctx.globalAlpha = this.opacity.get(z2, f2); + let radius = this.radius.get(z2, f2); + let width = this.width.get(z2, f2); + if (width > 0) { + ctx.strokeStyle = this.stroke.get(z2, f2); + ctx.lineWidth = width; + ctx.beginPath(); + ctx.arc(geom[0][0].x, geom[0][0].y, radius + width / 2, 0, 2 * Math.PI); + ctx.stroke(); + } + ctx.fillStyle = this.fill.get(z2, f2); + ctx.beginPath(); + ctx.arc(geom[0][0].x, geom[0][0].y, radius, 0, 2 * Math.PI); + ctx.fill(); } place(layout, geom, feature) { let pt = geom[0]; - let a2 = new import_point_geometry4.default(geom[0][0].x, geom[0][0].y); + let a2 = new import_point_geometry6.default(geom[0][0].x, geom[0][0].y); + let radius = this.radius.get(layout.zoom, feature); let bbox = { - minX: a2.x - this.radius, - minY: a2.y - this.radius, - maxX: a2.x + this.radius, - maxY: a2.y + this.radius + minX: a2.x - radius, + minY: a2.y - radius, + maxX: a2.x + radius, + maxY: a2.y + radius }; let draw = (ctx) => { - ctx.globalAlpha = 1; - if (this.width > 0) { - ctx.fillStyle = this.stroke; - ctx.beginPath(); - ctx.arc(0, 0, this.radius + this.width, 0, 2 * Math.PI); - ctx.fill(); - } - ctx.fillStyle = this.fill; - ctx.beginPath(); - ctx.arc(0, 0, this.radius, 0, 2 * Math.PI); - ctx.fill(); + this.draw(ctx, [[new import_point_geometry6.default(0, 0)]], layout.zoom, feature); }; return [{ anchor: a2, bboxes: [bbox], draw }]; } }; var ShieldSymbolizer = class { constructor(options) { - this.font = new FontSpec(options); - this.text = new TextSpec(options); - this.fill = options.fill || "black"; - this.stroke = options.stroke || "white"; - this.background = options.background || "white"; - this.padding = options.padding || 0; + this.font = new FontAttr(options); + this.text = new TextAttr(options); + this.fill = new StringAttr(options.fill, "black"); + this.background = new StringAttr(options.background, "white"); + this.padding = new NumberAttr(options.padding, 0); } - place(layout, geom, feature) { - let property = this.text.str(layout.zoom, feature.properties); + place(layout, geom, f2) { + let property = this.text.get(layout.zoom, f2); if (!property) return void 0; - let font = this.font.str(layout.zoom, feature.properties); + let font = this.font.get(layout.zoom, f2); layout.scratch.font = font; let metrics = layout.scratch.measureText(property); let width = metrics.width; let ascent = metrics.actualBoundingBoxAscent; let descent = metrics.actualBoundingBoxDescent; let pt = geom[0]; - let a2 = new import_point_geometry4.default(geom[0][0].x, geom[0][0].y); - let p2 = this.padding; + let a2 = new import_point_geometry6.default(geom[0][0].x, geom[0][0].y); + let p2 = this.padding.get(layout.zoom, f2); let bbox = { minX: a2.x - width / 2 - p2, minY: a2.y - ascent - p2, @@ -3032,9 +4525,9 @@ var protomaps = (() => { }; let draw = (ctx) => { ctx.globalAlpha = 1; - ctx.fillStyle = this.background; + ctx.fillStyle = this.background.get(layout.zoom, f2); ctx.fillRect(-width / 2 - p2, -ascent - p2, width + 2 * p2, ascent + descent + 2 * p2); - ctx.fillStyle = this.fill; + ctx.fillStyle = this.fill.get(layout.zoom, f2); ctx.font = font; ctx.fillText(property, -width / 2, 0); }; @@ -3042,7 +4535,7 @@ var protomaps = (() => { } }; var FlexSymbolizer = class { - constructor(list, options) { + constructor(list) { this.list = list; } place(layout, geom, feature) { @@ -3054,7 +4547,7 @@ var protomaps = (() => { let bbox = label.bboxes[0]; let height = bbox.maxY - bbox.minY; let draws = [{ draw: label.draw, translate: { x: 0, y: 0 } }]; - let newGeom = [[{ x: geom[0][0].x, y: geom[0][0].y + height }]]; + let newGeom = [[new import_point_geometry6.default(geom[0][0].x, geom[0][0].y + height)]]; for (let i2 = 1; i2 < this.list.length; i2++) { labels = this.list[i2].place(layout, newGeom, feature); if (labels) { @@ -3111,308 +4604,378 @@ var protomaps = (() => { return [{ anchor, bboxes: [bbox], draw }]; } }; - var CenteredTextSymbolizer = class { - constructor(options) { - this.font = new FontSpec(options); - this.text = new TextSpec(options); - this.fill = options.fill; - this.stroke = options.stroke || "black"; - this.width = options.width || 0; + var CenteredSymbolizer = class { + constructor(symbolizer) { + this.symbolizer = symbolizer; } place(layout, geom, feature) { - if (feature.geomType !== GeomType.Point) + let a2 = geom[0][0]; + let placed = this.symbolizer.place(layout, [[new import_point_geometry6.default(0, 0)]], feature); + if (!placed || placed.length == 0) + return void 0; + let first_label = placed[0]; + let bbox = first_label.bboxes[0]; + let width = bbox.maxX - bbox.minX; + let height = bbox.maxY - bbox.minY; + let centered = { + minX: a2.x - width / 2, + maxX: a2.x + width / 2, + minY: a2.y - height / 2, + maxY: a2.y + height / 2 + }; + let draw = (ctx) => { + ctx.translate(-width / 2, height / 2 - bbox.maxY); + first_label.draw(ctx, { justify: 2 }); + }; + return [{ anchor: a2, bboxes: [centered], draw }]; + } + }; + var Padding = class { + constructor(padding, symbolizer) { + this.padding = new NumberAttr(padding, 0); + this.symbolizer = symbolizer; + } + place(layout, geom, feature) { + let placed = this.symbolizer.place(layout, geom, feature); + if (!placed || placed.length == 0) return void 0; - let property = this.text.str(layout.zoom, feature.properties); + let padding = this.padding.get(layout.zoom, feature); + for (var label of placed) { + for (var bbox of label.bboxes) { + bbox.minX -= padding; + bbox.minY -= padding; + bbox.maxX += padding; + bbox.maxY += padding; + } + } + return placed; + } + }; + var TextSymbolizer = class { + constructor(options) { + this.font = new FontAttr(options); + this.text = new TextAttr(options); + this.fill = new StringAttr(options.fill, "black"); + this.stroke = new StringAttr(options.stroke, "black"); + this.width = new NumberAttr(options.width, 0); + this.lineHeight = new NumberAttr(options.lineHeight, 1); + this.letterSpacing = new NumberAttr(options.letterSpacing, 0); + this.maxLineCodeUnits = new NumberAttr(options.maxLineChars, 15); + this.justify = options.justify; + } + place(layout, geom, feature) { + let property = this.text.get(layout.zoom, feature); if (!property) return void 0; - let font = this.font.str(layout.zoom, feature.properties); + let font = this.font.get(layout.zoom, feature); layout.scratch.font = font; - let metrics = layout.scratch.measureText(property); - let width = metrics.width; + let letterSpacing = this.letterSpacing.get(layout.zoom, feature); + let lines = linebreak(property, this.maxLineCodeUnits.get(layout.zoom, feature)); + var longestLine = ""; + var longestLineLen = 0; + for (let line of lines) { + if (line.length > longestLineLen) { + longestLineLen = line.length; + longestLine = line; + } + } + let metrics = layout.scratch.measureText(longestLine); + let width = metrics.width + letterSpacing * (longestLineLen - 1); let ascent = metrics.actualBoundingBoxAscent; let descent = metrics.actualBoundingBoxDescent; - let a2 = new import_point_geometry4.default(geom[0][0].x, geom[0][0].y); + let lineHeight = (ascent + descent) * this.lineHeight.get(layout.zoom, feature); + let a2 = new import_point_geometry6.default(geom[0][0].x, geom[0][0].y); let bbox = { - minX: a2.x - width / 2, + minX: a2.x, minY: a2.y - ascent, - maxX: a2.x + width / 2, - maxY: a2.y + descent + maxX: a2.x + width, + maxY: a2.y + descent + (lines.length - 1) * lineHeight }; - let textX = -width / 2; - let draw = (ctx) => { + let draw = (ctx, extra) => { ctx.globalAlpha = 1; ctx.font = font; - if (this.width) { - ctx.lineWidth = this.width * 2; - ctx.strokeStyle = this.stroke; - ctx.strokeText(property, textX, 0); + ctx.fillStyle = this.fill.get(layout.zoom, feature); + let textStrokeWidth = this.width.get(layout.zoom, feature); + var y = 0; + for (let line of lines) { + var startX = 0; + if (this.justify == 2 || extra && extra.justify == 2) { + startX = (width - ctx.measureText(line).width) / 2; + } else if (this.justify == 3 || extra && extra.justify == 3) { + startX = width - ctx.measureText(line).width; + } + if (textStrokeWidth) { + ctx.lineWidth = textStrokeWidth * 2; + ctx.strokeStyle = this.stroke.get(layout.zoom, feature); + if (letterSpacing > 0) { + var xPos = startX; + for (var letter of line) { + ctx.strokeText(letter, xPos, y); + xPos += ctx.measureText(letter).width + letterSpacing; + } + } else { + ctx.strokeText(line, startX, y); + } + } + if (letterSpacing > 0) { + var xPos = startX; + for (var letter of line) { + ctx.fillText(letter, xPos, y); + xPos += ctx.measureText(letter).width + letterSpacing; + } + } else { + ctx.fillText(line, startX, y); + } + y += lineHeight; } - ctx.fillStyle = this.fill; - ctx.fillText(property, textX, 0); }; return [{ anchor: a2, bboxes: [bbox], draw }]; } }; - var OffsetTextSymbolizer = class { + var CenteredTextSymbolizer = class { constructor(options) { - this.font = new FontSpec(options); - this.text = new TextSpec(options); - this.fill = options.fill; - this.stroke = options.stroke || "black"; - this.width = options.width || 0; - this.offset = options.offset || 0; + this.centered = new CenteredSymbolizer(new TextSymbolizer(options)); + } + place(layout, geom, feature) { + return this.centered.place(layout, geom, feature); + } + }; + var OffsetSymbolizer = class { + constructor(symbolizer, options) { + var _a2, _b2, _c; + this.symbolizer = symbolizer; + this.offsetX = new NumberAttr(options.offsetX, 0); + this.offsetY = new NumberAttr(options.offsetY, 0); + this.justify = (_a2 = options.justify) != null ? _a2 : void 0; + this.placements = (_b2 = options.placements) != null ? _b2 : [ + 2, + 6, + 8, + 4, + 1, + 3, + 5, + 7 + ]; + this.ddValues = (_c = options.ddValues) != null ? _c : () => { + return {}; + }; } place(layout, geom, feature) { if (feature.geomType !== GeomType.Point) return void 0; - let property = this.text.str(layout.zoom, feature.properties); - if (!property) + let anchor = geom[0][0]; + let placed = this.symbolizer.place(layout, [[new import_point_geometry6.default(0, 0)]], feature); + if (!placed || placed.length == 0) return void 0; - let font = this.font.str(layout.zoom, feature.properties); - layout.scratch.font = font; - let metrics = layout.scratch.measureText(property); - let width = metrics.width; - let ascent = metrics.actualBoundingBoxAscent; - let descent = metrics.actualBoundingBoxDescent; - let a2 = new import_point_geometry4.default(geom[0][0].x, geom[0][0].y); - let offset = this.offset; - var text_origin = new import_point_geometry4.default(offset, -offset); - let draw = (ctx) => { - ctx.globalAlpha = 1; - ctx.font = font; - if (this.width) { - ctx.lineWidth = this.width * 2; - ctx.strokeStyle = this.stroke; - ctx.strokeText(property, text_origin.x, text_origin.y); - } - ctx.fillStyle = this.fill; - ctx.fillText(property, text_origin.x, text_origin.y); + let first_label = placed[0]; + let fb = first_label.bboxes[0]; + let offsetXValue = this.offsetX; + let offsetYValue = this.offsetY; + let justifyValue = this.justify; + let placements = this.placements; + const { + offsetX: ddOffsetX, + offsetY: ddOffsetY, + justify: ddJustify, + placements: ddPlacements + } = this.ddValues(layout.zoom, feature) || {}; + if (ddOffsetX) + offsetXValue = new NumberAttr(ddOffsetX, 0); + if (ddOffsetY) + offsetYValue = new NumberAttr(ddOffsetY, 0); + if (ddJustify) + justifyValue = ddJustify; + if (ddPlacements) + placements = ddPlacements; + const offsetX = offsetXValue.get(layout.zoom, feature); + const offsetY = offsetYValue.get(layout.zoom, feature); + let getBbox = (a2, o2) => { + return { + minX: a2.x + o2.x + fb.minX, + minY: a2.y + o2.y + fb.minY, + maxX: a2.x + o2.x + fb.maxX, + maxY: a2.y + o2.y + fb.maxY + }; }; - var bbox = { - minX: a2.x + text_origin.x, - minY: a2.y - ascent + text_origin.y, - maxX: a2.x + width + text_origin.x, - maxY: a2.y + descent + text_origin.y + var origin = new import_point_geometry6.default(offsetX, offsetY); + var justify; + let draw = (ctx) => { + ctx.translate(origin.x, origin.y); + first_label.draw(ctx, { justify }); }; - if (!layout.index.bboxCollides(bbox, layout.order)) - return [{ anchor: a2, bboxes: [bbox], draw }]; - text_origin = new import_point_geometry4.default(-width - offset, -offset); - bbox = { - minX: a2.x + text_origin.x, - minY: a2.y - ascent + text_origin.y, - maxX: a2.x + width + text_origin.x, - maxY: a2.y + descent + text_origin.y + const placeLabelInPoint = (a2, o2) => { + const bbox = getBbox(a2, o2); + if (!layout.index.bboxCollides(bbox, layout.order)) + return [{ anchor, bboxes: [bbox], draw }]; }; - if (!layout.index.bboxCollides(bbox, layout.order)) - return [{ anchor: a2, bboxes: [bbox], draw }]; + for (let placement of placements) { + const xAxisOffset = this.computeXAxisOffset(offsetX, fb, placement); + const yAxisOffset = this.computeYAxisOffset(offsetY, fb, placement); + justify = this.computeJustify(justifyValue, placement); + origin = new import_point_geometry6.default(xAxisOffset, yAxisOffset); + return placeLabelInPoint(anchor, origin); + } return void 0; } + computeXAxisOffset(offsetX, fb, placement) { + const labelWidth = fb.maxX; + const labelHalfWidth = labelWidth / 2; + if ([1, 5].includes(placement)) + return offsetX - labelHalfWidth; + if ([8, 7, 6].includes(placement)) + return offsetX - labelWidth; + return offsetX; + } + computeYAxisOffset(offsetY, fb, placement) { + const labelHalfHeight = Math.abs(fb.minY); + const labelBottom = fb.maxY; + const labelCenterHeight = (fb.minY + fb.maxY) / 2; + if ([3, 7].includes(placement)) + return offsetY - labelCenterHeight; + if ([8, 2, 1].includes(placement)) + return offsetY - labelBottom; + if ([6, 4, 5].includes(placement)) + return offsetY + labelHalfHeight; + return offsetY; + } + computeJustify(fixedJustify, placement) { + if (fixedJustify) + return fixedJustify; + if ([1, 5].includes(placement)) + return 2; + if ([2, 3, 4].includes(placement)) + return 1; + return 3; + } + }; + var OffsetTextSymbolizer = class { + constructor(options) { + this.symbolizer = new OffsetSymbolizer(new TextSymbolizer(options), options); + } + place(layout, geom, feature) { + return this.symbolizer.place(layout, geom, feature); + } }; + var LineLabelPlacement; + (function(LineLabelPlacement2) { + LineLabelPlacement2[LineLabelPlacement2["Above"] = 1] = "Above"; + LineLabelPlacement2[LineLabelPlacement2["Center"] = 2] = "Center"; + LineLabelPlacement2[LineLabelPlacement2["Below"] = 3] = "Below"; + })(LineLabelPlacement || (LineLabelPlacement = {})); var LineLabelSymbolizer = class { constructor(options) { - this.font = new FontSpec(options); - this.text = new TextSpec(options); - this.fill = options.fill || "black"; - this.stroke = options.stroke || "black"; - this.width = options.width || 0; - this.offset = options.offset || 0; + var _a2; + this.font = new FontAttr(options); + this.text = new TextAttr(options); + this.fill = new StringAttr(options.fill, "black"); + this.stroke = new StringAttr(options.stroke, "black"); + this.width = new NumberAttr(options.width, 0); + this.offset = new NumberAttr(options.offset, 0); + this.position = (_a2 = options.position) != null ? _a2 : 1; + this.maxLabelCodeUnits = new NumberAttr(options.maxLabelChars, 40); + this.repeatDistance = new NumberAttr(options.repeatDistance, 250); } place(layout, geom, feature) { - let name = this.text.str(layout.zoom, feature.properties); + let name = this.text.get(layout.zoom, feature); if (!name) return void 0; - if (name.length > 20) + if (name.length > this.maxLabelCodeUnits.get(layout.zoom, feature)) return void 0; + let MIN_LABELABLE_DIM = 20; let fbbox = feature.bbox; - let area = (fbbox.maxY - fbbox.minY) * (fbbox.maxX - fbbox.minX); - if (area < 400) + if (fbbox.maxY - fbbox.minY < MIN_LABELABLE_DIM && fbbox.maxX - fbbox.minX < MIN_LABELABLE_DIM) return void 0; - let font = this.font.str(layout.zoom, feature.properties); + let font = this.font.get(layout.zoom, feature); layout.scratch.font = font; let metrics = layout.scratch.measureText(name); let width = metrics.width; - let result = simpleLabel(geom, width); - if (!result) + let height = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent; + var repeatDistance = this.repeatDistance.get(layout.zoom, feature); + if (layout.overzoom > 4) + repeatDistance *= 1 << layout.overzoom - 4; + let cell_size = height * 2; + let label_candidates = simpleLabel(geom, width, repeatDistance, cell_size); + if (label_candidates.length == 0) return void 0; - let dx = result.end.x - result.start.x; - let dy = result.end.y - result.start.y; - let Q = 8; - let cells = lineCells(result.start, result.end, width, 8); - let bboxes = cells.map((c2) => { - return { - minX: c2.x - Q, - minY: c2.y - Q, - maxX: c2.x + Q, - maxY: c2.y + Q + let labels = []; + for (let candidate of label_candidates) { + let dx = candidate.end.x - candidate.start.x; + let dy = candidate.end.y - candidate.start.y; + let cells = lineCells(candidate.start, candidate.end, width, cell_size / 2); + let bboxes = cells.map((c2) => { + return { + minX: c2.x - cell_size / 2, + minY: c2.y - cell_size / 2, + maxX: c2.x + cell_size / 2, + maxY: c2.y + cell_size / 2 + }; + }); + let draw = (ctx) => { + ctx.globalAlpha = 1; + ctx.rotate(Math.atan2(dy, dx)); + if (dx < 0) { + ctx.scale(-1, -1); + ctx.translate(-width, 0); + } + let heightPlacement = 0; + if (this.position === 3) + heightPlacement += height; + else if (this.position === 2) + heightPlacement += height / 2; + ctx.translate(0, heightPlacement - this.offset.get(layout.zoom, feature)); + ctx.font = font; + let lineWidth = this.width.get(layout.zoom, feature); + if (lineWidth) { + ctx.lineWidth = lineWidth; + ctx.strokeStyle = this.stroke.get(layout.zoom, feature); + ctx.strokeText(name, 0, 0); + } + ctx.fillStyle = this.fill.get(layout.zoom, feature); + ctx.fillText(name, 0, 0); }; - }); - let draw = (ctx) => { - ctx.globalAlpha = 1; - ctx.rotate(Math.atan2(dy, dx)); - if (dx < 0) { - ctx.scale(-1, -1); - ctx.translate(-width, 0); - } - ctx.translate(0, -this.offset); - ctx.font = font; - if (this.width) { - ctx.lineWidth = this.width; - ctx.strokeStyle = this.stroke; - ctx.strokeText(name, 0, 0); - } - ctx.fillStyle = this.fill; - ctx.fillText(name, 0, 0); - }; - return [{ anchor: result.start, bboxes, draw }]; + labels.push({ + anchor: candidate.start, + bboxes, + draw, + deduplicationKey: name, + deduplicationDistance: repeatDistance + }); + } + return labels; } }; var PolygonLabelSymbolizer = class { constructor(options) { - this.font = new FontSpec(options); - this.text = new TextSpec(options); - this.fill = options.fill || "black"; - this.stroke = options.stroke || "black"; - this.width = options.width || 0; + this.symbolizer = new TextSymbolizer(options); } place(layout, geom, feature) { let fbbox = feature.bbox; let area = (fbbox.maxY - fbbox.minY) * (fbbox.maxX - fbbox.minX); if (area < 2e4) return void 0; - let property = this.text.str(layout.zoom, feature.properties); - if (!property) + let placed = this.symbolizer.place(layout, [[new import_point_geometry6.default(0, 0)]], feature); + if (!placed || placed.length == 0) return void 0; + let first_label = placed[0]; + let fb = first_label.bboxes[0]; let first_poly = geom[0]; let found = (0, import_polylabel.default)([first_poly.map((c2) => [c2.x, c2.y])]); - let a2 = new import_point_geometry4.default(found[0], found[1]); - let font = this.font.str(layout.zoom, feature.properties); - layout.scratch.font = font; - let lines = linebreak(property); - let lineHeight = 14; - var longestLine; - var longestLineLen = 0; - for (let line of lines) { - if (line.length > longestLineLen) { - longestLineLen = line.length; - longestLine = line; - } - } - let metrics = layout.scratch.measureText(longestLine); - let width = metrics.width; + let a2 = new import_point_geometry6.default(found[0], found[1]); let bbox = { - minX: a2.x - width / 2, - minY: a2.y - metrics.actualBoundingBoxAscent, - maxX: a2.x + width / 2, - maxY: a2.y + (lineHeight * lines.length - metrics.actualBoundingBoxAscent) + minX: a2.x - (fb.maxX - fb.minX) / 2, + minY: a2.y - (fb.maxY - fb.minY) / 2, + maxX: a2.x + (fb.maxX - fb.minX) / 2, + maxY: a2.y + (fb.maxY - fb.minY) / 2 }; - let fill = this.fill; let draw = (ctx) => { - ctx.globalAlpha = 1; - ctx.font = font; - var y = 0; - for (let line of lines) { - if (this.width) { - ctx.lineWidth = this.width; - ctx.strokeStyle = this.stroke; - ctx.strokeText(line, -width / 2, y); - } - ctx.fillStyle = fill; - ctx.fillText(line, -width / 2, y); - y += lineHeight; - } + ctx.translate(first_label.anchor.x - (fb.maxX - fb.minX) / 2, first_label.anchor.y); + first_label.draw(ctx); }; return [{ anchor: a2, bboxes: [bbox], draw }]; } }; - // node_modules/color2k/dist/index.module.js - function t(t2, n2, r2) { - return Math.min(Math.max(t2, r2), n2); - } - var n = class extends Error { - constructor(t2) { - super(`Failed to parse color: "${t2}"`); - } - }; - function r(r2) { - if (typeof r2 != "string") - throw new n(r2); - if (r2.trim().toLowerCase() === "transparent") - return [0, 0, 0, 0]; - let e2 = r2.trim(); - e2 = u.test(r2) ? function(t2) { - const r3 = t2.toLowerCase().trim(), e3 = o[function(t3) { - let n2 = 5381, r4 = t3.length; - for (; r4; ) - n2 = 33 * n2 ^ t3.charCodeAt(--r4); - return (n2 >>> 0) % 2341; - }(r3)]; - if (!e3) - throw new n(t2); - return `#${e3}`; - }(r2) : r2; - const f2 = s.exec(e2); - if (f2) { - const t2 = Array.from(f2).slice(1); - return [...t2.slice(0, 3).map((t3) => parseInt(_(t3, 2), 16)), parseInt(_(t2[3] || "f", 2), 16) / 255]; - } - const p2 = i.exec(e2); - if (p2) { - const t2 = Array.from(p2).slice(1); - return [...t2.slice(0, 3).map((t3) => parseInt(t3, 16)), parseInt(t2[3] || "ff", 16) / 255]; - } - const z2 = a.exec(e2); - if (z2) { - const t2 = Array.from(z2).slice(1); - return [...t2.slice(0, 3).map((t3) => parseInt(t3, 10)), parseFloat(t2[3] || "1")]; - } - const h = c.exec(e2); - if (h) { - const [e3, o2, _2, s2] = Array.from(h).slice(1).map(parseFloat); - if (t(0, 100, o2) !== o2) - throw new n(r2); - if (t(0, 100, _2) !== _2) - throw new n(r2); - return [...l(e3, o2, _2), s2 || 1]; - } - throw new n(r2); - } - var e = (t2) => parseInt(t2.replace(/_/g, ""), 36); - var o = "1q29ehhb 1n09sgk7 1kl1ekf_ _yl4zsno 16z9eiv3 1p29lhp8 _bd9zg04 17u0____ _iw9zhe5 _to73___ _r45e31e _7l6g016 _jh8ouiv _zn3qba8 1jy4zshs 11u87k0u 1ro9yvyo 1aj3xael 1gz9zjz0 _3w8l4xo 1bf1ekf_ _ke3v___ _4rrkb__ 13j776yz _646mbhl _nrjr4__ _le6mbhl 1n37ehkb _m75f91n _qj3bzfz 1939yygw 11i5z6x8 _1k5f8xs 1509441m 15t5lwgf _ae2th1n _tg1ugcv 1lp1ugcv 16e14up_ _h55rw7n _ny9yavn _7a11xb_ 1ih442g9 _pv442g9 1mv16xof 14e6y7tu 1oo9zkds 17d1cisi _4v9y70f _y98m8kc 1019pq0v 12o9zda8 _348j4f4 1et50i2o _8epa8__ _ts6senj 1o350i2o 1mi9eiuo 1259yrp0 1ln80gnw _632xcoy 1cn9zldc _f29edu4 1n490c8q _9f9ziet 1b94vk74 _m49zkct 1kz6s73a 1eu9dtog _q58s1rz 1dy9sjiq __u89jo3 _aj5nkwg _ld89jo3 13h9z6wx _qa9z2ii _l119xgq _bs5arju 1hj4nwk9 1qt4nwk9 1ge6wau6 14j9zlcw 11p1edc_ _ms1zcxe _439shk6 _jt9y70f _754zsow 1la40eju _oq5p___ _x279qkz 1fa5r3rv _yd2d9ip _424tcku _8y1di2_ _zi2uabw _yy7rn9h 12yz980_ __39ljp6 1b59zg0x _n39zfzp 1fy9zest _b33k___ _hp9wq92 1il50hz4 _io472ub _lj9z3eo 19z9ykg0 _8t8iu3a 12b9bl4a 1ak5yw0o _896v4ku _tb8k8lv _s59zi6t _c09ze0p 1lg80oqn 1id9z8wb _238nba5 1kq6wgdi _154zssg _tn3zk49 _da9y6tc 1sg7cv4f _r12jvtt 1gq5fmkz 1cs9rvci _lp9jn1c _xw1tdnb 13f9zje6 16f6973h _vo7ir40 _bt5arjf _rc45e4t _hr4e100 10v4e100 _hc9zke2 _w91egv_ _sj2r1kk 13c87yx8 _vqpds__ _ni8ggk8 _tj9yqfb 1ia2j4r4 _7x9b10u 1fc9ld4j 1eq9zldr _5j9lhpx _ez9zl6o _md61fzm".split(" ").reduce((t2, n2) => { - const r2 = e(n2.substring(0, 3)), o2 = e(n2.substring(3)).toString(16); - let _2 = ""; - for (let t3 = 0; t3 < 6 - o2.length; t3++) - _2 += "0"; - return t2[r2] = `${_2}${o2}`, t2; - }, {}); - var _ = (t2, n2) => Array.from(Array(n2)).map(() => t2).join(""); - var s = new RegExp(`^#${_("([a-f0-9])", 3)}([a-f0-9])?$`, "i"); - var i = new RegExp(`^#${_("([a-f0-9]{2})", 3)}([a-f0-9]{2})?$`, "i"); - var a = new RegExp(`^rgba?\\(\\s*(\\d+)\\s*${_(",\\s*(\\d+)\\s*", 2)}(?:,\\s*([\\d.]+))?\\s*\\)$`, "i"); - var c = /^hsla?\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%(?:\s*,\s*([\d.]+))?\s*\)$/i; - var u = /^[a-z]+$/i; - var f = (t2) => Math.round(255 * t2); - var l = (t2, n2, r2) => { - let e2 = r2 / 100; - if (n2 === 0) - return [e2, e2, e2].map(f); - const o2 = (t2 % 360 + 360) % 360 / 60, _2 = (1 - Math.abs(2 * e2 - 1)) * (n2 / 100), s2 = _2 * (1 - Math.abs(o2 % 2 - 1)); - let i2 = 0, a2 = 0, c2 = 0; - o2 >= 0 && o2 < 1 ? (i2 = _2, a2 = s2) : o2 >= 1 && o2 < 2 ? (i2 = s2, a2 = _2) : o2 >= 2 && o2 < 3 ? (a2 = _2, c2 = s2) : o2 >= 3 && o2 < 4 ? (a2 = s2, c2 = _2) : o2 >= 4 && o2 < 5 ? (i2 = s2, c2 = _2) : o2 >= 5 && o2 < 6 && (i2 = _2, c2 = s2); - const u2 = e2 - _2 / 2; - return [i2 + u2, a2 + u2, c2 + u2].map(f); - }; - function p(t2) { - const [n2, e2, o2, _2] = r(t2).map((t3, n3) => n3 === 3 ? t3 : t3 / 255), s2 = Math.max(n2, e2, o2), i2 = Math.min(n2, e2, o2), a2 = (s2 + i2) / 2; - if (s2 === i2) - return [0, 0, a2, _2]; - const c2 = s2 - i2; - return [60 * (n2 === s2 ? (e2 - o2) / c2 + (e2 < o2 ? 6 : 0) : e2 === s2 ? (o2 - n2) / c2 + 2 : (n2 - e2) / c2 + 4), a2 > 0.5 ? c2 / (2 - s2 - i2) : c2 / (s2 + i2), a2, _2]; - } - function z(n2, r2, e2, o2) { - return `hsla(${(n2 % 360).toFixed()}, ${t(0, 100, 100 * r2).toFixed()}%, ${t(0, 100, 100 * e2).toFixed()}%, ${parseFloat(t(0, 1, o2).toFixed(3))})`; - } - // src/default_style/style.ts var doShading = (params, shade) => { let shadeHsl = p(shade); @@ -3438,8 +5001,8 @@ var protomaps = (() => { symbolizer: new PolygonSymbolizer({ fill: params.glacier }), - filter: (f2) => { - return f2.natural == "glacier"; + filter: (z2, f2) => { + return f2.props.natural == "glacier"; } }, { @@ -3447,8 +5010,8 @@ var protomaps = (() => { symbolizer: new PolygonSymbolizer({ fill: params.residential }), - filter: (f2) => { - return f2.landuse == "residential" || f2.place == "neighbourhood"; + filter: (z2, f2) => { + return f2.props.landuse == "residential" || f2.props.place == "neighbourhood"; } }, { @@ -3456,8 +5019,8 @@ var protomaps = (() => { symbolizer: new PolygonSymbolizer({ fill: params.hospital }), - filter: (f2) => { - return f2.amenity == "hospital"; + filter: (z2, f2) => { + return f2.props.amenity == "hospital"; } }, { @@ -3465,8 +5028,8 @@ var protomaps = (() => { symbolizer: new PolygonSymbolizer({ fill: params.cemetery }), - filter: (f2) => { - return f2.landuse == "cemetery"; + filter: (z2, f2) => { + return f2.props.landuse == "cemetery"; } }, { @@ -3474,8 +5037,8 @@ var protomaps = (() => { symbolizer: new PolygonSymbolizer({ fill: params.school }), - filter: (f2) => { - return f2.amenity == "school" || f2.amenity == "kindergarten" || f2.amenity == "university" || f2.amenity == "college"; + filter: (z2, f2) => { + return f2.props.amenity == "school" || f2.props.amenity == "kindergarten" || f2.props.amenity == "university" || f2.props.amenity == "college"; } }, { @@ -3483,8 +5046,8 @@ var protomaps = (() => { symbolizer: new PolygonSymbolizer({ fill: params.industrial }), - filter: (f2) => { - return f2.landuse == "industrial"; + filter: (z2, f2) => { + return f2.props.landuse == "industrial"; } }, { @@ -3492,8 +5055,8 @@ var protomaps = (() => { symbolizer: new PolygonSymbolizer({ fill: params.wood }), - filter: (f2) => { - return f2.natural == "wood"; + filter: (z2, f2) => { + return f2.props.natural == "wood"; } }, { @@ -3501,8 +5064,8 @@ var protomaps = (() => { symbolizer: new PolygonSymbolizer({ fill: params.grass }), - filter: (f2) => { - return f2.landuse == "grass"; + filter: (z2, f2) => { + return f2.props.landuse == "grass"; } }, { @@ -3510,8 +5073,8 @@ var protomaps = (() => { symbolizer: new PolygonSymbolizer({ fill: params.park }), - filter: (f2) => { - return f2.leisure == "park"; + filter: (z2, f2) => { + return f2.props.leisure == "park"; } }, { @@ -3525,8 +5088,8 @@ var protomaps = (() => { symbolizer: new PolygonSymbolizer({ fill: params.sand }), - filter: (f2) => { - return f2.natural == "sand"; + filter: (z2, f2) => { + return f2.props.natural == "sand"; } }, { @@ -3539,80 +5102,116 @@ var protomaps = (() => { dataLayer: "roads", symbolizer: new LineSymbolizer({ color: params.highwayCasing, - width: exp(1.4, [[5, 1.5], [11, 4], [16, 9], [20, 40]]) + width: exp(1.4, [ + [5, 1.5], + [11, 4], + [16, 9], + [20, 40] + ]) }), - filter: (f2) => { - return f2["pmap:kind"] == "highway"; + filter: (z2, f2) => { + return f2.props["pmap:kind"] == "highway"; } }, { dataLayer: "roads", symbolizer: new LineSymbolizer({ color: params.majorRoadCasing, - width: exp(1.4, [[9, 3], [12, 4], [17, 8], [20, 22]]) + width: exp(1.4, [ + [9, 3], + [12, 4], + [17, 8], + [20, 22] + ]) }), - filter: (f2) => { - return f2["pmap:kind"] == "major_road"; + filter: (z2, f2) => { + return f2.props["pmap:kind"] == "major_road"; } }, { dataLayer: "roads", symbolizer: new LineSymbolizer({ color: params.mediumRoadCasing, - width: exp(1.4, [[13, 3], [17, 6], [20, 18]]) + width: exp(1.4, [ + [13, 3], + [17, 6], + [20, 18] + ]) }), - filter: (f2) => { - return f2["pmap:kind"] == "medium_road"; + filter: (z2, f2) => { + return f2.props["pmap:kind"] == "medium_road"; } }, { dataLayer: "roads", symbolizer: new LineSymbolizer({ color: params.minorRoadCasing, - width: exp(1.4, [[14, 2], [17, 5], [20, 15]]) + width: exp(1.4, [ + [14, 2], + [17, 5], + [20, 15] + ]) }), - filter: (f2) => { - return f2["pmap:kind"] == "minor_road"; + filter: (z2, f2) => { + return f2.props["pmap:kind"] == "minor_road"; } }, { dataLayer: "roads", symbolizer: new LineSymbolizer({ color: params.minorRoad, - width: exp(1.4, [[14, 1], [17, 3], [20, 13]]) + width: exp(1.4, [ + [14, 1], + [17, 3], + [20, 13] + ]) }), - filter: (f2) => { - return f2["pmap:kind"] == "minor_road"; + filter: (z2, f2) => { + return f2.props["pmap:kind"] == "minor_road"; } }, { dataLayer: "roads", symbolizer: new LineSymbolizer({ color: params.mediumRoad, - width: exp(1.4, [[13, 2], [17, 4], [20, 15]]) + width: exp(1.4, [ + [13, 2], + [17, 4], + [20, 15] + ]) }), - filter: (f2) => { - return f2["pmap:kind"] == "medium_road"; + filter: (z2, f2) => { + return f2.props["pmap:kind"] == "medium_road"; } }, { dataLayer: "roads", symbolizer: new LineSymbolizer({ color: params.majorRoad, - width: exp(1.4, [[9, 2], [12, 3], [17, 6], [20, 20]]) + width: exp(1.4, [ + [9, 2], + [12, 3], + [17, 6], + [20, 20] + ]) }), - filter: (f2) => { - return f2["pmap:kind"] == "major_road"; + filter: (z2, f2) => { + return f2.props["pmap:kind"] == "major_road"; } }, { dataLayer: "roads", symbolizer: new LineSymbolizer({ color: params.highway, - width: exp(1.4, [[5, 0.5], [11, 2.5], [16, 7], [20, 30]]) + width: exp(1.4, [ + [5, 0.5], + [11, 2.5], + [16, 7], + [20, 30] + ]) }), - filter: (f2) => { - return f2["pmap:kind"] == "highway"; + filter: (z2, f2) => { + return f2.props["pmap:kind"] == "highway"; } }, { @@ -3645,59 +5244,60 @@ var protomaps = (() => { symbolizer, new OffsetTextSymbolizer({ fill, - properties: language2 + label_props: language2 }) - ], {}); + ]); } else { return new FlexSymbolizer([ symbolizer, new CenteredTextSymbolizer({ fill, - properties: language2 + label_props: language2 }) - ], {}); + ]); } }; return [ { dataLayer: "places", symbolizer: languageStack(new CenteredTextSymbolizer({ - properties: nametags, + label_props: nametags, fill: params.countryLabel, - font: (z2, p2) => { + lineHeight: 1.5, + font: (z2, f2) => { if (z2 < 6) return "200 14px sans-serif"; return "200 20px sans-serif"; }, textTransform: "uppercase" }), params.countryLabel), - filter: (f2) => { - return f2["pmap:kind"] == "country"; + filter: (z2, f2) => { + return f2.props["pmap:kind"] == "country"; } }, { dataLayer: "places", symbolizer: languageStack(new CenteredTextSymbolizer({ - properties: nametags, + label_props: nametags, fill: params.stateLabel, font: "300 16px sans-serif" }), params.stateLabel), - filter: (f2) => { - return f2["pmap:kind"] == "state"; + filter: (z2, f2) => { + return f2.props["pmap:kind"] == "state"; } }, { id: "cities_high", dataLayer: "places", - filter: (f2) => { - return f2["pmap:kind"] == "city"; + filter: (z2, f2) => { + return f2.props["pmap:kind"] == "city"; }, minzoom: 7, symbolizer: languageStack(new CenteredTextSymbolizer({ - properties: nametags, + label_props: nametags, fill: params.cityLabel, - font: (z2, p2) => { - if (p2["pmap:rank"] == 1) { + font: (z2, f2) => { + if ((f2 == null ? void 0 : f2.props["pmap:rank"]) === 1) { if (z2 > 8) return "600 20px sans-serif"; return "600 12px sans-serif"; @@ -3715,8 +5315,8 @@ var protomaps = (() => { { id: "cities_low", dataLayer: "places", - filter: (f2) => { - return f2["pmap:kind"] == "city"; + filter: (z2, f2) => { + return f2.props["pmap:kind"] == "city"; }, maxzoom: 6, symbolizer: new GroupSymbolizer([ @@ -3725,11 +5325,12 @@ var protomaps = (() => { fill: params.cityLabel }), languageStack(new OffsetTextSymbolizer({ - properties: nametags, + label_props: nametags, fill: params.cityLabel, - offset: 2, - font: (z2, p2) => { - if (p2["pmap:rank"] == 1) { + offsetX: 2, + offsetY: 2, + font: (z2, f2) => { + if ((f2 == null ? void 0 : f2.props["pmap:rank"]) === 1) { if (z2 > 8) return "600 20px sans-serif"; return "600 12px sans-serif"; @@ -3749,19 +5350,19 @@ var protomaps = (() => { id: "neighbourhood", dataLayer: "places", symbolizer: languageStack(new CenteredTextSymbolizer({ - properties: nametags, + label_props: nametags, fill: params.neighbourhoodLabel, font: "500 10px sans-serif", textTransform: "uppercase" }), params.neighbourhoodLabel), - filter: (f2) => { - return f2["pmap:kind"] == "neighbourhood"; + filter: (z2, f2) => { + return f2.props["pmap:kind"] == "neighbourhood"; } }, { dataLayer: "landuse", symbolizer: languageStack(new PolygonLabelSymbolizer({ - properties: nametags, + label_props: nametags, fill: params.landuseLabel, font: "300 12px sans-serif" }), params.landuseLabel) @@ -3769,7 +5370,7 @@ var protomaps = (() => { { dataLayer: "water", symbolizer: languageStack(new PolygonLabelSymbolizer({ - properties: nametags, + label_props: nametags, fill: params.waterLabel, font: "italic 600 12px sans-serif" }), params.waterLabel) @@ -3777,7 +5378,7 @@ var protomaps = (() => { { dataLayer: "natural", symbolizer: languageStack(new PolygonLabelSymbolizer({ - properties: nametags, + label_props: nametags, fill: params.naturalLabel, font: "italic 300 12px sans-serif" }), params.naturalLabel) @@ -3785,7 +5386,7 @@ var protomaps = (() => { { dataLayer: "roads", symbolizer: languageStack(new LineLabelSymbolizer({ - properties: nametags, + label_props: nametags, fill: params.roadsLabel, font: "500 12px sans-serif" }), params.roadsLabel), @@ -3794,14 +5395,14 @@ var protomaps = (() => { { dataLayer: "roads", symbolizer: new ShieldSymbolizer({ - properties: ["ref"], + label_props: ["ref"], font: "600 9px sans-serif", background: params.highway, padding: 2, fill: params.neighbourhoodLabel }), - filter: (f2) => { - return f2["pmap:kind"] == "highway"; + filter: (z2, f2) => { + return f2.props["pmap:kind"] == "highway"; } }, { @@ -3812,9 +5413,10 @@ var protomaps = (() => { fill: params.poisLabel }), languageStack(new OffsetTextSymbolizer({ - properties: nametags, + label_props: nametags, fill: params.poisLabel, - offset: 2, + offsetX: 2, + offsetY: 2, font: "300 10px sans-serif" }), params.poisLabel) ]) @@ -3822,56 +5424,174 @@ var protomaps = (() => { ]; }; + // src/xray.ts + var xray_symbolizers = (dataSource, dataLayer, color) => { + return [ + { + dataSource, + dataLayer, + symbolizer: new CircleSymbolizer({ + opacity: 0.2, + fill: color, + radius: 4 + }), + filter: (z2, f2) => { + return f2.geomType == GeomType.Point; + } + }, + { + dataSource, + dataLayer, + symbolizer: new LineSymbolizer({ + opacity: 0.2, + color, + width: 2 + }), + filter: (z2, f2) => { + return f2.geomType == GeomType.Line; + } + }, + { + dataSource, + dataLayer, + symbolizer: new PolygonSymbolizer({ + opacity: 0.2, + fill: color, + stroke: color, + width: 1 + }), + filter: (z2, f2) => { + return f2.geomType == GeomType.Polygon; + } + } + ]; + }; + var xray_rules = (prepared_tilemap, xray) => { + var rules = []; + for (var [dataSource, tiles] of prepared_tilemap) { + for (var tile of tiles) { + for (var dataLayer of tile.data.keys()) { + if (dataSource === xray.dataSource && dataLayer === xray.dataLayer) { + } else { + rules = rules.concat(xray_symbolizers(dataSource, dataLayer, "steelblue")); + } + } + } + } + rules = rules.concat(xray_symbolizers(xray.dataSource || "", xray.dataLayer, "red")); + return rules; + }; + // src/frontends/static.ts var R2 = 6378137; var MAX_LATITUDE2 = 85.0511287798; var MAXCOORD2 = R2 * Math.PI; var project2 = (latlng) => { let d = Math.PI / 180; - let constrained_lat = Math.max(Math.min(MAX_LATITUDE2, latlng[0]), -MAX_LATITUDE2); + let constrained_lat = Math.max(Math.min(MAX_LATITUDE2, latlng.y), -MAX_LATITUDE2); let sin = Math.sin(constrained_lat * d); - return new import_point_geometry5.default(R2 * latlng[1] * d, R2 * Math.log((1 + sin) / (1 - sin)) / 2); + return new import_point_geometry7.default(R2 * latlng.x * d, R2 * Math.log((1 + sin) / (1 - sin)) / 2); + }; + var unproject = (point) => { + var d = 180 / Math.PI; + return { + lat: (2 * Math.atan(Math.exp(point.y / R2)) - Math.PI / 2) * d, + lng: point.x * d / R2 + }; + }; + var instancedProject = (origin, display_zoom) => { + return (latlng) => { + let projected = project2(latlng); + let normalized = new import_point_geometry7.default((projected.x + MAXCOORD2) / (MAXCOORD2 * 2), 1 - (projected.y + MAXCOORD2) / (MAXCOORD2 * 2)); + return normalized.mult((1 << display_zoom) * 256).sub(origin); + }; + }; + var instancedUnproject = (origin, display_zoom) => { + return (point) => { + let normalized = new import_point_geometry7.default(point.x, point.y).add(origin).div((1 << display_zoom) * 256); + let projected = new import_point_geometry7.default(normalized.x * (MAXCOORD2 * 2) - MAXCOORD2, (1 - normalized.y) * (MAXCOORD2 * 2) - MAXCOORD2); + return unproject(projected); + }; + }; + var getZoom = (degrees_lng, css_pixels) => { + let d = css_pixels * (360 / degrees_lng); + return Math.log2(d / 256); }; var Static = class { constructor(options) { let theme = options.dark ? dark : light; this.paint_rules = options.paint_rules || paintRules(theme, options.shade); this.label_rules = options.label_rules || labelRules(theme, options.shade, options.language1, options.language2); - let source; - if (options.url.url) { - source = new PmtilesSource(options.url); - } else if (options.url.endsWith(".pmtiles")) { - source = new PmtilesSource(options.url); - } else { - source = new ZxySource(options.url); - } - let cache = new TileCache(source, 1024); - this.view = new View(cache, 14, 2); - this.debug = options.debug || false; + this.backgroundColor = options.backgroundColor; + this.views = sourcesToViews(options); + this.debug = options.debug || ""; + this.xray = options.xray; } drawContext(ctx, width, height, latlng, display_zoom) { return __async(this, null, function* () { let center = project2(latlng); - let normalized_center = new import_point_geometry5.default((center.x + MAXCOORD2) / (MAXCOORD2 * 2), 1 - (center.y + MAXCOORD2) / (MAXCOORD2 * 2)); - let origin = normalized_center.clone().mult((1 << display_zoom) * 256).sub(new import_point_geometry5.default(width / 2, height / 2)); - let bbox = { minX: origin.x, minY: origin.y, maxX: origin.x + width, maxY: origin.y + height }; - let prepared_tiles = yield this.view.getBbox(display_zoom, bbox); + let normalized_center = new import_point_geometry7.default((center.x + MAXCOORD2) / (MAXCOORD2 * 2), 1 - (center.y + MAXCOORD2) / (MAXCOORD2 * 2)); + let origin = normalized_center.clone().mult(Math.pow(2, display_zoom) * 256).sub(new import_point_geometry7.default(width / 2, height / 2)); + let bbox = { + minX: origin.x, + minY: origin.y, + maxX: origin.x + width, + maxY: origin.y + height + }; + let promises = []; + for (const [k, v] of this.views) { + let promise = v.getBbox(display_zoom, bbox); + promises.push({ key: k, promise }); + } + let tile_responses = yield Promise.all(promises.map((o2) => { + return o2.promise.then((v) => { + return { status: "fulfilled", value: v, key: o2.key }; + }, (error) => { + return { status: "rejected", value: [], reason: error, key: o2.key }; + }); + })); + let prepared_tilemap = new Map(); + for (const tile_response of tile_responses) { + if (tile_response.status === "fulfilled") { + prepared_tilemap.set(tile_response.key, tile_response.value); + } + } let start = performance.now(); - let labeler = new Labeler(display_zoom, ctx, this.label_rules, void 0); - for (var prepared_tile of prepared_tiles) { - yield labeler.add(prepared_tile); + let labeler = new Labeler(display_zoom, ctx, this.label_rules, 16, void 0); + let layout_time = labeler.add(prepared_tilemap); + if (this.backgroundColor) { + ctx.save(); + ctx.fillStyle = this.backgroundColor; + ctx.fillRect(0, 0, width, height); + ctx.restore(); } - let p2 = painter(ctx, prepared_tiles, labeler.index, this.paint_rules, bbox, origin, true, this.debug); + let paint_rules = this.paint_rules; + if (this.xray) { + paint_rules = xray_rules(prepared_tilemap, this.xray); + } + let p2 = painter(ctx, display_zoom, prepared_tilemap, this.xray ? null : labeler.index, paint_rules, bbox, origin, true, this.debug); if (this.debug) { ctx.save(); ctx.translate(-origin.x, -origin.y); - for (var prepared_tile of prepared_tiles) { - ctx.strokeStyle = "black"; - ctx.strokeRect(prepared_tile.origin.x, prepared_tile.origin.y, prepared_tile.dim, prepared_tile.dim); + ctx.strokeStyle = this.debug; + ctx.fillStyle = this.debug; + ctx.font = "12px sans-serif"; + let idx = 0; + for (const [k, v] of prepared_tilemap) { + for (let prepared_tile of v) { + ctx.strokeRect(prepared_tile.origin.x, prepared_tile.origin.y, prepared_tile.dim, prepared_tile.dim); + let dt = prepared_tile.data_tile; + ctx.fillText(k + (k ? " " : "") + dt.z + " " + dt.x + " " + dt.y, prepared_tile.origin.x + 4, prepared_tile.origin.y + 14 * (1 + idx)); + } + idx++; } ctx.restore(); } - return performance.now() - start; + return { + elapsed: performance.now() - start, + project: instancedProject(origin, display_zoom), + unproject: instancedUnproject(origin, display_zoom) + }; }); } drawCanvas(_0, _1, _2) { @@ -3879,43 +5599,35 @@ var protomaps = (() => { let dpr = window.devicePixelRatio; let width = canvas.clientWidth; let height = canvas.clientHeight; - if (!canvas.sizeSet) { + if (!(canvas.width == width * dpr && canvas.height == height * dpr)) { canvas.width = width * dpr; canvas.height = height * dpr; - canvas.sizeSet = true; } - canvas.lang = options.lang; + if (options.lang) + canvas.lang = options.lang; let ctx = canvas.getContext("2d"); ctx.setTransform(dpr, 0, 0, dpr, 0, 0); return this.drawContext(ctx, width, height, latlng, display_zoom); }); } + drawContextBounds(ctx, top_left, bottom_right, width, height) { + return __async(this, null, function* () { + let delta_degrees = bottom_right.x - top_left.x; + let center = new import_point_geometry7.default((top_left.x + bottom_right.x) / 2, (top_left.y + bottom_right.y) / 2); + return this.drawContext(ctx, width, height, center, getZoom(delta_degrees, width)); + }); + } + drawCanvasBounds(_0, _1, _2, _3) { + return __async(this, arguments, function* (canvas, top_left, bottom_right, width, options = {}) { + let delta_degrees = bottom_right.x - top_left.x; + let center = new import_point_geometry7.default((top_left.x + bottom_right.x) / 2, (top_left.y + bottom_right.y) / 2); + return this.drawCanvas(canvas, center, getZoom(delta_degrees, width), options); + }); + } }; // src/frontends/leaflet.ts - var import_point_geometry6 = __toModule(require_point_geometry()); - var CanvasPool = class { - constructor(lang) { - this.lang = lang; - this.unused = []; - } - get(tile_size) { - if (this.unused.length) { - let tile = this.unused.shift(); - tile.removed = false; - return tile; - } - let element = L.DomUtil.create("canvas", "leaflet-tile"); - element.width = tile_size; - element.height = tile_size; - element.lang = this.lang; - return element; - } - put(elem) { - L.DomUtil.removeClass(elem, "leaflet-tile-loaded"); - this.unused.push(elem); - } - }; + var import_point_geometry8 = __toModule(require_point_geometry()); var timer = (duration) => { return new Promise((resolve, reject) => { setTimeout(() => { @@ -3923,29 +5635,32 @@ var protomaps = (() => { }, duration); }); }; - var leafletLayer = (options) => { + var reflect = (promise) => { + return promise.then((v) => { + return { status: "fulfilled", value: v }; + }, (error) => { + return { status: "rejected", reason: error }; + }); + }; + var leafletLayer = (options = {}) => { class LeafletLayer extends L.GridLayer { - constructor(options2) { + constructor(options2 = {}) { if (options2.noWrap && !options2.bounds) - options2.bounds = [[-90, -180], [90, 180]]; - if (!options2.attribution) + options2.bounds = [ + [-90, -180], + [90, 180] + ]; + if (options2.attribution == null) options2.attribution = 'Protomaps \xA9 OpenStreetMap'; super(options2); let theme = options2.dark ? dark : light; this.paint_rules = options2.paint_rules || paintRules(theme, options2.shade); this.label_rules = options2.label_rules || labelRules(theme, options2.shade, options2.language1, options2.language2); + this.backgroundColor = options2.backgroundColor; this.lastRequestedZ = void 0; - let source; - if (options2.url.url) { - source = new PmtilesSource(options2.url); - } else if (options2.url.endsWith(".pmtiles")) { - source = new PmtilesSource(options2.url); - } else { - source = new ZxySource(options2.url); - } + this.xray = options2.xray; this.tasks = options2.tasks || []; - let cache = new TileCache(source, 1024); - this.view = new View(cache, 14, 2); + this.views = sourcesToViews(options2); this.debug = options2.debug; let scratch = document.createElement("canvas").getContext("2d"); this.scratch = scratch; @@ -3954,9 +5669,11 @@ var protomaps = (() => { this.rerenderTile(t2); }); }; - this.labelers = new Labelers(this.scratch, this.label_rules, this.onTilesInvalidated); + this.labelers = new Labelers(this.scratch, this.label_rules, 16, this.onTilesInvalidated); this.tile_size = 256 * window.devicePixelRatio; - this.pool = new CanvasPool(options2.lang); + this.tileDelay = options2.tileDelay || 3; + this.lang = options2.lang; + this.inspector = this.inspect(this); } setDefaultStyle(darkOption, shade, language1, language2) { let theme = darkOption ? dark : light; @@ -3967,69 +5684,106 @@ var protomaps = (() => { }) { return __async(this, null, function* () { this.lastRequestedZ = coords.z; - var prepared_tile; - try { - prepared_tile = yield this.view.getDisplayTile(coords); - } catch (e2) { - if (e2.name == "AbortError") - return; - else - throw e2; + let promises = []; + for (const [k, v] of this.views) { + let promise = v.getDisplayTile(coords); + promises.push({ key: k, promise }); + } + let tile_responses = yield Promise.all(promises.map((o2) => { + return o2.promise.then((v) => { + return { status: "fulfilled", value: v, key: o2.key }; + }, (error) => { + return { status: "rejected", reason: error, key: o2.key }; + }); + })); + let prepared_tilemap = new Map(); + for (const tile_response of tile_responses) { + if (tile_response.status === "fulfilled") { + prepared_tilemap.set(tile_response.key, [tile_response.value]); + } else { + if (tile_response.reason.name === "AbortError") { + } else { + console.error(tile_response.reason); + } + } } if (element.key != key) return; if (this.lastRequestedZ !== coords.z) return; - yield Promise.allSettled(this.tasks); + yield Promise.all(this.tasks.map(reflect)); if (element.key != key) return; if (this.lastRequestedZ !== coords.z) return; - let layout_time = yield this.labelers.add(prepared_tile); + let layout_time = this.labelers.add(coords.z, prepared_tilemap); if (element.key != key) return; if (this.lastRequestedZ !== coords.z) return; - let label_data = this.labelers.getIndex(prepared_tile.z); + let label_data = this.labelers.getIndex(coords.z); if (!this._map) return; let center = this._map.getCenter().wrap(); let pixelBounds = this._getTiledPixelBounds(center), tileRange = this._pxBoundsToTileRange(pixelBounds), tileCenter = tileRange.getCenter(); - let priority = coords.distanceTo(tileCenter) * 5; + let priority = coords.distanceTo(tileCenter) * this.tileDelay; yield timer(priority); if (element.key != key) return; if (this.lastRequestedZ !== coords.z) return; let BUF = 16; - let bbox = { minX: 256 * coords.x - BUF, minY: 256 * coords.y - BUF, maxX: 256 * (coords.x + 1) + BUF, maxY: 256 * (coords.y + 1) + BUF }; - let origin = new import_point_geometry6.default(256 * coords.x, 256 * coords.y); + let bbox = { + minX: 256 * coords.x - BUF, + minY: 256 * coords.y - BUF, + maxX: 256 * (coords.x + 1) + BUF, + maxY: 256 * (coords.y + 1) + BUF + }; + let origin = new import_point_geometry8.default(256 * coords.x, 256 * coords.y); + element.width = this.tile_size; + element.height = this.tile_size; let ctx = element.getContext("2d"); ctx.setTransform(this.tile_size / 256, 0, 0, this.tile_size / 256, 0, 0); ctx.clearRect(0, 0, 256, 256); - let painting_time = painter(ctx, [prepared_tile], label_data, this.paint_rules, bbox, origin, false, this.debug); + if (this.backgroundColor) { + ctx.save(); + ctx.fillStyle = this.backgroundColor; + ctx.fillRect(0, 0, 256, 256); + ctx.restore(); + } + var painting_time = 0; + let paint_rules = this.paint_rules; + if (this.xray) { + paint_rules = xray_rules(prepared_tilemap, this.xray); + } + painting_time = painter(ctx, coords.z, prepared_tilemap, this.xray ? null : label_data, paint_rules, bbox, origin, false, this.debug); if (this.debug) { - let data_tile = prepared_tile.data_tile; ctx.save(); ctx.fillStyle = this.debug; ctx.font = "600 12px sans-serif"; ctx.fillText(coords.z + " " + coords.x + " " + coords.y, 4, 14); - ctx.font = "200 12px sans-serif"; - ctx.fillText(data_tile.z + " " + data_tile.x + " " + data_tile.y, 4, 28); + ctx.font = "12px sans-serif"; + let ypos = 28; + for (let [k, v] of prepared_tilemap) { + let dt = v[0].data_tile; + ctx.fillText(k + (k ? " " : "") + dt.z + " " + dt.x + " " + dt.y, 4, ypos); + ypos += 14; + } ctx.font = "600 10px sans-serif"; if (painting_time > 8) { - ctx.fillText(painting_time.toFixed() + " ms paint", 4, 42); + ctx.fillText(painting_time.toFixed() + " ms paint", 4, ypos); + ypos += 14; } if (layout_time > 8) { - ctx.fillText(layout_time.toFixed() + " ms layout", 4, 56); + ctx.fillText(layout_time.toFixed() + " ms layout", 4, ypos); } ctx.strokeStyle = this.debug; - ctx.lineWidth = coords.x / 4 === data_tile.x ? 1.5 : 0.5; + ctx.lineWidth = 0.5; ctx.beginPath(); ctx.moveTo(0, 0); ctx.lineTo(0, 256); ctx.stroke(); - ctx.lineWidth = coords.y / 4 === data_tile.y ? 1.5 : 0.5; + ctx.lineWidth = 0.5; ctx.beginPath(); ctx.moveTo(0, 0); ctx.lineTo(256, 0); @@ -4048,7 +5802,7 @@ var protomaps = (() => { } } clearLayout() { - this.labelers = new Labelers(this.scratch, this.label_rules, this.onTilesInvalidated); + this.labelers = new Labelers(this.scratch, this.label_rules, 16, this.onTilesInvalidated); } rerenderTiles() { for (let unwrapped_k in this._tiles) { @@ -4058,7 +5812,8 @@ var protomaps = (() => { } } createTile(coords, showTile) { - let element = this.pool.get(this.tile_size); + let element = L.DomUtil.create("canvas", "leaflet-tile"); + element.lang = this.lang; let key = this._tileCoordsToKey(coords); element.key = key; this.renderTile(coords, element, key, () => { @@ -4073,8 +5828,9 @@ var protomaps = (() => { } tile.el.removed = true; tile.el.key = void 0; + L.DomUtil.removeClass(tile.el, "leaflet-tile-loaded"); + tile.el.width = tile.el.height = 0; L.DomUtil.remove(tile.el); - this.pool.put(tile.el); delete this._tiles[key]; this.fire("tileunload", { tile: tile.el, @@ -4082,14 +5838,51 @@ var protomaps = (() => { }); } queryFeatures(lng, lat) { - return this.view.queryFeatures(lng, lat, this._map.getZoom()); + let featuresBySourceName = new Map(); + for (var [sourceName, view] of this.views) { + featuresBySourceName.set(sourceName, view.queryFeatures(lng, lat, this._map.getZoom())); + } + return featuresBySourceName; + } + inspect(layer) { + return (ev) => { + let typeGlyphs = ["\u25CE", "\u27CD", "\u25FB"]; + let wrapped = layer._map.wrapLatLng(ev.latlng); + let resultsBySourceName = layer.queryFeatures(wrapped.lng, wrapped.lat); + var content = ""; + let firstRow = true; + for (var [sourceName, results] of resultsBySourceName) { + for (var result of results) { + if (this.xray && this.xray !== true) { + if (!((this.xray.dataSource || "") === sourceName && this.xray.dataLayer === result.layerName)) { + continue; + } + } + content = content + `
${typeGlyphs[result.feature.geomType - 1]} ${sourceName} ${sourceName ? "/" : ""} ${result.layerName} ${result.feature.id || ""}
`; + for (const prop in result.feature.props) { + content = content + `
${prop} = ${result.feature.props[prop]}
`; + } + firstRow = false; + } + } + if (firstRow) { + content = "No features."; + } + L.popup().setLatLng(ev.latlng).setContent('
' + content + "
").openOn(layer._map); + }; + } + addInspector(map) { + return map.on("click", this.inspector); + } + removeInspector(map) { + return map.off("click", this.inspector); } } return new LeafletLayer(options); }; - // node_modules/protosprites/index.js - var potpack = (boxes) => { + // node_modules/potpack/index.mjs + function potpack(boxes) { let area = 0; let maxWidth = 0; for (const box of boxes) { @@ -4138,15 +5931,22 @@ var protomaps = (() => { h: height, fill: area / (width * height) || 0 }; + } + + // src/task.ts + var Font = (name, url, weight) => { + let ff = new FontFace(name, "url(" + url + ")", { weight }); + document.fonts.add(ff); + return ff.load(); }; - var mkimg = (src) => { + var mkimg = (src) => __async(void 0, null, function* () { return new Promise((resolve, reject) => { let img = new Image(); img.onload = () => resolve(img); img.onerror = () => reject("Invalid SVG"); img.src = src; }); - }; + }); var MISSING = ` @@ -4155,10 +5955,12 @@ var protomaps = (() => { `; - var Protosprites = class { + var Sheet = class { constructor(src) { this.src = src; - this.canvas = null; + this.canvas = document.createElement("canvas"); + this.mapping = new Map(); + this.missingBox = { x: 0, y: 0, w: 0, h: 0 }; } load() { return __async(this, null, function* () { @@ -4169,87 +5971,98 @@ var protomaps = (() => { src = yield c2.text(); } let tree = new window.DOMParser().parseFromString(src, "text/html"); - let icons = tree.body.children; - this.mapping = {}; + let icons = Array.from(tree.body.children); let missingImg = yield mkimg("data:image/svg+xml;base64," + btoa(MISSING)); let boxes = [ - { w: missingImg.width * scale, h: missingImg.height * scale, img: missingImg } + { + w: missingImg.width * scale, + h: missingImg.height * scale, + img: missingImg, + id: "" + } ]; let serializer = new XMLSerializer(); for (let ps of icons) { var svg64 = btoa(serializer.serializeToString(ps)); var image64 = "data:image/svg+xml;base64," + svg64; let img = yield mkimg(image64); - boxes.push({ w: img.width * scale, h: img.height * scale, img, id: ps.id }); + boxes.push({ + w: img.width * scale, + h: img.height * scale, + img, + id: ps.id + }); } let packresult = potpack(boxes); - this.canvas = document.createElement("canvas"); this.canvas.width = packresult.w; this.canvas.height = packresult.h; let ctx = this.canvas.getContext("2d"); - for (let box of boxes) { - ctx.drawImage(box.img, box.x, box.y, box.w, box.h); - if (box.id) - this.mapping[box.id] = { x: box.x, y: box.y, w: box.w, h: box.h }; - else - this.missingBox = { x: box.x, y: box.y, w: box.w, h: box.h }; + if (ctx) { + for (let box of boxes) { + if (box.x !== void 0 && box.y !== void 0) { + ctx.drawImage(box.img, box.x, box.y, box.w, box.h); + if (box.id) + this.mapping.set(box.id, { + x: box.x, + y: box.y, + w: box.w, + h: box.h + }); + else + this.missingBox = { x: box.x, y: box.y, w: box.w, h: box.h }; + } + } } return this; }); } get(name) { - let result = this.mapping[name]; + let result = this.mapping.get(name); if (!result) result = this.missingBox; - result.canvas = this.canvas; return result; } }; - // src/task.ts - var Font = (name, url, weight) => { - let ff = new FontFace(name, "url(" + url + ")", { weight }); - document.fonts.add(ff); - return ff.load(); - }; - var Sprites = (url) => { - return new Protosprites(url); - }; - // src/compat/json_style.ts + function number(val, defaultValue) { + return typeof val === "number" ? val : defaultValue; + } function filterFn(arr2) { if (arr2.includes("$type")) { - return (f2) => true; + return (z2) => true; } else if (arr2[0] == "==") { - return (f2) => f2[arr2[1]] === arr2[2]; + return (z2, f2) => f2.props[arr2[1]] === arr2[2]; } else if (arr2[0] == "!=") { - return (f2) => f2[arr2[1]] !== arr2[2]; + return (z2, f2) => f2.props[arr2[1]] !== arr2[2]; } else if (arr2[0] == "!") { let sub = filterFn(arr2[1]); - return (f2) => !sub(f2); + return (z2, f2) => !sub(z2, f2); } else if (arr2[0] === "<") { - return (f2) => f2[arr2[1]] < arr2[2]; + return (z2, f2) => number(f2.props[arr2[1]], Infinity) < arr2[2]; } else if (arr2[0] === "<=") { - return (f2) => f2[arr2[1]] <= arr2[2]; + return (z2, f2) => number(f2.props[arr2[1]], Infinity) <= arr2[2]; } else if (arr2[0] === ">") { - return (f2) => f2[arr2[1]] > arr2[2]; + return (z2, f2) => number(f2.props[arr2[1]], -Infinity) > arr2[2]; } else if (arr2[0] === ">=") { - return (f2) => f2[arr2[1]] >= arr2[2]; + return (z2, f2) => number(f2.props[arr2[1]], -Infinity) >= arr2[2]; } else if (arr2[0] === "in") { - return (f2) => arr2.slice(2, arr2.length).includes(f2[arr2[1]]); + return (z2, f2) => arr2.slice(2, arr2.length).includes(f2.props[arr2[1]]); } else if (arr2[0] === "!in") { - return (f2) => !arr2.slice(2, arr2.length).includes(f2[arr2[1]]); + return (z2, f2) => !arr2.slice(2, arr2.length).includes(f2.props[arr2[1]]); } else if (arr2[0] === "has") { - return (f2) => f2.hasOwnProperty(arr2[1]); + return (z2, f2) => f2.props.hasOwnProperty(arr2[1]); + } else if (arr2[0] === "!has") { + return (z2, f2) => !f2.props.hasOwnProperty(arr2[1]); } else if (arr2[0] === "all") { let parts = arr2.slice(1, arr2.length).map((e2) => filterFn(e2)); - return (f2) => parts.every((p2) => { - return p2(f2); + return (z2, f2) => parts.every((p2) => { + return p2(z2, f2); }); } else if (arr2[0] === "any") { let parts = arr2.slice(1, arr2.length).map((e2) => filterFn(e2)); - return (f2) => parts.some((p2) => { - return p2(f2); + return (z2, f2) => parts.some((p2) => { + return p2(z2, f2); }); } else { console.log("Unimplemented filter: ", arr2[0]); @@ -4258,7 +6071,7 @@ var protomaps = (() => { } function numberFn(obj) { if (obj.base && obj.stops) { - return (z2, f2) => { + return (z2) => { return exp(obj.base, obj.stops)(z2 - 1); }; } else if (obj[0] == "interpolate" && obj[1][0] == "exponential" && obj[2] == "zoom") { @@ -4273,13 +6086,15 @@ var protomaps = (() => { } else if (obj[0] == "step" && obj[1][0] == "get") { let slice = obj.slice(2); let prop = obj[1][1]; - return (z2, props) => { - let val = props[prop]; - if (val < slice[1]) - return slice[0]; - for (i2 = 1; i2 < slice.length; i2 += 2) { - if (val <= slice[i2]) - return slice[i2 + 1]; + return (z2, f2) => { + let val = f2 == null ? void 0 : f2.props[prop]; + if (typeof val === "number") { + if (val < slice[1]) + return slice[0]; + for (i2 = 1; i2 < slice.length; i2 += 2) { + if (val <= slice[i2]) + return slice[i2 + 1]; + } } return slice[slice.length - 1]; }; @@ -4294,15 +6109,15 @@ var protomaps = (() => { if (typeof obj == "number") { return obj; } - return numberFn(obj); + return (z2, f2) => f2 ? numberFn(obj)(z2, f2) : defaultValue; } function widthFn(width_obj, gap_obj) { let w = numberOrFn(width_obj, 1); let g = numberOrFn(gap_obj); - return (z2) => { - let tmp = typeof w == "number" ? w : w(z2, {}); + return (z2, f2) => { + let tmp = typeof w == "number" ? w : w(z2, f2); if (g) { - return tmp + (typeof g == "number" ? g : g(z2, {})); + return tmp + (typeof g == "number" ? g : g(z2, f2)); } return tmp; }; @@ -4324,23 +6139,23 @@ var protomaps = (() => { if (fontfaces.length && fontfaces[0].style) style = fontfaces[0].style + " "; if (typeof text_size == "number") { - return `${style}${weight}${text_size}px ${fontfaces.map((f2) => f2.face).join(", ")}`; + return (z2) => `${style}${weight}${text_size}px ${fontfaces.map((f2) => f2.face).join(", ")}`; } else if (text_size.stops) { var base = 1.4; if (text_size.base) base = text_size.base; let t2 = numberFn(text_size); - return (z2) => { - return `${style}${weight}${t2(z2, {})}px ${fontfaces.map((f2) => f2.face).join(", ")}`; + return (z2, f2) => { + return `${style}${weight}${t2(z2, f2)}px ${fontfaces.map((f3) => f3.face).join(", ")}`; }; } else if (text_size[0] == "step") { let t2 = numberFn(text_size); - return (z2, p2) => { - return `${style}${weight}${t2(z2, p2)}px ${fontfaces.map((f2) => f2.face).join(", ")}`; + return (z2, f2) => { + return `${style}${weight}${t2(z2, f2)}px ${fontfaces.map((f3) => f3.face).join(", ")}`; }; } else { console.log("Can't parse font: ", obj); - return (z2, p2) => "12px sans-serif"; + return (z2) => "12px sans-serif"; } } function json_style(obj, fontsubmap) { @@ -4414,7 +6229,8 @@ var protomaps = (() => { fill: layer.paint["text-color"], width: layer.paint["text-halo-width"], stroke: layer.paint["text-halo-color"], - textTransform: layer.layout["text-transform"] + textTransform: layer.layout["text-transform"], + label_props: layer.layout["text-field"] ? [layer.layout["text-field"]] : void 0 }) }); } else { @@ -4426,10 +6242,22 @@ var protomaps = (() => { fill: layer.paint["text-color"], stroke: layer.paint["text-halo-color"], width: layer.paint["text-halo-width"], - textTransform: layer.layout["text-transform"] + textTransform: layer.layout["text-transform"], + label_props: layer.layout["text-field"] ? [layer.layout["text-field"]] : void 0 }) }); } + } else if (layer.type == "circle") { + paint_rules.push({ + dataLayer: layer["source-layer"], + filter, + symbolizer: new CircleSymbolizer({ + radius: layer.paint["circle-radius"], + fill: layer.paint["circle-color"], + stroke: layer.paint["circle-stroke-color"], + width: layer.paint["circle-stroke-width"] + }) + }); } } label_rules.reverse(); diff --git a/static/javascript/protomaps.min.js b/static/javascript/protomaps.min.js index 958051c..01246b3 100644 --- a/static/javascript/protomaps.min.js +++ b/static/javascript/protomaps.min.js @@ -1,9 +1,9 @@ -var protomaps=(()=>{var Kt=Object.create;var de=Object.defineProperty;var ei=Object.getOwnPropertyDescriptor;var ti=Object.getOwnPropertyNames,rt=Object.getOwnPropertySymbols,ii=Object.getPrototypeOf,nt=Object.prototype.hasOwnProperty,ri=Object.prototype.propertyIsEnumerable;var qe=(e,t,i)=>t in e?de(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,at=(e,t)=>{for(var i in t||(t={}))nt.call(t,i)&&qe(e,i,t[i]);if(rt)for(var i of rt(t))ri.call(t,i)&&qe(e,i,t[i]);return e};var st=e=>de(e,"__esModule",{value:!0});var R=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ni=(e,t)=>{st(e);for(var i in t)de(e,i,{get:t[i],enumerable:!0})},ai=(e,t,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ti(t))!nt.call(e,r)&&r!=="default"&&de(e,r,{get:()=>t[r],enumerable:!(i=ei(t,r))||i.enumerable});return e},V=e=>ai(st(de(e!=null?Kt(ii(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);var J=(e,t,i)=>(qe(e,typeof t!="symbol"?t+"":t,i),i);var D=(e,t,i)=>new Promise((r,a)=>{var n=o=>{try{l(i.next(o))}catch(h){a(h)}},s=o=>{try{l(i.throw(o))}catch(h){a(h)}},l=o=>o.done?r(o.value):Promise.resolve(o.value).then(n,s);l((i=i.apply(e,t)).next())});var A=R((fr,lt)=>{"use strict";lt.exports=K;function K(e,t){this.x=e,this.y=t}K.prototype={clone:function(){return new K(this.x,this.y)},add:function(e){return this.clone()._add(e)},sub:function(e){return this.clone()._sub(e)},multByPoint:function(e){return this.clone()._multByPoint(e)},divByPoint:function(e){return this.clone()._divByPoint(e)},mult:function(e){return this.clone()._mult(e)},div:function(e){return this.clone()._div(e)},rotate:function(e){return this.clone()._rotate(e)},rotateAround:function(e,t){return this.clone()._rotateAround(e,t)},matMult:function(e){return this.clone()._matMult(e)},unit:function(){return this.clone()._unit()},perp:function(){return this.clone()._perp()},round:function(){return this.clone()._round()},mag:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},equals:function(e){return this.x===e.x&&this.y===e.y},dist:function(e){return Math.sqrt(this.distSqr(e))},distSqr:function(e){var t=e.x-this.x,i=e.y-this.y;return t*t+i*i},angle:function(){return Math.atan2(this.y,this.x)},angleTo:function(e){return Math.atan2(this.y-e.y,this.x-e.x)},angleWith:function(e){return this.angleWithSep(e.x,e.y)},angleWithSep:function(e,t){return Math.atan2(this.x*t-this.y*e,this.x*e+this.y*t)},_matMult:function(e){var t=e[0]*this.x+e[1]*this.y,i=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=i,this},_add:function(e){return this.x+=e.x,this.y+=e.y,this},_sub:function(e){return this.x-=e.x,this.y-=e.y,this},_mult:function(e){return this.x*=e,this.y*=e,this},_div:function(e){return this.x/=e,this.y/=e,this},_multByPoint:function(e){return this.x*=e.x,this.y*=e.y,this},_divByPoint:function(e){return this.x/=e.x,this.y/=e.y,this},_unit:function(){return this._div(this.mag()),this},_perp:function(){var e=this.y;return this.y=this.x,this.x=-e,this},_rotate:function(e){var t=Math.cos(e),i=Math.sin(e),r=t*this.x-i*this.y,a=i*this.x+t*this.y;return this.x=r,this.y=a,this},_rotateAround:function(e,t){var i=Math.cos(e),r=Math.sin(e),a=t.x+i*(this.x-t.x)-r*(this.y-t.y),n=t.y+r*(this.x-t.x)+i*(this.y-t.y);return this.x=a,this.y=n,this},_round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}};K.convert=function(e){return e instanceof K?e:Array.isArray(e)?new K(e[0],e[1]):e}});var Ae=R((dr,ot)=>{"use strict";var si=A();ot.exports=ee;function ee(e,t,i,r,a){this.properties={},this.extent=i,this.type=0,this._pbf=e,this._geometry=-1,this._keys=r,this._values=a,e.readFields(li,this,t)}function li(e,t,i){e==1?t.id=i.readVarint():e==2?oi(i,t):e==3?t.type=i.readVarint():e==4&&(t._geometry=i.pos)}function oi(e,t){for(var i=e.readVarint()+e.pos;e.pos>3}if(r--,i===1||i===2)a+=e.readSVarint(),n+=e.readSVarint(),i===1&&(l&&s.push(l),l=[]),l.push(new si(a,n));else if(i===7)l&&l.push(l[0].clone());else throw new Error("unknown command "+i)}return l&&s.push(l),s};ee.prototype.bbox=function(){var e=this._pbf;e.pos=this._geometry;for(var t=e.readVarint()+e.pos,i=1,r=0,a=0,n=0,s=1/0,l=-1/0,o=1/0,h=-1/0;e.pos>3}if(r--,i===1||i===2)a+=e.readSVarint(),n+=e.readSVarint(),al&&(l=a),nh&&(h=n);else if(i!==7)throw new Error("unknown command "+i)}return[s,o,l,h]};ee.prototype.toGeoJSON=function(e,t,i){var r=this.extent*Math.pow(2,i),a=this.extent*e,n=this.extent*t,s=this.loadGeometry(),l=ee.types[this.type],o,h;function d(y){for(var b=0;b{"use strict";var fi=Ae();ut.exports=ht;function ht(e,t){this.version=1,this.name=null,this.extent=4096,this.length=0,this._pbf=e,this._keys=[],this._values=[],this._features=[],e.readFields(di,this,t),this.length=this._features.length}function di(e,t,i){e===15?t.version=i.readVarint():e===1?t.name=i.readString():e===5?t.extent=i.readVarint():e===2?t._features.push(i.pos):e===3?t._keys.push(i.readString()):e===4&&t._values.push(ci(i))}function ci(e){for(var t=null,i=e.readVarint()+e.pos;e.pos>3;t=r===1?e.readString():r===2?e.readFloat():r===3?e.readDouble():r===4?e.readVarint64():r===5?e.readVarint():r===6?e.readSVarint():r===7?e.readBoolean():null}return t}ht.prototype.feature=function(e){if(e<0||e>=this._features.length)throw new Error("feature index out of bounds");this._pbf.pos=this._features[e];var t=this._pbf.readVarint()+this._pbf.pos;return new fi(this._pbf,t,this.extent,this._keys,this._values)}});var dt=R((mr,ft)=>{"use strict";var mi=$e();ft.exports=xi;function xi(e,t){this.layers=e.readFields(pi,{},t)}function pi(e,t,i){if(e===3){var r=new mi(i,i.readVarint()+i.pos);r.length&&(t[r.name]=r)}}});var ct=R((xr,ke)=>{ke.exports.VectorTile=dt();ke.exports.VectorTileFeature=Ae();ke.exports.VectorTileLayer=$e()});var mt=R(je=>{je.read=function(e,t,i,r,a){var n,s,l=a*8-r-1,o=(1<>1,d=-7,x=i?a-1:0,c=i?-1:1,y=e[t+x];for(x+=c,n=y&(1<<-d)-1,y>>=-d,d+=l;d>0;n=n*256+e[t+x],x+=c,d-=8);for(s=n&(1<<-d)-1,n>>=-d,d+=r;d>0;s=s*256+e[t+x],x+=c,d-=8);if(n===0)n=1-h;else{if(n===o)return s?NaN:(y?-1:1)*(1/0);s=s+Math.pow(2,r),n=n-h}return(y?-1:1)*s*Math.pow(2,n-r)};je.write=function(e,t,i,r,a,n){var s,l,o,h=n*8-a-1,d=(1<>1,c=a===23?Math.pow(2,-24)-Math.pow(2,-77):0,y=r?0:n-1,b=r?1:-1,g=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(l=isNaN(t)?1:0,s=d):(s=Math.floor(Math.log(t)/Math.LN2),t*(o=Math.pow(2,-s))<1&&(s--,o*=2),s+x>=1?t+=c/o:t+=c*Math.pow(2,1-x),t*o>=2&&(s++,o/=2),s+x>=d?(l=0,s=d):s+x>=1?(l=(t*o-1)*Math.pow(2,a),s=s+x):(l=t*Math.pow(2,x-1)*Math.pow(2,a),s=0));a>=8;e[i+y]=l&255,y+=b,l/=256,a-=8);for(s=s<0;e[i+y]=s&255,y+=b,s/=256,h-=8);e[i+y-b]|=g*128}});var wt=R((yr,gt)=>{"use strict";gt.exports=M;var Me=mt();function M(e){this.buf=ArrayBuffer.isView&&ArrayBuffer.isView(e)?e:new Uint8Array(e||0),this.pos=0,this.type=0,this.length=this.buf.length}M.Varint=0;M.Fixed64=1;M.Bytes=2;M.Fixed32=5;var Ue=(1<<16)*(1<<16),xt=1/Ue,yi=12,pt=typeof TextDecoder=="undefined"?null:new TextDecoder("utf8");M.prototype={destroy:function(){this.buf=null},readFields:function(e,t,i){for(i=i||this.length;this.pos>3,n=this.pos;this.type=r&7,e(a,t,this),this.pos===n&&this.skip(r)}return t},readMessage:function(e,t){return this.readFields(e,t,this.readVarint()+this.pos)},readFixed32:function(){var e=Le(this.buf,this.pos);return this.pos+=4,e},readSFixed32:function(){var e=bt(this.buf,this.pos);return this.pos+=4,e},readFixed64:function(){var e=Le(this.buf,this.pos)+Le(this.buf,this.pos+4)*Ue;return this.pos+=8,e},readSFixed64:function(){var e=Le(this.buf,this.pos)+bt(this.buf,this.pos+4)*Ue;return this.pos+=8,e},readFloat:function(){var e=Me.read(this.buf,this.pos,!0,23,4);return this.pos+=4,e},readDouble:function(){var e=Me.read(this.buf,this.pos,!0,52,8);return this.pos+=8,e},readVarint:function(e){var t=this.buf,i,r;return r=t[this.pos++],i=r&127,r<128||(r=t[this.pos++],i|=(r&127)<<7,r<128)||(r=t[this.pos++],i|=(r&127)<<14,r<128)||(r=t[this.pos++],i|=(r&127)<<21,r<128)?i:(r=t[this.pos],i|=(r&15)<<28,bi(i,e,this))},readVarint64:function(){return this.readVarint(!0)},readSVarint:function(){var e=this.readVarint();return e%2==1?(e+1)/-2:e/2},readBoolean:function(){return Boolean(this.readVarint())},readString:function(){var e=this.readVarint()+this.pos,t=this.pos;return this.pos=e,e-t>=yi&&pt?Ci(this.buf,t,e):Pi(this.buf,t,e)},readBytes:function(){var e=this.readVarint()+this.pos,t=this.buf.subarray(this.pos,e);return this.pos=e,t},readPackedVarint:function(e,t){if(this.type!==M.Bytes)return e.push(this.readVarint(t));var i=E(this);for(e=e||[];this.pos127;);else if(t===M.Bytes)this.pos=this.readVarint()+this.pos;else if(t===M.Fixed32)this.pos+=4;else if(t===M.Fixed64)this.pos+=8;else throw new Error("Unimplemented type: "+t)},writeTag:function(e,t){this.writeVarint(e<<3|t)},realloc:function(e){for(var t=this.length||16;t268435455||e<0){gi(e,this);return}this.realloc(4),this.buf[this.pos++]=e&127|(e>127?128:0),!(e<=127)&&(this.buf[this.pos++]=(e>>>=7)&127|(e>127?128:0),!(e<=127)&&(this.buf[this.pos++]=(e>>>=7)&127|(e>127?128:0),!(e<=127)&&(this.buf[this.pos++]=e>>>7&127)))},writeSVarint:function(e){this.writeVarint(e<0?-e*2-1:e*2)},writeBoolean:function(e){this.writeVarint(Boolean(e))},writeString:function(e){e=String(e),this.realloc(e.length*4),this.pos++;var t=this.pos;this.pos=Di(this.buf,e,this.pos);var i=this.pos-t;i>=128&&yt(t,i,this),this.pos=t-1,this.writeVarint(i),this.pos+=i},writeFloat:function(e){this.realloc(4),Me.write(this.buf,e,this.pos,!0,23,4),this.pos+=4},writeDouble:function(e){this.realloc(8),Me.write(this.buf,e,this.pos,!0,52,8),this.pos+=8},writeBytes:function(e){var t=e.length;this.writeVarint(t),this.realloc(t);for(var i=0;i=128&&yt(i,r,this),this.pos=i-1,this.writeVarint(r),this.pos+=r},writeMessage:function(e,t,i){this.writeTag(e,M.Bytes),this.writeRawMessage(t,i)},writePackedVarint:function(e,t){t.length&&this.writeMessage(e,_i,t)},writePackedSVarint:function(e,t){t.length&&this.writeMessage(e,Fi,t)},writePackedBoolean:function(e,t){t.length&&this.writeMessage(e,Mi,t)},writePackedFloat:function(e,t){t.length&&this.writeMessage(e,zi,t)},writePackedDouble:function(e,t){t.length&&this.writeMessage(e,ki,t)},writePackedFixed32:function(e,t){t.length&&this.writeMessage(e,Li,t)},writePackedSFixed32:function(e,t){t.length&&this.writeMessage(e,Si,t)},writePackedFixed64:function(e,t){t.length&&this.writeMessage(e,Ti,t)},writePackedSFixed64:function(e,t){t.length&&this.writeMessage(e,Bi,t)},writeBytesField:function(e,t){this.writeTag(e,M.Bytes),this.writeBytes(t)},writeFixed32Field:function(e,t){this.writeTag(e,M.Fixed32),this.writeFixed32(t)},writeSFixed32Field:function(e,t){this.writeTag(e,M.Fixed32),this.writeSFixed32(t)},writeFixed64Field:function(e,t){this.writeTag(e,M.Fixed64),this.writeFixed64(t)},writeSFixed64Field:function(e,t){this.writeTag(e,M.Fixed64),this.writeSFixed64(t)},writeVarintField:function(e,t){this.writeTag(e,M.Varint),this.writeVarint(t)},writeSVarintField:function(e,t){this.writeTag(e,M.Varint),this.writeSVarint(t)},writeStringField:function(e,t){this.writeTag(e,M.Bytes),this.writeString(t)},writeFloatField:function(e,t){this.writeTag(e,M.Fixed32),this.writeFloat(t)},writeDoubleField:function(e,t){this.writeTag(e,M.Fixed64),this.writeDouble(t)},writeBooleanField:function(e,t){this.writeVarintField(e,Boolean(t))}};function bi(e,t,i){var r=i.buf,a,n;if(n=r[i.pos++],a=(n&112)>>4,n<128||(n=r[i.pos++],a|=(n&127)<<3,n<128)||(n=r[i.pos++],a|=(n&127)<<10,n<128)||(n=r[i.pos++],a|=(n&127)<<17,n<128)||(n=r[i.pos++],a|=(n&127)<<24,n<128)||(n=r[i.pos++],a|=(n&1)<<31,n<128))return te(e,a,t);throw new Error("Expected varint not more than 10 bytes")}function E(e){return e.type===M.Bytes?e.readVarint()+e.pos:e.pos+1}function te(e,t,i){return i?t*4294967296+(e>>>0):(t>>>0)*4294967296+(e>>>0)}function gi(e,t){var i,r;if(e>=0?(i=e%4294967296|0,r=e/4294967296|0):(i=~(-e%4294967296),r=~(-e/4294967296),i^4294967295?i=i+1|0:(i=0,r=r+1|0)),e>=18446744073709552e3||e<-18446744073709552e3)throw new Error("Given varint doesn't fit into 10 bytes");t.realloc(10),wi(i,r,t),vi(r,t)}function wi(e,t,i){i.buf[i.pos++]=e&127|128,e>>>=7,i.buf[i.pos++]=e&127|128,e>>>=7,i.buf[i.pos++]=e&127|128,e>>>=7,i.buf[i.pos++]=e&127|128,e>>>=7,i.buf[i.pos]=e&127}function vi(e,t){var i=(e&7)<<4;t.buf[t.pos++]|=i|((e>>>=3)?128:0),!!e&&(t.buf[t.pos++]=e&127|((e>>>=7)?128:0),!!e&&(t.buf[t.pos++]=e&127|((e>>>=7)?128:0),!!e&&(t.buf[t.pos++]=e&127|((e>>>=7)?128:0),!!e&&(t.buf[t.pos++]=e&127|((e>>>=7)?128:0),!!e&&(t.buf[t.pos++]=e&127)))))}function yt(e,t,i){var r=t<=16383?1:t<=2097151?2:t<=268435455?3:Math.floor(Math.log(t)/(Math.LN2*7));i.realloc(r);for(var a=i.pos-1;a>=e;a--)i.buf[a+r]=i.buf[a]}function _i(e,t){for(var i=0;i>>8,e[i+2]=t>>>16,e[i+3]=t>>>24}function bt(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16)+(e[t+3]<<24)}function Pi(e,t,i){for(var r="",a=t;a239?4:n>223?3:n>191?2:1;if(a+l>i)break;var o,h,d;l===1?n<128&&(s=n):l===2?(o=e[a+1],(o&192)==128&&(s=(n&31)<<6|o&63,s<=127&&(s=null))):l===3?(o=e[a+1],h=e[a+2],(o&192)==128&&(h&192)==128&&(s=(n&15)<<12|(o&63)<<6|h&63,(s<=2047||s>=55296&&s<=57343)&&(s=null))):l===4&&(o=e[a+1],h=e[a+2],d=e[a+3],(o&192)==128&&(h&192)==128&&(d&192)==128&&(s=(n&15)<<18|(o&63)<<12|(h&63)<<6|d&63,(s<=65535||s>=1114112)&&(s=null))),s===null?(s=65533,l=1):s>65535&&(s-=65536,r+=String.fromCharCode(s>>>10&1023|55296),s=56320|s&1023),r+=String.fromCharCode(s),a+=l}return r}function Ci(e,t,i){return pt.decode(e.subarray(t,i))}function Di(e,t,i){for(var r=0,a,n;r55295&&a<57344)if(n)if(a<56320){e[i++]=239,e[i++]=191,e[i++]=189,n=a;continue}else a=n-55296<<10|a-56320|65536,n=null;else{a>56319||r+1===t.length?(e[i++]=239,e[i++]=191,e[i++]=189):n=a;continue}else n&&(e[i++]=239,e[i++]=191,e[i++]=189,n=null);a<128?e[i++]=a:(a<2048?e[i++]=a>>6|192:(a<65536?e[i++]=a>>12|224:(e[i++]=a>>18|240,e[i++]=a>>12&63|128),e[i++]=a>>6&63|128),e[i++]=a&63|128)}return i}});var Tt=R((We,Oe)=>{(function(e,t){typeof We=="object"&&typeof Oe!="undefined"?Oe.exports=t():typeof define=="function"&&define.amd?define(t):(e=e||self).RBush=t()})(We,function(){"use strict";function e(u,f,m,w,p){(function v(_,F,z,k,T){for(;k>z;){if(k-z>600){var S=k-z+1,P=F-z+1,ue=Math.log(S),j=.5*Math.exp(2*ue/3),G=.5*Math.sqrt(ue*j*(S-j)/S)*(P-S/2<0?-1:1),Q=Math.max(z,Math.floor(F-P*j/S+G)),Jt=Math.min(k,Math.floor(F+(S-P)*j/S+G));v(_,F,Q,Jt,T)}var ze=_[F],fe=z,Y=k;for(t(_,z,F),T(_[k],ze)>0&&t(_,z,k);fe0;)Y--}T(_[z],ze)===0?t(_,z,Y):t(_,++Y,k),Y<=F&&(z=Y+1),F<=Y&&(k=Y-1)}})(u,f,m||0,w||u.length-1,p||i)}function t(u,f,m){var w=u[f];u[f]=u[m],u[m]=w}function i(u,f){return uf?1:0}var r=function(u){u===void 0&&(u=9),this._maxEntries=Math.max(4,u),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()};function a(u,f,m){if(!m)return f.indexOf(u);for(var w=0;w=u.minX&&f.maxY>=u.minY}function b(u){return{children:u,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function g(u,f,m,w,p){for(var v=[f,m];v.length;)if(!((m=v.pop())-(f=v.pop())<=w)){var _=f+Math.ceil((m-f)/w/2)*w;e(u,_,f,m,p),v.push(f,_,_,m)}}return r.prototype.all=function(){return this._all(this.data,[])},r.prototype.search=function(u){var f=this.data,m=[];if(!y(u,f))return m;for(var w=this.toBBox,p=[];f;){for(var v=0;v=0&&p[f].children.length>this._maxEntries;)this._split(p,f),f--;this._adjustParentBBoxes(w,p,f)},r.prototype._split=function(u,f){var m=u[f],w=m.children.length,p=this._minEntries;this._chooseSplitAxis(m,p,w);var v=this._chooseSplitIndex(m,p,w),_=b(m.children.splice(v,m.children.length-v));_.height=m.height,_.leaf=m.leaf,n(m,this.toBBox),n(_,this.toBBox),f?u[f-1].children.push(_):this._splitRoot(m,_)},r.prototype._splitRoot=function(u,f){this.data=b([u,f]),this.data.height=u.height+1,this.data.leaf=!1,n(this.data,this.toBBox)},r.prototype._chooseSplitIndex=function(u,f,m){for(var w,p,v,_,F,z,k,T=1/0,S=1/0,P=f;P<=m-f;P++){var ue=s(u,0,P,this.toBBox),j=s(u,P,m,this.toBBox),G=(p=ue,v=j,_=void 0,F=void 0,z=void 0,k=void 0,_=Math.max(p.minX,v.minX),F=Math.max(p.minY,v.minY),z=Math.min(p.maxX,v.maxX),k=Math.min(p.maxY,v.maxY),Math.max(0,z-_)*Math.max(0,k-F)),Q=d(ue)+d(j);G=f;T--){var S=u.children[T];l(_,u.leaf?p(S):S),F+=x(_)}return F},r.prototype._adjustParentBBoxes=function(u,f,m){for(var w=m;w>=0;w--)l(f[w],u)},r.prototype._condense=function(u){for(var f=u.length-1,m=void 0;f>=0;f--)u[f].children.length===0?f>0?(m=u[f-1].children).splice(m.indexOf(u[f]),1):this.clear():n(u[f],this.toBBox)},r})});var Ct=R((Ne,He)=>{(function(e,t){typeof Ne=="object"&&typeof He!="undefined"?He.exports=t():typeof define=="function"&&define.amd?define(t):(e=e||self,e.TinyQueue=t())})(Ne,function(){"use strict";var e=function(r,a){if(r===void 0&&(r=[]),a===void 0&&(a=t),this.data=r,this.length=this.data.length,this.compare=a,this.length>0)for(var n=(this.length>>1)-1;n>=0;n--)this._down(n)};e.prototype.push=function(r){this.data.push(r),this.length++,this._up(this.length-1)},e.prototype.pop=function(){if(this.length!==0){var r=this.data[0],a=this.data.pop();return this.length--,this.length>0&&(this.data[0]=a,this._down(0)),r}},e.prototype.peek=function(){return this.data[0]},e.prototype._up=function(r){for(var a=this,n=a.data,s=a.compare,l=n[r];r>0;){var o=r-1>>1,h=n[o];if(s(l,h)>=0)break;n[r]=h,r=o}n[r]=l},e.prototype._down=function(r){for(var a=this,n=a.data,s=a.compare,l=this.length>>1,o=n[r];r=0)break;n[r]=d,r=h}n[r]=o};function t(i,r){return ir?1:0}return e})});var Xt=R((Dr,Ge)=>{"use strict";var Xe=Ct();Xe.default&&(Xe=Xe.default);Ge.exports=Dt;Ge.exports.default=Dt;function Dt(e,t,i){t=t||1;for(var r,a,n,s,l=0;ln)&&(n=o[0]),(!l||o[1]>s)&&(s=o[1])}var h=n-r,d=s-a,x=Math.min(h,d),c=x/2;if(x===0){var y=[r,a];return y.distance=0,y}for(var b=new Xe(void 0,Ei),g=r;gf.d&&(f=m);for(var w=b.length;b.length;){var p=b.pop();p.d>f.d&&(f=p,i&&console.log("found best %d after %d probes",Math.round(1e4*p.d)/1e4,w)),!(p.max-f.d<=t)&&(c=p.h/2,b.push(new $(p.x-c,p.y-c,c,e)),b.push(new $(p.x+c,p.y-c,c,e)),b.push(new $(p.x-c,p.y+c,c,e)),b.push(new $(p.x+c,p.y+c,c,e)),w+=4)}i&&(console.log("num probes: "+w),console.log("best distance: "+f.d));var v=[f.x,f.y];return v.distance=f.d,v}function Ei(e,t){return t.max-e.max}function $(e,t,i,r){this.x=e,this.y=t,this.h=i,this.d=qi(e,t,r),this.max=this.d+this.h*Math.SQRT2}function qi(e,t,i){for(var r=!1,a=1/0,n=0;nt!=x[1]>t&&e<(x[0]-d[0])*(t-d[1])/(x[1]-d[1])+d[0]&&(r=!r),a=Math.min(a,$i(e,t,d,x))}return a===0?0:(r?1:-1)*Math.sqrt(a)}function Ai(e){for(var t=0,i=0,r=0,a=e[0],n=0,s=a.length,l=s-1;n1?(a=r[0],n=r[1]):o>0&&(a+=s*o,n+=l*o)}return s=e-a,l=t-n,s*s+l*l}});var Rt=R((Rr,Yt)=>{Yt.exports=function(e,t){var i=[],r=[null],a,n,s,l=0,o=0,h=0,d=0,x=0,c=0,y=0,b=0,g=0,u=0,f=0,m=0;if(e.length<2)return[];if(e.length===2)return h=Math.sqrt(Math.pow(e[1].x-e[0].x,2)+Math.pow(e[1].y-e[0].y,2)),[{length:h,beginIndex:0,beginDistance:0,endIndex:2,endDistance:h,angles:[null,null]}];for(d=Math.sqrt(Math.pow(e[1].x-e[0].x,2)+Math.pow(e[1].y-e[0].y,2)),l=1,o=e.length-1;lt&&(i.push({length:h-m,beginDistance:m,beginIndex:f,endIndex:l+1,endDistance:h,angles:r}),f=l,m=h,r=[u]),d=x;return r.push(null),l-f>0&&i.push({length:h-m+x,beginIndex:f,beginDistance:m,endIndex:l+1,endDistance:h+x,angles:r}),i}});var hr={};ni(hr,{CenteredTextSymbolizer:()=>I,CircleSymbolizer:()=>be,FlexSymbolizer:()=>ge,Font:()=>sr,GroupSymbolizer:()=>we,IconSymbolizer:()=>At,LineLabelSymbolizer:()=>ae,LineSymbolizer:()=>C,OffsetTextSymbolizer:()=>H,PMTiles:()=>ce,PolygonLabelSymbolizer:()=>se,PolygonSymbolizer:()=>B,ShieldSymbolizer:()=>Ye,Sprites:()=>lr,Static:()=>Nt,arr:()=>Zi,createPattern:()=>Ui,dark:()=>ne,exp:()=>X,filterFn:()=>Fe,getFont:()=>it,json_style:()=>or,labelRules:()=>he,leafletLayer:()=>rr,light:()=>re,numberFn:()=>Ee,numberOrFn:()=>et,paintRules:()=>oe,widthFn:()=>tt});var Re=V(A());var Se=V(A()),zt=V(ct()),kt=V(wt());var vt=(e,t)=>e*Math.pow(2,t),_t=(e,t)=>vt(e.getUint16(t+1,!0),8)+e.getUint8(t,!0),Xi=(e,t)=>vt(e.getUint32(t+2,!0),16)+e.getUint16(t,!0),Yi=e=>{var t=e.getUint16(0,!0),i=e.getUint16(2,!0),r=e.getUint32(4,!0),a=e.getUint16(8,!0);return{version:i,json_size:r,root_entries:a}},Ft=e=>{let t=new Map;for(var i=0;i>7,s=_t(e,i+1),l=_t(e,i+4),o=Xi(e,i+7),h=e.getUint32(i+13,!0);t.set(a+"_"+s+"_"+l,[o,h,n])}return t},ce=class{constructor(t){J(this,"metadata",t=>new Promise((i,r)=>{this.root.then(a=>{i(a.metadata)})}));J(this,"getLeaf",(t,i)=>new Promise((r,a)=>{this.leaves.has(t)?(this.leaves.get(t)[0]++,r(this.leaves.get(t)[1])):this.outstanding_requests.has(t)?this.outstanding_requests.get(t).push(r):(this.outstanding_requests.set(t,[]),fetch(this.url,{headers:{Range:"bytes="+t+"-"+(t+i-1)}}).then(n=>n.arrayBuffer()).then(n=>{var s=Ft(new DataView(n),i/17);if(this.leaves.size>32){var l=1/0,o=void 0;this.leaves.forEach((h,d)=>{h[0]h(s)),this.outstanding_requests.delete(t)}))}));J(this,"getZxy",(t,i,r)=>{var a=t+"_"+i+"_"+r;return this.root.then(n=>{if(n.dir.has(a)&&n.dir.get(a)[2]==0)return n.dir.get(a);if(t>=7){var s=t-7,l=[7,Math.trunc(i/(1<d.has(a)?d.get(a):null)}}return null})});J(this,"transformRequest",(t,i,r,a)=>{if(t.endsWith(".pmtiles")&&a){var n=r.tileID.canonical,s=n.z+"_"+n.x+"_"+n.y;this.getZxy(n.z,n.x,n.y).then(l=>{l&&a({url:this.url,headers:{Range:"bytes="+l[0]+"-"+(l[0]+l[1]-1)}})})}return{url:t}});J(this,"leafletLayer",t=>{let i=this;var r=L.GridLayer.extend({createTile:function(a,n){var s=document.createElement("img"),l;return i.getZxy(a.z,a.x,a.y).then(o=>{o!==null&&fetch(i.url,{headers:{Range:"bytes="+o[0]+"-"+(o[0]+o[1]-1)}}).then(h=>h.arrayBuffer()).then(h=>{var d=new Blob([h],{type:"image/png"}),x=window.URL.createObjectURL(d);s.src=x,n(l,s)})}),s},_removeTile:function(a){var n=this._tiles[a];!n||(n.el.width=0,n.el.height=0,n.el.deleted=!0,L.DomUtil.remove(n.el),delete this._tiles[a],this.fire("tileunload",{tile:n.el,coords:this._keyToTileCoords(a)}))}});return new r(t)});this.url=t;let i=new AbortController,r=i.signal;this.root=fetch(this.url,{signal:r,headers:{Range:"bytes=0-511999"}}).then(a=>(a.headers.get("Content-Length")!=512e3&&(console.error("Content-Length mismatch indicates byte serving not supported; aborting."),i.abort()),a.arrayBuffer())).then(a=>{let n=Yi(new DataView(a,0,10));var s=new TextDecoder("utf-8");return{metadata:JSON.parse(s.decode(new DataView(a,10,n.json_size))),dir:Ft(new DataView(a,10+n.json_size,17*n.root_entries))}}),this.step=0,this.leaves=new Map,this.outstanding_requests=new Map}};var me;(function(r){r[r.Point=1]="Point",r[r.Line=2]="Line",r[r.Polygon=3]="Polygon"})(me||(me={}));function U(e){return e.x+":"+e.y+":"+e.z}var Ri=(e,t,i)=>{e.pos=t;for(var r=e.readVarint()+e.pos,a=1,n=0,s=0,l=0,o=1/0,h=-1/0,d=1/0,x=-1/0,c=[],y;e.pos>3}if(n--,a===1||a===2)s+=e.readSVarint()*i,l+=e.readSVarint()*i,sh&&(h=s),lx&&(x=l),a===1&&(y&&c.push(y),y=[]),y.push(new Se.default(s,l));else if(a===7)y&&y.push(y[0].clone());else throw new Error("unknown command "+a)}return y&&c.push(y),{geom:c,bbox:{minX:o,minY:d,maxX:h,maxY:x}}};function Mt(e,t){let i=new zt.VectorTile(new kt.default(e)),r=new Map;for(let[a,n]of Object.entries(i.layers)){let s=[],l=n;for(let o=0;os[0]!=t.z?(s[1].abort(),!1):!0);let r=yield this.p.getZxy(t.z,t.x,t.y);if(!r)throw new Error(`Tile ${t.z} ${t.x} ${t.y} not found in archive`);let a=new AbortController;this.controllers.push([t.z,a]);let n=a.signal;return new Promise((s,l)=>{fetch(this.p.url,{headers:{Range:"bytes="+r[0]+"-"+(r[0]+r[1]-1)},signal:n}).then(o=>o.arrayBuffer()).then(o=>{let h=Mt(o,i);s(h)}).catch(o=>{l(o)})})})}},xe=class{constructor(t){this.url=t,this.controllers=[]}get(t,i){return D(this,null,function*(){this.controllers=this.controllers.filter(s=>s[0]!=t.z?(s[1].abort(),!1):!0);let r=this.url.replace("{z}",t.z.toString()).replace("{x}",t.x.toString()).replace("{y}",t.y.toString()),a=new AbortController;this.controllers.push([t.z,a]);let n=a.signal;return new Promise((s,l)=>{fetch(r,{signal:n}).then(o=>o.arrayBuffer()).then(o=>{let h=Mt(o,i);s(h)}).catch(o=>{l(o)})})})}},Ze=6378137,Lt=85.0511287798,Te=Ze*Math.PI,Vi=e=>{let t=Math.PI/180,i=Math.max(Math.min(Lt,e[0]),-Lt),r=Math.sin(i*t);return new Se.default(Ze*e[1]*t,Ze*Math.log((1+r)/(1-r))/2)},pe=class{constructor(t,i){this.source=t,this.cache=new Map,this.inflight=new Map,this.tileSize=i}queryFeatures(t,i,r){let a=Vi([i,t]);var n=new Se.default((a.x+Te)/(Te*2),1-(a.y+Te)/(Te*2));n.x>1&&(n.x=n.x-Math.floor(n.x));let s=n.mult(1<=f.bbox.minX&&f.bbox.maxX>=b.minX&&b.maxY>=f.bbox.minY&&f.bbox.maxY>=b.minY&&d.push(f)}return d}get(t){return D(this,null,function*(){let i=U(t);return new Promise((r,a)=>{let n=this.cache.get(i);if(n)n.used=performance.now(),r(n.data);else{let s=this.inflight.get(i);s?s.push([r,a]):(this.inflight.set(i,[]),this.source.get(t,this.tileSize).then(l=>{this.cache.set(i,{used:performance.now(),data:l});let o=this.inflight.get(i);if(o&&o.forEach(h=>h[0](l)),this.inflight.delete(i),r(l),this.cache.size>=64){let h=1/0,d;this.cache.forEach((x,c)=>{x.used{let o=this.inflight.get(i);o&&o.forEach(h=>h[1](l)),this.inflight.delete(i),a(l)}))}})})}};var W=V(A()),Be=(e,t,i)=>{let r=[];for(let a of e){let n=[];for(let s of a)n.push(s.clone().mult(t).add(i));r.push(n)}return r},ye=class{constructor(t,i,r){this.tileCache=t,this.maxDataLevel=i,this.levelDiff=r}dataTilesForBounds(t,i){let r=[];var a=1,n=this.tileCache.tileSize;if(tthis.tileCache.get(n.data_tile)))).map((n,s)=>{let l=r[s];return{data:n,z:t,data_tile:l.data_tile,scale:l.scale,dim:l.dim,origin:l.origin}})})}getDisplayTile(t){return D(this,null,function*(){let i=this.dataTileForDisplayTile(t);return{data:yield this.tileCache.get(i.data_tile),z:t.z,data_tile:i.data_tile,scale:i.scale,origin:i.origin,dim:i.dim}})}queryFeatures(t,i,r){return this.tileCache.queryFeatures(t,i,Math.min(r-this.levelDiff,this.maxDataLevel))}};var St=V(A());function Pe(e,t,i,r,a,n,s,l){let o=performance.now();e.save(),e.miterLimit=2;for(var h of t){let g=h.origin,u=h.scale;e.save(),s&&(e.beginPath(),e.rect(g.x-n.x,g.y-n.y,h.dim,h.dim),e.clip()),e.translate(g.x-n.x,g.y-n.y);for(var d of r)if(!(d.minzoom&&h.zd.maxzoom)){var x=h.data.get(d.dataLayer);if(x!==void 0){d.symbolizer.before(e,h.z);for(var c of x){let f=c.geom,m=c.bbox;if(m.maxX*u+g.xa.maxX||m.minY*u+g.y>a.maxY||m.maxY*u+g.y{let r=256,a=t/r,n=Math.floor(i.minX/r),s=Math.floor(i.minY/r),l=Math.floor(i.maxX/r),o=Math.floor(i.maxY/r),h=Math.log2(a),d=[];for(let x=n;x<=l;x++)for(let c=s;c<=o;c++)d.push({display:U({z:e,x,y:c}),key:U({z:e-h,x:Math.floor(x/a),y:Math.floor(c/a)})});return d},Pt=class{constructor(){this.tree=new Bt.default,this.current=new Map}has(t){return this.current.has(t)}size(){return this.current.size}keys(){return this.current.keys()}searchBbox(t,i){let r=new Set;for(let a of this.tree.search(t))a.indexed_label.order<=i&&r.add(a.indexed_label);return r}searchLabel(t,i){let r=new Set;for(let a of t.bboxes)for(let n of this.tree.search(a))n.indexed_label.order<=i&&r.add(n.indexed_label);return r}bboxCollides(t,i){for(let r of this.tree.search(t))if(r.indexed_label.order<=i)return!0;return!1}labelCollides(t,i){for(let r of t.bboxes)for(let a of this.tree.search(r))if(a.indexed_label.order<=i)return!0;return!1}insert(t,i,r){let a={anchor:t.anchor,bboxes:t.bboxes,draw:t.draw,order:i,tileKey:r},n=this.current.get(r);if(n)n.add(a);else{let l=new Set;l.add(a),this.current.set(r,l)}for(let l of t.bboxes){var s=l;s.indexed_label=a,this.tree.insert(s)}}prune(t){let i=this.current.get(t);if(!i)return;let r=[];for(let a of this.tree.all())i.has(a.indexed_label)&&r.push(a);r.forEach(a=>{this.tree.remove(a)}),this.current.delete(t)}removeLabel(t){let i=[];for(let a of this.tree.all())t==a.indexed_label&&i.push(a);i.forEach(a=>{this.tree.remove(a)});let r=this.current.get(t.tileKey);r&&r.delete(t)}},Ce=class{constructor(t,i,r,a){this.index=new Pt,this.z=t,this.scratch=i,this.labelRules=r,this.callback=a}layout(t){let i=performance.now(),r=U(t.data_tile),a=new Set;for(let[s,l]of this.labelRules.entries()){if(l.visible==!1||l.minzoom&&this.zl.maxzoom)continue;let o=t.data.get(l.dataLayer);if(o===void 0)continue;let h=o;l.sort&&h.sort((x,c)=>l.sort?l.sort(x.properties,c.properties):0);let d={index:this.index,zoom:this.z,scratch:this.scratch,order:s};for(let x of h){if(l.filter&&!l.filter(x.properties))continue;let c=Be(x.geom,t.scale,t.origin),y=l.symbolizer.place(d,c,x);if(!!y)for(let b of y){var n=!1;if(this.index.labelCollides(b,1/0)){if(!this.index.labelCollides(b,s)){let g=this.index.searchLabel(b,1/0);for(let u of g){this.index.removeLabel(u);for(let f of u.bboxes)this.findInvalidatedTiles(a,t.dim,f,r)}this.index.insert(b,s,r),n=!0}}else this.index.insert(b,s,r),n=!0;if(n)for(let g of b.bboxes)(g.maxX>t.origin.x+t.dim||g.minXt.origin.y+t.dim)&&this.findInvalidatedTiles(a,t.dim,g,r)}}}return a.size>0&&this.callback&&this.callback(a),performance.now()-i}findInvalidatedTiles(t,i,r,a){let n=Ii(this.z,i,r);for(let s of n)s.key!=a&&this.index.has(s.key)&&t.add(s.display)}pruneCache(t){if(this.index.size()>16){let i,r=0;for(let a of this.index.keys()){let n=a.split(":"),s=Math.sqrt(Math.pow(+n[0]-t.data_tile.x,2)+Math.pow(+n[1]-t.data_tile.y,2));s>r&&(r=s,i=a)}i&&this.index.prune(i)}}add(t){let i=U(t.data_tile);if(this.index.has(i))return 0;{let r=this.layout(t);return this.pruneCache(t),r}}},De=class{constructor(t,i,r){this.labelers=new Map,this.scratch=t,this.labelRules=i,this.callback=r}add(t){var i=this.labelers.get(t.z);return i||(i=new Ce(t.z,this.scratch,this.labelRules,this.callback),this.labelers.set(t.z,i)),i.add(t)}getIndex(t){let i=this.labelers.get(t);if(i)return i.index}};var re={earth:"#FFFBF6",glacier:"#ffffff",residential:"#F4F4F8",hospital:"#FFF6F6",cemetery:"#EFF2EE",school:"#F7F6FF",industrial:"#FFF9EF",wood:"#F4F9EF",grass:"#EBF9E3",park:"#E5F9D5",water:"#B7DFF2",sand:"#ebebeb",buildings:"#F2EDE8",highwayCasing:"#FFC3C3",majorRoadCasing:"#FFB9B9",mediumRoadCasing:"#FFCE8E",minorRoadCasing:"#cccccc",highway:"#FFCEBB",majorRoad:"#FFE4B3",mediumRoad:"#FFF2C8",minorRoad:"#ffffff",boundaries:"#9e9e9e",mask:"#dddddd",countryLabel:"#aaaaaa",cityLabel:"#6C6C6C",stateLabel:"#999999",neighbourhoodLabel:"#888888",landuseLabel:"#898989",waterLabel:"#41ABDC",naturalLabel:"#4B8F14",roadsLabel:"#888888",poisLabel:"#606060"};var ne={earth:"#151515",glacier:"#1c1c1c",residential:"#252B2F",hospital:"#3E2C2C",cemetery:"#36483D",school:"#2C3440",industrial:"#33312C",wood:"#3A3E38",grass:"#4E604D",park:"#2C4034",water:"#4D5B73",sand:"#777777",buildings:"#464545",highwayCasing:"#000000",majorRoadCasing:"#1C1B1B",mediumRoadCasing:"#3E3E3E",minorRoadCasing:"#000000",highway:"#5B5B5B",majorRoad:"#595959",mediumRoad:"#4F4F4F",minorRoad:"#393939",boundaries:"#666666",mask:"#dddddd",countryLabel:"#ffffff",cityLabel:"#FFFFFF",stateLabel:"#ffffff",neighbourhoodLabel:"#FDFDFD",landuseLabel:"#DDDDDD",waterLabel:"#707E95",naturalLabel:"#4c4c4c",roadsLabel:"#C4C4C4",poisLabel:"#959393"};var q=V(A());var qt=V(Xt());function Qe(e){if(e.length<=15)return[e];let t=e.lastIndexOf(" ",14),i=e.indexOf(" ",14);if(t==-1&&i==-1)return[e];let r,a;return i==-1||t>=0&&14-t=t&&l.length>a&&(a=l.length,i=n[l.beginIndex],r=n[l.endIndex-1])}if(!!i&&!(i.x==r.x&&i.y==r.y))return{start:i,end:r}}function Et(e,t,i,r){let a=t.x-e.x,n=t.y-e.y,s=Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2)),l=[];for(var o=r;o{let r=document.createElement("canvas"),a=r.getContext("2d");return r.width=e,r.height=t,i(r,a),r},B=class{constructor(t){this.fill=t.fill||"#000000",this.opacity=t.opacity||1,this.pattern=t.pattern}before(t){this.pattern?t.fillStyle=t.createPattern(this.pattern,"repeat"):t.fillStyle=this.fill,t.globalAlpha=this.opacity}draw(t,i,r){t.beginPath();for(var a of i)for(var n=0;n{let r=i-e;return r>=0&&r{if(i<=t[0][0])return t[0][1];if(i>=t[t.length-1][0])return t[t.length-1][1];let r=0;for(;t[r+1][0]{o.globalAlpha=1;let h=this.sprites.get(this.name);o.drawImage(h.canvas,h.x,h.y,h.w,h.h,-8,-8,h.w,h.h)}}]}},be=class{constructor(t){this.radius=t.radius||3,this.fill=t.fill||"black",this.stroke=t.stroke||"white",this.width=t.width||0}place(t,i,r){let a=i[0],n=new q.default(i[0][0].x,i[0][0].y),s={minX:n.x-this.radius,minY:n.y-this.radius,maxX:n.x+this.radius,maxY:n.y+this.radius};return[{anchor:n,bboxes:[s],draw:o=>{o.globalAlpha=1,this.width>0&&(o.fillStyle=this.stroke,o.beginPath(),o.arc(0,0,this.radius+this.width,0,2*Math.PI),o.fill()),o.fillStyle=this.fill,o.beginPath(),o.arc(0,0,this.radius,0,2*Math.PI),o.fill()}}]}},Ye=class{constructor(t){this.font=new N(t),this.text=new O(t),this.fill=t.fill||"black",this.stroke=t.stroke||"white",this.background=t.background||"white",this.padding=t.padding||0}place(t,i,r){let a=this.text.str(t.zoom,r.properties);if(!a)return;let n=this.font.str(t.zoom,r.properties);t.scratch.font=n;let s=t.scratch.measureText(a),l=s.width,o=s.actualBoundingBoxAscent,h=s.actualBoundingBoxDescent,d=i[0],x=new q.default(i[0][0].x,i[0][0].y),c=this.padding,y={minX:x.x-l/2-c,minY:x.y-o-c,maxX:x.x+l/2+c,maxY:x.y+h+c};return[{anchor:x,bboxes:[y],draw:g=>{g.globalAlpha=1,g.fillStyle=this.background,g.fillRect(-l/2-c,-o-c,l+2*c,o+h+2*c),g.fillStyle=this.fill,g.font=n,g.fillText(a,-l/2,0)}}]}},ge=class{constructor(t,i){this.list=t}place(t,i,r){var a=this.list[0].place(t,i,r);if(!a)return;var n=a[0];let s=n.anchor,l=n.bboxes[0],o=l.maxY-l.minY,h=[{draw:n.draw,translate:{x:0,y:0}}],d=[[{x:i[0][0].x,y:i[0][0].y+o}]];for(let c=1;c{for(let y of h)c.save(),c.translate(y.translate.x,y.translate.y),y.draw(c),c.restore()}}]}},$t=(e,t)=>({minX:Math.min(e.minX,t.minX),minY:Math.min(e.minY,t.minY),maxX:Math.max(e.maxX,t.maxX),maxY:Math.max(e.maxY,t.maxY)}),we=class{constructor(t){this.list=t}place(t,i,r){let a=this.list[0];if(!a)return;var n=a.place(t,i,r);if(!n)return;var s=n[0];let l=s.anchor,o=s.bboxes[0],h=[s.draw];for(let x=1;x{h.forEach(c=>c(x))}}]}},I=class{constructor(t){this.font=new N(t),this.text=new O(t),this.fill=t.fill,this.stroke=t.stroke||"black",this.width=t.width||0}place(t,i,r){if(r.geomType!==me.Point)return;let a=this.text.str(t.zoom,r.properties);if(!a)return;let n=this.font.str(t.zoom,r.properties);t.scratch.font=n;let s=t.scratch.measureText(a),l=s.width,o=s.actualBoundingBoxAscent,h=s.actualBoundingBoxDescent,d=new q.default(i[0][0].x,i[0][0].y),x={minX:d.x-l/2,minY:d.y-o,maxX:d.x+l/2,maxY:d.y+h},c=-l/2;return[{anchor:d,bboxes:[x],draw:b=>{b.globalAlpha=1,b.font=n,this.width&&(b.lineWidth=this.width*2,b.strokeStyle=this.stroke,b.strokeText(a,c,0)),b.fillStyle=this.fill,b.fillText(a,c,0)}}]}},H=class{constructor(t){this.font=new N(t),this.text=new O(t),this.fill=t.fill,this.stroke=t.stroke||"black",this.width=t.width||0,this.offset=t.offset||0}place(t,i,r){if(r.geomType!==me.Point)return;let a=this.text.str(t.zoom,r.properties);if(!a)return;let n=this.font.str(t.zoom,r.properties);t.scratch.font=n;let s=t.scratch.measureText(a),l=s.width,o=s.actualBoundingBoxAscent,h=s.actualBoundingBoxDescent,d=new q.default(i[0][0].x,i[0][0].y),x=this.offset;var c=new q.default(x,-x);let y=g=>{g.globalAlpha=1,g.font=n,this.width&&(g.lineWidth=this.width*2,g.strokeStyle=this.stroke,g.strokeText(a,c.x,c.y)),g.fillStyle=this.fill,g.fillText(a,c.x,c.y)};var b={minX:d.x+c.x,minY:d.y-o+c.y,maxX:d.x+l+c.x,maxY:d.y+h+c.y};if(!t.index.bboxCollides(b,t.order))return[{anchor:d,bboxes:[b],draw:y}];if(c=new q.default(-l-x,-x),b={minX:d.x+c.x,minY:d.y-o+c.y,maxX:d.x+l+c.x,maxY:d.y+h+c.y},!t.index.bboxCollides(b,t.order))return[{anchor:d,bboxes:[b],draw:y}]}},ae=class{constructor(t){this.font=new N(t),this.text=new O(t),this.fill=t.fill||"black",this.stroke=t.stroke||"black",this.width=t.width||0,this.offset=t.offset||0}place(t,i,r){let a=this.text.str(t.zoom,r.properties);if(!a||a.length>20)return;let n=r.bbox;if((n.maxY-n.minY)*(n.maxX-n.minX)<400)return;let l=this.font.str(t.zoom,r.properties);t.scratch.font=l;let h=t.scratch.measureText(a).width,d=It(i,h);if(!d)return;let x=d.end.x-d.start.x,c=d.end.y-d.start.y,y=8,g=Et(d.start,d.end,h,8).map(f=>({minX:f.x-y,minY:f.y-y,maxX:f.x+y,maxY:f.y+y})),u=f=>{f.globalAlpha=1,f.rotate(Math.atan2(c,x)),x<0&&(f.scale(-1,-1),f.translate(-h,0)),f.translate(0,-this.offset),f.font=l,this.width&&(f.lineWidth=this.width,f.strokeStyle=this.stroke,f.strokeText(a,0,0)),f.fillStyle=this.fill,f.fillText(a,0,0)};return[{anchor:d.start,bboxes:g,draw:u}]}},se=class{constructor(t){this.font=new N(t),this.text=new O(t),this.fill=t.fill||"black",this.stroke=t.stroke||"black",this.width=t.width||0}place(t,i,r){let a=r.bbox;if((a.maxY-a.minY)*(a.maxX-a.minX)<2e4)return;let s=this.text.str(t.zoom,r.properties);if(!s)return;let l=i[0],o=(0,qt.default)([l.map(p=>[p.x,p.y])]),h=new q.default(o[0],o[1]),d=this.font.str(t.zoom,r.properties);t.scratch.font=d;let x=Qe(s),c=14;var y,b=0;for(let p of x)p.length>b&&(b=p.length,y=p);let g=t.scratch.measureText(y),u=g.width,f={minX:h.x-u/2,minY:h.y-g.actualBoundingBoxAscent,maxX:h.x+u/2,maxY:h.y+(c*x.length-g.actualBoundingBoxAscent)},m=this.fill;return[{anchor:h,bboxes:[f],draw:p=>{p.globalAlpha=1,p.font=d;var v=0;for(let _ of x)this.width&&(p.lineWidth=this.width,p.strokeStyle=this.stroke,p.strokeText(_,-u/2,v)),p.fillStyle=m,p.fillText(_,-u/2,v),v+=c}}]}};function ve(e,t,i){return Math.min(Math.max(e,i),t)}var le=class extends Error{constructor(t){super(`Failed to parse color: "${t}"`)}};function Oi(e){if(typeof e!="string")throw new le(e);if(e.trim().toLowerCase()==="transparent")return[0,0,0,0];let t=e.trim();t=Ki.test(e)?function(s){let l=s.toLowerCase().trim(),o=Ni[function(h){let d=5381,x=h.length;for(;x;)d=33*d^h.charCodeAt(--x);return(d>>>0)%2341}(l)];if(!o)throw new le(s);return`#${o}`}(e):e;let i=Hi.exec(t);if(i){let s=Array.from(i).slice(1);return[...s.slice(0,3).map(l=>parseInt(_e(l,2),16)),parseInt(_e(s[3]||"f",2),16)/255]}let r=Gi.exec(t);if(r){let s=Array.from(r).slice(1);return[...s.slice(0,3).map(l=>parseInt(l,16)),parseInt(s[3]||"ff",16)/255]}let a=Qi.exec(t);if(a){let s=Array.from(a).slice(1);return[...s.slice(0,3).map(l=>parseInt(l,10)),parseFloat(s[3]||"1")]}let n=Ji.exec(t);if(n){let[s,l,o,h]=Array.from(n).slice(1).map(parseFloat);if(ve(0,100,l)!==l)throw new le(e);if(ve(0,100,o)!==o)throw new le(e);return[...er(s,l,o),h||1]}throw new le(e)}var jt=e=>parseInt(e.replace(/_/g,""),36),Ni="1q29ehhb 1n09sgk7 1kl1ekf_ _yl4zsno 16z9eiv3 1p29lhp8 _bd9zg04 17u0____ _iw9zhe5 _to73___ _r45e31e _7l6g016 _jh8ouiv _zn3qba8 1jy4zshs 11u87k0u 1ro9yvyo 1aj3xael 1gz9zjz0 _3w8l4xo 1bf1ekf_ _ke3v___ _4rrkb__ 13j776yz _646mbhl _nrjr4__ _le6mbhl 1n37ehkb _m75f91n _qj3bzfz 1939yygw 11i5z6x8 _1k5f8xs 1509441m 15t5lwgf _ae2th1n _tg1ugcv 1lp1ugcv 16e14up_ _h55rw7n _ny9yavn _7a11xb_ 1ih442g9 _pv442g9 1mv16xof 14e6y7tu 1oo9zkds 17d1cisi _4v9y70f _y98m8kc 1019pq0v 12o9zda8 _348j4f4 1et50i2o _8epa8__ _ts6senj 1o350i2o 1mi9eiuo 1259yrp0 1ln80gnw _632xcoy 1cn9zldc _f29edu4 1n490c8q _9f9ziet 1b94vk74 _m49zkct 1kz6s73a 1eu9dtog _q58s1rz 1dy9sjiq __u89jo3 _aj5nkwg _ld89jo3 13h9z6wx _qa9z2ii _l119xgq _bs5arju 1hj4nwk9 1qt4nwk9 1ge6wau6 14j9zlcw 11p1edc_ _ms1zcxe _439shk6 _jt9y70f _754zsow 1la40eju _oq5p___ _x279qkz 1fa5r3rv _yd2d9ip _424tcku _8y1di2_ _zi2uabw _yy7rn9h 12yz980_ __39ljp6 1b59zg0x _n39zfzp 1fy9zest _b33k___ _hp9wq92 1il50hz4 _io472ub _lj9z3eo 19z9ykg0 _8t8iu3a 12b9bl4a 1ak5yw0o _896v4ku _tb8k8lv _s59zi6t _c09ze0p 1lg80oqn 1id9z8wb _238nba5 1kq6wgdi _154zssg _tn3zk49 _da9y6tc 1sg7cv4f _r12jvtt 1gq5fmkz 1cs9rvci _lp9jn1c _xw1tdnb 13f9zje6 16f6973h _vo7ir40 _bt5arjf _rc45e4t _hr4e100 10v4e100 _hc9zke2 _w91egv_ _sj2r1kk 13c87yx8 _vqpds__ _ni8ggk8 _tj9yqfb 1ia2j4r4 _7x9b10u 1fc9ld4j 1eq9zldr _5j9lhpx _ez9zl6o _md61fzm".split(" ").reduce((e,t)=>{let i=jt(t.substring(0,3)),r=jt(t.substring(3)).toString(16),a="";for(let n=0;n<6-r.length;n++)a+="0";return e[i]=`${a}${r}`,e},{}),_e=(e,t)=>Array.from(Array(t)).map(()=>e).join(""),Hi=new RegExp(`^#${_e("([a-f0-9])",3)}([a-f0-9])?$`,"i"),Gi=new RegExp(`^#${_e("([a-f0-9]{2})",3)}([a-f0-9]{2})?$`,"i"),Qi=new RegExp(`^rgba?\\(\\s*(\\d+)\\s*${_e(",\\s*(\\d+)\\s*",2)}(?:,\\s*([\\d.]+))?\\s*\\)$`,"i"),Ji=/^hsla?\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%(?:\s*,\s*([\d.]+))?\s*\)$/i,Ki=/^[a-z]+$/i,Ut=e=>Math.round(255*e),er=(e,t,i)=>{let r=i/100;if(t===0)return[r,r,r].map(Ut);let a=(e%360+360)%360/60,n=(1-Math.abs(2*r-1))*(t/100),s=n*(1-Math.abs(a%2-1)),l=0,o=0,h=0;a>=0&&a<1?(l=n,o=s):a>=1&&a<2?(l=s,o=n):a>=2&&a<3?(o=n,h=s):a>=3&&a<4?(o=s,h=n):a>=4&&a<5?(l=s,h=n):a>=5&&a<6&&(l=n,h=s);let d=r-n/2;return[l+d,o+d,h+d].map(Ut)};function Je(e){let[t,i,r,a]=Oi(e).map((h,d)=>d===3?h:h/255),n=Math.max(t,i,r),s=Math.min(t,i,r),l=(n+s)/2;if(n===s)return[0,0,l,a];let o=n-s;return[60*(t===n?(i-r)/o+(i.5?o/(2-n-s):o/(n+s),l,a]}function Zt(e,t,i,r){return`hsla(${(e%360).toFixed()}, ${ve(0,100,100*t).toFixed()}%, ${ve(0,100,100*i).toFixed()}%, ${parseFloat(ve(0,1,r).toFixed(3))})`}var Wt=(e,t)=>{let i=Je(t),r=at({},e);for(let[a,n]of Object.entries(e)){let s=Je(n);r[a]=Zt(i[0],i[1],s[2],s[3])}return r},oe=(e,t)=>(t&&(e=Wt(e,t)),[{dataLayer:"earth",symbolizer:new B({fill:e.earth})},{dataLayer:"natural",symbolizer:new B({fill:e.glacier}),filter:i=>i.natural=="glacier"},{dataLayer:"landuse",symbolizer:new B({fill:e.residential}),filter:i=>i.landuse=="residential"||i.place=="neighbourhood"},{dataLayer:"landuse",symbolizer:new B({fill:e.hospital}),filter:i=>i.amenity=="hospital"},{dataLayer:"landuse",symbolizer:new B({fill:e.cemetery}),filter:i=>i.landuse=="cemetery"},{dataLayer:"landuse",symbolizer:new B({fill:e.school}),filter:i=>i.amenity=="school"||i.amenity=="kindergarten"||i.amenity=="university"||i.amenity=="college"},{dataLayer:"landuse",symbolizer:new B({fill:e.industrial}),filter:i=>i.landuse=="industrial"},{dataLayer:"natural",symbolizer:new B({fill:e.wood}),filter:i=>i.natural=="wood"},{dataLayer:"landuse",symbolizer:new B({fill:e.grass}),filter:i=>i.landuse=="grass"},{dataLayer:"landuse",symbolizer:new B({fill:e.park}),filter:i=>i.leisure=="park"},{dataLayer:"water",symbolizer:new B({fill:e.water})},{dataLayer:"natural",symbolizer:new B({fill:e.sand}),filter:i=>i.natural=="sand"},{dataLayer:"buildings",symbolizer:new B({fill:e.buildings})},{dataLayer:"roads",symbolizer:new C({color:e.highwayCasing,width:X(1.4,[[5,1.5],[11,4],[16,9],[20,40]])}),filter:i=>i["pmap:kind"]=="highway"},{dataLayer:"roads",symbolizer:new C({color:e.majorRoadCasing,width:X(1.4,[[9,3],[12,4],[17,8],[20,22]])}),filter:i=>i["pmap:kind"]=="major_road"},{dataLayer:"roads",symbolizer:new C({color:e.mediumRoadCasing,width:X(1.4,[[13,3],[17,6],[20,18]])}),filter:i=>i["pmap:kind"]=="medium_road"},{dataLayer:"roads",symbolizer:new C({color:e.minorRoadCasing,width:X(1.4,[[14,2],[17,5],[20,15]])}),filter:i=>i["pmap:kind"]=="minor_road"},{dataLayer:"roads",symbolizer:new C({color:e.minorRoad,width:X(1.4,[[14,1],[17,3],[20,13]])}),filter:i=>i["pmap:kind"]=="minor_road"},{dataLayer:"roads",symbolizer:new C({color:e.mediumRoad,width:X(1.4,[[13,2],[17,4],[20,15]])}),filter:i=>i["pmap:kind"]=="medium_road"},{dataLayer:"roads",symbolizer:new C({color:e.majorRoad,width:X(1.4,[[9,2],[12,3],[17,6],[20,20]])}),filter:i=>i["pmap:kind"]=="major_road"},{dataLayer:"roads",symbolizer:new C({color:e.highway,width:X(1.4,[[5,.5],[11,2.5],[16,7],[20,30]])}),filter:i=>i["pmap:kind"]=="highway"},{dataLayer:"boundaries",symbolizer:new C({color:e.boundaries,width:2,opacity:.4})},{dataLayer:"mask",symbolizer:new B({fill:e.mask})}]),he=(e,t,i,r)=>{t&&(e=Wt(e,t));var a=["name"];i&&(a=i);let n=(s,l)=>r?s instanceof H?new ge([s,new H({fill:l,properties:r})],{}):new ge([s,new I({fill:l,properties:r})],{}):s;return[{dataLayer:"places",symbolizer:n(new I({properties:a,fill:e.countryLabel,font:(s,l)=>s<6?"200 14px sans-serif":"200 20px sans-serif",textTransform:"uppercase"}),e.countryLabel),filter:s=>s["pmap:kind"]=="country"},{dataLayer:"places",symbolizer:n(new I({properties:a,fill:e.stateLabel,font:"300 16px sans-serif"}),e.stateLabel),filter:s=>s["pmap:kind"]=="state"},{id:"cities_high",dataLayer:"places",filter:s=>s["pmap:kind"]=="city",minzoom:7,symbolizer:n(new I({properties:a,fill:e.cityLabel,font:(s,l)=>l["pmap:rank"]==1?s>8?"600 20px sans-serif":"600 12px sans-serif":s>8?"600 16px sans-serif":"600 10px sans-serif"}),e.cityLabel),sort:(s,l)=>s["pmap:rank"]-l["pmap:rank"]},{id:"cities_low",dataLayer:"places",filter:s=>s["pmap:kind"]=="city",maxzoom:6,symbolizer:new we([new be({radius:2,fill:e.cityLabel}),n(new H({properties:a,fill:e.cityLabel,offset:2,font:(s,l)=>l["pmap:rank"]==1?s>8?"600 20px sans-serif":"600 12px sans-serif":s>8?"600 16px sans-serif":"600 10px sans-serif"}),e.cityLabel)]),sort:(s,l)=>s["pmap:rank"]-l["pmap:rank"]},{id:"neighbourhood",dataLayer:"places",symbolizer:n(new I({properties:a,fill:e.neighbourhoodLabel,font:"500 10px sans-serif",textTransform:"uppercase"}),e.neighbourhoodLabel),filter:s=>s["pmap:kind"]=="neighbourhood"},{dataLayer:"landuse",symbolizer:n(new se({properties:a,fill:e.landuseLabel,font:"300 12px sans-serif"}),e.landuseLabel)},{dataLayer:"water",symbolizer:n(new se({properties:a,fill:e.waterLabel,font:"italic 600 12px sans-serif"}),e.waterLabel)},{dataLayer:"natural",symbolizer:n(new se({properties:a,fill:e.naturalLabel,font:"italic 300 12px sans-serif"}),e.naturalLabel)},{dataLayer:"roads",symbolizer:n(new ae({properties:a,fill:e.roadsLabel,font:"500 12px sans-serif"}),e.roadsLabel),minzoom:12},{dataLayer:"roads",symbolizer:new Ye({properties:["ref"],font:"600 9px sans-serif",background:e.highway,padding:2,fill:e.neighbourhoodLabel}),filter:s=>s["pmap:kind"]=="highway"},{dataLayer:"pois",symbolizer:new we([new be({radius:2,fill:e.poisLabel}),n(new H({properties:a,fill:e.poisLabel,offset:2,font:"300 10px sans-serif"}),e.poisLabel)])}]};var Ke=6378137,Ot=85.0511287798,Ve=Ke*Math.PI,tr=e=>{let t=Math.PI/180,i=Math.max(Math.min(Ot,e[0]),-Ot),r=Math.sin(i*t);return new Re.default(Ke*e[1]*t,Ke*Math.log((1+r)/(1-r))/2)},Nt=class{constructor(t){let i=t.dark?ne:re;this.paint_rules=t.paint_rules||oe(i,t.shade),this.label_rules=t.label_rules||he(i,t.shade,t.language1,t.language2);let r;t.url.url?r=new Z(t.url):t.url.endsWith(".pmtiles")?r=new Z(t.url):r=new xe(t.url);let a=new pe(r,1024);this.view=new ye(a,14,2),this.debug=t.debug||!1}drawContext(t,i,r,a,n){return D(this,null,function*(){let s=tr(a),o=new Re.default((s.x+Ve)/(Ve*2),1-(s.y+Ve)/(Ve*2)).clone().mult((1<new Promise((t,i)=>{setTimeout(()=>{t()},e)}),rr=e=>{class t extends L.GridLayer{constructor(r){r.noWrap&&!r.bounds&&(r.bounds=[[-90,-180],[90,180]]),r.attribution||(r.attribution='Protomaps \xA9 OpenStreetMap'),super(r);let a=r.dark?ne:re;this.paint_rules=r.paint_rules||oe(a,r.shade),this.label_rules=r.label_rules||he(a,r.shade,r.language1,r.language2),this.lastRequestedZ=void 0;let n;r.url.url?n=new Z(r.url):r.url.endsWith(".pmtiles")?n=new Z(r.url):n=new xe(r.url),this.tasks=r.tasks||[];let s=new pe(n,1024);this.view=new ye(s,14,2),this.debug=r.debug;let l=document.createElement("canvas").getContext("2d");this.scratch=l,this.onTilesInvalidated=o=>{o.forEach(h=>{this.rerenderTile(h)})},this.labelers=new De(this.scratch,this.label_rules,this.onTilesInvalidated),this.tile_size=256*window.devicePixelRatio,this.pool=new Gt(r.lang)}setDefaultStyle(r,a,n,s){let l=r?ne:re;this.paint_rules=oe(l,a),this.label_rules=he(l,a,n,s)}renderTile(r,a,n,s=()=>{}){return D(this,null,function*(){this.lastRequestedZ=r.z;var l;try{l=yield this.view.getDisplayTile(r)}catch(p){if(p.name=="AbortError")return;throw p}if(a.key!=n||this.lastRequestedZ!==r.z||(yield Promise.allSettled(this.tasks),a.key!=n)||this.lastRequestedZ!==r.z)return;let o=yield this.labelers.add(l);if(a.key!=n||this.lastRequestedZ!==r.z)return;let h=this.labelers.getIndex(l.z);if(!this._map)return;let d=this._map.getCenter().wrap(),x=this._getTiledPixelBounds(d),c=this._pxBoundsToTileRange(x),y=c.getCenter(),b=r.distanceTo(y)*5;if(yield ir(b),a.key!=n||this.lastRequestedZ!==r.z)return;let g=16,u={minX:256*r.x-g,minY:256*r.y-g,maxX:256*(r.x+1)+g,maxY:256*(r.y+1)+g},f=new Ht.default(256*r.x,256*r.y),m=a.getContext("2d");m.setTransform(this.tile_size/256,0,0,this.tile_size/256,0,0),m.clearRect(0,0,256,256);let w=Pe(m,[l],h,this.paint_rules,u,f,!1,this.debug);if(this.debug){let p=l.data_tile;m.save(),m.fillStyle=this.debug,m.font="600 12px sans-serif",m.fillText(r.z+" "+r.x+" "+r.y,4,14),m.font="200 12px sans-serif",m.fillText(p.z+" "+p.x+" "+p.y,4,28),m.font="600 10px sans-serif",w>8&&m.fillText(w.toFixed()+" ms paint",4,42),o>8&&m.fillText(o.toFixed()+" ms layout",4,56),m.strokeStyle=this.debug,m.lineWidth=r.x/4===p.x?1.5:.5,m.beginPath(),m.moveTo(0,0),m.lineTo(0,256),m.stroke(),m.lineWidth=r.y/4===p.y?1.5:.5,m.beginPath(),m.moveTo(0,0),m.lineTo(256,0),m.stroke(),m.restore()}s()})}rerenderTile(r){for(let a in this._tiles){let n=this._wrapCoords(this._keyToTileCoords(a));r===this._tileCoordsToKey(n)&&this.renderTile(n,this._tiles[a].el,r)}}clearLayout(){this.labelers=new De(this.scratch,this.label_rules,this.onTilesInvalidated)}rerenderTiles(){for(let r in this._tiles){let a=this._wrapCoords(this._keyToTileCoords(r)),n=this._tileCoordsToKey(a);this.renderTile(a,this._tiles[r].el,n)}}createTile(r,a){let n=this.pool.get(this.tile_size),s=this._tileCoordsToKey(r);return n.key=s,this.renderTile(r,n,s,()=>{a(null,n)}),n}_removeTile(r){let a=this._tiles[r];!a||(a.el.removed=!0,a.el.key=void 0,L.DomUtil.remove(a.el),this.pool.put(a.el),delete this._tiles[r],this.fire("tileunload",{tile:a.el,coords:this._keyToTileCoords(r)}))}queryFeatures(r,a){return this.view.queryFeatures(r,a,this._map.getZoom())}}return new t(e)};var nr=e=>{let t=0,i=0;for(let l of e)t+=l.w*l.h,i=Math.max(i,l.w);e.sort((l,o)=>o.h-l.h);let r=Math.max(Math.ceil(Math.sqrt(t/.95)),i),a=[{x:0,y:0,w:r,h:1/0}],n=0,s=0;for(let l of e)for(let o=a.length-1;o>=0;o--){let h=a[o];if(!(l.w>h.w||l.h>h.h)){if(l.x=h.x,l.y=h.y,s=Math.max(s,l.y+l.h),n=Math.max(n,l.x+l.w),l.w===h.w&&l.h===h.h){let d=a.pop();onew Promise((t,i)=>{let r=new Image;r.onload=()=>t(r),r.onerror=()=>i("Invalid SVG"),r.src=e}),ar=` +var protomaps=(()=>{var bi=Object.create;var Ce=Object.defineProperty;var wi=Object.getOwnPropertyDescriptor;var vi=Object.getOwnPropertyNames,Gt=Object.getOwnPropertySymbols,_i=Object.getPrototypeOf,Qt=Object.prototype.hasOwnProperty,zi=Object.prototype.propertyIsEnumerable;var er=(t,e,r)=>e in t?Ce(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,tr=(t,e)=>{for(var r in e||(e={}))Qt.call(e,r)&&er(t,r,e[r]);if(Gt)for(var r of Gt(e))zi.call(e,r)&&er(t,r,e[r]);return t};var rr=t=>Ce(t,"__esModule",{value:!0});var W=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Li=(t,e)=>{rr(t);for(var r in e)Ce(t,r,{get:e[r],enumerable:!0})},Si=(t,e,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of vi(e))!Qt.call(t,i)&&i!=="default"&&Ce(t,i,{get:()=>e[i],enumerable:!(r=wi(e,i))||r.enumerable});return t},U=t=>Si(rr(Ce(t!=null?bi(_i(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var E=(t,e,r)=>new Promise((i,n)=>{var a=l=>{try{o(r.next(l))}catch(u){n(u)}},s=l=>{try{o(r.throw(l))}catch(u){n(u)}},o=l=>l.done?i(l.value):Promise.resolve(l.value).then(a,s);o((r=r.apply(t,e)).next())});var Q=W((ma,ir)=>{"use strict";ir.exports=de;function de(t,e){this.x=t,this.y=e}de.prototype={clone:function(){return new de(this.x,this.y)},add:function(t){return this.clone()._add(t)},sub:function(t){return this.clone()._sub(t)},multByPoint:function(t){return this.clone()._multByPoint(t)},divByPoint:function(t){return this.clone()._divByPoint(t)},mult:function(t){return this.clone()._mult(t)},div:function(t){return this.clone()._div(t)},rotate:function(t){return this.clone()._rotate(t)},rotateAround:function(t,e){return this.clone()._rotateAround(t,e)},matMult:function(t){return this.clone()._matMult(t)},unit:function(){return this.clone()._unit()},perp:function(){return this.clone()._perp()},round:function(){return this.clone()._round()},mag:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},equals:function(t){return this.x===t.x&&this.y===t.y},dist:function(t){return Math.sqrt(this.distSqr(t))},distSqr:function(t){var e=t.x-this.x,r=t.y-this.y;return e*e+r*r},angle:function(){return Math.atan2(this.y,this.x)},angleTo:function(t){return Math.atan2(this.y-t.y,this.x-t.x)},angleWith:function(t){return this.angleWithSep(t.x,t.y)},angleWithSep:function(t,e){return Math.atan2(this.x*e-this.y*t,this.x*t+this.y*e)},_matMult:function(t){var e=t[0]*this.x+t[1]*this.y,r=t[2]*this.x+t[3]*this.y;return this.x=e,this.y=r,this},_add:function(t){return this.x+=t.x,this.y+=t.y,this},_sub:function(t){return this.x-=t.x,this.y-=t.y,this},_mult:function(t){return this.x*=t,this.y*=t,this},_div:function(t){return this.x/=t,this.y/=t,this},_multByPoint:function(t){return this.x*=t.x,this.y*=t.y,this},_divByPoint:function(t){return this.x/=t.x,this.y/=t.y,this},_unit:function(){return this._div(this.mag()),this},_perp:function(){var t=this.y;return this.y=this.x,this.x=-t,this},_rotate:function(t){var e=Math.cos(t),r=Math.sin(t),i=e*this.x-r*this.y,n=r*this.x+e*this.y;return this.x=i,this.y=n,this},_rotateAround:function(t,e){var r=Math.cos(t),i=Math.sin(t),n=e.x+r*(this.x-e.x)-i*(this.y-e.y),a=e.y+i*(this.x-e.x)+r*(this.y-e.y);return this.x=n,this.y=a,this},_round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}};de.convert=function(t){return t instanceof de?t:Array.isArray(t)?new de(t[0],t[1]):t}});var pt=W((pa,nr)=>{"use strict";var Fi=Q();nr.exports=me;function me(t,e,r,i,n){this.properties={},this.extent=r,this.type=0,this._pbf=t,this._geometry=-1,this._keys=i,this._values=n,t.readFields(ki,this,e)}function ki(t,e,r){t==1?e.id=r.readVarint():t==2?Mi(r,e):t==3?e.type=r.readVarint():t==4&&(e._geometry=r.pos)}function Mi(t,e){for(var r=t.readVarint()+t.pos;t.pos>3}if(i--,r===1||r===2)n+=t.readSVarint(),a+=t.readSVarint(),r===1&&(o&&s.push(o),o=[]),o.push(new Fi(n,a));else if(r===7)o&&o.push(o[0].clone());else throw new Error("unknown command "+r)}return o&&s.push(o),s};me.prototype.bbox=function(){var t=this._pbf;t.pos=this._geometry;for(var e=t.readVarint()+t.pos,r=1,i=0,n=0,a=0,s=1/0,o=-1/0,l=1/0,u=-1/0;t.pos>3}if(i--,r===1||r===2)n+=t.readSVarint(),a+=t.readSVarint(),no&&(o=n),au&&(u=a);else if(r!==7)throw new Error("unknown command "+r)}return[s,l,o,u]};me.prototype.toGeoJSON=function(t,e,r){var i=this.extent*Math.pow(2,r),n=this.extent*t,a=this.extent*e,s=this.loadGeometry(),o=me.types[this.type],l,u;function f(x){for(var w=0;w{"use strict";var Di=pt();sr.exports=ar;function ar(t,e){this.version=1,this.name=null,this.extent=4096,this.length=0,this._pbf=t,this._keys=[],this._values=[],this._features=[],t.readFields(Pi,this,e),this.length=this._features.length}function Pi(t,e,r){t===15?e.version=r.readVarint():t===1?e.name=r.readString():t===5?e.extent=r.readVarint():t===2?e._features.push(r.pos):t===3?e._keys.push(r.readString()):t===4&&e._values.push(Ai(r))}function Ai(t){for(var e=null,r=t.readVarint()+t.pos;t.pos>3;e=i===1?t.readString():i===2?t.readFloat():i===3?t.readDouble():i===4?t.readVarint64():i===5?t.readVarint():i===6?t.readSVarint():i===7?t.readBoolean():null}return e}ar.prototype.feature=function(t){if(t<0||t>=this._features.length)throw new Error("feature index out of bounds");this._pbf.pos=this._features[t];var e=this._pbf.readVarint()+this._pbf.pos;return new Di(this._pbf,e,this.extent,this._keys,this._values)}});var lr=W((xa,or)=>{"use strict";var Bi=gt();or.exports=Oi;function Oi(t,e){this.layers=t.readFields(Ei,{},e)}function Ei(t,e,r){if(t===3){var i=new Bi(r,r.readVarint()+r.pos);i.length&&(e[i.name]=i)}}});var ur=W((ya,Je)=>{Je.exports.VectorTile=lr();Je.exports.VectorTileFeature=pt();Je.exports.VectorTileLayer=gt()});var hr=W(xt=>{xt.read=function(t,e,r,i,n){var a,s,o=n*8-i-1,l=(1<>1,f=-7,c=r?n-1:0,d=r?-1:1,x=t[e+c];for(c+=d,a=x&(1<<-f)-1,x>>=-f,f+=o;f>0;a=a*256+t[e+c],c+=d,f-=8);for(s=a&(1<<-f)-1,a>>=-f,f+=i;f>0;s=s*256+t[e+c],c+=d,f-=8);if(a===0)a=1-u;else{if(a===l)return s?NaN:(x?-1:1)*(1/0);s=s+Math.pow(2,i),a=a-u}return(x?-1:1)*s*Math.pow(2,a-i)};xt.write=function(t,e,r,i,n,a){var s,o,l,u=a*8-n-1,f=(1<>1,d=n===23?Math.pow(2,-24)-Math.pow(2,-77):0,x=i?0:a-1,w=i?1:-1,z=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(o=isNaN(e)?1:0,s=f):(s=Math.floor(Math.log(e)/Math.LN2),e*(l=Math.pow(2,-s))<1&&(s--,l*=2),s+c>=1?e+=d/l:e+=d*Math.pow(2,1-c),e*l>=2&&(s++,l/=2),s+c>=f?(o=0,s=f):s+c>=1?(o=(e*l-1)*Math.pow(2,n),s=s+c):(o=e*Math.pow(2,c-1)*Math.pow(2,n),s=0));n>=8;t[r+x]=o&255,x+=w,o/=256,n-=8);for(s=s<0;t[r+x]=s&255,x+=w,s/=256,u-=8);t[r+x-w]|=z*128}});var gr=W((wa,pr)=>{"use strict";pr.exports=k;var Ge=hr();function k(t){this.buf=ArrayBuffer.isView&&ArrayBuffer.isView(t)?t:new Uint8Array(t||0),this.pos=0,this.type=0,this.length=this.buf.length}k.Varint=0;k.Fixed64=1;k.Bytes=2;k.Fixed32=5;var yt=(1<<16)*(1<<16),fr=1/yt,Ri=12,cr=typeof TextDecoder=="undefined"?null:new TextDecoder("utf8");k.prototype={destroy:function(){this.buf=null},readFields:function(t,e,r){for(r=r||this.length;this.pos>3,a=this.pos;this.type=i&7,t(n,e,this),this.pos===a&&this.skip(i)}return e},readMessage:function(t,e){return this.readFields(t,e,this.readVarint()+this.pos)},readFixed32:function(){var t=Qe(this.buf,this.pos);return this.pos+=4,t},readSFixed32:function(){var t=mr(this.buf,this.pos);return this.pos+=4,t},readFixed64:function(){var t=Qe(this.buf,this.pos)+Qe(this.buf,this.pos+4)*yt;return this.pos+=8,t},readSFixed64:function(){var t=Qe(this.buf,this.pos)+mr(this.buf,this.pos+4)*yt;return this.pos+=8,t},readFloat:function(){var t=Ge.read(this.buf,this.pos,!0,23,4);return this.pos+=4,t},readDouble:function(){var t=Ge.read(this.buf,this.pos,!0,52,8);return this.pos+=8,t},readVarint:function(t){var e=this.buf,r,i;return i=e[this.pos++],r=i&127,i<128||(i=e[this.pos++],r|=(i&127)<<7,i<128)||(i=e[this.pos++],r|=(i&127)<<14,i<128)||(i=e[this.pos++],r|=(i&127)<<21,i<128)?r:(i=e[this.pos],r|=(i&15)<<28,Ii(r,t,this))},readVarint64:function(){return this.readVarint(!0)},readSVarint:function(){var t=this.readVarint();return t%2==1?(t+1)/-2:t/2},readBoolean:function(){return Boolean(this.readVarint())},readString:function(){var t=this.readVarint()+this.pos,e=this.pos;return this.pos=t,t-e>=Ri&&cr?Gi(this.buf,e,t):Ji(this.buf,e,t)},readBytes:function(){var t=this.readVarint()+this.pos,e=this.buf.subarray(this.pos,t);return this.pos=t,e},readPackedVarint:function(t,e){if(this.type!==k.Bytes)return t.push(this.readVarint(e));var r=ie(this);for(t=t||[];this.pos127;);else if(e===k.Bytes)this.pos=this.readVarint()+this.pos;else if(e===k.Fixed32)this.pos+=4;else if(e===k.Fixed64)this.pos+=8;else throw new Error("Unimplemented type: "+e)},writeTag:function(t,e){this.writeVarint(t<<3|e)},realloc:function(t){for(var e=this.length||16;e268435455||t<0){Xi(t,this);return}this.realloc(4),this.buf[this.pos++]=t&127|(t>127?128:0),!(t<=127)&&(this.buf[this.pos++]=(t>>>=7)&127|(t>127?128:0),!(t<=127)&&(this.buf[this.pos++]=(t>>>=7)&127|(t>127?128:0),!(t<=127)&&(this.buf[this.pos++]=t>>>7&127)))},writeSVarint:function(t){this.writeVarint(t<0?-t*2-1:t*2)},writeBoolean:function(t){this.writeVarint(Boolean(t))},writeString:function(t){t=String(t),this.realloc(t.length*4),this.pos++;var e=this.pos;this.pos=Qi(this.buf,t,this.pos);var r=this.pos-e;r>=128&&dr(e,r,this),this.pos=e-1,this.writeVarint(r),this.pos+=r},writeFloat:function(t){this.realloc(4),Ge.write(this.buf,t,this.pos,!0,23,4),this.pos+=4},writeDouble:function(t){this.realloc(8),Ge.write(this.buf,t,this.pos,!0,52,8),this.pos+=8},writeBytes:function(t){var e=t.length;this.writeVarint(e),this.realloc(e);for(var r=0;r=128&&dr(r,i,this),this.pos=r-1,this.writeVarint(i),this.pos+=i},writeMessage:function(t,e,r){this.writeTag(t,k.Bytes),this.writeRawMessage(e,r)},writePackedVarint:function(t,e){e.length&&this.writeMessage(t,Ui,e)},writePackedSVarint:function(t,e){e.length&&this.writeMessage(t,Ni,e)},writePackedBoolean:function(t,e){e.length&&this.writeMessage(t,Zi,e)},writePackedFloat:function(t,e){e.length&&this.writeMessage(t,ji,e)},writePackedDouble:function(t,e){e.length&&this.writeMessage(t,qi,e)},writePackedFixed32:function(t,e){e.length&&this.writeMessage(t,$i,e)},writePackedSFixed32:function(t,e){e.length&&this.writeMessage(t,Wi,e)},writePackedFixed64:function(t,e){e.length&&this.writeMessage(t,Hi,e)},writePackedSFixed64:function(t,e){e.length&&this.writeMessage(t,Ki,e)},writeBytesField:function(t,e){this.writeTag(t,k.Bytes),this.writeBytes(e)},writeFixed32Field:function(t,e){this.writeTag(t,k.Fixed32),this.writeFixed32(e)},writeSFixed32Field:function(t,e){this.writeTag(t,k.Fixed32),this.writeSFixed32(e)},writeFixed64Field:function(t,e){this.writeTag(t,k.Fixed64),this.writeFixed64(e)},writeSFixed64Field:function(t,e){this.writeTag(t,k.Fixed64),this.writeSFixed64(e)},writeVarintField:function(t,e){this.writeTag(t,k.Varint),this.writeVarint(e)},writeSVarintField:function(t,e){this.writeTag(t,k.Varint),this.writeSVarint(e)},writeStringField:function(t,e){this.writeTag(t,k.Bytes),this.writeString(e)},writeFloatField:function(t,e){this.writeTag(t,k.Fixed32),this.writeFloat(e)},writeDoubleField:function(t,e){this.writeTag(t,k.Fixed64),this.writeDouble(e)},writeBooleanField:function(t,e){this.writeVarintField(t,Boolean(e))}};function Ii(t,e,r){var i=r.buf,n,a;if(a=i[r.pos++],n=(a&112)>>4,a<128||(a=i[r.pos++],n|=(a&127)<<3,a<128)||(a=i[r.pos++],n|=(a&127)<<10,a<128)||(a=i[r.pos++],n|=(a&127)<<17,a<128)||(a=i[r.pos++],n|=(a&127)<<24,a<128)||(a=i[r.pos++],n|=(a&1)<<31,a<128))return pe(t,n,e);throw new Error("Expected varint not more than 10 bytes")}function ie(t){return t.type===k.Bytes?t.readVarint()+t.pos:t.pos+1}function pe(t,e,r){return r?e*4294967296+(t>>>0):(e>>>0)*4294967296+(t>>>0)}function Xi(t,e){var r,i;if(t>=0?(r=t%4294967296|0,i=t/4294967296|0):(r=~(-t%4294967296),i=~(-t/4294967296),r^4294967295?r=r+1|0:(r=0,i=i+1|0)),t>=18446744073709552e3||t<-18446744073709552e3)throw new Error("Given varint doesn't fit into 10 bytes");e.realloc(10),Vi(r,i,e),Yi(i,e)}function Vi(t,e,r){r.buf[r.pos++]=t&127|128,t>>>=7,r.buf[r.pos++]=t&127|128,t>>>=7,r.buf[r.pos++]=t&127|128,t>>>=7,r.buf[r.pos++]=t&127|128,t>>>=7,r.buf[r.pos]=t&127}function Yi(t,e){var r=(t&7)<<4;e.buf[e.pos++]|=r|((t>>>=3)?128:0),!!t&&(e.buf[e.pos++]=t&127|((t>>>=7)?128:0),!!t&&(e.buf[e.pos++]=t&127|((t>>>=7)?128:0),!!t&&(e.buf[e.pos++]=t&127|((t>>>=7)?128:0),!!t&&(e.buf[e.pos++]=t&127|((t>>>=7)?128:0),!!t&&(e.buf[e.pos++]=t&127)))))}function dr(t,e,r){var i=e<=16383?1:e<=2097151?2:e<=268435455?3:Math.floor(Math.log(e)/(Math.LN2*7));r.realloc(i);for(var n=r.pos-1;n>=t;n--)r.buf[n+i]=r.buf[n]}function Ui(t,e){for(var r=0;r>>8,t[r+2]=e>>>16,t[r+3]=e>>>24}function mr(t,e){return(t[e]|t[e+1]<<8|t[e+2]<<16)+(t[e+3]<<24)}function Ji(t,e,r){for(var i="",n=e;n239?4:a>223?3:a>191?2:1;if(n+o>r)break;var l,u,f;o===1?a<128&&(s=a):o===2?(l=t[n+1],(l&192)==128&&(s=(a&31)<<6|l&63,s<=127&&(s=null))):o===3?(l=t[n+1],u=t[n+2],(l&192)==128&&(u&192)==128&&(s=(a&15)<<12|(l&63)<<6|u&63,(s<=2047||s>=55296&&s<=57343)&&(s=null))):o===4&&(l=t[n+1],u=t[n+2],f=t[n+3],(l&192)==128&&(u&192)==128&&(f&192)==128&&(s=(a&15)<<18|(l&63)<<12|(u&63)<<6|f&63,(s<=65535||s>=1114112)&&(s=null))),s===null?(s=65533,o=1):s>65535&&(s-=65536,i+=String.fromCharCode(s>>>10&1023|55296),s=56320|s&1023),i+=String.fromCharCode(s),n+=o}return i}function Gi(t,e,r){return cr.decode(t.subarray(e,r))}function Qi(t,e,r){for(var i=0,n,a;i55295&&n<57344)if(a)if(n<56320){t[r++]=239,t[r++]=191,t[r++]=189,a=n;continue}else n=a-55296<<10|n-56320|65536,a=null;else{n>56319||i+1===e.length?(t[r++]=239,t[r++]=191,t[r++]=189):a=n;continue}else a&&(t[r++]=239,t[r++]=191,t[r++]=189,a=null);n<128?t[r++]=n:(n<2048?t[r++]=n>>6|192:(n<65536?t[r++]=n>>12|224:(t[r++]=n>>18|240,t[r++]=n>>12&63|128),t[r++]=n>>6&63|128),t[r++]=n&63|128)}return r}});var Nr=W((Tt,Dt)=>{(function(t,e){typeof Tt=="object"&&typeof Dt!="undefined"?Dt.exports=e():typeof define=="function"&&define.amd?define(e):(t=t||self).RBush=e()})(Tt,function(){"use strict";function t(h,m,p,b,g){(function y(v,_,S,F,T){for(;F>S;){if(F-S>600){var M=F-S+1,B=_-S+1,q=Math.log(M),Z=.5*Math.exp(2*q/3),te=.5*Math.sqrt(q*Z*(M-Z)/M)*(B-M/2<0?-1:1),X=Math.max(S,Math.floor(_-B*Z/M+te)),ct=Math.min(F,Math.floor(_+(M-B)*Z/M+te));y(v,_,X,ct,T)}var ce=v[_],re=S,O=F;for(e(v,S,_),T(v[F],ce)>0&&e(v,S,F);re0;)O--}T(v[S],ce)===0?e(v,S,O):e(v,++O,F),O<=_&&(S=O+1),_<=O&&(F=O-1)}})(h,m,p||0,b||h.length-1,g||r)}function e(h,m,p){var b=h[m];h[m]=h[p],h[p]=b}function r(h,m){return hm?1:0}var i=function(h){h===void 0&&(h=9),this._maxEntries=Math.max(4,h),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()};function n(h,m,p){if(!p)return m.indexOf(h);for(var b=0;b=h.minX&&m.maxY>=h.minY}function w(h){return{children:h,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function z(h,m,p,b,g){for(var y=[m,p];y.length;)if(!((p=y.pop())-(m=y.pop())<=b)){var v=m+Math.ceil((p-m)/b/2)*b;t(h,v,m,p,g),y.push(m,v,v,p)}}return i.prototype.all=function(){return this._all(this.data,[])},i.prototype.search=function(h){var m=this.data,p=[];if(!x(h,m))return p;for(var b=this.toBBox,g=[];m;){for(var y=0;y=0&&g[m].children.length>this._maxEntries;)this._split(g,m),m--;this._adjustParentBBoxes(b,g,m)},i.prototype._split=function(h,m){var p=h[m],b=p.children.length,g=this._minEntries;this._chooseSplitAxis(p,g,b);var y=this._chooseSplitIndex(p,g,b),v=w(p.children.splice(y,p.children.length-y));v.height=p.height,v.leaf=p.leaf,a(p,this.toBBox),a(v,this.toBBox),m?h[m-1].children.push(v):this._splitRoot(p,v)},i.prototype._splitRoot=function(h,m){this.data=w([h,m]),this.data.height=h.height+1,this.data.leaf=!1,a(this.data,this.toBBox)},i.prototype._chooseSplitIndex=function(h,m,p){for(var b,g,y,v,_,S,F,T=1/0,M=1/0,B=m;B<=p-m;B++){var q=s(h,0,B,this.toBBox),Z=s(h,B,p,this.toBBox),te=(g=q,y=Z,v=void 0,_=void 0,S=void 0,F=void 0,v=Math.max(g.minX,y.minX),_=Math.max(g.minY,y.minY),S=Math.min(g.maxX,y.maxX),F=Math.min(g.maxY,y.maxY),Math.max(0,S-v)*Math.max(0,F-_)),X=f(q)+f(Z);te=m;T--){var M=h.children[T];o(v,h.leaf?g(M):M),_+=c(v)}return _},i.prototype._adjustParentBBoxes=function(h,m,p){for(var b=p;b>=0;b--)o(m[b],h)},i.prototype._condense=function(h){for(var m=h.length-1,p=void 0;m>=0;m--)h[m].children.length===0?m>0?(p=h[m-1].children).splice(p.indexOf(h[m]),1):this.clear():a(h[m],this.toBBox)},i})});var Kr=W(()=>{});var Jr=W((Bt,Ot)=>{(function(t,e){typeof Bt=="object"&&typeof Ot!="undefined"?Ot.exports=e():typeof define=="function"&&define.amd?define(e):(t=t||self,t.TinyQueue=e())})(Bt,function(){"use strict";var t=function(i,n){if(i===void 0&&(i=[]),n===void 0&&(n=e),this.data=i,this.length=this.data.length,this.compare=n,this.length>0)for(var a=(this.length>>1)-1;a>=0;a--)this._down(a)};t.prototype.push=function(i){this.data.push(i),this.length++,this._up(this.length-1)},t.prototype.pop=function(){if(this.length!==0){var i=this.data[0],n=this.data.pop();return this.length--,this.length>0&&(this.data[0]=n,this._down(0)),i}},t.prototype.peek=function(){return this.data[0]},t.prototype._up=function(i){for(var n=this,a=n.data,s=n.compare,o=a[i];i>0;){var l=i-1>>1,u=a[l];if(s(o,u)>=0)break;a[i]=u,i=l}a[i]=o},t.prototype._down=function(i){for(var n=this,a=n.data,s=n.compare,o=this.length>>1,l=a[i];i=0)break;a[i]=f,i=u}a[i]=l};function e(r,i){return ri?1:0}return t})});var Qr=W((qa,Et)=>{"use strict";var ot=Jr();ot.default&&(ot=ot.default);Et.exports=Gr;Et.exports.default=Gr;function Gr(t,e,r){e=e||1;for(var i,n,a,s,o=0;oa)&&(a=l[0]),(!o||l[1]>s)&&(s=l[1])}var u=a-i,f=s-n,c=Math.min(u,f),d=c/2;if(c===0){var x=[i,n];return x.distance=0,x}for(var w=new ot(void 0,Zn),z=i;zm.d&&(m=p);for(var b=w.length;w.length;){var g=w.pop();g.d>m.d&&(m=g,r&&console.log("found best %d after %d probes",Math.round(1e4*g.d)/1e4,b)),!(g.max-m.d<=e)&&(d=g.h/2,w.push(new le(g.x-d,g.y-d,d,t)),w.push(new le(g.x+d,g.y-d,d,t)),w.push(new le(g.x-d,g.y+d,d,t)),w.push(new le(g.x+d,g.y+d,d,t)),b+=4)}r&&(console.log("num probes: "+b),console.log("best distance: "+m.d));var y=[m.x,m.y];return y.distance=m.d,y}function Zn(t,e){return e.max-t.max}function le(t,e,r,i){this.x=t,this.y=e,this.h=r,this.d=$n(t,e,i),this.max=this.d+this.h*Math.SQRT2}function $n(t,e,r){for(var i=!1,n=1/0,a=0;ae!=c[1]>e&&t<(c[0]-f[0])*(e-f[1])/(c[1]-f[1])+f[0]&&(i=!i),n=Math.min(n,Hn(t,e,f,c))}return n===0?0:(i?1:-1)*Math.sqrt(n)}function Wn(t){for(var e=0,r=0,i=0,n=t[0],a=0,s=n.length,o=s-1;a1?(n=i[0],a=i[1]):l>0&&(n+=s*l,a+=o*l)}return s=t-n,o=e-a,s*s+o*o}});var ca={};Li(ca,{CenteredSymbolizer:()=>Vt,CenteredTextSymbolizer:()=>ee,CircleSymbolizer:()=>se,FlexSymbolizer:()=>Ze,Font:()=>ua,GeomType:()=>J,GroupSymbolizer:()=>$e,IconSymbolizer:()=>li,Index:()=>Pt,Justify:()=>G,Labeler:()=>Ve,Labelers:()=>Ye,LineLabelPlacement:()=>ze,LineLabelSymbolizer:()=>Le,LineSymbolizer:()=>R,OffsetSymbolizer:()=>Yt,OffsetTextSymbolizer:()=>fe,PMTiles:()=>rt,Padding:()=>hi,PmtilesSource:()=>Oe,PolygonLabelSymbolizer:()=>Se,PolygonSymbolizer:()=>A,Sheet:()=>yi,ShieldSymbolizer:()=>lt,Static:()=>pi,TextPlacements:()=>C,TextSymbolizer:()=>We,TileCache:()=>st,View:()=>Ct,ZxySource:()=>it,arr:()=>Qn,covering:()=>Zr,createPattern:()=>Gn,cubicBezier:()=>ra,dark:()=>ve,exp:()=>Y,filterFn:()=>Ke,getFont:()=>Zt,getZoom:()=>Ut,isCCW:()=>Ir,isInRing:()=>Mt,json_style:()=>fa,labelRules:()=>ke,leafletLayer:()=>la,light:()=>we,linear:()=>ta,numberFn:()=>ft,numberOrFn:()=>jt,paintRules:()=>Fe,painter:()=>Xe,pointInPolygon:()=>Xr,pointMinDistToLines:()=>Yr,pointMinDistToPoints:()=>Vr,sourcesToViews:()=>Ie,step:()=>ea,toIndex:()=>ae,transformGeom:()=>Ee,widthFn:()=>qt,wrap:()=>Re});var oe=U(Q());var he=U(Q());var be=U(Q()),Ar=U(ur()),Br=U(gr());var V=(t,e,r)=>new Promise((i,n)=>{var a=l=>{try{o(r.next(l))}catch(u){n(u)}},s=l=>{try{o(r.throw(l))}catch(u){n(u)}},o=l=>l.done?i(l.value):Promise.resolve(l.value).then(a,s);o((r=r.apply(t,e)).next())}),N=Uint8Array,ue=Uint16Array,xr=Uint32Array,yr=new N([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),br=new N([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),en=new N([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),wr=function(t,e){for(var r=new ue(31),i=0;i<31;++i)r[i]=e+=1<>>1|(D&21845)<<1,ne=(ne&52428)>>>2|(ne&13107)<<2,ne=(ne&61680)>>>4|(ne&3855)<<4,bt[D]=((ne&65280)>>>8|(ne&255)<<8)>>>1;var ne,Te=function(t,e,r){for(var i=t.length,n=0,a=new ue(e);n>>l]=u}else for(o=new ue(i),n=0;n>>15-t[n]);return o},De=new N(288);for(var D=0;D<144;++D)De[D]=8;for(var D=144;D<256;++D)De[D]=9;for(var D=256;D<280;++D)De[D]=7;for(var D=280;D<288;++D)De[D]=8;var Lr=new N(32);for(var D=0;D<32;++D)Lr[D]=5;var nn=Te(De,9,1),an=Te(Lr,5,1),wt=function(t){for(var e=t[0],r=1;re&&(e=t[r]);return e},H=function(t,e,r){var i=e/8|0;return(t[i]|t[i+1]<<8)>>(e&7)&r},vt=function(t,e){var r=e/8|0;return(t[r]|t[r+1]<<8|t[r+2]<<16)>>(e&7)},sn=function(t){return(t+7)/8|0},on=function(t,e,r){(e==null||e<0)&&(e=0),(r==null||r>t.length)&&(r=t.length);var i=new(t.BYTES_PER_ELEMENT==2?ue:t.BYTES_PER_ELEMENT==4?xr:N)(r-e);return i.set(t.subarray(e,r)),i},ln=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],K=function(t,e,r){var i=new Error(e||ln[t]);if(i.code=t,Error.captureStackTrace&&Error.captureStackTrace(i,K),!r)throw i;return i},_t=function(t,e,r){var i=t.length;if(!i||r&&r.f&&!r.l)return e||new N(0);var n=!e||r,a=!r||r.i;r||(r={}),e||(e=new N(i*3));var s=function(Ht){var Kt=e.length;if(Ht>Kt){var Jt=new N(Math.max(Kt*2,Ht));Jt.set(e),e=Jt}},o=r.f||0,l=r.p||0,u=r.b||0,f=r.l,c=r.d,d=r.m,x=r.n,w=i*8;do{if(!f){o=H(t,l,1);var z=H(t,l+1,3);if(l+=3,z)if(z==1)f=nn,c=an,d=9,x=5;else if(z==2){var b=H(t,l,31)+257,g=H(t,l+10,15)+4,y=b+H(t,l+5,31)+1;l+=14;for(var v=new N(y),_=new N(19),S=0;S>>4;if(h<16)v[S++]=h;else{var q=0,Z=0;for(h==16?(Z=3+H(t,l,3),l+=2,q=v[S-1]):h==17?(Z=3+H(t,l,7),l+=3):h==18&&(Z=11+H(t,l,127),l+=7);Z--;)v[S++]=q}}var te=v.subarray(0,b),X=v.subarray(b);d=wt(te),x=wt(X),f=Te(te,d,1),c=Te(X,x,1)}else K(1);else{var h=sn(l)+4,m=t[h-4]|t[h-3]<<8,p=h+m;if(p>i){a&&K(0);break}n&&s(u+m),e.set(t.subarray(h,p),u),r.b=u+=m,r.p=l=p*8,r.f=o;continue}if(l>w){a&&K(0);break}}n&&s(u+131072);for(var ct=(1<>>4;if(l+=q&15,l>w){a&&K(0);break}if(q||K(2),O<256)e[u++]=O;else if(O==256){re=l,f=null;break}else{var $t=O-254;if(O>264){var S=O-257,Me=yr[S];$t=H(t,l,(1<>>4;dt||K(3),l+=dt&15;var X=rn[mt];if(mt>3){var Me=br[mt];X+=vt(t,l)&(1<w){a&&K(0);break}n&&s(u+131072);for(var Wt=u+$t;u>3&1)+(e>>4&1);i>0;i-=!t[r++]);return r+(e&2)},fn=function(t){var e=t.length;return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0},cn=function(t){((t[0]&15)!=8||t[0]>>>4>7||(t[0]<<8|t[1])%31)&&K(6,"invalid zlib data"),t[1]&32&&K(6,"invalid zlib data: preset dictionaries not supported")};function dn(t,e){return _t(t,e)}function mn(t,e){return _t(t.subarray(hn(t),-8),e||new N(fn(t)))}function pn(t,e){return _t((cn(t),t.subarray(2,-4)),e)}function zt(t,e){return t[0]==31&&t[1]==139&&t[2]==8?mn(t,e):(t[0]&15)!=8||t[0]>>4>7||(t[0]<<8|t[1])%31?dn(t,e):pn(t,e)}var _a=typeof TextEncoder!="undefined"&&new TextEncoder,gn=typeof TextDecoder!="undefined"&&new TextDecoder,xn=0;try{gn.decode(un,{stream:!0}),xn=1}catch(t){}var za=typeof queueMicrotask=="function"?queueMicrotask:typeof setTimeout=="function"?setTimeout:function(t){t()},Sr=(t,e)=>t*Math.pow(2,e),Pe=(t,e)=>Math.floor(t/Math.pow(2,e)),et=(t,e)=>Sr(t.getUint16(e+1,!0),8)+t.getUint8(e),Fr=(t,e)=>Sr(t.getUint32(e+2,!0),16)+t.getUint16(e,!0),yn=(t,e,r,i,n)=>{if(t!=i.getUint8(n))return t-i.getUint8(n);let a=et(i,n+1);if(e!=a)return e-a;let s=et(i,n+4);return r!=s?r-s:0},bn=(t,e,r,i)=>{let n=Mr(t,e|128,r,i);return n?{z:e,x:r,y:i,offset:n[0],length:n[1],is_dir:!0}:null},kr=(t,e,r,i)=>{let n=Mr(t,e,r,i);return n?{z:e,x:r,y:i,offset:n[0],length:n[1],is_dir:!1}:null},Mr=(t,e,r,i)=>{let n=0,a=t.byteLength/17-1;for(;n<=a;){let s=a+n>>1,o=yn(e,r,i,t,s*17);if(o>0)n=s+1;else if(o<0)a=s-1;else return[Fr(t,s*17+7),t.getUint32(s*17+13,!0)]}return null},wn=(t,e)=>t.is_dir&&!e.is_dir?1:!t.is_dir&&e.is_dir?-1:t.z!==e.z?t.z-e.z:t.x!==e.x?t.x-e.x:t.y-e.y,Cr=(t,e)=>{let r=t.getUint8(e*17);return{z:r&127,x:et(t,e*17+1),y:et(t,e*17+4),offset:Fr(t,e*17+7),length:t.getUint32(e*17+13,!0),is_dir:r>>7==1}},Tr=t=>{let e=[],r=new DataView(t);for(let i=0;i{t.sort(wn);let e=new ArrayBuffer(17*t.length),r=new Uint8Array(e);for(let i=0;i>8&255,r[i*17+3]=n.x>>16&255,r[i*17+4]=n.y&255,r[i*17+5]=n.y>>8&255,r[i*17+6]=n.y>>16&255,r[i*17+7]=n.offset&255,r[i*17+8]=Pe(n.offset,8)&255,r[i*17+9]=Pe(n.offset,16)&255,r[i*17+10]=Pe(n.offset,24)&255,r[i*17+11]=Pe(n.offset,32)&255,r[i*17+12]=Pe(n.offset,48)&255,r[i*17+13]=n.length&255,r[i*17+14]=n.length>>8&255,r[i*17+15]=n.length>>16&255,r[i*17+16]=n.length>>24&255}return e},_n=(t,e)=>{if(t.byteLength<17)return null;let r=t.byteLength/17,i=Cr(t,r-1);if(i.is_dir){let n=i.z,a=e.z-n,s=Math.trunc(e.x/(1<>>0)*4294967296+(t>>>0)}function Sn(t,e){let r=e.buf,i,n;if(n=r[e.pos++],i=(n&112)>>4,n<128||(n=r[e.pos++],i|=(n&127)<<3,n<128)||(n=r[e.pos++],i|=(n&127)<<10,n<128)||(n=r[e.pos++],i|=(n&127)<<17,n<128)||(n=r[e.pos++],i|=(n&127)<<24,n<128)||(n=r[e.pos++],i|=(n&1)<<31,n<128))return xe(t,i);throw new Error("Expected varint not more than 10 bytes")}function Ae(t){let e=t.buf,r,i;return i=e[t.pos++],r=i&127,i<128||(i=e[t.pos++],r|=(i&127)<<7,i<128)||(i=e[t.pos++],r|=(i&127)<<14,i<128)||(i=e[t.pos++],r|=(i&127)<<21,i<128)?r:(i=e[t.pos],r|=(i&15)<<28,Sn(r,t))}function Fn(t,e,r,i){if(i==0){r==1&&(e[0]=t-1-e[0],e[1]=t-1-e[1]);let n=e[0];e[0]=e[1],e[1]=n}}function kn(t,e,r){let i=0,n=0;for(;n>0;for(;f>0;)s=(u[0]&f)>0?1:0,o=(u[1]&f)>0?1:0,l+=f*f*(3*s^o),Fn(f,u,s,o),f=f/2>>0;return i+l}var Lt=32,Be;(function(t){t[t.Unknown=0]="Unknown",t[t.None=1]="None",t[t.Gzip=2]="Gzip",t[t.Brotli=3]="Brotli",t[t.Zstd=4]="Zstd"})(Be||(Be={}));function tt(t,e){if(e===1||e===0)return t;if(e===2)return zt(new Uint8Array(t));throw Error("Compression method not supported")}var St;(function(t){t[t.Unknown=0]="Unknown",t[t.Mvt=1]="Mvt",t[t.Png=2]="Png",t[t.Jpeg=3]="Jpeg",t[t.Webp=4]="Webp"})(St||(St={}));var Ft=127;function Mn(t,e){let r=0,i=t.length-1;for(;r<=i;){let n=i+r>>1,a=e-t[n].tileId;if(a>0)r=n+1;else if(a<0)i=n-1;else return t[n]}return i>=0&&(t[i].runLength===0||e-t[i].tileId0?i[a].offset=i[a-1].offset+i[a-1].length:i[a].offset=s-1}return i}function Dn(t){let e=new DataView(t);return e.getUint16(2,!0)===2?(console.warn("PMTiles spec version 2 has been deprecated; please see github.com/protomaps/PMTiles for tools to upgrade"),2):e.getUint16(2,!0)===1?(console.warn("PMTiles spec version 1 has been deprecated; please see github.com/protomaps/PMTiles for tools to upgrade"),1):3}var ye=class extends Error{};function Pn(t,e){return V(this,null,function*(){let r=yield t.getBytes(0,16384);if(new DataView(r.data).getUint16(0,!0)!==19792)throw new Error("Wrong magic number for PMTiles archive");if(Dn(r.data)<3)return[yield Dr.getHeader(t)];let n=r.data.slice(0,Ft),a=Tn(n,r.etag);if(e){let s=r.data.slice(a.rootDirectoryOffset,a.rootDirectoryOffset+a.rootDirectoryLength),o=t.getKey()+"|"+(a.etag||"")+"|"+a.rootDirectoryOffset+"|"+a.rootDirectoryLength,l=Pr(tt(s,a.internalCompression));return[a,[o,Lt*l.length,l]]}return[a,void 0]})}function An(t,e,r,i){return V(this,null,function*(){let n=yield t.getBytes(e,r);if(i.etag&&i.etag!==n.etag)throw new ye("ETag mismatch: "+i.etag);let a=tt(n.data,i.internalCompression),s=Pr(a);if(s.length===0)throw new Error("Empty directory is invalid");return s})}var Bn=class{constructor(t=64e6,e=!0){this.cache=new Map,this.sizeBytes=0,this.maxSizeBytes=t,this.counter=1,this.prefetch=e}getHeader(t){return V(this,null,function*(){let e=t.getKey();if(this.cache.has(e))return this.cache.get(e).lastUsed=this.counter++,yield this.cache.get(e).data;let r=new Promise((i,n)=>{Pn(t,this.prefetch).then(a=>{this.cache.has(e)&&(this.cache.get(e).size=Ft,this.sizeBytes+=Ft),a[1]&&this.cache.set(a[1][0],{lastUsed:this.counter++,size:a[1][1],data:Promise.resolve(a[1][2])}),i(a[0]),this.prune()}).catch(a=>{n(a)})});return this.cache.set(e,{lastUsed:this.counter++,data:r,size:0}),r})}getDirectory(t,e,r,i){return V(this,null,function*(){let n=t.getKey()+"|"+(i.etag||"")+"|"+e+"|"+r;if(this.cache.has(n))return this.cache.get(n).lastUsed=this.counter++,yield this.cache.get(n).data;let a=new Promise((s,o)=>{An(t,e,r,i).then(l=>{s(l),this.cache.has(n)&&(this.cache.get(n).size=Lt*l.length,this.sizeBytes+=Lt*l.length),this.prune()}).catch(l=>{o(l)})});return this.cache.set(n,{lastUsed:this.counter++,data:a,size:0}),a})}getArrayBuffer(t,e,r,i){return V(this,null,function*(){let n=t.getKey()+"|"+(i.etag||"")+"|"+e+"|"+r;if(this.cache.has(n))return this.cache.get(n).lastUsed=this.counter++,yield this.cache.get(n).data;let a=new Promise((s,o)=>{t.getBytes(e,r).then(l=>{if(i.etag&&i.etag!==l.etag)throw new ye("ETag mismatch: "+i.etag);s(l.data),this.cache.has(n)&&(this.cache.get(n).size=l.data.byteLength,this.sizeBytes+=l.data.byteLength),this.prune()}).catch(l=>{o(l)})});return this.cache.set(n,{lastUsed:this.counter++,data:a,size:0}),a})}prune(){for(;this.sizeBytes>this.maxSizeBytes;){let t=1/0,e;this.cache.forEach((r,i)=>{r.lastUseda.maxZoom)return;let s=a.rootDirectoryOffset,o=a.rootDirectoryLength;for(let l=0;l<5;l++){let u=yield this.cache.getDirectory(this.source,s,o,a),f=Mn(u,n);if(f)if(f.runLength>0){let c=yield this.source.getBytes(a.tileDataOffset+f.offset,f.length,i);if(a.etag&&a.etag!==c.etag)throw new ye("ETag mismatch: "+a.etag);return{data:tt(c.data,a.tileCompression),cacheControl:c.cacheControl,expires:c.expires}}else s=a.leafDirectoryOffset+f.offset,o=f.length;else return}throw Error("Maximum directory depth exceeded")})}getZxy(t,e,r,i){return V(this,null,function*(){try{return yield this.getZxyAttempt(t,e,r,i)}catch(n){if(n instanceof ye)return this.cache.invalidate(this.source),yield this.getZxyAttempt(t,e,r,i);throw n}})}getMetadataAttempt(){return V(this,null,function*(){let t=yield this.cache.getHeader(this.source),e=yield this.source.getBytes(t.jsonMetadataOffset,t.jsonMetadataLength);if(t.etag&&t.etag!==e.etag)throw new ye("Etag mismatch: "+t.etag);let r=tt(e.data,t.internalCompression),i=new TextDecoder("utf-8");return JSON.parse(i.decode(r))})}getMetadata(){return V(this,null,function*(){try{return yield this.getMetadataAttempt()}catch(t){if(t instanceof ye)return this.cache.invalidate(this.source),yield this.getMetadataAttempt();throw t}})}};var J;(function(i){i[i.Point=1]="Point",i[i.Line=2]="Line",i[i.Polygon=3]="Polygon"})(J||(J={}));function ae(t){return t.x+":"+t.y+":"+t.z}var On=(t,e,r)=>{t.pos=e;for(var i=t.readVarint()+t.pos,n=1,a=0,s=0,o=0,l=1/0,u=-1/0,f=1/0,c=-1/0,d=[],x=[];t.pos>3}if(a--,n===1||n===2)s+=t.readSVarint()*r,o+=t.readSVarint()*r,su&&(u=s),oc&&(c=o),n===1&&(x.length>0&&d.push(x),x=[]),x.push(new be.default(s,o));else if(n===7)x&&x.push(x[0].clone());else throw new Error("unknown command "+n)}return x&&d.push(x),{geom:d,bbox:{minX:l,minY:f,maxX:u,maxY:c}}};function Or(t,e){let r=new Ar.VectorTile(new Br.default(t)),i=new Map;for(let[n,a]of Object.entries(r.layers)){let s=[],o=a;for(let l=0;ls[0]!=e.z?(s[1].abort(),!1):!0));let i=new AbortController;this.controllers.push([e.z,i]);let n=i.signal,a=yield this.p.getZxy(e.z,e.x,e.y,n);return a?Or(a.data,r):new Map})}},it=class{constructor(e,r){this.url=e,this.controllers=[],this.shouldCancelZooms=r}get(e,r){return E(this,null,function*(){this.shouldCancelZooms&&(this.controllers=this.controllers.filter(s=>s[0]!=e.z?(s[1].abort(),!1):!0));let i=this.url.replace("{z}",e.z.toString()).replace("{x}",e.x.toString()).replace("{y}",e.y.toString()),n=new AbortController;this.controllers.push([e.z,n]);let a=n.signal;return new Promise((s,o)=>{fetch(i,{signal:a}).then(l=>l.arrayBuffer()).then(l=>{let u=Or(l,r);s(u)}).catch(l=>{o(l)})})})}},kt=6378137,Er=85.0511287798,nt=kt*Math.PI,En=t=>{let e=Math.PI/180,r=Math.max(Math.min(Er,t[0]),-Er),i=Math.sin(r*e);return new be.default(kt*t[1]*e,kt*Math.log((1+i)/(1-i))/2)};function Rr(t){return t*t}function at(t,e){return Rr(t.x-e.x)+Rr(t.y-e.y)}function Rn(t,e,r){var i=at(e,r);if(i===0)return at(t,e);var n=((t.x-e.x)*(r.x-e.x)+(t.y-e.y)*(r.y-e.y))/i;return n=Math.max(0,Math.min(1,n)),at(t,new be.default(e.x+n*(r.x-e.x),e.y+n*(r.y-e.y)))}function Mt(t,e){for(var r=!1,i=0,n=e.length-1;it.y!=l>t.y&&t.x<(o-a)*(t.y-s)/(l-s)+a;u&&(r=!r)}return r}function Ir(t){for(var e=0,r=0;r1&&(s.x=s.x-Math.floor(s.x));let o=s.mult(1<{let a=this.cache.get(r);if(a)a.used=performance.now(),i(a.data);else{let s=this.inflight.get(r);s?s.push([i,n]):(this.inflight.set(r,[]),this.source.get(e,this.tileSize).then(o=>{this.cache.set(r,{used:performance.now(),data:o});let l=this.inflight.get(r);if(l&&l.forEach(u=>u[0](o)),this.inflight.delete(r),i(o),this.cache.size>=64){let u=1/0,f;this.cache.forEach((c,d)=>{c.used{let l=this.inflight.get(r);l&&l.forEach(u=>u[1](o)),this.inflight.delete(r),n(o)}))}})})}};var Ee=(t,e,r)=>{let i=[];for(let n of t){let a=[];for(let s of n)a.push(s.clone().mult(e).add(r));i.push(a)}return i},Re=(t,e)=>{let r=1<=r&&(t=t%r),t},Ct=class{constructor(e,r,i){this.tileCache=e,this.maxDataLevel=r,this.levelDiff=i}dataTilesForBounds(e,r){let i=Math.pow(2,e)/Math.pow(2,Math.ceil(e)),n=[];var a=1,s=this.tileCache.tileSize;if(ethis.tileCache.get(a.data_tile)))).map((a,s)=>{let o=i[s];return{data:a,z:e,data_tile:o.data_tile,scale:o.scale,dim:o.dim,origin:o.origin}})})}getDisplayTile(e){return E(this,null,function*(){let r=this.dataTileForDisplayTile(e);return{data:yield this.tileCache.get(r.data_tile),z:e.z,data_tile:r.data_tile,scale:r.scale,origin:r.origin,dim:r.dim}})}queryFeatures(e,r,i){let n=Math.round(i),a=Math.min(n-this.levelDiff,this.maxDataLevel),s=16/(1<{let e=i=>{let n=i.levelDiff===void 0?2:i.levelDiff,a=i.maxDataZoom||14,s;typeof i.url=="string"?i.url.endsWith(".pmtiles")?s=new Oe(i.url,!0):s=new it(i.url,!0):s=new Oe(i.url,!0);let o=new st(s,256*1<f.maxzoom)continue;let w=r.get(f.dataSource||"");if(!!w)for(let z of w){var c=z.data.get(f.dataLayer);if(c===void 0)continue;f.symbolizer.before&&f.symbolizer.before(t,z.z);let h=z.origin,m=z.dim,p=z.scale;if(t.save(),o){t.beginPath();let b=Math.max(h.x-s.x,a.minX-s.x),g=Math.max(h.y-s.y,a.minY-s.y),y=Math.min(h.x-s.x+m,a.maxX-s.x),v=Math.min(h.y-s.y+m,a.maxY-s.y);t.rect(b,g,y-b,v-g),t.clip()}t.translate(h.x-s.x,h.y-s.y);for(var d of c){let b=d.geom,g=d.bbox;g.maxX*p+h.xa.maxX||g.minY*p+h.y>a.maxY||g.maxY*p+h.y{let i=256,n=e/i,a=Math.floor(r.minX/i),s=Math.floor(r.minY/i),o=Math.floor(r.maxX/i),l=Math.floor(r.maxY/i),u=Math.log2(n),f=[];for(let c=a;c<=o;c++){let d=c%(1<this.dim&&(o=!0)}if(s||o){var u=s?this.dim:-this.dim,f=[];for(let x of e.bboxes)f.push({minX:x.minX+u,minY:x.minY,maxX:x.maxX+u,maxY:x.maxY});let c={anchor:new jr.default(e.anchor.x+u,e.anchor.y),bboxes:f,draw:e.draw,order:r,tileKey:i},d=this.current.get(i);d&&d.add(c);for(let x of f){var l=x;l.indexed_label=c,this.tree.insert(l)}}}pruneOrNoop(e){let r=e.split(":"),i,n=0,a=0;for(var s of this.current.keys()){let o=s.split(":");if(o[3]===r[3]){a++;let l=Math.sqrt(Math.pow(+o[0]-+r[0],2)+Math.pow(+o[1]-+r[1],2));l>n&&(n=l,i=s)}i&&a>this.maxLabeledTiles&&this.pruneKey(i)}}pruneKey(e){let r=this.current.get(e);if(!r)return;let i=[];for(let n of this.tree.all())r.has(n.indexed_label)&&i.push(n);i.forEach(n=>{this.tree.remove(n)}),this.current.delete(e)}removeLabel(e){let r=[];for(let n of this.tree.all())e==n.indexed_label&&r.push(n);r.forEach(n=>{this.tree.remove(n)});let i=this.current.get(e.tileKey);i&&i.delete(e)}},Ve=class{constructor(e,r,i,n,a){this.index=new Pt(256*1<l.maxzoom)continue;let u=l.dataSource||"",f=e.get(u);if(!!f)for(let c of f){let d=ae(c.data_tile)+":"+u;if(!i.has(d))continue;let x=c.data.get(l.dataLayer);if(x===void 0)continue;let w=x;l.sort&&w.sort((h,m)=>l.sort?l.sort(h.props,m.props):0);let z={index:this.index,zoom:this.z,scratch:this.scratch,order:o,overzoom:this.z-c.data_tile.z};for(let h of w){if(l.filter&&!l.filter(this.z,h))continue;let m=Ee(h.geom,c.scale,c.origin),p=l.symbolizer.place(z,m,h);if(!!p)for(let b of p){var a=!1;if(!(b.deduplicationKey&&this.index.deduplicationCollides(b))){if(this.index.labelCollides(b,1/0)){if(!this.index.labelCollides(b,o)){let g=this.index.searchLabel(b,1/0);for(let y of g){this.index.removeLabel(y);for(let v of y.bboxes)this.findInvalidatedTiles(n,c.dim,v,d)}this.index.insert(b,o,d),a=!0}}else this.index.insert(b,o,d),a=!0;if(a)for(let g of b.bboxes)(g.maxX>c.origin.x+c.dim||g.minXc.origin.y+c.dim)&&this.findInvalidatedTiles(n,c.dim,g,d)}}}}}for(var s of i)this.index.pruneOrNoop(s);return n.size>0&&this.callback&&this.callback(n),performance.now()-r}findInvalidatedTiles(e,r,i,n){let a=Zr(this.z,r,i);for(let s of a)s.key!=n&&this.index.hasPrefix(s.key)&&e.add(s.display)}add(e){var r=!0;for(let[i,n]of e)for(let a of n)this.index.has(ae(a.data_tile)+":"+i)||(r=!1);return r?0:this.layout(e)}},Ye=class{constructor(e,r,i,n){this.labelers=new Map,this.scratch=e,this.labelRules=r,this.maxLabeledTiles=i,this.callback=n}add(e,r){var i=this.labelers.get(e);return i||(i=new Ve(e,this.scratch,this.labelRules,this.maxLabeledTiles,this.callback),this.labelers.set(e,i)),i.add(r)}getIndex(e){let r=this.labelers.get(e);if(r)return r.index}};var we={earth:"#FFFBF6",glacier:"#ffffff",residential:"#F4F4F8",hospital:"#FFF6F6",cemetery:"#EFF2EE",school:"#F7F6FF",industrial:"#FFF9EF",wood:"#F4F9EF",grass:"#EBF9E3",park:"#E5F9D5",water:"#B7DFF2",sand:"#ebebeb",buildings:"#F2EDE8",highwayCasing:"#FFC3C3",majorRoadCasing:"#FFB9B9",mediumRoadCasing:"#FFCE8E",minorRoadCasing:"#cccccc",highway:"#FFCEBB",majorRoad:"#FFE4B3",mediumRoad:"#FFF2C8",minorRoad:"#ffffff",boundaries:"#9e9e9e",mask:"#dddddd",countryLabel:"#aaaaaa",cityLabel:"#6C6C6C",stateLabel:"#999999",neighbourhoodLabel:"#888888",landuseLabel:"#898989",waterLabel:"#41ABDC",naturalLabel:"#4B8F14",roadsLabel:"#888888",poisLabel:"#606060"};var ve={earth:"#151515",glacier:"#1c1c1c",residential:"#252B2F",hospital:"#3E2C2C",cemetery:"#36483D",school:"#2C3440",industrial:"#33312C",wood:"#3A3E38",grass:"#4E604D",park:"#2C4034",water:"#4D5B73",sand:"#777777",buildings:"#464545",highwayCasing:"#000000",majorRoadCasing:"#1C1B1B",mediumRoadCasing:"#3E3E3E",minorRoadCasing:"#000000",highway:"#5B5B5B",majorRoad:"#595959",mediumRoad:"#4F4F4F",minorRoad:"#393939",boundaries:"#666666",mask:"#dddddd",countryLabel:"#ffffff",cityLabel:"#FFFFFF",stateLabel:"#ffffff",neighbourhoodLabel:"#FDFDFD",landuseLabel:"#DDDDDD",waterLabel:"#707E95",naturalLabel:"#4c4c4c",roadsLabel:"#C4C4C4",poisLabel:"#959393"};function Ue(t,e,r){return Math.min(Math.max(t,r),e)}var _e=class extends Error{constructor(e){super(`Failed to parse color: "${e}"`)}};function In(t){if(typeof t!="string")throw new _e(t);if(t.trim().toLowerCase()==="transparent")return[0,0,0,0];let e=t.trim();e=jn.test(t)?function(s){let o=s.toLowerCase().trim(),l=Xn[function(u){let f=5381,c=u.length;for(;c;)f=33*f^u.charCodeAt(--c);return(f>>>0)%2341}(o)];if(!l)throw new _e(s);return`#${l}`}(t):t;let r=Vn.exec(e);if(r){let s=Array.from(r).slice(1);return[...s.slice(0,3).map(o=>parseInt(Ne(o,2),16)),parseInt(Ne(s[3]||"f",2),16)/255]}let i=Yn.exec(e);if(i){let s=Array.from(i).slice(1);return[...s.slice(0,3).map(o=>parseInt(o,16)),parseInt(s[3]||"ff",16)/255]}let n=Un.exec(e);if(n){let s=Array.from(n).slice(1);return[...s.slice(0,3).map(o=>parseInt(o,10)),parseFloat(s[3]||"1")]}let a=Nn.exec(e);if(a){let[s,o,l,u]=Array.from(a).slice(1).map(parseFloat);if(Ue(0,100,o)!==o)throw new _e(t);if(Ue(0,100,l)!==l)throw new _e(t);return[...qn(s,o,l),u||1]}throw new _e(t)}var $r=t=>parseInt(t.replace(/_/g,""),36),Xn="1q29ehhb 1n09sgk7 1kl1ekf_ _yl4zsno 16z9eiv3 1p29lhp8 _bd9zg04 17u0____ _iw9zhe5 _to73___ _r45e31e _7l6g016 _jh8ouiv _zn3qba8 1jy4zshs 11u87k0u 1ro9yvyo 1aj3xael 1gz9zjz0 _3w8l4xo 1bf1ekf_ _ke3v___ _4rrkb__ 13j776yz _646mbhl _nrjr4__ _le6mbhl 1n37ehkb _m75f91n _qj3bzfz 1939yygw 11i5z6x8 _1k5f8xs 1509441m 15t5lwgf _ae2th1n _tg1ugcv 1lp1ugcv 16e14up_ _h55rw7n _ny9yavn _7a11xb_ 1ih442g9 _pv442g9 1mv16xof 14e6y7tu 1oo9zkds 17d1cisi _4v9y70f _y98m8kc 1019pq0v 12o9zda8 _348j4f4 1et50i2o _8epa8__ _ts6senj 1o350i2o 1mi9eiuo 1259yrp0 1ln80gnw _632xcoy 1cn9zldc _f29edu4 1n490c8q _9f9ziet 1b94vk74 _m49zkct 1kz6s73a 1eu9dtog _q58s1rz 1dy9sjiq __u89jo3 _aj5nkwg _ld89jo3 13h9z6wx _qa9z2ii _l119xgq _bs5arju 1hj4nwk9 1qt4nwk9 1ge6wau6 14j9zlcw 11p1edc_ _ms1zcxe _439shk6 _jt9y70f _754zsow 1la40eju _oq5p___ _x279qkz 1fa5r3rv _yd2d9ip _424tcku _8y1di2_ _zi2uabw _yy7rn9h 12yz980_ __39ljp6 1b59zg0x _n39zfzp 1fy9zest _b33k___ _hp9wq92 1il50hz4 _io472ub _lj9z3eo 19z9ykg0 _8t8iu3a 12b9bl4a 1ak5yw0o _896v4ku _tb8k8lv _s59zi6t _c09ze0p 1lg80oqn 1id9z8wb _238nba5 1kq6wgdi _154zssg _tn3zk49 _da9y6tc 1sg7cv4f _r12jvtt 1gq5fmkz 1cs9rvci _lp9jn1c _xw1tdnb 13f9zje6 16f6973h _vo7ir40 _bt5arjf _rc45e4t _hr4e100 10v4e100 _hc9zke2 _w91egv_ _sj2r1kk 13c87yx8 _vqpds__ _ni8ggk8 _tj9yqfb 1ia2j4r4 _7x9b10u 1fc9ld4j 1eq9zldr _5j9lhpx _ez9zl6o _md61fzm".split(" ").reduce((t,e)=>{let r=$r(e.substring(0,3)),i=$r(e.substring(3)).toString(16),n="";for(let a=0;a<6-i.length;a++)n+="0";return t[r]=`${n}${i}`,t},{}),Ne=(t,e)=>Array.from(Array(e)).map(()=>t).join(""),Vn=new RegExp(`^#${Ne("([a-f0-9])",3)}([a-f0-9])?$`,"i"),Yn=new RegExp(`^#${Ne("([a-f0-9]{2})",3)}([a-f0-9]{2})?$`,"i"),Un=new RegExp(`^rgba?\\(\\s*(\\d+)\\s*${Ne(",\\s*(\\d+)\\s*",2)}(?:,\\s*([\\d.]+))?\\s*\\)$`,"i"),Nn=/^hsla?\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%(?:\s*,\s*([\d.]+))?\s*\)$/i,jn=/^[a-z]+$/i,Wr=t=>Math.round(255*t),qn=(t,e,r)=>{let i=r/100;if(e===0)return[i,i,i].map(Wr);let n=(t%360+360)%360/60,a=(1-Math.abs(2*i-1))*(e/100),s=a*(1-Math.abs(n%2-1)),o=0,l=0,u=0;n>=0&&n<1?(o=a,l=s):n>=1&&n<2?(o=s,l=a):n>=2&&n<3?(l=a,u=s):n>=3&&n<4?(l=s,u=a):n>=4&&n<5?(o=s,u=a):n>=5&&n<6&&(o=a,u=s);let f=i-a/2;return[o+f,l+f,u+f].map(Wr)};function At(t){let[e,r,i,n]=In(t).map((u,f)=>f===3?u:u/255),a=Math.max(e,r,i),s=Math.min(e,r,i),o=(a+s)/2;if(a===s)return[0,0,o,n];let l=a-s;return[60*(e===a?(r-i)/l+(r.5?l/(2-a-s):l/(a+s),o,n]}function Hr(t,e,r,i){return`hsla(${(t%360).toFixed()}, ${Ue(0,100,100*e).toFixed()}%, ${Ue(0,100,100*r).toFixed()}%, ${parseFloat(Ue(0,1,i).toFixed(3))})`}var j=U(Q()),ri=U(Kr()),ii=U(Qr());var I=class{constructor(e,r){this.str=e!=null?e:r,this.per_feature=typeof this.str=="function"&&this.str.length==2}get(e,r){return typeof this.str=="function"?this.str(e,r):this.str}},P=class{constructor(e,r=1){this.value=e!=null?e:r,this.per_feature=typeof this.value=="function"&&this.value.length==2}get(e,r){return typeof this.value=="function"?this.value(e,r):this.value}},je=class{constructor(e){var r;this.label_props=(r=e==null?void 0:e.label_props)!=null?r:["name"],this.textTransform=e==null?void 0:e.textTransform}get(e,r){let i,n;typeof this.label_props=="function"?n=this.label_props(e,r):n=this.label_props;for(let s of n)if(r.props.hasOwnProperty(s)&&typeof r.props[s]=="string"){i=r.props[s];break}let a;return typeof this.textTransform=="function"?a=this.textTransform(e,r):a=this.textTransform,i&&a==="uppercase"?i=i.toUpperCase():i&&a==="lowercase"?i=i.toLowerCase():i&&a==="capitalize"&&(i=i.toLowerCase().split(" ").map(l=>l[0].toUpperCase()+l.slice(1)).join(" ")),i}},qe=class{constructor(e){var r,i;(e==null?void 0:e.font)?this.font=e.font:(this.family=(r=e==null?void 0:e.fontFamily)!=null?r:"sans-serif",this.size=(i=e==null?void 0:e.fontSize)!=null?i:12,this.weight=e==null?void 0:e.fontWeight,this.style=e==null?void 0:e.fontStyle)}get(e,r){if(this.font)return typeof this.font=="function"?this.font(e,r):this.font;var i="";this.style&&(typeof this.style=="function"?i=this.style(e,r)+" ":i=this.style+" ");var n="";this.weight&&(typeof this.weight=="function"?n=this.weight(e,r)+" ":n=this.weight+" ");var a;typeof this.size=="function"?a=this.size(e,r):a=this.size;var s;return typeof this.family=="function"?s=this.family(e,r):s=this.family,`${i}${n}${a}px ${s}`}},Rt=class{constructor(e,r=[]){this.value=e!=null?e:r,this.per_feature=typeof this.value=="function"&&this.value.length==2}get(e,r){return typeof this.value=="function"?this.value(e,r):this.value}};var It=U(Q()),Kn=(t,e,r)=>{var i=[],n,a,s,o=0,l=0,u=0,f=0,c=0,d=0,x=0,w=0,z=0,h=0,m=0,p=0;if(t.length<2)return[];if(t.length===2)return u=Math.sqrt(Math.pow(t[1].x-t[0].x,2)+Math.pow(t[1].y-t[0].y,2)),[{length:u,beginIndex:0,beginDistance:0,endIndex:2,endDistance:u}];for(f=Math.sqrt(Math.pow(t[1].x-t[0].x,2)+Math.pow(t[1].y-t[0].y,2)),o=1,l=t.length-1;oe||u-p>r)&&(i.push({length:u-p,beginDistance:p,beginIndex:m,endIndex:o+1,endDistance:u}),m=o,p=u),f=c;return o-m>0&&i.push({length:u-p+c,beginIndex:m,beginDistance:p,endIndex:o+1,endDistance:u+c}),i};function ei(t,e,r,i){let n,a,s=0,o=[];var l=-1/0;for(let f of t){let c=Kn(f,Math.PI/45,e);for(let d of c)if(d.length>=e+i){let x=new It.default(f[d.beginIndex].x,f[d.beginIndex].y),w=f[d.endIndex-1],z=new It.default((w.x-x.x)/d.length,(w.y-x.y)/d.length);for(var u=i;u=0&&r-i{let i=document.createElement("canvas"),n=i.getContext("2d");return i.width=t,i.height=e,n!==null&&r(i,n),i},A=class{constructor(e){var r;this.pattern=e.pattern,this.fill=new I(e.fill,"black"),this.opacity=new P(e.opacity,1),this.stroke=new I(e.stroke,"black"),this.width=new P(e.width,0),this.per_feature=(r=this.fill.per_feature||this.opacity.per_feature||this.stroke.per_feature||this.width.per_feature||e.per_feature)!=null?r:!1,this.do_stroke=!1}before(e,r){if(!this.per_feature){e.globalAlpha=this.opacity.get(r),e.fillStyle=this.fill.get(r),e.strokeStyle=this.stroke.get(r);let i=this.width.get(r);i>0&&(this.do_stroke=!0),e.lineWidth=i}if(this.pattern){let i=e.createPattern(this.pattern,"repeat");i&&(e.fillStyle=i)}}draw(e,r,i,n){var a=!1;if(this.per_feature){e.globalAlpha=this.opacity.get(i,n),e.fillStyle=this.fill.get(i,n);var s=this.width.get(i,n);s&&(a=!0,e.strokeStyle=this.stroke.get(i,n),e.lineWidth=s)}let o=()=>{e.fill(),(a||this.do_stroke)&&e.stroke()};var l=0;e.beginPath();for(var u of r){l+u.length>ni&&(o(),l=0,e.beginPath());for(var f=0;f0&&o()}};function Qn(t,e){return r=>{let i=r-t;return i>=0&&i{if(e.length<1)return 0;if(r<=e[0][0])return e[0][1];if(r>=e[e.length-1][0])return e[e.length-1][1];let i=ai(r,e),n=oi(r,i,t,e);return si(n,e[i][1],e[i+1][1])}}function ea(t,e){return r=>{if(e.length<1)return 0;let i=t;for(let n=0;n=e[n][0]&&(i=e[n][1]);return i}}function ta(t){return Y(1,t)}function ra(t,e,r,i,n){return a=>{if(n.length<1)return 0;let s=new ri.default(t,e,r,i),o=ai(a,n),l=s.solve(oi(a,o,1,n));return si(l,n[o][1],n[o+1][1])}}var R=class{constructor(e){var r;this.color=new I(e.color,"black"),this.width=new P(e.width),this.opacity=new P(e.opacity),this.dash=e.dash?new Rt(e.dash):null,this.dashColor=new I(e.dashColor,"black"),this.dashWidth=new P(e.dashWidth,1),this.lineCap=new I(e.lineCap,"butt"),this.lineJoin=new I(e.lineJoin,"miter"),this.skip=!1,this.per_feature=!!(((r=this.dash)==null?void 0:r.per_feature)||this.color.per_feature||this.opacity.per_feature||this.width.per_feature||this.lineCap.per_feature||this.lineJoin.per_feature||e.per_feature)}before(e,r){this.per_feature||(e.strokeStyle=this.color.get(r),e.lineWidth=this.width.get(r),e.globalAlpha=this.opacity.get(r),e.lineCap=this.lineCap.get(r),e.lineJoin=this.lineJoin.get(r))}draw(e,r,i,n){if(this.skip)return;let a=()=>{this.per_feature&&(e.globalAlpha=this.opacity.get(i,n),e.lineCap=this.lineCap.get(i,n),e.lineJoin=this.lineJoin.get(i,n)),this.dash?(e.save(),this.per_feature?(e.lineWidth=this.dashWidth.get(i,n),e.strokeStyle=this.dashColor.get(i,n),e.setLineDash(this.dash.get(i,n))):e.setLineDash(this.dash.get(i)),e.stroke(),e.restore()):(e.save(),this.per_feature&&(e.lineWidth=this.width.get(i,n),e.strokeStyle=this.color.get(i,n)),e.stroke(),e.restore())};var s=0;e.beginPath();for(var o of r){s+o.length>ni&&(a(),s=0,e.beginPath());for(var l=0;l0&&a()}},li=class{constructor(e){this.name=e.name,this.sheet=e.sheet,this.dpr=window.devicePixelRatio}place(e,r,i){let n=r[0],a=new j.default(r[0][0].x,r[0][0].y),s=this.sheet.get(this.name),o=s.w/this.dpr,l=s.h/this.dpr,u={minX:a.x-o/2,minY:a.y-l/2,maxX:a.x+o/2,maxY:a.y+l/2};return[{anchor:a,bboxes:[u],draw:c=>{c.globalAlpha=1,c.drawImage(this.sheet.canvas,s.x,s.y,s.w,s.h,-s.w/2/this.dpr,-s.h/2/this.dpr,s.w/2,s.h/2)}}]}},se=class{constructor(e){this.radius=new P(e.radius,3),this.fill=new I(e.fill,"black"),this.stroke=new I(e.stroke,"white"),this.width=new P(e.width,0),this.opacity=new P(e.opacity)}draw(e,r,i,n){e.globalAlpha=this.opacity.get(i,n);let a=this.radius.get(i,n),s=this.width.get(i,n);s>0&&(e.strokeStyle=this.stroke.get(i,n),e.lineWidth=s,e.beginPath(),e.arc(r[0][0].x,r[0][0].y,a+s/2,0,2*Math.PI),e.stroke()),e.fillStyle=this.fill.get(i,n),e.beginPath(),e.arc(r[0][0].x,r[0][0].y,a,0,2*Math.PI),e.fill()}place(e,r,i){let n=r[0],a=new j.default(r[0][0].x,r[0][0].y),s=this.radius.get(e.zoom,i),o={minX:a.x-s,minY:a.y-s,maxX:a.x+s,maxY:a.y+s};return[{anchor:a,bboxes:[o],draw:u=>{this.draw(u,[[new j.default(0,0)]],e.zoom,i)}}]}},lt=class{constructor(e){this.font=new qe(e),this.text=new je(e),this.fill=new I(e.fill,"black"),this.background=new I(e.background,"white"),this.padding=new P(e.padding,0)}place(e,r,i){let n=this.text.get(e.zoom,i);if(!n)return;let a=this.font.get(e.zoom,i);e.scratch.font=a;let s=e.scratch.measureText(n),o=s.width,l=s.actualBoundingBoxAscent,u=s.actualBoundingBoxDescent,f=r[0],c=new j.default(r[0][0].x,r[0][0].y),d=this.padding.get(e.zoom,i),x={minX:c.x-o/2-d,minY:c.y-l-d,maxX:c.x+o/2+d,maxY:c.y+u+d};return[{anchor:c,bboxes:[x],draw:z=>{z.globalAlpha=1,z.fillStyle=this.background.get(e.zoom,i),z.fillRect(-o/2-d,-l-d,o+2*d,l+u+2*d),z.fillStyle=this.fill.get(e.zoom,i),z.font=a,z.fillText(n,-o/2,0)}}]}},Ze=class{constructor(e){this.list=e}place(e,r,i){var n=this.list[0].place(e,r,i);if(!n)return;var a=n[0];let s=a.anchor,o=a.bboxes[0],l=o.maxY-o.minY,u=[{draw:a.draw,translate:{x:0,y:0}}],f=[[new j.default(r[0][0].x,r[0][0].y+l)]];for(let d=1;d{for(let x of u)d.save(),d.translate(x.translate.x,x.translate.y),x.draw(d),d.restore()}}]}},ui=(t,e)=>({minX:Math.min(t.minX,e.minX),minY:Math.min(t.minY,e.minY),maxX:Math.max(t.maxX,e.maxX),maxY:Math.max(t.maxY,e.maxY)}),$e=class{constructor(e){this.list=e}place(e,r,i){let n=this.list[0];if(!n)return;var a=n.place(e,r,i);if(!a)return;var s=a[0];let o=s.anchor,l=s.bboxes[0],u=[s.draw];for(let c=1;c{u.forEach(d=>d(c))}}]}},Vt=class{constructor(e){this.symbolizer=e}place(e,r,i){let n=r[0][0],a=this.symbolizer.place(e,[[new j.default(0,0)]],i);if(!a||a.length==0)return;let s=a[0],o=s.bboxes[0],l=o.maxX-o.minX,u=o.maxY-o.minY,f={minX:n.x-l/2,maxX:n.x+l/2,minY:n.y-u/2,maxY:n.y+u/2};return[{anchor:n,bboxes:[f],draw:d=>{d.translate(-l/2,u/2-o.maxY),s.draw(d,{justify:2})}}]}},hi=class{constructor(e,r){this.padding=new P(e,0),this.symbolizer=r}place(e,r,i){let n=this.symbolizer.place(e,r,i);if(!n||n.length==0)return;let a=this.padding.get(e.zoom,i);for(var s of n)for(var o of s.bboxes)o.minX-=a,o.minY-=a,o.maxX+=a,o.maxY+=a;return n}},We=class{constructor(e){this.font=new qe(e),this.text=new je(e),this.fill=new I(e.fill,"black"),this.stroke=new I(e.stroke,"black"),this.width=new P(e.width,0),this.lineHeight=new P(e.lineHeight,1),this.letterSpacing=new P(e.letterSpacing,0),this.maxLineCodeUnits=new P(e.maxLineChars,15),this.justify=e.justify}place(e,r,i){let n=this.text.get(e.zoom,i);if(!n)return;let a=this.font.get(e.zoom,i);e.scratch.font=a;let s=this.letterSpacing.get(e.zoom,i),o=Xt(n,this.maxLineCodeUnits.get(e.zoom,i));var l="",u=0;for(let p of o)p.length>u&&(u=p.length,l=p);let f=e.scratch.measureText(l),c=f.width+s*(u-1),d=f.actualBoundingBoxAscent,x=f.actualBoundingBoxDescent,w=(d+x)*this.lineHeight.get(e.zoom,i),z=new j.default(r[0][0].x,r[0][0].y),h={minX:z.x,minY:z.y-d,maxX:z.x+c,maxY:z.y+x+(o.length-1)*w};return[{anchor:z,bboxes:[h],draw:(p,b)=>{p.globalAlpha=1,p.font=a,p.fillStyle=this.fill.get(e.zoom,i);let g=this.width.get(e.zoom,i);var y=0;for(let F of o){var v=0;if(this.justify==2||b&&b.justify==2?v=(c-p.measureText(F).width)/2:(this.justify==3||b&&b.justify==3)&&(v=c-p.measureText(F).width),g)if(p.lineWidth=g*2,p.strokeStyle=this.stroke.get(e.zoom,i),s>0){var _=v;for(var S of F)p.strokeText(S,_,y),_+=p.measureText(S).width+s}else p.strokeText(F,v,y);if(s>0){var _=v;for(var S of F)p.fillText(S,_,y),_+=p.measureText(S).width+s}else p.fillText(F,v,y);y+=w}}}]}},ee=class{constructor(e){this.centered=new Vt(new We(e))}place(e,r,i){return this.centered.place(e,r,i)}},Yt=class{constructor(e,r){var i,n,a;this.symbolizer=e,this.offsetX=new P(r.offsetX,0),this.offsetY=new P(r.offsetY,0),this.justify=(i=r.justify)!=null?i:void 0,this.placements=(n=r.placements)!=null?n:[2,6,8,4,1,3,5,7],this.ddValues=(a=r.ddValues)!=null?a:()=>({})}place(e,r,i){if(i.geomType!==J.Point)return;let n=r[0][0],a=this.symbolizer.place(e,[[new j.default(0,0)]],i);if(!a||a.length==0)return;let s=a[0],o=s.bboxes[0],l=this.offsetX,u=this.offsetY,f=this.justify,c=this.placements,{offsetX:d,offsetY:x,justify:w,placements:z}=this.ddValues(e.zoom,i)||{};d&&(l=new P(d,0)),x&&(u=new P(x,0)),w&&(f=w),z&&(c=z);let h=l.get(e.zoom,i),m=u.get(e.zoom,i),p=(_,S)=>({minX:_.x+S.x+o.minX,minY:_.y+S.y+o.minY,maxX:_.x+S.x+o.maxX,maxY:_.y+S.y+o.maxY});var b=new j.default(h,m),g;let y=_=>{_.translate(b.x,b.y),s.draw(_,{justify:g})},v=(_,S)=>{let F=p(_,S);if(!e.index.bboxCollides(F,e.order))return[{anchor:n,bboxes:[F],draw:y}]};for(let _ of c){let S=this.computeXAxisOffset(h,o,_),F=this.computeYAxisOffset(m,o,_);return g=this.computeJustify(f,_),b=new j.default(S,F),v(n,b)}}computeXAxisOffset(e,r,i){let n=r.maxX,a=n/2;return[1,5].includes(i)?e-a:[8,7,6].includes(i)?e-n:e}computeYAxisOffset(e,r,i){let n=Math.abs(r.minY),a=r.maxY,s=(r.minY+r.maxY)/2;return[3,7].includes(i)?e-s:[8,2,1].includes(i)?e-a:[6,4,5].includes(i)?e+n:e}computeJustify(e,r){return e||([1,5].includes(r)?2:[2,3,4].includes(r)?1:3)}},fe=class{constructor(e){this.symbolizer=new Yt(new We(e),e)}place(e,r,i){return this.symbolizer.place(e,r,i)}},ze;(function(i){i[i.Above=1]="Above",i[i.Center=2]="Center",i[i.Below=3]="Below"})(ze||(ze={}));var Le=class{constructor(e){var r;this.font=new qe(e),this.text=new je(e),this.fill=new I(e.fill,"black"),this.stroke=new I(e.stroke,"black"),this.width=new P(e.width,0),this.offset=new P(e.offset,0),this.position=(r=e.position)!=null?r:1,this.maxLabelCodeUnits=new P(e.maxLabelChars,40),this.repeatDistance=new P(e.repeatDistance,250)}place(e,r,i){let n=this.text.get(e.zoom,i);if(!n||n.length>this.maxLabelCodeUnits.get(e.zoom,i))return;let a=20,s=i.bbox;if(s.maxY-s.minY4&&(c*=1<({minX:y.x-d/2,minY:y.y-d/2,maxX:y.x+d/2,maxY:y.y+d/2})),g=y=>{y.globalAlpha=1,y.rotate(Math.atan2(m,h)),h<0&&(y.scale(-1,-1),y.translate(-u,0));let v=0;this.position===3?v+=f:this.position===2&&(v+=f/2),y.translate(0,v-this.offset.get(e.zoom,i)),y.font=o;let _=this.width.get(e.zoom,i);_&&(y.lineWidth=_,y.strokeStyle=this.stroke.get(e.zoom,i),y.strokeText(n,0,0)),y.fillStyle=this.fill.get(e.zoom,i),y.fillText(n,0,0)};w.push({anchor:z.start,bboxes:b,draw:g,deduplicationKey:n,deduplicationDistance:c})}return w}},Se=class{constructor(e){this.symbolizer=new We(e)}place(e,r,i){let n=i.bbox;if((n.maxY-n.minY)*(n.maxX-n.minX)<2e4)return;let s=this.symbolizer.place(e,[[new j.default(0,0)]],i);if(!s||s.length==0)return;let o=s[0],l=o.bboxes[0],u=r[0],f=(0,ii.default)([u.map(w=>[w.x,w.y])]),c=new j.default(f[0],f[1]),d={minX:c.x-(l.maxX-l.minX)/2,minY:c.y-(l.maxY-l.minY)/2,maxX:c.x+(l.maxX-l.minX)/2,maxY:c.y+(l.maxY-l.minY)/2};return[{anchor:c,bboxes:[d],draw:w=>{w.translate(o.anchor.x-(l.maxX-l.minX)/2,o.anchor.y),o.draw(w)}}]}};var fi=(t,e)=>{let r=At(e),i=tr({},t);for(let[n,a]of Object.entries(t)){let s=At(a);i[n]=Hr(r[0],r[1],s[2],s[3])}return i},Fe=(t,e)=>(e&&(t=fi(t,e)),[{dataLayer:"earth",symbolizer:new A({fill:t.earth})},{dataLayer:"natural",symbolizer:new A({fill:t.glacier}),filter:(r,i)=>i.props.natural=="glacier"},{dataLayer:"landuse",symbolizer:new A({fill:t.residential}),filter:(r,i)=>i.props.landuse=="residential"||i.props.place=="neighbourhood"},{dataLayer:"landuse",symbolizer:new A({fill:t.hospital}),filter:(r,i)=>i.props.amenity=="hospital"},{dataLayer:"landuse",symbolizer:new A({fill:t.cemetery}),filter:(r,i)=>i.props.landuse=="cemetery"},{dataLayer:"landuse",symbolizer:new A({fill:t.school}),filter:(r,i)=>i.props.amenity=="school"||i.props.amenity=="kindergarten"||i.props.amenity=="university"||i.props.amenity=="college"},{dataLayer:"landuse",symbolizer:new A({fill:t.industrial}),filter:(r,i)=>i.props.landuse=="industrial"},{dataLayer:"natural",symbolizer:new A({fill:t.wood}),filter:(r,i)=>i.props.natural=="wood"},{dataLayer:"landuse",symbolizer:new A({fill:t.grass}),filter:(r,i)=>i.props.landuse=="grass"},{dataLayer:"landuse",symbolizer:new A({fill:t.park}),filter:(r,i)=>i.props.leisure=="park"},{dataLayer:"water",symbolizer:new A({fill:t.water})},{dataLayer:"natural",symbolizer:new A({fill:t.sand}),filter:(r,i)=>i.props.natural=="sand"},{dataLayer:"buildings",symbolizer:new A({fill:t.buildings})},{dataLayer:"roads",symbolizer:new R({color:t.highwayCasing,width:Y(1.4,[[5,1.5],[11,4],[16,9],[20,40]])}),filter:(r,i)=>i.props["pmap:kind"]=="highway"},{dataLayer:"roads",symbolizer:new R({color:t.majorRoadCasing,width:Y(1.4,[[9,3],[12,4],[17,8],[20,22]])}),filter:(r,i)=>i.props["pmap:kind"]=="major_road"},{dataLayer:"roads",symbolizer:new R({color:t.mediumRoadCasing,width:Y(1.4,[[13,3],[17,6],[20,18]])}),filter:(r,i)=>i.props["pmap:kind"]=="medium_road"},{dataLayer:"roads",symbolizer:new R({color:t.minorRoadCasing,width:Y(1.4,[[14,2],[17,5],[20,15]])}),filter:(r,i)=>i.props["pmap:kind"]=="minor_road"},{dataLayer:"roads",symbolizer:new R({color:t.minorRoad,width:Y(1.4,[[14,1],[17,3],[20,13]])}),filter:(r,i)=>i.props["pmap:kind"]=="minor_road"},{dataLayer:"roads",symbolizer:new R({color:t.mediumRoad,width:Y(1.4,[[13,2],[17,4],[20,15]])}),filter:(r,i)=>i.props["pmap:kind"]=="medium_road"},{dataLayer:"roads",symbolizer:new R({color:t.majorRoad,width:Y(1.4,[[9,2],[12,3],[17,6],[20,20]])}),filter:(r,i)=>i.props["pmap:kind"]=="major_road"},{dataLayer:"roads",symbolizer:new R({color:t.highway,width:Y(1.4,[[5,.5],[11,2.5],[16,7],[20,30]])}),filter:(r,i)=>i.props["pmap:kind"]=="highway"},{dataLayer:"boundaries",symbolizer:new R({color:t.boundaries,width:2,opacity:.4})},{dataLayer:"mask",symbolizer:new A({fill:t.mask})}]),ke=(t,e,r,i)=>{e&&(t=fi(t,e));var n=["name"];r&&(n=r);let a=(s,o)=>i?s instanceof fe?new Ze([s,new fe({fill:o,label_props:i})]):new Ze([s,new ee({fill:o,label_props:i})]):s;return[{dataLayer:"places",symbolizer:a(new ee({label_props:n,fill:t.countryLabel,lineHeight:1.5,font:(s,o)=>s<6?"200 14px sans-serif":"200 20px sans-serif",textTransform:"uppercase"}),t.countryLabel),filter:(s,o)=>o.props["pmap:kind"]=="country"},{dataLayer:"places",symbolizer:a(new ee({label_props:n,fill:t.stateLabel,font:"300 16px sans-serif"}),t.stateLabel),filter:(s,o)=>o.props["pmap:kind"]=="state"},{id:"cities_high",dataLayer:"places",filter:(s,o)=>o.props["pmap:kind"]=="city",minzoom:7,symbolizer:a(new ee({label_props:n,fill:t.cityLabel,font:(s,o)=>(o==null?void 0:o.props["pmap:rank"])===1?s>8?"600 20px sans-serif":"600 12px sans-serif":s>8?"600 16px sans-serif":"600 10px sans-serif"}),t.cityLabel),sort:(s,o)=>s["pmap:rank"]-o["pmap:rank"]},{id:"cities_low",dataLayer:"places",filter:(s,o)=>o.props["pmap:kind"]=="city",maxzoom:6,symbolizer:new $e([new se({radius:2,fill:t.cityLabel}),a(new fe({label_props:n,fill:t.cityLabel,offsetX:2,offsetY:2,font:(s,o)=>(o==null?void 0:o.props["pmap:rank"])===1?s>8?"600 20px sans-serif":"600 12px sans-serif":s>8?"600 16px sans-serif":"600 10px sans-serif"}),t.cityLabel)]),sort:(s,o)=>s["pmap:rank"]-o["pmap:rank"]},{id:"neighbourhood",dataLayer:"places",symbolizer:a(new ee({label_props:n,fill:t.neighbourhoodLabel,font:"500 10px sans-serif",textTransform:"uppercase"}),t.neighbourhoodLabel),filter:(s,o)=>o.props["pmap:kind"]=="neighbourhood"},{dataLayer:"landuse",symbolizer:a(new Se({label_props:n,fill:t.landuseLabel,font:"300 12px sans-serif"}),t.landuseLabel)},{dataLayer:"water",symbolizer:a(new Se({label_props:n,fill:t.waterLabel,font:"italic 600 12px sans-serif"}),t.waterLabel)},{dataLayer:"natural",symbolizer:a(new Se({label_props:n,fill:t.naturalLabel,font:"italic 300 12px sans-serif"}),t.naturalLabel)},{dataLayer:"roads",symbolizer:a(new Le({label_props:n,fill:t.roadsLabel,font:"500 12px sans-serif"}),t.roadsLabel),minzoom:12},{dataLayer:"roads",symbolizer:new lt({label_props:["ref"],font:"600 9px sans-serif",background:t.highway,padding:2,fill:t.neighbourhoodLabel}),filter:(s,o)=>o.props["pmap:kind"]=="highway"},{dataLayer:"pois",symbolizer:new $e([new se({radius:2,fill:t.poisLabel}),a(new fe({label_props:n,fill:t.poisLabel,offsetX:2,offsetY:2,font:"300 10px sans-serif"}),t.poisLabel)])}]};var ci=(t,e,r)=>[{dataSource:t,dataLayer:e,symbolizer:new se({opacity:.2,fill:r,radius:4}),filter:(i,n)=>n.geomType==J.Point},{dataSource:t,dataLayer:e,symbolizer:new R({opacity:.2,color:r,width:2}),filter:(i,n)=>n.geomType==J.Line},{dataSource:t,dataLayer:e,symbolizer:new A({opacity:.2,fill:r,stroke:r,width:1}),filter:(i,n)=>n.geomType==J.Polygon}],ut=(t,e)=>{var r=[];for(var[i,n]of t)for(var a of n)for(var s of a.data.keys())i===e.dataSource&&s===e.dataLayer||(r=r.concat(ci(i,s,"steelblue")));return r=r.concat(ci(e.dataSource||"",e.dataLayer,"red")),r};var He=6378137,di=85.0511287798,$=He*Math.PI,mi=t=>{let e=Math.PI/180,r=Math.max(Math.min(di,t.y),-di),i=Math.sin(r*e);return new oe.default(He*t.x*e,He*Math.log((1+i)/(1-i))/2)},ia=t=>{var e=180/Math.PI;return{lat:(2*Math.atan(Math.exp(t.y/He))-Math.PI/2)*e,lng:t.x*e/He}},na=(t,e)=>r=>{let i=mi(r);return new oe.default((i.x+$)/($*2),1-(i.y+$)/($*2)).mult((1<r=>{let i=new oe.default(r.x,r.y).add(t).div((1<{let r=e*(360/t);return Math.log2(r/256)},pi=class{constructor(e){let r=e.dark?ve:we;this.paint_rules=e.paint_rules||Fe(r,e.shade),this.label_rules=e.label_rules||ke(r,e.shade,e.language1,e.language2),this.backgroundColor=e.backgroundColor,this.views=Ie(e),this.debug=e.debug||"",this.xray=e.xray}drawContext(e,r,i,n,a){return E(this,null,function*(){let s=mi(n),l=new oe.default((s.x+$)/($*2),1-(s.y+$)/($*2)).clone().mult(Math.pow(2,a)*256).sub(new oe.default(r/2,i/2)),u={minX:l.x,minY:l.y,maxX:l.x+r,maxY:l.y+i},f=[];for(let[p,b]of this.views){let g=b.getBbox(a,u);f.push({key:p,promise:g})}let c=yield Promise.all(f.map(p=>p.promise.then(b=>({status:"fulfilled",value:b,key:p.key}),b=>({status:"rejected",value:[],reason:b,key:p.key})))),d=new Map;for(let p of c)p.status==="fulfilled"&&d.set(p.key,p.value);let x=performance.now(),w=new Ve(a,e,this.label_rules,16,void 0),z=w.add(d);this.backgroundColor&&(e.save(),e.fillStyle=this.backgroundColor,e.fillRect(0,0,r,i),e.restore());let h=this.paint_rules;this.xray&&(h=ut(d,this.xray));let m=Xe(e,a,d,this.xray?null:w.index,h,u,l,!0,this.debug);if(this.debug){e.save(),e.translate(-l.x,-l.y),e.strokeStyle=this.debug,e.fillStyle=this.debug,e.font="12px sans-serif";let p=0;for(let[b,g]of d){for(let y of g){e.strokeRect(y.origin.x,y.origin.y,y.dim,y.dim);let v=y.data_tile;e.fillText(b+(b?" ":"")+v.z+" "+v.x+" "+v.y,y.origin.x+4,y.origin.y+14*(1+p))}p++}e.restore()}return{elapsed:performance.now()-x,project:na(l,a),unproject:aa(l,a)}})}drawCanvas(a,s,o){return E(this,arguments,function*(e,r,i,n={}){let l=window.devicePixelRatio,u=e.clientWidth,f=e.clientHeight;e.width==u*l&&e.height==f*l||(e.width=u*l,e.height=f*l),n.lang&&(e.lang=n.lang);let c=e.getContext("2d");return c.setTransform(l,0,0,l,0,0),this.drawContext(c,u,f,r,i)})}drawContextBounds(e,r,i,n,a){return E(this,null,function*(){let s=i.x-r.x,o=new oe.default((r.x+i.x)/2,(r.y+i.y)/2);return this.drawContext(e,n,a,o,Ut(s,n))})}drawCanvasBounds(s,o,l,u){return E(this,arguments,function*(e,r,i,n,a={}){let f=i.x-r.x,c=new oe.default((r.x+i.x)/2,(r.y+i.y)/2);return this.drawCanvas(e,c,Ut(f,n),a)})}};var gi=U(Q());var sa=t=>new Promise((e,r)=>{setTimeout(()=>{e()},t)}),oa=t=>t.then(e=>({status:"fulfilled",value:e}),e=>({status:"rejected",reason:e})),la=(t={})=>{class e extends L.GridLayer{constructor(i={}){i.noWrap&&!i.bounds&&(i.bounds=[[-90,-180],[90,180]]),i.attribution==null&&(i.attribution='Protomaps \xA9 OpenStreetMap'),super(i);let n=i.dark?ve:we;this.paint_rules=i.paint_rules||Fe(n,i.shade),this.label_rules=i.label_rules||ke(n,i.shade,i.language1,i.language2),this.backgroundColor=i.backgroundColor,this.lastRequestedZ=void 0,this.xray=i.xray,this.tasks=i.tasks||[],this.views=Ie(i),this.debug=i.debug;let a=document.createElement("canvas").getContext("2d");this.scratch=a,this.onTilesInvalidated=s=>{s.forEach(o=>{this.rerenderTile(o)})},this.labelers=new Ye(this.scratch,this.label_rules,16,this.onTilesInvalidated),this.tile_size=256*window.devicePixelRatio,this.tileDelay=i.tileDelay||3,this.lang=i.lang,this.inspector=this.inspect(this)}setDefaultStyle(i,n,a,s){let o=i?ve:we;this.paint_rules=Fe(o,n),this.label_rules=ke(o,n,a,s)}renderTile(i,n,a,s=()=>{}){return E(this,null,function*(){this.lastRequestedZ=i.z;let o=[];for(let[_,S]of this.views){let F=S.getDisplayTile(i);o.push({key:_,promise:F})}let l=yield Promise.all(o.map(_=>_.promise.then(S=>({status:"fulfilled",value:S,key:_.key}),S=>({status:"rejected",reason:S,key:_.key})))),u=new Map;for(let _ of l)_.status==="fulfilled"?u.set(_.key,[_.value]):_.reason.name==="AbortError"||console.error(_.reason);if(n.key!=a||this.lastRequestedZ!==i.z||(yield Promise.all(this.tasks.map(oa)),n.key!=a)||this.lastRequestedZ!==i.z)return;let f=this.labelers.add(i.z,u);if(n.key!=a||this.lastRequestedZ!==i.z)return;let c=this.labelers.getIndex(i.z);if(!this._map)return;let d=this._map.getCenter().wrap(),x=this._getTiledPixelBounds(d),w=this._pxBoundsToTileRange(x),z=w.getCenter(),h=i.distanceTo(z)*this.tileDelay;if(yield sa(h),n.key!=a||this.lastRequestedZ!==i.z)return;let m=16,p={minX:256*i.x-m,minY:256*i.y-m,maxX:256*(i.x+1)+m,maxY:256*(i.y+1)+m},b=new gi.default(256*i.x,256*i.y);n.width=this.tile_size,n.height=this.tile_size;let g=n.getContext("2d");g.setTransform(this.tile_size/256,0,0,this.tile_size/256,0,0),g.clearRect(0,0,256,256),this.backgroundColor&&(g.save(),g.fillStyle=this.backgroundColor,g.fillRect(0,0,256,256),g.restore());var y=0;let v=this.paint_rules;if(this.xray&&(v=ut(u,this.xray)),y=Xe(g,i.z,u,this.xray?null:c,v,p,b,!1,this.debug),this.debug){g.save(),g.fillStyle=this.debug,g.font="600 12px sans-serif",g.fillText(i.z+" "+i.x+" "+i.y,4,14),g.font="12px sans-serif";let _=28;for(let[S,F]of u){let T=F[0].data_tile;g.fillText(S+(S?" ":"")+T.z+" "+T.x+" "+T.y,4,_),_+=14}g.font="600 10px sans-serif",y>8&&(g.fillText(y.toFixed()+" ms paint",4,_),_+=14),f>8&&g.fillText(f.toFixed()+" ms layout",4,_),g.strokeStyle=this.debug,g.lineWidth=.5,g.beginPath(),g.moveTo(0,0),g.lineTo(0,256),g.stroke(),g.lineWidth=.5,g.beginPath(),g.moveTo(0,0),g.lineTo(256,0),g.stroke(),g.restore()}s()})}rerenderTile(i){for(let n in this._tiles){let a=this._wrapCoords(this._keyToTileCoords(n));i===this._tileCoordsToKey(a)&&this.renderTile(a,this._tiles[n].el,i)}}clearLayout(){this.labelers=new Ye(this.scratch,this.label_rules,16,this.onTilesInvalidated)}rerenderTiles(){for(let i in this._tiles){let n=this._wrapCoords(this._keyToTileCoords(i)),a=this._tileCoordsToKey(n);this.renderTile(n,this._tiles[i].el,a)}}createTile(i,n){let a=L.DomUtil.create("canvas","leaflet-tile");a.lang=this.lang;let s=this._tileCoordsToKey(i);return a.key=s,this.renderTile(i,a,s,()=>{n(null,a)}),a}_removeTile(i){let n=this._tiles[i];!n||(n.el.removed=!0,n.el.key=void 0,L.DomUtil.removeClass(n.el,"leaflet-tile-loaded"),n.el.width=n.el.height=0,L.DomUtil.remove(n.el),delete this._tiles[i],this.fire("tileunload",{tile:n.el,coords:this._keyToTileCoords(i)}))}queryFeatures(i,n){let a=new Map;for(var[s,o]of this.views)a.set(s,o.queryFeatures(i,n,this._map.getZoom()));return a}inspect(i){return n=>{let a=["\u25CE","\u27CD","\u25FB"],s=i._map.wrapLatLng(n.latlng),o=i.queryFeatures(s.lng,s.lat);var l="";let u=!0;for(var[f,c]of o)for(var d of c)if(!(this.xray&&this.xray!==!0&&!((this.xray.dataSource||"")===f&&this.xray.dataLayer===d.layerName))){l=l+`
${a[d.feature.geomType-1]} ${f} ${f?"/":""} ${d.layerName} ${d.feature.id||""}
`;for(let x in d.feature.props)l=l+`
${x} = ${d.feature.props[x]}
`;u=!1}u&&(l="No features."),L.popup().setLatLng(n.latlng).setContent('
'+l+"
").openOn(i._map)}}addInspector(i){return i.on("click",this.inspector)}removeInspector(i){return i.off("click",this.inspector)}}return new e(t)};function Nt(t){let e=0,r=0;for(let o of t)e+=o.w*o.h,r=Math.max(r,o.w);t.sort((o,l)=>l.h-o.h);let i=Math.max(Math.ceil(Math.sqrt(e/.95)),r),n=[{x:0,y:0,w:i,h:1/0}],a=0,s=0;for(let o of t)for(let l=n.length-1;l>=0;l--){let u=n[l];if(!(o.w>u.w||o.h>u.h)){if(o.x=u.x,o.y=u.y,s=Math.max(s,o.y+o.h),a=Math.max(a,o.x+o.w),o.w===u.w&&o.h===u.h){let f=n.pop();l{let i=new FontFace(t,"url("+e+")",{weight:r});return document.fonts.add(i),i.load()},xi=t=>E(void 0,null,function*(){return new Promise((e,r)=>{let i=new Image;i.onload=()=>e(i),i.onerror=()=>r("Invalid SVG"),i.src=t})}),ha=` -`,Ie=class{constructor(t){this.src=t,this.canvas=null}load(){return D(this,null,function*(){let t=this.src,i=window.devicePixelRatio;t.endsWith(".html")&&(t=yield(yield fetch(t)).text());let a=new window.DOMParser().parseFromString(t,"text/html").body.children;this.mapping={};let n=yield Qt("data:image/svg+xml;base64,"+btoa(ar)),s=[{w:n.width*i,h:n.height*i,img:n}],l=new XMLSerializer;for(let c of a){var o=btoa(l.serializeToString(c)),h="data:image/svg+xml;base64,"+o;let y=yield Qt(h);s.push({w:y.width*i,h:y.height*i,img:y,id:c.id})}let d=nr(s);this.canvas=document.createElement("canvas"),this.canvas.width=d.w,this.canvas.height=d.h;let x=this.canvas.getContext("2d");for(let c of s)x.drawImage(c.img,c.x,c.y,c.w,c.h),c.id?this.mapping[c.id]={x:c.x,y:c.y,w:c.w,h:c.h}:this.missingBox={x:c.x,y:c.y,w:c.w,h:c.h};return this})}get(t){let i=this.mapping[t];return i||(i=this.missingBox),i.canvas=this.canvas,i}};var sr=(e,t,i)=>{let r=new FontFace(e,"url("+t+")",{weight:i});return document.fonts.add(r),r.load()},lr=e=>new Ie(e);function Fe(e){if(e.includes("$type"))return t=>!0;if(e[0]=="==")return t=>t[e[1]]===e[2];if(e[0]=="!=")return t=>t[e[1]]!==e[2];if(e[0]=="!"){let t=Fe(e[1]);return i=>!t(i)}else{if(e[0]==="<")return t=>t[e[1]]t[e[1]]<=e[2];if(e[0]===">")return t=>t[e[1]]>e[2];if(e[0]===">=")return t=>t[e[1]]>=e[2];if(e[0]==="in")return t=>e.slice(2,e.length).includes(t[e[1]]);if(e[0]==="!in")return t=>!e.slice(2,e.length).includes(t[e[1]]);if(e[0]==="has")return t=>t.hasOwnProperty(e[1]);if(e[0]==="all"){let t=e.slice(1,e.length).map(i=>Fe(i));return i=>t.every(r=>r(i))}else if(e[0]==="any"){let t=e.slice(1,e.length).map(i=>Fe(i));return i=>t.some(r=>r(i))}else return console.log("Unimplemented filter: ",e[0]),t=>!1}}function Ee(e){if(e.base&&e.stops)return(i,r)=>X(e.base,e.stops)(i-1);if(e[0]=="interpolate"&&e[1][0]=="exponential"&&e[2]=="zoom"){let i=e.slice(3),r=[];for(var t=0;tX(e[1][1],r)(a-1)}else if(e[0]=="step"&&e[1][0]=="get"){let i=e.slice(2),r=e[1][1];return(a,n)=>{let s=n[r];if(s1}function et(e,t=0){return e?typeof e=="number"?e:Ee(e):t}function tt(e,t){let i=et(e,1),r=et(t);return a=>{let n=typeof i=="number"?i:i(a,{});return r?n+(typeof r=="number"?r:r(a,{})):n}}function it(e,t){let i=[];for(let l of e["text-font"])t.hasOwnProperty(l)&&i.push(t[l]);i.length===0&&i.push({face:"sans-serif"});let r=e["text-size"];var a="";i.length&&i[0].weight&&(a=i[0].weight+" ");var n="";if(i.length&&i[0].style&&(n=i[0].style+" "),typeof r=="number")return`${n}${a}${r}px ${i.map(l=>l.face).join(", ")}`;if(r.stops){var s=1.4;r.base&&(s=r.base);let l=Ee(r);return o=>`${n}${a}${l(o,{})}px ${i.map(h=>h.face).join(", ")}`}else if(r[0]=="step"){let l=Ee(r);return(o,h)=>`${n}${a}${l(o,h)}px ${i.map(d=>d.face).join(", ")}`}else return console.log("Can't parse font: ",e),(l,o)=>"12px sans-serif"}function or(e,t){let i=[],r=[],a=new Map;for(var n of e.layers){if(a.set(n.id,n),n.layout&&n.layout.visibility=="none")continue;if(n.ref){let h=a.get(n.ref);n.type=h.type,n.filter=h.filter,n.source=h.source,n["source-layer"]=h["source-layer"]}let o=n["source-layer"];var s,l=void 0;n.filter&&(l=Fe(n.filter)),n.type=="fill"?i.push({dataLayer:n["source-layer"],filter:l,symbolizer:new B({fill:n.paint["fill-color"],opacity:n.paint["fill-opacity"]})}):n.type=="fill-extrusion"?i.push({dataLayer:n["source-layer"],filter:l,symbolizer:new B({fill:n.paint["fill-extrusion-color"],opacity:n.paint["fill-extrusion-opacity"]})}):n.type=="line"?n.paint["line-dasharray"]?i.push({dataLayer:n["source-layer"],filter:l,symbolizer:new C({width:tt(n.paint["line-width"],n.paint["line-gap-width"]),dash:n.paint["line-dasharray"],dashColor:n.paint["line-color"]})}):i.push({dataLayer:n["source-layer"],filter:l,symbolizer:new C({color:n.paint["line-color"],width:tt(n.paint["line-width"],n.paint["line-gap-width"])})}):n.type=="symbol"&&(n.layout["symbol-placement"]=="line"?r.push({dataLayer:n["source-layer"],filter:l,symbolizer:new ae({font:it(n.layout,t),fill:n.paint["text-color"],width:n.paint["text-halo-width"],stroke:n.paint["text-halo-color"],textTransform:n.layout["text-transform"]})}):r.push({dataLayer:n["source-layer"],filter:l,symbolizer:new I({font:it(n.layout,t),fill:n.paint["text-color"],stroke:n.paint["text-halo-color"],width:n.paint["text-halo-width"],textTransform:n.layout["text-transform"]})}))}return r.reverse(),{paint_rules:i,label_rules:r,tasks:[]}}return hr;})(); +`,yi=class{constructor(e){this.src=e,this.canvas=document.createElement("canvas"),this.mapping=new Map,this.missingBox={x:0,y:0,w:0,h:0}}load(){return E(this,null,function*(){let e=this.src,r=window.devicePixelRatio;e.endsWith(".html")&&(e=yield(yield fetch(e)).text());let i=new window.DOMParser().parseFromString(e,"text/html"),n=Array.from(i.body.children),a=yield xi("data:image/svg+xml;base64,"+btoa(ha)),s=[{w:a.width*r,h:a.height*r,img:a,id:""}],o=new XMLSerializer;for(let d of n){var l=btoa(o.serializeToString(d)),u="data:image/svg+xml;base64,"+l;let x=yield xi(u);s.push({w:x.width*r,h:x.height*r,img:x,id:d.id})}let f=Nt(s);this.canvas.width=f.w,this.canvas.height=f.h;let c=this.canvas.getContext("2d");if(c)for(let d of s)d.x!==void 0&&d.y!==void 0&&(c.drawImage(d.img,d.x,d.y,d.w,d.h),d.id?this.mapping.set(d.id,{x:d.x,y:d.y,w:d.w,h:d.h}):this.missingBox={x:d.x,y:d.y,w:d.w,h:d.h});return this})}get(e){let r=this.mapping.get(e);return r||(r=this.missingBox),r}};function ht(t,e){return typeof t=="number"?t:e}function Ke(t){if(t.includes("$type"))return e=>!0;if(t[0]=="==")return(e,r)=>r.props[t[1]]===t[2];if(t[0]=="!=")return(e,r)=>r.props[t[1]]!==t[2];if(t[0]=="!"){let e=Ke(t[1]);return(r,i)=>!e(r,i)}else{if(t[0]==="<")return(e,r)=>ht(r.props[t[1]],1/0)ht(r.props[t[1]],1/0)<=t[2];if(t[0]===">")return(e,r)=>ht(r.props[t[1]],-1/0)>t[2];if(t[0]===">=")return(e,r)=>ht(r.props[t[1]],-1/0)>=t[2];if(t[0]==="in")return(e,r)=>t.slice(2,t.length).includes(r.props[t[1]]);if(t[0]==="!in")return(e,r)=>!t.slice(2,t.length).includes(r.props[t[1]]);if(t[0]==="has")return(e,r)=>r.props.hasOwnProperty(t[1]);if(t[0]==="!has")return(e,r)=>!r.props.hasOwnProperty(t[1]);if(t[0]==="all"){let e=t.slice(1,t.length).map(r=>Ke(r));return(r,i)=>e.every(n=>n(r,i))}else if(t[0]==="any"){let e=t.slice(1,t.length).map(r=>Ke(r));return(r,i)=>e.some(n=>n(r,i))}else return console.log("Unimplemented filter: ",t[0]),e=>!1}}function ft(t){if(t.base&&t.stops)return r=>Y(t.base,t.stops)(r-1);if(t[0]=="interpolate"&&t[1][0]=="exponential"&&t[2]=="zoom"){let r=t.slice(3),i=[];for(var e=0;eY(t[1][1],i)(n-1)}else if(t[0]=="step"&&t[1][0]=="get"){let r=t.slice(2),i=t[1][1];return(n,a)=>{let s=a==null?void 0:a.props[i];if(typeof s=="number"){if(s1}function jt(t,e=0){return t?typeof t=="number"?t:(r,i)=>i?ft(t)(r,i):e:e}function qt(t,e){let r=jt(t,1),i=jt(e);return(n,a)=>{let s=typeof r=="number"?r:r(n,a);return i?s+(typeof i=="number"?i:i(n,a)):s}}function Zt(t,e){let r=[];for(let o of t["text-font"])e.hasOwnProperty(o)&&r.push(e[o]);r.length===0&&r.push({face:"sans-serif"});let i=t["text-size"];var n="";r.length&&r[0].weight&&(n=r[0].weight+" ");var a="";if(r.length&&r[0].style&&(a=r[0].style+" "),typeof i=="number")return o=>`${a}${n}${i}px ${r.map(l=>l.face).join(", ")}`;if(i.stops){var s=1.4;i.base&&(s=i.base);let o=ft(i);return(l,u)=>`${a}${n}${o(l,u)}px ${r.map(f=>f.face).join(", ")}`}else if(i[0]=="step"){let o=ft(i);return(l,u)=>`${a}${n}${o(l,u)}px ${r.map(f=>f.face).join(", ")}`}else return console.log("Can't parse font: ",t),o=>"12px sans-serif"}function fa(t,e){let r=[],i=[],n=new Map;for(var a of t.layers){if(n.set(a.id,a),a.layout&&a.layout.visibility=="none")continue;if(a.ref){let u=n.get(a.ref);a.type=u.type,a.filter=u.filter,a.source=u.source,a["source-layer"]=u["source-layer"]}let l=a["source-layer"];var s,o=void 0;a.filter&&(o=Ke(a.filter)),a.type=="fill"?r.push({dataLayer:a["source-layer"],filter:o,symbolizer:new A({fill:a.paint["fill-color"],opacity:a.paint["fill-opacity"]})}):a.type=="fill-extrusion"?r.push({dataLayer:a["source-layer"],filter:o,symbolizer:new A({fill:a.paint["fill-extrusion-color"],opacity:a.paint["fill-extrusion-opacity"]})}):a.type=="line"?a.paint["line-dasharray"]?r.push({dataLayer:a["source-layer"],filter:o,symbolizer:new R({width:qt(a.paint["line-width"],a.paint["line-gap-width"]),dash:a.paint["line-dasharray"],dashColor:a.paint["line-color"]})}):r.push({dataLayer:a["source-layer"],filter:o,symbolizer:new R({color:a.paint["line-color"],width:qt(a.paint["line-width"],a.paint["line-gap-width"])})}):a.type=="symbol"?a.layout["symbol-placement"]=="line"?i.push({dataLayer:a["source-layer"],filter:o,symbolizer:new Le({font:Zt(a.layout,e),fill:a.paint["text-color"],width:a.paint["text-halo-width"],stroke:a.paint["text-halo-color"],textTransform:a.layout["text-transform"],label_props:a.layout["text-field"]?[a.layout["text-field"]]:void 0})}):i.push({dataLayer:a["source-layer"],filter:o,symbolizer:new ee({font:Zt(a.layout,e),fill:a.paint["text-color"],stroke:a.paint["text-halo-color"],width:a.paint["text-halo-width"],textTransform:a.layout["text-transform"],label_props:a.layout["text-field"]?[a.layout["text-field"]]:void 0})}):a.type=="circle"&&r.push({dataLayer:a["source-layer"],filter:o,symbolizer:new se({radius:a.paint["circle-radius"],fill:a.paint["circle-color"],stroke:a.paint["circle-stroke-color"],width:a.paint["circle-stroke-width"]})})}return i.reverse(),{paint_rules:r,label_rules:i,tasks:[]}}return ca;})(); /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */