array_push ($stack, array($maxLoc, $current[1]));}}} $encodedPoints = $this->createEncodings ($points, $dists);$encodedLevels = $this->encodeLevels ($points, $dists, $absMaxDist);return array ('encodedPoints' => $encodedPoints,'encodedLevels' => $encodedLevels,'encodedPointsLiteral' => str_replace('\\',"\\\\",$encodedPoints));}public function dpEncodeToJson ($points, $color='#0000ff', $weight=3,$opacity=0.9) {$result = $this->dpEncode(points);return array ('color' => $color,'weight' => $weight,'opacity' => $opacity,'points' => $result['encodedPoints'],'levels' => $result['encodedLevels'],'numLevels' => $this->numLevels,'zoomFactor' => $this->zoomFactor);}# distance(p0, p1, p2) computes the distance between the point p0 and thesegment [p1,p2]. This could probably be replaced with# something that is a bit more numerically stable.private function distance ($p0, $p1, $p2, $segLength) {$out = null;if($p1->lat() === $p2->lat() && $p1->lng() === $p2->lng()) {$out = sqrt(pow($p2->lat()-$p0->lat(),2) + pow($p2->lng()-$p0->lng(),2));}else {$u = (($p0->lat()-$p1->lat())*($p2->lat()-$p1->lat())+($p0->lng()-$p1->lng())*($p2->lng()-$p1->lng()))/$segLength; if($u <= 0) {$out = sqrt(pow($p0->lat() - $p1->lat(),2) + pow($p0->lng() - $p1->lng(),2));}if($u >= 1) {$out = sqrt(pow($p0->lat() - $p2->lat(),2) + pow($p0->lng() - $p2->lng(),2));}if(0 < $u && $u < 1) {$out = sqrt(pow($p0->lat()-$p1->lat()-$u*($p2->lat()-$p1->lat()),2) +pow($p0->lng()-$p1->lng()-$u*($p2->lng()-$p1->lng()),2));}}return $out;}
Add a Comment