Пример #1
0
        private void AddPushpin(string deviceID, Windows.Devices.Geolocation.BasicGeoposition position)
        {
            var mapDevices = new List <MapElement>();

            Windows.Devices.Geolocation.BasicGeoposition snPosition = new Windows.Devices.Geolocation.BasicGeoposition {
                Latitude = position.Latitude, Longitude = position.Longitude
            };

            var pushpin = new MapIcon
            {
                Location = new Geopoint(snPosition),
                NormalizedAnchorPoint = new Point(0.5, 1),
                ZIndex = 1000,
                Tag    = "NEW",
                Title  = deviceID,
                Image  = RandomAccessStreamReference.CreateFromUri(new Uri(resourceLoader.GetString("Map_Pushpin_New"))),
            };

            mapDevices.Add(pushpin);

            var mapDevicesLayer = new MapElementsLayer
            {
                ZIndex      = 1,
                MapElements = mapDevices
            };

            MapLayers.Add(mapDevicesLayer);
            CTRL_Map_Main.Layers.Add(mapDevicesLayer);
        }
Пример #2
0
        public void AddLayer(ILayer layer)
        {
            MapLayer mapLayer = layer as MapLayer;

            if (mapLayer != null)
            {
                if (mapLayer.Width != mapWidth || mapLayer.Height != mapHeight)
                {
                    throw new Exception("Map layer size exception");
                }

                MapLayers.Add(layer);
            }
        }
Пример #3
0
    private static void CreateVisualisations()
    {
        MapLayers.Add(new MapVisualisation(
                          world,
                          Keyboard.Key.F,
                          true,
                          Updaters.FitnessImage
                          ));
        MapLayers.Add(new MapVisualisation(
                          world,
                          Keyboard.Key.F,
                          true,
                          Updaters.HeightShadeImage
                          ));
        MapLayers.Add(new MapVisualisation(
                          world,
                          Keyboard.Key.B,
                          true,
                          Updaters.IsolineImage
                          ));

        MapLayers.Add(new MapVisualisation(
                          world,
                          Keyboard.Key.T,
                          false,
                          Updaters.TempImage
                          ));

        MapLayers.Add(new MapVisualisation(
                          world,
                          Keyboard.Key.M,
                          false,
                          Updaters.MoistureImage
                          ));

        MapLayers.Add(new MapVisualisation(
                          world,
                          Keyboard.Key.I,
                          false,
                          Updaters.IslandImage
                          ));

        MapLayers.Add(new MapVisualisation(
                          world,
                          Keyboard.Key.P,
                          false,
                          Updaters.PressureImage
                          ));
    }
Пример #4
0
 private void AddPinToMap(SimpleLocation location)
 {
     MapLayers.Add(new MapElementsLayer
     {
         ZIndex      = 1,
         MapElements = new List <MapElement>
         {
             new MapIcon
             {
                 Location = new Geopoint(location.Position),
                 Title    = location.Name
             }
         }
     });
 }
Пример #5
0
        private async void AddMapElements_Projects(bool centerOnTarget)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
            {
                Coordinates     = new List <Windows.Devices.Geolocation.BasicGeoposition>();
                var zindex      = 1000;
                var strokeColor = ColorHandler.FromHex(Project.FillColor);
                var mapProjects = new List <MapElement>();

                Coordinates.AddRange(GeoPositionConversor.Parse(Project.Coordinates));

                var mapPolygon = new MapPolygon
                {
                    Tag             = Project.Name,
                    Path            = new Geopath(Coordinates),
                    ZIndex          = zindex,
                    FillColor       = FillColor,
                    StrokeColor     = strokeColor,
                    StrokeThickness = 3,
                    StrokeDashed    = false,
                };

                mapProjects.Add(mapPolygon);


                var mapProjectsLayer = new MapElementsLayer
                {
                    ZIndex      = zindex,
                    MapElements = mapProjects
                };

                MapLayers.Add(mapProjectsLayer);
                CTRL_Map_Main.Layers.Add(mapProjectsLayer);
            });

            if (centerOnTarget)
            {
                await CTRL_Map_Main.TrySetViewBoundsAsync(GeoboundingBox.TryCompute(Coordinates), new Thickness(200), MapAnimationKind.Bow);
            }
        }
Пример #6
0
        private async Task <bool> DrawPushpins(List <Twin> twins)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
            {
                var mapDevices = new List <MapElement>();

                foreach (var device in twins)
                {
                    var position = device.DevicePosition;

                    var pushpin = new MapIcon
                    {
                        Location = new Geopoint(GeoPositionConversor.Parse(position)),
                        NormalizedAnchorPoint = new Point(0.5, 1),
                        ZIndex = 0,
                        Tag    = "EXISTING",
                        Title  = device.DeviceID,
                        Image  = RandomAccessStreamReference.CreateFromUri(new Uri(resourceLoader.GetString("Map_Pushpin_Default")))
                    };

                    mapDevices.Add(pushpin);

                    //ExistingDeviceMapIcons.Add(pushpin);
                }

                var mapDevicesLayer = new MapElementsLayer
                {
                    ZIndex      = 1,
                    MapElements = mapDevices
                };

                MapLayers.Add(mapDevicesLayer);
                CTRL_Map_Main.Layers.Add(mapDevicesLayer);
            });

            return(true);
        }
Пример #7
0
        private void Stops_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            // If we are running a switch command, don't do anything
            if (isSwitchCommandRunning)
            {
                // Perform re-routing mechanism here since we swapped
                // the indexes of our stops
                PerformReroutingOfPoints();
                return;
            }

            // If we have no more stops, clear our map layers and reset our
            // center to our default position
            if (Stops.Count == 0)
            {
                // Remove any pushpins
                MapLayers.Clear();

                // Set Center to default position
                Center = new Geopoint(defaultPosition);
                return;
            }

            // For old items, remove the map elements, for new items, add them
            if (e.OldItems != null)
            {
                foreach (var old in e.OldItems)
                {
                    StopModel stop = old as StopModel;

                    // Remove our removed stop from the map elements of its corresponding
                    // pushpin
                    if (mapElements.Any(x => ((MapIcon)x).Title == stop.Name))
                    {
                        mapElements.Remove(mapElements.Where(x => ((MapIcon)x).Title == stop.Name).First());
                    }
                }
            }

            if (e.NewItems != null)
            {
                foreach (var newItem in e.NewItems)
                {
                    StopModel stop         = newItem as StopModel;
                    var       stopGeopoint = new Geopoint(
                        new BasicGeoposition()
                    {
                        Latitude  = decimal.ToDouble(stop.Latitude),
                        Longitude = decimal.ToDouble(stop.Longitude)
                    });

                    var poi = new MapIcon
                    {
                        Location = stopGeopoint,
                        NormalizedAnchorPoint = new Point(0.5, 1.0),
                        Title  = stop.Name,
                        ZIndex = 0
                    };

                    // Add newly created pushpin to our map elements
                    mapElements.Add(poi);
                }
            }

            // Recreate the layer
            var layer = new MapElementsLayer
            {
                ZIndex      = 1,
                MapElements = mapElements
            };

            MapLayers.Clear();
            MapLayers.Add(layer);

            // Perform re-routing mechanism
            PerformReroutingOfPoints();
        }
        public BufferToolConfig(string anXMLProfile)
        {
            // Open XML
            myFileFuncs   = new FileFunctions();
            myStringFuncs = new StringFunctions();
            string strXMLFile = anXMLProfile; // The user has specified this and we've checked it exists.

            foundXML  = true;                 // In this version we have already checked that it exists.
            loadedXML = true;

            // Go forth and obtain all information.
            // Firstly, read the file.
            if (foundXML)
            {
                XmlDocument xmlConfig = new XmlDocument();
                try
                {
                    xmlConfig.Load(strXMLFile);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error in XML file; cannot load. System error message: " + ex.Message, "XML Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    loadedXML = false;
                    return;
                }
                string  strRawText;
                XmlNode currNode = xmlConfig.DocumentElement.FirstChild; // This gets us the DataBuffer.
                xmlDataBuffer = (XmlElement)currNode;

                // XML loaded successfully; get all of the detail in the Config object.

                try
                {
                    logFilePath = xmlDataBuffer["LogFilePath"].InnerText;
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'LogFilePath' in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    loadedXML = false;
                    return;
                }

                try
                {
                    defaultClearLog = false;
                    string strDefaultClearLogFile = xmlDataBuffer["DefaultClearLogFile"].InnerText;
                    if (strDefaultClearLogFile == "Yes")
                    {
                        defaultClearLog = true;
                    }
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'DefaultClearLogFile' in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    loadedXML = false;
                    return;
                }

                try
                {
                    defaultPath = xmlDataBuffer["DefaultPath"].InnerText;
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'DefaultPath' in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    loadedXML = false;
                    return;
                }

                try
                {
                    layerPath = xmlDataBuffer["LayerPath"].InnerText;
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'LayerPath' in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    loadedXML = false;
                    return;
                }

                //try
                //{
                //    tempFilePath = xmlDataBuffer["TempFilePath"].InnerText;
                //}
                //catch
                //{
                //    MessageBox.Show("Could not locate the item 'TempFilePath' in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //    loadedXML = false;
                //    return;
                //}

                // Locate the GIS Layers.
                XmlElement MapLayerCollection = null;
                try
                {
                    MapLayerCollection = xmlDataBuffer["InLayers"];
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'InLayers' in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    loadedXML = false;
                    return;
                }
                // Now cycle through them.
                foreach (XmlNode aNode in MapLayerCollection)
                {
                    MapLayer thisLayer = new MapLayer();
                    string   strName   = aNode.Name;
                    strName = strName.Replace("_", " "); // Replace any underscores with spaces for better display.
                    thisLayer.DisplayName = strName;

                    try
                    {
                        thisLayer.LayerName = aNode["LayerName"].InnerText;
                    }
                    catch
                    {
                        MessageBox.Show("Could not locate the item 'LayerName' for map layer " + thisLayer.DisplayName + " in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        loadedXML = false;
                        return;
                    }

                    // Sort out the columns. This is pretty involved.
                    try
                    {
                        InputColumns theInputColumns = new InputColumns();
                        string       strColumnList   = aNode["Columns"].InnerText;
                        // We have the format (inputColumn1 "outputColumn1", inputColumn2, inputColumn3, "outputColumn3", "inputText" "outputColumn4", ...)
                        // Firstly split the list at the commas.
                        List <string> strColumnDefList = strColumnList.Split(',').ToList();
                        // Go through these and sort out what's what.
                        foreach (string aColumnDef in strColumnDefList)
                        {
                            InputColumn thisInputColumn = new InputColumn();
                            // Check if the first character is a "\"". If so, we deal with it slightly differently.
                            string        strColumnDef = aColumnDef.Trim(); // Remove any spaces.
                            List <string> strColItems  = new List <string>();
                            if (strColumnDef.Substring(0, 1) == "\"")
                            {
                                // find the first entry.
                                int position; // First character is a '"' so we don't want to find that.
                                int start = 0;
                                // Extract the items from the string.
                                position = strColumnDef.IndexOf('\"', start + 1);
                                if (position == 0)
                                {
                                    position = 1;
                                }
                                if (position > 0)
                                {
                                    string strResult = strColumnDef.Substring(start, position - start + 1).Trim();
                                    strColItems.Add(strResult);
                                    //start = position;
                                }
                                // The second item is split by string.
                                List <string> strAllEntries = strColumnDef.Split(' ').ToList();
                                string        theEntry      = strAllEntries[strAllEntries.Count - 1]; // Last entry.
                                strColItems.Add(theEntry.Trim('"'));                                  // Trim quotes if they are there.
                            }
                            else
                            {
                                // Split at space.
                                strColItems = strColumnDef.Split(' ').ToList();
                            }
                            // Test to see how many elements.
                            if (strColItems.Count == 1)
                            {
                                thisInputColumn.InputName  = strColItems[0].Trim();
                                thisInputColumn.OutputName = strColItems[0].Trim(); // They are both the same.
                            }
                            else if (strColItems.Count == 2)
                            {
                                thisInputColumn.InputName  = strColItems[0].Trim();
                                thisInputColumn.OutputName = strColItems[1].Trim('"'); // Trim quotes if they are there
                            }
                            else
                            {
                                // More than two elements; that's not right.
                                MessageBox.Show("The column entry " + strColItems[0] + " for map layer " + thisLayer.DisplayName + " in the XML file contains " + strColItems.Count.ToString() + " items. It should only have two.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                loadedXML = false;
                                return;
                            }

                            theInputColumns.Add(thisInputColumn);
                        }
                        thisLayer.InputColumns = theInputColumns;
                    }
                    catch
                    {
                        MessageBox.Show("Could not locate the item 'Columns' for map layer " + thisLayer.DisplayName + " in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        loadedXML = false;
                        return;
                    }

                    try
                    {
                        thisLayer.WhereClause = aNode["WhereClause"].InnerText;
                    }
                    catch
                    {
                        MessageBox.Show("Could not locate the item 'WhereClause' for map layer " + thisLayer.DisplayName + " in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        loadedXML = false;
                        return;
                    }

                    //try
                    //{
                    //    thisLayer.SortOrder = aNode["SortOrder"].InnerText;
                    //}
                    //catch
                    //{
                    //    MessageBox.Show("Could not locate the item 'SortOrder' for map layer " + thisLayer.DisplayName + " in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //    loadedXML = false;
                    //    return;
                    //}

                    try
                    {
                        int  a;
                        bool blResult = int.TryParse(aNode["BufferSize"].InnerText, out a);
                        if (blResult)
                        {
                            thisLayer.BufferSize = a;
                        }
                        else
                        {
                            MessageBox.Show("Could not locate the item 'BufferSize' for map layer " + thisLayer.DisplayName + " in the XML file, or the item is not an integer", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            loadedXML = false;
                            return;
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Could not locate the item 'BufferSize' for map layer " + thisLayer.DisplayName + " in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        loadedXML = false;
                        return;
                    }

                    try
                    {
                        int  a;
                        bool blResult = int.TryParse(aNode["DissolveSize"].InnerText, out a);
                        if (blResult)
                        {
                            thisLayer.DissolveSize = a;
                        }
                        else
                        {
                            MessageBox.Show("Could not locate the item 'DissolveSize' for map layer " + thisLayer.DisplayName + " in the XML file, or the item is not an integer", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            loadedXML = false;
                            return;
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Could not locate the item 'BufferSize' for map layer " + thisLayer.DisplayName + " in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        loadedXML = false;
                        return;
                    }


                    // if everything is correct, add to the list.
                    if (loadedXML)
                    {
                        inputLayers.Add(thisLayer);
                    }
                }

                // Now get the output layer definition
                XmlElement OutLayerDef = null;
                try
                {
                    OutLayerDef = xmlDataBuffer["OutLayer"];
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'OutLayer' in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    loadedXML = false;
                    return;
                }

                // Get to the columns
                XmlNode ColumnNode = null;
                try
                {
                    ColumnNode = OutLayerDef["Columns"];
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'Columns' for the OutLayer in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    loadedXML = false;
                    return;
                }


                // Get all the columns.
                OutputColumns theOutputColumns = new OutputColumns();
                foreach (XmlNode aNode in ColumnNode)
                {
                    OutputColumn thisColumn = new OutputColumn();
                    thisColumn.ColumnName = aNode.Name;

                    try
                    {
                        thisColumn.ColumnName = aNode["ColumnName"].InnerText;
                    }
                    catch
                    {
                        MessageBox.Show("Could not locate the item 'ColumnName' for output column " + thisColumn.ColumnTag + " in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        loadedXML = false;
                        return;
                    }

                    // List of accepted types.
                    List <string> ColumnTypes = new List <string>()
                    {
                        "key", "cluster", "first", "common", "min", "max", "range"
                    };
                    try
                    {
                        strRawText = aNode["ColumnType"].InnerText.ToLower();
                        if (ColumnTypes.Contains(strRawText))
                        {
                            thisColumn.ColumnType = strRawText; // Always lower case.

                            // Now also add this type to the relevant output column in ALL the input layers.
                            foreach (MapLayer aLayer in inputLayers)
                            {
                                // Find the output column with the same name.
                                bool blFoundIt = false;
                                foreach (InputColumn aColumn in aLayer.InputColumns)
                                {
                                    if (aColumn.OutputName == thisColumn.ColumnName)
                                    {
                                        aColumn.ColumnType = strRawText;
                                        blFoundIt          = true;
                                        break;
                                    }
                                }
                                if (!blFoundIt)
                                {
                                    MessageBox.Show("The output column " + thisColumn.ColumnName + " was not found for map layer " + aLayer.LayerName, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    loadedXML = false;
                                    return;
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("The value for 'ColumnType' for output column " + thisColumn.ColumnTag + " in the XML file is not valid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            loadedXML = false;
                            return;
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Could not locate the item 'ColumnType' for output column " + thisColumn.ColumnTag + " in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        loadedXML = false;
                        return;
                    }

                    List <string> FieldTypes = new List <string>()
                    {
                        "TEXT", "FLOAT", "DOUBLE", "SHORT", "LONG", "DATE"
                    };
                    try
                    {
                        strRawText = aNode["FieldType"].InnerText.ToUpper();
                        if (FieldTypes.Contains(strRawText))
                        {
                            thisColumn.FieldType = strRawText; // Always upper case.

                            // Now also add this type to the relevant output column in ALL the input layers.
                            foreach (MapLayer aLayer in inputLayers)
                            {
                                // Find the output column with the same name.
                                bool blFoundIt = false;
                                foreach (InputColumn aColumn in aLayer.InputColumns)
                                {
                                    if (aColumn.OutputName == thisColumn.ColumnName)
                                    {
                                        aColumn.FieldType = strRawText;
                                        blFoundIt         = true;
                                        break;
                                    }
                                }
                                if (!blFoundIt)
                                {
                                    MessageBox.Show("The output column " + thisColumn.ColumnName + " was not found for map layer " + aLayer.LayerName, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    loadedXML = false;
                                    return;
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("The value for 'FieldType' for output column " + thisColumn.ColumnTag + " in the XML file is not valid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            loadedXML = false;
                            return;
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Could not locate the item 'ColumnType' for output column " + thisColumn.ColumnTag + " in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        loadedXML = false;
                        return;
                    }

                    try
                    {
                        int  a;
                        bool blResult = int.TryParse(aNode["ColumnLength"].InnerText, out a);
                        if (blResult)
                        {
                            thisColumn.ColumnLength = a;

                            // Now also add this length to the relevant output column in ALL the input layers.
                            foreach (MapLayer aLayer in inputLayers)
                            {
                                // Find the output column with the same name.
                                bool blFoundIt = false;
                                foreach (InputColumn aColumn in aLayer.InputColumns)
                                {
                                    if (aColumn.OutputName == thisColumn.ColumnName)
                                    {
                                        aColumn.FieldLength = a;
                                        blFoundIt           = true;
                                        break;
                                    }
                                }
                                if (!blFoundIt)
                                {
                                    MessageBox.Show("The output column " + thisColumn.ColumnName + " was not found for map layer " + aLayer.LayerName, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    loadedXML = false;
                                    return;
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("Could not locate the item 'ColumnLength' for map layer " + thisColumn.ColumnTag + " in the XML file, or the item is not an integer", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            loadedXML = false;
                            return;
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Could not locate the item 'ColumnLength' for map layer " + thisColumn.ColumnTag + " in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        loadedXML = false;
                        return;
                    }

                    if (loadedXML)
                    {
                        theOutputColumns.Add(thisColumn);
                    }
                }

                // Add the columns to the output layer definition
                outputLayer.OutputColumns = theOutputColumns;

                // Get the rest of the output layer definition
                try
                {
                    outputLayer.LayerPath = layerPath + @"\";
                    outputLayer.LayerFile = OutLayerDef["LayerFile"].InnerText;
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'LayerFile' for the OutLayer in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    loadedXML = false;
                    return;
                }

                try
                {
                    List <string> OutputFormatList = new List <string>()
                    {
                        "shape", "gdb"
                    };
                    strRawText = OutLayerDef["OutputFormat"].InnerText.ToLower();
                    if (OutputFormatList.Contains(strRawText))
                    {
                        outputLayer.Format = strRawText;
                    }
                    else
                    {
                        MessageBox.Show("The entry for the output layer's OutputFormat in the XML file is not valid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        loadedXML = false;
                    }
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'OutputFormat' for the OutLayer in the XML file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    loadedXML = false;
                    return;
                }
            }
            else
            {
                foundXML = false; // this has to be checked first; all other properties are empty.
            }
        }