X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/73bbee5df9f01eb927ff6d830f8e74802d0318c8..b9a19ab23a8dc63bc7c7f867e2ece6924319f0f2:/app/assets/javascripts/map.js.erb?ds=sidebyside
diff --git a/app/assets/javascripts/map.js.erb b/app/assets/javascripts/map.js.erb
index 80e77f26c..a7e9f6f50 100644
--- a/app/assets/javascripts/map.js.erb
+++ b/app/assets/javascripts/map.js.erb
@@ -12,82 +12,39 @@ L.extend(L.LatLngBounds.prototype, {
L.Icon.Default.imagePath = <%= "#{asset_prefix}/images".to_json %>;
-var map;
-var layers;
var objectLayer;
var objectLoader;
-function createMap(divName, options, moreOptions) {
- if (!layers) {
- layers = [
- {
- klass: L.OSM.Mapnik,
- attribution: "",
- keyid: "mapnik",
- layerCode: "M",
- name: I18n.t("javascripts.map.base.standard")
- },
- {
- klass: L.OSM.CycleMap,
- attribution: "Tiles courtesy of Andy Allan",
- keyid: "cyclemap",
- layerCode: "C",
- name: I18n.t("javascripts.map.base.cycle_map")
- },
- {
- klass: L.OSM.TransportMap,
- attribution: "Tiles courtesy of Andy Allan",
- keyid: "transportmap",
- layerCode: "T",
- name: I18n.t("javascripts.map.base.transport_map")
- },
- {
- klass: L.OSM.MapQuestOpen,
- attribution: "Tiles courtesy of MapQuest ",
- keyid: "mapquest",
- layerCode: "Q",
- name: I18n.t("javascripts.map.base.mapquest")
- }
- ];
- }
-
- moreOptions = moreOptions || {};
-
- options = $.extend({zoomControl: true, panZoomControl: true, layerControl: true}, options);
-
- map = L.map(divName, $.extend({}, options, {panControl: false, zoomsliderControl: false, maxZoom: 18}));
-
- if (map.attributionControl) {
- map.attributionControl.setPrefix('');
- }
-
-
- var layersControl = L.control.layers();
-
- if (options.layerControl) {
- layersControl.addTo(map);
- map.layersControl = layersControl;
- }
-
- if (moreOptions.locateControl) {
- var loc = L.control.locate({
- position: 'topright'
- });
- loc.addTo(map);
- }
-
- for (var i = 0; i < layers.length; i++) {
- layers[i].layer = new (layers[i].klass)(layers[i]);
- layersControl.addBaseLayer(layers[i].layer, layers[i].name);
- }
-
- layers[0].layer.addTo(map);
-
- $("#" + divName).on("resized", function () {
- map.invalidateSize();
- });
-
- return map;
+function mapLayers() {
+ return [{
+ layer: new L.OSM.Mapnik({
+ attribution: ''
+ }),
+ keyid: "mapnik",
+ layerCode: "M",
+ name: I18n.t("javascripts.map.base.standard")
+ }, {
+ layer: new L.OSM.CycleMap( {
+ attribution: "Tiles courtesy of Andy Allan",
+ }),
+ keyid: "cyclemap",
+ layerCode: "C",
+ name: I18n.t("javascripts.map.base.cycle_map")
+ }, {
+ layer: new L.OSM.TransportMap({
+ attribution: "Tiles courtesy of Andy Allan",
+ }),
+ keyid: "transportmap",
+ layerCode: "T",
+ name: I18n.t("javascripts.map.base.transport_map")
+ }, {
+ layer: new L.OSM.MapQuestOpen({
+ attribution: "Tiles courtesy of MapQuest ",
+ }),
+ keyid: "mapquest",
+ layerCode: "Q",
+ name: I18n.t("javascripts.map.base.mapquest")
+ }]
}
function getUserIcon(url) {
@@ -101,7 +58,7 @@ function getUserIcon(url) {
});
}
-function addObjectToMap(object, options) {
+function addObjectToMap(object, map, options) {
if (objectLoader) {
objectLoader.abort();
}
@@ -150,48 +107,3 @@ function addObjectToMap(object, options) {
}
});
}
-
-function addBoxToMap(bounds) {
- var box = L.rectangle(bounds, {
- weight: 2,
- color: '#e90',
- fillOpacity: 0
- });
-
- box.addTo(map);
-
- return box;
-}
-
-function getMapBaseLayer() {
- for (var i = 0; i < layers.length; i++) {
- if (map.hasLayer(layers[i].layer)) {
- return layers[i];
- }
- }
-}
-
-function getMapLayers() {
- var layerConfig = "";
- for (var i = 0; i < layers.length; i++) {
- if (map.hasLayer(layers[i].layer)) {
- layerConfig += layers[i].layerCode;
- }
- }
- return layerConfig;
-}
-
-function setMapLayers(layerConfig) {
- var foundLayer = false;
- for (var i = 0; i < layers.length; i++) {
- if (layerConfig.indexOf(layers[i].layerCode) >= 0) {
- map.addLayer(layers[i].layer);
- foundLayer = true;
- } else {
- map.removeLayer(layers[i].layer);
- }
- }
- if (!foundLayer) {
- map.addLayer(layers[0].layer);
- }
-}