ThinkGeo.com    |     Documentation    |     Premium Support

Integrating SevenCS with MapSuite

Hi,


I am trying to use just the control (zoom in/out, dragging,etc ) from MapSuite but for the map data, i have the custom map-data from SevenCS which is more suited for what i am doing.


Can i replace the default map from thinkgeo to that of sevencs ? Once given a longitude and latitude to my application, it will return me a bitmap images corresponding to that location and hopefully i can add this ground layering to Mapsuite.


Is this possible and is it as simple as adding layering ?


Thanks!



Kwong,


I have put together the code for you new custom layer. The first part is how to use it and the second part is the actually new class.


            // Here I create my custom layer

            SimpleCustomLayer customLayer = new SimpleCustomLayer();



            // Here I add my cusotm layer to the layers collection.

            Map1.StaticLayers.Add("CustomLayer", customLayer);


 


_+_+_+_+_+


New Class


_+_+_+_+_+


 


using System;

using System.Collections.Generic;

using System.Text;

using System.Drawing;


// What this sample does is creates your own layer.  You can use this layer just like any other layers

// in the system.  The advantage is that you can place it where you want and it will seamlessly integrate

// with the rest of the system.  As you can see it is really easy to create your own layers.

// The basic flow of events is that when the map needs to draw it will first call the OpenCore.

// This is where you do anything special to get your source ready.  Then it will call the GetBoundingBox

// method to make sure the current extent of the map is within the are you have data.  If not then it will

// never call the DrawCore because there is no need.  Then if you are int he extent it wil call the DrawCore.

// The DrawCore is where you place your code that need to do the drawing on the canvas.  As you can see below

// it is faily simple.


 


namespace ThinkGeo.MapSuite.Core

{


    class SimpleCustomLayer : Layer

    {


        protected override void OpenCore()

        {

            //  Here you should do anything you need to do it initilize your source.

            //  Maybe for you it is nothing and if so you can leave it blank.

        }


        protected override void CloseCore()

        {

            //  Here you should do anything you need to do it close your source.

            //  Maybe for you it is nothing and if so you can leave it blank.

        }


        protected override RectangleShape GetBoundingBoxCore()

        {


            // Here you will want to pass back a rectangle that defines the entire extent of

            // of image source.  So if a user pans outside off of where you have imagry for the map

            // control we will not try and fetch it.  If your data is for the whole world or you are

            // fine to just passing back a transparent image if the user goes off the edge then you can use

            // the default code I added



            //This assumes that your map is in decimal degrees and covers the whole world, if not you need to know the bounds.


 


            return new RectangleShape(-180.0, 83.0, 180.0, -90.0);

        }


 


        protected override void DrawCore(GeoCanvas canvas, GeographyUnit mapUnit, System.Collections.ObjectModel.Collection<simplecandidate> labeledInLayers)

        {

            // Here is where you will call your API.  You will get a bitmap back and then draw it in the canvas.

            // I have provided a mock method call to simulate what you will do.



            Bitmap customImage = GetImage(canvas.CurrentWorldExtent.UpperLeftPoint.X, canvas.CurrentWorldExtent.UpperLeftPoint.Y, canvas.CurrentWorldExtent.LowerRightPoint.X, canvas.CurrentWorldExtent.LowerRightPoint.Y, (int)canvas.CanvasWidth, (int)canvas.CanvasHeight);



            // Here we draw the image you generated to the canvas.

            canvas.DrawWorldImageWithoutScaling(canvas.ToGeoImage(customImage), canvas.CurrentWorldExtent.GetCenterPoint().X, canvas.CurrentWorldExtent.GetCenterPoint().Y, DrawingLevel.LevelOne);



            customImage.Dispose();

        }



        private Bitmap GetImage(double upperLeftX, double upperLeftY, double lowerRightX, double lowerRightY, int screenWidth, int screenHeight)

        {

            // In here you would get your image and return it.

            // I am just returning an image with some text so you can verify it works..



            Bitmap customImage = new Bitmap(screenWidth, screenHeight);

            Graphics g = Graphics.FromImage(customImage);

            g.DrawString("SimpleCustomLayer Test", new Font("Arial", 20, FontStyle.Bold), Brushes.Black, new PointF(screenWidth / 2, screenHeight / 2));

            g.Dispose();



            return customImage;

        }



    }

} </simplecandidate>


 


David



Hi  
  
 May i know what layer in openlayers does the custom layers corresponds to ? 
  
 Is there any tutorial how i can integrate any other custom openlayer’s api with asp.net ? 
  
 How can i wrap my own javascript in asp.net ? Are there any tutorial ?  I would like to make my code cleaner. 
  
 Thanks!

Hi, 



A layer doesn’t respect to an openlayers' layer, but an overlay does. Here are some corresponds between overlay in Web Edition and layer in OpenLayers. 



wmsOverlay -> layer.WMS 

layerOverlay -> layer.WMS 

GoogleOverlay -> layer.Google 

VirtualEarthOverlay -> layer.VirtualEarth 

YahooOverlay -> layer.Yahoo 



InMemoryMarkersOverlay -> layer.Markers 

FeatureMarkersOverlayer -> layer.Markers 



We don’t have the tutorial, we probably will make one in the future. Can you let me know which APIs you want to integrate with ASP.NET and if it is common used, we can integrate it on the server part in the future version. 



You can directly use openlayers’ API on client side. Here is one sample. Paste the following code to the header tag and there you can use openlayers’ API directly. 




var OnMapCreated = function(map) {
      // the parameter map is OpenLayers’ map we used, 
      // OpenLayers’ API could use freely here.
}




Thanks, 



Ben