Skip to content

Commit

Permalink
v0.6.38
Browse files Browse the repository at this point in the history
  • Loading branch information
mbloch committed Jul 19, 2023
1 parent a6ca9a8 commit 0977441
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v0.6.38
* Added `-symbols opacity=` option.

v0.6.37
* Support for simple line symbols using `type-arrow head-length=0`.

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mapshaper",
"version": "0.6.37",
"version": "0.6.38",
"description": "A tool for editing vector datasets for mapping and GIS.",
"keywords": [
"shapefile",
Expand Down
4 changes: 4 additions & 0 deletions src/cli/mapshaper-options.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,10 @@ export function getOptionParser() {
.option('stroke-width', {
describe: 'symbol line width (linear symbols only)'
})
.option('opacity', {
describe: 'symbol opacity',
type: 'number'
})
.option('geographic', {
old_alias: 'polygons',
describe: 'make geographic shapes instead of SVG objects',
Expand Down
1 change: 1 addition & 0 deletions src/commands/mapshaper-symbols.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ cmd.symbols = function(inputLyr, dataset, opts) {
scaleAndShiftCoords(coords, metersPerPx, shp[0]);
if (d.fill) rec.fill = d.fill;
if (d.stroke) rec.stroke = d.stroke;
if (d.opacity) rec.opacity = d.opacity;
return createGeometry(coords, geojsonType);
} else {
rec['svg-symbol'] = makePathSymbol(coords, d, geojsonType);
Expand Down
9 changes: 3 additions & 6 deletions src/symbols/mapshaper-basic-symbols.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { getPlanarSegmentEndpoint } from '../geom/mapshaper-geodesic';
import { getSymbolRadius, getSymbolFillColor } from './mapshaper-symbol-utils';
import { getSymbolRadius, applySymbolStyles } from './mapshaper-symbol-utils';
import { stop } from '../utils/mapshaper-logging';

export function makeCircleSymbol(d, opts) {
var radius = getSymbolRadius(d);
// TODO: remove duplication with svg-symbols.js
if (+opts.scale) radius *= +opts.scale;
return {
type: 'circle',
fill: getSymbolFillColor(d),
r: radius
};
var sym = { type: 'circle', r: radius };
return applySymbolStyles(sym, d);
}

export function getPolygonCoords(d) {
Expand Down
5 changes: 2 additions & 3 deletions src/symbols/mapshaper-path-symbols.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { roundCoordsForSVG, getSymbolFillColor, getSymbolStrokeColor } from '../symbols/mapshaper-symbol-utils';
import { roundCoordsForSVG, applySymbolStyles } from '../symbols/mapshaper-symbol-utils';
import { error } from '../utils/mapshaper-logging';
import { flattenMultiPolygonCoords } from '../svg/geojson-to-svg';

Expand All @@ -8,19 +8,18 @@ export function makePathSymbol(coords, properties, geojsonType) {
if (geojsonType == 'MultiPolygon' || geojsonType == 'Polygon') {
sym = {
type: 'polygon',
fill: getSymbolFillColor(properties),
coordinates: geojsonType == 'Polygon' ? coords : flattenMultiPolygonCoords(coords)
};
} else if (geojsonType == 'LineString' || geojsonType == 'MultiLineString') {
sym = {
type: 'polyline',
stroke: getSymbolStrokeColor(properties),
'stroke-width': properties['stroke-width'] || 2,
coordinates: geojsonType == 'LineString' ? [coords] : coords
};
} else {
error('Unsupported type:', geojsonType);
}
applySymbolStyles(sym, properties);
roundCoordsForSVG(sym.coordinates);
return sym;
}
3 changes: 3 additions & 0 deletions src/symbols/mapshaper-ring-symbols.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ export function makeRingSymbol(d, opts) {
var radii = parseRings(d.radii || '2').map(function(r) { return r * scale; });
var solidCenter = utils.isOdd(radii.length);
var color = getSymbolFillColor(d);
var opacity = opts.opacity || undefined;
var parts = [];
if (solidCenter) {
parts.push({
type: 'circle',
fill: color,
opacity: opacity,
r: radii.shift()
});
}
Expand All @@ -23,6 +25,7 @@ export function makeRingSymbol(d, opts) {
type: 'circle',
fill: 'none', // TODO remove default black fill so this is not needed
stroke: color,
opacity: opacity,
'stroke-width': roundToTenths(radii[i+1] - radii[i]),
r: roundToTenths(radii[i+1] * 0.5 + radii[i] * 0.5)
});
Expand Down
12 changes: 12 additions & 0 deletions src/symbols/mapshaper-symbol-utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ export function getSymbolStrokeColor(d) {
return d.stroke || d.fill || 'magenta';
}

export function applySymbolStyles(sym, d) {
if (sym.type == 'polyline') {
sym.stroke = getSymbolStrokeColor(d);
} else {
sym.fill = getSymbolFillColor(d);
}
if (d.opacity) {
sym.opacity = d.opacity;
}
return sym;
}

export function getSymbolRadius(d) {
if (d.radius === 0 || d.length === 0 || d.r === 0) return 0;
return d.radius || d.length || d.r || 5; // use a default value
Expand Down

0 comments on commit 0977441

Please sign in to comment.