0

Wrote a main.js file which contained:

var h3 = require("h3-js")

bundled it into a file h3bundled.js using browserify. placed that file in my project

In my html, I load two files, starting with h3bundled

<script src="h3bundled.js"></script>
<script src="mapScript.js"></script>

My intention is to reference functions from h3bundled in mapScript.

However when I get to the first line referencing these functions using the h3 var, execution just stops without any error.

Here is an example

    // Function to geocode the address using OpenStreetMap
    function geocodeAddress(address) {
        fetch('https://nominatim.openstreetmap.org/search?format=json&q=' + encodeURIComponent(address))
            .then(function(response) {
                return response.json();
            })
            .then(function(data) {
                if (data.length > 0) {
                    var lat = parseFloat(data[0].lat);
                    var lon = parseFloat(data[0].lon);
                    

                    var resolution = 8; // H3 resolution
                    var h3Index = h3.geoToH3(lat, lon, resolution);
                    console.log(h3Index)
                    showMap(lat, lon);
                    drawHexagons(lat, lon);
                    updateDataTable(address, lat, lon, resolution, h3Index);
                } else {
                    alert('Address not found.');
                }
            })
            .catch(function(error) {
                console.log('Error:', error);
            });
    };

I have tried loading the h3-js package via unpkg to the same effect. I am running the project on a localhost server, no obvious cross origin blocking.

For what it's worth I am very early in my javascript journey.

Nick
  • 58
  • 6

0 Answers0