Can I get an Unclickable geoxml3 Shadow Layer that sits entirely behind a Clickable Marker Layer?

225 Views Asked by At

In order to have markers that are clickable and marker shadows that are not, I'm setting up two geoxml3 parsers, one for the markers and one for the shadows. That works, but I'm hoping that having two layers will also let me keep the shadow of one marker from falling on another marker. It's a subtle thing, but having a visually horizontal shadow overlaid on a visually vertical marker undercuts the 3-D effect. And in a cluster of markers, things get pretty murky down among the marker stems.

Now, I get that icons are rendered from north to south, so that an icon will peek over the top of an overlapping icon to the south of it. What I was expecting was that each parser would create its own layer, in the sense that a marker layer would appear entirely in front of a preceding shadow layer, with no shadow falling on any marker. It sure looks, though, like the parsers are working north to south down both "layers" at the same time. It seems like for each point they render the shadow image and then the corresponding marker image before moving down to the next point. If the next marker is pretty close to the southwest of the previous marker, its shadow image falls onto that previous marker.

To make sure I wasn't seeing some sort of illusion, as an exercise I put together a map with a couple of big, overlapping shadowed markers. What I'd hope for would be to have the images layered, bottom to top:

  1. East Greenland Shadow
  2. Greenland Shadow
  3. East Greenland Marker
  4. Greenland Marker

Instead, they appear to be layered:

  1. East Greenland Shadow
  2. East Greenland Marker
  3. Greenland Shadow
  4. Greenland Marker

with the Greenland Shadow falling on the East Greenland Marker.

So, can I get all of the markers to appear, collectively, in front of all the shadows? I can't track it down at the moment, but I believe I saw a list of standard Google Maps layers somewhere, which included something like a non-clickable "Shadow Layer". When I create a google.maps.KmlLayer with standard icons, the API automatically pulls up the corresponding shadow images and places those on what I guess is the Shadow Layer, which sits entirely behind the KmlLayer I asked for.

In my current project, I need a geoxml3 marker layer, so I can programatically access the placemarks. Since I can actually work with 32x32 icons, in this case I can just fall back to using a KmlLayer for the shadows, but for future reference it would be great to have the option of a non-clickable geoxml3 layer that sits entirely behind a clickable layer. Is there a way to do that? Would that be a matter of somehow rendering onto that Google Maps Shadow Layer?

Here's the script:

        function initialize() {
            var mapOptions = {
                center: new google.maps.LatLng(71, -45),
                zoom: 4,
                preserveViewport: true
            };
            var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);

            // Shadow Layer
            var shadow = new geoXML3.parser({
                map: map, 
                zoom: false, 
                markerOptions: {clickable: false}
            });
            shadow.parse('greenland_shadow_5.kml');

            // Marker Layer
            var blues = new geoXML3.parser({
                map: map, 
                singleInfoWindow: true, 
                zoom: false, 
                suppressDirections: true,
                markerOptions: {
                    shape: {
                        type: 'circle', 
                        coords: [38,38,38]
                    }
                }
            });
            blues.parse('greenland_5.kml');

        }

        google.maps.event.addDomListener(window, 'load', initialize);

The two KML files are identical except for the IconStyles:

        <IconStyle>
            <Icon>
                <href>bluemarker_76x128.png</href>
                <scale>1.0</scale>
            </Icon>
            <hotSpot x="38" y="0" xunits="pixels" yunits="pixels" />
        </IconStyle>

versus:

        <IconStyle>
            <Icon>
                <href>markershadow_188x128.png</href>
                <scale>1.0</scale>
            </Icon>
            <hotSpot x="96" y="0" xunits="pixels" yunits="pixels" />
        </IconStyle>
1

There are 1 best solutions below

0
On BEST ANSWER

You could take the "MarkerShadow" class and use it to make a layer of just shadows. and make a layer with just markers: proof of concept - disadvantage: processes the same KML twice.

I can think of 4 options for you:

  • Put your shadows in a separate KML file and display them using the native google.maps.KmlLayer, that should put them underneath all the google.maps.Marker objects, which is what geoxml3 uses to render the icons. The issue with KmlLayer is that it does not support scaling, all icons are scaled to 64x64 and if they can't be, they are replaced by the default blue icon. KmlLayer is rendered in the overlayLayer pane.

  • create custom "markers" using Custom Overlays that support combining a marker image with a shadow image. Used to be supported natively by the Google Maps Javascript API v3, but they removed that functionality with the "visual refresh". It looks like the "shadowPane" still exists (at least for now), you could put all the shadows there.

overlayShadow contains the marker shadows. It may not receive DOM events. (Pane 2).

mapPanes reference

  • Use the zIndex option of the google.maps.Marker object to put the shadows below the markers. Put all the shadows at zIndex = 0 (so they are on the bottom, then use an algorithm to put the markers in their default orientations:

    zIndex: Math.round(latlng.lat()*-100000)<<5

  • "manually" add a shadow to the markers in a custom "createMarker" function (append the shadow image to the shadowPane)

proof of concept marker with shadow