var tilestrata = require("tilestrata"); var jsonp = require("tilestrata-jsonp"); var tilestrataPostGISGeoJSON = require("tilestrata-postgis-geojson-tiles");
server = tilestrata();
server .layer("geojson_tiles_jsonp") .route("tile.json") .use(jsonp({ variable: "callback" })) .use( // Provider 这里用tilestrataPostGISGeoJSON做示例 tilestrataPostGISGeoJSON({ geometryField: "geom", sql: function(server, req) { return"select name, {geojson} from (select name, ST_Transform(way,4326) as geom from osm_polygon where name ~ '上海') as a1 WHERE ST_Intersects(geom, {bbox})"; }, pgConfig: { username: "postgres", password: "postgres", host: "localhost", port: "5432", database: "osm" } }) );
TileRequestHandler.prototype.use = function(plugin) { if (!plugin) returnthis; // ...简化后的代码 if (plugin.reshook) returnthis._registerResponseHook(plugin); };
TileRequestHandler.prototype._registerResponseHook = function(plugin) { var id = "reshook#" + this.responseHooks.length; if (!plugin) thrownewError("Falsy value passed to registerResponseHook()"); if (typeof plugin.reshook !== "function") thrownewError( "Attempted to register a response hook with no reshook() method" ); this.responseHooks.push({ id: id, plugin: plugin }); returnthis; };