@@ -121,7 +121,7 @@ def draw_model(model=None, nodes=None, conduits=None, parcels=None, title=None,
121121 return img
122122
123123
124- def create_map (model = None , filename = None , basemap = None , auto_open = False ):
124+ def create_map (model = None , filename = None , basemap = None , auto_open = False , links_geojson = False , nodes_geojson = False ):
125125 """
126126 Export model as a geojson object and create an HTML map.
127127
@@ -135,6 +135,10 @@ def create_map(model=None, filename=None, basemap=None, auto_open=False):
135135 The path to the basemap file. If None, a default basemap path will be used.
136136 auto_open : bool, optional
137137 If True, the generated HTML file will be automatically opened in a web browser.
138+ links_geojson : str, optional
139+ A custon links GeoJSON string for writing to the HTML file. If none the default {geojson.dumps(model.links.geojson)} is used
140+ nodes_geojson : str, optional
141+ A custon nodes GeoJSON string for writing to the HTML file. If none the default {geojson.dumps(model.nodes.geojson)} is used
138142
139143 Returns
140144 -------
@@ -167,20 +171,24 @@ def create_map(model=None, filename=None, basemap=None, auto_open=False):
167171 # get map centroid and bbox
168172 c , bbox = centroid_and_bbox_from_coords (model .inp .coordinates )
169173
170- # start writing that thing
171174 with open (basemap , 'r' ) as bm :
172175 with open (filename , 'w' ) as newmap :
173176 for line in bm :
174177 if 'INSERT GEOJSON HERE' in line :
175- newmap .write (f'conduits = { geojson .dumps (model .links .geojson )} \n ' )
176- newmap .write (f'nodes = { geojson .dumps (model .nodes .geojson )} \n ' )
178+ if links_geojson is None :
179+ newmap .write (f'conduits = { geojson .dumps (model .links .geojson )} \n ' )
180+ else :
181+ newmap .write (f'conduits = { links_geojson } \n ' )
182+ if nodes_geojson is None :
183+ newmap .write (f'nodes = { geojson .dumps (model .nodes .geojson )} \n ' )
184+ else :
185+ newmap .write (f'nodes = { nodes_geojson } \n ' )
177186 elif '// INSERT MAP CENTER HERE' in line :
178187 newmap .write ('\t center:[{}, {}],\n ' .format (c [0 ], c [1 ]))
179188 elif '// INSERT BBOX HERE' in line and bbox is not None :
180189 newmap .write (f'\t map.fitBounds([[{ bbox [0 ]} , { bbox [1 ]} ], [{ bbox [2 ]} , { bbox [3 ]} ]]);\n ' )
181190 else :
182191 newmap .write (line )
183-
184192 if return_html :
185193 with open (filename , 'r' ) as f :
186194 return f .read ()
0 commit comments