官术网_书友最值得收藏!

  • 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);
主站蜘蛛池模板: 华坪县| 仁寿县| 大丰市| 南木林县| 柳江县| 舞阳县| 凌源市| 永宁县| 东明县| 石棉县| 台前县| 玛多县| 五河县| 镇雄县| 辽源市| 铅山县| 孟津县| 东兰县| 从化市| 福贡县| 中西区| 香河县| 兴隆县| 阜城县| 博客| 高碑店市| 禄丰县| 富宁县| 贞丰县| 双峰县| 铜鼓县| 蒙山县| 库尔勒市| 桂阳县| 阜南县| 根河市| 石屏县| 龙南县| 天津市| 麦盖提县| 兴文县|