OpenLayers Street View
Street View implementation for Open Layers.
Tested with OpenLayers versions 5 to 10. 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.
Disclaimer
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.
- Manually Load Google Maps Library. By default, the Google Maps Library is auto loaded by this module, but it can be disabled if you have already loaded it in another place, or if you want to use a custom Google Maps version.
Usage
const opt_options = {
apiKey: null,
size: 'lg',
radius: 100,
updatePegmanToClosestPanorama: true,
transparentButton: false,
zoomOnInit: 18,
minZoom: null,
resizable: true,
sizeToggler: true,
defaultMapSize: 'expanded',
autoLoadGoogleMaps: true,
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@3.0.0"></script>
CSS
<link rel="stylesheet" href="https://unpkg.com/ol-street-view@3.0.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 scssAdd size togglerImprove scss style (add some variables)