Skip to content

Commit

Permalink
Add add_locations function
Browse files Browse the repository at this point in the history
  • Loading branch information
gadhagod committed May 9, 2021
1 parent 84eab20 commit 4876ce7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,6 @@ history.json
map.png

# todo
todo
todo

tst.py
16 changes: 16 additions & 0 deletions examples/manual_history_append.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
This examples shows how to manually add locations to the map.
"""

import flask
from flask_geomapper import flask_geomapper

app = flask.Flask(__name__) # init flask app
fg = flask_geomapper(app, count_trigger=app.before_request, debug=True)

@app.route("/")
def show_map():
fg.add_locations([50], [50]) # Add a location with longitude 50 and latitude 50
return flask.send_file(fg.get_img(), mimetype="image/png")

app.run(debug=True, use_reloader=False)
40 changes: 38 additions & 2 deletions flask_geomapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,41 @@ def get_img(

return img_data

def clear_history(self) -> None: self.history: dict = {"Longitude": [], "Latitude": []}
def pop_first_location(self) -> None: self.history["Longitude"], self.history["Latitude"] = self.history["Longitude"][1:], self.history["Latitude"][1:]
def clear_history(self) -> dict:
"""
Clears all stored locations.
Returns: Location history.
* type: dict
"""
self.history: dict = {"Longitude": [], "Latitude": []}
return self.history

def pop_first_location(self) -> dict:
"""
Removes the first stored location.
Returns: Location history.
* type: dict
"""
self.history["Longitude"], self.history["Latitude"] = self.history["Longitude"][1:], self.history["Latitude"][1:]
return self.history

def add_locations(self, lons: list, lats: list) -> dict:
"""
Manually adds locations.
Parmeters:
* lons: List of longitudes, matched to latitude with list index
* type: list
* lat: List of latitudes, matched to longitude with list index
* type: list
Returns: Location history.
* type: dict
Example:
* basic: `add_history({"Longitude": [50, 45], "Latitude": [50, 45]})`
"""
self.history["Longitude"], self.history["Latitude"] = self.history["Longitude"] + lons, self.history["Latitude"] + lats
return self.history

0 comments on commit 4876ce7

Please sign in to comment.