From 04a4adfe3654c6adf8a4f94bf5732be334801d8b Mon Sep 17 00:00:00 2001 From: Matthew Bloch Date: Fri, 22 Mar 2024 14:06:04 -0400 Subject: [PATCH] Update website --- mapshaper-gui.js | 139 ++++++++++++++++++++++------------------------- page.css | 4 ++ 2 files changed, 68 insertions(+), 75 deletions(-) diff --git a/mapshaper-gui.js b/mapshaper-gui.js index b82bfc2b..4ee28581 100644 --- a/mapshaper-gui.js +++ b/mapshaper-gui.js @@ -5468,7 +5468,7 @@ labels: 'position labels', location: 'drag points', vertices: 'edit vertices', - selection: 'select features', + selection: 'selection tool', 'add-points': 'add points', drawing: 'draw/reshape tool', rectangles: 'drag-to-resize', @@ -9719,7 +9719,7 @@ } } - // pointer thresholds for hovering near a vertex or segment midpoint + // pixel distance threshold for hovering near a vertex or segment midpoint var HOVER_THRESHOLD$1 = 10; function initLineEditing(gui, ext, hit) { @@ -9789,27 +9789,10 @@ appendVertex$1(target, e.p); } if (e.shapes) { - replaceShapes(e.shapes); + replaceDrawnShapes(e.shapes); } }); - function replaceShapes(shapes) { - var target = hit.getHitTarget(); - var records = target.layer.data?.getRecords(); - var prevLen = target.layer.shapes.length; - var newLen = initialShapeCount + shapes.length; - var recordCount = records?.length || 0; - target.layer.shapes = target.layer.shapes.slice(0, initialShapeCount).concat(shapes); - while (records && records.length > newLen) { - records.pop(); - } - while (records && records.length < newLen) { - appendNewDataRecord(target.layer); - } - } - - - gui.on('undo_path_extend', function(e) { var target = hit.getHitTarget(); if (drawing() && prevHoverEvent) { @@ -9822,7 +9805,7 @@ gui.undo.undo(); // remove the path } if (e.shapes) { - replaceShapes(e.shapes); + replaceDrawnShapes(e.shapes); } }); @@ -9845,6 +9828,12 @@ non_blocking: true, max_width: '360px'}); } + function hideInstructions() { + if (!alert) return; + alert.close('fade'); + alert = null; + } + function turnOff() { var removed = 0; finishCurrentPath(); @@ -9852,10 +9841,7 @@ removed = removeOpenPolygons(); } clearDrawingInfo(); - if (alert) { - alert.close(); - alert = null; - } + hideInstructions(); initialArcCount = -1; initialShapeCount = -1; if (gui.interaction.getMode() == 'drawing') { @@ -9872,18 +9858,19 @@ var target = hit.getHitTarget(); var arcs = target.source.dataset.arcs; var n = target.layer.shapes.length; - // delete open paths (should only occur on single-arc shapes) + // delete open paths for (var i=initialShapeCount; i newLen) { + records.pop(); + } + while (records && records.length < newLen) { + appendNewDataRecord(target.layer); + } } // p: [x, y] source data coordinates @@ -10187,10 +10190,6 @@ y1 = yy[i], x2 = xx[j], y2 = yy[j], - // switching from midpoint to nearest point to the mouse - // cx = (x1 + x2) / 2, - // cy = (y1 + y2) / 2, - // p2 = [cx, cy], p2 = internal.findClosestPointOnSeg(p[0], p[1], x1, y1, x2, y2, 0), dist = geom.distance2D(p2[0], p2[1], p[0], p[1]); if (dist < minDist) { @@ -10212,49 +10211,39 @@ return closest; } - // shapes: shapes that have been drawn in the current session - // - function tryToClosePath(shapes) { + // Try to form polygon shapes from an array of path shapes + // shapes: array of all shapes that have been drawn in the current session + function convertClosedPaths(shapes) { var target = hit.getHitTarget(); + // try to convert paths to polygons + // NOTE: added "no_cuts" option to prevent polygons function from modifying + // arcs, which would break undo/redo and cause other problems var tmpLyr = { geometry_type: 'polyline', shapes: shapes.concat() }; - // create a temp dataset containing tmp layer and original layers - // (so original arcs are retained) - var tmpDataset = Object.assign({}, target.source.dataset); - tmpDataset.layers = tmpDataset.layers.concat(tmpLyr); - // NOTE: added "no_cuts" option to prevent polygons function from modifying - // arcs, which would break undo/redo and cause other problems - var outputLyr = mapshaper.cmd.polygons([tmpLyr], tmpDataset, {no_cuts: true})[0]; - var isOpenPath = getOpenPathTest(outputLyr.shapes); - var shapes2 = []; - shapes.forEach(function(shp) { - if (isOpenPath(shp)) { - shapes2.push(shp); - } - }); - return shapes2.concat(outputLyr.shapes); + var output = mapshaper.cmd.polygons([tmpLyr], target.source.dataset, {no_cuts: true}); + var closedShapes = output[0].shapes; + + // find paths that were not convertible to polygons + var isOpenPath = getOpenPathTest(closedShapes); + var openShapes = shapes.filter(function(shp) { return isOpenPath(shp); }); + + // retain both converted polygons and unconverted polylines + return openShapes.concat(closedShapes); } // Returns a function for testing if a shape is an unclosed path, and doesn't // overlap with an array of polygon shapes - // polygons: array of polygon shapes - function getOpenPathTest(polygons) { - var arcs = []; - internal.forEachArcId(polygons, function(arcId) { - if (arcId < 0) arcId = ~arcId; - arcs.push(arcId); + function getOpenPathTest(polygonShapes) { + var polygonArcs = []; + internal.forEachArcId(polygonShapes, function(arcId) { + polygonArcs.push(internal.absArcId(arcId)); }); + return function(shp) { - // assume that compound shapes are already polygons - var isOpen = false; - if (shapeHasOneFwdArc(shp)) { - var arcId = shp[0][0]; - if (arcId < 0) arcId = ~arcId; - isOpen = !arcs.includes(arcId); - } - return isOpen; + // assume that any compound shape is a polygon + return shapeHasOneFwdArc(shp) && !polygonArcs.includes(shp[0][0]); }; } diff --git a/page.css b/page.css index 6f280ec1..a008cf96 100644 --- a/page.css +++ b/page.css @@ -1220,6 +1220,10 @@ div.basemap-style-btn.active img { cursor: crosshair; } +.map-layers.drawing.dragging { + cursor: default; +} + .map-layers canvas { pointer-events: none; position: absolute;