简体   繁体   中英

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
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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