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

  • 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);
主站蜘蛛池模板: 壤塘县| 桃源县| 禹州市| 临洮县| 石景山区| 通榆县| 宕昌县| 华安县| 临猗县| 紫金县| 开封市| 宁河县| 莱阳市| 临泽县| 嫩江县| 精河县| 龙川县| 城步| 青河县| 启东市| 黑水县| 云南省| 三都| 曲沃县| 扬中市| 无锡市| 龙口市| 芜湖县| 巨野县| 洞口县| 普宁市| 兴业县| 兴安县| 昌宁县| 峨眉山市| 乌兰浩特市| 惠安县| 蒙城县| 杭州市| 南开区| 怀化市|