I am currently working on a map-based service. There the user can select items on the map by drawing rectangles and polygons using the drawingManager. I push these shapes to an global array after they are created to keep control on them like this:
      google.maps.event.addListener(drawingManager, 'overlaycomplete', function(e) {
      if (e.type != google.maps.drawing.OverlayType.MARKER) {
      // Switch back to non-drawing mode after drawing a shape.
      drawingManager.setDrawingMode(null);
      var newShape = e.overlay;
      all_overlays.push(newShape);
      newShape.type = e.type;
      newShape.id = all_overlays.length-1;
      all_overlays[newShape.id].id = all_overlays.length-1;
}
The user has the option to delete a single shape. I implemented the deletion like this:
function deleteSelectedShape() {
if (selectedShape) {
    all_overlays.splice(selectedShape.id,1);
    while(jQuery.inArray(selectedShape.id, selected_shapes) != -1)
        {
        var shape_index = jQuery.inArray(selectedShape.id, selected_shapes);
        selected_shapes.splice(shape_index,1);
        selected_buoys.splice(shape_index,1);
        }
    selectedShape.setMap(null);
    selectedShape = '';
    buildList();
    highlightSelectedBuoys();   
}
Unfortunatly this is not working. If I e.g. got an array with 4 shapes (ids:0,1,2,3) and delete the array with id=0, the all_overlays array does not change it's size, which messes the whole thing up in the next step. Where is my mistake?
 
     
     
    