0

I have a Map file that contains the initialisation and quite a few extra files of code for custom UI elements and map behaviours, is there any way to move sections of the code to other files so its not as confusing to read?

eg. move the createAddMarker() function to a separate JS file

      function initMap() {
        const myLocation = { lat: 54.236, lng: -4.5 };

        const IOMMapBorders = { north:54.555321, south: 53.843664, east: -3.9, west:-5.3}
        map = new google.maps.Map(document.getElementById("map"), {
          zoom: 11,
          center: myLocation,
          mapTypeId: 'hybrid',   
          disableDefaultUI: true,
          restriction: {
            latLngBounds: MyLocationBorders,
            strictBounds: false,
          },
          minZoom: 11,
          gestureHandling: 'greedy',
        });



        function createAddMarker() {

          const addMarkerButton = document.createElement('button');
          
          addMarkerButton.textContent = 'Add Marker *offline*';
          addMarkerButton.title = 'Click to add a location *offline*';
          addMarkerButton.type = 'button';
      
          addMarkerButton.addEventListener('click', () => {
            if (setMarker == true){
              addMarker(map.getCenter());
              setTimeout(() => { alert("Drag the marker to your location and click \"set marker\" to add inforation to the marker"); }, 100);
              CreateSetMap.style.visibility = 'visible';
              setMarker = false;
            }
            else
            {
              alert("Please set the marker before adding another marker to the map");
            }
          });
      
          return addMarkerButton
        }

it doesn't work just adding another js file and referencing it in the HTML but im new to js and not sure what other options there might be

0 Answers0