Newer
Older
KaiFengPC / src / views / project / projectIndex / addProjectLayer.js
@jimengfei jimengfei on 12 Jun 1 KB updata
export default class kaifengProjectLayer {
  static addPointProject(map, data, layerId) {
    !!!map.getSource(layerId) && map.addSource(layerId, { type: 'geojson', data: data });
    !!!map.getLayer(layerId) &&
      map.addLayer({
        id: layerId,
        type: 'symbol',
        source: layerId,
        layout: {
          'text-field': ['get', 'name'],
          'text-font': ['KlokanTech Noto Sans Regular'],
          'text-size': 16,
          'text-line-height': 2,
          'text-anchor': 'bottom',
        },
        paint: {
          'text-color': '#ffffff',
        },
      });
  }

  static addLineProject(map, data, layerId, color) {
    !!!map.getSource(layerId) && map.addSource(layerId, { type: 'geojson', data: data });
    !!!map.getLayer(layerId) &&
      map.addLayer({
        id: layerId,
        type: 'line',
        source: layerId,
        paint: {
          'line-color': color,
          'line-width': 6,
        },
      });
  }

  static addPolygonProject(map, data, layerId, color) {
    !!!map.getSource(layerId) && map.addSource(layerId, { type: 'geojson', data: data });
    !!!map.getLayer(layerId) &&
      map.addLayer({
        id: layerId,
        type: 'fill',
        source: layerId,
        paint: {
          'fill-color': color,
        },
      });
  }
}