Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying OpenLayers 2.10 Beginner's Guide
  • Table Of Contents Toc
  • Feedback & Rating feedback
OpenLayers 2.10 Beginner's Guide

OpenLayers 2.10 Beginner's Guide

4.2 (9)
close
close
OpenLayers 2.10 Beginner's Guide

OpenLayers 2.10 Beginner's Guide

4.2 (9)

Overview of this book

Table of Contents (18 chapters)
close
close
OpenLayers 2.10
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for Action – destroying features


Let's demonstrate the difference between removeFeatures and destroyFeatures.

  1. Open up the first example from the chapter. We'll use Firebug again.

  2. Before we remove features, we first need to add them to the map. We'll use the same code from the previous example. Let's create a feature object. In Firebug, type and execute:

    var feature_point = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(-72, 42));
  3. Now, let's add it to the map:

    map.layers[1].addFeatures([feature_point]);
  4. We have the feature on the map now, so let's see how removeFeatures works. We can call this function and either pass in a feature from the map.layers[1].features array, or pass in a feature object we've already created. Let's use the second method:

    map.layers[1].removeFeatures([feature_point]);
  5. Now you should not see any features on your map. If we check the map.layers[1].features array, it should be empty:

    >>>map.layers[1].features;
    []
  6. So, as we expected, the feature we originally...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech

Create a Note

Modal Close icon
You need to login to use this feature.
notes
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Delete Note

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Edit Note

Modal Close icon
Write a note (max 255 characters)
Cancel
Update Note

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY