blob: 910bb310e725675b53f5b9618b5ce8f6d3041f1f [file] [log] [blame]
Siobhan Tullye18b3442014-02-23 14:23:34 -05001/*
2 * Leaflet plugin to create map icons using Maki Icons from MapBox.
3 *
4 * References:
5 * Maki Icons: https://www.mapbox.com/maki/
6 * MapBox Marker API: https://www.mapbox.com/developers/api/#Stand-alone.markers
7 *
8 * Usage:
9 * var icon = L.MakiMarkers.icon({icon: "rocket", color: "#b0b", size: "m"});
10 *
11 * License:
12 * MIT: http://jseppi.mit-license.org/
13 */
14(function () {
15 "use strict";
16 L.MakiMarkers = {
17 // Available Maki Icons
18 icons: ["circle-stroked", "circle", "square-stroked", "square",
19 "triangle-stroked", "triangle", "star-stroked", "star", "cross",
20 "marker-stroked", "marker", "religious-jewish", "religious-christian",
21 "religious-muslim", "cemetery", "rocket", "airport", "heliport", "rail",
22 "rail-metro", "rail-light", "bus", "fuel", "parking", "parking-garage",
23 "airfield", "roadblock", "ferry", "harbor", "bicycle", "park", "park2",
24 "museum", "lodging", "monument", "zoo", "garden", "campsite", "theatre",
25 "art-gallery", "pitch", "soccer", "america-football", "tennis", "basketball",
26 "baseball", "golf", "swimming", "cricket", "skiing", "school", "college",
27 "library", "post", "fire-station", "town-hall", "police", "prison",
28 "embassy", "beer", "restaurant", "cafe", "shop", "fast-food", "bar", "bank",
29 "grocery", "cinema", "pharmacy", "hospital", "danger", "industrial",
30 "warehouse", "commercial", "building", "place-of-worship", "alcohol-shop",
31 "logging", "oil-well", "slaughterhouse", "dam", "water", "wetland",
32 "disability", "telephone", "emergency-telephone", "toilets", "waste-basket",
33 "music", "land-use", "city", "town", "village", "farm", "bakery", "dog-park",
34 "lighthouse", "clothing-store", "polling-place", "playground", "entrance",
35 "heart", "london-underground", "minefield", "rail-underground", "rail-above",
36 "camera", "laundry", "car", "suitcase", "hairdresser", "chemist"],
37 defaultColor: "#0a0",
38 defaultIcon: "circle-stroked",
39 defaultSize: "m",
40 apiUrl: "https://api.tiles.mapbox.com/v3/marker/",
41 smallOptions: {
42 iconSize: [20, 50],
43 popupAnchor: [0,-20]
44 },
45 mediumOptions: {
46 iconSize: [30,70],
47 popupAnchor: [0,-30]
48 },
49 largeOptions: {
50 iconSize: [36,90],
51 popupAnchor: [0,-40]
52 }
53 };
54
55 L.MakiMarkers.Icon = L.Icon.extend({
56 options: {
57 //Maki icon: any from https://www.mapbox.com/maki/ (ref: L.MakiMarkers.icons)
58 icon: L.MakiMarkers.defaultIcon,
59 //Marker color: short or long form hex color code
60 color: L.MakiMarkers.defaultColor,
61 //Marker size: "s" (small), "m" (medium), or "l" (large)
62 size: L.MakiMarkers.defaultSize,
63 shadowAnchor: null,
64 shadowSize: null,
65 shadowUrl: null,
66 className: 'maki-marker'
67 },
68
69 initialize: function(options) {
70 var pin;
71
72 options = L.setOptions(this, options);
73
74 switch (options.size) {
75 case "s":
76 L.extend(options, L.MakiMarkers.smallOptions);
77 break;
78 case "l":
79 L.extend(options, L.MakiMarkers.largeOptions);
80 break;
81 default:
82 options.size = "m";
83 L.extend(options, L.MakiMarkers.mediumOptions);
84 break;
85 }
86
87 if (options.color.charAt(0) === '#') {
88 options.color = options.color.substr(1);
89 }
90
91 pin = "pin-" + options.size + "-" + options.icon + "+" +
92 options.color + ".png";
93
94 options.iconUrl = "" + L.MakiMarkers.apiUrl + pin;
95 }
96 });
97
98 L.MakiMarkers.icon = function(options) {
99 return new L.MakiMarkers.Icon(options);
100 };
101})();