我正在使用小册子在地图上进行实时用户跟踪。我画出了这个圈子作为所有用户的边界。如果用户超出边界,我需要提醒消息。我正在跟踪用户。只有我需要警告用户的消息不在边界。小册子实时出现圆圈边界警报
var shipLayer = L.layerGroup();
var ships = L.icon({
iconUrl: 'images/marker.png',
iconSize: [16, 20]
});
var popup;
var region;
var fen = {
lat: "17.4468",
lng: "78.3922"
};
var i = 1;
var realtime = L.realtime(
function(success, error) {
var ship = mockShip();
success(ship);
}, {
interval: refresh * 1000,
getFeatureId: function(featureData) {
return featureData.properties.userName;
},
pointToLayer: function(feature, latlng) {
region = '';
if (typeof ship === "undefined" || ship === null) {
var title = feature.properties.userName + " - " + feature.properties.gpsTime;
popup = L.popup()
.setLatLng(latlng)
.setContent(feature.properties.userName + '<br/>' + feature.properties.gpsTime + '<br/>BatteryInfo:' + feature.properties.batteryInfo + '%')
.openOn(map);
marker = L.marker(latlng, {
title: title,
icon: ships
});
// this is my code for alert
if (fen.lat < feature.properties.latitude && fen.lng < feature.properties.longitude) {
alert('hi');
}
//end
region = L.circle(fen, 450, {
color: 'red',
fillColor: '#f03',
fillOpacity: 0
}).addTo(map);
marker.bindPopup(popup);
marker.on('mouseover', function(e) {
this.openPopup();
});
marker.on('mouseout', function(e) {
this.closePopup();
});
marker.addTo(shipLayer);
return marker;
}
}
}).addTo(map);
FYI:不需要像草坪此额外的LIB拉,因为'L.LatLng'对象都有一个'distanceTo'方法。因此,我的回答;) – iH8
啊,那更好! – nathansnider