频道栏目
首页 > 网络 > 网络协议 > 正文

网络分析(最近设施)

2016-08-24 09:38:00           
收藏   我要投稿
dojo.require("esri.tasks.closestfacility");
var closestFacilityTask, params;
var facilityPointGraphicsLayerName = "facilityPointGraphicsLayer";
var incidentPointGraphicsLayerName = "incidentPointGraphicsLayer";
var routeGraphicsLayerName = "routeGraphicsLayer";
var facilitiesGraphicsLayer = null;
var incidentsGraphicsLayer = null;
var routeGraphicLayer = null;
var mapOnClick_addIncidents_connect, mapOnClick_addFacilities_connect;

//安置点符号
function getFacilitySymbol()
{
    var facilityPointSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 20,
              new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([89,95,35]), 2), new dojo.Color([130,159,83,0.40])
            );
    return facilityPointSymbol;
}

//转移点符号
function getIncidentSymbol()
{
    var incidentPointSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, 16,
              new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([89,95,35]), 2), new dojo.Color([130,159,83,0.40])
            );
    return incidentPointSymbol;
}

//路径符号
function getRouteSymbol()
{
    var routePolylineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([89,95,35]), 4.0);
    return routePolylineSymbol;
}

//安置点高亮符号
function getFacilityHighlightSymbol()
{
    var facilityHighlightSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, 16,
              new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,255,0]), 2), new dojo.Color([255,0,0,0.40])
            );
    return facilityHighlightSymbol;
}

//转移点高亮符号
function getIncidentHighlightSymbol()
{    
    var highlightSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0,255,255],0.25), 4.5);
    return highlightSymbol;
}

//路径高亮符号
function getRouteHighlightSymbol()
{
    var routePolylineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 4.0);
    return routePolylineSymbol;
}

//安置点图层
function getFacilityPointGraphicsLayer()
{
    if(facilitiesGraphicsLayer == null)
    {
        facilitiesGraphicsLayer = getGraphicsLayer(facilityPointGraphicsLayerName);
        var facilityPointSymbol = getFacilitySymbol();
        var facilityRenderer = new esri.renderer.SimpleRenderer(facilityPointSymbol);
        facilitiesGraphicsLayer.setRenderer(facilityRenderer);        
    }
    return facilitiesGraphicsLayer;
}

//转移点图层
function getIncidentPointGraphicsLayer()
{
    if(incidentsGraphicsLayer == null)
    {
        incidentsGraphicsLayer = getGraphicsLayer(incidentPointGraphicsLayerName);
        var incidentPointSymbol = getIncidentSymbol();
        var incidentsRenderer = new esri.renderer.SimpleRenderer(incidentPointSymbol);
        incidentsGraphicsLayer.setRenderer(incidentsRenderer);
        //高亮显示
        map.graphics.enableMouseEvents();
        dojo.connect(incidentsGraphicsLayer,"onMouseOver", function(evt){
            var graphic = evt.graphic;
            map.graphics.clear();
            var routeGraphicsLayer = getRouteGraphicsLayer();
            var facilityPointGraphicsLayer = getFacilityPointGraphicsLayer();
            for(var i=0; i=0; i--) {
        graphicsLayer.remove(params.incidents.features.splice(i, 1)[0]);
    }
    params.incidents.features = [];
}
  
/********************************************/
//添加安置点
function addFacilities() {
    removeEventHandlers();
    mapOnClick_addFacilities_connect = dojo.connect(map, "onClick", addFacility);
}

//添加安置点事件响应
function addFacility(evt) {
    var inPoint = new esri.geometry.Point(evt.mapPoint.x,evt.mapPoint.y,map.spatialReference);
    var location = new esri.Graphic(inPoint);
    graphicsLayer = getFacilityPointGraphicsLayer();
    graphicsLayer.add(location);
    params.facilities.features.push(location);
}

//添除安置点
function clearFacilities() {
    removeEventHandlers();
    graphicsLayer = getFacilityPointGraphicsLayer();
    for (var i=params.facilities.features.length-1; i>=0; i--) {
        graphicsLayer.remove(params.facilities.features.splice(i, 1)[0]);
    }
    params.facilities.features = [];
} 
/********************************************/ 
  
//取消添加安置点与转移点事件
function removeEventHandlers() {
    dojo.disconnect(mapOnClick_addIncidents_connect);
    dojo.disconnect(mapOnClick_addFacilities_connect);
}

//进行路径分析
function solveClosestFacility() {
    if(params.incidents.features.length<1) return;
    removeEventHandlers();
    /*
    params.facilities = [];
    closestFacilityTask.solve(params,completeCallback,errorCallback);
    */
    var geometryArray = [];
    for(var i=0; i 0){
          //alert(solveResult.messages[0]);
        }
    }
    function errorCallback(err)
    {
        Ext.encode(err);
    }
}

//初始化网络分析功能
function initNetwork() {
    params = new esri.tasks.ClosestFacilityParameters();
    params.travelDirection = esri.tasks.NATravelDirection.TO_FACILITY;
    params.defaultTargetFacilityCount = 1;
    params.impedenceAttribute = "METERS";
    //params.impedenceAttributeName = "METERS";
    params.directionsTimeAttribute = "MINUTES";
    //params.directionsTimeAttributeName = "MINUTES";
    params.restrictUTurns = esri.tasks.NAUTurn.ALLOW_BACKTRACK;
    params.useHierarchy = false;
    params.returnDirections = false;
    params.returnRoutes = true;
    params.returnFacilities = true;
    params.returnIncidents = true;
    params.returnPointBarriers = false;
    params.returnPolygonBarriers = false;
    params.returnPolylineBarriers = false;
    //
    params.directionsLanguage = "en-US";
    params.directionsOutputType = "complete";
    params.outputLines = esri.tasks.NAOutputLine.TRUE_SHAPE_WITH_MEASURE;
    params.outputGeometryPrecisionUnits = "esriKilometers";
    params.directionsLengthUnits = "esriKilometers";
    params.timeOfDayUsage = "start";    
    //
    params.facilities = new esri.tasks.FeatureSet();
    params.facilities.features = [];
    //
    params.incidents = new esri.tasks.FeatureSet();
    params.incidents.features = [];
    //
    params.outSpatialReference = map.spatialReference;   
    closestFacilityTask = new esri.tasks.ClosestFacilityTask(config.map.network.closestFacility); 
    //("https://10.1.102.171:6080/arcgis/rest/services/jcxx/TranferRoad/NAServer/ClosestFacility");
}

//清除最近设施分析结果
function clearClosestFacilityResult() {
    map.graphics.clear();
    graphicsLayer = getFacilityPointGraphicsLayer();
    graphicsLayer.clear();
    graphicsLayer = getIncidentPointGraphicsLayer();
    graphicsLayer.clear();
    graphicsLayer = getRouteGraphicsLayer();
    graphicsLayer.clear();
    clearParams();
} 

//清除最近设施分析参数
function clearParams()
{
    params.facilities.features = [];
    params.incidents.features = [];
}
相关TAG标签 设施 网络
上一篇:传输层--计算机网络
下一篇:网络分析之Pgrouting
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站