/// <summary> /// Changes the zoom keeping a specified point on same place. /// </summary> /// <param name="zoomOffset">Positive - zoom in, Negative - zoom out</param> /// <param name="screenPosition">Screen position</param> /// <returns>True - if zoom changed, False - if zoom not changed</returns> public bool ZoomOnPoint(float zoomOffset, Vector2 screenPosition) { float newZoom = Mathf.Clamp(map.floatZoom + zoomOffset, 3, OnlineMaps.MAXZOOM); if (Math.Abs(newZoom - map.floatZoom) < float.Epsilon) { return(false); } double mx, my; bool hit = GetCoords(screenPosition, out mx, out my); if (!hit) { return(false); } map.dispatchEvents = false; int zoom = map.zoom; double tx, ty, tmx1, tmy1, tmx2, tmy2; map.GetTilePosition(out tx, out ty); map.projection.CoordinatesToTile(mx, my, zoom, out tmx1, out tmy1); double ox = tx - tmx1; double oy = ty - tmy1; map.floatZoom = newZoom; GetCoords(screenPosition, out mx, out my); map.projection.CoordinatesToTile(mx, my, zoom, out tmx2, out tmy2); double ox2 = tx - tmx2; double oy2 = ty - tmy2; tx -= ox - ox2; ty -= oy - oy2; map.projection.TileToCoordinates(tx, ty, zoom, out tx, out ty); map.SetPosition(tx, ty); map.dispatchEvents = true; map.DispatchEvent(OnlineMapsEvents.changedPosition, OnlineMapsEvents.changedZoom); if (OnMapZoom != null) { OnMapZoom(); } return(true); }
/// <summary> /// Changes the zoom keeping a specified point on same place. /// </summary> /// <param name="zoomOffset">Positive - zoom in, Negative - zoom out</param> /// <param name="screenPosition">Screen position</param> /// <returns>True - if zoom changed, False - if zoom not changed</returns> public bool ZoomOnPoint(int zoomOffset, Vector2 screenPosition) { int newZoom = Mathf.Clamp(map.zoom + zoomOffset, 3, OnlineMaps.MAXZOOM); if (newZoom == map.zoom) { return(false); } double mx, my; bool hit = GetCoords(out mx, out my, screenPosition); if (!hit) { return(false); } double ox, oy; map.GetPosition(out ox, out oy); map.dispatchEvents = false; map.zoom = newZoom; map.SetPosition(mx, my); double px, py; map.GetPosition(out px, out py); if (GetCoords(out mx, out my, screenPosition)) { px += px - mx; py += py - my; map.SetPosition(px, py); } else { map.SetPosition(ox, oy); } map.dispatchEvents = true; map.DispatchEvent(OnlineMapsEvents.changedPosition, OnlineMapsEvents.changedZoom); if (OnMapZoom != null) { OnMapZoom(); } return(true); }