/// <summary> /// get obj range points /// </summary> public bool GetCenterPosition(object o, out PointLatLng center) { center = new PointLatLng(); if (LinkArray.Contains(o)) { int index = LinkArray.IndexOf(o); double interval = route.Distance / (LinkArray.Count * 2); double distance = interval * (2 * index + 1) - 0.0001; List <PointLatLng> list = new List <PointLatLng>(); list.Add(PointsArray[0]); int i = 1; for (; i < PointsArray.Count; i++) { list.Add(PointsArray[i]); GMapRoute route2 = new GMapRoute(list, "end"); if (route2.Distance < distance) { continue; } double rate; if (i == 1) { rate = distance / route2.Distance; } else { list.RemoveAt(list.Count - 1); GMapRoute route1 = new GMapRoute(list, "start"); rate = (distance - route1.Distance) / (route2.Distance - route1.Distance); } center.Lat = PointsArray[i - 1].Lat + (PointsArray[i].Lat - PointsArray[i - 1].Lat) * rate; center.Lng = PointsArray[i - 1].Lng + (PointsArray[i].Lng - PointsArray[i - 1].Lng) * rate; return(true); } } return(false); }
/// <summary> /// get obj range points /// </summary> public void GetPositions(object o, ref List <PointLatLng> listPoint) { if (LinkArray.Contains(o)) { int index = LinkArray.IndexOf(o); double interval = route.Distance / LinkArray.Count; double distance = interval * (index) - 0.0001; List <PointLatLng> listGo = new List <PointLatLng>(); listGo.Add(PointsArray[0]); for (int i = 1; i < PointsArray.Count; i++) { listGo.Add(PointsArray[i]); GMapRoute routeGo = new GMapRoute(listGo, "go"); if (routeGo.Distance < distance || routeGo.Distance < 0.000000001) { listGo.RemoveAt(0); distance -= routeGo.Distance; } else { double rate = distance / routeGo.Distance; double latOffset = (listGo[1].Lat - listGo[0].Lat) * rate; double lngOffset = (listGo[1].Lng - listGo[0].Lng) * rate; PointLatLng from = new PointLatLng(); from.Lat = listGo[0].Lat + latOffset; from.Lng = listGo[0].Lng + lngOffset; List <PointLatLng> listBack = new List <PointLatLng>(); listBack.Add(from); listPoint.Add(from); int j = i - 1; for (; j >= 0; j--) { listBack.Add(PointsArray[j]); GMapRoute routeBack = new GMapRoute(listBack, "back"); if (routeBack.Distance < interval) { listPoint.Add(PointsArray[j]); if (j == 0) { break; } listBack.RemoveAt(0); interval -= routeBack.Distance; } else { rate = interval / routeBack.Distance; latOffset = (listBack[1].Lat - listBack[0].Lat) * rate; lngOffset = (listBack[1].Lng - listBack[0].Lng) * rate; PointLatLng to = new PointLatLng(); to.Lat = listBack[0].Lat + latOffset; to.Lng = listBack[0].Lng + lngOffset; listPoint.Add(to); break; } } break; /* * List<PointLatLng> listTmp = new List<PointLatLng>(listPoint); * while (j >= 0) * { * listTmp.Add(PointsArray[j]); * j--; * } * GMapRoute routeReal = new GMapRoute(listTmp, "real"); * return (double.Parse(routeReal.Distance.ToString("0.0000")) * 1000).ToString() + "米"; */ } } } }
/// <summary> /// get ojbects route /// </summary> private void GetObjectsRoute(object oBegin, object oEnd, ref List <PointLatLng> listPoint) { if (LinkArray.Contains(oBegin) && LinkArray.Contains(oEnd) && listPoint != null) { int begin = LinkArray.IndexOf(oBegin); int end = LinkArray.IndexOf(oEnd); double interval = route.Distance / LinkArray.Count; double distanceB = interval * (begin) - 0.0001; double distanceE = interval * (end) - 0.0001; List <PointLatLng> listGo = new List <PointLatLng>(); listGo.Add(PointsArray[0]); for (int i = 1; i < PointsArray.Count; i++) { listGo.Add(PointsArray[i]); GMapRoute routeGo = new GMapRoute(listGo, "go"); if (routeGo.Distance < distanceB) { listGo.RemoveAt(0); distanceB -= routeGo.Distance; } else { double rate = distanceB / routeGo.Distance; double latOffset = (listGo[1].Lat - listGo[0].Lat) * rate; double lngOffset = (listGo[1].Lng - listGo[0].Lng) * rate; PointLatLng from = new PointLatLng(); from.Lat = listGo[0].Lat + latOffset; from.Lng = listGo[0].Lng + lngOffset; listPoint.Add(from); List <PointLatLng> listBack = new List <PointLatLng>(); listBack.Add(from); int j = i; for (; j < PointsArray.Count; j++) { listBack.Add(PointsArray[j]); GMapRoute routeBack = new GMapRoute(listBack, "back"); if (routeBack.Distance < distanceE) { listPoint.Add(PointsArray[j]); if (j == 0) { break; } listBack.RemoveAt(0); distanceE -= routeBack.Distance; } else { rate = interval / routeBack.Distance; latOffset = (listBack[1].Lat - listBack[0].Lat) * rate; lngOffset = (listBack[1].Lng - listBack[0].Lng) * rate; PointLatLng to = new PointLatLng(); to.Lat = listBack[0].Lat + latOffset; to.Lng = listBack[0].Lng + lngOffset; listPoint.Add(to); break; } } break; } } } }