Pokonam dzis siebie - Integracja MapPointa z aplikacja

Dzisiaj od poranej godziny 5:30 walcze z MapPiont'em i udało mi się napisać coś takiego:
Dim objApp As MapPoint.Application
Dim objLoc As MapPoint.Location
Dim objMap As MapPoint.Map

PrivateSub MapPointView_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load
objApp = CreateObject("MapPoint.Application")
objApp.UserControl = True
mappointCT.OpenMap("D:\Documents and Settings\" & Anen & "\My Documents\Map.ptm")
Dim FindString AsString
Dim objFindResults As FindResults
Dim X AsInteger
FindString = (QuikDel.DeliveryCityTextBox.Text & " Poland, Poland")
objMap = Me.mappointCT.ActiveMap
objFindResults = objMap.FindResults(FindString)
X = 1
DoWhile X = 5
objLoc = objFindResults.Item(X)
FindResults.Items.Add(objLoc.Name)
X = X + 1
Loop
EndSub


PrivateSub FindResults_DoubleClick(ByVal sender AsObject, ByVal e As System.EventArgs) Handles FindResults.DoubleClick
MsgBox(FindResults.SelectedItem)
objLoc = FindResults.SelectedItem
objLoc.GoTo()
EndSub

Eksperyment zakończył się klapą gdyż ,
a) nie jestem dobry z basic'a
b) nie umiem jakoś myśleć w ten sposób

ale jak zrobimy to w c#

private void btnDirections_Click(object sender, EventArgs e)
{


txtResults.Text =
string.Empty;
stsMain.Text =
string.Empty;

FindSpecification findSpec =
new FindSpecification();

FindResults startResults =
null;
FindResults endResults =
null;


findSpec.DataSourceName = cmbZone.Text;

findSpec.InputPlace = txtOrigAddress.Text;


try
{
startResults = findService.Find(findSpec);
}
catch
{
MessageBox.Show(
"Problem connecting with service");
}


findSpec.InputPlace = txtDestAddress.Text;



try
{
endResults = findService.Find(findSpec);
}
catch
{
MessageBox.Show(
"Problem connecting with service");
}




if(startResults == null)
{
MessageBox.Show(
"Originating Address not found.");
}
else
{


if(startResults.NumberFound == 0)
{
MessageBox.Show(
"Originating Address not found.");
return;
}

}
if(endResults == null)
{
MessageBox.Show(
"Destination Address not found.");
}
else
{

if(endResults.NumberFound == 0)
{
MessageBox.Show(
"Destination Address not found.");
return;
}
}

stsMain.Text =
"Generating Route Information";



GetRoute(startResults,endResults);
}
+



private void GetRoute(FindResults sResults,
FindResults eResults)
{
SegmentSpecification[] routeSegment;
routeSegment =
new SegmentSpecification[2];

routeSegment[
0]= new SegmentSpecification();
routeSegment[
0].Waypoint = new Waypoint();
routeSegment[
0].Waypoint.Name =
sResults.Results[
0].FoundLocation.Entity.Name;
routeSegment[
0].Waypoint.Location =
sResults.Results[
0].FoundLocation;

routeSegment[
1]= new SegmentSpecification();
routeSegment[
1].Waypoint = new Waypoint();
routeSegment[
1].Waypoint.Name =
eResults.Results[
0].FoundLocation.Entity.Name;
routeSegment[
1].Waypoint.Location =
eResults.Results[
0].FoundLocation;


RouteSpecification routeSpecs =
new RouteSpecification();
routeSpecs.DataSourceName = cmbZone.Text;
routeSpecs.Segments = routeSegment;




RouteServiceSoap routeService =
new RouteServiceSoap();
routeService.Credentials = myCredentials;
routeService.PreAuthenticate =
true;



Route route =
new Route();
route = routeService.CalculateRoute(routeSpecs);

stsMain.Text =
"Fetching Route Information";



for (int i = 0;
i < class="code-digit">0].Directions.Length;i++)
{
txtResults.Text +=
"("+(i+1)+") "+
route.Itinerary.Segments[
0].Directions[i].Instruction +
" >> ";
}

stsMain.Text =
"Wait...Generating Map Information";



MapSpecification mapSpec =
new MapSpecification();
mapSpec.Options =
new MapOptions();
mapSpec.Options.Format =
new ImageFormat();


mapSpec.Options.Format.Height = pcMap.Height;
mapSpec.Options.Format.Width = pcMap.Width;



mapSpec.DataSourceName = cmbZone.Text;

mapSpec.Route = route;

try
{
// Get the map image

MapImage tempImage =
renderService.GetMap(mapSpec)[
0];
pcMap.Image =
new Bitmap(
new MemoryStream(tempImage.MimeData.Bits,
false), true);

stsMain.Text =
"Done";
}
catch(Exception e)
{
MessageBox.Show(e.ToString());
}
}


Trochę lepiej ale dalej klaps - nie ma tutaj wyjątku na mapy polskie - stąd integracja z GIS'em


Ale to już w następnym wpisie


P.S.

Session has not been terminated

0 komentarze: