` 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