This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Practical SVG: Google map icons  RSS feed

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66200
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been using SVG icons on google maps via the Marker mechanism. This expects the path along with other properties as shown below:


Any ideas on a better way to handle this than lifting the path string out of an SVG file and hard-coding it into the code?
 
Chris Coyier
Author
Greenhorn
Posts: 7
5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any ideas on a better way to handle this than lifting the path string out of an SVG file and hard-coding it into the code?


Not really! If the SVG existed somewhere else on the page, you could snag the path out of it like `path.getAttribute("d");`

Also, all those line breaks and tabs shoudn't be necessary. My guess is Illustrator exported it that way and you were trying to remain faithful to it's output by replicating the whitespace. Honestly I have no idea why it does whitespace that way sometimes. Although, it should _only_ do that when you're doing something like "Save As..." an SVG, which, IMO, is a bad idea. Like we talked about in this thread, Illustrator can export in a pretty nice way (that won't have any weird whitespace). Then just save your original as an `.ai` file, since you might as well save with all of Illustrator's native conveniences.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66200
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris Coyier wrote:Also, all those line breaks and tabs shoudn't be necessary.

Yeah, that was a result of cutting and pasting the block and my IDE "helpfully" interpreting the whitespace for me. I should stop being lazy and remove them.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66200
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris Coyier wrote:Not really!

That's kinda what I figured.

If the SVG existed somewhere else on the page, you could snag the path out of it like `path.getAttribute("d");`

Hmm, I know somewhere else in my code where this would be useful. Thanks!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!