<?php require_once 'class.polylineEncoder.php'; // read points from file (bristish shoreline from http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/BritishCoastline.html $points = file('BritishShoreline.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); foreach ($points as $key => $point) { $points[$key] = explode(',', $point); } $encoder = new PolylineEncoder(); $polyline = $encoder->encode($points); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>Google Maps JavaScript API Example</title> <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAANE0WF4ORtlpNk94qhyLbixTU4XYMib-DjEpB6gWbEqPTdmn-qhTJDTeEJNLFrmU7IWoTLQxpGVxRqg" type="text/javascript"></script> <script type="text/javascript"> //<![CDATA[ function load() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map")); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.addControl(new GScaleControl()); map.setCenter(new GLatLng(54.3, -2.23), 4);
/** * Afficher le formulaire d'ajout/édition de parcours * * @param array $params Paramètres * * @return string HTML * */ public function getHtmlFormulaireParcours($params = array()) { $html = ""; $bbCode = new bbCodeObject(); $recherche = new archiRecherche(); $idParcours = 0; $libelleParcours = ""; $titre = "Ajout d'un parcours"; $formAction = $this->creerUrl('ajouterParcours', 'adminListeParcours', array()); $checkedActif = false; $dateAjout = date("d/m/Y"); $commentaireParcours = ""; $idSource = "0"; $libelleSource = ""; if (isset($this->variablesGet['archiIdParcours']) && $this->variablesGet['archiIdParcours'] != '') { $d = new dateObject(); $titre = "Modification d'un parcours"; $idParcours = $this->variablesGet['archiIdParcours']; $reqParcours = "\n SELECT p.idParcours as idParcours,p.libelleParcours as libelleParcours,p.isActif as isActif,p.dateAjoutParcours as dateAjoutParcours,p.commentaireParcours as commentaireParcours,\n s.nom as nomSource, tp.nom as nomTypeSource, s.idSource as idSource\n FROM parcoursArt p\n LEFT JOIN source s ON s.idSource = p.idSource\n LEFT JOIN typeSource tp ON tp.idTypeSource = s.idTypeSource\n WHERE p.idParcours = '" . $idParcours . "'"; $resParcours = $this->connexionBdd->requete($reqParcours); $fetchParcours = mysql_fetch_assoc($resParcours); $libelleParcours = $fetchParcours['libelleParcours']; $commentaireParcours = $fetchParcours['commentaireParcours']; $libelleSource = stripslashes($fetchParcours['nomSource'] . " (" . $fetchParcours['nomTypeSource'] . ")"); $idSource = $fetchParcours['idSource']; $dateAjout = $d->toFrenchAffichage($fetchParcours['dateAjoutParcours']); if ($fetchParcours['isActif'] == 1) { $checkedActif = true; } $formAction = $this->creerUrl('modifierParcours', 'adminListeParcours', array()); } $html .= "<h1>{$titre}</h1>"; $arrayBBCode = $bbCode->getBoutonsMiseEnFormeTextArea(array('formName' => 'formParcours', 'fieldName' => 'commentaireParcours')); //coords $reqListeEtapes = "SELECT idEvenementGroupeAdresse FROM etapesParcoursArt WHERE idParcours = '" . $idParcours . "'"; $resListeEtapes = $this->connexionBdd->requete($reqListeEtapes); $a = new archiAdresse(); while ($fetchListeEtapes = mysql_fetch_assoc($resListeEtapes)) { $coords = $a->getCoordonneesFrom($fetchListeEtapes['idEvenementGroupeAdresse'], 'idEvenementGroupeAdresse'); $points[] = $coords["latitude"] . ", " . $coords["longitude"]; } $html .= "<br/><br/>"; include_once "includes/class.polylineEncoder.php"; foreach ($points as $key => $point) { $points[$key] = explode(',', $point); } $encoder = new PolylineEncoder(); @($polyline = $encoder->encode($points)); $reqTrace = "SELECT trace, levels FROM `parcoursArt` WHERE `idParcours` = " . mysql_escape_string($idParcours); $resTrace = $this->connexionBdd->requete($reqTrace); $trace = mysql_fetch_assoc($resTrace); // $configFields = array('idParcours' => array('libelle' => 'idParcours', 'type' => 'hidden', 'error' => '', 'value' => '', 'default' => $idParcours, 'htmlCode' => ''), 'dateAjoutParcours' => array('libelle' => 'date ajout', 'type' => 'date', 'error' => '', 'value' => '', 'default' => $dateAjout, 'htmlCode' => '', 'withDatePicker' => true), 'isActif' => array('libelle' => 'est actif', 'type' => 'singleCheckBox', 'error' => '', 'value' => '', 'default' => '', 'htmlCode' => '', 'isChecked' => $checkedActif, 'forceValueTo' => '1'), 'libelleParcours' => array('libelle' => 'libelle', 'type' => 'text', 'error' => '', 'value' => '', 'default' => $libelleParcours, 'htmlCode' => "style='width:300px;'"), 'commentaireParcours' => array('libelle' => 'commentaire', 'type' => 'bigText', 'error' => '', 'value' => '', 'default' => $commentaireParcours, 'htmlCode' => "style='width:400px;height:200px;'", 'htmlCodeBeforeField' => $arrayBBCode['boutonsHTML'], 'htmlCode2' => $arrayBBCode['divAndJsAfterForm']), 'idSourcetxt' => array('libelle' => 'source', 'type' => 'text', 'error' => '', 'value' => '', 'default' => $libelleSource, 'htmlCode' => '', 'htmlCode2' => "<input type='button' name='choixSource' onclick=\"document.getElementById('calqueSource').style.top=(getScrollHeight()+150)+'px';document.getElementById('calqueSource').style.display='block';document.getElementById('paramChampsAppelantSource').value='idSource';\" value='Choisir'>"), 'idSource' => array('libelle' => 'idSource', 'type' => 'hidden', 'error' => '', 'value' => '', 'default' => $idSource, 'htmlCode' => ""), "polyline" => array("libelle" => _("Liste des coordonnées") . " (" . _("à utiliser avec") . " <a href='https://developers.google.com/maps/documentation/utilities/polylineutility'>Interactive Polyline Encoder</a>)", "type" => "text", "default" => $polyline->points, "htmlCode" => "readonly onclick='this.select();'", "error" => ""), "levels" => array("libelle" => _("Niveaux"), "type" => "text", "default" => $polyline->levels, "htmlCode" => "readonly onclick='this.select();'", "error" => ""), "trace" => array("libelle" => _("Coordonnées détaillées"), "type" => "text", "default" => $trace["trace"], "htmlCode" => "", "error" => ""), "newLevels" => array("libelle" => _("Niveaux détaillés"), "type" => "text", "default" => $trace["levels"], "htmlCode" => "", "error" => "")); $configForm = array('fields' => $configFields, 'formAction' => $formAction, 'formName' => 'formParcours'); $f = new formGenerator(); $html .= $f->afficherFromArray($configForm); $this->addToJsHeader($recherche->getPopupChoixSource('ajoutModifParcoursAdmin')); return $html; }
/** * Code to build a polyline circle, stolen from: * http://stackoverflow.com/questions/7316963/drawing-a-circle-google-static-maps * Needed for drawing radius circle on static maps * * @param unknown_type $Lat * @param unknown_type $Lng * @param unknown_type $Rad * @param unknown_type $Detail */ protected function GMapCircle($Lat, $Lng, $Rad, $Detail = 8) { $R = 6371; $pi = pi(); $Lat = $Lat * $pi / 180; $Lng = $Lng * $pi / 180; $d = $Rad / $R; $points = array(); $i = 0; for ($i = 0; $i <= 360; $i += $Detail) { $brng = $i * $pi / 180; $pLat = asin(sin($Lat) * cos($d) + cos($Lat) * sin($d) * cos($brng)); $pLng = ($Lng + atan2(sin($brng) * sin($d) * cos($Lat), cos($d) - sin($Lat) * sin($pLat))) * 180 / $pi; $pLat = $pLat * 180 / $pi; $points[] = array($pLat, $pLng); } require_once COM_FABRIK_FRONTEND . DS . 'libs' . DS . 'googlemaps' . DS . 'polyline_encoder' . DS . 'class.polylineEncoder.php'; $PolyEnc = new PolylineEncoder(); $EncString = $PolyEnc->encode($points); return $EncString->points; }
/** * Encode a geometry obtained vi gisQuery::getEWKT into an encodedpolyline * http://code.google.com/apis/maps/documentation/polylinealgorithm.html */ function _polyline_encode($geom) { $points = explode(',', $geom); foreach ($points as $key => $point) { $coords = explode(' ', $point); $points[$key] = array(floatval($coords[1]), floatval($coords[0])); } $encoder = new PolylineEncoder(); return $encoder->encode($points)->rawPoints; }