diff --git a/server/mapobject/setup.go b/server/mapobject/setup.go index 62767b5..70d6d36 100644 --- a/server/mapobject/setup.go +++ b/server/mapobject/setup.go @@ -32,6 +32,8 @@ func (this *Listener) OnEvent(eventtype string, o interface{}) { panic(err) } + this.ctx.WebEventbus.Emit("mapobjects-cleared", block.Pos) + for id, name := range block.BlockMapping { for k, v := range this.objectlisteners { if k == name { @@ -46,7 +48,7 @@ func (this *Listener) OnEvent(eventtype string, o interface{}) { if obj != nil { this.ctx.Objectdb.AddMapData(obj) - this.ctx.WebEventbus.Emit("mapobject", obj) + this.ctx.WebEventbus.Emit("mapobject-created", obj) } } } //z diff --git a/server/static/css/custom.css b/server/static/css/custom.css new file mode 100644 index 0000000..f49372a --- /dev/null +++ b/server/static/css/custom.css @@ -0,0 +1,15 @@ +body { + height: 100%; +} + +#image-map { + width: 100%; + height: 100%; + border: 1px solid #ccc; + margin-bottom: 10px; +} + +.leaflet-custom-display { + background: #fff; + padding: 5px; +} diff --git a/server/static/index.html b/server/static/index.html index 2b9cdd6..c9c0709 100644 --- a/server/static/index.html +++ b/server/static/index.html @@ -5,25 +5,8 @@ + Minetest Mapserver - -
diff --git a/server/static/js/WebsocketChannel.js b/server/static/js/WebsocketChannel.js index d7913dc..0d97308 100644 --- a/server/static/js/WebsocketChannel.js +++ b/server/static/js/WebsocketChannel.js @@ -1,17 +1,33 @@ var WebSocketChannel = (function(){ 'use strict'; + var wsUrl = location.protocol.replace("http", "ws") + "//" + location.host + location.pathname.substring(0, location.pathname.lastIndexOf("/")) + "/api/ws"; + function connect(){ - var wsUrl = location.protocol.replace("http", "ws") + "//" + location.host + location.pathname.substring(0, location.pathname.lastIndexOf("/")) + "/api/ws"; var ws = new WebSocket(wsUrl); ws.onmessage = function(e){ var event = JSON.parse(e.data); if (event.type == "rendered-tile"){ + //Update tiles RealtimeTileLayer.update(event.data) + + } else if (event.type == "mapobject-created"){ + //TODO + console.log(event); + + } else if (event.type == "mapobjects-cleared"){ + //TODO + console.log(event); + } } + + ws.onerror = function(){ + //reconnect after some time + setTimeout(connect, 1000); + } } return {