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 – extract style


The extractStyles can be used to style the vector layer based on the styles specified in the KML file. Because the Flickr KML file provides style information, we can use this property—let's see how.

  1. If the KML file you are working with contains style information, we can directly access and use it. In this case, Flickr is providing us with a KML file embedded with style tags, so let's use it.

  2. We'll specify extractStyles: true inside our vector layer creation call. In the format value setting, add it in, and be sure to include the comma:

    ...  
    format: new OpenLayers.Format.KML({ 
                        extractAttributes: true, 
                        extractStyles: true 
                    })
    ...
  3. Now open the page and you should see thumbnails of the images:

What Just Happened?

Using extractStyles, our features went from the default orange dots to thumbnails of the actual uploaded photos. When this property is used, style definitions in the KML file are applied to the style...