Я узнал, что OpenLayer 2 имеет элемент управления OpenLayer.control.featurepopup, который позволяет добавлять всплывающие окна, которые отображаются при наведении курсора на элемент на карте и при нажатии на элемент.Я ищу способ сделать это с OpenLayer 5
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Testing Popups</title>
<link rel="stylesheet" href="https://openlayers.org/en/v5.3.0/css/ol.css" type="text/css">
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 700px;
}
</style>
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
</head>
<body>
Popop!!!!
<div id="map"></div>
<script>
var style,feature, map,vLayer,vSource,fpControl;
$(document).ready(function () {
style = [
new ol.style.Style({
image: new ol.style.Icon(({
scale: .7, opacity: 1,
rotateWithView: false, anchor: [0.5, 1],
anchorXUnits: 'fraction', anchorYUnits: 'fraction',
src: '//raw.githubusercontent.com/jonataswalker/map-utils/master/images/marker.png'
})),
zIndex: 5
})
];
feature = new ol.Feature({
geometry: new ol.geom.Point(new ol.proj.fromLonLat([-0.890000,51.57889])),
name: 'My Bus'
});
feature.setId(1007);
feature.setStyle(style);
// Create map
vSource = new ol.source.Vector();
vLayer = new ol.layer.Vector({
source : vSource
});
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
vLayer
],
view: new ol.View({
center: new ol.proj.fromLonLat([-0.890000,51.57889]),
zoom: 12,
numZoomLevels: 18,
maxResolution: 156543.0339,
})
});
vSource.addFeature(feature);
fpControl = new ol.Control.FeaturePopups({
boxSelectionOptions: {},
layers: [
[
// Uses: Internationalized templates.
vLayer, {
templates: {
hover: '${.name}',
single: '${i18n("Name")}: ${.name}<br>',
item: '<li><a href="#" ${showPopup()}>${.name}</a></li>'
}
}
]
]
});
map.addControl(fpControl);
});
</script>
</body>
</html>
Я ожидаю увидеть всплывающую подсказку, показывающую некоторые свойства вне функции, такие как 'name' и 'id', когда я наведу курсор на эту функцию.и всплывающее окно с той же информацией, когда я нажимаю на функцию.