Leaf Markers

I am new to flyers and I am trying to display markers. The tutorials don't seem to work for me. The map displays well, however I just cannot display the marker. below is my sample code:

wax.tilejson('http://localhost:8888/v2/DigitalHumanities.json', function(tilejson) { var map = new L.Map('map-div') .addLayer(new wax.leaf.connector(tilejson)) .setView(new L.LatLng(-17.1828,137.4609), 4); var markers = new L.marker(-17.1828,137.4609); map.addLayer(markers); var markerx = new L.marker(137.4609,-17.1828); map.addLayer(markerx); }); 

Ive tried samples in tutorials, namely: .addTo(map); , map.addLayer(markers); etc.

+7
source share
5 answers

The L.marker constructor should be used as:

 var markers = L.marker([-17.1828,137.4609]); map.addLayer(markers); 

You can check the API link here

+14
source

The actual syntax for creating a flyer marker is <

 L.marker(<LatLng> latlng, <Marker options> options? ); 

You can check the API link here
Below is your code

correct code

 wax.tilejson('http://localhost:8888/v2/DigitalHumanities.json', function(tilejson) { var map = new L.Map('map-div') .addLayer(new wax.leaf.connector(tilejson)) .setView(new L.LatLng(-17.1828,137.4609), 4); var markers = new L.marker([-17.1828,137.4609],{clickable:true}); map.addLayer(markers); var markerx = new L.marker([137.4609,-17.1828]); map.addLayer(markerx); }); 
0
source
 let markers = L.marker([-17.1828,137.4609]); 

or

 let markers = L.marker({lat: -17.1828,lng: 137.4609});` 

then

 map.addLayer(markers); 
0
source

You can do this using either factory or the 'new' keyword in the class (which, it seems to me, is what factory does. The difference is what is used.

I believe that they should work the same way:

 var markerx = new L.Marker(L.latLng(137.4609,-17.1828)); map.addLayer(markerx); 

.

 var markerx = L.marker(L.latLng(137.4609,-17.1828)); map.addLayer(markerx); 

But you cannot combine them.

0
source

Here you can find a working example < https://jsfiddle.net/viswanathamsantosh/x63kzb31/ >. The bottom line will add a marker and a pop-up to the map when you click on the marker.

 new L.Marker([46.947, 7.4448]).addTo(map).bindPopup('hello world!!!'); 
0
source

All Articles