1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
| /* ************************************************************************
qooxdoo - the new era of web development
************************************************************************ */
/*
* If you have added resources to your app remove the leading '*' in the
* following line to make use of them.
#asset(qx/mobile/css/*)
#ignore(google)
#ignore(google.maps.Map)
************************************************************************ */
/**
* Mobile page showing a OpenStreetMap map.
*
* @ignore(OpenLayers)
*/
qx.Class.define("test3.pages.GoogleMap",
{
extend : qx.ui.mobile.page.NavigationPage,
construct : function()
{
this.debug("Google Page");
this.base(arguments,false);
this.setTitle("Google Map");
this.setShowBackButton(true);
this.setBackButtonText("Back");
this._geolocationEnabled = qx.core.Environment.get("html.geolocation");
},
members :
{
_map : null,
_mapContainer : null,
_geolocationEnabled : false,
_showMyPositionButton : null,
// overridden
_initialize : function()
{
this.base(arguments);
if(this._geolocationEnabled) {
this._initGeoLocation();
}
this._loadMapLibrary();
// Listens on window orientation change, and triggers redraw of map.
// Needed for triggering OpenLayers to use a bigger area, and draw more tiles.
qx.event.Registration.addListener(window, "orientationchange", this._redrawMap, this);
},
/**
* Used the Mapnik Layer for redrawing. Needed after orientationChange event
* and drawing markers.
*/
_redrawMap : function () {
this.debug("_redrawMap");
var oldCenter = this._map.getCenter();
google.maps.event.trigger(this._map, 'resize');
this._map.panTo(oldCenter);
},
/**
* Prepares GeoLocation, and installs needed listeners.
*/
_initGeoLocation : function() {
var geo = qx.bom.GeoLocation.getInstance();
geo.addListener("position", this._onGeolocationSuccess,this)
geo.addListener("error", this._onGeolocationError,this);
},
/**
* Callback function when Geolocation did work.
*/
_onGeolocationSuccess : function(position) {
var latitude = position.getLatitude();
var longitude = position.getLongitude();
var mapPosition = new google.maps.LatLng(latitude, longitude);
var zoom = 15;
this._map.setCenter(mapPosition);
//this._setMarkerOnMap(this._map,mapPosition);
this._redrawMap();
},
/**
* Callback function when Geolocation returned an error.
*/
_onGeolocationError : function() {
this._showMyPositionButton.setEnabled(false);
var buttons = [];
buttons.push(qx.locale.Manager.tr("OK"));
var title = "Problem with Geolocation";
var text = "Please activate location services on your browser and device."
qx.ui.mobile.dialog.Manager.getInstance().confirm(title, text, function() {
}, this, buttons);
},
/**
* Retreives GeoPosition out of qx.bom.Geolocation and zooms to this point on map.
*/
_getGeoPosition : function() {
var geo = qx.bom.GeoLocation.getInstance();
geo.getCurrentPosition(false, 1000, 1000);
},
// overridden
_createScrollContainer : function()
{
// MapContainer
var layout = new qx.ui.mobile.layout.VBox().set({
alignX : "center",
alignY : "middle"
});
var mapContainer = new qx.ui.mobile.container.Composite(layout);
mapContainer.setId("googleMap");
this._mapContainer = mapContainer;
return mapContainer;
},
// overridden
_createContent : function() {
var menuContainer = new qx.ui.mobile.container.Composite();
menuContainer.setId("googleMapMenu");
// LABEL
var descriptionLabel = new qx.ui.mobile.basic.Label("Page Title");
descriptionLabel.addCssClass("googleMapLabel");
// TOGGLE BUTTON
var toggleNaviButton = new qx.ui.mobile.form.ToggleButton(true,"Show","Hide",12);
// SHOW MY POSITION BUTTON
this._showMyPositionButton = new qx.ui.mobile.form.Button("Find me!");
this._showMyPositionButton.addListener("tap", this._getGeoPosition, this);
// Button is disabled, when Geolocation is not possible.
this._showMyPositionButton.setEnabled(this._geolocationEnabled);
toggleNaviButton.addListener("changeValue", function() {
var newNavBarState = !this.isNavigationBarHidden();
this.setNavigationBarHidden(newNavBarState);
this.show();
},this);
var groupPosition = new qx.ui.mobile.form.Group([this._showMyPositionButton],false);
var groupFullScreen = new qx.ui.mobile.form.Group([descriptionLabel,toggleNaviButton],true);
this._showMyPositionButton.addCssClass("map-shadow");
groupFullScreen.addCssClass("map-shadow");
menuContainer.add(groupFullScreen);
menuContainer.add(groupPosition);
return menuContainer;
},
/**
* Loads JavaScript library which is needed for the map.
*/
_loadMapLibrary : function()
{
var canvas = this._mapContainer.getContentElement();//.getDomElement();
var mapOptions = {
zoom : 13,
mapTypeId : google.maps.MapTypeId.ROADMAP,
center : new google.maps.LatLng(49.011899,8.403311)
};
this._map = new google.maps.Map(canvas, mapOptions);
this._mapContainer.addListener("resize", this._redrawMap);
},
// overridden
_back : function()
{
//qx.core.Init.getApplication().getRouting().executeGet("/", {reverse:true});
},
/*
*****************************************************************************
DESTRUCTOR
*****************************************************************************
*/
destruct : function()
{
}
}
}); |
Partager