GfxLayer.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. define("dojox/geo/openlayers/GfxLayer", ["dojo/_base/kernel",
  2. "dojo/_base/declare",
  3. "dojo/_base/connect",
  4. "dojo/_base/html",
  5. "dojox/gfx",
  6. "dojox/gfx/_base",
  7. "dojox/gfx/shape",
  8. "dojox/gfx/path",
  9. "dojox/gfx/matrix",
  10. "dojox/geo/openlayers/Feature",
  11. "dojox/geo/openlayers/Layer"], function(dojo, declare, connect, html, gfx, gbase, shape,
  12. path, matrix, Feature, Layer){
  13. /*=====
  14. var Layer = dojox.geo.openlayers.Layer;
  15. =====*/
  16. return declare("dojox.geo.openlayers.GfxLayer", Layer, {
  17. // summary:
  18. // A layer dedicated to render dojox.geo.openlayers.GeometryFeature
  19. // description:
  20. // A layer class for rendering geometries as dojox.gfx.Shape objects.
  21. // This layer class accepts Features which encapsulates graphic objects to be added to the map.
  22. // All objects should be added to this group.
  23. // tags:
  24. // private
  25. _viewport : null,
  26. constructor : function(name, options){
  27. // summary:
  28. // Constructs a new GFX layer.
  29. var s = dojox.gfx.createSurface(this.olLayer.div, 100, 100);
  30. this._surface = s;
  31. var vp;
  32. if (options && options.viewport)
  33. vp = options.viewport;
  34. else
  35. vp = s.createGroup();
  36. this.setViewport(vp);
  37. dojo.connect(this.olLayer, "onMapResize", this, "onMapResize");
  38. this.olLayer.getDataExtent = this.getDataExtent;
  39. },
  40. getViewport : function(){
  41. // summary:
  42. // Gets the viewport
  43. // tags:
  44. // internal
  45. return this._viewport;
  46. },
  47. setViewport : function(g){
  48. // summary:
  49. // Sets the viewport
  50. // g: dojox.gfx.Group
  51. // tags:
  52. // internal
  53. if (this._viewport)
  54. this._viewport.removeShape();
  55. this._viewport = g;
  56. this._surface.add(g);
  57. },
  58. onMapResize : function(){
  59. // summary:
  60. // Called when map is resized.
  61. // tag:
  62. // protected
  63. this._surfaceSize();
  64. },
  65. setMap : function(map){
  66. // summary:
  67. // Sets the map for this layer.
  68. // tag:
  69. // protected
  70. this.inherited(arguments);
  71. this._surfaceSize();
  72. },
  73. getDataExtent : function(){
  74. // summary:
  75. // Get data extent
  76. // tags:
  77. // private
  78. var ret = this._surface.getDimensions();
  79. return ret;
  80. },
  81. getSurface : function(){
  82. // summary:
  83. // Get the underlying dojox.gfx.Surface
  84. // returns: dojox.gfx.Surface
  85. // The dojox.gfx.Surface this layer uses to draw its GFX rendering.
  86. return this._surface;
  87. },
  88. _surfaceSize : function(){
  89. // summary:
  90. // Recomputes the surface size when being resized.
  91. // tags:
  92. // private
  93. var s = this.olLayer.map.getSize();
  94. this._surface.setDimensions(s.w, s.h);
  95. },
  96. moveTo : function(event){
  97. // summary:
  98. // Called when this layer is moved or zoommed.
  99. // event:
  100. // The event
  101. var s = dojo.style(this.olLayer.map.layerContainerDiv);
  102. var left = parseInt(s.left);
  103. var top = parseInt(s.top);
  104. if (event.zoomChanged || left || top) {
  105. var d = this.olLayer.div;
  106. dojo.style(d, {
  107. left : -left + "px",
  108. top : -top + "px"
  109. });
  110. if (this._features == null)
  111. return;
  112. var vp = this.getViewport();
  113. vp.setTransform(matrix.translate(left, top));
  114. this.inherited(arguments);
  115. }
  116. },
  117. added : function(){
  118. // summary:
  119. // Called when added to a map.
  120. this.inherited(arguments);
  121. this._surfaceSize();
  122. }
  123. });
  124. });