Skip to content

Commit 0119ab8

Browse files
committed
adde cities, sweet alert, error handling and catching. Project looks good 💯
1 parent b7fb196 commit 0119ab8

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

index.html

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-service.js"></script>
2929
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-ui.js"></script>
3030
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-mapevents.js"></script>
31+
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
3132

3233
</head>
3334

js/app.js

+48-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99

10+
1011
function addMarkerToGroup(group, coordinate, html) {
1112
var marker = new H.map.Marker(coordinate);
1213
// add custom data to the marker
@@ -17,7 +18,6 @@ function addMarkerToGroup(group, coordinate, html) {
1718

1819
function getnews(city){
1920
var obj;
20-
// var url = "https://newsapi.org/v2/top-headlines?country=jp&apiKey=7b5f48dbc9e348db8616f70b532aff14";
2121
var url ='https://newsapi.org/v2/top-headlines?' +
2222
'q=' + city + '&' +
2323
'sortBy=popularity&' +
@@ -27,9 +27,21 @@ function getnews(city){
2727
.then((response) => response.json())
2828
.then((responseJSON) => {
2929
let newRes = responseJSON;
30-
31-
alert(newRes.articles[0].title, newRes.articles[0])
32-
})
30+
swal({
31+
title: newRes.articles[0].title,
32+
text: newRes.articles[0].content,
33+
icon: "info",
34+
buttons: [true,"See Full Article"],
35+
}).then(okay => {
36+
if (okay) {
37+
window.location.href = newRes.articles[0].url;
38+
}
39+
});
40+
}).catch(swal({
41+
title: "Error",
42+
text: "No News at the moment. Try again later.",
43+
icon: "warning"
44+
}))
3345
}
3446

3547
// initialize communication with the platform
@@ -44,8 +56,8 @@ var defaultLayers = platform.createDefaultLayers();
4456
// initialize a map - this map is centered over Europe
4557
var map = new H.Map(document.getElementById('map1'),
4658
defaultLayers.normal.map,{
47-
center: {lat: 53.430, lng: -2.961},
48-
zoom: 4
59+
center: {lat: 0, lng: 0},
60+
zoom: 2
4961
});
5062

5163
// MapEvents enables the event system
@@ -120,7 +132,35 @@ addInfoBubble(map);
120132
addMarkerToGroup(group, {lat:-33.8688, lng:151.2093},
121133
`<button onclick="getnews(\'Sydney\')">Sydney</button>`);
122134

123-
135+
addMarkerToGroup(group, {lat:-30.559483, lng:22.937506},
136+
`<button onclick="getnews(\'South Africa\')">South Africa</button>`);
137+
138+
addMarkerToGroup(group, {lat:-35.675148, lng:-71.542969},
139+
`<button onclick="getnews(\'Chile\')">Chile</button>`);
140+
141+
addMarkerToGroup(group, {lat:-14.235004, lng:-51.925282},
142+
`<button onclick="getnews(\'Brasil\')">Brasil</button>`);
143+
144+
addMarkerToGroup(group, {lat:45.501690, lng:-73.567253},
145+
`<button onclick="getnews(\'Montreal\')">Montreal</button>`);
146+
147+
addMarkerToGroup(group, {lat:59.938480, lng:30.312481},
148+
`<button onclick="getnews(\'Saint Petersbourg\')">Saint Petersbourg</button>`);
149+
150+
addMarkerToGroup(group, {lat:53.349804, lng:-6.260310},
151+
`<button onclick="getnews(\'Dublin\')">Dublin</button>`);
152+
153+
addMarkerToGroup(group, {lat:9.081999, lng:8.675277},
154+
`<button onclick="getnews(\'Nigeria\')">Nigeria</button>`);
155+
156+
addMarkerToGroup(group, {lat:41.299496, lng:69.240074},
157+
`<button onclick="getnews(\'Tashkent\')">Tashkent</button>`);
158+
159+
addMarkerToGroup(group, {lat:47.606209, lng:-122.332069},
160+
`<button onclick="getnews(\'Seattle\')">Seattle</button>`);
161+
162+
addMarkerToGroup(group, {lat:37.774929, lng:-122.419418},
163+
`<button onclick="getnews(\'San Francisco\')">San Francisco</button>`);
124164
}
125165

126166
// initialize communication with the platform
@@ -135,7 +175,7 @@ addInfoBubble(map);
135175
// initialize a map - this map is centered over Europe
136176
var map = new H.Map(document.getElementById('map'),
137177
defaultLayers.normal.map,{
138-
center: {lat: 53.430, lng: -2.961},
178+
center: {lat: 0, lng: 0},
139179
zoom: 7
140180
});
141181

0 commit comments

Comments
 (0)