Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

proper proj loading + readme is back -> 0.3.0

  • Loading branch information...
commit f20113d3d5ec5b7f02fe3c8f4cca702f7903c56e 1 parent 16d069d
@temsa authored
View
65 Readme.md
@@ -0,0 +1,65 @@
+This is a library for node.js, build on the original Proj4JS sources made for thr the browser
+
+## Use Node.JS port of Proj4JS ##
+Without cloning this project you can use it directly using npm :
+```
+ npm install proj4js
+```
+In your JS :
+
+```javascript
+ var Proj4js = require("proj4js");
+```
+
+## Usage example##
+
+### Synchronous mode
+
+You should use either one of the provided projection which is stored in the "defs" subdirectory of the "lib" folder of the node Proj4JS project (have a look at your project node_modules folder), or an equivalent file in your own "defs" subdirectory relative to the directory containing the module requiring proj4js.
+
+```javascript
+var Proj4js = require("proj4js"),
+ proj = new Proj4js.Proj("EPSG:4139");
+
+console.log(Proj4js.transform(Proj4js.WGS84, proj, new Proj4js.Point([45,5])));
+//returns
+//{ x: 44.999611051259926,
+// y: 5.0013285897182325,
+// z: -117.26076901517808 }
+
+```
+### Asychonous mode
+
+(Also works with local files, like synchronous mode)
+
+```javascript
+var Proj4js = require("proj4js"),
+ proj = new Proj4js.Proj("EPSG:2192", function() {
+ console.log(Proj4js.transform(Proj4js.WGS84, proj, new Proj4js.Point([45,5])));
+})
+
+console.log(Proj4js.transform(Proj4js.WGS84, proj, new Proj4js.Point([45,5])));
+//returns
+//{ x: 6295336.596034983,
+// y: -1241636.8411306776,
+// z: -250.30824038013816 }
+
+```
+
+## Documentation ##
+
+For more documentation on Proj4JS usage, please read the original proj4js documentation : http://trac.osgeo.org/proj4js/
+
+## "build" node.js version ##
+```
+ git clone git://github.com/temsa/node-proj4js.git
+ cd node-proj4js
+ cd build
+ npm install async underscore mkdirp
+ node ./build.js
+ cd node # here is the resulting package !
+```
+then you can use it with npm link (see documentation) or do a
+```
+ npm install
+```
View
13 build.node/README.txt
@@ -1,13 +0,0 @@
-## HowTo: Build & deploy "Shrunk" Single File Library version of proj4js ##
-
- * Build:
-
- cd build
- ./build.py
- cd ..
-
- * Upload the result to the server: e.g.
-
- scp build/proj4js.js openlayers@openlayers.org:openlayers.org/htdocs/code/
-
-
View
35 build.node/build.py
@@ -1,35 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-sys.path.append("../tools")
-
-import jsmin, mergejs
-
-sourceDirectory = "../lib"
-configFilename = "library.cfg"
-filename = "proj4js-compressed.js"
-outputFilename = "../lib/" + filename
-
-if len(sys.argv) > 1:
- configFilename = sys.argv[1]
- extension = configFilename[-4:]
-
- if extension != ".cfg":
- configFilename = sys.argv[1] + ".cfg"
-
-if len(sys.argv) > 2:
- outputFilename = sys.argv[2]
-
-print "Merging libraries."
-merged = mergejs.run(sourceDirectory, None, configFilename)
-print "Setting the filename to "+filename
-merged = merged.replace('scriptName: "proj4js.js",','scriptName: "'+filename+'",');
-print "Compressing."
-minimized = jsmin.jsmin(merged)
-print "Adding license file."
-minimized = file("license.txt").read() + minimized
-
-print "Writing to %s." % outputFilename
-file(outputFilename, "w").write(minimized)
-
-print "Done."
View
159 build.node/build.xml
@@ -1,159 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--*************************************************************************
-Filename : build.xml
-Project : proj4js
-Document Type : XML
-Purpose : build file for ant tool
-
-Author Date Description
-M.Adair 17-Dec-2001 initial version copied from mapbuilder
-
-$Id: build.xml 2955 2007-07-09 12:12:27Z steven $
-***************************************************************************--><!--
--->
-<!-- A "project" describes a set of targets that may be requested
- when Ant is executed. The "default" attribute defines the
- target which is executed if no specific target is requested,
- and the "basedir" attribute defines the current working directory
- from which Ant executes the requested task. This is normally
- set to the current working directory.
--->
- <project basedir=".." default="dist" name="proj4js">
-
-<!-- ===================== Property Definitions =========================== -->
-<!--
- Each of the following properties are used in the build script.
- Values for these properties are set by the first place they are
- defined, from the following list:
-
- * Definitions on the "ant" command line (ant -Dfoo=bar compile).
-
- * Definitions from a "build.properties" file in the top level
- source directory of this application.
-
- * Definitions from a "build.properties" file in the developer's
- home directory.
-
- * Default definitions in this build.xml file.
-
- You will note below that property values can be composed based on the
- contents of previously defined properties. This is a powerful technique
- that helps you minimize the number of changes required when your development
- environment is modified. Note that property composition is allowed within
- "build.properties" files as well as in the "build.xml" script.
--->
- <property file="build.properties"/>
- <property file="${user.home}/build.properties"/>
- <property file="default.properties"/>
-
-<!-- ==================== File and Directory Names ======================== -->
-<!--
-
- These properties generally define file and directory names (or paths) that
- affect where the build process stores its outputs.
-
- app.name Base name of this application, used to
- construct filenames and directories.
- Defaults to "myapp".
-
- app.path Context path to which this application should be
- deployed (defaults to "/" plus the value of the
- "app.name" property).
-
- app.version Version number of this iteration of the application.
-
- build.home The directory into which the "prepare" and
- "compile" targets will generate their output.
- Defaults to "build".
-
- dist.home The name of the base directory in which
- distribution files are created.
- Defaults to "dist".
--->
-
- <property environment="env"/>
- <property name="app.name" value="proj4js"/>
- <property name="app.path" value="/${app.name}"/>
- <property name="app.version" value="1.0.2"/>
- <property name="build.home" value="${basedir}/tempBuild"/>
- <property name="dist.home" value="${basedir}/dist"/>
- <property name="docs.home" value="${build.home}/docs"/>
-
-
-<!-- ==================== Prepare Target ================================== -->
-<!--
- The "prepare" target is used to create the "build" destination directory,
- and copy the static contents of your web application to it. If you need
- to copy static files from external dependencies, you can customize the
- contents of this task.
-
- Normally, this task is executed indirectly when needed.
-
--->
-
- <target name="prepare">
- <!-- Create build directories as needed -->
- <mkdir dir="${build.home}"/>
- <!-- Copy static content of the mapbuilder project -->
- <copy todir="${build.home}">
- <fileset dir="${basedir}" excludes="tools/*.pyc "
- includes="index.html
- lib/proj4js.js,
- lib/proj4js-combined.js
- lib/proj4js-compressed.js
- lib/defs/**
- lib/projCode/**
- build/**
- demo/**
- test/**
- tools/**"
- />
- </copy>
- </target>
-
-
-<!-- ==================== Clean Target ==================================== -->
-<!--
-
- The "clean" target deletes any previous "build" and "dist" directory,
- so that you can be ensured the application can be built from scratch.
-
--->
-
- <target description="Delete old build and dist directories" name="clean">
- <delete dir="${build.home}"/>
- <delete dir="${dist.home}"/>
- </target>
-
-
-<!-- ==================== Documentation =================================== -->
-
- <target description="Create documentation" name="docs" depends="prepare">
-
- <mkdir dir="${build.home}/docs"/>
- <mkdir dir="${build.home}/docs/NaturalDocs"/>
-
- <echo message="Generating documentation"/>
- <exec executable="cmd" os="Windows XP" dir="${build.home}">
- <arg line="/c perl C:\Progra~1\NaturalDocs\NaturalDocs -i ./lib -o html ./docs/NaturalDocs -p ./docs/NaturalDocs -r"/>
- </exec>
- </target>
-
-
-<!-- ==================== Dist Target ===================================== -->
-<!--
- The "dist" target creates the zip file distribution for the Apache/PHP
- environment.
--->
- <target name="dist" description="Create binary distribution" depends="clean,prepare,docs">
-
- <mkdir dir="${dist.home}"/>
-
- <!-- Create application zip file -->
- <zip destfile="${dist.home}/${app.name}-${app.version}.zip" update="true">
- <zipfileset dir="${build.home}" prefix="proj4js"/>
- </zip>
-
- </target>
-
-</project>
View
28 build.node/buildUncompressed.py
@@ -1,28 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-sys.path.append("../tools")
-
-import jsmin, mergejs
-
-sourceDirectory = "../lib"
-configFilename = "library.cfg"
-filename = "proj4js-combined.js"
-outputFilename = "../lib/" + filename
-
-if len(sys.argv) > 1:
- configFilename = sys.argv[1] + ".cfg"
-if len(sys.argv) > 2:
- outputFilename = sys.argv[2]
-
-print "Merging libraries."
-merged = mergejs.run(sourceDirectory, None, configFilename)
-print "Setting the filename to "+filename
-merged = merged.replace('scriptName: "proj4js.js",','scriptName: "'+filename+'",');
-print "Adding license file."
-merged = file("license.txt").read() + merged
-
-print "Writing to %s." % outputFilename
-file(outputFilename, "w").write(merged)
-
-print "Done."
View
11 build.node/library.cfg
@@ -1,11 +0,0 @@
-[first]
-proj4js.js
-
-[last]
-
-[include]
-projCode/*.js
-defs/GOOGLE.js
-
-[exclude]
-defs/*
View
11 build.node/license.txt
@@ -1,11 +0,0 @@
-/*
- proj4js.js -- Javascript reprojection library.
-
- Authors: Mike Adair madairATdmsolutions.ca
- Richard Greenwood richATgreenwoodmap.com
- Didier Richard didier.richardATign.fr
- Stephen Irons
- License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
- Note: This program is an almost direct port of the C library
- Proj4.
-*/
View
44 build/build.js
@@ -23,9 +23,49 @@ module.exports = Proj4js;";
function nodify(filename, content) {
content = content +"\n\
var alert = console.error;\n\
+Proj4js.reportError = console.error;\n\
Proj4js.getScriptLocation = function(){return './'};\n\
-Proj4js.loadScript = function(url, onload, onfail, check){onload(require(url));}\n\
-module.exports = Proj4js;\n" ;
+Proj4js.loadScript = function(url, onload, onfail, check){\n\
+ var URL = require('url').parse(url);\n\
+ if(URL.protocol) {\n\
+ require('http').get(URL, function(res){\n\
+ if(res.statusCode>=300) {\n\
+ if(Proj4js.debug) console.warn('this seems not to be valid projection, http statuscode :',res.statusCode)\n\
+ return onfail()\n\
+ }\n\
+ var body = '';\n\
+ res\n\
+ .on('data', function(chunk) {body+=chunk.toString()})\n\
+ .on('end', function() {\n\
+ var vm = require('vm');\n\
+ try {\n\
+ vm.runInContext(body, vm.createContext({Proj4js: Proj4js}, url.href));\n\
+ } catch (e) {\n\
+ if(Proj4js.debug) console.warn('this seems not to be valid JS :', body)\n\
+ onfail()\n\
+ }\n\
+ onload();\n\
+ })\n\
+ .on('error', function() {\n\
+ if(Proj4js.debug) console.warn('an http error happend while gettin ', URL.href)\n\
+ onfail()\n\
+ });\n\
+ });\n\
+ } else {\n\
+ try{\n\
+ onload(module.require(url)); //relative to this module\n\
+ } catch(e) {\n\
+ try {\n\
+ if(Proj4js.debug) console.warn('did not found module', url, 'trying relative to the calling script')\n\
+ onload(module.parent.require(url)); //relative to the caller\n\
+ } catch(e) {\n\
+ if(Proj4js.debug) console.warn('did not found the module locally, should now try on the internet; make sure to use the callback!')\n\
+ onfail()\n\
+ }\n\
+ }\n\
+ }\n\
+}\n\
+module.exports = Proj4js;" ;
write(filename, content);
}
Please sign in to comment.
Something went wrong with that request. Please try again.