bringing all changes from sandbox/euzuro/LayersReworking down into the trunk. this is a merge of r656:HEAD http://svn.openlayers.org/sandbox/euzuro/LayersReworking

git-svn-id: http://svn.openlayers.org/trunk/openlayers@806 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-06-27 23:16:26 +00:00
parent 63bd624827
commit ff0e83d0a0
24 changed files with 1262 additions and 467 deletions

View File

@@ -13,17 +13,43 @@ OpenLayers.Layer.prototype = {
/** @type DOMElement */
div: null,
/** This variable is set in map.addLayer, not within the layer itself
* @type OpenLayers.Map */
/** This variable is set when the layer is added to the map, via the
* accessor function setMap()
*
* @type OpenLayers.Map */
map: null,
// OPTIONS
/** @type String */
projection: null,
/** @type OpenLayers.Bounds */
maxExtent: null,
/** @type float */
maxResolution: null,
/** @type int */
minZoomLevel: null,
/** @type int */
maxZoomLevel: null,
/**
* @constructor
*
* @param {String} name
* @param {Object} options Hash of extra options to tag onto the layer
*/
initialize: function(name) {
initialize: function(name, options) {
if (arguments.length > 0) {
//add options to layer
Object.extend(this, options);
this.name = name;
if (this.div == null) {
this.div = OpenLayers.Util.createDiv();
@@ -46,14 +72,17 @@ OpenLayers.Layer.prototype = {
/**
* @params {OpenLayers.Bounds} bound
* @params {Boolean} zoomChanged tells when zoom has changed, as layers have to do some init work in that case.
* @params {Boolean} zoomChanged tells when zoom has changed, as layers
* have to do some init work in that case.
*/
moveTo: function (bound, zoomChanged) {
// not implemented here
return;
//this function should be implemented by all subclasses.
},
/**
/** Set the map property for the layer. This is done through an accessor
* so that subclasses can override this and take special action once
* they have their map variable set.
*
* @param {OpenLayers.Map} map
*/
setMap: function(map) {
@@ -62,11 +91,12 @@ OpenLayers.Layer.prototype = {
/**
* @returns Whether or not the layer is a base layer. This should be
* determined individually by all subclasses.
* determined individually by all subclasses. Default is false
* @type Boolean
*/
isBaseLayer: function() {
//this function should be implemented by all subclasses.
//this function should be implemented by all subclasses.
return false;
},
/**
@@ -87,6 +117,158 @@ OpenLayers.Layer.prototype = {
}
},
/********************************************************/
/* */
/* Layer Options */
/* */
/* Accessor functions to Layer Options parameters */
/* */
/********************************************************/
/**
* @type String
*/
getProjection: function() {
return this.projection;
},
/**
* @type OpenLayers.Bounds
*/
getMaxExtent: function() {
return this.maxExtent;
},
/**
* @type float
*/
getMaxResolution: function() {
return this.maxResolution;
},
/**
* @returns The minimum zoom level that can be reached in this layer
* @type int
*/
getMinZoomLevel: function() {
return this.minZoomLevel;
},
/**
* @returns The maximum zoom level that can be reached in this layer
* @type int
*/
getMaxZoomLevel: function() {
return this.maxZoomLevel;
},
/********************************************************/
/* */
/* Baselayer Functions */
/* */
/* The following functions must all be implemented */
/* by all base layers */
/* */
/********************************************************/
/**
* @returns Degrees per Pixel
* @type float
*/
getResolution: function() {
var viewSize = this.map.getSize();
var extent = this.map.getExtent();
return Math.max( extent.getWidth() / viewSize.w,
extent.getHeight() / viewSize.h );
},
/**
* @param {OpenLayers.Pixel} viewPortPx
*
* @returns An OpenLayers.LonLat which is the passed-in view port
* OpenLayers.Pixel, translated into lon/lat by the layer
* @type OpenLayers.LonLat
*/
getLonLatFromViewPortPx: function (viewPortPx) {
var size = this.map.getSize();
var center = this.map.getCenter(); //map center lon/lat
var res = this.map.getResolution();
var delta_x = viewPortPx.x - (size.w / 2);
var delta_y = viewPortPx.y - (size.h / 2);
return new OpenLayers.LonLat(center.lon + delta_x * res ,
center.lat - delta_y * res);
},
/**
* @param {OpenLayers.LonLat} lonlat
*
* @returns An OpenLayers.Pixel which is the passed-in OpenLayers.LonLat,
* translated into view port pixels
* @type OpenLayers.Pixel
*/
getViewPortPxFromLonLat: function (lonlat) {
var resolution = this.map.getResolution();
var extent = this.map.getExtent();
return new OpenLayers.Pixel(
Math.round(1/resolution * (lonlat.lon - extent.left)),
Math.round(1/resolution * (extent.top - lonlat.lat))
);
},
/**
* @param {OpenLayers.Bounds} bounds
*
* @return {int}
*/
getZoomForExtent: function (bounds) {
// this should be implemented by subclasses
},
/**
* @returns A Bounds object which represents the lon/lat bounds of the
* current viewPort.
* @type OpenLayers.Bounds
*/
getExtent: function () {
// this should be implemented by subclasses
var extent = null;
var center = this.map.getCenter();
if (center != null) {
var res = this.getResolution();
var size = this.map.getSize();
var w_deg = size.w * res;
var h_deg = size.h * res;
return new OpenLayers.Bounds(center.lon - w_deg / 2,
center.lat - h_deg / 2,
center.lon + w_deg / 2,
center.lat + h_deg / 2);
}
return extent;
/** ALT CALCULATION FOR GETEXTENT
var size = this.getSize();
var tlPx = new OpenLayers.Pixel(0,0);
var tlLL = this.getLonLatFromViewPortPx(tlPx);
var brPx = new OpenLayers.Pixel(size.w, size.h);
var brLL = this.getLonLatFromViewPortPx(brPx);
extent = new OpenLayers.Bounds(tlLL.lon,
brLL.lat,
brLL.lon,
tlLL.lat);
**/
},
/** @final @type String */
CLASS_NAME: "OpenLayers.Layer"
};