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, moreOptions) {
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 moreOptions = moreOptions || {};
56 options = $.extend({zoomControl: true, panZoomControl: true, layerControl: true}, options);
58 map = L.map(divName, $.extend({}, options, {panControl: false, zoomsliderControl: false, maxZoom: 18}));
60 if (map.attributionControl) {
61 map.attributionControl.setPrefix('');
65 var layersControl = L.control.layers();
67 if (options.layerControl) {
68 layersControl.addTo(map);
69 map.layersControl = layersControl;
72 if (moreOptions.locateControl) {
73 var loc = L.control.locate({
79 for (var i = 0; i < layers.length; i++) {
80 layers[i].layer = new (layers[i].klass)(layers[i]);
81 layersControl.addBaseLayer(layers[i].layer, layers[i].name);
84 layers[0].layer.addTo(map);
86 $("#" + divName).on("resized", function () {
93 function getUserIcon(url) {
95 iconUrl: url || <%= asset_path('marker-red.png').to_json %>,
98 popupAnchor: [1, -34],
99 shadowUrl: <%= asset_path('images/marker-shadow.png').to_json %>,
104 function addObjectToMap(object, options) {
106 objectLoader.abort();
110 map.removeLayer(objectLayer);
113 objectLoader = $.ajax({
114 url: OSM.apiUrl(object),
116 success: function (xml) {
117 objectLayer = new L.OSM.DataLayer(null, {
125 objectLayer.interestingNode = function (node, ways, relations) {
126 if (object.type === "node") {
128 } else if (object.type === "relation") {
129 for (var i = 0; i < relations.length; i++)
130 if (relations[i].members.indexOf(node) != -1)
137 objectLayer.addData(xml);
139 var bounds = objectLayer.getBounds();
142 map.fitBounds(bounds);
145 if (options.callback) {
146 options.callback(bounds);
149 objectLayer.addTo(map);
154 function getMapBaseLayer() {
155 for (var i = 0; i < layers.length; i++) {
156 if (map.hasLayer(layers[i].layer)) {
162 function getMapLayers() {
163 var layerConfig = "";
164 for (var i = 0; i < layers.length; i++) {
165 if (map.hasLayer(layers[i].layer)) {
166 layerConfig += layers[i].layerCode;
172 function setMapLayers(layerConfig) {
173 var foundLayer = false;
174 for (var i = 0; i < layers.length; i++) {
175 if (layerConfig.indexOf(layers[i].layerCode) >= 0) {
176 map.addLayer(layers[i].layer);
179 map.removeLayer(layers[i].layer);
183 map.addLayer(layers[0].layer);