summaryrefslogtreecommitdiff
path: root/misc/openlayers/examples/polar-projections.js
blob: ac717fbd97a63fd1eb6f5bac08ee81be7873d2cb (plain)
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
var map, layer, overlay;

var projectionOptions = {
    'EPSG:3574': {
        projection: new OpenLayers.Projection('EPSG:3574'),
        units: 'm',
        maxExtent: new OpenLayers.Bounds(-5505054, -5505054, 5505054, 5505054),
        maxResolution: 5505054 / 128,
        numZoomLevels: 18
    },
    'EPSG:3576': {
        projection: new OpenLayers.Projection('EPSG:3576'),
        units: 'm',
        maxExtent: new OpenLayers.Bounds(-5505054, -5505054, 5505054, 5505054),
        maxResolution: 5505054 / 128,
        numZoomLevels: 18
    },
    'EPSG:3571': {
        projection: new OpenLayers.Projection('EPSG:3571'),
        units: 'm',
        maxExtent: new OpenLayers.Bounds(-5505054, -5505054, 5505054, 5505054),
        maxResolution: 5505054 / 128,
        numZoomLevels: 18
    },
    'EPSG:3573': {
        projection: new OpenLayers.Projection('EPSG:3573'),
        units: 'm',
        maxExtent: new OpenLayers.Bounds(-5505054, -5505054, 5505054, 5505054),
        maxResolution: 5505054 / 128,
        numZoomLevels: 18
    }
};

function setProjection() {
    projCode = this.innerHTML;
    var oldExtent = map.getExtent();
    var oldCenter = map.getCenter();
    var oldProjection = map.getProjectionObject();
    
    // map projection is controlled by the base layer
    map.baseLayer.addOptions(projectionOptions[projCode]);
    
    // with the base layer updated, the map has the new projection now
    var newProjection = map.getProjectionObject();
    
    // transform the center of the old projection, not the extent
    map.setCenter(
        oldCenter.transform(oldProjection, newProjection,
        map.getZoomForExtent(oldExtent.transform(oldProjection, newProjection))
    ));
    
    for (var i=map.layers.length-1; i>=0; --i) {
        // update grid settings
        map.layers[i].addOptions(projectionOptions[projCode]);
        // redraw layer - just in case center and zoom are the same in old and
        // new projection
        map.layers[i].redraw();
    }
}

function init() {
    map = new OpenLayers.Map('map');
    layer = new OpenLayers.Layer.WMS(
        'world',
        'http://v2.suite.opengeo.org/geoserver/wms',
        {layers: 'world', version: '1.1.1'},
        projectionOptions['EPSG:3574']
    );
    overlay = new OpenLayers.Layer.WMS(
        'world',
        'http://v2.suite.opengeo.org/geoserver/wms',
        {transparent: 'true', layers: 'world:borders', styles: 'line'},
        projectionOptions['EPSG:3574']
    );
    overlay.isBaseLayer = false;
    map.addLayers([layer, overlay]);
    map.zoomToMaxExtent();
    
    // add behaviour to dom elements
    document.getElementById('epsg3574').onclick = setProjection;
    document.getElementById('epsg3576').onclick = setProjection;
    document.getElementById('epsg3571').onclick = setProjection;
    document.getElementById('epsg3573').onclick = setProjection;
}