SpawnOnMap provides an outline of placing custom markers. It uses the Start() function to calculate initial marker positions, then uses Update() to update those positions every time the map changes (either from zooming or panning).
SpawnOnMap 提供了放置自定义标记的概要。 它使用 Start() 函数计算初始标记位置,然后使用 Update() 在地图每次发生变化(缩放或平移)时更新这些位置。
..
.
void Start()
{
_locations = new Vector2d[_locationStrings.Length];
_spawnedObjects = new List<GameObject>();
for (int i = 0; i < _locationStrings.Length; i++)
{
var locationString = _locationStrings[i];
_locations[i] = Conversions.StringToLatLon(locationString);
var instance = Instantiate(_markerPrefab);
instance.transform.localPosition = _map.GeoToWorldPosition(_locations[i], true);
+ instance.transform.localScale = new Vector3(_spawnScale, _spawnScale, _spawnScale);
_spawnedObjects.Add(instance);
}
}
private void Update()
{
int count = _spawnedObjects.Count;
for (int i = 0; i < count; i++)
{
var spawnedObject = _spawnedObjects[i];
var location = _locations[i];
spawnedObject.transform.localPosition = _map.GeoToWorldPosition(location, true);
}
}
Use the SpawnOnMap script(使用 SpawnOnMap 脚本)
To use the SpawnOnMap script, add it as a Component to a Map GameObject. Below is a description of the variables.
要使用 SpawnOnMap 脚本,请将其作为组件添加到地图游戏对象。 下面是变量的描述。
Variables | Description |
---|---|
Map | Map object on which to place custom markers. (放置自定义标记的地图对象) |
Location Strings (位置字符串) | List of locations in (纬度、经度格式的位置列表) |
Spawn Scale (产卵规模) | Scale of spawned markers. Applied as uniform scale in all directions. (生成标记的比例。 在所有方向上应用统一比例。) |
Custom Prefab (定制预制件) | Prefab that will be spawned on the map as the marker. (将作为标记生成在地图上的预制件。) |