[483] | 1 | define([ |
---|
| 2 | "dojo/_base/lang", |
---|
| 3 | "dojo/_base/declare", |
---|
| 4 | "dojo/_base/array", |
---|
| 5 | "dojo/_base/html", |
---|
| 6 | "dojo/dom", |
---|
| 7 | "dojo/_base/event", |
---|
| 8 | "dojox/gfx/fx", |
---|
| 9 | "dojox/color" |
---|
| 10 | ], function(lang, declare,arr, html,dom, event, fx,color){ |
---|
| 11 | |
---|
| 12 | return declare("dojox.geo.charting.Feature", null, { |
---|
| 13 | // summary: |
---|
| 14 | // A class to encapsulate a map element. |
---|
| 15 | // tags: |
---|
| 16 | // private |
---|
| 17 | |
---|
| 18 | _isZoomIn: false, |
---|
| 19 | isSelected: false, |
---|
| 20 | markerText:null, |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | constructor: function(parent, name, shapeData){ |
---|
| 24 | // summary: |
---|
| 25 | // constructs a new Feature. |
---|
| 26 | // tags: |
---|
| 27 | // private |
---|
| 28 | this.id = name; |
---|
| 29 | this.shape = parent.mapObj.createGroup(); |
---|
| 30 | this.parent = parent; |
---|
| 31 | this.mapObj = parent.mapObj; |
---|
| 32 | this._bbox = shapeData.bbox; |
---|
| 33 | this._center = shapeData.center; |
---|
| 34 | //TODO: fill color would be defined by charting data and legend |
---|
| 35 | // this._highlightFill = ["#FFCE52", "#CE6342", "#63A584"][Math.floor(Math.random() * 3)]; |
---|
| 36 | this._defaultFill = parent.defaultColor; |
---|
| 37 | this._highlightFill = parent.highlightColor; |
---|
| 38 | this._defaultStroke = { |
---|
| 39 | width: this._normalizeStrokeWeight(.5), |
---|
| 40 | color: "white" |
---|
| 41 | }; |
---|
| 42 | |
---|
| 43 | var shapes = (lang.isArray(shapeData.shape[0])) ? shapeData.shape : [shapeData.shape]; |
---|
| 44 | arr.forEach(shapes, function(points){ |
---|
| 45 | this.shape.createPolyline(points).setStroke(this._defaultStroke); |
---|
| 46 | }, this); |
---|
| 47 | this.unsetValue(); |
---|
| 48 | }, |
---|
| 49 | unsetValue:function(){ |
---|
| 50 | // summary: |
---|
| 51 | // clears the numeric value on this Feature object (removes color). |
---|
| 52 | |
---|
| 53 | this.value = null; |
---|
| 54 | this.unsetColor(); |
---|
| 55 | }, |
---|
| 56 | unsetColor:function(){ |
---|
| 57 | // summary: |
---|
| 58 | // clears the colors on this Feature object. |
---|
| 59 | |
---|
| 60 | this._defaultFill = this.parent.defaultColor; |
---|
| 61 | var col = new color.Color(this.parent.defaultColor).toHsl(); |
---|
| 62 | col.l = 1.2 * col.l; |
---|
| 63 | this._highlightFill = color.fromHsl(col); |
---|
| 64 | this._setFillWith(this._defaultFill); |
---|
| 65 | }, |
---|
| 66 | setValue:function(value){ |
---|
| 67 | // summary: |
---|
| 68 | // sets a numeric value on this Feature object (used together with series to apply a color). |
---|
| 69 | // value: Number |
---|
| 70 | // A numeric value. |
---|
| 71 | |
---|
| 72 | this.value = value; |
---|
| 73 | if(value == null){ |
---|
| 74 | this.unsetValue(); |
---|
| 75 | }else{ |
---|
| 76 | if(this.parent.series.length != 0){ |
---|
| 77 | for(var i = 0; i < this.parent.series.length; i++){ |
---|
| 78 | var range = this.parent.series[i]; |
---|
| 79 | if((value >= range.min) && (value < range.max)){ |
---|
| 80 | this._setFillWith(range.color); |
---|
| 81 | this._defaultFill = range.color; |
---|
| 82 | var col = new color.Color(range.color).toHsv(); |
---|
| 83 | col.v = (col.v + 20); |
---|
| 84 | this._highlightFill = color.fromHsv(col); |
---|
| 85 | return; |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | // did not found a range : unset color |
---|
| 89 | this.unsetColor(); |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | }, |
---|
| 93 | _setFillWith: function(color){ |
---|
| 94 | var borders = (lang.isArray(this.shape.children)) ? this.shape.children : [this.shape.children]; |
---|
| 95 | arr.forEach(borders, lang.hitch(this,function(item){ |
---|
| 96 | if(this.parent.colorAnimationDuration > 0){ |
---|
| 97 | var anim1 = fx.animateFill({ |
---|
| 98 | shape: item, |
---|
| 99 | color: { |
---|
| 100 | start: item.getFill(), |
---|
| 101 | end: color |
---|
| 102 | }, |
---|
| 103 | duration: this.parent.colorAnimationDuration |
---|
| 104 | }); |
---|
| 105 | anim1.play(); |
---|
| 106 | }else{ |
---|
| 107 | item.setFill(color); |
---|
| 108 | } |
---|
| 109 | })); |
---|
| 110 | }, |
---|
| 111 | _setStrokeWith: function(stroke){ |
---|
| 112 | var borders = (lang.isArray(this.shape.children)) ? this.shape.children : [this.shape.children]; |
---|
| 113 | arr.forEach(borders, function(item){ |
---|
| 114 | item.setStroke({ |
---|
| 115 | color: stroke.color, |
---|
| 116 | width: stroke.width, |
---|
| 117 | join: "round" |
---|
| 118 | }); |
---|
| 119 | }); |
---|
| 120 | }, |
---|
| 121 | _normalizeStrokeWeight: function(weight){ |
---|
| 122 | var matrix = this.shape._getRealMatrix(); |
---|
| 123 | return (dojox.gfx.renderer != "vml")?weight/(this.shape._getRealMatrix()||{xx:1}).xx:weight; |
---|
| 124 | }, |
---|
| 125 | _onmouseoverHandler: function(evt){ |
---|
| 126 | this.parent.onFeatureOver(this); |
---|
| 127 | this._setFillWith(this._highlightFill); |
---|
| 128 | this.mapObj.marker.show(this.id, evt); |
---|
| 129 | }, |
---|
| 130 | _onmouseoutHandler: function(){ |
---|
| 131 | this._setFillWith(this._defaultFill); |
---|
| 132 | this.mapObj.marker.hide(); |
---|
| 133 | html.style("mapZoomCursor", "display", "none"); |
---|
| 134 | }, |
---|
| 135 | _onmousemoveHandler: function(evt){ |
---|
| 136 | if(this.mapObj.marker._needTooltipRefresh){ |
---|
| 137 | this.mapObj.marker.show(this.id, evt); |
---|
| 138 | } |
---|
| 139 | if(this.isSelected && evt){ |
---|
| 140 | if(this.parent.enableFeatureZoom){ |
---|
| 141 | evt = event.fix(evt || window.event); |
---|
| 142 | html.style("mapZoomCursor", "left", evt.pageX + 12 + "px"); |
---|
| 143 | html.style("mapZoomCursor", "top", evt.pageY + "px"); |
---|
| 144 | html.byId("mapZoomCursor").className = this._isZoomIn ? "mapZoomOut":"mapZoomIn"; |
---|
| 145 | html.style("mapZoomCursor", "display", "block"); |
---|
| 146 | }else{ |
---|
| 147 | html.style("mapZoomCursor", "display", "none"); |
---|
| 148 | } |
---|
| 149 | } |
---|
| 150 | }, |
---|
| 151 | _onclickHandler: function(evt){ |
---|
| 152 | this.parent.onFeatureClick(this); |
---|
| 153 | if(!this.isSelected){ |
---|
| 154 | this.parent.deselectAll(); |
---|
| 155 | this.select(true); |
---|
| 156 | this._onmousemoveHandler(evt); |
---|
| 157 | }else if(this.parent.enableFeatureZoom){ |
---|
| 158 | if(this._isZoomIn){ |
---|
| 159 | this._zoomOut(); |
---|
| 160 | }else{ |
---|
| 161 | this._zoomIn(); |
---|
| 162 | } |
---|
| 163 | } |
---|
| 164 | }, |
---|
| 165 | |
---|
| 166 | select: function(selected){ |
---|
| 167 | // summary: |
---|
| 168 | // Sets the selected state of this feature to the given value. |
---|
| 169 | // selected: Boolean |
---|
| 170 | // A Boolean value indicating the selected state. |
---|
| 171 | |
---|
| 172 | if(selected){ |
---|
| 173 | this.shape.moveToFront(); |
---|
| 174 | this._setStrokeWith({color:"black",width:this._normalizeStrokeWeight(2)}); |
---|
| 175 | this._setFillWith(this._highlightFill); |
---|
| 176 | this.isSelected = true; |
---|
| 177 | this.parent.selectedFeature = this; |
---|
| 178 | }else{ |
---|
| 179 | this._setStrokeWith(this._defaultStroke); |
---|
| 180 | this._setFillWith(this._defaultFill); |
---|
| 181 | this.isSelected = false; |
---|
| 182 | this._isZoomIn = false; |
---|
| 183 | } |
---|
| 184 | }, |
---|
| 185 | |
---|
| 186 | _zoomIn: function(){ |
---|
| 187 | var marker = this.mapObj.marker; |
---|
| 188 | marker.hide(); |
---|
| 189 | this.parent.fitToMapArea(this._bbox, 15,true,lang.hitch(this,function(){ |
---|
| 190 | this._setStrokeWith({color:"black",width:this._normalizeStrokeWeight(2)}); |
---|
| 191 | marker._needTooltipRefresh = true; |
---|
| 192 | this.parent.onZoomEnd(this); |
---|
| 193 | })); |
---|
| 194 | this._isZoomIn = true; |
---|
| 195 | dom.byId("mapZoomCursor").className = ""; |
---|
| 196 | }, |
---|
| 197 | _zoomOut: function(){ |
---|
| 198 | var marker = this.mapObj.marker; |
---|
| 199 | marker.hide(); |
---|
| 200 | this.parent.fitToMapContents(3,true,lang.hitch(this,function(){ |
---|
| 201 | this._setStrokeWith({color:"black",width:this._normalizeStrokeWeight(2)}); |
---|
| 202 | marker._needTooltipRefresh = true; |
---|
| 203 | this.parent.onZoomEnd(this); |
---|
| 204 | })); |
---|
| 205 | this._isZoomIn = false; |
---|
| 206 | dom.byId("mapZoomCursor").className = ""; |
---|
| 207 | }, |
---|
| 208 | |
---|
| 209 | init: function(){ |
---|
| 210 | // summary: |
---|
| 211 | // Initializes this feature. |
---|
| 212 | |
---|
| 213 | this.shape.id = this.id; |
---|
| 214 | this.tooltip = null; |
---|
| 215 | } |
---|
| 216 | }); |
---|
| 217 | }); |
---|