[ka-Map-users] Function to clear addObjectGeo

Paul Spencer pspencer at dmsolutions.ca
Wed Mar 22 09:22:54 EST 2006


not sure if I commented on this before, but it should be noted that a  
function like this already exists (removeObject) but it doesn't allow  
you to clear all the overlays on a single canvas, it only allows  
removing individual overlays or all overlays.

Is there interest in adding this function?  I don't see a need for it  
as I usually manage the overlays separately from kaMap and thus have  
have a reference to the things that need to be removed.

Cheers

Paul

On 5-Mar-06, at 12:56 PM, Brent Pedersen wrote:

> hi chris, another utility function you'll use:
>
> kaMap.prototype.removeOverlays = function(canvas){
> len = this.aObjects.length;
> for(i=0;i
> var item = this.aObjects[i];
> if(item.canvas == canvas){
> canvas.removeChild(item);
> item.canvas = null;
> item = null;
> this.aObjects.splice(i--,1);
> len = this.aObjects.length;
> }
> }
> }
>
> then call myKaMap.removeOverlays(myCanvas) at the start of  
> drawMarkers. because otehrwise, you jsut keep adding new markers  
> without getting rid of the old ones. and it will get rid of them  
> when you're not at the scale you want.
>
> also as you have it now, you're creating a new canvas every time  
> drawMarkers is called. probably bad.
>
> i'm not sure about the memory leakage of any of this...
> -b
>
>
>
>
> On 3/5/06, Base Bloc < chris at basebloc.com> wrote:
> Hi Guys,
>
>
> I'm still plugging away to get some workable functions together to  
> draw markers with tool-tips and it's hard work as I'm experienced  
> with PHP but not so hot on JavaScript and DOM so am making all the  
> usual mistakes but getting there slowly. I now have a system in  
> place that at a curtain scale places markers within an extended  
> extent of the visible map tiles using HttpRequest. All is working  
> fine and I currently have the system getting markers from a  
> database to place markers on the map at the required scale  
> (1:300000), then adding more markers as the map is panned.
>
>
> The problem I'm encountering now is that although the function is  
> working correctly as in it won't add markers+tool-tips until the  
> map is zoomed to 1:300000 when the map is zoomed back out above  
> 1:300000 the markers previously called all remain on screen and as  
> there are over 7000 points you can imagine what this looks like at  
> 1:4000000.
>
>
> Is there a simple way to clear all of the markers created by  
> addObjectGeo when the map is zoomed out past a curtain scale or  
> better yet add an event related to myKaMap.getCurrentScale() so  
> they are only displayed when the scale in greater than X?
>
>
> Here are the functions I'm using at present:
>
>
> //creates separate image for each marker
>
> function create_marker (img_id, var_1, lat, lon)
>
>             {
>
>
>     document[img_id] = document.createElement( 'img' );
>
>     document[img_id].src = 'images/kamap.gif';
>
>
>                         var bname = navigator.appName;
>
>                         if (bname == "Microsoft Internet Explorer")
>
>                {
>
>                         document[img_id].attachEvent 
> ("onmouseover",tool_tip)
>
>                         document[img_id].attachEvent 
> ("onmouseout",tool_tip_out)
>
>                         document[img_id].attachEvent 
> ("onclick",page_link)
>
>                }
>
>                         else
>
>                {
>
>                         document[img_id].addEventListener 
> ("mouseover",tool_tip,false)
>
>                         document[img_id].addEventListener 
> ("mouseout",tool_tip_out,false)
>
>                         document[img_id].addEventListener 
> ("click",page_link,false)
>
>                }
>
>
>                                     //Sends content and format  
> options to tool-tip
>
>                                     function tool_tip(){
>
>
>                                                 var test_var = var_1;
>
>                                                 var text = "My name  
> is " +test_var+ ", and I'm am now understanding JavaScripts";
>
>                                                 overlib(text,  
> STICKY, MOUSEOFF, CAPTION, 'info')
>
>                                                 }
>
>
>     myKaMap.addObjectGeo( myCanvas, lat, lon, document[img_id] );
>
>
>             }
>
>
>             function drawMarkers(){
>
>   Big_Extents = myKaMap.getGeoExpandedExtents();
>
>   myCanvas = myKaMap.createDrawingCanvas( 5000 );
>
>
>   //draw Markers within Big_Extents using kaXMLOverlay or just  
> addObjectGeo()
>
>
>             var scale = myKaMap.getCurrentScale();
>
>
>             if (scale <= 200000)
>
>             {
>
>
>             //this is where the HttpRequest would normally go, but  
> I have placed a couple of sample markers to make the script more clear
>
>             create_marker('C02573', 'Box', 511275, 1363860);
>
>             create_marker('C02574', 'Pipe', 515736, 1364260);
>
>
>             }
>
>
> }
>
>
> var scale = myKaMap.getCurrentScale();
>
>
>
>             myKaMap.registerForEvent( KAMAP_SCALE_CHANGED, null,  
> drawMarkers );
>
>             myKaMap.registerForEvent( KAMAP_EXTENTS_CHANGED, null,  
> maybeRedraw );
>
>             myKaMap.registerForEvent( KAMAP_MAP_INITIALIZED, null,  
> drawMarkers );
>
>
> }
>
>
> Sorry there are a few calls to functions there which I have not  
> added above, I didn't want to do a 500 line cut and paste, once I  
> have it working properly I will post the full code and related  
> functions.
>
>
> Any suggestions on a fix to this problem would be appreciated.
>
>
> Thanks,
>
>
> Chris
>
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Christopher Brown
>
> Head of Internet Development
>
> Base Bloc Cambodia
>
> #33, 123, Phnom Penh, Cambodia.
>
> P.O. Box 2086
>
> www.basebloc.com
>
> Tel (+885) 12 315 302
>
>
>
> _______________________________________________
> ka-Map-users mailing list
> ka-Map-users at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/ka-map-users
>
>
>
> _______________________________________________
> ka-Map-users mailing list
> ka-Map-users at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/ka-map-users

+-----------------------------------------------------------------+
|Paul Spencer                           pspencer at dmsolutions.ca   |
+-----------------------------------------------------------------+
|Applications & Software Development                              |
|DM Solutions Group Inc                 http://www.dmsolutions.ca/|
+-----------------------------------------------------------------+






More information about the ka-Map-users mailing list