Joac Joac - 6 months ago 30
Javascript Question

Geodesic Lines on GeoJSON features on google maps

Im writing a GeoJson layer for Google Maps that uses different kinds of Features, styled dynamically.

I cant find a way to plot

LineStrings
as geodesic lines.

I have to make a feature request for Google Maps API or I'm missing something?

Answer

It's not implemented(currently), but it would be a desirable feature.

A workaround would be to hide the feature and create a custom polyline instead:

      map.data.addListener('addfeature', function(e) {
        //when it's a Line
        if(e.feature.getGeometry().getType()==='LineString'){
          //hide the feature
          map.data.overrideStyle(e.feature, {visible: false});
          //add a polyline
          new google.maps.Polyline({path    : e.feature.getGeometry().getArray(),
                                    map     : this.getMap(),
                                    geodesic: true});
        }
      });

It's a simple example, of course you also need to apply the styles & event-handlers

Comments