/// <summary> /// Updates the map. /// Use this method to update the location of the map. /// Update method should be used when panning, zooming or changing location of the map. /// This method avoid startup delays that might occur on re-initializing the map. /// </summary> /// <param name="latLon">LatitudeLongitude.</param> /// <param name="zoom">Zoom level.</param> public virtual void UpdateMap(Vector2d latLon, float zoom) { if (Application.isEditor && !Application.isPlaying && !IsEditorPreviewEnabled) { return; } StartCoroutine(CalculateDistance.Instance.FindAllBinsInMap(2)); //so map will be snapped to zero using next new tile loaded _worldHeightFixed = false; float differenceInZoom = 0.0f; bool isAtInitialZoom = false; // Update map zoom, if it has changed. if (Math.Abs(Zoom - zoom) > Constants.EpsilonFloatingPoint) { SetZoom(zoom); } // Compute difference in zoom. Will be used to calculate correct scale of the map. differenceInZoom = Zoom - InitialZoom; isAtInitialZoom = (differenceInZoom - 0.0 < Constants.EpsilonFloatingPoint); //Update center latitude longitude var centerLatitudeLongitude = latLon; double xDelta = centerLatitudeLongitude.x; double zDelta = centerLatitudeLongitude.y; xDelta = xDelta > 0 ? Mathd.Min(xDelta, Mapbox.Utils.Constants.LatitudeMax) : Mathd.Max(xDelta, -Mapbox.Utils.Constants.LatitudeMax); zDelta = zDelta > 0 ? Mathd.Min(zDelta, Mapbox.Utils.Constants.LongitudeMax) : Mathd.Max(zDelta, -Mapbox.Utils.Constants.LongitudeMax); //Set Center in Latitude Longitude and Mercator. SetCenterLatitudeLongitude(new Vector2d(xDelta, zDelta)); Options.scalingOptions.scalingStrategy.SetUpScaling(this); Options.placementOptions.placementStrategy.SetUpPlacement(this); //Scale the map accordingly. if (Math.Abs(differenceInZoom) > Constants.EpsilonFloatingPoint || isAtInitialZoom) { _mapScaleFactor = Vector3.one * Mathf.Pow(2, differenceInZoom); Root.localScale = _mapScaleFactor; } //Update Tile extent. if (TileProvider != null) { TileProvider.UpdateTileExtent(); } if (OnUpdated != null) { OnUpdated(); } }
private void OnTileProviderChanged() { if (Application.isEditor && !Application.isPlaying && IsEditorPreviewEnabled == false) { Debug.Log("extentOptions"); return; } SetTileProvider(); TileProvider.Initialize(this); if (IsEditorPreviewEnabled) { TileProvider.UpdateTileExtent(); } }
/// <summary> /// Initializes the map using the mapOptions. /// </summary> /// <param name="options">Options.</param> protected virtual void InitializeMap(MapOptions options) { Options = options; _worldHeightFixed = false; _fileSource = MapboxAccess.Instance; _centerLatitudeLongitude = Conversions.StringToLatLon(options.locationOptions.latitudeLongitude); _initialZoom = (int)options.locationOptions.zoom; options.scalingOptions.scalingStrategy.SetUpScaling(this); options.placementOptions.placementStrategy.SetUpPlacement(this); //Set up events for changes. _imagery.UpdateLayer += OnImageOrTerrainUpdateLayer; _terrain.UpdateLayer += OnImageOrTerrainUpdateLayer; _vectorData.SubLayerRemoved += OnVectorDataSubLayerRemoved; _vectorData.SubLayerAdded += OnVectorDataSubLayerAdded; _vectorData.UpdateLayer += OnVectorDataUpdateLayer; _options.locationOptions.PropertyHasChanged += (object sender, System.EventArgs eventArgs) => { UpdateMap(); }; _options.extentOptions.PropertyHasChanged += (object sender, System.EventArgs eventArgs) => { OnTileProviderChanged(); }; _options.extentOptions.defaultExtents.PropertyHasChanged += (object sender, System.EventArgs eventArgs) => { if (Application.isEditor && !Application.isPlaying && IsEditorPreviewEnabled == false) { Debug.Log("defaultExtents"); return; } if (TileProvider != null) { TileProvider.UpdateTileExtent(); } }; _options.placementOptions.PropertyHasChanged += (object sender, System.EventArgs eventArgs) => { SetPlacementStrategy(); UpdateMap(); }; _options.scalingOptions.PropertyHasChanged += (object sender, System.EventArgs eventArgs) => { SetScalingStrategy(); UpdateMap(); }; _mapVisualizer.Initialize(this, _fileSource); TileProvider.Initialize(this); SendInitialized(); TileProvider.UpdateTileExtent(); }