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.
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 create a 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.
Click the button to Create an Access Token, then check the box under Secret Scopes called “TILESETS:READ”. Then click to CREATE TOKEN. Once that’s done, copy the token to your clipboard.
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. To do so, just add the code block for the map_layer you want to your model file. Then you can reference it by setting the map_layer_name
on the dimension in your view that contains the property key.
So, for example, if you were including the Canadian Provinces map_layer, you’d include the code block below in your model file and then do the following in your view:
dimension: english_province_name {
type: string
map_layer_name: 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"
}
Forward Sortation Areas (FSAs) are represented by the first three characters of the six-character Canadian ZIP code. There are approximately 1,600 FSAs in Canada. To load a map layer for FSA regions, use the following:
map_layer: canada_fsa {
format: "vector_tile_region"
url: "https://a.tiles.mapbox.com/v4/looker-maps.2ka31zfi/{z}/{x}/{y}.mvt?access_token=@{mapbox_api_key}"
feature_key: "lfsa000b16a_e-as0y69"
extents_json_url: "https://rawcdn.githack.com/dwmintz/looker_map_layers/49062485f99a0742f44857766d6aadff1b4d5f31/canada_fsa.json"
min_zoom_level: 5
max_zoom_level: 11
property_key: "CFSAUID"
}
Since many companies serve both the US and Canada, it might be helpful to have Canada's Forward Sortation Areas (FSAs) and US ZIP Code Tabulation Areas (ZCTAs) in a single map layer. This map_layer expects either a 3-character FSA or a 5-digit ZCTA in the postal code field.
map_layer: us_canada_postal_codes {
format: "vector_tile_region"
url: "https://a.tiles.mapbox.com/v4/looker-maps.8gkhpr0e/{z}/{x}/{y}.mvt?access_token=@{mapbox_api_key}"
feature_key: "us_canada_postal_codesgeojson"
extents_json_url: "https://rawcdn.githack.com/dwmintz/looker_map_layers/9a83b018f3e9db958ccfdf34cc601baec7995448/us_canada_postal_codes.json"
min_zoom_level: 3
max_zoom_level: 12
property_key: "POSTAL_CODE"
}
This layer can be used for mapping the 50+1 US states, the 31+1 Mexican states and the 10 + 3 Canadian provinces in a single layer. The layer expects the full names of the entities, with accents where appropriate. Canadian provinces use their English names.
map_layer: us_canada_postal_codes {
format: "vector_tile_region"
url: "https://a.tiles.mapbox.com/v4/looker-maps.490z8rk0/{z}/{x}/{y}.mvt?access_token=@{mapbox_api_key}"
feature_key: "na_provinces-1sin0g"
extents_json_url: "https://rawcdn.githack.com/dwmintz/looker_map_layers/b072977e16b4586657501a0409bf5e4ecc84bc58/na_provinces_extents.json"
min_zoom_level: 2
max_zoom_level: 8
property_key: "STATE"
}
Sometimes full ZIP codes are more granular than you want and the first three digits of the ZIP is more useful. This map_layer expects those three digits as a string.
map_layer: us_zip3 {
format: "vector_tile_region"
url: "https://a.tiles.mapbox.com/v4/looker-maps.6w6t82a6/{z}/{x}/{y}.mvt?access_token=@{mapbox_api_key}"
feature_key: "zip3-60pe24"
extents_json_url: "https://rawcdn.githack.com/dwmintz/looker_map_layers/e8f8cef33b776ad89cbb8772392addb1a29ea60e/zip3_extents.json"
min_zoom_level: 5
max_zoom_level: 11
property_key: "ZIP3"
}
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.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.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"
}
Use the GEOID to identify PUMAs (e.g. `2500302` for Worcester County (West Central) PUMA).
map_layer: us_pumas {
format: "vector_tile_region"
url: "https://a.tiles.mapbox.com/v4/looker-maps.9qdtc99b/{z}/{x}/{y}.mvt?access_token=@{mapbox_api_key}"
feature_key: "ipums_puma_2010-5ub0py"
extents_json_url: "https://rawcdn.githack.com/dwmintz/looker_map_layers/4a48ef77a012a9be8d9e1df7aa38e783f5f81e82/puma_extents.json"
min_zoom_level: 5
max_zoom_level: 11
property_key: "GEOID"
}
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"
}
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 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/daf65f60fd2f58665640418be05167ef25c2fdcc/uk_postal_districts.json"
min_zoom_level: 8
max_zoom_level: 13
property_key: "PostDist"
}
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/fc27a696834125e54f7d9a004870d34257016edf/uk_postal_sectors.json"
min_zoom_level: 8
max_zoom_level: 14
property_key: "RMSect"
}
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"
}
Italy is divided into 20 Regions (e.g. Toscana, Liguria), which are further subdivided into Provinces (e.g. Bergamo, Asti). Each Region in the region map_layer
has a code ("property_key: "COD_REG"
) as well as the name of the region (property_key: "NOME_REG"
) and you can use whichever you prefer to identify regions. n.b. Region names are ALL CAPS.
map_layer: regioni_italiani {
format: "vector_tile_region"
url: "https://a.tiles.mapbox.com/v4/looker-maps.61hkfosh/{z}/{x}/{y}.mvt?access_token=@{mapbox_api_key}"
feature_key: "reg2011_g"
extents_json_url: "https://rawcdn.githack.com/dwmintz/looker_map_layers/6894c6448fb0721f93e2ce4ce9c30659e6a30c06/regioni_italiani.json"
min_zoom_level: 3
max_zoom_level: 11
property_key: "NOME_REG"
}
Each Province in the province map_layer
has a code ("property_key: "COD_PRO"
) as well as the name of the region (property_key: "NOME_PRO"
) and you can use whichever you prefer to identify provinces. n.b. Province names are ALL CAPS.
map_layer: province_italiane {
format: "vector_tile_region"
url: "https://a.tiles.mapbox.com/v4/looker-maps.4ocnvk26/{z}/{x}/{y}.mvt?access_token=@{mapbox_api_key}"
feature_key: "province_ditalia"
extents_json_url: "https://rawcdn.githack.com/dwmintz/looker_map_layers/6894c6448fb0721f93e2ce4ce9c30659e6a30c06/province_italiane.json"
min_zoom_level: 3
max_zoom_level: 12
property_key: "NOME_PRO"
}