From 08550b99a079688110a65b8771e7c62771c707bf Mon Sep 17 00:00:00 2001 From: Weiming Date: Tue, 17 Sep 2019 23:53:04 -0400 Subject: [PATCH 1/2] translation done --- Tutorials/power-bi.md | 164 +++++++++++++++++++++--------------------- 1 file changed, 81 insertions(+), 83 deletions(-) diff --git a/Tutorials/power-bi.md b/Tutorials/power-bi.md index f2623f0..74103b8 100644 --- a/Tutorials/power-bi.md +++ b/Tutorials/power-bi.md @@ -16,186 +16,184 @@ prependJs: contentType: tutorial --- -Create customizable heatmaps, point cluster maps, and graduated circle maps with the **Mapbox Visual for Power BI** using Microsoft Power BI Desktop and Online. The Mapbox Visual can be imported and accessed as a visualization plugin inside Power BI. This guide will walk through getting started with the Mapbox Visual and how to create a Mapbox-powered visualization in [Microsoft Power BI](https://powerbi.microsoft.com/en-us/). You will need a Mapbox account and a Microsoft Power BI account to complete this tutorial. +通过使用微软Power BI桌面版以及在线版所提供的Mapbox Visual工具,制作可定制化的热力图、点状聚类图以及可变尺寸圆圈统计图。 + +Mapbox Visual可以在Power BI程序中作为一个可视化插件使用。此教程将会展示Mapbox Visual的一些初级使用技巧以及如何使用[微软Power BI](https://powerbi.microsoft.com/en-us/)来创建一个Mapbox驱动的可视化实例。此教程要求您已经拥有一个Mapbox的账号以及一个微软Power BI的账号。 ![an interactive data visualization on a map](/help/img/3rdparty/power-bi-final-product.gif) -## Getting started +## 准备工作 -Here are a few resources you'll need before you get started: +您需要进行以下准备工作: -- **Mapbox account**. You will need a Mapbox access token to add the Mapbox Visual in Power BI. Sign up for a free account on [Mapbox](https://account.mapbox.com/auth/signup/). -- **Power BI account**. Sign into your [Power BI account](https://app.powerbi.com/) or create a new one. -- **Mapbox Visual for Microsoft Power BI**. You can either add the Mapbox Visual using the Power BI Marketplace, or you can download the latest Mapbox Visual from the open-source GitHub repository. Both of these options are explained in detail in the tutorial. -- **Data**. This guide uses a sample CSV file with US healthcare spending derived from [data.gov](https://catalog.data.gov/dataset/). +- **Mapbox账号**:如果要将Mapbox Visual工具添加到Power BI程序中,您将需要一个Mapbox秘钥。此秘钥可以通过[免费注册](https://account.mapbox.com/auth/signup/)获取。 +- **Power BI账号**:登陆您的[Power BI账号](https://app.powerbi.com/)或者创建一个新的账号。 +- **支持微软Power BI的Mapbox Visual插件**:您可以在Power BI应用中心找到并添加Mapbox Visual,或者您也可以从[Github](https://github.com/mapbox/mapboxgl-powerbi)下载[Mapbox Visual最新版本](https://github.com/mapbox/mapboxgl-powerbi/raw/master/dist/mapboxGLMap.pbiviz)。详情请阅读本教程。 +- **数据**:本教程使用的数据来自于[美国的人寿保险开销的统计数据](https://catalog.data.gov/dataset/)。 {{ }} -## Add data to Power BI - -Start by adding data to a Power BI workspace. +## 向Power BI中添加数据 +我们首先介绍如何向Power BI工作环境中添加数据。 {{}>}} -This guide walks through using the Mapbox Visual in Power BI Online. The process in Power BI Desktop is similar, but the interface is different. +这部分教程将展示如果在Power BI在线版本中使用Mapbox Visual。桌面版的操作流程基本一致,但是界面有所差别。 {{}} -### Add a new dataset - -1. Sign into your Power BI account. -1. Click **Get Data** to import or connect to a data source. -1. To import the healthcare data you downloaded earlier, choose to _Import_ a _File_. -1. Choose _Local file_ and upload the CSV file. +### 添加一个新的数据集 +1. 登陆您的Power BI账号。 +2. 点击**获取数据**以载入或者连接数据集。 +3. 选择_载入一个文件_以载入您之前已经准备好的数据集。 +4. 选择_本地文件_以上传本地的CSV格式的文件。 {{}>}} -You can use the _Mapbox Visual for Microsoft Power BI_ with any dataset that contains geographic longitude and latitude data values. +您可以在_微软Power BI中的Mapbox Visual_使用包含地理坐标信息的任何数据。 {{}} ![add a new data file to your Power BI account](/help/img/3rdparty/power-bi-add-data.png) -### Create a new report +### 创建一个新的报告 -In your Power BI workspace, navigate to the **Datasets** tab and create a new report by clicking the bar graph icon next to your new dataset. The report window will open and you will be able to edit your new report. +在您的Power BI工作环境中,点击**数据集**标签,然后点击柱状图图标以创建一个新的报告。报告结果窗口会自动弹出,您将可以在这个窗口中修改报告。 ![create a new report in your Power BI workspace](/help/img/3rdparty/power-bi-create-workspace.gif) -### Add the Mapbox Visual to your Report +### 将Mapbox Visual添加到您的报告中 -You'll add the Mapbox Visual using the _Visualizations_ pane: +您需要通过使用_可视化_窗格来添加Mapbox Visual工具。 -1. In the _Visualizations_ pane, click the **Import a custom visual** option, represented by a three-dot icon. -1. Select **Import from marketplace**. -1. Enter "Mapbox" in the search menu and press enter. -1. Click the **Add** button next to the _Mapbox visual_ option to add it to your Power BI report. It will appear as a blue Mapbox logo on the _Visualizations_ toolbar. +1. 在_可视化_窗格中,点击选项**载入自定义可视化**。选项图标由三个小点构成。 +2. 选择**从应用商店导入**。 +3. 在搜索栏中输入“Mapbox”并回车。 +4. 点击位于_Mapbox Visual_选项旁边的**添加**按钮以将其添加至您的Power BI报告中。成功添加后,Mapbox的蓝色图标会显示在_可视化_工具栏中。 {{Screenshot showing the Mapbox Visual icon in the Visualizations pane in Power BI}} {{}>}} -Alternatively, you can download the latest [Mapbox Visual for Power BI](https://github.com/mapbox/mapboxgl-powerbi/raw/master/dist/mapboxGLMap.pbiviz) from Mapbox's [open-source GitHub repository](https://github.com/mapbox/mapboxgl-powerbi): +或者你也可以从[Mapbox](https://github.com/mapbox/mapboxgl-powerbi)下载[最新版本的Mpabox Visual](https://github.com/mapbox/mapboxgl-powerbi/raw/master/dist/mapboxGLMap.pbiviz): -1. Click the **Import a custom visual** icon (three dots) and select **Import from file**. -1. Upload the [latest Mapbox Visual](https://github.com/mapbox/mapboxgl-powerbi/raw/master/dist/mapboxGLMap.pbiviz). -1. A new blue Mapbox logo will appear in the _Visualizations_ pane. +1. 点击**添加一个自定义可视化插件**按钮并选择**从文件导入**。 +2. 上传[最新版本的Mapbox Visual文件](https://github.com/mapbox/mapboxgl-powerbi/raw/master/dist/mapboxGLMap.pbiviz)。 +3. 一个蓝色的图标会在添加成功后显示在_可视化_窗格中。 {{}} -## Create a visualization +## 创建一个可视化 -Click on the Mapbox icon in the _Visualizations_ pane to add a new visualization to your report. While customizing your visualization, you'll work in both the _Fields_ and _Format_ panels within the _Visualizations_ pane: +点击_可视化_窗格中的Mapbox图标以在您的报告中添加一个新的可视化。在自定义您的可视化过程中,您将会同时使用_可视化_窗格中的_字段_和_格式_窗格: -- The _Fields_ panel is where you will specify which data fields to associate with different types of Mapbox layers (for example map styles, heatmaps, circle maps, and cluster aggregation). -- The _Format_ panel is where you will specify the visualization style for each layer, such as color and radius. +- _字段_窗格能够将数据字段和不同的Mapbox图层(例如热力图、圆圈统计图、聚类图)相互连接。 +- _格式_窗格可以用于定义每一个图层的可视化风格,例如颜色和半径范围。 -### Initialize a visualization +### 初始化一个可视化 -In the _Fields_ panel, drag the `latitude` and `longitude` fields from your data onto the _Latitude_ and _Longitude_ shelves, and make sure that the _Do not summarize_ option is checked for both fields. You should see the Mapbox visualization container populate with instructions on how to create your first visualization. +在_字段_窗格中,将数据中`latitude`和`longitude`字段分别拖拽至_Latitude_以及_Longitude_栏目中。请务必将两个字段的_无需总结_选项选中。Mapbox可视化容器会自动弹出指令以帮助您完成您的第一个可视化。 -Connect your Mapbox account using your access token: +通过秘钥连接您的Mapbox账号: -1. Click on the link, **Click here to get a free Mapbox access token**, in the visualization container. Accept the external link request if prompted. You will be forwarded to either the Mapbox sign up page or your Mapbox account page. -1. If you don’t have a Mapbox account, sign up with your email address. -1. Copy your Mapbox Access token from your [account page](https://www.mapbox.com/account/access-tokens). -1. Back in Power BI, go to the _Format_ panel and find the _Viz Settings_ option. Paste your access token in the _Access token_ field. +1. 在可视化容器中点击链接,**点击此处以获取免费Mapbox秘钥**。如有提示,请允许访问外部链接。您将会被转接到Mapbox登录界面。 +2. 如果您没有Mapbox账号,您可以使用你的邮箱注册新的账号。 +3. 在[账户页面](https://www.mapbox.com/account/access-tokens)复制您的Mapbox秘钥。 +4. 返回到Power BI,在_格式_窗格中找到_可视化设置_选项并在_秘钥_一栏中粘贴您的秘钥。 ![animated GIF illustrating the process outlined above](/help/img/3rdparty/power-bi-initiate-viz.gif) -You will see your first map visualization! +您将会看到你的第一个地图可视化! ![the resulting data visualization: a map with uniform circles at every point from the dataset](/help/img/3rdparty/power-bi-first-visualization.png) -### Change the map style +### 修改地图风格 -With the Mapbox Visual for Power BI, you can change the map style used in your visualizations. You can use any Mapbox default style or create a custom map style with Mapbox Studio. To update the map style: +您可以利用Power BI中的Mapbox Visual来修改可视化中的地图风格。您可以使用任何Mapbox的默认设置,也可以在Mapbox Studio中自定义新风格。如果需要更新您的地图风格,您需要: -1. In the _Format_ panel, select _Viz Settings_ > _Map Style_. -1. Select from any default map style. This example uses the Mapbox Satellite style. +1. 在_字段_窗格中,选择_可视化设置_ > _地图风格_。 +2. 选择任何一个默认的地图风格。此教程使用Mapbox卫星图风格。 {{}>}} -You can use any custom map style from your Mapbox Studio account by selecting **Custom style**. This is useful for adding custom polygons, drone imagery, or finely-tuning the context and design of your Mapbox visualization to help answer your business question. +在**自定义风格**中,您可以从您的Mapbox Studio账户中选择任何一个您的自定义地图风格。这一项功能对于添加自定义多边形和无人机影像,或者对于Mapbox可视化内容以及设计格式的微调都非常重要,它能够更好的帮助您突出您的设计意图及宗旨。 -When you select **Custom style**, you will be prompted to add a _style URL_. To learn how to find your custom style URL, read about more about [style URLs](/help/glossary/style-url). +当您使用**自定义风格**的时候,系统会提示您添加一个_风格链接_。请访问[此链接](/help/glossary/style-url)以获取更多的关于自定义风格链接的信息。 +如果您想要学习更多的关于在Mapbox Studio中创建自定义地图风格的知识,请阅读[Mapbox Studio使用手册](https://docs.mapbox.com/studio-manual/)或者这篇[关于创建自定义地图风格的教程](/help/tutorials/create-a-custom-style)。如果您有任何问题,请联系[Mapbox客服](https://www.mapbox.com/contact/support)。 -To learn more about creating custom map styles in Mapbox Studio, explore the [Mapbox Studio manual](https://docs.mapbox.com/studio-manual/) or the [Create a custom map style](/help/tutorials/create-a-custom-style) tutorial. Have questions on how to implement these features? Reach out to our [support team](https://www.mapbox.com/contact/support). {{}} -Now you'll see your data on top of a satellite map. +现在,您的数据已经叠加在了卫星图层上。 ![the same data visualization as above, but with a satellite map behind the circle layer](/help/img/3rdparty/power-bi-viz-settings-map-style.png) -## Create a cluster layer - -Next, you'll adjust the visualization to illustrate where the average covered costs are lowest in the US using a cluster layer. +## 创建一个聚类图层 -In the _Fields_ panel, add the `Avg Covered Charges` field from your data to the _Cluster_ shelf. +接下来,您将通过调节可视化参数以及使用一个聚类图来展示美国平均人寿保险支出最低的区域。 -In the _Format_ panel: +在_字段_窗格中,在您的数据把`平均保险费用`字段添加到_聚类_栏目中。 -1. Turn the _Cluster_ layer **On** and the _Circle_ layer **Off**. -1. Under _Cluster_, select `maximum` from the _Aggregation type_ drop down list. +在_格式_窗格中: -![animated GIF illustrating the process outlined above to add a cluster layer](/help/img/3rdparty/power-bi-cluster.gif) +1. 显示_聚类_图层,隐层_圆圈_图层。 +2. 在_聚类_中,从_聚类算法类型_下拉菜单中选择`最大值`。 -### Style the cluster visualization +### 修改聚类可视化的风格 -In the cluster _Format_ panel: +在_格式_窗格中: -1. Change the _Min Color_ to `FEC0BF` and the _Max Color_ to `FF0027`. -1. Change the _Cluster Radius_ to `30`. -1. Set the _Blur_ to `0`. -1. Set the _Stroke Width_ to `3`. -1. Set the _Max Zoom_ to `6`. +1. 将_最小颜色值_修改为`FEC0BF`,将_最大颜色值_修改为`FF0027`。 +2. 将_聚类半径_修改为`30`。 +3. 将_模糊值_修改为`0`。 +4. 将_笔画粗细_修改为`3`。 +5. 将_最大放大倍数_修改为`6`。 ![screenshot of the Power BI UI with the properties as specified above](/help/img/3rdparty/power-bi-cluster-styled.png) -## Update layers based on zoom level +## 根据缩放度更新图层 -Sometimes you may want to visualize data differently at different zoom levels. With the Mapbox Visual for Power BI, you can use multiple layers in a single visualization and specify at which zoom levels each layer should be displayed. Here, you'll show a cluster layer at low zoom levels (zoomed further out) and a circle layer at high zoom levels (zoomed further in). +如果您想要在不同的缩放程度下显示不同的数据,您可以通过Power BI的Mapbox Visual,在同一个可视化中使用多个图层。您需要给每一个缩放度设置一个对应的显示图层。接下来这个例子展示了如何设置在缩小图层的时候显示一个聚类图,在放大图层的时候显示一个圆圈统计图。 -### Add data properties to shelves +### 将数据属性添加至栏目 -In the _Fields_ panel: +在_字段_窗格中: -1. Add the `Average covered charges` data field to both the _Color_ and _Size_ shelves. -1. Add `Provider Id` to the _Tooltip_ shelf. +1. 给`平均保险费用`添加_颜色_和_尺寸_栏目。 +2. 将`提供人ID`添加到_提示_栏目中。 ![screenshot of the Power BI UI with the properties as specified above](/help/img/3rdparty/power-bi-add-shelves.png) -### Style the circle layer +### 修改圆圈的风格 -Then, in the _Format_ panel re-enable the circle layer by toggling the _Circle_ layer **On**, and update the style properties: +在_格式_窗格中将_圆圈_图层重新设置为**显示**,并更新风格属性: -1. Set the circle _Radius_ to `1` and the _Zoom scale_ factor to `10`. -1. Set the circle _Min Color_ to `FEC0BF`, _Med Color_ to `FD817E`, and _Max Color_ to `FF0027`. -1. Set the circle _Stroke Color_ to white. -1. Set the circle _Min Zoom_ to `6`. This will hide the circle layer while the cluster visualization is being displayed. +1. 将圆圈的_半径_设置为`1`,将_缩放尺度_设置为`10`。 +2. 将圆圈的_最小颜色值_设置为`FEC0BF`,_中等颜色值_设置为`FD817E`,以及_最大颜色值_设置为`FF0027`。 +3. 将圆圈的_笔画颜色_设置为白色。 +4. 将圆圈的_最小缩放度_设置为`6`。当聚类图层显示的时候,圆圈统计图图层会隐藏。 ![screenshot of the Power BI UI with the properties as specified above](/help/img/3rdparty/power-bi-update-on-zoom.png) -## Final product +## 最终结果图 -You created a visualization in Microsoft Power BI using the Mapbox Visual for Power BI. +您已经成功使用微软Power BI中的Mapbox Visual工具制作一份可视化报告。 ![an interactive data visualization on a map](/help/img/3rdparty/power-bi-final-product.gif) -## Next steps +## 下一步 -For support and troubleshooting with the Mapbox Visual, you can open an issue in our [open source repository](https://github.com/mapbox/mapboxgl-powerbi) or [contact our support team](https://www.mapbox.com/contact/support/#other). +您可以在[Github](https://github.com/mapbox/mapboxgl-powerbi)或者[客服处](https://www.mapbox.com/contact/support/#other)寻求更多的帮助或者排查疑难杂症的经验。 -Want to do more with Mapbox and Power BI? [Contact sales](https://www.mapbox.com/contact/sales) to learn what else is possible — from adding custom shapes to visualize territories, adding detailed indoor maps, or visualizing billions of data points. +想要更加深入的学习Mapbox和Power BI吗?[在这里](https://www.mapbox.com/contact/sales)您可以了解到更多的可能性,包括通过添加自定义的shapefile文件来可视化领土范围、添加详细的室内地图,或者是大型点集数据的可视化。 From 7235e999b7fe2b5b43815506f0a15bc213337fd9 Mon Sep 17 00:00:00 2001 From: Weiming Date: Wed, 18 Sep 2019 11:17:39 -0400 Subject: [PATCH 2/2] new translation --- Tutorials/building-a-store-locator.md | 212 ++++++++++++-------------- Tutorials/power-bi-choropleth-map.md | 170 +++++++++++---------- 2 files changed, 187 insertions(+), 195 deletions(-) diff --git a/Tutorials/building-a-store-locator.md b/Tutorials/building-a-store-locator.md index e1346f1..0559a63 100644 --- a/Tutorials/building-a-store-locator.md +++ b/Tutorials/building-a-store-locator.md @@ -19,57 +19,53 @@ prependJs: contentType: tutorial --- -This guide will walk you through how to create a store locator map using Mapbox GL JS. You'll be able to browse all the locations from a sidebar and select a specific store to view more information. Selecting a [marker](/help/glossary/marker/) on the map will highlight the selected store on the sidebar. + +此教程将展示如何利用Mapbix GL JS创建一个商店定位地图。您将可以通过侧边栏浏览所有的位置并选择一个位置以查看详细信息。从侧边栏中选择一个[标签](/help/glossary/marker/)可以进而标记地图上所选商店的位置。 {{ }} -You will use [Sweetgreen](http://sweetgreen.com), a local salad shop, as an example. They have a healthy number of locations, plus their salads are delicious! - -This guide shows you how to use [Mapbox GL JS](https://www.mapbox.com/mapbox-gl-js/) to build an interactive web map. If you're new to Mapbox GL JS, you might want to read our guide on Mapbox [web applications](/help/how-mapbox-works/web-apps/) first. - -## Getting started - -For this project, we recommend that you create a local folder called "store-locator" to house your project files. You'll see this folder referred to as your *project folder*. - -There are a few resources you'll need before getting started: +我们将以一个当地的沙拉店,[Sweetgreen](http://sweetgreen.com),作为示例。他们拥有一系列的连锁店位置,而且他们的沙拉非常新鲜可口! -- [__A style URL__](/help/glossary/style-url). A style URL points to a unique map you have created with Mapbox Studio. You can either create a custom style with the [Mapbox Studio style editor](https://www.mapbox.com/studio-manual/reference/styles/) or use a [Mapbox style](https://www.mapbox.com/studio/styles). +本教程将展示如何使用[Mapbox GL JS](https://www.mapbox.com/mapbox-gl-js/)创建一个交互式的网页地图。如果您是第一次使用Mapbox GL JS,我们建议您先阅读Mapbox所提供的关于[网络应用](/help/how-mapbox-works/web-apps/)的教程。 -- [__An access token__](/help/glossary/access-token/) from your account. You will use an access token to associate a map with your account. Your access token is on the [Account page](https://www.mapbox.com/account/). +## 准备工作 -- [__Mapbox GL JS__](https://www.mapbox.com/mapbox-gl-js/). The Mapbox JavaScript library that uses WebGL to render interactive maps from Mapbox GL styles. +首先,我们建议您创建一个本地文件夹,“store-locator”,以存放您的工程文件。在之后的教程中,我们称这个文件夹为*工程文件夹*。 -- __A text editor.__ You'll be writing HTML, CSS, and JavaScript after all. +您需要以下的资源: -- __Data__. We collected some of Sweetgreen's locations and marked up the data in GeoJSON. - -- __Custom map marker__. You'll be using an image for your map marker. Save the image to your project folder. +- [__风格URL__](/help/glossary/style-url):一个风格URL对应着您在Mapbox Studio中所创建一个地图风格。您可以在[Mapbox Studio风格编辑器](https://www.mapbox.com/studio-manual/reference/styles/)中创建一个自定义风格,或者使用[预设的风格](https://www.mapbox.com/studio/styles)。 +- 账号[__秘钥__](/help/glossary/access-token/):您需要一个秘钥来将您的账号和您的地图关联起来。您的秘钥可以在[账号信息页](https://www.mapbox.com/account/)获取。 +- [__Mapbox GL JS__](https://www.mapbox.com/mapbox-gl-js/):Mapbox JavaScript开发者库使用了WebGL来呈递Mapbox GL风格的交互式地图。 +- __文本编辑器__:您需要能够编写THML、CSS以及JavaScript。 +- __数据__:我们准备了一些Sweetgreen连锁店的位置信息,并编译成了GeoJSON格式的文件。 +- __自定义地图标签__:您需要一张图片来作为您的地图标签。请自行选择并保存一张图片至您的工作文件夹中。 {{ }} -## Add structure +## 页面布局设置 -In your project folder, create an `index.html` file. Set up the document by adding Mapbox GL JS and CSS to your `head`: +在您的工程文件夹中,创建一个文件并命名为`index.html`。在`head`中添加以下Mapbox GL JS和CSS代码: ```html ``` -Next, markup the page to create a map container and sidebar listing: +然后,我们需要标记此页面并创建一个地图容器和一个侧边栏: ```html
Map
``` -Then, apply some CSS to create the page layout: +接下来,我们设置一些CSS以定义页面的布局: ```css body { @@ -81,8 +77,7 @@ body { -webkit-font-smoothing: antialiased; } -/* The page is split between map and sidebar - the sidebar gets 1/3, map -gets 2/3 of the page. You can adjust this to your personal liking. */ +/*这个页面被分为了地图和侧边栏。侧边栏相对宽度为页面的三分之一,地图容器为三分之二。您可以自行调整相对宽度。*/ .sidebar { width: 33.3333%; } @@ -108,56 +103,53 @@ gets 2/3 of the page. You can adjust this to your personal liking. */ }} -## Initialize the map +## 初始化地图 -Now that you have the structure of the page, initialize the map with Mapbox GL JS. +您已经完成了页面的布局设计,我们可以通过Mapbox GL JS来初始化我们的地图。 -First, add your access token using `mapboxgl.accessToken`. Then, create a new `map` object using `new mapboxgl.Map()` and store it in a variable called `map`: +首先,在`mapboxgl.accessToken`中添加您的秘钥。然后,通过`new mapboxgl.Map()`创建一个新的`map`对象,并将其保存在变量`map`中: ```js mapboxgl.accessToken = '{{ }}'; -// This adds the map to your page +// 在页面中添加一个地图 var map = new mapboxgl.Map({ - // container id specified in the HTML + // HTML中所包含的容器ID container: 'map', - // style URL + // 风格URL style: 'mapbox://styles/mapbox/light-v{{constants.VERSION_LIGHT_STYLE}}', - // initial position in [lon, lat] format + // 初始化的位置用[x, y]格式标记 center: [-77.034084, 38.909671], - // initial zoom + // 初始的缩放程度 zoom: 14 }); ``` -As you can see above, the Mapbox GL JS map requires several options: - -- `container`: the `id` of the `
` element on the page where the map should live. In this case, the `id` for the `
` is `'map'`. - -- `style`: the [style URL](/help/glossary/style-url/) for the map style. In this case, use the {{ }} which has the style URL `mapbox://styles/mapbox/light-{{constants.VERSION_LIGHT_STYLE}}`. +如您所见,Mapbox GL JS初始化地图的时候需要以下的设置: -- `center`: the initial centerpoint of the map in [longitude, latitude] format. +- `contianer`:`
`的`id`元素标注了地图的显示位置。在上面的例子中,我们 的`id`是`map`。 +- `style`:地图所选用的[风格URL](/help/glossary/style-url/)。在我们的例子中,{{ }}包含了风格URL`mapbox://styles/mapbox/light-{{constants.VERSION_LIGHT_STYLE}}`。 +- `center`:由[x, y]所标注的初始化地图中心位置。 +- `zoom`:初始的地图缩放程度。 -- `zoom`: the initial zoom level of the map. +## 加载数据 -## Load data +在Mapbox GL JS中,地图的呈递过程在浏览器中实现。想要实现这一过程,您需要添加一个具有地理信息的图层以及对应的操作步骤。 -With Mapbox GL JS, map rendering happens in the browser. For the browser to render your map, you need to add a layer with geospatial data and instructions for how that data should be rendered. - -To add a source to the map, your code needs to access the geospatial data. Store all the GeoJSON data in `sweetgreen.geojson` in a variable called `stores`: +您的代码需要能够访问地理信息才能够添加一个源地图。将所有的`sweetgreen.geojson`GeoJSON数据保存在变量`stores`中: ```js var stores = {{ sweetgreenLocations }}; ``` -Now you can add a layer that contains this data and describes how it should be rendered. Add the data to your map once the map loads using `addLayer()`. Create a new layer, and specify `stores` as a GeoJSON data source. Then, add instructions for rendering the source. This example only adds minimal styling --- for full details on all the layer styling options, see the [Mapbox Style Specification](https://www.mapbox.com/mapbox-gl-style-spec/): +现在您可以添加一个图层并进一步定义这个图层应该如何显示。当地图通过`addLayer()`显示的时候,向地图中添加您的数据。创建一个新的图层,并设置`stores`为您的GeoJSON数据源。然后,添加如何显示数据的操作步骤。此教程仅使用了极简风格,如果您想要了解完整的图层风格设置信息,请阅读[Mapbox风格设置文档](https://www.mapbox.com/mapbox-gl-style-spec/): ```js map.on('load', function(e) { - // Add the data to your map as a layer + // 向地图中添加数据图层 map.addLayer({ id: 'locations', type: 'symbol', - // Add a GeoJSON source containing place coordinates and information. + // 添加包含有坐标和附加信息的GeoJSON数据源 source: { type: 'geojson', data: stores @@ -170,17 +162,17 @@ map.on('load', function(e) { }); ``` -_Note: `restaurant-15` refers to an icon in the Mapbox Light style you added earlier in the code._ +_请注意,`restaurant-15`指的是Mapbox轻风格中的一个图标。您在之前的步骤中已经添加了这个风格。_ {{ }} -## Build store listing +## 创建商店列表 -Now that the points are on your map, it's time to build the restaurant location listing by iterating through the GeoJSON and creating a list of restaurants dynamically. This means that if you need to add a location then you *only* need to update the GeoJSON. +您已经将商店的位置显示在了地图上,现在可以利用一个循环语句来自动创建包含所有商店位置信息的列表了。我们使用一个循环语句遍历所有的GeoJSON数据,这样一来,如果您需要修改或者添加商店位置信息,您**只需要**修改GeoJSON文件,而不需要改动任何的代码。 -First, update the sidebar HTML to hold the listing information and update your CSS to accommodate the layout changes: +首先,我们需要改动HTML以保证列表信息的显示,同时相应的我们需要更改CSS格式设置: ```html