makinacorpus / Leaflet.TextPath

Show text along Polyline with Leaflet
https://makinacorpus.github.io/Leaflet.TextPath/
MIT License
285 stars 112 forks source link

Features: repeat distance, allowCrop, multi-color labels, orientation 'auto' and 'flip', turnedText, ... #72

Open plepe opened 5 years ago

plepe commented 5 years ago

I have a christmas present for you!

I would have liked to create pull requests for each feature, but they all depend on each other, that's why I created a "features" pull request.

It includes the following features:

Also:

Tell me what you think about it.

rainbow-and-directional-labels

plepe commented 5 years ago

One big problem is browser support for rotated text on textpath.

You can check how your browser behaves (first image) and compare with screenshots of other browser on this test page: https://xover.mud.at/~skunk/svg-rotate-glyph

Please submit screenshots of other browsers!

I guess I should implement a browser detection and mitigate problems (e.g. select a fixed-width font on firefox, disable rotation on IE/Edge).

clementallen commented 5 years ago

Love this! Really hope it can get merged in soon 👍 If it helps, here is screenshot of the above website in Safari 12 on macOS Mojave:

screenshot 2019-01-13 20 49 42
plepe commented 5 years ago

Oh no, Safari does not seem to support textpath at all!

Do you see airplanes, labels and other markers on this webpage? https://makinacorpus.github.io/Leaflet.TextPath/

Apparently there seems to be a bug in Safari: https://stackoverflow.com/questions/50937985/text-within-svg-textpath-not-visible-from-ios-browsers

clementallen commented 5 years ago

I can see the aircraft and other markers fine in safari:

screenshot 2019-01-14 19 18 05
plepe commented 5 years ago

That looks okay. I'll try to get my hands on a Mac soon, so I can test what's wrong with my test page ...

clementallen commented 5 years ago

Just cloned your fork and ran it on Safari. Everything seems to be fine apart from the turnText and orientation. Unfortunately I don't really know anything about SVG elements otherwise I'd try and fix it:

screenshot 2019-01-14 20 07 23 screenshot 2019-01-14 20 07 29
simon1tan commented 5 years ago

~~@plepe Thanks for the new options! I tried orientation:'auto' but getting multiple errors: Error: attribute transform: Expected number, "rotate(auto 0 0)". Error: attribute transform: Expected number, "rotate(auto 489.8046875…"~~

plepe commented 5 years ago

@plepe Thanks for the new options! I tried orientation:'auto' but getting multiple errors: Error: attribute transform: Expected number, "rotate(auto 0 0)". Error: attribute transform: Expected number, "rotate(auto 489.8046875…"

Oh. Hard to tell what is the problem without knowing further details. Could you create a test case?

simon1tan commented 5 years ago

Sorry @plepe. That was my error. Didn't refresh. Please ignore that error.

strixy commented 5 years ago

Good job! Thank you. I ran into one issue with the text not centering as expected, but otherwise super happy e-w text is displaying nicely now. As a fix I can propose the following solution, but I'm new here so I'll leave the final solution up to you.

Change line 109

from if (!options.allowCrop) { to if (!options.allowCrop || options.center) {

plepe commented 5 years ago

Thanks :-) The biggest problem right now is the browser incompatibilities. It will be necessary to implement some kind of switch, which mode to choose:

See: https://xover.mud.at/~skunk/svg-rotate-glyph/ (the relevant line is the "textpath with rotate=180" line)

(Safari also needs the deprecated 'xlink:' prefix when referencing the path)