protected override void OnCreate(Android.OS.Bundle savedInstanceState) { base.OnCreate(savedInstanceState); AddOnlineBaseLayer(CartoBaseMapStyle.CartoBasemapStyleDefault); // Get decoder from current layer, // so we wouldn't need a style asset to create a decoder from scratch MBVectorTileDecoder decoder = (MBVectorTileDecoder)(MapView.Layers[0] as VectorTileLayer).TileDecoder; // Remove default baselayer MapView.Layers.Clear(); // Do the actual copying and source creation on another thread so it wouldn't block the main thread System.Threading.Tasks.Task.Run(delegate { TileDataSource source = CreateTileDataSource(); var layer = new VectorTileLayer(source, decoder); RunOnUiThread(delegate { // However, actual layer insertion should be done on the main thread MapView.Layers.Insert(0, layer); }); }); // Zoom to the correct location MapPos rome = BaseProjection.FromWgs84(new MapPos(12.4807, 41.8962)); MapView.SetFocusPos(rome, 0); MapView.SetZoom(13, 0); }
public override void Create(VectorTileLayer layer, UnityTile tile) { _container = new GameObject(Key + " Container"); _container.transform.SetParent(tile.transform, false); var fc = layer.FeatureCount(); var filterOut = false; for (int i = 0; i < fc; i++) { filterOut = false; var feature = new VectorFeatureUnity(layer.GetFeature(i, 0), tile); foreach (var filter in Filters) { if (!string.IsNullOrEmpty(filter.Key) && !feature.Properties.ContainsKey(filter.Key)) { continue; } if (!filter.Try(feature)) { filterOut = true; break; } } if (!filterOut) { Build(feature, tile, _container); } } }
public void Clipping(string fileName) { string fullFileName = Path.Combine(fixturesPath, fileName); Assert.True(File.Exists(fullFileName), "Vector tile exists"); byte[] data = File.ReadAllBytes(fullFileName); VectorTile vt = new VectorTile(data); foreach (var lyrName in vt.LayerNames()) { VectorTileLayer lyr = vt.GetLayer(lyrName); for (int i = 0; i < lyr.FeatureCount(); i++) { VectorTileFeature feat = lyr.GetFeature(i); //skip features with unknown geometry type if (feat.GeometryType == GeomType.UNKNOWN) { continue; } List <List <Point2d <long> > > geomRaw = feat.Geometry <long>(); List <List <Point2d <long> > > geomClipped = feat.Geometry <long>(0); for (int j = 0; j < geomRaw.Count; j++) { List <Point2d <long> > part = geomRaw[j]; List <Point2d <long> > partClipped = geomClipped[j]; // Workaround to compare parts as clipping may or may not change the order of vertices // This only works if no actual clipping is done Assert.False(part.Except(partClipped).Any(), $"{fileName}, feature[{i}], geometry part[{j}]: geometry parts don't match after clipping"); } } } }
protected override void OnCreate(Android.OS.Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Remove default baselayer MapView.Layers.Clear(); var decoder = CartoVectorTileLayer.CreateTileDecoder(CartoBaseMapStyle.CartoBasemapStyleVoyager); // Do the actual copying and source creation on another thread so it wouldn't block the main thread System.Threading.Tasks.Task.Run(delegate { TileDataSource source = FileUtils.CreateTileDataSource(this, "rome_carto-streets.mbtiles"); var layer = new VectorTileLayer(source, decoder); RunOnUiThread(delegate { // However, actual layer insertion should be done on the main thread MapView.Layers.Insert(0, layer); }); }); // Zoom to the correct location MapPos rome = BaseProjection.FromWgs84(new MapPos(12.4807, 41.8962)); MapView.SetFocusPos(rome, 0); MapView.SetZoom(13, 0); }
public MapContainer() { Map = new MapView(); var timer = new Stopwatch(); timer.Start(); // NOTE: Uncomment the timer creation and BeginInvokeOnMainThread to apply a workaround //var startTimer = new System.Threading.Timer((_) => //{ // Device.BeginInvokeOnMainThread(() => // { MBTilesTileDataSource testDataSource = new MBTilesTileDataSource(((App)App.Current).CityDataFile); CompiledStyleSet styleSet = new CompiledStyleSet(new ZippedAssetPackage(AssetUtils.LoadAsset("nutibright-v3.zip"))); MBVectorTileDecoder decoder = new MBVectorTileDecoder(styleSet); VectorTileLayer testLayer = new VectorTileLayer(testDataSource, decoder); Map.Layers.Add(testLayer); // }); //}, null, 10, System.Threading.Timeout.Infinite); timer.Stop(); Debug.WriteLine($"Done map initialization in {timer.ElapsedMilliseconds}ms"); MapPos pos = Map.Options.BaseProjection.FromWgs84(new MapPos(App.CITY_POS_X, App.CITY_POS_Y)); Map.SetFocusPos(pos, 0); Map.SetZoom(15, 0); Content = Map.ToView(); }
public override void ViewDidLoad() { base.ViewDidLoad(); // Add default base layer AddOnlineBaseLayer(CartoBaseMapStyle.CartoBasemapStyleVoyager); Projection projection = MapView.Options.BaseProjection; TileDataSource source = FileUtils.CreateTileDataSource("rome_carto-streets", "mbtiles"); // Get decoder from current layer, // so we wouldn't need a style asset to create a decoder from scratch MBVectorTileDecoder decoder = (MBVectorTileDecoder)(MapView.Layers[0] as VectorTileLayer).TileDecoder; // Remove default baselayer MapView.Layers.Clear(); // Add our new layer var layer = new VectorTileLayer(source, decoder); MapView.Layers.Insert(0, layer); // Zoom to the correct location MapPos rome = projection.FromWgs84(new MapPos(12.4807, 41.8962)); MapView.SetFocusPos(rome, 0); MapView.SetZoom(13, 0); }
public override IEnumerator ParseTileData(object m, Coordinates tilecenter, int zoom, GOLayer[] layers, bool delayedLoad, List <string> layerNames) { if (mapData == null) { Debug.LogWarning("Map Data is null!"); #if !UNITY_WEBPLAYER FileHandler.Remove(gameObject.name); #endif yield break; } var decompressed = Compression.Decompress((byte[])mapData); vt = new VectorTile(decompressed, false); foreach (GOLayer layer in layers) { string[] lyrs = GetLayersStrings(layer).Split(','); foreach (string l in lyrs) { VectorTileLayer lyr = vt.GetLayer(l); if (lyr != null) { yield return(StartCoroutine(BuildLayer(lyr, layer, delayedLoad))); } } } }
public void LazyDecoding(string fileName) { string fullFileName = Path.Combine(fixturesPath, fileName); Assert.True(File.Exists(fullFileName), "Vector tile exists"); byte[] data = File.ReadAllBytes(fullFileName); VectorTile vt = new VectorTile(data); foreach (var layerName in vt.LayerNames()) { VectorTileLayer layer = vt.GetLayer(layerName); for (int i = 0; i < layer.FeatureCount(); i++) { VectorTileFeature feat = layer.GetFeature(i); var properties = feat.GetProperties(); foreach (var prop in properties) { Assert.AreEqual(prop.Value, feat.GetValue(prop.Key), "Property values match"); } foreach (var geomPart in feat.Geometry <int>()) { foreach (var coord in geomPart) { //TODO add Assert } } } } string geojson = vt.ToGeoJson(0, 0, 0); Assert.GreaterOrEqual(geojson.Length, 30, "geojson >= 30 chars"); }
protected override void OnCreate(Android.OS.Bundle savedInstanceState) { base.OnCreate(savedInstanceState); AddBaseLayer(CartoBaseMapStyle.CartoBasemapStyleDefault); TileDataSource source = CreateTileDataSource(); // Get decoder from current layer, // so we wouldn't need a style asset to create a decoder from scratch MBVectorTileDecoder decoder = (MBVectorTileDecoder)(MapView.Layers[0] as VectorTileLayer).TileDecoder; // Remove default baselayer MapView.Layers.Clear(); // Add our new layer var layer = new VectorTileLayer(source, decoder); MapView.Layers.Insert(0, layer); // Zoom to the correct location MapPos rome = BaseProjection.FromWgs84(new MapPos(12.4807, 41.8962)); MapView.SetFocusPos(rome, 0); MapView.SetZoom(13, 0); }
public void AtLeastOneLayer(string fileName) { string fullFileName = Path.Combine(fixturesPath, fileName); Assert.True(File.Exists(fullFileName), "Vector tile exists"); byte[] data = File.ReadAllBytes(fullFileName); VectorTile vt = new VectorTile(data); Assert.GreaterOrEqual(vt.LayerNames().Count, 1, "At least one layer"); string geojson = vt.ToGeoJson(0, 0, 0); Assert.GreaterOrEqual(geojson.Length, 30, "geojson >= 30 chars"); foreach (var lyrName in vt.LayerNames()) { VectorTileLayer lyr = vt.GetLayer(lyrName); for (int i = 0; i < lyr.FeatureCount(); i++) { Debug.WriteLine("{0} lyr:{1} feat:{2}", fileName, lyr.Name, i); VectorTileFeature feat = lyr.GetFeature(i); long extent = (long)lyr.Extent; foreach (var part in feat.Geometry <long>()) { foreach (var geom in part) { if (geom.X < 0 || geom.Y < 0 || geom.X > extent || geom.Y > extent) { Debug.WriteLine("{0} lyr:{1} feat:{2} x:{3} y:{4}", fileName, lyr.Name, i, geom.X, geom.Y); } } } } } }
public void ClipHardAtTileBoundary(string fileName) { string fullFileName = Path.Combine(fixturesPath, fileName); Assert.True(File.Exists(fullFileName), "Vector tile exists"); byte[] data = File.ReadAllBytes(fullFileName); VectorTile vt = new VectorTile(data); Assert.GreaterOrEqual(vt.LayerNames().Count, 1, "At least one layer"); string geojson = vt.ToGeoJson(0, 0, 0); Assert.GreaterOrEqual(geojson.Length, 30, "geojson >= 30 chars"); foreach (var lyrName in vt.LayerNames()) { VectorTileLayer lyr = vt.GetLayer(lyrName); for (int i = 0; i < lyr.FeatureCount(); i++) { Debug.WriteLine("{0} lyr:{1} feat:{2}", fileName, lyr.Name, i); VectorTileFeature feat = lyr.GetFeature(i, 0); long extent = (long)lyr.Extent; foreach (var part in feat.Geometry <int>()) { foreach (var geom in part) { Assert.GreaterOrEqual(geom.X, 0, "geom.X equal or greater 0"); Assert.GreaterOrEqual(geom.Y, 0, "geom.Y eqaul or greater 0"); Assert.LessOrEqual(geom.X, extent, "geom.X less or equal extent"); Assert.LessOrEqual(geom.Y, extent, "geom.Y less or equal extent"); } } } } }
public void Scaling(string fileName) { float[] scales = new float[] { 1.5f, 2.25f, 5.75f, 197.3f }; string fullFileName = Path.Combine(fixturesPath, fileName); byte[] data = File.ReadAllBytes(fullFileName); VectorTile vt = new VectorTile(data); foreach (var lyrName in vt.LayerNames()) { VectorTileLayer lyr = vt.GetLayer(lyrName); int featCnt = lyr.FeatureCount(); for (int idxFeat = 0; idxFeat < featCnt; idxFeat++) { VectorTileFeature feat = lyr.GetFeature(idxFeat); List <List <Point2d <int> > > rawParts = feat.Geometry <int>(); for (int idxPart = 0; idxPart < rawParts.Count; idxPart++) { List <Point2d <int> > rawGeom = rawParts[idxPart]; foreach (var scale in scales) { List <List <Point2d <float> > > scaledParts = feat.Geometry <float>(null, scale); List <Point2d <float> > scaledGeom = scaledParts[idxPart]; for (int idxVertex = 0; idxVertex < rawGeom.Count; idxVertex++) { Point2d <int> rawVertex = rawGeom[idxVertex]; Point2d <float> scaledVertex = scaledGeom[idxVertex]; Assert.AreEqual(scale * (float)rawVertex.X, scaledVertex.X, $"{fileName}, feature[{idxFeat}], geometry part[{idxPart}], vertex[{idxVertex}], scale[{scale}]: X does not match"); Assert.AreEqual(scale * (float)rawVertex.Y, scaledVertex.Y, $"{fileName}, feature[{idxFeat}], geometry part[{idxPart}], vertex[{idxVertex}], scale[{scale}]: Y does not match"); } } } } } }
private BuildingMeshBuilderProperties MakeProperties(VectorTileLayer layer) { var output = new BuildingMeshBuilderProperties { VectorTileLayer = layer, FeatureCount = layer?.FeatureCount() ?? 0, LayerFeatureFilters = SubLayerProperties.filterOptions.filters.Select(m => m.GetFilterComparer()).ToArray(), LayerFeatureFilterCombiner = new LayerFilterComparer() }; switch (SubLayerProperties.filterOptions.combinerType) { case LayerFilterCombinerOperationType.Any: output.LayerFeatureFilterCombiner = LayerFilterComparer.AnyOf(output.LayerFeatureFilters); break; case LayerFilterCombinerOperationType.All: output.LayerFeatureFilterCombiner = LayerFilterComparer.AllOf(output.LayerFeatureFilters); break; case LayerFilterCombinerOperationType.None: output.LayerFeatureFilterCombiner = LayerFilterComparer.NoneOf(output.LayerFeatureFilters); break; default: throw new ArgumentOutOfRangeException(); } output.BuildingsWithUniqueIds = SubLayerProperties.honorBuildingIdSetting && SubLayerProperties.buildingsWithUniqueIds; return(output); }
private MapTile CreateTile(int x, int y, Vector3 <double> lonLatZoom) { VectorTileObj vectorTileObj = dataController.GetData(lonLatZoom); ReadOnlyCollection <string> layers = vectorTileObj.LayerNames(); Bitmap drawingObjects = new Bitmap(256, 256); Graph graph = dataController.GetRoads(lonLatZoom); using (Graphics graphics = Graphics.FromImage(drawingObjects)) { foreach (string layerName in drawingLayersPallete.Keys) { if (layers.Contains(layerName)) { VectorTileLayer layer = vectorTileObj.GetLayer(layerName); MVTDrawer.DrawLayer(layer, drawingLayersPallete[layerName], graphics, 4096 / 128); } } MVTDrawer.DrawLinks(graph.nodes, graphics, 32); } return(Dispatcher.Invoke(() => { Model3DGroup model3DGroup = new Model3DGroup(); model3DGroup.Children.Add(CreateTileModel(x, y, ImageUtils.GetImageStream(drawingObjects))); return new MapTile(model3DGroup); })); }
public static void AddSortRankToFeatures( this VectorTileLayer tile ) { // for (int i = 0; i < tile.FeatureCount (); i++) { // VectorTileFeature f = tile.GetFeature (i); // } }
public override void Create(VectorTileLayer layer, UnityTile tile, Action <UnityTile, LayerVisualizerBase> callback) { if (!_activeCoroutines.ContainsKey(tile)) { _activeCoroutines.Add(tile, new List <int>()); } _activeCoroutines[tile].Add(Runnable.Run(ProcessLayer(layer, tile, tile.UnwrappedTileId, callback))); }
/// <summary> /// Creates an object for each layer, extract and filter in/out the features and runs Build method on them. /// </summary> /// <param name="layer"></param> /// <param name="tile"></param> public override IEnumerator AsyncCreate(VectorTileLayer layer, UnityTile tile, Action cb) { var container = new GameObject(Key + " Container"); container.transform.SetParent(tile.transform, false); //testing each feature with filters var fc = layer.FeatureCount(); var filterOut = false; for (int i = 0; i < fc; i++) { filterOut = false; var feature = new VectorFeatureUnity(layer.GetFeature(i, 0), tile, layer.Extent); foreach (var filter in Filters) { if (!string.IsNullOrEmpty(filter.Key) && !feature.Properties.ContainsKey(filter.Key)) { continue; } if (!filter.Try(feature)) { filterOut = true; break; } } if (!filterOut) { Build(feature, tile, container); } if (i % _meshesPerPass == 0) { yield return(null); } } var mergedStack = _defaultStack as MergedModifierStack; if (mergedStack != null) { mergedStack.End(tile, container); } for (int i = 0; i < Stacks.Count; i++) { mergedStack = Stacks[i].Stack as MergedModifierStack; if (mergedStack != null) { mergedStack.End(tile, container); } } // yield return null; cb(); }
protected bool LoadNutiteqMapCommon() { // Set base projection EPSG3857 proj = new EPSG3857(); _mapViewer.Options.BaseProjection = proj; // note: EPSG3857 is the default, so this is actually not required // Set initial location and other parameters, don't animate _mapViewer.FocusPos = proj.FromWgs84(new MapPos(-0.8164, 51.2383)); // Berlin _mapViewer.Zoom = 2; _mapViewer.MapRotation = 0; _mapViewer.Tilt = 90; // Start package manager var packageManager = new NutiteqPackageManager("nutiteq.mbstreets", _downloadPackagePath); packageManager.Start(); // Import initial package if (packageManager.GetLocalPackage("world0_4") == null) { packageManager.StartPackageImport("world0_4", 1, _importPackagePath); } // Set bounding box String bbox = "bbox(-0.8164,51.2382,0.6406,51.7401)"; // London (about 30MB) if (packageManager.GetLocalPackage(bbox) == null) { packageManager.StartPackageDownload(bbox); } // Now can add vector map as layer // define styling for vector map UnsignedCharVector styleBytes = AssetUtils.LoadBytes("osmbright.zip"); MBVectorTileDecoder vectorTileDecoder = null; if (styleBytes != null) { // Create style set MBVectorTileStyleSet vectorTileStyleSet = new MBVectorTileStyleSet(styleBytes); vectorTileDecoder = new MBVectorTileDecoder(vectorTileStyleSet); } else { Log.Error("Failed to load style data"); } // Create online base layer (no package download needed then). Use vector style from assets (osmbright.zip) // comment in to use online map. Packagemanager stuff is not needed then // VectorTileLayer baseLayer = new NutiteqOnlineVectorTileLayer("osmbright.zip"); var baseLayer = new VectorTileLayer(new PackageManagerTileDataSource(packageManager), vectorTileDecoder); _mapViewer.Layers.Add(baseLayer); return(true); }
public RouteSearchView() { BaseLayer = AddBaseLayer(CartoBaseMapStyle.CartoBasemapStylePositron); var washingtonDC = Projection.FromWgs84(new MapPos(-77.0369, 38.9072)); MapView.FocusPos = washingtonDC; MapView.Zoom = 14.0f; }
/// <summary> /// Creates a vector feature from lat lon and builds that feature using the modifier stack. /// </summary> /// <param name="layer">Layer.</param> /// <param name="tile">Tile.</param> private void BuildFeatureFromLatLon(VectorTileLayer layer, UnityTile tile) { var coordinates = (SubLayerProperties as PrefabItemOptions).coordinates; for (int i = 0; i < coordinates.Length; i++) { if (String.IsNullOrEmpty(coordinates[i])) { return; } //check if the coordinate is in the tile var coordinate = Conversions.StringToLatLon(coordinates[i]); var coordinateTileId = Conversions.LatitudeLongitudeToTileId( coordinate.x, coordinate.y, tile.InitialZoom); if (coordinateTileId.Canonical.Equals(tile.CanonicalTileId)) { //create new vector feature var feature = new VectorFeatureUnity(); feature.Properties = new Dictionary <string, object>(); feature.Points = new List <List <Vector3> >(); //create a point in tilespace from coordinates var latLonPoint = new List <Vector3>(); //Create a feature point based on the coordinate var _meters = Conversions.LatLonToMeters(coordinate); var _rect = tile.Rect; var _scale = tile.TileScale; var _extent = layer.Extent; //vectortile space point (0 - layerExtent) var point = new Vector3((float)((_meters - _rect.Min).x / _rect.Size.x) * _extent, 0, (float)((_meters - _rect.Max).y / _rect.Size.y) * _extent ); //UnityTile space latLonPoint.Add(new Vector3((float)(point.x / _extent * _rect.Size.x - (_rect.Size.x / 2)) * tile.TileScale, 0, (float)((point.z) / _extent * _rect.Size.y - (_rect.Size.y / 2)) * tile.TileScale )); //add coordinate feature to feature points feature.Points.Add(latLonPoint); //pass valid feature.Data to modifiers //this data has no relation to the features being drawn feature.Data = layer.GetFeature(0); //pass the feature to the mod stack base.Build(feature, tile, tile.gameObject); } } }
private void ParseLabelLayerToList(List <GOParsedLayer> list, VectorTile vt, GOLabelsLayer layer) { string[] lyrs = tile.GetLabelsStrings().Split(','); // string kindKey = tile.GetPoisKindKey(); foreach (string l in lyrs) { VectorTileLayer lyr = vt.GetLayer(l); if (lyr != null) { int featureCount = lyr.FeatureCount(); if (featureCount == 0) { continue; } GOParsedLayer pl = new GOParsedLayer(); pl.name = lyr.Name; pl.labelsLayer = layer; pl.goFeatures = new List <GOFeature> (); for (int i = 0; i < featureCount; i++) { VectorTileFeature vtf = lyr.GetFeature(i); IDictionary properties = vtf.GetProperties(); List <List <LatLng> > geomWgs = vtf.GeometryAsWgs84((ulong)goTile.zoomLevel, (ulong)goTile.tileCoordinates.x, (ulong)goTile.tileCoordinates.y, 0); if (geomWgs.Count == 0 || geomWgs[0].Count <= 1) { continue; } GOFeature gf = new GOFeature(); gf.properties = properties; gf.goFeatureType = vtf.GOFeatureType(geomWgs); gf.labelsLayer = layer; gf.featureIndex = (Int64)i + vt.LayerNames().IndexOf(lyr.Name); gf.goTile = goTile; gf = tile.EditLabelData(gf); gf.goFeatureType = GOFeatureType.Label; gf.ConvertAttributes(); if (geomWgs.Count > 0) { gf.geometry = geomWgs[0]; gf.ConvertGeometries(); gf.preloadedLabelData = GOSegment.FindTheLongestStreightSegment(gf.convertedGeometry, 0); AddFatureToList(gf, pl.goFeatures); } } list.Add(pl); } } }
public void Create(VectorTileLayer layer, CustomTile tile) { if (tile == null || layer == null) { return; } var properties = MakeProperties(layer); ProcessingFunction(properties, tile); }
public void Create(VectorTileLayer layer, CustomTile tile) { if (tile == null || layer == null) { return; } var properties = MakeProperties(layer); CoroutineManager.Run(ProcessingRoutine(properties, tile)); }
public static void InitializeVectorTileListener(this MapView map, VectorTileLayer layer) { LocalVectorDataSource source = new LocalVectorDataSource(map.Options.BaseProjection); VectorLayer popupLayer = new VectorLayer(source); map.Layers.Add(popupLayer); var listener = new VectorTileListener(popupLayer); (layer as VectorTileLayer).VectorTileEventListener = listener; }
protected void AddOnlineBaseLayer(CartoBaseMapStyle withStyle) { // Initialize map if (BaseLayer != null) { MapView.Layers.Remove(BaseLayer); } BaseLayer = new CartoOnlineVectorTileLayer(withStyle); MapView.Layers.Add(BaseLayer); }
protected bool LoadNutiteqMapCommon() { // Set base projection EPSG3857 proj = new EPSG3857(); _mapViewer.Options.BaseProjection = proj; // note: EPSG3857 is the default, so this is actually not required // Set initial location and other parameters, don't animate _mapViewer.FocusPos = proj.FromWgs84(new MapPos(-0.8164, 51.2383)); // Berlin _mapViewer.Zoom = 2; _mapViewer.MapRotation = 0; _mapViewer.Tilt = 90; // Start package manager var packageManager = new NutiteqPackageManager("nutiteq.mbstreets", _downloadPackagePath); packageManager.Start(); // Import initial package if (packageManager.GetLocalPackage("world0_4") == null) { packageManager.StartPackageImport("world0_4", 1, _importPackagePath); } // Set bounding box String bbox = "bbox(-0.8164,51.2382,0.6406,51.7401)"; // London (about 30MB) if (packageManager.GetLocalPackage(bbox) == null) { packageManager.StartPackageDownload(bbox); } // Now can add vector map as layer // define styling for vector map UnsignedCharVector styleBytes = AssetUtils.LoadBytes("osmbright.zip"); MBVectorTileDecoder vectorTileDecoder = null; if (styleBytes != null) { // Create style set MBVectorTileStyleSet vectorTileStyleSet = new MBVectorTileStyleSet(styleBytes); vectorTileDecoder = new MBVectorTileDecoder(vectorTileStyleSet); } else { Log.Error("Failed to load style data"); } // Create online base layer (no package download needed then). Use vector style from assets (osmbright.zip) // comment in to use online map. Packagemanager stuff is not needed then // VectorTileLayer baseLayer = new NutiteqOnlineVectorTileLayer("osmbright.zip"); var baseLayer = new VectorTileLayer(new PackageManagerTileDataSource(packageManager), vectorTileDecoder); _mapViewer.Layers.Add(baseLayer); return true; }
private static async Task <VectorTile> baseTileToVector(object baseTile) { var tile = baseTile as Mapbox.VectorTile.VectorTile; var result = new VectorTile(); foreach (var lyrName in tile.LayerNames()) { Mapbox.VectorTile.VectorTileLayer lyr = tile.GetLayer(lyrName); var vectorLayer = new VectorTileLayer(); vectorLayer.Name = lyrName; for (int i = 0; i < lyr.FeatureCount(); i++) { Mapbox.VectorTile.VectorTileFeature feat = lyr.GetFeature(i); var vectorFeature = new VectorTileFeature(); vectorFeature.Extent = 1; vectorFeature.GeometryType = convertGeometryType(feat.GeometryType); vectorFeature.Attributes = feat.GetProperties(); var vectorGeometry = new List <List <Point> >(); foreach (var points in feat.Geometry <int>()) { var vectorPoints = new List <Point>(); foreach (var coordinate in points) { var dX = (double)coordinate.X / (double)lyr.Extent; var dY = (double)coordinate.Y / (double)lyr.Extent; vectorPoints.Add(new Point(dX, dY)); //var newX = Utils.ConvertRange(dX, extent.Left, extent.Right, 0, vectorFeature.Extent); //var newY = Utils.ConvertRange(dY, extent.Top, extent.Bottom, 0, vectorFeature.Extent); //vectorPoints.Add(new Point(newX, newY)); } vectorGeometry.Add(vectorPoints); } vectorFeature.Geometry = vectorGeometry; vectorLayer.Features.Add(vectorFeature); } result.Layers.Add(vectorLayer); } return(result); }
public override void Create(VectorTileLayer layer, UnityTile tile) { _container = new GameObject(Key + " Container"); _container.transform.SetParent(tile.transform, false); var fc = layer.FeatureCount(); for (int i = 0; i < fc; i++) { var feature = new VectorFeatureUnity(layer.GetFeature(i, 0), tile); Build(feature, tile, _container); } }
public static void InitializeVectorTileListener(this VectorTileLayer tileLayer, MapView map) { LocalVectorDataSource source = new LocalVectorDataSource(map.Options.BaseProjection); var vectorLayer = map.FindVectorLayer(); if (vectorLayer == null) { vectorLayer = new VectorLayer(source); map.Layers.Add(vectorLayer); } tileLayer.VectorTileEventListener = new VectorTileListener(vectorLayer); }
public static void InitializePackageManager(string packageFolder, string importPackagePath, IMapView mapView, string downloadedPackage) { // Offline base layer // Define listener, definition is in same class above var packageManager = new CartoPackageManager("nutiteq.osm", packageFolder); packageManager.PackageManagerListener = new PackageListener(packageManager, downloadedPackage); // Download new package list only if it is older than 24h // Note: this is only needed if pre-made packages are used if (packageManager.ServerPackageListAge > 24 * 60 * 60) { packageManager.StartPackageListDownload(); } // Start manager - mandatory packageManager.Start(); // Import initial package if (packageManager.GetLocalPackage("world0_4") == null) { packageManager.StartPackageImport("world0_4", 1, importPackagePath); } // Now can add vector map as layer // Define styling for vector map BinaryData styleBytes = AssetUtils.LoadAsset("nutibright-v2a.zip"); MBVectorTileDecoder vectorTileDecoder = null; if (styleBytes != null) { // Create style set var vectorTileStyleSet = new CompiledStyleSet(new ZippedAssetPackage(styleBytes)); vectorTileDecoder = new MBVectorTileDecoder(vectorTileStyleSet); } else { Log.Error("Failed to load style data"); } // Create online base layer (no package download needed then). Use vector style from assets (osmbright.zip) // comment in to use online map. Packagemanager stuff is not needed then //VectorTileLayer baseLayer = new NutiteqOnlineVectorTileLayer("osmbright.zip"); var baseLayer = new VectorTileLayer(new PackageManagerTileDataSource(packageManager), vectorTileDecoder); mapView.Layers.Add(baseLayer); }
protected virtual void UpdateBaseLayer() { string styleAssetName = vectorStyleName + ".zip"; bool styleBuildings3D = false; if (vectorStyleName.Equals("nutibright3d")) { styleAssetName = BaseStyleFile; styleBuildings3D = true; } BinaryData styleBytes = AssetUtils.LoadAsset(styleAssetName); if (styleBytes == null) { Toast.MakeText(this, "Map style file must be in project assets: " + vectorStyleName, ToastLength.Short).Show(); return; } // Create style set CompiledStyleSet vectorTileStyleSet = new CompiledStyleSet(new ZippedAssetPackage(styleBytes)); vectorTileDecoder = new MBVectorTileDecoder(vectorTileStyleSet); // Set language, language-specific texts from vector tiles will be used vectorTileDecoder.SetStyleParameter("lang", vectorStyleLang); // OSM Bright style set supports choosing between 2d/3d buildings. Set corresponding parameter. if (styleAssetName.Equals(BaseStyleFile)) { vectorTileDecoder.SetStyleParameter("buildings3d", styleBuildings3D ? "1" : "0"); vectorTileDecoder.SetStyleParameter("markers3d", styleBuildings3D ? "1" : "0"); vectorTileDecoder.SetStyleParameter("texts3d", styleBuildings3D ? "1" : "0"); } // Create tile data source for vector tiles if (vectorTileDataSource == null) { vectorTileDataSource = CreateTileDataSource(); } // Remove old base layer, create new base layer if (BaseLayer != null) { MapView.Layers.Remove(BaseLayer); } BaseLayer = new VectorTileLayer(vectorTileDataSource, vectorTileDecoder); MapView.Layers.Insert(0, BaseLayer); }