开发者

Inserting metadata "markers" in an SVG image - is this possible?

I've created an SVG image parser class for Android, which is working nicely and is pretty much complete for the purposes I want. The application I am currently writing makes use of building floor plans which I design in Inkscape beforehand. Now, what I would like to do is to be able to mark specific X,Y points on the plan, which will not be rendered, but would just serve to inform the software application about where specific points are on the plan. This is so that the application can programmatically place various markers at those points at run-time.

The actual coding of it isn't the problem; I currently already have it working using text strings, though I could use various objects. What I do is place a text stri开发者_如何学Cng and I give the text string's ID attribute a special prefix, such as "_meta". My SVG parser then identifies that prefix, and records the string's X,Y co-ordinates together with any other metadata I put in the ID attribute after the "_meta" prefix. The string is not rendered to screen; it serves purely to tell the software about a particular point.

This works and I can happily continue to do it like this, but what I'd like to know is whether there is a more 'correct' or more elegant way to do this. I've looked over the SVG specification and my understanding about the standard metadata tags is that they're just able to convey information about the image. As far as I know there's no such thing as an object that serves specifically to mark any X,Y point. Using the ID field of an object to convey information that's parsed by the program works, but it seems slightly wrong and abusive of what the ID attribute is there for.

Any other approaches I should consider?

Thanks,

Trev


There's no element to mark a specific point of interest in svg at the moment. However, adding a point element has been discussed in the SVG Working Group in context of wanting to e.g connect elements representing nodes in a graph.

You'll be fine using either of these approaches:

  • custom namespaced elements and/or attributes for your data
  • the 'role' attribute and its related attributes, see here
  • the value inside 'id' as you've already done, noting that not all characters can be used inside an 'id' attribute
  • data-* attributes (presumably these will become more common since that's allowed in HTML5, even if it's not yet valid according to SVG spec)

In any case, the thing to be careful with is using custom non-namespaced attributes and elements since that may conflict with future additions to the SVG spec.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜