Commit 525f3102 authored by hertzhaft's avatar hertzhaft

more refactoring for renderShape

parent acf109a7
...@@ -360,104 +360,79 @@ ...@@ -360,104 +360,79 @@
}; };
$.each(coords, createHandle); $.each(coords, createHandle);
}; };
// convert coords into an array of screen points
var p = $.map(coords, function(coord) {
return trafo.transform(geom.position(coord));
});
var p1 = p[0];
var p2 = p[1];
var $elem;
// render the shape // render the shape
if (gt === 'Point') { if (gt === 'Point') {
/* /*
* Point * Point
*/ */
var p1 = trafo.transform(geom.position(coords[0]));
// point uses pin-like path of size 3*pu // point uses pin-like path of size 3*pu
var pu = hs / 3; var pu = hs / 3;
var $elem = $(svgElement('path', { $elem = $(svgElement('path', {
'id': id, 'class': cssclass, 'id': id, 'class': cssclass,
'd': 'M '+p1.x+','+p1.y+' l '+2*pu+','+pu+' c '+2*pu+','+pu+' '+0+','+3*pu+' '+(-pu)+','+pu+' Z', 'd': 'M '+p1.x+','+p1.y+' l '+2*pu+','+pu+' c '+2*pu+','+pu+' '+0+','+3*pu+' '+(-pu)+','+pu+' Z',
'stroke': stroke, 'stroke-width': strokeWidth, 'stroke': stroke, 'stroke-width': strokeWidth,
'fill': fill, 'style': style})); 'fill': fill, 'style': style}));
shape.$elem = $elem;
$svg.append($elem);
if (props.editable) {
$elem.one("mousedown.dlVertexDrag", getVertexDragHandler(data, shape, 0));
}
} else if (gt === 'Line') { } else if (gt === 'Line') {
/* /*
* Line * Line
*/ */
var p1 = trafo.transform(geom.position(coords[0])); $elem = $(svgElement('line', {
var p2 = trafo.transform(geom.position(coords[1]));
var $elem = $(svgElement('line', {
'id': id, 'class': cssclass, 'id': id, 'class': cssclass,
'x1': p1.x, 'y1': p1.y, 'x1': p1.x, 'y1': p1.y,
'x2': p2.x, 'y2': p2.y, 'x2': p2.x, 'y2': p2.y,
'stroke': stroke, 'stroke-width': strokeWidth, 'style': style})); 'stroke': stroke, 'stroke-width': strokeWidth, 'style': style}));
shape.$elem = $elem;
$svg.append($elem);
createHandles(shape);
} else if (gt === 'Rectangle') { } else if (gt === 'Rectangle') {
/* /*
* Rectangle * Rectangle
*/ */
var p1 = trafo.transform(geom.position(coords[0]));
var p2 = trafo.transform(geom.position(coords[1]));
var rect = geom.rectangle(p1, p2); var rect = geom.rectangle(p1, p2);
var $elem = $(svgElement('rect', { $elem = $(svgElement('rect', {
'id': id, 'class': cssclass, 'id': id, 'class': cssclass,
'x': rect.x, 'y': rect.y, 'x': rect.x, 'y': rect.y,
'width': rect.width, 'height': rect.height, 'width': rect.width, 'height': rect.height,
'stroke': stroke, 'stroke-width': strokeWidth, 'stroke': stroke, 'stroke-width': strokeWidth,
'fill': fill, 'style': style})); 'fill': fill, 'style': style}));
shape.$elem = $elem;
$svg.append($elem);
createHandles(shape);
} else if (gt === 'Polygon') { } else if (gt === 'Polygon') {
/* /*
* Polygon * Polygon
*/ */
var ps = []; $elem = $(svgElement('polygon', {
for (var i in coords) {
ps[i] = trafo.transform(geom.position(coords[i]));
}
var $elem = $(svgElement('polygon', {
'id': id, 'class': cssclass, 'id': id, 'class': cssclass,
'points': ps.join(" "), 'points': p.join(" "),
'stroke': stroke, 'stroke-width': strokeWidth, 'stroke': stroke, 'stroke-width': strokeWidth,
'fill': fill, 'style': style})); 'fill': fill, 'style': style}));
shape.$elem = $elem;
$svg.append($elem);
createHandles(shape);
} else if (gt === 'LineString') { } else if (gt === 'LineString') {
/* /*
* Polyline * Polyline
*/ */
var ps = []; $elem = $(svgElement('polyline', {
for (var i in coords) {
ps[i] = trafo.transform(geom.position(coords[i]));
}
var $elem = $(svgElement('polyline', {
'id': id, 'class': cssclass, 'id': id, 'class': cssclass,
'points': ps.join(" "), 'points': p.join(" "),
'stroke': stroke, 'stroke-width': strokeWidth, 'stroke': stroke, 'stroke-width': strokeWidth,
'fill': 'none', 'style': style})); 'fill': 'none', 'style': style}));
shape.$elem = $elem;
$svg.append($elem);
createHandles(shape);
} else if (gt === 'Circle') { } else if (gt === 'Circle') {
/* /*
* Circle * Circle
*/ */
var p1 = trafo.transform(geom.position(coords[0])); $elem = $(svgElement('circle', {
var p2 = trafo.transform(geom.position(coords[1]));
var $elem = $(svgElement('circle', {
'id': id, 'class': cssclass, 'id': id, 'class': cssclass,
'cx': p1.x, 'cy': p1.y, 'r' : p1.distance(p2), 'cx': p1.x, 'cy': p1.y, 'r' : p1.distance(p2),
'fill' : 'none', 'stroke': stroke, 'stroke-width': strokeWidth, 'fill' : 'none', 'stroke': stroke, 'stroke-width': strokeWidth,
'style': style})); 'style': style}));
shape.$elem = $elem;
$svg.append($elem);
createHandles(shape);
} else { } else {
console.error("Unable to render shape type:", gt); console.error("Unable to render shape type:", gt);
return; return;
} }
$svg.append($elem);
shape.$elem = $elem;
createHandles(shape);
$(data).trigger("renderShape", shape); $(data).trigger("renderShape", shape);
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment