And I forgot: yes, the messageWatcher gives successive “inputLoc and the time when I click successive points on the map.
> Le 16 juin 2016 à 00:55, Jacques Hausser <jacques.haus...@unil.ch> a écrit : > > In my html file, tCoord is declared (together with several other variables) > before the first function initialize() > . > In the function initialize() I set the map, I create an elevation service > (for the altitude) and a listener to catch the clicks on the map. > > Then I have a function retrieving the last clicked location (but filtering > out the double-clicks I leave to the API to deal with), pushing it in an > array ‘locations’, then requesting the altitude of this location. The value > of tCoord is set in this function as: > tCoord = results[0].location + “," + results[0].elevation; > and finally a marker is put at this location. > > This is certainly not a very well designed javascript function, but it works. > I have only a very thin and superficial knowledge of javascript (not even > speaking of the google map API). As it is sooo easy to get something not > working at all when trying to optimalize, I leave it as it is at the moment. > > Eager to read about your theory ! > > Jacques > >> Le 15 juin 2016 à 21:52, Mike Bonner <bonnm...@gmail.com> a écrit : >> >> Hey, when the var tcoord is declared and/or set its value, how do you do >> it? If you bring up the message watcher, after grabbing your return value >> it once, does it continue spamming your livecode handler? I have the >> inkling of a theory.. >> >> On Wed, Jun 15, 2016 at 1:41 PM, Mike Bonner <bonnm...@gmail.com> wrote: >> >>> Not sure I understand whats going on either, I'd probably have to see more >>> code. >>> >>> @david.. I don't have time to try it right now, but I _THINK_ if you have >>> an existing function in your page and you want to get the results of that >>> function out, you can treat the function as a parameter to your livecode >>> call. >>> >>> Meaning if you have defined a javascrpithandler named fred, and your page >>> has a function named add() which takes 2 values to be added it will >>> probably work do do this.. >>> >>> do "liveCode.fred(add(4,3))" in widget "browser" >>> >>> Hmm in fact, i'll try it now. >>> >>> Yep, it works fine. Just pop whatever existing function (that has a return >>> value) that you want to get back out of the widget as a parameter to your >>> javascripthandler call and poof. Out it comes. >>> >>> In my test I had this in the page.. >>> >>> >>> <html> >>> <body> >>> <script> >>> var tcoords='1,2,3' >>> function add(p1,p2) { >>> return p1 + p2; >>> } >>> </script> >>> </body></html> >>> >>> And have registered myJSHandler as my livecode hook. >>> >>> Then this will get the results back out. >>> do "liveCode.myJSHandler(add(1,2))" in widget 1 >>> It uses the existing add function to add the 2 numbers passed in, and my >>> generic handler displays 3 in the message box. >>> >>> >>> On Wed, Jun 15, 2016 at 1:28 PM, Jacques Hausser <jacques.haus...@unil.ch> >>> wrote: >>> >>>> YESSS ! IT WORKS ! Many thanks, Mike ! >>>> >>>> But I’m very surprised: I don’t have to call my command “getLoc” more >>>> than one time: after that, each time I change the location of my marker on >>>> the map, the value of tCoord (which is declared at the start of the script, >>>> that is, as “global”) is modified, the function is triggered and the new >>>> coordinates are displayed in fld “Result”. I do not understand why, >>>> actually. Nothing to do with my “exportXYZ” javascript function, which was >>>> suppressed. My card script now contains: >>>> >>>> command getLoc >>>> do "liveCode.inputLoc(tCoord);" in widget "mapBrowser" >>>> end getLoc >>>> >>>> on inputLoc >>>> put param(1) into fld “FResult" >>>> end inputLoc >>>> >>>> (it’s less general than your version, but I wanted just to check it) >>>> >>>> I still have to dig further away to understand how it works. But you made >>>> my day ! >>>> >>>> Jacques >>>> >>>>> Le 15 juin 2016 à 20:25, Mike Bonner <bonnm...@gmail.com> a écrit : >>>>> >>>>> You said tcoord contains the information you want to return... >>>>> >>>>> I don't think you need to actually include the livecode function call in >>>>> your html, I'm pretty sure you can remove it entirely and do something >>>> like >>>>> this.. >>>>> >>>>> do "liveCode.inputLoc(tcoord)" in widget "Browser" and it will work. >>>> (It >>>>> did for me, its possible there are issues elsewhere in the javascript >>>> code) >>>>> >>>>> In this way you can define a single javascripthandler and have it hand >>>> back >>>>> any data you need. >>>>> >>>>> As a quick example, I set the htmltext of a widget to the following.. >>>>> >>>>> >>>>> <html> >>>>> <body> >>>>> <script> >>>>> var tcoords='1,2,3' >>>>> </script> >>>>> </body></html> >>>>> >>>>> The ONLY thing in there as javascript is the declaration of tcoords >>>>> >>>>> Then from the message box I set a javascript handler to myJSHandler and >>>>> then.. >>>>> do "liveCode.myJSHandler(tcoords,'fred')" in widget 1 >>>>> >>>>> For my lc handler I used paramcount and param() to find out and show the >>>>> data that was passed out. >>>>> >>>>> command myjshandler >>>>> put empty >>>>> repeat with i = 1 to the paramcount >>>>> put param(i) & cr after msg >>>>> end repeat >>>>> end myjshandler >>>>> >>>>> As expected the message box displayed >>>>> 1,2,3 >>>>> fred >>>>> >>>>> You might be able to leverage this into some debugging ability. >>>>> >>>>> I did try a bunch of different ways to get things out (some that seemed >>>>> like they SHOULD work but didn't, causing an "error eveluating >>>> javascript" >>>>> error) >>>>> >>>>> It even seemed sometimes that a method that worked just a minute ago >>>> would >>>>> stop. (I'm so bad at javascript though, its no surprise i'm lost) >>>>> >>>>> >>>>> On Wed, Jun 15, 2016 at 10:38 AM, Jacques Hausser < >>>> jacques.haus...@unil.ch> >>>>> wrote: >>>>> >>>>>> Still trying to use the browser widget and its javascripthandlers. I >>>>>> picked information here and there (many thanks to those who answered my >>>>>> previous mails, especially Mike) but really I would be glad to find a >>>>>> detailed user’s guide somewhere. I’m using a html file exploiting >>>> google >>>>>> map’s API as URL, and it works perfectly well with the old style >>>> browser. >>>>>> But I cannot grab the information I want with the new browser widget. >>>>>> Hereunder a simplified (and tested) example of what I tried for the old >>>>>> browser (successfully) and the widget browser (to no avail). >>>>>> >>>>>> —————————————————————————————— >>>>>> old style browser: >>>>>> —————————————————————————————— >>>>>> in the card script: >>>>>> >>>>>> command getLoc >>>>>> get revBrowserCallScript(LBrowserID,exportXYZ) >>>>>> put it into fld "FResult" >>>>>> end getLoc >>>>>> >>>>>> in the html file: >>>>>> >>>>>> function exportXYZ() >>>>>> //tCoord contains the ccordinates and altitude of the last point >>>> clicked >>>>>> { >>>>>> var vCoord = tCoord; >>>>>> return vCoord; >>>>>> } >>>>>> —————————————————————————————— >>>>>> browser widget: >>>>>> —————————————————————————————— >>>>>> in the card script: >>>>>> >>>>>> command getLoc >>>>>> do "exportXYZ();" in widget "mapBrowser" >>>>>> end mouseUp >>>>>> >>>>>> command inputLoc pCoord >>>>>> —- this command’s name is in the list of javascripthandlers for my >>>> browser >>>>>> put pCoord into fld "FResult" >>>>>> end inputLoc >>>>>> >>>>>> in the html file: >>>>>> >>>>>> function exportXYZ() >>>>>> //tCoord contains the ccordinates and altitude of the last point >>>> clicked >>>>>> { >>>>>> var pCoord = tCoord; >>>>>> liveCode.inputLoc(pCoord); >>>>>> } >>>>>> —————————————————————————————— >>>>>> >>>>>> the html file is exactly the same in both cases except for the change >>>>>> illustrated above. The map is displayed as expected in the browser >>>> widget, >>>>>> I can click any location to get a marker displayed and I can move to a >>>> new >>>>>> region with the following: >>>>>> >>>>>> —————————————————————————————— >>>>>> in the card script: >>>>>> >>>>>> command newReg plat,plon,pzoom >>>>>> do "goToReg(plat,plon,pzoom);” in widget "mapBrowser" >>>>>> end mouseUp >>>>>> >>>>>> and in the htlm file: >>>>>> >>>>>> function goToReg(pLat,pLng,pZoom) >>>>>> { >>>>>> var newCenter = new google.maps.LatLng(pLat,pLng); >>>>>> tmap.setCenter(newCenter); >>>>>> var tZoom = parseInt(pZoom,10); >>>>>> tmap.setZoom(tZoom); >>>>>> } >>>>>> —————————————————————————————— >>>>>> >>>>>> Thus “do … in widget” works; but I cannot fetch those damned >>>> coordinates >>>>>> with “liveCode.inputLoc(pCoord);". How to make the javascriptHandlers >>>> to >>>>>> work ? >>>>>> >>>>>> PS: Mac 10.11.5, LC 8.0.2 rc2 >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> use-livecode mailing list >>>>>> use-livecode@lists.runrev.com >>>>>> Please visit this url to subscribe, unsubscribe and manage your >>>>>> subscription preferences: >>>>>> http://lists.runrev.com/mailman/listinfo/use-livecode >>>>> _______________________________________________ >>>>> use-livecode mailing list >>>>> use-livecode@lists.runrev.com >>>>> Please visit this url to subscribe, unsubscribe and manage your >>>> subscription preferences: >>>>> http://lists.runrev.com/mailman/listinfo/use-livecode >>>> >>>> ****************************************** >>>> Prof. Jacques Hausser >>>> Department of Ecology and Evolution >>>> Biophore / Sorge >>>> University of Lausanne >>>> CH 1015 Lausanne >>>> please use my private address: >>>> 6 route de Burtigny >>>> CH-1269 Bassins >>>> tel: ++ 41 22 366 19 40 >>>> mobile: ++ 41 79 757 05 24 >>>> E-Mail: jacques.haus...@unil.ch >>>> ******************************************* >>>> >>>> _______________________________________________ >>>> use-livecode mailing list >>>> use-livecode@lists.runrev.com >>>> Please visit this url to subscribe, unsubscribe and manage your >>>> subscription preferences: >>>> http://lists.runrev.com/mailman/listinfo/use-livecode >>>> >>> >>> >> _______________________________________________ >> use-livecode mailing list >> use-livecode@lists.runrev.com >> Please visit this url to subscribe, unsubscribe and manage your subscription >> preferences: >> http://lists.runrev.com/mailman/listinfo/use-livecode > > ****************************************** > Prof. Jacques Hausser > Department of Ecology and Evolution > Biophore / Sorge > University of Lausanne > CH 1015 Lausanne > please use my private address: > 6 route de Burtigny > CH-1269 Bassins > tel: ++ 41 22 366 19 40 > mobile: ++ 41 79 757 05 24 > E-Mail: jacques.haus...@unil.ch > ******************************************* > > _______________________________________________ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode ****************************************** Prof. Jacques Hausser Department of Ecology and Evolution Biophore / Sorge University of Lausanne CH 1015 Lausanne please use my private address: 6 route de Burtigny CH-1269 Bassins tel: ++ 41 22 366 19 40 mobile: ++ 41 79 757 05 24 E-Mail: jacques.haus...@unil.ch ******************************************* _______________________________________________ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode