return;
}
// Step1: get or create the symbol element:
// check existence
Element def = DOM.getElementById(id);
boolean isNew = (def == null);
// create or update
def = helper.createOrUpdateElement(defsGroup, id, "symbol", null, false);
DOM.setElementAttribute(def, "overflow", "visible");
// Step2: fill in the correct values:
Element node = null;
if (symbol.getRect() != null) {
// Create the rectangle symbol:
long width = (long) symbol.getRect().getW();
long height = (long) symbol.getRect().getH();
if (transformation != null && transformation.getXx() != 0) {
double scale = transformation.getXx();
width = Math.round(width / scale);
height = Math.round(height / scale);
}
node = DOM.createElementNS(DOM.NS_SVG, "rect");
DOM.setElementAttribute(node, "width", Long.toString(width));
DOM.setElementAttribute(node, "height", Long.toString(height));
DOM.setElementAttribute(node, "x", Long.toString(-Math.round(width / 2)));
DOM.setElementAttribute(node, "y", Long.toString(-Math.round(height / 2)));
} else if (symbol.getCircle() != null) {
// Create the circle symbol:
long radius = (long) symbol.getCircle().getR();
if (transformation != null && transformation.getXx() != 0) {
double scale = transformation.getXx();
radius = Math.round(radius / scale);
}
node = DOM.createElementNS(DOM.NS_SVG, "circle");
DOM.setElementAttribute(node, "cx", "0");
DOM.setElementAttribute(node, "cy", "0");
DOM.setElementAttribute(node, "r", Long.toString(radius));
} else if (symbol.getImage() != null) {
// Create the image symbol:
node = DOM.createElementNS(DOM.NS_SVG, "image");
String href = symbol.getImage().getHref();
if (href.indexOf(':') <= 0) {
// SVG in Chrome can't handle relative paths (the xml:base attribute has not yet been tested):
href = GWT.getHostPageBaseURL() + href;
}
DOM.setElementAttributeNS(DOM.NS_XLINK, node, "xlink:href", href);
long width = (long) symbol.getImage().getWidth();
long height = (long) symbol.getImage().getHeight();
if (transformation != null && transformation.getXx() != 0) {
double scale = transformation.getXx();
width = Math.round(width / scale);
height = Math.round(height / scale);
}
DOM.setElementAttribute(node, "width", Long.toString(width));
DOM.setElementAttribute(node, "height", Long.toString(height));
DOM.setElementAttribute(node, "x", Long.toString(-Math.round(width / 2)));
DOM.setElementAttribute(node, "y", Long.toString(-Math.round(height / 2)));
if (isNew) {
Element node2 = DOM.createElementNS(DOM.NS_SVG, "image");
href = symbol.getImage().getSelectionHref();
if (href.indexOf(':') <= 0) {
// SVG in Chrome can't handle relative paths (the xml:base attribute has not yet been tested):
href = GWT.getHostPageBaseURL() + href;
}
DOM.setElementAttributeNS(DOM.NS_XLINK, node2, "xlink:href", href);
DOM.setElementAttribute(node2, "width", Long.toString(width));
DOM.setElementAttribute(node2, "height", Long.toString(height));
DOM.setElementAttribute(node2, "x", Long.toString(-Math.round(width / 2)));
DOM.setElementAttribute(node2, "y", Long.toString(-Math.round(height / 2)));
Element def2 = helper.createOrUpdateElement(defsGroup, id + "-selection", "symbol", null, false);
DOM.setElementAttribute(def2, "overflow", "visible");
def2.appendChild(node2);
defs.appendChild(def2);
}
}
// Step3: Append the symbol definition: