Adding common map_layers to your instance

It’s now easier than ever to access common world map_layers in Looker. Just drop these bits of code in your model and you’re good to go.

One-time setup

Set Your Mapbox Token

To use any of these map_layers, you’ll need to create a free account on Mapbox.com. Once you’ve created your account, go to your account page to grab your default public token. This free token entitles you to up to 200,000 map loads per month. If you’re using more than that, you’ll need to start paying for a Mapbox account.

Add your Mapbox Token as a LookML Constant

Next, you’ll need to go to the LookML project where you’re going to be using maps and create a manifest file (if one doesn’t already exist). Create a constant parameter with your Mapbox token like this:

constant: mapbox_api_key {
  value: "[YOUR_DEFAULT_PUBLIC_TOKEN_FROM_MAPBOX]"
}

That’s it. Now you’re good to add as many map_layers as you want to this project from the list below:

Available map_layers

Canadian Provinces

If you'd like to use the English name of the Canadian provinces as the key (e.g. Quebec, British Columbia, etc.), use the following:
map_layer: canadian_provinces {
  format: "vector_tile_region"
  url: "https://a.tiles.mapbox.com/v4/looker-maps.oh_canada/{z}/{x}/{y}.mvt?access_token=@{mapbox_api_key}"
  feature_key: "provinces"
  extents_json_url: "https://rawcdn.githack.com/dwmintz/looker_map_layers/c98a443cfd7dc93191a3f3f6c54059b9a35a9134/canada_provinces.json"
  min_zoom_level: 2
  max_zoom_level: 10
  property_key: "PRENAME"
}

If you’d prefer to use the Standard geographical classification (SGC) code (e.g. 13 for New Brunswick, 48 for Alberta, etc.), use the following:

map_layer: canadian_provinces {
  format: "vector_tile_region"
  url: "https://a.tiles.mapbox.com/v4/looker-maps.oh_canada/{z}/{x}/{y}.mvt?access_token=@{mapbox_api_key}"
  feature_key: "provinces"
  extents_json_url: "https://rawcdn.githack.com/dwmintz/looker_map_layers/f5734c99c6ed23ce02e5c368e3774c2a59e82242/canada-provinces-id.json"
  min_zoom_level: 2
  max_zoom_level: 10
  property_key: "PRUID"
}

United States Core Based Statistical Areas

If you'd like to use the GEOID to identify CBSAs (e.g. `10180` for Abilene, TX, `18700` for Corvallis, OR), use the following:
map_layer: us_cbsa {
  format: "vector_tile_region"
  url: "https://a.tiles.mapbox.com/v4/looker-maps.looker-maps.us_cbsa/{z}/{x}/{y}.mvt?access_token=@{mapbox_api_key}"
  feature_key: "us_cbsas"
  extents_json_url: "https://rawcdn.githack.com/dwmintz/looker_map_layers/ecb8d20baa3fc2c4c77023011f2dfd26ee7a8f02/us_cbsa_geoid"
  min_zoom_level: 4
  max_zoom_level: 13
  property_key: "GEOID"
}

If you’d prefer to use the name of the CBSA (e.g. Augusta-Waterville, ME), use the following:

map_layer: us_cbsa {
  format: "vector_tile_region"
  url: "https://a.tiles.mapbox.com/v4/looker-maps.looker-maps.us_cbsa/{z}/{x}/{y}.mvt?access_token=@{mapbox_api_key}"
  feature_key: "us_cbsas"
  extents_json_url: "https://rawcdn.githack.com/dwmintz/looker_map_layers/ecb8d20baa3fc2c4c77023011f2dfd26ee7a8f02/us_cbsa_name"
  min_zoom_level: 4
  max_zoom_level: 13
  property_key: "NAME"
}

United States Census Tracts (2010)

Census tracts are identified by a 11-digit code called a GEOID, where the first two digits represent the state, the next three digits the county, and the last six digits the tract. This should be stored as a string.

map_layer: census_tract {
  format: "vector_tile_region"
  url: "https://a.tiles.mapbox.com/v4/dwmintz.3zfb3asw/{z}/{x}/{y}.mvt?access_token=@{mapbox_api_key}"
  feature_key: "us_tracts-6w08eq"
  extents_json_url: "https://cdn.rawgit.com/dwmintz/census_extents2/396e32db/tract_extents.json"
  min_zoom_level: 6
  max_zoom_level: 14
  property_key: "GEOID"
}

United States Block Groups (2010)

Census block groups are identified by a 13-digit code called a GEOID, where the first two digits represent the state, the next three digits the county, and the next six digits the tract, and the last two digits the block group. This should be stored as a string.

map_layer: block_group {
  format: "vector_tile_region"
  url: "https://a.tiles.mapbox.com/v4/dwmintz.4mqiv49l/{z}/{x}/{y}.mvt?access_token=@{mapbox_api_key}"
  feature_key: "us_block_groups_simple-c0qtbp"
  extents_json_url: "https://cdn.rawgit.com/dwmintz/census_extents2/59fa2cd8/bg_extents.json"
  min_zoom_level: 5
  max_zoom_level: 16
  property_key: "GEOID"
}

UK Postal Districts (2012)

UK Post Codes are alphanumeric codes of six-to-eight characters (including a space). The portion before the space is known as the outer code and consists of the postal area (already included as a default map_layer in Looker) and the postal district.

To map postal districts (e.g. SW1W, AB10, etc.) use the following:

map_layer: uk_postal_districts {
  format: "vector_tile_region"
  url: "https://a.tiles.mapbox.com/v4/looker-maps.63tiis35/{z}/{x}/{y}.mvt?access_token=@{mapbox_api_key}"
  feature_key: "PostalDistrict-5b1t0d"
  extents_json_url: "https://rawcdn.githack.com/dwmintz/looker_map_layers/6b7c7cff6d193189cca4f73b314f558e8ee58f85/uk_postal_districts.json"
  min_zoom_level: 8
  max_zoom_level: 13
  property_key: "PostDist"
}

UK Postal Sectors (2012)

UK Post Codes are alphanumeric codes of six-to-eight characters (including a space). The portion before the space is known as the outer code and consists of the postal area (already included as a default map_layer in Looker) and the postal district. The portion after the space is the inner code and consists of the postal sector (the first digit) and the postal unit (the rest).

To map postal sectors (e.g. EC2R 8, BT9 6, etc.) use the following (yes, include the space):

map_layer: uk_postal_sectors {
  format: "vector_tile_region"
  url: "https://a.tiles.mapbox.com/v4/looker-maps.cq6lxp6d/{z}/{x}/{y}.mvt?access_token=@{mapbox_api_key}"
  feature_key: "PostalSector-2trpb4"
  extents_json_url: "https://rawcdn.githack.com/dwmintz/looker_map_layers/6b7c7cff6d193189cca4f73b314f558e8ee58f85/uk_postal_sectors.json"
  min_zoom_level: 8
  max_zoom_level: 14
  property_key: "RMSect"
}

Codes Postaux de France (2015)

French post codes (codes postaux de France) are five-digit strings. This layer includes all the post codes for la Métropole (mainland France, Corsica, and Atlantic/Mediterranean islands). It does not include France d’outre-mer.

Post codes should be formatted as strings (e.g. 75001 for Île de la Cité, 33250 for Pauillac)

map_layer: codes_postaux {
  format: "vector_tile_region"
  url: "https://a.tiles.mapbox.com/v4/looker-maps.4opqm5ya/{z}/{x}/{y}.mvt?access_token=@{mapbox_api_key}"
  feature_key: "codes_postaux_V5_2_2-4z5c9k"
  extents_json_url: "https://rawcdn.githack.com/dwmintz/looker_map_layers/db083551a3705d4f3e0b93ce1862f7bc25abf452/codes_postaux_france.json"
  min_zoom_level: 3
  max_zoom_level: 11
  property_key: "ID"
}
3 Likes