Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions ToDo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
THE FINAL INTENDED URL Endpoint for Signle POIs (Business Pages)
Make a route that takes a way/node ID + type (similar like the addismap.com URLs)
and loads the data from the openstreetmap.org JSON and displays it
1. Get all Map data (Node/Way/Relation) from OSM using BBOX or Area
2. Generate a JSON data generating URL (End Point) for each Map data
3. Get a JSON Response using OSM_TYPE & OSM_ID obtained from OSM_OVERPASS_API {Elements}

Get URL https://www.addismap.com/p6624545638/bati-complex
Get URL https://openplaceguide.org/{name}
Get URL https://openplaceguide.org/{osm_type}{osm_id}/{osm_name}
Get URL https://openplaceguide.org/{osm_type}/{osm_id} -> desired URL (Endpoint)
Get URL https://www.openstreetmap.org/api/0.6/way/162817836.json


date=`date +%FT%H-%M-%S`
#XAPI="http://xapi.openstreetmap.org/api/0.6/map"
XAPI="http://www.overpass-api.de/api/xapi?map"
## ETHIOPIA via Geofabrik
URL=http://download.geofabrik.de/openstreetmap/africa/ethiopia.osm.bz2
dir=/srv/downloads/osm/ethiopia
name="ethiopia"
wget $URL -O $dir/$date-$name.osm.bz2
## ETHIOPIA via Geofabrik
URL=http://download.geofabrik.de/openstreetmap/africa/ethiopia.osm.pbf
dir=/srv/downloads/osm/ethiopia
name="ethiopia"
wget $URL -O $dir/$date-$name.osm.pbf
## Addis via XAPI
dir=/srv/downloads/osm/addis-ababa
name="addis-ababa"
top=9.13
bottom=8.8
left=38.61
right=38.96
URL=$XAPI?bbox=$left,$bottom,$right,$top
wget $URL -O $dir/$date-$name.osm
bzip2 $dir/$date-$name.osm
/srv/bame-website/scripts/new-osm.sh $dir/$date-$name.osm.bz2
#XAPI="http://xapi.openstreetmap.org/api/0.6"
#top=14.8922
#bottom=3.4024
#left=32.9999
#right=47.9862
#URL=$XAPI/map?bbox=$left,$bottom,$right,$top


12 changes: 8 additions & 4 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
use LaravelJsonApi\Core\Exceptions\JsonApiException;

class Handler extends ExceptionHandler
{
Expand All @@ -13,7 +14,7 @@ class Handler extends ExceptionHandler
* @var array<int, class-string<Throwable>>
*/
protected $dontReport = [
//
JsonApiException::class,
];

/**
Expand All @@ -34,8 +35,11 @@ class Handler extends ExceptionHandler
*/
public function register()
{
$this->reportable(function (Throwable $e) {
//
});
// $this->reportable(function (Throwable $e) {
// //
// });
$this->renderable(
\LaravelJsonApi\Exceptions\ExceptionParser::make()->renderable()
);
}
}
49 changes: 49 additions & 0 deletions app/Http/Controllers/OsmapController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;

use App\Models\Osmap;

class OsmapController extends Controller
{
public function index()
{
$query = '[out:json][timeout:400];nwr["name"](8.827402638625081,38.63822937011719,9.104808725563043,38.91632080078125);out%20body;';

$osmaps = collect(Http::get('https://www.overpass-api.de/api/map?data='.$query)->json()['elements']);

return view('osmaps.index', ['osmaps' => $osmaps]);
}

public function show($type, $id)
{
$query = '[out:json][timeout:400];way["tourism"="guest_house"](8.827402638625081,38.63822937011719,9.104808725563043,38.91632080078125);out%20body;';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you do not need to query overpass for this - you already have type and ID and can directly pass it to the show function


$osmaps = Http::get('https://www.overpass-api.de/api/map?data='.$query)->json()['elements'];

$map_length = count($osmaps);

if ($map_length > 0) {
foreach ($osmaps as $osmap) {
$type = $osmap['type'];
$id = $osmap['id'];
}
}
$osmurl = Http::get('https://www.openstreetmap.org/api/0.6/'.$type.'/'.$id.'.json');
return $osmurl;
// return view('osmaps.show', compact($osmap));
}

public function single($id)
{
// $bbox = '38.61,8.8,38.96,9.13';
// $xapi = Http::get('http://master.apis.dev.openstreetmap.org/api/0.6/map?bbox=' . $bbox);
$id = '445313461';
$data = Http::get('https://openstreetmap.org/api/0.6/node/'.$id.'json');
dump($data);
}
}

44 changes: 44 additions & 0 deletions app/Models/Osmap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Http;

class Osmap extends Model
{
use HasFactory;

// public static function map()
// {
// $query = '[out:json][timeout:400];way["tourism"="guest_house"](8.827402638625081,38.63822937011719,9.104808725563043,38.91632080078125);out%20body;';

// $apiUrl = Http::get('https://www.overpass-api.de/api/map?data='.$query)->json()['elements'];

// return $apiUrl;
// }

public static function osmApiUrl()
{
// Get a single OSM_TYPE and OSM_ID for each JSON elements from the OverPassApi Query
// When user hits /OSM_TYPE/OSM_ID endpoint -> Redirect to the intended URL or Get JSON Data

$query = '[out:json][timeout:400];way["tourism"="guest_house"](8.827402638625081,38.63822937011719,9.104808725563043,38.91632080078125);out%20body;';
$osmaps = Http::get('https://www.overpass-api.de/api/map?data='.$query)->json()['elements'];

$map_length = count($osmaps);

for ($i=0; $i < $map_length; $i++) {
foreach ($osmaps as $osmap) {
$type = $osmap['type'];
$id = $osmap['id'];
}
$osmurl = Http::get('https://www.openstreetmap.org/api/0.6/'.$type.'/'.$id.'.json');
return $osmurl;
}
$returnData = file_get_contents($osmurl, true);
$finalData = json_encode($returnData);
return $finalData;
}
}
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
"require": {
"php": "^8.0.2",
"guzzlehttp/guzzle": "^7.2",
"laravel-json-api/laravel": "^2.3",
"laravel/framework": "^9.2",
"laravel/sanctum": "^2.14.1",
"laravel/tinker": "^2.7"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",
"laravel-json-api/testing": "^1.1",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^6.1",
Expand Down
Loading