define([
"dojo",
"dojo/_base/declare",
"dojo/_base/lang",
"base/BaseWidget",
"dojo/text!widgets/attributeQuery/template.html",
"widgets/attributeQuery/config",
"base/AppEvent",
"base/ConfigData",
"iframe/jcyj/js/dataShow.js",
"dojo/dom",
"dojo/dom-construct",
"dojo/dom-attr",
"dojo/dom-style",
"dojo/on",
"esri/layers/FeatureLayer",
"controls/tab/TabControl",
"esri/dijit/SymbolStyler",
"esri/styles/basic",
"dojo/_base/array",
"esri/tasks/PrintTemplate",
"esri/tasks/query",
"esri/tasks/QueryTask",
"esri/InfoTemplate",
"esri/dijit/HorizontalSlider",
"esri/toolbars/draw",
"esri/graphic",
"esri/symbols/SimpleFillSymbol",
"esri/symbols/SimpleMarkerSymbol",
"esri/symbols/SimpleLineSymbol",
"esri/symbols/CartographicLineSymbol",
"esri/Color",
"esri/geometry/Point",
"esri/layers/GraphicsLayer",
"esri/SpatialReference",
"esri/tasks/GeometryService",
"esri/symbols/PictureMarkerSymbol",
"esri/tasks/ProjectParameters",
"esri/graphicsUtils",
"esri/tasks/IdentifyTask",
"esri/tasks/IdentifyParameters",
"dojo/domReady!"
], function (dojo,
declare,
lang,
BaseWidget,
template,
config,
AppEvent,
ConfigData,
dataShow,
dom,
domConstruct,
domAttr,
domStyle,
on,
FeatureLayer,
TabControl,
SymbolStyler,
basic,
arrayUtils,
PrintTemplate,
Query,
QueryTask,
InfoTemplate,
HorizontalSlider,
draw,
Graphic,
SimpleFillSymbol,
SimpleMarkerSymbol,
SimpleLineSymbol,
CartographicLineSymbol,
Color,
Point,
GraphicsLayer,
SpatialReference,
GeometryService,
PictureMarkerSymbol,
ProjectParameters,
graphicsUtils,
IdentifyTask,
IdentifyParameters) {
var Widget = declare([BaseWidget], {
widgetName: "attributeQueryWidget",
label: "属性查询",
templateString: template,
_map: null,
_tabControl: null,
_styler: null,
_selectLayer: null,
_printer: null,
_openprinturl: null,
StatisticalResultWidgetObj: null,
_queryGraphic: null,
_feildName: null,
RECORDS_PER_PAGE: 10, //每页显示数量
objectid: [],
_graphicslayer_attribute: null,
_graphicslayer_draw: null,
_graphicslayer_locationQuery: null,
displayField_name: null,
query_param: null,
queryTask: null,
_layui: null,
mapQuery_URL: null,//当前查询图层URL
mapQuery_layerName: null,//当前查询图层名
_geometryservice: new GeometryService(ConfigData.geometryServiceUrl),
constructor: function (options, srcRefNode) {
this._map = options.map;
attributeObj = this;
//初始化layui弹窗
layui.use('layer', function () {
attributeObj._layui = layui.layer;
});
},
postCreate: function () {
//创建地图查询工具条
$("#mainMapWidget").append(config.searchDom);
//绑定地图浏览工具条各种事件
$('#mapLayers').click(function () {//高级选项按钮点击事件
$("#showLayers").slideToggle("fast");
});
function oneclick() {
//注册全局点击事件--点击鼠标隐藏高级选项界面
$(window).one('click', function (e) {
var isshow = true;
var dom = $(e.target);
for (var i = 0; i < 6; i++) {
if (dom.parent().is('.searchDiv') || dom.parent().is('#mapQuery_tree')) {
isshow = false;
break;
}
if (dom.is(body)) break;
dom = dom.parent();
}
if (isshow) {
$("#showLayers").slideUp("fast");
return;
}
oneclick();
});
}
$("#showLayers").mouseenter(oneclick);//高级选项界面隐藏
$(".selected-layer-container input").click(function () {
$(".tree-container").slideDown('fast');
});
$(".selected-layer-container input").blur(function () {
$(".tree-container").slideUp('fast');
});
$(".tree-container").mouseenter(function () {
$(".selected-layer-container input").unbind("blur");
});
$(".tree-container").mouseleave(function () {
$(".selected-layer-container input").focus();
$(".selected-layer-container input").blur(function () {
$(".tree-container").slideUp('fast');
});
});
// $('.tree-container').mouseenter(function () {
// $(this).slideUp('fast');
// });
$("#searchMap").click(function () {//开始查询按钮点击事件
isQuery = true;
if (attributeObj.mapQuery_URL == null) {
alert("请选择查询的图层");
return;
}
showFun('attributeQueryWidget');
_AppEvent.dispatchAppEvent("Start_Query", true);
});
$("#mapQueryInput").keyup(function (e) {//输入框回车事件
if (e.keyCode == 13) {
isQuery = true;
if (attributeObj.mapQuery_URL == null) {
alert("请选择查询的图层");
return;
}
_AppEvent.dispatchAppEvent("Start_Query", true);
}
}).click(function () {
$(this).focus();
}).mouseleave(function () {
// $(this).blur();
});
$('.advanced-tab-container li').click(function () {//查询高级选项tab标签点击事件
if (!$(this).hasClass('on-tab-selected')) {
$('.on-tab-selected').removeClass('on-tab-selected');
var tabName = $(this).attr('class').slice(0, -4);
$(this).addClass('on-tab-selected');
console.log(tabName);
$('.on-selected').removeClass('on-selected');
$('.' + tabName).addClass('on-selected');
}
});
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓初始化--地图查询的目录树--并对目录树添加点击事件↓↓↓↓↓↓↓↓↓↓↓↓↓
// $.ajax({
// type: "get",
// url: getNativePath() + "resources/queryResourcesTree.do?soId=bbb7001c67c442540167c4a2a604000b",
// data: {
// "limit": 10000
// },
// dataType: "json",
// async: true,
// success: function (result) {
// var _ztreeObj = [];
// var resultObj = result.data;
// for (var i = 0; i < resultObj.length; i++) {
// var searchCatalog = {};
// searchCatalog.id = resultObj[i].resourcesId;
// searchCatalog.pId = resultObj[i].resourcesPid;
// searchCatalog.name = resultObj[i].resourcesName;
// searchCatalog.Datatime = resultObj[i].resourcesData;
// searchCatalog.Url = resultObj[i].resourcesUrl;
// _ztreeObj.push(searchCatalog);
// }
// for (var x in _ztreeObj) {
// if (_ztreeObj[x].pId == 0) {
// _ztreeObj[x].nocheck = true;
// }
// }
// var setting2 = {
// check: {
// enable: true,
// chkStyle: "radio",
// radioType: "all"
// },
// data: {
// simpleData: {
// enable: true
// }
// },
// callback: {
// onCheck: attributeObj.MapQuery_TreeOnCheck,
// beforeClick: attributeObj._beforeClick
// }
// };
// var ztree = $.fn.zTree.init($("#mapQuery_tree"), setting2, _ztreeObj);
// //默认勾选湿地公园
// var nodes = ztree.getNodesByParamFuzzy("name", "湿地公园", null);
// for (var nodesKey in nodes) {
// if (!nodes[nodesKey].isParent) {
// var node = nodes[nodesKey];
// ztree.checkNode(node, true, true, true);
// break;
// }
// }
// },
// error: function (e) {
// console.log(e);
// alert("请求失败");
// }
// });
},
//地图查询目录树选择事件
MapQuery_TreeOnCheck: function (event, treeId, treeNode) {
//改变输入框中的提示文字--填充图层名
$("#mapQueryInput").attr('placeholder', '搜索:' + treeNode.name + ',请输入搜索关键字或坐标:[x,y]');
$(".selected-layer-container input").val(treeNode.name);
//将选中节点的url存入全局变量并调用属性筛选框构造
attributeObj.mapQuery_URL = treeNode.Url;
attributeObj.mapQuery_layerName = treeNode.name;
attributeObj._selectlayer(treeNode.Url);
},
_beforeClick: function (treeId, treeNode) {
if (!treeNode.path && treeNode.isParent) {
var treeObj = $.fn.zTree.getZTreeObj(treeId);
treeObj.expandNode(treeNode, !treeNode.open, false, true, true);
}
return treeNode.path && !treeNode.isParent;
},
startup: function () {
attributeObj.treecheck = [];
//高级选项中,区域选择tab标签点击事件
$("#selectScope1").unbind("click").click(function () {//行政区
if (!$(this).hasClass("selectTab")) {
$("#selectScope2").removeClass("selectTab");
$(this).addClass("selectTab");
$('#drawTools').slideUp("fast");
$('#seek1').slideDown("fast");
}
});
$("#selectScope2").unbind("click").click(function () {//自定义
if (!$(this).hasClass("selectTab")) {
$("#selectScope1").removeClass("selectTab");
$(this).addClass("selectTab");
$('#seek1').slideUp("fast");
$('#drawTools').slideDown("fast");
}
});
//选择市区触发事件--查询对应的县区
on(dom.byId("city"), "change", function () {
$('#county').empty().append("县区/全市 ");
attributeObj._countyQuery("city", "county");
});
//注册绘制事件
attributeObj._drawGraphics();
attributeObj._graphicslayer_attribute = new GraphicsLayer({
id: "_attribute"
});
attributeObj._graphicslayer_draw = new GraphicsLayer({
id: "_draw"
});
attributeObj._graphicslayer_locationQuery = new GraphicsLayer({
id: "_location"
});
attributeObj._map.addLayers([attributeObj._graphicslayer_draw, attributeObj._graphicslayer_attribute, attributeObj._graphicslayer_locationQuery]);
AppEvent.addAppEventListener("Start_Query", lang.hitch(this, function (evt) {
if (evt) {
if ($('#mapQueryInput').val().substring(0, 1) === '[' && $('#mapQueryInput').val().substr(-1, 1)) {//位置查询
attributeObj._filledCoordinates();
} else {//属性查询
$("#bg").show();
attributeObj.queryTask = new QueryTask(attributeObj.mapQuery_URL);
//开始查询
if ($('#selectScope1 ').hasClass("selectTab")) {
attributeObj._areaQuery(false, "city", "county");
} else {
attributeObj._attributeQuery();
}
}
}
}));
AppEvent.addAppEventListener(AppEvent.APPLICATION_CLEAR, lang.hitch(this, function () {
attributeObj._graphicslayer_attribute.clear();
attributeObj._graphicslayer_draw.clear();
attributeObj._queryGraphic = null;
attributeObj._layui.closeAll();
attributeObj.objectid = [];
attributeObj._graphicslayer_locationQuery.clear();
attributeObj._map.infoWindow.hide();
}));
this.inherited(arguments);
},
open: function () {
this.inherited(arguments);
},
//给字段选择框添加候选属性
_selectlayer: function (selectUrl) {
if (!selectUrl) return;
var selectlayer = new FeatureLayer(selectUrl);
//所选图层初始化完成回调
selectlayer.on("load", function () {
$('#layer_feilds').empty(); //清空现有属性字段列表
attributeObj.displayField_name = selectlayer.displayField;
var str = '', firstr = '';
for (var i = 0; i < selectlayer.fields.length; i++) {
var regs = new RegExp("[\\u4E00-\\u9FFF]+", "g");
var ali = selectlayer.fields[i].alias;
var fieldsType = '';
if (regs.test(ali) && ali.toLowerCase().indexOf("object") == -1 && ali.toLowerCase().indexOf("shape") == -1 && ali.indexOf("area") == -1 && ali.indexOf("AREA") == -1 && ali.indexOf("Area") == -1 && ali.indexOf("FID") == -1) {
switch (selectlayer.fields[i].type) {
case "esriFieldTypeInteger":
fieldsType = 'esriFieldTypeInteger';
$('#layer_feilds').append("
" + selectlayer.fields[i].alias + "
");
break;
case "esriFieldTypeDouble":
fieldsType = 'esriFieldTypeDouble';
$('#layer_feilds').append(" " + selectlayer.fields[i].alias + "
");
break;
case "esriFieldTypeSmallInteger":
fieldsType = 'esriFieldTypeSmallInteger';
$('#layer_feilds').append(" " + selectlayer.fields[i].alias + "
");
break;
case "esriFieldTypeString":
fieldsType = 'esriFieldTypeString';
$('#layer_feilds').append(" " + selectlayer.fields[i].alias + "
");
break;
default:
break;
}
if (selectlayer.fields[i].name != attributeObj.displayField_name)
str += '' + selectlayer.fields[i].alias + ' ';
else
firstr += '' + selectlayer.fields[i].alias + ' ';
}
}
firstr += str;
$('#search-fields').html(firstr);
});
},
_filledField: function () {
//获取属性字段条件框所填写的值
var querySQL = "";
for (var i = 0; i < $('#layer_feilds')[0].children.length; i++) {
if ($('#layer_feilds')[0].children[i].children.length > 2) {
if ($($('#layer_feilds')[0].children[i].children[1]).val() != "") {
if (querySQL.length == 0) {
querySQL += $($('#layer_feilds')[0].children[i].children[0]).attr("name") + " >= " + $($('#layer_feilds')[0].children[i].children[1]).val();
} else {
querySQL += " and " + $($('#layer_feilds')[0].children[i].children[0]).attr("name") + " >= " + $($('#layer_feilds')[0].children[i].children[1]).val();
}
}
if ($($('#layer_feilds')[0].children[i].children[3]).val() != "") {
if (querySQL.length == 0) {
querySQL += $($('#layer_feilds')[0].children[i].children[0]).attr("name") + " <= " + $($('#layer_feilds')[0].children[i].children[3]).val();
} else {
querySQL += " and " + $($('#layer_feilds')[0].children[i].children[0]).attr("name") + " <= " + $($('#layer_feilds')[0].children[i].children[3]).val();
}
}
} else {
if ($($('#layer_feilds')[0].children[i].children[1]).val() != "") {
if (querySQL.length == 0) {
querySQL += $($('#layer_feilds')[0].children[i].children[0]).attr("name") + " like '%" + $($('#layer_feilds')[0].children[i].children[1]).val() + "%'";
} else {
querySQL += " and " + $($('#layer_feilds')[0].children[i].children[0]).attr("name") + " like '%" + $($('#layer_feilds')[0].children[i].children[1]).val() + "%'";
}
}
}
}
return querySQL;
},
_drawGraphics: function () { //自定义绘制图形
//添加点样式
var markerSymbol = new SimpleMarkerSymbol();
//markerSymbol.setPath("M16,4.938c-7.732,0-14,4.701-14,10.5c0,1.981,0.741,3.833,2.016,5.414L2,25.272l5.613-1.44c2.339,1.316,5.237,2.106,8.387,2.106c7.732,0,14-4.701,14-10.5S23.732,4.938,16,4.938zM16.868,21.375h-1.969v-1.889h1.969V21.375zM16.772,18.094h-1.777l-0.176-8.083h2.113L16.772,18.094z");
markerSymbol.setColor(new Color("#00FFFF"));
// 添加线样式
var lineSymbol = new CartographicLineSymbol(
CartographicLineSymbol.STYLE_SOLID,
new Color([255, 0, 0]), 10,
CartographicLineSymbol.CAP_ROUND,
CartographicLineSymbol.JOIN_MITER, 5
);
// 添加面样式
var fillSymbol = new SimpleFillSymbol(
SimpleFillSymbol.STYLE_SOLID,
new SimpleLineSymbol(
SimpleLineSymbol.STYLE_SOLID,
new Color('#fb003b'),
1
),
new Color([0, 0, 0, 0.15])
);
//定义绘制工具初始化函数
var tb = new draw(attributeObj._map);
tb.on("draw-end", function (evt) {//定义绘制结束回调函数--添加绘制图形至地图GraphicLayer图层中
//deactivate the toolbar and clear existing graphics
tb.deactivate();
$('.drawTools-active').removeClass('drawTools-active');
attributeObj._map.enableMapNavigation();
// 选择绘制的形状
var symbol;
if (evt.geometry.type === "point" || evt.geometry.type === "multipoint") {
symbol = markerSymbol;
} else if (evt.geometry.type === "line" || evt.geometry.type === "polyline") {
symbol = lineSymbol;
} else {
symbol = fillSymbol;
}
attributeObj._queryGraphic = evt.geometry;
attributeObj._graphicslayer_draw.add(new Graphic(evt.geometry, symbol));
});
// 绘制按钮点击事件,获取需要绘制的形状
on(dom.byId("drawTools"), "click", function (evt) {
if (evt.target.id === "drawTools") {
return;
}
if (evt.target.id === "clearAll") { //清除按钮清除事件
attributeObj._graphicslayer_draw.clear();
attributeObj._queryGraphic = null;
tb.deactivate();
$('.drawTools-active').removeClass('drawTools-active');
attributeObj._map.enableMapNavigation();
return;
}
$('.drawTools-active').removeClass('drawTools-active');
$(evt.target).addClass('drawTools-active');
attributeObj._graphicslayer_draw.clear();
attributeObj._queryGraphic = null;
var tool = evt.target.id.toLowerCase();
attributeObj._map.disableMapNavigation();
tb.activate(tool);
});
},
//COUNTY查询--在县区选择栏中动态添加所包含的县区
_countyQuery: function (city, county) {
var city_selected = city;
var count_selected = county;
var Url = ConfigData.areaQueryURL + "/2";
var queryTask = new QueryTask(Url);
var query = new Query();
query.returnGeometry = false;
query.outFields = [
"COUNTY"
];
var queryParam;
if ($('#' + city_selected + ' option:selected').text() != "市/全省") {
queryParam = "CITY like '%" + $('#' + city_selected + ' option:selected').text() + "%'";
}
if (queryParam == null) {
return;
}
query.where = queryParam;
queryTask.execute(query, function (results) {
var optionVal = results.features;
for (var i in optionVal) {
$('#' + count_selected).append("" + optionVal[i].attributes["COUNTY"] + " ");
}
});
},
//行政区查询
_areaQuery: function (queryLocation, city, county) {
var querylocation = queryLocation;
var city_selected = city;
var count_selected = county;
var queryParam;
var URL;
if ($('#' + city_selected + ' option:selected').text() != "市/全省") {
queryParam = "CITY like '%" + $('#' + city_selected + ' option:selected').text() + "%'";
URL = ConfigData.areaQueryURL + "/1";
}
if ($('#' + count_selected + ' option:selected').text() != "县区/全市") {
queryParam += "and COUNTY like '%" + $('#' + count_selected + ' option:selected').text() + "%'";
URL = ConfigData.areaQueryURL + "/2";
}
//如果查询参数为空则直接查询全省范围内的数据
if (queryParam == null) {
attributeObj._attributeQuery();
return;
}
var queryTask = new QueryTask(URL);
var query = new Query();
query.returnGeometry = true;
query.where = queryParam;
queryTask.execute(query, function (results) {
var resultsFeatures = results.features;
if (resultsFeatures.length > 0) {
if (!querylocation) { //行政区查询执行---输出指定行政区并进行属性查询
//获取几何中心,并定位
var resultGeometry = resultsFeatures[0].geometry;
// var cPoint;
var taxLotExtent = resultGeometry.getExtent();
attributeObj._map.setExtent(taxLotExtent);
attributeObj._queryGraphic = resultGeometry;
attributeObj._attributeQuery();
} else { //定位查询执行---在地图中描绘出所查询行政区,并定位至该范围
var str = "";
attributeObj._graphicslayer_locationQuery.fields = results.fields;
attributeObj._graphicslayer_locationQuery.displayField = results.displayFieldName;
attributeObj._graphicslayer_locationQuery.clear();
var color = Color.fromHex("#9af6f0");
var symbol = new SimpleFillSymbol();
symbol.setOutline(new SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new Color(color), 5));
symbol.setColor(new Color([0, 0, 0, 0.1]));
if (resultsFeatures.length > 0) {
var template = new InfoTemplate();
template.setTitle(attributeObj._getGraphicTitle);
template.setContent(attributeObj._getTextContent);
var featureAttributes = resultsFeatures[0].attributes;
var resultGeometry = resultsFeatures[0].geometry;
var adad = new Graphic(resultGeometry, symbol, featureAttributes, template);
attributeObj._graphicslayer_locationQuery.add(adad);
//获取几何范围,并定位
var cPoint;
var taxLotExtent = resultGeometry.getExtent();
// cPoint = taxLotExtent.getCenter();
attributeObj._map.setExtent(taxLotExtent);
}
$("#bg").hide();
}
}
}, function (error) {
$("#bg").hide();
console.log(error);
alert(error.message);
});
},
_attributeQuery: function () {
//查询按钮点击回调函数--执行查询,获取满足条件的要素OBJECTID
attributeObj._feildName = attributeObj._filledField();
var query_text = $('#mapQueryInput').val();
attributeObj.objectid = [];
var query = new Query();
query.returnGeometry = false;
query.outFields = [
"*"
];
if (attributeObj._queryGraphic != null) {
query.geometry = attributeObj._queryGraphic;
}
if (attributeObj._feildName == null || attributeObj._feildName == "") {
if ($.trim(query_text) == "") {
query.where = "1=1";
} else {
switch ($('#search-fields option:selected').attr('fieldsType')) {
case "esriFieldTypeInteger":
case "esriFieldTypeSmallInteger":
case "esriFieldTypeDouble":
if (isNaN($.trim(query_text))) {
$('#bg').hide();
attributeObj._layui.msg('请输入数字', {icon: 2, offset: ['50%', '50%']});
return;
}
query.where = $('#search-fields option:selected').attr('name') + " = " + $.trim(query_text);
break;
case "esriFieldTypeString":
default:
query.where = $('#search-fields option:selected').attr('name') + " like '%" + $.trim(query_text) + "%'";
break;
}
}
} else {
switch ($('#search-fields option:selected').attr('fieldsType')) {
case "esriFieldTypeInteger":
case "esriFieldTypeSmallInteger":
case "esriFieldTypeDouble":
if (isNaN($.trim(query_text))) {
$('#bg').hide();
attributeObj._layui.msg('请输入数字', {icon: 2, offset: ['50%', '50%']});
return;
}
attributeObj._feildName += " and " + attributeObj.displayField_name + " = " + $.trim(query_text);
break;
case "esriFieldTypeString":
attributeObj._feildName += " and " + attributeObj.displayField_name + " like '%" + $.trim(query_text) + "%'";
default:
attributeObj._feildName += " and " + attributeObj.displayField_name + " like '%" + $.trim(query_text) + "%'";
break;
}
query.where = attributeObj._feildName;
}
attributeObj.query_param = query;
attributeObj.queryTask.execute(query, function (results) {
//执行查询回调函数--获取满足条件的要素OBJECTID,并对查询结果进行分页展示
var resultCount = results.features.length;
for (var i = 0; i < resultCount; i++) {
attributeObj.objectid[i] = results.features[i].attributes.OBJECTID;
}
attributeObj._layui.closeAll('page');
setTimeout(function () {//延时执行等待上一个弹窗完全关闭
attributeObj._query_count();
}, 300);
}, function (error) {
attributeObj._layui.closeAll('page');
$("#bg").hide();
console.log(error);
alert(error.message);
});
},
//查询满足条件的结果的总个数
_query_count: function () {
attributeObj.queryTask.executeForCount(attributeObj.query_param, function (result_count) {
if (result_count > 0) {
if ($('#module-side-container').is(':visible')) {
var offset = ['97px', '420px'];
} else {
var offset = ['97px', '370px'];
}
//打开查询结果弹窗
attributeObj._layui.open({
type: 1,
maxmin: true,
title: '查询结果',
content: '
',
area: ['300px', '470px'],
offset: offset,
scrollbar: false,
shade: 0,
success: function (layero, index) {
//创建查询结果DOM
var resultContainer = domConstruct.create('div', {
id: 'attributeQueryResult'
}, "result-container");
var statisticalUl = domConstruct.create('ul', {
id: 'statistical_ul'
}, resultContainer);
var countSpan = domConstruct.create('span', {
id: 'count_ul',
innerHTML: "总数量:" + result_count + "(个)"
}, statisticalUl);
var clearSpan = domConstruct.create('span', {
id: 'attr_return',
class: 'clearResult',
innerHTML: "清除结果"
}, statisticalUl);
//绑定清除结果按钮点击事件
on(clearSpan, 'click', function () {
//清空图层,关闭地图弹窗和结果弹窗
attributeObj._graphicslayer_attribute.clear();
attributeObj._graphicslayer_draw.clear();
attributeObj._map.infoWindow.hide();
attributeObj._queryGraphic = null;
attributeObj.objectid = [];
attributeObj._layui.closeAll('page');
});
//执行分页查询结果详情
attributeObj._query_fenye(1, resultContainer);
},
cancel: function (index, layero) {
// if (confirm('操作将清空查询结果,请确认关闭')) { //只有当点击confirm框的确定时,该层才会关闭
//清空图层,关闭地图弹窗和结果弹窗
attributeObj._graphicslayer_attribute.clear();
attributeObj._graphicslayer_draw.clear();
attributeObj._map.infoWindow.hide();
attributeObj._queryGraphic = null;
attributeObj.objectid = [];
attributeObj._layui.close(index);
// }
// return false;
},
min: function (layero) {//最小化回调
$('#result-container').hide();
$(layero).css('height', 'auto');
var top = $(body).height() - 43;
$(layero).css('height', 'auto');
$(layero).css('top', top + 'px');
setTimeout(function () {
(function (layero) {
var left = $(body).width() - 180;
$(layero).css('left', left + 'px');
})(layero)
}, 10);
},
restore: function (layero) {//还原回调
$('#result-container').show();
$(layero).css('height', '470px');
$(layero).css('top', offset[0]);
$(layero).css('left', offset[1]);
}
});
} else {
attributeObj._map.infoWindow.hide();
attributeObj._graphicslayer_attribute.clear();
attributeObj._layui.closeAll('page');//关闭当前弹出的页面层
$("#bg").hide();
attributeObj._layui.msg('未查询到相应结果', {icon: 5, offset: ['50%', '50%']});
}
}, function (error) {
$("#bg").hide();
console.log(error);
alert(error.message);
});
},
//根据查询结果进行分页查询--并输出详细信息
_query_fenye: function (pageindexs, dom) {
$("#bg").show();
var startIndex = 0;
startIndex = (parseInt(pageindexs) - 1) * attributeObj.RECORDS_PER_PAGE;
var endIndex = 0;
endIndex = startIndex + attributeObj.RECORDS_PER_PAGE;
if (endIndex <= attributeObj.objectid.length) {
endIndex = endIndex;
} else {
endIndex = attributeObj.objectid.length;
}
var ids;
ids = attributeObj.objectid.slice(startIndex, endIndex);
var query = new Query();
query.returnGeometry = true;
query.objectIds = ids;
query.outSpatialReference = attributeObj._map.spatialReference;
query.outFields = ["*"];
attributeObj.queryTask.execute(query, function (results) {
var resultsFeatures = results.features;
var displayFields = results.displayFieldName;
// 销毁上一次的结果列表
domConstruct.destroy("content_ul");
//创建查询结果详情DOM
if (dom) {
var contentUl = domConstruct.create('ul', {
id: 'content_ul'
}, dom);
} else {
var contentUl = domConstruct.create('ul', {
id: 'content_ul'
}, 'attributeQueryResult');
}
//清空上次查询的详情
attributeObj._graphicslayer_attribute.clear();
attributeObj._queryGraphic = null;
attributeObj._map.infoWindow.hide();
//设定结果图层相关属性
attributeObj._graphicslayer_attribute.fields = results.fields;
attributeObj._graphicslayer_attribute.displayField = displayFields;
var treeObj = $.fn.zTree.getZTreeObj("mapQuery_tree");
var nodes = treeObj.getCheckedNodes(); //状态改变的节点
attributeObj._graphicslayer_attribute.name = nodes[0].name;
//初始化结果样式
var color = Color.fromRgb("rgba(246,9,9,0.6)");
var symbol;
switch (results.geometryType) {
case "esriGeometryPoint":
symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 10,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([0, 255, 255, 0.6]), 1),
new Color([255, 0, 0, 0.6]));
break;
case "esriGeometryPolyline":
symbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255, 0, 0, 0.6]), 2);
break;
default:
symbol = new SimpleFillSymbol();
symbol.setOutline(new SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new Color([0, 255, 255, 0.6]), 1));
break;
}
symbol.setColor(new Color(color));
//遍历查询结果,构造结果列表并将结果绘制到地图上
for (var i = 0; i < resultsFeatures.length; i++) {
if (attributeObj._graphicslayer_attribute.name.indexOf("城") != -1 && attributeObj._graphicslayer_attribute.name.indexOf("湿") != -1) {
var li = domConstruct.create("li", {
innerHTML: "" + (((pageindexs - 1) * attributeObj.RECORDS_PER_PAGE) + (i + 1)) + ". " +
"" + resultsFeatures[i].attributes[displayFields] + "第" + resultsFeatures[i].attributes["WETLAND_NO"] + "号湿地斑块 ",
style: "cursor: pointer"
}, contentUl);
} else {
var displayStr = resultsFeatures[i].attributes[displayFields];
if (displayStr==null||displayStr==''||displayStr==' '){//如果为空或者null就用图层名替代
displayStr = $('.selected-layer-container input').val();
}
var li = domConstruct.create("li", {
innerHTML: "" + (((pageindexs - 1) * attributeObj.RECORDS_PER_PAGE) + (i + 1)) + ". " +
"" + displayStr + " ",
style: "cursor: pointer"
}, contentUl);
}
//构造矢量要素并添加到图层上
var template = new InfoTemplate();
template.setTitle(attributeObj._getGraphicTitle);
template.setContent(attributeObj._getTextContent);
var featureAttributes = resultsFeatures[i].attributes;
var adad = new Graphic(resultsFeatures[i].geometry, symbol, featureAttributes, template);
attributeObj._graphicslayer_attribute.add(adad);
//给结果列表添加点击事件
on(li, "click", lang.hitch(adad, function (evt) {
var cPoint;
switch (this.geometry.type) {
case "point":
cPoint = new Point(this.geometry.x, this.geometry.y, attributeObj._map.spatialReference); // 实例化一个点
break;
default:
var taxLotExtent = this.geometry.getExtent();
cPoint = taxLotExtent.getCenter();
break;
}
attributeObj._map.infoWindow.setTitle(this.getTitle());
attributeObj._map.infoWindow.setContent(this.getContent());
attributeObj._map.infoWindow.show(cPoint);
attributeObj._map.centerAndZoom(cPoint, 10);
}));
}
//生成翻页按钮DOM
var pageDom = domConstruct.create('div', {
class: 'page'
}, contentUl);
if (pageindexs == 1) {
var previousDom = domConstruct.create('input', {
type: 'button',
value: '上一页'
}, pageDom);
} else {
var previousDom = domConstruct.create('input', {
type: 'button',
id: 'LOOKTG',
value: '上一页',
style: 'cursor: pointer;'
}, pageDom);
on(previousDom, 'click', lang.hitch(pageindexs, function (evt) {
attributeObj._query_fenye(parseInt(this) - 1);
}));
}
var pageSpan = domConstruct.create('span', {
style: 'margin: 0px 5px;',
innerHTML: pageindexs + "/" + Math.ceil(attributeObj.objectid.length / attributeObj.RECORDS_PER_PAGE)
}, pageDom);
if (pageindexs == Math.ceil(attributeObj.objectid.length / attributeObj.RECORDS_PER_PAGE)) {
var nextDom = domConstruct.create('input', {
type: 'button',
value: '下一页'
}, pageDom);
} else {
var nextDom = domConstruct.create('input', {
type: 'button',
id: 'next',
value: '下一页',
style: 'cursor: pointer;'
}, pageDom);
on(nextDom, 'click', lang.hitch(pageindexs, function (evt) {
attributeObj._query_fenye(parseInt(this) + 1);
}));
}
//获取当前所有查询结果的最大范围,并定位到此范围。
if (resultsFeatures.length > 1) {
var featureExtent = graphicsUtils.graphicsExtent(resultsFeatures);
attributeObj._map.setExtent(featureExtent);
} else {
if (results.geometryType == "esriGeometryPoint") {
attributeObj._map.centerAndZoom(resultsFeatures[0].geometry, 8);
} else {
attributeObj._map.setExtent(resultsFeatures[0].geometry.getExtent());
}
}
if ($("#statistical_ul p").length < 1) {
//统计前10000个满足条件的结果的总面积
for (var statisticsKey in config.statistics) {// 遍历得到当前图层的总面积统计字段
if (attributeObj.mapQuery_layerName.indexOf(statisticsKey) != -1) {
var statisticalField = config.statistics[statisticsKey].itemFields[1];
}
}
attributeObj.query_param.outFields = [statisticalField];
attributeObj.queryTask.execute(attributeObj.query_param, function (area_results) {
if (area_results.features.length > 0) {
var areaSum = 0;
for (var i in area_results.features) {
areaSum += area_results.features[i].attributes[statisticalField];
}
if (area_results.features.length > 9999) {
var txt = "前10000个查询结果总面积为" + areaSum.toFixed(2) + "公顷";
} else {
var txt = "查询结果总面积为" + areaSum.toFixed(2) + "公顷";
}
domConstruct.create('p', {
style: 'color: #9a9a9a;margin-top: 5px;',
innerHTML: txt
}, 'statistical_ul');
}
}, function (e) {
console.log(e);
});
}
$("#bg").hide();
}, function (error) {
$("#bg").hide();
console.log(error);
alert(error.message);
});
},
//定位查询--判断坐标格式并生成位置点
_filledCoordinates: function () {
attributeObj._layui.closeAll('page');
$("#bg").show();
//获取所填写的坐标
var _graphic;
var Coordinates = $('#mapQueryInput').val().substring(1, $('#mapQueryInput').val().length - 1);
if ((Coordinates == "") || (Coordinates.indexOf(",") <= -1)) {
attributeObj._layui.msg('请输入规范的坐标', {icon: 2, offset: ['50%', '50%']});
return;
}
var long_lat = Coordinates.split(",");
if (long_lat.length < 2 || long_lat.length > 2) {
attributeObj._layui.msg('请输入规范的坐标', {icon: 2, offset: ['50%', '50%']});
return;
}
var long = long_lat[0];
var lat = long_lat[1];
if (isNaN(lat) || isNaN(long)) {
attributeObj._layui.msg('请输入规范的坐标', {icon: 2, offset: ['50%', '50%']});
return;
}
var mm = long.toString();
var nn = mm.split(".");
var yy = nn[0];
attributeObj._graphicslayer_locationQuery.clear(); //添加新坐标点前先清空现有坐标点
if (yy.length >= 8) {//投影坐标
var zz = yy.substring(2, yy.length);
long = zz + "." + nn[1];
long = parseFloat(long);
//转换坐标系至CGCS2000
var poin = new Point(parseFloat(long), parseFloat(lat), new SpatialReference(4548));
var projectParameters = new ProjectParameters();
projectParameters.geometries = [poin];
projectParameters.outSR = new SpatialReference(4490);
attributeObj._geometryservice.project(projectParameters, function (result) {
var symbol = new PictureMarkerSymbol({
"url": "images/sign2.png",
"height": 30,
"width": 15,
"yoffset": 15
});
_graphic = new Graphic(result[0], symbol);
attributeObj._graphicslayer_locationQuery.add(_graphic); //添加坐标点
attributeObj._map.centerAndZoom(result[0], 10); //定位至该坐标点
attributeObj.locationQuery(_graphic);//开始定位查询
});
} else {//地理坐标
if ((long > 180 && lat < 90) || (long < 180 && lat > 90) || isNaN(lat) || isNaN(long)) {
attributeObj._layui.msg('请输入规范的坐标', {icon: 2, offset: ['50%', '50%']});
return;
}
var point = new Point(parseFloat(long), parseFloat(lat), new SpatialReference(4490)); // 实例化一个点
var symbol = new PictureMarkerSymbol({
"url": "images/sign2.png",
"height": 30,
"width": 15,
"yoffset": 15
});
_graphic = new Graphic(point, symbol);
attributeObj._graphicslayer_locationQuery.add(_graphic); //添加坐标点
attributeObj._map.centerAndZoom(point, 15); //定位至该坐标点
setTimeout(function () {
attributeObj.locationQuery(_graphic);//开始定位查询
}, 1000);
}
},
//定位查询--多图层查询
locationQuery: function (graphic) {
var identifyTask = new IdentifyTask(ConfigData.areaQueryURL.replace(/JIANGXI_BORDER/, 'ZHSD'));
var identifyParameters = new IdentifyParameters();
identifyParameters.layerIds = [0, 1, 2, 3, 4, 5, 6];//查所有图层
identifyParameters.layerOption = IdentifyParameters.LAYER_OPTION_ALL;
identifyParameters.returnGeometry = true;
identifyParameters.tolerance = 3;
identifyParameters.mapExtent = attributeObj._map.extent;
identifyParameters.geometry = graphic.geometry;
identifyTask.execute(identifyParameters, function (e) {
var result_count = e.length;
var resultsFeatures = e;
if (result_count > 0) {
//清空上次查询的详情
attributeObj._graphicslayer_attribute.clear();
attributeObj._map.infoWindow.hide();
if ($('#module-side-container').is(':visible')) {
var offset = ['97px', '420px'];
} else {
var offset = ['97px', '370px'];
}
//打开查询结果弹窗
attributeObj._layui.open({
type: 1,
maxmin: true,
title: '查询结果',
content: '
',
area: ['300px', '470px'],
offset: offset,
scrollbar: true,
shade: 0,
success: function (layero, index) {
//创建查询结果DOM
var resultContainer = domConstruct.create('div', {
id: 'attributeQueryResult'
}, "result-container");
var statisticalUl = domConstruct.create('ul', {
id: 'statistical_ul'
}, resultContainer);
var countSpan = domConstruct.create('span', {
id: 'count_ul',
innerHTML: "总数量:" + result_count + "(个)"
}, statisticalUl);
var clearSpan = domConstruct.create('span', {
id: 'attr_return',
class: 'clearResult',
innerHTML: "清除结果"
}, statisticalUl);
//绑定清除结果按钮点击事件
on(clearSpan, 'click', function () {
//清空图层,关闭地图弹窗和结果弹窗
attributeObj._graphicslayer_locationQuery.clear();
attributeObj._graphicslayer_attribute.clear();
attributeObj._map.infoWindow.hide();
attributeObj._layui.closeAll('page');
});
// 销毁上一次的结果列表
domConstruct.destroy("content_ul");
//创建查询结果详情DOM
if (statisticalUl) {
var contentUl = domConstruct.create('ul', {
id: 'content_ul',
style: 'height:368px;overflow:auto'
}, statisticalUl);
} else {
var contentUl = domConstruct.create('ul', {
id: 'content_ul',
style: 'height:368px;overflow:auto'
}, 'attributeQueryResult');
}
//遍历查询结果,构造结果列表并将结果绘制到地图上
for (var i = 0; i < resultsFeatures.length; i++) {
//初始化结果样式
var color = Color.fromRgb("rgba(246,9,9,0.6)");
var symbol;
switch (resultsFeatures[i].geometryType) {
case "esriGeometryPoint":
symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 10,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([0, 255, 255, 0.6]), 1),
new Color([255, 0, 0, 0.6]));
break;
case "esriGeometryPolyline":
symbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255, 0, 0, 0.6]), 2);
break;
default:
symbol = new SimpleFillSymbol();
symbol.setOutline(new SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new Color([0, 255, 255, 0.6]), 1));
break;
}
symbol.setColor(new Color(color));
if (resultsFeatures[i].layerName.indexOf("城") != -1 && resultsFeatures[i].layerName.indexOf("湿") != -1) {
var listName = resultsFeatures[i].value + "第" + resultsFeatures[i].feature.attributes["湿地斑块序号"] + "号湿地斑块";
} else {
var listName = resultsFeatures[i].value;
}
var li = domConstruct.create("li", {
innerHTML: "" + (i + 1) + ". " + resultsFeatures[i].layerName + ':' + listName + " ",
style: "cursor: pointer"
}, contentUl);
//构造矢量要素并添加到图层上
var template = new InfoTemplate();
template.setTitle(listName != ' ' ? listName : resultsFeatures[i].layerName);
template.setContent(attributeObj._locationGetTextContent);
var adad = resultsFeatures[i].feature;
adad.symbol = symbol;
adad.infoTemplate = template;
attributeObj._graphicslayer_attribute.add(adad);
//给结果列表添加点击事件
on(li, "click", lang.hitch(adad, function (evt) {
var cPoint;
switch (this.geometry.type) {
case "point":
cPoint = new Point(this.geometry.x, this.geometry.y, attributeObj._map.spatialReference); // 实例化一个点
break;
default:
var taxLotExtent = this.geometry.getExtent();
cPoint = taxLotExtent.getCenter();
break;
}
attributeObj._map.infoWindow.setTitle(this.getTitle());
attributeObj._map.infoWindow.setContent(this.getContent());
attributeObj._map.infoWindow.show(cPoint);
attributeObj._map.centerAndZoom(cPoint, 10);
}));
}
$("#bg").hide();
},
cancel: function (index, layero) {
// if (confirm('操作将清空查询结果,请确认关闭')) { //只有当点击confirm框的确定时,该层才会关闭
//清空图层,关闭地图弹窗和结果弹窗
attributeObj._graphicslayer_attribute.clear();
attributeObj._graphicslayer_locationQuery.clear();
attributeObj._map.infoWindow.hide();
attributeObj._layui.close(index);
},
min: function (layero) {//最小化回调
$('#result-container').hide();
$(layero).css('height', 'auto');
var top = $(body).height() - 43;
$(layero).css('height', 'auto');
$(layero).css('top', top + 'px');
setTimeout(function () {
(function (layero) {
var left = $(body).width() - 180;
$(layero).css('left', left + 'px');
})(layero)
}, 10);
},
restore: function (layero) {//还原回调
$('#result-container').show();
$(layero).css('height', '470px');
$(layero).css('top', '145px');
$(layero).css('left', '64%');
}
});
} else {
attributeObj._map.infoWindow.hide();
attributeObj._graphicslayer_attribute.clear();
attributeObj._layui.closeAll('page');//关闭当前弹出的页面层
$("#bg").hide();
attributeObj._layui.msg('当前位置未查询到湿地斑块', {icon: 5, offset: ['50%', '50%']});
}
}, function (e) {
$("#bg").hide();
console.log(e);
});
},
_getGraphicTitle: function (graphic) {
var layer = graphic.getLayer();
if (layer.name.indexOf("城") != -1 && layer.name.indexOf("湿") != -1) {
var title = graphic.attributes[layer.displayField] + "第" + graphic.attributes["WETLAND_ON"] + "号湿地斑块";
} else {
var title = graphic.attributes[layer.displayField] || layer.name;
}
return title;
},
_getTextContent: function (graphic) {
var content = "";
content += "";
var layer = graphic.getLayer();
for (var a = 0; a < layer.fields.length; a++) {
var ming = layer.fields[a].name;
var ali = layer.fields[a].alias;
if (ali != "OBJECTID" && graphic.attributes[ming] != null) {
var regs = new RegExp("[\\u4E00-\\u9FFF]+", "g");
if (regs.test(ali) && ali.toLowerCase().indexOf("object") == -1 && ali.toLowerCase().indexOf("shape") == -1 &&
ali.indexOf("area") == -1 && ali.indexOf("AREA") == -1 && ali.indexOf("Area") == -1 && ali.indexOf("FID") == -1) {
content += "
" + layer.fields[a].alias + ":" + graphic.attributes[ming] + "
";
}
}
}
//判断特定图层,显示图片、全景、视频
content += "
";
$('.actionList').children('a:first').nextAll().remove(); //清除“缩放至”之后的所有元素
return content;
},
_locationGetTextContent: function (graphic) {
var content = "";
content += "";
for (var a in graphic.attributes) {
if (graphic.attributes[a] != null && graphic.attributes[a] != undefined) {
var regs = new RegExp("[\\u4E00-\\u9FFF]+", "g");
if (regs.test(a)) {
content += "
" + a + ":" + graphic.attributes[a] + "
";
}
}
}
//判断特定图层,显示图片、全景、视频
content += "
";
$('.actionList').children('a:first').nextAll().remove(); //清除“缩放至”之后的所有元素
return content;
}
});
return Widget;
});