js/css cleanup

This commit is contained in:
NatureFreshMilk 2019-01-29 18:00:00 +01:00
parent 560f01dc7a
commit f0d6d7c19b
4 changed files with 36 additions and 20 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -5,25 +5,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="theme-color" content="#000">
<link rel="stylesheet" href="css/leaflet.css"/>
<link rel="stylesheet" href="css/custom.css"/>
<title>Minetest Mapserver</title>
<style>
body {
height: 100%;
}
#image-map {
width: 100%;
height: 100%;
border: 1px solid #ccc;
margin-bottom: 10px;
}
.leaflet-custom-display {
background: #fff;
padding: 5px;
}
</style>
</head>
<body>
<div id="image-map"></div>

View File

@ -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 {