Map component

Use this component when seeing something on a map would be useful for a user.

These examples show how to use DLMaps.Map() to create simple maps displaying area boundaries.

Show a local authority boundary

We regularly need to show the extent of an area or areas. The most common is the local authority boundary.

This example shows the boundaries for Harrogate borough council and City of York Council.



<div class="dl-map__wrapper " style="min-height: 350px;"><div 
        class="dl-map govuk-!-margin-top-3"
        id="basicMap"
        data-module="boundary-map"   
    >
        <noscript>To view this map, you need to enable JavaScript.</noscript>
    </div>



</div>

<script src="/static/javascripts/Leaflet.recentre.js"></script>
<script>
  const $mapElement = document.querySelector('[data-module="boundary-map"]')
  exmap = new DLMaps.Map($mapElement).init({
    geojsonURLs: [
      'https://raw.githubusercontent.com/digital-land/boundary-collection/master/collection/local-authority/E07000165/index.geojson',
      'https://raw.githubusercontent.com/digital-land/boundary-collection/master/collection/local-authority/E06000014/index.geojson'
    ]
  })
</script>
{%- from "digital-land-frontend/components/map/macro.jinja" import dlMap %}
{{ dlMap({
    "id": "basicMap",
    "classes": "govuk-!-margin-top-3"
}) }}
<script src="/static/javascripts/Leaflet.recentre.js"></script>
<script>
  const $mapElement = document.querySelector('[data-module="boundary-map"]')
  exmap = new DLMaps.Map($mapElement).init({
    geojsonURLs: [
      'https://raw.githubusercontent.com/digital-land/boundary-collection/master/collection/local-authority/E07000165/index.geojson',
      'https://raw.githubusercontent.com/digital-land/boundary-collection/master/collection/local-authority/E06000014/index.geojson'
    ]
  })
</script>

Show multiple shapes

There are a number of ways to pass ursl to geojson files to the map component.

All urls must point to .geojson files.

HTML attribute

You can pass a list of urls, separate by ;, to the data-geojson-urls attribute of the map element.

<div class="dl-map" id="aMap" 
    data-module="boundary-map"
    data-geojson-urls="/conservation-area/c52ff772-db94-4a8a-acdf-be3a1ac79d25/boundary.geojson;/local-authority-district/E06000001/geometry.geojson"
>

<div class="dl-map__wrapper">
    <div class="dl-map govuk-!-margin-top-3" id="aMap" style="height: 350px;" data-module="boundary-map" data-geojson-urls="https://raw.githubusercontent.com/digital-land/boundary-collection/master/collection/local-authority/E07000165/index.geojson;https://digital-land.github.io/local-authority-district/E06000001/geometry.geojson"></div>
</div>

<script>
const $mapElement = document.querySelector('[data-module="boundary-map"]')
new DLMaps.Map($mapElement).init({})
</script>
{%- from "digital-land-frontend/components/map/macro.jinja" import dlMap %}
<div class="dl-map__wrapper">
    <div class="dl-map govuk-!-margin-top-3" id="aMap" style="height: 350px;" data-module="boundary-map" data-geojson-urls="https://raw.githubusercontent.com/digital-land/boundary-collection/master/collection/local-authority/E07000165/index.geojson;https://digital-land.github.io/local-authority-district/E06000001/geometry.geojson"></div>
</div>

<script>
const $mapElement = document.querySelector('[data-module="boundary-map"]')
new DLMaps.Map($mapElement).init({})
</script>

Jinja macro option

Use the data-geojson-urls option when calling the jinja macro. It accepts a string with urls separated by ; or it accepts an array urls.



<div class="dl-map__wrapper " style="min-height: 350px;"><div 
        class="dl-map govuk-!-margin-top-3"
        id="aMap"
        data-module="boundary-map" data-geojson-urls="https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3090/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3091/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3092/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3093/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3094/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3095/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3096/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3097/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3098/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3099/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3100/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3101/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3102/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3103/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3104/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3105/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3106/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3107/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3108/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3109/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3110/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3111/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3112/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3113/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3114/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3115/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3116/geometry.geojson;https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3117/geometry.geojson"   
    >
        <noscript>To view this map, you need to enable JavaScript.</noscript>
    </div>



</div>

<script>
  const $mapElement = document.querySelector('[data-module="boundary-map"]')
  exmap = new DLMaps.Map($mapElement).init({})
</script>
{%- from "digital-land-frontend/components/map/macro.jinja" import dlMap %}
{{ dlMap({
    "id": "aMap",
    "classes": "govuk-!-margin-top-3",
    "attributes": {
        "data-geojson-urls": [
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3090/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3091/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3092/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3093/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3094/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3095/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3096/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3097/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3098/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3099/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3100/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3101/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3102/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3103/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3104/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3105/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3106/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3107/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3108/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3109/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3110/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3111/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3112/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3113/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3114/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3115/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3116/geometry.geojson',
            'https://digital-land.github.io/conservation-area/local-authority-eng/YOR/3117/geometry.geojson'
        ]
    }
}) }}
<script>
  const $mapElement = document.querySelector('[data-module="boundary-map"]')
  exmap = new DLMaps.Map($mapElement).init({})
</script>

JS init

An alternative approach is to provide the url(s) to the geojsonUrls option which initalising the module.



<div class="dl-map__wrapper " style="min-height: 350px;"><div 
        class="dl-map govuk-!-margin-top-3"
        id="basicMap"
        data-module="boundary-map"   
    >
        <noscript>To view this map, you need to enable JavaScript.</noscript>
    </div>



</div>

<script src="/static/javascripts/Leaflet.recentre.js"></script>
<script>
  const $mapElement = document.querySelector('[data-module="boundary-map"]')
  exmap = new DLMaps.Map($mapElement).init({
    geojsonURLs: [
      'https://raw.githubusercontent.com/digital-land/boundary-collection/master/collection/local-authority/E07000165/index.geojson',
      'https://raw.githubusercontent.com/digital-land/boundary-collection/master/collection/local-authority/E06000014/index.geojson'
    ]
  })
</script>
{%- from "digital-land-frontend/components/map/macro.jinja" import dlMap %}
{{ dlMap({
    "id": "basicMap",
    "classes": "govuk-!-margin-top-3"
}) }}
<script src="/static/javascripts/Leaflet.recentre.js"></script>
<script>
  const $mapElement = document.querySelector('[data-module="boundary-map"]')
  exmap = new DLMaps.Map($mapElement).init({
    geojsonURLs: [
      'https://raw.githubusercontent.com/digital-land/boundary-collection/master/collection/local-authority/E07000165/index.geojson',
      'https://raw.githubusercontent.com/digital-land/boundary-collection/master/collection/local-authority/E06000014/index.geojson'
    ]
  })
</script>

Options

There are a number of options you can set when initialising the module.

Option Type Description
defaultPos Point An array of coords the map will initially centre on. Defaults to [52.561928, -1.464854], which is the centre of the UK.
fullScreenControl Boolean True but default. Option to add button to make the map fullscreen
minZoom Int Sets the minimum zoom level for the map. Defaults to 6
maxZoom Int Sets the maximum zoom level for the map. Defaults to 18

Additional information

Aria Labelledby

You can added a aria-labelledby attribute by adding text to the optional arialabelledby option when using the component.


<div class="dl-map__wrapper " style="min-height: 350px;">
    <span id="aria-label-3199" class="govuk-visually-hidden">An example of the output of the digital land map component.</span>
    <div 
        class="dl-map govuk-!-margin-top-3"
        id="aMap"
        data-module="boundary-map" aria-labelledby="aria-label-3199" data-geojson-urls="https://digital-land.github.io/geography/conservation-area/c52ff772-db94-4a8a-acdf-be3a1ac79d25/boundary.geojson"   
    >
        <noscript>To view this map, you need to enable JavaScript.</noscript>
    </div>



</div>

<script>
const $mapElement = document.querySelector('[data-module="boundary-map"]')
new DLMaps.Map($mapElement).init({})
</script>
{%- from "digital-land-frontend/components/map/macro.jinja" import dlMap -%}
{{- dlMap({
    "id": "aMap",
    "classes": "govuk-!-margin-top-3",
    "attributes": {
        "data-geojson-urls": "https://digital-land.github.io/geography/conservation-area/c52ff772-db94-4a8a-acdf-be3a1ac79d25/boundary.geojson"
    },
    "arialabelledby": "An example of the output of the digital land map component."
}) }}
<script>
const $mapElement = document.querySelector('[data-module="boundary-map"]')
new DLMaps.Map($mapElement).init({})
</script>

Key

This is an experimental component.

An example of the key we use on the Brownfield land maps. Currently testing 2 options.

<div class="map-key">
    <h4 class="govuk-heading-s govuk-visually-hidden">Key</h4>
    <div class="map-key__entry">
        <div class="map-key__entry__item">
        <div class="bfs-pt__container">
            <div class="bfs-pt bfs-pt--small"></div>
            <span class="ellipsis">&hellip;</span>
            <div class="bfs-pt bfs-pt--large"></div>
        </div>
        </div>
        <p class="map-key__entry__label">Sites sized by hectares</p>
    </div>
</div>


<div class="bfs-hectares-key dl-map__panel-top-left">
    <h3 class="govuk-heading-s govuk-visually-hidden">Key</h3>
    <h4 class="bfs-hectares-key__title">Site size in hectares</h4>
    <div class="bfs-hectares-key__container">
        <div class="bfs-hectare"/></div>
        <div class="bfs-hectare bfs-hectare--lg"></div>
    </div>
</div>
<div class="map-key">
    <h4 class="govuk-heading-s govuk-visually-hidden">Key</h4>
    <div class="map-key__entry">
        <div class="map-key__entry__item">
        <div class="bfs-pt__container">
            <div class="bfs-pt bfs-pt--small"></div>
            <span class="ellipsis">&hellip;</span>
            <div class="bfs-pt bfs-pt--large"></div>
        </div>
        </div>
        <p class="map-key__entry__label">Sites sized by hectares</p>
    </div>
</div>


<div class="bfs-hectares-key dl-map__panel-top-left">
    <h3 class="govuk-heading-s govuk-visually-hidden">Key</h3>
    <h4 class="bfs-hectares-key__title">Site size in hectares</h4>
    <div class="bfs-hectares-key__container">
        <div class="bfs-hectare"/></div>
        <div class="bfs-hectare bfs-hectare--lg"></div>
    </div>
</div>

Brownfield map

An example of the national brownfield map.

<!DOCTYPE html>
<html lang="en" class="govuk-template ">
  <head>
    <meta charset="utf-8">
    <title>BFS Map | Digital Land</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
    <meta name="theme-color" content="#0b0c0c"> 

    <meta http-equiv="X-UA-Compatible" content="IE=edge">


  <link rel="shortcut icon" sizes="48x48" href="/design-system/static/images/favicon.ico" type="image/x-icon">
  <link rel="shortcut icon" sizes="32x32" href="/design-system/static/images/favicon-32x32.png" type="image/png">
  <link rel="shortcut icon" sizes="16x16" href="/design-system/static/images/favicon-16x16.png" type="image/png">
  <link rel="apple-touch-icon" href="/design-system/static/images/apple-touch-icon.png">



    <meta name="digital-land:template" content="digital-land-frontend/base--full-width.jinja">

<script src="https://polyfill.io/v3/polyfill.min.js?features=fetch%2CPromise%2Ces6%2Ces5%2Ces2015%2Ces2016%2CURL%2CURLSearchParams%2CObject.entries%2CObject.fromEntries%2CAbortController"></script>

<!-- should make this optional, no need to load if not showing a map -->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin="" />

<!-- Make sure you put this AFTER Leaflet's CSS -->
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js"
    integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="
    crossorigin=""></script>

<!-- assets needed for fullscreen maps -->
<script src='https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/Leaflet.fullscreen.min.js'></script>
<link href='https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/leaflet.fullscreen.css' rel='stylesheet' />

<!-- script needed for recentring map -->
<script src="/design-system/static/javascripts/Leaflet.recentre.js"></script>

<script src="/design-system/static/javascripts/digital-land-maps.js"></script>

    <link href="/design-system/static/stylesheets/dl-frontend.css" rel="stylesheet" />



    <meta property="og:image" content="/design-system/static/images/govuk-opengraph-image.png">
  </head>
  <body class="govuk-template__body ">
    <script>document.body.className = ((document.body.className) ? document.body.className + ' js-enabled' : 'js-enabled');</script>




  <a href="#main-content" class="govuk-skip-link" data-module="govuk-skip-link">Skip to main content</a>






    <!-- Cookie banner partial version 1.0.1 -->
<div id="global-cookie-message" class="govuk-clearfix global-cookie-message" data-module="cookie-banner" role="region" aria-label="cookie banner" data-nosnippet="">

  <div id="cookie-banner" class="govuk-width-container">
    <div class="govuk-grid-row">
      <div class="govuk-grid-column-two-thirds">
        <div class="cookie-banner__message govuk-!-margin-top-6">
          <h2 class="govuk-heading-m">Tell us whether you accept cookies</h2>
          <p class="govuk-body">We use <a class="govuk-link" href="/cookies">cookies to collect information</a> about how you use the Digital Land website to make the website work as well as possible.</p>
        </div>
        <div class="cooke-banner__buttons govuk-grid-row">
          <div class="govuk-grid-column-one-half">
            <button class="govuk-button" onclick="acceptCookies();showCookieConfirmation();">Accept all cookies</button>
          </div>
          <div class="govuk-grid-column-one-half">
            <a class="govuk-button" href="/cookies">Set cookie preferences</a>
          </div>
        </div>
      </div>
    </div>
  </div>

  <div id="cookie-confirmation" class="govuk-width-container govuk-!-padding-top-6" tabindex="-1" style="display: none;">
    <p class="cookie-banner__confirmation-message govuk-body">You’ve accepted all cookies. You can <a class="govuk-link" href="/cookies">change your cookie settings</a> at any time.</p>
    <button class="cookie-banner__hide-button govuk-button govuk-button--secondary" onclick="document.getElementById('cookie-confirmation').style.display='none';">Hide</button>
  </div>

</div>






<header role="banner" id="global-header" class="govuk-header  with-proposition dl-header dl-header--full" data-module="govuk-header">
  <div class="govuk-header__container dl-container--full-width">
    <div class="header-proposition">
      <div class="govuk-header__content">
        <a href="/" class="govuk-header__link govuk-header__link--service-name">

            Digital Land

        </a>

          <nav class="govuk-header__navigation" aria-label="Menu">
            <button type="button" class="govuk-header__menu-button govuk-js-header-toggle" aria-controls="navigation" aria-label="Show or hide Top Level Navigation">Menu</button>
            <ul id="navigation" class="govuk-header__navigation-list">

              <li class="govuk-header__navigation-item">
                <a class="govuk-header__link" href="/about">Team</a>
              </li>

              <li class="govuk-header__navigation-item">
                <a class="govuk-header__link" href="/project/">Projects</a>
              </li>

              <li class="govuk-header__navigation-item">
                <a class="govuk-header__link" href="/weeknote/">Weeknotes</a>
              </li>

              <li class="govuk-header__navigation-item">
                <a class="govuk-header__link" href="/blog-post/">Blog</a>
              </li>

              <li class="govuk-header__navigation-item">
                <a class="govuk-header__link" href="/guidance/">Guidance</a>
              </li>

              <li class="govuk-header__navigation-item">
                <a class="govuk-header__link" href="/dataset/">Datasets</a>
              </li>

              <li class="govuk-header__navigation-item">
                <a class="govuk-header__link" href="/organisation/">Organisations</a>
              </li>

              <li class="govuk-header__navigation-item">
                <a class="govuk-header__link" href="/map/">Map</a>
              </li>

            </ul>
          </nav>

      </div>
    </div>
  </div>
</header>





<div class="dl-container--full-width ">




<div class="govuk-phase-banner">
  <p class="govuk-phase-banner__content">
    <strong class="govuk-tag govuk-phase-banner__content__tag">
      prototype
    </strong>
    <span class="govuk-phase-banner__text">
      This is a prototype. Please provide <a class="govuk-link" href="mailto:digitalland@communities.gov.uk?subject=Prototype feedback">feedback to the Digital Land team</a>.
    </span>
  </p>
</div>





    <main class="govuk-main-wrapper " id="main-content" role="main">

<div class="govuk-grid-row">
    <div class="govuk-grid-column-full">
    <h1 class="govuk-heading-xl">Map of brownfield land</h1>
    </div>
</div>

<p class="govuk-body-l">National view of the brownfield land  collected and collated by Digital Land.</p>




<div class="dl-map__wrapper " style="min-height: 700px;"><div 
        class="dl-map govuk-!-margin-bottom-0"
        id="aMap"
        data-module="boundary-map"   
    >
        <noscript>To view this map, you need to enable JavaScript.</noscript>
    </div>
    <div class="dl-map__loader">
        <div class="dl-map__loader-msg">
            <div class="dl-map__spinning-loader"></div>
            <span class="govuk-!-font-size-24 govuk-!-margin-top-6">Loading brownfield land data</span>
        </div>
    </div>

    <div class="dl-map__side-panel js-hidden">

<div class="dl-map__side-panel__section">
<h3 class="govuk-heading-s govuk-!-margin-bottom-0">Displayed on map</h3>
</div>
<div class="dl-map__side-panel__section dl-map__side-panel__section--title js-hidden" data-module="dl-map-items">
  <p class="govuk-body govuk-!-margin-bottom-1"><span class="organisation-count"></span> organisation boundaries</p>
  <p class="govuk-body govuk-!-margin-top-3 govuk-!-margin-bottom-1 js-hidden">Active: <span class="active-organisation dl-map__highlight--yellow"></span></p>
</div>
<div class="dl-map__side-panel__section dl-map__side-panel__section--blue">

<div class="govuk-form-group govuk-!-margin-bottom-0">
  <label class="govuk-label" for="dl-organisation-autocomplete">
    Search for an organisation
  </label>
  <span id="dl-organisation-autocomplete-error" class="govuk-error-message" role="alert">
    <span class="govuk-visually-hidden">Error:</span> Value entered not recognised, please try again
  </span>
  <select class="govuk-select" id="dl-organisation-autocomplete" name="dl-organisation-autocomplete">
    <option value=""></option>
    <option value="development-corporation:Q20648596">Old Oak and Park Royal Development Corporation</option>
    <option value="development-corporation:Q4916714">Birmingham Heartlands Development Corporation</option>
    <option value="development-corporation:Q6670544">London Legacy Development Corporation</option>
    <option value="development-corporation:Q6670837">London Thames Gateway Development Corporation</option>
    <option value="development-corporation:Q72456968">South Tees Development Corporation</option>
    <option value="development-corporation:Q72463795">Ebbsfleet Development Corporation</option>
    <option value="development-corporation:Q7799380">Thurrock Thames Gateway Development Corporation</option>
    <option value="development-corporation:Q7860503">Tyne and Wear Development Corporation</option>
    <option value="development-corporation:Q7986087">West Northamptonshire Development Corporation</option>
    <option value="government-organisation:D303">Office for National Statistics</option>
    <option value="government-organisation:D38">Ordnance Survey</option>
    <option value="government-organisation:D4">Ministry of Housing, Communities and Local Government</option>
    <option value="government-organisation:D69">HM Land Registry</option>
    <option value="government-organisation:EA39">Planning Inspectorate</option>
    <option value="government-organisation:EA87">Valuation Office Agency</option>
    <option value="government-organisation:PB1164">Historic England</option>
    <option value="government-organisation:PB1204">Valuation Tribunal for England</option>
    <option value="government-organisation:PB1218">Regulator of Social Housing</option>
    <option value="government-organisation:PB1232">Homes England</option>
    <option value="government-organisation:PB160">Building Regulations Advisory Committee</option>
    <option value="government-organisation:PB207">Health and Safety Executive</option>
    <option value="government-organisation:PB372">Housing Ombudsman</option>
    <option value="government-organisation:PB373">Leasehold Advisory Service</option>
    <option value="government-organisation:PB375">Valuation Tribunal Service</option>
    <option value="government-organisation:PC163">Architects Registration Board</option>
    <option value="local-authority-eng:ADU">Adur District Council</option>
    <option value="local-authority-eng:ALL">Allerdale Borough Council</option>
    <option value="local-authority-eng:AMB">Amber Valley Borough Council</option>
    <option value="local-authority-eng:ARU">Arun District Council</option>
    <option value="local-authority-eng:ASF">Ashford Borough Council</option>
    <option value="local-authority-eng:ASH">Ashfield District Council</option>
    <option value="local-authority-eng:AYL">Aylesbury Vale District Council</option>
    <option value="local-authority-eng:BAB">Babergh District Council</option>
    <option value="local-authority-eng:BAE">Bassetlaw District Council</option>
    <option value="local-authority-eng:BAI">Basildon Borough Council</option>
    <option value="local-authority-eng:BAN">Basingstoke and Deane Borough Council</option>
    <option value="local-authority-eng:BAR">Barrow-in-Furness Borough Council</option>
    <option value="local-authority-eng:BAS">Bath and North East Somerset Council</option>
    <option value="local-authority-eng:BBD">Blackburn with Darwen Borough Council</option>
    <option value="local-authority-eng:BDF">Bedford Borough Council</option>
    <option value="local-authority-eng:BDG">London Borough of Barking and Dagenham</option>
    <option value="local-authority-eng:BEN">London Borough of Brent</option>
    <option value="local-authority-eng:BEX">London Borough of Bexley</option>
    <option value="local-authority-eng:BIR">Birmingham City Council</option>
    <option value="local-authority-eng:BKM">Buckinghamshire County Council</option>
    <option value="local-authority-eng:BLA">Blaby District Council</option>
    <option value="local-authority-eng:BMH">Bournemouth Borough Council</option>
    <option value="local-authority-eng:BNE">London Borough of Barnet</option>
    <option value="local-authority-eng:BNH">Brighton and Hove City Council</option>
    <option value="local-authority-eng:BNS">Barnsley Metropolitan Borough Council</option>
    <option value="local-authority-eng:BOL">Bolton Metropolitan Borough Council</option>
    <option value="local-authority-eng:BOS">Bolsover District Council</option>
    <option value="local-authority-eng:BOT">Boston Borough Council</option>
    <option value="local-authority-eng:BPC">Bournemouth, Christchurch and Poole Council</option>
    <option value="local-authority-eng:BPL">Blackpool Borough Council</option>
    <option value="local-authority-eng:BRA">Braintree District Council</option>
    <option value="local-authority-eng:BRC">Bracknell Forest Council</option>
    <option value="local-authority-eng:BRD">City of Bradford Metropolitan District Council</option>
    <option value="local-authority-eng:BRE">Breckland District Council</option>
    <option value="local-authority-eng:BRM">Bromsgrove District Council</option>
    <option value="local-authority-eng:BRO">Broadland District Council</option>
    <option value="local-authority-eng:BRT">Broxtowe Borough Council</option>
    <option value="local-authority-eng:BRW">Brentwood Borough Council</option>
    <option value="local-authority-eng:BRX">Broxbourne Borough Council</option>
    <option value="local-authority-eng:BRY">London Borough of Bromley</option>
    <option value="local-authority-eng:BST">Bristol City Council</option>
    <option value="local-authority-eng:BUC">Buckinghamshire Council</option>
    <option value="local-authority-eng:BUN">Burnley Borough Council</option>
    <option value="local-authority-eng:BUR">Bury Metropolitan Borough Council</option>
    <option value="local-authority-eng:CAB">Cambridge City Council</option>
    <option value="local-authority-eng:CAM">Cambridgeshire County Council</option>
    <option value="local-authority-eng:CAN">Cannock Chase District Council</option>
    <option value="local-authority-eng:CAR">Carlisle City Council</option>
    <option value="local-authority-eng:CAS">Castle Point Borough Council</option>
    <option value="local-authority-eng:CAT">Canterbury City Council</option>
    <option value="local-authority-eng:CBF">Central Bedfordshire Council</option>
    <option value="local-authority-eng:CHA">Charnwood Borough Council</option>
    <option value="local-authority-eng:CHC">Christchurch Borough Council</option>
    <option value="local-authority-eng:CHE">Cheshire East Council</option>
    <option value="local-authority-eng:CHI">Chichester District Council</option>
    <option value="local-authority-eng:CHL">Chelmsford City Council</option>
    <option value="local-authority-eng:CHN">Chiltern District Council</option>
    <option value="local-authority-eng:CHO">Chorley Borough Council</option>
    <option value="local-authority-eng:CHR">Cherwell District Council</option>
    <option value="local-authority-eng:CHS">Chesterfield Borough Council</option>
    <option value="local-authority-eng:CHT">Cheltenham Borough Council</option>
    <option value="local-authority-eng:CHW">Cheshire West and Chester Council</option>
    <option value="local-authority-eng:CLD">Calderdale Metropolitan Borough Council</option>
    <option value="local-authority-eng:CMA">Cumbria County Council</option>
    <option value="local-authority-eng:CMD">London Borough of Camden</option>
    <option value="local-authority-eng:COL">Colchester Borough Council</option>
    <option value="local-authority-eng:CON">Cornwall Council</option>
    <option value="local-authority-eng:COP">Copeland Borough Council</option>
    <option value="local-authority-eng:COR">Corby Borough Council</option>
    <option value="local-authority-eng:COT">Cotswold District Council</option>
    <option value="local-authority-eng:COV">Coventry City Council</option>
    <option value="local-authority-eng:CPCA">Cambridgeshire and Peterborough Combined Authority</option>
    <option value="local-authority-eng:CRA">Craven District Council</option>
    <option value="local-authority-eng:CRW">Crawley Borough Council</option>
    <option value="local-authority-eng:CRY">London Borough of Croydon</option>
    <option value="local-authority-eng:DAC">Dacorum Borough Council</option>
    <option value="local-authority-eng:DAL">Darlington Borough Council</option>
    <option value="local-authority-eng:DAR">Dartford Borough Council</option>
    <option value="local-authority-eng:DAV">Daventry District Council</option>
    <option value="local-authority-eng:DBY">Derbyshire County Council</option>
    <option value="local-authority-eng:DEB">Derbyshire Dales District Council</option>
    <option value="local-authority-eng:DER">Derby City Council</option>
    <option value="local-authority-eng:DEV">Devon County Council</option>
    <option value="local-authority-eng:DNC">Doncaster Metropolitan Borough Council</option>
    <option value="local-authority-eng:DOR">Dorset County Council</option>
    <option value="local-authority-eng:DOV">Dover District Council</option>
    <option value="local-authority-eng:DST">Dorset Council</option>
    <option value="local-authority-eng:DUD">Dudley Metropolitan Borough Council</option>
    <option value="local-authority-eng:DUR">Durham County Council</option>
    <option value="local-authority-eng:EAL">London Borough of Ealing</option>
    <option value="local-authority-eng:EAS">Eastbourne Borough Council</option>
    <option value="local-authority-eng:EAT">Eastleigh Borough Council</option>
    <option value="local-authority-eng:ECA">East Cambridgeshire District Council</option>
    <option value="local-authority-eng:EDE">East Devon District Council</option>
    <option value="local-authority-eng:EDN">Eden District Council</option>
    <option value="local-authority-eng:EDO">East Dorset District Council</option>
    <option value="local-authority-eng:EHA">East Hampshire District Council</option>
    <option value="local-authority-eng:EHE">East Hertfordshire District Council</option>
    <option value="local-authority-eng:ELI">East Lindsey District Council</option>
    <option value="local-authority-eng:ELM">Elmbridge Borough Council</option>
    <option value="local-authority-eng:ENF">London Borough of Enfield</option>
    <option value="local-authority-eng:ENO">East Northamptonshire Council</option>
    <option value="local-authority-eng:EPP">Epping Forest District Council</option>
    <option value="local-authority-eng:EPS">Epsom and Ewell Borough Council</option>
    <option value="local-authority-eng:ERE">Erewash Borough Council</option>
    <option value="local-authority-eng:ERY">East Riding of Yorkshire Council</option>
    <option value="local-authority-eng:ESK">East Suffolk Council</option>
    <option value="local-authority-eng:ESS">Essex County Council</option>
    <option value="local-authority-eng:EST">East Staffordshire Borough Council</option>
    <option value="local-authority-eng:ESX">East Sussex County Council</option>
    <option value="local-authority-eng:EXE">Exeter City Council</option>
    <option value="local-authority-eng:FAR">Fareham Borough Council</option>
    <option value="local-authority-eng:FEN">Fenland District Council</option>
    <option value="local-authority-eng:FOE">Forest of Dean District Council</option>
    <option value="local-authority-eng:FOR">Forest Heath District Council</option>
    <option value="local-authority-eng:FYL">Fylde Borough Council</option>
    <option value="local-authority-eng:GAT">Gateshead Metropolitan Borough Council</option>
    <option value="local-authority-eng:GED">Gedling Borough Council</option>
    <option value="local-authority-eng:GLA">Greater London Authority</option>
    <option value="local-authority-eng:GLO">Gloucester City Council</option>
    <option value="local-authority-eng:GLS">Gloucestershire County Council</option>
    <option value="local-authority-eng:GMCA">Greater Manchester Combined Authority</option>
    <option value="local-authority-eng:GOS">Gosport Borough Council</option>
    <option value="local-authority-eng:GRA">Gravesham Borough Council</option>
    <option value="local-authority-eng:GRE">Royal Borough of Greenwich</option>
    <option value="local-authority-eng:GRT">Guildford Borough Council</option>
    <option value="local-authority-eng:GRY">Great Yarmouth Borough Council</option>
    <option value="local-authority-eng:HAA">Havant Borough Council</option>
    <option value="local-authority-eng:HAE">Hambleton District Council</option>
    <option value="local-authority-eng:HAG">Harrogate Borough Council</option>
    <option value="local-authority-eng:HAL">Halton Borough Council</option>
    <option value="local-authority-eng:HAM">Hampshire County Council</option>
    <option value="local-authority-eng:HAO">Harborough District Council</option>
    <option value="local-authority-eng:HAR">Harlow District Council</option>
    <option value="local-authority-eng:HAS">Hastings Borough Council</option>
    <option value="local-authority-eng:HAT">Hart District Council</option>
    <option value="local-authority-eng:HAV">London Borough of Havering</option>
    <option value="local-authority-eng:HCK">London Borough of Hackney</option>
    <option value="local-authority-eng:HEF">Herefordshire Council</option>
    <option value="local-authority-eng:HER">Hertsmere Borough Council</option>
    <option value="local-authority-eng:HIG">High Peak Borough Council</option>
    <option value="local-authority-eng:HIL">London Borough of Hillingdon</option>
    <option value="local-authority-eng:HIN">Hinckley and Bosworth Borough Council</option>
    <option value="local-authority-eng:HMF">London Borough of Hammersmith & Fulham</option>
    <option value="local-authority-eng:HNS">London Borough of Hounslow</option>
    <option value="local-authority-eng:HOR">Horsham District Council</option>
    <option value="local-authority-eng:HPL">Hartlepool Borough Council</option>
    <option value="local-authority-eng:HRT">Hertfordshire County Council</option>
    <option value="local-authority-eng:HRW">London Borough of Harrow</option>
    <option value="local-authority-eng:HRY">London Borough of Haringey</option>
    <option value="local-authority-eng:HUN">Huntingdonshire District Council</option>
    <option value="local-authority-eng:HYN">Hyndburn Borough Council</option>
    <option value="local-authority-eng:IOS">Council of the Isles of Scilly</option>
    <option value="local-authority-eng:IOW">Isle of Wight Council</option>
    <option value="local-authority-eng:IPS">Ipswich Borough Council</option>
    <option value="local-authority-eng:ISL">London Borough of Islington</option>
    <option value="local-authority-eng:KEC">Royal Borough of Kensington and Chelsea</option>
    <option value="local-authority-eng:KEN">Kent County Council</option>
    <option value="local-authority-eng:KET">Kettering Borough Council</option>
    <option value="local-authority-eng:KHL">Hull City Council</option>
    <option value="local-authority-eng:KIN">Borough Council of King's Lynn and West Norfolk</option>
    <option value="local-authority-eng:KIR">Kirklees Council</option>
    <option value="local-authority-eng:KTT">Royal Borough of Kingston upon Thames</option>
    <option value="local-authority-eng:KWL">Knowsley Metropolitan Borough Council</option>
    <option value="local-authority-eng:LAC">Lancaster City Council</option>
    <option value="local-authority-eng:LAN">Lancashire County Council</option>
    <option value="local-authority-eng:LBH">London Borough of Lambeth</option>
    <option value="local-authority-eng:LCE">Leicester City Council</option>
    <option value="local-authority-eng:LCR">Liverpool City Region</option>
    <option value="local-authority-eng:LDS">Leeds City Council</option>
    <option value="local-authority-eng:LEC">Leicestershire County Council</option>
    <option value="local-authority-eng:LEE">Lewes District Council</option>
    <option value="local-authority-eng:LEW">London Borough of Lewisham</option>
    <option value="local-authority-eng:LIC">City of Lincoln Council</option>
    <option value="local-authority-eng:LIF">Lichfield District Council</option>
    <option value="local-authority-eng:LIN">Lincolnshire County Council</option>
    <option value="local-authority-eng:LIV">Liverpool City Council</option>
    <option value="local-authority-eng:LND">City of London Corporation</option>
    <option value="local-authority-eng:LUT">Luton Borough Council</option>
    <option value="local-authority-eng:MAI">Maidstone Borough Council</option>
    <option value="local-authority-eng:MAL">Maldon District Council</option>
    <option value="local-authority-eng:MAN">Manchester City Council</option>
    <option value="local-authority-eng:MAS">Mansfield District Council</option>
    <option value="local-authority-eng:MAV">Malvern Hills District Council</option>
    <option value="local-authority-eng:MDB">Middlesbrough Borough Council</option>
    <option value="local-authority-eng:MDE">Mid Devon District Council</option>
    <option value="local-authority-eng:MDW">Medway Council</option>
    <option value="local-authority-eng:MEL">Melton Borough Council</option>
    <option value="local-authority-eng:MEN">Mendip District Council</option>
    <option value="local-authority-eng:MIK">Milton Keynes Council</option>
    <option value="local-authority-eng:MOL">Mole Valley District Council</option>
    <option value="local-authority-eng:MRT">London Borough of Merton</option>
    <option value="local-authority-eng:MSS">Mid Sussex District Council</option>
    <option value="local-authority-eng:MSU">Mid Suffolk District Council</option>
    <option value="local-authority-eng:NBL">Northumberland County Council</option>
    <option value="local-authority-eng:NDE">North Devon District Council</option>
    <option value="local-authority-eng:NDO">North Dorset District Council</option>
    <option value="local-authority-eng:NEA">Newark and Sherwood District Council</option>
    <option value="local-authority-eng:NEC">Newcastle-under-Lyme Borough Council</option>
    <option value="local-authority-eng:NECA">North East Combined Authority</option>
    <option value="local-authority-eng:NED">North East Derbyshire District Council</option>
    <option value="local-authority-eng:NEL">North East Lincolnshire Council</option>
    <option value="local-authority-eng:NET">Newcastle City Council</option>
    <option value="local-authority-eng:NEW">New Forest District Council</option>
    <option value="local-authority-eng:NFK">Norfolk County Council</option>
    <option value="local-authority-eng:NGM">Nottingham City Council</option>
    <option value="local-authority-eng:NHE">North Hertfordshire District Council</option>
    <option value="local-authority-eng:NKE">North Kesteven District Council</option>
    <option value="local-authority-eng:NLN">North Lincolnshire Council</option>
    <option value="local-authority-eng:NNO">North Norfolk District Council</option>
    <option value="local-authority-eng:NOR">Northampton Borough Council</option>
    <option value="local-authority-eng:NOW">Norwich City Council</option>
    <option value="local-authority-eng:NSM">North Somerset  Council</option>
    <option value="local-authority-eng:NTCA">North of Tyne Combined Authority</option>
    <option value="local-authority-eng:NTH">Northamptonshire County Council</option>
    <option value="local-authority-eng:NTT">Nottinghamshire County Council</option>
    <option value="local-authority-eng:NTY">North Tyneside Council</option>
    <option value="local-authority-eng:NUN">Nuneaton and Bedworth Borough Council</option>
    <option value="local-authority-eng:NWA">North Warwickshire Borough Council</option>
    <option value="local-authority-eng:NWL">North West Leicestershire District Council</option>
    <option value="local-authority-eng:NWM">London Borough of Newham</option>
    <option value="local-authority-eng:NYK">North Yorkshire County Council</option>
    <option value="local-authority-eng:OAD">Oadby and Wigston Borough Council</option>
    <option value="local-authority-eng:OLD">Oldham Metropolitan Borough Council</option>
    <option value="local-authority-eng:OXF">Oxfordshire County Council</option>
    <option value="local-authority-eng:OXO">Oxford City Council</option>
    <option value="local-authority-eng:PEN">Pendle Borough Council</option>
    <option value="local-authority-eng:PLY">Plymouth City Council</option>
    <option value="local-authority-eng:POL">Borough of Poole</option>
    <option value="local-authority-eng:POR">Portsmouth City Council</option>
    <option value="local-authority-eng:PRE">Preston City Council</option>
    <option value="local-authority-eng:PTE">Peterborough City Council</option>
    <option value="local-authority-eng:PUR">Purbeck District Council</option>
    <option value="local-authority-eng:RCC">Redcar and Cleveland Borough Council</option>
    <option value="local-authority-eng:RCH">Rochdale Metropolitan Borough Council</option>
    <option value="local-authority-eng:RDB">London Borough of Redbridge</option>
    <option value="local-authority-eng:RDG">Reading Borough Council</option>
    <option value="local-authority-eng:RED">Redditch Borough Council</option>
    <option value="local-authority-eng:REI">Reigate and Banstead Borough Council</option>
    <option value="local-authority-eng:RIB">Ribble Valley Borough Council</option>
    <option value="local-authority-eng:RIC">London Borough of Richmond upon Thames</option>
    <option value="local-authority-eng:RIH">Richmondshire District Council</option>
    <option value="local-authority-eng:ROC">Rochford District Council</option>
    <option value="local-authority-eng:ROH">Rother District Council</option>
    <option value="local-authority-eng:ROS">Rossendale Borough Council</option>
    <option value="local-authority-eng:ROT">Rotherham Metropolitan Borough Council</option>
    <option value="local-authority-eng:RUG">Rugby Borough Council</option>
    <option value="local-authority-eng:RUH">Rushmoor Borough Council</option>
    <option value="local-authority-eng:RUN">Runnymede Borough Council</option>
    <option value="local-authority-eng:RUS">Rushcliffe Borough Council</option>
    <option value="local-authority-eng:RUT">Rutland County Council</option>
    <option value="local-authority-eng:RYE">Ryedale District Council</option>
    <option value="local-authority-eng:SAL">St Albans City and District Council</option>
    <option value="local-authority-eng:SAW">Sandwell Metropolitan Borough Council</option>
    <option value="local-authority-eng:SBU">South Bucks District Council</option>
    <option value="local-authority-eng:SCA">South Cambridgeshire District Council</option>
    <option value="local-authority-eng:SCE">Scarborough Borough Council</option>
    <option value="local-authority-eng:SCR">Sheffield City Region</option>
    <option value="local-authority-eng:SDE">South Derbyshire District Council</option>
    <option value="local-authority-eng:SED">St Edmundsbury Borough Council</option>
    <option value="local-authority-eng:SEG">Sedgemoor District Council</option>
    <option value="local-authority-eng:SEL">Selby District Council</option>
    <option value="local-authority-eng:SEV">Sevenoaks District Council</option>
    <option value="local-authority-eng:SFK">Suffolk County Council</option>
    <option value="local-authority-eng:SFT">Sefton Metropolitan Borough Council</option>
    <option value="local-authority-eng:SGC">South Gloucestershire Council</option>
    <option value="local-authority-eng:SHA">South Hams District Council</option>
    <option value="local-authority-eng:SHE">Folkestone and Hythe Council</option>
    <option value="local-authority-eng:SHF">Sheffield City Council</option>
    <option value="local-authority-eng:SHN">St Helens Council</option>
    <option value="local-authority-eng:SHO">South Holland District Council</option>
    <option value="local-authority-eng:SHR">Shropshire Council</option>
    <option value="local-authority-eng:SKE">South Kesteven District Council</option>
    <option value="local-authority-eng:SKP">Stockport Metropolitan Borough Council</option>
    <option value="local-authority-eng:SLA">South Lakeland District Council</option>
    <option value="local-authority-eng:SLF">Salford City Council</option>
    <option value="local-authority-eng:SLG">Slough Borough Council</option>
    <option value="local-authority-eng:SND">Sunderland City Council</option>
    <option value="local-authority-eng:SNO">South Norfolk District Council</option>
    <option value="local-authority-eng:SNR">South Northamptonshire Council</option>
    <option value="local-authority-eng:SOL">Solihull Metropolitan Borough Council</option>
    <option value="local-authority-eng:SOM">Somerset County Council</option>
    <option value="local-authority-eng:SOS">Southend-on-Sea Borough Council</option>
    <option value="local-authority-eng:SOX">South Oxfordshire District Council</option>
    <option value="local-authority-eng:SPE">Spelthorne Borough Council</option>
    <option value="local-authority-eng:SRI">South Ribble Borough Council</option>
    <option value="local-authority-eng:SRY">Surrey County Council</option>
    <option value="local-authority-eng:SSO">South Somerset District Council</option>
    <option value="local-authority-eng:SST">South Staffordshire Council</option>
    <option value="local-authority-eng:STA">Stafford Borough Council</option>
    <option value="local-authority-eng:STE">Stoke-on-Trent City Council</option>
    <option value="local-authority-eng:STF">Staffordshire Moorlands District Council</option>
    <option value="local-authority-eng:STH">Southampton City Council</option>
    <option value="local-authority-eng:STN">London Borough of Sutton</option>
    <option value="local-authority-eng:STO">Stroud District Council</option>
    <option value="local-authority-eng:STR">Stratford-on-Avon District Council</option>
    <option value="local-authority-eng:STS">Staffordshire County Council</option>
    <option value="local-authority-eng:STT">Stockton-on-Tees Borough Council</option>
    <option value="local-authority-eng:STV">Stevenage Borough Council</option>
    <option value="local-authority-eng:STY">South Tyneside Council</option>
    <option value="local-authority-eng:SUF">Suffolk Coastal District Council</option>
    <option value="local-authority-eng:SUR">Surrey Heath Borough Council</option>
    <option value="local-authority-eng:SWD">Swindon Borough Council</option>
    <option value="local-authority-eng:SWK">London Borough of Southwark</option>
    <option value="local-authority-eng:SWL">Swale Borough Council</option>
    <option value="local-authority-eng:SWT">Somerset West and Taunton Council</option>
    <option value="local-authority-eng:TAM">Tameside Metropolitan Borough Council</option>
    <option value="local-authority-eng:TAN">Tandridge District Council</option>
    <option value="local-authority-eng:TAU">Taunton Deane Borough Council</option>
    <option value="local-authority-eng:TAW">Tamworth Borough Council</option>
    <option value="local-authority-eng:TEI">Teignbridge District Council</option>
    <option value="local-authority-eng:TEN">Tendring District Council</option>
    <option value="local-authority-eng:TES">Test Valley Borough Council</option>
    <option value="local-authority-eng:TEW">Tewkesbury Borough Council</option>
    <option value="local-authority-eng:TFW">Telford & Wrekin Council</option>
    <option value="local-authority-eng:THA">Thanet District Council</option>
    <option value="local-authority-eng:THE">Three Rivers District Council</option>
    <option value="local-authority-eng:THR">Thurrock Council</option>
    <option value="local-authority-eng:TOB">Torbay Council</option>
    <option value="local-authority-eng:TON">Tonbridge and Malling Borough Council</option>
    <option value="local-authority-eng:TOR">Torridge District Council</option>
    <option value="local-authority-eng:TRF">Trafford Metropolitan Borough Council</option>
    <option value="local-authority-eng:TUN">Tunbridge Wells Borough Council</option>
    <option value="local-authority-eng:TVCA">Tees Valley Combined Authority</option>
    <option value="local-authority-eng:TWH">London Borough of Tower Hamlets</option>
    <option value="local-authority-eng:UTT">Uttlesford District Council</option>
    <option value="local-authority-eng:VAL">Vale of White Horse District Council</option>
    <option value="local-authority-eng:WAE">Waverley Borough Council</option>
    <option value="local-authority-eng:WAR">Warwickshire County Council</option>
    <option value="local-authority-eng:WAT">Watford Borough Council</option>
    <option value="local-authority-eng:WAV">Waveney District Council</option>
    <option value="local-authority-eng:WAW">Warwick District Council</option>
    <option value="local-authority-eng:WBK">West Berkshire Council</option>
    <option value="local-authority-eng:WDE">West Devon Borough Council</option>
    <option value="local-authority-eng:WDO">West Dorset District Council</option>
    <option value="local-authority-eng:WEA">Wealden District Council</option>
    <option value="local-authority-eng:WECA">West of England Combined Authority</option>
    <option value="local-authority-eng:WEL">Wellingborough Borough Council</option>
    <option value="local-authority-eng:WEW">Welwyn Hatfield Borough Council</option>
    <option value="local-authority-eng:WEY">Weymouth and Portland Borough Council</option>
    <option value="local-authority-eng:WFT">London Borough of Waltham Forest</option>
    <option value="local-authority-eng:WGN">Wigan Metropolitan Borough Council</option>
    <option value="local-authority-eng:WIL">Wiltshire Council</option>
    <option value="local-authority-eng:WIN">Winchester City Council</option>
    <option value="local-authority-eng:WKF">Wakefield Metropolitan District Council</option>
    <option value="local-authority-eng:WLA">West Lancashire Borough Council</option>
    <option value="local-authority-eng:WLI">West Lindsey District Council</option>
    <option value="local-authority-eng:WLL">Walsall Metropolitan Borough Council</option>
    <option value="local-authority-eng:WLV">City of Wolverhampton Council</option>
    <option value="local-authority-eng:WMCA">West Midlands Combined Authority</option>
    <option value="local-authority-eng:WND">London Borough of Wandsworth</option>
    <option value="local-authority-eng:WNM">Royal Borough of Windsor and Maidenhead</option>
    <option value="local-authority-eng:WOC">Worcester City Council</option>
    <option value="local-authority-eng:WOI">Woking Borough Council</option>
    <option value="local-authority-eng:WOK">Wokingham Borough Council</option>
    <option value="local-authority-eng:WOR">Worcestershire County Council</option>
    <option value="local-authority-eng:WOT">Worthing Borough Council</option>
    <option value="local-authority-eng:WOX">West Oxfordshire District Council</option>
    <option value="local-authority-eng:WRL">Wirral Borough Council</option>
    <option value="local-authority-eng:WRT">Warrington Borough Council</option>
    <option value="local-authority-eng:WSK">West Suffolk Council</option>
    <option value="local-authority-eng:WSM">City of Westminster</option>
    <option value="local-authority-eng:WSO">West Somerset District Council</option>
    <option value="local-authority-eng:WSX">West Sussex County Council</option>
    <option value="local-authority-eng:WYC">Wychavon District Council</option>
    <option value="local-authority-eng:WYCA">West Yorkshire Combined Authority</option>
    <option value="local-authority-eng:WYE">Wyre Forest District Council</option>
    <option value="local-authority-eng:WYO">Wycombe District Council</option>
    <option value="local-authority-eng:WYR">Wyre Borough Council</option>
    <option value="local-authority-eng:YOR">City of York Council</option>
    <option value="national-park-authority:Q20198711">South Downs National Park Authority</option>
    <option value="national-park-authority:Q27159704">Lake District National Park Authority</option>
    <option value="national-park-authority:Q27178932">Yorkshire Dales National Park Authority</option>
    <option value="national-park-authority:Q4972284">Broads Authority</option>
    <option value="national-park-authority:Q5225646">Dartmoor National Park Authority</option>
    <option value="national-park-authority:Q72617158">New Forest National Park Authority</option>
    <option value="national-park-authority:Q72617669">North York Moors National Park Authority</option>
    <option value="national-park-authority:Q72617784">Exmoor National Park Authority</option>
    <option value="national-park-authority:Q72617890">Northumberland National Park Authority</option>
    <option value="national-park-authority:Q72617988">Peak District National Park Authority</option>
    <option value="public-authority:Q5533909">GeoPlace</option>
    <option value="regional-park-authority:Q6515400">Lee Valley Regional Park Authority</option>
    <option value="transport-authority:Q25171369">West Midlands Passenger Transport Executive</option>
    <option value="transport-authority:Q6820591">Merseytravel</option>
    <option value="transport-authority:Q682520">Transport for London</option>
    <option value="transport-authority:Q7569004">South Yorkshire Passenger Transport Executive</option>
    <option value="transport-authority:Q7834921">Transport for Greater Manchester</option>
    <option value="transport-authority:Q7860508">Tyne and Wear Passenger Transport Executive</option>
    <option value="transport-authority:Q7985947">Transport for West Midlands</option>
    <option value="transport-authority:Q7987043">West Yorkshire Passenger Transport Executive</option>
    <option value="waste-authority:Q20711950">East London Waste Authority</option>
    <option value="waste-authority:Q20713477">North London Waste Authority</option>
    <option value="waste-authority:Q21921612">West London Waste Authority</option>
    <option value="waste-authority:Q21935501">Western Riverside Waste Authority</option>
    <option value="waste-authority:Q5600652">Greater Manchester Waste Disposal Authority</option>
  </select>
</div>
  <p class="govuk-!-margin-bottom-0 govuk-!-margin-top-1 dl-map__error js-hidden" data-module="organisation-search-error">Boundary for organisation not found.</p>
</div>


    </div>



</div>


    </main>
</div>













  <footer class="govuk-footer " role="contentinfo">
  <div class="govuk-width-container dl-container--full-width">

    <div class="govuk-footer__meta">
      <div class="govuk-footer__meta-item govuk-footer__meta-item--grow">

          <h2 class="govuk-visually-hidden">Support links</h2>

            <ul class="govuk-footer__inline-list">

                <li class="govuk-footer__inline-list-item">
                  <a class="govuk-footer__link" href="/cookies">
                    Cookies
                  </a>
                </li>

                <li class="govuk-footer__inline-list-item">
                  <a class="govuk-footer__link" href="/accessibility-statement">
                    Accessibility statement
                  </a>
                </li>

            </ul>


            <div class="govuk-footer__meta-custom">
              The <a class="govuk-footer__link" href="https://github.com/digital-land/digital-land/">software</a> and <a class="govuk-footer__link" href="https://github.com/digital-land/digital-land/">data</a> used to build these pages is <a class="govuk-footer__link" href="https://github.com/digital-land/digital-land/blob/master/LICENSE">open source</a>.
            </div>


        <svg
          aria-hidden="true"
          focusable="false"
          class="govuk-footer__licence-logo"
          xmlns="http://www.w3.org/2000/svg"
          viewBox="0 0 483.2 195.7"
          height="17"
          width="41"
        >
          <path
            fill="currentColor"
            d="M421.5 142.8V.1l-50.7 32.3v161.1h112.4v-50.7zm-122.3-9.6A47.12 47.12 0 0 1 221 97.8c0-26 21.1-47.1 47.1-47.1 16.7 0 31.4 8.7 39.7 21.8l42.7-27.2A97.63 97.63 0 0 0 268.1 0c-36.5 0-68.3 20.1-85.1 49.7A98 98 0 0 0 97.8 0C43.9 0 0 43.9 0 97.8s43.9 97.8 97.8 97.8c36.5 0 68.3-20.1 85.1-49.7a97.76 97.76 0 0 0 149.6 25.4l19.4 22.2h3v-87.8h-80l24.3 27.5zM97.8 145c-26 0-47.1-21.1-47.1-47.1s21.1-47.1 47.1-47.1 47.2 21 47.2 47S123.8 145 97.8 145"
          />
        </svg>
        <span class="govuk-footer__licence-description">
          All content is available under the
          <a
            class="govuk-footer__link"
            href="https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/"
            rel="license"
          >Open Government Licence v3.0</a>, except where otherwise stated
        </span>
      </div>
      <div class="govuk-footer__meta-item">
        <a
          class="govuk-footer__link govuk-footer__copyright-logo"
          href="https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/"
        >© Crown copyright</a>
      </div>
    </div>
  </div>
</footer>










    <script src="/design-system/static/javascripts/digital-land-cookies.js"></script>
    <script async src='https://www.google-analytics.com/analytics.js'></script>






    <script src="/design-system/static/javascripts/govuk/govuk-frontend.js"></script>
    <script>
      // initiate all GOVUK components
      window.GOVUKFrontend.initAll();
    </script>



    <script src="/design-system/static/javascripts/digital-land-frontend.js"></script>
    <script>
      window.DLFrontend.initAll();
    </script>







<script src="/design-system/static/javascripts/vendor/govuk-accessible-autocomplete.min.js"></script>
<script>
(function(dlf, accessibleAutocomplete) {
  let organisationMapper = {}
  const bfsHelpers = DLMaps.brownfieldSites

  // create URL used to fetch boundaries
  function laBoundaryURL(st_geo_code) {
    return `https://raw.githubusercontent.com/digital-land/boundary-collection/master/collection/local-authority/${st_geo_code}/index.geojson`
  }

  // add a property to a feature
  function addProperty(feature, name, value) {
    if( feature.properties ) {
      feature.properties[name] = value
    }
  }

  const organisationActiveStyle = {
    fillOpacity: 0.2,
    weight: 2,
    color: '#FFDD00',
    fillColor: '#FFEE80'
  }

  // $elements needed for map functions
  const $mapElement = document.querySelector('[data-module="boundary-map"]')
  const $sidePanel = document.querySelector(".dl-map__side-panel")
  const $mapItems = document.querySelector("[data-module='dl-map-items']")
  const $boundaryCount = $mapItems.querySelector(".organisation-count")
  const $activeOrganisation = $mapItems.querySelector(".active-organisation")

  // needed for organisation search
  const $picker = document.querySelector('#dl-organisation-autocomplete')
  const $orgSearchError = document.querySelector("[data-module='organisation-search-error']")

  // initiate the map component
  const bfsmap = new DLMaps.Map($mapElement).init({})
  var localAuthorityBoundaries = bfsmap.createFeatureGroup("localAuthorityBoundaries").addTo(bfsmap.map)
  var brownfieldSiteGroups = bfsmap.createFeatureGroup('brownfieldSiteGroups').addTo(bfsmap.map)
  bfsmap.setMapHeight()

  function handleOrganisationSearch(val) {
    const orgname = dlf.utils.toCamelCase(val)
    if (laTracker.get(orgname)) {
      $orgSearchError.classList.add("js-hidden")
      const match = laTracker.get(orgname)
      selectOrganisation(match.name, match.boundaryLayer)
    } else {
      $orgSearchError.classList.remove("js-hidden")
    }
  }

  accessibleAutocomplete.enhanceSelectElement({
    selectElement: $picker,
    onConfirm: handleOrganisationSearch,
    confirmOnBlur: false
  })

  // in the real map the whole array is passed to the template
  var brownfieldPublishers = [
      {"count": 32, "id": "local-authority-eng:DEB", "name": "Derbyshire Dales District Council", "statistical_geography": "E07000035"},
      {"count": 34, "id": "local-authority-eng:HAL", "name": "Halton Borough Council", "statistical_geography": "E06000006"}
      ]

  organisationMapper = dlf.utils.createOrgMapper(brownfieldPublishers)
  bfsHelpers.registerOrganisationMapper(organisationMapper)

  function addUsefulPropertiesToFeature(feature, organisation) {
    addProperty(feature, "organisation", organisation.id)
    addProperty(feature, "organisation_name", organisation.name)
    addProperty(feature, "bfs_count", organisation.count)
    return feature
  }

  function updateActiveOrgPanel(name) {
    $activeOrganisation.textContent = name
    const $container = $activeOrganisation.parentElement
    if ($container.classList.contains("js-hidden")) {
      $container.classList.remove("js-hidden")
    }
  }

  function LayerTracker(defaultProps) {
    this.items = {}
    this._defaultProps = defaultProps || {}
  }
  LayerTracker.prototype.add = function(name, props) {
    const trackerId = dlf.utils.toCamelCase(name)
    // can i use spread???
    this.items[trackerId] = {...this._defaultProps, ...props}
    this.items[trackerId]["name"] = name
    return trackerId
  }
  LayerTracker.prototype.addToItem = function(name, k, v) {
    const trackerId = dlf.utils.toCamelCase(name)
    if (Object.prototype.hasOwnProperty.call(this.items, trackerId)) {
      this.items[trackerId][k] = v
    }
  }
  LayerTracker.prototype.get = function (name) {
    return this.items[dlf.utils.toCamelCase(name)]
  }

  var laTracker = new LayerTracker({"loadedBFS": false})
  console.log(laTracker)


  function brownfieldDataUrl(organisation){
    orgDir = dlf.utils.curie_to_url_part(organisation)
    return `https://raw.githubusercontent.com/digital-land/dataset/master/docs/brownfield-land/organisation/${orgDir}/sites.geojson`
  }

  function setActiveBoundaryLayer(layer) {
    // track which layer is active
    localAuthorityBoundaries.activeLayer = layer._leaflet_id
    localAuthorityBoundaries.eachLayer(function (layer) {
      layer.activeBoundary = false
      layer.setStyle(bfsmap.styles.defaultBoundaryStyle)
    })
    if (hasParentLayer(layer)) {
      layer.parentId["activeBoundary"] = true
      layer.parentId.setStyle(organisationActiveStyle)
    }

    // should this be done another way? i.e. trigger an event on the side panel?
    updateActiveOrgPanel(layer.feature.properties['organisation_name'])
  }

  function hasParentLayer(childLayer) {
    return Object.prototype.hasOwnProperty.call(childLayer, "parentId")
  }

  function setParentLayer(parentLayer, layerName) {
    parentLayer.activeBoundary = false
    laTracker.addToItem(layerName, "layer", parentLayer)
    for (var lId in parentLayer._layers) {
      if (Object.prototype.hasOwnProperty.call(parentLayer._layers, lId)) {
        const childLayer = parentLayer._layers[lId]
        childLayer.parentId = localAuthorityBoundaries.getLayer(parentLayer._leaflet_id)
        laTracker.addToItem(layerName, "boundaryLayer", childLayer)
      }
    }
  }

  function addHoverState (layer) {
    bfsmap.addLayerHoverState(layer, {
      check: function (layer) {
        return !Object.prototype.hasOwnProperty.call(layer, "parentId") || !layer.parentId.activeBoundary
      }
    })
  }

  function onSuccessfulBrownfieldLoad (layer, organisationName) {
    if (laTracker.get(organisationName)) {
      laTracker.get(organisationName).loadedBFS = true
    }
  }

  /**
   * Select the organisation -> highlights polygon and loads data if not loaded
   * @param  {String} organisationName Name of organisation to select, e.g. Harrogate Borough Council
   * @param  {Object} layer Leaflet layer. Should be the boundary polygon layer not the parent
   */
  // needs to be own function because called from multiple sources: click and organisation search
  function selectOrganisation(organisationName, layer) {
    setActiveBoundaryLayer(layer)
    bfsmap.zoomToLayer(layer)
    if (laTracker.get(organisationName)) {
      const url = laTracker.get(organisationName).brownfield_data_url
      bfsHelpers.loadSites(bfsmap, url, organisationName, {
        layerGroup: brownfieldSiteGroups,
        cb: onSuccessfulBrownfieldLoad
      })
    }
  }


  function addLayerClickEvent(feature, layer) {
    const organisation = layer.feature.properties.organisation
    const organisationName = organisationMapper[organisation]
    laTracker.addToItem(organisationName, "brownfield_data_url", brownfieldDataUrl(organisation)) 
    layer.on('click', function(e) {
      selectOrganisation(organisationName, layer)
    })
  }

  function setupAuthorityBoundaryLayer(feature, layer) {
    // function is run for each boundary that is plotted
    addHoverState(layer)
    addLayerClickEvent(feature, layer)
  }

  console.log(brownfieldPublishers.length)
  var failing = []
  Promise.allSettled(
    brownfieldPublishers.map(function(bP) {
      const url = laBoundaryURL(bP.statistical_geography)
      // track the organisation layer on the map
      const trackerId = laTracker.add(bP.name, {"id": bP.id})
      return fetch(url)
        .then(resp => resp.json())
        .then((data) => {
          data.features[0] = addUsefulPropertiesToFeature(data.features[0], bP)
          // create geojson feature layer (parent)
          var boundary = L.geoJSON(data, {
            style: bfsmap.styles.defaultBoundaryStyle,
            onEachFeature: setupAuthorityBoundaryLayer
          })
          .on("add", function(e) {
            // set currently added layer as parent for all children layers
            setParentLayer(e.target, bP.name)
          })
          .addTo(localAuthorityBoundaries)
          return boundary
        })
        .catch(function(err) {
          console.log(bP.id, 'error', err)
          failing.push([bP.id, bP.statistical_geography])
        })
    }
  )).then(boundaries => {
    // after all boundaries collected then fitBounds of map
    bfsmap.map.fitBounds(localAuthorityBoundaries.getBounds())
    bfsmap.hideLoader()
    $boundaryCount.textContent = brownfieldPublishers.length - failing.length
    $mapItems.classList.remove("js-hidden")
    $sidePanel.classList.remove("js-hidden")
  })

  // candidate for dl-maps.js?
  bfsmap.map.on("zoom", function(e) {
    const zoomLevel = bfsmap.map.getZoom()
    if (zoomLevel > 7) {
      brownfieldSiteGroups.addTo(bfsmap.map)
    } else {
      brownfieldSiteGroups.remove()
    }
  })

window.bfsmap = bfsmap
window.laTracker = laTracker

})(window.DLFrontend, window.accessibleAutocomplete)

</script>

  </body>
</html>
{% extends "digital-land-frontend/layouts/base--full-width.jinja" %}
{% from 'digital-land-frontend/components/map/macro.jinja' import dlMap %}

{% set includesMap = true %}
{% block pageTitle %}BFS Map | Digital Land{% endblock %}

{% block content %}
<div class="govuk-grid-row">
    <div class="govuk-grid-column-full">
    <h1 class="govuk-heading-xl">Map of brownfield land</h1>
    </div>
</div>

<p class="govuk-body-l">National view of the brownfield land  collected and collated by Digital Land.</p>

{% set sidePanelHTML %}
<div class="dl-map__side-panel__section">
<h3 class="govuk-heading-s govuk-!-margin-bottom-0">Displayed on map</h3>
</div>
<div class="dl-map__side-panel__section dl-map__side-panel__section--title js-hidden" data-module="dl-map-items">
  <p class="govuk-body govuk-!-margin-bottom-1"><span class="organisation-count"></span> organisation boundaries</p>
  <p class="govuk-body govuk-!-margin-top-3 govuk-!-margin-bottom-1 js-hidden">Active: <span class="active-organisation dl-map__highlight--yellow"></span></p>
</div>
<div class="dl-map__side-panel__section dl-map__side-panel__section--blue">
  {% include 'design-system/partials/dl-organisation-autocomplete.html' %}
  <p class="govuk-!-margin-bottom-0 govuk-!-margin-top-1 dl-map__error js-hidden" data-module="organisation-search-error">Boundary for organisation not found.</p>
</div>

{% endset %}

{{ dlMap({
    "id": "aMap",
    "classes": "govuk-!-margin-bottom-0",
    "height": 700,
    "loader": {
      "text": "Loading brownfield land data"
    },
    "sidePanel": {
      "html": sidePanelHTML,
      "classes": "js-hidden"
    }
}) }}
{% endblock %}

{% block bodyEnd %}
{{ super() }}
<script src="{{ staticPath|default('/static') }}/javascripts/vendor/govuk-accessible-autocomplete.min.js"></script>
<script>
(function(dlf, accessibleAutocomplete) {
  let organisationMapper = {}
  const bfsHelpers = DLMaps.brownfieldSites

  // create URL used to fetch boundaries
  function laBoundaryURL(st_geo_code) {
    return `https://raw.githubusercontent.com/digital-land/boundary-collection/master/collection/local-authority/${st_geo_code}/index.geojson`
  }

  // add a property to a feature
  function addProperty(feature, name, value) {
    if( feature.properties ) {
      feature.properties[name] = value
    }
  }

  const organisationActiveStyle = {
    fillOpacity: 0.2,
    weight: 2,
    color: '#FFDD00',
    fillColor: '#FFEE80'
  }

  // $elements needed for map functions
  const $mapElement = document.querySelector('[data-module="boundary-map"]')
  const $sidePanel = document.querySelector(".dl-map__side-panel")
  const $mapItems = document.querySelector("[data-module='dl-map-items']")
  const $boundaryCount = $mapItems.querySelector(".organisation-count")
  const $activeOrganisation = $mapItems.querySelector(".active-organisation")

  // needed for organisation search
  const $picker = document.querySelector('#dl-organisation-autocomplete')
  const $orgSearchError = document.querySelector("[data-module='organisation-search-error']")

  // initiate the map component
  const bfsmap = new DLMaps.Map($mapElement).init({})
  var localAuthorityBoundaries = bfsmap.createFeatureGroup("localAuthorityBoundaries").addTo(bfsmap.map)
  var brownfieldSiteGroups = bfsmap.createFeatureGroup('brownfieldSiteGroups').addTo(bfsmap.map)
  bfsmap.setMapHeight()

  function handleOrganisationSearch(val) {
    const orgname = dlf.utils.toCamelCase(val)
    if (laTracker.get(orgname)) {
      $orgSearchError.classList.add("js-hidden")
      const match = laTracker.get(orgname)
      selectOrganisation(match.name, match.boundaryLayer)
    } else {
      $orgSearchError.classList.remove("js-hidden")
    }
  }

  accessibleAutocomplete.enhanceSelectElement({
    selectElement: $picker,
    onConfirm: handleOrganisationSearch,
    confirmOnBlur: false
  })

  // in the real map the whole array is passed to the template
  var brownfieldPublishers = [
      {"count": 32, "id": "local-authority-eng:DEB", "name": "Derbyshire Dales District Council", "statistical_geography": "E07000035"},
      {"count": 34, "id": "local-authority-eng:HAL", "name": "Halton Borough Council", "statistical_geography": "E06000006"}
      ]

  organisationMapper = dlf.utils.createOrgMapper(brownfieldPublishers)
  bfsHelpers.registerOrganisationMapper(organisationMapper)

  function addUsefulPropertiesToFeature(feature, organisation) {
    addProperty(feature, "organisation", organisation.id)
    addProperty(feature, "organisation_name", organisation.name)
    addProperty(feature, "bfs_count", organisation.count)
    return feature
  }

  function updateActiveOrgPanel(name) {
    $activeOrganisation.textContent = name
    const $container = $activeOrganisation.parentElement
    if ($container.classList.contains("js-hidden")) {
      $container.classList.remove("js-hidden")
    }
  }

  function LayerTracker(defaultProps) {
    this.items = {}
    this._defaultProps = defaultProps || {}
  }
  LayerTracker.prototype.add = function(name, props) {
    const trackerId = dlf.utils.toCamelCase(name)
    // can i use spread???
    this.items[trackerId] = {...this._defaultProps, ...props}
    this.items[trackerId]["name"] = name
    return trackerId
  }
  LayerTracker.prototype.addToItem = function(name, k, v) {
    const trackerId = dlf.utils.toCamelCase(name)
    if (Object.prototype.hasOwnProperty.call(this.items, trackerId)) {
      this.items[trackerId][k] = v
    }
  }
  LayerTracker.prototype.get = function (name) {
    return this.items[dlf.utils.toCamelCase(name)]
  }

  var laTracker = new LayerTracker({"loadedBFS": false})
  console.log(laTracker)


  function brownfieldDataUrl(organisation){
    orgDir = dlf.utils.curie_to_url_part(organisation)
    return `https://raw.githubusercontent.com/digital-land/dataset/master/docs/brownfield-land/organisation/${orgDir}/sites.geojson`
  }

  function setActiveBoundaryLayer(layer) {
    // track which layer is active
    localAuthorityBoundaries.activeLayer = layer._leaflet_id
    localAuthorityBoundaries.eachLayer(function (layer) {
      layer.activeBoundary = false
      layer.setStyle(bfsmap.styles.defaultBoundaryStyle)
    })
    if (hasParentLayer(layer)) {
      layer.parentId["activeBoundary"] = true
      layer.parentId.setStyle(organisationActiveStyle)
    }

    // should this be done another way? i.e. trigger an event on the side panel?
    updateActiveOrgPanel(layer.feature.properties['organisation_name'])
  }

  function hasParentLayer(childLayer) {
    return Object.prototype.hasOwnProperty.call(childLayer, "parentId")
  }

  function setParentLayer(parentLayer, layerName) {
    parentLayer.activeBoundary = false
    laTracker.addToItem(layerName, "layer", parentLayer)
    for (var lId in parentLayer._layers) {
      if (Object.prototype.hasOwnProperty.call(parentLayer._layers, lId)) {
        const childLayer = parentLayer._layers[lId]
        childLayer.parentId = localAuthorityBoundaries.getLayer(parentLayer._leaflet_id)
        laTracker.addToItem(layerName, "boundaryLayer", childLayer)
      }
    }
  }

  function addHoverState (layer) {
    bfsmap.addLayerHoverState(layer, {
      check: function (layer) {
        return !Object.prototype.hasOwnProperty.call(layer, "parentId") || !layer.parentId.activeBoundary
      }
    })
  }

  function onSuccessfulBrownfieldLoad (layer, organisationName) {
    if (laTracker.get(organisationName)) {
      laTracker.get(organisationName).loadedBFS = true
    }
  }

  /**
   * Select the organisation -> highlights polygon and loads data if not loaded
   * @param  {String} organisationName Name of organisation to select, e.g. Harrogate Borough Council
   * @param  {Object} layer Leaflet layer. Should be the boundary polygon layer not the parent
   */
  // needs to be own function because called from multiple sources: click and organisation search
  function selectOrganisation(organisationName, layer) {
    setActiveBoundaryLayer(layer)
    bfsmap.zoomToLayer(layer)
    if (laTracker.get(organisationName)) {
      const url = laTracker.get(organisationName).brownfield_data_url
      bfsHelpers.loadSites(bfsmap, url, organisationName, {
        layerGroup: brownfieldSiteGroups,
        cb: onSuccessfulBrownfieldLoad
      })
    }
  }


  function addLayerClickEvent(feature, layer) {
    const organisation = layer.feature.properties.organisation
    const organisationName = organisationMapper[organisation]
    laTracker.addToItem(organisationName, "brownfield_data_url", brownfieldDataUrl(organisation)) 
    layer.on('click', function(e) {
      selectOrganisation(organisationName, layer)
    })
  }

  function setupAuthorityBoundaryLayer(feature, layer) {
    // function is run for each boundary that is plotted
    addHoverState(layer)
    addLayerClickEvent(feature, layer)
  }

  console.log(brownfieldPublishers.length)
  var failing = []
  Promise.allSettled(
    brownfieldPublishers.map(function(bP) {
      const url = laBoundaryURL(bP.statistical_geography)
      // track the organisation layer on the map
      const trackerId = laTracker.add(bP.name, {"id": bP.id})
      return fetch(url)
        .then(resp => resp.json())
        .then((data) => {
          data.features[0] = addUsefulPropertiesToFeature(data.features[0], bP)
          // create geojson feature layer (parent)
          var boundary = L.geoJSON(data, {
            style: bfsmap.styles.defaultBoundaryStyle,
            onEachFeature: setupAuthorityBoundaryLayer
          })
          .on("add", function(e) {
            // set currently added layer as parent for all children layers
            setParentLayer(e.target, bP.name)
          })
          .addTo(localAuthorityBoundaries)
          return boundary
        })
        .catch(function(err) {
          console.log(bP.id, 'error', err)
          failing.push([bP.id, bP.statistical_geography])
        })
    }
  )).then(boundaries => {
    // after all boundaries collected then fitBounds of map
    bfsmap.map.fitBounds(localAuthorityBoundaries.getBounds())
    bfsmap.hideLoader()
    $boundaryCount.textContent = brownfieldPublishers.length - failing.length
    $mapItems.classList.remove("js-hidden")
    $sidePanel.classList.remove("js-hidden")
  })

  // candidate for dl-maps.js?
  bfsmap.map.on("zoom", function(e) {
    const zoomLevel = bfsmap.map.getZoom()
    if (zoomLevel > 7) {
      brownfieldSiteGroups.addTo(bfsmap.map)
    } else {
      brownfieldSiteGroups.remove()
    }
  })

window.bfsmap = bfsmap
window.laTracker = laTracker

})(window.DLFrontend, window.accessibleAutocomplete)

</script>
{% endblock %}