Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can I have fixed text in leaflet?

I want to add a text to the map that not scaled when zoom change and remain with it's original sizes.

I use this code (javascript):

var text = new L.marker(rect.getBounds().getSouthWest(), {opacity: 0.0001});
text.bindLabel("TEXT", styleProperties);
text.addTo(myLayer);

and obtain this unwanted result: enter image description here

I want that the text remain with the sizes of the first image at left when zoom are applied. Is it possible?

edit: the text must be like a name of the city, that moves with map but not change it's size when zoom (yes, I know that name of cities are images, for that not is easy solve my problem). Thanks however for answers, for now I maintain the labes, not is an elegant solution but works.

like image 973
newUser.java Avatar asked Sep 07 '16 10:09

newUser.java


People also ask

How do you add a marker in leaflet?

Adding a Simple MarkerStep 1 − Create a Map object by passing a <div> element (String or object) and map options (optional). Step 2 − Create a Layer object by passing the URL of the desired tile. Step 3 − Add the layer object to the map using the addLayer() method of the Map class.

Is leaflet API free?

Is there a fee for using it? Leaflet, unlike Google Maps and other all-in-one solutions, is just a JavaScript library. It's free to use, but doesn't provide map imagery on its own — you have to choose a tile service to combine with it.

Is leaflet an API?

Leaflet is designed with simplicity, performance and usability in mind. It works efficiently across all major desktop and mobile platforms, can be extended with lots of plugins, has a beautiful, easy to use and well-documented API and a simple, readable source code that is a joy to contribute to.


2 Answers

You could use Leaflet.label plugin (starting with Leaflet 1.0, L.Label is added to Leaflet core as L.Tooltip). You can style it with your own css. See the example.

like image 104
Marko Letic Avatar answered Oct 15 '22 10:10

Marko Letic


It looks to me your text is not really related to your map. What about adding the text in another div over the container of the map ?

  <div>
    <div id="map" style="width: 600px; height: 400px"></div>
    <div style="pointer-events: none; position: absolute; top: 100px; left: 100px">foo bar</div>
  </div>

See full example here

like image 30
YaFred Avatar answered Oct 15 '22 10:10

YaFred