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, zoom, callback) {
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, {
118 fillColor: "lightblue",
123 objectLayer.interestingNode = function (node, ways, relations) {
124 if (object.type === "node") {
126 } else if (object.type === "relation") {
127 for (var i = 0; i < relations.length; i++)
128 if (relations[i].members.indexOf(node) != -1)
135 objectLayer.addData(xml);
137 var bounds = objectLayer.getBounds();
140 map.fitBounds(bounds);
147 objectLayer.addTo(map);
152 function addBoxToMap(bounds) {
153 var box = L.rectangle(bounds, {
164 function getMapBaseLayer() {
165 for (var i = 0; i < layers.length; i++) {
166 if (map.hasLayer(layers[i].layer)) {
172 function getMapLayers() {
173 var layerConfig = "";
174 for (var i = 0; i < layers.length; i++) {
175 if (map.hasLayer(layers[i].layer)) {
176 layerConfig += layers[i].layerCode;
182 function setMapLayers(layerConfig) {
183 var foundLayer = false;
184 for (var i = 0; i < layers.length; i++) {
185 if (layerConfig.indexOf(layers[i].layerCode) >= 0) {
186 map.addLayer(layers[i].layer);
189 map.removeLayer(layers[i].layer);
193 map.addLayer(layers[0].layer);