equi/opengeodb-laravel

1.0.5 2016-11-07 10:39 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:20:46 UTC


README

Creative Commons Lizenzvertrag
本作品受Creative Commons署名-禁止演绎3.0德国许可证的许可。

关于

安装

Composer /Artisan

或者

composer require equi/opengeodb-laravel

在 composer.json 中添加行 "equi/opengeodb-laravel": "~1.0"

    ...
    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.2.*",
        ....
        "equi/opengeodb-laravel": "~1.0",
        ...
    },
    ...

手动更新时,请执行该命令

composer update

在 /config/app.php 的 "providers" 数组中添加此行

        Equi\Opengeodb\OpengeodbServiceprovider::class,

然后,将 default configs/migrations/.. 复制到 /app 目录。

php artisan vendor:publish

查找缺失的文件

OpenGeoDB -> 下载

你们需要哪些文件?

必需

opengeodb-end.sql
opengeodb_hier.sql
changes.sql

根据需要加载各个国家的文件

AT.sql
AThier.sql
BE.sql
BEhier.sql
CH.sql
CHhier.sql
DE.sql
DEhier.sql
LI.sql
LIhier.sql
Extra.sql    // Übergeordnete inhalte (Europa, Amerika, ...) und dazugehörige Sprachen (Deutschland = Germany ...)

这些文件似乎已过时,但将在 changes.sql 中更新

放哪里?

默认情况下在 /Storage/app/opengeodb/sql 或配置文件中指定的 storageopengodbsql 下的文件夹

配置 config/opengeodb.php

return [
    // Storage/app/.....
    'storagemap' => "/opengeodb/map",
    'storagee00' => "/opengeodb/e00",
    'storageopengodbsql' => "/opengeodb/sql",
    
    'mapcolor' => [
        'black'=>[0, 0, 0], 
        'white'=>[255, 255, 255], 
        'Therme'=>[255, 0, 0], 
        'Freizeitbad'=>[178, 237, 90], 
        'Sauna'=>[148, 208, 255], 
        'Anderes Bad'=>[148, 208, 255], 
        'Bad'=>[148, 208, 255], 
        'Hallenbad'=>[148, 208, 255], 
        'yellow'=>[148, 208, 255], 
        'pink'=>[148, 208, 255],
         
        'land'=>[20, 20, 20], 
        'bund'=>[125, 125, 125], 
        'kreis'=>[200, 200, 200], 
    ],
    
    'incresscolor' => 'black',
    
    'radiusdata' => [
        1 => 7,
        2 => 10,
        5 => 14,
    ]
    
];

创建和填充数据库

composer dump-autoload
php artisan migrate
php artisan db:seed --class=OpengeodbSeeder

对于某些PHP配置,de.sql 文件太大,可以尝试以下方法

php -d memory_limit=256M artisan db:seed --class=OpengeodbSeeder

引入/使用

绘制地图

示例显示了一个在 routes.php 中对 /Karte/ 响应的控制器。

namespace App\Http\Controllers;

use App\Http\Requests;
use Illuminate\Http\Request;
use App\Models\Thermal;
use Equi\Opengeodb\Map\GeoMap;
use Equi\Opengeodb\Models\GeodbMapcoord; 
use Equi\Opengeodb\Models\GeodbTextdata;

class MapController extends Controller
{

    public function getIndex() {
        $this->_data["result"] = "";
        $this->_data["ready"] = ""; 
        $this->_data["js"] = ""; 
        $this->_data["demaps"] = GeodbTextdata::where("loc_id", "105")->first()->GeodbMapcoords();
        $this->_data["atmaps"][] = GeodbMapcoord::where("loc_id", "106")->first();
        $this->_data["chmaps"][] = GeodbMapcoord::where("loc_id", "107")->first();
        $this->_data["title"] = \Lang::get("map.titlemap");
        $this->_data["description"] = \Lang::get("map.descriptionmap");
        return view('maps/map', $this->_data);
    }

    public function getShow($loc_id){
        return $this->zeichnethumb($loc_id);
    }
    
    public function getJson($loc_id){
        $map = $this->zeichne($loc_id);
        $data = $map->getArrayMapdata();
        for($i=0;$i < count($data); $i++){
            $datalinks = "";
            foreach($data[$i]["objects"] as $object){
                $datalinks .= "<a href='" .  \URL::route('seotherme', ["id" => $object->id, "badname" => $object->badurl]) . "' >" . $object->name . " (" . $object->stadt . ")</a><br>";
            }
            $data[$i]["objects"] = $datalinks;
        }
        return \Response::json(["data" => $data, "id" => $loc_id])->header('Content-Type', 'json');
    }
    
    public function getShowbig($loc_id){
        $map = $this->zeichne($loc_id);
        return \Response::make(\Storage::get($map->getImagePath()))->header('Content-Type', 'image/png');
    }
    
    public function postSearchloc(Request $request){
        $geo = new GeodbMaster();
        $geo->searchByName($request->get("search"));
        $geo->searchByPLZ($request->get("search"));
        $geodat = $geo->get();
        $json = [];
        foreach($geodat as $onecit){
            $city["loc_id"] = $onecit->loc_id;
            $city["name"] = $onecit->name();
            $city["plz"] = $onecit->plz();
            $json[] = $city;
        }
        return $json;
    } 

    private function zeichne($loc_id){
        if ($loc_id != 104)
            $map = new GeoMap($loc_id, 1090);
        else{
            $map = new GeoMap();
            $map->createEmptyMapAfterLoc_id($loc_id, 1090);
            $map->addDataFile("/105-bund.e00", "bund");
            $map->addDataFile("/105.e00", "land");
            $map->addDataFile("/106.e00", "land");
            $map->addDataFile("/107.e00", "land");
        }
        
        if (!$map->mapalreadyexists()) {
            $thermen = Thermal::all();
            foreach($thermen as $therme){
                $map->addGeoObjectIncrease($therme->lon, $therme->lat, $therme->id, $therme, $therme->artbad); 
            }
            $map->saveMapJson();
            $map->saveImage();
        }
        return $map;
    }
    
    private function zeichnethumb($loc_id){
        $image = \Config::get('opengeodb.storagemap')."thumb/" . $loc_id . ".png";
        if(\Storage::exists($image)) {
            return \Response::make(\Storage::get($image))->header('Content-Type', 'image/png');
        }elseif ($loc_id == 104){
            $map = new GeoMap();
            $map->createEmptyMapAfterLoc_id($loc_id, 350);
            $map->addDataFile("/105.e00", "land");
            $map->addDataFile("/106.e00", "land");
            $map->addDataFile("/107.e00", "land");
            $map->saveImage(storage_path("app". $image ));
        }else if (!\Storage::exists($image)) {
            $map = new GeoMap();
            $map->createMapAfterLoc_id($loc_id, 250);
            $map->saveImage(storage_path("app". $image ));
        }
        return \Response::make(\Storage::get($image))->header('Content-Type', 'image/png');
    }
    
}

这是我现在降低加载时间的方法。点在 map.blade.php 中。

  1. 要仅显示德国的地图,可以简单地调用 /Karte/show/105 (250px)。
    • <img src="{{URL::Asset('/karte/show/' . $demaps[$x]->loc_id)}}" alt="地图 {{$demaps[$x]->GeodbMaster()->name()}}">
    • 请将其放入 for 循环中或用数字替换 $x。
  2. 在函数 /Karte/showbig/105 (1090px) 中还会绘制更多的点。
    • <img src="{{URL::Asset('/karte/showbig/' . $demaps[$x]->loc_id)}}" alt="地图 {{$demaps[$x]->GeodbMaster()->name()}}" usemap="#map-{{$demaps[$x]->loc_id}}">
    • 请将其放入 for 循环中或用数字替换 $x。
  3. 在函数 /Karte/json/105 中,我还以 JSON 格式返回单个点。
    • <map name="map-{{$demaps[$x]->loc_id}}" id="map-{{$demaps[$x]->loc_id}}">
function gethtmlmap(id){
    $.ajax({
        url: "{{URL::asset("/karte/json")}}/" + id,
    }).done(function(data) {
        $("#map-" . id).html(""); 
        for(i=0; i < data.data.length; i++){
            area = $("#map-" + data.id).append("<area shape='circle' href='#' coords='" + data.data[i].x + "," + data.data[i].y + "," + (data.data[i].r + 10) + "' id='area" + data.data[i].x + data.data[i].y + data.data[i].r + "' data-id='" + i + "'>");
            $("#area" + data.data[i].x + data.data[i].y + data.data[i].r).mouseover(function (){
                UIkit.notify(data.data[$(this).data("id")].objects, {status:'info'});
            }); 
        }
    });
}
- Einfach als Javascript gethtmlmap($demaps[$x]->loc_id) aufrufen um an das JSON für die Karte zu kommen.  
- UIkit.notify(....); setzt ein kleines notify am Kopf der Seite ab. (benötigt uikit)  

获取数据/计算距离

方法 1

$geoloc = GeodbCoordinate::where("loc_id", $geotext->loc_id)->first();
$entrys = Location::select(\DB::raw("*, round(IFNULL((ACOS((SIN(RADIANS(" . $geoloc->lat ."))*SIN(RADIANS(lat))) + (COS(RADIANS(" . $geoloc->lat ."))*COS(RADIANS(lat))*COS(RADIANS(lon)-RADIANS(" . $geoloc->lon .")))) * 6371.110 ),0),2) AS distance"))->get();

Location 模型具有 lat 和 lon 字段,以避免始终搜索 100 MB 的数据。

方法 2

$augsburg = (new GeodbMaster())->searchByName("augsburg")->first();
$munich = (new GeodbMaster())->searchByPLZ(81929)->first();
$distanz = $augsburg->GeodbCoordinate()->calculatedistance($munich->GeodbCoordinate()->lon, $munich->GeodbCoordinate()->lat);

其他

要体验整个脚本,请访问 Thermen-Portal