Skip to content

Commit

Permalink
Switch to NPM, use API v2, Update publish action
Browse files Browse the repository at this point in the history
  • Loading branch information
amenk committed Dec 10, 2023
1 parent 6c230c2 commit 4f830f0
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2,488 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Publish
uses: cloudflare/wrangler-action@1.3.0
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
apiToken: ${{ secrets.CF_API_TOKEN }}
18 changes: 5 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,17 @@ You need the location (latitude, longitude) and optional the osmType (point, way

Example:

`GET https://discover.openplaceguide.org/v1/discover?lat=12.78&lng=36.92`
`GET https://discover.openplaceguide.org/v2/discover?lat=8.9776209&38&lon=38.7617240&osmId=way/162817836`

returns:

```json
{
"area": "ethiopia",
"url": "https://opg.addismap.com/",
"dataUrl": "https://opg.addismap.com/api/v1/place/"
}
[{"url":"https://opg.addismap.com/way/162817836","name":"AddisMap"}]
```

The returned url will redirect to the micro page for the OSM object.

The returned data URL can be fetched to obtain basic information, such as the logo image and a media gallery (if present).

The parmeters `osmType` and `osmId` are optional, if omitted, only the base URL to the federated OpenPlaceGuide instance
for the area fill be reported.

## Add your country
## Add your country / thematic website

Active contributors / teams of the OpenStreetMap are invited to set up a data repository for their country and register
the country in here.
Expand All @@ -51,5 +42,6 @@ the country in here.

4. Add the end of the file, add additional properties

## Development


`npm run dev`
2 changes: 1 addition & 1 deletion areas/ethiopia.json
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@
]
},
"properties": {
"name": "ethiopia",
"name": "AddisMap",
"url": "https://opg.addismap.com/",
"manager": [
"https://www.openstreetmap.org/user/self",
Expand Down
26 changes: 13 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ const router = Router()
Our index route, a simple hello world.
*/
router.get("/", () => {
return new Response('<h1>Welcome to the OpenPlaceGuide Discover API Service</h1>' +
'<p>Sample request: <a href="/v1/discover?lat=12.78&lng=36.92">/v1/discover?lat=12.78&lng=36.92</a></p>' +
return new Response('<h1>Welcome to the OpenPlaceGuide Discover V2 API Service</h1>' +
'<p>Sample request: <a href="/v2/discover?lat=8.9776209&38&lon=38.7617240&osmId=way/162817836">/v2/discover?lat=8.9776209&38&lon=38.7617240&osmId=way/162817836</a></p>' +
'<p><a href="https://github.com/openplaceguide/discover-cf-worker">GitHub</a></p>',
{
headers: {
"Content-Type": "text/html",
"Access-Control-Allow-Origin": "*"
"Access-Control-Allow-Origin": "*"
}
}
)
Expand All @@ -31,26 +31,27 @@ URL.
Try visit /example/hello and see the response.
*/
router.get("/v1/discover?", (req) => {
router.get("/v2/discover?", (req) => {
const {params, query} = req

const lng = query.lng;
const lon = query.lon ?? query.lng;
const lat = query.lat;
const osmId = query.osmId ?? '${type}/${id}';

let areas = [];

// Add new Areas / Countries here
areas.push(Eritrea);
// areas.push(Eritrea);
areas.push(Ethiopia);
areas.push(SouthSudan);
// areas.push(SouthSudan);

var featureCollection = {
type: 'FeatureCollection',
features: areas
};

var lookup = new PolygonLookup(featureCollection);
var poly = lookup.search(lng, lat);
var poly = lookup.search(lon, lat);

if (typeof poly === 'undefined') {
return new Response(JSON.stringify({'notice': 'not in any known area of OpenPlaceGuide'}), {
Expand All @@ -61,11 +62,10 @@ router.get("/v1/discover?", (req) => {
});
}

const response = {
"url": poly.properties.url,
"dataUrl": poly.properties.url + "api/v1/place/",
"area": poly.properties.name
}
const response = [{
"url": poly.properties.url + osmId,
"name": poly.properties.name
}]

// Return the HTML with the string to the client
return new Response(JSON.stringify(response), {
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"format": "prettier --write '**/*.{js,css,json,md}'"
"format": "prettier --write '**/*.{js,css,json,md}'",
"dev": "wrangler dev index.js"
},
"author": "Alexander Menk <[email protected]>",
"license": "ISC",
"devDependencies": {
"prettier": "^1.17.0"
"prettier": "^1.17.0",
"wrangler": "^3.19.0"
},
"dependencies": {
"itty-router": "^2.1.9",
Expand Down
Loading

0 comments on commit 4f830f0

Please sign in to comment.