How can I populate more than one Silverlight Image from Bing Maps asynchronous calls? -
How can I populate more than one Silverlight Image from Bing Maps asynchronous calls? -
i have next code, works fine if want populate 1 image response bing maps. if seek 2 variable _currentimage ends beingness "image1" because calls asynchronous. how can pass image variable along imageryservicegetmapuricompleted method?
using system; using system.windows.controls; using system.windows.media.imaging; using basicbingmapsimagerysvc.imageryservice; namespace basicbingmapsimagerysvc { public partial class mainpage : usercontrol { private const string bingmapskey = "my key"; private image _currentimage; public mainpage() { initializecomponent(); getmap(42.573377, -101.032251, image0, mapstyle.aerialwithlabels); getmap(42.573377, -101.032251, image1, mapstyle.road_v1); } private void getmap(double lat, double lon, image image, mapstyle mapstyle) { var mapurirequest = new mapurirequest(); // set credentials using valid bing maps key mapurirequest.credentials = new credentials(); mapurirequest.credentials.applicationid = bingmapskey; // set location of requested image mapurirequest.center = new location(); mapurirequest.center.latitude = lat; mapurirequest.center.longitude = lon; // set map style , zoom level var mapurioptions = new mapurioptions(); mapurioptions.style = mapstyle; mapurioptions.zoomlevel = 13; // set size of requested image match size of image command mapurioptions.imagesize = new sizeofint(); mapurioptions.imagesize.height = 256; mapurioptions.imagesize.width = 256; mapurirequest.options = mapurioptions; var imageryservice = new imageryserviceclient("basichttpbinding_iimageryservice"); imageryservice.getmapuricompleted += imageryservicegetmapuricompleted; _currentimage = image; imageryservice.getmapuriasync(mapurirequest); } private void imageryservicegetmapuricompleted(object sender, getmapuricompletedeventargs e) { // result mapuriresponse object mapuriresponse mapuriresponse = e.result; var bmpimg = new bitmapimage(new uri(mapuriresponse.uri)); _currentimage.source = bmpimg; } } }
you utilize lambda look / delegate event handler, allows 'capture' reference image:
var imageryservice = new imageryserviceclient("basichttpbinding_iimageryservice"); imageryservice.getmapuricompleted += (s,e) => { // result mapuriresponse object mapuriresponse mapuriresponse = e.result; var bmpimg = new bitmapimage(new uri(mapuriresponse.uri)); // set image source image.source = bmpimg; };
image silverlight asynchronous bing-maps
Comments
Post a Comment