"Upon refreshing the browser, an Angular map loses its positioning and appears blank

I have implemented a LeafLet map in my Laravel 9 system, which is functioning properly with some exceptions.

Here's how it looks like: https://i.stack.imgur.com/kcuVr.jpg

The code in the controller (CompetitionsMapController.php) is as follows:

    {
        $data = Competition::all();
        return view('map', ['data'=> $data]);
    }

This is the link in the navigation blade:

<li ng-class="{'active': (currentRoute=='competition.map')}">
     <a ui-sref="map">{{_('MAP')}}</a>
 </li>

And here is what's defined in the public/js/app.js:

    $stateProvider
    .state('map', {
        url: '/map',
        parent: 'root',

        views: {
            'content@':  {
                templateUrl: 'map'
            },       
        },
        restricted: true
    });

Everything works fine until I refresh the browser, then the map disappears.

As seen here: https://i.stack.imgur.com/OMM68.jpg

To make the map display again, I have to select another option on the navigation bar and come back to the MAP section. Even though Google Map works well after a browser refresh, this issue occurs only with the LeafLet map. Interestingly, if I include a simple JavaScript file within the application, it functions even after a refresh, suggesting that the problem lies specifically with the LeafLet map script.

Here is the LeafLet map script causing the issue:

var map = L.map('map').setView([57.36,15.26], 7);
          mapLink = '<a href="http://openstreetmap.org">OpenStreetMap</a>';
          L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
            attribution: '&copy; ' + mapLink + ' Contributors',
            maxZoom: 18,
            }).addTo(map);

So, I'm wondering what might be causing the problem and how can it be fixed?

While analyzing the error, I identified an issue in Safari:

Error: Can't find variable: L
eval code@
eval@[native code]
globalEval@http://127.0.0.1:8000/js/vendor.js:1:14516
M@http://127.0.0.1:8000/js/vendor.js:1:4621
append@http://127.0.0.1:8000/js/vendor.js:2:22024
@http://127.0.0.1:8000/js/vendor.js:2:23130
$e@http://127.0.0.1:8000/js/vendor.js:2:9577
html@http://127.0.0.1:8000/js/vendor.js:2:22802
@http://127.0.0.1:8000/js/vendor.js:22:14027
ye@http://127.0.0.1:8000/js/vendor.js:5:795
f@http://127.0.0.1:8000/js/vendor.js:4:25187
o@http://127.0.0.1:8000/js/vendor.js:4:20911
@http://127.0.0.1:8000/js/vendor.js:4:20442
c@http://127.0.0.1:8000/js/vendor.js:22:13517
@http://127.0.0.1:8000/js/vendor.js:22:13786
$broadcast@http://127.0.0.1:8000/js/vendor.js:6:4545
@http://127.0.0.1:8000/js/vendor.js:22:9167
o@http://127.0.0.1:8000/js/vendor.js:5:27411
@http://127.0.0.1:8000/js/vendor.js:5:27583
$digest@http://127.0.0.1:8000/js/vendor.js:6:1689
$apply@http://127.0.0.1:8000/js/vendor.js:6:3444
u@http://127.0.0.1:8000/js/vendor.js:5:9841
b@http://127.0.0.1:8000/js/vendor.js:5:11764
@http://127.0.0.1:8000/js/vendor.js:5:12237 – "<div ui-view=\"content\" class=\"ng-scope\" data-ng-animate=\"1\">"

Answer №1

Issue resolved! After selecting the map from the navigation, an additional blade called app.blade.php is loaded. By adding the following code snippet:

<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ed838a8e89c38382939ca38b848a8487">[email protected]</a>/dist/leaflet.js"></script>

The map now updates correctly. This simple fix resolves the problem.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error encountered when injecting Angular module

Currently, I am attempting to develop a sample Angular application with .Net in order to understand how to connect the two technologies. However, I have been encountering an error related to injector::modulerr that I cannot seem to resolve. Despite trying ...

Issue with Javascript Date and Time Validation

My application includes code that is supposed to display HTML pages based on today's date and the time of day (morning, afternoon, or evening). However, it seems like there is an issue with how the time is being checked. Currently, at 2:53pm, only the ...

What steps do I need to take to modify the text in the ionic navbar

Here is a snippet of my code... <ion-side-menu-content> <ion-nav-bar class="bar-stable"> <ion-nav-back-button> </ion-nav-back-button> <ion-nav-buttons side="left"> <button class="button b ...

Increase the size of the grid system column upon clicking on a Bootstrap icon

I am using Google Maps in a tab with Bootstrap, but the map is too small. I would like to change the Bootstrap grid system when I click on a FontAwesome icon: the first column should turn into col-md-8, and the second column should become col-md-4. Here i ...

Discovering objects on a JavaScript webpage using Selenium

Looking to automate some searches for myself, but running into an issue. Here is the website in question: Struggling to locate the search bar using the program, and unsure why. driver = webdriver.Firefox() driver.get('https://shop.orgatop.de/') ...

Node JS | Error: Unable to access the property 'first_name' of an undefined object

Just getting started with my MEAN application and I've hit a roadblock while trying to add data to the database. Can someone please help me find a solution for this? This is the main file, the entry point of the application. //Importing modules var ...

Substitute the ajax reply with the text currently displayed

I am facing an issue with the AJAX response in my HTML page. Currently, the response is being appended on top of the existing text instead of replacing it. Here is a snippet of my code: <html> <head> <h2>This is a test</h2> ...

The loading bar animation doesn't begin at a blank slate

I'm currently working on a project that utilizes Django for the backend and Bootstrap for the frontend. I have to admit, I am quite inexperienced when it comes to front-end development; JavaScript seems like magic to me. One of the key features I nee ...

Using JSON to pass a function with parameters

I have a small issue that I'm struggling to solve. My dilemma lies in sending a JSON with a function, along with parameters. Typically, it's easy to send a function in JSON like this: var jsonVariable = { var1 : 'value1', var2 : &apos ...

Is there a way to verify DNSSEC compatibility using node.js code?

Struggling with incorporating DNSSEC compliance checks into my web analytics tools using NodeJS. The standard library's dns module does not seem to accept DNSSEC record types such as rrsig, ds, nsec, and nsec3. Despite checking the documentation, thes ...

Load the Angular controller only after the service successfully fetches the Swagger API file

My current controller is dependent on a swagger-js enabled api. Unfortunately, the api remains unavailable until the swagger library acquires the swagger sepcification file. I am looking for a way to ensure that the controller only loads once the swagger A ...

There seems to be a glitch in my programming that is preventing it

Can someone please help me troubleshoot this code? I'm unable to figure out what's going wrong. The concept is to take user input, assign it to a variable, and then display a string. However, nothing appears on the screen after entering a name. ...

Issue with JavaScript Onclick Event Handler

Rephrasing Full JavaScript Code. Javascript <div id="PopUp1" style="display: none; color: #FFFFFF;"></div> <div id="Mask"></div> <script type="text/javascript"> var Content = '<p>Content!!!!!</p><input ty ...

Enhance the visual appeal of Autodesk Forge Viewer by incorporating environmental textures

Is there a way to incorporate an environmental texture into Autodesk Forge Viewer v6.0? I know in Three.js you can apply a texture to the scene's background and environment, so how would I achieve this in APS viewer? I'm not looking for a skybox ...

Having difficulty locating local grunt while trying to use grung ngtemplates

After following the setup instructions for grunt angular templates from here I proceeded with installing grunt-angular-template by running this command: npm install grunt-angular-templates --save-dev The installation was successful. My package.json fil ...

Storing a date in MySQL using Vue.js and Node.js

My current tech stack consists of nodejs and express.js for the backend, vuejs for the frontend, and mysql as the database. I am facing an issue where I cannot send a date retrieved from localStorage to my mysql database. Whenever I try to send the date, ...

An instructional HTML/JS dialogue for a linked page

On my website, there is a link that, when clicked, opens a new tab with a page that I don't control. I want to guide the user on what to do next after they are redirected to this new page ("Now please press the green button on this page"). Ideally, I ...

"VueJs and ChartJs work together to create single file components, but the computed property is only rendered in Vue Dev Tools when the component is

Currently, I am working on a single file component that utilizes Chart.Js to display a basic visualization of some hardcoded data. The Chart.Js library is being called from a CDN placed in the head section of my index.html file. The project is based on th ...

In JavaScript, a variable's value can be assigned to another variable using the variable

I have a collection of predetermined variables. I dynamically assign a value to another variable, which ends up representing the name of one of the predefined variables. This allows me to easily determine which set variable to use on a particular section o ...

How can I attach an event listener to each row in a table that is dynamically generated?

I am currently working on a table that is being populated using data from a JSON file. The number of entries in the JSON file can vary, resulting in different lengths for the table rows. Each row includes a bootstrap dropdown button with links for actions ...