Changeset 1634
- Timestamp:
- 10/05/06 23:28:53 (2 years ago)
- Files:
-
- trunk/openlayers/lib/OpenLayers.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Control/ArgParser.js (copied) (copied from trunk/openlayers/lib/OpenLayers/Control/Permalink.js) (3 diffs)
- trunk/openlayers/lib/OpenLayers/Control/Permalink.js (modified) (4 diffs)
- trunk/openlayers/lib/OpenLayers/Map.js (modified) (1 diff)
- trunk/openlayers/tests/test_Control_MouseToolbar.html (modified) (1 diff)
- trunk/openlayers/tests/test_Control_PanZoom.html (modified) (1 diff)
- trunk/openlayers/tests/test_Control_Permalink.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers.js
r1623 r1634 94 94 "OpenLayers/Control/PanZoom.js", 95 95 "OpenLayers/Control/PanZoomBar.js", 96 "OpenLayers/Control/ArgParser.js", 96 97 "OpenLayers/Control/Permalink.js", 97 98 "OpenLayers/Control/Scale.js", trunk/openlayers/lib/OpenLayers/Control/ArgParser.js
r1621 r1634 8 8 * @requires OpenLayers/Control.js 9 9 */ 10 OpenLayers.Control. Permalink= OpenLayers.Class.create();11 OpenLayers.Control. Permalink.prototype =10 OpenLayers.Control.ArgParser = OpenLayers.Class.create(); 11 OpenLayers.Control.ArgParser.prototype = 12 12 OpenLayers.Util.extend( new OpenLayers.Control(), { 13 13 14 /** @type DOMElement */15 element: null,16 17 /** @type String */18 base: '',19 20 14 /** @type OpenLayers.LonLat */ 21 15 center: null, … … 35 29 initialize: function(element, base) { 36 30 OpenLayers.Control.prototype.initialize.apply(this, arguments); 37 this.element = element; 38 if (base) { 39 this.base = base; 31 }, 32 33 /** Set the map property for the control. 34 * 35 * @param {OpenLayers.Map} map 36 */ 37 setMap: function(map) { 38 OpenLayers.Control.prototype.setMap.apply(this, arguments); 39 40 //make sure we dont already have an arg parser attached 41 for(var i=0; i< this.map.controls.length; i++) { 42 var control = this.map.controls[i]; 43 if ( (control != this) && 44 (control.CLASS_NAME == "OpenLayers.Control.ArgParser") ) { 45 break; 46 } 47 } 48 if (i == this.map.controls.length) { 49 50 var args = OpenLayers.Util.getArgs(); 51 if (args.lat && args.lon) { 52 this.center = new OpenLayers.LonLat(parseFloat(args.lon), 53 parseFloat(args.lat)); 54 if (args.zoom) { 55 this.zoom = parseInt(args.zoom); 56 } 57 58 // when we add a new baselayer to see when we can set the center 59 this.map.events.register('changebaselayer', this, 60 this.setCenter); 61 this.setCenter(); 62 } 63 64 if (args.layers) { 65 this.layers = args.layers; 66 67 // when we add a new layer, set its visibility 68 this.map.events.register('addlayer', this, 69 this.configureLayers); 70 this.configureLayers(); 71 } 40 72 } 41 73 }, 42 43 /**44 * @type DOMElement45 */46 draw: function() {47 OpenLayers.Control.prototype.draw.apply(this, arguments);48 var args = OpenLayers.Util.getArgs();49 50 if (args.lat && args.lon) {51 this.center = new OpenLayers.LonLat(parseFloat(args.lon),52 parseFloat(args.lat));53 if (args.zoom) {54 this.zoom = parseInt(args.zoom);55 }56 57 // when we add a new baselayer to see when we can set the center58 this.map.events.register('changebaselayer', this, this.setCenter);59 this.setCenter();60 }61 62 if (args.layers) {63 this.layers = args.layers;64 65 // when we add a new layer, set its visibility66 this.map.events.register('addlayer', this, this.configureLayers);67 this.configureLayers();68 }69 70 if (!this.element) {71 this.element = document.createElement("a");72 this.div.style.right = "3px";73 this.div.style.bottom = "3px";74 this.div.style.left = "";75 this.div.style.top = "";76 this.div.style.display = "block";77 this.div.style.position = "absolute";78 this.element.style.fontSize="smaller";79 this.element.innerHTML = "Permalink";80 this.element.href="";81 this.div.appendChild(this.element);82 }83 this.map.events.register('moveend', this, this.updateLink);84 return this.div;85 },86 74 87 /**88 *89 */90 updateLink: function() {91 var center = this.map.getCenter();92 var zoom = "zoom=" + this.map.getZoom();93 var lat = "lat=" + Math.round(center.lat*100000)/100000;94 var lon = "lon=" + Math.round(center.lon*100000)/100000;95 96 var layers = "layers=";97 for(var i=0; i< this.map.layers.length; i++) {98 var layer = this.map.layers[i];99 100 if (layer.isBaseLayer) {101 layers += (layer == this.map.baseLayer) ? "B" : "0";102 } else {103 layers += (layer.getVisibility()) ? "T" : "F";104 }105 }106 var href = this.base + "?" + lat + "&" + lon + "&" + zoom +107 "&" + layers;108 this.element.href = href;109 },110 111 75 /** As soon as a baseLayer has been loaded, we center and zoom 112 76 * ...and remove the handler. … … 146 110 147 111 /** @final @type String */ 148 CLASS_NAME: "OpenLayers.Control. Permalink"112 CLASS_NAME: "OpenLayers.Control.ArgParser" 149 113 }); trunk/openlayers/lib/OpenLayers/Control/Permalink.js
r1621 r1634 17 17 /** @type String */ 18 18 base: '', 19 20 /** @type OpenLayers.LonLat */21 center: null,22 23 /** @type int */24 zoom: null,25 26 /** @type Array */27 layers: null,28 19 29 20 /** … … 41 32 }, 42 33 34 /** Set the map property for the control. 35 * 36 * @param {OpenLayers.Map} map 37 */ 38 setMap: function(map) { 39 OpenLayers.Control.prototype.setMap.apply(this, arguments); 40 41 //make sure we have an arg parser attached 42 for(var i=0; i< this.map.controls.length; i++) { 43 var control = this.map.controls[i]; 44 if (control.CLASS_NAME == "OpenLayers.Control.ArgParser") { 45 break; 46 } 47 } 48 if (i == this.map.controls.length) { 49 this.map.addControl(new OpenLayers.Control.ArgParser()); 50 } 51 52 }, 53 43 54 /** 44 55 * @type DOMElement … … 46 57 draw: function() { 47 58 OpenLayers.Control.prototype.draw.apply(this, arguments); 48 var args = OpenLayers.Util.getArgs();49 59 50 if (args.lat && args.lon) {51 this.center = new OpenLayers.LonLat(parseFloat(args.lon),52 parseFloat(args.lat));53 if (args.zoom) {54 this.zoom = parseInt(args.zoom);55 }56 57 // when we add a new baselayer to see when we can set the center58 this.map.events.register('changebaselayer', this, this.setCenter);59 this.setCenter();60 }61 62 if (args.layers) {63 this.layers = args.layers;64 65 // when we add a new layer, set its visibility66 this.map.events.register('addlayer', this, this.configureLayers);67 this.configureLayers();68 }69 70 60 if (!this.element) { 71 61 this.element = document.createElement("a"); … … 109 99 }, 110 100 111 /** As soon as a baseLayer has been loaded, we center and zoom112 * ...and remove the handler.113 */114 setCenter: function() {115 116 if (this.map.baseLayer) {117 //dont need to listen for this one anymore118 this.map.events.unregister('changebaselayer', this,119 this.setCenter);120 121 this.map.setCenter(this.center, this.zoom);122 }123 },124 125 /** As soon as all the layers are loaded, cycle through them and126 * hide or show them.127 */128 configureLayers: function() {129 130 if (this.layers.length == this.map.layers.length) {131 this.map.events.unregister('addlayer', this, this.configureLayers);132 133 for(var i=0; i < this.layers.length; i++) {134 135 var layer = this.map.layers[i];136 var c = this.layers.charAt(i);137 138 if (c == "B") {139 this.map.setBaseLayer(layer);140 } else if ( (c == "T") || (c == "F") ) {141 layer.setVisibility(c == "T");142 }143 }144 }145 },146 147 101 /** @final @type String */ 148 102 CLASS_NAME: "OpenLayers.Control.Permalink" trunk/openlayers/lib/OpenLayers/Map.js
r1625 r1634 165 165 if (OpenLayers.Control != null) { // running full or lite? 166 166 this.controls = [ new OpenLayers.Control.MouseDefaults(), 167 new OpenLayers.Control.PanZoom()]; 167 new OpenLayers.Control.PanZoom(), 168 new OpenLayers.Control.ArgParser() 169 ]; 168 170 } else { 169 171 this.controls = []; trunk/openlayers/tests/test_Control_MouseToolbar.html
r1450 r1634 18 18 map.addControl(control); 19 19 t.ok( control.map === map, "Control.map is set to the map object" ); 20 t.ok( map.controls[ 2] === control, "map.controls contains control" );21 t.eq( parseInt(control.div.style.zIndex), map.Z_INDEX_BASE['Control'] + 3, "Control div zIndexed properly" );22 t.eq( parseInt(map.viewPortDiv.lastChild.style.zIndex), map.Z_INDEX_BASE['Control'] + 3, "Viewport div contains control div" );20 t.ok( map.controls[3] === control, "map.controls contains control" ); 21 t.eq( parseInt(control.div.style.zIndex), map.Z_INDEX_BASE['Control'] + 4, "Control div zIndexed properly" ); 22 t.eq( parseInt(map.viewPortDiv.lastChild.style.zIndex), map.Z_INDEX_BASE['Control'] + 4, "Viewport div contains control div" ); 23 23 t.eq( control.div.style.top, "6px", "Control div top located correctly by default"); 24 24 trunk/openlayers/tests/test_Control_PanZoom.html
r1424 r1634 18 18 map.addControl(control); 19 19 t.ok( control.map === map, "Control.map is set to the map object" ); 20 t.ok( map.controls[ 2] === control, "map.controls contains control" );21 t.eq( parseInt(control.div.style.zIndex), map.Z_INDEX_BASE['Control'] + 3, "Control div zIndexed properly" );22 t.eq( parseInt(map.viewPortDiv.lastChild.style.zIndex), map.Z_INDEX_BASE['Control'] + 3, "Viewport div contains control div" );20 t.ok( map.controls[3] === control, "map.controls contains control" ); 21 t.eq( parseInt(control.div.style.zIndex), map.Z_INDEX_BASE['Control'] + 4, "Control div zIndexed properly" ); 22 t.eq( parseInt(map.viewPortDiv.lastChild.style.zIndex), map.Z_INDEX_BASE['Control'] + 4, "Viewport div contains control div" ); 23 23 t.eq( control.div.style.top, "4px", "Control div top located correctly by default"); 24 24 trunk/openlayers/tests/test_Control_Permalink.html
r1621 r1634 47 47 map = new OpenLayers.Map($('map')); 48 48 map.addControl(control); 49 t.eq(map.controls[ 2].div.firstChild.nodeName, "A", "Permalink control creates div with 'a' inside." );49 t.eq(map.controls[3].div.firstChild.nodeName, "A", "Permalink control creates div with 'a' inside." ); 50 50 } 51 51 // -->
