Can someone guide me on how to personalize a marker icon in Quasar while utilizing Vue2-Leaflet for mapping?

I'm facing an issue with displaying an icon marker image in my Vue2-Leaflet and Quasar project. Instead of the desired image, I am seeing a broken image icon and encountering a 404 error in the console. Despite researching various solutions, I was able to resolve the problem using Leaflet.js and Quasar, but not with vue2-Leaflet and Quasar. Here is a snippet of my map code:

  <l-map style="height: 1000px" :zoom="zoom" :center="center">
  <l-tile-layer :url="url" :attribution="attribution"></l-tile-layer>
  <l-geo-json :geojson="geojson"></l-geo-json>
  <l-marker v-for="marker in markers" :key="marker.id" :visible="marker.visible" :draggable="marker.draggable" :lat-lng="marker.position"  :icon = "marker.icon"></l-marker>
  </l-map> 

And this is how I've structured my JavaScript:

markers: [
                { id: "m1", position : {lat:34.586956, lng:-82.238054}, tooltip: "tooltip for marker3", draggable: true, visible: true, icon: this.defaultIcon },
                { id: "m2", position : {lat:34.409676, lng:-82.246337}, tooltip: "tooltip for marker4", draggable: true, visible: true, icon: this.defaultIcon }
            ],

 defaultIcon: L.icon({
        iconUrl: 'http://leafletjs.com/examples/custom-icons/leaf-green.png',
        shadowUrl: 'http://leafletjs.com/examples/custom-icons/leaf-shadow.png',
        iconSize:     [38, 95],
        shadowSize:   [50, 64],
        iconAnchor:   [22, 94],
        shadowAnchor: [4, 62],
        popupAnchor:  [-3, -76]
      }),

I attempted to follow a similar example provided at https://jsfiddle.net/Boumi/z3bmc1ex/1/, but still encountered issues with broken images and the following errors:

  GET https://static.neshan.org/sdk/leaflet/1.4.0marker-icon.png 404
  GET https://static.neshan.org/sdk/leaflet/1.4.0marker-shadow.png 404

I also experimented with the following approach:

import icon from 'leaflet/dist/images/marker-icon.png';
import iconShadow from 'leaflet/dist/images/marker-shadow.png';

    let DefaultIcon = L.icon({
    iconUrl: icon,
    shadowUrl: iconShadow,
    iconSize: [24,36],
    iconAnchor: [12,36]
});

L.Marker.prototype.options.icon = DefaultIcon;

This method resolved the issue when using Leaflet.js and Quasar, but not in vue2-leaflet.js and Quasar. Any suggestions or guidance would be greatly appreciated. Thank you.

Answer №1

If you are experiencing a 404 error, it means that the image () does not exist on the server.

The HTTP 404 Not Found response status code indicates that the server is unable to locate the requested resource. Mozilla Docs

Make sure that you are using the correct URL for marker/shadow images. These URLs work correctly:

iconUrl: 'http://leafletjs.com/examples/custom-icons/leaf-green.png'
shadowUrl: 'http://leafletjs.com/examples/custom-icons/leaf-shadow.png'

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

Is it possible for Express in Node.js to handle multiple static folders at once?

Currently, I am working on a project that involves a user uploaded collection of styles, scripts, and images as well as my app's own collection of these resources. They are stored in separate directories on my server. I am wondering if there is a way ...

Challenges with Dual Y-Axis in a Horizontal Stacked Bar Graph

My charts are presenting me with several issues and questions: Is there a way to avoid the right y-axis tick values from either being partially erased or overlapping with the chart? When I set yValuesTripId as the domain for both the left and right y ...

Calculating the v-model name dynamically within a v-for loop

I am currently working on a form that is dynamically generated with a v-for loop. Important Note: I am utilizing "@" to escape blade in this process. My Vue instance includes the following data: data: { form: { inputs: [{icon: "", name="", ...

Help kids find solutions

Here is the HTML code I am working with: <div class = "touch" onclick="do(this)"> <span>text01</span> <span>text02</span> <span>text03</span> <span>text04</span> <div class = "findMe">a ...

The graph visualization fails to update properly even after attempting to redraw it

A new feature has been added to the website that allows users to zoom into specific areas of graphs created using Flot objects. An array containing all the Flot objects on the screen has been implemented, and the selection plugin is being used for this pur ...

I keep seeing this strange [object HTMLSpanElement] appearing on my HTML page

Thanks for the help, the issue has been resolved and I appreciate your valuable time! ...

I'm having trouble with populating data in Mongoose. Can anyone provide guidance on

I am currently working on a simple CRUD example for a larger open-source project. I'm trying to populate user data, but despite consulting documentation and forums, I haven't been able to resolve the issue that's causing trouble. The error ...

I am encountering a JSON parsing error while trying to implement jQuery autocomplete, despite using a local array

I'm attempting to implement the jQuery autocomplete feature on a WordPress website. My ultimate goal is to link the input field to an ajax request that will retrieve data from a database. However, I've encountered an unusual error when trying to ...

Is a non-traditional fading effect possible with scrolling?

I have implemented a code snippet to adjust the opacity of an element based on scrolling: $(window).scroll(function () { this = myfadingdiv var height = $(this).height(); var offset = $(this).offset().top; var opacity = (height - homeTop + ...

Firestore javascript query is returning empty results

Yesterday everything was working smoothly, but this morning it suddenly stopped moving forward. The Firestore query is not returning anything - no errors, no response. Surprisingly, the console displays the phone perfectly fine. Additionally, the phone n ...

Steps for Deactivating Past Dates on JQuery Datepicker1. Open your

I've been working on a custom JQuery Calendar for selecting appointments, with the requirement to disable dates prior to the current date and highlight available dates in an orange color (#f48024). Unfortunately, my attempt using minDate hasn't b ...

What is a memory-saving method to clear an object in JavaScript?

I am looking for a way to use the same object repeatedly in JavaScript by emptying it after its purpose is served, without creating a new object each time. In arrays, I usually do arr.length=0 to clear an array instead of assigning it to a new memory locat ...

What is the best way to display an alert when the button is clicked repeatedly?

Is it possible to keep displaying the alert every time we click the button, rather than just once after clicking it? I currently have an alert set to trigger when a button is clicked, but it disappears after 3 seconds. How can I make it show up again with ...

Tips for displaying personalized error messages from your REST API in a JavaScript client

I'm utilizing a Java REST API that has been generated using swagger. If the client is unauthorized, I am sending custom error messages in response. public Response collaborationCollabIdDelete(Integer collabId, SecurityContext securityContext, Str ...

In JavaScript, provide a boolean response to a callback function from a separate function

Working with the jQuery validate plugin involves utilizing a submitHandler callback function. This function determines whether the form submission should proceed based on its return value - false will prevent submission, while true will allow it to go thro ...

Using Jquery to Modify Information within HTML Table Cells

My dilemma involves an HTML table where each cell will have two data attributes. My goal is to create a button that toggles the value displayed in the table between these two attributes. <table class="table1"> <tbody> <tr> <td data-or ...

Bootstrap4 does not support the <button> element

How can I achieve a 'collapse icon' floated to the left followed by Copyright © using Bootstrap 4? I've looked at similar questions on this topic, but none seem to provide a direct answer. Other questions contain different code with ob ...

Ensure that the first option in the Woocommerce 2 Variable Product Dropdown List always displays all available choices

I am currently working on a variable WooCommerce product that includes 2 drop-down select fields. The first field is for selecting the Type of Product (framed or unframed artwork) and the second field is for choosing the Size of Artwork. With the help of ...

Tips for updating the value of an input text field in one HTML table according to a certain value entered in a different input text field located in another HTML table

I am working with an HTML table that consists of one row. Within this row, there are two TDs which each hold their own tables (each containing 10 rows with 10 input fields). My goal is to update the value of another corresponding text field based on change ...

Navigate to the Bootstrap Panel body when the relevant link is clicked

I am facing an issue with a long list of panels that are tedious to scroll through. To make navigation easier, I am attempting to create a shortcut link at the top of the page. Below is the code for the shortcut: <a data-toggle="collapse" data-parent ...