From 648f23259680f55d233656413679c58eec98c985 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 8 Nov 2012 13:26:29 -0800 Subject: [PATCH] Inline map.js marker functions --- app/assets/javascripts/diary_entry.js | 8 +++++--- app/assets/javascripts/index.js | 6 +++--- app/assets/javascripts/map.js.erb | 14 -------------- app/assets/javascripts/user.js | 9 +++++---- 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/app/assets/javascripts/diary_entry.js b/app/assets/javascripts/diary_entry.js index 30038a0af..a001d7482 100644 --- a/app/assets/javascripts/diary_entry.js +++ b/app/assets/javascripts/diary_entry.js @@ -6,10 +6,11 @@ $(document).ready(function () { $("#longitude").val(e.latlng.lng); if (marker) { - removeMarkerFromMap(marker); + map.removeLayer(marker); } - marker = addMarkerToMap(e.latlng, null, I18n.t('diary_entry.edit.marker_text')); + marker = L.marker(e.latlng).addTo(map) + .bindPopup(I18n.t('diary_entry.edit.marker_text')); } $("#usemap").click(function (e) { @@ -25,7 +26,8 @@ $(document).ready(function () { map.setView(centre, params.zoom); if ($("#latitude").val() && $("#longitude").val()) { - marker = addMarkerToMap(centre, null, I18n.t('diary_entry.edit.marker_text')); + marker = L.marker(centre).addTo(map) + .bindPopup(I18n.t('diary_entry.edit.marker_text')); } map.on("click", setLocation); diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index 4f0dfb148..28659a931 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -34,7 +34,7 @@ $(document).ready(function () { } if (params.marker) { - marker = addMarkerToMap([params.mlat, params.mlon]); + marker = L.marker([params.mlat, params.mlon]).addTo(map); } if (params.object) { @@ -57,10 +57,10 @@ $(document).ready(function () { } if (marker) { - removeMarkerFromMap(marker); + map.removeLayer(marker); } - marker = addMarkerToMap(centre, getArrowIcon()); + marker = L.marker(centre, {icon: getArrowIcon()}).addTo(map); }); function updateLocation() { diff --git a/app/assets/javascripts/map.js.erb b/app/assets/javascripts/map.js.erb index 520e9296e..ce75c1700 100644 --- a/app/assets/javascripts/map.js.erb +++ b/app/assets/javascripts/map.js.erb @@ -120,20 +120,6 @@ function getArrowIcon() { }); } -function addMarkerToMap(position, icon, description) { - var marker = L.marker(position, icon ? {icon: icon} : null).addTo(map); - - if (description) { - marker.bindPopup(description); - } - - return marker; -} - -function removeMarkerFromMap(marker) { - map.removeLayer(marker); -} - function addObjectToMap(object, zoom, callback) { $.ajax({ url: OSM.apiUrl(object), diff --git a/app/assets/javascripts/user.js b/app/assets/javascripts/user.js index e5620b0a3..674204d7b 100644 --- a/app/assets/javascripts/user.js +++ b/app/assets/javascripts/user.js @@ -14,7 +14,7 @@ $(document).ready(function () { var marker; if (OSM.home) { - marker = addMarkerToMap([OSM.home.lat, OSM.home.lon]); + marker = L.marker([OSM.home.lat, OSM.home.lon]).addTo(map); } map.on("click", function (e) { @@ -24,17 +24,18 @@ $(document).ready(function () { $('#home_lon').val(e.latlng.lng); if (marker) { - removeMarkerFromMap(marker); + map.removeLayer(marker); } - marker = addMarkerToMap(e.latlng); + marker = L.marker(e.latlng).addTo(map); } }); } else { $("[data-user]").each(function () { var user = $(this).data('user'); if (user.lon && user.lat) { - addMarkerToMap([user.lat, user.lon], L.icon({iconUrl: user.icon}), user.description); + L.marker([user.lat, user.lon], {icon: L.icon({iconUrl: user.icon})}).addTo(map) + .bindPopup(user.description); } }); } -- 2.39.5