Example #1
0
        }         // private void applyConfig(string cfg)

        /// <summary>
        /// Call from applyConfig. Parse saved map config
        /// </summary>
        /// <param name="cfg"></param>
        /// <returns></returns>
        public static List <VLayer> lyrsListFromConfig(string cfg)
        {
            var ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(cfg));
            var js = JsonObject.Load(ms);

            var layersList = new List <VLayer>();

            for (int cnt = 1; cnt < 1000; cnt++)
            {
                if (js.ContainsKey(cnt.ToString()))
                {
                    var jsLyr = js[cnt.ToString()];
                    var vLyr  = new VLayer((JsonObject)jsLyr);
                    //add to LayersList
                    if (vLyr.lyr.GetType() == typeof(ESRI.ArcGIS.Client.GraphicsLayer))
                    {
                        layersList.Add(vLyr);
                    }
                    else
                    {
                        layersList.Add(vLyr);
                    }
                }
                else
                {
                    break;
                }
            }             // fill layersList from json

            return(layersList);
        }         // private List<VLayer> lyrsListFromConfig(string cfg)
Example #2
0
        }         // public static GraphicsLayer reloadRLData(Map map, string layerID, string layerName)

        /// <summary>
        /// Create graphics from xml and restore Symbol for each Graphic in layer
        /// </summary>
        /// <param name="gl">redline layer</param>
        /// <param name="xmlContent">symbols parameters</param>
        public static void restoreRLGraphics(GraphicsLayer gl, string xmlContent)
        {
            // set Graphics symbols
            gl = VLayer.setContent(gl, xmlContent);

            foreach (var gr in gl.Graphics)
            {
                var t = gr.Attributes["aType"] as string;
                ESRI.ArcGIS.Client.Geometry.Geometry g = gr.Geometry;

                if (isText(g, t))
                {
                    gr.Symbol = remakeTextSymbol(gr);
                }
                else if (isPoint(g))
                {
                    gr.Symbol = dicSymbols[t];
                }
                else if (isLine(g))
                {
                    gr.Symbol = dicLineSymbols[t];
                }
                else if (isArea(g))
                {
                    gr.Symbol = dicAreaSymbols[t];
                }
                else
                {
                    (string.Format("restoreRLGraphics, unknown Geom type [{0}]", g.GetType())).clog();
                    continue;
                }
            }
        }         // public static void restoreRLGraphics(GraphicsLayer gl, string xmlContent)
Example #3
0
        /// <summary>
        /// Invoke from restoreMap method: applyConfig(cfg);
        /// get layers list, start ping services pingLyrsList
        /// </summary>
        /// <param name="cfg"></param>
        public void applyConfig(string cfg)
        {
            log(string.Format("VRestore.applyConfig"));
            // check if vLayers is not null already!
            if (vLayers != null)
            {
                throw new Exception("Подождите завершения загрузки предыдущей карты");
            }
            MapApplication.Current.Map.Cursor = System.Windows.Input.Cursors.Wait;
            // restore map layers from json string
            var layersList = lyrsListFromConfig(cfg);

            this.mapCfg  = cfg;
            this.vLayers = layersList;

            this.selectedLyr = null;
            foreach (var vl in layersList)
            {
                if (vl.selected)
                {
                    this.selectedLyr = vl;
                }
            }
            log(string.Format("VRestore.applyConfig, selectedLyr '{0}' '{1}'", selectedLyr.ID, selectedLyr.lyrName));

            pingLyrsList(layersList);

            // only after ping all layers
            //loadLyrsList(layersList);
        }         // private void applyConfig(string cfg)
Example #4
0
        }                    // public void addSelectedLayer()

        public void addLayer(VLayer lyr)
        {
            log("addLayer " + lyr.lyrUrl);
            ESRI.ArcGIS.Client.Map             map  = MapApplication.Current.Map;
            ESRI.ArcGIS.Client.LayerCollection lyrs = map.Layers;
            lyr.lyr.InitializationFailed += new EventHandler <EventArgs>(lyr_InitializationFailed);
            lyrs.Add(lyr.lyr);
            MapApplication.SetLayerName(lyr.lyr, lyr.lyrName);
            // http://help.arcgis.com/en/webapps/silverlightviewer/help/index.html#//01770000001s000000
        }         // public void addLayer(VLayer lyr)
Example #5
0
        }         // void pingsrv_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) {

        /// <summary>
        /// If layers in config: clear map.layers; attach mapprogress event; add layers from config to map;
        /// set extent; set selected layer
        /// </summary>
        /// <param name="cfg"></param>
        /// <param name="map"></param>
        /// <param name="lyrInitFail"></param>
        /// <param name="mapProgress"></param>
        public static VLayer loadMapCfg(string cfg, ESRI.ArcGIS.Client.Map map,
                                        EventHandler <EventArgs> lyrInitFail, EventHandler <ProgressEventArgs> mapProgress)
        {
            // if LayersList: clean map; add layers from LayersList to map
            ESRI.ArcGIS.Client.Geometry.Envelope ext = VRestore.mapExtentFromConfig(cfg);
            var layersList = VRestore.lyrsListFromConfig(cfg);

            if (layersList.Count <= 0)
            {
                throw new Exception("VRestore.loadMapCfg: список слоев пуст, видимо была сохранена пустая карта");
            }

            ESRI.ArcGIS.Client.LayerCollection lyrs = map.Layers;
            // clear map
            lyrs.Clear();
            VLayer sl = null;

            if (mapProgress != null && layersList.Count > 0)
            {
                map.Progress -= mapProgress;
                map.Progress += mapProgress;
            }

            // add layers to map
            foreach (var x in layersList)
            {
                //string.Format("loadMapCfg, add layer {0}", x.lyrUrl).clog();
                string.Format("VRestore.loadMapCfg, add layer '{0}' '{1}' '{2}'", x.ID, x.lyrName, x.lyrType).clog();
                if (lyrInitFail != null)
                {
                    x.lyr.InitializationFailed += new EventHandler <EventArgs>(lyrInitFail);
                }
                //x.lyr.SetValue(MapApplication.LayerNameProperty, x.lyrName);
                //x.lyr.Initialize();
                lyrs.Add(x.lyr);
                MapApplication.SetLayerName(x.lyr, x.lyrName);
                if (x.selected)
                {
                    sl = x;
                }
            }
            if (ext != null)
            {
                map.Extent = ext;
            }

            // select selected layer
            if (sl != null)
            {
                string.Format("VRestore.loadMapCfg, selected layer '{0}' '{1}'", sl.ID, sl.lyrName).clog();
                MapApplication.Current.SelectedLayer = sl.lyr;
            }
            return(sl);
        }         // public static VLayer loadMapCfg(string cfg, ESRI.ArcGIS.Client.Map map)
Example #6
0
        }         // public void runTool(object param)

        /// <summary>
        /// Creates a simple graphics layer
        /// </summary>
        /// <returns>Redline layer</returns>
        private GraphicsLayer getRLLayer()
        {
            // call from runTool
            log("getRLLayer");
            var lyr = MapApplication.Current.SelectedLayer;
            var gl  = VLayer.makeRLLayer(MapApplication.Current.Map, layerID, layerName);

            gl.MouseLeftButtonDown -= gl_MouseLeftButtonDown;
            gl.MouseLeftButtonDown += gl_MouseLeftButtonDown;
            MapApplication.Current.SelectedLayer = lyr;
            return(gl);
        }         // private GraphicsLayer getRLLayer()
Example #7
0
        }         // public void addLayer(VLayer lyr)

        public void addLayer2Q(VLayer lyr)
        {
            /* add layer to queue; if q.processing in stopped, ping layer service.
             */
            log("addLayer2Q " + lyr.lyrUrl);
            lyrsQueue.setLock();
            lyrsQueue.Enqueue(lyr);
            if (lyrsQueue.hasProcessor == false)
            {
                lyrsQueue.hasProcessor = true;
                lyrsQueue.releaseLock();
                pingService(lyr);
                return;
            }
            lyrsQueue.releaseLock();
        }         // public void addLayer(VLayer lyr)
Example #8
0
        }         // public static VLayer loadMapCfg(string cfg, ESRI.ArcGIS.Client.Map map)

        void lyr_InitializationFailed(object sender, EventArgs e)
        {
            Layer  layer = sender as Layer;
            var    lyr   = new VLayer(layer);
            string mesg  = "";

            if (layer.InitializationFailure != null)
            {
                mesg = layer.InitializationFailure.ToString() + "\n";
            }
            mesg = string.Format(
                "Невозможно включить слой [{0}], \n ошибка [{1}]", lyr.lyrUrl, mesg);
            log(string.Format("lyr_InitializationFailed, [{0}]", mesg));
            //MessageBox.Show(msg);
            this.msg     += mesg;
            layer.Visible = false;
        }         // void lyr_InitializationFailed(object sender, EventArgs e)
Example #9
0
        }         // void pingsrv_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) {

        void lyr_InitializationFailed(object sender, EventArgs e)
        {
            Layer  layer = sender as Layer;
            var    lyr   = new VLayer(layer);
            string msg   = "";

            if (layer.InitializationFailure != null)
            {
                msg = layer.InitializationFailure.ToString() + "\n";
            }
            msg = string.Format(
                "Невозможно включить слой [{0}], \n ошибка [{1}]", lyr.lyrUrl, msg);
            log(string.Format("lyr_InitializationFailed, [{0}]", msg));
            MessageBox.Show(msg);
            layer.Visible = false;
            // remove then add again.
            // this method is not applicable, because IE8 use cache for second request
        } // addSelectedLayer
Example #10
0
        }         // public void addLayer(VLayer lyr)

        /// <summary>
        /// Send fake request to layer service, add layer to map in callback
        /// </summary>
        /// <param name="lyr"></param>
        public void pingService(VLayer lyr)
        {
            var wc = new WebClient();

            wc.OpenReadCompleted += pingsrv_OpenReadCompleted;
            string url = lyr.lyrUrl + "?f=json&pretty=true";

            try {
                Uri u = new Uri(url, UriKind.RelativeOrAbsolute);
                this.listDialog.busyIndicator1.IsBusy = true;
                wc.OpenReadAsync(u, url);
                log(String.Format("pingService, request sent, url [{0}]...", url));
            }
            catch (Exception e) {
                log(String.Format("pingService, catch exception while open url [{0}], msg [{1}]", url, e.Message));
                pingsrv_OpenReadCompleted(null, null);
            }
        }         // public void pingService(VLayer lyr)
Example #11
0
        }         // private void renewRL()

        /// <summary>
        /// Reload graphics and restore graphics symbols in RL layer
        /// </summary>
        /// <param name="map">Map</param>
        /// <param name="layerID">layer id</param>
        /// <param name="layerName">layer name</param>
        /// <returns>redline layer or null</returns>
        public static GraphicsLayer reloadRLData(Map map, string layerID, string layerName)
        {
            // recreate RL layer, load RL content
            var gl = map.Layers[layerID] as GraphicsLayer;

            if (gl == null)
            {
                string.Format("VRedlineImpl.reloadRLData, lyr '{0}' doesn't exist", layerID).clog();
                return(null);
            }

            var rlc = VLayer.getContent(gl);

            //map.Layers.Remove(gl);
            //gl = makeRLLayer(map, layerID, layerName);
            gl.Graphics.Clear();
            restoreRLGraphics(gl, rlc);
            return(gl);
        }         // public static GraphicsLayer reloadRLData(Map map, string layerID, string layerName)
Example #12
0
        }         // public void pingService(VLayer lyr)

        /// <summary>
        /// Layer service ping callback. Peek next layer; if next is null call loadMapCfg.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void pingsrv_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            //listDialog.busyIndicator1.IsBusy = false;
            try {
                var wc  = sender as WebClient;
                var url = e.UserState as string;
                log(String.Format("VRestore.pingsrv_OpenReadCompleted, got responce, url '{0}'", url));

                //Stream stream = (Stream)e.Result;
                //BinaryReader reader = new BinaryReader(stream);
                //byte[] buffer = reader.ReadBytes((int)stream.Length);
                //var str = System.Text.Encoding.UTF8.GetString(buffer, 0, (int)stream.Length);

                if (e != null && e.Error != null)
                {
                    log(String.Format("VRestore.pingsrv_OpenReadCompleted, resp.Error: "
                                      + "url '{1}', msg [{0}]", e.Error.Message, url));
                }

                lyrsQueue.setLock();
                var lyr  = lyrsQueue.Dequeue() as VLayer;
                var next = lyrsQueue.Peek() as VLayer;
                if (next == null)
                {
                    lyrsQueue.hasProcessor = false;
                }
                lyrsQueue.releaseLock();

                //e.Result
                if (next == null)
                {
                    log(String.Format("VRestore.pingsrv_OpenReadCompleted, all services was pinged."));
                    restoreWnd.busyIndicator1.IsBusy = false;
                    this.selectedLyr = loadMapCfg(mapCfg, MapApplication.Current.Map, lyr_InitializationFailed, Map_Progress);
                    vLayers          = null;
                    MapApplication.Current.HideWindow(restoreWnd);
                }
            }
            catch (Exception ex) {
                log(String.Format("VRestore.pingsrv_OpenReadCompleted, exception '{0}'", ex.Message));
            }
        }         // void pingsrv_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) {
Example #13
0
        public void addSelectedLayer()
        {
            log("addSelectedLayer...");
            VLayerDescription ld = (VLayerDescription)this.listDialog.listBox2.SelectedItem;

            if (ld == null)
            {
                log("no selected layer");
                return;
            }
            log("selected layer: " + ld.toString());
            var lyr = new VLayer(ld);

            // if FeatureLayer retrieve attribs from server
            // look in VLayer.createLayer
            //lr.OutFields.Add("*");
            //lr.Initialize();
            addLayer2Q(lyr); // queue
            //addLayer(lyr);
        }                    // public void addSelectedLayer()
Example #14
0
        }         // private void editMarker(Graphic gr)

        private void restoreRLLayer(GraphicsLayer gl, string xmlContent)
        {
            // set Graphics symbols
            log("restoreRLLayer, ...");
            gl = VLayer.setContent(gl, xmlContent);

            foreach (var g in gl.Graphics)
            {
                var typ = g.Attributes["aType"] as string;
                currGeom = g.Geometry;
                markType = typ;

                if (isText())
                {
                    g.Symbol = remakeTextSymbol(g);
                }
                else if (isPoint(g.Geometry))
                {
                    g.Symbol = dicSymbols[typ];
                }
                else if (isLine(g.Geometry))
                {
                    g.Symbol = dicLineSymbols[typ];
                }
                else if (isArea(g.Geometry))
                {
                    g.Symbol = dicAreaSymbols[typ];
                }
                else
                {
                    log(string.Format("unknown Geom type [{0}]", g.Geometry.GetType()));
                    continue;
                }

                currGeom = null;
                markType = null;
            }
        }         // private void restoreRLLayer(GraphicsLayer gl, string xmlContent)
Example #15
0
 public bool CanExecute(object parameter)
 {
     try {
         //log(string.Format("CanExecute, param '{0}'", parameter==null?"null":parameter.GetType().ToString()));
         // todo: get current layer: check GP service availability
         var  currentLayer         = new VLayer();
         bool seismoGeoprocessorOK = false;
         if (
             currentLayer.lyrUrl.Contains("seismoprofiles") &&
             seismoGeoprocessorOK &&
             MapApplication.Current.Map != null
             )
         {
             return(true);
         }
         return(false);
     }
     catch (Exception ex) {
         log(string.Format("CanExecute, error {0}, {1}", ex.Message, ex.StackTrace));
         return(false);
     }
     // todo: seismoprofiles layer must be exist
 }         // public bool CanExecute(object parameter)
Example #16
0
        }         // private string getMapConfig()

        /// <summary>
        /// read layers list, create json object from them
        /// </summary>
        /// <param name="map"></param>
        /// <returns></returns>
        public static string mapConfig(ESRI.ArcGIS.Client.Map map)
        {
            var res = new JsonObject();             // http://msdn.microsoft.com/en-us/library/cc197957%28v=VS.95%29.aspx

            ESRI.ArcGIS.Client.LayerCollection lyrs = map.Layers;
            var ext = map.Extent.Clone();

            var obj = new JsonObject {
                { "xmin", ext.XMin },
                { "xmax", ext.XMax },
                { "ymin", ext.YMin },
                { "ymax", ext.YMax },
                { "sridWKID", ext.SpatialReference.WKID },
                { "sridWKT", ext.SpatialReference.WKT }
            };

            res.Add("MapExtent", obj);

            int num = 0;

            foreach (var lyr in lyrs)
            {
                // from bottom to top
                var vl = new VLayer(lyr);
                if (vl.ID == null || vl.ID == "")
                {
                    string.Format("VSave.mapConfig, skip layer '{0}'", vl.toJson()).clog();
                    continue;                     // skip empty GraphicsLayer
                }
                num += 1;
                obj  = vl.toJson();
                res.Add(num.ToString(), obj);
            }             // end foreach layer

            return(res.ToString());
        }                                                 // public static string mapConfig(ESRI.ArcGIS.Client.Map map)
Example #17
0
        }         // private void onMapLabelChanged(object sender, TextChangedEventArgs e)

        public void updateLayout()
        {
            // apply print layout
            log(string.Format("PrintForm.updateLayout"));
            this.label1.Content    = string.Format("{0}", this.tbMapLabel.Text);
            this.label1.FontFamily = SelectedFontFamily;
            this.label1.FontSize   = SelectedFontSize;

            this.tbDescription.Text       = string.Format("{0}", tbDescrSrc.Text);
            this.tbDescription.FontFamily = SelectedFontFamily;
            this.tbDescription.FontSize   = SelectedDescrFontSize;

            updatePixelsFromMillimeters();
            printableArea.Height = SelectedHeightPx;
            printableArea.Width  = SelectedWidthPx;

            scaleLine1.Map     = this.Map;
            scaleLine1.MapUnit = ESRI.ArcGIS.Client.Toolkit.ScaleLine.ScaleLineUnit.Kilometers;

            if (legendFixed)
            {
                ;
            }
            else
            {
                legendFixed = true;
                ESRI.ArcGIS.Client.Toolkit.Legend lgnd = this.legend1;
                foreach (var x in lgnd.LayerItems)                  // remove basemap from legend
                {
                    lgnd.LayerItems.Remove(x);
                    break;
                }

                ObservableCollection <ESRI.ArcGIS.Client.Toolkit.Primitives.LayerItemViewModel>
                swap = new ObservableCollection <ESRI.ArcGIS.Client.Toolkit.Primitives.LayerItemViewModel>();
                foreach (var x in lgnd.LayerItems)                  // fix labels
                {
                    var vl = new VLayer(x.Layer);
                    x.Label = vl.lyrName;
                    swap.Add(x);
                }
                lgnd.LayerItems.Clear();
                for (int ind = swap.Count; ind > 0; ind--)
                {
                    var x = swap[ind - 1];
                    lgnd.LayerItems.Insert(swap.Count - ind, x);
                }
            }             // fix legend

            if (cbLegend.IsChecked == false)
            {
                // legend off
                this.legend1.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
            {
                // legend on
                this.legend1.Visibility = System.Windows.Visibility.Visible;
                // legend width tailored
                log(string.Format("PrintForm.updateLayout: legend W {0}, map W {1}, prnA W {2}; legend ActW {3}, map ActW {4}",
                                  legend1.Width, Map.Width, printableArea.Width, legend1.ActualWidth, Map.ActualWidth));
                double mw = this.Map.ActualWidth;
                if (double.IsNaN(mw))
                {
                    mw = printableArea.Width;
                }
                if (double.IsNaN(this.legend1.ActualWidth) ||
                    this.legend1.ActualWidth > (mw / 4))
                {
                    this.legend1.Width = mw / 4;
                }
            }             // show legend

            if (cbComment.IsChecked == false)
            {
                // comment off
                this.tbDescription.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
            {
                // comment on
                this.tbDescription.Visibility = System.Windows.Visibility.Visible;
            }
        }         // public void updateLayout()
Example #18
0
        }         // public void log(String txt)

        /// <summary>
        /// Fires when the drawing action is complete.
        /// Issues an identify operation using the drawn geometry.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DrawComplete(object sender, DrawEventArgs e)
        {
            log("VIdentify.DrawComplete");
            var map        = MapApplication.Current.Map;
            var clickPoint = e.Geometry as MapPoint;

            var identifyParams = new IdentifyParameters()
            {
                Geometry         = clickPoint.Clone(),
                MapExtent        = map.Extent.Clone(),
                LayerOption      = LayerOption.visible,
                Tolerance        = 2,          // default = 2
                SpatialReference = map.SpatialReference.Clone(),
                Height           = (int)map.ActualHeight,
                Width            = (int)map.ActualWidth,
                ReturnGeometry   = false
            };

            // get layer url

            /*
             * для линейных слоев иногда ничего не находит
             * Возможно потому, что надо выбирать толеранец поболе?
             * http://rngis.algis.com/ArcGIS/rest/services/mesh/MapServer/identify?geometryType=esriGeometryPoint&geometry=%7b%22x%22%3a8678329.72666139%2c%22y%22%3a6793256.24367089%2c%22spatialReference%22%3a%7b%22wkid%22%3a102100%7d%7d&returnGeometry=true&sr=102100&imageDisplay=0%2c0%2c96&layers=visible&tolerance=2&mapExtent=-7380211.5%2c2988666.0221519%2c12657297%2c12246502.2278481&f=json&
             */
            var lyr = new VLayer(MapApplication.Current.SelectedLayer);

            srvUrl = lyr.getAGSMapServiceUrl();
            if (srvUrl == "")
            {
                log(string.Format("VIdentify.DrawComplete, layer has wrong type [{0}]", lyr.lyrType));
                identifyDialog.DataDisplayTitleBottom.Text =
                    string.Format("Ошибка, выделенный слой [тип {0}] не поддерживает операцию Identify, ", lyr.lyrType);
                return;
            }
            identifyTask.Url      = srvUrl;
            identifyTask.ProxyURL = lyr.proxy;
            //identifyTask.Token = "";
            log(string.Format("VIdentify.DrawComplete, ask [{0}]", srvUrl));

            // clear result window
            DataItems.Clear();
            // say "wait for server..."
            identifyDialog.DataDisplayTitleBottom.Text = "Ждем ответа от сервера...";

            if (identifyTask.IsBusy)
            {
                identifyTask.CancelAsync();
            }
            identifyTask.ExecuteAsync(identifyParams);

            var graphicsLayer = map.Layers["IdentifyResultsLayer"]
                                as GraphicsLayer;

            if (graphicsLayer == null)
            {
                graphicsLayer = createResultsLayer();
                map.Layers.Add(graphicsLayer);
                MapApplication.Current.SelectedLayer = lyr.lyr;
            }
            else
            {
                graphicsLayer.ClearGraphics();
            }

            Graphic graphic = new Graphic()
            {
                Geometry = clickPoint
            };

            graphicsLayer.Graphics.Add(graphic);
        }         // private void DrawComplete(object sender, DrawEventArgs e)
Example #19
0
        }         // public string getRLContent()

        public string getRLContent(GraphicsLayer gl)
        {
            // serialize GraphicsLayer
            log("getRLContent(gl), ...");
            return(VLayer.getContent(gl));
        }         // public string getRLContent(GraphicsLayer gl)
Example #20
0
        }         // public static GraphicsLayer makeRLLayer(Map map, string layerID, string layerName)

        /// <summary>
        /// Create RL layer.
        /// </summary>
        /// <param name="layerID"></param>
        /// <param name="layerName"></param>
        /// <returns></returns>
        public static GraphicsLayer createRLLayer(string layerID, string layerName)
        {
            return(VLayer.makeRLLayer(null, layerID, layerName));
        }         // public static GraphicsLayer createRLLayer(Map map, string layerID, string layerName)
Example #21
0
        }         // public static void restoreRLGraphics(GraphicsLayer gl, string xmlContent)

        /// <summary>
        /// Create and add to map a simple graphics layer or return existed
        /// </summary>
        /// <returns>redline layer</returns>
        public static GraphicsLayer makeRLLayer(Map map, string layerID, string layerName)
        {
            return(VLayer.makeRLLayer(map, layerID, layerName));
        }         // public static GraphicsLayer makeRLLayer(Map map, string layerID, string layerName)