root / trunk / web / dojo / dojox / drawing / plugins / tools / Iconize.js
History | View | Annotate | Download (1.66 KB)
| 1 | 9 | andrej.cim | /*
|
|---|---|---|---|
| 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.drawing.plugins.tools.Iconize"]){ |
||
| 9 | dojo._hasResource["dojox.drawing.plugins.tools.Iconize"]=true; |
||
| 10 | dojo.provide("dojox.drawing.plugins.tools.Iconize");
|
||
| 11 | dojo.require("dojox.drawing.plugins._Plugin");
|
||
| 12 | dojox.drawing.plugins.tools.Iconize=dojox.drawing.util.oo.declare(dojox.drawing.plugins._Plugin,function(_1){
|
||
| 13 | },{onClick:function(){
|
||
| 14 | var _2;
|
||
| 15 | for(var nm in this.stencils.stencils){ |
||
| 16 | if(this.stencils.stencils[nm].shortType=="path"){ |
||
| 17 | _2=this.stencils.stencils[nm];
|
||
| 18 | break;
|
||
| 19 | } |
||
| 20 | } |
||
| 21 | if(_2){
|
||
| 22 | this.makeIcon(_2.points);
|
||
| 23 | } |
||
| 24 | },makeIcon:function(p){ |
||
| 25 | var _3=function(n){ |
||
| 26 | return Number(n.toFixed(1)); |
||
| 27 | }; |
||
| 28 | var x=10000; |
||
| 29 | var y=10000; |
||
| 30 | p.forEach(function(pt){
|
||
| 31 | if(pt.x!==undefined&&!isNaN(pt.x)){ |
||
| 32 | x=Math.min(x,pt.x); |
||
| 33 | y=Math.min(y,pt.y); |
||
| 34 | } |
||
| 35 | }); |
||
| 36 | var _4=0; |
||
| 37 | var _5=0; |
||
| 38 | p.forEach(function(pt){
|
||
| 39 | if(pt.x!==undefined&&!isNaN(pt.x)){ |
||
| 40 | pt.x=_3(pt.x-x); |
||
| 41 | pt.y=_3(pt.y-y); |
||
| 42 | _4=Math.max(_4,pt.x); |
||
| 43 | _5=Math.max(_5,pt.y); |
||
| 44 | } |
||
| 45 | }); |
||
| 46 | var s=60; |
||
| 47 | var m=20; |
||
| 48 | p.forEach(function(pt){
|
||
| 49 | pt.x=_3(pt.x/_4)*s+m; |
||
| 50 | pt.y=_3(pt.y/_5)*s+m; |
||
| 51 | }); |
||
| 52 | var _6="[\n"; |
||
| 53 | dojo.forEach(p,function(pt,i){
|
||
| 54 | _6+="{\t";
|
||
| 55 | if(pt.t){
|
||
| 56 | _6+="t:'"+pt.t+"'"; |
||
| 57 | } |
||
| 58 | if(pt.x!==undefined&&!isNaN(pt.x)){ |
||
| 59 | if(pt.t){
|
||
| 60 | _6+=", ";
|
||
| 61 | } |
||
| 62 | _6+="x:"+pt.x+",\t\ty:"+pt.y; |
||
| 63 | } |
||
| 64 | _6+="\t}";
|
||
| 65 | if(i!=p.length-1){ |
||
| 66 | _6+=",";
|
||
| 67 | } |
||
| 68 | _6+="\n";
|
||
| 69 | }); |
||
| 70 | _6+="]";
|
||
| 71 | var n=dojo.byId("data"); |
||
| 72 | if(n){
|
||
| 73 | n.value=_6; |
||
| 74 | } |
||
| 75 | }}); |
||
| 76 | dojox.drawing.plugins.tools.Iconize.setup={name:"dojox.drawing.plugins.tools.Iconize",tooltip:"Iconize Tool",iconClass:"iconPan"};
|
||
| 77 | dojox.drawing.register(dojox.drawing.plugins.tools.Iconize.setup,"plugin");
|
||
| 78 | } |