Skip to content
This repository was archived by the owner on Apr 22, 2024. It is now read-only.

Commit d30c38f

Browse files
author
Sehgal
committed
Amazon Location Experiment
1 parent 32e4fd0 commit d30c38f

27 files changed

+25003
-1
lines changed

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
.DS_Store
2-
__pycache__
2+
__pycache__
3+
node_modules/
4+
build/
5+
dist/
6+
.vscode/

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"git.ignoreLimitWarning": true
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"git.ignoreLimitWarning": true
3+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Amazon Location Experiment
2+
3+
This experiment demonstrates Amazon Location Service, creates a Streamlit component for displaying maps created within the service, creates high level API for rapidly experimenting with the service features.
4+
5+
First create your own [Cognito Identity Pool ID](https://docs.aws.amazon.com/cognito/latest/developerguide/identity-pools.html) and replace as value for `_IDENTITY` variable in the `location_app.py` file. Also create a HERE map with the name `2-5D-Map` and a default `explore.map` ESRI map created by the Amazon Location Console Explore tool.
6+
7+
Start the demo by running `streamlit run location_app.py` command in terminal.
8+
9+
![Location Experiment App](location-experiment.png)
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Simple Map</title>
5+
<meta name="viewport" content="initial-scale=1.0">
6+
<meta charset="utf-8">
7+
<style>
8+
/* Always set the map height explicitly to define the size of the div
9+
* element that contains the map. */
10+
#map {
11+
height: 100%;
12+
}
13+
/* Optional: Makes the sample page fill the window. */
14+
html, body {
15+
height: 100%;
16+
margin: 0;
17+
padding: 0;
18+
}
19+
</style>
20+
</head>
21+
<body>
22+
<div id="map"></div>
23+
<script>
24+
var map;
25+
function initMap() {
26+
map = new google.maps.Map(document.getElementById('map'), {
27+
center: {lat: -34.397, lng: 150.644},
28+
zoom: 8
29+
});
30+
}
31+
</script>
32+
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"
33+
async defer></script>
34+
</body>
35+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Historic Topographic Maps</title>
6+
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
7+
8+
<!-- Load Leaflet from CDN -->
9+
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"
10+
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
11+
crossorigin=""/>
12+
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"
13+
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
14+
crossorigin=""></script>
15+
16+
<!-- Load Esri Leaflet from CDN -->
17+
<script src="https://unpkg.com/esri-leaflet@3.0.2/dist/esri-leaflet.js"
18+
integrity="sha512-myckXhaJsP7Q7MZva03Tfme/MSF5a6HC2xryjAM4FxPLHGqlh5VALCbywHnzs2uPoF/4G/QVXyYDDSkp5nPfig=="
19+
crossorigin=""></script>
20+
21+
<style>
22+
body { margin:0; padding:0; }
23+
#map { position: absolute; top:0; bottom:0; right:0; left:0; }
24+
</style>
25+
</head>
26+
<body>
27+
28+
<div id="map"></div>
29+
30+
<script>
31+
var map = L.map('map').setView([30.70, -81.47], 12);
32+
33+
L.esri.tiledMapLayer({
34+
url: 'https://services.arcgisonline.com/ArcGIS/rest/services/USA_Topo_Maps/MapServer'
35+
}).addTo(map);
36+
</script>
37+
38+
</body>
39+
</html>
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import streamlit as st
2+
import pandas as pd
3+
import boto3
4+
5+
client = boto3.client('location')
6+
7+
def list_resources():
8+
st.subheader('Maps')
9+
response = client.list_maps()
10+
st.write(pd.DataFrame.from_dict(response['Entries']))
11+
12+
st.subheader('Place Indexes')
13+
response = client.list_place_indexes()
14+
st.write(pd.DataFrame.from_dict(response['Entries']))
15+
16+
st.subheader('Trackers')
17+
response = client.list_trackers()
18+
st.write(pd.DataFrame.from_dict(response['Entries']))
19+
20+
tracker = st.text_input('List Device Positions by Tracker', '')
21+
if tracker:
22+
st.subheader('Device positions by ' + tracker)
23+
response = client.list_device_positions(TrackerName=tracker)
24+
st.write(pd.DataFrame.from_dict(response['Entries']))
25+
26+
st.subheader('Geofence consumers by ' + tracker)
27+
response = client.list_tracker_consumers(TrackerName=tracker)
28+
st.write(pd.DataFrame(response['ConsumerArns']))
29+
30+
st.subheader('Route Calculators')
31+
response = client.list_route_calculators()
32+
st.write(pd.DataFrame.from_dict(response['Entries']))
33+
34+
st.subheader('Geofence Collections')
35+
response = client.list_geofence_collections()
36+
st.write(pd.DataFrame.from_dict(response['Entries']))
37+
38+
collection = st.text_input('List Geofences in collection', '')
39+
if collection:
40+
st.subheader('Geofences in ' + collection)
41+
response = client.list_geofences(CollectionName=collection)
42+
st.write(pd.DataFrame.from_dict(response['Entries']))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import streamlit as st
2+
import location_api as loc
3+
from location_map_component.location_map import location_map
4+
5+
# Cognito pool ID
6+
# Learn how to create your own ID here
7+
# https://docs.aws.amazon.com/cognito/latest/developerguide/identity-pools.html
8+
_IDENTITY = "replace-with-your-cognito-identity-pool-id"
9+
10+
st.header('Amazon Location Experiment')
11+
12+
tabs = st.radio('Choose Amazon Location Feature',
13+
('View ESRI Map', 'View HERE Map', 'List Resources'))
14+
15+
if tabs == 'View ESRI Map':
16+
location_map("explore.map", identity=_IDENTITY)
17+
18+
if tabs == 'View HERE Map':
19+
landmark = st.sidebar.selectbox(
20+
"View Landmark",
21+
("Bhurj Khalifa", "Empire State Building", "Sydney Opera House", "London Eye", "World Trade Center")
22+
)
23+
if landmark == "London Eye":
24+
location_map("2-5D-Map", lon=-0.1196, lat=51.5033, zoom=15, pitch=50, identity=_IDENTITY)
25+
elif landmark == "Empire State Building":
26+
location_map("2-5D-Map", lon=-73.9857, lat=40.7484, zoom=15, pitch=30, identity=_IDENTITY)
27+
elif landmark == "Sydney Opera House":
28+
location_map("2-5D-Map", lon=151.2153, lat=-33.8568, zoom=15, pitch=40, identity=_IDENTITY)
29+
elif landmark == "World Trade Center":
30+
location_map("2-5D-Map", lon=-74.013382, lat=40.712742, zoom=14, pitch=40, identity=_IDENTITY)
31+
else:
32+
location_map("2-5D-Map", lon=55.2744, lat=25.1972, zoom=14, pitch=60, identity=_IDENTITY)
33+
34+
if tabs == 'List Resources':
35+
loc.list_resources()
36+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"git.ignoreLimitWarning": true
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2018 The Python Packaging Authority
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
recursive-include location_map/frontend/build *
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import os
2+
import streamlit.components.v1 as components
3+
import uuid
4+
5+
# Create a _RELEASE constant. We'll set this to False while we're developing
6+
# the component, and True when we're ready to package and distribute it.
7+
# (This is, of course, optional - there are innumerable ways to manage your
8+
# release process.)
9+
_RELEASE = True
10+
11+
# Declare a Streamlit component. `declare_component` returns a function
12+
# that is used to create instances of the component. We're naming this
13+
# function "_component_func", with an underscore prefix, because we don't want
14+
# to expose it directly to users. Instead, we will create a custom wrapper
15+
# function, below, that will serve as our component's public API.
16+
17+
# It's worth noting that this call to `declare_component` is the
18+
# *only thing* you need to do to create the binding between Streamlit and
19+
# your component frontend. Everything else we do in this file is simply a
20+
# best practice.
21+
22+
if not _RELEASE:
23+
_component_func = components.declare_component(
24+
# We give the component a simple, descriptive name ("location_map"
25+
# does not fit this bill, so please choose something better for your
26+
# own component :)
27+
"location_map",
28+
# Pass `url` here to tell Streamlit that the component will be served
29+
# by the local dev server that you run via `npm run start`.
30+
# (This is useful while your component is in development.)
31+
url="http://localhost:3001",
32+
)
33+
else:
34+
# When we're distributing a production version of the component, we'll
35+
# replace the `url` param with `path`, and point it to to the component's
36+
# build directory:
37+
parent_dir = os.path.dirname(os.path.abspath(__file__))
38+
build_dir = os.path.join(parent_dir, "frontend/build")
39+
_component_func = components.declare_component("location_map", path=build_dir)
40+
41+
42+
# Create a wrapper function for the component. This is an optional
43+
# best practice - we could simply expose the component function returned by
44+
# `declare_component` and call it done. The wrapper allows us to customize
45+
# our component's API: we can pre-process its input args, post-process its
46+
# output value, and add a docstring for users.
47+
def location_map(name, lon=-123.1187, lat=49.2819, zoom=10, pitch=0, identity='', key=None):
48+
component_value = _component_func(
49+
name=name,
50+
lon=lon,
51+
lat=lat,
52+
zoom=zoom,
53+
pitch=pitch,
54+
identity=identity,
55+
key=str(uuid.uuid4()),
56+
default=0)
57+
return component_value
58+
59+
60+
# Add some test code to play with the component while it's in development.
61+
# During development, we can run this just as we would any other Streamlit
62+
# app: `$ streamlit run location_map/__init__.py`
63+
if not _RELEASE:
64+
import streamlit as st
65+
_IDENTITY = "us-east-1:e74fc977-4241-4a56-8bdd-49ea4455f8cf"
66+
st.subheader("Does this display the map?")
67+
68+
location_map("explore.map", identity=_IDENTITY)
69+
70+
location_map(
71+
"2-5D-Map",
72+
lon=-73.9857, lat=40.7484,
73+
zoom=16, pitch=30,
74+
identity=_IDENTITY)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Run the component's dev server on :3001
2+
# (The Streamlit dev server already runs on :3000)
3+
PORT=3001
4+
5+
# Don't automatically open the web browser on `npm run start`.
6+
BROWSER=none
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"endOfLine": "lf",
3+
"semi": false,
4+
"trailingComma": "es5"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"git.ignoreLimitWarning": true
3+
}

0 commit comments

Comments
 (0)