/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
OpenLayers.ProxyHost = "";
//OpenLayers.ProxyHost = "examples/proxy.cgi?url=";
/**
* Ajax reader for OpenLayers
*
*  @uri url to do remote XML http get
*  @param {String} 'get' format params (x=y&a=b...)
*  @who object to handle callbacks for this request
*  @complete  the function to be called on success
*  @failure  the function to be called on failure
*
*   example usage from a caller:
*
*     caps: function(request) {
*      -blah-
*     },
*
*     OpenLayers.loadURL(url,params,this,caps);
*
* Notice the above example does not provide an error handler; a default empty
* handler is provided which merely logs the error if a failure handler is not
* supplied
*
*/
/**
* @param {} request
*/
OpenLayers.nullHandler = function(request) {
alert(OpenLayers.i18n("unhandledRequest", {'statusText':request.statusText}));
};
/**
* Function: loadURL
* Background load a document.
*
* Parameters:
* uri - {String} URI of source doc
* params - {String} Params on get (doesnt seem to work)
* caller - {Object} object which gets callbacks
* onComplete - {Function} Optional callback for success.  The callback
*     will be called with this set to caller and will receive the request
*     object as an argument.
* onFailure - {Function} Optional callback for failure.  In the event of
*     a failure, the callback will be called with this set to caller and will
*     receive the request object as an argument.
*
* Returns:
* {XMLHttpRequest}  The request object.  To abort loading, call
*     request.abort().
*/
OpenLayers.loadURL = function(uri, params, caller,
onComplete, onFailure) {
var success = (onComplete) ? OpenLayers.Function.bind(onComplete, caller)
: OpenLayers.nullHandler;
var failure = (onFailure) ? OpenLayers.Function.bind(onFailure, caller)
: OpenLayers.nullHandler;
// from prototype.js
var request = new OpenLayers.Ajax.Request(
uri,
{
method: 'get',
parameters: params,
onComplete: success,
onFailure: failure
}
);
return request.transport;
};
/**
* Function: parseXMLString
* Parse XML into a doc structure
*
* Parameters:
* text - {String}
*
* Returns:
* {?} Parsed AJAX Responsev
*/
OpenLayers.parseXMLString = function(text) {
//MS sucks, if the server is bad it dies
var index = text.indexOf('<');
if (index > 0) {
text = text.substring(index);
}
var ajaxResponse = OpenLayers.Util.Try(
function() {
var xmldom = new ActiveXObject('Microsoft.XMLDOM');
xmldom.loadXML(text);
return xmldom;
},
function() {
return new DOMParser().parseFromString(text, 'text/xml');
},
function() {
var req = new XMLHttpRequest();
req.open("GET", "data:" + "text/xml" +
";charset=utf-8," + encodeURIComponent(text), false);
if (req.overrideMimeType) {
req.overrideMimeType("text/xml");
}
req.send(null);
return req.responseXML;
}
);
return ajaxResponse;
};
/**
* Namespace: OpenLayers.Ajax
*/
OpenLayers.Ajax = {
/**
* Method: emptyFunction
*/
emptyFunction: function () {},
/**
* Method: getTransport
*
* Returns:
* {Object} Transport mechanism for whichever browser we're in, or false if
*          none available.
*/
getTransport: function() {
return OpenLayers.Util.Try(
function() {return new XMLHttpRequest();},
function() {return new ActiveXObject('Msxml2.XMLHTTP');},
function() {return new ActiveXObject('Microsoft.XMLHTTP');}
) || false;
},
/**
* Property: activeRequestCount
* {Integer}
*/
activeRequestCount: 0
};
/**
* Namespace: OpenLayers.Ajax.Responders
* {Object}
*/
OpenLayers.Ajax.Responders = {
/**
* Property: responders
* {Array}
*/
responders: [],
/**
* Method: register
*
* Parameters:
* responderToAdd - {?}
*/
register: function(responderToAdd) {
for (var i = 0; i < this.responders.length; i++){
if (responderToAdd == this.responders[i]){
return;
}
}
this.responders.push(responderToAdd);
},
/**
* Method: unregister
*
* Parameters:
* responderToRemove - {?}
*/
unregister: function(responderToRemove) {
OpenLayers.Util.removeItem(this.reponders, responderToRemove);
},
/**
* Method: dispatch
*
* Parameters:
* callback - {?}
* request - {?}
* transport - {?}
*/
dispatch: function(callback, request, transport) {
var responder;
for (var i = 0; i < this.responders.length; i++) {
responder = this.responders[i];
if (responder[callback] &&
typeof responder[callback] == 'function') {
try {
responder[callback].apply(responder,
[request, transport]);
} catch (e) {}
}
}
}
};
OpenLayers.Ajax.Responders.register({
/**
* Function: onCreate
*/
onCreate: function() {
OpenLayers.Ajax.activeRequestCount++;
},
/**
* Function: onComplete
*/
onComplete: function() {
OpenLayers.Ajax.activeRequestCount--;
}
});
/**
* Class: OpenLayers.Ajax.Base
*/
OpenLayers.Ajax.Base = OpenLayers.Class({
/**
* Constructor: OpenLayers.Ajax.Base
*
* Parameters:
* options - {Object}
*/
initialize: function(options) {
this.options = {
method:       'post',
asynchronous: true,
contentType:  'application/xml',
parameters:   ''
};
OpenLayers.Util.extend(this.options, options || {});
this.options.method = this.options.method.toLowerCase();
if (typeof this.options.parameters == 'string') {
this.options.parameters =
OpenLayers.Util.getParameters(this.options.parameters);
}
}
});
/**
* Class: OpenLayers.Ajax.Request
*
* Inherit:
*  - <OpenLayers.Ajax.Base>
*/
OpenLayers.Ajax.Request = OpenLayers.Class(OpenLayers.Ajax.Base, {
/**
* Property: _complete
*
* {Boolean}
*/
_complete: false,
/**
* Constructor: OpenLayers.Ajax.Request
*
* Parameters:
* url - {String}
* options - {Object}
*/
initialize: function(url, options) {
OpenLayers.Ajax.Base.prototype.initialize.apply(this, [options]);
if (OpenLayers.ProxyHost && OpenLayers.String.startsWith(url, "http")) {
url = OpenLayers.ProxyHost + encodeURIComponent(url);
}
this.transport = OpenLayers.Ajax.getTransport();
this.request(url);
},
/**
* Method: request
*
* Parameters:
* url - {String}
*/
request: function(url) {
this.url = url;
this.method = this.options.method;
var params = OpenLayers.Util.extend({}, this.options.parameters);
if (this.method != 'get' && this.method != 'post') {
// simulate other verbs over post
params['_method'] = this.method;
this.method = 'post';
}
this.parameters = params;
if (params = OpenLayers.Util.getParameterString(params)) {
// when GET, append parameters to URL
if (this.method == 'get') {
this.url += ((this.url.indexOf('?') > -1) ? '&' : '?') + params;
} else if (/Konqueror|Safari|KHTML/.test(navigator.userAgent)) {
params += '&_=';
}
}
try {
var response = new OpenLayers.Ajax.Response(this);
if (this.options.onCreate) {
this.options.onCreate(response);
}
OpenLayers.Ajax.Responders.dispatch('onCreate',
this,
response);
this.transport.open(this.method.toUpperCase(),
this.url,
this.options.asynchronous);
if (this.options.asynchronous) {
window.setTimeout(
OpenLayers.Function.bind(this.respondToReadyState, this, 1),
10);
}
this.transport.onreadystatechange =
OpenLayers.Function.bind(this.onStateChange, this);
this.setRequestHeaders();
this.body =  this.method == 'post' ?
(this.options.postBody || params) : null;
this.transport.send(this.body);
// Force Firefox to handle ready state 4 for synchronous requests
if (!this.options.asynchronous &&
this.transport.overrideMimeType) {
this.onStateChange();
}
} catch (e) {
this.dispatchException(e);
}
},
/**
* Method: onStateChange
*/
onStateChange: function() {
var readyState = this.transport.readyState;
if (readyState > 1 && !((readyState == 4) && this._complete)) {
this.respondToReadyState(this.transport.readyState);
}
},
/**
* Method: setRequestHeaders
*/
setRequestHeaders: function() {
var headers = {
'X-Requested-With': 'XMLHttpRequest',
'Accept': 'text/javascript, text/html, application/xml, text/xml, */*',
'OpenLayers': true
};
if (this.method == 'post') {
headers['Content-type'] = this.options.contentType +
(this.options.encoding ? '; charset=' + this.options.encoding : '');
/* Force "Connection: close" for older Mozilla browsers to work
* around a bug where XMLHttpRequest sends an incorrect
* Content-length header. See Mozilla Bugzilla #246651.
*/
if (this.transport.overrideMimeType &&
(navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005) {
headers['Connection'] = 'close';
}
}
// user-defined headers
if (typeof this.options.requestHeaders == 'object') {
var extras = this.options.requestHeaders;
if (typeof extras.push == 'function') {
for (var i = 0, length = extras.length; i < length; i += 2) {
headers[extras[i]] = extras[i+1];
}
} else {
for (var i in extras) {
headers[i] = pair[i];
}
}
}
for (var name in headers) {
this.transport.setRequestHeader(name, headers[name]);
}
},
/**
* Method: success
*
* Returns:
* {Boolean} -
*/
success: function() {
var status = this.getStatus();
return !status || (status >=200 && status < 300);
},
/**
* Method: getStatus
*
* Returns:
* {Integer} - Status
*/
getStatus: function() {
try {
return this.transport.status || 0;
} catch (e) {
return 0;
}
},
/**
* Method: respondToReadyState
*
* Parameters:
* readyState - {?}
*/
respondToReadyState: function(readyState) {
var state = OpenLayers.Ajax.Request.Events[readyState];
var response = new OpenLayers.Ajax.Response(this);
if (state == 'Complete') {
try {
this._complete = true;
(this.options['on' + response.status] ||
this.options['on' + (this.success() ? 'Success' : 'Failure')] ||
OpenLayers.Ajax.emptyFunction)(response);
} catch (e) {
this.dispatchException(e);
}
var contentType = response.getHeader('Content-type');
}
try {
(this.options['on' + state] ||
OpenLayers.Ajax.emptyFunction)(response);
OpenLayers.Ajax.Responders.dispatch('on' + state,
this,
response);
} catch (e) {
this.dispatchException(e);
}
if (state == 'Complete') {
// avoid memory leak in MSIE: clean up
this.transport.onreadystatechange = OpenLayers.Ajax.emptyFunction;
}
},
/**
* Method: getHeader
*
* Parameters:
* name - {String} Header name
*
* Returns:
* {?} - response header for the given name
*/
getHeader: function(name) {
try {
return this.transport.getResponseHeader(name);
} catch (e) {
return null;
}
},
/**
* Method: dispatchException
* If the optional onException function is set, execute it
* and then dispatch the call to any other listener registered
* for onException.
*
* If no optional onException function is set, we suspect that
* the user may have also not used
* OpenLayers.Ajax.Responders.register to register a listener
* for the onException call.  To make sure that something
* gets done with this exception, only dispatch the call if there
* are listeners.
*
* If you explicitly want to swallow exceptions, set
* request.options.onException to an empty function (function(){})
* or register an empty function with <OpenLayers.Ajax.Responders>
* for onException.
*
* Parameters:
* exception - {?}
*/
dispatchException: function(exception) {
var handler = this.options.onException;
if(handler) {
// call options.onException and alert any other listeners
handler(this, exception);
OpenLayers.Ajax.Responders.dispatch('onException', this, exception);
} else {
// check if there are any other listeners
var listener = false;
var responders = OpenLayers.Ajax.Responders.responders;
for (var i = 0; i < responders.length; i++) {
if(responders[i].onException) {
listener = true;
break;
}
}
if(listener) {
// call all listeners
OpenLayers.Ajax.Responders.dispatch('onException', this, exception);
} else {
// let the exception through
throw exception;
}
}
}
});
/**
* Property: Events
* {Array(String)}
*/
OpenLayers.Ajax.Request.Events =
['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
/**
* Class: OpenLayers.Ajax.Response
*/
OpenLayers.Ajax.Response = OpenLayers.Class({
/**
* Property: status
*
* {Integer}
*/
status: 0,
/**
* Property: statusText
*
* {String}
*/
statusText: '',
/**
* Constructor: OpenLayers.Ajax.Response
*
* Parameters:
* request - {Object}
*/
initialize: function(request) {
this.request = request;
var transport = this.transport = request.transport,
readyState = this.readyState = transport.readyState;
if ((readyState > 2 &&
!(!!(window.attachEvent && !window.opera))) ||
readyState == 4) {
this.status       = this.getStatus();
this.statusText   = this.getStatusText();
this.responseText = transport.responseText == null ?
'' : String(transport.responseText);
}
if(readyState == 4) {
var xml = transport.responseXML;
this.responseXML  = xml === undefined ? null : xml;
}
},
/**
* Method: getStatus
*/
getStatus: OpenLayers.Ajax.Request.prototype.getStatus,
/**
* Method: getStatustext
*
* Returns:
* {String} - statusText
*/
getStatusText: function() {
try {
return this.transport.statusText || '';
} catch (e) {
return '';
}
},
/**
* Method: getHeader
*/
getHeader: OpenLayers.Ajax.Request.prototype.getHeader,
/**
* Method: getResponseHeader
*
* Returns:
* {?} - response header for given name
*/
getResponseHeader: function(name) {
return this.transport.getResponseHeader(name);
}
});
/**
* Function: getElementsByTagNameNS
*
* Parameters:
* parentnode - {?}
* nsuri - {?}
* nsprefix - {?}
* tagname - {?}
*
* Returns:
* {?}
*/
OpenLayers.Ajax.getElementsByTagNameNS  = function(parentnode, nsuri,
nsprefix, tagname) {
var elem = null;
if (parentnode.getElementsByTagNameNS) {
elem = parentnode.getElementsByTagNameNS(nsuri, tagname);
} else {
elem = parentnode.getElementsByTagName(nsprefix + ':' + tagname);
}
return elem;
};
/**
* Function: serializeXMLToString
* Wrapper function around XMLSerializer, which doesn't exist/work in
*     IE/Safari. We need to come up with a way to serialize in those browser:
*     for now, these browsers will just fail. #535, #536
*
* Parameters:
* xmldom {XMLNode} xml dom to serialize
*
* Returns:
* {?}
*/
OpenLayers.Ajax.serializeXMLToString = function(xmldom) {
var serializer = new XMLSerializer();
var data = serializer.serializeToString(xmldom);
return data;
};
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Util.js
*/
/**
* Namespace: OpenLayers.Event
* Utility functions for event handling.
*/
OpenLayers.Event = {
/**
* Property: observers
* {Object} A hashtable cache of the event observers. Keyed by
* element._eventCacheID
*/
observers: false,
/**
* Constant: KEY_BACKSPACE
* {int}
*/
KEY_BACKSPACE: 8,
/**
* Constant: KEY_TAB
* {int}
*/
KEY_TAB: 9,
/**
* Constant: KEY_RETURN
* {int}
*/
KEY_RETURN: 13,
/**
* Constant: KEY_ESC
* {int}
*/
KEY_ESC: 27,
/**
* Constant: KEY_LEFT
* {int}
*/
KEY_LEFT: 37,
/**
* Constant: KEY_UP
* {int}
*/
KEY_UP: 38,
/**
* Constant: KEY_RIGHT
* {int}
*/
KEY_RIGHT: 39,
/**
* Constant: KEY_DOWN
* {int}
*/
KEY_DOWN: 40,
/**
* Constant: KEY_DELETE
* {int}
*/
KEY_DELETE: 46,
/**
* Method: element
* Cross browser event element detection.
*
* Parameters:
* event - {Event}
*
* Returns:
* {DOMElement} The element that caused the event
*/
element: function(event) {
return event.target || event.srcElement;
},
/**
* Method: isLeftClick
* Determine whether event was caused by a left click.
*
* Parameters:
* event - {Event}
*
* Returns:
* {Boolean}
*/
isLeftClick: function(event) {
return (((event.which) && (event.which == 1)) ||
((event.button) && (event.button == 1)));
},
/**
* Method: stop
* Stops an event from propagating.
*
* Parameters:
* event - {Event}
* allowDefault - {Boolean} If true, we stop the event chain but
*                               still allow the default browser
*                               behaviour (text selection, radio-button
*                               clicking, etc)
*                               Default false
*/
stop: function(event, allowDefault) {
if (!allowDefault) {
if (event.preventDefault) {
event.preventDefault();
} else {
event.returnValue = false;
}
}
if (event.stopPropagation) {
event.stopPropagation();
} else {
event.cancelBubble = true;
}
},
/**
* Method: findElement
*
* Parameters:
* event - {Event}
* tagName - {String}
*
* Returns:
* {DOMElement} The first node with the given tagName, starting from the
* node the event was triggered on and traversing the DOM upwards
*/
findElement: function(event, tagName) {
var element = OpenLayers.Event.element(event);
while (element.parentNode && (!element.tagName ||
(element.tagName.toUpperCase() != tagName.toUpperCase()))){
element = element.parentNode;
}
return element;
},
/**
* Method: observe
*
* Parameters:
* elementParam - {DOMElement || String}
* name - {String}
* observer - {function}
* useCapture - {Boolean}
*/
observe: function(elementParam, name, observer, useCapture) {
var element = OpenLayers.Util.getElement(elementParam);
useCapture = useCapture || false;
if (name == 'keypress' &&
(navigator.appVersion.match(/Konqueror|Safari|KHTML/)
|| element.attachEvent)) {
name = 'keydown';
}
//if observers cache has not yet been created, create it
if (!this.observers) {
this.observers = {};
}
//if not already assigned, make a new unique cache ID
if (!element._eventCacheID) {
var idPrefix = "eventCacheID_";
if (element.id) {
idPrefix = element.id + "_" + idPrefix;
}
element._eventCacheID = OpenLayers.Util.createUniqueID(idPrefix);
}
var cacheID = element._eventCacheID;
//if there is not yet a hash entry for this element, add one
if (!this.observers[cacheID]) {
this.observers[cacheID] = [];
}
//add a new observer to this element's list
this.observers[cacheID].push({
'element': element,
'name': name,
'observer': observer,
'useCapture': useCapture
});
//add the actual browser event listener
if (element.addEventListener) {
element.addEventListener(name, observer, useCapture);
} else if (element.attachEvent) {
element.attachEvent('on' + name, observer);
}
},
/**
* Method: stopObservingElement
* Given the id of an element to stop observing, cycle through the
*   element's cached observers, calling stopObserving on each one,
*   skipping those entries which can no longer be removed.
*
* parameters:
* elementParam - {DOMElement || String}
*/
stopObservingElement: function(elementParam) {
var element = OpenLayers.Util.getElement(elementParam);
var cacheID = element._eventCacheID;
this._removeElementObservers(OpenLayers.Event.observers[cacheID]);
},
/**
* Method: _removeElementObservers
*
* Parameters:
* elementObservers - {Array(Object)} Array of (element, name,
*                                         observer, usecapture) objects,
*                                         taken directly from hashtable
*/
_removeElementObservers: function(elementObservers) {
if (elementObservers) {
for(var i = elementObservers.length-1; i >= 0; i--) {
var entry = elementObservers[i];
var args = new Array(entry.element,
entry.name,
entry.observer,
entry.useCapture);
var removed = OpenLayers.Event.stopObserving.apply(this, args);
}
}
},
/**
* Method: stopObserving
*
* Parameters:
* elementParam - {DOMElement || String}
* name - {String}
* observer - {function}
* useCapture - {Boolean}
*
* Returns:
* {Boolean} Whether or not the event observer was removed
*/
stopObserving: function(elementParam, name, observer, useCapture) {
useCapture = useCapture || false;
var element = OpenLayers.Util.getElement(elementParam);
var cacheID = element._eventCacheID;
if (name == 'keypress') {
if ( navigator.appVersion.match(/Konqueror|Safari|KHTML/) ||
element.detachEvent) {
name = 'keydown';
}
}
// find element's entry in this.observers cache and remove it
var foundEntry = false;
var elementObservers = OpenLayers.Event.observers[cacheID];
if (elementObservers) {
// find the specific event type in the element's list
var i=0;
while(!foundEntry && i < elementObservers.length) {
var cacheEntry = elementObservers[i];
if ((cacheEntry.name == name) &&
(cacheEntry.observer == observer) &&
(cacheEntry.useCapture == useCapture)) {
elementObservers.splice(i, 1);
if (elementObservers.length == 0) {
delete OpenLayers.Event.observers[cacheID];
}
foundEntry = true;
break;
}
i++;
}
}
//actually remove the event listener from browser
if (foundEntry) {
if (element.removeEventListener) {
element.removeEventListener(name, observer, useCapture);
} else if (element && element.detachEvent) {
element.detachEvent('on' + name, observer);
}
}
return foundEntry;
},
/**
* Method: unloadCache
* Cycle through all the element entries in the events cache and call
*   stopObservingElement on each.
*/
unloadCache: function() {
// check for OpenLayers.Event before checking for observers, because
// OpenLayers.Event may be undefined in IE if no map instance was
// created
if (OpenLayers.Event && OpenLayers.Event.observers) {
for (var cacheID in OpenLayers.Event.observers) {
var elementObservers = OpenLayers.Event.observers[cacheID];
OpenLayers.Event._removeElementObservers.apply(this,
[elementObservers]);
}
OpenLayers.Event.observers = false;
}
},
CLASS_NAME: "OpenLayers.Event"
};
/* prevent memory leaks in IE */
OpenLayers.Event.observe(window, 'unload', OpenLayers.Event.unloadCache, false);
// FIXME: Remove this in 3.0. In 3.0, Event.stop will no longer be provided
// by OpenLayers.
if (window.Event) {
OpenLayers.Util.applyDefaults(window.Event, OpenLayers.Event);
} else {
var Event = OpenLayers.Event;
}
/**
* Class: OpenLayers.Events
*/
OpenLayers.Events = OpenLayers.Class({
/**
* Constant: BROWSER_EVENTS
* {Array(String)} supported events
*/
BROWSER_EVENTS: [
"mouseover", "mouseout",
"mousedown", "mouseup", "mousemove",
"click", "dblclick",
"resize", "focus", "blur"
],
/**
* Property: listeners
* {Object} Hashtable of Array(Function): events listener functions
*/
listeners: null,
/**
* Property: object
* {Object}  the code object issuing application events
*/
object: null,
/**
* Property: element
* {DOMElement}  the DOM element receiving browser events
*/
element: null,
/**
* Property: eventTypes
* {Array(String)}  list of support application events
*/
eventTypes: null,
/**
* Property: eventHandler
* {Function}  bound event handler attached to elements
*/
eventHandler: null,
/**
* APIProperty: fallThrough
* {Boolean}
*/
fallThrough: null,
/**
* Constructor: OpenLayers.Events
* Construct an OpenLayers.Events object.
*
* Parameters:
* object - {Object} The js object to which this Events object  is being
* added element - {DOMElement} A dom element to respond to browser events
* eventTypes - {Array(String)} Array of custom application events
* fallThrough - {Boolean} Allow events to fall through after these have
*                         been handled?
*/
initialize: function (object, element, eventTypes, fallThrough) {
this.object     = object;
this.element    = element;
this.eventTypes = eventTypes;
this.fallThrough = fallThrough;
this.listeners  = {};
// keep a bound copy of handleBrowserEvent() so that we can
// pass the same function to both Event.observe() and .stopObserving()
this.eventHandler = OpenLayers.Function.bindAsEventListener(
this.handleBrowserEvent, this
);
// if eventTypes is specified, create a listeners list for each
// custom application event.
if (this.eventTypes != null) {
for (var i = 0; i < this.eventTypes.length; i++) {
this.addEventType(this.eventTypes[i]);
}
}
// if a dom element is specified, add a listeners list
// for browser events on the element and register them
if (this.element != null) {
this.attachToElement(element);
}
},
/**
* APIMethod: destroy
*/
destroy: function () {
if (this.element) {
OpenLayers.Event.stopObservingElement(this.element);
}
this.element = null;
this.listeners = null;
this.object = null;
this.eventTypes = null;
this.fallThrough = null;
this.eventHandler = null;
},
/**
* APIMethod: addEventType
* Add a new event type to this events object.
* If the event type has already been added, do nothing.
*
* Parameters:
* eventName - {String}
*/
addEventType: function(eventName) {
if (!this.listeners[eventName]) {
this.listeners[eventName] = [];
}
},
/**
* Method: attachToElement
*
* Parameters:
* element - {HTMLDOMElement} a DOM element to attach browser events to
*/
attachToElement: function (element) {
for (var i = 0; i < this.BROWSER_EVENTS.length; i++) {
var eventType = this.BROWSER_EVENTS[i];
// every browser event has a corresponding application event
// (whether it's listened for or not).
this.addEventType(eventType);
// use Prototype to register the event cross-browser
OpenLayers.Event.observe(element, eventType, this.eventHandler);
}
// disable dragstart in IE so that mousedown/move/up works normally
OpenLayers.Event.observe(element, "dragstart", OpenLayers.Event.stop);
},
/**
* Method: on
* Convenience method for registering listeners with a common scope.
*
* Example use:
* (code)
* events.on({
*     "loadstart": loadStartListener,
*     "loadend": loadEndListener,
*     scope: object
* });
* (end)
*/
on: function(object) {
for(var type in object) {
if(type != "scope") {
this.register(type, object.scope, object[type]);
}
}
},
/**
* APIMethod: register
* Register an event on the events object.
*
* When the event is triggered, the 'func' function will be called, in the
* context of 'obj'. Imagine we were to register an event, specifying an
* OpenLayers.Bounds Object as 'obj'. When the event is triggered, the
* context in the callback function will be our Bounds object. This means
* that within our callback function, we can access the properties and
* methods of the Bounds object through the "this" variable. So our
* callback could execute something like:
* :    leftStr = "Left: " + this.left;
*
*                   or
*
* :    centerStr = "Center: " + this.getCenterLonLat();
*
* Parameters:
* type - {String} Name of the event to register
* obj - {Object} The object to bind the context to for the callback#.
*                     If no object is specified, default is the Events's
*                     'object' property.
* func - {Function} The callback function. If no callback is
*                        specified, this function does nothing.
*
*
*/
register: function (type, obj, func) {
if (func != null &&
((this.eventTypes && OpenLayers.Util.indexOf(this.eventTypes, type) != -1) ||
OpenLayers.Util.indexOf(this.BROWSER_EVENTS, type) != -1)) {
if (obj == null)  {
obj = this.object;
}
var listeners = this.listeners[type];
if (listeners != null) {
listeners.push( {obj: obj, func: func} );
}
}
},
/**
* APIMethod: registerPriority
* Same as register() but adds the new listener to the *front* of the
*     events queue instead of to the end.
*
*     TODO: get rid of this in 3.0 - Decide whether listeners should be
*     called in the order they were registered or in reverse order.
*
*
* Parameters:
* type - {String} Name of the event to register
* obj - {Object} The object to bind the context to for the callback#.
*                If no object is specified, default is the Events's
*                'object' property.
* func - {Function} The callback function. If no callback is
*                   specified, this function does nothing.
*/
registerPriority: function (type, obj, func) {
if (func != null) {
if (obj == null)  {
obj = this.object;
}
var listeners = this.listeners[type];
if (listeners != null) {
listeners.unshift( {obj: obj, func: func} );
}
}
},
/**
* Method: un
* Convenience method for unregistering listeners with a common scope.
*
* Example use:
* (code)
* events.un({
*     "loadstart": loadStartListener,
*     "loadend": loadEndListener,
*     scope: object
* });
* (end)
*/
un: function(object) {
for(var type in object) {
if(type != "scope") {
this.unregister(type, object.scope, object[type]);
}
}
},
/**
* APIMethod: unregister
*
* Parameters:
* type - {String}
* obj - {Object} If none specified, defaults to this.object
* func - {Function}
*/
unregister: function (type, obj, func) {
if (obj == null)  {
obj = this.object;
}
var listeners = this.listeners[type];
if (listeners != null) {
for (var i = 0; i < listeners.length; i++) {
if (listeners[i].obj == obj && listeners[i].func == func) {
listeners.splice(i, 1);
break;
}
}
}
},
/**
* Method: remove
* Remove all listeners for a given event type. If type is not registered,
*     does nothing.
*
* Parameters:
* type - {String}
*/
remove: function(type) {
if (this.listeners[type] != null) {
this.listeners[type] = [];
}
},
/**
* APIMethod: triggerEvent
* Trigger a specified registered event.
*
* Parameters:
* type - {String}
* evt - {Event}
*
* Returns:
* {Boolean} The last listener return.  If a listener returns false, the
*     chain of listeners will stop getting called.
*/
triggerEvent: function (type, evt) {
// prep evt object with object & div references
if (evt == null) {
evt = {};
}
evt.object = this.object;
evt.element = this.element;
if(!evt.type) {
evt.type = type;
}
// execute all callbacks registered for specified type
// get a clone of the listeners array to
// allow for splicing during callbacks
var listeners = (this.listeners[type]) ?
this.listeners[type].slice() : null;
if ((listeners != null) && (listeners.length > 0)) {
var continueChain;
for (var i = 0; i < listeners.length; i++) {
var callback = listeners[i];
// bind the context to callback.obj
continueChain = callback.func.apply(callback.obj, [evt]);
if ((continueChain != undefined) && (continueChain == false)) {
// if callback returns false, execute no more callbacks.
break;
}
}
// don't fall through to other DOM elements
if (!this.fallThrough) {
OpenLayers.Event.stop(evt, true);
}
}
return continueChain;
},
/**
* Method: handleBrowserEvent
* Basically just a wrapper to the triggerEvent() function, but takes
*     care to set a property 'xy' on the event with the current mouse
*     position.
*
* Parameters:
* evt - {Event}
*/
handleBrowserEvent: function (evt) {
evt.xy = this.getMousePosition(evt);
this.triggerEvent(evt.type, evt);
},
/**
* Method: getMousePosition
*
* Parameters:
* evt - {Event}
*
* Returns:
* {<OpenLayers.Pixel>} The current xy coordinate of the mouse, adjusted
*                      for offsets
*/
getMousePosition: function (evt) {
if (!this.element.offsets) {
this.element.offsets = OpenLayers.Util.pagePosition(this.element);
this.element.offsets[0] += (document.documentElement.scrollLeft
|| document.body.scrollLeft);
this.element.offsets[1] += (document.documentElement.scrollTop
|| document.body.scrollTop);
}
return new OpenLayers.Pixel(
(evt.clientX + (document.documentElement.scrollLeft
|| document.body.scrollLeft)) - this.element.offsets[0]
- (document.documentElement.clientLeft || 0),
(evt.clientY + (document.documentElement.scrollTop
|| document.body.scrollTop)) - this.element.offsets[1]
- (document.documentElement.clientTop || 0)
);
},
CLASS_NAME: "OpenLayers.Events"
});
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under a modified BSD license.
* See http://svn.openlayers.org/trunk/openlayers/repository-license.txt
* for the full text of the license. */
/**
* @requires OpenLayers/Util.js
*/
/**
* Class: OpenLayers.Projection
* Class for coordinate transforms between coordinate systems.
*     Depends on the proj4js library. If proj4js is not available,
*     then this is just an empty stub.
*/
OpenLayers.Projection = OpenLayers.Class({
/**
* Property: proj
* {Object} Proj4js.Proj instance.
*/
proj: null,
/**
* Property: projCode
* {String}
*/
projCode: null,
/**
* Constructor: OpenLayers.Projection
* This class offers several methods for interacting with a wrapped
*     pro4js projection object.
*
* Parameters:
* options - {Object} An optional object with properties to set on the
*     format
*
* Returns:
* {<OpenLayers.Projection>} A projection object.
*/
initialize: function(projCode, options) {
OpenLayers.Util.extend(this, options);
this.projCode = projCode;
if (window.Proj4js) {
this.proj = new Proj4js.Proj(projCode);
}
},
/**
* APIMethod: getCode
* Get the string SRS code.
*
* Returns:
* {String} The SRS code.
*/
getCode: function() {
return this.proj ? this.proj.srsCode : this.projCode;
},
/**
* APIMethod: getUnits
* Get the units string for the projection -- returns null if
*     proj4js is not available.
*
* Returns:
* {String} The units abbreviation.
*/
getUnits: function() {
return this.proj ? this.proj.units : null;
},
/**
* Method: toString
* Convert projection to string (getCode wrapper).
*
* Returns:
* {String} The projection code.
*/
toString: function() {
return this.getCode();
},
/**
* Method: equals
* Test equality of two projection instances.  Determines equality based
*     soley on the projection code.
*
* Returns:
* {Boolean} The two projections are equivalent.
*/
equals: function(projection) {
if (projection && projection.getCode) {
return this.getCode() == projection.getCode();
} else {
return false;
}
},
/* Method: destroy
* Destroy projection object.
*/
destroy: function() {
delete this.proj;
delete this.projCode;
},
CLASS_NAME: "OpenLayers.Projection"
});
/**
* Property: transforms
* Transforms is an object, with from properties, each of which may
* have a to property. This allows you to define projections without
* requiring support for proj4js to be included.
*
* This object has keys which correspond to a 'source' projection object.  The
* keys should be strings, corresponding to the projection.getCode() value.
* Each source projection object should have a set of destination projection
* keys included in the object.
*
* Each value in the destination object should be a transformation function,
* where the function is expected to be passed an object with a .x and a .y
* property.  The function should return the object, with the .x and .y
* transformed according to the transformation function.
*
* Note - Properties on this object should not be set directly.  To add a
*     transform method to this object, use the <addTransform> method.  For an
*     example of usage, see the OpenLayers.Layer.SphericalMercator file.
*/
OpenLayers.Projection.transforms = {};
/**
* APIMethod: addTransform
* Set a custom transform method between two projections.  Use this method in
*     cases where the proj4js lib is not available or where custom projections
*     need to be handled.
*
* Parameters:
* from - {String} The code for the source projection
* to - {String} the code for the destination projection
* method - {Function} A function that takes a point as an argument and
*     transforms that point from the source to the destination projection
*     in place.  The original point should be modified.
*/
OpenLayers.Projection.addTransform = function(from, to, method) {
if(!OpenLayers.Projection.transforms[from]) {
OpenLayers.Projection.transforms[from] = {};
}
OpenLayers.Projection.transforms[from][to] = method;
};
/**
* APIMethod: transform
* Transform a point coordinate from one projection to another.  Note that
*     the input point is transformed in place.
*
* Parameters:
* point - {{OpenLayers.Geometry.Point> | Object} An object with x and y
*     properties representing coordinates in those dimensions.
* sourceProj - {OpenLayers.Projection} Source map coordinate system
* destProj - {OpenLayers.Projection} Destination map coordinate system
*
* Returns:
* point - {object} A transformed coordinate.  The original point is modified.
*/
OpenLayers.Projection.transform = function(point, source, dest) {
if (source.proj && dest.proj) {
point = Proj4js.transform(source.proj, dest.proj, point);
} else if (source && dest &&
OpenLayers.Projection.transforms[source.getCode()] &&
OpenLayers.Projection.transforms[source.getCode()][dest.getCode()]) {
OpenLayers.Projection.transforms[source.getCode()][dest.getCode()](point);
}
return point;
};
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Util.js
* @requires OpenLayers/Events.js
* @requires OpenLayers/Tween.js
*/
/**
* Class: OpenLayers.Map
* Instances of OpenLayers.Map are interactive maps embedded in a web page.
* Create a new map with the <OpenLayers.Map> constructor.
*
* On their own maps do not provide much functionality.  To extend a map
* it's necessary to add controls (<OpenLayers.Control>) and
* layers (<OpenLayers.Layer>) to the map.
*/
OpenLayers.Map = OpenLayers.Class({
/**
* Constant: Z_INDEX_BASE
* {Object} Base z-indexes for different classes of thing
*/
Z_INDEX_BASE: { BaseLayer: 100, Overlay: 325, Popup: 750, Control: 1000 },
/**
* Constant: EVENT_TYPES
* {Array(String)} Supported application event types.  Register a listener
*     for a particular event with the following syntax:
* (code)
* map.events.register(type, obj, listener);
* (end)
*
* Listeners will be called with a reference to an event object.  The
*     properties of this event depends on exactly what happened.
*
* All event objects have at least the following properties:
*  - *object* {Object} A reference to map.events.object.
*  - *element* {DOMElement} A reference to map.events.element.
*
* Browser events have the following additional properties:
*  - *xy* {<OpenLayers.Pixel>} The pixel location of the event (relative
*      to the the map viewport).
*  - other properties that come with browser events
*
* Supported map event types:
*  - *preaddlayer* triggered before a layer has been added.  The event
*      object will include a *layer* property that references the layer
*      to be added.
*  - *addlayer* triggered after a layer has been added.  The event object
*      will include a *layer* property that references the added layer.
*  - *removelayer* triggered after a layer has been removed.  The event
*      object will include a *layer* property that references the removed
*      layer.
*  - *changelayer* triggered after a layer name change, order change, or
*      visibility change (due to resolution thresholds).  Listeners will
*      receive an event object with *layer* and *property* properties.  The
*      *layer* property will be a reference to the changed layer.  The
*      *property* property will be a key to the changed property (name,
*      visibility, or order).
*  - *movestart* triggered after the start of a drag, pan, or zoom
*  - *move* triggered after each drag, pan, or zoom
*  - *moveend* triggered after a drag, pan, or zoom completes
*  - *popupopen* triggered after a popup opens
*  - *popupclose* triggered after a popup opens
*  - *addmarker* triggered after a marker has been added
*  - *removemarker* triggered after a marker has been removed
*  - *clearmarkers* triggered after markers have been cleared
*  - *mouseover* triggered after mouseover the map
*  - *mouseout* triggered after mouseout the map
*  - *mousemove* triggered after mousemove the map
*  - *dragstart* triggered after the start of a drag
*  - *drag* triggered after a drag
*  - *dragend* triggered after the end of a drag
*  - *changebaselayer* triggered after the base layer changes
*/
EVENT_TYPES: [
"preaddlayer", "addlayer", "removelayer", "changelayer", "movestart",
"move", "moveend", "zoomend", "popupopen", "popupclose",
"addmarker", "removemarker", "clearmarkers", "mouseover",
"mouseout", "mousemove", "dragstart", "drag", "dragend",
"changebaselayer"],
/**
* Property: id
* {String} Unique identifier for the map
*/
id: null,
/**
* Property: fractionalZoom
* {Boolean} For a base layer that supports it, allow the map resolution
*     to be set to a value between one of the values in the resolutions
*     array.  Default is false.
*
* When fractionalZoom is set to true, it is possible to zoom to
*     an arbitrary extent.  This requires a base layer from a source
*     that supports requests for arbitrary extents (i.e. not cached
*     tiles on a regular lattice).  This means that fractionalZoom
*     will not work with commercial layers (Google, Yahoo, VE), layers
*     using TileCache, or any other pre-cached data sources.
*
* If you are using fractionalZoom, then you should also use
*     <getResolutionForZoom> instead of layer.resolutions[zoom] as the
*     former works for non-integer zoom levels.
*/
fractionalZoom: false,
/**
* APIProperty: events
* {<OpenLayers.Events>} An events object that handles all
*                       events on the map
*/
events: null,
/**
* APIProperty: div
* {DOMElement} The element that contains the map
*/
div: null,
/**
* Property: dragging
* {Boolean} The map is currently being dragged.
*/
dragging: false,
/**
* Property: size
* {<OpenLayers.Size>} Size of the main div (this.div)
*/
size: null,
/**
* Property: viewPortDiv
* {HTMLDivElement} The element that represents the map viewport
*/
viewPortDiv: null,
/**
* Property: layerContainerOrigin
* {<OpenLayers.LonLat>} The lonlat at which the later container was
*                       re-initialized (on-zoom)
*/
layerContainerOrigin: null,
/**
* Property: layerContainerDiv
* {HTMLDivElement} The element that contains the layers.
*/
layerContainerDiv: null,
/**
* APIProperty: layers
* {Array(<OpenLayers.Layer>)} Ordered list of layers in the map
*/
layers: null,
/**
* Property: controls
* {Array(<OpenLayers.Control>)} List of controls associated with the map
*/
controls: null,
/**
* Property: popups
* {Array(<OpenLayers.Popup>)} List of popups associated with the map
*/
popups: null,
/**
* APIProperty: baseLayer
* {<OpenLayers.Layer>} The currently selected base layer.  This determines
* min/max zoom level, projection, etc.
*/
baseLayer: null,
/**
* Property: center
* {<OpenLayers.LonLat>} The current center of the map
*/
center: null,
/**
* Property: resolution
* {Float} The resolution of the map.
*/
resolution: null,
/**
* Property: zoom
* {Integer} The current zoom level of the map
*/
zoom: 0,
/**
* Property: viewRequestID
* {String} Used to store a unique identifier that changes when the map
*          view changes. viewRequestID should be used when adding data
*          asynchronously to the map: viewRequestID is incremented when
*          you initiate your request (right now during changing of
*          baselayers and changing of zooms). It is stored here in the
*          map and also in the data that will be coming back
*          asynchronously. Before displaying this data on request
*          completion, we check that the viewRequestID of the data is
*          still the same as that of the map. Fix for #480
*/
viewRequestID: 0,
// Options
/**
* APIProperty: tileSize
* {<OpenLayers.Size>} Set in the map options to override the default tile
*                     size for this map.
*/
tileSize: null,
/**
* APIProperty: projection
* {String} Set in the map options to override the default projection
*          string this map - also set maxExtent, maxResolution, and
*          units if appropriate.
*/
projection: "EPSG:4326",
/**
* APIProperty: units
* {String} The map units.  Defaults to 'degrees'.  Possible values are
*          'degrees' (or 'dd'), 'm', 'ft', 'km', 'mi', 'inches'.
*/
units: 'degrees',
/**
* APIProperty: resolutions
* {Array(Float)} A list of map resolutions (map units per pixel) in
*     descending order.  If this is not set in the layer constructor, it
*     will be set based on other resolution related properties
*     (maxExtent, maxResolution, maxScale, etc.).
*/
resolutions: null,
/**
* APIProperty: maxResolution
* {Float} Default max is 360 deg / 256 px, which corresponds to
*          zoom level 0 on gmaps.  Specify a different value in the map
*          options if you are not using a geographic projection and
*          displaying the whole world.
*/
maxResolution: 1.40625,
/**
* APIProperty: minResolution
* {Float}
*/
minResolution: null,
/**
* APIProperty: maxScale
* {Float}
*/
maxScale: null,
/**
* APIProperty: minScale
* {Float}
*/
minScale: null,
/**
* APIProperty: maxExtent
* {<OpenLayers.Bounds>} The maximum extent for the map.  Defaults to the
*                       whole world in decimal degrees
*                       (-180, -90, 180, 90).  Specify a different
*                        extent in the map options if you are not using a
*                        geographic projection and displaying the whole
*                        world.
*/
maxExtent: null,
/**
* APIProperty: minExtent
* {<OpenLayers.Bounds>}
*/
minExtent: null,
/**
* APIProperty: restrictedExtent
* {<OpenLayers.Bounds>} Limit map navigation to this extent where possible.
*     If a non-null restrictedExtent is set, panning will be restricted
*     to the given bounds.  In addition, zooming to a resolution that
*     displays more than the restricted extent will center the map
*     on the restricted extent.  If you wish to limit the zoom level
*     or resolution, use maxResolution.
*/
restrictedExtent: null,
/**
* APIProperty: numZoomLevels
* {Integer} Number of zoom levels for the map.  Defaults to 16.  Set a
*           different value in the map options if needed.
*/
numZoomLevels: 16,
/**
* APIProperty: theme
* {String} Relative path to a CSS file from which to load theme styles.
*          Specify null in the map options (e.g. {theme: null}) if you
*          want to get cascading style declarations - by putting links to
*          stylesheets or style declarations directly in your page.
*/
theme: null,
/**
* APIProperty: displayProjection
* {<OpenLayers.Projection>} Requires proj4js support.Projection used by
*     several controls to display data to user. If this property is set,
*     it will be set on any control which has a null displayProjection
*     property at the time the control is added to the map.
*/
displayProjection: null,
/**
* APIProperty: fallThrough
* {Boolean} Should OpenLayers allow events on the map to fall through to
*           other elements on the page, or should it swallow them? (#457)
*           Default is to fall through.
*/
fallThrough: true,
/**
* Property: panTween
* {OpenLayers.Tween} Animated panning tween object, see panTo()
*/
panTween: null,
/**
* APIProperty: eventListeners
* {Object} If set as an option at construction, the eventListeners
*     object will be registered with <OpenLayers.Events.on>.  Object
*     structure must be a listeners object as shown in the example for
*     the events.on method.
*/
eventListeners: null,
/**
* Property: panMethod
* {Function} The Easing function to be used for tweening.  Default is
* OpenLayers.Easing.Expo.easeOut. Setting this to 'null' turns off
* animated panning.
*/
panMethod: OpenLayers.Easing.Expo.easeOut,
/**
* Property: paddingForPopups
* {<OpenLayers.Bounds>} Outside margin of the popup. Used to prevent
*     the popup from getting too close to the map border.
*/
paddingForPopups : null,
/**
* Constructor: OpenLayers.Map
* Constructor for a new OpenLayers.Map instance.
*
* Parameters:
* div - {String} Id of an element in your page that will contain the map.
* options - {Object} Optional object with properties to tag onto the map.
*
* Examples:
* (code)
* // create a map with default options in an element with the id "map1"
* var map = new OpenLayers.Map("map1");
*
* // create a map with non-default options in an element with id "map2"
* var options = {
*     maxExtent: new OpenLayers.Bounds(-200000, -200000, 200000, 200000),
*     maxResolution: 156543,
*     units: 'm',
*     projection: "EPSG:41001"
* };
* var map = new OpenLayers.Map("map2", options);
* (end)
*/
initialize: function (div, options) {
// Simple-type defaults are set in class definition.
//  Now set complex-type defaults
this.tileSize = new OpenLayers.Size(OpenLayers.Map.TILE_WIDTH,
OpenLayers.Map.TILE_HEIGHT);
this.maxExtent = new OpenLayers.Bounds(-180, -90, 180, 90);
this.paddingForPopups = new OpenLayers.Bounds(15, 15, 15, 15);
this.theme = OpenLayers._getScriptLocation() +
'theme/praterservice/style.css';
// now override default options
OpenLayers.Util.extend(this, options);
this.id = OpenLayers.Util.createUniqueID("OpenLayers.Map_");
this.div = OpenLayers.Util.getElement(div);
// the viewPortDiv is the outermost div we modify
var id = this.div.id + "_OpenLayers_ViewPort";
this.viewPortDiv = OpenLayers.Util.createDiv(id, null, null, null,
"relative", null,
"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
id = this.div.id + "_OpenLayers_Container";
this.layerContainerDiv = OpenLayers.Util.createDiv(id);
this.layerContainerDiv.style.zIndex=this.Z_INDEX_BASE['Popup']-1;
this.viewPortDiv.appendChild(this.layerContainerDiv);
this.events = new OpenLayers.Events(this,
this.div,
this.EVENT_TYPES,
this.fallThrough);
this.updateSize();
if(this.eventListeners instanceof Object) {
this.events.on(this.eventListeners);
}
// update the map size and location before the map moves
this.events.register("movestart", this, this.updateSize);
// Because Mozilla does not support the "resize" event for elements
// other than "window", we need to put a hack here.
if (OpenLayers.String.contains(navigator.appName, "Microsoft")) {
// If IE, register the resize on the div
this.events.register("resize", this, this.updateSize);
} else {
// Else updateSize on catching the window's resize
//  Note that this is ok, as updateSize() does nothing if the
//  map's size has not actually changed.
this.updateSizeDestroy = OpenLayers.Function.bind(this.updateSize,
this);
OpenLayers.Event.observe(window, 'resize',
this.updateSizeDestroy);
}
// only append link stylesheet if the theme property is set
if(this.theme) {
// check existing links for equivalent url
var addNode = true;
var nodes = document.getElementsByTagName('link');
for(var i=0; i<nodes.length; ++i) {
if(OpenLayers.Util.isEquivalentUrl(nodes.item(i).href,
this.theme)) {
addNode = false;
break;
}
}
// only add a new node if one with an equivalent url hasn't already
// been added
if(addNode) {
var cssNode = document.createElement('link');
cssNode.setAttribute('rel', 'stylesheet');
cssNode.setAttribute('type', 'text/css');
cssNode.setAttribute('href', this.theme);
document.getElementsByTagName('head')[0].appendChild(cssNode);
}
}
this.layers = [];
if (this.controls == null) {
if (OpenLayers.Control != null) { // running full or lite?
this.controls = [ new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoom(),
new OpenLayers.Control.ArgParser(),
new OpenLayers.Control.Attribution()
];
} else {
this.controls = [];
}
}
for(var i=0; i < this.controls.length; i++) {
this.addControlToMap(this.controls[i]);
}
this.popups = [];
this.unloadDestroy = OpenLayers.Function.bind(this.destroy, this);
// always call map.destroy()
OpenLayers.Event.observe(window, 'unload', this.unloadDestroy);
},
/**
* Method: unloadDestroy
* Function that is called to destroy the map on page unload. stored here
*     so that if map is manually destroyed, we can unregister this.
*/
unloadDestroy: null,
/**
* Method: updateSizeDestroy
* When the map is destroyed, we need to stop listening to updateSize
*    events: this method stores the function we need to unregister in
*    non-IE browsers.
*/
updateSizeDestroy: null,
/**
* APIMethod: destroy
* Destroy this map
*/
destroy:function() {
// if unloadDestroy is null, we've already been destroyed
if (!this.unloadDestroy) {
return false;
}
// map has been destroyed. dont do it again!
OpenLayers.Event.stopObserving(window, 'unload', this.unloadDestroy);
this.unloadDestroy = null;
if (this.updateSizeDestroy) {
OpenLayers.Event.stopObserving(window, 'resize',
this.updateSizeDestroy);
} else {
this.events.unregister("resize", this, this.updateSize);
}
this.paddingForPopups = null;
if (this.controls != null) {
for (var i = this.controls.length - 1; i>=0; --i) {
this.controls[i].destroy();
}
this.controls = null;
}
if (this.layers != null) {
for (var i = this.layers.length - 1; i>=0; --i) {
//pass 'false' to destroy so that map wont try to set a new
// baselayer after each baselayer is removed
this.layers[i].destroy(false);
}
this.layers = null;
}
if (this.viewPortDiv) {
this.div.removeChild(this.viewPortDiv);
}
this.viewPortDiv = null;
if(this.eventListeners) {
this.events.un(this.eventListeners);
this.eventListeners = null;
}
this.events.destroy();
this.events = null;
},
/**
* APIMethod: setOptions
* Change the map options
*
* Parameters:
* options - {Object} Hashtable of options to tag to the map
*/
setOptions: function(options) {
OpenLayers.Util.extend(this, options);
},
/**
* APIMethod: getTileSize
* Get the tile size for the map
*
* Returns:
* {<OpenLayers.Size>}
*/
getTileSize: function() {
return this.tileSize;
},
/**
* APIMethod: getBy
* Get a list of objects given a property and a match item.
*
* Parameters:
* array - {String} A property on the map whose value is an array.
* property - {String} A property on each item of the given array.
* match - {String | Object} A string to match.  Can also be a regular
*     expression literal or object.  In addition, it can be any object
*     with a method named test.  For reqular expressions or other, if
*     match.test(map[array][i][property]) evaluates to true, the item will
*     be included in the array returned.  If no items are found, an empty
*     array is returned.
*
* Returns:
* {Array} An array of items where the given property matches the given
*     criteria.
*/
getBy: function(array, property, match) {
var test = (typeof match.test == "function");
var found = OpenLayers.Array.filter(this[array], function(item) {
return item[property] == match || (test && match.test(item[property]));
});
return found;
},
/**
* APIMethod: getLayersBy
* Get a list of layers with properties matching the given criteria.
*
* Parameter:
* property - {String} A layer property to be matched.
* match - {String | Object} A string to match.  Can also be a regular
*     expression literal or object.  In addition, it can be any object
*     with a method named test.  For reqular expressions or other, if
*     match.test(layer[property]) evaluates to true, the layer will be
*     included in the array returned.  If no layers are found, an empty
*     array is returned.
*
* Returns:
* {Array(<OpenLayers.Layer>)} A list of layers matching the given criteria.
*     An empty array is returned if no matches are found.
*/
getLayersBy: function(property, match) {
return this.getBy("layers", property, match);
},
/**
* APIMethod: getLayersByName
* Get a list of layers with names matching the given name.
*
* Parameter:
* match - {String | Object} A layer name.  The name can also be a regular
*     expression literal or object.  In addition, it can be any object
*     with a method named test.  For reqular expressions or other, if
*     name.test(layer.name) evaluates to true, the layer will be included
*     in the list of layers returned.  If no layers are found, an empty
*     array is returned.
*
* Returns:
* {Array(<OpenLayers.Layer>)} A list of layers matching the given name.
*     An empty array is returned if no matches are found.
*/
getLayersByName: function(match) {
return this.getLayersBy("name", match);
},
/**
* APIMethod: getLayersByClass
* Get a list of layers of a given class (CLASS_NAME).
*
* Parameter:
* match - {String | Object} A layer class name.  The match can also be a
*     regular expression literal or object.  In addition, it can be any
*     object with a method named test.  For reqular expressions or other,
*     if type.test(layer.CLASS_NAME) evaluates to true, the layer will
*     be included in the list of layers returned.  If no layers are
*     found, an empty array is returned.
*
* Returns:
* {Array(<OpenLayers.Layer>)} A list of layers matching the given class.
*     An empty array is returned if no matches are found.
*/
getLayersByClass: function(match) {
return this.getLayersBy("CLASS_NAME", match);
},
/**
* APIMethod: getControlsBy
* Get a list of controls with properties matching the given criteria.
*
* Parameter:
* property - {String} A control property to be matched.
* match - {String | Object} A string to match.  Can also be a regular
*     expression literal or object.  In addition, it can be any object
*     with a method named test.  For reqular expressions or other, if
*     match.test(layer[property]) evaluates to true, the layer will be
*     included in the array returned.  If no layers are found, an empty
*     array is returned.
*
* Returns:
* {Array(<OpenLayers.Control>)} A list of controls matching the given
*     criteria.  An empty array is returned if no matches are found.
*/
getControlsBy: function(property, match) {
return this.getBy("controls", property, match);
},
/**
* APIMethod: getControlsByClass
* Get a list of controls of a given class (CLASS_NAME).
*
* Parameter:
* match - {String | Object} A control class name.  The match can also be a
*     regular expression literal or object.  In addition, it can be any
*     object with a method named test.  For reqular expressions or other,
*     if type.test(control.CLASS_NAME) evaluates to true, the control will
*     be included in the list of controls returned.  If no controls are
*     found, an empty array is returned.
*
* Returns:
* {Array(<OpenLayers.Control>)} A list of controls matching the given class.
*     An empty array is returned if no matches are found.
*/
getControlsByClass: function(match) {
return this.getControlsBy("CLASS_NAME", match);
},
/********************************************************/
/*                                                      */
/*                  Layer Functions                     */
/*                                                      */
/*     The following functions deal with adding and     */
/*        removing Layers to and from the Map           */
/*                                                      */
/********************************************************/
/**
* APIMethod: getLayer
* Get a layer based on its id
*
* Parameter:
* id - {String} A layer id
*
* Returns:
* {<OpenLayers.Layer>} The Layer with the corresponding id from the map's
*                      layer collection, or null if not found.
*/
getLayer: function(id) {
var foundLayer = null;
for (var i = 0; i < this.layers.length; i++) {
var layer = this.layers[i];
if (layer.id == id) {
foundLayer = layer;
break;
}
}
return foundLayer;
},
/**
* Method: setLayerZIndex
*
* Parameters:
* layer - {<OpenLayers.Layer>}
* zIdx - {int}
*/
setLayerZIndex: function (layer, zIdx) {
layer.setZIndex(
this.Z_INDEX_BASE[layer.isBaseLayer ? 'BaseLayer' : 'Overlay']
+ zIdx * 5 );
},
/**
* Method: resetLayersZIndex
* Reset each layer's z-index based on layer's array index
*/
resetLayersZIndex: function() {
for (var i = 0; i < this.layers.length; i++) {
var layer = this.layers[i];
this.setLayerZIndex(layer, i);
}
},
/**
* APIMethod: addLayer
*
* Parameters:
* layer - {<OpenLayers.Layer>}
*/
addLayer: function (layer) {
for(var i=0; i < this.layers.length; i++) {
if (this.layers[i] == layer) {
var msg = OpenLayers.i18n('layerAlreadyAdded',
{'layerName':layer.name});
OpenLayers.Console.warn(msg);
return false;
}
}
this.events.triggerEvent("preaddlayer", {layer: layer});
layer.div.className = "olLayerDiv";
layer.div.style.overflow = "";
this.setLayerZIndex(layer, this.layers.length);
if (layer.isFixed) {
this.viewPortDiv.appendChild(layer.div);
} else {
this.layerContainerDiv.appendChild(layer.div);
}
this.layers.push(layer);
layer.setMap(this);
if (layer.isBaseLayer)  {
if (this.baseLayer == null) {
// set the first baselaye we add as the baselayer
this.setBaseLayer(layer);
} else {
layer.setVisibility(false);
}
} else {
layer.redraw();
}
this.events.triggerEvent("addlayer", {layer: layer});
},
/**
* APIMethod: addLayers
*
* Parameters:
* layers - {Array(<OpenLayers.Layer>)}
*/
addLayers: function (layers) {
for (var i = 0; i <  layers.length; i++) {
this.addLayer(layers[i]);
}
},
/**
* APIMethod: removeLayer
* Removes a layer from the map by removing its visual element (the
*   layer.div property), then removing it from the map's internal list
*   of layers, setting the layer's map property to null.
*
*   a "removelayer" event is triggered.
*
*   very worthy of mention is that simply removing a layer from a map
*   will not cause the removal of any popups which may have been created
*   by the layer. this is due to the fact that it was decided at some
*   point that popups would not belong to layers. thus there is no way
*   for us to know here to which layer the popup belongs.
*
*     A simple solution to this is simply to call destroy() on the layer.
*     the default OpenLayers.Layer class's destroy() function
*     automatically takes care to remove itself from whatever map it has
*     been attached to.
*
*     The correct solution is for the layer itself to register an
*     event-handler on "removelayer" and when it is called, if it
*     recognizes itself as the layer being removed, then it cycles through
*     its own personal list of popups, removing them from the map.
*
* Parameters:
* layer - {<OpenLayers.Layer>}
* setNewBaseLayer - {Boolean} Default is true
*/
removeLayer: function(layer, setNewBaseLayer) {
if (setNewBaseLayer == null) {
setNewBaseLayer = true;
}
if (layer.isFixed) {
this.viewPortDiv.removeChild(layer.div);
} else {
this.layerContainerDiv.removeChild(layer.div);
}
OpenLayers.Util.removeItem(this.layers, layer);
layer.removeMap(this);
layer.map = null;
// if we removed the base layer, need to set a new one
if(this.baseLayer == layer) {
this.baseLayer = null;
if(setNewBaseLayer) {
for(var i=0; i < this.layers.length; i++) {
var iLayer = this.layers[i];
if (iLayer.isBaseLayer) {
this.setBaseLayer(iLayer);
break;
}
}
}
}
this.resetLayersZIndex();
this.events.triggerEvent("removelayer", {layer: layer});
},
/**
* APIMethod: getNumLayers
*
* Returns:
* {Int} The number of layers attached to the map.
*/
getNumLayers: function () {
return this.layers.length;
},
/**
* APIMethod: getLayerIndex
*
* Parameters:
* layer - {<OpenLayers.Layer>}
*
* Returns:
* {Integer} The current (zero-based) index of the given layer in the map's
*           layer stack. Returns -1 if the layer isn't on the map.
*/
getLayerIndex: function (layer) {
return OpenLayers.Util.indexOf(this.layers, layer);
},
/**
* APIMethod: setLayerIndex
* Move the given layer to the specified (zero-based) index in the layer
*     list, changing its z-index in the map display. Use
*     map.getLayerIndex() to find out the current index of a layer. Note
*     that this cannot (or at least should not) be effectively used to
*     raise base layers above overlays.
*
* Parameters:
* layer - {<OpenLayers.Layer>}
* idx - {int}
*/
setLayerIndex: function (layer, idx) {
var base = this.getLayerIndex(layer);
if (idx < 0) {
idx = 0;
} else if (idx > this.layers.length) {
idx = this.layers.length;
}
if (base != idx) {
this.layers.splice(base, 1);
this.layers.splice(idx, 0, layer);
for (var i = 0; i < this.layers.length; i++) {
this.setLayerZIndex(this.layers[i], i);
}
this.events.triggerEvent("changelayer", {
layer: layer, property: "order"
});
}
},
/**
* APIMethod: raiseLayer
* Change the index of the given layer by delta. If delta is positive,
*     the layer is moved up the map's layer stack; if delta is negative,
*     the layer is moved down.  Again, note that this cannot (or at least
*     should not) be effectively used to raise base layers above overlays.
*
* Paremeters:
* layer - {<OpenLayers.Layer>}
* idx - {int}
*/
raiseLayer: function (layer, delta) {
var idx = this.getLayerIndex(layer) + delta;
this.setLayerIndex(layer, idx);
},
/**
* APIMethod: setBaseLayer
* Allows user to specify one of the currently-loaded layers as the Map's
*     new base layer.
*
* Parameters:
* newBaseLayer - {<OpenLayers.Layer>}
*/
setBaseLayer: function(newBaseLayer) {
var oldExtent = null;
if (this.baseLayer) {
oldExtent = this.baseLayer.getExtent();
}
if (newBaseLayer != this.baseLayer) {
// is newBaseLayer an already loaded layer?m
if (OpenLayers.Util.indexOf(this.layers, newBaseLayer) != -1) {
// make the old base layer invisible
if (this.baseLayer != null) {
this.baseLayer.setVisibility(false);
}
// set new baselayer
this.baseLayer = newBaseLayer;
// Increment viewRequestID since the baseLayer is
// changing. This is used by tiles to check if they should
// draw themselves.
this.viewRequestID++;
this.baseLayer.visibility = true;
//redraw all layers
var center = this.getCenter();
if (center != null) {
//either get the center from the old Extent or just from
// the current center of the map.
var newCenter = (oldExtent)
? oldExtent.getCenterLonLat()
: center;
//the new zoom will either come from the old Extent or
// from the current resolution of the map
var newZoom = (oldExtent)
? this.getZoomForExtent(oldExtent, true)
: this.getZoomForResolution(this.resolution, true);
// zoom and force zoom change
this.setCenter(newCenter, newZoom, false, true);
}
this.events.triggerEvent("changebaselayer", {
layer: this.baseLayer
});
}
}
},
/********************************************************/
/*                                                      */
/*                 Control Functions                    */
/*                                                      */
/*     The following functions deal with adding and     */
/*        removing Controls to and from the Map         */
/*                                                      */
/********************************************************/
/**
* APIMethod: addControl
*
* Parameters:
* control - {<OpenLayers.Control>}
* px - {<OpenLayers.Pixel>}
*/
addControl: function (control, px) {
this.controls.push(control);
this.addControlToMap(control, px);
},
/**
* Method: addControlToMap
*
* Parameters:
*
* control - {<OpenLayers.Control>}
* px - {<OpenLayers.Pixel>}
*/
addControlToMap: function (control, px) {
// If a control doesn't have a div at this point, it belongs in the
// viewport.
control.outsideViewport = (control.div != null);
// If the map has a displayProjection, and the control doesn't, set
// the display projection.
if (this.displayProjection && !control.displayProjection) {
control.displayProjection = this.displayProjection;
}
control.setMap(this);
var div = control.draw(px);
if (div) {
if(!control.outsideViewport) {
div.style.zIndex = this.Z_INDEX_BASE['Control'] +
this.controls.length;
this.viewPortDiv.appendChild( div );
}
}
},
/**
* APIMethod: getControl
*
* Parameters:
* id - {String} ID of the control to return.
*
* Returns:
* {<OpenLayers.Control>} The control from the map's list of controls
*                        which has a matching 'id'. If none found,
*                        returns null.
*/
getControl: function (id) {
var returnControl = null;
for(var i=0; i < this.controls.length; i++) {
var control = this.controls[i];
if (control.id == id) {
returnControl = control;
break;
}
}
return returnControl;
},
/**
* APIMethod: removeControl
* Remove a control from the map. Removes the control both from the map
*     object's internal array of controls, as well as from the map's
*     viewPort (assuming the control was not added outsideViewport)
*
* Parameters:
* control - {<OpenLayers.Control>} The control to remove.
*/
removeControl: function (control) {
//make sure control is non-null and actually part of our map
if ( (control) && (control == this.getControl(control.id)) ) {
if (control.div && (control.div.parentNode == this.viewPortDiv)) {
this.viewPortDiv.removeChild(control.div);
}
OpenLayers.Util.removeItem(this.controls, control);
}
},
/********************************************************/
/*                                                      */
/*                  Popup Functions                     */
/*                                                      */
/*     The following functions deal with adding and     */
/*        removing Popups to and from the Map           */
/*                                                      */
/********************************************************/
/**
* APIMethod: addPopup
*
* Parameters:
* popup - {<OpenLayers.Popup>}
* exclusive - {Boolean} If true, closes all other popups first
*/
addPopup: function(popup, exclusive) {
if (exclusive) {
//remove all other popups from screen
for (var i = this.popups.length - 1; i >= 0; --i) {
this.removePopup(this.popups[i]);
}
}
popup.map = this;
this.popups.push(popup);
var popupDiv = popup.draw();
if (popupDiv) {
popupDiv.style.zIndex = this.Z_INDEX_BASE['Popup'] +
this.popups.length;
this.layerContainerDiv.appendChild(popupDiv);
}
},
/**
* APIMethod: removePopup
*
* Parameters:
* popup - {<OpenLayers.Popup>}
*/
removePopup: function(popup) {
OpenLayers.Util.removeItem(this.popups, popup);
if (popup.div) {
try { this.layerContainerDiv.removeChild(popup.div); }
catch (e) { } // Popups sometimes apparently get disconnected
// from the layerContainerDiv, and cause complaints.
}
popup.map = null;
},
/********************************************************/
/*                                                      */
/*              Container Div Functions                 */
/*                                                      */
/*   The following functions deal with the access to    */
/*    and maintenance of the size of the container div  */
/*                                                      */
/********************************************************/
/**
* APIMethod: getSize
*
* Returns:
* {<OpenLayers.Size>} An <OpenLayers.Size> object that represents the
*                     size, in pixels, of the div into which OpenLayers
*                     has been loaded.
*                     Note - A clone() of this locally cached variable is
*                     returned, so as not to allow users to modify it.
*/
getSize: function () {
var size = null;
if (this.size != null) {
size = this.size.clone();
}
return size;
},
/**
* APIMethod: updateSize
* This function should be called by any external code which dynamically
*     changes the size of the map div (because mozilla wont let us catch
*     the "onresize" for an element)
*/
updateSize: function() {
// the div might have moved on the page, also
this.events.element.offsets = null;
var newSize = this.getCurrentSize();
var oldSize = this.getSize();
if (oldSize == null) {
this.size = oldSize = newSize;
}
if (!newSize.equals(oldSize)) {
// store the new size
this.size = newSize;
//notify layers of mapresize
for(var i=0; i < this.layers.length; i++) {
this.layers[i].onMapResize();
}
if (this.baseLayer != null) {
var center = new OpenLayers.Pixel(newSize.w /2, newSize.h / 2);
var centerLL = this.getLonLatFromViewPortPx(center);
var zoom = this.getZoom();
this.zoom = null;
this.setCenter(this.getCenter(), zoom);
}
}
},
/**
* Method: getCurrentSize
*
* Returns:
* {<OpenLayers.Size>} A new <OpenLayers.Size> object with the dimensions
*                     of the map div
*/
getCurrentSize: function() {
var size = new OpenLayers.Size(this.div.clientWidth,
this.div.clientHeight);
// Workaround for the fact that hidden elements return 0 for size.
if (size.w == 0 && size.h == 0 || isNaN(size.w) && isNaN(size.h)) {
var dim = OpenLayers.Element.getDimensions(this.div);
size.w = dim.width;
size.h = dim.height;
}
if (size.w == 0 && size.h == 0 || isNaN(size.w) && isNaN(size.h)) {
size.w = parseInt(this.div.style.width);
size.h = parseInt(this.div.style.height);
}
return size;
},
/**
* Method: calculateBounds
*
* Parameters:
* center - {<OpenLayers.LonLat>} Default is this.getCenter()
* resolution - {float} Default is this.getResolution()
*
* Returns:
* {<OpenLayers.Bounds>} A bounds based on resolution, center, and
*                       current mapsize.
*/
calculateBounds: function(center, resolution) {
var extent = null;
if (center == null) {
center = this.getCenter();
}
if (resolution == null) {
resolution = this.getResolution();
}
if ((center != null) && (resolution != null)) {
var size = this.getSize();
var w_deg = size.w * resolution;
var h_deg = size.h * resolution;
extent = 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;
},
/********************************************************/
/*                                                      */
/*            Zoom, Center, Pan Functions               */
/*                                                      */
/*    The following functions handle the validation,    */
/*   getting and setting of the Zoom Level and Center   */
/*       as well as the panning of the Map              */
/*                                                      */
/********************************************************/
/**
* APIMethod: getCenter
*
* Returns:
* {<OpenLayers.LonLat>}
*/
getCenter: function () {
return this.center;
},
/**
* APIMethod: getZoom
*
* Returns:
* {Integer}
*/
getZoom: function () {
return this.zoom;
},
/**
* APIMethod: pan
* Allows user to pan by a value of screen pixels
*
* Parameters:
* dx - {Integer}
* dy - {Integer}
* options - {Object} Options to configure panning:
*  - *animate* {Boolean} Use panTo instead of setCenter. Default is true.
*  - *dragging* {Boolean} Call setCenter with dragging true.  Default is
*    false.
*/
pan: function(dx, dy, options) {
// this should be pushed to applyDefaults and extend
if (!options) {
options = {};
}
OpenLayers.Util.applyDefaults(options, {
animate: true,
dragging: false
});
// getCenter
var centerPx = this.getViewPortPxFromLonLat(this.getCenter());
// adjust
var newCenterPx = centerPx.add(dx, dy);
// only call setCenter if not dragging or there has been a change
if (!options.dragging || !newCenterPx.equals(centerPx)) {
var newCenterLonLat = this.getLonLatFromViewPortPx(newCenterPx);
if (options.animate) {
this.panTo(newCenterLonLat);
} else {
this.setCenter(newCenterLonLat, null, options.dragging);
}
}
},
/**
* APIMethod: panTo
* Allows user to pan to a new lonlat
* If the new lonlat is in the current extent the map will slide smoothly
*
* Parameters:
* lonlat - {<OpenLayers.Lonlat>}
*/
panTo: function(lonlat) {
if (this.panMethod && this.getExtent().containsLonLat(lonlat)) {
if (!this.panTween) {
this.panTween = new OpenLayers.Tween(this.panMethod);
}
var center = this.getCenter();
var from = {
lon: center.lon,
lat: center.lat
};
var to = {
lon: lonlat.lon,
lat: lonlat.lat
};
this.panTween.start(from, to, 50, {
callbacks: {
start: OpenLayers.Function.bind(function(lonlat) {
this.events.triggerEvent("movestart");
}, this),
eachStep: OpenLayers.Function.bind(function(lonlat) {
lonlat = new OpenLayers.LonLat(lonlat.lon, lonlat.lat);
this.moveTo(lonlat, this.zoom, {
'dragging': true,
'noEvent': true
});
}, this),
done: OpenLayers.Function.bind(function(lonlat) {
lonlat = new OpenLayers.LonLat(lonlat.lon, lonlat.lat);
this.moveTo(lonlat, this.zoom, {
'noEvent': true
});
this.events.triggerEvent("moveend");
}, this)
}
});
} else {
this.setCenter(lonlat);
}
},
/**
* APIMethod: setCenter
*
* Parameters:
* lonlat - {<OpenLayers.LonLat>}
* zoom - {Integer}
* dragging - {Boolean} Specifies whether or not to trigger
*                      movestart/end events
* forceZoomChange - {Boolean} Specifies whether or not to trigger zoom
*                             change events (needed on baseLayer change)
*
* TBD: reconsider forceZoomChange in 3.0
*/
setCenter: function(lonlat, zoom, dragging, forceZoomChange) {
this.moveTo(lonlat, zoom, {
'dragging': dragging,
'forceZoomChange': forceZoomChange,
'caller': 'setCenter'
});
},
/**
* Method: moveTo
*
* Parameters:
* lonlat - {<OpenLayers.LonLat>}
* zoom - {Integer}
* options - {Object}
*/
moveTo: function(lonlat, zoom, options) {
if (!options) {
options = {};
}
// dragging is false by default
var dragging = options.dragging;
// forceZoomChange is false by default
var forceZoomChange = options.forceZoomChange;
// noEvent is false by default
var noEvent = options.noEvent;
if (this.panTween && options.caller == "setCenter") {
this.panTween.stop();
}
if (!this.center && !this.isValidLonLat(lonlat)) {
lonlat = this.maxExtent.getCenterLonLat();
}
if(this.restrictedExtent != null) {
// In 3.0, decide if we want to change interpretation of maxExtent.
if(lonlat == null) {
lonlat = this.getCenter();
}
if(zoom == null) {
zoom = this.getZoom();
}
var resolution = this.getResolutionForZoom(zoom);
var extent = this.calculateBounds(lonlat, resolution);
if(!this.restrictedExtent.containsBounds(extent)) {
var maxCenter = this.restrictedExtent.getCenterLonLat();
if(extent.getWidth() > this.restrictedExtent.getWidth()) {
lonlat = new OpenLayers.LonLat(maxCenter.lon, lonlat.lat);
} else if(extent.left < this.restrictedExtent.left) {
lonlat = lonlat.add(this.restrictedExtent.left -
extent.left, 0);
} else if(extent.right > this.restrictedExtent.right) {
lonlat = lonlat.add(this.restrictedExtent.right -
extent.right, 0);
}
if(extent.getHeight() > this.restrictedExtent.getHeight()) {
lonlat = new OpenLayers.LonLat(lonlat.lon, maxCenter.lat);
} else if(extent.bottom < this.restrictedExtent.bottom) {
lonlat = lonlat.add(0, this.restrictedExtent.bottom -
extent.bottom);
}
else if(extent.top > this.restrictedExtent.top) {
lonlat = lonlat.add(0, this.restrictedExtent.top -
extent.top);
}
}
}
var zoomChanged = forceZoomChange || (
(this.isValidZoomLevel(zoom)) &&
(zoom != this.getZoom()) );
var centerChanged = (this.isValidLonLat(lonlat)) &&
(!lonlat.equals(this.center));
// if neither center nor zoom will change, no need to do anything
if (zoomChanged || centerChanged || !dragging) {
if (!this.dragging && !noEvent) {
this.events.triggerEvent("movestart");
}
if (centerChanged) {
if ((!zoomChanged) && (this.center)) {
// if zoom hasnt changed, just slide layerContainer
//  (must be done before setting this.center to new value)
this.centerLayerContainer(lonlat);
}
this.center = lonlat.clone();
}
// (re)set the layerContainerDiv's location
if ((zoomChanged) || (this.layerContainerOrigin == null)) {
this.layerContainerOrigin = this.center.clone();
this.layerContainerDiv.style.left = "0px";
this.layerContainerDiv.style.top  = "0px";
}
if (zoomChanged) {
this.zoom = zoom;
this.resolution = this.getResolutionForZoom(zoom);
// zoom level has changed, increment viewRequestID.
this.viewRequestID++;
}
var bounds = this.getExtent();
//send the move call to the baselayer and all the overlays
this.baseLayer.moveTo(bounds, zoomChanged, dragging);
bounds = this.baseLayer.getExtent();
for (var i = 0; i < this.layers.length; i++) {
var layer = this.layers[i];
if (!layer.isBaseLayer) {
var inRange = layer.calculateInRange();
if (layer.inRange != inRange) {
// the inRange property has changed. If the layer is
// no longer in range, we turn it off right away. If
// the layer is no longer out of range, the moveTo
// call below will turn on the layer.
layer.inRange = inRange;
if (!inRange) {
layer.display(false);
}
this.events.triggerEvent("changelayer", {
layer: layer, property: "visibility"
});
}
if (inRange && layer.visibility) {
layer.moveTo(bounds, zoomChanged, dragging);
}
}
}
if (zoomChanged) {
//redraw popups
for (var i = 0; i < this.popups.length; i++) {
this.popups[i].updatePosition();
}
}
this.events.triggerEvent("move");
if (zoomChanged) { this.events.triggerEvent("zoomend"); }
}
// even if nothing was done, we want to notify of this
if (!dragging && !noEvent) {
this.events.triggerEvent("moveend");
}
// Store the map dragging state for later use
this.dragging = !!dragging;
},
/**
* Method: centerLayerContainer
* This function takes care to recenter the layerContainerDiv.
*
* Parameters:
* lonlat - {<OpenLayers.LonLat>}
*/
centerLayerContainer: function (lonlat) {
var originPx = this.getViewPortPxFromLonLat(this.layerContainerOrigin);
var newPx = this.getViewPortPxFromLonLat(lonlat);
if ((originPx != null) && (newPx != null)) {
this.layerContainerDiv.style.left = Math.round(originPx.x - newPx.x) + "px";
this.layerContainerDiv.style.top  = Math.round(originPx.y - newPx.y) + "px";
}
},
/**
* Method: isValidZoomLevel
*
* Parameters:
* zoomLevel - {Integer}
*
* Returns:
* {Boolean} Whether or not the zoom level passed in is non-null and
*           within the min/max range of zoom levels.
*/
isValidZoomLevel: function(zoomLevel) {
return ( (zoomLevel != null) &&
(zoomLevel >= 0) &&
(zoomLevel < this.getNumZoomLevels()) );
},
/**
* Method: isValidLonLat
*
* Parameters:
* lonlat - {<OpenLayers.LonLat>}
*
* Returns:
* {Boolean} Whether or not the lonlat passed in is non-null and within
*           the maxExtent bounds
*/
isValidLonLat: function(lonlat) {
var valid = false;
if (lonlat != null) {
var maxExtent = this.getMaxExtent();
valid = maxExtent.containsLonLat(lonlat);
}
return valid;
},
/********************************************************/
/*                                                      */
/*                 Layer Options                        */
/*                                                      */
/*    Accessor functions to Layer Options parameters    */
/*                                                      */
/********************************************************/
/**
* APIMethod: getProjection
* This method returns a string representing the projection. In
*     the case of projection support, this will be the srsCode which
*     is loaded -- otherwise it will simply be the string value that
*     was passed to the projection at startup.
*
* FIXME: In 3.0, we will remove getProjectionObject, and instead
*     return a Projection object from this function.
*
* Returns:
* {String} The Projection string from the base layer or null.
*/
getProjection: function() {
var projection = this.getProjectionObject();
return projection ? projection.getCode() : null;
},
/**
* APIMethod: getProjectionObject
* Returns the projection obect from the baselayer.
*
* Returns:
* {<OpenLayers.Projection>} The Projection of the base layer.
*/
getProjectionObject: function() {
var projection = null;
if (this.baseLayer != null) {
projection = this.baseLayer.projection;
}
return projection;
},
/**
* APIMethod: getMaxResolution
*
* Returns:
* {String} The Map's Maximum Resolution
*/
getMaxResolution: function() {
var maxResolution = null;
if (this.baseLayer != null) {
maxResolution = this.baseLayer.maxResolution;
}
return maxResolution;
},
/**
* APIMethod: getMaxExtent
*
* Returns:
* {<OpenLayers.Bounds>}
*/
getMaxExtent: function () {
var maxExtent = null;
if (this.baseLayer != null) {
maxExtent = this.baseLayer.maxExtent;
}
return maxExtent;
},
/**
* APIMethod: getNumZoomLevels
*
* Returns:
* {Integer} The total number of zoom levels that can be displayed by the
*           current baseLayer.
*/
getNumZoomLevels: function() {
var numZoomLevels = null;
if (this.baseLayer != null) {
numZoomLevels = this.baseLayer.numZoomLevels;
}
return numZoomLevels;
},
/********************************************************/
/*                                                      */
/*                 Baselayer Functions                  */
/*                                                      */
/*    The following functions, all publicly exposed     */
/*       in the API?, are all merely wrappers to the    */
/*       the same calls on whatever layer is set as     */
/*                the current base layer                */
/*                                                      */
/********************************************************/
/**
* APIMethod: getExtent
*
* Returns:
* {<OpenLayers.Bounds>} A Bounds object which represents the lon/lat
*                       bounds of the current viewPort.
*                       If no baselayer is set, returns null.
*/
getExtent: function () {
var extent = null;
if (this.baseLayer != null) {
extent = this.baseLayer.getExtent();
}
return extent;
},
/**
* APIMethod: getResolution
*
* Returns:
* {Float} The current resolution of the map.
*         If no baselayer is set, returns null.
*/
getResolution: function () {
var resolution = null;
if (this.baseLayer != null) {
resolution = this.baseLayer.getResolution();
}
return resolution;
},
/**
* APIMethod: getScale
*
* Returns:
* {Float} The current scale denominator of the map.
*         If no baselayer is set, returns null.
*/
getScale: function () {
var scale = null;
if (this.baseLayer != null) {
var res = this.getResolution();
var units = this.baseLayer.units;
scale = OpenLayers.Util.getScaleFromResolution(res, units);
}
return scale;
},
/**
* APIMethod: getZoomForExtent
*
* Parameters:
* bounds - {<OpenLayers.Bounds>}
* closest - {Boolean} Find the zoom level that most closely fits the
*     specified bounds. Note that this may result in a zoom that does
*     not exactly contain the entire extent.
*     Default is false.
*
* Returns:
* {Integer} A suitable zoom level for the specified bounds.
*           If no baselayer is set, returns null.
*/
getZoomForExtent: function (bounds, closest) {
var zoom = null;
if (this.baseLayer != null) {
zoom = this.baseLayer.getZoomForExtent(bounds, closest);
}
return zoom;
},
/**
* APIMethod: getResolutionForZoom
*
* Parameter:
* zoom - {Float}
*
* Returns:
* {Float} A suitable resolution for the specified zoom.  If no baselayer
*     is set, returns null.
*/
getResolutionForZoom: function(zoom) {
var resolution = null;
if(this.baseLayer) {
resolution = this.baseLayer.getResolutionForZoom(zoom);
}
return resolution;
},
/**
* APIMethod: getZoomForResolution
*
* Parameter:
* resolution - {Float}
* closest - {Boolean} Find the zoom level that corresponds to the absolute
*     closest resolution, which may result in a zoom whose corresponding
*     resolution is actually smaller than we would have desired (if this
*     is being called from a getZoomForExtent() call, then this means that
*     the returned zoom index might not actually contain the entire
*     extent specified... but it'll be close).
*     Default is false.
*
* Returns:
* {Integer} A suitable zoom level for the specified resolution.
*           If no baselayer is set, returns null.
*/
getZoomForResolution: function(resolution, closest) {
var zoom = null;
if (this.baseLayer != null) {
zoom = this.baseLayer.getZoomForResolution(resolution, closest);
}
return zoom;
},
/********************************************************/
/*                                                      */
/*                  Zooming Functions                   */
/*                                                      */
/*    The following functions, all publicly exposed     */
/*       in the API, are all merely wrappers to the     */
/*               the setCenter() function               */
/*                                                      */
/********************************************************/
/**
* APIMethod: zoomTo
* Zoom to a specific zoom level
*
* Parameters:
* zoom - {Integer}
*/
zoomTo: function(zoom) {
if (this.isValidZoomLevel(zoom)) {
this.setCenter(null, zoom);
}
},
/**
* APIMethod: zoomIn
*
* Parameters:
* zoom - {int}
*/
zoomIn: function() {
this.zoomTo(this.getZoom() + 1);
},
/**
* APIMethod: zoomOut
*
* Parameters:
* zoom - {int}
*/
zoomOut: function() {
this.zoomTo(this.getZoom() - 1);
},
/**
* APIMethod: zoomToExtent
* Zoom to the passed in bounds, recenter
*
* Parameters:
* bounds - {<OpenLayers.Bounds>}
*/
zoomToExtent: function(bounds) {
var center = bounds.getCenterLonLat();
if (this.baseLayer.wrapDateLine) {
var maxExtent = this.getMaxExtent();
//fix straddling bounds (in the case of a bbox that straddles the
// dateline, it's left and right boundaries will appear backwards.
// we fix this by allowing a right value that is greater than the
// max value at the dateline -- this allows us to pass a valid
// bounds to calculate zoom)
//
bounds = bounds.clone();
while (bounds.right < bounds.left) {
bounds.right += maxExtent.getWidth();
}
//if the bounds was straddling (see above), then the center point
// we got from it was wrong. So we take our new bounds and ask it
// for the center. Because our new bounds is at least partially
// outside the bounds of maxExtent, the new calculated center
// might also be. We don't want to pass a bad center value to
// setCenter, so we have it wrap itself across the date line.
//
center = bounds.getCenterLonLat().wrapDateLine(maxExtent);
}
this.setCenter(center, this.getZoomForExtent(bounds));
},
/**
* APIMethod: zoomToMaxExtent
* Zoom to the full extent and recenter.
*/
zoomToMaxExtent: function() {
this.zoomToExtent(this.getMaxExtent());
},
/**
* APIMethod: zoomToScale
* Zoom to a specified scale
*
* Parameters:
* scale - {float}
*/
zoomToScale: function(scale) {
var res = OpenLayers.Util.getResolutionFromScale(scale,
this.baseLayer.units);
var size = this.getSize();
var w_deg = size.w * res;
var h_deg = size.h * res;
var center = this.getCenter();
var extent = new OpenLayers.Bounds(center.lon - w_deg / 2,
center.lat - h_deg / 2,
center.lon + w_deg / 2,
center.lat + h_deg / 2);
this.zoomToExtent(extent);
},
/********************************************************/
/*                                                      */
/*             Translation Functions                    */
/*                                                      */
/*      The following functions translate between       */
/*           LonLat, LayerPx, and ViewPortPx            */
/*                                                      */
/********************************************************/
//
// TRANSLATION: LonLat <-> ViewPortPx
//
/**
* Method: getLonLatFromViewPortPx
*
* Parameters:
* viewPortPx - {<OpenLayers.Pixel>}
*
* Returns:
* {<OpenLayers.LonLat>} An OpenLayers.LonLat which is the passed-in view
*                       port <OpenLayers.Pixel>, translated into lon/lat
*                       by the current base layer.
*/
getLonLatFromViewPortPx: function (viewPortPx) {
var lonlat = null;
if (this.baseLayer != null) {
lonlat = this.baseLayer.getLonLatFromViewPortPx(viewPortPx);
}
return lonlat;
},
/**
* APIMethod: getViewPortPxFromLonLat
*
* Parameters:
* lonlat - {<OpenLayers.LonLat>}
*
* Returns:
* {<OpenLayers.Pixel>} An OpenLayers.Pixel which is the passed-in
*                      <OpenLayers.LonLat>, translated into view port
*                      pixels by the current base layer.
*/
getViewPortPxFromLonLat: function (lonlat) {
var px = null;
if (this.baseLayer != null) {
px = this.baseLayer.getViewPortPxFromLonLat(lonlat);
}
return px;
},
//
// CONVENIENCE TRANSLATION FUNCTIONS FOR API
//
/**
* APIMethod: getLonLatFromPixel
*
* Parameters:
* px - {<OpenLayers.Pixel>}
*
* Returns:
* {<OpenLayers.LonLat>} An OpenLayers.LonLat corresponding to the given
*                       OpenLayers.Pixel, translated into lon/lat by the
*                       current base layer
*/
getLonLatFromPixel: function (px) {
return this.getLonLatFromViewPortPx(px);
},
/**
* APIMethod: getPixelFromLonLat
* Returns a pixel location given a map location.  The map location is
*     translated to an integer pixel location (in viewport pixel
*     coordinates) by the current base layer.
*
* Parameters:
* lonlat - {<OpenLayers.LonLat>} A map location.
*
* Returns:
* {<OpenLayers.Pixel>} An OpenLayers.Pixel corresponding to the
*     <OpenLayers.LonLat> translated into view port pixels by the current
*     base layer.
*/
getPixelFromLonLat: function (lonlat) {
var px = this.getViewPortPxFromLonLat(lonlat);
px.x = Math.round(px.x);
px.y = Math.round(px.y);
return px;
},
//
// TRANSLATION: ViewPortPx <-> LayerPx
//
/**
* APIMethod: getViewPortPxFromLayerPx
*
* Parameters:
* layerPx - {<OpenLayers.Pixel>}
*
* Returns:
* {<OpenLayers.Pixel>} Layer Pixel translated into ViewPort Pixel
*                      coordinates
*/
getViewPortPxFromLayerPx:function(layerPx) {
var viewPortPx = null;
if (layerPx != null) {
var dX = parseInt(this.layerContainerDiv.style.left);
var dY = parseInt(this.layerContainerDiv.style.top);
viewPortPx = layerPx.add(dX, dY);
}
return viewPortPx;
},
/**
* APIMethod: getLayerPxFromViewPortPx
*
* Parameters:
* viewPortPx - {<OpenLayers.Pixel>}
*
* Returns:
* {<OpenLayers.Pixel>} ViewPort Pixel translated into Layer Pixel
*                      coordinates
*/
getLayerPxFromViewPortPx:function(viewPortPx) {
var layerPx = null;
if (viewPortPx != null) {
var dX = -parseInt(this.layerContainerDiv.style.left);
var dY = -parseInt(this.layerContainerDiv.style.top);
layerPx = viewPortPx.add(dX, dY);
if (isNaN(layerPx.x) || isNaN(layerPx.y)) {
layerPx = null;
}
}
return layerPx;
},
//
// TRANSLATION: LonLat <-> LayerPx
//
/**
* Method: getLonLatFromLayerPx
*
* Parameters:
* px - {<OpenLayers.Pixel>}
*
* Returns:
* {<OpenLayers.LonLat>}
*/
getLonLatFromLayerPx: function (px) {
//adjust for displacement of layerContainerDiv
px = this.getViewPortPxFromLayerPx(px);
return this.getLonLatFromViewPortPx(px);
},
/**
* APIMethod: getLayerPxFromLonLat
*
* Parameters:
* lonlat - {<OpenLayers.LonLat>} lonlat
*
* Returns:
* {<OpenLayers.Pixel>} An OpenLayers.Pixel which is the passed-in
*                      <OpenLayers.LonLat>, translated into layer pixels
*                      by the current base layer
*/
getLayerPxFromLonLat: function (lonlat) {
//adjust for displacement of layerContainerDiv
var px = this.getPixelFromLonLat(lonlat);
return this.getLayerPxFromViewPortPx(px);
},
CLASS_NAME: "OpenLayers.Map"
});
/**
* Constant: TILE_WIDTH
* {Integer} 256 Default tile width (unless otherwise specified)
*/
OpenLayers.Map.TILE_WIDTH = 256;
/**
* Constant: TILE_HEIGHT
* {Integer} 256 Default tile height (unless otherwise specified)
*/
OpenLayers.Map.TILE_HEIGHT = 256;
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Map.js
* @requires OpenLayers/Projection.js
*/
/**
* Class: OpenLayers.Layer
*/
OpenLayers.Layer = OpenLayers.Class({
/**
* APIProperty: id
* {String}
*/
id: null,
/**
* APIProperty: name
* {String}
*/
name: null,
/**
* APIProperty: div
* {DOMElement}
*/
div: null,
/**
* Property: opacity
* {Float} The layer's opacity. Float number between 0.0 and 1.0.
*/
opacity: null,
/**
* Constant: EVENT_TYPES
* {Array(String)} Supported application event types.  Register a listener
*     for a particular event with the following syntax:
* (code)
* layer.events.register(type, obj, listener);
* (end)
*
* Listeners will be called with a reference to an event object.  The
*     properties of this event depends on exactly what happened.
*
* All event objects have at least the following properties:
*  - *object* {Object} A reference to layer.events.object.
*  - *element* {DOMElement} A reference to layer.events.element.
*
* Supported map event types:
*  - *loadstart* Triggered when layer loading starts.
*  - *loadend* Triggered when layer loading ends.
*  - *loadcancel* Triggered when layer loading is canceled.
*  - *visibilitychanged* Triggered when layer visibility is changed.
*/
EVENT_TYPES: ["loadstart", "loadend", "loadcancel", "visibilitychanged"],
/**
* APIProperty: events
* {<OpenLayers.Events>}
*/
events: null,
/**
* APIProperty: map
* {<OpenLayers.Map>} This variable is set when the layer is added to
*     the map, via the accessor function setMap().
*/
map: null,
/**
* APIProperty: isBaseLayer
* {Boolean} Whether or not the layer is a base layer. This should be set
*     individually by all subclasses. Default is false
*/
isBaseLayer: false,
/**
* Property: alpha
* {Boolean} The layer's images have an alpha channel.  Default is false.
*/
alpha: false,
/**
* APIProperty: displayInLayerSwitcher
* {Boolean} Display the layer's name in the layer switcher.  Default is
*     true.
*/
displayInLayerSwitcher: true,
/**
* APIProperty: visibility
* {Boolean} The layer should be displayed in the map.  Default is true.
*/
visibility: true,
/**
* APIProperty: attribution
* {String} Attribution string, displayed when an
*     <OpenLayers.Control.Attribution> has been added to the map.
*/
attribution: null,
/**
* Property: inRange
* {Boolean} The current map resolution is within the layer's min/max
*     range. This is set in <OpenLayers.Map.setCenter> whenever the zoom
*     changes.
*/
inRange: false,
/**
* Propery: imageSize
* {<OpenLayers.Size>} For layers with a gutter, the image is larger than
*     the tile by twice the gutter in each dimension.
*/
imageSize: null,
/**
* Property: imageOffset
* {<OpenLayers.Pixel>} For layers with a gutter, the image offset
*     represents displacement due to the gutter.
*/
imageOffset: null,
// OPTIONS
/**
* Property: options
* {Object} An optional object whose properties will be set on the layer.
*     Any of the layer properties can be set as a property of the options
*     object and sent to the constructor when the layer is created.
*/
options: null,
/**
* APIProperty: eventListeners
* {Object} If set as an option at construction, the eventListeners
*     object will be registered with <OpenLayers.Events.on>.  Object
*     structure must be a listeners object as shown in the example for
*     the events.on method.
*/
eventListeners: null,
/**
* APIProperty: gutter
* {Integer} Determines the width (in pixels) of the gutter around image
*     tiles to ignore.  By setting this property to a non-zero value,
*     images will be requested that are wider and taller than the tile
*     size by a value of 2 x gutter.  This allows artifacts of rendering
*     at tile edges to be ignored.  Set a gutter value that is equal to
*     half the size of the widest symbol that needs to be displayed.
*     Defaults to zero.  Non-tiled layers always have zero gutter.
*/
gutter: 0,
/**
* APIProperty: projection
* {<OpenLayers.Projection>} or {<String>} Set in the layer options to
*     override the default projection string this layer - also set maxExtent,
*     maxResolution, and units if appropriate. Can be either a string or
*     an <OpenLayers.Projection> object when created -- will be converted
*     to an object when setMap is called if a string is passed.
*/
projection: null,
/**
* APIProperty: units
* {String} The layer map units.  Defaults to 'degrees'.  Possible values
*     are 'degrees' (or 'dd'), 'm', 'ft', 'km', 'mi', 'inches'.
*/
units: null,
/**
* APIProperty: scales
* {Array}  An array of map scales in descending order.  The values in the
*     array correspond to the map scale denominator.  Note that these
*     values only make sense if the display (monitor) resolution of the
*     client is correctly guessed by whomever is configuring the
*     application.  In addition, the units property must also be set.
*     Use <resolutions> instead wherever possible.
*/
scales: null,
/**
* APIProperty: resolutions
* {Array} A list of map resolutions (map units per pixel) in descending
*     order.  If this is not set in the layer constructor, it will be set
*     based on other resolution related properties (maxExtent,
*     maxResolution, maxScale, etc.).
*/
resolutions: null,
/**
* APIProperty: maxExtent
* {<OpenLayers.Bounds>}  The center of these bounds will not stray outside
*     of the viewport extent during panning.  In addition, if
*     <displayOutsideMaxExtent> is set to false, data will not be
*     requested that falls completely outside of these bounds.
*/
maxExtent: null,
/**
* APIProperty: minExtent
* {<OpenLayers.Bounds>}
*/
minExtent: null,
/**
* APIProperty: maxResolution
* {Float} Default max is 360 deg / 256 px, which corresponds to
*     zoom level 0 on gmaps.  Specify a different value in the layer
*     options if you are not using a geographic projection and
*     displaying the whole world.
*/
maxResolution: null,
/**
* APIProperty: minResolution
* {Float}
*/
minResolution: null,
/**
* APIProperty: numZoomLevels
* {Integer}
*/
numZoomLevels: null,
/**
* APIProperty: minScale
* {Float}
*/
minScale: null,
/**
* APIProperty: maxScale
* {Float}
*/
maxScale: null,
/**
* APIProperty: displayOutsideMaxExtent
* {Boolean} Request map tiles that are completely outside of the max
*     extent for this layer. Defaults to false.
*/
displayOutsideMaxExtent: false,
/**
* APIProperty: wrapDateLine
* {Boolean} #487 for more info.
*/
wrapDateLine: false,
/**
* APIProperty: transitionEffect
* {String} The transition effect to use when the map is panned or
*     zoomed.
*
* There are currently two supported values:
*  - *null* No transition effect (the default).
*  - *resize*  Existing tiles are resized on zoom to provide a visual
*    effect of the zoom having taken place immediately.  As the
*    new tiles become available, they are drawn over top of the
*    resized tiles.
*/
transitionEffect: null,
/**
* Property: SUPPORTED_TRANSITIONS
* {Array} An immutable (that means don't change it!) list of supported
*     transitionEffect values.
*/
SUPPORTED_TRANSITIONS: ['resize'],
/**
* Constructor: OpenLayers.Layer
*
* Parameters:
* name - {String} The layer name
* options - {Object} Hashtable of extra options to tag onto the layer
*/
initialize: function(name, options) {
this.addOptions(options);
this.name = name;
if (this.id == null) {
this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
this.div = OpenLayers.Util.createDiv(this.id);
this.div.style.width = "100%";
this.div.style.height = "100%";
this.events = new OpenLayers.Events(this, this.div,
this.EVENT_TYPES);
if(this.eventListeners instanceof Object) {
this.events.on(this.eventListeners);
}
}
if (this.wrapDateLine) {
this.displayOutsideMaxExtent = true;
}
},
/**
* Method: destroy
* Destroy is a destructor: this is to alleviate cyclic references which
*     the Javascript garbage cleaner can not take care of on its own.
*
* Parameters:
* setNewBaseLayer - {Boolean} Set a new base layer when this layer has
*     been destroyed.  Default is true.
*/
destroy: function(setNewBaseLayer) {
if (setNewBaseLayer == null) {
setNewBaseLayer = true;
}
if (this.map != null) {
this.map.removeLayer(this, setNewBaseLayer);
}
this.projection = null;
this.map = null;
this.name = null;
this.div = null;
this.options = null;
if (this.events) {
if(this.eventListeners) {
this.events.un(this.eventListeners);
}
this.events.destroy();
}
this.eventListeners = null;
this.events = null;
},
/**
* Method: clone
*
* Parameters:
* obj - {<OpenLayers.Layer>} The layer to be cloned
*
* Returns:
* {<OpenLayers.Layer>} An exact clone of this <OpenLayers.Layer>
*/
clone: function (obj) {
if (obj == null) {
obj = new OpenLayers.Layer(this.name, this.options);
}
// catch any randomly tagged-on properties
OpenLayers.Util.applyDefaults(obj, this);
// a cloned layer should never have its map property set
//  because it has not been added to a map yet.
obj.map = null;
return obj;
},
/**
* APIMethod: setName
* Sets the new layer name for this layer.  Can trigger a changelayer event
*     on the map.
*
* Parameters:
* newName - {String} The new name.
*/
setName: function(newName) {
if (newName != this.name) {
this.name = newName;
if (this.map != null) {
this.map.events.triggerEvent("changelayer", {
layer: this,
property: "name"
});
}
}
},
/**
* APIMethod: addOptions
*
* Parameters:
* newOptions - {Object}
*/
addOptions: function (newOptions) {
if (this.options == null) {
this.options = {};
}
// update our copy for clone
OpenLayers.Util.extend(this.options, newOptions);
// add new options to this
OpenLayers.Util.extend(this, newOptions);
},
/**
* APIMethod: onMapResize
* This function can be implemented by subclasses
*/
onMapResize: function() {
//this function can be implemented by subclasses
},
/**
* APIMethod: redraw
* Redraws the layer.  Returns true if the layer was redrawn, false if not.
*
* Returns:
* {Boolean} The layer was redrawn.
*/
redraw: function() {
var redrawn = false;
if (this.map) {
// min/max Range may have changed
this.inRange = this.calculateInRange();
// map's center might not yet be set
var extent = this.getExtent();
if (extent && this.inRange && this.visibility) {
this.moveTo(extent, true, false);
redrawn = true;
}
}
return redrawn;
},
/**
* Method: moveTo
*
* Parameters:
* bound - {<OpenLayers.Bounds>}
* zoomChanged - {Boolean} Tells when zoom has changed, as layers have to
*     do some init work in that case.
* dragging - {Boolean}
*/
moveTo:function(bounds, zoomChanged, dragging) {
var display = this.visibility;
if (!this.isBaseLayer) {
display = display && this.inRange;
}
this.display(display);
},
/**
* Method: setMap
* 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.
*
*     Here we take care to bring over any of the necessary default
*     properties from the map.
*
* Parameters:
* map - {<OpenLayers.Map>}
*/
setMap: function(map) {
if (this.map == null) {
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;
if (this.projection && typeof this.projection == "string") {
this.projection = new OpenLayers.Projection(this.projection);
}
// Check the projection to see if we can get units -- if not, refer
// to properties.
this.units = this.projection.getUnits() ||
this.units || this.map.units;
this.initResolutions();
if (!this.isBaseLayer) {
this.inRange = this.calculateInRange();
var show = ((this.visibility) && (this.inRange));
this.div.style.display = show ? "" : "none";
}
// deal with gutters
this.setTileSize();
}
},
/**
* APIMethod: removeMap
* Just as setMap() allows each layer the possibility to take a
*     personalized action on being added to the map, removeMap() allows
*     each layer to take a personalized action on being removed from it.
*     For now, this will be mostly unused, except for the EventPane layer,
*     which needs this hook so that it can remove the special invisible
*     pane.
*
* Parameters:
* map - {<OpenLayers.Map>}
*/
removeMap: function(map) {
//to be overridden by subclasses
},
/**
* APIMethod: getImageSize
*
* Returns:
* {<OpenLayers.Size>} The size that the image should be, taking into
*     account gutters.
*/
getImageSize: function() {
return (this.imageSize || this.tileSize);
},
/**
* APIMethod: setTileSize
* Set the tile size based on the map size.  This also sets layer.imageSize
*     and layer.imageOffset for use by Tile.Image.
*
* Parameters:
* size - {<OpenLayers.Size>}
*/
setTileSize: function(size) {
var tileSize = (size) ? size :
((this.tileSize) ? this.tileSize :
this.map.getTileSize());
this.tileSize = tileSize;
if(this.gutter) {
// layers with gutters need non-null tile sizes
//if(tileSize == null) {
//    OpenLayers.console.error("Error in layer.setMap() for " +
//                              this.name + ": layers with " +
//                              "gutters need non-null tile sizes");
//}
this.imageOffset = new OpenLayers.Pixel(-this.gutter,
-this.gutter);
this.imageSize = new OpenLayers.Size(tileSize.w + (2*this.gutter),
tileSize.h + (2*this.gutter));
}
},
/**
* APIMethod: getVisibility
*
* Returns:
* {Boolean} The layer should be displayed (if in range).
*/
getVisibility: function() {
return this.visibility;
},
/**
* APIMethod: setVisibility
* Set the visibility flag for the layer and hide/show & redraw
*     accordingly. Fire event unless otherwise specified
*
* Note that visibility is no longer simply whether or not the layer's
*     style.display is set to "block". Now we store a 'visibility' state
*     property on the layer class, this allows us to remember whether or
*     not we *desire* for a layer to be visible. In the case where the
*     map's resolution is out of the layer's range, this desire may be
*     subverted.
*
* Parameters:
* visible - {Boolean} Whether or not to display the layer (if in range)
*/
setVisibility: function(visibility) {
if (visibility != this.visibility) {
this.visibility = visibility;
this.display(visibility);
this.redraw();
if (this.map != null) {
this.map.events.triggerEvent("changelayer", {
layer: this,
property: "visibility"
});
}
this.events.triggerEvent("visibilitychanged");
}
},
/**
* APIMethod: display
* Hide or show the Layer
*
* Parameters:
* display - {Boolean}
*/
display: function(display) {
var inRange = this.calculateInRange();
if (display != (this.div.style.display != "none")) {
this.div.style.display = (display && inRange) ? "block" : "none";
}
},
/**
* Method: calculateInRange
*
* Returns:
* {Boolean} The layer is displayable at the current map's current
*     resolution.
*/
calculateInRange: function() {
var inRange = false;
if (this.map) {
var resolution = this.map.getResolution();
inRange = ( (resolution >= this.minResolution) &&
(resolution <= this.maxResolution) );
}
return inRange;
},
/**
* APIMethod: setIsBaseLayer
*
* Parameters:
* isBaseLayer - {Boolean}
*/
setIsBaseLayer: function(isBaseLayer) {
if (isBaseLayer != this.isBaseLayer) {
this.isBaseLayer = isBaseLayer;
if (this.map != null) {
this.map.events.triggerEvent("changebaselayer", {
layer: this
});
}
}
},
/********************************************************/
/*                                                      */
/*                 Baselayer Functions                  */
/*                                                      */
/********************************************************/
/**
* Method: initResolutions
* This method's responsibility is to set up the 'resolutions' array
*     for the layer -- this array is what the layer will use to interface
*     between the zoom levels of the map and the resolution display
*     of the layer.
*
* The user has several options that determine how the array is set up.
*
* For a detailed explanation, see the following wiki from the
*     openlayers.org homepage:
*     http://trac.openlayers.org/wiki/SettingZoomLevels
*/
initResolutions: function() {
// These are the relevant options which are used for calculating
//  resolutions information.
//
var props = new Array(
'projection', 'units',
'scales', 'resolutions',
'maxScale', 'minScale',
'maxResolution', 'minResolution',
'minExtent', 'maxExtent',
'numZoomLevels', 'maxZoomLevel'
);
// First we create a new object where we will store all of the
//  resolution-related properties that we find in either the layer's
//  'options' array or from the map.
//
var confProps = {};
for(var i=0; i < props.length; i++) {
var property = props[i];
confProps[property] = this.options[property] || this.map[property];
}
// Do not use the scales/resolutions at the map level if
// minScale/minResolution and maxScale/maxResolution are
// specified at the layer level
if (this.options.minScale != null &&
this.options.maxScale != null &&
this.options.scales == null) {
confProps.scales = null;
}
if (this.options.minResolution != null &&
this.options.maxResolution != null &&
this.options.resolutions == null) {
confProps.resolutions = null;
}
// If numZoomLevels hasn't been set and the maxZoomLevel *has*,
//  then use maxZoomLevel to calculate numZoomLevels
//
if ( (!confProps.numZoomLevels) && (confProps.maxZoomLevel) ) {
confProps.numZoomLevels = confProps.maxZoomLevel + 1;
}
// First off, we take whatever hodge-podge of values we have and
//  calculate/distill them down into a resolutions[] array
//
if ((confProps.scales != null) || (confProps.resolutions != null)) {
//preset levels
if (confProps.scales != null) {
confProps.resolutions = [];
for(var i = 0; i < confProps.scales.length; i++) {
var scale = confProps.scales[i];
confProps.resolutions[i] =
OpenLayers.Util.getResolutionFromScale(scale,
confProps.units);
}
}
confProps.numZoomLevels = confProps.resolutions.length;
} else {
//maxResolution and numZoomLevels based calculation
// determine maxResolution
if (confProps.minScale) {
confProps.maxResolution =
OpenLayers.Util.getResolutionFromScale(confProps.minScale,
confProps.units);
} else if (confProps.maxResolution == "auto") {
var viewSize = this.map.getSize();
var wRes = confProps.maxExtent.getWidth() / viewSize.w;
var hRes = confProps.maxExtent.getHeight()/ viewSize.h;
confProps.maxResolution = Math.max(wRes, hRes);
}
// determine minResolution
if (confProps.maxScale != null) {
confProps.minResolution =
OpenLayers.Util.getResolutionFromScale(confProps.maxScale,
confProps.units);
} else if ( (confProps.minResolution == "auto") &&
(confProps.minExtent != null) ) {
var viewSize = this.map.getSize();
var wRes = confProps.minExtent.getWidth() / viewSize.w;
var hRes = confProps.minExtent.getHeight()/ viewSize.h;
confProps.minResolution = Math.max(wRes, hRes);
}
// determine numZoomLevels if not already set on the layer
// this gives numZoomLevels assuming approximately base 2 scaling
if (confProps.minResolution != null &&
this.options.numZoomLevels == undefined) {
var ratio = confProps.maxResolution / confProps.minResolution;
confProps.numZoomLevels =
Math.floor(Math.log(ratio) / Math.log(2)) + 1;
}
// now we have numZoomLevels and maxResolution,
//  we can populate the resolutions array
confProps.resolutions = new Array(confProps.numZoomLevels);
var base = 2;
if(typeof confProps.minResolution == "number" &&
confProps.numZoomLevels > 1) {
/**
* If maxResolution and minResolution are set (or related
* scale properties), we calculate the base for exponential
* scaling that starts at maxResolution and ends at
* minResolution in numZoomLevels steps.
*/
base = Math.pow(
(confProps.maxResolution / confProps.minResolution),
(1 / (confProps.numZoomLevels - 1))
);
}
for (var i=0; i < confProps.numZoomLevels; i++) {
var res = confProps.maxResolution / Math.pow(base, i);
confProps.resolutions[i] = res;
}
}
//sort resolutions array ascendingly
//
confProps.resolutions.sort( function(a, b) { return(b-a); } );
// now set our newly calculated values back to the layer
//  Note: We specifically do *not* set them to layer.options, which we
//        will preserve as it was when we added this layer to the map.
//        this way cloned layers reset themselves to new map div
//        dimensions)
//
this.resolutions = confProps.resolutions;
this.maxResolution = confProps.resolutions[0];
var lastIndex = confProps.resolutions.length - 1;
this.minResolution = confProps.resolutions[lastIndex];
this.scales = [];
for(var i = 0; i < confProps.resolutions.length; i++) {
this.scales[i] =
OpenLayers.Util.getScaleFromResolution(confProps.resolutions[i],
confProps.units);
}
this.minScale = this.scales[0];
this.maxScale = this.scales[this.scales.length - 1];
this.numZoomLevels = confProps.numZoomLevels;
},
/**
* APIMethod: getResolution
*
* Returns:
* {Float} The currently selected resolution of the map, taken from the
*     resolutions array, indexed by current zoom level.
*/
getResolution: function() {
var zoom = this.map.getZoom();
return this.getResolutionForZoom(zoom);
},
/**
* APIMethod: getExtent
*
* Returns:
* {<OpenLayers.Bounds>} A Bounds object which represents the lon/lat
*     bounds of the current viewPort.
*/
getExtent: function() {
// just use stock map calculateBounds function -- passing no arguments
//  means it will user map's current center & resolution
//
return this.map.calculateBounds();
},
/**
* APIMethod: getZoomForExtent
*
* Parameters:
* bounds - {<OpenLayers.Bounds>}
* closest - {Boolean} Find the zoom level that most closely fits the
*     specified bounds. Note that this may result in a zoom that does
*     not exactly contain the entire extent.
*     Default is false.
*
* Returns:
* {Integer} The index of the zoomLevel (entry in the resolutions array)
*     for the passed-in extent. We do this by calculating the ideal
*     resolution for the given extent (based on the map size) and then
*     calling getZoomForResolution(), passing along the 'closest'
*     parameter.
*/
getZoomForExtent: function(extent, closest) {
var viewSize = this.map.getSize();
var idealResolution = Math.max( extent.getWidth()  / viewSize.w,
extent.getHeight() / viewSize.h );
return this.getZoomForResolution(idealResolution, closest);
},
/**
* Method: getDataExtent
* Calculates the max extent which includes all of the data for the layer.
*     This function is to be implemented by subclasses.
*
* Returns:
* {<OpenLayers.Bounds>}
*/
getDataExtent: function () {
//to be implemented by subclasses
},
/**
* APIMethod: getResolutionForZoom
*
* Parameter:
* zoom - {Float}
*
* Returns:
* {Float} A suitable resolution for the specified zoom.
*/
getResolutionForZoom: function(zoom) {
zoom = Math.max(0, Math.min(zoom, this.resolutions.length - 1));
var resolution;
if(this.map.fractionalZoom) {
var low = Math.floor(zoom);
var high = Math.ceil(zoom);
resolution = this.resolutions[high] +
((zoom-low) * (this.resolutions[low]-this.resolutions[high]));
} else {
resolution = this.resolutions[Math.round(zoom)];
}
return resolution;
},
/**
* APIMethod: getZoomForResolution
*
* Parameters:
* resolution - {Float}
* closest - {Boolean} Find the zoom level that corresponds to the absolute
*     closest resolution, which may result in a zoom whose corresponding
*     resolution is actually smaller than we would have desired (if this
*     is being called from a getZoomForExtent() call, then this means that
*     the returned zoom index might not actually contain the entire
*     extent specified... but it'll be close).
*     Default is false.
*
* Returns:
* {Integer} The index of the zoomLevel (entry in the resolutions array)
*     that corresponds to the best fit resolution given the passed in
*     value and the 'closest' specification.
*/
getZoomForResolution: function(resolution, closest) {
var zoom;
if(this.map.fractionalZoom) {
var lowZoom = 0;
var highZoom = this.resolutions.length - 1;
var highRes = this.resolutions[lowZoom];
var lowRes = this.resolutions[highZoom];
var res;
for(var i=0; i<this.resolutions.length; ++i) {
res = this.resolutions[i];
if(res >= resolution) {
highRes = res;
lowZoom = i;
}
if(res <= resolution) {
lowRes = res;
highZoom = i;
break;
}
}
var dRes = highRes - lowRes;
if(dRes > 0) {
zoom = lowZoom + ((resolution - lowRes) / dRes);
} else {
zoom = lowZoom;
}
} else {
var diff;
var minDiff = Number.POSITIVE_INFINITY;
for(var i=0; i < this.resolutions.length; i++) {
if (closest) {
diff = Math.abs(this.resolutions[i] - resolution);
if (diff > minDiff) {
break;
}
minDiff = diff;
} else {
if (this.resolutions[i] < resolution) {
break;
}
}
}
zoom = Math.max(0, i-1);
}
return zoom;
},
/**
* APIMethod: getLonLatFromViewPortPx
*
* Parameters:
* viewPortPx - {<OpenLayers.Pixel>}
*
* Returns:
* {<OpenLayers.LonLat>} An OpenLayers.LonLat which is the passed-in
*     view port <OpenLayers.Pixel>, translated into lon/lat by the layer.
*/
getLonLatFromViewPortPx: function (viewPortPx) {
var lonlat = null;
if (viewPortPx != null) {
var size = this.map.getSize();
var center = this.map.getCenter();
if (center) {
var res  = this.map.getResolution();
var delta_x = viewPortPx.x - (size.w / 2);
var delta_y = viewPortPx.y - (size.h / 2);
lonlat = new OpenLayers.LonLat(center.lon + delta_x * res ,
center.lat - delta_y * res);
if (this.wrapDateLine) {
lonlat = lonlat.wrapDateLine(this.maxExtent);
}
} // else { DEBUG STATEMENT }
}
return lonlat;
},
/**
* APIMethod: getViewPortPxFromLonLat
* Returns a pixel location given a map location.  This method will return
*     fractional pixel values.
*
* Parameters:
* lonlat - {<OpenLayers.LonLat>}
*
* Returns:
* {<OpenLayers.Pixel>} An <OpenLayers.Pixel> which is the passed-in
*     <OpenLayers.LonLat>,translated into view port pixels.
*/
getViewPortPxFromLonLat: function (lonlat) {
var px = null;
if (lonlat != null) {
var resolution = this.map.getResolution();
var extent = this.map.getExtent();
px = new OpenLayers.Pixel(
(1/resolution * (lonlat.lon - extent.left)),
(1/resolution * (extent.top - lonlat.lat))
);
}
return px;
},
/**
* APIMethod: setOpacity
* Sets the opacity for the entire layer (all images)
*
* Parameter:
* opacity - {Float}
*/
setOpacity: function(opacity) {
if (opacity != this.opacity) {
this.opacity = opacity;
for(var i=0; i<this.div.childNodes.length; ++i) {
var element = this.div.childNodes[i].firstChild;
OpenLayers.Util.modifyDOMElement(element, null, null, null,
null, null, null, opacity);
}
}
},
/**
* Method: setZIndex
*
* Parameters:
* zIndex - {Integer}
*/
setZIndex: function (zIndex) {
this.div.style.zIndex = zIndex;
},
/**
* Method: adjustBounds
* This function will take a bounds, and if wrapDateLine option is set
*     on the layer, it will return a bounds which is wrapped around the
*     world. We do not wrap for bounds which *cross* the
*     maxExtent.left/right, only bounds which are entirely to the left
*     or entirely to the right.
*
* Parameters:
* bounds - {<OpenLayers.Bounds>}
*/
adjustBounds: function (bounds) {
if (this.gutter) {
// Adjust the extent of a bounds in map units by the
// layer's gutter in pixels.
var mapGutter = this.gutter * this.map.getResolution();
bounds = new OpenLayers.Bounds(bounds.left - mapGutter,
bounds.bottom - mapGutter,
bounds.right + mapGutter,
bounds.top + mapGutter);
}
if (this.wrapDateLine) {
// wrap around the date line, within the limits of rounding error
var wrappingOptions = {
'rightTolerance':this.getResolution()
};
bounds = bounds.wrapDateLine(this.maxExtent, wrappingOptions);
}
return bounds;
},
CLASS_NAME: "OpenLayers.Layer"
});
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* Class: OpenLayers.Icon
*
* The icon represents a graphical icon on the screen.  Typically used in
* conjunction with a <OpenLayers.Marker> to represent markers on a screen.
*
* An icon has a url, size and position.  It also contains an offset which
* allows the center point to be represented correctly.  This can be
* provided either as a fixed offset or a function provided to calculate
* the desired offset.
*
*/
OpenLayers.Icon = OpenLayers.Class({
/**
* Property: url
* {String}  image url
*/
url: null,
/**
* Property: size
* {<OpenLayers.Size>}
*/
size: null,
/**
* Property: offset
* {<OpenLayers.Pixel>} distance in pixels to offset the image when being rendered
*/
offset: null,
/**
* Property: calculateOffset
* {<OpenLayers.Pixel>} Function to calculate the offset (based on the size)
*/
calculateOffset: null,
/**
* Property: imageDiv
* {DOMElement}
*/
imageDiv: null,
/**
* Property: px
* {<OpenLayers.Pixel>}
*/
px: null,
/**
* Constructor: OpenLayers.Icon
* Creates an icon, which is an image tag in a div.
*
* url - {String}
* size - {<OpenLayers.Size>}
* offset - {<OpenLayers.Pixel>}
* calculateOffset - {Function}
*/
initialize: function(url, size, offset, calculateOffset) {
this.url = url;
this.size = (size) ? size : new OpenLayers.Size(20,20);
this.offset = offset ? offset : new OpenLayers.Pixel(-(this.size.w/2), -(this.size.h/2));
this.calculateOffset = calculateOffset;
var id = OpenLayers.Util.createUniqueID("OL_Icon_");
this.imageDiv = OpenLayers.Util.createAlphaImageDiv(id);
},
/**
* Method: destroy
* Nullify references and remove event listeners to prevent circular
* references and memory leaks
*/
destroy: function() {
OpenLayers.Event.stopObservingElement(this.imageDiv.firstChild);
this.imageDiv.innerHTML = "";
this.imageDiv = null;
},
/**
* Method: clone
*
* Returns:
* {<OpenLayers.Icon>} A fresh copy of the icon.
*/
clone: function() {
return new OpenLayers.Icon(this.url,
this.size,
this.offset,
this.calculateOffset);
},
/**
* Method: setSize
*
* Parameters:
* size - {<OpenLayers.Size>}
*/
setSize: function(size) {
if (size != null) {
this.size = size;
}
this.draw();
},
/**
* Method: setUrl
*
* Parameters:
* url - {String}
*/
setUrl: function(url) {
if (url != null) {
this.url = url;
}
this.draw();
},
/**
* Method: draw
* Move the div to the given pixel.
*
* Parameters:
* px - {<OpenLayers.Pixel>}
*
* Returns:
* {DOMElement} A new DOM Image of this icon set at the location passed-in
*/
draw: function(px) {
OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv,
null,
null,
this.size,
this.url,
"absolute");
this.moveTo(px);
return this.imageDiv;
},
/**
* Method: setOpacity
* Change the icon's opacity
*
* Parameters:
* opacity - {float}
*/
setOpacity: function(opacity) {
OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, null, null,
null, null, null, null, opacity);
},
/**
* Method: moveTo
* move icon to passed in px.
*
* Parameters:
* px - {<OpenLayers.Pixel>}
*/
moveTo: function (px) {
//if no px passed in, use stored location
if (px != null) {
this.px = px;
}
if (this.imageDiv != null) {
if (this.px == null) {
this.display(false);
} else {
if (this.calculateOffset) {
this.offset = this.calculateOffset(this.size);
}
var offsetPx = this.px.offset(this.offset);
OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, offsetPx);
}
}
},
/**
* Method: display
* Hide or show the icon
*
* Parameters:
* display - {Boolean}
*/
display: function(display) {
this.imageDiv.style.display = (display) ? "" : "none";
},
CLASS_NAME: "OpenLayers.Icon"
});
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Events.js
* @requires OpenLayers/Icon.js
*/
/**
* Class: OpenLayers.Marker
* Instances of OpenLayers.Marker are a combination of a
* <OpenLayers.LonLat> and an <OpenLayers.Icon>.
*
* Markers are generally added to a special layer called
* <OpenLayers.Layer.Markers>.
*
* Example:
* (code)
* var markers = new OpenLayers.Layer.Markers( "Markers" );
* map.addLayer(markers);
*
* var size = new OpenLayers.Size(10,17);
* var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
* var icon = new OpenLayers.Icon('http://boston.openguides.org/markers/AQUA.png',size,offset);
* markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0),icon));
* markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0),icon.clone()));
*
* (end)
*
* Note that if you pass an icon into the Marker constructor, it will take
* that icon and use it. This means that you should not share icons between
* markers -- you use them once, but you should clone() for any additional
* markers using that same icon.
*/
OpenLayers.Marker = OpenLayers.Class({
/**
* Property: icon
* {<OpenLayers.Icon>} The icon used by this marker.
*/
icon: null,
/**
* Property: lonlat
* {<OpenLayers.LonLat>} location of object
*/
lonlat: null,
/**
* Property: events
* {<OpenLayers.Events>} the event handler.
*/
events: null,
/**
* Property: map
* {<OpenLayers.Map>} the map this marker is attached to
*/
map: null,
/**
* Constructor: OpenLayers.Marker
* Paraemeters:
* icon - {<OpenLayers.Icon>}  the icon for this marker
* lonlat - {<OpenLayers.LonLat>} the position of this marker
*/
initialize: function(lonlat, icon) {
this.lonlat = lonlat;
var newIcon = (icon) ? icon : OpenLayers.Marker.defaultIcon();
if (this.icon == null) {
this.icon = newIcon;
} else {
this.icon.url = newIcon.url;
this.icon.size = newIcon.size;
this.icon.offset = newIcon.offset;
this.icon.calculateOffset = newIcon.calculateOffset;
}
this.events = new OpenLayers.Events(this, this.icon.imageDiv, null);
},
/**
* APIMethod: destroy
* Destroy the marker. You must first remove the marker from any
* layer which it has been added to, or you will get buggy behavior.
* (This can not be done within the marker since the marker does not
* know which layer it is attached to.)
*/
destroy: function() {
this.map = null;
this.events.destroy();
this.events = null;
if (this.icon != null) {
this.icon.destroy();
this.icon = null;
}
},
/**
* Method: draw
* Calls draw on the icon, and returns that output.
*
* Parameters:
* px - {<OpenLayers.Pixel>}
*
* Returns:
* {DOMElement} A new DOM Image with this marker's icon set at the
* location passed-in
*/
draw: function(px) {
return this.icon.draw(px);
},
/**
* Method: moveTo
* Move the marker to the new location.
*
* Parameters:
* px - {<OpenLayers.Pixel>} the pixel position to move to
*/
moveTo: function (px) {
if ((px != null) && (this.icon != null)) {
this.icon.moveTo(px);
}
this.lonlat = this.map.getLonLatFromLayerPx(px);
},
/**
* Method: onScreen
*
* Returns:
* {Boolean} Whether or not the marker is currently visible on screen.
*/
onScreen:function() {
var onScreen = false;
if (this.map) {
var screenBounds = this.map.getExtent();
onScreen = screenBounds.containsLonLat(this.lonlat);
}
return onScreen;
},
/**
* Method: inflate
* Englarges the markers icon by the specified ratio.
*
* Parameters:
* inflate - {float} the ratio to enlarge the marker by (passing 2
*                   will double the size).
*/
inflate: function(inflate) {
if (this.icon) {
var newSize = new OpenLayers.Size(this.icon.size.w * inflate,
this.icon.size.h * inflate);
this.icon.setSize(newSize);
}
},
/**
* Method: setOpacity
* Change the opacity of the marker by changin the opacity of
*   its icon
*
* Parameters:
* opacity - {float}  Specified as fraction (0.4, etc)
*/
setOpacity: function(opacity) {
this.icon.setOpacity(opacity);
},
/**
* Method: setUrl
* Change URL of the Icon Image.
*
* url - {String}
*/
setUrl: function(url) {
this.icon.setUrl(url);
},
/**
* Method: display
* Hide or show the icon
*
* display - {Boolean}
*/
display: function(display) {
this.icon.display(display);
},
CLASS_NAME: "OpenLayers.Marker"
});
/**
* Function: defaultIcon
* Creates a default <OpenLayers.Icon>.
*
* Returns:
* {<OpenLayers.Icon>} A default OpenLayers.Icon to use for a marker
*/
OpenLayers.Marker.defaultIcon = function() {
var url = OpenLayers.Util.getImagesLocation() + "marker.png";
var size = new OpenLayers.Size(26, 50);
var calculateOffset = function(size) {
return new OpenLayers.Pixel(-(size.w/2), -size.h);
};
return new OpenLayers.Icon(url, size, null, calculateOffset);
};
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Marker.js
*/
/**
* Class: OpenLayers.Marker.Box
*
* Inherits from:
*  - <OpenLayers.Marker>
*/
OpenLayers.Marker.Box = OpenLayers.Class(OpenLayers.Marker, {
/**
* Property: bounds
* {<OpenLayers.Bounds>}
*/
bounds: null,
/**
* Property: div
* {DOMElement}
*/
div: null,
/**
* Constructor: OpenLayers.Marker.Box
*
* Parameters:
* bounds - {<OpenLayers.Bounds>}
* borderColor - {String}
* borderWidth - {int}
*/
initialize: function(bounds, borderColor, borderWidth) {
this.bounds = bounds;
this.div    = OpenLayers.Util.createDiv();
this.div.style.overflow = 'hidden';
this.events = new OpenLayers.Events(this, this.div, null);
this.setBorder(borderColor, borderWidth);
},
/**
* Method: destroy
*/
destroy: function() {
this.bounds = null;
this.div = null;
OpenLayers.Marker.prototype.destroy.apply(this, arguments);
},
/**
* Method: setBorder
* Allow the user to change the box's color and border width
*
* Parameters:
* color - {String} Default is "red"
* width - {int} Default is 2
*/
setBorder: function (color, width) {
if (!color) {
color = "red";
}
if (!width) {
width = 2;
}
this.div.style.border = width + "px solid " + color;
},
/**
* Method: draw
*
* Parameters:
* px - {<OpenLayers.Pixel>}
* sz - {<OpenLayers.Size>}
*
* Returns:
* {DOMElement} A new DOM Image with this marker´s icon set at the
*         location passed-in
*/
draw: function(px, sz) {
OpenLayers.Util.modifyDOMElement(this.div, null, px, sz);
return this.div;
},
/**
* Method: onScreen
*
* Rreturn:
* {Boolean} Whether or not the marker is currently visible on screen.
*/
onScreen:function() {
var onScreen = false;
if (this.map) {
var screenBounds = this.map.getExtent();
onScreen = screenBounds.containsBounds(this.bounds, true, true);
}
return onScreen;
},
/**
* Method: display
* Hide or show the icon
*
* Parameters:
* display - {Boolean}
*/
display: function(display) {
this.div.style.display = (display) ? "" : "none";
},
CLASS_NAME: "OpenLayers.Marker.Box"
});
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* Class: OpenLayers.Popup
* A popup is a small div that can opened and closed on the map.
* Typically opened in response to clicking on a marker.
* See <OpenLayers.Marker>.  Popup's don't require their own
* layer and are added the the map using the <OpenLayers.Map.addPopup>
* method.
*
* Example:
* (code)
* popup = new OpenLayers.Popup("chicken",
*                    new OpenLayers.LonLat(5,40),
*                    new OpenLayers.Size(200,200),
*                    "example popup",
*                    true);
*
* map.addPopup(popup);
* (end)
*/
OpenLayers.Popup = OpenLayers.Class({
/**
* Property: events
* {<OpenLayers.Events>} custom event manager
*/
events: null,
/** Property: id
* {String} the unique identifier assigned to this popup.
*/
id: "",
/**
* Property: lonlat
* {<OpenLayers.LonLat>} the position of this popup on the map
*/
lonlat: null,
/**
* Property: div
* {DOMElement} the div that contains this popup.
*/
div: null,
/**
* Property: size
* {<OpenLayers.Size>} the width and height of the popup.
*/
size: null,
/**
* Property: contentHTML
* {String} The HTML that this popup displays.
*/
contentHTML: "",
/**
* Property: backgroundColor
* {String} the background color used by the popup.
*/
backgroundColor: "",
/**
* Property: opacity
* {float} the opacity of this popup (between 0.0 and 1.0)
*/
opacity: "",
/**
* Property: border
* {String} the border size of the popup.  (eg 2px)
*/
border: "",
/**
* Property: contentDiv
* {DOMElement} a reference to the element that holds the content of
*              the div.
*/
contentDiv: null,
/**
* Property: groupDiv
* {DOMElement} First and only child of 'div'. The group Div contains the
*     'contentDiv' and the 'closeDiv'.
*/
groupDiv: null,
/**
* Property: closeDiv
* {DOMElement} the optional closer image
*/
closeDiv: null,
/**
* APIProperty: autoSize
* {Boolean} Resize the popup to auto-fit the contents.
*     Default is false.
*/
autoSize: false,
/**
* APIProperty: minSize
* {<OpenLayers.Size>} Minimum size allowed for the popup's contents.
*/
minSize: null,
/**
* APIProperty: maxSize
* {<OpenLayers.Size>} Maximum size allowed for the popup's contents.
*/
maxSize: null,
/**
* Property: padding
* {int or <OpenLayers.Bounds>} An extra opportunity to specify internal
*     padding of the content div inside the popup. This was originally
*     confused with the css padding as specified in style.css's
*     'olPopupContent' class. We would like to get rid of this altogether,
*     except that it does come in handy for the framed and anchoredbubble
*     popups, who need to maintain yet another barrier between their
*     content and the outer border of the popup itself.
*
*     Note that in order to not break API, we must continue to support
*     this property being set as an integer. Really, though, we'd like to
*     have this specified as a Bounds object so that user can specify
*     distinct left, top, right, bottom paddings. With the 3.0 release
*     we can make this only a bounds.
*/
padding: 0,
/**
* Method: fixPadding
* To be removed in 3.0, this function merely helps us to deal with the
*     case where the user may have set an integer value for padding,
*     instead of an <OpenLayers.Bounds> object.
*/
fixPadding: function() {
if (typeof this.padding == "number") {
this.padding = new OpenLayers.Bounds(
this.padding, this.padding, this.padding, this.padding
);
}
},
/**
* APIProperty: panMapIfOutOfView
* {Boolean} When drawn, pan map such that the entire popup is visible in
*     the current viewport (if necessary).
*     Default is false.
*/
panMapIfOutOfView: false,
/**
* Property: map
* {<OpenLayers.Map>} this gets set in Map.js when the popup is added to the map
*/
map: null,
/**
* Constructor: OpenLayers.Popup
* Create a popup.
*
* Parameters:
* id - {String} a unqiue identifier for this popup.  If null is passed
*               an identifier will be automatically generated.
* lonlat - {<OpenLayers.LonLat>}  The position on the map the popup will
*                                 be shown.
* size - {<OpenLayers.Size>}      The size of the popup.
* contentHTML - {String}          The HTML content to display inside the
*                                 popup.
* closeBox - {Boolean}            Whether to display a close box inside
*                                 the popup.
* closeBoxCallback - {Function}   Function to be called on closeBox click.
*/
initialize:function(id, lonlat, size, contentHTML, closeBox, closeBoxCallback) {
if (id == null) {
id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
}
this.id = id;
this.lonlat = lonlat;
this.size = (size != null) ? size
: new OpenLayers.Size(
OpenLayers.Popup.WIDTH,
OpenLayers.Popup.HEIGHT);
if (contentHTML != null) {
this.contentHTML = contentHTML;
}
this.backgroundColor = OpenLayers.Popup.COLOR;
this.opacity = OpenLayers.Popup.OPACITY;
this.border = OpenLayers.Popup.BORDER;
this.div = OpenLayers.Util.createDiv(this.id, null, null,
null, null, null, "hidden");
this.div.className = 'olPopup';
var groupDivId = this.id + "_GroupDiv";
this.groupDiv = OpenLayers.Util.createDiv(groupDivId, null, null,
null, "relative", null,
"hidden");
var id = this.div.id + "_contentDiv";
this.contentDiv = OpenLayers.Util.createDiv(id, null, this.size.clone(),
null, "relative");
this.contentDiv.className = 'olPopupContent';
this.groupDiv.appendChild(this.contentDiv);
this.div.appendChild(this.groupDiv);
if (closeBox) {
this.addCloseBox(closeBoxCallback);
}
this.registerEvents();
},
/**
* Method: destroy
* nullify references to prevent circular references and memory leaks
*/
destroy: function() {
this.id = null;
this.lonlat = null;
this.size = null;
this.contentHTML = null;
this.backgroundColor = null;
this.opacity = null;
this.border = null;
this.events.destroy();
this.events = null;
if (this.closeDiv) {
OpenLayers.Event.stopObservingElement(this.closeDiv);
this.groupDiv.removeChild(this.closeDiv);
}
this.closeDiv = null;
this.div.removeChild(this.groupDiv);
this.groupDiv = null;
if (this.map != null) {
this.map.removePopup(this);
}
this.map = null;
this.div = null;
this.autoSize = null;
this.minSize = null;
this.maxSize = null;
this.padding = null;
this.panMapIfOutOfView = null;
},
/**
* Method: draw
* Constructs the elements that make up the popup.
*
* Parameters:
* px - {<OpenLayers.Pixel>} the position the popup in pixels.
*
* Returns:
* {DOMElement} Reference to a div that contains the drawn popup
*/
draw: function(px) {
if (px == null) {
if ((this.lonlat != null) && (this.map != null)) {
px = this.map.getLayerPxFromLonLat(this.lonlat);
}
}
//listen to movestart, moveend to disable overflow (FF bug)
if (OpenLayers.Util.getBrowserName() == 'firefox') {
this.map.events.register("movestart", this, function() {
var style = document.defaultView.getComputedStyle(
this.contentDiv, null
);
var currentOverflow = style.getPropertyValue("overflow");
if (currentOverflow != "hidden") {
this.contentDiv._oldOverflow = currentOverflow;
this.contentDiv.style.overflow = "hidden";
}
});
this.map.events.register("moveend", this, function() {
var oldOverflow = this.contentDiv._oldOverflow;
if (oldOverflow) {
this.contentDiv.style.overflow = oldOverflow;
this.contentDiv._oldOverflow = null;
}
});
}
this.moveTo(px);
if (!this.autoSize) {
this.setSize(this.size);
}
this.setBackgroundColor();
this.setOpacity();
this.setBorder();
this.setContentHTML();
if (this.panMapIfOutOfView) {
this.panIntoView();
}
return this.div;
},
/**
* Method: updatePosition
* if the popup has a lonlat and its map members set,
* then have it move itself to its proper position
*/
updatePosition: function() {
if ((this.lonlat) && (this.map)) {
var px = this.map.getLayerPxFromLonLat(this.lonlat);
if (px) {
this.moveTo(px);
}
}
},
/**
* Method: moveTo
*
* Parameters:
* px - {<OpenLayers.Pixel>} the top and left position of the popup div.
*/
moveTo: function(px) {
if ((px != null) && (this.div != null)) {
this.div.style.left = px.x + "px";
this.div.style.top = px.y + "px";
}
},
/**
* Method: visible
*
* Returns:
* {Boolean} Boolean indicating whether or not the popup is visible
*/
visible: function() {
return OpenLayers.Element.visible(this.div);
},
/**
* Method: toggle
* Toggles visibility of the popup.
*/
toggle: function() {
if (this.visible()) {
this.hide();
} else {
this.show();
}
},
/**
* Method: show
* Makes the popup visible.
*/
show: function() {
OpenLayers.Element.show(this.div);
if (this.panMapIfOutOfView) {
this.panIntoView();
}
},
/**
* Method: hide
* Makes the popup invisible.
*/
hide: function() {
OpenLayers.Element.hide(this.div);
},
/**
* Method: setSize
* Used to adjust the size of the popup.
*
* Parameters:
* size - {<OpenLayers.Size>} the new size of the popup's contents div
*     (in pixels).
*/
setSize:function(size) {
this.size = size;
var contentSize = this.size.clone();
// if our contentDiv has a css 'padding' set on it by a stylesheet, we
//  must add that to the desired "size".
var contentDivPadding = this.getContentDivPadding();
var wPadding = contentDivPadding.left + contentDivPadding.right;
var hPadding = contentDivPadding.top + contentDivPadding.bottom;
// take into account the popup's 'padding' property
this.fixPadding();
wPadding += this.padding.left + this.padding.right;
hPadding += this.padding.top + this.padding.bottom;
// make extra space for the close div
if (this.closeDiv) {
var closeDivWidth = parseInt(this.closeDiv.style.width);
wPadding += closeDivWidth + contentDivPadding.right;
}
//increase size of the main popup div to take into account the
// users's desired padding and close div.
this.size.w += wPadding;
this.size.h += hPadding;
//now if our browser is IE, we need to actually make the contents
// div itself bigger to take its own padding into effect. this makes
// me want to shoot someone, but so it goes.
if (OpenLayers.Util.getBrowserName() == "msie") {
contentSize.w += contentDivPadding.left + contentDivPadding.right;
contentSize.h += contentDivPadding.bottom + contentDivPadding.top;
}
if (this.div != null) {
this.div.style.width = this.size.w + "px";
this.div.style.height = this.size.h + "px";
}
if (this.contentDiv != null){
this.contentDiv.style.width = contentSize.w + "px";
this.contentDiv.style.height = contentSize.h + "px";
}
},
/**
* Method: setBackgroundColor
* Sets the background color of the popup.
*
* Parameters:
* color - {String} the background color.  eg "#FFBBBB"
*/
setBackgroundColor:function(color) {
if (color != undefined) {
this.backgroundColor = color;
}
if (this.div != null) {
this.div.style.backgroundColor = this.backgroundColor;
}
},
/**
* Method: setOpacity
* Sets the opacity of the popup.
*
* Parameters:
* opacity - {float} A value between 0.0 (transparent) and 1.0 (solid).
*/
setOpacity:function(opacity) {
if (opacity != undefined) {
this.opacity = opacity;
}
if (this.div != null) {
// for Mozilla and Safari
this.div.style.opacity = this.opacity;
// for IE
this.div.style.filter = 'alpha(opacity=' + this.opacity*100 + ')';
}
},
/**
* Method: setBorder
* Sets the border style of the popup.
*
* Parameters:
* border - {String} The border style value. eg 2px
*/
setBorder:function(border) {
if (border != undefined) {
this.border = border;
}
if (this.div != null) {
this.div.style.border = this.border;
}
},
/**
* Method: setContentHTML
* Allows the user to set the HTML content of the popup.
*
* Parameters:
* contentHTML - {String} HTML for the div.
*/
setContentHTML:function(contentHTML) {
if (contentHTML != null) {
this.contentHTML = contentHTML;
}
if (this.autoSize) {
// determine actual render dimensions of the contents
var realSize =
OpenLayers.Util.getRenderedDimensions(this.contentHTML);
// is the "real" size of the div is safe to display in our map?
var safeSize = this.getSafeContentSize(realSize);
var newSize = null;
if (safeSize.equals(realSize)) {
//real size of content is small enough to fit on the map,
// so we use real size.
newSize = realSize;
} else {
//make a new OL.Size object with the clipped dimensions
// set or null if not clipped.
var fixedSize = new OpenLayers.Size();
fixedSize.w = (safeSize.w < realSize.w) ? safeSize.w : null;
fixedSize.h = (safeSize.h < realSize.h) ? safeSize.h : null;
if (fixedSize.w && fixedSize.h) {
//content is too big in both directions, so we will use
// max popup size (safeSize), knowing well that it will
// overflow both ways.
newSize = safeSize;
} else {
//content is clipped in only one direction, so we need to
// run getRenderedDimensions() again with a fixed dimension
var clippedSize = OpenLayers.Util.getRenderedDimensions(
this.contentHTML, fixedSize
);
//if the clipped size is still the same as the safeSize,
// that means that our content must be fixed in the
// offending direction. If overflow is 'auto', this means
// we are going to have a scrollbar for sure, so we must
// adjust for that.
//
var currentOverflow = OpenLayers.Element.getStyle(
this.contentDiv, "overflow"
);
if ( (currentOverflow != "hidden") &&
(clippedSize.equals(safeSize)) ) {
var scrollBar = OpenLayers.Util.getScrollbarWidth();
if (fixedSize.w) {
clippedSize.h += scrollBar;
} else {
clippedSize.w += scrollBar;
}
}
newSize = this.getSafeContentSize(clippedSize);
}
}
this.setSize(newSize);
}
if (this.contentDiv != null) {
this.contentDiv.innerHTML = this.contentHTML;
}
},
/**
* APIMethod: getSafeContentSize
*
* Parameters:
* size - {<OpenLayers.Size>} Desired size to make the popup.
*
* Returns:
* {<OpenLayers.Size>} A size to make the popup which is neither smaller
*     than the specified minimum size, nor bigger than the maximum
*     size (which is calculated relative to the size of the viewport).
*/
getSafeContentSize: function(size) {
var safeContentSize = size.clone();
// if our contentDiv has a css 'padding' set on it by a stylesheet, we
//  must add that to the desired "size".
var contentDivPadding = this.getContentDivPadding();
var wPadding = contentDivPadding.left + contentDivPadding.right;
var hPadding = contentDivPadding.top + contentDivPadding.bottom;
// take into account the popup's 'padding' property
this.fixPadding();
wPadding += this.padding.left + this.padding.right;
hPadding += this.padding.top + this.padding.bottom;
if (this.closeDiv) {
var closeDivWidth = parseInt(this.closeDiv.style.width);
wPadding += closeDivWidth + contentDivPadding.right;
}
// prevent the popup from being smaller than a specified minimal size
if (this.minSize) {
safeContentSize.w = Math.max(safeContentSize.w,
(this.minSize.w - wPadding));
safeContentSize.h = Math.max(safeContentSize.h,
(this.minSize.h - hPadding));
}
// prevent the popup from being bigger than a specified maximum size
if (this.maxSize) {
safeContentSize.w = Math.min(safeContentSize.w,
(this.maxSize.w - wPadding));
safeContentSize.h = Math.min(safeContentSize.h,
(this.maxSize.h - hPadding));
}
//make sure the desired size to set doesn't result in a popup that
// is bigger than the map's viewport.
//
if (this.map && this.map.size) {
// Note that there *was* a reference to a
// 'OpenLayers.Popup.SCROLL_BAR_WIDTH' constant here, with special
// tolerance for it and everything... but it was never defined in
// the first place, so I don't know what to think.
var maxY = this.map.size.h -
this.map.paddingForPopups.top -
this.map.paddingForPopups.bottom -
hPadding;
var maxX = this.map.size.w -
this.map.paddingForPopups.left -
this.map.paddingForPopups.right -
wPadding;
safeContentSize.w = Math.min(safeContentSize.w, maxX);
safeContentSize.h = Math.min(safeContentSize.h, maxY);
}
return safeContentSize;
},
/**
* Method: getContentDivPadding
* Glorious, oh glorious hack in order to determine the css 'padding' of
*     the contentDiv. IE/Opera return null here unless we actually add the
*     popup's main 'div' element (which contains contentDiv) to the DOM.
*     So we make it invisible and then add it to the document temporarily.
*
*     Once we've taken the padding readings we need, we then remove it
*     from the DOM (it will actually get added to the DOM in
*     Map.js's addPopup)
*
* Returns:
* {<OpenLayers.Bounds>}
*/
getContentDivPadding: function() {
//use cached value if we have it
var contentDivPadding = this._contentDivPadding;
if (!contentDivPadding) {
//make the div invisible and add it to the page
this.div.style.display = "none";
document.body.appendChild(this.div);
//read the padding settings from css, put them in an OL.Bounds
contentDivPadding = new OpenLayers.Bounds(
OpenLayers.Element.getStyle(this.contentDiv, "padding-left"),
OpenLayers.Element.getStyle(this.contentDiv, "padding-bottom"),
OpenLayers.Element.getStyle(this.contentDiv, "padding-right"),
OpenLayers.Element.getStyle(this.contentDiv, "padding-top")
);
//cache the value
this._contentDivPadding = contentDivPadding;
//remove the div from the page and make it visible again
document.body.removeChild(this.div);
this.div.style.display = "";
}
return contentDivPadding;
},
/**
* Method: addCloseBox
*
* Parameters:
* callback - {Function} The callback to be called when the close button
*     is clicked.
*/
addCloseBox: function(callback) {
this.closeDiv = OpenLayers.Util.createDiv(
this.id + "_close", null, new OpenLayers.Size(17, 17)
);
this.closeDiv.className = "olPopupCloseBox";
// use the content div's css padding to determine if we should
//  padd the close div
var contentDivPadding = this.getContentDivPadding();
this.closeDiv.style.right = contentDivPadding.right + "px";
this.closeDiv.style.top = contentDivPadding.top + "px";
this.groupDiv.appendChild(this.closeDiv);
var closePopup = callback || function(e) {
this.hide();
OpenLayers.Event.stop(e);
};
OpenLayers.Event.observe(this.closeDiv, "click",
OpenLayers.Function.bindAsEventListener(closePopup, this));
},
/**
* Method: panIntoView
* Pans the map such that the popup is totaly viewable (if necessary)
*/
panIntoView: function() {
var mapSize = this.map.getSize();
//start with the top left corner of the popup, in px,
// relative to the viewport
var origTL = this.map.getViewPortPxFromLayerPx( new OpenLayers.Pixel(
parseInt(this.div.style.left),
parseInt(this.div.style.top)
));
var newTL = origTL.clone();
//new left (compare to margins, using this.size to calculate right)
if (origTL.x < this.map.paddingForPopups.left) {
newTL.x = this.map.paddingForPopups.left;
} else
if ( (origTL.x + this.size.w) > (mapSize.w - this.map.paddingForPopups.right)) {
newTL.x = mapSize.w - this.map.paddingForPopups.right - this.size.w;
}
//new top (compare to margins, using this.size to calculate bottom)
if (origTL.y < this.map.paddingForPopups.top) {
newTL.y = this.map.paddingForPopups.top;
} else
if ( (origTL.y + this.size.h) > (mapSize.h - this.map.paddingForPopups.bottom)) {
newTL.y = mapSize.h - this.map.paddingForPopups.bottom - this.size.h;
}
var dx = origTL.x - newTL.x;
var dy = origTL.y - newTL.y;
this.map.pan(dx, dy);
},
/**
* Method: registerEvents
* Registers events on the popup.
*
* Do this in a separate function so that subclasses can
*   choose to override it if they wish to deal differently
*   with mouse events
*
*   Note in the following handler functions that some special
*    care is needed to deal correctly with mousing and popups.
*
*   Because the user might select the zoom-rectangle option and
*    then drag it over a popup, we need a safe way to allow the
*    mousemove and mouseup events to pass through the popup when
*    they are initiated from outside.
*
*   Otherwise, we want to essentially kill the event propagation
*    for all other events, though we have to do so carefully,
*    without disabling basic html functionality, like clicking on
*    hyperlinks or drag-selecting text.
*/
registerEvents:function() {
this.events = new OpenLayers.Events(this, this.div, null, true);
this.events.on({
"mousedown": this.onmousedown,
"mousemove": this.onmousemove,
"mouseup": this.onmouseup,
"click": this.onclick,
"mouseout": this.onmouseout,
"dblclick": this.ondblclick,
scope: this
});
},
/**
* Method: onmousedown
* When mouse goes down within the popup, make a note of
*   it locally, and then do not propagate the mousedown
*   (but do so safely so that user can select text inside)
*
* Parameters:
* evt - {Event}
*/
onmousedown: function (evt) {
this.mousedown = true;
OpenLayers.Event.stop(evt, true);
},
/**
* Method: onmousemove
* If the drag was started within the popup, then
*   do not propagate the mousemove (but do so safely
*   so that user can select text inside)
*
* Parameters:
* evt - {Event}
*/
onmousemove: function (evt) {
if (this.mousedown) {
OpenLayers.Event.stop(evt, true);
}
},
/**
* Method: onmouseup
* When mouse comes up within the popup, after going down
*   in it, reset the flag, and then (once again) do not
*   propagate the event, but do so safely so that user can
*   select text inside
*
* Parameters:
* evt - {Event}
*/
onmouseup: function (evt) {
if (this.mousedown) {
this.mousedown = false;
OpenLayers.Event.stop(evt, true);
}
},
/**
* Method: onclick
* Ignore clicks, but allowing default browser handling
*
* Parameters:
* evt - {Event}
*/
onclick: function (evt) {
OpenLayers.Event.stop(evt, true);
},
/**
* Method: onmouseout
* When mouse goes out of the popup set the flag to false so that
*   if they let go and then drag back in, we won't be confused.
*
* Parameters:
* evt - {Event}
*/
onmouseout: function (evt) {
this.mousedown = false;
},
/**
* Method: ondblclick
* Ignore double-clicks, but allowing default browser handling
*
* Parameters:
* evt - {Event}
*/
ondblclick: function (evt) {
OpenLayers.Event.stop(evt, true);
},
CLASS_NAME: "OpenLayers.Popup"
});
OpenLayers.Popup.WIDTH = 200;
OpenLayers.Popup.HEIGHT = 200;
OpenLayers.Popup.COLOR = "white";
OpenLayers.Popup.OPACITY = 1;
OpenLayers.Popup.BORDER = "0px";
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/*
* @requires OpenLayers/Util.js
*/
/*
* Class: OpenLayers.Tile
* This is a class designed to designate a single tile, however
*     it is explicitly designed to do relatively little. Tiles store
*     information about themselves -- such as the URL that they are related
*     to, and their size - but do not add themselves to the layer div
*     automatically, for example. Create a new tile with the
*     <OpenLayers.Tile> constructor, or a subclass.
*
* TBD 3.0 - remove reference to url in above paragraph
*
*/
OpenLayers.Tile = OpenLayers.Class({
/**
* Constant: EVENT_TYPES
* {Array(String)} Supported application event types
*/
EVENT_TYPES: [ "loadstart", "loadend", "reload", "unload"],
/**
* APIProperty: events
* {<OpenLayers.Events>} An events object that handles all
*                       events on the tile.
*/
events: null,
/**
* Property: id
* {String} null
*/
id: null,
/**
* Property: layer
* {<OpenLayers.Layer>} layer the tile is attached to
*/
layer: null,
/**
* Property: url
* {String} url of the request.
*
* TBD 3.0
* Deprecated. The base tile class does not need an url. This should be
* handled in subclasses. Does not belong here.
*/
url: null,
/**
* APIProperty: bounds
* {<OpenLayers.Bounds>} null
*/
bounds: null,
/**
* Property: size
* {<OpenLayers.Size>} null
*/
size: null,
/**
* Property: position
* {<OpenLayers.Pixel>} Top Left pixel of the tile
*/
position: null,
/**
* Property: isLoading
* {Boolean} Is the tile loading?
*/
isLoading: false,
/**
* Property: isBackBuffer
* {Boolean} Is this tile a back buffer tile?
*/
isBackBuffer: false,
/**
* Property: lastRatio
* {Float} Used in transition code only.  This is the previous ratio
*     of the back buffer tile resolution to the map resolution.  Compared
*     with the current ratio to determine if zooming occurred.
*/
lastRatio: 1,
/**
* Property: isFirstDraw
* {Boolean} Is this the first time the tile is being drawn?
*     This is used to force resetBackBuffer to synchronize
*     the backBufferTile with the foreground tile the first time
*     the foreground tile loads so that if the user zooms
*     before the layer has fully loaded, the backBufferTile for
*     tiles that have been loaded can be used.
*/
isFirstDraw: true,
/**
* Property: backBufferTile
* {<OpenLayers.Tile>} A clone of the tile used to create transition
*     effects when the tile is moved or changes resolution.
*/
backBufferTile: null,
/** TBD 3.0 -- remove 'url' from the list of parameters to the constructor.
*             there is no need for the base tile class to have a url.
*
* Constructor: OpenLayers.Tile
* Constructor for a new <OpenLayers.Tile> instance.
*
* Parameters:
* layer - {<OpenLayers.Layer>} layer that the tile will go in.
* position - {<OpenLayers.Pixel>}
* bounds - {<OpenLayers.Bounds>}
* url - {<String>}
* size - {<OpenLayers.Size>}
*/
initialize: function(layer, position, bounds, url, size) {
this.layer = layer;
this.position = position.clone();
this.bounds = bounds.clone();
this.url = url;
this.size = size.clone();
//give the tile a unique id based on its BBOX.
this.id = OpenLayers.Util.createUniqueID("Tile_");
this.events = new OpenLayers.Events(this, null, this.EVENT_TYPES);
},
/**
* Method: unload
* Call immediately before destroying if you are listening to tile
* events, so that counters are properly handled if tile is still
* loading at destroy-time. Will only fire an event if the tile is
* still loading.
*/
unload: function() {
if (this.isLoading) {
this.isLoading = false;
this.events.triggerEvent("unload");
}
},
/**
* APIMethod: destroy
* Nullify references to prevent circular references and memory leaks.
*/
destroy:function() {
if (OpenLayers.Util.indexOf(this.layer.SUPPORTED_TRANSITIONS,
this.layer.transitionEffect) != -1) {
this.layer.events.unregister("loadend", this, this.resetBackBuffer);
this.events.unregister('loadend', this, this.resetBackBuffer);
} else {
this.events.unregister('loadend', this, this.showTile);
}
this.layer  = null;
this.bounds = null;
this.size = null;
this.position = null;
this.events.destroy();
this.events = null;
/* clean up the backBufferTile if it exists */
if (this.backBufferTile) {
this.backBufferTile.destroy();
this.backBufferTile = null;
}
},
/**
* Method: clone
*
* Parameters:
* obj - {<OpenLayers.Tile>} The tile to be cloned
*
* Returns:
* {<OpenLayers.Tile>} An exact clone of this <OpenLayers.Tile>
*/
clone: function (obj) {
if (obj == null) {
obj = new OpenLayers.Tile(this.layer,
this.position,
this.bounds,
this.url,
this.size);
}
// catch any randomly tagged-on properties
OpenLayers.Util.applyDefaults(obj, this);
return obj;
},
/**
* Method: draw
* Clear whatever is currently in the tile, then return whether or not
*     it should actually be re-drawn.
*
* Returns:
* {Boolean} Whether or not the tile should actually be drawn. Note that
*     this is not really the best way of doing things, but such is
*     the way the code has been developed. Subclasses call this and
*     depend on the return to know if they should draw or not.
*/
draw: function() {
var maxExtent = this.layer.maxExtent;
var withinMaxExtent = (maxExtent &&
this.bounds.intersectsBounds(maxExtent, false));
// The only case where we *wouldn't* want to draw the tile is if the
// tile is outside its layer's maxExtent.
var drawTile = (withinMaxExtent || this.layer.displayOutsideMaxExtent);
if (OpenLayers.Util.indexOf(this.layer.SUPPORTED_TRANSITIONS, this.layer.transitionEffect) != -1) {
if (drawTile) {
//we use a clone of this tile to create a double buffer for visual
//continuity.  The backBufferTile is used to create transition
//effects while the tile in the grid is repositioned and redrawn
if (!this.backBufferTile) {
this.backBufferTile = this.clone();
this.backBufferTile.hide();
// this is important.  It allows the backBuffer to place itself
// appropriately in the DOM.  The Image subclass needs to put
// the backBufferTile behind the main tile so the tiles can
// load over top and display as soon as they are loaded.
this.backBufferTile.isBackBuffer = true;
// potentially end any transition effects when the tile loads
this.events.register('loadend', this, this.resetBackBuffer);
// clear transition back buffer tile only after all tiles in
// this layer have loaded to avoid visual glitches
this.layer.events.register("loadend", this, this.resetBackBuffer);
}
// run any transition effects
this.startTransition();
} else {
// if we aren't going to draw the tile, then the backBuffer should
// be hidden too!
if (this.backBufferTile) {
this.backBufferTile.clear();
}
}
} else {
if (drawTile && this.isFirstDraw) {
this.events.register('loadend', this, this.showTile);
this.isFirstDraw = false;
}
}
this.shouldDraw = drawTile;
//clear tile's contents and mark as not drawn
this.clear();
return drawTile;
},
/**
* Method: moveTo
* Reposition the tile.
*
* Parameters:
* bounds - {<OpenLayers.Bounds>}
* position - {<OpenLayers.Pixel>}
* redraw - {Boolean} Call draw method on tile after moving.
*     Default is true
*/
moveTo: function (bounds, position, redraw) {
if (redraw == null) {
redraw = true;
}
this.bounds = bounds.clone();
this.position = position.clone();
if (redraw) {
this.draw();
}
},
/**
* Method: clear
* Clear the tile of any bounds/position-related data so that it can
*     be reused in a new location. To be implemented by subclasses.
*/
clear: function() {
// to be implemented by subclasses
},
/**
* Method: getBoundsFromBaseLayer
* Take the pixel locations of the corner of the tile, and pass them to
*     the base layer and ask for the location of those pixels, so that
*     displaying tiles over Google works fine.
*
* Parameters:
* position - {<OpenLayers.Pixel>}
*
* Returns:
* bounds - {<OpenLayers.Bounds>}
*/
getBoundsFromBaseLayer: function(position) {
var msg = OpenLayers.i18n('reprojectDeprecated',
{'layerName':this.layer.name});
OpenLayers.Console.warn(msg);
var topLeft = this.layer.map.getLonLatFromLayerPx(position);
var bottomRightPx = 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;
}
}
var bounds = new OpenLayers.Bounds(topLeft.lon,
bottomRight.lat,
bottomRight.lon,
topLeft.lat);
return bounds;
},
/**
* Method: startTransition
* Prepare the tile for a transition effect.  To be
*     implemented by subclasses.
*/
startTransition: function() {},
/**
* Method: resetBackBuffer
* Triggered by two different events, layer loadend, and tile loadend.
*     In any of these cases, we check to see if we can hide the
*     backBufferTile yet and update its parameters to match the
*     foreground tile.
*
* Basic logic:
*  - If the backBufferTile hasn't been drawn yet, reset it
*  - If layer is still loading, show foreground tile but don't hide
*    the backBufferTile yet
*  - If layer is done loading, reset backBuffer tile and show
*    foreground tile
*/
resetBackBuffer: function() {
this.showTile();
if (this.backBufferTile &&
(this.isFirstDraw || !this.layer.numLoadingTiles)) {
this.isFirstDraw = false;
// check to see if the backBufferTile is within the max extents
// before rendering it
var maxExtent = this.layer.maxExtent;
var withinMaxExtent = (maxExtent &&
this.bounds.intersectsBounds(maxExtent, false));
if (withinMaxExtent) {
this.backBufferTile.position = this.position;
this.backBufferTile.bounds = this.bounds;
this.backBufferTile.size = this.size;
this.backBufferTile.imageSize = this.layer.imageSize || this.size;
this.backBufferTile.imageOffset = this.layer.imageOffset;
this.backBufferTile.resolution = this.layer.getResolution();
this.backBufferTile.renderTile();
}
}
},
/**
* Method: showTile
* Show the tile only if it should be drawn.
*/
showTile: function() {
if (this.shouldDraw) {
this.show();
}
},
/**
* Method: show
* Show the tile.  To be implemented by subclasses.
*/
show: function() { },
/**
* Method: hide
* Hide the tile.  To be implemented by subclasses.
*/
hide: function() { },
CLASS_NAME: "OpenLayers.Tile"
});
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Tile.js
*/
/**
* Class: OpenLayers.Tile.Image
* Instances of OpenLayers.Tile.Image are used to manage the image tiles
* used by various layers.  Create a new image tile with the
* <OpenLayers.Tile.Image> constructor.
*
* Inherits from:
*  - <OpenLayers.Tile>
*/
OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
/**
* Property: url
* {String} The URL of the image being requested. No default. Filled in by
* layer.getURL() function.
*/
url: null,
/**
* Property: imgDiv
* {DOMElement} The div element which wraps the image.
*/
imgDiv: null,
/**
* Property: frame
* {DOMElement} The image element is appended to the frame.  Any gutter on
* the image will be hidden behind the frame.
*/
frame: null,
/**
* Property: layerAlphaHack
* {Boolean} True if the png alpha hack needs to be applied on the layer's div.
*/
layerAlphaHack: null,
/** TBD 3.0 - reorder the parameters to the init function to remove
*             URL. the getUrl() function on the layer gets called on
*             each draw(), so no need to specify it here.
*
* Constructor: OpenLayers.Tile.Image
* Constructor for a new <OpenLayers.Tile.Image> instance.
*
* Parameters:
* layer - {<OpenLayers.Layer>} layer that the tile will go in.
* position - {<OpenLayers.Pixel>}
* bounds - {<OpenLayers.Bounds>}
* url - {<String>} Deprecated. Remove me in 3.0.
* size - {<OpenLayers.Size>}
*/
initialize: function(layer, position, bounds, url, size) {
OpenLayers.Tile.prototype.initialize.apply(this, arguments);
this.url = url; //deprecated remove me
this.frame = document.createElement('div');
this.frame.style.overflow = 'hidden';
this.frame.style.position = 'absolute';
this.layerAlphaHack = this.layer.alpha && OpenLayers.Util.alphaHack();
},
/**
* APIMethod: destroy
* nullify references to prevent circular references and memory leaks
*/
destroy: function() {
if (this.imgDiv != null)  {
if (this.layerAlphaHack) {
OpenLayers.Event.stopObservingElement(this.imgDiv.childNodes[0].id);
} else {
OpenLayers.Event.stopObservingElement(this.imgDiv.id);
}
if (this.imgDiv.parentNode == this.frame) {
this.frame.removeChild(this.imgDiv);
this.imgDiv.map = null;
}
}
this.imgDiv = null;
if ((this.frame != null) && (this.frame.parentNode == this.layer.div)) {
this.layer.div.removeChild(this.frame);
}
this.frame = null;
OpenLayers.Tile.prototype.destroy.apply(this, arguments);
},
/**
* Method: clone
*
* Parameters:
* obj - {<OpenLayers.Tile.Image>} The tile to be cloned
*
* Returns:
* {<OpenLayers.Tile.Image>} An exact clone of this <OpenLayers.Tile.Image>
*/
clone: function (obj) {
if (obj == null) {
obj = new OpenLayers.Tile.Image(this.layer,
this.position,
this.bounds,
this.url,
this.size);
}
//pick up properties from superclass
obj = OpenLayers.Tile.prototype.clone.apply(this, [obj]);
//dont want to directly copy the image div
obj.imgDiv = null;
return obj;
},
/**
* Method: draw
* Check that a tile should be drawn, and draw it.
*
* Returns:
* {Boolean} Always returns true.
*/
draw: function() {
if (this.layer != this.layer.map.baseLayer && this.layer.reproject) {
this.bounds = this.getBoundsFromBaseLayer(this.position);
}
if (!OpenLayers.Tile.prototype.draw.apply(this, arguments)) {
return false;
}
if (this.isLoading) {
//if we're already loading, send 'reload' instead of 'loadstart'.
this.events.triggerEvent("reload");
} else {
this.isLoading = true;
this.events.triggerEvent("loadstart");
}
return this.renderTile();
},
/**
* Method: renderTile
* Internal function to actually initialize the image tile,
*     position it correctly, and set its url.
*/
renderTile: function() {
if (this.imgDiv == null) {
this.initImgDiv();
}
this.imgDiv.viewRequestID = this.layer.map.viewRequestID;
this.url = this.layer.getURL(this.bounds);
// position the frame
OpenLayers.Util.modifyDOMElement(this.frame,
null, this.position, this.size);
var imageSize = this.layer.getImageSize();
if (this.layerAlphaHack) {
OpenLayers.Util.modifyAlphaImageDiv(this.imgDiv,
null, null, imageSize, this.url);
} else {
OpenLayers.Util.modifyDOMElement(this.imgDiv,
null, null, imageSize) ;
this.imgDiv.src = this.url;
}
return true;
},
/**
* Method: clear
*  Clear the tile of any bounds/position-related data so that it can
*   be reused in a new location.
*/
clear: function() {
if(this.imgDiv) {
this.hide();
if (OpenLayers.Tile.Image.useBlankTile) {
this.imgDiv.src = OpenLayers.Util.getImagesLocation() + "blank.gif";
}
}
},
/**
* Method: initImgDiv
* Creates the imgDiv property on the tile.
*/
initImgDiv: function() {
var offset = this.layer.imageOffset;
var size = this.layer.getImageSize();
if (this.layerAlphaHack) {
this.imgDiv = OpenLayers.Util.createAlphaImageDiv(null,
offset,
size,
null,
"relative",
null,
null,
null,
true);
} else {
this.imgDiv = OpenLayers.Util.createImage(null,
offset,
size,
null,
"relative",
null,
null,
true);
}
this.imgDiv.className = 'olTileImage';
/* checkImgURL used to be used to called as a work around, but it
ended up hiding problems instead of solving them and broke things
like relative URLs. See discussion on the dev list:
http://openlayers.org/pipermail/dev/2007-January/000205.html
OpenLayers.Event.observe( this.imgDiv, "load",
OpenLayers.Function.bind(this.checkImgURL, this) );
*/
this.frame.style.zIndex = this.isBackBuffer ? 0 : 1;
this.frame.appendChild(this.imgDiv);
this.layer.div.appendChild(this.frame);
if(this.layer.opacity != null) {
OpenLayers.Util.modifyDOMElement(this.imgDiv, null, null, null,
null, null, null,
this.layer.opacity);
}
// we need this reference to check back the viewRequestID
this.imgDiv.map = this.layer.map;
//bind a listener to the onload of the image div so that we
// can register when a tile has finished loading.
var onload = function() {
//normally isLoading should always be true here but there are some
// right funky conditions where loading and then reloading a tile
// with the same url *really*fast*. this check prevents sending
// a 'loadend' if the msg has already been sent
//
if (this.isLoading) {
this.isLoading = false;
this.events.triggerEvent("loadend");
}
};
if (this.layerAlphaHack) {
OpenLayers.Event.observe(this.imgDiv.childNodes[0], 'load',
OpenLayers.Function.bind(onload, this));
} else {
OpenLayers.Event.observe(this.imgDiv, 'load',
OpenLayers.Function.bind(onload, this));
}
// Bind a listener to the onerror of the image div so that we
// can registere when a tile has finished loading with errors.
var onerror = function() {
// If we have gone through all image reload attempts, it is time
// to realize that we are done with this image. Since
// OpenLayers.Util.onImageLoadError already has taken care about
// the error, we can continue as if the image was loaded
// successfully.
if (this.imgDiv._attempts > OpenLayers.IMAGE_RELOAD_ATTEMPTS) {
onload.call(this);
}
};
OpenLayers.Event.observe(this.imgDiv, "error",
OpenLayers.Function.bind(onerror, this));
},
/**
* Method: checkImgURL
* 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.
*
* This function should no longer  be neccesary with the improvements to
* Grid.js in OpenLayers 2.3. The lack of a good isEquivilantURL function
* caused problems in 2.2, but it's possible that with the improved
* isEquivilant URL function, this might be neccesary at some point.
*
* See discussion in the thread at
* http://openlayers.org/pipermail/dev/2007-January/000205.html
*/
checkImgURL: function () {
// Sometimes our image will load after it has already been removed
// from the map, in which case this check is not needed.
if (this.layer) {
var loaded = this.layerAlphaHack ? this.imgDiv.firstChild.src : this.imgDiv.src;
if (!OpenLayers.Util.isEquivalentUrl(loaded, this.url)) {
this.hide();
}
}
},
/**
* Method: startTransition
* This method is invoked on tiles that are backBuffers for tiles in the
*     grid.  The grid tile is about to be cleared and a new tile source
*     loaded.  This is where the transition effect needs to be started
*     to provide visual continuity.
*/
startTransition: function() {
// backBufferTile has to be valid and ready to use
if (!this.backBufferTile || !this.backBufferTile.imgDiv) {
return;
}
// calculate the ratio of change between the current resolution of the
// backBufferTile and the layer.  If several animations happen in a
// row, then the backBufferTile will scale itself appropriately for
// each request.
var ratio = 1;
if (this.backBufferTile.resolution) {
ratio = this.backBufferTile.resolution / this.layer.getResolution();
}
// if the ratio is not the same as it was last time (i.e. we are
// zooming), then we need to adjust the backBuffer tile
if (ratio != this.lastRatio) {
if (this.layer.transitionEffect == 'resize') {
// In this case, we can just immediately resize the
// backBufferTile.
var upperLeft = new OpenLayers.LonLat(
this.backBufferTile.bounds.left,
this.backBufferTile.bounds.top
);
var size = new OpenLayers.Size(
this.backBufferTile.size.w * ratio,
this.backBufferTile.size.h * ratio
);
var px = this.layer.map.getLayerPxFromLonLat(upperLeft);
OpenLayers.Util.modifyDOMElement(this.backBufferTile.frame,
null, px, size);
var imageSize = this.backBufferTile.imageSize;
imageSize = new OpenLayers.Size(imageSize.w * ratio,
imageSize.h * ratio);
var imageOffset = this.backBufferTile.imageOffset;
if(imageOffset) {
imageOffset = new OpenLayers.Pixel(
imageOffset.x * ratio, imageOffset.y * ratio
);
}
OpenLayers.Util.modifyDOMElement(
this.backBufferTile.imgDiv, null, imageOffset, imageSize
) ;
this.backBufferTile.show();
}
} else {
// default effect is just to leave the existing tile
// until the new one loads if this is a singleTile and
// there was no change in resolution.  Otherwise we
// don't bother to show the backBufferTile at all
if (this.layer.singleTile) {
this.backBufferTile.show();
} else {
this.backBufferTile.hide();
}
}
this.lastRatio = ratio;
},
/**
* Method: show
* Show the tile by showing its frame.
*/
show: function() {
this.frame.style.display = '';
// Force a reflow on gecko based browsers to actually show the element
// before continuing execution.
if (OpenLayers.Util.indexOf(this.layer.SUPPORTED_TRANSITIONS,
this.layer.transitionEffect) != -1) {
if (navigator.userAgent.toLowerCase().indexOf("gecko") != -1) {
this.frame.scrollLeft = this.frame.scrollLeft;
}
}
},
/**
* Method: hide
* Hide the tile by hiding its frame.
*/
hide: function() {
this.frame.style.display = 'none';
},
CLASS_NAME: "OpenLayers.Tile.Image"
}
);
OpenLayers.Tile.Image.useBlankTile = (
OpenLayers.Util.getBrowserName() == "safari" ||
OpenLayers.Util.getBrowserName() == "opera");
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Layer.js
*/
/**
* Class: OpenLayers.Layer.HTTPRequest
*
* Inherits from:
*  - <OpenLayers.Layer>
*/
OpenLayers.Layer.HTTPRequest = OpenLayers.Class(OpenLayers.Layer, {
/**
* Constant: URL_HASH_FACTOR
* {Float} Used to hash URL param strings for multi-WMS server selection.
*         Set to the Golden Ratio per Knuth's recommendation.
*/
URL_HASH_FACTOR: (Math.sqrt(5) - 1) / 2,
/**
* Property: url
* {Array(String) or String} This is either an array of url strings or
*                           a single url string.
*/
url: null,
/**
* Property: params
* {Object} Hashtable of key/value parameters
*/
params: null,
/**
* APIProperty: reproject
* *Deprecated*. See http://trac.openlayers.org/wiki/SpatialMercator
* for information on the replacement for this functionality.
* {Boolean} 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.
*
*/
reproject: false,
/**
* Constructor: OpenLayers.Layer.HTTPRequest
*
* Parameters:
* name - {String}
* url - {Array(String) or String}
* params - {Object}
* options - {Object} Hashtable of extra options to tag onto the layer
*/
initialize: function(name, url, params, options) {
var newArguments = arguments;
newArguments = [name, options];
OpenLayers.Layer.prototype.initialize.apply(this, newArguments);
this.url = url;
this.params = OpenLayers.Util.extend( {}, params);
},
/**
* APIMethod: destroy
*/
destroy: function() {
this.url = null;
this.params = null;
OpenLayers.Layer.prototype.destroy.apply(this, arguments);
},
/**
* APIMethod: clone
*
* Parameters:
* obj - {Object}
*
* Returns:
* {<OpenLayers.Layer.HTTPRequest>} An exact clone of this
*                                  <OpenLayers.Layer.HTTPRequest>
*/
clone: function (obj) {
if (obj == null) {
obj = new OpenLayers.Layer.HTTPRequest(this.name,
this.url,
this.params,
this.options);
}
//get all additions from superclasses
obj = OpenLayers.Layer.prototype.clone.apply(this, [obj]);
// copy/set any non-init, non-simple values here
return obj;
},
/**
* APIMethod: setUrl
*
* Parameters:
* newUrl - {String}
*/
setUrl: function(newUrl) {
this.url = newUrl;
},
/**
* APIMethod: mergeNewParams
*
* Parameters:
* newParams - {Object}
*
* Returns:
* redrawn: {Boolean} whether the layer was actually redrawn.
*/
mergeNewParams:function(newParams) {
this.params = OpenLayers.Util.extend(this.params, newParams);
return this.redraw();
},
/**
* APIMethod: redraw
* Redraws the layer.  Returns true if the layer was redrawn, false if not.
*
* Parameters:
* force - {Boolean} Force redraw by adding random parameter.
*
* Returns:
* {Boolean} The layer was redrawn.
*/
redraw: function(force) {
if (force) {
return this.mergeNewParams({"_olSalt": Math.random()});
} else {
return OpenLayers.Layer.prototype.redraw.apply(this, []);
}
},
/**
* Method: selectUrl
* selectUrl() implements the standard floating-point multiplicative
*     hash function described by Knuth, and hashes the contents of the
*     given param string into a float between 0 and 1. This float is then
*     scaled to the size of the provided urls array, and used to select
*     a URL.
*
* Parameters:
* paramString - {String}
* urls - {Array(String)}
*
* Returns:
* {String} An entry from the urls array, deterministically selected based
*          on the paramString.
*/
selectUrl: function(paramString, urls) {
var product = 1;
for (var i = 0; i < paramString.length; i++) {
product *= paramString.charCodeAt(i) * this.URL_HASH_FACTOR;
product -= Math.floor(product);
}
return urls[Math.floor(product * urls.length)];
},
/**
* Method: getFullRequestString
* Combine url with layer's params and these newParams.
*
*    does checking on the serverPath variable, allowing for cases when it
*     is supplied with trailing ? or &, as well as cases where not.
*
*    return in formatted string like this:
*        "server?key1=value1&key2=value2&key3=value3"
*
* WARNING: The altUrl parameter is deprecated and will be removed in 3.0.
*
* Parameters:
* newParams - {Object}
* altUrl - {String} Use this as the url instead of the layer's url
*
* Returns:
* {String}
*/
getFullRequestString:function(newParams, altUrl) {
// if not altUrl passed in, use layer's url
var url = altUrl || this.url;
// create a new params hashtable with all the layer params and the
// new params together. then convert to string
var allParams = OpenLayers.Util.extend({}, this.params);
allParams = OpenLayers.Util.extend(allParams, newParams);
var paramsString = OpenLayers.Util.getParameterString(allParams);
// if url is not a string, it should be an array of strings,
// in which case we will deterministically select one of them in
// order to evenly distribute requests to different urls.
//
if (url instanceof Array) {
url = this.selectUrl(paramsString, url);
}
// ignore parameters that are already in the url search string
var urlParams =
OpenLayers.Util.upperCaseObject(OpenLayers.Util.getParameters(url));
for(var key in allParams) {
if(key.toUpperCase() in urlParams) {
delete allParams[key];
}
}
paramsString = OpenLayers.Util.getParameterString(allParams);
// requestString always starts with url
var requestString = url;
if (paramsString != "") {
var lastServerChar = url.charAt(url.length - 1);
if ((lastServerChar == "&") || (lastServerChar == "?")) {
requestString += paramsString;
} else {
if (url.indexOf('?') == -1) {
//serverPath has no ? -- add one
requestString += '?' + paramsString;
} else {
//serverPath contains ?, so must already have
// paramsString at the end
requestString += '&' + paramsString;
}
}
}
return requestString;
},
CLASS_NAME: "OpenLayers.Layer.HTTPRequest"
});
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Layer/HTTPRequest.js
*/
/**
* Class: OpenLayers.Layer.Grid
* Base class for layers that use a lattice of tiles.  Create a new grid
* layer with the <OpenLayers.Layer.Grid> constructor.
*
* Inherits from:
*  - <OpenLayers.Layer.HTTPRequest>
*/
OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
/**
* APIProperty: tileSize
* {<OpenLayers.Size>}
*/
tileSize: null,
/**
* Property: grid
* {Array(Array(<OpenLayers.Tile>))} This is an array of rows, each row is
*     an array of tiles.
*/
grid: null,
/**
* APIProperty: singleTile
* {Boolean} Moves the layer into single-tile mode, meaning that one tile
*     will be loaded. The tile's size will be determined by the 'ratio'
*     property. When the tile is dragged such that it does not cover the
*     entire viewport, it is reloaded.
*/
singleTile: false,
/** APIProperty: ratio
*  {Float} Used only when in single-tile mode, this specifies the
*          ratio of the size of the single tile to the size of the map.
*/
ratio: 1.5,
/**
* APIProperty: buffer
* {Integer} Used only when in gridded mode, this specifies the number of
*           extra rows and colums of tiles on each side which will
*           surround the minimum grid tiles to cover the map.
*/
buffer: 2,
/**
* APIProperty: numLoadingTiles
* {Integer} How many tiles are still loading?
*/
numLoadingTiles: 0,
/**
* Constructor: OpenLayers.Layer.Grid
* Create a new grid layer
*
* Parameters:
* name - {String}
* url - {String}
* params - {Object}
* options - {Object} Hashtable of extra options to tag onto the layer
*/
initialize: function(name, url, params, options) {
OpenLayers.Layer.HTTPRequest.prototype.initialize.apply(this,
arguments);
//grid layers will trigger 'tileloaded' when each new tile is
// loaded, as a means of progress update to listeners.
// listeners can access 'numLoadingTiles' if they wish to keep track
// of the loading progress
//
this.events.addEventType("tileloaded");
this.grid = [];
},
/**
* APIMethod: destroy
* Deconstruct the layer and clear the grid.
*/
destroy: function() {
this.clearGrid();
this.grid = null;
this.tileSize = null;
OpenLayers.Layer.HTTPRequest.prototype.destroy.apply(this, arguments);
},
/**
* Method: clearGrid
* Go through and remove all tiles from the grid, calling
*    destroy() on each of them to kill circular references
*/
clearGrid:function() {
if (this.grid) {
for(var iRow=0; iRow < this.grid.length; iRow++) {
var row = this.grid[iRow];
for(var iCol=0; iCol < row.length; iCol++) {
var tile = row[iCol];
this.removeTileMonitoringHooks(tile);
tile.destroy();
}
}
this.grid = [];
}
},
/**
* APIMethod: clone
* Create a clone of this layer
*
* Parameters:
* obj - {Object} Is this ever used?
*
* Returns:
* {<OpenLayers.Layer.Grid>} An exact clone of this OpenLayers.Layer.Grid
*/
clone: function (obj) {
if (obj == null) {
obj = new OpenLayers.Layer.Grid(this.name,
this.url,
this.params,
this.options);
}
//get all additions from superclasses
obj = OpenLayers.Layer.HTTPRequest.prototype.clone.apply(this, [obj]);
// copy/set any non-init, non-simple values here
if (this.tileSize != null) {
obj.tileSize = this.tileSize.clone();
}
// we do not want to copy reference to grid, so we make a new array
obj.grid = [];
return obj;
},
/**
* Method: moveTo
* This function is called whenever the map is moved. All the moving
* of actual 'tiles' is done by the map, but moveTo's role is to accept
* a bounds and make sure the data that that bounds requires is pre-loaded.
*
* Parameters:
* bounds - {<OpenLayers.Bounds>}
* zoomChanged - {Boolean}
* dragging - {Boolean}
*/
moveTo:function(bounds, zoomChanged, dragging) {
OpenLayers.Layer.HTTPRequest.prototype.moveTo.apply(this, arguments);
bounds = bounds || this.map.getExtent();
if (bounds != null) {
// if grid is empty or zoom has changed, we *must* re-tile
var forceReTile = !this.grid.length || zoomChanged;
// total bounds of the tiles
var tilesBounds = this.getTilesBounds();
if (this.singleTile) {
// We want to redraw whenever even the slightest part of the
//  current bounds is not contained by our tile.
//  (thus, we do not specify partial -- its default is false)
if ( forceReTile ||
(!dragging && !tilesBounds.containsBounds(bounds))) {
this.initSingleTile(bounds);
}
} else {
// if the bounds have changed such that they are not even
//  *partially* contained by our tiles (IE user has
//  programmatically panned to the other side of the earth)
//  then we want to reTile (thus, partial true).
//
if (forceReTile || !tilesBounds.containsBounds(bounds, true)) {
this.initGriddedTiles(bounds);
} else {
//we might have to shift our buffer tiles
this.moveGriddedTiles(bounds);
}
}
}
},
/**
* APIMethod: setTileSize
* Check if we are in singleTile mode and if so, set the size as a ratio
*     of the map size (as specified by the layer's 'ratio' property).
*
* Parameters:
* size - {<OpenLayers.Size>}
*/
setTileSize: function(size) {
if (this.singleTile) {
size = this.map.getSize().clone();
size.h = parseInt(size.h * this.ratio);
size.w = parseInt(size.w * this.ratio);
}
OpenLayers.Layer.HTTPRequest.prototype.setTileSize.apply(this, [size]);
},
/**
* Method: getGridBounds
* Deprecated. This function will be removed in 3.0. Please use
*     getTilesBounds() instead.
*
* Returns:
* {<OpenLayers.Bounds>} A Bounds object representing the bounds of all the
* currently loaded tiles (including those partially or not at all seen
* onscreen)
*/
getGridBounds: function() {
var msg = "The getGridBounds() function is deprecated. It will be " +
"removed in 3.0. Please use getTilesBounds() instead.";
OpenLayers.Console.warn(msg);
return this.getTilesBounds();
},
/**
* APIMethod: getTilesBounds
* Return the bounds of the tile grid.
*
* Returns:
* {<OpenLayers.Bounds>} A Bounds object representing the bounds of all the
*     currently loaded tiles (including those partially or not at all seen
*     onscreen).
*/
getTilesBounds: function() {
var bounds = null;
if (this.grid.length) {
var bottom = this.grid.length - 1;
var bottomLeftTile = this.grid[bottom][0];
var right = this.grid[0].length - 1;
var topRightTile = this.grid[0][right];
bounds = new OpenLayers.Bounds(bottomLeftTile.bounds.left,
bottomLeftTile.bounds.bottom,
topRightTile.bounds.right,
topRightTile.bounds.top);
}
return bounds;
},
/**
* Method: initSingleTile
*
* Parameters:
* bounds - {<OpenLayers.Bounds>}
*/
initSingleTile: function(bounds) {
//determine new tile bounds
var center = bounds.getCenterLonLat();
var tileWidth = bounds.getWidth() * this.ratio;
var tileHeight = bounds.getHeight() * this.ratio;
var tileBounds =
new OpenLayers.Bounds(center.lon - (tileWidth/2),
center.lat - (tileHeight/2),
center.lon + (tileWidth/2),
center.lat + (tileHeight/2));
var ul = new OpenLayers.LonLat(tileBounds.left, tileBounds.top);
var px = this.map.getLayerPxFromLonLat(ul);
if (!this.grid.length) {
this.grid[0] = [];
}
var tile = this.grid[0][0];
if (!tile) {
tile = this.addTile(tileBounds, px);
this.addTileMonitoringHooks(tile);
tile.draw();
this.grid[0][0] = tile;
} else {
tile.moveTo(tileBounds, px);
}
//remove all but our single tile
this.removeExcessTiles(1,1);
},
/**
* Method: calculateGridLayout
* Generate parameters for the grid layout. This
*
* Parameters:
* bounds - {<OpenLayers.Bound>}
* extent - {<OpenLayers.Bounds>}
* resolution - {Number}
*
* Returns:
* Object containing properties tilelon, tilelat, tileoffsetlat,
* tileoffsetlat, tileoffsetx, tileoffsety
*/
calculateGridLayout: function(bounds, extent, resolution) {
var tilelon = resolution * this.tileSize.w;
var tilelat = resolution * this.tileSize.h;
var offsetlon = bounds.left - extent.left;
var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
var tilecolremain = offsetlon/tilelon - tilecol;
var tileoffsetx = -tilecolremain * this.tileSize.w;
var tileoffsetlon = extent.left + tilecol * tilelon;
var offsetlat = bounds.top - (extent.bottom + tilelat);
var tilerow = Math.ceil(offsetlat/tilelat) + this.buffer;
var tilerowremain = tilerow - offsetlat/tilelat;
var tileoffsety = -tilerowremain * this.tileSize.h;
var tileoffsetlat = extent.bottom + tilerow * tilelat;
return {
tilelon: tilelon, tilelat: tilelat,
tileoffsetlon: tileoffsetlon, tileoffsetlat: tileoffsetlat,
tileoffsetx: tileoffsetx, tileoffsety: tileoffsety
};
},
/**
* Method: initGriddedTiles
*
* Parameters:
* bounds - {<OpenLayers.Bounds>}
*/
initGriddedTiles:function(bounds) {
// work out mininum number of rows and columns; this is the number of
// tiles required to cover the viewport plus at least one for panning
var viewSize = this.map.getSize();
var minRows = Math.ceil(viewSize.h/this.tileSize.h) +
Math.max(1, 2 * this.buffer);
var minCols = Math.ceil(viewSize.w/this.tileSize.w) +
Math.max(1, 2 * this.buffer);
var extent = this.map.getMaxExtent();
var resolution = this.map.getResolution();
var tileLayout = this.calculateGridLayout(bounds, extent, resolution);
var tileoffsetx = Math.round(tileLayout.tileoffsetx); // heaven help us
var tileoffsety = Math.round(tileLayout.tileoffsety);
var tileoffsetlon = tileLayout.tileoffsetlon;
var tileoffsetlat = tileLayout.tileoffsetlat;
var tilelon = tileLayout.tilelon;
var tilelat = tileLayout.tilelat;
this.origin = new OpenLayers.Pixel(tileoffsetx, tileoffsety);
var startX = tileoffsetx;
var startLon = tileoffsetlon;
var rowidx = 0;
var layerContainerDivLeft = parseInt(this.map.layerContainerDiv.style.left);
var layerContainerDivTop = parseInt(this.map.layerContainerDiv.style.top);
do {
var row = this.grid[rowidx++];
if (!row) {
row = [];
this.grid.push(row);
}
tileoffsetlon = startLon;
tileoffsetx = startX;
var colidx = 0;
do {
var tileBounds =
new OpenLayers.Bounds(tileoffsetlon,
tileoffsetlat,
tileoffsetlon + tilelon,
tileoffsetlat + tilelat);
var x = tileoffsetx;
x -= layerContainerDivLeft;
var y = tileoffsety;
y -= layerContainerDivTop;
var px = new OpenLayers.Pixel(x, y);
var tile = row[colidx++];
if (!tile) {
tile = this.addTile(tileBounds, px);
this.addTileMonitoringHooks(tile);
row.push(tile);
} else {
tile.moveTo(tileBounds, px, false);
}
tileoffsetlon += tilelon;
tileoffsetx += this.tileSize.w;
} while ((tileoffsetlon <= bounds.right + tilelon * this.buffer)
|| colidx < minCols)
tileoffsetlat -= tilelat;
tileoffsety += this.tileSize.h;
} while((tileoffsetlat >= bounds.bottom - tilelat * this.buffer)
|| rowidx < minRows)
//shave off exceess rows and colums
this.removeExcessTiles(rowidx, colidx);
//now actually draw the tiles
this.spiralTileLoad();
},
/**
* Method: spiralTileLoad
*   Starts at the top right corner of the grid and proceeds in a spiral
*    towards the center, adding tiles one at a time to the beginning of a
*    queue.
*
*   Once all the grid's tiles have been added to the queue, we go back
*    and iterate through the queue (thus reversing the spiral order from
*    outside-in to inside-out), calling draw() on each tile.
*/
spiralTileLoad: function() {
var tileQueue = [];
var directions = ["right", "down", "left", "up"];
var iRow = 0;
var iCell = -1;
var direction = OpenLayers.Util.indexOf(directions, "right");
var directionsTried = 0;
while( directionsTried < directions.length) {
var testRow = iRow;
var testCell = iCell;
switch (directions[direction]) {
case "right":
testCell++;
break;
case "down":
testRow++;
break;
case "left":
testCell--;
break;
case "up":
testRow--;
break;
}
// if the test grid coordinates are within the bounds of the
//  grid, get a reference to the tile.
var tile = null;
if ((testRow < this.grid.length) && (testRow >= 0) &&
(testCell < this.grid[0].length) && (testCell >= 0)) {
tile = this.grid[testRow][testCell];
}
if ((tile != null) && (!tile.queued)) {
//add tile to beginning of queue, mark it as queued.
tileQueue.unshift(tile);
tile.queued = true;
//restart the directions counter and take on the new coords
directionsTried = 0;
iRow = testRow;
iCell = testCell;
} else {
//need to try to load a tile in a different direction
direction = (direction + 1) % 4;
directionsTried++;
}
}
// now we go through and draw the tiles in forward order
for(var i=0; i < tileQueue.length; i++) {
var tile = tileQueue[i];
tile.draw();
//mark tile as unqueued for the next time (since tiles are reused)
tile.queued = false;
}
},
/**
* APIMethod: addTile
* Gives subclasses of Grid the opportunity to create an
* OpenLayer.Tile of their choosing. The implementer should initialize
* the new tile and take whatever steps necessary to display it.
*
* Parameters
* bounds - {<OpenLayers.Bounds>}
* position - {<OpenLayers.Pixel>}
*
* Returns:
* {<OpenLayers.Tile>} The added OpenLayers.Tile
*/
addTile:function(bounds, position) {
// Should be implemented by subclasses
},
/**
* Method: addTileMonitoringHooks
* This function takes a tile as input and adds the appropriate hooks to
*     the tile so that the layer can keep track of the loading tiles.
*
* Parameters:
* tile - {<OpenLayers.Tile>}
*/
addTileMonitoringHooks: function(tile) {
tile.onLoadStart = function() {
//if that was first tile then trigger a 'loadstart' on the layer
if (this.numLoadingTiles == 0) {
this.events.triggerEvent("loadstart");
}
this.numLoadingTiles++;
};
tile.events.register("loadstart", this, tile.onLoadStart);
tile.onLoadEnd = function() {
this.numLoadingTiles--;
this.events.triggerEvent("tileloaded");
//if that was the last tile, then trigger a 'loadend' on the layer
if (this.numLoadingTiles == 0) {
this.events.triggerEvent("loadend");
}
};
tile.events.register("loadend", this, tile.onLoadEnd);
tile.events.register("unload", this, tile.onLoadEnd);
},
/**
* Method: removeTileMonitoringHooks
* This function takes a tile as input and removes the tile hooks
*     that were added in addTileMonitoringHooks()
*
* Parameters:
* tile - {<OpenLayers.Tile>}
*/
removeTileMonitoringHooks: function(tile) {
tile.unload();
tile.events.un({
"loadstart": tile.onLoadStart,
"loadend": tile.onLoadEnd,
"unload": tile.onLoadEnd,
scope: this
});
},
/**
* Method: moveGriddedTiles
*
* Parameters:
* bounds - {<OpenLayers.Bounds>}
*/
moveGriddedTiles: function(bounds) {
var buffer = this.buffer || 1;
while (true) {
var tlLayer = this.grid[0][0].position;
var tlViewPort =
this.map.getViewPortPxFromLayerPx(tlLayer);
if (tlViewPort.x > -this.tileSize.w * (buffer - 1)) {
this.shiftColumn(true);
} else if (tlViewPort.x < -this.tileSize.w * buffer) {
this.shiftColumn(false);
} else if (tlViewPort.y > -this.tileSize.h * (buffer - 1)) {
this.shiftRow(true);
} else if (tlViewPort.y < -this.tileSize.h * buffer) {
this.shiftRow(false);
} else {
break;
}
};
},
/**
* Method: shiftRow
* Shifty grid work
*
* Parameters:
* prepend - {Boolean} if true, prepend to beginning.
*                          if false, then append to end
*/
shiftRow:function(prepend) {
var modelRowIndex = (prepend) ? 0 : (this.grid.length - 1);
var grid = this.grid;
var modelRow = grid[modelRowIndex];
var resolution = this.map.getResolution();
var deltaY = (prepend) ? -this.tileSize.h : this.tileSize.h;
var deltaLat = resolution * -deltaY;
var row = (prepend) ? grid.pop() : grid.shift();
for (var i=0; i < modelRow.length; i++) {
var modelTile = modelRow[i];
var bounds = modelTile.bounds.clone();
var position = modelTile.position.clone();
bounds.bottom = bounds.bottom + deltaLat;
bounds.top = bounds.top + deltaLat;
position.y = position.y + deltaY;
row[i].moveTo(bounds, position);
}
if (prepend) {
grid.unshift(row);
} else {
grid.push(row);
}
},
/**
* Method: shiftColumn
* Shift grid work in the other dimension
*
* Parameters:
* prepend - {Boolean} if true, prepend to beginning.
*                          if false, then append to end
*/
shiftColumn: function(prepend) {
var deltaX = (prepend) ? -this.tileSize.w : this.tileSize.w;
var resolution = this.map.getResolution();
var deltaLon = resolution * deltaX;
for (var i=0; i<this.grid.length; i++) {
var row = this.grid[i];
var modelTileIndex = (prepend) ? 0 : (row.length - 1);
var modelTile = row[modelTileIndex];
var bounds = modelTile.bounds.clone();
var position = modelTile.position.clone();
bounds.left = bounds.left + deltaLon;
bounds.right = bounds.right + deltaLon;
position.x = position.x + deltaX;
var tile = prepend ? this.grid[i].pop() : this.grid[i].shift();
tile.moveTo(bounds, position);
if (prepend) {
row.unshift(tile);
} else {
row.push(tile);
}
}
},
/**
* Method: removeExcessTiles
* When the size of the map or the buffer changes, we may need to
*     remove some excess rows and columns.
*
* Parameters:
* rows - {Integer} Maximum number of rows we want our grid to have.
* colums - {Integer} Maximum number of columns we want our grid to have.
*/
removeExcessTiles: function(rows, columns) {
// remove extra rows
while (this.grid.length > rows) {
var row = this.grid.pop();
for (var i=0, l=row.length; i<l; i++) {
var tile = row[i];
this.removeTileMonitoringHooks(tile);
tile.destroy();
}
}
// remove extra columns
while (this.grid[0].length > columns) {
for (var i=0, l=this.grid.length; i<l; i++) {
var row = this.grid[i];
var tile = row.pop();
this.removeTileMonitoringHooks(tile);
tile.destroy();
}
}
},
/**
* Method: onMapResize
* For singleTile layers, this will set a new tile size according to the
* dimensions of the map pane.
*/
onMapResize: function() {
if (this.singleTile) {
this.clearGrid();
this.setTileSize();
}
},
/**
* APIMethod: getTileBounds
* Returns The tile bounds for a layer given a pixel location.
*
* Parameters:
* viewPortPx - {<OpenLayers.Pixel>} The location in the viewport.
*
* Returns:
* {<OpenLayers.Bounds>} Bounds of the tile at the given pixel location.
*/
getTileBounds: function(viewPortPx) {
var maxExtent = this.map.getMaxExtent();
var resolution = this.getResolution();
var tileMapWidth = resolution * this.tileSize.w;
var tileMapHeight = resolution * this.tileSize.h;
var mapPoint = this.getLonLatFromViewPortPx(viewPortPx);
var tileLeft = maxExtent.left + (tileMapWidth *
Math.floor((mapPoint.lon -
maxExtent.left) /
tileMapWidth));
var tileBottom = maxExtent.bottom + (tileMapHeight *
Math.floor((mapPoint.lat -
maxExtent.bottom) /
tileMapHeight));
return new OpenLayers.Bounds(tileLeft, tileBottom,
tileLeft + tileMapWidth,
tileBottom + tileMapHeight);
},
CLASS_NAME: "OpenLayers.Layer.Grid"
});
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Layer.js
*/
/**
* Class: OpenLayers.Layer.Markers
*
* Inherits from:
*  - <OpenLayers.Layer>
*/
OpenLayers.Layer.Markers = OpenLayers.Class(OpenLayers.Layer, {
/**
* APIProperty: isBaseLayer
* {Boolean} Markers layer is never a base layer.
*/
isBaseLayer: false,
/**
* Property: markers
* {Array(<OpenLayers.Marker>)} internal marker list
*/
markers: null,
/**
* Property: drawn
* {Boolean} internal state of drawing. This is a workaround for the fact
* that the map does not call moveTo with a zoomChanged when the map is
* first starting up. This lets us catch the case where we have *never*
* drawn the layer, and draw it even if the zoom hasn't changed.
*/
drawn: false,
/**
* Constructor: OpenLayers.Layer.Markers
* Create a Markers layer.
*
* Parameters:
* name - {String}
* options - {Object} Hashtable of extra options to tag onto the layer
*/
initialize: function(name, options) {
OpenLayers.Layer.prototype.initialize.apply(this, arguments);
this.markers = [];
},
/**
* APIMethod: destroy
*/
destroy: function() {
this.clearMarkers();
this.markers = null;
OpenLayers.Layer.prototype.destroy.apply(this, arguments);
},
/**
* APIMethod: setOpacity
* Sets the opacity for all the markers.
*
* Parameter:
* opacity - {Float}
*/
setOpacity: function(opacity) {
if (opacity != this.opacity) {
this.opacity = opacity;
for (var i = 0; i < this.markers.length; i++) {
this.markers[i].setOpacity(this.opacity);
}
}
},
/**
* Method: moveTo
*
* Parameters:
* bounds - {<OpenLayers.Bounds>}
* zoomChanged - {Boolean}
* dragging - {Boolean}
*/
moveTo:function(bounds, zoomChanged, dragging) {
OpenLayers.Layer.prototype.moveTo.apply(this, arguments);
if (zoomChanged || !this.drawn) {
for(var i=0; i < this.markers.length; i++) {
this.drawMarker(this.markers[i]);
}
this.drawn = true;
}
},
/**
* APIMethod: addMarker
*
* Parameters:
* marker - {<OpenLayers.Marker>}
*/
addMarker: function(marker) {
this.markers.push(marker);
if (this.opacity != null) {
marker.setOpacity(this.opacity);
}
if (this.map && this.map.getExtent()) {
marker.map = this.map;
this.drawMarker(marker);
}
},
/**
* APIMethod: removeMarker
*
* Parameters:
* marker - {<OpenLayers.Marker>}
*/
removeMarker: function(marker) {
if (this.markers && this.markers.length) {
OpenLayers.Util.removeItem(this.markers, marker);
if ((marker.icon != null) && (marker.icon.imageDiv != null) &&
(marker.icon.imageDiv.parentNode == this.div) ) {
this.div.removeChild(marker.icon.imageDiv);
marker.drawn = false;
}
}
},
/**
* Method: clearMarkers
* This method removes all markers from a layer. The markers are not
* destroyed by this function, but are removed from the list of markers.
*/
clearMarkers: function() {
if (this.markers != null) {
while(this.markers.length > 0) {
this.removeMarker(this.markers[0]);
}
}
},
/**
* Method: drawMarker
* Calculate the pixel location for the marker, create it, and
*    add it to the layer's div
*
* Parameters:
* marker - {<OpenLayers.Marker>}
*/
drawMarker: function(marker) {
var px = this.map.getLayerPxFromLonLat(marker.lonlat);
if (px == null) {
marker.display(false);
} else {
var markerImg = marker.draw(px);
if (!marker.drawn) {
this.div.appendChild(markerImg);
marker.drawn = true;
}
}
},
/**
* APIMethod: getDataExtent
* Calculates the max extent which includes all of the markers.
*
* Returns:
* {<OpenLayers.Bounds>}
*/
getDataExtent: function () {
var maxExtent = null;
if ( this.markers && (this.markers.length > 0)) {
var maxExtent = new OpenLayers.Bounds();
for(var i=0; i < this.markers.length; i++) {
var marker = this.markers[i];
maxExtent.extend(marker.lonlat);
}
}
return maxExtent;
},
CLASS_NAME: "OpenLayers.Layer.Markers"
});
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Layer/Grid.js
* @requires OpenLayers/Tile/Image.js
*/
/**
* Class: OpenLayers.Layer.WMS
* Instances of OpenLayers.Layer.WMS are used to display data from OGC Web
*     Mapping Services. Create a new WMS layer with the <OpenLayers.Layer.WMS>
*     constructor.
*
* Inherits from:
*  - <OpenLayers.Layer.Grid>
*/
OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, {
/**
* Constant: DEFAULT_PARAMS
* {Object} Hashtable of default parameter key/value pairs
*/
DEFAULT_PARAMS: { service: "WMS",
version: "1.1.1",
request: "GetMap",
styles: "",
exceptions: "application/vnd.ogc.se_inimage",
format: "image/jpeg"
},
/**
* Property: reproject
* *Deprecated*. See http://trac.openlayers.org/wiki/SphericalMercator
* for information on the replacement for this functionality.
* {Boolean} Try to reproject this layer if its coordinate reference system
*           is different than that of the base layer.  Default is true.
*           Set this in the layer options.  Should be set to false in
*           most cases.
*/
reproject: false,
/**
* APIProperty: isBaseLayer
* {Boolean} Default is true for WMS layer
*/
isBaseLayer: true,
/**
* APIProperty: encodeBBOX
* {Boolean} Should the BBOX commas be encoded? The WMS spec says 'no',
* but some services want it that way. Default false.
*/
encodeBBOX: false,
/**
* Constructor: OpenLayers.Layer.WMS
* Create a new WMS layer object
*
* Example:
* (code)
* var wms = new OpenLayers.Layer.WMS("NASA Global Mosaic",
*                                    "http://wms.jpl.nasa.gov/wms.cgi",
*                                    {layers: "modis,global_mosaic"});
* (end)
*
* Parameters:
* name - {String} A name for the layer
* url - {String} Base url for the WMS
*                (e.g. http://wms.jpl.nasa.gov/wms.cgi)
* params - {Object} An object with key/value pairs representing the
*                   GetMap query string parameters and parameter values.
* options - {Ojbect} Hashtable of extra options to tag onto the layer
*/
initialize: function(name, url, params, options) {
var newArguments = [];
//uppercase params
params = OpenLayers.Util.upperCaseObject(params);
newArguments.push(name, url, params, options);
OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
OpenLayers.Util.applyDefaults(
this.params,
OpenLayers.Util.upperCaseObject(this.DEFAULT_PARAMS)
);
//layer is transparent
if (this.params.TRANSPARENT &&
this.params.TRANSPARENT.toString().toLowerCase() == "true") {
// unless explicitly set in options, make layer an overlay
if ( (options == null) || (!options.isBaseLayer) ) {
this.isBaseLayer = false;
}
// jpegs can never be transparent, so intelligently switch the
//  format, depending on teh browser's capabilities
if (this.params.FORMAT == "image/jpeg") {
this.params.FORMAT = OpenLayers.Util.alphaHack() ? "image/gif"
: "image/png";
}
}
},
/**
* Method: destroy
* Destroy this layer
*/
destroy: function() {
// for now, nothing special to do here.
OpenLayers.Layer.Grid.prototype.destroy.apply(this, arguments);
},
/**
* Method: clone
* Create a clone of this layer
*
* Returns:
* {<OpenLayers.Layer.WMS>} An exact clone of this layer
*/
clone: function (obj) {
if (obj == null) {
obj = new OpenLayers.Layer.WMS(this.name,
this.url,
this.params,
this.options);
}
//get all additions from superclasses
obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
// copy/set any non-init, non-simple values here
return obj;
},
/**
* Method: getURL
* Return a GetMap query string for this layer
*
* Parameters:
* bounds - {<OpenLayers.Bounds>} A bounds representing the bbox for the
*                                request.
*
* Returns:
* {String} A string with the layer's url and parameters and also the
*          passed-in bounds and appropriate tile size specified as
*          parameters.
*/
getURL: function (bounds) {
bounds = this.adjustBounds(bounds);
var imageSize = this.getImageSize();
var newParams = {
'BBOX': this.encodeBBOX ?  bounds.toBBOX() : bounds.toArray(),
'WIDTH': imageSize.w,
'HEIGHT': imageSize.h
};
var requestString = this.getFullRequestString(newParams);
return requestString;
},
/**
* Method: addTile
* addTile creates a tile, initializes it, and adds it to the layer div.
*
* Parameters:
* bounds - {<OpenLayers.Bounds>}
* position - {<OpenLayers.Pixel>}
*
* Returns:
* {<OpenLayers.Tile.Image>} The added OpenLayers.Tile.Image
*/
addTile:function(bounds,position) {
return new OpenLayers.Tile.Image(this, position, bounds,
null, this.tileSize);
},
/**
* APIMethod: mergeNewParams
* Catch changeParams and uppercase the new params to be merged in
*     before calling changeParams on the super class.
*
*     Once params have been changed, we will need to re-init our tiles.
*
* Parameters:
* newParams - {Object} Hashtable of new params to use
*/
mergeNewParams:function(newParams) {
var upperParams = OpenLayers.Util.upperCaseObject(newParams);
var newArguments = [upperParams];
return OpenLayers.Layer.Grid.prototype.mergeNewParams.apply(this,
newArguments);
},
/**
* Method: getFullRequestString
* Combine the layer's url with its params and these newParams.
*
*     Add the SRS parameter from projection -- this is probably
*     more eloquently done via a setProjection() method, but this
*     works for now and always.
*
* Parameters:
* newParams - {Object}
* altUrl - {String} Use this as the url instead of the layer's url
*
* Returns:
* {String}
*/
getFullRequestString:function(newParams, altUrl) {
var projectionCode = this.map.getProjection();
this.params.SRS = (projectionCode == "none") ? null : projectionCode;
return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply(
this, arguments);
},
CLASS_NAME: "OpenLayers.Layer.WMS"
});
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Layer/WMS.js
*/
/**
* Class: OpenLayers.Layer.WMS.Untiled
* *Deprecated*.  To be removed in 3.0.  Instead use OpenLayers.Layer.WMS and
*     pass the option 'singleTile' as true.
*
* Inherits from:
*  - <OpenLayers.Layer.WMS>
*/
OpenLayers.Layer.WMS.Untiled = OpenLayers.Class(OpenLayers.Layer.WMS, {
/**
* APIProperty: singleTile
* {singleTile} Always true for untiled.
*/
singleTile: true,
/**
* Constructor: OpenLayers.Layer.WMS.Untiled
*
* Parameters:
* name - {String}
* url - {String}
* params - {Object}
* options - {Object}
*/
initialize: function(name, url, params, options) {
OpenLayers.Layer.WMS.prototype.initialize.apply(this, arguments);
var msg = "The OpenLayers.Layer.WMS.Untiled class is deprecated and " +
"will be removed in 3.0. Instead, you should use the " +
"normal OpenLayers.Layer.WMS class, passing it the option " +
"'singleTile' as true.";
OpenLayers.Console.warn(msg);
},
/**
* Method: clone
* Create a clone of this layer
*
* Returns:
* {<OpenLayers.Layer.WMS.Untiled>} An exact clone of this layer
*/
clone: function (obj) {
if (obj == null) {
obj = new OpenLayers.Layer.WMS.Untiled(this.name,
this.url,
this.params,
this.options);
}
//get all additions from superclasses
obj = OpenLayers.Layer.WMS.prototype.clone.apply(this, [obj]);
// copy/set any non-init, non-simple values here
return obj;
},
CLASS_NAME: "OpenLayers.Layer.WMS.Untiled"
});
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Layer/Markers.js
* @requires OpenLayers/Ajax.js
*/
/**
* Class: OpenLayers.Layer.GeoRSS
* Add GeoRSS Point features to your map.
*
* Inherits from:
*  - <OpenLayers.Layer.Markers>
*  - <OpenLayers.Layer>
*/
OpenLayers.Layer.GeoRSS = OpenLayers.Class(OpenLayers.Layer.Markers, {
/**
* Property: location
* {String} store url of text file
*/
location: null,
/**
* Property: features
* {Array(<OpenLayers.Feature>)}
*/
features: null,
/**
* APIProperty: formatOptions
* {Object} Hash of options which should be passed to the format when it is
* created. Must be passed in the constructor.
*/
formatOptions: null,
/**
* Property: selectedFeature
* {<OpenLayers.Feature>}
*/
selectedFeature: null,
/**
* APIProperty: icon
* {<OpenLayers.Icon>}. This determines the Icon to be used on the map
* for this GeoRSS layer.
*/
icon: null,
/**
* APIProperty: popupSize
* {<OpenLayers.Size>} This determines the size of GeoRSS popups. If
* not provided, defaults to 250px by 120px.
*/
popupSize: null,
/**
* APIProperty: useFeedTitle
* {Boolean} Set layer.name to the first <title> element in the feed. Default is true.
*/
useFeedTitle: true,
/**
* Constructor: OpenLayers.Layer.GeoRSS
* Create a GeoRSS Layer.
*
* Parameters:
* name - {String}
* location - {String}
* options - {Object}
*/
initialize: function(name, location, options) {
OpenLayers.Layer.Markers.prototype.initialize.apply(this, [name, options]);
this.location = location;
this.features = [];
},
/**
* Method: destroy
*/
destroy: function() {
// Warning: Layer.Markers.destroy() must be called prior to calling
// clearFeatures() here, otherwise we leak memory. Indeed, if
// Layer.Markers.destroy() is called after clearFeatures(), it won't be
// able to remove the marker image elements from the layer's div since
// the markers will have been destroyed by clearFeatures().
OpenLayers.Layer.Markers.prototype.destroy.apply(this, arguments);
this.clearFeatures();
this.features = null;
},
/**
* Method: loadRSS
* Start the load of the RSS data. Don't do this when we first add the layer,
* since we may not be visible at any point, and it would therefore be a waste.
*/
loadRSS: function() {
if (!this.loaded) {
this.events.triggerEvent("loadstart");
OpenLayers.loadURL(this.location, null, this, this.parseData);
this.loaded = true;
}
},
/**
* Method: moveTo
* If layer is visible and RSS has not been loaded, load RSS.
*
* Parameters:
* bounds - {Object}
* zoomChanged - {Object}
* minor - {Object}
*/
moveTo:function(bounds, zoomChanged, minor) {
OpenLayers.Layer.Markers.prototype.moveTo.apply(this, arguments);
if(this.visibility && !this.loaded){
this.events.triggerEvent("loadstart");
this.loadRSS();
}
},
/**
* Method: parseData
* Parse the data returned from the Events call.
*
* Parameters:
* ajaxRequest - {XMLHttpRequest}
*/
parseData: function(ajaxRequest) {
var doc = ajaxRequest.responseXML;
if (!doc || !doc.documentElement) {
doc = OpenLayers.Format.XML.prototype.read(ajaxRequest.responseText);
}
if (this.useFeedTitle) {
var name = null;
try {
name = doc.getElementsByTagNameNS('*', 'title')[0].firstChild.nodeValue;
}
catch (e) {
name = doc.getElementsByTagName('title')[0].firstChild.nodeValue;
}
if (name) {
this.setName(name);
}
}
var options = {};
OpenLayers.Util.extend(options, this.formatOptions);
if (this.map && !this.projection.equals(this.map.getProjectionObject())) {
options.externalProjection = this.projection;
options.internalProjection = this.map.getProjectionObject();
}
var format = new OpenLayers.Format.GeoRSS(options);
var features = format.read(doc);
for (var i = 0; i < features.length; i++) {
var data = {};
var feature = features[i];
// we don't support features with no geometry in the GeoRSS
// layer at this time.
if (!feature.geometry) {
continue;
}
var title = feature.attributes.title ?
feature.attributes.title : "Untitled";
var description = feature.attributes.description ?
feature.attributes.description : "No description.";
var link = feature.attributes.link ? feature.attributes.link : "";
var location = feature.geometry.getBounds().getCenterLonLat();
data.icon = this.icon == null ?
OpenLayers.Marker.defaultIcon() :
this.icon.clone();
data.popupSize = this.popupSize ?
this.popupSize.clone() :
new OpenLayers.Size(250, 120);
if (title || description) {
var contentHTML = '<div class="olLayerGeoRSSClose">[x]</div>';
contentHTML += '<div class="olLayerGeoRSSTitle">';
if (link) {
contentHTML += '<a class="link" href="'+link+'">';
}
contentHTML += title;
if (link) {
contentHTML += '</a>';
}
contentHTML += '</div>';
contentHTML += '<div style="" class="olLayerGeoRSSDescription">';
contentHTML += description;
contentHTML += '</div>';
data['popupContentHTML'] = contentHTML;
}
var feature = new OpenLayers.Feature(this, location, data);
this.features.push(feature);
var marker = feature.createMarker();
marker.events.register('click', feature, this.markerClick);
this.addMarker(marker);
}
this.events.triggerEvent("loadend");
},
/**
* Method: markerClick
*
* Parameters:
* evt - {Event}
*/
markerClick: function(evt) {
var sameMarkerClicked = (this == this.layer.selectedFeature);
this.layer.selectedFeature = (!sameMarkerClicked) ? this : null;
for(var i=0; i < this.layer.map.popups.length; i++) {
this.layer.map.removePopup(this.layer.map.popups[i]);
}
if (!sameMarkerClicked) {
var popup = this.createPopup();
OpenLayers.Event.observe(popup.div, "click",
OpenLayers.Function.bind(function() {
for(var i=0; i < this.layer.map.popups.length; i++) {
this.layer.map.removePopup(this.layer.map.popups[i]);
}
}, this)
);
this.layer.map.addPopup(popup);
}
OpenLayers.Event.stop(evt);
},
/**
* Method: clearFeatures
* Destroy all features in this layer.
*/
clearFeatures: function() {
if (this.features != null) {
while(this.features.length > 0) {
var feature = this.features[0];
OpenLayers.Util.removeItem(this.features, feature);
feature.destroy();
}
}
},
CLASS_NAME: "OpenLayers.Layer.GeoRSS"
});