From a6ca9a8ab0e65dc34a6b637a56de526ca1cb9d72 Mon Sep 17 00:00:00 2001 From: Matthew Bloch Date: Wed, 19 Jul 2023 15:24:17 -0400 Subject: [PATCH] v0.6.37 --- CHANGELOG.md | 3 ++ package-lock.json | 4 +-- package.json | 2 +- src/symbols/mapshaper-arrow-symbols.mjs | 38 ++++++++++++++----------- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d335bc24..87a1fe2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +v0.6.37 +* Support for simple line symbols using `type-arrow head-length=0`. + v0.6.36 * Improved `fill-effect=sphere` gradient. * Sphere effect can be previewed in the web UI. diff --git a/package-lock.json b/package-lock.json index ba1ba11d..17ab3788 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mapshaper", - "version": "0.6.36", + "version": "0.6.37", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "mapshaper", - "version": "0.6.36", + "version": "0.6.37", "license": "MPL-2.0", "dependencies": { "@placemarkio/tokml": "^0.3.3", diff --git a/package.json b/package.json index 73b1d9e8..c429fa55 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mapshaper", - "version": "0.6.36", + "version": "0.6.37", "description": "A tool for editing vector datasets for mapping and GIS.", "keywords": [ "shapefile", diff --git a/src/symbols/mapshaper-arrow-symbols.mjs b/src/symbols/mapshaper-arrow-symbols.mjs index 5049a117..f6e434b2 100644 --- a/src/symbols/mapshaper-arrow-symbols.mjs +++ b/src/symbols/mapshaper-arrow-symbols.mjs @@ -23,7 +23,7 @@ export function getArrowCoords(d, style) { headDx = size.headWidth / 2, stemDx = size.stemWidth / 2, baseDx = stemDx * (1 - stemTaper), - head, stem, coords, dx, dy; + coords, dx, dy; if (curvature) { // make curved stem @@ -36,11 +36,11 @@ export function getArrowCoords(d, style) { dy = stemLen * Math.cos(theta / 2); if (stickArrow) { - stem = getCurvedStemCoords(-ax, -ay, dx, dy); + coords = getCurvedStemCoords(-ax, -ay, dx, dy); } else { var leftStem = getCurvedStemCoords(-ax, -ay, -stemDx + dx, dy); var rightStem = getCurvedStemCoords(ax, ay, stemDx + dx, dy); - stem = leftStem.concat(rightStem.reverse()); + coords = leftStem.concat(rightStem.reverse()); } } else { @@ -48,23 +48,26 @@ export function getArrowCoords(d, style) { dx = 0; dy = stemLen; if (stickArrow) { - stem = [[0, 0], [0, stemLen]]; + coords = [[0, 0], [0, stemLen]]; } else { - stem = [[-baseDx, 0], [baseDx, 0]]; + coords = [[-baseDx, 0], [baseDx, 0]]; } } if (stickArrow) { // make stick arrow - head = [[-headDx + dx, stemLen - headLen], [dx, stemLen], [headDx + dx, stemLen - headLen]]; - coords = [stem, head]; // MultiLineString coords + coords = [coords]; // MultiLineString coords + if (headLen > 0) { + coords.push([[-headDx + dx, stemLen - headLen], [dx, stemLen], [headDx + dx, stemLen - headLen]]); + } } else { // make filled arrow // coordinates go counter clockwise, starting from the leftmost head coordinate - head = [[stemDx + dx, dy], [headDx + dx, dy], - [dx, headLen + dy], [-headDx + dx, dy], [-stemDx + dx, dy]]; - coords = stem.concat(head); - coords.push(stem[0].concat()); // closed path + coords.push([stemDx + dx, dy]); + if (headLen > 0) { + coords.push([headDx + dx, dy], [dx, headLen + dy], [-headDx + dx, dy]); + } + coords.push([-stemDx + dx, dy], coords[0].concat()); // close path coords = [coords]; // Polygon coords } @@ -93,7 +96,6 @@ function calcArrowSize(d, stickArrow) { var totalLen = Math.max(d.radius || d.length || d.r || 0, 0), scale = 1, o = initArrowSize(d); // calc several parameters - if (totalLen >= 0) { scale = calcScale(totalLen, o.headLen, d); o.stemWidth *= scale; @@ -102,7 +104,7 @@ function calcArrowSize(d, stickArrow) { o.stemLen = stickArrow ? totalLen : totalLen - o.headLen; } - if (o.headWidth < o.stemWidth) { + if (o.headWidth < o.stemWidth && o.headWidth > 0) { stop('Arrow head must be at least as wide as the stem.'); } return o; @@ -131,14 +133,18 @@ export function initArrowSize(d) { headWidth: d['head-width'], headLen: d['head-length'] }; - if (!o.headWidth) { - if (o.headLen) { + if (o.headWidth === 0) { + o.headLen = 0; + } else if (o.headWidth > 0 === false) { + if (o.headLen > 0) { o.headWidth = o.headLen / sizeRatio; + } else if (o.headLen === 0) { + o.headWidth = 0; } else { o.headWidth = o.stemWidth * 3; // assumes stemWidth has been set } } - if (!o.headLen) { + if (o.headLen >= 0 === false) { o.headLen = o.headWidth * sizeRatio; } return o;