完善地图可视化要素编辑功能(仍有缺陷需要改进)

This commit is contained in:
Li Jianxuan 2015-02-10 09:29:16 +00:00
parent 8c2cebecc4
commit c6f4df21c1
5 changed files with 378 additions and 10 deletions

View File

@ -4145,6 +4145,64 @@ class Admin_DataController extends Zend_Controller_Action
return;
}
/**
* 地图可视化
*/
public function mapAction()
{
$uuid = $this->_getParam('uuid');
if(empty($uuid))
{
$map = new Visual\Map;
view::addPaginator($map->fetchAll(),$this,10);
return true;
}
if(!empty($uuid))
{
$submit = $this->_getParam('submit');
$map = new Visual\Map;
if(!empty($submit))
{
$data = [
'uuid' => $uuid,
'status' => $this->_getParam('status'),
'layers' => $this->_getParam('status'),
'zoom_min' => $this->_getParam('zoom_min'),
'zoom_max' => $this->_getParam('zoom_max'),
'zoom_default' => $this->_getParam('zoom_default'),
'center_lon' => $this->_getParam('center_lon'),
'center_lat' => $this->_getParam('center_lat'),
];
$data = $map->processParam($data);
$status = $map->add($data);
if($status === true)
return view::Post($this,"添加成功!",-1);
$this->view->error = "添加失败";
if(is_string($status))
$this->view->error = $status;
$this->view->info = $data;
}
$this->_helper->viewRenderer('map-add');
$this->view->info = $map->fetch($uuid);
if(!isset($this->view->info['uuid']))
$this->view->info['uuid'] = $uuid;
return true;
}
}//mapAction()
/**
* 數據導入
*/
@ -4330,15 +4388,6 @@ class Admin_DataController extends Zend_Controller_Action
return true;
}//dataimportAction()
/**
* 地图可视化
*/
public function mapAction()
{
$map = new Visual\Map;
view::addPaginator($map->fetchAll(),$this,10);
}//mapAction()
public function doiAction()
{

View File

@ -0,0 +1,274 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - ');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin">后台首页</a>');
$this->breadcrumb('<a href="/admin/data">数据管理</a>');
$this->breadcrumb()->setSeparator(' > ');
?>
<div class="row-fluid">
<div class="span2">
<?= $this->partial('data/left.phtml'); ?>
</div>
<div class="span10">
<h3>地图可视化要素编辑</h3>
<hr />
<?php if(!empty($this->error)) {?>
<div class="alert alert-error">
<?= $this->error ?>
</div>
<?php }?>
<form class="form-horizontal" method="post" action="">
<div class="control-group">
<label class="control-label" for="inputUUID">UUID</label>
<div class="controls">
<input type="text" id="inputUUID" placeholder="UUID" value="<?= $this->info['uuid'] ?>" class="input-block-level" name="uuid" readonly>
</div>
</div>
<div class="control-group">
<label class="control-label">状态</label>
<div class="controls">
<label class="radio inline">
<?php $checked = function(){
if(isset($this->info['status']))
{
if($this->info['status'] == 1)
{
return 'checked="checked"';
}
}else{
return 'checked="checked"';
}
}; ?>
<input type="radio" name="status" id="optionsRadios1" value="1" <?= $checked() ?>>
启用
</label>
<label class="radio inline">
<input type="radio" name="status" id="optionsRadios2" value="0"
<?= isset($this->info['status']) && $this->info['status'] == 0 ? 'checked="checked"':"" ?>>
禁用
</label>
</div>
</div>
<div class="control-group">
<label class="control-label">最小缩放等级</label>
<div class="controls">
<select name="zoom_min">
<?php for($i=1;$i<=23;$i++){ ?>
<?php if($this->info['zoom_min'] != $i) { ?>
<option value="<?= $i ?>"><?= $i ?></option>
<?php }else{ ?>
<option value="<?= $i ?>" selected="selected"><?= $i ?></option>
<?php } ?>
<?php }?>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">最大缩放等级</label>
<div class="controls">
<select name="zoom_max">
<?php for($i=1;$i<=23;$i++){ ?>
<?php if($this->info['zoom_max'] != $i) { ?>
<option value="<?= $i ?>"><?= $i ?></option>
<?php }else{ ?>
<option value="<?= $i ?>" selected="selected"><?= $i ?></option>
<?php } ?>
<?php }?>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">默认缩放等级</label>
<div class="controls">
<select name="zoom_default">
<?php for($i=1;$i<=23;$i++){ ?>
<?php if($this->info['zoom_default'] != $i) { ?>
<option value="<?= $i ?>"><?= $i ?></option>
<?php }else{ ?>
<option value="<?= $i ?>" selected="selected"><?= $i ?></option>
<?php } ?>
<?php }?>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputLongitude">中心点经度</label>
<div class="controls">
<input type="text" id="inputLongitude" placeholder="longitude" value="<?= $this->info['center_lon'] ?>" class="input-block-level" name="center_lon">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputLatitude">中心点维度</label>
<div class="controls">
<input type="text" id="inputLatitude" placeholder="latitude" value="<?= $this->info['center_lat'] ?>" class="input-block-level" name="center_lat">
</div>
</div>
<?php if(!empty($this->info['layers'])) { ?>
<?php var_dump($this->info['layers']) ?>
<?php $vars = array() ?>
<?php $encoder = new \Westdc\Visual\VariableEncoder; ?>
<?php $vars = $encoder->decode($this->info['layers']);?>
<?php foreach($vars as $index=>$value) { ?>
<div class="control-group var-group">
<label class="control-label" for="inputVariable">可视化要素 <small><a href="javascript:void(0);" onclick="delVar(this)">删除</a></small></label>
<div class="controls">
<input type="text" placeholder="标题" name="layers[<?= $index ?>][title]" class="input-xlarge" value="<?= $value['title'] ?>">
<input type="text" placeholder="类型" name="layers[<?= $index ?>][type]" class="input-xlarge" value="<?= $value['type'] ?>">
</div>
<div class="controls" style="padding-top:10px;">
<input type="text" placeholder="url" name="layers[<?= $index ?>][sql]" class="input-block-level" value="<?= $value['url'] ?>">
</div>
<div class="controls" style="padding-top:10px;">
<input type="text" placeholder="最大经度" name="layers[<?= $index ?>][extent][lon_max]" class="input-mini" value="<?= $value['extent']['lon_max'] ?>">
<input type="text" placeholder="最小经度" name="layers[<?= $index ?>][extent][lon_min]" class="input-mini" value="<?= $value['extent']['lon_min'] ?>">
<input type="text" placeholder="最大维度" name="layers[<?= $index ?>][extent][lat_max]" class="input-mini" value="<?= $value['extent']['lat_max'] ?>">
<input type="text" placeholder="最小维度" name="layers[<?= $index ?>][extent][lat_min]" class="input-mini" value="<?= $value['extent']['lat_min'] ?>">
</div>
</div>
<?php } ?>
<?php } ?>
<div class="control-group" id="last-control-group">
<div class="controls">
<button type="button" class="btn btn-defualt" id="addVariable">添加要素</button>
</div>
</div>
<div class="control-group" id="last-control-group">
<div class="controls">
<input type="hidden" name="submit" value="1" />
<button type="submit" class="btn btn-primary">提交</button>
</div>
</div>
</form>
</div>
</div>
<script type="text/javascript">
var fieldData,fieldHtml,varHtml,current_count;
function makeVarSelectHtml(field_data){
current_count = $('.var-group').length;
fieldHtml = []
varHtml = '<input type="text" placeholder="标题" name="layers['+current_count+'][title]" class="input-xlarge"> '
+ '<input type="text" placeholder="类型" name="layers['+current_count+'][type]" class="input-xlarge">'
+ '</div><div class="controls" style="padding-top:10px;">'
+ '<input type="text" placeholder="url" name="layers['+current_count+'][sql]" class="input-block-level">'
+ '</div><div class="controls" style="padding-top:10px;">'
+ '<input type="text" placeholder="最大经度" name="layers['+current_count+'][extent][lon_max]" class="input-mini"> '
+ '<input type="text" placeholder="最小经度" name="layers['+current_count+'][extent][lon_min]" class="input-mini"> '
+ '<input type="text" placeholder="最大维度" name="layers['+current_count+'][extent][lat_max]" class="input-mini"> '
+ '<input type="text" placeholder="最小维度" name="layers['+current_count+'][extent][lat_min]" class="input-mini">';
html = '<div class="control-group var-group">'
+ '<label class="control-label" for="inputVariable">可视化要素 <small><a href="javascript:void(0);" onclick="delVar(this)">删除</a></small></label>'
+ '<div class="controls">'
+ varHtml
+ '</div>'
+'</div>';
return html;
}
function delVar(dom){
$(dom).parent().parent().parent('.control-group').remove();
};
$(document).ready(function(){
$('#data-table').change(function(){
$('.var-group').remove();
$.ajax({
type:"POST",
url:'',
data:'tablename='+ $(this).val(),
success:function(data){
fieldData = data;
html = [];
for(i in data)
{
html.push('<option value="' + data[i] + '">' + data[i] + '</option>');
}
html = '<select name="visual_timefield">' + html.join('')+'</select>';
$('#field-time').html(html);
},
beforeSend:function(){
$('#field-time').html('加载中');
}
});
});
<?php if(!empty($this->info['ts_created']) && !empty($this->info['visual_datatable'])) { ?>
$.ajax({
type:"POST",
url:'',
data:'tablename=<?= $this->info['visual_datatable'] ?>',
success:function(data){
fieldData = data;
html = [];
for(i in data)
{
if('<?= $this->info['visual_timefield'] ?>' == data[i])
html.push('<option value="' + data[i] + '" selected="selected">' + data[i] + '</option>');
else
html.push('<option value="' + data[i] + '">' + data[i] + '</option>');
}
html = '<select name="visual_timefield">' + html.join('')+'</select>';
$('#field-time').html(html);
},
beforeSend:function(){
$('#field-time').html('加载中');
}
});
<?php } ?>
$('#addVariable').click(function(e) {
if($('#var-group').length > 0)
$('#var-group').append(makeVarSelectHtml(fieldData));
else
$('#last-control-group').prepend(makeVarSelectHtml(fieldData));
});
$('#open-field-helper').click(function(){
if(null == fieldData || $('#data-table').val() == '0')
{
alert('请先选择数据表和时间字段');
return false;
}
$('.modal-body p').html(fieldData.join(','));
$('#modal-show-field').modal('show');
});
});
</script>
<div id="modal-show-field" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">字段列表</h3>
</div>
<div class="modal-body">
<p></p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
</div>
</div>

View File

@ -31,7 +31,7 @@
<p class="content"><?= $item['description']; ?></p>
<p>
操作:
<a href="/admin/data/visual/uuid/<?php echo $item['uuid'];?>">编辑可视化要素</a> |
<a href="/admin/data/map/uuid/<?php echo $item['uuid'];?>">编辑可视化要素</a> |
<a href="/visual/view/uuid/<?= $item['uuid'] ?>">前台预览</a>
</p>
</li>

View File

@ -77,6 +77,7 @@
<?php endif;?>
<a href="/admin/down/sendmail/uuid/<?php echo $item['uuid'];?>" title="向数据下载者发送通知邮件">邮件通知</a> |
<a href="/admin/data/visual/uuid/<?php echo $item['uuid'];?>">数据可视化</a> |
<a href="/admin/data/map/uuid/<?php echo $item['uuid'];?>">地图可视化</a> |
<a href="/admin/data/doi/uuid/<?php echo $item['uuid'];?>">DOI注册</a>
</p>
</li>

View File

@ -8,6 +8,8 @@
namespace Westdc\Visual;
use Helpers\dbh;
class Map {
private $db;
@ -41,12 +43,54 @@ class Map {
return $rs->fetchAll(\PDO::FETCH_ASSOC);
}
public function fetch($uuid)
{
$sql = "SELECT * FROM {$this->mainTable} WHERE uuid='$uuid'";
$rs = $this->db->query($sql);
return $rs->fetch(\PDO::FETCH_ASSOC);
}
public function delete($id)
{
$sql = "DELETE FROM {$this->mainTable} WHERE id=$id";
return $this->db->exec($sql);
}
public function add($data){
$dbh = new dbh();
if($this->checkExists($data['uuid']) === true)
return $dbh->insert($this->mainTable,$data);
return $dbh->update($this->mainTable,$data," uuid={$data['uuid']} ");
}
public function processParam($data){
if(is_array($data['layers']) && count($data['layers'])){
foreach($data['layers'] as $index=>$value){
if(!is_array($value) || count($value) < 1) {
unset($data['layers']['index']);
continue;
}
}
$data['layers'] = json_encode($data['layers'],JSON_NUMERIC_CHECK);
}
return $data;
}
public function checkExists($uuid){
$row = $this->fetch($uuid);
if(!isset($row['id']) || empty($row['id']))
return false;
return true;
}
}