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
In Progress | 0 / 1 sections completed | 0%
Credits
In Progress | 0 / 1 sections completed | 0%
About the Author
In Progress | 0 / 1 sections completed | 0%
About the Reviewers
In Progress | 0 / 1 sections completed | 0%
www.PacktPub.com
In Progress | 0 / 1 sections completed | 0%
Preface
In Progress | 0 / 1 sections completed | 0%
Index
In Progress | 0 / 1 sections completed | 0%

Time For Action – using the SelectFeature control


Let's put together a few things we've learned so far. We'll create some points and a polygon, place it on the map, and use the SelectFeature control to allow the user to select them. We'll register the featureselected and featureunselected events so that we can fire an event when the user interacts with a feature. When those events are fired, we'll access the feature's attributes object and display information from it. Let's do it.

  1. We'll be adding a vector layer, some features, and a SelectFeature control. The file will be referred to as chapter9_selectFeature.html.

  2. First, let's make vector_layer a global variable like we did earlier in this chapter. Place this outside the init function, right after var map;.

    var vector_layer;
  3. Next, we'll add a <div> element that we'll output feature info to when the user clicks on a feature. Add this div after the map div:

    <div id='map_feature_log'></div>
  4. Now, back to the init function code...

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

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