The OpenLayers server threw a disk, and clobbered another, resulting in a loss

of data up to our last backup. In the previous subversion repository, this was
r1694->r1777. I'm sorry to all those of you who might have checked out that 
code, as this will surely cause problems for you. We're currently working to
figure out what went wrong, and how to prevent it in the future.


git-svn-id: http://svn.openlayers.org/trunk/openlayers@1695 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2006-10-13 20:41:21 +00:00
parent 60ba893119
commit 7c2a8a0cab
38 changed files with 1477 additions and 1279 deletions

View File

@@ -63,6 +63,7 @@ OpenLayers.Control.prototype = {
if (this.div == null) {
this.div = OpenLayers.Util.createDiv();
this.div.id = this.id;
this.div.className = 'olControl';
}
if (px != null) {
this.position = px.clone();

View File

@@ -179,11 +179,7 @@ OpenLayers.Control.MouseDefaults.prototype =
var left = Math.min(start.lon, end.lon);
var right = Math.max(start.lon, end.lon);
var bounds = new OpenLayers.Bounds(left, bottom, right, top);
var zoom = this.map.getZoomForExtent(bounds);
this.map.setCenter(new OpenLayers.LonLat(
(start.lon + end.lon) / 2,
(start.lat + end.lat) / 2
), zoom);
this.map.zoomToExtent(bounds);
} else {
var end = this.map.getLonLatFromViewPortPx( evt.xy );
this.map.setCenter(new OpenLayers.LonLat(

View File

@@ -191,7 +191,11 @@ OpenLayers.Layer.prototype = {
* @param {Boolean} dragging
*/
moveTo:function(bounds, zoomChanged, dragging) {
this.display(this.visibility && this.inRange);
var display = this.visibility;
if (!this.isBaseLayer) {
display = display && this.inRange;
}
this.display(display);
},
/** Set the map property for the layer. This is done through an accessor
@@ -206,10 +210,17 @@ OpenLayers.Layer.prototype = {
setMap: function(map) {
this.map = map;
// grab some essential layer data from the map if it hasn't already
// been set
this.maxExtent = this.maxExtent || this.map.maxExtent;
this.projection = this.projection || this.map.projection;
this.units = this.units || this.map.units;
this.initResolutions();
this.inRange = this.calculateInRange();
if (!this.isBaseLayer) {
this.inRange = this.calculateInRange();
}
},
/**
@@ -406,8 +417,6 @@ OpenLayers.Layer.prototype = {
// this way cloned layers reset themselves to new map div
// dimensions)
//
this.projection = confProps.projection;
this.units = confProps.units;
this.resolutions = confProps.resolutions;
this.maxResolution = confProps.resolutions[0];
@@ -423,9 +432,6 @@ OpenLayers.Layer.prototype = {
this.minScale = this.scales[0];
this.maxScale = this.scales[this.scales.length - 1];
this.minExtent = confProps.minExtent;
this.maxExtent = confProps.maxExtent;
this.numZoomLevels = confProps.numZoomLevels;
},

View File

@@ -25,6 +25,15 @@ OpenLayers.Layer.EventPane.prototype =
/** @type DOMElement */
pane: null,
/** This is the object which will be used to load the 3rd party library
* in the case of the google layer, this will be of type GMap,
* in the case of the ve layer, this will be of type VEMap
*
* @type Object */
mapObject: null,
/**
* @constructor
*
@@ -34,10 +43,19 @@ OpenLayers.Layer.EventPane.prototype =
initialize: function(name, options) {
OpenLayers.Layer.prototype.initialize.apply(this, arguments);
if (this.pane == null) {
this.pane = OpenLayers.Util.createDiv();
this.pane = OpenLayers.Util.createDiv(this.div.id + "_EventPane");
}
},
/**
*
*/
destroy: function() {
this.mapObject = null;
OpenLayers.Layer.prototype.destroy.apply(this, arguments);
},
/** 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.
@@ -60,8 +78,52 @@ OpenLayers.Layer.EventPane.prototype =
} else {
this.map.layerContainerDiv.appendChild(this.pane);
}
// once our layer has been added to the map, we can load it
this.loadMapObject();
// if map didn't load, display warning
if (this.mapObject == null) {
this.loadWarningMessage();
}
},
/** If we can't load the GMap, then display an error message to the
* user and tell them where to go for help.
*
* @private
*
*/
loadWarningMessage:function() {
this.div.style.backgroundColor = "darkblue";
var viewSize = this.map.getSize();
msgW = Math.min(viewSize.w, 300);
msgH = Math.min(viewSize.h, 200);
var size = new OpenLayers.Size(msgW, msgH);
var centerPx = new OpenLayers.Pixel(viewSize.w/2, viewSize.h/2);
var topLeft = centerPx.add(-size.w/2, -size.h/2);
var div = OpenLayers.Util.createDiv(this.name + "_warning",
topLeft,
size,
null,
null,
null,
"auto");
div.style.padding = "7px";
div.style.backgroundColor = "yellow";
div.innerHTML = this.getWarningHTML();
this.div.appendChild(div);
},
/**
* @param {Boolean} display
*/
@@ -70,11 +132,181 @@ OpenLayers.Layer.EventPane.prototype =
this.pane.style.display = this.div.style.display;
},
setZIndex: function (zIdx) {
/**
* @param {int} zIndex
*/
setZIndex: function (zIndex) {
OpenLayers.Layer.prototype.setZIndex.apply(this, arguments);
this.pane.style.zIndex = parseInt(this.div.style.zIndex) + 1;
},
/**
* @param {OpenLayers.Bounds} bounds
* @param {Boolean} zoomChanged
* @param {Boolean} dragging
*/
moveTo:function(bounds, zoomChanged, dragging) {
OpenLayers.Layer.prototype.moveTo.apply(this, arguments);
if (this.mapObject != null) {
var newCenter = this.map.getCenter();
var newZoom = this.map.getZoom();
if (newCenter != null) {
var moOldCenter = this.getMapObjectCenter();
var oldCenter = this.getOLLonLatFromMapObjectLonLat(moOldCenter);
var moOldZoom = this.getMapObjectZoom();
var oldZoom= this.getOLZoomFromMapObjectZoom(moOldZoom);
if ( !(newCenter.equals(oldCenter)) ||
!(newZoom == oldZoom) ) {
var center = this.getMapObjectLonLatFromOLLonLat(newCenter);
var zoom = this.getMapObjectZoomFromOLZoom(newZoom);
this.setMapObjectCenter(center, zoom);
}
}
}
},
/********************************************************/
/* */
/* Baselayer Functions */
/* */
/********************************************************/
/**
* @param {OpenLayers.Pixel} viewPortPx
*
* @returns An OpenLayers.LonLat which is the passed-in view port
* OpenLayers.Pixel, translated into lon/lat by GMAPS
* If gmap is not loaded or not centered, returns null
* @type OpenLayers.LonLat
*/
getLonLatFromViewPortPx: function (viewPortPx) {
var lonlat = null;
if ( (this.mapObject != null) &&
(this.getMapObjectCenter() != null) ) {
var moPixel = this.getMapObjectPixelFromOLPixel(viewPortPx);
var moLonLat = this.getMapObjectLonLatFromMapObjectPixel(moPixel)
lonlat = this.getOLLonLatFromMapObjectLonLat(moLonLat);
}
return lonlat;
},
/**
* @param {OpenLayers.LonLat} lonlat
*
* @returns An OpenLayers.Pixel which is the passed-in OpenLayers.LonLat,
* translated into view port pixels BY GMAPS
* If gmap is not loaded or not centered, returns null
* @type OpenLayers.Pixel
*/
getViewPortPxFromLonLat: function (lonlat) {
var viewPortPx = null;
if ( (this.mapObject != null) &&
(this.getMapObjectCenter() != null) ) {
var moLonLat = this.getMapObjectLonLatFromOLLonLat(lonlat);
var moPixel = this.getMapObjectPixelFromMapObjectLonLat(moLonLat)
viewPortPx = this.getOLPixelFromMapObjectPixel(moPixel);
}
return viewPortPx;
},
/********************************************************/
/* */
/* Translation Functions */
/* */
/* The following functions translate Map Object and */
/* OL formats for Pixel, LonLat */
/* */
/********************************************************/
//
// TRANSLATION: MapObject LatLng <-> OpenLayers.LonLat
//
/**
* @param {Object} moLonLat
*
* @returns An OpenLayers.LonLat, translated from the passed in
* MapObject LonLat
* Returns null if null value is passed in
* @type OpenLayers.LonLat
*/
getOLLonLatFromMapObjectLonLat: function(moLonLat) {
var olLonLat = null;
if (moLonLat != null) {
var lon = this.getLongitudeFromMapObjectLonLat(moLonLat);
var lat = this.getLatitudeFromMapObjectLonLat(moLonLat);
olLonLat = new OpenLayers.LonLat(lon, lat);
}
return olLonLat;
},
/**
* @param {OpenLayers.LonLat} olLonLat
*
* @returns A MapObject LonLat, translated from the passed in
* OpenLayers.LonLat
* Returns null if null value is passed in
* @type Object
*/
getMapObjectLonLatFromOLLonLat: function(olLonLat) {
var moLatLng = null;
if (olLonLat != null) {
moLatLng = this.getMapObjectLonLatFromLonLat(olLonLat.lon,
olLonLat.lat);
}
return moLatLng;
},
//
// TRANSLATION: MapObject Pixel <-> OpenLayers.Pixel
//
/**
* @param {Object} moPixel
*
* @returns An OpenLayers.Pixel, translated from the passed in
* MapObject Pixel
* Returns null if null value is passed in
* @type OpenLayers.Pixel
*/
getOLPixelFromMapObjectPixel: function(moPixel) {
var olPixel = null;
if (moPixel != null) {
var x = this.getXFromMapObjectPixel(moPixel);
var y = this.getYFromMapObjectPixel(moPixel);
olPixel = new OpenLayers.Pixel(x, y);
}
return olPixel;
},
/**
* @param {OpenLayers.Pixel} olPixel
*
* @returns A MapObject Pixel, translated from the passed in
* OpenLayers.Pixel
* Returns null if null value is passed in
* @type Object
*/
getMapObjectPixelFromOLPixel: function(olPixel) {
var moPixel = null;
if (olPixel != null) {
moPixel = this.getMapObjectPixelFromXY(olPixel.x, olPixel.y);
}
return moPixel;
},
/** @final @type String */
CLASS_NAME: "OpenLayers.Layer.EventPane"
});

View File

@@ -67,9 +67,46 @@ OpenLayers.Layer.FixedZoomLevels.prototype = {
// do want to put some functionality or state in here.
},
/**
*
*/
initResolutions: function() {
// resolutions are set automatically in the black-box. this is the
// definition of a fixed-zoom-levels layer
var props = new Array('minZoomLevel', 'maxZoomLevel', 'numZoomLevels');
for(var i=0; i < props.length; i++) {
var property = props[i];
this[property] = (this.options[property] != null)
? this.options[property]
: this.map[property];
}
if ( (this.minZoomLevel == null) ||
(this.minZoomLevel < this.MIN_ZOOM_LEVEL) ){
this.minZoomLevel = this.MIN_ZOOM_LEVEL;
}
var limitZoomLevels = this.MAX_ZOOM_LEVEL - this.minZoomLevel + 1;
if (this.numZoomLevels != null) {
this.numZoomLevels = Math.min(this.numZoomLevels, limitZoomLevels);
} else {
if (this.maxZoomLevel != null) {
var zoomDiff = this.maxZoomLevel - this.minZoomLevel + 1;
this.numZoomLevels = Math.min(zoomDiff, limitZoomLevels);
} else {
this.numZoomLevels = limitZoomLevels;
}
}
this.maxZoomLevel = this.minZoomLevel + this.numZoomLevels - 1;
if (this.RESOLUTIONS != null) {
var resolutionsIndex = 0;
this.resolutions = [];
for(var i= this.minZoomLevel; i < this.numZoomLevels; i++) {
this.resolutions[resolutionsIndex++] = this.RESOLUTIONS[i];
}
}
},
/**
@@ -77,16 +114,21 @@ OpenLayers.Layer.FixedZoomLevels.prototype = {
* @type float
*/
getResolution: function() {
var resolution = null;
var viewSize = this.map.getSize();
var extent = this.getExtent();
if ((viewSize != null) && (extent != null)) {
resolution = Math.max( extent.getWidth() / viewSize.w,
extent.getHeight() / viewSize.h );
if (this.resolutions != null) {
return OpenLayers.Layer.prototype.getResolution.apply(this, arguments);
} else {
var resolution = null;
var viewSize = this.map.getSize();
var extent = this.getExtent();
if ((viewSize != null) && (extent != null)) {
resolution = Math.max( extent.getWidth() / viewSize.w,
extent.getHeight() / viewSize.h );
}
return resolution;
}
return resolution;
},
/** Calculates using px-> lonlat translation functions on tl and br
@@ -127,12 +169,64 @@ OpenLayers.Layer.FixedZoomLevels.prototype = {
*/
getZoomForResolution: function(resolution) {
var extent = OpenLayers.Layer.prototype.getExtent.apply(this,
[resolution]);
return this.getZoomForExtent(extent);
if (this.resolutions != null) {
return OpenLayers.Layer.prototype.getZoomForResolution.apply(this, arguments);
} else {
var extent = OpenLayers.Layer.prototype.getExtent.apply(this,
[resolution]);
return this.getZoomForExtent(extent);
}
},
/********************************************************/
/* */
/* Translation Functions */
/* */
/* The following functions translate GMaps and OL */
/* formats for Pixel, LonLat, Bounds, and Zoom */
/* */
/********************************************************/
//
// TRANSLATION: MapObject Zoom <-> OpenLayers Zoom
//
/**
* @param {int} gZoom
*
* @returns An OpenLayers Zoom level, translated from the passed in gZoom
* Returns null if null value is passed in
* @type int
*/
getOLZoomFromMapObjectZoom: function(moZoom) {
var zoom = null;
if (moZoom != null) {
zoom = moZoom - this.minZoomLevel;
}
return zoom;
},
/**
* @param {int} olZoom
*
* @returns A MapObject level, translated from the passed in olZoom
* Returns null if null value is passed in
* @type int
*/
getMapObjectZoomFromOLZoom: function(olZoom) {
var zoom = null;
if (olZoom != null) {
zoom = olZoom + this.minZoomLevel;
}
return zoom;
},
/** @final @type String */
CLASS_NAME: "FixedZoomLevels.js"
};

View File

@@ -51,8 +51,33 @@ OpenLayers.Layer.GeoRSS.prototype =
if (!doc || ajaxRequest.fileType!="XML") {
doc = OpenLayers.parseXMLString(ajaxRequest.responseText);
}
this.name = doc.getElementsByTagName("title")[0].firstChild.nodeValue;
var itemlist = doc.getElementsByTagName('item');
this.name = null;
try {
this.name = doc.getElementsByTagNameNS('*', 'title')[0].firstChild.nodeValue;
}
catch (e) {
this.name = doc.getElementsByTagName('title')[0].firstChild.nodeValue;
}
/* Try RSS items first, then Atom entries */
var itemlist = null;
try {
itemlist = doc.getElementsByTagNameNS('*', 'item');
}
catch (e) {
itemlist = doc.getElementsByTagName('item');
}
if (itemlist.length == 0) {
try {
itemlist = doc.getElementsByTagNameNS('*', 'entry');
}
catch(e) {
itemlist = doc.getElementsByTagName('entry');
}
}
for (var i = 0; i < itemlist.length; i++) {
var data = {};
var point = OpenLayers.Util.getNodes(itemlist[i], 'georss:point');
@@ -72,44 +97,52 @@ OpenLayers.Layer.GeoRSS.prototype =
location = new OpenLayers.LonLat(parseFloat(location[1]), parseFloat(location[0]));
/* Provide defaults for title and description */
var title = "No title";
var title = "Untitled";
try {
title = OpenLayers.Util.getNodes(itemlist[i],
"title")[0].firstChild.nodeValue;
}
catch (e) { alert(e); }
var description = "No description";
catch (e) { title="Untitled"; }
/* First try RSS descriptions, then Atom summaries */
var descr_nodes = null;
try {
description = OpenLayers.Util.getNodes(itemlist[i],
"description")[0].firstChild.nodeValue;
descr_nodes = itemlist[i].getElementsByTagNameNS("*",
"description");
}
catch (e) { alert(e); }
catch (e) {
descr_nodes = itemlist[i].getElementsByTagName("description");
}
if (descr_nodes.length == 0) {
try {
descr_nodes = itemlist[i].getElementsByTagNameNS("*",
"summary");
}
catch (e) {
descr_nodes = itemlist[i].getElementsByTagName("summary");
}
}
var description = "No description.";
try {
description = descr_nodes[0].firstChild.nodeValue;
}
catch (e) { description="No description."; }
try { var link = OpenLayers.Util.getNodes(itemlist[i], "link")[0].firstChild.nodeValue; } catch (e) { }
data.icon = OpenLayers.Marker.defaultIcon();
data.popupSize = new OpenLayers.Size(250, 100);
data.popupSize = new OpenLayers.Size(250, 120);
if ((title != null) && (description != null)) {
contentHTML = "<br />";
contentHTML += "<div style='margin: -0.5em 0.5em 0.5em 0.5em'>"
contentHTML += "<div style='height: 1.3em; overflow: hidden'>";
contentHTML += "<span style='font-size: 1.2em; font-weight: bold'>";
if (link) contentHTML += "<a href='"+link+"' target='_blank'>";
contentHTML += title;
if (link) contentHTML += "</a>";
contentHTML += "</span>";
contentHTML += "</div>";
contentHTML += "<span style='font-size: 0.7em; align:center'>";
contentHTML = '<div class="olLayerGeoRSSClose">[x]</div>';
contentHTML += '<div class="olLayerGeoRSSTitle">';
if (link) contentHTML += '<a class="link" href="'+link+'" target="_blank">';
contentHTML += title;
if (link) contentHTML += '</a>';
contentHTML += '</div>';
contentHTML += '<div style="" class="olLayerGeoRSSDescription">';
contentHTML += description;
contentHTML += "</span>";
contentHTML += "</div>"
data['popupContentHTML'] = contentHTML;
//data['popupContentHTML'] = '<h2>'+title+'</h2><p>'+description+'</p>';
contentHTML += '</div>';
data['popupContentHTML'] = contentHTML;
}
var feature = new OpenLayers.Feature(this, location, data);
this.features.push(feature);

View File

@@ -2,37 +2,32 @@
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the full
* text of the license. */
/**
* @class
*
* @requires OpenLayers/Layer/EventPane.js
* @requires OpenLayers/Layer/FixedZoomLevels.js
*/
OpenLayers.Layer.Google = OpenLayers.Class.create();
OpenLayers.Layer.Google.prototype =
OpenLayers.Class.inherit( OpenLayers.Layer.EventPane,
OpenLayers.Layer.FixedZoomLevels, {
/** @type Boolean */
isFixed: true,
/** @final @type int */
MIN_ZOOM_LEVEL: 0,
/** @final @type int */
MAX_ZOOM_LEVEL: 17,
/** @type GMap2 gmap stores the Google Map element */
gmap:null,
/** Hardcode these resolutions so that they are more closely
* tied with the standard wms projection
*
* @final @type Array(float) */
RESOLUTIONS: [1.40625,0.703125,0.3515625,0.17578125,0.087890625,0.0439453125,0.02197265625,0.010986328125,0.0054931640625,0.00274658203125,0.001373291015625,0.0006866455078125,0.00034332275390625,0.000171661376953125,0.0000858306884765625,0.00004291534423828125],
/** @type GMapType */
type: null,
// OPTIONS
/** @type int */
minZoomLevel: 0,
/** @type int */
maxZoomLevel: 16,
/**
* @constructor
*
@@ -42,85 +37,20 @@ OpenLayers.Layer.Google.prototype =
OpenLayers.Layer.EventPane.prototype.initialize.apply(this, arguments);
OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this,
arguments);
if (this.maxExtent == null) {
this.maxExtent = new OpenLayers.Bounds(-180, -90, 180, 90);
}
this.addContainerPxFunction();
this.numZoomLevels = this.maxZoomLevel - this.minZoomLevel + 1;
this.addContainerPxFunction();
},
/**
*
*/
destroy: function() {
this.gmap = null;
OpenLayers.Layer.EventPane.prototype.destroy.apply(this, arguments);
},
/**
* @param {OpenLayers.Map} map
*/
setMap:function(map) {
OpenLayers.Layer.EventPane.prototype.setMap.apply(this, arguments);
// once our layer has been added to the map, we can load it
this.loadGMap();
},
/** Assuming we are not dragging (in which case GMaps is moving itself,
* and the dragging flag is set) we need to move the gmap to the
* new center/zoom
*
* @param {OpenLayers.Bounds} bounds
* @param {Boolean} zoomChanged
* @param {Boolean} dragging
*/
moveTo:function(bounds, zoomChanged, dragging) {
OpenLayers.Layer.EventPane.prototype.moveTo.apply(this, arguments);
if ((this.gmap != null) && (!this.dragging)) {
var newOLCenter = this.map.getCenter();
var newOLZoom = this.map.getZoom();
if (newOLCenter != null) {
var oldGCenter = this.gmap.getCenter();
var oldOLCenter = this.getOLLonLatFromGLatLng(oldGCenter);
var oldGZoom = this.gmap.getZoom();
var oldOLZoom = this.getOLZoomFromGZoom(oldGZoom);
if ( !(newOLCenter.equals(oldOLCenter)) ||
!(newOLZoom == oldOLZoom) ) {
var newGCenter = this.getGLatLngFromOLLonLat(newOLCenter);
var newGZoom = this.getGZoomFromOLZoom(newOLZoom);
this.gmap.setCenter(newGCenter, newGZoom);
if (this.type != null) {
this.gmap.setMapType(this.type);
this.type = null;
}
}
}
}
},
/** Load the GMap and register appropriate event listeners. If we can't
* load GMap2, then display a warning message.
*
* @private
*
*/
loadGMap:function() {
loadMapObject:function() {
//has gmaps library has been loaded?
try {
// create GMap, hide nav controls
this.gmap = new GMap2( this.div );
this.gmap.disableDragging();
this.mapObject = new GMap2( this.div );
// move the ToS and branding stuff up to the pane
// thanks a *mil* Erik for thinking of this
@@ -138,119 +68,45 @@ OpenLayers.Layer.Google.prototype =
termsOfUse.style.right = "";
termsOfUse.style.bottom = "";
// this causes the GMap to set itself to Map's center/zoom
this.moveTo();
} catch (e) {
this.loadWarningMessage();
// do not crash
}
},
/** Overridden from EventPane because if a map type has been specified,
* we need to attach a listener for the first moveend -- this is how
* we will know that the map has been centered. Only once the map has
* been centered is it safe to change the gmap object's map type.
*
* @param {OpenLayers.Map} map
*/
setMap: function(map) {
OpenLayers.Layer.EventPane.prototype.setMap.apply(this, arguments);
if (this.type != null) {
this.map.events.register("moveend", this, this.setMapType);
}
},
/** The map has been centered, and a map type was specified, so we
* set the map type on the gmap object, then unregister the listener
* so that we dont keep doing this every time the map moves.
*
* @private
*/
setMapType: function() {
if (this.mapObject.getCenter() != null) {
this.mapObject.setMapType(this.type);
this.map.events.unregister("moveend", this, this.setMapType);
}
},
/**
* @param {Event} evt
*/
onMapResize: function() {
this.gmap.checkResize();
},
/** If we can't load the GMap, then display an error message to the
* user and tell them where to go for help.
*
* @private
*
*/
loadWarningMessage:function() {
this.div.style.backgroundColor = "darkblue";
var html = "";
html += "The Google Layer was unable to load correctly.<br>";
html += "<br>";
html += "To get rid of this message, click on the Google Layer's "
html += "tab in the layer switcher in the upper-right corner.<br>";
html += "<br>";
html += "Most likely, this is because the Google Maps library";
html += " script was either not included, or does not contain the";
html += " correct API key for your site.<br>";
html += "<br>";
html += "Developers: For help getting this working correctly, ";
html += "<a href='http://trac.openlayers.org/wiki/GoogleMapsLayer' "
html += "target='_blank'>";
html += "click here";
html += "</a>";
var viewSize = this.map.getSize();
msgW = Math.min(viewSize.w, 300);
msgH = Math.min(viewSize.h, 200);
var size = new OpenLayers.Size(msgW, msgH);
var centerPx = new OpenLayers.Pixel(viewSize.w/2, viewSize.h/2);
var topLeft = centerPx.add(-size.w/2, -size.h/2);
var div = OpenLayers.Util.createDiv("gmapsWarning",
topLeft,
size,
null,
null,
null,
"auto");
div.style.padding = "7px";
div.style.backgroundColor = "yellow";
div.innerHTML = html;
this.div.appendChild(div);
},
/********************************************************/
/* */
/* Baselayer Functions */
/* */
/********************************************************/
/**
* @param {OpenLayers.Pixel} viewPortPx
*
* @returns An OpenLayers.LonLat which is the passed-in view port
* OpenLayers.Pixel, translated into lon/lat by GMAPS
* If gmap is not loaded or not centered, returns null
* @type OpenLayers.LonLat
*/
getLonLatFromViewPortPx: function (viewPortPx) {
var lonlat = null;
if ((this.gmap != null) && (this.gmap.getCenter() != null)) {
var gPoint = this.getGPointFromOLPixel(viewPortPx);
var gLatLng = this.gmap.fromContainerPixelToLatLng(gPoint)
lonlat = this.getOLLonLatFromGLatLng(gLatLng);
}
return lonlat;
},
/**
* @param {OpenLayers.LonLat} lonlat
*
* @returns An OpenLayers.Pixel which is the passed-in OpenLayers.LonLat,
* translated into view port pixels BY GMAPS
* If gmap is not loaded or not centered, returns null
* @type OpenLayers.Pixel
*/
getViewPortPxFromLonLat: function (lonlat) {
var viewPortPx = null;
if ((this.gmap != null) && (this.gmap.getCenter() != null)) {
var gLatLng = this.getGLatLngFromOLLonLat(lonlat);
// note we use special hacked function here
var gPoint = this.gmap.fromLatLngToContainerPixel(gLatLng);
viewPortPx = this.getOLPixelFromGPoint(gPoint);
}
return viewPortPx;
this.mapObject.checkResize();
},
@@ -258,152 +114,43 @@ OpenLayers.Layer.Google.prototype =
* @param {OpenLayers.Bounds} bounds
*
* @returns Corresponding zoom level for a specified Bounds.
* If gmap is not loaded or not centered, returns null
* If mapObject is not loaded or not centered, returns null
* @type int
*/
*
getZoomForExtent: function (bounds) {
var zoom = null;
if ((this.gmap != null) && (this.gmap.getCenter() != null)) {
var gBounds = this.getGLatLngBoundsFromOLBounds(bounds);
var gZoom = this.gmap.getBoundsZoomLevel(gBounds);
if (this.mapObject != null) {
var moBounds = this.getMapObjectBoundsFromOLBounds(bounds);
var moZoom = this.getMapObjectZoomFromMapObjectBounds(moBounds);
//make sure zoom is within bounds
var gZoom = Math.min(Math.max(gZoom, this.minZoomLevel),
var moZoom = Math.min(Math.max(moZoom, this.minZoomLevel),
this.maxZoomLevel);
zoom = this.getOLZoomFromGZoom(gZoom);
zoom = this.getOLZoomFromMapObjectZoom(moZoom);
}
return zoom;
},
/********************************************************/
/* */
/* Translation Functions */
/* */
/* The following functions translate GMaps and OL */
/* formats for Pixel, LonLat, Bounds, and Zoom */
/* */
/********************************************************/
//
// TRANSLATION: GZoom <-> OpenLayers Zoom
//
/**
* @param {int} gZoom
*
* @returns An OpenLayers Zoom level, translated from the passed in gZoom
* Returns null if null value is passed in
* @type int
*/
getOLZoomFromGZoom: function(gZoom) {
var zoom = null;
if (gZoom != null) {
zoom = gZoom - this.minZoomLevel;
}
return zoom;
},
*/
/**
* @param {int} olZoom
*
* @returns A GZoom level, translated from the passed in olZoom
* Returns null if null value is passed in
* @type int
*/
getGZoomFromOLZoom: function(olZoom) {
var zoom = null;
if (olZoom != null) {
zoom = olZoom + this.minZoomLevel;
}
return zoom;
},
//
// TRANSLATION: GLatLng <-> LonLat
// TRANSLATION: MapObject Bounds <-> OpenLayers.Bounds
//
/**
* @param {GLatLng} gLatLng
* @param {Object} moBounds
*
* @returns An OpenLayers.LonLat, translated from the passed in GLatLng
* Returns null if null value is passed in
* @type OpenLayers.LonLat
*/
getOLLonLatFromGLatLng: function(gLatLng) {
var olLonLat = null;
if (gLatLng != null) {
olLonLat = new OpenLayers.LonLat(gLatLng.lng(), gLatLng.lat());
}
return olLonLat;
},
/**
* @param {OpenLayers.LonLat} olLonLat
*
* @returns A GLatLng, translated from the passed in OpenLayers.LonLat
* Returns null if null value is passed in
* @type GLatLng
*/
getGLatLngFromOLLonLat: function(olLonLat) {
var gLatLng = null;
if (olLonLat != null) {
gLatLng = new GLatLng(olLonLat.lat, olLonLat.lon);
}
return gLatLng;
},
//
// TRANSLATION: GPoint <-> OpenLayers.Pixel
//
/**
* @param {GPoint} gPoint
*
* @returns An OpenLayers.Pixel, translated from the passed in GPoint
* Returns null if null value is passed in
* @type OpenLayers.Pixel
*/
getOLPixelFromGPoint: function(gPoint) {
var olPixel = null;
if (gPoint != null) {
olPixel = new OpenLayers.Pixel(gPoint.x, gPoint.y);
}
return olPixel;
},
/**
* @param {OpenLayers.Pixel} olPixel
*
* @returns A GPoint, translated from the passed in OpenLayers.Pixel
* Returns null if null value is passed in
* @type GPoint
*/
getGPointFromOLPixel: function(olPixel) {
var gPoint = null;
if (olPixel != null) {
gPoint = new GPoint(olPixel.x, olPixel.y);
}
return gPoint;
},
//
// TRANSLATION: GLatLngBounds <-> OpenLayers.Bounds
//
/**
* @param {GLatLngBounds} gLatLngBounds
*
* @returns An OpenLayers.Bounds, translated from gLatLngBounds
* @returns An OpenLayers.Bounds, translated from the passed-in
* MapObject Bounds
* Returns null if null value is passed in
* @type OpenLayers.Bounds
*/
getOLBoundsFromGLatLngBounds: function(gLatLngBounds) {
getOLBoundsFromMapObjectBounds: function(moBounds) {
var olBounds = null;
if (gLatLngBounds != null) {
var sw = gLatLngBounds.getSouthWest();
var ne = gLatLngBounds.getNorthEast();
if (moBounds != null) {
var sw = moBounds.getSouthWest();
var ne = moBounds.getNorthEast();
olBounds = new OpenLayers.Bounds(sw.lng(),
sw.lat(),
ne.lng(),
@@ -415,47 +162,222 @@ OpenLayers.Layer.Google.prototype =
/**
* @param {OpenLayers.Bounds} olBounds
*
* @returns A GLatLngBounds, translated from olBounds
* @returns A MapObject Bounds, translated from olBounds
* Returns null if null value is passed in
* @type GLatLngBounds
* @type Object
*/
getGLatLngBoundsFromOLBounds: function(olBounds) {
var gLatLngBounds = null;
getMapObjectBoundsFromOLBounds: function(olBounds) {
var moBounds = null;
if (olBounds != null) {
var sw = new GLatLng(olBounds.bottom, olBounds.left);
var ne = new GLatLng(olBounds.top, olBounds.right);
gLatLngBounds = new GLatLngBounds(sw, ne);
moBounds = new GLatLngBounds(sw, ne);
}
return gLatLngBounds;
return moBounds;
},
/** Hack-on function because GMAPS does not give it to us
*
* @param {GLatLng} gLatLng
*
* @returns A GPoint specifying gLatLng translated into "Container" coords
* @type GPoint
*/
addContainerPxFunction: function() {
if (typeof GMap2 != "undefined" && !GMap2.fromLatLngToContainerPixel) {
if (typeof GMap2 != "undefined" && !GMap2.fromLatLngToContainerPixel) {
/** Hack-on function because GMAPS does not give it to us
*
* @param {GLatLng} gLatLng
*
* @returns A GPoint specifying gLatLng translated into "Container" coords
* @type GPoint
*/
GMap2.prototype.fromLatLngToContainerPixel = function(gLatLng) {
GMap2.prototype.fromLatLngToContainerPixel = function(gLatLng) {
// first we translate into "DivPixel"
var gPoint = this.fromLatLngToDivPixel(gLatLng);
// locate the sliding "Div" div
// it seems like "b" is the main div
var div = this.b.firstChild.firstChild;
// adjust by the offset of "Div" and voila!
gPoint.x += div.offsetLeft;
gPoint.y += div.offsetTop;
return gPoint;
};
}
// first we translate into "DivPixel"
var gPoint = this.fromLatLngToDivPixel(gLatLng);
// locate the sliding "Div" div
// it seems like "b" is the main div
var div = this.b.firstChild.firstChild;
// adjust by the offset of "Div" and voila!
gPoint.x += div.offsetLeft;
gPoint.y += div.offsetTop;
return gPoint;
};
}
},
/**
* @return String with information on why layer is broken, how to get
* it working.
* @type String
*/
getWarningHTML:function() {
var html = "";
html += "The Google Layer was unable to load correctly.<br>";
html += "<br>";
html += "To get rid of this message, select a new BaseLayer "
html += "in the layer switcher in the upper-right corner.<br>";
html += "<br>";
html += "Most likely, this is because the Google Maps library";
html += " script was either not included, or does not contain the";
html += " correct API key for your site.<br>";
html += "<br>";
html += "Developers: For help getting this working correctly, ";
html += "<a href='http://trac.openlayers.org/wiki/GoogleMapsLayer' "
html += "target='_blank'>";
html += "click here";
html += "</a>";
return html;
},
/************************************
* *
* MapObject Interface Controls *
* *
************************************/
// Get&Set Center, Zoom
/** Set the mapObject to the specified center and zoom
*
* @param {Object} center MapObject LonLat format
* @param {int} zoom MapObject zoom format
*/
setMapObjectCenter: function(center, zoom) {
this.mapObject.setCenter(center, zoom);
},
/**
* @returns the mapObject's current center in Map Object format
* @type Object
*/
getMapObjectCenter: function() {
return this.mapObject.getCenter();
},
/**
* @returns the mapObject's current zoom, in Map Object format
* @type int
*/
getMapObjectZoom: function() {
return this.mapObject.getZoom();
},
// LonLat - Pixel Translation
/**
* @param {Object} moPixel MapObject Pixel format
*
* @returns MapObject LonLat translated from MapObject Pixel
* @type Object
*/
getMapObjectLonLatFromMapObjectPixel: function(moPixel) {
return this.mapObject.fromContainerPixelToLatLng(moPixel);
},
/**
* @param {Object} moPixel MapObject Pixel format
*
* @returns MapObject Pixel translated from MapObject LonLat
* @type Object
*/
getMapObjectPixelFromMapObjectLonLat: function(moLonLat) {
return this.mapObject.fromLatLngToContainerPixel(moLonLat);
},
// Bounds
/**
* @param {Object} moBounds MapObject Bounds format
*
* @returns MapObject Zoom for specified MapObject Bounds
* @type Object
*/
getMapObjectZoomFromMapObjectBounds: function(moBounds) {
return this.mapObject.getBoundsZoomLevel(moBounds);
},
/************************************
* *
* MapObject Primitives *
* *
************************************/
// LonLat
/**
* @param {Object} moLonLat MapObject LonLat format
*
* @returns Longitude of the given MapObject LonLat
* @type float
*/
getLongitudeFromMapObjectLonLat: function(moLonLat) {
return moLonLat.lng();
},
/**
* @param {Object} moLonLat MapObject LonLat format
*
* @returns Latitude of the given MapObject LonLat
* @type float
*/
getLatitudeFromMapObjectLonLat: function(moLonLat) {
return moLonLat.lat();
},
/**
* @param {int} lon float
* @param {int} lat float
*
* @returns MapObject LonLat built from lon and lat params
* @type Object
*/
getMapObjectLonLatFromLonLat: function(lon, lat) {
return new GLatLng(lat, lon);
},
// Pixel
/**
* @param {Object} moPixel MapObject Pixel format
*
* @returns X value of the MapObject Pixel
* @type int
*/
getXFromMapObjectPixel: function(moPixel) {
return moPixel.x;
},
/**
* @param {Object} moPixel MapObject Pixel format
*
* @returns Y value of the MapObject Pixel
* @type int
*/
getYFromMapObjectPixel: function(moPixel) {
return moPixel.y;
},
/**
* @param {int} x
* @param {int} y
*
* @returns MapObject Pixel from x and y parameters
* @type Object
*/
getMapObjectPixelFromXY: function(x, y) {
return new GPoint(x, y);
},
/** @final @type String */
CLASS_NAME: "OpenLayers.Layer.Google"
});

View File

@@ -17,6 +17,15 @@ OpenLayers.Layer.HTTPRequest.prototype =
/** Hashtable of key/value parameters
* @type Object */
params: null,
/** Whether layer should reproject itself based on base layer locations.
* This allows reprojection onto commercial layers. Default is false:
* Most layers can't reproject, but layers which can create non-square
* geographic pixels can, like WMS.
*
* @type Boolean
*/
reproject: false,
/**
* @constructor

View File

@@ -3,104 +3,63 @@
* text of the license. */
/**
* @class
* @class
*
* @requires OpenLayers/Layer/EventPane.js
* @requires OpenLayers/Layer/FixedZoomLevels.js
*/
OpenLayers.Layer.MultiMap = OpenLayers.Class.create();
OpenLayers.Layer.MultiMap.prototype =
OpenLayers.Class.inherit( OpenLayers.Layer.EventPane, {
/** @type MMMap */
multimap: null,
OpenLayers.Layer.MultiMap.prototype =
OpenLayers.Class.inherit( OpenLayers.Layer.EventPane,
OpenLayers.Layer.FixedZoomLevels, {
/** @type int */
minZoomLevel: 1,
/** @type int */
maxZoomLevel: 17,
/** @final @type int */
MIN_ZOOM_LEVEL: 1,
/**
/** @final @type int */
MAX_ZOOM_LEVEL: 17,
/** Hardcode these resolutions so that they are more closely
* tied with the standard wms projection
*
* @final @type Array(float) */
RESOLUTIONS: [9, 1.40625,0.703125,0.3515625,0.17578125,0.087890625,0.0439453125,0.02197265625,0.010986328125,0.0054931640625,0.00274658203125,0.001373291015625,0.0006866455078125,0.00034332275390625,0.000171661376953125,0.0000858306884765625,0.00004291534423828125],
/** @type VEMapType */
type: null,
/**
* @constructor
*
* @param {String} name
*/
initialize:function(name) {
initialize: function(name, options) {
OpenLayers.Layer.EventPane.prototype.initialize.apply(this, arguments);
this.numZoomLevels = this.maxZoomLevel - this.minZoomLevel + 1;
OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this,
arguments);
},
/**
* @param {OpenLayers.Map} map
*/
setMap:function(map) {
OpenLayers.Layer.EventPane.prototype.setMap.apply(this, arguments);
// once our layer has been added to the map, we can load the multimap
this.loadMMMap();
},
/**
* @param {OpenLayers.Bounds} bounds
* @param {Boolean} zoomChanged
* @param {Boolean} dragging
*/
moveTo:function(bounds, zoomChanged, dragging) {
OpenLayers.Layer.EventPane.prototype.moveTo.apply(this, arguments);
if (this.multimap != null) {
var olCenter = this.map.getCenter();
var mmCenter = this.getMMLatLongFromOLLonLat(olCenter);
if (zoomChanged) {
var olZoom = this.map.getZoom();
var mmZoom = this.getMMZoomFromOLZoom(olZoom);
this.multimap.goToPosition(mmCenter, mmZoom);
} else {
this.multimap.goToPosition(mmCenter);
}
}
},
/**
*
*/
loadMMMap:function() {
try {
// create MMMap, hide nav controls
this.multimap = new MultimapViewer(this.div);
} catch (e) {
// do nothing this is to keep from crashing
// if the MM library was not loaded.
}
if (this.multimap == null) {
this.loadWarningMessage();
}
loadMapObject:function() {
try { //crash proofing
this.mapObject = new MultimapViewer(this.div);
} catch (e) { }
},
/** If we can't load the multimap, then display an error message to the
* user and tell them where to go for help.
*
* @private
*
/**
* @return String with information on why layer is broken, how to get
* it working.
* @type String
*/
loadWarningMessage:function() {
this.div.style.backgroundColor = "darkblue";
getWarningHTML:function() {
var html = "";
html += "The MM Layer was unable to load correctly.<br>";
html += "<br>";
html += "To get rid of this message, click on the MM Layer's "
html += "tab in the layer switcher in the upper-right corner.<br>";
html += "To get rid of this message, select a new BaseLayer "
html += "in the layer switcher in the upper-right corner.<br>";
html += "<br>";
html += "Most likely, this is because the MM library";
html += " script was either not correctly included.<br>";
@@ -110,230 +69,146 @@ OpenLayers.Layer.MultiMap.prototype =
html += "target='_blank'>";
html += "click here";
html += "</a>";
var viewSize = this.map.getSize();
msgW = Math.min(viewSize.w, 300);
msgH = Math.min(viewSize.h, 200);
var size = new OpenLayers.Size(msgW, msgH);
var centerPx = new OpenLayers.Pixel(viewSize.w/2, viewSize.h/2);
var topLeft = centerPx.add(-size.w/2, -size.h/2);
var div = OpenLayers.Util.createDiv("mmWarning",
topLeft,
size,
null,
null,
null,
"auto");
div.style.padding = "7px";
div.style.backgroundColor = "yellow";
div.innerHTML = html;
this.div.appendChild(div);
return html;
},
/********************************************************/
/* */
/* Baselayer Functions */
/* */
/********************************************************/
/**
* @param {OpenLayers.Pixel} viewPortPx
*
* @returns An OpenLayers.LonLat which is the passed-in view port
* OpenLayers.Pixel, translated into lon/lat by MM
* If multimap is not loaded, returns null.
* @type OpenLayers.LonLat
/************************************
* *
* MapObject Interface Controls *
* *
************************************/
// Get&Set Center, Zoom
/** Set the mapObject to the specified center and zoom
*
* @param {Object} center MapObject LonLat format
* @param {int} zoom MapObject zoom format
*/
getLonLatFromViewPortPx: function (viewPortPx) {
var lonlat = null;
if (this.multimap != null) {
var pixel = this.getPixelFromOLPixel(viewPortPx);
var zoom = this.multimap.getZoomFactor();
pixel.x = pixel.x - (this.map.getSize().w/2);
pixel.y = pixel.y - (this.map.getSize().h/2);
var mmLatLong = this.multimap.getMapPositionAt(pixel);
lonlat = this.getOLLonLatFromMMLatLong(mmLatLong);
}
return lonlat;
setMapObjectCenter: function(center, zoom) {
this.mapObject.goToPosition(center, zoom);
},
/**
* @param {OpenLayers.LonLat} lonlat
*
* @returns An OpenLayers.Pixel which is the passed-in OpenLayers.LonLat,
* translated into view port pixels BY MM
* If multimap is not loaded, returns null.
* @type OpenLayers.Pixel
* @returns the mapObject's current center in Map Object format
* @type Object
*/
getViewPortPxFromLonLat: function (lonlat) {
var viewPortPx = null;
if (this.multimap != null) {
var mmLatLong = this.getMMLatLongFromOLLonLat(lonlat);
var pixel = this.multimap.geoPosToContainerPixels(mmLatLong);
viewPortPx = this.getOLPixelFromPixel(pixel);
}
return viewPortPx;
getMapObjectCenter: function() {
return this.mapObject.getCurrentPosition();
},
/**
* @param {OpenLayers.Bounds} bounds
*
* @returns Corresponding zoom lemml for a specified Bounds.
* If multimap is not loaded, returns null.
/**
* @returns the mapObject's current zoom, in Map Object format
* @type int
*/
getZoomForExtent: function (bounds) {
var zoom = null;
if (this.multimap != null) {
var maxRes = this.map.getMaxResolution();
var viewSize = this.map.getSize();
var width = bounds.getWidth();
var height = bounds.getHeight();
var degPerPixel = (width > height) ? width / viewSize.w
: height / viewSize.h;
var mmZoom = Math.floor( (Math.log(maxRes/degPerPixel)) /
Math.log(2) );
//make sure zoom is within bounds
var mmZoom = Math.min(Math.max(mmZoom, this.minZoomLevel),
this.maxZoomLevel);
zoom = this.getOLZoomFromMMZoom(mmZoom);
}
return zoom;
getMapObjectZoom: function() {
return this.mapObject.getZoomFactor();
},
/********************************************************/
/* */
/* Translation Functions */
/* */
/* The following functions translate GMaps and OL */
/* formats for Pixel, LonLat, Bounds, and Zoom */
/* */
/********************************************************/
//
// TRANSLATION: GZoom <-> OpenLayers Zoom
//
// LonLat - Pixel Translation
/**
* @param {int} mmZoom
/**
* @param {Object} moPixel MapObject Pixel format
*
* @returns An OpenLayers Zoom lemml, translated from the passed in mmZoom
* Returns null if null value is passed in
* @type int
* @returns MapObject LonLat translated from MapObject Pixel
* @type Object
*/
getOLZoomFromMMZoom: function(mmZoom) {
if (mmZoom) return mmZoom - 1;
return null;
getMapObjectLonLatFromMapObjectPixel: function(moPixel) {
moPixel.x = moPixel.x - (this.map.getSize().w/2);
moPixel.y = moPixel.y - (this.map.getSize().h/2);
return this.mapObject.getMapPositionAt(moPixel);
},
/**
* @param {Object} moPixel MapObject Pixel format
*
* @returns MapObject Pixel translated from MapObject LonLat
* @type Object
*/
getMapObjectPixelFromMapObjectLonLat: function(moLonLat) {
return this.mapObject.geoPosToContainerPixels(moLonLat);
},
/************************************
* *
* MapObject Primitives *
* *
************************************/
// LonLat
/**
* @param {int} olZoom
* @param {Object} moLonLat MapObject LonLat format
*
* @returns A MMZoom lemml, translated from the passed in olZoom
* Returns null if null value is passed in
* @returns Longitude of the given MapObject LonLat
* @type float
*/
getLongitudeFromMapObjectLonLat: function(moLonLat) {
return moLonLat.lon;
},
/**
* @param {Object} moLonLat MapObject LonLat format
*
* @returns Latitude of the given MapObject LonLat
* @type float
*/
getLatitudeFromMapObjectLonLat: function(moLonLat) {
return moLonLat.lat;
},
/**
* @param {int} lon float
* @param {int} lat float
*
* @returns MapObject LonLat built from lon and lat params
* @type Object
*/
getMapObjectLonLatFromLonLat: function(lon, lat) {
return new MMLatLon(lat, lon);
},
// Pixel
/**
* @param {Object} moPixel MapObject Pixel format
*
* @returns X value of the MapObject Pixel
* @type int
*/
getMMZoomFromOLZoom: function(olZoom) {
if (olZoom) return olZoom + 1;
return null;
getXFromMapObjectPixel: function(moPixel) {
return moPixel.x;
},
//
// TRANSLATION: MMLatLong <-> LonLat
//
/**
* @param {MMLatLong} mmLatLong
/**
* @param {Object} moPixel MapObject Pixel format
*
* @returns An OpenLayers.LonLat, translated from the passed in MMLatLong
* Returns null if null value is passed in
* @type OpenLayers.LonLat
* @returns Y value of the MapObject Pixel
* @type int
*/
getOLLonLatFromMMLatLong: function(mmLatLong) {
var olLonLat = null;
if (mmLatLong != null) {
olLonLat = new OpenLayers.LonLat(mmLatLong.lon,
mmLatLong.lat);
}
return olLonLat;
getYFromMapObjectPixel: function(moPixel) {
return moPixel.y;
},
/**
* @param {OpenLayers.LonLat} olLonLat
/**
* @param {int} x
* @param {int} y
*
* @returns A MMLatLong, translated from the passed in OpenLayers.LonLat
* Returns null if null value is passed in
* @type MMLatLong
* @returns MapObject Pixel from x and y parameters
* @type Object
*/
getMMLatLongFromOLLonLat: function(olLonLat) {
var mmLatLong = null;
if (olLonLat != null) {
mmLatLong = new MMLatLon(olLonLat.lat, olLonLat.lon);
}
return mmLatLong;
getMapObjectPixelFromXY: function(x, y) {
return new MMPoint(x, y);
},
//
// TRANSLATION: Pixel <-> OpenLayers.Pixel
//
/**
* @param {Pixel} pixel
*
* @returns An OpenLayers.Pixel, translated from the passed in Pixel
* Returns null if null value is passed in
* @type OpenLayers.Pixel
*/
getOLPixelFromPixel: function(pixel) {
var olPixel = null;
if (pixel != null) {
olPixel = new OpenLayers.Pixel(pixel.x, pixel.y);
}
return olPixel;
},
/**
* @param {OpenLayers.Pixel} olPixel
*
* @returns A Pixel, translated from the passed in OpenLayers.Pixel
* Returns null if null value is passed in
*
* As it turns out, the only specifications we can see for the
* MM-compatible Pixel is an x & y property, which emmry
* OpenLayers.Pixel has by default. So just leamm it as-is.
*
* @type Pixel
*/
getPixelFromOLPixel: function(olPixel) {
var pixel = null;
if (olPixel != null) {
pixel = new MMPoint(olPixel.x, olPixel.y);
}
return pixel;
},
destroy: function() {
this.multimap = null;
OpenLayers.Layer.EventPane.prototype.destroy.apply(this, arguments);
},
/** @final @type String */
CLASS_NAME: "OpenLayers.Layer.MultiMap"
});

View File

@@ -3,82 +3,46 @@
* text of the license. */
/**
* @class
* @class
*
* @requires OpenLayers/Layer/EventPane.js
* @requires OpenLayers/Layer/FixedZoomLevels.js
*/
OpenLayers.Layer.VirtualEarth = OpenLayers.Class.create();
OpenLayers.Layer.VirtualEarth.prototype =
OpenLayers.Layer.VirtualEarth.prototype =
OpenLayers.Class.inherit( OpenLayers.Layer.EventPane,
OpenLayers.Layer.FixedZoomLevels, {
/** @type VEMap */
vemap: null,
/** @type int */
minZoomLevel: 1,
/** @final @type int */
MIN_ZOOM_LEVEL: 1,
/** @final @type int */
MAX_ZOOM_LEVEL: 17,
/** @type int */
maxZoomLevel: 17,
/**
/** Hardcode these resolutions so that they are more closely
* tied with the standard wms projection
*
* @final @type Array(float) */
RESOLUTIONS: [1.40625,0.703125,0.3515625,0.17578125,0.087890625,0.0439453125,0.02197265625,0.010986328125,0.0054931640625,0.00274658203125,0.001373291015625,0.0006866455078125,0.00034332275390625,0.000171661376953125,0.0000858306884765625,0.00004291534423828125],
/** @type VEMapType */
type: null,
/**
* @constructor
*
* @param {String} name
*/
initialize:function(name) {
initialize: function(name, options) {
OpenLayers.Layer.EventPane.prototype.initialize.apply(this, arguments);
OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this,
arguments);
this.numZoomLevels = this.maxZoomLevel - this.minZoomLevel + 1;
},
/**
* @param {OpenLayers.Map} map
*/
setMap:function(map) {
OpenLayers.Layer.EventPane.prototype.setMap.apply(this, arguments);
// once our layer has been added to the map, we can load the vemap
this.loadVEMap();
},
/**
* @param {OpenLayers.Bounds} bounds
* @param {Boolean} zoomChanged
* @param {Boolean} dragging
*/
moveTo:function(bounds, zoomChanged, dragging) {
OpenLayers.Layer.EventPane.prototype.moveTo.apply(this, arguments);
if (this.vemap != null) {
if (this.type != null) {
this.vemap.SetMapStyle(this.type);
this.type = null;
}
var olCenter = this.map.getCenter();
var veCenter = this.getVELatLongFromOLLonLat(olCenter);
if (zoomChanged) {
var olZoom = this.map.getZoom();
var veZoom = this.getVEZoomFromOLZoom(olZoom);
this.vemap.SetCenterAndZoom(veCenter, veZoom);
} else {
this.vemap.PanToLatLong(veCenter);
}
}
},
/**
*
*/
loadVEMap:function() {
loadMapObject:function() {
// create div and set to same size as map
var veDiv = OpenLayers.Util.createDiv(this.name);
@@ -87,47 +51,30 @@ OpenLayers.Layer.VirtualEarth.prototype =
veDiv.style.height = sz.h;
this.div.appendChild(veDiv);
try {
try { // crash prevention
this.mapObject = new VEMap(this.name);
} catch (e) { }
// create VEMap, hide nav controls
this.vemap = new VEMap(this.name);
} catch (e) {
// do nothing this is to keep from crashing
// if the VE library was not loaded.
if (this.mapObject != null) {
try { // this is to catch a Mozilla bug without falling apart
this.mapObject.LoadMap(null, null, this.type);
} catch (e) { }
this.mapObject.HideDashboard();
}
if (this.vemap == null) {
this.loadWarningMessage();
} else {
try {
this.vemap.LoadMap();
} catch (e) {
// this is to catch a Mozilla bug without falling apart
}
this.vemap.HideDashboard();
}
},
/** If we can't load the vemap, then display an error message to the
* user and tell them where to go for help.
*
* @private
*
/**
* @return String with information on why layer is broken, how to get
* it working.
* @type String
*/
loadWarningMessage:function() {
this.div.style.backgroundColor = "darkblue";
getWarningHTML:function() {
var html = "";
html += "The VE Layer was unable to load correctly.<br>";
html += "<br>";
html += "To get rid of this message, click on the VE Layer's "
html += "tab in the layer switcher in the upper-right corner.<br>";
html += "To get rid of this message, select a new BaseLayer "
html += "in the layer switcher in the upper-right corner.<br>";
html += "<br>";
html += "Most likely, this is because the VE library";
html += " script was either not correctly included.<br>";
@@ -137,229 +84,144 @@ OpenLayers.Layer.VirtualEarth.prototype =
html += "target='_blank'>";
html += "click here";
html += "</a>";
var viewSize = this.map.getSize();
msgW = Math.min(viewSize.w, 300);
msgH = Math.min(viewSize.h, 200);
var size = new OpenLayers.Size(msgW, msgH);
var centerPx = new OpenLayers.Pixel(viewSize.w/2, viewSize.h/2);
var topLeft = centerPx.add(-size.w/2, -size.h/2);
var div = OpenLayers.Util.createDiv("veWarning",
topLeft,
size,
null,
null,
null,
"auto");
div.style.padding = "7px";
div.style.backgroundColor = "yellow";
div.innerHTML = html;
this.div.appendChild(div);
return html;
},
/********************************************************/
/* */
/* Baselayer Functions */
/* */
/********************************************************/
/**
* @param {OpenLayers.Pixel} viewPortPx
*
* @returns An OpenLayers.LonLat which is the passed-in view port
* OpenLayers.Pixel, translated into lon/lat by VE
* If vemap is not loaded, returns null.
* @type OpenLayers.LonLat
/************************************
* *
* MapObject Interface Controls *
* *
************************************/
// Get&Set Center, Zoom
/** Set the mapObject to the specified center and zoom
*
* @param {Object} center MapObject LonLat format
* @param {int} zoom MapObject zoom format
*/
getLonLatFromViewPortPx: function (viewPortPx) {
var lonlat = null;
if (this.vemap != null) {
var pixel = this.getPixelFromOLPixel(viewPortPx);
var zoom = this.vemap.GetZoomLevel();
var veLatLong = this.vemap.PixelToLatLong(pixel.x, pixel.y, zoom);
lonlat = this.getOLLonLatFromVELatLong(veLatLong);
}
return lonlat;
setMapObjectCenter: function(center, zoom) {
this.mapObject.SetCenterAndZoom(center, zoom);
},
/**
* @param {OpenLayers.LonLat} lonlat
*
* @returns An OpenLayers.Pixel which is the passed-in OpenLayers.LonLat,
* translated into view port pixels BY VE
* If vemap is not loaded, returns null.
* @type OpenLayers.Pixel
* @returns the mapObject's current center in Map Object format
* @type Object
*/
getViewPortPxFromLonLat: function (lonlat) {
var viewPortPx = null;
if (this.vemap != null) {
var veLatLong = this.getVELatLongFromOLLonLat(lonlat);
var pixel = this.vemap.LatLongToPixel(veLatLong);
viewPortPx = this.getOLPixelFromPixel(pixel);
}
return viewPortPx;
getMapObjectCenter: function() {
return this.mapObject.GetCenter();
},
/**
* @param {OpenLayers.Bounds} bounds
*
* @returns Corresponding zoom level for a specified Bounds.
* If vemap is not loaded, returns null.
/**
* @returns the mapObject's current zoom, in Map Object format
* @type int
*/
getZoomForExtent: function (bounds) {
var zoom = null;
if (this.vemap != null) {
var maxRes = this.map.getMaxResolution();
var viewSize = this.map.getSize();
var width = bounds.getWidth();
var height = bounds.getHeight();
var degPerPixel = (width > height) ? width / viewSize.w
: height / viewSize.h;
var veZoom = Math.floor( (Math.log(maxRes/degPerPixel)) /
Math.log(2) );
//make sure zoom is within bounds
var veZoom = Math.min(Math.max(veZoom, this.minZoomLevel),
this.maxZoomLevel);
zoom = this.getOLZoomFromVEZoom(veZoom);
}
return zoom;
getMapObjectZoom: function() {
return this.mapObject.GetZoomLevel();
},
/********************************************************/
/* */
/* Translation Functions */
/* */
/* The following functions translate GMaps and OL */
/* formats for Pixel, LonLat, Bounds, and Zoom */
/* */
/********************************************************/
//
// TRANSLATION: GZoom <-> OpenLayers Zoom
//
// LonLat - Pixel Translation
/**
* @param {int} veZoom
/**
* @param {Object} moPixel MapObject Pixel format
*
* @returns An OpenLayers Zoom level, translated from the passed in veZoom
* Returns null if null value is passed in
* @type int
* @returns MapObject LonLat translated from MapObject Pixel
* @type Object
*/
getOLZoomFromVEZoom: function(veZoom) {
var zoom = null;
if (veZoom != null) {
zoom = veZoom - this.minZoomLevel;
}
return zoom;
getMapObjectLonLatFromMapObjectPixel: function(moPixel) {
return this.mapObject.PixelToLatLong(moPixel.x, moPixel.y);
},
/**
* @param {Object} moPixel MapObject Pixel format
*
* @returns MapObject Pixel translated from MapObject LonLat
* @type Object
*/
getMapObjectPixelFromMapObjectLonLat: function(moLonLat) {
return this.mapObject.LatLongToPixel(moLonLat);
},
/************************************
* *
* MapObject Primitives *
* *
************************************/
// LonLat
/**
* @param {int} olZoom
* @param {Object} moLonLat MapObject LonLat format
*
* @returns A VEZoom level, translated from the passed in olZoom
* Returns null if null value is passed in
* @returns Longitude of the given MapObject LonLat
* @type float
*/
getLongitudeFromMapObjectLonLat: function(moLonLat) {
return moLonLat.Longitude;
},
/**
* @param {Object} moLonLat MapObject LonLat format
*
* @returns Latitude of the given MapObject LonLat
* @type float
*/
getLatitudeFromMapObjectLonLat: function(moLonLat) {
return moLonLat.Latitude;
},
/**
* @param {int} lon float
* @param {int} lat float
*
* @returns MapObject LonLat built from lon and lat params
* @type Object
*/
getMapObjectLonLatFromLonLat: function(lon, lat) {
return new VELatLong(lat, lon);
},
// Pixel
/**
* @param {Object} moPixel MapObject Pixel format
*
* @returns X value of the MapObject Pixel
* @type int
*/
getVEZoomFromOLZoom: function(olZoom) {
var zoom = null;
if (olZoom != null) {
zoom = olZoom + this.minZoomLevel;
}
return zoom;
getXFromMapObjectPixel: function(moPixel) {
return moPixel.x;
},
//
// TRANSLATION: VELatLong <-> LonLat
//
/**
* @param {VELatLong} veLatLong
/**
* @param {Object} moPixel MapObject Pixel format
*
* @returns An OpenLayers.LonLat, translated from the passed in VELatLong
* Returns null if null value is passed in
* @type OpenLayers.LonLat
* @returns Y value of the MapObject Pixel
* @type int
*/
getOLLonLatFromVELatLong: function(veLatLong) {
var olLonLat = null;
if (veLatLong != null) {
olLonLat = new OpenLayers.LonLat(veLatLong.Longitude,
veLatLong.Latitude);
}
return olLonLat;
getYFromMapObjectPixel: function(moPixel) {
return moPixel.y;
},
/**
* @param {OpenLayers.LonLat} olLonLat
/**
* @param {int} x
* @param {int} y
*
* @returns A VELatLong, translated from the passed in OpenLayers.LonLat
* Returns null if null value is passed in
* @type VELatLong
* @returns MapObject Pixel from x and y parameters
* @type Object
*/
getVELatLongFromOLLonLat: function(olLonLat) {
var veLatLong = null;
if (olLonLat != null) {
veLatLong = new VELatLong(olLonLat.lat, olLonLat.lon);
}
return veLatLong;
getMapObjectPixelFromXY: function(x, y) {
return new Msn.VE.Pixel(x, y);
},
//
// TRANSLATION: Pixel <-> OpenLayers.Pixel
//
/**
* @param {Pixel} pixel
*
* @returns An OpenLayers.Pixel, translated from the passed in Pixel
* Returns null if null value is passed in
* @type OpenLayers.Pixel
*/
getOLPixelFromPixel: function(pixel) {
var olPixel = null;
if (pixel != null) {
olPixel = new OpenLayers.Pixel(pixel.x, pixel.y);
}
return olPixel;
},
/**
* @param {OpenLayers.Pixel} olPixel
*
* @returns A Pixel, translated from the passed in OpenLayers.Pixel
* Returns null if null value is passed in
*
* As it turns out, the only specifications we can see for the
* VE-compatible Pixel is an x & y property, which every
* OpenLayers.Pixel has by default. So just leave it as-is.
*
* @type Pixel
*/
getPixelFromOLPixel: function(olPixel) {
var pixel = null;
if (olPixel != null) {
pixel = new Msn.VE.Pixel(olPixel.x, olPixel.y);
}
return pixel;
},
/** @final @type String */
CLASS_NAME: "OpenLayers.Layer.VirtualEarth"
});

View File

@@ -20,6 +20,8 @@ OpenLayers.Layer.WMS.prototype =
exceptions: "application/vnd.ogc.se_inimage",
format: "image/jpeg"
},
reproject: true,
/**
* @constructor
@@ -42,7 +44,7 @@ OpenLayers.Layer.WMS.prototype =
// unless explicitly set in options, if the layer is transparent,
// it will be an overlay
if ((options == null) || !(options.isBaseLayer)) {
if (options == null || options.isBaseLayer == null) {
this.isBaseLayer = ((this.params.TRANSPARENT != "true") &&
(this.params.TRANSPARENT != true));
}

View File

@@ -21,6 +21,7 @@ OpenLayers.Layer.WMS.Untiled.prototype =
exceptions: "application/vnd.ogc.se_inimage",
format: "image/jpeg"
},
reproject: true,
/** @type OpenLayers.Tile.Image */
tile: null,

View File

@@ -3,208 +3,105 @@
* text of the license. */
/**
* @class
* @class
*
* @requires OpenLayers/Layer/EventPane.js
* @requires OpenLayers/Layer/FixedZoomLevels.js
*/
OpenLayers.Layer.Yahoo = OpenLayers.Class.create();
OpenLayers.Layer.Yahoo.prototype =
OpenLayers.Class.inherit( OpenLayers.Layer.EventPane, {
/** @type YMap */
yahoomap: null,
OpenLayers.Layer.Yahoo.prototype =
OpenLayers.Class.inherit( OpenLayers.Layer.EventPane,
OpenLayers.Layer.FixedZoomLevels, {
/** @type int */
minZoomLevel: 0,
/** @type int */
maxZoomLevel: 15,
/** @final @type int */
MIN_ZOOM_LEVEL: 0,
/**
/** @final @type int */
MAX_ZOOM_LEVEL: 15,
/** Hardcode these resolutions so that they are more closely
* tied with the standard wms projection
*
* @final @type Array(float) */
RESOLUTIONS: [1.40625,0.703125,0.3515625,0.17578125,0.087890625,0.0439453125,0.02197265625,0.010986328125,0.0054931640625,0.00274658203125,0.001373291015625,0.0006866455078125,0.00034332275390625,0.000171661376953125,0.0000858306884765625,0.00004291534423828125],
/** @type YahooMapType */
type: null,
/**
* @constructor
*
* @param {String} name
*/
initialize:function(name) {
initialize: function(name, options) {
OpenLayers.Layer.EventPane.prototype.initialize.apply(this, arguments);
this.numZoomLevels = this.maxZoomLevel - this.minZoomLevel + 1;
OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this,
arguments);
},
/**
* @param {OpenLayers.Map} map
*/
setMap:function(map) {
OpenLayers.Layer.EventPane.prototype.setMap.apply(this, arguments);
// once our layer has been added to the map, we can load the yahoomap
this.loadYMap();
},
/**
* @param {OpenLayers.Bounds} bounds
* @param {Boolean} zoomChanged
* @param {Boolean} dragging
*/
moveTo:function(bounds, zoomChanged, dragging) {
OpenLayers.Layer.EventPane.prototype.moveTo.apply(this, arguments);
if (this.yahoomap != null) {
var olCenter = this.map.getCenter();
var mmCenter = this.getYLatLongFromOLLonLat(olCenter);
if (zoomChanged) {
var olZoom = this.map.getZoom();
var mmZoom = this.getYZoomFromOLZoom(olZoom);
this.yahoomap.setZoomLevel(mmZoom);
}
this.yahoomap.drawZoomAndCenter(mmCenter, mmZoom);
}
},
/**
*
*/
loadYMap:function() {
this.yahoomap = new YMap(this.div);
loadMapObject:function() {
try { //do not crash!
this.mapObject = new YMap(this.div, this.type);
} catch(e) {}
},
/** Overridden from EventPane because we need to remove this yahoo event
* pane which prohibits our drag and drop, and we can only do this
* once the map has been loaded and centered.
*
* @param {OpenLayers.Map} map
*/
setMap: function(map) {
OpenLayers.Layer.EventPane.prototype.setMap.apply(this, arguments);
if (this.yahoomap == null) {
this.loadWarningMessage();
}
this.map.events.register("moveend", this, this.fixYahooEventPane);
},
/** If we can't load the yahoomap, then display an error message to the
* user and tell them where to go for help.
/** The map has been centered, so the mysterious yahoo eventpane has been
* added. we remove it so that it doesnt mess with *our* event pane.
*
* @private
*
*/
loadWarningMessage:function() {
fixYahooEventPane: function() {
var yahooEventPane = $("ygddfdiv");
if (yahooEventPane != null) {
if (yahooEventPane.parentNode != null)
yahooEventPane.parentNode.removeChild(yahooEventPane);
this.div.style.backgroundColor = "darkblue";
this.map.events.unregister("moveend", this,
this.fixYahooEventPane);
}
},
/**
* @return String with information on why layer is broken, how to get
* it working.
* @type String
*/
getWarningHTML:function() {
var html = "";
html += "The Y Layer was unable to load correctly.<br>";
html += "The Yahoo Layer was unable to load correctly.<br>";
html += "<br>";
html += "To get rid of this message, click on the Y Layer's "
html += "tab in the layer switcher in the upper-right corner.<br>";
html += "To get rid of this message, select a new BaseLayer "
html += "in the layer switcher in the upper-right corner.<br>";
html += "<br>";
html += "Most likely, this is because the Y library";
html += "Most likely, this is because the Yahoo library";
html += " script was either not correctly included.<br>";
html += "<br>";
html += "Demmlopers: For help getting this working correctly, ";
html += "Developers: For help getting this working correctly, ";
html += "<a href='http://trac.openlayers.org/wiki/YahooLayer' "
html += "target='_blank'>";
html += "click here";
html += "</a>";
var viewSize = this.map.getSize();
msgW = Math.min(viewSize.w, 300);
msgH = Math.min(viewSize.h, 200);
var size = new OpenLayers.Size(msgW, msgH);
var centerPx = new OpenLayers.Pixel(viewSize.w/2, viewSize.h/2);
var topLeft = centerPx.add(-size.w/2, -size.h/2);
var div = OpenLayers.Util.createDiv("mmWarning",
topLeft,
size,
null,
null,
null,
"auto");
div.style.padding = "7px";
div.style.backgroundColor = "yellow";
div.innerHTML = html;
this.div.appendChild(div);
return html;
},
/********************************************************/
/* */
/* Baselayer Functions */
/* */
/********************************************************/
/**
* @param {OpenLayers.Pixel} viewPortPx
*
* @returns An OpenLayers.LonLat which is the passed-in view port
* OpenLayers.Pixel, translated into lon/lat by Y
* If yahoomap is not loaded, returns null.
* @type OpenLayers.LonLat
*/
getLonLatFromViewPortPx: function (viewPortPx) {
var lonlat = null;
if (this.yahoomap != null) {
var pixel = this.getPixelFromOLPixel(viewPortPx);
var mmLatLong = this.yahoomap.convertXYLatLon(pixel);
lonlat = this.getOLLonLatFromYLatLong(mmLatLong);
}
return lonlat;
},
/**
* @param {OpenLayers.LonLat} lonlat
*
* @returns An OpenLayers.Pixel which is the passed-in OpenLayers.LonLat,
* translated into view port pixels BY Y
* If yahoomap is not loaded, returns null.
* @type OpenLayers.Pixel
*/
getViewPortPxFromLonLat: function (lonlat) {
var viewPortPx = null;
if (this.yahoomap != null) {
var mmLatLong = this.getYLatLongFromOLLonLat(lonlat);
var pixel = this.yahoomap.convertLatLonXY(mmLatLong);
viewPortPx = this.getOLPixelFromPixel(pixel);
}
return viewPortPx;
},
/**
* @param {OpenLayers.Bounds} bounds
*
* @returns Corresponding zoom lemml for a specified Bounds.
* If yahoomap is not loaded, returns null.
* @type int
*/
getZoomForExtent: function (bounds) {
var zoom = null;
if (this.yahoomap != null) {
var maxRes = this.map.getMaxResolution();
var viewSize = this.map.getSize();
var width = bounds.getWidth();
var height = bounds.getHeight();
var degPerPixel = (width > height) ? width / viewSize.w
: height / viewSize.h;
var mmZoom = Math.floor( (Math.log(maxRes/degPerPixel)) /
Math.log(2) );
//make sure zoom is within bounds
var mmZoom = Math.min(Math.max(mmZoom, this.minZoomLevel),
this.maxZoomLevel);
zoom = this.getOLZoomFromYZoom(mmZoom);
}
return zoom;
},
/********************************************************/
/* */
/* Translation Functions */
@@ -214,107 +111,175 @@ OpenLayers.Layer.Yahoo.prototype =
/* */
/********************************************************/
//
// TRANSLATION: GZoom <-> OpenLayers Zoom
// TRANSLATION: MapObject Zoom <-> OpenLayers Zoom
//
/**
* @param {int} mmZoom
* @param {int} gZoom
*
* @returns An OpenLayers Zoom lemml, translated from the passed in mmZoom
* @returns An OpenLayers Zoom level, translated from the passed in gZoom
* Returns null if null value is passed in
* @type int
*/
getOLZoomFromYZoom: function(mmZoom) {
return 18 - mmZoom;
getOLZoomFromMapObjectZoom: function(moZoom) {
var zoom = null;
if (moZoom != null) {
zoom = OpenLayers.Layer.FixedZoomLevels.prototype.getOLZoomFromMapObjectZoom.apply(this, [moZoom]);
zoom = 18 - zoom;
}
return zoom;
},
/**
* @param {int} olZoom
*
* @returns A YZoom lemml, translated from the passed in olZoom
* @returns A MapObject level, translated from the passed in olZoom
* Returns null if null value is passed in
* @type int
*/
getYZoomFromOLZoom: function(olZoom) {
return 18 - olZoom;
getMapObjectZoomFromOLZoom: function(olZoom) {
var zoom = null;
if (olZoom != null) {
zoom = OpenLayers.Layer.FixedZoomLevels.prototype.getMapObjectZoomFromOLZoom.apply(this, [olZoom]);
zoom = 18 - zoom;
}
return zoom;
},
//
// TRANSLATION: YLatLong <-> LonLat
//
/************************************
* *
* MapObject Interface Controls *
* *
************************************/
/**
* @param {YLatLong} mmLatLong
// Get&Set Center, Zoom
/** Set the mapObject to the specified center and zoom
*
* @returns An OpenLayers.LonLat, translated from the passed in YLatLong
* Returns null if null value is passed in
* @type OpenLayers.LonLat
* @param {Object} center MapObject LonLat format
* @param {int} zoom MapObject zoom format
*/
getOLLonLatFromYLatLong: function(mmLatLong) {
var olLonLat = null;
if (mmLatLong != null) {
olLonLat = new OpenLayers.LonLat(mmLatLong.Lon,
mmLatLong.Lat);
}
return olLonLat;
setMapObjectCenter: function(center, zoom) {
this.mapObject.drawZoomAndCenter(center, zoom);
},
/**
* @returns the mapObject's current center in Map Object format
* @type Object
*/
getMapObjectCenter: function() {
return this.mapObject.getCenterLatLon();
},
/**
* @returns the mapObject's current zoom, in Map Object format
* @type int
*/
getMapObjectZoom: function() {
return this.mapObject.getZoomLevel();
},
// LonLat - Pixel Translation
/**
* @param {Object} moPixel MapObject Pixel format
*
* @returns MapObject LonLat translated from MapObject Pixel
* @type Object
*/
getMapObjectLonLatFromMapObjectPixel: function(moPixel) {
return this.mapObject.convertXYLatLon(moPixel);
},
/**
* @param {Object} moPixel MapObject Pixel format
*
* @returns MapObject Pixel translated from MapObject LonLat
* @type Object
*/
getMapObjectPixelFromMapObjectLonLat: function(moLonLat) {
return this.mapObject.convertLatLonXY(moLonLat);
},
/************************************
* *
* MapObject Primitives *
* *
************************************/
// LonLat
/**
* @param {Object} moLonLat MapObject LonLat format
*
* @returns Longitude of the given MapObject LonLat
* @type float
*/
getLongitudeFromMapObjectLonLat: function(moLonLat) {
return moLonLat.Lon;
},
/**
* @param {OpenLayers.LonLat} olLonLat
* @param {Object} moLonLat MapObject LonLat format
*
* @returns A YLatLong, translated from the passed in OpenLayers.LonLat
* Returns null if null value is passed in
* @type YLatLong
* @returns Latitude of the given MapObject LonLat
* @type float
*/
getYLatLongFromOLLonLat: function(olLonLat) {
var mmLatLong = null;
if (olLonLat != null) {
mmLatLong = new YGeoPoint(olLonLat.lat, olLonLat.lon);
}
return mmLatLong;
},
//
// TRANSLATION: Pixel <-> OpenLayers.Pixel
//
/**
* @param {Pixel} pixel
*
* @returns An OpenLayers.Pixel, translated from the passed in Pixel
* Returns null if null value is passed in
* @type OpenLayers.Pixel
*/
getOLPixelFromPixel: function(pixel) {
var olPixel = null;
if (pixel != null) {
olPixel = new OpenLayers.Pixel(pixel.x, pixel.y);
}
return olPixel;
getLatitudeFromMapObjectLonLat: function(moLonLat) {
return moLonLat.Lat;
},
/**
* @param {OpenLayers.Pixel} olPixel
* @param {int} lon float
* @param {int} lat float
*
* @returns A Pixel, translated from the passed in OpenLayers.Pixel
* Returns null if null value is passed in
*
* As it turns out, the only specifications we can see for the
* Y-compatible Pixel is an x & y property, which emmry
* OpenLayers.Pixel has by default. So just leamm it as-is.
*
* @type Pixel
* @returns MapObject LonLat built from lon and lat params
* @type Object
*/
getPixelFromOLPixel: function(olPixel) {
var pixel = null;
if (olPixel != null) {
pixel = new YCoordPoint(olPixel.x, olPixel.y);
}
return pixel;
getMapObjectLonLatFromLonLat: function(lon, lat) {
return new YGeoPoint(lat, lon);
},
// Pixel
/**
* @param {Object} moPixel MapObject Pixel format
*
* @returns X value of the MapObject Pixel
* @type int
*/
getXFromMapObjectPixel: function(moPixel) {
return moPixel.x;
},
/**
* @param {Object} moPixel MapObject Pixel format
*
* @returns Y value of the MapObject Pixel
* @type int
*/
getYFromMapObjectPixel: function(moPixel) {
return moPixel.y;
},
/**
* @param {int} x
* @param {int} y
*
* @returns MapObject Pixel from x and y parameters
* @type Object
*/
getMapObjectPixelFromXY: function(x, y) {
return new YCoordPoint(x, y);
},
/** @final @type String */
CLASS_NAME: "OpenLayers.Layer.Yahoo"
});

View File

@@ -131,6 +131,7 @@ OpenLayers.Map.prototype = {
"hidden");
this.viewPortDiv.style.width = "100%";
this.viewPortDiv.style.height = "100%";
this.viewPortDiv.className = "olMapViewport";
this.div.appendChild(this.viewPortDiv);
// the layerContainerDiv is the one that holds all the layers
@@ -298,14 +299,12 @@ OpenLayers.Map.prototype = {
if (this.baseLayer == null) {
// set the first baselaye we add as the baselayer
this.setBaseLayer(layer);
this.events.triggerEvent("changebaselayer");
} else {
layer.setVisibility(false);
}
} else {
var extent = this.getExtent();
if (extent) {
layer.moveTo(extent, true);
if (this.getCenter() != null) {
layer.moveTo(this.getExtent(), true);
}
}
@@ -450,13 +449,13 @@ OpenLayers.Map.prototype = {
//redraw all layers
var center = this.getCenter();
if (center != null) {
var zoom = null;
if (oldBaseLayer != null) {
var oldResolution = oldBaseLayer.getResolution();
zoom = this.baseLayer.getZoomForResolution(oldResolution);
if (oldBaseLayer == null) {
this.setCenter(center);
} else {
this.zoomToExtent(oldBaseLayer.getExtent());
}
this.setCenter(center, zoom);
}
if ((noEvent == null) || (noEvent == false)) {
this.events.triggerEvent("changebaselayer");
}
@@ -702,21 +701,33 @@ OpenLayers.Map.prototype = {
}
}
//send the move call to the baselayer and all the overlays
var bounds = this.getExtent();
//send the move call to the baselayer and all the overlays
this.baseLayer.moveTo(bounds, zoomChanged, dragging);
for (var i = 0; i < this.layers.length; i++) {
var layer = this.layers[i];
var inRange = layer.calculateInRange();
if (layer.inRange != inRange) {
layer.inRange = inRange;
layer.display(layer.visibility && layer.inRange);
this.events.triggerEvent("changelayer");
}
if (layer.visibility && layer.inRange) {
layer.moveTo(bounds, zoomChanged, dragging);
}
if (!layer.isBaseLayer) {
var moveLayer;
var inRange = layer.calculateInRange();
if (layer.inRange != inRange) {
// Layer property has changed. We are going
// to call moveLayer so that the layer can be turned
// off or on.
layer.inRange = inRange;
moveLayer = true;
this.events.triggerEvent("changelayer");
} else {
// If nothing has changed, then we only move the layer
// if it is visible and inrange.
moveLayer = (layer.visibility && layer.inRange);
}
if (moveLayer) {
layer.moveTo(bounds, zoomChanged, dragging);
}
}
}
this.events.triggerEvent("move");

View File

@@ -41,6 +41,13 @@ OpenLayers.Popup.prototype = {
/** @type String */
border: "",
/** @type DOMElement */
contentDiv:null,
/** @type int */
padding: 5,
/** this gets set in Map.js when the popup is added to the map
* @type OpenLayers.Map */
@@ -74,6 +81,14 @@ OpenLayers.Popup.prototype = {
this.div = OpenLayers.Util.createDiv(this.id, null, null,
null, null, null, "hidden");
this.div.className = 'olPopup';
var id = this.div.id + "_contentDiv";
this.contentDiv = OpenLayers.Util.createDiv(id, null, this.size.clone(),
null, "relative", null,
"hidden");
this.contentDiv.className = 'olPopupContent';
this.div.appendChild(this.contentDiv);
this.registerEvents();
},
@@ -219,17 +234,18 @@ OpenLayers.Popup.prototype = {
},
/**
* @param {String} contentHTML
*/
* @param {String} contentHTML
*/
setContentHTML:function(contentHTML) {
if (contentHTML != null) {
this.contentHTML = contentHTML;
}
if (this.div != null) {
this.div.innerHTML = this.contentHTML;
if (this.contentDiv != null) {
this.contentDiv.innerHTML = this.contentHTML;
}
},
/** Do this in a separate function so that subclasses can

View File

@@ -15,9 +15,7 @@ OpenLayers.Popup.AnchoredBubble.CORNER_SIZE = 5;
OpenLayers.Popup.AnchoredBubble.prototype =
OpenLayers.Class.inherit( OpenLayers.Popup.Anchored, {
/** @type DOMElement */
contentDiv:null,
rounded: false,
/**
* @constructor
@@ -45,18 +43,10 @@ OpenLayers.Popup.AnchoredBubble.prototype =
OpenLayers.Popup.Anchored.prototype.draw.apply(this, arguments);
// make the content Div
var contentSize = this.size.clone();
contentSize.h -= (2 * OpenLayers.Popup.AnchoredBubble.CORNER_SIZE);
var id = this.div.id + "_contentDiv";
this.contentDiv = OpenLayers.Util.createDiv(id, null, contentSize,
null, "relative", null,
"hidden");
this.div.appendChild(this.contentDiv);
this.setContentHTML();
this.setRicoCorners(true);
this.setRicoCorners(!this.rounded);
this.rounded = true;
//set the popup color and opacity
this.setBackgroundColor();
@@ -75,11 +65,13 @@ OpenLayers.Popup.AnchoredBubble.prototype =
var contentSize = this.size.clone();
contentSize.h -= (2 * OpenLayers.Popup.AnchoredBubble.CORNER_SIZE);
contentSize.h -= (2 * this.padding);
this.contentDiv.style.height = contentSize.h + "px";
//size has changed - must redo corners
this.setRicoCorners(false);
this.setRicoCorners(!this.rounded);
this.rounded = true;
}
},
@@ -122,19 +114,6 @@ OpenLayers.Popup.AnchoredBubble.prototype =
this.border = 0;
},
/**
* @param {String} contentHTML
*/
setContentHTML:function(contentHTML) {
if (contentHTML != null) {
this.contentHTML = contentHTML;
}
if (this.contentDiv != null) {
this.contentDiv.innerHTML = this.contentHTML;
}
},
/**
* @private
*

View File

@@ -96,6 +96,25 @@ OpenLayers.Tile.prototype = {
clear: function() {
this.drawn = false;
},
getBoundsFromBaseLayer: function(position) {
var topLeft = this.layer.map.getLonLatFromLayerPx(this.position);
var bottomRightPx = this.position.clone();
bottomRightPx.x += this.size.w;
bottomRightPx.y += this.size.h;
var bottomRight = this.layer.map.getLonLatFromLayerPx(bottomRightPx);
// Handle the case where the base layer wraps around the date line.
// Google does this, and it breaks WMS servers to request bounds in that fashion.
if (topLeft.lon > bottomRight.lon) {
if (topLeft.lon < 0) {
topLeft.lon = -180 - (topLeft.lon+180);
} else {
bottomRight.lon = 180+bottomRight.lon+180;
}
}
bounds = new OpenLayers.Bounds(topLeft.lon, bottomRight.lat, bottomRight.lon, topLeft.lat);
return bounds;
},
/** @final @type String */
CLASS_NAME: "OpenLayers.Tile"

View File

@@ -26,7 +26,7 @@ OpenLayers.Tile.Image.prototype =
initialize: function(layer, position, bounds, url, size) {
OpenLayers.Tile.prototype.initialize.apply(this, arguments);
},
/**
*
*/
@@ -47,7 +47,11 @@ OpenLayers.Tile.Image.prototype =
if (this.imgDiv == null) {
this.initImgDiv();
}
if (this.layer != this.layer.map.baseLayer && this.layer.reproject) {
this.bounds = this.getBoundsFromBaseLayer(this.position);
}
this.url = this.layer.getURL(this.bounds);
this.imgDiv.style.display = "none";
if (this.layer.displayOutsideMaxExtent || (this.layer.maxExtent &&
(this.bounds.intersectsBounds(this.layer.maxExtent,false))
@@ -79,6 +83,9 @@ OpenLayers.Tile.Image.prototype =
* @param {Boolean} redraw
*/
moveTo: function (bounds, position, redraw) {
if (this.layer != this.layer.map.baseLayer && this.layer.reproject) {
bounds = this.getBoundsFromBaseLayer(position);
}
this.url = this.layer.getURL(bounds);
OpenLayers.Tile.prototype.moveTo.apply(this, arguments);
},
@@ -107,6 +114,15 @@ OpenLayers.Tile.Image.prototype =
null,
true);
}
this.imgDiv.className = 'olTileImage';
/* checkImgURL *should* pretty predictably get called after the
createImage / createAlphaImageDiv onLoad handler */
OpenLayers.Event.observe( this.imgDiv, "load",
this.checkImgURL.bindAsEventListener(this) );
this.layer.div.appendChild(this.imgDiv);
if(this.layer.opacity != null) {
@@ -116,6 +132,23 @@ OpenLayers.Tile.Image.prototype =
}
},
/**
* Make sure that the image that just loaded is the one this tile is meant
* to display, since panning/zooming might have changed the tile's URL in
* the meantime. If the tile URL did change before the image loaded, set
* the imgDiv display to 'none', as either (a) it will be reset to visible
* when the new URL loads in the image, or (b) we don't want to display
* this tile after all because its new bounds are outside our maxExtent.
*
* @private
*/
checkImgURL: function () {
var loaded = this.layer.alpha ? this.imgDiv.firstChild.src : this.imgDiv.src;
if (loaded != this.url) {
this.imgDiv.style.display = "none";
}
},
/** @final @type String */
CLASS_NAME: "OpenLayers.Tile.Image"
}

View File

@@ -133,9 +133,6 @@ OpenLayers.Util.createDiv = function(id, px, sz, imgURL, position,
var dom = document.createElement('div');
//set specific properties
dom.style.padding = "0";
dom.style.margin = "0";
if (imgURL) {
dom.style.backgroundImage = 'url(' + imgURL + ')';
}