Trouble with Leafletjs Routing Machine collapse button loading issue

In my project, I am using django 1.10.5, booststrap 4.0, and LeafletJs 1.0.3 along with the routing machine plugin and geocoder. However, I have encountered an issue where the collapse button of the control panel for the routing machine does not appear (it's missing from the HTML code) when the map size exceeds 640 x 640px upon initial page load. https://i.sstatic.net/04CeF.png https://i.sstatic.net/8Qn7C.pngInterestingly, there are no problems when I manually resize the map using Chrome Dev Tools after the page has fully loaded, as long as the map size is set to 640x640px or smaller in the CSS.

I have a working version without Django and Bootstrap, but I specifically need it to function properly with both frameworks integrated.

CSS Code:

.map-add-size{
  position: relative;
  width: 500px;
  height:500px;
}

HTML:

{% extends 'base.html' %}
{% load static %}
{% load crispy_forms_tags %}
{% block css %}
  <link href="{% static 'routes/css/add.css' %}" rel="stylesheet">
  {{block.super}}
    <link rel="stylesheet" href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1c70797d7a7079685c2d322c322f">[email protected]</a>/dist/leaflet.css">
    <link href="{% static 'routes/css/leaflet-routing-machine.css' %}" rel="stylesheet" >
    <link href="{% static 'routes/css/Control.Geocoder.css' %}" rel="stylesheet">

{% endblock %}

{% block content %}

...

JavaScript:

window.lrmConfig = {
//    serviceUrl: 'https://api.mapbox.com/directions/v5',
//    profile: 'mapbox/driving',
};

var map = L.map('map-add').setView([51.505, -0.09], 3);

L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}{r}.png', {
    attribution: '© OpenStreetMap contributors'
}).addTo(map);

...

Answer №1

After some experimentation, I have managed to find a solution that allows the functionality to work on screen sizes larger than 640px. While I am not completely confident that this is the best way to address the issue, it does seem to be effective for the time being.

In leaflet-routing-machine.js, I made a modification by changing the value from 640 to 1200 in the following line of code. This adjustment has enabled the button to function properly on maps exceeding 640px in size.

collapsible = collapsible || (collapsible === undefined && map.getSize().x <= 1200);

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

tips for remaining in modal window post form submission

I have a form within a modal window. I am using ajax to load content in the same modal window, but the issue is that it redirects to the main page after submitting the form. How can I ensure that the modal window stays open even after the form submission? ...

The intricate Q pledge: the assurance of one promise generating a series of other promises

I am facing an http request that is expected to provide a list of tasks, but the process of generating these tasks is quite intricate. Here is a breakdown of how it operates: Retrieve all existing tasks from the database Identify and expire any outdated ...

What is the method of updating content on a webpage without altering the page itself or using hashed URLs?

I have a good understanding of how to update webpage content through AJAX and loading remote content. However, I recently came across UStream's innovative new layout. When you click on any video, not only does the content change seamlessly without rel ...

Making modifications to the database will trigger real-time updates in the web interface. How is it possible to achieve this seamlessly?

Can someone please help me understand how to automatically insert news or new events from a Facebook page as an event in a webpage? I am a programmer and currently, the data is retrieved from the database using AJAX without reloading the page. However, I ...

A dynamic url-generating app that uses specified taxonomy and a .csv file

Greetings! Today's challenge is quite complex, and I am in need of advice or guidance. To avoid getting too bogged down, I'll try to describe my problem as accurately as possible while preserving all the important details. I am currently using ...

Retrieve JSON data using AngularJS

Can someone guide me on how to make a GET request to my API endpoint and handle the JSON response in my code? Sample Controller.js Code: oknok.controller('listagemController', function ($scope, $http) { $scope.init = function () { ...

Pass function A as a prop, then trigger a different function when the child function calls A

Apologies for the uninformative title; I struggled to come up with a suitable one regarding my issue. I have a question concerning React code. My Child component receives the onValueChanged function as a prop. This function was initially passed down to th ...

Although I can reach fatimatestpro.pythonanywhere.com, I am unable to access fatimatestpro.pythonanywhere.com/help/

After setting up my first project on PythonAnywhere, I encountered a challenge while trying to access multiple views (HTML pages) from my views.py file. Here is the structure of my project: emailpro --emailpro ----url.py --emai ...

Tips for invoking an asynchronous function within an if condition?

When trying to maintain variables in the background.js of a Chrome extension, I encountered difficulties that require me to reinitialize some global variables. Here is the code snippet (view fiddle) I am using to demonstrate the issue: var temp = null; ...

Div I add to page is not being styled by CSS

I'm currently developing a Chrome extension that provides a preview of a webpage when hovering over a hyperlink to it. To achieve this, I am creating a div and filling it with different items. However, the issue I'm facing is that the CSS styles ...

Manager annotations not being properly applied with Django's create() function

Consider this scenario with a custom model, manager, and queryset: from django.db import models class BlaQuerySet(models.QuerySet): def annotate_field(self): return self.annotate(bla_field=Value('Bla') class BlaManager(models.Manage ...

When executing the app.delete function, the req.body is found to be empty

I've encountered an issue when trying to send JSON data in an $http Delete call, as the req.body returned is coming back as an empty JavaScript object. Below is my $http delete call where "scenario" is a json object: //Deletes the item from the data ...

What is the method for assigning a value to a knockout observable using jQuery?

There is a span element present on an HTML page. <span id="Amount" value="<?php echo $userProvidedAmount ; ?>"></span> Within my knockout code, I am attempting to incorporate this value into an observable using jQuery. However, despite ...

Code that changes every occurrence of a particular filtered selection of HREF values to a different value

When faced with the limitation in Firefox where links cannot be opened in a new tab if they have a HREF tag diverting to a function, it might be necessary to utilize a script to convert them to an actual HREF. Understanding the functionality of foo: func ...

Issue with Electron | JavaScript Runtime

Attempting to utilize WebTorrent with Electron and Node.js for torrent downloading. Here is the code snippet in main.js: const electron = require('electron') const { app, BrowserWindow } = electron const path = require('path') const u ...

Interactive Conversation Interface for Customer Communication

I've noticed on a lot of websites that companies often place contact forms, login or sign up forms in the lower right corner, similar to a chat box. When you hover and click on it, a full form opens up for users to submit data. I'd like to impl ...

Creating packing features specifically designed for resolution within a reusable module

I've decided to revamp my Angular application based on John Papa's style guide (well, mostly) and my main focus is on improving modularity. The stumbling block I've encountered is with route resolves. So far, I've been using a global ap ...

Error encountered in Jest mockImplementation: Incompatible types - 'string[]' cannot be assigned to 'Cat[]' type

Recently, I've been writing a unit test for my API using Jest and leveraging some boilerplate code. However, I hit a snag when an error popped up that left me scratching my head. Here is the snippet of code that's causing trouble: describe(' ...

over line up text align on the baseline with hr

I'm looking to make sure the text is positioned just above the hr tag, similar to how the logout button appears with bootstrap. This is the desired outcome: https://i.sstatic.net/gIl1b.png Here's the code I have using bootstrap : <di ...

Utilize object destructuring in React when implementing pagination functionality and incrementing the page by one

Whenever the bottom of this div is reached, I want to add one to the page. However, I keep getting an error saying "use object destructuring" and I'm not sure how to resolve it. Below is the code snippet: const vendorContainer = documen ...