2amigos / yii2-leaflet-extension

Yii 2 Extension library to display interactive maps with Leaflet .
http://yiiwheels.com
Other
30 stars 26 forks source link

Update Map.php #12

Closed ranvirp closed 8 years ago

ranvirp commented 9 years ago

Initializing javascript variable without 'var', so that map variable is not local in scope and can be used by other javascript functions also.

gfargo commented 9 years ago

Is there a reason this hasn't been investigated further? Seems to be a logical modification, without removing the var for local scope the map is inaccessible to all other JS :cold_sweat:

Seems a little backwards, before seeing this I was starting to question to purpose of this Yii Extension in the first place as Javascript Maps often need to be reactive to client side data and this extension appears to offer 0 explanation on how to accomplish that.

I assume you'd take a classic approach and use an AJAX call to a PHP Map file; like mentioned here. Great Plugin, hope you continue to work on it :beers:

gfargo commented 9 years ago

A simple workaround is to extend the Map.php class with your own version which removes the var. An example can be viewed in this gist.

Cheers :beers:

edit

@ranvirp making leaflefMap a globally scoped variable is explained here in the wiki. Feel free to ping me with questions.

tonydspaniard commented 9 years ago

Thank you very much for this PR. Nevertheless, I think it would be much better to provide an accessor to a module to access the local variable so external scripts can make use of it.

I dislike the fact of having the variable as "global". I apologize for not being on top of the updates lately, I am quite busy these days.