- Kotlin Blueprints
- Ashish Belagali Hardik Trivedi Akshay Chordiya
- 136字
- 2021-07-02 21:50:16
Listening to message saved events
Storing the message in the database takes some amount of time and we want to update the UI or reflect the state of the UI after the message is successfully saved into the database. We specify an EventSource and add an EventListener to receive the callback when a new message is stored in the database.
When a new message is saved into the database the callback function of the event listener is called and we then plot the message on the map using ol.Feature:
/* Reactive: Event listener to get updates when new message is
saved */
var source = new EventSource("/message/subscribe");
// Callback function called on event update
source.addEventListener('message', function (e) {
var message = $.parseJSON(e.data);
var feature = new ol.Feature({
geometry: new ol.geom.Point(message.location.coordinates),
content: message.content
});
vectorSource.addFeature(feature);
}, false);
推薦閱讀
- Java逍遙游記
- 零基礎學Visual C++第3版
- ASP.NET MVC4框架揭秘
- Microsoft Application Virtualization Cookbook
- Python應用輕松入門
- 網絡爬蟲原理與實踐:基于C#語言
- 學Python也可以這么有趣
- 微信小程序入門指南
- 焊接機器人系統操作、編程與維護
- Linux Shell核心編程指南
- HTML+CSS+JavaScript網頁設計從入門到精通 (清華社"視頻大講堂"大系·網絡開發視頻大講堂)
- Mastering Adobe Captivate 7
- Building Web and Mobile ArcGIS Server Applications with JavaScript(Second Edition)
- Instant AppFog
- 邊做邊學深度強化學習:PyTorch程序設計實踐