sg

Salı, Aralık 06, 2005

Pure PHP framework - preview and questions

Hi,
 I'm currently building a Google Maps framework without JS. Tell me what you think about it and please answer my few questions before I release it ;)

How it works for users?

1. Create a map document

It's a basic HTML file, with two div tagged as "map" and "info".
In the body, you have to include the php file and create your map.

Exemple :

    <div id="map" style="width: 1024px; height: 600px"></div>
    <div id="info" style="width: 1024px; height: 100px"></div>
<?
 
include 'google-maps.php';
 
displaymap( "map""ABQIAAAAjkvNer1lD2e6J9CLkI4udxRi_j0U6kJrkFvY4-OX2XYmEAa76BQjq4p15uMdUBVS_3mlJigNF5tK1A"
  
"http://127.0.0.1/eclipse/PHPGoogleMaps/TB.php""" );
?>

displaymap needs :
 - id of div used for map
 - Google Maps API key
 - trackback URL
 - options (not implemented yet)

As you can see, no data is needed in this file! Everything will happen in trackback.

2. Create trackback document

It has never been so easy to display dynamic data with PHP in Google Maps. This is an example of my current TB.php :

<?
 
// load php file
 
include 'google-maps.php';
 
// create interface object with map
 
$aMap = new GoogleMap();
 
// init all values
 
$aMap->Init();

 
// map is displaying
 
if ($aMap->mapaction == "init" ) {
  
// center and zoom the map     
  
$aMap->MoveAndZoom(-1.551818847656347.2029916218996);
 }

 
// if zoom has changed
 
if ($aMap->mapaction == "zoomed" ) {
  
// clear all objects added      
  
$aMap->AddClear();
 }

 
// user clicked on a marker
 // we can get id of point too here
 
if ($aMap->mapaction == "clicked" )
  {
      
// standard php array of points 
    
$points = array();
    
// rectangle from map bounds
    
$points[0][0] =  $aMap->Xmin;
    
$points[0][1] =  $aMap->Ymin;
    
$points[1][0] =  $aMap->Xmax;
    
$points[1][1] =  $aMap->Ymin;
    
$points[2][0] =  $aMap->Xmax;
    
$points[2][1] =  $aMap->Ymax;
    
$points[3][0] =  $aMap->Xmin;
    
$points[3][1] =  $aMap->Ymax;
    
$points[4][0] =  $aMap->Xmin;
    
$points[4][1] =  $aMap->Ymin;
    
// add the path
    
$aMap->AddTrace($points "#ff00ff"100.3);
  }

 
// get map center (should be calculated automaticaly)
 
$realx = ($aMap->Xmin  $aMap->Xmax)/2;
 
$realy = ($aMap->Ymin  $aMap->Ymax)/2;
 
$realzl $aMap->zlevel;

 
// a caption (html)
 
$caption $realx." - ". $realy." - ".$realzl;

 
// if the map hadn't caught a click event
 
if ($aMap->mapaction != "clicked" )
  
// add a new point
  
$aMap->AddPoint(
   (
$aMap->Xmin $aMap-> Xmax)/2,
   (
$aMap->Ymin $aMap-> Ymax)/2
   
1// (point id)
   
$caption// (displayed in the baloon tip) 
   
"http://www.google.com/mapfiles/markerD.png// marker icon URL
   
);

 
// if map has been dragged
 
if ($aMap->mapaction == "moved" )
  
// display the coordinates in info div
  
$aMap->DisplayInfo(
    
"info",
    
$caption);

 
// send scenario to map
 
$aMap->ShowXMLforAJAX();
?>

And that's all. You don't have to mix PHP and JS in your code, it just works.

The code is not really complicated (about 8ko of code...). It is not really easy to add a Google Map feature. If you want for example change the overlay, you have to modify PHP class and XML JS parsing. Anyway, the code is fully asynchronous, so it would be a good idea to implement a "loading" feature.
Oh and yes I have put AJAX for my XML generation function, but I'm not really sure that GXmlHttp is AJAX, because I don't really know what it means :)

My main problem actually is the center and zoom. When center request is managed by JS, it looks OK but tiles don't load or even worse when I zoom out after, I catch a level 17... Any idea?

I will certainly add direct GPX handling, as I really need it (and my class is 99% ready).

Let's see an example :
http://gabriel.landais.org/testGM/

Sources :
http://gabriel.landais.org/testGM/index.phps
http://gabriel.landais.org/testGM/google-maps.phps
http://gabriel.landais.org/testGM/map.inc.phps
http://gabriel.landais.org/testGM/TB.phps

That's all

Gabriel

--
http://gabriel.landais.org/component/option,com_places/

0 Comments:

Yorum Gönder

<< Home


Komik Videolar   islam  şarkı sözleri  yemek tarifleri  gelibolu  huzur   sağlık