Created
December 21, 2019 03:47
-
-
Save RikdeBoer/c5c839b0d2aa8457cefcdf24ec033e02 to your computer and use it in GitHub Desktop.
Leaflet emoji marker with indicator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>Leaflet - Emoji marker with inidicator</title> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<link href="https://unpkg.com/[email protected]/dist/leaflet.css" rel="stylesheet" integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" crossorigin=""/> | |
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew==" crossorigin=""></script> | |
<style> | |
.mymarker { | |
font-size: 50px; | |
} | |
.mymarker > .indicator { | |
font-size: 28px; | |
position: relative; | |
left: -26px; | |
bottom: 15px; | |
white-space: nowrap; | |
} | |
.leaflet-popup { | |
margin-bottom: 70px; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="map-placeholder" style="height:400px"></div> | |
<script> | |
const size = 50; // needs to correspond to font-size above | |
const iconOptions = { | |
iconSize : [size, size], | |
iconAnchor: [size/2, size + 9], | |
className : 'mymarker', | |
html: '🏛️<div class="indicator">🍽️ 🍷 🔓</div>' | |
} | |
const markerOptions = { | |
draggable: true, | |
icon: L.divIcon(iconOptions) | |
} | |
const center = [-37.8277, 144.9771] | |
const myMap = L.map('map-placeholder').setView(center, 16) | |
const myMarker = L.marker(center, markerOptions).addTo(myMap) | |
myMarker | |
.bindPopup('I am an emoji marker<br/>with 3 emoji indicators.') | |
.openPopup() | |
myMap.addLayer(L.tileLayer( | |
'https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}@2x.png', | |
{ attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contr.' } | |
)) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment