-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathosmLeaflet.jquery.js
57 lines (51 loc) · 1.6 KB
/
osmLeaflet.jquery.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
(function ($) {
var defaults = {
zoom : 10,
maxZoom : 18,
latitude : 0,
longitude : 0,
cloudmadeAttribution : 'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 CloudMade, osmLeaflet.jQuery by Mathieu ROBIN'
},
settings,
map,
methods = {
init : function (options) {
return this.each(function () {
if(options) {
settings = $.extend(defaults, options);
}
map = new L.Map(this.id);
var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png',
cloudmade = new L.TileLayer(cloudmadeUrl, {
maxZoom: settings.maxZoom,
attribution: settings.cloudmadeAttribution
});
map.setView(new L.LatLng(settings.latitude, settings.longitude), settings.zoom).addLayer(cloudmade);
});
},
addMarker : function (options) {
return this.each(function () {
var markerLocation = new L.LatLng(options.latitude, options.longitude);
var marker = new L.Marker(markerLocation);
map.addLayer(marker);
});
},
addPopup : function (options) {
return this.each(function () {
var popup = new L.Popup();
popup.setLatLng(new L.LatLng(options.latitude, options.longitude));
popup.setContent(options.content);
map.openPopup(popup);
});
}
};
$.fn.osmLeaflet = function (method) {
if(methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if(( typeof method === 'object') || (!method)) {
return methods.init.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist on jQuery.osmLeaflet');
}
};
})(jQuery);