Reply To: KMLin custom php map

Home Forums MapPress Support KMLin custom php map Reply To: KMLin custom php map

#10969
Chris
Keymaster

Hi, to format code click the kitchen sink icon on the right of the editor toolbar, then change ‘paragraph’ format to ‘preformatted’.

Sorry, I should’ve tested the code first.  There are two problems:

1 – I gave you the wrong syntax.  The KML parameter should itself be an array with ‘url’ as an element (I thought I might eventually add more KML options).  Corrected code is below.

2-  when a KML is added programmatically (vs. in the Map Editor)  it doesn’t have a center until the file is loaded.  I hadn’t considered that case and the map ends up centering on NULL, which gives a blank map.

I can easily update the code to use (0,0) as the center if the KML isn’t loaded – but then the map won’t automatically center correctly.

A better solution is to load the POIs asynchronously, but that may require a lot of re-coding.  Do you plan to set a map center explicitly, or did you need it to automatically center using the KML data?

If you like, send me a note using the contact form and I can send you the 0,0 fix to try out right away.  Otherwise, I’ll work on the other solution but I can’t say yet when it will be ready.

 

$mymap = new Mappress_Map(array("width" => "100%")); 
$mypoi_1= new Mappress_Poi(array("iconid" => "green-dot", "title" => "KML Example", "type" => "kml", "kml" => array("url" => "http://kml-samples.googlecode.com/svn/trunk/kml/Region/polygon-min-max.kml"))); 
$mypoi_2 = new Mappress_Poi(array("title" => "500 Chestnut St", "body" => "Independence National Park, Philadelphia, PA<br/>19106", "point" => array("lat" => 39.948712,"lng" => -75.15001))); 
$mymap->pois = array($mypoi_1, $mypoi_2); 
echo $mymap->display(array("directions"=>"none"));