123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- const MapsViewElementID = "mapContainer";
- const InfoTextElementID = "informationText";
- const DefaultLatitude = 52.531;
- const DefaultLongitude = 13.385;
- const SetMapFunction = setPannableMap;
- var positionOptions = {
- enableHighAccuracy: false,
- timeout: 30000,
- maximumAge: 0
- }
- var map;
- var marker;
- var lastPosition = [ DefaultLatitude, DefaultLongitude ];
- function init()
- {
- loadPannableMap();
- getPosition(SetMapFunction);
- }
- function setInformationText(text)
- {
- var informationTextElement = document.getElementById(InfoTextElementID);
- informationTextElement.innerHTML = text;
- }
- function getPosition(setMapFunction)
- {
- if (navigator && navigator.geolocation) {
- navigator.geolocation.getCurrentPosition(setMapFunction,
- onError,
- positionOptions);
- setInformationText("Retrieving location...");
- }
- else {
- alert("No Geolocation API available!");
- setInformationText("Unable to retrieve location!");
- setMapFunction({ coords: {
- latitude: DefaultLatitude,
- longitude: DefaultLongitude }});
- }
- }
- function setStaticMap(position)
- {
- setInformationText("Location found!");
-
- var mapsViewElement = document.getElementById(MapsViewElementID);
-
-
- var url = new StaticMap({
- center: { lat: position.coords.latitude,
- lon: position.coords.longitude },
- zoom: 12,
- size: { width: 640, height: 360 }
- }).getCSSUrl();
- mapsViewElement.style.backgroundImage = url;
- }
- function loadPannableMap()
- {
- setInformationText("Loading map...");
- map = new ovi.mapsapi.map.Display(
- document.getElementById(MapsViewElementID),
- { components: [
-
- new ovi.mapsapi.map.component.Behavior()
-
-
-
-
- ],
- zoomLevel: 8,
- center: [DefaultLatitude, DefaultLongitude]
- });
- }
- function setPannableMap(position)
- {
- setInformationText("Location found!");
-
- lastPosition = position.coords;
-
- map.setCenter( [ position.coords.latitude, position.coords.longitude ] );
-
- marker = new ovi.mapsapi.map.StandardMarker(
- [position.coords.latitude, position.coords.longitude],
- {
- text: "Me",
- draggable: false
- });
-
-
- map.objects.add(marker);
- }
- function onError(error)
- {
- setInformationText("Error: " + error.message);
- }
- function setAccuracy(accuracy)
- {
- if (accuracy == "high") {
- setInformationText("Accuracy set: high");
- positionOptions.enableHighAccuracy = false;
- }
- else {
- setInformationText("Accuracy set: low");
- positionOptions.enableHighAccuracy = true;
- }
- getPosition(SetMapFunction);
- }
- function centerMap()
- {
- if (map) {
- map.setCenter(lastPosition);
- }
- }
- function update()
- {
- getPosition(SetMapFunction);
- }
|