private void StartBuffer() { if (!allowRedraw || !needRedraw) return; if (buffer.status != OnlineMapsBufferStatus.wait) return; if (latitude < -90) latitude = -90; else if (latitude > 90) latitude = 90; while (longitude < -180 || longitude > 180) { if (longitude < -180) longitude += 360; else if (longitude > 180) longitude -= 360; } buffer.redrawType = redrawType; buffer.generateSmartBuffer = isUserControl; buffer.status = OnlineMapsBufferStatus.start; #if !UNITY_WEBGL if (renderInThread) { if (renderThread == null) { renderThread = new Thread(buffer.GenerateFrontBuffer); renderThread.Start(); } } else buffer.GenerateFrontBuffer(); #else buffer.GenerateFrontBuffer(); #endif redrawType = OnlineMapsRedrawType.none; needRedraw = false; }
/// <summary> /// Sets the desired type of redrawing the map. /// </summary> public void CheckRedrawType() { if (allowRedraw) { redrawType = OnlineMapsRedrawType.full; needRedraw = true; } }
// ReSharper disable once UnusedMember.Local private void Start() { if (redrawOnPlay) { allowRedraw = true; redrawType = OnlineMapsRedrawType.full; } needRedraw = true; _zoom = CheckMapSize(_zoom); }
/// <summary> /// Sets the texture, which will draw the map. /// Texture displaying on the source you need to change yourself. /// </summary> /// <param name="newTexture">Texture, where you want to draw the map.</param> public void SetTexture(Texture2D newTexture) { texture = newTexture; width = newTexture.width; height = newTexture.height; allowRedraw = true; needRedraw = true; redrawType = OnlineMapsRedrawType.full; }
/// <summary> /// Set the the map coordinate. /// </summary> /// <param name="lng">Longitude</param> /// <param name="lat">Latitude</param> public void SetPosition(double lng, double lat) { int countX = width / OnlineMapsUtils.tileSize; int countY = height / OnlineMapsUtils.tileSize; if (positionRange != null) { if (positionRange.type == OnlineMapsPositionRangeType.center) { positionRange.CheckAndFix(ref lng, ref lat); } else if (positionRange.type == OnlineMapsPositionRangeType.border) { double px, py; OnlineMapsUtils.LatLongToTiled(lng, lat, _zoom, out px, out py); Vector2 offset = new Vector2(countX / 2f, countY / 2f); double tlx, tly, brx, bry; OnlineMapsUtils.TileToLatLong(px - offset.x, py - offset.y, _zoom, out tlx, out tly); OnlineMapsUtils.TileToLatLong(px + offset.x, py + offset.y, _zoom, out brx, out bry); double ltlx = tlx; double lbrx = brx; bool tlc = positionRange.CheckAndFix(ref tly, ref tlx); bool brc = positionRange.CheckAndFix(ref bry, ref brx); if (tlc && brc) { if (ltlx == tlx || lbrx == brx) { double tx, ty; OnlineMapsUtils.LatLongToTiled(tlx, tly, _zoom, out tx, out ty); OnlineMapsUtils.TileToLatLong(tx + offset.x, ty + offset.y, _zoom, out lng, out lat); } else { lng = positionRange.center.x; lat = positionRange.center.y; } } else if (tlc) { double tx, ty; OnlineMapsUtils.LatLongToTiled(tlx, tly, _zoom, out tx, out ty); OnlineMapsUtils.TileToLatLong(tx + offset.x, ty + offset.y, _zoom, out lng, out lat); } else if (brc) { double tx, ty; OnlineMapsUtils.LatLongToTiled(brx, bry, _zoom, out tx, out ty); OnlineMapsUtils.TileToLatLong(tx - offset.x, ty - offset.y, _zoom, out lng, out lat); } } } double tpx, tpy; OnlineMapsUtils.LatLongToTiled(lng, lat, _zoom, out tpx, out tpy); float haftCountY = countY / 2f; int maxY = (2 << zoom) / 2; bool modified = false; if (tpy - haftCountY < 0) { tpy = haftCountY; modified = true; } else if (tpy + haftCountY >= maxY - 1) { tpy = maxY - haftCountY - 1; modified = true; } if (modified) OnlineMapsUtils.TileToLatLong(tpx, tpy, _zoom, out lng, out lat); if (latitude == lat && longitude == lng) return; allowRedraw = true; needRedraw = true; if (redrawType == OnlineMapsRedrawType.none || redrawType == OnlineMapsRedrawType.move) redrawType = OnlineMapsRedrawType.move; else redrawType = OnlineMapsRedrawType.full; latitude = lat; longitude = lng; UpdateTopLeftPosition(); UpdateBottonRightPosition(); DispatchEvent(OnlineMapsEvents.changedPosition); }
/// <summary> /// Full redraw map. /// </summary> public void Redraw() { needRedraw = true; allowRedraw = true; redrawType = OnlineMapsRedrawType.full; buffer.updateBackBuffer = true; }
// ReSharper disable once UnusedMember.Local private void LateUpdate() { if (control == null) return; if (buffer.status == OnlineMapsBufferStatus.complete) { if (allowRedraw) { if (target == OnlineMapsTarget.texture) { if (!useSmartTexture || !buffer.generateSmartBuffer) { texture.SetPixels(buffer.frontBuffer); texture.Apply(false); if (control.activeTexture != texture) control.SetTexture(texture); } else { smartTexture.SetPixels(buffer.smartBuffer); smartTexture.Apply(false); if (control.activeTexture != smartTexture) control.SetTexture(smartTexture); if (!isUserControl) needRedraw = true; } } else { ((OnlineMapsTileSetControl)control).UpdateTileset(); } } buffer.status = OnlineMapsBufferStatus.wait; } if (allowRedraw && needRedraw) { if (buffer.status == OnlineMapsBufferStatus.wait) { position = position.FixAngle(); buffer.redrawType = redrawType; buffer.generateSmartBuffer = isUserControl; buffer.status = OnlineMapsBufferStatus.start; if (renderThread == null) { renderThread = new Thread(buffer.GenerateFrontBuffer); renderThread.Start(); } redrawType = OnlineMapsRedrawType.none; needRedraw = false; } } }