本文整理汇总了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
},
//.........这里部分代码省略.........