Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map and gallery template added to tags page #821

Merged
merged 2 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ def show
@tag = Tag.find_by_name params[:id]
@maps = @tag.maps.paginate(page: params[:page], per_page: 24)
@title = "Maps tagged with ' #{@tag.name} '"
render template: 'maps/index'
tag = Tag.where(name: 'featured').first # note that this is not a join table but the .maps method still works
@unpaginated = true
@authors = User.where(login: tag.maps.collect(&:author)) if tag
@authors ||= []
render template: 'tags/index'
end

def destroy
Expand Down
129 changes: 129 additions & 0 deletions app/views/tags/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<%= stylesheet_link_tag "/lib/leaflet/dist/leaflet.css" %>
<%= stylesheet_link_tag "/lib/leaflet-environmental-layers/dist/LeafletEnvironmentalLayers.css" %>
<%= javascript_include_tag('/lib/leaflet-environmental-layers/dist/LeafletEnvironmentalLayers.js') %>
<%= javascript_include_tag('/lib/leaflet-environmental-layers/dist/windRoseLayer.js') %>
<%= javascript_include_tag('/lib/leaflet-fullhash/leaflet-fullHash.js') %>
<%= javascript_include_tag('https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/Leaflet.fullscreen.min.js') %>
<%= stylesheet_link_tag "https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/leaflet.fullscreen.css" %>

<%= javascript_include_tag('/lib/leaflet-spin/example/spin/dist/spin.min.js') %>
<%= javascript_include_tag('/lib/leaflet-spin/example/leaflet.spin.min.js') %>

<div class="container-fluid">
<div id="mapknitter-unique" class="mx-auto" style="height: 450px; width: 100%;">
</div>
<div class="galary-template">
<%= render :template => 'front_ui/gallery' %>
</div>
</div>

<script>
var defaultLoc;
var places = [
{ name: 'Louisiana', zoom: 8, lat: 29.884, lng: -90.172 },
{ name: 'Puerto Rico', zoom: 7, lat: 18.315, lng: -66.797 },
{ name: 'Mexico City', zoom: 6, lat: 20.120, lng: -99.005 },
{ name: 'Lima', zoom: 10, lat: -11.9995, lng: -77.0285 },
{ name: 'Nairobi', zoom: 12, lat: -1.2500, lng: 36.8291 },
{ name: 'Jakarta', zoom: 10, lat: -6.1847, lng: 106.9015 },
{ name: 'Korea', zoom: 6, lat: 36.189, lng: 128.309 },
{ name: 'Bangalore', zoom: 10, lat: 13.0034, lng: 77.5768 },
{ name: 'Milan', zoom: 9, lat: 45.4311, lng: 9.3339 }
];
function randomizeVals() {
defaultLoc = places[parseInt(Math.random() * places.length)];
}
randomizeVals();

/**
* Randomize array element order in-place.
* Using Durstenfeld shuffle algorithm.
*/
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}

defaultLoc.lat = defaultLoc.lat || <%= params[:lat] || 'false' %>;
defaultLoc.lng = defaultLoc.lng || <%= params[:lng] || 'false' %>;
defaultLoc.zoom = defaultLoc.zoom || <%= params[:z] || 'false' %>;

var Mapknitterunique = new L.Map('mapknitter-unique').setView([places[0].lat, places[0].lng], 8);
var hash = new L.Hash(Mapknitterunique);

var MapKnitter = L.layerGroup.mapKnitterLayer().addTo(Mapknitterunique);

function displayFeaturedPlaces() {
shuffleArray(places);
places.forEach(function(place, i) {
// use "mapknitter.org#8/29.884/-90.172/" style easyHash links
var locHash = '#' + place.zoom + '/' + place.lat + '/' + place.lng + '/';
$('.featured-places').append('<a class="place-' + i + '" href="javascript:void(0);">' + place.name + '</a>');
$('.featured-places .place-' + i).click(function click() {
var loc = hash.parseHash(locHash);
Mapknitterunique.flyTo(loc.center, loc.zoom)
});
});
}
displayFeaturedPlaces();

Mapknitterunique.locate({setView: true, minZoom : 2, maxZoom: 12});

Mapknitterunique.on('locationfound', function (locationEvent) {
getCoordinates(locationEvent);
});

Mapknitterunique.on('locationerror', function (locationEvent) {
setDefaultCoordinates(locationEvent);
});

function getCoordinates(location) {
var lat = location.latitude;
var lon = location.longitude;
saveLocation(lat, lon);
}

function setDefaultCoordinates() {
Mapknitterunique.stopLocate();
var bounds = new L.LatLngBounds(
new L.LatLng(defaultLoc.lat-1, defaultLoc.lng-1),
new L.LatLng(defaultLoc.lat+1 , defaultLoc.lng+1)
);
Mapknitterunique.options.maxBounds = bounds;
Mapknitterunique.options.maxBoundsViscosity = 0.75;
Mapknitterunique.setView([defaultLoc.lat,defaultLoc.lng], defaultLoc.zoom);
}

function saveLocation(lat, lon) {
$.post( "/save_location.json", {'lat': lat, 'lon': lon}, function(data) {});
}


var token = "pk.eyJ1Ijoianl3YXJyZW4iLCJhIjoiVzVZcGg3NCJ9.BJ6ArUPuTs1JT9Ssu3K8ig";
var baselayer = L.tileLayer('https://api.mapbox.com/styles/v1/mapbox/outdoors-v11/tiles/{z}/{x}/{y}?access_token=' + token, {
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(Mapknitterunique);

Mapknitterunique.addControl(new L.Control.Fullscreen()); // to go full-screen
Mapknitterunique.on('fullscreenchange', function () {
if (Mapknitterunique.isFullscreen()) {
Mapknitterunique.options.minZoom = 3 ;
}
else {
Mapknitterunique.options.minZoom = 1 ;
}
});


var baseMaps = {
"Baselayer1": baselayer
};
var overlayMaps = {
"MapKnitter": MapKnitter
};
L.control.layers(baseMaps, overlayMaps).addTo(Mapknitterunique);
</script>