Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 6    Views: 43

PaddyO
Lost but trying
Profile
Posts: 189
Reg: Sep 11, 2013
Geelong
5,190
08/12/14 12:42 AM (10 years ago)

Customising a 'third' data scenario in BT_screen_map?

Hi everyone, In BT_screen_map there is a comment in the -(void)loadData method that explains how the method chooses to either grab the map data direct from the app's config file, or to grab it from an external dataURL: /* Screen Data scenarios -------------------------------- a) No dataURL is provided in the screen data - use the info configured in the app's configuration file b) A dataURL is provided, download now if we don't have a cache, else, download on refresh. */ //this creates a txt file in memory that includes the screen id of the BT map screen item. It becomes the cached file. I want to have a third option: to customise this method (or a close copy of it) so that it can pull data from another, different URL, in addition to the one that I have specified in the config file. Let's say that I want to toggle between two different dataURLs as my sources of map data, for the sake of argument. My question is (because I'm getting really lost in the code, especially when it goes out of BT_screen_map and over to BT_strings in the core) how far down the map-loading sequence do I need to go in order to simply reload this different URL's data? As a large chunk of the code in BT_screen_map seems 'generic', but flows on from the initial decision about which data source to use, I'm thinking that it's not much... but I'm stumped trying to work out how to mod the existing code so I can add this third (or fourth or fifth, if I wanted to) option. Has anyone had a play with this or could offer some advice? Cheers Paddy
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
08/12/14 03:23 PM (10 years ago)
Paddy, This can be done, but requires understanding the code a good deal. Most of the plugins that use the dataURL do so by making use of the BT_downloader class. This class downloads a text file, saves it to the cache, and calls a method (usually parseScreenData). This is the case with the map plugin. To add additional dataURL's, you will need to first find a way to identify these (either using a custom control panel property or by manually adding them to the code). This needs to be identified in the downloadData method. Also, when doing this you should probably also change the saveAsFileName to something different so you don't overwrite one cached file with the other. Secondly, you need to move the logic for initializing the self.mapLocations array up to viewDidLoad. Currently that array is initialized in the loadData method and parseScreenData method. Since you'll be calling the parseScreenData method at least twice (once for each dataURL), you don't want to re-initialize the array and overwrite any previous data loaded into memory. Theoretically, that should get you where you need. However, you may notice some undesirable effects. Namely, when the parseScreenData method is called, it creates a 1 second delay and then centers the map. This will happen for each download, which may be close together or further apart depending on the sources and sizes and the workings of the Internet. You probably should add some logic there to make sure that centering only happens once the last file has been downloaded.
 
Susan Metoxen
buzztouch Evangelist
Profile
Posts: 1706
Reg: May 01, 2011
Hopkins, Minnes...
26,260
like
08/12/14 10:03 PM (10 years ago)
What an awesome answer, Chris! Great question too, Paddy!
 
PaddyO
Lost but trying
Profile
Posts: 189
Reg: Sep 11, 2013
Geelong
5,190
like
08/13/14 06:47 AM (10 years ago)
Thanks so much Chris, that gives me a solid starting point. I already have my app generating its own 3rd URL on the fly to send off to a php script... now to feed the results back into the sequence you've outlined. The fact that it caches a text file for each data set makes sense but I would never have imagined that this was how it approached the procedure every time. I think I'll replicate (and rename) those methods, else I'm definitely going to trip myself up with conditionals embedded in conditionals and it will get very ugly very quickly! Thanks again for the pointer. Cheers Paddy
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
08/13/14 06:52 AM (10 years ago)
Glad to help. FYI, the download methods cannot be renamed as they are part of a protocol. If you rename them, they won't be called.
 
PaddyO
Lost but trying
Profile
Posts: 189
Reg: Sep 11, 2013
Geelong
5,190
like
08/13/14 01:28 PM (10 years ago)
Thanks Chris, good to know. Uber-conditionals here I come! Cheers Paddy
 
PaddyO
Lost but trying
Profile
Posts: 189
Reg: Sep 11, 2013
Geelong
5,190
like
08/17/14 09:50 PM (10 years ago)
Edit: removed bloated question. All sorted. :) Bottom line: I have it working, Chris! Thanks for the pointers, it ended up being much simpler than I imagined. Cheers Paddy.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.