Permalink
Browse files

moved example app out as cartegan

  • Loading branch information...
1 parent 81a504b commit 67c7f1aafcba03eb3d99a4a3f6660fe1a2835fa6 @coolaj86 coolaj86 committed May 11, 2012
@@ -1,68 +0,0 @@
-html
- head
- title Tolmey Test
- script(src='pakmanaged.js', type='text/javascript')
- body
- h1 Tolmey Tester
- p
- | Enter a zoom level between 0 and 20, and hit the button to load the OpenStreetMap tile for your location.
- form#lat_long(name='lat_long')
-
- h2 Map Center
- label(for='map-lat') Latitude
- input(name='map-lat')
- br
- label(for='map-lon') Longitude
- input(name='map-lon')
- br
- button#get-coords Use Current Location
- br
- label(for='map-radius') Radius (in meters)
- input(name='map-radius', type='number', value='500')
-
- br
- br
-
- label(for='map-provider') Map Service
- br
- select#map-provider(name='map-provider')
- option(value='openstreetmap') OpenStreetMap.org
- option(value='google', selected='selected') Google Maps (KeyHole)
- option(value='bing') Bing Maps (Virtual Earth)
- option(value='yahoo') Yahoo Maps (Nokia OVI)
- option(value='user') Custom
-
- br
- textarea#map-provider-user
- | (function () {
- | "use strict";
- |
- | function toTile(x, y, zoom) {
- | // write your custom function here
- | }
- |
- | return toTile;
- | }());
-
- br
- label(for='map-zoom') Map Scale (Zoom)
- br
- select#map-resolution(name='map-zoom')
- option(value='14') (14) 1 : 36K (9.6 m/px)
- option(value='15') (15) 1 : 18K (4.8 m/px)
- option(value='16') (16) 1 : 9,028 (2.4 m/px)
- option(value='17', selected='selected') (17) 1 : 4,514 (1.2 m/px)
- option(value='18') (18) 1 : 2,257 (60 cm/px)
- option(value='19') (19) 1 : 1,129 (30 cm/px)
- option(value='20') (20) 1 : 564 (15 cm/px)
-
- br
- br
- button#submit_button(type='submit') Display Map Tile
-
- h3 The center image should show up below
- img#map-result(src='foobar.png', name='map_result')
-
- h3 Other images
- ul#map-urls
- li.map-url http://{{server}}
@@ -1,96 +0,0 @@
-(function () {
- "use strict";
-
- var Tolmey = require('tolmey')
- , request = require('ahr2')
- ;
-
- function displayMapTileForCoordinates(event) {
- event.preventDefault();
-
- var converter = Tolmey.create()
- ;
-
- navigator.geolocation.getCurrentPosition(function (position) {
- var lat = $('[name=map-lat]').val()
- , lon = $('[name=map-lon]').val()
- , zoom = $('[name=map-zoom]').val()
- , radius = $('[name=map-radius]').val()
- , mapProvider = $('[name=map-provider]').val() || 'openstreetmap'
- , coord = converter.getMercatorFromGPS(lat, lon, zoom)
- , url = converter.getTileURL(mapProvider, coord.x, coord.y, zoom)
- , maxRadius = (Math.pow(2, (18 - zoom)) * 1000)
- ;
-
- /*
- * 1000 tiles per download
- * zoom | radius | power
- * 21 - 250
- * 20 - 500 - 2^(19-20) * 1000
- * 19 - 1000 - 2^(19-19) * 1000 - highest level for much of the world
- * 18 - 2000 - 2^(19-18) * 1000
- * 17 - 4000
- * 16 - 8000
- * 15 - 16000
- * 14 - 32000
- * 13 - 64000
- * 12 - 128000
- * 11 - 256000
- * 10 - 512000
- * 9 - 1024000
- * 8 - 2048000 - you might already have the whole earth at this level
- * 7 - you already have the whole earth at this level
- */
- /*
- * 16 zoom
- * radius | tiles
- * 3712-3951 : 256
- * 3952-4038 : 272
- * 4039-4135 : 289
- * 4136- : 306
- * -5500- : 506
- * -8000- : 1024
- *
- */
- // TODO provide override
- if (radius > maxRadius) {
- alert('Changing your radius to ' + maxRadius
- + ' which is the maximum allowed radius for zoom level ' + zoom
- + ' (just a little over 250 tiles).'
- );
- radius = maxRadius;
- }
-
- request.post("coords/" + lat + "/" + lon + "/" + zoom + "/" + zoom + "/" + radius)
- .when(function (err, ahr, data) {
- console.log(err);
- console.log(data);
- $("img#map-result").attr("src", url);
- });
-
- // TODO tile out a decent portion of the screen
- var loadingGif = 'http://jimpunk.net/Loading/wp-content/uploads/loading1.gif';
- $("img#map-result").attr("src", loadingGif);
- });
- }
-
- function getNavigatorCoords(ev) {
- ev.preventDefault();
-
- navigator.geolocation.getCurrentPosition(function (position) {
- var lat = position.coords.latitude
- , lon = position.coords.longitude
- ;
-
- console.log('ll', lat, lon);
- $('[name=map-lat]').val(String(lat));
- $('[name=map-lon]').val(String(lon));
- });
- }
-
- $.domReady(function () {
- $("body").delegate("form", "submit", displayMapTileForCoordinates);
- $("body").delegate("button#get-coords", "click", getNavigatorCoords);
- });
-
-}());
@@ -1,22 +0,0 @@
-{
- "author": "AJ ONeal <coolaj86@gmail.com> (http://coolaj86.info/)",
- "name": "tolmey-example",
- "description": "A nice web app that uses tolmey for kicks",
- "version": "0.1.0",
- "repository": {
- "type": "git",
- "url": "git://github.com/SpotterRF/Tolmey.git"
- },
- "main": "lib/app.js",
- "browserDependencies": {
- "jeesh": "*"
- , "tolmey": "0.6.x"
- , "ahr2": "2.x"
- },
- "dependencies": {},
- "devDependencies": {},
- "optionalDependencies": {},
- "engines": {
- "node": "*"
- }
-}
View
@@ -1,6 +0,0 @@
-#!/bin/bash
-cd browser-src
-jade *.jade
-mv index.html ../public/
-pakmanager build
-mv pakmanaged* ../public/
View
@@ -1,118 +0,0 @@
-(function () {
- "use strict";
-
- var tolmey = require('tolmey').create()
- , sys = require('sys')
- , fs = require('fs')
- , path = require('path')
- , request = require('ahr2')
- , EventEmitter = require('events').EventEmitter
- , Lateral = require('lateral')
- , strategies = require('../strategies')
- ;
-
- // prototype-itize and subclass as EventEmitter
- function download(callback, tiles, strategy) {
- var emitter = new EventEmitter()
- , maxThreads = 4
- , lateral
- ;
-
- strategy = strategy || strategies.google;
-
- function toFilePath(tile) {
- return path.join(__dirname, "tiles",
- String(tile.zoom)
- + "-"
- + String(tile.y)
- + "-"
- + String(tile.x)
- + ".jpg"
- );
- }
-
- function handleTile(next, tile, i) {
- var url = strategy(tile, i)
- , newfilepath = toFilePath(tile)
- ;
-
- // have n threads requesting images at once
- function getTile() {
- var res = request.get(url)
- ;
-
- res.upload.on('error', function (err) {
- console.error(err);
- //fs.writeFile(newfilepath, new Buffer());
- });
- res.on('error', function (err) {
- console.error(err);
- //fs.writeFile(newfilepath, new Buffer());
- });
-
- res.when(function (err, ahr, data) {
- // TODO test that data is buffer with jpg contents
- // TODO keep count and halt on continual errors
-
- var filename
- ;
-
- if (err) {
- if (res.statusCode == 404) {
- sys.print('-');
- fs.writeFile(newfilepath, new Buffer(0));
- } else {
- console.error('some other error retrieving image');
- }
- //emitter.emit('error', err, '0');
- next();
- return;
- }
-
- filename = newfilepath + '.tmp';
-
- fs.writeFile(filename, data, function (err) {
- if (err) {
- emitter.emit('error', err, '1');
- next();
- return;
- }
-
- fs.rename(filename, newfilepath, function (err) {
- if (err) {
- emitter.emit('error', err, '2');
- }
- next();
- });
- });
- });
- }
-
- fs.lstat(newfilepath, function (err, stat) {
- if (!stat) {
- sys.print('.');
- emitter.emit('cache-miss', tile, url);
- getTile();
- } else {
- sys.print('+');
- emitter.emit('cache-hit', tile, url);
- next();
- }
- });
-
- }
-
- console.log('length', tiles.length);
-
- lateral = Lateral.create(handleTile, maxThreads);
-
- lateral.add(tiles).when(function () {
- callback();
- emitter.emit('end');
- });
-
- return emitter;
- }
-
- module.exports = download;
-}());
View
@@ -1,25 +0,0 @@
-{
- "author": "AJ ONeal <coolaj86@gmail.com> (http://coolaj86.info/)",
- "name": "tolmey-cache-server",
- "description": "A simple server that caches map tiles",
- "version": "0.1.0",
- "repository": {
- "type": "git",
- "url": "git://github.com/SpotterRF/Tolmey.git"
- },
- "main": "lib/index",
- "scripts": {
- "test": "node server"
- },
- "dependencies": {
- "lateral": "2.x",
- "ahr2": "2.x",
- "connect_router": "1.x",
- "steve": "0.5.x"
- },
- "devDependencies": {},
- "optionalDependencies": {},
- "engines": {
- "node": "*"
- }
-}
View
@@ -1,58 +0,0 @@
-/*jshint es5:true laxcomma:true node:true*/
-(function () {
- "use strict";
-
- var connect = require('steve')
- , connectRouter = require('connect_router')
- , request = require('ahr2')
- , tolmey = require('../tolmey').create()
- , downloader = require('./downloader')
- , app
- ;
-
- function grabImages(req, res) {
- req.params.zoom = 0;
-
- var tiles = tolmey.getFlatTileCoords(req.params)
- , emitter
- ;
-
- emitter = downloader(function () {
- console.log('all done');
- res.end('it worketh oh so well\n');
- }, tiles, tolmey.strategies.google);
-
- emitter.on('error', function () {
- console.log("sad errorination!");
- });
- }
-
- function router(app) {
- app.post('/coords/:lat/:lon/:zoom/:maxZoom/:radius', grabImages);
- // curl -X POST http://localhost:4040/coords/10.53535/-144.7294/16/16/100
- // 16-30840-6421.jpg
- // curl -X POST http://localhost:4040/coords/33.335544/44.419178/16/16/35000
- }
-
- app = connect();
- app.use(connect.static(__dirname + '/public'));
- app.use(connectRouter(router));
-
- function main() {
- var port = process.argv[2] || process.env.PORT || 4040
- , server
- ;
-
- function onListening() {
- var address = server.address()
- ;
-
- console.log('Listening on', address.address + ':' + address.port);
- }
- server = app.listen(port, onListening);
- }
-
- if (require.main === module) {
- main();
- }
-}());
Oops, something went wrong.

0 comments on commit 67c7f1a

Please sign in to comment.