Permalink
Browse files

Mostly getting through a sample GeoJSON input and creating the extent…

…s and zooms that the pages table will need
  • Loading branch information...
Michal Migurski Michal Migurski
Michal Migurski authored and Michal Migurski committed Nov 10, 2011
1 parent 50c8c75 commit 5391b88210fd9a57efedcf64e4e06ce627cccc1f
View
@@ -11,7 +11,7 @@
"properties":
{
"provider": "http:\/\/tile.openstreetmap.org\/{Z}\/{X}\/{Y}.png",
- "zoom": 15
+ "zoom": 17
},
"type": "Feature",
"geometry":
@@ -24,13 +24,13 @@
"properties":
{
"provider": "http:\/\/tile.openstreetmap.org\/{Z}\/{X}\/{Y}.png",
- "zoom": 15
+ "zoom": 17
},
"type": "Feature",
"geometry":
{
- "type": "Polygon",
- "coordinates": [[ [-122.289914, 37.829211], [-122.289914, 37.813753], [-122.274464, 37.813753], [-122.274464, 37.829211], [-122.289914, 37.829211] ]]
+ "type": "Point",
+ "coordinates": [-122.281694, 37.822091]
}
}
]
@@ -0,0 +1,95 @@
+<?php
+
+ define('MMaps_Coordinate_Max_Zoom', 25);
+
+ class MMaps_Point
+ {
+ var $x;
+ var $y;
+
+ function MMaps_Point($x, $y)
+ {
+ $this->x = $x;
+ $this->y = $y;
+ }
+
+ function toString()
+ {
+ return sprintf('(%.3f, %.3f)', $this->x, $this->y);
+ }
+
+ function copy()
+ {
+ return new MMaps_Point($this->x, $this->y);
+ }
+ }
+
+ class MMaps_Coordinate
+ {
+ var $row;
+ var $column;
+ var $zoom;
+
+ function MMaps_Coordinate($row, $column, $zoom)
+ {
+ $this->row = $row;
+ $this->column = $column;
+ $this->zoom = $zoom;
+ }
+
+ function toString()
+ {
+ return sprintf('(%.3f, %.3f @%.3f)', $this->row, $this->column, $this->zoom);
+ }
+
+ function equalTo($other)
+ {
+ return $this->row == $other->row && $this->column == $other->column && $this->zoom == $other->zoom;
+ }
+
+ function copy()
+ {
+ return new MMaps_Coordinate($this->row, $this->column, $this->zoom);
+ }
+
+ function container()
+ {
+ return new MMaps_Coordinate(floor($this->row), floor($this->column), $this->zoom);
+ }
+
+ function zoomTo($destination)
+ {
+ return new MMaps_Coordinate($this->row * pow(2, $destination - $this->zoom),
+ $this->column * pow(2, $destination - $this->zoom),
+ $destination);
+ }
+
+ function zoomBy($distance)
+ {
+ return new MMaps_Coordinate($this->row * pow(2, $distance),
+ $this->column * pow(2, $distance),
+ $this->zoom + $distance);
+ }
+
+ function up($distance=1)
+ {
+ return new MMaps_Coordinate($this->row - $distance, $this->column, $this->zoom);
+ }
+
+ function right($distance=1)
+ {
+ return new MMaps_Coordinate($this->row, $this->column + $distance, $this->zoom);
+ }
+
+ function down($distance=1)
+ {
+ return new MMaps_Coordinate($this->row + $distance, $this->column, $this->zoom);
+ }
+
+ function left($distance=1)
+ {
+ return new MMaps_Coordinate($this->row, $this->column - $distance, $this->zoom);
+ }
+ }
+
+?>
View
@@ -0,0 +1,120 @@
+<?php
+
+ require_once 'Core.php';
+
+ class MMaps_Location
+ {
+ var $lat;
+ var $lon;
+
+ function MMaps_Location($lat, $lon)
+ {
+ $this->lat = $lat;
+ $this->lon = $lon;
+ }
+
+ function toString()
+ {
+ return sprintf('(%.3f, %.3f)', $this->lat, $this->lon);
+ }
+ }
+
+ class MMaps_Transformation
+ {
+ var $ax;
+ var $bx;
+ var $cx;
+ var $ay;
+ var $by;
+ var $cy;
+
+ function MMaps_Transformation($ax, $bx, $cx, $ay, $by, $cy)
+ {
+ $this->ax = $ax;
+ $this->bx = $bx;
+ $this->cx = $cx;
+ $this->ay = $ay;
+ $this->by = $by;
+ $this->cy = $cy;
+ }
+
+ function transform($point)
+ {
+ return new MMaps_Point($this->ax * $point->x + $this->bx * $point->y + $this->cx,
+ $this->ay * $point->x + $this->by * $point->y + $this->cy);
+ }
+
+ function untransform($point)
+ {
+ return new MMaps_Point(($point->x * $this->by - $point->y * $this->bx - $this->cx * $this->by + $this->cy * $this->bx) / ($this->ax * $this->by - $this->ay * $this->bx),
+ ($point->x * $this->ay - $point->y * $this->ax - $this->cx * $this->ay + $this->cy * $this->ax) / ($this->bx * $this->ay - $this->by * $this->ax));
+ }
+ }
+
+ class MMaps_Linear_Projection
+ {
+ var $zoom;
+ var $transformation;
+
+ function MMaps_Linear_Projection($zoom, $transformation=null)
+ {
+ $this->zoom = $zoom;
+ $this->transformation = is_null($transformation) ? new MMaps_Transformation(1, 0, 0, 0, 1, 0) : $transformation;
+ }
+
+ function rawProject($point)
+ {
+ return $point->copy();
+ }
+
+ function rawUnproject($point)
+ {
+ return $point->copy();
+ }
+
+ function project($point)
+ {
+ $point = $this->rawProject($point);
+ $point = $this->transformation->transform($point);
+ return $point;
+ }
+
+ function unproject($point)
+ {
+ $point = $this->transformation->untransform($point);
+ $point = $this->rawUnproject($point);
+ return $point;
+ }
+
+ function locationCoordinate($location)
+ {
+ $point = new MMaps_Point(M_PI * $location->lon / 180, M_PI * $location->lat / 180);
+ $point = $this->project($point);
+ $coordinate = new MMaps_Coordinate($point->y, $point->x, $this->zoom);
+ return $coordinate;
+ }
+
+ function coordinateLocation($coordinate)
+ {
+ $coordinate = $coordinate->zoomTo($this->zoom);
+ $point = new MMaps_Point($coordinate->column, $coordinate->row);
+ $point = $this->unproject($point);
+ $location = new MMaps_Location(180 * $point->y / M_PI, 180 * $point->x / M_PI);
+ return $location;
+ }
+ }
+
+ class MMaps_Mercator_Projection extends MMaps_Linear_Projection
+ {
+ function rawProject($point)
+ {
+ return new MMaps_Point($point->x, log(tan(0.25 * M_PI + 0.5 * $point->y)));
+ }
+
+ function rawUnproject($point)
+ {
+ return new MMaps_Point($point->x, 2 * atan(pow(M_E, $point->y)) - 0.5 * M_PI);
+ }
+ }
+
+?>
Oops, something went wrong.

0 comments on commit 5391b88

Please sign in to comment.