2 L.extend(L.LatLngBounds.prototype, {
4 return (this._northEast.lat - this._southWest.lat) *
5 (this._northEast.lng - this._southWest.lng);
9 return new L.LatLngBounds(this._southWest.wrap(), this._northEast.wrap());
13 L.Icon.Default.imagePath = <%= "#{asset_prefix}/images".to_json %>;
20 function createMap(divName, options) {
28 name: I18n.t("javascripts.map.base.standard")
31 klass: L.OSM.CycleMap,
32 attribution: "Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
35 name: I18n.t("javascripts.map.base.cycle_map")
38 klass: L.OSM.TransportMap,
39 attribution: "Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
40 keyid: "transportmap",
42 name: I18n.t("javascripts.map.base.transport_map")
45 klass: L.OSM.MapQuestOpen,
46 attribution: "Tiles courtesy of <a href='http://www.mapquest.com/' target='_blank'>MapQuest</a> <img src='http://developer.mapquest.com/content/osm/mq_logo.png'>",
49 name: I18n.t("javascripts.map.base.mapquest")
54 options = $.extend({zoomControl: true, panZoomControl: true, layerControl: true}, options);
56 map = L.map(divName, $.extend({}, options, {panControl: false, zoomsliderControl: false, maxZoom: 18}));
58 if (map.attributionControl) {
59 map.attributionControl.setPrefix('');
63 var layersControl = L.control.layers();
65 if (options.layerControl) {
66 layersControl.addTo(map);
67 map.layersControl = layersControl;
70 for (var i = 0; i < layers.length; i++) {
71 layers[i].layer = new (layers[i].klass)(layers[i]);
72 layersControl.addBaseLayer(layers[i].layer, layers[i].name);
75 layers[0].layer.addTo(map);
77 $("#" + divName).on("resized", function () {
84 function getUserIcon(url) {
86 iconUrl: url || <%= asset_path('marker-red.png').to_json %>,
89 popupAnchor: [1, -34],
90 shadowUrl: <%= asset_path('images/marker-shadow.png').to_json %>,
95 function addObjectToMap(object, options) {
101 map.removeLayer(objectLayer);
104 objectLoader = $.ajax({
105 url: OSM.apiUrl(object),
107 success: function (xml) {
108 objectLayer = new L.OSM.DataLayer(null, {
116 objectLayer.interestingNode = function (node, ways, relations) {
117 if (object.type === "node") {
119 } else if (object.type === "relation") {
120 for (var i = 0; i < relations.length; i++)
121 if (relations[i].members.indexOf(node) != -1)
128 objectLayer.addData(xml);
130 var bounds = objectLayer.getBounds();
133 map.fitBounds(bounds);
136 if (options.callback) {
137 options.callback(bounds);
140 objectLayer.addTo(map);
145 function addBoxToMap(bounds) {
146 var box = L.rectangle(bounds, {
157 function getMapBaseLayer() {
158 for (var i = 0; i < layers.length; i++) {
159 if (map.hasLayer(layers[i].layer)) {
165 function getMapLayers() {
166 var layerConfig = "";
167 for (var i = 0; i < layers.length; i++) {
168 if (map.hasLayer(layers[i].layer)) {
169 layerConfig += layers[i].layerCode;
175 function setMapLayers(layerConfig) {
176 var foundLayer = false;
177 for (var i = 0; i < layers.length; i++) {
178 if (layerConfig.indexOf(layers[i].layerCode) >= 0) {
179 map.addLayer(layers[i].layer);
182 map.removeLayer(layers[i].layer);
186 map.addLayer(layers[0].layer);