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

TextPath and GeoJson layer #24

Closed
AlfaQuarto opened this issue Mar 2, 2015 · 7 comments
Closed

TextPath and GeoJson layer #24

AlfaQuarto opened this issue Mar 2, 2015 · 7 comments

Comments

@AlfaQuarto
Copy link

Hi,

I need to add to my geojson layer text/label for each feature.

Is it possible to do this with Leaflet.TextPath? If not, can it be added to this plugin?

:)

@fredericbonifas
Copy link
Collaborator

Hi,

Yes absolutely, simply do:

var myGeojsonLayer = L.geoJson(...);
myGeojsonLayer.setText(...)

@AlfaQuarto
Copy link
Author

Works great 👍 Thanks for fast response! :)

@Sc00t
Copy link

Sc00t commented Apr 7, 2015

Hi,

I've been trying to get this to work but dont seem to be making any head way.

I'm trying to use this method to simulate road names but just cant get it to work. I'm loading my geoJSON data but cant seem to get my text to display.

I don't suppose you could show an example of how this works with geoJSON feature data?

Thanks.

@leplatrem
Copy link
Collaborator

Something like that should do it (untested):

L.geoJson(data, {
    onEachFeature: function (feature, layer) {
        layer.setText(feature.properties.streetname);
    }
}).addTo(map);

Please reproduce a small test case in jsfiddle or similar to make assistance easier...

@fredericbonifas
Copy link
Collaborator

@Sc00t You can check the demo which now has an example similar to your case: http://makinacorpus.github.io/Leaflet.TextPath/

@Sc00t
Copy link

Sc00t commented Apr 7, 2015

Thank you both, much appreciated. The demo shows exactly what I was
wanting to see.

I do have a further question if I may, I'm using a custom map and plan
to use this method to draw many lines with text on. I am debating the
performance of the solution now, orginally my geoJSON layer was rendered
in a canvas but I see this solution requires I use SVG which unless I'm
mistaken still keeps the object in the DOM? I wonder if I load in
hundreds / thousands of this type of line/text, would the performance of
the map become unuseable.

Thanks.

On 2015-04-07 20:42, Frederic Bonifas wrote:

@Sc00t [1] You can check the demo which now has an example similar to
your case: http://makinacorpus.github.io/Leaflet.TextPath/ [2]

Reply to this email directly or view it on GitHub [3].

Links:

[1] https://github.com/Sc00t
[2] http://makinacorpus.github.io/Leaflet.TextPath/
[3]
#24 (comment)

@leplatrem
Copy link
Collaborator

Closing since it seems resolved.

For your performance question, indeed SVG is mandatory and will not be as performant as canvas (see #37 and #40)

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

No branches or pull requests

4 participants