{"version":3,"file":"uppsala.arcgismap.localplanlist.min.js","names":["define","EsriConfig","WebMap","MapView","FullScreen","Locate","BasemapToggle","MapViewConfigurator","ToggleHandler","Tooltip","agentdetector","WatchUtils","_stageStartQueryStringVal","_stagePublicConsultationQueryStringVal","_stageReviewQueryStringVal","_stageAdoptionQueryStringVal","_stageCompleteQueryStringVal","_stagesQueryStringKey","_diarienummerQueryStringKey","_aktbeteckningQueryStringKey","_optionIdQueryStringKey","_optionLayerTypeQueryStringKey","gisStageAttributeKey","gisDiarieNummerAttributeKey","gisAktbeteckningAttributeKey","gisObjectIdAttributeKey","view","map","completeLayer","ongoingLayer","addressLayer","realEstateLayer","areaLayer","localplanlist","init","mapDomContainerId","tooltipConfig","stagesQueryStringKey","diarienummerQueryStringKey","aktbeteckningQueryStringKey","optionIdQueryStringKey","optionLayerTypeQueryStringKey","filterValues","loadingSpinnerSelector","$cookieNoticeOverlay","$","grayoverlayShowClass","initMap","removeClass","addClass","StageStartFilterValue","StagePublicConsultationFilterValue","StageReviewFilterValue","StageAdoptionFilterValue","StageCompleteFilterValue","portalUrl","portalItem","id","container","zoom","center","isIphone","widget","ui","add","addWidgetFullscreen","document","getElementById","undefined","addWidgetLegend","addWidgetMyLocation","nextBasemap","addWidgetBasemapToggle","when","initToggler","triggerSelectors","targetContainerSelector","targetSelectors","toggleClass","ariaExpandedSelectors","SelectorToTooltipify","SelectorToCheck","Math","max","documentElement","clientWidth","window","innerWidth","click","initLayers","goToSelectedSuggestion","applyFilters","on","whenLayerView","then","layerview","whenFalse","hide","catch","error","console","log","findLayerById","visible","selectedStageFilters","getQueryParameterValues","applyFiltersOngoing","applyFiltersComplete","stages","activeSuggestionAktbeteckning","getQueryParameterValue","selectedSuggestionIsComplete","length","completeStageIsInFilter","includes","activeSuggestionIsHidden","this","filterLayer","stagesFilterExpression","getFilterExpressionStages","activeSuggestionDiarienummer","showActiveSuggestion","layer","displayActiveSuggestion","suggestionAttributeKey","suggestionValue","initialFilterExpression","defExpression","definitionExpression","refreshLayer","query","createQuery","queryFeatures","displayOnlySelectedSuggestion","displayPopup","queryLayerForItem","diarieNummer","queryString","onlyDisplaySelected","outSpatialReference","spatialReference","where","response","features","featuresInLayer","currentFeature","goTo","geometry","popup","type","location","key","URLSearchParams","search","get","getAll","expression","mappedStages","mapStagesToLayerFilterValues","i","l","arr","push"],"sources":["arcgis/uppsala.arcgismap.localplanlist.js"],"mappings":"AAGAA,OAAO,CACH,cACA,cACA,qBACA,0BACA,sBACA,6BACA,uBACA,gBACA,UACA,gBACA,yBACD,SAAUC,EAAYC,EAAQC,EAASC,EAAYC,EAAQC,EAAeC,EAAqBC,EAAeC,EAASC,EAAeC,GAGrI,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEAC,EACAC,EACAC,EACAC,EACAC,EAGJ,MAAMC,EAAuB,sBACvBC,EAA8B,eAC9BC,EAA+B,gBAC/BC,EAA0B,WAmBhC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAIC,EAAgB,CAGhBC,KAAM,SACFC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,GAEA,IAAIC,EAAuBC,EAAE,mBACzBC,EAAuB,mBAG3Bb,EAAcc,QACVZ,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAG,GAEAF,EAAqBI,YAAYF,EAEzC,EAEAC,QAAS,SACLZ,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAG,GAGAD,EAAEF,GAAwBM,SAASH,GAGnC7B,EAAwBoB,EACxBnB,EAA8BoB,EAC9BnB,EAA+BoB,EAC/BnB,EAA0BoB,EAC1BnB,EAAiCoB,EAGjC7B,EAA4B8B,EAAaQ,sBACzCrC,EAAyC6B,EAAaS,mCACtDrC,EAA6B4B,EAAaU,uBAC1CrC,EAA+B2B,EAAaW,yBAC5CrC,EAA+B0B,EAAaY,yBAE5CrD,EAAWsD,UAAY,uCAGvB5B,EAAM,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C,KAnZG,cAuZnB,OAAOD,CACX,GAEJ,OAAOhI,CACX","ignoreList":[],"sourcesContent":["/** Incapsulates the special map funtionality on the local plan list page\n * */\n\ndefine([\n \"esri/config\",\n \"esri/WebMap\",\n \"esri/views/MapView\",\n \"esri/widgets/Fullscreen\",\n \"esri/widgets/Locate\",\n \"esri/widgets/BasemapToggle\",\n \"behaviorconfigurator\",\n \"togglehandler\",\n \"tooltip\",\n \"agentdetector\",\n \"esri/core/watchUtils\"\n], function (EsriConfig, WebMap, MapView, FullScreen, Locate, BasemapToggle, MapViewConfigurator, ToggleHandler, Tooltip, agentdetector, WatchUtils) {\n\n //variables for assigning query string keys and values in init function\n let _stageStartQueryStringVal;\n let _stagePublicConsultationQueryStringVal;\n let _stageReviewQueryStringVal;\n let _stageAdoptionQueryStringVal;\n let _stageCompleteQueryStringVal;\n\n let _stagesQueryStringKey;\n let _diarienummerQueryStringKey;\n let _aktbeteckningQueryStringKey;\n let _optionIdQueryStringKey;\n let _optionLayerTypeQueryStringKey;\n\n //GIS keys and id's\n const gisStageAttributeKey = \"HandelseBeskrivning\";\n const gisDiarieNummerAttributeKey = \"DiarieNummer\";\n const gisAktbeteckningAttributeKey = \"Aktbeteckning\";\n const gisObjectIdAttributeKey = \"OBJECTID\";\n\n const gisStartStageId = \"Beslut detaljplaneuppdrag\";\n const gisPublicConsultationStageId = \"Beslut samråd\";\n const gisReviewStageId = \"Beslut granskning\";\n const gisApprovalStageId = \"Beslut godkännande\";\n const gisAdoptionKFStageId = \"Beslut antagande KF\";\n const gisAdoptionPBNStageId = \"Beslut antagande PBN\";\n const gisAppealStageId = \"Beslut överklagande\";\n const gisCompleteStageId = \"Laga Kraft\";\n\n // if you change the mapId you porberbly need to look up and change the layerId's to.\n const gisMapId = \"487ef32067754cc58b8892caaada123f\";\n const gisCompleteLayerId = \"17946addb4a-layer-1\";\n const gisOngoingLayerId = \"17946adf267-layer-2\";\n const gisAreaLayerId = \"17c79db7034-layer-6\";\n const gisRealEstateLayerId = \"17c79db7406-layer-7\";\n const gisAddressLayerId = \"17c79db783f-layer-8\";\n\n let view;\n let map;\n let completeLayer;\n let ongoingLayer;\n let addressLayer;\n let realEstateLayer;\n let areaLayer;\n\n var localplanlist = {\n\n //init method ensures functional cookies are accepted and initializes the map if they are\n init: function init(\n mapDomContainerId,\n tooltipConfig,\n stagesQueryStringKey,\n diarienummerQueryStringKey,\n aktbeteckningQueryStringKey,\n optionIdQueryStringKey,\n optionLayerTypeQueryStringKey,\n filterValues,\n loadingSpinnerSelector) {\n\n var $cookieNoticeOverlay = $(\"#js-grayoverlay\");\n var grayoverlayShowClass = \"grayoverlay-show\";\n\n\n localplanlist.initMap(\n mapDomContainerId,\n tooltipConfig,\n stagesQueryStringKey,\n diarienummerQueryStringKey,\n aktbeteckningQueryStringKey,\n optionIdQueryStringKey,\n optionLayerTypeQueryStringKey,\n filterValues,\n loadingSpinnerSelector,\n grayoverlayShowClass);\n\n $cookieNoticeOverlay.removeClass(grayoverlayShowClass);\n\n },\n\n initMap: function (\n mapDomContainerId,\n tooltipConfig,\n stagesQueryStringKey,\n diarienummerQueryStringKey,\n aktbeteckningQueryStringKey,\n optionIdQueryStringKey,\n optionLayerTypeQueryStringKey,\n filterValues,\n loadingSpinnerSelector,\n grayoverlayShowClass) {\n\n //display gray overlay with spinner while loading\n $(loadingSpinnerSelector).addClass(grayoverlayShowClass);\n\n //assign query string keys from backend\n _stagesQueryStringKey = stagesQueryStringKey;\n _diarienummerQueryStringKey = diarienummerQueryStringKey;\n _aktbeteckningQueryStringKey = aktbeteckningQueryStringKey;\n _optionIdQueryStringKey = optionIdQueryStringKey;\n _optionLayerTypeQueryStringKey = optionLayerTypeQueryStringKey;\n\n //assign possible stage values from backend\n _stageStartQueryStringVal = filterValues.StageStartFilterValue;\n _stagePublicConsultationQueryStringVal = filterValues.StagePublicConsultationFilterValue;\n _stageReviewQueryStringVal = filterValues.StageReviewFilterValue;\n _stageAdoptionQueryStringVal = filterValues.StageAdoptionFilterValue;\n _stageCompleteQueryStringVal = filterValues.StageCompleteFilterValue;\n\n EsriConfig.portalUrl = \"https://kartportal.uppsala.se/portal\";\n\n // gets https://kartportal.uppsala.se/portal/apps/mapviewer/index.html?webmap=487ef32067754cc58b8892caaada123f\n map = new WebMap({\n portalItem: {\n id: gisMapId\n }\n });\n\n view = new MapView({\n container: mapDomContainerId, // Reference to the DOM node that will contain the view\n map: map,\n zoom: 7,\n center: [17.637770, 59.858948] // long, lat\n });\n\n MapViewConfigurator.init(view);\n addWidgetFullscreen(view);\n addWidgetLegend(view);\n addWidgetMyLocation(view);\n addWidgetBasemapToggle(view);\n\n // wire up open/close events for the legend widgit, when view has loaded\n view.when(function () {\n ToggleHandler.initToggler(\n {\n triggerSelectors: [\".js-arcgislegend\"],\n targetContainerSelector: \".js-arcgislegend\",\n targetSelectors: [\".js-arcgislegend-panel\"],\n toggleClass: \"arcgislegend-open\",\n ariaExpandedSelectors: [\".js-arcgislegend-toggler\"]\n }\n );\n Tooltip.init(\n tooltipConfig.SelectorToTooltipify,\n tooltipConfig.SelectorToCheck\n );\n\n // if we are not in mobile mode, click the legend widget to open it\n var viewportWidth = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0);\n if (viewportWidth > 768) {\n $(\".js-arcgislegend-toggler\").click();\n } \n });\n\n function addWidgetFullscreen(view) {\n if (agentdetector.isIphone()) {\n //Don't add fullscreen on iPhone since the fullscreen widget depends on the FullScreen Api which isn't implemented, at least not fully, in iPhone Safari or iPhone Chrome. \n //Listed as a Known Limitation on https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Fullscreen.html\n return;\n }\n\n var widget = new FullScreen({\n view: view\n });\n\n view.ui.add(widget, \"top-right\");\n }\n function addWidgetBasemapToggle(view) {\n var widget = new BasemapToggle({\n view: view,\n nextBasemap: \"satellite\"\n });\n view.ui.add(widget, \"bottom-left\")\n }\n function addWidgetLegend(view) {\n var widget = document.getElementById('js-arcgislegend');\n\n if (widget !== undefined) {\n view.ui.add(widget, \"top-left\");\n }\n }\n function addWidgetMyLocation(view) {\n var widget = new Locate({\n view: view\n });\n\n view.ui.add(widget, \"bottom-right\");\n }\n\n localplanlist.initLayers();\n localplanlist.goToSelectedSuggestion();\n localplanlist.applyFilters();\n\n //hide loading spinner when complete layer is loaded to map\n //check when each layer is created in the view if the complete layer has been loaded\n view.on(\"layerview-create\", () => {\n //if completeLayer is not loaded and in layer view, this will throw an error (ends up in catch)\n view.whenLayerView(completeLayer).then(layerview => {\n //wait for view to finish updating\n WatchUtils.whenFalse(layerview, \"updating\", () => {\n $(loadingSpinnerSelector).hide();\n });\n }).catch(function (error) {\n console.log(error);\n });\n }); \n },\n initLayers: function () {\n view.when(function () {\n completeLayer = map.findLayerById(gisCompleteLayerId);\n ongoingLayer = map.findLayerById(gisOngoingLayerId);\n realEstateLayer = map.findLayerById(gisRealEstateLayerId);\n addressLayer = map.findLayerById(gisAddressLayerId);\n areaLayer = map.findLayerById(gisAreaLayerId);\n\n areaLayer.visible = false;\n addressLayer.visible = false;\n realEstateLayer.visible = false;\n });\n },\n applyFilters: function () {\n if (view) {\n view.when(function () {\n //filtering of local plans is based on the selected stages in multiselect filter + the selected suggestion in groupable-autocomplete, if the suggestion is a localplan.\n //if the selected suggestion is a local plan it is always included even if it belongs to a stage that is not chosen in the multiselect filter\n const selectedStageFilters = localplanlist.getQueryParameterValues(_stagesQueryStringKey)\n localplanlist.applyFiltersOngoing(selectedStageFilters);\n localplanlist.applyFiltersComplete(selectedStageFilters);\n });\n }\n },\n applyFiltersComplete: function (stages) {\n //check if user has selected a complete local plan from the search suggestions\n const activeSuggestionAktbeteckning = localplanlist.getQueryParameterValue(_aktbeteckningQueryStringKey);\n const selectedSuggestionIsComplete = activeSuggestionAktbeteckning.length;\n\n //check if complete stage is selected by user in filter\n //if no stages are selected, all are selected\n const completeStageIsInFilter = stages.includes(_stageCompleteQueryStringVal) || !stages.length;\n\n //if stage complete is selected or the selected suggestion is a complete local plan we want to make complete layer visble\n completeLayer.visible = completeStageIsInFilter || selectedSuggestionIsComplete;\n\n //if selected suggestion is a complete localplan but complete stage is not chosen in stages filter\n //we want to display the active suggestion\n const activeSuggestionIsHidden = selectedSuggestionIsComplete && !completeStageIsInFilter\n\n //filter the layer with defintion expression\n this.filterLayer(completeLayer, activeSuggestionIsHidden, gisAktbeteckningAttributeKey, activeSuggestionAktbeteckning, \"\");\n },\n applyFiltersOngoing: function (stages) {\n //get expression for filtering on selected stage filters\n const stagesFilterExpression = localplanlist.getFilterExpressionStages(stages);\n\n //check if user has selected an ongoing local plan from the search suggestions\n //if so we always want to show that suggestion\n const activeSuggestionDiarienummer = localplanlist.getQueryParameterValue(_diarienummerQueryStringKey);\n const showActiveSuggestion = activeSuggestionDiarienummer.length;\n\n //filter layer with defintion expression\n this.filterLayer(ongoingLayer, showActiveSuggestion, gisDiarieNummerAttributeKey, activeSuggestionDiarienummer, stagesFilterExpression);\n },\n filterLayer: function (layer, displayActiveSuggestion, suggestionAttributeKey, suggestionValue, initialFilterExpression) {\n //set inital defintion expression, \n //example: ongoing layer wants to filter on stages while complete layer does not, so pass stage filter as initial for ongoing layer\n let defExpression = initialFilterExpression;\n\n //add selected suggestion to initialExpression if such selection exist\n //if selected local plan is in another stage than the ones selected in the filter, this expression shows the selected local plan anyway.\n //if initial expression is not empty append to existing with OR\n if (displayActiveSuggestion) {\n defExpression = defExpression.length ?\n defExpression + \" OR \" + suggestionAttributeKey + \" = '\" + suggestionValue + \"'\" :\n suggestionAttributeKey + \" = '\" + suggestionValue + \"'\";\n }\n\n //filter the layer to display selected stages and suggestion from filter.\n layer.definitionExpression = defExpression;\n this.refreshLayer(layer);\n },\n refreshLayer: function (layer) {\n var query = layer.createQuery();\n layer.queryFeatures(query);\n },\n goToSelectedSuggestion: function () {\n if (view) {\n view.when(function () {\n const layerTypeId = localplanlist.getQueryParameterValue(_optionLayerTypeQueryStringKey);\n let query = \"\";\n let displayOnlySelectedSuggestion = false;\n let displayPopup = false;\n\n switch (layerTypeId) {\n\n //navigera till objekt i lager för adresser\n case \"0\":\n displayOnlySelectedSuggestion = true;\n query = gisObjectIdAttributeKey + \"=\" + localplanlist.getQueryParameterValue(_optionIdQueryStringKey);\n localplanlist.queryLayerForItem(query, addressLayer, displayOnlySelectedSuggestion, displayPopup);\n //set zoom level when displaying address\n view.zoom = 11;\n break;\n\n //navigera till objekt i lager för fastigheter\n case \"1\":\n displayOnlySelectedSuggestion = true;\n query = gisObjectIdAttributeKey + \"=\" + localplanlist.getQueryParameterValue(_optionIdQueryStringKey);\n localplanlist.queryLayerForItem(query, realEstateLayer, displayOnlySelectedSuggestion, displayPopup);\n break;\n\n //navigera till objekt i lager för område\n case \"2\":\n displayOnlySelectedSuggestion = true;\n query = gisObjectIdAttributeKey + \"=\" + localplanlist.getQueryParameterValue(_optionIdQueryStringKey);\n localplanlist.queryLayerForItem(query, areaLayer, displayOnlySelectedSuggestion, displayPopup);\n break;\n\n // navigera till objekt i lager för detaljplaner\n case \"3\":\n //visa popups för detaljplaner\n displayPopup = true;\n //pågående\n const diarieNummer = localplanlist.getQueryParameterValue(_diarienummerQueryStringKey);\n if (diarieNummer.length > 0) {\n query = gisDiarieNummerAttributeKey + \" = '\" + diarieNummer + \"'\";\n localplanlist.queryLayerForItem(query, ongoingLayer, displayOnlySelectedSuggestion, displayPopup);\n }\n //avslutade\n else {\n query = gisAktbeteckningAttributeKey + \" = '\" + localplanlist.getQueryParameterValue(_aktbeteckningQueryStringKey) + \"'\";\n localplanlist.queryLayerForItem(query, completeLayer, displayOnlySelectedSuggestion, displayPopup);\n }\n break;\n }\n });\n }\n },\n queryLayerForItem: function (queryString, layer, onlyDisplaySelected, displayPopup) {\n let query = layer.createQuery();\n query.outSpatialReference = view.spatialReference;\n query.where = queryString;\n\n //vissa lager ska filtrera bort allt förrutom träffen, andra inte\n if (onlyDisplaySelected) {\n\n layer.definitionExpression = queryString;\n }\n\n layer.queryFeatures(query)\n .then(function (response) {\n if (response.features.length > 0 && response.features[0] !== undefined) {\n\n const featuresInLayer = response.features;\n const currentFeature = response.features[0];\n\n view.goTo(currentFeature.geometry).then(function () {\n if (displayPopup) {\n localplanlist.displayPopup(featuresInLayer, currentFeature);\n }\n });\n\n //vissa lager döljs initialt och behöver visas\n if (layer.visible == false) {\n layer.visible = true;\n }\n\n }\n else {\n //ska vi ha någon felhantering här?\n //console.log(\"no item matching the search suggestion was found in the map layer for query: \");\n }\n });\n\n },\n displayPopup: function (featuresInLayer, currentFeature) {\n\n view.popup.visible = true;\n view.popup.features = featuresInLayer;\n\n //om det är \"point\" fungerar inte view.center\n if (currentFeature.geometry.type == \"point\") {\n view.popup.location = currentFeature.geometry;\n }\n else {\n view.popup.location = view.center;\n }\n },\n getQueryParameterValue: function (key) {\n const urlParams = new URLSearchParams(window.location.search);\n return urlParams.get(key);\n },\n getQueryParameterValues: function (key) {\n const urlParams = new URLSearchParams(window.location.search);\n return urlParams.getAll(key);\n },\n getFilterExpressionStages: function (stages) {\n let expression = \"\";\n const mappedStages = this.mapStagesToLayerFilterValues(stages);\n\n for (var i = 0, l = mappedStages.length; i < l; i++) {\n if (i == 0) {\n expression += gisStageAttributeKey + \" = '\" + mappedStages[i] + \"'\"\n }\n else {\n expression += \" OR \" + gisStageAttributeKey + \" = '\" + mappedStages[i] + \"'\"\n }\n }\n return expression;\n },\n mapStagesToLayerFilterValues: function (stages) {\n let arr = [];\n for (var i = 0, l = stages.length; i < l; i++) {\n switch (stages[i]) {\n case _stageStartQueryStringVal:\n arr.push(gisStartStageId);\n break;\n case _stagePublicConsultationQueryStringVal:\n arr.push(gisPublicConsultationStageId);\n break;\n //review filter displays review and approval\n case _stageReviewQueryStringVal:\n arr.push(gisReviewStageId);\n arr.push(gisApprovalStageId);\n break;\n //adoption filter option displays KF, PBN and appeal\n case _stageAdoptionQueryStringVal:\n arr.push(gisAdoptionKFStageId);\n arr.push(gisAdoptionPBNStageId);\n arr.push(gisAppealStageId);\n break;\n case _stageCompleteQueryStringVal:\n arr.push(gisCompleteStageId);\n break;\n }\n }\n return arr;\n },\n };\n return localplanlist;\n});\n\n"]}