Allows you to use Embedded JavaScript (EJS) into MapServer Mapfiles.
npm install mapfile-ejsThe module mapfile-ejs allows you to use Embedded JavaScript (EJS) into MapServer Mapfiles.
1. Install Node.js and npm from https://nodejs.org/
2. Install mapfile-ejs with npm install mapfile-ejs -g
Use the file extension \*.emap for MapServer Mapfiles with EJS.
If you watch a directory, all \.emap files will be rendering to \.map files.
``plain
Usage: emap [options]
Options:
-h, --help Output usage information
-V, --version Output the version number
-d, --directory
-i, --inputEncoding
-o, --outputEncoding
-r, --ignoreInitial Ignore rendering of mapfiles with EJS on initial (default: false)
-e, --eFiles Render all e files like .exml, .ecss (default: false)
Examples:
Start watching and rendering with default options:
$ emap
Start watching and rendering with custom options:
$ emap -d ./examples -i iso-8859-1 -o iso-8859-1 -r -e
`
Render a file:
`js
import { render } from 'mapfile-ejs';
(async () => {
// render file with default options
await render(
./template__utf8.emap,./template__utf8.map
./template__iso_8859_1.emap
);
// render file with custom options
await render(
,./template__iso_8859_1__02.map
,ISO-8859-1
{ inputEncoding: , outputEncoding: ISO-8859-1 }`
);
})();
Watch a directory:
`js
import { watch } from 'mapfile-ejs';
// watch a directory with default options
watch(dir1);
// watch a directory with custom options
watch(dir2, {utf8
inputEncoding: ,utf8
outputEncoding: ,`
eFiles: false,
ignoreInitial: false
});
More details are available at the API Documentation
and at the examples directory
Input (example.emap):
`js`
MAP
<%
//Loop to create 3 layers
for(let i = 0; i < 3; i++) {
-%>
LAYER
NAME "layer_<%- i %>"
END
<%
} //End of loop
-%>
END
Output (example.map):
`js`
MAP
LAYER
NAME "layer_0"
END
LAYER
NAME "layer_1"
END
LAYER
NAME "layer_2"
END
END
How to use require and include:
`jsnode:path
<%
// import is available like
const path = await import();
-%>
<%
// include is available (include_file.ejs) like
-%>
<%- await include('include_file', { }); %>
`
Run cli during development:
`bash`
npm run emap -- -d ./examples/watch/dir1
Run examples:
`bash`
node examples/isTemplate/index.js
node examples/render/index.js
node examples/watch/index.js
* Fix mistakes in README.md (2023-04-28)
* Update dependencies (2023-04-27)
* Switch from require()to import() (2023-04-27)render()
* Switch to async render() (2023-04-07).eslintrc.js
* Remove api documentation (2023-04-27)
* Remove ESLint configuration file (2023-04-27)
* Update dependencies
* Fix npm bug
* Change npm publisher
* Update dependencies
* Update dependencies
* Update mistaks in README.md
* Fix log bugs in the cli tool emapREADME.md
* Addexamples in
* Add API Documentation docs/apidocs/changelog
* Add changelog .eslintrc.js
* Add ESLint configuration file .vscode/settings.json
* Add Visual Studio Code configuration src
* Restructure code in directorynpm run cli -d ./examples/watchDir/dir1
* Add npm script MapfileRenderer
* Update dependencies
* Switch from class to module with render() and watch() functionisTemplate()` function
* Add
* Add new examples