leaflet-rxjs

所属分类:网络编程
开发工具:JavaScript
文件大小:0KB
下载次数:0
上传日期:2018-07-12 20:33:11
上 传 者sh-1993
说明:  传单rxjs允许您利用传单的 React编程功能。该软件包为任何偶数......添加了可观察的功能...,
(leaflet-rxjs allows you to harness the power of reactive programming with Leaflet. This package adds observable functionality to any event generating Leaflet object.)

文件列表:
LICENSE (1069, 2018-07-12)
bower.json (826, 2018-07-12)
package.json (705, 2018-07-12)
src/ (0, 2018-07-12)
src/L.RxJS.js (4490, 2018-07-12)

# leaflet-rxjs leaflet-rxjs allows you to harness the power of reactive programming with Leaflet. This package adds observable functionality to any event generating Leaflet object. ## Requirements ## - [Leaflet](http://leafletjs.com/) ^1.0.0 - [RxJS](https://github.com/Reactive-Extensions/RxJS) ^5.0.0 # What is Reactive Programming? ## Reactive Programming lets you represent a series of independent events as a stream of data rather than a series of callback calls. This approach encourages clean, concise code that is easy to reason about. Observables also have array-like functions such as map, filter, and reduce which can operate on these data streams. [staltz](https://github.com/staltz) wrote a good [overview](https://gist.github.com/staltz/868e7e9bc2a7b8c1f754). # Use # Register your event with one of the observable creation methods. All existing Leaflet event types can be returned as observables. See the Leaflet [documentation](http://leafletjs.com/reference.html) for the full list of event types. # API Reference # ### `observable(types: String): Rx.Observable` Get an rxjs observable for the supplied Leaflet event types. When a subscriber joins they receive all subsequent events. * **Parameters:** `types` — `string` — Leaflet event types. Multiple allowed, separated by commas. * **Returns:** `Rx.Observable` ### `asyncObservable(types: String): Rx.Observable` Get an rxjs asyc observable for the supplied Leaflet event types. This observable will store the last event, and will only publish the event when the observable is unsubscribed using Leaflet's off() method. * **Parameters:** `types` — `string` — Leaflet event types. Multiple allowed, separated by commas. * **Returns:** `Rx.Observable` ### `replayObservable(types: String): Rx.Observable` Get an rxjs replay observable for the supplied Leaflet event types. A buffer of previous events is stored. When a subscriber joins they receive event history and further events. * **Parameters:** `types` — `string` — Leaflet event types. Multiple allowed, separated by commas. * **Returns:** `Rx.Observable` # Example # ```js // Registering an event callback in regular Leaflet fashion map.on('zoomend', function(event) { console.log('Executed as a Leaflet on callback', event); }); // Registering events with leaflet-rxjs var mapObservable = map.observable('click dblclick'); // Subscribe to the observable mapObservable.subscribe(function(event) { console.log('Executed from an observable', event); }); // Multiple subscribers are supported mapObservable.subscribe(function(event) { console.log('Second subscriber', event); }); // Unregister the mapObservable after 60 seconds setTimeout(function(){ map.off('moveend', mapObservable); }, 60000); // Also works on other objects (any Leaflet object with event support) var popup = L.popup() .setLatLng(latlng) .setContent('

Hello world!
This is a nice popup.

') .openOn(map); var popupObservable = popup.observable('click'); popupObservable.subscribe(function(event) { console.log('Executed on a click to the popup', event); }); ```

近期下载者

相关文件


收藏者