File size: 830 Bytes
6f10462
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import folium
import json
import os

def generate_map(geojson_file, output_file):
    # Load GeoJSON data
    with open(geojson_file) as f:
        geojson_data = json.load(f)

    # Create a base map
    m = folium.Map(location=[-7.5, 112.5], zoom_start=7)

    # Add GeoJSON overlay
    folium.GeoJson(
        geojson_data,
        name='geojson',
        tooltip=folium.GeoJsonTooltip(fields=['name'], aliases=['Region:'])
    ).add_to(m)

    # Add layer control
    folium.LayerControl().add_to(m)

    # Save the map to an HTML file
    m.save(output_file)
    print(f'Map has been generated and saved to {output_file}')

if __name__ == '__main__':
    geojson_path = os.path.join('data', 'geojson', 'jatim.geojson')
    output_path = os.path.join('app', 'templates', 'map.html')
    generate_map(geojson_path, output_path)