This class represents a GeoJSON reader responsible for fetching and
interpreting GeoJSON data. It creates an instance of H.map.Object
that can be displayed on the map (for more details see GeoJSON documentation).
Auxiliary data that accompanies geometries (the contents of the field
properties) is bound to the map object and can be fetched with the method
getData() on that object. See H.map.Object#getData.
Note that you can load a GeoJSON file even from a different domain, if that domain supports Cross-Origin Resource Sharing.
| Name | Type | Description |
|---|---|---|
opt_url |
string |
optional
The optional URL of the data file. |
opt_options |
H.data.geojson.Reader.Options |
optional
An object providing additional reader configuration parameters. |
Example
var reader = new H.data.geojson.Reader('/path/to/geojson/file.json');
reader.parse();
// Assumption: map already exists
map.addLayer(reader.getLayer());
Extends
Methods
-
addEventListener (type, handler, opt_capture, opt_scope) inherited
-
This method adds a listener for a specific event.
Note that to prevent potential memory leaks, you must either call
removeEventListenerordisposeon the given object when you no longer need it.Name Type Description typestring The name of the event
handlerfunction An event handler function
opt_captureboolean optional trueindicates that the method should listen in the capture phase (bubble otherwise)opt_scopeObject optional An object defining the scope for the handler function
-
addOnDisposeCallback (callback, opt_scope) inherited
-
This method adds a callback which is triggered when the
EventTargetobject is being disposed.Name Type Description callbackfunction The callback function.
opt_scopeObject optional An optional scope for the callback function
-
dispatchEvent (evt) inherited
-
This method dispatches an event on the
EventTargetobject.Name Type Description evtH.util.Event | string An object representing the event or a string with the event name
-
dispose () inherited
-
This method removes listeners from the given object. Classes that extend
EventTargetmay need to override this method in order to remove references to DOM Elements and additional listeners. -
getLayer ()H.map.layer.ObjectLayer inherited
-
This method retrieves an object layer (
H.map.layer.ObjectLayer) that contains parsed data and can be added directly to the map. The method gets a new instance ofObjectLayerwith every invocation. If the data has not been parsed, the method returns anObjectLayerthat contains partial information, and the reader adds any new parsed objects to the provider associated with the layer later on.Returns:
Type Description H.map.layer.ObjectLayer -
getParsedObjects ()Array.<!H.map.Object> inherited
-
This method retrieves a collection of objects representing parsed data converted to data objects. Note that the method returns only currently parsed objects if parsing is ongoing.
Returns:
Type Description Array.<!H.map.Object> An array of objects representing parsed data -
getState ()H.data.AbstractReader.State inherited
-
This method retrieves the processing state of the
Reader. For possible states seeH.data.AbstractReader.State.Returns:
Type Description H.data.AbstractReader.State A value indicating the state of the Reader -
getUrl ()string | undefined inherited
-
This method retrieves the URL of the current file, which is either a file being fetched/parsed or a file that has been already parsed.
Returns:
Type Description string | undefined url A string containing the URL or undefined -
parse () inherited
-
This method launches parsing of the data file at the current URL (see
H.data.AbstractReader#setUrlorH.data.AbstractReader). The method uses XHR as a transport, therefore the same origin policy applies, or the server should respond with the appropriate CORS headers. -
This method launches the parsing process on the provided data.
Name Type Description datastring | Object A string or object containing the data to parse
-
removeEventListener (type, handler, opt_capture, opt_scope) inherited
-
This method removes a previously added listener from the
EventTargetinstance.Name Type Description typestring The name of the event
handlerfunction A previously added event handler
opt_captureboolean optional trueindicates that the method should listen in the capture phase (bubble otherwise)opt_scopeObject optional An object defining the scope for the handler function
-
setUrl (url)H.data.AbstractReader inherited
-
This method sets the URL for the
Reader. It resets the current state of theReaderto its initial values (clears data about last parsed objects, etc.), and throwsInvalidStateexception if the state of theReaderis notREADYorERROR.Name Type Description urlstring The new URL
Returns:
Type Description H.data.AbstractReader An object reflecting the Readerafter modification
Type Definitions
-
This type encapsulates configuration (initialization) properties for a
H.data.geojson.Reader.Properties:
Name Type Argument Description stylefunction <optional>
A function to be invoked during the parsing process, after object creation, and is used to set the style of the object.
disableLegacyModeboolean <optional>
A flag indicating whether GeoJSON geometry types MultiPoint, MultiLineString, MultiPolygon should be represented respectively by
H.geo.MultiPoint,H.geo.MultiLineStringandH.geo.MultiPolygon. To maximise compatibility when fetching data from remote services and enabling features like polygon interiors it is recommended to set this flag totrue.
For backward compatibility with older releases of the API the default value of the flag isfalse.
Events
-
statechange inherited
-
Event fired when the reader state changes, see
H.data.AbstractReader#getState.Type: