Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in SVG export, give top layer g element id="<filename>-<layername>" #246

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

cedricsam
Copy link
Contributor

  • To facilitate CSS/JS-targeting using ID when layers order and complement change frequently
  • Also easier to keep track of layers in Illustrator

* To facilitate targetting with ID when layers order changes frequently
@mbloch
Copy link
Owner

mbloch commented Nov 30, 2017

What about just using the original layer names as ids in SVG output, rather than concatenating the file name with the layer name? (I think that's what I originally intended to do.)

@cedricsam
Copy link
Contributor Author

The reason why I'd prefer also having the file name in there was to get an id attribute that's as unique as possible, in the scenario where multiple SVGs made from mapshaper, with the same layer names, were to be embedded on a webpage. But then again, id attributes of features already often share the same values in a general multi-layer (let alone multi-SVG) scenario.

Do you prefer just having the layer name because it'd be shorter and perhaps easier to see in a layer list on Illustrator? I don't feel strongly about the file name, but a layer name as the g's id would be a nice improvement. :)

@mbloch
Copy link
Owner

mbloch commented Nov 30, 2017

As you point out, even if you create unique layer ids, collisions could still occur between the ids of map features and other elements in a document. (This is when you're including an SVG map "inline" on a web page, as opposed to embedding as an <object> or <img>, right?)

One simple solution would be to add an option to the -o command to apply a prefix to all the ids in an SVG document, including both layer and feature ids. Sort of a crude namespace. It could be called something like svg-namespace= or id-prefix=. I would prefer this to generating complex layer ids. What do you think?

@cedricsam
Copy link
Contributor Author

Yes, collisions will still occur. There’s also the case of when several features use the same id-field (which is more a matter of how you pick your id-field), but I see how it could be disruptive to Illustrator scripts that depend on the ID just being a single-value attribute, without anything else.

That said, I like the idea of a svg-namespace= or id-prefix, and to provide control over the naming, rather than reuse the filename. Do you want to discard this PR and start over your way, or wouldn’t mind if I looked into this? (And what do you think of the point-symbol=square improvements? #241 #243)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants