[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-31。"],[],[],null,["# Creating custom map regions\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003e ***Note:** In Looker 22.14, support for GeoJSON files was added to the [`map_layer`](/looker/docs/reference/param-model-map-layer) parameter.*\n\n\nLooker includes several built-in [map layers](/looker/docs/reference/param-model-map-layer#built-in_map_layers), but you can also define custom map regions to display geographical data. Suppose you have a table of average ages for three neighborhoods, as follows:\n\n\nYou might want to map **Customer Neighborhood** to a particular geographic\nregion, so it can be visualized on a map. To accomplish this, follow the\nsteps described on this page.\n\n\u003cbr /\u003e\n\nPrepare region data\n-------------------\n\n\nTo prepare the region data, you need a data file that contains the geographic\nshapes of each region and also contains metadata that associates the region with\nthe data in the database.\n\n\nLooker uses a format called\n[TopoJSON](https://github.com/topojson/topojson) to store this data\nin a compact way. TopoJSON files can be easily created from many common shapefile\nformats, or you can draw one yourself with online tools, as detailed in the\n[Converting shapefiles to TopoJSON](https://community.looker.com/technical-tips-tricks-1021/converting-shapefiles-to-topojson-30011) Community post.\n\n\nFor the purposes of this example, there would already be a TopoJSON file prepared that provides this mapping. Each region in the TopoJSON file has a property called `neighborhood` that matches the values of the\n**Customer Neighborhood** field, which is defined in the LookML project as a dimension called `neighborhood`.\n\nUpload region data\n------------------\n\n\nTo import the region data into Looker, you can drag and drop the TopoJSON file into the **File Browser** section of the project. This data will be committed alongside the LookML code and updated like any other code in a LookML project.\n\n\nYour browser does not support the embedded video.\n\nCreate the map layer\n--------------------\n\n\nNow that you have the region data in the project, you need to create a map layer in the LookML model.\n\n\nYou can add a definition in the model file using the [`map_layer`](/looker/docs/reference/param-model-map-layer) parameter: \n\n```\nmap_layer: my_neighborhood_layer {\n file: \"neighborhoods.topojson\"\n property_key: \"neighborhood\"\n}\n```\n\n\nThe `file` parameter references the name of the file in the project that contains the region data, and the `property_key` is the property of the dataset that you want to expose within Looker. If you're not sure what the key is, simply omit the property key and Looker will attempt to select the appropriate key.\n\n\n\u003e **Tip:** You can also use a TopoJSON file that's hosted elsewhere online, by specifying `url` instead of `file` in the layer definition:\n\n\u003cbr /\u003e\n\n```\nmap_layer: my_neighborhood_layer {\n url: \"https://raw.githubusercontent.com/cooluser/JSON_Stuff/master/Neighborhoods.topoJSON\"\n property_key: \"neighborhood\"\n}\n```\n\nAssociate the map layer with data\n---------------------------------\n\n\nThe only thing left to do is to associate the dimension `neighborhood` in the view with the newly created map layer by applying the [`map_layer_name`](/looker/docs/reference/param-field-map-layer-name) parameter. \n\n```\ndimension: neighborhood {\n sql: ${TABLE}.neighborhood ;;\n map_layer_name: my_neighborhood_layer\n}\n \n```\n\n\nThis tells Looker that the values of this dimension are associated with the `property_key` exposed by the map layer. It also lets Looker know that it's possible to display this data on a map.\n\nViewing the map\n---------------\n\n\nThe queries that use the `neighborhood` dimension can now be displayed on a map from the Explore page:"]]