{"version":3,"file":"uppsala.arcgismap.behaviorconfigurator.min.js","names":["define","$","init","mapView","warningDivSelector","warningTextElementSelector","popup","collapseEnabled","ui","move","ctrlPressed","document","keydown","e","key","hideWarning","keyup","on","warningDiv","getElementById","warningTextElement","addEventListener","preventDefault","touches","length","event","warnUser","stopPropagation","keyPressed","indexOf","pointers","Map","timeout","warning","classList","add","style","display","innerHTML","showWarning","window","clearTimeout","setTimeout","remove","pointerType","set","pointerId","x","y","delete","size","Math","sqrt","pow","get","getNavigation","mouseWheelZoomEnabled","browserTouchPanEnabled"],"sources":["arcgis/uppsala.arcgismap.behaviorconfigurator.js"],"mappings":"AAKAA,OAAO,CAAC,WAAW,SAAUC,GA8IzB,MA7ImB,CAEfC,KAAM,SACFC,EACAC,EAAqB,iBACrBC,EAA6B,mCAG7BF,EAAQG,MAAMC,iBAAkB,EAGhCJ,EAAQK,GAAGC,KAAK,OAAQ,gBAIxBC,aAAc,EACdT,EAAEU,UAAUC,SAAQ,SAAUC,GACZ,YAAVA,EAAEC,MACFJ,aAAc,GAEJ,WAAVG,EAAEC,KACFC,GAER,IACAd,EAAEU,UAAUK,OAAM,SAAUH,GACV,YAAVA,EAAEC,MACFJ,aAAc,EAEtB,IAEAT,EAAEU,UAAUM,GAAG,QAASF,GAGxB,IAAIG,EAAaP,SAASQ,eAAef,GACrCgB,EAAqBT,SAASQ,eAAed,GACjDa,EAAWG,iBAAiB,SAAS,SAAUR,GACvCH,cACAK,IACAF,EAAES,iBAEV,IAEAJ,EAAWG,iBAAiB,cAAc,SAAUR,GAC5CA,EAAEU,QAAQC,OAAS,GACnBT,GAER,IAGAZ,EAAQc,GAAG,UAAU,SAAUQ,GAEP,YADFA,EAAMX,MAEpBJ,aAAc,EAEtB,IACAP,EAAQc,GAAG,eAAe,SAAUJ,IACZ,IAAhBH,cACAgB,EAAS,mEACTb,EAAEc,kBAEV,IAEAxB,EAAQc,GAAG,YAAY,SAAUQ,GAC7B,IAAIG,EAAaH,EAAMX,IAEJ,YAAfc,IACAlB,aAAc,IAK0B,IADvB,CAAC,UAAW,aACdmB,QAAQD,IACvBH,EAAMH,gBAEd,IAGA,MAAMQ,EAAW,IAAIC,IAkCrB,IAAIC,EACJ,SAASN,EAASO,IAclB,SAAqBA,GACjBf,EAAWgB,UAAUC,IAAI,oBACzBf,EAAmBgB,MAAMC,QAAU,QACnCjB,EAAmBkB,UAAYL,CACnC,CAjBIM,CAAYN,GACRD,GACAQ,OAAOC,aAAaT,GAExBA,EAAUQ,OAAOE,YAAW,WACxB3B,GACJ,GAAG,IACP,CAEA,SAASA,IACLG,EAAWgB,UAAUS,OAAO,oBAC5BvB,EAAmBgB,MAAMC,QAAU,MACvC,CA/CAlC,EAAQc,GAAG,gBAAiBQ,IACE,UAAtBA,EAAMmB,aAGVd,EAASe,IAAIpB,EAAMqB,UAAW,CAAEC,EAAGtB,EAAMsB,EAAGC,EAAGvB,EAAMuB,GAAI,IAG7D7C,EAAQc,GAAG,CAAC,aAAc,kBAAmBQ,IACf,UAAtBA,EAAMmB,aAGVd,EAASmB,OAAOxB,EAAMqB,UAAU,IAGpC3C,EAAQc,GAAG,gBAAiBQ,IACxB,GAA0B,UAAtBA,EAAMmB,YACN,OAGJ,GAAsB,IAAlBd,EAASoB,KACT,OAEaC,KAAKC,KAClBD,KAAKE,IAAI5B,EAAMsB,EAAIjB,EAASwB,IAAI7B,EAAMqB,WAAWC,EAAG,GACpDI,KAAKE,IAAI5B,EAAMuB,EAAIlB,EAASwB,IAAI7B,EAAMqB,WAAWE,EAAG,IAEzC,IAGftB,EAAS,mDAAmD,GAwBpE,EAEA6B,cAAe,WACX,MAAO,CACHC,uBAAuB,EACvBC,wBAAwB,EAEhC,EAIR","ignoreList":[],"sourcesContent":["/** The idea for this abstraction is to encapsulate the behavior of arcgis maps, \n * so that it behaves the same way on all of our maps on different pages.\n * Inspired by https://developers.arcgis.com/javascript/latest/sample-code/view-disable-zoom/ \n * */\n\ndefine([\"jquery\"], function ($) {\n var configurator = {\n\n init: function init(\n mapView,\n warningDivSelector = \"js-grayoverlay\",\n warningTextElementSelector = \"js-mapoverlay--zoominstructions\") {\n\n //popup collapse function not enabled\n mapView.popup.collapseEnabled = false\n\n //postion zoom buttons to bottom right\n mapView.ui.move(\"zoom\", \"bottom-right\");\n\n // determin when ctrl is pressed and adjust how the map behaves in regards to zoom.\n // if ctrl+mousewheel, allow zoom in map. else display overlay with msg that tells the user how to zoom\n ctrlPressed = false;\n $(document).keydown(function (e) {\n if (e.key === \"Control\") {\n ctrlPressed = true;\n }\n if (e.key === \"Escape\") {\n hideWarning();\n }\n });\n $(document).keyup(function (e) {\n if (e.key === \"Control\") {\n ctrlPressed = false;\n }\n });\n\n $(document).on('click', hideWarning);\n\n // if the overlay is visible when mousewheel scrolling, we need to prevent default otherwise the user starts to zoom the browser window instead.\n var warningDiv = document.getElementById(warningDivSelector);\n var warningTextElement = document.getElementById(warningTextElementSelector);\n warningDiv.addEventListener('wheel', function (e) {\n if (ctrlPressed) {\n hideWarning();\n e.preventDefault();\n }\n });\n\n warningDiv.addEventListener('touchstart', function (e) {\n if (e.touches.length > 1) {\n hideWarning();\n }\n });\n\n // sometimes the keypress does not bubble up to body so we also listen for keypresses on map \n mapView.on(\"key-up\", function (event) {\n var keyReleased = event.key;\n if (keyReleased === \"Control\") {\n ctrlPressed = false;\n }\n });\n mapView.on(\"mouse-wheel\", function (e) {\n if (ctrlPressed === false) {\n warnUser(\"Använd ctrl + scroll eller zoomknapparna i kartan för att zooma\");\n e.stopPropagation();\n }\n });\n\n mapView.on(\"key-down\", function (event) {\n var keyPressed = event.key;\n // allow scroll with mouse wheel if ctrl is pressed.\n if (keyPressed === \"Control\") {\n ctrlPressed = true;\n }\n\n // prevent page scrolling if using arrow keys to scroll the map\n var prohibitedKeys = [\"ArrowUp\", \"ArrowDown\"];\n if (prohibitedKeys.indexOf(keyPressed) !== -1) {\n event.preventDefault();\n }\n });\n\n // Trap attempted single touch panning.\n const pointers = new Map(); // javascript map\n mapView.on(\"pointer-down\", (event) => {\n if (event.pointerType !== \"touch\") {\n return;\n }\n pointers.set(event.pointerId, { x: event.x, y: event.y });\n });\n\n mapView.on([\"pointer-up\", \"pointer-leave\"], (event) => {\n if (event.pointerType !== \"touch\") {\n return;\n }\n pointers.delete(event.pointerId);\n });\n\n mapView.on(\"pointer-move\", (event) => {\n if (event.pointerType !== \"touch\") {\n return;\n }\n\n if (pointers.size !== 1) {\n return;\n }\n const distance = Math.sqrt(\n Math.pow(event.x - pointers.get(event.pointerId).x, 2) +\n Math.pow(event.y - pointers.get(event.pointerId).y, 2)\n );\n if (distance < 20) {\n return;\n }\n warnUser(\"Använd två fingrar för att flytta runt i kartan.\");\n });\n\n // Display a warning.\n var timeout;\n function warnUser(warning) {\n showWarning(warning);\n if (timeout) {\n window.clearTimeout(timeout);\n }\n timeout = window.setTimeout(function () {\n hideWarning();\n }, 2000);\n }\n\n function hideWarning() {\n warningDiv.classList.remove(\"grayoverlay-show\");\n warningTextElement.style.display = \"none\";\n }\n function showWarning(warning) {\n warningDiv.classList.add(\"grayoverlay-show\");\n warningTextElement.style.display = \"block\";\n warningTextElement.innerHTML = warning;\n }\n },\n\n getNavigation: function () {\n return {\n mouseWheelZoomEnabled: true,\n browserTouchPanEnabled: false\n }\n }\n };\n\n return configurator;\n});\n\n"]}