2017-04-04 01:24:46 +02:00
|
|
|
/*
|
|
|
|
========================================================================
|
2022-04-09 04:45:47 +02:00
|
|
|
The 2022 /r/place Atlas
|
|
|
|
|
|
|
|
An Atlas of Reddit's 2022 /r/place, with information to each
|
2017-04-04 01:24:46 +02:00
|
|
|
artwork of the canvas provided by the community.
|
2022-04-09 04:45:47 +02:00
|
|
|
|
|
|
|
Copyright (c) 2017 Roland Rytz <roland@draemm.li>
|
|
|
|
Copyright (c) 2022 r/placeAtlas2 contributors
|
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
Licensed under the GNU Affero General Public License Version 3
|
2022-04-09 03:23:15 +02:00
|
|
|
https://place-atlas.stefanocoding.me/license.txt
|
2017-04-04 01:24:46 +02:00
|
|
|
========================================================================
|
|
|
|
*/
|
|
|
|
|
2022-04-09 03:23:15 +02:00
|
|
|
const prodDomain = "place-atlas.stefanocoding.me"
|
2017-04-04 01:24:46 +02:00
|
|
|
|
|
|
|
var innerContainer = document.getElementById("innerContainer");
|
|
|
|
var container = document.getElementById("container");
|
|
|
|
var canvas = document.getElementById("highlightCanvas");
|
|
|
|
var context = canvas.getContext("2d");
|
|
|
|
|
|
|
|
var zoom = 1;
|
2017-04-08 03:27:51 +02:00
|
|
|
|
|
|
|
if(window.devicePixelRatio){
|
|
|
|
zoom = 1/window.devicePixelRatio;
|
|
|
|
}
|
|
|
|
|
2017-04-08 05:57:12 +02:00
|
|
|
var maxZoom = 128;
|
|
|
|
var minZoom = 0.1;
|
|
|
|
|
2017-04-06 19:15:16 +02:00
|
|
|
var zoomOrigin = [0, 0];
|
2017-04-08 03:27:51 +02:00
|
|
|
var scaleZoomOrigin = [0, 0];
|
2017-04-04 01:24:46 +02:00
|
|
|
|
|
|
|
var dragging = false;
|
|
|
|
var lastPosition = [0, 0];
|
|
|
|
|
2017-04-06 19:15:16 +02:00
|
|
|
var viewportSize = [0, 0];
|
|
|
|
|
2022-04-08 17:19:10 +02:00
|
|
|
document.getElementById("entriesListDonate").addEventListener("click", function(e){
|
2017-05-01 17:54:19 +02:00
|
|
|
document.getElementById("donateOverlay").style.display = "flex";
|
|
|
|
});
|
|
|
|
|
2022-04-09 06:54:06 +02:00
|
|
|
document.getElementById("closeDonateButton").addEventListener("click", function(e){
|
2017-05-01 17:54:19 +02:00
|
|
|
document.getElementById("donateOverlay").style.display = "none";
|
|
|
|
});
|
|
|
|
|
2017-04-05 20:48:32 +02:00
|
|
|
function applyView(){
|
2017-04-10 12:25:04 +02:00
|
|
|
|
2017-04-10 15:16:34 +02:00
|
|
|
//console.log(zoomOrigin, scaleZoomOrigin);
|
2017-04-10 16:28:22 +02:00
|
|
|
//console.log(scaleZoomOrigin[0]);
|
|
|
|
|
2022-04-03 11:08:52 +02:00
|
|
|
scaleZoomOrigin[0] = Math.max(-1000, Math.min(1000, scaleZoomOrigin[0]));
|
2022-04-04 22:39:49 +02:00
|
|
|
scaleZoomOrigin[1] = Math.max(-1000, Math.min(1000, scaleZoomOrigin[1]));
|
2017-04-10 16:28:22 +02:00
|
|
|
|
|
|
|
zoomOrigin = [scaleZoomOrigin[0]*zoom, scaleZoomOrigin[1]*zoom];
|
2017-04-05 20:48:32 +02:00
|
|
|
|
2022-04-04 22:39:49 +02:00
|
|
|
innerContainer.style.height = (~~(zoom*2000))+"px";
|
2022-04-03 11:08:52 +02:00
|
|
|
innerContainer.style.width = (~~(zoom*2000))+"px";
|
2017-04-05 20:48:32 +02:00
|
|
|
|
2017-04-08 03:27:51 +02:00
|
|
|
innerContainer.style.left = ~~(container.clientWidth/2 - innerContainer.clientWidth/2 + zoomOrigin[0] + container.offsetLeft)+"px";
|
|
|
|
innerContainer.style.top = ~~(container.clientHeight/2 - innerContainer.clientHeight/2 + zoomOrigin[1] + container.offsetTop)+"px";
|
2017-04-09 02:08:35 +02:00
|
|
|
|
2017-04-05 20:48:32 +02:00
|
|
|
}
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2022-04-05 11:48:15 +02:00
|
|
|
var atlas = null;
|
|
|
|
|
2022-04-08 17:35:21 +02:00
|
|
|
if (document.location.host !== prodDomain) document.body.dataset.dev = ""
|
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
init();
|
|
|
|
|
2022-04-05 11:48:15 +02:00
|
|
|
async function init(){
|
2022-04-06 17:34:04 +02:00
|
|
|
// For Reviewing Reddit Changes
|
|
|
|
//let resp = await fetch("../tools/temp_atlas.json");
|
2022-04-06 17:34:36 +02:00
|
|
|
let resp = await fetch("./atlas.json");
|
2022-04-05 11:48:15 +02:00
|
|
|
atlas = await resp.json();
|
|
|
|
atlas.sort(function (a, b) {
|
|
|
|
if (a.center[1] < b.center[1]) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.center[1] > b.center[1]) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
// a must be equal to b
|
|
|
|
return 0;
|
|
|
|
});
|
2022-04-08 01:11:29 +02:00
|
|
|
//TEMP FOR TIME TRAVEL
|
|
|
|
atlasBackup = atlas;
|
2022-04-05 11:48:15 +02:00
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2017-04-06 19:15:16 +02:00
|
|
|
//console.log(document.documentElement.clientWidth, document.documentElement.clientHeight);
|
|
|
|
|
|
|
|
zoomOrigin = [0, 0];
|
|
|
|
applyView();
|
|
|
|
|
2017-04-08 03:27:51 +02:00
|
|
|
var initialPinchDistance = 0;
|
|
|
|
var initialPinchZoom = 0;
|
|
|
|
var initialPinchZoomOrigin = [0, 0];
|
|
|
|
|
2017-04-08 05:57:12 +02:00
|
|
|
var desiredZoom;
|
|
|
|
var zoomAnimationFrame;
|
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
var mode = "view";
|
|
|
|
|
|
|
|
var args = window.location.search;
|
|
|
|
if(args){
|
|
|
|
mode = args.split("mode=")[1];
|
|
|
|
if(mode){
|
|
|
|
mode = mode.split("&")[0];
|
|
|
|
} else {
|
|
|
|
mode = "view";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-09 05:41:40 +02:00
|
|
|
document.body.dataset.mode = mode
|
|
|
|
|
2022-04-09 11:27:14 +02:00
|
|
|
initGlobal()
|
|
|
|
if (mode !== "draw") initViewGlobal()
|
|
|
|
|
2022-04-09 05:41:40 +02:00
|
|
|
if(mode === "draw"){
|
|
|
|
initDraw();
|
|
|
|
} else if(mode === "about"){
|
2017-04-06 23:09:37 +02:00
|
|
|
window.location = "./about.html";
|
2022-04-09 05:41:40 +02:00
|
|
|
} else if(mode === "overlap"){
|
2017-04-06 23:20:08 +02:00
|
|
|
if(initOverlap){
|
|
|
|
initOverlap();
|
|
|
|
}
|
2022-04-08 06:06:16 +02:00
|
|
|
} else if(mode.startsWith("diff")){
|
|
|
|
try {
|
|
|
|
let liveResp = await fetch("https://place-atlas.stefanocoding.me/atlas.json");
|
|
|
|
let liveJson = await liveResp.json();
|
|
|
|
let liveAtlasReduced = liveJson.reduce(function(a, c) {
|
|
|
|
a[c.id] = c;
|
|
|
|
return a;
|
|
|
|
},{});
|
2022-04-08 22:02:14 +02:00
|
|
|
// Mark added/edited entries
|
2022-04-08 06:06:16 +02:00
|
|
|
atlas = atlas.map(function(entry) {
|
|
|
|
if(liveAtlasReduced[entry.id] === undefined){
|
|
|
|
entry.diff = "add";
|
|
|
|
}else if(JSON.stringify(entry) !== JSON.stringify(liveAtlasReduced[entry.id])){
|
|
|
|
entry.diff = "edit";
|
|
|
|
}
|
|
|
|
return entry;
|
|
|
|
});
|
2022-04-08 22:02:14 +02:00
|
|
|
|
|
|
|
// Mark removed entries
|
|
|
|
let atlasReduced = atlas.reduce(function(a, c) {
|
|
|
|
a[c.id] = c;
|
|
|
|
return a;
|
|
|
|
},{});
|
2022-04-09 06:09:32 +02:00
|
|
|
let removedEntries = liveJson.filter(entry =>
|
|
|
|
atlasReduced[entry.id] === undefined
|
|
|
|
).map(entry => {
|
|
|
|
entry.diff = "delete"
|
|
|
|
return entry
|
|
|
|
})
|
2022-04-08 22:02:14 +02:00
|
|
|
atlas.push(...removedEntries)
|
|
|
|
|
|
|
|
if(mode.includes("only")){
|
|
|
|
atlas = atlas.filter(function(entry) {
|
|
|
|
return typeof entry.diff == "string"
|
|
|
|
});
|
|
|
|
}
|
2022-04-08 06:06:16 +02:00
|
|
|
//TEMP FOR TIME TRAVEL
|
|
|
|
atlasBackup = atlas;
|
|
|
|
} catch (error) {
|
2022-04-09 07:04:32 +02:00
|
|
|
console.warn("Diff mode failed to load, reverting to normal view.", error);
|
2022-04-08 06:06:16 +02:00
|
|
|
} finally {
|
2022-04-08 22:02:14 +02:00
|
|
|
if(initOverlap && mode.includes("overlap")){
|
|
|
|
initOverlap();
|
|
|
|
} else {
|
|
|
|
initView();
|
|
|
|
}
|
2022-04-08 06:06:16 +02:00
|
|
|
}
|
2022-04-09 05:41:40 +02:00
|
|
|
} else if(mode === "explore"){
|
|
|
|
initExplore();
|
|
|
|
} else {
|
|
|
|
initView();
|
2017-04-06 23:09:37 +02:00
|
|
|
}
|
2022-04-06 10:30:04 +02:00
|
|
|
|
2017-04-10 17:57:13 +02:00
|
|
|
document.getElementById("loading").style.display = "none";
|
|
|
|
|
2017-04-08 05:57:12 +02:00
|
|
|
document.getElementById("zoomInButton").addEventListener("click", function(e){
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
/*if(zoomAnimationFrame){
|
2017-04-08 05:57:12 +02:00
|
|
|
window.cancelAnimationFrame(zoomAnimationFrame);
|
2017-04-10 12:25:04 +02:00
|
|
|
}*/
|
2017-04-08 05:57:12 +02:00
|
|
|
|
|
|
|
var x = container.clientWidth/2;
|
|
|
|
var y = container.clientHeight/2;
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2017-04-08 05:57:12 +02:00
|
|
|
initialPinchZoomOrigin = [
|
|
|
|
scaleZoomOrigin[0],
|
|
|
|
scaleZoomOrigin[1]
|
|
|
|
];
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2017-04-08 05:57:12 +02:00
|
|
|
initialPinchZoom = zoom;
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2017-04-08 05:57:12 +02:00
|
|
|
lastPosition = [x, y];
|
2017-04-10 12:25:04 +02:00
|
|
|
zoom = zoom * 2;
|
|
|
|
zoom = Math.max(minZoom, Math.min(maxZoom, zoom));
|
2017-04-08 05:57:12 +02:00
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
applyZoom(x, y, zoom);
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2017-04-05 00:53:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
document.getElementById("zoomOutButton").addEventListener("click", function(e){
|
2017-04-08 05:57:12 +02:00
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
/*if(zoomAnimationFrame){
|
2017-04-08 05:57:12 +02:00
|
|
|
window.cancelAnimationFrame(zoomAnimationFrame);
|
2017-04-10 12:25:04 +02:00
|
|
|
}*/
|
2017-04-08 05:57:12 +02:00
|
|
|
|
|
|
|
var x = container.clientWidth/2;
|
|
|
|
var y = container.clientHeight/2;
|
|
|
|
|
|
|
|
initialPinchZoomOrigin = [
|
|
|
|
scaleZoomOrigin[0],
|
|
|
|
scaleZoomOrigin[1]
|
|
|
|
];
|
|
|
|
|
|
|
|
initialPinchZoom = zoom;
|
|
|
|
|
|
|
|
lastPosition = [x, y];
|
2017-04-10 12:25:04 +02:00
|
|
|
zoom = zoom / 2;
|
|
|
|
zoom = Math.max(minZoom, Math.min(maxZoom, zoom));
|
2017-04-08 05:57:12 +02:00
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
applyZoom(x, y, zoom);
|
2017-04-05 00:53:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
document.getElementById("zoomResetButton").addEventListener("click", function(e){
|
|
|
|
zoom = 1;
|
2017-04-06 19:15:16 +02:00
|
|
|
zoomOrigin = [0, 0];
|
2017-04-10 15:16:34 +02:00
|
|
|
scaleZoomOrigin = [0, 0];
|
2017-04-09 02:08:35 +02:00
|
|
|
updateLines();
|
2017-04-05 00:53:10 +02:00
|
|
|
applyView();
|
|
|
|
});
|
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
container.addEventListener("dblclick", function(e){
|
2017-04-10 12:25:04 +02:00
|
|
|
/*if(zoomAnimationFrame){
|
2017-04-08 05:57:12 +02:00
|
|
|
window.cancelAnimationFrame(zoomAnimationFrame);
|
2017-04-10 12:25:04 +02:00
|
|
|
}*/
|
2017-04-08 05:57:12 +02:00
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
var x = e.clientX - container.offsetLeft;
|
|
|
|
var y = e.clientY - container.offsetTop;
|
2017-04-08 05:57:12 +02:00
|
|
|
|
|
|
|
initialPinchZoomOrigin = [
|
|
|
|
scaleZoomOrigin[0],
|
|
|
|
scaleZoomOrigin[1]
|
|
|
|
];
|
|
|
|
|
|
|
|
initialPinchZoom = zoom;
|
|
|
|
|
|
|
|
lastPosition = [x, y];
|
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
if(e.ctrlKey){
|
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
zoom = zoom / 2;
|
2017-04-04 01:24:46 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
zoom = zoom * 2;
|
2017-04-04 01:24:46 +02:00
|
|
|
}
|
2017-04-08 05:57:12 +02:00
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
zoom = Math.max(minZoom, Math.min(maxZoom, zoom));
|
|
|
|
applyZoom(x, y, zoom);
|
2017-04-08 05:57:12 +02:00
|
|
|
|
2017-04-06 19:29:54 +02:00
|
|
|
e.preventDefault();
|
2017-04-04 01:24:46 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
container.addEventListener("wheel", function(e){
|
2017-04-08 05:57:12 +02:00
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
/*if(zoomAnimationFrame){
|
2017-04-08 05:57:12 +02:00
|
|
|
window.cancelAnimationFrame(zoomAnimationFrame);
|
2017-04-10 12:25:04 +02:00
|
|
|
}*/
|
2017-04-08 05:57:12 +02:00
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
var x = e.clientX - container.offsetLeft;
|
|
|
|
var y = e.clientY - container.offsetTop;
|
2017-04-08 05:57:12 +02:00
|
|
|
|
|
|
|
initialPinchZoomOrigin = [
|
|
|
|
scaleZoomOrigin[0],
|
|
|
|
scaleZoomOrigin[1]
|
|
|
|
];
|
|
|
|
|
|
|
|
initialPinchZoom = zoom;
|
|
|
|
|
|
|
|
lastPosition = [x, y];
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2022-04-06 22:42:48 +02:00
|
|
|
// Check if we are zooming by pixels
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaMode
|
|
|
|
if (e.deltaMode === 0) {
|
|
|
|
// Scale the pixel delta by the current zoom factor
|
|
|
|
// We want to zoom faster when closer, and slower when further
|
|
|
|
// This creates a smoother experience
|
|
|
|
zoom -= e.deltaY * (0.001 * zoom);
|
|
|
|
} else {
|
|
|
|
if(e.deltaY > 0){
|
|
|
|
|
|
|
|
zoom = zoom / 2;
|
|
|
|
|
|
|
|
} else if(e.deltaY < 0){
|
|
|
|
|
|
|
|
zoom = zoom * 2;
|
|
|
|
}
|
2017-04-04 01:24:46 +02:00
|
|
|
}
|
2017-04-06 19:29:54 +02:00
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
zoom = Math.max(minZoom, Math.min(maxZoom, zoom));
|
|
|
|
applyZoom(x, y, zoom);
|
2017-04-08 05:57:12 +02:00
|
|
|
|
2017-04-06 19:29:54 +02:00
|
|
|
e.preventDefault();
|
2022-04-08 16:13:50 +02:00
|
|
|
}, {passive: true});
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2017-04-10 12:25:04 +02:00
|
|
|
/*function setDesiredZoom(x, y, target){
|
2017-04-08 05:57:12 +02:00
|
|
|
zoom = (zoom*2 + target)/3;
|
2017-04-10 12:25:04 +02:00
|
|
|
//console.log(zoom);
|
2017-04-08 05:57:12 +02:00
|
|
|
if(Math.abs(1 - zoom/target) <= 0.01){
|
|
|
|
zoom = target;
|
|
|
|
}
|
|
|
|
applyZoom(x, y, zoom);
|
|
|
|
if(zoom != target){
|
|
|
|
zoomAnimationFrame = window.requestAnimationFrame(function(){
|
|
|
|
setDesiredZoom(x, y, target);
|
|
|
|
});
|
|
|
|
}
|
2017-04-10 12:25:04 +02:00
|
|
|
}*/
|
2017-04-08 05:57:12 +02:00
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
container.addEventListener("mousedown", function(e){
|
2017-04-08 03:27:51 +02:00
|
|
|
mousedown(e.clientX, e.clientY);
|
2017-04-06 19:29:54 +02:00
|
|
|
e.preventDefault();
|
2017-04-04 01:24:46 +02:00
|
|
|
});
|
2017-04-08 03:27:51 +02:00
|
|
|
|
2017-04-10 23:56:35 +02:00
|
|
|
container.addEventListener("touchstart", function(e){
|
|
|
|
|
|
|
|
if(e.touches.length == 2){
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
touchstart(e);
|
|
|
|
|
2022-04-08 15:56:22 +02:00
|
|
|
}, {passive: true});
|
2017-04-08 03:27:51 +02:00
|
|
|
|
|
|
|
function mousedown(x, y){
|
|
|
|
lastPosition = [x, y];
|
|
|
|
dragging = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function touchstart(e){
|
|
|
|
|
|
|
|
if(e.touches.length == 1){
|
|
|
|
|
|
|
|
mousedown(e.touches[0].clientX, e.touches[0].clientY);
|
|
|
|
|
|
|
|
} else if(e.touches.length == 2){
|
|
|
|
|
|
|
|
initialPinchDistance = Math.sqrt(
|
|
|
|
Math.pow(e.touches[0].clientX - e.touches[1].clientX, 2)
|
|
|
|
+ Math.pow(e.touches[0].clientY - e.touches[1].clientY, 2)
|
|
|
|
);
|
|
|
|
|
|
|
|
initialPinchZoom = zoom;
|
|
|
|
initialPinchZoomOrigin = [
|
|
|
|
scaleZoomOrigin[0],
|
|
|
|
scaleZoomOrigin[1]
|
|
|
|
];
|
|
|
|
|
|
|
|
mousedown(
|
|
|
|
(e.touches[0].clientX + e.touches[1].clientX)/2,
|
|
|
|
(e.touches[0].clientY + e.touches[1].clientY)/2
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-04-04 01:24:46 +02:00
|
|
|
|
|
|
|
window.addEventListener("mousemove", function(e){
|
2017-04-09 02:08:35 +02:00
|
|
|
updateLines();
|
2017-04-08 03:27:51 +02:00
|
|
|
mousemove(e.clientX, e.clientY);
|
2017-04-10 16:09:56 +02:00
|
|
|
if(dragging){
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
2017-04-08 03:27:51 +02:00
|
|
|
});
|
2017-04-10 23:56:35 +02:00
|
|
|
window.addEventListener("touchmove", function(e){
|
|
|
|
|
|
|
|
if(e.touches.length == 2 || e.scale > 1){
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
touchmove(e);
|
|
|
|
|
|
|
|
},
|
|
|
|
{passive: false}
|
|
|
|
);
|
2017-04-08 03:27:51 +02:00
|
|
|
|
|
|
|
function mousemove(x, y){
|
2017-04-04 01:24:46 +02:00
|
|
|
if(dragging){
|
2017-04-08 03:27:51 +02:00
|
|
|
var deltaX = x - lastPosition[0];
|
|
|
|
var deltaY = y - lastPosition[1];
|
|
|
|
lastPosition = [x, y];
|
2017-04-04 01:24:46 +02:00
|
|
|
|
|
|
|
zoomOrigin[0] += deltaX;
|
|
|
|
zoomOrigin[1] += deltaY;
|
|
|
|
|
2017-04-08 03:27:51 +02:00
|
|
|
scaleZoomOrigin[0] += deltaX/zoom;
|
|
|
|
scaleZoomOrigin[1] += deltaY/zoom;
|
|
|
|
|
2017-04-10 16:28:22 +02:00
|
|
|
previousZoomOrigin = [zoomOrigin[0], zoomOrigin[1]];
|
|
|
|
previousScaleZoomOrigin = [scaleZoomOrigin[0], scaleZoomOrigin[1]];
|
|
|
|
|
2017-04-09 02:08:35 +02:00
|
|
|
updateLines();
|
2017-04-04 01:24:46 +02:00
|
|
|
applyView();
|
2017-04-08 03:27:51 +02:00
|
|
|
}
|
|
|
|
}
|
2017-04-06 19:29:54 +02:00
|
|
|
|
2017-04-08 03:27:51 +02:00
|
|
|
function touchmove(e){
|
2017-04-09 02:08:35 +02:00
|
|
|
|
|
|
|
updateLines();
|
2017-04-08 03:27:51 +02:00
|
|
|
|
|
|
|
if(e.touches.length == 1){
|
|
|
|
|
|
|
|
mousemove(e.touches[0].clientX, e.touches[0].clientY);
|
|
|
|
|
|
|
|
} else if(e.touches.length == 2){
|
|
|
|
|
|
|
|
var newPinchDistance = Math.sqrt(
|
|
|
|
Math.pow(e.touches[0].clientX - e.touches[1].clientX, 2)
|
|
|
|
+ Math.pow(e.touches[0].clientY - e.touches[1].clientY, 2)
|
|
|
|
);
|
|
|
|
|
|
|
|
zoom = initialPinchZoom * newPinchDistance / initialPinchDistance;
|
|
|
|
|
|
|
|
var x = (e.touches[0].clientX + e.touches[1].clientX)/2 - container.offsetLeft;
|
|
|
|
var y = (e.touches[0].clientY + e.touches[1].clientY)/2 - container.offsetTop;
|
|
|
|
|
2017-04-08 05:57:12 +02:00
|
|
|
applyZoom(x, y, zoom);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-04-08 03:27:51 +02:00
|
|
|
|
2017-04-08 05:57:12 +02:00
|
|
|
function applyZoom(x, y, zoom){
|
2017-04-08 03:27:51 +02:00
|
|
|
|
2017-04-08 05:57:12 +02:00
|
|
|
var deltaX = x - lastPosition[0];
|
|
|
|
var deltaY = y - lastPosition[1];
|
2017-04-08 03:27:51 +02:00
|
|
|
|
2017-04-08 05:57:12 +02:00
|
|
|
var pinchTranslateX = (x - container.clientWidth/2 - deltaX);
|
|
|
|
var pinchTranslateY = (y - container.clientHeight/2 - deltaY);
|
|
|
|
|
|
|
|
scaleZoomOrigin[0] = initialPinchZoomOrigin[0] + deltaX/zoom + pinchTranslateX/zoom - pinchTranslateX/initialPinchZoom;
|
|
|
|
scaleZoomOrigin[1] = initialPinchZoomOrigin[1] + deltaY/zoom + pinchTranslateY/zoom - pinchTranslateY/initialPinchZoom;
|
|
|
|
|
|
|
|
zoomOrigin[0] = scaleZoomOrigin[0]*zoom;
|
|
|
|
zoomOrigin[1] = scaleZoomOrigin[1]*zoom;
|
2017-04-08 03:27:51 +02:00
|
|
|
|
2017-04-08 05:57:12 +02:00
|
|
|
applyView();
|
|
|
|
updateLines();
|
2017-04-08 03:27:51 +02:00
|
|
|
}
|
2017-04-04 01:24:46 +02:00
|
|
|
|
|
|
|
window.addEventListener("mouseup", function(e){
|
2017-04-10 16:09:56 +02:00
|
|
|
if(dragging){
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
2017-04-08 03:27:51 +02:00
|
|
|
mouseup(e.clientX, e.clientY);
|
|
|
|
});
|
|
|
|
window.addEventListener("touchend", touchend);
|
|
|
|
|
|
|
|
function mouseup(x, y){
|
2017-04-04 01:24:46 +02:00
|
|
|
if(dragging){
|
|
|
|
dragging = false;
|
|
|
|
}
|
2017-04-08 03:27:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function touchend(e){
|
|
|
|
|
|
|
|
if(e.touches.length == 0){
|
|
|
|
|
|
|
|
mouseup();
|
|
|
|
|
|
|
|
} else if(e.touches.length == 1){
|
|
|
|
initialPinchZoom = zoom;
|
|
|
|
lastPosition = [e.touches[0].clientX, e.touches[0].clientY];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2017-04-06 19:15:16 +02:00
|
|
|
window.addEventListener("resize", function(){
|
|
|
|
//console.log(document.documentElement.clientWidth, document.documentElement.clientHeight);
|
|
|
|
|
|
|
|
applyView();
|
|
|
|
});
|
2017-04-04 01:24:46 +02:00
|
|
|
|
|
|
|
}
|