Skip to content

Commit

Permalink
Update website
Browse files Browse the repository at this point in the history
  • Loading branch information
mbloch committed Jul 13, 2023
1 parent 030e17c commit bc9a490
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 24 deletions.
27 changes: 17 additions & 10 deletions mapshaper-gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -4038,8 +4038,11 @@
}

function updateMenuBtn() {
var name = model.getActiveLayer().layer.name || "[unnamed layer]";
btn.classed('active', 'true').findChild('.layer-name').html(name + "  ▼");
var lyrName = model.getActiveLayer().layer.name || '';
var menuTitle = lyrName || '[unnamed layer]';
var pageTitle = lyrName || 'mapshaper';
btn.classed('active', 'true').findChild('.layer-name').html(menuTitle + "  ▼");
window.document.title = pageTitle;
}

function render() {
Expand Down Expand Up @@ -10172,12 +10175,12 @@
return action == 'hover' && _overlayCanv.visible();
}

function drawCanvasLayer(target, canv) {
if (!target) return;
if (target.style.type == 'outline') {
drawOutlineLayerToCanvas(target, canv, ext);
function drawCanvasLayer(lyr, canv) {
if (!lyr) return;
if (lyr.style.type == 'outline') {
drawOutlineLayerToCanvas(lyr, canv, ext);
} else {
drawStyledLayerToCanvas(target, canv, ext);
drawStyledLayerToCanvas(lyr, canv, ext);
}
}

Expand Down Expand Up @@ -11039,7 +11042,9 @@
} else {
_overlayLyr = null;
}
drawLayers('hover');
// 'hover' bypasses style creation in drawLayers2()... sometimes we need that
// drawLayers('hover');
drawLayers();
}

function getDisplayOptions() {
Expand All @@ -11054,12 +11059,14 @@
return flags.simplify_method || flags.simplify || flags.proj ||
flags.arc_count || flags.repair || flags.clip || flags.erase ||
flags.slice || flags.affine || flags.rectangle || flags.buffer ||
flags.union || flags.mosaic || flags.snap || flags.clean || false;
flags.union || flags.mosaic || flags.snap || flags.clean || flags.drop || false;
}

// Test if an update allows hover popup to stay open
function popupCanStayOpen(flags) {
// if (arcsMayHaveChanged(flags)) return false;
// keeping popup open after -drop geometry causes problems...
// // if (arcsMayHaveChanged(flags)) return false;
if (arcsMayHaveChanged(flags)) return false;
if (flags.points || flags.proj) return false;
if (!flags.same_table) return false;
return true;
Expand Down
55 changes: 41 additions & 14 deletions mapshaper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function () {

var VERSION = "0.6.32";
var VERSION = "0.6.33";


var utils = /*#__PURE__*/Object.freeze({
Expand Down Expand Up @@ -11665,15 +11665,24 @@
}
cands.forEach(function(cand) {
var p = getTestPoint(cand.ids);
var isEnclosed = b.containsPoint(p[0], p[1]) && (index ?
index.pointInPolygon(p[0], p[1]) : geom.testPointInRing(p[0], p[1], pathIds, arcs));
var isEnclosed = b.containsPoint(p[0], p[1]) &&
// added a bounds-in-bounds test to handle a case where the test point
// fell along the shared boundary of two rings, but the rings did no overlap
// (this gave a false positive for the enclosure test)
// (for speed, the midpoint of an arc is used as the test point; this
// works well in the typical case where rings to not share an edge.
// Finding an internal test point would be better, we just need a fast
// function to find internal points)
b.contains(cand.bounds) &&
(index ? index.pointInPolygon(p[0], p[1]) : geom.testPointInRing(p[0], p[1], pathIds, arcs));
if (isEnclosed) {
paths.push(cand.ids);
}
});
return paths.length > 0 ? paths : null;
};

// return array of indexed paths within a given shape
this.findPathsInsideShape = function(shape) {
var paths = []; // list of enclosed paths
shape.forEach(function(ids) {
Expand Down Expand Up @@ -12075,7 +12084,6 @@
yy = coords.yy,
ids = nodes.getConnectedArcs(fromArcId),
toArcId = fromArcId; // initialize to fromArcId -- an error condition

if (filter) {
ids = ids.filter(filter);
}
Expand Down Expand Up @@ -12104,21 +12112,20 @@
continue;
}
icand = arcs.indexOfVertex(candId, -2);

if (toArcId == fromArcId) {
// first valid candidate
ito = icand;
toArcId = candId;
continue;
}

code = chooseRighthandPath(fromX, fromY, nodeX, nodeY, xx[ito], yy[ito], xx[icand], yy[icand]);
if (code == 2) {
ito = icand;
toArcId = candId;
}
}


if (toArcId == fromArcId) {
// This shouldn't occur, assuming that other arcs are present
error("Pathfinder error");
Expand Down Expand Up @@ -12183,6 +12190,9 @@
chooseRighthandVector: chooseRighthandVector
});

var FWD_USED = 0x8;
var REV_USED = 0x80;

function setBits(bits, arcBits, mask) {
return (bits & ~mask) | (arcBits & mask);
}
Expand Down Expand Up @@ -12210,6 +12220,16 @@
return bits & 7;
}

function markPathsAsUsed(paths, routesArr) {
forEachArcId(paths, function(arcId) {
if (arcId < 0) {
routesArr[~arcId] |= REV_USED;
} else {
routesArr[arcId] |= FWD_USED;
}
});
}

// Open arc pathways in a single shape or array of shapes
//
function openArcRoutes(paths, arcColl, routesArr, fwd, rev, dissolve, orBits) {
Expand Down Expand Up @@ -12400,6 +12420,7 @@
andBits: andBits,
setRouteBits: setRouteBits,
getRouteBits: getRouteBits,
markPathsAsUsed: markPathsAsUsed,
openArcRoutes: openArcRoutes,
closeArcRoutes: closeArcRoutes,
getPathFinder: getPathFinder,
Expand Down Expand Up @@ -33401,7 +33422,7 @@ ${svg}
var clipArcTouches = 0;
var clipArcUses = 0;
var usedClipArcs = [];
var dividePath = getPathFinder(nodes, useRoute, routeIsActive);
var findPath = getPathFinder(nodes, useRoute, routeIsActive);
var dissolvePolygon = getPolygonDissolver(nodes);

// The following cleanup step is a performance bottleneck (it often takes longer than
Expand Down Expand Up @@ -33434,12 +33455,16 @@ ${svg}
return null;
});

markPathsAsUsed(clippedShapes, routeFlags); // to help us find unused paths later


// add clip/erase polygons that are fully contained in a target polygon
// need to index only non-intersecting clip shapes
// (Intersecting shapes have one or more arcs that have been scanned)

// first, find shapes that do not intersect the target layer
// (these could be inside or outside the target polygons)

var undividedClipShapes = findUndividedClipShapes(clipShapes);

closeArcRoutes(clipShapes, arcs, routeFlags, true, true); // not needed?
Expand Down Expand Up @@ -33468,7 +33493,7 @@ ${svg}
for (var i=0, n=ids.length; i<n; i++) {
clipArcTouches = 0;
clipArcUses = 0;
path = dividePath(ids[i]);
path = findPath(ids[i]);
if (path) {
// if ring doesn't touch/intersect a clip/erase polygon, check if it is contained
// if (clipArcTouches === 0) {
Expand All @@ -33487,6 +33512,7 @@ ${svg}
}
});


// Clear pathways of current target shape to hidden/closed
closeArcRoutes(shape, arcs, routeFlags, true, true, true);
// Also clear pathways of any clip arcs that were used
Expand Down Expand Up @@ -33557,8 +33583,9 @@ ${svg}
return usable;
}

// Filter a collection of shapes to exclude paths that contain clip/erase arcs
// and paths that are hidden (e.g. internal boundaries)

// Filter a collection of shapes to exclude paths that incorporate parts of
// clip/erase polygons and paths that are hidden (e.g. internal boundaries)
function findUndividedClipShapes(clipShapes) {
return clipShapes.map(function(shape) {
var usableParts = [];
Expand All @@ -33582,12 +33609,12 @@ ${svg}
});
}

// Test if arc is unused in both directions
// (not testing open/closed or visible/hidden)

function arcIsUnused(id, flags) {
var abs = absArcId(id),
flag = flags[abs];
return (flag & 0x44) === 0;
return (flag & 0x88) === 0;
// return id < 0 ? (flag & 0x80) === 0 : (flag & 0x8) === 0;
}

function arcIsVisible(id, flags) {
Expand All @@ -33610,7 +33637,7 @@ ${svg}
enclosedPaths.forEach(function(ids) {
var path;
for (var j=0; j<ids.length; j++) {
path = dividePath(ids[j]);
path = findPath(ids[j]);
if (path) {
dissolvedPaths.push(path);
}
Expand Down

0 comments on commit bc9a490

Please sign in to comment.