1
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3
* full text of the license. */
7
* @requires OpenLayers/Control.js
11
* Class: OpenLayers.Control.ArgParser
14
* - <OpenLayers.Control>
16
OpenLayers.Control.ArgParser = OpenLayers.Class(OpenLayers.Control, {
20
* {<OpenLayers.LonLat>}
32
* {Array(<OpenLayers.Layer>)}
37
* APIProperty: displayProjection
38
* {<OpenLayers.Projection>} Requires proj4js support.
39
* Projection used when reading the coordinates from the URL. This will
40
* reproject the map coordinates from the URL into the map's
43
* If you are using this functionality, be aware that any permalink
44
* which is added to the map will determine the coordinate type which
45
* is read from the URL, which means you should not add permalinks with
46
* different displayProjections to the same map.
48
displayProjection: null,
51
* Constructor: OpenLayers.Control.ArgParser
56
initialize: function(options) {
57
OpenLayers.Control.prototype.initialize.apply(this, arguments);
62
* Set the map property for the control.
65
* map - {<OpenLayers.Map>}
67
setMap: function(map) {
68
OpenLayers.Control.prototype.setMap.apply(this, arguments);
70
//make sure we dont already have an arg parser attached
71
for(var i=0, len=this.map.controls.length; i<len; i++) {
72
var control = this.map.controls[i];
73
if ( (control != this) &&
74
(control.CLASS_NAME == "OpenLayers.Control.ArgParser") ) {
76
// If a second argparser is added to the map, then we
77
// override the displayProjection to be the one added to the
79
if (control.displayProjection != this.displayProjection) {
80
this.displayProjection = control.displayProjection;
86
if (i == this.map.controls.length) {
88
var args = OpenLayers.Util.getParameters();
89
// Be careful to set layer first, to not trigger unnecessary layer loads
91
this.layers = args.layers;
93
// when we add a new layer, set its visibility
94
this.map.events.register('addlayer', this,
95
this.configureLayers);
96
this.configureLayers();
98
if (args.lat && args.lon) {
99
this.center = new OpenLayers.LonLat(parseFloat(args.lon),
100
parseFloat(args.lat));
102
this.zoom = parseInt(args.zoom);
105
// when we add a new baselayer to see when we can set the center
106
this.map.events.register('changebaselayer', this,
115
* As soon as a baseLayer has been loaded, we center and zoom
116
* ...and remove the handler.
118
setCenter: function() {
120
if (this.map.baseLayer) {
121
//dont need to listen for this one anymore
122
this.map.events.unregister('changebaselayer', this,
125
if (this.displayProjection) {
126
this.center.transform(this.displayProjection,
127
this.map.getProjectionObject());
130
this.map.setCenter(this.center, this.zoom);
135
* Method: configureLayers
136
* As soon as all the layers are loaded, cycle through them and
139
configureLayers: function() {
141
if (this.layers.length == this.map.layers.length) {
142
this.map.events.unregister('addlayer', this, this.configureLayers);
144
for(var i=0, len=this.layers.length; i<len; i++) {
146
var layer = this.map.layers[i];
147
var c = this.layers.charAt(i);
150
this.map.setBaseLayer(layer);
151
} else if ( (c == "T") || (c == "F") ) {
152
layer.setVisibility(c == "T");
158
CLASS_NAME: "OpenLayers.Control.ArgParser"