Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently May 21st, 2024, 10:17 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Javascript action variables
PostPosted: March 26th, 2017, 8:26 pm 
Offline

Joined: August 22nd, 2005, 11:56 am
Posts: 125
Location: The Netherlands
Opus: Pro 9.75 (Build 16749)
OS: Windows 10 Pro 64-bit
Hello all,

Have made a simple page with a single frame (frmMap) and a button (btnMarkerAdd)...
To create a Google Map in the frame I've added the following code in a 'Javascript action' in the 'On Show trigger' of the page, which works OK:
(Also have added of course <script type="text/javascript" src="http://maps.google.com/maps/api/js"></script> into the HTML <head> section in the Publish Settings...)!

var centerMap = new google.maps.LatLng(52.18958, 5.29524);
var optionMap = {
center: centerMap,
zoom: 8,
MapTypeId: google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementById('frmMapD'), optionMap);


Now I want to add a marker to the map already shown on screen by clicking the btnMarkerAdd button...
So I've added the following code in a 'Javascript action' in the 'Left Mouse Click trigger' of the button:

var positionMarker = new google.maps.LatLng(52.28958, 5.39524);
var marker = new google.maps.Marker({
position: positionMarker,
map: map
});


This however does not work as I get an error "map is not defined".
Well, 'map' is defined of course in the code when the page loads, and to some extent I can understand that it does not work, but can't figure out how to overcome this 'problem'?
I know there is a way to pass variables from Opus Script to Javascript by using _DWPub. just before the variable name, but is it also possible for example to pass variables from one Javascript action to another, or am I missing the point here :-)

Jan

_________________
"World War II Allied Aircraft Crashes in the Netherlands & North Sea" (Made with Opus Pro 9.75), available via https://www.airwar4045.nl


For this message Jan has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject: Re: Javascript action variables
PostPosted: March 27th, 2017, 12:03 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
The simple answer is just delete the 'var' before map.

The reason is that adding the JS action to an on show trigger creates a JS function which means that using the 'var' keyword scopes the map variable to the function not the window. The second script, on the button trigger, also creates a JS function but without the var it looks for the variable in the window scope and cannot find it.

</mack>

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


For this message mackavi has been thanked by : Jan


Top
 Profile Visit website  
 
 Post subject: Re: Javascript action variables
PostPosted: March 27th, 2017, 1:30 pm 
Offline

Joined: August 22nd, 2005, 11:56 am
Posts: 125
Location: The Netherlands
Opus: Pro 9.75 (Build 16749)
OS: Windows 10 Pro 64-bit
THANKS Mack for your reply... What should I (or we) do without your continuous help :D
Have removed var and IT WORKS!

Greetings from a very sunny Holland,
Jan

_________________
"World War II Allied Aircraft Crashes in the Netherlands & North Sea" (Made with Opus Pro 9.75), available via https://www.airwar4045.nl


For this message Jan has been thanked by : mackavi


Top
 Profile Visit website  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group