Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm looking for a way to show text on Leaflet map using markers or anything else without showing any icon. I want to show text only and be able to style and rotate it... Any suggestion?

Thanks a lot

Etienne

share|improve this question

3 Answers 3

up vote 5 down vote accepted

I solved my problem by using the Leaflet L.DivIcon feature that represents a lightweight icon for markers that uses a simple div element instead of an image... These markers have an html and a className options that allow me to create labels with css drived styles...

Etienne

share|improve this answer

You can start here with this Leaflet plugin. Probably create or edit a marker to your liking. Is the text coming from feature attributes?

share|improve this answer

Use the Leaflet Label Plugin (already mentioned by geomajor56).

<script src="scripts/leaflet.label.js"></script>

With the Leaflet Label plugin, labels are directly tied to markers, but you can set the opacity of the marker to almost zero so only the label is visible. (If you set the marker's opacity to 0, the associated label disappears as well.)

var marker = new L.marker([39.5, -77.3], { opacity: 0.01 });
marker.bindLabel("My Label", {noHide: true, className: "my-label", offset: [0, 0] });
marker.addTo(map);

You can then use CSS to style your labels as you see fit:

.my-label {
    position: absolute;
    width:1000px;
    font-size:20px;
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.