这是我将获取请求发送到磁贴服务器的 javascript 部分:
var tile_layer = L.tileLayer(
"http://127.0.0.1:8080/{z}/{x}/{y}.png",
{"detectRetina": false, "maxNativeZoom": 18, "maxZoom": 18, "minZoom": 0, "noWrap": false, "opacity": 1, "subdomains": "abc", "tms": false}
).addTo(map);
现在我想使用 PHP 来转发这些请求,如下所示:
var tile_layer = L.tileLayer("controller/request.php?x={x}&y={y}&z={z}",
{"detectRetina": false, "maxNativeZoom": 18, "maxZoom": 18, "minZoom": 0, "noWrap": false, "opacity": 1, "subdomains": "abc", "tms": false}
).addTo(map);
我怎么能做到这一点,因为似乎请求没有被转发到下面的controller/request.php文件:
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('http://127.0.0.1:8080/styles/basic-preview/'.$_GET['z'].'/'.$_GET['x'].'/'.$_GET['y'].'.png');
$request->setMethod(HTTP_Request2::METHOD_GET);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setBody('');
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}