def index(): fig5=Figure(height=550,width=750) m5=folium.Map(location=[-6.920817, 107.604100],tiles='cartodbpositron',zoom_start=17) fig5.add_child(m5) folium.LayerControl().add_to(m5) m5.save('templates/map.html') return render_template('GoogleMaps.html')
def __init__(self, location=None, layout='horizontal', **kwargs): super(DualMap, self).__init__() for key in ('width', 'height', 'left', 'top', 'position'): assert key not in kwargs, ('Argument {} cannot be used with ' 'DualMap.'.format(key)) if layout not in ('horizontal', 'vertical'): raise ValueError('Undefined option for argument `layout`: {}. ' 'Use either \'horizontal\' or \'vertical\'.' .format(layout)) width = '50%' if layout == 'horizontal' else '100%' height = '100%' if layout == 'horizontal' else '50%' self.m1 = Map(location=location, width=width, height=height, left='0%', top='0%', position='absolute', **kwargs) self.m2 = Map(location=location, width=width, height=height, left='50%' if layout == 'horizontal' else '0%', top='0%' if layout == 'horizontal' else '50%', position='absolute', **kwargs) figure = Figure() figure.add_child(self.m1) figure.add_child(self.m2) # Important: add self to Figure last. figure.add_child(self) self.children_for_m2 = [] self.children_for_m2_copied = [] # list with ids
def visualisation_sections( list_data: List[Tuple], map_filename: str, ) -> None: """Save the HTML code of the map visualisation. Every tuple correspond to a different point. :param list_data: list of tuples which contains in position 0: coordinates of the point as a tuple (latitude,longitude), in position 1: section of the road related with the point (outpput of find_optimal) with the type List['str','str',tuple,tuple] as the output of get_road_section, in position 2: list of all the node of a street (output of get_ways_from_node). :param map_filename: name of the map HTML code file. return None: the function just save the code with the correct path. """ figure = Figure(height=550, width=750) map_display = folium.Map(location=[48.896205, 2.260466], tiles='cartodbpositron', zoom_start=14) figure.add_child(map_display) colors = [ 'red', 'blue', 'green', 'purple', 'orange', 'darkred', 'lightred', 'beige', 'darkblue', 'darkgreen', 'cadetblue', 'darkpurple', 'white', 'pink', 'lightblue', 'lightgreen', 'gray', 'black', 'lightgray' ] color_index = 0 for data in list_data: latitude, longitude = data[0] section = data[1] list_node_street = data[2] begin_coordinates = section[2] end_coordinates = section[3] coordinates = [node[1] for node in list_node_street] coordinates = coordinates[coordinates.index(begin_coordinates): coordinates.index(end_coordinates) + 1] feature_group = folium.FeatureGroup( f"Tronçon Point ({latitude}, {longitude})") folium.vector_layers.PolyLine( coordinates, popup=f'<b>Tronçon Point ({latitude}, {longitude})</b>', tooltip=f'Tronçon Point ({latitude}, {longitude})', color=colors[color_index % len(colors)], weight=10).add_to(feature_group) folium.Marker( location=[latitude, longitude], popup='Custom Marker 1', tooltip= f'<strong>Point d\'interet ({latitude}, {longitude}) </strong>', icon=folium.Icon(color=colors[color_index % len(colors)], icon='none')).add_to(map_display) color_index += 1 feature_group.add_to(map_display) folium.LayerControl().add_to(map_display) map_display.save(map_filename) return None
def __init__(self, location=None, width='100%', height='100%', left='0%', top='0%', position='relative', tiles='OpenStreetMap', API_key=None, max_zoom=18, min_zoom=0, max_native_zoom=None, zoom_start=10, world_copy_jump=False, no_wrap=False, attr=None, min_lat=-90, max_lat=90, min_lon=-180, max_lon=180, max_bounds=False, detect_retina=False, crs='EPSG3857', control_scale=False, prefer_canvas=False, no_touch=False, disable_3d=False, subdomains='abc', png_enabled=False, zoom_control=True): super(Map, self).__init__() self._name = 'Map' self._env = ENV # Undocumented for now b/c this will be subject to a re-factor soon. self._png_image = None self.png_enabled = png_enabled if location is None: # If location is not passed we center and zoom out. self.location = [0, 0] self.zoom_start = 1 else: self.location = _validate_location(location) self.zoom_start = zoom_start Figure().add_child(self) # Map Size Parameters. self.width = _parse_size(width) self.height = _parse_size(height) self.left = _parse_size(left) self.top = _parse_size(top) self.position = position self.min_lat = min_lat self.max_lat = max_lat self.min_lon = min_lon self.max_lon = max_lon self.max_bounds = max_bounds self.no_wrap = no_wrap self.world_copy_jump = world_copy_jump self.crs = crs self.control_scale = control_scale self.zoom_control = zoom_control self.global_switches = GlobalSwitches( prefer_canvas, no_touch, disable_3d ) self.objects_to_stay_in_front = [] if tiles: self.add_tile_layer( tiles=tiles, min_zoom=min_zoom, max_zoom=max_zoom, max_native_zoom=max_native_zoom, no_wrap=no_wrap, attr=attr, API_key=API_key, detect_retina=detect_retina, subdomains=subdomains )
def _repr_html_(self, **kwargs): """Displays the HTML Map in a Jupyter notebook.""" if self._parent is None: self.add_to(Figure()) out = self._parent._repr_html_(**kwargs) self._parent = None else: out = self._parent._repr_html_(**kwargs) return out
def __init__(self, location=None, layout='horizontal', **kwargs): super(DualMap, self).__init__() for key in ('width', 'height', 'left', 'top', 'position'): assert key not in kwargs, ('Argument {} cannot be used with ' 'DualMap.'.format(key)) if layout not in ('horizontal', 'vertical'): raise ValueError( 'Undefined option for argument `layout`: {}. ' 'Use either \'horizontal\' or \'vertical\'.'.format(layout)) width = '50%' if layout == 'horizontal' else '100%' height = '100%' if layout == 'horizontal' else '50%' self.m1 = Map(location=location, width=width, height=height, left='0%', top='0%', position='absolute', **kwargs) self.m2 = Map(location=location, width=width, height=height, left='50%' if layout == 'horizontal' else '0%', top='0%' if layout == 'horizontal' else '50%', position='absolute', **kwargs) figure = Figure() figure.add_child(self.m1) figure.add_child(self.m2) # Important: add self to Figure last. figure.add_child(self) self.children_for_m2 = [] self.children_for_m2_copied = [] # list with ids
def map(): address = input() geolocator = Nominatim(user_agent="Pavan Sai") location = geolocator.geocode(address) a = location.latitude b = location.longitude print(a, b) m = folium.Map(location=[a, b], tiles='cartodbdark_matter', zoom_start=16) fig = Figure(width=550, height=350).add_child(m) folium.Marker(location=[a, b], popup='Nakkapalli city', tooltip='Click here to see Popup').add_to(m) m
def render_nodes(node, parent): mf = Figure() mf._name = parent._name mf._id = parent._id mf._template = Template('{{this.script.render(**kwargs)}}\n') node.add_to(mf) html = mf.render() html = "".join([s for s in html.splitlines(True) if s.strip("\r\n")]) return html
def plot_plotly(chart, width='100%', height=525): # produce the html in Ipython compatible format plot_html, plotdivid, width, height = _plot_html(chart, {'showLink': False}, True, width, height, True) # define the plotly js library source url head = '<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>' # extract the div element from the ipython html div = plot_html[0:plot_html.index('<script')] # extract the script element from the ipython html script = plot_html[plot_html.index('Plotly.newPlot'):plot_html.index('});</script>')] + ';' # combine div and script to build the body contents body = '<body>{div}<script>{script}</script></body>'.format(div=div, script=script) # instantiate a figure object figure = Figure() # add the head figure.header.add_child(Element(head)) # add the body figure.html.add_child(Element(body)) return figure
def __init__(self, location=None, width='100%', height='100%', left='0%', top='0%', position='relative', tiles='OpenStreetMap', attr=None, min_zoom=0, max_zoom=18, zoom_start=10, min_lat=-90, max_lat=90, min_lon=-180, max_lon=180, max_bounds=False, crs='EPSG3857', control_scale=False, prefer_canvas=False, no_touch=False, disable_3d=False, png_enabled=False, zoom_control=True, **kwargs): super(Map, self).__init__() self._name = 'Map' self._env = ENV # Undocumented for now b/c this will be subject to a re-factor soon. self._png_image = None self.png_enabled = png_enabled if location is None: # If location is not passed we center and zoom out. self.location = [0, 0] zoom_start = 1 else: self.location = validate_location(location) Figure().add_child(self) # Map Size Parameters. self.width = _parse_size(width) self.height = _parse_size(height) self.left = _parse_size(left) self.top = _parse_size(top) self.position = position max_bounds_array = [[min_lat, min_lon], [max_lat, max_lon]] \ if max_bounds else None self.crs = crs self.control_scale = control_scale self.options = parse_options(max_bounds=max_bounds_array, zoom=zoom_start, zoom_control=zoom_control, prefer_canvas=prefer_canvas, **kwargs) self.global_switches = GlobalSwitches(no_touch, disable_3d) self.objects_to_stay_in_front = [] if tiles: tile_layer = TileLayer(tiles=tiles, attr=attr, min_zoom=min_zoom, max_zoom=max_zoom) self.add_child(tile_layer, name=tile_layer.tile_name)
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.''' import streamlit as st from streamlit_folium import folium_static import folium import pandas as pd from branca.element import Figure #create a title on web st.markdown( "<h1 style='text-align: center; color: black;'>ASTROANALYZER </h1>", unsafe_allow_html=True) #create a base map fig3 = Figure(width=550, height=350) m3 = folium.Map( location=[-8.907970, 33.433200], zoom_start=2, tiles= 'https://api.mapbox.com/v4/mapbox.mapbox-incidents-v1/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoiZS1rIiwiYSI6ImNrbWwycnY1aTA5OXQycXJ6b3piZmRjdjAifQ.4sci1n22WrZvWaQL_99mrA', attr='Mapbox') fig3.add_child(m3) st.sidebar.title('Map Legend:') st.sidebar.header('High Mass Binaries - Red') st.sidebar.header('Low Mass Binaries - Blue') st.sidebar.write('') st.sidebar.title('Radius for plotted dots:') #radius for plotted points
def __init__(self, location=None, width='100%', height='100%', left="0%", top="0%", position='relative', tiles='OpenStreetMap', API_key=None, max_zoom=18, min_zoom=1, zoom_start=10, continuous_world=False, world_copy_jump=False, no_wrap=False, attr=None, min_lat=-90, max_lat=90, min_lon=-180, max_lon=180, max_bounds=True, detect_retina=False, crs='EPSG3857', control_scale=False, prefer_canvas=False, no_touch=False, disable_3d=False): super(LegacyMap, self).__init__() self._name = 'Map' self._env = ENV if not location: # If location is not passed we center and ignore zoom. self.location = [0, 0] self.zoom_start = min_zoom else: self.location = location self.zoom_start = zoom_start Figure().add_child(self) # Map Size Parameters. self.width = _parse_size(width) self.height = _parse_size(height) self.left = _parse_size(left) self.top = _parse_size(top) self.position = position self.min_lat = min_lat self.max_lat = max_lat self.min_lon = min_lon self.max_lon = max_lon self.max_bounds = max_bounds self.continuous_world = continuous_world self.no_wrap = no_wrap self.world_copy_jump = world_copy_jump self.crs = crs self.control_scale = control_scale self.global_switches = GlobalSwitches(prefer_canvas, no_touch, disable_3d) if tiles: self.add_tile_layer(tiles=tiles, min_zoom=min_zoom, max_zoom=max_zoom, continuous_world=continuous_world, no_wrap=no_wrap, attr=attr, API_key=API_key, detect_retina=detect_retina) self._template = Template(u""" {% macro header(this, kwargs) %} <style> #{{this.get_name()}} { position : {{this.position}}; width : {{this.width[0]}}{{this.width[1]}}; height: {{this.height[0]}}{{this.height[1]}}; left: {{this.left[0]}}{{this.left[1]}}; top: {{this.top[0]}}{{this.top[1]}}; } </style> {% endmacro %} {% macro html(this, kwargs) %} <div class="folium-map" id="{{this.get_name()}}" ></div> {% endmacro %} {% macro script(this, kwargs) %} {% if this.max_bounds %} var southWest = L.latLng({{ this.min_lat }}, {{ this.min_lon }}); var northEast = L.latLng({{ this.max_lat }}, {{ this.max_lon }}); var bounds = L.latLngBounds(southWest, northEast); {% else %} var bounds = null; {% endif %} var {{this.get_name()}} = L.map( '{{this.get_name()}}', {center: [{{this.location[0]}},{{this.location[1]}}], zoom: {{this.zoom_start}}, maxBounds: bounds, layers: [], worldCopyJump: {{this.world_copy_jump.__str__().lower()}}, crs: L.CRS.{{this.crs}} }); {% if this.control_scale %}L.control.scale().addTo({{this.get_name()}});{% endif %} {% endmacro %} """) # noqa
from flask import Flask import folium from branca.element import Figure fig = Figure(width=550, height=350) app = Flask(__name__) @app.route('/') def index(): start_coords = (51.389167, 30.099444) #Coordiniates of Chernobyl folium_map = folium.Map(width=550, height=350, location=start_coords, zoom_start=11, min_zoom=8, max_zoom=14) fig.add_child(folium_map) folium.TileLayer('Stamen Terrain').add_to(folium_map) folium.TileLayer('Stamen Toner').add_to(folium_map) folium.TileLayer('Stamen Water Color').add_to(folium_map) folium.TileLayer('cartodbpositron').add_to(folium_map) folium.TileLayer('cartodbdark_matter').add_to(folium_map) folium.LayerControl().add_to(folium_map) return fig._repr_html_()
stationsInfo = json.load(f) with open(path + '/data/paramsInfo.json', 'r') as f: paramsInfo = json.load(f)[param] #%% points = [{ 'name': stationsInfo[ID]['name'], 'coords': (stationsInfo[ID]['lat'], stationsInfo[ID]['lon']), 'country': stationsInfo[ID]['country'] } for ID in stationsInfo.keys() & paramsInfo['stations']] centroid = (52.23, 17.01) # lat / lon #%% fig = Figure(width='80%', height='80%') basemap = folium.Map(location=centroid, control_scale=True, zoom_start=5) fig.add_child(basemap) folium.TileLayer('cartodbpositron').add_to(basemap) folium.TileLayer('Stamen Toner').add_to(basemap) folium.TileLayer('Stamen Terrain').add_to(basemap) icosGroup = folium.FeatureGroup(name="ICOS").add_to(basemap) for point in points: icon = folium.Icon( color='white', icon='train', icon_color='red',
def return_map(self,mypandas,which_data = None,width_height = None, date = 'last'): """Create a Folium map from a pandas input Keyword arguments ----------------- babepandas : pandas consided which_data: variable from pandas data. If pandas is produced from cocoa get_stat method then 'diff' and 'cumul' can be also used width_height : as a list of width and height of the histo, default [500,400] date : - default 'last' Value at the last date (from database point of view) and for all the location defined in the pandas will be computed - date Value at date (from database point of view) and for all the location defined in the pandas will be computed """ if width_height: plot_width = width_height[0] plot_height = width_height[1] else : plot_width = width_height_default[0] plot_height = width_height_default[1] label , what ='','' if type(which_data) is None.__class__: which_data = mypandas.columns[2] label = which_data else: which_data = which_data if which_data == 'diff': what = 'day to day diffence' else: what = 'cumulative sum' label = mypandas.columns[2] + ' (' + what + ')' if date == "last" : when = mypandas['date'].max() else: when = date jhu_stuff = mypandas.loc[(mypandas.date == when)] a = self.info.add_field(field=['geometry'],input=jhu_stuff ,geofield='location') data=gpd.GeoDataFrame(self.info.add_field(input=a,geofield='location',\ field=['country_name']),crs="EPSG:4326") data = data.loc[data.geometry != None] data['geoid'] = data.index.astype(str) data=data[['geoid','location',which_data,'geometry']] data[which_data] = round(data[which_data]) data = data.set_index('geoid') centroid=unary_union(data.geometry).centroid min_col,max_col=CocoDisplay.min_max_range(0,max(data[which_data])) colormap = branca.colormap.linear.RdPu_09.scale(min_col,max_col) #colormap = (colormap.to_step(n=len(data[which_data]),method='log')) colormap.caption = 'Covid-19 cases : ' + label fig = Figure(width=plot_width, height=plot_height) mapa = folium.Map(location=[centroid.y, centroid.x], zoom_start=2) #tiles='https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}.png', #attr = "IGN") fig.add_child(mapa) folium.GeoJson( data, style_function=lambda x: { #'fillColor': '#ffffffff' if x['properties'][which_data] < max(data[which_data]/1000.) else 'fillColor':colormap(x['properties'][which_data]), 'fillOpacity': 0.8, 'color' : None, }, name="Cases", highlight_function=lambda x: {'weight':2, 'color':'green'}, tooltip=folium.GeoJsonTooltip(fields=['location',which_data], aliases = ['country','totcases'], labels=False), ).add_to(mapa) colormap.add_to(mapa) #folium.LayerControl(autoZIndex=False, collapsed=False).add_to(mapa) return mapa
def make_choropleth_map(df, plot_col, popup_dict, tooltip_dict, colorscale, fig_width, fig_height, zoom=6, centroid=[36.2, -119.1]): fig = Figure(width=fig_width, height=fig_height) m = folium.Map(location=centroid, tiles='cartodbpositron', zoom_start=zoom, width=fig_width, height=fig_height) popup = GeoJsonPopup( fields=list(popup_dict.keys()), aliases=list(popup_dict.values()), localize=True, labels=True, style=f"background-color: light_gray;", max_width=100, ) tooltip = GeoJsonTooltip( fields=list(tooltip_dict.keys()), aliases=list(tooltip_dict.values()), # localize = True sets the commas for numbers, but zipcode should be displayed as string #localize=True, sticky=False, labels=True, style=f""" background-color: "gray"; border: 0px #FFFFFF; border-radius: 0px; box-shadow: 0px; font-size: 12px; """, max_width=300, ) #https://medium.com/analytics-vidhya/create-and-visualize-choropleth-map-with-folium-269d3fd12fa0 g = folium.GeoJson( df, style_function=lambda x: { "fillColor": colorscale(x["properties"][plot_col]) if x["properties"][plot_col] is not None else f"gray", "color": "#FFFFFF", "fillOpacity": 0.8, "weight": 0.2, }, tooltip=tooltip, popup=popup, ).add_to(m) fig.add_child(m) return fig
import folium from branca.element import Figure m = folium.Map(location=[23.76327225, 90.3598240238032], tiles='cartodbpositron', zoom_start=11) m1 = folium.Map(location=[28.644800, 77.216721], tiles='cartodbpositron', zoom_start=14) fig = Figure(width=550, height=350) fig1 = Figure(height=550, width=750) fig.add_child(m) fig1.add_child(m1) folium.Marker(location=[23.76327225, 90.3598240238032], popup='Current', tooltip='<strong>Current</strong>', icon=folium.Icon(color='red', icon='none')).add_to(m) folium.Marker(location=[22.5726, 88.3639], popup='Destination', tooltip='<strong>Destination</strong>', icon=folium.Icon(color='green', prefix='glyphicon', icon='off')).add_to(m) m.save("user2destination.html") coords_1 = [[28.65685, 77.21899], [28.65699, 77.21898], [28.65699, 77.21898], [28.65702, 77.21875], [28.65702, 77.21875], [28.6547, 77.21902], [28.65308, 77.21921], [28.65286, 77.21926], [28.65255, 77.21938], [28.65227, 77.21954], [28.65152, 77.22005], [28.64655, 77.22346], [28.64643, 77.22354], [28.64635, 77.22357], [28.64623, 77.2236], [28.64616, 77.22363], [28.64612, 77.22364], [28.64557, 77.22364], [28.64525, 77.22365], [28.64525, 77.22365], [28.64517, 77.22366], [28.64515, 77.22367], [28.64512, 77.22367], [28.64504, 77.22369], [28.64493, 77.22371], [28.64483, 77.22373], [28.64462, 77.22377],
print('Direcciones de IP inválidas, intente de nuevo.') elif int(inputs[0]) == 9: ## BONO REQ 8 ## # ABS_PATH = repr(os.path.dirname(os.path.abspath(__file__))) if resultadoREQ1[0] is not False: """ REQ 1 """ """ {'first': {'info': 'Bogota-Colombia', 'next': {'info': '4315-South America-1 (SAm-1)', 'next': {'info': '5800-South America-1 (SAm-1)', 'next': {'info': 'Santiago-Chile', 'next': {'info': '16012-Segunda FOS Canal de Chacao', 'next': {'info': 'Beijing-China', 'next': {'info': '6007-Asia Africa Europe-1 (AAE-1)', 'next': {'info': '5723-Asia Africa Europe-1 (AAE-1)', 'next': {'info': '5723-MedNautilus Submarine System', 'next': {'info': '3905-MedNautilus Submarine System', 'next': {'info': '3221-MedNautilus Submarine System', 'next': {'info': '3221-KAFOS', 'next': {'info': '6059-KAFOS', 'next': {'info': '5356-KAFOS', 'next': None}}}}}}}}}}}}}}, 'last': {'info': '5356-KAFOS', 'next': None}, 'size': 14, 'key': None, 'type': 'SINGLE_LINKED', 'cmpfunction': <function defaultfunction at 0x000001C1A4847B88>} """ baseReq1 = Figure(width=750, height=550) mapaReq1 = folium.Map(location=[0, 0], tiles='cartodbpositron', zoom_start=3) grupoCaminos1 = folium.FeatureGroup("Req 1") coordREQ1 = [] for vertice in lt.iterator(pathREQ1): if vertice[0] not in "1234567890": pais = vertice.split("-")[1] paisValue = mp.get(analyzer['countries'], pais)['value']
def test(): firstloc = request.form['floc'] endloc = request.form['eloc'] pilihankota = int(request.form.get("comp_select")) adjMatrix = [[]] listNode = [] listCoor = [] listJalan = [] if (request.form.get("pilihkota")): if (pilihankota == 2) : adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("ITB.txt") elif (pilihankota == 3) : adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("Alunalun.txt") elif (pilihankota == 4) : adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("buahbatu.txt") elif (pilihankota == 5) : adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("Kebumen.txt") elif (pilihankota == 6) : adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("graf.txt") elif (pilihankota == 7) : adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("tayu.txt") elif (pilihankota == 8) : adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("blitar.txt") elif (pilihankota == 9) : adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("monas.txt") if request.method == 'POST': if (pilihankota == 1): fig5=Figure(height=550,width=750) m5=folium.Map(location=[-6.920817, 107.604100],tiles='cartodbpositron',zoom_start=17) fig5.add_child(m5) folium.LayerControl().add_to(m5) m5.save('templates/map.html') flash('Masukkan Map Kota Anda', "info") return render_template('GoogleMaps.html') fig5=Figure(height=550,width=750) middle = main.middlePoint(listCoor) m5=folium.Map(location=[middle[0],middle[1]],tiles='cartodbpositron',zoom_start=17) fig5.add_child(m5) f1=folium.FeatureGroup("Jalan Asli") for i in range(len(listCoor)-1): for j in range(i+1, len(listCoor)): if (adjMatrix[i][j] != 0): place1 = [[listCoor[i][0],listCoor[i][1]],[listCoor[j][0],listCoor[j][1]]] line_1=folium.vector_layers.PolyLine(place1,color='red',weight=10).add_to(f1) #bikin node for i in range(len(listCoor)): folium.Marker(listCoor[i],popup=listNode[i],tooltip='<strong>Click here to see Popup</strong>',icon=folium.Icon(color='blue',icon='none')).add_to(m5) f1.add_to(m5) folium.LayerControl().add_to(m5) m5.save('templates/map.html') return render_template('GoogleMaps.html', comp_select = str(pilihankota)) if (request.form.get("search")): if (pilihankota == 2) : adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("ITB.txt") path, isNodeFound, isPathFound = main.main(adjMatrix,listNode,listCoor,firstloc,endloc) elif (pilihankota == 3) : adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("Alunalun.txt") path, isNodeFound, isPathFound = main.main(adjMatrix,listNode,listCoor,firstloc,endloc) elif (pilihankota == 4) : adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("buahbatu.txt") path, isNodeFound, isPathFound = main.main(adjMatrix,listNode,listCoor,firstloc,endloc) elif (pilihankota == 5) : adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("Kebumen.txt") path, isNodeFound, isPathFound = main.main(adjMatrix,listNode,listCoor,firstloc,endloc) elif (pilihankota == 6) : adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("graf.txt") path, isNodeFound, isPathFound = main.main(adjMatrix,listNode,listCoor,firstloc,endloc) elif (pilihankota == 7) : adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("tayu.txt") path, isNodeFound, isPathFound = main.main(adjMatrix,listNode,listCoor,firstloc,endloc) elif (pilihankota == 8) : adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("blitar.txt") path, isNodeFound, isPathFound = main.main(adjMatrix,listNode,listCoor,firstloc,endloc) elif (pilihankota == 9) : adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("monas.txt") path, isNodeFound, isPathFound = main.main(adjMatrix,listNode,listCoor,firstloc,endloc) if request.method == 'POST': if (pilihankota == 1): fig5=Figure(height=550,width=750) m5=folium.Map(location=[-6.920817, 107.604100],tiles='cartodbpositron',zoom_start=17) fig5.add_child(m5) folium.LayerControl().add_to(m5) m5.save('templates/map.html') flash('Masukkan Map Kota Anda') return render_template('GoogleMaps.html') elif (not isNodeFound): #cek flag nodefound fig5=Figure(height=550,width=750) middle = main.middlePoint(listCoor) m5=folium.Map(location=[middle[0], middle[1]],tiles='cartodbpositron',zoom_start=17) fig5.add_child(m5) f1=folium.FeatureGroup("Jalan Asli") for i in range(len(listCoor)-1): for j in range(i+1, len(listCoor)): if (adjMatrix[i][j] != 0): place1 = [[listCoor[i][0],listCoor[i][1]],[listCoor[j][0],listCoor[j][1]]] line_1=folium.vector_layers.PolyLine(place1,color='red',weight=10).add_to(f1) for i in range(len(listCoor)): folium.Marker(listCoor[i],popup=listNode[i],tooltip='<strong>Click here to see Popup</strong>',icon=folium.Icon(color='blue',icon='none')).add_to(m5) f1.add_to(m5) folium.LayerControl().add_to(m5) m5.save('templates/map.html') flash('Tidak ditemukan lokasi yang sesuai') return render_template('GoogleMaps.html', comp_select = str(pilihankota)) elif (not isPathFound): fig5=Figure(height=550,width=750) middle = main.middlePoint(listCoor) m5=folium.Map(location=[middle[0], middle[1]],tiles='cartodbpositron',zoom_start=17) fig5.add_child(m5) f1=folium.FeatureGroup("Jalan Asli") for i in range(len(listCoor)-1): for j in range(i+1, len(listCoor)): if (adjMatrix[i][j] != 0): place1 = [[listCoor[i][0],listCoor[i][1]],[listCoor[j][0],listCoor[j][1]]] line_1=folium.vector_layers.PolyLine(place1,color='red',weight=10).add_to(f1) for i in range(len(listCoor)): folium.Marker(listCoor[i],popup=listNode[i],tooltip='<strong>Click here to see Popup</strong>',icon=folium.Icon(color='blue',icon='none')).add_to(m5) f1.add_to(m5) folium.LayerControl().add_to(m5) m5.save('templates/map.html') flash('Tidak ditemukan jalan menuju lokasi tujuan') return render_template('GoogleMaps.html',comp_select = str(pilihankota)) else: for i in range(len(path)-1): listJalan.append([listCoor[path[i]],listCoor[path[i+1]]]) fig5=Figure(height=550,width=750) middle = main.middlePoint(listCoor) m5=folium.Map(location=[middle[0],middle[1]],tiles='cartodbpositron',zoom_start=17) fig5.add_child(m5) f1=folium.FeatureGroup("Jalan Asli") for i in range(len(listCoor)-1): for j in range(i+1, len(listCoor)): if (adjMatrix[i][j] != 0): place1 = [[listCoor[i][0],listCoor[i][1]],[listCoor[j][0],listCoor[j][1]]] line_1=folium.vector_layers.PolyLine(place1,color='red',weight=10).add_to(f1) jarakpath = "Jaraknya " + str(main.hitungJarakPath(adjMatrix,path,listCoor)) + " meter" for i in range(len(listJalan)): line_1=folium.vector_layers.PolyLine(listJalan[i],popup=jarakpath,tooltip=jarakpath,color='blue',weight=10).add_to(f1) #bikin node for i in range(len(listCoor)): folium.Marker(listCoor[i],popup=listNode[i],tooltip='<strong>Click here to see Popup</strong>',icon=folium.Icon(color='blue',icon='none')).add_to(m5) for i in range(len(path)): folium.Marker(listCoor[path[i]],popup=listNode[path[i]],tooltip='<strong>Click here to see Popup</strong>',icon=folium.Icon(color='green',icon='none')).add_to(m5) f1.add_to(m5) folium.LayerControl().add_to(m5) m5.save('templates/map.html') #kalau sampai sini aman #bisa mulai gambar #untuk ngecek apakah node i dan j dihubungkan 1 sisi atau gak -> cek adjMatrix[i][j] jika isinya 0 berarti gak berhubungan #untuk cek coordinat simpul ke i dari listNode tinggal pilih listCoor[i] (isinya tuple, yang pertama lat kedua long) #harusnya bisa lah ya kan alam gitu lho hehe #ini buat nampilin pake panah2 gitu jadi maneh gk usah liat #nah kalau mau hitung jaraknya bisa pake ini hitungJarakPath, jaraknya dalam meter return render_template('GoogleMaps.html')