Skip to content

Commit

Permalink
allow disabling hash
Browse files Browse the repository at this point in the history
stopgap for #174
  • Loading branch information
kkaefer committed Oct 30, 2013
1 parent ecb6c47 commit ab1018b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
3 changes: 2 additions & 1 deletion debug/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ domready(function() {
lat: 38.912753,
lon: -77.032194,
rotation: 0,
style: style_json
style: style_json,
hash: true
});
new Debug(globalMap);
});
2 changes: 0 additions & 2 deletions js/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ Layer.prototype._renderTile = function(tile, id, style) {
debug: this.map.debug,
antialiasing: this.map.antialiasing,
vertices: this.map.vertices,
fonts: this.map.fonts,
sprite: this.map.sprite,
rotating: this.map.rotating,
zooming: this.map.zooming
});
Expand Down
1 change: 0 additions & 1 deletion js/llmr.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
exports.Map = require('./map');
window = exports;
37 changes: 23 additions & 14 deletions js/map.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
var Transform = require('./transform.js');
var Hash = require('./hash.js');
var Style = require('./parse_style.js');
Expand All @@ -19,7 +20,9 @@ function Map(config) {
this.transform = new Transform(this.tileSize);

this._setupContainer(config.container);
this.hash = new Hash(this);
if (config.hash) {
this.hash = new Hash(this);
}
this._setupPosition(config);

this.transform.minZoom = config.minZoom || 0;
Expand All @@ -43,7 +46,9 @@ function Map(config) {

this.resize();

this.hash.onhash();
if (this.hash) {
this.hash.onhash();
}
this.update();
}

Expand Down Expand Up @@ -159,7 +164,7 @@ Map.prototype.resize = function() {
this.transform.width = width;
this.transform.height = height;

this.sprite.resize(this.painter.gl);
this.style.sprite.resize(this.painter.gl);
this.painter.resize(width, height);
};

Expand Down Expand Up @@ -199,8 +204,8 @@ Map.prototype.switchStyle = function(style) {
// Transfer a stripped down version of the style to the workers. They only
// need the layer => bucket mapping, as well as the bucket descriptions.
this.dispatcher.broadcast('set style', {
mapping: this.style.mapping,
buckets: this.style.buckets
mapping: this.originalStyle.mapping,
buckets: this.originalStyle.buckets
});

// clears all tiles to recalculate geometries (for changes to linecaps, linejoins, ...)
Expand All @@ -216,7 +221,7 @@ Map.prototype.switchStyle = function(style) {
*/

Map.prototype._setupPosition = function(pos) {
if (this.hash.parseHash()) return;
if (this.hash && this.hash.parseHash()) return;
this.setPosition(pos.zoom, pos.lat, pos.lon, pos.rotation);
};

Expand Down Expand Up @@ -354,8 +359,8 @@ Map.prototype._setupEvents = function() {
Map.prototype._setupDispatcher = function() {
this.dispatcher = new Dispatcher(4, this);
this.dispatcher.broadcast('set style', {
mapping: this.style.mapping,
buckets: this.style.buckets
mapping: this.originalStyle.mapping,
buckets: this.originalStyle.buckets
});
};

Expand Down Expand Up @@ -426,17 +431,21 @@ Map.prototype._rerender = function() {
};

Map.prototype._setupStyle = function(style) {
this.style = style;
this.style.layers = Style.parse(this.style.layers, this.style.constants);
this.originalStyle = style;
this.style = {
mapping: style.mapping,
buckets: style.buckets
};
this.style.parsed = Style.parse(this.originalStyle.layers, this.originalStyle.constants);

var map = this;
function rerender() { map._rerender(); }
this.sprite = new ImageSprite(this.style, rerender);
this.style.sprite = new ImageSprite(this.originalStyle, rerender);
};

Map.prototype._updateStyle = function() {
this.style.zoomed_layers = Style.parseZoom(this.style.layers, this.style.constants, this.transform.z);
this.style.background_color = Style.parseColor(this.style.background, this.style.constants);
this.style.zoomed = Style.parseZoom(this.style.parsed, this.originalStyle.constants, this.transform.z);
this.style.background = Style.parseColor(this.originalStyle.background, this.originalStyle.constants);
};

Map.prototype.update = function() {
Expand All @@ -449,7 +458,7 @@ Map.prototype.update = function() {
// Call when a (re-)render of the map is required, e.g. when the user panned or
// zoomed or when new data is available.
Map.prototype.render = function() {
this.painter.clear(this.style.background_color);
this.painter.clear(this.style.background);

this.layers.forEach(function(layer) {
layer.render();
Expand Down
9 changes: 4 additions & 5 deletions js/painter.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ GLPainter.prototype.draw = function glPainterDraw(tile, style, params) {

drawBackground(gl, painter, style);

style.zoomed_layers.forEach(applyStyle);
style.zoomed.forEach(applyStyle);

function applyStyle(layerStyle) {
var bucket_info = style.buckets[layerStyle.bucket];
Expand All @@ -362,7 +362,7 @@ GLPainter.prototype.draw = function glPainterDraw(tile, style, params) {
} else if (bucket_info.type == 'line') {
drawLine(gl, painter, layer, layerStyle, tile, stats, params);
} else if (bucket_info.type == 'point') {
drawPoint(gl, painter, layer, layerStyle, tile, stats, params);
drawPoint(gl, painter, layer, layerStyle, tile, stats, params, style.sprite);
} else if (bucket_info.type == 'text') {
drawText(gl, painter, layer, layerStyle, tile, stats, params, bucket_info);
}
Expand All @@ -381,7 +381,7 @@ function drawBackground(gl, painter, style) {
// Draw background.
gl.switchShader(painter.areaShader, painter.posMatrix, painter.exMatrix);
gl.enable(gl.STENCIL_TEST);
gl.uniform4fv(painter.areaShader.u_color, style.background_color);
gl.uniform4fv(painter.areaShader.u_color, style.background);
gl.bindBuffer(gl.ARRAY_BUFFER, painter.backgroundBuffer);
gl.vertexAttribPointer(
painter.areaShader.a_pos,
Expand Down Expand Up @@ -548,8 +548,7 @@ function drawLine(gl, painter, layer, layerStyle, tile, stats, params) {
}
}

function drawPoint(gl, painter, layer, layerStyle, tile, stats, params) {
var imageSprite = params.sprite;
function drawPoint(gl, painter, layer, layerStyle, tile, stats, params, imageSprite) {
var imagePos = imageSprite.getPosition(layerStyle.image);
var buffer, begin, end, count;

Expand Down

0 comments on commit ab1018b

Please sign in to comment.