Feature.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. define("dojox/geo/openlayers/Feature", ["dojo/_base/kernel", "dojo/_base/declare", "dojox/geo/openlayers/Map"], function(dojo, declare, Map){
  2. return declare("dojox.geo.openlayers.Feature", null, {
  3. // summary:
  4. // A Feature encapsulates an item so that it can be added to a Layer.
  5. // This class is not attended to be used as it, but serve as a base class
  6. // for specific features such as GeometryFeature which can display georeferenced
  7. // geometries and WidgetFeature which can display georeferenced widgets.
  8. constructor : function(){
  9. // summary:
  10. // Construct a new Feature
  11. this._layer = null;
  12. this._coordSys = dojox.geo.openlayers.EPSG4326;
  13. },
  14. getCoordinateSystem : function(){
  15. // summary:
  16. // Returns the coordinate system in which coordinates of this feature are expressed.
  17. // returns: OpenLayers.Projection
  18. // The coordinate system in which coordinates of this feature are expressed.
  19. return this._coordSys;
  20. },
  21. setCoordinateSystem : function(/* OpenLayers.Projection */cs){
  22. // summary:
  23. // Set the coordinate system in which coordinates of this feature are expressed.
  24. // cs: OpenLayers.Projection
  25. // The coordinate system in which coordinates of this feature are expressed.
  26. this._coordSys = cs;
  27. },
  28. getLayer : function(){
  29. // summary:
  30. // Returns the Layer to which this feature belongs.
  31. // returns: dojox.geo.openlayers.Layer
  32. // The layer to which this feature belongs.
  33. return this._layer;
  34. },
  35. _setLayer : function(/* dojox.geo.openlayers.Layer */l){
  36. // summary:
  37. // Sets the layer to which this Feature belongs
  38. // description:
  39. // Called when the feature is added to the Layer.
  40. // tags:
  41. // private
  42. this._layer = l;
  43. },
  44. render : function(){
  45. // summary:
  46. // subclasses implements drawing specific behavior.
  47. },
  48. remove : function(){
  49. // summary:
  50. // Subclasses implements specific behavior.
  51. // Called when removed from the layer.
  52. },
  53. _getLocalXY : function(p){
  54. // summary:
  55. // From projected coordinates to screen coordinates
  56. // p: Object
  57. // Object with x and y fields
  58. // tags:
  59. // private
  60. var x = p.x;
  61. var y = p.y;
  62. var layer = this.getLayer();
  63. var resolution = layer.olLayer.map.getResolution();
  64. var extent = layer.olLayer.getExtent();
  65. var rx = (x / resolution + (-extent.left / resolution));
  66. var ry = ((extent.top / resolution) - y / resolution);
  67. return [rx, ry];
  68. }
  69. });
  70. });