0
# Marker and Symbol Layers
1
2
Display point data using markers and customizable SVG symbols with hover text, info boxes, and flexible styling options. Markers are perfect for showing specific locations like businesses, landmarks, or events.
3
4
## Capabilities
5
6
### Marker Layer Creation
7
8
Create layers containing traditional Google Maps markers with labels and info boxes.
9
10
```python { .api }
11
def marker_layer(locations, hover_text='', label='', info_box_content=None, display_info_box=None):
12
"""
13
Create a layer of markers.
14
15
Parameters:
16
- locations (array-like): Array of (latitude, longitude) tuples
17
- hover_text (str or list): Text to display on hover
18
- label (str or list): Text displayed inside marker
19
- info_box_content (str or list, optional): Content for info box popup
20
- display_info_box (bool or list, optional): Whether to show info box on click
21
22
Returns:
23
Markers: Markers layer instance
24
"""
25
```
26
27
### Symbol Layer Creation
28
29
Create layers with customizable SVG symbols for more flexible point visualization.
30
31
```python { .api }
32
def symbol_layer(locations, hover_text='', fill_color=None, fill_opacity=1.0, stroke_color=None, stroke_opacity=1.0, scale=3, info_box_content=None, display_info_box=None):
33
"""
34
Create a layer of symbols (SVG markers).
35
36
Parameters:
37
- locations (array-like): Array of (latitude, longitude) tuples
38
- hover_text (str or list): Text to display on hover
39
- fill_color (str or list, optional): Symbol fill color
40
- fill_opacity (float or list): Fill opacity (0.0-1.0)
41
- stroke_color (str or list, optional): Symbol outline color
42
- stroke_opacity (float or list): Stroke opacity (0.0-1.0)
43
- scale (float or list): Symbol size scaling factor
44
- info_box_content (str or list, optional): Content for info box popup
45
- display_info_box (bool or list, optional): Whether to show info box on click
46
47
Returns:
48
Markers: Markers layer instance containing symbols
49
"""
50
```
51
52
### Individual Marker Widget
53
54
Single marker widget with customizable appearance and interaction.
55
56
```python { .api }
57
class Marker:
58
"""
59
Individual marker widget.
60
61
Attributes:
62
- location (tuple): (latitude, longitude) tuple
63
- hover_text (str): Mouse hover text
64
- label (str): Text displayed inside marker
65
- display_info_box (bool): Whether to show info box on click
66
- info_box_content (str): Content for info box
67
"""
68
```
69
70
### Individual Symbol Widget
71
72
Single symbol widget for SVG-based markers with styling options.
73
74
```python { .api }
75
class Symbol:
76
"""
77
Individual symbol widget (SVG-based marker).
78
79
Attributes:
80
- location (tuple): (latitude, longitude) tuple
81
- fill_color (str): Symbol fill color
82
- fill_opacity (float): Fill opacity (0.0-1.0)
83
- stroke_color (str): Symbol outline color
84
- stroke_opacity (float): Stroke opacity (0.0-1.0)
85
- scale (float): Symbol size scaling factor
86
- hover_text (str): Mouse hover text
87
- info_box_content (str): Content for info box
88
- display_info_box (bool): Whether to show info box on click
89
"""
90
```
91
92
### Markers Container
93
94
Container widget for managing multiple markers or symbols.
95
96
```python { .api }
97
class Markers:
98
"""
99
Container for multiple markers/symbols.
100
101
Attributes:
102
- markers (list): List of Marker or Symbol instances
103
"""
104
```
105
106
### Marker Styling Options
107
108
Reusable styling configuration for markers.
109
110
```python { .api }
111
class MarkerOptions:
112
"""
113
Style options for markers.
114
115
Attributes:
116
- hover_text (str): Default hover text
117
- display_info_box (bool): Default info box behavior
118
- info_box_content (str): Default info box content
119
- label (str): Default marker label
120
"""
121
122
def to_marker(self, latitude, longitude):
123
"""
124
Create marker with these options.
125
126
Parameters:
127
- latitude (float): Marker latitude
128
- longitude (float): Marker longitude
129
130
Returns:
131
Marker: Configured marker instance
132
"""
133
```
134
135
## Usage Examples
136
137
### Basic Markers
138
139
```python
140
import gmaps
141
142
gmaps.configure(api_key="YOUR_API_KEY")
143
144
# Define locations
145
locations = [
146
(37.7749, -122.4194), # San Francisco
147
(37.7849, -122.4094), # Another point
148
(37.7649, -122.4294) # Third point
149
]
150
151
# Create marker layer
152
fig = gmaps.figure()
153
marker_layer = gmaps.marker_layer(locations)
154
fig.add_layer(marker_layer)
155
fig
156
```
157
158
### Markers with Labels and Info Boxes
159
160
```python
161
import gmaps
162
163
gmaps.configure(api_key="YOUR_API_KEY")
164
165
locations = [(37.7749, -122.4194), (37.7849, -122.4094)]
166
labels = ['A', 'B']
167
hover_texts = ['San Francisco City Hall', 'Golden Gate Park']
168
info_box_content = [
169
'San Francisco City Hall<br>Built in 1915',
170
'Golden Gate Park<br>1,017 acre urban park'
171
]
172
173
fig = gmaps.figure()
174
marker_layer = gmaps.marker_layer(
175
locations,
176
hover_text=hover_texts,
177
label=labels,
178
info_box_content=info_box_content,
179
display_info_box=True
180
)
181
fig.add_layer(marker_layer)
182
fig
183
```
184
185
### Styled Symbol Layer
186
187
```python
188
import gmaps
189
import numpy as np
190
191
gmaps.configure(api_key="YOUR_API_KEY")
192
193
# Generate sample data
194
np.random.seed(42)
195
num_points = 50
196
lat_center, lng_center = 37.7749, -122.4194
197
locations = np.random.normal(
198
[lat_center, lng_center],
199
[0.01, 0.01],
200
(num_points, 2)
201
)
202
203
# Create color-coded symbols based on data values
204
values = np.random.rand(num_points)
205
colors = ['red' if v > 0.5 else 'blue' for v in values]
206
scales = [2 + 3 * v for v in values] # Scale based on value
207
208
fig = gmaps.figure()
209
symbol_layer = gmaps.symbol_layer(
210
locations,
211
fill_color=colors,
212
fill_opacity=0.7,
213
stroke_color='black',
214
stroke_opacity=1.0,
215
scale=scales,
216
hover_text=[f'Value: {v:.2f}' for v in values]
217
)
218
fig.add_layer(symbol_layer)
219
fig
220
```
221
222
### Mixed Marker Types
223
224
```python
225
import gmaps
226
227
gmaps.configure(api_key="YOUR_API_KEY")
228
229
fig = gmaps.figure()
230
231
# Add traditional markers
232
marker_locations = [(37.7749, -122.4194), (37.7849, -122.4094)]
233
markers = gmaps.marker_layer(
234
marker_locations,
235
label=['City Hall', 'Park'],
236
hover_text=['Government Building', 'Recreation Area']
237
)
238
fig.add_layer(markers)
239
240
# Add colored symbols
241
symbol_locations = [(37.7649, -122.4294), (37.7949, -122.3994)]
242
symbols = gmaps.symbol_layer(
243
symbol_locations,
244
fill_color=['green', 'orange'],
245
scale=[4, 6],
246
hover_text=['Location C', 'Location D']
247
)
248
fig.add_layer(symbols)
249
250
fig
251
```
252
253
### Individual Marker Creation
254
255
```python
256
import gmaps
257
258
gmaps.configure(api_key="YOUR_API_KEY")
259
260
# Create individual markers
261
marker1 = gmaps.Marker(
262
location=(37.7749, -122.4194),
263
label='1',
264
hover_text='First location',
265
info_box_content='This is the first marker'
266
)
267
268
marker2 = gmaps.Symbol(
269
location=(37.7849, -122.4094),
270
fill_color='red',
271
scale=5,
272
hover_text='Second location'
273
)
274
275
# Create markers container
276
markers_layer = gmaps.Markers(markers=[marker1, marker2])
277
278
fig = gmaps.figure()
279
fig.add_layer(markers_layer)
280
fig
281
```