-
Notifications
You must be signed in to change notification settings - Fork 195
/
Copy pathexample.html
349 lines (285 loc) · 9.39 KB
/
example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Flask Google Maps Example</title>
{{"decoupled-map"|googlemap_js(37.4419, -122.1419, varname="decoupledmap", markers=[(37.4419, -122.1419)])}}
{{mymap.js}}
{{sndmap.js}}
{{trdmap.js}}
{{clustermap.js}}
{{movingmap.js}}
{{rectmap.js}}
{{circlemap.js}}
{{plinemap.js}}
{{pgonmap.js}}
{{collapsible.js}}
{{infoboxmap.js}}
{{clickmap.js}}
</head>
<body>
<h1>Flask Google Maps Example</h1>
Provide your Google Maps API Key to test it.
Get you APIKEY in <a href="https://console.developers.google.com/">https://console.developers.google.com/</a><br>
NOTE: You need to create an APIKEY and also activate Maps Javascript API for it.
<form action="." method="GET">
<input type="text" name="apikey" id="apikey"/><input type="submit" value="load"/>
</form>
<hr>
<h2> Template function centered, no marker </h2>
{{googlemap("simple-map", 37.4419, -122.1419, varname="simplemap")}}
<code>
<pre>
{% raw %}
{{googlemap("simple-map", 37.4419, -122.1419)}}
{% endraw %}
</pre>
</code>
<h1>Disabling controls</h1>
<h2> Template function centered, no marker, no controls </h2>
{{googlemap("no-controls-map",
37.4419, -122.1419,
varname="nocontrolsmap",
zoom_control=False,
maptype_control=False,
scale_control=False,
streetview_control=False,
rotate_control=False,
fullscreen_control=False)}}
<code>
<pre>
{% raw %}
{{
googlemap(
identifier="no-controls-map",
lat=37.4419,
lng=-122.1419,
zoom_control=False,
maptype_control=False,
scale_control=False,
streetview_control=False,
rotate_control=False,
fullscreen_control=False
)
}}
{% endraw %}
</pre>
</code>
<h2> Template filter decoupled with single marker </h2>
{{"decoupled-map"|googlemap_html(37.4419, -122.1419)}}
<code>
<pre>
{% raw %}
on the head:
{{"decoupled-map"|googlemap_js(37.4419, -122.1419, markers=[(37.4419, -122.1419)])}}
on the body:
{{"decoupled-map"|googlemap_html(37.4419, -122.1419)}}
{% endraw %}
</pre>
</code>
<h2> Template function with multiple markers </h2>
{% with map=googlemap_obj("another-map", 37.4419, -122.1419, varname="anothermap", markers=[(37.4419, -122.1419), (37.4300, -122.1400, "Hello!")]) %}
{{map.html}}
{{map.js}}
{% endwith %}
<code>
<pre>
{% raw %}
{% with map=googlemap_obj("another-map", 37.4419, -122.1419, markers=[(37.4419, -122.1419), (37.4300, -122.1400, "Hello")]) %}
{{map.html}}
{{map.js}}
{% endwith %}
{% endraw %}
</pre>
</code>
<h1> Clustered map in view</h1>
<h2>Cluster markes by proximity</h2>
{{clustermap.html}}
<code>
<pre>
{% raw %}
View:
from flask_googlemaps import Map
@app.route("/")
def mapview():
mymap = Map(
identifier="cluster-map",
lat=37.4419,
lng=-122.1419,
markers=[{'lat': 37.4419, 'lng': -122.1419}, {'lat': 37.4500, 'lng': -122.1419}, {'lat': 36.4419, 'lng': -120.1419}]
cluster=True,
cluster_gridsize=10
)
return render_template('clustermap.html', clustermap=clustermap)
Template:
in head:
{{clustermap.js}}
in body:
{{clustermap.html}}
{% endraw %}
</pre>
</code>
<h1> Moving Map</h1>
<h2>You can move markers dynamically and add new markers, refresh its position etc... </h2>
{{movingmap.html}}
{% for position in movingmarkers %}
<button onclick='movingmap_markers.map(function(mk){mk.setPosition({lat: {{ position.lat }}, lng:{{ position.lng }}})})'>Go to position {{ loop.index }} </button>
{% endfor %}
<br />
<button onclick='movingmap_markers.map(function(mk){mk.setMap(null)})'>Remove marker</button>
<button onclick='movingmap_markers.map(function(mk){mk.setMap(movingmap)})'>Restore marker</button>
<button onclick='new google.maps.Marker({title: "New Marker", position: {lat: 37.4640, lng: -122.1350}}).setMap(movingmap)'>Add New Marker Above</button>
<pre>
<button onclick='movingmap_markers.map(function(mk){mk.setPosition({lat: 37.44, lng:-122.135})})'>Go to position 1 </button>
<button onclick='movingmap_markers.map(function(mk){mk.setPosition({lat: 37.443, lng:-122.135})})'>Go to position 2 </button>
<button onclick='movingmap_markers.map(function(mk){mk.setPosition({lat: 37.445, lng:-122.135})})'>Go to position 3 </button>
<button onclick='movingmap_markers.map(function(mk){mk.setPosition({lat: 37.449, lng:-122.135})})'>Go to position 4 </button>
<button onclick='movingmap_markers.map(function(mk){mk.setMap(null)})'>Remove marker</button>
<button onclick='movingmap_markers.map(function(mk){mk.setMap(movingmap)})'>Restore marker</button>
<button onclick='onclick='new google.maps.Marker({title: "New Marker", position: {lat: 37.4640, lng: -122.1350}}).setMap(movingmap)''>Add new marker above</button>
</pre>
<h2> First map generated in view</h2>
{{mymap.html}}
<code>
<pre>
{% raw %}
View:
from flask_googlemaps import Map
@app.route("/")
def mapview():
mymap = Map(
identifier="view-side",
lat=37.4419,
lng=-122.1419,
markers=[(37.4419, -122.1419)]
)
return render_template('example.html', mymap=mymap)
Template:
in head:
{{mymap.js}}
in body:
{{mymap.html}}
{% endraw %}
</pre>
</code>
<h2> Second map generated in view</h2>
<h3> Example for different icons in multiple markers</h3>
<h4>The blue point is clickable!</h4>
{{sndmap.html}}
<code>
<pre>
{% raw %}
View:
from flask_googlemaps import Map, icons
@app.route("/")
def mapview():
sndmap = Map(
identifier="sndmap",
lat=37.4419,
lng=-122.1419,
markers={icons.dots.green: [(37.4419, -122.1419), (37.4500, -122.1350)],
'http://maps.google.com/mapfiles/ms/icons/blue-dot.png': [(37.4300, -122.1400, "Hello World")]}
)
return render_template('example.html', sndmap=sndmap)
Template:
in head:
{{sndmap.js}}
in body:
{{sndmap.html}}
{% endraw %}
</pre>
</code>
<h2> 3rd map generated in view</h2>
<h3> Example for multiple markers with infoboxes</h3>
<h4>Click in markers to see it in action!</h4>
<h4>Click in the YELLOW marker to see HTML rendered</h4>
{{trdmap.html}}
<code>
<pre>
{% raw %}
View:
from flask_googlemaps import Map, icons
@app.route("/")
def mapview():
trdmap = Map(
identifier="trdmap",
lat=37.4419,
lng=-122.1419,
markers=[
{
'icon': icons.alpha.B,
'lat': 37.4419,
'lng': -122.1419,
'infobox': "Hello I am < b style='color:green;'>B< / b >!"
},
{
'icon': icons.dots.blue,
'lat': 37.4300,
'lng': -122.1400,
'infobox': "Hello I am < b style='color:blue;'>BLUE< / b >!"
},
{
'icon': icons.dots.yellow,
'lat': 37.4500,
'lng': -122.1350,
'infobox': (
"Hello I am < b style='color:#ffcc00;'> YELLOW < / b >!"
"< h2 >It is HTML title< / h2 >"
"< img src=' //placehold.it/50' >"
"< br >Images allowed!"
)
}
]
)
return render_template('example.html', trdmap=trdmap)
Template:
in head:
{{trdmap.js}}
in body:
{{trdmap.html}}
{% endraw %}
</pre>
</code>
<h2>Map with rectangle example</h2>
{{ rectmap.html }}
<h2>Map with circle example</h2>
{{ circlemap.html }}
<h2>Map with polyline example</h2>
{{ plinemap.html }}
<h2>Map with polygons examples</h2>
{{ pgonmap.html }}
<h2 style="display:inline-block;">Collapsible map example</h2>
<button id="collapsible_collapse">Show map</button>
{{ collapsible.html }}
<code>
<pre>
{% raw %}
View:
from flask_googlemaps import Map, icons
@app.route("/")
def mapview():
collapsible = Map(
identifier="collapsible",
varname="collapsible",
lat=60.000025,
lng=30.288809,
zoom = 13,
collapsible = True
)
return render_template('example.html', collapsible=collapsible)
Template:
in head:
{{collapsible.js}}
in body:
<button id="collapsible_collapse">Show map</button>
{{collapsible.html}}
{% endraw %}
</pre>
</code>
<h2>Infoboxes for map shapes</h2>
{{infoboxmap.html}}
<h2>LatLon from click to flask and back:</h2>
{{clickmap.html}}
</body>
</html>