Skip to content

Instantly share code, notes, and snippets.

@enjalot
Created June 28, 2016 03:38
Show Gist options
  • Save enjalot/a5d312a7f11a0d69d41ab47f662f513c to your computer and use it in GitHub Desktop.
Save enjalot/a5d312a7f11a0d69d41ab47f662f513c to your computer and use it in GitHub Desktop.
WWSD #1: Leaflet starter
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map = L.map('map').setView([30, 0], 2);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
var CustomIcon = L.Icon.extend({
options: {
iconSize: [40, 40],
shadowSize: [50, 64],
iconAnchor: [22, 94],
shadowAnchor: [4, 62],
popupAnchor: [-3, -76]
}
});
var svgrect = "<svg xmlns='http://www.w3.org/2000/svg'><rect x='0' y='0' width='20' height='10' fill='#5a7cd2'></rect><rect x='0' y='15' width='20' height='10' fill='#5d52cf'></rect></svg>";
var url = "data:image/svg+xml;utf-8," + svgrect
console.log(url)
var greenIcon = new CustomIcon({iconUrl: url})
L.marker([52, -0.09], {icon: greenIcon}).bindPopup("I am a green leaf.").addTo(map);
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment