From dc25c01bcdd0013d2929b957c7c505521c71c047 Mon Sep 17 00:00:00 2001 From: zaziemo Date: Wed, 19 Aug 2015 16:32:17 +0200 Subject: [PATCH] add a different map representation to the SPV so a small map is rendered in the SPV and a location is provided via toggling the map gets bigger (#5813) --- .../single_post_content_view.js | 54 +++++++++++++++++-- app/assets/stylesheets/map.scss | 6 ++- app/assets/stylesheets/single-post-view.scss | 3 +- .../single-post-content_tpl.jst.hbs | 7 ++- 4 files changed, 63 insertions(+), 7 deletions(-) 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 463986151..bb3a28feb 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 @@ -1,7 +1,11 @@ // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later app.views.SinglePostContent = app.views.Base.extend({ - templateName: "single-post-viewer/single-post-content", + events: { + "click .near-from": "toggleMap" + }, + + templateName: 'single-post-viewer/single-post-content', tooltipSelector: "time, .post_scope", subviews : { @@ -10,7 +14,6 @@ app.views.SinglePostContent = app.views.Base.extend({ "#real-post-content" : "postContentView", ".oembed" : "oEmbedView", ".opengraph" : "openGraphView", - ".status-message-location" : "postLocationStreamView", '.poll': 'pollView', }, @@ -23,8 +26,47 @@ app.views.SinglePostContent = app.views.Base.extend({ this.pollView = new app.views.Poll({ model: this.model }); }, - postLocationStreamView : function(){ - return new app.views.LocationStream({ model : this.model}); + map : function(){ + if (this.$el.find(".mapContainer")){ + + // find and set height of mapContainer to max size of the container + // which is necessary to have all necessary tiles prerendered + var mapContainer = this.$el.find(".mapContainer"); + mapContainer.css("height", "200px"); + + // get location data and render map + var location = this.model.get("location"); + 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], 14); + var attribution = "Map data © OpenStreetMap contributors, " + + "CC-BY-SA, " + + "Imagery © Mapbox"; + + L.tileLayer(tileLayerSource, { + attribution: attribution, + maxZoom: 18, + id: "zaziemo.mpn66kn8", + accessToken: "pk.eyJ1IjoiemF6aWVtbyIsImEiOiI3ODVjMzVjNmM2ZTU3YWM3YTE5YWYwMTRhODljM2M1MSJ9.-nVgyS4PLnV4m9YkvMB5wA" + }).addTo(map); + + // set mapContainer size to a smaller preview size + mapContainer.css("height", "75px"); + map.invalidateSize(); + + // 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"); + } }, presenter : function() { @@ -37,6 +79,10 @@ app.views.SinglePostContent = app.views.Base.extend({ showPost : function() { return (app.currentUser.get("showNsfw")) || !this.model.get("nsfw"); + }, + + postRenderTemplate : function(){ + _.defer(_.bind(this.map, this)); } }); // @license-end diff --git a/app/assets/stylesheets/map.scss b/app/assets/stylesheets/map.scss index 6729448cb..f304d135b 100644 --- a/app/assets/stylesheets/map.scss +++ b/app/assets/stylesheets/map.scss @@ -1,4 +1,4 @@ -.map { +.mapContainer { position: relative; overflow: hidden; } @@ -8,6 +8,10 @@ text-decoration: underline; } +.leaflet-control-zoom { + display: none; +} + .leaflet-bottom .leaflet-control { margin-bottom: 0; } diff --git a/app/assets/stylesheets/single-post-view.scss b/app/assets/stylesheets/single-post-view.scss index 2706c8608..cf2298821 100644 --- a/app/assets/stylesheets/single-post-view.scss +++ b/app/assets/stylesheets/single-post-view.scss @@ -23,11 +23,12 @@ padding-left: 10px; } } - .status-message-location { + .near-from { color: $text-grey; font-size: 12px; margin: 10px 20px 0px 15px; } + .row.reshare { border-top: 1px solid lighten($border-grey,5%); padding-top: 10px; diff --git a/app/assets/templates/single-post-viewer/single-post-content_tpl.jst.hbs b/app/assets/templates/single-post-viewer/single-post-content_tpl.jst.hbs index 3f55e580a..c8dcd63f1 100644 --- a/app/assets/templates/single-post-viewer/single-post-content_tpl.jst.hbs +++ b/app/assets/templates/single-post-viewer/single-post-content_tpl.jst.hbs @@ -67,9 +67,14 @@
{{/unless}}
+ {{#if location.lat}}
-
+
+ {{t "publisher.near_from" location=location.address}} +
+
+ {{/if}} {{#if root}}