I just want a simple map on a web page that, when the user clicks on it, the map displays again with a pushpin in the click location. But, I have a problem that I just can't seem to get around.
I build a map and place it in a webcontrols image button. On the click event I calculate the latlong and set a pushpin. This all works fine until the map is zoomed or panned and then a subseqeunt map click places the pushpin in the wrong location.
Any help would be much appreciated!
Here is the click event code...
PixelCoord myPixelCoords = new PixelCoord();
myPixelCoords.X = e.X;
myPixelCoords.Y = e.Y;
RenderMap(0, 0, 0, myPixelCoords);
Here is the RenderMap code... (right out of the sample but with a pushpin)
void RenderMap(double myPanHorizontalAdjustment, double
myPanVerticalAdjustment, double myZoomValue, PixelCoord PushPinCoord)
{
MapWithNavigationButtonsCS.Global global =
(MapWithNavigationButtonsCS.Global)Context.Applica tionInstance;
//Get the latest map specification object
MapSpecification mapSpec = (MapSpecification)Cache["myMapSpec"];
//Pan or zoom the map as appropriate
mapSpec.Options.PanHorizontal = mapSpec.Options.PanHorizontal +
myPanHorizontalAdjustment;
mapSpec.Options.PanVertical = mapSpec.Options.PanVertical +
myPanVerticalAdjustment;
if (!(mapSpec.Options.Zoom + myZoomValue <= 0))
{
mapSpec.Options.Zoom = mapSpec.Options.Zoom + myZoomValue;
}
if (PushPinCoord != null)
{
PixelCoord [] coordinates = {PushPinCoord};
LatLong[] centerCoords =
global.RenderService.ConvertToLatLong(coordinates ,mapSpec.Views[0],
500, 500);
Pushpin[] myPushPins = new Pushpin[1];
myPushPins[0] = new Pushpin();
myPushPins[0].PinID = "pin0";
myPushPins[0].IconName = "0";
myPushPins[0].IconDataSource = "MapPoint.Icons";
myPushPins[0].LatLong = new LatLong();
myPushPins[0].LatLong = centerCoords[0];
mapSpec.Pushpins = myPushPins;
}
//Declare the map image array and get the map
MapImage[] myMapImages;
try
{
myMapImages = global.RenderService.GetMap(mapSpec);
//Assign the Map Url
this.Map.ImageUrl = myMapImages[0].Url;
//Also restore the changed map specification
Cache["myMapSpec"] = mapSpec;
}
catch(SoapException myException)
{
}
}
Thanks in advance for the help!
Jay