<path d="M01.010101, ..." type="unit" name="Store A">
<path d="M02.101010, ..." type="corridor">
// Notice I'm not using Paperscript
paper.project.importSVG(document.getElementById('levelSVG'), {
expandShapes: true, // expand shapes to full Paperjs Path objects
applyMatrix: true, // imported items have their transformation matrices applied to their contents
onLoad: function(item, svgData) {
_this.setState({'levelCanvasObject': item}); // ignore this Reactiness
item.scale(parseFloat(magnification)); // ignore this
}
});However, I noticed that when I import the SVG, the resulting Object has this structure:
Group {
applyMatrix: true,
...,
children: [
0: Path {
applyMatrix: true,
...,
name: null // this is what I want to populate with the name attribute
// there is also no type attribute (so I can't tell if it's a Unit or Corridor)
},
...
],
...
}
In summary, the goal is to highlight the Unit-type paths with a red color when hovered with the mouse, and use that show the Path's name somewhere in the DOM. My initial thoughts are that I should be passing the 'name' and 'type' attributes down from the SVG to the Paper paths during the import process. Then using onMouseEnter/Leave methods on each path to grab the path type; if it's a Unit type, then grab the path name and append it to a DOM element somewhere.
Am I on the right track? How can I get the name and type on each Path using importSVG? How would you recommend implementing a feature like this?
Thanks,
JJ @ Fantasmo
function importPath(node) {
return PathItem.create(node.getAttribute('d'));
}onLoad: function(item, svgData) {
// _this.setState({'levelCanvasObject': item}); // ignore
// item.scale(parseFloat(magnification)); // ignore
item.children.forEach((path, index) => {
const relativeSVGPath = svgData.children[index];
path.name = relativeSVGPath.name;
path.type = relativeSVGPath.type;
path.onMouseEnter(() => { /* add name to DOM element if it's a Unit type */ }
path.onMouseLeave(() => { /* remove name from DOM element */ }
});
}