Im a bit of a noob when it comes to front end and this SVG seems to be a lot more harder than the rest ! I have added an object in an SVG tag via JS and here is what it looks like;
no matter what I do, the object is always showing up as 0x0 in the corner what am i missing here? Any help is appreciated!
Here is the JS function:
success: function (fdataf) {
$trdoc = new DOMParser().parseFromString(fdataf, 'text/html');
$rooms = $trdoc.getElementsByClassName("Room");
$main_svg = $trdoc.getElementById("main_svg");
// $created_image = $trdoc.createElement("svg");
// $created_image.setAttribute("width", "23");
// $created_image.setAttribute("height", "23");
// $created_image.setAttribute("id", "NEWSENSOR");
//
// $created_image.setAttribute("viewBox", "85.5 51.0 4630.1 4565.1");
$objectEl = $trdoc.createElement("object");
$objectEl.setAttribute("src", "gas_detector.svg");
$objectEl.setAttribute("type", "image/svg+xml");
$objectEl.setAttribute("width", "100");
$objectEl.setAttribute("height", "100");
$objectEl.setAttribute("Content-type", "image/svg+xml");
// $created_image.appendChild($objectEl);
for (let i = 0; i < $rooms.length; i++) {
$roomName = $rooms[i].getAttribute("id");
$rx = $rooms[i].getAttribute("x");
$ry = $rooms[i].getAttribute("y");
console.log($roomName);
if ($roomName == 'Room102'){
// $created_image.setAttribute("x", +($rx) + 5);
// $created_image.setAttribute("y", +($ry) + 5);
// $created_image.setAttribute("id", "NEWSENSOR");
console.log(typeof (+($rx)));
$main_svg.appendChild($objectEl);
}
}
console.log("AREWE?")
console.log(new XMLSerializer().serializeToString($trdoc));
document.getElementById("floorView").innerHTML = new XMLSerializer().serializeToString($trdoc);
document.getElementById(calling_floor).style.fill = "#0275d8";
}
});}
Tried to embed the object in a foreignObject but it dodnt help:
$created_image = $trdoc.createElement("foreignObject");
// $created_image.setAttribute("width", "23");
// $created_image.setAttribute("height", "23");
// $created_image.setAttribute("id", "NEWSENSOR");
//
// $created_image.setAttribute("viewBox", "85.5 51.0 4630.1 4565.1");
$objectEl = $trdoc.createElement("object");
$objectEl.setAttribute("src", "gas_detector.svg");
$objectEl.setAttribute("type", "image/svg+xml");
$objectEl.setAttribute("width", "100");
$objectEl.setAttribute("height", "100");
$objectEl.setAttribute("Content-type", "image/svg+xml");
$created_image.appendChild($objectEl);