Satisfying gjslint

This commit is contained in:
Tim Schaub
2013-01-06 10:07:29 -07:00
parent 6f929efeb3
commit 39af56ecb3
+55 -25
View File
@@ -7,8 +7,16 @@ goog.require('ol.Projection');
/**
* @constructor
* @param {ol.renderer.Layer} layerRenderer Layer renderer.
*/
ol.renderer.tile.Canvas = function(layerRenderer) { ol.renderer.tile.Canvas = function(layerRenderer) {
/**
* @type {ol.renderer.Layer}
* @private
*/
this.layerRenderer_ = layerRenderer; this.layerRenderer_ = layerRenderer;
/** /**
@@ -16,7 +24,7 @@ ol.renderer.tile.Canvas = function(layerRenderer) {
* @private * @private
*/ */
this.projection_; this.projection_;
/** /**
* @type {number} * @type {number}
* @private * @private
@@ -28,7 +36,7 @@ ol.renderer.tile.Canvas = function(layerRenderer) {
* @private * @private
*/ */
this.origin_ = new ol.Coordinate(0, 0); this.origin_ = new ol.Coordinate(0, 0);
/** /**
* @type {ol.Pixel} * @type {ol.Pixel}
* @private * @private
@@ -40,13 +48,13 @@ ol.renderer.tile.Canvas = function(layerRenderer) {
* @private * @private
*/ */
this.size_; this.size_;
/** /**
* @type {CanvasContext} * @type {CanvasContext}
* @private * @private
*/ */
this.context_; this.context_;
/** /**
* @type {CanvasImageData} * @type {CanvasImageData}
* @private * @private
@@ -55,8 +63,9 @@ ol.renderer.tile.Canvas = function(layerRenderer) {
}; };
/** /**
* @param size {Object|ol.Size} * @param {Object|ol.Size} size Tile size.
*/ */
ol.renderer.tile.Canvas.prototype.setSize = function(size) { ol.renderer.tile.Canvas.prototype.setSize = function(size) {
if (!(size instanceof ol.Size)) { if (!(size instanceof ol.Size)) {
@@ -65,14 +74,15 @@ ol.renderer.tile.Canvas.prototype.setSize = function(size) {
this.size_ = size; this.size_ = size;
if (!this.context_) { if (!this.context_) {
this.context_ = document.createElement('canvas').getContext('2d'); this.context_ = document.createElement('canvas').getContext('2d');
this.pixelData_ = this.context_.createImageData(1,1).data; this.pixelData_ = this.context_.createImageData(1, 1).data;
this.pixelData[3] = 1; // opacity this.pixelData[3] = 1; // opacity
} }
goog.style.setSize(this.canvas_, size); goog.style.setSize(this.canvas_, size);
}; };
/** /**
* @param size {Object|ol.Coordinate} * @param {Object|ol.Coordinate} origin Tile origin.
*/ */
ol.renderer.tile.Canvas.prototype.setOrigin = function(origin) { ol.renderer.tile.Canvas.prototype.setOrigin = function(origin) {
if (!(origin instanceof ol.Coordinate)) { if (!(origin instanceof ol.Coordinate)) {
@@ -82,22 +92,24 @@ ol.renderer.tile.Canvas.prototype.setOrigin = function(origin) {
this.originPixel_ = this.layerRenderer_.getPixelFromCoordinate(origin); this.originPixel_ = this.layerRenderer_.getPixelFromCoordinate(origin);
}; };
/** /**
* @param resolution {number} * @param {number} resolution Tile resolution.
*/ */
ol.renderer.tile.Canvas.prototype.setResolution = function(resolution) { ol.renderer.tile.Canvas.prototype.setResolution = function(resolution) {
this.resolution_ = resolution; this.resolution_ = resolution;
}; };
/*
* @param geoJson {Object|Array} GeoJSON or an array of GeoJSON features /**
* @param projection {ol.Projection=} * @param {Object|Array} geoJson GeoJSON or an array of GeoJSON features.
* @param {ol.Projection=} opt_projection Projection.
*/ */
ol.renderer.tile.Canvas.prototype.render = function(geoJson, projection) { ol.renderer.tile.Canvas.prototype.render = function(geoJson, opt_projection) {
var map = this.map; var map = this.map;
this.projection_ = map.getProjection(); this.projection_ = map.getProjection();
this.resolution_ = map.getResolution(); this.resolution_ = map.getResolution();
var features; var features;
if (goog.isArray(geoJson)) { if (goog.isArray(geoJson)) {
features = geoJson; features = geoJson;
@@ -106,49 +118,67 @@ ol.renderer.tile.Canvas.prototype.render = function(geoJson, projection) {
} else if (geoJson.type === 'Feature') { } else if (geoJson.type === 'Feature') {
features = [geoJson]; features = [geoJson];
} }
if (features) { if (features) {
//FIXME Support geometry level projections //FIXME Support geometry level projections
projection = projection || new ol.Projection('EPSG:4326'); // @type {ol.Projection}
if (!(projection instanceof ol.Projection)) { var projection;
projection = new ol.Projection(projection); if (goog.isDef(opt_projection)) {
projection = opt_projection;
} else {
projection = new ol.Projection('EPSG:4326');
} }
for (var i=0, ii=features.length; i<ii; ++i) { for (var i = 0, ii = features.length; i < ii; ++i) {
this.renderGeometry(features[i].geometry, projection); this.renderGeometry(features[i].geometry, projection);
} }
} }
}; };
/**
* @param {Object} geometry GeoJSON geometry.
* @param {ol.Projection} projection Projection.
*/
ol.renderer.tile.Canvas.prototype.renderGeometry = ol.renderer.tile.Canvas.prototype.renderGeometry =
function(geometry, projection) { function(geometry, projection) {
var i, coordinates, hole = false; var i, coordinates, hole = false;
if (geometry.type === 'Point') { if (geometry.type === 'Point') {
this.renderPosList([geometry.coordinates], projection, false, false, hole); this.renderPosList([geometry.coordinates],
projection, false, false, hole);
} else if (geometry.type === 'MultiPoint') { } else if (geometry.type === 'MultiPoint') {
this.renderPosList(geometry.coordinates, projection, false, false, hole); this.renderPosList(geometry.coordinates,
projection, false, false, hole);
} else if (geometry.type === 'LineString') { } else if (geometry.type === 'LineString') {
this.renderPosList(geometry.coordinates, projection, true, false, hole); this.renderPosList(geometry.coordinates, projection, true, false, hole);
} else if (geometry.type === 'MultiLineString') { } else if (geometry.type === 'MultiLineString') {
coordinates = geometry.coordinates; coordinates = geometry.coordinates;
for (i=0, ii=coordinates.length; i<ii; ++i) { for (i = 0, ii = coordinates.length; i < ii; ++i) {
this.renderPosList(coordinates[i], projection, true, false, hole); this.renderPosList(coordinates[i], projection, true, false, hole);
} }
} else if (geometry.type === 'Polygon') { } else if (geometry.type === 'Polygon') {
coordinates = geometry.coordinates; coordinates = geometry.coordinates;
for (i=0, ii=coordinates.length; i<ii; ++i) { for (i = 0, ii = coordinates.length; i < ii; ++i) {
this.renderPosList(coordinates[i], projection, true, true, hole); this.renderPosList(coordinates[i], projection, true, true, hole);
hole = true; hole = true;
} }
} }
}; };
/**
* @param {Array} posList Coordinates.
* @param {ol.Projection} projection Projection.
* @param {boolean} connect Connect endpoints.
* @param {boolean} fill Fill.
* @param {boolean} hole Treat as hole.
*/
ol.renderer.tileCanvas.prototype.renderPosList = ol.renderer.tileCanvas.prototype.renderPosList =
function(posList, projection, connect, fill, hole) { function(posList, projection, connect, fill, hole) {
var position, coordinate, pixel, localX, localY; var position, coordinate, pixel, localX, localY;
if (connect === true) { if (connect === true) {
this.context_.beginPath(); this.context_.beginPath();
} }
for (i=0, ii=posList.length; i<ii; ++i) { for (i = 0, ii = posList.length; i < ii; ++i) {
position = posList[i]; position = posList[i];
coordinate = ol.Projection.transform(new ol.Coordinate( coordinate = ol.Projection.transform(new ol.Coordinate(
position[0], position[1]), projection, this.projection); position[0], position[1]), projection, this.projection);
@@ -170,5 +200,5 @@ ol.renderer.tileCanvas.prototype.renderPosList =
//FIXME deal with holes //FIXME deal with holes
this.context_.fill(); this.context_.fill();
} }
}; };