Why does clicking a Leaflet marker sometimes open the wrong marker?

In this https://net-control.us/map.php?NetID=10684 Leaflet map several markers (05, 13, 21) open the wrong marker when clicked. As a demonstration display this map, center the markers, zoom in once or twice, then click one of those markers.

All the markers in question open correctly if you increase the distance between them by zooming in further. I’ve seen this before in other Leaflet maps but have never been able to figure out why. Please only serious answers or suggestions.

If you plan to lecture me about showing code or the color of the marker or some other non-answer save it! If you want to tell me to search for other answers, save it, I’ve already done that too. I’d really like a serious proposal for a solution. If you have no idea, then don’t answer.

I’ve test in Safari, Chrome, Firefox, Brave and a few others the issues is prevalent in all of them. While there may be some other issues with this map, none show up about the problem in console.log.
My only expectation is an explanation why this is happening because I’m pretty sure there is no solution based on coding but if I’m wrong let me know.

Pass array from html to javascript

I’m trying to create a carousel so I can click through each element in csv file:

In a routes/index.js file I’m reading a csv file with film data in an array, and then loading this into the index.ejs file when its opened:

//get request - open index.ejs page
router.get(['/', '/index', '/discover', '/home'], function (req, res) {

  //read film data into array for frontend
  const films = [];
  fs.createReadStream('film_data.csv')
    .pipe(csvParser())
    .on('data', (row) => {
      films.push(row);
    })
   .on('end', () => {
      res.render('index', { title: 'Express', session: { email:req.cookies.sessionEmail }, films: films });
    })
});

In the index.ejs file I am trying to create a carousel so I click next or previous and show the next film title in the array:

<!-- Film carousel -->
<div class="carousel" id="film-carousel" data='<%- films %>'>
  <button id="prev-btn">Previous</button>
  <div id="current-film">
    <!-- films displayed here from scripts/index.js -->
  </div>
  <button id="next-btn">Next</button>
</div>

<!-- END film carousel -->

The functionality for this is handled in the scripts/index.js file, however I don’t know how to put the array from the .ejs file to the .js file so I can implement this, does anyone know how to do this?

This is my scripts/index.js file:

window.onload = function () {
  const currentFilmElement = document.getElementById('current-film');
  const prevButton         = document.getElementById('prev-btn');
  const nextButton         = document.getElementById('next-btn');

  var films        = document.getElementById('film-carousel').getAttribute('data');
  var currentIndex = 0;

  // Initial update
  updateFilm();

  // Function to update the displayed film
  function updateFilm() {
    currentFilmElement.innerHTML = `<strong>Title:</strong> ${films[currentIndex].primaryTitle} <br><p></p>`;
  }

  // Event listener for the previous button
  prevButton.addEventListener('click', function () {
    currentIndex = (currentIndex - 1);
    if(currentIndex < 0) {
      currentIndex = 0;
    }
    updateFilm();
  });

  // Event listener for the next button
  nextButton.addEventListener('click', function () {
    currentIndex = (currentIndex + 1);
    updateFilm();
  });
};

Currently I am trying to pass it as a data attribute which i am accessing in the scipts/index.js file, but when I try to use the array here I get errors, and rather than seeing film data it is in the format [object object], [object object] etc.
Can anyone advise?

Angular ReactiveForm does not change its value after it is prefilled

I use a reactiveForm for an edit mode. I use patchValue to prefill the data that I want to edit. The UI works fine but the value of the form never changes.

I check what happens when I change a value :

public ngOnInit(): void {
        this.form.valueChanges.subscribe(value => {
            this.changeDetectorRef.detectChanges();
            console.log('value has changed', value); // Return updated values of the form
            console.log(this.form.value); // return initial value of the form
        });
}

I don’t understand why the form value doesn’t change. And What is more disturbing : if I refresh the page after the form as loaded, I don’t have any issue.

Any Idea on where I should investigate?

Can’t link and display images in ParcelJS

I have a problem with my project in react with parcel. The problem is that the images are not shown. Does anyone know why and how to solve the problem?The images folder is a subfolder of the folder where the react components are also loaded correctly, so it should work. For the configuration I don’t have the configuration file but use the json package.
The fonts seem to work instead

I put the image in the same directory but didn’t work

React: this.forceUpdate and passing state through react-router-dom Link component

I solved my own problem already but I have no clue as to what’s happening and why it works.

I have a Link component that Link to the same page it’s currently on, but for a different product. So the same component but displaying a different product.
<Link to={directUrl} onClick={() => this.forceUpdate} state={{ urlPicture: picture }}> (Do note is in a sub-component, not the main component it routes to itself.)

Because it routes to the same page, Link doesn’t automatically refresh the page. To solve this I added onClick={() => this.forceUpdate}, but now my state didn’t pass properly. I checked this with the following lines of code in the other component.

location = useLocation()
const [ firstImage, setFirstImage ] = useState(location.state?.urlPicture || null)
console.log(`here is ${mainPicture}`) //mainPicture is just a string

However, when I replace onClick={() => this.forceUpdate} with onClick={() => window.location.reload()}, then my state does pass properly through the Link.

I do know that there is a difference between the 2 and that this.forceUpdate is the lighter of the 2, but to my knowledge it should refresh the component and update it’s state. I don’t see why it’s not sufficient and honestly I have no clue why it’s working the way it does.

Thanks in advance.

is this code standard ? whenever we click the accordion btn the other ones will be closed

  const accordions = document.getElementsByClassName('accordion');
        const menus = document.getElementsByClassName('select-menu');

        for (let i = 0; i < accordions.length; i++) {
            accordions[i].addEventListener('click', function () {
                // Toggle the active class for the clicked accordion
                this.classList.toggle('active');

                // Close other accordions
                for (let j = 0; j < accordions.length; j++) {
                    if (j !== i) {
                        accordions[j].classList.remove('active');
                    }
                }

                // Close other menu items
                for (let j = 0; j < menus.length; j++) {
                    if (j !== i) {
                        menus[j].classList.toggle('active')
                    }
                }

                // Toggle the display of the corresponding menu
                if (this.classList.contains('active')) {
                    menus[i].style.display = 'block';
                } else {
                    menus[i].classList.toggle('active')
                }
            });
        }

is it good or could be better and shorter ??
I used another for loop inside another one the code works but i think it is not optimized can someone please help with this thanks a lot.

how to find a rectangles corner when scaling by new corners X and Y?

i have a JS app that render a rectangle with coordinate of (1,5), (3,3) (5,5),(7,3) as clockwise start from topleft .
if i drag topright corner i will get new x,y that will be 4,2 so my new rect coodiates will be
[1,5 ], [4,2,] [6,4][3,7]

tell me the logic to calculate this even drag is in any corner the. relate point need to be recalculated with keeping the shape as rectangle
attaching a image to better understand in the image dotted line is new line after dragging TR BR and TL need to be calculated

image

JS code to find new coordinate from a new corner and old bbox data

How to support indefinite integrals on mathquill.js?

I’m building a web app based on mathquill and I’d like to support indefinite integrals. However, when I type int, the output I see is this:

enter image description here

Ideally, the two gray blank spaces shouldn’t appear. I tried editing the html render of integrals on mathquill source code, which is the following:

LatexCmds['int'] =
LatexCmds.integral = P(SummationNotation, function(_, super_) {
  _.init = function() {
    var htmlTemplate =
      '<span class="mq-int mq-non-leaf">'
    +   '<big>&int;</big>'
    +   '<span class="mq-supsub mq-non-leaf">'
    +     '<span class="mq-sup"><span class="mq-sup-inner">&1</span></span>'
    +     '<span class="mq-sub">&0</span>'
    +     '<span style="display:inline-block;width:0">&#8203</span>'
    +   '</span>'
    + '</span>'
    ;
    Symbol.prototype.init.call(this, '\int ', htmlTemplate);
  };
  // FIXME: refactor rather than overriding
  _.createLeftOf = MathCommand.p.createLeftOf;
});

And transformed it into this one:

LatexCmds['int'] =
LatexCmds.integral = P(SummationNotation, function(_, super_) {
  _.init = function() {
    var htmlTemplate =
      '<span class="mq-int mq-non-leaf">'
    +   '<big>&int;</big>'
    + '</span>'
    ;
    Symbol.prototype.init.call(this, '\int ', htmlTemplate);
  };
  // FIXME: refactor rather than overriding
  _.createLeftOf = MathCommand.p.createLeftOf;
});

Which technically should get rid of those gray blanks. However, the problem persists, and I don’t know how to fix it.

React.js Routing Issue (react-router-dom)

I deployed my static website. But, when I refresh the page it shows nothing but a blank page except the homepage. I have already added the redirect/rewrite rule and the browser returns 200 code. What could cause this error?

github: GitHub – kobrak1/bunch-of-apps
website: https://bunch-of-apps.onrender.com/

I have tried to add Redirect/Rewrite rules on render.com as Source: /* and Destination: “/index.html”.
Browser can not find the index.html file when the user refreshes the page except the homepage.

how to access caption from Semantic Search using Javascript?

I’m trying to build a web app that can perform a semantic search using natural language and return the answer as a result. Using response.data.results, I am able to see the caption text in the console under semanticSearch->captions->text.

console image

However I can’t figure out what is the syntax to access that info. I tried response.data.results.semanticSearch.captions[0].text but that is giving me an error “TypeError: Cannot read properties of undefined (reading ‘captions’)”

Any advice would be much appreciated.

Thanks!
Kenneth

Not getting all the data in mongoose when I send get

When I send retrive all tour data only the data which I imported via dev data(script used to load data) is comming back but the data which I created is not coming

Below is the tour which is in dev data
enter image description here

When I send this ID I am getting response for this
enter image description here
But below is the tour I created
enter image description here
But when I send the get this data I am not getting response,
enter image description here
I am facing this issue, and when I retrive all the tours also this tour which I created is not coming

Can anybody check why mongoose is not sending the data which I sent

My code link-https://github.com/chandangowda33/natours.git

I tried to decode but not getting

Fetch has been blocked by CORS policy in JavaScript (Google Cloud Platform)

I have encountered a problem regarding a http request to Google Platform API. This is the example https: https://maps.googleapis.com/maps/api/directions/json?key={my api key}&origin=And%C4%9Bl&destination=Milovice,benatecka-vrutice&mode=transit&transit_mode=train|tram|subway|bus&transit_routing_preference=less_walking

While this https works perfectly in any browser and returns a JSON format, when I try to fetch it in my javascript appliacation it is always blocked by CORS policy.

console response

I thought it had something to do with my Google Studio Project setup because when I try to fetch from some other APIs in javascript it works just fine. I tried to read some articles about this issue but could not find anything useful.

I will be grateful for any help!
Daniel

FusionCharts Sankey Diagram in React Native Expo

enter image description here

Anyone know how to render fusionChart sankey diagram in React Native Expo app.

I implemented this but it renders text showing ” loading chart please wait “

Here is my code:

import React from 'react';
import FusionCharts from 'react-native-fusioncharts';

const SankeyChart = () => {

  const sankeyChartData = {
    nodes: [
      {label: 'Node A'},
      {label: 'Node B'},
      {label: 'Node C'},  
    ],
    links: [
      {source: 'Node A', target: 'Node B', value: 20},
      {source: 'Node B', target: 'Node C', value: 15},
    ],
  };


  const chartConfig = {
    type: 'sankey',
    width: 300,
    height: 300,
    dataFormat: 'json',
    dataSource: {
      chart: {
        caption: 'Sankey Diagram',
        theme: 'fusion',
      },
      link: sankeyChartData.links,
      node: sankeyChartData.nodes,
    },
  };

  return <FusionCharts chartConfig={chartConfig} />;
};

export default SankeyChart;

Uncaught TypeError TypeError: Cannot read properties of undefined (reading ‘cache’)

So i made a dashboard for a discord bot and was trying to get the guilds, however it gave the error named in the title, the full error is this:

Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'cache')
    at getManageableGuilds (e:The House Party 2Panzer Botdashboardmiddleware.js:34:35)
    at module.exports.updateGuilds (e:The House Party 2Panzer Botdashboardmiddleware.js:9:33)
    at processTicksAndRejections (internal/process/task_queues:95:5)

I am trying to use client.guilds.cache.get(id) to get the guilds but this does not seem to work, i also tried using fetch but that did not work either. I already tried fixing it with ChatGPT without any result. I am pretty sure I defined the client object correctly:

const client = new Discord.Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildVoiceStates
    ]
});
client.login(TOKEN);
module.exports = client;

This is what my middleware.js looks like, the updateGuilds part works fine but the getManageableGuilds function is where I am gettings errors, const guild = await client.guilds.cache.get(id):

const authClient = require('./auth-client')
const client = require('../main')

module.exports.updateGuilds = async (req, res, next) => {
    try {
        const key = res.cookies.get('key')
        if(key) {
            const authGuilds = await authClient.getGuilds(key)
            res.locals.guilds = getManageableGuilds(authGuilds)
        } 
    } finally {
        next()
    }
}


module.exports.updateUser = async (req, res, next) => {
    try {
        const key = res.cookies.get('key')
        if(key) res.locals.user = await authClient.getUser(key)
    } finally {
        next()
    }
}

module.exports.validateUser = async (req, res, next) => {
    res.locals.user ? next() : res.render('errors/401')
}

async function getManageableGuilds(authGuilds) {
    const guilds = [];
    for(const id of authGuilds.keys()){
        const isManager = authGuilds
            .get(id).permissions
            .includes('MANAGE_GUILD');
        const guild = await client.guilds.cache.get(id)
        if (!guild || !isManager) continue;

        guilds.push(guild);
    }
    return guilds;
}