diff --git a/app/assets/javascripts/app/views/location_stream.js b/app/assets/javascripts/app/views/location_stream.js index 591a88bdb54e5add2d8ce92c9a571f6a8728a234..446a9765f45d33131b88e0e1bbd701ced1d72a48 100644 --- a/app/assets/javascripts/app/views/location_stream.js +++ b/app/assets/javascripts/app/views/location_stream.js @@ -7,35 +7,37 @@ app.views.LocationStream = app.views.Content.extend({ templateName: "status-message-location", toggleMap: function () { - var mapContainer = this.$el.find(".mapContainer"); + if (gon.appConfig.map.enabled){ + var mapContainer = this.$el.find(".mapContainer"); - if (mapContainer.hasClass("empty")) { - var location = this.model.get("location"); - mapContainer.css("height", "150px"); + if (mapContainer.hasClass("empty")) { + var location = this.model.get("location"); + mapContainer.css("height", "150px"); - if (location.lat) { - var tileLayerSource = "https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}"; - var map = L.map(mapContainer[0]).setView([location.lat, location.lng], 16); - var attribution = "Map data © <a href='http://openstreetmap.org'>OpenStreetMap</a> contributors, " + - "<a href='http://creativecommons.org/licenses/by-sa/2.0/''>CC-BY-SA</a>, " + - "Imagery © <a href='http://mapbox.com'>Mapbox</a>"; + if (location.lat) { + var tileLayerSource = "https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}"; + var map = L.map(mapContainer[0]).setView([location.lat, location.lng], 16); + var attribution = "Map data © <a href='http://openstreetmap.org'>OpenStreetMap</a> contributors, " + + "<a href='http://creativecommons.org/licenses/by-sa/2.0/''>CC-BY-SA</a>, " + + "Imagery © <a href='http://mapbox.com'>Mapbox</a>"; - L.tileLayer(tileLayerSource, { - attribution: attribution, - maxZoom: 18, - id: "zaziemo.mpn66kn8", - accessToken: "pk.eyJ1IjoiemF6aWVtbyIsImEiOiI3ODVjMzVjNmM2ZTU3YWM3YTE5YWYwMTRhODljM2M1MSJ9.-nVgyS4PLnV4m9YkvMB5wA" - }).addTo(map); + L.tileLayer(tileLayerSource, { + attribution: attribution, + maxZoom: 18, + id: gon.appConfig.map.mapbox.id, + accessToken: gon.appConfig.map.mapbox.accessToken + }).addTo(map); - var markerOnMap = L.marker(location).addTo(map); - mapContainer.removeClass("empty"); - return map; - } - } else { - if (mapContainer.css("display") === "none") { - mapContainer.css("display", "block"); - } else { - mapContainer.css("display", "none"); + var markerOnMap = L.marker(location).addTo(map); + mapContainer.removeClass("empty"); + return map; + } + } else { + if (mapContainer.css("display") === "none") { + mapContainer.css("display", "block"); + } else { + mapContainer.css("display", "none"); + } } } } diff --git a/app/assets/javascripts/app/views/single-post-viewer/single_post_content_view.js b/app/assets/javascripts/app/views/single-post-viewer/single_post_content_view.js index bb3a28feb5e304ff8cde2d042e91ca1df6131bab..d1f3dcfd609a17b80a96c1576872f880329c50f2 100644 --- a/app/assets/javascripts/app/views/single-post-viewer/single_post_content_view.js +++ b/app/assets/javascripts/app/views/single-post-viewer/single_post_content_view.js @@ -27,7 +27,7 @@ app.views.SinglePostContent = app.views.Base.extend({ }, map : function(){ - if (this.$el.find(".mapContainer")){ + if (this.$el.find(".mapContainer")&&gon.appConfig.map.enabled){ // find and set height of mapContainer to max size of the container // which is necessary to have all necessary tiles prerendered @@ -45,8 +45,8 @@ app.views.SinglePostContent = app.views.Base.extend({ L.tileLayer(tileLayerSource, { attribution: attribution, maxZoom: 18, - id: "zaziemo.mpn66kn8", - accessToken: "pk.eyJ1IjoiemF6aWVtbyIsImEiOiI3ODVjMzVjNmM2ZTU3YWM3YTE5YWYwMTRhODljM2M1MSJ9.-nVgyS4PLnV4m9YkvMB5wA" + id: gon.appConfig.map.mapbox.id, + accessToken: gon.appConfig.map.mapbox.accessToken }).addTo(map); // set mapContainer size to a smaller preview size @@ -56,16 +56,18 @@ app.views.SinglePostContent = app.views.Base.extend({ // put marker on map var markerOnMap = L.marker(location).addTo(map); return map; - }; + }; }, toggleMap: function () { - if (this.$el.find(".mapContainer").css("height") === "75px") { - this.$el.find(".mapContainer").css("height", "200px"); - this.$el.find(".leaflet-control-zoom").css("display", "block"); - } else { - this.$el.find(".mapContainer").css("height", "75px"); - this.$el.find(".leaflet-control-zoom").css("display", "none"); + if (gon.appConfig.map.enabled){ + if (this.$el.find(".mapContainer").css("height") === "75px") { + this.$el.find(".mapContainer").css("height", "200px"); + this.$el.find(".leaflet-control-zoom").css("display", "block"); + } else { + this.$el.find(".mapContainer").css("height", "75px"); + this.$el.find(".leaflet-control-zoom").css("display", "none"); + } } }, diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index eb06e2f9e09fcd6be53ecf7715732c9bc096ed50..e4e0816560ecf4d296cabb9b15de8db139ed5e76 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -145,7 +145,8 @@ class ApplicationController < ActionController::Base def gon_set_appconfig gon.push(appConfig: { chat: {enabled: AppConfig.chat.enabled?}, - settings: {podname: AppConfig.settings.pod_name} + settings: {podname: AppConfig.settings.pod_name}, + map: {enabled: AppConfig.map.enabled?, mapbox: AppConfig.map.mapbox} }) end diff --git a/config/defaults.yml b/config/defaults.yml index 9d4bd0d9c29bab48f51fa7d5b1e71b65d3ccb6e4..6f67eeb13a651290e00f43ec7f68a51a33d65593 100644 --- a/config/defaults.yml +++ b/config/defaults.yml @@ -75,6 +75,11 @@ defaults: log: file: 'log/vines.log' level: 'info' + map: + enabled: true + mapbox: + id: 'zaziemo.mpn66kn8' + accessToken: 'pk.eyJ1IjoiemF6aWVtbyIsImEiOiI3ODVjMzVjNmM2ZTU3YWM3YTE5YWYwMTRhODljM2M1MSJ9.-nVgyS4PLnV4m9YkvMB5wA' privacy: jquery_cdn: false google_analytics_key: diff --git a/config/diaspora.yml.example b/config/diaspora.yml.example index cf2e286cee85b3e4c615d4329cc91612c400da51..0f7d8ec5232974ec3bf9e4e348e38ab3e22fad69 100644 --- a/config/diaspora.yml.example +++ b/config/diaspora.yml.example @@ -324,6 +324,17 @@ configuration: ## Section ## The debug level logs all XML sent and received by the server. #level: 'info' + ## Displaying location of posts in a map. We are using the map tiles of + ## https://www.mapbox.com. There you have to create a account to get and ID + ## and an access token. If you want to use this feature you can write an email + ## to team@diasporafoundation.org and you'll get an unlimited and free account. + map: ##Section + + # enable: true + # mapbox: + # id: 'your.id' + # accessToken: 'youraccesstoken' + ## Settings potentially affecting the privacy of your users. privacy: ## Section