<krpano>

	<!-- iphone landscape fullscreen helper -->
	<include url="%VIEWER%/plugins/iphone_fullscreen_swipe.xml" devices="iphone" />

	<!-- disable safearea to use the full-screen-area on 'notch'-iPhones -->
	<display safearea="off" />


	<!-- the map as embedded krpano viewer -->
	<layer name="map" keep="true"
		type="krpano"
		bgalpha="0.5"
		bgroundedge.normal="17"
		maskchildren="true"
		bgshadow="0 0 20 0x000000 0.5"
		align="lefttop" x="2%" y="2%" width="20%" height="30%"
		parent.mobile="OVERLAY"
		onloaded="load_map_viewer();"
		state="visible"
		onclick.normal="tween(x|y|width|height, calc(parseint(width) LT 50 ? '5%|5%|90%|90%' : '2%|2%|20%|30%'),1.0, default);"
		/>


	<!-- for mobile devices use a different layout with a splitscreen -->

	<layer name="fsbutton" keep="true" devices="mobile"
		type="container"
		align="rightbottom" x="12" y="12" width="40" height="40"
		bgalpha="0.5" bgroundedge="15" bgcapture="true"
		onclick="mobile_toggle_map_size();"
	>
		<layer name="fsicon" enabled="false"
			url="fs.png" crop="0|0|64|64"
			align="center" width="32" height="32"
			/>
	</layer>


	<!-- show layers (the map) outside the area -->
	<area cliplayers="false" devices="mobile" />

	<events name="mobile_layout" keep="true" devices="mobile"
		onresize="mobile_layout()"
		/>

	<action name="mobile_toggle_map_size" type="Javascript"><![CDATA[

		var is_landscape = krpano.stagewidth > krpano.stageheight;

		var maplayer = krpano.get("layer[map]");
		if (maplayer)
		{
			var curstate = maplayer.state;

			if (curstate == "visible" || curstate == "zoomin")
			{
				krpano.set("layer[fsicon].crop", "64|0|64|64");
				maplayer.state = "zoomout";
				krpano.actions.tween(is_landscape ? "area.width|layer[map].x" : "area.height|layer[map].y", "100%|-40%", 0.5, "default", function()
				{
					maplayer.state = "hidden";
					maplayer.visible = false;
				});
			}
			else if (curstate == "hidden" || curstate == "zoomout")
			{
				krpano.set("layer[fsicon].crop", "0|0|64|64");
				maplayer.state = "zoomin";
				maplayer.visible = true;
				krpano.actions.tween(is_landscape ? "area.width|layer[map].x" : "area.height|layer[map].y", "60%|0%", 0.5, "default", function()
				{
					maplayer.state = "visible";
				});
			}


		}
	]]></action>


	<action name="mobile_layout" type="Javascript"><![CDATA[

		var maplayer = krpano.get("layer[map]");
		if (maplayer)
		{
			var is_landscape = krpano.stagewidth > krpano.stageheight;
			var state = maplayer.state;

			if (is_landscape)	// landscape layout
			{
				krpano.area.width = state == "visible" ? "60%" : state == "hidden" ? "100%" : krpano.area.width;
				krpano.area.height = "100%";
				maplayer.align = "righttop";
				maplayer.x = state == "visible" ? "0%" : state == "hidden" ? "-40%" : maplayer.x;
				maplayer.y = 0;
				maplayer.width = "40%";
				maplayer.height = "100%";
			}
			else	// portrait layout
			{
				krpano.area.width = "100%";
				krpano.area.height = state == "visible" ? "60%" : state == "hidden" ? "100%" : krpano.area.height;
				maplayer.align = "leftbottom";
				maplayer.x = 0;
				maplayer.y = state == "visible" ? "0%" : state == "hidden" ? "-40%" : maplayer.y;
				maplayer.height = "40%";
				maplayer.width = "100%";
			}
		}

	]]></action>


	<action name="load_map_viewer" type="Javascript"><![CDATA[

		// get the krpano api
		map = caller.krpano;

		// lat/lng conversion functions
		function lat_to_atv(lat){ return ((1.0 - Math.asinh(Math.tan(lat * Math.PI/180)) / Math.PI) / 2.0 - 0.5) * map.image.hfov; }
		function atv_to_lat(atv){ return Math.atan(Math.sinh(Math.PI * (1.0 - ((atv / map.image.hfov) + 0.5) * 2.0))) * 180.0/Math.PI; }
		function lng_to_ath(lng){ return lng / 360.0 * map.image.hfov; }
		function ath_to_lng(ath){ return ath / map.image.hfov * 360.0; }

		// parse OpenStreetMap tile urls
		map.customParseTilePath = function(path, cubeside, level, h, v, stereo, image)
		{
			return path.split("{s}").join("abc"[(Math.random()*3)|0]).split("{x}").join(1*h-1).split("{y}").join(1*v-1).split("{z}").join(1*level);
		}

		// add the 'light' post-processing plugin to make the map satellite image a bit brighter
		var pp = map.addplugin();
		pp.url = "%VIEWER%/plugins/pp_light.js";
		pp.keep = true;
		pp.phase = 1;
		pp.shadows = 7;

		// setup the image element for loading the map tiles
		map.image.reset();
		map.image.hfov = 0.001;
		map.image.flat =
		{
			// Satellite images from NASA via ESRI, Maxar, Microsoft
			url : "https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}.jpg",
			multires : "256,512x512,1024x1024,2048x2048,4096x4096,8192x8192,16384x16384,32768x32768,65536x65536,131072x131072,262144x262144,524288x524288,1048576x1048576,2097152x2097152,4194304x4194304,8388608x8388608,16777216x16777216,33554432x33554432"
		}

		// and load it
		map.actions.loadpanoimage();

		// view and control setup
		map.view.fov = 0.01;
		map.view.fovmax = 1;
		map.view.maxpixelzoom = 4.0;
		map.control.zoomtocursor = true;
		map.control.zoomoutcursor = false;

		// add map attribution layer
		var l = map.addlayer("mapattribution");
		l.type = "text";
		l.bgalpha = 0.8;
		l.bgroundedge = "7 0 0 0";
		l.bgborder = "1 0xFFFFFF 0.8";
		l.html = "&copy; [a href='http://goto.arcgisonline.com/maps/World_Street_Map' target='_blank']ArcGIS World Imagery, Maxar, Microsoft[/a]&nbsp;";
		l.align = "rightbottom";

		// add zoom-out / see-all-hotspots button
		var seeallbutton = map.addlayer("seeall");
		seeallbutton.type = "text";
		seeallbutton.bgalpha = 0.8;
		seeallbutton.bgroundedge = "0 0 0 7";
		seeallbutton.bgborder = "1 0xFFFFFF 0.8";
		seeallbutton.html = "➦";
		seeallbutton.css = "font-size:20px;";
		seeallbutton.padding = "4 8";
		seeallbutton.align = "righttop";
		seeallbutton.onclick = see_all_hotspots;

		// add hotspots
		var activespot = map.addhotspot();
		activespot.url = "%CURRENTXML%/vtourskin_mapspotactive.png";
		activespot.edge = "bottom";
		activespot.x = -4;
		activespot.y = -7;
		activespot.scale = map.device.mobile ? 0.5 : map.device.tablet ? 0.4 : 0.3;
		activespot.zorder = 2;
		activespot.visible = false;
		activespot.enabled = false;

		// automatically generate the hotspots based on the <scene> lat/lng information
		var range = [1,-1,1,-1];
		krpano.scene.getArray().forEach( function(scene)
		{
			var lng = Number(scene.lng);
			var lat = Number(scene.lat);

			if (!isNaN(lng) && !isNaN(lat))
			{
				// add a map-spot
				var spot = map.addhotspot();
				spot.url = "%CURRENTXML%/vtourskin_mapspot.png";
				spot.edge = activespot.edge;
				spot.x = activespot.x;
				spot.y = activespot.y;
				spot.scale = activespot.scale;
				spot.zorder = 1;
				spot.ath = lng_to_ath(lng);
				spot.atv = lat_to_atv(lat);
				spot.capture = false;

				spot.onclick = function()
				{
					activespot.ath = spot.ath;
					activespot.atv = spot.atv;
					activespot.visible = true;

					krpano.actions.loadscene(scene.name,null,'MERGE','BLEND(0.5)');

					map.actions.lookto(spot.ath, spot.atv, 0.00000001, 'tween(default,1.0)' );
				};

				if (spot.ath < range[0]) range[0] = spot.ath;
				if (spot.ath > range[1]) range[1] = spot.ath;
				if (spot.atv < range[2]) range[2] = spot.atv;
				if (spot.atv > range[3]) range[3] = spot.atv;

				if (scene.name == krpano.xml.scene)
				{
					activespot.ath = spot.ath;
					activespot.atv = spot.atv;
					activespot.visible = true;
				}
			}
		});

		// select the view area and zoom to see all hotspots
		map.view.hlookat = (range[0] + range[1]) / 2;
		map.view.vlookat = (range[2] + range[3]) / 2;
		map.view.fovtype = "VFOV";
		map.view.fov = 2 * Math.max(range[1] - range[0], range[3] - range[2]);

		function see_all_hotspots()
		{
			map.actions.lookto((range[0] + range[1]) / 2, (range[2] + range[3]) / 2, 1.5 * Math.max(range[1] - range[0], range[3] - range[2]),'tween(default,1)');
		};

		// custom contextmenu
		map.contextmenu.fullscreen = false;
		map.contextmenu.versioninfo = false;

	]]></action>


	<!-- use the panos/scenes from the corfu-demotour example -->

	<scene name="scene_achilleion-hof-unten" autoload="true" title="Achilleion - Garden" onstart="" thumburl="../demotour-corfu/panos/achilleion-hof-unten.tiles/thumb.jpg" lat="39.563340" lng="19.904324" heading="0.0">

		<view hlookat="-1" vlookat="11" fovtype="DFOV" fov="120" fovmin="70" fovmax="140" limitview="auto" />

		<preview url="../demotour-corfu/panos/achilleion-hof-unten.tiles/preview.jpg" />

		<image>
			<cube url="../demotour-corfu/panos/achilleion-hof-unten.tiles/mobile_%s.jpg" if="browser.domain != 'krpano.com'" />
			<cube url="https://krpano.com/tours/corfu/panos/achilleion-hof-unten.tiles/%s/l%l/%v/l%l_%s_%v_%h.jpg" multires="512,768,1536,2816" if="browser.domain == 'krpano.com'" />
		</image>

	</scene>

	<scene name="scene_canaldemure5" title="Canal d&#180;Amour 2" onstart="" thumburl="../demotour-corfu/panos/canaldemure5.tiles/thumb.jpg" lat="39.796233694" lng="19.70181763" heading="0.0">

		<view hlookat="-118" vlookat="4" fovtype="MFOV" fov="132" fovmin="70" fovmax="140" limitview="auto" />

		<preview url="../demotour-corfu/panos/canaldemure5.tiles/preview.jpg" />

		<image>
			<cube url="../demotour-corfu/panos/canaldemure5.tiles/mobile_%s.jpg" if="browser.domain != 'krpano.com'" />
			<cube url="https://krpano.com/tours/corfu/panos/canaldemure5.tiles/%s/l%l/%v/l%l_%s_%v_%h.jpg" multires="512,768,1536,2816" if="browser.domain == 'krpano.com'" />
		</image>

	</scene>

	<scene name="scene_kalamaki-strand" title="Kalamaki Beach 2" onstart="" thumburl="../demotour-corfu/panos/kalamaki-strand.tiles/thumb.jpg" lat="39.7989065" lng="19.8847845" heading="0.0">

		<view hlookat="18" vlookat="1" fovtype="MFOV" fov="120" fovmin="70" fovmax="140" limitview="auto" />

		<preview url="../demotour-corfu/panos/kalamaki-strand.tiles/preview.jpg" />

		<image>
			<cube url="../demotour-corfu/panos/kalamaki-strand.tiles/mobile_%s.jpg" if="browser.domain != 'krpano.com'" />
			<cube url="https://krpano.com/tours/corfu/panos/kalamaki-strand.tiles/%s/l%l/%v/l%l_%s_%v_%h.jpg" multires="512,1152,2176" if="browser.domain == 'krpano.com'" />
		</image>

	</scene>

	<scene name="scene_kassiopi-felsen" title="Kassiopi Beach 2" onstart="" thumburl="../demotour-corfu/panos/kassiopi-felsen.tiles/thumb.jpg" lat="39.79083003" lng="19.92507129" heading="0.0">

		<view hlookat="-4" vlookat="18" fovtype="MFOV" fov="110" fovmin="70" fovmax="140" limitview="auto" />

		<preview url="../demotour-corfu/panos/kassiopi-felsen.tiles/preview.jpg" />

		<image>
			<cube url="../demotour-corfu/panos/kassiopi-felsen.tiles/mobile_%s.jpg" if="browser.domain != 'krpano.com'" />
			<cube url="https://krpano.com/tours/corfu/panos/kassiopi-felsen.tiles/%s/l%l/%v/l%l_%s_%v_%h.jpg" multires="512,768,1536,2816" if="browser.domain == 'krpano.com'" />
		</image>

	</scene>

	<scene name="scene_korfu-stadt-alte-festung-ganz-oben" title="Corfu Old Fortress 1" onstart="" thumburl="../demotour-corfu/panos/korfu-stadt-alte-festung-ganz-oben.tiles/thumb.jpg" lat="39.62343265" lng="19.9288907" heading="0.0">

		<view hlookat="123" vlookat="17" fovtype="MFOV" fov="133" fovmin="70" fovmax="140" limitview="auto" />

		<preview url="../demotour-corfu/panos/korfu-stadt-alte-festung-ganz-oben.tiles/preview.jpg" />

		<image>
			<cube url="../demotour-corfu/panos/korfu-stadt-alte-festung-ganz-oben.tiles/mobile_%s.jpg" if="browser.domain != 'krpano.com'" />
			<cube url="https://krpano.com/tours/corfu/panos/korfu-stadt-alte-festung-ganz-oben.tiles/%s/l%l/%v/l%l_%s_%v_%h.jpg" multires="512,768,1536,2816" if="browser.domain == 'krpano.com'" />
		</image>

	</scene>

	<scene name="scene_pantokrator-antenne" title="Mount Pantokrator - Communication Station" onstart="" thumburl="../demotour-corfu/panos/pantokrator-antenne.tiles/thumb.jpg" lat="39.74802500" lng="19.87182944" heading="0.0">

		<view hlookat="-3" vlookat="4" fovtype="MFOV" fov="130" fovmin="70" fovmax="140" limitview="auto" />

		<preview url="../demotour-corfu/panos/pantokrator-antenne.tiles/preview.jpg" />

		<image>
			<cube url="../demotour-corfu/panos/pantokrator-antenne.tiles/mobile_%s.jpg" if="browser.domain != 'krpano.com'" />
			<cube url="https://krpano.com/tours/corfu/panos/pantokrator-antenne.tiles/%s/l%l/%v/l%l_%s_%v_%h.jpg" multires="512,768,1536,2816" if="browser.domain == 'krpano.com'" />
		</image>

	</scene>

	<scene name="scene_pantokrator-kloster" title="Mount Pantokrator - Monastery" onstart="" thumburl="../demotour-corfu/panos/pantokrator-kloster.tiles/thumb.jpg" lat="39.74836333" lng="19.87214583" heading="0.0">

		<view hlookat="0" vlookat="0" fovtype="MFOV" fov="120" fovmin="70" fovmax="140" limitview="auto" />

		<preview url="../demotour-corfu/panos/pantokrator-kloster.tiles/preview.jpg" />

		<image>
			<cube url="../demotour-corfu/panos/pantokrator-kloster.tiles/mobile_%s.jpg" if="browser.domain != 'krpano.com'" />
			<cube url="https://krpano.com/tours/corfu/panos/pantokrator-kloster.tiles/%s/l%l/%v/l%l_%s_%v_%h.jpg" multires="512,768,1536,2816" if="browser.domain == 'krpano.com'" />
		</image>

	</scene>

</krpano>
