1

How do I not show any countries except Zambia?

<script type="text/javascript">
         (function() { 
         var inputs  = 'Zambia';//may be any country
         var raster = new ol.layer.Tile({
            source: new ol.source.OSM(),
           projection: 'EPSG:3857'
          });
        var vector = new ol.layer.Vector({
             source: new ol.source.Vector({
             ormat: new ol.format.GeoJSON(),
              url: 'countries.geojson'
            }),
           style: function(feature, res){
               if(feature.get("name") == inputs){
                  return new ol.style.Style({
                  stroke: new ol.style.Stroke({
                   color: 'red',
                   width: 2
                  })
                   });
              } 
          }  
       });
     var map1 = new ol.Map({
        target: 'map',
        layers: [raster, vector],
        view: new ol.View({
     center: ol.proj.transform([27.60315,-13.41099],'EPSG:4326','EPSG:3857'),
     zoom: 6
    })
     });
  })();
</script>

1 Answer 1

1
var inputs  = 'Zambia';
                    var raster = new ol.layer.Tile({
                        source: new ol.source.OSM(),
                            projection: 'EPSG:3857'
                    });

                    // vector layer
                    var vector = new ol.layer.Vector({
                         features: [vectorSource],
                        source: new ol.source.Vector({
                            format: new ol.format.GeoJSON(),
                            url: 'countries.geojson'
                        }),
                        style: function(feature, res){
                            if(feature.get("name") != inputs){
                                return new ol.style.Style({
                                     fill: new ol.style.Fill({
                                         color: 'rgb(181, 208, 208)'
                                       })
                                });
                            }
                            if(feature.get("name") == inputs){
                                return new ol.style.Style({
                                    stroke: new ol.style.Stroke({
                                        color: '#319FD3',
                                        width: 2
                                      })
                                });
                            }
                        }
                    });

                    // create first map
                    var map1 = new ol.Map({
                        target: 'map',
                        layers: [ raster,vector],
                        view: new ol.View({
                            center: ol.proj.transform([27.60315,-13.41099], 'EPSG:4326', 'EPSG:3857'),
                            zoom: 6
                        })
                    });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.