Topic: Using OpenSeaMap in Online Maps
Hello everyone,
is it possible to use the maps from OpenSeaMap, has anyone had experience with this?
Thanks in advance.
Dear greetings
You are not logged in. Please login or register.
Infinity Code Forum → Online Maps Help → Using OpenSeaMap in Online Maps
Hello everyone,
is it possible to use the maps from OpenSeaMap, has anyone had experience with this?
Thanks in advance.
Dear greetings
Hi.
Yes, you can use the OpenSeaMap.
Thank you for the quick reply,
i use OnlineMaps in Unity3D, but i don't know exactly how to set the provider to use OpenSeaMap maps. Can you give me an example?
Source: online
Provider: custom(?)
Custom provider url: http://map.openseamap.org/ (?)
Kind regards
Example:
using System;
using UnityEngine;
namespace InfinityCode.OnlineMapsSupport
{
public class OpenSeaMapLayer : MonoBehaviour
{
// Overlay transparency
[Range(0, 1)]
public float alpha = 1;
private float _alpha = 1;
private void LoadTileOverlay(OnlineMapsTile tile)
{
var url = "https://tiles.openseamap.org/seamark/" + tile.zoom + "/" + tile.x + "/" + tile.y + ".png";
OnlineMapsWWW www = new OnlineMapsWWW(url);
www.OnComplete += OnDownloadComplete;
www.customFields["tile"] = tile;
}
private void OnDownloadComplete(OnlineMapsWWW www)
{
OnlineMapsTile tile = www.customFields["tile"] as OnlineMapsTile;
if (tile == null || tile.status == OnlineMapsTileStatus.disposed || tile.status == OnlineMapsTileStatus.error) return;
Texture2D texture = new Texture2D(256, 256);
www.LoadImageIntoTexture(texture);
tile.overlayBackTexture = texture;
}
private void OnStartDownloadTile(OnlineMapsTile tile)
{
tile.status = OnlineMapsTileStatus.loading;
// Load overlay for tile.
LoadTileOverlay(tile);
// Load the tile using a standard loader.
OnlineMapsTileManager.StartDownloadTile(tile);
}
private void Start()
{
if (OnlineMapsCache.instance != null)
{
// Subscribe to the cache events.
OnlineMapsCache.instance.OnLoadedFromCache += LoadTileOverlay;
}
OnlineMapsTileManager.OnStartDownloadTile += OnStartDownloadTile;
}
private void Update()
{
// Update the transparency of overlay.
if (Math.Abs(_alpha - alpha) > float.Epsilon)
{
_alpha = alpha;
lock (OnlineMapsTile.lockTiles)
{
foreach (OnlineMapsTile tile in OnlineMaps.instance.tileManager.tiles) tile.overlayBackAlpha = alpha;
}
}
}
}
}
It works, thank you very much!
Infinity Code Forum → Online Maps Help → Using OpenSeaMap in Online Maps
Powered by PunBB, supported by Informer Technologies, Inc.