| 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 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
_isZoomIn: false, |
| 19 |
isSelected: false, |
| 20 |
markerText:null, |
| 21 |
|
| 22 |
|
| 23 |
constructor: function(parent, name, shapeData){ |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 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 |
|
| 35 |
|
| 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 |
|
| 51 |
|
| 52 |
|
| 53 |
this.value = null; |
| 54 |
this.unsetColor(); |
| 55 |
}, |
| 56 |
unsetColor:function(){ |
| 57 |
|
| 58 |
|
| 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 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 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 |
|
| 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 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 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 |
|
| 211 |
|
| 212 |
|
| 213 |
this.shape.id = this.id; |
| 214 |
this.tooltip = null; |
| 215 |
} |
| 216 |
}); |
| 217 |
}); |