Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Server-side code now can use client-side code!

  • Loading branch information...
commit 93ad166722737979ca78642b36c10262dc551ae4 1 parent 746767f
@mbostock authored
Showing with 5 additions and 49 deletions.
  1. +5 −3 index.js
  2. +0 −46 lib/topojson/object.js
View
8 index.js
@@ -1,3 +1,5 @@
-exports.topology = require("./lib/topojson/topology");
-exports.object = require("./lib/topojson/object");
-exports.simplify = require("./lib/topojson/simplify");
+var fs = require("fs");
+
+var topojson = module.exports = new Function("topojson", "return " + fs.readFileSync(__dirname + "/topojson.js", "utf8"))();
+topojson.topology = require("./lib/topojson/topology");
+topojson.simplify = require("./lib/topojson/simplify");
View
46 lib/topojson/object.js
@@ -1,46 +0,0 @@
-module.exports = function(topology, o) {
- var tf = topology.transform,
- kx = tf.scale[0],
- ky = tf.scale[1],
- dx = tf.translate[0],
- dy = tf.translate[1],
- arcs = topology.arcs;
-
- function arc(i, points) {
- if (points.length) points.pop();
- for (var a = arcs[i < 0 ? ~i : i], k = 0, n = a.length, x = 0, y = 0, p; k < n; ++k) points.push([
- (x += (p = a[k])[0]) * kx + dx,
- (y += p[1]) * ky + dy
- ]);
- if (i < 0) reverse(points, n);
- }
-
- function line(arcs) {
- var points = [];
- for (var i = 0, n = arcs.length; i < n; ++i) arc(arcs[i], points);
- return points;
- }
-
- function polygon(arcs) {
- return arcs.map(line);
- }
-
- function geometry(o) {
- return {type: o.type, id: o.id, coordinates: geometryType[o.type](o.arcs)};
- }
-
- var geometryType = {
- LineString: line,
- MultiLineString: polygon,
- Polygon: polygon,
- MultiPolygon: function(arcs) { return arcs.map(polygon); }
- };
-
- return o.type === "GeometryCollection"
- ? {type: o.type, geometries: o.geometries.map(geometry)}
- : geometry(o);
-};
-
-function reverse(array, n) {
- var t, j = array.length, i = j - n; while (i < --j) t = array[i], array[i++] = array[j], array[j] = t;
-}
Please sign in to comment.
Something went wrong with that request. Please try again.