var objectLoader; function getUserIcon(url) { return L.icon({ iconUrl: url || <%= asset_path('marker-red.png').to_json %>, iconSize: [25, 41], iconAnchor: [12, 41], popupAnchor: [1, -34], shadowUrl: <%= asset_path('images/marker-shadow.png').to_json %>, shadowSize: [41, 41] }); } function addObjectToMap(object, map, options) { if (objectLoader) objectLoader.abort(); if (map.objectLayer) map.removeLayer(map.objectLayer); objectLoader = $.ajax({ url: OSM.apiUrl(object), dataType: "xml", success: function (xml) { map.objectLayer = new L.OSM.DataLayer(null, { styles: { node: options.style, way: options.style, area: options.style } }); map.objectLayer.interestingNode = function (node, ways, relations) { if (object.type === "node") { return true; } else if (object.type === "relation") { for (var i = 0; i < relations.length; i++) if (relations[i].members.indexOf(node) != -1) return true; } else { return false; } }; map.objectLayer.addData(xml); if (options.zoom) map.fitBounds(map.objectLayer.getBounds()); if (options.callback) options.callback(map.objectLayer.getBounds()); map.objectLayer.addTo(map); } }); }