summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <cb15g11@soton.ac.uk>2014-09-06 18:30:13 +0100
committerChristopher Baines <cb15g11@soton.ac.uk>2014-09-06 18:30:13 +0100
commit903dbcd6c4c4343355008aabe0b98afa52159313 (patch)
treeb33fedcfbabb96eeb2f940624c3edcccaf89439d
parent063c97feb6a9cafc822fab0b53e66ff1cd0c10a3 (diff)
downloadleaflet-soton-903dbcd6c4c4343355008aabe0b98afa52159313.tar
leaflet-soton-903dbcd6c4c4343355008aabe0b98afa52159313.tar.gz
Add panByURI method
-rw-r--r--examples/buildingsearch.html2
-rw-r--r--src/leaflet-soton.js62
2 files changed, 63 insertions, 1 deletions
diff --git a/examples/buildingsearch.html b/examples/buildingsearch.html
index 8bb64b7..77843e9 100644
--- a/examples/buildingsearch.html
+++ b/examples/buildingsearch.html
@@ -149,7 +149,7 @@ body { height: 100%; margin: 0px; padding: 0px }
a.href = "#";
a.onclick = function() {
- map.showByURI(building.properties.uri);
+ map.panByURI(building.properties.uri);
};
var label = document.createElement("span");
diff --git a/src/leaflet-soton.js b/src/leaflet-soton.js
index e5bb696..baaafa9 100644
--- a/src/leaflet-soton.js
+++ b/src/leaflet-soton.js
@@ -882,6 +882,68 @@ SELECT * WHERE {\
throw "unable to handle " + feature.geometry.type;
}
},
+ panByURI: function(uri) {
+ var feature = LS.getFeatureByURI(uri);
+
+ if (feature === null) {
+ throw "can't find " + uri;
+ }
+
+ if (!("geometry" in feature)) {
+ throw "no location for " + uri;
+ }
+
+ if (feature.geometry.type === "Polygon") {
+ console.log(feature);
+
+ var center;
+ if ("center" in feature.properties) {
+ center = feature.properties.center;
+ } else {
+ center = feature.geometry.coordinates[0][0];
+ center = [center[1], center[0]];
+ }
+
+ this.panTo(center);
+
+ if ("level" in feature.properties) {
+ if (L.Util.isArray(feature.properties.level)) {
+ this.setLevel(feature.properties.level[0]);
+ } else {
+ this.setLevel(feature.properties.level);
+ }
+ }
+
+ this.closePopup();
+
+ return;
+ } else if (feature.geometry.type === "Point") {
+ this.panTo(L.GeoJSON.coordsToLatLng(feature.geometry.coordinates));
+
+ if ("level" in feature.properties) {
+ if (L.Util.isArray(feature.properties.level)) {
+ this.setLevel(feature.properties.level[0]);
+ } else {
+ this.setLevel(feature.properties.level);
+ }
+ } else {
+ // If this is a workstation
+ if (uri.indexOf("http://id.southampton.ac.uk/point-of-service/workstations") === 0) {
+ var room = LS.getRoomFor(uri);
+
+ if (room !== null) {
+ this.setLevel(room.properties.level);
+ }
+ }
+ }
+
+ this.closePopup();
+ return;
+ } else {
+ throw "unable to handle " + feature.geometry.type;
+ }
+
+ },
showInfo: function(content, latlng, options) {
options = options || {};