Map.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. define("dojox/geo/charting/widget/Map", ["dojo/_base/kernel", "dojo/_base/lang", "dojo/_base/declare","dojo/_base/html","dojo/dom-geometry",
  2. "dijit/_Widget","dojox/geo/charting/Map"],
  3. function(dojo, lang, declare, html,domGeom, Widget, Map) {
  4. return declare("dojox.geo.charting.widget.Map", Widget, {
  5. // summary:
  6. // A map viewer widget based on the dojox.geo.charting.Map component
  7. //
  8. // description:
  9. // The `dojox.geo.charting.widget.Map` widget combines map display together with charting capabilities.
  10. // It encapsulates an `dojox.geo.charting.Map` object on which most operations are delegated.
  11. // Parameters can be passed as argument at construction time to specify map data file (json shape format)
  12. // as well as charting data.
  13. //
  14. // The parameters are :
  15. //
  16. // * `shapeData`: The json object containing map data or the name of the file containing map data.
  17. // * `dataStore`: the dataStore to fetch the charting data from
  18. // * `dataBindingAttribute`: property name of the dataStore items to use as value for charting
  19. // * `markerData`: tooltips to display for map features, handled as json style.
  20. // * `adjustMapCenterOnResize`: if true, the center of the map remains the same when resizing the widget
  21. // * `adjustMapScaleOnResize`: if true, the map scale is adjusted to leave the visible portion of the map identical as much as possible
  22. //
  23. // example:
  24. //
  25. // | var map = new dojox.geo.charting.widget.Map({
  26. // | shapeData : 'map.json',
  27. // | adjustMapCenterOnresize : true,
  28. // | adjustMapScaleOnresize : true,
  29. // | });
  30. shapeData : "",
  31. dataStore : null,
  32. dataBindingAttribute : "",
  33. dataBindingValueFunction: null,
  34. markerData : "",
  35. series : "",
  36. adjustMapCenterOnResize: null,
  37. adjustMapScaleOnResize: null,
  38. animateOnResize: null,
  39. onFeatureClick: null,
  40. onFeatureOver: null,
  41. enableMouseSupport: null,
  42. enableTouchSupport: null,
  43. enableMouseZoom: null,
  44. enableMousePan: null,
  45. enableKeyboardSupport: false,
  46. showTooltips: false,
  47. enableFeatureZoom: null,
  48. colorAnimationDuration: 0,
  49. mouseClickThreshold: 2,
  50. _mouseInteractionSupport:null,
  51. _touchInteractionSupport:null,
  52. _keyboardInteractionSupport:null,
  53. constructor : function(/* Object */options, /* HtmlNode */div){
  54. // summary:
  55. // Constructs a new Map widget
  56. this.map = null;
  57. },
  58. startup : function(){
  59. this.inherited(arguments);
  60. if (this.map) {
  61. this.map.fitToMapContents();
  62. }
  63. },
  64. postMixInProperties : function(){
  65. this.inherited(arguments);
  66. },
  67. create : function(/*Object?*/params, /*DomNode|String?*/srcNodeRef){
  68. this.inherited(arguments);
  69. },
  70. getInnerMap: function() {
  71. return this.map;
  72. },
  73. buildRendering : function(){
  74. // summary:
  75. // Construct the UI for this widget, creates the underlying real dojox.geo.charting.Map object.
  76. // tags:
  77. // protected
  78. this.inherited(arguments);
  79. if (this.shapeData) {
  80. this.map = new Map(this.domNode, this.shapeData);
  81. if (this.markerData && (this.markerData.length > 0))
  82. this.map.setMarkerData(this.markerData);
  83. if (this.dataStore) {
  84. if (this.dataBindingValueFunction) {
  85. this.map.setDataBindingValueFunction(this.dataBindingValueFunction);
  86. }
  87. this.map.setDataStore(this.dataStore,this.dataBindingAttribute);
  88. }
  89. if (this.series && (this.series.length > 0)) {
  90. this.map.addSeries(this.series);
  91. }
  92. if (this.onFeatureClick) {
  93. this.map.onFeatureClick = this.onFeatureClick;
  94. }
  95. if (this.onFeatureOver) {
  96. this.map.onFeatureOver = this.onFeatureOver;
  97. }
  98. if (this.enableMouseSupport) {
  99. if (!dojox.geo.charting.MouseInteractionSupport) {
  100. throw Error("Can't find dojox.geo.charting.MouseInteractionSupport. Didn't you forget to dojo" + ".require() it?");
  101. }
  102. var options = {};
  103. options.enablePan = this.enableMousePan;
  104. options.enableZoom = this.enableMouseZoom;
  105. options.mouseClickThreshold = this.mouseClickThreshold;
  106. this._mouseInteractionSupport = new dojox.geo.charting.MouseInteractionSupport(this.map,options);
  107. this._mouseInteractionSupport.connect();
  108. }
  109. if (this.enableTouchSupport) {
  110. if (!dojox.geo.charting.TouchInteractionSupport) {
  111. throw Error("Can't find dojox.geo.charting.TouchInteractionSupport. Didn't you forget to dojo" + ".require() it?");
  112. }
  113. this._touchInteractionSupport = new dojox.geo.charting.TouchInteractionSupport(this.map,{});
  114. this._touchInteractionSupport.connect();
  115. }
  116. if (this.enableKeyboardSupport) {
  117. if (!dojox.geo.charting.KeyboardInteractionSupport) {
  118. throw Error("Can't find dojox.geo.charting.KeyboardInteractionSupport. Didn't you forget to dojo" + ".require() it?");
  119. }
  120. this._keyboardInteractionSupport = new dojox.geo.charting.KeyboardInteractionSupport(this.map,{});
  121. this._keyboardInteractionSupport.connect();
  122. }
  123. this.map.showTooltips = this.showTooltips;
  124. this.map.enableFeatureZoom = this.enableFeatureZoom;
  125. this.map.colorAnimationDuration = this.colorAnimationDuration;
  126. }
  127. },
  128. resize : function(b){
  129. // summary:
  130. // Resize the widget.
  131. // description:
  132. // Resize the domNode and the widget to the dimensions of a box of the following form:
  133. // `{ l: 50, t: 200, w: 300: h: 150 }`
  134. // box:
  135. // If passed, denotes the new size of the widget.
  136. var box;
  137. switch (arguments.length) {
  138. case 0:
  139. // case 0, do not resize the div, just the surface
  140. break;
  141. case 1:
  142. // argument, override node box
  143. box = lang.mixin({}, b);
  144. domGeom.getMarginBox(this.domNode, box);
  145. break;
  146. case 2:
  147. // two argument, width, height
  148. box = {
  149. w : arguments[0],
  150. h : arguments[1]
  151. };
  152. domGeom.getMarginBox(this.domNode, box);
  153. break;
  154. }
  155. if (this.map) {
  156. this.map.resize(this.adjustMapCenterOnResize,this.adjustMapScaleOnResize,this.animateOnResize);
  157. }
  158. }
  159. });
  160. });