Exemplo n.º 1
0
        /// <summary>
        /// Adds a layer created from the specified KML stream.
        /// </summary>
        /// <param name="kml">The source KML stream.</param>
        /// <param name="name">The new layer name (must be a valid alphanumeric name).</param>
        /// <param name="addingItemProc">The callback to invoke for each KML item as it is being loaded.</param>
        public void UpdateKmlLayer(string layerKey, Stream kml, AddingKmlItemDelegate addingItemProc)
        {
            KmlMapsLayer kl = _layers.Find((l) => l.MapLayer.Key == layerKey) as KmlMapsLayer;

            System.Diagnostics.Debug.Assert(kl != null);
            kl.Update(kml, addingItemProc);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Adds a layer created from the specified KML stream.
 /// </summary>
 /// <param name="kml">The source KML stream.</param>
 /// <param name="name">The new layer name (must be a valid alphanumeric name).</param>
 /// <param name="addingItemProc">The callback to invoke for each KML item as it is being loaded.</param>
 public void Update(Stream kml, AddingKmlItemDelegate addingItemProc)
 {
     _vectorLayer.Children.Clear();
     if (kml != null)
     {
         C1Mapper.LoadKML(_vectorLayer, kml, addingItemProc, out _bounds);
     }
 }
Exemplo n.º 3
0
        internal void SetKml(KmlLayer kmlLayer, Stream kmlStream, string layerKey)
        {
            AddingKmlItemDelegate addingItemProc = null;

            if (_runtime)
            {
                // TODO: maybe allow non-custom (i.e. report's main) data source here too?
                var layerData = string.IsNullOrEmpty(kmlLayer.ItemFilterExpr) ?
                                null :
                                MakeCustomData(kmlLayer.RecordSource);

                try
                {
                    addingItemProc = delegate(ref string itemName, out Color? stroke, out Color? fill, out bool trackCoords)
                    {
                        stroke      = null;
                        fill        = null;
                        trackCoords = false;

                        DataRowReportScriptContext context = null;
                        if (layerData != null)
                        {
                            try
                            {
                                // quote item name with ' doubling single quotes if any:
                                var filter = s_kmlItemNameRegex.Replace(kmlLayer.ItemFilterExpr,
                                                                        string.Format(CultureInfo.InvariantCulture, "'{0}'", itemName.Replace("'", "''")));
                                DataRow[] res = layerData.Select(filter);
                                if (res.Length > 0)
                                {
                                    context = new DataRowReportScriptContext(res[0]);
                                }
                                else // provide empty (dbnull) context values so that expressions still evaluate to something reasonable:
                                {
                                    context = new DataRowReportScriptContext(layerData.NewRow(), layerData.Columns);
                                }
                            }
                            catch
                            {
                                // eat select errors
                            }
                        }
                        if (context == null)
                        {
                            context = new DataRowReportScriptContext(null, null);
                        }
                        context.AddConstant(KmlLayer.varItemName, itemName);
                        bool itemVisible = Maps.Util.GetBool(ParentReport.Evaluate(kmlLayer.ItemVisibleExpr, context), true);
                        if (itemVisible)
                        {
                            var itemStyle = EvalStyleExpr <KmlItemStyle>(kmlLayer.ItemStyleExpr, KmlItemStyles, ExternalKmlItemStyle, kmlLayer.ItemStyle, context);
                            stroke      = Maps.Util.IsColorEmpty(itemStyle.StrokeColor) ? (Color?)null : itemStyle.StrokeColor;
                            fill        = Maps.Util.IsColorEmpty(itemStyle.FillColor) ? (Color?)null : itemStyle.FillColor;
                            itemName    = string.IsNullOrEmpty(itemStyle.ItemNameExpr) ? itemName : Maps.Util.GetString(ParentReport.Evaluate(itemStyle.ItemNameExpr, context));
                            trackCoords = Maps.Util.GetBool(ParentReport.Evaluate(kmlLayer.ItemTrackExpr, context), true);
                        }
                        return(itemVisible);
                    };
                }
                finally
                {
                    if (layerData != null)
                    {
                        layerData.Dispose();
                    }
                }
            }

            InitMapper();
            _c1mapper.UpdateKmlLayer(layerKey, kmlStream, addingItemProc);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Loads a KML or KMZ file from the specified stream into the layer.
        /// </summary>
        /// <param name="vl">The layer to load the stream into.</param>
        /// <param name="stream">The source stream.</param>
        /// <param name="addingItemProc">The callback to call for each KML item.</param>
        /// <param name="maxBounds">OUT: The union of all loaded items' bounds.</param>
        private static void LoadKML(dynamic vl, Stream stream, AddingKmlItemDelegate addingItemProc, out Rect maxBounds)
        {
            maxBounds = Rect.Empty;
#if !DYN
            var vects = KmlReader.Read(stream);
#else
            dynamic vects = DynLoader.CallC1MapsStaticMethod("C1.WPF.Maps.KmlReader", "Read", stream);
#endif
            vl.BeginUpdate();
#if !DYN
            foreach (C1VectorItemBase vect in vects)
            {
#else
            for (int i = 0; i < vects.Count; ++i)
            {
                dynamic vect = vects[i];
#endif
                if (addingItemProc != null)
                {
                    var oldName = ToolTipService.GetToolTip(vect) as string;
                    var newName = oldName;
                    Nullable <System.Drawing.Color> stroke, fill;
                    bool trackCoords;
                    if (!addingItemProc(ref newName, out stroke, out fill, out trackCoords))
                    {
                        continue;
                    }
                    if (stroke.HasValue)
                    {
                        vect.Stroke = Util.BrushFromGdiColor(stroke.Value);
                    }
                    if (fill.HasValue)
                    {
                        vect.Fill = Util.BrushFromGdiColor(fill.Value);
                    }
                    if (newName != oldName)
                    {
                        ToolTipService.SetToolTip(vect, newName);
#if !DYN
                        if (vect is C1VectorPlacemark)
                        {
                            ((C1VectorPlacemark)vect).Label = newName;
                        }
#else
                        if (vect.GetType() == DynLoader.GetC1MapsType("C1VectorPlacemark"))
                        {
                            vect.Label = newName;
                        }
#endif
                    }
                    if (trackCoords)
                    {
                        maxBounds.Union(vect.Bounds);
                    }
                }
                else
                {
                    maxBounds.Union(vect.Bounds);
                }

                vl.Children.Add(vect);
            }
            vl.EndUpdate();
        }