我会试着解释我的问题:
我正在用街景API创建一个自定义的全景图,我把我的全景图切成512px的块(我的全景图总是512px的倍数)。
在大多数情况下,它呈现得很好:http://postimg.org/image/vdrre7qt7/
但是,当我使用大的全景图时,它是这样渲染的:http://postimg.org/image/5uxo0nof7/
当我放大时,这个效果就消失了。
在移动设备上,无论全景图大小如何,渲染效果都是相同的(并且必须放大到3或4个缩放值才能正确显示)。
这是我的代码(size.w和size.h是全景维度):
var streetViewPanoramaData = {
links: [],
copyright: 'Stuff',
tiles: {
tileSize: new google.maps.Size(512, 512),
worldSize: new google.maps.Size(size.w, size.h),
centerHeading: 0,
getTileUrl: t.getCustomPanoramaTileUrl
}
};
streetViewPanoramaData["location"] = {
pano: panoID,
description: "Custom Panorama",
latLng: new google.maps.LatLng(37.556429, -122.050745)
};这是getCustomePanoramaTileURL
this.getCustomPanoramaTileUrl = function(panoID, zoom, tileX, tileY) {
// Return a pano image given the panoID.
return "/the/directory/" + panoID + '/' + 0 + '_' + tileX + '_' + tileY + '.jpg';
}"/the/directory/panoID“包含我的tiles。
任何销售线索都将受到欢迎:)
发布于 2016-03-07 23:17:28
我想,我也有同样的问题。我花了几个小时才解出来。
所以,问题是,您只创建了一个图像,并将其拆分为瓦片。
谷歌需要多张图片,分成多张图片--每种缩放级别对应一张图片。
您需要为连续的1/2高1/2宽大小创建每个版本的全景图,直到全景图适合一个平铺。
例如,如果您有6000 * 3000像素的全景图,并且使用512 * 512平铺大小,则需要创建:
瓦片全景图6000 * 3000 (12*6 tiles)
这是我用来生成磁贴的小PHP脚本:
// util function used below
function resize_image($old_src, $new_src, $new_width, $new_height=null)
{
$src=imagecreatefromjpeg($old_src);
list($width, $height)=getimagesize($old_src);
$new_height = $new_height ? $new_height : round(($height/$width)*$new_width);
$tmp=imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
if (file_exists($new_src))
unlink($new_src);
imagejpeg($tmp, $new_src, 85);
}
$pano="/path/to/your/panorama.jpg";
$tiles_dir="/directory/where/you/want/to/place/tiles";
$crop_width=$crop_height=500; // your tiles size
$zooms=array(8000, 4000, 2000, 1000, 500); // I have 8000*4000 image, so I set sizes manually
$zooms=array_reverse($zooms);
foreach ($zooms as $zoom_level=>$zoom_width)
{
$name=str_replace('.jpg', '', basename($pano));
$zoom_dir=$tiles_dir.'/'.$name.'/'.$zoom_level;
if (!is_dir($zoom_dir))
mkdir($zoom_dir, 0777, true);
$temp_image_src=sys_get_temp_dir().DIRECTORY_SEPARATOR.uniqid();
resize_image($pano, $temp_image_src, $zoom_width); // my own function that resizes image
$img = new Imagick($temp_image_src);
$imgHeight=$img->getImageHeight();
$imgWidth=$img->getImageWidth();
$crop_width_num_times=ceil($imgWidth/$crop_width);
$crop_height_num_times=ceil($imgHeight/$crop_height);
$counter_x=0;
for ($i=0; $i<$crop_width_num_times; $i++)
{
$counter_y=0;
for ($j=0; $j<$crop_height_num_times; $j++)
{
$img = new Imagick($temp_image_src);
$x=($i*$crop_width);
$y=($j*$crop_height);
$img->cropImage($crop_width, $crop_height, $x, $y);
$data=$img->getImageBlob();
for ($z=0; $z<=5; $z++)
{
$newFileName=$zoom_dir."/".$counter_x."_".$counter_y.".jpg";
$result=file_put_contents($newFileName, $data);
}
$counter_y++;
}
$counter_x++;
}
}https://stackoverflow.com/questions/32909113
复制相似问题