Boat Routes/gmap/code

From MinecraftOnline
Jump to navigation Jump to search

This feature has been replaced by overlays on the Map using Overviewer. See Template:BoatRouteData.

tl;dr: scroll down

This is code that can be used in bookmarklets to display the boat routes on the Map. The code is written in CoffeeScript, and has to be compiled to javascript first. The data for the boat routes can be found on Boat Routes/gmap. Please note that this is not up to date.

require = (pkg) =>
    @_required ?= []
    if pkg in @_required
        Promise.resolve pkg
    else
        new Promise (resolve, reject) =>
            script = document.createElement 'script'
            script.src = "//unpkg.com/#{pkg}"
            script.onload = =>
                @_required.push pkg
                resolve pkg
                return
            script.onerror = reject
            document.body.appendChild script
            return

handleData = (data) =>
    for name, info of data
        L.Polyline.fromEncoded info.path, color: info.color
                .bindTooltip name, sticky: true
                .addTo overviewer.map
        L.Polyline.fromEncoded info.path, color: 'white', dashArray: '5 10'
                .bindTooltip name, sticky: true
                .addTo overviewer.map
        for bname, binfo of info.branches
            L.Polyline.fromEncoded binfo.path, color: binfo.color
                    .bindTooltip bname, sticky: true
                    .addTo overviewer.map
    return

require "polyline-encoded"
    .then =>
        fetch "/w/api.php?format=json&action=query&titles=Boat Routes/gmap&prop=revisions&rvprop=content"
    .then (response) =>
        response.json()
    .then (json) =>
        for _, page of json.query.pages
            handleData JSON.parse page.revisions[0]['*']
        return

And here's the version that can be used directly as bookmarklet:

javascript:(function(){var o,e=[].indexOf;o=(o=>{var e,r,i,n,t;for(n in o)for(r in i=o[n],L.Polyline.fromEncoded(i.path,{color:i.color}).bindTooltip(n,{sticky:!0}).addTo(overviewer.map),L.Polyline.fromEncoded(i.path,{color:"white",dashArray:"5 10"}).bindTooltip(n,{sticky:!0}).addTo(overviewer.map),t=i.branches)e=t[r],L.Polyline.fromEncoded(e.path,{color:e.color}).bindTooltip(r,{sticky:!0}).addTo(overviewer.map)}),(o=>(null==this._required&&(this._required=[]),e.call(this._required,o)>=0?Promise.resolve(o):new Promise((e,r)=>{var i;(i=document.createElement("script")).src=`//unpkg.com/${o}`,i.onload=(()=>{this._required.push(o),e(o)}),i.onerror=r,document.body.appendChild(i)})))("polyline-encoded").then(()=>fetch("/w/api.php?format=json&action=query&titles=Boat Routes/gmap&prop=revisions&rvprop=content")).then(o=>o.json()).then(e=>{var r,i,n;for(r in n=e.query.pages)i=n[r],o(JSON.parse(i.revisions[0]["*"]))})}).call(this);

If you're interested in adding routes, check out Route tools.

Since this code is placed on this wiki, it's licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported license (see MinecraftOnline:Copyrights for details).