Вопрос

I must be missing something obvious - I am basically trying to do in v2, what I think is outlined in [this SO question], except that doesn't work in v2. Specifically, Gmaps.maps is no longer defined.

I've gotten as far as figuring that if I store the marker data array that's returned when I call addMarkers in the buildMaps callback, I can use the elements of that array to delete a marker.

If I'm storing a custom attribute in the JSON that I sent to addMarkers, I can then hold on to that JSON array as well, and query for that attribute, find the index, and then hide the marker with that index in the marker data array - here's what I mean, in pseudo-code:

json_array=generate_json();
handler.build_map({}, function() { window.marker_data=handler.addMarkers(); });

indexes=find_in_json(json_array, {"type":"hotel"});
marker_data[i].hide() for i in indexes;

But this means I have the same conceptual data in two places - is there a better way to do this that avoids managing the "model" of the marker in two separate arrays?

Это было полезно?

Решение

I understand your concern.

What I do is to merge data in this case, check http://apneadiving.github.io/ there is an example (check sidebar section)

var markers = handler.addMarkers(json_array);

_.each(json_array, function(json, index){
  json.marker = markers[index];
});
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top