map1.php 6.31 KB
<!DOCTYPE html>
<?php
	$open_file = '../../../../home/pi/Desktop/vAlert/bin/vAlert8.cfg';
	$handle = fopen($open_file,"r");
	$localarray = array("LOCAL_LONGITUDE","LOCAL_LATITUDE","#LOCAL_LONGITUDE","#LOCAL_LATITUDE","!LOCAL_LONGITUDE","!LOCAL_LATITUDE");
	$nn = 0;
	while(($data = fgetcsv($handle,1000,"\n")) != false){
		$i = 0;
		foreach($data as $key => $value){
			$value = str_replace('[','',$value);
			$value = str_replace(']','',$value);
			$aa[$nn][$i] = $value;		
			$i++;
		}
		$nn++;
	} 
	//取得location 座標
	foreach($aa as $key=>$value){
		if(in_array($value[0] , $localarray)){
			$location[] = $aa[$key+1][0];
		}
	}
	$location[0] =  ($location[0] != "") ? $location[0]:'116.400244';
	$location[1] =  ($location[1] != "") ? $location[1]:'39.92556';
	//print_r($location);
?>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	<style type="text/css">
		body, html{width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
		#allmap{height:100%;width:100%;}
		#r-result{width:100%;}
	</style>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=jG5Ee8caLHGHml2XOR4D7xOq8WyP4IBd"></script>
	<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.js"></script>
</head>
<body>
	<div id="allmap"></div>
	<div class="introduction">
		<?php
		if($_GET['event'] != ''){
			$point = explode(",",$_GET['location']);
			$earthpoint = $point[0];
			$earthpoint1 = $point[1];
			$new_point = $_GET['location'];
			$strtime = $_GET['strtime'];
			$earthquaketime = strtotime($strtime)+28800;
			$diff = time()-$earthquaketime."<br>";
			//echo microtime(true);

		}
		?>
	</div>
</body>
</html>
<script type="text/javascript">
	// baidu API
	var map = new BMap.Map("allmap");
	var point = new BMap.Point(<?php echo ($new_point == '') ? $location['0'].",".$location['1']:$new_point; ?>);  //create earthquake point
	map.centerAndZoom(point, 6);
	var icon = new BMap.Icon('pin.png', new BMap.Size(20, 32), {anchor: new BMap.Size(10, 30)});
	var marker2 = new BMap.Marker(new BMap.Point(<?php echo $location['0'].",".$location['1']; ?>),{icon:icon}); //create sensor laocal point
	map.addOverlay(marker2);
	var top_left_control = new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT});//
	map.addControl(top_left_control);
	i=0;

	<?php
		if($new_point != ''){
	?>
		var stop = <?php echo $_GET['clock'];?>;
		var p_wave = <?php echo ($diff)*7000 ?>+<?php echo $_GET['clock'];?>*1000;
		var dis = map.getDistance(new BMap.Point(<?php echo $location['0'].",".$location['1']; ?>),new BMap.Point(<?php echo $new_point; ?>)).toFixed(2);
		//console.log(dis);
		setTimeout(function(){ resetMkPoint(i);},1000); //1 second update
	<?php
		}
	?>


	function resetMkPoint(i){
		//var p_wave = <?php echo ($diff)*7000*$_GET['clock']; ?>;
		var math = new Array();
		var myLabel = new Array();
		var vibration = new Array();
		var new_circle = new Array();
		if(i<=stop ){
			remove_overlay()
			timer = setTimeout(function(){i++;resetMkPoint(i);},1000);
			var marker2 = new BMap.Marker(new BMap.Point(<?php echo $location['0'].",".$location['1']; ?>),{icon:icon}); 
			map.addOverlay(marker2);
			var s_wave = <?php echo ($diff)*3550 ?>+i*1000;
			var marker = new BMap.Marker(new BMap.Point(<?php echo $new_point; ?>)); 
			var circle = new BMap.Circle(point,<?php echo ($diff)*7000 ?>+i*7000,{fillColor:"red",strokeWeight:2,fillOpacity:0.1,strokeOpacity:0.1});
			var circle1 = new BMap.Circle(point,<?php echo ($diff)*3550 ?>+i*3550,{strokeColor:'blue', strokeWeight:1}); 

			<?php
				$num = 0;
				for($num=0;$num<$_GET['level'];$num++){
			?>
				var num = <?php echo $num;?>;
				math[num] = (Math.pow(10,((<?php echo $_GET['level']-$num;?>)/4.357))-1)*10000;
				new_circle[num] = new BMap.Point(<?php echo round($earthpoint+(pow(10,((($_GET['level']-$num)/4.357)-1))-0.1),2).",".round($earthpoint1,2); ?>);
				myLabel[num] = new BMap.Label(" "+num,{offset:new BMap.Size(0,0),position:new_circle[num]}); 

				<?php

				}
			?>
			//console.log(new_circle);
			for (a = 1; a < math.length; a++) {
				vibration[a] = new BMap.Circle(point,math[a].toFixed(2),{strokeColor:"black",strokeWeight:2,fillOpacity:0.1,strokeOpacity:1,strokeStyle:'dashed'});
				map.addOverlay(vibration[a]);
				map.addOverlay(myLabel[a]);
			}

			map.addOverlay(marker);
			map.addOverlay(circle);
			map.addOverlay(circle1);

		}else {

			remove_overlay()
			timer = setTimeout(function(){i++;resetMkPoint(i);},1000);
			var marker2 = new BMap.Marker(new BMap.Point(<?php echo $location['0'].",".$location['1']; ?>),{icon:icon}); 
			map.addOverlay(marker2);
			var marker = new BMap.Marker(new BMap.Point(<?php echo $new_point; ?>)); 
			var circle = new BMap.Circle(point,<?php echo ($diff)*7000 ?>+i*7000,{fillColor:"red",strokeWeight:2,fillOpacity:0.1,strokeOpacity:0.1}); 
			var circle1 = new BMap.Circle(point,<?php echo ($diff)*3550 ?>+i*3550,{strokeColor:'blue', strokeWeight:1}); 
			var s_dis = i*3550+<?php echo ($diff)*3550 ?>;
			<?php
				$num = 0;
				for($num=0;$num<$_GET['level'];$num++){
			?>
				var num = <?php echo $num;?>;
				math[num] = (Math.pow(10,((<?php echo $_GET['level']-$num;?>)/4.357))-1)*10000;
				new_circle[num] = new BMap.Point(<?php echo round($earthpoint+(pow(10,((($_GET['level']-$num)/4.357)-1))-0.1),2).",".round($earthpoint1,2); ?>);
				myLabel[num] = new BMap.Label(" "+num,{offset:new BMap.Size(0,0),position:new_circle[num]});
			<?php
				}
			?>

			for (a = 1; a < math.length; a++) {
				vibration[a] = new BMap.Circle(point,math[a].toFixed(2),{strokeColor:"black",strokeWeight:2,fillOpacity:0.1,strokeOpacity:1,strokeStyle:'dashed'});
				map.addOverlay(vibration[a]);
				map.addOverlay(myLabel[a]);
			}

			map.addOverlay(marker);
			map.addOverlay(circle);
			map.addOverlay(circle1);

			if(dis <= s_dis){
				  clearTimeout(timer);
			}

		}
	}

	function add_overlay(){
		val = 15 * 1000;
		selectedDate = new Date().valueOf() + val;
		$('.text_bold_nounderline').show();
		$('.clock').countdown(selectedDate, function(event) {
			   $(this).html(event.strftime('%S'));
			   $('.text_bold_nounderline').hide();
		});
	}

	function remove_overlay(){
		map.clearOverlays();
	}

</script>