html读写配置⽂件,js:读取配置⽂件
前⾔ :gis开发中有很多地图url,直接写在各个js⽂件中,⼀旦需要修改(例如测试地址改为⽣产服务器上的arcgis服务地址)会⾮常⿇烦。为了⽅便管理这些服务地址,让其他开发⼈员接⼿时也能明确项⽬中调⽤了哪些服务,引⼊配置⽂件显得很有必要。
下⽅代码是实际项⽬的⼀份js⽂件,⾥⾯带了3个gis相关的地址;⼀旦需要更改必须全局搜索然后逐个⽂件去修改地址,⾮常⿇烦。(其他项⽬⽰例代码,与后⽂改造代码⽆关)
$(function () {
initData();
});
function initData() {
var touminigdu = 1;
HXcommon.ajax('facilitymge/service/InfoDivide/GetInfo', {}, function (data) {
var result = sult;
var html1 = '';
var itemName = data.mainItem;
var items = [];
var no;
for (var k = 0; k < itemName.length; k++) {
if (itemName[k].mainBiz != '未划分') {
items.push(itemName[k]);
} else {
no = itemName[k];
}
明星不雅照片
}
items.push(no);
itemName = items;
for (var k = 0; k < itemName.length; k++) {
var colorStr = itemName[k].color;
var cs = colorStr.split(',');
var color = [];
for (var i = 0; i < cs.length; i++) {
color.push(cs[i]);
}
html1 += '
' + itemName[k].mainBiz + '
';
}
$("#biz").html(html1);
});
}
require([
"esri/map", "esri/layers/FeatureLayer", "esri/geometry/Extent",
"esri/symbols/SimpleFillSymbol", "esri/symbols/SimpleLineSymbol",
"esri/renderers/SimpleRenderer", "esri/SpatialReference", "esri/graphic",
"esri/layers/GraphicsLayer", "esri/lang",
"esri/geometry/Polygon","esri/Color", "dojo/number", "dojo/dom-style",
"dijit/TooltipDialog", "dijit/popup", "dojo/domReady!"
], function (Map, FeatureLayer, Extent,
SimpleFillSymbol, SimpleLineSymbol,
SimpleRenderer,SpatialReference, Graphic, GraphicsLayer, esriLang,
Polygon,Color, number, domStyle,
TooltipDialog, dijitPopup) {
var map, dialog;
var myDynamicMapServiceLayer;
var contentSql = "''";
map = new Map("mapDiv", {
slider: false,
logo: false,
minScale: 61984.128,
maxScale: 968.5019999999997,包贝尔 王祖蓝
extent: new Extent({xmin: -100, ymin: -4000, xmax: 8000, ymax: 100, spatialReference: 3857})
});
var mapUrl = "10.10.5.155:6080/arcgis/rest/services/wireless/wirelessMap/MapServer";
var featureUrl = "10.10.5.155:6080/arcgis/rest/services/wireless/wirelessMap/FeatureServer/1"; var mapBasicLayer = new esri.layers.ArcGISDynamicMapServiceLayer(mapUrl);
map.addLayer(mapBasicLayer);
myDynamicMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer(mapUrl);
map.addLayer(myDynamicMapServiceLayer);
var gLayerPolygon = new GraphicsLayer();
map.addLayer(gLayerPolygon);
var symbol = new SimpleFillSymbol();
//填充⾊
symbol.setColor(new Color([0, 0, 0, 0.25]));
//边框颜⾊
symbol.outline.setColor([255, 0, 0, 1]);
symbol.outline.setWidth(3);
var featureLayer = new esri.layers.FeatureLayer(featureUrl, {
mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
outFields: ["*"]
});
var featureSymbol = new SimpleFillSymbol();//featureLayer加载空样式
featureSymbol.setColor(new Color([255, 255, 255, 0])); //⽹格填充⾊设为空
featureSymbol.outline.setColor([]);//边框颜⾊设为空
featureLayer.setRenderer(new SimpleRenderer(featureSymbol));
map.addLayer(featureLayer);//保持该图层在最上⽅ 以便响应⿏标事件
// size(245,125);
dialog = new TooltipDialog({
id: "tooltipDialog",
style: "position: absolute; width: 250px; font: normal normal normal 10pt Helvetica;z-index:100" });
dialog.startup();
<("load", function () {
<("mouse-out", closeDialog);
<("click", hightlightGraphicClickHandler);
});
//移开⿏标 关闭信息框
function closeDialog() {
dijitPopup.close(dialog);
};
//单击⾊块,弹出对应批⽂列表
function hightlightGraphicClickHandler(evt) {
console.log("频率信息是" + aphic.attributes.CODE);
var freqInfo = aphic.attributes.CODE;
HXcommon.layer.open('list.html?freqInfo=' + freqInfo, '批⽂列表', 'layer-fault-manage-txt', '1100', '570'); }
//⾊块⿏标移⼊添加⾼亮显⽰、信息框展⽰
<("mouse-over", function (evt) {
closeDialog();
${TYPE}
var t = "${TYPE}
频率范围: ${CODE}
频率范围:读取配置文件失败
眼的组词"
详细信息: ${DETAIL}
+ "详细信息:
";
var highlightSymbol = new SimpleFillSymbol(//⿏标滑过⾼亮显⽰样式
SimpleFillSymbol.STYLE_SOLID,
new SimpleLineSymbol(
SimpleLineSymbol.STYLE_SOLID,
new Color([255, 0, 0]), 1.5
),
new Color([125, 0, 0, 0.3])
)
;
var content = esriLang.aphic.attributes, t);
var highlightGraphic = new ry, highlightSymbol);
highlightGraphic.aphic.attributes);
这次是我真的决定离开dialog.setContent(content);
domStyle.set(dialog.domNode, "opacity", 0.85);
dijitPopup.open({
popup: dialog,
x: evt.pageX,
y: evt.pageY
});
});
//点击某⼀类别的⽆线电按钮,⾼亮显⽰该类别所有⾊块
$("#biz").on('click', 'span', function (evt) {
closeDialog();
map.setExtent(new Extent({xmin: -100, ymin: -4000, xmax: 8000, ymax: 100, spatialReference: 3857})); var queryName = ",'" + evt.currentTarget.innerText + "'";
if ($(this).hasClass("cur")) {
contentSql = contentSql.split(queryName)[0] + contentSql.split(queryName)[1];
$(this).removeClass("cur");
$(this).css("border", "2px solid transparent");
} else {
contentSql += queryName;
$(this).addClass("cur");
$(this).css("border", "green 1px solid");
}
var layerDefinitions = [];
layerDefinitions[1] = "type in(" + contentSql + ")";
myDynamicMapServiceLayer.setLayerDefinitions(layerDefinitions);
if ("''" == contentSql) {//取消所有选中后恢复底图默认透明度
mapBasicLayer.setOpacity(1);
} else {
mapBasicLayer.setOpacity(0.1);
}
});
//点击定位按钮,频谱图定位到对应输⼊位置并标⽰范围(或单条竖线)
$("#navigate").on('click', function (evt) {
var startNumber,endNumber;
var hzStr = $("#endunit").find("option:selected").text();
var xyObj;
if(""==$("#startfreq").val()){//⽆输⼊
HXcommon.layer.alert("请输⼊频率值");
保护水资源的标语
}else if(""!=$("#startfreq").val()&&""==$("#endfreq").val()){//单⼀输⼊,线条展⽰
startNumber = parseFloat($("#startfreq").val());
if(isNaN(startNumber)){//不是数字,错误输⼊
HXcommon.layer.alert("输⼊有误,请重新输⼊数值");
return;
}else{//正确输⼊了单⼀数值
xyObj = getXYvalue(hzStr, startNumber, startNumber);