Skip to main content
more explanations
Source Link
geogeek
  • 4.6k
  • 5
  • 36
  • 81

You can use the function getFeaturesInExtent(extent), after you read your local geojson file.

So this code should work for you:

vectorLayer = new ol.layer.Vector({
              title: 'Layer',
              source: new ol.source.GeoJSON({
                  projection : 'EPSG:3857',
                 url: 'local_geojson_data.json'
})}) ; //layer viewing the whole data

var selected_features = vectorLayer.getSource.getFeaturesInExtent([minx, miny, maxx, maxy]);
//select only features in extent

selected_vectorLayer = new ol.layer.Vector({
              title: 'selected_Layer',
              source: new ol.source.Vector({
                  features : selected_features
})}) ; //draw those features in a new layer

You can use the function getFeaturesInExtent(extent), after you read your local geojson file.

You can use the function getFeaturesInExtent(extent), after you read your local geojson file.

So this code should work for you:

vectorLayer = new ol.layer.Vector({
              title: 'Layer',
              source: new ol.source.GeoJSON({
                  projection : 'EPSG:3857',
                 url: 'local_geojson_data.json'
})}) ; //layer viewing the whole data

var selected_features = vectorLayer.getSource.getFeaturesInExtent([minx, miny, maxx, maxy]);
//select only features in extent

selected_vectorLayer = new ol.layer.Vector({
              title: 'selected_Layer',
              source: new ol.source.Vector({
                  features : selected_features
})}) ; //draw those features in a new layer
Source Link
geogeek
  • 4.6k
  • 5
  • 36
  • 81

You can use the function getFeaturesInExtent(extent), after you read your local geojson file.