SuperMap for JavaScript 中的最佳路径分析功能转换为三维中的最佳路径分析功能
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SuperMap for JavaScript 中的最佳路径分析功能转换为三维中的最佳路径分析功能相关的知识,希望对你有一定的参考价值。
1、注意,要处理有交通网络分析服务
2、代码
var nodeArray = [],pathListIndex = 0,routeCompsIndex = 0,pathTime,style = {
strokeColor: "#304DBE",
strokeWidth: 3,
pointerEvents: "visiblePainted",
fill: false
},
styleGuidePoint = {
pointRadius: 10,
externalGraphic: path + "/SWimg/c1.png"
};
var url2="http://localhost:8090/iserver/services/transportationAnalyst-scene/rest/networkanalyst/[email protected]";
//查找最优路径
function findPath() {
if(nodeArray.length>1)
{
alert("进来了。");
var findPathService, parameter, analystParameter, resultSetting;
resultSetting = new SuperMap.REST.TransportationAnalystResultSetting({
returnEdgeFeatures: true,
returnEdgeGeometry: true,
returnEdgeIDs: true,
returnNodeFeatures: true,
returnNodeGeometry: true,
returnNodeIDs: true,
returnPathGuides: true,
returnRoutes: true
});
analystParameter = new SuperMap.REST.TransportationAnalystParameter({
resultSetting: resultSetting,
//weightFieldName: "SHAPE_LENGTH"
});
parameter = new SuperMap.REST.FindPathParameters({
isAnalyzeById: false,
nodes: nodeArray,
hasLeastEdgeCount: false,
parameter: analystParameter
});
if (nodeArray.length <= 1) {
alert("站点数目有误");
}
findPathService = new SuperMap.REST.FindPathService(url2, {
eventListeners: { "processCompleted": processCompleted }
});
findPathService.processAsync(parameter);
}else
{
alert("没有正常选点。");
}
}
function processCompleted(findPathEventArgs) {
var result = findPathEventArgs.result;
allScheme(result);
}
function allScheme(result) {
if (pathListIndex < result.pathList.length) {
addPath(result);
} else {
pathListIndex = 0;
//线绘制完成后会绘制关于路径指引点的信息
addPathGuideItems(result);
}
}
var pathFeature = new SuperMap.Web.Core.Feature3D();
var pointsttt = null;
//以动画效果显示分析结果
function addPath(result) {
pan();
if(pointsttt == null)
{
pointsttt = new SuperMap.Web.Core.Point3Ds();
}
//style3d.set_bottomAltitude(2000);
if (routeCompsIndex < result.pathList[pathListIndex].route.components.length) {
for (var k = 0; k < 2; k++) {
if (result.pathList[pathListIndex].route.components[routeCompsIndex + k]) {
//points.push(new SuperMap.Geometry.Point(result.pathList[pathListIndex].route.components[routeCompsIndex + k].x, result.pathList[pathListIndex].route.components[routeCompsIndex + k].y));
var point = new SuperMap.Web.Core.Point3D();
point.x=result.pathList[pathListIndex].route.components[routeCompsIndex + k].x;
point.y=result.pathList[pathListIndex].route.components[routeCompsIndex + k].y;
point.z=120;
pointsttt.add(point);
}
}
//每隔0.001毫秒加载一条弧段
pathTime = setTimeout(function () { addPath(result); }, 0.001);
routeCompsIndex++;
} else {
clearTimeout(pathTime);
var colorLine = new SuperMap.Web.Core.Color(255,0,0,255);
var style3d = new SuperMap.Web.Core.Style3D();
style3d.set_lineColor(colorLine);
style3d.set_lineWidth(20);
style3d.set_altitudeMode(2);
var geoLinettt = new SuperMap.Web.Core.GeoLine3D();
geoLinettt.addPart(pointsttt);
pathFeature.set_geometry(geoLinettt);
pathFeature.set_style3D(style3d);
trackingLayer.add(pathFeature, routeCompsIndex);
routeCompsIndex = 0;
pathListIndex++;
allScheme(result);
pointsttt = null;
}
}
//再查出来的结果中插入符号
function addPathGuideItems(result){
}
function xuanDian(){
nodeArray=[];
trackingLayer.removeAll(); //删除跟踪图层上的图像
//设置控件的当前操作为自定义操作
var xuanDian = new SuperMap.Web.UI.Action3Ds.xuanDian(sceneControl);
sceneControl.set_sceneAction(xuanDian);
}
//通过继承SceneAction的方式来扩展用户的Action,继承方式采用框架提供的格式
//扩展Action的构造函数
SuperMap.Web.UI.Action3Ds.xuanDian = function (sceneControl) {
SuperMap.Web.UI.Action3Ds.xuanDian.initializeBase(this);
this._name = "xuanDian";
this._sceneControl = sceneControl;
//对应的场景操作类型为漫游
this._type = SuperMap.Web.UI.Action3Ds.SceneActionType.PAN;
};
//扩展Action的属性和方法
SuperMap.Web.UI.Action3Ds.xuanDian.prototype = {
/*
* 析构方法
*/
dispose: function () {
this._sceneControl = null;
},
/*
* 鼠标单击方法
*/
onMouseDown: function (e) {
//通过事件对象查询到相关的信息
var x = e.get_clientX();
var y = e.get_clientY();
var point = new SuperMap.Pixel(x, y);
var point3d=sceneControl.pixelToGlobe(point,SuperMap.Web.Realspace.PixelToGlobeMode.TerrainAndModel);
var point = new SuperMap.Geometry.Point(point3d.x,point3d.y);
nodeArray.push(point);
DrawPicForz(point3d.x,point3d.y,point3d.z,"fx");
}
};
SuperMap.Web.UI.Action3Ds.xuanDian.registerClass(‘SuperMap.Web.UI.Action3Ds.xuanDian‘, SuperMap.Web.UI.Action3Ds.SceneAction, Sys.IDisposable);
//z在三维场景中添加一个符号
function DrawPicForz(x, y,z,type){
var geometry = new SuperMap.Web.Core.GeoPoint3D(
new SuperMap.Web.Core.Point3D(x, y,z));//原来的高度是180
var feature3D = new SuperMap.Web.Core.Feature3D();
//设置feature3D中的style3D属性
var style = new SuperMap.Web.Core.Style3D();
var pictureurl = null;
var geoPlacemark = new SuperMap.Web.Core.GeoPlacemark();
if(type == "fx"){
pictureurl = path + "/SWimg/water1.png";
}
//style.set_altitudeMode("CLAMP_TO_GROUND");
style.set_altitudeMode(SuperMap.Web.Realspace.AltitudeMode.ABSOLUTE);
style.set_markerFile(pictureurl);
var instanceVar = new SuperMap.Web.Core.TextStyle3D();
instanceVar.set_backColor(new SuperMap.Web.Core.Color(255, 0, 0, 255));
instanceVar.set_fontScale(3);
feature3D.set_textStyle3D(instanceVar);
//创建Geoplacemark
geoPlacemark.set_geometry(geometry);
feature3D.set_geometry(geoPlacemark);
feature3D.set_style3D(style);
var trackingLayer = scene.get_trackingLayer3D();
//跟踪图层设置为可见
trackingLayer.set_isVisible(true);
trackingLayer.add(feature3D, "daohang");
}
以上是关于SuperMap for JavaScript 中的最佳路径分析功能转换为三维中的最佳路径分析功能的主要内容,如果未能解决你的问题,请参考以下文章
Arcgis for Javascript 对接iServer发布的Mapserver服务
无插件猴赛雷!SuperMap iClient3D for WebGL的4大“网红 ”潜质
SuperMap iClient3D for WebGL教程(地形篇)-CesiumTerrainProvider
SuperMap for WebGL 9D 加载平面坐标系三维场景