define([
|
"dojo",
|
"dojo/_base/declare",
|
"dojo/_base/lang",
|
"base/BaseWidget",
|
"dojo/text!widgets/space/template.html",
|
"widgets/space/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/ArcGISDynamicMapServiceLayer",
|
"esri/layers/ArcGISTiledMapServiceLayer",
|
"esri/tasks/QueryTask",
|
"controls/tab/TabControl",
|
"esri/dijit/SymbolStyler",
|
"esri/styles/basic",
|
"dojo/_base/array",
|
"esri/InfoTemplate",
|
"esri/tasks/Geoprocessor",
|
"esri/SpatialReference",
|
"esri/tasks/FeatureSet",
|
"esri/tasks/query",
|
"esri/graphic",
|
"esri/Color",
|
"esri/symbols/SimpleFillSymbol",
|
"esri/symbols/SimpleLineSymbol",
|
"esri/symbols/SimpleMarkerSymbol",
|
"esri/layers/GraphicsLayer",
|
"esri/geometry/Point",
|
"esri/geometry/Polygon",
|
"esri/geometry/Polyline",
|
"esri/tasks/GeometryService",
|
"esri/tasks/ProjectParameters",
|
"esri/geometry/normalizeUtils",
|
"jslibs/geojsonUtil",
|
"esri/graphicsUtils",
|
"esri/layers/FeatureLayer",
|
"esri/geometry/geodesicUtils",
|
"esri/units",
|
"dojo/domReady!"
|
], function (dojo,
|
declare,
|
lang,
|
BaseWidget,
|
template,
|
config,
|
AppEvent,
|
ConfigData,
|
dataShow,
|
dom,
|
domConstruct,
|
domAttr,
|
domStyle,
|
on,
|
ArcGISDynamicMapServiceLayer,
|
ArcGISTiledMapServiceLayer,
|
QueryTask,
|
TabControl,
|
SymbolStyler,
|
basic,
|
arrayUtils,
|
InfoTemplate,
|
Geoprocessor,
|
SpatialReference,
|
FeatureSet,
|
Query,
|
Graphic,
|
Color,
|
SimpleFillSymbol,
|
SimpleLineSymbol,
|
SimpleMarkerSymbol,
|
GraphicsLayer,
|
Point,
|
Polygon,
|
Polyline,
|
GeometryService,
|
ProjectParameters,
|
normalizeUtils,
|
GeoJsonUtil,
|
graphicsUtils,
|
FeatureLayer,
|
geodesicUtils,
|
Units) {
|
var Widget = declare([BaseWidget], {
|
widgetName: "SpaceWidget",
|
label: "空间分析_叠加分析",
|
templateString: template,
|
_map: null,
|
SpaceObj: null,
|
inputLayer: null,
|
intersectLayer: null,
|
intersectFields: null,
|
intersectDisplayField: null,
|
gp: null,
|
timer: null,
|
intersect_graphicslayer: new GraphicsLayer(),
|
input_graphicslayer: new GraphicsLayer(),
|
inputgeometry: [],
|
inputfeatures: [],
|
_layui: null,
|
geometryservice: new GeometryService(ConfigData.geometryServiceUrl),
|
constructor: function (options, srcRefNode) {
|
this._map = options.map;
|
SpaceObj = this;
|
//初始化layui弹窗
|
layui.use('layer', function () {
|
SpaceObj._layui = layui.layer;
|
});
|
},
|
postCreate: function () {
|
|
},
|
startup: function () {
|
SpaceObj.inherited(arguments);
|
SpaceObj._init.ztree_input();
|
SpaceObj._init.ztree_intersect();
|
$("#SpaceWidget #input").click(function () {
|
$("#menuContent").fadeToggle(1);
|
});
|
$("#SpaceWidget #input").blur(function () {
|
$("#menuContent").fadeOut(1);
|
});
|
on(dom.byId("menuContent"), "mouseenter", function () {
|
$("#SpaceWidget #input").unbind("blur");
|
});
|
on(dom.byId("menuContent"), "mouseleave", function () {
|
$("#SpaceWidget #input").focus();
|
$("#SpaceWidget #input").blur(function () {
|
$("#menuContent").fadeOut(1);
|
});
|
});
|
$("#SpaceWidget #intersect").click(function () {
|
$("#multiPic").fadeToggle(1);
|
});
|
$("#SpaceWidget #intersect").blur(function () {
|
$("#multiPic").fadeOut(1);
|
});
|
$("#multiPic").mouseenter(function () {
|
$("#SpaceWidget #intersect").unbind("blur");
|
});
|
$("#multiPic").mouseleave(function () {
|
$("#SpaceWidget #intersect").focus();
|
$("#SpaceWidget #intersect").blur(function () {
|
$("#multiPic").fadeOut(1);
|
});
|
});
|
$("#SpaceWidget #intersect").keyup(function () {
|
if (!$(this).val()) {
|
SpaceObj.intersectLayer = null;
|
}
|
});
|
$("#SpaceWidget #input").keyup(function () {
|
if (!$(this).val()) {
|
SpaceObj.inputLayer = null;
|
}
|
});
|
//提示界面关闭按钮点击事件
|
$('#poputClose').unbind().click(function () {
|
$('#popup').hide();
|
});
|
//提示按钮点击事件
|
$('.gt').unbind().click(function () {
|
$("#popup div").html(config[$(this).attr("value")]);
|
$('#popup').show();
|
});
|
//高级选项按钮点击事件
|
$('#spaceFwBtn').click(function () {
|
if ($("#spaceFwBtn").hasClass('space-on')) {
|
$("#spaceFwBtn").removeClass('space-on');
|
$("#spaceFwBtn").addClass('space-off');
|
//打开高级选项弹窗
|
SpaceObj._layui.open({
|
type: 1,
|
closeBtn: 2,
|
// offset: ['100px', '300px'],
|
resize: false,
|
title: ["高级选项", 'line-height: 30px;height: 30px;'],
|
content: config.advancedDom,
|
area: ['500px', '300px'],
|
scrollbar: false,
|
shade: 0,
|
success: function (layero, index) {//打开弹窗后的回调函数
|
$('.layui-layer').css({//自动居中无效--手动设置弹窗居中
|
position: 'absolute',
|
top: ($(window).height() - $('.layui-layer').height()) / 2,
|
left: ($(window).width() - $('.layui-layer').width()) / 2,
|
});
|
|
$('.gt').unbind().click(function () {
|
$("#popup div").html(config[$(this).attr("value")]);
|
$('#popup').show();
|
});
|
//绑定导入文件的一些列方法
|
SpaceObj._init_import();
|
//选择市触发事件--查询对应的县区
|
$("#space_city").unbind().on("change", function () {
|
$('#space_county').empty().append("<option selected=\"selected\">县区/全市</option>");
|
$("#space_current_extent").removeClass('current_extent');
|
SpaceObj._countyQuery();
|
});
|
//当前视图按钮点击事件
|
$("#space_current_extent").unbind().click(function () {
|
if ($("#space_current_extent").hasClass("current_extent")) {
|
$("#space_current_extent").removeClass("current_extent");
|
$("#space_city").removeAttr("disabled");
|
$("#space_county").removeAttr("disabled");
|
} else {
|
$("#space_current_extent").addClass("current_extent");
|
$("#space_city option:first").prop("selected", 'selected');
|
// $("#space_city").attr("disabled", "disabled");
|
$("#space_county").empty().append("<option selected=\"selected\">县区/全市</option>");
|
}
|
});
|
//添加坐标点按钮
|
$("#addpt").unbind().click(function () {
|
SpaceObj._addpoint();
|
});
|
//完成添加按钮
|
$("#addft").unbind().click(function () {
|
SpaceObj._addfeatures();
|
});
|
},
|
cancel: function (index, layero) {//关闭按钮点击回调
|
$("#spaceFwBtn").removeClass('space-off');
|
$("#spaceFwBtn").addClass('space-on');
|
$("#SpaceWidget #input").attr("disabled", false);
|
$("#SpaceWidget #input").val(SpaceObj.inputLayer);
|
//清除已经画上去的点
|
SpaceObj.input_graphicslayer.clear();
|
}
|
});
|
//启用layui-tab
|
layui.use('element', function () {
|
var element = layui.element;
|
//一些事件监听
|
element.on('tab(demo)', function (data) {
|
//当切换到第二个标签之后则禁用使用图层输入要素
|
if (data.index > 0) {
|
//清空叠加要素中所选图层
|
SpaceObj.inputLayer = null;
|
$("#SpaceWidget #input").val("");
|
$("#SpaceWidget #input").attr("disabled", true);
|
} else {
|
$("#SpaceWidget #input").attr("disabled", false);
|
$("#SpaceWidget #input").val(SpaceObj.inputLayer);
|
var treeObj = $.fn.zTree.getZTreeObj("inputTree");
|
var node = treeObj.getNodeByParam("name", $("#SpaceWidget #input").val(), null);
|
if (node) {
|
SpaceObj.inputLayer = node.Url;
|
}
|
}
|
});
|
});
|
} else {
|
$("#spaceFwBtn").removeClass('space-off');
|
$("#spaceFwBtn").addClass('space-on');
|
//关闭所有弹窗
|
layer.closeAll();
|
}
|
});
|
//开始分析按钮点击事件
|
$("#spaceBtn").click(function () {
|
SpaceObj._areaQuery();
|
});
|
//给清除结果按钮绑定事件,防止重复绑定,先解绑再绑定
|
$('#Space_return').unbind("click");
|
$('#Space_return').click(function () {
|
SpaceObj.intersect_graphicslayer.clear();
|
SpaceObj.input_graphicslayer.clear();
|
SpaceObj.inputgeometry = [];
|
SpaceObj.inputfeatures = [];
|
$(".left-box-3 #space_result").empty().remove();
|
$("#space_idData").empty().remove();
|
$("#space_barcon").empty().remove();
|
SpaceObj._map.infoWindow.hide();
|
});
|
var template = new InfoTemplate();
|
SpaceObj.intersect_graphicslayer.name = "intersect";
|
template.setTitle(SpaceObj._getGraphicTitle);
|
template.setContent(SpaceObj._getTextContent);
|
SpaceObj.intersect_graphicslayer.setInfoTemplate(template);
|
SpaceObj._map.addLayers([SpaceObj.input_graphicslayer, SpaceObj.intersect_graphicslayer]);
|
AppEvent.addAppEventListener(AppEvent.APPLICATION_CLEAR, lang.hitch(this, function (evt) {
|
SpaceObj.input_graphicslayer.clear();
|
SpaceObj.intersect_graphicslayer.clear();
|
SpaceObj.inputgeometry = [];
|
SpaceObj.inputfeatures = [];
|
SpaceObj._map.infoWindow.hide();
|
}));
|
},
|
open: function () {
|
SpaceObj.inherited(arguments);
|
},
|
_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_NO"] + "号湿地斑块";
|
} else {
|
var title = graphic.attributes[layer.displayField];
|
}
|
return title;
|
|
},
|
_getTextContent: function (graphic) {
|
var content = "";
|
content += "<div class='con'>";
|
var layer = graphic.getLayer();
|
if (graphic.geometry.type == "polygon") {
|
var results = geodesicUtils.geodesicAreas([graphic.geometry], Units.SQUARE_METERS);
|
var result = results[0];
|
if (result > 100000000) {
|
result = (result / 1000000).toFixed(2) + "平方千米";
|
} else if (result > 10000) {
|
result = (result / 10000).toFixed(2) + "公顷";
|
} else {
|
result = result.toFixed(0) + "平方米";
|
}
|
content += "<div><b style='color: red'>叠加面积约为:" + result + "</b></div>";
|
} else if (graphic.geometry.type == "polyline") {
|
var results = geodesicUtils.geodesicLengths([graphic.geometry], Units.METERS);
|
var result = results[0];
|
if (result > 1000) {
|
result = (result / 1000).toFixed(3) + "公里";
|
} else {
|
result = result.toFixed(0) + "米";
|
}
|
content += "<div><b style='color: red'>叠加长度约为:" + result + "</b></div>";
|
}
|
for (var a = 0; a < layer.fields.length; a++) {
|
var ming = layer.fields[a].name;
|
var ali = layer.fields[a].alias;
|
if (ali != "OBJECTID") {
|
var regs = new RegExp("[\\u4E00-\\u9FFF]+", "g");
|
if (regs.test(ali) && graphic.attributes[ming] != null) {
|
content += "<div>" + layer.fields[a].alias + ":<b>" + graphic.attributes[ming] + "</b></div>";
|
}
|
}
|
}
|
content += "</div>";
|
//移除其他模块添加的<a>标签
|
$('.actionList').children('a:first').nextAll().remove(); //清除“缩放至”之后的所有元素
|
return content;
|
},
|
_init: {
|
//初始化输入图层目录树
|
"ztree_input": function ztree_input() {
|
var _ztreeObj = [];
|
// $.ajax({
|
// type: "get",
|
// url: getNativePath() + "resources/queryResourcesTree.do?soId=bbb7001c67c442540167c4a2a604000b",
|
// data: {
|
// "limit": 1000
|
// },
|
// dataType: "json",
|
// async: false,
|
// success: function (result) {
|
// var resultObj = result.data;
|
// for (var i = 0; i < resultObj.length; i++) {
|
// var searchCatalog = {};
|
// if (resultObj[i].resourcesName.indexOf("行政") == -1) {
|
// searchCatalog.id = resultObj[i].resourcesId;
|
// searchCatalog.pId = resultObj[i].resourcesPid;
|
// searchCatalog.name = resultObj[i].resourcesName;
|
// searchCatalog.Url = resultObj[i].resourcesUrl;
|
// _ztreeObj.push(searchCatalog);
|
// }
|
// }
|
// return _ztreeObj;
|
// },
|
// error: function (e) {
|
// console(e);
|
// alert("请求失败");
|
// }
|
// });
|
var setting = {
|
|
// view: {
|
// addDiyDom: SpaceObj._addDiyDom
|
// },
|
data: {
|
simpleData: {
|
enable: true
|
}
|
},
|
callback: {
|
beforeClick: SpaceObj._beforeClick,
|
onClick: SpaceObj._zTreeOnClick
|
}
|
};
|
$.fn.zTree.init($("#inputTree"), setting, _ztreeObj);
|
},
|
|
//初始化叠加图层目录树
|
"ztree_intersect": function ztree_intersect() {
|
var _ztree_intersect = [];
|
// $.ajax({
|
// type: "get",
|
// url: getNativePath() + "resources/queryResourcesTree.do?soId=bbb7001c67c442540167c4a2a604000b",
|
// data: {
|
// "limit": 1000
|
// },
|
// dataType: "json",
|
// async: false,
|
// success: function (result) {
|
// var resultObj = result.data;
|
// for (var i = 0; i < resultObj.length; i++) {
|
// var searchCatalog = {};
|
// if (resultObj[i].resourcesName.indexOf("点") == -1 && resultObj[i].resourcesName.indexOf("全景") == -1) {
|
// searchCatalog.id = resultObj[i].resourcesId;
|
// searchCatalog.pId = resultObj[i].resourcesPid;
|
// searchCatalog.name = resultObj[i].resourcesName;
|
// searchCatalog.Url = resultObj[i].resourcesUrl;
|
// _ztree_intersect.push(searchCatalog);
|
// }
|
// }
|
// return _ztree_intersect;
|
// },
|
// error: function (e) {
|
// console(e);
|
// alert("请求失败");
|
// }
|
// });
|
var _setting = {
|
// view: {
|
// addDiyDom: SpaceObj._addDiyDom
|
// },
|
data: {
|
simpleData: {
|
enable: true
|
}
|
},
|
callback: {
|
beforeClick: SpaceObj._beforeClick,
|
onClick: SpaceObj._zTreeOnClick
|
}
|
};
|
$.fn.zTree.init($("#intersectTree"), _setting, _ztree_intersect);
|
}
|
},
|
_beforeClick: function (treeId, treeNode) {
|
var check = (treeNode && !treeNode.isParent);
|
return check;
|
},
|
_zTreeOnClick: function (event, treeId, treeNode) {
|
if (treeId == "inputTree") {
|
SpaceObj.inputLayer = treeNode.name;
|
$("#input").val(treeNode.name);
|
$("#menuContent").fadeOut(1);
|
} else {
|
SpaceObj.intersectLayer = treeNode.name;
|
//获取当前节点服务字段和displayField
|
$.ajax({
|
url: treeNode.Url,
|
data: {
|
f: 'pjson'
|
},
|
dataType: 'json',
|
type: 'get',
|
success: function (e) {
|
SpaceObj.intersectFields = e.fields;
|
SpaceObj.intersectDisplayField = e.displayField;
|
}
|
});
|
$("#intersect").val(treeNode.name);
|
$("#multiPic").fadeOut(1);
|
}
|
},
|
//COUNTY查询--在县区选择栏中动态添加所包含的县区
|
_countyQuery: function () {
|
var Url = ConfigData.areaQueryURL + "/2";
|
var queryTask = new QueryTask(Url);
|
var query = new Query();
|
query.returnGeometry = false;
|
query.outFields = [
|
"COUNTY"
|
];
|
var queryParam;
|
if ($('#space_city option:selected').text() != "市/全省") {
|
queryParam = "CITY like '%" + $('#space_city option:selected').text() + "%'";
|
}
|
if (queryParam == null) {
|
return;
|
}
|
query.where = queryParam;
|
queryTask.execute(query, function (results) {
|
var optionVal = results.features;
|
for (var i in optionVal) {
|
$('#space_county').append("<option>" + optionVal[i].attributes["COUNTY"] + "</option>");
|
}
|
});
|
},
|
//叠加分析条件判断,包括行政区查询
|
_areaQuery: function () {
|
if (SpaceObj.intersectLayer == null) {
|
$("#bg").hide();
|
alert("请选择叠加图层");
|
return;
|
}
|
if (SpaceObj.inputLayer == null && SpaceObj.inputfeatures.length < 1) {
|
$("#bg").hide();
|
alert("请选择输入图层或导入要素");
|
return;
|
} else {
|
$("#bg").show();
|
SpaceObj.input_graphicslayer.clear();
|
SpaceObj.inputgeometry = [];
|
if ($("#space_current_extent").hasClass("current_extent")) {
|
var extent = [SpaceObj._map.extent.xmin, SpaceObj._map.extent.ymin, SpaceObj._map.extent.xmax, SpaceObj._map.extent.ymax];
|
SpaceObj._setIntersectParams(extent);
|
return;
|
} else if ($('#space_city option:selected').length > 0 && $('#space_city option:selected').text() != "市/全省") {
|
var queryParam;
|
var cityName = $('#space_city option:selected').text();
|
if ($('#space_county option:selected').text() == "县区/全市" && ConfigData.XZQfeatures) {
|
for (var i in ConfigData.XZQfeatures) {
|
if (ConfigData.XZQfeatures[i].attributes["CITY"] == cityName) {
|
SpaceObj._setIntersectParams(ConfigData.XZQfeatures[i]);
|
return;
|
}
|
}
|
} else {
|
queryParam = "CITY like '%" + $('#space_city option:selected').text() + "%'";
|
queryParam += "and COUNTY like '%" + $('#space_county option:selected').text() + "%'";
|
var URL = ConfigData.areaQueryURL + "/2";
|
}
|
}
|
if (queryParam == null) {
|
SpaceObj._setIntersectParams();
|
return;
|
}
|
var queryTask = new QueryTask(URL);
|
var query = new Query();
|
query.returnGeometry = true;
|
query.where = queryParam;
|
queryTask.execute(query, function (results) {
|
var len = results.features;
|
if (len.length > 0) {
|
//获取查询几何结果并查询结果所包含的要素
|
SpaceObj._setIntersectParams(len[0]);
|
return;
|
}
|
}, function (e) {
|
$("#bg").hide();
|
alert("范围查询出错");
|
console.log(e.message);
|
});
|
}
|
},
|
//设置叠加分析的参数
|
_setIntersectParams: function (extent) {
|
var param = {}, url = ConfigData.intersect_new;
|
if (extent) {
|
if (extent instanceof Array) {
|
param.Extent = extent.join(',');
|
} else {
|
url = ConfigData.intersect_custom;
|
var featureSet = new FeatureSet();
|
featureSet.features = [extent];
|
param.selectingFeatures = featureSet;
|
}
|
}
|
if (SpaceObj.inputfeatures.length > 0) {//如果导入了要素
|
var inputfeatureSet = new FeatureSet();
|
inputfeatureSet.features = SpaceObj.inputfeatures;
|
param.inputfeatures = inputfeatureSet;
|
url = ConfigData.intersect;
|
} else {
|
param.inputDataElement = 'sde.DBO.' + SpaceObj.inputLayer;
|
}
|
param.intersectDataElement = 'sde.DBO.' + SpaceObj.intersectLayer;
|
SpaceObj._intersect_analyse(url, param);
|
},
|
//执行叠加分析GP服务
|
_intersect_analyse: function (url, param) {
|
//构造gp服务参数
|
SpaceObj.gp = new Geoprocessor(url);
|
//第一步构造GP
|
var spatialReference = new SpatialReference(4490);
|
SpaceObj.gp.setOutSpatialReference(spatialReference);
|
SpaceObj.gp.setProcessSpatialReference(spatialReference);
|
//成功之后,调用_jobResult
|
SpaceObj.gp.submitJob(param, SpaceObj._jobResult, SpaceObj._joberror);
|
},
|
//取GP服务结果
|
_jobResult: function (result) {
|
// console.log(result);
|
var jobId = result.jobId;
|
var status = result.jobStatus;
|
if (status == "esriJobSucceeded") {
|
//成功之后,将其中的结果取出来,当然这也是参数名字。
|
//在模型中,想要取出中间结果,需要设置为模型参数
|
SpaceObj.gp.getResultData(jobId, "result", SpaceObj._addResults);
|
}
|
},
|
//GP服务错误回调
|
_joberror: function (error) {
|
if (error.jobStatus == "esriJobFailed") {
|
// $("#interesect").remove();
|
clearTimeout(SpaceObj.timer);
|
SpaceObj.timer = null;
|
$("#bg").hide();
|
alert("分析失败,请检查网络并清理内存后重试,或使用定制区域缩小分析范围!");
|
console.error(error);
|
}
|
},
|
//将叠加结果添加到地图上
|
_addResults: function (results) {
|
//清空参与分析的记录
|
SpaceObj.inputgeometry = [];
|
SpaceObj.inputfeatures = [];
|
SpaceObj.intersect_graphicslayer.clear();
|
//将结果输出至地图
|
var features = results.value.features;
|
if (features.length < 1) {
|
clearTimeout(SpaceObj.timer);
|
SpaceObj.timer = null;
|
alert("叠加结果为空");
|
$("#bg").hide();
|
return;
|
}
|
var treeObj = $.fn.zTree.getZTreeObj("intersectTree");
|
var nodes = treeObj.getSelectedNodes(); //状态改变的节点
|
SpaceObj.intersect_graphicslayer.name = nodes[0].name;
|
SpaceObj.intersect_graphicslayer.displayField = SpaceObj.intersectDisplayField;//城市规划区湿地没有NAME字段
|
SpaceObj.intersect_graphicslayer.fields = SpaceObj.intersectFields;//城市规划区湿地没有NAME字段
|
$(".left-box-3 #space_result").empty().remove();
|
$("#space_idData").empty().remove();
|
$("#space_barcon").empty().remove();
|
$(".left-box-3").append("<p id='space_result' style='width:100%;text-align:center;font-size:14px;'>重叠区域一共有:<h>" + features.length + "<h>个</p>");
|
$("#space_result").after(" <table id='space_idData' ></table>");
|
$("#space_idData").after("<div id='space_barcon' name='space_barcon' style='width:100%;text-align:center;font-size:14px;'></div>");
|
for (var i in features) {
|
var feature = features[i];
|
feature.attributes.TOTAL_AREA = (feature.attributes.TOTAL_AREA - 0).toFixed(2);
|
if (feature.geometry.type === "point" || feature.geometry.type === "multipoint") {
|
var symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 10,
|
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 255, 255]), 1),
|
new dojo.Color([0, 255, 255]));
|
} else if (feature.geometry.type === "line" || feature.geometry.type === "polyline") {
|
var symbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 255, 255]), 2);
|
} else {
|
var symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
|
new Color([255, 0, 0, 1]), 1), new Color([0, 255, 255, 0.65]));
|
}
|
feature.setSymbol(symbol);
|
SpaceObj.intersect_graphicslayer.add(feature);
|
if (SpaceObj.intersect_graphicslayer.name.indexOf("城") != -1 && SpaceObj.intersect_graphicslayer.name.indexOf("湿") != -1) {
|
$('#space_idData').append("<tr><td>" + (parseInt(i) + 1) + "、" + feature.attributes[SpaceObj.intersect_graphicslayer.displayField] +
|
"第" + feature.attributes["WETLAND_NO"] + "号湿地斑块</td>></tr>");
|
} else {
|
$('#space_idData').append("<tr><td>" + (parseInt(i) + 1) + "、" + feature.attributes[SpaceObj.intersect_graphicslayer.displayField] + "</td>></tr>");
|
}
|
on($('#space_idData tr:last'), "click", lang.hitch(feature, function (evt) {
|
var cPoint;
|
switch (this.geometry.type) {
|
case "point":
|
cPoint = new Point(this.geometry.x, this.geometry.y, SpaceObj._map.spatialReference); // 实例化一个点
|
break;
|
default:
|
var taxLotExtent = this.geometry.getExtent();
|
cPoint = taxLotExtent.getCenter();
|
break;
|
}
|
|
// console.log(this.getContent())
|
SpaceObj._map.infoWindow.setTitle(this.getTitle());
|
SpaceObj._map.infoWindow.setContent(this.getContent());
|
SpaceObj._map.infoWindow.show(cPoint);
|
SpaceObj._map.centerAt(cPoint);
|
}));
|
}
|
// console.log(SpaceObj.intersect_graphicslayer.displayField);
|
if (features.length > 10) {
|
SpaceObj._Result_fenye(1, 10);
|
}
|
clearTimeout(SpaceObj.timer);
|
SpaceObj.timer = null;
|
var featureExtent = graphicsUtils.graphicsExtent(features);
|
SpaceObj._map.setExtent(featureExtent);
|
$("#bg").hide();
|
// $("#interesect").remove();
|
},
|
//分页函数
|
_Result_fenye: function (pno, psize) {
|
var itable = document.getElementById("space_idData");
|
var num = itable.rows.length; //表格所有行数(所有记录数)
|
//console.log(num);
|
var totalPage = 0; //总页数
|
var pageSize = psize; //每页显示行数
|
//总共分几页
|
if (num / pageSize > parseInt(num / pageSize)) {
|
totalPage = parseInt(num / pageSize) + 1;
|
} else {
|
totalPage = parseInt(num / pageSize);
|
}
|
var currentPage = pno; //当前页数
|
var startRow = (currentPage - 1) * pageSize + 1; //开始显示的行 31
|
var endRow = currentPage * pageSize; //结束显示的行 40
|
endRow = (endRow > num) ? num : endRow;
|
//console.log(endRow);
|
//遍历显示数据实现分页
|
for (var i = 1; i < (num + 1); i++) {
|
var irow = itable.rows[i - 1];
|
if (i >= startRow && i <= endRow) {
|
irow.style.display = "block";
|
} else {
|
irow.style.display = "none";
|
}
|
}
|
var tempStr = "共" + num + "条记录 分" + totalPage + "页 当前第" + currentPage + "页</br>";
|
if (currentPage > 1) {
|
tempStr += "<a href=\"#\" onClick=\"SpaceObj._Result_fenye(" + (1) + "," + psize + ")\">首页<</a>";
|
tempStr += "<input type='button' value='上一页' style='background:#fff;width:50px;border:1px solid #919191;border-radius:5px' onClick=\"SpaceObj._Result_fenye(" + (currentPage - 1) + "," + psize + ")\"></input>"
|
} else {
|
tempStr += "首页";
|
tempStr += "<上一页";
|
}
|
if (currentPage < totalPage) {
|
tempStr += "<input type='button' value='下一页' style='background:#fff;width:50px;border:1px solid #919191;border-radius:5px' onClick=\"SpaceObj._Result_fenye(" + (currentPage + 1) + "," + psize + ")\">></input>";
|
tempStr += "<a href=\"#\" onClick=\"SpaceObj._Result_fenye(" + (totalPage) + "," + psize + ")\">尾页</a>";
|
} else {
|
tempStr += "下一页>";
|
tempStr += "尾页";
|
}
|
document.getElementById("space_barcon").innerHTML = tempStr;
|
},
|
//点击添加事件,根据输入坐标和所选坐标系,在地图中加入点
|
_addpoint: function () {
|
//获取所填写的坐标
|
var Coordinates = $('#input_coordinate').val();
|
$('#input_coordinate').val("");
|
$('#input_coordinate').focus();
|
if ((Coordinates == "") || (Coordinates.indexOf(",") <= -1)) {
|
alert("请按照格式输入坐标");
|
return;
|
}
|
var long_lat = Coordinates.split(",");
|
var long = long_lat[0];
|
var lat = long_lat[1];
|
if ((long > 180 && lat < 90) || (long < 180 && lat > 90) || isNaN(lat) || isNaN(long)) {
|
alert("请输入规范的坐标");
|
return;
|
}
|
if (long > 0 && long < 180 && lat < 90 && lat > 0) {
|
//获取选中的坐标系
|
var CoordinatesSys = $('#coordinate input[name="coor"]:checked ').val();
|
switch (CoordinatesSys) {
|
case "CGCS2000":
|
var point = new Point(parseFloat(long), parseFloat(lat), new SpatialReference(4490)); // 实例化一个点
|
SpaceObj.inputgeometry.push(point); //添加至点数组
|
var simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CROSS, 10, //定义一个点符号样式
|
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
|
new Color([255, 0, 0]), 1),
|
new Color([0, 255, 0, 0.55]));
|
var pt = new esri.Graphic(point, simpleMarkerSymbol);
|
SpaceObj.input_graphicslayer.add(pt); //添加坐标点
|
SpaceObj._map.centerAndZoom(point, 7); //定位至该坐标点
|
break;
|
case "Xian1980":
|
var wkid = 4610;
|
//转换坐标系至CGCS2000
|
var poin = new Point(parseFloat(long), parseFloat(lat), new SpatialReference(wkid));
|
var projectParameters = new ProjectParameters();
|
projectParameters.geometries = [poin];
|
projectParameters.outSR = new SpatialReference(4490);
|
SpaceObj.geometryservice.project(projectParameters, function (result) {
|
console.log(result[0]);
|
SpaceObj.inputgeometry.push(result[0]); //添加至点数组
|
var simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CROSS, 10, //定义一个点符号样式
|
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
|
new Color([255, 0, 0]), 1),
|
new Color([0, 255, 0, 0.55]));
|
var pt = new esri.Graphic(result[0], simpleMarkerSymbol);
|
SpaceObj.input_graphicslayer.add(pt); //添加坐标点
|
SpaceObj._map.centerAndZoom(result[0], 7); //定位至该坐标点
|
return;
|
});
|
break;
|
default:
|
break;
|
}
|
} else {
|
//获取选中的坐标系
|
var CoordinatesSys = $('#coordinate input[name="coor"]:checked ').val();
|
var mm = long.toString();
|
var nn = mm.split(".");
|
var yy = nn[0];
|
if (yy.length >= 8) {
|
var zz = yy.substring(2, yy.length);
|
long = zz + "." + nn[1];
|
long = parseFloat(long);
|
}
|
switch (CoordinatesSys) {
|
case "CGCS2000":
|
var wkid = 4548;
|
//转换坐标系至CGCS2000
|
var poin = new Point(parseFloat(long), parseFloat(lat), new SpatialReference(wkid));
|
var projectParameters = new ProjectParameters();
|
projectParameters.geometries = [poin];
|
projectParameters.outSR = new SpatialReference(4490);
|
SpaceObj.geometryservice.project(projectParameters, function (result) {
|
SpaceObj.inputgeometry.push(result[0]); //添加至点数组
|
var simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CROSS, 10, //定义一个点符号样式
|
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
|
new Color([255, 0, 0]), 1),
|
new Color([255, 0, 0, 1]));
|
var pt = new esri.Graphic(result[0], simpleMarkerSymbol);
|
SpaceObj.input_graphicslayer.add(pt); //添加坐标点
|
SpaceObj._map.centerAndZoom(result[0], 7); //定位至该坐标点
|
return;
|
});
|
break;
|
case "Xian1980":
|
var wkid = 2384;
|
//转换坐标系至CGCS2000
|
var poin = new Point(parseFloat(long), parseFloat(lat), new SpatialReference(wkid));
|
var projectParameters = new ProjectParameters();
|
projectParameters.geometries = [poin];
|
projectParameters.outSR = new SpatialReference(4490);
|
SpaceObj.geometryservice.project(projectParameters, function (result) {
|
SpaceObj.inputgeometry.push(result[0]); //添加至点数组
|
var simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CROSS, 10, //定义一个点符号样式
|
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
|
new Color([255, 0, 0]), 1),
|
new Color([255, 0, 0, 1]));
|
var pt = new esri.Graphic(result[0], simpleMarkerSymbol);
|
SpaceObj.input_graphicslayer.add(pt); //添加坐标点
|
SpaceObj._map.centerAndZoom(result[0], 7); //定位至该坐标点
|
return;
|
});
|
break;
|
default:
|
break;
|
}
|
}
|
},
|
//完成添加事件,根据所选的几何类型,生成对应的几何要素
|
_addfeatures: function () {
|
var type = $("#graphic_type input[name='abc']:checked").val();
|
switch (parseInt(type)) {
|
case 1:
|
point();
|
break;
|
case 2:
|
line();
|
break;
|
case 3:
|
polygon();
|
break;
|
default:
|
break;
|
}
|
|
//生成点
|
function point() {
|
if (SpaceObj.inputgeometry.length < 1) {
|
alert("先添加坐标点");
|
return;
|
}
|
for (var num in SpaceObj.inputgeometry) {
|
SpaceObj.inputfeatures.push(new Graphic(SpaceObj.inputgeometry));
|
}
|
SpaceObj.inputgeometry = [];
|
return;
|
}
|
|
//生成线
|
function line() {
|
if (SpaceObj.inputgeometry.length < 1) {
|
alert("先添加坐标点");
|
return;
|
}
|
var symbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0, 0.45]), 2);
|
var polyline = new Polyline(new SpatialReference({
|
wkid: 4490
|
}));
|
polyline.addPath(SpaceObj.inputgeometry);
|
var gra_line = new Graphic(polyline, symbol);
|
SpaceObj.inputfeatures.push(gra_line);
|
SpaceObj.inputgeometry = [];
|
SpaceObj.input_graphicslayer.add(gra_line);
|
return;
|
}
|
|
//生成面
|
function polygon() {
|
if (SpaceObj.inputgeometry.length < 1) {
|
alert("先添加坐标点");
|
return;
|
}
|
var polygon = new Polygon(new SpatialReference({
|
wkid: 4490
|
}));
|
var ring = 0;
|
var rings = new Array([]);
|
var first = true;
|
for (var num in SpaceObj.inputgeometry) {
|
rings[ring].push(SpaceObj.inputgeometry[num]);
|
if (!first && rings[ring][0].x == SpaceObj.inputgeometry[num].x && rings[ring][0].y == SpaceObj.inputgeometry[num].y) {
|
polygon.addRing(rings[ring]);
|
if (parseInt(num) < parseInt(SpaceObj.inputgeometry.length - 1)) {
|
rings.push(new Array());
|
ring++;
|
first = true;
|
continue;
|
}
|
}
|
first = false;
|
}
|
if (rings[ring][0].x != SpaceObj.inputgeometry[num].x || rings[ring][0].y != SpaceObj.inputgeometry[num].y || rings[ring].length < 2) {
|
alert("多边形未闭合,请检查");
|
return;
|
}
|
rings = null;
|
SpaceObj.inputfeatures.push(polygon);
|
SpaceObj.inputgeometry = [];
|
SpaceObj.normalize(SpaceObj.inputfeatures);
|
return;
|
}
|
},
|
//标准化几何图形
|
normalize: function (polygons) {
|
normalizeUtils.normalizeCentralMeridian(polygons, SpaceObj.geometryservice).then(function (normalizedGeometries) {
|
console.log(normalizedGeometries);
|
var normalizedGeometrires_polygon = [];
|
for (var x in normalizedGeometries) {
|
normalizedGeometrires_polygon.push(normalizedGeometries[x]);
|
}
|
//简化多边形,并使用户绘制多边形拓扑正确
|
SpaceObj.geometryservice.simplify(normalizedGeometrires_polygon, function (geometries) {
|
var _geometries = geometries;
|
SpaceObj.inputfeatures = [];
|
var symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255, 0, 0, 1]), 1), new Color([255, 0, 0, 0.45]));
|
for (var n in _geometries) {
|
var gra_polygon = new Graphic(_geometries[n], symbol);
|
SpaceObj.inputfeatures.push(gra_polygon);
|
SpaceObj.input_graphicslayer.add(gra_polygon);
|
}
|
return;
|
});
|
});
|
},
|
//绑定导入文件的事件
|
_init_import: function () {
|
$("#okBtn").unbind().click(lang.hitch(this, function (evt) {
|
SpaceObj.inputgeometry = [];
|
SpaceObj.inputfeatures = [];
|
var sds = $("#file_imp li");
|
for (var up = 0; up < sds.length; up++) {
|
if ($(sds[up]).hasClass("check")) {
|
if (up == 1 || up == 2) {
|
this.submitClick();
|
} else if (up == 3) {
|
this.submitClick_kml();
|
} else {
|
this.submitClick_shp();
|
}
|
}
|
}
|
}));
|
$('#file_imp li').unbind().click(function (evt) {
|
if (this.id == "txt_imp" || this.id == "excel_imp") {
|
$("#dis_imp").css({
|
"display": "block"
|
});
|
$(".ups").css({
|
"display": "none"
|
});
|
$(".upload").css({
|
"display": "block"
|
});
|
} else if (this.id == "kml_imp") {
|
$("#dis_imp").css({
|
"display": "none"
|
});
|
$(".ups").css({
|
"display": "none"
|
});
|
$("#upload_" + this.id).css({
|
"display": "block"
|
});
|
} else if (this.id == "shp_imp") {
|
$("#dis_imp").css({
|
"display": "none"
|
});
|
$(".ups").css({
|
"display": "none"
|
});
|
$("#upload_" + this.id).css({
|
"display": "block"
|
});
|
} else {
|
return;
|
}
|
$("#file_imp li").removeClass("check");
|
$("#" + this.id).addClass("check");
|
});
|
},
|
//以下都是导入文件的方法
|
submitClick: function () {
|
/*var pictureSymbol = new PictureMarkerSymbol("assets/images/location.png", 25, 25);*/
|
SpaceObj.input_graphicslayer.clear();
|
var sms = new SimpleMarkerSymbol();
|
sms.setColor(new Color([255, 0, 0]));
|
sms.setOutline(null);
|
sms.setSize("10");
|
console.log($(".upload")[0]);
|
console.log(new FormData($(".upload")[0]));
|
$.ajax({
|
url: ConfigData.txtAjax,
|
type: 'post',
|
data: new FormData($(".upload")[0]), // IE10以上版本支持
|
processData: false,
|
contentType: false,
|
dataType: 'json',
|
success: function (data) {
|
SpaceObj.input_graphicslayer.clear();
|
SpaceObj.inputfeatures = [];
|
if (data.error) {
|
alert(data.error);
|
} else {
|
SpaceObj.input_graphicslayer.clear();
|
switch (data.type) {
|
case "dian": {
|
for (var dd = 0; dd < data.data.length; dd++) {
|
var dian_data = data.data[dd];
|
for (var i = 0; i < dian_data.length; i++) {
|
var lat = dian_data[i].x;
|
var long = dian_data[i].y;
|
var poin = new Point(parseFloat(lat), parseFloat(long), new SpatialReference({
|
wkid: 4490
|
}));
|
var point = new Point(parseFloat(lat), parseFloat(long), new SpatialReference({
|
wkid: 4490
|
}));
|
var content = "";
|
content += "<div class='con'>";
|
content += "<div>" + "经度" + ":<b>" + dian_data[i].x + "</b></div>";
|
content += "<div>" + "纬度" + ":<b>" + dian_data[i].y + "</b></div>";
|
content += "<div>" + "名称" + ":<b>" + dian_data[i].name + "</b></div>";
|
content += "<div>" + "备注" + ":<b>" + dian_data[i].remark + "</b></div>";
|
content += "</div>";
|
var graphic = new esri.Graphic(poin, sms, content);
|
var infoTemplate = new InfoTemplate();
|
infoTemplate.setTitle(dian_data[i].name);
|
infoTemplate.setContent(content);
|
graphic.setInfoTemplate(infoTemplate);
|
SpaceObj.inputfeatures.push(graphic);
|
SpaceObj.input_graphicslayer.add(graphic);
|
SpaceObj._map.centerAndZoom(poin, 6);
|
}
|
}
|
}
|
break;
|
case "xian": {
|
var xian_arr = [];
|
var name;
|
var mai = data.data;
|
if (mai.length > 1) {
|
for (var dd = 0; dd < data.data.length; dd++) {
|
var polyline = new Polyline((new SpatialReference({
|
wkid: 4490
|
})));
|
var xian_data = data.data[dd];
|
if (xian_data.length > 1) {
|
for (var i = 0; i < xian_data.length; i++) {
|
xian_arr.push([xian_data[i].x, xian_data[i].y]);
|
name = xian_data[i].name;
|
}
|
polyline.addPath(xian_arr);
|
var sls = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255, 0, 0]), 2);
|
|
var graphic = new esri.Graphic(polyline, sls, content);
|
SpaceObj.inputfeatures.push(graphic);
|
SpaceObj.input_graphicslayer.add(graphic);
|
SpaceObj._map.setExtent(graphic._extent.expand(5));
|
xian_arr = [];
|
} else {
|
alert("名称为'" + name + "'的坐标点个数少于2,不能构成线");
|
}
|
}
|
} else {
|
var xian_data = data.data[0];
|
for (var i = 0; i < xian_data.length; i++) {
|
var polyline = new Polyline((new SpatialReference({
|
wkid: 4490
|
})));
|
if (i != xian_data.length - 1) {
|
|
if (xian_data[i].no == xian_data[i + 1].no) {
|
xian_arr.push([xian_data[i].x, xian_data[i].y]);
|
} else {
|
xian_arr.push([xian_data[i].x, xian_data[i].y]);
|
name = xian_data[i].name;
|
if (xian_arr.length > 2 || xian_arr.length == 2) {
|
polyline.addPath(xian_arr);
|
var sls = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255, 0, 0]), 2);
|
|
var content = "";
|
content += "<div class='con'>";
|
content += "<div>" + "名称" + ":<b>" + xian_data[i].name + "</b></div>";
|
content += "<div>" + "备注" + ":<b>" + xian_data[i].remark + "</b></div>";
|
content += "</div>";
|
var graphic = new esri.Graphic(polyline, sls, content);
|
var infoTemplate = new InfoTemplate();
|
infoTemplate.setTitle(xian_data[i].name);
|
infoTemplate.setContent(content);
|
graphic.setInfoTemplate(infoTemplate);
|
SpaceObj.inputfeatures.push(graphic);
|
SpaceObj.input_graphicslayer.add(graphic);
|
SpaceObj._map.setExtent(graphic._extent.expand(5));
|
xian_arr = [];
|
} else {
|
alert("名称为'" + name + "'的坐标点个数少于2,不能构成线");
|
}
|
}
|
} else {
|
xian_arr.push([xian_data[i].x, xian_data[i].y]);
|
name = xian_data[i].name;
|
if (xian_arr.length > 2 || xian_arr.length == 2) {
|
polyline.addPath(xian_arr);
|
var sls = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255, 0, 0]), 2);
|
var content = "";
|
content += "<div class='con'>";
|
content += "<div>" + "名称" + ":<b>" + xian_data[i].name + "</b></div>";
|
content += "<div>" + "备注" + ":<b>" + xian_data[i].remark + "</b></div>";
|
content += "</div>";
|
var graphic = new esri.Graphic(polyline, sls, content);
|
var infoTemplate = new InfoTemplate();
|
infoTemplate.setTitle(xian_data[i].name);
|
infoTemplate.setContent(content);
|
graphic.setInfoTemplate(infoTemplate);
|
SpaceObj.inputfeatures.push(graphic);
|
SpaceObj.input_graphicslayer.add(graphic);
|
SpaceObj._map.setExtent(graphic._extent.expand(5));
|
} else {
|
alert("名称为'" + name + "'的坐标点个数少于2,不能构成线");
|
}
|
}
|
}
|
}
|
}
|
break;
|
case "mian": {
|
var mian_arr = [];
|
var name;
|
var mai = data.data;
|
if (mai.length > 1) {
|
for (var dd = 0; dd < data.data.length; dd++) {
|
var polygon = new Polygon(new SpatialReference({
|
wkid: 4490
|
}));
|
var mian_data = data.data[dd];
|
mian_arr = [];
|
if (mian_data.length > 3) {
|
for (var i = 0; i < mian_data.length; i++) {
|
mian_arr.push([mian_data[i].x, mian_data[i].y]);
|
name = mian_data[i].name;
|
}
|
polygon.addRing(mian_arr);
|
var sfs = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
|
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
|
new Color([255, 0, 0]), 1), new Color([255, 255, 0, 0.45])
|
);
|
var graphic = new esri.Graphic(polygon, sfs, content);
|
SpaceObj.inputfeatures.push(graphic);
|
SpaceObj.input_graphicslayer.add(graphic);
|
SpaceObj._map.setExtent(graphic._extent.expand(5));
|
} else {
|
alert("名称为'" + name + "'的坐标点个数少于3,不能构成面");
|
}
|
|
}
|
} else {
|
var mian_data = data.data[0];
|
for (var i = 0; i < mian_data.length; i++) {
|
var polygon = new Polygon(new SpatialReference({
|
wkid: 4490
|
}));
|
if (i != mian_data.length - 1) {
|
|
if (mian_data[i].no == mian_data[i + 1].no) {
|
mian_arr.push([mian_data[i].x, mian_data[i].y]);
|
} else {
|
mian_arr.push([mian_data[i].x, mian_data[i].y]);
|
mian_arr.push(mian_arr[0]);
|
name = mian_data[i].name;
|
if (mian_arr.length > 4 || mian_arr.length == 4) {
|
polygon.addRing(mian_arr);
|
var sfs = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
|
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
|
new Color([255, 0, 0]), 1), new Color([255, 255, 0, 0.45])
|
);
|
|
var content = "";
|
content += "<div class='con'>";
|
content += "<div>" + "名称" + ":<b>" + mian_data[i].name + "</b></div>";
|
content += "<div>" + "备注" + ":<b>" + mian_data[i].remark + "</b></div>";
|
content += "</div>";
|
var graphic = new esri.Graphic(polygon, sfs, content);
|
var infoTemplate = new InfoTemplate();
|
infoTemplate.setTitle(mian_data[i].name);
|
infoTemplate.setContent(content);
|
graphic.setInfoTemplate(infoTemplate);
|
SpaceObj.inputfeatures.push(graphic);
|
SpaceObj.input_graphicslayer.add(graphic);
|
SpaceObj._map.setExtent(graphic._extent.expand(5));
|
mian_arr = [];
|
} else {
|
alert("名称为'" + name + "'的坐标点个数少于3,不能构成面");
|
}
|
}
|
} else {
|
mian_arr.push([mian_data[i].x, mian_data[i].y]);
|
mian_arr.push(mian_arr[0]);
|
name = mian_data[i].name;
|
if (mian_arr.length > 4 || mian_arr.length == 4) {
|
polygon.addRing(mian_arr);
|
var sfs = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
|
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
|
new Color([255, 0, 0]), 1), new Color([255, 255, 0, 0.45])
|
);
|
var content = "";
|
content += "<div class='con'>";
|
content += "<div>" + "名称" + ":<b>" + mian_data[i].name + "</b></div>";
|
content += "<div>" + "备注" + ":<b>" + mian_data[i].remark + "</b></div>";
|
content += "</div>";
|
var graphic = new esri.Graphic(polygon, sfs, content);
|
var infoTemplate = new InfoTemplate();
|
infoTemplate.setTitle(mian_data[i].name);
|
infoTemplate.setContent(content);
|
graphic.setInfoTemplate(infoTemplate);
|
graphic.name = "mian";
|
SpaceObj.inputfeatures.push(graphic);
|
SpaceObj.input_graphicslayer.add(graphic);
|
SpaceObj._map.setExtent(graphic._extent.expand(5));
|
|
} else {
|
alert("名称为'" + name + "'的坐标点个数少于3,不能构成面");
|
}
|
|
}
|
|
}
|
}
|
//SpaceObj._map.setExtent(SpaceObj.input_graphicslayer._extent.expand(5));
|
}
|
break;
|
}
|
|
/*SpaceObj._map.setExtent(graphic._extent.expand(1.5)); */
|
|
/*SpaceObj.input_graphicslayer.name="sss";
|
SpaceObj.input_graphicslayer.id="sss";*/
|
/*SpaceObj.input_graphicslayer.className="sss";
|
SpaceObj.input_graphicslayer.layerId="sss";
|
SpaceObj.input_graphicslayer.Type="sss";*/
|
|
//SpaceObj._map.setExtent(new Extent(SpaceObj.input_graphicslayer.initialExtent, new SpatialReference({wkid:4490})));
|
|
}
|
},
|
error: function (e) {
|
console(e);
|
alert("错误!" + e.status + ":" + e.statusText);
|
}
|
});
|
return false;
|
},
|
submitClick_kml: function () {
|
var layerDefinition = {
|
"geometryType": "esriGeometryPolygon",
|
"fields": [{
|
"name": "BUFF_DIST",
|
"type": "esriFieldTypeInteger",
|
"alias": "Buffer Distance"
|
}]
|
};
|
var sms = new SimpleMarkerSymbol();
|
sms.setColor(new Color([255, 0, 0]));
|
sms.setOutline(null);
|
sms.setSize("10");
|
SpaceObj.input_graphicslayer.clear();
|
$.ajax({
|
url: ConfigData.kmlAjax,
|
type: 'post',
|
data: new FormData($("#upload_kml_imp")[0]), // IE10以上版本支持
|
processData: false,
|
contentType: false,
|
dataType: 'json',
|
success: function (data) {
|
SpaceObj.input_graphicslayer.clear();
|
SpaceObj.inputfeatures = [];
|
if (data.error) {
|
alert(data.error);
|
} else {
|
SpaceObj.input_graphicslayer.clear();
|
var Model = data[0].readInputModels;
|
var Line = data[0].readInputModelLines;
|
var Mian = data[0].readInputModelMians;
|
/*============点===================*/
|
if (Model.length > 0) {
|
var points = [];
|
var attributes = [];
|
for (var i = 0; i < Model.length; i++) {
|
var lat = Model[i].longitude;
|
var long = Model[i].latitude;
|
var poin = new Point(parseFloat(lat), parseFloat(long), new SpatialReference({
|
wkid: parseInt(4490)
|
}));
|
points[i] = poin;
|
attributes[i] = {
|
name: Model[i].name,
|
remark: Model[i].remark
|
};
|
}
|
var PrjParams = new ProjectParameters();
|
PrjParams.geometries = points;
|
PrjParams.outSR = new SpatialReference({
|
wkid: 4490
|
});
|
geometryService.project(PrjParams, function (outputpoint) {
|
for (var int = 0; int < outputpoint.length; int++) {
|
var content = "";
|
content += "<div class='con'>";
|
content += "<div>" + "经度" + ":<b>" + outputpoint[int].x + "</b></div>";
|
content += "<div>" + "纬度" + ":<b>" + outputpoint[int].y + "</b></div>";
|
content += "<div>" + "名称" + ":<b>" + attributes[int].name + "</b></div>";
|
content += "<div>" + "备注" + ":<b>" + attributes[int].remark + "</b></div>";
|
content += "</div>";
|
var graphic = new esri.Graphic(outputpoint[int], sms, content);
|
var infoTemplate = new InfoTemplate();
|
infoTemplate.setTitle(attributes[int].name);
|
infoTemplate.setContent(content);
|
graphic.setInfoTemplate(infoTemplate);
|
SpaceObj.inputfeatures.push(graphic);
|
SpaceObj.input_graphicslayer.add(graphic);
|
//SpaceObj._map.centerAndZoom(outputpoint[int], 6);
|
}
|
|
});
|
}
|
/*============结束===================*/
|
/*============线===================*/
|
if (Line.length > 0) {
|
var xian_arr = [];
|
var name;
|
for (var i = 0; i < Line.length; i++) {
|
var polyline = new Polyline((new SpatialReference({
|
wkid: 4490
|
})));
|
var xian_data = Line[i].readInputModels;
|
if (xian_data.length > 1) {
|
for (var yy = 0; yy < xian_data.length; yy++) {
|
xian_arr.push([xian_data[yy].longitude, xian_data[yy].latitude]);
|
name = xian_data[yy].name;
|
}
|
polyline.addPath(xian_arr);
|
var sls = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255, 0, 0]), 2);
|
var graphic = new esri.Graphic(polyline, sls, "");
|
SpaceObj.inputfeatures.push(graphic);
|
SpaceObj.input_graphicslayer.add(graphic);
|
SpaceObj._map.setExtent(graphic._extent.expand(5));
|
xian_arr = [];
|
} else {
|
alert("名称为'" + name + "'的坐标点个数少于2,不能构成线");
|
}
|
}
|
}
|
/*============结束===================*/
|
/*============面===================*/
|
if (Mian.length > 0) {
|
var mian_arr = [];
|
var name;
|
for (var dd = 0; dd < Mian.length; dd++) {
|
var polygon = new Polygon(new SpatialReference({
|
wkid: 4490
|
}));
|
var mian_data = Mian[dd].readInputModels;
|
mian_arr = [];
|
if (mian_data.length > 3) {
|
for (var i = 0; i < mian_data.length; i++) {
|
mian_arr.push([mian_data[i].longitude, mian_data[i].latitude]);
|
name = mian_data[i].name;
|
}
|
polygon.addRing(mian_arr);
|
var sfs = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
|
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
|
new Color([255, 0, 0]), 1), new Color([255, 255, 0, 0.45])
|
);
|
var graphic = new esri.Graphic(polygon, sfs, content);
|
SpaceObj.inputfeatures.push(graphic);
|
SpaceObj.input_graphicslayer.add(graphic);
|
SpaceObj._map.setExtent(graphic._extent.expand(5));
|
} else {
|
alert("名称为'" + name + "'的坐标点个数少于3,不能构成面");
|
}
|
}
|
}
|
/*========结束========*/
|
}
|
},
|
error: function (e) {
|
console(e);
|
alert("错误!" + e.status + ":" + e.statusText);
|
}
|
});
|
return false;
|
},
|
submitClick_shp: function () {
|
var SpaceObj = this;
|
$.ajax({
|
url: ConfigData.shpAjax,
|
type: 'post',
|
data: new FormData($("#upload_shp_imp")[0]), // IE10以上版本支持
|
processData: false,
|
contentType: false,
|
dataType: 'json',
|
success: function (data) {
|
// debugger;
|
SpaceObj.input_graphicslayer.clear();
|
SpaceObj.inputfeatures = [];
|
var jsonf = new GeoJsonUtil();
|
var json = jsonf.geojsonToArcGIS(data);
|
var features = [];
|
var geo;
|
var symbol;
|
for (var i = 0; i < json.length; i++) {
|
switch (json[i].geometry.type) {
|
case "Point":
|
geo = new Point();
|
geo.x = json[i].geometry.x;
|
geo.y = json[i].geometry.y;
|
symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 10,
|
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1),
|
new dojo.Color([255, 0, 0]));
|
|
break;
|
case "Polygon":
|
geo = new Polygon();
|
geo.rings = json[i].geometry.rings;
|
symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
|
new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASH, new dojo.Color([255, 0, 0]), 1),
|
new dojo.Color([255, 0, 0, 0.45]));
|
break;
|
case "LineString":
|
var geo = new Polyline();
|
geo.paths = json[i].geometry.paths;
|
symbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 2);
|
break;
|
}
|
geo.spatialReference.wkid = json[i].geometry.spatialReference.wkid;
|
g = new esri.Graphic(geo, symbol, json[i].attributes);
|
SpaceObj.inputfeatures.push(g);
|
SpaceObj.input_graphicslayer.add(g);
|
features.push(g);
|
}
|
/*var getuuid = uuid();
|
console.log(getuuid);
|
var newNode = { id:getuuid,name:data.layername,checked:true};
|
SpaceObj._zTree.addNodes(null, newNode);
|
|
ConfigData.layers[getuuid] = SpaceObj.input_graphicslayer;*/
|
|
var myFeatureExtent = graphicsUtils.graphicsExtent(features);
|
SpaceObj._map.setExtent(myFeatureExtent.expand(2));
|
},
|
error: function (e) {
|
console(e);
|
alert("错误!" + e.status + ":" + e.statusText);
|
}
|
});
|
}
|
});
|
return Widget;
|
});
|