OpenLayers Street View
Street View implementation for Open Layers.
Tested with OpenLayers version 5, 6 and 7. For Ol5, you must set a custom "target" to prevent the control from being rendered at the default target ("ol-overlaycontainer-stopevent"), because that messes up the events and breaks the control.
Disclaminer
If you are going to use this module, read the Google Terms of Service.
Examples
- Basic usage: create an OpenLayers map instance, and pass that map and options to the Street View constructor.
Usage
const opt_options = {
apiKey: null,
size: 'lg',
zoomOnInit: 18,
resizable: true,
sizeToggler: true,
defaultMapSize: 'expanded',
autoLoadGoogleMaps: true,
target: 'map',
language: 'en',
i18n: {...},
}
const streetView = new StreetView(opt_options);
map.addControl(streetView);
Methods
streetView.init()
const googleStreetViewPanorama = streetView.getStreetViewPanorama();
const vectorLayer = streetView.getPegmanLayer();
const rasterLlayer = streetView.getStreetViewLayer();
const googleStreetViewPanorama = streetView.showStreetView(coords);
streetView.hideStreetView();
streetView.setMap(null);
Events
streetView.once(`loadLib`, () => console.log('Fired once after the Google library is loaded'))
streetView.on(`streetViewInit`, () => console.log('Fired everytime Street View mode is activated'))
streetView.on(`streetViewExit`, () => console.log('Fired everytime after is exited'))
Install
Browser
JS
Load ol-street-view.js
after OpenLayers and interactjs. StreetView is available as StreetView
.
<script src="https://unpkg.com/ol-street-view@2.1.0"></script>
CSS
<link rel="stylesheet" href="https://unpkg.com/ol-street-view@2.1.0/dist/css/ol-street-view.min.css" />
Parcel, Webpack, etc.
NPM package: ol-street-view.
Install the package via npm
npm install ol-street-view
JS
import StreetView, { Options, i18n, SVEventTypes, Language, BtnControlSize, MapSize } from 'ol-street-view';
CSS
import 'ol-street-view/lib/style/css/ol-street-view.css';
import 'ol-street-view/lib/style/scss/ol-street-view.scss';
TypeScript type definition
TypeScript types are shipped with the project in the dist directory and should be automatically used in a TypeScript project. Interfaces are provided for the Options.
Todo
- Find the argument in the XYZ request that enables the Photo Spheres in the map
- ~~Add resizable screen option~~
- Add feedback support when element can't be dropped
- Add extra layout (vertical)
Add scss- ~~Add size toggler~~
- Improve scss style (add some variables)