0

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>
4

1 回答 1

0

您可以使用“MarkerShadow”类并使用它来制作仅包含阴影的图层。并仅使用标记制作一个图层:概念证明 - 缺点:两次处理相同的 KML。

我可以为您想到 4 个选项:

  • 将您的阴影放在一个单独的 KML 文件中并使用本机google.maps.KmlLayer显示它们,这应该将它们放在所有 google.maps.Marker 对象下方,这是 geoxml3 用来呈现图标的对象。KmlLayer 的问题是它不支持缩放,所有图标都缩放为 64x64,如果不能,则替换为默认的蓝色图标。KmlLayer 在 overlayLayer 窗格中呈现。

  • 使用支持将标记图像与阴影图像组合的自定义叠加层创建自定义“标记” 。曾经由 Google Maps Javascript API v3 本机支持,但他们通过“视觉刷新”删除了该功能。看起来“shadowPane”仍然存在(至少现在),你可以把所有的阴影放在那里。

overlayShadow 包含标记阴影。它可能不会接收 DOM 事件。(窗格 2)。

mapPanes 参考

  • 使用google.maps.Marker对象的zIndex选项将阴影置于标记下方。将所有阴影放在 zIndex = 0 处(因此它们位于底部,然后使用算法将标记置于默认方向:

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

  • “手动”在自定义“createMarker”函数中为标记添加阴影(将阴影图像附加到 shadowPane)

带阴影的概念标记证明

于 2014-08-13T12:06:34.170 回答