Google Maps API和DynamicMapsEngineLayer:在地图中循环显示功能 [英] Google Maps API and DynamicMapsEngineLayer: Loop Over Features in the Map

查看:164
本文介绍了Google Maps API和DynamicMapsEngineLayer:在地图中循环显示功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想强调一点.我的场景 没有 有用户事件驱动它触发事件监听器.我知道Maps API文档显示了如何从MapsEngineMouseEvent获取功能的featureId属性.但是我的情况需要以编程方式获取功能的featureId.

I want to emphasize something. My scenario does not have a user event driving it to trigger an event listener. I know the Maps API documentation shows how to get a feature's featureId property from a MapsEngineMouseEvent. But my scenario needs to get the feature's featureId programmatically.

我还尝试通过编程方式伪造"单击,但这也不起作用. (看来事件对象无法实例化?)

I've also tried programmatically "faking" a click, but that doesn't work either. (It seems the event object can't be instantiated??)

我的直觉是,解决这个问题的方法要么是1)不存在,要么2)看似简单,要么3)仅当最低8级的法师进行自然20智慧检定时才会被发现.

My hunch is, the solution to this either 1) doesn't exist, 2) is deceptively simple, or 3) will only be discovered if a minimum level 8 mage rolls a natural 20 wisdom check..

[原始问题陈述]

在定制的Google Maps客户端中,我有几种情况需要循环遍历通过表演工作. >

I have few scenarios in a customized Google Maps client where I need to loop over features in a DynamicMapsEngineLayer and modify their style traits. The DynamicMapsEngineLayer works by performing..

..客户端矢量数据的呈现,使开发人员能够 响应用户交互动态重新设置矢量层的样式 例如悬停并单击.

..client-side rendering of vector data, allowing the developer to dynamically restyle the vector layer in response to user interactions like hover and click.

Maps API文档介绍了如何使用事件侦听器重新设置各个功能的样式,这些事件侦听器公开了由Google服务器分配的特殊featureId值.但是我的情况没有用户驱动的事件.例如,考虑以下假设链接:

The Maps API documentation describes how to restyle individual features using event listeners, which expose a special featureId value assigned by Google servers. But my scenario doesn't have user-driven events. For example, consider this hypothetical link:

http://www.acme-map.com/index.php? ZoomToAndHighlightFeatureWithId = 12345

FeatureWithId是我们自己的唯一ID,而不是Google的特殊ID featureId,这是我们目前在运行时中没有的.

FeatureWithId is our own unique id, not Google's special featureId, which we don't have at this point in the runtime.

我需要将地图加载到功能上方,并通过更改其样式特征来突出显示它.它需要在地图首次加载时以编程方式执行此操作,而无需任何用户交互.如果这些矢量要素是在DOM中真正呈现的,那么肯定有一种方法,无论多么隐秘,都可以进入地图的内脏并访问这些对象?

I need the map to load right above a feature and highlight it by changing its style trait. It needs to do this programmatically when the map first loads, without any user interaction. If these vector features are truly rendered in the DOM, then surely there's a way, no matter how cryptic, to reach into the map's guts and access these objects?

是否可以在没有事件侦听器的情况下在DynamicMapsEngineLayer中循环访问单个要素或获取featureId属性?

推荐答案

我在这里可能遗漏了一些东西,但是如果您已经知道功能部件ID,则可以在不发生事件的情况下直接对其进行样式更改.只需直接调用 getFeatureStyle()并根据需要设置样式:

I may be missing something here, but if you already know the feature ID, you can restyle it directly without an event. Just call getFeatureStyle() directly and set the style as you wish:

var style = dynamicLayer.getFeatureStyle('1234');
style.strokeColor = '#FF0000';
style.iconImage = 'url(images/myIcon.png)';

如果您不知道功能ID,但是您还有其他属性要查询,则可以拨打

And if you don't know the feature ID, but you do have some other attribute to query against, you can make a call out to the Maps Engine API to fetch it.

这篇关于Google Maps API和DynamicMapsEngineLayer:在地图中循环显示功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆