Saturday, 5 August 2017

javascript - leaflet GeoJSON value not variable name


I have a GeoJSON file that has fields of the days of the week like "Monday" with values 'Y' or 'N'. So I want to get today's day value, using something like


var theDayValue = 'feature.properties + day'


However this gives me a string. I want to get the value of


var theDayValue = feature.properties.Monday.


I plan on using this to show if open or closed in Leaflet by symbol color.



Answer




You could try using bracket notation instead of dot notation... you just have to give it the property name as a string (i.e., var theDayValue = feature.properties['Monday']). Assuming that 'day' is a variable whose value is the string matching the name of the field you want, that would look like this:


var day = 'Monday';
var theDayValue = feature.properties[day];

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...