1
0
forked from MTSR/mapserver

realtime update

This commit is contained in:
Thomas Rudin 2019-01-22 20:19:04 +01:00
parent d5ea47ad87
commit 9031d1e213
3 changed files with 19 additions and 6 deletions

View File

@ -5,8 +5,8 @@ test: $(STATIC_VFS)
go test ./...
clean:
rm $(STATIC_VFS)
rm mapserver
rm -rf $(STATIC_VFS)
rm -rf mapserver
$(STATIC_VFS):
go get github.com/mjibson/esc

View File

@ -20,7 +20,7 @@
});
function getTileSource(layerId, x,y,zoom,cacheBust){
return "api/tile/" + layerId + "/" + x + "/" + y + "/" + zoom + (cacheBust ? "?_=" + Date.now() : "");
return "api/tile/" + layerId + "/" + x + "/" + y + "/" + zoom + "?_=" + Date.now();
}
function getImageId(layerId, x, y, zoom){
@ -39,15 +39,27 @@
}
function updateTile(data){
var id = getImageId(data.layerId, data.x, data.y, data.zoom);
var id = getImageId(data.layerid, data.x, data.y, data.zoom);
var el = document.getElementById(id);
if (el){
//Update src attribute if img found
el.src = getTileSource(data.layerId, data.x, data.y, data.zoom, true);
el.src = getTileSource(data.layerid, data.x, data.y, data.zoom, true);
}
}
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"){
updateTile(event.tilepos)
}
}
var layers = {};
var Layer = createTileLayer(0);

View File

@ -3,13 +3,14 @@ package web
import (
"encoding/json"
"fmt"
"github.com/gorilla/websocket"
"mapserver/app"
"mapserver/coords"
"mapserver/mapblockparser"
"math/rand"
"net/http"
"sync"
"github.com/gorilla/websocket"
)
type WS struct {