yii2-google-maps-library icon indicating copy to clipboard operation
yii2-google-maps-library copied to clipboard

Making the Map variable Global

Open contreras2004 opened this issue 7 years ago • 1 comments

I notice after you initialize the map you cant access it by calling it from another js that had not been registered using this line of code:

$map->appendScript(implode("\n", $js));

This is important if you need to perform an action for example after pushing a button outside of the map canvas (example: draw a polyline with the push of a button)

I suggest making the map variable global by adding this line of code in Map.php right before line 407

$js[] = "var {$this->getName()};";

And change line 414 to:

$js[] = "{$this->getName()} = new google.maps.Map(container, mapOptions);";

Please correct me if I'm wrong but I cant seam to get a reference to the map if I want to register custom JS at the bottom of the page using $this->registerJs($js);

contreras2004 avatar Sep 15 '17 15:09 contreras2004

The problem with global variables is that they could conflict with other in same scope. Thats why the resulting JS is in a module pattern.

I am currently creating a new version for PHP 7+, where we won't have that issue and will work with latest release of Google Maps API and fully tested and integrated with Travis. I will provide the option for devs to setup callables that will receive the instance of the map.

That library will contain Yii adapters (widget) as this one, but will also be able to be used on other frameworks. Current state is that I am about to finish the Layers...

image

Thats my prove of work and commitment to improve it.

tonydspaniard avatar Sep 15 '17 19:09 tonydspaniard