javascript - Re-dropping Multiple Google Maps Markers Without Repaint On Map -
i've got largish (~1,300) set of markers i'm placing on map on timeline. it's playing video on time sequence, markers placed using google.maps.animation.drop on map. have standard video/audio player-type controls allow navigate timeline: play/pause, skip start, skip end, , scrubber bar move arbitrarily within timeline.
if start map empty , timeline paused @ beginning , jump end there's brief delay of marker objects created , drop onto map together. fine.
once marker's been placed , user moves backward in timeline (to point particular marker should no longer visible) marker.setmap(null) , marker hidden. i've read correct way remove marker , works.
the big problem manifests if create/drop (or large number) of markers, navigate in timeline (such large number of markers removed), , jump forward again. creates nasty flash of pins on map disappear , drop top of map.
as mentioned, correct effect (pins drop in without appearing on map beforehand) happens first time pins drop, subsequent drops cause odd behavior. small numbers of pins it's largely imperceptible, lot of pins it's more distracting.
it seems there must in internal state of marker marker.setmap(null) not resetting, i'm not @ sure might be.
i created new markers needed , destroyed them when disappeared, overhead made things sluggish. in theory feel approach should work throughout, 1 shot right effect , repeats behave badly.
does see i'm doing wrong or have suggestions on how make behave?
the logic adds pins, shows, , hides follows:
realtime.prototype.placepin = function(ent) { var ctxt = this; ent.latlng = new google.maps.latlng(ent.lat, ent.lng); ent.marker = new google.maps.marker({ position: ent.latlng, map: null, animation: google.maps.animation.drop, optimized: false }); }; realtime.prototype.tick = function(force_tick) { var ctxt = this; if ((!ctxt.playing || ctxt.dragging) && !force_tick) { return; } else { ctxt.time += ctxt.per_tick; } ctxt.nowdate = new date(ctxt.time * 1000); ctxt.pins_to_drop = []; (var = 0, l = ctxt.entries.length; < l; i++) { var ent = ctxt.entries[i]; var ent_date = new date(ent.created + ' utc'); if (ent_date < ctxt.nowdate) { if (!ent.marker || ent.marker.map == null) { if (!ent.marker) { ctxt.placepin(ent); } ctxt.pins_to_drop.push(ent); } } else { if (ent.marker && ent.marker.map != null) { ent.marker.setmap(null); } } } ctxt.updateui(); }; realtime.prototype.updateui = function() { var ctxt = this; (var = 0, l = ctxt.pins_to_drop.length; < l; i++) { var ent = ctxt.pins_to_drop[i]; ent.marker.setmap(null); ent.marker.setanimation(google.maps.animation.drop); ent.marker.setmap(ctxt.map); } };
see updated fiddle , not sure if solves problem way hide/unhide marker calling setvisible() of marker marker.setvisible(boolean). drop animation in case work first time setvisible() not associate marker map again since associated.
Comments
Post a Comment