/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License.
*/ var directions = {}; var contactsWithAddress = []; var contactAddresses = []; var compassWatchId = -1; var locationWatchId = -1; var map_with_pos = {}; var previous_pos_marker = {};
console.log("Ready");
$(window).bind('pageshow resize orientationchange', function(e) { // resize page if needed
maxHeight();
});
$('#toggleswitch').change(function() { // toggle switch for FROM location var v = $(this).val(); if (v === "on") {
$("#fromfield").css("display", "none");
} else {
$("#fromfield").css("display", "block");
}
});
$("#refreshMyLocationBt").click(function(e) { // refresh my location button
e.stopImmediatePropagation();
e.preventDefault(); var app = new MyApplication();
app.mylocation();
});
$("#cancelMyLocationBt").click(function(e) { // stop/resume watching my location button
e.stopImmediatePropagation();
e.preventDefault(); var $icon = $($(this).find(".ui-icon")[0]); var oldClass = $icon.attr("class"); if ($(this).text() === "Stop") {
$($(this).find(".ui-btn-text")[0]).text("Resume");
$icon.attr("class", oldClass.replace("delete", "star"));
window.navigator.geolocation.clearWatch(locationWatchId);
} else {
$($(this).find(".ui-btn-text")[0]).text("Stop");
$icon.attr("class", oldClass.replace("star", "delete")); var map = new MapCtrl();
map.syncPositionWithMap();
}
});
$("#refreshPhotoBt").click(function(e) { // refresh my photo button
e.stopImmediatePropagation();
e.preventDefault(); var app = new MyApplication();
app.photos();
});
$("#showPhoneStatus").click(function(e) { // show phone status information
e.stopImmediatePropagation();
e.preventDefault(); var app = new MyApplication();
app.showPhoneStatus();
});
maxHeight(); var app = new MyApplication();
}
function maxHeight() {
var w = $(window).height(); var cs = $('div[data-role="content"]'); for (var i = 0, max = cs.length; i < max; i++) { var c = $(cs[i]); var h = $($('div[data-role="header"]')[i]).outerHeight(true); var f = $($('div[data-role="footer"]')[i]).outerHeight(true); var c_h = c.height(); var c_oh = c.outerHeight(true); var c_new = w - h - f - c_oh + c_h; var total = h + f + c_oh; if (c_h < c.get(0).scrollHeight) {
c.height(c.get(0).scrollHeight);
} else {
c.height(c_new);
}
}
this.findDirections = function() {
$("#directionsResultsList").html(""); var useMyLocation = $("#toggleswitch").val() === "off" ? false : true; var to = $("#tofield").val(); var from = $("#fromfield").val(); var mode = "DRIVING";
$("input[name*=radio-choice-]:checked").each(function() {
mode = $(this).val();
}); var mapHandler = new MapCtrl(function(error) {
$('h1[id="dirlistHeader"]').html("GPS error"); try {
showAlert(error.message);
} catch (e) {
}
});
mapHandler.mapContainter = "directionMap";
mapHandler.headerID = "#dirlistHeader";
mapHandler.findDirections(from, to, useMyLocation, mode, printDirectionResults);
};
this.showDirection = function() { var m = new MapCtrl(); var index = getParmFromHash(window.location.href, "i") || -1;
m.mapContainter = "directionMap";
m.headerID = "#directionHeader";
m.printDirection(index);
};
function printDirectionResults(results) {
$("#directionsResultsList").html(""); if (results.length === 0 || typeof results === "undefined") {
$("#directionsResultsList").html("No directions found"); return;
} var html = "
dirResults\" data-role=\"listview\" data-divider-theme=\"b\" data-inset=\"true\">"; for (var i = 0, max = results.length; i < max; i++) {
html += "
this.undefinedAction = function() {
window.console.log("Action not defined");
};
this.mylocation = function() {
resetStopButton(); var mapHandler = new MapCtrl(function(error) {
window.console.error(error.message);
});
mapHandler.headerID = "#header";
mapHandler.locateMe();
};
function resetStopButton() { var $stopButton = $($("#cancelMyLocationBt")[0]); var $icon = $($stopButton.find(".ui-icon")[0]); var oldClass = $icon.attr("class");
$($stopButton.find(".ui-btn-text")[0]).text("Stop");
$icon.attr("class", oldClass.replace("star", "delete"));
}
function MapCtrl(onFail) { var map; var marker; var infoWindow;
var self = this;
self.mapPrinted = false; this.mapContainter = "map"; this.headerID = "#noheader"; /** * Address to show on map * @type String
*/ this.address = "Prague";
/** * Loads new map * @param {Function} callback function to be called when map is loaded * @returns {undefined}
*/ function loadMap(mapContainer, callback, waitForPostion) { var latlng = new google.maps.LatLng(55.17, 23.76); var myOptions = {
zoom: 6,
center: latlng,
streetViewControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoomControl: true
};
map = new google.maps.Map(document.getElementById(mapContainer), myOptions);
self.map = map;
google.maps.event.trigger(map, 'resize');
/** * Loads new map * @param {Function} callback function to be called when map is loaded * @returns {undefined}
*/ function loadMapWatchLocation(mapContainer, callback) { var latlng = new google.maps.LatLng(55.17, 23.76); var myOptions = {
zoom: 6,
center: latlng,
streetViewControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoomControl: true
};
function requestPhotosFromMaps(position, callback) { var request = {
location: new google.maps.LatLng(position.coords.latitude, position.coords.longitude),
radius: 3000
};
var service = new google.maps.places.PlacesService(document.getElementById("photosContent"));
service.nearbySearch(request, function(results, status) {
pickRandomPhoto(results, status, callback);
});
}
function pickRandomPhoto(results, status, callback) { if (results.length === 0 || status != google.maps.places.PlacesServiceStatus.OK) {
callback();
} var random = parseInt(1000 * Math.random()) % results.length; var notFound = true; var iteration = 0; while (notFound && iteration < results.length) { if (typeof results[random].photos !== "undefined") {
notFound = false; var url = (!results[random].photos[0].raw_reference) ? results[random].photos[0].getUrl({maxHeight: 1200}) : results[random].photos[0].raw_reference.fife_url;
callback(url, results[random].name);
} else {
random = parseInt(1000 * Math.random()) % results.length;
iteration += 1;
}
}
$.mobile.hidePageLoadingMsg(); if (notFound) {
callback();
}
}
function geo_error(error) { if (typeof error === "function") {
error.callback();
} else {
showAlert("Problem with retrieving location ", "Error");
}
}
/** * Uses Geocoder to translate string address to map position and places marker on found position
*/ function showAddressOnMap(address, mapContainter, headerID) { if (address.indexOf("'") === 0) {
address = address.substring(1, address.length);
} if (address.charAt(address.length - 1) === '\'') {
address = address.substring(0, address.length - 1);
}
var geocoder = new google.maps.Geocoder();
geocoder.geocode({'address': address}, function(results, status) { if (status === google.maps.GeocoderStatus.OK) { var myOptions = {
zoom: 6,
center: new google.maps.LatLng(55.17, 23.76),
streetViewControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoomControl: true
};
map = new google.maps.Map(document.getElementById(mapContainter), myOptions);
self.map = map;
map.setCenter(results[0].geometry.location);
map.setZoom(13);
if (!marker) {
marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map
});
} else {
marker.setPosition(results[0].geometry.location);
}
function getDirections(from, to, mode, callback) { var directionsDisplay = new google.maps.DirectionsRenderer(); var directionsService = new google.maps.DirectionsService();
directionsDisplay.setMap(self.map); var request = {
origin: from,
destination: to,
provideRouteAlternatives: true,
travelMode: google.maps.DirectionsTravelMode[mode]
};
directionsService.route(request, function(response, status) {
$(self.headerID).html("Directions");
$.mobile.hidePageLoadingMsg();
directions = response; if (status == google.maps.DirectionsStatus.OK) {
callback(response.routes);
} else {
callback([]);
}
});
}
this.printDirection = function(index) {
$.mobile.showPageLoadingMsg(); if (parseInt(index) < 0) {
showAlert("Direction not found", "Problem"); return;
} var _r = directions.routes[index];
directions.routes = [_r];
$(self.headerID).html("Loading...");
google.load("maps", "3.8", {"callback": function() {
loadMap(self.mapContainter, function() { var directionsDisplay = new google.maps.DirectionsRenderer();
directionsDisplay.setMap(self.map);
$(self.headerID).html(directions.routes[0].summary);
directionsDisplay.setDirections(directions);
$.mobile.hidePageLoadingMsg();
}, false);
}, other_params: "sensor=true&language=en&libraries=places"});
};
}
function ContactsCtrl() {
this.headerID = "#noheader";
this.listContactsWithAddress = function(onSuccess, onError) {
$(this.headerID).html("Loading..."); var options = new ContactFindOptions();
options.filter = "";
options.multiple = true; var filter = ["name", "addresses"];
window.navigator.contacts.find(filter, onSuccess, onError, options);
};
}
function validateSearchField(elementID, newhash) { if ($("#" + elementID).val().length > 0) {
window.location.hash = newhash;
} else {
showAlert("You need to specify address", "Empty value");
}
} function validateDirectionFields() { var useMyLocation = $("#toggleswitch").val() === "off" ? false : true; if ($("#tofield").val().length > 0 && ($("#fromfield").val().length > 0 || useMyLocation)) {
window.location.hash = "findDirections";
} else {
showAlert("You need to specify address", "Empty value");
}
}
function getParmFromHash(url, parm) { var re = new RegExp("#.*[?&]" + parm + "=([^&]+)(&|$)"); var match = url.match(re); return(match ? match[1] : "");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.