douleijiang8111 2019-05-07 06:42
浏览 102

简单的PHP脚本,可用于直接从MBTiles文件加载平铺地图数据(PBF)

    <?php

  $z = $_GET['z'];
  $x = $_GET['x'];
  $y = $_GET['y'];

  try {
    $conn = new PDO("sqlite:output.mbtiles");

    $z = floatval($z);
    $y = floatval($y);
    $x = floatval($x);
    $flip = true;
    if ($flip) {
      $y = pow(2, $z) - 1 - $y;
    }

    $sql = "SELECT * FROM tiles WHERE zoom_level = $z AND tile_column = $x AND tile_row = $y";
    $q = $conn->prepare($sql);
    $q->execute();

    $q->bindColumn(1, $zoom_level);
    $q->bindColumn(2, $tile_column);
    $q->bindColumn(3, $tile_row);
    $q->bindColumn(4, $tile_data, PDO::PARAM_LOB);

    if ($data = $q->fetch()) {
      do {
        header('Access-Control-Allow-Origin: *');
        header('Content-Type: application/octet-stream');
        header('Content-Encoding: gzip');
        echo $tile_data;
      } while ($data = $q->fetch());
    }
    else {
      header('Access-Control-Allow-Origin: *');
      header('HTTP/1.1 204 No Content');
      header('Content-Type: application/json; charset=utf-8');
      echo '{ "message": "Tile does not exist" }';
    }
  }
  catch(PDOException $e) {
    print 'Exception : '.$e->getMessage();
  }

?>

Above is php code to get pbf data from sqlite mbtiles. But I may not able to get any data.

I went through the below link https://github.com/tmnnrs/mbtiles-php

but not able to figure it out how it works.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度