Leaflet/examples/custom-icons-example.html

50 lines
1.7 KiB
HTML
Raw Normal View History

2011-05-18 19:54:58 +08:00
<!DOCTYPE html>
<html>
<head>
<title>Leaflet Quick Start Guide Example</title>
<meta charset="utf-8" />
2012-02-14 23:02:29 +08:00
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2011-05-18 19:54:58 +08:00
<link rel="stylesheet" href="../dist/leaflet.css" />
<!--[if lte IE 8]><link rel="stylesheet" href="../dist/leaflet.ie.css" /><![endif]-->
</head>
<body>
<div id="map" style="width: 600px; height: 400px"></div>
<script src="../dist/leaflet.js"></script>
<script>
var map = new L.Map('map');
2012-02-14 23:02:29 +08:00
2011-05-18 19:54:58 +08:00
var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/22677/256/{z}/{x}/{y}.png',
cloudmadeAttribution = 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2011 CloudMade',
cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 18, attribution: cloudmadeAttribution});
2012-02-14 23:02:29 +08:00
2011-05-18 19:54:58 +08:00
map.setView(new L.LatLng(51.5, -0.09), 13).addLayer(cloudmade);
2012-02-14 23:02:29 +08:00
2011-05-18 19:54:58 +08:00
var LeafIcon = L.Icon.extend({
iconUrl: '../docs/images/leaf-green.png',
shadowUrl: '../docs/images/leaf-shadow.png',
iconSize: new L.Point(38, 95),
shadowSize: new L.Point(68, 95),
iconAnchor: new L.Point(22, 94),
popupAnchor: new L.Point(-3, -76)
});
2012-02-14 23:02:29 +08:00
2011-05-18 19:54:58 +08:00
var greenIcon = new LeafIcon(),
redIcon = new LeafIcon('../docs/images/leaf-red.png'),
orangeIcon = new LeafIcon('../docs/images/leaf-orange.png');
2012-02-14 23:02:29 +08:00
2011-05-18 19:54:58 +08:00
var marker1 = new L.Marker(new L.LatLng(51.5, -0.09), {icon: greenIcon}),
marker2 = new L.Marker(new L.LatLng(51.495, -0.083), {icon: redIcon}),
marker3 = new L.Marker(new L.LatLng(51.49, -0.1), {icon: orangeIcon});
2012-02-14 23:02:29 +08:00
2011-05-18 19:54:58 +08:00
marker1.bindPopup("I am a green leaf.");
marker2.bindPopup("I am a red leaf.");
marker3.bindPopup("I am an orange leaf.");
2012-02-14 23:02:29 +08:00
2011-05-18 19:54:58 +08:00
map.addLayer(marker1).addLayer(marker2).addLayer(marker3);
</script>
</body>
2012-02-14 23:02:29 +08:00
</html>