Skip to content

Commit 11ce6a9

Browse files
Reverting retrieve_map_data.py, added some misecellaneous fixes and support for pre-selected layers
1 parent 759d5d1 commit 11ce6a9

File tree

4 files changed

+102
-47
lines changed

4 files changed

+102
-47
lines changed

map_data.json

+1-1
Large diffs are not rendered by default.

retrieve_open_map_data.py

+73-23
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,75 @@
2323
'quilting-quilds': 'quilting-guilds'
2424
}
2525

26-
def retrieve_json_blob(url):
27-
map_category_page = requests.get(url)
28-
return json.loads(map_category_page.text)
29-
30-
def pull_geojson_from_json(blob):
31-
for category in blob:
32-
if 'field_geojson_link' in category.keys():
33-
print(category['field_geojson_link'])
34-
internal_url = category['field_geojson_link'][0]['uri'].replace('internal:','')
35-
geojson_url = BASE_URL + internal_url
36-
print(geojson_url)
37-
geojson_page = requests.get(geojson_url)
38-
if (geojson_page.status_code == 200 and geojson_page.text is not None):
39-
print(geojson_page.text)
40-
41-
#map_layer_url = BASE_URL + '/map-layers'
42-
#map_categories = web(1, map_layer_url)
43-
#print(json.dumps(map_categories))
44-
45-
json_blob_url = "https://data.openupstate.org/rest/maps?_format=json"
46-
map_data = retrieve_json_blob(json_blob_url)
47-
pull_geojson_from_json(map_data)
26+
#Retrieve a single map category url
27+
def retrieve_map_category_url(url):
28+
map_category_url = BASE_URL + url
29+
map_category_page = requests.get(map_category_url)
30+
#Don't spam the server
31+
plain = map_category_page.text
32+
s = BeautifulSoup(plain, "html.parser")
33+
geojson_link_anchor_list = s.select(".field--name-field-geojson-link a")
34+
geojson_link_anchor = ""
35+
if (geojson_link_anchor_list):
36+
geojson_link_anchor = geojson_link_anchor_list[0]
37+
return geojson_link_anchor.text
38+
39+
#Retrieve a single map category url
40+
def retrieve_map_category_geojson_data(url):
41+
full_url = BASE_URL + url
42+
geojson_page = requests.get(full_url)
43+
geojson_data = ""
44+
if (geojson_page.status_code == 200 and geojson_page.text is not None):
45+
geojson_data = json.loads(geojson_page.text)
46+
return geojson_data
47+
48+
49+
def web(page,WebUrl):
50+
href_list = []
51+
if(page>0):
52+
url = WebUrl
53+
code = requests.get(url)
54+
plain = code.text
55+
s = BeautifulSoup(plain, "html.parser")
56+
#only_a_tags = SoupStrainer(".field-content a")
57+
count_entries = 0
58+
for link in s.select(".field-content a"):
59+
#for link in only_a_tags:
60+
#for link in only_a_tags.a:
61+
href = link.get('href')
62+
63+
if MAP_URL_DIRECTORY in href:
64+
category = href.split(MAP_URL_DIRECTORY)[1]
65+
#url_category = geojson_url_exceptions[category] or category;
66+
67+
url_category = ''
68+
if category in geojson_url_exceptions:
69+
url_category = geojson_url_exceptions[category]
70+
else:
71+
url_category = category
72+
73+
map_entry = {
74+
'href': href,
75+
'geojson_url': "/map/geojson/" + url_category,
76+
'name': link.get_text(),
77+
'category': category,
78+
}
79+
map_entry["geojson_data"] = retrieve_map_category_geojson_data(map_entry["geojson_url"])
80+
81+
#skip for now
82+
#map_entry['map_spreadsheet_url'] = retrieve_map_category_url(href)
83+
#print(map_entry)
84+
if (map_entry["geojson_data"]):
85+
href_list.append(map_entry)
86+
87+
count_entries += 1
88+
#if (count_entries > 10):
89+
# break
90+
return href_list
91+
92+
map_layer_url = BASE_URL + '/map-layers'
93+
map_categories = web(1, map_layer_url)
94+
print(json.dumps(map_categories))
4895

4996
#Retrieve map category URL
5097
def retrieve_map_category_urls(url):
@@ -56,4 +103,7 @@ def retrieve_map_category_urls(url):
56103
time.sleep(5)
57104
map_category_page = requests.get(map_category_url)
58105
geojson_link_anchor = s.select(".field--name-field-geojson-link a")
59-
geojson_link_anchor.text
106+
geojson_link_anchor.text
107+
108+
109+

src/components/MapData.vue

+26-21
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,11 @@
1010
<div class="open-data--utility-control open-data--utility-control__add" v-on:click="updateMapLocations()">Update locations</div>
1111
<div class="open-data--utility-control open-data--utility-control__remove" v-on:click="removeAllMapLayers()">Remove locations</div>
1212
<div class="clearfix"></div>
13-
<div class="open-data--utility-control-toggle" id="utility_control_panel_toggle"><div class="open-data--utility-control-toggle-arrow" v-on:click="toggleUtilityControls()">Toggle Controls</div>
13+
<div class="open-data--utility-control-toggle" id="utility_control_panel_toggle"><div class="open-data--utility-control-toggle-arrow" v-on:click="toggleUtilityControls()">Toggle Controls</div></div>
1414
</div>
15-
16-
</div>
17-
<!--<div class="open-data--utility-control-toggle"><div class="open-data--utility-control-toggle-arrow" v-on:click="toggleUtilityControls()">V</div></div>-->
18-
19-
<!--<img src="../../public/arrows.svg"/>
20-
<svg id="more-arrows" viewBox="0 0 75 65">
21-
<polygon class="arrow-top" points="37.6,27.9 1.8,1.3 3.3,0 37.6,25.3 71.9,0 73.7,1.3 "/>
22-
<polygon class="arrow-middle" points="37.6,45.8 0.8,18.7 4.4,16.4 37.6,41.2 71.2,16.4 74.5,18.7 "/>
23-
<polygon class="arrow-bottom" points="37.6,64 0,36.1 5.1,32.8 37.6,56.8 70.4,32.8 75.5,36.1 "/>
24-
</svg>-->
15+
<!--<div class="open-data--utility-control-toggle"><div class="open-data--utility-control-toggle-arrow" v-on:click="toggleUtilityControls()">V</div></div>-->
2516
</div>
26-
<div class="open-data--map-data--category-container">
17+
<div class="open-data--map-data--category-container" v-if="!map_only">
2718
<div class="open-data--selected-items">
2819
<div class="open-data--selected-item" v-bind:style="selected_map_category.item_styles || {}" v-on:click="toggleMapLayer(selected_map_category)" v-bind:key="selected_map_category.id" v-for="(selected_map_category, index) in selectedGeoJsonData">
2920
{{selected_map_category.name}}
@@ -32,7 +23,7 @@
3223
<input type="textbox" class="open-data--map-data--filter-input" v-model="filterTerm" v-on:keyup="filterMapCategories()" placeholder="Filter selection here..." id="map_data_filter_input"/>
3324
<div class="open-data--list-container">
3425
<ul class="open-data--map-data--list">
35-
<li class="open-data--map-data--item" v-on:click="toggleMapLayer(map_category)" v-bind:style="map_category.item_styles" v-bind:key="map_category.name" v-for="(map_category, index) in filteredGeoJsonData">
26+
<li class="open-data--map-data--item" v-on:mouseover="highlightMapCategory(map_category)" v-on:click="toggleMapLayer(map_category)" v-bind:style="map_category.item_styles" v-bind:key="map_category.name" v-for="(map_category, index) in filteredGeoJsonData">
3627
<span class="open-data--name">{{map_category.name}}</span>
3728
<div class="open-data--controls">
3829
<input id="remove_map_layer" type="checkbox" v-if="hasMapLayer(map_category)">
@@ -54,7 +45,8 @@
5445
map_category.item_styles = {};
5546
});
5647
57-
window.map_json = map_json;
48+
//TODO: stop using globals globals.
49+
window.map_json = map_json;
5850
5951
function generateRandomHexColor() {
6052
return '#' + ("000000" + Math.random().toString(16).slice(2, 8).toUpperCase()).slice(-6);
@@ -79,9 +71,13 @@ window.map_json = map_json;
7971
filteredGeoJsonData: map_json,
8072
selectedGeoJsonData: {},
8173
filterTerm: "",
74+
hoveredMapCategory: null,
8275
}
8376
},
8477
methods: {
78+
highlightMapCategory: function () {
79+
80+
},
8581
updateMapLocations: function () {
8682
let L = window.L;
8783
let map = window.my_map;
@@ -92,7 +88,7 @@ window.map_json = map_json;
9288
if (map && L) {
9389
this.geoJsonData.forEach(function(map_category, index) {
9490
if (map_category.geojson_data.type !== "FeatureCollection") {
95-
console.log("diff type", map_category)
91+
//console.log("diff type", map_category)
9692
}
9793
map_data.addMapLayer(map_category);
9894
});
@@ -110,6 +106,10 @@ window.map_json = map_json;
110106
}
111107
},
112108
fetchMapData: function () {
109+
/*
110+
TODO: If we want to use opendata site, resolve COORS issues. If data is stored in a database, we can just hit our own
111+
API here.
112+
113113
var xmlhttp = new XMLHttpRequest();
114114
115115
xmlhttp.onreadystatechange = function() {
@@ -125,10 +125,10 @@ window.map_json = map_json;
125125
}
126126
}
127127
};
128-
128+
129129
xmlhttp.open("GET", "https://data.openupstate.org/rest/maps?_format=json", true);
130130
xmlhttp.send();
131-
/*
131+
132132
let map_data_promise = fetch("https://data.openupstate.org/rest/maps?_format=json").then(function(data){
133133
console.log("fetch data", data);
134134
});
@@ -159,6 +159,7 @@ window.map_json = map_json;
159159
let geo_json = map_category.geojson_data;
160160
let map = window.my_map;
161161
let L = window.L;
162+
162163
if (map_category.layer && !map.hasLayer(map_category)) {
163164
let marker_color = this.setMapCategoryColor(map_category, map_category.marker_color);
164165
map.addLayer(map_category.layer);
@@ -242,13 +243,13 @@ window.map_json = map_json;
242243
}
243244
},
244245
addPreSelectedMaps: function(map_selections) {
246+
let map_data = this;
245247
console.log("MAP SELECTIONS", map_selections);
246248
this.geoJsonData.forEach(function(map_category, index) {
247-
if (map_category.category.type !== "FeatureCollection") {
248-
console.log("diff type", map_category);
249+
if (map_selections.includes(map_category.category)) {
250+
map_data.addMapLayer(map_category);
249251
}
250252
});
251-
map_data.addMapLayer(map_category);
252253
},
253254
toggleUtilityControls: function () {
254255
let control_panel = document.getElementById("utility_control_panel");
@@ -290,6 +291,7 @@ control_panel_toggle.style.display = "none";
290291
.open-data--control-label {
291292
font-size:10px;
292293
}
294+
293295
.open-data--map-data--item {
294296
background-color: white;
295297
border: 0.5px solid gray;
@@ -458,8 +460,11 @@ control_panel_toggle.style.display = "none";
458460
}
459461
460462
.open-data--map-marker {
461-
fill-opacity: .3px;
462463
transition: all 2s ease-out;
464+
465+
&:hover {
466+
467+
}
463468
}
464469
465470

src/router.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export default new Router({
2323
name: 'about',
2424
component: MapData,
2525
props: (route) => ({
26-
preselected_maps: route.query.preselected_maps,
27-
map_only: route.query.map_only
26+
preselected_maps: route.query.preselected_maps ? route.query.preselected_maps.split(',') : [],
27+
map_only: !!route.query.map_only
2828
})
2929
},
3030
]

0 commit comments

Comments
 (0)