Google Maps API and DynamicMapsEngineLayer: Loop Over Features in the Map

左心房为你撑大大i 提交于 2019-12-11 02:59:17

问题


[Edit APRIL 2, 2014]

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??)

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


[Original Problem Statement]

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.

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 is our own unique id, not Google's special featureId, which we don't have at this point in the runtime.

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?

Is there a way to loop over individual features in a DynamicMapsEngineLayer or get the featureId property without an event listener?


回答1:


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)';

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.



来源:https://stackoverflow.com/questions/22789669/google-maps-api-and-dynamicmapsenginelayer-loop-over-features-in-the-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!