ThinkGeo.com    |     Documentation    |     Premium Support

Add Markers from database over Google overlay

Hi


I am evaluating your product (and really liking it)


Trying to write my first Web app. I need to add markers from a database (SQL 2000) and overlay them over Google map. The markers have Lat, Lon (can also have it in State Plane) and unique ID. I understand that I need to use CustomOverlays but I am missing how to add the markers to it (1000s of them)


Can you point me to the right direction?


Thanks


Jakub


 






 

 


Jakub,


Welcome to the community, hope you enjoy the learning and sharing here.





 


Here is a simple sample how to use it, please let us know if you have any issues.




using System;
using System.Web.UI;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.WebEdition;

namespace WebApplication2
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Map1.CurrentExtent = new RectangleShape(-13939426.6371, 6701997.4056, -7812401.86, 2626987.386962);
                Map1.MapUnit = GeographyUnit.Meter;

                Proj4Projection proj4 = new Proj4Projection();
                proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
                proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();

                InMemoryMarkerOverlay inMemoryMarkerOverlay = new InMemoryMarkerOverlay();
                inMemoryMarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.WebImage = new WebImage("../../theme/default/img/marker.gif");
                inMemoryMarkerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

                // Put the following line of code to a loop to add all the 1000 records
                inMemoryMarkerOverlay.Features.Add("id", new Feature(-100, 40));
                inMemoryMarkerOverlay.FeatureSource.Projection = proj4;

                GoogleOverlay google = new GoogleOverlay("Google Map");
                google.JavaScriptLibraryUri = new Uri(@"maps.google.com/maps?file=api&v=2&key=ABQIAAAAoxK_HcqphMsnUQHEwLwHlRSavkNJi0NVTgm4UDidoiIU5dUJpRQW88FufPCp0aTPraxZgZFAIUHn3Q");
                google.GoogleMapType = GoogleMapType.Normal;

                Map1.CustomOverlays.Add(google);
                Map1.CustomOverlays.Add(inMemoryMarkerOverlay);
            }
        }
    }
}


Thanks,


Ben


 



Sweet! That did the trick. Thank you for a fast response.


I am quite impressed. I am liking your component more and more.




Is there some sort of a clustering function? I will have potentially tens of thousands of points to display on a relatively small area (airport size) and I'd like to show more of them as users zoom in. 

I am worried about performance. When I loaded all the points into Google Map it slowed to a crawl when there was no clustering implemented. maybe your component does not have that problem? 



Thanks, 

Jakub 



 



Well, the problem is there too. I just tried to load ~2500 markers and I am getting a message "Stop running this script? A script on this page is causing IE to run slowly. If it continues to run, your computer may become unresponsive" 
  
 The markers load eventually when I click No repeatedly, but the messagebox appears on every pan and zoom. which is actually worse than in the Google Map. 
  
 Is there a way to prevent that? Can I zoom to the extent of my markers on the first load? 


Jakub, 
  
 Clustering is an interesting tech, thanks for reminding and I’ve written it down for discussing when we will involve it in the future release. 
  
 Now with the current version, we can accomplish the same feature by using ZoomLevels. For example, I need to show 1000 markers within an airport, I make the 1000 markers only be visible between ZoomLevel16 ~ ZoomLevel20, and create one marker to represent the airport between ZoomLevel01 to ZoomLevel15. In that way, when I have a large viewport,  one marker is displayed and only when I zoom in very far, the 1000 markers are displayed in a small viewport, where not many markers need to be rendered at the same time. We can make it smoother by for example, creating one marker for ZoomLevel01 to ZoomLevel05, creating 5 markers representing that airport for ZoomLevel06 to ZoomLevel10, … and finally showing the 1000 markers at the rest zoomLevels. This method is a good workaround but not that convenient to use (as we need to create new markers for different ZoomLevels), we will still discuss the Clustering feature which will be pretty convenient. 
  
 If you still want to change the extent for the first load, you can simply add the following lines to the Page_Load method. Here you input the extent in DecimalDegree and the proj4 will convert it to the GoogleMap’s projection. 
 
    proj4.Open();
    Map1.CurrentExtent = (RectangleShape)proj4.ConvertToExternalProjection(new RectangleShape(-131.22, 55.05, -54.03, 16.91));
    proj4.Close();
                
 Thanks, 
  
 Ben 


Thanks for considering clustering. It would add a kicka.. performance to your app. The K-means clustering approach seems to be the best for this type application, I think.


I must be little dense on the zoom levels. That is what I tried to do but I could only find command to show items UNTIL a certain zoom level (ApplyUntilZoomLevel), not FROM a zoom level.


Can you post a bit of code on how to show various markers at zoom level intervals?


That will be a clincher, if that works I am buying  (and hoping that I will see clustering in near future). :)


Thanks,


Jakub


 



Jakub, 



The FROM ZoomLevel is set every time and it's just very easy to be overlooked. Let's say we set a zoomlevel range like
 
overlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel =  ApplyUntilZoomLevel.Level05; 

that's from zoomLevel01 to ZoomLevel05. 



We can also set another range like 

 
overlay.ZoomLevelSet.ZoomLevel06.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level10;

that's from zoomlevel06 to zoomlevel10. 



There is a sample (Samples->Markers->SetTheZoomLevelsOnAMarker) just for how to use ZoomLevel for markers, please have a look and I'm sure with this function you can make the marker performance pretty good. 



Thanks, 



Ben