ProjPane.js 2.8 KB

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