File: Permalink.html

package info (click to toggle)
openlayers 2.11%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 60,144 kB
  • ctags: 10,906
  • sloc: xml: 7,435; python: 778; sh: 68; makefile: 30
file content (331 lines) | stat: -rw-r--r-- 18,263 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<html>
<head>
  <script src="../OLLoader.js"></script>
  <script type="text/javascript">
    var map; 
    function test_Control_Permalink_constructor (t) {
        t.plan(42);
    
        control = new OpenLayers.Control.Permalink();
        t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
        t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
        t.eq(control.base, document.location.href, "base is correct");
        t.ok(!control.anchor, "anchor is correct");

        control = new OpenLayers.Control.Permalink('permalink', 'test.html');
        t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
        t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
        t.eq(control.base, 'test.html', "base is correct");
        t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object");
        t.ok(!control.anchor, "anchor is correct");

        control = new OpenLayers.Control.Permalink('permalink');
        t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
        t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
        t.eq(control.base, document.location.href, "base is correct");
        t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object");
        t.ok(!control.anchor, "anchor is correct");

        control = new OpenLayers.Control.Permalink(OpenLayers.Util.getElement('permalink'));
        t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
        t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
        t.eq(control.base, document.location.href, "base is correct");
        t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object");
        t.ok(!control.anchor, "anchor is correct");

        control = new OpenLayers.Control.Permalink({anchor: true});
        t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
        t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
        t.eq(control.base, document.location.href, "base is correct");
        t.ok(control.element == null, "element is null");
        t.ok(control.anchor, "anchor is correct");

        control = new OpenLayers.Control.Permalink({anchor: false});
        t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
        t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
        t.eq(control.base, document.location.href, "base is correct");
        t.ok(!control.anchor, "anchor is correct");

        control = new OpenLayers.Control.Permalink({});
        t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
        t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
        t.eq(control.base, document.location.href, "base is correct");
        t.ok(!control.anchor, "anchor is correct");

        control = new OpenLayers.Control.Permalink({element: 'permalink', base: 'test.html'});
        t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
        t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
        t.eq(control.base, 'test.html', "base is correct");
        t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object");
        t.ok(!control.anchor, "anchor is correct");

        control = new OpenLayers.Control.Permalink({element: 'permalink', base: 'test.html', anchor: true});
        t.ok(control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object");
        t.eq(control.displayClass, "olControlPermalink", "displayClass is correct");
        t.eq(control.base, 'test.html', "base is correct");
        t.ok(OpenLayers.Util.isElement(control.element), "element is a dom object");
        t.ok(control.anchor, "anchor is correct");
    }
    function test_Control_Permalink_uncentered (t) {
        t.plan( 1 );
    
        control = new OpenLayers.Control.Permalink('permalink');
        map = new OpenLayers.Map('map');
        map.addControl(control);
        map.events.triggerEvent("changelayer", {});
        t.ok(true, "permalink didn't bomb out.");
    }   
    function test_Control_Permalink_initwithelem (t) {
        t.plan( 1 );
    
        control = new OpenLayers.Control.Permalink(OpenLayers.Util.getElement('permalink'));
        t.ok(true, "If the above line doesn't throw an error, we're safe."); 
    }
    function test_Control_Permalink_updateLinks (t) {
        t.plan( 3 );
    
        control = new OpenLayers.Control.Permalink('permalink');
        t.ok( control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object" );
        map = new OpenLayers.Map('map');
        layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'});
        map.addLayer(layer);
        layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}, {'isBaseLayer': false});
        map.addLayer(layer);
        layer.setVisibility(true);
        if (!map.getCenter())  map.zoomToMaxExtent();
        map.addControl(control);
        map.pan(5, 0, {animate:false});
        t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getElement('permalink').href, location+"?zoom=2&lat=0&lon=1.75781&layers=BT"), 'pan sets permalink');
        
        map.layers[1].setVisibility(false);
        
        t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getElement('permalink').href, location+"?zoom=2&lat=0&lon=1.75781&layers=BF"), 'setVisibility sets permalink');
    }
    function test_Control_Permalink_updateLinksBase (t) {
        t.plan( 2 );
    
        control = new OpenLayers.Control.Permalink('permalink', "./edit.html" );
        t.ok( control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object" );
        map = new OpenLayers.Map('map');
        layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'});
        map.addLayer(layer);
        if (!map.getCenter())  map.zoomToMaxExtent();
        map.addControl(control);
        map.pan(5, 0, {animate:false});
        OpenLayers.Util.getElement('edit_permalink').href = './edit.html?zoom=2&lat=0&lon=1.75781&layers=B';
        t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base");
  }
  function test_Control_Permalink_noElement (t) {
        t.plan( 2 );
        control = new OpenLayers.Control.Permalink( );
        t.ok( control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object" );
        map = new OpenLayers.Map('map');
        map.addControl(control);
        t.eq(map.controls[4].div.firstChild.nodeName, "A", "Permalink control creates div with 'a' inside." );
  }
  function test_Control_Permalink_base_with_query (t) {
      t.plan( 3 );
  
      control = new OpenLayers.Control.Permalink('permalink', "./edit.html?foo=bar" );
      map = new OpenLayers.Map('map');
      layer = new OpenLayers.Layer.WMS('Test Layer', "http://example.com" );
      map.addLayer(layer);
      if (!map.getCenter())  map.zoomToMaxExtent();
      map.addControl(control);
      map.pan(5, 0, {animate:false});
      OpenLayers.Util.getElement('edit_permalink').href = './edit.html?foo=bar&zoom=2&lat=0&lon=1.75781&layers=B';
      t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and querystring");
      
      control = new OpenLayers.Control.Permalink('permalink', "./edit.html?foo=bar&" );
      map.addControl(control);
      map.pan(0, 0, {animate:false});
      t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and querystring ending with '&'");
      
      control = new OpenLayers.Control.Permalink('permalink', "./edit.html?" );
      OpenLayers.Util.getElement('edit_permalink').href = './edit.html?zoom=2&lat=0&lon=1.75781&layers=B';
      map.addControl(control);
      map.pan(5, 0, {animate:false});
      map.pan(-5, 0, {animate:false});
      t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and querystring ending with '?'");

  }

    function test_Control_Permalink_nonRepeating (t) {
        t.plan( 2 );
    
        control = new OpenLayers.Control.Permalink('permalink', "./edit.html?zoom=3" );
        t.ok( control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object" );
        map = new OpenLayers.Map('map');
        layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'});
        map.addLayer(layer);
        if (!map.getCenter())  map.zoomToMaxExtent();
        map.addControl(control);
        map.pan(5, 0, {animate:false});
        OpenLayers.Util.getElement('edit_permalink').href = './edit.html?zoom=2&lat=0&lon=1.75781&layers=B';
        t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with existing zoom in base");
  }
  
    function test_Control_Permalink_customized(t) {
        t.plan(2);
      
        var argParserClass = OpenLayers.Class(OpenLayers.Control.ArgParser, {
            CLASS_NAME: "CustomArgParser"
        });
      
        control = new OpenLayers.Control.Permalink(null, "./edit.html", {
            argParserClass: argParserClass,
            createParams: function(center, zoom, layers) {
                var params = OpenLayers.Control.Permalink.prototype.createParams.apply(control, arguments);
                params.customParam = "foo";
                return params;
            }
        });
        map = new OpenLayers.Map('map');
        layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'});
        map.addLayer(layer);
        if (!map.getCenter())  map.zoomToMaxExtent();
        map.addControl(control);
        map.pan(5, 0, {animate:false});
      
        t.eq(this.map.controls[this.map.controls.length-1].CLASS_NAME, "CustomArgParser", "Custom ArgParser added correctly.");
        t.eq(control.div.firstChild.getAttribute("href"), "./edit.html?zoom=2&lat=0&lon=1.75781&layers=B&customParam=foo", "Custom parameter encoded correctly.");
    }
    
    function test_Control_Permalink_createParams(t) {
        t.plan(18);

        var baseLayer = { 'isBaseLayer': true };

        var m = {
            'getCenter': function() { return null; }
        };
        
        var pl = {
            'map': m,
            'base': {}
        };

        old_getParameters = OpenLayers.Util.getParameters;
        OpenLayers.Util.getParameters = function(base) {
            t.ok(base == pl.base, "correct base sent in to Util.getParameters()");
            return g_Params;
        };
        
      //null center, null map.getCenter()
        g_Params = {};
        m.baseLayer = baseLayer;
        var returnParams = OpenLayers.Control.Permalink.prototype.createParams.apply(pl, []);
        t.ok(returnParams == g_Params, "correct params returned on null center");

      //valid center, zoom, layers
        g_Params = { 'test': {} };
        var center = { 'lon': 1.2345678901, 'lat': 9.8765432109 };
        var zoom = {};
        var layers = [
            { 'isBaseLayer': true },
            baseLayer,
            { 'isBaseLayer': false, 'getVisibility': function() { return true; } },
            { 'isBaseLayer': false, 'getVisibility': function() { return false; } }
        ];
        var returnParams = OpenLayers.Control.Permalink.prototype.createParams.apply(pl, [center, zoom, layers]);

        t.ok(returnParams.test == g_Params.test, "correct params returned from Util.getParameters() when valid center, zoom, layers");
        t.ok(returnParams.zoom == zoom, "params.zoom set correctly when valid center, zoom, layers");
        t.eq(returnParams.lon, 1.23457, "lon set and rounded correctly when valid center, zoom, layers");
        t.eq(returnParams.lat, 9.87654, "lat set and rounded correctly when valid center, zoom, layers");
        t.eq(returnParams.layers, "0BTF", "layers processed correctly when valid center, zoom, layers")


      //null center, zoom, layers, with displayProjection
        g_Params = { 'test': {} };
        g_Projection = {};
        m = {
            'baseLayer': baseLayer,
            'getProjectionObject':  function() { return g_Projection; },
            'center': { 'lon': {}, 'lat': {} },
            'getCenter': function() { return this.center; },
            'zoom': {},
            'getZoom': function() { return this.zoom; },
           'layers': [
                { 'isBaseLayer': false, 'getVisibility': function() { return true; } },
                baseLayer,
                { 'isBaseLayer': false, 'getVisibility': function() { return false; } },
                { 'isBaseLayer': true }
            ],
            'getLayers': function() { return this.layers; }
        };
        pl = { 
            'base': {},
            'map': m,
            'displayProjection': {}
        };
        
        old_transform = OpenLayers.Projection.transform;
        OpenLayers.Projection.transform = function(point, projObj, dispProj) {
            t.ok(point.x = m.center.lon, "correct x value passed into transform");
            t.ok(point.y = m.center.lat, "correct x value passed into transform");
            t.ok(projObj == g_Projection, "correct projection object from map passed into transform");
            t.ok(dispProj == pl.displayProjection, "correct displayProjection from control passed into transform");

            return { 'x': 9.8765432109, 'y': 1.2345678901 };
        };
        
        center = zoom = layers = null;

        var returnParams = OpenLayers.Control.Permalink.prototype.createParams.apply(pl, [center, zoom, layers]);
        t.ok(returnParams.test == g_Params.test, "correct params returned from Util.getParameters() when null center, zoom, layers, with displayProjection");
        t.ok(returnParams.zoom == m.zoom, "params.zoom set correctly when null center, zoom, layers, with displayProjection");
        t.eq(returnParams.lon, 9.87654, "lon set, transformed, and rounded correctly when null center, zoom, layers, with displayProjection");
        t.eq(returnParams.lat, 1.23457, "lat set, transformed, and rounded correctly when null center, zoom, layers, with displayProjection");
        t.eq(returnParams.layers, "TBF0", "layers processed correctly when null center, zoom, layers, with displayProjection");

        OpenLayers.Util.getParameters = old_getParameters;
        OpenLayers.Projection.transform = old_transform;
    }
    function test_Control_Permalink_Anchor (t) {
        t.plan(3);
    
        control = new OpenLayers.Control.Permalink({anchor: true});
        t.ok( control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object" );
        map = new OpenLayers.Map('map');
        layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'});
        map.addLayer(layer);
        layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}, {'isBaseLayer': false});
        map.addLayer(layer);
        layer.setVisibility(true);
        if (!map.getCenter())  map.zoomToMaxExtent();
        map.addControl(control);
        map.pan(5, 0, {animate:false});
        t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getParameterString(control.createParams()), "zoom=2&lat=0&lon=1.75781&layers=BT"), 'pan sets permalink');
        
        map.layers[1].setVisibility(false);
        t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getParameterString(control.createParams()), "zoom=2&lat=0&lon=1.75781&layers=BF"), 'setVisibility sets permalink');
    }
    
    function test_Control_Permalink_AnchorBaseElement (t) {
        t.plan(3);
    
        control = new OpenLayers.Control.Permalink('permalink', document.location.href, {anchor: true});
        t.ok( control instanceof OpenLayers.Control.Permalink, "new OpenLayers.Control returns object" );
        map = new OpenLayers.Map('map');
        layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'});
        map.addLayer(layer);
        layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}, {'isBaseLayer': false});
        map.addLayer(layer);
        layer.setVisibility(true);
        if (!map.getCenter())  map.zoomToMaxExtent();
        map.addControl(control);
        map.pan(5, 0, {animate:false});
        t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getElement('permalink').href, location+"#zoom=2&lat=0&lon=1.75781&layers=BT"), 'pan sets permalink');
        
        map.layers[1].setVisibility(false);
        t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getElement('permalink').href, location+"#zoom=2&lat=0&lon=1.75781&layers=BF"), 'setVisibility sets permalink');
    }
  </script>
</head>
<body>
    <a id="permalink" href="">Permalink</a> <br />
    <a id="edit_permalink" href="">Edit</a> <br />
    <div id="map" style="width: 1024px; height: 512px;"/>
</body>
</html>