The map on my leaflet only loads the initial row of tiles

I'm having trouble loading Leaflet map tiles beyond the first row in my Vue 3 component. I've experimented with various ways to declare the vertical size of the div, and have attempted to use map.invalidateSize() on mount, but so far no luck.

<script setup lang="ts">
import { onMounted } from "vue";
import * as L from "leaflet";
import "leaflet/dist/leaflet.css";

onMounted(() => {
  var map = L.map("map", { attributionControl: false }).setView([0, 0], 0);
  L.tileLayer("http://127.0.0.1:7800/{z}/{x}/{y}.jpeg", {
    maxZoom: 0,
    noWrap: true,
  }).addTo(map);
});
</script>

<template>
  <h1>Map Detail</h1>
  <div id="map"></div>
</template>

<style>
#map {
  width: 100%;
  height: 512px;
}
</style>

Answer №1

Not sure if both methods will be effective, but feel free to give them a try:

  1. Adjusting the dimensions of #map with this code snippet

    #map {
     width: 100%;
     height: calc(512px / 100%); // Specify height relative to parent element's width
    }
    
  2. Increasing maxZoom value to 18 in tile layer, and setting map zoom to 1

    import { onMounted } from "vue";
    import * as L from "leaflet";
    import "leaflet/dist/leaflet.css";
    
    onMounted(() => {
      var map = L.map("map", {
        attributionControl: false,
        zoom: 1, // Set initial zoom level to 1
      }).setView([0, 0], 0);
      L.tileLayer("http://127.0.0.1:7800/{z}/{x}/{y}.jpeg", {
        maxZoom: 18,
        noWrap: true,
      }).addTo(map);
    });
    

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

transferring data from a form with a binary image file to store in an SQL server

I am aiming to create a form where users can upload an image along with some data fields. Currently, I can only get either the image or the data fields to work separately. The following code allows me to upload an image to my SQL database as binary data. I ...

Retrieve model from stored value

Many tutorials suggest using the JSONLoader when loading a Three.js model into a scene: var loader = new THREE.JSONLoader(); var createMesh = function(geometry) { var zmesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial() ); zmesh.position. ...

Modifying the Vue page background directly from a page: a step-by-step guide

UPDATE: I recently discovered that I need to modify the body background-color, but I am unsure of how to accomplish this from within the style of this page based on the wrapper's class. The class is determined by the data values. I aim to change the ...

Discover the key technique to modify the status of a different component in React

I'm working on developing a popup window component. Here is the initial code for the popup component: The component takes in two props, activity (which can be set to true or false) and content (a view component that will be displayed inside the popu ...

Exploring the world of mongoose searching

Currently, I am setting up a search functionality for a Mongodb database using Mongoose. Here's what I have on the frontend: var searchQuery = { title: ($('#responseTitle').val()), text: ($('#responseKeywords&ap ...

Child instances in Vue.js can access data from the parent component using

Is there a way to incorporate the data option in child instances within Vue.js? <html> <body> {{ foo }} <script> var root = new Vue({ el: 'body' }); var ...

Updating the background image with Jquery is resulting in a distracting flicker effect

Here is a snippet of the script I'm using to create a slider that changes the background image for each image object in a specified time cycle. #Sliderimg - height set to 500px, $("#Sliderimg").css({ "background-image": "url(../Images/" + SliderIma ...

Vue.js is displaying the error message "Expected Object, got Array" when the length appears as undefined

I have an app where users input style codes into a field. I want to create a popup confirmation modal that displays a message with the number of style codes provided. The code I currently have is: <template> <h4>Style Number</h4> <For ...

Execute a Jquery function on every field

I need to capitalize each value of the select options that come from a SQL database. However, the code provided only works on the first field... function capitalize(str){ var text = str.text().replace(/^(.)|\s(.)/g, function($1){ return $1.toUpperCas ...

How to Implement Search Functionality in a Multiple Select Dropdown using Select2 Plugin in VueJS

I'm currently using the Select2 component from VueJS https://www.npmjs.com/package/vue-select2 import VueSelect2 from "vue-select2"; https://i.sstatic.net/MvJVw.png I am interested in adding an option to search within the displayed list it ...

Tips for maintaining interactivity after a page refresh

$(document).ready(function () { $("#2").click(function () { $("#content").load("{% url 'about' %}"); }); $("#3").click(function () { $("#content").load("{% url ...

when the AJAX request has a specific condition

When making an AJAX request, I want to pass data only if a certain condition is met. The "data: testobj" line represents a JSON object that will return {"name":"tom"} $.ajax({ type: "POST", url: 'test.asp', data: testobj, succes ...

A single pledge fulfilled in two distinct ways

My code ended up with a promise that raised some questions. Is it acceptable to resolve one condition with the token string value (resolve(token)), while resolving another condition with a promise of type Promise<string>: resolve(resultPromise); con ...

Attempting to save data to a .txt file using PHP and making an AJAX POST request

I have been facing an issue while trying to save a dynamically created string based on user interaction in my web app. It's just a simple string without anything special. I am using ajax to send this string to the server, and although it reaches the f ...

Looking for a rival on socket.io

Currently, I am working on a script utilizing socket.io with express in node.js to find an opponent. In this setup, only two players are allowed in a room. If no free rooms are available, a new one should be created automatically. The core logic of the c ...

Can you explain how the functionality of `v-b-modal` and `v-b-toggle` attributes operate and where they are monitored?

I'm trying to figure out how to add a custom attribute that triggers events, similar to the ones in this example. However, I can't seem to understand how they function. For instance: <b-button v-b-modal.modal-1>Launch demo modal</b-but ...

Ways to trigger the onclick event from different controls

I have a videojs player and a button on my html page. The videojs player supports the functionality to pause/play the video when clicked. I want to trigger this event by clicking on my button. How can I achieve this? Here is the code that I tried, but it ...

Convergence phenomenon in SVG when two distinct paths intersect

Working with individual SVG paths and in need of a mitre effect when there is a path join, which is a new concept for me. The SVG shape resembles a polygon, with each side as its own individual path. Although the sample SVG code provided does not display ...

Exploring the depths of npm in the realm of frontend development

Currently, I am delving into the realm of Javascript/Node development through self-teaching. While I grasp the concept of npm handling package installations for my Node application on the server side, I am struggling to comprehend how npm assists me with ...

Enhancing Vuejs Security: Best Practices and Tips for Secure Development

Recently, I developed a Web Application utilizing Vue.js and fetching data from the backend using 'vue-resource' in combination with Express and Postgres. Now, my main objective is to enhance its security by integrating an API Key. I am somewha ...