-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesri2geojson2leaflethtml.py
81 lines (73 loc) · 2.33 KB
/
esri2geojson2leaflethtml.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
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
import os
import json
import webbrowser
featureServerURL = 'https://services1.arcgis.com/k3vhq11XkBNeeOfM/ArcGIS/rest/services/CityBoundary/FeatureServer/0'
datasetName = 'Richmond City Boundary'
mapAttribution = '<a href="' + featureServerURL + '">' + datasetName + ' Dataset</a>'
mapCoordinates = '[37.533333, -77.466667]'
mapName = 'richmond-city-boundary'
outputMapName = datasetName + ' leaflet html map done!'
mapGeoJSON = mapName + '.geojson'
mapGeoJSONPath = '"' + mapGeoJSON + '"'
mapHTML = mapName + '.html'
localPath = 'file:///Users/j.albertbowden/Desktop/github/esri2geojson2leaflethtml/'
mapHTMLName = localPath + mapHTML
esriCall = 'esri2geojson ' + featureServerURL + ' ' + mapGeoJSON
print('esri2geojson call!')
os.system(esriCall)
print('geojson output complete!')
with open(mapGeoJSON) as jsonFile:
dataJSON = json.load(jsonFile)
dataJSON = json.dumps(dataJSON)
dataJSON = 'var cityBoundary = ' + dataJSON
# http://cdn.leafletjs.com/leaflet/v1.5.1/leaflet.zip
htmlScriptLeaflet = """<script>
""" + dataJSON + """
var makeMap = function(){
var map = L.map('map').setView(""" + mapCoordinates + """, 12);
mapCitation = '<a href="http://openstreetmap.org">OpenStreetMap</a>';
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© ' + mapCitation + ' Contributors | """ + mapAttribution + """',
maxZoom: 18,
}).addTo(map);
var boundaryStyle = {
color: "#222",
weight: 1,
opacity: 1,
fillOpacity: 0.15,
fillColor: "#000"
};
var myStyle = {
"color": "#fff",
"weight": 5,
"opacity": 0.65
};
var geoJsonLayer = L.geoJson(cityBoundary, {
color: "#222",
weight: 3.25,
opacity: 1,
fillOpacity: 0.15,
fillColor: "#000"
}).addTo(map);
};
makeMap();
</script>\n"""
f = open(mapHTML,'w')
message = """<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8" />
<title>""" + datasetName + """ Leaflet Map</title>
<link type="text/css" rel="stylesheet" href="leaflet/leaflet.css" />
<link type="text/css" rel="stylesheet" href="map.css" />
</head>
<body>
<h1>""" + datasetName + """</h1>
<div id="map"></div>
</body>
<script src="leaflet/leaflet.js"></script>\n"""
message = message + htmlScriptLeaflet + '</html>'
f.write(message)
f.close()
print(outputMapName)
webbrowser.open(mapHTMLName, new=2) # open in new tab