Ejemplo n.º 1
0
		private void initializePinsLayer()
		{
			// Just initialize with empty so that it's guaranteed that there are sources initiated
			// when the pins collection is still null
			var mapLockedPinsSource = new MGLShapeSource(mapLockedPinsSourceKey, new NSObject[]{}, null);
			nStyle.AddSource(mapLockedPinsSource);

			// Pins with bearings layer - configure elements
			var mapLockedPinsLayer = new MGLSymbolStyleLayer(mapLockedPinsKey, mapLockedPinsSource) {
				IconImageName = NSExpression.FromKeyPath(pin_image_key),
				IconRotation = NSExpression.FromKeyPath(pin_rotation_key),
				IconScale = NSExpression.FromKeyPath(pin_size_key),
				IconRotationAlignment = NSExpression.FromConstant(NSObject.FromObject("map")), // Finally the map-lock flat = "map"
				IconAllowsOverlap = NSExpression.FromConstant(NSObject.FromObject(true)) // Always overlap
			};
			nStyle.AddLayer(mapLockedPinsLayer);

			// Just initialize with empty so that it's guaranteed that there are sources initiated
			// when the pins collection is still null
			var normalPinsSource = new MGLShapeSource(normalPinsSourceKey, new NSObject[] { }, null);
			nStyle.AddSource(normalPinsSource);

			// Normal pins layer - configure elements
			var normalPinsLayer = new MGLSymbolStyleLayer(normalPinsKey, normalPinsSource) {
				IconImageName = NSExpression.FromKeyPath(pin_image_key),
				IconScale = NSExpression.FromKeyPath(pin_size_key),
				IconOffset = NSExpression.FromKeyPath(pin_offset_key), //https://www.mapbox.com/mapbox-gl-js/style-spec/#layout-symbol-icon-offset
				IconAnchor = NSExpression.FromConstant(NSObject.FromObject("bottom")), // https://www.mapbox.com/mapbox-gl-js/style-spec/#layout-symbol-icon-anchor = "bottom" or "center"
				IconAllowsOverlap = NSExpression.FromConstant(NSObject.FromObject(true))
			};
			nStyle.AddLayer(normalPinsLayer);
		}
Ejemplo n.º 2
0
 void AddSources(System.Collections.IList sources)
 {
     if (sources == null || MapView == null || MapView.Style == null)
     {
         return;
     }
     foreach (ShapeSource source in sources)
     {
         if (source.Id != null && source.Shape != null)
         {
             var shape     = ShapeFromAnnotation(source.Shape);
             var sourceId  = (NSString)("NXCustom_" + source.Id);
             var oldSource = MapView.Style?.SourceWithIdentifier(sourceId);
             if (oldSource != null && oldSource is MGLShapeSource)
             {
                 (oldSource as MGLShapeSource).Shape = shape;
             }
             else
             {
                 var mglSource = new MGLShapeSource(sourceId, shape, null);
                 MapView.Style.AddSource(mglSource);
             }
         }
     }
 }
Ejemplo n.º 3
0
		private void initializeRoutesLayer()
		{
			// Just initialize with empty so that it's guaranteed that there are sources initiated
			// when the routes collection is still null
			var routeSource = new MGLShapeSource(line_source_key, new NSObject[] { }, null);
			nStyle.AddSource(routeSource);

			var borderLinesLayer = new MGLLineStyleLayer(border_line_layer_key, routeSource);
			borderLinesLayer.LineColor = NSExpression.FromKeyPath(border_line_color_key);
			borderLinesLayer.LineWidth = NSExpression.FromKeyPath(border_line_width_key);
			borderLinesLayer.LineJoin = NSExpression.FromConstant(NSObject.FromObject("round"));
			borderLinesLayer.LineCap = NSExpression.FromConstant(NSObject.FromObject("round"));
			nStyle.AddLayer(borderLinesLayer);

			var linesLayer = new MGLLineStyleLayer(line_layer_key, routeSource);
			linesLayer.LineColor = NSExpression.FromKeyPath(line_color_key);
			linesLayer.LineWidth = NSExpression.FromKeyPath(line_width_key);
			linesLayer.LineJoin = NSExpression.FromConstant(NSObject.FromObject("round"));
			linesLayer.LineCap = NSExpression.FromConstant(NSObject.FromObject("round"));
			nStyle.AddLayer(linesLayer);
		}
Ejemplo n.º 4
0
        public static MGLSource ToSource(this Source source)
        {
            MGLShapeSource result = null;

            switch (source)
            {
            case GeoJsonSource geojsonSource:
            {
                var options = geojsonSource.Options.ToOptions();

                if (geojsonSource.Data != null)
                {
                    var shape = geojsonSource.Data.ToShape();
                    return(new MGLShapeSource(source.Id, shape, options));
                }

                if (string.IsNullOrWhiteSpace(geojsonSource.Url))
                {
                    return(new MGLComputedShapeSource(geojsonSource.Id, options));
                }

                var url = geojsonSource.IsLocal
                            ? NSUrl.FromFilename(geojsonSource.Url.Replace("asset://", string.Empty))
                            : NSUrl.FromString(geojsonSource.Url);
                return(new MGLShapeSource(source.Id, url, options));
            }

            case VectorSource vectorSource:
                if (vectorSource.TileSet != null)
                {
                    return(new MGLVectorTileSource(vectorSource.Id, vectorSource.TileSet.Tiles, vectorSource.Options.ToOptions()));
                }

                return(new MGLVectorTileSource(vectorSource.Id, NSUrl.FromString(vectorSource.Url)));

            case RasterSource rasterSource:
                if (rasterSource.TileSet != null)
                {
                    var options = new NSMutableDictionary <NSString, NSObject>();
                    if (rasterSource.TileSize.HasValue)
                    {
                        options.Add(MGLTileSourceOptions.TileSize, NSNumber.FromInt32(rasterSource.TileSize.Value));
                    }

                    // TODO No TileSet for iOS??
                    return(new MGLRasterTileSource(rasterSource.Id, rasterSource.TileSet.Tiles, new NSDictionary <NSString, NSObject>(options.Keys, options.Values)));
                }
                return(rasterSource.TileSize.HasValue
                        ? new MGLRasterTileSource(rasterSource.Id, NSUrl.FromString(rasterSource.ConfigurationURL), rasterSource.TileSize.Value)
                        : new MGLRasterTileSource(rasterSource.Id, NSUrl.FromString(rasterSource.ConfigurationURL)));

            case RasterDemSource rasterDemSource:
                if (rasterDemSource.TileSet != null)
                {
                    var options = new NSMutableDictionary <NSString, NSObject>();
                    if (rasterDemSource.TileSize.HasValue)
                    {
                        options.Add(MGLTileSourceOptions.TileSize, NSNumber.FromInt32(rasterDemSource.TileSize.Value));
                    }

                    // TODO No TileSet for iOS??
                    return(new MGLRasterDEMSource(rasterDemSource.Id, rasterDemSource.TileSet.Tiles, new NSDictionary <NSString, NSObject>(options.Keys, options.Values)));
                }
                return(rasterDemSource.TileSize.HasValue
                        ? new MGLRasterDEMSource(rasterDemSource.Id, NSUrl.FromString(rasterDemSource.Url), rasterDemSource.TileSize.Value)
                        : new MGLRasterDEMSource(rasterDemSource.Id, NSUrl.FromString(rasterDemSource.Url)));

            case MapboxImageSource imageSource:
                //TODO Other image source
                return(new MGLImageSource(imageSource.Id, imageSource.Coordinates.ToNative(), imageSource.Source.GetImage()));
            }

            return(result);
        }