Unable to access GeoJSON properties with ":" using JS variable - javascript

I am currently following the tutorial on Mapbox to build a store locator with a map.
I'm having problems displaying data from my GeoJSON file that I got from Turbo Overpass. Example of the GeoJSON being used :
"properties": {
"#id": "node/5750820619",
"addr:city": "Caissargues",
"addr:housenumber": "180",
"addr:postcode": "30132",
"addr:street": "Avenue de la Vistrenque",
"description:covid19": "horaires légèrement réduits",
"name": "Bio Marché",
},
In my Javascript file I can access properties such as name using this code :
var details = listing.appendChild(document.createElement('div'));
details.innerHTML = prop.addr:city;
...but am unable to figure out how to access the addr:city or addr:postcode field as I either get an unexpected identified in vs code or it returns a undefined value in the website. I've tried using prop.addr:city;, prop.addr/':city'/; and other ways proposed on websites.
If someone could point me in the right direction or propose the solution I would be very grateful.
Thanks !

You should access these properties like this:
details.innerHTML = prop['addr:city'];
This works because in Javascript object properties can always be accessed using these brackets.
For example this:
const a = prop.a;
is equal to
const a = prop['a'];
However using the last syntax Javascript is a lot more relaxed. You could even do this:
const property = prop['some property with lots of spaces'];

Related

How do I access context key values in vscode extension?

Description
I am setting a configPath context variable using...
const configPath = '/some/file/path.yml';
vscode.commands.executeCommand(
'setContext',
'ext.configPath',
configPath
);
... which can be used within when properties in package.json. For example, "when": "ext.configPath".
Problem
I cannot seem to obtain the value for string interpolation, or programmatically.
Ask
I would like to know...
How to interpolate the context variable value within a string in the package.json file. For example, for tree data title...
{
"id": "ext.treedata.accounts",
"name": "Accounts - ${context:ext.configPath}",
"when": "ext.configPath"
}
... I would expect the title to read Accounts - /some/file/path.yml.
How to obtain the context variable value programmatically. For example...
const configPath = vscode.getContext('ext.configPath');
console.log(configPath); // Outputs: /some/file/path.yml
I've tried using ${context:ext.configPath} to interpolate, and I've tried looking for getContext methods. I've also tried searching the vscode extension development docs.
There is no getContext API/command, unfortunately. There is however, an open issue (https://github.com/microsoft/vscode/issues/10471), but no ETA.
So, in your case, you will have to store that value somewhere. Depending on your scenarios, maybe you could take advantage of workspaceState or globalState Mementos.
Hope this helps

fail to implement st_distance_sphere

When trying to create an app that one of its functions is to search for certain places near a given point, I have encountered this error:
SequelizeDatabaseError: st_distance_sphere (geometry, geometry)
function does not exist.
I see in the Doc that it works but I can't see the failure.
const distance= Sequelize.fn('ST_Distance_Sphere', Sequelize.col('ubication'), ubication);
This is the conflict code
and this is the other variable
const ubication = Sequelize.literal(`ST_GeomFromText('POINT( ${meeti.ubication.coordinates[0]} ${meeti.ubication.coordinates[1]} )' )`);
Thank you very much in advance
The function name you are using is obsolete. The proper name is ST_DistanceSphere

Syntax to access json array

I don't know the syntax to access the "relatedTo" array of my Json object.
When I do JSON.parse(data).projects[0].name I have "New Pretender",
when I do JSON.parse(data).projects[0].relatedTo[0] I have undefined
I have tried few different syntaxes but none of them was working...
The structure is like this :
{
"projects": [{
"name":"New Pretender",
"shortDescription":"A love coach not like the others",
"year":"2016",
"description":"An interactive game/fiction design object you can play with a boob-shaped joystick. Talk about manipulation and other things.",
"relatedTo": ["ecriture", "rhetorique", "jeu"]
}, {
"name":"Pénombre",
"shortDescription":"A game about go out",
"year":"2016",
"description":"This game invites th player to experiment what it is to be alone in a huge world, not knowing where you have to go.",
"relatedTo": ["jeu", "carte"]
}, {
"name":"Bodmer Lab",
"shortDescription":"A generative book based on Martin Bodmer' Faust collection",
"year":"2016",
"description":"This is a book made with a lots of digitized old books that are in the Martin Bodmer huge collection.",
"relatedTo": ["ecriture", "generatif"]
}]
}
Given the structure above, projects[0].relatedTo[0] would return ecriture. I do not see anything incorrect with your syntax. However, it seems as if you may not be looking at the object you think you are.
Is it possible projects[0] is pointing to a project that does not have any relations (i.e. an empty list)? This would result in undefined when trying to access relatedTo[0]. I'd encourage you to check out what relatedTo is, and even what projects[0] is.
I feel so idiotic... I forgot that I have duplicated my json file so I was just calling a file in which the property doesn't exist. I changed the path and now it's ok.

Understanding a this._(STRING) call in node RED

I'm trying to understand existing code of the Switch node in node-red to deal with and make my own node correctly.
I'm stuck with these lines :
var operators = [
{v:"eq",t:"=="},
{v:"neq",t:"!="},
{v:"lt",t:"<"},
{v:"lte",t:"<="},
{v:"gt",t:">"},
{v:"gte",t:">="},
{v:"btwn",t:this._("switch.rules.btwn")},
{v:"cont",t:this._("switch.rules.cont")},
{v:"regex",t:this._("switch.rules.regex")},
{v:"true",t:this._("switch.rules.true")},
{v:"false",t:this._("switch.rules.false")},
{v:"null",t:this._("switch.rules.null")},
{v:"nnull",t:this._("switch.rules.nnull")},
{v:"else",t:this._("switch.rules.else")}
];
Especially with the this._("switch.rules.smthg"). How it will work ? Sometime in the code, i will see this call, but i'm not able to find where is it stored, and so make my own, like this._(myawesomenode.myawesomesection.myawesomepropertie)
EDIT
Thanks to your comments, i've seen it's for internationalisation.
Suppposing i have this catalog :
{
"and": {
"list": {
"key": "THE DATA I WANT"
}
}
}
How can i have my data ? I've tried something like this._(and.list.key) without result.
This is the function to pull in the translated version of a label.
"switch.rules.btwn" is the key to look up the version of the label in the right language for the user.
See the Internationalisation section of the Node-RED documentation for more details.
I don't know node-red, but this looks like there is some method defined on the this object with the name/identifier _, which is called with a string parameter.
You can do this like this._ = function (arg) {...}
You might find the definition in the constructor for the this object (whatever that is in that context)

Querying the DOM in Windows 8 Apps from within a method

I'm struggling with this even after reading the MSDN documentation and the following online guides:
Codefoster
Stephen Walter
I think my problem is easy to fix and that I just am thinking about something in the wrong way. Basically I am querying my web service and on success running the following method. I am then trying to bind the result to my listview. For now I am using a hardcoded value publicMembers.itemlistwhich has been declared at the top of the document just to make sure I can actually bind to the list before doing it with my query results. Ignore line 2 for now.
Success Method:
_lookUpSuccess: function xhrSucceed(Result) {
var response = JSON.parse(Result.responseText);
listView = document.querySelector("#termTest");
ui.setOptions(listView, {
itemDataSource: publicMembers.itemList,
itemTemplate: document.querySelector(".itemtemplate"),
})
},
Now, instead of using document.querySelector, I have also tried with WinJS.Utilities.id and WinJS.Utilities.query, neither of which worked either. This doesn't break my code and introduce an error but it doesn't bind to the listview either so I think I have an issue in querying the right DOM element. However exactly the same code does work if I add it to the top of the script, it is only when I place it in this method that it stops working.
EDIT: Also to clarify, when I debug publicMembers.itemList is storing the values I expect them to be.
Please point out if I have explained things poorly and I will try and improve my question.
Thanks.
I haven't used WinJS.UI.setOptions, but rather this other way of setting the data source. Can you see if it works?
_lookUpSuccess: function xhrSucceed(result) {
var response = JSON.parse(result.responseText);
listView = document.querySelector("#termTest");
listView.winControl.itemDataSource = publicMembers.itemList;
},
This would assume you're defining the itemTemplate as part of the data-win-options attribute of your ListView's HTML element. You could also probably just do listView.winControl.itemTemplate = document.querySelector(".itemtemplate") if you prefer to set it programmatically.

Categories

Resources