Skip to content

Commit

Permalink
testing some idea
Browse files Browse the repository at this point in the history
  • Loading branch information
katemat committed Jul 16, 2020
1 parent e2ae2d0 commit 5f2e9ec
Showing 1 changed file with 66 additions and 65 deletions.
131 changes: 66 additions & 65 deletions public/item.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,75 @@
console.log('item.js is linked')
console.log('item.js is linked');

const itemAddress = document.querySelector('.item-location')
const itemLatitude = document.querySelector('.lat')
const itemLongitude = document.querySelector('.long')
const itemLocation = document.querySelector('.item-location')
const itemAddress = document.querySelector('.item-location');
const itemLatitude = document.querySelector('.lat');
const itemLongitude = document.querySelector('.long');
const itemLocation = document.querySelector('.item-location');

var map, searchManager, address, infobox
var item_location = {}
var map, searchManager, address, infobox;
var item_location = {};

const reverseGeocode = function(e) {
// infobox.setMap(null)
itemAddress.value = '';
if (map.entities != []) {
map.entities.clear();
}
//If search manager is not defined, load the search module.
if (!searchManager) {
//Create an instance of the search manager and call the reverseGeocode function again.
Microsoft.Maps.loadModule('Microsoft.Maps.Search', function () {
searchManager = new Microsoft.Maps.Search.SearchManager(map);
reverseGeocode();
const reverseGeocode = function (e) {
// infobox.setMap(null)
itemAddress.value = '';
if (map.entities != []) {
map.entities.clear();
}
//If search manager is not defined, load the search module.
if (!searchManager) {
//Create an instance of the search manager and call the reverseGeocode function again.
Microsoft.Maps.loadModule('Microsoft.Maps.Search', function () {
searchManager = new Microsoft.Maps.Search.SearchManager(map);
reverseGeocode();
});
} else {
var searchRequest = {
// local arguement to be passed in
location: e.location,
callback: function (res) {
//Tell the user the name of the result.
itemAddress.value = res.name;
itemLatitude.value = res.location.latitude;
itemLongitude.value = res.location.longitude;

infobox = new Microsoft.Maps.Infobox(e.location, {
title: 'Address',
description: res.name,
latitude: res.location.latitude,
longitude: res.location.longitude,
});
} else {

var searchRequest = {
// local arguement to be passed in
location: e.location,
callback: function (res) {
//Tell the user the name of the result.
itemAddress.value = res.name;
itemLatitude.value = res.location.latitude;
itemLongitude.value = res.location.longitude;

infobox = new Microsoft.Maps.Infobox(e.location, {
title: 'Address',
description: res.name,
latitude: res.location.latitude,
longitude: res.location.longitude
});
infobox.setMap(map);
console.log(infobox)
setTimeout(function () { infobox.setMap(null) }, 2000);
},
errorCallback: function (e) {
//If there is an error, alert the user about it.
alert("Unable to reverse geocode location.");
}
};
infobox.setMap(map);
console.log(infobox);
setTimeout(function () {
infobox.setMap(null);
}, 2000);
},
errorCallback: function (e) {
//If there is an error, alert the user about it.
alert('Unable to reverse geocode location.');
},
};

//Make the reverse geocode request.
searchManager.reverseGeocode(searchRequest);

var pin = new Microsoft.Maps.Pushpin(e.location, {
// title: address
// color: 'green'

})
map.entities.push(pin);
console.log(map.entities)
}
}
//Make the reverse geocode request.
searchManager.reverseGeocode(searchRequest);

function getMap() {
map = new Microsoft.Maps.Map('.item-map', {
// user location
center: new Microsoft.Maps.Location(-37.7989538, 144.9597395)
var pin = new Microsoft.Maps.Pushpin(e.location, {
// title: address
// color: 'green'
});
map.entities.push(pin);
console.log(map.entities);
}
};

Microsoft.Maps.Events.addHandler(map, 'click', (e) => {
reverseGeocode(e)
})
}
function getMap() {
map = new Microsoft.Maps.Map('.item-map', {
// user location
center: new Microsoft.Maps.Location(-37.7989538, 144.9597395),
credentials:
'AuewOzxuyMxFiwOpCiEiYyNsck-yIwg3nBqGlLukoPc6gZm-v9Eiyw3eBGpPPTDw',
});

Microsoft.Maps.Events.addHandler(map, 'click', (e) => {
reverseGeocode(e);
});
}

0 comments on commit 5f2e9ec

Please sign in to comment.