Remove all features from data layer

I used something like:

var map;
function initialize() {
  map = new google.maps.Map(document.getElementById('map-canvas'), {
    zoom: 4,
    center: {lat: -28, lng: 137.883}

google.maps.event.addDomListener(window, 'load', initialize);

to load a geojson shape file to the layer of my map. In the shape file, there are a couple of 'feature' classes defining polygons to be drawn on the map. Up until here I have no problems.

Later on though, I want to load another geojson file over the other one (replacing the drawn 'features' on the map). When you just load another file over the other one it just redraws it over the other one. How on earth do you clear the layer of all the features before loading in the new geojson shape file?

I've tried using with a loop, but I can't seem to get all the features from the layer.


This will iterate over all the features and remove them from {
    // If you want, check here for some constraints.;

Edit 1: Explanation Map data forEach function use callbacks, so you have to give a callback function as parameter:

var callback = function(){ alert("Hi, I am a callback"); };;

Now for each element in data it will show an alert. It's also possible to give callbacks with parameter, like in the code shown above.

   var callback = function(feature) {
        // If you want, check here for some constraints.;

Further explanation and examples:

Seems that the is a collection of 'feature' classes.

So you can use the to iterate through and remove each feature in the collection

Need Your Help

Hibernate Validator - @Length - How to specify separate message for min and max?

java bean-validation hibernate-validator

I am using Hibernate validator for form validation in my web-app. I am using the @Length annotation for my String attribute as follows:

Docker won't start on Windows: Not Enough memory to start docker

windows docker virtual-machine hyper-v

I am trying to get started with Docker on Windows. My machine has 4GB of RAM and a 1.9GHz - 2.5GHz Intel i5 processor, running Windows 10 Pro x64. I know these aren't powerful specs, but I would have