Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verify if marker is inside from route #547

Closed
joaoavanzini opened this issue Sep 10, 2019 · 2 comments
Closed

verify if marker is inside from route #547

joaoavanzini opened this issue Sep 10, 2019 · 2 comments

Comments

@joaoavanzini
Copy link

Hello, my name is João, and I'm using the leaflet.js to do my project of the conclusion course at the University of Campinas - Brazil. The problem to solve is: the marker needs to stay inside from route, if not, need to return a false. Can someone help me? Thanks.

code:

var map = L.map('map',18);

  L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
    maxZoom: 20,
  }).addTo(map);

  var cont = 0;
  var marker = null;

  function refresh() {
  
    $.ajax({
      method: "GET",
      url: "mapa/coordenada",
      dataType: "json"
    })
      .done(function( msg ) {
        registro_coordenada(msg.coordenada);
      });
  }

  function select_cord() {
  
    $.ajax({
      method: "GET",
      url: "mapa/coordenada",
      dataType: "json"
    })
      .done(function( msg ) {
        add_cord(msg.coordenada);
      });
  }
  
  function add_cord(coordenada){
    out = coordenada.split(",");

    var control = L.Routing.control(L.extend(window.lrmConfig, {
      waypoints: [
      L.latLng(-22.5627235,-47.425501),
      L.latLng([out[0],out[1]])
  ],
      geocoder: L.Control.Geocoder.nominatim(),
      routeWhileDragging: true,
      reverseWaypoints: true,
      showAlternatives: true,
      altLineOptions: {
          styles: [
            {color: 'black', opacity: 0.15, weight: 9},
            {color: 'white', opacity: 0.8, weight: 6},
            {color: 'blue', opacity: 0.5, weight: 2}
        ]
    }
  })).addTo(map);

  L.Routing.errorControl(control).addTo(map);

  }

var icone = new L.Icon({
                      iconUrl: 'https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-red.png',
                      shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
                      iconSize: [25, 41],
                      iconAnchor: [12, 41],
                      popupAnchor: [1, -34],
                      shadowSize: [41, 41]
                    });


function registro_coordenada(coordenada){
  out = coordenada.split(",");
  if (cont === 0 ){
    marker = L.marker([out[0],out[1]], {icon: icone}).addTo(map).bindPopup("<b>Localização atual</b>").openPopup();
    cont = 1;
    return;
  }
  map.removeLayer(marker);
  //var marker = L.marker([out[0],out[1]]).remove(map).bindPopup("<b>Localização atual</b>").openPopup();
  marker = L.marker([out[0],out[1]], {icon: icone}).addTo(map).bindPopup("<b>Localização atual</b>").openPopup().closePopup();
}

$(document).ready(function(){
  if ($('#map')){
    self.setInterval(function () {
      refresh()
    }, 1000);
  }
  select_cord();
});

@joaoavanzini
Copy link
Author

Please, anyone can help??

@perliedman
Copy link
Owner

Hi, sorry, this is a place for discussing issues with Leaflet Routing Machine, or possibly proposing features. While it might sound unfriendly, the hard fact is that I (who respond to most reports), simply do not have time to solve programming problems for others in my free time. I wish you good luck and hope you find a solution. You might also try to ask a question in some other forum, like Stack Overflow, but I think you might want to state the actual problem you are trying to solve a bit clearer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants