I have drawn a floor map of a super market using MS Visio 2013. I have converted it to a svg file. What i want to do is to pin point some locations of the floor map using another svg file.
I have tried this by many other means. I created a html 5 canvas and drew the map using javascript commands.Then i used a svg image to show the locations.
ctx.drawSvg('location.svg', x_coordinate , y_coordinate , 10, 14);
//x_coordinate,y_coordinate is defining the multiple locations which this location.svg file will be drawn.
But results of that method was low in quality. Not to mention the fact that it gets more low quality when you zoom in to the map.
I know the method of embedding a svg to a html page or using a svg file as a background.But with those two how can i use another svg file to pinpoint the multiple locations?
Is there any way of doing this using svg files? :)
This is actually quite simple. There are several ways to do it, but the following way is probably one of the simplest. It doesn't use Canvas at all, just pure SVG.
I am going to assume that when you say the "pin" is another file, that is not really a strict requirement. Ie. that there is no reason you couldn't include the pin picture in your map SVG file.
Here's a sample SVG map file. I will assume for now that it is embedded in the HTML file, but an external file should work as well.
The group "floor" is our floor plan, and the pin image has been included in the
<defs>
section. Stuff defined in the<defs>
section is not rendered itself. It has to be referenced elsewhere in the file.From here all you need is a simple Javascript loop which uses the DOM to add one
<use>
element for each pin.The
<use>
allows us to make a reference to another element in the SVG file. So we create a<use>
element for each pin we want to place. Each<use>
references our predefined pin symbol.Here is a demo: http://jsfiddle.net/6cFfU/3/
Update:
To use an external "pin" file, referencing it from an image should work.
Demo here: http://jsfiddle.net/6cFfU/4/
If you are not even allowed to reference the pin file from your map file. Then you just need to insert this marker definition using a bit of DOM manipulation. Something like:
Demo here: http://jsfiddle.net/7Mysc/1/
That's assuming you want to go the pure SVG route. There are other ways. For instance you could do a similar thing using HTML. Wrap your PIN file in a
<div>
and use jQuery to clone the div, then use absolute positioning to position them them in the correct place. However you then have to worry about adjusting for the map scale etc.