Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 149846

Open layers 6.1. - popup with multiple points features

$
0
0

I have some bug in my open layer (6.1.) project with a popup bubble. I am not able to create and see the popup and fill it not even in one single GeoJSON layer with cities. I read this without progress: popup with multiple points features I would like just render the name of the city when clicking on the icon.

Index.html

<html lang="en">
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <link rel="icon" href="pic/fav.png" sizes="192x192" />
  <link rel="stylesheet" type="text/css" href="style.css">
  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
  <script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

  <title>Retail Space</title>

</head>

<!--++++++++++++++++++++++++++++++++++++++  BODY  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>

  <body>

    <div id="container">

<!--++++++++++++++++++++++++++++++++++++++  HEADERBAR  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>

      <div id="headerbar">
        <div id="logobar">

        </div>

        <div id="controlbar">

        </div>
      </div>

<!--++++++++++++++++++++++++++++++++++++++  MAPBAR  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>

      <div id="map-container"><div id="popup"></div>
        <div id="tooltip" class="tooltip"></div>
      </div>
      <script src="main.js"></script>


    </div> <!--/container-->
  </body>
</html>

main.js

import GeoJSON from 'ol/format/GeoJSON';
import TileJSON from 'ol/source/TileJSON';
import Map from 'ol/Map';
import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
import View from 'ol/View';
import VectorTileLayer from 'ol/layer/VectorTile';
import VectorTileSource from 'ol/source/VectorTile';
import TileLayer from 'ol/layer/Tile';
import Feature from 'ol/Feature';
import Point from 'ol/geom/Point';
import OSM from 'ol/source/OSM';
import TileWMS from 'ol/source/TileWMS';
import Overlay from 'ol/Overlay';
import {Style, Fill, Stroke, Icon} from 'ol/style';
import {fromLonLat} from 'ol/proj';
import sync from 'ol-hashed';


var iconStyle_municip = new Style({
  image: new Icon({
    anchor: [0.5, 5],
    anchorXUnits: 'fraction',
    anchorYUnits: 'pixels',
    src: 'pic/municip.png'
  })
});

//OSM layer creation
var OSMmap = new TileLayer({
  source: new OSM(),

  format: new GeoJSON({featureProjection: 'EPSG:3857'}),
});

//Obce 5000+ layer creation
var cities = new VectorLayer({
      source: new VectorSource({
        format: new GeoJSON({featureProjection: 'EPSG:3857'}),
        url: 'obce5000geojson.geojson'
      })
    });

cities.setStyle(iconStyle_municip);

//Map initiation
new Map({
  target: 'map-container',

  layers: [OSMmap, cities],

  view: new View({
    center: fromLonLat([15, 49.80]),
    zoom: 8
  }),

});

//tooltip start
var element = document.getElementById('popup');

var popup = new Overlay({
  element: element,
  positioning: 'bottom-center',
  stopEvent: false,
  offset: [0, -50]
});
map.addOverlay(popup);

// display popup on click
map.on('click', function(evt) {
  var feature = map.forEachFeatureAtPixel(evt.pixel,
    function(feature) {
      return feature;
    }
  );
  if (feature) {
    var coordinates = this.getCoordinateFromPixel(evt.pixel);
    popup.setPosition(coordinates);
    $(element).popover({
      'placement': 'top',
      'html': true,
      'content': feature.get('obec')
    });
    $(element).popover('show');
  } else {
    $(element).popover('destroy');
  }
});

Viewing all articles
Browse latest Browse all 149846

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>