[ka-Map-users] kaXmlOverlay (from CVS) to query object with mouse click event.

The Bun rosario.carbone at ipl.com
Tue Oct 23 06:59:42 EDT 2007




The Bun wrote:
> 
> After many hours of testing I finally found a way to add an image and
> query all from the client and I think this can be useful to share with
> others ka-Mappers. I simply added some code and assigned an handler to
> “xml_overlay.handler_onclick” for each point added at the beginning of the
> myMapInitialized function of the startUp.js source.
> 
> Next step now is adding handlers when points objects are added with
> myXmlOverlay.loadXml('points.php'); the following code is to be considered
> as starting point, in fact it is hard coded:
> 
>     myXmlOverlay = new kaXmlOverlay( myKaMap, 250 );
>     //add this code to load the points xml file with point data to overlay
>     // Add the first point
>     var my_point = myXmlOverlay.addNewPoint("P3", 191041.51, 2695345.23);
>     var my_icon = new kaXmlIcon();
>     my_icon.icon_w = 28;
>     my_icon.icon_h = 28;
>     my_icon.icon_src = 'kamap.gif';
>     my_point.addGraphic(my_icon);
>     my_point.xml_overlay.handler_onclick = function ( my_point ) {
>                                                                     alert(
> my_point.pid );
>                                                                  };    
>     my_point.enableOnclick();
>     // Add the second point
>     var my_point2 = myXmlOverlay.addNewPoint("P4", 171041.51, 2895345.23);
>     var my_icon2 = new kaXmlIcon();
>     my_icon2.icon_w = 28;
>     my_icon2.icon_h = 28;
>     my_icon2.icon_src = 'kamap.gif';
>     my_point2.addGraphic(my_icon2);
>     my_point2.xml_overlay.handler_onclick = function ( my_point ) {
>                                                                     alert(
> my_point.pid );
>                                                                  };    
>     my_point.enableOnclick();	
> 
> N.B. I used the kaXmlOverlay.js of the the ka-Map daily CVS image because
> the standard version doesn’t implement any event handling, you, at this
> time I am testing don’t need to do any change at the code.
> 
> Have fun!
> 
> Rosario
> 

I then reckon a better technique is assigning the handling during the
loadXml method at some point in the kaXmlOverlay class. At the beginning of
the function myMapInitialized in startUp,js you need:


    myXmlOverlay = new kaXmlOverlay( myKaMap, 250 );
    myXmlOverlay.loadXml('points.php');

where point.php contains the actual points you want to add, like for
example:

<?php
header("Content-Type: text/xml");
header("Cache-Control: no-store, no-cache, must-revalidate");
echo '<?xml version="1.0" encoding="UTF-8"?>'
?>
<overlay>
  <point x="291041.51" y="3695345.23" id="P1">
    <label>Place1</label>
    <symbol shape="bullet" size="10" opacity="1" color="#FF0000" />
  </point>
  <point x="-1455207.55" y="1367013.15" id="P2">
    <label>Place2</label>
    <symbol shape="bullet" size="10" opacity="1" color="#FF0000" />
  </point>
</overlay>

Finally in the kaXmlOverlay.prototype.loadXmlDoc method after that a new
point has just added and pushed in the list of overlay points, I mean after:

    np = new kaXmlPoint(pid,this);
    this.ovrObjects.push(np);

You need to add:

    np.xml_overlay.handler_onclick = function ( np ) {
        alert( np.pid );
    };    
    np.enableOnclick();

The result for the two techniques is the same but I reckon this one is
cleaner.

Regards
Rosario
-- 
View this message in context: http://www.nabble.com/kaXmlOverlay-%28from-CVS%29-to-query-object-with-mouse-click-event.-tf4653999.html#a13361761
Sent from the ka-map-users mailing list archive at Nabble.com.




More information about the ka-Map-users mailing list