ThinkGeo.com    |     Documentation    |     Premium Support

No background with the method GetBitmap()

Hello everyone,


 


I want to get an image from my component. I use the method GetBitmap() to create an image but when I open the image created, there's no background in my image (I haven't the backgound color either).


            Bitmap bmp = Map1.GetBitmap(width, height);

            bmp.Save(@"C:\folder\image_name.bmp", ImageFormat.Bmp);


I use a Google background in the BackgroundOverlay.


            GoogleOverlay gOverlay = new GoogleOverlay();

            gOverlay.Name = "Google Overlay";

            gOverlay.GoogleMapType = GoogleMapType.Hybrid;



            string sOverlayMapURL =   "google_parameters";



            gOverlay.JavaScriptLibraryUri = new Uri(sOverlayMapURL);

            Map1.BackgroundOverlay = gOverlay;


 


 



Pierre, 


In Web Edition, 3rd part overlays (for instance GoogleOverlay, VirtualEarthOverlay, YahooOverlay) are integrated by using their javascript libraries on client side and as a result we cannot get the bitmap through the server side method Map.GetBitMap(). Instead, we can use the server part layer “GoogleLayer” which can be printed on the server side. Here is how to use it.
 

            Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#B3C6D4"));

            Map1.CurrentExtent = new RectangleShape(-13939426.6371, 6701997.4056, -7812401.86, 2626987.386962);

            Map1.MapUnit = GeographyUnit.Meter;

            GoogleMapsLayer googleLayer = new GoogleMapsLayer("maps.google.com/maps?file=api&v=2&key=ABQIAAAAoxK_HcqphMsnUQHEwLwHlRSavkNJi0NVTgm4UDidoiIU5dUJpRQW88FufPCp0aTPraxZgZFAIUHn3Q");

            Map1.StaticOverlay.Layers.Add(googleLayer);

 Here is the picture I get using the GetBitMap method.

 
Thanks,
 
Ben

Hello,


I use the code youd send me but I've got an WebException :


System.Net.WebException was unhandled

  Message="The remote server returned an error: (400) Bad Request."

  Source="System"

  StackTrace:

       at System.Net.HttpWebRequest.GetResponse()

       at ThinkGeo.MapSuite.Core.x2953481043f26695.x70793724ab2439e6()

       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

       at System.Threading.ExecutionContext.runTryCode(Object userData)

       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)

       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

       at System.Threading.ThreadHelper.ThreadStart()

  InnerException: 

 


I don't know where this exception has been thrown.


GoogleMapsLayer gLayer = new GoogleMapsLayer(sOverlayMapURL);

gLayer.Name = "Google Layer";

gLayer.MapType = GoogleMapsMapType.Hybrid;

gLayer.PictureFormat = GoogleMapsPictureFormat.Jpeg;


Map1.StaticOverlay.Layers.Add(gLayer);


Did I forget something ?






 


Pierre,


Maybe something wrong with the GoogleMap key you were using. Here is a demo which works fine, please have a look and let me know if you have any issues.


Thanks,


Ben


 






456-GetGoogleBackground.zip (10.5 KB)

Hello,


 


Any key generates this error. My page is already load when the error appears.


I use a HTTP analyzer to see what's happen and I get this :


/staticmap?center=49,660545,0,56026&zoom=15&size=512x512&maptype=hybrid&format=jpg-baseline&key=maps.google.com/maps?file=api&v=2&key=ABQIAAAAoxK_HcqphMsnUQHEwLwHlRSavkNJi0NVTgm4UDidoiIU5dUJpRQW88FufPCp0aTPraxZgZFAIUHn3Q&sensor=false


It's an error due to the globalization. The correct center parameter must be 49.660545,0.56026


I try to change everything in english but I can't change this. I think it's coming from the core.


 


Could you take a look ? It's quite urgent.


 


Thanks.



 Posted By Pierre-Antoine on 02-26-2009 03:30 AM 

Hello,


 


Any key generates this error. My page is already load when the error appears.


I use a HTTP analyzer to see what’s happen and I get this :


/staticmap?center=49,660545,0,56026&zoom=15&size=512x512&maptype=hybrid&format=jpg-baseline&key=maps.google.com/maps?file=api&v=2&key=ABQIAAAAoxK_HcqphMsnUQHEwLwHlRSavkNJi0NVTgm4UDidoiIU5dUJpRQW88FufPCp0aTPraxZgZFAIUHn3Q&sensor=false


It’s an error due to the globalization. The correct center parameter must be 49.660545,0.56026


I try to change everything in english but I can’t change this. I think it’s coming from the core.


 


Could you take a look ? It’s quite urgent.


 


Thanks.





(EDIT : I’ve got the Regional and Language Option in French)






 



 


Pierre,


We recreated this problem and yes, it is a bug. Thanks for pointing it out and we will make it right in the next version.


If you change your server language to English, I'm pretty sure this problem will be gone. Go to “Start” → “Control Panel” → “Regional and Language Options” ->”Regional Options” Panel, and change the language to English,  it then will work.  Onother thing you can try is keep using French as your language, click the “customize...” button (still in the “Regional Options”),  change the "Decimal Symbol" to “.” and change the "Digit grouping symbol" to “,”,  it should work too.




Thanks,


Ben. .


 





 



I am having the same issue but with VirtualEarth, I don't see VirtualEarth version of  GoogleMapsLayer. Please advise. 



Todd, 
  
 We don’t have the VirtualEarth version for now and we will add it in the future release.  
  
 Thanks, 
  
 Ben

Todd, 
  
   We are about to release the Virtual Earth support.  Watch the Developers Blog area for details.  I would image it will be out in about a week. 
  
 David

This is great, looking forward to it. 


Will the VE webedition resolves the below issues? I am using WebEdition 3.1.16


1. On Map1.PrintMap -- the image is cutoff (see attached image)


2. Using either OnClientDoubleClick or OnClientDoubleClick event cause Firefox browser to display a blank map image 


(Use UseVirtualEarth.aspx sample and OnClientDoubleClick /OnClientDoubleClick event)


3. Of course, Map1.GetBitmap with no background


4. Enhancement -- Able to add drawn shape label on client-side (The example provide in the forum does not work)


function OnClientDrawEnd(feature) {

    feature.name = 'test label';    

}


Thanks


 






 


Ttd,


Here is the answers.


1, I'm not sure about the cutoff problem as I didn't find the attached image. But I think if GoogleMapsLayer works fine, there is much chance we will not have this problem in VE layer either.


2, You mean the OnClientClick / OnClientDoubleClick right? I couldn't recreate this issue as it works fine on my machine with FireFox 3.0.3. Here are my codes


Server Side:



 if (!Page.IsPostBack)
{
Map1.CurrentExtent = new RectangleShape(-13939426.6371, 6701997.4056, -7812401.86, 2626987.386962);
Map1.MapUnit = GeographyUnit.Meter;
Map1.OnClientDoubleClick = "clientDoubleClick";

VirtualEarthOverlay ve = new VirtualEarthOverlay("VirtualEarth Map");
ve.JavaScriptLibraryUri = new Uri("dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2");
Map1.CustomOverlays.Add(ve);
}

Client Side:



 function clientDoubleClick() {
alert("clientDoubleClick");
}

function clientClick() {
alert("clientClick");
}

3, Sure it will solve this problem.


4, You mean the example in the following post?


gis.thinkgeo.com/tabid/143/a...fault.aspx


I think this example is find and it is supposed to label the drawn rectangle in a post back. You can see we can add the column value on client side like this.



 var clientDrawEnd = function(feature) {
feature.fieldValues = [{ Key: 'name', Value: 'test label'}];
}

We don't provide the way to label the drawn shapes in clientDrawEnd event as it's a bit difficult to decide the label position on Client Side. You can have a try to add a popup with transparent background on the drawn shape to make it as a label. I'm not sure whether that will work well though and we will have a look if we can do some improvements on that.


Thanks,


Ben




Attached is an example application which causes the VE Map cutoff on Print and the Firefox blank display (my Firefox version is 3.0.7). Please let me know what you found. Thanks



504-Default_.txt (2.73 KB)
505-Default.aspx.cs (7.44 KB)

Ttd, 
  
 We recreated the cutoff issue and I’ve added it to our tracking system, we will see if we can make it right in the next version. Thanks for reporting.  
 We couldn’t recreate the blank map issue though (With FireFox 3.0.7), I guess it relates with some other aspects like the net speed, if it is slow, it might has some problems when getting the images from VE. Just guess. Can you provide more info how to recreate this?  
  
 Thanks, 
  
 Ben

Can you provide the status of VE webedition release date. The Print and "no background" issue are a show stopper for our application. Please advise. Thanks




 


Ttd,


Here attached is the extension of VirtualEarth, we planned to add it to our installer but not finally completed. Please have a try now and let me know if you have any issues.


Here is the sample code:



VirtualEarthLayer layer = new VirtualEarthLayer("138592", "Disyue1@", "66.29.94.102");

Thanks,


Ben




517-MicrosoftMapLayerExtension.zip (25.5 KB)

Using MicrosoftMapLayerExtension.dll, does that means I must use a full Virtual Earth license.  I don't see any property to designate the URI (ex. (dev.virtualearth.net/mapcont...ashx?v=6.2), only IP Address, AccountID & Password. Do you have an example using the URI with your DLL. Thanks






 


Here is the sample, Ttd,


You can use VirtualEarthOverlay when showing on the map and switch to the server side VirtualEartyLayer when you want to get the bitmap or print. Here is a user doing the same thing for googleMap, please have a look if you are interested.


gis.thinkgeo.com/Support/Dis...fault.aspx


Let me know if you have any issues.


Thanks,


Ben




521-VirtualEarthLayerSample.zip (11.7 KB)

Thanks Ben,


I try your example. Was able to save a VirtualEarthLayer image with content or shape. However, encounter some problems. 


First, I can't add a custom ImageUri on VirtualEarthLayer. Second , whenever I add the add shapes to VirtualEarthLayer layer, I am getting "The given key was not present in the dictionary." on Bitmap bmpMap = Map1.GetBitmap(iWidth, iHeight).


 



       private void SaveImage(){

        Overlay objAactiveOverlay = Map1.ActiveBaseOverlay;

        SetTicketLogoImage();

        Map1.CustomOverlays["VirtualEarth Overlay"].IsVisible = true;

        Map1.ActiveBaseOverlay = (LayerOverlay)Map1.CustomOverlays["VirtualEarth Overlay"];


        ScreenPointF ULPoint = Map1.ToScreenCoordinate(Map1.CurrentExtent.UpperLeftPoint);

        ScreenPointF LRCoord = Map1.ToScreenCoordinate(Map1.CurrentExtent.LowerRightPoint);

        int iWidth = Convert.ToInt32(LRCoord.X - ULPoint.X);

        int iHeight = Convert.ToInt32(LRCoord.Y - ULPoint.Y);


        Bitmap bmpMap = Map1.GetBitmap(iWidth, iHeight);

        bmpMap.Save((@"c:\TEST\A-" + DateTime.Now.ToString("MM-dd-yyyy hhmm tt") + ".jpg"),    System.Drawing.Imaging.ImageFormat.Jpeg);

        

        //Reset existing 

        //Map1.ActiveBaseOverlay = objAactiveOverlay;

    }




This is how I structure my application-- Three CustomOverlays (VirtualEarthOverlay, custom shapes and text overlay, and hidden VirtualEarthLayer). All shapes and drawing is done on client-side; On Save, the client-side shapes are added to the Customlayers before calling the GetBitMap function. Below is my two sample functions. Please advise. Thanks


private void testAddEdit2Overlay()

    {

        LayerOverlay lOlay = (LayerOverlay)Map1.CustomOverlays["shapeOverlay"];

        LayerOverlay veOlay = (LayerOverlay)Map1.CustomOverlays["VirtualEarth Overlay"];


        InMemoryFeatureLayer shapeLayer = (InMemoryFeatureLayer)lOlay.Layers[0];

        InMemoryFeatureLayer textLayer = (InMemoryFeatureLayer)lOlay.Layers[1];

        InMemoryFeatureLayer veLayer = (InMemoryFeatureLayer)lOlay.Layers[0];

        shapeLayer.InternalFeatures.Clear();

        veLayer.InternalFeatures.Clear();

        foreach (string EditShapeKey in Map1.EditOverlay.Features.GetKeys())

        {

            Feature featureEdit = Map1.EditOverlay.Features[EditShapeKey];

            // shapeLayer.InternalFeatures.Add(featureEdit.Id, featureEdit);

            veLayer.InternalFeatures.Add(featureEdit.Id, featureEdit);  

            textLayer.InternalFeatures.Add(featureEdit.Id, featureEdit);

        }

        lOlay.Redraw();

        veOlay.Redraw();

        

    }



Ttd, 
 That exception seems from the GeoKeyedCollection, please make sure your VirtualEarthOverlay.Id equals to “VirtualEarth Overlay”. 
  
  
 Also, seems the following codes has some problem. The shapeLayer and veLayer is in fact the same one (Olay.Layers[0]) 
 
            InMemoryFeatureLayer shapeLayer = (InMemoryFeatureLayer)lOlay.Layers[0];

            InMemoryFeatureLayer textLayer = (InMemoryFeatureLayer)lOlay.Layers[1];

            InMemoryFeatureLayer veLayer = (InMemoryFeatureLayer)lOlay.Layers[0];


 
 About Virtual Earth’s custom ImageUri, do you mean VE’s service reference? I think you can use property layer.EndpointAddress to change it. See the comments in the above sample for more detail. 
 Thanks, 
 Ben