forked from MTSR/mapserver
search form
This commit is contained in:
parent
0470347a79
commit
e98e85ec8a
2
go.mod
2
go.mod
@ -9,7 +9,7 @@ require (
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||
github.com/prometheus/client_golang v0.9.4
|
||||
github.com/sirupsen/logrus v1.3.0
|
||||
github.com/stretchr/testify v1.2.2
|
||||
github.com/stretchr/testify v1.3.0
|
||||
github.com/yuin/gopher-lua v0.0.0-20190206043414-8bfc7677f583
|
||||
golang.org/x/image v0.0.0-20190118043309-183bebdce1b2 // indirect
|
||||
)
|
||||
|
5
go.sum
5
go.sum
@ -2,6 +2,7 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy
|
||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0=
|
||||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
@ -19,6 +20,7 @@ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me
|
||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
|
||||
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||
@ -57,13 +59,16 @@ github.com/prometheus/client_golang v0.9.4/go.mod h1:oCXIBxdI62A4cR6aTRJCgetEjec
|
||||
github.com/prometheus/client_golang v1.1.0 h1:BQ53HtBmfOitExawJ6LokA4x8ov/z0SYYb0+HxJfRI8=
|
||||
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 h1:idejC8f05m9MGOsuEi1ATq9shN03HrxNkD/luQvxCv8=
|
||||
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 h1:S/YWwWx/RA8rT8tKFRuGUZhuA90OyIBpPCXkcbwU8DE=
|
||||
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275 h1:PnBWHBf+6L0jOqq0gIVUe6Yk0/QMZ640k6NvkxcBf+8=
|
||||
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
|
||||
github.com/prometheus/common v0.4.1 h1:K0MGApIoQvMw27RTdJkPbr3JZ7DNbtxQNyi5STVM6Kw=
|
||||
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
||||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a h1:9a8MnZMP0X2nLJdBg+pBmGgkJlSaKC2KaQmTCk1XDtE=
|
||||
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.2 h1:6LJUbpNm42llc4HRCuvApCSWB/WfhuNo9K98Q9sNGfs=
|
||||
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/sirupsen/logrus v1.3.0 h1:hI/7Q+DtNZ2kINb6qt/lS+IyXnHQe9e90POfeewL/ME=
|
||||
|
@ -1,10 +1,63 @@
|
||||
import SearchResult from './SearchResult.js';
|
||||
import { getMapObjects } from '../api.js';
|
||||
|
||||
const state = {
|
||||
busy: false,
|
||||
result: []
|
||||
}
|
||||
|
||||
function searchFor(type, key, valuelike){
|
||||
return getMapObjects({
|
||||
pos1: { x:-2048, y:-2048, z:-2048 },
|
||||
pos2: { x:2048, y:2048, z:2048 },
|
||||
type: type,
|
||||
attributelike: {
|
||||
key: key,
|
||||
value: "%" + valuelike +"%"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function search(query){
|
||||
state.result = [];
|
||||
|
||||
var prom_list = [
|
||||
searchFor("shop", "out_item", query),
|
||||
searchFor("poi", "name", query),
|
||||
searchFor("train", "station", query),
|
||||
searchFor("travelnet", "station_name", query),
|
||||
searchFor("bones", "owner", query),
|
||||
searchFor("locator", "name", query),
|
||||
searchFor("label", "text", query),
|
||||
searchFor("digiterm", "display_text", query),
|
||||
searchFor("digilinelcd", "text", query)
|
||||
];
|
||||
|
||||
Promise.all(prom_list)
|
||||
.then(function(results){
|
||||
|
||||
var arr = [];
|
||||
results.forEach(function(r) {
|
||||
arr = arr.concat(r);
|
||||
});
|
||||
|
||||
state.result = arr;
|
||||
state.busy = false;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
export default {
|
||||
oncreate(vnode){
|
||||
console.log("oncreate", vnode);
|
||||
search(vnode.attrs.query);
|
||||
},
|
||||
|
||||
view(vnode){
|
||||
return m("div", vnode.attrs.query)
|
||||
if (state.result.length == 0) {
|
||||
return m("div", vnode.attrs.query);
|
||||
} else {
|
||||
return m(SearchResult, { result: state.result })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
152
static/js/components/SearchResult.js
Normal file
152
static/js/components/SearchResult.js
Normal file
@ -0,0 +1,152 @@
|
||||
import layerMgr from '../map/LayerManager.js';
|
||||
|
||||
export default {
|
||||
view: function(vnode){
|
||||
var result = vnode.attrs.result;
|
||||
|
||||
function getLayer(obj){
|
||||
var layer = layerMgr.getLayerByY(obj.y);
|
||||
return layer ? layer.name : "<unknown>";
|
||||
}
|
||||
|
||||
function getPos(obj){
|
||||
var text = obj.x + "/" + obj.y + "/" + obj.z;
|
||||
|
||||
return m("span", {class:"badge badge-success"}, text);
|
||||
}
|
||||
|
||||
var rows = result.map(function(obj){
|
||||
|
||||
var row_classes = "";
|
||||
var description = obj.type;
|
||||
var type = obj.type;
|
||||
|
||||
// train-line result
|
||||
if (obj.type == "train"){
|
||||
description = [
|
||||
m("span", obj.attributes.station),
|
||||
" ",
|
||||
m("span", {class:"badge badge-info"}, obj.attributes.line)
|
||||
];
|
||||
|
||||
type = m("i", { class: "fa fa-subway" });
|
||||
}
|
||||
|
||||
// travelnet
|
||||
if (obj.type == "travelnet"){
|
||||
description = m("span", obj.attributes.station_name);
|
||||
type = m("img", { src: "pics/travelnet_inv.png" });
|
||||
}
|
||||
|
||||
// bones
|
||||
if (obj.type == "bones"){
|
||||
description = m("span", obj.attributes.owner);
|
||||
type = m("img", { src: "pics/bones_top.png" });
|
||||
}
|
||||
|
||||
// label
|
||||
if (obj.type == "label"){
|
||||
description = m("span", obj.attributes.text);
|
||||
type = m("img", { src: "pics/mapserver_label.png" });
|
||||
}
|
||||
|
||||
// digiterm
|
||||
if (obj.type == "digiterm"){
|
||||
description = m("span", obj.attributes.display_text);
|
||||
type = m("img", { src: "pics/digiterms_beige_front.png" });
|
||||
}
|
||||
|
||||
// digiline lcd
|
||||
if (obj.type == "digilinelcd"){
|
||||
description = m("span", obj.attributes.text);
|
||||
type = m("img", { src: "pics/lcd_lcd.png" });
|
||||
}
|
||||
|
||||
// locator
|
||||
if (obj.type == "locator"){
|
||||
description = m("span", obj.attributes.name);
|
||||
|
||||
var img = "pics/locator_beacon_level1.png";
|
||||
|
||||
if (obj.attributes.level == "2")
|
||||
img = "pics/locator_beacon_level2.png";
|
||||
else if (obj.attributes.level == "3")
|
||||
img = "pics/locator_beacon_level3.png";
|
||||
|
||||
type = m("img", { src: img });
|
||||
}
|
||||
|
||||
// poi marker
|
||||
if (obj.type == "poi"){
|
||||
description = m("span", obj.attributes.name);
|
||||
|
||||
var color = obj.attributes.color || "blue";
|
||||
var icon = obj.attributes.icon || "home";
|
||||
|
||||
type = m("div", { style: "position: relative", class: "awesome-marker awesome-marker-icon-" + color }, [
|
||||
m("i", { class: "fa fa-" + icon })
|
||||
]);
|
||||
}
|
||||
|
||||
//shop
|
||||
if (obj.type == "shop") {
|
||||
if (obj.attributes.stock == 0){
|
||||
row_classes += "table-warning";
|
||||
type = m("img", { src: "pics/shop_empty.png" });
|
||||
} else {
|
||||
type = m("img", { src: "pics/shop.png" });
|
||||
}
|
||||
|
||||
description = m("span", [
|
||||
"Shop, trading ",
|
||||
m("span", {class:"badge badge-primary"},
|
||||
obj.attributes.out_count,
|
||||
"x",
|
||||
m("i", {class:"fa fa-cart-arrow-down"})
|
||||
),
|
||||
m("span", {class:"badge badge-info"}, obj.attributes.out_item),
|
||||
" for ",
|
||||
m("span", {class:"badge badge-primary"},
|
||||
obj.attributes.in_count,
|
||||
"x",
|
||||
m("i", {class:"fa fa-money-bill"})
|
||||
),
|
||||
m("span", {class:"badge badge-info"}, obj.attributes.in_item),
|
||||
" Stock: ",
|
||||
m("span", {class:"badge badge-info"}, obj.attributes.stock)
|
||||
]);
|
||||
}
|
||||
|
||||
function onclick(){
|
||||
var layer = layerMgr.getLayerByY(obj.y);
|
||||
m.route.set(`/map/${layer.id}/${12}/${obj.x}/${obj.z}`);
|
||||
}
|
||||
|
||||
return m("tr", {"class": row_classes}, [
|
||||
m("td", type),
|
||||
m("td", obj.attributes.owner),
|
||||
m("td", getLayer(obj)),
|
||||
m("td", getPos(obj)),
|
||||
m("td", description),
|
||||
m("button[type=button]", {class: "btn btn-secondary", onclick: onclick }, [
|
||||
"Goto ",
|
||||
m("i", { class: "fas fa-play" })
|
||||
])
|
||||
]);
|
||||
});
|
||||
|
||||
return m("table", {class:"table table-striped"}, [
|
||||
m("thead", [
|
||||
m("tr", [
|
||||
m("th", "Type"),
|
||||
m("th", "Owner"),
|
||||
m("th", "Layer"),
|
||||
m("th", "Position"),
|
||||
m("th", "Description"),
|
||||
m("th", "Action")
|
||||
])
|
||||
]),
|
||||
m("tbody", rows)
|
||||
]);
|
||||
}
|
||||
};
|
@ -4,11 +4,14 @@ import routes from './routes.js';
|
||||
import wsChannel from './WebSocketChannel.js';
|
||||
import config from './config.js';
|
||||
import { hashCompat } from './compat.js';
|
||||
import layerManager from './map/LayerManager.js';
|
||||
|
||||
// hash route compat
|
||||
hashCompat();
|
||||
|
||||
getConfig().then(cfg => {
|
||||
|
||||
layerManager.setup(cfg.layers);
|
||||
config.set(cfg);
|
||||
wsChannel.connect();
|
||||
m.route(document.getElementById("app"), "/map/0/12/0/0", routes);
|
||||
|
@ -2,17 +2,20 @@ import RealtimeTileLayer from './RealtimeTileLayer.js';
|
||||
|
||||
class LayerManager {
|
||||
|
||||
setup(wsChannel, layers, map, currentLayerId){
|
||||
setup(layers){
|
||||
this.listeners = [];
|
||||
this.currentLayer = layers[0];
|
||||
this.layers = layers;
|
||||
this.currentLayer = this.layers[0];
|
||||
}
|
||||
|
||||
setupMap(wsChannel, map, currentLayerId){
|
||||
this.map = map;
|
||||
this.layerObjects = {};
|
||||
|
||||
var self = this;
|
||||
|
||||
//All layers
|
||||
layers.forEach(function(layer){
|
||||
this.layers.forEach(function(layer){
|
||||
var tileLayer = new RealtimeTileLayer(wsChannel, layer.id, map);
|
||||
self.layerObjects[layer.name] = tileLayer;
|
||||
if (layer.id == currentLayerId){
|
||||
|
@ -25,7 +25,7 @@ export function createMap(node, layerId, zoom, lat, lon){
|
||||
|
||||
var overlays = {};
|
||||
|
||||
layerManager.setup(wsChannel, cfg.layers, map, layerId);
|
||||
layerManager.setupMap(wsChannel, map, layerId);
|
||||
|
||||
//All overlays
|
||||
Overlaysetup(cfg, map, overlays, wsChannel, layerManager);
|
||||
|
@ -17,41 +17,7 @@ export default {
|
||||
|
||||
SearchStore.busy = true;
|
||||
|
||||
function searchFor(type, key, valuelike){
|
||||
return getMapObjects({
|
||||
pos1: { x:-2048, y:-2048, z:-2048 },
|
||||
pos2: { x:2048, y:2048, z:2048 },
|
||||
type: type,
|
||||
attributelike: {
|
||||
key: key,
|
||||
value: "%" + valuelike +"%"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var prom_list = [
|
||||
searchFor("shop", "out_item", SearchStore.query),
|
||||
searchFor("poi", "name", SearchStore.query),
|
||||
searchFor("train", "station", SearchStore.query),
|
||||
searchFor("travelnet", "station_name", SearchStore.query),
|
||||
searchFor("bones", "owner", SearchStore.query),
|
||||
searchFor("locator", "name", SearchStore.query),
|
||||
searchFor("label", "text", SearchStore.query),
|
||||
searchFor("digiterm", "display_text", SearchStore.query),
|
||||
searchFor("digilinelcd", "text", SearchStore.query)
|
||||
];
|
||||
|
||||
Promise.all(prom_list)
|
||||
.then(function(results){
|
||||
|
||||
var arr = [];
|
||||
results.forEach(function(r) {
|
||||
arr = arr.concat(r);
|
||||
});
|
||||
|
||||
SearchStore.result = arr;
|
||||
SearchStore.busy = false;
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user