<pre>hi chris, another utility function you'll use:<br><br>kaMap.prototype.removeOverlays = function(canvas){<br>        len = this.aObjects.length;<br> for(i=0;i<len;i++){ <br>         var item = this.aObjects[i];<br>                if(item.canvas
== canvas){<br>                 canvas.removeChild(item);<br>                        item.canvas = null;<br> item = null;<br>                 this.aObjects.splice(i--,1);<br>                        len = this.aObjects.length;<br>                }<br>        }<br>}<br></pre>
<br>
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.<br>
<br>
<font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">also as you have it now, you're creating a new canvas every time drawMarkers is called. probably bad.<br>
<br>
i'm not sure about the memory leakage of any of this... <br>
-b<br>
<br>
<br></span></font><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"></span></font><br><br><div><span class="gmail_quote">On 3/5/06, <b class="gmail_sendername">Base Bloc</b> <<a href="mailto:chris@basebloc.com">
chris@basebloc.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div style="direction: ltr;">
<div>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Hi Guys,</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">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.</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">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.</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">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?</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Here are the functions I'm using at present:</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">//creates separate image for each marker</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">function create_marker (img_id, var_1, lat, lon)</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> {</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> document[img_id] =
document.createElement( 'img' );</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> document[img_id].src =
'images/kamap.gif';</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">
var
bname = navigator.appName;</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">
if
(bname == "Microsoft Internet Explorer")</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">
{</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">
document[img_id].attachEvent("onmouseover",tool_tip)</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">
document[img_id].attachEvent("onmouseout",tool_tip_out)</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">
document[img_id].attachEvent("onclick",page_link)</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">
}</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">
else</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">
{</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">
document[img_id].addEventListener("mouseover",tool_tip,false)</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">
document[img_id].addEventListener("mouseout",tool_tip_out,false)</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">
document[img_id].addEventListener("click",page_link,false)</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">
}</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">
</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">
//Sends
content and format options to
tool-tip </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">
function
tool_tip(){ </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">
var
test_var = var_1;</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">
var
text = "My name is " +test_var+ ", and I'm am now understanding
JavaScripts";</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">
overlib(text,
STICKY, MOUSEOFF, CAPTION, 'info')</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">
}</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> myKaMap.addObjectGeo( myCanvas, lat, lon,
document[img_id] );</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> }</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> function
drawMarkers(){</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> Big_Extents = myKaMap.getGeoExpandedExtents();</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> myCanvas = myKaMap.createDrawingCanvas( 5000 );</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> //draw Markers within Big_Extents using kaXMLOverlay
or just addObjectGeo()</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> var
scale = myKaMap.getCurrentScale();</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> if
(scale <= 200000)</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> {</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> //this
is where the HttpRequest would normally go, but I have placed a couple of
sample markers to make the script more clear</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> create_marker('C02573',
'Box', 511275, 1363860);</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> create_marker('C02574',
'Pipe', 515736, 1364260);</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> }</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">}</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">var scale = myKaMap.getCurrentScale();</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> myKaMap.registerForEvent(
KAMAP_SCALE_CHANGED, null, drawMarkers );</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> myKaMap.registerForEvent(
KAMAP_EXTENTS_CHANGED, null, maybeRedraw );</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> myKaMap.registerForEvent(
KAMAP_MAP_INITIALIZED, null, drawMarkers );</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">}</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">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.</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Any suggestions on a fix to this problem would be
appreciated.</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Thanks,</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Chris</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font color="navy" face="Arial" size="1"><span style="font-size: 8pt; font-family: Arial; color: navy;">~~~~~~~~~~~~~~~~~~~~~~~~~~~</span></font></p>
<p><font color="navy" face="Arial" size="1"><span style="font-size: 8pt; font-family: Arial; color: navy;">Christopher Brown</span></font></p>
<p><font color="navy" face="Arial" size="1"><span style="font-size: 8pt; font-family: Arial; color: navy;">Head of Internet Development</span></font></p>
<p><font color="navy" face="Arial" size="1"><span style="font-size: 8pt; font-family: Arial; color: navy;">Base Bloc Cambodia</span></font></p>
<p><font color="navy" face="Arial" size="1"><span style="font-size: 8pt; font-family: Arial; color: navy;">#33, 123, Phnom Penh, Cambodia.
</span></font></p>
<p><font color="navy" face="Arial" size="1"><span style="font-size: 8pt; font-family: Arial; color: navy;">P.O. Box</span></font><font color="navy" face="Arial" size="1"><span style="font-size: 8pt; font-family: Arial; color: navy;">
2086</span></font><font color="navy" face="Arial" size="1"><span style="font-size: 8pt; font-family: Arial; color: navy;"></span></font></p>
<p><font color="navy" face="Arial" size="1"><span style="font-size: 8pt; font-family: Arial; color: navy;"><a href="http://www.basebloc.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">www.basebloc.com
</a></span></font></p>
<p><font color="navy" face="Arial" size="1"><span style="font-size: 8pt; font-family: Arial; color: navy;">Tel (+885) 12 315 302</span></font></p>
<p><font face="Times New Roman" size="2"> </font></p>
</div>
</div><br>_______________________________________________<br>ka-Map-users mailing list<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:ka-Map-users@lists.maptools.org">ka-Map-users@lists.maptools.org
</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://lists.maptools.org/mailman/listinfo/ka-map-users" target="_blank">http://lists.maptools.org/mailman/listinfo/ka-map-users</a><br><br><br></blockquote>
</div><br>