Implementation of multiple popu display based on openlayer4

Posted by justinma on Sun, 05 Apr 2020 02:43:43 +0200

                     . You can click the official website to pop up the demo. Based on this logic, you can write a dynamic overlay layer and the dom nodes you need.

Source code

<!DOCTYPE html>
    <link rel="stylesheet" href="" type="text/css">
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
    <script src=",Element.prototype.classList,URL"></script>
    <script src=""></script>
      .ol-popup {
        position: absolute;
        background-color: white;
        -webkit-filter: drop-shadow(0 1px 4px rgba(0,0,0,0.2));
        filter: drop-shadow(0 1px 4px rgba(0,0,0,0.2));
        padding: 15px;
        border-radius: 10px;
        border: 1px solid #cccccc;
        bottom: 12px;
        left: -50px;
        min-width: 50px;
      .ol-popup:after, .ol-popup:before {
        top: 100%;
        border: solid transparent;
        content: " ";
        height: 0;
        width: 0;
        position: absolute;
        pointer-events: none;
      .ol-popup:after {
        border-top-color: white;
        border-width: 10px;
        left: 48px;
        margin-left: -10px;
      .ol-popup:before {
        border-top-color: #cccccc;
        border-width: 11px;
        left: 48px;
        margin-left: -11px;
      .ol-popup-closer {
        text-decoration: none;
        position: absolute;
        top: 2px;
        right: 8px;
      .ol-popup-closer:after {
        content: "✖";
    <div id="map" class="map"></div>
        var map = new ol.Map({
        layers: [
          new ol.layer.Tile({
            source:  new ol.source.OSM()
        target: 'map',
        view: new ol.View({
          center: [115.55145, 23.01361],
          zoom: 9
          //Pop up layer
      var points=[[115.55145, 23.01361],[115.55145, 24.01361],[116.55145, 23.01361]];

          var tmp=document.createElement('div');
          tmp.innerHTML='<div>hi hi</div>';
          var overlay_tmp= new ol.Overlay({
            element: tmp,
            autoPan: true,
            autoPanAnimation: {
              duration: 250

       map.on('singleclick', function(evt) {

Topics: Android