mapshaper 0.5.95 → 0.5.98

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mapshaper",
3
- "version": "0.5.95",
3
+ "version": "0.5.98",
4
4
  "description": "A tool for editing vector datasets for mapping and GIS.",
5
5
  "keywords": [
6
6
  "shapefile",
@@ -5623,14 +5623,11 @@
5623
5623
  }
5624
5624
 
5625
5625
  function vertexTest(x, y) {
5626
- var maxDist = getZoomAdjustedHitBuffer(20, 2),
5627
- bufDist = getZoomAdjustedHitBuffer(0.05), // tiny threshold for hitting almost-identical lines
5626
+ var maxDist = getZoomAdjustedHitBuffer(25, 2),
5628
5627
  cands = findHitCandidates(x, y, maxDist);
5629
5628
  sortByDistance(x, y, cands, displayLayer.arcs);
5630
- cands = pickNearestCandidates(cands, bufDist, maxDist);
5631
- var arcs = cands.map(function(cand) { return absArcId(cand.info.arcId); });
5629
+ cands = pickNearestCandidates(cands, 0, maxDist);
5632
5630
  return {
5633
- arcs: utils$1.uniq(arcs),
5634
5631
  ids: utils$1.pluck(cands, 'id')
5635
5632
  };
5636
5633
  }
@@ -7538,10 +7535,10 @@
7538
7535
 
7539
7536
  // pointer thresholds for hovering near a vertex or segment midpoint
7540
7537
  var HOVER_THRESHOLD = 8;
7541
- var MIDPOINT_THRESHOLD = 12;
7538
+ var MIDPOINT_THRESHOLD = 11;
7542
7539
 
7543
7540
  function initVertexDragging(gui, ext, hit) {
7544
- var activeMidpoint;
7541
+ var insertionPoint;
7545
7542
  var dragInfo;
7546
7543
 
7547
7544
  function active() {
@@ -7559,7 +7556,6 @@
7559
7556
 
7560
7557
  function clearHoverVertex() {
7561
7558
  hit.clearVertexOverlay();
7562
- // gui.state.vertex_overlay = null;
7563
7559
  }
7564
7560
 
7565
7561
  function findDraggableVertices(e) {
@@ -7580,17 +7576,28 @@
7580
7576
  };
7581
7577
  }
7582
7578
 
7579
+ function findVertexInsertionPoint(e) {
7580
+ var target = hit.getHitTarget();
7581
+ if (!target.arcs.isFlat()) return null; // vertex insertion not supported with simplification
7582
+ var p = ext.translatePixelCoords(e.x, e.y);
7583
+ var shp = target.layer.shapes[e.id];
7584
+ var midpoint = findNearestMidpoint(p, shp, target.arcs);
7585
+ if (!midpoint ||
7586
+ midpoint.distance / ext.getPixelSize() > MIDPOINT_THRESHOLD) return null;
7587
+ return midpoint;
7588
+ }
7589
+
7583
7590
  hit.on('dragstart', function(e) {
7584
7591
  if (!active()) return;
7585
- if (activeMidpoint) {
7592
+ if (insertionPoint) {
7586
7593
  var target = hit.getHitTarget();
7587
- internal.insertVertex(target.arcs, activeMidpoint.i, activeMidpoint.point);
7594
+ internal.insertVertex(target.arcs, insertionPoint.i, insertionPoint.point);
7588
7595
  dragInfo = {
7589
7596
  insertion: true,
7590
- ids: [activeMidpoint.i],
7591
- points: [activeMidpoint.point]
7597
+ ids: [insertionPoint.i],
7598
+ points: [insertionPoint.point]
7592
7599
  };
7593
- activeMidpoint = null;
7600
+ insertionPoint = null;
7594
7601
  } else {
7595
7602
  dragInfo = findDraggableVertices(e);
7596
7603
  }
@@ -7643,7 +7650,7 @@
7643
7650
 
7644
7651
  // highlight hit vertex in path edit mode
7645
7652
  hit.on('hover', function(e) {
7646
- activeMidpoint = null;
7653
+ insertionPoint = null;
7647
7654
  if (!active() || dragging()) return; // no hover effect while dragging
7648
7655
  var info = findDraggableVertices(e);
7649
7656
  if (info) {
@@ -7652,32 +7659,20 @@
7652
7659
  return;
7653
7660
  }
7654
7661
  // if hovering near a segment midpoint: show the midpoint and save midpoint info
7655
- var p = ext.translatePixelCoords(e.x, e.y);
7656
- var target = hit.getHitTarget();
7657
- var shp = target.layer.shapes[e.id];
7658
- var midpoint = findNearestMidpoint(p, shp, target.arcs);
7659
- if (midpoint &&
7660
- midpoint.distance / ext.getPixelSize() < MIDPOINT_THRESHOLD &&
7661
- target.arcs.isFlat()) { // vertex insertion not supported with simplification
7662
- hit.setHoverVertex(midpoint.point);
7663
- activeMidpoint = midpoint;
7664
- return;
7662
+ insertionPoint = findVertexInsertionPoint(e);
7663
+ if (insertionPoint) {
7664
+ hit.setHoverVertex(insertionPoint.point);
7665
+ } else {
7666
+ // pointer is not over a vertex: clear any hover effect
7667
+ clearHoverVertex();
7665
7668
  }
7666
- // pointer is not over a vertex or midpoint: clear hover effect
7667
- clearHoverVertex();
7668
7669
  }, null, 100);
7669
7670
  }
7670
7671
 
7672
+
7671
7673
  // Given a location @p (e.g. corresponding to the mouse pointer location),
7672
- // find the midpoint of two vertices on @shp suitable for inserting a new vertex,
7673
- // but only if:
7674
- // 1. point @p is closer to the midpoint than either adjacent vertex
7675
- // 2. the segment containing @p is longer than a minimum distance in pixels.
7676
- //
7674
+ // find the midpoint of two vertices on @shp suitable for inserting a new vertex
7677
7675
  function findNearestMidpoint(p, shp, arcs) {
7678
- // var v1 = internal.findNearestVertex(p[0], p[1], shp, arcs);
7679
- // var v0 = internal.findAdjacentVertex(v1, shp, arcs, -1);
7680
- // var v2 = internal.findAdjacentVertex(v1, shp, arcs, 1);
7681
7676
  var minDist = Infinity, v;
7682
7677
  internal.forEachSegmentInShape(shp, arcs, function(i, j, xx, yy) {
7683
7678
  var x1 = xx[i],
@@ -7692,6 +7687,7 @@
7692
7687
  v = {
7693
7688
  i: (i < j ? i : j) + 1, // insertion point
7694
7689
  segment: [i, j],
7690
+ segmentLen: geom.distance2D(x1, y1, x2, y2),
7695
7691
  point: [cx, cy],
7696
7692
  distance: dist
7697
7693
  };
@@ -7874,6 +7870,20 @@
7874
7870
  return style;
7875
7871
  }
7876
7872
 
7873
+ // style for vertex edit mode
7874
+ function getVertexStyle(lyr, o) {
7875
+ return {
7876
+ ids: o.ids,
7877
+ overlay: true,
7878
+ strokeColor: black,
7879
+ strokeWidth: 1.5,
7880
+ vertices: true,
7881
+ vertex_overlay: o.hit_coordinates || null,
7882
+ selected_points: o.selected_points || null,
7883
+ fillColor: null
7884
+ };
7885
+ }
7886
+
7877
7887
  // Returns a display style for the overlay layer.
7878
7888
  // The overlay layer renders several kinds of feature, each of which is displayed
7879
7889
  // with a different style.
@@ -7883,18 +7893,14 @@
7883
7893
  // * pinned shapes
7884
7894
  //
7885
7895
  function getOverlayStyle(lyr, o) {
7896
+ if (o.mode == 'vertices') {
7897
+ return getVertexStyle(lyr, o);
7898
+ }
7886
7899
  var geomType = lyr.geometry_type;
7887
7900
  var topId = o.id; // pinned id (if pinned) or hover id
7888
7901
  var topIdx = -1;
7889
7902
  var styler = function(style, i) {
7890
7903
  utils$1.extend(style, i === topIdx ? topStyle: baseStyle);
7891
- // kludge to show vertices when editing path shapes
7892
- if (o.mode == 'vertices') {
7893
- style.vertices = true;
7894
- style.vertex_overlay = o.hit_coordinates || null;
7895
- style.selected_points = o.selected_points || null;
7896
- style.fillColor = null;
7897
- }
7898
7904
  };
7899
7905
  var baseStyle = getDefaultStyle(lyr, selectionStyles[geomType]);
7900
7906
  var topStyle;
@@ -7906,18 +7912,26 @@
7906
7912
  topIdx = ids.length;
7907
7913
  ids.push(o.id); // put the pinned/hover feature last in the render order
7908
7914
  }
7909
- var overlayStyle = {
7915
+ var style = {
7910
7916
  styler: styler,
7911
7917
  ids: ids,
7912
7918
  overlay: true
7913
7919
  };
7920
+ // kludge to show vertices when editing path shapes
7921
+ if (o.mode == 'vertices') {
7922
+ style.vertices = true;
7923
+ style.vertex_overlay = o.hit_coordinates || null;
7924
+ style.selected_points = o.selected_points || null;
7925
+ style.fillColor = null;
7926
+ }
7927
+
7914
7928
  if (layerHasCanvasDisplayStyle(lyr)) {
7915
7929
  if (geomType == 'point') {
7916
- overlayStyle.styler = getOverlayPointStyler(getCanvasDisplayStyle(lyr).styler, styler);
7930
+ style.styler = getOverlayPointStyler(getCanvasDisplayStyle(lyr).styler, styler);
7917
7931
  }
7918
- overlayStyle.type = 'styled';
7932
+ style.type = 'styled';
7919
7933
  }
7920
- return ids.length > 0 ? overlayStyle : null;
7934
+ return ids.length > 0 ? style : null;
7921
7935
  }
7922
7936
 
7923
7937
  function getSelectedFeatureStyle(lyr, o) {
@@ -8365,9 +8379,10 @@
8365
8379
  _self.drawVertices = function(shapes, arcs, style, filter) {
8366
8380
  var iter = new internal.ShapeIter(arcs);
8367
8381
  var t = getScaledTransform(_ext);
8382
+ var bounds = _ext.getBounds();
8368
8383
  var radius = (style.strokeWidth > 2 ? style.strokeWidth * 0.9 : 2) * GUI.getPixelRatio() * getScaledLineScale(_ext);
8369
8384
  var color = style.strokeColor || 'black';
8370
- var radius2 = radius * 1.7;
8385
+
8371
8386
  var i, j, p;
8372
8387
  _ctx.beginPath();
8373
8388
  _ctx.fillStyle = color;
@@ -8377,6 +8392,7 @@
8377
8392
  for (j=0; j<shp.length; j++) {
8378
8393
  iter.init(shp[j]);
8379
8394
  while (iter.hasNext()) {
8395
+ if (!bounds.containsPoint(iter.x, iter.y)) continue;
8380
8396
  drawCircle(iter.x * t.mx + t.bx, iter.y * t.my + t.by, radius, _ctx);
8381
8397
  }
8382
8398
  }
@@ -8384,7 +8400,7 @@
8384
8400
 
8385
8401
  if (style.vertex_overlay) {
8386
8402
  p = style.vertex_overlay;
8387
- drawCircle(p[0] * t.mx + t.bx, p[1] * t.my + t.by, radius2, _ctx);
8403
+ drawCircle(p[0] * t.mx + t.bx, p[1] * t.my + t.by, radius * 1.5, _ctx);
8388
8404
  }
8389
8405
  _ctx.fill();
8390
8406
  _ctx.closePath();