streetview-panorama
Advanced tools
Comparing version 1.0.0 to 1.0.1
129
index.js
@@ -5,8 +5,6 @@ //const streetview = require('streetview-panorama') | ||
//streetview.saveImg( { type:"google", id:"Ec8-wVGl7_ExksLoefbfOw", fileName:'./panorama/' } ) | ||
//streetview.getImgPreview( { type:"naver", id:"e75tezRrNRrTbh6k7Nvxsw" } ) | ||
//streetview.getImgPreview( { type:"kakao", id:"1071043104", fileName:'./panorama/' } ) | ||
//streetview.getImgPreview( { type:"google", id:"AF1QipNj7fskmGw14klOjldXQ6WDR4d2OrUJezadVcpi", fileName:'./panorama/aaa6.png' } ) | ||
//streetview.saveImgPreview( { type:"naver", id:"e75tezRrNRrTbh6k7Nvxsw" } ) | ||
//streetview.saveImgPreview( { type:"kakao", id:"1071043104", fileName:'./panorama/' } ) | ||
//streetview.saveImgPreview( { type:"google", id:"AF1QipNj7fskmGw14klOjldXQ6WDR4d2OrUJezadVcpi", fileName:'./panorama/aaa6.png' } ) | ||
// let ccc = await streetview.getImg( { type:"kakao", id:"1071043104"} ) | ||
const { Canvas, Image } = require('canvas') | ||
@@ -19,13 +17,6 @@ const fs = require('fs') | ||
let streetview = { | ||
queueImg : [], | ||
saveImg : async (options) => { | ||
const b64 = await streetview.getImg(options) | ||
const vFilePathNm = streetview.getFileName(options) | ||
return fs.writeFile(vFilePathNm, b64, ()=> { | ||
console.log("download complete : " + options.id + " => " + vFilePathNm ) | ||
}) | ||
}, | ||
getImg : async (options) => { | ||
const vType = options.type | ||
let vId = options.id | ||
const vId = options.id | ||
@@ -36,8 +27,9 @@ let vPanoImgInfo = [] | ||
var vImgPath = json.street_view[1].street[0].img_path | ||
let vUrl = "https://map0.daumcdn.net/map_roadview" + vImgPath + vImgPath.substr(vImgPath.lastIndexOf("/")) + "_" | ||
let vUrl = streetview.gvType[vType].imgUrl(vImgPath) | ||
let vNum = 1, size = 512; | ||
for ( let y = 0; y < 4; y++ ) { | ||
for ( let x = 0; x < 8; x++ ) { | ||
vPanoImgInfo.push( { "x": x * size, "y" : y*size | ||
, "src": vUrl + ("0"+vNum).substr(-2) +".jpg" } ) | ||
vPanoImgInfo.push( { x:x*size, y:y*size, type:vType | ||
, src: vUrl + ("0"+vNum).substr(-2) +".jpg" } ) | ||
vNum++ | ||
@@ -47,3 +39,4 @@ } | ||
} else if ( vType == "naver" ) { | ||
let vUrl = "https://panorama.pstatic.net/image/" + vId + "/512/M/" | ||
let vUrl = streetview.gvType[vType].imgUrl(vId) | ||
let size = 512 | ||
@@ -54,3 +47,3 @@ let vArr = ['l','f','r','b','d','u'] | ||
for ( let x = 0; x < 2; x++ ) { | ||
vPanoImgInfo.push( { x: x*size + (xx*2)*size , y : y*size | ||
vPanoImgInfo.push( { x: x*size + (xx*2)*size , y:y*size, type:vType | ||
, src: vUrl + vArr[xx] +"/" + (x+1) + "/" + (y+1) } ) | ||
@@ -61,7 +54,9 @@ } | ||
} else if ( vType == "google" ) { | ||
let vUrl = "https://streetviewpixels-pa.googleapis.com/v1/tile?cb_client=maps_sv.tactile&zoom=3&panoid=" + vId | ||
let vUrl = streetview.gvType[vType].imgUrl(vId) | ||
let size = 512 | ||
for ( let y = 0; y < 4; y++ ) { | ||
for ( let x = 0; x < 7; x++ ) { | ||
vPanoImgInfo.push( { x: x*size , y : y*size | ||
vPanoImgInfo.push( { x: x*size , y : y*size, type:vType | ||
, src: vUrl + "&x=" + x + "&y=" + y } ) | ||
@@ -71,35 +66,35 @@ } | ||
} | ||
options.panoImgInfo = vPanoImgInfo | ||
streetview.queueImg.push(options) | ||
streetview.download() | ||
}, | ||
gvDownloading : false, | ||
download : () => { | ||
if ( streetview.gvDownloading ) return | ||
streetview.gvDownloading = true | ||
if ( streetview.queueImg.length == 0) { | ||
streetview.gvDownloading = false | ||
return | ||
} | ||
const options = streetview.queueImg.shift() | ||
const vPanoImgInfo = options.panoImgInfo | ||
return await streetview.mergeImages(vPanoImgInfo, vType) | ||
streetview.mergeImages(vPanoImgInfo, options.type) | ||
.then(b64 => { | ||
const vFilePathNm = streetview.getFileName(options) | ||
var data = b64.replace(/^data:image\/\w+;base64,/, ""); | ||
var buf = Buffer.from(data, 'base64'); | ||
return buf } ) | ||
return fs.writeFile(vFilePathNm, buf, ()=> { | ||
console.log("download complete : " + options.id + " => " + vFilePathNm ) | ||
streetview.gvDownloading = false | ||
streetview.download() | ||
}) | ||
}) | ||
}, | ||
mergeImages : (sources, pType) => { | ||
return new Promise(function (resolve) { | ||
let options = { | ||
format: 'image/png', | ||
quality: 0.92 | ||
} | ||
let canvas = new Canvas() | ||
if ( pType == "kakao" ) { | ||
canvas.width = 4096 | ||
canvas.height = 2304 | ||
} else if ( pType == "naver" ) { | ||
canvas.width = 1024 * 6 | ||
canvas.height = 1024 | ||
} else if ( pType == "google" ) { | ||
canvas.width = 3584 | ||
canvas.height = 1664 | ||
} | ||
var ctx = canvas.getContext('2d'); | ||
ctx.fillStyle = 'black'; | ||
ctx.fillRect(0, 0, canvas.width, canvas.height); | ||
var images = sources.map(function (source) { return new Promise(function (resolve, reject) { | ||
var img = new Image(); | ||
img.crossOrigin = options.crossOrigin; | ||
img.onerror = function () { return reject(new Error('Couldn\'t load image : ' + img.src)); }; | ||
@@ -112,6 +107,12 @@ img.onload = function () { return resolve(Object.assign({}, source, { img: img })); }; | ||
.then(function (images) { | ||
images.forEach(function (image) { // 개개 이미지 로드 | ||
return ctx.drawImage(image.img, image.x || 0, image.y || 0) | ||
let canvas = new Canvas() | ||
canvas.width = streetview.gvType[pType].width | ||
canvas.height = streetview.gvType[pType].height | ||
let ctx = canvas.getContext('2d') | ||
ctx.fillStyle = 'black' | ||
ctx.fillRect(0, 0, canvas.width, canvas.height) | ||
images.forEach(function (image) { | ||
return ctx.drawImage(image.img, image.x, image.y) | ||
}) | ||
return canvas.toDataURL(options.format, options.quality); | ||
return canvas.toDataURL('image/png', 0.92); | ||
})); | ||
@@ -126,4 +127,6 @@ }); | ||
if ( vFilePathNm.substr(-1) == "/" ) { | ||
streetview.makeFolder(vFilePathNm,fs) | ||
streetview.makeFolder(vFilePathNm,fs) | ||
vFilePathNm += options.id + ".png" | ||
} else { | ||
streetview.makeFolder(vFilePathNm.substr(0, vFilePathNm.lastIndexOf("/")),fs) | ||
} | ||
@@ -133,16 +136,16 @@ } | ||
}, | ||
getImgPreview : (options) => { | ||
saveImgPreview : (options) => { | ||
const vType = options.type | ||
let vId = options.id | ||
const vId = options.id | ||
if ( vType == "kakao" ) { | ||
streetview.fetch("https://rv.maps.daum.net/roadview-search/searchNodeInfo.do?OUTPUT=json&ID="+vId).then((response)=>{ | ||
let vImgPath = response.street_view[1].street[0].img_path | ||
options.url = "https://map1.daumcdn.net/map_roadview" + vImgPath + ".jpg" | ||
options.url = streetview.gvType[vType].imgPreUrl(vImgPath) | ||
streetview.getImgPreviewDownload(options) | ||
}) | ||
} else if ( vType == "naver" ) { | ||
options.url = "https://panorama.pstatic.net/image/" + vId + "/512/P" | ||
options.url = streetview.gvType[vType].imgPreUrl(vId) | ||
streetview.getImgPreviewDownload(options) | ||
} else if ( vType == "google" ) { | ||
options.url = "https://streetviewpixels-pa.googleapis.com/v1/tile?cb_client=maps_sv.tactile&x=0&y=0&zoom=0&nbt=1&fover=2&panoid=" + vId | ||
options.url = streetview.gvType[vType].imgPreUrl(vId) | ||
streetview.getImgPreviewDownload(options) | ||
@@ -171,4 +174,24 @@ } | ||
} | ||
}, | ||
gvType : { | ||
kakao : { | ||
width : 4896, | ||
height : 2304, | ||
imgUrl : (vImgPath) => "https://map0.daumcdn.net/map_roadview" + vImgPath + vImgPath.substr(vImgPath.lastIndexOf("/")) + "_", | ||
imgPreUrl : (vImgPath) => "https://map1.daumcdn.net/map_roadview" + vImgPath + ".jpg" | ||
}, | ||
naver : { | ||
width : 6144, | ||
height : 1024, | ||
imgUrl : (pId) => "https://panorama.pstatic.net/image/" + pId + "/512/M/", | ||
imgPreUrl : (pId) => "https://panorama.pstatic.net/image/" + pId + "/512/P" | ||
}, | ||
google : { | ||
width : 3584, | ||
height : 1664, | ||
imgUrl : (pId) => "https://streetviewpixels-pa.googleapis.com/v1/tile?cb_client=maps_sv.tactile&zoom=3&panoid=" + pId, | ||
imgPreUrl : (pId) => "https://streetviewpixels-pa.googleapis.com/v1/tile?cb_client=maps_sv.tactile&x=0&y=0&zoom=0&nbt=1&fover=2&panoid=" + pId | ||
} | ||
} | ||
} | ||
module.exports = streetview |
{ | ||
"name": "streetview-panorama", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "> CLI app helper", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -0,1 +1,5 @@ | ||
# streetview-panorama | ||
get street view images for google map, naver map, kakao map | ||
``` | ||
const streetview = require('streetview-panorama') | ||
@@ -7,6 +11,21 @@ | ||
streetview.getImgPreview( { id:"e75tezRrNRrTbh6k7Nvxsw", type:"naver" } ) | ||
streetview.getImgPreview( { id:"1071043104", type:"kakao", fileName:'./panorama/' } ) | ||
streetview.getImgPreview( { id:"AF1QipNj7fskmGw14klOjldXQ6WDR4d2OrUJezadVcpi", type:"google", fileName:'./panorama/aaa6.png' } ) | ||
streetview.saveImgPreview( { id:"e75tezRrNRrTbh6k7Nvxsw", type:"naver" } ) | ||
streetview.saveImgPreview( { id:"1071043104", type:"kakao", fileName:'./panorama/' } ) | ||
streetview.saveImgPreview( { id:"AF1QipNj7fskmGw14klOjldXQ6WDR4d2OrUJezadVcpi", type:"google", fileName:'./panorama/aaa6.png' } ) | ||
``` | ||
# saveImg | ||
* naver(6144*1024) | ||
![Alt text](/example/naver.png "naver streetview image") | ||
* kakao(4896*2304) | ||
![Alt text](/example/kakao.png "kakao streetview image") | ||
* google(3584*1664) | ||
![Alt text](/example/google.png "google streetview image") | ||
# saveImgPreview | ||
* naver | ||
![Alt text](/example/naverPreview.png "naver streetview preview image") | ||
* kakao | ||
![Alt text](/example/kakaoPreview.png "kakao streetview preview image") | ||
![Alt text](/example/googlePreview.png "google streetview preview image") |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9464
174
31