Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overlaying a text box on a leaflet.js map

This might seem a very simple question, but I've searched elsewhere for the answer with no luck!

How do I overlay a simple text box on to a Leaflet map that loads when the map loads (not fixed to any point on a map) - for example, to give a title and more information within the actual map object. Nothing fancy.

like image 293
jmk Avatar asked Nov 17 '15 21:11

jmk


People also ask

How do you add an overlay to a leaflet?

Image OverlayStep 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. Step 4 − Create the image overlay using L.

What is tile layer in leaflet?

Used to load and display tile layers on the map, implements ILayer interface.

Can leaflet use Vector tiles?

Leaflet doesn't support vector tiles by default. For basemaps, it is recommended to use it with traditional raster tiles (Mercator XYZ). Such tiles can be generated on demand for any of the GL styles with the open-source server software called TileServer GL.


1 Answers

I know this is old, but here's some sample code, CSS as necessary:

L.Control.textbox = L.Control.extend({
		onAdd: function(map) {
			
		var text = L.DomUtil.create('div');
		text.id = "info_text";
		text.innerHTML = "<strong>text here</strong>"
		return text;
		},

		onRemove: function(map) {
			// Nothing to do here
		}
	});
	L.control.textbox = function(opts) { return new L.Control.textbox(opts);}
	L.control.textbox({ position: 'bottomleft' }).addTo(map);
like image 94
Kyouma Avatar answered Sep 21 '22 10:09

Kyouma