Changeset 1187
- Timestamp:
- 10/10/08 16:21:34 (3 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/camptocamp/MapFishAeai/client/mfbase/mapfish/widgets/recenter/Base.js
r1183 r1187 27 27 /** 28 28 * Class: mapfish.widgets.recenter.Base 29 * Base class for various recentering tools. 29 * Base class for various recentering tools. Must be extended in specific classes. 30 30 * 31 31 * Inherits from: … … 38 38 * Parameters: 39 39 * config - {Object} The config object 40 * Returns: 41 * {<mapfish.widgets.recenter.Base>} 40 42 */ 41 43 mapfish.widgets.recenter.Base = function(config) { 42 44 Ext.apply(this, config); 43 45 mapfish.widgets.recenter.Base.superclass.constructor.call(this); 44 } 46 }; 45 47 46 48 Ext.extend(mapfish.widgets.recenter.Base, Ext.FormPanel, { … … 48 50 /** 49 51 * APIProperty: scales 50 * { <Array>} - List of available scales52 * {Array} - List of available scales 51 53 */ 52 54 scales: null, … … 54 56 /** 55 57 * APIProperty: showCenter 56 * { <Boolean>} - Indicates if a symbol must be shown at the new center58 * {Boolean} - Indicates if a symbol must be shown at the new center 57 59 */ 58 60 showCenter: null, 59 61 60 62 /** 61 * APIProperty: default Scale62 * { <Integer>} - Scale used if no scaleis provided by the user63 */ 64 default Scale: null,63 * APIProperty: defaultZoom 64 * {Integer} - Zoom level used if no zoom level is provided by the user 65 */ 66 defaultZoom: null, 65 67 66 68 /** 67 69 * Property: scaleData 68 * { <Array>} - 2D-array containing available scales values and labels70 * {Array} - 2D-array containing available scales values and labels 69 71 */ 70 72 scaleData: null, … … 72 74 /** 73 75 * Property: vectorLayer 74 * {<OpenLayers. Layer.Vector>} - Vector layer used to display a symbol75 * on new center point76 * {<OpenLayers.Layer.Vector>} - Vector layer used to display a symbol 77 * on new center point 76 78 */ 77 79 vectorLayer: null, … … 94 96 * implemented by child classes. 95 97 */ 96 fillComponent: null,98 fillComponent: function() {}, 97 99 98 100 /** … … 115 117 116 118 this.scaleData = []; 117 for (var i = 0 ; i < this.scales.length; i++) {119 for (var i = 0, len = this.scales.length; i < len; i++) { 118 120 119 121 this.scaleData.push([ … … 146 148 * Recentering action. implemented by child classes. 147 149 */ 148 recenter: null,150 recenter: function() {}, 149 151 150 152 /** 151 153 * Method: recenterOnCoords 152 154 * 153 * Recenters on given coordinates and scale 154 */ 155 recenterOnCoords: function(x, y, scale) { 156 157 if (typeof scale == 'undefined') { 158 if (this.defaultScale) { 159 // use default scale if provided in widget config 160 scale = this.defaultScale; 161 162 } else { 163 // keep current scale 164 scale = this.map.getScale(); 165 } 155 * Recenters on given coordinates and zoom level 156 */ 157 recenterOnCoords: function(x, y, zoom) { 158 159 if (zoom == undefined) { 160 // use default zoom level if provided in widget config, 161 // else keep current zoom level 162 zoom = this.defaultZoom ? this.defaultZoom : this.map.getZoom(); 166 163 } 167 164 … … 182 179 } 183 180 184 //console.log('recentering on x=' + x + ' y=' + y + ' scale=' + scale); 185 this.map.setCenter(new OpenLayers.LonLat(x, y), scale); 181 this.map.setCenter(new OpenLayers.LonLat(x, y), zoom); 186 182 }, 187 183 … … 208 204 "Center Symbol", { 209 205 styleMap: styles, 210 isBaseLayer: false, 211 calculateInRange: function() { 212 return true; 213 } 206 alwaysInRange: true 214 207 } 215 208 ); … … 220 213 221 214 /** 222 * Method: getScaleByName 223 * 224 * Returns the zoom level matching the given scale label 225 */ 226 getScaleByName: function(scaleName) { 215 * Method: getZoomByName 216 * 217 * Returns: 218 * {Integer} - zoom level matching the given scale label 219 */ 220 getZoomByName: function(scaleName) { 227 221 var scales = this.scaleData; 228 for (var i = 0 ; i < scales.length; i++) {222 for (var i = 0, len = scales.length; i < len; i++) { 229 223 var cur = scales[i]; 230 224 if (cur[1] == scaleName) { sandbox/camptocamp/MapFishAeai/client/mfbase/mapfish/widgets/recenter/Coords.js
r1183 r1187 36 36 * scales: config.scales, // list of available scales. 37 37 * // If not provided, no scales combo is displayed 38 * showCenter: true, // boolean, indicates if a symbol must be shown at the new center 39 * defaultScale: 4 // scale used if no scale is provided by the user 40 * // if no scale value is eventually available, scale remains unchanged 38 * showCenter: true, // boolean, indicates if a symbol must be shown 39 * // at the new center 40 * defaultZoom: 4 // zoom level used if no zoom level is provided by 41 * // the user. If no zoom level value is eventually 42 * // available, zoom level remains unchanged. 41 43 * }); 42 44 * (end) … … 47 49 48 50 /** 49 * Constructor: mapfish.widgets.recenter. Base51 * Constructor: mapfish.widgets.recenter.Coords 50 52 * 51 53 * Parameters: 52 54 * config - {Object} The config object 55 * Returns: 56 * {<mapfish.widgets.recenter.Coords>} 53 57 */ 54 58 mapfish.widgets.recenter.Coords = function(config) { 55 59 Ext.apply(this, config); 56 60 mapfish.widgets.recenter.Coords.superclass.constructor.call(this); 57 } 61 }; 58 62 59 63 Ext.extend(mapfish.widgets.recenter.Coords, mapfish.widgets.recenter.Base, { … … 97 101 if (this.checkCoords(x, y)) { 98 102 99 var scale;103 var zoom; 100 104 101 105 if (this.scales && values.scale) { 102 106 // use user-provided scale 103 scale = this.getScaleByName(values.scale);107 zoom = this.getZoomByName(values.scale); 104 108 } 105 109 106 this.recenterOnCoords(x, y, scale);110 this.recenterOnCoords(x, y, zoom); 107 111 } 108 112 }, … … 112 116 * 113 117 * Checks that submitted coordinates are well-formatted and within the map bounds. 118 * Returns: 119 * {Boolean} 114 120 */ 115 121 checkCoords: function(x, y) { sandbox/camptocamp/MapFishAeai/client/mfbase/mapfish/widgets/recenter/Ws.js
r1183 r1187 62 62 63 63 /** 64 * Constructor: mapfish.widgets.Ws Recenter64 * Constructor: mapfish.widgets.Ws 65 65 * 66 66 * Parameters: 67 67 * config - {Object} The config object 68 * Returns: 69 * {<mapfish.widgets.recenter.Ws>} 68 70 */ 69 71 … … 71 73 Ext.apply(this, config); 72 74 mapfish.widgets.recenter.Ws.superclass.constructor.call(this); 73 } 75 }; 74 76 75 77 Ext.extend(mapfish.widgets.recenter.Ws, mapfish.widgets.recenter.Base, { … … 183 185 onWsRecenterSelect: function(combo) { 184 186 185 if (combo.value == '') {187 if (combo.value.length == 0) { 186 188 return; 187 189 // prevent action if user press enter only on first try 188 190 } 189 191 var url = this.wsRecenterCurrentService.url + this.wsRecenterCurrentService.urlSuffixGeo + '?' + this.wsRecenterCurrentService.paramIdGeo + '=' + combo.value; 190 newOpenLayers.Request.GET({192 OpenLayers.Request.GET({ 191 193 url: url, 192 194 success: function(response) { 193 195 194 196 var values = this.getForm().getValues(); 195 var scale;197 var zoom; 196 198 197 199 var f = new OpenLayers.Format.GeoJSON(); … … 204 206 if (this.scales && values.scale) { 205 207 // use user-provided scale 206 scale = this.getScaleByName(values.scale);208 zoom = this.getZoomByName(values.scale); 207 209 } 208 210 209 this.recenterOnCoords(feature.geometry.x, feature.geometry.y, scale);211 this.recenterOnCoords(feature.geometry.x, feature.geometry.y, zoom); 210 212 211 213 }, … … 213 215 var msg = this.errorMsg + "<br /><br />" + url + "<br /><br />" + response.status + "<br />" + response.statusText; 214 216 this.showError(msg); 215 }, scope: this // bind parent context to the current event handler 217 }, 218 scope: this // bind parent context to the current event handler 216 219 217 220 }); … … 223 226 initWsRecenterService: function () { 224 227 // set default service 225 for (var i =0; i < this.wsRecenterServices.length; i++) {228 for (var i = 0, len = this.wsRecenterServices.length; i < len; i++) { 226 229 if (this.wsRecenterServices[i].isDefault) { 227 230 this.wsRecenterCurrentService = this.wsRecenterServices[i];