1 ( function ( $, window ) {
\r
3 $( "#mapview-demo-page" ).bind( "pageshow", function ( e ) {
\r
4 var mapView = $( "#sampleMap" ),
\r
5 menuPopup = $( "#map_menu_popup" ),
\r
6 routeFromButton = $( "#routeFrom" ),
\r
7 routeToButton = $( "#routeTo" ),
\r
8 getAddressButton = $( "#getAddress" ),
\r
9 resultPopup = $( "#map_result_popup" ),
\r
10 closeButton = $( "#map_close_btn" ),
\r
16 measureRoute = function () {
\r
17 var measureShape, length, displayLength;
\r
20 type : "LineString",
\r
21 coordinates : [ routePoints.from.geometry.coordinates,
\r
22 routePoints.to.geometry.coordinates ]
\r
25 length = $.geo.length( measureShape, true );
\r
26 if ( length > 1000 ) {
\r
27 displayLength = ( length / 1000 ).toFixed( 6 ) + " km";
\r
29 displayLength = length.toFixed( 6 ) + " m";
\r
32 mapView.mapview( "append", measureShape, length.toFixed( 2 ) + "m" );
\r
33 resultPopup.find( "p" ).text( "Route distance = " + displayLength );
\r
34 resultPopup.popup( "open" );
\r
36 checkRoute = function ( role ) {
\r
37 menuPopup.popupwindow( "close" );
\r
39 if ( routePoints[ role ] ) {
\r
40 mapView.mapview( "remove", routePoints[ role ] );
\r
41 routePoints[ role ] = null;
\r
44 routePoints[ role ] = {
\r
48 coordinates: mapView.mapview( "toMap", targetPoint, false )
\r
52 if ( role === "from" ) {
\r
53 mapView.mapview( "append", routePoints[ role ], {
\r
57 mapView.mapview( "append", routePoints[ role ], {
\r
62 if ( routePoints.from && routePoints.to ) {
\r
67 mapView.bind( "mapviewtaphold", function ( e, position ) {
\r
68 var offset = mapView.offset(),
\r
72 targetPoint = [ pageX - offset.left, pageY - offset.top ];
\r
73 menuPopup.popupwindow( "open", pageX, pageY );
\r
76 routeFromButton.bind( "vclick", function ( e ) {
\r
77 checkRoute( "from" );
\r
80 routeToButton.bind( "vclick", function ( e ) {
\r
84 getAddressButton.bind( "vclick", function ( e ) {
\r
85 var targetCoordinate = mapView.mapview( "toMap", targetPoint );
\r
87 menuPopup.popupwindow( "close" );
\r
90 url : "http://nominatim.openstreetmap.org/reverse",
\r
93 lat : String( targetCoordinate[1] ),
\r
94 lon : String( targetCoordinate[0] ),
\r
95 addressdetails : String( 1 )
\r
98 jsonp : "json_callback",
\r
99 success : function ( results ) {
\r
100 mapView.mapview( "option", {
\r
101 center : targetCoordinate,
\r
104 resultPopup.find( "p" ).text( results.display_name );
\r
105 resultPopup.popup( "open" );
\r
110 closeButton.bind( "vclick", function ( e ) {
\r
111 resultPopup.popup( "close" );
\r
114 resultPopup.bind( "popupafterclose", function ( e ) {
\r
115 resultPopup.find( "p" ).text( "" );
\r
116 mapView.mapview( "empty" );
\r
117 routePoints.from = routePoints.to = null;
\r
121 } ( jQuery, window ) );
\r