shop marker

master
Thomas Rudin 2018-08-20 09:47:58 +02:00
parent f148b443ee
commit 4e6ad00e7d
5 changed files with 89 additions and 0 deletions

View File

@ -74,6 +74,7 @@ public class TileServer {
get("/config", injector.getInstance(ConfigRoute.class), json);
get("/layers", injector.getInstance(LayerConfigRoute.class), json);
get("/shop", injector.getInstance(ShopRoute.class), json);
get("/travelnet", injector.getInstance(TravelnetRoute.class), json);
get("/missions", injector.getInstance(MissionsRoute.class), json);
get("/poi", injector.getInstance(PoiRoute.class), json);

View File

@ -0,0 +1,34 @@
package io.rudin.minetest.tileserver.route;
import io.rudin.minetest.tileserver.blockdb.tables.pojos.Shop;
import org.jooq.DSLContext;
import spark.Request;
import spark.Response;
import spark.Route;
import javax.inject.Inject;
import javax.inject.Singleton;
import static io.rudin.minetest.tileserver.blockdb.tables.Shop.SHOP;
@Singleton
public class ShopRoute implements Route {
@Inject
public ShopRoute(DSLContext ctx) {
this.ctx = ctx;
}
private final DSLContext ctx;
@Override
public Object handle(Request request, Response response) throws Exception {
response.header("Content-Type", "application/json");
return ctx
.selectFrom(SHOP)
.fetch()
.into(Shop.class);
}
}

View File

@ -28,6 +28,7 @@
<script src="js/tileserver.js"></script>
<script src="js/map.js"></script>
<script src="js/overlay.shop.js"></script>
<script src="js/overlay.poi.js"></script>
<script src="js/overlay.player.js"></script>
<script src="js/overlay.travelnet.js"></script>

View File

@ -0,0 +1,53 @@
(function(tileserver){
var shopLayer = L.layerGroup();
var ShopIcon = L.icon({
iconUrl: 'pics/shop.png',
iconSize: [32, 32],
iconAnchor: [16, 16],
popupAnchor: [0, -16]
});
function updateShop(shop) {
if (shop.y < tileserver.currentHeight.from || shop.y > tileserver.currentHeight.to)
//ignore block from different height
return;
var marker = L.marker([shop.z - 16, shop.x], {icon: ShopIcon});
var popup = "<h4>" + shop.type + "</h4><hr>" +
"<b>Owner: </b> " + shop.owner + "<br>" +
"<b>In item: </b> " + shop.inItem + "<br>" +
"<b>Out item: </b> " + shop.outItem + "<br>" +
"<b>Stock: </b> " + shop.outStock + "<br>" +
"<b>X: </b> " + shop.x + "<br>" +
"<b>Y: </b> " + shop.y + "<br>" +
"<b>Z: </b> " + shop.z + "<br>";
marker.bindPopup(popup).addTo(shopLayer);
}
function update(){
m.request({ url: "shop" })
.then(function(list){
shopLayer.clearLayers();
list.forEach(updateShop);
});
}
//update on height change
tileserver.heightChangedCallbacks.push(update);
tileserver.overlays["Shops"] = shopLayer;
tileserver.defaultOverlays.push(shopLayer);
//initial update
update();
})(window.tileserver);

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB