| 1 |
define(["dojo", "../../util/oo", "../_Plugin", "../../manager/_registry"], |
| 2 |
function(dojo, oo, Plugin, registry){ |
| 3 |
|
| 4 |
|
| 5 |
var Iconize = oo.declare( |
| 6 |
Plugin, |
| 7 |
function(options){ |
| 8 |
|
| 9 |
}, |
| 10 |
{ |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
onClick: function(){ |
| 17 |
var item; |
| 18 |
for(var nm in this.stencils.stencils){ |
| 19 |
console.log(" stanceil item:", this.stencils.stencils[nm].id, this.stencils.stencils[nm]) |
| 20 |
if(this.stencils.stencils[nm].shortType=="path"){ |
| 21 |
item = this.stencils.stencils[nm]; |
| 22 |
break; |
| 23 |
} |
| 24 |
} |
| 25 |
if(item){ |
| 26 |
console.log("click Iconize plugin", item.points); |
| 27 |
this.makeIcon(item.points); |
| 28 |
} |
| 29 |
}, |
| 30 |
makeIcon: function(p){ |
| 31 |
var rnd = function(n){ |
| 32 |
return Number(n.toFixed(1)); |
| 33 |
} |
| 34 |
|
| 35 |
var x = 10000; |
| 36 |
var y = 10000; |
| 37 |
p.forEach(function(pt){ |
| 38 |
if(pt.x!==undefined && !isNaN(pt.x)){ |
| 39 |
x = Math.min(x, pt.x); |
| 40 |
y = Math.min(y, pt.y); |
| 41 |
} |
| 42 |
}); |
| 43 |
|
| 44 |
var xmax = 0; |
| 45 |
var ymax = 0; |
| 46 |
p.forEach(function(pt){ |
| 47 |
if(pt.x!==undefined && !isNaN(pt.x)){ |
| 48 |
pt.x = rnd(pt.x - x); |
| 49 |
|
| 50 |
pt.y = rnd(pt.y - y); |
| 51 |
xmax = Math.max(xmax, pt.x); |
| 52 |
ymax = Math.max(ymax, pt.y); |
| 53 |
} |
| 54 |
}); |
| 55 |
|
| 56 |
console.log("xmax:", xmax, "ymax:", ymax) |
| 57 |
|
| 58 |
var s = 60 |
| 59 |
var m = 20 |
| 60 |
|
| 61 |
p.forEach(function(pt){ |
| 62 |
pt.x = rnd(pt.x / xmax) * s + m; |
| 63 |
pt.y = rnd(pt.y / ymax) * s + m; |
| 64 |
}); |
| 65 |
|
| 66 |
var txt = "[\n"; |
| 67 |
dojo.forEach(p, function(pt, i){ |
| 68 |
txt += "{\t" |
| 69 |
if(pt.t){ |
| 70 |
txt += "t:'"+pt.t+"'" |
| 71 |
} |
| 72 |
if(pt.x!==undefined && !isNaN(pt.x)){ |
| 73 |
if(pt.t){ |
| 74 |
txt += ", "; |
| 75 |
} |
| 76 |
txt += "x:"+pt.x+",\t\ty:"+pt.y; |
| 77 |
} |
| 78 |
txt += "\t}"; |
| 79 |
if(i!=p.length-1){ |
| 80 |
txt += "," |
| 81 |
} |
| 82 |
txt += "\n" |
| 83 |
}); |
| 84 |
txt+="]" |
| 85 |
|
| 86 |
console.log(txt) |
| 87 |
var n = dojo.byId("data"); |
| 88 |
if(n){ |
| 89 |
n.value = txt; |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
); |
| 94 |
|
| 95 |
Iconize.setup = { |
| 96 |
name:"dojox.drawing.plugins.tools.Iconize", |
| 97 |
tooltip:"Iconize Tool", |
| 98 |
iconClass:"iconPan" |
| 99 |
}; |
| 100 |
dojo.setObject('dojox.drawing.plugins.tools.Iconize', Iconize); |
| 101 |
registry.register(Iconize.setup, "plugin"); |
| 102 |
|
| 103 |
return Iconize; |
| 104 |
}); |