Book Image

OpenLayers 2.10 Beginner's Guide

Book Image

OpenLayers 2.10 Beginner's Guide

Overview of this book

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

Time for Action – adding some interactivity


In this example, we'll be using the cluster strategy, selectFeature control, and showing photo information on selection. As we go along, feel free to tweak the examples yourself, change the functionality, or anything else—that's the best way to learn!

  1. Make a copy (or direct edit) of the code from the previous example. We'll be improving it.

  2. We'll keep extractAttributes and extractStyles. Even though we specify extractStyles, we're going to be using a custom styleMap object. We're doing this so that we can still access the thumbnail image location (which is set as externalGraphic in the feature's style object when using extractStyles). Make sure the format object looks like the following:

    ...
    format: new OpenLayers.Format.KML({ 
      extractAttributes: true, extractStyles: true
    })
    …
  3. Let's add a cluster strategy to the vector layer now so our points cluster. Our strategies array should now look like the following:

                strategies: [new OpenLayers...