This class holds all properties and functions necessary to create a spokenGeoJSON instance. A spokenGeoJSON class instance creates a leaflet.js map which is populated with data from a geojson and then after a button click watches the device's location and gives audible statements regarding the current Location being inside of outside of the polygons that make up the geojson.
To fake movement while testing the application, the triggerNavigatorGeoLocation(moveDirection=false,fakeLocation=false,moveAmountInDecimals=0.1) function can be used see defintion below.
(string)
, This argument is the string value of the divID in the HTML where the leaflet.js map will be placed.
Currently, all properties of the class object are public and can be populated by simple assignment. Many of the them are changed by internal methods of the spokenGeoJSON class.
These are properties of the spokenGeoJSON class function.
(string)
: , This property is the divID of a div on the html page you want the leaflet.js map to appear. It accepts the one argument used to initiated the class, which is the string of the Div element where the map will appear.
(object)
: , This property holds data from geojson that is put into the leaflet.js map. At class instance creation, it only has an empty string. An outside function must populate it.
(array)
: , This property is the center of the map when first created in order of [long, lat]. Default is [-95.498,29.7604]
(object)
: , This property is an object in the format of turf.js points that represents the lat/long of the current position of the device.
(object)
: , This property is min and max magnification of the map. Default value is [-95.498,29.7604]
(integer)
: , This property is the initial zoom level of the map
(float)
: , This property is a float representing a latitude value. It is initially populated with the map center, but once location tracking is started will reflect the most recent location of the device.
(float)
: , This property is a float representing a longitude value. It is initially populated with the map center, but once location tracking is started will reflect the most recent location of the device.
(object)
: , The leaflet map object that is created by the following code
L.map(this.divIDForMap, this.mapConfig).setView([this.lat, this.lng], this.zoom);
. For this to work, leaflet.js needs to be loaded via a script tag elment already.
(object)
: , The tiles for the map background from openstreet map. This can be changed on the fly after class instance creation.
(string)
: , A string representing the last location state that triggered speech.
(string)
: , A string representation of the latest measured location state. This means lat/long location converted into a location state by comparing the location to polygons in the geojson.
(object)
: , A unix date time object created by
new Date()
code. This is updated on class instance creation and whenever a location state has been spoken. This time is compared to later times to determine if enough time has passed to speak again when location state is spoken at some interval as opposed to only when a new location state is detected.
(boolean)
: , A true or false boolean value for whether or not the introductury text has been said yet. This starts off as false and converts to true once the introductury text has been said. It should be converted back to false if speaking and/or location has been stopped due to button bush and then restarted via a different button push.
(boolean)
: , Determines whether lat long is said or not. Default is to not say it where has a value of false.
(object)
: , This is the result of the code
window.speechSynthesis
and creates a speech synthesis object available for use by any function in the class, so it doesn't have to recreated each time. Speech synthesis is a native browser capability.
(object)
: , This is a placeholder for a speechSynthesis object
(object)
: , This is a placeholder for a speechSynthesis object
(boolean)
: , If false, it only speaks when there is a location state change. If true, you get speach every X unit of time as defined by the property speakHowOftenIfNotEveryInSeconds.
(integer)
: , An integer of how many seconds to wait from when a location state is spoken until you say the location state again. This only applies if sayEveryMeasurement is true. Otherwise, the object instance will only speak when a location state has changed. For example, outside a floodplain polygon vs. inside the floodplain polygon.
(boolean)
: , A true or false for whether a button has been pushed to stop speaking. True = no speaking. false = speak when conditions require it based on other configuration.
(object)
: , This property holds an object created by calling the native setInterval function that calls the insideLoop function every X time interval. The time interval is set by property speakHowOftenIfNotEveryInSeconds.
undefined
:
, nothing is returned
This function kicks off a bunch of things including asking for location, starting speech, setting up noSleep, and the loops.
(object)
, a speech utterance ready to go for when the maker is within the floodplain.
(object)
, a speech utterance ready to go for when the maker is NOT within the floodplain.
undefined
:
, nothing is returned
This function triggers the adjustPosition(position) function with a position. The position argument is either one from the navigator browswer API or can be fake. This function creates the fake location based on the three optional arguments of moveDirection, fakeLocation, and moveAmountInDecimals to create a position.
EXAMPLE: If you wanted to test out moving from the current location without actually moving the device, you would call in the browswer's console: spokenGeoJSON_Harris_global.triggerNavigatorGeoLocation(move="west",fakeLocation=false,moveAmountInDecimals=0.001)
(string
= false
)
, Default value is false, whic triggers no movement. Other values possible are "north","south","west", and "east".
(string
= false
)
, Whether the starting location should be the current location measured by navigator.getLocation or this.mapCenterAtStart property used on page start.
(object
= 0.1
)
, Default value is 0.1. Any float value like 0.001 or 1.0 will work.
undefined
:
, nothing is returned. However, the adjustPosition(position) function is triggered.
This function checks if the location state should change based on the last measured location state the the most recently measured location state.
It updates the location state if it determines it is necessary by comparing current location to last known location or this.lastMeasuredLocationState then calls the decideWhatToSpeak() function, which figures out if speaking is appropriate at this time.
undefined
:
, nothing is returned. However, the adjustPosition(position) function is triggered.
This function grabs several properties from the class object instance and uses them to decide what should be spoken. It then calls the function speakAndUpdate(synthesizedSpeechUtterance,locationState) which says the generated speach utterances, updates this.lastSpokenState and this.lastSpokenStateAtTime Properties that it calls upon to decide what to speak include:
undefined
:
, nothing is returned. However, the speakAndUpdate() function is called
This function checks to see if enough time has gone by to speak again if there is a limit on how often to speak.
(object)
, This should be the property of 'this.lastSpokenStateAtTime'
boolean
:
, Returns a boolean value of true or false. True if enough time has passed to speak.
This function does three things via a single function so these lines don't have to be rewritten a bunch of times in decideWhatToSpeak() function. It takes in an synthesizedSpeechUtterance object that it calls to speak It takes in locationState argument that it makes the new value of this.lastSpokenState It finds a new date and updates the value of this.lastSpokenStateAtTime with it.
(object)
, A synthesizedSpeechUtterance object created in decideWhatToSpeak() function
(string)
, A locationState string created in decideWhatToSpeak() function that represents
the location state value of the last measured position. This might be "outside" or "inside" for example.
undefined
:
, nothing is returned. However, the adjustPosition(position) function is triggered.
This function stops the speech utterance calls and sets this.locationState to "noLocationKnownYet" It also changes the button styles so it is obvious they were pushed.
These changes are all reverse if the start buton is pressed again and getLocation function is called.
undefined
:
, nothing is returned
This function changes how often words are spoken are the introductury text. If the howOften argument is "boundaries", then it only tells the user when they have passed from "outside" to "inside" or the inverse. If the howOften argument is set to "constantly", the speaker will also here a message that they are "still in ___" at some interval set by other configuration properties. This function is probably called as a result of a button push in the user interface.
(string)
, A string value of preferred state. Options are "boundaries" and "constantly".
(string
= 10
)
, This updates the property this.speakHowOftenIfNotEveryInSeconds that is used to determine how often to give location state updates when there is no change.
undefined
:
, nothing is returned
Merely toggles show or hide on the dropdown list of buttons used to select rate at which "no change" messages are spoken.
undefined
:
, nothing is returned
// Close the dropdown of class .dropbtn if the user clicks outside of it
(any)
undefined
:
, nothing is returned
This function calls the javascript built-in fetch function to get the geojson data loaded and creates an instance of the spokenGeoJSON class and then adds the data to it as 'polygons' property before calling the onEachFeature method of the spokenGeoJSON class that applies that data to the leaflet map intiated when the class instance was first initiated.
(string
= "./data/FEMA_FIRM_FloodPolygons.json"
)
, A string representation of the URL to the data file. Default is "./data/FEMA_FIRM_FloodPolygons.json"
undefined
:
, nothing is returned
This function starts calling the initial JavaScript functions after the HTML is loaded. Specifically it calls the loadDataAndInitiateClassInstance () function.
undefined
:
, nothing is returned