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

View file

@ -18,8 +18,8 @@ var goMap = {
'config':{
'containerid': 'gocontainer',
'defaults':{
'lat':51.505,
'lon':-0.09,
'lat':50.27,
'lon':30.30,
'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($) {
$.mapwidget = function(config) {
var loc = goMap.point.lat + '/' + goMap.point.lon;
@ -107,12 +116,29 @@ var goMap = {
},
addMarker:function(point){
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();
return {
showPoint: mapobj.showPoint,
addMarker: mapobj.addMarker
addMarker: mapobj.addMarker,
addPopupMarker: mapobj.addPopupMarker
};
};
})(jQuery);