Map.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. define("dojox/geo/openlayers/widget/Map", ["dojo/_base/kernel",
  2. "dojo/_base/declare",
  3. "dojo/_base/array",
  4. "dojo/_base/html",
  5. "dojo/query",
  6. "dijit/_Widget",
  7. "dojox/geo/openlayers/Map",
  8. "dojox/geo/openlayers/Layer",
  9. "dojox/geo/openlayers/GfxLayer"], function(dojo, declare, array, html, query, Widget, Map, Layer, GfxLayer){
  10. /*=====
  11. var Widget = dijit.Widget;
  12. =====*/
  13. return declare("dojox.geo.openlayers.widget.Map", Widget, {
  14. // summary:
  15. // A widget version of the `dojox.geo.openlayers.Map` component.
  16. // description:
  17. // The `dojox.geo.openlayers.widget.Map` widget is the widget
  18. // version of the `dojox.geo.openlayers.Map` component.
  19. // With this widget, user can specify some attributes in the markup suach as
  20. //
  21. // * `baseLayerType`: The type of the base layer. Permitted values are
  22. // * `initialLocation`: The initial location as for the dojox.geo.openlayers.Map.fitTo method
  23. // * `touchHandler`: Tells if we attach touch handler or not.
  24. //
  25. // example:
  26. //
  27. // | <div id="map" dojoType="dojox.geo.openlayers.widget.Map" baseLayerType="Google" initialLocation="{
  28. // | position : [7.154126, 43.651748],
  29. // | extent : 0.2 }"
  30. // | style="background-color: #b5d0d0; width: 100%; height: 100%;">
  31. //
  32. // summay:
  33. // Base layer type as defined in `dojox.geo.openlayer.BaseLayerType
  34. // description:
  35. // baseLayerType can be either
  36. // * `OSM`
  37. // * `WMS`
  38. // * `Google`
  39. // * `VirtualEarth`
  40. // * `Yahoo`
  41. // * `ArcGIS`
  42. // baseLayerType : String
  43. // Base layer type property.
  44. baseLayerType : dojox.geo.openlayers.BaseLayerType.OSM,
  45. // summary:
  46. // The part of the map shown at startup time.
  47. // description:
  48. // initial location is the string description of the location shown at
  49. // startup time. Format is the same as for the `dojox.geo.openlayers.widget.Map.fitTo`
  50. // method.
  51. // | {
  52. // | bounds : [ulx, uly, lrx, lry]
  53. // | }
  54. // The map is fit on the specified bounds expressed as decimal degrees latitude and longitude.
  55. // The bounds are defined with their upper left and lower right corners coordinates.
  56. //
  57. // | {
  58. // | position : [longitude, latitude],
  59. // | extent : degrees
  60. // | }
  61. // The map is fit on the specified position showing the extent <extent> around
  62. // the specified center position.
  63. initialLocation : null,
  64. // summary:
  65. // Tells if the touch handler should be attached to the map or not.
  66. // description:
  67. // Tells if the touch handler should be attached to the map or not.
  68. // Touch handler handles touch events so that the widget can be used
  69. // on mobile applications.
  70. touchHandler : false,
  71. // summary:
  72. // The underlying `dojox.geo.openlayers.Map` object.
  73. // This is s readonly member.
  74. map : null,
  75. startup : function(){
  76. // summary:
  77. // Processing after the DOM fragment is added to the document
  78. this.inherited(arguments);
  79. this.map.initialFit({
  80. initialLocation : this.initialLocation
  81. });
  82. },
  83. buildRendering : function(){
  84. // summary:
  85. // Construct the UI for this widget, creates the real dojox.geo.openlayers.Map object.
  86. // tags:
  87. // protected
  88. this.inherited(arguments);
  89. var div = this.domNode;
  90. var map = new Map(div, {
  91. baseLayerType : this.baseLayerType,
  92. touchHandler : this.touchHandler
  93. });
  94. this.map = map;
  95. this._makeLayers();
  96. },
  97. _makeLayers : function(){
  98. // summary:
  99. // Creates layers defined as markup.
  100. // tags:
  101. // private
  102. var n = this.domNode;
  103. var layers = /* ?? query. */query("> .layer", n);
  104. array.forEach(layers, function(l){
  105. var type = l.getAttribute("type");
  106. var name = l.getAttribute("name");
  107. var cls = "dojox.geo.openlayers." + type;
  108. var p = dojo.getObject(cls);
  109. if (p) {
  110. var layer = new p(name, {});
  111. if (layer)
  112. this.map.addLayer(layer);
  113. }
  114. }, this);
  115. },
  116. resize : function(b){
  117. // summary:
  118. // Resize the widget.
  119. // description:
  120. // Resize the domNode and the widget to the dimensions of a box of the following form:
  121. // `{ l: 50, t: 200, w: 300: h: 150 }`
  122. // b: undefined | Box | width, height
  123. // If passed, denotes the new size of the widget.
  124. // Can be either nothing (widget adapts to the div),
  125. // a box, or a width and a height.
  126. var olm = this.map.getOLMap();
  127. var box;
  128. switch (arguments.length) {
  129. case 0:
  130. // case 0, do not resize the div, just the surface
  131. break;
  132. case 1:
  133. // argument, override node box
  134. box = dojo.mixin({}, b);
  135. dojo.marginBox(olm.div, box);
  136. break;
  137. case 2:
  138. // two argument, width, height
  139. box = {
  140. w : arguments[0],
  141. h : arguments[1]
  142. };
  143. dojo.marginBox(olm.div, box);
  144. break;
  145. }
  146. olm.updateSize();
  147. }
  148. });
  149. });