当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript GeoJSON.extend方法代码示例

本文整理汇总了TypeScript中leaflet.GeoJSON.extend方法的典型用法代码示例。如果您正苦于以下问题:TypeScript GeoJSON.extend方法的具体用法?TypeScript GeoJSON.extend怎么用?TypeScript GeoJSON.extend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在leaflet.GeoJSON的用法示例。


在下文中一共展示了GeoJSON.extend方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: of

const AsynchronousGeoJSONOverlay = L.GeoJSON.extend({
  bounds: null,
  // retain layer data to detect whether it's already loaded
  data: null,
  enabled: true,
  // retain url grab errors
  error: Error,
  id: 'async-geojson',
  legends: [],
  // retain  for custom layer adjustments
  map: null,
  // persistent styles (allows alternating styles in geoJSON features)
  styles: {},
  title: 'Async GeoJSON',
  // url to download geoJSON
  url: null,

  /**
   * Init function
   */
  initialize: function() {
    // for content downloads in async map layers; added to layer during
    // initialization, or manually
    this.httpClient = null;

    L.GeoJSON.prototype.initialize.call(this, [], {
      onEachFeature: (feature, layer) => this.onEachFeature(feature, layer),
      pointToLayer: (feature, layer) => this.pointToLayer(feature, layer),
      style: feature => this.style(feature)
    });
  },

  /**
   * Runs after the geoJSON data is successfully added
   */
  afterAdd: function() {
    // subclasses should override this method
  },

  /**
   * Handling all errors
   *
   * @param {Error}
   *
   * @return {Observable}
   *    For caught errors during http requests
   */
  handleError: function(error: any) {
    this.error = error;
    this.data = null;
    return of(null);
  },

  /**
   * Fetch data, and ensure it is parsed into geojson
   */
  loadData: function() {
    if (!this.url || !this.httpClient) {
      this.data = null;
      return;
    }

    if (this.data !== null) {
      return;
    }

    // flag that data is being loaded
    this.data = 'loading';
    this.httpClient
      .get(this.url)
      .pipe(catchError(error => this.handleError(error)))
      .subscribe(data => {
        try {
          data = this.parse(data);
          // flag that data is loaded
          this.data = data;
          // add data to layer (and map if layer still visible)
          this.addData(data);
          this.afterAdd();
        } catch (error) {
          this.handleError(error);
        }
      });
  },

  /**
   * Get geoJSON data and add it to the existing layer
   */
  onAdd: function(map) {
    this.map = map;
    L.GeoJSON.prototype.onAdd.call(this, map);

    this.loadData();
    this.afterAdd();
  },

  onEachFeature: function(feature, layer) {
    // subclasses should override this method
  },

//.........这里部分代码省略.........
开发者ID:ehunter-usgs,项目名称:earthquake-eventpages,代码行数:101,代码来源:asynchronous-geojson-overlay.ts


注:本文中的leaflet.GeoJSON.extend方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。