| 154 | | |
|---|
| | 163 | |
|---|
| | 164 | def locationPoint(self, location): |
|---|
| | 165 | """ Return an x, y point on the map image for a given geographical location. |
|---|
| | 166 | """ |
|---|
| | 167 | point = Core.Point(self.offset.x, self.offset.y) |
|---|
| | 168 | coord = self.provider.locationCoordinate(location).zoomTo(self.coordinate.zoom) |
|---|
| | 169 | |
|---|
| | 170 | # distance from the known coordinate offset |
|---|
| | 171 | point.x += self.provider.tileWidth() * (coord.column - self.coordinate.column) |
|---|
| | 172 | point.y += self.provider.tileHeight() * (coord.row - self.coordinate.row) |
|---|
| | 173 | |
|---|
| | 174 | # because of the center/corner business |
|---|
| | 175 | point.x += self.dimensions.x/2 |
|---|
| | 176 | point.y += self.dimensions.y/2 |
|---|
| | 177 | |
|---|
| | 178 | return point |
|---|
| | 179 | |
|---|
| | 180 | def pointLocation(self, point): |
|---|
| | 181 | """ Return a geographical location on the map image for a given x, y point. |
|---|
| | 182 | """ |
|---|
| | 183 | hizoomCoord = self.coordinate.zoomTo(Core.Coordinate.MAX_ZOOM) |
|---|
| | 184 | |
|---|
| | 185 | # because of the center/corner business |
|---|
| | 186 | point = Core.Point(point.x - self.dimensions.x/2, |
|---|
| | 187 | point.y - self.dimensions.y/2) |
|---|
| | 188 | |
|---|
| | 189 | # distance in tile widths from reference tile to point |
|---|
| | 190 | xTiles = (point.x - self.offset.x) / self.provider.tileWidth(); |
|---|
| | 191 | yTiles = (point.y - self.offset.y) / self.provider.tileHeight(); |
|---|
| | 192 | |
|---|
| | 193 | # distance in rows & columns at maximum zoom |
|---|
| | 194 | xDistance = xTiles * math.pow(2, (Core.Coordinate.MAX_ZOOM - self.coordinate.zoom)); |
|---|
| | 195 | yDistance = yTiles * math.pow(2, (Core.Coordinate.MAX_ZOOM - self.coordinate.zoom)); |
|---|
| | 196 | |
|---|
| | 197 | # new point coordinate reflecting that distance |
|---|
| | 198 | coord = Core.Coordinate(round(hizoomCoord.row + yDistance), |
|---|
| | 199 | round(hizoomCoord.column + xDistance), |
|---|
| | 200 | hizoomCoord.zoom) |
|---|
| | 201 | |
|---|
| | 202 | coord = coord.zoomTo(self.coordinate.zoom) |
|---|
| | 203 | |
|---|
| | 204 | location = self.provider.coordinateLocation(coord) |
|---|
| | 205 | |
|---|
| | 206 | return location |
|---|
| | 207 | |
|---|