Exemplo n.º 1
0
        void AddLayers(System.Collections.IList layers)
        {
            if (layers == null)
            {
                return;
            }
            foreach (Layer layer in layers)
            {
                if (string.IsNullOrEmpty(layer.Id))
                {
                    continue;
                }
                NSString id       = (NSString)("NXCustom_" + layer.Id);
                var      oldLayer = MapView.Style.LayerWithIdentifier(id);
                if (oldLayer != null)
                {
                    MapView.Style.RemoveLayer(oldLayer);
                }
                if (layer is CircleLayer)
                {
                    var circleLayer = layer as CircleLayer;
                    if (string.IsNullOrEmpty(circleLayer.SourceId))
                    {
                        continue;
                    }
                    var sourceId = (NSString)("NXCustom_" + circleLayer.SourceId);

                    var source = MapView.Style.SourceWithIdentifier(sourceId);
                    if (source == null)
                    {
                        continue;
                    }
                    var newLayer = new MGLCircleStyleLayer(id, source);
                    newLayer.CircleColor   = MGLStyleValue.ValueWithRawValue(circleLayer.CircleColor.ToUIColor());
                    newLayer.CircleOpacity = MGLStyleValue.ValueWithRawValue(NSNumber.FromDouble(circleLayer.CircleOpacity));
                    newLayer.CircleRadius  = MGLStyleValue.ValueWithRawValue(NSNumber.FromDouble(circleLayer.CircleRadius));
                    MapView.Style.AddLayer(newLayer);
                }
                else if (layer is LineLayer)
                {
                    var lineLayer = layer as LineLayer;
                    if (string.IsNullOrEmpty(lineLayer.SourceId))
                    {
                        continue;
                    }
                    var sourceId = (NSString)("NXCustom_" + lineLayer.SourceId);
                    var source   = MapView.Style.SourceWithIdentifier(sourceId);
                    if (source == null)
                    {
                        continue;
                    }
                    var newLayer = new MGLLineStyleLayer(id, source);
                    newLayer.LineWidth = MGLStyleValue.ValueWithRawValue(NSNumber.FromDouble(lineLayer.LineWidth));
                    newLayer.LineColor = MGLStyleValue.ValueWithRawValue(lineLayer.LineColor.ToUIColor());
                    //TODO lineCap
                    MapView.Style.AddLayer(newLayer);
                }
            }
        }
Exemplo n.º 2
0
 private NSObject GetObjectFromStyleValue(MGLStyleValue value)
 {
     if (value is MGLConstantStyleValue cValue)
     {
         return(cValue.RawValue);
     }
     if (value is MGLCameraStyleFunction csFunc)
     {
         return(GetValueFromCameraStyleFunction(csFunc));
     }
     if (value != null && value.RespondsToSelector(new ObjCRuntime.Selector("rawValue")))
     {
         return(value.ValueForKey((NSString)"rawValue"));
     }
     return(value);
 }
        void AddLayer(MGLStyle style)
        {
            var source = new MGLVectorSource(identifier: "contours", configurationURL: new NSUrl("mapbox://mapbox.mapbox-terrain-v2"));
            var layer  = new MGLLineStyleLayer(identifier: "contours", source: source);

            layer.SourceLayerIdentifier = "contour";
            layer.LineJoin = MGLStyleValue.ValueWithRawValue(NSValue.FromObject(MGLLineJoin.Round));
            layer.LineCap  = MGLStyleValue.ValueWithRawValue(NSValue.FromObject(MGLLineCap.Round));

            layer.LineColor = MGLStyleValue.ValueWithRawValue(UIColor.Brown);

            layer.LineWidth = MGLStyleValue.ValueWithRawValue(NSValue.FromObject(1.0));
            style.AddSource(source);

            style.AddLayer(layer);
            contoursLayer = layer;
        }
Exemplo n.º 4
0
        private NSObject GetValueFromCameraStyleFunction(MGLCameraStyleFunction csFunc)
        {
            if (csFunc.Stops == null || csFunc.Stops.Count == 0)
            {
                return(null);
            }
            MGLStyleValue output = null;

            switch (csFunc.InterpolationMode)
            {
            case MGLInterpolationMode.Identity:
                nuint i = 0;
                while (i < csFunc.Stops.Count)
                {
                    var key       = csFunc.Stops.Keys[i];
                    var zoomLevel = (key as NSNumber).DoubleValue;
                    if (zoomLevel < MapView.ZoomLevel)
                    {
                        output = csFunc.Stops[key];
                    }
                    else
                    {
                        break;
                    }
                    i++;
                }
                break;

            default: break;
            }
            if (output == null)
            {
                output = csFunc.Stops.Values[0];
            }
            return(GetObjectFromStyleValue(output));
        }
Exemplo n.º 5
0
        private MGLVectorStyleLayer GetStyleLayer(StyleLayer styleLayer, NSString id)
        {
            if (string.IsNullOrEmpty(styleLayer.SourceId))
            {
                return(null);
            }
            var sourceId = styleLayer.SourceId.ToCustomId();

            var source = MapView.Style.SourceWithIdentifier(sourceId);

            if (source == null)
            {
                return(null);
            }
            if (styleLayer is CircleLayer circleLayer)
            {
                var newLayer = new MGLCircleStyleLayer(id, source)
                {
                    CircleColor   = MGLStyleValue.ValueWithRawValue(circleLayer.CircleColor.ToUIColor()),
                    CircleOpacity = MGLStyleValue.ValueWithRawValue(NSNumber.FromDouble(circleLayer.CircleOpacity)),
                    CircleRadius  = MGLStyleValue.ValueWithRawValue(NSNumber.FromDouble(circleLayer.CircleRadius))
                };
                if (circleLayer.StrokeColor is Color strokeColor)
                {
                    newLayer.CircleStrokeColor   = MGLStyleValue.ValueWithRawValue(strokeColor.ToUIColor());
                    newLayer.CircleStrokeOpacity = MGLStyleValue.ValueWithRawValue(NSNumber.FromDouble(circleLayer.StrokeOpacity));
                    newLayer.CircleStrokeWidth   = MGLStyleValue.ValueWithRawValue(NSNumber.FromDouble(circleLayer.StrokeWidth));
                }
                return(newLayer);
            }

            if (styleLayer is LineLayer lineLayer)
            {
                var newLayer = new MGLLineStyleLayer(id, source)
                {
                    LineWidth = MGLStyleValue.ValueWithRawValue(NSNumber.FromDouble(lineLayer.LineWidth)),
                    LineColor = MGLStyleValue.ValueWithRawValue(lineLayer.LineColor.ToUIColor())
                };
                if (lineLayer.Dashes != null && lineLayer.Dashes.Length != 0)
                {
                    var arr = new NSMutableArray <NSNumber>();
                    foreach (double dash in lineLayer.Dashes)
                    {
                        arr.Add(NSNumber.FromDouble(dash));
                    }
                    newLayer.LineDashPattern = MGLStyleValue.ValueWithRawValue(arr);
                }
                //TODO lineCap
                return(newLayer);
            }

            if (styleLayer is FillLayer fl)
            {
                var newLayer = new MGLFillStyleLayer(id, source)
                {
                    FillColor   = MGLStyleValue.ValueWithRawValue(fl.FillColor.ToUIColor()),
                    FillOpacity = MGLStyleValue.ValueWithRawValue(NSNumber.FromDouble(fl.FillOpacity))
                };
                return(newLayer);
            }

            if (styleLayer is SymbolLayer sl)
            {
                var newLayer = new MGLSymbolStyleLayer(id, source)
                {
                    IconImageName = MGLConstantStyleValue.ValueWithRawValue((NSString)sl.IconImageName),
                    IconOpacity   = MGLStyleValue.ValueWithRawValue(NSNumber.FromDouble(sl.IconOpacity))
                };
                return(newLayer);
            }

            return(null);
        }