单击矢量层后显示功能名称

问题描述 投票:0回答:3

我是 Openlayers 3 的新用户。我有从 geojson 文件导入的矢量图层。我想在单击矢量图层后显示有关我的功能的信息。 知道我该怎么做吗?

vector geojson openlayers-3
3个回答
0
投票

我使用了here的库来实现此目的。示例代码是

var popup = new ol.Overlay.Popup();
map.addOverlay(popup);

//handling Onclick popup
map.on('click', function(evt) {
 var feature = map.forEachFeatureAtPixel(evt.pixel,
   function(feature, layer) {
    return feature;
  });
 if (feature) {
    var coord = event.feature.getGeometry().getCoordinates();
    popup.show(coord, '<div><h2>Tilte</h2><p>' +feature.get('<property_in_single_quotes>')+ '</p></div>');  
}
});

希望这有帮助


0
投票

看看这些例子:

1) http://openlayers.org/en/v3.14.1/examples/vector-layer.html?q=overlay

2)http://openlayers.org/en/v3.14.1/examples/popup.html?q=overlay

您不是将矢量信息放在地图旁边,而是将其放在您创建的弹出窗口中

<div>


0
投票

我是 OL 和 Java 脚本新手 它们有停止点和坐标,如何才能通过单击矢量对象(停止)来显示其名称。地理位置与特定坐标相关

    var pointsStation = [     //координаты остановок
        {   id:111, name:'Красноярск АВ',
            cords:[92.905977,56.03295]
     var iconFeature = new ol.Feature({
                geometry: new 
        ol.geom.Point(ol.proj.transform(pointsStation[j].cords, 'EPSG:4326', 'EPSG:3857')),
                name: pointsStation[j].name,
                id: 'station-' + pointsStation[j].id

这就是根据坐标设置停靠点名称的方式。你需要点击它们打开一个窗口,里面会显示车站名称、到达和出发时间指定

© www.soinside.com 2019 - 2024. All rights reserved.