nbn-upgrade-map icon indicating copy to clipboard operation
nbn-upgrade-map copied to clipboard

Use geographic bounds on wesbite

Open LukePrior opened this issue 2 years ago • 3 comments

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")
                        }
                    }
                }
            }
        }
    }
});

LukePrior avatar Jul 08 '23 03:07 LukePrior

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

lyricnz avatar Jul 11 '23 02:07 lyricnz

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

LukePrior avatar Jul 11 '23 05:07 LukePrior

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

lyricnz avatar Jul 11 '23 05:07 lyricnz