27.10.2014 Views

Google Maps API 3

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 9 ■ DEALING WITH MASSIVE NUMBERS OF MARKERS<br />

<br />

<br />

<br />

<br />

The JavaScript<br />

Start this example from the JavaScript code shown in Listing 9-6. It will create a map that’s zoomed<br />

down somewhere in the middle of the United States.<br />

Listing 9-6. The Starting JavaScript Code for Example 9-3<br />

(function() {<br />

window.onload = function() {<br />

};<br />

})();<br />

// Creating a map<br />

var options = {<br />

zoom: 5,<br />

center: new google.maps.LatLng(37.99, -93.77),<br />

mapTypeId: google.maps.MapTypeId.ROADMAP<br />

};<br />

var map = new google.maps.Map(document.getElementById('map'), options);<br />

Creating a MarkerManager Object<br />

In the JavaScript file you’re now going to add code to create a MarkerManager object. You are then going<br />

to create several markers at random locations and add these to the object.<br />

Let’s start by creating a new MarkerManager object. In its simplest form, all you need to do is to pass<br />

a reference to the map to it. You will insert this code right below the code that creates the map.<br />

var mgr = new MarkerManager(map);<br />

The MarkerManager constructor does have an optional second argument, which is an object literal<br />

containing options for tweaking its default settings (see Table 9-7). For now, you will omit this and<br />

settle with the default settings, but you will come back to the options object later in this chapter.<br />

Table 9-7. Definition of the MarkerManager Constructor<br />

Constructor<br />

MarkerManager(map:Map, options?:Object)<br />

Description<br />

Creates an empty MarkerManager object<br />

196

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!