terça-feira, 19 de julho de 2016

WebSockets with OpenStreetMaps...



using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(Maps2.Startup))]

namespace Maps2
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            // Any connection or hub wire up and configuration should go here
            app.MapSignalR();
            ConfigureAuth(app);
        }
    }
}
    <script src="Scripts/jquery-1.6.4.min.js"></script>
    <script src="/Scripts/jquery.signalR-2.0.0.js"></script>
    <script src="/signalr/hubs"></script>
        <script type="text/javascript">
            var chat = j.connection.chatHub;
            chat.client.broadcastMessage = function (name, message) {
                var encodedMsg = j('
'
).text(message).html();
                try
                {
                    var json = j.parseJSON(encodedMsg);
                    LeafletMap.addPoint(json);
                }
                catch (exception) {
                    console.log(exception);
                }
            };
            // Start the connection.
            j.connection.hub.start().done(function () {
            });
    </script>
using System;
using System.Web;
using Microsoft.AspNet.SignalR;
namespace Maps2




{
    public class ChatHub : Hub
    {
        public void Send(string name, string message)
        {
            // Call the broadcastMessage method to update clients.
            Clients.All.broadcastMessage(name, message);
        }
    }
Postar um comentário