mapbox/mapbox-gl-directions

setOrigin and setDestination changing others maps directions

Open

#170 opened on Mar 14, 2018

 (10 comments) (1 reaction) (0 assignees)JavaScript (130 forks)github user discovery
bughelp wanted

Repository metrics

Stars
 (253 stars)
PR merge metrics
 (Avg merge 22h 39m) (1 merged PR in 30d)

Description

Hi,

I have 2 classes with 2 differents maps with differents containers. When i made changes on one map, this is independant from the other map, excepts for setOrigin and setDestination. Those 2 functions impacts the two independants directions instances.

Class 1

this.map1 = new mapboxgl.Map({
      container: 'map1',
      style: 'mapbox://styles/mapbox/streets-v10',
    });

this.directions1 = new MapboxDirections({
      accessToken: mapboxgl.accessToken,
      unit: 'metric',
      profile: 'walking',
      interactive: false,
      controls: {
        inputs: false,
        instructions: false,
        profileSwitcher: false
      }
    });
    this.map1.addControl(this.directions);
... 
this.directions1.setOrigin([lon, lat]);
this.directions1.setDestination([lon+1, lat+1]);

Class 2

this.map2 = new mapboxgl.Map({
      container: 'map2',
      style: 'mapbox://styles/mapbox/streets-v10',
    });

this.directions2 = new MapboxDirections({
      accessToken: mapboxgl.accessToken,
      unit: 'metric',
      profile: 'walking',
      interactive: false,
      controls: {
        inputs: false,
        instructions: false,
        profileSwitcher: false
      }
    });
    this.map2.addControl(this.directions);
... 
this.directions2.setOrigin([lon+3, lat+3]);
this.directions2.setDestination([lon+3, lat+3]);

Problem : the setOrigin and setDestination from directions2 impacts the direction1 instance.

Contributor guide