ThinkGeo.com    |     Documentation    |     Premium Support

Add marker and remove marker

Kamal, 
  
 What the memory leak exactly is? Do you mean by client or server side? Could you provide us more information about the memory leak or some screenshot for the exception? 
  
 Thanks, 
 Howard

Hi Ben,


I mean to say usage of memory is going to increase. So performance is going down. I am using sIEve tool to detect the leak.  I have used marker layer at server side. Leaking in memory is increasing as timer refresh the marker.


Thanks.



Hi kamal,


We had a test about the memory leak issue, and we can not recreate the problem, the memory usage is stable. Our test sample is in the attachment, please take a look. We are using a timer control to refresh the map by server side every 100 milliseconds.
So how do you refresh the marker overlay in your application? Could you please make some change to the sample in the attachment so that we can use it to recreate this issue?
Any more information is appreciated.
Thanks,
Sun

1363-Post6348Demo.zip (184 KB)

Greetings, 
 I am using thinkgeo to show map related things. 
 1. I am showing more than 1 device’s marker on the map. For example one device is in UK and anther one is in sydney. I want to set current extent of the map so all the devices’ marker will visible at one time in one extent. Could anyone please help me. 
 Thanks 
 Kam

Kamal, 
  
 To satisfy your requirement, please try our SimpleMarkerOverlay which contains a sample in our installed package at "\Samples\Markers\UseDraggableMarkers.aspx"; please let me know if you have more queries. 
  
 Thanks, 
 Howard

Thanks Howards.But I am using InMemoryMarkerOverlay.I have used this marker overlay extensively. 
 I am getting the point marker longitude as 73.91 and latitude as 18.55 and second point is latitude as 51.5001 and longitude as -0.12624. 
 So I am using below code for setting current extent. 
 Map1.CurrentExtent = new RectangleShape(-0.12624, 51.5001 , 73.91, 18.55); 
 So above code is maximized the map and showing nothing. So I multiplied these values with 419976384.Now it is showing both markers. But when the second point is from another country then again I have to set this value. 
 I need to show two different markers irrespect to country in one extent with exact zoom level. 
 Could you please help me. 
 Thanks: 
 Kamal 


Kamal,  
  
 There are several possibilities to cause this issue. First of all, please check whether the ZoomLevelSet for the marker overlay is crossing the extent you set. Secondly, did you set the projection? Also we are not sure why you need to multiply 419976384 in your app? Please provide us your code so that we can recreate your issue easily. 
  
 Thanks, 
 Howard

Hi Howard, 
 Here is a sample code.Please look at below code 
 for (int i = 0; i < numberOfDeviceCnt; i++) 
                 { 
                         string strTable = m_arrDeviceImei.ToString();                    
                         //Start: Set a properties and position of a markeroverlay  
                         markerOverlay_LiveTrackForAll = new InMemoryMarkerOverlay("markerOverlay_LiveTrackForAll" + i); 
                         markerOverlay_LiveTrackForAll.FeatureSource.Open(); 
                          
                         markerOverlay_LiveTrackForAll.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.WebImage = new WebImage("Position.gif", 32, 32, -16f, -16f);     
                         markerOverlay_LiveTrackForAll.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; 
                         markerOverlay_LiveTrackForAll.FeatureSource.Open(); 
                         FeatureSourceColumn LidColumn = new FeatureSourceColumn("name"); 
                         FeatureSourceColumn LDateColumn = new FeatureSourceColumn("datetime"); 
                         FeatureSourceColumn LspeedColumn = new FeatureSourceColumn("speed"); 
                         markerOverlay_LiveTrackForAll.Columns.Add(LidColumn); 
                         markerOverlay_LiveTrackForAll.Columns.Add(LDateColumn); 
                         markerOverlay_LiveTrackForAll.Columns.Add(LspeedColumn); 
                         Proj4Projection m_objProj4_for_LiveTrack = new Proj4Projection(); 
                         m_objProj4_for_LiveTrack.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326); 
                         m_objProj4_for_LiveTrack.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString(); 
                         m_objProj4_for_LiveTrack.Open(); 
                         markerOverlay_LiveTrackForAll.FeatureSource.Projection = m_objProj4_for_LiveTrack; 
                         Map1.CustomOverlays.Add(markerOverlay_LiveTrackForAll); 
  
  
      //Getting data from database as lon,lat,speed,time 
      double intLat = Convert.ToDouble(dsForLiveEntites.Tables[0].Rows[0][0]); 
                     double intLon = Convert.ToDouble(dsForLiveEntites.Tables[0].Rows[0][1]); 
                                       
                     DateTime objDT = (DateTime)dsForLiveEntites.Tables[0].Rows[0][2]; 
                     string strDate = objDT.ToString("G", CultureInfo.CreateSpecificCulture("en-NZ")); 
                     double nSpeed = Convert.ToDouble(dsForLiveEntites.Tables[0].Rows[0][3]); 
                     double dSpeed = nSpeed * (1.852); 
                     string strSpeed = dSpeed.ToString(); 
                     pMarker = new PointShape(intLon, intLat); 
                     dictionaryAttributes = new Dictionary<string, string>(); 
                     dictionaryAttributes.Add("name", strEntityName); 
                     dictionaryAttributes.Add("datetime", strDate); 
                     dictionaryAttributes.Add("speed", strSpeed); 
      marLiveOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.ContentHtml = sbContentHtmlTrailMarker.ToString(); 
                     marLiveOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.Width = 250; 
                     marLiveOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.Height = 50; 
                     marLiveOverlay.Features.Add(new Feature(pMarker, dictionaryAttributes)); 
                     Proj4Projection objProj = (Proj4Projection)marLiveOverlay.FeatureSource.Projection; 
                     objProj.Open(); 
                     Map1.CenterAt((PointShape)objProj.ConvertToExternalProjection(pMarker)); 
  } 
 Thanks: 
 Kamal

Hi,


How can be get the distance between two points.


I am using the below code.


                    PointShape p1 = new PointShape(dbMinX, dblMinY);

                    PointShape p2 = new PointShape(dblMaxX, dblMaxY);

                    double dbDist = (double)Map1.GetScreenDistanceBetweenTwoWorldPoints(p1, p2);


                    double dbdist1 = Map1.GetWorldDistanceBetweenTwoScreenPoints(p1, p2);


 


I am getting the below error.


"worldExtent

Parameter name: The world extent is not valid."


I was trying to use GetWorldDistanceBetweenTwoScreenPoints also.Could you please help me if any.


Thanks:


Kamal



Kamal, 
  
 By default, you need to use this method after setting current extent. Because we cannot convert the screen points to world coordinate without any world information. Please have a try and let me know how it works. 
  
 For the code you attached, I cannot see what the exact value is; for example, you use projection to set the map’s center, but I’m not sure whether the marker’s position is in meter or decimal degree. I guess it’s the issue of placing a marker with its position in decimal degree to a map in meter unit. If it’s available, please provide us your data with a demo so that we can check the problem. 
  
 Thanks, 
 Howard

Hi Howard,


 Values for pointshape p1 is ( -119.41799926757812,18.450000762939453)


and for p2 is (139.69200134277344,51.500099182128906).


I have already posted sample code.Could you please look at the code  which I sent you on 5 Jan 10  and let me know for any clarification.


 


Thanks:


Kamal


 



Kamal, 
  
 The issue is not the value of p1 and p2. The post at "01-06-2010 08:36 AM " is because the extent is invalid. Please debug whether the Map1.CurrentExtent is null or other reason. If possible, please post the value of CurrentExtent here. 
  
 For the other question with the code, We want to check value in the data row or related value. So I want your demo to check for you. 
  
 Thanks and looking foward your feedback. 
  
 Thanks, 
 Howard 


would anyone know how to add and remove markers with the desktop edition in C#? 
 I tried putting this code in to look like the java code.  
 But this does not work.  
  
  marker.MouseDoubleClick += new MouseEventHandler(this.markerOverlay.Markers.Remove(this.marker));

 Gary,


 
For a good example of how to do this in the Desktop Edition with C# take a look at the "AddAnInMmeoryMarkerOverlay" sample under the Markers section of the HowDoIsamples that come with the Desktop Edition.  This will show you the code how to add markers. 
 
Thanks!

Hi Clint, I’ve taken a look at the sample,but I’m looking to edit/delete a marker by say double clicking on it. I want to add an event that I can code to happen when double clicking a marker. And to have that event affect the specified marker.

Gary, 
  
 Double Click is going to be tough because the InMemoryMarkerOverlay doesn’t expose the DoubleClickEvent, the main reason for this is that the Map Uses the DoubleClickEvent for zooming in by default.  I believe this can be changed but would take some work on your side.   
  
 However you can easily accomplish what you want with the InMemoryMarkerOverlay_Click event.  Using this event you will be able to tell what marker the user clicked on and do what ever operation you wish such as deleting the marker all together.  To see how this works take a look at the sample called ClickEventOnAMarker under the Markers section in the How Do I Sample apps. 
  
 I was able to easily delete a marker when clicking on it by making the two minor modifications: 
  
 In the Page_Load set the ID’s for the Features when you add them to the InMemoryMarkerOverlay. 
  
 markerOverlay.Features.Add(“Kansas”, new Feature(-94.48242, 38.75977, “Kansas”)); 
  markerOverlay.Features.Add(“Texas”, new Feature(-97, 32, “Texas”)); 
  
 In the markerOverlay_Click routine add the following line of code towards the bottom to delete the marker when the user clicks on it. 
  
 markerOverlay.Features.Remove(e.FeatureId); 
  
 Hope this helps, let us know if you have any additional questions. 
  
 Thanks

Hi, I can’t seem to find the “ClickEventOnAMarker” sample in the How Do I Samples. All I have under Markers are: 
 Add simple markers on the map 
 Add an InMemoryMakrerOverlay 
 Add a FeatureSource marker Overlay 
 Use a draggable marker 
 Drag to copy a marker

Gary, 
  
 Since this was posted in the Web Edition forum I thought you were wanting to do this using the Web Edition, but after reading more of the post it looks like you want to use the Desktop edition.  The Desktop edition doesn’t expose the ClickEvent on the InMemoryMarkerOverlay, however you can accomplish the same behavior by using the Map_Click event and then doing a spatial query to find the closest Marker in the InMemoryMarkerOvlery within a certain tolerance and then delete it or do any other custom action. 
  
 Thanks!

Hi Kamal. I know that passed many years but, if some need the solution, its this:



Try this, it’s work fine for me.



<script type=“text/javascript”>



        OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
            defaultHandlerOptions: {
                ‘single’: true,
                ‘double’: false,
                ‘pixelTolerance’: 0,
                ‘stopSingle’: false,
                ‘stopDouble’: false
            },



            initialize: function (options) {
                this.handlerOptions = OpenLayers.Util.extend(
                    {}, this.defaultHandlerOptions
                );
                OpenLayers.Control.prototype.initialize.apply(
                    this, arguments
                );
                this.handler = new OpenLayers.Handler.Click(
                    this, {
                        ‘click’: this.trigger
                    }, this.handlerOptions
                );
            },



            trigger: function (e) {
                var lonlat = map.getLonLatFromPixel(e.xy);
               // alert(“You clicked near " + lonlat.lat + " N, " +
                //                          +lonlat.lon + " E”);
                
                document.getElementById(’<% = txt_Latitude.ClientID %>’).value = lonlat.lat;
                document.getElementById(’<% = txt_Longitude.ClientID %>’).value = lonlat.lon;
            }
        })



        
        var map;
        function init() {
            map = new OpenLayers.Map(‘map’);



            // ‘map’ is your map created using new OpenLayers.Map(options)
           
        
            markers = new OpenLayers.Layer.Markers(“Markers”);
            markers.id = “Markers”;
            map.addLayer(markers);
            
           
            
            map.events.register(“click”, map, function (e) {
                //var position = this.events.getMousePosition(e);
                var position = map.getLonLatFromPixel(e.xy);
                var size = new OpenLayers.Size(21, 25);
                var offset = new OpenLayers.Pixel(-(size.w / 2), -size.h);
                var icon = new OpenLayers.Icon(’…/Images/IconsMarkers/iconKMarker.png’, size, offset);
                var markerslayer = map.getLayer(‘Markers’);
                
                if (markers != null) {
                    markers.clearMarkers();
                    markerslayer.addMarker(new OpenLayers.Marker(position, icon));
                }
                else {
                    markerslayer.removeMarker(markers);
                    markers.destroy();
                }
            });
            



            var ol_wms = new OpenLayers.Layer.WMS(“OpenLayers WMS”,
                "vmap0.tiles.osgeo.org/wms/vmap0?", { layers: ‘basic’ });



            var jpl_wms = new OpenLayers.Layer.WMS(“NASA Global Mosaic”,
                “t1.hypercube.telascience.org/cgi-bin/landsat7”,
                { layers: “landsat7” });



            jpl_wms.setVisibility(false);



            map.addLayers([ol_wms, jpl_wms]);
            //map.addControl(new OpenLayers.Control.LayerSwitcher());
            map.setCenter(new OpenLayers.LonLat(-101.228027, 22.71539), 5);
            //map.zoomToMaxExtent();
            //map.addPopup(popup);
            var click = new OpenLayers.Control.Click();
            map.addControl(click);
            
            click.activate();



        }



    </script>

Hello Yemmill,



Warm welcome to Map Suite Forums!

Really thanks for your sharing and thanks for the great Open Layers to allow us provide different solutions. :)



I checked your codes and looks very great except the custom Click control is not required. Besides, Howard also gave the same solution like yours in the first one reply and Kamal have many other questions which seems not like the original one like the title.



Thanks again for your sharing and hope you’ll have a good journey on map suite.

Troy