#1 Tue 04 May 2010 15:16
- Geomatikman
- Juste Inscrit !
- Date d'inscription: 27 Jul 2009
- Messages: 6
OpenLayers+Markers dynamique
salut,
Maintenant j'ai un petit souci.Je veux afficher les markers dynamiquement en fonctions de coordonnées; et voila ce que j'ai fait;
je remplace coordonnée manuelle en lonlat.lon et lonlat.lat existant dans une page PHP et je l'appel come ca:
document.write('<?php include ("resultat.php"); ?>');
Le fichier .js dans une page;
Code:
function PINIZE() { var lonlat='<?php echo ($lonlat); ?>'; var gphys = new OpenLayers.Layer.Google( "Relief", {'type': G_PHYSICAL_MAP , 'transparent': true, 'sphericalMercator': true} map = new OpenLayers.Map( 'map_canvas'); map.addControl(new OpenLayers.Control.PanZoomBar()); map.addLayers([gphys]); //Creation du layer Marker markers = new OpenLayers.Layer.Markers("Marker"); map.addLayer(markers); //Creation du Marker feature = new OpenLayers.Feature(gphys, new OpenLayers.LonLat(lonlat.lon,lonlat.lat)); marker = feature.createMarker(); markers.addMarker(marker); marker.events.register("mousedown", marker, mousedown); //Gestion des evenements function mousedown(evt) { popup = feature.createPopup(true); popup.setContentHTML("Exemple de PopUp sur un marqueur"); popup.setBackgroundColor("Yellow"); popup.setOpacity(0.6); markers.map.addPopup(popup); } ); if(!map.getZoom()) { map.setCenter(new OpenLayers.LonLat(lonlat.lon,lonlat.lat)); map.zoomTo(6); } }
La page resultat.php:
Code:
include ("connexion.php"); $rechNomCom = $_GET['rechNomCom']; $result = mysql_query("select nom, id, x, y, statut from localite where nom like '%".$rechNomCom."%' ;"); while($tabRes = mysql_fetch_array($result)) { if ($tabRes['statut'] == 'AME') { $nomRes[] = "AME".$tabRes['nom']; $zoomRes[] = "5"; $departementRes[] = ""; $xRes[] = $tabRes['x']; $yRes[] = $tabRes['y']; } } for($i=0; $i<sizeof($nomRes); $i++) { echo "<li style='margin-top:10px; list-style-type:none;'><div style='color:#005a9f; text-decoration:underline; cursor:pointer;' onclick=' var lonlat = OpenLayers.Layer.SphericalMercator.forwardMercator(".$xRes[$i].", ".$yRes[$i]."); map.setCenter(new OpenLayers.LonLat(lonlat.lon, lonlat.lat), ".$zoomRes[$i]."); PINIZE(); '>".$nomRes[$i].($departementRes[$i] != "" ? " - ".$departementRes[$i] : "")."</div></li>"; }
le souci je crois est que lonlat.lon /lat ne sont pas reconnu dans pinize()??
Y-a t il quelqu'un pour aide?
Hors ligne