nodetiles-core
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -21,2 +21,4 @@ var async = require("async"); | ||
var Map = function(options) { | ||
options = options || {}; | ||
this.datasources = []; | ||
@@ -27,3 +29,3 @@ this.styles = []; | ||
if (options && options.projection){ | ||
if (options.projection){ | ||
this.projection = projector.util.cleanProjString(options.projection); | ||
@@ -33,2 +35,5 @@ console.log(this.projection); | ||
this.boundsBuffer = | ||
("boundsBuffer" in options) ? options.boundsBuffer : BUFFER_RATIO; | ||
this._renderer = cartoRenderer; | ||
@@ -41,4 +46,3 @@ }; | ||
render: function(options) { | ||
var bounds = options.bounds; | ||
this._getData(bounds.minX, bounds.minY, bounds.maxX, bounds.maxY, function(error, shapes) { | ||
this._getData(options.bounds, options.boundsBuffer, function(error, shapes) { | ||
if (error) { | ||
@@ -61,4 +65,3 @@ options.callback(error); | ||
renderGrid: function(options) {//minX, minY, maxX, maxY, width, height, asImage, callback) { | ||
var bounds = options.bounds; | ||
this._getData(bounds.minX, bounds.minY, bounds.maxX, bounds.maxY, function(error, shapes) { | ||
this._getData(options.bounds, options.boundsBuffer, function(error, shapes) { | ||
if (error) { | ||
@@ -81,4 +84,4 @@ options.callback(error); | ||
_getData: function(minX, minY, maxX, maxY, callback) { | ||
var buffer = (maxX - minX) * BUFFER_RATIO; | ||
_getData: function(bounds, buffer, callback) { | ||
var dataBounds = this._bufferedBounds(bounds, buffer); | ||
@@ -105,3 +108,3 @@ // this is a bit quick and dirty - we could possibly use style data | ||
// allow simple sources to just return results immediately | ||
var syncData = datasource(minX - buffer, minY - buffer, maxX + buffer, maxY + buffer, projection, preCallback); | ||
var syncData = datasource(dataBounds.minX, dataBounds.minY, dataBounds.maxX, dataBounds.maxY, projection, preCallback); | ||
if (syncData) { | ||
@@ -125,2 +128,24 @@ preCallback(null, syncData); | ||
_bufferedBounds: function(bounds, buffer) { | ||
if (buffer == null) { | ||
buffer = this.boundsBuffer; | ||
} | ||
if (typeof buffer === "function") { | ||
return buffer.call(this, bounds); | ||
} | ||
if (typeof buffer !== "number") { | ||
buffer = BUFFER_RATIO; | ||
} | ||
amount = (bounds.maxX - bounds.minX) * buffer; | ||
return { | ||
minX: bounds.minX - amount, | ||
minY: bounds.minY - amount, | ||
maxX: bounds.maxX + amount, | ||
maxY: bounds.maxY + amount | ||
}; | ||
}, | ||
addData: function(datasource) { | ||
@@ -127,0 +152,0 @@ // validate datasource |
{ | ||
"name": "nodetiles-core", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Joyful map rendering with Node.js.", | ||
"contributors": [ | ||
"contributors": [ | ||
{ | ||
@@ -13,3 +13,3 @@ "name": "Rob Bracket", | ||
"email": "ben@codeforamerica.org" | ||
}, | ||
}, | ||
{ | ||
@@ -28,3 +28,3 @@ "name": "Alex Yule", | ||
"node": ">0.8.x", | ||
"npm": ">1.1.x" | ||
"npm": ">1.1.x" | ||
}, | ||
@@ -35,15 +35,18 @@ "dependencies": { | ||
"canvas": "~1.0", | ||
"proj4js":"~0.3.0", | ||
"proj4js-defs":">=0.0.1", | ||
"carto":"~0.9.3", | ||
"shp":"https://github.com/yuletide/node-shp/tarball/master" | ||
"proj4js": "~0.3.0", | ||
"proj4js-defs": ">=0.0.1", | ||
"carto": "~0.9.3", | ||
"shp": "https://github.com/yuletide/node-shp/tarball/master" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~1.9", | ||
"chai": "~1.5", | ||
"sinon": "~1.6" | ||
"mocha": "~1.17.1", | ||
"chai": "~1.9.0", | ||
"sinon": "~1.8.0", | ||
"istanbul": "~0.2.4", | ||
"coveralls": "~2.7.1" | ||
}, | ||
"scripts": { | ||
"pretest": "npm ls --depth=Infinity > /dev/null", | ||
"test": "mocha" | ||
} | ||
} |
Nodetiles-Core | ||
============= | ||
[![Build Status](https://travis-ci.org/nodetiles/nodetiles-core.png?branch=master)](https://travis-ci.org/nodetiles/nodetiles-core) | ||
[![Dependency Status](https://gemnasium.com/nodetiles/nodetiles-core.png)](https://gemnasium.com/nodetiles/nodetiles-core) | ||
[![Coverage Status](https://coveralls.io/repos/nodetiles/nodetiles-core/badge.png?branch=master)](https://coveralls.io/r/nodetiles/nodetiles-core?branch=master) | ||
[![Code Climate](https://codeclimate.com/github/nodetiles/nodetiles-core.png)](https://codeclimate.com/github/nodetiles/nodetiles-core) | ||
[![NPM version](https://badge.fury.io/js/nodetiles-core.png)](http://badge.fury.io/js/nodetiles-core) | ||
Nodetiles-core is a javascript library for rendering map tiles suitable for slippy-maps and static images. Features include: | ||
- **Flexible Data-connectors**: We offer GeoJson and Shapefile connectors out-of-the-box, but it's easy to build your own. | ||
- **Flexible Data-connectors**: We offer GeoJson and Shapefile connectors out-of-the-box, but it's easy to build your own. | ||
- **Map Projections**: Transform data between more [3,900+](https://github.com/yuletide/node-proj4js-defs/blob/master/epsg.js) EPSG projections using Proj4.js | ||
- **CartoCSS Support**: We support many (if not most) stylesheet features of [CartCSS](http://mapbox.com/tilemill/docs/manual/carto/) making it trivial to import your map styles from tools like Tilemill | ||
- **CartoCSS Support**: We support many (if not most) stylesheet features of [CartoCSS](http://mapbox.com/tilemill/docs/manual/carto/) making it trivial to import your map styles from tools like Tilemill | ||
- **Slippy-map URL helpers**: Easily serve map tiles, UTFGrids, and Tile.json. Check out [nodetiles-init](https://github.com/nodetiles/nodetiles-init) for a simple scaffold. | ||
- **Static maps**: If slipply-maps aren't your style, generate static images of any dimension; checkout [nodetiles-example-static](https://github.com/nodetiles/nodetiles-example-static) for examples. | ||
- **Static maps**: If slippy-maps aren't your style, generate static images of any dimension; checkout [nodetiles-example-static](https://github.com/nodetiles/nodetiles-example-static) for examples. | ||
- **Joyfully simple, pluggable, flexible, powerful**: We built Nodetiles to be easily understandable, extensible and a joy to use. It's built with Javascript and tries to provide a solid foundation of tools that are still easy to understand, extend or replace depending on your needs. [File an issue](https://github.com/nodetiles/nodetiles-core/issues/new) if Nodetiles can't do what you need. | ||
@@ -26,3 +34,3 @@ | ||
fs = require('fs'); // we'll output to a file | ||
/* Create your map context */ | ||
@@ -34,5 +42,5 @@ var map = new nodetiles.Map({ | ||
/* Add some data */ | ||
map.addData(new GeoJsonSource({ | ||
map.addData(new GeoJsonSource({ | ||
name: "world", | ||
path: __dirname + '/countries.geojson', | ||
path: __dirname + '/countries.geojson', | ||
projection: "EPSG:900913" | ||
@@ -78,3 +86,3 @@ })); | ||
--------- | ||
Copyright (c) 2012-2013 Code for America. See LICENSE for details. | ||
Copyright (c) 2012-2014 Code for America. See LICENSE for details. | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
260286
22
2536
86
5
15