Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Making the Map variable Global #88

Open
contreras2004 opened this issue Sep 15, 2017 · 1 comment
Open

Making the Map variable Global #88

contreras2004 opened this issue Sep 15, 2017 · 1 comment

Comments

@contreras2004
Copy link

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);

@tonydspaniard
Copy link
Member

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants