[gnome-maps] geoJSON: Clamp bounding box
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps] geoJSON: Clamp bounding box
- Date: Thu, 25 Feb 2016 18:41:31 +0000 (UTC)
commit 6f320fac1f455cbc21976e36f4270e672da07511
Author: Razvan Brinzea <razvan brinzea gmail com>
Date: Thu Feb 25 20:33:27 2016 +0200
geoJSON: Clamp bounding box
Some bounding boxes calculted from geoJSON layers
where invalid bouding boxes in the eyes of libchamplain.
geoJSONSource now offers valid bounding boxes for layers
with geometries that have latitude very close to -90
or 90.
src/geoJSONSource.js | 9 +++++++++
src/mapView.js | 9 +++++++++
2 files changed, 18 insertions(+), 0 deletions(-)
---
diff --git a/src/geoJSONSource.js b/src/geoJSONSource.js
index dd4e514..f549169 100644
--- a/src/geoJSONSource.js
+++ b/src/geoJSONSource.js
@@ -30,6 +30,7 @@ const Place = imports.place;
const PlaceMarker = imports.placeMarker;
const Utils = imports.utils;
const GeoJSONStyle = imports.geoJSONStyle;
+const MapView = imports.mapView;
const TILE_SIZE = 256;
@@ -104,6 +105,13 @@ const GeoJSONSource = new Lang.Class({
}).bind(this));
},
+ _clampBBox: function() {
+ this._bbox.top = Math.min(this._bbox.top, MapView.MAX_LATITUDE);
+ this._bbox.left = Math.max(this._bbox.left, MapView.MIN_LONGITUDE);
+ this._bbox.bottom = Math.max(this._bbox.bottom, MapView.MIN_LATITUDE);
+ this._bbox.right = Math.min(this._bbox.right, MapView.MAX_LONGITUDE);
+ },
+
_parseLineString: function(coordinates) {
this._compose(coordinates);
},
@@ -207,6 +215,7 @@ const GeoJSONSource = new Lang.Class({
this._parseInternal(json);
this._tileIndex = Geojsonvt.geojsonvt(json, { extent: TILE_SIZE,
maxZoom: 20 });
+ this._clampBBox();
},
_renderTile: function(tile) {
diff --git a/src/mapView.js b/src/mapView.js
index 2bf8f04..3955e81 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -55,6 +55,15 @@ const MapType = {
const _LOCATION_STORE_TIMEOUT = 500;
const MapMinZoom = 2;
+/*
+ * Due to the mathematics of spherical mericator projection,
+ * the map must be truncated at a latitude less than 90 degrees.
+ */
+const MAX_LATITUDE = 85.05112;
+const MIN_LATITUDE = -85.05112;
+const MAX_LONGITUDE = 180;
+const MIN_LONGITUDE = -180;
+
const MapView = new Lang.Class({
Name: 'MapView',
Extends: GtkChamplain.Embed,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]