package votorola.s.gwt.scene.geo; // Copyright 2011, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. import votorola.a.*; import votorola.a.trust.*; import votorola.g.*; import votorola.g.net.*; import votorola.s.gwt.scene.feed.ss.*; /** A configurer of bites for the geographic map. */ public final class GeomapBiterSS implements Biter { /** Constructs a GeomapBiterSS. * * @param _traceOrNull the network trace to use throughout the life of this * biter; or null to use none. */ public GeomapBiterSS( final VoteServer.Run run, NetworkTrace _traceOrNull ) { geocoder = run.trustserver().geocoder(); traceOrNull = _traceOrNull; } // - B i t e r ------------------------------------------------------------------------ public void configure( final BiteJig bite ) { if( traceOrNull == null ) return; for( final PersonJig person: bite.persons() ) { if( person.user() == null ) continue; final Geocode geocode; { final TraceNode traceNode; try { traceNode = person.traceNode( traceOrNull ); } catch( votorola.s.gwt.scene.feed.NoSuchItem x ) { continue; } catch( java.sql.SQLException x ) { throw new RuntimeException( x ); } final String geohandle = traceNode.getGeohandle(); if( geohandle == null ) continue; final String cc = traceNode.getCountryCode(); if( cc == null ) continue; try { geocode = geocoder.geocode( Net.ccTLD(cc), geohandle ); } catch( Exception x ) { throw VotorolaRuntimeException.castOrWrapped( x ); } } final ResidenceJig residence = person.setResidence(); residence.setLat( (float)Math.toDegrees( geocode.latitude() )); residence.setLon( (float)Math.toDegrees( geocode.longitude() )); } } //// P r i v a t e /////////////////////////////////////////////////////////////////////// private final GoogleGeocoder geocoder; private final NetworkTrace traceOrNull; }