diff --git a/Makefile b/Makefile
index d7f2c00..529bf21 100644
--- a/Makefile
+++ b/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
diff --git a/go.mod b/go.mod
index 2ff95de..3a87658 100644
--- a/go.mod
+++ b/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.4.2
- github.com/stretchr/testify v1.2.2
+ github.com/stretchr/testify v1.4.0
github.com/yuin/gopher-lua v0.0.0-20190206043414-8bfc7677f583
golang.org/x/image v0.0.0-20190118043309-183bebdce1b2 // indirect
)
diff --git a/go.sum b/go.sum
index 51d6b77..27b948d 100644
--- a/go.sum
+++ b/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=
@@ -71,10 +76,13 @@ github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
+github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
+github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/yuin/gopher-lua v0.0.0-20190206043414-8bfc7677f583 h1:SZPG5w7Qxq7bMcMVl6e3Ht2X7f+AAGQdzjkbyOnNNZ8=
github.com/yuin/gopher-lua v0.0.0-20190206043414-8bfc7677f583/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I=
@@ -98,3 +106,5 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
diff --git a/static/css/custom.css b/static/css/custom.css
index 343f9a5..108c255 100644
--- a/static/css/custom.css
+++ b/static/css/custom.css
@@ -1,10 +1,13 @@
body {
- height: 100%;
+ height: 98%;
margin: 0;
- overflow: hidden;
}
-#image-map {
+#app {
+ height: 100%;
+}
+
+.full-screen {
width: 100%;
height: 100%;
border: 1px solid #ccc;
@@ -16,15 +19,6 @@ body {
padding: 5px;
}
-#search-menu {
- position: absolute;
- top: 5%;
- bottom: 5%;
- left: 5%;
- right: 5%;
- z-index: 99999;
-}
-
.mapserver-label-icon {
margin-left: -100px !important;
margin-top: -100px !important;
diff --git a/static/index.html b/static/index.html
index 5b98d85..f1d1e29 100644
--- a/static/index.html
+++ b/static/index.html
@@ -15,8 +15,7 @@
Minetest Mapserver
-
-
+
diff --git a/static/js/Hashroute.js b/static/js/Hashroute.js
deleted file mode 100644
index f3b3777..0000000
--- a/static/js/Hashroute.js
+++ /dev/null
@@ -1,59 +0,0 @@
-
-export default {
-
- setup: function(map, layerMgr){
- function updateHash(){
- var center = map.getCenter();
- window.location.hash =
- layerMgr.getCurrentLayer().id + "/" +
- center.lng + "/" + center.lat + "/" + map.getZoom();
- }
-
- map.on('zoomend', updateHash);
- map.on('moveend', updateHash);
- map.on('baselayerchange', updateHash);
- updateHash();
- },
-
- getLayerId: function(){
- var hashParts = window.location.hash.substring(1).split("/");
- if (hashParts.length == 4){
- //new format
- return +hashParts[0];
-
- }
-
- return 0;
- },
-
- getZoom: function(){
- var hashParts = window.location.hash.substring(1).split("/");
- if (hashParts.length == 3){
- //old format
- return +hashParts[2];
-
- } else if (hashParts.length == 4){
- //new format
- return +hashParts[3];
-
- }
-
- return 11;
- },
-
- getCenter: function(){
- var hashParts = window.location.hash.substring(1).split("/");
- if (hashParts.length == 3){
- //old format
- return [+hashParts[1], +hashParts[0]];
-
- } else if (hashParts.length == 4){
- //new format
- return [+hashParts[2], +hashParts[1]];
-
- }
-
- return [0, 0];
- }
-
-};
diff --git a/static/js/compat.js b/static/js/compat.js
new file mode 100644
index 0000000..ad4c44b
--- /dev/null
+++ b/static/js/compat.js
@@ -0,0 +1,15 @@
+
+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]}`;
+ }
+
+ match = window.location.hash.match(/^#\/(\d*)\/(\d*)\/(\d*)\/(\d*)$/m);
+ if (match) {
+ window.location.hash = `#!/map/${match[1]}/${match[2]}/${match[3]}/${match[4]}`;
+ }
+ }
+}
diff --git a/static/js/components/Map.js b/static/js/components/Map.js
new file mode 100644
index 0000000..6329b0c
--- /dev/null
+++ b/static/js/components/Map.js
@@ -0,0 +1,51 @@
+import layerManager from '../map/LayerManager.js';
+import { createMap } from '../map/MapFactory.js';
+
+export default {
+ view(){
+ return m("div", { class: "full-screen" });
+ },
+
+ oncreate(vnode){
+
+ const map = createMap(
+ vnode.dom,
+ +vnode.attrs.layerId,
+ +vnode.attrs.zoom,
+ +vnode.attrs.lat,
+ +vnode.attrs.lon
+ );
+
+ vnode.state.map = map;
+
+ function updateHash(){
+ const center = map.getCenter();
+ const layerId = layerManager.getCurrentLayer().id;
+
+ m.route.set(`/map/${layerId}/${map.getZoom()}/${center.lng}/${center.lat}`);
+ }
+
+ map.on('zoomend', updateHash);
+ map.on('moveend', updateHash);
+ map.on('baselayerchange', updateHash);
+ },
+
+ onbeforeupdate(newVnode) {
+ const center = newVnode.state.map.getCenter();
+ const newAattrs = newVnode.attrs;
+
+ return newAattrs.layerId != layerManager.getCurrentLayer().id ||
+ newAattrs.zoom != newVnode.state.map.getZoom() ||
+ Math.abs(newAattrs.lat - center.lat) > 0.1 ||
+ Math.abs(newAattrs.lat - center.lat) > 0.1;
+ },
+
+ onupdate(vnode){
+ layerManager.switchLayer(+vnode.attrs.layerId);
+ vnode.state.map.setView([+vnode.attrs.lat, +vnode.attrs.lon], +vnode.attrs.zoom);
+ },
+
+ onremove(vnode){
+ vnode.state.map.remove();
+ }
+};
diff --git a/static/js/components/Search.js b/static/js/components/Search.js
new file mode 100644
index 0000000..668db86
--- /dev/null
+++ b/static/js/components/Search.js
@@ -0,0 +1,62 @@
+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){
+ search(vnode.attrs.query);
+ },
+
+ view(vnode){
+ if (state.result.length == 0) {
+ return m("div", vnode.attrs.query);
+ } else {
+ return m(SearchResult, { result: state.result });
+ }
+ }
+};
diff --git a/static/js/search/SearchInput.js b/static/js/components/SearchInput.js
similarity index 59%
rename from static/js/search/SearchInput.js
rename to static/js/components/SearchInput.js
index b584f03..be43df3 100644
--- a/static/js/search/SearchInput.js
+++ b/static/js/components/SearchInput.js
@@ -1,31 +1,34 @@
-import SearchStore from './SearchStore.js';
-import SearchService from './SearchService.js';
+
+const state = {
+ query: ""
+};
+
+function doSearch(){
+ m.route.set(`/search/${state.query}`);
+}
export default {
view: function(){
+
function handleInput(e){
- SearchStore.query = e.target.value;
+ state.query = e.target.value;
}
function handleKeyDown(e){
if (e.keyCode == 13){
- SearchService.search();
+ doSearch();
}
}
- 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
+ value: state.query
}),
- m("div", { class: "input-group-append", onclick: handleDoSearch }, [
+ m("div", { class: "input-group-append", onclick: doSearch }, [
m("span", { class: "input-group-text" }, [
m("i", { class: "fa fa-search"})
])
diff --git a/static/js/search/SearchResult.js b/static/js/components/SearchResult.js
similarity index 93%
rename from static/js/search/SearchResult.js
rename to static/js/components/SearchResult.js
index 88de72e..2618fca 100644
--- a/static/js/search/SearchResult.js
+++ b/static/js/components/SearchResult.js
@@ -1,9 +1,8 @@
-import SearchStore from './SearchStore.js';
-import layerMgr from '../LayerManager.js';
+import layerMgr from '../map/LayerManager.js';
export default {
view: function(vnode){
- var map = vnode.attrs.map;
+ var result = vnode.attrs.result;
function getLayer(obj){
var layer = layerMgr.getLayerByY(obj.y);
@@ -16,7 +15,7 @@ export default {
return m("span", {class:"badge badge-success"}, text);
}
- var rows = SearchStore.result.map(function(obj){
+ var rows = result.map(function(obj){
var row_classes = "";
var description = obj.type;
@@ -120,11 +119,7 @@ export default {
function onclick(){
var layer = layerMgr.getLayerByY(obj.y);
-
- layerMgr.switchLayer(layer.id);
-
- map.setView([obj.z, obj.x], 12);
- SearchStore.show = false;
+ m.route.set(`/map/${layer.id}/${12}/${obj.x}/${obj.z}`);
}
return m("tr", {"class": row_classes}, [
diff --git a/static/js/config.js b/static/js/config.js
new file mode 100644
index 0000000..b348712
--- /dev/null
+++ b/static/js/config.js
@@ -0,0 +1,12 @@
+
+var config;
+
+export default {
+ get(){
+ return config;
+ },
+
+ set(cfg){
+ config = cfg;
+ }
+};
diff --git a/static/js/main.js b/static/js/main.js
index 080e9ee..3835a8f 100644
--- a/static/js/main.js
+++ b/static/js/main.js
@@ -1,5 +1,18 @@
import { getConfig } from './api.js';
-import { setup } from './map.js';
+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';
-getConfig().then(setup);
+// 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);
+});
diff --git a/static/js/CoordinatesDisplay.js b/static/js/map/CoordinatesDisplay.js
similarity index 100%
rename from static/js/CoordinatesDisplay.js
rename to static/js/map/CoordinatesDisplay.js
diff --git a/static/js/map/CustomOverlay.js b/static/js/map/CustomOverlay.js
new file mode 100644
index 0000000..b59a95f
--- /dev/null
+++ b/static/js/map/CustomOverlay.js
@@ -0,0 +1,48 @@
+
+var customOverlays = {};
+
+try {
+ customOverlays = JSON.parse(localStorage["mapserver-customOverlays"]);
+} catch (e){}
+
+function save(){
+ localStorage["mapserver-customOverlays"] = JSON.stringify(customOverlays);
+}
+
+function onAddLayer(e){
+ customOverlays[e.name] = true;
+ save();
+}
+
+function onRemoveLayer(e){
+ customOverlays[e.name] = false;
+ save();
+}
+
+export default function(map, overlays){
+
+ Object.keys(customOverlays)
+ .filter(name => overlays[name])
+ .forEach(name => {
+ const layer = overlays[name];
+
+ if (customOverlays[name] && !map.hasLayer(layer)){
+ //Add
+ map.addLayer(layer);
+ }
+
+ if (!customOverlays[name] && map.hasLayer(layer)){
+ //Remove
+ map.removeLayer(layer);
+ }
+ });
+
+ map.on('unload', () => {
+ map.off('overlayadd', onAddLayer);
+ map.off('overlayremove', onRemoveLayer);
+ });
+
+ map.on('overlayadd', onAddLayer);
+ map.on('overlayremove', onRemoveLayer);
+
+}
diff --git a/static/js/LayerManager.js b/static/js/map/LayerManager.js
similarity index 91%
rename from static/js/LayerManager.js
rename to static/js/map/LayerManager.js
index 6d0d395..7d4e2f4 100644
--- a/static/js/LayerManager.js
+++ b/static/js/map/LayerManager.js
@@ -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){
diff --git a/static/js/map.js b/static/js/map/MapFactory.js
similarity index 70%
rename from static/js/map.js
rename to static/js/map/MapFactory.js
index 882c015..789f81c 100644
--- a/static/js/map.js
+++ b/static/js/map/MapFactory.js
@@ -1,21 +1,23 @@
-import wsChannel from './WebSocketChannel.js';
-import Hashroute from './Hashroute.js';
+import wsChannel from '../WebSocketChannel.js';
import SimpleCRS from './SimpleCRS.js';
import CoordinatesDisplay from './CoordinatesDisplay.js';
import WorldInfoDisplay from './WorldInfoDisplay.js';
import SearchControl from './SearchControl.js';
import Overlaysetup from './Overlaysetup.js';
+import CustomOverlay from './CustomOverlay.js';
import layerManager from './LayerManager.js';
+import config from '../config.js';
-export function setup(cfg){
- wsChannel.connect();
+export function createMap(node, layerId, zoom, lat, lon){
- var map = L.map('image-map', {
+ const cfg = config.get();
+
+ const map = L.map(node, {
minZoom: 2,
maxZoom: 12,
- center: Hashroute.getCenter(),
- zoom: Hashroute.getZoom(),
+ center: [lat, lon],
+ zoom: zoom,
crs: SimpleCRS
});
@@ -23,10 +25,11 @@ export function setup(cfg){
var overlays = {};
- layerManager.setup(wsChannel, cfg.layers, map, Hashroute.getLayerId());
+ layerManager.setupMap(wsChannel, map, layerId);
//All overlays
Overlaysetup(cfg, map, overlays, wsChannel, layerManager);
+ CustomOverlay(map, overlays);
new CoordinatesDisplay({ position: 'bottomleft' }).addTo(map);
new WorldInfoDisplay(wsChannel, { position: 'bottomright' }).addTo(map);
@@ -38,5 +41,5 @@ export function setup(cfg){
//layer control
L.control.layers(layerManager.layerObjects, overlays, { position: "topright" }).addTo(map);
- Hashroute.setup(map, layerManager);
+ return map;
}
diff --git a/static/js/Overlaysetup.js b/static/js/map/Overlaysetup.js
similarity index 100%
rename from static/js/Overlaysetup.js
rename to static/js/map/Overlaysetup.js
diff --git a/static/js/RealtimeTileLayer.js b/static/js/map/RealtimeTileLayer.js
similarity index 100%
rename from static/js/RealtimeTileLayer.js
rename to static/js/map/RealtimeTileLayer.js
diff --git a/static/js/SearchControl.js b/static/js/map/SearchControl.js
similarity index 50%
rename from static/js/SearchControl.js
rename to static/js/map/SearchControl.js
index 1aa228f..34a5fcf 100644
--- a/static/js/SearchControl.js
+++ b/static/js/map/SearchControl.js
@@ -1,18 +1,13 @@
-import SearchMenu from './search/SearchMenu.js';
-import SearchInput from './search/SearchInput.js';
+import SearchInput from '../components/SearchInput.js';
export default L.Control.extend({
initialize: function(wsChannel, opts) {
L.Control.prototype.initialize.call(this, opts);
},
- onAdd: function(map) {
+ onAdd: function() {
var div = L.DomUtil.create('div');
m.mount(div, SearchInput);
- m.mount(document.getElementById("search-content"), {
- view: () => m(SearchMenu, {map: map})
- });
-
return div;
}
});
diff --git a/static/js/SimpleCRS.js b/static/js/map/SimpleCRS.js
similarity index 100%
rename from static/js/SimpleCRS.js
rename to static/js/map/SimpleCRS.js
diff --git a/static/js/WorldInfoDisplay.js b/static/js/map/WorldInfoDisplay.js
similarity index 100%
rename from static/js/WorldInfoDisplay.js
rename to static/js/map/WorldInfoDisplay.js
diff --git a/static/js/overlays/ATMOverlay.js b/static/js/map/overlays/ATMOverlay.js
similarity index 100%
rename from static/js/overlays/ATMOverlay.js
rename to static/js/map/overlays/ATMOverlay.js
diff --git a/static/js/overlays/AbstractGeoJsonOverlay.js b/static/js/map/overlays/AbstractGeoJsonOverlay.js
similarity index 96%
rename from static/js/overlays/AbstractGeoJsonOverlay.js
rename to static/js/map/overlays/AbstractGeoJsonOverlay.js
index 1827d32..2be845a 100644
--- a/static/js/overlays/AbstractGeoJsonOverlay.js
+++ b/static/js/map/overlays/AbstractGeoJsonOverlay.js
@@ -1,5 +1,5 @@
-import debounce from '../util/debounce.js';
-import { getMapObjects } from '../api.js';
+import debounce from '../../util/debounce.js';
+import { getMapObjects } from '../../api.js';
export default L.LayerGroup.extend({
initialize: function(wsChannel, layerMgr, type) {
diff --git a/static/js/overlays/AbstractIconOverlay.js b/static/js/map/overlays/AbstractIconOverlay.js
similarity index 97%
rename from static/js/overlays/AbstractIconOverlay.js
rename to static/js/map/overlays/AbstractIconOverlay.js
index dc5aa12..560486b 100644
--- a/static/js/overlays/AbstractIconOverlay.js
+++ b/static/js/map/overlays/AbstractIconOverlay.js
@@ -1,5 +1,5 @@
-import debounce from '../util/debounce.js';
-import { getMapObjects } from '../api.js';
+import debounce from '../../util/debounce.js';
+import { getMapObjects } from '../../api.js';
export default L.LayerGroup.extend({
initialize: function(wsChannel, layerMgr, type, icon) {
diff --git a/static/js/overlays/BonesOverlay.js b/static/js/map/overlays/BonesOverlay.js
similarity index 100%
rename from static/js/overlays/BonesOverlay.js
rename to static/js/map/overlays/BonesOverlay.js
diff --git a/static/js/overlays/BorderOverlay.js b/static/js/map/overlays/BorderOverlay.js
similarity index 100%
rename from static/js/overlays/BorderOverlay.js
rename to static/js/map/overlays/BorderOverlay.js
diff --git a/static/js/overlays/DigitermOverlay.js b/static/js/map/overlays/DigitermOverlay.js
similarity index 100%
rename from static/js/overlays/DigitermOverlay.js
rename to static/js/map/overlays/DigitermOverlay.js
diff --git a/static/js/overlays/LabelOverlay.js b/static/js/map/overlays/LabelOverlay.js
similarity index 100%
rename from static/js/overlays/LabelOverlay.js
rename to static/js/map/overlays/LabelOverlay.js
diff --git a/static/js/overlays/LcdOverlay.js b/static/js/map/overlays/LcdOverlay.js
similarity index 100%
rename from static/js/overlays/LcdOverlay.js
rename to static/js/map/overlays/LcdOverlay.js
diff --git a/static/js/overlays/LocatorOverlay.js b/static/js/map/overlays/LocatorOverlay.js
similarity index 100%
rename from static/js/overlays/LocatorOverlay.js
rename to static/js/map/overlays/LocatorOverlay.js
diff --git a/static/js/overlays/LuacontrollerOverlay.js b/static/js/map/overlays/LuacontrollerOverlay.js
similarity index 100%
rename from static/js/overlays/LuacontrollerOverlay.js
rename to static/js/map/overlays/LuacontrollerOverlay.js
diff --git a/static/js/overlays/MinecartOverlay.js b/static/js/map/overlays/MinecartOverlay.js
similarity index 100%
rename from static/js/overlays/MinecartOverlay.js
rename to static/js/map/overlays/MinecartOverlay.js
diff --git a/static/js/overlays/MissionOverlay.js b/static/js/map/overlays/MissionOverlay.js
similarity index 100%
rename from static/js/overlays/MissionOverlay.js
rename to static/js/map/overlays/MissionOverlay.js
diff --git a/static/js/overlays/PlayerOverlay.js b/static/js/map/overlays/PlayerOverlay.js
similarity index 100%
rename from static/js/overlays/PlayerOverlay.js
rename to static/js/map/overlays/PlayerOverlay.js
diff --git a/static/js/overlays/PoiOverlay.js b/static/js/map/overlays/PoiOverlay.js
similarity index 100%
rename from static/js/overlays/PoiOverlay.js
rename to static/js/map/overlays/PoiOverlay.js
diff --git a/static/js/overlays/PrivProtectorOverlay.js b/static/js/map/overlays/PrivProtectorOverlay.js
similarity index 100%
rename from static/js/overlays/PrivProtectorOverlay.js
rename to static/js/map/overlays/PrivProtectorOverlay.js
diff --git a/static/js/overlays/ProtectorOverlay.js b/static/js/map/overlays/ProtectorOverlay.js
similarity index 100%
rename from static/js/overlays/ProtectorOverlay.js
rename to static/js/map/overlays/ProtectorOverlay.js
diff --git a/static/js/overlays/ShopOverlay.js b/static/js/map/overlays/ShopOverlay.js
similarity index 100%
rename from static/js/overlays/ShopOverlay.js
rename to static/js/map/overlays/ShopOverlay.js
diff --git a/static/js/overlays/TechnicAnchorOverlay.js b/static/js/map/overlays/TechnicAnchorOverlay.js
similarity index 100%
rename from static/js/overlays/TechnicAnchorOverlay.js
rename to static/js/map/overlays/TechnicAnchorOverlay.js
diff --git a/static/js/overlays/TechnicQuarryOverlay.js b/static/js/map/overlays/TechnicQuarryOverlay.js
similarity index 100%
rename from static/js/overlays/TechnicQuarryOverlay.js
rename to static/js/map/overlays/TechnicQuarryOverlay.js
diff --git a/static/js/overlays/TechnicSwitchOverlay.js b/static/js/map/overlays/TechnicSwitchOverlay.js
similarity index 100%
rename from static/js/overlays/TechnicSwitchOverlay.js
rename to static/js/map/overlays/TechnicSwitchOverlay.js
diff --git a/static/js/overlays/TrainOverlay.js b/static/js/map/overlays/TrainOverlay.js
similarity index 100%
rename from static/js/overlays/TrainOverlay.js
rename to static/js/map/overlays/TrainOverlay.js
diff --git a/static/js/overlays/TrainlineOverlay.js b/static/js/map/overlays/TrainlineOverlay.js
similarity index 100%
rename from static/js/overlays/TrainlineOverlay.js
rename to static/js/map/overlays/TrainlineOverlay.js
diff --git a/static/js/overlays/TrainsignalOverlay.js b/static/js/map/overlays/TrainsignalOverlay.js
similarity index 100%
rename from static/js/overlays/TrainsignalOverlay.js
rename to static/js/map/overlays/TrainsignalOverlay.js
diff --git a/static/js/overlays/TravelnetOverlay.js b/static/js/map/overlays/TravelnetOverlay.js
similarity index 100%
rename from static/js/overlays/TravelnetOverlay.js
rename to static/js/map/overlays/TravelnetOverlay.js
diff --git a/static/js/overlays/XPProtectorOverlay.js b/static/js/map/overlays/XPProtectorOverlay.js
similarity index 100%
rename from static/js/overlays/XPProtectorOverlay.js
rename to static/js/map/overlays/XPProtectorOverlay.js
diff --git a/static/js/nomodule.js b/static/js/nomodule.js
index 4adba96..c46af90 100644
--- a/static/js/nomodule.js
+++ b/static/js/nomodule.js
@@ -1,5 +1,5 @@
-m.mount(document.getElementById("image-map"), {
+m.mount(document.getElementById("app"), {
view: function(){
return m("div", "I'm sorry, your browser is just too old ;)");
}
diff --git a/static/js/routes.js b/static/js/routes.js
new file mode 100644
index 0000000..b715183
--- /dev/null
+++ b/static/js/routes.js
@@ -0,0 +1,15 @@
+
+import Map from './components/Map.js';
+import Search from './components/Search.js';
+
+var Home = {
+ view: function() {
+ return "Home";
+ }
+};
+
+export default {
+ "/": Home,
+ "/map/:layerId/:zoom/:lon/:lat": Map,
+ "/search/:query": Search
+};
diff --git a/static/js/search/SearchMenu.js b/static/js/search/SearchMenu.js
deleted file mode 100644
index 66dcc21..0000000
--- a/static/js/search/SearchMenu.js
+++ /dev/null
@@ -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())
- ]);
- }
-};
diff --git a/static/js/search/SearchService.js b/static/js/search/SearchService.js
deleted file mode 100644
index fe521a8..0000000
--- a/static/js/search/SearchService.js
+++ /dev/null
@@ -1,62 +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;
-
- 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;
- });
-
- },
-
- clear: function(){
- SearchStore.result = [];
- SearchStore.show = false;
- }
-};
diff --git a/static/js/search/SearchStore.js b/static/js/search/SearchStore.js
deleted file mode 100644
index a154484..0000000
--- a/static/js/search/SearchStore.js
+++ /dev/null
@@ -1,7 +0,0 @@
-
-export default {
- query: "",
- show: false,
- busy: false,
- result: []
-};