package org.apidesign.html.location;
import net.java.html.geo.OnLocation;
import net.java.html.geo.Position;
import net.java.html.json.ComputedProperty;
import net.java.html.json.Function;
import net.java.html.json.Model;
import net.java.html.json.Property;
@author <jtulach@apidesign.org>
@Model(className = "LocationModel", properties = {
@Property(name = "latitude", type = double.class),
@Property(name = "longitude", type = double.class),
@Property(name = "message", type = String.class)
})
final class LocationController {
@Function static void findLocation(LocationModel model) {
LocateMeHandle.createQuery(new LocationController(model)).start();
}
@ComputedProperty static String url(double latitude, double longitude) {
return "http://www.mapy.cz/#!x=" + longitude + "&y=" + latitude + "&z=11&l=16";
}
@Function static void findPraha(LocationModel model) {
model.setLatitude(50.1);
model.setLongitude(14.45);
}
private final LocationModel location;
private LocationController(LocationModel l) {
this.location = l;
}
@OnLocation(onError = "error") void locateMe(Position p) {
location.setLatitude(p.getCoords().getLatitude());
location.setLongitude(p.getCoords().getLongitude());
}
void error(Exception ex) {
location.setMessage(ex.getMessage());
}
static {
LocationModel loc = new LocationModel();
loc.setLongitude(16.0075239);
loc.setLatitude(50.5622514);
loc.setMessage("OK");
loc.applyBindings();
}
}