Skip to Main Content
Leaflet.js Essentials
book

Leaflet.js Essentials

by Paul Crickard III
August 2014
Intermediate to advanced content levelIntermediate to advanced
180 pages
3h 41m
English
Packt Publishing
Content preview from Leaflet.js Essentials

Using a custom marker in Leaflet

To create a marker icon in Leaflet, you need to create an instance of the L.icon class. The L.icon class takes 10 options, as follows:

  • iconUrl
  • iconRetinaUrl
  • iconSize
  • iconAnchor
  • shadowUrl
  • shadowRetinaUrl
  • shadowSize
  • shadowAnchor
  • popupAnchor
  • className

The only required option is iconUrl. In this example, you will ignore the retina images and the class name. Open LeafletEssentials.html and add the following code:

var myIcon = L.icon({
    iconUrl: 'mymarker.png',
    shadowUrl: 'shadow.png',
    iconSize:     [40, 60], 
    shadowSize:   [60, 40], 
    iconAnchor:   [20, 60], 
    shadowAnchor: [20, 40],  
    popupAnchor:  [0, -53] 
});

The preceding code sets the options. The iconUrl option directs the URL to the icon image and the shadowUrl option directs the URL to ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

GeoServer Beginner's Guide - Second Edition

GeoServer Beginner's Guide - Second Edition

Stefano Iacovella
React Cookbook

React Cookbook

David Griffiths, Dawn Griffiths
Stop Guessing

Stop Guessing

Nat Greene

Publisher Resources

ISBN: 9781783554812Supplemental Content