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([options])
-
options
:Data.DataOptions optional
DataOptions
.Methods
add([feature])
-
feature
:Data.Feature | Data.FeatureOptions optional
Data.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 FeatureOptions
are given, a new feature will be created with the specified properties.
Note that the IDs 1234
and '1234'
are equivalent. Adding a feature with ID 1234
will replace a feature with ID '1234'
, and vice versa.
addGeoJson(geoJson[, options])
-
geoJson
:Object
-
options
:Data.GeoJsonOptions optional
Array
< Data.Feature
>
contains(feature)
-
feature
:Data.Feature
boolean
forEach(callback)
-
callback
:function( Data.Feature ): void
getControlPosition()
ControlPosition
getControls()
Array
<string>
null
drawing mode, which is added by default. Possible drawing modes are "Point"
, "LineString"
or "Polygon"
.getDrawingMode()
string|null
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(id)
-
id
:number|string
Data.Feature
|undefined
undefined
. Note that the IDs 1234
and '1234'
are equivalent. Either can be used to look up the same feature.
getStyle()
Data.StylingFunction
| Data.StyleOptions
loadGeoJson(url[, options, callback])
-
url
:string
-
options
:Data.GeoJsonOptions optional
-
callback
:function( Array < Data.Feature >): void optional
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 addGeoJson()
.
overrideStyle(feature, style)
-
feature
:Data.Feature
-
style
:Data.StyleOptions
setStyle()
. Style properties set to null
revert to the value specified via setStyle()
.remove(feature)
-
feature
:Data.Feature
revertStyle([feature])
-
feature
:Data.Feature optional
overrideStyle()
calls. The style of the given feature reverts to the style specified by setStyle()
. If no feature is given, all features have their style reverted.
setControlPosition(controlPosition)
-
controlPosition
:ControlPosition
setControls(controls)
-
controls
:Array <string>
null
drawing mode, which is added by default. If null
, drawing controls are disabled and not displayed. Possible drawing modes are "Point"
, "LineString"
or "Polygon"
.setDrawingMode(drawingMode)
-
drawingMode
:string optional
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"
.setMap(map)
-
map
:Map
null
, the features will be removed from the map.setStyle(style)
-
style
:Data.StylingFunction | Data.StyleOptions
overrideStyle()
continue to apply. Pass either an object with the desired style options, or a function that computes the style for each feature. The function will be called every time a feature's properties are updated.
Events
function(event)
-
event
:Data.AddFeatureEvent
function(event)
-
event
:Data.MouseEvent
function(event)
-
event
:Data.MouseEvent
function(event)
-
event
:Data.MouseEvent
function(event)
-
event
:Data.MouseEvent
function(event)
-
event
:Data.MouseEvent
function(event)
-
event
:Data.RemoveFeatureEvent
function(event)
-
event
:Data.RemovePropertyEvent
function(event)
-
event
:Data.SetGeometryEvent
function(event)
-
event
:Data.SetPropertyEvent
function(event)
-
event
:Data.MouseEvent
Data.DataOptions interface
google.maps
. Data.DataOptions
interface
DataOptions object used to define the properties that a developer can set on a Data
object.
Properties |
|
---|---|
map
|
Type:
Map
Map on which to display the features in the collection.
|
controlPosition
optional
|
Type:
ControlPosition
optional
Default:
ControlPosition.TOP_LEFT
The position of the drawing controls on the map.
|
controls
optional
|
Type:
Array
<string> optional
Default:
null
Describes which drawing modes are available for the user to select, in the order they are displayed. This should not include the
null
drawing mode, which is added by default. If null
, drawing controls are disabled and not displayed. Possible drawing modes are "Point"
, "LineString"
or "Polygon"
. |
drawingMode
optional
|
Type:
string optional
Default:
null
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"
. |
featureFactory
optional
|
Type:
function( Data.Geometry
): Data.Feature
optional
When drawing is enabled and a user draws a Geometry (a Point, Line String or Polygon), this function is called with that Geometry and should return a Feature that is to be added to the Data layer. If a featureFactory is not supplied, a Feature with no id and no properties will be created from that Geometry instead. Defaults to
null
. |
style
optional
|
Type:
Data.StylingFunction
| Data.StyleOptions
optional
|
Data.GeoJsonOptions interface
google.maps
. Data.GeoJsonOptions
interface
Optional parameters for importing GeoJSON.
Properties |
|
---|---|
idPropertyName
optional
|
Type:
string optional
The name of the Feature property to use as the feature ID. If not specified, the GeoJSON Feature id will be used.
|
Data.StyleOptions interface
google.maps
. Data.StyleOptions
interface
These options specify the way a Feature should appear when displayed on a map.
Properties |
|
---|---|
animation
optional
|
Type:
Animation
optional
The animation to play when marker is added to a map. Only applies to point geometries.
|
clickable
optional
|
Type:
boolean optional
Default:
true
If
true
, the marker receives mouse and touch events. |
cursor
optional
|
Type:
string optional
Mouse cursor to show on hover. Only applies to point geometries.
|
draggable
optional
|
Type:
boolean optional
Default:
false
If
true
, the object can be dragged across the map and the underlying feature will have its geometry updated. |
editable
optional
|
Type:
boolean optional
Default:
false
If
true
, the object can be edited by dragging control points and the underlying feature will have its geometry updated. Only applies to LineString and Polygon geometries. |
fillColor
optional
|
Type:
string optional
The fill color. All CSS3 colors are supported except for extended named colors. Only applies to polygon geometries.
|
fillOpacity
optional
|
Type:
number optional
The fill opacity between 0.0 and 1.0. Only applies to polygon geometries.
|
icon
optional
|
Icon for the foreground. If a string is provided, it is treated as though it were an
Icon
with the string as url
. Only applies to point geometries. |
icons
optional
|
Type:
Array
< IconSequence
> optional
The icons to be rendered along a polyline. Only applies to line geometries.
|
label
optional
|
Type:
string| MarkerLabel
optional
Adds a label to the marker. The label can either be a string, or a
MarkerLabel
object. Only applies to point geometries. |
opacity
optional
|
Type:
number optional
The marker's opacity between 0.0 and 1.0. Only applies to point geometries.
|
shape
optional
|
Type:
MarkerShape
optional
Defines the image map used for hit detection. Only applies to point geometries.
|
strokeColor
optional
|
Type:
string optional
The stroke color. All CSS3 colors are supported except for extended named colors. Only applies to line and polygon geometries.
|
strokeOpacity
optional
|
Type:
number optional
The stroke opacity between 0.0 and 1.0. Only applies to line and polygon geometries.
|
strokeWeight
optional
|
Type:
number optional
The stroke width in pixels. Only applies to line and polygon geometries.
|
title
optional
|
Type:
string optional
Rollover text. Only applies to point geometries.
|
visible
optional
|
Type:
boolean optional
Default:
true
Whether the feature is visible.
|
zIndex
optional
|
Type:
number optional
All features are displayed on the map in order of their zIndex, with higher values displaying in front of features with lower values. Markers are always displayed in front of line-strings and polygons.
|
Data.StylingFunction typedef
google.maps
. Data.StylingFunction
typedef
A function that computes the appearance of a feature.
The Data.setStyle()
method can accept a styling function. Use this when features should appear differently depending on their properties. You can find more information about styling features in the developer's guide
.
function( Data.Feature
): Data.StyleOptions
Data.Feature class
google.maps
. Data.Feature
class
A feature has a geometry, an id, and a set of properties.
Access by calling const {Data} = await google.maps.importLibrary("maps")
.See Libraries in the Maps JavaScript API
.
Constructor
Data.Feature([options])
-
options
:Data.FeatureOptions optional
Methods
forEachProperty(callback)
-
callback
:function(*, string): void
getId()
number|string|undefined
getProperty(name)
-
name
:string
*
undefined
if the property does not exist.removeProperty(name)
-
name
:string
setGeometry(newGeometry)
-
newGeometry
:Data.Geometry | LatLng | LatLngLiteral
setProperty(name, newValue)
-
name
:string
-
newValue
:*
newValue
is undefined
this is equivalent to calling removeProperty
.Events
function(event)
-
event
:Data.RemovePropertyEvent
function(event)
-
event
:Data.SetGeometryEvent
function(event)
-
event
:Data.SetPropertyEvent
Data.FeatureOptions interface
google.maps
. Data.FeatureOptions
interface
Optional parameters for creating Data.Feature
objects.
Properties |
|
---|---|
geometry
optional
|
Type:
Data.Geometry
| LatLng
| LatLngLiteral
optional
The feature geometry. If none is specified when a feature is constructed, the feature's geometry will be
null
. If a LatLng
object or LatLngLiteral
is given, this will be converted to a Data.Point
geometry. |
id
optional
|
Type:
number|string optional
Feature ID is optional. If provided, it can be used to look up the feature in a
Data
object using the getFeatureById()
method. Note that a feature's ID cannot be subsequently changed. |
properties
optional
|
Type:
Object
optional
The feature properties. This is an arbitrary mapping of property names to values.
|
Data.Geometry interface
google.maps
. Data.Geometry
interface
A superclass for the various geometry objects.
Methods
forEachLatLng(callback)
-
callback
:function( LatLng ): void
getType()
string
"Point"
, "MultiPoint"
, "LineString"
, "MultiLineString"
, "LinearRing"
, "Polygon"
, "MultiPolygon"
, or "GeometryCollection"
.Data.Point class
google.maps
. Data.Point
class
A Point geometry contains a single LatLng
.
This class implements Data.Geometry
.
Access by calling const {Data} = await google.maps.importLibrary("maps")
.See Libraries in the Maps JavaScript API
.
Constructor
Data.Point(latLng)
-
latLng
:LatLng | LatLngLiteral
Data.Point
from the given LatLng
or LatLngLiteral
.Methods
getType()
string
"Point"
.Data.MultiPoint class
google.maps
. Data.MultiPoint
class
A MultiPoint geometry contains a number of LatLng
s.
This class implements Data.Geometry
.
Access by calling const {Data} = await google.maps.importLibrary("maps")
.See Libraries in the Maps JavaScript API
.
Constructor
Data.MultiPoint(elements)
-
elements
:Array < LatLng | LatLngLiteral >
Data.MultiPoint
from the given LatLng
s or LatLngLiteral
s.Methods
getLength()
number
LatLng
s.getType()
string
"MultiPoint"
.Data.LineString class
google.maps
. Data.LineString
class
A LineString geometry contains a number of LatLng
s.
This class implements Data.Geometry
.
Access by calling const {Data} = await google.maps.importLibrary("maps")
.See Libraries in the Maps JavaScript API
.
Constructor
Data.LineString(elements)
-
elements
:Array < LatLng | LatLngLiteral >
Data.LineString
from the given LatLng
s or LatLngLiteral
s.Methods
getLength()
number
LatLng
s.getType()
string
"LineString"
.Data.MultiLineString class
google.maps
. Data.MultiLineString
class
A MultiLineString geometry contains a number of LineString
s.
This class implements Data.Geometry
.
Access by calling const {Data} = await google.maps.importLibrary("maps")
.See Libraries in the Maps JavaScript API
.
Constructor
Data.MultiLineString(elements)
-
elements
:Array < Data.LineString | Array < LatLng | LatLngLiteral >>
Data.MultiLineString
from the given Data.LineString
s or arrays of positions.Methods
getArray()
Array
< Data.LineString
>
Data.LineString
s. A new array is returned each time getArray()
is called.getAt(n)
-
n
:number
Data.LineString
n
-th contained Data.LineString
.getLength()
number
Data.LineString
s.getType()
string
"MultiLineString"
.Data.LinearRing class
google.maps
. Data.LinearRing
class
A LinearRing geometry contains a number of LatLng
s, representing a closed LineString. There is no need to make the first LatLng
equal to the last LatLng
. The LinearRing is closed implicitly.
This class implements Data.Geometry
.
Access by calling const {Data} = await google.maps.importLibrary("maps")
.See Libraries in the Maps JavaScript API
.
Constructor
Data.LinearRing(elements)
-
elements
:Array < LatLng | LatLngLiteral >
Data.LinearRing
from the given LatLng
s or LatLngLiteral
s.Methods
getLength()
number
LatLng
s.getType()
string
"LinearRing"
.Data.Polygon class
google.maps
. Data.Polygon
class
A Polygon geometry contains a number of Data.LinearRing
s. The first linear-ring must be the polygon exterior boundary and subsequent linear-rings must be interior boundaries, also known as holes. See the sample polygon with a hole
.
This class implements Data.Geometry
.
Access by calling const {Data} = await google.maps.importLibrary("maps")
.See Libraries in the Maps JavaScript API
.
Constructor
Data.Polygon(elements)
-
elements
:Array < Data.LinearRing | Array < LatLng | LatLngLiteral >>
Data.Polygon
from the given Data.LinearRing
s or arrays of positions.Methods
getArray()
Array
< Data.LinearRing
>
Data.LinearRing
s. A new array is returned each time getArray()
is called.getAt(n)
-
n
:number
Data.LinearRing
n
-th contained Data.LinearRing
.getLength()
number
Data.LinearRing
s.getType()
string
"Polygon"
.Data.MultiPolygon class
google.maps
. Data.MultiPolygon
class
A MultiPolygon geometry contains a number of Data.Polygon
s.
This class implements Data.Geometry
.
Access by calling const {Data} = await google.maps.importLibrary("maps")
.See Libraries in the Maps JavaScript API
.
Constructor
Data.MultiPolygon(elements)
-
elements
:Array < Data.Polygon | Array < Data.LinearRing | Array < LatLng | LatLngLiteral >>>
Data.MultiPolygon
from the given Data.Polygon
s or arrays of positions.Methods
getArray()
Array
< Data.Polygon
>
Data.Polygon
s. A new array is returned each time getArray()
is called.getAt(n)
-
n
:number
Data.Polygon
n
-th contained Data.Polygon
.getLength()
number
Data.Polygon
s.getType()
string
"MultiPolygon"
.Data.GeometryCollection class
google.maps
. Data.GeometryCollection
class
A GeometryCollection contains a number of geometry objects. Any LatLng
or LatLngLiteral
objects are automatically converted to Data.Point
geometry objects.
This class implements Data.Geometry
.
Access by calling const {Data} = await google.maps.importLibrary("maps")
.See Libraries in the Maps JavaScript API
.
Constructor
Data.GeometryCollection(elements)
-
elements
:Array < Data.Geometry | LatLng | LatLngLiteral >
Data.GeometryCollection
from the given geometry objects or LatLng
s.Methods
getArray()
Array
< Data.Geometry
>
getArray()
is called.getAt(n)
-
n
:number
Data.Geometry
n
-th contained geometry object.getLength()
number
getType()
string
"GeometryCollection"
.Data.MouseEvent interface
google.maps
. Data.MouseEvent
interface
This object is passed to mouse event handlers on a Data
object.
This interface extends MapMouseEvent
.
Properties |
|
---|---|
feature
|
Type:
Data.Feature
The feature which generated the mouse event.
|
Inherited:
domEvent
, latLng
|
Methods |
|
---|---|
Inherited:
stop
|
Data.AddFeatureEvent interface
google.maps
. Data.AddFeatureEvent
interface
The properties of a addfeature
event.
Properties |
|
---|---|
feature
|
Type:
Data.Feature
The feature that was added to the
FeatureCollection
. |
Data.RemoveFeatureEvent interface
google.maps
. Data.RemoveFeatureEvent
interface
The properties of a removefeature
event.
Properties |
|
---|---|
feature
|
Type:
Data.Feature
The feature that was removed from the
FeatureCollection
. |
Data.SetGeometryEvent interface
google.maps
. Data.SetGeometryEvent
interface
The properties of a setgeometry
event.
Properties |
|
---|---|
feature
|
Type:
Data.Feature
The feature whose geometry was set.
|
newGeometry
optional
|
Type:
Data.Geometry
optional
The new feature geometry.
|
oldGeometry
optional
|
Type:
Data.Geometry
optional
The previous feature geometry.
|
Data.SetPropertyEvent interface
google.maps
. Data.SetPropertyEvent
interface
The properties of a setproperty
event.
Properties |
|
---|---|
feature
|
Type:
Data.Feature
The feature whose property was set.
|
name
|
Type:
string
The property name.
|
newValue
|
Type:
*
The new value.
|
oldValue
|
Type:
*
The previous value. Will be
undefined
if the property was added. |
Data.RemovePropertyEvent interface
google.maps
. Data.RemovePropertyEvent
interface
The properties of a removeproperty
event.
Properties |
|
---|---|
feature
|
Type:
Data.Feature
The feature whose property was removed.
|
name
|
Type:
string
The property name.
|
oldValue
|
Type:
*
The previous value.
|