gis-leaflet-helper 3.3.11 → 3.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4151,7 +4151,7 @@ function requireLeafletSrc() {
4151
4151
  polygonCenter,
4152
4152
  centroid
4153
4153
  };
4154
- function simplify(points, tolerance) {
4154
+ function simplify2(points, tolerance) {
4155
4155
  if (!tolerance || !points.length) {
4156
4156
  return points.slice();
4157
4157
  }
@@ -4334,7 +4334,7 @@ function requireLeafletSrc() {
4334
4334
  }
4335
4335
  var LineUtil = {
4336
4336
  __proto__: null,
4337
- simplify,
4337
+ simplify: simplify2,
4338
4338
  pointToSegmentDistance,
4339
4339
  closestPointOnSegment,
4340
4340
  clipSegment,
@@ -5660,7 +5660,7 @@ function requireLeafletSrc() {
5660
5660
  _simplifyPoints: function() {
5661
5661
  var parts = this._parts, tolerance = this.options.smoothFactor;
5662
5662
  for (var i = 0, len = parts.length; i < len; i++) {
5663
- parts[i] = simplify(parts[i], tolerance);
5663
+ parts[i] = simplify2(parts[i], tolerance);
5664
5664
  }
5665
5665
  },
5666
5666
  _update: function() {
@@ -19361,7 +19361,7 @@ function parse(code) {
19361
19361
  return code;
19362
19362
  }
19363
19363
  }
19364
- function extend(destination, source) {
19364
+ function extend$1(destination, source) {
19365
19365
  destination = destination || {};
19366
19366
  var value, property;
19367
19367
  if (!source) {
@@ -21336,8 +21336,8 @@ function Projection(srsCode, callback) {
21336
21336
  ecc.ep2,
21337
21337
  nadgrids
21338
21338
  );
21339
- extend(this, json);
21340
- extend(this, ourProj);
21339
+ extend$1(this, json);
21340
+ extend$1(this, ourProj);
21341
21341
  this.a = sphere_.a;
21342
21342
  this.b = sphere_.b;
21343
21343
  this.rf = sphere_.rf;
@@ -30085,14 +30085,14 @@ const Draw = leafletSrcExports.Handler.extend({
30085
30085
  }
30086
30086
  if (this._latlng && this._radius) {
30087
30087
  this._endAngle = ((_a = GeoUtil.calcBearAndDisByPoints(e.latlng, this._latlng)) == null ? void 0 : _a.angle) + 180;
30088
- if (this.sector) {
30089
- this.sector.setStyle({ startAngle: this._startAngle, endAngle: this._endAngle, ...this.style });
30088
+ if (this.geometry) {
30089
+ this.geometry.setStyle({ startAngle: this._startAngle, endAngle: this._endAngle, ...this.style });
30090
30090
  } else {
30091
30091
  const labelTextCollision = new LabelTextCollision({
30092
30092
  collisionFlg: true,
30093
30093
  padding: 0.5
30094
30094
  });
30095
- this.sector = new Sector(this._latlng, this._radius, {
30095
+ this.geometry = new Sector(this._latlng, this._radius, {
30096
30096
  renderer: labelTextCollision,
30097
30097
  startAngle: this._startAngle,
30098
30098
  endAngle: this._endAngle,
@@ -30117,9 +30117,10 @@ const Draw = leafletSrcExports.Handler.extend({
30117
30117
  }
30118
30118
  },
30119
30119
  _mouseDblClick(e) {
30120
- this.disable();
30121
30120
  this._map.removeLayer(this.tempPoint);
30122
- this.finishedCallback && this.finishedCallback(this.sector);
30121
+ this.onFinish && this.geometry && this.onFinish(this.geometry);
30122
+ !this.options.continue && this.disable();
30123
+ this.geometry = null;
30123
30124
  }
30124
30125
  },
30125
30126
  MarkerEvents: {
@@ -30780,7 +30781,7 @@ const MixinContextMenu = {
30780
30781
  }
30781
30782
  };
30782
30783
  const classes = [leafletSrcExports.Marker, leafletSrcExports.Path];
30783
- const defaultOptions = {
30784
+ const defaultOptions$1 = {
30784
30785
  contextmenu: false,
30785
30786
  contextmenuItems: [],
30786
30787
  contextmenuInheritItems: false
@@ -30788,9 +30789,9 @@ const defaultOptions = {
30788
30789
  for (let i = 0, l = classes.length; i < l; i++) {
30789
30790
  const cls = classes[i];
30790
30791
  if (!cls.prototype.options) {
30791
- cls.prototype.options = defaultOptions;
30792
+ cls.prototype.options = defaultOptions$1;
30792
30793
  } else {
30793
- cls.mergeOptions(defaultOptions);
30794
+ cls.mergeOptions(defaultOptions$1);
30794
30795
  }
30795
30796
  cls.addInitHook(function() {
30796
30797
  if (this.options.contextmenu) {
@@ -30921,6 +30922,784 @@ const LayerManager = leafletSrcExports.LayerGroup.extend({
30921
30922
  return rasterLayers.length ? Math.max(...rasterLayers.map((d) => d.options.zIndex)) + 1 : null;
30922
30923
  }
30923
30924
  });
30925
+ function simplify(coords, first, last, sqTolerance) {
30926
+ let maxSqDist = sqTolerance;
30927
+ const mid2 = first + (last - first >> 1);
30928
+ let minPosToMid = last - first;
30929
+ let index;
30930
+ const ax = coords[first];
30931
+ const ay = coords[first + 1];
30932
+ const bx = coords[last];
30933
+ const by = coords[last + 1];
30934
+ for (let i = first + 3; i < last; i += 3) {
30935
+ const d = getSqSegDist(coords[i], coords[i + 1], ax, ay, bx, by);
30936
+ if (d > maxSqDist) {
30937
+ index = i;
30938
+ maxSqDist = d;
30939
+ } else if (d === maxSqDist) {
30940
+ const posToMid = Math.abs(i - mid2);
30941
+ if (posToMid < minPosToMid) {
30942
+ index = i;
30943
+ minPosToMid = posToMid;
30944
+ }
30945
+ }
30946
+ }
30947
+ if (maxSqDist > sqTolerance) {
30948
+ if (index - first > 3) simplify(coords, first, index, sqTolerance);
30949
+ coords[index + 2] = maxSqDist;
30950
+ if (last - index > 3) simplify(coords, index, last, sqTolerance);
30951
+ }
30952
+ }
30953
+ function getSqSegDist(px, py, x, y, bx, by) {
30954
+ let dx = bx - x;
30955
+ let dy = by - y;
30956
+ if (dx !== 0 || dy !== 0) {
30957
+ const t = ((px - x) * dx + (py - y) * dy) / (dx * dx + dy * dy);
30958
+ if (t > 1) {
30959
+ x = bx;
30960
+ y = by;
30961
+ } else if (t > 0) {
30962
+ x += dx * t;
30963
+ y += dy * t;
30964
+ }
30965
+ }
30966
+ dx = px - x;
30967
+ dy = py - y;
30968
+ return dx * dx + dy * dy;
30969
+ }
30970
+ function createFeature(id, type, geom, tags) {
30971
+ const feature = {
30972
+ id: id == null ? null : id,
30973
+ type,
30974
+ geometry: geom,
30975
+ tags,
30976
+ minX: Infinity,
30977
+ minY: Infinity,
30978
+ maxX: -Infinity,
30979
+ maxY: -Infinity
30980
+ };
30981
+ if (type === "Point" || type === "MultiPoint" || type === "LineString") {
30982
+ calcLineBBox(feature, geom);
30983
+ } else if (type === "Polygon") {
30984
+ calcLineBBox(feature, geom[0]);
30985
+ } else if (type === "MultiLineString") {
30986
+ for (const line of geom) {
30987
+ calcLineBBox(feature, line);
30988
+ }
30989
+ } else if (type === "MultiPolygon") {
30990
+ for (const polygon of geom) {
30991
+ calcLineBBox(feature, polygon[0]);
30992
+ }
30993
+ }
30994
+ return feature;
30995
+ }
30996
+ function calcLineBBox(feature, geom) {
30997
+ for (let i = 0; i < geom.length; i += 3) {
30998
+ feature.minX = Math.min(feature.minX, geom[i]);
30999
+ feature.minY = Math.min(feature.minY, geom[i + 1]);
31000
+ feature.maxX = Math.max(feature.maxX, geom[i]);
31001
+ feature.maxY = Math.max(feature.maxY, geom[i + 1]);
31002
+ }
31003
+ }
31004
+ function convert(data, options) {
31005
+ const features = [];
31006
+ if (data.type === "FeatureCollection") {
31007
+ for (let i = 0; i < data.features.length; i++) {
31008
+ convertFeature(features, data.features[i], options, i);
31009
+ }
31010
+ } else if (data.type === "Feature") {
31011
+ convertFeature(features, data, options);
31012
+ } else {
31013
+ convertFeature(features, { geometry: data }, options);
31014
+ }
31015
+ return features;
31016
+ }
31017
+ function convertFeature(features, geojson, options, index) {
31018
+ if (!geojson.geometry) return;
31019
+ const coords = geojson.geometry.coordinates;
31020
+ if (coords && coords.length === 0) return;
31021
+ const type = geojson.geometry.type;
31022
+ const tolerance = Math.pow(options.tolerance / ((1 << options.maxZoom) * options.extent), 2);
31023
+ let geometry = [];
31024
+ let id = geojson.id;
31025
+ if (options.promoteId) {
31026
+ id = geojson.properties[options.promoteId];
31027
+ } else if (options.generateId) {
31028
+ id = index || 0;
31029
+ }
31030
+ if (type === "Point") {
31031
+ convertPoint(coords, geometry);
31032
+ } else if (type === "MultiPoint") {
31033
+ for (const p of coords) {
31034
+ convertPoint(p, geometry);
31035
+ }
31036
+ } else if (type === "LineString") {
31037
+ convertLine(coords, geometry, tolerance, false);
31038
+ } else if (type === "MultiLineString") {
31039
+ if (options.lineMetrics) {
31040
+ for (const line of coords) {
31041
+ geometry = [];
31042
+ convertLine(line, geometry, tolerance, false);
31043
+ features.push(createFeature(id, "LineString", geometry, geojson.properties));
31044
+ }
31045
+ return;
31046
+ } else {
31047
+ convertLines(coords, geometry, tolerance, false);
31048
+ }
31049
+ } else if (type === "Polygon") {
31050
+ convertLines(coords, geometry, tolerance, true);
31051
+ } else if (type === "MultiPolygon") {
31052
+ for (const polygon of coords) {
31053
+ const newPolygon = [];
31054
+ convertLines(polygon, newPolygon, tolerance, true);
31055
+ geometry.push(newPolygon);
31056
+ }
31057
+ } else if (type === "GeometryCollection") {
31058
+ for (const singleGeometry of geojson.geometry.geometries) {
31059
+ convertFeature(features, {
31060
+ id,
31061
+ geometry: singleGeometry,
31062
+ properties: geojson.properties
31063
+ }, options, index);
31064
+ }
31065
+ return;
31066
+ } else {
31067
+ throw new Error("Input data is not a valid GeoJSON object.");
31068
+ }
31069
+ features.push(createFeature(id, type, geometry, geojson.properties));
31070
+ }
31071
+ function convertPoint(coords, out) {
31072
+ out.push(projectX(coords[0]), projectY(coords[1]), 0);
31073
+ }
31074
+ function convertLine(ring, out, tolerance, isPolygon) {
31075
+ let x0, y0;
31076
+ let size = 0;
31077
+ for (let j = 0; j < ring.length; j++) {
31078
+ const x = projectX(ring[j][0]);
31079
+ const y = projectY(ring[j][1]);
31080
+ out.push(x, y, 0);
31081
+ if (j > 0) {
31082
+ if (isPolygon) {
31083
+ size += (x0 * y - x * y0) / 2;
31084
+ } else {
31085
+ size += Math.sqrt(Math.pow(x - x0, 2) + Math.pow(y - y0, 2));
31086
+ }
31087
+ }
31088
+ x0 = x;
31089
+ y0 = y;
31090
+ }
31091
+ const last = out.length - 3;
31092
+ out[2] = 1;
31093
+ simplify(out, 0, last, tolerance);
31094
+ out[last + 2] = 1;
31095
+ out.size = Math.abs(size);
31096
+ out.start = 0;
31097
+ out.end = out.size;
31098
+ }
31099
+ function convertLines(rings, out, tolerance, isPolygon) {
31100
+ for (let i = 0; i < rings.length; i++) {
31101
+ const geom = [];
31102
+ convertLine(rings[i], geom, tolerance, isPolygon);
31103
+ out.push(geom);
31104
+ }
31105
+ }
31106
+ function projectX(x) {
31107
+ return x / 360 + 0.5;
31108
+ }
31109
+ function projectY(y) {
31110
+ const sin = Math.sin(y * Math.PI / 180);
31111
+ const y2 = 0.5 - 0.25 * Math.log((1 + sin) / (1 - sin)) / Math.PI;
31112
+ return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
31113
+ }
31114
+ function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
31115
+ k1 /= scale;
31116
+ k2 /= scale;
31117
+ if (minAll >= k1 && maxAll < k2) return features;
31118
+ else if (maxAll < k1 || minAll >= k2) return null;
31119
+ const clipped = [];
31120
+ for (const feature of features) {
31121
+ const geometry = feature.geometry;
31122
+ let type = feature.type;
31123
+ const min = axis === 0 ? feature.minX : feature.minY;
31124
+ const max = axis === 0 ? feature.maxX : feature.maxY;
31125
+ if (min >= k1 && max < k2) {
31126
+ clipped.push(feature);
31127
+ continue;
31128
+ } else if (max < k1 || min >= k2) {
31129
+ continue;
31130
+ }
31131
+ let newGeometry = [];
31132
+ if (type === "Point" || type === "MultiPoint") {
31133
+ clipPoints(geometry, newGeometry, k1, k2, axis);
31134
+ } else if (type === "LineString") {
31135
+ clipLine(geometry, newGeometry, k1, k2, axis, false, options.lineMetrics);
31136
+ } else if (type === "MultiLineString") {
31137
+ clipLines(geometry, newGeometry, k1, k2, axis, false);
31138
+ } else if (type === "Polygon") {
31139
+ clipLines(geometry, newGeometry, k1, k2, axis, true);
31140
+ } else if (type === "MultiPolygon") {
31141
+ for (const polygon of geometry) {
31142
+ const newPolygon = [];
31143
+ clipLines(polygon, newPolygon, k1, k2, axis, true);
31144
+ if (newPolygon.length) {
31145
+ newGeometry.push(newPolygon);
31146
+ }
31147
+ }
31148
+ }
31149
+ if (newGeometry.length) {
31150
+ if (options.lineMetrics && type === "LineString") {
31151
+ for (const line of newGeometry) {
31152
+ clipped.push(createFeature(feature.id, type, line, feature.tags));
31153
+ }
31154
+ continue;
31155
+ }
31156
+ if (type === "LineString" || type === "MultiLineString") {
31157
+ if (newGeometry.length === 1) {
31158
+ type = "LineString";
31159
+ newGeometry = newGeometry[0];
31160
+ } else {
31161
+ type = "MultiLineString";
31162
+ }
31163
+ }
31164
+ if (type === "Point" || type === "MultiPoint") {
31165
+ type = newGeometry.length === 3 ? "Point" : "MultiPoint";
31166
+ }
31167
+ clipped.push(createFeature(feature.id, type, newGeometry, feature.tags));
31168
+ }
31169
+ }
31170
+ return clipped.length ? clipped : null;
31171
+ }
31172
+ function clipPoints(geom, newGeom, k1, k2, axis) {
31173
+ for (let i = 0; i < geom.length; i += 3) {
31174
+ const a = geom[i + axis];
31175
+ if (a >= k1 && a <= k2) {
31176
+ addPoint(newGeom, geom[i], geom[i + 1], geom[i + 2]);
31177
+ }
31178
+ }
31179
+ }
31180
+ function clipLine(geom, newGeom, k1, k2, axis, isPolygon, trackMetrics) {
31181
+ let slice = newSlice(geom);
31182
+ const intersect = axis === 0 ? intersectX : intersectY;
31183
+ let len = geom.start;
31184
+ let segLen, t;
31185
+ for (let i = 0; i < geom.length - 3; i += 3) {
31186
+ const ax2 = geom[i];
31187
+ const ay2 = geom[i + 1];
31188
+ const az2 = geom[i + 2];
31189
+ const bx = geom[i + 3];
31190
+ const by = geom[i + 4];
31191
+ const a2 = axis === 0 ? ax2 : ay2;
31192
+ const b = axis === 0 ? bx : by;
31193
+ let exited = false;
31194
+ if (trackMetrics) segLen = Math.sqrt(Math.pow(ax2 - bx, 2) + Math.pow(ay2 - by, 2));
31195
+ if (a2 < k1) {
31196
+ if (b > k1) {
31197
+ t = intersect(slice, ax2, ay2, bx, by, k1);
31198
+ if (trackMetrics) slice.start = len + segLen * t;
31199
+ }
31200
+ } else if (a2 > k2) {
31201
+ if (b < k2) {
31202
+ t = intersect(slice, ax2, ay2, bx, by, k2);
31203
+ if (trackMetrics) slice.start = len + segLen * t;
31204
+ }
31205
+ } else {
31206
+ addPoint(slice, ax2, ay2, az2);
31207
+ }
31208
+ if (b < k1 && a2 >= k1) {
31209
+ t = intersect(slice, ax2, ay2, bx, by, k1);
31210
+ exited = true;
31211
+ }
31212
+ if (b > k2 && a2 <= k2) {
31213
+ t = intersect(slice, ax2, ay2, bx, by, k2);
31214
+ exited = true;
31215
+ }
31216
+ if (!isPolygon && exited) {
31217
+ if (trackMetrics) slice.end = len + segLen * t;
31218
+ newGeom.push(slice);
31219
+ slice = newSlice(geom);
31220
+ }
31221
+ if (trackMetrics) len += segLen;
31222
+ }
31223
+ let last = geom.length - 3;
31224
+ const ax = geom[last];
31225
+ const ay = geom[last + 1];
31226
+ const az = geom[last + 2];
31227
+ const a = axis === 0 ? ax : ay;
31228
+ if (a >= k1 && a <= k2) addPoint(slice, ax, ay, az);
31229
+ last = slice.length - 3;
31230
+ if (isPolygon && last >= 3 && (slice[last] !== slice[0] || slice[last + 1] !== slice[1])) {
31231
+ addPoint(slice, slice[0], slice[1], slice[2]);
31232
+ }
31233
+ if (slice.length) {
31234
+ newGeom.push(slice);
31235
+ }
31236
+ }
31237
+ function newSlice(line) {
31238
+ const slice = [];
31239
+ slice.size = line.size;
31240
+ slice.start = line.start;
31241
+ slice.end = line.end;
31242
+ return slice;
31243
+ }
31244
+ function clipLines(geom, newGeom, k1, k2, axis, isPolygon) {
31245
+ for (const line of geom) {
31246
+ clipLine(line, newGeom, k1, k2, axis, isPolygon, false);
31247
+ }
31248
+ }
31249
+ function addPoint(out, x, y, z) {
31250
+ out.push(x, y, z);
31251
+ }
31252
+ function intersectX(out, ax, ay, bx, by, x) {
31253
+ const t = (x - ax) / (bx - ax);
31254
+ addPoint(out, x, ay + (by - ay) * t, 1);
31255
+ return t;
31256
+ }
31257
+ function intersectY(out, ax, ay, bx, by, y) {
31258
+ const t = (y - ay) / (by - ay);
31259
+ addPoint(out, ax + (bx - ax) * t, y, 1);
31260
+ return t;
31261
+ }
31262
+ function wrap(features, options) {
31263
+ const buffer = options.buffer / options.extent;
31264
+ let merged = features;
31265
+ const left = clip(features, 1, -1 - buffer, buffer, 0, -1, 2, options);
31266
+ const right = clip(features, 1, 1 - buffer, 2 + buffer, 0, -1, 2, options);
31267
+ if (left || right) {
31268
+ merged = clip(features, 1, -buffer, 1 + buffer, 0, -1, 2, options) || [];
31269
+ if (left) merged = shiftFeatureCoords(left, 1).concat(merged);
31270
+ if (right) merged = merged.concat(shiftFeatureCoords(right, -1));
31271
+ }
31272
+ return merged;
31273
+ }
31274
+ function shiftFeatureCoords(features, offset) {
31275
+ const newFeatures = [];
31276
+ for (let i = 0; i < features.length; i++) {
31277
+ const feature = features[i];
31278
+ const type = feature.type;
31279
+ let newGeometry;
31280
+ if (type === "Point" || type === "MultiPoint" || type === "LineString") {
31281
+ newGeometry = shiftCoords(feature.geometry, offset);
31282
+ } else if (type === "MultiLineString" || type === "Polygon") {
31283
+ newGeometry = [];
31284
+ for (const line of feature.geometry) {
31285
+ newGeometry.push(shiftCoords(line, offset));
31286
+ }
31287
+ } else if (type === "MultiPolygon") {
31288
+ newGeometry = [];
31289
+ for (const polygon of feature.geometry) {
31290
+ const newPolygon = [];
31291
+ for (const line of polygon) {
31292
+ newPolygon.push(shiftCoords(line, offset));
31293
+ }
31294
+ newGeometry.push(newPolygon);
31295
+ }
31296
+ }
31297
+ newFeatures.push(createFeature(feature.id, type, newGeometry, feature.tags));
31298
+ }
31299
+ return newFeatures;
31300
+ }
31301
+ function shiftCoords(points, offset) {
31302
+ const newPoints = [];
31303
+ newPoints.size = points.size;
31304
+ if (points.start !== void 0) {
31305
+ newPoints.start = points.start;
31306
+ newPoints.end = points.end;
31307
+ }
31308
+ for (let i = 0; i < points.length; i += 3) {
31309
+ newPoints.push(points[i] + offset, points[i + 1], points[i + 2]);
31310
+ }
31311
+ return newPoints;
31312
+ }
31313
+ function transformTile(tile, extent) {
31314
+ if (tile.transformed) return tile;
31315
+ const z2 = 1 << tile.z;
31316
+ const tx = tile.x;
31317
+ const ty = tile.y;
31318
+ for (const feature of tile.features) {
31319
+ const geom = feature.geometry;
31320
+ const type = feature.type;
31321
+ feature.geometry = [];
31322
+ if (type === 1) {
31323
+ for (let j = 0; j < geom.length; j += 2) {
31324
+ feature.geometry.push(transformPoint(geom[j], geom[j + 1], extent, z2, tx, ty));
31325
+ }
31326
+ } else {
31327
+ for (let j = 0; j < geom.length; j++) {
31328
+ const ring = [];
31329
+ for (let k = 0; k < geom[j].length; k += 2) {
31330
+ ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
31331
+ }
31332
+ feature.geometry.push(ring);
31333
+ }
31334
+ }
31335
+ }
31336
+ tile.transformed = true;
31337
+ return tile;
31338
+ }
31339
+ function transformPoint(x, y, extent, z2, tx, ty) {
31340
+ return [
31341
+ Math.round(extent * (x * z2 - tx)),
31342
+ Math.round(extent * (y * z2 - ty))
31343
+ ];
31344
+ }
31345
+ function createTile(features, z, tx, ty, options) {
31346
+ const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
31347
+ const tile = {
31348
+ features: [],
31349
+ numPoints: 0,
31350
+ numSimplified: 0,
31351
+ numFeatures: features.length,
31352
+ source: null,
31353
+ x: tx,
31354
+ y: ty,
31355
+ z,
31356
+ transformed: false,
31357
+ minX: 2,
31358
+ minY: 1,
31359
+ maxX: -1,
31360
+ maxY: 0
31361
+ };
31362
+ for (const feature of features) {
31363
+ addFeature(tile, feature, tolerance, options);
31364
+ }
31365
+ return tile;
31366
+ }
31367
+ function addFeature(tile, feature, tolerance, options) {
31368
+ const geom = feature.geometry;
31369
+ const type = feature.type;
31370
+ const simplified = [];
31371
+ tile.minX = Math.min(tile.minX, feature.minX);
31372
+ tile.minY = Math.min(tile.minY, feature.minY);
31373
+ tile.maxX = Math.max(tile.maxX, feature.maxX);
31374
+ tile.maxY = Math.max(tile.maxY, feature.maxY);
31375
+ if (type === "Point" || type === "MultiPoint") {
31376
+ for (let i = 0; i < geom.length; i += 3) {
31377
+ simplified.push(geom[i], geom[i + 1]);
31378
+ tile.numPoints++;
31379
+ tile.numSimplified++;
31380
+ }
31381
+ } else if (type === "LineString") {
31382
+ addLine(simplified, geom, tile, tolerance, false, false);
31383
+ } else if (type === "MultiLineString" || type === "Polygon") {
31384
+ for (let i = 0; i < geom.length; i++) {
31385
+ addLine(simplified, geom[i], tile, tolerance, type === "Polygon", i === 0);
31386
+ }
31387
+ } else if (type === "MultiPolygon") {
31388
+ for (let k = 0; k < geom.length; k++) {
31389
+ const polygon = geom[k];
31390
+ for (let i = 0; i < polygon.length; i++) {
31391
+ addLine(simplified, polygon[i], tile, tolerance, true, i === 0);
31392
+ }
31393
+ }
31394
+ }
31395
+ if (simplified.length) {
31396
+ let tags = feature.tags || null;
31397
+ if (type === "LineString" && options.lineMetrics) {
31398
+ tags = {};
31399
+ for (const key in feature.tags) tags[key] = feature.tags[key];
31400
+ tags["mapbox_clip_start"] = geom.start / geom.size;
31401
+ tags["mapbox_clip_end"] = geom.end / geom.size;
31402
+ }
31403
+ const tileFeature = {
31404
+ geometry: simplified,
31405
+ type: type === "Polygon" || type === "MultiPolygon" ? 3 : type === "LineString" || type === "MultiLineString" ? 2 : 1,
31406
+ tags
31407
+ };
31408
+ if (feature.id !== null) {
31409
+ tileFeature.id = feature.id;
31410
+ }
31411
+ tile.features.push(tileFeature);
31412
+ }
31413
+ }
31414
+ function addLine(result, geom, tile, tolerance, isPolygon, isOuter) {
31415
+ const sqTolerance = tolerance * tolerance;
31416
+ if (tolerance > 0 && geom.size < (isPolygon ? sqTolerance : tolerance)) {
31417
+ tile.numPoints += geom.length / 3;
31418
+ return;
31419
+ }
31420
+ const ring = [];
31421
+ for (let i = 0; i < geom.length; i += 3) {
31422
+ if (tolerance === 0 || geom[i + 2] > sqTolerance) {
31423
+ tile.numSimplified++;
31424
+ ring.push(geom[i], geom[i + 1]);
31425
+ }
31426
+ tile.numPoints++;
31427
+ }
31428
+ if (isPolygon) rewind(ring, isOuter);
31429
+ result.push(ring);
31430
+ }
31431
+ function rewind(ring, clockwise) {
31432
+ let area = 0;
31433
+ for (let i = 0, len = ring.length, j = len - 2; i < len; j = i, i += 2) {
31434
+ area += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
31435
+ }
31436
+ if (area > 0 === clockwise) {
31437
+ for (let i = 0, len = ring.length; i < len / 2; i += 2) {
31438
+ const x = ring[i];
31439
+ const y = ring[i + 1];
31440
+ ring[i] = ring[len - 2 - i];
31441
+ ring[i + 1] = ring[len - 1 - i];
31442
+ ring[len - 2 - i] = x;
31443
+ ring[len - 1 - i] = y;
31444
+ }
31445
+ }
31446
+ }
31447
+ const defaultOptions = {
31448
+ maxZoom: 14,
31449
+ // max zoom to preserve detail on
31450
+ indexMaxZoom: 5,
31451
+ // max zoom in the tile index
31452
+ indexMaxPoints: 1e5,
31453
+ // max number of points per tile in the tile index
31454
+ tolerance: 3,
31455
+ // simplification tolerance (higher means simpler)
31456
+ extent: 4096,
31457
+ // tile extent
31458
+ buffer: 64,
31459
+ // tile buffer on each side
31460
+ lineMetrics: false,
31461
+ // whether to calculate line metrics
31462
+ promoteId: null,
31463
+ // name of a feature property to be promoted to feature.id
31464
+ generateId: false,
31465
+ // whether to generate feature ids. Cannot be used with promoteId
31466
+ debug: 0
31467
+ // logging level (0, 1 or 2)
31468
+ };
31469
+ let GeoJSONVT$1 = class GeoJSONVT {
31470
+ constructor(data, options) {
31471
+ options = this.options = extend(Object.create(defaultOptions), options);
31472
+ const debug = options.debug;
31473
+ if (debug) console.time("preprocess data");
31474
+ if (options.maxZoom < 0 || options.maxZoom > 24) throw new Error("maxZoom should be in the 0-24 range");
31475
+ if (options.promoteId && options.generateId) throw new Error("promoteId and generateId cannot be used together.");
31476
+ let features = convert(data, options);
31477
+ this.tiles = {};
31478
+ this.tileCoords = [];
31479
+ if (debug) {
31480
+ console.timeEnd("preprocess data");
31481
+ console.log("index: maxZoom: %d, maxPoints: %d", options.indexMaxZoom, options.indexMaxPoints);
31482
+ console.time("generate tiles");
31483
+ this.stats = {};
31484
+ this.total = 0;
31485
+ }
31486
+ features = wrap(features, options);
31487
+ if (features.length) this.splitTile(features, 0, 0, 0);
31488
+ if (debug) {
31489
+ if (features.length) console.log("features: %d, points: %d", this.tiles[0].numFeatures, this.tiles[0].numPoints);
31490
+ console.timeEnd("generate tiles");
31491
+ console.log("tiles generated:", this.total, JSON.stringify(this.stats));
31492
+ }
31493
+ }
31494
+ // splits features from a parent tile to sub-tiles.
31495
+ // z, x, and y are the coordinates of the parent tile
31496
+ // cz, cx, and cy are the coordinates of the target tile
31497
+ //
31498
+ // If no target tile is specified, splitting stops when we reach the maximum
31499
+ // zoom or the number of points is low as specified in the options.
31500
+ splitTile(features, z, x, y, cz, cx, cy) {
31501
+ const stack = [features, z, x, y];
31502
+ const options = this.options;
31503
+ const debug = options.debug;
31504
+ while (stack.length) {
31505
+ y = stack.pop();
31506
+ x = stack.pop();
31507
+ z = stack.pop();
31508
+ features = stack.pop();
31509
+ const z2 = 1 << z;
31510
+ const id = toID(z, x, y);
31511
+ let tile = this.tiles[id];
31512
+ if (!tile) {
31513
+ if (debug > 1) console.time("creation");
31514
+ tile = this.tiles[id] = createTile(features, z, x, y, options);
31515
+ this.tileCoords.push({ z, x, y });
31516
+ if (debug) {
31517
+ if (debug > 1) {
31518
+ console.log("tile z%d-%d-%d (features: %d, points: %d, simplified: %d)", z, x, y, tile.numFeatures, tile.numPoints, tile.numSimplified);
31519
+ console.timeEnd("creation");
31520
+ }
31521
+ const key = `z${z}`;
31522
+ this.stats[key] = (this.stats[key] || 0) + 1;
31523
+ this.total++;
31524
+ }
31525
+ }
31526
+ tile.source = features;
31527
+ if (cz == null) {
31528
+ if (z === options.indexMaxZoom || tile.numPoints <= options.indexMaxPoints) continue;
31529
+ } else if (z === options.maxZoom || z === cz) {
31530
+ continue;
31531
+ } else if (cz != null) {
31532
+ const zoomSteps = cz - z;
31533
+ if (x !== cx >> zoomSteps || y !== cy >> zoomSteps) continue;
31534
+ }
31535
+ tile.source = null;
31536
+ if (features.length === 0) continue;
31537
+ if (debug > 1) console.time("clipping");
31538
+ const k1 = 0.5 * options.buffer / options.extent;
31539
+ const k2 = 0.5 - k1;
31540
+ const k3 = 0.5 + k1;
31541
+ const k4 = 1 + k1;
31542
+ let tl = null;
31543
+ let bl = null;
31544
+ let tr = null;
31545
+ let br = null;
31546
+ let left = clip(features, z2, x - k1, x + k3, 0, tile.minX, tile.maxX, options);
31547
+ let right = clip(features, z2, x + k2, x + k4, 0, tile.minX, tile.maxX, options);
31548
+ features = null;
31549
+ if (left) {
31550
+ tl = clip(left, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, options);
31551
+ bl = clip(left, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, options);
31552
+ left = null;
31553
+ }
31554
+ if (right) {
31555
+ tr = clip(right, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, options);
31556
+ br = clip(right, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, options);
31557
+ right = null;
31558
+ }
31559
+ if (debug > 1) console.timeEnd("clipping");
31560
+ stack.push(tl || [], z + 1, x * 2, y * 2);
31561
+ stack.push(bl || [], z + 1, x * 2, y * 2 + 1);
31562
+ stack.push(tr || [], z + 1, x * 2 + 1, y * 2);
31563
+ stack.push(br || [], z + 1, x * 2 + 1, y * 2 + 1);
31564
+ }
31565
+ }
31566
+ getTile(z, x, y) {
31567
+ z = +z;
31568
+ x = +x;
31569
+ y = +y;
31570
+ const options = this.options;
31571
+ const { extent, debug } = options;
31572
+ if (z < 0 || z > 24) return null;
31573
+ const z2 = 1 << z;
31574
+ x = x + z2 & z2 - 1;
31575
+ const id = toID(z, x, y);
31576
+ if (this.tiles[id]) return transformTile(this.tiles[id], extent);
31577
+ if (debug > 1) console.log("drilling down to z%d-%d-%d", z, x, y);
31578
+ let z0 = z;
31579
+ let x0 = x;
31580
+ let y0 = y;
31581
+ let parent;
31582
+ while (!parent && z0 > 0) {
31583
+ z0--;
31584
+ x0 = x0 >> 1;
31585
+ y0 = y0 >> 1;
31586
+ parent = this.tiles[toID(z0, x0, y0)];
31587
+ }
31588
+ if (!parent || !parent.source) return null;
31589
+ if (debug > 1) {
31590
+ console.log("found parent tile z%d-%d-%d", z0, x0, y0);
31591
+ console.time("drilling down");
31592
+ }
31593
+ this.splitTile(parent.source, z0, x0, y0, z, x, y);
31594
+ if (debug > 1) console.timeEnd("drilling down");
31595
+ return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
31596
+ }
31597
+ };
31598
+ function toID(z, x, y) {
31599
+ return ((1 << z) * y + x) * 32 + z;
31600
+ }
31601
+ function extend(dest, src) {
31602
+ for (const i in src) dest[i] = src[i];
31603
+ return dest;
31604
+ }
31605
+ function geojsonvt(data, options) {
31606
+ return new GeoJSONVT$1(data, options);
31607
+ }
31608
+ const GeoJSONVT2 = L.GridLayer.extend({
31609
+ options: {
31610
+ async: false
31611
+ },
31612
+ initialize: function(geojson, options) {
31613
+ L.setOptions(this, options);
31614
+ L.GridLayer.prototype.initialize.call(this, options);
31615
+ this.tileIndex = geojsonvt(geojson, this.options);
31616
+ },
31617
+ createTile: function(coords) {
31618
+ var tile = L.DomUtil.create("canvas", "leaflet-tile");
31619
+ var size = this.getTileSize();
31620
+ tile.width = size.x;
31621
+ tile.height = size.y;
31622
+ var ctx = tile.getContext("2d");
31623
+ var tileInfo = this.tileIndex.getTile(coords.z, coords.x, coords.y);
31624
+ var features = tileInfo ? tileInfo.features : [];
31625
+ console.log(111, features.length);
31626
+ for (var i = 0; i < features.length; i++) {
31627
+ var feature = features[i];
31628
+ this.drawFeature(ctx, feature);
31629
+ }
31630
+ return tile;
31631
+ },
31632
+ drawFeature: function(ctx, feature) {
31633
+ type !== feature.type;
31634
+ var type = feature.type;
31635
+ ctx.beginPath();
31636
+ if (this.options.style) this.options.style instanceof Function ? this.setStyle(ctx, this.options.style(feature.tags)) : this.setStyle(ctx, this.options.style);
31637
+ if (type === 2 || type === 3) {
31638
+ for (var j = 0; j < feature.geometry.length; j++) {
31639
+ var ring = feature.geometry[j];
31640
+ for (var k = 0; k < ring.length; k++) {
31641
+ var p = ring[k];
31642
+ if (k) ctx.lineTo(p[0] / 16, p[1] / 16);
31643
+ else ctx.moveTo(p[0] / 16, p[1] / 16);
31644
+ }
31645
+ }
31646
+ } else if (type === 1) {
31647
+ for (var j = 0; j < feature.geometry.length; j++) {
31648
+ var p = feature.geometry[j];
31649
+ ctx.arc(p[0] / 16, p[1] / 16, 2, 0, Math.PI * 2, true);
31650
+ }
31651
+ }
31652
+ if (type === 3) ctx.fill(this.options.style.fillRule || "evenodd");
31653
+ ctx.stroke();
31654
+ },
31655
+ setStyle: function(ctx, style) {
31656
+ style.stroke || true;
31657
+ {
31658
+ ctx.lineWidth = style.weight || 5;
31659
+ var color = this.setOpacity(style.color, style.opacity);
31660
+ ctx.strokeStyle = color;
31661
+ }
31662
+ style.fill || true;
31663
+ {
31664
+ ctx.fillStyle = style.fillColor || "#03f";
31665
+ var color = this.setOpacity(style.fillColor, style.fillOpacity);
31666
+ ctx.fillStyle = color;
31667
+ }
31668
+ },
31669
+ setOpacity: function(color, opacity) {
31670
+ if (opacity) {
31671
+ var color = color || "#03f";
31672
+ if (color.iscolorHex()) {
31673
+ var colorRgb = color.colorRgb();
31674
+ return "rgba(" + colorRgb[0] + "," + colorRgb[1] + "," + colorRgb[2] + "," + opacity + ")";
31675
+ } else {
31676
+ return color;
31677
+ }
31678
+ } else {
31679
+ return color;
31680
+ }
31681
+ }
31682
+ });
31683
+ String.prototype.iscolorHex = function() {
31684
+ var sColor = this.toLowerCase();
31685
+ var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
31686
+ return reg.test(sColor);
31687
+ };
31688
+ String.prototype.colorRgb = function() {
31689
+ var sColor = this.toLowerCase();
31690
+ if (sColor.length === 4) {
31691
+ var sColorNew = "#";
31692
+ for (var i = 1; i < 4; i += 1) {
31693
+ sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1));
31694
+ }
31695
+ sColor = sColorNew;
31696
+ }
31697
+ var sColorChange = [];
31698
+ for (var i = 1; i < 7; i += 2) {
31699
+ sColorChange.push(parseInt("0x" + sColor.slice(i, i + 2)));
31700
+ }
31701
+ return sColorChange;
31702
+ };
30924
31703
  function injectCss(cls) {
30925
31704
  const myStyle = document.createElement("style");
30926
31705
  const doc = document.head || document.documentElement;
@@ -31185,6 +31964,14 @@ function injectCss(cls) {
31185
31964
  container.style.cursor = `url(${cursor}), auto`;
31186
31965
  }
31187
31966
  },
31967
+ setBackground: function(background) {
31968
+ const container = this.getContainer();
31969
+ if (Color.isColor(background)) {
31970
+ container.style.backgroundColor = background;
31971
+ } else {
31972
+ container.style.background = `url(${background}), no-repeat center center / cover`;
31973
+ }
31974
+ },
31188
31975
  flyTo(target, zoom = 0, options = { animate: false }) {
31189
31976
  if (target instanceof L.Marker) {
31190
31977
  target = target._latlng;
@@ -31245,6 +32032,7 @@ function injectCss(cls) {
31245
32032
  _L.PolylineDecorator = PolylineDecorator;
31246
32033
  _L.RadarCircle = RadarCircle;
31247
32034
  _L.Plot = Plot$1;
32035
+ _L.GeoJSON.VT = GeoJSONVT2;
31248
32036
  return _this.L = _L;
31249
32037
  })(window);
31250
32038
  export {