Show Result routing path with Leaflet

I get route between 2 Point :

{
  "routes": [
    {
      "overview_polyline": {
        "points": "m{f~D}_ygHp@wAJs@Is@eAsBGk@Hg@"
      },
      "legs": [
        {
          "summary": "میدان انقلاب - انقلاب",
          "distance": {
            "value": 209.0,
            "text": "۲۲۵ متر"
          },
          "duration": {
            "value": 13.0,
            "text": "کمتر از ۱ دقیقه"
          },
          "steps": [
            {
              "name": "بزرگراه اهواز-حمیدیه",
              "instruction": "در جهت شرق در بزرگراه اهواز-حمیدیه قرار بگیرید",
              "bearing_after": 119,
              "type": "depart",
              "distance": {
                "value": 25.0,
                "text": "۲۵ متر"
              },
              "duration": {
                "value": 1.0,
                "text": "کمتر از ۱ دقیقه"
              },
              "polyline": "m{f~D}_ygHTm@",
              "start_location": [
                48.629912,
                31.333827
              ]
            },
            {
              "name": "انقلاب",
              "instruction": "در میدان انقلاب، از خروجی دوم، خارج شوید",
              "rotaryName": "میدان انقلاب",
              "bearing_after": 126,
              "type": "rotary",
              "modifier": "straight",
              "exit": 2,
              "distance": {
                "value": 101.0,
                "text": "۱۲۵ متر"
              },
              "duration": {
                "value": 5.0,
                "text": "کمتر از ۱ دقیقه"
              },
              "polyline": "wzf~DkaygHNWJQJs@Is@Yk@",
              "start_location": [
                48.630143,
                31.333717
              ]
            },
            {
              "name": "",
              "instruction": "به مسیر خود ادامه دهید",
              "bearing_after": 53,
              "type": "exit rotary",
              "modifier": "straight",
              "exit": 2,
              "distance": {
                "value": 83.0,
                "text": "۱۰۰ متر"
              },
              "duration": {
                "value": 8.0,
                "text": "کمتر از ۱ دقیقه"
              },
              "polyline": "szf~DigygHk@gAGk@Hg@",
              "start_location": [
                48.631088,
                31.333703
              ]
            },
            {
              "name": "انقلاب",
              "instruction": "در مقصد قرار دارید",
              "bearing_after": 0,
              "type": "arrive",
              "distance": {
                "value": 0.0,
                "text": ""
              },
              "duration": {
                "value": 0.0,
                "text": ""
              },
              "polyline": "}{f~DelygH",
              "start_location": [
                48.631869,
                31.333913
              ]
            }
          ]
        }
      ]
    }
  ]
}

In Steps we have 4 points:

[31.333827,48.629912 ],
[31.333717,48.630143 ],
[31.333703,48.631088],
[31.333913,48.631869 ]

When I use polyline my output is like below picture. But real Path is another thing.

enter image description here

I use Leaflet and get my .png file for map from another server and get Json String from another server.
How can Manage this?

Get Javascript maxLength in input

I have a problem with downloading and displaying the value, when set to “rigidly” maxLenght – everything works fine, but when I want the script to download the value myself, I have a problem.

The script is supposed to get the value maxlenght = “” from each and after typing by the user it will print out how many characters are left.



var maxLen = document.getElementsByClassName("handlerWorld").maxLength;

function countChar(jqObj) {
    var len = jqObj.val().length;
    var diff = maxLen - len;

    if (len > maxLen) {
        len = maxLen;
        diff = 0;
    }
    jqObj.val(jqObj.val().substr(0, len)).prev('label').find('span.chars-twenty').text(diff);
}

$(document).ready(function () {
    $("[class*='handlerWorld']").keyup(function () {
        countChar($(this));
    }).each(function () {
        countChar($(this));
    });
});

My HTML:

<div class="form-group">
          <label for="nameIput">Nazwa firmy <span>Remaining: <span class="chars-twenty"></span></label>
          <input type="text" id="name" maxlength="140" name="name" class="form-control handlerWorld">
        </div>
        <div class="form-group">
          <label for="urlInput">URL <span>Remaining: <span class="chars-twenty"></span></label>
          <input type="text" id="url" name="url" maxlength="100" class="form-control handlerWorld">
          
        </div>

HTML input dynamic filtering from PHP array variable?

I have a score entry page on a PHP-based website. It uses a DB query to retrieve the player’s Name & DB ID into a PHP array variable, then loops around the returned data to create an HTML <select> dropdown list.

This has now become too long… especially when entering on a mobile device (on iOS its even worse with that scroll wheel implementation they use – I dont even know what it looks like on Android!)

So I have a PHP array with the Name & ID fields in it.

I would like to convert this to filter a dynamic dropdown list as characters are typed in by the user.

I am novice at Javascript and it’s nuances, though understand the principles of the language. The DOM model and other things I am also not very familiar with. I expect to use an onChange() function on the <input> textbox(?).

But how do I either tie that back to my existing PHP array variable? Or copy this variable “across” to the JS function?

I have changed the underlying DB to a NoSQL version (MongoDB). The bulk of tutorials, blogs, etc, for “AJAX Live Search” or equivalent seem to be centred around MySQL (which I previously used…)

How do I use in-memory cache in Remix.run dev mode?

I need to fetch data from an API that is pretty slow and seldom changes, so I thought I’d use an in-memory cache. I first tried a very simple approach by just saving it to a variable outside the scope of the loader function in my route:

let cache;

export const loader = async () => {
  if (!cache) {
    // we always end up here
    cache = await (await fetch("...)).json()
  }
}

but that didn’t work. I then tried a proper caching library (lru-cache), but that cache was also always empty. I then realized that the entired file got reloaded on each request which I guess is a dev mode thing, so I tried moving the creation of the cache to a separate file cache.server.ts and importing it from there.

import LRU from "lru-cache";
console.log("Creating cache"); // this is logged on each request
const cache = new LRU({ max: 200 });
export default cache;

But that file also seems to be reloaded on each request.

If I build a production version and run that everything works great, but it would be nice to have some way of getting it to work in dev mode as well.

How do i perform an operation on a child element and return the parent?

I have an array like this

const array = [
  { 
    name: 'Parent Brand 1', 
    childBrands: [
      { name: 'Child Brand 1', status: 'active' },
      { name: 'Child Brand 2', status: 'discontinued' },
    ] 
  }
, { 
    name: 'Parent Brand 2',
    childBrands: [
      { name: 'Child Brand 1', status: 'discontinued' },
      { name: 'Child Brand 2', status: 'active' },
    ] 
  }
];

How do I make it so that it filters the child brands by status and returns the parent object? After filtering by ‘active’ status it should return something like this,

const array = [
  { 
    name: 'Parent Brand 1', 
    childBrands: [
      { name: 'Child Brand 1', status: 'active' },
    ] 
  }
, { 
    name: 'Parent Brand 2',
    childBrands: [
      { name: 'Child Brand 2', status: 'active' },
    ] 
  }
];

Using a flatMap and filter only returns the child elements when i need the parent object including the child element

{ "name": "Child Brand 1","status": "active" }

{ "name": "Child Brand 2","status": "active" }

How can I improve code quality in javascript image player? [closed]

I’ve made some image player by javascript.
It uses global variables to draw images.
It is hard to understand my code.
Because It is not intuition.

If there are many images, This code maybe cannot works.
How can I improve code quality?
I’m newbie of javascript.
please help me.

var g_image_list = [create_image("http://placekitten.com/148/148"),
create_image("http://placekitten.com/248/248"),
create_image("https://images.squarespace-cdn.com/content/v1/543593e4e4b0bf8b316933e3/1504286897079-V3OLCF6NQ1P06SZSE2G1/image-asset.png")];

var g_index = 0;


function onFrameChange()
{
  var sliderBar = document.getElementById('image_slider');
  var output = document.getElementById('index');
  output.innerText = parseInt(sliderBar.value);
  
  g_index = parseInt(sliderBar.value);
  updateCanvas();
}

function create_image(url){
    var img = new Image();
        img.src = url;
    return img;
}

function updateCanvas(){
    console.log("image loaded");
        drawImage(g_image_list[g_index]);

}

function drawImage(img){
    var ctx = document.querySelector("canvas").getContext("2d");
    ctx.drawImage(img, 0, 0, 500, 500);
}
canvas{
    border: 1px solid black;
}
<canvas width="500" height="500"></canvas>

<div id="index">0</div>

<input type="range" min="0" max="2" class="slider" value="0" id="image_slider" oninput="javascript:onFrameChange();">

Cypress – Use Chance JS to generate Data and store that Data for use later

Essentially what I want to do is generate a name using ChanceJS for a test case within cypress, but in a separate file / test case I want to be able to recall that name that I generated earlier so I can select it / check it exists.

I have cut down these code snippets a fair bit so they wont make total sense.

I have tried having my own file with a constant in it called constants.js

    require('chance')
 export const constants = {
    ITEM: chance.word()
  }

and then having something like this in a test file

import { constants } from '../constants';
//Add Item
it('Add a Item', function(){
cy.pass_credentials()
cy.get('.dx-datagrid-toolbar-button > .dx-button-content > .dx-icon').click({force: true})
cy.get('[id$=_Name]').type(constants.ITEM) // using my random name for the item name
}

and then later I try to use it again to select the item in a separate file

import { constants } from '../constants';
it('Add Data', function(){
cy.pass_credentials()
cy.get('[id$=_TaskId]').type(constants.ITEM)    //typing my random name in so I can select it as its now part of a drop making up this new piece of data  
cy.contains(constants.ITEM).type('{enter}')     //trying to press enter so I select my item
}

But the issue I am having is that it is generating a new random name which means im trying to select something that is not there. I’m not sure if every time I import it on a new file to be used that’s what’s causing it to re-generate?

I guess I could do with some pointers or a better solution to my issue.

Perdi mi codigo en un archivo .js de extjs [closed]

tengo el siguiente problema: ayer estaba trabajando en el proyecto de extjs como de costumbre y hoy al abrirlo veo un error que no estaba ayer, el problema es que uno de los archivos .js se quedo vacio…cdo lo abro no muestra nada ..se ve asi: “NULL NULL NULL NULL ….” ..sin embargo tiene 154 kb de tamanno ….no se que pudo haber pasado, por favor necesito su ayuda.
Gracias!!

JS How to compare an array of objects and get the lowest value together with object data

I have a product in multiple variations

{
  product: {
    name: 'TShirt',
    brand: 'Some brand",
    variations: [
       {
         color: 'red',
         sku: '1234',
         price: 129,
         id: 1
       },
       {
         color: 'black',
         sku: '123442',
         price: 99,
         id: 2,
       },
       {
         color: 'yellow',
         sku: '1234423',
         price: 79,
         id: 3
       }
    ]
  }
}

Now I want to get and display the cheapest variation of the product. I’ve managed to get the cheapest variants price:

const min = Math.min(...variations.map((item) => item.price))

but how can I get the rest of the object? In this example the ‘yellow’ variant?

Hidden columns in Material-Table causing crash

I have three columns in my Material-Table which provide useful data but are not essential. I want these columns hidden by default when the page is loaded, but give the user the option to un-hide them. I have the columnsButton option set which allows me to manually select which columns I want hidden. By default, no columns are hidden.

I have tried using hidden: true and hiddenByColumnsButton: true. hidden just hides the column and the option to show it does not appear in the columnsButton list. hiddenbyColumnsButton does not hide the column and no effect the functionality of the list. Using both of them at the same time in the same column results in the app crashing: Uncaught TypeError: Cannot read properties of undefined

This is my table and a two of my columns. For the purpose of this question, I want to have Title hidden by default with the option to display it in the columnsButton list.

    const columns = [
        {
            title: <Typography className={classes.colHeader}>Intake ID</Typography>,
            field: "IntakeID",
            cellStyle: { minWidth: 118, maxWidth: 118 },
            // hidden: true,
        },
        {
            title: <Typography className={classes.colHeader}>Title</Typography>,
            field: "Title",
            cellStyle: { minWidth: 280, maxWidth: 280 },
            hidden: true,
            hiddenByColumnsButton: true,
        },
    ];

...
                <MTable
                    title="Table"
                    data={intakes.intakes}
                    columns={columns}
                    options={{
                        columnsButton: true,
                        pageSize: 10,
                        pageSizeOptions: [10, 15, 25, 50, 100],
                        paginationType: "stepped",
                        padding: "small",
                        filtering: true,
                />

React native Videos with TMDB API

i’m creating an app of movies/series Database and its almost done , but it stay one problem is , i created a button that go to youtube to see the trailer of movie but it didn’t work,
i tried two code but dont solve my problem

```<TouchableOpacity onPress={() => {
              Linking.openURL('https://www.youtube.com/watch?v=${details.key.toString()}');
            }}
            >  ```

<TouchableOpacity onPress={() => {
                  Linking.openURL('https://www.youtube.com/watch?v=${details.key}');
                }}
                >  

{details.key} is the key of movie in youtube trailer,
any solutons please?