create new marker on map widget

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

Post Reply
okk
Posts: 77
Joined: Wed Feb 04, 2015 11:37 am

create new marker on map widget

Post by okk » Fri May 11, 2018 9:11 pm

Hi, I am trying to use the new Map Widget in Livecode Indy 9.0.0. I would like to create a new marker on the map when the user clicks on the map widget for a second (mousedown without moving the mouse). The widget seems not to create any mousedown message, so I thought I need to have an invisible button on top of the map widget, but then I loose the native map navigation (scroll, zoom etc.). Any hints how to solve this? Thanks. Oliver

okk
Posts: 77
Joined: Wed Feb 04, 2015 11:37 am

Re: create new marker on map widget

Post by okk » Fri May 11, 2018 10:37 pm

Hi, I perhaps found a workable solution, see the atttached stack. I placed an invisible button on top of the map widget with follwoing code:

Code: Select all



on mousedown
   local repeatcounter
   put the mouseloc into tempmouseloc
   repeat while the mouse is down
      wait 2 ticks
      if the mouseloc is not tempmouseloc then pass mousedown
      put repeatcounter+1 into repeatcounter
      if repeatcounter > 10 then 
         
         set the rect of me to the rect of widget "utopia"
         put the left of me into xmini
         put the width of me into xmaxi
         put the top of me into ymini
         put the height of me into ymaxi
         
         put the region of widget "utopia" into tempregion
         set the itemDelimiter to comma
         
         
         put item 1 of tempregion into latcenter 
         put item 2 of tempregion into loncenter
         put item 3 of tempregion into latspan
         put item 4 of tempregion into lonspan
         put latcenter + latspan/2 into latmini
         put loncenter - lonspan/2 into lonmini
         put latcenter - latspan/2 into latmaxi
         put loncenter + lonspan/2 into lonmaxi
         
         put latmaxi-latmini into latdiff
         put lonmaxi-lonmini into londiff
         
         put the mouseh into xposition
         put the mousev into yposition
         
         put (latmini+(yposition-ymini)/ymaxi*latdiff) into currentlat
         put (lonmini+(xposition-xmini)/xmaxi*londiff) into currentlon
         ask "name of the marker"
         if the result is "Cancel" then exit mousedown
         
         put the markers of widget "utopia" into tMarkers
         put currentlat & comma & currentlon into tMarkers [it]["coordinates"]
         put it into tMarkers[it]["title"]
         set the markers of widget "utopia" to tMarkers
         
         exit repeat
      end if
   end repeat
end mousedown
Do you think this is the way to go or are there easier solutions? Thanks. Oliver
Attachments
mapmarkers.livecode.zip
(1.67 KiB) Downloaded 4 times

okk
Posts: 77
Joined: Wed Feb 04, 2015 11:37 am

Re: create new marker on map widget

Post by okk » Fri May 11, 2018 11:11 pm

+ a bonus question: can I place a livecode object like a button on top of a map widget??? thx. o

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”