XAML
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" x:Class="selptpgn.MainPage"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Canvas x:Name="LayoutRoot" Background="White" Margin="10, 10,10,-100">
<Grid Visibility="Collapsed" x:Name="gd1" Canvas.ZIndex="5" Height="30" Canvas.Left="1" Canvas.Top="1" Width="100" Background="#FFE9EC8F"/>
<Button Visibility="Collapsed" Click="ptQry" Canvas.ZIndex="5" x:Name="BtptQry" Content="Point Query" Canvas.Left="10" Canvas.Top="10" Width="91"/>
<Button Visibility="Collapsed" Click="lnQry" Canvas.ZIndex="5" x:Name="BtlnQry" Content="Line Query" Canvas.Left="10" Canvas.Top="37" Width="91"/>
<Button Visibility="Collapsed" Click="recQry" Canvas.ZIndex="5" x:Name="BtRecQry" Content="Rec Query" Canvas.Left="10" Canvas.Top="64" Width="91"/>
<Button Visibility="Collapsed" Click="pgnQry" Canvas.ZIndex="5" x:Name="BtPgnQry" Content="Polygon Query" Canvas.Left="10" Canvas.Top="91" Width="91"/>
<sdk:DataGrid x:Name="dg1" Canvas.ZIndex="5" Height="100" Canvas.Left="98" Canvas.Top="280" Width="397"/>
</Canvas>
</UserControl>
CS
using System.Linq;
using System.Net;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Xml.Linq;
using SGWSilverlightAPI.Interface;
using SGWSilverlightAPI.Map;
using SGWSilverlightAPI.Layer;
using SGWSilverlightAPI.Geometry;
using SGWPolygon = SGWSilverlightAPI.Geometry.Polygon;
using SGWPoint = SGWSilverlightAPI.Geometry.Point;
using System.IO;
using System.Windows.Media.Effects;
using SGWSilverlightAPI.Navigate;
using System;
namespace selptpgn
{
public partial class MainPage : UserControl
{
MapBase m_pMapBase = null;
System.Windows.Shapes.Path myPath = null;
public MainPage()
{
InitializeComponent();
myPath = new System.Windows.Shapes.Path();
m_pMapBase = new MapBase();
m_pMapBase.Width = 600;
m_pMapBase.Height = 400;
m_pMapBase.Background = new SolidColorBrush(Colors.Black);
LayoutRoot.Children.Add(m_pMapBase);
MapLayer pLayer = new MapLayer();
pLayer.ResourcePath = "http://sgs.supergeo.com.tw/selpgnpt/Agent.aspx";
pLayer.OnLayerLoaded += OnLayerLoaded;
m_pMapBase.AddLayer(pLayer);
m_pMapBase.MouseLeftButtonUp += idfy;
}
private void idfy(object sender, MouseButtonEventArgs e)
{
for (int i = m_pMapBase.Children.Count - 1; i > 0; i--)
{
m_pMapBase.Children.RemoveAt(i);
}
List<ILayer> pLayers = m_pMapBase.Layers;
MapLayer pLayer = pLayers[0] as MapLayer;
List<innerLayer> pLayers2 = pLayer.Layers;
innerLayer pLayer2 = pLayers2[1];
SGWPoint pt1 = m_pMapBase.CursorPosition(e);
scrPt = pt1;
SGWPoint pt2 = m_pMapBase.ToMapPoint(pt1.X, pt1.Y);
curPt = pt2;
pLayer2.ExecuteQuery(pt2.ExportToWKT(), true, sendLnQry, null);
}
SGWPoint curPt = null;
SGWPoint scrPt = null;
void m_pMapBase_MouseMove(object sender, MouseEventArgs e)
{
List<ILayer> pLayers = m_pMapBase.Layers;
MapLayer pLayer = pLayers[0] as MapLayer;
List<innerLayer> pLayers2 = pLayer.Layers;
innerLayer pLayer2 = pLayers2[0];
SGWPoint pt1 = m_pMapBase.CursorPosition(e);
scrPt = pt1;
SGWPoint pt2 = m_pMapBase.ToMapPoint(pt1.X, pt1.Y);
curPt = pt2;
SGWPolygon pgn = new SGWPolygon();
for (int a = 0; a <= 360; a += 30)
{
double xp = pt2.X + Math.Sin(a * Math.PI / 180.0) * 0.2;
double yp = pt2.Y + Math.Cos(a * Math.PI / 180.0) * 0.2;
pgn.ExteriorRing.InsertPoint(-1, new SGWPoint(xp, yp));
}
pLayer2.ExecuteQuery(pgn.ExportToWKT(), true, QuerySucceed, null);
m_pMapBase.MouseMove -= m_pMapBase_MouseMove;
}
private void OnLayerLoaded(object sender, EventArgs e)
{
Envelope pExt = m_pMapBase.Layers[0].Extent;
ITransformation pTrans = new ScaleTransformation(1);
m_pMapBase.Transformation = pTrans;
Envelope pext1 = new Envelope(120.265316, 23.645119, 120.276890, 23.637143);
m_pMapBase.ZoomMapTo(pext1);
m_pMapBase.RefreshMap(true);
}
private void getCtyName(XDocument pDoc)
{
this.Dispatcher.BeginInvoke(() =>
{
foreach (XElement pSubElem in pDoc.Descendants("Feature"))
{
XElement pValElem = pSubElem.Element("Values");
foreach (XElement pVal in pValElem.Elements())
{
}
XElement pGeomElem = pSubElem.Element("Geometry");
if (pGeomElem != null)
{
string sWKT = pGeomElem.Value;
SGWPoint po = new SGWPoint();
LineString ls = new LineString();
SGWPolygon pg = new SGWPolygon();
if (sWKT.StartsWith("POINT"))
{
po.ImportFromWKT(pGeomElem.Value);
XElement pValues = pSubElem.Element("Values");
XElement pValue1 = pValues.Element("NAME");
gd1.Children.Clear();
TextBlock tb1 = new TextBlock();
tb1.Text = pValue1.Value;
gd1.Children.Add(tb1);
Canvas.SetLeft(gd1, scrPt.X - 40);
Canvas.SetTop(gd1, scrPt.Y - 10);
gd1.Visibility = System.Windows.Visibility.Visible;
}
else if (sWKT.StartsWith("LINESTRING"))
{
ls.ImportFromWKT(pGeomElem.Value);
MessageBox.Show(ls.ExportToWKT());
}
else if (sWKT.StartsWith("POLYGON"))
{
pg.ImportFromWKT(pGeomElem.Value);
XElement pValues = pSubElem.Element("Values");
XElement pValue1 = pValues.Element("name");
}
}
}
});
}
private void pick1(object sender, SelectionChangedEventArgs e)
{
//locate to the selected province
List<ILayer> pLayers = m_pMapBase.Layers;
CachedLayer pLayer = pLayers[0] as CachedLayer;
List<innerLayer> pLayers2 = pLayer.Layers;
innerLayer pLayer2 = pLayers2[0];
}
PointCollection myPtC = null;
private void QuerySucceed(XDocument pDoc)
{
foreach (XElement pSubElem in pDoc.Descendants("Feature"))
{
XElement pGeomElem = pSubElem.Element("Geometry");
if (pGeomElem != null)
{
string sWKT = pGeomElem.Value;
SGWPolygon pg = new SGWPolygon();
pg.ImportFromWKT(pGeomElem.Value);
Spg = pg;
XElement pValues = pSubElem.Element("Values");
XElement pValue1 = pValues.Element("name");
XElement pValue2 = pValues.Element("name_alt");
XElement pValue3 = pValues.Element("type");
XElement pValue4 = pValues.Element("Shape_Area");
pg.ImportFromWKT(pGeomElem.Value);
//draw the selected polygon
SolidColorBrush b1 = new SolidColorBrush();
b1.Color = Colors.Blue;
myPath.Stroke = b1;
DropShadowEffect ef1 = new DropShadowEffect();
ef1.Color = Colors.Black;
ef1.Direction = 45;
ef1.ShadowDepth = 5;
ef1.BlurRadius = 6;
ef1.Opacity = 0.3;
SolidColorBrush b2 = new SolidColorBrush();
b2.Color = Colors.Yellow;
b2.Opacity = 0.5;
myPath.Fill = b2;
myPath.Effect = ef1;
myPath.StrokeThickness = 2;
ColorAnimation ca1 = new ColorAnimation();
// Create a duration of 5 seconds.
Duration duration = new Duration(TimeSpan.FromSeconds(0.2));
ca1.Duration = duration;
Storyboard sb = new Storyboard();
sb.Duration = duration;
sb.Children.Add(ca1);
ca1.From = Colors.Red;
ca1.To = Colors.Yellow;
sb.AutoReverse = true;
sb.RepeatBehavior = RepeatBehavior.Forever;
Storyboard.SetTarget(ca1, b2);
Storyboard.SetTargetProperty(ca1, new PropertyPath("Stroke.Color"));
// Make the Storyboard a resource.
LayoutRoot.Resources.Remove("unique_id");
LayoutRoot.Resources.Add("unique_id", sb);
// Begin the animation.
sb.Begin();
myPtC = new PointCollection();
SGWPoint Spt = new SGWPoint();
SGWPoint Spt2 = new SGWPoint();
for (int i = 0; i < pg.ExteriorRing.PointCount - 1; i++)
{
Spt = pg.ExteriorRing.GetPoint(i);
Spt2 = m_pMapBase.FromMapPoint(Spt.X, Spt.Y);
myPtC.Add(new System.Windows.Point(Spt2.X, Spt2.Y));
}
PolyLineSegment myLineSegment = new PolyLineSegment();
myLineSegment.Points = myPtC;
PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
myPathSegmentCollection.Add(myLineSegment);
PathFigure myPathFigure = new PathFigure();
myPathFigure.StartPoint = myPtC[0];
myPathFigure.Segments = myPathSegmentCollection;
PathFigureCollection myPathFigureCollection = new PathFigureCollection();
myPathFigureCollection.Add(myPathFigure);
PathGeometry myPathGeometry = new PathGeometry();
myPathGeometry.Figures = myPathFigureCollection;
myPath.Data = myPathGeometry;
m_pMapBase.Children.Remove(myPath);
m_pMapBase.Children.Add(myPath);
m_pMapBase.RefreshMap(true);
}
}
}
SGWPolygon Spg = null;
private void UU()
{
if (Spg == null || myPath == null)
return;
PointCollection myPtC = new PointCollection();
SGWPoint Spt = new SGWPoint();
SGWPoint Spt2 = new SGWPoint();
for (int i = 0; i < Spg.ExteriorRing.PointCount - 1; i++)
{
Spt = Spg.ExteriorRing.GetPoint(i);
Spt2 = m_pMapBase.FromMapPoint(Spt.X, Spt.Y);
myPtC.Add(new System.Windows.Point(Spt2.X, Spt2.Y));
}
PolyLineSegment myLineSegment = new PolyLineSegment();
myLineSegment.Points = myPtC;
PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
myPathSegmentCollection.Add(myLineSegment);
PathFigure myPathFigure = new PathFigure();
myPathFigure.StartPoint = myPtC[0];
myPathFigure.Segments = myPathSegmentCollection;
PathFigureCollection myPathFigureCollection = new PathFigureCollection();
myPathFigureCollection.Add(myPathFigure);
PathGeometry myPathGeometry = new PathGeometry();
myPathGeometry.Figures = myPathFigureCollection;
myPath.Data = myPathGeometry;
}
private void ptQry(object sender, RoutedEventArgs e)
{
//point query
m_pMapBase.MouseLeftButtonUp += m_pMapBase_MouseLeftButtonUp;
}
void m_pMapBase_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
//point query
List<ILayer> pLayers = m_pMapBase.Layers;
MapLayer pLayer = pLayers[0] as MapLayer;
List<innerLayer> pLayers2 = pLayer.Layers;
innerLayer pLayer2 = pLayers2[0];
SGWPoint pt1 = m_pMapBase.CursorPosition(e);
scrPt = pt1;
SGWPoint pt2 = m_pMapBase.ToMapPoint(pt1.X, pt1.Y);
curPt = pt2;
pLayer2.ExecuteQuery(pt2.ExportToWKT(), true, QuerySucceed, null);
m_pMapBase.MouseLeftButtonUp -= m_pMapBase_MouseLeftButtonUp;
}
System.Windows.Shapes.Path myPathLn = null;
PointCollection lnptC = null;
PolyLineSegment myLineSegment = null;
PathSegmentCollection myPathSegmentCollection = null;
PathFigureCollection myPathFigureCollection = null;
PathFigure myPathFigure = null;
PathGeometry myPathGeometry = null;
LineString tLnS = null;
System.Windows.Shapes.Polygon Path2 = null;
System.Windows.Shapes.Polygon pg1 = null;
private void lnQry(object sender, RoutedEventArgs e)
{
m_pMapBase.MouseLeftButtonDown += drawLn;
m_pMapBase.Children.Remove(myPathLn);
for (int i = m_pMapBase.Children.Count - 1; i > 0; i--)
{
m_pMapBase.Children.RemoveAt(i);
}
m_pMapBase.SelectMapTool(null);
lnptC = new PointCollection();
myLineSegment = new PolyLineSegment();
myPathSegmentCollection = new PathSegmentCollection();
myPathFigureCollection = new PathFigureCollection();
myPathFigure = new PathFigure();
myPathGeometry = new PathGeometry();
myPathLn = new System.Windows.Shapes.Path();
SolidColorBrush b1 = new SolidColorBrush();
b1.Color = Colors.Red;
myPathLn.Stroke = b1;
myPathLn.StrokeThickness = 3;
m_pMapBase.Children.Remove(myPathLn);
m_pMapBase.Children.Add(myPathLn);
}
string str1 = ""; //user query line string
private void drawLn(object sender, MouseButtonEventArgs e)
{
//show the user defined line nodes
tLnS = new LineString();
lnptC.Add(new System.Windows.Point(m_pMapBase.CursorPosition(e).X, m_pMapBase.CursorPosition(e).Y));
myLineSegment.Points = lnptC;
SGWPoint pt1 = new SGWPoint();
pt1 = m_pMapBase.ToMapPoint(m_pMapBase.CursorPosition(e).X, m_pMapBase.CursorPosition(e).Y);
str1 = str1 + pt1.X.ToString() + " " + pt1.Y.ToString() + ",";
myPathSegmentCollection.Remove(myLineSegment);
myPathSegmentCollection.Add(myLineSegment);
myPathFigure.StartPoint = lnptC[0];
myPathFigure.Segments = myPathSegmentCollection;
myPathFigureCollection.Remove(myPathFigure);
myPathFigureCollection.Add(myPathFigure);
myPathGeometry.Figures = myPathFigureCollection;
myPathLn.Data = myPathGeometry;
if (e.ClickCount == 2) //double click
{
//query with the graphic
m_pMapBase.MouseLeftButtonDown -= drawLn;
tLnS.ImportFromWKT("LINESTRING (" + str1.Substring(0, str1.Length - 1) + ")");
List<ILayer> pLayers = m_pMapBase.Layers;
MapLayer pLayer = pLayers[0] as MapLayer;
List<innerLayer> pLayers2 = pLayer.Layers;
innerLayer pLayer2 = pLayers2[0];
pLayer2.ExecuteQuery(tLnS.ExportToWKT(), true, sendLnQry, null);
str1 = "";
}
}
private void sendLnQry(XDocument pDoc)
{
SGWPolygon pg = new SGWPolygon();
System.Windows.Media.PointCollection myPtC = null;
if (myPtC != null)
myPtC.Clear();
foreach (XElement pSubElem in pDoc.Descendants("Feature"))
{
XElement pGeomElem = pSubElem.Element("Geometry");
if (pGeomElem != null)
{
string sWKT = pGeomElem.Value;
pg.ImportFromWKT(pGeomElem.Value);
myPtC = new PointCollection();
Path2 = new System.Windows.Shapes.Polygon();
XElement pValues = pSubElem.Element("Values");
XElement pValue1 = pValues.Element("SurveyArea");
pg.ImportFromWKT(pGeomElem.Value);
SolidColorBrush b1 = new SolidColorBrush();
b1.Color = Colors.Blue;
Path2.Stroke = b1;
DropShadowEffect ef1 = new DropShadowEffect();
ef1.Color = Colors.Black;
ef1.Direction = 45;
ef1.ShadowDepth = 5;
ef1.BlurRadius = 6;
ef1.Opacity = 0.3;
SolidColorBrush b2 = new SolidColorBrush();
b2.Color = Colors.Yellow;
b2.Opacity = 0.5;
Path2.Fill = b2;
Path2.Effect = ef1;
Path2.StrokeThickness = 2;
ColorAnimation ca1 = new ColorAnimation();
// Create a duration of 5 seconds.
Duration duration = new Duration(TimeSpan.FromSeconds(0.2));
ca1.Duration = duration;
Storyboard sb = new Storyboard();
sb.Duration = duration;
sb.Children.Add(ca1);
ca1.From = Colors.Red;
ca1.To = Colors.Yellow;
sb.AutoReverse = true;
sb.RepeatBehavior = RepeatBehavior.Forever;
Storyboard.SetTarget(ca1, b2);
Storyboard.SetTargetProperty(ca1, new PropertyPath("Stroke.Color"));
// Make the Storyboard a resource.
LayoutRoot.Resources.Remove("unique_id");
LayoutRoot.Resources.Add("unique_id", sb);
// Begin the animation.
sb.Begin();
SGWPoint Spt = new SGWPoint();
SGWPoint Spt2 = new SGWPoint();
System.Windows.Point pt1 = new System.Windows.Point();
for (int i = 0; i < pg.ExteriorRing.PointCount - 1; i++)
{
Spt = pg.ExteriorRing.GetPoint(i);
Spt2 = m_pMapBase.FromMapPoint(Spt.X, Spt.Y);
pt1.X = Spt2.X;
pt1.Y = Spt2.Y;
Path2.Points.Add(pt1);
}
m_pMapBase.Children.Remove(Path2);
m_pMapBase.Children.Add(Path2);
//select points by the selected polygon
List<ILayer> pLayers = m_pMapBase.Layers;
MapLayer pLayer = pLayers[0] as MapLayer;
List<innerLayer> pLayers2 = pLayer.Layers;
innerLayer pLayer2 = pLayers2[0];
pLayer2.ExecuteQuery(pg.ExportToWKT(), true, QryPts, null);
}
}
}
private void QryPts(XDocument pDoc)
{
//show the points on the map
SGWPoint pt1 = null;
System.Windows.Shapes.Ellipse ep1 = null;
List<QryRst> source1 = new List<QryRst>();
//clear the points on the mpa
for (int i = LayoutRoot.Children.Count - 1; i > 6; i--)
{
LayoutRoot.Children.RemoveAt(i);
}
foreach (XElement pSubElem in pDoc.Descendants("Feature"))
{
XElement pGeomElem = pSubElem.Element("Geometry");
if (pGeomElem != null)
{
string sWKT = pGeomElem.Value;
pt1 = new SGWPoint();
ep1 = new Ellipse();
SolidColorBrush b1 = new SolidColorBrush();
b1.Color = Colors.Purple;
ep1.Stroke = b1;
SolidColorBrush b2 = new SolidColorBrush();
b2.Color = Colors.Green;
b2.Opacity = 0.5;
ep1.Fill = b2;
ep1.StrokeThickness = 2;
ep1.Width = 20;
ep1.Height = 20;
pt1.ImportFromWKT(pGeomElem.Value);
Canvas.SetLeft(ep1, m_pMapBase.FromMapPoint(pt1.X, pt1.Y).X-10);
Canvas.SetTop(ep1, m_pMapBase.FromMapPoint(pt1.X, pt1.Y).Y-10);
XElement pValues = pSubElem.Element("Values");
XElement pValue1 = pValues.Element("Id");
LayoutRoot.Children.Remove(ep1);
LayoutRoot.Children.Add(ep1);
//put the value on data grid
source1.Add(new QryRst()
{
CityName = pValue1.Value,
XY = pt1.X + "," + pt1.Y
});
dg1.ItemsSource = source1;
}
}
}
public class QryRst
{
public string CityName { get; set; }
public string XY { get; set; }
}
private void recQry(object sender, RoutedEventArgs e)
{
m_pMapBase.SelectMapTool(null);
m_pMapBase.MouseLeftButtonDown -= drawLn;
m_pMapBase.MouseLeftButtonDown += drwRec;
for (int i = m_pMapBase.Children.Count - 1; i > 0; i--)
{
m_pMapBase.Children.RemoveAt(i);
}
}
SGWPoint recpt1 = null;
SGWPoint recpt2 = null;
System.Windows.Media.PointCollection ptRC = null;
System.Windows.Shapes.Path rcPath = null;
PolyLineSegment myLineSegmentRC = null;
PathSegmentCollection myPathSegmentCollectionRC = null;
PathFigureCollection myPathFigureCollectionRC = null;
PathFigure myPathFigureRC = null;
PathGeometry myPathGeometryRC = null;
string strRC = "";
private void drwRec(object sender, MouseButtonEventArgs e)
{
//draw rectangel
recpt1 = m_pMapBase.CursorPosition(e); //screen pt, start point
recpt2 = m_pMapBase.ToMapPoint(recpt1.X, recpt1.Y); //geo pt, start point
m_pMapBase.MouseLeftButtonUp += RecFinished;
ptRC = new PointCollection();
rcPath = new System.Windows.Shapes.Path();
m_pMapBase.MouseMove += RecMov;
myLineSegmentRC = new PolyLineSegment();
myPathSegmentCollectionRC = new PathSegmentCollection();
myPathFigureCollectionRC = new PathFigureCollection();
myPathFigureRC = new PathFigure();
myPathGeometryRC = new PathGeometry();
rcPath = new System.Windows.Shapes.Path();
}
private void RecMov(object sender, MouseEventArgs e)
{
//show the rectange while mouse cursor moves
ptRC.Clear();
ptRC.Add(new System.Windows.Point(recpt1.X, recpt1.Y));
ptRC.Add(new System.Windows.Point(m_pMapBase.CursorPosition(e).X, recpt1.Y));
ptRC.Add(new System.Windows.Point(m_pMapBase.CursorPosition(e).X, m_pMapBase.CursorPosition(e).Y));
ptRC.Add(new System.Windows.Point(recpt1.X, m_pMapBase.CursorPosition(e).Y));
ptRC.Add(new System.Windows.Point(recpt1.X, recpt1.Y));
strRC = "";
foreach (System.Windows.Point kpt in ptRC)
{
SGWPoint tpt = new SGWPoint();
tpt = m_pMapBase.ToMapPoint(kpt.X, kpt.Y);
strRC = strRC + tpt.X + " " + tpt.Y + ",";
}
myLineSegmentRC.Points = ptRC;
SolidColorBrush b1 = new SolidColorBrush();
b1.Color = Colors.Red;
rcPath.Stroke = b1;
rcPath.StrokeThickness = 3;
m_pMapBase.Children.Remove(rcPath);
m_pMapBase.Children.Add(rcPath);
myPathSegmentCollectionRC.Remove(myLineSegmentRC);
myPathSegmentCollectionRC.Add(myLineSegmentRC);
myPathFigureRC.StartPoint = ptRC[0];
myPathFigureRC.Segments = myPathSegmentCollectionRC;
myPathFigureCollectionRC.Remove(myPathFigureRC);
myPathFigureCollectionRC.Add(myPathFigureRC);
myPathGeometryRC.Figures = myPathFigureCollectionRC;
rcPath.Data = myPathGeometryRC;
}
private void RecFinished(object sender, MouseButtonEventArgs e)
{
m_pMapBase.MouseLeftButtonUp -= RecFinished;
m_pMapBase.MouseLeftButtonDown -= drwRec;
m_pMapBase.MouseMove -= RecMov;
string strRC2 = "";
strRC2 = "POLYGON ((" + strRC.Substring(0, strRC.Length - 1) + "))";
List<ILayer> pLayers = m_pMapBase.Layers;
MapLayer pLayer = pLayers[0] as MapLayer;
List<innerLayer> pLayers2 = pLayer.Layers;
innerLayer pLayer2 = pLayers2[0];
pLayer2.ExecuteQuery(strRC2, true, sendLnQry, null);
strRC2 = "";
}
private void pgnQry(object sender, RoutedEventArgs e)
{
m_pMapBase.SelectMapTool(null);
m_pMapBase.MouseLeftButtonDown += pgnDraw;
m_pMapBase.MouseLeftButtonDown -= RecMov;
m_pMapBase.Children.Remove(pg1);
m_pMapBase.MouseLeftButtonUp -= RecFinished;
for (int i = m_pMapBase.Children.Count - 1; i > 0; i--)
{
m_pMapBase.Children.RemoveAt(i);
}
// Create a blue and a black Brush
pg1 = new System.Windows.Shapes.Polygon();
SolidColorBrush yellowBrush = new SolidColorBrush();
yellowBrush.Color = Colors.Yellow;
yellowBrush.Opacity = 0.5;
SolidColorBrush blackBrush = new SolidColorBrush();
blackBrush.Color = Colors.Black;
pg1.StrokeThickness = 5;
pg1.Stroke = blackBrush;
pg1.Fill = yellowBrush;
m_pMapBase.Children.Remove(pg1);
m_pMapBase.Children.Add(pg1);
}
string pgnstr = "";
private void pgnDraw(object sender, MouseButtonEventArgs e)
{
//draw polygon on the map
//when double click , query the layer with the polygon
pg1.Points.Add(new System.Windows.Point(m_pMapBase.CursorPosition(e).X, m_pMapBase.CursorPosition(e).Y));
SGWPoint pt1 = new SGWPoint();
pt1 = m_pMapBase.ToMapPoint(m_pMapBase.CursorPosition(e).X, m_pMapBase.CursorPosition(e).Y);
pgnstr = pgnstr + pt1.X.ToString() + " " + pt1.Y.ToString() + ",";
if (e.ClickCount == 2) //double click
{
//query with the graphic
m_pMapBase.MouseLeftButtonDown -= pgnDraw;
pgnstr = "POLYGON ((" + pgnstr.Substring(0, pgnstr.Length - 1) + "))";
List<ILayer> pLayers = m_pMapBase.Layers;
MapLayer pLayer = pLayers[0] as MapLayer;
List<innerLayer> pLayers2 = pLayer.Layers;
innerLayer pLayer2 = pLayers2[0];
pLayer2.ExecuteQuery(pgnstr, true, sendLnQry, null);
pgnstr = "";
}
}
}
}