Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top