---
title: GeoJSONSource
source: https://vjmap.com/en/doc/GeoJSONSource.html
---

# GeoJSONSource
**扩展事件**


包含 GeoJSON 的源。（见`样式规范`有关选项的详细文档。）

### Parameters
- `id` **`string`**
- `options` **任何**
- `dispatcher` **调度员**
- `eventedParent` **`事件发生`**

### Examples
```
map.addSource('some id', {
    type: 'geojson',
    data: 'https://xxx.geojson'
});
```

```
map.addSource('some id', {
   type: 'geojson',
   data: {
       "type": "FeatureCollection",
       "features": [{
           "type": "Feature",
           "properties": {},
           "geometry": {
               "type": "Point",
               "coordinates": [
                   -76.53063297271729,
                   39.18174077994108
               ]
           }
       }]
   }
});
```

```
map.getSource('some id').setData({
  "type": "FeatureCollection",
  "features": [{
      "type": "Feature",
      "properties": { "name": "Null Island" },
      "geometry": {
          "type": "Point",
          "coordinates": [ 0, 0 ]
      }
  }]
});
```

### setData
设置 GeoJSON 数据并重新渲染地图。

#### Parameters
- `data` **( `Object`| `string`)** GeoJSON 数据对象或指向一个的 URL。在大 GeoJSON 文件的情况下，后者更可取。

返回**[GeoJSONSource][271]**这个

### getClusterExpansionZoom
对于集群源，获取给定集群扩展的缩放比例。

#### Parameters
- `clusterId` **`number`**集群的`cluster_id`属性值。
- `callback` **回调&lt; `number`\>**检索缩放值时要调用的回调 ( `(error, zoom) => { ... }`)。

返回**[GeoJSONSource][271]**这个

### getClusterChildren
对于集群源，在下一个缩放级别（作为 GeoJSON 功能数组）获取给定集群的子项。

#### Parameters
- `clusterId` **`number`**集群的`cluster_id`属性值。
- `callback` **Callback&lt; `Array`&lt;GeoJSONFeature>>**检索要素时要调用的回调 ( `(error, features) => { ... }`)。

返回**[GeoJSONSource][271]**这个

### getClusterLeaves
对于集群源，获取属于集群的原始点（作为 GeoJSON 特征数组）。

#### Parameters
- `clusterId` **`number`**集群的`cluster_id`属性值。
- `limit` **`number`**要返回的最大特征数。（`10`如果给出了假值，则默认为。）
- `offset` **`number`**要跳过的功能数量（例如分页）。（`0`如果给出了假值，则默认为。）
- `callback` **Callback&lt; `Array`&lt;GeoJSONFeature>>**检索要素时要调用的回调 ( `(error, features) => { ... }`)。

#### Examples
```
// Retrieve cluster leaves on click
map.on('click', 'clusters', function(e) {
  var features = map.queryRenderedFeatures(e.point, {
    layers: ['clusters']
  });

  var clusterId = features[0].properties.cluster_id;
  var pointCount = features[0].properties.point_count;
  var clusterSource = map.getSource('clusters');

  clusterSource.getClusterLeaves(clusterId, pointCount, 0, function(error, features) {
    // Print cluster leaves in the console
    console.log('Cluster leaves:', error, features);
  })
});
```

返回**[GeoJSONSource][271]**这个
