{"id":560,"date":"2019-08-12T16:10:18","date_gmt":"2019-08-12T15:10:18","guid":{"rendered":"https:\/\/www.maxcanvas.org\/?page_id=560"},"modified":"2026-10-25T22:13:26","modified_gmt":"2026-10-25T22:13:26","slug":"panorama-viewer","status":"publish","type":"page","link":"https:\/\/www.maxcanvas.org\/?page_id=560","title":{"rendered":"Panorama Viewer"},"content":{"rendered":"\n<p>Got bored waiting for FaceBook to add an easy &#8220;Panorama Picture Viewer&#8221; to their Application.<br>So to see the pictures myself, I made a small tool for it using MaxCanvas.  F12 and dig around to see the code if you need it. <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Click &#8220;Next&#8221; and &#8220;Prev&#8221; to scroll through the images<\/li><li>Hover Over the &#8220;Pan&#8221; buttons to &#8230;. well &#8230; &#8220;pan&#8221; \ud83d\ude0e<\/li><li>Hover Over the image for a zoom box<\/li><\/ul>\n\n\n\n<figure><iframe loading=\"lazy\" width=\"1010px\" height=\"810px\" scrolling=\"no\" src=\"https:\/\/www.maxcanvas.org\/MaxCanvas\/Examples\/MC%20PanoramaViewer.html\"><\/iframe><\/figure>\n\n\n\n<p>N.B.  as I do not want to re-distribute the images, this is not in the MC examples package and the below is minimally commented ;p<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Code<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ MaxCanvas Panorama Viewer\n\/\/ Simple Panorama viewer, since facebook has not provided one\n\/\/\n\/\/ Required to drag MC.js into Intellisense\n\/\/ thanks to https:\/\/visualstudiomagazine.com\/blogs\/tool-tracker\/2018\/07\/use-javascript-code.aspx (Dec 2018)\n\/\/\/ &lt;reference path=\"MC.js\" \/>\n\n\/\/ Gamecode is wrapped in .. window.onload = (function () { -- ALL CODE HERE --}); .. so game will start AFTER everything else is loaded\n\nwindow.onload = (function() {\n\n\/\/ AQUIRE HTML DOM CANVAS REFERENCE\n\/\/  HTML has to have a HTML5 canvas element tagged as \"canvas\"\nvar c=document.getElementById(\"canvas\");\n\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/ INITIALISE MC Engine \/\/\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\nMC.init(c);\n\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/ END OF Initialisation \/\/\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/-----------------------------------------------------------------------------\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/ VARIABLE DECLARATION \/\/\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\nvar PV = {  \/\/ object to hold everything (and so avoid polluting global namespace)\n    \/\/ Variables\n    Pan1 : new MC.Picture(),\n    T : new MC.Point(0, 0),\n    B : new MC.Point(0.5, 1),\n    set : false,\n    mod : 0,\n    maxMod: 0,\n    datum: new MC.Point(MC.canvas.midX - 300, MC.canvas.midY - 300),\n    delta : 0.001,\n    current: 0,\n    path: \"..\/Assets\/images\/panoramas\/\",\n    files: [\n        [\"Dio01.JPG\", \"Greek Style Diorama\"],\n        [\"Dio02.JPG\",\" Prada Wallpaper\"],\n        [\"P1.JPG\", \"1. Busy Pompeii Street 2019\"],\n        [\"At1.JPG\", \"2. View from Athens Apartment\"],\n        [\"Sa1.JPG\", \"3. Fira Harbour (Santorini)\"],\n        [\"Sa2.JPG\", \"4. Santorini Caldera\"],\n        [\"K1.JPG\", \"5. Kotor from half way up the walls\"],\n        [\"M1.JPG\", \"6. Messina\"],\n        [\"M2.JPG\", \"7. Messina\"],\n        [\"M3.JPG\", \"8. Messina\"],\n        [\"Sal1.JPG\", \"9. Salerno Harbour\"],\n        [\"A1.JPG\", \"10. Appledore &amp; Crow Point from Instow Beach\"],\n        [\"A2.JPG\", \"11. Estuary from Crow Point\"],\n        [\"A3.JPG\", \"12. Braunton Burrows\"],\n        [\"A4.JPG\", \"13. Tapeley House Monument View\"],\n        [\"A5.JPG\", \"14. Appledore from Instow\"]\n    ],\n    \/\/ a \"hit sprite\" to see if zoom is required - will not be rendered\n    win: new MC.Sprite({\n        type: \"rect\",\n        size1: 533,\n        size2: 533\n    }),\n\n    \/\/ GUI setup\n    GUI : new MC.GUI(),\n    Title : new MC.ConBox({ width: 600,\n        height: 60,\n        text: \"Title\",\n        pos: new MC.Point(MC.canvas.midX, 50)\n    }),\n    Prev : new MC.ConBox({\n        width: 160,\n        height: 60,\n        text: \"&lt; Prev\",\n        pos: new MC.Point(90, 50),\n        onClick: function () { PV.change(-1) }\n\n    }),\n    Next : new MC.ConBox({\n        width: 160,\n        height: 60,\n        text: \"Next >\",\n        pos: new MC.Point(MC.canvas.right - 90, 50),\n        onClick: function () { PV.change(1) }\n    }),\n    Left : new MC.ConBox({\n        width: 160,\n        height: 60,\n        text: \"&lt;&lt; pan LEFT (a)\",\n        pos: new MC.Point(MC.canvas.midX - 90,MC.canvas.bottom - 50)\n    }),\n    Right : new MC.ConBox({\n        width: 160,\n        height: 60,\n        text: \"(d) pan RIGHT >>\",\n        pos: new MC.Point(MC.canvas.midX + 90, MC.canvas.bottom - 50)\n    }),\n\n    \/\/ Methods\n    setUp : function () {\n        PV.Pan1 = new MC.Picture(PV.path + PV.files[PV.current][0]);\n        PV.Title.text = \"Loading\";\n        PV.set = false;\n        PV.mod = 0;\n    },\n    change : function (direction) { \/\/ only use 1 and -1 for these calls \n        if (direction === 1 || direction === -1) {\n            PV.current += direction;\n            if (PV.current >= PV.files.length) {\n                PV.current = 0;\n            }\n            if (PV.current &lt; 0) {\n                PV.current = PV.files.length - 1;\n            }\n            PV.setUp();\n        }\n    }\n}; \n\n\nPV.GUI.push(PV.Prev, PV.Next, PV.Left, PV.Right);  \/\/ Add the ConBoxes to the GUI\n    \nMC.mouse.onClickL = function () { \/\/ configure MC.game so it checks the GUI upon Left click down \n        PV.GUI.click();\n    };    \n    \n\n\n\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/ END OF declarations  \/\/\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/-----------------------------------------------------------------------------\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/      GAME LOOP       \/\/\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\n    \/\/ Set up for the first time\n    PV.setUp();\n\n\/\/ first call, request subsequently made within\ngameLoop();\n\nfunction gameLoop() {\n    \/\/ ESSENTIAL MAINTAINANCE\n    requestAnimationFrame(gameLoop);    \/\/ Required so the PC will automatically call the gameLoop again when (1) the screen is ready and (2) the CPU has finished any previous frame calculations\n    MC.game.update();                   \/\/ Essential to update MC.game to ensure MC.game.deltaTime is available\n    \n    \/\/ PHYSICS UPDATE LOOP\n    \/\/ Check if Image freshly loaded\n    if (!PV.set &amp;&amp; PV.Pan1.loaded)\n    {\n        PV.B.set(600 \/ PV.Pan1.width, 1);\n        PV.maxMod = 1 - PV.B.x;\n        PV.Title.text = PV.files[PV.current][1];\n        PV.set = true;\n    }\n    \/\/ Navigate as required\n    if (MC.keys.a.down || MC.keys.leftArrow.down || PV.Left.hover) PV.mod = MC.maths.maxOf(0, PV.mod - PV.delta);\n    else if (MC.keys.d.down || MC.keys.rightArrow.down || PV.Right.hover) PV.mod = MC.maths.minOf(PV.maxMod, PV.mod + PV.delta);\n\n    \/\/ NON-PHYSICS UPDATES\n    PV.GUI.update();    \/\/ calls update on all ConBoxes in the GUI.  Required so they can change colour if the mouse \"hovers\" over them\n\n    \/\/ RENDER\n    \/\/ Stage 1.  Clear the canvas\n    MC.draw.clearCanvas(\"Black\");\n    \n    \/\/ Stage 2.  Render\n    PV.Pan1.render(new MC.Point(MC.canvas.midX, MC.canvas.midY), 0, 600, 600, PV.T.clone().add(PV.mod, 0), PV.B.clone().add(PV.mod, 0));\n\n    \/\/ Stage 3.  Render GUI\n    PV.Title.render(); \/\/ not updated, so no hoverover colour change\n    PV.GUI.render();\n\n    \/\/ Render zoom box (if required)\n    if (PV.win.hit(MC.game.mouse)) {\n        var centre = MC.mouse.pos.clone().minus(PV.datum).div(600); \/\/ 0-1 ratio of where mouse is in picture screen\n        var picpos = new MC.Point(PV.mod + (centre.x * PV.B.x), centre.y); \/\/ 0-1 ratio of where on the ACTUAL picture it is\n        var newmod = new MC.Point(0.05 * PV.B.x, 0.05);\n        var NT = picpos.clone().minus(newmod);\n        var NB = picpos.clone().add(newmod);\n        MC.draw.rect(MC.mouse.pos, 202, 202, 0, \"Orange\");\n        PV.Pan1.render(MC.game.mouse, 0, 200, 200, NT, NB);\n    };\n}\n\n}); \/\/ EoF\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Got bored waiting for FaceBook to add an easy &#8220;Panorama Picture Viewer&#8221; to their Application.So to see the pictures myself, I made a small tool for it using MaxCanvas. F12 and dig around to see the code if you need it. Click &#8220;Next&#8221; and &#8220;Prev&#8221; to scroll through the images Hover Over the &#8220;Pan&#8221; buttons [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_oct_exclude_from_cache":false,"footnotes":""},"class_list":["post-560","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/www.maxcanvas.org\/index.php?rest_route=\/wp\/v2\/pages\/560","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.maxcanvas.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.maxcanvas.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.maxcanvas.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.maxcanvas.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=560"}],"version-history":[{"count":8,"href":"https:\/\/www.maxcanvas.org\/index.php?rest_route=\/wp\/v2\/pages\/560\/revisions"}],"predecessor-version":[{"id":604,"href":"https:\/\/www.maxcanvas.org\/index.php?rest_route=\/wp\/v2\/pages\/560\/revisions\/604"}],"wp:attachment":[{"href":"https:\/\/www.maxcanvas.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=560"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}