Basic popup overlay for an 'ol' map. By default the map is centred so that the popup is entirely visible.
Compatible with OpenLayers version 3, 4, 5 and 6 (see note in Install - Parcel,
Webpack etc. regarding installing the appropriate version
of ol-popup
for OpenLayers).
The examples demonstrate usage and can be viewed online thanks to raw.githack.com:
- Basic usage
- Create a popup instance, show it on single-click specifying the content
- DOM Events
- Handle DOM events triggered by interacting with elements within the popup content
- Scroll
- Controlling popup dimensions and scrolling overflowing content
- Multiple popups
- Add a new popup each time the maps is clicked
- Bundling with
ol
package (Parcel, Webpack...)- To use the popup with the
ol
package and a module bundler such as Parcel, Webpack etc. see ol-popup-examples.
- To use the popup with the
The source for all examples can be found in examples.
Load ol-popup.js
after OpenLayers. The popup overlay is available as Popup
or ol.Overlay.Popup
.
<script src="https://unpkg.com/[email protected]"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/src/ol-popup.css" />
NPM package: ol-popup.
Install the package via npm
npm install ol-popup --save
ol
package prior to v5 you'll need to install [email protected]
.
The CSS file ol-popup.css
can be found in ./node_modules/ol-popup/src
To use the popup with the ol
package and a module bundler such as Parcel, Webpack etc. see ol-popup-examples.
Extends ol.Overlay
OpenLayers Popup Overlay. See the examples for usage. Styling can be done via CSS.
Parameters
opt_options
olx.OverlayOptions options as defined by ol.Overlay. Defaults to{autoPan: true, autoPanAnimation: {duration: 250}}
Show the popup.
Parameters
coord
ol.Coordinate Where to anchor the popup.html
(String | HTMLElement) String or element of HTML to display within the popup.
Returns Popup The Popup instance
Hide the popup.
Returns Popup The Popup instance
Indicates if the popup is in open state
Returns Boolean Whether the popup instance is open
Contributions are welcome, please create an issue first to discuss any potential contributions.
The API section of the README.md
is generated from the JSDoc comments in the source code. To update the API docs edit the comments in the code then run:
npm run doc
In order to use the doc
npm script you will need to install the devDependencies
:
npm install --only=dev
MIT (c) Matt Walker.
Based on an example by Tim Schaub posted on the OL3-Dev list.
If you find the popup useful you might also like the ol-layerswitcher.