A variable opacity tile layer is indeed a bit of work. I have some code
you're welcome to grab from the CLASlite application I'm developing for
Carnegie Institution for Science. The app itself isn't ready for prime time,
but this code works well.

The code is in this file:

http://code.google.com/p/claslite/source/browse/web/app/static/js/scriptino-map.js

Search for TileMapType and you will find the map type constructor along with
a bit of code that calls it. The TileMapType constructor takes an options
object that includes among other things a getTileUrl() function patterned
after the function of that name in the V2 Maps API. You'll see an
implementation of this function in the same file - naturally you'd change
that to suit the URL format of your own tile layer.

Here's how the code works: the getTile() method creates a tile DIV with its
background-image set to the tile image URL returned by getTileUrl(). It
keeps track of the active tiles in an object named 'tiles', and
releaseTile() removes a tile reference from this object. Then, there is a
setOpacity() method with can be called from your opacity slider. This loops
through all active tiles and sets their opacity.

Most of the code should be fairly self-contained, but it does use an
S.extend() function defined in scriptino-base.js in that same directory. If
you're using jQuery you could use $.extend() or any similar function here.

Also there is a bit of complexity in this scriptino-map.js file because it
started out as a wrapper around both the V2 and V3 Maps APIs. You'll also
see an implementation of V2 tile layer with variable opacity. That code also
works, but it's interesting to note that the V3 version is *much* smoother.
The V2 code flickers when you move the opacity slider - it looks like it's
removing and replacing the tile layer each time. The V3 code works perfectly
smoothly - the opacity changes and nothing else happens.

If I get a few minutes this weekend I will turn this code into a standalone
test app without all the other stuff that's in this app, but in the
meantime, feel free to use the code in this file, and fire away with any
questions.

-Mike

On Thu, Jan 20, 2011 at 1:41 PM, PaulC <[email protected]> wrote:

> My understanding is with v3 you need to create a custom map type if
> you want to overlay a map with tiles with variable opacity.  Does
> anybody have example code of how this is done because, quite frankly,
> the documentation is pretty weak on this.
>
> Am I the only person who is being to believe that v3 was created to
> discourage people for using the API.  So far all I'm finding is how v3
> makes things more difficulty with no obvious advantages.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Maps JavaScript API v3" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-maps-js-api-v3%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-maps-js-api-v3?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to