Skip to content

Commit

Permalink
move to browserify + cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaefer committed Nov 21, 2013
1 parent c06c281 commit 7376ada
Show file tree
Hide file tree
Showing 17 changed files with 151 additions and 23 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/js/shaders.js
/dist
/editor/dist
/node_modules
/tiles-original
/tiles
/ARCHIVE
/deploy.sh
*.sublime-*
12 changes: 11 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@ module.exports = function(grunt) {
options: {
debug: true
}
},
editor: {
files: {
'editor/dist/editor.js': ['editor/js/editor.js']
},
entry: 'editor/js/editor.js',
options: {
debug: true,
standalone: 'editor'
}
}
},
watch: {
scripts: {
files: ['js/*.js'],
files: ['js/*.js', 'editor/js/*.js'],
tasks: ['browserify']
},
shaders: {
Expand Down
28 changes: 28 additions & 0 deletions bin/build-icons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env node

var path = require('path');

if (process.argv.length < 4) {
console.warn('Usage: %s %s [positions.json] [metadata.json]', process.argv[0], path.basename(__filename));
process.exit(1);
}

var sprite = require(path.join(process.cwd(), process.argv[2]));
var maki = require(path.join(process.cwd(), process.argv[3]));

var result = {};

for (var i = 0; i < maki.length; i++) {
var name = maki[i].icon;
result[name] = {
'name': maki[i].name,
'tags': maki[i].tags,
'sizes': {
'12': { x: sprite[name + '-12'].x, y: sprite[name + '-12'].y },
'18': { x: sprite[name + '-18'].x, y: sprite[name + '-18'].y },
'24': { x: sprite[name + '-24'].x, y: sprite[name + '-24'].y }
}
}
}

console.log(JSON.stringify(result));
2 changes: 1 addition & 1 deletion bin/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ zlib.inflate(data, function(err, data) {
if (err) throw err;

var tile = new VectorTile(new Protobuf(new Uint8Array(data)));

for (var layer_name in tile.layers) {
var layer = tile.layers[layer_name];

Expand Down
41 changes: 41 additions & 0 deletions bin/stats-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env node
var Protobuf = require('../js/protobuf.js');
var VectorTile = require('../js/vectortile.js');


// Script for displaying tags/frequency in a vector tile

var fs = require("fs");
var zlib = require("zlib");

if (process.argv.length < 3) {
console.warn('Usage: %s %s [file.vector.pbf]', process.argv[0], process.argv[1]);
process.exit(1);
}

var data = fs.readFileSync(process.argv[2]);

zlib.inflate(data, function(err, data) {
if (err) throw err;

var tile = new VectorTile(new Protobuf(new Uint8Array(data)));

var stats = {};
for (var layer_name in tile.layers) {
var layer = tile.layers[layer_name];
var types = stats[layer_name] = { fill: 0, line: 0, point: 0, other: 0 };
for (var i = 0; i < layer.length; i++) {
var feature = layer.feature(i);
switch (feature._type) {
case 1: types.point++; break;
case 2: types.line++; break;
case 3: types.fill++; break;
default: types.other++; break;
}
}
console.warn(layer_name, types);
}

console.warn(stats.road);

});
44 changes: 44 additions & 0 deletions bin/stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env node
var Protobuf = require('../js/protobuf.js');
var VectorTile = require('../js/vectortile.js');


// Script for displaying tags/frequency in a vector tile

var fs = require("fs");
var zlib = require("zlib");

if (process.argv.length < 3) {
console.warn('Usage: %s %s [file.vector.pbf]', process.argv[0], process.argv[1]);
process.exit(1);
}

var data = fs.readFileSync(process.argv[2]);

zlib.inflate(data, function(err, data) {
if (err) throw err;

var tile = new VectorTile(new Protobuf(new Uint8Array(data)));


var stats = {};
for (var layer_name in tile.layers) {
var layer = tile.layers[layer_name];
var tags = stats[layer_name] = {};
for (var i = 0; i < layer.length; i++) {
var feature = layer.feature(i);
for (var key_name in feature) {
if (['osm_id', 'name', 'name_en', 'name_de', 'name_es', 'name_fr', 'maki', 'website', 'address', 'reflen', 'len', 'area'].indexOf(key_name) >= 0) continue;
if (feature.hasOwnProperty(key_name) && key_name[0] !== '_') {
if (!(key_name in tags)) tags[key_name] = {};
var val = feature[key_name];
if (tags[key_name][val]) tags[key_name][val]++;
else tags[key_name][val] = 1;
}
}
}
}

console.warn(stats.road);

});
16 changes: 4 additions & 12 deletions editor/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,12 @@
<link rel="stylesheet" type="text/css" href="css/site.css">
<link rel="icon" href="favicon.png" type="image/x-icon">
<script src="../dist/llmr.js"></script>
<script src="js/ender.js"></script>
<script>var E = $.noConflict();</script>
<!-- <script src="js/ender.js"></script> -->
<!-- <script>var E = $.noConflict();</script> -->
<script src="js/jquery-1.9.1.js"></script>
<script src="js/jquery-ui-1.10.3.custom.js"></script>
<script src="js/colorpicker.classic.js"></script>

<script src="js/dropdown.js"></script>
<script src="js/stylelist.js"></script>
<script src="js/linewidthwidget.js"></script>
<script src="js/datafilterview.js"></script>
<script src="js/site.js"></script>
<script src="js/util.js"></script>
<script src="js/layerview.js"></script>
<script src="js/app.js"></script>
<script src="dist/editor.js"></script>
</head>
<body class="no-style-selected">

Expand Down Expand Up @@ -71,7 +63,7 @@

<script>
$(function() {
new App();
new editor.App();
});
</script>
</body>
Expand Down
5 changes: 5 additions & 0 deletions editor/js/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
var util = llmr.util;

var Dropdown = require('./dropdown.js');
var StyleList = require('./stylelist.js');
var DataFilterView = require('./datafilterview.js');
var LayerView = require('./layerview.js');

module.exports = App;
function App(root) {
var app = this;

Expand Down
1 change: 1 addition & 0 deletions editor/js/datafilterview.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = DataFilterView;
function DataFilterView(list) {
var view = this;

Expand Down
6 changes: 1 addition & 5 deletions editor/js/dropdown.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

module.exports = Dropdown;
function Dropdown(el) {
this.root = $(el);
this.items = [];
Expand Down Expand Up @@ -33,7 +33,3 @@ Dropdown.prototype.select = function(key) {
this.items[key].addClass('active');
}
};

// <li class="active">Current</li>
// <li>Other</li>
// <li>Third</li>
3 changes: 3 additions & 0 deletions editor/js/editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
App: require('./app.js')
};
9 changes: 6 additions & 3 deletions editor/js/layerview.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
var util = require('./util.js');

module.exports = LayerView;
function LayerView(layer, bucket, style) {
var view = this;
this.layer = layer;
Expand Down Expand Up @@ -59,7 +62,7 @@ LayerView.prototype.addEffects = function() {
this.root.find('.name').hover(function(e) {
var newLayer = null;
if (e.type == 'mouseenter') {
var data = util.clone(view.layer.data);
var data = llmr.util.clone(view.layer.data);
data.color = '#FF0000';
data.pulsating = 1000;
data.hidden = false;
Expand All @@ -85,7 +88,7 @@ LayerView.prototype.deactivate = function() {

LayerView.prototype.updateType = function() {
var bucket = this.bucket;
this.root.find('.type').addClass('icon').addClass(bucket.type + '-icon').attr('title', titlecase(bucket.type));
this.root.find('.type').addClass('icon').addClass(bucket.type + '-icon').attr('title', util.titlecase(bucket.type));
};

LayerView.prototype.updateColor = function() {
Expand Down Expand Up @@ -135,7 +138,7 @@ LayerView.prototype.activate = function(e) {
this.root.removeClass('tab-color tab-width tab-type tab-symbol tab-name').addClass('tab-' + tab);
}

this['activate' + titlecase(tab)]();
this['activate' + util.titlecase(tab)]();
this.fire('activate');

return false;
Expand Down
1 change: 1 addition & 0 deletions editor/js/stylelist.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = StyleList;
function StyleList() {
var list = this;
this.list = JSON.parse(localStorage['llmr/styles'] || '[]');
Expand Down
1 change: 1 addition & 0 deletions editor/js/util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// source: http://stackoverflow.com/questions/196972/convert-string-to-title-case-with-javascript
exports.titlecase = titlecase;
function titlecase(str) {
return str.replace(/\w\S*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); });
}
1 change: 0 additions & 1 deletion icons/maki-sprite.json

This file was deleted.

Binary file removed icons/maki-sprite.png
Binary file not shown.
Binary file removed icons/[email protected]
Binary file not shown.

0 comments on commit 7376ada

Please sign in to comment.