root / trunk / web / dojo / dojox / geo / charting / _Feature.js
History | View | Annotate | Download (4.68 KB)
1 |
/*
|
---|---|
2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
4 |
see: http://dojotoolkit.org/license for details
|
5 |
*/
|
6 |
|
7 |
|
8 |
if(!dojo._hasResource["dojox.geo.charting._Feature"]){ |
9 |
dojo._hasResource["dojox.geo.charting._Feature"]=true; |
10 |
dojo.provide("dojox.geo.charting._Feature");
|
11 |
dojo.require("dojox.gfx.fx");
|
12 |
dojo.declare("dojox.geo.charting._Feature",null,{_isZoomIn:false,_isFocused:false,markerText:null,constructor:function(_1,_2,_3){ |
13 |
this.id=_2;
|
14 |
this.shape=_1.mapObj.createGroup();
|
15 |
this.parent=_1;
|
16 |
this.mapObj=_1.mapObj;
|
17 |
this._bbox=_3.bbox;
|
18 |
this._center=_3.center;
|
19 |
this._defaultFill=_1.defaultColor;
|
20 |
this._highlightFill=_1.highlightColor;
|
21 |
this._defaultStroke={width:this._normalizeStrokeWeight(0.5),color:"white"}; |
22 |
this._scale=Math.min(this.parent.containerSize.w/this._bbox.w,this.parent.containerSize.h/this._bbox.h); |
23 |
var _4=(dojo.isArray(_3.shape[0]))?_3.shape:[_3.shape]; |
24 |
dojo.forEach(_4,function(_5){
|
25 |
this.shape.createPolyline(_5).setStroke(this._defaultStroke).setFill(this._defaultFill); |
26 |
},this);
|
27 |
},setValue:function(_6){ |
28 |
this.value=_6;
|
29 |
if(this.parent.series.length!=0){ |
30 |
for(var i=0;i<this.parent.series.length;i++){ |
31 |
var _7=this.parent.series[i]; |
32 |
if((_6>=_7.min)&&(_6<_7.max)){
|
33 |
this._setFillWith(_7.color);
|
34 |
this._defaultFill=_7.color;
|
35 |
} |
36 |
} |
37 |
} |
38 |
},_setFillWith:function(_8){ |
39 |
var _9=(dojo.isArray(this.shape.children))?this.shape.children:[this.shape.children]; |
40 |
dojo.forEach(_9,function(_a){
|
41 |
_a.setFill(_8); |
42 |
}); |
43 |
},_setStrokeWith:function(_b){ |
44 |
var _c=(dojo.isArray(this.shape.children))?this.shape.children:[this.shape.children]; |
45 |
dojo.forEach(_c,function(_d){
|
46 |
_d.setStroke({color:_b.color,width:_b.width,join:"round"}); |
47 |
}); |
48 |
},_normalizeStrokeWeight:function(_e){ |
49 |
var _f=this.shape._getRealMatrix(); |
50 |
return (dojox.gfx.renderer!="vml")?_e/(this.shape._getRealMatrix()||{xx:1}).xx:_e; |
51 |
},_onmouseoverHandler:function(evt){ |
52 |
this.parent.onFeatureOver(this); |
53 |
this._setFillWith(this._highlightFill); |
54 |
this.mapObj.marker.show(this.id); |
55 |
},_onmouseoutHandler:function(){ |
56 |
this._setFillWith(this._defaultFill); |
57 |
this.mapObj.marker.hide();
|
58 |
dojo.style("mapZoomCursor","display","none"); |
59 |
},_onmousemoveHandler:function(evt){ |
60 |
if(this._isFocused){ |
61 |
var evt=dojo.fixEvent(evt||window.event);
|
62 |
dojo.style("mapZoomCursor","left",evt.pageX+12+"px"); |
63 |
dojo.style("mapZoomCursor","top",evt.pageY+"px"); |
64 |
dojo.byId("mapZoomCursor").className=(this._isZoomIn)?"mapZoomOut":"mapZoomIn"; |
65 |
dojo.style("mapZoomCursor","display","block"); |
66 |
} |
67 |
},_onclickHandler:function(){ |
68 |
if(!this._isFocused){ |
69 |
for(var _10 in this.mapObj.features){ |
70 |
if(this.mapObj.features[_10]!=this){ |
71 |
this.mapObj.features[_10]._setStrokeWith(this._defaultStroke); |
72 |
this.mapObj.features[_10]._setFillWith(this.mapObj.features[_10]._defaultFill); |
73 |
this.mapObj.features[_10]._isFocused=false; |
74 |
this.mapObj.features[_10]._isZoomIn=false; |
75 |
} |
76 |
} |
77 |
this._focus();
|
78 |
}else{
|
79 |
if(this._isZoomIn){ |
80 |
this._zoomOut();
|
81 |
}else{
|
82 |
this._zoomIn();
|
83 |
} |
84 |
} |
85 |
},_focus:function(){ |
86 |
this.shape._moveToFront();
|
87 |
this._setStrokeWith({color:"black",width:this._normalizeStrokeWeight(2)}); |
88 |
this.parent.onFeatureClick(this); |
89 |
this._isFocused=true; |
90 |
},_zoomIn:function(){ |
91 |
var _11=dojox.gfx.fx.animateTransform({duration:1000,shape:this.mapObj,transform:[{name:"translate",start:[-this.mapObj.currentBBox.x,-this.mapObj.currentBBox.y],end:[-this._bbox.x,-this._bbox.y]},{name:"scaleAt",start:[this.mapObj.currentScale,this.mapObj.currentBBox.x,this.mapObj.currentBBox.y],end:[this._scale,this._bbox.x,this._bbox.y]}]}); |
92 |
dojo.connect(_11,"onEnd",this,function(){ |
93 |
this._setStrokeWith({color:"black",width:this._normalizeStrokeWeight(2)}); |
94 |
this.parent.onZoomEnd(this); |
95 |
}); |
96 |
_11.play(); |
97 |
this.mapObj.currentScale=this._scale; |
98 |
this.mapObj.currentBBox={x:this._bbox.x,y:this._bbox.y}; |
99 |
this._isZoomIn=true; |
100 |
dojo.byId("mapZoomCursor").className=""; |
101 |
},_zoomOut:function(){ |
102 |
var _12=dojox.gfx.fx.animateTransform({duration:1000,shape:this.mapObj,transform:[{name:"translate",start:[-this._bbox.x,-this._bbox.y],end:[-this.mapObj.boundBox[0],-this.mapObj.boundBox[1]]},{name:"scaleAt",start:[this._scale,this._bbox.x,this._bbox.y],end:[this.mapObj.scale,this.mapObj.boundBox[0],this.mapObj.boundBox[1]]}]}); |
103 |
dojo.connect(_12,"onEnd",this,function(){ |
104 |
this._setStrokeWith({color:"black",width:this._normalizeStrokeWeight(2)}); |
105 |
}); |
106 |
_12.play(); |
107 |
this.mapObj.currentScale=this.mapObj.scale; |
108 |
this.mapObj.currentBBox={x:this.mapObj.boundBox[0],y:this.mapObj.boundBox[1]}; |
109 |
this._isZoomIn=false; |
110 |
dojo.byId("mapZoomCursor").className=""; |
111 |
},init:function(){ |
112 |
this.shape.rawNode.id=this.id; |
113 |
this.tooltip=null; |
114 |
this.shape.connect("onmouseover",this,this._onmouseoverHandler); |
115 |
this.shape.connect("onmouseout",this,this._onmouseoutHandler); |
116 |
this.shape.connect("onmousemove",this,this._onmousemoveHandler); |
117 |
this.shape.connect("onclick",this,this._onclickHandler); |
118 |
}}); |
119 |
} |