简体   繁体   English

在 openlayers 3 中搜索标记

[英]Search for markers in openlayers 3

I don't understand how to search for the markers that I have added to the map.我不明白如何搜索已添加到地图的标记。 The search would be carried out by the title.搜索将按标题进行。 I put a piece of my code我放了一段我的代码

var markers_id = new ol.layer.Vector({
            source: new ol.source.Vector({
              features: [
                new ol.Feature({    
                  geometry: new ol.geom.Point([14, 25]),
                  name: 'Sala Polivalente',
                  title: '16APPB050',
                  content: "<div>Sala Polivalente<br/><img src='images/APPB050.png' /></div>"
                }),
                new ol.Feature({    
                  geometry: new ol.geom.Point([19.5, 27.3]),
                  name: 'ASEO FEMENINO Y DISCAPACITADO FEMENINO',
                  title: '16APPB030',
                  content:  "<div>ASEO FEMENINO Y DISCAPACITADO FEMENINO<br/><img src='images/APPB030.png' /></div>"
                }),
                new ol.Feature({     
                  geometry: new ol.geom.Point([19.5, 25.7]),
                  name: 'DISTRIBUIDOR CENTRAL',
                  title: '16APPB020',
                  content:  "<div>DISTRIBUIDOR CENTRAL<br/><img src='images/APPB020.png' /></div>"
                }),

                new ol.Feature({     
                  geometry: new ol.geom.Point([17.5, 27.3]),
                  name: '>ASEO MASCULINO Y DISCAPACITADO MASCULINO',
                  title: '16APPB040',
                  content:  "<div>ASEO MASCULINO Y DISCAPACITADO MASCULINO<br/><img src='images/APPB040.png' /></div>"
                })
                      ]
                  })
                
              });

map.addLayer(markers_id);

You would check each feature for the property value you are search for您将检查您要搜索的属性值的每个功能

markers_id.getSource().forEachFeature(function(feature){
  if (feature.get('title') == searchString) {
     // found feature
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM