路网与路径规划

路网与路径规划

设计:

  1. svg矢量图
  2. 路网
  3. 路径算法
  4. 路径规划

路网:


var mapData = {mapInfo: {color: "blue",lineWidth: "2",path: "M0,500L2000,500L2000,1500L0,1500Z",navPathPoints: [],nodes: [{ index: 0, value: "a", r: 20, x: "715", y: "1000" },{ index: 1, value: "a1", r: 20, x: "715", y: "845" },{ index: 2, value: "a2", r: 20, x: "715", y: "1155" },{ index: 3, value: "b", r: 20, x: "1015", y: "1000" },{ index: 4, value: "b1", r: 20, x: "1015", y: "845" },{ index: 5, value: "b2", r: 20, x: "1015", y: "1155" },{ index: 6, value: "c", r: 20, x: "1315", y: "1000" },{ index: 7, value: "c1", r: 20, x: "1315", y: "845" },{ index: 8, value: "c2", r: 20, x: "1315", y: "1155" },{ index: 9, value: "d", r: 20, x: "1650", y: "1155" }],paths: [{ source: 0, target: 1, distance: 155 },{ source: 0, target: 2, distance: 155 },{ source: 3, target: 4, distance: 155 },{ source: 3, target: 5, distance: 155 },{ source: 6, target: 7, distance: 155 },{ source: 6, target: 8, distance: 155 },{ source: 8, target: 9, distance: 345 },{ source: 1, target: 4, distance: 300 },{ source: 2, target: 5, distance: 300 },{ source: 4, target: 7, distance: 300 },{ source: 5, target: 8, distance: 300 },],}
}

// 找到起点终点附近的点位,链接点位,路径规划吸附在路网上
findNearPoint = function (point) {var self = this;var p1 = {x: point[0],y: point[1]}var tempValue = "";var nodeIndex = "";this.mapInfo.nodes.forEach(function (p, index) {var p2 = {x: parseFloat(p.x),y: parseFloat(p.y)}var len = dist(p1, p2);if (index == 0) {tempValue = len;nodeIndex = index;} else {if (tempValue > len) {tempValue = len;nodeIndex = index;}}});return this.mapInfo.nodes[nodeIndex];
};

在这里插入图片描述


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部