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('');
62 if (options.panZoomControl) {
63 new L.Control.Pan().addTo(map);
64 new L.Control.Zoomslider({stepHeight: 7}).addTo(map);
67 var layersControl = L.control.layers();
69 if (options.layerControl) {
70 layersControl.addTo(map);
71 map.layersControl = layersControl;
74 for (var i = 0; i < layers.length; i++) {
75 layers[i].layer = new (layers[i].klass)(layers[i]);
76 layersControl.addBaseLayer(layers[i].layer, layers[i].name);
79 layers[0].layer.addTo(map);
81 $("#" + divName).on("resized", function () {
88 function getUserIcon(url) {
90 iconUrl: url || <%= asset_path('marker-red.png').to_json %>,
93 popupAnchor: [1, -34],
94 shadowUrl: <%= asset_path('images/marker-shadow.png').to_json %>,
99 function addObjectToMap(object, options) {
101 objectLoader.abort();
105 map.removeLayer(objectLayer);
108 objectLoader = $.ajax({
109 url: OSM.apiUrl(object),
111 success: function (xml) {
112 objectLayer = new L.OSM.DataLayer(null, {
120 objectLayer.interestingNode = function (node, ways, relations) {
121 if (object.type === "node") {
123 } else if (object.type === "relation") {
124 for (var i = 0; i < relations.length; i++)
125 if (relations[i].members.indexOf(node) != -1)
132 objectLayer.addData(xml);
134 var bounds = objectLayer.getBounds();
137 map.fitBounds(bounds);
140 if (options.callback) {
141 options.callback(bounds);
144 objectLayer.addTo(map);
149 function addBoxToMap(bounds) {
150 var box = L.rectangle(bounds, {
161 function getMapBaseLayer() {
162 for (var i = 0; i < layers.length; i++) {
163 if (map.hasLayer(layers[i].layer)) {
169 function getMapLayers() {
170 var layerConfig = "";
171 for (var i = 0; i < layers.length; i++) {
172 if (map.hasLayer(layers[i].layer)) {
173 layerConfig += layers[i].layerCode;
179 function setMapLayers(layerConfig) {
180 var foundLayer = false;
181 for (var i = 0; i < layers.length; i++) {
182 if (layerConfig.indexOf(layers[i].layerCode) >= 0) {
183 map.addLayer(layers[i].layer);
186 map.removeLayer(layers[i].layer);
190 map.addLayer(layers[0].layer);