Created
December 6, 2013 15:24
-
-
Save mogya/7826409 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
Window = require('map_view'); | |
var win = new Window({ | |
title:'map' | |
}); | |
win.open(); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* データ処理タスククラス DataTask | |
データ更新処理を別スレッドで実行する | |
- リクエストを受け付けて | |
- タイマが弾けたら、最後にリクエストされたパラメタでactionを呼び出す | |
*/ | |
function datatask(_args) { | |
// setIntervalは別コンテキストで実行するため、クラスにするとthisが使えなくてどうしようもなくなるのでグローバル変数にしちゃう | |
var data_task = {}; | |
// params.interval タスクのチェック間隔 | |
// params.action タイマー満了時に呼び出される実処理の関数。 | |
// 第一引数に、第二引数に_requestに渡した引数が入ります | |
// params.caller actionを実行するコンテキスト。actionの第一引数として渡されます | |
data_task.init = function(params){ | |
data_task.interval = params.interval||500; | |
data_task.action = params.action; | |
data_task.caller = params.caller; | |
data_task.go = true; | |
data_task.task = null; | |
data_task.timer = null; | |
}; | |
var deepCopy = function(obj) { | |
return JSON.parse(JSON.stringify(obj)); | |
}; | |
//_requestをTaskに積む。最後の一個以外は実行されないので、つねに上書き。 | |
data_task.request = function(params) { | |
data_task.task = params; | |
}; | |
//Task処理。taskが積まれていたら、取り出してactionを実施する | |
data_task.do = function() { | |
if (data_task.go){ | |
if (data_task.task != null){ | |
var t = deepCopy(data_task.task); | |
data_task.task = null; | |
if (data_task.action){ data_task.action(data_task.caller,t); }; | |
}; | |
}else{ | |
clearInterval(data_task.timer); | |
data_task.timer = null; | |
}; | |
}; | |
data_task.start = function() { | |
data_task.go = true; | |
if (data_task.timer == null){ | |
// data_task.doを実行。実行コンテキストが違うので、data_taskを渡して、doの第一引数として受け取る | |
data_task.timer = setInterval( data_task.do, data_task.interval ); | |
}; | |
}; | |
data_task.stop = function() { | |
data_task.go = false; | |
}; | |
data_task.init(_args); | |
return data_task; | |
}; | |
module.exports = datatask; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mapview(_args) { | |
var win = Titanium.UI.createWindow({ | |
title:_args.title | |
}); | |
var isAndroid = false; | |
var MapModule = Titanium.Map; | |
var MapType = MapModule.STANDARD_TYPE; | |
if (Titanium.Platform.name == 'android') { | |
isAndroid = true; | |
MapModule = require('ti.map'); | |
MapType = MapModule.NORMAL_TYPE; | |
} | |
// | |
// CREATE MAP VIEW | |
// | |
var mapview = MapModule.createView({ | |
mapType: MapType, | |
region:{latitude:35.68066, longitude:139.76749, latitudeDelta:0.015, longitudeDelta:0.015}, | |
animate:true, | |
regionFit:true, | |
userLocation:true, | |
}); | |
win.add(mapview); | |
var taskAction = function(self,evt){ | |
Titanium.API.info('taskAction '+evt.longitude+','+evt.latitude); | |
}; | |
var DataTask = require('data_task'); | |
var datatask = new DataTask({ | |
interval:3000, | |
action:taskAction, | |
caller:this | |
}); | |
datatask.start(); | |
// | |
// EVENT LISTENERS | |
// | |
// region change event listener | |
var regionchanged = 'regionChanged'; | |
if (Ti.version >= '3.0.0') { | |
regionchanged = 'regionchanged'; | |
} | |
mapview.addEventListener(regionchanged,function(evt){ | |
Titanium.API.info('regionchange '+evt.longitude+','+evt.latitude); | |
datatask.request(evt); | |
}); | |
return win; | |
}; | |
module.exports = mapview; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment