Skip to main content
Added Fiddle
Source Link
Lars
  • 2.2k
  • 2
  • 19
  • 33

Use a ol.StyleFunction() and get the name (or any other - depending on the source) attribute of the feature. E.g.:

// vector layer
var vector = new ol.layer.Vector({
    source: new ol.source.Vector({
        format: new ol.format.GeoJSON(),
        url: 'https://raw.githubusercontent.com/openlayers/ol3/6838fdd4c94fe80f1a3c98ca92f84cf1454e232a/examples/data/geojson/countries.geojson'
    }),
    style: function(feature, res){
        // replace "Germany" with any country name you would like to display...
        if(feature.get("name") == "Germany"){
            return new ol.style.Style({
                stroke: new ol.style.Stroke({
                    color: 'red',
                    width: 2
                })
            });
        }
    }
});

See Demo on JSFiddle

Use a ol.StyleFunction() and get the name attribute of the feature. E.g.:

// vector layer
var vector = new ol.layer.Vector({
    source: new ol.source.Vector({
        format: new ol.format.GeoJSON(),
        url: 'https://raw.githubusercontent.com/openlayers/ol3/6838fdd4c94fe80f1a3c98ca92f84cf1454e232a/examples/data/geojson/countries.geojson'
    }),
    style: function(feature, res){
        // replace "Germany" with any country name you would like to display...
        if(feature.get("name") == "Germany"){
            return new ol.style.Style({
                stroke: new ol.style.Stroke({
                    color: 'red',
                    width: 2
                })
            });
        }
    }
});

Use a ol.StyleFunction() and get the name (or any other - depending on the source) attribute of the feature. E.g.:

// vector layer
var vector = new ol.layer.Vector({
    source: new ol.source.Vector({
        format: new ol.format.GeoJSON(),
        url: 'https://raw.githubusercontent.com/openlayers/ol3/6838fdd4c94fe80f1a3c98ca92f84cf1454e232a/examples/data/geojson/countries.geojson'
    }),
    style: function(feature, res){
        // replace "Germany" with any country name you would like to display...
        if(feature.get("name") == "Germany"){
            return new ol.style.Style({
                stroke: new ol.style.Stroke({
                    color: 'red',
                    width: 2
                })
            });
        }
    }
});

See Demo on JSFiddle

Added link and a comment
Source Link
Lars
  • 2.2k
  • 2
  • 19
  • 33

Use a stylefunctionol.StyleFunction() and get the name attribute of the feature. E.g.:

// vector layer
var vector = new ol.layer.Vector({
    source: new ol.source.Vector({
        format: new ol.format.GeoJSON(),
        url: 'https://raw.githubusercontent.com/openlayers/ol3/6838fdd4c94fe80f1a3c98ca92f84cf1454e232a/examples/data/geojson/countries.geojson'
    }),
    style: function(feature, res){
        // replace "Germany" with any country name you would like to display...
        if(feature.get("name") == "Germany"){
            return new ol.style.Style({
                stroke: new ol.style.Stroke({
                    color: 'red',
                    width: 2
                })
            });
        }
    }
});

Just replace Germany with any country you want to display.

Use a stylefunction and get the name attribute of the feature. E.g.:

// vector layer
var vector = new ol.layer.Vector({
    source: new ol.source.Vector({
        format: new ol.format.GeoJSON(),
        url: 'https://raw.githubusercontent.com/openlayers/ol3/6838fdd4c94fe80f1a3c98ca92f84cf1454e232a/examples/data/geojson/countries.geojson'
    }),
    style: function(feature, res){
        if(feature.get("name") == "Germany"){
            return new ol.style.Style({
                stroke: new ol.style.Stroke({
                    color: 'red',
                    width: 2
                })
            });
        }
    }
});

Just replace Germany with any country you want to display.

Use a ol.StyleFunction() and get the name attribute of the feature. E.g.:

// vector layer
var vector = new ol.layer.Vector({
    source: new ol.source.Vector({
        format: new ol.format.GeoJSON(),
        url: 'https://raw.githubusercontent.com/openlayers/ol3/6838fdd4c94fe80f1a3c98ca92f84cf1454e232a/examples/data/geojson/countries.geojson'
    }),
    style: function(feature, res){
        // replace "Germany" with any country name you would like to display...
        if(feature.get("name") == "Germany"){
            return new ol.style.Style({
                stroke: new ol.style.Stroke({
                    color: 'red',
                    width: 2
                })
            });
        }
    }
});
Source Link
Lars
  • 2.2k
  • 2
  • 19
  • 33

Use a stylefunction and get the name attribute of the feature. E.g.:

// vector layer
var vector = new ol.layer.Vector({
    source: new ol.source.Vector({
        format: new ol.format.GeoJSON(),
        url: 'https://raw.githubusercontent.com/openlayers/ol3/6838fdd4c94fe80f1a3c98ca92f84cf1454e232a/examples/data/geojson/countries.geojson'
    }),
    style: function(feature, res){
        if(feature.get("name") == "Germany"){
            return new ol.style.Style({
                stroke: new ol.style.Stroke({
                    color: 'red',
                    width: 2
                })
            });
        }
    }
});

Just replace Germany with any country you want to display.