favorite info added

This commit is contained in:
simon 2020-08-24 14:10:03 +03:00
parent 79240f34d7
commit 8ef3394e5e
2 changed files with 39 additions and 9 deletions

View file

@ -44,6 +44,10 @@
return popupContent; return popupContent;
} }
function markerClick(e){
}
function setupMarkers(){ function setupMarkers(){
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
@ -54,10 +58,7 @@
complete: function(r) { complete: function(r) {
var points = JSON.parse(r.responseText); var points = JSON.parse(r.responseText);
points.forEach(e => { points.forEach(e => {
var point = {}; window.goMap.map.addPopupMarker(e,markerClick);
point.lat = e.latitude;
point.lon = e.longitude;
window.goMap.map.addMarker(point);
}); });
}, },
error: function(e) { error: function(e) {
@ -65,8 +66,11 @@
} }
}); });
} }
//TODO add document ready or map ready event
setTimeout(function(){ setupMarkers(); }, 4000); $( document ).ready(function() {
setupMarkers();
});
</script> </script>
</head> </head>
<body> <body>

View file

@ -18,8 +18,8 @@ var goMap = {
'config':{ 'config':{
'containerid': 'gocontainer', 'containerid': 'gocontainer',
'defaults':{ 'defaults':{
'lat':51.505, 'lat':50.27,
'lon':-0.09, 'lon':30.30,
'zoom':13 'zoom':13
} }
}, },
@ -82,6 +82,15 @@ var goMap = {
} }
}; };
function toColor(num) {
num >>>= 0;
var b = num & 0xFF,
g = (num & 0xFF00) >>> 8,
r = (num & 0xFF0000) >>> 16,
a = ( (num & 0xFF000000) >>> 24 ) / 255 ;
return "rgba(" + [r, g, b, a].join(",") + ")";
}
(function($) { (function($) {
$.mapwidget = function(config) { $.mapwidget = function(config) {
var loc = goMap.point.lat + '/' + goMap.point.lon; var loc = goMap.point.lat + '/' + goMap.point.lon;
@ -107,12 +116,29 @@ var goMap = {
}, },
addMarker:function(point){ addMarker:function(point){
L.marker([point.lat, point.lon]).addTo(mapobj.map); L.marker([point.lat, point.lon]).addTo(mapobj.map);
},
addPopupMarker:function(favorite,onClickEvent){
window.point = favorite;
var point = {};
point.lat = favorite.latitude;
point.lon = favorite.longitude;
var popup = L.popup().setContent(
"name: <b>" + favorite.name + "</b><br/>" +
"address: <i>" + favorite.address + "</i><br/>"
+ "category: " + favorite.category);
L.marker([point.lat, point.lon])
.bindPopup(popup)
.addTo(mapobj.map)
.on('click', function(e) {
onClickEvent(e);
});
} }
}; };
mapobj.init(); mapobj.init();
return { return {
showPoint: mapobj.showPoint, showPoint: mapobj.showPoint,
addMarker: mapobj.addMarker addMarker: mapobj.addMarker,
addPopupMarker: mapobj.addPopupMarker
}; };
}; };
})(jQuery); })(jQuery);