diff --git a/art/layer-switcher-maximize.svg b/art/layer-switcher-maximize.svg new file mode 100644 index 0000000000..6b9f0d39b8 --- /dev/null +++ b/art/layer-switcher-maximize.svg @@ -0,0 +1,128 @@ + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/art/layer-switcher-minimize.svg b/art/layer-switcher-minimize.svg new file mode 100644 index 0000000000..70fcb8cbae --- /dev/null +++ b/art/layer-switcher-minimize.svg @@ -0,0 +1,142 @@ + + + + + + + + + image/svg+xml + + + + + + + + + - + + + + + + diff --git a/examples/LayerSwitcher.html b/examples/LayerSwitcher.html new file mode 100644 index 0000000000..d66c45a7d5 --- /dev/null +++ b/examples/LayerSwitcher.html @@ -0,0 +1,67 @@ + + + + + + + + + + +
+
click to add the marker to the map
+
click to remove the marker from the map
+ + diff --git a/examples/boxes.html b/examples/boxes.html new file mode 100644 index 0000000000..cd85e70629 --- /dev/null +++ b/examples/boxes.html @@ -0,0 +1,49 @@ + + + + + + + +

OpenLayers Example

+
+ + diff --git a/examples/google.html b/examples/google.html index 31b23bef00..d6081d51b0 100644 --- a/examples/google.html +++ b/examples/google.html @@ -22,7 +22,7 @@ function init(){ map = new OpenLayers.Map( $('map') ); - gmap = new OpenLayers.Layer.Google( "Google" ); + gmap = new OpenLayers.Layer.Google( "Google" , {type: G_HYBRID_MAP }); map.addLayer(gmap); markers = new OpenLayers.Layer.Markers("markers"); @@ -30,6 +30,7 @@ map.setCenter(new OpenLayers.LonLat(lon, lat), zoom); map.addControl( new OpenLayers.Control.LayerSwitcher() ); + } function add() { @@ -41,7 +42,7 @@ function remove() { markers.removeMarker(marker); } - + // --> @@ -49,7 +50,6 @@

OpenLayers With Google Layer Example

-
click to add the marker to the map
click to remove the marker from the map
diff --git a/img/layer-switcher-minimize.png b/img/layer-switcher-minimize.png index e41bb92e06..e80bf213f8 100644 Binary files a/img/layer-switcher-minimize.png and b/img/layer-switcher-minimize.png differ diff --git a/lib/OpenLayers.js b/lib/OpenLayers.js index b1a8d32847..5631d8a83f 100644 --- a/lib/OpenLayers.js +++ b/lib/OpenLayers.js @@ -58,6 +58,7 @@ if (typeof(_OPENLAYERS_SFL_) == "undefined") { "OpenLayers/Layer.js", "OpenLayers/Icon.js", "OpenLayers/Marker.js", + "OpenLayers/Marker/Box.js", "OpenLayers/Popup.js", "OpenLayers/Tile.js", "OpenLayers/Feature.js", @@ -77,6 +78,7 @@ if (typeof(_OPENLAYERS_SFL_) == "undefined") { "OpenLayers/Layer/WFS.js", "OpenLayers/Layer/WMS/Untiled.js", "OpenLayers/Layer/GeoRSS.js", + "OpenLayers/Layer/Boxes.js", "OpenLayers/Popup/Anchored.js", "OpenLayers/Popup/AnchoredBubble.js", "OpenLayers/Control.js", @@ -87,7 +89,8 @@ if (typeof(_OPENLAYERS_SFL_) == "undefined") { "OpenLayers/Control/PanZoomBar.js", "OpenLayers/Control/Permalink.js", "OpenLayers/Control/Scale.js", - "OpenLayers/Control/LayerSwitcher.js" + "OpenLayers/Control/LayerSwitcher.js", + "OpenLayers/Control/LayerTabs.js" ); // etc. var allScriptTags = ""; diff --git a/lib/OpenLayers/Control/LayerSwitcher.js b/lib/OpenLayers/Control/LayerSwitcher.js index 8ad77ff677..9f643321c7 100644 --- a/lib/OpenLayers/Control/LayerSwitcher.js +++ b/lib/OpenLayers/Control/LayerSwitcher.js @@ -1,225 +1,396 @@ /* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license. * See http://svn.openlayers.org/trunk/openlayers/license.txt for the full * text of the license. */ + // @require: OpenLayers/Control.js + /** * @class */ OpenLayers.Control.LayerSwitcher = Class.create(); - -/** color used in the UI to show a layer is active/displayed -* -* @final -* @type String -*/ -OpenLayers.Control.LayerSwitcher.ACTIVE_COLOR = "darkblue"; - -/** color used in the UI to show a layer is deactivated/hidden -* -* @final -* @type String -*/ -OpenLayers.Control.LayerSwitcher.NONACTIVE_COLOR = "lightblue"; - - OpenLayers.Control.LayerSwitcher.prototype = Object.extend( new OpenLayers.Control(), { /** @type String */ - activeColor: "", + activeColor: "darkblue", - /** @type String */ - nonActiveColor: "", - - /** @type String */ - mode: "checkbox", + // DOM Elements + + /** @type DOMElement */ + layersDiv: null, + + /** @type DOMElement */ + baseLayersDiv: null, + + /** @type Array */ + baseLayerInputs: null, + + /** @type DOMElement */ + dataLayersDiv: null, + + /** @type Array */ + dataLayerInputs: null, + + + /** @type DOMElement */ + minimizeDiv: null, + + /** @type DOMElement */ + maximizeDiv: null, + /** * @constructor */ initialize: function(options) { - this.activeColor = OpenLayers.Control.LayerSwitcher.ACTIVE_COLOR; - this.nonActiveColor = OpenLayers.Control.LayerSwitcher.NONACTIVE_COLOR; - this.backdrops = []; OpenLayers.Control.prototype.initialize.apply(this, arguments); }, + /** + * @param {OpenLayers.Map} map + */ + setMap: function(map) { + OpenLayers.Control.prototype.setMap.apply(this, arguments); + + this.map.events.register("addlayer", this, this.redraw); + this.map.events.register("changelayer", this, this.redraw); + this.map.events.register("removelayer", this, this.redraw); + this.map.events.register("changebaselayer", this, this.redraw); + }, + /** * @returns A reference to the DIV DOMElement containing the switcher tabs * @type DOMElement */ draw: function() { - // initialize our internal div OpenLayers.Control.prototype.draw.apply(this); + // create layout divs + this.loadContents(); + + // set mode to minimize + this.minimizeControl(); + + // populate div with current info + this.redraw(); + + return this.div; + }, + + /** Goes through and takes the current state of the Map and rebuilds the + * control to display that state. Groups base layers into a radio-button + * group and lists each data layer with a checkbox. + * + * @returns A reference to the DIV DOMElement containing the control + * @type DOMElement + */ + redraw: function() { + + //clear out previous layers + this.baseLayersDiv.innerHTML = ""; + this.baseLayerInputs = new Array(); + + this.dataLayersDiv.innerHTML = ""; + this.dataLayerInputs = new Array(); + + for( var i = 0; i < this.map.layers.length; i++) { + var layer = this.map.layers[i]; + var baseLayer = layer.isBaseLayer; + + // only check a baselayer if it is *the* baselayer, check data + // layers if they are visible + var checked = (baseLayer) ? (layer == this.map.baseLayer) + : layer.getVisibility(); + + // create input element + var inputElem = document.createElement("input"); + inputElem.id = "input_" + layer.name; + inputElem.name = (baseLayer) ? "baseLayers" : layer.name; + inputElem.type = (baseLayer) ? "radio" : "checkbox"; + inputElem.value = layer.name; + inputElem.checked = checked; + inputElem.layer = layer; + + // create span + var labelSpan = document.createElement("span"); + labelSpan.innerHTML = layer.name; + labelSpan.style.verticalAlign = (baseLayer) ? "bottom" : "auto"; + Event.observe(labelSpan, + "click", + this.onLabelClick.bindAsEventListener(inputElem)); + + // create line break + var br = document.createElement("br"); + + + var groupArray = (baseLayer) ? this.baseLayerInputs + : this.dataLayerInputs; + groupArray.push(inputElem); + + + var groupDiv = (baseLayer) ? this.baseLayersDiv + : this.dataLayersDiv; + groupDiv.appendChild(inputElem); + groupDiv.appendChild(labelSpan); + groupDiv.appendChild(br); + + } + + return this.div; + }, + + /** A label has been clicked, check or uncheck its corresponding input + * + * @private + * + * @param {Event} e + */ + onLabelClick: function(e) { + this.checked = !this.checked; + }, + + /** Need to update the map accordingly whenever user clicks in either of + * the layers. + * + * @private + * + * @param {Event} e + */ + onLayerClick: function(e) { + this.updateMap(); + }, + + + /** Cycles through the loaded data and base layer input arrays and makes + * the necessary calls to the Map object such that that the map's + * visual state corresponds to what the user has selected in the control + * + * @private + */ + updateMap: function() { + + // set the newly selected base layer + for(var i=0; i < this.baseLayerInputs.length; i++) { + var input = this.baseLayerInputs[i]; + if (input.checked) { + this.map.setBaseLayer(input.layer, true); + } + } + + // set the correct visibilities for the overlays + for(var i=0; i < this.dataLayerInputs.length; i++) { + var input = this.dataLayerInputs[i]; + input.layer.setVisibility(input.checked, true); + } + + }, + + /** Set up the labels and divs for the control + * + * @param {Event} e + */ + maximizeControl: function(e) { + + //HACK HACK HACK - find a way to auto-size this layerswitcher + this.div.style.width = "20em"; + this.div.style.height = ""; + + this.showControls(false); + + if (e != null) { + Event.stop(e); + } + }, + + /** Hide all the contents of the control, shrink the size, + * add the maximize icon + * + * @param {Event} e + */ + minimizeControl: function(e) { + + this.div.style.width = "0px"; + this.div.style.height = "0px"; + +// this.div.style.backgroundColor = "transparent"; + + this.showControls(true); + + if (e != null) { + Event.stop(e); + } + }, + + /** Hide/Show all LayerSwitcher controls depending on whether we are + * minimized or not + * + * @private + * + * @param {Boolean} minimize + */ + showControls: function(minimize) { + + this.maximizeDiv.style.display = minimize ? "" : "none"; + this.minimizeDiv.style.display = minimize ? "none" : ""; + + this.layersDiv.style.display = minimize ? "none" : ""; + }, + + /** Set up the labels and divs for the control + * + */ + loadContents: function() { + + //configure main div this.div.style.position = "absolute"; this.div.style.top = "10px"; this.div.style.right = "0px"; this.div.style.left = ""; this.div.style.fontFamily = "sans-serif"; - this.div.style.color = "white"; this.div.style.fontWeight = "bold"; this.div.style.marginTop = "3px"; this.div.style.marginLeft = "3px"; this.div.style.marginBottom = "3px"; - this.div.style.fontSize="smaller"; - this.div.style.width = "10em"; - - this.map.events.register("addlayer", this, this.redraw); - this.map.events.register("removelayer", this, this.redraw); - this.map.events.register("changelayer", this, this.redraw); - return this.redraw(); - }, - - /** - * @returns A reference to the DIV DOMElement containing the switcher tabs - * @type DOMElement - */ - redraw: function() { - - //clear out previous incarnation of LayerSwitcher tabs - this.div.innerHTML = ""; - var visible = false; - for( var i = 0; i < this.map.layers.length; i++) { - if (visible && this.mode == "radio") { - this.map.layers[i].setVisibility(false); - } else { - visible = this.map.layers[i].getVisibility(); - } - this.addTab(this.map.layers[i]); - } - - return this.div; - }, + this.div.style.fontSize = "smaller"; + this.div.style.color = "white"; + this.div.style.backgroundColor = "transparent"; - /** - * @param {event} evt - */ - singleClick: function(evt) { - var div = Event.element(evt); + Event.observe(this.div, "mouseup", + this.mouseUp.bindAsEventListener(this)); + Event.observe(this.div, "mousedown", + this.mouseDown.bindAsEventListener(this)); + Event.observe(this.div, "dblclick", this.ignoreEvent); - // See comment about OL #57 fix below. - // If the click occurred on the corner spans we need - // to make sure we act on the actual label tab instead. - div = div.labelElement || div; - var layer = div.layer; - if (this.mode == "radio") { - for(var i=0; i < this.backdrops.length; i++) { - this.setTabActivation(this.backdrops[i], false); - this.backdrops[i].layer.setVisibility(false); - } - this.setTabActivation(div, true); - layer.setVisibility(true); - } else { - var visible = layer.getVisibility(); - - this.setTabActivation(div, !visible); - layer.setVisibility(!visible); - } - Event.stop(evt); - }, - - /** - * @private - * - * @param {event} evt - */ - ignoreEvent: function(evt) { - Event.stop(evt); - return false; - }, + // layers list div + this.layersDiv = document.createElement("div"); + this.layersDiv.id = "layersDiv"; + this.layersDiv.style.paddingTop = "5px"; + this.layersDiv.style.paddingLeft = "10px"; + this.layersDiv.style.paddingBottom = "5px"; + this.layersDiv.style.paddingRight = "75px"; + this.layersDiv.style.backgroundColor = this.activeColor; - /** - * @private - * - * @param {OpenLayers.Layer} layer - */ - addTab: function(layer) { - - // Outer DIV - for Rico Corners + // had to set width/height to get transparency in IE to work. + // thanks -- http://jszen.blogspot.com/2005/04/ie6-opacity-filter-caveat.html // - var backdropLabelOuter = document.createElement('div'); - backdropLabelOuter.id = "LayerSwitcher_" + layer.name + "_Tab"; - backdropLabelOuter.style.marginTop = "4px"; - backdropLabelOuter.style.marginBottom = "4px"; - - this._setEventHandlers(backdropLabelOuter); + this.layersDiv.style.width = "100%"; + this.layersDiv.style.height = "100%"; - // Inner Label - for Rico Corners - // - var backdropLabel = document.createElement('p'); - backdropLabel.innerHTML = layer.name; - backdropLabel.style.marginTop = "0px"; - backdropLabel.style.marginBottom = "0px"; - backdropLabel.style.paddingLeft = "10px"; - backdropLabel.style.paddingRight = "10px"; - - // add reference to layer onto the div for use in event handlers - backdropLabel.layer = layer; - // set event handlers - this._setEventHandlers(backdropLabel); - - // add label to div - backdropLabelOuter.appendChild(backdropLabel); + var baseLbl = document.createElement("div"); + baseLbl.innerHTML = "Base Layer"; + baseLbl.style.marginTop = "3px"; + baseLbl.style.marginLeft = "3px"; + baseLbl.style.marginBottom = "3px"; + this.layersDiv.appendChild(baseLbl); - this.backdrops.append(backdropLabel); - - // add div to main LayerSwitcher Div - this.div.appendChild(backdropLabelOuter); + this.baseLayersDiv = document.createElement("div"); + this.baseLayersDiv.style.paddingLeft = "10px"; + Event.observe(this.baseLayersDiv, "click", + this.onLayerClick.bindAsEventListener(this)); + this.layersDiv.appendChild(this.baseLayersDiv); + - Rico.Corner.round(backdropLabelOuter, {corners: "tl bl", + var dataLbl = document.createElement("div"); + dataLbl.innerHTML = "Overlays"; + dataLbl.style.marginTop = "3px"; + dataLbl.style.marginLeft = "3px"; + dataLbl.style.marginBottom = "3px"; + this.layersDiv.appendChild(dataLbl); + + this.dataLayersDiv = document.createElement("div"); + this.dataLayersDiv.style.paddingLeft = "10px"; + Event.observe(this.dataLayersDiv, "click", + this.onLayerClick.bindAsEventListener(this)); + this.layersDiv.appendChild(this.dataLayersDiv); + + this.div.appendChild(this.layersDiv); + + Rico.Corner.round(this.div, {corners: "tl bl", bgColor: "transparent", - color: "white", + color: this.activeColor, blend: false}); - // extend the event handlers to operate on the - // rounded corners as well. (Fixes OL #57.) - var spanElements=backdropLabel.parentNode.getElementsByTagName("span"); + Rico.Corner.changeOpacity(this.layersDiv, 0.75); + + var imgLocation = OpenLayers.Util.getImagesLocation(); + var sz = new OpenLayers.Size(18,18); + + // maximize button div + var img = imgLocation + 'layer-switcher-maximize.png'; + this.maximizeDiv = OpenLayers.Util.createAlphaImageDiv( + "OpenLayers_Control_ResizeDiv", + null, + sz, + img, + "absolute"); + this.maximizeDiv.style.top = "5px"; + this.maximizeDiv.style.right = "0px"; + this.maximizeDiv.style.left = ""; + this.maximizeDiv.style.display = "none"; + Event.observe(this.maximizeDiv, + "click", + this.maximizeControl.bindAsEventListener(this)); - for (var currIdx = 0; currIdx < spanElements.length; currIdx++) { - this._setEventHandlers(spanElements[currIdx], backdropLabel); - } + this.div.appendChild(this.maximizeDiv); - this.setTabActivation(backdropLabel, layer.getVisibility()); + // minimize button div + var img = imgLocation + 'layer-switcher-minimize.png'; + var sz = new OpenLayers.Size(18,18); + this.minimizeDiv = OpenLayers.Util.createAlphaImageDiv( + "OpenLayers_Control_ResizeDiv", + null, + sz, + img, + "absolute"); + this.minimizeDiv.style.top = "5px"; + this.minimizeDiv.style.right = "0px"; + this.minimizeDiv.style.left = ""; + this.minimizeDiv.style.display = "none"; + Event.observe(this.minimizeDiv, + "click", + this.minimizeControl.bindAsEventListener(this)); + + this.div.appendChild(this.minimizeDiv); }, - - /* - @private - @param {DOMElement} div - @param {Boolean} activate - */ - _setEventHandlers : function(element, labelDiv) { + /** + * @private + * + * @param {Event} evt + */ + ignoreEvent: function(evt) { + Event.stop(evt); + }, - // We only want to respond to a mousedown event. - element.onclick = this.singleClick.bindAsEventListener(this); - element.ondblclick = this.singleClick.bindAsEventListener(this); - element.onmouseup = this.ignoreEvent.bindAsEventListener(this); - element.onmousedown = this.ignoreEvent.bindAsEventListener(this); + /** Register a local 'mouseDown' flag so that we'll know whether or not + * to ignore a mouseUp event + * + * @private + * + * @param {Event} evt + */ + mouseDown: function(evt) { + this.mouseDown = true; + this.ignoreEvent(evt); + }, - // If we are operating on a corner span we need to store a - // reference to the actual tab. (See comment about OL #57 fix above.) - if (labelDiv) { - element.labelElement = labelDiv; + /** If the 'mouseDown' flag has been set, that means that the drag was + * started from within the LayerSwitcher control, and thus we can + * ignore the mouseup. Otherwise, let the Event continue. + * + * @private + * + * @param {Event} evt + */ + mouseUp: function(evt) { + if (this.mouseDown) { + this.mouseDown = false; + this.ignoreEvent(evt); } }, - /** - * @private - * - * @param {DOMElement} div - * @param {Boolean} activate - */ - setTabActivation:function(div, activate) { - var color = (activate) ? this.activeColor : this.nonActiveColor; - Rico.Corner.changeColor(div, color); - }, - - - /** @final @type String */ CLASS_NAME: "OpenLayers.Control.LayerSwitcher" }); - diff --git a/lib/OpenLayers/Control/LayerTabs.js b/lib/OpenLayers/Control/LayerTabs.js new file mode 100644 index 0000000000..ca7214979a --- /dev/null +++ b/lib/OpenLayers/Control/LayerTabs.js @@ -0,0 +1,224 @@ +/* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license. + * See http://svn.openlayers.org/trunk/openlayers/license.txt for the full + * text of the license. */ +// @require: OpenLayers/Control.js +/** +* @class +*/ +OpenLayers.Control.LayerTabs = Class.create(); + +/** color used in the UI to show a layer is active/displayed +* +* @final +* @type String +*/ +OpenLayers.Control.LayerTabs.ACTIVE_COLOR = "darkblue"; + +/** color used in the UI to show a layer is deactivated/hidden +* +* @final +* @type String +*/ +OpenLayers.Control.LayerTabs.NONACTIVE_COLOR = "lightblue"; + + +OpenLayers.Control.LayerTabs.prototype = + Object.extend( new OpenLayers.Control(), { + + /** @type String */ + activeColor: "", + + /** @type String */ + nonActiveColor: "", + + /** @type String */ + mode: "checkbox", + + /** + * @constructor + */ + initialize: function(options) { + this.activeColor = OpenLayers.Control.LayerTabs.ACTIVE_COLOR; + this.nonActiveColor = OpenLayers.Control.LayerTabs.NONACTIVE_COLOR; + this.backdrops = []; + OpenLayers.Control.prototype.initialize.apply(this, arguments); + }, + + /** + * @returns A reference to the DIV DOMElement containing the switcher tabs + * @type DOMElement + */ + draw: function() { + // initialize our internal div + OpenLayers.Control.prototype.draw.apply(this); + + this.div.style.position = "absolute"; + this.div.style.top = "10px"; + this.div.style.right = "0px"; + this.div.style.left = ""; + this.div.style.fontFamily = "sans-serif"; + this.div.style.color = "white"; + this.div.style.fontWeight = "bold"; + this.div.style.marginTop = "3px"; + this.div.style.marginLeft = "3px"; + this.div.style.marginBottom = "3px"; + this.div.style.fontSize="smaller"; + this.div.style.width = "10em"; + + this.map.events.register("addlayer", this, this.redraw); + this.map.events.register("removelayer", this, this.redraw); + return this.redraw(); + }, + + /** + * @returns A reference to the DIV DOMElement containing the switcher tabs + * @type DOMElement + */ + redraw: function() { + + //clear out previous incarnation of LayerTabs tabs + this.div.innerHTML = ""; + var visible = false; + for( var i = 0; i < this.map.layers.length; i++) { + if (visible && this.mode == "radio") { + this.map.layers[i].setVisibility(false); + } else { + visible = this.map.layers[i].getVisibility(); + } + this.addTab(this.map.layers[i]); + } + + return this.div; + }, + + /** + * @param {event} evt + */ + singleClick: function(evt) { + var div = Event.element(evt); + + // See comment about OL #57 fix below. + // If the click occurred on the corner spans we need + // to make sure we act on the actual label tab instead. + div = div.labelElement || div; + + var layer = div.layer; + if (this.mode == "radio") { + for(var i=0; i < this.backdrops.length; i++) { + this.setTabActivation(this.backdrops[i], false); + this.backdrops[i].layer.setVisibility(false); + } + this.setTabActivation(div, true); + layer.setVisibility(true); + } else { + var visible = layer.getVisibility(); + + this.setTabActivation(div, !visible); + layer.setVisibility(!visible); + } + Event.stop(evt); + }, + + /** + * @private + * + * @param {event} evt + */ + ignoreEvent: function(evt) { + Event.stop(evt); + return false; + }, + + /** + * @private + * + * @param {OpenLayers.Layer} layer + */ + addTab: function(layer) { + + // Outer DIV - for Rico Corners + // + var backdropLabelOuter = document.createElement('div'); + backdropLabelOuter.id = "LayerTabs_" + layer.name + "_Tab"; + backdropLabelOuter.style.marginTop = "4px"; + backdropLabelOuter.style.marginBottom = "4px"; + + this._setEventHandlers(backdropLabelOuter); + + // Inner Label - for Rico Corners + // + var backdropLabel = document.createElement('p'); + backdropLabel.innerHTML = layer.name; + backdropLabel.style.marginTop = "0px"; + backdropLabel.style.marginBottom = "0px"; + backdropLabel.style.paddingLeft = "10px"; + backdropLabel.style.paddingRight = "10px"; + + // add reference to layer onto the div for use in event handlers + backdropLabel.layer = layer; + + // set event handlers + this._setEventHandlers(backdropLabel); + + // add label to div + backdropLabelOuter.appendChild(backdropLabel); + + this.backdrops.append(backdropLabel); + + // add div to main LayerTabs Div + this.div.appendChild(backdropLabelOuter); + + Rico.Corner.round(backdropLabelOuter, {corners: "tl bl", + bgColor: "transparent", + color: "white", + blend: false}); + + // extend the event handlers to operate on the + // rounded corners as well. (Fixes OL #57.) + var spanElements=backdropLabel.parentNode.getElementsByTagName("span"); + + for (var currIdx = 0; currIdx < spanElements.length; currIdx++) { + this._setEventHandlers(spanElements[currIdx], backdropLabel); + } + + this.setTabActivation(backdropLabel, layer.getVisibility()); + }, + + /* + @private + + @param {DOMElement} div + @param {Boolean} activate + */ + _setEventHandlers : function(element, labelDiv) { + + // We only want to respond to a mousedown event. + element.onclick = this.singleClick.bindAsEventListener(this); + element.ondblclick = this.singleClick.bindAsEventListener(this); + element.onmouseup = this.ignoreEvent.bindAsEventListener(this); + element.onmousedown = this.ignoreEvent.bindAsEventListener(this); + + // If we are operating on a corner span we need to store a + // reference to the actual tab. (See comment about OL #57 fix above.) + if (labelDiv) { + element.labelElement = labelDiv; + } + }, + + /** + * @private + * + * @param {DOMElement} div + * @param {Boolean} activate + */ + setTabActivation:function(div, activate) { + var color = (activate) ? this.activeColor : this.nonActiveColor; + Rico.Corner.changeColor(div, color); + }, + + + + /** @final @type String */ + CLASS_NAME: "OpenLayers.Control.LayerTabs" +}); + diff --git a/lib/OpenLayers/Control/MouseToolbar.js b/lib/OpenLayers/Control/MouseToolbar.js index 161a15cd08..9df72d5b3c 100644 --- a/lib/OpenLayers/Control/MouseToolbar.js +++ b/lib/OpenLayers/Control/MouseToolbar.js @@ -85,6 +85,7 @@ OpenLayers.Control.MouseToolbar.prototype = */ defaultDblClick: function (evt) { this.switchModeTo("pan"); + this.performedDrag = false; var newCenter = this.map.getLonLatFromViewPortPx( evt.xy ); this.map.setCenter(newCenter, this.map.zoom + 2); }, @@ -95,6 +96,7 @@ OpenLayers.Control.MouseToolbar.prototype = defaultMouseDown: function (evt) { if (!Event.isLeftClick(evt)) return; this.mouseDragStart = evt.xy.clone(); + this.performedDrag = false; if (evt.shiftKey && this.mode !="zoombox") { this.switchModeTo("zoombox"); } else if (evt.altKey && this.mode !="measure") { @@ -217,6 +219,7 @@ OpenLayers.Control.MouseToolbar.prototype = this.map.setCenter(newCenter, null, true); this.mouseDragStart = evt.xy.clone(); } + this.performedDrag = true; } }, @@ -244,8 +247,9 @@ OpenLayers.Control.MouseToolbar.prototype = this.leaveMode(); break; case "pan": - this.map.setCenter(this.map.center); - + if (this.performedDrag) { + this.map.setCenter(this.map.center); + } } document.onselectstart = null; this.mouseDragStart = null; diff --git a/lib/OpenLayers/Icon.js b/lib/OpenLayers/Icon.js index f0c8d93e69..bcd5f8b73f 100644 --- a/lib/OpenLayers/Icon.js +++ b/lib/OpenLayers/Icon.js @@ -95,15 +95,28 @@ OpenLayers.Icon.prototype = { this.px = px; } - if ((this.px != null) && (this.imageDiv != null)) { - if (this.calculateOffset) { - this.offset = this.calculateOffset(this.size); + 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); + this.display(true); } - var offsetPx = this.px.offset(this.offset); - OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, offsetPx); } }, + /** Hide or show the icon + * + * @param {Boolean} display + */ + display: function(display) { + this.imageDiv.style.display = (display) ? "" : "none"; + }, + /** @final @type String */ CLASS_NAME: "OpenLayers.Icon" }; \ No newline at end of file diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index 3559b1e008..036378cfb9 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -22,7 +22,14 @@ OpenLayers.Layer.prototype = { * @type OpenLayers.Map */ map: null, - + /** Whether or not the layer is a base layer. This should be set + * individually by all subclasses. + * Default is false + * + * @type Boolean + */ + isBaseLayer: false, + // OPTIONS /** @type Array */ @@ -135,6 +142,12 @@ OpenLayers.Layer.prototype = { moveTo:function(bounds, zoomChanged, minor) { //this function can be implemented by subclasses. }, + + /** + */ + reproject:function() { + //this function can be implemented by subclasses. + }, /** Set the map property for the layer. This is done through an accessor * so that subclasses can override this and take special action once @@ -146,16 +159,6 @@ OpenLayers.Layer.prototype = { this.map = map; }, - /** - * @returns Whether or not the layer is a base layer. This should be - * determined individually by all subclasses. Default is false - * @type Boolean - */ - isBaseLayer: function() { - //this function should be implemented by all subclasses. - return false; - }, - /** * @returns Whether or not the layer is visible * @type Boolean @@ -165,18 +168,20 @@ OpenLayers.Layer.prototype = { }, /** - * @param {bool} visible - */ - setVisibility: function(visible) { + * @param {Boolean} visible + * @param {Boolean} noEvent + */ + setVisibility: function(visible, noEvent) { if (visible != this.getVisibility()) { this.div.style.display = (visible) ? "block" : "none"; - if (this.map != null) { - if (visible) { - var extent = this.map.getExtent(); - if (extent != null) { - this.moveTo(this.map.getExtent()); - } + if ((visible) && (this.map != null)) { + var extent = this.map.getExtent(); + if (extent != null) { + this.moveTo(this.map.getExtent()); } + } + if ((this.map != null) && + ((noEvent == null) || (noEvent == false))) { this.map.events.triggerEvent("changelayer"); } } diff --git a/lib/OpenLayers/Layer/Boxes.js b/lib/OpenLayers/Layer/Boxes.js new file mode 100644 index 0000000000..009a86d724 --- /dev/null +++ b/lib/OpenLayers/Layer/Boxes.js @@ -0,0 +1,45 @@ +/* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license. + * See http://svn.openlayers.org/trunk/openlayers/license.txt for the full + * text of the license. */ +// @require: OpenLayers/Layer.js +// @require: OpenLayers/Layer/Markers.js +/** +* @class +*/ +OpenLayers.Layer.Boxes = Class.create(); +OpenLayers.Layer.Boxes.prototype = + Object.extend( new OpenLayers.Layer.Markers(), { + + initialize: function () { + OpenLayers.Layer.Markers.prototype.initialize.apply(this, arguments); + }, + + /** Calculate the pixel location for the marker, create it, and + * add it to the layer's div + * + * @private + * + * @param {OpenLayers.Marker.Box} marker + */ + drawMarker: function(marker) { + var bounds = marker.bounds; + var topleft = this.map.getLayerPxFromLonLat( + new OpenLayers.LonLat(bounds.left, bounds.top)); + var botright = this.map.getLayerPxFromLonLat( + new OpenLayers.LonLat(bounds.right, bounds.bottom)); + if (botright == null || topleft == null) { + marker.display(false); + } else { + var sz = new OpenLayers.Size( + botright.x - topleft.x, botright.y - topleft.y); + var markerDiv = marker.draw(topleft, sz); + if (!marker.drawn) { + this.div.appendChild(markerDiv); + marker.drawn = true; + } + } + }, + + /** @final @type String */ + CLASS_NAME: "OpenLayers.Layer.Boxes" +}); diff --git a/lib/OpenLayers/Layer/GeoRSS.js b/lib/OpenLayers/Layer/GeoRSS.js index df75e10ae9..cd92fd4a13 100644 --- a/lib/OpenLayers/Layer/GeoRSS.js +++ b/lib/OpenLayers/Layer/GeoRSS.js @@ -10,6 +10,11 @@ OpenLayers.Layer.GeoRSS = Class.create(); OpenLayers.Layer.GeoRSS.prototype = Object.extend( new OpenLayers.Layer.Markers(), { + /** GeoRSS layer is never a base layer. + * @type Boolean + */ + isBaseLayer: false, + /** store url of text file * @type str */ location:null, @@ -41,15 +46,7 @@ OpenLayers.Layer.GeoRSS.prototype = this.features = null; OpenLayers.Layer.Markers.prototype.destroy.apply(this, arguments); }, - - /** WFS layer is never a base class. - * @type Boolean - */ - isBaseLayer: function() { - return false; - }, - - + /** * @param {?} ajaxRequest */ diff --git a/lib/OpenLayers/Layer/Google.js b/lib/OpenLayers/Layer/Google.js index 576dc434d4..0cd41d3c4e 100644 --- a/lib/OpenLayers/Layer/Google.js +++ b/lib/OpenLayers/Layer/Google.js @@ -37,14 +37,27 @@ if (typeof GMap2 != "undefined") { OpenLayers.Layer.Google = Class.create(); OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), { + + /** Google layer is always base layer + * + * @type Boolean + */ + isBaseLayer: true, + /** @type Boolean */ isFixed: true, /** @type GMap2 gmap stores the Google Map element */ gmap:null, + + /** @type GMapType */ + type: null, /** @type Boolean */ dragging:false, + + /** @type Boolean */ + dontListen:false, // OPTIONS @@ -82,19 +95,13 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), { setMap:function(map) { OpenLayers.Layer.prototype.setMap.apply(this, arguments); - // once our layer has been added to the map, we can create the vemap - this.map.events.register("addlayer", this, this.loadGMap); + // once our layer has been added to the map, we can load it + this.loadGMap(); }, - /** Google layer is a base class if the GMap loaded correctly. - * @type Boolean - */ - isBaseLayer: function() { - return (this.gmap != null); - }, - - /** Assuming we are not dragging (in which case GMaps moving itself) - * we need to move the gmap to the new center/zoom + /** Assuming we are not dragging (in which case GMaps is moving itself, + * and the dragging flag is set) we need to move the gmap to the + * new center/zoom * * @param {OpenLayers.Bounds} bounds * @param {Boolean} zoomChanged @@ -117,9 +124,16 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), { if ( (!newCenter.equals(currentCenter)) || (newZoom != currentZoom) ) { + this.dontListen = true; this.gmap.setCenter(this.getGLatLngFromOLLonLat(newCenter), this.getGZoomFromOLZoom(newZoom)); - + + if (this.type != null) { + this.gmap.setMapType(this.type); + this.type = null; + } + + this.dontListen = false; } } } @@ -136,11 +150,12 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), { //has gmaps library has been loaded? try { // create GMap, hide nav controls - this.gmap = new GMap2(this.div); - + this.gmap = new GMap2(this.div ); + // this causes the GMap to set itself to Map's center/zoom this.moveTo(); - + + // catch pans and zooms from GMap GEvent.addListener(this.gmap, "moveend", @@ -240,14 +255,17 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), { * @param {event} e */ catchPanZoom: function(e) { + + if (!this.dontListen) { - var gCenter = this.gmap.getCenter(); - var gZoom = this.gmap.getZoom(); - - var olCenter = this.getOLLonLatFromGLatLng(gCenter); - var olZoom = this.getOLZoomFromGZoom(gZoom); - - this.map.setCenter(olCenter, olZoom); + var gCenter = this.gmap.getCenter(); + var gZoom = this.gmap.getZoom(); + + var olCenter = this.getOLLonLatFromGLatLng(gCenter); + var olZoom = this.getOLZoomFromGZoom(gZoom); + + this.map.setCenter(olCenter, olZoom, this.dragging); + } }, @@ -338,7 +356,7 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), { getOLZoomFromGZoom: function(gZoom) { var zoom = null; if (gZoom != null) { - zoom = gZoom - 1; + zoom = gZoom; } return zoom; }, @@ -353,7 +371,7 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), { getGZoomFromOLZoom: function(olZoom) { var zoom = null; if (olZoom != null) { - zoom = olZoom + 1; + zoom = olZoom; } return zoom; }, diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index a511954ea0..9904e7046f 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -136,7 +136,7 @@ OpenLayers.Layer.Grid.prototype = */ moveTo:function(bounds, zoomChanged, minor) { if (bounds == null) { - bounds = this.map.getBounds(); + bounds = this.map.getExtent(); } if (bounds != null) { if (!this.getVisibility()) { diff --git a/lib/OpenLayers/Layer/KaMap.js b/lib/OpenLayers/Layer/KaMap.js index 05fd110b93..838a491641 100644 --- a/lib/OpenLayers/Layer/KaMap.js +++ b/lib/OpenLayers/Layer/KaMap.js @@ -10,7 +10,13 @@ OpenLayers.Layer.KaMap = Class.create(); OpenLayers.Layer.KaMap.prototype = Object.extend( new OpenLayers.Layer.Grid(), { - + + /** KaMap Layer is always a base layer + * + * @type Boolean + */ + isBaseLayer: true, + units: 'degrees', scales: {inches: 1, feet: 12, miles: 63360.0, meters: 39.3701, kilometers: 39370.1, degrees: 4374754}, @@ -118,9 +124,7 @@ OpenLayers.Layer.KaMap.prototype = } while(tileoffsetlat > bounds.bottom - tilelat) }, - isBaseLayer: function() { - return true; - }, + /** @final @type String */ CLASS_NAME: "OpenLayers.Layer.KaMap" }); diff --git a/lib/OpenLayers/Layer/Markers.js b/lib/OpenLayers/Layer/Markers.js index d1c59d1d64..212b44a820 100644 --- a/lib/OpenLayers/Layer/Markers.js +++ b/lib/OpenLayers/Layer/Markers.js @@ -9,6 +9,12 @@ OpenLayers.Layer.Markers = Class.create(); OpenLayers.Layer.Markers.prototype = Object.extend( new OpenLayers.Layer(), { + /** Markers layer is never a base layer. + * + * @type Boolean + */ + isBaseLayer: false, + /** internal marker list * @type Array(OpenLayers.Marker) */ markers: null, @@ -44,17 +50,18 @@ OpenLayers.Layer.Markers.prototype = this.redraw(); } }, - - /** WFS layer is never a base class. - * @type Boolean - */ - isBaseLayer: function() { - return false; - }, - + + /** - * @param {OpenLayers.Marker} marker - */ + */ + reproject:function() { + this.redraw(); + }, + + + /** + * @param {OpenLayers.Marker} marker + */ addMarker: function(marker) { this.markers.append(marker); if (this.map && this.map.getExtent()) { @@ -103,7 +110,9 @@ OpenLayers.Layer.Markers.prototype = */ drawMarker: function(marker) { var px = this.map.getLayerPxFromLonLat(marker.lonlat); - if (px != null) { + if (px == null) { + marker.display(false); + } else { var markerImg = marker.draw(px); if (!marker.drawn) { this.div.appendChild(markerImg); diff --git a/lib/OpenLayers/Layer/Text.js b/lib/OpenLayers/Layer/Text.js index 20a2fca4a8..fc4557f117 100644 --- a/lib/OpenLayers/Layer/Text.js +++ b/lib/OpenLayers/Layer/Text.js @@ -10,6 +10,12 @@ OpenLayers.Layer.Text = Class.create(); OpenLayers.Layer.Text.prototype = Object.extend( new OpenLayers.Layer.Markers(), { + /** Text layer is never a base layer. + * + * @type Boolean + */ + isBaseLayer: false, + /** store url of text file - this should be specified in the "options" hash * @type str */ location:null, @@ -44,13 +50,6 @@ OpenLayers.Layer.Text.prototype = OpenLayers.Layer.Markers.prototype.destroy.apply(this, arguments); }, - /** Text layer is never a base class. - * @type Boolean - */ - isBaseLayer: function() { - return false; - }, - /** * @param {?} ajaxRequest diff --git a/lib/OpenLayers/Layer/VirtualEarth.js b/lib/OpenLayers/Layer/VirtualEarth.js index 1f2a087869..1726ba3b4a 100644 --- a/lib/OpenLayers/Layer/VirtualEarth.js +++ b/lib/OpenLayers/Layer/VirtualEarth.js @@ -11,6 +11,12 @@ OpenLayers.Layer.VirtualEarth = Class.create(); OpenLayers.Layer.VirtualEarth.prototype = Object.extend( new OpenLayers.Layer(), { + /** Virtual Earth layer is always a base layer. + * + * @type Boolean + */ + isBaseLayer: true, + /** @type Boolean */ isFixed: true, @@ -32,15 +38,8 @@ OpenLayers.Layer.VirtualEarth.prototype = setMap:function(map) { OpenLayers.Layer.prototype.setMap.apply(this, arguments); - // once our layer has been added to the map, we can create the vemap - this.map.events.register("addlayer", this, this.loadVEMap); - }, - - /** Virtual Earth layer is always a base class. - * @type Boolean - */ - isBaseLayer: function() { - return true; + // once our layer has been added to the map, we can load the vemap + this.loadVEMap(); }, /** @@ -257,7 +256,7 @@ OpenLayers.Layer.VirtualEarth.prototype = getOLZoomFromVEZoom: function(veZoom) { var zoom = null; if (veZoom != null) { - zoom = veZoom - 1; + zoom = veZoom; } return zoom; }, @@ -272,7 +271,7 @@ OpenLayers.Layer.VirtualEarth.prototype = getVEZoomFromOLZoom: function(olZoom) { var zoom = null; if (olZoom != null) { - zoom = olZoom + 1; + zoom = olZoom; } return zoom; }, diff --git a/lib/OpenLayers/Layer/WFS.js b/lib/OpenLayers/Layer/WFS.js index 7153994181..39bcb5090b 100644 --- a/lib/OpenLayers/Layer/WFS.js +++ b/lib/OpenLayers/Layer/WFS.js @@ -11,6 +11,12 @@ OpenLayers.Layer.WFS.prototype = Object.extend(new OpenLayers.Layer.Grid(), Object.extend(new OpenLayers.Layer.Markers(), { + /** WFS layer is never a base layer. + * + * @type Boolean + */ + isBaseLayer: false, + /** Allow the user to specify special classes for features and tiles. * * This allows for easy-definition of behaviour. The defaults are @@ -47,6 +53,12 @@ OpenLayers.Layer.WFS.prototype = newArguments.push(name, url, params, options); } OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments); + + var newArguments = new Array(); + if (arguments.length > 0) { + //uppercase params + newArguments.push(name, options); + } OpenLayers.Layer.Markers.prototype.initialize.apply(this, newArguments); if (arguments.length > 0) { @@ -83,14 +95,7 @@ OpenLayers.Layer.WFS.prototype = OpenLayers.Layer.Grid.prototype.moveTo.apply(this, arguments); OpenLayers.Layer.Markers.prototype.moveTo.apply(this, arguments); }, - - /** WFS layer is never a base class. - * @type Boolean - */ - isBaseLayer: function() { - return false; - }, - + /** * @param {Object} obj * diff --git a/lib/OpenLayers/Layer/WMS.js b/lib/OpenLayers/Layer/WMS.js index 4960578c5a..ebb9c00811 100644 --- a/lib/OpenLayers/Layer/WMS.js +++ b/lib/OpenLayers/Layer/WMS.js @@ -18,6 +18,14 @@ OpenLayers.Layer.WMS.prototype = format: "image/jpeg" }, + /** WMS layer by default is a base layer. + * If the user wishes to use a WMS as a datalayer, s/he needs only + * set this property to false. + * + * @type Boolean + */ + isBaseLayer: true, + /** * @constructor * @@ -74,15 +82,7 @@ OpenLayers.Layer.WMS.prototype = return obj; }, - - - /** WMS layer is never a base class. - * @type Boolean - */ - isBaseLayer: function() { - return (this.params.TRANSPARENT != 'true'); - }, - + /** * addTile creates a tile, initializes it, and * adds it to the layer div. diff --git a/lib/OpenLayers/Layer/WMS/Untiled.js b/lib/OpenLayers/Layer/WMS/Untiled.js index ab78944648..08d0d40fa7 100644 --- a/lib/OpenLayers/Layer/WMS/Untiled.js +++ b/lib/OpenLayers/Layer/WMS/Untiled.js @@ -20,6 +20,12 @@ OpenLayers.Layer.WMS.Untiled.prototype = format: "image/jpeg" }, + + /** WMS.Untiled layer is never a base layer. + * @type Boolean + */ + isBaseLayer: false, + /** @type DOMElement */ imgDiv: null, @@ -81,14 +87,6 @@ OpenLayers.Layer.WMS.Untiled.prototype = }, - /** WFS layer is never a base class. - * @type Boolean - */ - isBaseLayer: function() { - return false; //(this.params.TRANSPARENT != true); - }, - - /** Once HTTPRequest has set the map, we can load the image div * * @param {OpenLayers.Map} map diff --git a/lib/OpenLayers/Layer/WorldWind.js b/lib/OpenLayers/Layer/WorldWind.js index 14236ab83a..98b6611c5b 100644 --- a/lib/OpenLayers/Layer/WorldWind.js +++ b/lib/OpenLayers/Layer/WorldWind.js @@ -12,6 +12,12 @@ OpenLayers.Layer.WorldWind.prototype = DEFAULT_PARAMS: { }, + /** WorldWind layer is always a base layer + * + * @type Boolean + */ + isBaseLayer: true, + // LevelZeroTileSizeDegrees lzd: null, @@ -55,9 +61,7 @@ OpenLayers.Layer.WorldWind.prototype = return tile; } }, - isBaseLayer: function() { - return true; - }, + /** @final @type String */ CLASS_NAME: "OpenLayers.Layer.WorldWind" }); diff --git a/lib/OpenLayers/Layer/Yahoo.js b/lib/OpenLayers/Layer/Yahoo.js index cbf6d417ce..8a9824b7de 100644 --- a/lib/OpenLayers/Layer/Yahoo.js +++ b/lib/OpenLayers/Layer/Yahoo.js @@ -12,6 +12,12 @@ document.write(" + + +
+ + diff --git a/tests/test_Layer.html b/tests/test_Layer.html index cc15c065fc..e2db4f3251 100644 --- a/tests/test_Layer.html +++ b/tests/test_Layer.html @@ -24,7 +24,7 @@ t.eq( layer.options["chicken"], 151 , "layer.options correctly made fresh copy" ); - t.eq( layer.isBaseLayer(), false, "Default layer is not base layer" ); + t.eq( layer.isBaseLayer, false, "Default layer is not base layer" ); layer = new OpenLayers.Layer('Test Layer'); t.ok( layer instanceof OpenLayers.Layer, "new OpenLayers.Layer returns object" ); diff --git a/tests/test_Layer_Google.html b/tests/test_Layer_Google.html index 5a8a588ead..2b025101c7 100644 --- a/tests/test_Layer_Google.html +++ b/tests/test_Layer_Google.html @@ -23,17 +23,11 @@ } function test_02_Layer_Google_isBaseLayer (t) { - t.plan(2); + t.plan(1); - var map = new OpenLayers.Map('map'); var layer = new OpenLayers.Layer.Google('Goog Layer'); - map.addLayer(layer); - t.ok(layer.isBaseLayer(), "a default load of google layer responds as a base layer"); - - layer.gmap = null; - - t.ok(!layer.isBaseLayer(), "a bad load of google layer does not respond as a base layer"); + t.ok(layer.isBaseLayer, "a default load of google layer responds as a base layer"); } function test_03_Layer_Google_Translation_zoom (t) { @@ -48,7 +42,7 @@ // the code afterwards works by itself to test that translation // works correctly both ways. var gZoom = 5; - var correspondingOLZoom = 4; + var correspondingOLZoom = 5; olZoom = layer.getOLZoomFromGZoom(gZoom); diff --git a/tests/test_Layer_Grid.html b/tests/test_Layer_Grid.html index 8c1b878766..89043e740d 100644 --- a/tests/test_Layer_Grid.html +++ b/tests/test_Layer_Grid.html @@ -49,10 +49,6 @@ map.setCenter(new OpenLayers.LonLat(0,0)); - layer = new OpenLayers.Layer.WMS(name, url, params); - map.addLayer(layer); - - map.setCenter(new OpenLayers.LonLat(0,0), 5); //grab a reference to one of the tiles var tile = layer.grid[0][0]; diff --git a/tests/test_Layer_KaMap.html b/tests/test_Layer_KaMap.html index b8298e281b..94e1ae8481 100644 --- a/tests/test_Layer_KaMap.html +++ b/tests/test_Layer_KaMap.html @@ -43,11 +43,6 @@ map.setCenter(new OpenLayers.LonLat(0,0)); - layer = new OpenLayers.Layer.KaMap(name, url, params, units); - map.addLayer(layer); - - map.setCenter(new OpenLayers.LonLat(0,0), 5); - //grab a reference to one of the tiles var tile = layer.grid[0][0]; diff --git a/tests/test_Layer_WMS.html b/tests/test_Layer_WMS.html index 84125f1724..5ef1f628f5 100644 --- a/tests/test_Layer_WMS.html +++ b/tests/test_Layer_WMS.html @@ -99,16 +99,12 @@ function test_05_Layer_WMS_isBaseLayer(t) { - t.plan(2); + t.plan(1); var url = "http://octo.metacarta.com/cgi-bin/mapserv"; layer = new OpenLayers.Layer.WMS(name, url, params); - t.ok( layer.isBaseLayer(), "baselayer is true when no transparent set"); - - layer.params.TRANSPARENT = "true"; - - t.ok( !layer.isBaseLayer(), "baselayer is false when transparent set"); + t.ok( layer.isBaseLayer, "baselayer is true by default"); } function test_06_Layer_WMS_mergeNewParams (t) { diff --git a/tests/test_Map.html b/tests/test_Map.html index 74fbfb3c11..64e780a485 100644 --- a/tests/test_Map.html +++ b/tests/test_Map.html @@ -223,6 +223,37 @@ t.ok( gotLayer == null, "getLayer correctly returns null when layer not found"); } + function test_10_Map_setBaseLayer(t) { + t.plan( 4 ); + + map = new OpenLayers.Map($('map')); + + var wmslayer = new OpenLayers.Layer.WMS('Test Layer', + "http://octo.metacarta.com/cgi-bin/mapserv", + {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}, + {maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805" } ); + + var wmslayer2 = new OpenLayers.Layer.WMS('Test Layer2', + "http://octo.metacarta.com/cgi-bin/mapserv", + {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}, + {maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805" } ); + + map.addLayers([wmslayer, wmslayer2]); + + t.ok(map.baseLayer == wmslayer, "default base layer is first one added"); + + map.setBaseLayer(null); + t.ok(map.baseLayer == wmslayer, "setBaseLayer on null object does nothing (and does not break)"); + + map.setBaseLayer("chicken"); + t.ok(map.baseLayer == wmslayer, "setBaseLayer on non-layer object does nothing (and does not break)"); + + map.setBaseLayer(wmslayer2); + t.ok(map.baseLayer == wmslayer2, "setbaselayer correctly sets 'baseLayer' property"); + + } + + function test_99_Map_destroy (t) { t.plan( 2 ); map = new OpenLayers.Map($('map'));