Skip to content

Commit

Permalink
v0.6.56
Browse files Browse the repository at this point in the history
  • Loading branch information
mbloch committed Dec 7, 2023
1 parent 6ccbddc commit 3512682
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v0.6.56
* Added support for importing ES modules using the -require command.
* Removed the -require init= function.

v0.6.55
* Improvements to the web UI intersections tool.

Expand Down
24 changes: 15 additions & 9 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1034,20 +1034,26 @@ mapshaper ne_50m_rivers_lake_centerlines.shp ne_50m_land.shp combine-files \

### -require

Require a Node module for use in commands like `-each` and `-run`. Required modules are added to the expression context. Named expressions are accessed via thair names or aliases. Unnamed modules have their exported properties added to the expression context.
Require a Node module or ES module for use in commands like `-each` and `-run`. Modules are added to the expression context. When the `alias=` option is given, modules are accessed via their aliases. Modules that are imported by name (e.g. `-require d3`) are accessed via their name, or by their alias if the `alias=` option is used. Module files without an alias name have their exported functions and data added directly to the expression context.

`<module>` or `module=` Name of a Node module or path to a module file.
`<module>` or `module=` Name of an installed module or path to a module file.

`alias=` Use an alias for a named module or module file.

`init=` JS expression to run after the module loads.
`alias=` Import the module as a custom-named variable.

```bash
# Example: use the underscore module
# Example: use the underscore module (which has been installed locally)
$ mapshaper data.json \
-require underscore alias=_ \
-each 'id = _.uniqueId()' \
-o data.json force
-o data2.json
```

```bash
# Example: import a module file containing a user-defined function
$ mapshaper data.json \
-require scripts/includes.mjs \
-each 'displayname = getDisplayName(d)' \
-o data2.json
```

### -run
Expand Down Expand Up @@ -1089,9 +1095,9 @@ $ mapshaper -i country.shp -require projection.js -run '-proj {tmerc(target.bbox
```javascript
// contents of projection.js file
module.exports.tmerc = function(bbox) {
var lon0 = (bbox[0] + bbox[2]) / 2,
var lon0 = (bbox[0] + bbox[2]) / 2,
lat0 = (bbox[1] + bbox[3]) / 2;
return `+proj=tmerc lat_0=${lat0} lon_0=${lon0}`;
return `+proj=tmerc lat_0=${lat0} lon_0=${lon0}`;
};
```

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.55",
"version": "0.6.56",
"description": "A tool for editing vector datasets for mapping and GIS.",
"keywords": [
"shapefile",
Expand Down
2 changes: 1 addition & 1 deletion www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ <h4>Options</h4>
<div class="coordinate-info colored-text selectable"></div>
<div class="intersection-display">
<span class="intersection-check text-btn colored-text">Check line intersections</span><span class="intersection-count">0 line intersections</span>
<img class="close-btn" src="images/close.png">
<img class="close-btn" draggable="false" src="images/close.png">
<div class="repair-btn text-btn colored-text">Repair</div>

</div>
Expand Down

0 comments on commit 3512682

Please sign in to comment.