Geolocation 在mapbox中为地图上的标记添加标题也会在firebase中为标记命名

Geolocation 在mapbox中为地图上的标记添加标题也会在firebase中为标记命名,geolocation,firebase,mapbox,marker,Geolocation,Firebase,Mapbox,Marker,在火基地,而不是一些随机数和字母,我想给标记的名称 function addPoint(uuid, point) { var marker = L.rotatedMarker([point.coords.latitude, point.coords.longitude], { //zIndexOffset: (uuid === myUuid ? 1000 : 0), icon: createIcon(uuid, point) }) markers[uuid] = m

在火基地,而不是一些随机数和字母,我想给标记的名称

function addPoint(uuid, point) {
  var marker = L.rotatedMarker([point.coords.latitude, point.coords.longitude], {
    //zIndexOffset: (uuid === myUuid ? 1000 : 0),
    icon: createIcon(uuid, point)
  })

  markers[uuid] = marker;

  marker.options.angle = point.orientation;
  marker.addTo(map)

  map.fitBounds(Object.keys(markers).map(function(uuid) {
    return markers[uuid].getLatLng()
  }))
}

function removePoint(uuid) {
  if (markers[uuid]) {
    map.removeLayer(markers[uuid])
    //markers[uuid] = null
  }
}

function updatePoint(uuid, point) {
  // Avoid clipping effect when zooming map + updating point at the same time.
  if (mapZooming) {
    map.once('zoomend', function() {
      updatePoint(uuid, point)
    })
    return
  }

  var marker = markers[uuid]

  marker.setIcon(createIcon(uuid, point));

  marker.options.angle = point.orientation
  marker.setLatLng([point.coords.latitude, point.coords.longitude])
}

function putPoint(uuid, point) {
  if (markers[uuid]) {
    updatePoint(uuid, point)
  } else {
    addPoint(uuid, point)
  }
}
//
//火基
//
var终点;
endpoint=newfirebase('https://'+config.Firebase+'.firebaseio.com/maps/'+mapId);
endpoint.on('child_added',函数(childSnapshot){
var uuid=childSnapshot.key()
var point=childSnapshot.val()
if(uuid==myUuid)返回
添加点(uuid,点)
})
endpoint.on('child_changed',函数(childSnapshot){
var uuid=childSnapshot.key()
var point=childSnapshot.val()
if(uuid==myUuid)返回
putPoint(uuid,point)
})
endpoint.on('child_removed',函数(oldChildSnapshot){
var uuid=oldChildSnapshot.key()
移除点(uuid)
})
//
//追踪
//
var-watchPositionId;
var currentCoords=null;
var currentOrientation=null;
函数pushCurrentStatus(){
如果(!currentCoords)返回
endpoint.child(myUuid).set({
协调:{
纬度:currentCoords.latitude,
经度:currentCoords.longitude,
},
方向:当前方向,
时间戳:现在()
})
}
pushCurrentStatus=节气门(pushCurrentStatus,50)
if(导航器.地理位置){
setTimeout(函数(){
watchPositionId=navigator.geolocation.watchPosition(
成功观察职位,
故障观察位置,
{enableHighAccurance:false}
)
}, 0)
setTimeout(函数(){
navigator.geolocation.clearWatch(watchPositionId)
watchPositionId=navigator.geolocation.watchPosition(
成功观察职位,
故障观察位置,
{enableHighAccurance:true}
)
}, 5000)
}
功能成功观察位置(位置){
如果(!position.coords)返回
currentCoords=position.coords
pushCurrentStatus()
putPoint(myUuid,{coords:currentCoords,orientation:currentCoords})
}
函数failWatchPosition(){
警报('无法获取您的位置')
}
if(window.DeviceOrientationEvent){
addEventListener('deviceorientation',deviceOrientationHandler,true)
}
函数deviceOrientationHandler(事件){
αvar;
if(event.webkitCompassHeading){
alpha=event.webkitCompassHeading;
}否则{
alpha=event.alpha;
}
如果(!alpha)返回
currentOrientation=360-alpha
pushCurrentStatus()
putPoint(myUuid,{coords:currentCoords,orientation:currentCoords})
}
//
//删除旧标记
//
setInterval(函数(){
endpoint.limitToFirst(100).once('value',函数(snap){
var now=Math.floor(Date.now()/1000)
snap.forEach(函数(childSnapshot){
var uuid=childSnapshot.key()
var point=childSnapshot.val()
if(uuid==myUuid)返回
if(childSnapshot.val().timestamp
function addPoint(uuid, point) {
  var marker = L.rotatedMarker([point.coords.latitude, point.coords.longitude], {
    //zIndexOffset: (uuid === myUuid ? 1000 : 0),
    icon: createIcon(uuid, point)
  })

  markers[uuid] = marker;

  marker.options.angle = point.orientation;
  marker.addTo(map)

  map.fitBounds(Object.keys(markers).map(function(uuid) {
    return markers[uuid].getLatLng()
  }))
}

function removePoint(uuid) {
  if (markers[uuid]) {
    map.removeLayer(markers[uuid])
    //markers[uuid] = null
  }
}

function updatePoint(uuid, point) {
  // Avoid clipping effect when zooming map + updating point at the same time.
  if (mapZooming) {
    map.once('zoomend', function() {
      updatePoint(uuid, point)
    })
    return
  }

  var marker = markers[uuid]

  marker.setIcon(createIcon(uuid, point));

  marker.options.angle = point.orientation
  marker.setLatLng([point.coords.latitude, point.coords.longitude])
}

function putPoint(uuid, point) {
  if (markers[uuid]) {
    updatePoint(uuid, point)
  } else {
    addPoint(uuid, point)
  }
}
//
// Firebase
//
var endpoint;

endpoint = new Firebase('https://' + config.firebase + '.firebaseio.com/maps/' + mapId);

endpoint.on('child_added', function(childSnapshot) {
  var uuid = childSnapshot.key()
  var point = childSnapshot.val()

  if (uuid === myUuid) return

  addPoint(uuid, point)
})

endpoint.on('child_changed', function(childSnapshot) {
  var uuid = childSnapshot.key()
  var point = childSnapshot.val()

  if (uuid === myUuid) return

  putPoint(uuid, point)
})

endpoint.on('child_removed', function(oldChildSnapshot) {
  var uuid = oldChildSnapshot.key()

  removePoint(uuid)
})

//
// Tracking
//
var watchPositionId;
var currentCoords = null;
var currentOrientation = null;

function pushCurrentStatus() {
  if (!currentCoords) return

  endpoint.child(myUuid).set({
    coords: {
      latitude: currentCoords.latitude,
      longitude: currentCoords.longitude,
    },
    orientation: currentOrientation,
    timestamp: now()
  })
}
pushCurrentStatus = _.throttle(pushCurrentStatus, 50)

if (navigator.geolocation) {
  setTimeout(function() {
    watchPositionId = navigator.geolocation.watchPosition(
      successWatchPosition,
      failWatchPosition,
      {enableHighAccuracy: false}
    )
  }, 0)

  setTimeout(function() {
    navigator.geolocation.clearWatch(watchPositionId)

    watchPositionId = navigator.geolocation.watchPosition(
      successWatchPosition,
      failWatchPosition,
      {enableHighAccuracy: true}
    )
  }, 5000)
}

function successWatchPosition(position) {
  if (!position.coords) return

  currentCoords = position.coords

  pushCurrentStatus()
  putPoint(myUuid, {coords: currentCoords, orientation: currentOrientation})
}

function failWatchPosition() {
  alert('Fail to get your location')
}


if (window.DeviceOrientationEvent) {
  window.addEventListener('deviceorientation', deviceOrientationHandler, true)
}

function deviceOrientationHandler(event) {
  var alpha;

  if (event.webkitCompassHeading) {
    alpha = event.webkitCompassHeading;
  } else {
    alpha = event.alpha;
  }

  if (!alpha) return

  currentOrientation = 360 - alpha

  pushCurrentStatus()
  putPoint(myUuid, {coords: currentCoords, orientation: currentOrientation})
}


//
// Remove old markers
//
setInterval(function() {
  endpoint.limitToFirst(100).once('value', function(snap) {
    var now = Math.floor(Date.now() / 1000)

    snap.forEach(function(childSnapshot) {
      var uuid = childSnapshot.key()
      var point = childSnapshot.val()

      if (uuid === myUuid) return

      if (childSnapshot.val().timestamp < now - 60 * 30) {
        endpoint.child(uuid).set(null)
      } else {
        updatePoint(uuid, point)
      }
    })
  })
}, 5000);

})();