Skip to main content

Streetview SDK

Integrate Streetview in HTML element with Streetview-SDK

Description

Streetview SDK allows users to embed streetview.vn 360° image viewer into user's HTML element.

tip

When using that, just use our Enterprise Dashboard or guild API Key to create your API Key try for free!

Usage

To integrate streetview.vn 360° image viewer on your web applications, you need to add the code snippet below in your HTML file. This code snippet will embed streetview.vn 360° image viewer via Streetview-SDK library.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="./logo.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Khám phá đường phố Việt Nam | Streetview.vn</title>
<meta
name="description"
content="Khám phá đường phố tại Việt Nam bằng công nghệ 360° độc đáo với Streetview.vn"
/>
<meta
name="keywords"
content="streetview.vn, xem duong pho viet nam, vietnam streetview, xem duong pho, street, view, kham pha duong pho, duong, pho"
/>
<meta property="og:image" content="./logo_ngang.png" />
<meta property="twitter:image" content="./logo_ngang.png" />
<script src="https://streetview.vn/sdk/streetviewvn.umd.js"></script>
<link
rel="stylesheet"
href="https://streetview.vn/sdk/style.css"
type="text/css"
/>
</head>

<body style="margin: 0; padding: 0;">
<div
id="root"
style="width: 100dvw; height: 100dvh; padding: 0; margin: 0;"
></div>
<script type="text/javascript">
const container = document.getElementById("root");
const { Photo } = StreetViewVN_Viewer;
const { PhotoAdapter } = StreetViewVN_Viewer.adapter;
const { VirtualTourPlugin, CompassPlugin } = StreetViewVN_Viewer.plugins;

const BASE_PANORAMA = {
baseUrl: "http://streetview.vn/loader_hd.png",
width: 1280,
cols: 2,
rows: 1,
tileUrl: () => null,
};

const photo = new Photo({
apiKey: "YOUR_API_KEY",
lang: {
zoom: "Thu phóng",
zoomOut: "Thu nhỏ",
zoomIn: "Phóng to",
moveUp: "Tiến",
moveDown: "Lùi",
moveLeft: "Trái",
moveRight: "Phải",
description: "Chi tiết",
download: "Tải xuống",
fullscreen: "Toàn màn hình",
loading: "Đang tải...",
menu: "Danh mục",
close: "Đóng",
twoFingers: "Sử dụng 2 ngón tay để điều hướng",
ctrlZoom: "Sử dụng Ctrl + scroll để thu phóng ảnh",
loadError: "Không thể tải hình ảnh 360 lúc này",
webglError: "Trình duyệt của bạn không hỗ trợ WebGL",
},
container,
navbar: false,
panorama: BASE_PANORAMA,
loadingImg: "http://streetview.vn/logo.svg",
adapter: [
PhotoAdapter,
{
showErrorTile: false,
baseBlur: false,
resolution: 64,
shouldGoFast: () => false,
},
],
defaultZoomLvl: 0,
defaultYaw: 0,
defaultPitch: 0,
plugins: [
[
CompassPlugin,
{
size: "34px",
position: ["top", "right"],
},
],
[
VirtualTourPlugin,
{
arrowEnabled: false,
preload: true,
},
],
],
});
photo
.getPlugin(VirtualTourPlugin)
.setCurrentLatLng({ lng: 105.836501728, lat: 21.037001424 }, true);
</script>
</body>
</html>

Photo

ParameterTypeRequiredExampleDescription
apiKeystringyesYOUR_API_KEYYour API_KEY to call the API.
langobjectnoSee details ↓Tooltip description of elements in the streetview-sdk interface.
navbarbooleannoEnable toolbar with image zoom in/out, rotate orientation.
panoramaobjectnoSee details ↓Configure the default 360 image to display if the image and its properties are not available.
loadingImgstringnohttp://www.streetview.vn/logo.svgImage loading.
defaultZoomLvlnumbernoConfigure default zoom of the image.
defaultYawnumbernoyaw * 180 / Math.PIConfigure the default yaw angle of the image.
defaultPitchnumbernopitch * 180 / Math.PIConfigure the image's strong pitch angle.
containerHTMLElementyesDOM element associated with viewer. Can pass useRef(...).current.
adapterAdapterConstructor | [AdapterConstructor, any]yesSee details ↓Used to configure and override the configuration of the @photo-sphere-viewer library. You can use our PhotoAdapter class or rewrite it by inheriting the @photo-sphere-viewer/equirectangular-tiles-adapter class.
pluginsArray<PluginConstructor | [PluginConstructor, any]>yesSee details ↓Used to use streetview-sdk plugins.

lang

{
"zoom": "Zoom",
"zoomOut": "Zoom Out",
"zoomIn": "Zoom In",
"moveUp": "Move Up",
"moveDown": "Move Down",
"moveLeft": "Move Left",
"moveRight": "Move Right",
"description": "Description",
"download": "Download",
"fullscreen": "Fullscreen",
"loading": "Loading",
"menu": "Menu",
"close": "Close",
"twoFingers": "Use 2 fingers to navigate",
"ctrlZoom": "Use Ctrl + scroll to zoom in and out",
"loadError": "Load error",
"hintWheel": "Drag or swipe left - right - up - down to view 360 images",
"webglError": "Your browser does not support WebGL"
}

panorama

{
"baseUrl": "http://www.streetview.vn/loader_hd.png",
"width": 1280,
"cols": 2,
"rows": 1,
"tileUrl": null
}

adapter

adapter:[
PhotoAdapter, {
showErrorTile: false,
baseBlur: false,
resolution: 64,
shouldGoFast: () => false
}]

Plugins

To use plugins you need to initialize that plugin.

const { VirtualTourPlugin, CompassPlugin } = StreetViewVN_Viewer.plugins;

CompassPlugin

Is a plugin to display compass. It has the function of displaying the direction of the viewing angle and the nodes near the viewing point.

  [CompassPlugin, {
size: "34px",
position: ["top", "right"]
}]
  • Plugin configuration
  {
size: '120px',
position: ['top', 'left'],
backgroundSvg: compass,
coneColor: 'rgba(255, 255, 255, 0.5)',
navigation: true,
navigationColor: 'rgba(255, 0, 0, 0.2)',
hotspots: [],
hotspotColor: 'rgba(0, 0, 0, 0.5)',
className: null,
}
ParameterTypeRequiredExampleDescription
sizestringno'120px'Size of compass.
positionstring | [string, string]no'top left'Position of the compass.
backgroundSvgstringnoSVG used as compass background.
coneColorstringyes'rgba(255, 255, 255, 0.5)'Color of compass cone.
navigationbooleannotrueAllow clicking on compass to rotate viewer.
navigationColorstringno'rgba(255, 0, 0, 0.2)'Color of the cone.
hotspotsCompassHotspot[]nocolor?: 'rgba(255, 0, 0, 0.2)'Small dots visible on the compass (will contain any markers with "compass" data).
hotspotColorstringno'rgba(0, 0, 0, 0.5)'Default color of hotspot.
classNamestringnoCSS classes added to the compass element.
info

You can see detailed example here Example

PlanPlugin

Is a plugin to display minimap with zoom in and out functions and point to the point where your pixel is located

  [
PlanPlugin,
{
defaultZoom: 10,
visibleOnLoad: true,
pinSize: 80,
enabledLocate: false,
size: {width: '180px', height: '120px'}
}
],
  • Plugin configuration:
{
coordinates: null,
bearing: 0,
size: {width: '300px', height: '200px'},
position: ['bottom', 'left'],
visibleOnLoad: true,
pinImage: pin,
pinSize: 35,
enabledLocate: true,
onMaximized: () => {},
onMinimize: () => {},
onChangeCenter: () => {},
spotStyle: {
size: 15,
image: null,
color: 'white',
hoverSize: null,
hoverImage: null,
hoverColor: null,
hoverBorderSize: 4,
hoverBorderColor: 'rgba(255, 255, 255, 0.8)',
},
defaultZoom: 15,
layers: [{
urlTemplate: null,
attribution: OSM_ATTRIBUTION,
name: OSM_LABEL,
}],
configureLeaflet: null,
buttons: {
maximize: true,
close: true,
reset: true,
},
}
ParameterTypeRequiredExampleDescription
coordinatesGpsPositionnoVị trí GPS của bức ảnh toàn cảnh hiện tại.
bearingstring | numberno0Độ lệch xoay áp dụng cho chốt trung tâm.
sizeCssSizeno'300px * 200px'Kích thước của bản đồ.
positionstring | [string, string]no'bottom left'Vị trí của bản đồ.
visibleOnLoadbooleannotrueHiển thị bản đồ khi tải ảnh toàn cảnh đầu tiên.
pinImagestringnoSVG hoặc URL hình ảnh được sử dụng cho trung tâm (phải là hình vuông).
pinSizenumberno35Kích thước của điểm trung tâm.
spotStylePlanHotspotStylenoKiểu mặc định của điểm truy cập.
defaultZoomnumberno15Mức thu phóng mặc định.
layersPlanLayernoOpenStreetMapXác định các lớp có sẵn.
configureLeaflet(map: Map)noCho phép bạn cấu hình Leaflet từ đầu.
hotspotsPlanHotspotnoĐiểm truy cập trên bản đồ.
buttonsObjectnoCấu hình các nút bản đồ.
info

You can see detailed example here Example

TrackPlugin

Is a plugin to display lines and pixel points that streetview has recorded.

 [TrackPlugin, {}]
info

You can see detailed example here Example

VirtualTourPlugin

Is a plugin to display 360° photo viewer

  [VirtualTourPlugin, {
arrowEnabled: false,
preload: false
}]
  • Plugin configuration
{
dataMode: 'server',
positionMode: 'gps',
renderMode: '3d',
apiKey: null,
nodes: null,
getNode: getNode,
onLoadNode: () => {},
startNodeId: null,
preload: true,
updateCoordinatesPlan: true,
speed: null,
transitionOptions: {
showLoader: false,
speed: 500,
zoomTo: PSV_DEFAULT_ZOOM,
fadeIn: true,
rotation: true,
},
linksOnCompass: true,
getLinkTooltip: null,
markerStyle: null,
arrowStyle: DEFAULT_ARROW,
markerPitchOffset: null,
arrowPosition: null,
arrowsPosition: {
minPitch: 0.3,
maxPitch: Math.PI / 2,
linkOverlapAngle: Math.PI / 4,
linkPitchOffset: -0.1,
},
map: null,
arrowEnabled: false
}
ParameterTypeRequiredExampleDescription
dataModestringnoclient | serverConfigure data mode.
positionModestringnomanual | gpsConfigure location mode.
speednumbernoSpeed ​​configuration.
renderModestringno3d | 2d | markersConfigure the visibility of the link.
nodesVirtualTourNodenoInitial buttons (client mode).
startNodeIdstringnoId of the initial node, if not defined then the first node will be used.
preloadbooleannotruePreload linked panoramas.
transitionOptionsTransitionOptionsno{ showLoader: true, speed: '20rpm', fadeIn: true, rotation: true }Configures the transition between buttons. Can be a callback.
linksOnCompassbooleannotrueIf the Compass plugin is enabled, it will display links on the compass.
updateCoordinatesPlanbooleannotrueUpdate coordinate plan.
arrowStyleVirtualTourArrowStylenoGlobal arrow style.
markerPitchOffsetnumbernoMarker offset.
arrowPositionstringnotop | bottomPosition of the arrow.
arrowEnabledbooleannotrueShow arrow.
arrowsPositionArrowsPositionOptionsnoConfiguration of the arrow box.
mapMapOptionsnoSpecial configuration when using MapPlugin.
  • Method
NameParameterDescription
onLoadNode()Configure data mode.
getNode()getNode?: (nodeId: string) => VirtualTourNode | Promise<VirtualTourNode>Function to get a button (server mode).
info

You can see detailed example here Example

Definitions

CompassHotspot

type CompassHotspot = ExtendedPosition & {
color?: string;
};

GpsPosition

type GpsPosition = [number, number, number?];

CssSize

type CssSize = {
width: string;
height: string;
};

PlanHotspotStyle

type PlanHotspotStyle = {
/**
* Size of the hotspot
* @default 15
*/
size?: number;
/**
* SVG or image URL used for hotspot
*/
image?: string;
/**
* Color of the hotspot when no image is provided
* @default 'white'
*/
color?: string;
/**
* Size on mouse hover
* @default null
*/
hoverSize?: number;

onMaximized?: () => void,
onMinimize?: () => void,
onChangeCenter?: (c: any) => void,
/**
* SVG or image URL on mouse hover
* @default null
*/
hoverImage?: string;

enabledLocate?: boolean;
/**
* Color on mouse hover
* @default null
*/
hoverColor?: string;
/**
* Size of the border shown on mouse hover
* @default 4
*/
hoverBorderSize?: number;
/**
* Color of the border shown on mouse hover
* @default 'rgba(255, 255, 255, 0.8)'
*/
hoverBorderColor?: string;
};

PlanLayer

type PlanLayer = {
urlTemplate?: string;
layer?: Layer;
name?: string;
attribution?: string;
};

PlanHotspot

type PlanHotspot = PlanHotspotStyle & {
/**
* GPS coordinates of the marker
*/
coordinates: GpsPosition;

/**
* Unique identifier for the {@link SelectHotspot} event
*/
id?: string;

/**
* Tooltip visible on the map
*/
tooltip?: string | {content: string; className?: string};
};

VirtualTourNode

type VirtualTourNode = {
id: string;
panorama: any;
/**
* short name of the node (links tooltip, gallery)
*/
name?: string;
/**
* caption visible in the navbar
*/
caption?: string;
/**
* description visible in the side panel
*/
description?: string;
/**
* data used for this panorama
*/
panoData?: PanoData | PanoDataProvider;
/**
* sphere correction to apply to this panorama
*/
sphereCorrection?: SphereCorrection;
/**
* links to other nodes
*/
links?: VirtualTourLink[];
/**
* GPS position
*/
gps?: GpsPosition;
/**
* thumbnail for the gallery
*/
thumbnail?: string;
/**
* additional markers to use on this node
*/
markers?: Array<MarkerConfig & {gps?: GpsPosition}>;
/**
* configuration of the hotspot when using the MapPlugin
*/
map?: Partial<Point> & Omit<MapHotspot, 'id' | 'yaw' | 'distance'>;
/**
* configuration of the hotspot when using the PlanPlugin
*/
plan?: Omit<PlanHotspot, 'id' | 'coordinates'>;
/**
* Any custom data you want to attach to the node
*/
data?: any;
};

TransitionOptions

transitionOptions?:| Pick<VirtualTourTransitionOptions, 'showLoader' | 'speed' | 'fadeIn' | 'rotation'>| ((
toNode: VirtualTourNode,
fromNode?: VirtualTourNode,
fromLink?: VirtualTourLink
) => VirtualTourTransitionOptions);

VirtualTourArrowStyle

type VirtualTourArrowStyle = {
/**
* URL of an image used for the arrow
*/
image?: string;
/**
* Use a custom element for the arrow
*/
element?: HTMLElement | ((link: VirtualTourLink) => HTMLElement);
/**
* CSS classes added to the element
*/
className?: string;
/**
* Size of the arrow
*/
size?: Size;
/**
* CSS properties to set on the arrow
*/
style?: Record<string, string>;

/** @deprecated */
color?: string;
/** @deprecated */
hoverColor?: string;
/** @deprecated */
outlineColor?: string;

enabledTooltip?: boolean;
};

ArrowsPositionOptions

arrowsPosition?: {
/**
* (3D mode) Minimal vertical view angle
* @default 0.3
*/
minPitch?: number;
/**
* (3D mode) Maximal vertical view angle
* @default PI/2
*/
maxPitch?: number;
/**
* (3D mode) Make transparent links that are close to each other
* @default PI/4
*/
linkOverlapAngle?: number;
/**
* (2D+GPS mode) vertical offset applied to link markers, to compensate for viewer height
* @default -0.1
*/
linkPitchOffset?: number;
}

MapOptions

 map?: {
/**
* URL of the map
*/
imageUrl: string;
/**
* size of the map in pixels
*/
size?: Size;
/**
* bounds of the map in GPS coordinates (minX, minY, maxX, maxY)
*/
extent?: [number, number, number, number];
};