-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathusejson.py
54 lines (43 loc) · 1.52 KB
/
usejson.py
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
# vanishing.py
# Python that controls an ArcGIS webmap
# import some Brython libraries
import json
# import html
# import essential JS objects
main_map = JSObject(main_map)
esri = JSObject(esri)
SpatialReference = JSObject(wgs84)
Point = JSObject(ptmaker)
PictureMarkerSymbol = JSObject(picmaker)
Graphic = JSObject(grmaker)
# re-center map
main_map.centerAndZoom( [ -71.08017, 42.355626 ], 11 )
# define what to do with JSON returned
def on_complete(req):
if req.status==200 or req.status==0:
# returned successfully
mypts = json.loads( req.text )
for feature in mypts.features:
# can decide how to map these points using Python code
# for example:
# if feature.attributes.HANDICAP == "Yes":
# markerpng = "accessible.png"
# else:
# markerpng = "unaccessible.png"
#
if feature.attributes.Voter_Entrance is None:
JSObject(console).log( feature.attributes.NAME + " missing Voter_Entrance details" )
# test creating a point, adding a marker
pt = Point( [ feature.geometry.x.value , feature.geometry.y.value ], SpatialReference )
symbol = PictureMarkerSymbol( "marker.png", 22, 22 )
gr = Graphic( pt, symbol )
main_map.graphics.add(gr)
else:
# failed
alert( req.text )
# make an AJAX request
req = ajax()
req.on_complete = on_complete
#req.set_timeout(timeout, err_msg)
req.open('GET', 'samplejson.json?v=2', True)
req.send()