2017-04-04 01:24:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================================================================
|
|
|
|
The /r/place Atlas
|
2017-04-06 00:43:45 +02:00
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
An Atlas of Reddit's /r/place, with information to each
|
|
|
|
artwork of the canvas provided by the community.
|
2017-04-06 00:43:45 +02:00
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
Copyright (C) 2017 Roland Rytz <roland@draemm.li>
|
|
|
|
Licensed under the GNU Affero General Public License Version 3
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as
|
|
|
|
published by the Free Software Foundation, either version 3 of the
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
For more information, see:
|
2022-04-03 11:08:52 +02:00
|
|
|
http://place-atlas.stefanocoding.me/license.txt
|
2017-04-06 00:43:45 +02:00
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
========================================================================
|
|
|
|
*/
|
2017-04-08 05:57:12 +02:00
|
|
|
var linesCanvas = document.getElementById("linesCanvas");
|
|
|
|
var linesContext = linesCanvas.getContext("2d");
|
|
|
|
var hovered = [];
|
|
|
|
|
2017-04-10 16:28:22 +02:00
|
|
|
var previousZoomOrigin = [0, 0];
|
|
|
|
var previousScaleZoomOrigin = [0, 0];
|
|
|
|
|
2017-04-11 23:16:35 +02:00
|
|
|
var backgroundCanvas = document.createElement("canvas");
|
2022-04-03 11:08:52 +02:00
|
|
|
backgroundCanvas.width = 2000;
|
2022-04-04 22:39:49 +02:00
|
|
|
backgroundCanvas.height = 2000;
|
2017-04-11 23:16:35 +02:00
|
|
|
var backgroundContext = backgroundCanvas.getContext("2d");
|
|
|
|
|
2017-04-08 05:57:12 +02:00
|
|
|
function updateLines(){
|
|
|
|
|
|
|
|
linesCanvas.width = linesCanvas.clientWidth;
|
|
|
|
linesCanvas.height = linesCanvas.clientHeight;
|
|
|
|
linesContext.lineCap = "round";
|
|
|
|
linesContext.lineWidth = Math.max(Math.min(zoom*1.5, 16*1.5), 6);
|
|
|
|
linesContext.strokeStyle = "#000000";
|
|
|
|
|
|
|
|
for(var i = 0; i < hovered.length; i++){
|
|
|
|
var element = hovered[i].element;
|
|
|
|
|
2017-04-09 02:08:35 +02:00
|
|
|
if(element.getBoundingClientRect().left != 0){
|
|
|
|
|
|
|
|
linesContext.beginPath();
|
|
|
|
//linesContext.moveTo(element.offsetLeft + element.clientWidth - 10, element.offsetTop + 20);
|
|
|
|
linesContext.moveTo(
|
|
|
|
element.getBoundingClientRect().left + document.documentElement.scrollLeft + element.clientWidth/2
|
|
|
|
,element.getBoundingClientRect().top + document.documentElement.scrollTop + 20
|
|
|
|
);
|
|
|
|
linesContext.lineTo(
|
|
|
|
~~(hovered[i].center[0]*zoom) + innerContainer.offsetLeft
|
|
|
|
,~~(hovered[i].center[1]*zoom) + innerContainer.offsetTop
|
|
|
|
);
|
|
|
|
linesContext.stroke();
|
|
|
|
|
|
|
|
}
|
2017-04-08 05:57:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
linesContext.lineWidth = Math.max(Math.min(zoom, 16), 4);
|
|
|
|
linesContext.strokeStyle = "#FFFFFF";
|
|
|
|
|
|
|
|
for(var i = 0; i < hovered.length; i++){
|
|
|
|
var element = hovered[i].element;
|
|
|
|
|
2017-04-09 02:08:35 +02:00
|
|
|
if(element.getBoundingClientRect().left != 0){
|
|
|
|
|
|
|
|
linesContext.beginPath();
|
|
|
|
linesContext.moveTo(
|
|
|
|
element.getBoundingClientRect().left + document.documentElement.scrollLeft + element.clientWidth/2
|
|
|
|
,element.getBoundingClientRect().top + document.documentElement.scrollTop + 20
|
|
|
|
);
|
|
|
|
linesContext.lineTo(
|
|
|
|
~~(hovered[i].center[0]*zoom) + innerContainer.offsetLeft
|
|
|
|
,~~(hovered[i].center[1]*zoom) + innerContainer.offsetTop
|
|
|
|
);
|
|
|
|
linesContext.stroke();
|
|
|
|
}
|
2017-04-08 05:57:12 +02:00
|
|
|
}
|
|
|
|
}
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2017-04-11 23:16:35 +02:00
|
|
|
function renderBackground(atlas){
|
|
|
|
|
|
|
|
backgroundContext.clearRect(0, 0, canvas.width, canvas.height);
|
|
|
|
|
|
|
|
//backgroundCanvas.width = 1000 * zoom;
|
|
|
|
//backgroundCanvas.height = 1000 * zoom;
|
|
|
|
|
|
|
|
//backgroundContext.lineWidth = zoom;
|
|
|
|
|
|
|
|
backgroundContext.fillStyle = "rgba(0, 0, 0, 0.6)";
|
|
|
|
backgroundContext.fillRect(0, 0, backgroundCanvas.width, backgroundCanvas.height);
|
|
|
|
|
|
|
|
for(var i = 0; i < atlas.length; i++){
|
|
|
|
|
|
|
|
var path = atlas[i].path;
|
|
|
|
|
|
|
|
backgroundContext.beginPath();
|
|
|
|
|
|
|
|
if(path[0]){
|
|
|
|
//backgroundContext.moveTo(path[0][0]*zoom, path[0][1]*zoom);
|
|
|
|
backgroundContext.moveTo(path[0][0], path[0][1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(var p = 1; p < path.length; p++){
|
|
|
|
//backgroundContext.lineTo(path[p][0]*zoom, path[p][1]*zoom);
|
|
|
|
backgroundContext.lineTo(path[p][0], path[p][1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
backgroundContext.closePath();
|
|
|
|
|
|
|
|
backgroundContext.strokeStyle = "rgba(255, 255, 255, 0.8)";
|
|
|
|
backgroundContext.stroke();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
function initView(){
|
2017-04-09 21:45:08 +02:00
|
|
|
|
2017-04-06 23:09:37 +02:00
|
|
|
var wrapper = document.getElementById("wrapper");
|
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
var objectsContainer = document.getElementById("objectsList");
|
2017-04-09 02:08:35 +02:00
|
|
|
var closeObjectsListButton = document.getElementById("closeObjectsListButton");
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2017-04-05 20:48:32 +02:00
|
|
|
var filterInput = document.getElementById("searchList");
|
2017-04-06 00:43:45 +02:00
|
|
|
|
2017-04-05 20:48:32 +02:00
|
|
|
var entriesList = document.getElementById("entriesList");
|
2017-04-06 11:44:50 +02:00
|
|
|
var hideListButton = document.getElementById("hideListButton");
|
|
|
|
var entriesListShown = true;
|
2017-04-05 20:48:32 +02:00
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
var sortedAtlas;
|
|
|
|
|
2017-04-05 20:48:32 +02:00
|
|
|
var entriesLimit = 50;
|
|
|
|
var entriesOffset = 0;
|
|
|
|
var moreEntriesButton = document.createElement("button");
|
|
|
|
moreEntriesButton.innerHTML = "Show "+entriesLimit+" more";
|
|
|
|
moreEntriesButton.id = "moreEntriesButton";
|
|
|
|
moreEntriesButton.onclick = function(){
|
2017-04-09 21:45:08 +02:00
|
|
|
buildObjectsList(null, null);
|
2017-04-05 20:48:32 +02:00
|
|
|
};
|
2017-04-06 23:09:37 +02:00
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
var defaultSort = "shuffle";
|
2017-04-09 21:45:08 +02:00
|
|
|
document.getElementById("sort").value = defaultSort;
|
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
var lastPos = [0, 0];
|
|
|
|
|
|
|
|
var fixed = false; // Fix hovered items in place, so that clicking on links is possible
|
|
|
|
|
2017-04-09 22:22:06 +02:00
|
|
|
renderBackground(atlas);
|
2017-04-04 01:24:46 +02:00
|
|
|
render();
|
|
|
|
|
2017-04-09 21:45:08 +02:00
|
|
|
buildObjectsList(null, null);
|
2017-04-05 20:48:32 +02:00
|
|
|
|
2017-04-06 00:43:45 +02:00
|
|
|
// parse linked atlas entry id from link hash
|
2017-04-06 01:58:30 +02:00
|
|
|
/*if (window.location.hash.substring(3)){
|
|
|
|
zoom = 4;
|
|
|
|
applyView();
|
|
|
|
highlightEntryFromUrl();
|
|
|
|
}*/
|
|
|
|
|
2022-04-04 22:39:49 +02:00
|
|
|
if(document.documentElement.clientWidth > 2000){
|
2017-04-06 23:09:37 +02:00
|
|
|
entriesListShown = true;
|
|
|
|
wrapper.className = wrapper.className.replace(/ listHidden/g, "");
|
|
|
|
}
|
|
|
|
|
2022-04-04 22:39:49 +02:00
|
|
|
if(document.documentElement.clientWidth < 2000){
|
2017-04-06 23:09:37 +02:00
|
|
|
entriesListShown = false;
|
|
|
|
wrapper.className += " listHidden";
|
|
|
|
}
|
|
|
|
|
|
|
|
applyView();
|
|
|
|
render();
|
|
|
|
updateLines();
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-04-06 01:58:30 +02:00
|
|
|
var args = window.location.search;
|
|
|
|
if(args){
|
|
|
|
id = args.split("id=")[1];
|
|
|
|
if(id){
|
|
|
|
highlightEntryFromUrl();
|
2017-04-06 00:43:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
container.addEventListener("mousemove", function(e){
|
2017-04-10 23:56:35 +02:00
|
|
|
if(e.sourceCapabilities){
|
|
|
|
if(!e.sourceCapabilities.firesTouchEvents){
|
|
|
|
updateHovering(e);
|
|
|
|
}
|
|
|
|
} else {
|
2017-04-10 16:09:56 +02:00
|
|
|
updateHovering(e);
|
|
|
|
}
|
2017-04-04 01:24:46 +02:00
|
|
|
});
|
|
|
|
|
2017-04-05 20:48:32 +02:00
|
|
|
filterInput.addEventListener("input", function(e){
|
|
|
|
entriesOffset = 0;
|
|
|
|
entriesList.innerHTML = "";
|
|
|
|
entriesList.appendChild(moreEntriesButton);
|
|
|
|
|
2017-04-09 21:45:08 +02:00
|
|
|
if(this.value === ""){
|
|
|
|
document.getElementById("relevantOption").disabled = true;
|
2017-04-10 12:25:04 +02:00
|
|
|
sortedAtlas = atlas.concat();
|
2017-04-09 21:45:08 +02:00
|
|
|
buildObjectsList(null, null);
|
|
|
|
} else {
|
|
|
|
document.getElementById("relevantOption").disabled = false;
|
|
|
|
buildObjectsList(this.value.toLowerCase(), "relevant");
|
|
|
|
}
|
2017-04-06 00:43:45 +02:00
|
|
|
|
2017-04-05 20:48:32 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
document.getElementById("sort").addEventListener("input", function(e){
|
|
|
|
entriesOffset = 0;
|
|
|
|
entriesList.innerHTML = "";
|
|
|
|
entriesList.appendChild(moreEntriesButton);
|
|
|
|
|
2017-04-09 21:45:08 +02:00
|
|
|
if(this.value != "relevant"){
|
|
|
|
defaultSort = this.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
buildObjectsList(filterInput.value.toLowerCase(), this.value);
|
2017-04-06 00:43:45 +02:00
|
|
|
|
2017-04-05 20:48:32 +02:00
|
|
|
});
|
2017-04-06 11:44:50 +02:00
|
|
|
|
|
|
|
hideListButton.addEventListener("click", function(e){
|
|
|
|
entriesListShown = !entriesListShown;
|
|
|
|
if(entriesListShown){
|
2017-04-06 23:09:37 +02:00
|
|
|
wrapper.className = wrapper.className.replace(/ listHidden/g, "");
|
2017-04-06 11:44:50 +02:00
|
|
|
} else {
|
2017-04-06 23:09:37 +02:00
|
|
|
wrapper.className += " listHidden";
|
2017-04-06 11:44:50 +02:00
|
|
|
}
|
|
|
|
applyView();
|
|
|
|
render();
|
|
|
|
updateLines();
|
2017-04-07 19:52:56 +02:00
|
|
|
return false;
|
2017-04-06 11:44:50 +02:00
|
|
|
});
|
2017-04-05 20:48:32 +02:00
|
|
|
|
2017-04-09 02:08:35 +02:00
|
|
|
closeObjectsListButton.addEventListener("click", function(e){
|
|
|
|
hovered = [];
|
|
|
|
objectsContainer.innerHTML = "";
|
|
|
|
updateLines();
|
|
|
|
closeObjectsListButton.className = "hidden";
|
|
|
|
fixed = false;
|
|
|
|
render();
|
|
|
|
});
|
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
function shuffle(){
|
|
|
|
//console.log("shuffled atlas");
|
|
|
|
for (var i = sortedAtlas.length - 1; i > 0; i--) {
|
|
|
|
var j = Math.floor(Math.random() * (i + 1));
|
|
|
|
var temp = sortedAtlas[i];
|
|
|
|
sortedAtlas[i] = sortedAtlas[j];
|
|
|
|
sortedAtlas[j] = temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-06 01:58:30 +02:00
|
|
|
function createInfoBlock(entry){
|
|
|
|
var element = document.createElement("div");
|
|
|
|
element.className = "object";
|
|
|
|
|
2017-04-10 18:17:29 +02:00
|
|
|
var html = "<h2><a href=\"?id="+entry.id+"\">"+entry.name+"</a></h2>";
|
2017-04-06 01:58:30 +02:00
|
|
|
|
|
|
|
if(entry.description){
|
2017-04-10 18:17:29 +02:00
|
|
|
html += "<p>"+entry.description+"</p>";
|
2017-04-06 01:58:30 +02:00
|
|
|
}
|
|
|
|
if(entry.website){
|
2017-04-10 18:17:29 +02:00
|
|
|
html += "<a target=\"_blank\" href="+entry.website+">Website</a>";
|
2017-04-06 01:58:30 +02:00
|
|
|
}
|
|
|
|
if(entry.subreddit){
|
2017-04-10 12:25:04 +02:00
|
|
|
var subreddits = entry.subreddit.split(",");
|
|
|
|
|
|
|
|
for(var i in subreddits){
|
|
|
|
var subreddit = subreddits[i].trim();
|
|
|
|
if(subreddit.substring(0, 2) == "r/"){
|
|
|
|
subreddit = "/" + subreddit;
|
|
|
|
} else if(subreddit.substring(0, 1) != "/"){
|
|
|
|
subreddit = "/r/" + subreddit;
|
|
|
|
}
|
2017-04-10 18:17:29 +02:00
|
|
|
html += "<a target=\"_blank\" href=https://reddit.com"+subreddit+">"+subreddit+"</a>";
|
2017-04-06 01:58:30 +02:00
|
|
|
}
|
|
|
|
}
|
2022-04-04 16:31:10 +02:00
|
|
|
html+="<p style='font-family: Dejavu Sans Mono, sans, Sans-Serif;'>id: "+entry.id+"</p>";
|
2017-04-06 01:58:30 +02:00
|
|
|
element.innerHTML += html;
|
|
|
|
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
function highlightEntryFromUrl(){
|
|
|
|
|
|
|
|
var objectsContainer = document.getElementById("objectsList");
|
|
|
|
|
|
|
|
var id = 0;
|
|
|
|
|
|
|
|
var args = window.location.search;
|
|
|
|
if(args){
|
|
|
|
id = args.split("id=")[1];
|
|
|
|
if(id){
|
|
|
|
id = parseInt(id.split("&")[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//var id = parseInt(window.location.hash.substring(3));
|
|
|
|
|
|
|
|
var entry = atlas.filter(function(e){
|
|
|
|
return e.id === id;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (entry.length === 1){
|
|
|
|
entry = entry[0];
|
2017-05-03 20:33:58 +02:00
|
|
|
|
|
|
|
document.title = entry.name + " on the /r/place Atlas";
|
|
|
|
|
2017-04-06 01:58:30 +02:00
|
|
|
var infoElement = createInfoBlock(entry);
|
|
|
|
objectsContainer.innerHTML = "";
|
|
|
|
objectsContainer.appendChild(infoElement);
|
|
|
|
|
2017-04-06 19:15:16 +02:00
|
|
|
//console.log(entry.center[0]);
|
|
|
|
//console.log(entry.center[1]);
|
|
|
|
|
|
|
|
zoom = 4;
|
2017-04-11 23:16:35 +02:00
|
|
|
renderBackground(atlas);
|
2017-04-06 19:15:16 +02:00
|
|
|
applyView();
|
|
|
|
|
2017-04-06 01:58:30 +02:00
|
|
|
zoomOrigin = [
|
2017-04-06 19:15:16 +02:00
|
|
|
innerContainer.clientWidth/2 - entry.center[0]* zoom// + container.offsetLeft
|
|
|
|
,innerContainer.clientHeight/2 - entry.center[1]* zoom// + container.offsetTop
|
|
|
|
];
|
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
scaleZoomOrigin = [
|
2022-04-04 22:39:49 +02:00
|
|
|
2000/2 - entry.center[0]// + container.offsetLeft
|
2022-04-03 11:08:52 +02:00
|
|
|
,2000/2 - entry.center[1]// + container.offsetTop
|
2017-04-10 12:25:04 +02:00
|
|
|
];
|
|
|
|
|
2017-04-06 19:15:16 +02:00
|
|
|
//console.log(zoomOrigin);
|
|
|
|
|
2017-04-06 01:58:30 +02:00
|
|
|
applyView();
|
|
|
|
hovered = [entry];
|
|
|
|
render();
|
|
|
|
hovered[0].element = infoElement;
|
2017-04-09 02:08:35 +02:00
|
|
|
closeObjectsListButton.className = "";
|
2017-04-06 01:58:30 +02:00
|
|
|
updateLines();
|
|
|
|
fixed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
function updateHovering(e, tapped){
|
2017-04-10 16:09:56 +02:00
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
if(!dragging && (!fixed || tapped)){
|
2017-04-04 01:24:46 +02:00
|
|
|
var pos = [
|
2017-04-06 19:15:16 +02:00
|
|
|
(e.clientX - (container.clientWidth/2 - innerContainer.clientWidth/2 + zoomOrigin[0] + container.offsetLeft))/zoom
|
|
|
|
,(e.clientY - (container.clientHeight/2 - innerContainer.clientHeight/2 + zoomOrigin[1] + container.offsetTop))/zoom
|
2017-04-04 01:24:46 +02:00
|
|
|
];
|
|
|
|
|
2022-04-03 21:38:16 +02:00
|
|
|
if(pos[0] <= 2200 && pos[0] >= -100 && pos[0] <= 2200 && pos[0] >= -100){
|
2017-04-04 01:24:46 +02:00
|
|
|
var newHovered = [];
|
|
|
|
for(var i = 0; i < atlas.length; i++){
|
|
|
|
if(pointIsInPolygon(pos, atlas[i].path)){
|
|
|
|
newHovered.push(atlas[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var changed = false;
|
|
|
|
|
|
|
|
if(hovered.length == newHovered.length){
|
|
|
|
for(var i = 0; i < hovered.length; i++){
|
|
|
|
if(hovered[i].id != newHovered[i].id){
|
|
|
|
changed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(changed){
|
|
|
|
hovered = newHovered;
|
2017-04-05 20:48:32 +02:00
|
|
|
|
|
|
|
objectsContainer.innerHTML = "";
|
|
|
|
|
|
|
|
for(var i in hovered){
|
2017-04-06 00:43:45 +02:00
|
|
|
var element = createInfoBlock(hovered[i]);
|
2017-04-05 20:48:32 +02:00
|
|
|
|
|
|
|
objectsContainer.appendChild(element);
|
|
|
|
|
|
|
|
hovered[i].element = element;
|
|
|
|
}
|
|
|
|
|
2017-04-09 02:08:35 +02:00
|
|
|
if(hovered.length > 0){
|
|
|
|
closeObjectsListButton.className = "";
|
|
|
|
} else {
|
|
|
|
closeObjectsListButton.className = "hidden";
|
|
|
|
}
|
|
|
|
|
2017-04-06 00:43:45 +02:00
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-09 21:45:08 +02:00
|
|
|
function buildObjectsList(filter, sort){
|
2017-04-05 20:48:32 +02:00
|
|
|
|
|
|
|
if(entriesList.contains(moreEntriesButton)){
|
|
|
|
entriesList.removeChild(moreEntriesButton);
|
|
|
|
}
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
if(!sortedAtlas){
|
|
|
|
sortedAtlas = atlas.concat();
|
|
|
|
document.getElementById("atlasSize").innerHTML = "The Atlas contains "+sortedAtlas.length+" entries.";
|
|
|
|
}
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2017-04-05 20:48:32 +02:00
|
|
|
if(filter){
|
|
|
|
sortedAtlas = atlas.filter(function(value){
|
2017-04-09 21:45:08 +02:00
|
|
|
return (
|
|
|
|
value.name.toLowerCase().indexOf(filter) !== -1
|
|
|
|
|| value.description.toLowerCase().indexOf(filter) !== -1
|
|
|
|
);
|
2017-04-05 20:48:32 +02:00
|
|
|
});
|
|
|
|
document.getElementById("atlasSize").innerHTML = "Found "+sortedAtlas.length+" entries.";
|
2017-04-04 01:24:46 +02:00
|
|
|
} else {
|
2017-04-05 20:48:32 +02:00
|
|
|
document.getElementById("atlasSize").innerHTML = "The Atlas contains "+sortedAtlas.length+" entries.";
|
2017-04-04 01:24:46 +02:00
|
|
|
}
|
|
|
|
|
2017-04-09 21:45:08 +02:00
|
|
|
if(sort === null){
|
|
|
|
sort = defaultSort;
|
|
|
|
}
|
|
|
|
|
2017-04-09 22:22:06 +02:00
|
|
|
renderBackground(sortedAtlas);
|
|
|
|
render();
|
|
|
|
|
2017-04-09 21:45:08 +02:00
|
|
|
document.getElementById("sort").value = sort;
|
|
|
|
|
2017-04-09 22:00:22 +02:00
|
|
|
//console.log(sort);
|
2017-04-05 20:48:32 +02:00
|
|
|
|
|
|
|
var sortFunction;
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2017-04-06 19:44:09 +02:00
|
|
|
//console.log(sort);
|
|
|
|
|
2017-04-05 20:48:32 +02:00
|
|
|
switch(sort){
|
2017-04-10 12:25:04 +02:00
|
|
|
case "shuffle":
|
|
|
|
sortFunction = null;
|
|
|
|
if(entriesOffset == 0){
|
|
|
|
shuffle();
|
|
|
|
}
|
|
|
|
break;
|
2017-04-05 20:48:32 +02:00
|
|
|
case "alphaAsc":
|
|
|
|
sortFunction = function(a, b){
|
2017-04-06 19:44:09 +02:00
|
|
|
return a.name.toLowerCase().localeCompare(b.name.toLowerCase());
|
2017-04-05 20:48:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "alphaDesc":
|
|
|
|
sortFunction = function(a, b){
|
2017-04-06 19:44:09 +02:00
|
|
|
return b.name.toLowerCase().localeCompare(a.name.toLowerCase());
|
2017-04-05 20:48:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "newest":
|
|
|
|
sortFunction = function(a, b){
|
|
|
|
if (a.id > b.id) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.id < b.id) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
// a must be equal to b
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "oldest":
|
|
|
|
sortFunction = function(a, b){
|
|
|
|
if (a.id < b.id) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.id > b.id) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
// a must be equal to b
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2017-04-09 21:45:08 +02:00
|
|
|
case "relevant":
|
|
|
|
sortFunction = function(a, b){
|
|
|
|
if(a.name.toLowerCase().indexOf(filter) !== -1 && b.name.toLowerCase().indexOf(filter) !== -1){
|
|
|
|
if (a.name.toLowerCase().indexOf(filter) < b.name.toLowerCase().indexOf(filter)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if (a.name.toLowerCase().indexOf(filter) > b.name.toLowerCase().indexOf(filter)) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
2017-04-09 22:00:22 +02:00
|
|
|
return a.name.toLowerCase().localeCompare(b.name.toLowerCase());
|
2017-04-09 21:45:08 +02:00
|
|
|
}
|
|
|
|
} else if(a.name.toLowerCase().indexOf(filter) !== -1){
|
|
|
|
return -1;
|
|
|
|
} else if(b.name.toLowerCase().indexOf(filter) !== -1){
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
if (a.description.toLowerCase().indexOf(filter) < b.description.toLowerCase().indexOf(filter)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if (a.description.toLowerCase().indexOf(filter) > b.description.toLowerCase().indexOf(filter)) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
2017-04-09 22:00:22 +02:00
|
|
|
return a.name.toLowerCase().localeCompare(b.name.toLowerCase());
|
2017-04-09 21:45:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2017-04-05 20:48:32 +02:00
|
|
|
}
|
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
if(sortFunction){
|
|
|
|
sortedAtlas.sort(sortFunction);
|
|
|
|
}
|
2017-04-06 00:43:45 +02:00
|
|
|
|
2017-04-05 20:48:32 +02:00
|
|
|
for(var i = entriesOffset; i < entriesOffset+entriesLimit; i++){
|
|
|
|
|
|
|
|
if(i >= sortedAtlas.length){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-04-06 00:43:45 +02:00
|
|
|
|
|
|
|
var element = createInfoBlock(sortedAtlas[i]);
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2017-04-06 01:58:30 +02:00
|
|
|
element.entry = sortedAtlas[i];
|
2017-04-05 20:48:32 +02:00
|
|
|
|
|
|
|
element.addEventListener("mouseenter", function(e){
|
2017-04-06 19:29:54 +02:00
|
|
|
if(!fixed && !dragging){
|
2017-04-06 01:58:30 +02:00
|
|
|
objectsContainer.innerHTML = "";
|
2017-04-10 15:16:34 +02:00
|
|
|
|
|
|
|
previousZoomOrigin = [zoomOrigin[0], zoomOrigin[1]];
|
|
|
|
previousScaleZoomOrigin = [scaleZoomOrigin[0], scaleZoomOrigin[1]];
|
|
|
|
|
|
|
|
applyView();
|
|
|
|
|
2017-04-06 01:58:30 +02:00
|
|
|
zoomOrigin = [
|
2017-04-06 19:15:16 +02:00
|
|
|
innerContainer.clientWidth/2 - this.entry.center[0]* zoom// + container.offsetLeft
|
|
|
|
,innerContainer.clientHeight/2 - this.entry.center[1]* zoom// + container.offsetTop
|
2017-04-06 01:58:30 +02:00
|
|
|
]
|
2017-04-06 19:15:16 +02:00
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
scaleZoomOrigin = [
|
2022-04-04 22:39:49 +02:00
|
|
|
2000/2 - this.entry.center[0]
|
2022-04-03 11:08:52 +02:00
|
|
|
,2000/2 - this.entry.center[1]
|
2017-04-10 12:25:04 +02:00
|
|
|
]
|
|
|
|
|
2017-04-06 19:15:16 +02:00
|
|
|
//console.log(zoomOrigin);
|
|
|
|
|
|
|
|
|
2017-04-06 01:58:30 +02:00
|
|
|
applyView();
|
|
|
|
hovered = [this.entry];
|
|
|
|
render();
|
|
|
|
hovered[0].element = this;
|
|
|
|
updateLines();
|
|
|
|
}
|
2017-04-06 00:43:45 +02:00
|
|
|
|
2017-04-05 20:48:32 +02:00
|
|
|
});
|
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
element.addEventListener("click", function(e){
|
|
|
|
toggleFixed(e);
|
2017-04-10 15:16:34 +02:00
|
|
|
if(fixed){
|
|
|
|
previousZoomOrigin = [zoomOrigin[0], zoomOrigin[1]];
|
|
|
|
previousScaleZoomOrigin = [scaleZoomOrigin[0], scaleZoomOrigin[1]];
|
|
|
|
applyView();
|
|
|
|
}
|
2017-04-10 12:25:04 +02:00
|
|
|
if(document.documentElement.clientWidth < 500){
|
|
|
|
|
|
|
|
objectsContainer.innerHTML = "";
|
|
|
|
|
|
|
|
entriesListShown = false;
|
|
|
|
wrapper.className += " listHidden";
|
|
|
|
|
|
|
|
zoom = 4;
|
2017-04-11 23:16:35 +02:00
|
|
|
renderBackground(atlas);
|
2017-04-10 12:25:04 +02:00
|
|
|
applyView();
|
|
|
|
|
|
|
|
zoomOrigin = [
|
|
|
|
innerContainer.clientWidth/2 - this.entry.center[0]* zoom// + container.offsetLeft
|
|
|
|
,innerContainer.clientHeight/2 - this.entry.center[1]* zoom// + container.offsetTop
|
|
|
|
]
|
|
|
|
|
|
|
|
scaleZoomOrigin = [
|
2022-04-04 22:39:49 +02:00
|
|
|
2000/2 - this.entry.center[0]
|
2022-04-03 11:08:52 +02:00
|
|
|
,2000/2 - this.entry.center[1]
|
2017-04-10 12:25:04 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
previousZoomOrigin = [zoomOrigin[0], zoomOrigin[1]];
|
|
|
|
previousScaleZoomOrigin = [scaleZoomOrigin[0], scaleZoomOrigin[1]];
|
|
|
|
|
|
|
|
fixed = true;
|
|
|
|
|
|
|
|
hovered = [this.entry];
|
|
|
|
hovered[0].element = this;
|
|
|
|
|
|
|
|
applyView();
|
|
|
|
render();
|
|
|
|
updateLines();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-04-05 20:48:32 +02:00
|
|
|
element.addEventListener("mouseleave", function(e){
|
2017-04-06 19:29:54 +02:00
|
|
|
if(!fixed && !dragging){
|
2017-04-10 16:09:56 +02:00
|
|
|
zoomOrigin = [previousScaleZoomOrigin[0]*zoom, previousScaleZoomOrigin[1]*zoom];
|
2017-04-10 15:16:34 +02:00
|
|
|
scaleZoomOrigin = [previousScaleZoomOrigin[0], previousScaleZoomOrigin[1]];
|
2017-04-08 03:27:51 +02:00
|
|
|
applyView();
|
2017-04-06 01:58:30 +02:00
|
|
|
hovered = [];
|
|
|
|
updateLines();
|
|
|
|
render();
|
|
|
|
}
|
2017-04-05 20:48:32 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
entriesList.appendChild(element);
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2017-04-05 20:48:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
entriesOffset += entriesLimit;
|
|
|
|
|
|
|
|
if(sortedAtlas.length > entriesOffset){
|
|
|
|
moreEntriesButton.innerHTML = "Show "+Math.min(entriesLimit, sortedAtlas.length - entriesOffset)+" more";
|
|
|
|
entriesList.appendChild(moreEntriesButton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function render(){
|
2017-04-11 23:16:35 +02:00
|
|
|
|
|
|
|
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
|
|
|
|
|
|
//canvas.width = 1000*zoom;
|
|
|
|
//canvas.height = 1000*zoom;
|
|
|
|
|
2017-04-05 20:48:32 +02:00
|
|
|
context.globalCompositeOperation = "source-over";
|
|
|
|
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
|
|
|
|
|
|
if(hovered.length > 0){
|
|
|
|
container.style.cursor = "pointer";
|
|
|
|
} else {
|
|
|
|
container.style.cursor = "default";
|
|
|
|
}
|
2017-04-06 00:43:45 +02:00
|
|
|
|
2017-04-05 20:48:32 +02:00
|
|
|
|
|
|
|
for(var i = 0; i < hovered.length; i++){
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2017-04-06 00:43:45 +02:00
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
var path = hovered[i].path;
|
2017-04-06 00:43:45 +02:00
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
context.beginPath();
|
|
|
|
|
|
|
|
if(path[0]){
|
2017-04-11 23:16:35 +02:00
|
|
|
//context.moveTo(path[0][0]*zoom, path[0][1]*zoom);
|
2017-04-04 01:24:46 +02:00
|
|
|
context.moveTo(path[0][0], path[0][1]);
|
|
|
|
}
|
2017-04-06 00:43:45 +02:00
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
for(var p = 1; p < path.length; p++){
|
2017-04-11 23:16:35 +02:00
|
|
|
//context.lineTo(path[p][0]*zoom, path[p][1]*zoom);
|
2017-04-04 01:24:46 +02:00
|
|
|
context.lineTo(path[p][0], path[p][1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
context.closePath();
|
|
|
|
|
|
|
|
context.globalCompositeOperation = "source-over";
|
|
|
|
|
|
|
|
context.fillStyle = "rgba(0, 0, 0, 1)";
|
|
|
|
context.fill();
|
|
|
|
}
|
|
|
|
|
|
|
|
context.globalCompositeOperation = "source-out";
|
|
|
|
context.drawImage(backgroundCanvas, 0, 0);
|
2017-04-05 04:20:49 +02:00
|
|
|
|
|
|
|
for(var i = 0; i < hovered.length; i++){
|
2017-04-06 00:43:45 +02:00
|
|
|
|
2017-04-05 04:20:49 +02:00
|
|
|
var path = hovered[i].path;
|
2017-04-06 00:43:45 +02:00
|
|
|
|
2017-04-05 04:20:49 +02:00
|
|
|
context.beginPath();
|
|
|
|
|
|
|
|
if(path[0]){
|
2017-04-11 23:16:35 +02:00
|
|
|
//context.moveTo(path[0][0]*zoom, path[0][1]*zoom);
|
2017-04-05 04:20:49 +02:00
|
|
|
context.moveTo(path[0][0], path[0][1]);
|
|
|
|
}
|
2017-04-06 00:43:45 +02:00
|
|
|
|
2017-04-05 04:20:49 +02:00
|
|
|
for(var p = 1; p < path.length; p++){
|
2017-04-11 23:16:35 +02:00
|
|
|
//context.lineTo(path[p][0]*zoom, path[p][1]*zoom);
|
2017-04-05 04:20:49 +02:00
|
|
|
context.lineTo(path[p][0], path[p][1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
context.closePath();
|
|
|
|
|
|
|
|
context.globalCompositeOperation = "source-over";
|
|
|
|
|
|
|
|
context.strokeStyle = "rgba(0, 0, 0, 1)";
|
2017-04-11 23:16:35 +02:00
|
|
|
//context.lineWidth = zoom;
|
2017-04-05 04:20:49 +02:00
|
|
|
context.stroke();
|
|
|
|
}
|
|
|
|
|
2017-04-06 00:43:45 +02:00
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
}
|
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
function toggleFixed(e, tapped){
|
2017-04-04 01:24:46 +02:00
|
|
|
if(!fixed && hovered.length == 0){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
fixed = !fixed;
|
|
|
|
if(!fixed){
|
2017-04-10 12:25:04 +02:00
|
|
|
updateHovering(e, tapped);
|
2017-04-04 01:24:46 +02:00
|
|
|
render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener("resize", updateLines);
|
|
|
|
window.addEventListener("mousemove", updateLines);
|
|
|
|
window.addEventListener("dblClick", updateLines);
|
|
|
|
window.addEventListener("wheel", updateLines);
|
|
|
|
|
|
|
|
container.addEventListener("mousedown", function(e){
|
|
|
|
lastPos = [
|
|
|
|
e.clientX
|
|
|
|
,e.clientY
|
|
|
|
];
|
|
|
|
});
|
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
container.addEventListener("touchstart", function(e){
|
|
|
|
if(e.touches.length == 1){
|
|
|
|
lastPos = [
|
|
|
|
e.touches[0].clientX
|
|
|
|
,e.touches[0].clientY
|
|
|
|
];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
container.addEventListener("mouseup", function(e){
|
|
|
|
if(Math.abs(lastPos[0] - e.clientX) + Math.abs(lastPos[1] - e.clientY) <= 4){
|
|
|
|
toggleFixed(e);
|
|
|
|
}
|
|
|
|
});
|
2017-04-05 20:48:32 +02:00
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
container.addEventListener("touchend", function(e){
|
|
|
|
//console.log(e);
|
|
|
|
//console.log(e.changedTouches[0].clientX);
|
|
|
|
if(e.changedTouches.length == 1){
|
|
|
|
e = e.changedTouches[0];
|
2017-04-10 15:16:34 +02:00
|
|
|
//console.log(lastPos[0] - e.clientX);
|
2017-04-10 12:25:04 +02:00
|
|
|
if(Math.abs(lastPos[0] - e.clientX) + Math.abs(lastPos[1] - e.clientY) <= 4){
|
2017-04-10 15:16:34 +02:00
|
|
|
//console.log("Foo!!");
|
2017-04-10 16:09:56 +02:00
|
|
|
dragging = false;
|
|
|
|
fixed = false;
|
|
|
|
setTimeout(
|
|
|
|
function(){
|
|
|
|
updateHovering(e, true);
|
|
|
|
}
|
|
|
|
, 10);
|
2017-04-10 12:25:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-04-05 20:48:32 +02:00
|
|
|
objectsContainer.addEventListener("scroll", function(e){
|
|
|
|
updateLines();
|
|
|
|
});
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2017-04-06 23:09:37 +02:00
|
|
|
window.addEventListener("resize", function(){
|
|
|
|
//console.log(document.documentElement.clientWidth, document.documentElement.clientHeight);
|
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
var viewportWidth = document.documentElement.clientWidth;
|
|
|
|
|
2022-04-04 22:39:49 +02:00
|
|
|
if(document.documentElement.clientWidth > 2000 && viewportWidth <= 2000){
|
2017-04-06 23:09:37 +02:00
|
|
|
entriesListShown = true;
|
|
|
|
wrapper.className = wrapper.className.replace(/ listHidden/g, "");
|
|
|
|
}
|
|
|
|
|
2022-04-04 22:39:49 +02:00
|
|
|
if(document.documentElement.clientWidth < 2000 && viewportWidth >= 2000){
|
2017-04-06 23:09:37 +02:00
|
|
|
entriesListShown = false;
|
|
|
|
wrapper.className += " listHidden";
|
|
|
|
}
|
|
|
|
|
|
|
|
viewportWidth = document.documentElement.clientWidth;
|
|
|
|
|
|
|
|
applyView();
|
|
|
|
render();
|
|
|
|
updateLines();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-04-06 00:43:45 +02:00
|
|
|
}
|