private static bool MoveRelationMemberToWay(List <string> nodeRefs, List <OnlineMapsOSMRelationMember> members, Dictionary <string, OnlineMapsOSMWay> ways) { string lastRef = nodeRefs[nodeRefs.Count - 1]; int memberIndex = -1; for (int i = 0; i < members.Count; i++) { OnlineMapsOSMRelationMember member = members[i]; OnlineMapsOSMWay w = ways[member.reference]; if (w.nodeRefs[0] == lastRef) { nodeRefs.AddRange(w.nodeRefs.Skip(1)); memberIndex = i; break; } if (w.nodeRefs[w.nodeRefs.Count - 1] == lastRef) { List <string> refs = w.nodeRefs; refs.Reverse(); nodeRefs.AddRange(refs.Skip(1)); memberIndex = i; break; } } if (memberIndex != -1) { members.RemoveAt(memberIndex); } else { return(false); } return(true); }
private void OnBuildingRequestComplete(string response) { osmRequest = null; Action action = () => { Dictionary <string, OnlineMapsOSMNode> nodes; List <OnlineMapsOSMWay> ways; List <OnlineMapsOSMRelation> relations; OnlineMapsOSMAPIQuery.ParseOSMResponseFast(response, out nodes, out ways, out relations); lock (newBuildingsData) { List <string> waysInRelation = new List <string>(); foreach (OnlineMapsOSMRelation relation in relations) { if (relation.members.Count == 0) { continue; } OnlineMapsOSMWay way = new OnlineMapsOSMWay(); List <string> nodeRefs = new List <string>(); List <OnlineMapsOSMRelationMember> members = relation.members.Where(m => m.type == "way" && m.role == "outer").ToList(); if (members.Count == 0) { continue; } OnlineMapsOSMWay relationWay = GetWayByID(ways, members[0].reference); if (relationWay == null) { continue; } nodeRefs.AddRange(relationWay.nodeRefs); members.RemoveAt(0); while (members.Count > 0) { string lastRef = nodeRefs[nodeRefs.Count - 1]; int memberIndex = -1; for (int i = 0; i < members.Count; i++) { OnlineMapsOSMRelationMember member = members[i]; OnlineMapsOSMWay w = GetWayByID(ways, member.reference); if (w.nodeRefs[0] == lastRef) { nodeRefs.AddRange(w.nodeRefs.Skip(1)); memberIndex = i; break; } if (w.nodeRefs[w.nodeRefs.Count - 1] == lastRef) { List <string> refs = w.nodeRefs; refs.Reverse(); nodeRefs.AddRange(refs.Skip(1)); memberIndex = i; break; } } if (memberIndex != -1) { members.RemoveAt(memberIndex); } else { break; } } waysInRelation.AddRange(relation.members.Select(m => m.reference)); way.nodeRefs = nodeRefs; way.id = relation.id; way.tags = relation.tags; newBuildingsData.Enqueue(new OnlineMapsBuildingsNodeData(way, nodes)); } ways.RemoveAll(delegate(OnlineMapsOSMWay w) { if (waysInRelation.Contains(w.id)) { w.Dispose(); return(true); } return(false); }); foreach (OnlineMapsOSMWay way in ways) { newBuildingsData.Enqueue(new OnlineMapsBuildingsNodeData(way, nodes)); } } sendBuildingsReceived = true; }; #if !UNITY_WEBGL if (map.renderInThread) { OnlineMapsThreadManager.AddThreadAction(action); } else { action(); } #else action(); #endif if (OnRequestComplete != null) { OnRequestComplete(); } }