I have a map drawn in CorelDRAW that shows the location of some company assets. Each one in shown as a square on the map. My aim is to create an interactive version of the map, where the user can click on a square and be shown more information about the asset.
CorelDRAW allows me to specify a name for each shape. Then, if the diagram is exported as an SVG, the shape names are used for the id attributes.
This gives me a map in SVG format; let's say it looks like this:
<svg width="100" height="100">
<rect id="firstAsset" x="25" y="50" width="20" height="20" />
<rect id="secondAsset" x="50" y="15" width="20" height="20" />
</svg>
I want to be able to click on each rectangle and have information displayed about it. A popup would do, such as this example at w3cschools, or a modal box if there's more information to display.
So, I've started by embedding a test svg in an html document. This doesn't mean it will end up on a web server; the file may just end up saved on a SharePoint. Ideally it would end up a single file that can be distributed by email if need be.
Here is what I have so far, using modal boxes: link to js fiddle.
The problem is, the full SVG is going to have dozens more clickable shapes, and if the map is updated in CorelDRAW, I will have to add the onclick() and class attributes to each shape all over again. I need to be able to take information about each asset in some standard format, and then have it automatically added to each asset in the SVG.
I originally envisioned writing a script that would take the SVG file and a file with the information to display. It would search the SVG for id attributes, check for corresponding information to display, and if so make the element clickable to display that information. This is where I'm stuck. Do I need to write a separate program just to maintain this map? Or could this be done using javascript in the document itself?
To recap, I have:
- An automatically generated SVG with id attributes against each asset
- I will have some information about each asset, which I can put in html format
and I want to be able to click on an asset on the map and show the information about it.
P.S. I'm new to html and javascript.