oobrien / oomap

OpenOrienteeringMap. Includes the website, tiling scripts, and mapnik stylesheets for OOMap and other raster tile layers.
GNU General Public License v2.0
45 stars 8 forks source link

Pull in postboxes from OSM as an addition to Dracos postboxes #50

Closed oobrien closed 1 year ago

oobrien commented 4 years ago

The OSM postbox locations may be more up to date but may not contain the clue numbers on the Dracos project. But they would also be available worldwide. So this could be implemented as an additional pull-in call, complementary to the existing one.

cadnant commented 3 years ago

This works - as coded (in main.js), replaces existing postbox search, but could have as an alternative instead. Could also genericise to pull in other OSM POIs?

function handleGetPostboxes()
{
    var bounds = ol.proj.transformExtent([mapBound[0], mapBound[1], mapBound[2], mapBound[3]], "EPSG:3857", "EPSG:4326");
    var url = 'https://overpass-api.de/api/interpreter?data=[out:json][timeout:25];node[amenity=post_box](' + bounds[1] + "," + bounds[0] + "," + bounds[3] + "," + bounds[2]+");out;";
    $.get(url, null, handleGetOSMboxesCallback);
    $( "#postboxes_searching" ).dialog( "open" );

}

function handleGetOSMboxesCallback(result)
{
    var changed = false;
    $( "#postboxes_searching" ).dialog( "close" );
    if (result.elements.length > 0)
    {
        for(var i = 0; i < result.elements.length; i++)
        {
            var control = new Object();
            control.id = topID++;
            control.number = topNumber++;
            //TODO Use a different number if one is already being used.
            control.angle = 45;
            control.score = 10;
            if (control.number >= 20) { control.score = 20; }
            if (control.number >= 30) { control.score = 30; }
            if (control.number >= 40) { control.score = 40; }
            if (control.number >= 50) { control.score = 50; }
            control.type = "c_regular";
            control.description = "Postbox " + result.elements[i].tags.ref;
            //control.description = "Postbox";

            control.lat = ol.proj.transform([result.elements[i].lon, result.elements[i].lat], "EPSG:4326", "EPSG:3857")[1];
            control.lon = ol.proj.transform([result.elements[i].lon, result.elements[i].lat], "EPSG:4326", "EPSG:3857")[0];

            control.wgs84lat = result.elements[i].lat;
            control.wgs84lon = result.elements[i].lon;
            var dupe = false;
            for (var j = 0; j < controls.length; j++)
            {
                if (controls[j].wgs84lat == control.wgs84lat && controls[j].wgs84lon == control.wgs84lon)
                {
                    dupe = true;
                }
            }
            if (!dupe)
            {
                controls.push(control);
                changed = true;
            }
        }
        $( "#getPostboxes" ).button("disable");
        rebuildMapControls();
        rebuildDescriptions();

        if (changed)
        {
            if (mapID != "new")
            {
                mapID = "new";
                updateUrl();
            }

            $( "#getraster" ).button("disable");
            $( "#getworldfile" ).button("disable");
            $( "#getkmz" ).button("disable");
        }
    }
    else
    {
        $( "#postboxes_error" ).dialog( "open" );
        $( "#postboxes_error_text" ).html(result.message);
    }

}
cadnant commented 1 year ago

Postbox retrieval switched from the Dracos database to OSM. Advantages: postboxes available globally, and in the UK the OSM data tends to be more up-to-date than the now aging Dracos data. Disadvantages: for the UK, OSM remains significantly less complete than Dracos. Solution is to survey any relevant postboxes missing or missing metadata from OSM!