forked from MTSR/mapserver
jshint + cleanup
This commit is contained in:
parent
3bde44da92
commit
b21cda248f
2
Makefile
2
Makefile
@ -36,7 +36,7 @@ clean:
|
||||
rm -rf $(OUT_DIR)
|
||||
|
||||
jshint:
|
||||
jshint static/js/*.js static/js/util static/js/overlays static/js/search
|
||||
jshint static/js/*.js static/js/components static/js/map static/js/util
|
||||
|
||||
$(STATIC_VFS):
|
||||
go generate
|
||||
|
@ -4,12 +4,12 @@ export function hashCompat(){
|
||||
if (window.location.hash) {
|
||||
let match = window.location.hash.match(/^#\/(\d*)\/(\d*)\/(\d*)$/m);
|
||||
if (match) {
|
||||
window.location.hash = `#!/map/0/${match[1]}/${match[2]}/${match[3]}`
|
||||
window.location.hash = `#!/map/0/${match[1]}/${match[2]}/${match[3]}`;
|
||||
}
|
||||
|
||||
match = window.location.hash.match(/^#\/(\d*)\/(\d*)\/(\d*)\/(\d*)$/m);
|
||||
if (match) {
|
||||
window.location.hash = `#!/map/${match[1]}/${match[2]}/${match[3]}/${match[4]}`
|
||||
window.location.hash = `#!/map/${match[1]}/${match[2]}/${match[3]}/${match[4]}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
import wsChannel from '../WebSocketChannel.js';
|
||||
import layerManager from '../map/LayerManager.js';
|
||||
import { createMap } from '../map/MapFactory.js';
|
||||
|
||||
export default {
|
||||
view(vnode){
|
||||
view(){
|
||||
return m("div", { class: "full-screen" });
|
||||
},
|
||||
|
||||
@ -31,7 +30,7 @@ export default {
|
||||
map.on('baselayerchange', updateHash);
|
||||
},
|
||||
|
||||
onbeforeupdate(newVnode, oldVnode) {
|
||||
onbeforeupdate(newVnode) {
|
||||
const center = newVnode.state.map.getCenter();
|
||||
const newAattrs = newVnode.attrs;
|
||||
|
||||
@ -49,4 +48,4 @@ export default {
|
||||
onremove(vnode){
|
||||
vnode.state.map.remove();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -4,7 +4,7 @@ import { getMapObjects } from '../api.js';
|
||||
const state = {
|
||||
busy: false,
|
||||
result: []
|
||||
}
|
||||
};
|
||||
|
||||
function searchFor(type, key, valuelike){
|
||||
return getMapObjects({
|
||||
@ -49,7 +49,6 @@ function search(query){
|
||||
|
||||
export default {
|
||||
oncreate(vnode){
|
||||
console.log("oncreate", vnode);
|
||||
search(vnode.attrs.query);
|
||||
},
|
||||
|
||||
@ -57,7 +56,7 @@ export default {
|
||||
if (state.result.length == 0) {
|
||||
return m("div", vnode.attrs.query);
|
||||
} else {
|
||||
return m(SearchResult, { result: state.result })
|
||||
return m(SearchResult, { result: state.result });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,7 +1,7 @@
|
||||
|
||||
const state = {
|
||||
query: ""
|
||||
}
|
||||
};
|
||||
|
||||
function doSearch(){
|
||||
m.route.set(`/search/${state.query}`);
|
||||
|
@ -9,4 +9,4 @@ export default {
|
||||
set(cfg){
|
||||
config = cfg;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -2,7 +2,7 @@
|
||||
var customOverlays = {};
|
||||
|
||||
try {
|
||||
customOverlays = JSON.parse(localStorage["mapserver-customOverlays"])
|
||||
customOverlays = JSON.parse(localStorage["mapserver-customOverlays"]);
|
||||
} catch (e){}
|
||||
|
||||
function save(){
|
||||
|
@ -5,7 +5,7 @@ export default L.Control.extend({
|
||||
L.Control.prototype.initialize.call(this, opts);
|
||||
},
|
||||
|
||||
onAdd: function(map) {
|
||||
onAdd: function() {
|
||||
var div = L.DomUtil.create('div');
|
||||
m.mount(div, SearchInput);
|
||||
return div;
|
||||
|
@ -1,35 +0,0 @@
|
||||
import SearchStore from './SearchStore.js';
|
||||
import SearchService from './SearchService.js';
|
||||
|
||||
export default {
|
||||
view: function(){
|
||||
function handleInput(e){
|
||||
SearchStore.query = e.target.value;
|
||||
}
|
||||
|
||||
function handleKeyDown(e){
|
||||
if (e.keyCode == 13){
|
||||
SearchService.search();
|
||||
}
|
||||
}
|
||||
|
||||
function handleDoSearch(){
|
||||
SearchService.search();
|
||||
}
|
||||
|
||||
return m("div", { class: "input-group mb-3" }, [
|
||||
m("input[type=text]", {
|
||||
placeholder: "Search",
|
||||
class: "form-control",
|
||||
oninput: handleInput,
|
||||
onkeydown: handleKeyDown,
|
||||
value: SearchStore.query
|
||||
}),
|
||||
m("div", { class: "input-group-append", onclick: handleDoSearch }, [
|
||||
m("span", { class: "input-group-text" }, [
|
||||
m("i", { class: "fa fa-search"})
|
||||
])
|
||||
])
|
||||
]);
|
||||
}
|
||||
};
|
@ -1,36 +0,0 @@
|
||||
|
||||
import SearchService from './SearchService.js';
|
||||
import SearchStore from './SearchStore.js';
|
||||
import SearchResult from './SearchResult.js';
|
||||
|
||||
export default {
|
||||
view: function(vnode){
|
||||
|
||||
var style = {};
|
||||
|
||||
if (!SearchStore.show) {
|
||||
style.display = "none";
|
||||
}
|
||||
|
||||
function close(){
|
||||
SearchService.clear();
|
||||
}
|
||||
|
||||
function getContent(){
|
||||
if (SearchStore.busy){
|
||||
return m("div", m("i", { class: "fa fa-spinner"}));
|
||||
} else {
|
||||
return m(SearchResult, { map: vnode.attrs.map });
|
||||
}
|
||||
}
|
||||
|
||||
return m("div", { class: "card", id: "search-menu", style: style }, [
|
||||
m("div", { class: "card-header" }, [
|
||||
m("i", { class: "fa fa-search"}),
|
||||
"Search",
|
||||
m("i", { class: "fa fa-times float-right", onclick: close }),
|
||||
]),
|
||||
m("div", { class: "card-body", style: {overflow: "auto"} }, getContent())
|
||||
]);
|
||||
}
|
||||
};
|
@ -1,157 +0,0 @@
|
||||
import SearchStore from './SearchStore.js';
|
||||
import layerMgr from '../map/LayerManager.js';
|
||||
|
||||
export default {
|
||||
view: function(vnode){
|
||||
var map = vnode.attrs.map;
|
||||
|
||||
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 = SearchStore.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);
|
||||
|
||||
layerMgr.switchLayer(layer.id);
|
||||
|
||||
map.setView([obj.z, obj.x], 12);
|
||||
SearchStore.show = false;
|
||||
}
|
||||
|
||||
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)
|
||||
]);
|
||||
}
|
||||
};
|
@ -1,28 +0,0 @@
|
||||
import SearchStore from './SearchStore.js';
|
||||
import { getMapObjects } from '../api.js';
|
||||
|
||||
export default {
|
||||
|
||||
search: function(){
|
||||
SearchStore.show = true;
|
||||
this.fetchData();
|
||||
},
|
||||
|
||||
fetchData: function(){
|
||||
SearchStore.result = [];
|
||||
|
||||
if (!SearchStore.query){
|
||||
return;
|
||||
}
|
||||
|
||||
SearchStore.busy = true;
|
||||
|
||||
|
||||
|
||||
},
|
||||
|
||||
clear: function(){
|
||||
SearchStore.result = [];
|
||||
SearchStore.show = false;
|
||||
}
|
||||
};
|
@ -1,7 +0,0 @@
|
||||
|
||||
export default {
|
||||
query: "",
|
||||
show: false,
|
||||
busy: false,
|
||||
result: []
|
||||
};
|
@ -4,12 +4,12 @@ import Search from './components/Search.js';
|
||||
|
||||
var Home = {
|
||||
view: function() {
|
||||
return "Home"
|
||||
return "Home";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default {
|
||||
"/": Home,
|
||||
"/map/:layerId/:zoom/:lon/:lat": Map,
|
||||
"/search/:query": Search
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user