- upgrade to latest version of
Rollup - use latest version of
Rollupplugins, now part of@rollup - replace
uglifywithterser - each projection type has a module in
projections(currently only selection - could be generated in Gruntfile). Assumingproj4jssource is in../proj4js, these are in the format:
import laea from '../../proj4js/lib/projections/laea.js';
import projections from '../../proj4js/lib/projections.js';
projections.add(laea);- copy
projs.jstoproj4js/(an empty function, as in custom default in Gruntfile) - clear
dist/es/ rollup -cwill then userollup-config.jsand create modules indist/es/- once pushed to Github, these can then be imported in the browser or in Deno from
dist/esonjsDelivr, for example:deno run https://cdn.jsdelivr.net/gh/probins/myproj@0.4.1/test.js. Until NodeJS supports importing from URL, the modules can be imported from the installed package (assuming thepackage.jsoncontainstype:module).
Proj4js currently uses a JSON representation of the traditional string definition for each projection. dist/defs/ contains (uncompressed) modules consisting of a default export of this JS object for a given projection id, for example, dist/defs/epsg3035.js contains the def for the 'EPSG:3035' projection. These can then be imported in the browser and in Deno via jsDelivr instead of defining the string in each app. It might be better to put these in a separate repo, as they do not normally change and so do not need updating whenever a new version of Proj4js is released. Definitions can easily be added via a pull request. Once JSON modules are implemented, these modules can be changed to JSON.
The base module produced in Part 1 is still quite large, so a 'bare' version consisting of just the Proj4js code without any of the convenience options is created in dist/esbare/:
- the current Proj4js Readme documents only 2 functions: the main
proj4()function (core.js) for transforming coordinates from one projection to another, andproj4.def()for adding a projection based on its definition (defs.js). The exportedproj4object, however, contains various other properties which are not documented - the outdated aliases for Web Mercator can be left out
- Web Mercator (EPSG:3857) and EPSG:4269 are currently always added, whether you use them or not. These can also be left out, and added like any other projection/CRS.
- with projection definitions now available as modules, there is no longer any need to support traditional Proj strings and WKT definitions; this code can be moved to independent modules converting to/from Proj4js objects.
- MGRS should also be separated out into its own module
Part of this can be done by:
- creating
bareindex.jsas a separate entry point with only the needed/documented functions imported - Web Mercator and EPSG:4269 along with the outdated aliases for the former are defined in
global.js, imported only intodefs.js. This import could be moved toindex.js(keeping BC) and left out ofbareindex.js - The
mercprojection is added in thestartfunction ofprojections.js, run whenProj.jsis first imported. This could also be moved toindex.js(also keeping BC) and left out ofbareindex.js.lonlatcan be left in there. defs.jsis imported intoindex.jsandparseCode.js. Without support for String codes,defs.jsjust doesget/setfor definitions, and most ofparseCode.jsis not needed. In 'bare' mode, a newbaredefs.jswhich only doesget/setcould be imported intobareindex.js, butparseCode.jsis imported intoProj.js, which is more fundamental, so leaving it out is more complex.
It should therefore be possible to rearrange the code so that index.js remains with the existing functionality as the BC entry point, and would include the Web Mercator def and projection, and include support for Proj and WKT def strings. bareindex.js would be the cut-down entry point that does not include these.
For the moment, this repo contains bareindex.js and hacked versions of 3 other modules. So, again assuming proj4js source is in ../proj4js, to create dist/esbare:
- copy
bareindex.jsto../proj4js/lib/ - copy
defs.js,projections.jsandparseCode.jsto../proj4js/lib/so they overwrite the existing ones - run
rollup -c rollup.bareconfig.jsto createdist/esbare.
As with Part 2, this can be pushed to Github and the modules imported in the browser using jsDelivr. test.html shows an example of this, and testbare.js shows sample usage with relative addresses, for example: deno run https://cdn.jsdelivr.net/gh/probins/myproj@0.4.1/testbare.js.
Current full build available on cdnjs.com is 76k. Base module from Part 2 (dist/es/) is 29k. Removing undocumented functions and treating merc as other projection types as described in Part 3 (dist/esbare) reduces this to 21k. Removing the parsing of Proj def and WKT strings reduces it further to 12k.