javascript - Google Maps and Revealing Module Pattern – Context -
i created little function, puts map (google maps) on website. structure code bit used revealing module pattern (multiple instances of same module multiple maps). on page load load google maps api ajax , attach click event listener each marker.
i created fiddle basic code: http://jsfiddle.net/k9mqz/.
if there 1 .map
in html works fine, put second .map
in html , click on marker in first map, content gets shown in second map. i'm not sure, think part, broken part in google maps api event listener:
google.maps.event.addlistener( marker[ idx ], 'click', function( e ) { // doesn't refer right instance of module. instead uses last instances time, if click marker on first map. clickmarker( idx, data ); });
if put console.log($el) in clickmarker
function, returns second map. suggestions make work?
you never defined $eltitle
, $eldescription
, therefore, when set them, being set globally on window
. second call overwrote value set in first.
to fix, modify line:
$elcanvas,
to
$elcanvas, $eltitle, $eldescription,
http://jsfiddle.net/k9mqz/4/ (now there layout problem)
i found setting breakpoint inside openoverlay
method , inspecting available variables. didn't see $eltitle
, started digging till found on window
.
Comments
Post a Comment