Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {% extends "layout.html" %}
- <!-- title of page -->
- {% block title %}
- Park Map
- {% endblock %}
- {% block main %}
- <!-- alert for when user logs in -->
- <div class ="alert-messages">
- {% if success_login %}
- <div class="alert alert-primary fade show p-1" role="alert" style="position:abolute;z-index:999;">
- <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true"></span></button>
- {{ success_login }}
- </div>
- {% endif %}
- </div>
- <!-- Div that holds the temp boostrap notification -->
- <div id="alert_placeholder"></div>
- <!-- JS script to hide and show the login error -->
- <script src="static/js/DismissLogin.js"></script>
- <body>
- <!-- script to init the google map -->
- <!-- https://www.youtube.com/watch?v=Zxf1mnP5zcw&t=131s -->
- <!-- https://www.youtube.com/watch?v=oVr6unKZbg4 -->
- <script>
- // https://pietschsoft.com/post/2015/09/05/javascript-basics-how-to-create-a-dictionary-with-keyvalue-pairs
- // create a dict to store the markers that get generated by the add_markers function
- // creates variable for keeping track of currently highlighted div
- var markers_dict = new Object();
- var currently_highlighted;
- var marker_selected;
- function initMap(){
- var options = {
- zoom:12,
- center:{lat:49.2827, lng:-123.1207},
- disableDefaultUI: true
- }
- var map = new google.maps.Map(document.getElementById('map'), options);
- // use jinja to loop through the index_park_info python dict we created our divs from
- {% for dictionary in index_park_info %}
- var park_id = "{{ dictionary["place_id"] }}";
- addMarker({lat:{{ dictionary["location_lat"] }},lng:{{ dictionary["location_long"] }}}, park_id);
- {% endfor %}
- // add marker function to add markers to our map
- function addMarker(coords, park_id){
- var info_box_park = document.getElementById("Park " + park_id);
- var marker = new google.maps.Marker({
- position:coords,
- map:map,
- icon: 'https://i.imgur.com/5rNpwiF.png'
- });
- // my own "scroll" function, so we don't end up repeating it's code when called/needed
- // un-higlights old element if the currently highlighted global variable is set to anything, then change that selected divs backround colour to white
- // highlights new element, takes the id string from the "info_box_park" & stores it inside of the var "currently_highlighted", to identify that selected dom, sets that selected doms colour to grey
- // https://stackoverflow.com/questions/11064081/javascript-change-google-map-marker-color
- function zoom(){
- map.setZoom(12);
- map.panTo(marker.getPosition());
- info_box_park.scrollIntoView({ behavior: 'smooth',});
- if (currently_highlighted) document.getElementById(currently_highlighted).style.backgroundColor = "white";
- currently_highlighted = info_box_park.id;
- info_box_park.style.backgroundColor = "#f2f2f2";
- if (marker_selected) marker_selected.setIcon('https://i.imgur.com/5rNpwiF.png')
- marker_selected = marker;
- marker.setIcon('https://mts.googleapis.com/vt/icon/name=icons/spotlight/spotlight-waypoint-blue.png&psize=16&font=fonts/Roboto-Regular.ttf&color=ff333333&ax=44&ay=48&scale=1')
- }
- // my own "scroll" function, does the same as zoom - scrolling the park into view upon being called
- function scroll(){
- map.setZoom(12);
- map.panTo(marker.getPosition());
- if (currently_highlighted) document.getElementById(currently_highlighted).style.backgroundColor = "white";
- currently_highlighted = info_box_park.id;
- info_box_park.style.backgroundColor = "#f2f2f2";
- if (marker_selected) marker_selected.setIcon('https://i.imgur.com/5rNpwiF.png')
- marker_selected = marker;
- marker.setIcon('https://mts.googleapis.com/vt/icon/name=icons/spotlight/spotlight-waypoint-blue.png&psize=16&font=fonts/Roboto-Regular.ttf&color=ff333333&ax=44&ay=48&scale=1')
- }
- // listener to call the zoom function for when a marker is clicked on
- marker.addListener('click', function(){zoom();});
- // listener we put on the info_box_park div when clicked on, it'll centre the map on the marker
- info_box_park.addEventListener('click', function(){scroll();});
- }
- }
- </script>
- <!-- script to load the google maps JS API to use on the front end of our web app -->
- <!-- this will try to load a function called init map -->
- <script defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAdojekZi5cr_AdmgSpt_4KIS_JA0x8Ax0&callback=initMap">
- </script>
- <!-- https://www.w3schools.com/css/css3_flexbox.asp -->
- <!-- div to place the map on the left side of the window -->
- <div class="flex-container">
- <!-- div to place the text on the right hand side of the window -->
- <!-- also use jinja to dynamically name each heading and paragraph of each park in this generated list for us to loop through later with JS -->
- <div class="col-md-4">
- <div class="margin: auto 1.5em; display: inline-block">
- <div class="Skatepark list">
- <!-- jinja forloop to create unique divs for each park from my python dict-->
- {% for dictionary in index_park_info %}
- <div class="list_item" id="Park {{ dictionary["place_id"] }}">
- <h5 class="{{ dictionary["place_id"] }}">
- {{ dictionary["name"] }}
- </h5>
- <p class="{{ dictionary["place_id"] }}">
- {{ dictionary["formatted_address"] }}
- </p>
- {% if dictionary["phone"] is not none %}
- <p class="{{ dictionary["place_id"] }}">
- {{ dictionary["phone"] }}
- </p>
- {% endif %}
- {% if dictionary["website"] is not none %}
- <p class="{{ dictionary["place_id"] }}">
- <a href= "{{ dictionary["website"] }}" > Website </a>
- </p>
- {% endif %}
- <!-- boostrap buttons to add that park to the users saved park and also navigate them to the reviews tab!-->
- <!-- create a button that calls a python function in my flask webserver when its pressed -->
- <button type="button" class="btn btn-outline-primary add_to_parks_buttons" id="{{ dictionary["place_id"] }}">Add to My Parks</button>
- <button type="button" class="btn btn-outline-info" id="{{ dictionary["place_id"] }}">Reviews</button>
- </div>
- {% endfor %}
- <!-- call MapAjax.js script to loop through all of my divs & take the "park_id" from the buttons in these divs, & send that id to flask with ajax -->
- <script src="static/js/AjaxMapErrors.js"></script>
- </div>
- </div>
- </div>
- <!-- https://www.youtube.com/watch?v=tiV4hJ30zIc -->
- <div class="col-md-8">
- <div class="margin: auto 1.5em; display: inline-block">
- <!-- https://www.youtube.com/watch?v=x99gNzHtm0k -->
- <!-- https://stackoverflow.com/questions/16466240/adjusting-and-image-size-to-fit-a-div-bootstrap -->
- <div id="map"></div>
- </div>
- </div>
- </body>
- {% endblock %}
Add Comment
Please, Sign In to add comment