[76] | 1 | var panes = { |
---|
| 2 | mapL: {}, |
---|
| 3 | mapLL: {}, |
---|
| 4 | mapR: {} |
---|
| 5 | }; |
---|
| 6 | |
---|
| 7 | ProjPane = Class.create(); |
---|
| 8 | ProjPane.prototype = { |
---|
| 9 | id: null, |
---|
| 10 | map: null, |
---|
| 11 | proj: null, |
---|
| 12 | |
---|
| 13 | initialize: function(pane, code) { |
---|
| 14 | this.id = pane; |
---|
| 15 | if (code) this.setProj(code); |
---|
| 16 | }, |
---|
| 17 | |
---|
| 18 | updateCoords: function(coords) { |
---|
| 19 | document.getElementById(this.id+'_coords').innerHTML = coords.toString(); |
---|
| 20 | var pt = this.map.getLayerPxFromLonLat(coords); |
---|
| 21 | this.marker.moveTo(pt); |
---|
| 22 | }, |
---|
| 23 | |
---|
| 24 | setProj: function(code) { |
---|
| 25 | document.getElementById(this.id+'_proj').value = code; |
---|
| 26 | |
---|
| 27 | this.proj = new Proj4js.Proj(code); |
---|
| 28 | var mapDef = Proj4js.maps[this.proj.srsCode]; |
---|
| 29 | |
---|
| 30 | if (this.map) this.map.destroy(); |
---|
| 31 | this.map = new OpenLayers.Map(this.id, mapDef.mapOptions); |
---|
| 32 | this.mapLayer = new OpenLayers.Layer.WMS(mapDef.layerName, mapDef.layerUrl, mapDef.layerParams, mapDef.layerOptions); |
---|
| 33 | this.map.addLayer(this.mapLayer); |
---|
| 34 | |
---|
| 35 | this.map.addLayer(new OpenLayers.Layer.Markers('')); |
---|
| 36 | this.marker = new OpenLayers.Marker(new OpenLayers.LonLat(0,0)); |
---|
| 37 | this.map.layers[1].addMarker(this.marker); |
---|
| 38 | this.marker.map = this.map; |
---|
| 39 | if (window.bounds) { |
---|
| 40 | this.map.addLayer(new OpenLayers.Layer.Boxes()); |
---|
| 41 | this.map.layers[2].addMarker(new OpenLayers.Marker.Box(bounds)); |
---|
| 42 | this.map.setCenter(bounds.getCenterLonLat()); |
---|
| 43 | } else { |
---|
| 44 | this.map.zoomToMaxExtent(); |
---|
| 45 | } |
---|
| 46 | this.map.events.register('click', this.map, this.mapClicked.bind(this)); |
---|
| 47 | |
---|
| 48 | document.getElementById(this.id+'_units').innerHTML = this.proj.units; |
---|
| 49 | document.getElementById(this.id+'_title').innerHTML = this.proj.title; |
---|
| 50 | document.getElementById(this.id+'_class').innerHTML = this.proj.projName; |
---|
| 51 | }, |
---|
| 52 | |
---|
| 53 | mapClicked: function(ev) { |
---|
| 54 | var olc = this.map.getLonLatFromViewPortPx(ev.xy); |
---|
| 55 | c = new Proj4js.Point(olc.lon, olc.lat); |
---|
| 56 | this.updateCoords(c); |
---|
| 57 | |
---|
| 58 | if (this.opposite && this.opposite.proj) { |
---|
| 59 | var newCoords = this.proj.transform(c, this.opposite.proj); |
---|
| 60 | this.opposite.updateCoords(newCoords); |
---|
| 61 | } |
---|
| 62 | if (this.common) { |
---|
| 63 | var newCoords = this.proj.inverse(c); |
---|
| 64 | this.common.updateCoords(newCoords); |
---|
| 65 | } |
---|
| 66 | if (this.projected1 && this.projected1.proj) { |
---|
| 67 | var newCoords = this.projected1.proj.forward(c); |
---|
| 68 | this.projected1.updateCoords(newCoords); |
---|
| 69 | } |
---|
| 70 | if (this.projected2 && this.projected2.proj) { |
---|
| 71 | var newCoords = this.projected2.proj.forward(c); |
---|
| 72 | this.projected2.updateCoords(newCoords); |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | }; |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | function init() { |
---|
| 79 | panes['mapLL'] = new ProjPane('mapLL',Proj4js.defaultDatum); |
---|
| 80 | panes['mapL'] = new ProjPane('mapL'); |
---|
| 81 | panes['mapR'] = new ProjPane('mapR'); |
---|
| 82 | |
---|
| 83 | panes['mapLL'].projected1 = panes['mapL']; |
---|
| 84 | panes['mapLL'].projected2 = panes['mapR']; |
---|
| 85 | panes['mapL'].opposite = panes['mapR']; |
---|
| 86 | panes['mapR'].opposite = panes['mapL']; |
---|
| 87 | panes['mapL'].common = panes['mapLL']; |
---|
| 88 | panes['mapR'].common = panes['mapLL']; |
---|
| 89 | |
---|
| 90 | }; |
---|
| 91 | |
---|