private void GroupMarkers() { List <MarkerGroup> groups = new List <MarkerGroup>(); for (int zoom = OnlineMaps.MAXZOOM; zoom >= 3; zoom--) { List <OnlineMapsMarker> ms = markers.Select(m => m).ToList(); for (int j = 0; j < ms.Count - 1; j++) { OnlineMapsMarker marker = ms[j]; MarkerGroup group = null; double px, py; marker.GetPosition(out px, out py); OnlineMaps.instance.projection.CoordinatesToTile(px, py, zoom, out px, out py); int k = j + 1; while (k < ms.Count) { OnlineMapsMarker marker2 = ms[k]; double p2x, p2y; marker2.GetPosition(out p2x, out p2y); OnlineMaps.instance.projection.CoordinatesToTile(p2x, p2y, zoom, out p2x, out p2y); if (OnlineMapsUtils.Magnitude(px, py, p2x, p2y) < distance) { if (group == null) { group = new MarkerGroup(zoom, groupTexture); groups.Add(group); group.Add(marker); if (marker.range.min == 3) { marker.range.min = zoom + 1; } } group.Add(marker2); if (marker2.range.min == 3) { marker2.range.min = zoom + 1; } ms.RemoveAt(k); px = group.tilePositionX; py = group.tilePositionY; } else { k++; } } } } foreach (MarkerGroup g in groups) { g.Apply(font); } }
public void AimToCurrentLocat() { // from current map position fromPosition = OnlineMaps.instance.position; // to GPS position; toPosition = OnlineMapsLocationService.instance.position; // calculates tile positions moveZoom = OnlineMaps.instance.zoom; OnlineMaps.instance.projection.CoordinatesToTile(fromPosition.x, fromPosition.y, moveZoom, out fromTileX, out fromTileY); OnlineMaps.instance.projection.CoordinatesToTile(toPosition.x, toPosition.y, moveZoom, out toTileX, out toTileY); // if tile offset < 4, then start smooth movement if (OnlineMapsUtils.Magnitude(fromTileX, fromTileY, toTileX, toTileY) < 4) { // set relative position 0 angle = 0; // start movement isMovement = true; } else // too far { OnlineMaps.instance.SetPositionAndZoom(toPosition.x, toPosition.y, 18); } }
private void OnGUI() { // On click button, starts movement if (GUI.Button(new Rect(5, 5, 100, 30), "Goto marker")) { // from current map position fromPosition = OnlineMaps.instance.position; // to GPS position; toPosition = OnlineMapsLocationService.instance.position; // calculates tile positions moveZoom = OnlineMaps.instance.zoom; OnlineMaps.instance.projection.CoordinatesToTile(fromPosition.x, fromPosition.y, moveZoom, out fromTileX, out fromTileY); OnlineMaps.instance.projection.CoordinatesToTile(toPosition.x, toPosition.y, moveZoom, out toTileX, out toTileY); // if tile offset < 4, then start smooth movement if (OnlineMapsUtils.Magnitude(fromTileX, fromTileY, toTileX, toTileY) < 4) { // set relative position 0 angle = 0; // start movement isMovement = true; } else // too far { OnlineMaps.instance.position = toPosition; } } }
public void hustFindMeGPS() { fromPosition = OnlineMaps.instance.position; // to GPS position; toPosition = OnlineMapsLocationService.instance.position; //*** must do********************************************************* //add 0,0 check if equals to zero return function... //*** must do********************************************************* // calculates tile positions double fromTileX, fromTileY, toTileX, toTileY; OnlineMaps.instance.projection.CoordinatesToTile(fromPosition.x, fromPosition.y, OnlineMaps.instance.zoom, out fromTileX, out fromTileY); OnlineMaps.instance.projection.CoordinatesToTile(toPosition.x, toPosition.y, OnlineMaps.instance.zoom, out toTileX, out toTileY); // if tile offset < 4, then start smooth movement if (OnlineMapsUtils.Magnitude(fromTileX, fromTileY, toTileX, toTileY) < 4) { // set relative position 0 angle = 0; // start movement if (toPosition.x != 0 || toPosition.y != 0) { isMovement = true; } } else // too far { if (toPosition.x == 0 && toPosition.y == 0) { return; } OnlineMaps.instance.position = toPosition; OnlineMaps.instance.zoom = 17; } }
private void UpdateBuildingsPosition() { OnlineMapsTileSetControl control = OnlineMapsTileSetControl.instance; Bounds bounds = new Bounds(); double tlx, tly, brx, bry; api.GetTopLeftPosition(out tlx, out tly); api.GetBottomRightPosition(out brx, out bry); bounds.min = new Vector3((float)tlx, (float)bry); bounds.max = new Vector3((float)brx, (float)tly); List <string> unusedKeys = new List <string>(); bool useElevation = control.useElevation; foreach (KeyValuePair <string, OnlineMapsBuildingBase> building in buildings) { if (!bounds.Intersects(building.Value.boundsCoords)) { unusedKeys.Add(building.Key); } else { if (useElevation) { Vector3 newPosition = control.GetWorldPositionWithElevation(building.Value.centerCoordinates.x, building.Value.centerCoordinates.y, tlx, tly, brx, bry); building.Value.transform.position = newPosition; } else { Vector3 newPosition = control.GetWorldPosition(building.Value.centerCoordinates.x, building.Value.centerCoordinates.y); building.Value.transform.position = newPosition; } } } List <string> usedKeys = new List <string>(); List <string> destroyKeys = new List <string>(); double px, py; api.GetPosition(out px, out py); api.projection.CoordinatesToTile(px, py, api.zoom, out px, out py); float maxDistance = Mathf.Sqrt(Mathf.Pow(api.width / 2 / OnlineMapsUtils.tileSize, 2) + Mathf.Pow(api.height / 2 / OnlineMapsUtils.tileSize, 2)) * 2; foreach (KeyValuePair <string, OnlineMapsBuildingBase> building in unusedBuildings) { OnlineMapsBuildingBase value = building.Value; if (bounds.Intersects(value.boundsCoords)) { usedKeys.Add(building.Key); if (useElevation) { Vector3 newPosition = control.GetWorldPositionWithElevation(building.Value.centerCoordinates, tlx, tly, brx, bry); building.Value.transform.position = newPosition; } else { Vector3 newPosition = control.GetWorldPosition(building.Value.centerCoordinates.x, building.Value.centerCoordinates.y); building.Value.transform.position = newPosition; } } else { double bx, by; api.projection.CoordinatesToTile(value.centerCoordinates.x, value.centerCoordinates.y, api.zoom, out bx, out by); if (OnlineMapsUtils.Magnitude(0, 0, bx - px, by - py) > maxDistance) { destroyKeys.Add(building.Key); } } } foreach (string key in unusedKeys) { OnlineMapsBuildingBase value = buildings[key]; value.gameObject.SetActive(false); unusedBuildings.Add(key, value); buildings.Remove(key); } foreach (string key in usedKeys) { OnlineMapsBuildingBase value = unusedBuildings[key]; if (maxActiveBuildings > 0 && buildings.Count >= maxActiveBuildings) { break; } if (OnShowBuilding != null && !OnShowBuilding(value)) { continue; } value.gameObject.SetActive(true); buildings.Add(key, value); unusedBuildings.Remove(key); } foreach (string key in destroyKeys) { OnlineMapsBuildingBase value = unusedBuildings[key]; if (OnBuildingDispose != null) { OnBuildingDispose(value); } OnlineMapsUtils.DestroyImmediate(value.gameObject); unusedBuildings.Remove(key); } if (destroyKeys.Count > 0) { OnlineMaps.instance.needGC = true; } }