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 = data.result;

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 = "http://10.10.5.155:6080/arcgis/rest/services/wireless/wirelessMap/MapServer";

var featureUrl = "http://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]));

你可能感兴趣的:(html,读写配置文件)