Skip to content

Commit

Permalink
Add min/max rendering levels for tiled geometries as options for vect…
Browse files Browse the repository at this point in the history
…or layer
  • Loading branch information
mshubin committed Nov 19, 2014
1 parent f9a0a67 commit b6e9a66
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 35 deletions.
27 changes: 13 additions & 14 deletions src/BatchRenderable.js
Expand Up @@ -106,21 +106,20 @@ BatchRenderable.prototype.remove = function( geometry )
BatchRenderable.prototype.add = function( geometry, tile )
{
this.tile = tile;

var numVertices = this.vertices.length;
var numLineIndices = this.lineIndices.length;
var numTriIndices = this.triIndices.length;

this.build( geometry, tile );

var vertexCount = this.vertices.length - numVertices;

if ( vertexCount > 0 )
var geometryInTile = this.build( geometry, tile );
if ( geometryInTile )
{
this.geometryInfos.push({ geometry: geometry,
vertexCount: vertexCount,
lineIndexCount: this.lineIndices.length - numLineIndices,
triIndexCount: this.triIndices.length - numTriIndices });
var vertexCount = this.vertices.length - numVertices;
var numVertices = this.vertices.length;
var numLineIndices = this.lineIndices.length;
var numTriIndices = this.triIndices.length;

this.geometryInfos.push({
geometry: geometry,
vertexCount: vertexCount,
lineIndexCount: this.lineIndices.length - numLineIndices,
triIndexCount: this.triIndices.length - numTriIndices
});
this.bufferDirty = true;

return true;
Expand Down
45 changes: 45 additions & 0 deletions src/GeoBound.js
Expand Up @@ -122,6 +122,51 @@ GeoBound.prototype.intersects = function( geoBound )

/**************************************************************************************************************/

/**
Intersects this geo bound with GeoJSON geometry
*/
GeoBound.prototype.intersectsGeometry = function( geometry )
{
var isIntersected = false;
var geoBound = new GeoBound();
var coords = geometry['coordinates'];
switch (geometry['type'])
{
case "LineString":
geoBound.computeFromCoordinates( coords[i] );
isIntersected |= this.intersects(geoBound);
break;
case "Polygon":
// Don't take care about holes
for ( var i = 0; i < coords.length && !isIntersected; i++ )
{
geoBound.computeFromCoordinates( coords[i] );
isIntersected |= this.intersects(geoBound);
}
break;
case "MultiLineString":
for ( var i = 0; i < coords.length && !isIntersected; i++ )
{
geoBound.computeFromCoordinates( coords[i] );
isIntersected |= this.intersects(geoBound);
}
break;
case "MultiPolygon":
for ( var i = 0; i < coords.length && !isIntersected; i++ )
{
for ( var j = 0; j < coords[i].length && !isIntersected; j++ )
{
geoBound.computeFromCoordinates( coords[i][j] );
isIntersected |= this.intersects(geoBound);
}
}
break;
}
return isIntersected;
}

/**************************************************************************************************************/

return GeoBound;

});
8 changes: 6 additions & 2 deletions src/LineRenderer.js
Expand Up @@ -141,6 +141,8 @@ var LineRenderable = function(bucket)
mat4.identity(this.matrix);
}

/**************************************************************************************************************/

Utils.inherits(BatchRenderable,LineRenderable);

/**************************************************************************************************************/
Expand Down Expand Up @@ -195,6 +197,8 @@ LineRenderable.prototype.build = function(geometry)
this.lineIndices.push( lastIndex + i, lastIndex + i + 1 );
}
}
// Geometry is always added contrary to tiled renderables
return true;
}

/**************************************************************************************************************/
Expand Down Expand Up @@ -277,9 +281,9 @@ LineRenderer.prototype.render = function(renderables, start, end)

// Update uniforms
gl.uniform4f(this.program.uniforms["u_color"], style.strokeColor[0], style.strokeColor[1], style.strokeColor[2], style.strokeColor[3] * renderable.bucket.layer._opacity);
gl.uniform1f(this.program.uniforms["speed"], style.speed ? style.speed : 1.);
gl.uniform1f(this.program.uniforms["speed"], style.hasOwnProperty('speed') ? style.speed : 1.0);
gl.uniform1f(this.program.uniforms["time"], Date.now()/1000 - this.time);
gl.uniform1f(this.program.uniforms["gradientLength"], style.gradientLength ? style.gradientLength : 10.);
gl.uniform1f(this.program.uniforms["gradientLength"], style.hasOwnProperty('gradientLength') ? style.gradientLength : 10.0);

renderable.bindBuffers( renderContext );

Expand Down
8 changes: 8 additions & 0 deletions src/PolygonRenderer.js
Expand Up @@ -58,6 +58,7 @@ var PolygonRenderer = function(globe)
void main(void)\n\
{\n\
gl_FragColor = u_color;\n\
//if (u_color.a == 0.0) discard;\n\
}\n\
";

Expand Down Expand Up @@ -184,6 +185,7 @@ PolygonRenderable.prototype.build = function(geometry)
for ( var i=0; i<triangList.length; i++ )
{
this.triIndices.push(lastIndex + triangList[i][0], lastIndex + triangList[i][1], lastIndex + triangList[i][2] );
//this.lineIndices.push( lastIndex + triangList[i][0], lastIndex + triangList[i][1], lastIndex + triangList[i][1], lastIndex + triangList[i][2], lastIndex + triangList[i][2], lastIndex + triangList[i][0] );
}


Expand Down Expand Up @@ -231,6 +233,8 @@ PolygonRenderable.prototype.build = function(geometry)
// Update last index
lastIndex = this.vertices.length / this.vertexSize;
}
// Geometry is always added contrary to tiled renderables
return true;
}

/**************************************************************************************************************/
Expand Down Expand Up @@ -310,6 +314,7 @@ PolygonRenderer.prototype.render = function(renderables, start, end)
style.fillColor[3] * renderable.bucket.layer._opacity); // use fillColor

renderable.bindBuffers(renderContext);
gl.lineWidth( style.strokeWidth );

// Setup attributes
gl.vertexAttribPointer(program.attributes['vertex'], 3, gl.FLOAT, false, 4 * renderable.vertexSize, 0);
Expand All @@ -329,6 +334,9 @@ PolygonRenderer.prototype.render = function(renderables, start, end)
}
}

// Revert line width
gl.lineWidth(1.);

//gl.enable(gl.DEPTH_TEST);
//gl.disable(gl.POLYGON_OFFSET_FILL);
gl.depthFunc(gl.LESS);
Expand Down
43 changes: 24 additions & 19 deletions src/TiledVectorRenderable.js
Expand Up @@ -185,31 +185,36 @@ TiledVectorRenderable.prototype._fixDateLine = function( tile, coords )

/**
* Add a feature to the renderable
* @return Boolean indicating if geometry intersects the given tile
*/
TiledVectorRenderable.prototype.build = function( geometry, tile )
{
this.tile = tile;

var coords = geometry['coordinates'];
switch (geometry['type'])
var tileInRange = this.bucket.layer.minLevel <= tile.level && this.bucket.layer.maxLevel > tile.level;
if ( tileInRange )
{
case "LineString":
this.buildVerticesAndIndices( tile, coords );
break;
case "Polygon":
for ( var i = 0; i < coords.length; i++ )
this.buildVerticesAndIndices( tile, coords[i] );
break;
case "MultiLineString":
for ( var i = 0; i < coords.length; i++ )
this.buildVerticesAndIndices( tile, coords[i] );
break;
case "MultiPolygon":
for ( var j = 0; j < coords.length; j++ )
for ( var i = 0; i < coords[j].length; i++ )
this.buildVerticesAndIndices( tile, coords[j][i] );
break;
var coords = geometry['coordinates'];
switch (geometry['type'])
{
case "LineString":
this.buildVerticesAndIndices( tile, coords );
break;
case "Polygon":
for ( var i = 0; i < coords.length; i++ )
this.buildVerticesAndIndices( tile, coords[i] );
break;
case "MultiLineString":
for ( var i = 0; i < coords.length; i++ )
this.buildVerticesAndIndices( tile, coords[i] );
break;
case "MultiPolygon":
for ( var j = 0; j < coords.length; j++ )
for ( var i = 0; i < coords[j].length; i++ )
this.buildVerticesAndIndices( tile, coords[j][i] );
break;
}
}
return tile.geoBound.intersectsGeometry(geometry);
}

/**************************************************************************************************************/
Expand Down
5 changes: 5 additions & 0 deletions src/VectorLayer.js
Expand Up @@ -29,6 +29,8 @@ define(['./Utils', './BaseLayer', './FeatureStyle'],
@param options Configuration properties for VectorLayer. See {@link BaseLayer} for base properties :
<ul>
<li>style : the style to use. See {@link FeatureStyle}</li>
<li>minLevel : minimum rendering level depending on tile level</li>
<li>maxLevel : maximum rendering level depending on tile level</li>
</ul>
*/
var VectorLayer = function( options )
Expand All @@ -41,6 +43,9 @@ var VectorLayer = function( options )
else
this.style = new FeatureStyle();

this.minLevel = options && options.hasOwnProperty('minLevel') ? options['minLevel'] : 0.0;
this.maxLevel = options && options.hasOwnProperty('maxLevel') ? options['maxLevel'] : 15.0;

this.features = [];
}

Expand Down

0 comments on commit b6e9a66

Please sign in to comment.