2

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

elrobis
  • 1,512
  • 2
  • 16
  • 22
  • Please note that in my hypothetical URL, `FeatureWithId=12345` does not refer to Google's special `featureId` property, but to the feature's unique id within our own database schema. I apologize for any confusion this creates. – elrobis Apr 02 '14 at 15:14

1 Answers1

2

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.

lambshaanxy
  • 22,552
  • 10
  • 68
  • 92
  • The only way to get a `featureId` is with an event listener, and I don't have an event to work with in my scenario. As for using the Maps Engine (GME) API to get the `featureId` ..are you sure about that? I haven't found a way using the GME API to get the `featureId` for a given feature. [See for yourself](https://www.googleapis.com/mapsengine/v1/tables/17049733889568943420-07322983871134970075/features?intersects=POINT%28-81.04999%2034.02950%29&version=published&key=AIzaSyCG0XUkwREAafhZm8Grm03kglXY07Yy6Oo). Note that the `featureId` is not provided with the features. :/ – elrobis Apr 02 '14 at 14:23
  • BTW, the `gx_id` value which appears in the feature result, is unfortunately not the same as the `featureId`. – elrobis Apr 02 '14 at 14:25
  • Ugh.. I see where I misled you hear. My bad. The `featureId` needed to access style properties is some "special sauce" that Google adds when you create a Maps Engine layer. ...but in my hypothetical URL, the id is the unique id within our schema. So it creates a semantics problem.. So I have my own unique id, but I need to get theirs, which is why I need the loop, to look through the features drawn in the map, see if they have OUR id, then get Google's BS id.. Blast.. – elrobis Apr 02 '14 at 15:11
  • The GME API's `gx_id` should be the same as DMEL's `featureId`. Can't you call the API to look up your feature and get its `gx_id`? – lambshaanxy Apr 02 '14 at 23:19
  • Hmm, well I'll try it tmrw, but if I compare the featureId emitted from the event listener to the gx_id they are different. ......qhich led me to believe they were not the same. I'll try first thing in the AM though. – elrobis Apr 03 '14 at 03:32
  • 1
    thanks for your help. It turns out I was making a rediculous mistake. The reason my click and my Maps Engine API request had different featureId/gx_id values, was because my server-side stuff was hitting an old instance of the data. ::face-palm:: I'm gonna up-vote you and accept your answer, but I think I'll delete the question a little later since it could create a ton of confusion for someone else. – elrobis Apr 03 '14 at 14:42
  • Thanks, but why delete? This will be useful for the next person with the same problem, who might well make the same mistake; it's easy to confuse the table IDs because they all look so similar. – lambshaanxy Apr 03 '14 at 22:19