Skip to content

Commit

Permalink
custom text bubble with table, change to package.json & .env to work …
Browse files Browse the repository at this point in the history
…with windows
  • Loading branch information
mmt456 committed May 17, 2024
1 parent 313439e commit 0fd7ce5
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PUBLIC_URL=.
PUBLIC_URL=.
PORT=3002
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"web-vitals": "^2.1.2"
},
"scripts": {
"start": "PORT=3002 react-scripts start",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
Expand Down
70 changes: 70 additions & 0 deletions src/vis/MeasurementMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,61 @@ function cts(p: Cell): string {
return p.x + ',' + p.y;
}

// print results of user search event to console
function searchEventHandler(result: any): void {
const xhr = new XMLHttpRequest();
xhr.open('GET', "http://127.0.0.1:8000/?state=va&cityname=arlington&primary=3109&street_number=9th&st=St&post_direction=N&zip_5=22201&zip_9=2024");
xhr.onload = function() {
console.log("200 check");
console.log(xhr.status);
if (xhr.status === 200) {
//result.marker.setPopupContent(xhr.responseText);
result.marker.setPopupContent(organizePopup(xhr.responseText));
}
};
xhr.send();
}



// organize popup content. called from searchEvenHandler
function organizePopup(apiText: any): string{
let dict = JSON.parse(apiText);
let returnString = "<table style='border:1px solid black;'>"
+ "<b>" + "<tr>"
+ "<th style='border:1px solid black;'>" + "Provider" + "</th>"
+ "<th style='border:1px solid black;'>" + "Available Speeds up to" + "</th>"
+ "<th style='border:1px solid black;'>" + "Starting Rate" + "</th>"
+ "</tr>" + "</b>";

if ("message" in dict) {
return dict["message"];
}
let dict2 = dict["here you go"];
console.log(dict2);

// for loop that goes over each key in dictionary
for (let key in dict2) {
/*returnString = returnString + "<b>" + key + "</b>" + ": Available speeds up to " + dict2[key]["Available speeds"]
+ ", Starting at " + dict2[key]["Starting at"] + "<br />" + "<br />";*/

returnString += "<tr>"
+ "<td style='border:1px solid black;'>" + key + "</td>"
+ "<td style='border:1px solid black;'>" + dict2[key]["Available speeds"] + "</td>"
+ "<td style='border:1px solid black;'>" + dict2[key]["Starting at"] + "</td>"
+ "</tr>";

}

return returnString + "</table>";
}

// make request/call to api, then get back the json data,
// then return the string
function resultFormat(result: any): string {
return "Loading...";
}

export const UNITS = {
dbm: 'dBm',
ping: 'ms',
Expand Down Expand Up @@ -137,8 +192,23 @@ const MeasurementMap = ({
const search = new (GeoSearchControl as any)({
provider: new OpenStreetMapProvider(),
style: 'bar', // optional: bar|button - default button
showPopup: true,
marker: {
icon: new L.Icon.Default(),
draggable:false,
},
popupFormat: resultFormat,

//showMarker: false,
});
_map.addControl(search);
_map.on('geosearch/showlocation', searchEventHandler);

/*var marker = L.marker(search.location)
.bindPopup("hello")
.addTo(_map);*/


})();
}, [width, height]);

Expand Down

0 comments on commit 0fd7ce5

Please sign in to comment.