LukePrior / nbn-upgrade-map

Interactive map showing premises eligible for the NBN FTTP upgrade program.
https://lukeprior.github.io/nbn-upgrade-map/
MIT License
101 stars 11 forks source link

Use geographic bounds on wesbite #164

Open LukePrior opened 12 months ago

LukePrior commented 12 months ago

A very hacky version, need to find a better way to deal with this many markers

// download suburb list
var results = [];
$.ajax({
    url: "https://raw.githubusercontent.com/LukePrior/nbn-upgrade-map/main/results/results.json",
    async: false,
    dataType: 'json',
    success: function (data) {
        results = data["suburbs"];
    }
});

var bounds = {}
$.ajax({
    url: "https://raw.githubusercontent.com/LukePrior/nbn-upgrade-map/main/results/suburb-extents.json",
    async: false,
    dataType: 'json',
    success: function (data) {
        bounds = data;
    }
});

current_sububrs = [];

// on map pan
map.on("moveend", function() {
    if (map.getZoom() > 13) {
        for (state in bounds) {
            for (suburb in bounds[state]) {
                // check if bounds are in view
                mapbounds = map.getBounds();
                if (mapbounds.contains(bounds[state][suburb])) {
                    for (result in results) {
                        if (results[result]["internal"] == suburb && results[result]["state"] == state) {
                            if (current_sububrs.includes((state + suburb).toLowerCase())) {
                                continue;
                            }
                            current_sububrs.push((state + suburb).toLowerCase());
                            loadSuburb("https://raw.githubusercontent.com/LukePrior/nbn-upgrade-map/main/results/" + state + "/" + results[result]["file"] + ".geojson")
                        }
                    }
                }
            }
        }
    }
});
lyricnz commented 11 months ago

Recent PR adds this to combined results. I don't know which is better - doing it client-side (like this) or in pre-generated JSON like https://github.com/LukePrior/nbn-upgrade-map/pull/178

LukePrior commented 11 months ago

Yeah I'm mainly considering how it'll effect initial load time because the site needs to fetch results before dropdown can be populated

lyricnz commented 11 months ago

CPU time vs download time. Depends on your capacity for each.