apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.27k stars 382 forks source link

Loading GeoJSON #440

Closed ghost closed 10 years ago

ghost commented 10 years ago

Google Maps API supports loading GeoJSON to a map.data layer with the loadGeoJson method that accepts a url to the json, which I'm planning to use with json output from same Rails app loading the map.

var map;
function initialize() {
  // Create a simple map.
  map = new google.maps.Map(document.getElementById('map-canvas'), {
    zoom: 4,
    center: {lat: -28, lng: 137.883}
  });

  // Load a GeoJSON from the same server as our demo.
  map.data.loadGeoJson('https://storage.googleapis.com/maps-devrel/google.json');
}

google.maps.event.addDomListener(window, 'load', initialize);

This adds features from the geojson like multipolygons or whatever it may be to the map. I'm trying to get a handle on how things work in source, but is there a way to directly call this loadGeoJson from a gmaps handler object or will something need changed in the builder to support this?

apneadiving commented 10 years ago

Good idea :)

Since its attached to the map, attach it to the map too.

//currently you can do
handler.getMap().data.loadGeoJson(...)

// but you can add a method here: https://github.com/apneadiving/Google-Maps-for-Rails/blob/master/vendor/assets/javascripts/gmaps/google/objects/map.coffee
// to have:
handler.map.loadGeoJson(...)
ghost commented 10 years ago

@apneadiving awesome, I will give it a shot.

handler.getMap().data.loadGeoJson(...) worked fine, I just was loading an older version of API so using the latest API version has loadGeoJson method. thanks!