Data class
google.maps.Data
class
A layer for displaying geospatial data. Points, line-strings and polygons can be displayed.
Every Map
has a Data
object by default, so most of the time there is no need to construct one. For example:
var myMap = new google.maps.Map(...);
myMap.data.addGeoJson(...);
myMap.data.setStyle(...);
Data
object is a collection of Features
.
This class extends
MVCObject
.
Access by calling const {Data} = await google.maps.importLibrary("maps")
.
See Libraries in the Maps JavaScript API.
Constructor | |
---|---|
Data |
Data([options]) Parameters:
Creates an empty collection, with the given DataOptions . |
Methods | |
---|---|
add |
add([feature]) Parameters:
Return Value:
Data.Feature Adds a feature to the collection, and returns the added feature. If the feature has an ID, it will replace any existing feature in the collection with the same ID. If no feature is given, a new feature will be created with null geometry and no properties. If Note that the IDs |
addGeoJson |
addGeoJson(geoJson[, options]) Parameters:
Return Value:
Array<Data.Feature> Adds GeoJSON features to the collection. Give this method a parsed JSON. The imported features are returned. Throws an exception if the GeoJSON could not be imported. |
contains |
contains(feature) Parameters:
Return Value:
boolean Checks whether the given feature is in the collection. |
forEach |
forEach(callback) Parameters:
Return Value: None
Repeatedly invokes the given function, passing a feature in the collection to the function on each invocation. The order of iteration through the features is undefined. |
getControlPosition |
getControlPosition() Parameters: None
Return Value:
ControlPosition Returns the position of the drawing controls on the map. |
getControls |
getControls() Parameters: None
Return Value:
Array<string> Returns which drawing modes are available for the user to select, in the order they are displayed. This does not include the null drawing mode, which is added by default. Possible drawing modes are "Point" , "LineString" or "Polygon" . |
getDrawingMode |
getDrawingMode() Parameters: None
Return Value:
string|null Returns the current drawing mode of the given Data layer. A drawing mode of null means that the user can interact with the map as normal, and clicks do not draw anything. Possible drawing modes are null , "Point" , "LineString" or "Polygon" . |
getFeatureById |
getFeatureById(id) Parameters:
Return Value:
Data.Feature|undefined Returns the feature with the given ID, if it exists in the collection. Otherwise returns undefined . Note that the IDs |
getMap |
getMap() Parameters: None
Return Value:
Map Returns the map on which the features are displayed. |
getStyle |
getStyle() Parameters: None
Return Value:
Data.StylingFunction|Data.StyleOptions Gets the style for all features in the collection. |
loadGeoJson |
loadGeoJson(url[, options, callback]) Parameters:
Return Value: None
Loads GeoJSON from a URL, and adds the features to the collection. NOTE: The GeoJSON is fetched using XHR, and may not work cross-domain. If you have issues, we recommend you fetch the GeoJSON using your choice of AJAX library, and then call |
overrideStyle |
overrideStyle(feature, style) Parameters:
|